()
| 6841 | // ------------------------------------------------------------------ |
| 6842 | |
| 6843 | const makeAdmin = (): ExecutorAdmin => { |
| 6844 | const platformCore = makeCoreDb( |
| 6845 | makeFumaClient( |
| 6846 | withQueryContext(rootDbUntyped, { |
| 6847 | ...ownerContext, |
| 6848 | reach: "tenant", |
| 6849 | } satisfies ExecutorOwnerPolicyContext), |
| 6850 | ), |
| 6851 | ); |
| 6852 | |
| 6853 | const rowToAdminSubject = (row: CoreRow<"subject">): AdminSubject => ({ |
| 6854 | externalId: row.external_id, |
| 6855 | createdAt: row.created_at instanceof Date ? row.created_at : new Date(row.created_at), |
| 6856 | // bigint on drivers that return one, and a blob on SQLite — hence the |
| 6857 | // ORM read rather than raw SQL (see `subject-registry.ts`). |
| 6858 | lastSeenAt: row.last_seen_at == null ? null : Number(row.last_seen_at), |
| 6859 | status: row.status ?? null, |
| 6860 | }); |
| 6861 | |
| 6862 | const rowToAdminConnection = (row: ConnectionRow): AdminConnection => { |
| 6863 | const owner = row.owner as Owner; |
| 6864 | return { |
| 6865 | owner, |
| 6866 | // Org rows carry the empty-string sentinel, not a principal. |
| 6867 | subject: owner === "org" ? null : row.subject, |
| 6868 | integration: IntegrationSlug.make(row.integration), |
| 6869 | name: ConnectionName.make(row.name), |
| 6870 | oauthScope: row.oauth_scope == null ? null : String(row.oauth_scope), |
| 6871 | lastHealth: presentedLastHealth(row), |
| 6872 | }; |
| 6873 | }; |
| 6874 | |
| 6875 | const listSubjects = ( |
| 6876 | options?: AdminListSubjectsOptions, |
| 6877 | ): Effect.Effect<readonly AdminSubject[], StorageFailure> => { |
| 6878 | // Always both, always integers — see `normalizeAdminPaging`. Passing |
| 6879 | // them through independently produced a bare OFFSET, which SQLite |
| 6880 | // rejects outright. |
| 6881 | const { limit, offset } = normalizeAdminPaging(options); |
| 6882 | return platformCore |
| 6883 | .findMany("subject", { |
| 6884 | // Oldest first, ties broken on the unique key so the order is |
| 6885 | // total and paging can't repeat or skip a row. |
| 6886 | orderBy: [ |
| 6887 | ["created_at", "asc"], |
| 6888 | ["external_id", "asc"], |
| 6889 | ], |
| 6890 | limit, |
| 6891 | offset, |
| 6892 | }) |
| 6893 | .pipe(Effect.map((rows) => rows.map(rowToAdminSubject))); |
| 6894 | }; |
| 6895 | |
| 6896 | // Keyed on `(tenant, external_id)` — the table's unique index. No |
| 6897 | // `tenant` clause here: the tenant policy adds it to every read, the |
| 6898 | // same way `touchSubject` relies on it. |
| 6899 | const getSubject = (externalId: string): Effect.Effect<AdminSubject | null, StorageFailure> => |
| 6900 | platformCore |
no test coverage detected