@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.
- package/CHANGELOG.md +87 -0
- package/README.md +1296 -1235
- package/dist/chunks/errors-core-Cqi4-9ew.js +1 -0
- package/dist/chunks/index-CkbfQQ4n.js +1 -0
- package/dist/chunks/index-yjpbvFgw.js +1 -0
- package/dist/chunks/ip-validation-g5LWgy9t.js +1 -0
- package/dist/chunks/security-Dy24T8N7.js +1 -0
- package/dist/cjs/chunks/errors-core-DKPohm9I.cjs +1 -0
- package/dist/cjs/chunks/index-BEV9nG0N.cjs +1 -0
- package/dist/cjs/chunks/index-ZjHAxYdA.cjs +1 -0
- package/dist/cjs/chunks/ip-validation-BZqPamPC.cjs +1 -0
- package/dist/cjs/chunks/security-aXZVI7qW.cjs +1 -0
- package/dist/cjs/cli/bin.cjs +1 -505
- package/dist/cjs/cli/index.cjs +1 -209
- package/dist/cjs/codecs/index.cjs +1 -45
- package/dist/cjs/coercion/index.cjs +1 -588
- package/dist/cjs/compat/emitter.cjs +1 -184
- package/dist/cjs/compat/result.cjs +1 -189
- package/dist/cjs/errors.cjs +1 -180
- package/dist/cjs/index.cjs +1 -1894
- package/dist/cjs/kernel.cjs +1 -415
- package/dist/cjs/locales/af.cjs +1 -108
- package/dist/cjs/locales/ar.cjs +1 -108
- package/dist/cjs/locales/bn.cjs +1 -108
- package/dist/cjs/locales/da.cjs +1 -108
- package/dist/cjs/locales/de.cjs +1 -108
- package/dist/cjs/locales/en.cjs +1 -108
- package/dist/cjs/locales/es-MX.cjs +1 -107
- package/dist/cjs/locales/es.cjs +1 -96
- package/dist/cjs/locales/fi.cjs +1 -108
- package/dist/cjs/locales/fr.cjs +1 -96
- package/dist/cjs/locales/hi.cjs +1 -108
- package/dist/cjs/locales/id.cjs +1 -108
- package/dist/cjs/locales/index.cjs +1 -43
- package/dist/cjs/locales/it.cjs +1 -108
- package/dist/cjs/locales/ja.cjs +1 -108
- package/dist/cjs/locales/ko.cjs +1 -108
- package/dist/cjs/locales/lazy.cjs +1 -188
- package/dist/cjs/locales/nl.cjs +1 -108
- package/dist/cjs/locales/no.cjs +1 -108
- package/dist/cjs/locales/pl.cjs +1 -108
- package/dist/cjs/locales/pt-BR.cjs +1 -108
- package/dist/cjs/locales/pt.cjs +1 -108
- package/dist/cjs/locales/ru.cjs +1 -108
- package/dist/cjs/locales/runtime.cjs +1 -51
- package/dist/cjs/locales/sv.cjs +1 -108
- package/dist/cjs/locales/sw.cjs +1 -108
- package/dist/cjs/locales/th.cjs +1 -108
- package/dist/cjs/locales/tr.cjs +1 -108
- package/dist/cjs/locales/vi.cjs +1 -108
- package/dist/cjs/locales/zh.cjs +1 -108
- package/dist/cjs/mini.cjs +1 -242
- package/dist/cjs/pigment.cjs +1 -207
- package/dist/cjs/plugins/index.cjs +1 -12
- package/dist/cjs/registry.cjs +1 -37
- package/dist/cjs/v3/index.cjs +1 -425
- package/dist/cjs/v4/core/index.cjs +1 -894
- package/dist/cjs/v4/index.cjs +1 -425
- package/dist/cjs/v4/locales/index.cjs +1 -130
- package/dist/cjs/v4/mini/index.cjs +1 -509
- package/dist/cjs/v4-mini/index.cjs +1 -532
- package/dist/cjs/validators/any.cjs +1 -40
- package/dist/cjs/validators/array.cjs +1 -283
- package/dist/cjs/validators/base.cjs +1 -887
- package/dist/cjs/validators/base64.cjs +1 -73
- package/dist/cjs/validators/bigint.cjs +1 -232
- package/dist/cjs/validators/boolean.cjs +1 -146
- package/dist/cjs/validators/codec.cjs +1 -205
- package/dist/cjs/validators/custom.cjs +1 -71
- package/dist/cjs/validators/date.cjs +1 -278
- package/dist/cjs/validators/discriminated-union.cjs +1 -130
- package/dist/cjs/validators/enum.cjs +1 -154
- package/dist/cjs/validators/file.cjs +1 -130
- package/dist/cjs/validators/function.cjs +1 -63
- package/dist/cjs/validators/hex.cjs +1 -70
- package/dist/cjs/validators/index.cjs +1 -123
- package/dist/cjs/validators/intersection.cjs +1 -120
- package/dist/cjs/validators/json.cjs +1 -70
- package/dist/cjs/validators/lazy.cjs +1 -53
- package/dist/cjs/validators/literal.cjs +1 -64
- package/dist/cjs/validators/map.cjs +1 -218
- package/dist/cjs/validators/nan.cjs +1 -41
- package/dist/cjs/validators/never.cjs +1 -36
- package/dist/cjs/validators/null.cjs +1 -43
- package/dist/cjs/validators/number.cjs +1 -427
- package/dist/cjs/validators/object.cjs +1 -868
- package/dist/cjs/validators/promise.cjs +1 -115
- package/dist/cjs/validators/record.cjs +1 -262
- package/dist/cjs/validators/set.cjs +1 -203
- package/dist/cjs/validators/string-bool.cjs +1 -124
- package/dist/cjs/validators/string-formats.cjs +1 -168
- package/dist/cjs/validators/string.cjs +1 -12
- package/dist/cjs/validators/symbol.cjs +1 -62
- package/dist/cjs/validators/template-literal.cjs +1 -108
- package/dist/cjs/validators/tuple.cjs +1 -187
- package/dist/cjs/validators/uint8array.cjs +1 -106
- package/dist/cjs/validators/undefined.cjs +1 -43
- package/dist/cjs/validators/union.cjs +1 -191
- package/dist/cjs/validators/unknown.cjs +1 -40
- package/dist/cjs/validators/void.cjs +1 -48
- package/dist/cjs/validators/xor.cjs +1 -69
- package/dist/cli/bin.js +1 -406
- package/dist/cli/index.js +1 -205
- package/dist/codecs/index.js +1 -11
- package/dist/coercion/index.js +1 -579
- package/dist/compat/emitter.js +1 -180
- package/dist/compat/result.js +1 -170
- package/dist/errors-core.d.ts +20 -1
- package/dist/errors.js +1 -171
- package/dist/index.d.ts +248 -357
- package/dist/index.js +1 -1534
- package/dist/kernel.js +1 -409
- package/dist/locales/af.js +1 -106
- package/dist/locales/ar.js +1 -106
- package/dist/locales/bn.js +1 -106
- package/dist/locales/da.js +1 -106
- package/dist/locales/de.js +1 -106
- package/dist/locales/en.js +1 -106
- package/dist/locales/es-MX.js +1 -105
- package/dist/locales/es.js +1 -94
- package/dist/locales/fi.js +1 -106
- package/dist/locales/fr.js +1 -94
- package/dist/locales/hi.js +1 -106
- package/dist/locales/id.js +1 -106
- package/dist/locales/index.js +1 -29
- package/dist/locales/it.js +1 -106
- package/dist/locales/ja.js +1 -106
- package/dist/locales/ko.js +1 -106
- package/dist/locales/lazy.js +1 -177
- package/dist/locales/nl.js +1 -106
- package/dist/locales/no.js +1 -106
- package/dist/locales/pl.js +1 -106
- package/dist/locales/pt-BR.js +1 -106
- package/dist/locales/pt.js +1 -106
- package/dist/locales/ru.js +1 -106
- package/dist/locales/runtime.js +1 -41
- package/dist/locales/sv.js +1 -106
- package/dist/locales/sw.js +1 -106
- package/dist/locales/th.js +1 -106
- package/dist/locales/tr.js +1 -106
- package/dist/locales/vi.js +1 -106
- package/dist/locales/zh.js +1 -106
- package/dist/mini.d.ts +3 -3
- package/dist/mini.js +1 -156
- package/dist/pigment.js +1 -180
- package/dist/plugins/index.js +1 -1
- package/dist/registry.js +1 -34
- package/dist/utils/json-schema.d.ts +10 -1
- package/dist/v3/index.js +1 -46
- package/dist/v4/core/index.d.ts +28 -16
- package/dist/v4/core/index.js +1 -277
- package/dist/v4/index.js +1 -50
- package/dist/v4/locales/index.d.ts +4 -0
- package/dist/v4/locales/index.js +1 -77
- package/dist/v4/mini/index.js +1 -47
- package/dist/v4-mini/index.d.ts +1 -1
- package/dist/v4-mini/index.js +1 -75
- package/dist/validators/any.js +1 -37
- package/dist/validators/array.d.ts +7 -0
- package/dist/validators/array.js +1 -279
- package/dist/validators/base.d.ts +63 -8
- package/dist/validators/base.js +1 -868
- package/dist/validators/base64.js +1 -68
- package/dist/validators/bigint.js +1 -228
- package/dist/validators/boolean.js +1 -142
- package/dist/validators/codec.js +1 -200
- package/dist/validators/custom.js +1 -67
- package/dist/validators/date.js +1 -274
- package/dist/validators/discriminated-union.d.ts +2 -2
- package/dist/validators/discriminated-union.js +1 -123
- package/dist/validators/enum.js +1 -150
- package/dist/validators/file.js +1 -125
- package/dist/validators/function.js +1 -58
- package/dist/validators/hex.js +1 -65
- package/dist/validators/index.d.ts +1 -1
- package/dist/validators/index.js +1 -35
- package/dist/validators/intersection.js +1 -116
- package/dist/validators/json.js +1 -66
- package/dist/validators/lazy.js +1 -50
- package/dist/validators/literal.d.ts +7 -3
- package/dist/validators/literal.js +1 -60
- package/dist/validators/map.js +1 -214
- package/dist/validators/nan.js +1 -38
- package/dist/validators/never.js +1 -32
- package/dist/validators/null.js +1 -40
- package/dist/validators/number.d.ts +20 -1
- package/dist/validators/number.js +1 -423
- package/dist/validators/object.d.ts +12 -2
- package/dist/validators/object.js +1 -864
- package/dist/validators/promise.js +1 -111
- package/dist/validators/record.d.ts +11 -8
- package/dist/validators/record.js +1 -258
- package/dist/validators/set.js +1 -199
- package/dist/validators/string-bool.js +1 -120
- package/dist/validators/string-formats.d.ts +58 -62
- package/dist/validators/string-formats.js +1 -135
- package/dist/validators/string.d.ts +47 -10
- package/dist/validators/string.js +1 -4
- package/dist/validators/symbol.js +1 -58
- package/dist/validators/template-literal.js +1 -103
- package/dist/validators/tuple.d.ts +17 -13
- package/dist/validators/tuple.js +1 -183
- package/dist/validators/uint8array.js +1 -101
- package/dist/validators/undefined.js +1 -40
- package/dist/validators/union.js +1 -187
- package/dist/validators/unknown.js +1 -37
- package/dist/validators/void.js +1 -44
- package/dist/validators/xor.d.ts +2 -2
- package/dist/validators/xor.js +1 -66
- package/package.json +239 -238
- package/dist/chunks/errors-core-BeiFUtZM.js +0 -81
- package/dist/chunks/index-0R2ntSud.js +0 -508
- package/dist/chunks/index-BvH403Yy.js +0 -88
- package/dist/chunks/security-B0Pd_vSY.js +0 -35
- package/dist/chunks/string-BJRQod3t.js +0 -530
- package/dist/cjs/chunks/errors-core-DWxLFs2f.cjs +0 -83
- package/dist/cjs/chunks/index-BkI37108.cjs +0 -538
- package/dist/cjs/chunks/index-Cc3bjUMX.cjs +0 -91
- package/dist/cjs/chunks/security-Dc3Jh13T.cjs +0 -37
- package/dist/cjs/chunks/string-BKZrc4hs.cjs +0 -533
package/dist/validators/map.js
CHANGED
|
@@ -1,214 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { getMessages } from '../locales/runtime.js';
|
|
3
|
-
import { V as VldError } from '../chunks/errors-core-BeiFUtZM.js';
|
|
4
|
-
|
|
5
|
-
function createMapError(message) {
|
|
6
|
-
return new VldError([{ code: 'invalid_type', path: [], message }]);
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Immutable Map validator
|
|
10
|
-
*/
|
|
11
|
-
class VldMap extends VldBase {
|
|
12
|
-
/**
|
|
13
|
-
* Private constructor to enforce immutability
|
|
14
|
-
*/
|
|
15
|
-
constructor(keyValidator, valueValidator, errorMessage) {
|
|
16
|
-
super(VLD_VALIDATOR_TYPES.MAP);
|
|
17
|
-
this.keyValidator = keyValidator;
|
|
18
|
-
this.valueValidator = valueValidator;
|
|
19
|
-
this.errorMessage = errorMessage;
|
|
20
|
-
this._simpleKeyMode = this.getSimpleItemMode(keyValidator);
|
|
21
|
-
this._simpleValueMode = this.getSimpleItemMode(valueValidator);
|
|
22
|
-
this._simpleKeyValue = this._simpleKeyMode === 'literal' ? keyValidator.literal : undefined;
|
|
23
|
-
this._simpleValueValue = this._simpleValueMode === 'literal' ? valueValidator.literal : undefined;
|
|
24
|
-
}
|
|
25
|
-
get keySchema() {
|
|
26
|
-
return this.keyValidator;
|
|
27
|
-
}
|
|
28
|
-
get valueSchema() {
|
|
29
|
-
return this.valueValidator;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Create a new Map validator
|
|
33
|
-
*/
|
|
34
|
-
static create(keyValidator, valueValidator) {
|
|
35
|
-
return new VldMap(keyValidator, valueValidator);
|
|
36
|
-
}
|
|
37
|
-
getSimpleItemMode(validator) {
|
|
38
|
-
if (validator.isSimple !== true) {
|
|
39
|
-
return undefined;
|
|
40
|
-
}
|
|
41
|
-
switch (validator.validatorType) {
|
|
42
|
-
case VLD_VALIDATOR_TYPES.STRING:
|
|
43
|
-
return 'string';
|
|
44
|
-
case VLD_VALIDATOR_TYPES.NUMBER:
|
|
45
|
-
return 'number';
|
|
46
|
-
case VLD_VALIDATOR_TYPES.BOOLEAN:
|
|
47
|
-
return 'boolean';
|
|
48
|
-
case VLD_VALIDATOR_TYPES.BIGINT:
|
|
49
|
-
return 'bigint';
|
|
50
|
-
case VLD_VALIDATOR_TYPES.SYMBOL:
|
|
51
|
-
return 'symbol';
|
|
52
|
-
case VLD_VALIDATOR_TYPES.NULL:
|
|
53
|
-
return 'null';
|
|
54
|
-
case VLD_VALIDATOR_TYPES.UNDEFINED:
|
|
55
|
-
case VLD_VALIDATOR_TYPES.VOID:
|
|
56
|
-
return 'undefinedValue';
|
|
57
|
-
case VLD_VALIDATOR_TYPES.LITERAL:
|
|
58
|
-
return 'literal';
|
|
59
|
-
case VLD_VALIDATOR_TYPES.ANY:
|
|
60
|
-
case VLD_VALIDATOR_TYPES.UNKNOWN:
|
|
61
|
-
return 'passthrough';
|
|
62
|
-
default:
|
|
63
|
-
return undefined;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
getSimpleItemError(mode, expected, received) {
|
|
67
|
-
switch (mode) {
|
|
68
|
-
case 'string':
|
|
69
|
-
return getMessages().invalidString;
|
|
70
|
-
case 'number':
|
|
71
|
-
return getMessages().invalidNumber;
|
|
72
|
-
case 'boolean':
|
|
73
|
-
return getMessages().invalidBoolean;
|
|
74
|
-
case 'bigint':
|
|
75
|
-
return getMessages().invalidBigint;
|
|
76
|
-
case 'symbol':
|
|
77
|
-
return getMessages().invalidSymbol;
|
|
78
|
-
case 'null':
|
|
79
|
-
return `Expected null, received ${typeof received}`;
|
|
80
|
-
case 'undefinedValue':
|
|
81
|
-
return getMessages().expectedUndefined;
|
|
82
|
-
case 'literal':
|
|
83
|
-
return getMessages().literalExpected(JSON.stringify(expected), JSON.stringify(received));
|
|
84
|
-
default:
|
|
85
|
-
return getMessages().invalidMap;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
parseSimpleItem(mode, expected, value) {
|
|
89
|
-
switch (mode) {
|
|
90
|
-
case 'string':
|
|
91
|
-
if (typeof value !== 'string') {
|
|
92
|
-
throw new Error(this.getSimpleItemError(mode, expected, value));
|
|
93
|
-
}
|
|
94
|
-
return value;
|
|
95
|
-
case 'number':
|
|
96
|
-
if (typeof value !== 'number' || isNaN(value)) {
|
|
97
|
-
throw new Error(this.getSimpleItemError(mode, expected, value));
|
|
98
|
-
}
|
|
99
|
-
return value;
|
|
100
|
-
case 'boolean':
|
|
101
|
-
if (typeof value !== 'boolean') {
|
|
102
|
-
throw new Error(this.getSimpleItemError(mode, expected, value));
|
|
103
|
-
}
|
|
104
|
-
return value;
|
|
105
|
-
case 'bigint':
|
|
106
|
-
if (typeof value !== 'bigint') {
|
|
107
|
-
throw new Error(this.getSimpleItemError(mode, expected, value));
|
|
108
|
-
}
|
|
109
|
-
return value;
|
|
110
|
-
case 'symbol':
|
|
111
|
-
if (typeof value !== 'symbol') {
|
|
112
|
-
throw new Error(this.getSimpleItemError(mode, expected, value));
|
|
113
|
-
}
|
|
114
|
-
return value;
|
|
115
|
-
case 'null':
|
|
116
|
-
if (value !== null) {
|
|
117
|
-
throw new Error(this.getSimpleItemError(mode, expected, value));
|
|
118
|
-
}
|
|
119
|
-
return null;
|
|
120
|
-
case 'undefinedValue':
|
|
121
|
-
if (value !== undefined) {
|
|
122
|
-
throw new Error(this.getSimpleItemError(mode, expected, value));
|
|
123
|
-
}
|
|
124
|
-
return undefined;
|
|
125
|
-
case 'literal':
|
|
126
|
-
if (value !== expected) {
|
|
127
|
-
throw new Error(this.getSimpleItemError(mode, expected, value));
|
|
128
|
-
}
|
|
129
|
-
return expected;
|
|
130
|
-
case 'passthrough':
|
|
131
|
-
return value;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Parse and validate a Map value
|
|
136
|
-
*/
|
|
137
|
-
parse(value) {
|
|
138
|
-
if (!(value instanceof Map)) {
|
|
139
|
-
throw new Error(this.errorMessage || getMessages().invalidMap);
|
|
140
|
-
}
|
|
141
|
-
return this.parseKnownMap(value);
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Parse a value that has already passed the Map instance guard.
|
|
145
|
-
* @internal Used by object validators to avoid duplicate hot-path checks.
|
|
146
|
-
*/
|
|
147
|
-
parseKnownMap(value) {
|
|
148
|
-
const result = new Map();
|
|
149
|
-
const simpleKeyMode = this._simpleKeyMode;
|
|
150
|
-
const simpleValueMode = this._simpleValueMode;
|
|
151
|
-
if (simpleKeyMode === 'string' && simpleValueMode === 'number') {
|
|
152
|
-
for (const [key, val] of value) {
|
|
153
|
-
if (typeof key !== 'string') {
|
|
154
|
-
throw new Error(this.getSimpleItemError(simpleKeyMode, this._simpleKeyValue, key));
|
|
155
|
-
}
|
|
156
|
-
if (typeof val !== 'number' || isNaN(val)) {
|
|
157
|
-
throw new Error(this.getSimpleItemError(simpleValueMode, this._simpleValueValue, val));
|
|
158
|
-
}
|
|
159
|
-
result.set(key, val);
|
|
160
|
-
}
|
|
161
|
-
return result;
|
|
162
|
-
}
|
|
163
|
-
if (simpleKeyMode === 'string' && simpleValueMode === 'string') {
|
|
164
|
-
for (const [key, val] of value) {
|
|
165
|
-
if (typeof key !== 'string') {
|
|
166
|
-
throw new Error(this.getSimpleItemError(simpleKeyMode, this._simpleKeyValue, key));
|
|
167
|
-
}
|
|
168
|
-
if (typeof val !== 'string') {
|
|
169
|
-
throw new Error(this.getSimpleItemError(simpleValueMode, this._simpleValueValue, val));
|
|
170
|
-
}
|
|
171
|
-
result.set(key, val);
|
|
172
|
-
}
|
|
173
|
-
return result;
|
|
174
|
-
}
|
|
175
|
-
if (simpleKeyMode !== undefined && simpleValueMode !== undefined) {
|
|
176
|
-
const keyMode = simpleKeyMode;
|
|
177
|
-
const valueMode = simpleValueMode;
|
|
178
|
-
for (const [key, val] of value) {
|
|
179
|
-
const validKey = this.parseSimpleItem(keyMode, this._simpleKeyValue, key);
|
|
180
|
-
const validValue = this.parseSimpleItem(valueMode, this._simpleValueValue, val);
|
|
181
|
-
result.set(validKey, validValue);
|
|
182
|
-
}
|
|
183
|
-
return result;
|
|
184
|
-
}
|
|
185
|
-
for (const [key, val] of value) {
|
|
186
|
-
try {
|
|
187
|
-
const validKey = simpleKeyMode === undefined
|
|
188
|
-
? this.keyValidator.parse(key)
|
|
189
|
-
: this.parseSimpleItem(simpleKeyMode, this._simpleKeyValue, key);
|
|
190
|
-
const validValue = simpleValueMode === undefined
|
|
191
|
-
? this.valueValidator.parse(val)
|
|
192
|
-
: this.parseSimpleItem(simpleValueMode, this._simpleValueValue, val);
|
|
193
|
-
result.set(validKey, validValue);
|
|
194
|
-
}
|
|
195
|
-
catch (error) {
|
|
196
|
-
throw new Error(error.message);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
return result;
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* Safely parse and validate a Map value
|
|
203
|
-
*/
|
|
204
|
-
safeParse(value) {
|
|
205
|
-
try {
|
|
206
|
-
return { success: true, data: this.parse(value) };
|
|
207
|
-
}
|
|
208
|
-
catch (error) {
|
|
209
|
-
return { success: false, error: createMapError(error.message) };
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
export { VldMap };
|
|
1
|
+
import{VldBase as e,VLD_VALIDATOR_TYPES as r}from"./base.js";import{getMessages as t}from"../locales/runtime.js";import{V as i}from"../chunks/errors-core-Cqi4-9ew.js";class VldMap extends e{constructor(e,t,i){super(r.MAP),this.keyValidator=e,this.valueValidator=t,this.errorMessage=i,this._simpleKeyMode=this.getSimpleItemMode(e),this._simpleValueMode=this.getSimpleItemMode(t),this._simpleKeyValue="literal"===this._simpleKeyMode?e.literal:void 0,this._simpleValueValue="literal"===this._simpleValueMode?t.literal:void 0}get keySchema(){return this.keyValidator}get valueSchema(){return this.valueValidator}static create(e,r){return new VldMap(e,r)}getSimpleItemMode(e){if(!0===e.isSimple)switch(e.validatorType){case r.STRING:return"string";case r.NUMBER:return"number";case r.BOOLEAN:return"boolean";case r.BIGINT:return"bigint";case r.SYMBOL:return"symbol";case r.NULL:return"null";case r.UNDEFINED:case r.VOID:return"undefinedValue";case r.LITERAL:return"literal";case r.ANY:case r.UNKNOWN:return"passthrough";default:return}}getSimpleItemError(e,r,i){switch(e){case"string":return t().invalidString;case"number":return t().invalidNumber;case"boolean":return t().invalidBoolean;case"bigint":return t().invalidBigint;case"symbol":return t().invalidSymbol;case"null":return"Expected null, received "+typeof i;case"undefinedValue":return t().expectedUndefined;case"literal":return t().literalExpected(JSON.stringify(r),JSON.stringify(i));default:return t().invalidMap}}parseSimpleItem(e,r,t){switch(e){case"string":if("string"!=typeof t)throw new Error(this.getSimpleItemError(e,r,t));return t;case"number":if("number"!=typeof t||isNaN(t))throw new Error(this.getSimpleItemError(e,r,t));return t;case"boolean":if("boolean"!=typeof t)throw new Error(this.getSimpleItemError(e,r,t));return t;case"bigint":if("bigint"!=typeof t)throw new Error(this.getSimpleItemError(e,r,t));return t;case"symbol":if("symbol"!=typeof t)throw new Error(this.getSimpleItemError(e,r,t));return t;case"null":if(null!==t)throw new Error(this.getSimpleItemError(e,r,t));return null;case"undefinedValue":if(void 0!==t)throw new Error(this.getSimpleItemError(e,r,t));return;case"literal":if(t!==r)throw new Error(this.getSimpleItemError(e,r,t));return r;case"passthrough":return t}}parse(e){if(!(e instanceof Map))throw new Error(this.errorMessage||t().invalidMap);return this.parseKnownMap(e)}parseKnownMap(e){const r=new Map,t=this._simpleKeyMode,i=this._simpleValueMode;if("string"===t&&"number"===i){for(const[s,a]of e){if("string"!=typeof s)throw new Error(this.getSimpleItemError(t,this._simpleKeyValue,s));if("number"!=typeof a||isNaN(a))throw new Error(this.getSimpleItemError(i,this._simpleValueValue,a));r.set(s,a)}return r}if("string"===t&&"string"===i){for(const[s,a]of e){if("string"!=typeof s)throw new Error(this.getSimpleItemError(t,this._simpleKeyValue,s));if("string"!=typeof a)throw new Error(this.getSimpleItemError(i,this._simpleValueValue,a));r.set(s,a)}return r}if(void 0!==t&&void 0!==i){const s=t,a=i;for(const[t,i]of e){const e=this.parseSimpleItem(s,this._simpleKeyValue,t),o=this.parseSimpleItem(a,this._simpleValueValue,i);r.set(e,o)}return r}for(const[s,a]of e)try{const e=void 0===t?this.keyValidator.parse(s):this.parseSimpleItem(t,this._simpleKeyValue,s),o=void 0===i?this.valueValidator.parse(a):this.parseSimpleItem(i,this._simpleValueValue,a);r.set(e,o)}catch(e){throw new Error(e.message)}return r}safeParse(e){try{return{success:!0,data:this.parse(e)}}catch(e){return{success:!1,error:(r=e.message,new i([{code:"invalid_type",path:[],message:r}]))}}var r}}export{VldMap};
|
package/dist/validators/nan.js
CHANGED
|
@@ -1,38 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { V as VldError } from '../chunks/errors-core-BeiFUtZM.js';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* VldNan - Validates that a value is NaN (Not a Number)
|
|
6
|
-
* Part of Zod 4 API parity implementation
|
|
7
|
-
*/
|
|
8
|
-
function createNanError(message) {
|
|
9
|
-
return new VldError([{ code: 'invalid_number', path: [], message }]);
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* NaN validator - validates that a value is NaN
|
|
13
|
-
* Note: Uses Number.isNaN() which is more strict than global isNaN()
|
|
14
|
-
*/
|
|
15
|
-
class VldNan extends VldBase {
|
|
16
|
-
constructor() {
|
|
17
|
-
super(VLD_VALIDATOR_TYPES.NAN);
|
|
18
|
-
}
|
|
19
|
-
static create() {
|
|
20
|
-
return new VldNan();
|
|
21
|
-
}
|
|
22
|
-
parse(value) {
|
|
23
|
-
if (typeof value !== 'number' || !Number.isNaN(value)) {
|
|
24
|
-
throw new Error(`Expected NaN, received ${typeof value === 'number' ? 'a valid number' : typeof value}`);
|
|
25
|
-
}
|
|
26
|
-
return value;
|
|
27
|
-
}
|
|
28
|
-
safeParse(value) {
|
|
29
|
-
try {
|
|
30
|
-
return { success: true, data: this.parse(value) };
|
|
31
|
-
}
|
|
32
|
-
catch (error) {
|
|
33
|
-
return { success: false, error: createNanError(error.message) };
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export { VldNan };
|
|
1
|
+
import{VldBase as e,VLD_VALIDATOR_TYPES as r}from"./base.js";import{V as s}from"../chunks/errors-core-Cqi4-9ew.js";class VldNan extends e{constructor(){super(r.NAN)}static create(){return new VldNan}parse(e){if("number"!=typeof e||!Number.isNaN(e))throw new Error("Expected NaN, received "+("number"==typeof e?"a valid number":typeof e));return e}safeParse(e){try{return{success:!0,data:this.parse(e)}}catch(e){return{success:!1,error:(r=e.message,new s([{code:"invalid_number",path:[],message:r}]))}}var r}}export{VldNan};
|
package/dist/validators/never.js
CHANGED
|
@@ -1,32 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { getMessages } from '../locales/runtime.js';
|
|
3
|
-
import { V as VldError } from '../chunks/errors-core-BeiFUtZM.js';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Validator that never succeeds
|
|
7
|
-
*/
|
|
8
|
-
class VldNever extends VldBase {
|
|
9
|
-
/**
|
|
10
|
-
* Create a new never validator
|
|
11
|
-
*/
|
|
12
|
-
static create() {
|
|
13
|
-
return new VldNever();
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Parse never value (always fails)
|
|
17
|
-
*/
|
|
18
|
-
parse(_value) {
|
|
19
|
-
throw new Error(getMessages().neverType);
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Safely parse never value (always fails)
|
|
23
|
-
*/
|
|
24
|
-
safeParse(_value) {
|
|
25
|
-
return {
|
|
26
|
-
success: false,
|
|
27
|
-
error: new VldError([{ code: 'invalid_type', path: [], message: getMessages().neverType }])
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export { VldNever };
|
|
1
|
+
import{VldBase as e}from"./base.js";import{getMessages as r}from"../locales/runtime.js";import{V as s}from"../chunks/errors-core-Cqi4-9ew.js";class VldNever extends e{static create(){return new VldNever}parse(e){throw new Error(r().neverType)}safeParse(e){return{success:!1,error:new s([{code:"invalid_type",path:[],message:r().neverType}])}}}export{VldNever};
|
package/dist/validators/null.js
CHANGED
|
@@ -1,40 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { V as VldError } from '../chunks/errors-core-BeiFUtZM.js';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* VldNull - Validates that a value is exactly null
|
|
6
|
-
* Part of Zod 4 API parity implementation
|
|
7
|
-
*/
|
|
8
|
-
function createNullError(message) {
|
|
9
|
-
return new VldError([{ code: 'invalid_type', path: [], message }]);
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Null validator - validates that a value is exactly null
|
|
13
|
-
*/
|
|
14
|
-
class VldNull extends VldBase {
|
|
15
|
-
constructor() {
|
|
16
|
-
super(VLD_VALIDATOR_TYPES.NULL);
|
|
17
|
-
}
|
|
18
|
-
static create() {
|
|
19
|
-
return new VldNull();
|
|
20
|
-
}
|
|
21
|
-
get isSimple() {
|
|
22
|
-
return true;
|
|
23
|
-
}
|
|
24
|
-
parse(value) {
|
|
25
|
-
if (value !== null) {
|
|
26
|
-
throw new Error(`Expected null, received ${typeof value}`);
|
|
27
|
-
}
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
safeParse(value) {
|
|
31
|
-
try {
|
|
32
|
-
return { success: true, data: this.parse(value) };
|
|
33
|
-
}
|
|
34
|
-
catch (error) {
|
|
35
|
-
return { success: false, error: createNullError(error.message) };
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export { VldNull };
|
|
1
|
+
import{VldBase as e,VLD_VALIDATOR_TYPES as r}from"./base.js";import{V as s}from"../chunks/errors-core-Cqi4-9ew.js";class VldNull extends e{constructor(){super(r.NULL)}static create(){return new VldNull}get isSimple(){return!0}parse(e){if(null!==e)throw new Error("Expected null, received "+typeof e);return null}safeParse(e){try{return{success:!0,data:this.parse(e)}}catch(e){return{success:!1,error:(r=e.message,new s([{code:"invalid_type",path:[],message:r}]))}}var r}}export{VldNull};
|
|
@@ -3,6 +3,15 @@ import { VldBase, ParseResult, ValidatorType, type ErrorParam } from './base.js'
|
|
|
3
3
|
* Type for number validation check functions
|
|
4
4
|
*/
|
|
5
5
|
type NumberCheck = (value: number) => boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Metadata for a single number constraint, enabling Zod 4-compatible issues.
|
|
8
|
+
*/
|
|
9
|
+
interface NumberCheckMeta {
|
|
10
|
+
readonly kind: 'min' | 'max' | 'int' | 'gt' | 'lt' | 'multiple_of' | 'finite' | 'safe' | 'other';
|
|
11
|
+
readonly value?: number;
|
|
12
|
+
readonly inclusive?: boolean;
|
|
13
|
+
readonly message: string | undefined;
|
|
14
|
+
}
|
|
6
15
|
interface NumberJSONSchemaHints {
|
|
7
16
|
type?: 'number' | 'integer';
|
|
8
17
|
minimum?: number;
|
|
@@ -19,6 +28,7 @@ interface NumberValidatorConfig {
|
|
|
19
28
|
readonly errorMessage: string | undefined;
|
|
20
29
|
readonly validatorType?: ValidatorType;
|
|
21
30
|
readonly jsonSchema: NumberJSONSchemaHints | undefined;
|
|
31
|
+
readonly checkMetas: ReadonlyArray<NumberCheckMeta> | undefined;
|
|
22
32
|
}
|
|
23
33
|
/**
|
|
24
34
|
* Immutable number validator with chainable methods
|
|
@@ -28,6 +38,7 @@ export declare class VldNumber extends VldBase<number, number> {
|
|
|
28
38
|
private readonly _checks;
|
|
29
39
|
private readonly _isSimple;
|
|
30
40
|
private readonly _fastCheckMode;
|
|
41
|
+
private readonly _checkMetas;
|
|
31
42
|
/**
|
|
32
43
|
* Protected constructor to allow extension while maintaining immutability
|
|
33
44
|
*/
|
|
@@ -49,14 +60,22 @@ export declare class VldNumber extends VldBase<number, number> {
|
|
|
49
60
|
static create(): VldNumber;
|
|
50
61
|
/**
|
|
51
62
|
* Parse and validate a number value
|
|
63
|
+
* Zod 4 behavior: Infinity and NaN are rejected by default (they are not valid numbers).
|
|
52
64
|
*/
|
|
53
65
|
parse(value: unknown): number;
|
|
66
|
+
/**
|
|
67
|
+
* Build the Zod 4-compatible VldIssue for a failed number check.
|
|
68
|
+
*/
|
|
69
|
+
private _createCheckIssue;
|
|
70
|
+
/**
|
|
71
|
+
* Run all checks against a known number and return the index of the first failing check, or -1.
|
|
72
|
+
*/
|
|
73
|
+
private _findFailingCheck;
|
|
54
74
|
/**
|
|
55
75
|
* Parse a value that has already passed the number type guard.
|
|
56
76
|
* @internal Used by object validators to avoid duplicate hot-path checks.
|
|
57
77
|
*/
|
|
58
78
|
parseKnownNumber(value: number): number;
|
|
59
|
-
private passesChecks;
|
|
60
79
|
/**
|
|
61
80
|
* Safely parse and validate a number value
|
|
62
81
|
*/
|