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

Function listSubjectsWithConnections

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

Source from the content-addressed store, hash-verified

7079 // per-subject query produced. Subjects with no connections still report
7080 // an empty array rather than dropping out of the page.
7081 const listSubjectsWithConnections = (
7082 options?: AdminListSubjectsOptions,
7083 ): Effect.Effect<readonly AdminSubjectWithConnections[], StorageFailure> =>
7084 Effect.gen(function* () {
7085 const subjects = yield* listSubjects(options);
7086 // No page, no connection query — `in ([])` is a query that cannot
7087 // match, so issuing it would be pure latency.
7088 if (subjects.length === 0) return [];
7089
7090 const rows = yield* platformCore.findMany("connection", {
7091 where: (b: AnyCb) =>
7092 b.and(
7093 b("owner", "=", "user"),
7094 b(
7095 "subject",
7096 "in",
7097 subjects.map((entry) => entry.externalId),
7098 ),
7099 ),
7100 orderBy: [
7101 ["integration", "asc"],
7102 ["name", "asc"],
7103 ],
7104 });
7105
7106 const bySubject = new Map<string, AdminConnection[]>();
7107 for (const row of rows) {
7108 const connection = rowToAdminConnection(row);
7109 const bucket = bySubject.get(row.subject);
7110 if (bucket) bucket.push(connection);
7111 else bySubject.set(row.subject, [connection]);
7112 }
7113
7114 return subjects.map((entry) => ({
7115 ...entry,
7116 connections: bySubject.get(entry.externalId) ?? [],
7117 }));
7118 });
7119
7120 // Absent subject short-circuits: no connection query is issued for a
7121 // 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