(
options?: AdminListSubjectsOptions,
)
| 7171 | // per-subject query produced. Subjects with no connections still report |
| 7172 | // an empty array rather than dropping out of the page. |
| 7173 | const listSubjectsWithConnections = ( |
| 7174 | options?: AdminListSubjectsOptions, |
| 7175 | ): Effect.Effect<readonly AdminSubjectWithConnections[], StorageFailure> => |
| 7176 | Effect.gen(function* () { |
| 7177 | const subjects = yield* listSubjects(options); |
| 7178 | // No page, no connection query — `in ([])` is a query that cannot |
| 7179 | // match, so issuing it would be pure latency. |
| 7180 | if (subjects.length === 0) return []; |
| 7181 | |
| 7182 | const rows = yield* platformCore.findMany("connection", { |
| 7183 | where: (b: AnyCb) => |
| 7184 | b.and( |
| 7185 | b("owner", "=", "user"), |
| 7186 | b( |
| 7187 | "subject", |
| 7188 | "in", |
| 7189 | subjects.map((entry) => entry.externalId), |
| 7190 | ), |
| 7191 | ), |
| 7192 | orderBy: [ |
| 7193 | ["integration", "asc"], |
| 7194 | ["name", "asc"], |
| 7195 | ], |
| 7196 | }); |
| 7197 | |
| 7198 | const bySubject = new Map<string, AdminConnection[]>(); |
| 7199 | for (const row of rows) { |
| 7200 | const connection = rowToAdminConnection(row); |
| 7201 | const bucket = bySubject.get(row.subject); |
| 7202 | if (bucket) bucket.push(connection); |
| 7203 | else bySubject.set(row.subject, [connection]); |
| 7204 | } |
| 7205 | |
| 7206 | return subjects.map((entry) => ({ |
| 7207 | ...entry, |
| 7208 | connections: bySubject.get(entry.externalId) ?? [], |
| 7209 | })); |
| 7210 | }); |
| 7211 | |
| 7212 | // Absent subject short-circuits: no connection query is issued for a |
| 7213 | // principal the tenant never recorded. |
nothing calls this directly
no test coverage detected