/** * Field-level guards shared by the durable application primitives (the * command mailbox, WFT-84, and the delivery outbox, WFT-85): identity * components, durable JSON metadata, injected clock readings, generated * identifiers, derived instants, and wait budgets. * * Every guard rejects at the boundary that owns the contract rather than letting * a bad value reach durable storage — a record the decoder cannot read back * would surface much later as corruption on an unrelated read. * * The guards are produced by a factory bound to the primitive's own validation * error class, so a mailbox caller sees `ApplicationCommandValidationError` and * an outbox caller sees its own, while the checks themselves are written once. * * @module core/application-primitive-guards */ import { type JSONValue } from './json.ts'; /** Maximum bytes in any opaque identity component (namespace, resource, owner, caller, target, kind). */ export declare const MAX_APPLICATION_IDENTITY_BYTES = 256; /** Maximum encoded bytes for durable JSON metadata such as an outcome, progress, or failure details. */ export declare const MAX_DURABLE_METADATA_BYTES = 65536; /** * The largest delay `setTimeout` schedules faithfully (a signed 32-bit * millisecond count). A larger value is clamped to a tick by the runtime, which * would turn a rare poll into a tight loop against durable storage. */ export declare const MAX_TIMER_DELAY_MS = 2147483647; /** Default gap between durable polls for the bounded waits. */ export declare const DEFAULT_WAIT_POLL_INTERVAL_MS = 50; /** The UTF-8 length of a string. */ export declare function byteLengthOf(value: string): number; /** Whether a string contains no unpaired surrogate. */ export declare function isWellFormedString(value: string): boolean; /** A validation error class a primitive binds its guards to. */ export type ApplicationValidationErrorClass = new (message: string, options?: ErrorOptions) => Error; /** The guard set produced by {@link createApplicationGuards}. */ export type ApplicationGuards = { readonly requireIdentity: (value: unknown, field: string, maxBytes: number) => string; readonly optionalIdentityOf: (value: unknown, field: string, maxBytes: number) => string | undefined; readonly requirePositiveInteger: (value: unknown, field: string, maximum: number) => number; readonly requireNonNegativeInteger: (value: unknown, field: string, maximum: number) => number; readonly validateDurableJSONValue: (value: unknown, field: string) => JSONValue | undefined; readonly requireGeneratedIdentifier: (value: string, field: string) => string; readonly requireClockInstant: (now: number, source?: string) => number; readonly requireDerivedInstant: (instant: number, field: string) => number; readonly requireMaintenanceInstant: (now: number) => number; readonly requireWaitBudget: (options: { readonly timeoutMs?: number | undefined; readonly pollIntervalMs?: number | undefined; }) => { readonly timeoutMs: number; readonly pollIntervalMs: number; }; }; /** * Bind the shared guards to one primitive's validation error class. * * Every guard throws an instance of `ValidationError`, so callers and tests of * the mailbox keep matching `ApplicationCommandValidationError` while the * outbox matches its own class. */ export declare function createApplicationGuards(ValidationError: ApplicationValidationErrorClass): ApplicationGuards;