@oxog/vld 2.0.3 → 2.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +120 -1
- package/README.md +1296 -1171
- package/dist/chunks/errors-core-Cqi4-9ew.js +1 -0
- package/dist/chunks/index-CkbfQQ4n.js +1 -0
- package/dist/chunks/index-yjpbvFgw.js +1 -0
- package/dist/chunks/ip-validation-g5LWgy9t.js +1 -0
- package/dist/chunks/security-Dy24T8N7.js +1 -0
- package/dist/cjs/chunks/errors-core-DKPohm9I.cjs +1 -0
- package/dist/cjs/chunks/index-BEV9nG0N.cjs +1 -0
- package/dist/cjs/chunks/index-ZjHAxYdA.cjs +1 -0
- package/dist/cjs/chunks/ip-validation-BZqPamPC.cjs +1 -0
- package/dist/cjs/chunks/security-aXZVI7qW.cjs +1 -0
- package/dist/cjs/cli/bin.cjs +2 -0
- package/dist/cjs/cli/index.cjs +1 -0
- package/dist/cjs/codecs/index.cjs +1 -0
- package/dist/cjs/coercion/index.cjs +1 -0
- package/dist/cjs/compat/emitter.cjs +1 -0
- package/dist/cjs/compat/result.cjs +1 -0
- package/dist/cjs/errors.cjs +1 -387
- package/dist/cjs/index.cjs +1 -10759
- package/dist/cjs/kernel.cjs +1 -0
- package/dist/cjs/locales/af.cjs +1 -0
- package/dist/cjs/locales/ar.cjs +1 -0
- package/dist/cjs/locales/bn.cjs +1 -0
- package/dist/cjs/locales/da.cjs +1 -0
- package/dist/cjs/locales/de.cjs +1 -0
- package/dist/cjs/locales/en.cjs +1 -0
- package/dist/cjs/locales/es-MX.cjs +1 -0
- package/dist/cjs/locales/es.cjs +1 -0
- package/dist/cjs/locales/fi.cjs +1 -0
- package/dist/cjs/locales/fr.cjs +1 -0
- package/dist/cjs/locales/hi.cjs +1 -0
- package/dist/cjs/locales/id.cjs +1 -0
- package/dist/cjs/locales/index.cjs +1 -2877
- package/dist/cjs/locales/it.cjs +1 -0
- package/dist/cjs/locales/ja.cjs +1 -0
- package/dist/cjs/locales/ko.cjs +1 -0
- package/dist/cjs/locales/lazy.cjs +1 -3169
- package/dist/cjs/locales/nl.cjs +1 -0
- package/dist/cjs/locales/no.cjs +1 -0
- package/dist/cjs/locales/pl.cjs +1 -0
- package/dist/cjs/locales/pt-BR.cjs +1 -0
- package/dist/cjs/locales/pt.cjs +1 -0
- package/dist/cjs/locales/ru.cjs +1 -0
- package/dist/cjs/locales/runtime.cjs +1 -0
- package/dist/cjs/locales/sv.cjs +1 -0
- package/dist/cjs/locales/sw.cjs +1 -0
- package/dist/cjs/locales/th.cjs +1 -0
- package/dist/cjs/locales/tr.cjs +1 -0
- package/dist/cjs/locales/vi.cjs +1 -0
- package/dist/cjs/locales/zh.cjs +1 -0
- package/dist/cjs/mini.cjs +1 -7474
- package/dist/cjs/pigment.cjs +1 -0
- package/dist/cjs/plugins/index.cjs +1 -0
- package/dist/cjs/registry.cjs +1 -0
- package/dist/cjs/v3/index.cjs +1 -0
- package/dist/cjs/v4/core/index.cjs +1 -0
- package/dist/cjs/v4/index.cjs +1 -0
- package/dist/cjs/v4/locales/index.cjs +1 -0
- package/dist/cjs/v4/mini/index.cjs +1 -0
- package/dist/cjs/v4-mini/index.cjs +1 -0
- package/dist/cjs/validators/any.cjs +1 -0
- package/dist/cjs/validators/array.cjs +1 -0
- package/dist/cjs/validators/base.cjs +1 -0
- package/dist/cjs/validators/base64.cjs +1 -0
- package/dist/cjs/validators/bigint.cjs +1 -0
- package/dist/cjs/validators/boolean.cjs +1 -0
- package/dist/cjs/validators/codec.cjs +1 -0
- package/dist/cjs/validators/custom.cjs +1 -0
- package/dist/cjs/validators/date.cjs +1 -0
- package/dist/cjs/validators/discriminated-union.cjs +1 -0
- package/dist/cjs/validators/enum.cjs +1 -0
- package/dist/cjs/validators/file.cjs +1 -0
- package/dist/cjs/validators/function.cjs +1 -0
- package/dist/cjs/validators/hex.cjs +1 -0
- package/dist/cjs/validators/index.cjs +1 -0
- package/dist/cjs/validators/intersection.cjs +1 -0
- package/dist/cjs/validators/json.cjs +1 -0
- package/dist/cjs/validators/lazy.cjs +1 -0
- package/dist/cjs/validators/literal.cjs +1 -0
- package/dist/cjs/validators/map.cjs +1 -0
- package/dist/cjs/validators/nan.cjs +1 -0
- package/dist/cjs/validators/never.cjs +1 -0
- package/dist/cjs/validators/null.cjs +1 -0
- package/dist/cjs/validators/number.cjs +1 -0
- package/dist/cjs/validators/object.cjs +1 -0
- package/dist/cjs/validators/promise.cjs +1 -0
- package/dist/cjs/validators/record.cjs +1 -0
- package/dist/cjs/validators/set.cjs +1 -0
- package/dist/cjs/validators/string-bool.cjs +1 -0
- package/dist/cjs/validators/string-formats.cjs +1 -0
- package/dist/cjs/validators/string.cjs +1 -0
- package/dist/cjs/validators/symbol.cjs +1 -0
- package/dist/cjs/validators/template-literal.cjs +1 -0
- package/dist/cjs/validators/tuple.cjs +1 -0
- package/dist/cjs/validators/uint8array.cjs +1 -0
- package/dist/cjs/validators/undefined.cjs +1 -0
- package/dist/cjs/validators/union.cjs +1 -0
- package/dist/cjs/validators/unknown.cjs +1 -0
- package/dist/cjs/validators/void.cjs +1 -0
- package/dist/cjs/validators/xor.cjs +1 -0
- package/dist/cli/bin.d.ts +0 -1
- package/dist/cli/bin.js +2 -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 +1 -0
- package/dist/codecs/index.d.ts +21 -4
- package/dist/codecs/index.js +1 -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 +1 -111
- 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 +1 -181
- package/dist/compat/index.d.ts +4 -5
- package/dist/compat/result.d.ts +1 -2
- package/dist/compat/result.js +1 -171
- package/dist/errors-core.d.ts +58 -0
- package/dist/errors.d.ts +4 -54
- package/dist/errors.js +1 -235
- package/dist/events.d.ts +3 -4
- package/dist/index.d.ts +1093 -851
- package/dist/index.js +1 -855
- package/dist/kernel.d.ts +2 -3
- package/dist/kernel.js +1 -405
- package/dist/locales/af.d.ts +1 -2
- package/dist/locales/af.js +1 -107
- package/dist/locales/ar.d.ts +1 -2
- package/dist/locales/ar.js +1 -107
- package/dist/locales/bn.d.ts +1 -2
- package/dist/locales/bn.js +1 -107
- package/dist/locales/da.d.ts +1 -2
- package/dist/locales/da.js +1 -107
- package/dist/locales/de.d.ts +1 -2
- package/dist/locales/de.js +1 -107
- package/dist/locales/en.d.ts +1 -2
- package/dist/locales/en.js +1 -107
- package/dist/locales/es-MX.d.ts +1 -2
- package/dist/locales/es-MX.js +1 -106
- package/dist/locales/es.d.ts +1 -2
- package/dist/locales/es.js +1 -95
- package/dist/locales/fi.d.ts +1 -2
- package/dist/locales/fi.js +1 -107
- package/dist/locales/fr.d.ts +1 -2
- package/dist/locales/fr.js +1 -95
- package/dist/locales/hi.d.ts +1 -2
- package/dist/locales/hi.js +1 -107
- package/dist/locales/id.d.ts +1 -2
- package/dist/locales/id.js +1 -107
- package/dist/locales/index.d.ts +10 -15
- package/dist/locales/index.js +1 -3
- package/dist/locales/it.d.ts +1 -2
- package/dist/locales/it.js +1 -107
- package/dist/locales/ja.d.ts +1 -2
- package/dist/locales/ja.js +1 -107
- package/dist/locales/ko.d.ts +1 -2
- package/dist/locales/ko.js +1 -107
- package/dist/locales/lazy.d.ts +4 -26
- package/dist/locales/lazy.js +1 -220
- package/dist/locales/nl.d.ts +1 -2
- package/dist/locales/nl.js +1 -107
- package/dist/locales/no.d.ts +1 -2
- package/dist/locales/no.js +1 -107
- package/dist/locales/pl.d.ts +1 -2
- package/dist/locales/pl.js +1 -107
- package/dist/locales/pt-BR.d.ts +1 -2
- package/dist/locales/pt-BR.js +1 -107
- package/dist/locales/pt.d.ts +1 -2
- package/dist/locales/pt.js +1 -107
- package/dist/locales/ru.d.ts +1 -2
- package/dist/locales/ru.js +1 -107
- package/dist/locales/runtime.d.ts +10 -0
- package/dist/locales/runtime.js +1 -0
- package/dist/locales/sv.d.ts +1 -2
- package/dist/locales/sv.js +1 -107
- package/dist/locales/sw.d.ts +1 -2
- package/dist/locales/sw.js +1 -107
- package/dist/locales/th.d.ts +1 -2
- package/dist/locales/th.js +1 -107
- package/dist/locales/tr.d.ts +1 -2
- package/dist/locales/tr.js +1 -107
- package/dist/locales/types.d.ts +0 -1
- package/dist/locales/vi.d.ts +1 -2
- package/dist/locales/vi.js +1 -107
- package/dist/locales/zh.d.ts +1 -2
- package/dist/locales/zh.js +1 -107
- package/dist/logger.d.ts +0 -1
- package/dist/mini.d.ts +67 -68
- package/dist/mini.js +1 -132
- package/dist/pigment.d.ts +0 -1
- package/dist/pigment.js +1 -178
- 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 +1 -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 +26 -7
- package/dist/utils/security.d.ts +2 -6
- package/dist/v3/index.d.ts +2 -0
- package/dist/v3/index.js +1 -0
- package/dist/v4/core/index.d.ts +272 -0
- package/dist/v4/core/index.js +1 -0
- package/dist/v4/index.d.ts +4 -0
- package/dist/v4/index.js +1 -0
- package/dist/v4/locales/index.d.ts +57 -0
- package/dist/v4/locales/index.js +1 -0
- package/dist/v4/mini/index.d.ts +2 -0
- package/dist/v4/mini/index.js +1 -0
- package/dist/v4-mini/index.d.ts +22 -0
- package/dist/v4-mini/index.js +1 -0
- package/dist/validators/any.d.ts +7 -2
- package/dist/validators/any.js +1 -0
- package/dist/validators/array.d.ts +16 -2
- package/dist/validators/array.js +1 -0
- package/dist/validators/base.d.ts +213 -14
- package/dist/validators/base.js +1 -0
- package/dist/validators/base64.d.ts +1 -2
- package/dist/validators/base64.js +1 -0
- package/dist/validators/bigint.d.ts +21 -3
- package/dist/validators/bigint.js +1 -0
- package/dist/validators/boolean.d.ts +13 -4
- package/dist/validators/boolean.js +1 -0
- package/dist/validators/codec.d.ts +9 -2
- package/dist/validators/codec.js +1 -0
- package/dist/validators/custom.d.ts +15 -2
- package/dist/validators/custom.js +1 -0
- package/dist/validators/date.d.ts +19 -3
- package/dist/validators/date.js +1 -0
- package/dist/validators/discriminated-union.d.ts +6 -5
- package/dist/validators/discriminated-union.js +1 -0
- package/dist/validators/enum.d.ts +10 -7
- package/dist/validators/enum.js +1 -0
- package/dist/validators/file.d.ts +7 -2
- package/dist/validators/file.js +1 -0
- package/dist/validators/function.d.ts +11 -5
- package/dist/validators/function.js +1 -0
- package/dist/validators/hex.d.ts +1 -2
- package/dist/validators/hex.js +1 -0
- package/dist/validators/index.d.ts +38 -39
- package/dist/validators/index.js +1 -515
- package/dist/validators/intersection.d.ts +1 -2
- package/dist/validators/intersection.js +1 -0
- package/dist/validators/json.d.ts +1 -2
- package/dist/validators/json.js +1 -0
- package/dist/validators/lazy.d.ts +5 -9
- package/dist/validators/lazy.js +1 -0
- package/dist/validators/literal.d.ts +9 -5
- package/dist/validators/literal.js +1 -0
- package/dist/validators/map.d.ts +15 -2
- package/dist/validators/map.js +1 -0
- package/dist/validators/nan.d.ts +2 -3
- package/dist/validators/nan.js +1 -0
- package/dist/validators/never.d.ts +1 -2
- package/dist/validators/never.js +1 -0
- package/dist/validators/null.d.ts +3 -3
- package/dist/validators/null.js +1 -0
- package/dist/validators/number.d.ts +75 -27
- package/dist/validators/number.js +1 -0
- package/dist/validators/object.d.ts +42 -11
- package/dist/validators/object.js +1 -0
- package/dist/validators/promise.d.ts +15 -10
- package/dist/validators/promise.js +1 -0
- package/dist/validators/record.d.ts +21 -9
- package/dist/validators/record.js +1 -0
- package/dist/validators/set.d.ts +11 -2
- package/dist/validators/set.js +1 -0
- package/dist/validators/string-bool.d.ts +7 -10
- package/dist/validators/string-bool.js +1 -0
- package/dist/validators/string-formats.d.ts +64 -65
- package/dist/validators/string-formats.js +1 -0
- package/dist/validators/string.d.ts +84 -26
- package/dist/validators/string.js +1 -0
- package/dist/validators/symbol.d.ts +8 -3
- package/dist/validators/symbol.js +1 -0
- package/dist/validators/template-literal.d.ts +1 -2
- package/dist/validators/template-literal.js +1 -0
- package/dist/validators/tuple.d.ts +29 -12
- package/dist/validators/tuple.js +1 -0
- package/dist/validators/uint8array.d.ts +3 -4
- package/dist/validators/uint8array.js +1 -0
- package/dist/validators/undefined.d.ts +3 -3
- package/dist/validators/undefined.js +1 -0
- package/dist/validators/union.d.ts +7 -4
- package/dist/validators/union.js +1 -0
- package/dist/validators/unknown.d.ts +7 -2
- package/dist/validators/unknown.js +1 -0
- package/dist/validators/void.d.ts +3 -2
- package/dist/validators/void.js +1 -0
- package/dist/validators/xor.d.ts +4 -5
- package/dist/validators/xor.js +1 -0
- package/package.json +239 -154
- package/dist/chunks/bigint-CRS0QVsy.js +0 -1854
- package/dist/chunks/bigint-CRS0QVsy.js.map +0 -1
- package/dist/chunks/date-50JV_Mfj.js +0 -506
- package/dist/chunks/date-50JV_Mfj.js.map +0 -1
- package/dist/chunks/index-DO8CFMxD.js +0 -894
- 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 +0 -28
- 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
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { SchemaRegistry } from '../registry.js';
|
|
1
2
|
/**
|
|
2
3
|
* Base result type for validation
|
|
3
4
|
*/
|
|
@@ -8,6 +9,108 @@ export type ParseResult<T> = {
|
|
|
8
9
|
readonly success: false;
|
|
9
10
|
readonly error: Error;
|
|
10
11
|
};
|
|
12
|
+
export interface StandardTypedV1<Input = unknown, Output = Input> {
|
|
13
|
+
readonly '~standard': StandardTypedV1Props<Input, Output>;
|
|
14
|
+
}
|
|
15
|
+
export interface StandardTypedV1Props<Input = unknown, Output = Input> {
|
|
16
|
+
readonly version: 1;
|
|
17
|
+
readonly vendor: string;
|
|
18
|
+
readonly types?: StandardTypedV1Types<Input, Output> | undefined;
|
|
19
|
+
}
|
|
20
|
+
export interface StandardTypedV1Types<Input = unknown, Output = Input> {
|
|
21
|
+
readonly input: Input;
|
|
22
|
+
readonly output: Output;
|
|
23
|
+
}
|
|
24
|
+
export interface StandardSchemaV1<Input = unknown, Output = Input> extends StandardTypedV1<Input, Output> {
|
|
25
|
+
readonly '~standard': StandardSchemaV1Props<Input, Output>;
|
|
26
|
+
}
|
|
27
|
+
export interface StandardSchemaV1Props<Input = unknown, Output = Input> extends StandardTypedV1Props<Input, Output> {
|
|
28
|
+
readonly validate: (value: unknown, options?: StandardSchemaV1Options | undefined) => StandardSchemaV1Result<Output> | Promise<StandardSchemaV1Result<Output>>;
|
|
29
|
+
}
|
|
30
|
+
export interface StandardSchemaV1Options {
|
|
31
|
+
readonly libraryOptions?: Record<string, unknown> | undefined;
|
|
32
|
+
}
|
|
33
|
+
export type StandardSchemaV1Result<Output> = StandardSchemaV1SuccessResult<Output> | StandardSchemaV1FailureResult;
|
|
34
|
+
export interface StandardSchemaV1SuccessResult<Output> {
|
|
35
|
+
readonly value: Output;
|
|
36
|
+
readonly issues?: undefined;
|
|
37
|
+
}
|
|
38
|
+
export interface StandardSchemaV1FailureResult {
|
|
39
|
+
readonly issues: ReadonlyArray<StandardSchemaV1Issue>;
|
|
40
|
+
}
|
|
41
|
+
export interface StandardSchemaV1Issue {
|
|
42
|
+
readonly message: string;
|
|
43
|
+
readonly path?: ReadonlyArray<PropertyKey | StandardSchemaV1PathSegment> | undefined;
|
|
44
|
+
}
|
|
45
|
+
export interface StandardSchemaV1PathSegment {
|
|
46
|
+
readonly key: PropertyKey;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Validator type constants for O(1) dispatch
|
|
50
|
+
* Used by VldObject to replace instanceof chains with Map lookups
|
|
51
|
+
*/
|
|
52
|
+
export declare const VLD_VALIDATOR_TYPES: {
|
|
53
|
+
readonly STRING: "string";
|
|
54
|
+
readonly STRING_FORMAT: "stringFormat";
|
|
55
|
+
readonly STRING_BOOL: "stringBool";
|
|
56
|
+
readonly NUMBER: "number";
|
|
57
|
+
readonly BOOLEAN: "boolean";
|
|
58
|
+
readonly DATE: "date";
|
|
59
|
+
readonly BIGINT: "bigint";
|
|
60
|
+
readonly UNDEFINED: "undefined";
|
|
61
|
+
readonly NULL: "null";
|
|
62
|
+
readonly UNKNOWN: "unknown";
|
|
63
|
+
readonly ANY: "any";
|
|
64
|
+
readonly VOID: "void";
|
|
65
|
+
readonly NEVER: "never";
|
|
66
|
+
readonly SYMBOL: "symbol";
|
|
67
|
+
readonly NAN: "nan";
|
|
68
|
+
readonly HEX: "hex";
|
|
69
|
+
readonly BASE64: "base64";
|
|
70
|
+
readonly UINT8_ARRAY: "uint8Array";
|
|
71
|
+
readonly COERCE_STRING: "coerceString";
|
|
72
|
+
readonly COERCE_NUMBER: "coerceNumber";
|
|
73
|
+
readonly COERCE_BOOLEAN: "coerceBoolean";
|
|
74
|
+
readonly COERCE_DATE: "coerceDate";
|
|
75
|
+
readonly COERCE_BIGINT: "coerceBigint";
|
|
76
|
+
readonly OBJECT: "object";
|
|
77
|
+
readonly ARRAY: "array";
|
|
78
|
+
readonly TUPLE: "tuple";
|
|
79
|
+
readonly SET: "set";
|
|
80
|
+
readonly MAP: "map";
|
|
81
|
+
readonly RECORD: "record";
|
|
82
|
+
readonly UNION: "union";
|
|
83
|
+
readonly DISCRIMINATED_UNION: "discriminatedUnion";
|
|
84
|
+
readonly INTERSECTION: "intersection";
|
|
85
|
+
readonly XOR: "xor";
|
|
86
|
+
readonly ENUM: "enum";
|
|
87
|
+
readonly LITERAL: "literal";
|
|
88
|
+
readonly LAZY: "lazy";
|
|
89
|
+
readonly CUSTOM: "custom";
|
|
90
|
+
readonly FUNCTION: "function";
|
|
91
|
+
readonly FILE: "file";
|
|
92
|
+
readonly JSON: "json";
|
|
93
|
+
readonly TEMPLATE_LITERAL: "templateLiteral";
|
|
94
|
+
readonly PROMISE: "promise";
|
|
95
|
+
readonly OPTIONAL: "optional";
|
|
96
|
+
readonly NULLABLE: "nullable";
|
|
97
|
+
readonly NULLISH: "nullish";
|
|
98
|
+
readonly EXACT_OPTIONAL: "exactOptional";
|
|
99
|
+
readonly DEFAULT: "default";
|
|
100
|
+
readonly CATCH: "catch";
|
|
101
|
+
readonly REFINE: "refine";
|
|
102
|
+
readonly TRANSFORM: "transform";
|
|
103
|
+
readonly PIPE: "pipe";
|
|
104
|
+
readonly PREPROCESS: "preprocess";
|
|
105
|
+
readonly SUPER_REFINE: "superRefine";
|
|
106
|
+
readonly BRAND: "brand";
|
|
107
|
+
readonly READONLY: "readonly";
|
|
108
|
+
readonly META: "meta";
|
|
109
|
+
readonly PREFAULT: "prefault";
|
|
110
|
+
readonly PREFault: "prefault";
|
|
111
|
+
readonly CODEC: "codec";
|
|
112
|
+
};
|
|
113
|
+
export type ValidatorType = typeof VLD_VALIDATOR_TYPES[keyof typeof VLD_VALIDATOR_TYPES];
|
|
11
114
|
/**
|
|
12
115
|
* Context for superRefine - allows adding multiple issues
|
|
13
116
|
*/
|
|
@@ -18,11 +121,53 @@ export interface SuperRefineContext {
|
|
|
18
121
|
}): void;
|
|
19
122
|
path: (string | number)[];
|
|
20
123
|
}
|
|
124
|
+
export interface CheckPayload<T> {
|
|
125
|
+
value: T;
|
|
126
|
+
issues: Array<{
|
|
127
|
+
message?: string;
|
|
128
|
+
code?: string;
|
|
129
|
+
}>;
|
|
130
|
+
aborted?: boolean;
|
|
131
|
+
}
|
|
132
|
+
export type VldCheck<T> = ((payload: CheckPayload<T>) => void | Promise<void>) | {
|
|
133
|
+
_zod?: {
|
|
134
|
+
check?: (payload: CheckPayload<T>) => void | Promise<void>;
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
export type ErrorMap = (issue: {
|
|
138
|
+
code?: string;
|
|
139
|
+
input?: unknown;
|
|
140
|
+
path?: (string | number)[];
|
|
141
|
+
}) => string | undefined;
|
|
142
|
+
export type ErrorParam = string | {
|
|
143
|
+
error?: string | ErrorMap;
|
|
144
|
+
message?: string;
|
|
145
|
+
};
|
|
146
|
+
export declare function resolveErrorMessage(error: ErrorParam | undefined, fallback: string): string;
|
|
147
|
+
type ValueOrFactory<T> = T | (() => T);
|
|
148
|
+
interface SchemaCompositionFactories {
|
|
149
|
+
array<TInput, TOutput>(schema: VldBase<TInput, TOutput>): VldBase<unknown[], TOutput[]>;
|
|
150
|
+
union<TInput, TOutput, TNext>(left: VldBase<TInput, TOutput>, right: VldBase<any, TNext>): VldBase<unknown, TOutput | TNext>;
|
|
151
|
+
intersection<TInput, TOutput, TNext>(left: VldBase<TInput, TOutput>, right: VldBase<any, TNext>): VldBase<unknown, TOutput & TNext>;
|
|
152
|
+
toJSONSchema(schema: VldBase<any, any>, options?: unknown): unknown;
|
|
153
|
+
}
|
|
154
|
+
export declare function configureSchemaCompositionFactories(factories: SchemaCompositionFactories): void;
|
|
21
155
|
/**
|
|
22
156
|
* Abstract base class for all validators
|
|
23
157
|
* Implements immutable pattern to prevent memory leaks and race conditions
|
|
24
158
|
*/
|
|
25
159
|
export declare abstract class VldBase<TInput, TOutput = TInput> {
|
|
160
|
+
/**
|
|
161
|
+
* Runtime type identifier for O(1) dispatch
|
|
162
|
+
* Used by VldObject instead of instanceof chains
|
|
163
|
+
*/
|
|
164
|
+
readonly validatorType: ValidatorType;
|
|
165
|
+
/**
|
|
166
|
+
* Constructor with runtime type identifier
|
|
167
|
+
* @param validatorType The runtime type identifier
|
|
168
|
+
*/
|
|
169
|
+
constructor(validatorType?: ValidatorType);
|
|
170
|
+
get '~standard'(): StandardSchemaV1Props<unknown, TOutput>;
|
|
26
171
|
/**
|
|
27
172
|
* Parse and validate a value, throwing an error if invalid
|
|
28
173
|
* @param value The value to validate
|
|
@@ -36,6 +181,28 @@ export declare abstract class VldBase<TInput, TOutput = TInput> {
|
|
|
36
181
|
* @returns A result object with either success and data, or failure and error
|
|
37
182
|
*/
|
|
38
183
|
abstract safeParse(value: unknown): ParseResult<TOutput>;
|
|
184
|
+
parseAsync(value: unknown): Promise<TOutput>;
|
|
185
|
+
safeParseAsync(value: unknown): Promise<ParseResult<TOutput>>;
|
|
186
|
+
/** Strongly typed forward parse aliases from the Zod 4 codec API. */
|
|
187
|
+
decode(value: TInput): TOutput;
|
|
188
|
+
safeDecode(value: TInput): ParseResult<TOutput>;
|
|
189
|
+
decodeAsync(value: TInput): Promise<TOutput>;
|
|
190
|
+
safeDecodeAsync(value: TInput): Promise<ParseResult<TOutput>>;
|
|
191
|
+
/**
|
|
192
|
+
* Backward parse aliases. Primitive and validation-only schemas are
|
|
193
|
+
* bidirectional; codecs override these methods with their inverse transform.
|
|
194
|
+
*/
|
|
195
|
+
encode(value: TOutput): TInput;
|
|
196
|
+
safeEncode(value: TOutput): ParseResult<TInput>;
|
|
197
|
+
encodeAsync(value: TOutput): Promise<TInput>;
|
|
198
|
+
safeEncodeAsync(value: TOutput): Promise<ParseResult<TInput>>;
|
|
199
|
+
/** Zod's short alias for safeParseAsync. */
|
|
200
|
+
spa(value: unknown): Promise<ParseResult<TOutput>>;
|
|
201
|
+
/** Compatibility helpers retained by Zod 4. */
|
|
202
|
+
isOptional(): boolean;
|
|
203
|
+
isNullable(): boolean;
|
|
204
|
+
/** VLD validators are immutable, so cloning can safely share the instance. */
|
|
205
|
+
clone(): this;
|
|
39
206
|
/**
|
|
40
207
|
* Check if a value is valid according to this validator
|
|
41
208
|
* @param value The value to check
|
|
@@ -57,7 +224,7 @@ export declare abstract class VldBase<TInput, TOutput = TInput> {
|
|
|
57
224
|
* @returns A new refined validator
|
|
58
225
|
*/
|
|
59
226
|
refine<TRefined extends TOutput>(predicate: (value: TOutput) => value is TRefined, message?: string): VldRefine<TInput, TOutput, TRefined>;
|
|
60
|
-
refine(predicate: (value: TOutput) => boolean
|
|
227
|
+
refine(predicate: (value: TOutput) => boolean | Promise<boolean>, message?: string): VldRefine<TInput, TOutput, TOutput>;
|
|
61
228
|
/**
|
|
62
229
|
* Advanced refinement with context for adding multiple issues
|
|
63
230
|
* @param refinement The refinement function with context
|
|
@@ -69,13 +236,22 @@ export declare abstract class VldBase<TInput, TOutput = TInput> {
|
|
|
69
236
|
* @param transformer The transformation function
|
|
70
237
|
* @returns A new transformed validator
|
|
71
238
|
*/
|
|
72
|
-
transform<TTransformed>(transformer: (value: TOutput) => TTransformed): VldTransform<TInput, TOutput, TTransformed>;
|
|
239
|
+
transform<TTransformed>(transformer: (value: TOutput) => TTransformed | Promise<TTransformed>): VldTransform<TInput, TOutput, TTransformed>;
|
|
73
240
|
/**
|
|
74
241
|
* Create a new validator with a default value for undefined inputs
|
|
75
242
|
* @param defaultValue The default value
|
|
76
243
|
* @returns A new validator with default
|
|
77
244
|
*/
|
|
78
|
-
default(defaultValue: TOutput): VldDefault<TInput, TOutput>;
|
|
245
|
+
default(defaultValue: ValueOrFactory<TOutput>): VldDefault<TInput, TOutput>;
|
|
246
|
+
/** Provide an input value before parsing when the input is undefined. */
|
|
247
|
+
prefault(defaultValue: ValueOrFactory<TInput>): VldPrefault<TInput, TOutput>;
|
|
248
|
+
nonoptional(message?: ErrorParam): VldRefine<TInput, TOutput, TOutput>;
|
|
249
|
+
array(): VldBase<unknown[], TOutput[]>;
|
|
250
|
+
or<TNext>(option: VldBase<any, TNext>): VldBase<unknown, TOutput | TNext>;
|
|
251
|
+
and<TNext>(incoming: VldBase<any, TNext>): VldBase<unknown, TOutput & TNext>;
|
|
252
|
+
overwrite(transformer: (value: TOutput) => TOutput): VldTransform<TInput, TOutput, TOutput>;
|
|
253
|
+
with(...checks: VldCheck<TOutput>[]): VldSuperRefine<TInput, TOutput>;
|
|
254
|
+
toJSONSchema(options?: unknown): unknown;
|
|
79
255
|
/**
|
|
80
256
|
* Create a new validator that catches errors and returns a fallback
|
|
81
257
|
* @param fallbackValue The fallback value
|
|
@@ -110,7 +286,7 @@ export declare abstract class VldBase<TInput, TOutput = TInput> {
|
|
|
110
286
|
* @param next The next validator to pipe into
|
|
111
287
|
* @returns A new piped validator
|
|
112
288
|
*/
|
|
113
|
-
pipe<TNextOutput>(next: VldBase<
|
|
289
|
+
pipe<TNextOutput>(next: VldBase<any, TNextOutput>): VldPipe<TInput, TOutput, TNextOutput>;
|
|
114
290
|
/**
|
|
115
291
|
* Create a new validator that returns readonly output
|
|
116
292
|
* Zod 4 API parity - marks output as readonly for TypeScript
|
|
@@ -140,7 +316,7 @@ export declare abstract class VldBase<TInput, TOutput = TInput> {
|
|
|
140
316
|
* const withLength = (schema: VldBase<unknown, string>) => schema.transform(s => s.length);
|
|
141
317
|
* const lengthSchema = v.string().apply(withLength); // validates string, returns number
|
|
142
318
|
*/
|
|
143
|
-
apply<
|
|
319
|
+
apply<TResult>(fn: (schema: this) => TResult): TResult;
|
|
144
320
|
/**
|
|
145
321
|
* Create a new validator that refines this one with a custom predicate
|
|
146
322
|
* Alias for refine() - check() is the Zod 4 API name
|
|
@@ -149,7 +325,7 @@ export declare abstract class VldBase<TInput, TOutput = TInput> {
|
|
|
149
325
|
* @returns A new refined validator
|
|
150
326
|
*/
|
|
151
327
|
check<TRefined extends TOutput>(predicate: (value: TOutput) => value is TRefined, message?: string): VldRefine<TInput, TOutput, TRefined>;
|
|
152
|
-
check(predicate: (value: TOutput) => boolean
|
|
328
|
+
check(predicate: (value: TOutput) => boolean | Promise<boolean>, message?: string): VldRefine<TInput, TOutput, TOutput>;
|
|
153
329
|
/**
|
|
154
330
|
* Get metadata for this schema
|
|
155
331
|
* Zod 4 API parity - allows attaching OpenAPI/JSON Schema metadata
|
|
@@ -163,6 +339,12 @@ export declare abstract class VldBase<TInput, TOutput = TInput> {
|
|
|
163
339
|
* @returns A new validator with the metadata
|
|
164
340
|
*/
|
|
165
341
|
meta(data: Partial<SchemaMetadata>): VldMeta<TInput, TOutput>;
|
|
342
|
+
/**
|
|
343
|
+
* Register this schema in a metadata registry and return the same instance.
|
|
344
|
+
* This mirrors Zod 4's registry convenience API without changing validator
|
|
345
|
+
* immutability.
|
|
346
|
+
*/
|
|
347
|
+
register<TMetadata extends Record<string, unknown>>(targetRegistry: SchemaRegistry<TMetadata>, metadata: TMetadata): this;
|
|
166
348
|
/**
|
|
167
349
|
* Add a description to this schema
|
|
168
350
|
* Zod 4 API parity - convenience method for .meta({ description: ... })
|
|
@@ -170,6 +352,7 @@ export declare abstract class VldBase<TInput, TOutput = TInput> {
|
|
|
170
352
|
* @returns A new validator with the description
|
|
171
353
|
*/
|
|
172
354
|
describe(description: string): VldMeta<TInput, TOutput>;
|
|
355
|
+
get description(): string | undefined;
|
|
173
356
|
}
|
|
174
357
|
/**
|
|
175
358
|
* Schema metadata interface for OpenAPI/JSON Schema compatibility
|
|
@@ -198,6 +381,9 @@ export declare class VldMeta<TInput, TOutput> extends VldBase<TInput, TOutput> {
|
|
|
198
381
|
* Get the metadata
|
|
199
382
|
*/
|
|
200
383
|
getMeta(): Readonly<Partial<SchemaMetadata>>;
|
|
384
|
+
meta(): SchemaMetadata | undefined;
|
|
385
|
+
meta(data: Partial<SchemaMetadata>): VldMeta<TInput, TOutput>;
|
|
386
|
+
describe(description: string): VldMeta<TInput, TOutput>;
|
|
201
387
|
}
|
|
202
388
|
/**
|
|
203
389
|
* Readonly validator - marks output as readonly
|
|
@@ -231,9 +417,10 @@ export declare class VldRefine<TInput, TBase, TOutput extends TBase = TBase> ext
|
|
|
231
417
|
private readonly baseValidator;
|
|
232
418
|
private readonly predicate;
|
|
233
419
|
private readonly customMessage?;
|
|
234
|
-
constructor(baseValidator: VldBase<TInput, TBase>, predicate: (value: TBase) => boolean
|
|
420
|
+
constructor(baseValidator: VldBase<TInput, TBase>, predicate: (value: TBase) => boolean | Promise<boolean>, customMessage?: string | undefined);
|
|
235
421
|
parse(value: unknown): TOutput;
|
|
236
422
|
safeParse(value: unknown): ParseResult<TOutput>;
|
|
423
|
+
parseAsync(value: unknown): Promise<TOutput>;
|
|
237
424
|
}
|
|
238
425
|
/**
|
|
239
426
|
* Transform validator - transforms data after validation
|
|
@@ -241,9 +428,10 @@ export declare class VldRefine<TInput, TBase, TOutput extends TBase = TBase> ext
|
|
|
241
428
|
export declare class VldTransform<TInput, TBase, TOutput> extends VldBase<TInput, TOutput> {
|
|
242
429
|
private readonly baseValidator;
|
|
243
430
|
private readonly transformer;
|
|
244
|
-
constructor(baseValidator: VldBase<TInput, TBase>, transformer: (value: TBase) => TOutput);
|
|
431
|
+
constructor(baseValidator: VldBase<TInput, TBase>, transformer: (value: TBase) => TOutput | Promise<TOutput>);
|
|
245
432
|
parse(value: unknown): TOutput;
|
|
246
433
|
safeParse(value: unknown): ParseResult<TOutput>;
|
|
434
|
+
parseAsync(value: unknown): Promise<TOutput>;
|
|
247
435
|
}
|
|
248
436
|
/**
|
|
249
437
|
* Default validator - provides default value for undefined
|
|
@@ -253,14 +441,16 @@ export declare class VldTransform<TInput, TBase, TOutput> extends VldBase<TInput
|
|
|
253
441
|
export declare class VldDefault<TInput, TOutput> extends VldBase<TInput | undefined, TOutput> {
|
|
254
442
|
private readonly baseValidator;
|
|
255
443
|
private readonly defaultValue;
|
|
256
|
-
constructor(baseValidator: VldBase<TInput, TOutput>, defaultValue: TOutput);
|
|
444
|
+
constructor(baseValidator: VldBase<TInput, TOutput>, defaultValue: ValueOrFactory<TOutput>);
|
|
257
445
|
parse(value: unknown): TOutput;
|
|
258
446
|
safeParse(value: unknown): ParseResult<TOutput>;
|
|
259
447
|
/**
|
|
260
448
|
* Pre-parse default - validates the default value instead of returning it directly
|
|
261
449
|
* This is useful when the default value needs to be validated against the schema
|
|
262
450
|
*/
|
|
263
|
-
prefault(): VldPrefault<TInput, TOutput>;
|
|
451
|
+
prefault(defaultValue?: ValueOrFactory<TInput>): VldPrefault<TInput, TOutput>;
|
|
452
|
+
unwrap(): VldBase<TInput, TOutput>;
|
|
453
|
+
removeDefault(): VldBase<TInput, TOutput>;
|
|
264
454
|
}
|
|
265
455
|
/**
|
|
266
456
|
* Prefault validator - validates the default value instead of returning it directly
|
|
@@ -268,13 +458,14 @@ export declare class VldDefault<TInput, TOutput> extends VldBase<TInput | undefi
|
|
|
268
458
|
export declare class VldPrefault<TInput, TOutput> extends VldBase<TInput | undefined, TOutput> {
|
|
269
459
|
private readonly baseValidator;
|
|
270
460
|
private readonly defaultValue;
|
|
271
|
-
constructor(baseValidator: VldBase<TInput, TOutput>, defaultValue:
|
|
461
|
+
constructor(baseValidator: VldBase<TInput, TOutput>, defaultValue: ValueOrFactory<TInput>);
|
|
272
462
|
parse(value: unknown): TOutput;
|
|
273
463
|
safeParse(value: unknown): ParseResult<TOutput>;
|
|
274
464
|
/**
|
|
275
465
|
* Calling prefault multiple times should be safe - return self
|
|
276
466
|
*/
|
|
277
|
-
prefault(): VldPrefault<TInput, TOutput>;
|
|
467
|
+
prefault(defaultValue?: ValueOrFactory<TInput>): VldPrefault<TInput, TOutput>;
|
|
468
|
+
unwrap(): VldBase<TInput, TOutput>;
|
|
278
469
|
}
|
|
279
470
|
/**
|
|
280
471
|
* Catch validator - provides fallback value on validation error
|
|
@@ -283,6 +474,7 @@ export declare class VldPrefault<TInput, TOutput> extends VldBase<TInput | undef
|
|
|
283
474
|
export declare class VldCatch<TInput, TOutput> extends VldBase<TInput, TOutput> {
|
|
284
475
|
private readonly baseValidator;
|
|
285
476
|
private readonly fallbackValue;
|
|
477
|
+
private readonly simpleMode;
|
|
286
478
|
constructor(baseValidator: VldBase<TInput, TOutput>, fallbackValue: TOutput);
|
|
287
479
|
parse(value: unknown): TOutput;
|
|
288
480
|
safeParse(value: unknown): ParseResult<TOutput>;
|
|
@@ -292,7 +484,9 @@ export declare class VldCatch<TInput, TOutput> extends VldBase<TInput, TOutput>
|
|
|
292
484
|
*/
|
|
293
485
|
export declare class VldOptional<TInput, TOutput> extends VldBase<TInput | undefined, TOutput | undefined> {
|
|
294
486
|
private readonly baseValidator;
|
|
487
|
+
private readonly simpleMode;
|
|
295
488
|
constructor(baseValidator: VldBase<TInput, TOutput>);
|
|
489
|
+
private parseSimpleValue;
|
|
296
490
|
static create<TInput, TOutput>(baseValidator: VldBase<TInput, TOutput>): VldOptional<TInput, TOutput>;
|
|
297
491
|
parse(value: unknown): TOutput | undefined;
|
|
298
492
|
safeParse(value: unknown): ParseResult<TOutput | undefined>;
|
|
@@ -306,6 +500,7 @@ export declare class VldOptional<TInput, TOutput> extends VldBase<TInput | undef
|
|
|
306
500
|
*/
|
|
307
501
|
export declare class VldExactOptional<TInput, TOutput> extends VldBase<TInput | undefined, TOutput | undefined> {
|
|
308
502
|
private readonly baseValidator;
|
|
503
|
+
private readonly simpleMode;
|
|
309
504
|
constructor(baseValidator: VldBase<TInput, TOutput>);
|
|
310
505
|
static create<TInput, TOutput>(baseValidator: VldBase<TInput, TOutput>): VldExactOptional<TInput, TOutput>;
|
|
311
506
|
parse(value: unknown): TOutput | undefined;
|
|
@@ -317,6 +512,7 @@ export declare class VldExactOptional<TInput, TOutput> extends VldBase<TInput |
|
|
|
317
512
|
*/
|
|
318
513
|
export declare class VldNullable<TInput, TOutput> extends VldBase<TInput | null, TOutput | null> {
|
|
319
514
|
private readonly baseValidator;
|
|
515
|
+
private readonly simpleMode;
|
|
320
516
|
constructor(baseValidator: VldBase<TInput, TOutput>);
|
|
321
517
|
static create<TInput, TOutput>(baseValidator: VldBase<TInput, TOutput>): VldNullable<TInput, TOutput>;
|
|
322
518
|
parse(value: unknown): TOutput | null;
|
|
@@ -328,6 +524,7 @@ export declare class VldNullable<TInput, TOutput> extends VldBase<TInput | null,
|
|
|
328
524
|
*/
|
|
329
525
|
export declare class VldNullish<TInput, TOutput> extends VldBase<TInput | null | undefined, TOutput | null | undefined> {
|
|
330
526
|
private readonly baseValidator;
|
|
527
|
+
private readonly simpleMode;
|
|
331
528
|
constructor(baseValidator: VldBase<TInput, TOutput>);
|
|
332
529
|
static create<TInput, TOutput>(baseValidator: VldBase<TInput, TOutput>): VldNullish<TInput, TOutput>;
|
|
333
530
|
parse(value: unknown): TOutput | null | undefined;
|
|
@@ -340,7 +537,7 @@ export declare class VldNullish<TInput, TOutput> extends VldBase<TInput | null |
|
|
|
340
537
|
export declare class VldPipe<TInput, TIntermediate, TOutput> extends VldBase<TInput, TOutput> {
|
|
341
538
|
private readonly first;
|
|
342
539
|
private readonly second;
|
|
343
|
-
constructor(first: VldBase<TInput, TIntermediate>, second: VldBase<
|
|
540
|
+
constructor(first: VldBase<TInput, TIntermediate>, second: VldBase<any, TOutput>);
|
|
344
541
|
parse(value: unknown): TOutput;
|
|
345
542
|
safeParse(value: unknown): ParseResult<TOutput>;
|
|
346
543
|
}
|
|
@@ -353,6 +550,8 @@ export declare class VldSuperRefine<TInput, TOutput> extends VldBase<TInput, TOu
|
|
|
353
550
|
constructor(_inner: VldBase<TInput, TOutput>, _refinement: (value: TOutput, ctx: SuperRefineContext) => void | Promise<void>);
|
|
354
551
|
parse(value: unknown): TOutput;
|
|
355
552
|
safeParse(value: unknown): ParseResult<TOutput>;
|
|
553
|
+
parseAsync(value: unknown): Promise<TOutput>;
|
|
554
|
+
safeParseAsync(value: unknown): Promise<ParseResult<TOutput>>;
|
|
356
555
|
}
|
|
357
556
|
/**
|
|
358
557
|
* Preprocess validator - transforms input before validation
|
|
@@ -365,4 +564,4 @@ export declare class VldPreprocess<TInput, TOutput> extends VldBase<unknown, TOu
|
|
|
365
564
|
parse(value: unknown): TOutput;
|
|
366
565
|
safeParse(value: unknown): ParseResult<TOutput>;
|
|
367
566
|
}
|
|
368
|
-
|
|
567
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{globalRegistry as e}from"../registry.js";const s={STRING:"string",STRING_FORMAT:"stringFormat",STRING_BOOL:"stringBool",NUMBER:"number",BOOLEAN:"boolean",DATE:"date",BIGINT:"bigint",UNDEFINED:"undefined",NULL:"null",UNKNOWN:"unknown",ANY:"any",VOID:"void",NEVER:"never",SYMBOL:"symbol",NAN:"nan",HEX:"hex",BASE64:"base64",UINT8_ARRAY:"uint8Array",COERCE_STRING:"coerceString",COERCE_NUMBER:"coerceNumber",COERCE_BOOLEAN:"coerceBoolean",COERCE_DATE:"coerceDate",COERCE_BIGINT:"coerceBigint",OBJECT:"object",ARRAY:"array",TUPLE:"tuple",SET:"set",MAP:"map",RECORD:"record",UNION:"union",DISCRIMINATED_UNION:"discriminatedUnion",INTERSECTION:"intersection",XOR:"xor",ENUM:"enum",LITERAL:"literal",LAZY:"lazy",CUSTOM:"custom",FUNCTION:"function",FILE:"file",JSON:"json",TEMPLATE_LITERAL:"templateLiteral",PROMISE:"promise",OPTIONAL:"optional",NULLABLE:"nullable",NULLISH:"nullish",EXACT_OPTIONAL:"exactOptional",DEFAULT:"default",CATCH:"catch",REFINE:"refine",TRANSFORM:"transform",PIPE:"pipe",PREPROCESS:"preprocess",SUPER_REFINE:"superRefine",BRAND:"brand",READONLY:"readonly",META:"meta",PREFAULT:"prefault",PREFault:"prefault",CODEC:"codec"};function r(e,s){return"string"==typeof e?e:"string"==typeof e?.error?e.error:"function"==typeof e?.error?e.error({})||s:"string"==typeof e?.message?e.message:s}function t(e){return null!==e&&("object"==typeof e||"function"==typeof e)&&"function"==typeof e.then}let a;function n(e){a=e}function i(e){return"function"==typeof e?e():function(e){if(Array.isArray(e))return[...e];if(e instanceof Map)return new Map(e);if(e instanceof Set)return new Set(e);if(null!==e&&"object"==typeof e){const s=Object.getPrototypeOf(e);if(s===Object.prototype||null===s)return{...e}}return e}(e)}function o(e){if(!0===e.isSimple)switch(e.validatorType){case s.STRING:return"string";case s.NUMBER:return"number";case s.BOOLEAN:return"boolean";case s.BIGINT:return"bigint";case s.SYMBOL:return"symbol";default:return}}function c(e,s){switch(e){case"string":return"string"==typeof s?s:void 0;case"number":return"number"!=typeof s||isNaN(s)?void 0:s;case"boolean":return"boolean"==typeof s?s:void 0;case"bigint":return"bigint"==typeof s?s:void 0;case"symbol":return"symbol"==typeof s?s:void 0;default:return}}class VldBase{constructor(e="unknown"){this.validatorType=e}get"~standard"(){return{version:1,vendor:"vld",validate:e=>{const s=this.safeParse(e);return s.success?{value:s.data}:{issues:[{message:s.error.message}]}},types:void 0}}async parseAsync(e){return this.parse(e)}async safeParseAsync(e){try{return{success:!0,data:await this.parseAsync(e)}}catch(e){return{success:!1,error:e}}}decode(e){return this.parse(e)}safeDecode(e){return this.safeParse(e)}async decodeAsync(e){return this.parseAsync(e)}async safeDecodeAsync(e){return this.safeParseAsync(e)}encode(e){return this.parse(e)}safeEncode(e){const s=this.safeParse(e);return s.success?{success:!0,data:s.data}:s}async encodeAsync(e){return this.parseAsync(e)}async safeEncodeAsync(e){const s=await this.safeParseAsync(e);return s.success?{success:!0,data:s.data}:s}spa(e){return this.safeParseAsync(e)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}clone(){return this}isValid(e){return this.safeParse(e).success}parseOrDefault(e,s){const r=this.safeParse(e);if(r.success)return r.data;const t=this.safeParse(s);if(!t.success)throw new Error(`Invalid default value provided: ${t.error.message}`);return t.data}refine(e,s){return new VldRefine(this,e,s)}superRefine(e){return new VldSuperRefine(this,e)}transform(e){return new VldTransform(this,e)}default(e){return new VldDefault(this,e)}prefault(e){return new VldPrefault(this,e)}nonoptional(e){return new VldRefine(this,e=>void 0!==e,r(e,"Expected non-optional value"))}array(){return a.array(this)}or(e){return a.union(this,e)}and(e){return a.intersection(this,e)}overwrite(e){return new VldTransform(this,e)}with(...e){return new VldSuperRefine(this,(s,r)=>{const a={value:s,issues:[]},n=[];for(const s of e){const e="function"==typeof s?s:s._zod?.check;if(!e)continue;const r=e(a);t(r)&&n.push(Promise.resolve(r))}const i=()=>{for(const e of a.issues)r.addIssue(void 0===e.code?{message:e.message||"Custom check failed"}:{message:e.message||"Custom check failed",code:e.code})};if(n.length>0)return Promise.all(n).then(i);i()})}toJSONSchema(e){return a.toJSONSchema(this,e)}catch(e){return new VldCatch(this,e)}optional(){return new VldOptional(this)}nullable(){return new VldNullable(this)}nullish(){return new VldNullish(this)}exactOptional(){return new VldExactOptional(this)}pipe(e){return new VldPipe(this,e)}readonly(){return new VldReadonly(this)}brand(){return new VldBrand(this)}apply(e){return e(this)}check(e,s){return new VldRefine(this,e,s)}meta(s){if(void 0===s)return e.get(this);const r=new VldMeta(this,s);return e.add(r,s),r}register(e,s){return e.add(this,s),this}describe(e){return this.meta({description:e})}get description(){return this.meta()?.description}}class VldMeta extends VldBase{constructor(e,r){super(s.META),this.baseValidator=e,this.metadata=r}parse(e){return this.baseValidator.parse(e)}safeParse(e){return this.baseValidator.safeParse(e)}getMeta(){return{...this.metadata}}meta(s){if(void 0===s)return{...this.metadata,...e.get(this)};const r=new VldMeta(this.baseValidator,{...this.metadata,...s});return e.add(r,r.getMeta()),r}describe(e){return this.meta({description:e})}}class VldReadonly extends VldBase{constructor(e){super(s.READONLY),this.baseValidator=e}parse(e){return this.baseValidator.parse(e)}safeParse(e){const s=this.baseValidator.safeParse(e);return s.success?{success:!0,data:s.data}:{success:!1,error:s.error}}}class VldBrand extends VldBase{constructor(e){super(s.BRAND),this.baseValidator=e}parse(e){return this.baseValidator.parse(e)}safeParse(e){const s=this.baseValidator.safeParse(e);return s.success?{success:!0,data:s.data}:{success:!1,error:s.error}}}class VldRefine extends VldBase{constructor(e,r,t){super(s.REFINE),this.baseValidator=e,this.predicate=r,this.customMessage=t}parse(e){const s=this.baseValidator.parse(e),r=this.predicate(s);if(t(r))throw new Error("Use parseAsync for async refinements");if(!r)throw new Error(this.customMessage||"Refinement check failed");return s}safeParse(e){try{return{success:!0,data:this.parse(e)}}catch(e){return{success:!1,error:e}}}async parseAsync(e){const s=await this.baseValidator.parseAsync(e);if(!await this.predicate(s))throw new Error(this.customMessage||"Refinement check failed");return s}}class VldTransform extends VldBase{constructor(e,r){super(s.TRANSFORM),this.baseValidator=e,this.transformer=r}parse(e){const s=this.baseValidator.parse(e);try{const e=this.transformer(s);if(t(e))throw new Error("Use parseAsync for async transforms");return e}catch(e){throw new Error(`Transform failed: ${e.message}`)}}safeParse(e){try{return{success:!0,data:this.parse(e)}}catch(e){return{success:!1,error:e}}}async parseAsync(e){const s=await this.baseValidator.parseAsync(e);try{return await this.transformer(s)}catch(e){throw new Error(`Transform failed: ${e.message}`)}}}class VldDefault extends VldBase{constructor(e,r){super(s.DEFAULT),this.baseValidator=e,this.defaultValue=r}parse(e){return void 0===e?i(this.defaultValue):this.baseValidator.parse(e)}safeParse(e){return void 0===e?{success:!0,data:i(this.defaultValue)}:this.baseValidator.safeParse(e)}prefault(e){return new VldPrefault(this.baseValidator,void 0===e?this.defaultValue:e)}unwrap(){return this.baseValidator}removeDefault(){return this.baseValidator}}class VldPrefault extends VldBase{constructor(e,r){super(s.PREFAULT),this.baseValidator=e,this.defaultValue=r}parse(e){return void 0===e?this.baseValidator.parse(i(this.defaultValue)):this.baseValidator.parse(e)}safeParse(e){return void 0===e?this.baseValidator.safeParse(i(this.defaultValue)):this.baseValidator.safeParse(e)}prefault(e){return void 0===e?this:new VldPrefault(this.baseValidator,e)}unwrap(){return this.baseValidator}}class VldCatch extends VldBase{constructor(e,r){super(s.CATCH),this.baseValidator=e,this.fallbackValue=r,this.simpleMode=o(e);const t=e.safeParse(r);if(!t.success)throw new Error(`Invalid fallback value: ${t.error.message}`)}parse(e){const s=c(this.simpleMode,e);if(void 0!==s)return s;if(void 0!==this.simpleMode)return this.fallbackValue;try{return this.baseValidator.parse(e)}catch{return this.fallbackValue}}safeParse(e){const s=c(this.simpleMode,e);if(void 0!==s)return{success:!0,data:s};if(void 0!==this.simpleMode)return{success:!0,data:this.fallbackValue};const r=this.baseValidator.safeParse(e);return r.success?r:{success:!0,data:this.fallbackValue}}}class VldOptional extends VldBase{constructor(e){super(s.OPTIONAL),this.baseValidator=e,this.simpleMode=o(e)}parseSimpleValue(e){return c(this.simpleMode,e)}static create(e){return new VldOptional(e)}parse(e){if(void 0===e)return;const s=this.parseSimpleValue(e);return void 0!==s?s:this.baseValidator.parse(e)}safeParse(e){if(void 0===e)return{success:!0,data:void 0};const s=this.parseSimpleValue(e);return void 0!==s?{success:!0,data:s}:this.baseValidator.safeParse(e)}unwrap(){return this.baseValidator}}class VldExactOptional extends VldBase{constructor(e){super(s.EXACT_OPTIONAL),this.baseValidator=e,this.simpleMode=o(e)}static create(e){return new VldExactOptional(e)}parse(e){if(void 0===e)return;const s=c(this.simpleMode,e);return void 0!==s?s:this.baseValidator.parse(e)}safeParse(e){if(void 0===e)return{success:!0,data:void 0};const s=c(this.simpleMode,e);return void 0!==s?{success:!0,data:s}:this.baseValidator.safeParse(e)}unwrap(){return this.baseValidator}}class VldNullable extends VldBase{constructor(e){super(s.NULLABLE),this.baseValidator=e,this.simpleMode=o(e)}static create(e){return new VldNullable(e)}parse(e){if(null===e)return null;const s=c(this.simpleMode,e);return void 0!==s?s:this.baseValidator.parse(e)}safeParse(e){if(null===e)return{success:!0,data:null};const s=c(this.simpleMode,e);return void 0!==s?{success:!0,data:s}:this.baseValidator.safeParse(e)}unwrap(){return this.baseValidator}}class VldNullish extends VldBase{constructor(e){super(s.NULLISH),this.baseValidator=e,this.simpleMode=o(e)}static create(e){return new VldNullish(e)}parse(e){if(null==e)return e;const s=c(this.simpleMode,e);return void 0!==s?s:this.baseValidator.parse(e)}safeParse(e){if(null==e)return{success:!0,data:e};const s=c(this.simpleMode,e);return void 0!==s?{success:!0,data:s}:this.baseValidator.safeParse(e)}unwrap(){return this.baseValidator}}class VldPipe extends VldBase{constructor(e,r){super(s.PIPE),this.first=e,this.second=r}parse(e){const s=this.first.parse(e);return this.second.parse(s)}safeParse(e){const s=this.first.safeParse(e);return s.success?this.second.safeParse(s.data):{success:!1,error:s.error}}}class VldSuperRefine extends VldBase{constructor(e,r){super(s.SUPER_REFINE),this._inner=e,this._refinement=r}parse(e){const s=this._inner.parse(e),r=[],t={addIssue:e=>r.push(e),path:[]};if(this._refinement(s,t)instanceof Promise)throw new Error("Use parseAsync for async refinements");if(r.length>0)throw new Error(r.map(e=>e.message).join("; "));return s}safeParse(e){const s=this._inner.safeParse(e);if(!s.success)return{success:!1,error:s.error};const r=[],t={addIssue:e=>r.push(e),path:[]};if(this._refinement(s.data,t)instanceof Promise)throw new Error("Use safeParseAsync for async refinements");return r.length>0?{success:!1,error:new Error(r.map(e=>e.message).join("; "))}:s}async parseAsync(e){const s=await this._inner.parseAsync(e),r=[],t={addIssue:e=>r.push(e),path:[]};if(await this._refinement(s,t),r.length>0)throw new Error(r.map(e=>e.message).join("; "));return s}async safeParseAsync(e){try{return{success:!0,data:await this.parseAsync(e)}}catch(e){return{success:!1,error:e}}}}class VldPreprocess extends VldBase{constructor(e,r){super(s.PREPROCESS),this._preprocessor=e,this._schema=r}static create(e,s){return new VldPreprocess(e,s)}parse(e){const s=this._preprocessor(e);return this._schema.parse(s)}safeParse(e){try{const s=this._preprocessor(e);return this._schema.safeParse(s)}catch(e){return{success:!1,error:e}}}}export{s as VLD_VALIDATOR_TYPES,VldBase,VldBrand,VldCatch,VldDefault,VldExactOptional,VldMeta,VldNullable,VldNullish,VldOptional,VldPipe,VldPrefault,VldPreprocess,VldReadonly,VldRefine,VldSuperRefine,VldTransform,n as configureSchemaCompositionFactories,r as resolveErrorMessage};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { VldBase, ParseResult } from './base';
|
|
1
|
+
import { VldBase, ParseResult } from './base.js';
|
|
2
2
|
/**
|
|
3
3
|
* Base64 string validator
|
|
4
4
|
*/
|
|
@@ -15,4 +15,3 @@ export declare class VldBase64 extends VldBase<string, string> {
|
|
|
15
15
|
urlSafeMode(): VldBase64;
|
|
16
16
|
static create(urlSafe?: boolean): VldBase64;
|
|
17
17
|
}
|
|
18
|
-
//# sourceMappingURL=base64.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{VldBase as e,VLD_VALIDATOR_TYPES as s}from"./base.js";import{createIssue as r}from"../errors.js";import{getMessages as t}from"../locales/runtime.js";import{V as a}from"../chunks/errors-core-Cqi4-9ew.js";class VldBase64 extends e{constructor(e=!1){super(s.BASE64),this.urlSafe=e}parse(e){const s=this.safeParse(e);if(!s.success)throw s.error;return s.data}safeParse(e){if("string"!=typeof e)return{success:!1,error:new a([r("invalid_type",[],t().expectedString)])};return(this.urlSafe?VldBase64.BASE64_URL_REGEX:VldBase64.BASE64_REGEX).test(e)?!this.urlSafe&&e.length>0&&e.length%4!=0?{success:!1,error:new a([r("custom",[],t().invalidBase64)])}:{success:!0,data:e}:{success:!1,error:new a([r("custom",[],t().invalidBase64)])}}urlSafeMode(){return new VldBase64(!0)}static create(e=!1){return new VldBase64(e)}}VldBase64.BASE64_REGEX=/^[A-Za-z0-9+/]*={0,2}$/,VldBase64.BASE64_URL_REGEX=/^[A-Za-z0-9_-]*={0,2}$/;export{VldBase64};
|
|
@@ -1,32 +1,51 @@
|
|
|
1
|
-
import { VldBase, ParseResult } from './base';
|
|
1
|
+
import { VldBase, ParseResult, ValidatorType } from './base.js';
|
|
2
2
|
/**
|
|
3
3
|
* Type for bigint validation check functions
|
|
4
4
|
*/
|
|
5
5
|
type BigIntCheck = (value: bigint) => boolean;
|
|
6
|
+
interface BigIntJSONSchemaHints {
|
|
7
|
+
readonly minimum?: bigint;
|
|
8
|
+
readonly maximum?: bigint;
|
|
9
|
+
readonly exclusiveMinimum?: bigint;
|
|
10
|
+
readonly exclusiveMaximum?: bigint;
|
|
11
|
+
}
|
|
6
12
|
/**
|
|
7
13
|
* Configuration for bigint validator
|
|
8
14
|
*/
|
|
9
15
|
interface BigIntValidatorConfig {
|
|
10
16
|
readonly checks: ReadonlyArray<BigIntCheck>;
|
|
11
|
-
readonly errorMessage
|
|
17
|
+
readonly errorMessage: string | undefined;
|
|
18
|
+
readonly validatorType?: ValidatorType;
|
|
19
|
+
readonly jsonSchema: BigIntJSONSchemaHints | undefined;
|
|
12
20
|
}
|
|
13
21
|
/**
|
|
14
22
|
* Immutable bigint validator
|
|
15
23
|
*/
|
|
16
24
|
export declare class VldBigInt extends VldBase<bigint, bigint> {
|
|
17
25
|
protected readonly config: BigIntValidatorConfig;
|
|
26
|
+
private readonly _checks;
|
|
27
|
+
private readonly _fastCheckMode;
|
|
18
28
|
/**
|
|
19
29
|
* Protected constructor to allow extension while maintaining immutability
|
|
20
30
|
*/
|
|
21
31
|
protected constructor(config?: Partial<BigIntValidatorConfig>);
|
|
32
|
+
get jsonSchema(): BigIntJSONSchemaHints | undefined;
|
|
33
|
+
get isSimple(): boolean;
|
|
22
34
|
/**
|
|
23
35
|
* Create a new bigint validator
|
|
24
36
|
*/
|
|
25
37
|
static create(): VldBigInt;
|
|
38
|
+
private detectFastCheckMode;
|
|
39
|
+
private getValidationError;
|
|
26
40
|
/**
|
|
27
41
|
* Parse and validate a bigint value
|
|
28
42
|
*/
|
|
29
43
|
parse(value: unknown): bigint;
|
|
44
|
+
/**
|
|
45
|
+
* Parse a value that has already passed the bigint type guard.
|
|
46
|
+
* @internal Used by object validators to avoid duplicate hot-path checks.
|
|
47
|
+
*/
|
|
48
|
+
parseKnownBigInt(value: bigint): bigint;
|
|
30
49
|
/**
|
|
31
50
|
* Safely parse and validate a bigint value
|
|
32
51
|
*/
|
|
@@ -77,4 +96,3 @@ export declare class VldBigInt extends VldBase<bigint, bigint> {
|
|
|
77
96
|
lte(value: bigint | number, message?: string): VldBigInt;
|
|
78
97
|
}
|
|
79
98
|
export {};
|
|
80
|
-
//# sourceMappingURL=bigint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{VldBase as e,VLD_VALIDATOR_TYPES as i}from"./base.js";import{getMessages as n}from"../locales/runtime.js";import{V as t}from"../chunks/errors-core-Cqi4-9ew.js";function s(e){return new t([{code:"invalid_type",path:[],message:e}])}class VldBigInt extends e{constructor(e){super(e?.validatorType||i.BIGINT),this.config={checks:e?.checks||[],errorMessage:e?.errorMessage,jsonSchema:e?.jsonSchema},this._checks=this.config.checks,this._fastCheckMode=this.detectFastCheckMode()}get jsonSchema(){return this.config.jsonSchema}get isSimple(){return 0===this._checks.length}static create(){return new VldBigInt}detectFastCheckMode(){if(0===this._checks.length)return"none";if(1!==this._checks.length)return;const e=this.config.jsonSchema;return 0n===e?.exclusiveMinimum&&void 0===e.minimum&&void 0===e.maximum?"positive":0n===e?.exclusiveMaximum&&void 0===e.minimum&&void 0===e.maximum?"negative":0n===e?.minimum&&void 0===e.maximum&&void 0===e.exclusiveMaximum?"nonnegative":0n===e?.maximum&&void 0===e.minimum&&void 0===e.exclusiveMinimum?"nonpositive":void 0}getValidationError(){return new Error(this.config.errorMessage||n().invalidBigint)}parse(e){if("bigint"!=typeof e)throw this.getValidationError();return this.parseKnownBigInt(e)}parseKnownBigInt(e){switch(this._fastCheckMode){case"none":return e;case"positive":if(e>0n)return e;throw this.getValidationError();case"negative":if(e<0n)return e;throw this.getValidationError();case"nonnegative":if(e>=0n)return e;throw this.getValidationError();case"nonpositive":if(e<=0n)return e;throw this.getValidationError()}for(const i of this._checks)if(!i(e))throw this.getValidationError();return e}safeParse(e){if("bigint"!=typeof e)return{success:!1,error:s(this.getValidationError().message)};try{return{success:!0,data:this.parseKnownBigInt(e)}}catch(e){return{success:!1,error:s(e.message)}}}min(e,i){return new VldBigInt({...this.config,checks:[...this.config.checks,i=>i>=e],errorMessage:i||`BigInt must be at least ${e}`,jsonSchema:{...this.config.jsonSchema,minimum:e}})}max(e,i){return new VldBigInt({...this.config,checks:[...this.config.checks,i=>i<=e],errorMessage:i||`BigInt must be at most ${e}`,jsonSchema:{...this.config.jsonSchema,maximum:e}})}positive(e){return new VldBigInt({...this.config,checks:[...this.config.checks,e=>e>0n],errorMessage:e||"BigInt must be positive",jsonSchema:{...this.config.jsonSchema,exclusiveMinimum:0n}})}negative(e){return new VldBigInt({...this.config,checks:[...this.config.checks,e=>e<0n],errorMessage:e||"BigInt must be negative",jsonSchema:{...this.config.jsonSchema,exclusiveMaximum:0n}})}nonnegative(e){return new VldBigInt({...this.config,checks:[...this.config.checks,e=>e>=0n],errorMessage:e||"BigInt must be non-negative",jsonSchema:{...this.config.jsonSchema,minimum:0n}})}nonpositive(e){return new VldBigInt({...this.config,checks:[...this.config.checks,e=>e<=0n],errorMessage:e||"BigInt must be non-positive",jsonSchema:{...this.config.jsonSchema,maximum:0n}})}gt(e,i){const n="bigint"==typeof e?e:BigInt(e);return new VldBigInt({...this.config,checks:[...this.config.checks,e=>e>n],errorMessage:i||`BigInt must be greater than ${n}`,jsonSchema:{...this.config.jsonSchema,exclusiveMinimum:n}})}lt(e,i){const n="bigint"==typeof e?e:BigInt(e);return new VldBigInt({...this.config,checks:[...this.config.checks,e=>e<n],errorMessage:i||`BigInt must be less than ${n}`,jsonSchema:{...this.config.jsonSchema,exclusiveMaximum:n}})}gte(e,i){const n="bigint"==typeof e?e:BigInt(e);return this.min(n,i)}lte(e,i){const n="bigint"==typeof e?e:BigInt(e);return this.max(n,i)}}export{VldBigInt};
|
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
import { VldBase, ParseResult } from './base';
|
|
1
|
+
import { VldBase, ParseResult, ValidatorType } from './base.js';
|
|
2
2
|
/**
|
|
3
3
|
* Immutable boolean validator
|
|
4
4
|
*/
|
|
5
5
|
export declare class VldBoolean extends VldBase<boolean, boolean> {
|
|
6
|
-
private readonly errorMessage
|
|
6
|
+
private readonly errorMessage;
|
|
7
7
|
/**
|
|
8
8
|
* Protected constructor to allow extension while maintaining immutability
|
|
9
9
|
*/
|
|
10
|
-
protected constructor(errorMessage?: string);
|
|
10
|
+
protected constructor(errorMessage?: string, validatorType?: ValidatorType);
|
|
11
|
+
/**
|
|
12
|
+
* Returns true if this is a simple boolean validator with no custom checks
|
|
13
|
+
* Used by VldObject for optimized fast-path dispatch
|
|
14
|
+
*/
|
|
15
|
+
get isSimple(): boolean;
|
|
11
16
|
/**
|
|
12
17
|
* Create a new boolean validator
|
|
13
18
|
*/
|
|
@@ -16,6 +21,11 @@ export declare class VldBoolean extends VldBase<boolean, boolean> {
|
|
|
16
21
|
* Parse and validate a boolean value
|
|
17
22
|
*/
|
|
18
23
|
parse(value: unknown): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Parse a value that has already passed the boolean type guard.
|
|
26
|
+
* @internal Used by object validators to avoid duplicate hot-path checks.
|
|
27
|
+
*/
|
|
28
|
+
parseKnownBoolean(value: boolean): boolean;
|
|
19
29
|
/**
|
|
20
30
|
* Safely parse and validate a boolean value
|
|
21
31
|
*/
|
|
@@ -29,4 +39,3 @@ export declare class VldBoolean extends VldBase<boolean, boolean> {
|
|
|
29
39
|
*/
|
|
30
40
|
false(message?: string): VldBoolean;
|
|
31
41
|
}
|
|
32
|
-
//# sourceMappingURL=boolean.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{VldBase as e,VLD_VALIDATOR_TYPES as s}from"./base.js";import{V as r,c as t,g as a}from"../chunks/errors-core-Cqi4-9ew.js";class VldBoolean extends e{constructor(e,r){super(r||s.BOOLEAN),this.errorMessage=e}get isSimple(){return!0}static create(){return new VldBoolean}parse(e){if("boolean"!=typeof e)throw new r([t("boolean",a(e),this.errorMessage)]);return e}parseKnownBoolean(e){return e}safeParse(e){return"boolean"==typeof e?{success:!0,data:e}:{success:!1,error:new r([t("boolean",a(e),this.errorMessage)])}}true(e){return new VldTrue(e||"Value must be true")}false(e){return new VldFalse(e||"Value must be false")}}class VldTrue extends VldBoolean{constructor(e){super(e),this.message=e}get isSimple(){return!1}parse(e){if(!0!==e)throw new r([{code:"custom",path:[],message:this.message}]);return!0}parseKnownBoolean(e){if(!0!==e)throw new r([{code:"custom",path:[],message:this.message}]);return!0}safeParse(e){return!0!==e?{success:!1,error:new r([{code:"custom",path:[],message:this.message}])}:{success:!0,data:!0}}}class VldFalse extends VldBoolean{constructor(e){super(e),this.message=e}get isSimple(){return!1}parse(e){if(!1!==e)throw new r([{code:"custom",path:[],message:this.message}]);return!1}parseKnownBoolean(e){if(!1!==e)throw new r([{code:"custom",path:[],message:this.message}]);return!1}safeParse(e){return!1!==e?{success:!1,error:new r([{code:"custom",path:[],message:this.message}])}:{success:!0,data:!1}}}export{VldBoolean};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { VldBase, ParseResult } from './base';
|
|
1
|
+
import { VldBase, ParseResult } from './base.js';
|
|
2
2
|
/**
|
|
3
3
|
* Codec transform functions for bidirectional transformations
|
|
4
4
|
*/
|
|
@@ -23,6 +23,10 @@ export declare class VldCodec<TInput, TOutput> extends VldBase<TInput, TOutput>
|
|
|
23
23
|
* Safely parse (decode) a value from input to output format
|
|
24
24
|
*/
|
|
25
25
|
safeParse(value: unknown): ParseResult<TOutput>;
|
|
26
|
+
/**
|
|
27
|
+
* Create a new codec with input and output directions swapped.
|
|
28
|
+
*/
|
|
29
|
+
invert(): VldCodec<TOutput, TInput>;
|
|
26
30
|
/**
|
|
27
31
|
* Encode a value from output back to input format
|
|
28
32
|
*/
|
|
@@ -51,5 +55,8 @@ export declare class VldCodec<TInput, TOutput> extends VldBase<TInput, TOutput>
|
|
|
51
55
|
* Create a codec validator
|
|
52
56
|
*/
|
|
53
57
|
static create<TInput, TOutput>(inputValidator: VldBase<unknown, TInput>, outputValidator: VldBase<unknown, TOutput>, codecTransform: CodecTransform<TInput, TOutput>): VldCodec<TInput, TOutput>;
|
|
58
|
+
/**
|
|
59
|
+
* Create a codec with input and output directions swapped.
|
|
60
|
+
*/
|
|
61
|
+
static invert<TInput, TOutput>(codec: VldCodec<TInput, TOutput>): VldCodec<TOutput, TInput>;
|
|
54
62
|
}
|
|
55
|
-
//# sourceMappingURL=codec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{VldBase as r,VLD_VALIDATOR_TYPES as s}from"./base.js";import{createIssue as e}from"../errors.js";import{getMessages as t}from"../locales/runtime.js";import{V as c}from"../chunks/errors-core-Cqi4-9ew.js";class VldCodec extends r{constructor(r,e,t){super(s.CODEC),this.inputValidator=r,this.outputValidator=e,this.codecTransform=t}parse(r){const s=this.safeParse(r);if(!s.success)throw s.error;return s.data}safeParse(r){const s=this.inputValidator.safeParse(r);if(!s.success)return{success:!1,error:s.error};try{const r=this.codecTransform.decode(s.data);if(r instanceof Promise)throw new c([e("custom",[],t().codecAsyncNotSupported)]);return this.outputValidator.safeParse(r)}catch(r){return r instanceof c?{success:!1,error:r}:{success:!1,error:new c([e("custom",[],t().codecDecodeFailed)])}}}invert(){return new VldCodec(this.outputValidator,this.inputValidator,{decode:this.codecTransform.encode,encode:this.codecTransform.decode})}encode(r){const s=this.safeEncode(r);if(!s.success)throw s.error;return s.data}safeEncode(r){const s=this.outputValidator.safeParse(r);if(!s.success)return{success:!1,error:s.error};try{const r=this.codecTransform.encode(s.data);if(r instanceof Promise)throw new c([e("custom",[],t().codecAsyncNotSupported)]);return this.inputValidator.safeParse(r)}catch(r){return r instanceof c?{success:!1,error:r}:{success:!1,error:new c([e("custom",[],t().codecEncodeFailed)])}}}async parseAsync(r){const s=await this.safeParseAsync(r);if(!s.success)throw s.error;return s.data}async safeParseAsync(r){const s=this.inputValidator.safeParse(r);if(!s.success)return{success:!1,error:s.error};try{const r=await this.codecTransform.decode(s.data);return this.outputValidator.safeParse(r)}catch(r){return r instanceof c?{success:!1,error:r}:{success:!1,error:new c([e("custom",[],t().codecDecodeFailed)])}}}async encodeAsync(r){const s=await this.safeEncodeAsync(r);if(!s.success)throw s.error;return s.data}async safeEncodeAsync(r){const s=this.outputValidator.safeParse(r);if(!s.success)return{success:!1,error:s.error};try{const r=await this.codecTransform.encode(s.data);return this.inputValidator.safeParse(r)}catch(r){return r instanceof c?{success:!1,error:r}:{success:!1,error:new c([e("custom",[],t().codecEncodeFailed)])}}}static create(r,s,e){return new VldCodec(r,s,e)}static invert(r){return r.invert()}}export{VldCodec};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { VldBase, ParseResult } from './base';
|
|
1
|
+
import { VldBase, ParseResult } from './base.js';
|
|
2
2
|
/**
|
|
3
3
|
* Type-safe custom validator options
|
|
4
4
|
*/
|
|
@@ -7,11 +7,21 @@ export interface CustomValidatorOptions<TOutput> {
|
|
|
7
7
|
* Parse function that validates and transforms input
|
|
8
8
|
*/
|
|
9
9
|
parse: (value: unknown) => TOutput;
|
|
10
|
+
/**
|
|
11
|
+
* Optional async parse implementation
|
|
12
|
+
* If not provided, async parsing delegates to parse()
|
|
13
|
+
*/
|
|
14
|
+
parseAsync?: (value: unknown) => Promise<TOutput>;
|
|
10
15
|
/**
|
|
11
16
|
* Optional safeParse implementation
|
|
12
17
|
* If not provided, will use try-catch around parse()
|
|
13
18
|
*/
|
|
14
19
|
safeParse?: (value: unknown) => ParseResult<TOutput>;
|
|
20
|
+
/**
|
|
21
|
+
* Optional async safeParse implementation
|
|
22
|
+
* If not provided, will use try-catch around parseAsync()
|
|
23
|
+
*/
|
|
24
|
+
safeParseAsync?: (value: unknown) => Promise<ParseResult<TOutput>>;
|
|
15
25
|
}
|
|
16
26
|
/**
|
|
17
27
|
* Immutable custom validator for user-defined validation logic
|
|
@@ -19,7 +29,9 @@ export interface CustomValidatorOptions<TOutput> {
|
|
|
19
29
|
*/
|
|
20
30
|
export declare class VldCustom<TOutput = unknown> extends VldBase<unknown, TOutput> {
|
|
21
31
|
private readonly _parseFn;
|
|
32
|
+
private readonly _parseAsyncFn;
|
|
22
33
|
private readonly _safeParseFn;
|
|
34
|
+
private readonly _safeParseAsyncFn;
|
|
23
35
|
private constructor();
|
|
24
36
|
/**
|
|
25
37
|
* Create a new custom validator
|
|
@@ -33,6 +45,8 @@ export declare class VldCustom<TOutput = unknown> extends VldBase<unknown, TOutp
|
|
|
33
45
|
* Safely parse using the custom safeParse function or default implementation
|
|
34
46
|
*/
|
|
35
47
|
safeParse(value: unknown): ParseResult<TOutput>;
|
|
48
|
+
parseAsync(value: unknown): Promise<TOutput>;
|
|
49
|
+
safeParseAsync(value: unknown): Promise<ParseResult<TOutput>>;
|
|
36
50
|
}
|
|
37
51
|
/**
|
|
38
52
|
* Helper function to create custom validators
|
|
@@ -44,4 +58,3 @@ export declare class VldCustom<TOutput = unknown> extends VldBase<unknown, TOutp
|
|
|
44
58
|
* })
|
|
45
59
|
*/
|
|
46
60
|
export declare function custom<TOutput = unknown>(options: CustomValidatorOptions<TOutput>): VldCustom<TOutput>;
|
|
47
|
-
//# sourceMappingURL=custom.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{VldBase as s,VLD_VALIDATOR_TYPES as r}from"./base.js";class VldCustom extends s{constructor(s){super(r.CUSTOM),this._parseFn=s.parse,this._parseAsyncFn=s.parseAsync||(s=>Promise.resolve(this._parseFn(s))),this._safeParseFn=s.safeParse||(s=>{try{return{success:!0,data:this._parseFn(s)}}catch(s){return{success:!1,error:s}}}),this._safeParseAsyncFn=s.safeParseAsync||(async s=>{try{return{success:!0,data:await this._parseAsyncFn(s)}}catch(s){return{success:!1,error:s}}})}static create(s){return new VldCustom(s)}parse(s){return this._parseFn(s)}safeParse(s){return this._safeParseFn(s)}async parseAsync(s){return this._parseAsyncFn(s)}async safeParseAsync(s){return this._safeParseAsyncFn(s)}}function e(s){return VldCustom.create(s)}export{VldCustom,e as custom};
|