@oxog/vld 2.1.0 → 2.2.7

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.
Files changed (228) hide show
  1. package/CHANGELOG.md +113 -0
  2. package/README.md +413 -1235
  3. package/dist/chunks/errors-core-CerMg2rq.js +1 -0
  4. package/dist/chunks/index-CkbfQQ4n.js +1 -0
  5. package/dist/chunks/index-yjpbvFgw.js +1 -0
  6. package/dist/chunks/ip-validation-g5LWgy9t.js +1 -0
  7. package/dist/chunks/security-Dy24T8N7.js +1 -0
  8. package/dist/cjs/chunks/errors-core-DrydF46s.cjs +1 -0
  9. package/dist/cjs/chunks/index-BEV9nG0N.cjs +1 -0
  10. package/dist/cjs/chunks/index-ZjHAxYdA.cjs +1 -0
  11. package/dist/cjs/chunks/ip-validation-BZqPamPC.cjs +1 -0
  12. package/dist/cjs/chunks/security-aXZVI7qW.cjs +1 -0
  13. package/dist/cjs/cli/bin.cjs +1 -505
  14. package/dist/cjs/cli/index.cjs +1 -209
  15. package/dist/cjs/codecs/index.cjs +1 -45
  16. package/dist/cjs/coercion/index.cjs +1 -588
  17. package/dist/cjs/compat/emitter.cjs +1 -184
  18. package/dist/cjs/compat/result.cjs +1 -189
  19. package/dist/cjs/errors.cjs +1 -180
  20. package/dist/cjs/index.cjs +1 -1894
  21. package/dist/cjs/kernel.cjs +1 -415
  22. package/dist/cjs/locales/af.cjs +1 -108
  23. package/dist/cjs/locales/ar.cjs +1 -108
  24. package/dist/cjs/locales/bn.cjs +1 -108
  25. package/dist/cjs/locales/da.cjs +1 -108
  26. package/dist/cjs/locales/de.cjs +1 -108
  27. package/dist/cjs/locales/en.cjs +1 -108
  28. package/dist/cjs/locales/es-MX.cjs +1 -107
  29. package/dist/cjs/locales/es.cjs +1 -96
  30. package/dist/cjs/locales/fi.cjs +1 -108
  31. package/dist/cjs/locales/fr.cjs +1 -96
  32. package/dist/cjs/locales/hi.cjs +1 -108
  33. package/dist/cjs/locales/id.cjs +1 -108
  34. package/dist/cjs/locales/index.cjs +1 -43
  35. package/dist/cjs/locales/it.cjs +1 -108
  36. package/dist/cjs/locales/ja.cjs +1 -108
  37. package/dist/cjs/locales/ko.cjs +1 -108
  38. package/dist/cjs/locales/lazy.cjs +1 -188
  39. package/dist/cjs/locales/nl.cjs +1 -108
  40. package/dist/cjs/locales/no.cjs +1 -108
  41. package/dist/cjs/locales/pl.cjs +1 -108
  42. package/dist/cjs/locales/pt-BR.cjs +1 -108
  43. package/dist/cjs/locales/pt.cjs +1 -108
  44. package/dist/cjs/locales/ru.cjs +1 -108
  45. package/dist/cjs/locales/runtime.cjs +1 -51
  46. package/dist/cjs/locales/sv.cjs +1 -108
  47. package/dist/cjs/locales/sw.cjs +1 -108
  48. package/dist/cjs/locales/th.cjs +1 -108
  49. package/dist/cjs/locales/tr.cjs +1 -108
  50. package/dist/cjs/locales/vi.cjs +1 -108
  51. package/dist/cjs/locales/zh.cjs +1 -108
  52. package/dist/cjs/mini.cjs +1 -242
  53. package/dist/cjs/pigment.cjs +1 -207
  54. package/dist/cjs/plugins/index.cjs +1 -12
  55. package/dist/cjs/registry.cjs +1 -37
  56. package/dist/cjs/v3/index.cjs +1 -425
  57. package/dist/cjs/v4/core/index.cjs +1 -894
  58. package/dist/cjs/v4/index.cjs +1 -425
  59. package/dist/cjs/v4/locales/index.cjs +1 -130
  60. package/dist/cjs/v4/mini/index.cjs +1 -509
  61. package/dist/cjs/v4-mini/index.cjs +1 -532
  62. package/dist/cjs/validators/any.cjs +1 -40
  63. package/dist/cjs/validators/array.cjs +1 -283
  64. package/dist/cjs/validators/base.cjs +1 -887
  65. package/dist/cjs/validators/base64.cjs +1 -73
  66. package/dist/cjs/validators/bigint.cjs +1 -232
  67. package/dist/cjs/validators/boolean.cjs +1 -146
  68. package/dist/cjs/validators/codec.cjs +1 -205
  69. package/dist/cjs/validators/custom.cjs +1 -71
  70. package/dist/cjs/validators/date.cjs +1 -278
  71. package/dist/cjs/validators/discriminated-union.cjs +1 -130
  72. package/dist/cjs/validators/enum.cjs +1 -154
  73. package/dist/cjs/validators/file.cjs +1 -130
  74. package/dist/cjs/validators/function.cjs +1 -63
  75. package/dist/cjs/validators/hex.cjs +1 -70
  76. package/dist/cjs/validators/index.cjs +1 -123
  77. package/dist/cjs/validators/intersection.cjs +1 -120
  78. package/dist/cjs/validators/json.cjs +1 -70
  79. package/dist/cjs/validators/lazy.cjs +1 -53
  80. package/dist/cjs/validators/literal.cjs +1 -64
  81. package/dist/cjs/validators/map.cjs +1 -218
  82. package/dist/cjs/validators/nan.cjs +1 -41
  83. package/dist/cjs/validators/never.cjs +1 -36
  84. package/dist/cjs/validators/null.cjs +1 -43
  85. package/dist/cjs/validators/number.cjs +1 -427
  86. package/dist/cjs/validators/object.cjs +1 -868
  87. package/dist/cjs/validators/promise.cjs +1 -115
  88. package/dist/cjs/validators/record.cjs +1 -262
  89. package/dist/cjs/validators/set.cjs +1 -203
  90. package/dist/cjs/validators/string-bool.cjs +1 -124
  91. package/dist/cjs/validators/string-formats.cjs +1 -168
  92. package/dist/cjs/validators/string.cjs +1 -12
  93. package/dist/cjs/validators/symbol.cjs +1 -62
  94. package/dist/cjs/validators/template-literal.cjs +1 -108
  95. package/dist/cjs/validators/tuple.cjs +1 -187
  96. package/dist/cjs/validators/uint8array.cjs +1 -106
  97. package/dist/cjs/validators/undefined.cjs +1 -43
  98. package/dist/cjs/validators/union.cjs +1 -191
  99. package/dist/cjs/validators/unknown.cjs +1 -40
  100. package/dist/cjs/validators/void.cjs +1 -48
  101. package/dist/cjs/validators/xor.cjs +1 -69
  102. package/dist/cli/bin.js +1 -406
  103. package/dist/cli/index.js +1 -205
  104. package/dist/codecs/index.js +1 -11
  105. package/dist/coercion/index.js +1 -579
  106. package/dist/compat/emitter.js +1 -180
  107. package/dist/compat/result.js +1 -170
  108. package/dist/errors-core.d.ts +32 -2
  109. package/dist/errors.js +1 -171
  110. package/dist/index.d.ts +315 -361
  111. package/dist/index.js +1 -1534
  112. package/dist/kernel.js +1 -409
  113. package/dist/locales/af.js +1 -106
  114. package/dist/locales/ar.js +1 -106
  115. package/dist/locales/bn.js +1 -106
  116. package/dist/locales/da.js +1 -106
  117. package/dist/locales/de.js +1 -106
  118. package/dist/locales/en.js +1 -106
  119. package/dist/locales/es-MX.js +1 -105
  120. package/dist/locales/es.js +1 -94
  121. package/dist/locales/fi.js +1 -106
  122. package/dist/locales/fr.js +1 -94
  123. package/dist/locales/hi.js +1 -106
  124. package/dist/locales/id.js +1 -106
  125. package/dist/locales/index.js +1 -29
  126. package/dist/locales/it.js +1 -106
  127. package/dist/locales/ja.js +1 -106
  128. package/dist/locales/ko.js +1 -106
  129. package/dist/locales/lazy.js +1 -177
  130. package/dist/locales/nl.js +1 -106
  131. package/dist/locales/no.js +1 -106
  132. package/dist/locales/pl.js +1 -106
  133. package/dist/locales/pt-BR.js +1 -106
  134. package/dist/locales/pt.js +1 -106
  135. package/dist/locales/ru.js +1 -106
  136. package/dist/locales/runtime.js +1 -41
  137. package/dist/locales/sv.js +1 -106
  138. package/dist/locales/sw.js +1 -106
  139. package/dist/locales/th.js +1 -106
  140. package/dist/locales/tr.js +1 -106
  141. package/dist/locales/vi.js +1 -106
  142. package/dist/locales/zh.js +1 -106
  143. package/dist/mini.d.ts +3 -3
  144. package/dist/mini.js +1 -156
  145. package/dist/pigment.js +1 -180
  146. package/dist/plugins/index.js +1 -1
  147. package/dist/registry.js +1 -34
  148. package/dist/utils/json-schema.d.ts +10 -1
  149. package/dist/v3/index.js +1 -46
  150. package/dist/v4/core/index.d.ts +28 -16
  151. package/dist/v4/core/index.js +1 -277
  152. package/dist/v4/index.js +1 -50
  153. package/dist/v4/locales/index.d.ts +4 -0
  154. package/dist/v4/locales/index.js +1 -77
  155. package/dist/v4/mini/index.js +1 -47
  156. package/dist/v4-mini/index.d.ts +1 -1
  157. package/dist/v4-mini/index.js +1 -75
  158. package/dist/validators/any.js +1 -37
  159. package/dist/validators/array.d.ts +7 -0
  160. package/dist/validators/array.js +1 -279
  161. package/dist/validators/base.d.ts +210 -17
  162. package/dist/validators/base.js +1 -868
  163. package/dist/validators/base64.js +1 -68
  164. package/dist/validators/bigint.d.ts +7 -0
  165. package/dist/validators/bigint.js +1 -228
  166. package/dist/validators/boolean.js +1 -142
  167. package/dist/validators/codec.js +1 -200
  168. package/dist/validators/custom.d.ts +20 -10
  169. package/dist/validators/custom.js +1 -67
  170. package/dist/validators/date.d.ts +2 -0
  171. package/dist/validators/date.js +1 -274
  172. package/dist/validators/discriminated-union.d.ts +4 -2
  173. package/dist/validators/discriminated-union.js +1 -123
  174. package/dist/validators/enum.d.ts +8 -2
  175. package/dist/validators/enum.js +1 -150
  176. package/dist/validators/file.js +1 -125
  177. package/dist/validators/function.js +1 -58
  178. package/dist/validators/hex.js +1 -65
  179. package/dist/validators/index.d.ts +1 -1
  180. package/dist/validators/index.js +1 -35
  181. package/dist/validators/intersection.js +1 -116
  182. package/dist/validators/json.js +1 -66
  183. package/dist/validators/lazy.js +1 -50
  184. package/dist/validators/literal.d.ts +8 -3
  185. package/dist/validators/literal.js +1 -60
  186. package/dist/validators/map.d.ts +7 -0
  187. package/dist/validators/map.js +1 -214
  188. package/dist/validators/nan.js +1 -38
  189. package/dist/validators/never.js +1 -32
  190. package/dist/validators/null.js +1 -40
  191. package/dist/validators/number.d.ts +25 -1
  192. package/dist/validators/number.js +1 -423
  193. package/dist/validators/object.d.ts +18 -2
  194. package/dist/validators/object.js +1 -864
  195. package/dist/validators/promise.d.ts +6 -7
  196. package/dist/validators/promise.js +1 -111
  197. package/dist/validators/record.d.ts +13 -8
  198. package/dist/validators/record.js +1 -258
  199. package/dist/validators/set.d.ts +5 -0
  200. package/dist/validators/set.js +1 -199
  201. package/dist/validators/string-bool.js +1 -120
  202. package/dist/validators/string-formats.d.ts +58 -62
  203. package/dist/validators/string-formats.js +1 -135
  204. package/dist/validators/string.d.ts +49 -10
  205. package/dist/validators/string.js +1 -4
  206. package/dist/validators/symbol.js +1 -58
  207. package/dist/validators/template-literal.js +1 -103
  208. package/dist/validators/tuple.d.ts +17 -13
  209. package/dist/validators/tuple.js +1 -183
  210. package/dist/validators/uint8array.js +1 -101
  211. package/dist/validators/undefined.js +1 -40
  212. package/dist/validators/union.d.ts +1 -0
  213. package/dist/validators/union.js +1 -187
  214. package/dist/validators/unknown.js +1 -37
  215. package/dist/validators/void.js +1 -44
  216. package/dist/validators/xor.d.ts +2 -2
  217. package/dist/validators/xor.js +1 -66
  218. package/package.json +240 -238
  219. package/dist/chunks/errors-core-BeiFUtZM.js +0 -81
  220. package/dist/chunks/index-0R2ntSud.js +0 -508
  221. package/dist/chunks/index-BvH403Yy.js +0 -88
  222. package/dist/chunks/security-B0Pd_vSY.js +0 -35
  223. package/dist/chunks/string-BJRQod3t.js +0 -530
  224. package/dist/cjs/chunks/errors-core-DWxLFs2f.cjs +0 -83
  225. package/dist/cjs/chunks/index-BkI37108.cjs +0 -538
  226. package/dist/cjs/chunks/index-Cc3bjUMX.cjs +0 -91
  227. package/dist/cjs/chunks/security-Dc3Jh13T.cjs +0 -37
  228. package/dist/cjs/chunks/string-BKZrc4hs.cjs +0 -533
