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

Function makeAdmin

packages/core/sdk/src/executor.ts:7070–7231  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

7068 // ------------------------------------------------------------------
7069
7070 const makeAdmin = (): ExecutorAdmin => {
7071 const platformCore = makeCoreDb(
7072 makeFumaClient(
7073 withQueryContext(rootDbUntyped, {
7074 ...ownerContext,
7075 reach: "tenant",
7076 } satisfies ExecutorOwnerPolicyContext),
7077 ),
7078 );
7079
7080 const rowToAdminSubject = (row: CoreRow<"subject">): AdminSubject => ({
7081 externalId: row.external_id,
7082 createdAt: row.created_at instanceof Date ? row.created_at : new Date(row.created_at),
7083 // bigint on drivers that return one, and a blob on SQLite — hence the
7084 // ORM read rather than raw SQL (see `subject-registry.ts`).
7085 lastSeenAt: row.last_seen_at == null ? null : Number(row.last_seen_at),
7086 status: row.status ?? null,
7087 });
7088
7089 const rowToAdminConnection = (row: ConnectionRow): AdminConnection => {
7090 const owner = row.owner as Owner;
7091 return {
7092 owner,
7093 // Org rows carry the empty-string sentinel, not a principal.
7094 subject: owner === "org" ? null : row.subject,
7095 integration: IntegrationSlug.make(row.integration),
7096 name: ConnectionName.make(row.name),
7097 oauthScope: row.oauth_scope == null ? null : String(row.oauth_scope),
7098 lastHealth: presentedLastHealth(row),
7099 };
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,

Callers 1

createExecutorFunction · 0.85

Calls 3

makeFumaClientFunction · 0.90
withQueryContextFunction · 0.90
makeCoreDbFunction · 0.85

Tested by

no test coverage detected