@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
|
@@ -2,7 +2,13 @@
|
|
|
2
2
|
* Promise validator - validates Promise values
|
|
3
3
|
* Validates that the resolved value matches the inner schema
|
|
4
4
|
*/
|
|
5
|
-
import { type ParseResult } from './base';
|
|
5
|
+
import { type ParseResult, type StandardSchemaV1Props } from './base.js';
|
|
6
|
+
type PromiseInner<T> = {
|
|
7
|
+
parse(value: unknown): T;
|
|
8
|
+
safeParse(value: unknown): ParseResult<T>;
|
|
9
|
+
parseAsync?(value: unknown): Promise<T>;
|
|
10
|
+
safeParseAsync?(value: unknown): Promise<ParseResult<T>>;
|
|
11
|
+
};
|
|
6
12
|
/**
|
|
7
13
|
* Promise validator - validates Promise<T> where T matches inner schema
|
|
8
14
|
* Zod 4 API parity - allows async validation with proper type inference
|
|
@@ -14,15 +20,15 @@ import { type ParseResult } from './base';
|
|
|
14
20
|
*/
|
|
15
21
|
export declare class VldPromise<T> {
|
|
16
22
|
private readonly inner;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
});
|
|
23
|
+
readonly validatorType: "promise";
|
|
24
|
+
constructor(inner: PromiseInner<T>);
|
|
25
|
+
get '~standard'(): StandardSchemaV1Props<unknown, T>;
|
|
21
26
|
/**
|
|
22
27
|
* Check if value is thenable (Promise-like)
|
|
23
28
|
* Must be called BEFORE wrapping in Promise.resolve
|
|
24
29
|
*/
|
|
25
30
|
private _isThenable;
|
|
31
|
+
unwrap(): PromiseInner<T>;
|
|
26
32
|
/**
|
|
27
33
|
* Parse and validate a Promise value asynchronously
|
|
28
34
|
* @param value The Promise to validate
|
|
@@ -30,12 +36,14 @@ export declare class VldPromise<T> {
|
|
|
30
36
|
* @throws {Error} If validation fails when Promise resolves
|
|
31
37
|
*/
|
|
32
38
|
parse(value: unknown): Promise<T>;
|
|
39
|
+
parseAsync(value: unknown): Promise<T>;
|
|
33
40
|
/**
|
|
34
41
|
* Safely parse and validate a Promise value asynchronously
|
|
35
42
|
* @param value The Promise to validate
|
|
36
43
|
* @returns A Promise resolving to ParseResult containing the validated value
|
|
37
44
|
*/
|
|
38
45
|
safeParse(value: unknown): Promise<ParseResult<T>>;
|
|
46
|
+
safeParseAsync(value: unknown): Promise<ParseResult<T>>;
|
|
39
47
|
}
|
|
40
48
|
/**
|
|
41
49
|
* Create a Promise validator
|
|
@@ -46,8 +54,5 @@ export declare class VldPromise<T> {
|
|
|
46
54
|
* const result = await promiseSchema.parse(Promise.resolve("hello"));
|
|
47
55
|
* // result is string
|
|
48
56
|
*/
|
|
49
|
-
export declare function promise<T>(inner:
|
|
50
|
-
|
|
51
|
-
safeParse(value: unknown): ParseResult<T>;
|
|
52
|
-
}): VldPromise<T>;
|
|
53
|
-
//# sourceMappingURL=promise.d.ts.map
|
|
57
|
+
export declare function promise<T>(inner: PromiseInner<T>): VldPromise<T>;
|
|
58
|
+
export {};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { VLD_VALIDATOR_TYPES } from './base.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Promise validator - validates Promise values
|
|
5
|
+
* Validates that the resolved value matches the inner schema
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Promise validator - validates Promise<T> where T matches inner schema
|
|
9
|
+
* Zod 4 API parity - allows async validation with proper type inference
|
|
10
|
+
*
|
|
11
|
+
* Validates that the input is a Promise, and validates the resolved value
|
|
12
|
+
* against the inner schema when parsed.
|
|
13
|
+
*
|
|
14
|
+
* Use parseAsync() or safeParseAsync() for proper async handling.
|
|
15
|
+
*/
|
|
16
|
+
class VldPromise {
|
|
17
|
+
constructor(inner) {
|
|
18
|
+
this.inner = inner;
|
|
19
|
+
this.validatorType = VLD_VALIDATOR_TYPES.PROMISE;
|
|
20
|
+
}
|
|
21
|
+
get '~standard'() {
|
|
22
|
+
return {
|
|
23
|
+
version: 1,
|
|
24
|
+
vendor: 'vld',
|
|
25
|
+
validate: async (value) => {
|
|
26
|
+
const result = await this.safeParseAsync(value);
|
|
27
|
+
if (result.success) {
|
|
28
|
+
return { value: result.data };
|
|
29
|
+
}
|
|
30
|
+
return { issues: [{ message: result.error.message }] };
|
|
31
|
+
},
|
|
32
|
+
types: undefined
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Check if value is thenable (Promise-like)
|
|
37
|
+
* Must be called BEFORE wrapping in Promise.resolve
|
|
38
|
+
*/
|
|
39
|
+
_isThenable(value) {
|
|
40
|
+
return value !== null && typeof value.then === 'function';
|
|
41
|
+
}
|
|
42
|
+
unwrap() {
|
|
43
|
+
return this.inner;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Parse and validate a Promise value asynchronously
|
|
47
|
+
* @param value The Promise to validate
|
|
48
|
+
* @returns The validated value
|
|
49
|
+
* @throws {Error} If validation fails when Promise resolves
|
|
50
|
+
*/
|
|
51
|
+
async parse(value) {
|
|
52
|
+
// Check if value is thenable BEFORE wrapping in Promise.resolve
|
|
53
|
+
if (!this._isThenable(value)) {
|
|
54
|
+
throw new Error('Expected a Promise value');
|
|
55
|
+
}
|
|
56
|
+
// Now we can safely await it
|
|
57
|
+
const resolved = await Promise.resolve(value);
|
|
58
|
+
return this.inner.parseAsync ? this.inner.parseAsync(resolved) : this.inner.parse(resolved);
|
|
59
|
+
}
|
|
60
|
+
parseAsync(value) {
|
|
61
|
+
return this.parse(value);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Safely parse and validate a Promise value asynchronously
|
|
65
|
+
* @param value The Promise to validate
|
|
66
|
+
* @returns A Promise resolving to ParseResult containing the validated value
|
|
67
|
+
*/
|
|
68
|
+
async safeParse(value) {
|
|
69
|
+
// Check if value is thenable BEFORE wrapping in Promise.resolve
|
|
70
|
+
if (!this._isThenable(value)) {
|
|
71
|
+
return {
|
|
72
|
+
success: false,
|
|
73
|
+
error: new Error('Expected a Promise value')
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
try {
|
|
77
|
+
const resolved = await Promise.resolve(value);
|
|
78
|
+
if (this.inner.safeParseAsync) {
|
|
79
|
+
return await this.inner.safeParseAsync(resolved);
|
|
80
|
+
}
|
|
81
|
+
const innerResult = this.inner.safeParse(resolved);
|
|
82
|
+
if (!innerResult.success) {
|
|
83
|
+
return innerResult;
|
|
84
|
+
}
|
|
85
|
+
return { success: true, data: innerResult.data };
|
|
86
|
+
}
|
|
87
|
+
catch (err) {
|
|
88
|
+
return {
|
|
89
|
+
success: false,
|
|
90
|
+
error: err instanceof Error ? err : new Error(String(err))
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
safeParseAsync(value) {
|
|
95
|
+
return this.safeParse(value);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Create a Promise validator
|
|
100
|
+
* @param inner The schema to validate the resolved value against
|
|
101
|
+
* @returns A new Promise validator
|
|
102
|
+
* @example
|
|
103
|
+
* const promiseSchema = v.promise(v.string());
|
|
104
|
+
* const result = await promiseSchema.parse(Promise.resolve("hello"));
|
|
105
|
+
* // result is string
|
|
106
|
+
*/
|
|
107
|
+
function promise(inner) {
|
|
108
|
+
return new VldPromise(inner);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export { VldPromise, promise };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { VldBase, ParseResult } from './base';
|
|
1
|
+
import { VldBase, ParseResult } from './base.js';
|
|
2
2
|
/**
|
|
3
3
|
* Immutable record validator for key-value pairs
|
|
4
4
|
* BUG-NEW-018 FIX: Uses comprehensive dangerous key protection
|
|
@@ -10,15 +10,25 @@ export declare class VldRecord<T> extends VldBase<unknown, Record<string, T>> {
|
|
|
10
10
|
* Private constructor to enforce immutability
|
|
11
11
|
*/
|
|
12
12
|
protected constructor(valueValidator: VldBase<unknown, T>, errorMessage?: string | undefined);
|
|
13
|
+
private readonly _simpleValueMode;
|
|
14
|
+
private readonly _simpleValue;
|
|
15
|
+
get valueSchema(): VldBase<unknown, T>;
|
|
13
16
|
/**
|
|
14
17
|
* Create a new record validator
|
|
15
18
|
*/
|
|
16
19
|
static create<T>(valueValidator: VldBase<unknown, T>): VldRecord<T>;
|
|
20
|
+
private getSimpleValueMode;
|
|
21
|
+
private getSimpleValueError;
|
|
17
22
|
/**
|
|
18
23
|
* Parse and validate a record value
|
|
19
24
|
* BUG-NEW-018 FIX: Use comprehensive dangerous key protection
|
|
20
25
|
*/
|
|
21
26
|
parse(value: unknown): Record<string, T>;
|
|
27
|
+
/**
|
|
28
|
+
* Parse a value that has already passed the record object type guard.
|
|
29
|
+
* @internal Used by object validators to avoid duplicate hot-path checks.
|
|
30
|
+
*/
|
|
31
|
+
parseKnownRecord(obj: Record<string, unknown>): Record<string, T>;
|
|
22
32
|
/**
|
|
23
33
|
* Safely parse and validate a record value
|
|
24
34
|
*/
|
|
@@ -35,4 +45,3 @@ export declare class VldRecord<T> extends VldBase<unknown, Record<string, T>> {
|
|
|
35
45
|
*/
|
|
36
46
|
loose(): VldBase<unknown, Record<string, T>>;
|
|
37
47
|
}
|
|
38
|
-
//# sourceMappingURL=record.d.ts.map
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import { VldBase, VLD_VALIDATOR_TYPES } from './base.js';
|
|
2
|
+
import { getMessages } from '../locales/runtime.js';
|
|
3
|
+
import { i as isDangerousKey } from '../chunks/security-B0Pd_vSY.js';
|
|
4
|
+
import { V as VldError } from '../chunks/errors-core-BeiFUtZM.js';
|
|
5
|
+
|
|
6
|
+
function createRecordError(message) {
|
|
7
|
+
return new VldError([{ code: 'invalid_object', path: [], message }]);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Immutable record validator for key-value pairs
|
|
11
|
+
* BUG-NEW-018 FIX: Uses comprehensive dangerous key protection
|
|
12
|
+
*/
|
|
13
|
+
class VldRecord extends VldBase {
|
|
14
|
+
/**
|
|
15
|
+
* Private constructor to enforce immutability
|
|
16
|
+
*/
|
|
17
|
+
constructor(valueValidator, errorMessage) {
|
|
18
|
+
super(VLD_VALIDATOR_TYPES.RECORD);
|
|
19
|
+
this.valueValidator = valueValidator;
|
|
20
|
+
this.errorMessage = errorMessage;
|
|
21
|
+
this._simpleValueMode = this.getSimpleValueMode(valueValidator);
|
|
22
|
+
this._simpleValue = this._simpleValueMode === 'literal' ? valueValidator.literal : undefined;
|
|
23
|
+
}
|
|
24
|
+
get valueSchema() {
|
|
25
|
+
return this.valueValidator;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Create a new record validator
|
|
29
|
+
*/
|
|
30
|
+
static create(valueValidator) {
|
|
31
|
+
return new VldRecord(valueValidator);
|
|
32
|
+
}
|
|
33
|
+
getSimpleValueMode(valueValidator) {
|
|
34
|
+
if (valueValidator.isSimple !== true) {
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
switch (valueValidator.validatorType) {
|
|
38
|
+
case VLD_VALIDATOR_TYPES.STRING:
|
|
39
|
+
return 'string';
|
|
40
|
+
case VLD_VALIDATOR_TYPES.NUMBER:
|
|
41
|
+
return 'number';
|
|
42
|
+
case VLD_VALIDATOR_TYPES.BOOLEAN:
|
|
43
|
+
return 'boolean';
|
|
44
|
+
case VLD_VALIDATOR_TYPES.BIGINT:
|
|
45
|
+
return 'bigint';
|
|
46
|
+
case VLD_VALIDATOR_TYPES.SYMBOL:
|
|
47
|
+
return 'symbol';
|
|
48
|
+
case VLD_VALIDATOR_TYPES.NULL:
|
|
49
|
+
return 'null';
|
|
50
|
+
case VLD_VALIDATOR_TYPES.UNDEFINED:
|
|
51
|
+
case VLD_VALIDATOR_TYPES.VOID:
|
|
52
|
+
return 'undefinedValue';
|
|
53
|
+
case VLD_VALIDATOR_TYPES.LITERAL:
|
|
54
|
+
return 'literal';
|
|
55
|
+
case VLD_VALIDATOR_TYPES.ANY:
|
|
56
|
+
case VLD_VALIDATOR_TYPES.UNKNOWN:
|
|
57
|
+
return 'passthrough';
|
|
58
|
+
default:
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
getSimpleValueError(received) {
|
|
63
|
+
switch (this._simpleValueMode) {
|
|
64
|
+
case 'string':
|
|
65
|
+
return getMessages().invalidString;
|
|
66
|
+
case 'number':
|
|
67
|
+
return getMessages().invalidNumber;
|
|
68
|
+
case 'boolean':
|
|
69
|
+
return getMessages().invalidBoolean;
|
|
70
|
+
case 'bigint':
|
|
71
|
+
return getMessages().invalidBigint;
|
|
72
|
+
case 'symbol':
|
|
73
|
+
return getMessages().invalidSymbol;
|
|
74
|
+
case 'null':
|
|
75
|
+
return `Expected null, received ${typeof received}`;
|
|
76
|
+
case 'undefinedValue':
|
|
77
|
+
return getMessages().expectedUndefined;
|
|
78
|
+
case 'literal':
|
|
79
|
+
return getMessages().literalExpected(JSON.stringify(this._simpleValue), JSON.stringify(received));
|
|
80
|
+
default:
|
|
81
|
+
return getMessages().invalidRecord;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Parse and validate a record value
|
|
86
|
+
* BUG-NEW-018 FIX: Use comprehensive dangerous key protection
|
|
87
|
+
*/
|
|
88
|
+
parse(value) {
|
|
89
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
90
|
+
throw new Error(this.errorMessage || getMessages().invalidRecord);
|
|
91
|
+
}
|
|
92
|
+
return this.parseKnownRecord(value);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Parse a value that has already passed the record object type guard.
|
|
96
|
+
* @internal Used by object validators to avoid duplicate hot-path checks.
|
|
97
|
+
*/
|
|
98
|
+
parseKnownRecord(obj) {
|
|
99
|
+
const result = {};
|
|
100
|
+
const keys = Object.keys(obj);
|
|
101
|
+
const simpleMode = this._simpleValueMode;
|
|
102
|
+
for (let i = 0; i < keys.length; i++) {
|
|
103
|
+
const key = keys[i];
|
|
104
|
+
// Skip dangerous keys to prevent prototype pollution
|
|
105
|
+
// Now using comprehensive protection from shared utility
|
|
106
|
+
if (isDangerousKey(key)) {
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
const val = obj[key];
|
|
110
|
+
if (simpleMode !== undefined) {
|
|
111
|
+
switch (simpleMode) {
|
|
112
|
+
case 'string':
|
|
113
|
+
if (typeof val !== 'string') {
|
|
114
|
+
throw new Error(getMessages().objectField(key, getMessages().invalidString));
|
|
115
|
+
}
|
|
116
|
+
result[key] = val;
|
|
117
|
+
continue;
|
|
118
|
+
case 'number':
|
|
119
|
+
if (typeof val !== 'number' || isNaN(val)) {
|
|
120
|
+
throw new Error(getMessages().objectField(key, getMessages().invalidNumber));
|
|
121
|
+
}
|
|
122
|
+
result[key] = val;
|
|
123
|
+
continue;
|
|
124
|
+
case 'boolean':
|
|
125
|
+
if (typeof val !== 'boolean') {
|
|
126
|
+
throw new Error(getMessages().objectField(key, getMessages().invalidBoolean));
|
|
127
|
+
}
|
|
128
|
+
result[key] = val;
|
|
129
|
+
continue;
|
|
130
|
+
case 'bigint':
|
|
131
|
+
if (typeof val !== 'bigint') {
|
|
132
|
+
throw new Error(getMessages().objectField(key, getMessages().invalidBigint));
|
|
133
|
+
}
|
|
134
|
+
result[key] = val;
|
|
135
|
+
continue;
|
|
136
|
+
case 'symbol':
|
|
137
|
+
if (typeof val !== 'symbol') {
|
|
138
|
+
throw new Error(getMessages().objectField(key, getMessages().invalidSymbol));
|
|
139
|
+
}
|
|
140
|
+
result[key] = val;
|
|
141
|
+
continue;
|
|
142
|
+
case 'null':
|
|
143
|
+
if (val !== null) {
|
|
144
|
+
throw new Error(getMessages().objectField(key, this.getSimpleValueError(val)));
|
|
145
|
+
}
|
|
146
|
+
result[key] = null;
|
|
147
|
+
continue;
|
|
148
|
+
case 'undefinedValue':
|
|
149
|
+
if (val !== undefined) {
|
|
150
|
+
throw new Error(getMessages().objectField(key, getMessages().expectedUndefined));
|
|
151
|
+
}
|
|
152
|
+
result[key] = undefined;
|
|
153
|
+
continue;
|
|
154
|
+
case 'literal':
|
|
155
|
+
if (val !== this._simpleValue) {
|
|
156
|
+
throw new Error(getMessages().objectField(key, this.getSimpleValueError(val)));
|
|
157
|
+
}
|
|
158
|
+
result[key] = this._simpleValue;
|
|
159
|
+
continue;
|
|
160
|
+
case 'passthrough':
|
|
161
|
+
result[key] = val;
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
try {
|
|
166
|
+
result[key] = this.valueValidator.parse(val);
|
|
167
|
+
}
|
|
168
|
+
catch (error) {
|
|
169
|
+
throw new Error(getMessages().objectField(key, error.message));
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return result;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Safely parse and validate a record value
|
|
176
|
+
*/
|
|
177
|
+
safeParse(value) {
|
|
178
|
+
try {
|
|
179
|
+
return { success: true, data: this.parse(value) };
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
return { success: false, error: createRecordError(error.message) };
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Create a partial record variant (all keys optional)
|
|
187
|
+
* Similar to v.object().partial() but for records
|
|
188
|
+
*/
|
|
189
|
+
partial() {
|
|
190
|
+
const optionalValidator = this.valueValidator.optional();
|
|
191
|
+
return new VldRecord(optionalValidator);
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Create a loose record variant (allows extra keys)
|
|
195
|
+
* Similar to v.object().passthrough() but for records
|
|
196
|
+
* Note: Records already allow any keys, so this mainly affects error handling
|
|
197
|
+
*/
|
|
198
|
+
loose() {
|
|
199
|
+
// For records, "loose" means we don't throw errors for validation failures
|
|
200
|
+
// We return a modified version that catches validation errors
|
|
201
|
+
return new VldLooseRecord(this.valueValidator);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Loose record variant that allows validation failures
|
|
206
|
+
* Used internally by .loose() method
|
|
207
|
+
*/
|
|
208
|
+
class VldLooseRecord extends VldBase {
|
|
209
|
+
constructor(valueValidator) {
|
|
210
|
+
super(VLD_VALIDATOR_TYPES.RECORD);
|
|
211
|
+
this.valueValidator = valueValidator;
|
|
212
|
+
}
|
|
213
|
+
get valueSchema() {
|
|
214
|
+
return this.valueValidator;
|
|
215
|
+
}
|
|
216
|
+
parse(value) {
|
|
217
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
218
|
+
throw new Error(getMessages().invalidRecord);
|
|
219
|
+
}
|
|
220
|
+
const result = {};
|
|
221
|
+
const obj = value;
|
|
222
|
+
for (const [key, val] of Object.entries(obj)) {
|
|
223
|
+
// Skip dangerous keys
|
|
224
|
+
if (isDangerousKey(key)) {
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
// For loose records, skip invalid values instead of throwing
|
|
228
|
+
const parseResult = this.valueValidator.safeParse(val);
|
|
229
|
+
if (parseResult.success) {
|
|
230
|
+
result[key] = parseResult.data;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return result;
|
|
234
|
+
}
|
|
235
|
+
safeParse(value) {
|
|
236
|
+
try {
|
|
237
|
+
return { success: true, data: this.parse(value) };
|
|
238
|
+
}
|
|
239
|
+
catch (error) {
|
|
240
|
+
return { success: false, error: createRecordError(error.message) };
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Create a partial variant (all keys optional)
|
|
245
|
+
*/
|
|
246
|
+
partial() {
|
|
247
|
+
const optionalValidator = this.valueValidator.optional();
|
|
248
|
+
return new VldLooseRecord(optionalValidator);
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Return self (already loose)
|
|
252
|
+
*/
|
|
253
|
+
loose() {
|
|
254
|
+
return this;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export { VldRecord };
|
package/dist/validators/set.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { VldBase, ParseResult } from './base';
|
|
1
|
+
import { VldBase, ParseResult } from './base.js';
|
|
2
2
|
/**
|
|
3
3
|
* Immutable Set validator
|
|
4
4
|
*/
|
|
@@ -9,17 +9,26 @@ export declare class VldSet<T> extends VldBase<unknown, Set<T>> {
|
|
|
9
9
|
* Private constructor to enforce immutability
|
|
10
10
|
*/
|
|
11
11
|
private constructor();
|
|
12
|
+
private readonly _simpleItemMode;
|
|
13
|
+
private readonly _simpleItemValue;
|
|
14
|
+
get itemSchema(): VldBase<unknown, T>;
|
|
12
15
|
/**
|
|
13
16
|
* Create a new Set validator
|
|
14
17
|
*/
|
|
15
18
|
static create<T>(itemValidator: VldBase<unknown, T>): VldSet<T>;
|
|
19
|
+
private getSimpleItemMode;
|
|
20
|
+
private getSimpleItemError;
|
|
16
21
|
/**
|
|
17
22
|
* Parse and validate a Set value
|
|
18
23
|
*/
|
|
19
24
|
parse(value: unknown): Set<T>;
|
|
25
|
+
/**
|
|
26
|
+
* Parse a value that has already passed the Set instance guard.
|
|
27
|
+
* @internal Used by object validators to avoid duplicate hot-path checks.
|
|
28
|
+
*/
|
|
29
|
+
parseKnownSet(value: Set<unknown>): Set<T>;
|
|
20
30
|
/**
|
|
21
31
|
* Safely parse and validate a Set value
|
|
22
32
|
*/
|
|
23
33
|
safeParse(value: unknown): ParseResult<Set<T>>;
|
|
24
34
|
}
|
|
25
|
-
//# sourceMappingURL=set.d.ts.map
|
|
@@ -0,0 +1,199 @@
|
|
|
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 createSetError(message) {
|
|
6
|
+
return new VldError([{ code: 'invalid_type', path: [], message }]);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Immutable Set validator
|
|
10
|
+
*/
|
|
11
|
+
class VldSet extends VldBase {
|
|
12
|
+
/**
|
|
13
|
+
* Private constructor to enforce immutability
|
|
14
|
+
*/
|
|
15
|
+
constructor(itemValidator, errorMessage) {
|
|
16
|
+
super(VLD_VALIDATOR_TYPES.SET);
|
|
17
|
+
this.itemValidator = itemValidator;
|
|
18
|
+
this.errorMessage = errorMessage;
|
|
19
|
+
this._simpleItemMode = this.getSimpleItemMode(itemValidator);
|
|
20
|
+
this._simpleItemValue = this._simpleItemMode === 'literal' ? itemValidator.literal : undefined;
|
|
21
|
+
}
|
|
22
|
+
get itemSchema() {
|
|
23
|
+
return this.itemValidator;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Create a new Set validator
|
|
27
|
+
*/
|
|
28
|
+
static create(itemValidator) {
|
|
29
|
+
return new VldSet(itemValidator);
|
|
30
|
+
}
|
|
31
|
+
getSimpleItemMode(itemValidator) {
|
|
32
|
+
if (itemValidator.isSimple !== true) {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
switch (itemValidator.validatorType) {
|
|
36
|
+
case VLD_VALIDATOR_TYPES.STRING:
|
|
37
|
+
return 'string';
|
|
38
|
+
case VLD_VALIDATOR_TYPES.NUMBER:
|
|
39
|
+
return 'number';
|
|
40
|
+
case VLD_VALIDATOR_TYPES.BOOLEAN:
|
|
41
|
+
return 'boolean';
|
|
42
|
+
case VLD_VALIDATOR_TYPES.BIGINT:
|
|
43
|
+
return 'bigint';
|
|
44
|
+
case VLD_VALIDATOR_TYPES.SYMBOL:
|
|
45
|
+
return 'symbol';
|
|
46
|
+
case VLD_VALIDATOR_TYPES.NULL:
|
|
47
|
+
return 'null';
|
|
48
|
+
case VLD_VALIDATOR_TYPES.UNDEFINED:
|
|
49
|
+
case VLD_VALIDATOR_TYPES.VOID:
|
|
50
|
+
return 'undefinedValue';
|
|
51
|
+
case VLD_VALIDATOR_TYPES.LITERAL:
|
|
52
|
+
return 'literal';
|
|
53
|
+
case VLD_VALIDATOR_TYPES.ANY:
|
|
54
|
+
case VLD_VALIDATOR_TYPES.UNKNOWN:
|
|
55
|
+
return 'passthrough';
|
|
56
|
+
default:
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
getSimpleItemError(received) {
|
|
61
|
+
switch (this._simpleItemMode) {
|
|
62
|
+
case 'string':
|
|
63
|
+
return getMessages().invalidString;
|
|
64
|
+
case 'number':
|
|
65
|
+
return getMessages().invalidNumber;
|
|
66
|
+
case 'boolean':
|
|
67
|
+
return getMessages().invalidBoolean;
|
|
68
|
+
case 'bigint':
|
|
69
|
+
return getMessages().invalidBigint;
|
|
70
|
+
case 'symbol':
|
|
71
|
+
return getMessages().invalidSymbol;
|
|
72
|
+
case 'null':
|
|
73
|
+
return `Expected null, received ${typeof received}`;
|
|
74
|
+
case 'undefinedValue':
|
|
75
|
+
return getMessages().expectedUndefined;
|
|
76
|
+
case 'literal':
|
|
77
|
+
return getMessages().literalExpected(JSON.stringify(this._simpleItemValue), JSON.stringify(received));
|
|
78
|
+
default:
|
|
79
|
+
return getMessages().invalidSet;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Parse and validate a Set value
|
|
84
|
+
*/
|
|
85
|
+
parse(value) {
|
|
86
|
+
if (!(value instanceof Set)) {
|
|
87
|
+
throw new Error(this.errorMessage || getMessages().invalidSet);
|
|
88
|
+
}
|
|
89
|
+
return this.parseKnownSet(value);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Parse a value that has already passed the Set instance guard.
|
|
93
|
+
* @internal Used by object validators to avoid duplicate hot-path checks.
|
|
94
|
+
*/
|
|
95
|
+
parseKnownSet(value) {
|
|
96
|
+
const result = new Set();
|
|
97
|
+
const simpleMode = this._simpleItemMode;
|
|
98
|
+
if (simpleMode === 'string') {
|
|
99
|
+
for (const item of value) {
|
|
100
|
+
if (typeof item !== 'string') {
|
|
101
|
+
throw new Error(this.getSimpleItemError(item));
|
|
102
|
+
}
|
|
103
|
+
result.add(item);
|
|
104
|
+
}
|
|
105
|
+
return result;
|
|
106
|
+
}
|
|
107
|
+
if (simpleMode === 'number') {
|
|
108
|
+
for (const item of value) {
|
|
109
|
+
if (typeof item !== 'number' || isNaN(item)) {
|
|
110
|
+
throw new Error(this.getSimpleItemError(item));
|
|
111
|
+
}
|
|
112
|
+
result.add(item);
|
|
113
|
+
}
|
|
114
|
+
return result;
|
|
115
|
+
}
|
|
116
|
+
if (simpleMode === 'boolean') {
|
|
117
|
+
for (const item of value) {
|
|
118
|
+
if (typeof item !== 'boolean') {
|
|
119
|
+
throw new Error(this.getSimpleItemError(item));
|
|
120
|
+
}
|
|
121
|
+
result.add(item);
|
|
122
|
+
}
|
|
123
|
+
return result;
|
|
124
|
+
}
|
|
125
|
+
if (simpleMode === 'bigint') {
|
|
126
|
+
for (const item of value) {
|
|
127
|
+
if (typeof item !== 'bigint') {
|
|
128
|
+
throw new Error(this.getSimpleItemError(item));
|
|
129
|
+
}
|
|
130
|
+
result.add(item);
|
|
131
|
+
}
|
|
132
|
+
return result;
|
|
133
|
+
}
|
|
134
|
+
if (simpleMode === 'symbol') {
|
|
135
|
+
for (const item of value) {
|
|
136
|
+
if (typeof item !== 'symbol') {
|
|
137
|
+
throw new Error(this.getSimpleItemError(item));
|
|
138
|
+
}
|
|
139
|
+
result.add(item);
|
|
140
|
+
}
|
|
141
|
+
return result;
|
|
142
|
+
}
|
|
143
|
+
if (simpleMode === 'null') {
|
|
144
|
+
for (const item of value) {
|
|
145
|
+
if (item !== null) {
|
|
146
|
+
throw new Error(this.getSimpleItemError(item));
|
|
147
|
+
}
|
|
148
|
+
result.add(null);
|
|
149
|
+
}
|
|
150
|
+
return result;
|
|
151
|
+
}
|
|
152
|
+
if (simpleMode === 'undefinedValue') {
|
|
153
|
+
for (const item of value) {
|
|
154
|
+
if (item !== undefined) {
|
|
155
|
+
throw new Error(this.getSimpleItemError(item));
|
|
156
|
+
}
|
|
157
|
+
result.add(undefined);
|
|
158
|
+
}
|
|
159
|
+
return result;
|
|
160
|
+
}
|
|
161
|
+
if (simpleMode === 'literal') {
|
|
162
|
+
for (const item of value) {
|
|
163
|
+
if (item !== this._simpleItemValue) {
|
|
164
|
+
throw new Error(this.getSimpleItemError(item));
|
|
165
|
+
}
|
|
166
|
+
result.add(this._simpleItemValue);
|
|
167
|
+
}
|
|
168
|
+
return result;
|
|
169
|
+
}
|
|
170
|
+
if (simpleMode === 'passthrough') {
|
|
171
|
+
for (const item of value) {
|
|
172
|
+
result.add(item);
|
|
173
|
+
}
|
|
174
|
+
return result;
|
|
175
|
+
}
|
|
176
|
+
for (const item of value) {
|
|
177
|
+
try {
|
|
178
|
+
result.add(this.itemValidator.parse(item));
|
|
179
|
+
}
|
|
180
|
+
catch (error) {
|
|
181
|
+
throw new Error(error.message);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return result;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Safely parse and validate a Set value
|
|
188
|
+
*/
|
|
189
|
+
safeParse(value) {
|
|
190
|
+
try {
|
|
191
|
+
return { success: true, data: this.parse(value) };
|
|
192
|
+
}
|
|
193
|
+
catch (error) {
|
|
194
|
+
return { success: false, error: createSetError(error.message) };
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export { VldSet };
|