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/computed-validator.d.ts /** * Callback function for computed fields * Receives validated & mutated data and full schema context */ type ComputedCallback = (data: any, context: SchemaContext) => TResult | Promise; /** * Computed field validator * * Computes a value based on other validated fields in the schema. * The computed value is persisted and can optionally be validated. * * @example * ```ts * // Basic computed field * const schema = v.object({ * title: v.string().required(), * slug: v.computed(data => slugify(data.title)), * }); * * // With result validation * const schema = v.object({ * title: v.string().required(), * slug: v.computed( * data => slugify(data.title), * v.string().minLength(3) * ), * }); * * // Async computation * const schema = v.object({ * image: v.string().url(), * thumbnail: v.computed(async data => { * return await generateThumbnail(data.image); * }), * }); * ``` */ declare class ComputedValidator extends BaseValidator { protected callback: ComputedCallback; protected resultValidator?: BaseValidator | undefined; /** * Create a new computed field validator * * @param callback - Function to compute the value from validated data * @param resultValidator - Optional validator to validate the computed result */ constructor(callback: ComputedCallback, resultValidator?: BaseValidator | undefined); /** * Execute the callback and optionally validate the result */ validate(data: any, context: SchemaContext): Promise; /** * Clone this validator with all its configuration * Critical for ObjectValidator.clone(), extend(), merge(), etc. */ clone(): this; /** * Computed fields don't have a specific type to match */ matchesType(value: any): boolean; /** * @inheritdoc * * Computed fields are server-side runtime values — they have no input schema * and cannot be represented in JSON Schema. Calling this method is always a * programming error. * * @throws Error Always throws — computed/managed fields have no JSON Schema representation. */ toJsonSchema(_target?: JsonSchemaTarget): JsonSchemaResult; } //#endregion export { ComputedCallback, ComputedValidator }; //# sourceMappingURL=computed-validator.d.mts.map