()
| 5224 | // ------------------------------------------------------------------ |
| 5225 | |
| 5226 | const makeAdmin = (): ExecutorAdmin => { |
| 5227 | const platformCore = makeCoreDb( |
| 5228 | makeFumaClient( |
| 5229 | withQueryContext(rootDbUntyped, { |
| 5230 | ...ownerContext, |
| 5231 | reach: "tenant", |
| 5232 | } satisfies ExecutorOwnerPolicyContext), |
| 5233 | ), |
| 5234 | ); |
| 5235 | |
| 5236 | const rowToAdminSubject = (row: CoreRow<"subject">): AdminSubject => ({ |
| 5237 | externalId: row.external_id, |
| 5238 | createdAt: row.created_at instanceof Date ? row.created_at : new Date(row.created_at), |
| 5239 | // bigint on drivers that return one, and a blob on SQLite — hence the |
| 5240 | // ORM read rather than raw SQL (see `subject-registry.ts`). |
| 5241 | lastSeenAt: row.last_seen_at == null ? null : Number(row.last_seen_at), |
| 5242 | status: row.status ?? null, |
| 5243 | }); |
| 5244 | |
| 5245 | const rowToAdminConnection = (row: ConnectionRow): AdminConnection => { |
| 5246 | const owner = row.owner as Owner; |
| 5247 | return { |
| 5248 | owner, |
| 5249 | // Org rows carry the empty-string sentinel, not a principal. |
| 5250 | subject: owner === "org" ? null : row.subject, |
| 5251 | integration: IntegrationSlug.make(row.integration), |
| 5252 | name: ConnectionName.make(row.name), |
| 5253 | oauthScope: row.oauth_scope == null ? null : String(row.oauth_scope), |
| 5254 | lastHealth: Option.getOrNull(decodeLastHealth(row.last_health)), |
| 5255 | }; |
| 5256 | }; |
| 5257 | |
| 5258 | const listSubjects = ( |
| 5259 | options?: AdminListSubjectsOptions, |
| 5260 | ): Effect.Effect<readonly AdminSubject[], StorageFailure> => { |
| 5261 | // Always both, always integers — see `normalizeAdminPaging`. Passing |
| 5262 | // them through independently produced a bare OFFSET, which SQLite |
| 5263 | // rejects outright. |
| 5264 | const { limit, offset } = normalizeAdminPaging(options); |
| 5265 | return platformCore |
| 5266 | .findMany("subject", { |
| 5267 | // Oldest first, ties broken on the unique key so the order is |
| 5268 | // total and paging can't repeat or skip a row. |
| 5269 | orderBy: [ |
| 5270 | ["created_at", "asc"], |
| 5271 | ["external_id", "asc"], |
| 5272 | ], |
| 5273 | limit, |
| 5274 | offset, |
| 5275 | }) |
| 5276 | .pipe(Effect.map((rows) => rows.map(rowToAdminSubject))); |
| 5277 | }; |
| 5278 | |
| 5279 | // Keyed on `(tenant, external_id)` — the table's unique index. No |
| 5280 | // `tenant` clause here: the tenant policy adds it to every read, the |
| 5281 | // same way `touchSubject` relies on it. |
| 5282 | const getSubject = (externalId: string): Effect.Effect<AdminSubject | null, StorageFailure> => |
| 5283 | platformCore |
no test coverage detected