/** * Type guards and encode/decode for the durable remote task ledger (WFT-25). * * Every stored or wire-derived field is proven from `unknown` — the project * brief's Security section requires operation IDs, workflow IDs, names, * queues, header counts, header bytes, retry fields, and payload sizes to be * bounded before a storage write, and `input`/`headers` are treated as * hostile the same way `worker/manifest/parse.ts` treats manifest content. * * Guards here intentionally check only the fields that are load-bearing for * correctness and the fields the brief calls out for bounding — matching the * existing `isQueuedRecord`/`isInflightRecord` style in `task-state.ts` * rather than re-deriving every field's shape from the type system. * * @module server/task-ledger-codec */ import type { RemoteTaskCancelling, RemoteTaskCompleting, RemoteTaskDeadLettered, RemoteTaskLeased, RemoteTaskQueued, RemoteTaskRecord, RemoteTaskTerminal, RemoteTaskTerminalCancelled, RemoteTaskTerminalResolved, RemoteTaskTerminalRetryExhausted } from './task-ledger-types.ts'; /** * Whether `value` is a valid `workflowRevision` per the durable task * ledger's non-empty, bounded identifier contract — the same contract * `decodeRemoteTaskRecord` enforces on read. Exported so dispatch-time * callers (`task-dispatch.ts`) can reject an invalid caller-supplied * revision before it reaches a ledger write, instead of writing a record * that later fails to decode. */ export declare function isValidWorkflowRevision(value: unknown): value is string; /** * Whether `value` is a valid caller-facing task `operationId` — a non-empty, * bounded identifier per the ledger's own contract, and not the exact string * `.` or `..` (WFT-95). WHATWG URL path normalization collapses `.`/`..` * path segments (and their percent-encoded forms) before `handleRequest()` * ever sees `url.pathname`, so a REST route with a single trailing * `:operationId` segment (e.g. `weft.tasks.get`'s * `/v1/tasks/detail/:operationId`) can never address a record whose * operationId is literally `.` or `..`. Exported so fresh-dispatch admission * (`task-dispatch.ts`'s `dispatchTaskImpl`) can reject an invalid * caller-supplied `operationId` before it ever reaches a ledger write, * closing that URL-normalization quirk as an enforced admission-time * guarantee instead of an assumption. Deliberately NOT applied when * redispatching an already-decoded, previously persisted ledger record — * see `dispatchTaskImpl`'s `redispatch` option — since such an id was valid * under the pre-WFT-95 decode contract and may already be durably * persisted. Does not reject an id that merely contains a dot character. */ export declare function isValidOperationId(value: unknown): value is string; /** Bounded header map: at most {@link MAX_TASK_HEADER_COUNT} entries, each key/value at most {@link MAX_TASK_HEADER_VALUE_BYTES}. */ export declare function isValidTaskHeaders(value: unknown): value is Readonly>; export declare function isRemoteTaskQueued(value: unknown): value is RemoteTaskQueued; export declare function isRemoteTaskLeased(value: unknown): value is RemoteTaskLeased; export declare function isRemoteTaskCompleting(value: unknown): value is RemoteTaskCompleting; export declare function isRemoteTaskCancelling(value: unknown): value is RemoteTaskCancelling; export declare function isRemoteTaskTerminalResolved(value: unknown): value is RemoteTaskTerminalResolved; export declare function isRemoteTaskTerminalCancelled(value: unknown): value is RemoteTaskTerminalCancelled; export declare function isRemoteTaskTerminalRetryExhausted(value: unknown): value is RemoteTaskTerminalRetryExhausted; export declare function isRemoteTaskTerminal(value: unknown): value is RemoteTaskTerminal; export declare function isRemoteTaskDeadLettered(value: unknown): value is RemoteTaskDeadLettered; /** Discriminate and validate a decoded value as any {@link RemoteTaskRecord} state. */ export declare function isRemoteTaskRecord(value: unknown): value is RemoteTaskRecord; /** Canonical encoding for a validated {@link RemoteTaskRecord}. */ export declare function encodeRemoteTaskRecord(record: RemoteTaskRecord): Uint8Array; /** * Decode and validate a task ledger record. Returns `null` when the bytes are * absent or decode to a value that fails bounds validation. This does not * catch `decode()` throwing on bytes that are not valid MessagePack; storage * bytes are always ones this codebase wrote, so byte-level corruption is * treated as a storage integrity failure worth surfacing, not swallowing. */ export declare function decodeRemoteTaskRecord(bytes: Uint8Array | null): RemoteTaskRecord | null;