@@ -1,40 +1 @@
1
- import { VldBase, VLD_VALIDATOR_TYPES } from './base.js';
2
- import { V as VldError } from '../chunks/errors-core-BeiFUtZM.js';
3
-
4
- /**
5
- * VldUndefined - Validates that a value is exactly undefined
6
- * Part of Zod 4 API parity implementation
7
- */
8
- function createUndefinedError(message) {
9
- return new VldError([{ code: 'invalid_type', path: [], message }]);
10
- }
11
- /**
12
- * Undefined validator - validates that a value is exactly undefined
13
- */
14
- class VldUndefined extends VldBase {
15
- constructor() {
16
- super(VLD_VALIDATOR_TYPES.UNDEFINED);
17
- }
18
- static create() {
19
- return new VldUndefined();
20
- }
21
- get isSimple() {
22
- return true;
23
- }
24
- parse(value) {
25
- if (value !== undefined) {
26
- throw new Error(`Expected undefined, received ${typeof value}`);
27
- }
28
- return undefined;
29
- }
30
- safeParse(value) {
31
- try {
32
- return { success: true, data: this.parse(value) };
33
- }
34
- catch (error) {
35
- return { success: false, error: createUndefinedError(error.message) };
36
- }
37
- }
38
- }
39
-
40
- export { VldUndefined };
1
+ import{VldBase as e,VLD_VALIDATOR_TYPES as r}from"./base.js";import{V as s}from"../chunks/errors-core-CerMg2rq.js";class VldUndefined extends e{constructor(){super(r.UNDEFINED)}static create(){return new VldUndefined}get isSimple(){return!0}parse(e){if(void 0!==e)throw new Error("Expected undefined, received "+typeof e)}safeParse(e){try{return{success:!0,data:this.parse(e)}}catch(e){return{success:!1,error:(r=e.message,new s([{code:"invalid_type",path:[],message:r}]))}}var r}}export{VldUndefined};
@@ -13,6 +13,7 @@ export declare class VldUnion<T extends readonly VldBase<any, any>[]> extends Vl
13
13
  * Private constructor to enforce immutability
