import { JsonSchemaResult, JsonSchemaTarget } from "../standard-schema/json-schema.mjs"; import { SchemaContext } from "../types/context-types.mjs"; import { ValidationResult } from "../types/result-types.mjs"; import { BaseValidator } from "./base-validator.mjs"; //#region ../@warlock.js/seal/src/validators/lazy-validator.d.ts /** * Lazy validator — defers resolution of the inner validator until validate-time. * * Solves the chicken-and-egg of self-referencing schemas. JavaScript evaluates * an object literal before the `const` binding completes, so this can't work: * * ```ts * const categorySchema = v.object({ * name: v.string(), * children: v.array(categorySchema), // ❌ ReferenceError * }); * ``` * * Wrap the recursive reference in `v.lazy(() => …)` — the thunk isn't invoked * during construction, only when `validate()` is called: * * ```ts * type Category = { name: string; children: Category[] }; * * const categorySchema: ObjectValidator<...> = v.object({ * name: v.string(), * children: v.array(v.lazy(() => categorySchema)), * }); * * type T = Infer; * // { name: string; children: T[] } ← recursive type * ``` * * The thunk is memoized — it's invoked once on the first validate (or * `matchesType` / `toJsonSchema`) call and the result is cached. The thunk is * expected to return a stable validator; calling it on every validate would be * wasteful and could mask bugs where the user accidentally returns a fresh * validator each time. * * **JSON Schema caveat.** v1 uses simple resolve-and-delegate — recursive * schemas will infinite-loop in `toJsonSchema()`. If you need JSON Schema for * a recursive shape, generate it manually with `$defs` + `$ref` until v2 lands. * * @see `domains/seal/plans/2026-05-12-lazy-validator.md` */ declare class LazyValidator extends BaseValidator { private thunk; private resolvedValidator; constructor(thunk: () => T); /** * Resolve the inner validator. Memoizes the result so subsequent calls * don't re-execute the thunk. */ private resolve; validate(data: any, context: SchemaContext): Promise; matchesType(value: any): boolean; clone(): this; /** * JSON Schema generation — simple resolve-and-delegate. * * **Recursive schemas will infinite-loop.** Until v2 adds `$ref` + `$defs` * generation, callers needing JSON Schema for recursive shapes must build * the schema manually. */ toJsonSchema(target?: JsonSchemaTarget): JsonSchemaResult; } //#endregion export { LazyValidator }; //# sourceMappingURL=lazy-validator.d.mts.map