memory.ts
This file
Path
packages/project/src/standing-posture/memory.ts
36 lines · 938 bytes · TypeScript
Last changed by
Merge build/comments-project into mainoscabrielbefore adoption49efd2a
History of this fileTake it
Merge build/1213-platform-performance-and-agent-surfacesoscabrielbefore adoption1d75a0d
lines 1–36why, one step back1import type { ProjectName } from "@repo/protocol/ids";2import { Effect, Layer, Ref } from "effect";34import { StandingPostures } from "../standing-posture.ts";5import type {6 StandingEntry,7 StandingPosturesApi,8} from "../standing-posture.ts";910export const StandingPosturesMemory = Layer.effect(11 StandingPostures,12 Effect.gen(function* () {13 const kept = yield* Ref.make<ReadonlyMap<ProjectName, StandingEntry>>(14 new Map()15 );1617 const store: StandingPosturesApi = {18 get: (projects) =>19 Effect.map(20 Ref.get(kept),21 (all) =>22 new Map(23 projects.flatMap((project) => {24 const entry = all.get(project);2526 return entry === undefined ? [] : [[project, entry] as const];27 })28 )29 ),30 put: (entries) =>31 Ref.update(kept, (all) => new Map([...all, ...entries])),32 };3334 return store;35 })36);