MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / listSubjectsWithConnections

Function listSubjectsWithConnections

packages/core/sdk/src/executor.ts:6333–6370  ·  view source on GitHub ↗
(
        options?: AdminListSubjectsOptions,
      )

Source from the content-addressed store, hash-verified

6331 // per-subject query produced. Subjects with no connections still report
6332 // an empty array rather than dropping out of the page.
6333 const listSubjectsWithConnections = (
6334 options?: AdminListSubjectsOptions,
6335 ): Effect.Effect<readonly AdminSubjectWithConnections[], StorageFailure> =>
6336 Effect.gen(function* () {
6337 const subjects = yield* listSubjects(options);
6338 // No page, no connection query — `in ([])` is a query that cannot
6339 // match, so issuing it would be pure latency.
6340 if (subjects.length === 0) return [];
6341
6342 const rows = yield* platformCore.findMany("connection", {
6343 where: (b: AnyCb) =>
6344 b.and(
6345 b("owner", "=", "user"),
6346 b(
6347 "subject",
6348 "in",
6349 subjects.map((entry) => entry.externalId),
6350 ),
6351 ),
6352 orderBy: [
6353 ["integration", "asc"],
6354 ["name", "asc"],
6355 ],
6356 });
6357
6358 const bySubject = new Map<string, AdminConnection[]>();
6359 for (const row of rows) {
6360 const connection = rowToAdminConnection(row);
6361 const bucket = bySubject.get(row.subject);
6362 if (bucket) bucket.push(connection);
6363 else bySubject.set(row.subject, [connection]);
6364 }
6365
6366 return subjects.map((entry) => ({
6367 ...entry,
6368 connections: bySubject.get(entry.externalId) ?? [],
6369 }));
6370 });
6371
6372 // Absent subject short-circuits: no connection query is issued for a
6373 // principal the tenant never recorded.

Callers

nothing calls this directly

Calls 5

listSubjectsFunction · 0.85
rowToAdminConnectionFunction · 0.85
pushMethod · 0.80
getMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected