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

Function listSubjects

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

Source from the content-addressed store, hash-verified

7100 };
7101
7102 const listSubjects = (
7103 options?: AdminListSubjectsOptions,
7104 ): Effect.Effect<readonly AdminSubject[], StorageFailure> => {
7105 // Always both, always integers — see `normalizeAdminPaging`. Passing
7106 // them through independently produced a bare OFFSET, which SQLite
7107 // rejects outright.
7108 const { limit, offset } = normalizeAdminPaging(options);
7109 const externalIds = options?.externalIds;
7110 // An empty id set is a query that cannot match; answer it without a
7111 // round trip rather than emitting `in ()`, which some drivers reject.
7112 if (externalIds !== undefined && externalIds.length === 0) return Effect.succeed([]);
7113 return platformCore
7114 .findMany("subject", {
7115 // The id filter is the ONLY predicate here; the tenant clause is
7116 // the policy's, added to every read the same way `getSubject`
7117 // relies on it.
7118 ...(externalIds === undefined
7119 ? {}
7120 : { where: (b: AnyCb) => b("external_id", "in", [...externalIds]) }),
7121 // Oldest first, ties broken on the unique key so the order is
7122 // total and paging can't repeat or skip a row.
7123 orderBy: [
7124 ["created_at", "asc"],
7125 ["external_id", "asc"],
7126 ],
7127 limit,
7128 offset,
7129 })
7130 .pipe(Effect.map((rows) => rows.map(rowToAdminSubject)));
7131 };
7132
7133 // Keyed on `(tenant, external_id)` — the table's unique index. No
7134 // `tenant` clause here: the tenant policy adds it to every read, the

Callers 1

Calls 1

normalizeAdminPagingFunction · 0.85

Tested by

no test coverage detected