@oxog/vld 2.0.2 → 2.0.3

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 (48) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/LICENSE +20 -20
  3. package/README.md +2 -2
  4. package/dist/chunks/{bigint-DgsCr2dC.js → bigint-CRS0QVsy.js} +147 -2
  5. package/dist/chunks/bigint-CRS0QVsy.js.map +1 -0
  6. package/dist/chunks/{date-ODue_rtq.js → date-50JV_Mfj.js} +2 -2
  7. package/dist/chunks/{date-ODue_rtq.js.map → date-50JV_Mfj.js.map} +1 -1
  8. package/dist/chunks/{index-CETyGkrv.js → index-DO8CFMxD.js} +4 -4
  9. package/dist/chunks/index-DO8CFMxD.js.map +1 -0
  10. package/dist/chunks/{json-o20GFhTh.js → json-Cp4WO0M9.js} +4 -4
  11. package/dist/chunks/json-Cp4WO0M9.js.map +1 -0
  12. package/dist/chunks/{unknown-SLIH1VCf.js → unknown-Dhzri_T-.js} +2 -2
  13. package/dist/chunks/unknown-Dhzri_T-.js.map +1 -0
  14. package/dist/cjs/index.cjs +777 -1
  15. package/dist/cjs/index.cjs.map +1 -1
  16. package/dist/cjs/locales/index.cjs.map +1 -1
  17. package/dist/cjs/mini.cjs +145 -0
  18. package/dist/cjs/mini.cjs.map +1 -1
  19. package/dist/cli/commands/validate.d.ts.map +1 -1
  20. package/dist/codecs/index.js +3 -3
  21. package/dist/coercion/index.js +2 -2
  22. package/dist/coercion/index.js.map +1 -1
  23. package/dist/index.d.ts +244 -0
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +550 -11
  26. package/dist/index.js.map +1 -1
  27. package/dist/mini.js +5 -5
  28. package/dist/utils/json-schema.d.ts +67 -0
  29. package/dist/utils/json-schema.d.ts.map +1 -0
  30. package/dist/validators/base.d.ts +79 -0
  31. package/dist/validators/base.d.ts.map +1 -1
  32. package/dist/validators/index.d.ts +3 -2
  33. package/dist/validators/index.d.ts.map +1 -1
  34. package/dist/validators/index.js +514 -4
  35. package/dist/validators/index.js.map +1 -1
  36. package/dist/validators/number.d.ts +30 -0
  37. package/dist/validators/number.d.ts.map +1 -1
  38. package/dist/validators/promise.d.ts +53 -0
  39. package/dist/validators/promise.d.ts.map +1 -0
  40. package/dist/validators/string-formats.d.ts +6 -0
  41. package/dist/validators/string-formats.d.ts.map +1 -1
  42. package/package.json +6 -5
  43. package/dist/chunks/bigint-DgsCr2dC.js.map +0 -1
  44. package/dist/chunks/index-BZqWZvVe.js +0 -426
  45. package/dist/chunks/index-BZqWZvVe.js.map +0 -1
  46. package/dist/chunks/index-CETyGkrv.js.map +0 -1
  47. package/dist/chunks/json-o20GFhTh.js.map +0 -1
  48. package/dist/chunks/unknown-SLIH1VCf.js.map +0 -1
package/dist/cjs/mini.cjs CHANGED
@@ -88,6 +88,16 @@ class VldBase {
88
88
  nullish() {
89
89
  return new VldNullish(this);
90
90
  }
91
+ /**
92
+ * Make this validator exactly optional - allows undefined but not missing
93
+ * Unlike .optional() which treats missing as undefined, exactOptional()
94
+ * requires the key to be present but allows undefined as a value
95
+ * Zod 4 API parity
96
+ * @returns A new exact optional validator
97
+ */
98
+ exactOptional() {
99
+ return new VldExactOptional(this);
100
+ }
91
101
  /**
92
102
  * Pipe the output of this validator into another validator
93
103
  * @param next The next validator to pipe into
@@ -132,6 +142,49 @@ class VldBase {
132
142
  apply(fn) {
133
143
  return fn(this);
134
144
  }
145
+ check(predicate, message) {
146
+ return new VldRefine(this, predicate, message);
147
+ }
148
+ /**
149
+ * Get or set metadata for this schema
150
+ */
151
+ meta(data) {
152
+ if (data === undefined) {
153
+ return undefined;
154
+ }
155
+ return new VldMeta(this, data);
156
+ }
157
+ /**
158
+ * Add a description to this schema
159
+ * Zod 4 API parity - convenience method for .meta({ description: ... })
160
+ * @param description The description to add
161
+ * @returns A new validator with the description
162
+ */
163
+ describe(description) {
164
+ return new VldMeta(this, { description });
165
+ }
166
+ }
167
+ /**
168
+ * Metadata validator - wraps a schema with metadata
169
+ */
170
+ class VldMeta extends VldBase {
171
+ constructor(baseValidator, metadata) {
172
+ super();
173
+ this.baseValidator = baseValidator;
174
+ this.metadata = metadata;
175
+ }
176
+ parse(value) {
177
+ return this.baseValidator.parse(value);
178
+ }
179
+ safeParse(value) {
180
+ return this.baseValidator.safeParse(value);
181
+ }
182
+ /**
183
+ * Get the metadata
184
+ */
185
+ getMeta() {
186
+ return this.metadata;
187
+ }
135
188
  }
