Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
1.2 kB · 34 lines
TypeScript
1234567891011121314151617181920212223242526272829303132333435import * as Effect from "effect/Effect";import entries from "../dist/catalog/catalog.ts";import type { Artifact } from "./artifact-types.ts";import { loadArtifact } from "./artifact.ts";import { ArtifactUnavailable } from "./deployment-errors.ts";import { sameRelease, type ReleaseIdentity } from "./installation-metadata.ts";
export type ArtifactLoader = ( pinned?: ReleaseIdentity,) => Effect.Effect<Artifact, ArtifactUnavailable>;
// Cache only successfully verified immutable artifacts, never a running fiber or// rejected Promise owned by another request's lifetime.const validated = new Map<string, Artifact>();export function customerArtifact( pinned?: ReleaseIdentity, development = false,) { return Effect.gen(function* () { const entry = entries.at(-1); if ( entries.length !== 1 || !entry || (pinned && !sameRelease(entry.identity, pinned)) ) return yield* new ArtifactUnavailable(); const key = entry.identity.artifactDigest + ":" + development; const cached = validated.get(key); if (cached) return cached; const artifact = yield* loadArtifact(entry, pinned, development); validated.set(key, artifact); return artifact; });}