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

Function listSubjectsWithConnections

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

Source from the content-addressed store, hash-verified

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.

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