project-namespace.ts
This file
Path
apps/platform/test/project-namespace.ts
52 lines · 1.7 KiB · TypeScript
Last changed by
Merge build/comments-platform into mainoscabrielbefore adoptionddf09e8
History of this fileTake it
The walk stopped after 200 commits: lines older than 678c8b8 point at it.
Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
lines 1–2why, one step back1import { nameOfKey, ProjectKey } from "@repo/protocol/ids";2import type { ProjectName } from "@repo/protocol/ids";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 3–23why, one step back3import { untouchable } from "@repo/testkit/untouchable";4import { Effect, Option, SynchronizedRef } from "effect";56import type { ProjectNamespace } from "../src/adapters/do-projects.ts";7import type { ProjectShell } from "../src/project-shell.ts";89export const inProcessNamespace = <R>(10 shellFor: (name: ProjectName) => Effect.Effect<ProjectShell, never, R>11) =>12 Effect.gen(function* () {13 const context = yield* Effect.context<R>();1415 const shells = yield* SynchronizedRef.make<16 ReadonlyMap<string, ProjectShell>17 >(new Map());1819 const shellOf = (name: string) =>20 SynchronizedRef.modifyEffect(shells, (all) =>21 Option.match(Option.fromUndefinedOr(all.get(name)), {22 onNone: () =>23 Effect.map(Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 24why, one step back24 shellFor(Option.getOrThrow(nameOfKey(ProjectKey.make(name)))),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 25–52why, one step back25 (shell) => [shell, new Map(all).set(name, shell)] as const26 ),27 onSome: (shell) => Effect.succeed([shell, all] as const),28 })29 );3031 const namespace: ProjectNamespace = {32 get: (id) => ({33 call: (request) =>34 Effect.runPromiseWith(context)(35 Effect.flatMap(shellOf(id.toString()), (shell) =>36 shell.call(request)37 )38 ),39 }),40 idFromName: (name) =>41 untouchable<DurableObjectId>("DurableObjectId", {42 equals: (other) => other.toString() === name,43 name,44 toString: () => name,45 }),46 };4748 return {49 names: Effect.map(SynchronizedRef.get(shells), (all) => [...all.keys()]),50 namespace,51 };52 });