/** * Hostile-input parsing for worker manifests. * * Everything here treats its input as adversarial: a manifest arrives from a * worker process the host does not control, and it decides whether that worker * becomes routing-eligible. Every field is proven from `unknown` rather than * asserted, every open-ended collection is bounded before it is walked, and * the normalized size is checked against the canonical form so a compact * payload cannot expand past the ceiling after normalization. * * @module worker/manifest/parse */ import { type ManifestValidationFailure } from './failure.ts'; import type { WorkerManifest } from './types.ts'; /** * A successfully validated manifest, paired with the canonical serialization * the digest is computed over so callers do not serialize it a second time. * * @example * ```ts * import { * digestCanonicalWorkerManifest, * parseWorkerManifest, * type WorkerManifestParseSuccess, * } from '@lostgradient/weft'; * * const result = parseWorkerManifest({ * manifestVersion: 1, * protocolVersion: 2, * sdkVersion: '0.18.0', * runtime: { name: 'bun', version: '1.3.14' }, * deployment: { name: 'billing', buildId: 'b3', artifactDigest: 'sha256:41d0' }, * workflows: {}, * capabilities: {}, * }); * * if (result.ok) { * const accepted: WorkerManifestParseSuccess = result; * console.log(await digestCanonicalWorkerManifest(accepted.canonicalJson)); * } * ``` */ export type WorkerManifestParseSuccess = Readonly<{ ok: true; /** The normalized manifest, with every open-ended record key sorted. */ manifest: WorkerManifest; /** Canonical serialization of that manifest — the digest input. */ canonicalJson: string; }>; /** * Outcome of validating an untrusted manifest. * * @example * ```ts * import { parseWorkerManifest, type WorkerManifestParseResult } from '@lostgradient/weft'; * * const result: WorkerManifestParseResult = parseWorkerManifest({}); * console.log(result.ok); * ``` */ export type WorkerManifestParseResult = WorkerManifestParseSuccess | ManifestValidationFailure; /** * Validate an untrusted worker manifest. * * The returned manifest is already normalized, so a caller that stores or * digests the result never has to re-derive canonical form. Rejection is a * value, not an exception — a bad manifest is an ordinary wire condition. * * @example * ```ts * import { parseWorkerManifest } from '@lostgradient/weft'; * * const result = parseWorkerManifest({ * manifestVersion: 1, * protocolVersion: 2, * sdkVersion: '0.18.0', * runtime: { name: 'bun', version: '1.3.14' }, * deployment: { name: 'billing', buildId: 'b3', artifactDigest: 'sha256:41d0' }, * workflows: {}, * capabilities: {}, * }); * * console.log(result.ok ? result.manifest.deployment.name : result.reason); * ``` */ export declare function parseWorkerManifest(value: unknown): WorkerManifestParseResult;