Skip to content
Myr

memory.ts

This file

Path

packages/project/src/description/memory.ts

36 lines · 947 bytes · TypeScript

Last changed by

Merge redesign into mainoscabrielbefore adoptioncaedd21

History of this file

Take it

Merge redesign into mainoscabrielbefore adoptioncaedd21

lines 1–36why, one step back
1import type { ProjectName } from "@repo/protocol/ids";
2import { Effect, Layer, Ref } from "effect";34import { ProjectDescriptions } from "../description.ts";5import type {6 KeptDescription,7 ProjectDescriptionsApi,8} from "../description.ts";910export const ProjectDescriptionsMemory = Layer.effect(11 ProjectDescriptions,12 Effect.gen(function* () {13 const kept = yield* Ref.make<ReadonlyMap<ProjectName, KeptDescription>>(14 new Map()15 );1617 const store: ProjectDescriptionsApi = {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);