import { z } from "zod"; import type { ResultValue } from "./result.js"; import { AgencyFunction } from "./agencyFunction.js"; /** * Async validator used by `@validate(...)` chains. May be: * - a plain async function `(value) => Result` (the simplest shape; * users can import `success` / `failure` from the agency-lang runtime * and return whichever applies); * - an `AgencyFunction` (an Agency `def` referenced by name), which is * invoked via `.invoke({ type: "positional", args: [value] })` so we * go through the same call infrastructure as `__call(...)`. * * Validators that need access to the execution context read it from the * active `agencyStore` ALS frame via `getRuntimeContext()`. There is no * `ctx` arg to thread through. */ export type AgencyValidator = ((value: unknown) => Promise | ResultValue) | AgencyFunction; /** * Run Zod parse then thread the result through validators in order, * stopping on the first failure. Validators may transform: the value * passed to validator N+1 is whatever validator N returned with success. * * Why outside Zod? See spec ยง "Why run validators outside Zod" โ€” * keeping validators out of the sync Zod path lets them be async, * call other Agency functions, hit the network, etc. */ export declare function __validateChain(value: unknown, schema: z.ZodType, validators: AgencyValidator[]): Promise; /** * Structural descriptor for nested validation. Built at codegen time * from the resolved type tree. The walker uses this descriptor to know * which validator list to apply at each depth and how to dispatch * unions / arrays / objects / nullables. */ export type TypeValidationDescriptor = { kind: "leaf"; schema: z.ZodType; validators: AgencyValidator[]; } | { kind: "object"; schema: z.ZodType; validators: AgencyValidator[]; properties: Record; } | { kind: "array"; schema: z.ZodType; validators: AgencyValidator[]; element: TypeValidationDescriptor; } | { /** * A Record: every entry value walks the same `value` descriptor * (#630 โ€” this is how alias-carried validators on the value type run). * KEYS are schema-checked only: running validators on keys would mean * rewriting keys when a validator transforms, which needs its own * design. Documented in the guide. */ kind: "record"; schema: z.ZodType; validators: AgencyValidator[]; value: TypeValidationDescriptor; } | { kind: "union"; schema: z.ZodType; validators: AgencyValidator[]; branches: Array<{ test: (v: unknown) => boolean; descriptor: TypeValidationDescriptor; }>; } | { kind: "nullable"; schema: z.ZodType; validators: AgencyValidator[]; inner: TypeValidationDescriptor; } | { kind: "ref"; /** * Deferred descriptor read. Emitted for alias references whose * target descriptor is not initialized yet at module load (forward * refs) or is the descriptor currently being built (self-recursion). * Resolved at walk time, when every __agency_descriptor exists. * Dispatched BEFORE the own-validator step: a ref carries no schema * or validators of its own โ€” use-site validators are merged onto * the resolved descriptor inside get() at emission time. */ get: () => TypeValidationDescriptor; }; export type RecursiveValidationOpts = { /** Hard cap on traversal depth. Default 64. */ maxDepth?: number; }; /** * Walk `value` alongside `descriptor`, running per-node validator chains * and recursing into nested types. Bails with a failure once depth * exceeds `opts.maxDepth ?? 64`. */ export declare function __validateChainRecursive(value: unknown, descriptor: TypeValidationDescriptor, opts?: RecursiveValidationOpts): Promise;