@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
|
@@ -0,0 +1,887 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var registry = require('../registry.cjs');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Validator type constants for O(1) dispatch
|
|
7
|
+
* Used by VldObject to replace instanceof chains with Map lookups
|
|
8
|
+
*/
|
|
9
|
+
const VLD_VALIDATOR_TYPES = {
|
|
10
|
+
// Primitives
|
|
11
|
+
STRING: 'string',
|
|
12
|
+
STRING_FORMAT: 'stringFormat',
|
|
13
|
+
STRING_BOOL: 'stringBool',
|
|
14
|
+
NUMBER: 'number',
|
|
15
|
+
BOOLEAN: 'boolean',
|
|
16
|
+
DATE: 'date',
|
|
17
|
+
BIGINT: 'bigint',
|
|
18
|
+
UNDEFINED: 'undefined',
|
|
19
|
+
NULL: 'null',
|
|
20
|
+
UNKNOWN: 'unknown',
|
|
21
|
+
ANY: 'any',
|
|
22
|
+
VOID: 'void',
|
|
23
|
+
NEVER: 'never',
|
|
24
|
+
SYMBOL: 'symbol',
|
|
25
|
+
NAN: 'nan',
|
|
26
|
+
HEX: 'hex',
|
|
27
|
+
BASE64: 'base64',
|
|
28
|
+
UINT8_ARRAY: 'uint8Array',
|
|
29
|
+
// Coercion
|
|
30
|
+
COERCE_STRING: 'coerceString',
|
|
31
|
+
COERCE_NUMBER: 'coerceNumber',
|
|
32
|
+
COERCE_BOOLEAN: 'coerceBoolean',
|
|
33
|
+
COERCE_DATE: 'coerceDate',
|
|
34
|
+
COERCE_BIGINT: 'coerceBigint',
|
|
35
|
+
// Composite
|
|
36
|
+
OBJECT: 'object',
|
|
37
|
+
ARRAY: 'array',
|
|
38
|
+
TUPLE: 'tuple',
|
|
39
|
+
SET: 'set',
|
|
40
|
+
MAP: 'map',
|
|
41
|
+
RECORD: 'record',
|
|
42
|
+
// Union types
|
|
43
|
+
UNION: 'union',
|
|
44
|
+
DISCRIMINATED_UNION: 'discriminatedUnion',
|
|
45
|
+
INTERSECTION: 'intersection',
|
|
46
|
+
XOR: 'xor',
|
|
47
|
+
// Values
|
|
48
|
+
ENUM: 'enum',
|
|
49
|
+
LITERAL: 'literal',
|
|
50
|
+
// Special validators
|
|
51
|
+
LAZY: 'lazy',
|
|
52
|
+
CUSTOM: 'custom',
|
|
53
|
+
FUNCTION: 'function',
|
|
54
|
+
FILE: 'file',
|
|
55
|
+
JSON: 'json',
|
|
56
|
+
TEMPLATE_LITERAL: 'templateLiteral',
|
|
57
|
+
PROMISE: 'promise',
|
|
58
|
+
// Wrapper/Modifier validators
|
|
59
|
+
OPTIONAL: 'optional',
|
|
60
|
+
NULLABLE: 'nullable',
|
|
61
|
+
NULLISH: 'nullish',
|
|
62
|
+
EXACT_OPTIONAL: 'exactOptional',
|
|
63
|
+
DEFAULT: 'default',
|
|
64
|
+
CATCH: 'catch',
|
|
65
|
+
REFINE: 'refine',
|
|
66
|
+
TRANSFORM: 'transform',
|
|
67
|
+
PIPE: 'pipe',
|
|
68
|
+
PREPROCESS: 'preprocess',
|
|
69
|
+
SUPER_REFINE: 'superRefine',
|
|
70
|
+
BRAND: 'brand',
|
|
71
|
+
READONLY: 'readonly',
|
|
72
|
+
META: 'meta',
|
|
73
|
+
PREFAULT: 'prefault',
|
|
74
|
+
PREFault: 'prefault',
|
|
75
|
+
// Codec
|
|
76
|
+
CODEC: 'codec',
|
|
77
|
+
};
|
|
78
|
+
function resolveErrorMessage(error, fallback) {
|
|
79
|
+
if (typeof error === 'string') {
|
|
80
|
+
return error;
|
|
81
|
+
}
|
|
82
|
+
if (typeof error?.error === 'string') {
|
|
83
|
+
return error.error;
|
|
84
|
+
}
|
|
85
|
+
if (typeof error?.error === 'function') {
|
|
86
|
+
return error.error({}) || fallback;
|
|
87
|
+
}
|
|
88
|
+
if (typeof error?.message === 'string') {
|
|
89
|
+
return error.message;
|
|
90
|
+
}
|
|
91
|
+
return fallback;
|
|
92
|
+
}
|
|
93
|
+
function isPromiseLike(value) {
|
|
94
|
+
return value !== null &&
|
|
95
|
+
(typeof value === 'object' || typeof value === 'function') &&
|
|
96
|
+
typeof value.then === 'function';
|
|
97
|
+
}
|
|
98
|
+
function getSimpleWrappedMode(baseValidator) {
|
|
99
|
+
if (baseValidator.isSimple !== true) {
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
switch (baseValidator.validatorType) {
|
|
103
|
+
case VLD_VALIDATOR_TYPES.STRING:
|
|
104
|
+
return 'string';
|
|
105
|
+
case VLD_VALIDATOR_TYPES.NUMBER:
|
|
106
|
+
return 'number';
|
|
107
|
+
case VLD_VALIDATOR_TYPES.BOOLEAN:
|
|
108
|
+
return 'boolean';
|
|
109
|
+
case VLD_VALIDATOR_TYPES.BIGINT:
|
|
110
|
+
return 'bigint';
|
|
111
|
+
case VLD_VALIDATOR_TYPES.SYMBOL:
|
|
112
|
+
return 'symbol';
|
|
113
|
+
default:
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
function parseSimpleWrappedValue(mode, value) {
|
|
118
|
+
switch (mode) {
|
|
119
|
+
case 'string':
|
|
120
|
+
return typeof value === 'string' ? value : undefined;
|
|
121
|
+
case 'number':
|
|
122
|
+
return typeof value === 'number' && !isNaN(value) ? value : undefined;
|
|
123
|
+
case 'boolean':
|
|
124
|
+
return typeof value === 'boolean' ? value : undefined;
|
|
125
|
+
case 'bigint':
|
|
126
|
+
return typeof value === 'bigint' ? value : undefined;
|
|
127
|
+
case 'symbol':
|
|
128
|
+
return typeof value === 'symbol' ? value : undefined;
|
|
129
|
+
default:
|
|
130
|
+
return undefined;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Abstract base class for all validators
|
|
135
|
+
* Implements immutable pattern to prevent memory leaks and race conditions
|
|
136
|
+
*/
|
|
137
|
+
class VldBase {
|
|
138
|
+
/**
|
|
139
|
+
* Constructor with runtime type identifier
|
|
140
|
+
* @param validatorType The runtime type identifier
|
|
141
|
+
*/
|
|
142
|
+
constructor(validatorType = 'unknown') {
|
|
143
|
+
this.validatorType = validatorType;
|
|
144
|
+
}
|
|
145
|
+
get '~standard'() {
|
|
146
|
+
return {
|
|
147
|
+
version: 1,
|
|
148
|
+
vendor: 'vld',
|
|
149
|
+
validate: (value) => {
|
|
150
|
+
const result = this.safeParse(value);
|
|
151
|
+
if (result.success) {
|
|
152
|
+
return { value: result.data };
|
|
153
|
+
}
|
|
154
|
+
return { issues: [{ message: result.error.message }] };
|
|
155
|
+
},
|
|
156
|
+
types: undefined
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
async parseAsync(value) {
|
|
160
|
+
return this.parse(value);
|
|
161
|
+
}
|
|
162
|
+
async safeParseAsync(value) {
|
|
163
|
+
try {
|
|
164
|
+
return { success: true, data: await this.parseAsync(value) };
|
|
165
|
+
}
|
|
166
|
+
catch (error) {
|
|
167
|
+
return { success: false, error: error };
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Check if a value is valid according to this validator
|
|
172
|
+
* @param value The value to check
|
|
173
|
+
* @returns True if valid, false otherwise
|
|
174
|
+
*/
|
|
175
|
+
isValid(value) {
|
|
176
|
+
return this.safeParse(value).success;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Parse a value or return a default if validation fails
|
|
180
|
+
* BUG-NEW-017 FIX: Validate default value to ensure type safety
|
|
181
|
+
* @param value The value to validate
|
|
182
|
+
* @param defaultValue The default value to return on failure
|
|
183
|
+
* @returns The validated value or default
|
|
184
|
+
*/
|
|
185
|
+
parseOrDefault(value, defaultValue) {
|
|
186
|
+
const result = this.safeParse(value);
|
|
187
|
+
if (result.success) {
|
|
188
|
+
return result.data;
|
|
189
|
+
}
|
|
190
|
+
// Validate the default value to ensure it's actually valid
|
|
191
|
+
const defaultResult = this.safeParse(defaultValue);
|
|
192
|
+
if (!defaultResult.success) {
|
|
193
|
+
throw new Error(`Invalid default value provided: ${defaultResult.error.message}`);
|
|
194
|
+
}
|
|
195
|
+
return defaultResult.data;
|
|
196
|
+
}
|
|
197
|
+
refine(predicate, message) {
|
|
198
|
+
return new VldRefine(this, predicate, message);
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Advanced refinement with context for adding multiple issues
|
|
202
|
+
* @param refinement The refinement function with context
|
|
203
|
+
* @returns A new super refined validator
|
|
204
|
+
*/
|
|
205
|
+
superRefine(refinement) {
|
|
206
|
+
return new VldSuperRefine(this, refinement);
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Create a new validator that transforms the output
|
|
210
|
+
* @param transformer The transformation function
|
|
211
|
+
* @returns A new transformed validator
|
|
212
|
+
*/
|
|
213
|
+
transform(transformer) {
|
|
214
|
+
return new VldTransform(this, transformer);
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Create a new validator with a default value for undefined inputs
|
|
218
|
+
* @param defaultValue The default value
|
|
219
|
+
* @returns A new validator with default
|
|
220
|
+
*/
|
|
221
|
+
default(defaultValue) {
|
|
222
|
+
return new VldDefault(this, defaultValue);
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Create a new validator that catches errors and returns a fallback
|
|
226
|
+
* @param fallbackValue The fallback value
|
|
227
|
+
* @returns A new validator with catch
|
|
228
|
+
*/
|
|
229
|
+
catch(fallbackValue) {
|
|
230
|
+
return new VldCatch(this, fallbackValue);
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Make this validator optional (allows undefined)
|
|
234
|
+
* @returns A new optional validator
|
|
235
|
+
*/
|
|
236
|
+
optional() {
|
|
237
|
+
return new VldOptional(this);
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Make this validator nullable (allows null)
|
|
241
|
+
* @returns A new nullable validator
|
|
242
|
+
*/
|
|
243
|
+
nullable() {
|
|
244
|
+
return new VldNullable(this);
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Make this validator nullish (allows null or undefined)
|
|
248
|
+
* @returns A new nullish validator
|
|
249
|
+
*/
|
|
250
|
+
nullish() {
|
|
251
|
+
return new VldNullish(this);
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Make this validator exactly optional - allows undefined but not missing
|
|
255
|
+
* Unlike .optional() which treats missing as undefined, exactOptional()
|
|
256
|
+
* requires the key to be present but allows undefined as a value
|
|
257
|
+
* Zod 4 API parity
|
|
258
|
+
* @returns A new exact optional validator
|
|
259
|
+
*/
|
|
260
|
+
exactOptional() {
|
|
261
|
+
return new VldExactOptional(this);
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Pipe the output of this validator into another validator
|
|
265
|
+
* @param next The next validator to pipe into
|
|
266
|
+
* @returns A new piped validator
|
|
267
|
+
*/
|
|
268
|
+
pipe(next) {
|
|
269
|
+
return new VldPipe(this, next);
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Create a new validator that returns readonly output
|
|
273
|
+
* Zod 4 API parity - marks output as readonly for TypeScript
|
|
274
|
+
* @returns A new readonly validator
|
|
275
|
+
*/
|
|
276
|
+
readonly() {
|
|
277
|
+
return new VldReadonly(this);
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Brand the output type with a unique brand for nominal typing
|
|
281
|
+
* Zod 4 API parity - prevents accidental assignment of similarly typed values
|
|
282
|
+
* @returns A new branded validator
|
|
283
|
+
* @example
|
|
284
|
+
* const userIdSchema = v.string().brand<'UserId'>();
|
|
285
|
+
* const productIdSchema = v.string().brand<'ProductId'>();
|
|
286
|
+
*
|
|
287
|
+
* let userId: UserId = userIdSchema.parse('abc');
|
|
288
|
+
* let productId: ProductId = productIdSchema.parse('xyz');
|
|
289
|
+
*
|
|
290
|
+
* userId = productId; // TypeScript error: types are incompatible
|
|
291
|
+
*/
|
|
292
|
+
brand() {
|
|
293
|
+
return new VldBrand(this);
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Apply an external function to transform this validator
|
|
297
|
+
* Zod 4 API parity - allows external function chaining
|
|
298
|
+
* @param fn External function that takes this validator and returns a new validator
|
|
299
|
+
* @returns The result of applying the function to this validator
|
|
300
|
+
* @example
|
|
301
|
+
* const withLength = (schema: VldBase<unknown, string>) => schema.transform(s => s.length);
|
|
302
|
+
* const lengthSchema = v.string().apply(withLength); // validates string, returns number
|
|
303
|
+
*/
|
|
304
|
+
apply(fn) {
|
|
305
|
+
return fn(this);
|
|
306
|
+
}
|
|
307
|
+
check(predicate, message) {
|
|
308
|
+
return new VldRefine(this, predicate, message);
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Get or set metadata for this schema
|
|
312
|
+
*/
|
|
313
|
+
meta(data) {
|
|
314
|
+
if (data === undefined) {
|
|
315
|
+
return registry.globalRegistry.get(this);
|
|
316
|
+
}
|
|
317
|
+
const schema = new VldMeta(this, data);
|
|
318
|
+
registry.globalRegistry.add(schema, data);
|
|
319
|
+
return schema;
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Register this schema in a metadata registry and return the same instance.
|
|
323
|
+
* This mirrors Zod 4's registry convenience API without changing validator
|
|
324
|
+
* immutability.
|
|
325
|
+
*/
|
|
326
|
+
register(targetRegistry, metadata) {
|
|
327
|
+
targetRegistry.add(this, metadata);
|
|
328
|
+
return this;
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Add a description to this schema
|
|
332
|
+
* Zod 4 API parity - convenience method for .meta({ description: ... })
|
|
333
|
+
* @param description The description to add
|
|
334
|
+
* @returns A new validator with the description
|
|
335
|
+
*/
|
|
336
|
+
describe(description) {
|
|
337
|
+
return this.meta({ description });
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Metadata validator - wraps a schema with metadata
|
|
342
|
+
*/
|
|
343
|
+
class VldMeta extends VldBase {
|
|
344
|
+
constructor(baseValidator, metadata) {
|
|
345
|
+
super(VLD_VALIDATOR_TYPES.META);
|
|
346
|
+
this.baseValidator = baseValidator;
|
|
347
|
+
this.metadata = metadata;
|
|
348
|
+
}
|
|
349
|
+
parse(value) {
|
|
350
|
+
return this.baseValidator.parse(value);
|
|
351
|
+
}
|
|
352
|
+
safeParse(value) {
|
|
353
|
+
return this.baseValidator.safeParse(value);
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Get the metadata
|
|
357
|
+
*/
|
|
358
|
+
getMeta() {
|
|
359
|
+
return { ...this.metadata };
|
|
360
|
+
}
|
|
361
|
+
meta(data) {
|
|
362
|
+
if (data === undefined) {
|
|
363
|
+
return { ...this.metadata, ...registry.globalRegistry.get(this) };
|
|
364
|
+
}
|
|
365
|
+
const schema = new VldMeta(this.baseValidator, { ...this.metadata, ...data });
|
|
366
|
+
registry.globalRegistry.add(schema, schema.getMeta());
|
|
367
|
+
return schema;
|
|
368
|
+
}
|
|
369
|
+
describe(description) {
|
|
370
|
+
return this.meta({ description });
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Readonly validator - marks output as readonly
|
|
375
|
+
*/
|
|
376
|
+
class VldReadonly extends VldBase {
|
|
377
|
+
constructor(baseValidator) {
|
|
378
|
+
super(VLD_VALIDATOR_TYPES.READONLY);
|
|
379
|
+
this.baseValidator = baseValidator;
|
|
380
|
+
}
|
|
381
|
+
parse(value) {
|
|
382
|
+
return this.baseValidator.parse(value);
|
|
383
|
+
}
|
|
384
|
+
safeParse(value) {
|
|
385
|
+
const result = this.baseValidator.safeParse(value);
|
|
386
|
+
if (result.success) {
|
|
387
|
+
return { success: true, data: result.data };
|
|
388
|
+
}
|
|
389
|
+
return { success: false, error: result.error };
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Brand validator - adds a unique brand to the output type for nominal typing
|
|
394
|
+
* Uses TypeScript's branded types pattern to prevent accidental assignment
|
|
395
|
+
*/
|
|
396
|
+
class VldBrand extends VldBase {
|
|
397
|
+
constructor(baseValidator) {
|
|
398
|
+
super(VLD_VALIDATOR_TYPES.BRAND);
|
|
399
|
+
this.baseValidator = baseValidator;
|
|
400
|
+
}
|
|
401
|
+
parse(value) {
|
|
402
|
+
return this.baseValidator.parse(value);
|
|
403
|
+
}
|
|
404
|
+
safeParse(value) {
|
|
405
|
+
const result = this.baseValidator.safeParse(value);
|
|
406
|
+
if (result.success) {
|
|
407
|
+
return {
|
|
408
|
+
success: true,
|
|
409
|
+
data: result.data
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
return { success: false, error: result.error };
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* Refine validator - adds custom validation
|
|
417
|
+
*/
|
|
418
|
+
class VldRefine extends VldBase {
|
|
419
|
+
constructor(baseValidator, predicate, customMessage) {
|
|
420
|
+
super(VLD_VALIDATOR_TYPES.REFINE);
|
|
421
|
+
this.baseValidator = baseValidator;
|
|
422
|
+
this.predicate = predicate;
|
|
423
|
+
this.customMessage = customMessage;
|
|
424
|
+
}
|
|
425
|
+
parse(value) {
|
|
426
|
+
const baseResult = this.baseValidator.parse(value);
|
|
427
|
+
const passed = this.predicate(baseResult);
|
|
428
|
+
if (isPromiseLike(passed)) {
|
|
429
|
+
throw new Error('Use parseAsync for async refinements');
|
|
430
|
+
}
|
|
431
|
+
if (!passed) {
|
|
432
|
+
throw new Error(this.customMessage || 'Refinement check failed');
|
|
433
|
+
}
|
|
434
|
+
return baseResult;
|
|
435
|
+
}
|
|
436
|
+
safeParse(value) {
|
|
437
|
+
try {
|
|
438
|
+
return { success: true, data: this.parse(value) };
|
|
439
|
+
}
|
|
440
|
+
catch (error) {
|
|
441
|
+
return { success: false, error: error };
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
async parseAsync(value) {
|
|
445
|
+
const baseResult = await this.baseValidator.parseAsync(value);
|
|
446
|
+
if (!await this.predicate(baseResult)) {
|
|
447
|
+
throw new Error(this.customMessage || 'Refinement check failed');
|
|
448
|
+
}
|
|
449
|
+
return baseResult;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* Transform validator - transforms data after validation
|
|
454
|
+
*/
|
|
455
|
+
class VldTransform extends VldBase {
|
|
456
|
+
constructor(baseValidator, transformer) {
|
|
457
|
+
super(VLD_VALIDATOR_TYPES.TRANSFORM);
|
|
458
|
+
this.baseValidator = baseValidator;
|
|
459
|
+
this.transformer = transformer;
|
|
460
|
+
}
|
|
461
|
+
parse(value) {
|
|
462
|
+
const baseResult = this.baseValidator.parse(value);
|
|
463
|
+
try {
|
|
464
|
+
const transformed = this.transformer(baseResult);
|
|
465
|
+
if (isPromiseLike(transformed)) {
|
|
466
|
+
throw new Error('Use parseAsync for async transforms');
|
|
467
|
+
}
|
|
468
|
+
return transformed;
|
|
469
|
+
}
|
|
470
|
+
catch (error) {
|
|
471
|
+
throw new Error(`Transform failed: ${error.message}`);
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
safeParse(value) {
|
|
475
|
+
try {
|
|
476
|
+
return { success: true, data: this.parse(value) };
|
|
477
|
+
}
|
|
478
|
+
catch (error) {
|
|
479
|
+
return { success: false, error: error };
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
async parseAsync(value) {
|
|
483
|
+
const baseResult = await this.baseValidator.parseAsync(value);
|
|
484
|
+
try {
|
|
485
|
+
return await this.transformer(baseResult);
|
|
486
|
+
}
|
|
487
|
+
catch (error) {
|
|
488
|
+
throw new Error(`Transform failed: ${error.message}`);
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* Default validator - provides default value for undefined
|
|
494
|
+
* Note: Does not validate the default value at construction time.
|
|
495
|
+
* Use .prefault() to validate the default value at parse time.
|
|
496
|
+
*/
|
|
497
|
+
class VldDefault extends VldBase {
|
|
498
|
+
constructor(baseValidator, defaultValue) {
|
|
499
|
+
super(VLD_VALIDATOR_TYPES.DEFAULT);
|
|
500
|
+
this.baseValidator = baseValidator;
|
|
501
|
+
this.defaultValue = defaultValue;
|
|
502
|
+
}
|
|
503
|
+
parse(value) {
|
|
504
|
+
if (value === undefined) {
|
|
505
|
+
return this.defaultValue;
|
|
506
|
+
}
|
|
507
|
+
return this.baseValidator.parse(value);
|
|
508
|
+
}
|
|
509
|
+
safeParse(value) {
|
|
510
|
+
if (value === undefined) {
|
|
511
|
+
return { success: true, data: this.defaultValue };
|
|
512
|
+
}
|
|
513
|
+
return this.baseValidator.safeParse(value);
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* Pre-parse default - validates the default value instead of returning it directly
|
|
517
|
+
* This is useful when the default value needs to be validated against the schema
|
|
518
|
+
*/
|
|
519
|
+
prefault() {
|
|
520
|
+
// Return a new validator that validates the default value when parse(undefined) is called
|
|
521
|
+
return new VldPrefault(this.baseValidator, this.defaultValue);
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
525
|
+
* Prefault validator - validates the default value instead of returning it directly
|
|
526
|
+
*/
|
|
527
|
+
class VldPrefault extends VldBase {
|
|
528
|
+
constructor(baseValidator, defaultValue) {
|
|
529
|
+
super(VLD_VALIDATOR_TYPES.PREFAULT);
|
|
530
|
+
this.baseValidator = baseValidator;
|
|
531
|
+
this.defaultValue = defaultValue;
|
|
532
|
+
}
|
|
533
|
+
parse(value) {
|
|
534
|
+
if (value === undefined) {
|
|
535
|
+
// Validate the default value through the base validator
|
|
536
|
+
return this.baseValidator.parse(this.defaultValue);
|
|
537
|
+
}
|
|
538
|
+
return this.baseValidator.parse(value);
|
|
539
|
+
}
|
|
540
|
+
safeParse(value) {
|
|
541
|
+
if (value === undefined) {
|
|
542
|
+
return this.baseValidator.safeParse(this.defaultValue);
|
|
543
|
+
}
|
|
544
|
+
return this.baseValidator.safeParse(value);
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* Calling prefault multiple times should be safe - return self
|
|
548
|
+
*/
|
|
549
|
+
prefault() {
|
|
550
|
+
return this;
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* Catch validator - provides fallback value on validation error
|
|
555
|
+
* BUG-NPM-003 FIX: Validate fallback value at construction time
|
|
556
|
+
*/
|
|
557
|
+
class VldCatch extends VldBase {
|
|
558
|
+
constructor(baseValidator, fallbackValue) {
|
|
559
|
+
super(VLD_VALIDATOR_TYPES.CATCH);
|
|
560
|
+
this.baseValidator = baseValidator;
|
|
561
|
+
this.fallbackValue = fallbackValue;
|
|
562
|
+
this.simpleMode = getSimpleWrappedMode(baseValidator);
|
|
563
|
+
// BUG-NPM-003 FIX: Validate the fallback value to ensure type safety
|
|
564
|
+
const validation = baseValidator.safeParse(fallbackValue);
|
|
565
|
+
if (!validation.success) {
|
|
566
|
+
throw new Error(`Invalid fallback value: ${validation.error.message}`);
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
parse(value) {
|
|
570
|
+
const simpleValue = parseSimpleWrappedValue(this.simpleMode, value);
|
|
571
|
+
if (simpleValue !== undefined) {
|
|
572
|
+
return simpleValue;
|
|
573
|
+
}
|
|
574
|
+
if (this.simpleMode !== undefined) {
|
|
575
|
+
return this.fallbackValue;
|
|
576
|
+
}
|
|
577
|
+
try {
|
|
578
|
+
return this.baseValidator.parse(value);
|
|
579
|
+
}
|
|
580
|
+
catch {
|
|
581
|
+
return this.fallbackValue;
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
safeParse(value) {
|
|
585
|
+
const simpleValue = parseSimpleWrappedValue(this.simpleMode, value);
|
|
586
|
+
if (simpleValue !== undefined) {
|
|
587
|
+
return { success: true, data: simpleValue };
|
|
588
|
+
}
|
|
589
|
+
if (this.simpleMode !== undefined) {
|
|
590
|
+
return { success: true, data: this.fallbackValue };
|
|
591
|
+
}
|
|
592
|
+
const result = this.baseValidator.safeParse(value);
|
|
593
|
+
if (result.success) {
|
|
594
|
+
return result;
|
|
595
|
+
}
|
|
596
|
+
return { success: true, data: this.fallbackValue };
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
/**
|
|
600
|
+
* Optional validator - allows undefined
|
|
601
|
+
*/
|
|
602
|
+
class VldOptional extends VldBase {
|
|
603
|
+
constructor(baseValidator) {
|
|
604
|
+
super(VLD_VALIDATOR_TYPES.OPTIONAL);
|
|
605
|
+
this.baseValidator = baseValidator;
|
|
606
|
+
this.simpleMode = getSimpleWrappedMode(baseValidator);
|
|
607
|
+
}
|
|
608
|
+
parseSimpleValue(value) {
|
|
609
|
+
return parseSimpleWrappedValue(this.simpleMode, value);
|
|
610
|
+
}
|
|
611
|
+
static create(baseValidator) {
|
|
612
|
+
return new VldOptional(baseValidator);
|
|
613
|
+
}
|
|
614
|
+
parse(value) {
|
|
615
|
+
if (value === undefined) {
|
|
616
|
+
return undefined;
|
|
617
|
+
}
|
|
618
|
+
const simpleValue = this.parseSimpleValue(value);
|
|
619
|
+
if (simpleValue !== undefined) {
|
|
620
|
+
return simpleValue;
|
|
621
|
+
}
|
|
622
|
+
return this.baseValidator.parse(value);
|
|
623
|
+
}
|
|
624
|
+
safeParse(value) {
|
|
625
|
+
if (value === undefined) {
|
|
626
|
+
return { success: true, data: undefined };
|
|
627
|
+
}
|
|
628
|
+
const simpleValue = this.parseSimpleValue(value);
|
|
629
|
+
if (simpleValue !== undefined) {
|
|
630
|
+
return { success: true, data: simpleValue };
|
|
631
|
+
}
|
|
632
|
+
return this.baseValidator.safeParse(value);
|
|
633
|
+
}
|
|
634
|
+
unwrap() {
|
|
635
|
+
return this.baseValidator;
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
/**
|
|
639
|
+
* Exact optional validator - allows undefined but requires key presence
|
|
640
|
+
* Unlike Optional which treats missing as undefined, ExactOptional
|
|
641
|
+
* requires the key to be present (not missing from object) but allows undefined
|
|
642
|
+
* Zod 4 API parity
|
|
643
|
+
*/
|
|
644
|
+
class VldExactOptional extends VldBase {
|
|
645
|
+
constructor(baseValidator) {
|
|
646
|
+
super(VLD_VALIDATOR_TYPES.EXACT_OPTIONAL);
|
|
647
|
+
this.baseValidator = baseValidator;
|
|
648
|
+
this.simpleMode = getSimpleWrappedMode(baseValidator);
|
|
649
|
+
}
|
|
650
|
+
static create(baseValidator) {
|
|
651
|
+
return new VldExactOptional(baseValidator);
|
|
652
|
+
}
|
|
653
|
+
parse(value) {
|
|
654
|
+
if (value === undefined) {
|
|
655
|
+
return undefined;
|
|
656
|
+
}
|
|
657
|
+
const simpleValue = parseSimpleWrappedValue(this.simpleMode, value);
|
|
658
|
+
if (simpleValue !== undefined) {
|
|
659
|
+
return simpleValue;
|
|
660
|
+
}
|
|
661
|
+
return this.baseValidator.parse(value);
|
|
662
|
+
}
|
|
663
|
+
safeParse(value) {
|
|
664
|
+
// Unlike regular optional, undefined is explicitly valid
|
|
665
|
+
// but we still validate through the base validator
|
|
666
|
+
if (value === undefined) {
|
|
667
|
+
return { success: true, data: undefined };
|
|
668
|
+
}
|
|
669
|
+
const simpleValue = parseSimpleWrappedValue(this.simpleMode, value);
|
|
670
|
+
if (simpleValue !== undefined) {
|
|
671
|
+
return { success: true, data: simpleValue };
|
|
672
|
+
}
|
|
673
|
+
return this.baseValidator.safeParse(value);
|
|
674
|
+
}
|
|
675
|
+
unwrap() {
|
|
676
|
+
return this.baseValidator;
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
/**
|
|
680
|
+
* Nullable validator - allows null
|
|
681
|
+
*/
|
|
682
|
+
class VldNullable extends VldBase {
|
|
683
|
+
constructor(baseValidator) {
|
|
684
|
+
super(VLD_VALIDATOR_TYPES.NULLABLE);
|
|
685
|
+
this.baseValidator = baseValidator;
|
|
686
|
+
this.simpleMode = getSimpleWrappedMode(baseValidator);
|
|
687
|
+
}
|
|
688
|
+
static create(baseValidator) {
|
|
689
|
+
return new VldNullable(baseValidator);
|
|
690
|
+
}
|
|
691
|
+
parse(value) {
|
|
692
|
+
if (value === null) {
|
|
693
|
+
return null;
|
|
694
|
+
}
|
|
695
|
+
const simpleValue = parseSimpleWrappedValue(this.simpleMode, value);
|
|
696
|
+
if (simpleValue !== undefined) {
|
|
697
|
+
return simpleValue;
|
|
698
|
+
}
|
|
699
|
+
return this.baseValidator.parse(value);
|
|
700
|
+
}
|
|
701
|
+
safeParse(value) {
|
|
702
|
+
if (value === null) {
|
|
703
|
+
return { success: true, data: null };
|
|
704
|
+
}
|
|
705
|
+
const simpleValue = parseSimpleWrappedValue(this.simpleMode, value);
|
|
706
|
+
if (simpleValue !== undefined) {
|
|
707
|
+
return { success: true, data: simpleValue };
|
|
708
|
+
}
|
|
709
|
+
return this.baseValidator.safeParse(value);
|
|
710
|
+
}
|
|
711
|
+
unwrap() {
|
|
712
|
+
return this.baseValidator;
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
/**
|
|
716
|
+
* Nullish validator - allows null or undefined
|
|
717
|
+
*/
|
|
718
|
+
class VldNullish extends VldBase {
|
|
719
|
+
constructor(baseValidator) {
|
|
720
|
+
super(VLD_VALIDATOR_TYPES.NULLISH);
|
|
721
|
+
this.baseValidator = baseValidator;
|
|
722
|
+
this.simpleMode = getSimpleWrappedMode(baseValidator);
|
|
723
|
+
}
|
|
724
|
+
static create(baseValidator) {
|
|
725
|
+
return new VldNullish(baseValidator);
|
|
726
|
+
}
|
|
727
|
+
parse(value) {
|
|
728
|
+
if (value === null || value === undefined) {
|
|
729
|
+
return value;
|
|
730
|
+
}
|
|
731
|
+
const simpleValue = parseSimpleWrappedValue(this.simpleMode, value);
|
|
732
|
+
if (simpleValue !== undefined) {
|
|
733
|
+
return simpleValue;
|
|
734
|
+
}
|
|
735
|
+
return this.baseValidator.parse(value);
|
|
736
|
+
}
|
|
737
|
+
safeParse(value) {
|
|
738
|
+
if (value === null || value === undefined) {
|
|
739
|
+
return { success: true, data: value };
|
|
740
|
+
}
|
|
741
|
+
const simpleValue = parseSimpleWrappedValue(this.simpleMode, value);
|
|
742
|
+
if (simpleValue !== undefined) {
|
|
743
|
+
return { success: true, data: simpleValue };
|
|
744
|
+
}
|
|
745
|
+
return this.baseValidator.safeParse(value);
|
|
746
|
+
}
|
|
747
|
+
unwrap() {
|
|
748
|
+
return this.baseValidator;
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
/**
|
|
752
|
+
* Pipe validator - chains validators, passing output of one to the next
|
|
753
|
+
*/
|
|
754
|
+
class VldPipe extends VldBase {
|
|
755
|
+
constructor(first, second) {
|
|
756
|
+
super(VLD_VALIDATOR_TYPES.PIPE);
|
|
757
|
+
this.first = first;
|
|
758
|
+
this.second = second;
|
|
759
|
+
}
|
|
760
|
+
parse(value) {
|
|
761
|
+
const intermediateResult = this.first.parse(value);
|
|
762
|
+
return this.second.parse(intermediateResult);
|
|
763
|
+
}
|
|
764
|
+
safeParse(value) {
|
|
765
|
+
const firstResult = this.first.safeParse(value);
|
|
766
|
+
if (!firstResult.success) {
|
|
767
|
+
return { success: false, error: firstResult.error };
|
|
768
|
+
}
|
|
769
|
+
return this.second.safeParse(firstResult.data);
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
/**
|
|
773
|
+
* SuperRefine validator - advanced refinement with context
|
|
774
|
+
*/
|
|
775
|
+
class VldSuperRefine extends VldBase {
|
|
776
|
+
constructor(_inner, _refinement) {
|
|
777
|
+
super(VLD_VALIDATOR_TYPES.SUPER_REFINE);
|
|
778
|
+
this._inner = _inner;
|
|
779
|
+
this._refinement = _refinement;
|
|
780
|
+
}
|
|
781
|
+
parse(value) {
|
|
782
|
+
const result = this._inner.parse(value);
|
|
783
|
+
const issues = [];
|
|
784
|
+
const ctx = {
|
|
785
|
+
addIssue: (issue) => issues.push(issue),
|
|
786
|
+
path: []
|
|
787
|
+
};
|
|
788
|
+
const maybePromise = this._refinement(result, ctx);
|
|
789
|
+
if (maybePromise instanceof Promise) {
|
|
790
|
+
throw new Error('Use parseAsync for async refinements');
|
|
791
|
+
}
|
|
792
|
+
if (issues.length > 0) {
|
|
793
|
+
throw new Error(issues.map(i => i.message).join('; '));
|
|
794
|
+
}
|
|
795
|
+
return result;
|
|
796
|
+
}
|
|
797
|
+
safeParse(value) {
|
|
798
|
+
const result = this._inner.safeParse(value);
|
|
799
|
+
if (!result.success)
|
|
800
|
+
return { success: false, error: result.error };
|
|
801
|
+
const issues = [];
|
|
802
|
+
const ctx = {
|
|
803
|
+
addIssue: (issue) => issues.push(issue),
|
|
804
|
+
path: []
|
|
805
|
+
};
|
|
806
|
+
const maybePromise = this._refinement(result.data, ctx);
|
|
807
|
+
if (maybePromise instanceof Promise) {
|
|
808
|
+
throw new Error('Use safeParseAsync for async refinements');
|
|
809
|
+
}
|
|
810
|
+
if (issues.length > 0) {
|
|
811
|
+
return {
|
|
812
|
+
success: false,
|
|
813
|
+
error: new Error(issues.map(i => i.message).join('; '))
|
|
814
|
+
};
|
|
815
|
+
}
|
|
816
|
+
return result;
|
|
817
|
+
}
|
|
818
|
+
async parseAsync(value) {
|
|
819
|
+
const result = await this._inner.parseAsync(value);
|
|
820
|
+
const issues = [];
|
|
821
|
+
const ctx = {
|
|
822
|
+
addIssue: (issue) => issues.push(issue),
|
|
823
|
+
path: []
|
|
824
|
+
};
|
|
825
|
+
await this._refinement(result, ctx);
|
|
826
|
+
if (issues.length > 0) {
|
|
827
|
+
throw new Error(issues.map(i => i.message).join('; '));
|
|
828
|
+
}
|
|
829
|
+
return result;
|
|
830
|
+
}
|
|
831
|
+
async safeParseAsync(value) {
|
|
832
|
+
try {
|
|
833
|
+
return { success: true, data: await this.parseAsync(value) };
|
|
834
|
+
}
|
|
835
|
+
catch (error) {
|
|
836
|
+
return { success: false, error: error };
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
/**
|
|
841
|
+
* Preprocess validator - transforms input before validation
|
|
842
|
+
*/
|
|
843
|
+
class VldPreprocess extends VldBase {
|
|
844
|
+
constructor(_preprocessor, _schema) {
|
|
845
|
+
super(VLD_VALIDATOR_TYPES.PREPROCESS);
|
|
846
|
+
this._preprocessor = _preprocessor;
|
|
847
|
+
this._schema = _schema;
|
|
848
|
+
}
|
|
849
|
+
static create(preprocessor, schema) {
|
|
850
|
+
return new VldPreprocess(preprocessor, schema);
|
|
851
|
+
}
|
|
852
|
+
parse(value) {
|
|
853
|
+
const preprocessed = this._preprocessor(value);
|
|
854
|
+
return this._schema.parse(preprocessed);
|
|
855
|
+
}
|
|
856
|
+
safeParse(value) {
|
|
857
|
+
try {
|
|
858
|
+
const preprocessed = this._preprocessor(value);
|
|
859
|
+
return this._schema.safeParse(preprocessed);
|
|
860
|
+
}
|
|
861
|
+
catch (error) {
|
|
862
|
+
return {
|
|
863
|
+
success: false,
|
|
864
|
+
error: error
|
|
865
|
+
};
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
exports.VLD_VALIDATOR_TYPES = VLD_VALIDATOR_TYPES;
|
|
871
|
+
exports.VldBase = VldBase;
|
|
872
|
+
exports.VldBrand = VldBrand;
|
|
873
|
+
exports.VldCatch = VldCatch;
|
|
874
|
+
exports.VldDefault = VldDefault;
|
|
875
|
+
exports.VldExactOptional = VldExactOptional;
|
|
876
|
+
exports.VldMeta = VldMeta;
|
|
877
|
+
exports.VldNullable = VldNullable;
|
|
878
|
+
exports.VldNullish = VldNullish;
|
|
879
|
+
exports.VldOptional = VldOptional;
|
|
880
|
+
exports.VldPipe = VldPipe;
|
|
881
|
+
exports.VldPrefault = VldPrefault;
|
|
882
|
+
exports.VldPreprocess = VldPreprocess;
|
|
883
|
+
exports.VldReadonly = VldReadonly;
|
|
884
|
+
exports.VldRefine = VldRefine;
|
|
885
|
+
exports.VldSuperRefine = VldSuperRefine;
|
|
886
|
+
exports.VldTransform = VldTransform;
|
|
887
|
+
exports.resolveErrorMessage = resolveErrorMessage;
|