@oxog/vld 2.1.0 → 2.2.5

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 (220) hide show
  1. package/CHANGELOG.md +87 -0
  2. package/README.md +1296 -1235
  3. package/dist/chunks/errors-core-Cqi4-9ew.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-DKPohm9I.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 +20 -1
  109. package/dist/errors.js +1 -171
  110. package/dist/index.d.ts +248 -357
  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 +63 -8
  162. package/dist/validators/base.js +1 -868
  163. package/dist/validators/base64.js +1 -68
  164. package/dist/validators/bigint.js +1 -228
  165. package/dist/validators/boolean.js +1 -142
  166. package/dist/validators/codec.js +1 -200
  167. package/dist/validators/custom.js +1 -67
  168. package/dist/validators/date.js +1 -274
  169. package/dist/validators/discriminated-union.d.ts +2 -2
  170. package/dist/validators/discriminated-union.js +1 -123
  171. package/dist/validators/enum.js +1 -150
  172. package/dist/validators/file.js +1 -125
  173. package/dist/validators/function.js +1 -58
  174. package/dist/validators/hex.js +1 -65
  175. package/dist/validators/index.d.ts +1 -1
  176. package/dist/validators/index.js +1 -35
  177. package/dist/validators/intersection.js +1 -116
  178. package/dist/validators/json.js +1 -66
  179. package/dist/validators/lazy.js +1 -50
  180. package/dist/validators/literal.d.ts +7 -3
  181. package/dist/validators/literal.js +1 -60
  182. package/dist/validators/map.js +1 -214
  183. package/dist/validators/nan.js +1 -38
  184. package/dist/validators/never.js +1 -32
  185. package/dist/validators/null.js +1 -40
  186. package/dist/validators/number.d.ts +20 -1
  187. package/dist/validators/number.js +1 -423
  188. package/dist/validators/object.d.ts +12 -2
  189. package/dist/validators/object.js +1 -864
  190. package/dist/validators/promise.js +1 -111
  191. package/dist/validators/record.d.ts +11 -8
  192. package/dist/validators/record.js +1 -258
  193. package/dist/validators/set.js +1 -199
  194. package/dist/validators/string-bool.js +1 -120
  195. package/dist/validators/string-formats.d.ts +58 -62
  196. package/dist/validators/string-formats.js +1 -135
  197. package/dist/validators/string.d.ts +47 -10
  198. package/dist/validators/string.js +1 -4
  199. package/dist/validators/symbol.js +1 -58
  200. package/dist/validators/template-literal.js +1 -103
  201. package/dist/validators/tuple.d.ts +17 -13
  202. package/dist/validators/tuple.js +1 -183
  203. package/dist/validators/uint8array.js +1 -101
  204. package/dist/validators/undefined.js +1 -40
  205. package/dist/validators/union.js +1 -187
  206. package/dist/validators/unknown.js +1 -37
  207. package/dist/validators/void.js +1 -44
  208. package/dist/validators/xor.d.ts +2 -2
  209. package/dist/validators/xor.js +1 -66
  210. package/package.json +239 -238
  211. package/dist/chunks/errors-core-BeiFUtZM.js +0 -81
  212. package/dist/chunks/index-0R2ntSud.js +0 -508
  213. package/dist/chunks/index-BvH403Yy.js +0 -88
  214. package/dist/chunks/security-B0Pd_vSY.js +0 -35
  215. package/dist/chunks/string-BJRQod3t.js +0 -530
  216. package/dist/cjs/chunks/errors-core-DWxLFs2f.cjs +0 -83
  217. package/dist/cjs/chunks/index-BkI37108.cjs +0 -538
  218. package/dist/cjs/chunks/index-Cc3bjUMX.cjs +0 -91
  219. package/dist/cjs/chunks/security-Dc3Jh13T.cjs +0 -37
  220. package/dist/cjs/chunks/string-BKZrc4hs.cjs +0 -533
