@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,868 +1 @@
1
- import { globalRegistry } from '../registry.js';
2
-
3
- /**
4
- * Validator type constants for O(1) dispatch
5
- * Used by VldObject to replace instanceof chains with Map lookups
6
- */
7
- const VLD_VALIDATOR_TYPES = {
8
- // Primitives
9
- STRING: 'string',
10
- STRING_FORMAT: 'stringFormat',
11
- STRING_BOOL: 'stringBool',
12
- NUMBER: 'number',
13
- BOOLEAN: 'boolean',
14
- DATE: 'date',
15
- BIGINT: 'bigint',
16
- UNDEFINED: 'undefined',
17
- NULL: 'null',
18
- UNKNOWN: 'unknown',
19
- ANY: 'any',
20
- VOID: 'void',
21
- NEVER: 'never',
22
- SYMBOL: 'symbol',
23
- NAN: 'nan',
24
- HEX: 'hex',
25
- BASE64: 'base64',
26
- UINT8_ARRAY: 'uint8Array',
27
- // Coercion
28
- COERCE_STRING: 'coerceString',
29
- COERCE_NUMBER: 'coerceNumber',
30
- COERCE_BOOLEAN: 'coerceBoolean',
31
- COERCE_DATE: 'coerceDate',
32
- COERCE_BIGINT: 'coerceBigint',
33
- // Composite
34
- OBJECT: 'object',
35
- ARRAY: 'array',
36
- TUPLE: 'tuple',
37
- SET: 'set',
38
- MAP: 'map',
39
- RECORD: 'record',
40
- // Union types
41
- UNION: 'union',
42
- DISCRIMINATED_UNION: 'discriminatedUnion',
43
- INTERSECTION: 'intersection',
44
- XOR: 'xor',
45
- // Values
46
- ENUM: 'enum',
47
- LITERAL: 'literal',
48
- // Special validators
49
- LAZY: 'lazy',
50
- CUSTOM: 'custom',
51
- FUNCTION: 'function',
52
- FILE: 'file',
53
- JSON: 'json',
54
- TEMPLATE_LITERAL: 'templateLiteral',
55
- PROMISE: 'promise',
56
- // Wrapper/Modifier validators
57
- OPTIONAL: 'optional',
58
- NULLABLE: 'nullable',
59
- NULLISH: 'nullish',
60
- EXACT_OPTIONAL: 'exactOptional',
61
- DEFAULT: 'default',
62
- CATCH: 'catch',
63
- REFINE: 'refine',
64
- TRANSFORM: 'transform',
65
- PIPE: 'pipe',
66
- PREPROCESS: 'preprocess',
67
- SUPER_REFINE: 'superRefine',
68
- BRAND: 'brand',
69
- READONLY: 'readonly',
70
- META: 'meta',
71
- PREFAULT: 'prefault',
72
- PREFault: 'prefault',
73
- // Codec
74
- CODEC: 'codec',
75
- };
76
- function resolveErrorMessage(error, fallback) {
77
- if (typeof error === 'string') {
78
- return error;
79
- }
80
- if (typeof error?.error === 'string') {
81
- return error.error;
82
- }
83
- if (typeof error?.error === 'function') {
84
- return error.error({}) || fallback;
85
- }
86
- if (typeof error?.message === 'string') {
87
- return error.message;
88
- }
89
- return fallback;
90
- }
91
- function isPromiseLike(value) {
92
- return value !== null &&
93
- (typeof value === 'object' || typeof value === 'function') &&
94
- typeof value.then === 'function';
95
- }
96
- function getSimpleWrappedMode(baseValidator) {
97
- if (baseValidator.isSimple !== true) {
98
- return undefined;
99
- }
100
- switch (baseValidator.validatorType) {
101
- case VLD_VALIDATOR_TYPES.STRING:
102
- return 'string';
103
- case VLD_VALIDATOR_TYPES.NUMBER:
104
- return 'number';
105
- case VLD_VALIDATOR_TYPES.BOOLEAN:
106
- return 'boolean';
107
- case VLD_VALIDATOR_TYPES.BIGINT:
108
- return 'bigint';
109
- case VLD_VALIDATOR_TYPES.SYMBOL:
110
- return 'symbol';
111
- default:
112
- return undefined;
113
- }
114
- }
115
- function parseSimpleWrappedValue(mode, value) {
116
- switch (mode) {
117
- case 'string':
118
- return typeof value === 'string' ? value : undefined;
119
- case 'number':
120
- return typeof value === 'number' && !isNaN(value) ? value : undefined;
121
- case 'boolean':
122
- return typeof value === 'boolean' ? value : undefined;
123
- case 'bigint':
124
- return typeof value === 'bigint' ? value : undefined;
125
- case 'symbol':
126
- return typeof value === 'symbol' ? value : undefined;
127
- default:
128
- return undefined;
129
- }
130
- }
131
- /**
132
- * Abstract base class for all validators
133
- * Implements immutable pattern to prevent memory leaks and race conditions
134
- */
135
- class VldBase {
136
- /**
137
- * Constructor with runtime type identifier
138
- * @param validatorType The runtime type identifier
139
- */
140
- constructor(validatorType = 'unknown') {
141
- this.validatorType = validatorType;
142
- }
143
- get '~standard'() {
144
- return {
145
- version: 1,
146
- vendor: 'vld',
147
- validate: (value) => {
148
- const result = this.safeParse(value);
149
- if (result.success) {
150
- return { value: result.data };
151
- }
152
- return { issues: [{ message: result.error.message }] };
153
- },
154
- types: undefined
155
- };
156
- }
157
- async parseAsync(value) {
158
- return this.parse(value);
159
- }
160
- async safeParseAsync(value) {
161
- try {
162
- return { success: true, data: await this.parseAsync(value) };
163
- }
164
- catch (error) {
165
- return { success: false, error: error };
166
- }
167
- }
168
- /**
169
- * Check if a value is valid according to this validator
170
- * @param value The value to check
171
- * @returns True if valid, false otherwise
172
- */
173
- isValid(value) {
174
- return this.safeParse(value).success;
175
- }
176
- /**
177
- * Parse a value or return a default if validation fails
178
- * BUG-NEW-017 FIX: Validate default value to ensure type safety
179
- * @param value The value to validate
180
- * @param defaultValue The default value to return on failure
181
- * @returns The validated value or default
182
- */
183
- parseOrDefault(value, defaultValue) {
184
- const result = this.safeParse(value);
185
- if (result.success) {
186
- return result.data;
187
- }
188
- // Validate the default value to ensure it's actually valid
189
- const defaultResult = this.safeParse(defaultValue);
190
- if (!defaultResult.success) {
191
- throw new Error(`Invalid default value provided: ${defaultResult.error.message}`);
192
- }
193
- return defaultResult.data;
194
- }
195
- refine(predicate, message) {
196
- return new VldRefine(this, predicate, message);
197
- }
198
- /**
199
- * Advanced refinement with context for adding multiple issues
200
- * @param refinement The refinement function with context
201
- * @returns A new super refined validator
202
- */
203
- superRefine(refinement) {
204
- return new VldSuperRefine(this, refinement);
205
- }
206
- /**
207
- * Create a new validator that transforms the output
208
- * @param transformer The transformation function
209
- * @returns A new transformed validator
210
- */
211
- transform(transformer) {
212
- return new VldTransform(this, transformer);
213
- }
214
- /**
215
- * Create a new validator with a default value for undefined inputs
216
- * @param defaultValue The default value
217
- * @returns A new validator with default
218
- */
219
- default(defaultValue) {
220
- return new VldDefault(this, defaultValue);
221
- }
222
- /**
223
- * Create a new validator that catches errors and returns a fallback
224
- * @param fallbackValue The fallback value
225
- * @returns A new validator with catch
226
- */
227
- catch(fallbackValue) {
228
- return new VldCatch(this, fallbackValue);
229
- }
230
- /**
231
- * Make this validator optional (allows undefined)
232
- * @returns A new optional validator
233
- */
234
- optional() {
235
- return new VldOptional(this);
236
- }
237
- /**
238
- * Make this validator nullable (allows null)
239
- * @returns A new nullable validator
240
- */
241
- nullable() {
242
- return new VldNullable(this);
243
- }
244
- /**
245
- * Make this validator nullish (allows null or undefined)
246
- * @returns A new nullish validator
247
- */
248
- nullish() {
249
- return new VldNullish(this);
250
- }
251
- /**
252
- * Make this validator exactly optional - allows undefined but not missing
253
- * Unlike .optional() which treats missing as undefined, exactOptional()
254
- * requires the key to be present but allows undefined as a value
255
- * Zod 4 API parity
256
- * @returns A new exact optional validator
257
- */
258
- exactOptional() {
259
- return new VldExactOptional(this);
260
- }
261
- /**
262
- * Pipe the output of this validator into another validator
263
- * @param next The next validator to pipe into
264
- * @returns A new piped validator
265
- */
266
- pipe(next) {
267
- return new VldPipe(this, next);
268
- }
269
- /**
270
- * Create a new validator that returns readonly output
271
- * Zod 4 API parity - marks output as readonly for TypeScript
272
- * @returns A new readonly validator
273
- */
274
- readonly() {
275
- return new VldReadonly(this);
276
- }
277
- /**
278
- * Brand the output type with a unique brand for nominal typing
279
- * Zod 4 API parity - prevents accidental assignment of similarly typed values
280
- * @returns A new branded validator
281
- * @example
282
- * const userIdSchema = v.string().brand<'UserId'>();
283
- * const productIdSchema = v.string().brand<'ProductId'>();
284
- *
285
- * let userId: UserId = userIdSchema.parse('abc');
286
- * let productId: ProductId = productIdSchema.parse('xyz');
287
- *
288
- * userId = productId; // TypeScript error: types are incompatible
289
- */
290
- brand() {
291
- return new VldBrand(this);
292
- }
293
- /**
294
- * Apply an external function to transform this validator
295
- * Zod 4 API parity - allows external function chaining
296
- * @param fn External function that takes this validator and returns a new validator
297
- * @returns The result of applying the function to this validator
298
- * @example
299
- * const withLength = (schema: VldBase<unknown, string>) => schema.transform(s => s.length);
300
- * const lengthSchema = v.string().apply(withLength); // validates string, returns number
301
- */
302
- apply(fn) {
303
- return fn(this);
304
- }
305
- check(predicate, message) {
306
- return new VldRefine(this, predicate, message);
307
- }
308
- /**
309
- * Get or set metadata for this schema
310
- */
311
- meta(data) {
312
- if (data === undefined) {
313
- return globalRegistry.get(this);
314
- }
315
- const schema = new VldMeta(this, data);
316
- globalRegistry.add(schema, data);
317
- return schema;
318
- }
319
- /**
320
- * Register this schema in a metadata registry and return the same instance.
321
- * This mirrors Zod 4's registry convenience API without changing validator
322
- * immutability.
323
- */
324
- register(targetRegistry, metadata) {
325
- targetRegistry.add(this, metadata);
326
- return this;
327
- }
328
- /**
329
- * Add a description to this schema
330
- * Zod 4 API parity - convenience method for .meta({ description: ... })
331
- * @param description The description to add
332
- * @returns A new validator with the description
333
- */
334
- describe(description) {
335
- return this.meta({ description });
336
- }
337
- }
338
- /**
339
- * Metadata validator - wraps a schema with metadata
340
- */
341
- class VldMeta extends VldBase {
342
- constructor(baseValidator, metadata) {
343
- super(VLD_VALIDATOR_TYPES.META);
344
- this.baseValidator = baseValidator;
345
- this.metadata = metadata;
346
- }
347
- parse(value) {
348
- return this.baseValidator.parse(value);
349
- }
350
- safeParse(value) {
351
- return this.baseValidator.safeParse(value);
352
- }
353
- /**
354
- * Get the metadata
355
- */
356
- getMeta() {
357
- return { ...this.metadata };
358
- }
359
- meta(data) {
360
- if (data === undefined) {
361
- return { ...this.metadata, ...globalRegistry.get(this) };
362
- }
363
- const schema = new VldMeta(this.baseValidator, { ...this.metadata, ...data });
364
- globalRegistry.add(schema, schema.getMeta());
365
- return schema;
366
- }
367
- describe(description) {
368
- return this.meta({ description });
369
- }
370
- }
371
- /**
372
- * Readonly validator - marks output as readonly
373
- */
374
- class VldReadonly extends VldBase {
375
- constructor(baseValidator) {
376
- super(VLD_VALIDATOR_TYPES.READONLY);
377
- this.baseValidator = baseValidator;
378
- }
379
- parse(value) {
380
- return this.baseValidator.parse(value);
381
- }
382
- safeParse(value) {
383
- const result = this.baseValidator.safeParse(value);
384
- if (result.success) {
385
- return { success: true, data: result.data };
386
- }
387
- return { success: false, error: result.error };
388
- }
389
- }
390
- /**
391
- * Brand validator - adds a unique brand to the output type for nominal typing
392
- * Uses TypeScript's branded types pattern to prevent accidental assignment
393
- */
394
- class VldBrand extends VldBase {
395
- constructor(baseValidator) {
396
- super(VLD_VALIDATOR_TYPES.BRAND);
397
- this.baseValidator = baseValidator;
398
- }
399
- parse(value) {
400
- return this.baseValidator.parse(value);
401
- }
402
- safeParse(value) {
403
- const result = this.baseValidator.safeParse(value);
404
- if (result.success) {
405
- return {
406
- success: true,
407
- data: result.data
408
- };
409
- }
410
- return { success: false, error: result.error };
411
- }
412
- }
413
- /**
414
- * Refine validator - adds custom validation
415
- */
416
- class VldRefine extends VldBase {
417
- constructor(baseValidator, predicate, customMessage) {
418
- super(VLD_VALIDATOR_TYPES.REFINE);
419
- this.baseValidator = baseValidator;
420
- this.predicate = predicate;
421
- this.customMessage = customMessage;
422
- }
423
- parse(value) {
424
- const baseResult = this.baseValidator.parse(value);
425
- const passed = this.predicate(baseResult);
426
- if (isPromiseLike(passed)) {
427
- throw new Error('Use parseAsync for async refinements');
428
- }
429
- if (!passed) {
430
- throw new Error(this.customMessage || 'Refinement check failed');
431
- }
432
- return baseResult;
433
- }
434
- safeParse(value) {
435
- try {
436
- return { success: true, data: this.parse(value) };
437
- }
438
- catch (error) {
439
- return { success: false, error: error };
440
- }
441
- }
442
- async parseAsync(value) {
443
- const baseResult = await this.baseValidator.parseAsync(value);
444
- if (!await this.predicate(baseResult)) {
445
- throw new Error(this.customMessage || 'Refinement check failed');
446
- }
447
- return baseResult;
448
- }
449
- }
450
- /**
451
- * Transform validator - transforms data after validation
452
- */
453
- class VldTransform extends VldBase {
454
- constructor(baseValidator, transformer) {
455
- super(VLD_VALIDATOR_TYPES.TRANSFORM);
456
- this.baseValidator = baseValidator;
457
- this.transformer = transformer;
458
- }
459
- parse(value) {
460
- const baseResult = this.baseValidator.parse(value);
461
- try {
462
- const transformed = this.transformer(baseResult);
463
- if (isPromiseLike(transformed)) {
464
- throw new Error('Use parseAsync for async transforms');
465
- }
466
- return transformed;
467
- }
468
- catch (error) {
469
- throw new Error(`Transform failed: ${error.message}`);
470
- }
471
- }
472
- safeParse(value) {
473
- try {
474
- return { success: true, data: this.parse(value) };
475
- }
476
- catch (error) {
477
- return { success: false, error: error };
478
- }
479
- }
480
- async parseAsync(value) {
481
- const baseResult = await this.baseValidator.parseAsync(value);
482
- try {
483
- return await this.transformer(baseResult);
484
- }
485
- catch (error) {
486
- throw new Error(`Transform failed: ${error.message}`);
487
- }
488
- }
489
- }
490
- /**
491
- * Default validator - provides default value for undefined
492
- * Note: Does not validate the default value at construction time.
493
- * Use .prefault() to validate the default value at parse time.
494
- */
495
- class VldDefault extends VldBase {
496
- constructor(baseValidator, defaultValue) {
497
- super(VLD_VALIDATOR_TYPES.DEFAULT);
498
- this.baseValidator = baseValidator;
499
- this.defaultValue = defaultValue;
500
- }
501
- parse(value) {
502
- if (value === undefined) {
503
- return this.defaultValue;
504
- }
505
- return this.baseValidator.parse(value);
506
- }
507
- safeParse(value) {
508
- if (value === undefined) {
509
- return { success: true, data: this.defaultValue };
510
- }
511
- return this.baseValidator.safeParse(value);
512
- }
513
- /**
514
- * Pre-parse default - validates the default value instead of returning it directly
515
- * This is useful when the default value needs to be validated against the schema
516
- */
517
- prefault() {
518
- // Return a new validator that validates the default value when parse(undefined) is called
519
- return new VldPrefault(this.baseValidator, this.defaultValue);
520
- }
521
- }
522
- /**
523
- * Prefault validator - validates the default value instead of returning it directly
524
- */
525
- class VldPrefault extends VldBase {
526
- constructor(baseValidator, defaultValue) {
527
- super(VLD_VALIDATOR_TYPES.PREFAULT);
528
- this.baseValidator = baseValidator;
529
- this.defaultValue = defaultValue;
530
- }
531
- parse(value) {
532
- if (value === undefined) {
533
- // Validate the default value through the base validator
534
- return this.baseValidator.parse(this.defaultValue);
535
- }
536
- return this.baseValidator.parse(value);
537
- }
538
- safeParse(value) {
539
- if (value === undefined) {
540
- return this.baseValidator.safeParse(this.defaultValue);
541
- }
542
- return this.baseValidator.safeParse(value);
543
- }
544
- /**
545
- * Calling prefault multiple times should be safe - return self
546
- */
547
- prefault() {
548
- return this;
549
- }
550
- }
551
- /**
552
- * Catch validator - provides fallback value on validation error
553
- * BUG-NPM-003 FIX: Validate fallback value at construction time
554
- */
555
- class VldCatch extends VldBase {
556
- constructor(baseValidator, fallbackValue) {
557
- super(VLD_VALIDATOR_TYPES.CATCH);
558
- this.baseValidator = baseValidator;
559
- this.fallbackValue = fallbackValue;
560
- this.simpleMode = getSimpleWrappedMode(baseValidator);
561
- // BUG-NPM-003 FIX: Validate the fallback value to ensure type safety
562
- const validation = baseValidator.safeParse(fallbackValue);
563
- if (!validation.success) {
564
- throw new Error(`Invalid fallback value: ${validation.error.message}`);
565
- }
566
- }
567
- parse(value) {
568
- const simpleValue = parseSimpleWrappedValue(this.simpleMode, value);
569
- if (simpleValue !== undefined) {
570
- return simpleValue;
571
- }
572
- if (this.simpleMode !== undefined) {
573
- return this.fallbackValue;
574
- }
575
- try {
576
- return this.baseValidator.parse(value);
577
- }
578
- catch {
579
- return this.fallbackValue;
580
- }
581
- }
582
- safeParse(value) {
583
- const simpleValue = parseSimpleWrappedValue(this.simpleMode, value);
584
- if (simpleValue !== undefined) {
585
- return { success: true, data: simpleValue };
586
- }
587
- if (this.simpleMode !== undefined) {
588
- return { success: true, data: this.fallbackValue };
589
- }
590
- const result = this.baseValidator.safeParse(value);
591
- if (result.success) {
592
- return result;
593
- }
594
- return { success: true, data: this.fallbackValue };
595
- }
596
- }
597
- /**
598
- * Optional validator - allows undefined
599
- */
600
- class VldOptional extends VldBase {
601
- constructor(baseValidator) {
602
- super(VLD_VALIDATOR_TYPES.OPTIONAL);
603
- this.baseValidator = baseValidator;
604
- this.simpleMode = getSimpleWrappedMode(baseValidator);
605
- }
606
- parseSimpleValue(value) {
607
- return parseSimpleWrappedValue(this.simpleMode, value);
608
- }
609
- static create(baseValidator) {
610
- return new VldOptional(baseValidator);
611
- }
612
- parse(value) {
613
- if (value === undefined) {
614
- return undefined;
615
- }
616
- const simpleValue = this.parseSimpleValue(value);
617
- if (simpleValue !== undefined) {
618
- return simpleValue;
619
- }
620
- return this.baseValidator.parse(value);
621
- }
622
- safeParse(value) {
623
- if (value === undefined) {
624
- return { success: true, data: undefined };
625
- }
626
- const simpleValue = this.parseSimpleValue(value);
627
- if (simpleValue !== undefined) {
628
- return { success: true, data: simpleValue };
629
- }
630
- return this.baseValidator.safeParse(value);
631
- }
632
- unwrap() {
633
- return this.baseValidator;
634
- }
635
- }
636
- /**
637
- * Exact optional validator - allows undefined but requires key presence
638
- * Unlike Optional which treats missing as undefined, ExactOptional
639
- * requires the key to be present (not missing from object) but allows undefined
640
- * Zod 4 API parity
641
- */
642
- class VldExactOptional extends VldBase {
643
- constructor(baseValidator) {
644
- super(VLD_VALIDATOR_TYPES.EXACT_OPTIONAL);
645
- this.baseValidator = baseValidator;
646
- this.simpleMode = getSimpleWrappedMode(baseValidator);
647
- }
648
- static create(baseValidator) {
649
- return new VldExactOptional(baseValidator);
650
- }
651
- parse(value) {
652
- if (value === undefined) {
653
- return undefined;
654
- }
655
- const simpleValue = parseSimpleWrappedValue(this.simpleMode, value);
656
- if (simpleValue !== undefined) {
657
- return simpleValue;
658
- }
659
- return this.baseValidator.parse(value);
660
- }
661
- safeParse(value) {
662
- // Unlike regular optional, undefined is explicitly valid
663
- // but we still validate through the base validator
664
- if (value === undefined) {
665
- return { success: true, data: undefined };
666
- }
667
- const simpleValue = parseSimpleWrappedValue(this.simpleMode, value);
668
- if (simpleValue !== undefined) {
669
- return { success: true, data: simpleValue };
670
- }
671
- return this.baseValidator.safeParse(value);
672
- }
673
- unwrap() {
674
- return this.baseValidator;
675
- }
676
- }
677
- /**
678
- * Nullable validator - allows null
679
- */
680
- class VldNullable extends VldBase {
681
- constructor(baseValidator) {
682
- super(VLD_VALIDATOR_TYPES.NULLABLE);
683
- this.baseValidator = baseValidator;
684
- this.simpleMode = getSimpleWrappedMode(baseValidator);
685
- }
686
- static create(baseValidator) {
687
- return new VldNullable(baseValidator);
688
- }
689
- parse(value) {
690
- if (value === null) {
691
- return null;
692
- }
693
- const simpleValue = parseSimpleWrappedValue(this.simpleMode, value);
694
- if (simpleValue !== undefined) {
695
- return simpleValue;
696
- }
697
- return this.baseValidator.parse(value);
698
- }
699
- safeParse(value) {
700
- if (value === null) {
701
- return { success: true, data: null };
702
- }
703
- const simpleValue = parseSimpleWrappedValue(this.simpleMode, value);
704
- if (simpleValue !== undefined) {
705
- return { success: true, data: simpleValue };
706
- }
707
- return this.baseValidator.safeParse(value);
708
- }
709
- unwrap() {
710
- return this.baseValidator;
711
- }
712
- }
713
- /**
714
- * Nullish validator - allows null or undefined
715
- */
716
- class VldNullish extends VldBase {
717
- constructor(baseValidator) {
718
- super(VLD_VALIDATOR_TYPES.NULLISH);
719
- this.baseValidator = baseValidator;
720
- this.simpleMode = getSimpleWrappedMode(baseValidator);
721
- }
722
- static create(baseValidator) {
723
- return new VldNullish(baseValidator);
724
- }
725
- parse(value) {
726
- if (value === null || value === undefined) {
727
- return value;
728
- }
729
- const simpleValue = parseSimpleWrappedValue(this.simpleMode, value);
730
- if (simpleValue !== undefined) {
731
- return simpleValue;
732
- }
733
- return this.baseValidator.parse(value);
734
- }
735
- safeParse(value) {
736
- if (value === null || value === undefined) {
737
- return { success: true, data: value };
738
- }
739
- const simpleValue = parseSimpleWrappedValue(this.simpleMode, value);
740
- if (simpleValue !== undefined) {
741
- return { success: true, data: simpleValue };
742
- }
743
- return this.baseValidator.safeParse(value);
744
- }
745
- unwrap() {
746
- return this.baseValidator;
747
- }
748
- }
749
- /**
750
- * Pipe validator - chains validators, passing output of one to the next
751
- */
752
- class VldPipe extends VldBase {
753
- constructor(first, second) {
754
- super(VLD_VALIDATOR_TYPES.PIPE);
755
- this.first = first;
756
- this.second = second;
757
- }
758
- parse(value) {
759
- const intermediateResult = this.first.parse(value);
760
- return this.second.parse(intermediateResult);
761
- }
762
- safeParse(value) {
763
- const firstResult = this.first.safeParse(value);
764
- if (!firstResult.success) {
765
- return { success: false, error: firstResult.error };
766
- }
767
- return this.second.safeParse(firstResult.data);
768
- }
769
- }
770
- /**
771
- * SuperRefine validator - advanced refinement with context
772
- */
773
- class VldSuperRefine extends VldBase {
774
- constructor(_inner, _refinement) {
775
- super(VLD_VALIDATOR_TYPES.SUPER_REFINE);
776
- this._inner = _inner;
777
- this._refinement = _refinement;
778
- }
779
- parse(value) {
780
- const result = this._inner.parse(value);
781
- const issues = [];
782
- const ctx = {
783
- addIssue: (issue) => issues.push(issue),
784
- path: []
785
- };
786
- const maybePromise = this._refinement(result, ctx);
787
- if (maybePromise instanceof Promise) {
788
- throw new Error('Use parseAsync for async refinements');
789
- }
790
- if (issues.length > 0) {
791
- throw new Error(issues.map(i => i.message).join('; '));
792
- }
793
- return result;
794
- }
795
- safeParse(value) {
796
- const result = this._inner.safeParse(value);
797
- if (!result.success)
798
- return { success: false, error: result.error };
799
- const issues = [];
800
- const ctx = {
801
- addIssue: (issue) => issues.push(issue),
802
- path: []
803
- };
804
- const maybePromise = this._refinement(result.data, ctx);
805
- if (maybePromise instanceof Promise) {
806
- throw new Error('Use safeParseAsync for async refinements');
807
- }
808
- if (issues.length > 0) {
809
- return {
810
- success: false,
811
- error: new Error(issues.map(i => i.message).join('; '))
812
- };
813
- }
814
- return result;
815
- }
816
- async parseAsync(value) {
817
- const result = await this._inner.parseAsync(value);
818
- const issues = [];
819
- const ctx = {
820
- addIssue: (issue) => issues.push(issue),
821
- path: []
822
- };
823
- await this._refinement(result, ctx);
824
- if (issues.length > 0) {
825
- throw new Error(issues.map(i => i.message).join('; '));
826
- }
827
- return result;
828
- }
829
- async safeParseAsync(value) {
830
- try {
831
- return { success: true, data: await this.parseAsync(value) };
832
- }
833
- catch (error) {
834
- return { success: false, error: error };
835
- }
836
- }
837
- }
838
- /**
839
- * Preprocess validator - transforms input before validation
840
- */
841
- class VldPreprocess extends VldBase {
842
- constructor(_preprocessor, _schema) {
843
- super(VLD_VALIDATOR_TYPES.PREPROCESS);
844
- this._preprocessor = _preprocessor;
845
- this._schema = _schema;
846
- }
847
- static create(preprocessor, schema) {
848
- return new VldPreprocess(preprocessor, schema);
849
- }
850
- parse(value) {
851
- const preprocessed = this._preprocessor(value);
852
- return this._schema.parse(preprocessed);
853
- }
854
- safeParse(value) {
855
- try {
856
- const preprocessed = this._preprocessor(value);
857
- return this._schema.safeParse(preprocessed);
858
- }
859
- catch (error) {
860
- return {
861
- success: false,
862
- error: error
863
- };
864
- }
865
- }
866
- }
867
-
868
- export { VLD_VALIDATOR_TYPES, VldBase, VldBrand, VldCatch, VldDefault, VldExactOptional, VldMeta, VldNullable, VldNullish, VldOptional, VldPipe, VldPrefault, VldPreprocess, VldReadonly, VldRefine, VldSuperRefine, VldTransform, resolveErrorMessage };
1
+ import{globalRegistry as e}from"../registry.js";import{V as t}from"../chunks/errors-core-CerMg2rq.js";function s(e){if(e instanceof t)return e;const s=e instanceof Error?e.message:String(e);return new t([{code:"custom",path:[],message:s}])}const r={STRING:"string",STRING_FORMAT:"stringFormat",STRING_BOOL:"stringBool",NUMBER:"number",BOOLEAN:"boolean",DATE:"date",BIGINT:"bigint",UNDEFINED:"undefined",NULL:"null",UNKNOWN:"unknown",ANY:"any",VOID:"void",NEVER:"never",SYMBOL:"symbol",NAN:"nan",HEX:"hex",BASE64:"base64",UINT8_ARRAY:"uint8Array",COERCE_STRING:"coerceString",COERCE_NUMBER:"coerceNumber",COERCE_BOOLEAN:"coerceBoolean",COERCE_DATE:"coerceDate",COERCE_BIGINT:"coerceBigint",OBJECT:"object",ARRAY:"array",TUPLE:"tuple",SET:"set",MAP:"map",RECORD:"record",UNION:"union",DISCRIMINATED_UNION:"discriminatedUnion",INTERSECTION:"intersection",XOR:"xor",ENUM:"enum",LITERAL:"literal",LAZY:"lazy",CUSTOM:"custom",FUNCTION:"function",FILE:"file",JSON:"json",TEMPLATE_LITERAL:"templateLiteral",PROMISE:"promise",OPTIONAL:"optional",NULLABLE:"nullable",NULLISH:"nullish",EXACT_OPTIONAL:"exactOptional",DEFAULT:"default",CATCH:"catch",REFINE:"refine",TRANSFORM:"transform",PIPE:"pipe",PREPROCESS:"preprocess",SUPER_REFINE:"superRefine",BRAND:"brand",READONLY:"readonly",META:"meta",PREFAULT:"prefault",PREFault:"prefault",CODEC:"codec"};function a(e,t){if("string"==typeof e)return e;if("function"==typeof e){const s=e(void 0);return"string"==typeof s?s:"object"==typeof s&&s?.message?s.message:t}if("object"==typeof e&&null!==e){if("string"==typeof e.error)return e.error;if("function"==typeof e.error)return e.error({})||t;if("string"==typeof e.message)return e.message}return t}function i(e){return null!==e&&("object"==typeof e||"function"==typeof e)&&"function"==typeof e.then}let n;function o(e){n=e}function h(e){return"function"==typeof e?e():function(e){if(Array.isArray(e))return[...e];if(e instanceof Map)return new Map(e);if(e instanceof Set)return new Set(e);if(null!==e&&"object"==typeof e){const t=Object.getPrototypeOf(e);if(t===Object.prototype||null===t)return{...e}}return e}(e)}function u(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";default:return}}function l(e,t){switch(e){case"string":return"string"==typeof t?t:void 0;case"number":return"number"!=typeof t||isNaN(t)?void 0:t;case"boolean":return"boolean"==typeof t?t:void 0;case"bigint":return"bigint"==typeof t?t:void 0;case"symbol":return"symbol"==typeof t?t:void 0;default:return}}class VldBase{constructor(e="unknown"){this.validatorType=e}get type(){return this.validatorType}get _def(){return{typeName:"Zod"+this.validatorType.charAt(0).toUpperCase()+this.validatorType.slice(1),...this.config||{}}}get def(){return this._def}get _zod(){return this._def}get"~standard"(){return{version:1,vendor:"vld",validate:e=>{const t=this.safeParse(e);return t.success?{value:t.data}:{issues:[{message:t.error.message}]}},types:void 0}}async parseAsync(e){return this.parse(e)}async safeParseAsync(e){try{return{success:!0,data:await this.parseAsync(e)}}catch(e){return{success:!1,error:s(e)}}}decode(e){return this.parse(e)}safeDecode(e){return this.safeParse(e)}async decodeAsync(e){return this.parseAsync(e)}async safeDecodeAsync(e){return this.safeParseAsync(e)}encode(e){return this.parse(e)}safeEncode(e){const t=this.safeParse(e);return t.success?{success:!0,data:t.data}:t}async encodeAsync(e){return this.parseAsync(e)}async safeEncodeAsync(e){const t=await this.safeParseAsync(e);return t.success?{success:!0,data:t.data}:t}spa(e){return this.safeParseAsync(e)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}clone(){return this}isValid(e){return this.safeParse(e).success}parseOrDefault(e,t){const s=this.safeParse(e);if(s.success)return s.data;const r=this.safeParse(t);if(!r.success)throw new Error(`Invalid default value provided: ${r.error.message}`);return r.data}refine(e,t){return new VldRefine(this,e,t)}superRefine(e){return new VldSuperRefine(this,e)}transform(e){return new VldTransform(this,e)}default(e){return new VldDefault(this,e)}prefault(e){return new VldPrefault(this,e)}nonoptional(e){return new VldRefine(this,e=>void 0!==e,a(e,"Expected non-optional value"))}array(){return n.array(this)}or(e){return n.union(this,e)}and(e){return n.intersection(this,e)}overwrite(e){return new VldTransform(this,e)}with(...e){return new VldSuperRefine(this,(t,s)=>{const r={value:t,issues:[]},a=[];for(const t of e){const e="function"==typeof t?t:t._zod?.check;if(!e)continue;const s=e(r);i(s)&&a.push(Promise.resolve(s))}const n=()=>{for(const e of r.issues)s.addIssue(void 0===e.code?{message:e.message||"Custom check failed"}:{message:e.message||"Custom check failed",code:e.code})};if(a.length>0)return Promise.all(a).then(n);n()})}toJSONSchema(e){return n.toJSONSchema(this,e)}catch(e){return new VldCatch(this,e)}optional(){return new VldOptional(this)}nullable(){return new VldNullable(this)}nullish(){return new VldNullish(this)}exactOptional(){return new VldExactOptional(this)}pipe(e){return new VldPipe(this,e)}readonly(){return new VldReadonly(this)}brand(){return new VldBrand(this)}apply(e){return e(this)}check(e,t){return this.refine(e,t)}meta(t){if(void 0===t)return e.get(this)??this.baseValidator?.meta?.()??this.schema?.meta?.()??this.inner?.meta?.();const s=new VldMeta(this,t);return e.add(s,t),s}register(e,t){return e.add(this,t),this}describe(e){return this.meta({description:e})}get description(){return this.meta()?.description??this.baseValidator?.description??this.schema?.description??this.inner?.description}}class VldMeta extends VldBase{constructor(e,t){super(r.META),this.baseValidator=e,this.metadata=t}parse(e){return this.baseValidator.parse(e)}safeParse(e){return this.baseValidator.safeParse(e)}getMeta(){return{...this.metadata}}meta(t){if(void 0===t)return{...this.metadata,...e.get(this)};const s=new VldMeta(this.baseValidator,{...this.metadata,...t});return e.add(s,s.getMeta()),s}describe(e){return this.meta({description:e})}}class VldReadonly extends VldBase{constructor(e){super(r.READONLY),this.baseValidator=e}parse(e){return this.baseValidator.parse(e)}safeParse(e){const t=this.baseValidator.safeParse(e);return t.success?{success:!0,data:t.data}:{success:!1,error:t.error}}}class VldBrand extends VldBase{constructor(e){super(r.BRAND),this.baseValidator=e}parse(e){return this.baseValidator.parse(e)}safeParse(e){const t=this.baseValidator.safeParse(e);return t.success?{success:!0,data:t.data}:{success:!1,error:t.error}}}class VldRefine extends VldBase{constructor(e,t,s){super(r.REFINE),this.baseValidator=e,this.predicate=t,this.customMessage=s??"Refinement check failed","object"==typeof s&&null!==s&&"path"in s&&Array.isArray(s.path)&&(this.refinePath=s.path)}_createIssue(e){if("function"==typeof this.customMessage){const t=this.customMessage(e);return"string"==typeof t?{code:"custom",path:this.refinePath??[],message:t}:{code:"custom",path:t?.path??this.refinePath??[],message:t?.message??"Refinement check failed"}}if("object"==typeof this.customMessage&&null!==this.customMessage){const e=this.customMessage.message??this.customMessage.error,t="function"==typeof e?e({}):"string"==typeof e?e:"Refinement check failed";return{code:"custom",path:this.customMessage.path??this.refinePath??[],message:t}}return{code:"custom",path:this.refinePath??[],message:"string"==typeof this.customMessage?this.customMessage:"Refinement check failed"}}parse(e){const s=this.baseValidator.parse(e),r=this.predicate(s);if(i(r))throw new Error("Use parseAsync for async refinements");if(!r)throw new t([this._createIssue(s)]);return s}safeParse(e){try{return{success:!0,data:this.parse(e)}}catch(e){return{success:!1,error:s(e)}}}async parseAsync(e){const s=await this.baseValidator.parseAsync(e);if(!await this.predicate(s))throw new t([this._createIssue(s)]);return s}async safeParseAsync(e){try{return{success:!0,data:await this.parseAsync(e)}}catch(e){return{success:!1,error:s(e)}}}_wrap(e){return new VldRefine(e,this.predicate,this.customMessage)}min(e,t){return this._wrap(this.baseValidator.min?.(e,t)??this.baseValidator)}max(e,t){return this._wrap(this.baseValidator.max?.(e,t)??this.baseValidator)}length(e,t){return this._wrap(this.baseValidator.length?.(e,t)??this.baseValidator)}email(e){return this._wrap(this.baseValidator.email?.(e)??this.baseValidator)}url(e){return this._wrap(this.baseValidator.url?.(e)??this.baseValidator)}uuid(e){return this._wrap(this.baseValidator.uuid?.(e)??this.baseValidator)}regex(e,t){return this._wrap(this.baseValidator.regex?.(e,t)??this.baseValidator)}startsWith(e,t){return this._wrap(this.baseValidator.startsWith?.(e,t)??this.baseValidator)}endsWith(e,t){return this._wrap(this.baseValidator.endsWith?.(e,t)??this.baseValidator)}includes(e,t){return this._wrap(this.baseValidator.includes?.(e,t)??this.baseValidator)}ip(e){return this._wrap(this.baseValidator.ip?.(e)??this.baseValidator)}ipv4(e){return this._wrap(this.baseValidator.ipv4?.(e)??this.baseValidator)}ipv6(e){return this._wrap(this.baseValidator.ipv6?.(e)??this.baseValidator)}nonempty(e){return this._wrap(this.baseValidator.nonempty?.(e)??this.baseValidator)}trim(){return this._wrap(this.baseValidator.trim?.()??this.baseValidator)}toLowerCase(){return this._wrap(this.baseValidator.toLowerCase?.()??this.baseValidator)}lowercase(){return this.toLowerCase()}toUpperCase(){return this._wrap(this.baseValidator.toUpperCase?.()??this.baseValidator)}uppercase(){return this.toUpperCase()}positive(e){return this._wrap(this.baseValidator.positive?.(e)??this.baseValidator)}negative(e){return this._wrap(this.baseValidator.negative?.(e)??this.baseValidator)}nonnegative(e){return this._wrap(this.baseValidator.nonnegative?.(e)??this.baseValidator)}nonpositive(e){return this._wrap(this.baseValidator.nonpositive?.(e)??this.baseValidator)}int(e){return this._wrap(this.baseValidator.int?.(e)??this.baseValidator)}finite(e){return this._wrap(this.baseValidator.finite?.(e)??this.baseValidator)}safe(e){return this._wrap(this.baseValidator.safe?.(e)??this.baseValidator)}multipleOf(e,t){return this._wrap(this.baseValidator.multipleOf?.(e,t)??this.baseValidator)}step(e,t){return this._wrap(this.baseValidator.step?.(e,t)??this.baseValidator)}gt(e,t){return this._wrap(this.baseValidator.gt?.(e,t)??this.baseValidator)}gte(e,t){return this._wrap(this.baseValidator.gte?.(e,t)??this.baseValidator)}lt(e,t){return this._wrap(this.baseValidator.lt?.(e,t)??this.baseValidator)}lte(e,t){return this._wrap(this.baseValidator.lte?.(e,t)??this.baseValidator)}extend(e){return this._wrap(this.baseValidator.extend?.(e)??this.baseValidator)}merge(e){return this._wrap(this.baseValidator.merge?.(e)??this.baseValidator)}pick(...e){return this._wrap(this.baseValidator.pick?.(...e)??this.baseValidator)}omit(...e){return this._wrap(this.baseValidator.omit?.(...e)??this.baseValidator)}partial(){return this._wrap(this.baseValidator.partial?.()??this.baseValidator)}required(){return this._wrap(this.baseValidator.required?.()??this.baseValidator)}strict(e){return this._wrap(this.baseValidator.strict?.(e)??this.baseValidator)}passthrough(){return this._wrap(this.baseValidator.passthrough?.()??this.baseValidator)}strip(){return this._wrap(this.baseValidator.strip?.()??this.baseValidator)}catchall(e){return this._wrap(this.baseValidator.catchall?.(e)??this.baseValidator)}get shape(){return this.baseValidator.shape}get keyof(){return this.baseValidator.keyof}unwrap(){return this.baseValidator.unwrap?this.baseValidator.unwrap():this.baseValidator}get element(){return this.baseValidator.element}}class VldTransform extends VldBase{constructor(e,t){super(r.TRANSFORM),this.baseValidator=e,this.transformer=t}parse(e){const t=this.baseValidator.parse(e);try{const e=this.transformer(t);if(i(e))throw new Error("Use parseAsync for async transforms");return e}catch(e){throw new Error(`Transform failed: ${e.message}`)}}safeParse(e){try{return{success:!0,data:this.parse(e)}}catch(e){return{success:!1,error:s(e)}}}async parseAsync(e){const t=await this.baseValidator.parseAsync(e);try{return await this.transformer(t)}catch(e){throw new Error(`Transform failed: ${e.message}`)}}}class VldDefault extends VldBase{constructor(e,t){super(r.DEFAULT),this.baseValidator=e,this.defaultValue=t}parse(e){return void 0===e?h(this.defaultValue):this.baseValidator.parse(e)}safeParse(e){return void 0===e?{success:!0,data:h(this.defaultValue)}:this.baseValidator.safeParse(e)}prefault(e){return new VldPrefault(this.baseValidator,void 0===e?this.defaultValue:e)}unwrap(){return this.baseValidator}removeDefault(){return this.baseValidator}}class VldPrefault extends VldBase{constructor(e,t){super(r.PREFAULT),this.baseValidator=e,this.defaultValue=t}parse(e){return void 0===e?this.baseValidator.parse(h(this.defaultValue)):this.baseValidator.parse(e)}safeParse(e){return void 0===e?this.baseValidator.safeParse(h(this.defaultValue)):this.baseValidator.safeParse(e)}prefault(e){return void 0===e?this:new VldPrefault(this.baseValidator,e)}unwrap(){return this.baseValidator}}class VldCatch extends VldBase{constructor(e,t){super(r.CATCH),this.baseValidator=e,this.fallbackValue=t,this.simpleMode=u(e);const s=e.safeParse(t);if(!s.success)throw new Error(`Invalid fallback value: ${s.error.message}`)}parse(e){const t=l(this.simpleMode,e);if(void 0!==t)return t;if(void 0!==this.simpleMode)return this.fallbackValue;try{return this.baseValidator.parse(e)}catch{return this.fallbackValue}}safeParse(e){const t=l(this.simpleMode,e);if(void 0!==t)return{success:!0,data:t};if(void 0!==this.simpleMode)return{success:!0,data:this.fallbackValue};const s=this.baseValidator.safeParse(e);return s.success?s:{success:!0,data:this.fallbackValue}}}class VldOptional extends VldBase{constructor(e){super(r.OPTIONAL),this.baseValidator=e,this.simpleMode=u(e)}parseSimpleValue(e){return l(this.simpleMode,e)}static create(e){return new VldOptional(e)}parse(e){if(void 0===e)return;const t=this.parseSimpleValue(e);return void 0!==t?t:this.baseValidator.parse(e)}safeParse(e){if(void 0===e)return{success:!0,data:void 0};const t=this.parseSimpleValue(e);return void 0!==t?{success:!0,data:t}:this.baseValidator.safeParse(e)}unwrap(){return this.baseValidator}}class VldExactOptional extends VldBase{constructor(e){super(r.EXACT_OPTIONAL),this.baseValidator=e,this.simpleMode=u(e)}static create(e){return new VldExactOptional(e)}parse(e){if(void 0===e)return;const t=l(this.simpleMode,e);return void 0!==t?t:this.baseValidator.parse(e)}safeParse(e){if(void 0===e)return{success:!0,data:void 0};const t=l(this.simpleMode,e);return void 0!==t?{success:!0,data:t}:this.baseValidator.safeParse(e)}unwrap(){return this.baseValidator}}class VldNullable extends VldBase{constructor(e){super(r.NULLABLE),this.baseValidator=e,this.simpleMode=u(e)}static create(e){return new VldNullable(e)}parse(e){if(null===e)return null;const t=l(this.simpleMode,e);return void 0!==t?t:this.baseValidator.parse(e)}safeParse(e){if(null===e)return{success:!0,data:null};const t=l(this.simpleMode,e);return void 0!==t?{success:!0,data:t}:this.baseValidator.safeParse(e)}unwrap(){return this.baseValidator}}class VldNullish extends VldBase{constructor(e){super(r.NULLISH),this.baseValidator=e,this.simpleMode=u(e)}static create(e){return new VldNullish(e)}parse(e){if(null==e)return e;const t=l(this.simpleMode,e);return void 0!==t?t:this.baseValidator.parse(e)}safeParse(e){if(null==e)return{success:!0,data:e};const t=l(this.simpleMode,e);return void 0!==t?{success:!0,data:t}:this.baseValidator.safeParse(e)}unwrap(){return this.baseValidator}}class VldPipe extends VldBase{constructor(e,t){super(r.PIPE),this.first=e,this.second=t}parse(e){const t=this.first.parse(e);return this.second.parse(t)}safeParse(e){const t=this.first.safeParse(e);return t.success?this.second.safeParse(t.data):{success:!1,error:t.error}}}class VldSuperRefine extends VldBase{constructor(e,t){super(r.SUPER_REFINE),this._inner=e,this._refinement=t}parse(e){const s=this._inner.parse(e),r=[],a={addIssue:e=>{r.push({code:e.code||"custom",path:e.path??[],message:e.message||"Validation error"})},path:[]};if(this._refinement(s,a)instanceof Promise)throw new Error("Use parseAsync for async refinements");if(r.length>0)throw new t(r,r.map(e=>e.message).join("; "));return s}safeParse(e){const r=this._inner.safeParse(e);if(!r.success)return{success:!1,error:s(r.error)};const a=[],i={addIssue:e=>{a.push({code:e.code||"custom",path:e.path??[],message:e.message||"Validation error"})},path:[]};if(this._refinement(r.data,i)instanceof Promise)throw new Error("Use safeParseAsync for async refinements");return a.length>0?{success:!1,error:new t(a,a.map(e=>e.message).join("; "))}:r}async parseAsync(e){const s=await this._inner.parseAsync(e),r=[],a={addIssue:e=>{r.push({code:e.code||"custom",path:e.path??[],message:e.message||"Validation error"})},path:[]};if(await this._refinement(s,a),r.length>0)throw new t(r,r.map(e=>e.message).join("; "));return s}async safeParseAsync(e){try{return{success:!0,data:await this.parseAsync(e)}}catch(e){return{success:!1,error:s(e)}}}_wrap(e){return new VldSuperRefine(e,this._refinement)}min(e,t){return this._wrap(this._inner.min?.(e,t)??this._inner)}max(e,t){return this._wrap(this._inner.max?.(e,t)??this._inner)}length(e,t){return this._wrap(this._inner.length?.(e,t)??this._inner)}email(e){return this._wrap(this._inner.email?.(e)??this._inner)}url(e){return this._wrap(this._inner.url?.(e)??this._inner)}uuid(e){return this._wrap(this._inner.uuid?.(e)??this._inner)}regex(e,t){return this._wrap(this._inner.regex?.(e,t)??this._inner)}startsWith(e,t){return this._wrap(this._inner.startsWith?.(e,t)??this._inner)}endsWith(e,t){return this._wrap(this._inner.endsWith?.(e,t)??this._inner)}includes(e,t){return this._wrap(this._inner.includes?.(e,t)??this._inner)}ip(e){return this._wrap(this._inner.ip?.(e)??this._inner)}ipv4(e){return this._wrap(this._inner.ipv4?.(e)??this._inner)}ipv6(e){return this._wrap(this._inner.ipv6?.(e)??this._inner)}nonempty(e){return this._wrap(this._inner.nonempty?.(e)??this._inner)}trim(){return this._wrap(this._inner.trim?.()??this._inner)}toLowerCase(){return this._wrap(this._inner.toLowerCase?.()??this._inner)}lowercase(){return this.toLowerCase()}toUpperCase(){return this._wrap(this._inner.toUpperCase?.()??this._inner)}uppercase(){return this.toUpperCase()}positive(e){return this._wrap(this._inner.positive?.(e)??this._inner)}negative(e){return this._wrap(this._inner.negative?.(e)??this._inner)}nonnegative(e){return this._wrap(this._inner.nonnegative?.(e)??this._inner)}nonpositive(e){return this._wrap(this._inner.nonpositive?.(e)??this._inner)}int(e){return this._wrap(this._inner.int?.(e)??this._inner)}finite(e){return this._wrap(this._inner.finite?.(e)??this._inner)}safe(e){return this._wrap(this._inner.safe?.(e)??this._inner)}multipleOf(e,t){return this._wrap(this._inner.multipleOf?.(e,t)??this._inner)}step(e,t){return this._wrap(this._inner.step?.(e,t)??this._inner)}gt(e,t){return this._wrap(this._inner.gt?.(e,t)??this._inner)}gte(e,t){return this._wrap(this._inner.gte?.(e,t)??this._inner)}lt(e,t){return this._wrap(this._inner.lt?.(e,t)??this._inner)}lte(e,t){return this._wrap(this._inner.lte?.(e,t)??this._inner)}extend(e){return this._wrap(this._inner.extend?.(e)??this._inner)}merge(e){return this._wrap(this._inner.merge?.(e)??this._inner)}pick(...e){return this._wrap(this._inner.pick?.(...e)??this._inner)}omit(...e){return this._wrap(this._inner.omit?.(...e)??this._inner)}partial(){return this._wrap(this._inner.partial?.()??this._inner)}required(){return this._wrap(this._inner.required?.()??this._inner)}strict(e){return this._wrap(this._inner.strict?.(e)??this._inner)}passthrough(){return this._wrap(this._inner.passthrough?.()??this._inner)}strip(){return this._wrap(this._inner.strip?.()??this._inner)}catchall(e){return this._wrap(this._inner.catchall?.(e)??this._inner)}get shape(){return this._inner.shape}get keyof(){return this._inner.keyof}unwrap(){return this._inner.unwrap?this._inner.unwrap():this._inner}get element(){return this._inner.element}}class VldPreprocess extends VldBase{constructor(e,t){super(r.PREPROCESS),this._preprocessor=e,this._schema=t}static create(e,t){return new VldPreprocess(e,t)}parse(e){const t=this._preprocessor(e);return this._schema.parse(t)}safeParse(e){try{const t=this._preprocessor(e);return this._schema.safeParse(t)}catch(e){return{success:!1,error:s(e)}}}}export{r as VLD_VALIDATOR_TYPES,VldBase,VldBrand,VldCatch,VldDefault,VldExactOptional,VldMeta,VldNullable,VldNullish,VldOptional,VldPipe,VldPrefault,VldPreprocess,VldReadonly,VldRefine,VldSuperRefine,VldTransform,o as configureSchemaCompositionFactories,s as ensureVldError,i as isPromiseLike,a as resolveErrorMessage};