@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.
- package/CHANGELOG.md +113 -0
- package/README.md +413 -1235
- package/dist/chunks/errors-core-CerMg2rq.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-DrydF46s.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 +32 -2
- package/dist/errors.js +1 -171
- package/dist/index.d.ts +315 -361
- 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 +210 -17
- package/dist/validators/base.js +1 -868
- package/dist/validators/base64.js +1 -68
- package/dist/validators/bigint.d.ts +7 -0
- 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.d.ts +20 -10
- package/dist/validators/custom.js +1 -67
- package/dist/validators/date.d.ts +2 -0
- package/dist/validators/date.js +1 -274
- package/dist/validators/discriminated-union.d.ts +4 -2
- package/dist/validators/discriminated-union.js +1 -123
- package/dist/validators/enum.d.ts +8 -2
- 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 +8 -3
- package/dist/validators/literal.js +1 -60
- package/dist/validators/map.d.ts +7 -0
- 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 +25 -1
- package/dist/validators/number.js +1 -423
- package/dist/validators/object.d.ts +18 -2
- package/dist/validators/object.js +1 -864
- package/dist/validators/promise.d.ts +6 -7
- package/dist/validators/promise.js +1 -111
- package/dist/validators/record.d.ts +13 -8
- package/dist/validators/record.js +1 -258
- package/dist/validators/set.d.ts +5 -0
- 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 +49 -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.d.ts +1 -0
- 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 +240 -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/index.js
CHANGED
|
@@ -1,1534 +1 @@
|
|
|
1
|
-
import { VLD_VALIDATOR_TYPES, VldPreprocess, VldBase, VldExactOptional, VldNullish, VldNullable, VldOptional, resolveErrorMessage } from './validators/base.js';
|
|
2
|
-
export { VldMeta, VldBrand as ZodBranded, VldCatch as ZodCatch, VldDefault as ZodDefault, VldMeta as ZodMeta, VldRefine as ZodNonOptional, VldPipe as ZodPipe, VldPrefault as ZodPrefault, VldReadonly as ZodReadonly, VldTransform as ZodTransform } from './validators/base.js';
|
|
3
|
-
import { globalRegistry } from './registry.js';
|
|
4
|
-
export { registry } from './registry.js';
|
|
5
|
-
import { V as VldString } from './chunks/string-BJRQod3t.js';
|
|
6
|
-
import { VldNumber } from './validators/number.js';
|
|
7
|
-
import { VldBoolean } from './validators/boolean.js';
|
|
8
|
-
import { VldDate } from './validators/date.js';
|
|
9
|
-
import { VldStringBool } from './validators/string-bool.js';
|
|
10
|
-
import { VldArray } from './validators/array.js';
|
|
11
|
-
import { VldObject } from './validators/object.js';
|
|
12
|
-
import { VldUnion } from './validators/union.js';
|
|
13
|
-
import { VldLiteral } from './validators/literal.js';
|
|
14
|
-
import { VldBigInt } from './validators/bigint.js';
|
|
15
|
-
import { VldSymbol } from './validators/symbol.js';
|
|
16
|
-
import { VldTuple } from './validators/tuple.js';
|
|
17
|
-
import { VldRecord } from './validators/record.js';
|
|
18
|
-
import { VldSet } from './validators/set.js';
|
|
19
|
-
import { VldMap } from './validators/map.js';
|
|
20
|
-
import { VldEnum } from './validators/enum.js';
|
|
21
|
-
import { VldIntersection } from './validators/intersection.js';
|
|
22
|
-
import { VldAny } from './validators/any.js';
|
|
23
|
-
import { VldUnknown } from './validators/unknown.js';
|
|
24
|
-
import { VldVoid } from './validators/void.js';
|
|
25
|
-
import { VldNever } from './validators/never.js';
|
|
26
|
-
import { VldNull } from './validators/null.js';
|
|
27
|
-
import { VldUndefined } from './validators/undefined.js';
|
|
28
|
-
import { VldNan } from './validators/nan.js';
|
|
29
|
-
import { VldLazy } from './validators/lazy.js';
|
|
30
|
-
import { VldDiscriminatedUnion } from './validators/discriminated-union.js';
|
|
31
|
-
import { VldXor } from './validators/xor.js';
|
|
32
|
-
import { VldJson } from './validators/json.js';
|
|
33
|
-
import { templateLiteral as templateLiteral$1 } from './validators/template-literal.js';
|
|
34
|
-
export { VldTemplateLiteral as ZodTemplateLiteral } from './validators/template-literal.js';
|
|
35
|
-
import { custom as custom$1 } from './validators/custom.js';
|
|
36
|
-
export { VldCustom as ZodCustom, VldCustom as ZodSuccess } from './validators/custom.js';
|
|
37
|
-
import { VldFile, file as file$1 } from './validators/file.js';
|
|
38
|
-
import { functionValidator } from './validators/function.js';
|
|
39
|
-
export { VldFunction as ZodFunction } from './validators/function.js';
|
|
40
|
-
import { VldCodec } from './validators/codec.js';
|
|
41
|
-
import { VldBase64 } from './validators/base64.js';
|
|
42
|
-
import { VldHex } from './validators/hex.js';
|
|
43
|
-
import { VldUint8Array } from './validators/uint8array.js';
|
|
44
|
-
import { promise as promise$1 } from './validators/promise.js';
|
|
45
|
-
export { VldPromise as ZodPromise } from './validators/promise.js';
|
|
46
|
-
import { map as map$1 } from './compat/result.js';
|
|
47
|
-
export { Err, Ok, ResultUtils, all, failure, flatMap, fromNullable, isErr, isOk, isResult, mapErr, match, success, tryCatch, tryCatchAsync, unwrap, unwrapOr } from './compat/result.js';
|
|
48
|
-
import { l as localeNamespace } from './chunks/index-BvH403Yy.js';
|
|
49
|
-
export { s as setLocaleAsync } from './chunks/index-BvH403Yy.js';
|
|
50
|
-
import { VldCoerceBigInt, VldCoerceDate, VldCoerceBoolean, VldCoerceNumber, VldCoerceString } from './coercion/index.js';
|
|
51
|
-
import { flattenError, prettifyError, treeifyError } from './errors.js';
|
|
52
|
-
export { prettifyErrorColored, prettifyErrorPlain } from './errors.js';
|
|
53
|
-
import { uuid as uuid$1, httpUrl as httpUrl$1, email as email$1, regexes as REGEXES, ksuid as ksuid$1, guid as guid$1, xid as xid$1, stringFormat as stringFormat$1, iso as iso$1, hash as hash$1, e164 as e164$1, cidrv6 as cidrv6$1, cidrv4 as cidrv4$1, mac as mac$1, ipv6 as ipv6$1, ipv4 as ipv4$1, ulid as ulid$1, cuid2 as cuid2$1, cuid as cuid$1, nanoid as nanoid$1, jwt as jwt$1, hex as hex$1, base64url as base64url$1, base64 as base64$1, emoji as emoji$1, hostname as hostname$1, uuidv7 as uuidv7$1, uuidv6 as uuidv6$1, uuidv4 as uuidv4$1 } from './validators/string-formats.js';
|
|
54
|
-
export { VldStringFormat as ZodBase64, VldStringFormat as ZodBase64URL, VldStringFormat as ZodCIDRv4, VldStringFormat as ZodCIDRv6, VldStringFormat as ZodCUID, VldStringFormat as ZodCUID2, VldStringFormat as ZodCustomStringFormat, VldStringFormat as ZodE164, VldStringFormat as ZodEmail, VldStringFormat as ZodEmoji, VldStringFormat as ZodGUID, VldStringFormat as ZodIPv4, VldStringFormat as ZodIPv6, VldStringFormat as ZodISODate, VldStringFormat as ZodISODateTime, VldStringFormat as ZodISODuration, VldStringFormat as ZodISOTime, VldStringFormat as ZodJWT, VldStringFormat as ZodKSUID, VldStringFormat as ZodMAC, VldStringFormat as ZodNanoID, VldStringFormat as ZodStringFormat, VldStringFormat as ZodULID, VldStringFormat as ZodURL, VldStringFormat as ZodUUID, VldStringFormat as ZodXID } from './validators/string-formats.js';
|
|
55
|
-
export { b as base64Json, a as base64ToBytes, c as base64ToUint8Array, d as base64UrlToBytes, e as base64urlToBytes, f as bytesToUtf8, g as epochMillisToDate, h as epochSecondsToDate, i as hexLowerToBytes, j as hexToBytes, k as hexToUint8Array, l as invertCodec, m as isoDatetimeToDate, n as jsonCodec, o as jwtPayload, p as numberToBigInt, s as stringToBigInt, q as stringToBoolean, r as stringToHttpURL, t as stringToInt, u as stringToNumber, v as stringToURL, w as stringToUint8Array, x as uint8ArrayToBase64, y as uint8ArrayToBase64Url, z as uint8ArrayToHex, A as uint8ArrayToString, B as uriComponent, C as utf8ToBytes } from './chunks/index-0R2ntSud.js';
|
|
56
|
-
export { createEmitter, createEventBus, withEmitter } from './compat/emitter.js';
|
|
57
|
-
export { createVldKernel, definePlugin, getVldKernel, resetVldKernel, usePlugin } from './kernel.js';
|
|
58
|
-
export { blue, bold, createTheme, cyan, dim, gray, green, grey, italic, magenta, default as pigment, red, strip, supportsColor, underline, vldTheme, white, yellow } from './pigment.js';
|
|
59
|
-
import { V as VldError } from './chunks/errors-core-BeiFUtZM.js';
|
|
60
|
-
export { getLocale, getMessages, getSupportedLocales, isLocaleLoaded, isLocaleSupported, registerLocale, setLocale } from './locales/runtime.js';
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* JSON Schema support for VLD validators
|
|
64
|
-
* Provides conversion between VLD schemas and JSON Schema
|
|
65
|
-
*/
|
|
66
|
-
/**
|
|
67
|
-
* Convert a VLD schema to JSON Schema
|
|
68
|
-
* @param schema The VLD schema to convert
|
|
69
|
-
* @param options Conversion options
|
|
70
|
-
* @returns JSON Schema definition
|
|
71
|
-
*/
|
|
72
|
-
function toJSONSchema(schema, options = {}) {
|
|
73
|
-
const normalizedOptions = normalizeOptions(options);
|
|
74
|
-
const result = normalizeForTarget(schemaToJSONSchema(schema, normalizedOptions), normalizedOptions);
|
|
75
|
-
const target = normalizedOptions.target || 'draft-07';
|
|
76
|
-
if (target === 'draft-04') {
|
|
77
|
-
result.$schema ?? (result.$schema = 'http://json-schema.org/draft-04/schema#');
|
|
78
|
-
}
|
|
79
|
-
else if (target === 'draft-07') {
|
|
80
|
-
result.$schema ?? (result.$schema = 'http://json-schema.org/draft-07/schema#');
|
|
81
|
-
}
|
|
82
|
-
else if (target === 'draft-2019-09') {
|
|
83
|
-
result.$schema ?? (result.$schema = 'https://json-schema.org/draft/2019-09/schema');
|
|
84
|
-
}
|
|
85
|
-
else if (target === 'draft-2020-12') {
|
|
86
|
-
result.$schema ?? (result.$schema = 'https://json-schema.org/draft/2020-12/schema');
|
|
87
|
-
}
|
|
88
|
-
return result;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Convert a JSON Schema to a VLD schema
|
|
92
|
-
* @param json The JSON Schema definition
|
|
93
|
-
* @returns A VLD schema
|
|
94
|
-
*/
|
|
95
|
-
function fromJSONSchema(json) {
|
|
96
|
-
return jsonSchemaToVLD(json);
|
|
97
|
-
}
|
|
98
|
-
function normalizeOptions(options) {
|
|
99
|
-
const target = options.target;
|
|
100
|
-
if (target === 'draft-4') {
|
|
101
|
-
return { ...options, target: 'draft-04' };
|
|
102
|
-
}
|
|
103
|
-
if (target === 'draft-7') {
|
|
104
|
-
return { ...options, target: 'draft-07' };
|
|
105
|
-
}
|
|
106
|
-
return options;
|
|
107
|
-
}
|
|
108
|
-
function normalizeForTarget(definition, options) {
|
|
109
|
-
const target = options.target || 'draft-07';
|
|
110
|
-
const result = { ...definition };
|
|
111
|
-
if (Array.isArray(result.items)) {
|
|
112
|
-
const tupleItems = result.items.map((item) => normalizeForTarget(item, options));
|
|
113
|
-
if (target === 'draft-2020-12' || target === 'draft-2019-09') {
|
|
114
|
-
result.prefixItems = tupleItems;
|
|
115
|
-
result.items = false;
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
result.items = tupleItems;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
else if (result.items && typeof result.items === 'object') {
|
|
122
|
-
result.items = normalizeForTarget(result.items, options);
|
|
123
|
-
}
|
|
124
|
-
if (result.prefixItems) {
|
|
125
|
-
result.prefixItems = result.prefixItems.map((item) => normalizeForTarget(item, options));
|
|
126
|
-
}
|
|
127
|
-
if (result.properties) {
|
|
128
|
-
result.properties = Object.fromEntries(Object.entries(result.properties).map(([key, value]) => [key, normalizeForTarget(value, options)]));
|
|
129
|
-
}
|
|
130
|
-
if (result.additionalProperties && typeof result.additionalProperties === 'object') {
|
|
131
|
-
result.additionalProperties = normalizeForTarget(result.additionalProperties, options);
|
|
132
|
-
}
|
|
133
|
-
for (const key of ['anyOf', 'allOf', 'oneOf']) {
|
|
134
|
-
if (result[key]) {
|
|
135
|
-
result[key] = result[key].map((item) => normalizeForTarget(item, options));
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
if (result.not && typeof result.not === 'object') {
|
|
139
|
-
result.not = normalizeForTarget(result.not, options);
|
|
140
|
-
}
|
|
141
|
-
if (target === 'openapi-3.0') {
|
|
142
|
-
normalizeOpenAPI30(result);
|
|
143
|
-
}
|
|
144
|
-
return result;
|
|
145
|
-
}
|
|
146
|
-
function normalizeOpenAPI30(definition) {
|
|
147
|
-
if (Array.isArray(definition.type) && definition.type.includes('null')) {
|
|
148
|
-
const nonNullTypes = definition.type.filter((type) => type !== 'null');
|
|
149
|
-
definition.nullable = true;
|
|
150
|
-
if (nonNullTypes.length === 1) {
|
|
151
|
-
const nonNullType = nonNullTypes[0];
|
|
152
|
-
if (nonNullType !== undefined) {
|
|
153
|
-
definition.type = nonNullType;
|
|
154
|
-
}
|
|
155
|
-
else {
|
|
156
|
-
delete definition.type;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
else if (nonNullTypes.length > 1) {
|
|
160
|
-
definition.type = nonNullTypes;
|
|
161
|
-
}
|
|
162
|
-
else {
|
|
163
|
-
delete definition.type;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
if (typeof definition.exclusiveMinimum === 'number') {
|
|
167
|
-
definition.minimum ?? (definition.minimum = definition.exclusiveMinimum);
|
|
168
|
-
definition.exclusiveMinimum = true;
|
|
169
|
-
}
|
|
170
|
-
if (typeof definition.exclusiveMaximum === 'number') {
|
|
171
|
-
definition.maximum ?? (definition.maximum = definition.exclusiveMaximum);
|
|
172
|
-
definition.exclusiveMaximum = true;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Internal function to convert VLD schema to JSON Schema
|
|
177
|
-
*/
|
|
178
|
-
function schemaToJSONSchema(schema, options) {
|
|
179
|
-
const target = options.target || 'draft-07';
|
|
180
|
-
const schemaAny = schema;
|
|
181
|
-
const validatorType = schema.validatorType;
|
|
182
|
-
// Handle primitives
|
|
183
|
-
if (schema.constructor.name === 'VldString' || validatorType === VLD_VALIDATOR_TYPES.STRING) {
|
|
184
|
-
return withMetadata(schema, buildStringSchema(target, schema), options);
|
|
185
|
-
}
|
|
186
|
-
if (schema.constructor.name === 'VldNumber' || validatorType === VLD_VALIDATOR_TYPES.NUMBER) {
|
|
187
|
-
return withMetadata(schema, buildNumberSchema(schema), options);
|
|
188
|
-
}
|
|
189
|
-
if (schema.constructor.name === 'VldBoolean' || validatorType === VLD_VALIDATOR_TYPES.BOOLEAN) {
|
|
190
|
-
return withMetadata(schema, { type: 'boolean' }, options);
|
|
191
|
-
}
|
|
192
|
-
if (schema.constructor.name === 'VldBigInt' || validatorType === VLD_VALIDATOR_TYPES.BIGINT) {
|
|
193
|
-
return withMetadata(schema, buildBigIntSchema(schema), options);
|
|
194
|
-
}
|
|
195
|
-
if (schema.constructor.name === 'VldDate' || validatorType === VLD_VALIDATOR_TYPES.DATE) {
|
|
196
|
-
return withMetadata(schema, buildDateSchema(schema), options);
|
|
197
|
-
}
|
|
198
|
-
if (schema.constructor.name === 'VldArray' || validatorType === VLD_VALIDATOR_TYPES.ARRAY) {
|
|
199
|
-
return withMetadata(schema, buildArraySchema(schema, options), options);
|
|
200
|
-
}
|
|
201
|
-
if (schema.constructor.name === 'VldObject' || validatorType === VLD_VALIDATOR_TYPES.OBJECT) {
|
|
202
|
-
return withMetadata(schema, buildObjectSchema(schema, options), options);
|
|
203
|
-
}
|
|
204
|
-
// Handle union types
|
|
205
|
-
if (schema.constructor.name === 'VldUnion') {
|
|
206
|
-
return withMetadata(schema, buildUnionSchema(schema, options), options);
|
|
207
|
-
}
|
|
208
|
-
// Handle literal types
|
|
209
|
-
if (schema.constructor.name === 'VldLiteral') {
|
|
210
|
-
return withMetadata(schema, buildLiteralSchema(schema), options);
|
|
211
|
-
}
|
|
212
|
-
if (schema.constructor.name === 'VldEnum') {
|
|
213
|
-
return withMetadata(schema, buildEnumSchema(schema), options);
|
|
214
|
-
}
|
|
215
|
-
if (schema.constructor.name === 'VldSet' || validatorType === VLD_VALIDATOR_TYPES.SET) {
|
|
216
|
-
return withMetadata(schema, buildSetSchema(schema, options), options);
|
|
217
|
-
}
|
|
218
|
-
if (schema.constructor.name === 'VldMap' || validatorType === VLD_VALIDATOR_TYPES.MAP) {
|
|
219
|
-
return withMetadata(schema, buildMapSchema(schema, options), options);
|
|
220
|
-
}
|
|
221
|
-
if (schema.constructor.name === 'VldRecord' || validatorType === VLD_VALIDATOR_TYPES.RECORD) {
|
|
222
|
-
return withMetadata(schema, buildRecordSchema(schema, options), options);
|
|
223
|
-
}
|
|
224
|
-
if (schema.constructor.name === 'VldTuple' || validatorType === VLD_VALIDATOR_TYPES.TUPLE) {
|
|
225
|
-
return withMetadata(schema, buildTupleSchema(schema, options), options);
|
|
226
|
-
}
|
|
227
|
-
if (schema.constructor.name === 'VldIntersection') {
|
|
228
|
-
return withMetadata(schema, buildIntersectionSchema(schema, options), options);
|
|
229
|
-
}
|
|
230
|
-
if (schema.constructor.name === 'VldOptional') {
|
|
231
|
-
return withMetadata(schema, buildOptionalSchema(schema, options), options);
|
|
232
|
-
}
|
|
233
|
-
if (schema.constructor.name === 'VldNullable') {
|
|
234
|
-
return withMetadata(schema, buildNullableSchema(schema, options), options);
|
|
235
|
-
}
|
|
236
|
-
if (schema.constructor.name === 'VldNullish') {
|
|
237
|
-
return withMetadata(schema, buildNullishSchema(schema, options), options);
|
|
238
|
-
}
|
|
239
|
-
if (schema.constructor.name === 'VldExactOptional') {
|
|
240
|
-
return withMetadata(schema, buildExactOptionalSchema(schema, options), options);
|
|
241
|
-
}
|
|
242
|
-
if (schema.constructor.name === 'VldLazy') {
|
|
243
|
-
return withMetadata(schema, { type: 'object' }, options); // Placeholder for recursive schemas
|
|
244
|
-
}
|
|
245
|
-
if (schema.constructor.name === 'VldJson') {
|
|
246
|
-
return withMetadata(schema, {}, options); // Any JSON
|
|
247
|
-
}
|
|
248
|
-
if (schema.constructor.name === 'VldAny') {
|
|
249
|
-
return withMetadata(schema, {}, options); // JSON Schema true
|
|
250
|
-
}
|
|
251
|
-
if (schema.constructor.name === 'VldUnknown') {
|
|
252
|
-
return withMetadata(schema, {}, options); // JSON Schema true
|
|
253
|
-
}
|
|
254
|
-
if (schema.constructor.name === 'VldNever') {
|
|
255
|
-
return withMetadata(schema, { not: {} }, options); // JSON Schema false
|
|
256
|
-
}
|
|
257
|
-
if (schema.constructor.name === 'VldNull') {
|
|
258
|
-
return withMetadata(schema, { type: 'null' }, options);
|
|
259
|
-
}
|
|
260
|
-
if (schema.constructor.name === 'VldUndefined') {
|
|
261
|
-
return withMetadata(schema, { not: {} }, options); // Undefined can't be represented in JSON Schema
|
|
262
|
-
}
|
|
263
|
-
if (schema.constructor.name === 'VldNan') {
|
|
264
|
-
return withMetadata(schema, { type: 'number', not: {} }, options); // NaN is a number type constraint
|
|
265
|
-
}
|
|
266
|
-
if (schema.constructor.name === 'VldVoid') {
|
|
267
|
-
return withMetadata(schema, { not: {} }, options); // Void/undefined can't be represented
|
|
268
|
-
}
|
|
269
|
-
// Handle branded types - unwrap and continue
|
|
270
|
-
if (schema.constructor.name === 'VldBrand') {
|
|
271
|
-
return withMetadata(schema, schemaToJSONSchema(schemaAny.baseValidator, options), options);
|
|
272
|
-
}
|
|
273
|
-
// Handle readonly types
|
|
274
|
-
if (schema.constructor.name === 'VldReadonly') {
|
|
275
|
-
return withMetadata(schema, schemaToJSONSchema(schemaAny.baseValidator, options), options);
|
|
276
|
-
}
|
|
277
|
-
// Handle transform types
|
|
278
|
-
if (schema.constructor.name === 'VldTransform') {
|
|
279
|
-
return schemaToJSONSchema(schema._inner, options);
|
|
280
|
-
}
|
|
281
|
-
// Handle meta types - unwrap metadata
|
|
282
|
-
if (schema.constructor.name === 'VldMeta') {
|
|
283
|
-
const result = schemaToJSONSchema(schemaAny.baseValidator, options);
|
|
284
|
-
return withMetadata(schema, result, options);
|
|
285
|
-
}
|
|
286
|
-
// Handle refine/superRefine types
|
|
287
|
-
if (schema.constructor.name === 'VldRefine' || schema.constructor.name === 'VldSuperRefine') {
|
|
288
|
-
return withMetadata(schema, schemaToJSONSchema(unwrapInner(schemaAny), options), options);
|
|
289
|
-
}
|
|
290
|
-
// Handle pipe types
|
|
291
|
-
if (schema.constructor.name === 'VldPipe') {
|
|
292
|
-
return withMetadata(schema, schemaToJSONSchema(schemaAny._next || schemaAny.second, options), options);
|
|
293
|
-
}
|
|
294
|
-
// Handle default/catch types
|
|
295
|
-
if (schema.constructor.name === 'VldDefault' || schema.constructor.name === 'VldCatch') {
|
|
296
|
-
return withMetadata(schema, schemaToJSONSchema(unwrapInner(schemaAny), options), options);
|
|
297
|
-
}
|
|
298
|
-
// Handle preprocess types
|
|
299
|
-
if (schema.constructor.name === 'VldPreprocess') {
|
|
300
|
-
return withMetadata(schema, schemaToJSONSchema(schemaAny._schema, options), options);
|
|
301
|
-
}
|
|
302
|
-
// Handle string format validators
|
|
303
|
-
if (schema.constructor.name === 'VldStringFormat') {
|
|
304
|
-
const formatSchema = schema;
|
|
305
|
-
return withMetadata(schema, { type: 'string', format: formatSchema._format }, options);
|
|
306
|
-
}
|
|
307
|
-
// Fallback for unknown types
|
|
308
|
-
return withMetadata(schema, {}, options);
|
|
309
|
-
}
|
|
310
|
-
function unwrapInner(schema) {
|
|
311
|
-
if (typeof schema.unwrap === 'function') {
|
|
312
|
-
return schema.unwrap();
|
|
313
|
-
}
|
|
314
|
-
return schema._inner || schema._baseValidator || schema.baseValidator || schema.valueValidator;
|
|
315
|
-
}
|
|
316
|
-
function getMetadata(schema) {
|
|
317
|
-
const registered = globalRegistry.get(schema);
|
|
318
|
-
const schemaAny = schema;
|
|
319
|
-
const local = typeof schemaAny.getMeta === 'function' ? schemaAny.getMeta() : undefined;
|
|
320
|
-
return registered || local ? { ...(local || {}), ...(registered || {}) } : undefined;
|
|
321
|
-
}
|
|
322
|
-
function withMetadata(schema, definition, options) {
|
|
323
|
-
if (options.includeMetadata === false) {
|
|
324
|
-
return definition;
|
|
325
|
-
}
|
|
326
|
-
const metadata = getMetadata(schema);
|
|
327
|
-
if (!metadata) {
|
|
328
|
-
return definition;
|
|
329
|
-
}
|
|
330
|
-
const result = { ...definition };
|
|
331
|
-
if (metadata.id)
|
|
332
|
-
result.$id = metadata.id;
|
|
333
|
-
if (metadata.title)
|
|
334
|
-
result.title = metadata.title;
|
|
335
|
-
if (metadata.description)
|
|
336
|
-
result.description = metadata.description;
|
|
337
|
-
if (metadata.examples && options.includeExamples !== false)
|
|
338
|
-
result.examples = metadata.examples;
|
|
339
|
-
if (metadata.default !== undefined)
|
|
340
|
-
result.default = metadata.default;
|
|
341
|
-
if (metadata.deprecated)
|
|
342
|
-
result.deprecated = true;
|
|
343
|
-
if (metadata.readOnly)
|
|
344
|
-
result.readOnly = true;
|
|
345
|
-
if (metadata.writeOnly)
|
|
346
|
-
result.writeOnly = true;
|
|
347
|
-
return result;
|
|
348
|
-
}
|
|
349
|
-
/**
|
|
350
|
-
* Build string JSON Schema
|
|
351
|
-
*/
|
|
352
|
-
function buildStringSchema(_target, schema) {
|
|
353
|
-
const hints = schema?.config?.jsonSchema || {};
|
|
354
|
-
const result = { type: 'string' };
|
|
355
|
-
if (hints.exactLength !== undefined) {
|
|
356
|
-
result.minLength = hints.exactLength;
|
|
357
|
-
result.maxLength = hints.exactLength;
|
|
358
|
-
}
|
|
359
|
-
else {
|
|
360
|
-
if (hints.minLength !== undefined)
|
|
361
|
-
result.minLength = hints.minLength;
|
|
362
|
-
if (hints.maxLength !== undefined)
|
|
363
|
-
result.maxLength = hints.maxLength;
|
|
364
|
-
}
|
|
365
|
-
if (hints.format)
|
|
366
|
-
result.format = hints.format;
|
|
367
|
-
if (hints.pattern)
|
|
368
|
-
result.pattern = hints.pattern;
|
|
369
|
-
return result;
|
|
370
|
-
}
|
|
371
|
-
/**
|
|
372
|
-
* Build number JSON Schema from VLD number schema
|
|
373
|
-
*/
|
|
374
|
-
function buildNumberSchema(schema, _target) {
|
|
375
|
-
const config = schema.config || {};
|
|
376
|
-
const hints = config.jsonSchema || {};
|
|
377
|
-
const checks = config.checks || [];
|
|
378
|
-
const result = { type: hints.type || 'number' };
|
|
379
|
-
if (hints.minimum !== undefined)
|
|
380
|
-
result.minimum = hints.minimum;
|
|
381
|
-
if (hints.maximum !== undefined)
|
|
382
|
-
result.maximum = hints.maximum;
|
|
383
|
-
if (hints.exclusiveMinimum !== undefined)
|
|
384
|
-
result.exclusiveMinimum = hints.exclusiveMinimum;
|
|
385
|
-
if (hints.exclusiveMaximum !== undefined)
|
|
386
|
-
result.exclusiveMaximum = hints.exclusiveMaximum;
|
|
387
|
-
if (hints.multipleOf !== undefined)
|
|
388
|
-
result.multipleOf = hints.multipleOf;
|
|
389
|
-
if (Object.keys(hints).length > 0) {
|
|
390
|
-
return result;
|
|
391
|
-
}
|
|
392
|
-
for (const check of checks) {
|
|
393
|
-
// Try to extract constraints from closures
|
|
394
|
-
const checkStr = check.toString();
|
|
395
|
-
if (checkStr.includes('>=') || checkStr.includes('min')) {
|
|
396
|
-
result.minimum = 0; // Default, actual value is in closure
|
|
397
|
-
}
|
|
398
|
-
if (checkStr.includes('<=') || checkStr.includes('max')) {
|
|
399
|
-
result.maximum = 0; // Default, actual value is in closure
|
|
400
|
-
}
|
|
401
|
-
if (checkStr.includes('isInteger') || checkStr.includes('int')) {
|
|
402
|
-
result.type = 'integer';
|
|
403
|
-
}
|
|
404
|
-
if (checkStr.includes('isSafeInteger')) {
|
|
405
|
-
result.type = 'integer';
|
|
406
|
-
}
|
|
407
|
-
if (checkStr.includes('Number.isFinite')) ;
|
|
408
|
-
}
|
|
409
|
-
return result;
|
|
410
|
-
}
|
|
411
|
-
function bigintToSafeNumber(value) {
|
|
412
|
-
const asNumber = Number(value);
|
|
413
|
-
if (!Number.isSafeInteger(asNumber)) {
|
|
414
|
-
return undefined;
|
|
415
|
-
}
|
|
416
|
-
return BigInt(asNumber) === value ? asNumber : undefined;
|
|
417
|
-
}
|
|
418
|
-
function applyBigIntBound(result, numericKey, extensionKey, value) {
|
|
419
|
-
if (value === undefined) {
|
|
420
|
-
return;
|
|
421
|
-
}
|
|
422
|
-
result[extensionKey] = value.toString();
|
|
423
|
-
const safeNumber = bigintToSafeNumber(value);
|
|
424
|
-
if (safeNumber !== undefined) {
|
|
425
|
-
result[numericKey] = safeNumber;
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
function buildBigIntSchema(schema) {
|
|
429
|
-
const hints = schema.jsonSchema || schema.config?.jsonSchema || {};
|
|
430
|
-
const result = { type: 'integer' };
|
|
431
|
-
applyBigIntBound(result, 'minimum', 'x-vld-minimum', hints.minimum);
|
|
432
|
-
applyBigIntBound(result, 'maximum', 'x-vld-maximum', hints.maximum);
|
|
433
|
-
applyBigIntBound(result, 'exclusiveMinimum', 'x-vld-exclusiveMinimum', hints.exclusiveMinimum);
|
|
434
|
-
applyBigIntBound(result, 'exclusiveMaximum', 'x-vld-exclusiveMaximum', hints.exclusiveMaximum);
|
|
435
|
-
return result;
|
|
436
|
-
}
|
|
437
|
-
function buildDateSchema(schema) {
|
|
438
|
-
const hints = schema.jsonSchema || schema.config?.jsonSchema || {};
|
|
439
|
-
const result = {
|
|
440
|
-
type: 'string',
|
|
441
|
-
format: 'date-time'
|
|
442
|
-
};
|
|
443
|
-
if (hints.formatMinimum)
|
|
444
|
-
result.formatMinimum = hints.formatMinimum;
|
|
445
|
-
if (hints.formatMaximum)
|
|
446
|
-
result.formatMaximum = hints.formatMaximum;
|
|
447
|
-
if (hints.formatExclusiveMinimum)
|
|
448
|
-
result.formatExclusiveMinimum = hints.formatExclusiveMinimum;
|
|
449
|
-
if (hints.formatExclusiveMaximum)
|
|
450
|
-
result.formatExclusiveMaximum = hints.formatExclusiveMaximum;
|
|
451
|
-
return result;
|
|
452
|
-
}
|
|
453
|
-
/**
|
|
454
|
-
* Build array JSON Schema
|
|
455
|
-
*/
|
|
456
|
-
function buildArraySchema(schema, options) {
|
|
457
|
-
const inner = schema._item || schema._inner || schema.config?.itemValidator;
|
|
458
|
-
const result = { type: 'array' };
|
|
459
|
-
if (inner) {
|
|
460
|
-
result.items = schemaToJSONSchema(inner, options);
|
|
461
|
-
}
|
|
462
|
-
if (schema.config?.exactLength !== undefined) {
|
|
463
|
-
result.minItems = schema.config.exactLength;
|
|
464
|
-
result.maxItems = schema.config.exactLength;
|
|
465
|
-
}
|
|
466
|
-
else {
|
|
467
|
-
if (schema.config?.minLength !== undefined)
|
|
468
|
-
result.minItems = schema.config.minLength;
|
|
469
|
-
if (schema.config?.maxLength !== undefined)
|
|
470
|
-
result.maxItems = schema.config.maxLength;
|
|
471
|
-
}
|
|
472
|
-
if (schema.config?.unique)
|
|
473
|
-
result.uniqueItems = true;
|
|
474
|
-
return result;
|
|
475
|
-
}
|
|
476
|
-
/**
|
|
477
|
-
* Build object JSON Schema
|
|
478
|
-
*/
|
|
479
|
-
function buildObjectSchema(schema, options) {
|
|
480
|
-
const shape = schema._shape || schema.shape || schema.config?.shape;
|
|
481
|
-
if (!shape)
|
|
482
|
-
return { type: 'object' };
|
|
483
|
-
const properties = {};
|
|
484
|
-
const required = [];
|
|
485
|
-
for (const [key, value] of Object.entries(shape)) {
|
|
486
|
-
const child = value;
|
|
487
|
-
properties[key] = schemaToJSONSchema(child, options);
|
|
488
|
-
// VLD objects require all keys by default
|
|
489
|
-
if (!isOptionalLike(child)) {
|
|
490
|
-
required.push(key);
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
const result = {
|
|
494
|
-
type: 'object',
|
|
495
|
-
properties
|
|
496
|
-
};
|
|
497
|
-
if (required.length > 0) {
|
|
498
|
-
result.required = required;
|
|
499
|
-
}
|
|
500
|
-
// Handle passthrough mode
|
|
501
|
-
if (schema._passthrough || schema._loose || schema.config?.passthrough) {
|
|
502
|
-
result.additionalProperties = true;
|
|
503
|
-
}
|
|
504
|
-
else if (schema._strict || schema.config?.strict) {
|
|
505
|
-
result.additionalProperties = false;
|
|
506
|
-
}
|
|
507
|
-
else if (schema.config?.catchall) {
|
|
508
|
-
result.additionalProperties = schemaToJSONSchema(schema.config.catchall, options);
|
|
509
|
-
}
|
|
510
|
-
return result;
|
|
511
|
-
}
|
|
512
|
-
function isOptionalLike(schema) {
|
|
513
|
-
const name = schema.constructor.name;
|
|
514
|
-
return (name === 'VldOptional' ||
|
|
515
|
-
name === 'VldNullish' ||
|
|
516
|
-
name === 'VldExactOptional' ||
|
|
517
|
-
schema.validatorType === VLD_VALIDATOR_TYPES.OPTIONAL ||
|
|
518
|
-
schema.validatorType === VLD_VALIDATOR_TYPES.NULLISH ||
|
|
519
|
-
schema.validatorType === VLD_VALIDATOR_TYPES.EXACT_OPTIONAL);
|
|
520
|
-
}
|
|
521
|
-
/**
|
|
522
|
-
* Build union JSON Schema
|
|
523
|
-
*/
|
|
524
|
-
function buildUnionSchema(schema, options) {
|
|
525
|
-
const validators = schema._validators || schema._options || schema.validators || [];
|
|
526
|
-
return {
|
|
527
|
-
anyOf: validators.map((v) => schemaToJSONSchema(v, options))
|
|
528
|
-
};
|
|
529
|
-
}
|
|
530
|
-
/**
|
|
531
|
-
* Build literal JSON Schema
|
|
532
|
-
*/
|
|
533
|
-
function buildLiteralSchema(schema) {
|
|
534
|
-
const value = schema._literal ?? schema.literal ?? schema._value ?? schema.value;
|
|
535
|
-
if (value === null)
|
|
536
|
-
return { type: 'null' };
|
|
537
|
-
if (typeof value === 'string')
|
|
538
|
-
return { type: 'string', const: value };
|
|
539
|
-
if (typeof value === 'number')
|
|
540
|
-
return { type: 'number', const: value };
|
|
541
|
-
if (typeof value === 'boolean')
|
|
542
|
-
return { type: 'boolean', const: value };
|
|
543
|
-
return { const: value };
|
|
544
|
-
}
|
|
545
|
-
/**
|
|
546
|
-
* Build enum JSON Schema
|
|
547
|
-
*/
|
|
548
|
-
function buildEnumSchema(schema) {
|
|
549
|
-
const values = schema._values || schema.values;
|
|
550
|
-
if (Array.isArray(values)) {
|
|
551
|
-
return { enum: [...values] };
|
|
552
|
-
}
|
|
553
|
-
return {};
|
|
554
|
-
}
|
|
555
|
-
/**
|
|
556
|
-
* Build record JSON Schema
|
|
557
|
-
*/
|
|
558
|
-
function buildRecordSchema(schema, options) {
|
|
559
|
-
const valueValidator = schema.valueSchema || schema._value || schema._inner || schema.valueValidator;
|
|
560
|
-
if (valueValidator) {
|
|
561
|
-
return {
|
|
562
|
-
type: 'object',
|
|
563
|
-
additionalProperties: schemaToJSONSchema(valueValidator, options)
|
|
564
|
-
};
|
|
565
|
-
}
|
|
566
|
-
return { type: 'object' };
|
|
567
|
-
}
|
|
568
|
-
/**
|
|
569
|
-
* Build Set JSON Schema as the JSON-compatible array representation.
|
|
570
|
-
*/
|
|
571
|
-
function buildSetSchema(schema, options) {
|
|
572
|
-
const itemValidator = schema.itemSchema || schema.itemValidator || schema._item || schema._inner;
|
|
573
|
-
const result = {
|
|
574
|
-
type: 'array',
|
|
575
|
-
uniqueItems: true,
|
|
576
|
-
'x-vld-type': 'set'
|
|
577
|
-
};
|
|
578
|
-
if (itemValidator) {
|
|
579
|
-
result.items = schemaToJSONSchema(itemValidator, options);
|
|
580
|
-
}
|
|
581
|
-
return result;
|
|
582
|
-
}
|
|
583
|
-
/**
|
|
584
|
-
* Build Map JSON Schema as an array of key/value pairs.
|
|
585
|
-
*/
|
|
586
|
-
function buildMapSchema(schema, options) {
|
|
587
|
-
const keyValidator = schema.keySchema || schema.keyValidator || schema._key;
|
|
588
|
-
const valueValidator = schema.valueSchema || schema.valueValidator || schema._value;
|
|
589
|
-
const keySchema = keyValidator ? schemaToJSONSchema(keyValidator, options) : {};
|
|
590
|
-
const valueSchema = valueValidator ? schemaToJSONSchema(valueValidator, options) : {};
|
|
591
|
-
return {
|
|
592
|
-
type: 'array',
|
|
593
|
-
'x-vld-type': 'map',
|
|
594
|
-
items: {
|
|
595
|
-
type: 'array',
|
|
596
|
-
items: [keySchema, valueSchema],
|
|
597
|
-
minItems: 2,
|
|
598
|
-
maxItems: 2
|
|
599
|
-
}
|
|
600
|
-
};
|
|
601
|
-
}
|
|
602
|
-
/**
|
|
603
|
-
* Build tuple JSON Schema
|
|
604
|
-
*/
|
|
605
|
-
function buildTupleSchema(schema, options) {
|
|
606
|
-
const items = schema.items || schema._items || schema.validators;
|
|
607
|
-
if (!items || !Array.isArray(items)) {
|
|
608
|
-
return { type: 'array' };
|
|
609
|
-
}
|
|
610
|
-
return {
|
|
611
|
-
type: 'array',
|
|
612
|
-
items: items.map((item) => schemaToJSONSchema(item, options)),
|
|
613
|
-
minItems: items.length,
|
|
614
|
-
maxItems: items.length
|
|
615
|
-
};
|
|
616
|
-
}
|
|
617
|
-
/**
|
|
618
|
-
* Build intersection JSON Schema
|
|
619
|
-
*/
|
|
620
|
-
function buildIntersectionSchema(schema, options) {
|
|
621
|
-
const first = schema._first || schema.first;
|
|
622
|
-
const second = schema._second || schema.second;
|
|
623
|
-
const schemas = [];
|
|
624
|
-
if (first)
|
|
625
|
-
schemas.push(schemaToJSONSchema(first, options));
|
|
626
|
-
if (second)
|
|
627
|
-
schemas.push(schemaToJSONSchema(second, options));
|
|
628
|
-
if (schemas.length === 0)
|
|
629
|
-
return {};
|
|
630
|
-
if (schemas.length === 1)
|
|
631
|
-
return schemas[0] ?? {};
|
|
632
|
-
return { allOf: schemas };
|
|
633
|
-
}
|
|
634
|
-
/**
|
|
635
|
-
* Build optional JSON Schema
|
|
636
|
-
*/
|
|
637
|
-
function buildOptionalSchema(schema, options) {
|
|
638
|
-
const inner = unwrapInner(schema);
|
|
639
|
-
if (!inner)
|
|
640
|
-
return {};
|
|
641
|
-
const result = schemaToJSONSchema(inner, options);
|
|
642
|
-
// Remove from required array - but we don't track required here
|
|
643
|
-
return result;
|
|
644
|
-
}
|
|
645
|
-
/**
|
|
646
|
-
* Build nullable JSON Schema
|
|
647
|
-
*/
|
|
648
|
-
function buildNullableSchema(schema, options) {
|
|
649
|
-
const inner = unwrapInner(schema);
|
|
650
|
-
if (!inner)
|
|
651
|
-
return { type: 'null' };
|
|
652
|
-
const result = schemaToJSONSchema(inner, options);
|
|
653
|
-
if (typeof result.type === 'string') {
|
|
654
|
-
return { type: [result.type, 'null'] };
|
|
655
|
-
}
|
|
656
|
-
else if (Array.isArray(result.type)) {
|
|
657
|
-
result.type.push('null');
|
|
658
|
-
return result;
|
|
659
|
-
}
|
|
660
|
-
return {
|
|
661
|
-
anyOf: [result, { type: 'null' }]
|
|
662
|
-
};
|
|
663
|
-
}
|
|
664
|
-
/**
|
|
665
|
-
* Build nullish JSON Schema
|
|
666
|
-
*/
|
|
667
|
-
function buildNullishSchema(schema, options) {
|
|
668
|
-
const inner = unwrapInner(schema);
|
|
669
|
-
if (!inner)
|
|
670
|
-
return {};
|
|
671
|
-
const result = schemaToJSONSchema(inner, options);
|
|
672
|
-
if (typeof result.type === 'string') {
|
|
673
|
-
return { ...result, type: [result.type, 'null'] };
|
|
674
|
-
}
|
|
675
|
-
return result;
|
|
676
|
-
}
|
|
677
|
-
/**
|
|
678
|
-
* Build exactOptional JSON Schema
|
|
679
|
-
*/
|
|
680
|
-
function buildExactOptionalSchema(schema, options) {
|
|
681
|
-
const inner = unwrapInner(schema);
|
|
682
|
-
if (!inner)
|
|
683
|
-
return {};
|
|
684
|
-
return schemaToJSONSchema(inner, options);
|
|
685
|
-
}
|
|
686
|
-
/**
|
|
687
|
-
* Internal function to convert JSON Schema to VLD schema
|
|
688
|
-
*/
|
|
689
|
-
function jsonSchemaToVLD(json) {
|
|
690
|
-
return applyJSONSchemaMetadata(jsonSchemaToVLDInner(json), json);
|
|
691
|
-
}
|
|
692
|
-
function jsonSchemaToVLDInner(json) {
|
|
693
|
-
// Handle $ref
|
|
694
|
-
if (json.$ref) {
|
|
695
|
-
// For now, return any - full $ref handling requires registry
|
|
696
|
-
return VldAny.create();
|
|
697
|
-
}
|
|
698
|
-
// Handle anyOf/oneOf (union)
|
|
699
|
-
if (json.anyOf || json.oneOf) {
|
|
700
|
-
const options = (json.anyOf || json.oneOf)
|
|
701
|
-
.map((s) => jsonSchemaToVLD(s))
|
|
702
|
-
.filter(Boolean);
|
|
703
|
-
if (options.length > 0) {
|
|
704
|
-
return VldUnion.create(...options);
|
|
705
|
-
}
|
|
706
|
-
}
|
|
707
|
-
// Handle allOf (intersection)
|
|
708
|
-
if (json.allOf) {
|
|
709
|
-
// For intersection, we'd need VldIntersection
|
|
710
|
-
const firstSchema = json.allOf[0];
|
|
711
|
-
if (firstSchema === undefined) {
|
|
712
|
-
return VldAny.create();
|
|
713
|
-
}
|
|
714
|
-
const first = jsonSchemaToVLD(firstSchema);
|
|
715
|
-
if (json.allOf.length > 1) {
|
|
716
|
-
const second = jsonSchemaToVLD({ allOf: json.allOf.slice(1) });
|
|
717
|
-
return VldIntersection.create(first, second);
|
|
718
|
-
}
|
|
719
|
-
return first;
|
|
720
|
-
}
|
|
721
|
-
// Handle not
|
|
722
|
-
if (json.not) {
|
|
723
|
-
// For negation, we need special handling
|
|
724
|
-
return VldAny.create();
|
|
725
|
-
}
|
|
726
|
-
// Handle const
|
|
727
|
-
if (json.const !== undefined) {
|
|
728
|
-
return VldLiteral.create(json.const);
|
|
729
|
-
}
|
|
730
|
-
// Handle enum
|
|
731
|
-
if (json.enum) {
|
|
732
|
-
return VldEnum.create(json.enum);
|
|
733
|
-
}
|
|
734
|
-
// Handle type
|
|
735
|
-
const type = json.nullable && typeof json.type === 'string'
|
|
736
|
-
? [json.type, 'null']
|
|
737
|
-
: json.type;
|
|
738
|
-
if (type === 'string' || type === undefined) {
|
|
739
|
-
let s = VldString.create();
|
|
740
|
-
if (json.minLength !== undefined)
|
|
741
|
-
s = s.min(json.minLength);
|
|
742
|
-
if (json.maxLength !== undefined)
|
|
743
|
-
s = s.max(json.maxLength);
|
|
744
|
-
if (json.pattern)
|
|
745
|
-
s = s.regex(new RegExp(json.pattern));
|
|
746
|
-
if (json.format) {
|
|
747
|
-
// Map JSON Schema formats to VLD validators
|
|
748
|
-
switch (json.format) {
|
|
749
|
-
case 'date-time':
|
|
750
|
-
case 'date':
|
|
751
|
-
case 'time':
|
|
752
|
-
// Would need DateTime validator
|
|
753
|
-
break;
|
|
754
|
-
case 'email':
|
|
755
|
-
return email$1();
|
|
756
|
-
case 'uri':
|
|
757
|
-
case 'uri-reference':
|
|
758
|
-
return httpUrl$1();
|
|
759
|
-
case 'uuid':
|
|
760
|
-
return uuid$1();
|
|
761
|
-
}
|
|
762
|
-
}
|
|
763
|
-
return s;
|
|
764
|
-
}
|
|
765
|
-
if (type === 'number' || type === 'integer') {
|
|
766
|
-
let n = VldNumber.create();
|
|
767
|
-
if (type === 'integer')
|
|
768
|
-
n = n.int();
|
|
769
|
-
if (json.minimum !== undefined)
|
|
770
|
-
n = n.min(json.minimum);
|
|
771
|
-
if (json.maximum !== undefined)
|
|
772
|
-
n = n.max(json.maximum);
|
|
773
|
-
if (typeof json.exclusiveMinimum === 'number')
|
|
774
|
-
n = n.gt(json.exclusiveMinimum);
|
|
775
|
-
if (typeof json.exclusiveMaximum === 'number')
|
|
776
|
-
n = n.lt(json.exclusiveMaximum);
|
|
777
|
-
if (json.exclusiveMinimum === true && json.minimum !== undefined)
|
|
778
|
-
n = n.gt(json.minimum);
|
|
779
|
-
if (json.exclusiveMaximum === true && json.maximum !== undefined)
|
|
780
|
-
n = n.lt(json.maximum);
|
|
781
|
-
if (json.multipleOf !== undefined)
|
|
782
|
-
n = n.multipleOf(json.multipleOf);
|
|
783
|
-
return n;
|
|
784
|
-
}
|
|
785
|
-
if (type === 'boolean') {
|
|
786
|
-
return VldBoolean.create();
|
|
787
|
-
}
|
|
788
|
-
if (type === 'array') {
|
|
789
|
-
if (json.prefixItems && json.prefixItems.length > 0) {
|
|
790
|
-
const validators = json.prefixItems.map((item) => jsonSchemaToVLD(item));
|
|
791
|
-
return VldTuple.create(...validators);
|
|
792
|
-
}
|
|
793
|
-
if (Array.isArray(json.items)) {
|
|
794
|
-
const validators = json.items.map((item) => jsonSchemaToVLD(item));
|
|
795
|
-
return VldTuple.create(...validators);
|
|
796
|
-
}
|
|
797
|
-
if (json.items && !Array.isArray(json.items)) {
|
|
798
|
-
return VldArray.create(jsonSchemaToVLD(json.items));
|
|
799
|
-
}
|
|
800
|
-
return VldArray.create(VldAny.create());
|
|
801
|
-
}
|
|
802
|
-
if (type === 'object') {
|
|
803
|
-
if (json.properties) {
|
|
804
|
-
const shape = {};
|
|
805
|
-
const required = new Set(json.required || []);
|
|
806
|
-
for (const [key, propSchema] of Object.entries(json.properties)) {
|
|
807
|
-
const fieldSchema = jsonSchemaToVLD(propSchema);
|
|
808
|
-
shape[key] = required.has(key) ? fieldSchema : fieldSchema.optional();
|
|
809
|
-
}
|
|
810
|
-
let obj = VldObject.create(shape);
|
|
811
|
-
if (json.additionalProperties === false) {
|
|
812
|
-
obj = obj.strict();
|
|
813
|
-
}
|
|
814
|
-
else if (json.additionalProperties === true) {
|
|
815
|
-
obj = obj.passthrough();
|
|
816
|
-
}
|
|
817
|
-
else if (json.additionalProperties) {
|
|
818
|
-
// additionalProperties is a schema
|
|
819
|
-
const valueSchema = jsonSchemaToVLD(json.additionalProperties);
|
|
820
|
-
return VldRecord.create(valueSchema);
|
|
821
|
-
}
|
|
822
|
-
return obj;
|
|
823
|
-
}
|
|
824
|
-
// Empty object schema
|
|
825
|
-
return VldObject.create({});
|
|
826
|
-
}
|
|
827
|
-
if (type === 'null') {
|
|
828
|
-
return VldNull.create();
|
|
829
|
-
}
|
|
830
|
-
if (Array.isArray(type)) {
|
|
831
|
-
// Union of types
|
|
832
|
-
const options = type.map((t) => {
|
|
833
|
-
return jsonSchemaToVLD({ ...json, type: t, nullable: false });
|
|
834
|
-
});
|
|
835
|
-
if (options.length > 0) {
|
|
836
|
-
return VldUnion.create(...options);
|
|
837
|
-
}
|
|
838
|
-
}
|
|
839
|
-
// Fallback to any
|
|
840
|
-
return VldAny.create();
|
|
841
|
-
}
|
|
842
|
-
function applyJSONSchemaMetadata(schema, json) {
|
|
843
|
-
const metadata = {};
|
|
844
|
-
if (json.$id)
|
|
845
|
-
metadata.id = json.$id;
|
|
846
|
-
if (json.title)
|
|
847
|
-
metadata.title = json.title;
|
|
848
|
-
if (json.description)
|
|
849
|
-
metadata.description = json.description;
|
|
850
|
-
if (json.examples)
|
|
851
|
-
metadata.examples = json.examples;
|
|
852
|
-
if (json.default !== undefined)
|
|
853
|
-
metadata.default = json.default;
|
|
854
|
-
if (json.deprecated)
|
|
855
|
-
metadata.deprecated = true;
|
|
856
|
-
if (json.readOnly)
|
|
857
|
-
metadata.readOnly = true;
|
|
858
|
-
if (json.writeOnly)
|
|
859
|
-
metadata.writeOnly = true;
|
|
860
|
-
return Object.keys(metadata).length > 0
|
|
861
|
-
? schema.meta(metadata)
|
|
862
|
-
: schema;
|
|
863
|
-
}
|
|
864
|
-
|
|
865
|
-
/**
|
|
866
|
-
* VLD Logger
|
|
867
|
-
*
|
|
868
|
-
* This module provides a debug logging system for VLD,
|
|
869
|
-
* compatible with @oxog/log when available.
|
|
870
|
-
*/
|
|
871
|
-
/**
|
|
872
|
-
* Log level priorities (lower = more verbose)
|
|
873
|
-
*/
|
|
874
|
-
const LOG_LEVEL_PRIORITY = {
|
|
875
|
-
debug: 0,
|
|
876
|
-
info: 1,
|
|
877
|
-
warn: 2,
|
|
878
|
-
error: 3,
|
|
879
|
-
silent: 4
|
|
880
|
-
};
|
|
881
|
-
/**
|
|
882
|
-
* ANSI color codes for terminal output
|
|
883
|
-
*/
|
|
884
|
-
const COLORS = {
|
|
885
|
-
reset: '\x1b[0m',
|
|
886
|
-
dim: '\x1b[2m',
|
|
887
|
-
red: '\x1b[31m',
|
|
888
|
-
yellow: '\x1b[33m',
|
|
889
|
-
blue: '\x1b[34m',
|
|
890
|
-
cyan: '\x1b[36m',
|
|
891
|
-
gray: '\x1b[90m'
|
|
892
|
-
};
|
|
893
|
-
/**
|
|
894
|
-
* Level colors
|
|
895
|
-
*/
|
|
896
|
-
const LEVEL_COLORS = {
|
|
897
|
-
debug: COLORS.gray,
|
|
898
|
-
info: COLORS.blue,
|
|
899
|
-
warn: COLORS.yellow,
|
|
900
|
-
error: COLORS.red
|
|
901
|
-
};
|
|
902
|
-
/**
|
|
903
|
-
* Level labels
|
|
904
|
-
*/
|
|
905
|
-
const LEVEL_LABELS = {
|
|
906
|
-
debug: 'DEBUG',
|
|
907
|
-
info: 'INFO ',
|
|
908
|
-
warn: 'WARN ',
|
|
909
|
-
error: 'ERROR'
|
|
910
|
-
};
|
|
911
|
-
/**
|
|
912
|
-
* Default log handler
|
|
913
|
-
*/
|
|
914
|
-
function createDefaultHandler(options) {
|
|
915
|
-
const colored = options.colored ?? true;
|
|
916
|
-
const timestamps = options.timestamps ?? true;
|
|
917
|
-
return (entry) => {
|
|
918
|
-
const parts = [];
|
|
919
|
-
// Timestamp
|
|
920
|
-
if (timestamps) {
|
|
921
|
-
const time = entry.timestamp.toISOString().slice(11, 23);
|
|
922
|
-
parts.push(colored ? `${COLORS.dim}${time}${COLORS.reset}` : time);
|
|
923
|
-
}
|
|
924
|
-
// Level
|
|
925
|
-
const levelLabel = LEVEL_LABELS[entry.level];
|
|
926
|
-
const levelColor = LEVEL_COLORS[entry.level];
|
|
927
|
-
parts.push(colored ? `${levelColor}${levelLabel}${COLORS.reset}` : levelLabel);
|
|
928
|
-
// Name
|
|
929
|
-
parts.push(colored ? `${COLORS.cyan}[${entry.name}]${COLORS.reset}` : `[${entry.name}]`);
|
|
930
|
-
// Message
|
|
931
|
-
parts.push(entry.message);
|
|
932
|
-
// Output
|
|
933
|
-
const output = parts.join(' ');
|
|
934
|
-
// Use appropriate console method
|
|
935
|
-
switch (entry.level) {
|
|
936
|
-
case 'debug':
|
|
937
|
-
console.debug(output, entry.data !== undefined ? entry.data : '');
|
|
938
|
-
break;
|
|
939
|
-
case 'info':
|
|
940
|
-
console.info(output, entry.data !== undefined ? entry.data : '');
|
|
941
|
-
break;
|
|
942
|
-
case 'warn':
|
|
943
|
-
console.warn(output, entry.data !== undefined ? entry.data : '');
|
|
944
|
-
break;
|
|
945
|
-
case 'error':
|
|
946
|
-
console.error(output, entry.data !== undefined ? entry.data : '');
|
|
947
|
-
break;
|
|
948
|
-
}
|
|
949
|
-
};
|
|
950
|
-
}
|
|
951
|
-
/**
|
|
952
|
-
* Create a logger instance
|
|
953
|
-
*/
|
|
954
|
-
function createLogger(options = {}) {
|
|
955
|
-
const name = options.name ?? 'vld';
|
|
956
|
-
let level = options.level ?? 'warn';
|
|
957
|
-
const handler = options.handler ?? createDefaultHandler(options);
|
|
958
|
-
const log = (logLevel, message, data) => {
|
|
959
|
-
if (LOG_LEVEL_PRIORITY[logLevel] < LOG_LEVEL_PRIORITY[level]) {
|
|
960
|
-
return;
|
|
961
|
-
}
|
|
962
|
-
const entry = {
|
|
963
|
-
level: logLevel,
|
|
964
|
-
message,
|
|
965
|
-
data,
|
|
966
|
-
timestamp: new Date(),
|
|
967
|
-
name
|
|
968
|
-
};
|
|
969
|
-
handler(entry);
|
|
970
|
-
};
|
|
971
|
-
const logger = {
|
|
972
|
-
debug: (message, data) => log('debug', message, data),
|
|
973
|
-
info: (message, data) => log('info', message, data),
|
|
974
|
-
warn: (message, data) => log('warn', message, data),
|
|
975
|
-
error: (message, data) => log('error', message, data),
|
|
976
|
-
isLevelEnabled: (checkLevel) => LOG_LEVEL_PRIORITY[checkLevel] >= LOG_LEVEL_PRIORITY[level],
|
|
977
|
-
setLevel: (newLevel) => {
|
|
978
|
-
level = newLevel;
|
|
979
|
-
},
|
|
980
|
-
getLevel: () => level,
|
|
981
|
-
child: (childName) => createLogger({
|
|
982
|
-
...options,
|
|
983
|
-
name: `${name}:${childName}`
|
|
984
|
-
})
|
|
985
|
-
};
|
|
986
|
-
return logger;
|
|
987
|
-
}
|
|
988
|
-
// ============================================
|
|
989
|
-
// Global Logger Management
|
|
990
|
-
// ============================================
|
|
991
|
-
let globalLogger = null;
|
|
992
|
-
/**
|
|
993
|
-
* Initialize the global VLD logger
|
|
994
|
-
*/
|
|
995
|
-
function initLogger(options) {
|
|
996
|
-
globalLogger = createLogger({
|
|
997
|
-
name: 'vld',
|
|
998
|
-
...options
|
|
999
|
-
});
|
|
1000
|
-
return globalLogger;
|
|
1001
|
-
}
|
|
1002
|
-
/**
|
|
1003
|
-
* Get the global VLD logger
|
|
1004
|
-
* Returns null if not initialized
|
|
1005
|
-
*/
|
|
1006
|
-
function getLogger() {
|
|
1007
|
-
return globalLogger;
|
|
1008
|
-
}
|
|
1009
|
-
/**
|
|
1010
|
-
* Set log level for the global logger
|
|
1011
|
-
*/
|
|
1012
|
-
function setLogLevel(level) {
|
|
1013
|
-
if (globalLogger) {
|
|
1014
|
-
globalLogger.setLevel(level);
|
|
1015
|
-
}
|
|
1016
|
-
}
|
|
1017
|
-
/**
|
|
1018
|
-
* Enable debug mode for VLD
|
|
1019
|
-
*/
|
|
1020
|
-
function enableDebug() {
|
|
1021
|
-
if (!globalLogger) {
|
|
1022
|
-
initLogger({ level: 'debug' });
|
|
1023
|
-
}
|
|
1024
|
-
else {
|
|
1025
|
-
globalLogger.setLevel('debug');
|
|
1026
|
-
}
|
|
1027
|
-
}
|
|
1028
|
-
/**
|
|
1029
|
-
* Disable all VLD logging
|
|
1030
|
-
*/
|
|
1031
|
-
function disableLogging() {
|
|
1032
|
-
if (globalLogger) {
|
|
1033
|
-
globalLogger.setLevel('silent');
|
|
1034
|
-
}
|
|
1035
|
-
}
|
|
1036
|
-
/**
|
|
1037
|
-
* Create a no-op logger for testing
|
|
1038
|
-
*/
|
|
1039
|
-
function createNoOpLogger() {
|
|
1040
|
-
return createLogger({ level: 'silent' });
|
|
1041
|
-
}
|
|
1042
|
-
|
|
1043
|
-
/**
|
|
1044
|
-
* VLD - Fast, Type-Safe Validation Library
|
|
1045
|
-
* Zero dependencies, blazing fast performance
|
|
1046
|
-
*
|
|
1047
|
-
* This is the new modular implementation with:
|
|
1048
|
-
* - Immutable validators (no memory leaks)
|
|
1049
|
-
* - Secure deepMerge (no prototype pollution)
|
|
1050
|
-
* - TypeScript strict mode support
|
|
1051
|
-
* - Better performance through pooling and memoization
|
|
1052
|
-
* - Plugin system for extensibility
|
|
1053
|
-
* - Event system for validation lifecycle hooks
|
|
1054
|
-
* - Result pattern for functional error handling
|
|
1055
|
-
* - Colored console output for better debugging
|
|
1056
|
-
* - Debug logging system
|
|
1057
|
-
*/
|
|
1058
|
-
// Import base class
|
|
1059
|
-
let globalConfig = {};
|
|
1060
|
-
let globalErrorMap;
|
|
1061
|
-
function configure(config) {
|
|
1062
|
-
if (config === undefined) {
|
|
1063
|
-
return { ...globalConfig };
|
|
1064
|
-
}
|
|
1065
|
-
globalConfig = { ...globalConfig, ...config };
|
|
1066
|
-
if ('customError' in config) {
|
|
1067
|
-
globalErrorMap = config.customError;
|
|
1068
|
-
}
|
|
1069
|
-
else if ('errorMap' in config) {
|
|
1070
|
-
globalErrorMap = config.errorMap;
|
|
1071
|
-
}
|
|
1072
|
-
return { ...globalConfig };
|
|
1073
|
-
}
|
|
1074
|
-
function setGlobalErrorMap(errorMap) {
|
|
1075
|
-
globalErrorMap = errorMap;
|
|
1076
|
-
globalConfig = { ...globalConfig, errorMap };
|
|
1077
|
-
}
|
|
1078
|
-
function getGlobalErrorMap() {
|
|
1079
|
-
return globalErrorMap;
|
|
1080
|
-
}
|
|
1081
|
-
function enumValuesFromNativeEnum(enumObject) {
|
|
1082
|
-
const values = Object.keys(enumObject)
|
|
1083
|
-
.filter(key => !/^\d+$/.test(key))
|
|
1084
|
-
.map(key => enumObject[key])
|
|
1085
|
-
.filter((value) => typeof value === 'string' || typeof value === 'number');
|
|
1086
|
-
const uniqueValues = Array.from(new Set(values));
|
|
1087
|
-
if (uniqueValues.length === 0) {
|
|
1088
|
-
throw new Error('nativeEnum requires at least one string or number value');
|
|
1089
|
-
}
|
|
1090
|
-
return uniqueValues;
|
|
1091
|
-
}
|
|
1092
|
-
function toErrorMessage(error) {
|
|
1093
|
-
return error instanceof Error ? error.message : String(error);
|
|
1094
|
-
}
|
|
1095
|
-
function addFormattedIssue(root, path, message) {
|
|
1096
|
-
let current = root;
|
|
1097
|
-
for (const segment of path) {
|
|
1098
|
-
const key = String(segment);
|
|
1099
|
-
const next = current[key];
|
|
1100
|
-
if (!next || Array.isArray(next)) {
|
|
1101
|
-
current[key] = { _errors: [] };
|
|
1102
|
-
}
|
|
1103
|
-
current = current[key];
|
|
1104
|
-
}
|
|
1105
|
-
current._errors.push(message);
|
|
1106
|
-
}
|
|
1107
|
-
function isCodec(schema) {
|
|
1108
|
-
return schema instanceof VldCodec;
|
|
1109
|
-
}
|
|
1110
|
-
function messageFromRefinementParam(param) {
|
|
1111
|
-
return param === undefined ? undefined : resolveErrorMessage(param, 'Refinement check failed');
|
|
1112
|
-
}
|
|
1113
|
-
function cloneSchema(schema) {
|
|
1114
|
-
return schema;
|
|
1115
|
-
}
|
|
1116
|
-
function createTransform(transformer) {
|
|
1117
|
-
return custom$1({
|
|
1118
|
-
parse: (value) => {
|
|
1119
|
-
const transformed = transformer(value, { addIssue: () => undefined, path: [] });
|
|
1120
|
-
if (transformed !== null && typeof transformed === 'object' && typeof transformed.then === 'function') {
|
|
1121
|
-
throw new Error('Use parseAsync for async transforms');
|
|
1122
|
-
}
|
|
1123
|
-
return transformed;
|
|
1124
|
-
},
|
|
1125
|
-
parseAsync: async (value) => {
|
|
1126
|
-
const transformed = await Promise.resolve(transformer(value, { addIssue: () => undefined, path: [] }));
|
|
1127
|
-
return transformed;
|
|
1128
|
-
}
|
|
1129
|
-
});
|
|
1130
|
-
}
|
|
1131
|
-
function createRefinement(predicate, message) {
|
|
1132
|
-
return custom$1({
|
|
1133
|
-
parse: (value) => {
|
|
1134
|
-
const passed = predicate(value);
|
|
1135
|
-
if (passed !== null && typeof passed === 'object' && typeof passed.then === 'function') {
|
|
1136
|
-
throw new Error('Use parseAsync for async refinements');
|
|
1137
|
-
}
|
|
1138
|
-
if (!passed) {
|
|
1139
|
-
throw new Error(messageFromRefinementParam(message) || 'Refinement check failed');
|
|
1140
|
-
}
|
|
1141
|
-
return value;
|
|
1142
|
-
},
|
|
1143
|
-
parseAsync: async (value) => {
|
|
1144
|
-
if (!await predicate(value)) {
|
|
1145
|
-
throw new Error(messageFromRefinementParam(message) || 'Refinement check failed');
|
|
1146
|
-
}
|
|
1147
|
-
return value;
|
|
1148
|
-
}
|
|
1149
|
-
});
|
|
1150
|
-
}
|
|
1151
|
-
function createSuperRefinement(refinement) {
|
|
1152
|
-
return VldUnknown.create().superRefine(refinement);
|
|
1153
|
-
}
|
|
1154
|
-
function propertyCheck(property, schema, message) {
|
|
1155
|
-
return custom$1({
|
|
1156
|
-
parse: (value) => {
|
|
1157
|
-
if (typeof value !== 'object' || value === null || !(property in value)) {
|
|
1158
|
-
throw new Error(messageFromRefinementParam(message) || `Expected object with property "${property}"`);
|
|
1159
|
-
}
|
|
1160
|
-
const result = schema.safeParse(value[property]);
|
|
1161
|
-
if (!result.success) {
|
|
1162
|
-
throw new Error(messageFromRefinementParam(message) || result.error.message);
|
|
1163
|
-
}
|
|
1164
|
-
return value;
|
|
1165
|
-
}
|
|
1166
|
-
});
|
|
1167
|
-
}
|
|
1168
|
-
function getParsedType(value) {
|
|
1169
|
-
if (value === null)
|
|
1170
|
-
return 'null';
|
|
1171
|
-
if (Array.isArray(value))
|
|
1172
|
-
return 'array';
|
|
1173
|
-
if (Number.isNaN(value))
|
|
1174
|
-
return 'nan';
|
|
1175
|
-
return typeof value;
|
|
1176
|
-
}
|
|
1177
|
-
const TimePrecision = {
|
|
1178
|
-
Any: null,
|
|
1179
|
-
Minute: -1,
|
|
1180
|
-
Second: 0,
|
|
1181
|
-
Millisecond: 3,
|
|
1182
|
-
Microsecond: 6
|
|
1183
|
-
};
|
|
1184
|
-
const ZodFirstPartyTypeKind = {};
|
|
1185
|
-
const $brand = Symbol.for('vld_brand');
|
|
1186
|
-
const $input = Symbol.for('VldInput');
|
|
1187
|
-
const $output = Symbol.for('VldOutput');
|
|
1188
|
-
const ZodIssueCode = {
|
|
1189
|
-
invalid_type: 'invalid_type',
|
|
1190
|
-
too_big: 'too_big',
|
|
1191
|
-
too_small: 'too_small',
|
|
1192
|
-
invalid_format: 'invalid_format',
|
|
1193
|
-
not_multiple_of: 'not_multiple_of',
|
|
1194
|
-
unrecognized_keys: 'unrecognized_keys',
|
|
1195
|
-
invalid_union: 'invalid_union',
|
|
1196
|
-
invalid_key: 'invalid_key',
|
|
1197
|
-
invalid_element: 'invalid_element',
|
|
1198
|
-
invalid_value: 'invalid_value',
|
|
1199
|
-
custom: 'custom'
|
|
1200
|
-
};
|
|
1201
|
-
const util = {
|
|
1202
|
-
getParsedType,
|
|
1203
|
-
propertyKeyTypes: new Set(['string', 'number', 'symbol']),
|
|
1204
|
-
primitiveTypes: new Set(['string', 'number', 'bigint', 'boolean', 'symbol', 'undefined', 'null']),
|
|
1205
|
-
assert: (condition, message = 'Assertion failed') => {
|
|
1206
|
-
if (!condition) {
|
|
1207
|
-
throw new Error(message);
|
|
1208
|
-
}
|
|
1209
|
-
},
|
|
1210
|
-
assertNever: (value) => {
|
|
1211
|
-
throw new Error(`Unexpected value: ${String(value)}`);
|
|
1212
|
-
},
|
|
1213
|
-
joinValues: (values, separator = ' | ') => values.map(value => JSON.stringify(value)).join(separator),
|
|
1214
|
-
jsonStringifyReplacer: (_key, value) => typeof value === 'bigint' ? value.toString() : value,
|
|
1215
|
-
nullish: (value) => value === null || value === undefined,
|
|
1216
|
-
cached: (getter) => {
|
|
1217
|
-
let initialized = false;
|
|
1218
|
-
let value;
|
|
1219
|
-
return () => {
|
|
1220
|
-
if (!initialized) {
|
|
1221
|
-
value = getter();
|
|
1222
|
-
initialized = true;
|
|
1223
|
-
}
|
|
1224
|
-
return value;
|
|
1225
|
-
};
|
|
1226
|
-
}
|
|
1227
|
-
};
|
|
1228
|
-
const core = {
|
|
1229
|
-
util,
|
|
1230
|
-
regexes: REGEXES,
|
|
1231
|
-
locales: localeNamespace,
|
|
1232
|
-
NEVER: VldNever.create(),
|
|
1233
|
-
TimePrecision,
|
|
1234
|
-
ZodIssueCode,
|
|
1235
|
-
globalRegistry,
|
|
1236
|
-
config: configure,
|
|
1237
|
-
getErrorMap: getGlobalErrorMap,
|
|
1238
|
-
setErrorMap: setGlobalErrorMap,
|
|
1239
|
-
parse: (schema, value) => schema.parse(value),
|
|
1240
|
-
safeParse: (schema, value) => schema.safeParse(value),
|
|
1241
|
-
parseAsync: (schema, value) => schema.parseAsync(value),
|
|
1242
|
-
safeParseAsync: (schema, value) => schema.safeParseAsync(value)
|
|
1243
|
-
};
|
|
1244
|
-
/**
|
|
1245
|
-
* Main API object with factory methods for all validators
|
|
1246
|
-
*/
|
|
1247
|
-
const v = {
|
|
1248
|
-
// Primitive validators
|
|
1249
|
-
string: () => VldString.create(),
|
|
1250
|
-
number: () => VldNumber.create(),
|
|
1251
|
-
int: () => VldNumber.create().int(),
|
|
1252
|
-
int32: () => VldNumber.create().int().min(-2147483648).max(2147483647),
|
|
1253
|
-
uint32: () => VldNumber.create().uint32(),
|
|
1254
|
-
uint64: () => VldNumber.create().uint64(),
|
|
1255
|
-
int64: () => VldNumber.create().int64(),
|
|
1256
|
-
float32: () => VldNumber.create().float32(),
|
|
1257
|
-
float64: () => VldNumber.create().float64(),
|
|
1258
|
-
boolean: () => VldBoolean.create(),
|
|
1259
|
-
date: () => VldDate.create(),
|
|
1260
|
-
bigint: () => VldBigInt.create(),
|
|
1261
|
-
symbol: () => VldSymbol.create(),
|
|
1262
|
-
stringbool: (options) => VldStringBool.create(options),
|
|
1263
|
-
// Complex validators
|
|
1264
|
-
array: (item) => VldArray.create(item),
|
|
1265
|
-
object: (shape) => VldObject.create(shape),
|
|
1266
|
-
strictObject: (shape) => VldObject.create(shape).strict(),
|
|
1267
|
-
looseObject: (shape) => VldObject.create(shape).passthrough(),
|
|
1268
|
-
tuple: (...items) => VldTuple.create(...items),
|
|
1269
|
-
record: (value) => VldRecord.create(value),
|
|
1270
|
-
partialRecord: (value) => VldRecord.create(value).partial(),
|
|
1271
|
-
looseRecord: (value) => VldRecord.create(value).loose(),
|
|
1272
|
-
set: (item) => VldSet.create(item),
|
|
1273
|
-
map: (key, value) => VldMap.create(key, value),
|
|
1274
|
-
// Union and intersection
|
|
1275
|
-
union: (...validators) => VldUnion.create(...validators),
|
|
1276
|
-
intersection: (first, second) => VldIntersection.create(first, second),
|
|
1277
|
-
discriminatedUnion: (discriminator, ...options) => VldDiscriminatedUnion.create(discriminator, [...options]),
|
|
1278
|
-
xor: (...options) => VldXor.create([...options]),
|
|
1279
|
-
keyof: (schema) => schema.keyof(),
|
|
1280
|
-
// Literal and enum
|
|
1281
|
-
literal: (value) => VldLiteral.create(value),
|
|
1282
|
-
enum: (...values) => VldEnum.create(values),
|
|
1283
|
-
nativeEnum: (enumObject) => VldEnum.create(enumValuesFromNativeEnum(enumObject)),
|
|
1284
|
-
// Special validators
|
|
1285
|
-
any: () => VldAny.create(),
|
|
1286
|
-
unknown: () => VldUnknown.create(),
|
|
1287
|
-
void: () => VldVoid.create(),
|
|
1288
|
-
never: () => VldNever.create(),
|
|
1289
|
-
null: () => VldNull.create(),
|
|
1290
|
-
undefined: () => VldUndefined.create(),
|
|
1291
|
-
nan: () => VldNan.create(),
|
|
1292
|
-
// NEVER constant - Zod 4 API parity for use in transforms
|
|
1293
|
-
NEVER: VldNever.create(),
|
|
1294
|
-
TimePrecision,
|
|
1295
|
-
ZodIssueCode,
|
|
1296
|
-
ZodFirstPartyTypeKind,
|
|
1297
|
-
// Utility validators
|
|
1298
|
-
optional: (validator) => VldOptional.create(validator),
|
|
1299
|
-
nullable: (validator) => VldNullable.create(validator),
|
|
1300
|
-
nullish: (validator) => VldNullish.create(validator),
|
|
1301
|
-
exactOptional: (validator) => VldExactOptional.create(validator),
|
|
1302
|
-
nonoptional: (validator, message) => validator.refine((value) => value !== undefined, messageFromRefinementParam(message)),
|
|
1303
|
-
catch: (validator, fallbackValue) => validator.catch(fallbackValue),
|
|
1304
|
-
prefault: (validator, defaultValue) => validator.default(typeof defaultValue === 'function' ? defaultValue() : defaultValue).prefault(),
|
|
1305
|
-
readonly: (validator) => validator.readonly(),
|
|
1306
|
-
pipe: (first, second) => first.pipe(second),
|
|
1307
|
-
clone: (schema) => cloneSchema(schema),
|
|
1308
|
-
describe: (schemaOrDescription, description) => schemaOrDescription instanceof VldBase
|
|
1309
|
-
? schemaOrDescription.describe(description || '')
|
|
1310
|
-
: VldUnknown.create().describe(schemaOrDescription),
|
|
1311
|
-
meta: (schemaOrMetadata, metadata) => schemaOrMetadata instanceof VldBase
|
|
1312
|
-
? schemaOrMetadata.meta(metadata || {})
|
|
1313
|
-
: VldUnknown.create().meta(schemaOrMetadata),
|
|
1314
|
-
transform: (schemaOrTransformer, transformer) => schemaOrTransformer instanceof VldBase
|
|
1315
|
-
? schemaOrTransformer.transform(transformer || ((value) => value))
|
|
1316
|
-
: createTransform(schemaOrTransformer),
|
|
1317
|
-
overwrite: (transformer) => createTransform(transformer),
|
|
1318
|
-
refine: (schemaOrPredicate, predicateOrMessage, message) => schemaOrPredicate instanceof VldBase
|
|
1319
|
-
? schemaOrPredicate.refine(predicateOrMessage, messageFromRefinementParam(message))
|
|
1320
|
-
: createRefinement(schemaOrPredicate, predicateOrMessage),
|
|
1321
|
-
check: (schemaOrPredicate, predicateOrMessage, message) => schemaOrPredicate instanceof VldBase
|
|
1322
|
-
? schemaOrPredicate.check(predicateOrMessage, messageFromRefinementParam(message))
|
|
1323
|
-
: createRefinement(schemaOrPredicate, predicateOrMessage),
|
|
1324
|
-
superRefine: (schemaOrRefinement, refinement) => schemaOrRefinement instanceof VldBase
|
|
1325
|
-
? schemaOrRefinement.superRefine(refinement || (() => undefined))
|
|
1326
|
-
: createSuperRefinement(schemaOrRefinement),
|
|
1327
|
-
property: propertyCheck,
|
|
1328
|
-
instanceof: (constructor, message) => custom$1({
|
|
1329
|
-
parse: (value) => {
|
|
1330
|
-
if (!(value instanceof constructor)) {
|
|
1331
|
-
throw new Error(messageFromRefinementParam(message) || `Expected instance of ${constructor.name || 'provided constructor'}`);
|
|
1332
|
-
}
|
|
1333
|
-
return value;
|
|
1334
|
-
}
|
|
1335
|
-
}),
|
|
1336
|
-
config: configure,
|
|
1337
|
-
setErrorMap: setGlobalErrorMap,
|
|
1338
|
-
getErrorMap: getGlobalErrorMap,
|
|
1339
|
-
core,
|
|
1340
|
-
util,
|
|
1341
|
-
locales: localeNamespace,
|
|
1342
|
-
// Recursive schemas
|
|
1343
|
-
lazy: (schemaGetter) => VldLazy.create(schemaGetter),
|
|
1344
|
-
// JSON validator
|
|
1345
|
-
json: (schema) => VldJson.create(schema),
|
|
1346
|
-
// Custom validator for type-safe user-defined schemas
|
|
1347
|
-
custom: (options) => custom$1(options),
|
|
1348
|
-
// File validator for file uploads
|
|
1349
|
-
file: () => file$1(),
|
|
1350
|
-
// Function validator for function validation
|
|
1351
|
-
function: () => functionValidator(),
|
|
1352
|
-
// Preprocessing
|
|
1353
|
-
preprocess: (preprocessor, schema) => VldPreprocess.create(preprocessor, schema),
|
|
1354
|
-
// Coercion API
|
|
1355
|
-
coerce: {
|
|
1356
|
-
string: () => VldCoerceString.create(),
|
|
1357
|
-
number: () => VldCoerceNumber.create(),
|
|
1358
|
-
boolean: () => VldCoerceBoolean.create(),
|
|
1359
|
-
date: () => VldCoerceDate.create(),
|
|
1360
|
-
bigint: () => VldCoerceBigInt.create(),
|
|
1361
|
-
},
|
|
1362
|
-
// String format validators (Zod 4 parity)
|
|
1363
|
-
email: (options) => email$1(options),
|
|
1364
|
-
url: () => VldString.create().url(),
|
|
1365
|
-
uuid: (options) => uuid$1(options),
|
|
1366
|
-
uuidv4: () => uuidv4$1(),
|
|
1367
|
-
uuidv6: () => uuidv6$1(),
|
|
1368
|
-
uuidv7: () => uuidv7$1(),
|
|
1369
|
-
hostname: () => hostname$1(),
|
|
1370
|
-
emoji: () => emoji$1(),
|
|
1371
|
-
base64: () => base64$1(),
|
|
1372
|
-
base64url: () => base64url$1(),
|
|
1373
|
-
hex: () => hex$1(),
|
|
1374
|
-
jwt: () => jwt$1(),
|
|
1375
|
-
nanoid: () => nanoid$1(),
|
|
1376
|
-
cuid: () => cuid$1(),
|
|
1377
|
-
cuid2: () => cuid2$1(),
|
|
1378
|
-
ulid: () => ulid$1(),
|
|
1379
|
-
ipv4: () => ipv4$1(),
|
|
1380
|
-
ipv6: () => ipv6$1(),
|
|
1381
|
-
mac: () => mac$1(),
|
|
1382
|
-
cidrv4: () => cidrv4$1(),
|
|
1383
|
-
cidrv6: () => cidrv6$1(),
|
|
1384
|
-
e164: () => e164$1(),
|
|
1385
|
-
hash: (algorithm) => hash$1(algorithm),
|
|
1386
|
-
iso: {
|
|
1387
|
-
date: () => iso$1.date(),
|
|
1388
|
-
time: () => iso$1.time(),
|
|
1389
|
-
dateTime: () => iso$1.dateTime(),
|
|
1390
|
-
duration: () => iso$1.duration(),
|
|
1391
|
-
},
|
|
1392
|
-
stringFormat: (name, validator) => stringFormat$1(name, validator),
|
|
1393
|
-
minLength: (value, message) => VldString.create().min(value, message),
|
|
1394
|
-
maxLength: (value, message) => VldString.create().max(value, message),
|
|
1395
|
-
length: (value, message) => VldString.create().length(value, message),
|
|
1396
|
-
regex: (pattern, message) => VldString.create().regex(pattern, message),
|
|
1397
|
-
startsWith: (value, message) => VldString.create().startsWith(value, message),
|
|
1398
|
-
endsWith: (value, message) => VldString.create().endsWith(value, message),
|
|
1399
|
-
includes: (value, message) => VldString.create().includes(value, message),
|
|
1400
|
-
trim: () => VldString.create().trim(),
|
|
1401
|
-
toLowerCase: () => VldString.create().toLowerCase(),
|
|
1402
|
-
lowercase: () => VldString.create().toLowerCase(),
|
|
1403
|
-
toUpperCase: () => VldString.create().toUpperCase(),
|
|
1404
|
-
uppercase: () => VldString.create().toUpperCase(),
|
|
1405
|
-
gt: (value, message) => VldNumber.create().gt(value, message),
|
|
1406
|
-
gte: (value, message) => VldNumber.create().gte(value, message),
|
|
1407
|
-
lt: (value, message) => VldNumber.create().lt(value, message),
|
|
1408
|
-
lte: (value, message) => VldNumber.create().lte(value, message),
|
|
1409
|
-
positive: (message) => VldNumber.create().positive(message),
|
|
1410
|
-
negative: (message) => VldNumber.create().negative(message),
|
|
1411
|
-
nonnegative: (message) => VldNumber.create().nonnegative(message),
|
|
1412
|
-
nonpositive: (message) => VldNumber.create().nonpositive(message),
|
|
1413
|
-
multipleOf: (value, message) => VldNumber.create().multipleOf(value, message),
|
|
1414
|
-
minSize: (value, message) => VldString.create().min(value, message),
|
|
1415
|
-
maxSize: (value, message) => VldString.create().max(value, message),
|
|
1416
|
-
size: (value, message) => VldString.create().length(value, message),
|
|
1417
|
-
normalize: (form) => VldString.create().transform(value => value.normalize(form)),
|
|
1418
|
-
slugify: () => VldString.create().transform(value => value
|
|
1419
|
-
.normalize('NFKD')
|
|
1420
|
-
.replace(/[\u0300-\u036f]/g, '')
|
|
1421
|
-
.toLowerCase()
|
|
1422
|
-
.trim()
|
|
1423
|
-
.replace(/[^a-z0-9]+/g, '-')
|
|
1424
|
-
.replace(/^-+|-+$/g, '')),
|
|
1425
|
-
mime: (types, message) => VldFile.create().mime(types, message),
|
|
1426
|
-
// Zod v4 parity string formats
|
|
1427
|
-
xid: () => xid$1(),
|
|
1428
|
-
guid: () => guid$1(),
|
|
1429
|
-
httpUrl: () => httpUrl$1(),
|
|
1430
|
-
ksuid: () => ksuid$1(),
|
|
1431
|
-
regexes: REGEXES,
|
|
1432
|
-
// Template literal validator
|
|
1433
|
-
templateLiteral: (...components) => templateLiteral$1(...components),
|
|
1434
|
-
// Codec validators (binary data validators)
|
|
1435
|
-
base64Bytes: () => VldBase64.create(),
|
|
1436
|
-
hexBytes: () => VldHex.create(),
|
|
1437
|
-
uint8Array: () => VldUint8Array.create(),
|
|
1438
|
-
// Codec factory
|
|
1439
|
-
codec: (inputValidator, outputValidator, transform) => VldCodec.create(inputValidator, outputValidator, transform),
|
|
1440
|
-
invertCodec: (codec) => codec.invert(),
|
|
1441
|
-
// Promise validator (Zod v4 parity)
|
|
1442
|
-
promise: (inner) => promise$1(inner),
|
|
1443
|
-
// Root parse helpers (Zod v4 parity)
|
|
1444
|
-
parse: (schema, value) => schema.parse(value),
|
|
1445
|
-
safeParse: (schema, value) => schema.safeParse(value),
|
|
1446
|
-
parseAsync: (schema, value) => schema.parseAsync(value),
|
|
1447
|
-
safeParseAsync: (schema, value) => schema.safeParseAsync(value),
|
|
1448
|
-
decode: (schema, value) => schema.parse(value),
|
|
1449
|
-
safeDecode: (schema, value) => schema.safeParse(value),
|
|
1450
|
-
decodeAsync: (schema, value) => schema.parseAsync(value),
|
|
1451
|
-
safeDecodeAsync: (schema, value) => schema.safeParseAsync(value),
|
|
1452
|
-
encode: (schema, value) => isCodec(schema)
|
|
1453
|
-
? schema.encode(value)
|
|
1454
|
-
: schema.parse(value),
|
|
1455
|
-
safeEncode: (schema, value) => isCodec(schema)
|
|
1456
|
-
? schema.safeEncode(value)
|
|
1457
|
-
: schema.safeParse(value),
|
|
1458
|
-
encodeAsync: async (schema, value) => isCodec(schema)
|
|
1459
|
-
? schema.encodeAsync(value)
|
|
1460
|
-
: schema.parseAsync(value),
|
|
1461
|
-
safeEncodeAsync: async (schema, value) => isCodec(schema)
|
|
1462
|
-
? schema.safeEncodeAsync(value)
|
|
1463
|
-
: schema.safeParseAsync(value),
|
|
1464
|
-
formatError: (error) => {
|
|
1465
|
-
const formatted = { _errors: [] };
|
|
1466
|
-
if (error instanceof VldError) {
|
|
1467
|
-
for (const issue of error.issues) {
|
|
1468
|
-
addFormattedIssue(formatted, issue.path, issue.message);
|
|
1469
|
-
}
|
|
1470
|
-
return formatted;
|
|
1471
|
-
}
|
|
1472
|
-
formatted._errors.push(toErrorMessage(error));
|
|
1473
|
-
return formatted;
|
|
1474
|
-
},
|
|
1475
|
-
treeifyError: treeifyError,
|
|
1476
|
-
prettifyError: prettifyError,
|
|
1477
|
-
flattenError: flattenError,
|
|
1478
|
-
toJSONSchema: toJSONSchema
|
|
1479
|
-
};
|
|
1480
|
-
/**
|
|
1481
|
-
* Zod-compatible namespace alias.
|
|
1482
|
-
*/
|
|
1483
|
-
const z = v;
|
|
1484
|
-
/**
|
|
1485
|
-
* Zod-compatible root-level factory aliases.
|
|
1486
|
-
*
|
|
1487
|
-
* VLD's primary API remains `v.*`, but Zod exposes most factories directly
|
|
1488
|
-
* from the package root. Re-exporting these aliases makes migration less
|
|
1489
|
-
* intrusive without changing existing behavior.
|
|
1490
|
-
*/
|
|
1491
|
-
const { string, number, int, int32, uint32, uint64, int64, float32, float64, boolean, date, bigint, symbol, stringbool, array, object, strictObject, looseObject, tuple, record, partialRecord, looseRecord, set, union, intersection, discriminatedUnion, xor, keyof, literal, nativeEnum, any, unknown, nan, optional, nullable, nullish, exactOptional, nonoptional, readonly, pipe, clone, describe, meta, transform, overwrite, refine, check, superRefine, property, config, setErrorMap, getErrorMap, locales, lazy, json, custom, file, preprocess, coerce, email, url, uuid, uuidv4, uuidv6, uuidv7, hostname, emoji, base64, base64url, hex, jwt, nanoid, cuid, cuid2, ulid, ipv4, ipv6, mac, cidrv4, cidrv6, e164, hash, iso, stringFormat, normalize, slugify, mime, xid, guid, httpUrl, ksuid, regexes, templateLiteral, base64Bytes, hexBytes, uint8Array, codec, promise, prefault, parse, safeParse, parseAsync, safeParseAsync, decode, safeDecode, decodeAsync, safeDecodeAsync, encode, safeEncode, encodeAsync, safeEncodeAsync, formatError, NEVER } = v;
|
|
1492
|
-
const catchFactory = v.catch;
|
|
1493
|
-
const enumFactory = v.enum;
|
|
1494
|
-
const functionFactory = v.function;
|
|
1495
|
-
const instanceOfFactory = v.instanceof;
|
|
1496
|
-
const mapFactory = v.map;
|
|
1497
|
-
const neverFactory = v.never;
|
|
1498
|
-
const nullFactory = v.null;
|
|
1499
|
-
const undefinedFactory = v.undefined;
|
|
1500
|
-
const voidFactory = v.void;
|
|
1501
|
-
const defaultFactory = v;
|
|
1502
|
-
const zodStringFactory = VldString;
|
|
1503
|
-
function map(first, second) {
|
|
1504
|
-
if (first instanceof VldBase && second instanceof VldBase) {
|
|
1505
|
-
return v.map(first, second);
|
|
1506
|
-
}
|
|
1507
|
-
return map$1(first, second);
|
|
1508
|
-
}
|
|
1509
|
-
const minLength = (value, message) => v.string().min(value, message);
|
|
1510
|
-
const maxLength = (value, message) => v.string().max(value, message);
|
|
1511
|
-
const length = (value, message) => v.string().length(value, message);
|
|
1512
|
-
const regex = (pattern, message) => v.string().regex(pattern, message);
|
|
1513
|
-
const startsWith = (value, message) => v.string().startsWith(value, message);
|
|
1514
|
-
const endsWith = (value, message) => v.string().endsWith(value, message);
|
|
1515
|
-
const includes = (value, message) => v.string().includes(value, message);
|
|
1516
|
-
const trim = () => v.string().trim();
|
|
1517
|
-
const toLowerCase = () => v.string().toLowerCase();
|
|
1518
|
-
const lowercase = toLowerCase;
|
|
1519
|
-
const toUpperCase = () => v.string().toUpperCase();
|
|
1520
|
-
const uppercase = toUpperCase;
|
|
1521
|
-
const gt = (value, message) => v.number().gt(value, message);
|
|
1522
|
-
const gte = (value, message) => v.number().gte(value, message);
|
|
1523
|
-
const lt = (value, message) => v.number().lt(value, message);
|
|
1524
|
-
const lte = (value, message) => v.number().lte(value, message);
|
|
1525
|
-
const positive = (message) => v.number().positive(message);
|
|
1526
|
-
const negative = (message) => v.number().negative(message);
|
|
1527
|
-
const nonnegative = (message) => v.number().nonnegative(message);
|
|
1528
|
-
const nonpositive = (message) => v.number().nonpositive(message);
|
|
1529
|
-
const multipleOf = (value, message) => v.number().multipleOf(value, message);
|
|
1530
|
-
const minSize = minLength;
|
|
1531
|
-
const maxSize = maxLength;
|
|
1532
|
-
const size = length;
|
|
1533
|
-
|
|
1534
|
-
export { $brand, $input, $output, NEVER, TimePrecision, VldBase, VldError, VldIntersection, VldAny as ZodAny, VldArray as ZodArray, VldBigInt as ZodBigInt, VldBigInt as ZodBigIntFormat, VldBoolean as ZodBoolean, VldCodec as ZodCodec, VldDate as ZodDate, VldDiscriminatedUnion as ZodDiscriminatedUnion, VldEnum as ZodEnum, VldError as ZodError, VldExactOptional as ZodExactOptional, VldFile as ZodFile, ZodFirstPartyTypeKind, VldIntersection as ZodIntersection, ZodIssueCode, VldJson as ZodJSON, VldLazy as ZodLazy, VldLiteral as ZodLiteral, VldMap as ZodMap, VldNan as ZodNaN, VldNever as ZodNever, VldNull as ZodNull, VldNullable as ZodNullable, VldNumber as ZodNumber, VldNumber as ZodNumberFormat, VldObject as ZodObject, VldOptional as ZodOptional, VldPreprocess as ZodPreprocess, VldError as ZodRealError, VldRecord as ZodRecord, VldSet as ZodSet, VldString as ZodString, VldSymbol as ZodSymbol, VldTuple as ZodTuple, VldBase as ZodType, VldUndefined as ZodUndefined, VldUnion as ZodUnion, VldUnknown as ZodUnknown, VldVoid as ZodVoid, VldXor as ZodXor, zodStringFactory as _ZodString, defaultFactory as _default, functionFactory as _function, any, array, base64, base64Bytes, base64url, bigint, boolean, catchFactory as catch, check, cidrv4, cidrv6, clone, codec, coerce, config, core, createLogger, createNoOpLogger, cuid, cuid2, custom, date, decode, decodeAsync, v as default, describe, disableLogging, discriminatedUnion, e164, email, emoji, enableDebug, encode, encodeAsync, endsWith, enumFactory as enum, exactOptional, file, flattenError, float32, float64, formatError, fromJSONSchema, functionFactory as function, getErrorMap, getLogger, globalRegistry, gt, gte, guid, hash, hex, hexBytes, hostname, httpUrl, includes, initLogger, instanceOfFactory as instanceof, int, int32, int64, intersection, ipv4, ipv6, iso, json, jwt, keyof, ksuid, lazy, length, literal, locales, looseObject, looseRecord, lowercase, lt, lte, mac, map, mapFactory as mapSchema, maxLength, maxSize, meta, mime, minLength, minSize, multipleOf, nan, nanoid, nativeEnum, negative, neverFactory as never, nonnegative, nonoptional, nonpositive, normalize, nullFactory as null, nullable, nullish, number, object, optional, overwrite, parse, parseAsync, partialRecord, pipe, positive, prefault, preprocess, prettifyError, promise, property, readonly, record, refine, regex, regexes, safeDecode, safeDecodeAsync, safeEncode, safeEncodeAsync, safeParse, safeParseAsync, set, setErrorMap, setLogLevel, size, slugify, startsWith, strictObject, string, stringFormat, stringbool, superRefine, symbol, templateLiteral, toJSONSchema, toLowerCase, toUpperCase, transform, treeifyError, trim, tuple, uint32, uint64, uint8Array, ulid, undefinedFactory as undefined, union, unknown, uppercase, url, util, uuid, uuidv4, uuidv6, uuidv7, v, voidFactory as void, xid, xor, z };
|
|
1
|
+
import{VLD_VALIDATOR_TYPES as Z,configureSchemaCompositionFactories as S,VldBase as V,VldDefault as O,VldPreprocess as E,VldExactOptional as I,VldNullish as M,VldNullable as L,VldOptional as T,resolveErrorMessage as _,VldPipe as N,VldPrefault as U,VldCatch as P,VldReadonly as D,VldMeta as R,VldRefine as $,VldTransform as F}from"./validators/base.js";export{VldBrand as ZodBranded}from"./validators/base.js";import{globalRegistry as J,registry as W}from"./registry.js";import{VldString as K}from"./validators/string.js";import{VldNumber as G}from"./validators/number.js";import{VldBoolean as X}from"./validators/boolean.js";import{VldDate as H}from"./validators/date.js";import{VldStringBool as Y}from"./validators/string-bool.js";import{VldArray as Q}from"./validators/array.js";import{VldObject as ee}from"./validators/object.js";import{VldUnion as te}from"./validators/union.js";import{VldLiteral as re}from"./validators/literal.js";import{VldBigInt as ne}from"./validators/bigint.js";import{VldSymbol as oe}from"./validators/symbol.js";import{VldTuple as ae}from"./validators/tuple.js";import{VldRecord as ie}from"./validators/record.js";import{VldSet as se}from"./validators/set.js";import{VldMap as ce}from"./validators/map.js";import{VldEnum as ue}from"./validators/enum.js";import{VldIntersection as le}from"./validators/intersection.js";import{VldAny as me}from"./validators/any.js";import{VldUnknown as de}from"./validators/unknown.js";import{VldVoid as fe}from"./validators/void.js";import{VldNever as pe}from"./validators/never.js";import{VldNull as ye}from"./validators/null.js";import{VldUndefined as ge}from"./validators/undefined.js";import{VldNan as ve}from"./validators/nan.js";import{VldLazy as he}from"./validators/lazy.js";import{VldDiscriminatedUnion as be}from"./validators/discriminated-union.js";import{VldXor as Ze}from"./validators/xor.js";import{VldJson as xe}from"./validators/json.js";import{VldTemplateLiteral as je,templateLiteral as Se}from"./validators/template-literal.js";import{custom as Ve,VldCustom as Oe}from"./validators/custom.js";import{VldFile as Ae,file as we}from"./validators/file.js";import{VldFunction as Ee,functionValidator as Ie}from"./validators/function.js";import{VldCodec as Me}from"./validators/codec.js";import{VldBase64 as Le}from"./validators/base64.js";import{VldHex as Te}from"./validators/hex.js";import{VldUint8Array as _e}from"./validators/uint8array.js";import{VldPromise as Ne,promise as Ue}from"./validators/promise.js";import{map as Pe}from"./compat/result.js";export{Err,Ok,ResultUtils,all,failure,flatMap,fromNullable,isErr,isOk,isResult,mapErr,match,success,tryCatch,tryCatchAsync,unwrap,unwrapOr}from"./compat/result.js";import{l as De}from"./chunks/index-yjpbvFgw.js";export{s as setLocaleAsync}from"./chunks/index-yjpbvFgw.js";import{VldCoerceBigInt as Ce,VldCoerceDate as Re,VldCoerceBoolean as ke,VldCoerceNumber as Be,VldCoerceString as $e}from"./coercion/index.js";import{flattenError as ze,prettifyError as Fe,treeifyError as Je}from"./errors.js";export{prettifyErrorColored,prettifyErrorPlain}from"./errors.js";import{uuid as We,httpUrl as Ke,email as qe,regexes as Ge,VldStringFormat as Xe,ksuid as He,guid as Ye,xid as Qe,stringFormat as et,iso as tt,hash as rt,e164 as nt,creditCard as ot,cidrv6 as at,cidrv4 as it,mac as st,ipv6 as ct,ipv4 as ut,ulid as lt,cuid2 as mt,cuid as dt,nanoid as ft,jwt as pt,hex as yt,base64url as gt,base64 as vt,emoji as ht,hostname as bt,uuidv7 as Zt,uuidv6 as xt,uuidv4 as jt,url as St}from"./validators/string-formats.js";export{b as base64Json,a as base64ToBytes,c as base64ToUint8Array,d as base64UrlToBytes,e as base64urlToBytes,f as bytesToUtf8,g as epochMillisToDate,h as epochSecondsToDate,i as hexLowerToBytes,j as hexToBytes,k as hexToUint8Array,l as invertCodec,m as isoDatetimeToDate,n as jsonCodec,o as jwtPayload,p as numberToBigInt,s as stringToBigInt,q as stringToBoolean,r as stringToHttpURL,t as stringToInt,u as stringToNumber,v as stringToURL,w as stringToUint8Array,x as uint8ArrayToBase64,y as uint8ArrayToBase64Url,z as uint8ArrayToHex,A as uint8ArrayToString,B as uriComponent,C as utf8ToBytes}from"./chunks/index-CkbfQQ4n.js";export{createEmitter,createEventBus,withEmitter}from"./compat/emitter.js";export{createVldKernel,definePlugin,getVldKernel,resetVldKernel,usePlugin}from"./kernel.js";export{blue,bold,createTheme,cyan,dim,gray,green,grey,italic,magenta,default as pigment,red,strip,supportsColor,underline,vldTheme,white,yellow}from"./pigment.js";import{V as Vt}from"./chunks/errors-core-CerMg2rq.js";export{getLocale,getMessages,getSupportedLocales,isLocaleLoaded,isLocaleSupported,registerLocale,setLocale}from"./locales/runtime.js";function Ot(e,t={}){const r=function(e){const t=e.target;if("draft-4"===t)return{...e,target:"draft-04"};if("draft-7"===t)return{...e,target:"draft-07"};return e}(t),n=wt(Et(e,r),r),o=r.target||"draft-2020-12";return"draft-04"===o?n.$schema??(n.$schema="http://json-schema.org/draft-04/schema#"):"draft-07"===o?n.$schema??(n.$schema="http://json-schema.org/draft-07/schema#"):"draft-2019-09"===o?n.$schema??(n.$schema="https://json-schema.org/draft/2019-09/schema"):"draft-2020-12"===o&&(n.$schema??(n.$schema="https://json-schema.org/draft/2020-12/schema")),n}function At(e,t={}){if("boolean"==typeof e)return e?me.create():pe.create();let r;try{r=JSON.parse(JSON.stringify(e))}catch{throw new Error("fromJSONSchema input is not valid JSON (possibly cyclic); use $defs/$ref for recursive schemas")}const n=Nt(r),o=n.meta();return t.registry&&o&&t.registry.add(n,o),n}function wt(e,t){const r=t.target||"draft-2020-12",n={...e};if(Array.isArray(n.items)){const e=n.items.map(e=>wt(e,t));"draft-2020-12"===r||"draft-2019-09"===r?(n.prefixItems=e,n.items=!1):n.items=e}else n.items&&"object"==typeof n.items&&(n.items=wt(n.items,t));n.prefixItems&&(n.prefixItems=n.prefixItems.map(e=>wt(e,t))),n.properties&&(n.properties=Object.fromEntries(Object.entries(n.properties).map(([e,r])=>[e,wt(r,t)]))),n.additionalProperties&&"object"==typeof n.additionalProperties&&(n.additionalProperties=wt(n.additionalProperties,t));for(const e of["anyOf","allOf","oneOf"])n[e]&&(n[e]=n[e].map(e=>wt(e,t)));return n.not&&"object"==typeof n.not&&(n.not=wt(n.not,t)),"openapi-3.0"===r&&function(e){if(Array.isArray(e.type)&&e.type.includes("null")){const t=e.type.filter(e=>"null"!==e);if(e.nullable=!0,1===t.length){const r=t[0];void 0!==r?e.type=r:delete e.type}else t.length>1?e.type=t:delete e.type}"number"==typeof e.exclusiveMinimum&&(e.minimum??(e.minimum=e.exclusiveMinimum),e.exclusiveMinimum=!0);"number"==typeof e.exclusiveMaximum&&(e.maximum??(e.maximum=e.exclusiveMaximum),e.exclusiveMaximum=!0)}(n),n}function Et(e,t){t.target;const r=e,n=e.validatorType;if("VldString"===e.constructor.name||n===Z.STRING)return Lt(e,function(e,t){const r=t?.config?.jsonSchema||{},n={type:"string"};void 0!==r.exactLength?(n.minLength=r.exactLength,n.maxLength=r.exactLength):(void 0!==r.minLength&&(n.minLength=r.minLength),void 0!==r.maxLength&&(n.maxLength=r.maxLength));r.format&&(n.format=r.format);r.pattern&&(n.pattern=r.pattern);return n}(0,e),t);if("VldNumber"===e.constructor.name||n===Z.NUMBER)return Lt(e,function(e){const t=e.config||{},r=t.jsonSchema||{},n=t.checks||[],o={type:r.type||"number"};void 0!==r.minimum&&(o.minimum=r.minimum);void 0!==r.maximum&&(o.maximum=r.maximum);void 0!==r.exclusiveMinimum&&(o.exclusiveMinimum=r.exclusiveMinimum);void 0!==r.exclusiveMaximum&&(o.exclusiveMaximum=r.exclusiveMaximum);void 0!==r.multipleOf&&(o.multipleOf=r.multipleOf);if(Object.keys(r).length>0)return o;for(const e of n){const t=e.toString();(t.includes(">=")||t.includes("min"))&&(o.minimum=0),(t.includes("<=")||t.includes("max"))&&(o.maximum=0),(t.includes("isInteger")||t.includes("int"))&&(o.type="integer"),t.includes("isSafeInteger")&&(o.type="integer"),t.includes("Number.isFinite")}return o}(e),t);if("VldBoolean"===e.constructor.name||n===Z.BOOLEAN)return Lt(e,{type:"boolean"},t);if("VldBigInt"===e.constructor.name||n===Z.BIGINT)return It(e,t,"BigInt",()=>function(e){const t=e.jsonSchema||e.config?.jsonSchema||{},r={type:"integer"};return Tt(r,"minimum","x-vld-minimum",t.minimum),Tt(r,"maximum","x-vld-maximum",t.maximum),Tt(r,"exclusiveMinimum","x-vld-exclusiveMinimum",t.exclusiveMinimum),Tt(r,"exclusiveMaximum","x-vld-exclusiveMaximum",t.exclusiveMaximum),r}(e));if("VldDate"===e.constructor.name||n===Z.DATE)return It(e,t,"Date",()=>function(e){const t=e.jsonSchema||e.config?.jsonSchema||{},r={type:"string",format:"date-time"};t.formatMinimum&&(r.formatMinimum=t.formatMinimum);t.formatMaximum&&(r.formatMaximum=t.formatMaximum);t.formatExclusiveMinimum&&(r.formatExclusiveMinimum=t.formatExclusiveMinimum);t.formatExclusiveMaximum&&(r.formatExclusiveMaximum=t.formatExclusiveMaximum);return r}(e));if("VldArray"===e.constructor.name||n===Z.ARRAY)return Lt(e,function(e,t){const r=e._item||e._inner||e.config?.itemValidator,n={type:"array"};r&&(n.items=Et(r,t));void 0!==e.config?.exactLength?(n.minItems=e.config.exactLength,n.maxItems=e.config.exactLength):(void 0!==e.config?.minLength&&(n.minItems=e.config.minLength),void 0!==e.config?.maxLength&&(n.maxItems=e.config.maxLength));e.config?.unique&&(n.uniqueItems=!0);return n}(e,t),t);if("VldObject"===e.constructor.name||n===Z.OBJECT)return Lt(e,function(e,t){const r=e._shape||e.shape||e.config?.shape;if(!r)return{type:"object"};const n={},o=[];for(const[e,a]of Object.entries(r)){const r=a;n[e]=Et(r,t),_t(r)||o.push(e)}const a={type:"object",properties:n};o.length>0&&(a.required=o);e._passthrough||e._loose||e.config?.passthrough?a.additionalProperties=!0:e.config?.catchall?a.additionalProperties=Et(e.config.catchall,t):a.additionalProperties=!1;return a}(e,t),t);if("VldUnion"===e.constructor.name)return Lt(e,function(e,t){const r=e._validators||e._options||e.validators||[];return{anyOf:r.map(e=>Et(e,t))}}(e,t),t);if("VldLiteral"===e.constructor.name)return Lt(e,function(e){const t=e._literal??e.literal??e._value??e.value;return null===t?{type:"null"}:"string"==typeof t?{type:"string",const:t}:"number"==typeof t?{type:"number",const:t}:"boolean"==typeof t?{type:"boolean",const:t}:{const:t}}(e),t);if("VldEnum"===e.constructor.name)return Lt(e,function(e){const t=e._values||e.values;if(Array.isArray(t))return{enum:[...t]};return{}}(e),t);if("VldSet"===e.constructor.name||n===Z.SET)return It(e,t,"Set",()=>function(e,t){const r=e.itemSchema||e.itemValidator||e._item||e._inner,n={type:"array",uniqueItems:!0,"x-vld-type":"set"};r&&(n.items=Et(r,t));return n}(e,t));if("VldMap"===e.constructor.name||n===Z.MAP)return It(e,t,"Map",()=>function(e,t){const r=e.keySchema||e.keyValidator||e._key,n=e.valueSchema||e.valueValidator||e._value,o=r?Et(r,t):{},a=n?Et(n,t):{};return{type:"array","x-vld-type":"map",items:{type:"array",items:[o,a],minItems:2,maxItems:2}}}(e,t));if("VldRecord"===e.constructor.name||n===Z.RECORD)return Lt(e,function(e,t){const r=e.valueSchema||e._value||e._inner||e.valueValidator;if(r)return{type:"object",additionalProperties:Et(r,t)};return{type:"object"}}(e,t),t);if("VldTuple"===e.constructor.name||n===Z.TUPLE)return Lt(e,function(e,t){const r=e.items||e._items||e.validators;if(!r||!Array.isArray(r))return{type:"array"};return{type:"array",items:r.map(e=>Et(e,t)),minItems:r.length,maxItems:r.length}}(e,t),t);if("VldIntersection"===e.constructor.name)return Lt(e,function(e,t){const r=e._first||e.first,n=e._second||e.second,o=[];r&&o.push(Et(r,t));n&&o.push(Et(n,t));return 0===o.length?{}:1===o.length?o[0]??{}:{allOf:o}}(e,t),t);if("VldOptional"===e.constructor.name)return Lt(e,function(e,t){const r=Mt(e);if(!r)return{};const n=Et(r,t);return n}(e,t),t);if("VldNullable"===e.constructor.name)return Lt(e,function(e,t){const r=Mt(e);if(!r)return{type:"null"};const n=Et(r,t);if("string"==typeof n.type)return{type:[n.type,"null"]};if(Array.isArray(n.type))return n.type.push("null"),n;return{anyOf:[n,{type:"null"}]}}(e,t),t);if("VldNullish"===e.constructor.name)return Lt(e,function(e,t){const r=Mt(e);if(!r)return{};const n=Et(r,t);if("string"==typeof n.type)return{...n,type:[n.type,"null"]};return n}(e,t),t);if("VldExactOptional"===e.constructor.name)return Lt(e,function(e,t){const r=Mt(e);return r?Et(r,t):{}}(e,t),t);if("VldLazy"===e.constructor.name)return Lt(e,{type:"object"},t);if("VldJson"===e.constructor.name)return Lt(e,{},t);if("VldAny"===e.constructor.name)return Lt(e,{},t);if("VldUnknown"===e.constructor.name)return Lt(e,{},t);if("VldNever"===e.constructor.name)return Lt(e,{not:{}},t);if("VldNull"===e.constructor.name)return Lt(e,{type:"null"},t);if("VldUndefined"===e.constructor.name)return It(e,t,"Undefined",()=>({not:{}}));if("VldNan"===e.constructor.name)return It(e,t,"NaN",()=>({type:"number",not:{}}));if("VldVoid"===e.constructor.name)return It(e,t,"Void",()=>({not:{}}));if("VldSymbol"===e.constructor.name)return It(e,t,"Symbol",()=>({}));if("VldBrand"===e.constructor.name)return Lt(e,Et(r.baseValidator,t),t);if("VldReadonly"===e.constructor.name)return Lt(e,Et(r.baseValidator,t),t);if("VldTransform"===e.constructor.name)return It(e,t,"Transform",()=>Et(Mt(r),t));if("VldMeta"===e.constructor.name){const n=Et(r.baseValidator,t);return Lt(e,n,t)}if("VldRefine"===e.constructor.name||"VldSuperRefine"===e.constructor.name)return Lt(e,Et(Mt(r),t),t);if("VldPipe"===e.constructor.name){const n="input"===t.io?r.first:r._next||r.second;return Lt(e,Et(n,t),t)}if("VldDefault"===e.constructor.name||"VldCatch"===e.constructor.name)return Lt(e,Et(Mt(r),t),t);if("VldPreprocess"===e.constructor.name)return It(e,t,"Preprocess",()=>Et(r._schema,t));if("VldCodec"===e.constructor.name){const n="input"===t.io?r.inputValidator:r.outputValidator;return Lt(e,Et(n,t),t)}if("VldCustom"===e.constructor.name)return It(e,t,"Custom",()=>({}));if("VldStringFormat"===e.constructor.name){return Lt(e,{type:"string",format:e._format},t)}return Lt(e,{},t)}function It(e,t,r,n){if("any"===t.unrepresentable)return Lt(e,{},t);if("vld"===t.unrepresentable)return Lt(e,n(),t);throw new Error(`${r} cannot be represented in JSON Schema`)}function Mt(e){return"function"==typeof e.unwrap?e.unwrap():e._inner||e._baseValidator||e.baseValidator||e.valueValidator}function Lt(e,t,r){if(!1===r.includeMetadata)return t;const n=function(e){const t=J.get(e),r=e,n="function"==typeof r.getMeta?r.getMeta():void 0;return t||n?{...n||{},...t||{}}:void 0}(e);if(!n)return t;const o={...t};return n.id&&(o.$id=n.id),n.title&&(o.title=n.title),n.description&&(o.description=n.description),n.examples&&!1!==r.includeExamples&&(o.examples=n.examples),void 0!==n.default&&(o.default=n.default),n.deprecated&&(o.deprecated=!0),n.readOnly&&(o.readOnly=!0),n.writeOnly&&(o.writeOnly=!0),o}function Tt(e,t,r,n){if(void 0===n)return;e[r]=n.toString();const o=function(e){const t=Number(e);if(Number.isSafeInteger(t))return BigInt(t)===e?t:void 0}(n);void 0!==o&&(e[t]=o)}function _t(e){const t=e.constructor.name;return"VldOptional"===t||"VldNullish"===t||"VldExactOptional"===t||e.validatorType===Z.OPTIONAL||e.validatorType===Z.NULLISH||e.validatorType===Z.EXACT_OPTIONAL}function Nt(e){return function(e,t){const r={};t.$id&&(r.id=t.$id);t.title&&(r.title=t.title);t.description&&(r.description=t.description);t.examples&&(r.examples=t.examples);void 0!==t.default&&(r.default=t.default);t.deprecated&&(r.deprecated=!0);t.readOnly&&(r.readOnly=!0);t.writeOnly&&(r.writeOnly=!0);return Object.keys(r).length>0?e.meta(r):e}(function(e){if(e.$ref)return me.create();if(e.anyOf||e.oneOf){const t=(e.anyOf||e.oneOf).map(e=>Nt(e)).filter(Boolean);if(t.length>0)return te.create(...t)}if(e.allOf){const t=e.allOf[0];if(void 0===t)return me.create();const r=Nt(t);if(e.allOf.length>1){const t=Nt({allOf:e.allOf.slice(1)});return le.create(r,t)}return r}if(e.not)return me.create();if(void 0!==e.const)return re.create(e.const);if(e.enum)return ue.create(e.enum);const t=e.nullable&&"string"==typeof e.type?[e.type,"null"]:e.type;if("string"===t||void 0===t){let t=K.create();if(void 0!==e.minLength&&(t=t.min(e.minLength)),void 0!==e.maxLength&&(t=t.max(e.maxLength)),e.pattern&&(t=t.regex(new RegExp(e.pattern))),e.format)switch(e.format){case"date-time":case"date":case"time":break;case"email":return qe();case"uri":case"uri-reference":return Ke();case"uuid":return We()}return t}if("number"===t||"integer"===t){let r=G.create();return"integer"===t&&(r=r.int()),void 0!==e.minimum&&(r=r.min(e.minimum)),void 0!==e.maximum&&(r=r.max(e.maximum)),"number"==typeof e.exclusiveMinimum&&(r=r.gt(e.exclusiveMinimum)),"number"==typeof e.exclusiveMaximum&&(r=r.lt(e.exclusiveMaximum)),!0===e.exclusiveMinimum&&void 0!==e.minimum&&(r=r.gt(e.minimum)),!0===e.exclusiveMaximum&&void 0!==e.maximum&&(r=r.lt(e.maximum)),void 0!==e.multipleOf&&(r=r.multipleOf(e.multipleOf)),r}if("boolean"===t)return X.create();if("array"===t){if(e.prefixItems&&e.prefixItems.length>0){const t=e.prefixItems.map(e=>Nt(e));return ae.create(...t)}if(Array.isArray(e.items)){const t=e.items.map(e=>Nt(e));return ae.create(...t)}return e.items&&!Array.isArray(e.items)?Q.create(Nt(e.items)):Q.create(me.create())}if("object"===t){if(e.properties){const t={},r=new Set(e.required||[]);for(const[n,o]of Object.entries(e.properties)){const e=Nt(o);t[n]=r.has(n)?e:e.optional()}let n=ee.create(t);if(!1===e.additionalProperties)n=n.strict();else if(!0===e.additionalProperties)n=n.passthrough();else if(e.additionalProperties){const t=Nt(e.additionalProperties);return ie.create(t)}return n}return ee.create({})}if("null"===t)return ye.create();if(Array.isArray(t)){const r=t.map(t=>Nt({...e,type:t,nullable:!1}));if(r.length>0)return te.create(...r)}return me.create()}(e),e)}const Ut={debug:0,info:1,warn:2,error:3,silent:4},Pt="[0m",Dt="[2m",Ct="[36m",Rt={debug:"[90m",info:"[34m",warn:"[33m",error:"[31m"},kt={debug:"DEBUG",info:"INFO ",warn:"WARN ",error:"ERROR"};function Bt(e={}){const t=e.name??"vld";let r=e.level??"warn";const n=e.handler??function(e){const t=e.colored??!0,r=e.timestamps??!0;return e=>{const n=[];if(r){const r=e.timestamp.toISOString().slice(11,23);n.push(t?`${Dt}${r}${Pt}`:r)}const o=kt[e.level],a=Rt[e.level];n.push(t?`${a}${o}${Pt}`:o),n.push(t?`${Ct}[${e.name}]${Pt}`:`[${e.name}]`),n.push(e.message);const i=n.join(" ");switch(e.level){case"debug":console.debug(i,void 0!==e.data?e.data:"");break;case"info":console.info(i,void 0!==e.data?e.data:"");break;case"warn":console.warn(i,void 0!==e.data?e.data:"");break;case"error":console.error(i,void 0!==e.data?e.data:"")}}}(e),o=(e,o,a)=>{if(Ut[e]<Ut[r])return;const i={level:e,message:o,data:a,timestamp:new Date,name:t};n(i)};return{debug:(e,t)=>o("debug",e,t),info:(e,t)=>o("info",e,t),warn:(e,t)=>o("warn",e,t),error:(e,t)=>o("error",e,t),isLevelEnabled:e=>Ut[e]>=Ut[r],setLevel:e=>{r=e},getLevel:()=>r,child:r=>Bt({...e,name:`${t}:${r}`})}}let $t=null;function zt(e){return $t=Bt({name:"vld",...e}),$t}function Ft(){return $t}function Jt(e){$t&&$t.setLevel(e)}function Wt(){$t?$t.setLevel("debug"):zt({level:"debug"})}function Kt(){$t&&$t.setLevel("silent")}function qt(){return Bt({level:"silent"})}const Gt=Symbol.for("@oxog/vld/global-state"),Xt=globalThis,Ht=Xt[Gt]??(Xt[Gt]={config:{}});function Yt(e){return void 0===e||(Ht.config={...Ht.config,...e},"customError"in e?Ht.errorMap=e.customError:"errorMap"in e&&(Ht.errorMap=e.errorMap)),{...Ht.config}}function Qt(e){Ht.errorMap=e,Ht.config={...Ht.config,errorMap:e}}function er(){return Ht.errorMap}function tr(e){const t=Object.keys(e).filter(e=>!/^\d+$/.test(e)).map(t=>e[t]).filter(e=>"string"==typeof e||"number"==typeof e),r=Array.from(new Set(t));if(0===r.length)throw new Error("nativeEnum requires at least one string or number value");return r}function rr(e,t,r){let n=e;for(const e of t){const t=String(e),r=n[t];r&&!Array.isArray(r)||(n[t]={_errors:[]}),n=n[t]}n._errors.push(r)}function nr(e){return void 0===e?void 0:_(e,"Refinement check failed")}function or(e){return Ve({parse:t=>{const r=e(t,{addIssue:()=>{},path:[]});if(null!==r&&"object"==typeof r&&"function"==typeof r.then)throw new Error("Use parseAsync for async transforms");return r},parseAsync:async t=>await Promise.resolve(e(t,{addIssue:()=>{},path:[]}))})}function ar(e,t){return Ve({parse:r=>{const n=e(r);if(null!==n&&"object"==typeof n&&"function"==typeof n.then)throw new Error("Use parseAsync for async refinements");if(!n)throw new Error(nr(t)||"Refinement check failed");return r},parseAsync:async r=>{if(!await e(r))throw new Error(nr(t)||"Refinement check failed");return r}})}const ir={Any:null,Minute:-1,Second:0,Millisecond:3,Microsecond:6},sr={},cr=Symbol.for("vld_brand"),ur=Symbol.for("VldInput"),lr=Symbol.for("VldOutput"),mr={invalid_type:"invalid_type",too_big:"too_big",too_small:"too_small",invalid_format:"invalid_format",not_multiple_of:"not_multiple_of",unrecognized_keys:"unrecognized_keys",invalid_union:"invalid_union",invalid_key:"invalid_key",invalid_element:"invalid_element",invalid_value:"invalid_value",custom:"custom"},dr={getParsedType:function(e){return null===e?"null":Array.isArray(e)?"array":Number.isNaN(e)?"nan":typeof e},propertyKeyTypes:new Set(["string","number","symbol"]),primitiveTypes:new Set(["string","number","bigint","boolean","symbol","undefined","null"]),assert:(e,t="Assertion failed")=>{if(!e)throw new Error(t)},assertNever:e=>{throw new Error(`Unexpected value: ${String(e)}`)},joinValues:(e,t=" | ")=>e.map(e=>JSON.stringify(e)).join(t),jsonStringifyReplacer:(e,t)=>"bigint"==typeof t?t.toString():t,nullish:e=>null==e,cached:e=>{let t,r=!1;return()=>(r||(t=e(),r=!0),t)}},fr={util:dr,regexes:Ge,locales:De,NEVER:pe.create(),TimePrecision:ir,ZodIssueCode:mr,globalRegistry:J,config:Yt,getErrorMap:er,setErrorMap:Qt,parse:(e,t)=>e.parse(t),safeParse:(e,t)=>e.safeParse(t),parseAsync:(e,t)=>e.parseAsync(t),safeParseAsync:(e,t)=>e.safeParseAsync(t)};function pr(e){return ee.create(e||{})}function yr(e,t,r){const n=r.get(e);if(n)return n;if(e instanceof he){const n=e,o=he.create(()=>yr(n.unwrap(),t,r));return r.set(e,o),o}const o=function(e,t){const r=e;if(e instanceof ee){const n=e.shape,o={};let a=!1;for(const e of Object.keys(n))o[e]=t(n[e]),a||(a=o[e]!==n[e]);let i=r.config.catchall;if(i){const e=t(i);a||(a=e!==i),i=e}return a?new ee({...r.config,shape:o,catchall:i}):e}if(e instanceof Q){const n=t(r.element);return n===r.element?e:Q.create(n)}if(e instanceof se){const n=t(r.itemSchema);return n===r.itemSchema?e:se.create(n)}if(e instanceof ce){const n=t(r.keySchema),o=t(r.valueSchema);return n===r.keySchema&&o===r.valueSchema?e:ce.create(n,o)}if(e instanceof ie){const n=t(r.valueSchema),o=r.keySchema?t(r.keySchema):void 0,a=void 0!==r.keySchema&&o!==r.keySchema;return n!==r.valueSchema||a?ie.create(n,o):e}if(e instanceof ae){const n=e.items.map(t),o=n.some((e,t)=>e!==r.items[t]),a=null==r.restValidator?void 0:t(r.restValidator),i=null!=r.restValidator&&a!==r.restValidator;return o||i?new ae(n,r.errorMessage,a):e}if(e instanceof te){const n=r.validators.map(t);return n.some((e,t)=>e!==r.validators[t])?new te(n,r.errorMessage):e}if(e instanceof Ze){const n=r._options.map(t);return n.some((e,t)=>e!==r._options[t])?new Ze(n):e}if(e instanceof be){const n=r._options.map(t);return n.some((e,t)=>e!==r._options[t])?te.create(...n):e}if(e instanceof le){const n=t(r.validatorA),o=t(r.validatorB);return n===r.validatorA&&o===r.validatorB?e:le.create(n,o)}if(e instanceof N){const n=t(r.first),o=t(r.second);return n===r.first&&o===r.second?e:new N(n,o)}if(e instanceof T){const n=t(r.baseValidator);return n===r.baseValidator?e:T.create(n)}if(e instanceof L){const n=t(r.baseValidator);return n===r.baseValidator?e:L.create(n)}if(e instanceof M){const n=t(r.baseValidator);return n===r.baseValidator?e:M.create(n)}if(e instanceof I){const n=t(r.baseValidator);return n===r.baseValidator?e:I.create(n)}if(e instanceof O){const n=t(r.baseValidator);return n===r.baseValidator?e:new O(n,r.defaultValue)}if(e instanceof U){const n=t(r.baseValidator);return n===r.baseValidator?e:new U(n,r.defaultValue)}if(e instanceof P){const n=t(r.baseValidator);return n===r.baseValidator?e:new P(n,r.fallbackValue)}if(e instanceof D){const n=t(r.baseValidator);return n===r.baseValidator?e:new D(n)}if(e instanceof R){const n=t(r.baseValidator);return n===r.baseValidator?e:new R(n,r.metadata)}if(e instanceof $){const n=t(r.baseValidator);return n===r.baseValidator?e:new $(n,r.predicate,r.customMessage)}if(e instanceof F){const n=t(r.baseValidator);return n===r.baseValidator?e:new F(n,r.transformer)}if(e instanceof E){const n=t(r._schema);return n===r._schema?e:new E(r._preprocessor,n)}return e}(e,e=>yr(e,t,r)),a=t(o)??o;return r.set(e,a),a}function gr(e){return yr(e,e=>e instanceof ee?e.partial():void 0,new Map)}function vr(e){return yr(e,e=>e instanceof N?e.first:void 0,new Map)}function hr(e){return yr(e,e=>e instanceof N?e.second:void 0,new Map)}S({array:e=>Q.create(e),union:(e,t)=>te.create(e,t),intersection:(e,t)=>le.create(e,t),toJSONSchema:(e,t)=>Ot(e,t)});const br={string:()=>K.create(),number:()=>G.create(),int:()=>G.create().int(),int32:()=>G.create().int().min(-2147483648).max(2147483647),uint32:()=>G.create().uint32(),uint64:()=>G.create().uint64(),int64:()=>G.create().int64(),float32:()=>G.create().float32(),float64:()=>G.create().float64(),boolean:()=>X.create(),date:()=>H.create(),bigint:()=>ne.create(),symbol:()=>oe.create(),stringbool:e=>Y.create(e),array:e=>Q.create(e),object:pr,strictObject:function(e){return pr(e).strict()},looseObject:function(e){return pr(e).passthrough()},tuple:function(...e){const t=Array.isArray(e[0])?e[0]:e.filter(e=>e instanceof V),r=ae.create(...t);return Array.isArray(e[0])&&e[1]instanceof V?r.rest(e[1]):r},record:function(e,t){return void 0===t?ie.create(e):ie.create(t,e)},partialRecord:function(e,t){return void 0===t?ie.create(e).partial():ie.create(t,e).partial()},looseRecord:function(e,t){return void 0===t?ie.create(e).loose():ie.create(t,e).loose()},set:e=>se.create(e),map:(e,t)=>ce.create(e,t),union:function(...e){const t=Array.isArray(e[0])?e[0]:e.filter(e=>e instanceof V);return te.create(...t)},intersection:(e,t)=>le.create(e,t),discriminatedUnion:function(e,...t){const r=Array.isArray(t[0])?t[0]:t.filter(e=>e instanceof V);return be.create(e,r)},xor:function(...e){const t=Array.isArray(e[0])?e[0]:e.filter(e=>e instanceof V);return Ze.create(t)},keyof:e=>e.keyof(),deepPartial:gr,input:vr,output:hr,literal:function(e){return re.create(e)},enum:function(...e){const t=e[0],r=Array.isArray(t)?t:null!==t&&"object"==typeof t?tr(t):e.filter(e=>"string"==typeof e||"number"==typeof e);return ue.create(r)},nativeEnum:e=>ue.create(tr(e)),any:()=>me.create(),unknown:()=>de.create(),void:()=>fe.create(),never:()=>pe.create(),null:()=>ye.create(),undefined:()=>ge.create(),nan:()=>ve.create(),NEVER:pe.create(),TimePrecision:ir,ZodIssueCode:mr,ZodFirstPartyTypeKind:sr,optional:e=>T.create(e),nullable:e=>L.create(e),nullish:e=>M.create(e),exactOptional:e=>I.create(e),nonoptional:(e,t)=>e.refine(e=>void 0!==e,nr(t)),catch:(e,t)=>e.catch(t),prefault:(e,t)=>e.prefault(t),readonly:e=>e.readonly(),pipe:(e,t)=>e.pipe(t),clone:e=>e,describe:(e,t)=>e instanceof V?e.describe(t||""):de.create().describe(e),meta:(e,t)=>e instanceof V?e.meta(t||{}):de.create().meta(e),transform:(e,t)=>e instanceof V?e.transform(t||(e=>e)):or(e),overwrite:e=>or(e),refine:(e,t,r)=>e instanceof V?e.refine(t,nr(r)):ar(e,t),check:(e,t,r)=>e instanceof V?e.check(t,nr(r)):ar(e,t),superRefine:(e,t)=>e instanceof V?e.superRefine(t||(()=>{})):function(e){return de.create().superRefine(e)}(e),property:function(e,t,r){return Ve({parse:n=>{if("object"!=typeof n||null===n||!(e in n))throw new Error(nr(r)||`Expected object with property "${e}"`);const o=t.safeParse(n[e]);if(!o.success)throw new Error(nr(r)||o.error.message);return n}})},instanceof:(e,t)=>Ve({parse:r=>{if(!(r instanceof e))throw new Error(nr(t)||`Expected instance of ${e.name||"provided constructor"}`);return r}}),config:Yt,setErrorMap:Qt,getErrorMap:er,core:fr,util:dr,locales:De,lazy:e=>he.create(e),json:e=>xe.create(e),custom:Ve,file:()=>we(),function:()=>Ie(),preprocess:(e,t)=>E.create(e,t),coerce:{string:()=>$e.create(),number:()=>Be.create(),boolean:()=>ke.create(),date:()=>Re.create(),bigint:()=>Ce.create()},email:e=>qe(e),url:e=>St(e),uuid:e=>We(e),uuidv4:()=>jt(),uuidv6:()=>xt(),uuidv7:()=>Zt(),hostname:()=>bt(),emoji:()=>ht(),base64:()=>vt(),base64url:()=>gt(),hex:()=>yt(),jwt:()=>pt(),nanoid:()=>ft(),cuid:()=>dt(),cuid2:()=>mt(),ulid:()=>lt(),ipv4:()=>ut(),ipv6:()=>ct(),mac:()=>st(),cidrv4:()=>it(),cidrv6:()=>at(),creditCard:e=>ot(e),e164:()=>nt(),hash:e=>rt(e),iso:{ZodISODate:Xe,ZodISODateTime:Xe,ZodISODuration:Xe,ZodISOTime:Xe,date:()=>tt.date(),time:e=>tt.time(e),datetime:e=>tt.datetime(e),dateTime:e=>tt.dateTime(e),duration:()=>tt.duration()},stringFormat:(e,t)=>et(e,t),minLength:(e,t)=>K.create().min(e,t),maxLength:(e,t)=>K.create().max(e,t),length:(e,t)=>K.create().length(e,t),regex:(e,t)=>K.create().regex(e,t),startsWith:(e,t)=>K.create().startsWith(e,t),endsWith:(e,t)=>K.create().endsWith(e,t),includes:(e,t)=>K.create().includes(e,t),trim:()=>K.create().trim(),toLowerCase:()=>K.create().toLowerCase(),lowercase:()=>K.create().toLowerCase(),toUpperCase:()=>K.create().toUpperCase(),uppercase:()=>K.create().toUpperCase(),gt:(e,t)=>G.create().gt(e,t),gte:(e,t)=>G.create().gte(e,t),lt:(e,t)=>G.create().lt(e,t),lte:(e,t)=>G.create().lte(e,t),positive:e=>G.create().positive(e),negative:e=>G.create().negative(e),nonnegative:e=>G.create().nonnegative(e),nonpositive:e=>G.create().nonpositive(e),multipleOf:(e,t)=>G.create().multipleOf(e,t),minSize:(e,t)=>K.create().min(e,t),maxSize:(e,t)=>K.create().max(e,t),size:(e,t)=>K.create().length(e,t),normalize:e=>K.create().transform(t=>t.normalize(e)),slugify:()=>K.create().transform(e=>e.normalize("NFKD").replace(/[\u0300-\u036f]/g,"").toLowerCase().trim().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")),mime:(e,t)=>Ae.create().mime(e,t),xid:()=>Qe(),guid:()=>Ye(),httpUrl:()=>Ke(),ksuid:()=>He(),regexes:Ge,templateLiteral:(...e)=>Se(...e),base64Bytes:()=>Le.create(),hexBytes:()=>Te.create(),uint8Array:()=>_e.create(),codec:(e,t,r)=>Me.create(e,t,r),invertCodec:e=>e.invert(),promise:e=>Ue(e),parse:(e,t)=>e.parse(t),safeParse:(e,t)=>e.safeParse(t),parseAsync:(e,t)=>e.parseAsync(t),safeParseAsync:(e,t)=>e.safeParseAsync(t),decode:(e,t)=>e.parse(t),safeDecode:(e,t)=>e.safeParse(t),decodeAsync:(e,t)=>e.parseAsync(t),safeDecodeAsync:(e,t)=>e.safeParseAsync(t),encode:(e,t)=>e.encode(t),safeEncode:(e,t)=>e.safeEncode(t),encodeAsync:(e,t)=>e.encodeAsync(t),safeEncodeAsync:(e,t)=>e.safeEncodeAsync(t),formatError:e=>{const t={_errors:[]};if(e instanceof Vt){for(const r of e.issues)rr(t,r.path,r.message);return t}return t._errors.push(function(e){return e instanceof Error?e.message:String(e)}(e)),t},treeifyError:Je,prettifyError:Fe,flattenError:ze,toJSONSchema:Ot,fromJSONSchema:At};Object.assign(br,{globalRegistry:J,registry:W,_default:(e,t)=>new O(e,t),success:e=>Ve({parse:e=>e}),_function:()=>Ie(),ZodType:V,ZodTypeAny:V,ZodTypeDef:Object,ZodError:Vt,ZodRealError:Vt,_ZodString:K,ZodString:K,ZodStringFormat:K,ZodEmail:K,ZodGUID:K,ZodUUID:K,ZodURL:K,ZodEmoji:K,ZodNanoID:K,ZodCUID:K,ZodCUID2:K,ZodULID:K,ZodXID:K,ZodKSUID:K,ZodIPv4:K,ZodMAC:K,ZodIPv6:K,ZodCIDRv4:K,ZodCIDRv6:K,ZodBase64:K,ZodBase64URL:K,ZodE164:K,ZodJWT:K,ZodCustomStringFormat:K,ZodNumber:G,ZodNumberFormat:G,ZodBoolean:X,ZodBigInt:ne,ZodBigIntFormat:ne,ZodSymbol:oe,ZodUndefined:ge,ZodNull:ye,ZodAny:me,ZodUnknown:de,ZodNever:pe,ZodVoid:fe,ZodDate:H,ZodArray:Q,ZodObject:ee,ZodUnion:te,ZodXor:Ze,ZodDiscriminatedUnion:be,ZodIntersection:le,ZodTuple:ae,ZodRecord:ie,ZodMap:ce,ZodSet:se,ZodEnum:ue,ZodLiteral:re,ZodFile:Ae,ZodTransform:V,ZodOptional:V,ZodExactOptional:V,ZodNullable:V,ZodDefault:V,ZodPrefault:V,ZodNonOptional:V,ZodSuccess:Oe,ZodCatch:V,ZodNaN:ve,ZodPipe:V,ZodCodec:Me,ZodPreprocess:V,ZodReadonly:V,ZodTemplateLiteral:je,ZodLazy:he,ZodPromise:Ne,ZodFunction:Ee,ZodCustom:Oe,ZodISODateTime:K,ZodISODate:K,ZodISOTime:K,ZodISODuration:K,$brand:Symbol.for("zod.brand"),$output:Symbol.for("zod.output"),$input:Symbol.for("zod.input")});const Zr=br,{string:xr,number:jr,int:Sr,int32:Vr,uint32:Or,uint64:Ar,int64:wr,float32:Er,float64:Ir,boolean:Mr,date:Lr,bigint:Tr,symbol:_r,stringbool:Nr,array:Ur,object:Pr,strictObject:Dr,looseObject:Cr,tuple:Rr,record:kr,partialRecord:Br,looseRecord:$r,set:zr,union:Fr,intersection:Jr,discriminatedUnion:Wr,xor:Kr,keyof:qr,literal:Gr,nativeEnum:Xr,any:Hr,unknown:Yr,nan:Qr,optional:en,nullable:tn,nullish:rn,exactOptional:nn,nonoptional:on,readonly:an,pipe:sn,clone:cn,describe:un,meta:ln,transform:mn,overwrite:dn,refine:fn,check:pn,superRefine:yn,property:gn,config:vn,setErrorMap:hn,getErrorMap:bn,locales:Zn,lazy:xn,json:jn,custom:Sn,file:Vn,preprocess:On,coerce:An,email:wn,url:En,uuid:In,uuidv4:Mn,uuidv6:Ln,uuidv7:Tn,hostname:_n,emoji:Nn,base64:Un,base64url:Pn,hex:Dn,jwt:Cn,nanoid:Rn,cuid:kn,cuid2:Bn,ulid:$n,ipv4:zn,ipv6:Fn,mac:Jn,cidrv4:Wn,cidrv6:Kn,creditCard:qn,e164:Gn,hash:Xn,iso:Hn,stringFormat:Yn,normalize:Qn,slugify:eo,mime:to,xid:ro,guid:no,httpUrl:oo,ksuid:ao,regexes:io,templateLiteral:so,base64Bytes:co,hexBytes:uo,uint8Array:lo,codec:mo,promise:fo,prefault:po,parse:yo,safeParse:go,parseAsync:vo,safeParseAsync:ho,decode:bo,safeDecode:Zo,decodeAsync:xo,safeDecodeAsync:jo,encode:So,safeEncode:Vo,encodeAsync:Oo,safeEncodeAsync:Ao,formatError:wo,NEVER:Eo}=br,Io=br.catch,Mo=br.enum,Lo=br.function,To=br.instanceof,_o=br.map,No=br.never,Uo=br.null,Po=br.undefined,Do=br.void,Co=br,Ro=K;function ko(e,t){return e instanceof V&&t instanceof V?br.map(e,t):Pe(e,t)}const Bo=(e,t)=>br.string().min(e,t),$o=(e,t)=>br.string().max(e,t),zo=(e,t)=>br.string().length(e,t),Fo=(e,t)=>br.string().regex(e,t),Jo=(e,t)=>br.string().startsWith(e,t),Wo=(e,t)=>br.string().endsWith(e,t),Ko=(e,t)=>br.string().includes(e,t),qo=()=>br.string().trim(),Go=()=>br.string().toLowerCase(),Xo=Go,Ho=()=>br.string().toUpperCase(),Yo=Ho,Qo=(e,t)=>br.number().gt(e,t),ea=(e,t)=>br.number().gte(e,t),ta=(e,t)=>br.number().lt(e,t),ra=(e,t)=>br.number().lte(e,t),na=e=>br.number().positive(e),oa=e=>br.number().negative(e),aa=e=>br.number().nonnegative(e),ia=e=>br.number().nonpositive(e),sa=(e,t)=>br.number().multipleOf(e,t),ca=Bo,ua=$o,la=zo;export{cr as $brand,ur as $input,lr as $output,Eo as NEVER,ir as TimePrecision,V as VldBase,Vt as VldError,le as VldIntersection,R as VldMeta,me as ZodAny,Q as ZodArray,Xe as ZodBase64,Xe as ZodBase64URL,ne as ZodBigInt,ne as ZodBigIntFormat,X as ZodBoolean,Xe as ZodCIDRv4,Xe as ZodCIDRv6,Xe as ZodCUID,Xe as ZodCUID2,P as ZodCatch,Me as ZodCodec,Xe as ZodCreditCard,Oe as ZodCustom,Xe as ZodCustomStringFormat,H as ZodDate,O as ZodDefault,be as ZodDiscriminatedUnion,Xe as ZodE164,Xe as ZodEmail,Xe as ZodEmoji,ue as ZodEnum,Vt as ZodError,I as ZodExactOptional,Ae as ZodFile,sr as ZodFirstPartyTypeKind,Ee as ZodFunction,Xe as ZodGUID,Xe as ZodIPv4,Xe as ZodIPv6,Xe as ZodISODate,Xe as ZodISODateTime,Xe as ZodISODuration,Xe as ZodISOTime,le as ZodIntersection,mr as ZodIssueCode,xe as ZodJSON,Xe as ZodJWT,Xe as ZodKSUID,he as ZodLazy,re as ZodLiteral,Xe as ZodMAC,ce as ZodMap,R as ZodMeta,ve as ZodNaN,Xe as ZodNanoID,pe as ZodNever,$ as ZodNonOptional,ye as ZodNull,L as ZodNullable,G as ZodNumber,G as ZodNumberFormat,ee as ZodObject,T as ZodOptional,N as ZodPipe,U as ZodPrefault,E as ZodPreprocess,Ne as ZodPromise,D as ZodReadonly,Vt as ZodRealError,ie as ZodRecord,se as ZodSet,K as ZodString,Xe as ZodStringFormat,Oe as ZodSuccess,oe as ZodSymbol,je as ZodTemplateLiteral,F as ZodTransform,ae as ZodTuple,V as ZodType,Xe as ZodULID,Xe as ZodURL,Xe as ZodUUID,ge as ZodUndefined,te as ZodUnion,de as ZodUnknown,fe as ZodVoid,Xe as ZodXID,Ze as ZodXor,Ro as _ZodString,Co as _default,Lo as _function,Hr as any,Ur as array,Un as base64,co as base64Bytes,Pn as base64url,Tr as bigint,Mr as boolean,Io as catch,pn as check,Wn as cidrv4,Kn as cidrv6,cn as clone,mo as codec,An as coerce,vn as config,fr as core,Bt as createLogger,qt as createNoOpLogger,qn as creditCard,kn as cuid,Bn as cuid2,Sn as custom,Lr as date,bo as decode,xo as decodeAsync,gr as deepPartial,br as default,un as describe,Kt as disableLogging,Wr as discriminatedUnion,Gn as e164,wn as email,Nn as emoji,Wt as enableDebug,So as encode,Oo as encodeAsync,Wo as endsWith,Mo as enum,nn as exactOptional,Vn as file,ze as flattenError,Er as float32,Ir as float64,wo as formatError,At as fromJSONSchema,Lo as function,bn as getErrorMap,Ft as getLogger,J as globalRegistry,Qo as gt,ea as gte,no as guid,Xn as hash,Dn as hex,uo as hexBytes,_n as hostname,oo as httpUrl,Ko as includes,zt as initLogger,vr as input,To as instanceof,Sr as int,Vr as int32,wr as int64,Jr as intersection,zn as ipv4,Fn as ipv6,Hn as iso,jn as json,Cn as jwt,qr as keyof,ao as ksuid,xn as lazy,zo as length,Gr as literal,Zn as locales,Cr as looseObject,$r as looseRecord,Xo as lowercase,ta as lt,ra as lte,Jn as mac,ko as map,_o as mapSchema,$o as maxLength,ua as maxSize,ln as meta,to as mime,Bo as minLength,ca as minSize,sa as multipleOf,Qr as nan,Rn as nanoid,Xr as nativeEnum,oa as negative,No as never,aa as nonnegative,on as nonoptional,ia as nonpositive,Qn as normalize,Uo as null,tn as nullable,rn as nullish,jr as number,Pr as object,en as optional,hr as output,dn as overwrite,yo as parse,vo as parseAsync,Br as partialRecord,sn as pipe,na as positive,po as prefault,On as preprocess,Fe as prettifyError,fo as promise,gn as property,an as readonly,kr as record,fn as refine,Fo as regex,io as regexes,W as registry,Zo as safeDecode,jo as safeDecodeAsync,Vo as safeEncode,Ao as safeEncodeAsync,go as safeParse,ho as safeParseAsync,zr as set,hn as setErrorMap,Jt as setLogLevel,la as size,eo as slugify,Jo as startsWith,Dr as strictObject,xr as string,Yn as stringFormat,Nr as stringbool,yn as superRefine,_r as symbol,so as templateLiteral,Ot as toJSONSchema,Go as toLowerCase,Ho as toUpperCase,mn as transform,Je as treeifyError,qo as trim,Rr as tuple,Or as uint32,Ar as uint64,lo as uint8Array,$n as ulid,Po as undefined,Fr as union,Yr as unknown,Yo as uppercase,En as url,dr as util,In as uuid,Mn as uuidv4,Ln as uuidv6,Tn as uuidv7,br as v,Do as void,ro as xid,Kr as xor,Zr as z};
|