Skip to content
Myr

state.ts

This file

Path

apps/platform/src/visibility/state.ts

69 lines · 2.0 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/comments-platform into mainoscabrielbefore adoptionddf09e8

lines 1–2why, one step back
1// A salt is kept only in the project's Durable Object: no ledger entry, trailer,
2// note or event carries 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 3–69why, one step back
3import type { Fetch } from "@repo/artifacts/fetch";
4import {5 AdmissionStarts,6 ProjectVisibilityLive,7 SaltSource,8} from "@repo/project/visibility/state";9import { Effect, Layer, Schema } from "effect";1011import { AdmissionParams, admissionId } from "../answer-runs.ts";12import type { PlatformConfig } from "../platform.ts";13import { layerRepos } from "./layer-repos.ts";1415export const WebCryptoSalts: Layer.Layer<SaltSource> = Layer.succeed(16 SaltSource,17 SaltSource.of({18 next: Effect.sync(() => crypto.getRandomValues(new Uint8Array(32))),19 })20);2122export interface AdmissionWorkflow {23 readonly create: (options: {24 readonly id: string;25 readonly params: typeof AdmissionParams.Encoded;26 }) => Promise<{ readonly id: string }>;27 readonly get: (id: string) => Promise<{ readonly id: string }>;28}2930const encodeParams = Schema.encodeEffect(AdmissionParams);3132export const admissionStarts = (33 workflow: AdmissionWorkflow34): Layer.Layer<AdmissionStarts> =>35 Layer.succeed(36 AdmissionStarts,37 AdmissionStarts.of({38 start: (input) =>39 Effect.gen(function* () {40 const params = AdmissionParams.make(input);41 const id = admissionId(params);42 const encoded = yield* encodeParams(params);4344 yield* Effect.tryPromise(() =>45 workflow.create({ id, params: encoded })46 ).pipe(47 // The id is taken: the admission was started before.48 Effect.catch((error) =>49 Effect.tryPromise(() => workflow.get(id)).pipe(50 Effect.mapError(() => error)51 )52 )53 );54 }).pipe(Effect.orDie),55 })56 );5758export const stateLive = (59 config: PlatformConfig60): Layer.Layer<never, never, Fetch> =>61 ProjectVisibilityLive.pipe(62 Layer.provide(63 Layer.mergeAll(64 layerRepos(config),65 WebCryptoSalts,66 admissionStarts(config.ANSWER)67 )68 )69 );