()
| 6330 | // ------------------------------------------------------------------ |
| 6331 | |
| 6332 | const makeAdmin = (): ExecutorAdmin => { |
| 6333 | const platformCore = makeCoreDb( |
| 6334 | makeFumaClient( |
| 6335 | withQueryContext(rootDbUntyped, { |
| 6336 | ...ownerContext, |
| 6337 | reach: "tenant", |
| 6338 | } satisfies ExecutorOwnerPolicyContext), |
| 6339 | ), |
| 6340 | ); |
| 6341 | |
| 6342 | const rowToAdminSubject = (row: CoreRow<"subject">): AdminSubject => ({ |
| 6343 | externalId: row.external_id, |
| 6344 | createdAt: row.created_at instanceof Date ? row.created_at : new Date(row.created_at), |
| 6345 | // bigint on drivers that return one, and a blob on SQLite — hence the |
| 6346 | // ORM read rather than raw SQL (see `subject-registry.ts`). |
| 6347 | lastSeenAt: row.last_seen_at == null ? null : Number(row.last_seen_at), |
| 6348 | status: row.status ?? null, |
| 6349 | }); |
| 6350 | |
| 6351 | const rowToAdminConnection = (row: ConnectionRow): AdminConnection => { |
| 6352 | const owner = row.owner as Owner; |
| 6353 | return { |
| 6354 | owner, |
| 6355 | // Org rows carry the empty-string sentinel, not a principal. |
| 6356 | subject: owner === "org" ? null : row.subject, |
| 6357 | integration: IntegrationSlug.make(row.integration), |
| 6358 | name: ConnectionName.make(row.name), |
| 6359 | oauthScope: row.oauth_scope == null ? null : String(row.oauth_scope), |
| 6360 | lastHealth: presentedLastHealth(row), |
| 6361 | }; |
| 6362 | }; |
| 6363 | |
| 6364 | const listSubjects = ( |
| 6365 | options?: AdminListSubjectsOptions, |
| 6366 | ): Effect.Effect<readonly AdminSubject[], StorageFailure> => { |
| 6367 | // Always both, always integers — see `normalizeAdminPaging`. Passing |
| 6368 | // them through independently produced a bare OFFSET, which SQLite |
| 6369 | // rejects outright. |
| 6370 | const { limit, offset } = normalizeAdminPaging(options); |
| 6371 | return platformCore |
| 6372 | .findMany("subject", { |
| 6373 | // Oldest first, ties broken on the unique key so the order is |
| 6374 | // total and paging can't repeat or skip a row. |
| 6375 | orderBy: [ |
| 6376 | ["created_at", "asc"], |
| 6377 | ["external_id", "asc"], |
| 6378 | ], |
| 6379 | limit, |
| 6380 | offset, |
| 6381 | }) |
| 6382 | .pipe(Effect.map((rows) => rows.map(rowToAdminSubject))); |
| 6383 | }; |
| 6384 | |
| 6385 | // Keyed on `(tenant, external_id)` — the table's unique index. No |
| 6386 | // `tenant` clause here: the tenant policy adds it to every read, the |
| 6387 | // same way `touchSubject` relies on it. |
| 6388 | const getSubject = (externalId: string): Effect.Effect<AdminSubject | null, StorageFailure> => |
| 6389 | platformCore |
no test coverage detected