@oxog/vld 2.0.2 → 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 +75 -1
- package/LICENSE +20 -20
- package/README.md +101 -37
- package/dist/chunks/errors-core-BeiFUtZM.js +81 -0
- package/dist/chunks/{index-CETyGkrv.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-ODue_rtq.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 +1558 -9647
- 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 -7208
- 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 +1195 -600
- package/dist/index.js +1262 -44
- 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 +77 -0
- 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 +228 -5
- 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 -38
- package/dist/validators/index.js +35 -5
- 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 +80 -21
- 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 +58 -0
- 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 +13 -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-SLIH1VCf.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 +116 -31
- package/dist/chunks/bigint-DgsCr2dC.js +0 -1709
- package/dist/chunks/bigint-DgsCr2dC.js.map +0 -1
- package/dist/chunks/date-ODue_rtq.js.map +0 -1
- package/dist/chunks/index-BZqWZvVe.js +0 -426
- package/dist/chunks/index-BZqWZvVe.js.map +0 -1
- package/dist/chunks/index-CETyGkrv.js.map +0 -1
- package/dist/chunks/json-o20GFhTh.js +0 -2021
- package/dist/chunks/json-o20GFhTh.js.map +0 -1
- package/dist/chunks/unknown-SLIH1VCf.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/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/record.d.ts.map +0 -1
- package/dist/validators/set.d.ts.map +0 -1
- package/dist/validators/string-bool.d.ts.map +0 -1
- package/dist/validators/string-formats.d.ts.map +0 -1
- package/dist/validators/string.d.ts.map +0 -1
- package/dist/validators/symbol.d.ts.map +0 -1
- package/dist/validators/template-literal.d.ts.map +0 -1
- package/dist/validators/tuple.d.ts.map +0 -1
- package/dist/validators/uint8array.d.ts.map +0 -1
- package/dist/validators/undefined.d.ts.map +0 -1
- package/dist/validators/union.d.ts.map +0 -1
- package/dist/validators/unknown.d.ts.map +0 -1
- package/dist/validators/void.d.ts.map +0 -1
- package/dist/validators/xor.d.ts.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,17 +1,866 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import { VLD_VALIDATOR_TYPES, VldPreprocess, VldBase, VldExactOptional, VldNullish, VldNullable, VldOptional, resolveErrorMessage } from './validators/base.js';
|
|
2
|
+
export { VldMeta, VldBrand as ZodBranded, VldCatch as ZodCatch, VldDefault as ZodDefault, VldMeta as ZodMeta, VldRefine as ZodNonOptional, VldPipe as ZodPipe, VldPrefault as ZodPrefault, VldReadonly as ZodReadonly, VldTransform as ZodTransform } from './validators/base.js';
|
|
3
|
+
import { globalRegistry } from './registry.js';
|
|
4
|
+
export { registry } from './registry.js';
|
|
5
|
+
import { V as VldString } from './chunks/string-BJRQod3t.js';
|
|
6
|
+
import { VldNumber } from './validators/number.js';
|
|
7
|
+
import { VldBoolean } from './validators/boolean.js';
|
|
8
|
+
import { VldDate } from './validators/date.js';
|
|
9
|
+
import { VldStringBool } from './validators/string-bool.js';
|
|
10
|
+
import { VldArray } from './validators/array.js';
|
|
11
|
+
import { VldObject } from './validators/object.js';
|
|
12
|
+
import { VldUnion } from './validators/union.js';
|
|
13
|
+
import { VldLiteral } from './validators/literal.js';
|
|
14
|
+
import { VldBigInt } from './validators/bigint.js';
|
|
15
|
+
import { VldSymbol } from './validators/symbol.js';
|
|
16
|
+
import { VldTuple } from './validators/tuple.js';
|
|
17
|
+
import { VldRecord } from './validators/record.js';
|
|
18
|
+
import { VldSet } from './validators/set.js';
|
|
19
|
+
import { VldMap } from './validators/map.js';
|
|
20
|
+
import { VldEnum } from './validators/enum.js';
|
|
21
|
+
import { VldIntersection } from './validators/intersection.js';
|
|
22
|
+
import { VldAny } from './validators/any.js';
|
|
23
|
+
import { VldUnknown } from './validators/unknown.js';
|
|
24
|
+
import { VldVoid } from './validators/void.js';
|
|
25
|
+
import { VldNever } from './validators/never.js';
|
|
26
|
+
import { VldNull } from './validators/null.js';
|
|
27
|
+
import { VldUndefined } from './validators/undefined.js';
|
|
28
|
+
import { VldNan } from './validators/nan.js';
|
|
29
|
+
import { VldLazy } from './validators/lazy.js';
|
|
30
|
+
import { VldDiscriminatedUnion } from './validators/discriminated-union.js';
|
|
31
|
+
import { VldXor } from './validators/xor.js';
|
|
32
|
+
import { VldJson } from './validators/json.js';
|
|
33
|
+
import { templateLiteral as templateLiteral$1 } from './validators/template-literal.js';
|
|
34
|
+
export { VldTemplateLiteral as ZodTemplateLiteral } from './validators/template-literal.js';
|
|
35
|
+
import { custom as custom$1 } from './validators/custom.js';
|
|
36
|
+
export { VldCustom as ZodCustom, VldCustom as ZodSuccess } from './validators/custom.js';
|
|
37
|
+
import { VldFile, file as file$1 } from './validators/file.js';
|
|
38
|
+
import { functionValidator } from './validators/function.js';
|
|
39
|
+
export { VldFunction as ZodFunction } from './validators/function.js';
|
|
40
|
+
import { VldCodec } from './validators/codec.js';
|
|
41
|
+
import { VldBase64 } from './validators/base64.js';
|
|
42
|
+
import { VldHex } from './validators/hex.js';
|
|
43
|
+
import { VldUint8Array } from './validators/uint8array.js';
|
|
44
|
+
import { promise as promise$1 } from './validators/promise.js';
|
|
45
|
+
export { VldPromise as ZodPromise } from './validators/promise.js';
|
|
46
|
+
import { map as map$1 } from './compat/result.js';
|
|
47
|
+
export { Err, Ok, ResultUtils, all, failure, flatMap, fromNullable, isErr, isOk, isResult, mapErr, match, success, tryCatch, tryCatchAsync, unwrap, unwrapOr } from './compat/result.js';
|
|
48
|
+
import { l as localeNamespace } from './chunks/index-BvH403Yy.js';
|
|
49
|
+
export { s as setLocaleAsync } from './chunks/index-BvH403Yy.js';
|
|
50
|
+
import { VldCoerceBigInt, VldCoerceDate, VldCoerceBoolean, VldCoerceNumber, VldCoerceString } from './coercion/index.js';
|
|
51
|
+
import { flattenError, prettifyError, treeifyError } from './errors.js';
|
|
52
|
+
export { prettifyErrorColored, prettifyErrorPlain } from './errors.js';
|
|
53
|
+
import { uuid as uuid$1, httpUrl as httpUrl$1, email as email$1, regexes as REGEXES, ksuid as ksuid$1, guid as guid$1, xid as xid$1, stringFormat as stringFormat$1, iso as iso$1, hash as hash$1, e164 as e164$1, cidrv6 as cidrv6$1, cidrv4 as cidrv4$1, mac as mac$1, ipv6 as ipv6$1, ipv4 as ipv4$1, ulid as ulid$1, cuid2 as cuid2$1, cuid as cuid$1, nanoid as nanoid$1, jwt as jwt$1, hex as hex$1, base64url as base64url$1, base64 as base64$1, emoji as emoji$1, hostname as hostname$1, uuidv7 as uuidv7$1, uuidv6 as uuidv6$1, uuidv4 as uuidv4$1 } from './validators/string-formats.js';
|
|
54
|
+
export { VldStringFormat as ZodBase64, VldStringFormat as ZodBase64URL, VldStringFormat as ZodCIDRv4, VldStringFormat as ZodCIDRv6, VldStringFormat as ZodCUID, VldStringFormat as ZodCUID2, VldStringFormat as ZodCustomStringFormat, VldStringFormat as ZodE164, VldStringFormat as ZodEmail, VldStringFormat as ZodEmoji, VldStringFormat as ZodGUID, VldStringFormat as ZodIPv4, VldStringFormat as ZodIPv6, VldStringFormat as ZodISODate, VldStringFormat as ZodISODateTime, VldStringFormat as ZodISODuration, VldStringFormat as ZodISOTime, VldStringFormat as ZodJWT, VldStringFormat as ZodKSUID, VldStringFormat as ZodMAC, VldStringFormat as ZodNanoID, VldStringFormat as ZodStringFormat, VldStringFormat as ZodULID, VldStringFormat as ZodURL, VldStringFormat as ZodUUID, VldStringFormat as ZodXID } from './validators/string-formats.js';
|
|
55
|
+
export { b as base64Json, a as base64ToBytes, c as base64ToUint8Array, d as base64UrlToBytes, e as base64urlToBytes, f as bytesToUtf8, g as epochMillisToDate, h as epochSecondsToDate, i as hexLowerToBytes, j as hexToBytes, k as hexToUint8Array, l as invertCodec, m as isoDatetimeToDate, n as jsonCodec, o as jwtPayload, p as numberToBigInt, s as stringToBigInt, q as stringToBoolean, r as stringToHttpURL, t as stringToInt, u as stringToNumber, v as stringToURL, w as stringToUint8Array, x as uint8ArrayToBase64, y as uint8ArrayToBase64Url, z as uint8ArrayToHex, A as uint8ArrayToString, B as uriComponent, C as utf8ToBytes } from './chunks/index-0R2ntSud.js';
|
|
12
56
|
export { createEmitter, createEventBus, withEmitter } from './compat/emitter.js';
|
|
13
57
|
export { createVldKernel, definePlugin, getVldKernel, resetVldKernel, usePlugin } from './kernel.js';
|
|
14
|
-
export { blue, bold, createTheme, cyan, dim, gray, green, grey, italic, magenta, pigment, red, strip, supportsColor, underline, vldTheme, white, yellow } from './pigment.js';
|
|
58
|
+
export { blue, bold, createTheme, cyan, dim, gray, green, grey, italic, magenta, default as pigment, red, strip, supportsColor, underline, vldTheme, white, yellow } from './pigment.js';
|
|
59
|
+
import { V as VldError } from './chunks/errors-core-BeiFUtZM.js';
|
|
60
|
+
export { getLocale, getMessages, getSupportedLocales, isLocaleLoaded, isLocaleSupported, registerLocale, setLocale } from './locales/runtime.js';
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* JSON Schema support for VLD validators
|
|
64
|
+
* Provides conversion between VLD schemas and JSON Schema
|
|
65
|
+
*/
|
|
66
|
+
/**
|
|
67
|
+
* Convert a VLD schema to JSON Schema
|
|
68
|
+
* @param schema The VLD schema to convert
|
|
69
|
+
* @param options Conversion options
|
|
70
|
+
* @returns JSON Schema definition
|
|
71
|
+
*/
|
|
72
|
+
function toJSONSchema(schema, options = {}) {
|
|
73
|
+
const normalizedOptions = normalizeOptions(options);
|
|
74
|
+
const result = normalizeForTarget(schemaToJSONSchema(schema, normalizedOptions), normalizedOptions);
|
|
75
|
+
const target = normalizedOptions.target || 'draft-07';
|
|
76
|
+
if (target === 'draft-04') {
|
|
77
|
+
result.$schema ?? (result.$schema = 'http://json-schema.org/draft-04/schema#');
|
|
78
|
+
}
|
|
79
|
+
else if (target === 'draft-07') {
|
|
80
|
+
result.$schema ?? (result.$schema = 'http://json-schema.org/draft-07/schema#');
|
|
81
|
+
}
|
|
82
|
+
else if (target === 'draft-2019-09') {
|
|
83
|
+
result.$schema ?? (result.$schema = 'https://json-schema.org/draft/2019-09/schema');
|
|
84
|
+
}
|
|
85
|
+
else if (target === 'draft-2020-12') {
|
|
86
|
+
result.$schema ?? (result.$schema = 'https://json-schema.org/draft/2020-12/schema');
|
|
87
|
+
}
|
|
88
|
+
return result;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Convert a JSON Schema to a VLD schema
|
|
92
|
+
* @param json The JSON Schema definition
|
|
93
|
+
* @returns A VLD schema
|
|
94
|
+
*/
|
|
95
|
+
function fromJSONSchema(json) {
|
|
96
|
+
return jsonSchemaToVLD(json);
|
|
97
|
+
}
|
|
98
|
+
function normalizeOptions(options) {
|
|
99
|
+
const target = options.target;
|
|
100
|
+
if (target === 'draft-4') {
|
|
101
|
+
return { ...options, target: 'draft-04' };
|
|
102
|
+
}
|
|
103
|
+
if (target === 'draft-7') {
|
|
104
|
+
return { ...options, target: 'draft-07' };
|
|
105
|
+
}
|
|
106
|
+
return options;
|
|
107
|
+
}
|
|
108
|
+
function normalizeForTarget(definition, options) {
|
|
109
|
+
const target = options.target || 'draft-07';
|
|
110
|
+
const result = { ...definition };
|
|
111
|
+
if (Array.isArray(result.items)) {
|
|
112
|
+
const tupleItems = result.items.map((item) => normalizeForTarget(item, options));
|
|
113
|
+
if (target === 'draft-2020-12' || target === 'draft-2019-09') {
|
|
114
|
+
result.prefixItems = tupleItems;
|
|
115
|
+
result.items = false;
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
result.items = tupleItems;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
else if (result.items && typeof result.items === 'object') {
|
|
122
|
+
result.items = normalizeForTarget(result.items, options);
|
|
123
|
+
}
|
|
124
|
+
if (result.prefixItems) {
|
|
125
|
+
result.prefixItems = result.prefixItems.map((item) => normalizeForTarget(item, options));
|
|
126
|
+
}
|
|
127
|
+
if (result.properties) {
|
|
128
|
+
result.properties = Object.fromEntries(Object.entries(result.properties).map(([key, value]) => [key, normalizeForTarget(value, options)]));
|
|
129
|
+
}
|
|
130
|
+
if (result.additionalProperties && typeof result.additionalProperties === 'object') {
|
|
131
|
+
result.additionalProperties = normalizeForTarget(result.additionalProperties, options);
|
|
132
|
+
}
|
|
133
|
+
for (const key of ['anyOf', 'allOf', 'oneOf']) {
|
|
134
|
+
if (result[key]) {
|
|
135
|
+
result[key] = result[key].map((item) => normalizeForTarget(item, options));
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (result.not && typeof result.not === 'object') {
|
|
139
|
+
result.not = normalizeForTarget(result.not, options);
|
|
140
|
+
}
|
|
141
|
+
if (target === 'openapi-3.0') {
|
|
142
|
+
normalizeOpenAPI30(result);
|
|
143
|
+
}
|
|
144
|
+
return result;
|
|
145
|
+
}
|
|
146
|
+
function normalizeOpenAPI30(definition) {
|
|
147
|
+
if (Array.isArray(definition.type) && definition.type.includes('null')) {
|
|
148
|
+
const nonNullTypes = definition.type.filter((type) => type !== 'null');
|
|
149
|
+
definition.nullable = true;
|
|
150
|
+
if (nonNullTypes.length === 1) {
|
|
151
|
+
const nonNullType = nonNullTypes[0];
|
|
152
|
+
if (nonNullType !== undefined) {
|
|
153
|
+
definition.type = nonNullType;
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
delete definition.type;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
else if (nonNullTypes.length > 1) {
|
|
160
|
+
definition.type = nonNullTypes;
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
delete definition.type;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
if (typeof definition.exclusiveMinimum === 'number') {
|
|
167
|
+
definition.minimum ?? (definition.minimum = definition.exclusiveMinimum);
|
|
168
|
+
definition.exclusiveMinimum = true;
|
|
169
|
+
}
|
|
170
|
+
if (typeof definition.exclusiveMaximum === 'number') {
|
|
171
|
+
definition.maximum ?? (definition.maximum = definition.exclusiveMaximum);
|
|
172
|
+
definition.exclusiveMaximum = true;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Internal function to convert VLD schema to JSON Schema
|
|
177
|
+
*/
|
|
178
|
+
function schemaToJSONSchema(schema, options) {
|
|
179
|
+
const target = options.target || 'draft-07';
|
|
180
|
+
const schemaAny = schema;
|
|
181
|
+
const validatorType = schema.validatorType;
|
|
182
|
+
// Handle primitives
|
|
183
|
+
if (schema.constructor.name === 'VldString' || validatorType === VLD_VALIDATOR_TYPES.STRING) {
|
|
184
|
+
return withMetadata(schema, buildStringSchema(target, schema), options);
|
|
185
|
+
}
|
|
186
|
+
if (schema.constructor.name === 'VldNumber' || validatorType === VLD_VALIDATOR_TYPES.NUMBER) {
|
|
187
|
+
return withMetadata(schema, buildNumberSchema(schema), options);
|
|
188
|
+
}
|
|
189
|
+
if (schema.constructor.name === 'VldBoolean' || validatorType === VLD_VALIDATOR_TYPES.BOOLEAN) {
|
|
190
|
+
return withMetadata(schema, { type: 'boolean' }, options);
|
|
191
|
+
}
|
|
192
|
+
if (schema.constructor.name === 'VldBigInt' || validatorType === VLD_VALIDATOR_TYPES.BIGINT) {
|
|
193
|
+
return withMetadata(schema, buildBigIntSchema(schema), options);
|
|
194
|
+
}
|
|
195
|
+
if (schema.constructor.name === 'VldDate' || validatorType === VLD_VALIDATOR_TYPES.DATE) {
|
|
196
|
+
return withMetadata(schema, buildDateSchema(schema), options);
|
|
197
|
+
}
|
|
198
|
+
if (schema.constructor.name === 'VldArray' || validatorType === VLD_VALIDATOR_TYPES.ARRAY) {
|
|
199
|
+
return withMetadata(schema, buildArraySchema(schema, options), options);
|
|
200
|
+
}
|
|
201
|
+
if (schema.constructor.name === 'VldObject' || validatorType === VLD_VALIDATOR_TYPES.OBJECT) {
|
|
202
|
+
return withMetadata(schema, buildObjectSchema(schema, options), options);
|
|
203
|
+
}
|
|
204
|
+
// Handle union types
|
|
205
|
+
if (schema.constructor.name === 'VldUnion') {
|
|
206
|
+
return withMetadata(schema, buildUnionSchema(schema, options), options);
|
|
207
|
+
}
|
|
208
|
+
// Handle literal types
|
|
209
|
+
if (schema.constructor.name === 'VldLiteral') {
|
|
210
|
+
return withMetadata(schema, buildLiteralSchema(schema), options);
|
|
211
|
+
}
|
|
212
|
+
if (schema.constructor.name === 'VldEnum') {
|
|
213
|
+
return withMetadata(schema, buildEnumSchema(schema), options);
|
|
214
|
+
}
|
|
215
|
+
if (schema.constructor.name === 'VldSet' || validatorType === VLD_VALIDATOR_TYPES.SET) {
|
|
216
|
+
return withMetadata(schema, buildSetSchema(schema, options), options);
|
|
217
|
+
}
|
|
218
|
+
if (schema.constructor.name === 'VldMap' || validatorType === VLD_VALIDATOR_TYPES.MAP) {
|
|
219
|
+
return withMetadata(schema, buildMapSchema(schema, options), options);
|
|
220
|
+
}
|
|
221
|
+
if (schema.constructor.name === 'VldRecord' || validatorType === VLD_VALIDATOR_TYPES.RECORD) {
|
|
222
|
+
return withMetadata(schema, buildRecordSchema(schema, options), options);
|
|
223
|
+
}
|
|
224
|
+
if (schema.constructor.name === 'VldTuple' || validatorType === VLD_VALIDATOR_TYPES.TUPLE) {
|
|
225
|
+
return withMetadata(schema, buildTupleSchema(schema, options), options);
|
|
226
|
+
}
|
|
227
|
+
if (schema.constructor.name === 'VldIntersection') {
|
|
228
|
+
return withMetadata(schema, buildIntersectionSchema(schema, options), options);
|
|
229
|
+
}
|
|
230
|
+
if (schema.constructor.name === 'VldOptional') {
|
|
231
|
+
return withMetadata(schema, buildOptionalSchema(schema, options), options);
|
|
232
|
+
}
|
|
233
|
+
if (schema.constructor.name === 'VldNullable') {
|
|
234
|
+
return withMetadata(schema, buildNullableSchema(schema, options), options);
|
|
235
|
+
}
|
|
236
|
+
if (schema.constructor.name === 'VldNullish') {
|
|
237
|
+
return withMetadata(schema, buildNullishSchema(schema, options), options);
|
|
238
|
+
}
|
|
239
|
+
if (schema.constructor.name === 'VldExactOptional') {
|
|
240
|
+
return withMetadata(schema, buildExactOptionalSchema(schema, options), options);
|
|
241
|
+
}
|
|
242
|
+
if (schema.constructor.name === 'VldLazy') {
|
|
243
|
+
return withMetadata(schema, { type: 'object' }, options); // Placeholder for recursive schemas
|
|
244
|
+
}
|
|
245
|
+
if (schema.constructor.name === 'VldJson') {
|
|
246
|
+
return withMetadata(schema, {}, options); // Any JSON
|
|
247
|
+
}
|
|
248
|
+
if (schema.constructor.name === 'VldAny') {
|
|
249
|
+
return withMetadata(schema, {}, options); // JSON Schema true
|
|
250
|
+
}
|
|
251
|
+
if (schema.constructor.name === 'VldUnknown') {
|
|
252
|
+
return withMetadata(schema, {}, options); // JSON Schema true
|
|
253
|
+
}
|
|
254
|
+
if (schema.constructor.name === 'VldNever') {
|
|
255
|
+
return withMetadata(schema, { not: {} }, options); // JSON Schema false
|
|
256
|
+
}
|
|
257
|
+
if (schema.constructor.name === 'VldNull') {
|
|
258
|
+
return withMetadata(schema, { type: 'null' }, options);
|
|
259
|
+
}
|
|
260
|
+
if (schema.constructor.name === 'VldUndefined') {
|
|
261
|
+
return withMetadata(schema, { not: {} }, options); // Undefined can't be represented in JSON Schema
|
|
262
|
+
}
|
|
263
|
+
if (schema.constructor.name === 'VldNan') {
|
|
264
|
+
return withMetadata(schema, { type: 'number', not: {} }, options); // NaN is a number type constraint
|
|
265
|
+
}
|
|
266
|
+
if (schema.constructor.name === 'VldVoid') {
|
|
267
|
+
return withMetadata(schema, { not: {} }, options); // Void/undefined can't be represented
|
|
268
|
+
}
|
|
269
|
+
// Handle branded types - unwrap and continue
|
|
270
|
+
if (schema.constructor.name === 'VldBrand') {
|
|
271
|
+
return withMetadata(schema, schemaToJSONSchema(schemaAny.baseValidator, options), options);
|
|
272
|
+
}
|
|
273
|
+
// Handle readonly types
|
|
274
|
+
if (schema.constructor.name === 'VldReadonly') {
|
|
275
|
+
return withMetadata(schema, schemaToJSONSchema(schemaAny.baseValidator, options), options);
|
|
276
|
+
}
|
|
277
|
+
// Handle transform types
|
|
278
|
+
if (schema.constructor.name === 'VldTransform') {
|
|
279
|
+
return schemaToJSONSchema(schema._inner, options);
|
|
280
|
+
}
|
|
281
|
+
// Handle meta types - unwrap metadata
|
|
282
|
+
if (schema.constructor.name === 'VldMeta') {
|
|
283
|
+
const result = schemaToJSONSchema(schemaAny.baseValidator, options);
|
|
284
|
+
return withMetadata(schema, result, options);
|
|
285
|
+
}
|
|
286
|
+
// Handle refine/superRefine types
|
|
287
|
+
if (schema.constructor.name === 'VldRefine' || schema.constructor.name === 'VldSuperRefine') {
|
|
288
|
+
return withMetadata(schema, schemaToJSONSchema(unwrapInner(schemaAny), options), options);
|
|
289
|
+
}
|
|
290
|
+
// Handle pipe types
|
|
291
|
+
if (schema.constructor.name === 'VldPipe') {
|
|
292
|
+
return withMetadata(schema, schemaToJSONSchema(schemaAny._next || schemaAny.second, options), options);
|
|
293
|
+
}
|
|
294
|
+
// Handle default/catch types
|
|
295
|
+
if (schema.constructor.name === 'VldDefault' || schema.constructor.name === 'VldCatch') {
|
|
296
|
+
return withMetadata(schema, schemaToJSONSchema(unwrapInner(schemaAny), options), options);
|
|
297
|
+
}
|
|
298
|
+
// Handle preprocess types
|
|
299
|
+
if (schema.constructor.name === 'VldPreprocess') {
|
|
300
|
+
return withMetadata(schema, schemaToJSONSchema(schemaAny._schema, options), options);
|
|
301
|
+
}
|
|
302
|
+
// Handle string format validators
|
|
303
|
+
if (schema.constructor.name === 'VldStringFormat') {
|
|
304
|
+
const formatSchema = schema;
|
|
305
|
+
return withMetadata(schema, { type: 'string', format: formatSchema._format }, options);
|
|
306
|
+
}
|
|
307
|
+
// Fallback for unknown types
|
|
308
|
+
return withMetadata(schema, {}, options);
|
|
309
|
+
}
|
|
310
|
+
function unwrapInner(schema) {
|
|
311
|
+
if (typeof schema.unwrap === 'function') {
|
|
312
|
+
return schema.unwrap();
|
|
313
|
+
}
|
|
314
|
+
return schema._inner || schema._baseValidator || schema.baseValidator || schema.valueValidator;
|
|
315
|
+
}
|
|
316
|
+
function getMetadata(schema) {
|
|
317
|
+
const registered = globalRegistry.get(schema);
|
|
318
|
+
const schemaAny = schema;
|
|
319
|
+
const local = typeof schemaAny.getMeta === 'function' ? schemaAny.getMeta() : undefined;
|
|
320
|
+
return registered || local ? { ...(local || {}), ...(registered || {}) } : undefined;
|
|
321
|
+
}
|
|
322
|
+
function withMetadata(schema, definition, options) {
|
|
323
|
+
if (options.includeMetadata === false) {
|
|
324
|
+
return definition;
|
|
325
|
+
}
|
|
326
|
+
const metadata = getMetadata(schema);
|
|
327
|
+
if (!metadata) {
|
|
328
|
+
return definition;
|
|
329
|
+
}
|
|
330
|
+
const result = { ...definition };
|
|
331
|
+
if (metadata.id)
|
|
332
|
+
result.$id = metadata.id;
|
|
333
|
+
if (metadata.title)
|
|
334
|
+
result.title = metadata.title;
|
|
335
|
+
if (metadata.description)
|
|
336
|
+
result.description = metadata.description;
|
|
337
|
+
if (metadata.examples && options.includeExamples !== false)
|
|
338
|
+
result.examples = metadata.examples;
|
|
339
|
+
if (metadata.default !== undefined)
|
|
340
|
+
result.default = metadata.default;
|
|
341
|
+
if (metadata.deprecated)
|
|
342
|
+
result.deprecated = true;
|
|
343
|
+
if (metadata.readOnly)
|
|
344
|
+
result.readOnly = true;
|
|
345
|
+
if (metadata.writeOnly)
|
|
346
|
+
result.writeOnly = true;
|
|
347
|
+
return result;
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Build string JSON Schema
|
|
351
|
+
*/
|
|
352
|
+
function buildStringSchema(_target, schema) {
|
|
353
|
+
const hints = schema?.config?.jsonSchema || {};
|
|
354
|
+
const result = { type: 'string' };
|
|
355
|
+
if (hints.exactLength !== undefined) {
|
|
356
|
+
result.minLength = hints.exactLength;
|
|
357
|
+
result.maxLength = hints.exactLength;
|
|
358
|
+
}
|
|
359
|
+
else {
|
|
360
|
+
if (hints.minLength !== undefined)
|
|
361
|
+
result.minLength = hints.minLength;
|
|
362
|
+
if (hints.maxLength !== undefined)
|
|
363
|
+
result.maxLength = hints.maxLength;
|
|
364
|
+
}
|
|
365
|
+
if (hints.format)
|
|
366
|
+
result.format = hints.format;
|
|
367
|
+
if (hints.pattern)
|
|
368
|
+
result.pattern = hints.pattern;
|
|
369
|
+
return result;
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Build number JSON Schema from VLD number schema
|
|
373
|
+
*/
|
|
374
|
+
function buildNumberSchema(schema, _target) {
|
|
375
|
+
const config = schema.config || {};
|
|
376
|
+
const hints = config.jsonSchema || {};
|
|
377
|
+
const checks = config.checks || [];
|
|
378
|
+
const result = { type: hints.type || 'number' };
|
|
379
|
+
if (hints.minimum !== undefined)
|
|
380
|
+
result.minimum = hints.minimum;
|
|
381
|
+
if (hints.maximum !== undefined)
|
|
382
|
+
result.maximum = hints.maximum;
|
|
383
|
+
if (hints.exclusiveMinimum !== undefined)
|
|
384
|
+
result.exclusiveMinimum = hints.exclusiveMinimum;
|
|
385
|
+
if (hints.exclusiveMaximum !== undefined)
|
|
386
|
+
result.exclusiveMaximum = hints.exclusiveMaximum;
|
|
387
|
+
if (hints.multipleOf !== undefined)
|
|
388
|
+
result.multipleOf = hints.multipleOf;
|
|
389
|
+
if (Object.keys(hints).length > 0) {
|
|
390
|
+
return result;
|
|
391
|
+
}
|
|
392
|
+
for (const check of checks) {
|
|
393
|
+
// Try to extract constraints from closures
|
|
394
|
+
const checkStr = check.toString();
|
|
395
|
+
if (checkStr.includes('>=') || checkStr.includes('min')) {
|
|
396
|
+
result.minimum = 0; // Default, actual value is in closure
|
|
397
|
+
}
|
|
398
|
+
if (checkStr.includes('<=') || checkStr.includes('max')) {
|
|
399
|
+
result.maximum = 0; // Default, actual value is in closure
|
|
400
|
+
}
|
|
401
|
+
if (checkStr.includes('isInteger') || checkStr.includes('int')) {
|
|
402
|
+
result.type = 'integer';
|
|
403
|
+
}
|
|
404
|
+
if (checkStr.includes('isSafeInteger')) {
|
|
405
|
+
result.type = 'integer';
|
|
406
|
+
}
|
|
407
|
+
if (checkStr.includes('Number.isFinite')) ;
|
|
408
|
+
}
|
|
409
|
+
return result;
|
|
410
|
+
}
|
|
411
|
+
function bigintToSafeNumber(value) {
|
|
412
|
+
const asNumber = Number(value);
|
|
413
|
+
if (!Number.isSafeInteger(asNumber)) {
|
|
414
|
+
return undefined;
|
|
415
|
+
}
|
|
416
|
+
return BigInt(asNumber) === value ? asNumber : undefined;
|
|
417
|
+
}
|
|
418
|
+
function applyBigIntBound(result, numericKey, extensionKey, value) {
|
|
419
|
+
if (value === undefined) {
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
result[extensionKey] = value.toString();
|
|
423
|
+
const safeNumber = bigintToSafeNumber(value);
|
|
424
|
+
if (safeNumber !== undefined) {
|
|
425
|
+
result[numericKey] = safeNumber;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
function buildBigIntSchema(schema) {
|
|
429
|
+
const hints = schema.jsonSchema || schema.config?.jsonSchema || {};
|
|
430
|
+
const result = { type: 'integer' };
|
|
431
|
+
applyBigIntBound(result, 'minimum', 'x-vld-minimum', hints.minimum);
|
|
432
|
+
applyBigIntBound(result, 'maximum', 'x-vld-maximum', hints.maximum);
|
|
433
|
+
applyBigIntBound(result, 'exclusiveMinimum', 'x-vld-exclusiveMinimum', hints.exclusiveMinimum);
|
|
434
|
+
applyBigIntBound(result, 'exclusiveMaximum', 'x-vld-exclusiveMaximum', hints.exclusiveMaximum);
|
|
435
|
+
return result;
|
|
436
|
+
}
|
|
437
|
+
function buildDateSchema(schema) {
|
|
438
|
+
const hints = schema.jsonSchema || schema.config?.jsonSchema || {};
|
|
439
|
+
const result = {
|
|
440
|
+
type: 'string',
|
|
441
|
+
format: 'date-time'
|
|
442
|
+
};
|
|
443
|
+
if (hints.formatMinimum)
|
|
444
|
+
result.formatMinimum = hints.formatMinimum;
|
|
445
|
+
if (hints.formatMaximum)
|
|
446
|
+
result.formatMaximum = hints.formatMaximum;
|
|
447
|
+
if (hints.formatExclusiveMinimum)
|
|
448
|
+
result.formatExclusiveMinimum = hints.formatExclusiveMinimum;
|
|
449
|
+
if (hints.formatExclusiveMaximum)
|
|
450
|
+
result.formatExclusiveMaximum = hints.formatExclusiveMaximum;
|
|
451
|
+
return result;
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Build array JSON Schema
|
|
455
|
+
*/
|
|
456
|
+
function buildArraySchema(schema, options) {
|
|
457
|
+
const inner = schema._item || schema._inner || schema.config?.itemValidator;
|
|
458
|
+
const result = { type: 'array' };
|
|
459
|
+
if (inner) {
|
|
460
|
+
result.items = schemaToJSONSchema(inner, options);
|
|
461
|
+
}
|
|
462
|
+
if (schema.config?.exactLength !== undefined) {
|
|
463
|
+
result.minItems = schema.config.exactLength;
|
|
464
|
+
result.maxItems = schema.config.exactLength;
|
|
465
|
+
}
|
|
466
|
+
else {
|
|
467
|
+
if (schema.config?.minLength !== undefined)
|
|
468
|
+
result.minItems = schema.config.minLength;
|
|
469
|
+
if (schema.config?.maxLength !== undefined)
|
|
470
|
+
result.maxItems = schema.config.maxLength;
|
|
471
|
+
}
|
|
472
|
+
if (schema.config?.unique)
|
|
473
|
+
result.uniqueItems = true;
|
|
474
|
+
return result;
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Build object JSON Schema
|
|
478
|
+
*/
|
|
479
|
+
function buildObjectSchema(schema, options) {
|
|
480
|
+
const shape = schema._shape || schema.shape || schema.config?.shape;
|
|
481
|
+
if (!shape)
|
|
482
|
+
return { type: 'object' };
|
|
483
|
+
const properties = {};
|
|
484
|
+
const required = [];
|
|
485
|
+
for (const [key, value] of Object.entries(shape)) {
|
|
486
|
+
const child = value;
|
|
487
|
+
properties[key] = schemaToJSONSchema(child, options);
|
|
488
|
+
// VLD objects require all keys by default
|
|
489
|
+
if (!isOptionalLike(child)) {
|
|
490
|
+
required.push(key);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
const result = {
|
|
494
|
+
type: 'object',
|
|
495
|
+
properties
|
|
496
|
+
};
|
|
497
|
+
if (required.length > 0) {
|
|
498
|
+
result.required = required;
|
|
499
|
+
}
|
|
500
|
+
// Handle passthrough mode
|
|
501
|
+
if (schema._passthrough || schema._loose || schema.config?.passthrough) {
|
|
502
|
+
result.additionalProperties = true;
|
|
503
|
+
}
|
|
504
|
+
else if (schema._strict || schema.config?.strict) {
|
|
505
|
+
result.additionalProperties = false;
|
|
506
|
+
}
|
|
507
|
+
else if (schema.config?.catchall) {
|
|
508
|
+
result.additionalProperties = schemaToJSONSchema(schema.config.catchall, options);
|
|
509
|
+
}
|
|
510
|
+
return result;
|
|
511
|
+
}
|
|
512
|
+
function isOptionalLike(schema) {
|
|
513
|
+
const name = schema.constructor.name;
|
|
514
|
+
return (name === 'VldOptional' ||
|
|
515
|
+
name === 'VldNullish' ||
|
|
516
|
+
name === 'VldExactOptional' ||
|
|
517
|
+
schema.validatorType === VLD_VALIDATOR_TYPES.OPTIONAL ||
|
|
518
|
+
schema.validatorType === VLD_VALIDATOR_TYPES.NULLISH ||
|
|
519
|
+
schema.validatorType === VLD_VALIDATOR_TYPES.EXACT_OPTIONAL);
|
|
520
|
+
}
|
|
521
|
+
/**
|
|
522
|
+
* Build union JSON Schema
|
|
523
|
+
*/
|
|
524
|
+
function buildUnionSchema(schema, options) {
|
|
525
|
+
const validators = schema._validators || schema._options || schema.validators || [];
|
|
526
|
+
return {
|
|
527
|
+
anyOf: validators.map((v) => schemaToJSONSchema(v, options))
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
/**
|
|
531
|
+
* Build literal JSON Schema
|
|
532
|
+
*/
|
|
533
|
+
function buildLiteralSchema(schema) {
|
|
534
|
+
const value = schema._literal ?? schema.literal ?? schema._value ?? schema.value;
|
|
535
|
+
if (value === null)
|
|
536
|
+
return { type: 'null' };
|
|
537
|
+
if (typeof value === 'string')
|
|
538
|
+
return { type: 'string', const: value };
|
|
539
|
+
if (typeof value === 'number')
|
|
540
|
+
return { type: 'number', const: value };
|
|
541
|
+
if (typeof value === 'boolean')
|
|
542
|
+
return { type: 'boolean', const: value };
|
|
543
|
+
return { const: value };
|
|
544
|
+
}
|
|
545
|
+
/**
|
|
546
|
+
* Build enum JSON Schema
|
|
547
|
+
*/
|
|
548
|
+
function buildEnumSchema(schema) {
|
|
549
|
+
const values = schema._values || schema.values;
|
|
550
|
+
if (Array.isArray(values)) {
|
|
551
|
+
return { enum: [...values] };
|
|
552
|
+
}
|
|
553
|
+
return {};
|
|
554
|
+
}
|
|
555
|
+
/**
|
|
556
|
+
* Build record JSON Schema
|
|
557
|
+
*/
|
|
558
|
+
function buildRecordSchema(schema, options) {
|
|
559
|
+
const valueValidator = schema.valueSchema || schema._value || schema._inner || schema.valueValidator;
|
|
560
|
+
if (valueValidator) {
|
|
561
|
+
return {
|
|
562
|
+
type: 'object',
|
|
563
|
+
additionalProperties: schemaToJSONSchema(valueValidator, options)
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
return { type: 'object' };
|
|
567
|
+
}
|
|
568
|
+
/**
|
|
569
|
+
* Build Set JSON Schema as the JSON-compatible array representation.
|
|
570
|
+
*/
|
|
571
|
+
function buildSetSchema(schema, options) {
|
|
572
|
+
const itemValidator = schema.itemSchema || schema.itemValidator || schema._item || schema._inner;
|
|
573
|
+
const result = {
|
|
574
|
+
type: 'array',
|
|
575
|
+
uniqueItems: true,
|
|
576
|
+
'x-vld-type': 'set'
|
|
577
|
+
};
|
|
578
|
+
if (itemValidator) {
|
|
579
|
+
result.items = schemaToJSONSchema(itemValidator, options);
|
|
580
|
+
}
|
|
581
|
+
return result;
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* Build Map JSON Schema as an array of key/value pairs.
|
|
585
|
+
*/
|
|
586
|
+
function buildMapSchema(schema, options) {
|
|
587
|
+
const keyValidator = schema.keySchema || schema.keyValidator || schema._key;
|
|
588
|
+
const valueValidator = schema.valueSchema || schema.valueValidator || schema._value;
|
|
589
|
+
const keySchema = keyValidator ? schemaToJSONSchema(keyValidator, options) : {};
|
|
590
|
+
const valueSchema = valueValidator ? schemaToJSONSchema(valueValidator, options) : {};
|
|
591
|
+
return {
|
|
592
|
+
type: 'array',
|
|
593
|
+
'x-vld-type': 'map',
|
|
594
|
+
items: {
|
|
595
|
+
type: 'array',
|
|
596
|
+
items: [keySchema, valueSchema],
|
|
597
|
+
minItems: 2,
|
|
598
|
+
maxItems: 2
|
|
599
|
+
}
|
|
600
|
+
};
|
|
601
|
+
}
|
|
602
|
+
/**
|
|
603
|
+
* Build tuple JSON Schema
|
|
604
|
+
*/
|
|
605
|
+
function buildTupleSchema(schema, options) {
|
|
606
|
+
const items = schema.items || schema._items || schema.validators;
|
|
607
|
+
if (!items || !Array.isArray(items)) {
|
|
608
|
+
return { type: 'array' };
|
|
609
|
+
}
|
|
610
|
+
return {
|
|
611
|
+
type: 'array',
|
|
612
|
+
items: items.map((item) => schemaToJSONSchema(item, options)),
|
|
613
|
+
minItems: items.length,
|
|
614
|
+
maxItems: items.length
|
|
615
|
+
};
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
618
|
+
* Build intersection JSON Schema
|
|
619
|
+
*/
|
|
620
|
+
function buildIntersectionSchema(schema, options) {
|
|
621
|
+
const first = schema._first || schema.first;
|
|
622
|
+
const second = schema._second || schema.second;
|
|
623
|
+
const schemas = [];
|
|
624
|
+
if (first)
|
|
625
|
+
schemas.push(schemaToJSONSchema(first, options));
|
|
626
|
+
if (second)
|
|
627
|
+
schemas.push(schemaToJSONSchema(second, options));
|
|
628
|
+
if (schemas.length === 0)
|
|
629
|
+
return {};
|
|
630
|
+
if (schemas.length === 1)
|
|
631
|
+
return schemas[0] ?? {};
|
|
632
|
+
return { allOf: schemas };
|
|
633
|
+
}
|
|
634
|
+
/**
|
|
635
|
+
* Build optional JSON Schema
|
|
636
|
+
*/
|
|
637
|
+
function buildOptionalSchema(schema, options) {
|
|
638
|
+
const inner = unwrapInner(schema);
|
|
639
|
+
if (!inner)
|
|
640
|
+
return {};
|
|
641
|
+
const result = schemaToJSONSchema(inner, options);
|
|
642
|
+
// Remove from required array - but we don't track required here
|
|
643
|
+
return result;
|
|
644
|
+
}
|
|
645
|
+
/**
|
|
646
|
+
* Build nullable JSON Schema
|
|
647
|
+
*/
|
|
648
|
+
function buildNullableSchema(schema, options) {
|
|
649
|
+
const inner = unwrapInner(schema);
|
|
650
|
+
if (!inner)
|
|
651
|
+
return { type: 'null' };
|
|
652
|
+
const result = schemaToJSONSchema(inner, options);
|
|
653
|
+
if (typeof result.type === 'string') {
|
|
654
|
+
return { type: [result.type, 'null'] };
|
|
655
|
+
}
|
|
656
|
+
else if (Array.isArray(result.type)) {
|
|
657
|
+
result.type.push('null');
|
|
658
|
+
return result;
|
|
659
|
+
}
|
|
660
|
+
return {
|
|
661
|
+
anyOf: [result, { type: 'null' }]
|
|
662
|
+
};
|
|
663
|
+
}
|
|
664
|
+
/**
|
|
665
|
+
* Build nullish JSON Schema
|
|
666
|
+
*/
|
|
667
|
+
function buildNullishSchema(schema, options) {
|
|
668
|
+
const inner = unwrapInner(schema);
|
|
669
|
+
if (!inner)
|
|
670
|
+
return {};
|
|
671
|
+
const result = schemaToJSONSchema(inner, options);
|
|
672
|
+
if (typeof result.type === 'string') {
|
|
673
|
+
return { ...result, type: [result.type, 'null'] };
|
|
674
|
+
}
|
|
675
|
+
return result;
|
|
676
|
+
}
|
|
677
|
+
/**
|
|
678
|
+
* Build exactOptional JSON Schema
|
|
679
|
+
*/
|
|
680
|
+
function buildExactOptionalSchema(schema, options) {
|
|
681
|
+
const inner = unwrapInner(schema);
|
|
682
|
+
if (!inner)
|
|
683
|
+
return {};
|
|
684
|
+
return schemaToJSONSchema(inner, options);
|
|
685
|
+
}
|
|
686
|
+
/**
|
|
687
|
+
* Internal function to convert JSON Schema to VLD schema
|
|
688
|
+
*/
|
|
689
|
+
function jsonSchemaToVLD(json) {
|
|
690
|
+
return applyJSONSchemaMetadata(jsonSchemaToVLDInner(json), json);
|
|
691
|
+
}
|
|
692
|
+
function jsonSchemaToVLDInner(json) {
|
|
693
|
+
// Handle $ref
|
|
694
|
+
if (json.$ref) {
|
|
695
|
+
// For now, return any - full $ref handling requires registry
|
|
696
|
+
return VldAny.create();
|
|
697
|
+
}
|
|
698
|
+
// Handle anyOf/oneOf (union)
|
|
699
|
+
if (json.anyOf || json.oneOf) {
|
|
700
|
+
const options = (json.anyOf || json.oneOf)
|
|
701
|
+
.map((s) => jsonSchemaToVLD(s))
|
|
702
|
+
.filter(Boolean);
|
|
703
|
+
if (options.length > 0) {
|
|
704
|
+
return VldUnion.create(...options);
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
// Handle allOf (intersection)
|
|
708
|
+
if (json.allOf) {
|
|
709
|
+
// For intersection, we'd need VldIntersection
|
|
710
|
+
const firstSchema = json.allOf[0];
|
|
711
|
+
if (firstSchema === undefined) {
|
|
712
|
+
return VldAny.create();
|
|
713
|
+
}
|
|
714
|
+
const first = jsonSchemaToVLD(firstSchema);
|
|
715
|
+
if (json.allOf.length > 1) {
|
|
716
|
+
const second = jsonSchemaToVLD({ allOf: json.allOf.slice(1) });
|
|
717
|
+
return VldIntersection.create(first, second);
|
|
718
|
+
}
|
|
719
|
+
return first;
|
|
720
|
+
}
|
|
721
|
+
// Handle not
|
|
722
|
+
if (json.not) {
|
|
723
|
+
// For negation, we need special handling
|
|
724
|
+
return VldAny.create();
|
|
725
|
+
}
|
|
726
|
+
// Handle const
|
|
727
|
+
if (json.const !== undefined) {
|
|
728
|
+
return VldLiteral.create(json.const);
|
|
729
|
+
}
|
|
730
|
+
// Handle enum
|
|
731
|
+
if (json.enum) {
|
|
732
|
+
return VldEnum.create(json.enum);
|
|
733
|
+
}
|
|
734
|
+
// Handle type
|
|
735
|
+
const type = json.nullable && typeof json.type === 'string'
|
|
736
|
+
? [json.type, 'null']
|
|
737
|
+
: json.type;
|
|
738
|
+
if (type === 'string' || type === undefined) {
|
|
739
|
+
let s = VldString.create();
|
|
740
|
+
if (json.minLength !== undefined)
|
|
741
|
+
s = s.min(json.minLength);
|
|
742
|
+
if (json.maxLength !== undefined)
|
|
743
|
+
s = s.max(json.maxLength);
|
|
744
|
+
if (json.pattern)
|
|
745
|
+
s = s.regex(new RegExp(json.pattern));
|
|
746
|
+
if (json.format) {
|
|
747
|
+
// Map JSON Schema formats to VLD validators
|
|
748
|
+
switch (json.format) {
|
|
749
|
+
case 'date-time':
|
|
750
|
+
case 'date':
|
|
751
|
+
case 'time':
|
|
752
|
+
// Would need DateTime validator
|
|
753
|
+
break;
|
|
754
|
+
case 'email':
|
|
755
|
+
return email$1();
|
|
756
|
+
case 'uri':
|
|
757
|
+
case 'uri-reference':
|
|
758
|
+
return httpUrl$1();
|
|
759
|
+
case 'uuid':
|
|
760
|
+
return uuid$1();
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
return s;
|
|
764
|
+
}
|
|
765
|
+
if (type === 'number' || type === 'integer') {
|
|
766
|
+
let n = VldNumber.create();
|
|
767
|
+
if (type === 'integer')
|
|
768
|
+
n = n.int();
|
|
769
|
+
if (json.minimum !== undefined)
|
|
770
|
+
n = n.min(json.minimum);
|
|
771
|
+
if (json.maximum !== undefined)
|
|
772
|
+
n = n.max(json.maximum);
|
|
773
|
+
if (typeof json.exclusiveMinimum === 'number')
|
|
774
|
+
n = n.gt(json.exclusiveMinimum);
|
|
775
|
+
if (typeof json.exclusiveMaximum === 'number')
|
|
776
|
+
n = n.lt(json.exclusiveMaximum);
|
|
777
|
+
if (json.exclusiveMinimum === true && json.minimum !== undefined)
|
|
778
|
+
n = n.gt(json.minimum);
|
|
779
|
+
if (json.exclusiveMaximum === true && json.maximum !== undefined)
|
|
780
|
+
n = n.lt(json.maximum);
|
|
781
|
+
if (json.multipleOf !== undefined)
|
|
782
|
+
n = n.multipleOf(json.multipleOf);
|
|
783
|
+
return n;
|
|
784
|
+
}
|
|
785
|
+
if (type === 'boolean') {
|
|
786
|
+
return VldBoolean.create();
|
|
787
|
+
}
|
|
788
|
+
if (type === 'array') {
|
|
789
|
+
if (json.prefixItems && json.prefixItems.length > 0) {
|
|
790
|
+
const validators = json.prefixItems.map((item) => jsonSchemaToVLD(item));
|
|
791
|
+
return VldTuple.create(...validators);
|
|
792
|
+
}
|
|
793
|
+
if (Array.isArray(json.items)) {
|
|
794
|
+
const validators = json.items.map((item) => jsonSchemaToVLD(item));
|
|
795
|
+
return VldTuple.create(...validators);
|
|
796
|
+
}
|
|
797
|
+
if (json.items && !Array.isArray(json.items)) {
|
|
798
|
+
return VldArray.create(jsonSchemaToVLD(json.items));
|
|
799
|
+
}
|
|
800
|
+
return VldArray.create(VldAny.create());
|
|
801
|
+
}
|
|
802
|
+
if (type === 'object') {
|
|
803
|
+
if (json.properties) {
|
|
804
|
+
const shape = {};
|
|
805
|
+
const required = new Set(json.required || []);
|
|
806
|
+
for (const [key, propSchema] of Object.entries(json.properties)) {
|
|
807
|
+
const fieldSchema = jsonSchemaToVLD(propSchema);
|
|
808
|
+
shape[key] = required.has(key) ? fieldSchema : fieldSchema.optional();
|
|
809
|
+
}
|
|
810
|
+
let obj = VldObject.create(shape);
|
|
811
|
+
if (json.additionalProperties === false) {
|
|
812
|
+
obj = obj.strict();
|
|
813
|
+
}
|
|
814
|
+
else if (json.additionalProperties === true) {
|
|
815
|
+
obj = obj.passthrough();
|
|
816
|
+
}
|
|
817
|
+
else if (json.additionalProperties) {
|
|
818
|
+
// additionalProperties is a schema
|
|
819
|
+
const valueSchema = jsonSchemaToVLD(json.additionalProperties);
|
|
820
|
+
return VldRecord.create(valueSchema);
|
|
821
|
+
}
|
|
822
|
+
return obj;
|
|
823
|
+
}
|
|
824
|
+
// Empty object schema
|
|
825
|
+
return VldObject.create({});
|
|
826
|
+
}
|
|
827
|
+
if (type === 'null') {
|
|
828
|
+
return VldNull.create();
|
|
829
|
+
}
|
|
830
|
+
if (Array.isArray(type)) {
|
|
831
|
+
// Union of types
|
|
832
|
+
const options = type.map((t) => {
|
|
833
|
+
return jsonSchemaToVLD({ ...json, type: t, nullable: false });
|
|
834
|
+
});
|
|
835
|
+
if (options.length > 0) {
|
|
836
|
+
return VldUnion.create(...options);
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
// Fallback to any
|
|
840
|
+
return VldAny.create();
|
|
841
|
+
}
|
|
842
|
+
function applyJSONSchemaMetadata(schema, json) {
|
|
843
|
+
const metadata = {};
|
|
844
|
+
if (json.$id)
|
|
845
|
+
metadata.id = json.$id;
|
|
846
|
+
if (json.title)
|
|
847
|
+
metadata.title = json.title;
|
|
848
|
+
if (json.description)
|
|
849
|
+
metadata.description = json.description;
|
|
850
|
+
if (json.examples)
|
|
851
|
+
metadata.examples = json.examples;
|
|
852
|
+
if (json.default !== undefined)
|
|
853
|
+
metadata.default = json.default;
|
|
854
|
+
if (json.deprecated)
|
|
855
|
+
metadata.deprecated = true;
|
|
856
|
+
if (json.readOnly)
|
|
857
|
+
metadata.readOnly = true;
|
|
858
|
+
if (json.writeOnly)
|
|
859
|
+
metadata.writeOnly = true;
|
|
860
|
+
return Object.keys(metadata).length > 0
|
|
861
|
+
? schema.meta(metadata)
|
|
862
|
+
: schema;
|
|
863
|
+
}
|
|
15
864
|
|
|
16
865
|
/**
|
|
17
866
|
* VLD Logger
|
|
@@ -206,7 +1055,192 @@ function createNoOpLogger() {
|
|
|
206
1055
|
* - Colored console output for better debugging
|
|
207
1056
|
* - Debug logging system
|
|
208
1057
|
*/
|
|
209
|
-
// Import
|
|
1058
|
+
// Import base class
|
|
1059
|
+
let globalConfig = {};
|
|
1060
|
+
let globalErrorMap;
|
|
1061
|
+
function configure(config) {
|
|
1062
|
+
if (config === undefined) {
|
|
1063
|
+
return { ...globalConfig };
|
|
1064
|
+
}
|
|
1065
|
+
globalConfig = { ...globalConfig, ...config };
|
|
1066
|
+
if ('customError' in config) {
|
|
1067
|
+
globalErrorMap = config.customError;
|
|
1068
|
+
}
|
|
1069
|
+
else if ('errorMap' in config) {
|
|
1070
|
+
globalErrorMap = config.errorMap;
|
|
1071
|
+
}
|
|
1072
|
+
return { ...globalConfig };
|
|
1073
|
+
}
|
|
1074
|
+
function setGlobalErrorMap(errorMap) {
|
|
1075
|
+
globalErrorMap = errorMap;
|
|
1076
|
+
globalConfig = { ...globalConfig, errorMap };
|
|
1077
|
+
}
|
|
1078
|
+
function getGlobalErrorMap() {
|
|
1079
|
+
return globalErrorMap;
|
|
1080
|
+
}
|
|
1081
|
+
function enumValuesFromNativeEnum(enumObject) {
|
|
1082
|
+
const values = Object.keys(enumObject)
|
|
1083
|
+
.filter(key => !/^\d+$/.test(key))
|
|
1084
|
+
.map(key => enumObject[key])
|
|
1085
|
+
.filter((value) => typeof value === 'string' || typeof value === 'number');
|
|
1086
|
+
const uniqueValues = Array.from(new Set(values));
|
|
1087
|
+
if (uniqueValues.length === 0) {
|
|
1088
|
+
throw new Error('nativeEnum requires at least one string or number value');
|
|
1089
|
+
}
|
|
1090
|
+
return uniqueValues;
|
|
1091
|
+
}
|
|
1092
|
+
function toErrorMessage(error) {
|
|
1093
|
+
return error instanceof Error ? error.message : String(error);
|
|
1094
|
+
}
|
|
1095
|
+
function addFormattedIssue(root, path, message) {
|
|
1096
|
+
let current = root;
|
|
1097
|
+
for (const segment of path) {
|
|
1098
|
+
const key = String(segment);
|
|
1099
|
+
const next = current[key];
|
|
1100
|
+
if (!next || Array.isArray(next)) {
|
|
1101
|
+
current[key] = { _errors: [] };
|
|
1102
|
+
}
|
|
1103
|
+
current = current[key];
|
|
1104
|
+
}
|
|
1105
|
+
current._errors.push(message);
|
|
1106
|
+
}
|
|
1107
|
+
function isCodec(schema) {
|
|
1108
|
+
return schema instanceof VldCodec;
|
|
1109
|
+
}
|
|
1110
|
+
function messageFromRefinementParam(param) {
|
|
1111
|
+
return param === undefined ? undefined : resolveErrorMessage(param, 'Refinement check failed');
|
|
1112
|
+
}
|
|
1113
|
+
function cloneSchema(schema) {
|
|
1114
|
+
return schema;
|
|
1115
|
+
}
|
|
1116
|
+
function createTransform(transformer) {
|
|
1117
|
+
return custom$1({
|
|
1118
|
+
parse: (value) => {
|
|
1119
|
+
const transformed = transformer(value, { addIssue: () => undefined, path: [] });
|
|
1120
|
+
if (transformed !== null && typeof transformed === 'object' && typeof transformed.then === 'function') {
|
|
1121
|
+
throw new Error('Use parseAsync for async transforms');
|
|
1122
|
+
}
|
|
1123
|
+
return transformed;
|
|
1124
|
+
},
|
|
1125
|
+
parseAsync: async (value) => {
|
|
1126
|
+
const transformed = await Promise.resolve(transformer(value, { addIssue: () => undefined, path: [] }));
|
|
1127
|
+
return transformed;
|
|
1128
|
+
}
|
|
1129
|
+
});
|
|
1130
|
+
}
|
|
1131
|
+
function createRefinement(predicate, message) {
|
|
1132
|
+
return custom$1({
|
|
1133
|
+
parse: (value) => {
|
|
1134
|
+
const passed = predicate(value);
|
|
1135
|
+
if (passed !== null && typeof passed === 'object' && typeof passed.then === 'function') {
|
|
1136
|
+
throw new Error('Use parseAsync for async refinements');
|
|
1137
|
+
}
|
|
1138
|
+
if (!passed) {
|
|
1139
|
+
throw new Error(messageFromRefinementParam(message) || 'Refinement check failed');
|
|
1140
|
+
}
|
|
1141
|
+
return value;
|
|
1142
|
+
},
|
|
1143
|
+
parseAsync: async (value) => {
|
|
1144
|
+
if (!await predicate(value)) {
|
|
1145
|
+
throw new Error(messageFromRefinementParam(message) || 'Refinement check failed');
|
|
1146
|
+
}
|
|
1147
|
+
return value;
|
|
1148
|
+
}
|
|
1149
|
+
});
|
|
1150
|
+
}
|
|
1151
|
+
function createSuperRefinement(refinement) {
|
|
1152
|
+
return VldUnknown.create().superRefine(refinement);
|
|
1153
|
+
}
|
|
1154
|
+
function propertyCheck(property, schema, message) {
|
|
1155
|
+
return custom$1({
|
|
1156
|
+
parse: (value) => {
|
|
1157
|
+
if (typeof value !== 'object' || value === null || !(property in value)) {
|
|
1158
|
+
throw new Error(messageFromRefinementParam(message) || `Expected object with property "${property}"`);
|
|
1159
|
+
}
|
|
1160
|
+
const result = schema.safeParse(value[property]);
|
|
1161
|
+
if (!result.success) {
|
|
1162
|
+
throw new Error(messageFromRefinementParam(message) || result.error.message);
|
|
1163
|
+
}
|
|
1164
|
+
return value;
|
|
1165
|
+
}
|
|
1166
|
+
});
|
|
1167
|
+
}
|
|
1168
|
+
function getParsedType(value) {
|
|
1169
|
+
if (value === null)
|
|
1170
|
+
return 'null';
|
|
1171
|
+
if (Array.isArray(value))
|
|
1172
|
+
return 'array';
|
|
1173
|
+
if (Number.isNaN(value))
|
|
1174
|
+
return 'nan';
|
|
1175
|
+
return typeof value;
|
|
1176
|
+
}
|
|
1177
|
+
const TimePrecision = {
|
|
1178
|
+
Any: null,
|
|
1179
|
+
Minute: -1,
|
|
1180
|
+
Second: 0,
|
|
1181
|
+
Millisecond: 3,
|
|
1182
|
+
Microsecond: 6
|
|
1183
|
+
};
|
|
1184
|
+
const ZodFirstPartyTypeKind = {};
|
|
1185
|
+
const $brand = Symbol.for('vld_brand');
|
|
1186
|
+
const $input = Symbol.for('VldInput');
|
|
1187
|
+
const $output = Symbol.for('VldOutput');
|
|
1188
|
+
const ZodIssueCode = {
|
|
1189
|
+
invalid_type: 'invalid_type',
|
|
1190
|
+
too_big: 'too_big',
|
|
1191
|
+
too_small: 'too_small',
|
|
1192
|
+
invalid_format: 'invalid_format',
|
|
1193
|
+
not_multiple_of: 'not_multiple_of',
|
|
1194
|
+
unrecognized_keys: 'unrecognized_keys',
|
|
1195
|
+
invalid_union: 'invalid_union',
|
|
1196
|
+
invalid_key: 'invalid_key',
|
|
1197
|
+
invalid_element: 'invalid_element',
|
|
1198
|
+
invalid_value: 'invalid_value',
|
|
1199
|
+
custom: 'custom'
|
|
1200
|
+
};
|
|
1201
|
+
const util = {
|
|
1202
|
+
getParsedType,
|
|
1203
|
+
propertyKeyTypes: new Set(['string', 'number', 'symbol']),
|
|
1204
|
+
primitiveTypes: new Set(['string', 'number', 'bigint', 'boolean', 'symbol', 'undefined', 'null']),
|
|
1205
|
+
assert: (condition, message = 'Assertion failed') => {
|
|
1206
|
+
if (!condition) {
|
|
1207
|
+
throw new Error(message);
|
|
1208
|
+
}
|
|
1209
|
+
},
|
|
1210
|
+
assertNever: (value) => {
|
|
1211
|
+
throw new Error(`Unexpected value: ${String(value)}`);
|
|
1212
|
+
},
|
|
1213
|
+
joinValues: (values, separator = ' | ') => values.map(value => JSON.stringify(value)).join(separator),
|
|
1214
|
+
jsonStringifyReplacer: (_key, value) => typeof value === 'bigint' ? value.toString() : value,
|
|
1215
|
+
nullish: (value) => value === null || value === undefined,
|
|
1216
|
+
cached: (getter) => {
|
|
1217
|
+
let initialized = false;
|
|
1218
|
+
let value;
|
|
1219
|
+
return () => {
|
|
1220
|
+
if (!initialized) {
|
|
1221
|
+
value = getter();
|
|
1222
|
+
initialized = true;
|
|
1223
|
+
}
|
|
1224
|
+
return value;
|
|
1225
|
+
};
|
|
1226
|
+
}
|
|
1227
|
+
};
|
|
1228
|
+
const core = {
|
|
1229
|
+
util,
|
|
1230
|
+
regexes: REGEXES,
|
|
1231
|
+
locales: localeNamespace,
|
|
1232
|
+
NEVER: VldNever.create(),
|
|
1233
|
+
TimePrecision,
|
|
1234
|
+
ZodIssueCode,
|
|
1235
|
+
globalRegistry,
|
|
1236
|
+
config: configure,
|
|
1237
|
+
getErrorMap: getGlobalErrorMap,
|
|
1238
|
+
setErrorMap: setGlobalErrorMap,
|
|
1239
|
+
parse: (schema, value) => schema.parse(value),
|
|
1240
|
+
safeParse: (schema, value) => schema.safeParse(value),
|
|
1241
|
+
parseAsync: (schema, value) => schema.parseAsync(value),
|
|
1242
|
+
safeParseAsync: (schema, value) => schema.safeParseAsync(value)
|
|
1243
|
+
};
|
|
210
1244
|
/**
|
|
211
1245
|
* Main API object with factory methods for all validators
|
|
212
1246
|
*/
|
|
@@ -216,6 +1250,11 @@ const v = {
|
|
|
216
1250
|
number: () => VldNumber.create(),
|
|
217
1251
|
int: () => VldNumber.create().int(),
|
|
218
1252
|
int32: () => VldNumber.create().int().min(-2147483648).max(2147483647),
|
|
1253
|
+
uint32: () => VldNumber.create().uint32(),
|
|
1254
|
+
uint64: () => VldNumber.create().uint64(),
|
|
1255
|
+
int64: () => VldNumber.create().int64(),
|
|
1256
|
+
float32: () => VldNumber.create().float32(),
|
|
1257
|
+
float64: () => VldNumber.create().float64(),
|
|
219
1258
|
boolean: () => VldBoolean.create(),
|
|
220
1259
|
date: () => VldDate.create(),
|
|
221
1260
|
bigint: () => VldBigInt.create(),
|
|
@@ -237,9 +1276,11 @@ const v = {
|
|
|
237
1276
|
intersection: (first, second) => VldIntersection.create(first, second),
|
|
238
1277
|
discriminatedUnion: (discriminator, ...options) => VldDiscriminatedUnion.create(discriminator, [...options]),
|
|
239
1278
|
xor: (...options) => VldXor.create([...options]),
|
|
1279
|
+
keyof: (schema) => schema.keyof(),
|
|
240
1280
|
// Literal and enum
|
|
241
1281
|
literal: (value) => VldLiteral.create(value),
|
|
242
1282
|
enum: (...values) => VldEnum.create(values),
|
|
1283
|
+
nativeEnum: (enumObject) => VldEnum.create(enumValuesFromNativeEnum(enumObject)),
|
|
243
1284
|
// Special validators
|
|
244
1285
|
any: () => VldAny.create(),
|
|
245
1286
|
unknown: () => VldUnknown.create(),
|
|
@@ -250,18 +1291,62 @@ const v = {
|
|
|
250
1291
|
nan: () => VldNan.create(),
|
|
251
1292
|
// NEVER constant - Zod 4 API parity for use in transforms
|
|
252
1293
|
NEVER: VldNever.create(),
|
|
1294
|
+
TimePrecision,
|
|
1295
|
+
ZodIssueCode,
|
|
1296
|
+
ZodFirstPartyTypeKind,
|
|
253
1297
|
// Utility validators
|
|
254
1298
|
optional: (validator) => VldOptional.create(validator),
|
|
255
1299
|
nullable: (validator) => VldNullable.create(validator),
|
|
256
1300
|
nullish: (validator) => VldNullish.create(validator),
|
|
1301
|
+
exactOptional: (validator) => VldExactOptional.create(validator),
|
|
1302
|
+
nonoptional: (validator, message) => validator.refine((value) => value !== undefined, messageFromRefinementParam(message)),
|
|
1303
|
+
catch: (validator, fallbackValue) => validator.catch(fallbackValue),
|
|
1304
|
+
prefault: (validator, defaultValue) => validator.default(typeof defaultValue === 'function' ? defaultValue() : defaultValue).prefault(),
|
|
1305
|
+
readonly: (validator) => validator.readonly(),
|
|
1306
|
+
pipe: (first, second) => first.pipe(second),
|
|
1307
|
+
clone: (schema) => cloneSchema(schema),
|
|
1308
|
+
describe: (schemaOrDescription, description) => schemaOrDescription instanceof VldBase
|
|
1309
|
+
? schemaOrDescription.describe(description || '')
|
|
1310
|
+
: VldUnknown.create().describe(schemaOrDescription),
|
|
1311
|
+
meta: (schemaOrMetadata, metadata) => schemaOrMetadata instanceof VldBase
|
|
1312
|
+
? schemaOrMetadata.meta(metadata || {})
|
|
1313
|
+
: VldUnknown.create().meta(schemaOrMetadata),
|
|
1314
|
+
transform: (schemaOrTransformer, transformer) => schemaOrTransformer instanceof VldBase
|
|
1315
|
+
? schemaOrTransformer.transform(transformer || ((value) => value))
|
|
1316
|
+
: createTransform(schemaOrTransformer),
|
|
1317
|
+
overwrite: (transformer) => createTransform(transformer),
|
|
1318
|
+
refine: (schemaOrPredicate, predicateOrMessage, message) => schemaOrPredicate instanceof VldBase
|
|
1319
|
+
? schemaOrPredicate.refine(predicateOrMessage, messageFromRefinementParam(message))
|
|
1320
|
+
: createRefinement(schemaOrPredicate, predicateOrMessage),
|
|
1321
|
+
check: (schemaOrPredicate, predicateOrMessage, message) => schemaOrPredicate instanceof VldBase
|
|
1322
|
+
? schemaOrPredicate.check(predicateOrMessage, messageFromRefinementParam(message))
|
|
1323
|
+
: createRefinement(schemaOrPredicate, predicateOrMessage),
|
|
1324
|
+
superRefine: (schemaOrRefinement, refinement) => schemaOrRefinement instanceof VldBase
|
|
1325
|
+
? schemaOrRefinement.superRefine(refinement || (() => undefined))
|
|
1326
|
+
: createSuperRefinement(schemaOrRefinement),
|
|
1327
|
+
property: propertyCheck,
|
|
1328
|
+
instanceof: (constructor, message) => custom$1({
|
|
1329
|
+
parse: (value) => {
|
|
1330
|
+
if (!(value instanceof constructor)) {
|
|
1331
|
+
throw new Error(messageFromRefinementParam(message) || `Expected instance of ${constructor.name || 'provided constructor'}`);
|
|
1332
|
+
}
|
|
1333
|
+
return value;
|
|
1334
|
+
}
|
|
1335
|
+
}),
|
|
1336
|
+
config: configure,
|
|
1337
|
+
setErrorMap: setGlobalErrorMap,
|
|
1338
|
+
getErrorMap: getGlobalErrorMap,
|
|
1339
|
+
core,
|
|
1340
|
+
util,
|
|
1341
|
+
locales: localeNamespace,
|
|
257
1342
|
// Recursive schemas
|
|
258
1343
|
lazy: (schemaGetter) => VldLazy.create(schemaGetter),
|
|
259
1344
|
// JSON validator
|
|
260
1345
|
json: (schema) => VldJson.create(schema),
|
|
261
1346
|
// Custom validator for type-safe user-defined schemas
|
|
262
|
-
custom: (options) => custom(options),
|
|
1347
|
+
custom: (options) => custom$1(options),
|
|
263
1348
|
// File validator for file uploads
|
|
264
|
-
file: () => file(),
|
|
1349
|
+
file: () => file$1(),
|
|
265
1350
|
// Function validator for function validation
|
|
266
1351
|
function: () => functionValidator(),
|
|
267
1352
|
// Preprocessing
|
|
@@ -275,42 +1360,175 @@ const v = {
|
|
|
275
1360
|
bigint: () => VldCoerceBigInt.create(),
|
|
276
1361
|
},
|
|
277
1362
|
// String format validators (Zod 4 parity)
|
|
278
|
-
email: (options) => email(options),
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
1363
|
+
email: (options) => email$1(options),
|
|
1364
|
+
url: () => VldString.create().url(),
|
|
1365
|
+
uuid: (options) => uuid$1(options),
|
|
1366
|
+
uuidv4: () => uuidv4$1(),
|
|
1367
|
+
uuidv6: () => uuidv6$1(),
|
|
1368
|
+
uuidv7: () => uuidv7$1(),
|
|
1369
|
+
hostname: () => hostname$1(),
|
|
1370
|
+
emoji: () => emoji$1(),
|
|
1371
|
+
base64: () => base64$1(),
|
|
1372
|
+
base64url: () => base64url$1(),
|
|
1373
|
+
hex: () => hex$1(),
|
|
1374
|
+
jwt: () => jwt$1(),
|
|
1375
|
+
nanoid: () => nanoid$1(),
|
|
1376
|
+
cuid: () => cuid$1(),
|
|
1377
|
+
cuid2: () => cuid2$1(),
|
|
1378
|
+
ulid: () => ulid$1(),
|
|
1379
|
+
ipv4: () => ipv4$1(),
|
|
1380
|
+
ipv6: () => ipv6$1(),
|
|
1381
|
+
mac: () => mac$1(),
|
|
1382
|
+
cidrv4: () => cidrv4$1(),
|
|
1383
|
+
cidrv6: () => cidrv6$1(),
|
|
1384
|
+
e164: () => e164$1(),
|
|
1385
|
+
hash: (algorithm) => hash$1(algorithm),
|
|
298
1386
|
iso: {
|
|
299
|
-
date: () => iso.date(),
|
|
300
|
-
time: () => iso.time(),
|
|
301
|
-
dateTime: () => iso.dateTime(),
|
|
302
|
-
duration: () => iso.duration(),
|
|
1387
|
+
date: () => iso$1.date(),
|
|
1388
|
+
time: () => iso$1.time(),
|
|
1389
|
+
dateTime: () => iso$1.dateTime(),
|
|
1390
|
+
duration: () => iso$1.duration(),
|
|
303
1391
|
},
|
|
304
|
-
stringFormat: (name, validator) => stringFormat(name, validator),
|
|
1392
|
+
stringFormat: (name, validator) => stringFormat$1(name, validator),
|
|
1393
|
+
minLength: (value, message) => VldString.create().min(value, message),
|
|
1394
|
+
maxLength: (value, message) => VldString.create().max(value, message),
|
|
1395
|
+
length: (value, message) => VldString.create().length(value, message),
|
|
1396
|
+
regex: (pattern, message) => VldString.create().regex(pattern, message),
|
|
1397
|
+
startsWith: (value, message) => VldString.create().startsWith(value, message),
|
|
1398
|
+
endsWith: (value, message) => VldString.create().endsWith(value, message),
|
|
1399
|
+
includes: (value, message) => VldString.create().includes(value, message),
|
|
1400
|
+
trim: () => VldString.create().trim(),
|
|
1401
|
+
toLowerCase: () => VldString.create().toLowerCase(),
|
|
1402
|
+
lowercase: () => VldString.create().toLowerCase(),
|
|
1403
|
+
toUpperCase: () => VldString.create().toUpperCase(),
|
|
1404
|
+
uppercase: () => VldString.create().toUpperCase(),
|
|
1405
|
+
gt: (value, message) => VldNumber.create().gt(value, message),
|
|
1406
|
+
gte: (value, message) => VldNumber.create().gte(value, message),
|
|
1407
|
+
lt: (value, message) => VldNumber.create().lt(value, message),
|
|
1408
|
+
lte: (value, message) => VldNumber.create().lte(value, message),
|
|
1409
|
+
positive: (message) => VldNumber.create().positive(message),
|
|
1410
|
+
negative: (message) => VldNumber.create().negative(message),
|
|
1411
|
+
nonnegative: (message) => VldNumber.create().nonnegative(message),
|
|
1412
|
+
nonpositive: (message) => VldNumber.create().nonpositive(message),
|
|
1413
|
+
multipleOf: (value, message) => VldNumber.create().multipleOf(value, message),
|
|
1414
|
+
minSize: (value, message) => VldString.create().min(value, message),
|
|
1415
|
+
maxSize: (value, message) => VldString.create().max(value, message),
|
|
1416
|
+
size: (value, message) => VldString.create().length(value, message),
|
|
1417
|
+
normalize: (form) => VldString.create().transform(value => value.normalize(form)),
|
|
1418
|
+
slugify: () => VldString.create().transform(value => value
|
|
1419
|
+
.normalize('NFKD')
|
|
1420
|
+
.replace(/[\u0300-\u036f]/g, '')
|
|
1421
|
+
.toLowerCase()
|
|
1422
|
+
.trim()
|
|
1423
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
1424
|
+
.replace(/^-+|-+$/g, '')),
|
|
1425
|
+
mime: (types, message) => VldFile.create().mime(types, message),
|
|
1426
|
+
// Zod v4 parity string formats
|
|
1427
|
+
xid: () => xid$1(),
|
|
1428
|
+
guid: () => guid$1(),
|
|
1429
|
+
httpUrl: () => httpUrl$1(),
|
|
1430
|
+
ksuid: () => ksuid$1(),
|
|
1431
|
+
regexes: REGEXES,
|
|
305
1432
|
// Template literal validator
|
|
306
|
-
templateLiteral: (...components) => templateLiteral(...components),
|
|
1433
|
+
templateLiteral: (...components) => templateLiteral$1(...components),
|
|
307
1434
|
// Codec validators (binary data validators)
|
|
308
1435
|
base64Bytes: () => VldBase64.create(),
|
|
309
1436
|
hexBytes: () => VldHex.create(),
|
|
310
1437
|
uint8Array: () => VldUint8Array.create(),
|
|
311
1438
|
// Codec factory
|
|
312
|
-
codec: (inputValidator, outputValidator, transform) => VldCodec.create(inputValidator, outputValidator, transform)
|
|
1439
|
+
codec: (inputValidator, outputValidator, transform) => VldCodec.create(inputValidator, outputValidator, transform),
|
|
1440
|
+
invertCodec: (codec) => codec.invert(),
|
|
1441
|
+
// Promise validator (Zod v4 parity)
|
|
1442
|
+
promise: (inner) => promise$1(inner),
|
|
1443
|
+
// Root parse helpers (Zod v4 parity)
|
|
1444
|
+
parse: (schema, value) => schema.parse(value),
|
|
1445
|
+
safeParse: (schema, value) => schema.safeParse(value),
|
|
1446
|
+
parseAsync: (schema, value) => schema.parseAsync(value),
|
|
1447
|
+
safeParseAsync: (schema, value) => schema.safeParseAsync(value),
|
|
1448
|
+
decode: (schema, value) => schema.parse(value),
|
|
1449
|
+
safeDecode: (schema, value) => schema.safeParse(value),
|
|
1450
|
+
decodeAsync: (schema, value) => schema.parseAsync(value),
|
|
1451
|
+
safeDecodeAsync: (schema, value) => schema.safeParseAsync(value),
|
|
1452
|
+
encode: (schema, value) => isCodec(schema)
|
|
1453
|
+
? schema.encode(value)
|
|
1454
|
+
: schema.parse(value),
|
|
1455
|
+
safeEncode: (schema, value) => isCodec(schema)
|
|
1456
|
+
? schema.safeEncode(value)
|
|
1457
|
+
: schema.safeParse(value),
|
|
1458
|
+
encodeAsync: async (schema, value) => isCodec(schema)
|
|
1459
|
+
? schema.encodeAsync(value)
|
|
1460
|
+
: schema.parseAsync(value),
|
|
1461
|
+
safeEncodeAsync: async (schema, value) => isCodec(schema)
|
|
1462
|
+
? schema.safeEncodeAsync(value)
|
|
1463
|
+
: schema.safeParseAsync(value),
|
|
1464
|
+
formatError: (error) => {
|
|
1465
|
+
const formatted = { _errors: [] };
|
|
1466
|
+
if (error instanceof VldError) {
|
|
1467
|
+
for (const issue of error.issues) {
|
|
1468
|
+
addFormattedIssue(formatted, issue.path, issue.message);
|
|
1469
|
+
}
|
|
1470
|
+
return formatted;
|
|
1471
|
+
}
|
|
1472
|
+
formatted._errors.push(toErrorMessage(error));
|
|
1473
|
+
return formatted;
|
|
1474
|
+
},
|
|
1475
|
+
treeifyError: treeifyError,
|
|
1476
|
+
prettifyError: prettifyError,
|
|
1477
|
+
flattenError: flattenError,
|
|
1478
|
+
toJSONSchema: toJSONSchema
|
|
313
1479
|
};
|
|
1480
|
+
/**
|
|
1481
|
+
* Zod-compatible namespace alias.
|
|
1482
|
+
*/
|
|
1483
|
+
const z = v;
|
|
1484
|
+
/**
|
|
1485
|
+
* Zod-compatible root-level factory aliases.
|
|
1486
|
+
*
|
|
1487
|
+
* VLD's primary API remains `v.*`, but Zod exposes most factories directly
|
|
1488
|
+
* from the package root. Re-exporting these aliases makes migration less
|
|
1489
|
+
* intrusive without changing existing behavior.
|
|
1490
|
+
*/
|
|
1491
|
+
const { string, number, int, int32, uint32, uint64, int64, float32, float64, boolean, date, bigint, symbol, stringbool, array, object, strictObject, looseObject, tuple, record, partialRecord, looseRecord, set, union, intersection, discriminatedUnion, xor, keyof, literal, nativeEnum, any, unknown, nan, optional, nullable, nullish, exactOptional, nonoptional, readonly, pipe, clone, describe, meta, transform, overwrite, refine, check, superRefine, property, config, setErrorMap, getErrorMap, locales, lazy, json, custom, file, preprocess, coerce, email, url, uuid, uuidv4, uuidv6, uuidv7, hostname, emoji, base64, base64url, hex, jwt, nanoid, cuid, cuid2, ulid, ipv4, ipv6, mac, cidrv4, cidrv6, e164, hash, iso, stringFormat, normalize, slugify, mime, xid, guid, httpUrl, ksuid, regexes, templateLiteral, base64Bytes, hexBytes, uint8Array, codec, promise, prefault, parse, safeParse, parseAsync, safeParseAsync, decode, safeDecode, decodeAsync, safeDecodeAsync, encode, safeEncode, encodeAsync, safeEncodeAsync, formatError, NEVER } = v;
|
|
1492
|
+
const catchFactory = v.catch;
|
|
1493
|
+
const enumFactory = v.enum;
|
|
1494
|
+
const functionFactory = v.function;
|
|
1495
|
+
const instanceOfFactory = v.instanceof;
|
|
1496
|
+
const mapFactory = v.map;
|
|
1497
|
+
const neverFactory = v.never;
|
|
1498
|
+
const nullFactory = v.null;
|
|
1499
|
+
const undefinedFactory = v.undefined;
|
|
1500
|
+
const voidFactory = v.void;
|
|
1501
|
+
const defaultFactory = v;
|
|
1502
|
+
const zodStringFactory = VldString;
|
|
1503
|
+
function map(first, second) {
|
|
1504
|
+
if (first instanceof VldBase && second instanceof VldBase) {
|
|
1505
|
+
return v.map(first, second);
|
|
1506
|
+
}
|
|
1507
|
+
return map$1(first, second);
|
|
1508
|
+
}
|
|
1509
|
+
const minLength = (value, message) => v.string().min(value, message);
|
|
1510
|
+
const maxLength = (value, message) => v.string().max(value, message);
|
|
1511
|
+
const length = (value, message) => v.string().length(value, message);
|
|
1512
|
+
const regex = (pattern, message) => v.string().regex(pattern, message);
|
|
1513
|
+
const startsWith = (value, message) => v.string().startsWith(value, message);
|
|
1514
|
+
const endsWith = (value, message) => v.string().endsWith(value, message);
|
|
1515
|
+
const includes = (value, message) => v.string().includes(value, message);
|
|
1516
|
+
const trim = () => v.string().trim();
|
|
1517
|
+
const toLowerCase = () => v.string().toLowerCase();
|
|
1518
|
+
const lowercase = toLowerCase;
|
|
1519
|
+
const toUpperCase = () => v.string().toUpperCase();
|
|
1520
|
+
const uppercase = toUpperCase;
|
|
1521
|
+
const gt = (value, message) => v.number().gt(value, message);
|
|
1522
|
+
const gte = (value, message) => v.number().gte(value, message);
|
|
1523
|
+
const lt = (value, message) => v.number().lt(value, message);
|
|
1524
|
+
const lte = (value, message) => v.number().lte(value, message);
|
|
1525
|
+
const positive = (message) => v.number().positive(message);
|
|
1526
|
+
const negative = (message) => v.number().negative(message);
|
|
1527
|
+
const nonnegative = (message) => v.number().nonnegative(message);
|
|
1528
|
+
const nonpositive = (message) => v.number().nonpositive(message);
|
|
1529
|
+
const multipleOf = (value, message) => v.number().multipleOf(value, message);
|
|
1530
|
+
const minSize = minLength;
|
|
1531
|
+
const maxSize = maxLength;
|
|
1532
|
+
const size = length;
|
|
314
1533
|
|
|
315
|
-
export { VldIntersection, createLogger, createNoOpLogger, v as default, disableLogging, enableDebug, getLogger, initLogger, setLogLevel, v };
|
|
316
|
-
//# sourceMappingURL=index.js.map
|
|
1534
|
+
export { $brand, $input, $output, NEVER, TimePrecision, VldBase, VldError, VldIntersection, VldAny as ZodAny, VldArray as ZodArray, VldBigInt as ZodBigInt, VldBigInt as ZodBigIntFormat, VldBoolean as ZodBoolean, VldCodec as ZodCodec, VldDate as ZodDate, VldDiscriminatedUnion as ZodDiscriminatedUnion, VldEnum as ZodEnum, VldError as ZodError, VldExactOptional as ZodExactOptional, VldFile as ZodFile, ZodFirstPartyTypeKind, VldIntersection as ZodIntersection, ZodIssueCode, VldJson as ZodJSON, VldLazy as ZodLazy, VldLiteral as ZodLiteral, VldMap as ZodMap, VldNan as ZodNaN, VldNever as ZodNever, VldNull as ZodNull, VldNullable as ZodNullable, VldNumber as ZodNumber, VldNumber as ZodNumberFormat, VldObject as ZodObject, VldOptional as ZodOptional, VldPreprocess as ZodPreprocess, VldError as ZodRealError, VldRecord as ZodRecord, VldSet as ZodSet, VldString as ZodString, VldSymbol as ZodSymbol, VldTuple as ZodTuple, VldBase as ZodType, VldUndefined as ZodUndefined, VldUnion as ZodUnion, VldUnknown as ZodUnknown, VldVoid as ZodVoid, VldXor as ZodXor, zodStringFactory as _ZodString, defaultFactory as _default, functionFactory as _function, any, array, base64, base64Bytes, base64url, bigint, boolean, catchFactory as catch, check, cidrv4, cidrv6, clone, codec, coerce, config, core, createLogger, createNoOpLogger, cuid, cuid2, custom, date, decode, decodeAsync, v as default, describe, disableLogging, discriminatedUnion, e164, email, emoji, enableDebug, encode, encodeAsync, endsWith, enumFactory as enum, exactOptional, file, flattenError, float32, float64, formatError, fromJSONSchema, functionFactory as function, getErrorMap, getLogger, globalRegistry, gt, gte, guid, hash, hex, hexBytes, hostname, httpUrl, includes, initLogger, instanceOfFactory as instanceof, int, int32, int64, intersection, ipv4, ipv6, iso, json, jwt, keyof, ksuid, lazy, length, literal, locales, looseObject, looseRecord, lowercase, lt, lte, mac, map, mapFactory as mapSchema, maxLength, maxSize, meta, mime, minLength, minSize, multipleOf, nan, nanoid, nativeEnum, negative, neverFactory as never, nonnegative, nonoptional, nonpositive, normalize, nullFactory as null, nullable, nullish, number, object, optional, overwrite, parse, parseAsync, partialRecord, pipe, positive, prefault, preprocess, prettifyError, promise, property, readonly, record, refine, regex, regexes, safeDecode, safeDecodeAsync, safeEncode, safeEncodeAsync, safeParse, safeParseAsync, set, setErrorMap, setLogLevel, size, slugify, startsWith, strictObject, string, stringFormat, stringbool, superRefine, symbol, templateLiteral, toJSONSchema, toLowerCase, toUpperCase, transform, treeifyError, trim, tuple, uint32, uint64, uint8Array, ulid, undefinedFactory as undefined, union, unknown, uppercase, url, util, uuid, uuidv4, uuidv6, uuidv7, v, voidFactory as void, xid, xor, z };
|