()
| 6240 | // ------------------------------------------------------------------ |
| 6241 | |
| 6242 | const makeAdmin = (): ExecutorAdmin => { |
| 6243 | const platformCore = makeCoreDb( |
| 6244 | makeFumaClient( |
| 6245 | withQueryContext(rootDbUntyped, { |
| 6246 | ...ownerContext, |
| 6247 | reach: "tenant", |
| 6248 | } satisfies ExecutorOwnerPolicyContext), |
| 6249 | ), |
| 6250 | ); |
| 6251 | |
| 6252 | const rowToAdminSubject = (row: CoreRow<"subject">): AdminSubject => ({ |
| 6253 | externalId: row.external_id, |
| 6254 | createdAt: row.created_at instanceof Date ? row.created_at : new Date(row.created_at), |
| 6255 | // bigint on drivers that return one, and a blob on SQLite — hence the |
| 6256 | // ORM read rather than raw SQL (see `subject-registry.ts`). |
| 6257 | lastSeenAt: row.last_seen_at == null ? null : Number(row.last_seen_at), |
| 6258 | status: row.status ?? null, |
| 6259 | }); |
| 6260 | |
| 6261 | const rowToAdminConnection = (row: ConnectionRow): AdminConnection => { |
| 6262 | const owner = row.owner as Owner; |
| 6263 | return { |
| 6264 | owner, |
| 6265 | // Org rows carry the empty-string sentinel, not a principal. |
| 6266 | subject: owner === "org" ? null : row.subject, |
| 6267 | integration: IntegrationSlug.make(row.integration), |
| 6268 | name: ConnectionName.make(row.name), |
| 6269 | oauthScope: row.oauth_scope == null ? null : String(row.oauth_scope), |
| 6270 | lastHealth: presentedLastHealth(row), |
| 6271 | }; |
| 6272 | }; |
| 6273 | |
| 6274 | const listSubjects = ( |
| 6275 | options?: AdminListSubjectsOptions, |
| 6276 | ): Effect.Effect<readonly AdminSubject[], StorageFailure> => { |
| 6277 | // Always both, always integers — see `normalizeAdminPaging`. Passing |
| 6278 | // them through independently produced a bare OFFSET, which SQLite |
| 6279 | // rejects outright. |
| 6280 | const { limit, offset } = normalizeAdminPaging(options); |
| 6281 | return platformCore |
| 6282 | .findMany("subject", { |
| 6283 | // Oldest first, ties broken on the unique key so the order is |
| 6284 | // total and paging can't repeat or skip a row. |
| 6285 | orderBy: [ |
| 6286 | ["created_at", "asc"], |
| 6287 | ["external_id", "asc"], |
| 6288 | ], |
| 6289 | limit, |
| 6290 | offset, |
| 6291 | }) |
| 6292 | .pipe(Effect.map((rows) => rows.map(rowToAdminSubject))); |
| 6293 | }; |
| 6294 | |
| 6295 | // Keyed on `(tenant, external_id)` — the table's unique index. No |
| 6296 | // `tenant` clause here: the tenant policy adds it to every read, the |
| 6297 | // same way `touchSubject` relies on it. |
| 6298 | const getSubject = (externalId: string): Effect.Effect<AdminSubject | null, StorageFailure> => |
| 6299 | platformCore |
no test coverage detected