project-store.ts
This file
Path
packages/project/src/project-store.ts
109 lines · 3.5 KiB · TypeScript
Last changed by
Merge observability into mainoscabrielbefore adoption1985111
History of this fileTake it
The walk stopped after 200 commits: lines older than 678c8b8 point at it.
Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
lines 1–78why, one step back1import type { CommitSha } from "@repo/protocol/ids";2import { Context } from "effect";3import type { Effect, Option, Schema } from "effect";45import type { ProjectEventInput } from "./events.ts";6import type {7 AnswerRow,8 AskRow,9 AttemptRow,10 BudgetDayRow,11 ClaimRow,12 DecisionRow,13 EnvValueRow,14 EventRow,15 LandingRow,16 LayerRead,17 LayerReadRow,18 LayerRow,19 LedgerRow,20 OutboxRow,21 ProjectRow,22 ProposalRow,23 PushEventRow,24 RatchetRow,25} from "./project-store/rows.ts";2627export const snapshotLandings = 50;2829/** How many events a project keeps; a watcher resuming from an older one has missed some. */30export const keptEvents = 500;3132export interface ProjectSnapshot {33 readonly answers: readonly AnswerRow[];34 readonly asks: readonly AskRow[];35 readonly attempts: readonly AttemptRow[];36 readonly budgetDays: readonly BudgetDayRow[];37 readonly claims: readonly ClaimRow[];38 readonly decisions: readonly DecisionRow[];39 readonly envValues: readonly EnvValueRow[];40 readonly landings: readonly LandingRow[];41 readonly lastSeq: number;42 readonly layers: readonly LayerRow[];43 readonly ledger: readonly LedgerRow[];44 readonly outbox: readonly OutboxRow[];45 readonly project: Option.Option<ProjectRow>;46 readonly proposals: readonly ProposalRow[];47 readonly queue: Schema.Json;48 readonly ratchets: readonly RatchetRow[];49}5051export interface ProjectWrites {52 readonly answers?: readonly AnswerRow[];53 readonly asks?: readonly AskRow[];54 readonly attempts?: readonly AttemptRow[];55 readonly budgetDays?: readonly BudgetDayRow[];56 readonly claims?: readonly ClaimRow[];57 readonly decisions?: readonly DecisionRow[];58 readonly envValues?: readonly EnvValueRow[];59 readonly events?: readonly ProjectEventInput[];60 readonly landings?: readonly LandingRow[];61 readonly layerReads?: readonly LayerRead[];62 readonly layers?: readonly LayerRow[];63 readonly ledger?: readonly LedgerRow[];64 readonly outbox?: readonly OutboxRow[];65 readonly project?: ProjectRow;66 readonly proposals?: readonly ProposalRow[];67 readonly pushEvents?: readonly PushEventRow[];68 readonly queue?: Schema.Json;69 readonly ratchets?: readonly RatchetRow[];70}7172export interface Committed {73 /** Event ids already stored. When there is one, the commit wrote nothing. */74 readonly duplicatePushEvents: readonly string[];75 readonly seqs: readonly number[];76}7778/**Merge build/comments-project into mainoscabrielbefore adoption49efd2a
lines 79–81why, one step back79 * `commit` is all or nothing, so a crash between calls never leaves half a80 * transition. A commit carrying a push event already stored is a replay: it81 * writes nothing and lists the ids it had seen. Store failures are defects.Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
lines 82–85why, one step back82 */83export class ProjectStore extends Context.Service<84 ProjectStore,85 {Merge observability into mainoscabrielbefore adoption1985111
lines 86–92why, one step back86 /**87 * Takes out the outbox rows it still holds of `ids`, and names them: of88 * two acks of one row, only the first takes it.89 */90 readonly ackOutbox: (91 ids: readonly string[]92 ) => Effect.Effect<readonly string[]>;Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
lines 93–100why, one step back93 readonly commit: (writes: ProjectWrites) => Effect.Effect<Committed>;94 readonly eventsSince: (95 seq: number,96 limit: number97 ) => Effect.Effect<readonly EventRow[]>;98 readonly landing: (99 sha: CommitSha100 ) => Effect.Effect<Option.Option<LandingRow>>;Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 101–102why, one step back101 /** Every landing the project keeps, past the snapshot's newest. */102 readonly landingCount: () => Effect.Effect<number>;Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
lines 103–109why, one step back103 readonly layerReadsSince: (104 seq: number,105 limit: number106 ) => Effect.Effect<readonly LayerReadRow[]>;107 readonly load: () => Effect.Effect<ProjectSnapshot>;108 }109>()("project/ProjectStore") {}