@willaimg/yatsp 4.3.6
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/README.md +22 -0
- package/compile.cjs +96 -0
- package/compile.d.cts +1 -0
- package/compile.d.ts +1 -0
- package/compile.js +52 -0
- package/index.cjs +52 -0
- package/index.d.cts +3 -0
- package/index.d.ts +3 -0
- package/index.js +7 -0
- package/locales/index.cjs +36 -0
- package/locales/index.d.cts +1 -0
- package/locales/index.d.ts +1 -0
- package/locales/index.js +1 -0
- package/mini/index.cjs +51 -0
- package/mini/index.d.cts +3 -0
- package/mini/index.d.ts +3 -0
- package/mini/index.js +3 -0
- package/package.json +142 -0
- package/src/compile.ts +56 -0
- package/src/index.ts +7 -0
- package/src/locales/index.ts +1 -0
- package/src/mini/index.ts +3 -0
- package/src/v3/YatspError.ts +340 -0
- package/src/v3/benchmarks/datetime.ts +58 -0
- package/src/v3/benchmarks/discriminatedUnion.ts +80 -0
- package/src/v3/benchmarks/index.ts +59 -0
- package/src/v3/benchmarks/ipv4.ts +57 -0
- package/src/v3/benchmarks/object.ts +69 -0
- package/src/v3/benchmarks/primitives.ts +162 -0
- package/src/v3/benchmarks/realworld.ts +63 -0
- package/src/v3/benchmarks/string.ts +55 -0
- package/src/v3/benchmarks/union.ts +80 -0
- package/src/v3/errors.ts +13 -0
- package/src/v3/external.ts +6 -0
- package/src/v3/helpers/enumUtil.ts +17 -0
- package/src/v3/helpers/errorUtil.ts +8 -0
- package/src/v3/helpers/parseUtil.ts +176 -0
- package/src/v3/helpers/partialUtil.ts +34 -0
- package/src/v3/helpers/typeAliases.ts +2 -0
- package/src/v3/helpers/util.ts +224 -0
- package/src/v3/index.ts +4 -0
- package/src/v3/locales/en.ts +124 -0
- package/src/v3/standard-schema.ts +113 -0
- package/src/v3/tests/Mocker.ts +54 -0
- package/src/v3/tests/all-errors.test.ts +157 -0
- package/src/v3/tests/anyunknown.test.ts +28 -0
- package/src/v3/tests/array.test.ts +71 -0
- package/src/v3/tests/async-parsing.test.ts +388 -0
- package/src/v3/tests/async-refinements.test.ts +46 -0
- package/src/v3/tests/base.test.ts +29 -0
- package/src/v3/tests/bigint.test.ts +55 -0
- package/src/v3/tests/branded.test.ts +53 -0
- package/src/v3/tests/catch.test.ts +220 -0
- package/src/v3/tests/coerce.test.ts +133 -0
- package/src/v3/tests/complex.test.ts +70 -0
- package/src/v3/tests/custom.test.ts +31 -0
- package/src/v3/tests/date.test.ts +32 -0
- package/src/v3/tests/deepmasking.test.ts +186 -0
- package/src/v3/tests/default.test.ts +112 -0
- package/src/v3/tests/description.test.ts +33 -0
- package/src/v3/tests/discriminated-unions.test.ts +315 -0
- package/src/v3/tests/enum.test.ts +80 -0
- package/src/v3/tests/error.test.ts +586 -0
- package/src/v3/tests/firstparty.test.ts +87 -0
- package/src/v3/tests/firstpartyschematypes.test.ts +21 -0
- package/src/v3/tests/function.test.ts +261 -0
- package/src/v3/tests/generics.test.ts +48 -0
- package/src/v3/tests/instanceof.test.ts +37 -0
- package/src/v3/tests/intersection.test.ts +128 -0
- package/src/v3/tests/language-server.source.ts +76 -0
- package/src/v3/tests/language-server.test.ts +206 -0
- package/src/v3/tests/literal.test.ts +36 -0
- package/src/v3/tests/map.test.ts +110 -0
- package/src/v3/tests/masking.test.ts +4 -0
- package/src/v3/tests/mocker.test.ts +19 -0
- package/src/v3/tests/nan.test.ts +24 -0
- package/src/v3/tests/nativeEnum.test.ts +87 -0
- package/src/v3/tests/nullable.test.ts +42 -0
- package/src/v3/tests/number.test.ts +176 -0
- package/src/v3/tests/object-augmentation.test.ts +29 -0
- package/src/v3/tests/object-in-es5-env.test.ts +29 -0
- package/src/v3/tests/object.test.ts +431 -0
- package/src/v3/tests/optional.test.ts +42 -0
- package/src/v3/tests/parseUtil.test.ts +23 -0
- package/src/v3/tests/parser.test.ts +41 -0
- package/src/v3/tests/partials.test.ts +243 -0
- package/src/v3/tests/pickomit.test.ts +111 -0
- package/src/v3/tests/pipeline.test.ts +29 -0
- package/src/v3/tests/preprocess.test.ts +186 -0
- package/src/v3/tests/primitive.test.ts +440 -0
- package/src/v3/tests/promise.test.ts +90 -0
- package/src/v3/tests/readonly.test.ts +114 -0
- package/src/v3/tests/record.test.ts +171 -0
- package/src/v3/tests/recursive.test.ts +197 -0
- package/src/v3/tests/refine.test.ts +313 -0
- package/src/v3/tests/safeparse.test.ts +27 -0
- package/src/v3/tests/set.test.ts +142 -0
- package/src/v3/tests/standard-schema.test.ts +83 -0
- package/src/v3/tests/string.test.ts +922 -0
- package/src/v3/tests/transformer.test.ts +233 -0
- package/src/v3/tests/tuple.test.ts +90 -0
- package/src/v3/tests/unions.test.ts +57 -0
- package/src/v3/tests/validations.test.ts +133 -0
- package/src/v3/tests/void.test.ts +15 -0
- package/src/v3/types.ts +5162 -0
- package/src/v4/classic/checks.ts +33 -0
- package/src/v4/classic/coerce.ts +27 -0
- package/src/v4/classic/compat.ts +78 -0
- package/src/v4/classic/deep-partial.ts +76 -0
- package/src/v4/classic/errors.ts +97 -0
- package/src/v4/classic/external.ts +57 -0
- package/src/v4/classic/from-json-schema.ts +944 -0
- package/src/v4/classic/in-out.ts +45 -0
- package/src/v4/classic/index.ts +5 -0
- package/src/v4/classic/iso.ts +20 -0
- package/src/v4/classic/parse.ts +88 -0
- package/src/v4/classic/schemas.ts +2994 -0
- package/src/v4/classic/tests/anyunknown.test.ts +26 -0
- package/src/v4/classic/tests/apply.test.ts +86 -0
- package/src/v4/classic/tests/array.test.ts +264 -0
- package/src/v4/classic/tests/assignability.test.ts +402 -0
- package/src/v4/classic/tests/async-parsing.test.ts +381 -0
- package/src/v4/classic/tests/async-refinements.test.ts +68 -0
- package/src/v4/classic/tests/base.test.ts +7 -0
- package/src/v4/classic/tests/bigint.test.ts +89 -0
- package/src/v4/classic/tests/brand.test.ts +106 -0
- package/src/v4/classic/tests/catch.test.ts +604 -0
- package/src/v4/classic/tests/coalesce.test.ts +20 -0
- package/src/v4/classic/tests/codec-examples.test.ts +572 -0
- package/src/v4/classic/tests/codec.test.ts +704 -0
- package/src/v4/classic/tests/coerce.test.ts +160 -0
- package/src/v4/classic/tests/continuability.test.ts +374 -0
- package/src/v4/classic/tests/credit-card.test.ts +76 -0
- package/src/v4/classic/tests/custom.test.ts +40 -0
- package/src/v4/classic/tests/cyclic-data.test.ts +985 -0
- package/src/v4/classic/tests/date.test.ts +92 -0
- package/src/v4/classic/tests/datetime.test.ts +316 -0
- package/src/v4/classic/tests/deep-partial.test.ts +380 -0
- package/src/v4/classic/tests/default-locale.test.ts +32 -0
- package/src/v4/classic/tests/default.test.ts +455 -0
- package/src/v4/classic/tests/describe-meta-checks.test.ts +27 -0
- package/src/v4/classic/tests/description.test.ts +32 -0
- package/src/v4/classic/tests/detached-methods.test.ts +226 -0
- package/src/v4/classic/tests/discriminated-unions.test.ts +942 -0
- package/src/v4/classic/tests/enum.test.ts +305 -0
- package/src/v4/classic/tests/error-utils.test.ts +917 -0
- package/src/v4/classic/tests/error.test.ts +1108 -0
- package/src/v4/classic/tests/file.test.ts +96 -0
- package/src/v4/classic/tests/firstparty.test.ts +179 -0
- package/src/v4/classic/tests/fix-json-issue.test.ts +26 -0
- package/src/v4/classic/tests/from-json-schema.test.ts +1467 -0
- package/src/v4/classic/tests/function.test.ts +391 -0
- package/src/v4/classic/tests/generics.test.ts +72 -0
- package/src/v4/classic/tests/global-config.test.ts +32 -0
- package/src/v4/classic/tests/hash.test.ts +67 -0
- package/src/v4/classic/tests/iban.test.ts +81 -0
- package/src/v4/classic/tests/in-out.test.ts +159 -0
- package/src/v4/classic/tests/index.test.ts +958 -0
- package/src/v4/classic/tests/instance-footprint.test.ts +319 -0
- package/src/v4/classic/tests/instanceof.test.ts +127 -0
- package/src/v4/classic/tests/intersection.test.ts +334 -0
- package/src/v4/classic/tests/issue-schema.test.ts +215 -0
- package/src/v4/classic/tests/jitless-allows-eval.test.ts +39 -0
- package/src/v4/classic/tests/json.test.ts +109 -0
- package/src/v4/classic/tests/lazy.test.ts +262 -0
- package/src/v4/classic/tests/literal.test.ts +128 -0
- package/src/v4/classic/tests/locales_ka.test.ts +29 -0
- package/src/v4/classic/tests/locales_ro.test.ts +24 -0
- package/src/v4/classic/tests/map.test.ts +342 -0
- package/src/v4/classic/tests/nan.test.ts +21 -0
- package/src/v4/classic/tests/nested-refine.test.ts +168 -0
- package/src/v4/classic/tests/nonoptional.test.ts +101 -0
- package/src/v4/classic/tests/nullable.test.ts +22 -0
- package/src/v4/classic/tests/number.test.ts +401 -0
- package/src/v4/classic/tests/object.test.ts +1006 -0
- package/src/v4/classic/tests/optin-ladder.test.ts +235 -0
- package/src/v4/classic/tests/optional.test.ts +366 -0
- package/src/v4/classic/tests/partial.test.ts +497 -0
- package/src/v4/classic/tests/pickomit.test.ts +211 -0
- package/src/v4/classic/tests/pipe.test.ts +101 -0
- package/src/v4/classic/tests/prefault.test.ts +144 -0
- package/src/v4/classic/tests/preprocess-types.test.ts +44 -0
- package/src/v4/classic/tests/preprocess.test.ts +351 -0
- package/src/v4/classic/tests/primitive.test.ts +175 -0
- package/src/v4/classic/tests/promise.test.ts +81 -0
- package/src/v4/classic/tests/properties.test.ts +141 -0
- package/src/v4/classic/tests/prototypes.test.ts +23 -0
- package/src/v4/classic/tests/readonly.test.ts +184 -0
- package/src/v4/classic/tests/record.test.ts +885 -0
- package/src/v4/classic/tests/recursive-types.test.ts +707 -0
- package/src/v4/classic/tests/redos.test.ts +68 -0
- package/src/v4/classic/tests/refine.test.ts +693 -0
- package/src/v4/classic/tests/registries.test.ts +243 -0
- package/src/v4/classic/tests/set.test.ts +190 -0
- package/src/v4/classic/tests/standard-schema.test.ts +153 -0
- package/src/v4/classic/tests/string-formats.test.ts +125 -0
- package/src/v4/classic/tests/string.test.ts +1440 -0
- package/src/v4/classic/tests/stringbool.test.ts +124 -0
- package/src/v4/classic/tests/template-literal.test.ts +814 -0
- package/src/v4/classic/tests/to-json-schema-methods.test.ts +438 -0
- package/src/v4/classic/tests/to-json-schema.test.ts +4733 -0
- package/src/v4/classic/tests/transform.test.ts +378 -0
- package/src/v4/classic/tests/tuple.test.ts +511 -0
- package/src/v4/classic/tests/union.test.ts +310 -0
- package/src/v4/classic/tests/url.test.ts +13 -0
- package/src/v4/classic/tests/validate.test.ts +645 -0
- package/src/v4/classic/tests/validations.test.ts +283 -0
- package/src/v4/classic/tests/void.test.ts +12 -0
- package/src/v4/core/api.ts +1913 -0
- package/src/v4/core/checks.ts +1274 -0
- package/src/v4/core/compile.ts +2315 -0
- package/src/v4/core/core.ts +230 -0
- package/src/v4/core/doc.ts +52 -0
- package/src/v4/core/errors.ts +546 -0
- package/src/v4/core/index.ts +19 -0
- package/src/v4/core/json-schema-generator.ts +131 -0
- package/src/v4/core/json-schema-processors.ts +934 -0
- package/src/v4/core/json-schema.ts +148 -0
- package/src/v4/core/memoizer.ts +331 -0
- package/src/v4/core/parse.ts +309 -0
- package/src/v4/core/regexes.ts +217 -0
- package/src/v4/core/registries.ts +109 -0
- package/src/v4/core/schemas.ts +5295 -0
- package/src/v4/core/standard-schema.ts +159 -0
- package/src/v4/core/tests/cached.test.ts +54 -0
- package/src/v4/core/tests/compile-differential.test.ts +1004 -0
- package/src/v4/core/tests/compile-generative.test.ts +445 -0
- package/src/v4/core/tests/compile-global.test.ts +89 -0
- package/src/v4/core/tests/compile-off-by-default.test.ts +26 -0
- package/src/v4/core/tests/compile-stats.test.ts +34 -0
- package/src/v4/core/tests/compile.test.ts +2040 -0
- package/src/v4/core/tests/email-regex.test.ts +140 -0
- package/src/v4/core/tests/extend.test.ts +59 -0
- package/src/v4/core/tests/index.test.ts +46 -0
- package/src/v4/core/tests/locales/be.test.ts +124 -0
- package/src/v4/core/tests/locales/el.test.ts +214 -0
- package/src/v4/core/tests/locales/en.test.ts +22 -0
- package/src/v4/core/tests/locales/es.test.ts +180 -0
- package/src/v4/core/tests/locales/fr.test.ts +72 -0
- package/src/v4/core/tests/locales/he.test.ts +379 -0
- package/src/v4/core/tests/locales/hr.test.ts +163 -0
- package/src/v4/core/tests/locales/nl.test.ts +46 -0
- package/src/v4/core/tests/locales/parity.test.ts +42 -0
- package/src/v4/core/tests/locales/ru.test.ts +128 -0
- package/src/v4/core/tests/locales/tg.test.ts +85 -0
- package/src/v4/core/tests/locales/tk.test.ts +69 -0
- package/src/v4/core/tests/locales/tr.test.ts +69 -0
- package/src/v4/core/tests/locales/uz.test.ts +105 -0
- package/src/v4/core/tests/polyfill-collision.test.ts +46 -0
- package/src/v4/core/tests/record-constructor.test.ts +125 -0
- package/src/v4/core/tests/recursive-tuples.test.ts +45 -0
- package/src/v4/core/tests/treeshake.test.ts +51 -0
- package/src/v4/core/tests/url-no-canparse.test.ts +133 -0
- package/src/v4/core/to-json-schema.ts +857 -0
- package/src/v4/core/util.ts +1284 -0
- package/src/v4/core/versions.ts +5 -0
- package/src/v4/core/visit.ts +193 -0
- package/src/v4/core/zsf.ts +323 -0
- package/src/v4/index.ts +4 -0
- package/src/v4/locales/ar.ts +120 -0
- package/src/v4/locales/az.ts +116 -0
- package/src/v4/locales/be.ts +188 -0
- package/src/v4/locales/bg.ts +133 -0
- package/src/v4/locales/bn.ts +123 -0
- package/src/v4/locales/ca.ts +121 -0
- package/src/v4/locales/ckb.ts +140 -0
- package/src/v4/locales/cs.ts +123 -0
- package/src/v4/locales/da.ts +128 -0
- package/src/v4/locales/de.ts +121 -0
- package/src/v4/locales/el.ts +124 -0
- package/src/v4/locales/en.ts +136 -0
- package/src/v4/locales/eo.ts +123 -0
- package/src/v4/locales/es.ts +145 -0
- package/src/v4/locales/fa.ts +131 -0
- package/src/v4/locales/fi.ts +126 -0
- package/src/v4/locales/fr-CA.ts +121 -0
- package/src/v4/locales/fr.ts +139 -0
- package/src/v4/locales/gu.ts +123 -0
- package/src/v4/locales/he.ts +253 -0
- package/src/v4/locales/hi.ts +126 -0
- package/src/v4/locales/hr.ts +135 -0
- package/src/v4/locales/hu.ts +122 -0
- package/src/v4/locales/hy.ts +175 -0
- package/src/v4/locales/id.ts +120 -0
- package/src/v4/locales/index.ts +63 -0
- package/src/v4/locales/is.ts +124 -0
- package/src/v4/locales/it.ts +121 -0
- package/src/v4/locales/ja.ts +119 -0
- package/src/v4/locales/ka.ts +128 -0
- package/src/v4/locales/kh.ts +7 -0
- package/src/v4/locales/km.ts +124 -0
- package/src/v4/locales/kn.ts +126 -0
- package/src/v4/locales/ko.ts +126 -0
- package/src/v4/locales/lt.ts +243 -0
- package/src/v4/locales/mk.ts +123 -0
- package/src/v4/locales/ms.ts +120 -0
- package/src/v4/locales/ne.ts +128 -0
- package/src/v4/locales/nl.ts +126 -0
- package/src/v4/locales/nn.ts +121 -0
- package/src/v4/locales/no.ts +121 -0
- package/src/v4/locales/ota.ts +122 -0
- package/src/v4/locales/pl.ts +123 -0
- package/src/v4/locales/ps.ts +131 -0
- package/src/v4/locales/pt-BR.ts +161 -0
- package/src/v4/locales/pt.ts +159 -0
- package/src/v4/locales/ro.ts +132 -0
- package/src/v4/locales/ru.ts +188 -0
- package/src/v4/locales/sk.ts +123 -0
- package/src/v4/locales/sl.ts +123 -0
- package/src/v4/locales/sv.ts +124 -0
- package/src/v4/locales/ta.ts +123 -0
- package/src/v4/locales/tg.ts +135 -0
- package/src/v4/locales/th.ts +124 -0
- package/src/v4/locales/tk.ts +113 -0
- package/src/v4/locales/tr.ts +116 -0
- package/src/v4/locales/ua.ts +7 -0
- package/src/v4/locales/uk.ts +122 -0
- package/src/v4/locales/ur.ts +124 -0
- package/src/v4/locales/uz.ts +120 -0
- package/src/v4/locales/vi.ts +122 -0
- package/src/v4/locales/yo.ts +129 -0
- package/src/v4/locales/zh-CN.ts +121 -0
- package/src/v4/locales/zh-TW.ts +120 -0
- package/src/v4/mini/checks.ts +33 -0
- package/src/v4/mini/coerce.ts +27 -0
- package/src/v4/mini/deep-partial.ts +73 -0
- package/src/v4/mini/external.ts +52 -0
- package/src/v4/mini/in-out.ts +45 -0
- package/src/v4/mini/index.ts +3 -0
- package/src/v4/mini/iso.ts +66 -0
- package/src/v4/mini/parse.ts +16 -0
- package/src/v4/mini/schemas.ts +2093 -0
- package/src/v4/mini/tests/apply.test.ts +57 -0
- package/src/v4/mini/tests/assignability.test.ts +190 -0
- package/src/v4/mini/tests/brand.test.ts +94 -0
- package/src/v4/mini/tests/checks.test.ts +158 -0
- package/src/v4/mini/tests/codec.test.ts +582 -0
- package/src/v4/mini/tests/computed.test.ts +30 -0
- package/src/v4/mini/tests/cyclic-data.test.ts +84 -0
- package/src/v4/mini/tests/deep-partial.test.ts +54 -0
- package/src/v4/mini/tests/error.test.ts +41 -0
- package/src/v4/mini/tests/functions.test.ts +14 -0
- package/src/v4/mini/tests/index.test.ts +1148 -0
- package/src/v4/mini/tests/number.test.ts +109 -0
- package/src/v4/mini/tests/object.test.ts +292 -0
- package/src/v4/mini/tests/prototypes.test.ts +43 -0
- package/src/v4/mini/tests/recursive-types.test.ts +341 -0
- package/src/v4/mini/tests/standard-schema.test.ts +50 -0
- package/src/v4/mini/tests/string.test.ts +396 -0
- package/src/v4-mini/index.ts +3 -0
- package/v3/YatspError.cjs +167 -0
- package/v3/YatspError.d.cts +164 -0
- package/v3/YatspError.d.ts +164 -0
- package/v3/YatspError.js +143 -0
- package/v3/errors.cjs +36 -0
- package/v3/errors.d.cts +5 -0
- package/v3/errors.d.ts +5 -0
- package/v3/errors.js +9 -0
- package/v3/external.cjs +41 -0
- package/v3/external.d.cts +6 -0
- package/v3/external.d.ts +6 -0
- package/v3/external.js +6 -0
- package/v3/helpers/enumUtil.cjs +21 -0
- package/v3/helpers/enumUtil.d.cts +8 -0
- package/v3/helpers/enumUtil.d.ts +8 -0
- package/v3/helpers/enumUtil.js +1 -0
- package/v3/helpers/errorUtil.cjs +28 -0
- package/v3/helpers/errorUtil.d.cts +9 -0
- package/v3/helpers/errorUtil.d.ts +9 -0
- package/v3/helpers/errorUtil.js +6 -0
- package/v3/helpers/parseUtil.cjs +143 -0
- package/v3/helpers/parseUtil.d.cts +78 -0
- package/v3/helpers/parseUtil.d.ts +78 -0
- package/v3/helpers/parseUtil.js +109 -0
- package/v3/helpers/partialUtil.cjs +21 -0
- package/v3/helpers/partialUtil.d.cts +8 -0
- package/v3/helpers/partialUtil.d.ts +8 -0
- package/v3/helpers/partialUtil.js +1 -0
- package/v3/helpers/typeAliases.cjs +21 -0
- package/v3/helpers/typeAliases.d.cts +2 -0
- package/v3/helpers/typeAliases.d.ts +2 -0
- package/v3/helpers/typeAliases.js +1 -0
- package/v3/helpers/util.cjs +156 -0
- package/v3/helpers/util.d.cts +85 -0
- package/v3/helpers/util.d.ts +85 -0
- package/v3/helpers/util.js +133 -0
- package/v3/index.cjs +52 -0
- package/v3/index.d.cts +4 -0
- package/v3/index.d.ts +4 -0
- package/v3/index.js +4 -0
- package/v3/locales/en.cjs +112 -0
- package/v3/locales/en.d.cts +3 -0
- package/v3/locales/en.d.ts +3 -0
- package/v3/locales/en.js +109 -0
- package/v3/standard-schema.cjs +21 -0
- package/v3/standard-schema.d.cts +102 -0
- package/v3/standard-schema.d.ts +102 -0
- package/v3/standard-schema.js +1 -0
- package/v3/types.cjs +3798 -0
- package/v3/types.d.cts +1034 -0
- package/v3/types.d.ts +1034 -0
- package/v3/types.js +3697 -0
- package/v4/classic/checks.cjs +53 -0
- package/v4/classic/checks.d.cts +1 -0
- package/v4/classic/checks.d.ts +1 -0
- package/v4/classic/checks.js +1 -0
- package/v4/classic/coerce.cjs +66 -0
- package/v4/classic/coerce.d.cts +17 -0
- package/v4/classic/coerce.d.ts +17 -0
- package/v4/classic/coerce.js +17 -0
- package/v4/classic/compat.cjs +80 -0
- package/v4/classic/compat.d.cts +48 -0
- package/v4/classic/compat.d.ts +48 -0
- package/v4/classic/compat.js +31 -0
- package/v4/classic/deep-partial.cjs +58 -0
- package/v4/classic/deep-partial.d.cts +14 -0
- package/v4/classic/deep-partial.d.ts +14 -0
- package/v4/classic/deep-partial.js +13 -0
- package/v4/classic/errors.cjs +102 -0
- package/v4/classic/errors.d.cts +29 -0
- package/v4/classic/errors.d.ts +29 -0
- package/v4/classic/errors.js +57 -0
- package/v4/classic/external.cjs +97 -0
- package/v4/classic/external.d.cts +19 -0
- package/v4/classic/external.d.ts +19 -0
- package/v4/classic/external.js +17 -0
- package/v4/classic/from-json-schema.cjs +926 -0
- package/v4/classic/from-json-schema.d.cts +12 -0
- package/v4/classic/from-json-schema.d.ts +12 -0
- package/v4/classic/from-json-schema.js +881 -0
- package/v4/classic/in-out.cjs +82 -0
- package/v4/classic/in-out.d.cts +8 -0
- package/v4/classic/in-out.d.ts +8 -0
- package/v4/classic/in-out.js +36 -0
- package/v4/classic/index.cjs +52 -0
- package/v4/classic/index.d.cts +3 -0
- package/v4/classic/index.d.ts +3 -0
- package/v4/classic/index.js +4 -0
- package/v4/classic/iso.cjs +68 -0
- package/v4/classic/iso.d.cts +7 -0
- package/v4/classic/iso.d.ts +7 -0
- package/v4/classic/iso.js +15 -0
- package/v4/classic/parse.cjs +63 -0
- package/v4/classic/parse.d.cts +44 -0
- package/v4/classic/parse.d.ts +44 -0
- package/v4/classic/parse.js +16 -0
- package/v4/classic/schemas.cjs +1676 -0
- package/v4/classic/schemas.d.cts +816 -0
- package/v4/classic/schemas.d.ts +816 -0
- package/v4/classic/schemas.js +1535 -0
- package/v4/core/api.cjs +1269 -0
- package/v4/core/api.d.cts +335 -0
- package/v4/core/api.d.ts +335 -0
- package/v4/core/api.js +1107 -0
- package/v4/core/checks.cjs +561 -0
- package/v4/core/checks.d.cts +294 -0
- package/v4/core/checks.d.ts +294 -0
- package/v4/core/checks.js +516 -0
- package/v4/core/compile.cjs +1908 -0
- package/v4/core/compile.d.cts +65 -0
- package/v4/core/compile.d.ts +65 -0
- package/v4/core/compile.js +1858 -0
- package/v4/core/core.cjs +167 -0
- package/v4/core/core.d.cts +82 -0
- package/v4/core/core.d.ts +82 -0
- package/v4/core/core.js +141 -0
- package/v4/core/doc.cjs +61 -0
- package/v4/core/doc.d.cts +16 -0
- package/v4/core/doc.d.ts +16 -0
- package/v4/core/doc.js +38 -0
- package/v4/core/errors.cjs +317 -0
- package/v4/core/errors.d.cts +225 -0
- package/v4/core/errors.d.ts +225 -0
- package/v4/core/errors.js +267 -0
- package/v4/core/index.cjs +70 -0
- package/v4/core/index.d.cts +19 -0
- package/v4/core/index.d.ts +19 -0
- package/v4/core/index.js +19 -0
- package/v4/core/json-schema-generator.cjs +122 -0
- package/v4/core/json-schema-generator.d.cts +65 -0
- package/v4/core/json-schema-generator.d.ts +65 -0
- package/v4/core/json-schema-generator.js +99 -0
- package/v4/core/json-schema-processors.cjs +929 -0
- package/v4/core/json-schema-processors.d.cts +65 -0
- package/v4/core/json-schema-processors.d.ts +65 -0
- package/v4/core/json-schema-processors.js +843 -0
- package/v4/core/json-schema.cjs +21 -0
- package/v4/core/json-schema.d.cts +89 -0
- package/v4/core/json-schema.d.ts +89 -0
- package/v4/core/json-schema.js +1 -0
- package/v4/core/memoizer.cjs +360 -0
- package/v4/core/memoizer.d.cts +15 -0
- package/v4/core/memoizer.d.ts +15 -0
- package/v4/core/memoizer.js +311 -0
- package/v4/core/parse.cjs +233 -0
- package/v4/core/parse.d.cts +52 -0
- package/v4/core/parse.d.ts +52 -0
- package/v4/core/parse.js +175 -0
- package/v4/core/regexes.cjs +209 -0
- package/v4/core/regexes.d.cts +90 -0
- package/v4/core/regexes.d.ts +90 -0
- package/v4/core/regexes.js +156 -0
- package/v4/core/registries.cjs +76 -0
- package/v4/core/registries.d.cts +35 -0
- package/v4/core/registries.d.ts +35 -0
- package/v4/core/registries.js +52 -0
- package/v4/core/schemas.cjs +2669 -0
- package/v4/core/schemas.d.cts +1273 -0
- package/v4/core/schemas.d.ts +1273 -0
- package/v4/core/schemas.js +2606 -0
- package/v4/core/standard-schema.cjs +21 -0
- package/v4/core/standard-schema.d.cts +126 -0
- package/v4/core/standard-schema.d.ts +126 -0
- package/v4/core/standard-schema.js +1 -0
- package/v4/core/to-json-schema.cjs +681 -0
- package/v4/core/to-json-schema.d.cts +154 -0
- package/v4/core/to-json-schema.d.ts +154 -0
- package/v4/core/to-json-schema.js +651 -0
- package/v4/core/util.cjs +949 -0
- package/v4/core/util.d.cts +278 -0
- package/v4/core/util.d.ts +278 -0
- package/v4/core/util.js +859 -0
- package/v4/core/versions.cjs +27 -0
- package/v4/core/versions.d.cts +5 -0
- package/v4/core/versions.d.ts +5 -0
- package/v4/core/versions.js +5 -0
- package/v4/core/visit.cjs +214 -0
- package/v4/core/visit.d.cts +30 -0
- package/v4/core/visit.d.ts +30 -0
- package/v4/core/visit.js +169 -0
- package/v4/index.cjs +51 -0
- package/v4/index.d.cts +3 -0
- package/v4/index.d.ts +3 -0
- package/v4/index.js +4 -0
- package/v4/locales/ar.cjs +138 -0
- package/v4/locales/ar.d.cts +5 -0
- package/v4/locales/ar.d.ts +4 -0
- package/v4/locales/ar.js +111 -0
- package/v4/locales/az.cjs +137 -0
- package/v4/locales/az.d.cts +5 -0
- package/v4/locales/az.d.ts +4 -0
- package/v4/locales/az.js +110 -0
- package/v4/locales/be.cjs +195 -0
- package/v4/locales/be.d.cts +5 -0
- package/v4/locales/be.d.ts +4 -0
- package/v4/locales/be.js +168 -0
- package/v4/locales/bg.cjs +152 -0
- package/v4/locales/bg.d.cts +5 -0
- package/v4/locales/bg.d.ts +4 -0
- package/v4/locales/bg.js +125 -0
- package/v4/locales/bn.cjs +140 -0
- package/v4/locales/bn.d.cts +5 -0
- package/v4/locales/bn.d.ts +4 -0
- package/v4/locales/bn.js +113 -0
- package/v4/locales/ca.cjs +139 -0
- package/v4/locales/ca.d.cts +5 -0
- package/v4/locales/ca.d.ts +4 -0
- package/v4/locales/ca.js +112 -0
- package/v4/locales/ckb.cjs +160 -0
- package/v4/locales/ckb.d.cts +5 -0
- package/v4/locales/ckb.d.ts +4 -0
- package/v4/locales/ckb.js +133 -0
- package/v4/locales/cs.cjs +143 -0
- package/v4/locales/cs.d.cts +5 -0
- package/v4/locales/cs.d.ts +4 -0
- package/v4/locales/cs.js +116 -0
- package/v4/locales/da.cjs +147 -0
- package/v4/locales/da.d.cts +5 -0
- package/v4/locales/da.d.ts +4 -0
- package/v4/locales/da.js +120 -0
- package/v4/locales/de.cjs +140 -0
- package/v4/locales/de.d.cts +5 -0
- package/v4/locales/de.d.ts +4 -0
- package/v4/locales/de.js +113 -0
- package/v4/locales/el.cjs +139 -0
- package/v4/locales/el.d.cts +5 -0
- package/v4/locales/el.d.ts +4 -0
- package/v4/locales/el.js +112 -0
- package/v4/locales/en.cjs +152 -0
- package/v4/locales/en.d.cts +5 -0
- package/v4/locales/en.d.ts +4 -0
- package/v4/locales/en.js +125 -0
- package/v4/locales/eo.cjs +141 -0
- package/v4/locales/eo.d.cts +5 -0
- package/v4/locales/eo.d.ts +4 -0
- package/v4/locales/eo.js +114 -0
- package/v4/locales/es.cjs +163 -0
- package/v4/locales/es.d.cts +5 -0
- package/v4/locales/es.d.ts +4 -0
- package/v4/locales/es.js +136 -0
- package/v4/locales/fa.cjs +146 -0
- package/v4/locales/fa.d.cts +5 -0
- package/v4/locales/fa.d.ts +4 -0
- package/v4/locales/fa.js +119 -0
- package/v4/locales/fi.cjs +144 -0
- package/v4/locales/fi.d.cts +5 -0
- package/v4/locales/fi.d.ts +4 -0
- package/v4/locales/fi.js +117 -0
- package/v4/locales/fr-CA.cjs +139 -0
- package/v4/locales/fr-CA.d.cts +5 -0
- package/v4/locales/fr-CA.d.ts +4 -0
- package/v4/locales/fr-CA.js +112 -0
- package/v4/locales/fr.cjs +156 -0
- package/v4/locales/fr.d.cts +5 -0
- package/v4/locales/fr.d.ts +4 -0
- package/v4/locales/fr.js +129 -0
- package/v4/locales/gu.cjs +140 -0
- package/v4/locales/gu.d.cts +5 -0
- package/v4/locales/gu.d.ts +4 -0
- package/v4/locales/gu.js +113 -0
- package/v4/locales/he.cjs +248 -0
- package/v4/locales/he.d.cts +5 -0
- package/v4/locales/he.d.ts +4 -0
- package/v4/locales/he.js +221 -0
- package/v4/locales/hi.cjs +138 -0
- package/v4/locales/hi.d.cts +5 -0
- package/v4/locales/hi.d.ts +4 -0
- package/v4/locales/hi.js +111 -0
- package/v4/locales/hr.cjs +153 -0
- package/v4/locales/hr.d.cts +5 -0
- package/v4/locales/hr.d.ts +4 -0
- package/v4/locales/hr.js +126 -0
- package/v4/locales/hu.cjs +140 -0
- package/v4/locales/hu.d.cts +5 -0
- package/v4/locales/hu.d.ts +4 -0
- package/v4/locales/hu.js +113 -0
- package/v4/locales/hy.cjs +185 -0
- package/v4/locales/hy.d.cts +5 -0
- package/v4/locales/hy.d.ts +4 -0
- package/v4/locales/hy.js +158 -0
- package/v4/locales/id.cjs +138 -0
- package/v4/locales/id.d.cts +5 -0
- package/v4/locales/id.d.ts +4 -0
- package/v4/locales/id.js +111 -0
- package/v4/locales/index.cjs +152 -0
- package/v4/locales/index.d.cts +63 -0
- package/v4/locales/index.d.ts +63 -0
- package/v4/locales/index.js +63 -0
- package/v4/locales/is.cjs +141 -0
- package/v4/locales/is.d.cts +5 -0
- package/v4/locales/is.d.ts +4 -0
- package/v4/locales/is.js +114 -0
- package/v4/locales/it.cjs +140 -0
- package/v4/locales/it.d.cts +5 -0
- package/v4/locales/it.d.ts +4 -0
- package/v4/locales/it.js +113 -0
- package/v4/locales/ja.cjs +139 -0
- package/v4/locales/ja.d.cts +5 -0
- package/v4/locales/ja.d.ts +4 -0
- package/v4/locales/ja.js +112 -0
- package/v4/locales/ka.cjs +144 -0
- package/v4/locales/ka.d.cts +5 -0
- package/v4/locales/ka.d.ts +4 -0
- package/v4/locales/ka.js +117 -0
- package/v4/locales/kh.cjs +12 -0
- package/v4/locales/kh.d.cts +5 -0
- package/v4/locales/kh.d.ts +5 -0
- package/v4/locales/kh.js +5 -0
- package/v4/locales/km.cjs +142 -0
- package/v4/locales/km.d.cts +5 -0
- package/v4/locales/km.d.ts +4 -0
- package/v4/locales/km.js +115 -0
- package/v4/locales/kn.cjs +143 -0
- package/v4/locales/kn.d.cts +5 -0
- package/v4/locales/kn.d.ts +4 -0
- package/v4/locales/kn.js +116 -0
- package/v4/locales/ko.cjs +143 -0
- package/v4/locales/ko.d.cts +5 -0
- package/v4/locales/ko.d.ts +4 -0
- package/v4/locales/ko.js +116 -0
- package/v4/locales/lt.cjs +234 -0
- package/v4/locales/lt.d.cts +5 -0
- package/v4/locales/lt.d.ts +4 -0
- package/v4/locales/lt.js +207 -0
- package/v4/locales/mk.cjs +141 -0
- package/v4/locales/mk.d.cts +5 -0
- package/v4/locales/mk.d.ts +4 -0
- package/v4/locales/mk.js +114 -0
- package/v4/locales/ms.cjs +139 -0
- package/v4/locales/ms.d.cts +5 -0
- package/v4/locales/ms.d.ts +4 -0
- package/v4/locales/ms.js +112 -0
- package/v4/locales/ne.cjs +138 -0
- package/v4/locales/ne.d.cts +5 -0
- package/v4/locales/ne.d.ts +4 -0
- package/v4/locales/ne.js +111 -0
- package/v4/locales/nl.cjs +142 -0
- package/v4/locales/nl.d.cts +5 -0
- package/v4/locales/nl.d.ts +4 -0
- package/v4/locales/nl.js +115 -0
- package/v4/locales/nn.cjs +140 -0
- package/v4/locales/nn.d.cts +5 -0
- package/v4/locales/nn.d.ts +4 -0
- package/v4/locales/nn.js +113 -0
- package/v4/locales/no.cjs +140 -0
- package/v4/locales/no.d.cts +5 -0
- package/v4/locales/no.d.ts +4 -0
- package/v4/locales/no.js +113 -0
- package/v4/locales/ota.cjs +141 -0
- package/v4/locales/ota.d.cts +5 -0
- package/v4/locales/ota.d.ts +4 -0
- package/v4/locales/ota.js +114 -0
- package/v4/locales/pl.cjs +141 -0
- package/v4/locales/pl.d.cts +5 -0
- package/v4/locales/pl.d.ts +4 -0
- package/v4/locales/pl.js +114 -0
- package/v4/locales/ps.cjs +146 -0
- package/v4/locales/ps.d.cts +5 -0
- package/v4/locales/ps.d.ts +4 -0
- package/v4/locales/ps.js +119 -0
- package/v4/locales/pt-BR.cjs +170 -0
- package/v4/locales/pt-BR.d.cts +5 -0
- package/v4/locales/pt-BR.d.ts +4 -0
- package/v4/locales/pt-BR.js +143 -0
- package/v4/locales/pt.cjs +169 -0
- package/v4/locales/pt.d.cts +5 -0
- package/v4/locales/pt.d.ts +4 -0
- package/v4/locales/pt.js +142 -0
- package/v4/locales/ro.cjs +149 -0
- package/v4/locales/ro.d.cts +5 -0
- package/v4/locales/ro.d.ts +4 -0
- package/v4/locales/ro.js +122 -0
- package/v4/locales/ru.cjs +195 -0
- package/v4/locales/ru.d.cts +5 -0
- package/v4/locales/ru.d.ts +4 -0
- package/v4/locales/ru.js +168 -0
- package/v4/locales/sk.cjs +143 -0
- package/v4/locales/sk.d.cts +5 -0
- package/v4/locales/sk.d.ts +4 -0
- package/v4/locales/sk.js +116 -0
- package/v4/locales/sl.cjs +141 -0
- package/v4/locales/sl.d.cts +5 -0
- package/v4/locales/sl.d.ts +4 -0
- package/v4/locales/sl.js +114 -0
- package/v4/locales/sv.cjs +142 -0
- package/v4/locales/sv.d.cts +5 -0
- package/v4/locales/sv.d.ts +4 -0
- package/v4/locales/sv.js +115 -0
- package/v4/locales/ta.cjs +142 -0
- package/v4/locales/ta.d.cts +5 -0
- package/v4/locales/ta.d.ts +4 -0
- package/v4/locales/ta.js +115 -0
- package/v4/locales/tg.cjs +144 -0
- package/v4/locales/tg.d.cts +5 -0
- package/v4/locales/tg.d.ts +4 -0
- package/v4/locales/tg.js +117 -0
- package/v4/locales/th.cjs +142 -0
- package/v4/locales/th.d.cts +5 -0
- package/v4/locales/th.d.ts +4 -0
- package/v4/locales/th.js +115 -0
- package/v4/locales/tk.cjs +134 -0
- package/v4/locales/tk.d.cts +5 -0
- package/v4/locales/tk.d.ts +4 -0
- package/v4/locales/tk.js +107 -0
- package/v4/locales/tr.cjs +137 -0
- package/v4/locales/tr.d.cts +5 -0
- package/v4/locales/tr.d.ts +4 -0
- package/v4/locales/tr.js +110 -0
- package/v4/locales/ua.cjs +12 -0
- package/v4/locales/ua.d.cts +5 -0
- package/v4/locales/ua.d.ts +5 -0
- package/v4/locales/ua.js +5 -0
- package/v4/locales/uk.cjs +140 -0
- package/v4/locales/uk.d.cts +5 -0
- package/v4/locales/uk.d.ts +4 -0
- package/v4/locales/uk.js +113 -0
- package/v4/locales/ur.cjs +142 -0
- package/v4/locales/ur.d.cts +5 -0
- package/v4/locales/ur.d.ts +4 -0
- package/v4/locales/ur.js +115 -0
- package/v4/locales/uz.cjs +140 -0
- package/v4/locales/uz.d.cts +5 -0
- package/v4/locales/uz.d.ts +4 -0
- package/v4/locales/uz.js +113 -0
- package/v4/locales/vi.cjs +140 -0
- package/v4/locales/vi.d.cts +5 -0
- package/v4/locales/vi.d.ts +4 -0
- package/v4/locales/vi.js +113 -0
- package/v4/locales/yo.cjs +139 -0
- package/v4/locales/yo.d.cts +5 -0
- package/v4/locales/yo.d.ts +4 -0
- package/v4/locales/yo.js +112 -0
- package/v4/locales/zh-CN.cjs +141 -0
- package/v4/locales/zh-CN.d.cts +5 -0
- package/v4/locales/zh-CN.d.ts +4 -0
- package/v4/locales/zh-CN.js +114 -0
- package/v4/locales/zh-TW.cjs +139 -0
- package/v4/locales/zh-TW.d.cts +5 -0
- package/v4/locales/zh-TW.d.ts +4 -0
- package/v4/locales/zh-TW.js +112 -0
- package/v4/mini/checks.cjs +54 -0
- package/v4/mini/checks.d.cts +1 -0
- package/v4/mini/checks.d.ts +1 -0
- package/v4/mini/checks.js +1 -0
- package/v4/mini/coerce.cjs +71 -0
- package/v4/mini/coerce.d.cts +7 -0
- package/v4/mini/coerce.d.ts +7 -0
- package/v4/mini/coerce.js +22 -0
- package/v4/mini/deep-partial.cjs +58 -0
- package/v4/mini/deep-partial.d.cts +14 -0
- package/v4/mini/deep-partial.d.ts +14 -0
- package/v4/mini/deep-partial.js +13 -0
- package/v4/mini/external.cjs +95 -0
- package/v4/mini/external.d.cts +16 -0
- package/v4/mini/external.d.ts +16 -0
- package/v4/mini/external.js +16 -0
- package/v4/mini/in-out.cjs +82 -0
- package/v4/mini/in-out.d.cts +8 -0
- package/v4/mini/in-out.d.ts +8 -0
- package/v4/mini/in-out.js +36 -0
- package/v4/mini/index.cjs +51 -0
- package/v4/mini/index.d.cts +3 -0
- package/v4/mini/index.d.ts +3 -0
- package/v4/mini/index.js +3 -0
- package/v4/mini/iso.cjs +83 -0
- package/v4/mini/iso.d.cts +22 -0
- package/v4/mini/iso.d.ts +22 -0
- package/v4/mini/iso.js +34 -0
- package/v4/mini/parse.cjs +37 -0
- package/v4/mini/parse.d.cts +1 -0
- package/v4/mini/parse.d.ts +1 -0
- package/v4/mini/parse.js +1 -0
- package/v4/mini/schemas.cjs +1149 -0
- package/v4/mini/schemas.d.cts +480 -0
- package/v4/mini/schemas.d.ts +480 -0
- package/v4/mini/schemas.js +1004 -0
- package/v4-mini/index.cjs +51 -0
- package/v4-mini/index.d.cts +3 -0
- package/v4-mini/index.d.ts +3 -0
- package/v4-mini/index.js +3 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { expect, test } from "vitest";
|
|
2
|
+
import * as z from "yatsp/v4";
|
|
3
|
+
|
|
4
|
+
test("locales - uz", () => {
|
|
5
|
+
z.config(z.locales.uz());
|
|
6
|
+
|
|
7
|
+
const invalidType = z.number().safeParse("a");
|
|
8
|
+
expect(invalidType.error!.issues[0].code).toBe("invalid_type");
|
|
9
|
+
expect(invalidType.error!.issues[0].message).toBe("Noto‘g‘ri kirish: kutilgan raqam, qabul qilingan string");
|
|
10
|
+
|
|
11
|
+
const invalidType2 = z.string().safeParse(1);
|
|
12
|
+
expect(invalidType2.error!.issues[0].code).toBe("invalid_type");
|
|
13
|
+
expect(invalidType2.error!.issues[0].message).toBe("Noto‘g‘ri kirish: kutilgan string, qabul qilingan raqam");
|
|
14
|
+
|
|
15
|
+
const invalidValue = z.enum(["a", "b"]).safeParse(1);
|
|
16
|
+
expect(invalidValue.error!.issues[0].code).toBe("invalid_value");
|
|
17
|
+
expect(invalidValue.error!.issues[0].message).toBe('Noto‘g‘ri variant: quyidagilardan biri kutilgan "a"|"b"');
|
|
18
|
+
|
|
19
|
+
const tooBig = z.number().max(10).safeParse(15);
|
|
20
|
+
expect(tooBig.error!.issues[0].code).toBe("too_big");
|
|
21
|
+
expect(tooBig.error!.issues[0].message).toBe("Juda katta: kutilgan number <=10");
|
|
22
|
+
|
|
23
|
+
const tooSmall = z.number().min(10).safeParse(5);
|
|
24
|
+
expect(tooSmall.error!.issues[0].code).toBe("too_small");
|
|
25
|
+
expect(tooSmall.error!.issues[0].message).toBe("Juda kichik: kutilgan number >=10");
|
|
26
|
+
|
|
27
|
+
const invalidFormatRegex = z.string().regex(/abcd/).safeParse("invalid-string");
|
|
28
|
+
expect(invalidFormatRegex.error!.issues[0].code).toBe("invalid_format");
|
|
29
|
+
expect(invalidFormatRegex.error!.issues[0].message).toContain("shabloniga mos kelishi kerak");
|
|
30
|
+
|
|
31
|
+
const invalidFormatStartsWith = z.string().startsWith("abcd").safeParse("invalid-string");
|
|
32
|
+
expect(invalidFormatStartsWith.error!.issues[0].code).toBe("invalid_format");
|
|
33
|
+
expect(invalidFormatStartsWith.error!.issues[0].message).toContain('"abcd" bilan boshlanishi kerak');
|
|
34
|
+
|
|
35
|
+
const notMultipleOf = z.number().multipleOf(3).safeParse(10);
|
|
36
|
+
expect(notMultipleOf.error!.issues[0].code).toBe("not_multiple_of");
|
|
37
|
+
expect(notMultipleOf.error!.issues[0].message).toContain("3 ning karralisi bo‘lishi kerak");
|
|
38
|
+
|
|
39
|
+
const unrecognizedKeys = z.object({ a: z.string(), b: z.number() }).strict().safeParse({ a: "a", b: 1, c: 2 });
|
|
40
|
+
expect(unrecognizedKeys.error!.issues[0].code).toBe("unrecognized_keys");
|
|
41
|
+
expect(unrecognizedKeys.error!.issues[0].message).toContain('Noma’lum kalit: "c"');
|
|
42
|
+
|
|
43
|
+
const invalidUnion = z.union([z.string(), z.number()]).safeParse(true);
|
|
44
|
+
expect(invalidUnion.error!.issues[0].code).toBe("invalid_union");
|
|
45
|
+
expect(invalidUnion.error!.issues[0].message).toBe("Noto‘g‘ri kirish");
|
|
46
|
+
|
|
47
|
+
const tooBigString = z.string().max(5).safeParse("too long string");
|
|
48
|
+
expect(tooBigString.error!.issues[0].code).toBe("too_big");
|
|
49
|
+
expect(tooBigString.error!.issues[0].message).toContain("belgi");
|
|
50
|
+
expect(tooBigString.error!.issues[0].message).toContain("bo‘lishi kerak");
|
|
51
|
+
|
|
52
|
+
const tooSmallArray = z.array(z.string()).min(3).safeParse(["a", "b"]);
|
|
53
|
+
expect(tooSmallArray.error!.issues[0].code).toBe("too_small");
|
|
54
|
+
expect(tooSmallArray.error!.issues[0].message).toContain("element");
|
|
55
|
+
expect(tooSmallArray.error!.issues[0].message).toContain("bo‘lishi kerak");
|
|
56
|
+
|
|
57
|
+
const invalidFormatEndsWith = z.string().endsWith("xyz").safeParse("invalid-string");
|
|
58
|
+
expect(invalidFormatEndsWith.error!.issues[0].code).toBe("invalid_format");
|
|
59
|
+
expect(invalidFormatEndsWith.error!.issues[0].message).toContain('"xyz" bilan tugashi kerak');
|
|
60
|
+
|
|
61
|
+
const invalidFormatIncludes = z.string().includes("test").safeParse("invalid-string");
|
|
62
|
+
expect(invalidFormatIncludes.error!.issues[0].code).toBe("invalid_format");
|
|
63
|
+
expect(invalidFormatIncludes.error!.issues[0].message).toContain('"test" ni o‘z ichiga olishi kerak');
|
|
64
|
+
|
|
65
|
+
const invalidFormatEmail = z.string().email().safeParse("invalid-email");
|
|
66
|
+
expect(invalidFormatEmail.error!.issues[0].code).toBe("invalid_format");
|
|
67
|
+
expect(invalidFormatEmail.error!.issues[0].message).toContain("elektron pochta manzili");
|
|
68
|
+
|
|
69
|
+
const invalidFormatUrl = z.string().url().safeParse("invalid-url");
|
|
70
|
+
expect(invalidFormatUrl.error!.issues[0].code).toBe("invalid_format");
|
|
71
|
+
expect(invalidFormatUrl.error!.issues[0].message).toContain("URL");
|
|
72
|
+
|
|
73
|
+
const unrecognizedKeysMultiple = z
|
|
74
|
+
.object({ a: z.string(), b: z.number() })
|
|
75
|
+
.strict()
|
|
76
|
+
.safeParse({ a: "a", b: 1, c: 2, d: 3 });
|
|
77
|
+
expect(unrecognizedKeysMultiple.error!.issues[0].code).toBe("unrecognized_keys");
|
|
78
|
+
expect(unrecognizedKeysMultiple.error!.issues[0].message).toContain("Noma’lum kalitlar");
|
|
79
|
+
|
|
80
|
+
const invalidElement = z.array(z.string()).safeParse([1, 2, 3]);
|
|
81
|
+
expect(invalidElement.error!.issues[0].code).toBe("invalid_type");
|
|
82
|
+
expect(invalidElement.error!.issues[0].message).toContain("raqam");
|
|
83
|
+
|
|
84
|
+
const tooSmallMap = z
|
|
85
|
+
.map(z.string(), z.string())
|
|
86
|
+
.min(3)
|
|
87
|
+
.safeParse(new Map([["a", "b"]]));
|
|
88
|
+
expect(tooSmallMap.error!.issues[0].code).toBe("too_small");
|
|
89
|
+
expect(tooSmallMap.error!.issues[0].message).toContain("yozuv");
|
|
90
|
+
expect(tooSmallMap.error!.issues[0].message).toContain("bo‘lishi kerak");
|
|
91
|
+
|
|
92
|
+
const tooBigMap = z
|
|
93
|
+
.map(z.string(), z.string())
|
|
94
|
+
.max(2)
|
|
95
|
+
.safeParse(
|
|
96
|
+
new Map([
|
|
97
|
+
["a", "b"],
|
|
98
|
+
["c", "d"],
|
|
99
|
+
["e", "f"],
|
|
100
|
+
])
|
|
101
|
+
);
|
|
102
|
+
expect(tooBigMap.error!.issues[0].code).toBe("too_big");
|
|
103
|
+
expect(tooBigMap.error!.issues[0].message).toContain("yozuv");
|
|
104
|
+
expect(tooBigMap.error!.issues[0].message).toContain("bo‘lishi kerak");
|
|
105
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import * as path from "node:path";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import { build, transform } from "esbuild";
|
|
4
|
+
import { expect, test } from "vitest";
|
|
5
|
+
import * as core from "yatsp/v4/core";
|
|
6
|
+
|
|
7
|
+
// Browser polyfills for node globals land as raw text in the bundle's top scope — an esbuild `banner`, a scope-unaware injector — so the bundler never sees the collision and the browser is the first thing to read both declarations. yatsp must therefore declare none of these names at module scope. The JSON Schema pass shipped an `export function process` for three minors before #6397 reported the white screen it caused.
|
|
8
|
+
const INJECTED = ["process", "Buffer", "global", "__dirname", "__filename"];
|
|
9
|
+
|
|
10
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
11
|
+
const CLASSIC = path.resolve(here, "../../../index.ts");
|
|
12
|
+
const MINI = path.resolve(here, "../../../mini/index.ts");
|
|
13
|
+
|
|
14
|
+
const polyfills = INJECTED.map((name) => `const ${name} = {};`).join("\n");
|
|
15
|
+
|
|
16
|
+
// toJSONSchema has to be reachable: a bundle that only parses a schema tree-shakes the offending module away and would pass no matter what it declares. `z.core.process` is the pre-rename export name, read as a namespace property so the entry itself declares no `process` binding.
|
|
17
|
+
const ENTRY = `import * as z from "%ENTRY%";\nglobalThis.__out = [z.toJSONSchema(z.string()), z.core.process];`;
|
|
18
|
+
|
|
19
|
+
test.each([
|
|
20
|
+
["classic", CLASSIC],
|
|
21
|
+
["mini", MINI],
|
|
22
|
+
])(
|
|
23
|
+
"a %s bundle reaching toJSONSchema parses beside polyfilled node globals",
|
|
24
|
+
async (_flavor, entrypoint) => {
|
|
25
|
+
const result = await build({
|
|
26
|
+
stdin: { contents: ENTRY.replace("%ENTRY%", entrypoint), loader: "ts", resolveDir: here },
|
|
27
|
+
bundle: true,
|
|
28
|
+
format: "esm",
|
|
29
|
+
target: "es2020",
|
|
30
|
+
write: false,
|
|
31
|
+
logLevel: "silent",
|
|
32
|
+
banner: { js: polyfills },
|
|
33
|
+
});
|
|
34
|
+
const out = result.outputFiles[0]!.text;
|
|
35
|
+
|
|
36
|
+
expect(out).toContain("https://json-schema.org/draft/2020-12/schema");
|
|
37
|
+
|
|
38
|
+
// the banner is appended after esbuild has already renamed its own symbols, so this second pass is where a duplicate surfaces: `The symbol "process" has already been declared`
|
|
39
|
+
await expect(transform(out, { loader: "js", format: "esm" })).resolves.toBeTruthy();
|
|
40
|
+
},
|
|
41
|
+
30000
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
test("the pre-rename `process` export still resolves to the helper", () => {
|
|
45
|
+
expect(core.process).toBe(core.processSchema);
|
|
46
|
+
});
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { expect, test } from "vitest";
|
|
2
|
+
import * as z from "yatsp/v4";
|
|
3
|
+
|
|
4
|
+
test("record should parse objects with non-function constructor field", () => {
|
|
5
|
+
const schema = z.record(z.string(), z.any());
|
|
6
|
+
|
|
7
|
+
expect(() => schema.parse({ constructor: "string", key: "value" })).not.toThrow();
|
|
8
|
+
|
|
9
|
+
const result1 = schema.parse({ constructor: "string", key: "value" });
|
|
10
|
+
expect(result1).toEqual({ constructor: "string", key: "value" });
|
|
11
|
+
|
|
12
|
+
expect(() => schema.parse({ constructor: 123, key: "value" })).not.toThrow();
|
|
13
|
+
|
|
14
|
+
const result2 = schema.parse({ constructor: 123, key: "value" });
|
|
15
|
+
expect(result2).toEqual({ constructor: 123, key: "value" });
|
|
16
|
+
|
|
17
|
+
expect(() => schema.parse({ constructor: null, key: "value" })).not.toThrow();
|
|
18
|
+
|
|
19
|
+
const result3 = schema.parse({ constructor: null, key: "value" });
|
|
20
|
+
expect(result3).toEqual({ constructor: null, key: "value" });
|
|
21
|
+
|
|
22
|
+
expect(() => schema.parse({ constructor: {}, key: "value" })).not.toThrow();
|
|
23
|
+
|
|
24
|
+
const result4 = schema.parse({ constructor: {}, key: "value" });
|
|
25
|
+
expect(result4).toEqual({ constructor: {}, key: "value" });
|
|
26
|
+
|
|
27
|
+
expect(() => schema.parse({ constructor: [], key: "value" })).not.toThrow();
|
|
28
|
+
|
|
29
|
+
const result5 = schema.parse({ constructor: [], key: "value" });
|
|
30
|
+
expect(result5).toEqual({ constructor: [], key: "value" });
|
|
31
|
+
|
|
32
|
+
expect(() => schema.parse({ constructor: true, key: "value" })).not.toThrow();
|
|
33
|
+
|
|
34
|
+
const result6 = schema.parse({ constructor: true, key: "value" });
|
|
35
|
+
expect(result6).toEqual({ constructor: true, key: "value" });
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test("record should still work with normal objects", () => {
|
|
39
|
+
const schema = z.record(z.string(), z.string());
|
|
40
|
+
|
|
41
|
+
expect(() => schema.parse({ normalKey: "value" })).not.toThrow();
|
|
42
|
+
|
|
43
|
+
const result1 = schema.parse({ normalKey: "value" });
|
|
44
|
+
expect(result1).toEqual({ normalKey: "value" });
|
|
45
|
+
|
|
46
|
+
expect(() => schema.parse({ key1: "value1", key2: "value2" })).not.toThrow();
|
|
47
|
+
|
|
48
|
+
const result2 = schema.parse({ key1: "value1", key2: "value2" });
|
|
49
|
+
expect(result2).toEqual({ key1: "value1", key2: "value2" });
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test("record should validate values according to schema even with constructor field", () => {
|
|
53
|
+
const stringSchema = z.record(z.string(), z.string());
|
|
54
|
+
|
|
55
|
+
expect(() => stringSchema.parse({ constructor: "string", key: "value" })).not.toThrow();
|
|
56
|
+
|
|
57
|
+
expect(() => stringSchema.parse({ constructor: 123, key: "value" })).toThrow();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test("record should work with different key types and constructor field", () => {
|
|
61
|
+
const enumSchema = z.record(z.enum(["constructor", "key"]), z.string());
|
|
62
|
+
|
|
63
|
+
expect(() => enumSchema.parse({ constructor: "value1", key: "value2" })).not.toThrow();
|
|
64
|
+
|
|
65
|
+
const result = enumSchema.parse({ constructor: "value1", key: "value2" });
|
|
66
|
+
expect(result).toEqual({ constructor: "value1", key: "value2" });
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test("record should skip non-enumerable own properties", () => {
|
|
70
|
+
const schema = z.record(z.string(), z.string());
|
|
71
|
+
|
|
72
|
+
const input = { key: "value" };
|
|
73
|
+
Object.defineProperty(input, "~standard", {
|
|
74
|
+
value: { validate: () => {}, vendor: "yatsp", version: 1 },
|
|
75
|
+
enumerable: false,
|
|
76
|
+
writable: false,
|
|
77
|
+
configurable: false,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
const result = schema.safeParse(input);
|
|
81
|
+
expect(result.success).toBe(true);
|
|
82
|
+
if (result.success) {
|
|
83
|
+
expect(result.data).toEqual({ key: "value" });
|
|
84
|
+
expect("~standard" in result.data).toBe(false);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test("record fails on enumerable invalid values even when non-enumerable properties are present", () => {
|
|
89
|
+
const schema = z.record(z.string(), z.string());
|
|
90
|
+
|
|
91
|
+
const input = { key: "value", bad: 123 };
|
|
92
|
+
Object.defineProperty(input, "hidden", {
|
|
93
|
+
value: "should be ignored",
|
|
94
|
+
enumerable: false,
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
const result = schema.safeParse(input);
|
|
98
|
+
expect(result.success).toBe(false);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test("record validates enumerable Symbol keys and skips non-enumerable Symbol keys", () => {
|
|
102
|
+
const enumerableSym = Symbol.for("included");
|
|
103
|
+
const nonEnumerableSym = Symbol.for("hidden");
|
|
104
|
+
const schema = z.record(z.symbol(), z.string());
|
|
105
|
+
|
|
106
|
+
const input: Record<symbol, unknown> = { [enumerableSym]: "value" };
|
|
107
|
+
Object.defineProperty(input, nonEnumerableSym, {
|
|
108
|
+
value: 123,
|
|
109
|
+
enumerable: false,
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
const result = schema.safeParse(input);
|
|
113
|
+
expect(result.success).toBe(true);
|
|
114
|
+
if (result.success) {
|
|
115
|
+
expect(result.data[enumerableSym]).toBe("value");
|
|
116
|
+
expect(Object.prototype.hasOwnProperty.call(result.data, nonEnumerableSym)).toBe(false);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
test("z.json() accepts z.toJSONSchema() output (issue #5714)", () => {
|
|
121
|
+
const schema = z.object({ name: z.string() });
|
|
122
|
+
const jsonSchema = z.toJSONSchema(schema);
|
|
123
|
+
|
|
124
|
+
expect(z.json().safeParse(jsonSchema).success).toBe(true);
|
|
125
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import * as z from "yatsp/v4";
|
|
3
|
+
|
|
4
|
+
describe("Recursive Tuples Regression #5089", () => {
|
|
5
|
+
it("creates recursive tuple without crash", () => {
|
|
6
|
+
expect(() => {
|
|
7
|
+
const y = z.lazy((): any => z.tuple([y, y]).or(z.string()));
|
|
8
|
+
}).not.toThrow();
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it("parses recursive tuple data correctly", () => {
|
|
12
|
+
const y = z.lazy((): any => z.tuple([y, y]).or(z.string()));
|
|
13
|
+
|
|
14
|
+
// Base case
|
|
15
|
+
expect(y.parse("hello")).toBe("hello");
|
|
16
|
+
|
|
17
|
+
// Recursive cases
|
|
18
|
+
expect(() => y.parse(["a", "b"])).not.toThrow();
|
|
19
|
+
expect(() => y.parse(["a", ["b", "c"]])).not.toThrow();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("matches #5089 expected behavior", () => {
|
|
23
|
+
// Exact code from the issue
|
|
24
|
+
expect(() => {
|
|
25
|
+
const y = z.lazy((): any => z.tuple([y, y]).or(z.string()));
|
|
26
|
+
y.parse(["a", ["b", "c"]]);
|
|
27
|
+
}).not.toThrow();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("handles workaround pattern", () => {
|
|
31
|
+
// Alternative pattern from issue discussion
|
|
32
|
+
expect(() => {
|
|
33
|
+
const y = z.lazy((): any => z.string().or(z.lazy(() => z.tuple([y, y]))));
|
|
34
|
+
y.parse(["a", ["b", "c"]]);
|
|
35
|
+
}).not.toThrow();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("recursive arrays still work (comparison)", () => {
|
|
39
|
+
const y = z.lazy((): any => z.array(y).or(z.string()));
|
|
40
|
+
|
|
41
|
+
expect(y.parse("hello")).toBe("hello");
|
|
42
|
+
expect(y.parse(["hello", "world"])).toEqual(["hello", "world"]);
|
|
43
|
+
expect(y.parse(["a", ["b", "c"]])).toEqual(["a", ["b", "c"]]);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import * as path from "node:path";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import { build } from "esbuild";
|
|
4
|
+
import { expect, test } from "vitest";
|
|
5
|
+
|
|
6
|
+
// These declarations are unreachable from a minimal schema, but esbuild only drops them because of details that read as noise: `@__PURE__` annotations, and the `anchor()` helper in regexes.ts that exists solely because esbuild will not drop an annotated call whose argument interpolates a variable. Inlining the helper or deleting an annotation silently puts them back with no other test going red.
|
|
7
|
+
//
|
|
8
|
+
// Rollup drops all of these regardless, so a rollup fixture would report no difference and prove nothing. This has to run under esbuild.
|
|
9
|
+
|
|
10
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
11
|
+
const MINI = path.resolve(here, "../../../mini/index.ts");
|
|
12
|
+
const CLASSIC = path.resolve(here, "../../../index.ts");
|
|
13
|
+
|
|
14
|
+
async function bundle(entrypoint: string, source: string): Promise<string> {
|
|
15
|
+
const result = await build({
|
|
16
|
+
stdin: {
|
|
17
|
+
contents: source.replace("%ENTRY%", entrypoint),
|
|
18
|
+
loader: "ts",
|
|
19
|
+
resolveDir: here,
|
|
20
|
+
},
|
|
21
|
+
bundle: true,
|
|
22
|
+
minify: true,
|
|
23
|
+
format: "esm",
|
|
24
|
+
target: "es2020",
|
|
25
|
+
treeShaking: true,
|
|
26
|
+
write: false,
|
|
27
|
+
logLevel: "silent",
|
|
28
|
+
});
|
|
29
|
+
return result.outputFiles[0]!.text;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
test("a minimal yatsp/mini schema drops the declarations it cannot reach", async () => {
|
|
33
|
+
const out = await bundle(MINI, `import * as z from "%ENTRY%";\nconsole.log(z.boolean().parse(true));`);
|
|
34
|
+
|
|
35
|
+
// Sanity check: the schema itself is present, so an empty bundle cannot pass this test.
|
|
36
|
+
expect(out).toContain("boolean");
|
|
37
|
+
|
|
38
|
+
expect(out, "core.ts `$brand` lost its @__PURE__ annotation").not.toContain("yatsp_brand");
|
|
39
|
+
expect(out, "util.ts `NUMBER_FORMAT_RANGES` escaped its @__PURE__ IIFE").not.toContain("MAX_SAFE_INTEGER");
|
|
40
|
+
expect(out, "regexes.ts `date` is pinned again — was `anchor()` inlined?").not.toContain("02-29");
|
|
41
|
+
}, 30000);
|
|
42
|
+
|
|
43
|
+
// `registries.ts` is dropped from the mini module graph entirely, so its two symbols are absent there before and after. Classic is the entrypoint that exercises them.
|
|
44
|
+
test("a minimal classic schema drops the registry symbols", async () => {
|
|
45
|
+
const out = await bundle(CLASSIC, `import * as z from "%ENTRY%";\nconsole.log(z.boolean().parse(true));`);
|
|
46
|
+
|
|
47
|
+
expect(out).toContain("boolean");
|
|
48
|
+
|
|
49
|
+
expect(out, "registries.ts `$output` lost its @__PURE__ annotation").not.toContain("YatspOutput");
|
|
50
|
+
expect(out, "registries.ts `$input` lost its @__PURE__ annotation").not.toContain("YatspInput");
|
|
51
|
+
}, 30000);
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
|
|
2
|
+
|
|
3
|
+
const URLDescriptor = Object.getOwnPropertyDescriptor(globalThis, "URL")!;
|
|
4
|
+
const NativeURL = globalThis.URL;
|
|
5
|
+
const canParseDescriptor = Object.getOwnPropertyDescriptor(NativeURL, "canParse")!;
|
|
6
|
+
const parseDescriptor = Object.getOwnPropertyDescriptor(NativeURL, "parse")!;
|
|
7
|
+
|
|
8
|
+
function restoreURL() {
|
|
9
|
+
Object.defineProperty(globalThis, "URL", URLDescriptor);
|
|
10
|
+
Object.defineProperty(NativeURL, "canParse", canParseDescriptor);
|
|
11
|
+
Object.defineProperty(NativeURL, "parse", parseDescriptor);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
describe("URL parser fallbacks", () => {
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
restoreURL();
|
|
17
|
+
vi.resetModules();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
afterEach(restoreURL);
|
|
21
|
+
|
|
22
|
+
test("uses the boolean and object APIs on modern runtimes", async () => {
|
|
23
|
+
const canParse = vi.spyOn(NativeURL, "canParse");
|
|
24
|
+
const URLStatic = NativeURL as typeof URL & { parse: (input: string) => URL | null };
|
|
25
|
+
const parse = vi.spyOn(URLStatic, "parse");
|
|
26
|
+
const z = await import("../../index.js");
|
|
27
|
+
|
|
28
|
+
expect(z.validate(z.url(), "https://example.com")).toBe(true);
|
|
29
|
+
expect(canParse).toHaveBeenCalledOnce();
|
|
30
|
+
expect(parse).not.toHaveBeenCalled();
|
|
31
|
+
|
|
32
|
+
canParse.mockClear();
|
|
33
|
+
expect(z.validate(z.url({ normalize: true }), "https://example.com")).toBe(true);
|
|
34
|
+
expect(parse).toHaveBeenCalledOnce();
|
|
35
|
+
expect(canParse).not.toHaveBeenCalled();
|
|
36
|
+
|
|
37
|
+
parse.mockClear();
|
|
38
|
+
expect(z.validate(z.ipv6(), "2001:db8::1")).toBe(true);
|
|
39
|
+
expect(canParse).toHaveBeenCalledOnce();
|
|
40
|
+
expect(parse).not.toHaveBeenCalled();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test("URL fast-path selection preserves live option getter reads", async () => {
|
|
44
|
+
const z = await import("../../index.js");
|
|
45
|
+
const postProcessor = z.core.globalConfig.postProcessor;
|
|
46
|
+
z.core.globalConfig.postProcessor = undefined;
|
|
47
|
+
try {
|
|
48
|
+
for (const inherited of [false, true]) {
|
|
49
|
+
const schema = z.url();
|
|
50
|
+
const target = inherited ? Object.create(Object.getPrototypeOf(schema.def)) : schema.def;
|
|
51
|
+
let reads = 0;
|
|
52
|
+
Object.defineProperty(target, "hostname", {
|
|
53
|
+
get: () => (++reads === 1 ? /^example\.com$/ : undefined),
|
|
54
|
+
});
|
|
55
|
+
if (inherited) Object.setPrototypeOf(schema.def, target);
|
|
56
|
+
expect(z.validate(schema, "https://example.com")).toBe(false);
|
|
57
|
+
expect(reads).toBe(2);
|
|
58
|
+
reads = 0;
|
|
59
|
+
expect(schema.safeParse("https://example.com").success).toBe(false);
|
|
60
|
+
expect(reads).toBe(2);
|
|
61
|
+
}
|
|
62
|
+
} finally {
|
|
63
|
+
z.core.globalConfig.postProcessor = postProcessor;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test("the exported object parser still returns a URL", async () => {
|
|
68
|
+
const { parseURLObject } = await import("../schemas.js");
|
|
69
|
+
const result = parseURLObject("https://example.com", {});
|
|
70
|
+
expect(result).toBeInstanceOf(NativeURL);
|
|
71
|
+
if (typeof result === "number") expect.unreachable();
|
|
72
|
+
expect(result.hostname).toBe("example.com");
|
|
73
|
+
expect(parseURLObject("invalid", {})).toBe(2);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test("falls back when URL.canParse is absent", async () => {
|
|
77
|
+
Reflect.deleteProperty(NativeURL, "canParse");
|
|
78
|
+
const z = await import("../../index.js");
|
|
79
|
+
const cases = [
|
|
80
|
+
[z.url(), "https://example.com", "not a url"],
|
|
81
|
+
[z.ipv6(), "2001:db8::1", "not-an-ip"],
|
|
82
|
+
[z.cidrv6(), "2001:db8::/32", "not-an-ip/32"],
|
|
83
|
+
] as const;
|
|
84
|
+
|
|
85
|
+
for (const [schema, valid, invalid] of cases) {
|
|
86
|
+
for (const subject of [schema, z.compile(schema)]) {
|
|
87
|
+
expect(z.validate(subject, valid)).toBe(true);
|
|
88
|
+
expect(z.validate(subject, invalid)).toBe(false);
|
|
89
|
+
expect(subject.safeParse(valid).success).toBe(true);
|
|
90
|
+
expect(subject.safeParse(invalid).success).toBe(false);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test("falls back when URL.parse is absent", async () => {
|
|
96
|
+
Reflect.deleteProperty(NativeURL, "parse");
|
|
97
|
+
const z = await import("../../index.js");
|
|
98
|
+
const cases = [
|
|
99
|
+
[z.url({ normalize: true }), "https://example.com", "not a url"],
|
|
100
|
+
[z.url({ hostname: /^example\.com$/ }), "https://example.com", "https://other.com"],
|
|
101
|
+
[z.httpUrl(), "https://example.com", "mailto:a@example.com"],
|
|
102
|
+
] as const;
|
|
103
|
+
|
|
104
|
+
for (const [schema, valid, invalid] of cases) {
|
|
105
|
+
for (const subject of [schema, z.compile(schema)]) {
|
|
106
|
+
expect(z.validate(subject, valid)).toBe(true);
|
|
107
|
+
expect(z.validate(subject, invalid)).toBe(false);
|
|
108
|
+
expect(subject.safeParse(valid).success).toBe(true);
|
|
109
|
+
expect(subject.safeParse(invalid).success).toBe(false);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
test("rejects without a global URL constructor", async () => {
|
|
115
|
+
const z = await import("../../index.js");
|
|
116
|
+
const cases = [
|
|
117
|
+
[z.url(), "https://example.com"],
|
|
118
|
+
[z.url({ normalize: true }), "https://example.com"],
|
|
119
|
+
[z.ipv6(), "2001:db8::1"],
|
|
120
|
+
[z.cidrv6(), "2001:db8::/32"],
|
|
121
|
+
] as const;
|
|
122
|
+
const subjects = cases.flatMap(([schema, input]) => [
|
|
123
|
+
[schema, input] as const,
|
|
124
|
+
[z.compile(schema), input] as const,
|
|
125
|
+
]);
|
|
126
|
+
Object.defineProperty(globalThis, "URL", { configurable: true, value: undefined });
|
|
127
|
+
|
|
128
|
+
for (const [schema, input] of subjects) {
|
|
129
|
+
expect(z.validate(schema, input)).toBe(false);
|
|
130
|
+
expect(schema.safeParse(input).success).toBe(false);
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
});
|