events.ts
This file
Path
packages/project/src/events.ts
61 lines · 1.9 KiB · TypeScript
Last changed by
Merge build/comments-project into mainoscabrielbefore adoption49efd2a
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–51why, one step back1import type { Ask, AskListing } from "@repo/protocol/domain/ask";2import type { ProjectEvent as Event } from "@repo/protocol/domain/event";3import { ProjectEvent } from "@repo/protocol/domain/event";4import type { Outcome } from "@repo/protocol/domain/outcome";5import type { AskId, CommitSha, LandedSha } from "@repo/protocol/ids";6import { Data, Effect, Schema } from "effect";7import type { DateTime } from "effect";89/** Drops a key from each member of a union, not from the union as a whole. */10type OmitEach<Union, Key extends PropertyKey> = Union extends unknown11 ? Omit<Union, Key>12 : never;1314export type ProjectEventInput = OmitEach<Event, "seq">;1516export const ProjectEventInput = Data.taggedEnum<ProjectEventInput>();1718export const listingOf = (ask: Ask): AskListing => {19 const listing = {20 ask: ask.id,21 blockedBy: ask.blockedBy,22 claimed: ask.state === "claimed",23 kind: ask.kind,24 territory: ask.territory.module,25 want: ask.brief.want,26 };2728 return ask.reserve === undefined29 ? listing30 : { ...listing, reserve: ask.reserve };31};3233export const askOpened = (ask: Ask, at: DateTime.Utc): ProjectEventInput =>34 ProjectEventInput.AskOpened({ ask: listingOf(ask), at });3536export const askClosed = (37 ask: AskId,38 landing: LandedSha,39 at: DateTime.Utc40): ProjectEventInput => ProjectEventInput.AskClosed({ ask, at, landing });4142export const judged = (43 ask: AskId,44 head: CommitSha,45 outcome: Outcome,46 at: DateTime.Utc47): ProjectEventInput => ProjectEventInput.Judged({ ask, at, head, outcome });4849const asEvent = Schema.decodeUnknownEffect(Schema.toType(ProjectEvent));5051/**Merge build/comments-project into mainoscabrielbefore adoption49efd2a
lines 52–53why, one step back52 * The service commits under the project's lock, so nothing numbers an event in53 * between.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 54–61why, one step back54 */55export const numbered = (56 lastSeq: number,57 events: readonly ProjectEventInput[]58): Effect.Effect<readonly ProjectEvent[]> =>59 Effect.forEach(events, (event, index) =>60 Effect.orDie(asEvent({ ...event, seq: lastSeq + index + 1 }))61 );