@oxog/vld 2.0.3 → 2.1.0
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 +33 -1
- package/README.md +101 -37
- package/dist/chunks/errors-core-BeiFUtZM.js +81 -0
- package/dist/chunks/{index-DO8CFMxD.js → index-0R2ntSud.js} +16 -402
- package/dist/chunks/index-BvH403Yy.js +88 -0
- package/dist/chunks/security-B0Pd_vSY.js +35 -0
- package/dist/chunks/string-BJRQod3t.js +530 -0
- package/dist/cjs/chunks/errors-core-DWxLFs2f.cjs +83 -0
- package/dist/cjs/chunks/index-BkI37108.cjs +538 -0
- package/dist/cjs/chunks/index-Cc3bjUMX.cjs +91 -0
- package/dist/cjs/chunks/security-Dc3Jh13T.cjs +37 -0
- package/dist/cjs/chunks/string-BKZrc4hs.cjs +533 -0
- package/dist/cjs/cli/bin.cjs +506 -0
- package/dist/cjs/cli/index.cjs +209 -0
- package/dist/cjs/codecs/index.cjs +45 -0
- package/dist/{chunks/date-50JV_Mfj.js → cjs/coercion/index.cjs} +185 -103
- package/dist/cjs/compat/emitter.cjs +184 -0
- package/dist/cjs/compat/result.cjs +189 -0
- package/dist/cjs/errors.cjs +6 -213
- package/dist/cjs/index.cjs +1471 -10336
- package/dist/cjs/kernel.cjs +415 -0
- package/dist/cjs/locales/af.cjs +108 -0
- package/dist/cjs/locales/ar.cjs +108 -0
- package/dist/cjs/locales/bn.cjs +108 -0
- package/dist/cjs/locales/da.cjs +108 -0
- package/dist/cjs/locales/de.cjs +108 -0
- package/dist/cjs/locales/en.cjs +108 -0
- package/dist/cjs/locales/es-MX.cjs +107 -0
- package/dist/cjs/locales/es.cjs +96 -0
- package/dist/cjs/locales/fi.cjs +108 -0
- package/dist/cjs/locales/fr.cjs +96 -0
- package/dist/cjs/locales/hi.cjs +108 -0
- package/dist/cjs/locales/id.cjs +108 -0
- package/dist/cjs/locales/index.cjs +41 -2875
- package/dist/cjs/locales/it.cjs +108 -0
- package/dist/cjs/locales/ja.cjs +108 -0
- package/dist/cjs/locales/ko.cjs +108 -0
- package/dist/cjs/locales/lazy.cjs +42 -3023
- package/dist/cjs/locales/nl.cjs +108 -0
- package/dist/cjs/locales/no.cjs +108 -0
- package/dist/cjs/locales/pl.cjs +108 -0
- package/dist/cjs/locales/pt-BR.cjs +108 -0
- package/dist/cjs/locales/pt.cjs +108 -0
- package/dist/cjs/locales/ru.cjs +108 -0
- package/dist/cjs/locales/runtime.cjs +51 -0
- package/dist/cjs/locales/sv.cjs +108 -0
- package/dist/cjs/locales/sw.cjs +108 -0
- package/dist/cjs/locales/th.cjs +108 -0
- package/dist/cjs/locales/tr.cjs +108 -0
- package/dist/cjs/locales/vi.cjs +108 -0
- package/dist/cjs/locales/zh.cjs +108 -0
- package/dist/cjs/mini.cjs +121 -7353
- package/dist/cjs/pigment.cjs +207 -0
- package/dist/cjs/plugins/index.cjs +12 -0
- package/dist/cjs/registry.cjs +37 -0
- package/dist/cjs/v3/index.cjs +425 -0
- package/dist/cjs/v4/core/index.cjs +894 -0
- package/dist/cjs/v4/index.cjs +425 -0
- package/dist/cjs/v4/locales/index.cjs +130 -0
- package/dist/cjs/v4/mini/index.cjs +509 -0
- package/dist/cjs/v4-mini/index.cjs +532 -0
- package/dist/cjs/validators/any.cjs +40 -0
- package/dist/cjs/validators/array.cjs +283 -0
- package/dist/cjs/validators/base.cjs +887 -0
- package/dist/cjs/validators/base64.cjs +73 -0
- package/dist/cjs/validators/bigint.cjs +232 -0
- package/dist/cjs/validators/boolean.cjs +146 -0
- package/dist/cjs/validators/codec.cjs +205 -0
- package/dist/cjs/validators/custom.cjs +71 -0
- package/dist/cjs/validators/date.cjs +278 -0
- package/dist/cjs/validators/discriminated-union.cjs +130 -0
- package/dist/cjs/validators/enum.cjs +154 -0
- package/dist/cjs/validators/file.cjs +130 -0
- package/dist/cjs/validators/function.cjs +63 -0
- package/dist/cjs/validators/hex.cjs +70 -0
- package/dist/cjs/validators/index.cjs +123 -0
- package/dist/cjs/validators/intersection.cjs +120 -0
- package/dist/cjs/validators/json.cjs +70 -0
- package/dist/cjs/validators/lazy.cjs +53 -0
- package/dist/cjs/validators/literal.cjs +64 -0
- package/dist/cjs/validators/map.cjs +218 -0
- package/dist/cjs/validators/nan.cjs +41 -0
- package/dist/cjs/validators/never.cjs +36 -0
- package/dist/cjs/validators/null.cjs +43 -0
- package/dist/cjs/validators/number.cjs +427 -0
- package/dist/cjs/validators/object.cjs +868 -0
- package/dist/cjs/validators/promise.cjs +115 -0
- package/dist/cjs/validators/record.cjs +262 -0
- package/dist/cjs/validators/set.cjs +203 -0
- package/dist/cjs/validators/string-bool.cjs +124 -0
- package/dist/cjs/validators/string-formats.cjs +168 -0
- package/dist/cjs/validators/string.cjs +12 -0
- package/dist/cjs/validators/symbol.cjs +62 -0
- package/dist/cjs/validators/template-literal.cjs +108 -0
- package/dist/cjs/validators/tuple.cjs +187 -0
- package/dist/cjs/validators/uint8array.cjs +106 -0
- package/dist/cjs/validators/undefined.cjs +43 -0
- package/dist/cjs/validators/union.cjs +191 -0
- package/dist/cjs/validators/unknown.cjs +40 -0
- package/dist/cjs/validators/void.cjs +48 -0
- package/dist/cjs/validators/xor.cjs +69 -0
- package/dist/cli/bin.d.ts +0 -1
- package/dist/cli/bin.js +407 -0
- package/dist/cli/commands/benchmark.d.ts +1 -2
- package/dist/cli/commands/validate.d.ts +1 -2
- package/dist/cli/index.d.ts +0 -1
- package/dist/cli/index.js +205 -0
- package/dist/codecs/index.d.ts +21 -4
- package/dist/codecs/index.js +11 -4
- package/dist/coercion/bigint.d.ts +2 -3
- package/dist/coercion/boolean.d.ts +3 -3
- package/dist/coercion/date.d.ts +3 -3
- package/dist/coercion/index.d.ts +5 -6
- package/dist/coercion/index.js +473 -5
- package/dist/coercion/number.d.ts +2 -3
- package/dist/coercion/string.d.ts +2 -3
- package/dist/compat/emitter.d.ts +0 -1
- package/dist/compat/emitter.js +0 -1
- package/dist/compat/index.d.ts +4 -5
- package/dist/compat/result.d.ts +1 -2
- package/dist/compat/result.js +0 -1
- package/dist/errors-core.d.ts +39 -0
- package/dist/errors.d.ts +4 -54
- package/dist/errors.js +4 -68
- package/dist/events.d.ts +3 -4
- package/dist/index.d.ts +1186 -835
- package/dist/index.js +1046 -367
- package/dist/kernel.d.ts +2 -3
- package/dist/kernel.js +10 -6
- package/dist/locales/af.d.ts +1 -2
- package/dist/locales/af.js +0 -1
- package/dist/locales/ar.d.ts +1 -2
- package/dist/locales/ar.js +0 -1
- package/dist/locales/bn.d.ts +1 -2
- package/dist/locales/bn.js +0 -1
- package/dist/locales/da.d.ts +1 -2
- package/dist/locales/da.js +0 -1
- package/dist/locales/de.d.ts +1 -2
- package/dist/locales/de.js +0 -1
- package/dist/locales/en.d.ts +1 -2
- package/dist/locales/en.js +0 -1
- package/dist/locales/es-MX.d.ts +1 -2
- package/dist/locales/es-MX.js +0 -1
- package/dist/locales/es.d.ts +1 -2
- package/dist/locales/es.js +0 -1
- package/dist/locales/fi.d.ts +1 -2
- package/dist/locales/fi.js +0 -1
- package/dist/locales/fr.d.ts +1 -2
- package/dist/locales/fr.js +0 -1
- package/dist/locales/hi.d.ts +1 -2
- package/dist/locales/hi.js +0 -1
- package/dist/locales/id.d.ts +1 -2
- package/dist/locales/id.js +0 -1
- package/dist/locales/index.d.ts +10 -15
- package/dist/locales/index.js +28 -2
- package/dist/locales/it.d.ts +1 -2
- package/dist/locales/it.js +0 -1
- package/dist/locales/ja.d.ts +1 -2
- package/dist/locales/ja.js +0 -1
- package/dist/locales/ko.d.ts +1 -2
- package/dist/locales/ko.js +0 -1
- package/dist/locales/lazy.d.ts +4 -26
- package/dist/locales/lazy.js +12 -55
- package/dist/locales/nl.d.ts +1 -2
- package/dist/locales/nl.js +0 -1
- package/dist/locales/no.d.ts +1 -2
- package/dist/locales/no.js +0 -1
- package/dist/locales/pl.d.ts +1 -2
- package/dist/locales/pl.js +0 -1
- package/dist/locales/pt-BR.d.ts +1 -2
- package/dist/locales/pt-BR.js +0 -1
- package/dist/locales/pt.d.ts +1 -2
- package/dist/locales/pt.js +0 -1
- package/dist/locales/ru.d.ts +1 -2
- package/dist/locales/ru.js +0 -1
- package/dist/locales/runtime.d.ts +10 -0
- package/dist/locales/runtime.js +41 -0
- package/dist/locales/sv.d.ts +1 -2
- package/dist/locales/sv.js +0 -1
- package/dist/locales/sw.d.ts +1 -2
- package/dist/locales/sw.js +0 -1
- package/dist/locales/th.d.ts +1 -2
- package/dist/locales/th.js +0 -1
- package/dist/locales/tr.d.ts +1 -2
- package/dist/locales/tr.js +0 -1
- package/dist/locales/types.d.ts +0 -1
- package/dist/locales/vi.d.ts +1 -2
- package/dist/locales/vi.js +0 -1
- package/dist/locales/zh.d.ts +1 -2
- package/dist/locales/zh.js +0 -1
- package/dist/logger.d.ts +0 -1
- package/dist/mini.d.ts +64 -65
- package/dist/mini.js +31 -7
- package/dist/pigment.d.ts +0 -1
- package/dist/pigment.js +6 -4
- package/dist/plugins/index.d.ts +2 -3
- package/dist/plugins/index.js +1 -0
- package/dist/plugins/types.d.ts +4 -5
- package/dist/registry.d.ts +23 -0
- package/dist/registry.js +34 -0
- package/dist/utils/codec-utils.d.ts +0 -1
- package/dist/utils/deep-merge.d.ts +0 -1
- package/dist/utils/ip-validation.d.ts +0 -1
- package/dist/utils/json-schema.d.ts +16 -6
- package/dist/utils/security.d.ts +2 -6
- package/dist/v3/index.d.ts +2 -0
- package/dist/v3/index.js +46 -0
- package/dist/v4/core/index.d.ts +260 -0
- package/dist/v4/core/index.js +277 -0
- package/dist/v4/index.d.ts +4 -0
- package/dist/v4/index.js +50 -0
- package/dist/v4/locales/index.d.ts +53 -0
- package/dist/v4/locales/index.js +77 -0
- package/dist/v4/mini/index.d.ts +2 -0
- package/dist/v4/mini/index.js +47 -0
- package/dist/v4-mini/index.d.ts +22 -0
- package/dist/v4-mini/index.js +75 -0
- package/dist/validators/any.d.ts +7 -2
- package/dist/validators/any.js +37 -0
- package/dist/validators/array.d.ts +9 -2
- package/dist/validators/array.js +279 -0
- package/dist/validators/base.d.ts +150 -6
- package/dist/validators/base.js +868 -0
- package/dist/validators/base64.d.ts +1 -2
- package/dist/validators/base64.js +68 -0
- package/dist/validators/bigint.d.ts +21 -3
- package/dist/validators/bigint.js +228 -0
- package/dist/validators/boolean.d.ts +13 -4
- package/dist/validators/boolean.js +142 -0
- package/dist/validators/codec.d.ts +9 -2
- package/dist/validators/codec.js +200 -0
- package/dist/validators/custom.d.ts +15 -2
- package/dist/validators/custom.js +67 -0
- package/dist/validators/date.d.ts +19 -3
- package/dist/validators/date.js +274 -0
- package/dist/validators/discriminated-union.d.ts +4 -3
- package/dist/validators/discriminated-union.js +123 -0
- package/dist/validators/enum.d.ts +10 -7
- package/dist/validators/enum.js +150 -0
- package/dist/validators/file.d.ts +7 -2
- package/dist/validators/file.js +125 -0
- package/dist/validators/function.d.ts +11 -5
- package/dist/validators/function.js +58 -0
- package/dist/validators/hex.d.ts +1 -2
- package/dist/validators/hex.js +65 -0
- package/dist/validators/index.d.ts +38 -39
- package/dist/validators/index.js +35 -515
- package/dist/validators/intersection.d.ts +1 -2
- package/dist/validators/intersection.js +116 -0
- package/dist/validators/json.d.ts +1 -2
- package/dist/validators/json.js +66 -0
- package/dist/validators/lazy.d.ts +5 -9
- package/dist/validators/lazy.js +50 -0
- package/dist/validators/literal.d.ts +2 -2
- package/dist/validators/literal.js +60 -0
- package/dist/validators/map.d.ts +15 -2
- package/dist/validators/map.js +214 -0
- package/dist/validators/nan.d.ts +2 -3
- package/dist/validators/nan.js +38 -0
- package/dist/validators/never.d.ts +1 -2
- package/dist/validators/never.js +32 -0
- package/dist/validators/null.d.ts +3 -3
- package/dist/validators/null.js +40 -0
- package/dist/validators/number.d.ts +56 -27
- package/dist/validators/number.js +423 -0
- package/dist/validators/object.d.ts +30 -9
- package/dist/validators/object.js +864 -0
- package/dist/validators/promise.d.ts +15 -10
- package/dist/validators/promise.js +111 -0
- package/dist/validators/record.d.ts +11 -2
- package/dist/validators/record.js +258 -0
- package/dist/validators/set.d.ts +11 -2
- package/dist/validators/set.js +199 -0
- package/dist/validators/string-bool.d.ts +7 -10
- package/dist/validators/string-bool.js +120 -0
- package/dist/validators/string-formats.d.ts +7 -4
- package/dist/validators/string-formats.js +135 -0
- package/dist/validators/string.d.ts +39 -18
- package/dist/validators/string.js +4 -0
- package/dist/validators/symbol.d.ts +8 -3
- package/dist/validators/symbol.js +58 -0
- package/dist/validators/template-literal.d.ts +1 -2
- package/dist/validators/template-literal.js +103 -0
- package/dist/validators/tuple.d.ts +15 -2
- package/dist/validators/tuple.js +183 -0
- package/dist/validators/uint8array.d.ts +3 -4
- package/dist/validators/uint8array.js +101 -0
- package/dist/validators/undefined.d.ts +3 -3
- package/dist/validators/undefined.js +40 -0
- package/dist/validators/union.d.ts +7 -4
- package/dist/validators/union.js +187 -0
- package/dist/validators/unknown.d.ts +7 -2
- package/dist/{chunks/unknown-Dhzri_T-.js → validators/unknown.js} +12 -3
- package/dist/validators/void.d.ts +3 -2
- package/dist/validators/void.js +44 -0
- package/dist/validators/xor.d.ts +2 -3
- package/dist/validators/xor.js +66 -0
- package/package.json +114 -30
- package/dist/chunks/bigint-CRS0QVsy.js +0 -1854
- package/dist/chunks/bigint-CRS0QVsy.js.map +0 -1
- package/dist/chunks/date-50JV_Mfj.js.map +0 -1
- package/dist/chunks/index-DO8CFMxD.js.map +0 -1
- package/dist/chunks/json-Cp4WO0M9.js +0 -2021
- package/dist/chunks/json-Cp4WO0M9.js.map +0 -1
- package/dist/chunks/unknown-Dhzri_T-.js.map +0 -1
- package/dist/cjs/errors.cjs.map +0 -1
- package/dist/cjs/index.cjs.map +0 -1
- package/dist/cjs/locales/index.cjs.map +0 -1
- package/dist/cjs/locales/lazy.cjs.map +0 -1
- package/dist/cjs/mini.cjs.map +0 -1
- package/dist/cli/bin.d.ts.map +0 -1
- package/dist/cli/commands/benchmark.d.ts.map +0 -1
- package/dist/cli/commands/validate.d.ts.map +0 -1
- package/dist/cli/index.d.ts.map +0 -1
- package/dist/codecs/index.d.ts.map +0 -1
- package/dist/codecs/index.js.map +0 -1
- package/dist/coercion/bigint.d.ts.map +0 -1
- package/dist/coercion/boolean.d.ts.map +0 -1
- package/dist/coercion/date.d.ts.map +0 -1
- package/dist/coercion/index.d.ts.map +0 -1
- package/dist/coercion/index.js.map +0 -1
- package/dist/coercion/number.d.ts.map +0 -1
- package/dist/coercion/string.d.ts.map +0 -1
- package/dist/compat/emitter.d.ts.map +0 -1
- package/dist/compat/emitter.js.map +0 -1
- package/dist/compat/index.d.ts.map +0 -1
- package/dist/compat/result.d.ts.map +0 -1
- package/dist/compat/result.js.map +0 -1
- package/dist/errors.d.ts.map +0 -1
- package/dist/errors.js.map +0 -1
- package/dist/events.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/kernel.d.ts.map +0 -1
- package/dist/kernel.js.map +0 -1
- package/dist/locales/af.d.ts.map +0 -1
- package/dist/locales/af.js.map +0 -1
- package/dist/locales/ar.d.ts.map +0 -1
- package/dist/locales/ar.js.map +0 -1
- package/dist/locales/backup-en.d.ts +0 -3
- package/dist/locales/backup-en.d.ts.map +0 -1
- package/dist/locales/bn.d.ts.map +0 -1
- package/dist/locales/bn.js.map +0 -1
- package/dist/locales/da.d.ts.map +0 -1
- package/dist/locales/da.js.map +0 -1
- package/dist/locales/de.d.ts.map +0 -1
- package/dist/locales/de.js.map +0 -1
- package/dist/locales/en.d.ts.map +0 -1
- package/dist/locales/en.js.map +0 -1
- package/dist/locales/es-MX.d.ts.map +0 -1
- package/dist/locales/es-MX.js.map +0 -1
- package/dist/locales/es.d.ts.map +0 -1
- package/dist/locales/es.js.map +0 -1
- package/dist/locales/fi.d.ts.map +0 -1
- package/dist/locales/fi.js.map +0 -1
- package/dist/locales/fr.d.ts.map +0 -1
- package/dist/locales/fr.js.map +0 -1
- package/dist/locales/hi.d.ts.map +0 -1
- package/dist/locales/hi.js.map +0 -1
- package/dist/locales/id.d.ts.map +0 -1
- package/dist/locales/id.js.map +0 -1
- package/dist/locales/index.d.ts.map +0 -1
- package/dist/locales/index.js.map +0 -1
- package/dist/locales/it.d.ts.map +0 -1
- package/dist/locales/it.js.map +0 -1
- package/dist/locales/ja.d.ts.map +0 -1
- package/dist/locales/ja.js.map +0 -1
- package/dist/locales/ko.d.ts.map +0 -1
- package/dist/locales/ko.js.map +0 -1
- package/dist/locales/lazy.d.ts.map +0 -1
- package/dist/locales/lazy.js.map +0 -1
- package/dist/locales/nl.d.ts.map +0 -1
- package/dist/locales/nl.js.map +0 -1
- package/dist/locales/no.d.ts.map +0 -1
- package/dist/locales/no.js.map +0 -1
- package/dist/locales/pl.d.ts.map +0 -1
- package/dist/locales/pl.js.map +0 -1
- package/dist/locales/pt-BR.d.ts.map +0 -1
- package/dist/locales/pt-BR.js.map +0 -1
- package/dist/locales/pt.d.ts.map +0 -1
- package/dist/locales/pt.js.map +0 -1
- package/dist/locales/ru.d.ts.map +0 -1
- package/dist/locales/ru.js.map +0 -1
- package/dist/locales/sv.d.ts.map +0 -1
- package/dist/locales/sv.js.map +0 -1
- package/dist/locales/sw.d.ts.map +0 -1
- package/dist/locales/sw.js.map +0 -1
- package/dist/locales/th.d.ts.map +0 -1
- package/dist/locales/th.js.map +0 -1
- package/dist/locales/tr.d.ts.map +0 -1
- package/dist/locales/tr.js.map +0 -1
- package/dist/locales/types.d.ts.map +0 -1
- package/dist/locales/vi.d.ts.map +0 -1
- package/dist/locales/vi.js.map +0 -1
- package/dist/locales/zh.d.ts.map +0 -1
- package/dist/locales/zh.js.map +0 -1
- package/dist/logger.d.ts.map +0 -1
- package/dist/mini.d.ts.map +0 -1
- package/dist/mini.js.map +0 -1
- package/dist/pigment.d.ts.map +0 -1
- package/dist/pigment.js.map +0 -1
- package/dist/plugins/index.d.ts.map +0 -1
- package/dist/plugins/types.d.ts.map +0 -1
- package/dist/utils/codec-utils.d.ts.map +0 -1
- package/dist/utils/deep-merge.d.ts.map +0 -1
- package/dist/utils/ip-validation.d.ts.map +0 -1
- package/dist/utils/json-schema.d.ts.map +0 -1
- package/dist/utils/security.d.ts.map +0 -1
- package/dist/validators/any.d.ts.map +0 -1
- package/dist/validators/array.d.ts.map +0 -1
- package/dist/validators/base.d.ts.map +0 -1
- package/dist/validators/base64.d.ts.map +0 -1
- package/dist/validators/bigint.d.ts.map +0 -1
- package/dist/validators/boolean.d.ts.map +0 -1
- package/dist/validators/codec.d.ts.map +0 -1
- package/dist/validators/custom.d.ts.map +0 -1
- package/dist/validators/date.d.ts.map +0 -1
- package/dist/validators/discriminated-union.d.ts.map +0 -1
- package/dist/validators/enum.d.ts.map +0 -1
- package/dist/validators/file.d.ts.map +0 -1
- package/dist/validators/function.d.ts.map +0 -1
- package/dist/validators/hex.d.ts.map +0 -1
- package/dist/validators/index.d.ts.map +0 -1
- package/dist/validators/index.js.map +0 -1
- package/dist/validators/intersection.d.ts.map +0 -1
- package/dist/validators/json.d.ts.map +0 -1
- package/dist/validators/lazy.d.ts.map +0 -1
- package/dist/validators/literal.d.ts.map +0 -1
- package/dist/validators/map.d.ts.map +0 -1
- package/dist/validators/nan.d.ts.map +0 -1
- package/dist/validators/never.d.ts.map +0 -1
- package/dist/validators/null.d.ts.map +0 -1
- package/dist/validators/number.d.ts.map +0 -1
- package/dist/validators/object.d.ts.map +0 -1
- package/dist/validators/promise.d.ts.map +0 -1
- package/dist/validators/record.d.ts.map +0 -1
- package/dist/validators/set.d.ts.map +0 -1
- package/dist/validators/string-bool.d.ts.map +0 -1
- package/dist/validators/string-formats.d.ts.map +0 -1
- package/dist/validators/string.d.ts.map +0 -1
- package/dist/validators/symbol.d.ts.map +0 -1
- package/dist/validators/template-literal.d.ts.map +0 -1
- package/dist/validators/tuple.d.ts.map +0 -1
- package/dist/validators/uint8array.d.ts.map +0 -1
- package/dist/validators/undefined.d.ts.map +0 -1
- package/dist/validators/union.d.ts.map +0 -1
- package/dist/validators/unknown.d.ts.map +0 -1
- package/dist/validators/void.d.ts.map +0 -1
- package/dist/validators/xor.d.ts.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,195 +1,63 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
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';
|
|
12
56
|
export { createEmitter, createEventBus, withEmitter } from './compat/emitter.js';
|
|
13
57
|
export { createVldKernel, definePlugin, getVldKernel, resetVldKernel, usePlugin } from './kernel.js';
|
|
14
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';
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
* VLD Logger
|
|
18
|
-
*
|
|
19
|
-
* This module provides a debug logging system for VLD,
|
|
20
|
-
* compatible with @oxog/log when available.
|
|
21
|
-
*/
|
|
22
|
-
/**
|
|
23
|
-
* Log level priorities (lower = more verbose)
|
|
24
|
-
*/
|
|
25
|
-
const LOG_LEVEL_PRIORITY = {
|
|
26
|
-
debug: 0,
|
|
27
|
-
info: 1,
|
|
28
|
-
warn: 2,
|
|
29
|
-
error: 3,
|
|
30
|
-
silent: 4
|
|
31
|
-
};
|
|
32
|
-
/**
|
|
33
|
-
* ANSI color codes for terminal output
|
|
34
|
-
*/
|
|
35
|
-
const COLORS = {
|
|
36
|
-
reset: '\x1b[0m',
|
|
37
|
-
dim: '\x1b[2m',
|
|
38
|
-
red: '\x1b[31m',
|
|
39
|
-
yellow: '\x1b[33m',
|
|
40
|
-
blue: '\x1b[34m',
|
|
41
|
-
cyan: '\x1b[36m',
|
|
42
|
-
gray: '\x1b[90m'
|
|
43
|
-
};
|
|
44
|
-
/**
|
|
45
|
-
* Level colors
|
|
46
|
-
*/
|
|
47
|
-
const LEVEL_COLORS = {
|
|
48
|
-
debug: COLORS.gray,
|
|
49
|
-
info: COLORS.blue,
|
|
50
|
-
warn: COLORS.yellow,
|
|
51
|
-
error: COLORS.red
|
|
52
|
-
};
|
|
53
|
-
/**
|
|
54
|
-
* Level labels
|
|
55
|
-
*/
|
|
56
|
-
const LEVEL_LABELS = {
|
|
57
|
-
debug: 'DEBUG',
|
|
58
|
-
info: 'INFO ',
|
|
59
|
-
warn: 'WARN ',
|
|
60
|
-
error: 'ERROR'
|
|
61
|
-
};
|
|
62
|
-
/**
|
|
63
|
-
* Default log handler
|
|
64
|
-
*/
|
|
65
|
-
function createDefaultHandler(options) {
|
|
66
|
-
const colored = options.colored ?? true;
|
|
67
|
-
const timestamps = options.timestamps ?? true;
|
|
68
|
-
return (entry) => {
|
|
69
|
-
const parts = [];
|
|
70
|
-
// Timestamp
|
|
71
|
-
if (timestamps) {
|
|
72
|
-
const time = entry.timestamp.toISOString().slice(11, 23);
|
|
73
|
-
parts.push(colored ? `${COLORS.dim}${time}${COLORS.reset}` : time);
|
|
74
|
-
}
|
|
75
|
-
// Level
|
|
76
|
-
const levelLabel = LEVEL_LABELS[entry.level];
|
|
77
|
-
const levelColor = LEVEL_COLORS[entry.level];
|
|
78
|
-
parts.push(colored ? `${levelColor}${levelLabel}${COLORS.reset}` : levelLabel);
|
|
79
|
-
// Name
|
|
80
|
-
parts.push(colored ? `${COLORS.cyan}[${entry.name}]${COLORS.reset}` : `[${entry.name}]`);
|
|
81
|
-
// Message
|
|
82
|
-
parts.push(entry.message);
|
|
83
|
-
// Output
|
|
84
|
-
const output = parts.join(' ');
|
|
85
|
-
// Use appropriate console method
|
|
86
|
-
switch (entry.level) {
|
|
87
|
-
case 'debug':
|
|
88
|
-
console.debug(output, entry.data !== undefined ? entry.data : '');
|
|
89
|
-
break;
|
|
90
|
-
case 'info':
|
|
91
|
-
console.info(output, entry.data !== undefined ? entry.data : '');
|
|
92
|
-
break;
|
|
93
|
-
case 'warn':
|
|
94
|
-
console.warn(output, entry.data !== undefined ? entry.data : '');
|
|
95
|
-
break;
|
|
96
|
-
case 'error':
|
|
97
|
-
console.error(output, entry.data !== undefined ? entry.data : '');
|
|
98
|
-
break;
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Create a logger instance
|
|
104
|
-
*/
|
|
105
|
-
function createLogger(options = {}) {
|
|
106
|
-
const name = options.name ?? 'vld';
|
|
107
|
-
let level = options.level ?? 'warn';
|
|
108
|
-
const handler = options.handler ?? createDefaultHandler(options);
|
|
109
|
-
const log = (logLevel, message, data) => {
|
|
110
|
-
if (LOG_LEVEL_PRIORITY[logLevel] < LOG_LEVEL_PRIORITY[level]) {
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
const entry = {
|
|
114
|
-
level: logLevel,
|
|
115
|
-
message,
|
|
116
|
-
data,
|
|
117
|
-
timestamp: new Date(),
|
|
118
|
-
name
|
|
119
|
-
};
|
|
120
|
-
handler(entry);
|
|
121
|
-
};
|
|
122
|
-
const logger = {
|
|
123
|
-
debug: (message, data) => log('debug', message, data),
|
|
124
|
-
info: (message, data) => log('info', message, data),
|
|
125
|
-
warn: (message, data) => log('warn', message, data),
|
|
126
|
-
error: (message, data) => log('error', message, data),
|
|
127
|
-
isLevelEnabled: (checkLevel) => LOG_LEVEL_PRIORITY[checkLevel] >= LOG_LEVEL_PRIORITY[level],
|
|
128
|
-
setLevel: (newLevel) => {
|
|
129
|
-
level = newLevel;
|
|
130
|
-
},
|
|
131
|
-
getLevel: () => level,
|
|
132
|
-
child: (childName) => createLogger({
|
|
133
|
-
...options,
|
|
134
|
-
name: `${name}:${childName}`
|
|
135
|
-
})
|
|
136
|
-
};
|
|
137
|
-
return logger;
|
|
138
|
-
}
|
|
139
|
-
// ============================================
|
|
140
|
-
// Global Logger Management
|
|
141
|
-
// ============================================
|
|
142
|
-
let globalLogger = null;
|
|
143
|
-
/**
|
|
144
|
-
* Initialize the global VLD logger
|
|
145
|
-
*/
|
|
146
|
-
function initLogger(options) {
|
|
147
|
-
globalLogger = createLogger({
|
|
148
|
-
name: 'vld',
|
|
149
|
-
...options
|
|
150
|
-
});
|
|
151
|
-
return globalLogger;
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* Get the global VLD logger
|
|
155
|
-
* Returns null if not initialized
|
|
156
|
-
*/
|
|
157
|
-
function getLogger() {
|
|
158
|
-
return globalLogger;
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Set log level for the global logger
|
|
162
|
-
*/
|
|
163
|
-
function setLogLevel(level) {
|
|
164
|
-
if (globalLogger) {
|
|
165
|
-
globalLogger.setLevel(level);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Enable debug mode for VLD
|
|
170
|
-
*/
|
|
171
|
-
function enableDebug() {
|
|
172
|
-
if (!globalLogger) {
|
|
173
|
-
initLogger({ level: 'debug' });
|
|
174
|
-
}
|
|
175
|
-
else {
|
|
176
|
-
globalLogger.setLevel('debug');
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* Disable all VLD logging
|
|
181
|
-
*/
|
|
182
|
-
function disableLogging() {
|
|
183
|
-
if (globalLogger) {
|
|
184
|
-
globalLogger.setLevel('silent');
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* Create a no-op logger for testing
|
|
189
|
-
*/
|
|
190
|
-
function createNoOpLogger() {
|
|
191
|
-
return createLogger({ level: 'silent' });
|
|
192
|
-
}
|
|
59
|
+
import { V as VldError } from './chunks/errors-core-BeiFUtZM.js';
|
|
60
|
+
export { getLocale, getMessages, getSupportedLocales, isLocaleLoaded, isLocaleSupported, registerLocale, setLocale } from './locales/runtime.js';
|
|
193
61
|
|
|
194
62
|
/**
|
|
195
63
|
* JSON Schema support for VLD validators
|
|
@@ -202,7 +70,22 @@ function createNoOpLogger() {
|
|
|
202
70
|
* @returns JSON Schema definition
|
|
203
71
|
*/
|
|
204
72
|
function toJSONSchema(schema, options = {}) {
|
|
205
|
-
|
|
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;
|
|
206
89
|
}
|
|
207
90
|
/**
|
|
208
91
|
* Convert a JSON Schema to a VLD schema
|
|
@@ -212,98 +95,184 @@ function toJSONSchema(schema, options = {}) {
|
|
|
212
95
|
function fromJSONSchema(json) {
|
|
213
96
|
return jsonSchemaToVLD(json);
|
|
214
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
|
+
}
|
|
215
175
|
/**
|
|
216
176
|
* Internal function to convert VLD schema to JSON Schema
|
|
217
177
|
*/
|
|
218
178
|
function schemaToJSONSchema(schema, options) {
|
|
179
|
+
const target = options.target || 'draft-07';
|
|
180
|
+
const schemaAny = schema;
|
|
181
|
+
const validatorType = schema.validatorType;
|
|
219
182
|
// Handle primitives
|
|
220
|
-
if (schema.constructor.name === 'VldString') {
|
|
221
|
-
return buildStringSchema();
|
|
183
|
+
if (schema.constructor.name === 'VldString' || validatorType === VLD_VALIDATOR_TYPES.STRING) {
|
|
184
|
+
return withMetadata(schema, buildStringSchema(target, schema), options);
|
|
222
185
|
}
|
|
223
|
-
if (schema.constructor.name === 'VldNumber') {
|
|
224
|
-
return buildNumberSchema(schema);
|
|
186
|
+
if (schema.constructor.name === 'VldNumber' || validatorType === VLD_VALIDATOR_TYPES.NUMBER) {
|
|
187
|
+
return withMetadata(schema, buildNumberSchema(schema), options);
|
|
225
188
|
}
|
|
226
|
-
if (schema.constructor.name === 'VldBoolean') {
|
|
227
|
-
return { type: 'boolean' };
|
|
189
|
+
if (schema.constructor.name === 'VldBoolean' || validatorType === VLD_VALIDATOR_TYPES.BOOLEAN) {
|
|
190
|
+
return withMetadata(schema, { type: 'boolean' }, options);
|
|
228
191
|
}
|
|
229
|
-
if (schema.constructor.name === 'VldBigInt') {
|
|
230
|
-
return
|
|
192
|
+
if (schema.constructor.name === 'VldBigInt' || validatorType === VLD_VALIDATOR_TYPES.BIGINT) {
|
|
193
|
+
return withMetadata(schema, buildBigIntSchema(schema), options);
|
|
231
194
|
}
|
|
232
|
-
if (schema.constructor.name === 'VldDate') {
|
|
233
|
-
return
|
|
195
|
+
if (schema.constructor.name === 'VldDate' || validatorType === VLD_VALIDATOR_TYPES.DATE) {
|
|
196
|
+
return withMetadata(schema, buildDateSchema(schema), options);
|
|
234
197
|
}
|
|
235
|
-
if (schema.constructor.name === 'VldArray') {
|
|
236
|
-
return buildArraySchema(schema, options);
|
|
198
|
+
if (schema.constructor.name === 'VldArray' || validatorType === VLD_VALIDATOR_TYPES.ARRAY) {
|
|
199
|
+
return withMetadata(schema, buildArraySchema(schema, options), options);
|
|
237
200
|
}
|
|
238
|
-
if (schema.constructor.name === 'VldObject') {
|
|
239
|
-
return buildObjectSchema(schema, options);
|
|
201
|
+
if (schema.constructor.name === 'VldObject' || validatorType === VLD_VALIDATOR_TYPES.OBJECT) {
|
|
202
|
+
return withMetadata(schema, buildObjectSchema(schema, options), options);
|
|
240
203
|
}
|
|
241
204
|
// Handle union types
|
|
242
205
|
if (schema.constructor.name === 'VldUnion') {
|
|
243
|
-
return buildUnionSchema(schema, options);
|
|
206
|
+
return withMetadata(schema, buildUnionSchema(schema, options), options);
|
|
244
207
|
}
|
|
245
208
|
// Handle literal types
|
|
246
209
|
if (schema.constructor.name === 'VldLiteral') {
|
|
247
|
-
return buildLiteralSchema(schema);
|
|
210
|
+
return withMetadata(schema, buildLiteralSchema(schema), options);
|
|
248
211
|
}
|
|
249
212
|
if (schema.constructor.name === 'VldEnum') {
|
|
250
|
-
return buildEnumSchema(schema);
|
|
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);
|
|
251
217
|
}
|
|
252
|
-
if (schema.constructor.name === '
|
|
253
|
-
return
|
|
218
|
+
if (schema.constructor.name === 'VldMap' || validatorType === VLD_VALIDATOR_TYPES.MAP) {
|
|
219
|
+
return withMetadata(schema, buildMapSchema(schema, options), options);
|
|
254
220
|
}
|
|
255
|
-
if (schema.constructor.name === '
|
|
256
|
-
return
|
|
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);
|
|
257
226
|
}
|
|
258
227
|
if (schema.constructor.name === 'VldIntersection') {
|
|
259
|
-
return buildIntersectionSchema(schema, options);
|
|
228
|
+
return withMetadata(schema, buildIntersectionSchema(schema, options), options);
|
|
260
229
|
}
|
|
261
230
|
if (schema.constructor.name === 'VldOptional') {
|
|
262
|
-
return buildOptionalSchema(schema, options);
|
|
231
|
+
return withMetadata(schema, buildOptionalSchema(schema, options), options);
|
|
263
232
|
}
|
|
264
233
|
if (schema.constructor.name === 'VldNullable') {
|
|
265
|
-
return buildNullableSchema(schema, options);
|
|
234
|
+
return withMetadata(schema, buildNullableSchema(schema, options), options);
|
|
266
235
|
}
|
|
267
236
|
if (schema.constructor.name === 'VldNullish') {
|
|
268
|
-
return buildNullishSchema(schema, options);
|
|
237
|
+
return withMetadata(schema, buildNullishSchema(schema, options), options);
|
|
269
238
|
}
|
|
270
239
|
if (schema.constructor.name === 'VldExactOptional') {
|
|
271
|
-
return buildExactOptionalSchema(schema, options);
|
|
240
|
+
return withMetadata(schema, buildExactOptionalSchema(schema, options), options);
|
|
272
241
|
}
|
|
273
242
|
if (schema.constructor.name === 'VldLazy') {
|
|
274
|
-
return { type: 'object' }; // Placeholder for recursive schemas
|
|
243
|
+
return withMetadata(schema, { type: 'object' }, options); // Placeholder for recursive schemas
|
|
275
244
|
}
|
|
276
245
|
if (schema.constructor.name === 'VldJson') {
|
|
277
|
-
return {}; // Any JSON
|
|
246
|
+
return withMetadata(schema, {}, options); // Any JSON
|
|
278
247
|
}
|
|
279
248
|
if (schema.constructor.name === 'VldAny') {
|
|
280
|
-
return {}; // JSON Schema true
|
|
249
|
+
return withMetadata(schema, {}, options); // JSON Schema true
|
|
281
250
|
}
|
|
282
251
|
if (schema.constructor.name === 'VldUnknown') {
|
|
283
|
-
return {}; // JSON Schema true
|
|
252
|
+
return withMetadata(schema, {}, options); // JSON Schema true
|
|
284
253
|
}
|
|
285
254
|
if (schema.constructor.name === 'VldNever') {
|
|
286
|
-
return { not: {} }; // JSON Schema false
|
|
255
|
+
return withMetadata(schema, { not: {} }, options); // JSON Schema false
|
|
287
256
|
}
|
|
288
257
|
if (schema.constructor.name === 'VldNull') {
|
|
289
|
-
return { type: 'null' };
|
|
258
|
+
return withMetadata(schema, { type: 'null' }, options);
|
|
290
259
|
}
|
|
291
260
|
if (schema.constructor.name === 'VldUndefined') {
|
|
292
|
-
return { not: {} }; // Undefined can't be represented in JSON Schema
|
|
261
|
+
return withMetadata(schema, { not: {} }, options); // Undefined can't be represented in JSON Schema
|
|
293
262
|
}
|
|
294
263
|
if (schema.constructor.name === 'VldNan') {
|
|
295
|
-
return { type: 'number', not: {} }; // NaN is a number type constraint
|
|
264
|
+
return withMetadata(schema, { type: 'number', not: {} }, options); // NaN is a number type constraint
|
|
296
265
|
}
|
|
297
266
|
if (schema.constructor.name === 'VldVoid') {
|
|
298
|
-
return { not: {} }; // Void/undefined can't be represented
|
|
267
|
+
return withMetadata(schema, { not: {} }, options); // Void/undefined can't be represented
|
|
299
268
|
}
|
|
300
269
|
// Handle branded types - unwrap and continue
|
|
301
270
|
if (schema.constructor.name === 'VldBrand') {
|
|
302
|
-
return schemaToJSONSchema(
|
|
271
|
+
return withMetadata(schema, schemaToJSONSchema(schemaAny.baseValidator, options), options);
|
|
303
272
|
}
|
|
304
273
|
// Handle readonly types
|
|
305
274
|
if (schema.constructor.name === 'VldReadonly') {
|
|
306
|
-
return schemaToJSONSchema(
|
|
275
|
+
return withMetadata(schema, schemaToJSONSchema(schemaAny.baseValidator, options), options);
|
|
307
276
|
}
|
|
308
277
|
// Handle transform types
|
|
309
278
|
if (schema.constructor.name === 'VldTransform') {
|
|
@@ -311,64 +280,115 @@ function schemaToJSONSchema(schema, options) {
|
|
|
311
280
|
}
|
|
312
281
|
// Handle meta types - unwrap metadata
|
|
313
282
|
if (schema.constructor.name === 'VldMeta') {
|
|
314
|
-
const
|
|
315
|
-
|
|
316
|
-
if (options.includeMetadata !== false && metaSchema.metadata) {
|
|
317
|
-
const meta = metaSchema.metadata;
|
|
318
|
-
if (meta.title)
|
|
319
|
-
result.title = meta.title;
|
|
320
|
-
if (meta.description)
|
|
321
|
-
result.description = meta.description;
|
|
322
|
-
if (meta.examples && options.includeExamples)
|
|
323
|
-
result.examples = meta.examples;
|
|
324
|
-
if (meta.default !== undefined)
|
|
325
|
-
result.default = meta.default;
|
|
326
|
-
if (meta.deprecated)
|
|
327
|
-
result.deprecated = true;
|
|
328
|
-
if (meta.readOnly)
|
|
329
|
-
result.readOnly = true;
|
|
330
|
-
if (meta.writeOnly)
|
|
331
|
-
result.writeOnly = true;
|
|
332
|
-
}
|
|
333
|
-
return result;
|
|
283
|
+
const result = schemaToJSONSchema(schemaAny.baseValidator, options);
|
|
284
|
+
return withMetadata(schema, result, options);
|
|
334
285
|
}
|
|
335
286
|
// Handle refine/superRefine types
|
|
336
287
|
if (schema.constructor.name === 'VldRefine' || schema.constructor.name === 'VldSuperRefine') {
|
|
337
|
-
return
|
|
288
|
+
return withMetadata(schema, schemaToJSONSchema(unwrapInner(schemaAny), options), options);
|
|
338
289
|
}
|
|
339
290
|
// Handle pipe types
|
|
340
291
|
if (schema.constructor.name === 'VldPipe') {
|
|
341
|
-
return schemaToJSONSchema(
|
|
292
|
+
return withMetadata(schema, schemaToJSONSchema(schemaAny._next || schemaAny.second, options), options);
|
|
342
293
|
}
|
|
343
294
|
// Handle default/catch types
|
|
344
295
|
if (schema.constructor.name === 'VldDefault' || schema.constructor.name === 'VldCatch') {
|
|
345
|
-
return
|
|
296
|
+
return withMetadata(schema, schemaToJSONSchema(unwrapInner(schemaAny), options), options);
|
|
346
297
|
}
|
|
347
298
|
// Handle preprocess types
|
|
348
299
|
if (schema.constructor.name === 'VldPreprocess') {
|
|
349
|
-
return schemaToJSONSchema(
|
|
300
|
+
return withMetadata(schema, schemaToJSONSchema(schemaAny._schema, options), options);
|
|
350
301
|
}
|
|
351
302
|
// Handle string format validators
|
|
352
303
|
if (schema.constructor.name === 'VldStringFormat') {
|
|
353
304
|
const formatSchema = schema;
|
|
354
|
-
return { type: 'string', format: formatSchema._format };
|
|
305
|
+
return withMetadata(schema, { type: 'string', format: formatSchema._format }, options);
|
|
355
306
|
}
|
|
356
307
|
// Fallback for unknown types
|
|
357
|
-
return {};
|
|
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;
|
|
358
348
|
}
|
|
359
349
|
/**
|
|
360
350
|
* Build string JSON Schema
|
|
361
351
|
*/
|
|
362
|
-
function buildStringSchema(_target) {
|
|
363
|
-
|
|
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;
|
|
364
370
|
}
|
|
365
371
|
/**
|
|
366
372
|
* Build number JSON Schema from VLD number schema
|
|
367
373
|
*/
|
|
368
374
|
function buildNumberSchema(schema, _target) {
|
|
369
375
|
const config = schema.config || {};
|
|
376
|
+
const hints = config.jsonSchema || {};
|
|
370
377
|
const checks = config.checks || [];
|
|
371
|
-
const result = { type: 'number' };
|
|
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
|
+
}
|
|
372
392
|
for (const check of checks) {
|
|
373
393
|
// Try to extract constraints from closures
|
|
374
394
|
const checkStr = check.toString();
|
|
@@ -388,32 +408,85 @@ function buildNumberSchema(schema, _target) {
|
|
|
388
408
|
}
|
|
389
409
|
return result;
|
|
390
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
|
+
}
|
|
391
453
|
/**
|
|
392
454
|
* Build array JSON Schema
|
|
393
455
|
*/
|
|
394
456
|
function buildArraySchema(schema, options) {
|
|
395
|
-
const inner = schema._item || schema._inner;
|
|
457
|
+
const inner = schema._item || schema._inner || schema.config?.itemValidator;
|
|
458
|
+
const result = { type: 'array' };
|
|
396
459
|
if (inner) {
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
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;
|
|
401
471
|
}
|
|
402
|
-
|
|
472
|
+
if (schema.config?.unique)
|
|
473
|
+
result.uniqueItems = true;
|
|
474
|
+
return result;
|
|
403
475
|
}
|
|
404
476
|
/**
|
|
405
477
|
* Build object JSON Schema
|
|
406
478
|
*/
|
|
407
479
|
function buildObjectSchema(schema, options) {
|
|
408
|
-
const shape = schema._shape || schema.shape;
|
|
480
|
+
const shape = schema._shape || schema.shape || schema.config?.shape;
|
|
409
481
|
if (!shape)
|
|
410
482
|
return { type: 'object' };
|
|
411
483
|
const properties = {};
|
|
412
484
|
const required = [];
|
|
413
485
|
for (const [key, value] of Object.entries(shape)) {
|
|
414
|
-
|
|
486
|
+
const child = value;
|
|
487
|
+
properties[key] = schemaToJSONSchema(child, options);
|
|
415
488
|
// VLD objects require all keys by default
|
|
416
|
-
if (
|
|
489
|
+
if (!isOptionalLike(child)) {
|
|
417
490
|
required.push(key);
|
|
418
491
|
}
|
|
419
492
|
}
|
|
@@ -425,28 +498,40 @@ function buildObjectSchema(schema, options) {
|
|
|
425
498
|
result.required = required;
|
|
426
499
|
}
|
|
427
500
|
// Handle passthrough mode
|
|
428
|
-
if (schema._passthrough || schema._loose) {
|
|
501
|
+
if (schema._passthrough || schema._loose || schema.config?.passthrough) {
|
|
429
502
|
result.additionalProperties = true;
|
|
430
503
|
}
|
|
431
|
-
else if (schema._strict) {
|
|
504
|
+
else if (schema._strict || schema.config?.strict) {
|
|
432
505
|
result.additionalProperties = false;
|
|
433
506
|
}
|
|
507
|
+
else if (schema.config?.catchall) {
|
|
508
|
+
result.additionalProperties = schemaToJSONSchema(schema.config.catchall, options);
|
|
509
|
+
}
|
|
434
510
|
return result;
|
|
435
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
|
+
}
|
|
436
521
|
/**
|
|
437
522
|
* Build union JSON Schema
|
|
438
523
|
*/
|
|
439
524
|
function buildUnionSchema(schema, options) {
|
|
440
|
-
const validators = schema._validators || schema._options || [];
|
|
525
|
+
const validators = schema._validators || schema._options || schema.validators || [];
|
|
441
526
|
return {
|
|
442
|
-
anyOf: validators.map((v) =>
|
|
527
|
+
anyOf: validators.map((v) => schemaToJSONSchema(v, options))
|
|
443
528
|
};
|
|
444
529
|
}
|
|
445
530
|
/**
|
|
446
531
|
* Build literal JSON Schema
|
|
447
532
|
*/
|
|
448
533
|
function buildLiteralSchema(schema) {
|
|
449
|
-
const value = schema._value
|
|
534
|
+
const value = schema._literal ?? schema.literal ?? schema._value ?? schema.value;
|
|
450
535
|
if (value === null)
|
|
451
536
|
return { type: 'null' };
|
|
452
537
|
if (typeof value === 'string')
|
|
@@ -471,26 +556,60 @@ function buildEnumSchema(schema) {
|
|
|
471
556
|
* Build record JSON Schema
|
|
472
557
|
*/
|
|
473
558
|
function buildRecordSchema(schema, options) {
|
|
474
|
-
const valueValidator = schema._value || schema._inner;
|
|
559
|
+
const valueValidator = schema.valueSchema || schema._value || schema._inner || schema.valueValidator;
|
|
475
560
|
if (valueValidator) {
|
|
476
561
|
return {
|
|
477
562
|
type: 'object',
|
|
478
|
-
additionalProperties:
|
|
563
|
+
additionalProperties: schemaToJSONSchema(valueValidator, options)
|
|
479
564
|
};
|
|
480
565
|
}
|
|
481
566
|
return { type: 'object' };
|
|
482
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
|
+
}
|
|
483
602
|
/**
|
|
484
603
|
* Build tuple JSON Schema
|
|
485
604
|
*/
|
|
486
605
|
function buildTupleSchema(schema, options) {
|
|
487
|
-
const items = schema._items || schema.
|
|
606
|
+
const items = schema.items || schema._items || schema.validators;
|
|
488
607
|
if (!items || !Array.isArray(items)) {
|
|
489
608
|
return { type: 'array' };
|
|
490
609
|
}
|
|
491
610
|
return {
|
|
492
611
|
type: 'array',
|
|
493
|
-
items: items.map((item) =>
|
|
612
|
+
items: items.map((item) => schemaToJSONSchema(item, options)),
|
|
494
613
|
minItems: items.length,
|
|
495
614
|
maxItems: items.length
|
|
496
615
|
};
|
|
@@ -503,23 +622,23 @@ function buildIntersectionSchema(schema, options) {
|
|
|
503
622
|
const second = schema._second || schema.second;
|
|
504
623
|
const schemas = [];
|
|
505
624
|
if (first)
|
|
506
|
-
schemas.push(
|
|
625
|
+
schemas.push(schemaToJSONSchema(first, options));
|
|
507
626
|
if (second)
|
|
508
|
-
schemas.push(
|
|
627
|
+
schemas.push(schemaToJSONSchema(second, options));
|
|
509
628
|
if (schemas.length === 0)
|
|
510
629
|
return {};
|
|
511
630
|
if (schemas.length === 1)
|
|
512
|
-
return schemas[0];
|
|
631
|
+
return schemas[0] ?? {};
|
|
513
632
|
return { allOf: schemas };
|
|
514
633
|
}
|
|
515
634
|
/**
|
|
516
635
|
* Build optional JSON Schema
|
|
517
636
|
*/
|
|
518
637
|
function buildOptionalSchema(schema, options) {
|
|
519
|
-
const inner = schema
|
|
638
|
+
const inner = unwrapInner(schema);
|
|
520
639
|
if (!inner)
|
|
521
640
|
return {};
|
|
522
|
-
const result =
|
|
641
|
+
const result = schemaToJSONSchema(inner, options);
|
|
523
642
|
// Remove from required array - but we don't track required here
|
|
524
643
|
return result;
|
|
525
644
|
}
|
|
@@ -527,10 +646,10 @@ function buildOptionalSchema(schema, options) {
|
|
|
527
646
|
* Build nullable JSON Schema
|
|
528
647
|
*/
|
|
529
648
|
function buildNullableSchema(schema, options) {
|
|
530
|
-
const inner = schema
|
|
649
|
+
const inner = unwrapInner(schema);
|
|
531
650
|
if (!inner)
|
|
532
651
|
return { type: 'null' };
|
|
533
|
-
const result =
|
|
652
|
+
const result = schemaToJSONSchema(inner, options);
|
|
534
653
|
if (typeof result.type === 'string') {
|
|
535
654
|
return { type: [result.type, 'null'] };
|
|
536
655
|
}
|
|
@@ -546,37 +665,31 @@ function buildNullableSchema(schema, options) {
|
|
|
546
665
|
* Build nullish JSON Schema
|
|
547
666
|
*/
|
|
548
667
|
function buildNullishSchema(schema, options) {
|
|
549
|
-
const inner = schema
|
|
668
|
+
const inner = unwrapInner(schema);
|
|
550
669
|
if (!inner)
|
|
551
670
|
return {};
|
|
552
|
-
|
|
671
|
+
const result = schemaToJSONSchema(inner, options);
|
|
672
|
+
if (typeof result.type === 'string') {
|
|
673
|
+
return { ...result, type: [result.type, 'null'] };
|
|
674
|
+
}
|
|
675
|
+
return result;
|
|
553
676
|
}
|
|
554
677
|
/**
|
|
555
678
|
* Build exactOptional JSON Schema
|
|
556
679
|
*/
|
|
557
680
|
function buildExactOptionalSchema(schema, options) {
|
|
558
|
-
const inner = schema
|
|
681
|
+
const inner = unwrapInner(schema);
|
|
559
682
|
if (!inner)
|
|
560
683
|
return {};
|
|
561
|
-
return
|
|
684
|
+
return schemaToJSONSchema(inner, options);
|
|
562
685
|
}
|
|
563
686
|
/**
|
|
564
687
|
* Internal function to convert JSON Schema to VLD schema
|
|
565
688
|
*/
|
|
566
689
|
function jsonSchemaToVLD(json) {
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
const VldNumber = require('../validators/number').VldNumber;
|
|
571
|
-
const VldBoolean = require('../validators/boolean').VldBoolean;
|
|
572
|
-
const VldObject = require('../validators/object').VldObject;
|
|
573
|
-
const VldArray = require('../validators/array').VldArray;
|
|
574
|
-
const VldUnion = require('../validators/union').VldUnion;
|
|
575
|
-
const VldLiteral = require('../validators/literal').VldLiteral;
|
|
576
|
-
const VldEnum = require('../validators/enum').VldEnum;
|
|
577
|
-
const VldNull = require('../validators/null').VldNull;
|
|
578
|
-
const VldAny = require('../validators/any').VldAny;
|
|
579
|
-
const VldRecord = require('../validators/record').VldRecord;
|
|
690
|
+
return applyJSONSchemaMetadata(jsonSchemaToVLDInner(json), json);
|
|
691
|
+
}
|
|
692
|
+
function jsonSchemaToVLDInner(json) {
|
|
580
693
|
// Handle $ref
|
|
581
694
|
if (json.$ref) {
|
|
582
695
|
// For now, return any - full $ref handling requires registry
|
|
@@ -594,10 +707,13 @@ function jsonSchemaToVLD(json) {
|
|
|
594
707
|
// Handle allOf (intersection)
|
|
595
708
|
if (json.allOf) {
|
|
596
709
|
// For intersection, we'd need VldIntersection
|
|
597
|
-
const
|
|
710
|
+
const firstSchema = json.allOf[0];
|
|
711
|
+
if (firstSchema === undefined) {
|
|
712
|
+
return VldAny.create();
|
|
713
|
+
}
|
|
714
|
+
const first = jsonSchemaToVLD(firstSchema);
|
|
598
715
|
if (json.allOf.length > 1) {
|
|
599
716
|
const second = jsonSchemaToVLD({ allOf: json.allOf.slice(1) });
|
|
600
|
-
const VldIntersection = require('../validators/intersection').VldIntersection;
|
|
601
717
|
return VldIntersection.create(first, second);
|
|
602
718
|
}
|
|
603
719
|
return first;
|
|
@@ -616,15 +732,17 @@ function jsonSchemaToVLD(json) {
|
|
|
616
732
|
return VldEnum.create(json.enum);
|
|
617
733
|
}
|
|
618
734
|
// Handle type
|
|
619
|
-
const type = json.type
|
|
735
|
+
const type = json.nullable && typeof json.type === 'string'
|
|
736
|
+
? [json.type, 'null']
|
|
737
|
+
: json.type;
|
|
620
738
|
if (type === 'string' || type === undefined) {
|
|
621
|
-
|
|
622
|
-
if (json.minLength)
|
|
623
|
-
s
|
|
624
|
-
if (json.maxLength)
|
|
625
|
-
s
|
|
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);
|
|
626
744
|
if (json.pattern)
|
|
627
|
-
s
|
|
745
|
+
s = s.regex(new RegExp(json.pattern));
|
|
628
746
|
if (json.format) {
|
|
629
747
|
// Map JSON Schema formats to VLD validators
|
|
630
748
|
switch (json.format) {
|
|
@@ -634,39 +752,48 @@ function jsonSchemaToVLD(json) {
|
|
|
634
752
|
// Would need DateTime validator
|
|
635
753
|
break;
|
|
636
754
|
case 'email':
|
|
637
|
-
|
|
638
|
-
return email();
|
|
755
|
+
return email$1();
|
|
639
756
|
case 'uri':
|
|
640
757
|
case 'uri-reference':
|
|
641
|
-
|
|
642
|
-
return httpUrl();
|
|
758
|
+
return httpUrl$1();
|
|
643
759
|
case 'uuid':
|
|
644
|
-
|
|
645
|
-
return uuid();
|
|
760
|
+
return uuid$1();
|
|
646
761
|
}
|
|
647
762
|
}
|
|
648
763
|
return s;
|
|
649
764
|
}
|
|
650
765
|
if (type === 'number' || type === 'integer') {
|
|
651
|
-
|
|
766
|
+
let n = VldNumber.create();
|
|
652
767
|
if (type === 'integer')
|
|
653
|
-
n.int();
|
|
768
|
+
n = n.int();
|
|
654
769
|
if (json.minimum !== undefined)
|
|
655
|
-
n.min(json.minimum);
|
|
770
|
+
n = n.min(json.minimum);
|
|
656
771
|
if (json.maximum !== undefined)
|
|
657
|
-
n.max(json.maximum);
|
|
658
|
-
if (json.exclusiveMinimum
|
|
659
|
-
n.gt(json.exclusiveMinimum);
|
|
660
|
-
if (json.exclusiveMaximum
|
|
661
|
-
n.lt(json.exclusiveMaximum);
|
|
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);
|
|
662
781
|
if (json.multipleOf !== undefined)
|
|
663
|
-
n.multipleOf(json.multipleOf);
|
|
782
|
+
n = n.multipleOf(json.multipleOf);
|
|
664
783
|
return n;
|
|
665
784
|
}
|
|
666
785
|
if (type === 'boolean') {
|
|
667
786
|
return VldBoolean.create();
|
|
668
787
|
}
|
|
669
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
|
+
}
|
|
670
797
|
if (json.items && !Array.isArray(json.items)) {
|
|
671
798
|
return VldArray.create(jsonSchemaToVLD(json.items));
|
|
672
799
|
}
|
|
@@ -675,17 +802,12 @@ function jsonSchemaToVLD(json) {
|
|
|
675
802
|
if (type === 'object') {
|
|
676
803
|
if (json.properties) {
|
|
677
804
|
const shape = {};
|
|
678
|
-
const required = json.required || [];
|
|
805
|
+
const required = new Set(json.required || []);
|
|
679
806
|
for (const [key, propSchema] of Object.entries(json.properties)) {
|
|
680
|
-
|
|
807
|
+
const fieldSchema = jsonSchemaToVLD(propSchema);
|
|
808
|
+
shape[key] = required.has(key) ? fieldSchema : fieldSchema.optional();
|
|
681
809
|
}
|
|
682
810
|
let obj = VldObject.create(shape);
|
|
683
|
-
if (!required.length) {
|
|
684
|
-
// If no required fields, make all optional
|
|
685
|
-
for (const key of Object.keys(shape)) {
|
|
686
|
-
if (!required.includes(key)) ;
|
|
687
|
-
}
|
|
688
|
-
}
|
|
689
811
|
if (json.additionalProperties === false) {
|
|
690
812
|
obj = obj.strict();
|
|
691
813
|
}
|
|
@@ -695,7 +817,7 @@ function jsonSchemaToVLD(json) {
|
|
|
695
817
|
else if (json.additionalProperties) {
|
|
696
818
|
// additionalProperties is a schema
|
|
697
819
|
const valueSchema = jsonSchemaToVLD(json.additionalProperties);
|
|
698
|
-
|
|
820
|
+
return VldRecord.create(valueSchema);
|
|
699
821
|
}
|
|
700
822
|
return obj;
|
|
701
823
|
}
|
|
@@ -708,7 +830,7 @@ function jsonSchemaToVLD(json) {
|
|
|
708
830
|
if (Array.isArray(type)) {
|
|
709
831
|
// Union of types
|
|
710
832
|
const options = type.map((t) => {
|
|
711
|
-
return jsonSchemaToVLD({ ...json, type: t });
|
|
833
|
+
return jsonSchemaToVLD({ ...json, type: t, nullable: false });
|
|
712
834
|
});
|
|
713
835
|
if (options.length > 0) {
|
|
714
836
|
return VldUnion.create(...options);
|
|
@@ -717,6 +839,206 @@ function jsonSchemaToVLD(json) {
|
|
|
717
839
|
// Fallback to any
|
|
718
840
|
return VldAny.create();
|
|
719
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
|
+
}
|
|
720
1042
|
|
|
721
1043
|
/**
|
|
722
1044
|
* VLD - Fast, Type-Safe Validation Library
|
|
@@ -733,7 +1055,192 @@ function jsonSchemaToVLD(json) {
|
|
|
733
1055
|
* - Colored console output for better debugging
|
|
734
1056
|
* - Debug logging system
|
|
735
1057
|
*/
|
|
736
|
-
// Import
|
|
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
|
+
};
|
|
737
1244
|
/**
|
|
738
1245
|
* Main API object with factory methods for all validators
|
|
739
1246
|
*/
|
|
@@ -769,9 +1276,11 @@ const v = {
|
|
|
769
1276
|
intersection: (first, second) => VldIntersection.create(first, second),
|
|
770
1277
|
discriminatedUnion: (discriminator, ...options) => VldDiscriminatedUnion.create(discriminator, [...options]),
|
|
771
1278
|
xor: (...options) => VldXor.create([...options]),
|
|
1279
|
+
keyof: (schema) => schema.keyof(),
|
|
772
1280
|
// Literal and enum
|
|
773
1281
|
literal: (value) => VldLiteral.create(value),
|
|
774
1282
|
enum: (...values) => VldEnum.create(values),
|
|
1283
|
+
nativeEnum: (enumObject) => VldEnum.create(enumValuesFromNativeEnum(enumObject)),
|
|
775
1284
|
// Special validators
|
|
776
1285
|
any: () => VldAny.create(),
|
|
777
1286
|
unknown: () => VldUnknown.create(),
|
|
@@ -782,19 +1291,62 @@ const v = {
|
|
|
782
1291
|
nan: () => VldNan.create(),
|
|
783
1292
|
// NEVER constant - Zod 4 API parity for use in transforms
|
|
784
1293
|
NEVER: VldNever.create(),
|
|
1294
|
+
TimePrecision,
|
|
1295
|
+
ZodIssueCode,
|
|
1296
|
+
ZodFirstPartyTypeKind,
|
|
785
1297
|
// Utility validators
|
|
786
1298
|
optional: (validator) => VldOptional.create(validator),
|
|
787
1299
|
nullable: (validator) => VldNullable.create(validator),
|
|
788
1300
|
nullish: (validator) => VldNullish.create(validator),
|
|
789
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,
|
|
790
1342
|
// Recursive schemas
|
|
791
1343
|
lazy: (schemaGetter) => VldLazy.create(schemaGetter),
|
|
792
1344
|
// JSON validator
|
|
793
1345
|
json: (schema) => VldJson.create(schema),
|
|
794
1346
|
// Custom validator for type-safe user-defined schemas
|
|
795
|
-
custom: (options) => custom(options),
|
|
1347
|
+
custom: (options) => custom$1(options),
|
|
796
1348
|
// File validator for file uploads
|
|
797
|
-
file: () => file(),
|
|
1349
|
+
file: () => file$1(),
|
|
798
1350
|
// Function validator for function validation
|
|
799
1351
|
function: () => functionValidator(),
|
|
800
1352
|
// Preprocessing
|
|
@@ -808,48 +1360,175 @@ const v = {
|
|
|
808
1360
|
bigint: () => VldCoerceBigInt.create(),
|
|
809
1361
|
},
|
|
810
1362
|
// String format validators (Zod 4 parity)
|
|
811
|
-
email: (options) => email(options),
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
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),
|
|
831
1386
|
iso: {
|
|
832
|
-
date: () => iso.date(),
|
|
833
|
-
time: () => iso.time(),
|
|
834
|
-
dateTime: () => iso.dateTime(),
|
|
835
|
-
duration: () => iso.duration(),
|
|
1387
|
+
date: () => iso$1.date(),
|
|
1388
|
+
time: () => iso$1.time(),
|
|
1389
|
+
dateTime: () => iso$1.dateTime(),
|
|
1390
|
+
duration: () => iso$1.duration(),
|
|
836
1391
|
},
|
|
837
|
-
stringFormat: (name, validator) => stringFormat(name, validator),
|
|
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),
|
|
838
1426
|
// Zod v4 parity string formats
|
|
839
|
-
xid: () => xid(),
|
|
840
|
-
guid: () => guid(),
|
|
841
|
-
httpUrl: () => httpUrl(),
|
|
1427
|
+
xid: () => xid$1(),
|
|
1428
|
+
guid: () => guid$1(),
|
|
1429
|
+
httpUrl: () => httpUrl$1(),
|
|
1430
|
+
ksuid: () => ksuid$1(),
|
|
1431
|
+
regexes: REGEXES,
|
|
842
1432
|
// Template literal validator
|
|
843
|
-
templateLiteral: (...components) => templateLiteral(...components),
|
|
1433
|
+
templateLiteral: (...components) => templateLiteral$1(...components),
|
|
844
1434
|
// Codec validators (binary data validators)
|
|
845
1435
|
base64Bytes: () => VldBase64.create(),
|
|
846
1436
|
hexBytes: () => VldHex.create(),
|
|
847
1437
|
uint8Array: () => VldUint8Array.create(),
|
|
848
1438
|
// Codec factory
|
|
849
1439
|
codec: (inputValidator, outputValidator, transform) => VldCodec.create(inputValidator, outputValidator, transform),
|
|
1440
|
+
invertCodec: (codec) => codec.invert(),
|
|
850
1441
|
// Promise validator (Zod v4 parity)
|
|
851
|
-
promise: (inner) => promise(inner)
|
|
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
|
|
852
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;
|
|
853
1533
|
|
|
854
|
-
export { VldIntersection, createLogger, createNoOpLogger, v as default, disableLogging, enableDebug, fromJSONSchema, getLogger, initLogger, setLogLevel, toJSONSchema, v };
|
|
855
|
-
//# sourceMappingURL=index.js.map
|
|
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 };
|