/** * Hostile-input parsing for workflow revision manifests. * * A manifest arrives from a source this module does not control — persisted * storage read by an older or differently-configured build, a wire payload, * an operator-supplied fixture. Every field is proven from `unknown` rather * than asserted, every open-ended collection is bounded before it is walked, * and `contractHash` is always recomputed and compared rather than trusted * as supplied — a caller cannot assert a hash it did not earn. * * @module core/contract/manifest-parse */ import { type WorkflowRevisionManifestValidationFailure } from './failure.ts'; import type { WorkflowRevisionManifest } from './types.ts'; /** * A successfully validated manifest, paired with the canonical serialization * of its (normalized) contract, so a caller does not have to re-derive it. * * @example * ```ts * import { * buildWorkflowContract, * buildWorkflowRevisionManifest, * parseWorkflowRevisionManifest, * type WorkflowRevisionManifestParseSuccess, * } from '@lostgradient/weft'; * * const manifest = await buildWorkflowRevisionManifest(buildWorkflowContract({ name: 'checkout' })); * const result = await parseWorkflowRevisionManifest(manifest); * if (result.ok) { * const accepted: WorkflowRevisionManifestParseSuccess = result; * console.log(accepted.canonicalJson.length > 0); * } * ``` */ export type WorkflowRevisionManifestParseSuccess = Readonly<{ ok: true; /** The validated, normalized manifest. */ manifest: WorkflowRevisionManifest; /** Canonical serialization of `manifest.contract` — `canonicalWorkflowContractJson(manifest.contract)`. */ canonicalJson: string; }>; /** * Outcome of validating an untrusted workflow revision manifest. * * @example * ```ts * import { parseWorkflowRevisionManifest, type WorkflowRevisionManifestParseResult } from '@lostgradient/weft'; * * const result: WorkflowRevisionManifestParseResult = await parseWorkflowRevisionManifest({}); * console.log(result.ok); * ``` */ export type WorkflowRevisionManifestParseResult = WorkflowRevisionManifestParseSuccess | WorkflowRevisionManifestValidationFailure; /** * Validate an untrusted workflow revision manifest. * * The returned manifest is already normalized, `contractHash` is always * recomputed from the (normalized) contract and compared against the * supplied value — a mismatch is rejected with `'contract-hash-mismatch'` * regardless of what the caller asserted — and `manifest.name`/ * `manifest.workflowVersion` must agree with `manifest.contract.name`/ * `manifest.contract.workflowVersion`. `revision` is validated (bounded, * non-empty) but never recomputed: it is an opaque label the parser trusts * once it is well-formed. * * @example * ```ts * import { buildWorkflowContract, buildWorkflowRevisionManifest, parseWorkflowRevisionManifest } from '@lostgradient/weft'; * * const manifest = await buildWorkflowRevisionManifest(buildWorkflowContract({ name: 'checkout' })); * const result = await parseWorkflowRevisionManifest(manifest); * console.log(result.ok ? result.manifest.name : result.reason); * ``` */ export declare function parseWorkflowRevisionManifest(value: unknown): Promise;