@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,200 @@
|
|
|
1
|
+
import { VldBase, VLD_VALIDATOR_TYPES } from './base.js';
|
|
2
|
+
import { createIssue } from '../errors.js';
|
|
3
|
+
import { getMessages } from '../locales/runtime.js';
|
|
4
|
+
import { V as VldError } from '../chunks/errors-core-BeiFUtZM.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Codec validator for bidirectional transformations
|
|
8
|
+
* Enables converting between different data representations
|
|
9
|
+
*/
|
|
10
|
+
class VldCodec extends VldBase {
|
|
11
|
+
constructor(inputValidator, outputValidator, codecTransform) {
|
|
12
|
+
super(VLD_VALIDATOR_TYPES.CODEC);
|
|
13
|
+
this.inputValidator = inputValidator;
|
|
14
|
+
this.outputValidator = outputValidator;
|
|
15
|
+
this.codecTransform = codecTransform;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Parse (decode) a value from input to output format
|
|
19
|
+
*/
|
|
20
|
+
parse(value) {
|
|
21
|
+
const result = this.safeParse(value);
|
|
22
|
+
if (!result.success) {
|
|
23
|
+
throw result.error;
|
|
24
|
+
}
|
|
25
|
+
return result.data;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Safely parse (decode) a value from input to output format
|
|
29
|
+
*/
|
|
30
|
+
safeParse(value) {
|
|
31
|
+
// First validate the input
|
|
32
|
+
const inputResult = this.inputValidator.safeParse(value);
|
|
33
|
+
if (!inputResult.success) {
|
|
34
|
+
return { success: false, error: inputResult.error };
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
// Then decode to output
|
|
38
|
+
const decoded = this.codecTransform.decode(inputResult.data);
|
|
39
|
+
// Handle async decode
|
|
40
|
+
if (decoded instanceof Promise) {
|
|
41
|
+
throw new VldError([
|
|
42
|
+
createIssue('custom', [], getMessages().codecAsyncNotSupported)
|
|
43
|
+
]);
|
|
44
|
+
}
|
|
45
|
+
// Validate the decoded output
|
|
46
|
+
return this.outputValidator.safeParse(decoded);
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
if (error instanceof VldError) {
|
|
50
|
+
return { success: false, error };
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
success: false,
|
|
54
|
+
error: new VldError([
|
|
55
|
+
createIssue('custom', [], getMessages().codecDecodeFailed)
|
|
56
|
+
])
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Create a new codec with input and output directions swapped.
|
|
62
|
+
*/
|
|
63
|
+
invert() {
|
|
64
|
+
return new VldCodec(this.outputValidator, this.inputValidator, {
|
|
65
|
+
decode: this.codecTransform.encode,
|
|
66
|
+
encode: this.codecTransform.decode
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Encode a value from output back to input format
|
|
71
|
+
*/
|
|
72
|
+
encode(value) {
|
|
73
|
+
const result = this.safeEncode(value);
|
|
74
|
+
if (!result.success) {
|
|
75
|
+
throw result.error;
|
|
76
|
+
}
|
|
77
|
+
return result.data;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Safely encode a value from output back to input format
|
|
81
|
+
*/
|
|
82
|
+
safeEncode(value) {
|
|
83
|
+
// First validate the output
|
|
84
|
+
const outputResult = this.outputValidator.safeParse(value);
|
|
85
|
+
if (!outputResult.success) {
|
|
86
|
+
return { success: false, error: outputResult.error };
|
|
87
|
+
}
|
|
88
|
+
try {
|
|
89
|
+
// Then encode to input
|
|
90
|
+
const encoded = this.codecTransform.encode(outputResult.data);
|
|
91
|
+
// Handle async encode
|
|
92
|
+
if (encoded instanceof Promise) {
|
|
93
|
+
throw new VldError([
|
|
94
|
+
createIssue('custom', [], getMessages().codecAsyncNotSupported)
|
|
95
|
+
]);
|
|
96
|
+
}
|
|
97
|
+
// Validate the encoded input
|
|
98
|
+
return this.inputValidator.safeParse(encoded);
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
if (error instanceof VldError) {
|
|
102
|
+
return { success: false, error };
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
success: false,
|
|
106
|
+
error: new VldError([
|
|
107
|
+
createIssue('custom', [], getMessages().codecEncodeFailed)
|
|
108
|
+
])
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Async version of parse (decode)
|
|
114
|
+
*/
|
|
115
|
+
async parseAsync(value) {
|
|
116
|
+
const result = await this.safeParseAsync(value);
|
|
117
|
+
if (!result.success) {
|
|
118
|
+
throw result.error;
|
|
119
|
+
}
|
|
120
|
+
return result.data;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Async version of safeParse (decode)
|
|
124
|
+
*/
|
|
125
|
+
async safeParseAsync(value) {
|
|
126
|
+
// First validate the input
|
|
127
|
+
const inputResult = this.inputValidator.safeParse(value);
|
|
128
|
+
if (!inputResult.success) {
|
|
129
|
+
return { success: false, error: inputResult.error };
|
|
130
|
+
}
|
|
131
|
+
try {
|
|
132
|
+
// Then decode to output (supports async)
|
|
133
|
+
const decoded = await this.codecTransform.decode(inputResult.data);
|
|
134
|
+
// Validate the decoded output
|
|
135
|
+
return this.outputValidator.safeParse(decoded);
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
if (error instanceof VldError) {
|
|
139
|
+
return { success: false, error };
|
|
140
|
+
}
|
|
141
|
+
return {
|
|
142
|
+
success: false,
|
|
143
|
+
error: new VldError([
|
|
144
|
+
createIssue('custom', [], getMessages().codecDecodeFailed)
|
|
145
|
+
])
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Async version of encode
|
|
151
|
+
*/
|
|
152
|
+
async encodeAsync(value) {
|
|
153
|
+
const result = await this.safeEncodeAsync(value);
|
|
154
|
+
if (!result.success) {
|
|
155
|
+
throw result.error;
|
|
156
|
+
}
|
|
157
|
+
return result.data;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Async version of safeEncode
|
|
161
|
+
*/
|
|
162
|
+
async safeEncodeAsync(value) {
|
|
163
|
+
// First validate the output
|
|
164
|
+
const outputResult = this.outputValidator.safeParse(value);
|
|
165
|
+
if (!outputResult.success) {
|
|
166
|
+
return { success: false, error: outputResult.error };
|
|
167
|
+
}
|
|
168
|
+
try {
|
|
169
|
+
// Then encode to input (supports async)
|
|
170
|
+
const encoded = await this.codecTransform.encode(outputResult.data);
|
|
171
|
+
// Validate the encoded input
|
|
172
|
+
return this.inputValidator.safeParse(encoded);
|
|
173
|
+
}
|
|
174
|
+
catch (error) {
|
|
175
|
+
if (error instanceof VldError) {
|
|
176
|
+
return { success: false, error };
|
|
177
|
+
}
|
|
178
|
+
return {
|
|
179
|
+
success: false,
|
|
180
|
+
error: new VldError([
|
|
181
|
+
createIssue('custom', [], getMessages().codecEncodeFailed)
|
|
182
|
+
])
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Create a codec validator
|
|
188
|
+
*/
|
|
189
|
+
static create(inputValidator, outputValidator, codecTransform) {
|
|
190
|
+
return new VldCodec(inputValidator, outputValidator, codecTransform);
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Create a codec with input and output directions swapped.
|
|
194
|
+
*/
|
|
195
|
+
static invert(codec) {
|
|
196
|
+
return codec.invert();
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
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,67 @@
|
|
|
1
|
+
import { VldBase, VLD_VALIDATOR_TYPES } from './base.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Immutable custom validator for user-defined validation logic
|
|
5
|
+
* Provides type safety while allowing complete control over validation
|
|
6
|
+
*/
|
|
7
|
+
class VldCustom extends VldBase {
|
|
8
|
+
constructor(options) {
|
|
9
|
+
super(VLD_VALIDATOR_TYPES.CUSTOM);
|
|
10
|
+
this._parseFn = options.parse;
|
|
11
|
+
this._parseAsyncFn = options.parseAsync || ((value) => Promise.resolve(this._parseFn(value)));
|
|
12
|
+
this._safeParseFn = options.safeParse || ((value) => {
|
|
13
|
+
try {
|
|
14
|
+
return { success: true, data: this._parseFn(value) };
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
return { success: false, error: error };
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
this._safeParseAsyncFn = options.safeParseAsync || (async (value) => {
|
|
21
|
+
try {
|
|
22
|
+
return { success: true, data: await this._parseAsyncFn(value) };
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
return { success: false, error: error };
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Create a new custom validator
|
|
31
|
+
*/
|
|
32
|
+
static create(options) {
|
|
33
|
+
return new VldCustom(options);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Parse and validate using the custom parse function
|
|
37
|
+
*/
|
|
38
|
+
parse(value) {
|
|
39
|
+
return this._parseFn(value);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Safely parse using the custom safeParse function or default implementation
|
|
43
|
+
*/
|
|
44
|
+
safeParse(value) {
|
|
45
|
+
return this._safeParseFn(value);
|
|
46
|
+
}
|
|
47
|
+
async parseAsync(value) {
|
|
48
|
+
return this._parseAsyncFn(value);
|
|
49
|
+
}
|
|
50
|
+
async safeParseAsync(value) {
|
|
51
|
+
return this._safeParseAsyncFn(value);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Helper function to create custom validators
|
|
56
|
+
* Usage: v.custom<number>({
|
|
57
|
+
* parse: (value) => {
|
|
58
|
+
* if (typeof value !== 'string') throw new Error('Expected string');
|
|
59
|
+
* return parseInt(value, 10);
|
|
60
|
+
* }
|
|
61
|
+
* })
|
|
62
|
+
*/
|
|
63
|
+
function custom(options) {
|
|
64
|
+
return VldCustom.create(options);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export { VldCustom, custom };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { VldBase, ParseResult } from './base';
|
|
1
|
+
import { VldBase, ParseResult, ValidatorType } from './base.js';
|
|
2
2
|
/**
|
|
3
3
|
* Type for date validation check functions
|
|
4
4
|
*/
|
|
@@ -7,22 +7,33 @@ interface DateCheck {
|
|
|
7
7
|
fn: DateCheckFn;
|
|
8
8
|
message: string;
|
|
9
9
|
}
|
|
10
|
+
interface DateJSONSchemaHints {
|
|
11
|
+
readonly formatMinimum?: string;
|
|
12
|
+
readonly formatMaximum?: string;
|
|
13
|
+
readonly formatExclusiveMinimum?: string;
|
|
14
|
+
readonly formatExclusiveMaximum?: string;
|
|
15
|
+
}
|
|
10
16
|
/**
|
|
11
17
|
* Configuration for date validator
|
|
12
18
|
*/
|
|
13
19
|
interface DateValidatorConfig {
|
|
14
20
|
readonly checks: ReadonlyArray<DateCheck>;
|
|
15
|
-
readonly errorMessage
|
|
21
|
+
readonly errorMessage: string | undefined;
|
|
22
|
+
readonly validatorType?: ValidatorType;
|
|
23
|
+
readonly jsonSchema: DateJSONSchemaHints | undefined;
|
|
16
24
|
}
|
|
17
25
|
/**
|
|
18
26
|
* Immutable date validator with chainable methods
|
|
19
27
|
*/
|
|
20
28
|
export declare class VldDate extends VldBase<Date, Date> {
|
|
21
29
|
private readonly config;
|
|
30
|
+
private readonly _checks;
|
|
31
|
+
private readonly _isSimple;
|
|
22
32
|
/**
|
|
23
33
|
* Protected constructor to allow extension while maintaining immutability
|
|
24
34
|
*/
|
|
25
35
|
protected constructor(config?: Partial<DateValidatorConfig>);
|
|
36
|
+
get jsonSchema(): DateJSONSchemaHints | undefined;
|
|
26
37
|
/**
|
|
27
38
|
* Create a new date validator
|
|
28
39
|
*/
|
|
@@ -31,6 +42,12 @@ export declare class VldDate extends VldBase<Date, Date> {
|
|
|
31
42
|
* Parse and validate a date value
|
|
32
43
|
*/
|
|
33
44
|
parse(value: unknown): Date;
|
|
45
|
+
/**
|
|
46
|
+
* Parse a Date instance that has already passed the Date validity check.
|
|
47
|
+
* @internal Used by object validators to avoid duplicate hot-path checks.
|
|
48
|
+
*/
|
|
49
|
+
parseKnownDate(value: Date): Date;
|
|
50
|
+
private parseValidDate;
|
|
34
51
|
/**
|
|
35
52
|
* Safely parse and validate a date value
|
|
36
53
|
*/
|
|
@@ -85,4 +102,3 @@ export declare class VldDate extends VldBase<Date, Date> {
|
|
|
85
102
|
lt(value: Date | number, message?: string): VldDate;
|
|
86
103
|
}
|
|
87
104
|
export {};
|
|
88
|
-
//# sourceMappingURL=date.d.ts.map
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import { VldBase, VLD_VALIDATOR_TYPES } from './base.js';
|
|
2
|
+
import { getMessages } from '../locales/runtime.js';
|
|
3
|
+
import { V as VldError } from '../chunks/errors-core-BeiFUtZM.js';
|
|
4
|
+
|
|
5
|
+
function createDateError(message) {
|
|
6
|
+
return new VldError([{ code: 'invalid_date', path: [], message }]);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Immutable date validator with chainable methods
|
|
10
|
+
*/
|
|
11
|
+
class VldDate extends VldBase {
|
|
12
|
+
/**
|
|
13
|
+
* Protected constructor to allow extension while maintaining immutability
|
|
14
|
+
*/
|
|
15
|
+
constructor(config) {
|
|
16
|
+
super(config?.validatorType || VLD_VALIDATOR_TYPES.DATE);
|
|
17
|
+
this.config = {
|
|
18
|
+
checks: config?.checks || [],
|
|
19
|
+
errorMessage: config?.errorMessage,
|
|
20
|
+
jsonSchema: config?.jsonSchema
|
|
21
|
+
};
|
|
22
|
+
this._checks = this.config.checks;
|
|
23
|
+
this._isSimple = this._checks.length === 0;
|
|
24
|
+
}
|
|
25
|
+
get jsonSchema() {
|
|
26
|
+
return this.config.jsonSchema;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Create a new date validator
|
|
30
|
+
*/
|
|
31
|
+
static create() {
|
|
32
|
+
return new VldDate();
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Parse and validate a date value
|
|
36
|
+
*/
|
|
37
|
+
parse(value) {
|
|
38
|
+
let date;
|
|
39
|
+
if (value instanceof Date) {
|
|
40
|
+
date = value;
|
|
41
|
+
}
|
|
42
|
+
else if (typeof value === 'string' || typeof value === 'number') {
|
|
43
|
+
date = new Date(value);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
throw new Error(this.config.errorMessage || getMessages().invalidDate);
|
|
47
|
+
}
|
|
48
|
+
// Check if the date is valid
|
|
49
|
+
if (isNaN(date.getTime())) {
|
|
50
|
+
throw new Error(this.config.errorMessage || getMessages().invalidDate);
|
|
51
|
+
}
|
|
52
|
+
return this.parseValidDate(date);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Parse a Date instance that has already passed the Date validity check.
|
|
56
|
+
* @internal Used by object validators to avoid duplicate hot-path checks.
|
|
57
|
+
*/
|
|
58
|
+
parseKnownDate(value) {
|
|
59
|
+
if (isNaN(value.getTime())) {
|
|
60
|
+
throw new Error(this.config.errorMessage || getMessages().invalidDate);
|
|
61
|
+
}
|
|
62
|
+
return this.parseValidDate(value);
|
|
63
|
+
}
|
|
64
|
+
parseValidDate(date) {
|
|
65
|
+
if (this._isSimple) {
|
|
66
|
+
return date;
|
|
67
|
+
}
|
|
68
|
+
// Apply all checks
|
|
69
|
+
for (const check of this._checks) {
|
|
70
|
+
if (!check.fn(date)) {
|
|
71
|
+
throw new Error(check.message);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return date;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Safely parse and validate a date value
|
|
78
|
+
*/
|
|
79
|
+
safeParse(value) {
|
|
80
|
+
if (value instanceof Date) {
|
|
81
|
+
try {
|
|
82
|
+
return { success: true, data: this.parseKnownDate(value) };
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
return { success: false, error: createDateError(error.message) };
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
try {
|
|
89
|
+
return { success: true, data: this.parse(value) };
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
return { success: false, error: createDateError(error.message) };
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Create a new validator with minimum date constraint
|
|
97
|
+
* BUG-NEW-009 FIX: Validate that min date is valid before creating validator
|
|
98
|
+
*/
|
|
99
|
+
min(date, message) {
|
|
100
|
+
const minDate = date instanceof Date ? date : new Date(date);
|
|
101
|
+
// Validate that minDate is valid
|
|
102
|
+
if (isNaN(minDate.getTime())) {
|
|
103
|
+
throw new Error(`Invalid date provided to min(): ${date}`);
|
|
104
|
+
}
|
|
105
|
+
return new VldDate({
|
|
106
|
+
...this.config,
|
|
107
|
+
checks: [...this.config.checks, {
|
|
108
|
+
fn: (v) => v >= minDate,
|
|
109
|
+
message: message || getMessages().dateMin(minDate)
|
|
110
|
+
}],
|
|
111
|
+
jsonSchema: { ...this.config.jsonSchema, formatMinimum: minDate.toISOString() }
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Create a new validator with maximum date constraint
|
|
116
|
+
* BUG-NEW-009 FIX: Validate that max date is valid before creating validator
|
|
117
|
+
*/
|
|
118
|
+
max(date, message) {
|
|
119
|
+
const maxDate = date instanceof Date ? date : new Date(date);
|
|
120
|
+
// Validate that maxDate is valid
|
|
121
|
+
if (isNaN(maxDate.getTime())) {
|
|
122
|
+
throw new Error(`Invalid date provided to max(): ${date}`);
|
|
123
|
+
}
|
|
124
|
+
return new VldDate({
|
|
125
|
+
...this.config,
|
|
126
|
+
checks: [...this.config.checks, {
|
|
127
|
+
fn: (v) => v <= maxDate,
|
|
128
|
+
message: message || getMessages().dateMax(maxDate)
|
|
129
|
+
}],
|
|
130
|
+
jsonSchema: { ...this.config.jsonSchema, formatMaximum: maxDate.toISOString() }
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Create a new validator with a range constraint
|
|
135
|
+
* BUG-NEW-019 FIX: Validate that min/max dates are valid before creating validator
|
|
136
|
+
*/
|
|
137
|
+
between(min, max, message) {
|
|
138
|
+
const minDate = min instanceof Date ? min : new Date(min);
|
|
139
|
+
const maxDate = max instanceof Date ? max : new Date(max);
|
|
140
|
+
// Validate that both dates are valid
|
|
141
|
+
if (isNaN(minDate.getTime())) {
|
|
142
|
+
throw new Error(`Invalid min date provided to between(): ${min}`);
|
|
143
|
+
}
|
|
144
|
+
if (isNaN(maxDate.getTime())) {
|
|
145
|
+
throw new Error(`Invalid max date provided to between(): ${max}`);
|
|
146
|
+
}
|
|
147
|
+
return new VldDate({
|
|
148
|
+
...this.config,
|
|
149
|
+
checks: [...this.config.checks, {
|
|
150
|
+
fn: (v) => v >= minDate && v <= maxDate,
|
|
151
|
+
message: message || `Date must be between ${minDate.toISOString()} and ${maxDate.toISOString()}`
|
|
152
|
+
}],
|
|
153
|
+
jsonSchema: {
|
|
154
|
+
...this.config.jsonSchema,
|
|
155
|
+
formatMinimum: minDate.toISOString(),
|
|
156
|
+
formatMaximum: maxDate.toISOString()
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Create a new validator that checks if date is in the past
|
|
162
|
+
* BUG-NEW-006 FIX: Capture reference date at validator creation time for deterministic behavior
|
|
163
|
+
*/
|
|
164
|
+
past(message) {
|
|
165
|
+
const referenceDate = new Date(); // Capture NOW at validator creation time
|
|
166
|
+
return new VldDate({
|
|
167
|
+
...this.config,
|
|
168
|
+
checks: [...this.config.checks, {
|
|
169
|
+
fn: (v) => v < referenceDate,
|
|
170
|
+
message: message || 'Date must be in the past'
|
|
171
|
+
}],
|
|
172
|
+
jsonSchema: { ...this.config.jsonSchema, formatExclusiveMaximum: referenceDate.toISOString() }
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Create a new validator that checks if date is in the future
|
|
177
|
+
* BUG-NEW-006 FIX: Capture reference date at validator creation time for deterministic behavior
|
|
178
|
+
*/
|
|
179
|
+
future(message) {
|
|
180
|
+
const referenceDate = new Date(); // Capture NOW at validator creation time
|
|
181
|
+
return new VldDate({
|
|
182
|
+
...this.config,
|
|
183
|
+
checks: [...this.config.checks, {
|
|
184
|
+
fn: (v) => v > referenceDate,
|
|
185
|
+
message: message || 'Date must be in the future'
|
|
186
|
+
}],
|
|
187
|
+
jsonSchema: { ...this.config.jsonSchema, formatExclusiveMinimum: referenceDate.toISOString() }
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Create a new validator that checks if date is today
|
|
192
|
+
* BUG-NEW-008 FIX: Capture reference date at validator creation time for deterministic behavior
|
|
193
|
+
*/
|
|
194
|
+
today(message) {
|
|
195
|
+
// Capture the reference date (today) at validator creation time
|
|
196
|
+
const referenceDate = new Date();
|
|
197
|
+
const refYear = referenceDate.getFullYear();
|
|
198
|
+
const refMonth = referenceDate.getMonth();
|
|
199
|
+
const refDate = referenceDate.getDate();
|
|
200
|
+
return new VldDate({
|
|
201
|
+
...this.config,
|
|
202
|
+
checks: [...this.config.checks, {
|
|
203
|
+
fn: (v) => {
|
|
204
|
+
return v.getFullYear() === refYear &&
|
|
205
|
+
v.getMonth() === refMonth &&
|
|
206
|
+
v.getDate() === refDate;
|
|
207
|
+
},
|
|
208
|
+
message: message || 'Date must be today'
|
|
209
|
+
}]
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Create a new validator that checks if date is a weekday
|
|
214
|
+
*/
|
|
215
|
+
weekday(message) {
|
|
216
|
+
return new VldDate({
|
|
217
|
+
...this.config,
|
|
218
|
+
checks: [...this.config.checks, {
|
|
219
|
+
fn: (v) => {
|
|
220
|
+
const day = v.getDay();
|
|
221
|
+
return day >= 1 && day <= 5;
|
|
222
|
+
},
|
|
223
|
+
message: message || 'Date must be a weekday'
|
|
224
|
+
}]
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Create a new validator that checks if date is a weekend
|
|
229
|
+
*/
|
|
230
|
+
weekend(message) {
|
|
231
|
+
return new VldDate({
|
|
232
|
+
...this.config,
|
|
233
|
+
checks: [...this.config.checks, {
|
|
234
|
+
fn: (v) => {
|
|
235
|
+
const day = v.getDay();
|
|
236
|
+
return day === 0 || day === 6;
|
|
237
|
+
},
|
|
238
|
+
message: message || 'Date must be a weekend'
|
|
239
|
+
}]
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Create a new validator with strict greater than constraint
|
|
244
|
+
* Zod 4 API parity - strictly greater than (not equal to)
|
|
245
|
+
*/
|
|
246
|
+
gt(value, message) {
|
|
247
|
+
const compareDate = value instanceof Date ? value : new Date(value);
|
|
248
|
+
return new VldDate({
|
|
249
|
+
...this.config,
|
|
250
|
+
checks: [...this.config.checks, {
|
|
251
|
+
fn: (v) => v.getTime() > compareDate.getTime(),
|
|
252
|
+
message: message || `Date must be greater than ${compareDate.toISOString()}`
|
|
253
|
+
}],
|
|
254
|
+
jsonSchema: { ...this.config.jsonSchema, formatExclusiveMinimum: compareDate.toISOString() }
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Create a new validator with strict less than constraint
|
|
259
|
+
* Zod 4 API parity - strictly less than (not equal to)
|
|
260
|
+
*/
|
|
261
|
+
lt(value, message) {
|
|
262
|
+
const compareDate = value instanceof Date ? value : new Date(value);
|
|
263
|
+
return new VldDate({
|
|
264
|
+
...this.config,
|
|
265
|
+
checks: [...this.config.checks, {
|
|
266
|
+
fn: (v) => v.getTime() < compareDate.getTime(),
|
|
267
|
+
message: message || `Date must be less than ${compareDate.toISOString()}`
|
|
268
|
+
}],
|
|
269
|
+
jsonSchema: { ...this.config.jsonSchema, formatExclusiveMaximum: compareDate.toISOString() }
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export { VldDate };
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* Part of Zod 4 API parity implementation
|
|
4
4
|
* Provides O(1) lookup performance by using a discriminator key
|
|
5
5
|
*/
|
|
6
|
-
import { VldBase } from './base';
|
|
7
|
-
import type { ParseResult } from './base';
|
|
6
|
+
import { VldBase } from './base.js';
|
|
7
|
+
import type { ParseResult } from './base.js';
|
|
8
8
|
/**
|
|
9
9
|
* Discriminated union validator - validates union based on discriminator key
|
|
10
10
|
* Much faster than regular union when you have a discriminator field
|
|
@@ -13,6 +13,8 @@ export declare class VldDiscriminatedUnion<K extends string, Options extends Vld
|
|
|
13
13
|
private readonly _discriminator;
|
|
14
14
|
private readonly _options;
|
|
15
15
|
private readonly _discriminatorMap;
|
|
16
|
+
private readonly _stringDiscriminatorMap;
|
|
17
|
+
private readonly _validValues;
|
|
16
18
|
constructor(_discriminator: K, _options: Options);
|
|
17
19
|
static create<K extends string, Options extends VldBase<any, any>[]>(discriminator: K, options: Options): VldDiscriminatedUnion<K, Options>;
|
|
18
20
|
parse(value: unknown): Options[number] extends VldBase<any, infer T> ? T : never;
|
|
@@ -26,4 +28,3 @@ export declare class VldDiscriminatedUnion<K extends string, Options extends Vld
|
|
|
26
28
|
*/
|
|
27
29
|
getOptions(): Options;
|
|
28
30
|
}
|
|
29
|
-
//# sourceMappingURL=discriminated-union.d.ts.map
|