@@ -1,73 +1 @@
1
- 'use strict';
2
-
3
- var validators_base = require('./base.cjs');
4
- var errors = require('../errors.cjs');
5
- var locales_runtime = require('../locales/runtime.cjs');
6
- var errorsCore = require('../chunks/errors-core-DWxLFs2f.cjs');
7
- require('../registry.cjs');
8
- require('../pigment.cjs');
9
- require('../locales/en.cjs');
10
-
11
- /**
12
- * Base64 string validator
13
- */
14
- class VldBase64 extends validators_base.VldBase {
15
- constructor(urlSafe = false) {
16
- super(validators_base.VLD_VALIDATOR_TYPES.BASE64);
17
- this.urlSafe = urlSafe;
18
- }
19
- parse(value) {
20
- const result = this.safeParse(value);
21
- if (!result.success) {
22
- throw result.error;
23
- }
24
- return result.data;
25
- }
26
- safeParse(value) {
27
- if (typeof value !== 'string') {
28
- return {
29
- success: false,
30
- error: new errorsCore.VldError([
31
- errors.createIssue('invalid_type', [], locales_runtime.getMessages().expectedString)
32
- ])
33
- };
34
- }
35
- // Check if it's a valid base64 string
36
- const regex = this.urlSafe ? VldBase64.BASE64_URL_REGEX : VldBase64.BASE64_REGEX;
37
- // Check basic format
38
- if (!regex.test(value)) {
39
- return {
40
- success: false,
41
- error: new errorsCore.VldError([
42
- errors.createIssue('custom', [], locales_runtime.getMessages().invalidBase64)
43
- ])
44
- };
45
- }
46
- // For standard base64, check length is multiple of 4 (after padding)
47
- // Empty strings are valid (decode to empty buffer)
48
- // For URL-safe base64, padding is not required
49
- if (!this.urlSafe && value.length > 0 && value.length % 4 !== 0) {
50
- return {
51
- success: false,
52
- error: new errorsCore.VldError([
53
- errors.createIssue('custom', [], locales_runtime.getMessages().invalidBase64)
54
- ])
55
- };
56
- }
57
- return { success: true, data: value };
58
- }
59
- /**
60
- * Create a URL-safe base64 validator
61
- */
62
- urlSafeMode() {
63
- return new VldBase64(true);
64
- }
65
- static create(urlSafe = false) {
66
- return new VldBase64(urlSafe);
67
- }
68
- }
69
- VldBase64.BASE64_REGEX = /^[A-Za-z0-9+/]*={0,2}$/;
70
- // Note: RFC 4648 specifies URL-safe base64 should omit padding, but we allow it for compatibility
71
- VldBase64.BASE64_URL_REGEX = /^[A-Za-z0-9_-]*={0,2}$/;
72
-
73
- exports.VldBase64 = VldBase64;
1
+ "use strict";var e=require("./base.cjs"),s=require("../errors.cjs"),r=require("../locales/runtime.cjs"),a=require("../chunks/errors-core-DKPohm9I.cjs");require("../registry.cjs"),require("../pigment.cjs"),require("../locales/en.cjs");class VldBase64 extends e.VldBase{constructor(s=!1){super(e.VLD_VALIDATOR_TYPES.BASE64),this.urlSafe=s}parse(e){const s=this.safeParse(e);if(!s.success)throw s.error;return s.data}safeParse(e){if("string"!=typeof e)return{success:!1,error:new a.VldError([s.createIssue("invalid_type",[],r.getMessages().expectedString)])};return(this.urlSafe?VldBase64.BASE64_URL_REGEX:VldBase64.BASE64_REGEX).test(e)?!this.urlSafe&&e.length>0&&e.length%4!=0?{success:!1,error:new a.VldError([s.createIssue("custom",[],r.getMessages().invalidBase64)])}:{success:!0,data:e}:{success:!1,error:new a.VldError([s.createIssue("custom",[],r.getMessages().invalidBase64)])}}urlSafeMode(){return new VldBase64(!0)}static create(e=!1){return new VldBase64(e)}}VldBase64.BASE64_REGEX=/^[A-Za-z0-9+/]*={0,2}$/,VldBase64.BASE64_URL_REGEX=/^[A-Za-z0-9_-]*={0,2}$/,exports.VldBase64=VldBase64;
@@ -1,232 +1 @@
1
- 'use strict';
2
-
3
- var validators_base = require('./base.cjs');
4
- var locales_runtime = require('../locales/runtime.cjs');
5
- var errorsCore = require('../chunks/errors-core-DWxLFs2f.cjs');
6
- require('../registry.cjs');
7
- require('../locales/en.cjs');
8
-
9
- function createBigIntError(message) {
10
- return new errorsCore.VldError([{ code: 'invalid_type', path: [], message }]);
11
- }
12
- /**
13
- * Immutable bigint validator
14
- */
15
- class VldBigInt extends validators_base.VldBase {
16
- /**
17
- * Protected constructor to allow extension while maintaining immutability
18
- */
19
- constructor(config) {
20
- super(config?.validatorType || validators_base.VLD_VALIDATOR_TYPES.BIGINT);
21
- this.config = {
22
- checks: config?.checks || [],
23
- errorMessage: config?.errorMessage,
24
- jsonSchema: config?.jsonSchema
25
- };
26
- this._checks = this.config.checks;
27
- this._fastCheckMode = this.detectFastCheckMode();
28
- }
29
- get jsonSchema() {
30
- return this.config.jsonSchema;
31
- }
32
- get isSimple() {
33
- return this._checks.length === 0;
34
- }
35
- /**
36
- * Create a new bigint validator
37
- */
38
- static create() {
39
- return new VldBigInt();
40
- }
41
- detectFastCheckMode() {
42
- if (this._checks.length === 0) {
43
- return 'none';
44
- }
45
- if (this._checks.length !== 1) {
46
- return undefined;
47
- }
48
- const schema = this.config.jsonSchema;
49
- if (schema?.exclusiveMinimum === 0n && schema.minimum === undefined && schema.maximum === undefined) {
50
- return 'positive';
51
- }
52
- if (schema?.exclusiveMaximum === 0n && schema.minimum === undefined && schema.maximum === undefined) {
53
- return 'negative';
54
- }
55
- if (schema?.minimum === 0n && schema.maximum === undefined && schema.exclusiveMaximum === undefined) {
56
- return 'nonnegative';
57
- }
58
- if (schema?.maximum === 0n && schema.minimum === undefined && schema.exclusiveMinimum === undefined) {
59
- return 'nonpositive';
60
- }
61
- return undefined;
62
- }
63
- getValidationError() {
64
- return new Error(this.config.errorMessage || locales_runtime.getMessages().invalidBigint);
65
- }
66
- /**
67
- * Parse and validate a bigint value
68
- */
69
- parse(value) {
70
- if (typeof value !== 'bigint') {
71
- throw this.getValidationError();
72
- }
73
- return this.parseKnownBigInt(value);
74
- }
75
- /**
76
- * Parse a value that has already passed the bigint type guard.
77
- * @internal Used by object validators to avoid duplicate hot-path checks.
78
- */
79
- parseKnownBigInt(value) {
80
- switch (this._fastCheckMode) {
81
- case 'none':
82
- return value;
83
- case 'positive':
84
- if (value > 0n)
85
- return value;
86
- throw this.getValidationError();
87
- case 'negative':
88
- if (value < 0n)
89
- return value;
90
- throw this.getValidationError();
91
- case 'nonnegative':
92
- if (value >= 0n)
93
- return value;
94
- throw this.getValidationError();
95
- case 'nonpositive':
96
- if (value <= 0n)
97
- return value;
98
- throw this.getValidationError();
99
- }
100
- // Apply all checks
101
- for (const check of this._checks) {
102
- if (!check(value)) {
103
- throw this.getValidationError();
104
- }
105
- }
106
- return value;
107
- }
108
- /**
109
- * Safely parse and validate a bigint value
110
- */
111
- safeParse(value) {
112
- if (typeof value !== 'bigint') {
113
- return { success: false, error: createBigIntError(this.getValidationError().message) };
114
- }
115
- try {
116
- return { success: true, data: this.parseKnownBigInt(value) };
117
- }
118
- catch (error) {
119
- return { success: false, error: createBigIntError(error.message) };
120
- }
121
- }
122
- /**
123
- * Create a new validator with minimum value constraint
124
- */
125
- min(value, message) {
126
- return new VldBigInt({
127
- ...this.config,
128
- checks: [...this.config.checks, (v) => v >= value],
129
- errorMessage: message || `BigInt must be at least ${value}`,
130
- jsonSchema: { ...this.config.jsonSchema, minimum: value }
131
- });
132
- }
133
- /**
134
- * Create a new validator with maximum value constraint
135
- */
136
- max(value, message) {
137
- return new VldBigInt({
138
- ...this.config,
139
- checks: [...this.config.checks, (v) => v <= value],
140
- errorMessage: message || `BigInt must be at most ${value}`,
141
- jsonSchema: { ...this.config.jsonSchema, maximum: value }
142
- });
143
- }
144
- /**
145
- * Create a new validator that checks for positive values
146
- */
147
- positive(message) {
148
- return new VldBigInt({
149
- ...this.config,
150
- checks: [...this.config.checks, (v) => v > 0n],
151
- errorMessage: message || 'BigInt must be positive',
152
- jsonSchema: { ...this.config.jsonSchema, exclusiveMinimum: 0n }
153
- });
154
- }
155
- /**
156
- * Create a new validator that checks for negative values
157
- */
158
- negative(message) {
159
- return new VldBigInt({
160
- ...this.config,
161
- checks: [...this.config.checks, (v) => v < 0n],
162
- errorMessage: message || 'BigInt must be negative',
163
- jsonSchema: { ...this.config.jsonSchema, exclusiveMaximum: 0n }
164
- });
165
- }
166
- /**
167
- * Create a new validator that checks for non-negative values
168
- */
169
- nonnegative(message) {
170
- return new VldBigInt({
171
- ...this.config,
172
- checks: [...this.config.checks, (v) => v >= 0n],
173
- errorMessage: message || 'BigInt must be non-negative',
174
- jsonSchema: { ...this.config.jsonSchema, minimum: 0n }
175
- });
176
- }
177
- /**
178
- * Create a new validator that checks for non-positive values
179
- */
180
- nonpositive(message) {
181
- return new VldBigInt({
182
- ...this.config,
183
- checks: [...this.config.checks, (v) => v <= 0n],
184
- errorMessage: message || 'BigInt must be non-positive',
185
- jsonSchema: { ...this.config.jsonSchema, maximum: 0n }
186
- });
187
- }
188
- /**
189
- * Create a new validator with strict greater than constraint
190
- * Zod 4 API parity - strictly greater than (not equal to)
191
- */
192
- gt(value, message) {
193
- const compareValue = typeof value === 'bigint' ? value : BigInt(value);
194
- return new VldBigInt({
195
- ...this.config,
196
- checks: [...this.config.checks, (v) => v > compareValue],
197
- errorMessage: message || `BigInt must be greater than ${compareValue}`,
198
- jsonSchema: { ...this.config.jsonSchema, exclusiveMinimum: compareValue }
199
- });
200
- }
201
- /**
202
- * Create a new validator with strict less than constraint
203
- * Zod 4 API parity - strictly less than (not equal to)
204
- */
205
- lt(value, message) {
206
- const compareValue = typeof value === 'bigint' ? value : BigInt(value);
207
- return new VldBigInt({
208
- ...this.config,
209
- checks: [...this.config.checks, (v) => v < compareValue],
210
- errorMessage: message || `BigInt must be less than ${compareValue}`,
211
- jsonSchema: { ...this.config.jsonSchema, exclusiveMaximum: compareValue }
212
- });
213
- }
214
- /**
215
- * Create a new validator with greater than or equal constraint
216
- * Zod 4 API parity - alias for min()
217
- */
218
- gte(value, message) {
219
- const compareValue = typeof value === 'bigint' ? value : BigInt(value);
220
- return this.min(compareValue, message);
221
- }
222
- /**
223
- * Create a new validator with less than or equal constraint
224
- * Zod 4 API parity - alias for max()
225
- */
226
- lte(value, message) {
227
- const compareValue = typeof value === 'bigint' ? value : BigInt(value);
228
- return this.max(compareValue, message);
229
- }
230
- }
231
-
232
- exports.VldBigInt = VldBigInt;
1
+ "use strict";var e=require("./base.cjs"),i=require("../locales/runtime.cjs"),n=require("../chunks/errors-core-DKPohm9I.cjs");function t(e){return new n.VldError([{code:"invalid_type",path:[],message:e}])}require("../registry.cjs"),require("../locales/en.cjs");class VldBigInt extends e.VldBase{constructor(i){super(i?.validatorType||e.VLD_VALIDATOR_TYPES.BIGINT),this.config={checks:i?.checks||[],errorMessage:i?.errorMessage,jsonSchema:i?.jsonSchema},this._checks=this.config.checks,this._fastCheckMode=this.detectFastCheckMode()}get jsonSchema(){return this.config.jsonSchema}get isSimple(){return 0===this._checks.length}static create(){return new VldBigInt}detectFastCheckMode(){if(0===this._checks.length)return"none";if(1!==this._checks.length)return;const e=this.config.jsonSchema;return 0n===e?.exclusiveMinimum&&void 0===e.minimum&&void 0===e.maximum?"positive":0n===e?.exclusiveMaximum&&void 0===e.minimum&&void 0===e.maximum?"negative":0n===e?.minimum&&void 0===e.maximum&&void 0===e.exclusiveMaximum?"nonnegative":0n===e?.maximum&&void 0===e.minimum&&void 0===e.exclusiveMinimum?"nonpositive":void 0}getValidationError(){return new Error(this.config.errorMessage||i.getMessages().invalidBigint)}parse(e){if("bigint"!=typeof e)throw this.getValidationError();return this.parseKnownBigInt(e)}parseKnownBigInt(e){switch(this._fastCheckMode){case"none":return e;case"positive":if(e>0n)return e;throw this.getValidationError();case"negative":if(e<0n)return e;throw this.getValidationError();case"nonnegative":if(e>=0n)return e;throw this.getValidationError();case"nonpositive":if(e<=0n)return e;throw this.getValidationError()}for(const i of this._checks)if(!i(e))throw this.getValidationError();return e}safeParse(e){if("bigint"!=typeof e)return{success:!1,error:t(this.getValidationError().message)};try{return{success:!0,data:this.parseKnownBigInt(e)}}catch(e){return{success:!1,error:t(e.message)}}}min(e,i){return new VldBigInt({...this.config,checks:[...this.config.checks,i=>i>=e],errorMessage:i||`BigInt must be at least ${e}`,jsonSchema:{...this.config.jsonSchema,minimum:e}})}max(e,i){return new VldBigInt({...this.config,checks:[...this.config.checks,i=>i<=e],errorMessage:i||`BigInt must be at most ${e}`,jsonSchema:{...this.config.jsonSchema,maximum:e}})}positive(e){return new VldBigInt({...this.config,checks:[...this.config.checks,e=>e>0n],errorMessage:e||"BigInt must be positive",jsonSchema:{...this.config.jsonSchema,exclusiveMinimum:0n}})}negative(e){return new VldBigInt({...this.config,checks:[...this.config.checks,e=>e<0n],errorMessage:e||"BigInt must be negative",jsonSchema:{...this.config.jsonSchema,exclusiveMaximum:0n}})}nonnegative(e){return new VldBigInt({...this.config,checks:[...this.config.checks,e=>e>=0n],errorMessage:e||"BigInt must be non-negative",jsonSchema:{...this.config.jsonSchema,minimum:0n}})}nonpositive(e){return new VldBigInt({...this.config,checks:[...this.config.checks,e=>e<=0n],errorMessage:e||"BigInt must be non-positive",jsonSchema:{...this.config.jsonSchema,maximum:0n}})}gt(e,i){const n="bigint"==typeof e?e:BigInt(e);return new VldBigInt({...this.config,checks:[...this.config.checks,e=>e>n],errorMessage:i||`BigInt must be greater than ${n}`,jsonSchema:{...this.config.jsonSchema,exclusiveMinimum:n}})}lt(e,i){const n="bigint"==typeof e?e:BigInt(e);return new VldBigInt({...this.config,checks:[...this.config.checks,e=>e<n],errorMessage:i||`BigInt must be less than ${n}`,jsonSchema:{...this.config.jsonSchema,exclusiveMaximum:n}})}gte(e,i){const n="bigint"==typeof e?e:BigInt(e);return this.min(n,i)}lte(e,i){const n="bigint"==typeof e?e:BigInt(e);return this.max(n,i)}}exports.VldBigInt=VldBigInt;
@@ -1,146 +1 @@
1
- 'use strict';
2
-
3
- var validators_base = require('./base.cjs');
4
- var locales_runtime = require('../locales/runtime.cjs');
5
- var errorsCore = require('../chunks/errors-core-DWxLFs2f.cjs');
6
- require('../registry.cjs');
7
- require('../locales/en.cjs');
8
-
9
- function createBooleanError(message) {
10
- return new errorsCore.VldError([{ code: 'invalid_boolean', path: [], message }]);
11
- }
12
- /**
13
- * Immutable boolean validator
14
- */
15
- class VldBoolean extends validators_base.VldBase {
16
- /**
17
- * Protected constructor to allow extension while maintaining immutability
18
- */
19
- constructor(errorMessage, validatorType) {
20
- super(validatorType || validators_base.VLD_VALIDATOR_TYPES.BOOLEAN);
21
- this.errorMessage = errorMessage;
22
- }
23
- /**
24
- * Returns true if this is a simple boolean validator with no custom checks
25
- * Used by VldObject for optimized fast-path dispatch
26
- */
27
- get isSimple() {
28
- return true;
29
- }
30
- /**
31
- * Create a new boolean validator
32
- */
33
- static create() {
34
- return new VldBoolean();
35
- }
36
- /**
37
- * Parse and validate a boolean value
38
- */
39
- parse(value) {
40
- if (typeof value !== 'boolean') {
41
- throw new Error(this.errorMessage || locales_runtime.getMessages().invalidBoolean);
42
- }
43
- return value;
44
- }
45
- /**
46
- * Parse a value that has already passed the boolean type guard.
47
- * @internal Used by object validators to avoid duplicate hot-path checks.
48
- */
49
- parseKnownBoolean(value) {
50
- return value;
51
- }
52
- /**
53
- * Safely parse and validate a boolean value
54
- */
55
- safeParse(value) {
56
- if (typeof value === 'boolean') {
57
- return { success: true, data: value };
58
- }
59
- return {
60
- success: false,
61
- error: createBooleanError(this.errorMessage || locales_runtime.getMessages().invalidBoolean)
62
- };
63
- }
64
- /**
65
- * Create a new validator that only accepts true
66
- */
67
- true(message) {
68
- return new VldTrue(message || 'Value must be true');
69
- }
70
- /**
71
- * Create a new validator that only accepts false
72
- */
73
- false(message) {
74
- return new VldFalse(message || 'Value must be false');
75
- }
76
- }
77
- /**
78
- * Validator that only accepts true
79
- */
80
- class VldTrue extends VldBoolean {
81
- constructor(message) {
82
- super(message);
83
- this.message = message;
84
- }
85
- get isSimple() {
86
- return false;
87
- }
88
- parse(value) {
89
- if (value !== true) {
90
- throw new Error(this.message);
91
- }
92
- return true;
93
- }
94
- parseKnownBoolean(value) {
95
- if (value !== true) {
96
- throw new Error(this.message);
97
- }
98
- return true;
99
- }
100
- // BUG-003 FIX: Override safeParse to ensure true validation
101
- safeParse(value) {
102
- if (value !== true) {
103
- return {
104
- success: false,
105
- error: createBooleanError(this.message)
106
- };
107
- }
108
- return { success: true, data: true };
109
- }
110
- }
111
- /**
112
- * Validator that only accepts false
113
- */
114
- class VldFalse extends VldBoolean {
115
- constructor(message) {
116
- super(message);
117
- this.message = message;
118
- }
119
- get isSimple() {
120
- return false;
121
- }
122
- parse(value) {
123
- if (value !== false) {
124
- throw new Error(this.message);
125
- }
126
- return false;
127
- }
128
- parseKnownBoolean(value) {
129
- if (value !== false) {
130
- throw new Error(this.message);
131
- }
132
- return false;
133
- }
134
- // BUG-003 FIX: Override safeParse to ensure false validation
135
- safeParse(value) {
136
- if (value !== false) {
137
- return {
138
- success: false,
139
- error: createBooleanError(this.message)
140
- };
141
- }
142
- return { success: true, data: false };
143
- }
144
- }
145
-
146
- exports.VldBoolean = VldBoolean;
1
+ "use strict";var e=require("./base.cjs"),s=require("../chunks/errors-core-DKPohm9I.cjs");require("../registry.cjs");class VldBoolean extends e.VldBase{constructor(s,r){super(r||e.VLD_VALIDATOR_TYPES.BOOLEAN),this.errorMessage=s}get isSimple(){return!0}static create(){return new VldBoolean}parse(e){if("boolean"!=typeof e)throw new s.VldError([s.createInvalidTypeIssue("boolean",s.getTypeName(e),this.errorMessage)]);return e}parseKnownBoolean(e){return e}safeParse(e){return"boolean"==typeof e?{success:!0,data:e}:{success:!1,error:new s.VldError([s.createInvalidTypeIssue("boolean",s.getTypeName(e),this.errorMessage)])}}true(e){return new VldTrue(e||"Value must be true")}false(e){return new VldFalse(e||"Value must be false")}}class VldTrue extends VldBoolean{constructor(e){super(e),this.message=e}get isSimple(){return!1}parse(e){if(!0!==e)throw new s.VldError([{code:"custom",path:[],message:this.message}]);return!0}parseKnownBoolean(e){if(!0!==e)throw new s.VldError([{code:"custom",path:[],message:this.message}]);return!0}safeParse(e){return!0!==e?{success:!1,error:new s.VldError([{code:"custom",path:[],message:this.message}])}:{success:!0,data:!0}}}class VldFalse extends VldBoolean{constructor(e){super(e),this.message=e}get isSimple(){return!1}parse(e){if(!1!==e)throw new s.VldError([{code:"custom",path:[],message:this.message}]);return!1}parseKnownBoolean(e){if(!1!==e)throw new s.VldError([{code:"custom",path:[],message:this.message}]);return!1}safeParse(e){return!1!==e?{success:!1,error:new s.VldError([{code:"custom",path:[],message:this.message}])}:{success:!0,data:!1}}}exports.VldBoolean=VldBoolean;
@@ -1,205 +1 @@
1
- 'use strict';
2
-
3
- var validators_base = require('./base.cjs');
4
- var errors = require('../errors.cjs');
5
- var locales_runtime = require('../locales/runtime.cjs');
6
- var errorsCore = require('../chunks/errors-core-DWxLFs2f.cjs');
7
- require('../registry.cjs');
8
- require('../pigment.cjs');
9
- require('../locales/en.cjs');
10
-
11
- /**
12
- * Codec validator for bidirectional transformations
13
- * Enables converting between different data representations
14
- */
15
- class VldCodec extends validators_base.VldBase {
16
- constructor(inputValidator, outputValidator, codecTransform) {
17
- super(validators_base.VLD_VALIDATOR_TYPES.CODEC);
18
- this.inputValidator = inputValidator;
19
- this.outputValidator = outputValidator;
20
- this.codecTransform = codecTransform;
21
- }
22
- /**
23
- * Parse (decode) a value from input to output format
24
- */
25
- parse(value) {
26
- const result = this.safeParse(value);
27
- if (!result.success) {
28
- throw result.error;
29
- }
30
- return result.data;
31
- }
32
- /**
33
- * Safely parse (decode) a value from input to output format
34
- */
35
- safeParse(value) {
36
- // First validate the input
37
- const inputResult = this.inputValidator.safeParse(value);
38
- if (!inputResult.success) {
39
- return { success: false, error: inputResult.error };
40
- }
41
- try {
42
- // Then decode to output
43
- const decoded = this.codecTransform.decode(inputResult.data);
44
- // Handle async decode
45
- if (decoded instanceof Promise) {
46
- throw new errorsCore.VldError([
47
- errors.createIssue('custom', [], locales_runtime.getMessages().codecAsyncNotSupported)
48
- ]);
49
- }
50
- // Validate the decoded output
51
- return this.outputValidator.safeParse(decoded);
52
- }
53
- catch (error) {
54
- if (error instanceof errorsCore.VldError) {
55
- return { success: false, error };
56
- }
57
- return {
58
- success: false,
59
- error: new errorsCore.VldError([
60
- errors.createIssue('custom', [], locales_runtime.getMessages().codecDecodeFailed)
61
- ])
62
- };
63
- }
64
- }
65
- /**
66
- * Create a new codec with input and output directions swapped.
67
- */
68
- invert() {
69
- return new VldCodec(this.outputValidator, this.inputValidator, {
70
- decode: this.codecTransform.encode,
71
- encode: this.codecTransform.decode
72
- });
73
- }
74
- /**
75
- * Encode a value from output back to input format
76
- */
77
- encode(value) {
78
- const result = this.safeEncode(value);
79
- if (!result.success) {
80
- throw result.error;
81
- }
82
- return result.data;
83
- }
84
- /**
85
- * Safely encode a value from output back to input format
86
- */
87
- safeEncode(value) {
88
- // First validate the output
89
- const outputResult = this.outputValidator.safeParse(value);
90
- if (!outputResult.success) {
91
- return { success: false, error: outputResult.error };
92
- }
93
- try {
94
- // Then encode to input
95
- const encoded = this.codecTransform.encode(outputResult.data);
96
- // Handle async encode
97
- if (encoded instanceof Promise) {
98
- throw new errorsCore.VldError([
99
- errors.createIssue('custom', [], locales_runtime.getMessages().codecAsyncNotSupported)
100
- ]);
101
- }
102
- // Validate the encoded input
103
- return this.inputValidator.safeParse(encoded);
104
- }
105
- catch (error) {
106
- if (error instanceof errorsCore.VldError) {
107
- return { success: false, error };
108
- }
109
- return {
110
- success: false,
111
- error: new errorsCore.VldError([
112
- errors.createIssue('custom', [], locales_runtime.getMessages().codecEncodeFailed)
113
- ])
114
- };
115
- }
116
- }
117
- /**
118
- * Async version of parse (decode)
119
- */
120
- async parseAsync(value) {
121
- const result = await this.safeParseAsync(value);
122
- if (!result.success) {
123
- throw result.error;
124
- }
125
- return result.data;
126
- }
127
- /**
128
- * Async version of safeParse (decode)
129
- */
130
- async safeParseAsync(value) {
131
- // First validate the input
132
- const inputResult = this.inputValidator.safeParse(value);
133
- if (!inputResult.success) {
134
- return { success: false, error: inputResult.error };
135
- }
136
- try {
137
- // Then decode to output (supports async)
138
- const decoded = await this.codecTransform.decode(inputResult.data);
139
- // Validate the decoded output
140
- return this.outputValidator.safeParse(decoded);
141
- }
142
- catch (error) {
143
- if (error instanceof errorsCore.VldError) {
144
- return { success: false, error };
145
- }
146
- return {
147
- success: false,
148
- error: new errorsCore.VldError([
149
- errors.createIssue('custom', [], locales_runtime.getMessages().codecDecodeFailed)
150
- ])
151
- };
152
- }
153
- }
154
- /**
155
- * Async version of encode
156
- */
157
- async encodeAsync(value) {
158
- const result = await this.safeEncodeAsync(value);
159
- if (!result.success) {
160
- throw result.error;
161
- }
162
- return result.data;
163
- }
164
- /**
165
- * Async version of safeEncode
166
- */
167
- async safeEncodeAsync(value) {
168
- // First validate the output
169
- const outputResult = this.outputValidator.safeParse(value);
170
- if (!outputResult.success) {
171
- return { success: false, error: outputResult.error };
172
- }
173
- try {
174
- // Then encode to input (supports async)
175
- const encoded = await this.codecTransform.encode(outputResult.data);
176
- // Validate the encoded input
177
- return this.inputValidator.safeParse(encoded);
178
- }
179
- catch (error) {
180
- if (error instanceof errorsCore.VldError) {
181
- return { success: false, error };
182
- }
183
- return {
184
- success: false,
185
- error: new errorsCore.VldError([
186
- errors.createIssue('custom', [], locales_runtime.getMessages().codecEncodeFailed)
187
- ])
188
- };
189
- }
190
- }
191
- /**
192
- * Create a codec validator
193
- */
194
- static create(inputValidator, outputValidator, codecTransform) {
195
- return new VldCodec(inputValidator, outputValidator, codecTransform);
196
- }
197
- /**
198
- * Create a codec with input and output directions swapped.
199
- */
200
- static invert(codec) {
201
- return codec.invert();
202
- }
203
- }
204
-
205
- exports.VldCodec = VldCodec;
1
+ "use strict";var e=require("./base.cjs"),r=require("../errors.cjs"),s=require("../locales/runtime.cjs"),c=require("../chunks/errors-core-DKPohm9I.cjs");require("../registry.cjs"),require("../pigment.cjs"),require("../locales/en.cjs");class VldCodec extends e.VldBase{constructor(r,s,c){super(e.VLD_VALIDATOR_TYPES.CODEC),this.inputValidator=r,this.outputValidator=s,this.codecTransform=c}parse(e){const r=this.safeParse(e);if(!r.success)throw r.error;return r.data}safeParse(e){const t=this.inputValidator.safeParse(e);if(!t.success)return{success:!1,error:t.error};try{const e=this.codecTransform.decode(t.data);if(e instanceof Promise)throw new c.VldError([r.createIssue("custom",[],s.getMessages().codecAsyncNotSupported)]);return this.outputValidator.safeParse(e)}catch(e){return e instanceof c.VldError?{success:!1,error:e}:{success:!1,error:new c.VldError([r.createIssue("custom",[],s.getMessages().codecDecodeFailed)])}}}invert(){return new VldCodec(this.outputValidator,this.inputValidator,{decode:this.codecTransform.encode,encode:this.codecTransform.decode})}encode(e){const r=this.safeEncode(e);if(!r.success)throw r.error;return r.data}safeEncode(e){const t=this.outputValidator.safeParse(e);if(!t.success)return{success:!1,error:t.error};try{const e=this.codecTransform.encode(t.data);if(e instanceof Promise)throw new c.VldError([r.createIssue("custom",[],s.getMessages().codecAsyncNotSupported)]);return this.inputValidator.safeParse(e)}catch(e){return e instanceof c.VldError?{success:!1,error:e}:{success:!1,error:new c.VldError([r.createIssue("custom",[],s.getMessages().codecEncodeFailed)])}}}async parseAsync(e){const r=await this.safeParseAsync(e);if(!r.success)throw r.error;return r.data}async safeParseAsync(e){const t=this.inputValidator.safeParse(e);if(!t.success)return{success:!1,error:t.error};try{const e=await this.codecTransform.decode(t.data);return this.outputValidator.safeParse(e)}catch(e){return e instanceof c.VldError?{success:!1,error:e}:{success:!1,error:new c.VldError([r.createIssue("custom",[],s.getMessages().codecDecodeFailed)])}}}async encodeAsync(e){const r=await this.safeEncodeAsync(e);if(!r.success)throw r.error;return r.data}async safeEncodeAsync(e){const t=this.outputValidator.safeParse(e);if(!t.success)return{success:!1,error:t.error};try{const e=await this.codecTransform.encode(t.data);return this.inputValidator.safeParse(e)}catch(e){return e instanceof c.VldError?{success:!1,error:e}:{success:!1,error:new c.VldError([r.createIssue("custom",[],s.getMessages().codecEncodeFailed)])}}}static create(e,r,s){return new VldCodec(e,r,s)}static invert(e){return e.invert()}}exports.VldCodec=VldCodec;