code-store.ts
This file
Path
packages/project/src/code-store.ts
24 lines · 885 bytes · TypeScript
Last changed by
Merge build/comments-project into mainoscabrielbefore adoption49efd2a
History of this fileTake it
Name the ask an opening opened, say why a policy has not evaluated, and give code history a durable storeoscabrielbefore adoption51f046c
lines 1–10why, one step back1import { Context, Effect, Option } from "effect";23/** A store of text by key, whose every failure reads as a miss. */4export interface CodeStoreApi {5 readonly get: (key: string) => Effect.Effect<Option.Option<string>>;6 readonly put: (key: string, value: string) => Effect.Effect<void>;7}89export const MAX_KEY_BYTES = 1024;10Merge build/comments-project into mainoscabrielbefore adoption49efd2a
line 11why, one step back11/** A key over the limit is a caller's bug (hash the path), so it dies rather than misses. */Name the ask an opening opened, say why a policy has not evaluated, and give code history a durable storeoscabrielbefore adoption51f046c
lines 12–24why, one step back12export const fittingKey = (key: string) =>13 new TextEncoder().encode(key).byteLength > MAX_KEY_BYTES14 ? Effect.die(15 `a code store key holds at most ${MAX_KEY_BYTES} bytes; hash its path`16 )17 : Effect.succeed(key);1819export const CodeStore = Context.Reference<CodeStoreApi>("project/CodeStore", {20 defaultValue: () => ({21 get: (key) => Effect.as(fittingKey(key), Option.none()),22 put: (key) => Effect.asVoid(fittingKey(key)),23 }),24});