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

Function makeAdmin

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

Source from the content-addressed store, hash-verified

4759 // ------------------------------------------------------------------
4760
4761 const makeAdmin = (): ExecutorAdmin => {
4762 const platformCore = makeCoreDb(
4763 makeFumaClient(
4764 withQueryContext(rootDbUntyped, {
4765 ...ownerContext,
4766 reach: "tenant",
4767 } satisfies ExecutorOwnerPolicyContext),
4768 ),
4769 );
4770
4771 const rowToAdminSubject = (row: CoreRow<"subject">): AdminSubject => ({
4772 externalId: row.external_id,
4773 createdAt: row.created_at instanceof Date ? row.created_at : new Date(row.created_at),
4774 // bigint on drivers that return one, and a blob on SQLite — hence the
4775 // ORM read rather than raw SQL (see `subject-registry.ts`).
4776 lastSeenAt: row.last_seen_at == null ? null : Number(row.last_seen_at),
4777 status: row.status ?? null,
4778 });
4779
4780 const rowToAdminConnection = (row: ConnectionRow): AdminConnection => {
4781 const owner = row.owner as Owner;
4782 return {
4783 owner,
4784 // Org rows carry the empty-string sentinel, not a principal.
4785 subject: owner === "org" ? null : row.subject,
4786 integration: IntegrationSlug.make(row.integration),
4787 name: ConnectionName.make(row.name),
4788 oauthScope: row.oauth_scope == null ? null : String(row.oauth_scope),
4789 lastHealth: Option.getOrNull(decodeLastHealth(row.last_health)),
4790 };
4791 };
4792
4793 const listSubjects = (
4794 options?: AdminListSubjectsOptions,
4795 ): Effect.Effect<readonly AdminSubject[], StorageFailure> => {
4796 // Always both, always integers — see `normalizeAdminPaging`. Passing
4797 // them through independently produced a bare OFFSET, which SQLite
4798 // rejects outright.
4799 const { limit, offset } = normalizeAdminPaging(options);
4800 return platformCore
4801 .findMany("subject", {
4802 // Oldest first, ties broken on the unique key so the order is
4803 // total and paging can't repeat or skip a row.
4804 orderBy: [
4805 ["created_at", "asc"],
4806 ["external_id", "asc"],
4807 ],
4808 limit,
4809 offset,
4810 })
4811 .pipe(Effect.map((rows) => rows.map(rowToAdminSubject)));
4812 };
4813
4814 // Keyed on `(tenant, external_id)` — the table's unique index. No
4815 // `tenant` clause here: the tenant policy adds it to every read, the
4816 // same way `touchSubject` relies on it.
4817 const getSubject = (externalId: string): Effect.Effect<AdminSubject | null, StorageFailure> =>
4818 platformCore

Callers 1

createExecutorFunction · 0.85

Calls 3

makeFumaClientFunction · 0.90
withQueryContextFunction · 0.90
makeCoreDbFunction · 0.85

Tested by

no test coverage detected