Skip to content
Myr

memory.ts

This file

Path

packages/project/src/lander/memory.ts

80 lines · 2.4 KiB · TypeScript

Last changed by

Merge build/comments-project into mainoscabrielbefore adoption49efd2a

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–80why, one step back
1import type { RepoBusy, StaleBase } from "@repo/protocol/refusal";
2import { VerifierBlocked } from "@repo/protocol/refusal";3import type { ConfigBundle } from "@repo/rules/rules-evaluator";4import { Array, Data, Effect, Layer } from "effect";5import type { Result } from "effect";67import { Lander } from "../lander.ts";8import type {9 BundleJob,10 ComposeJob,11 Composed,12 Landed,13 LandJob,14 MergeJob,15 Merged,16} from "../lander.ts";1718export type LanderJob = Data.TaggedEnum<{19 Merge: { readonly job: MergeJob };20 Land: { readonly job: LandJob };21 Compose: { readonly job: ComposeJob };22 BundleRules: { readonly job: BundleJob };23}>;2425export const LanderJob = Data.taggedEnum<LanderJob>();2627export interface LanderScript {28 readonly merge?: readonly Result.Result<29 Merged,30 StaleBase | VerifierBlocked31 >[];32 readonly land?: readonly Result.Result<33 Landed,34 StaleBase | RepoBusy | VerifierBlocked35 >[];36 readonly compose?: readonly Result.Result<Composed, VerifierBlocked>[];37 readonly bundle?: readonly Result.Result<ConfigBundle, VerifierBlocked>[];38}3940export type ScriptedLander = Layer.Layer<Lander> & {41 readonly jobs: Effect.Effect<readonly LanderJob[]>;42};4344export const LanderMemory = {45 layer: (script: LanderScript): ScriptedLander => {46 const jobs: LanderJob[] = [];47 const served = new Map<keyof LanderScript, number>();4849 const answer = <A, E>(50 operation: keyof LanderScript,51 results: readonly Result.Result<A, E>[] | undefined,52 job: LanderJob53 ): Effect.Effect<A, E | VerifierBlocked> =>54 Effect.suspend((): Effect.Effect<A, E | VerifierBlocked> => {55 const count = served.get(operation) ?? 0;5657 jobs.push(job);58 served.set(operation, count + 1);5960 if (results === undefined || !Array.isReadonlyArrayNonEmpty(results)) {61 return Effect.fail(new VerifierBlocked({}));62 }6364 return Effect.fromResult(65 results[Math.min(count, results.length - 1)] ?? results[0]66 );67 });6869 const layer = Layer.succeed(Lander, {70 bundleRules: (job) =>71 answer("bundle", script.bundle, LanderJob.BundleRules({ job })),72 compose: (job) =>73 answer("compose", script.compose, LanderJob.Compose({ job })),74 land: (job) => answer("land", script.land, LanderJob.Land({ job })),75 merge: (job) => answer("merge", script.merge, LanderJob.Merge({ job })),76 });7778 return Object.assign(layer, { jobs: Effect.sync(() => [...jobs]) });79 },80};