env-port.ts
This file
Path
packages/project/src/env-port.ts
106 lines · 3.4 KiB · TypeScript
Last changed by
Merge build/comments-project into mainoscabrielbefore adoption49efd2a
History of this fileTake 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–14why, one step back1import { CheckJob } from "@repo/checks/check-runner";2import type { EnvSchemaView } from "@repo/protocol/domain/env";3import { RepoPath, sameHandle } from "@repo/protocol/ids";4import type { EnvKey, Handle, LandedSha } from "@repo/protocol/ids";5import type { Person } from "@repo/protocol/principal";6import { NotDecider, UnknownEnvItem } from "@repo/protocol/refusal";7import type { NotSensitive, ValueTooShort } from "@repo/protocol/refusal";8import { Context, Effect, Layer, Option, Schema, Struct } from "effect";9import type { DateTime, Redacted } from "effect";1011import type { ProjectSnapshot, ProjectWrites } from "./project-store.ts";12import { noPlan, policyIn } from "./visibility-port.ts";13import type { VisibilityPlan } from "./visibility-port.ts";14Merge build/comments-project into mainoscabrielbefore adoption49efd2a
line 15why, one step back15/** Never holds a value, so it may be stored and cross a Workflow step. */Give checks the env as 611's job carries it, open values for landed runs, and parse env schemas in the Workeroscabrielbefore adoption234865c
line 16why, one step back16export const UnlandedRunEnv = Schema.Struct(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 17–19why, one step back17 Struct.pick(CheckJob.fields, ["placeholders", "proxies"])18);19Give checks the env as 611's job carries it, open values for landed runs, and parse env schemas in the Workeroscabrielbefore adoption234865c
lines 20–21why, one step back20export type UnlandedRunEnv = typeof UnlandedRunEnv.Type;21Merge build/comments-project into mainoscabrielbefore adoption49efd2a
line 22why, one step back22/** Holds opened values for landed code: never stored, never in a Workflow step's output. */Give checks the env as 611's job carries it, open values for landed runs, and parse env schemas in the Workeroscabrielbefore adoption234865c
lines 23–26why, one step back23export const RunEnv = Schema.Struct(24 Struct.pick(CheckJob.fields, ["landed", "placeholders", "proxies", "values"])25);26Merge 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 27–28why, one step back27export type RunEnv = typeof RunEnv.Type;28Give checks the env as 611's job carries it, open values for landed runs, and parse env schemas in the Workeroscabrielbefore adoption234865c
line 29why, one step back29export const noRunEnv: UnlandedRunEnv = { placeholders: [], proxies: [] };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 30–106why, one step back3031export type EnvSchemaFile = Omit<EnvSchemaView, "at" | "project">;3233const envFile = RepoPath.make(".env.schema");3435export interface ValueSet {36 readonly result: {37 readonly key: EnvKey;38 readonly setAt: DateTime.Utc;39 readonly setBy: Handle;40 };41 readonly writes: ProjectWrites;42}4344export type Scanned = { readonly text: string } | { readonly blob: Uint8Array };4546export interface EnvPort {47 readonly view: (48 at: LandedSha,49 snapshot: ProjectSnapshot50 ) => Effect.Effect<EnvSchemaFile>;51 readonly set: (52 input: {53 readonly acknowledgeShort: boolean;54 readonly by: Person;55 readonly key: EnvKey;56 readonly now: DateTime.Utc;57 readonly value: Redacted.Redacted;58 },59 snapshot: ProjectSnapshot60 ) => Effect.Effect<61 ValueSet,62 NotDecider | UnknownEnvItem | NotSensitive | ValueTooShort63 >;64 readonly runEnv: (65 input: { readonly landed: boolean },66 snapshot: ProjectSnapshot67 ) => Effect.Effect<RunEnv>;68 readonly scan: (69 scanned: Scanned,70 snapshot: ProjectSnapshot71 ) => Effect.Effect<Option.Option<EnvKey>>;72 readonly onLanded: (73 input: {74 readonly after: LandedSha;75 readonly before: Option.Option<LandedSha>;76 readonly now: DateTime.Utc;77 },78 snapshot: ProjectSnapshot79 ) => Effect.Effect<VisibilityPlan>;80}8182const decides = (snapshot: ProjectSnapshot, handle: Handle) =>83 Option.exists(policyIn(snapshot), (policy) =>84 policy.deciders.some(({ handles }) =>85 handles.some((each) => sameHandle(each, handle))86 )87 );8889export const noEnv: EnvPort = {90 onLanded: () => Effect.succeed(noPlan),91 runEnv: () => Effect.succeed(noRunEnv),92 scan: () => Effect.succeedNone,93 set: ({ by, key }, snapshot) =>94 Effect.fail(95 decides(snapshot, by.handle)96 ? new UnknownEnvItem({ key })97 : new NotDecider({})98 ),99 view: () => Effect.succeed({ file: envFile, imports: [], items: [] }),100};101102export const ProjectEnv = Context.Reference<EnvPort>("project/ProjectEnv", {103 defaultValue: () => noEnv,104});105106export const NoEnv: Layer.Layer<never> = Layer.succeed(ProjectEnv, noEnv);