held-back.ts
This file
Path
apps/platform/src/visibility/held-back.ts
136 lines · 4.4 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/comments-platform into mainoscabrielbefore adoptionddf09e8
lines 1–3why, one step back1// Refusals and logs here never name a layer's paths or content: exact colliding paths2// only when everyone accountable reads every layer, and blob comparison only for layers3// the answerer or a finisher reads.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 4–9why, one step back4import type { Fetch } from "@repo/artifacts/fetch";5import { ObjectId, RefName } from "@repo/artifacts/repo-host";6import type { RepoHost, RepoNotFound } from "@repo/artifacts/repo-host";7import type { ProjectApi } from "@repo/project/project";8import { Projects } from "@repo/project/projects";9import type { Layer as LayerDeclaration } from "@repo/protocol/domain/visibility";Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
lines 10–11why, one step back10import { BlobSha, keyOf, RepoName, RepoPath } from "@repo/protocol/ids";11import type { Handle, 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 12–23why, one step back12import { Anonymous, Person } from "@repo/protocol/principal";13import { privatePaths, writeDown } from "@repo/visibility/guards";14import { LayerRepos } from "@repo/visibility/layer-repos";15import { Effect, Layer, Option } from "effect";1617import type { PlatformConfig } from "../platform.ts";18import { LandingGuards } from "../workflows/answer/guards.ts";19import type { GuardInput } from "../workflows/answer/guards.ts";20import { layerRepos } from "./layer-repos.ts";2122const mainRef = RefName.make("refs/heads/main");23Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
lines 24–25why, one step back24const repoOf = (project: ProjectName, layer: LayerDeclaration) =>25 layer.repo ?? RepoName.make(`${keyOf(project)}--${layer.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 26–136why, one step back2627const blobsUnder = (28 host: RepoHost["Service"],29 repo: RepoName,30 tree: string31): Effect.Effect<readonly BlobSha[], RepoNotFound> =>32 Effect.flatMap(host.readTree(repo, ObjectId.make(tree)), (entries) =>33 Effect.map(34 Effect.forEach(35 Option.getOrElse(entries, () => []),36 (entry) =>37 entry.type === "tree"38 ? blobsUnder(host, repo, entry.sha)39 : Effect.succeed(40 entry.type === "blob" ? [BlobSha.make(entry.sha)] : []41 )42 ),43 (nested) => nested.flat()44 )45 );4647const layerBlobs = (host: RepoHost["Service"], repo: RepoName) =>48 Effect.gen(function* () {49 const tip = (yield* host.refs(repo)).get(mainRef);5051 if (tip === undefined) {52 return [];53 }5455 const commit = yield* host.readCommit(repo, tip);5657 return Option.isNone(commit)58 ? []59 : yield* blobsUnder(host, repo, commit.value.tree);60 }).pipe(Effect.catchTag("RepoNotFound", () => Effect.succeed([])));6162const reads = (api: ProjectApi, handle: Handle, layer: LayerDeclaration) =>63 Effect.map(64 api.layerAccess(Person.make({ handle }), layer.name),65 (access) => Option.isSome(access) && access.value !== "none"66 );6768const guardsOver =69 (repos: RepoHost["Service"], projects: Projects["Service"]) =>70 (input: GuardInput) =>71 Effect.gen(function* () {72 const api = yield* projects.get(input.project).pipe(Effect.orDie);73 const people = [input.answerer, ...input.finishers];7475 const { layers } = yield* api76 .ledger(Anonymous.make({}))77 .pipe(Effect.orDie);7879 const facts = yield* api.layerFacts(80 Person.make({ handle: input.answerer })81 );8283 const access = yield* Effect.forEach(layers, (layer) =>84 Effect.map(85 Effect.forEach(people, (handle) => reads(api, handle, layer)),86 (each) => ({ each, layer })87 )88 );8990 const readable = access.filter(({ each }) => each.some(Boolean));9192 const readsAll =93 access.length > 0 && access.every(({ each }) => each.every(Boolean));9495 const blobs = yield* Effect.forEach(readable, ({ layer }) =>96 layerBlobs(repos, repoOf(input.project, layer))97 );9899 return [100 ...Option.toArray(101 privatePaths({102 changes: input.changes,103 layerPaths: new Set(104 facts.layerPaths.map((path) => RepoPath.make(path))105 ),106 pusherCanRead: readsAll,107 })108 ),109 ...Option.toArray(110 writeDown({111 changes: input.changes,112 layerBlobs: new Set(blobs.flat()),113 readerCanReadLayer: readable.length > 0,114 })115 ),116 ];117 });118119export const LandingGuardsLive: Layer.Layer<120 never,121 never,122 LayerRepos | Projects123> = Layer.effect(124 LandingGuards,125 Effect.gen(function* () {126 const repos = yield* LayerRepos;127 const projects = yield* Projects;128129 return Option.some({ check: guardsOver(repos, projects) });130 })131);132133export const heldBackLive = (134 config: PlatformConfig135): Layer.Layer<never, never, Fetch | Projects> =>136 LandingGuardsLive.pipe(Layer.provide(layerRepos(config)));