(
options?: AdminListSubjectsOptions,
)
| 6934 | // per-subject query produced. Subjects with no connections still report |
| 6935 | // an empty array rather than dropping out of the page. |
| 6936 | const listSubjectsWithConnections = ( |
| 6937 | options?: AdminListSubjectsOptions, |
| 6938 | ): Effect.Effect<readonly AdminSubjectWithConnections[], StorageFailure> => |
| 6939 | Effect.gen(function* () { |
| 6940 | const subjects = yield* listSubjects(options); |
| 6941 | // No page, no connection query — `in ([])` is a query that cannot |
| 6942 | // match, so issuing it would be pure latency. |
| 6943 | if (subjects.length === 0) return []; |
| 6944 | |
| 6945 | const rows = yield* platformCore.findMany("connection", { |
| 6946 | where: (b: AnyCb) => |
| 6947 | b.and( |
| 6948 | b("owner", "=", "user"), |
| 6949 | b( |
| 6950 | "subject", |
| 6951 | "in", |
| 6952 | subjects.map((entry) => entry.externalId), |
| 6953 | ), |
| 6954 | ), |
| 6955 | orderBy: [ |
| 6956 | ["integration", "asc"], |
| 6957 | ["name", "asc"], |
| 6958 | ], |
| 6959 | }); |
| 6960 | |
| 6961 | const bySubject = new Map<string, AdminConnection[]>(); |
| 6962 | for (const row of rows) { |
| 6963 | const connection = rowToAdminConnection(row); |
| 6964 | const bucket = bySubject.get(row.subject); |
| 6965 | if (bucket) bucket.push(connection); |
| 6966 | else bySubject.set(row.subject, [connection]); |
| 6967 | } |
| 6968 | |
| 6969 | return subjects.map((entry) => ({ |
| 6970 | ...entry, |
| 6971 | connections: bySubject.get(entry.externalId) ?? [], |
| 6972 | })); |
| 6973 | }); |
| 6974 | |
| 6975 | // Absent subject short-circuits: no connection query is issued for a |
| 6976 | // principal the tenant never recorded. |
nothing calls this directly
no test coverage detected