()
| 4646 | // ------------------------------------------------------------------ |
| 4647 | |
| 4648 | const makeAdmin = (): ExecutorAdmin => { |
| 4649 | const platformCore = makeCoreDb( |
| 4650 | makeFumaClient( |
| 4651 | withQueryContext(rootDbUntyped, { |
| 4652 | ...ownerContext, |
| 4653 | reach: "tenant", |
| 4654 | } satisfies ExecutorOwnerPolicyContext), |
| 4655 | ), |
| 4656 | ); |
| 4657 | |
| 4658 | const rowToAdminSubject = (row: CoreRow<"subject">): AdminSubject => ({ |
| 4659 | externalId: row.external_id, |
| 4660 | createdAt: row.created_at instanceof Date ? row.created_at : new Date(row.created_at), |
| 4661 | // bigint on drivers that return one, and a blob on SQLite — hence the |
| 4662 | // ORM read rather than raw SQL (see `subject-registry.ts`). |
| 4663 | lastSeenAt: row.last_seen_at == null ? null : Number(row.last_seen_at), |
| 4664 | status: row.status ?? null, |
| 4665 | }); |
| 4666 | |
| 4667 | const rowToAdminConnection = (row: ConnectionRow): AdminConnection => { |
| 4668 | const owner = row.owner as Owner; |
| 4669 | return { |
| 4670 | owner, |
| 4671 | // Org rows carry the empty-string sentinel, not a principal. |
| 4672 | subject: owner === "org" ? null : row.subject, |
| 4673 | integration: IntegrationSlug.make(row.integration), |
| 4674 | name: ConnectionName.make(row.name), |
| 4675 | oauthScope: row.oauth_scope == null ? null : String(row.oauth_scope), |
| 4676 | lastHealth: Option.getOrNull(decodeLastHealth(row.last_health)), |
| 4677 | }; |
| 4678 | }; |
| 4679 | |
| 4680 | const listSubjects = ( |
| 4681 | options?: AdminListSubjectsOptions, |
| 4682 | ): Effect.Effect<readonly AdminSubject[], StorageFailure> => { |
| 4683 | // Always both, always integers — see `normalizeAdminPaging`. Passing |
| 4684 | // them through independently produced a bare OFFSET, which SQLite |
| 4685 | // rejects outright. |
| 4686 | const { limit, offset } = normalizeAdminPaging(options); |
| 4687 | return platformCore |
| 4688 | .findMany("subject", { |
| 4689 | // Oldest first, ties broken on the unique key so the order is |
| 4690 | // total and paging can't repeat or skip a row. |
| 4691 | orderBy: [ |
| 4692 | ["created_at", "asc"], |
| 4693 | ["external_id", "asc"], |
| 4694 | ], |
| 4695 | limit, |
| 4696 | offset, |
| 4697 | }) |
| 4698 | .pipe(Effect.map((rows) => rows.map(rowToAdminSubject))); |
| 4699 | }; |
| 4700 | |
| 4701 | // Keyed on `(tenant, external_id)` — the table's unique index. No |
| 4702 | // `tenant` clause here: the tenant policy adds it to every read, the |
| 4703 | // same way `touchSubject` relies on it. |
| 4704 | const getSubject = (externalId: string): Effect.Effect<AdminSubject | null, StorageFailure> => |
| 4705 | platformCore |
no test coverage detected