Skip to content
Myr

memory.ts

This file

Path

apps/platform/src/releases/memory.ts

39 lines · 1.2 KiB · TypeScript

Last changed by

Merge build/comments-platform into mainoscabrielbefore adoptionddf09e8

History of this file

Take 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–39why, one step back
1import { Context, Effect, Layer, Option, Predicate, Ref } from "effect";
23import { ReleaseStore } from "../releases.ts";45export class ReleaseReads extends Context.Service<6 ReleaseReads,7 { readonly keys: Effect.Effect<readonly string[]> }8>()("platform/ReleaseReads") {}910const encoder = new TextEncoder();1112export const ReleaseStoreMemory = {13 layer: (14 files: Readonly<Record<string, string | Uint8Array>>15 ): Layer.Layer<ReleaseStore | ReleaseReads> =>16 Layer.effectContext(17 Effect.gen(function* () {18 const reads = yield* Ref.make<readonly string[]>([]);1920 const kept = new Map(21 Object.entries(files).map(([key, file]) => [22 key,23 Predicate.isString(file) ? encoder.encode(file) : file,24 ])25 );2627 return Context.make(ReleaseStore, {28 get: (key) =>29 Effect.as(30 Ref.update(reads, (keys) => [...keys, key]),31 Option.map(Option.fromUndefinedOr(kept.get(key)), (body) => ({32 body,33 size: body.byteLength,34 }))35 ),36 }).pipe(Context.add(ReleaseReads, { keys: Ref.get(reads) }));37 })38 ),39};