@warlock.js/seal 5.30.0 → 5.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +38 -7
- package/README.md +57 -9
- package/cjs/index.cjs +24 -16
- package/cjs/index.cjs.map +1 -1
- package/cjs/{object--LXRt5RF.cjs → object-VTtA-k1a.cjs} +15 -13
- package/cjs/object-VTtA-k1a.cjs.map +1 -0
- package/cjs/object.cjs +2 -2
- package/cjs/{required-methods-DYsRO9aZ.cjs → required-methods-chT0TXQS.cjs} +107 -31
- package/cjs/required-methods-chT0TXQS.cjs.map +1 -0
- package/cjs/{string-DsqnKoSB.cjs → string-edcPIpcU.cjs} +4 -4
- package/cjs/string-edcPIpcU.cjs.map +1 -0
- package/cjs/string.cjs +2 -2
- package/esm/config.d.mts.map +1 -1
- package/esm/config.mjs.map +1 -1
- package/esm/factory/validators.d.mts +8 -8
- package/esm/factory/validators.d.mts.map +1 -1
- package/esm/factory/validators.mjs +7 -1
- package/esm/factory/validators.mjs.map +1 -1
- package/esm/mutators/string-mutators.mjs +2 -2
- package/esm/mutators/string-mutators.mjs.map +1 -1
- package/esm/object.d.mts +1 -3
- package/esm/object.d.mts.map +1 -1
- package/esm/object.mjs.map +1 -1
- package/esm/rules/common/literal.mjs.map +1 -1
- package/esm/rules/core/union.d.mts +8 -1
- package/esm/rules/core/union.d.mts.map +1 -1
- package/esm/rules/core/union.mjs +56 -10
- package/esm/rules/core/union.mjs.map +1 -1
- package/esm/rules/core/when.mjs.map +1 -1
- package/esm/standard-schema/json-schema.d.mts.map +1 -1
- package/esm/standard-schema/json-schema.mjs.map +1 -1
- package/esm/standard-schema/map-result.d.mts.map +1 -1
- package/esm/standard-schema/map-result.mjs.map +1 -1
- package/esm/standard-schema/types.d.mts.map +1 -1
- package/esm/types/data-transformer-types.d.mts.map +1 -1
- package/esm/types/inference-types.d.mts +1 -1
- package/esm/types/inference-types.d.mts.map +1 -1
- package/esm/types/rule-types.d.mts +10 -1
- package/esm/types/rule-types.d.mts.map +1 -1
- package/esm/validators/array-validator.d.mts.map +1 -1
- package/esm/validators/array-validator.mjs +3 -3
- package/esm/validators/array-validator.mjs.map +1 -1
- package/esm/validators/base-validator.d.mts +8 -8
- package/esm/validators/base-validator.d.mts.map +1 -1
- package/esm/validators/base-validator.mjs +50 -20
- package/esm/validators/base-validator.mjs.map +1 -1
- package/esm/validators/computed-validator.d.mts.map +1 -1
- package/esm/validators/computed-validator.mjs +4 -4
- package/esm/validators/computed-validator.mjs.map +1 -1
- package/esm/validators/discriminated-union-validator.mjs +1 -1
- package/esm/validators/discriminated-union-validator.mjs.map +1 -1
- package/esm/validators/lazy-validator.mjs +1 -1
- package/esm/validators/lazy-validator.mjs.map +1 -1
- package/esm/validators/object-validator.d.mts.map +1 -1
- package/esm/validators/object-validator.mjs +9 -7
- package/esm/validators/object-validator.mjs.map +1 -1
- package/esm/validators/record-validator.d.mts.map +1 -1
- package/esm/validators/record-validator.mjs +3 -3
- package/esm/validators/record-validator.mjs.map +1 -1
- package/esm/validators/scalar-validator.mjs.map +1 -1
- package/esm/validators/tuple-validator.d.mts.map +1 -1
- package/esm/validators/tuple-validator.mjs +3 -3
- package/esm/validators/tuple-validator.mjs.map +1 -1
- package/esm/validators/union-validator.d.mts +3 -1
- package/esm/validators/union-validator.d.mts.map +1 -1
- package/esm/validators/union-validator.mjs +3 -1
- package/esm/validators/union-validator.mjs.map +1 -1
- package/llms-full.txt +656 -527
- package/llms.txt +1 -1
- package/package.json +1 -1
- package/skills/bridge-standard-schema/SKILL.md +60 -36
- package/skills/compose-seal-modifiers/SKILL.md +89 -53
- package/skills/define-structural-shape/SKILL.md +41 -27
- package/skills/define-structural-shape/array-methods.md +27 -27
- package/skills/define-structural-shape/object-methods.md +38 -30
- package/skills/extend-seal-with-plugins/SKILL.md +39 -5
- package/skills/generate-json-schema/SKILL.md +13 -13
- package/skills/handle-seal-errors/SKILL.md +23 -23
- package/skills/index.md +4 -1
- package/skills/overview/SKILL.md +10 -2
- package/skills/pick-seal-primitive/SKILL.md +45 -45
- package/skills/pick-seal-primitive/date-methods.md +96 -96
- package/skills/pick-seal-primitive/number-methods.md +55 -55
- package/skills/pick-seal-primitive/string-methods.md +107 -102
- package/skills/seal-basics/SKILL.md +14 -14
- package/cjs/object--LXRt5RF.cjs.map +0 -1
- package/cjs/required-methods-DYsRO9aZ.cjs.map +0 -1
- package/cjs/string-DsqnKoSB.cjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"when.mjs","names":[],"sources":["../../../../../../../../../packages/seal/src/rules/core/when.ts"],"sourcesContent":["import { get } from \"@mongez/reinforcements\";\nimport { invalidRule, VALID_RULE } from \"../../helpers\";\nimport type { SchemaRule, WhenRuleOptions } from \"../../types\";\n\n/**\n * When rule - conditional validation based on another field value\n */\nexport const whenRule: SchemaRule<WhenRuleOptions> = {\n name: \"when\",\n description: \"Apply conditional validation based on another field value\",\n async validate(value: any, context) {\n const fieldToCheck = this.context.options.field;\n const conditions = this.context.options.is;\n const otherwise = this.context.options.otherwise;\n const scope = this.context.options.scope || \"global\";\n\n const fieldValue =\n scope === \"global\"
|
|
1
|
+
{"version":3,"file":"when.mjs","names":[],"sources":["../../../../../../../../../packages/seal/src/rules/core/when.ts"],"sourcesContent":["import { get } from \"@mongez/reinforcements\";\nimport { invalidRule, VALID_RULE } from \"../../helpers\";\nimport type { SchemaRule, WhenRuleOptions } from \"../../types\";\n\n/**\n * When rule - conditional validation based on another field value\n */\nexport const whenRule: SchemaRule<WhenRuleOptions> = {\n name: \"when\",\n description: \"Apply conditional validation based on another field value\",\n async validate(value: any, context) {\n const fieldToCheck = this.context.options.field;\n const conditions = this.context.options.is;\n const otherwise = this.context.options.otherwise;\n const scope = this.context.options.scope || \"global\";\n\n const fieldValue =\n scope === \"global\" ? get(context.allValues, fieldToCheck) : get(context.parent, fieldToCheck);\n\n // Convert field value to string for key lookup\n // This handles boolean, number, and string field values\n const fieldValueKey = String(fieldValue);\n\n if (conditions[fieldValueKey]) {\n const result = await conditions[fieldValueKey].validate(value, context);\n if (result.isValid) {\n return VALID_RULE;\n }\n\n // Safe error access\n this.context.errorMessage = result.errors?.[0]?.error || \"Validation failed\";\n return invalidRule(this, context);\n }\n\n if (otherwise) {\n const result = await otherwise.validate(value, context);\n\n if (result.isValid) {\n return VALID_RULE;\n }\n\n // Safe error access\n this.context.errorMessage = result.errors?.[0]?.error || \"Validation failed\";\n return invalidRule(this, context);\n }\n\n return VALID_RULE;\n },\n};\n"],"mappings":";;;;;;;;AAOA,MAAa,WAAwC;CACnD,MAAM;CACN,aAAa;CACb,MAAM,SAAS,OAAY,SAAS;EAClC,MAAM,eAAe,KAAK,QAAQ,QAAQ;EAC1C,MAAM,aAAa,KAAK,QAAQ,QAAQ;EACxC,MAAM,YAAY,KAAK,QAAQ,QAAQ;EAGvC,MAAM,cAFQ,KAAK,QAAQ,QAAQ,SAAS,cAGhC,WAAW,IAAI,QAAQ,WAAW,YAAY,IAAI,IAAI,QAAQ,QAAQ,YAAY;EAI9F,MAAM,gBAAgB,OAAO,UAAU;EAEvC,IAAI,WAAW,gBAAgB;GAC7B,MAAM,SAAS,MAAM,WAAW,cAAc,CAAC,SAAS,OAAO,OAAO;GACtE,IAAI,OAAO,SACT,OAAO;GAIT,KAAK,QAAQ,eAAe,OAAO,SAAS,EAAE,EAAE,SAAS;GACzD,OAAO,YAAY,MAAM,OAAO;EAClC;EAEA,IAAI,WAAW;GACb,MAAM,SAAS,MAAM,UAAU,SAAS,OAAO,OAAO;GAEtD,IAAI,OAAO,SACT,OAAO;GAIT,KAAK,QAAQ,eAAe,OAAO,SAAS,EAAE,EAAE,SAAS;GACzD,OAAO,YAAY,MAAM,OAAO;EAClC;EAEA,OAAO;CACT;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-schema.d.mts","names":[],"sources":["../../../../../../../../packages/seal/src/standard-schema/json-schema.ts"],"mappings":";;;;;AAKA;KAAY,gBAAA,GAAmB,oBAAA,CAAqB,MAAM;;;AAAA;KAK9C,gBAAA,GAAmB,MAAM;;;;AAAA;AAmBrC;;;;;;;;;AAAgF;
|
|
1
|
+
{"version":3,"file":"json-schema.d.mts","names":[],"sources":["../../../../../../../../packages/seal/src/standard-schema/json-schema.ts"],"mappings":";;;;;AAKA;KAAY,gBAAA,GAAmB,oBAAA,CAAqB,MAAM;;;AAAA;KAK9C,gBAAA,GAAmB,MAAM;;;;AAAA;AAmBrC;;;;;;;;;AAAgF;AA0ChF;;;iBA1CgB,aAAA,CAAc,MAAA,EAAQ,gBAAA,EAAkB,MAAA,EAAQ,gBAAgB;;;;;AA0CF;AA2B9E;;;;;;;;;;;;;;;;;iBA3BgB,kBAAA,CAAmB,MAAA,EAAQ,gBAAA,GAAmB,gBAAgB;;;;;iBA2B9D,cAAA,CACd,KAAA,EAAO,KAAA;EAAQ,IAAA;EAAc,OAAA;IAAW,OAAA,EAAS,MAAA;EAAA;AAAA,IACjD,QAAA,WACC,MAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-schema.mjs","names":[],"sources":["../../../../../../../../packages/seal/src/standard-schema/json-schema.ts"],"sourcesContent":["import type { StandardJSONSchemaV1 } from \"./types\";\n\n/**\n * Supported JSON Schema generation targets.\n */\nexport type JsonSchemaTarget = StandardJSONSchemaV1.Target;\n\n/**\n * The result shape for a generated JSON Schema.\n */\nexport type JsonSchemaResult = Record<string, unknown>;\n\n/**\n * Apply nullable to a JSON Schema object based on the target dialect.\n *\n * - draft-2020-12 : `type` becomes an array: `[\"string\", \"null\"]`\n * - openai-strict : same as draft-2020-12 (type array form)\n * - draft-07 : wraps in `oneOf: [{ ...schema }, { type: \"null\" }]`\n * - openapi-3.0 : adds `nullable: true` alongside the existing type\n *\n * Mutates the schema in-place.\n *\n * @example\n * ```ts\n * const schema = { type: \"string\" };\n * applyNullable(schema, \"draft-2020-12\");\n * // → { type: [\"string\", \"null\"] }\n * ```\n */\nexport function applyNullable(schema: JsonSchemaResult, target: JsonSchemaTarget): void {\n if (target === \"openapi-3.0\") {\n schema.nullable = true;\n return;\n }\n\n if (target === \"draft-2020-12\" || target === \"openai-strict\") {\n const baseType = schema.type as string | string[] | undefined;\n schema.type = Array.isArray(baseType)
|
|
1
|
+
{"version":3,"file":"json-schema.mjs","names":[],"sources":["../../../../../../../../packages/seal/src/standard-schema/json-schema.ts"],"sourcesContent":["import type { StandardJSONSchemaV1 } from \"./types\";\n\n/**\n * Supported JSON Schema generation targets.\n */\nexport type JsonSchemaTarget = StandardJSONSchemaV1.Target;\n\n/**\n * The result shape for a generated JSON Schema.\n */\nexport type JsonSchemaResult = Record<string, unknown>;\n\n/**\n * Apply nullable to a JSON Schema object based on the target dialect.\n *\n * - draft-2020-12 : `type` becomes an array: `[\"string\", \"null\"]`\n * - openai-strict : same as draft-2020-12 (type array form)\n * - draft-07 : wraps in `oneOf: [{ ...schema }, { type: \"null\" }]`\n * - openapi-3.0 : adds `nullable: true` alongside the existing type\n *\n * Mutates the schema in-place.\n *\n * @example\n * ```ts\n * const schema = { type: \"string\" };\n * applyNullable(schema, \"draft-2020-12\");\n * // → { type: [\"string\", \"null\"] }\n * ```\n */\nexport function applyNullable(schema: JsonSchemaResult, target: JsonSchemaTarget): void {\n if (target === \"openapi-3.0\") {\n schema.nullable = true;\n return;\n }\n\n if (target === \"draft-2020-12\" || target === \"openai-strict\") {\n const baseType = schema.type as string | string[] | undefined;\n schema.type = Array.isArray(baseType) ? [...baseType, \"null\"] : [baseType as string, \"null\"];\n return;\n }\n\n // draft-07: oneOf wrapping\n const copy = { ...schema };\n for (const key of Object.keys(schema)) {\n delete schema[key];\n }\n schema.oneOf = [copy, { type: \"null\" }];\n}\n\n/**\n * Wrap a field schema as nullable for OpenAI strict mode.\n *\n * OpenAI strict requires optional fields to be expressed as a nullable type\n * rather than being omitted from the `required` array. This helper wraps a\n * given schema into its nullable equivalent using the type-array form.\n *\n * Unlike `applyNullable()` (which mutates in-place), this returns a new\n * schema object to avoid side effects when wrapping child schemas.\n *\n * @example\n * ```ts\n * wrapNullableStrict({ type: \"string\", minLength: 3 })\n * // → { type: [\"string\", \"null\"], minLength: 3 }\n *\n * wrapNullableStrict({ type: \"object\", properties: {...} })\n * // → { type: [\"object\", \"null\"], properties: {...} }\n *\n * wrapNullableStrict({ oneOf: [...] })\n * // → { oneOf: [..., { type: \"null\" }] }\n * ```\n */\nexport function wrapNullableStrict(schema: JsonSchemaResult): JsonSchemaResult {\n // If the schema uses oneOf/anyOf (e.g. union), append null to the list\n if (schema.oneOf) {\n return { ...schema, oneOf: [...(schema.oneOf as unknown[]), { type: \"null\" }] };\n }\n\n if (schema.anyOf) {\n return { ...schema, anyOf: [...(schema.anyOf as unknown[]), { type: \"null\" }] };\n }\n\n // If there's no type at all (permissive `{}`), stay permissive\n if (schema.type === undefined) {\n return schema;\n }\n\n // Standard case: wrap type into array with null\n const baseType = schema.type as string | string[];\n return {\n ...schema,\n type: Array.isArray(baseType) ? [...baseType, \"null\"] : [baseType, \"null\"],\n };\n}\n\n/**\n * Find the first rule matching the given name in a rules array,\n * and return its options bag.\n */\nexport function getRuleOptions(\n rules: Array<{ name: string; context: { options: Record<string, unknown> } }>,\n ruleName: string,\n): Record<string, unknown> | undefined {\n const rule = rules.find((r) => r.name === ruleName);\n return rule?.context?.options as Record<string, unknown> | undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA6BA,SAAgB,cAAc,QAA0B,QAAgC;CACtF,IAAI,WAAW,eAAe;EAC5B,OAAO,WAAW;EAClB;CACF;CAEA,IAAI,WAAW,mBAAmB,WAAW,iBAAiB;EAC5D,MAAM,WAAW,OAAO;EACxB,OAAO,OAAO,MAAM,QAAQ,QAAQ,IAAI,CAAC,GAAG,UAAU,MAAM,IAAI,CAAC,UAAoB,MAAM;EAC3F;CACF;CAGA,MAAM,OAAO,EAAE,GAAG,OAAO;CACzB,KAAK,MAAM,OAAO,OAAO,KAAK,MAAM,GAClC,OAAO,OAAO;CAEhB,OAAO,QAAQ,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC;AACxC;;;;;;;;;;;;;;;;;;;;;;;AAwBA,SAAgB,mBAAmB,QAA4C;CAE7E,IAAI,OAAO,OACT,OAAO;EAAE,GAAG;EAAQ,OAAO,CAAC,GAAI,OAAO,OAAqB,EAAE,MAAM,OAAO,CAAC;CAAE;CAGhF,IAAI,OAAO,OACT,OAAO;EAAE,GAAG;EAAQ,OAAO,CAAC,GAAI,OAAO,OAAqB,EAAE,MAAM,OAAO,CAAC;CAAE;CAIhF,IAAI,OAAO,SAAS,QAClB,OAAO;CAIT,MAAM,WAAW,OAAO;CACxB,OAAO;EACL,GAAG;EACH,MAAM,MAAM,QAAQ,QAAQ,IAAI,CAAC,GAAG,UAAU,MAAM,IAAI,CAAC,UAAU,MAAM;CAC3E;AACF;;;;;AAMA,SAAgB,eACd,OACA,UACqC;CAErC,OADa,MAAM,MAAM,MAAM,EAAE,SAAS,QAChC,CAAC,EAAE,SAAS;AACxB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map-result.d.mts","names":[],"sources":["../../../../../../../../packages/seal/src/standard-schema/map-result.ts"],"mappings":";;;;;;AAiBA;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"map-result.d.mts","names":[],"sources":["../../../../../../../../packages/seal/src/standard-schema/map-result.ts"],"mappings":";;;;;;AAiBA;;;;;;;;;AAAsF;;;iBAAtE,mBAAA,CAAoB,MAAA,EAAQ,gBAAA,GAAmB,gBAAA,CAAiB,MAAM"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map-result.mjs","names":[],"sources":["../../../../../../../../packages/seal/src/standard-schema/map-result.ts"],"sourcesContent":["import type { ValidationResult } from \"../types\";\nimport type { StandardSchemaV1 } from \"./types\";\n\n/**\n * Maps a Seal ValidationResult to a Standard Schema result shape.\n *\n * Seal error paths are dot-notation strings (e.g. \"address.city\").\n * Standard Schema expects an array of path segments: [{ key: \"address\" }, { key: \"city\" }].\n *\n * @example\n * ```ts\n * const result = await validator.validate(value, context);\n * return mapToStandardResult(result);\n * // Success → { value: <data> }\n * // Failure → { issues: [{ message: \"...\", path: [{ key: \"...\" }] }] }\n * ```\n */\nexport function mapToStandardResult(
|
|
1
|
+
{"version":3,"file":"map-result.mjs","names":[],"sources":["../../../../../../../../packages/seal/src/standard-schema/map-result.ts"],"sourcesContent":["import type { ValidationResult } from \"../types\";\nimport type { StandardSchemaV1 } from \"./types\";\n\n/**\n * Maps a Seal ValidationResult to a Standard Schema result shape.\n *\n * Seal error paths are dot-notation strings (e.g. \"address.city\").\n * Standard Schema expects an array of path segments: [{ key: \"address\" }, { key: \"city\" }].\n *\n * @example\n * ```ts\n * const result = await validator.validate(value, context);\n * return mapToStandardResult(result);\n * // Success → { value: <data> }\n * // Failure → { issues: [{ message: \"...\", path: [{ key: \"...\" }] }] }\n * ```\n */\nexport function mapToStandardResult(result: ValidationResult): StandardSchemaV1.Result<unknown> {\n if (result.isValid) {\n return { value: result.data };\n }\n\n return {\n issues: result.errors.map((e) => ({\n message: e.error,\n path: e.input ? e.input.split(\".\").map((key) => ({ key })) : undefined,\n })),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;AAiBA,SAAgB,oBAAoB,QAA4D;CAC9F,IAAI,OAAO,SACT,OAAO,EAAE,OAAO,OAAO,KAAK;CAG9B,OAAO,EACL,QAAQ,OAAO,OAAO,KAAK,OAAO;EAChC,SAAS,EAAE;EACX,MAAM,EAAE,QAAQ,EAAE,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,SAAS,EAAE,IAAI,EAAE,IAAI;CAC/D,EAAE,EACJ;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","names":[],"sources":["../../../../../../../../packages/seal/src/standard-schema/types.ts"],"mappings":";;AAgBA;;;;;;;;;;UAAiB,gBAAA,2BAA2C,KAAA;EAAA,SACjD,WAA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AAA;AAAA,kBAGjC,oBAAA;EAAA,UACN,KAAA,2BAAgC,KAAA,UAAe,IAAA,CAC9D,gBAAA,CAAiB,KAAA,CAAM,KAAA,EAAO,MAAA;IAAA,SAGrB,UAAA,EAAY,SAAA;EAAA;EAhET;EAAA,UAoEG,SAAA;IAnEV;IAAA,SAqEI,KAAA,GAAQ,OAAA,EAAS,OAAA,KAAY,MAAA;IArEhB;IAAA,SAuEb,MAAA,GAAS,OAAA,EAAS,OAAA,KAAY,MAAA;EAAA;EAnExB;;;;;;;;;;;;EAAA,KAkFL,MAAA;EAAA,UAOK,OAAA;IAAA,SACN,MAAA,EAAQ,MAAA;IAAA,SACR,cAAA,GAAiB,MAAA;EAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-transformer-types.d.mts","names":[],"sources":["../../../../../../../../packages/seal/src/types/data-transformer-types.ts"],"mappings":";;;;;AAOA;;;KAAY,mBAAA,IACV,IAAA,OACA,MAAA;EACE,OAAA;EACA,OAAA,EAAS,aAAA;AAAA,YAEF,OAAO;;;;;AAAA;KAON,yBAAA,
|
|
1
|
+
{"version":3,"file":"data-transformer-types.d.mts","names":[],"sources":["../../../../../../../../packages/seal/src/types/data-transformer-types.ts"],"mappings":";;;;;AAOA;;;KAAY,mBAAA,IACV,IAAA,OACA,MAAA;EACE,OAAA;EACA,OAAA,EAAS,aAAA;AAAA,YAEF,OAAO;;;;;AAAA;KAON,yBAAA,IAA6B,IAAA,OAAW,OAAA,EAAS,aAAA,WAAwB,OAAO;;;;;KAMhF,yBAAA;EACV,SAAA,EAAW,mBAAmB;EAC9B,OAAA;AAAA"}
|
|
@@ -159,7 +159,7 @@ declare namespace Infer {
|
|
|
159
159
|
*/
|
|
160
160
|
type Output<T> = T extends LazyValidator<infer L> ? Output<L> : T extends DiscriminatedUnionValidator<any, infer Branches> ? Branches extends ReadonlyArray<infer B> ? B extends BaseValidator ? WithNullable<T, Output<B>> : never : never : T extends ObjectValidator<infer S> ? WithNullable<T, InferOutputObjectShape<S>> : T extends ArrayValidator ? T extends {
|
|
161
161
|
validator: infer V extends BaseValidator;
|
|
162
|
-
} ? WithNullable<T, Array<Output<V>>> : never : T extends LiteralValidator<infer V> ? WithNullable<T, V[number]> : T extends InstanceOfValidator<infer R> ? WithNullable<T, R> : T extends ComputedValidator<infer R> ? R : T extends ManagedValidator<infer R> ? R : T extends StandardSchemaV1
|
|
162
|
+
} ? WithNullable<T, Array<Output<V>>> : never : T extends LiteralValidator<infer V> ? WithNullable<T, V[number]> : T extends InstanceOfValidator<infer R> ? WithNullable<T, R> : T extends ComputedValidator<infer R> ? R : T extends ManagedValidator<infer R> ? R : T extends StandardSchemaV1 ? WithNullable<T, StandardSchemaV1.InferOutput<T>> : T extends StringValidator ? WithNullable<T, string> : T extends IntValidator ? WithNullable<T, number> : T extends FloatValidator ? WithNullable<T, number> : T extends BooleanValidator ? WithNullable<T, boolean> : T extends DateValidator ? WithNullable<T, Date> : T extends ScalarValidator ? WithNullable<T, string | number | boolean> : T extends AnyValidator ? any : unknown;
|
|
163
163
|
}
|
|
164
164
|
/**
|
|
165
165
|
* @deprecated Use `Infer.Input<T>` instead. Kept as an alias for one or two
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inference-types.d.mts","names":[],"sources":["../../../../../../../../packages/seal/src/types/inference-types.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmB6C;;;;;;;;;;AAoErB;AAUxB;;;;;;;;;;;;;;AACkB;AAWlB;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"inference-types.d.mts","names":[],"sources":["../../../../../../../../packages/seal/src/types/inference-types.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmB6C;;;;;;;;;;AAoErB;AAUxB;;;;;;;;;;;;;;AACkB;AAWlB;;;;;;;;;;AAGc;AAEJ;;;;;;;;KA7BL,YAAA,MAAkB,CAAA;EAAY,UAAA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AAG,CAAA,IAChB,CAAA,SAAU,iBAAA,YACR,CAAA,GACA,CAAA,SAAU,gBAAA,YACR,CAAA,GAMA,CAAA,SAAU,gBAAA,GACR,YAAA,CAAa,CAAA,EAAG,gBAAA,CAAiB,WAAA,CAAY,CAAA,KAC7C,CAAA,SAAU,eAAA,GACR,YAAA,CAAa,CAAA,YACb,CAAA,SAAU,YAAA,GACR,YAAA,CAAa,CAAA,YACb,CAAA,SAAU,cAAA,GACR,YAAA,CAAa,CAAA,YACb,CAAA,SAAU,gBAAA,GACR,YAAA,CAAa,CAAA,aACb,CAAA,SAAU,aAAA,GACR,YAAA,CAAa,CAAA,EAAG,IAAA,IAChB,CAAA,SAAU,eAAA,GACR,YAAA,CAAa,CAAA,+BACb,CAAA,SAAU,YAAA;AAAA;;;;;KASlC,UAAA,MAAgB,KAAA,CAAM,KAAK,CAAC,CAAA;;;;;KAM5B,WAAA,MAAiB,KAAA,CAAM,MAAM,CAAC,CAAA;;;;KAK9B,gBAAA,WAA2B,MAAA,IAAU,sBAAA,CAAuB,CAAA;;;;KAK5D,aAAA,MAAmB,mBAAmB,CAAC,CAAA;;;;;;;;;;AAjIqC;KA6I5E,eAAA,OAAsB,KAAA,CAAM,MAAA,CAAO,CAAA,uCAC3B,CAAA,SAEd,CAAA,uCACuB,CAAA,mBACH,CAAA,OAAQ,CAAA,UAEtB,CAAA,GACF,CAAA,GACF,CAAA"}
|
|
@@ -9,8 +9,17 @@ type RuleResult = {
|
|
|
9
9
|
error: string;
|
|
10
10
|
input: string;
|
|
11
11
|
path: string;
|
|
12
|
+
/**
|
|
13
|
+
* Report several errors for this rule, each at its own path. When set,
|
|
14
|
+
* it replaces `error`/`path` in the validation result.
|
|
15
|
+
*/
|
|
16
|
+
errors?: Array<{
|
|
17
|
+
error: string;
|
|
18
|
+
path: string;
|
|
19
|
+
}>;
|
|
12
20
|
} | {
|
|
13
|
-
isValid: true;
|
|
21
|
+
isValid: true; /** Replace the validated value, including an explicit undefined output. */
|
|
22
|
+
data?: unknown;
|
|
14
23
|
};
|
|
15
24
|
type AttributeValue = string | number;
|
|
16
25
|
type ValidationAttributesList = Record<string, AttributeValue | Record<string, AttributeValue>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rule-types.d.mts","names":[],"sources":["../../../../../../../../packages/seal/src/types/rule-types.ts"],"mappings":";;;;;AAKA;KAAY,UAAA;EAEN,OAAA;EACA,KAAA;EACA,KAAA;EACA,IAAA;AAAA;
|
|
1
|
+
{"version":3,"file":"rule-types.d.mts","names":[],"sources":["../../../../../../../../packages/seal/src/types/rule-types.ts"],"mappings":";;;;;AAKA;KAAY,UAAA;EAEN,OAAA;EACA,KAAA;EACA,KAAA;EACA,IAAA;EADA;;;;EAMA,MAAA,GAAS,KAAK;IAAG,KAAA;IAAe,IAAA;EAAA;AAAA;EAGhC,OAAA,QAKD;EAHC,IAAA;AAAA;AAAA,KAGD,cAAA;AAAA,KAEO,wBAAA,GAA2B,MAAA,SAErC,cAAA,GAAiB,MAAA,SAAe,cAAA;AAFlC;;;AAAA,KAQY,iBAAA,YAA6B,MAAM,SAAS,CAAA;;;;KAK5C,UAAA,iBAA2B,iBAAA,GAAoB,iBAAA;EAbd,gBAe3C,IAAA,UAbA;EAeA,WAAA,WAfgC;EAiBhC,aAAA,YAjB8C;EAmB9C,QAAA,GACE,IAAA,EAAM,oBAAA,CAAqB,OAAA,GAC3B,KAAA,OACA,OAAA,EAAS,aAAA,KACN,OAAA,CAAQ,UAAA,GAjBc;EAmB3B,mBAAA,WAnB6C;EAqB7C,YAAA,WArBuC;EAuBvC,SAAA;AAAA;AAvBuD;AAKzD;;AALyD,KA6B7C,oBAAA,iBAAqC,iBAAA,GAAoB,iBAAA,IACnE,UAAA;EAzBqC;;;;EA8BnC,OAAA;IACE,YAAA;IACA,OAAA,EAAS,OAAA;IACT,cAAA,EAAgB,wBAAA;IAChB,oBAAA,EAAsB,MAAA,kBAlCL;IAoCjB,iBAAA,EAAmB,MAAA,eApCkC;IAsCrD,kBAAA,EAAoB,MAAA;EAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array-validator.d.mts","names":[],"sources":["../../../../../../../../packages/seal/src/validators/array-validator.ts"],"mappings":";;;;;;;;;cAmBa,cAAA,SAAuB,aAAA;EAEzB,SAAA,EAAW,aAAA;cAAX,SAAA,EAAW,aAAA,EAClB,YAAA;EADkB;;;EAWb,WAAA,CAAY,KAAA;EA8G+C;;;EAvGlD,KAAA;EApBkB;EA6B3B,IAAA;EA7BwC;EAkCxC,OAAA;EAhCE;EAqCF,UAAA;;EAKA,IAAA,CAAK,SAAA,mBAAmC,GAAA;EA1CtC;EA+CF,GAAA,CAAI,GAAA,UAAa,YAAA;EApCjB;EAyCA,SAAA,CAAU,MAAA,UAAgB,YAAA;EAlCjB;EAuCT,GAAA,CAAI,GAAA,UAAa,YAAA;EAzBjB;EA8BA,SAAA,CAAU,MAAA,UAAgB,YAAA;EApB1B;EAyBA,MAAA,CAAO,MAAA,UAAgB,YAAA;EAzBiB;;;;;;;;;;;;;;EA2CxC,OAAA,CAAQ,GAAA,UAAa,GAAA,UAAa,YAAA;EAlBX;;;EA4BvB,aAAA,CAAc,GAAA,UAAa,GAAA,UAAa,YAAA;EAVN;EAelC,MAAA,CAAO,YAAA;EALO;EAUd,MAAA,CAAO,SAAA,mBAAmC,YAAA;EAVF;EAexC,MAAA,CAAO,IAAA,OAAW,OAAA,EAAS,aAAA;EAVpB;;;;;;EAqBD,QAAA,CAAS,IAAA,OAAW,OAAA,EAAS,aAAA,GAAgB,OAAA,CAAQ,gBAAA;EAXzC;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"array-validator.d.mts","names":[],"sources":["../../../../../../../../packages/seal/src/validators/array-validator.ts"],"mappings":";;;;;;;;;cAmBa,cAAA,SAAuB,aAAA;EAEzB,SAAA,EAAW,aAAA;cAAX,SAAA,EAAW,aAAA,EAClB,YAAA;EADkB;;;EAWb,WAAA,CAAY,KAAA;EA8G+C;;;EAvGlD,KAAA;EApBkB;EA6B3B,IAAA;EA7BwC;EAkCxC,OAAA;EAhCE;EAqCF,UAAA;;EAKA,IAAA,CAAK,SAAA,mBAAmC,GAAA;EA1CtC;EA+CF,GAAA,CAAI,GAAA,UAAa,YAAA;EApCjB;EAyCA,SAAA,CAAU,MAAA,UAAgB,YAAA;EAlCjB;EAuCT,GAAA,CAAI,GAAA,UAAa,YAAA;EAzBjB;EA8BA,SAAA,CAAU,MAAA,UAAgB,YAAA;EApB1B;EAyBA,MAAA,CAAO,MAAA,UAAgB,YAAA;EAzBiB;;;;;;;;;;;;;;EA2CxC,OAAA,CAAQ,GAAA,UAAa,GAAA,UAAa,YAAA;EAlBX;;;EA4BvB,aAAA,CAAc,GAAA,UAAa,GAAA,UAAa,YAAA;EAVN;EAelC,MAAA,CAAO,YAAA;EALO;EAUd,MAAA,CAAO,SAAA,mBAAmC,YAAA;EAVF;EAexC,MAAA,CAAO,IAAA,OAAW,OAAA,EAAS,aAAA;EAVpB;;;;;;EAqBD,QAAA,CAAS,IAAA,OAAW,OAAA,EAAS,aAAA,GAAgB,OAAA,CAAQ,gBAAA;EAXzC;;;;;;;;;;;EA2ET,YAAA,CAAa,MAAA,GAAQ,gBAAA,GAAqC,gBAAA;AAAA"}
|
|
@@ -121,7 +121,7 @@ var ArrayValidator = class extends BaseValidator {
|
|
|
121
121
|
async validate(data, context) {
|
|
122
122
|
const valueForRules = data ?? this.getDefaultValue();
|
|
123
123
|
const mutatedData = await this.mutate(valueForRules, context);
|
|
124
|
-
const result = await
|
|
124
|
+
const result = await this.validateRules(data, context);
|
|
125
125
|
if (result.isValid === false) return result;
|
|
126
126
|
if (mutatedData === void 0 || mutatedData === null) return result;
|
|
127
127
|
if (!Array.isArray(mutatedData)) return result;
|
|
@@ -139,11 +139,11 @@ var ArrayValidator = class extends BaseValidator {
|
|
|
139
139
|
if (childResult.isValid === false) errors.push(...childResult.errors);
|
|
140
140
|
});
|
|
141
141
|
await Promise.all(validationPromises);
|
|
142
|
-
return {
|
|
142
|
+
return this.refineResult({
|
|
143
143
|
isValid: errors.length === 0,
|
|
144
144
|
errors,
|
|
145
145
|
data: await this.startTransformationPipeline(mutatedData, context)
|
|
146
|
-
};
|
|
146
|
+
}, context);
|
|
147
147
|
}
|
|
148
148
|
/**
|
|
149
149
|
* @inheritdoc
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array-validator.mjs","names":[],"sources":["../../../../../../../../packages/seal/src/validators/array-validator.ts"],"sourcesContent":["import { setKeyPath } from \"../helpers\";\nimport { flipArrayMutator, sortArrayMutator, uniqueArrayMutator } from \"../mutators\";\nimport {\n arrayRule,\n betweenLengthRule,\n lengthRule,\n maxLengthRule,\n minLengthRule,\n sortedArrayRule,\n uniqueArrayRule,\n} from \"../rules\";\nimport type { SchemaContext, ValidationResult } from \"../types\";\nimport { BaseValidator } from \"./base-validator\";\nimport { applyNullable, getRuleOptions } from \"../standard-schema/json-schema\";\nimport type { JsonSchemaResult, JsonSchemaTarget } from \"../standard-schema/json-schema\";\n\n/**\n * Array validator class\n */\nexport class ArrayValidator extends BaseValidator {\n public constructor(\n public validator: BaseValidator,\n errorMessage?: string,\n ) {\n super();\n this.blankIsMissing = true;\n this.addMutableRule(arrayRule, errorMessage);\n }\n\n /**\n * Check if value is an array type\n */\n public matchesType(value: any): boolean {\n return Array.isArray(value);\n }\n\n /**\n * Clone the validator\n */\n public override clone(): this {\n const cloned = super.clone();\n\n cloned.validator = this.validator.clone();\n\n return cloned;\n }\n\n /** Reverse array order */\n public flip() {\n return this.addMutator(flipArrayMutator);\n }\n\n /** Reverse array order (alias) */\n public reverse() {\n return this.addMutator(flipArrayMutator);\n }\n\n /** Make it has only unique values */\n public onlyUnique() {\n return this.addMutator(uniqueArrayMutator);\n }\n\n /** Sort array */\n public sort(direction: \"asc\" | \"desc\" = \"asc\", key?: string) {\n return this.addMutator(sortArrayMutator, { direction, key });\n }\n\n /** Array length must be greater than the given length */\n public min(min: number, errorMessage?: string) {\n return this.addRule(minLengthRule, errorMessage, { minLength: min });\n }\n\n /** @alias min */\n public minLength(length: number, errorMessage?: string) {\n return this.min(length, errorMessage);\n }\n\n /** Array length must be less than the given length */\n public max(max: number, errorMessage?: string) {\n return this.addRule(maxLengthRule, errorMessage, { maxLength: max });\n }\n\n /** @alias max */\n public maxLength(length: number, errorMessage?: string) {\n return this.max(length, errorMessage);\n }\n\n /** Array length must be of the given length */\n public length(length: number, errorMessage?: string) {\n return this.addRule(lengthRule, errorMessage, { length });\n }\n\n /**\n * Array length must be between min and max (inclusive)\n *\n * @param min - Minimum length (inclusive)\n * @param max - Maximum length (inclusive)\n *\n * @example\n * ```ts\n * v.array(v.string()).between(1, 10) // Array must have 1 to 10 items\n * v.array(v.number()).lengthBetween(5, 20) // Same using alias\n * ```\n *\n * @category Validation Rule\n */\n public between(min: number, max: number, errorMessage?: string) {\n return this.addRule(betweenLengthRule, errorMessage, {\n minLength: min,\n maxLength: max,\n });\n }\n\n /**\n * Alias for between() - array length between min and max\n */\n public lengthBetween(min: number, max: number, errorMessage?: string) {\n return this.between(min, max, errorMessage);\n }\n\n /** Array must have unique values */\n public unique(errorMessage?: string) {\n return this.addRule(uniqueArrayRule, errorMessage);\n }\n\n /** Array must be sorted */\n public sorted(direction: \"asc\" | \"desc\" = \"asc\", errorMessage?: string) {\n return this.addRule(sortedArrayRule, errorMessage, { direction });\n }\n\n /** Mutate the data */\n public mutate(data: any, context: SchemaContext) {\n if (!Array.isArray(data)) return data;\n return super.mutate([...data], context);\n }\n\n /** Validate array\n *\n * Absent input (and absent without `.default()`) propagates as `data: undefined`\n * so the parent ObjectValidator can omit the key. Without this, optional array\n * fields would silently materialise as `[]` in the validated output.\n */\n public async validate(data: any, context: SchemaContext): Promise<ValidationResult> {\n // Apply default when absent, then mutate. Mirrors BaseValidator's\n // `valueForRules = data ?? this.getDefaultValue()` so `.default([...])`\n // works on arrays too.\n const valueForRules = data ?? this.getDefaultValue();\n const mutatedData = await this.mutate(valueForRules, context);\n\n const result = await super.validate(data, context);\n\n if (result.isValid === false) return result;\n\n // Nothing to iterate for absent (no default) or null (nullable) inputs —\n // propagate so the parent ObjectValidator can omit the key.\n if (mutatedData === undefined || mutatedData === null) return result;\n\n // Defensive: type rule (arrayRule) should have failed for non-arrays.\n if (!Array.isArray(mutatedData)) return result;\n\n const errors: ValidationResult[\"errors\"] = [];\n\n // Validate all items in parallel (consistent with ObjectValidator)\n const validationPromises = mutatedData.map(async (value: any, index: number) => {\n const childContext: SchemaContext = {\n ...context,\n parent: mutatedData,\n value,\n key: index.toString(),\n path: setKeyPath(context.path, index.toString()),\n };\n\n const childResult = await this.validator.validate(value, childContext);\n\n // Update mutated data with validated result\n mutatedData[index] = childResult.data;\n\n // Collect errors from this element\n if (childResult.isValid === false) {\n errors.push(...childResult.errors);\n }\n });\n\n await Promise.all(validationPromises);\n\n return {\n isValid: errors.length === 0,\n errors,\n data: await this.startTransformationPipeline(mutatedData, context),\n };\n }\n\n /**\n * @inheritdoc\n *\n * Recursively generates JSON Schema for the array items.\n *\n * @example\n * ```ts\n * v.array(v.string().min(1)).minLength(1).toJsonSchema(\"draft-2020-12\")\n * // → { type: \"array\", items: { type: \"string\", minLength: 1 }, minItems: 1 }\n * ```\n */\n public override toJsonSchema(target: JsonSchemaTarget = \"draft-2020-12\"): JsonSchemaResult {\n const schema: JsonSchemaResult = {\n type: \"array\",\n items: this.validator.toJsonSchema(target),\n };\n\n const minOpts = getRuleOptions(this.rules, \"minLength\");\n if (minOpts?.minLength !== undefined) schema.minItems = minOpts.minLength;\n\n const maxOpts = getRuleOptions(this.rules, \"maxLength\");\n if (maxOpts?.maxLength !== undefined) schema.maxItems = maxOpts.maxLength;\n\n const betweenOpts = getRuleOptions(this.rules, \"betweenLength\");\n if (betweenOpts) {\n if (betweenOpts.minLength !== undefined) schema.minItems = betweenOpts.minLength;\n if (betweenOpts.maxLength !== undefined) schema.maxItems = betweenOpts.maxLength;\n }\n\n const lengthOpts = getRuleOptions(this.rules, \"length\");\n if (lengthOpts?.length !== undefined) {\n schema.minItems = lengthOpts.length;\n schema.maxItems = lengthOpts.length;\n }\n\n if (this.isNullable) applyNullable(schema, target);\n\n return schema;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAmBA,IAAa,iBAAb,cAAoC,cAAc;CAChD,AAAO,YACL,AAAO,WACP,cACA;EACA,MAAM;EAHC;EAIP,KAAK,iBAAiB;EACtB,KAAK,eAAe,WAAW,YAAY;CAC7C;;;;CAKA,AAAO,YAAY,OAAqB;EACtC,OAAO,MAAM,QAAQ,KAAK;CAC5B;;;;CAKA,AAAgB,QAAc;EAC5B,MAAM,SAAS,MAAM,MAAM;EAE3B,OAAO,YAAY,KAAK,UAAU,MAAM;EAExC,OAAO;CACT;;CAGA,AAAO,OAAO;EACZ,OAAO,KAAK,WAAW,gBAAgB;CACzC;;CAGA,AAAO,UAAU;EACf,OAAO,KAAK,WAAW,gBAAgB;CACzC;;CAGA,AAAO,aAAa;EAClB,OAAO,KAAK,WAAW,kBAAkB;CAC3C;;CAGA,AAAO,KAAK,YAA4B,OAAO,KAAc;EAC3D,OAAO,KAAK,WAAW,kBAAkB;GAAE;GAAW;EAAI,CAAC;CAC7D;;CAGA,AAAO,IAAI,KAAa,cAAuB;EAC7C,OAAO,KAAK,QAAQ,eAAe,cAAc,EAAE,WAAW,IAAI,CAAC;CACrE;;CAGA,AAAO,UAAU,QAAgB,cAAuB;EACtD,OAAO,KAAK,IAAI,QAAQ,YAAY;CACtC;;CAGA,AAAO,IAAI,KAAa,cAAuB;EAC7C,OAAO,KAAK,QAAQ,eAAe,cAAc,EAAE,WAAW,IAAI,CAAC;CACrE;;CAGA,AAAO,UAAU,QAAgB,cAAuB;EACtD,OAAO,KAAK,IAAI,QAAQ,YAAY;CACtC;;CAGA,AAAO,OAAO,QAAgB,cAAuB;EACnD,OAAO,KAAK,QAAQ,YAAY,cAAc,EAAE,OAAO,CAAC;CAC1D;;;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AQ,IAAI,kBAAkB;EAEpC,OAAO;GACL,SAAS,OAAO,WAAW;GAC3B;GACA,MAAM,MAAM,KAAK,4BAA4B,aAAa,OAAO;EACnE;CACF;;;;;;;;;;;;CAaA,AAAgB,aAAa,SAA2B,iBAAmC;EACzF,MAAM,SAA2B;GAC/B,MAAM;GACN,OAAO,KAAK,UAAU,aAAa,MAAM;EAC3C;EAEA,MAAM,UAAU,eAAe,KAAK,OAAO,WAAW;EACtD,IAAI,SAAS,cAAc,QAAW,OAAO,WAAW,QAAQ;EAEhE,MAAM,UAAU,eAAe,KAAK,OAAO,WAAW;EACtD,IAAI,SAAS,cAAc,QAAW,OAAO,WAAW,QAAQ;EAEhE,MAAM,cAAc,eAAe,KAAK,OAAO,eAAe;EAC9D,IAAI,aAAa;GACf,IAAI,YAAY,cAAc,QAAW,OAAO,WAAW,YAAY;GACvE,IAAI,YAAY,cAAc,QAAW,OAAO,WAAW,YAAY;EACzE;EAEA,MAAM,aAAa,eAAe,KAAK,OAAO,QAAQ;EACtD,IAAI,YAAY,WAAW,QAAW;GACpC,OAAO,WAAW,WAAW;GAC7B,OAAO,WAAW,WAAW;EAC/B;EAEA,IAAI,KAAK,YAAY,cAAc,QAAQ,MAAM;EAEjD,OAAO;CACT;AACF"}
|
|
1
|
+
{"version":3,"file":"array-validator.mjs","names":[],"sources":["../../../../../../../../packages/seal/src/validators/array-validator.ts"],"sourcesContent":["import { setKeyPath } from \"../helpers\";\nimport { flipArrayMutator, sortArrayMutator, uniqueArrayMutator } from \"../mutators\";\nimport {\n arrayRule,\n betweenLengthRule,\n lengthRule,\n maxLengthRule,\n minLengthRule,\n sortedArrayRule,\n uniqueArrayRule,\n} from \"../rules\";\nimport type { SchemaContext, ValidationResult } from \"../types\";\nimport { BaseValidator } from \"./base-validator\";\nimport { applyNullable, getRuleOptions } from \"../standard-schema/json-schema\";\nimport type { JsonSchemaResult, JsonSchemaTarget } from \"../standard-schema/json-schema\";\n\n/**\n * Array validator class\n */\nexport class ArrayValidator extends BaseValidator {\n public constructor(\n public validator: BaseValidator,\n errorMessage?: string,\n ) {\n super();\n this.blankIsMissing = true;\n this.addMutableRule(arrayRule, errorMessage);\n }\n\n /**\n * Check if value is an array type\n */\n public matchesType(value: any): boolean {\n return Array.isArray(value);\n }\n\n /**\n * Clone the validator\n */\n public override clone(): this {\n const cloned = super.clone();\n\n cloned.validator = this.validator.clone();\n\n return cloned;\n }\n\n /** Reverse array order */\n public flip() {\n return this.addMutator(flipArrayMutator);\n }\n\n /** Reverse array order (alias) */\n public reverse() {\n return this.addMutator(flipArrayMutator);\n }\n\n /** Make it has only unique values */\n public onlyUnique() {\n return this.addMutator(uniqueArrayMutator);\n }\n\n /** Sort array */\n public sort(direction: \"asc\" | \"desc\" = \"asc\", key?: string) {\n return this.addMutator(sortArrayMutator, { direction, key });\n }\n\n /** Array length must be greater than the given length */\n public min(min: number, errorMessage?: string) {\n return this.addRule(minLengthRule, errorMessage, { minLength: min });\n }\n\n /** @alias min */\n public minLength(length: number, errorMessage?: string) {\n return this.min(length, errorMessage);\n }\n\n /** Array length must be less than the given length */\n public max(max: number, errorMessage?: string) {\n return this.addRule(maxLengthRule, errorMessage, { maxLength: max });\n }\n\n /** @alias max */\n public maxLength(length: number, errorMessage?: string) {\n return this.max(length, errorMessage);\n }\n\n /** Array length must be of the given length */\n public length(length: number, errorMessage?: string) {\n return this.addRule(lengthRule, errorMessage, { length });\n }\n\n /**\n * Array length must be between min and max (inclusive)\n *\n * @param min - Minimum length (inclusive)\n * @param max - Maximum length (inclusive)\n *\n * @example\n * ```ts\n * v.array(v.string()).between(1, 10) // Array must have 1 to 10 items\n * v.array(v.number()).lengthBetween(5, 20) // Same using alias\n * ```\n *\n * @category Validation Rule\n */\n public between(min: number, max: number, errorMessage?: string) {\n return this.addRule(betweenLengthRule, errorMessage, {\n minLength: min,\n maxLength: max,\n });\n }\n\n /**\n * Alias for between() - array length between min and max\n */\n public lengthBetween(min: number, max: number, errorMessage?: string) {\n return this.between(min, max, errorMessage);\n }\n\n /** Array must have unique values */\n public unique(errorMessage?: string) {\n return this.addRule(uniqueArrayRule, errorMessage);\n }\n\n /** Array must be sorted */\n public sorted(direction: \"asc\" | \"desc\" = \"asc\", errorMessage?: string) {\n return this.addRule(sortedArrayRule, errorMessage, { direction });\n }\n\n /** Mutate the data */\n public mutate(data: any, context: SchemaContext) {\n if (!Array.isArray(data)) return data;\n return super.mutate([...data], context);\n }\n\n /** Validate array\n *\n * Absent input (and absent without `.default()`) propagates as `data: undefined`\n * so the parent ObjectValidator can omit the key. Without this, optional array\n * fields would silently materialise as `[]` in the validated output.\n */\n public async validate(data: any, context: SchemaContext): Promise<ValidationResult> {\n // Apply default when absent, then mutate. Mirrors BaseValidator's\n // `valueForRules = data ?? this.getDefaultValue()` so `.default([...])`\n // works on arrays too.\n const valueForRules = data ?? this.getDefaultValue();\n const mutatedData = await this.mutate(valueForRules, context);\n\n const result = await this.validateRules(data, context);\n\n if (result.isValid === false) return result;\n\n // Nothing to iterate for absent (no default) or null (nullable) inputs —\n // propagate so the parent ObjectValidator can omit the key.\n if (mutatedData === undefined || mutatedData === null) return result;\n\n // Defensive: type rule (arrayRule) should have failed for non-arrays.\n if (!Array.isArray(mutatedData)) return result;\n\n const errors: ValidationResult[\"errors\"] = [];\n\n // Validate all items in parallel (consistent with ObjectValidator)\n const validationPromises = mutatedData.map(async (value: any, index: number) => {\n const childContext: SchemaContext = {\n ...context,\n parent: mutatedData,\n value,\n key: index.toString(),\n path: setKeyPath(context.path, index.toString()),\n };\n\n const childResult = await this.validator.validate(value, childContext);\n\n // Update mutated data with validated result\n mutatedData[index] = childResult.data;\n\n // Collect errors from this element\n if (childResult.isValid === false) {\n errors.push(...childResult.errors);\n }\n });\n\n await Promise.all(validationPromises);\n\n return this.refineResult(\n {\n isValid: errors.length === 0,\n errors,\n data: await this.startTransformationPipeline(mutatedData, context),\n },\n context,\n );\n }\n\n /**\n * @inheritdoc\n *\n * Recursively generates JSON Schema for the array items.\n *\n * @example\n * ```ts\n * v.array(v.string().min(1)).minLength(1).toJsonSchema(\"draft-2020-12\")\n * // → { type: \"array\", items: { type: \"string\", minLength: 1 }, minItems: 1 }\n * ```\n */\n public override toJsonSchema(target: JsonSchemaTarget = \"draft-2020-12\"): JsonSchemaResult {\n const schema: JsonSchemaResult = {\n type: \"array\",\n items: this.validator.toJsonSchema(target),\n };\n\n const minOpts = getRuleOptions(this.rules, \"minLength\");\n if (minOpts?.minLength !== undefined) schema.minItems = minOpts.minLength;\n\n const maxOpts = getRuleOptions(this.rules, \"maxLength\");\n if (maxOpts?.maxLength !== undefined) schema.maxItems = maxOpts.maxLength;\n\n const betweenOpts = getRuleOptions(this.rules, \"betweenLength\");\n if (betweenOpts) {\n if (betweenOpts.minLength !== undefined) schema.minItems = betweenOpts.minLength;\n if (betweenOpts.maxLength !== undefined) schema.maxItems = betweenOpts.maxLength;\n }\n\n const lengthOpts = getRuleOptions(this.rules, \"length\");\n if (lengthOpts?.length !== undefined) {\n schema.minItems = lengthOpts.length;\n schema.maxItems = lengthOpts.length;\n }\n\n if (this.isNullable) applyNullable(schema, target);\n\n return schema;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAmBA,IAAa,iBAAb,cAAoC,cAAc;CAChD,AAAO,YACL,AAAO,WACP,cACA;EACA,MAAM;EAHC;EAIP,KAAK,iBAAiB;EACtB,KAAK,eAAe,WAAW,YAAY;CAC7C;;;;CAKA,AAAO,YAAY,OAAqB;EACtC,OAAO,MAAM,QAAQ,KAAK;CAC5B;;;;CAKA,AAAgB,QAAc;EAC5B,MAAM,SAAS,MAAM,MAAM;EAE3B,OAAO,YAAY,KAAK,UAAU,MAAM;EAExC,OAAO;CACT;;CAGA,AAAO,OAAO;EACZ,OAAO,KAAK,WAAW,gBAAgB;CACzC;;CAGA,AAAO,UAAU;EACf,OAAO,KAAK,WAAW,gBAAgB;CACzC;;CAGA,AAAO,aAAa;EAClB,OAAO,KAAK,WAAW,kBAAkB;CAC3C;;CA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W;GACpC,OAAO,WAAW,WAAW;GAC7B,OAAO,WAAW,WAAW;EAC/B;EAEA,IAAI,KAAK,YAAY,cAAc,QAAQ,MAAM;EAEjD,OAAO;CACT;AACF"}
|
|
@@ -12,6 +12,7 @@ import { ContextualizedTransformer, SimpleTransformerCallback, TransformerCallba
|
|
|
12
12
|
*/
|
|
13
13
|
declare class BaseValidator<TInput = unknown, TOutput = TInput> {
|
|
14
14
|
rules: ContextualSchemaRule[];
|
|
15
|
+
protected refinements: ContextualSchemaRule[];
|
|
15
16
|
mutators: ContextualizedMutator[];
|
|
16
17
|
protected defaultValue: any | (() => any);
|
|
17
18
|
protected description?: string;
|
|
@@ -346,15 +347,12 @@ declare class BaseValidator<TInput = unknown, TOutput = TInput> {
|
|
|
346
347
|
errorMessage?: string;
|
|
347
348
|
}): this;
|
|
348
349
|
/**
|
|
349
|
-
*
|
|
350
|
-
*
|
|
351
|
-
* `value` is deliberately untyped: custom rules run in the rule pipeline,
|
|
352
|
-
* before a container validates its children (an object's fields are not yet
|
|
353
|
-
* validated or defaulted) and, when `firstErrorOnly` is `false` (the default
|
|
354
|
-
* is `true`), even after the type rule has failed. Typing it as the schema
|
|
355
|
-
* output would promise a shape the callback does not always receive.
|
|
350
|
+
* Validate the successful output after type rules, children and transformers.
|
|
351
|
+
* Refinements are skipped for absent/null values and failed validation.
|
|
356
352
|
*/
|
|
357
|
-
refine(callback: (value:
|
|
353
|
+
refine(callback: (value: NonNullable<this["~standard"]["types"]>["output"], context: SchemaContext) => Promise<string | undefined> | string | undefined): this;
|
|
354
|
+
/** Complete validation only after the entire output is available. */
|
|
355
|
+
protected refineResult(result: ValidationResult, context: SchemaContext): Promise<ValidationResult>;
|
|
358
356
|
/**
|
|
359
357
|
* Add mutator to the validator
|
|
360
358
|
*/
|
|
@@ -418,6 +416,8 @@ declare class BaseValidator<TInput = unknown, TOutput = TInput> {
|
|
|
418
416
|
* Validate the data
|
|
419
417
|
*/
|
|
420
418
|
validate(data: any, context: SchemaContext): Promise<ValidationResult>;
|
|
419
|
+
/** Validate presence and value rules before containers descend into children. */
|
|
420
|
+
protected validateRules(data: any, context: SchemaContext): Promise<ValidationResult>;
|
|
421
421
|
/**
|
|
422
422
|
* Set rule attributes list
|
|
423
423
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-validator.d.mts","names":[],"sources":["../../../../../../../../packages/seal/src/validators/base-validator.ts"],"mappings":";;;;;;;;;;;;cAyBa,aAAA,6BAA0C,MAAA;EAC9C,KAAA,EAAO,oBAAA;
|
|
1
|
+
{"version":3,"file":"base-validator.d.mts","names":[],"sources":["../../../../../../../../packages/seal/src/validators/base-validator.ts"],"mappings":";;;;;;;;;;;;cAyBa,aAAA,6BAA0C,MAAA;EAC9C,KAAA,EAAO,oBAAA;EAAA,UACJ,WAAA,EAAa,oBAAA;EAChB,QAAA,EAAU,qBAAA;EAAA,UACP,YAAA;EAAA,UACA,WAAA;EAAA,UACA,UAAA;EAAA,UACA,UAAA;EAAA,UACA,SAAA;EALO;EAAA,UAOP,cAAA;EAW6D;;;;;;;EAAA,UAF7D,UAAA,UAEJ,MAAA,EAAQ,gBAAA,YAA4B,aAAA,gBAA6B,OAAA;EAAA,UAC7D,QAAA;EA6MgE;;;;;;;EApMnE,UAAA;EAyXI;;;;;;;EAhXJ,YAAA,EAAc,oBAAA;EAwZF;;;EAAA,UAnZT,gBAAA,EAAkB,yBAAA;EAsZzB;;;;;EAAA,UA/YO,cAAA,EAAgB,wBAAA;EA8ZF;;;EAAA,UAzZd,oBAAA,EAAsB,MAAA;EAwcb;;;EAAA,IAncR,OAAA;EAidE;;;EAAA,IAzcF,SAAA;EAieA;;;;;EAAA,cAvdG,QAAA;EAujB0B;;;;EA/iBjC,eAAA;EAolB2C;;;;;;EA1kB3C,QAAA;IAAqB,UAAA;EAAA;EAqyBsD;;;;;;EAzxB3E,WAAA;IAAwB,UAAA;EAAA;EA3GxB;;;;;;;;;;;;;;;;;;EAmIA,cAAA,C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|
|
14
14
|
this.rules = [];
|
|
15
|
+
this.refinements = [];
|
|
15
16
|
this.mutators = [];
|
|
16
17
|
this.shouldOmit = false;
|
|
17
18
|
this.isNullable = false;
|
|
@@ -271,6 +272,7 @@ var BaseValidator = class {
|
|
|
271
272
|
const Constructor = this.constructor;
|
|
272
273
|
const cloned = Object.create(Constructor.prototype);
|
|
273
274
|
cloned.rules = [...this.rules];
|
|
275
|
+
cloned.refinements = [...this.refinements];
|
|
274
276
|
cloned.mutators = [...this.mutators];
|
|
275
277
|
cloned.dataTransformers = [...this.dataTransformers];
|
|
276
278
|
cloned.defaultValue = this.defaultValue;
|
|
@@ -415,16 +417,12 @@ var BaseValidator = class {
|
|
|
415
417
|
return this.addRule(rule, errorMessage, ruleOptions);
|
|
416
418
|
}
|
|
417
419
|
/**
|
|
418
|
-
*
|
|
419
|
-
*
|
|
420
|
-
* `value` is deliberately untyped: custom rules run in the rule pipeline,
|
|
421
|
-
* before a container validates its children (an object's fields are not yet
|
|
422
|
-
* validated or defaulted) and, when `firstErrorOnly` is `false` (the default
|
|
423
|
-
* is `true`), even after the type rule has failed. Typing it as the schema
|
|
424
|
-
* output would promise a shape the callback does not always receive.
|
|
420
|
+
* Validate the successful output after type rules, children and transformers.
|
|
421
|
+
* Refinements are skipped for absent/null values and failed validation.
|
|
425
422
|
*/
|
|
426
423
|
refine(callback) {
|
|
427
|
-
|
|
424
|
+
const instance = this.instance;
|
|
425
|
+
instance.refinements.push(instance.createRule({
|
|
428
426
|
name: "custom",
|
|
429
427
|
async validate(value, context) {
|
|
430
428
|
const result = await callback(value, context);
|
|
@@ -434,7 +432,30 @@ var BaseValidator = class {
|
|
|
434
432
|
}
|
|
435
433
|
return VALID_RULE;
|
|
436
434
|
}
|
|
437
|
-
});
|
|
435
|
+
}));
|
|
436
|
+
return instance;
|
|
437
|
+
}
|
|
438
|
+
/** Complete validation only after the entire output is available. */
|
|
439
|
+
async refineResult(result, context) {
|
|
440
|
+
if (!result.isValid || result.data == null) return result;
|
|
441
|
+
const errors = [];
|
|
442
|
+
for (const rule of this.refinements) {
|
|
443
|
+
this.setRuleAttributesList(rule);
|
|
444
|
+
const refined = await rule.validate(result.data, context);
|
|
445
|
+
if (!refined.isValid) {
|
|
446
|
+
errors.push({
|
|
447
|
+
type: rule.name,
|
|
448
|
+
error: refined.error,
|
|
449
|
+
input: refined.path ?? context.path
|
|
450
|
+
});
|
|
451
|
+
if (context.configurations?.firstErrorOnly ?? true) break;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
return errors.length ? {
|
|
455
|
+
isValid: false,
|
|
456
|
+
errors,
|
|
457
|
+
data: void 0
|
|
458
|
+
} : result;
|
|
438
459
|
}
|
|
439
460
|
/**
|
|
440
461
|
* Add mutator to the validator
|
|
@@ -527,6 +548,16 @@ var BaseValidator = class {
|
|
|
527
548
|
* Validate the data
|
|
528
549
|
*/
|
|
529
550
|
async validate(data, context) {
|
|
551
|
+
const result = await this.refineResult(await this.validateRules(data, context), context);
|
|
552
|
+
if (!result.isValid && this.hasCatch) return {
|
|
553
|
+
isValid: true,
|
|
554
|
+
errors: [],
|
|
555
|
+
data: typeof this.catchValue === "function" ? await this.catchValue(result.errors, data) : this.catchValue
|
|
556
|
+
};
|
|
557
|
+
return result;
|
|
558
|
+
}
|
|
559
|
+
/** Validate presence and value rules before containers descend into children. */
|
|
560
|
+
async validateRules(data, context) {
|
|
530
561
|
if (data === null && this.isNullable) return {
|
|
531
562
|
isValid: true,
|
|
532
563
|
errors: [],
|
|
@@ -552,7 +583,7 @@ var BaseValidator = class {
|
|
|
552
583
|
}
|
|
553
584
|
}
|
|
554
585
|
const usedDefault = blankMatchesDefault || input == null && isUsableDefault(valueForRules) || parentFilledDefault && isUsableDefault(input);
|
|
555
|
-
|
|
586
|
+
let mutatedData = this.isOptional && valueForRules === void 0 ? void 0 : await this.mutate(valueForRules, context);
|
|
556
587
|
const errors = [];
|
|
557
588
|
let isValid = true;
|
|
558
589
|
const isFirstErrorOnly = context.configurations?.firstErrorOnly ?? true;
|
|
@@ -563,27 +594,26 @@ var BaseValidator = class {
|
|
|
563
594
|
if ((rule.requiresValue ?? true) && skipEmptyRules) continue;
|
|
564
595
|
this.setRuleAttributesList(rule);
|
|
565
596
|
const result = await rule.validate(mutatedData, context);
|
|
597
|
+
if (result.isValid && "data" in result) mutatedData = result.data;
|
|
566
598
|
if (result.isValid === false) {
|
|
567
599
|
isValid = false;
|
|
568
|
-
errors.
|
|
569
|
-
type: rule.name,
|
|
600
|
+
const reported = result.errors?.length ? result.errors : [{
|
|
570
601
|
error: result.error,
|
|
571
|
-
|
|
602
|
+
path: result.path
|
|
603
|
+
}];
|
|
604
|
+
for (const { error, path } of reported) errors.push({
|
|
605
|
+
type: rule.name,
|
|
606
|
+
error,
|
|
607
|
+
input: path ?? context.path
|
|
572
608
|
});
|
|
573
609
|
if (isFirstErrorOnly) break;
|
|
574
610
|
}
|
|
575
611
|
}
|
|
576
|
-
|
|
612
|
+
return {
|
|
577
613
|
isValid,
|
|
578
614
|
errors,
|
|
579
615
|
data: mutatedData !== void 0 ? await this.startTransformationPipeline(mutatedData, context) : void 0
|
|
580
616
|
};
|
|
581
|
-
if (result.isValid === false && this.hasCatch) return {
|
|
582
|
-
isValid: true,
|
|
583
|
-
errors: [],
|
|
584
|
-
data: typeof this.catchValue === "function" ? await this.catchValue(result.errors, data) : this.catchValue
|
|
585
|
-
};
|
|
586
|
-
return result;
|
|
587
617
|
}
|
|
588
618
|
/**
|
|
589
619
|
* Set rule attributes list
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-validator.mjs","names":["defaultRequiredRule"],"sources":["../../../../../../../../packages/seal/src/validators/base-validator.ts"],"sourcesContent":["import { clone } from \"@mongez/reinforcements\";\nimport { validate } from \"../factory/validate\";\nimport { VALID_RULE, invalidRule } from \"../helpers/validation-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 /** Treat empty or whitespace-only form strings as an absent value. */\n protected blankIsMissing = 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 | ((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, value] of Object.entries(attributes)) {\n instance.attributesText[key] = value;\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, value] of Object.entries(attributes)) {\n instance.translatedAttributes[key] = value;\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.translatedAttributes = { ...this.translatedAttributes };\n cloned.isNullable = this.isNullable;\n cloned.isOptional = this.isOptional;\n cloned.blankIsMissing = this.blankIsMissing;\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 * `value` is deliberately untyped: custom rules run in the rule pipeline,\n * before a container validates its children (an object's fields are not yet\n * validated or defaulted) and, when `firstErrorOnly` is `false` (the default\n * is `true`), even after the type rule has failed. Typing it as the schema\n * output would promise a shape the callback does not always receive.\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 | ((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 isBlank = this.blankIsMissing && typeof data === \"string\" && data.trim() === \"\";\n\n if (isBlank && this.isNullable) {\n return { isValid: true, errors: [], data: null };\n }\n\n const input = isBlank ? undefined : data;\n let valueForRules = input ?? this.getDefaultValue();\n // A parent object pre-fills an absent key with this field's default and\n // flags it; consume the flag so nested item contexts don't inherit it.\n const parentFilledDefault = context?.valueIsDefault === true;\n\n if (parentFilledDefault) context.valueIsDefault = false;\n\n // A default only stands in for a value when it is one the field accepts:\n // a `null` default on a non-nullable field is still \"no value\".\n const isUsableDefault = (value: unknown) =>\n value !== undefined && (value !== null || this.isNullable);\n\n // A present blank string on a field whose default is itself blank is that\n // default (an HTML form posts `note=\"\"` for an untouched input).\n let blankMatchesDefault = false;\n\n if (typeof input === \"string\" && input.trim() === \"\" && this.defaultValue !== undefined) {\n const fallback = this.getDefaultValue();\n\n if (typeof fallback === \"string\" && fallback.trim() === \"\") {\n valueForRules = fallback;\n blankMatchesDefault = true;\n }\n }\n\n // The author's own default is a value, even an empty one: `.default(\"\")`\n // must not fail the required check it exists to satisfy.\n const usedDefault =\n blankMatchesDefault ||\n (input == null && isUsableDefault(valueForRules)) ||\n (parentFilledDefault && isUsableDefault(input));\n // Optional fields with no resolved value are absent, not values to\n // transform. Skipping here protects every mutator while still allowing\n // defaults and present values through the normal mutation pipeline.\n const mutatedData =\n this.isOptional && valueForRules === undefined\n ? undefined\n : 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 // D8 fix (design/core-defects-found.md): for an optional field, only a\n // truly ABSENT value (`valueForRules === undefined` — the key was\n // missing, or was `null`/`undefined` and got coalesced above) may skip\n // the value rules. A PRESENT-but-empty value (e.g. `\"\"` from `?page=`)\n // must still run them, so `v.int().optional()` given `\"\"` fails instead\n // of silently handing back a string that `Infer.Output`'s\n // `number | undefined` forbids. Non-optional fields are unaffected —\n // their `requiredRule` (not nulled out by `.optional()`) already rejects\n // `\"\"` before these rules matter.\n // An empty default of the wrong type (`v.int().default(\"\")`) must still\n // meet the type rule; skipping it would hand back a value `Infer.Output`\n // forbids. An empty default of the right type (`v.string().default(\"\")`)\n // keeps skipping the value rules, so `.min(3).default(\"\")` still passes.\n const emptyDefaultOfWrongType =\n usedDefault && isEmpty && valueForRules !== null && !this.matchesType(valueForRules);\n\n const skipEmptyRules = emptyDefaultOfWrongType\n ? false\n : this.isOptional\n ? valueForRules === undefined\n : isEmpty;\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 =\n this.requiredRule && !usedDefault ? [this.requiredRule, ...this.rules] : this.rules;\n\n for (const rule of rulesToRun) {\n if ((rule.requiresValue ?? true) && skipEmptyRules) 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 rule.context.translatedAttributes = this.translatedAttributes;\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\"): JsonSchemaRes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,kBACF;GAEJ;EACF;EAEA,MAAM,SAA2B;GAC/B;GACA;GACA,MACE,gBAAgB,SACZ,MAAM,KAAK,4BAA4B,aAAa,OAAO,IAC3D;EACR;EAKA,IAAI,OAAO,YAAY,SAAS,KAAK,UAMnC,OAAO;GAAE,SAAS;GAAM,QAAQ,CAAC;GAAG,MAJlC,OAAO,KAAK,eAAe,aACvB,MAAM,KAAK,WAAW,OAAO,QAAQ,IAAI,IACzC,KAAK;EAEwC;EAGrD,OAAO;CACT;;;;CAKA,AAAU,sBAAsB,MAA4B;EAC1D,KAAK,QAAQ,iBACX,OAAO,KAAK,eAAe,KAAK,UAAU,WACrC,KAAK,eAAe,KAAK,QAC1B,KAAK;EACX,KAAK,QAAQ,uBAAuB,KAAK;CAC3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8CA,KAAK,eAA4D;EAC/D,OAAO;GACL,SAAS;GACT,QAAQ;GACR,OAAO;GACP,UAAU,OAAO,UAAmB;IAElC,OAAO,oBAAoB,MADN,SAAS,MAAM,KAAK,CACR;GACnC;GACA,YAAY;IACV,QAAQ,YAAY,KAAK,aAAa,QAAQ,MAAM;IACpD,SAAS,YAAY,KAAK,aAAa,QAAQ,MAAM;GACvD;EACF;CACF;;;;;;;;;;;;;;;;;;;;;;;;;;CA2BA,AAAO,aAAa,UAA4B,iBAAmC;EACjF,OAAO,CAAC;CACV;AACF"}
|
|
1
|
+
{"version":3,"file":"base-validator.mjs","names":["defaultRequiredRule"],"sources":["../../../../../../../../packages/seal/src/validators/base-validator.ts"],"sourcesContent":["import { clone } from \"@mongez/reinforcements\";\nimport { validate } from \"../factory/validate\";\nimport { VALID_RULE, invalidRule } from \"../helpers/validation-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 protected refinements: 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 /** Treat empty or whitespace-only form strings as an absent value. */\n protected blankIsMissing = 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, value] of Object.entries(attributes)) {\n instance.attributesText[key] = value;\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, value] of Object.entries(attributes)) {\n instance.translatedAttributes[key] = value;\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.refinements = [...this.refinements];\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.translatedAttributes = { ...this.translatedAttributes };\n cloned.isNullable = this.isNullable;\n cloned.isOptional = this.isOptional;\n cloned.blankIsMissing = this.blankIsMissing;\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 * Validate the successful output after type rules, children and transformers.\n * Refinements are skipped for absent/null values and failed validation.\n */\n public refine(\n callback: (\n value: NonNullable<this[\"~standard\"][\"types\"]>[\"output\"],\n context: SchemaContext,\n ) => Promise<string | undefined> | string | undefined,\n ): this {\n const instance = this.instance;\n instance.refinements.push(\n instance.createRule({\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 return instance;\n }\n\n /** Complete validation only after the entire output is available. */\n protected async refineResult(\n result: ValidationResult,\n context: SchemaContext,\n ): Promise<ValidationResult> {\n if (!result.isValid || result.data == null) return result;\n\n const errors: ValidationResult[\"errors\"] = [];\n for (const rule of this.refinements) {\n this.setRuleAttributesList(rule);\n const refined = await rule.validate(result.data, context);\n if (!refined.isValid) {\n errors.push({ type: rule.name, error: refined.error, input: refined.path ?? context.path });\n if (context.configurations?.firstErrorOnly ?? true) break;\n }\n }\n return errors.length ? { isValid: false, errors, data: undefined } : result;\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 const result = await this.refineResult(await this.validateRules(data, context), context);\n\n if (!result.isValid && this.hasCatch) {\n const fallback =\n typeof this.catchValue === \"function\"\n ? await this.catchValue(result.errors, data)\n : this.catchValue;\n return { isValid: true, errors: [], data: fallback };\n }\n return result;\n }\n\n /** Validate presence and value rules before containers descend into children. */\n protected async validateRules(data: any, context: SchemaContext): Promise<ValidationResult> {\n if (data === null && this.isNullable) {\n return { isValid: true, errors: [], data: null };\n }\n\n const isBlank = this.blankIsMissing && typeof data === \"string\" && data.trim() === \"\";\n\n if (isBlank && this.isNullable) {\n return { isValid: true, errors: [], data: null };\n }\n\n const input = isBlank ? undefined : data;\n let valueForRules = input ?? this.getDefaultValue();\n // A parent object pre-fills an absent key with this field's default and\n // flags it; consume the flag so nested item contexts don't inherit it.\n const parentFilledDefault = context?.valueIsDefault === true;\n\n if (parentFilledDefault) context.valueIsDefault = false;\n\n // A default only stands in for a value when it is one the field accepts:\n // a `null` default on a non-nullable field is still \"no value\".\n const isUsableDefault = (value: unknown) =>\n value !== undefined && (value !== null || this.isNullable);\n\n // A present blank string on a field whose default is itself blank is that\n // default (an HTML form posts `note=\"\"` for an untouched input).\n let blankMatchesDefault = false;\n\n if (typeof input === \"string\" && input.trim() === \"\" && this.defaultValue !== undefined) {\n const fallback = this.getDefaultValue();\n\n if (typeof fallback === \"string\" && fallback.trim() === \"\") {\n valueForRules = fallback;\n blankMatchesDefault = true;\n }\n }\n\n // The author's own default is a value, even an empty one: `.default(\"\")`\n // must not fail the required check it exists to satisfy.\n const usedDefault =\n blankMatchesDefault ||\n (input == null && isUsableDefault(valueForRules)) ||\n (parentFilledDefault && isUsableDefault(input));\n // Optional fields with no resolved value are absent, not values to\n // transform. Skipping here protects every mutator while still allowing\n // defaults and present values through the normal mutation pipeline.\n let mutatedData =\n this.isOptional && valueForRules === undefined\n ? undefined\n : 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 // D8 fix (design/core-defects-found.md): for an optional field, only a\n // truly ABSENT value (`valueForRules === undefined` — the key was\n // missing, or was `null`/`undefined` and got coalesced above) may skip\n // the value rules. A PRESENT-but-empty value (e.g. `\"\"` from `?page=`)\n // must still run them, so `v.int().optional()` given `\"\"` fails instead\n // of silently handing back a string that `Infer.Output`'s\n // `number | undefined` forbids. Non-optional fields are unaffected —\n // their `requiredRule` (not nulled out by `.optional()`) already rejects\n // `\"\"` before these rules matter.\n // An empty default of the wrong type (`v.int().default(\"\")`) must still\n // meet the type rule; skipping it would hand back a value `Infer.Output`\n // forbids. An empty default of the right type (`v.string().default(\"\")`)\n // keeps skipping the value rules, so `.min(3).default(\"\")` still passes.\n const emptyDefaultOfWrongType =\n usedDefault && isEmpty && valueForRules !== null && !this.matchesType(valueForRules);\n\n const skipEmptyRules = emptyDefaultOfWrongType\n ? false\n : this.isOptional\n ? valueForRules === undefined\n : isEmpty;\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 =\n this.requiredRule && !usedDefault ? [this.requiredRule, ...this.rules] : this.rules;\n\n for (const rule of rulesToRun) {\n if ((rule.requiresValue ?? true) && skipEmptyRules) continue;\n\n this.setRuleAttributesList(rule);\n\n const result = await rule.validate(mutatedData, context);\n\n if (result.isValid && \"data\" in result) {\n mutatedData = result.data;\n }\n\n if (result.isValid === false) {\n isValid = false;\n const reported = result.errors?.length\n ? result.errors\n : [{ error: result.error, path: result.path }];\n\n for (const { error, path } of reported) {\n errors.push({ type: rule.name, error, input: 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 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 rule.context.translatedAttributes = this.translatedAttributes;\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;qBACQ,CAAC;kBACN,CAAC;oBAGrB;oBACA;mBACD;wBAEK;kBAYN;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;EACtB,SAAS,aAAa;EACtB,OAAO;CACT;;;;;;;CAQA,AAAO,cAA4C;EACjD,MAAM,WAAW,KAAK;EACtB,SAAS,aAAa;EACtB,OAAO;CACT;;;;;;;;;;;;;;;;;;;CAoBA,AAAO,eAAe,WAAgC,UAAe,CAAC,GAAG;EACvE,MAAM,WAAW,KAAK;EACtB,SAAS,sBAAsB,WAAW,OAAO;EAEjD,OAAO;CACT;;;;;;;;;;;;;;;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