136
189
  /**
137
190
  * Readonly validator - marks output as readonly
@@ -347,6 +400,38 @@ class VldOptional extends VldBase {
347
400
  return this.baseValidator;
348
401
  }
349
402
  }
403
+ /**
404
+ * Exact optional validator - allows undefined but requires key presence
405
+ * Unlike Optional which treats missing as undefined, ExactOptional
406
+ * requires the key to be present (not missing from object) but allows undefined
407
+ * Zod 4 API parity
408
+ */
409
+ class VldExactOptional extends VldBase {
410
+ constructor(baseValidator) {
411
+ super();
412
+ this.baseValidator = baseValidator;
413
+ }
414
+ static create(baseValidator) {
415
+ return new VldExactOptional(baseValidator);
416
+ }
417
+ parse(value) {
418
+ if (value === undefined) {
419
+ return undefined;
420
+ }
421
+ return this.baseValidator.parse(value);
422
+ }
423
+ safeParse(value) {
424
+ // Unlike regular optional, undefined is explicitly valid
425
+ // but we still validate through the base validator
426
+ if (value === undefined) {
427
+ return { success: true, data: undefined };
428
+ }
429
+ return this.baseValidator.safeParse(value);
430
+ }
431
+ unwrap() {
432
+ return this.baseValidator;
433
+ }
434
+ }
350
435
  /**
351
436
  * Nullable validator - allows null
352
437
  */
@@ -3995,6 +4080,66 @@ class VldNumber extends VldBase {
3995
4080
  lte(value, message) {
3996
4081
  return this.max(value, message);
3997
4082
  }
4083
+ /**
4084
+ * Create a validator for unsigned 32-bit integers
4085
+ * Range: 0 to 4,294,967,295
4086
+ */
4087
+ uint32(message) {
4088
+ return new VldNumber({
4089
+ checks: [...this.config.checks, (v) => Number.isSafeInteger(v) && v >= 0 && v <= 4294967295],
4090
+ errorMessage: message || 'Expected an unsigned 32-bit integer'
4091
+ });
4092
+ }
4093
+ /**
4094
+ * Create a validator for unsigned 64-bit integers
4095
+ * Range: 0 to 2^53-1 (safe integer limit)
4096
+ */
4097
+ uint64(message) {
4098
+ return new VldNumber({
4099
+ checks: [...this.config.checks, (v) => Number.isSafeInteger(v) && v >= 0],
4100
+ errorMessage: message || 'Expected an unsigned 64-bit integer'
4101
+ });
4102
+ }
4103
+ /**
4104
+ * Create a validator for signed 32-bit integers
4105
+ * Range: -2,147,483,648 to 2,147,483,647
4106
+ */
4107
+ int32(message) {
4108
+ return new VldNumber({
4109
+ checks: [...this.config.checks, (v) => Number.isSafeInteger(v) && v >= -2147483648 && v <= 2147483647],
4110
+ errorMessage: message || 'Expected a signed 32-bit integer'
4111
+ });
4112
+ }
4113
+ /**
4114
+ * Create a validator for signed 64-bit integers
4115
+ * Range: -(2^53-1) to 2^53-1 (safe integer limit)
4116
+ */
4117
+ int64(message) {
4118
+ return new VldNumber({
4119
+ checks: [...this.config.checks, (v) => Number.isSafeInteger(v)],
4120
+ errorMessage: message || 'Expected a signed 64-bit integer'
4121
+ });
4122
+ }
4123
+ /**
4124
+ * Create a validator for 32-bit floats (IEEE 754 single precision)
4125
+ * Range: -3.4e38 to 3.4e38, precision ~7 decimal digits
4126
+ */
4127
+ float32(message) {
4128
+ return new VldNumber({
4129
+ checks: [...this.config.checks, (v) => Number.isFinite(v) && Math.abs(v) <= 3.4e38],
4130
+ errorMessage: message || 'Expected a 32-bit float'
4131
+ });
4132
+ }
4133
+ /**
4134
+ * Create a validator for 64-bit floats (IEEE 754 double precision)
4135
+ * Alias for standard number validation
4136
+ */
4137
+ float64(message) {
4138
+ return new VldNumber({
4139
+ checks: [...this.config.checks, (v) => Number.isFinite(v)],
4140
+ errorMessage: message || 'Expected a 64-bit float'
4141
+ });
4142
+ }
3998
4143
  }
3999
4144
 
4000
4145
  /**