()
| 4733 | // ------------------------------------------------------------------ |
| 4734 | |
| 4735 | const makeAdmin = (): ExecutorAdmin => { |
| 4736 | const platformCore = makeCoreDb( |
| 4737 | makeFumaClient( |
| 4738 | withQueryContext(rootDbUntyped, { |
| 4739 | ...ownerContext, |
| 4740 | reach: "tenant", |
| 4741 | } satisfies ExecutorOwnerPolicyContext), |
| 4742 | ), |
| 4743 | ); |
| 4744 | |
| 4745 | const rowToAdminSubject = (row: CoreRow<"subject">): AdminSubject => ({ |
| 4746 | externalId: row.external_id, |
| 4747 | createdAt: row.created_at instanceof Date ? row.created_at : new Date(row.created_at), |
| 4748 | // bigint on drivers that return one, and a blob on SQLite — hence the |
| 4749 | // ORM read rather than raw SQL (see `subject-registry.ts`). |
| 4750 | lastSeenAt: row.last_seen_at == null ? null : Number(row.last_seen_at), |
| 4751 | status: row.status ?? null, |
| 4752 | }); |
| 4753 | |
| 4754 | const rowToAdminConnection = (row: ConnectionRow): AdminConnection => { |
| 4755 | const owner = row.owner as Owner; |
| 4756 | return { |
| 4757 | owner, |
| 4758 | // Org rows carry the empty-string sentinel, not a principal. |
| 4759 | subject: owner === "org" ? null : row.subject, |
| 4760 | integration: IntegrationSlug.make(row.integration), |
| 4761 | name: ConnectionName.make(row.name), |
| 4762 | oauthScope: row.oauth_scope == null ? null : String(row.oauth_scope), |
| 4763 | lastHealth: Option.getOrNull(decodeLastHealth(row.last_health)), |
| 4764 | }; |
| 4765 | }; |
| 4766 | |
| 4767 | const listSubjects = ( |
| 4768 | options?: AdminListSubjectsOptions, |
| 4769 | ): Effect.Effect<readonly AdminSubject[], StorageFailure> => { |
| 4770 | // Always both, always integers — see `normalizeAdminPaging`. Passing |
| 4771 | // them through independently produced a bare OFFSET, which SQLite |
| 4772 | // rejects outright. |
| 4773 | const { limit, offset } = normalizeAdminPaging(options); |
| 4774 | return platformCore |
| 4775 | .findMany("subject", { |
| 4776 | // Oldest first, ties broken on the unique key so the order is |
| 4777 | // total and paging can't repeat or skip a row. |
| 4778 | orderBy: [ |
| 4779 | ["created_at", "asc"], |
| 4780 | ["external_id", "asc"], |
| 4781 | ], |
| 4782 | limit, |
| 4783 | offset, |
| 4784 | }) |
| 4785 | .pipe(Effect.map((rows) => rows.map(rowToAdminSubject))); |
| 4786 | }; |
| 4787 | |
| 4788 | // Keyed on `(tenant, external_id)` — the table's unique index. No |
| 4789 | // `tenant` clause here: the tenant policy adds it to every read, the |
| 4790 | // same way `touchSubject` relies on it. |
| 4791 | const getSubject = (externalId: string): Effect.Effect<AdminSubject | null, StorageFailure> => |
| 4792 | platformCore |
no test coverage detected