14
14
  */
15
15
  private constructor();
16
+ get options(): T;
16
17
  private createSimpleMode;
17
18
  private parseSimpleValue;
18
19
  /**
@@ -1,187 +1 @@
1
- import { VldBase, VLD_VALIDATOR_TYPES } from './base.js';
2
- import { getMessages } from '../locales/runtime.js';
3
-
4
- /**
5
- * Optimized immutable union validator for multiple type options
6
- * Features type-checking shortcuts for 110x performance improvement
7
- */
8
- class VldUnion extends VldBase {
9
- /**
10
- * Private constructor to enforce immutability
11
- */
12
- constructor(validators, errorMessage) {
13
- super(VLD_VALIDATOR_TYPES.UNION);
14
- this.validators = validators;
15
- this.errorMessage = errorMessage;
16
- this.typeCheckers = validators.map(validator => this.createTypeChecker(validator));
17
- this.simpleModes = validators.map(validator => this.createSimpleMode(validator));
18
- this.simpleValues = validators.map((validator, i) => this.simpleModes[i] === 'literal' ? validator.literal : undefined);
19
- }
20
- createSimpleMode(validator) {
21
- if (validator.isSimple !== true) {
22
- return undefined;
23
- }
24
- switch (validator.validatorType) {
25
- case VLD_VALIDATOR_TYPES.STRING:
26
- return 'string';
27
- case VLD_VALIDATOR_TYPES.NUMBER:
28
- return 'number';
29
- case VLD_VALIDATOR_TYPES.BOOLEAN:
30
- return 'boolean';
31
- case VLD_VALIDATOR_TYPES.BIGINT:
32
- return 'bigint';
33
- case VLD_VALIDATOR_TYPES.SYMBOL:
34
- return 'symbol';
35
- case VLD_VALIDATOR_TYPES.NULL:
36
- return 'null';
37
- case VLD_VALIDATOR_TYPES.UNDEFINED:
38
- case VLD_VALIDATOR_TYPES.VOID:
39
- return 'undefined';
40
- case VLD_VALIDATOR_TYPES.LITERAL:
41
- return 'literal';
42
- case VLD_VALIDATOR_TYPES.ANY:
43
- case VLD_VALIDATOR_TYPES.UNKNOWN:
44
- return 'passthrough';
45
- default:
46
- return undefined;
47
- }
48
- }
49
- parseSimpleValue(mode, index, value) {
50
- switch (mode) {
51
- case 'string':
52
- case 'number':
53
- case 'boolean':
54
- case 'bigint':
55
- case 'symbol':
56
- return value;
57
- case 'null':
58
- return null;
59
- case 'undefined':
60
- return undefined;
61
- case 'literal':
62
- return this.simpleValues[index];
63
- case 'passthrough':
64
- return value;
65
- default:
66
- return undefined;
67
- }
68
- }
69
- /**
70
- * Create type checker based on validator type for fast path optimization
71
- * Uses a safer approach that's less prone to spoofing
72
- */
73
- createTypeChecker(validator) {
74
- switch (validator.validatorType) {
75
- case VLD_VALIDATOR_TYPES.STRING:
76
- return (v) => typeof v === 'string';
77
- case VLD_VALIDATOR_TYPES.NUMBER:
78
- return (v) => typeof v === 'number' && !isNaN(v);
79
- case VLD_VALIDATOR_TYPES.BOOLEAN:
80
- return (v) => typeof v === 'boolean';
81
- case VLD_VALIDATOR_TYPES.BIGINT:
82
- return (v) => typeof v === 'bigint';
83
- case VLD_VALIDATOR_TYPES.SYMBOL:
84
- return (v) => typeof v === 'symbol';
85
- case VLD_VALIDATOR_TYPES.NAN:
86
- return (v) => typeof v === 'number' && Number.isNaN(v);
87
- case VLD_VALIDATOR_TYPES.ARRAY:
88
- return Array.isArray;
89
- case VLD_VALIDATOR_TYPES.OBJECT:
90
- return (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
91
- case VLD_VALIDATOR_TYPES.NULL:
92
- return (v) => v === null;
93
- case VLD_VALIDATOR_TYPES.UNDEFINED:
94
- case VLD_VALIDATOR_TYPES.VOID:
95
- return (v) => v === undefined;
96
- case VLD_VALIDATOR_TYPES.ENUM:
97
- return (v) => typeof v === 'string' || typeof v === 'number';
98
- case VLD_VALIDATOR_TYPES.LITERAL: {
99
- const literal = validator.literal;
100
- return (v) => v === literal;
101
- }
102
- case VLD_VALIDATOR_TYPES.NEVER:
103
- return () => false;
104
- case VLD_VALIDATOR_TYPES.ANY:
105
- case VLD_VALIDATOR_TYPES.UNKNOWN:
106
- return () => true;
107
- default:
108
- return () => true;
109
- }
110
- }
111
- /**
112
- * Create a new union validator
113
- */
114
- static create(...validators) {
115
- return new VldUnion(validators);
116
- }
117
- /**
118
- * Parse and validate a value against union options
119
- * Optimized with type checking and direct parsing to avoid success-result allocations
120
- * BUG-NEW-013 FIX: Single-pass error collection to avoid double parsing
121
- */
122
- parse(value) {
123
- // Single pass: collect errors during validation
124
- const errors = [];
125
- for (let i = 0; i < this.validators.length; i++) {
126
- const validator = this.validators[i];
127
- const typeChecker = this.typeCheckers[i];
128
- // Skip validators that definitely won't match based on type
129
- if (typeChecker && !typeChecker(value)) {
130
- continue;
131
- }
132
- const simpleMode = this.simpleModes[i];
133
- if (simpleMode !== undefined) {
134
- return this.parseSimpleValue(simpleMode, i, value);
135
- }
136
- try {
137
- return validator.parse(value);
138
- }
139
- catch (error) {
140
- const message = error instanceof Error ? error.message : String(error);
141
- errors.push(message);
142
- }
143
- }
144
- // All validators failed - throw with collected errors
145
- throw new Error(this.errorMessage ||
146
- getMessages().unionNoMatch(errors));
147
- }
148
- /**
149
- * Safely parse and validate a value against union options
150
- * Optimized version using type checking shortcuts
151
- * BUG-NEW-013 FIX: Single-pass error collection to avoid double parsing
152
- */
153
- safeParse(value) {
154
- // Single pass: collect errors during validation
155
- const errors = [];
156
- for (let i = 0; i < this.validators.length; i++) {
157
- const validator = this.validators[i];
158
- const typeChecker = this.typeCheckers[i];
159
- // Skip validators that definitely won't match based on type
160
- if (typeChecker && !typeChecker(value)) {
161
- continue;
162
- }
163
- const simpleMode = this.simpleModes[i];
164
- if (simpleMode !== undefined) {
165
- return {
166
- success: true,
167
- data: this.parseSimpleValue(simpleMode, i, value)
168
- };
169
- }
170
- try {
171
- return { success: true, data: validator.parse(value) };
172
- }
173
- catch (error) {
174
- const message = error instanceof Error ? error.message : String(error);
175
- errors.push(message);
176
- }
177
- }
178
- // All validators failed - return error with collected messages
179
- return {
180
- success: false,
181
- error: new Error(this.errorMessage ||
182
- getMessages().unionNoMatch(errors))
183
- };
184
- }
185
- }
186
-
187
- export { VldUnion };
1
+ import{VldBase as e,VLD_VALIDATOR_TYPES as r,ensureVldError as s}from"./base.js";import{getMessages as t}from"../locales/runtime.js";class VldUnion extends e{constructor(e,s){super(r.UNION),this.validators=e,this.errorMessage=s,this.typeCheckers=e.map(e=>this.createTypeChecker(e)),this.simpleModes=e.map(e=>this.createSimpleMode(e)),this.simpleValues=e.map((e,r)=>"literal"===this.simpleModes[r]?e.literal:void 0)}get options(){return this.validators}createSimpleMode(e){if(!0===e.isSimple)switch(e.validatorType){case r.STRING:return"string";case r.NUMBER:return"number";case r.BOOLEAN:return"boolean";case r.BIGINT:return"bigint";case r.SYMBOL:return"symbol";case r.NULL:return"null";case r.UNDEFINED:case r.VOID:return"undefined";case r.LITERAL:return"literal";case r.ANY:case r.UNKNOWN:return"passthrough";default:return}}parseSimpleValue(e,r,s){switch(e){case"string":case"number":case"boolean":case"bigint":case"symbol":case"passthrough":return s;case"null":return null;case"undefined":default:return;case"literal":return this.simpleValues[r]}}createTypeChecker(e){switch(e.validatorType){case r.STRING:return e=>"string"==typeof e;case r.NUMBER:return e=>"number"==typeof e&&!isNaN(e);case r.BOOLEAN:return e=>"boolean"==typeof e;case r.BIGINT:return e=>"bigint"==typeof e;case r.SYMBOL:return e=>"symbol"==typeof e;case r.NAN:return e=>"number"==typeof e&&Number.isNaN(e);case r.ARRAY:return Array.isArray;case r.OBJECT:return e=>"object"==typeof e&&null!==e&&!Array.isArray(e);case r.NULL:return e=>null===e;case r.UNDEFINED:case r.VOID:return e=>void 0===e;case r.ENUM:return e=>"string"==typeof e||"number"==typeof e;case r.LITERAL:{const r=e.literal;return e=>e===r}case r.NEVER:return()=>!1;case r.ANY:case r.UNKNOWN:default:return()=>!0}}static create(...e){return new VldUnion(e)}parse(e){const r=[];for(let s=0;s<this.validators.length;s++){const t=this.validators[s],a=this.typeCheckers[s];if(a&&!a(e))continue;const n=this.simpleModes[s];if(void 0!==n)return this.parseSimpleValue(n,s,e);try{return t.parse(e)}catch(e){const s=e instanceof Error?e.message:String(e);r.push(s)}}throw new Error(this.errorMessage||t().unionNoMatch(r))}safeParse(e){const r=[];for(let s=0;s<this.validators.length;s++){const t=this.validators[s],a=this.typeCheckers[s];if(a&&!a(e))continue;const n=this.simpleModes[s];if(void 0!==n)return{success:!0,data:this.parseSimpleValue(n,s,e)};try{return{success:!0,data:t.parse(e)}}catch(e){const s=e instanceof Error?e.message:String(e);r.push(s)}}return{success:!1,error:s(this.errorMessage||t().unionNoMatch(r))}}}export{VldUnion};
@@ -1,37 +1 @@
1
- import { VldBase, VLD_VALIDATOR_TYPES } from './base.js';
2
-
3
- /**
4
- * Validator that accepts unknown values
5
- */
6
- class VldUnknown extends VldBase {
7
- constructor() {
8
- super(VLD_VALIDATOR_TYPES.UNKNOWN);
9
- }
10
- /**
11
- * Create a new unknown validator
12
- */
13
- static create() {
14
- return new VldUnknown();
15
- }
16
- /**
17
- * Returns true because unknown accepts every input without checks.
18
- * Used by composite validators for passthrough fast paths.
19
- */
20
- get isSimple() {
21
- return true;
22
- }
23
- /**
24
- * Parse unknown value (always succeeds)
25
- */
26
- parse(value) {
27
- return value;
28
- }
29
- /**
30
- * Safely parse unknown value (always succeeds)
31
- */
32
- safeParse(value) {
33
- return { success: true, data: value };
34
- }
35
- }
36
-
37
- export { VldUnknown };
1
+ import{VldBase as e,VLD_VALIDATOR_TYPES as r}from"./base.js";class VldUnknown extends e{constructor(){super(r.UNKNOWN)}static create(){return new VldUnknown}get isSimple(){return!0}parse(e){return e}safeParse(e){return{success:!0,data:e}}}export{VldUnknown};
@@ -1,44 +1 @@
1
- import { VldBase, VLD_VALIDATOR_TYPES } from './base.js';
2
- import { getMessages } from '../locales/runtime.js';
3
- import { V as VldError } from '../chunks/errors-core-BeiFUtZM.js';
4
-
5
- /**
6
- * Validator that only accepts undefined
7
- */
8
- class VldVoid extends VldBase {
9
- constructor() {
10
- super(VLD_VALIDATOR_TYPES.VOID);
11
- }
12
- /**
13
- * Create a new void validator
14
- */
15
- static create() {
16
- return new VldVoid();
17
- }
18
- get isSimple() {
19
- return true;
20
- }
21
- /**
22
- * Parse void value (must be undefined)
23
- */
24
- parse(value) {
25
- if (value !== undefined) {
26
- throw new Error(getMessages().expectedUndefined);
27
- }
28
- return undefined;
29
- }
30
- /**
31
- * Safely parse void value
32
- */
33
- safeParse(value) {
34
- if (value === undefined) {
35
- return { success: true, data: undefined };
36
- }
37
- return {
38
- success: false,
39
- error: new VldError([{ code: 'invalid_type', path: [], message: getMessages().expectedUndefined }])
40
- };
41
- }
42
- }
43
-
44
- export { VldVoid };
1
+ import{VldBase as e,VLD_VALIDATOR_TYPES as r}from"./base.js";import{getMessages as s}from"../locales/runtime.js";import{V as o}from"../chunks/errors-core-CerMg2rq.js";class VldVoid extends e{constructor(){super(r.VOID)}static create(){return new VldVoid}get isSimple(){return!0}parse(e){if(void 0!==e)throw new Error(s().expectedUndefined)}safeParse(e){return void 0===e?{success:!0,data:void 0}:{success:!1,error:new o([{code:"invalid_type",path:[],message:s().expectedUndefined}])}}}export{VldVoid};
@@ -9,10 +9,10 @@ import type { ParseResult } from './base.js';
9
9
  * XOR validator - ensures exactly one option matches
10
10
  * Unlike regular union which allows multiple matches, XOR requires exactly one
11
11
  */
12
- export declare class VldXor<Options extends VldBase<any, any>[]> extends VldBase<unknown, Options[number] extends VldBase<any, infer T> ? T : never> {
12
+ export declare class VldXor<Options extends readonly VldBase<any, any>[]> extends VldBase<unknown, Options[number] extends VldBase<any, infer T> ? T : never> {
13
13
  private readonly _options;
14
14
  constructor(_options: Options);
15
- static create<Options extends VldBase<any, any>[]>(options: Options): VldXor<Options>;
15
+ static create<Options extends readonly VldBase<any, any>[]>(options: Options): VldXor<Options>;
16
16
  parse(value: unknown): Options[number] extends VldBase<any, infer T> ? T : never;
17
17
  safeParse(value: unknown): ParseResult<Options[number] extends VldBase<any, infer T> ? T : never>;
18
18
  /**
@@ -1,66 +1 @@
1
- import { VldBase, VLD_VALIDATOR_TYPES } from './base.js';
2
-
3
- /**
4
- * VldXor - Exclusive union validator
5
- * Part of Zod 4 API parity implementation
6
- * Ensures exactly one schema in the union matches
7
- */
8
- /**
9
- * XOR validator - ensures exactly one option matches
10
- * Unlike regular union which allows multiple matches, XOR requires exactly one
11
- */
12
- class VldXor extends VldBase {
13
- constructor(_options) {
14
- super(VLD_VALIDATOR_TYPES.XOR);
15
- this._options = _options;
16
- }
17
- static create(options) {
18
- if (options.length < 2) {
19
- throw new Error('XOR requires at least 2 options');
20
- }
21
- return new VldXor(options);
22
- }
23
- parse(value) {
24
- const result = this.safeParse(value);
25
- if (!result.success) {
26
- throw result.error;
27
- }
28
- return result.data;
29
- }
30
- safeParse(value) {
31
- let matchCount = 0;
32
- let lastSuccess = null;
33
- for (const option of this._options) {
34
- const result = option.safeParse(value);
35
- if (result.success) {
36
- matchCount++;
37
- lastSuccess = result;
38
- if (matchCount > 1) {
39
- // Early exit if more than one match
40
- break;
41
- }
42
- }
43
- }
44
- if (matchCount === 0) {
45
- return {
46
- success: false,
47
- error: new Error('No schema matched in XOR union')
48
- };
49
- }
50
- if (matchCount > 1) {
51
- return {
52
- success: false,
53
- error: new Error(`Input matches ${matchCount} schemas in XOR union, but exactly one is required`)
54
- };
55
- }
56
- return lastSuccess;
57
- }
58
- /**
59
- * Get all options
60
- */
61
- getOptions() {
62
- return this._options;
63
- }
64
- }
65
-
66
- export { VldXor };
1
+ import{VldBase as s,VLD_VALIDATOR_TYPES as e,ensureVldError as r}from"./base.js";class VldXor extends s{constructor(s){super(e.XOR),this._options=s}static create(s){return new VldXor(s)}parse(s){const e=this.safeParse(s);if(!e.success)throw e.error;return e.data}safeParse(s){let e=0,t=null;for(const r of this._options){const o=r.safeParse(s);if(o.success&&(e++,t=o,e>1))break}return 0===e?{success:!1,error:r("No schema matched in XOR union")}:e>1?{success:!1,error:r(`Input matches ${e} schemas in XOR union, but exactly one is required`)}:t}getOptions(){return this._options}}export{VldXor};