()
| 4806 | // ------------------------------------------------------------------ |
| 4807 | |
| 4808 | const makeAdmin = (): ExecutorAdmin => { |
| 4809 | const platformCore = makeCoreDb( |
| 4810 | makeFumaClient( |
| 4811 | withQueryContext(rootDbUntyped, { |
| 4812 | ...ownerContext, |
| 4813 | reach: "tenant", |
| 4814 | } satisfies ExecutorOwnerPolicyContext), |
| 4815 | ), |
| 4816 | ); |
| 4817 | |
| 4818 | const rowToAdminSubject = (row: CoreRow<"subject">): AdminSubject => ({ |
| 4819 | externalId: row.external_id, |
| 4820 | createdAt: row.created_at instanceof Date ? row.created_at : new Date(row.created_at), |
| 4821 | // bigint on drivers that return one, and a blob on SQLite — hence the |
| 4822 | // ORM read rather than raw SQL (see `subject-registry.ts`). |
| 4823 | lastSeenAt: row.last_seen_at == null ? null : Number(row.last_seen_at), |
| 4824 | status: row.status ?? null, |
| 4825 | }); |
| 4826 | |
| 4827 | const rowToAdminConnection = (row: ConnectionRow): AdminConnection => { |
| 4828 | const owner = row.owner as Owner; |
| 4829 | return { |
| 4830 | owner, |
| 4831 | // Org rows carry the empty-string sentinel, not a principal. |
| 4832 | subject: owner === "org" ? null : row.subject, |
| 4833 | integration: IntegrationSlug.make(row.integration), |
| 4834 | name: ConnectionName.make(row.name), |
| 4835 | oauthScope: row.oauth_scope == null ? null : String(row.oauth_scope), |
| 4836 | lastHealth: Option.getOrNull(decodeLastHealth(row.last_health)), |
| 4837 | }; |
| 4838 | }; |
| 4839 | |
| 4840 | const listSubjects = ( |
| 4841 | options?: AdminListSubjectsOptions, |
| 4842 | ): Effect.Effect<readonly AdminSubject[], StorageFailure> => { |
| 4843 | // Always both, always integers — see `normalizeAdminPaging`. Passing |
| 4844 | // them through independently produced a bare OFFSET, which SQLite |
| 4845 | // rejects outright. |
| 4846 | const { limit, offset } = normalizeAdminPaging(options); |
| 4847 | return platformCore |
| 4848 | .findMany("subject", { |
| 4849 | // Oldest first, ties broken on the unique key so the order is |
| 4850 | // total and paging can't repeat or skip a row. |
| 4851 | orderBy: [ |
| 4852 | ["created_at", "asc"], |
| 4853 | ["external_id", "asc"], |
| 4854 | ], |
| 4855 | limit, |
| 4856 | offset, |
| 4857 | }) |
| 4858 | .pipe(Effect.map((rows) => rows.map(rowToAdminSubject))); |
| 4859 | }; |
| 4860 | |
| 4861 | // Keyed on `(tenant, external_id)` — the table's unique index. No |
| 4862 | // `tenant` clause here: the tenant policy adds it to every read, the |
| 4863 | // same way `touchSubject` relies on it. |
| 4864 | const getSubject = (externalId: string): Effect.Effect<AdminSubject | null, StorageFailure> => |
| 4865 | platformCore |
no test coverage detected