{"version":3,"file":"base-validator.mjs","names":["defaultRequiredRule"],"sources":["../../../../../../../@warlock.js/seal/src/validators/base-validator.ts"],"sourcesContent":["import { clone } from \"@mongez/reinforcements\";\nimport { validate } from \"../factory/validate\";\nimport { VALID_RULE, invalidRule } from \"../helpers\";\nimport { isEmptyValue } from \"../helpers/is-empty-value\";\nimport { requiredRule as defaultRequiredRule } from \"../rules/core/required\";\nimport type { JsonSchemaResult, JsonSchemaTarget } from \"../standard-schema/json-schema\";\nimport { mapToStandardResult } from \"../standard-schema/map-result\";\nimport type { StandardJSONSchemaV1, StandardSchemaV1 } from \"../standard-schema/types\";\nimport type {\n  ContextualSchemaRule,\n  ContextualizedMutator,\n  ContextualizedTransformer,\n  Mutator,\n  SchemaContext,\n  SchemaRule,\n  SchemaRuleOptions,\n  SimpleTransformerCallback,\n  TransformerCallback,\n  ValidationAttributesList,\n  ValidationResult,\n} from \"../types\";\n\n/**\n * Base validator class - foundation for all validators\n */\nexport class BaseValidator<TInput = unknown, TOutput = TInput> {\n  public rules: ContextualSchemaRule[] = [];\n  public mutators: ContextualizedMutator[] = [];\n  protected defaultValue: any | (() => any);\n  protected description?: string;\n  protected shouldOmit = false;\n  protected isNullable = false;\n  protected isMutable = false;\n\n  /**\n   * Catch state — when `hasCatch` is true and validation fails, `catchValue`\n   * (or its callback result) substitutes for the failed value, and the public\n   * result reports `isValid: true` with no errors.\n   *\n   * See `.catch()` for semantics and the v1 scope (leaf-only).\n   */\n  protected catchValue:\n    | any\n    | ((errors: ValidationResult[\"errors\"], originalInput: any) => any | Promise<any>);\n  protected hasCatch = false;\n\n  /**\n   * Whether the field is optional.\n   * - false (default): field is required unless a requiredRule governs the condition.\n   * - true: field can be absent or empty — set by calling .optional().\n   *\n   * Also used as a TypeScript literal brand via the optional() return type.\n   */\n  public isOptional = false;\n\n  /**\n   * The single required-condition rule for this field.\n   * - null: field uses strict default (always required when not optional).\n   * - set: the rule governs when the field is required (e.g., requiredIf).\n   *\n   * Stored separately from rules[] and prepended at validate() time.\n   */\n  public requiredRule: ContextualSchemaRule | null = this.createRule(defaultRequiredRule);\n\n  /**\n   * Pipeline to transform the mutated/original data before returning it\n   */\n  protected dataTransformers: ContextualizedTransformer[] = [];\n\n  /**\n   * Attributes text to be replaced on translations\n   * If the value is an object, it will be used as the attributes list for the rule\n   * If the value is a string, it will be used as the attributes list for the rule\n   */\n  protected attributesText: ValidationAttributesList = {};\n\n  /**\n   * Attributed that will be always using the attribute translator\n   */\n  protected translatedAttributes: Record<string, string> = {};\n\n  /**\n   * Mark the validator as mutable\n   */\n  public get mutable() {\n    this.isMutable = true;\n    return this;\n  }\n\n  /**\n   * Mark the validator as immutable\n   */\n  public get immutable() {\n    this.isMutable = false;\n    return this;\n  }\n\n  /**\n   * Get the instance to apply changes to.\n   * By default (immutable), returns a clone so the original is unchanged.\n   * When `.mutable` is set, returns `this` to mutate in place.\n   */\n  protected get instance(): this {\n    return this.isMutable ? this : this.clone();\n  }\n\n  /**\n   * Get the default value\n   * Supports lazy evaluation via callbacks\n   */\n  public getDefaultValue(): any {\n    return typeof this.defaultValue === \"function\" ? this.defaultValue() : this.defaultValue;\n  }\n\n  /**\n   * Allow null as a valid value.\n   *\n   * Brands the return type with `{ isNullable: true }` so `Infer<>` widens\n   * the inferred output to include `| null`.\n   */\n  public nullable(): this & { isNullable: true } {\n    const instance = this.instance;\n    instance.isNullable = true;\n    return instance as this & { isNullable: true };\n  }\n\n  /**\n   * Explicitly disallow null values after calling nullable.\n   *\n   * Brands the return type with `{ isNullable: false }` to cancel any prior\n   * `.nullable()` at the type level.\n   */\n  public notNullable(): this & { isNullable: false } {\n    const instance = this.instance;\n    instance.isNullable = false;\n    return instance as this & { isNullable: false };\n  }\n\n  /**\n   * Add transformer with optional options\n   *\n   * @param transform - The transformer callback function\n   * @param options - Optional options to pass to the transformer\n   *\n   * @example\n   * ```ts\n   * // Without options\n   * v.date().addTransformer(data => data.toISOString())\n   *\n   * // With options\n   * v.date().addTransformer(\n   *   (data, { options }) => dayjs(data).format(options.format),\n   *   { format: 'YYYY-MM-DD' }\n   * )\n   * ```\n   */\n  public addTransformer(transform: TransformerCallback, options: any = {}) {\n    const instance = this.instance;\n    instance.addMutableTransformer(transform, options);\n\n    return instance;\n  }\n\n  /**\n   * Add transformer with optional options\n   *\n   * @param transform - The transformer callback function\n   * @param options - Optional options to pass to the transformer\n   *\n   * @example\n   * ```ts\n   * // Without options\n   * v.date().addTransformer(data => data.toISOString())\n   *\n   * // With options\n   * v.date().addTransformer(\n   *   (data, { options }) => dayjs(data).format(options.format),\n   *   { format: 'YYYY-MM-DD' }\n   * )\n   * ```\n   */\n  public addMutableTransformer(transform: TransformerCallback, options: any = {}) {\n    this.dataTransformers.push({\n      transform,\n      options,\n    });\n  }\n\n  /**\n   * Transform the output value - simple one-time transformation\n   *\n   * @param callback - Simple callback receiving data and context\n   *\n   * @example\n   * ```ts\n   * // Simple transformation\n   * v.string().outputAs(data => data.toUpperCase())\n   *\n   * // With context\n   * v.string().outputAs((data, context) => {\n   *   console.log(`Transforming ${context.path}`);\n   *   return data.toLowerCase();\n   * })\n   * ```\n   */\n  public outputAs(callback: SimpleTransformerCallback) {\n    return this.addTransformer((data, { context }) => callback(data, context));\n  }\n\n  /**\n   * Transform output to JSON string\n   *\n   * Works with any validator type (string, number, date, object, array, etc.)\n   *\n   * @param indent - Optional indentation for pretty printing (default: 0 for compact)\n   *\n   * @example\n   * ```ts\n   * // Compact JSON\n   * v.object({ name: v.string() }).toJSON()\n   * // Output: '{\"name\":\"John\"}'\n   *\n   * // Pretty-printed JSON\n   * v.array(v.object({...})).toJSON(2)\n   * // Output:\n   * // [\n   * //   {\n   * //     \"name\": \"John\"\n   * //   }\n   * // ]\n   *\n   * // Works with any type\n   * v.string().toJSON()  // '\"hello\"'\n   * v.number().toJSON()  // '42'\n   * v.date().toJSON()    // '\"2024-10-26T00:00:00.000Z\"'\n   * ```\n   *\n   * @category Transformer\n   */\n  public toJSON(indent?: number) {\n    return this.addTransformer((data, { options }) => JSON.stringify(data, null, options.indent), {\n      indent: indent ?? 0,\n    });\n  }\n\n  /**\n   * Start data transformation pipeline\n   * Context is passed at runtime, not stored\n   */\n  public async startTransformationPipeline(data: any, context: SchemaContext) {\n    for (const transformer of this.dataTransformers) {\n      data = await transformer.transform(data, {\n        options: transformer.options,\n        context,\n      });\n    }\n\n    return data;\n  }\n\n  /**\n   * Set attributes text to be replaced on translations\n   * If the value is an object, it will be used as the attributes list for the rule\n   * If the value is a string, it will be used as the attributes list for the rule\n   *\n   * @example\n   * v.string().attributes({\n   *   name: \"Name\",\n   *   email: \"Email\",\n   * });\n   * // Example 2: Add custom attributes for matches\n   * v.string().matches(\"confirmPassword\").attributes({\n   *   matches: {\n   *     confirmPassword: \"Confirm Password\",\n   *   },\n   * });\n   */\n  public attributes(attributes: Record<string, string | Record<string, string>>) {\n    const instance = this.instance;\n    for (const key in attributes) {\n      instance.attributesText[key] = attributes[key];\n    }\n\n    return instance;\n  }\n\n  /**\n   * Define a lazy getter property for each attribute in the given object and use the config attribute translator\n   */\n  public transAttributes(attributes: Record<string, string>) {\n    const instance = this.instance;\n    for (const key in attributes) {\n      instance.translatedAttributes[key] = attributes[key];\n    }\n\n    return instance;\n  }\n\n  /**\n   * Add description to the validator\n   */\n  public describe(description: string) {\n    const instance = this.instance;\n    instance.description = description;\n    return instance;\n  }\n\n  /**\n   * Check if this validator can handle the given value's type\n   * Override this in specific validators to enable type-based routing in union validators\n   *\n   * Default: returns true (validator will attempt to validate any type)\n   *\n   * @param value - The value to check\n   * @returns True if this validator can handle this type\n   *\n   * @example\n   * ```ts\n   * // StringValidator\n   * public matchesType(value: any): boolean {\n   *   return typeof value === 'string';\n   * }\n   *\n   * // Custom FileValidator\n   * public matchesType(value: any): boolean {\n   *   return value instanceof UploadedFile;\n   * }\n   * ```\n   */\n  public matchesType(_value: any): boolean {\n    return true; // Default: permissive, attempt to validate any type\n  }\n\n  /**\n   * Create a copy of this validator with the same configuration\n   * Copies all rules, mutators, transformers, default values, and settings\n   *\n   * @returns A new validator instance with copied configuration\n   *\n   * @example\n   * ```ts\n   * // Create reusable validator templates\n   * const baseString = v.string().required().trim().min(3);\n   * const emailField = baseString.clone().email();\n   * const usernameField = baseString.clone().alphanumeric().max(20);\n   *\n   * // Works with all validators\n   * const positiveInt = v.int().positive().required();\n   * const ageField = positiveInt.clone().min(18).max(120);\n   * ```\n   */\n  public clone(): this {\n    // Create a new instance using Object.create to preserve the prototype chain\n    const Constructor = this.constructor as new (...args: any[]) => this;\n    const cloned = Object.create(Constructor.prototype);\n\n    // Copy all BaseValidator properties\n    cloned.rules = [...this.rules];\n    cloned.mutators = [...this.mutators];\n    cloned.dataTransformers = [...this.dataTransformers];\n    cloned.defaultValue = this.defaultValue;\n    cloned.shouldOmit = this.shouldOmit;\n    cloned.description = this.description;\n    cloned.attributesText = { ...this.attributesText };\n    cloned.isNullable = this.isNullable;\n    cloned.isOptional = this.isOptional;\n    cloned.requiredRule = this.requiredRule; // same reference is fine — rule is treated as immutable\n    cloned.catchValue = this.catchValue;\n    cloned.hasCatch = this.hasCatch;\n\n    return cloned;\n  }\n\n  /**\n   * @deprecated This method is no longer needed and does nothing.\n   * Empty values are now automatically skipped for validation rules by default.\n   * Only presence validators (required, present, etc.) will check empty values.\n   * You can safely remove this call from your code.\n   */\n  public ignoreEmptyValue(_ignoreEmptyValue = true) {\n    // No-op for backward compatibility\n    return this;\n  }\n\n  /**\n   * Omit this field from the validated data output\n   *\n   * Field will still be validated but not included in the final result.\n   * Useful for confirmation fields, captcha, terms acceptance, etc.\n   *\n   * @example\n   * ```ts\n   * v.object({\n   *   password: v.string().required(),\n   *   confirmPassword: v.string().required().sameAs(\"password\").omit(),\n   *   acceptTerms: v.boolean().required().omit(),\n   * });\n   * // Output: { password: \"...\" }\n   * // confirmPassword and acceptTerms validated but omitted\n   * ```\n   */\n  public omit() {\n    const instance = this.instance;\n    instance.shouldOmit = true;\n    return instance;\n  }\n\n  /**\n   * @alias omit\n   */\n  public exclude() {\n    return this.omit();\n  }\n\n  /**\n   * Check if this field should be omitted from the output\n   */\n  public isOmitted(): boolean {\n    return this.shouldOmit;\n  }\n\n  /**\n   * Add rule to the validator\n   */\n  public addRule<T extends SchemaRuleOptions = SchemaRuleOptions>(\n    rule: SchemaRule<T>,\n    errorMessage?: string,\n    options: T = {} as T,\n  ): this {\n    const instance = this.instance;\n    instance.addMutableRule(rule, errorMessage, options);\n    return instance;\n  }\n\n  /**\n   * Set the required-condition rule for this field.\n   *\n   * Unlike addRule(), this does NOT push to rules[]. The rule is stored in the\n   * dedicated `requiredRule` slot and is prepended to the validation pipeline\n   * at runtime. Only one required rule can be active per field — this replaces\n   * any previously set required rule.\n   *\n   * Also marks the field as not optional (isOptional = false).\n   *\n   * @example\n   * ```ts\n   * // Used internally by required(), requiredIf(), requiredWith(), etc.\n   * BaseValidator.prototype.required = function(msg) {\n   *   return this.setRequiredRule(requiredRule, msg);\n   * };\n   * ```\n   */\n  public setRequiredRule<T extends SchemaRuleOptions = SchemaRuleOptions>(\n    rule: SchemaRule<T>,\n    errorMessage?: string,\n    options: T = {} as T,\n  ): this {\n    const instance = this.instance;\n    instance.isOptional = false;\n    instance.requiredRule = instance.createRule(rule, errorMessage, options);\n    return instance;\n  }\n\n  /**\n   * Add mutable rule\n   */\n  public addMutableRule<T extends SchemaRuleOptions = SchemaRuleOptions>(\n    rule: SchemaRule<T>,\n    errorMessage?: string,\n    options: T = {} as T,\n  ): ContextualSchemaRule<T> {\n    const newRule: ContextualSchemaRule<T> = this.createRule(rule, errorMessage, options);\n\n    this.rules.push(newRule);\n\n    return newRule;\n  }\n\n  /**\n   * Create new rule\n   */\n  protected createRule<T extends SchemaRuleOptions = SchemaRuleOptions>(\n    rule: SchemaRule<T>,\n    errorMessage?: string,\n    options: T = {} as T,\n  ): ContextualSchemaRule<T> {\n    const newRule: ContextualSchemaRule<T> = {\n      ...(clone(rule) as ContextualSchemaRule<T>),\n      context: {\n        errorMessage,\n        options,\n        attributesList: this.attributesText,\n        translatedAttributes: this.translatedAttributes,\n        translationParams: {},\n        translatableParams: {},\n      },\n    };\n\n    if (errorMessage) {\n      newRule.errorMessage = errorMessage;\n    }\n\n    if (rule.sortOrder === undefined) {\n      newRule.sortOrder = this.rules.length + 1;\n    }\n\n    return newRule;\n  }\n\n  /**\n   * Use a custom or pre-built validation rule\n   *\n   * @param rule - The validation rule to apply\n   * @param options - Rule options including errorMessage and any rule-specific options\n   *\n   * @example\n   * ```ts\n   * import { hexColorRule } from \"@warlock.js/seal\";\n   *\n   * v.string().useRule(hexColorRule, { errorMessage: \"Invalid color\" });\n   * ```\n   *\n   * @example\n   * ```ts\n   * // With rule options\n   * v.string().useRule(myCustomRule, {\n   *   customOption: true,\n   *   errorMessage: \"Custom validation failed\"\n   * });\n   * ```\n   */\n  public useRule<T extends SchemaRuleOptions = SchemaRuleOptions>(\n    rule: SchemaRule<T>,\n    options?: T & { errorMessage?: string },\n  ) {\n    const { errorMessage, ...ruleOptions } = options || ({} as any);\n    return this.addRule(rule, errorMessage, ruleOptions);\n  }\n\n  /**\n   * Define custom rule\n   */\n  public refine(\n    callback: (\n      value: any,\n      context: SchemaContext,\n    ) => Promise<string | undefined> | string | undefined,\n  ) {\n    return this.addRule({\n      name: \"custom\",\n      async validate(value, context) {\n        const result = await callback(value, context);\n        if (result) {\n          this.context.errorMessage = result;\n          return invalidRule(this, context);\n        }\n        return VALID_RULE;\n      },\n    });\n  }\n\n  /**\n   * Add mutator to the validator\n   */\n  public addMutator(mutator: Mutator, options: any = {}) {\n    const instance = this.instance;\n    instance.addMutableMutator(mutator, options);\n    return instance;\n  }\n\n  /**\n   * Add mutable mutator\n   */\n  public addMutableMutator(mutator: Mutator, options: any = {}) {\n    this.mutators.push({\n      mutate: mutator,\n      context: {\n        options,\n        ctx: {} as any,\n      },\n    });\n  }\n\n  /**\n   * Set default value for the field. The default is used when the input is\n   * absent (`undefined`); it then flows through the rule pipeline.\n   *\n   * Brands the return type with `{ hasDefault: true }` so `Infer<>` treats\n   * the field as guaranteed-present even when chained with `.optional()`.\n   */\n  public default(value: any): this & { hasDefault: true } {\n    const instance = this.instance;\n    instance.defaultValue = value;\n    return instance as this & { hasDefault: true };\n  }\n\n  /**\n   * Fallback to a value when validation fails.\n   *\n   * Complementary to `.default()`: `.default(x)` fires when input is **absent**,\n   * `.catch(y)` fires when input is **present but invalid**. Combine them when\n   * you want both behaviours: `.optional().default(x).catch(y)`.\n   *\n   * The fallback can be a value or a callback `(errors, originalInput) => fallback`.\n   * The callback variant is the only side-channel for the swallowed errors —\n   * use it to log/alert before the fallback substitutes.\n   *\n   * Brands the return type with `{ hasCatch: true }` so `Infer<>` treats the\n   * field as guaranteed-present (the catch ensures a value will always exist).\n   *\n   * **Scope (v1).** Catch is honoured for **leaf validators** (string, number,\n   * boolean, date, …) and for fields inside containers. It is a **no-op on\n   * container validators themselves** (`v.object`, `v.array`, `v.record`,\n   * `v.tuple`, `v.discriminatedUnion`) — those use their own iteration logic\n   * that bypasses the catch hook in `BaseValidator.validate()`.\n   *\n   * @example\n   * ```ts\n   * v.int().min(0).catch(3)                   // bad number → 3\n   * v.string().in([\"us\", \"eu\"]).catch(\"us\")   // unknown enum → \"us\"\n   * v.string().catch((errors, input) => {\n   *   console.warn(`bad user value: ${JSON.stringify(input)}`, errors);\n   *   return \"anonymous\";\n   * })\n   * ```\n   */\n  public catch(\n    fallback:\n      | any\n      | ((errors: ValidationResult[\"errors\"], originalInput: any) => any | Promise<any>),\n  ): this & { hasCatch: true } {\n    const instance = this.instance;\n\n    instance.catchValue = fallback;\n    instance.hasCatch = true;\n\n    return instance as this & { hasCatch: true };\n  }\n\n  /**\n   * Mutate the data\n   */\n  public async mutate(data: any, context: SchemaContext) {\n    let mutatedData = data;\n\n    for (const mutator of this.mutators) {\n      mutator.context.ctx = context;\n      mutatedData = await mutator.mutate(mutatedData, mutator.context);\n    }\n\n    return mutatedData;\n  }\n\n  /**\n   * Set the label for the validator that will be matching the :input attribute\n   */\n  public label(label: string) {\n    const instance = this.instance;\n    instance.attributesText.input = label;\n    return instance;\n  }\n\n  /**\n   * Validate the data\n   */\n  public async validate(data: any, context: SchemaContext): Promise<ValidationResult> {\n    if (data === null && this.isNullable) {\n      return { isValid: true, errors: [], data: null };\n    }\n\n    const valueForRules = data ?? this.getDefaultValue();\n    const mutatedData = await this.mutate(valueForRules, context);\n\n    const errors: ValidationResult[\"errors\"] = [];\n    let isValid = true;\n    const isFirstErrorOnly = context.configurations?.firstErrorOnly ?? true;\n\n    const isEmpty = isEmptyValue(valueForRules);\n\n    // Prepend the required-condition rule if set, so it always runs first.\n    // requiredRule has requiresValue = false so it runs even on empty values.\n    const rulesToRun = this.requiredRule ? [this.requiredRule, ...this.rules] : this.rules;\n\n    for (const rule of rulesToRun) {\n      if ((rule.requiresValue ?? true) && isEmpty) continue;\n\n      this.setRuleAttributesList(rule);\n\n      const result = await rule.validate(mutatedData, context);\n\n      if (result.isValid === false) {\n        isValid = false;\n        errors.push({\n          type: rule.name,\n          error: result.error,\n          input: result.path ?? context.path,\n        });\n\n        if (isFirstErrorOnly) {\n          break;\n        }\n      }\n    }\n\n    const result: ValidationResult = {\n      isValid,\n      errors,\n      data:\n        mutatedData !== undefined\n          ? await this.startTransformationPipeline(mutatedData, context)\n          : undefined,\n    };\n\n    // Catch fallback — only on the leaf path. Container validators override\n    // validate() and don't run this hook on their own outcome, so catching\n    // a whole object/array/record is a no-op in v1.\n    if (result.isValid === false && this.hasCatch) {\n      const fallback =\n        typeof this.catchValue === \"function\"\n          ? await this.catchValue(result.errors, data)\n          : this.catchValue;\n\n      return { isValid: true, errors: [], data: fallback };\n    }\n\n    return result;\n  }\n\n  /**\n   * Set rule attributes list\n   */\n  protected setRuleAttributesList(rule: ContextualSchemaRule) {\n    rule.context.attributesList =\n      typeof this.attributesText[rule.name] === \"object\"\n        ? (this.attributesText[rule.name] as ValidationAttributesList)\n        : this.attributesText;\n  }\n\n  /**\n   * Standard Schema V1 compliance.\n   *\n   * Allows this validator to be used with any Standard Schema-aware library\n   * (OpenAI structured outputs, LangGraph, TanStack Form, Conform, Valibot adapters, etc.)\n   * without extra adapters.\n   *\n   * Delegates to the `validate()` factory so all `configureSeal()` options\n   * (translations, firstErrorOnly) are picked up automatically at call time.\n   *\n   * Includes Standard JSON Schema support via `jsonSchema.input()` / `jsonSchema.output()`.\n   *\n   * ## How Standard Schema libraries consume this\n   *\n   * You pass the **schema object itself** to the library — they internally read\n   * `schema[\"~standard\"]`. Do NOT pass `schema[\"~standard\"]` directly.\n   *\n   * @example\n   * ```ts\n   * const schema = v.object({ name: v.string().required() });\n   *\n   * // TanStack Form — pass schema, library reads [\"~standard\"] internally\n   * const form = useForm({ validators: { onChange: schema } });\n   *\n   * // Conform (Remix) — same pattern\n   * const [form] = useForm({ onValidate({ formData }) {\n   *   return parseWithStandardSchema(formData, { schema });\n   * }});\n   *\n   * // Direct validation (lower level — most apps don't need this)\n   * const result = await schema[\"~standard\"].validate({ name: \"Hasan\" });\n   * // → { value: { name: \"Hasan\" } }  on success\n   * // → { issues: [{ message: \"...\", path: [{ key: \"name\" }] }] }  on failure\n   *\n   * // JSON Schema for OpenAI / LangChain tool calling\n   * const parameters = schema[\"~standard\"].jsonSchema.input({ target: \"openai-strict\" });\n   * // → { type: \"object\", properties: {...}, required: [...], additionalProperties: false }\n   * ```\n   *\n   * @note Cross-field rules (sameAs, requiredIf, requiredWith) rely on sibling values\n   * available in the full validation context. When called on a standalone scalar validator,\n   * sibling data is absent and those rules will not evaluate correctly.\n   * Always call on the parent ObjectValidator for full-payload validation.\n   */\n  get [\"~standard\"](): StandardJSONSchemaV1.Props<TInput, TOutput> {\n    return {\n      version: 1,\n      vendor: \"seal\",\n      types: undefined as unknown as StandardSchemaV1.Types<TInput, TOutput>,\n      validate: async (value: unknown) => {\n        const result = await validate(this, value);\n        return mapToStandardResult(result) as StandardSchemaV1.Result<TOutput>;\n      },\n      jsonSchema: {\n        input: (options) => this.toJsonSchema(options.target),\n        output: (options) => this.toJsonSchema(options.target),\n      },\n    };\n  }\n\n  /**\n   * Generate a JSON Schema representation of this validator.\n   *\n   * Supports targets: `\"draft-2020-12\"` (default), `\"draft-07\"`, `\"openapi-3.0\"`.\n   *\n   * Subclasses override this to describe their specific constraints.\n   * The base implementation returns `{}` (permissive — accepts anything),\n   * which is correct for validators with no representable JSON Schema constraints.\n   *\n   * @note Rules that cannot be expressed in JSON Schema are silently omitted:\n   * - Cross-field rules: sameAs, requiredIf, requiredWith, requiredWithout\n   * - Custom callbacks: refine()\n   * - Framework-specific runtime rules (core/cascade plugins)\n   * These rules still run normally at validation time — only absent from JSON Schema.\n   *\n   * @example\n   * ```ts\n   * v.string().min(3).max(50).toJsonSchema(\"draft-2020-12\")\n   * // → { type: \"string\", minLength: 3, maxLength: 50 }\n   *\n   * v.object({ name: v.string().required(), age: v.int().optional() })\n   *   .toJsonSchema(\"draft-07\")\n   * // → { type: \"object\", properties: { name: { type: \"string\" }, age: { type: \"integer\" } }, required: [\"name\"] }\n   * ```\n   */\n  public toJsonSchema(_target: JsonSchemaTarget = \"draft-2020-12\"): JsonSchemaResult {\n    return {};\n  }\n}\n"],"mappings":";;;;;;;;;;;;AAyBA,IAAa,gBAAb,MAA+D;;eACtB,CAAC;kBACG,CAAC;oBAGrB;oBACA;mBACD;kBAYD;oBASD;sBAS+B,KAAK,WAAWA,YAAmB;0BAK5B,CAAC;wBAON,CAAC;8BAKG,CAAC;;;;;CAK1D,IAAW,UAAU;EACnB,KAAK,YAAY;EACjB,OAAO;CACT;;;;CAKA,IAAW,YAAY;EACrB,KAAK,YAAY;EACjB,OAAO;CACT;;;;;;CAOA,IAAc,WAAiB;EAC7B,OAAO,KAAK,YAAY,OAAO,KAAK,MAAM;CAC5C;;;;;CAMA,AAAO,kBAAuB;EAC5B,OAAO,OAAO,KAAK,iBAAiB,aAAa,KAAK,aAAa,IAAI,KAAK;CAC9E;;;;;;;CAQA,AAAO,WAAwC;EAC7C,MAAM,WAAW,KAAK;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