@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,881 @@
|
|
|
1
|
+
import { globalRegistry } from "../core/registries.js";
|
|
2
|
+
import { assignProp, isPlainObject } from "../core/util.js";
|
|
3
|
+
import * as _checks from "./checks.js";
|
|
4
|
+
import * as _iso from "./iso.js";
|
|
5
|
+
import * as _schemas from "./schemas.js";
|
|
6
|
+
// Local z object to avoid circular dependency with ../index.js
|
|
7
|
+
const z = {
|
|
8
|
+
..._schemas,
|
|
9
|
+
..._checks,
|
|
10
|
+
iso: _iso,
|
|
11
|
+
};
|
|
12
|
+
// Keys that are recognized and handled by the conversion logic
|
|
13
|
+
const RECOGNIZED_KEYS = /*@__PURE__*/ new Set([
|
|
14
|
+
// Schema identification
|
|
15
|
+
"$schema",
|
|
16
|
+
"$ref",
|
|
17
|
+
"$defs",
|
|
18
|
+
"definitions",
|
|
19
|
+
// Core schema keywords
|
|
20
|
+
"$id",
|
|
21
|
+
"id",
|
|
22
|
+
"$comment",
|
|
23
|
+
"$anchor",
|
|
24
|
+
"$vocabulary",
|
|
25
|
+
"$dynamicRef",
|
|
26
|
+
"$dynamicAnchor",
|
|
27
|
+
// Type
|
|
28
|
+
"type",
|
|
29
|
+
"enum",
|
|
30
|
+
"const",
|
|
31
|
+
// Composition
|
|
32
|
+
"anyOf",
|
|
33
|
+
"oneOf",
|
|
34
|
+
"allOf",
|
|
35
|
+
"not",
|
|
36
|
+
// Object
|
|
37
|
+
"properties",
|
|
38
|
+
"required",
|
|
39
|
+
"additionalProperties",
|
|
40
|
+
"patternProperties",
|
|
41
|
+
"propertyNames",
|
|
42
|
+
"minProperties",
|
|
43
|
+
"maxProperties",
|
|
44
|
+
// Array
|
|
45
|
+
"items",
|
|
46
|
+
"prefixItems",
|
|
47
|
+
"additionalItems",
|
|
48
|
+
"minItems",
|
|
49
|
+
"maxItems",
|
|
50
|
+
"uniqueItems",
|
|
51
|
+
"contains",
|
|
52
|
+
"minContains",
|
|
53
|
+
"maxContains",
|
|
54
|
+
// String
|
|
55
|
+
"minLength",
|
|
56
|
+
"maxLength",
|
|
57
|
+
"pattern",
|
|
58
|
+
"format",
|
|
59
|
+
// Number
|
|
60
|
+
"minimum",
|
|
61
|
+
"maximum",
|
|
62
|
+
"exclusiveMinimum",
|
|
63
|
+
"exclusiveMaximum",
|
|
64
|
+
"multipleOf",
|
|
65
|
+
// Already handled metadata
|
|
66
|
+
"description",
|
|
67
|
+
"default",
|
|
68
|
+
// Content
|
|
69
|
+
"contentEncoding",
|
|
70
|
+
"contentMediaType",
|
|
71
|
+
"contentSchema",
|
|
72
|
+
// Unsupported (error-throwing)
|
|
73
|
+
"unevaluatedItems",
|
|
74
|
+
"unevaluatedProperties",
|
|
75
|
+
"if",
|
|
76
|
+
"then",
|
|
77
|
+
"else",
|
|
78
|
+
"dependentSchemas",
|
|
79
|
+
"dependentRequired",
|
|
80
|
+
// OpenAPI
|
|
81
|
+
"nullable",
|
|
82
|
+
"readOnly",
|
|
83
|
+
]);
|
|
84
|
+
function detectVersion(schema, defaultTarget) {
|
|
85
|
+
const $schema = schema.$schema;
|
|
86
|
+
if ($schema === "https://json-schema.org/draft/2020-12/schema") {
|
|
87
|
+
return "draft-2020-12";
|
|
88
|
+
}
|
|
89
|
+
if ($schema === "http://json-schema.org/draft-07/schema#") {
|
|
90
|
+
return "draft-7";
|
|
91
|
+
}
|
|
92
|
+
if ($schema === "http://json-schema.org/draft-04/schema#") {
|
|
93
|
+
return "draft-4";
|
|
94
|
+
}
|
|
95
|
+
// Use defaultTarget if provided, otherwise default to draft-2020-12
|
|
96
|
+
return defaultTarget ?? "draft-2020-12";
|
|
97
|
+
}
|
|
98
|
+
// Positional schemas constrain the elements that are present; only minItems makes them required.
|
|
99
|
+
function applyMinItems(items, minItems) {
|
|
100
|
+
return items.map((item, index) => (index < minItems ? item : item.optional()));
|
|
101
|
+
}
|
|
102
|
+
// Inverse of the encoding applied to $ref pointer segments in to-json-schema.ts. Per RFC 6901 the `~1` replacement must run before `~0`.
|
|
103
|
+
function decodeJSONPointerSegment(segment) {
|
|
104
|
+
return segment.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
105
|
+
}
|
|
106
|
+
function resolveRef(ref, ctx) {
|
|
107
|
+
if (!ref.startsWith("#")) {
|
|
108
|
+
throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
|
|
109
|
+
}
|
|
110
|
+
const path = ref.slice(1).split("/").filter(Boolean);
|
|
111
|
+
// Handle root reference "#"
|
|
112
|
+
if (path.length === 0) {
|
|
113
|
+
return ctx.rootSchema;
|
|
114
|
+
}
|
|
115
|
+
const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
|
|
116
|
+
if (path[0] === defsKey) {
|
|
117
|
+
const key = path[1] === undefined ? undefined : decodeJSONPointerSegment(path[1]);
|
|
118
|
+
if (!key || !ctx.defs[key]) {
|
|
119
|
+
throw new Error(`Reference not found: ${ref}`);
|
|
120
|
+
}
|
|
121
|
+
return ctx.defs[key];
|
|
122
|
+
}
|
|
123
|
+
throw new Error(`Reference not found: ${ref}`);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Enforces the keywords that constrain an object's own keys — `propertyNames`,
|
|
127
|
+
* `minProperties`, `maxProperties` — before `objectSchema` runs. The guard has
|
|
128
|
+
* to see the raw input: an object parse drops `__proto__` and can add keys from
|
|
129
|
+
* a property `default`, so its output is not the set of names the instance
|
|
130
|
+
* actually carried.
|
|
131
|
+
*/
|
|
132
|
+
function checkObjectGuards(objectSchema, guards) {
|
|
133
|
+
// An identity transform, not z.any(), so `toJSONSchema` reports the object on both the input and the output side of the pipe.
|
|
134
|
+
const guard = z
|
|
135
|
+
.transform((value) => value)
|
|
136
|
+
.check((payload) => {
|
|
137
|
+
const value = payload.value;
|
|
138
|
+
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
139
|
+
return;
|
|
140
|
+
const keys = Object.getOwnPropertyNames(value);
|
|
141
|
+
if (guards.minProperties !== undefined && keys.length < guards.minProperties) {
|
|
142
|
+
payload.issues.push({
|
|
143
|
+
origin: "object",
|
|
144
|
+
code: "too_small",
|
|
145
|
+
minimum: guards.minProperties,
|
|
146
|
+
inclusive: true,
|
|
147
|
+
message: `Too small: expected object to have >=${guards.minProperties} properties`,
|
|
148
|
+
input: value,
|
|
149
|
+
inst: objectSchema,
|
|
150
|
+
continue: true,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
if (guards.maxProperties !== undefined && keys.length > guards.maxProperties) {
|
|
154
|
+
payload.issues.push({
|
|
155
|
+
origin: "object",
|
|
156
|
+
code: "too_big",
|
|
157
|
+
maximum: guards.maxProperties,
|
|
158
|
+
inclusive: true,
|
|
159
|
+
message: `Too big: expected object to have <=${guards.maxProperties} properties`,
|
|
160
|
+
input: value,
|
|
161
|
+
inst: objectSchema,
|
|
162
|
+
continue: true,
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
if (guards.keySchema) {
|
|
166
|
+
for (const key of keys) {
|
|
167
|
+
const result = guards.keySchema.safeParse(key);
|
|
168
|
+
if (result.success)
|
|
169
|
+
continue;
|
|
170
|
+
payload.issues.push({
|
|
171
|
+
code: "invalid_key",
|
|
172
|
+
origin: "record",
|
|
173
|
+
issues: result.error.issues,
|
|
174
|
+
input: key,
|
|
175
|
+
path: [key],
|
|
176
|
+
continue: true,
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
return guard.pipe(objectSchema);
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* An injective string for JSON data: two values share a key exactly when `uniqueItems` calls them
|
|
185
|
+
* equal, so duplicate detection is a Map lookup rather than a pairwise walk. Strings and keys are
|
|
186
|
+
* length-prefixed so no value can spell another one. `null` means "never equal to anything" — a
|
|
187
|
+
* cycle or a NaN, neither of which JSON can express.
|
|
188
|
+
*/
|
|
189
|
+
function canonicalKey(value, seen) {
|
|
190
|
+
if (value === null)
|
|
191
|
+
return "z";
|
|
192
|
+
const type = typeof value;
|
|
193
|
+
if (type !== "object") {
|
|
194
|
+
if (type === "number" && Number.isNaN(value))
|
|
195
|
+
return null;
|
|
196
|
+
const raw = String(value);
|
|
197
|
+
return `${type[0]}${raw.length}:${raw}`;
|
|
198
|
+
}
|
|
199
|
+
if (seen.has(value))
|
|
200
|
+
return null;
|
|
201
|
+
seen.add(value);
|
|
202
|
+
try {
|
|
203
|
+
if (Array.isArray(value)) {
|
|
204
|
+
const parts = [];
|
|
205
|
+
for (const item of value) {
|
|
206
|
+
const key = canonicalKey(item, seen);
|
|
207
|
+
if (key === null)
|
|
208
|
+
return null;
|
|
209
|
+
parts.push(key);
|
|
210
|
+
}
|
|
211
|
+
return `a${parts.length}:[${parts.join(",")}]`;
|
|
212
|
+
}
|
|
213
|
+
const keys = Object.keys(value).sort();
|
|
214
|
+
const parts = [];
|
|
215
|
+
for (const k of keys) {
|
|
216
|
+
const key = canonicalKey(value[k], seen);
|
|
217
|
+
if (key === null)
|
|
218
|
+
return null;
|
|
219
|
+
parts.push(`${k.length}:${k}=${key}`);
|
|
220
|
+
}
|
|
221
|
+
return `o${parts.length}:{${parts.join(",")}}`;
|
|
222
|
+
}
|
|
223
|
+
finally {
|
|
224
|
+
seen.delete(value);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
// keywords whose value is a schema or an array of them
|
|
228
|
+
const SCHEMA_KEYWORDS = /*@__PURE__*/ new Set([
|
|
229
|
+
"items",
|
|
230
|
+
"prefixItems",
|
|
231
|
+
"additionalItems",
|
|
232
|
+
"additionalProperties",
|
|
233
|
+
"contains",
|
|
234
|
+
"propertyNames",
|
|
235
|
+
"not",
|
|
236
|
+
"if",
|
|
237
|
+
"then",
|
|
238
|
+
"else",
|
|
239
|
+
"allOf",
|
|
240
|
+
"anyOf",
|
|
241
|
+
"oneOf",
|
|
242
|
+
"unevaluatedItems",
|
|
243
|
+
"unevaluatedProperties",
|
|
244
|
+
"contentSchema",
|
|
245
|
+
]);
|
|
246
|
+
// keywords whose value maps names to schemas. draft-7 `dependencies` also allows an array of property names, which holds no schema to walk
|
|
247
|
+
const SCHEMA_MAP_KEYWORDS = /*@__PURE__*/ new Set([
|
|
248
|
+
"properties",
|
|
249
|
+
"patternProperties",
|
|
250
|
+
"dependentSchemas",
|
|
251
|
+
"dependencies",
|
|
252
|
+
"$defs",
|
|
253
|
+
"definitions",
|
|
254
|
+
]);
|
|
255
|
+
/**
|
|
256
|
+
* True when a subschema holds a `$ref` anywhere a schema can appear. Only those positions are
|
|
257
|
+
* walked: `$ref` under `default` or an `x-` annotation is instance data with an ordinary key, and
|
|
258
|
+
* reading it as a reference would drop a constraint that resolves perfectly well.
|
|
259
|
+
*/
|
|
260
|
+
function containsRef(value) {
|
|
261
|
+
if (typeof value !== "object" || value === null)
|
|
262
|
+
return false;
|
|
263
|
+
if (Array.isArray(value))
|
|
264
|
+
return value.some(containsRef);
|
|
265
|
+
if (typeof value.$ref === "string")
|
|
266
|
+
return true;
|
|
267
|
+
return Object.entries(value).some(([key, sub]) => {
|
|
268
|
+
if (SCHEMA_KEYWORDS.has(key))
|
|
269
|
+
return containsRef(sub);
|
|
270
|
+
if (!SCHEMA_MAP_KEYWORDS.has(key) || typeof sub !== "object" || sub === null)
|
|
271
|
+
return false;
|
|
272
|
+
return Object.values(sub).some(containsRef);
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
function plural(n) {
|
|
276
|
+
return n === 1 ? "element" : "elements";
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Enforces `uniqueItems` and the `contains` family before `arraySchema` runs, for the same reason
|
|
280
|
+
* `checkObjectGuards` runs pre-pipe: an item parse can apply a nested `default`, so the parsed
|
|
281
|
+
* array is not the instance the keywords are defined over. A guard issue aborts the pipe, so
|
|
282
|
+
* `minItems`/`maxItems` are not also reported on the same parse — instance correctness is worth
|
|
283
|
+
* more than co-reporting two issues.
|
|
284
|
+
*/
|
|
285
|
+
function checkArrayGuards(arraySchema, guards) {
|
|
286
|
+
// An identity transform, not z.any(), so `toJSONSchema` reports the array on both the input and the output side of the pipe.
|
|
287
|
+
const guard = z
|
|
288
|
+
.transform((value) => value)
|
|
289
|
+
.check((payload) => {
|
|
290
|
+
const items = payload.value;
|
|
291
|
+
if (!Array.isArray(items))
|
|
292
|
+
return;
|
|
293
|
+
if (guards.uniqueItems === true) {
|
|
294
|
+
const firstSeen = new Map();
|
|
295
|
+
for (let i = 0; i < items.length; i++) {
|
|
296
|
+
const key = canonicalKey(items[i], new Set());
|
|
297
|
+
if (key === null)
|
|
298
|
+
continue;
|
|
299
|
+
const first = firstSeen.get(key);
|
|
300
|
+
if (first === undefined) {
|
|
301
|
+
firstSeen.set(key, i);
|
|
302
|
+
continue;
|
|
303
|
+
}
|
|
304
|
+
payload.issues.push({
|
|
305
|
+
code: "custom",
|
|
306
|
+
message: `Array items must be unique: element at index ${i} duplicates the one at index ${first}`,
|
|
307
|
+
input: items,
|
|
308
|
+
path: [i],
|
|
309
|
+
continue: true,
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
if (guards.containsSchema) {
|
|
314
|
+
const minContains = guards.minContains ?? 1;
|
|
315
|
+
// one past the ceiling already proves the failure, and nothing above it changes the verdict
|
|
316
|
+
const ceiling = guards.maxContains !== undefined ? guards.maxContains + 1 : Number.POSITIVE_INFINITY;
|
|
317
|
+
let matches = 0;
|
|
318
|
+
for (const item of items) {
|
|
319
|
+
if (guards.containsSchema.safeParse(item).success && ++matches >= ceiling)
|
|
320
|
+
break;
|
|
321
|
+
}
|
|
322
|
+
if (matches < minContains) {
|
|
323
|
+
// the scan ran to the end, so this count is exact
|
|
324
|
+
payload.issues.push({
|
|
325
|
+
code: "custom",
|
|
326
|
+
message: `Array must contain at least ${minContains} matching ${plural(minContains)}; found ${matches}`,
|
|
327
|
+
input: items,
|
|
328
|
+
continue: true,
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
if (guards.maxContains !== undefined && matches > guards.maxContains) {
|
|
332
|
+
payload.issues.push({
|
|
333
|
+
code: "custom",
|
|
334
|
+
message: `Array must contain at most ${guards.maxContains} matching ${plural(guards.maxContains)}`,
|
|
335
|
+
input: items,
|
|
336
|
+
continue: true,
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
return guard.pipe(arraySchema);
|
|
342
|
+
}
|
|
343
|
+
function getTupleRest(restSchema, ctx) {
|
|
344
|
+
if (restSchema === false) {
|
|
345
|
+
return undefined;
|
|
346
|
+
}
|
|
347
|
+
if (restSchema === undefined || restSchema === true) {
|
|
348
|
+
return z.any();
|
|
349
|
+
}
|
|
350
|
+
return convertSchema(restSchema, ctx);
|
|
351
|
+
}
|
|
352
|
+
// the RFC 3339 full-time keyword, narrower than `z.iso.time()`; local because sharing it via `timeSource` pins that builder into every bundle (+139 B gzipped on a mini `z.boolean()`)
|
|
353
|
+
const fullTime = /^(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d+)?(?:Z|[+-](?:[01]\d|2[0-3]):[0-5]\d)$/;
|
|
354
|
+
function convertBaseSchema(schema, ctx) {
|
|
355
|
+
// Handle unsupported features
|
|
356
|
+
if (schema.not !== undefined) {
|
|
357
|
+
// Special case: { not: {} } represents never
|
|
358
|
+
if (typeof schema.not === "object" && Object.keys(schema.not).length === 0) {
|
|
359
|
+
return z.never();
|
|
360
|
+
}
|
|
361
|
+
throw new Error("not is not supported in Yatsp (except { not: {} } for never)");
|
|
362
|
+
}
|
|
363
|
+
if (schema.unevaluatedItems !== undefined) {
|
|
364
|
+
throw new Error("unevaluatedItems is not supported");
|
|
365
|
+
}
|
|
366
|
+
if (schema.unevaluatedProperties !== undefined) {
|
|
367
|
+
throw new Error("unevaluatedProperties is not supported");
|
|
368
|
+
}
|
|
369
|
+
if (schema.if !== undefined || schema.then !== undefined || schema.else !== undefined) {
|
|
370
|
+
throw new Error("Conditional schemas (if/then/else) are not supported");
|
|
371
|
+
}
|
|
372
|
+
if (schema.dependentSchemas !== undefined || schema.dependentRequired !== undefined) {
|
|
373
|
+
throw new Error("dependentSchemas and dependentRequired are not supported");
|
|
374
|
+
}
|
|
375
|
+
// Handle $ref
|
|
376
|
+
if (schema.$ref) {
|
|
377
|
+
const refPath = schema.$ref;
|
|
378
|
+
if (ctx.refs.has(refPath)) {
|
|
379
|
+
return ctx.refs.get(refPath);
|
|
380
|
+
}
|
|
381
|
+
if (ctx.processing.has(refPath)) {
|
|
382
|
+
// Circular reference - use lazy
|
|
383
|
+
return z.lazy(() => {
|
|
384
|
+
if (!ctx.refs.has(refPath)) {
|
|
385
|
+
throw new Error(`Circular reference not resolved: ${refPath}`);
|
|
386
|
+
}
|
|
387
|
+
return ctx.refs.get(refPath);
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
ctx.processing.add(refPath);
|
|
391
|
+
const resolved = resolveRef(refPath, ctx);
|
|
392
|
+
const yatspSchema = convertSchema(resolved, ctx);
|
|
393
|
+
ctx.refs.set(refPath, yatspSchema);
|
|
394
|
+
ctx.processing.delete(refPath);
|
|
395
|
+
return yatspSchema;
|
|
396
|
+
}
|
|
397
|
+
// Handle enum
|
|
398
|
+
if (schema.enum !== undefined) {
|
|
399
|
+
const enumValues = schema.enum;
|
|
400
|
+
// Special case: OpenAPI 3.0 null representation { type: "string", nullable: true, enum: [null] }
|
|
401
|
+
if (ctx.version === "openapi-3.0" &&
|
|
402
|
+
schema.nullable === true &&
|
|
403
|
+
enumValues.length === 1 &&
|
|
404
|
+
enumValues[0] === null) {
|
|
405
|
+
return z.null();
|
|
406
|
+
}
|
|
407
|
+
if (enumValues.length === 0) {
|
|
408
|
+
return z.never();
|
|
409
|
+
}
|
|
410
|
+
if (enumValues.length === 1) {
|
|
411
|
+
return z.literal(enumValues[0]);
|
|
412
|
+
}
|
|
413
|
+
// Check if all values are strings
|
|
414
|
+
if (enumValues.every((v) => typeof v === "string")) {
|
|
415
|
+
return z.enum(enumValues);
|
|
416
|
+
}
|
|
417
|
+
// Mixed types - use union of literals
|
|
418
|
+
const literalSchemas = enumValues.map((v) => z.literal(v));
|
|
419
|
+
if (literalSchemas.length < 2) {
|
|
420
|
+
return literalSchemas[0];
|
|
421
|
+
}
|
|
422
|
+
return z.union([literalSchemas[0], literalSchemas[1], ...literalSchemas.slice(2)]);
|
|
423
|
+
}
|
|
424
|
+
// Handle const
|
|
425
|
+
if (schema.const !== undefined) {
|
|
426
|
+
return z.literal(schema.const);
|
|
427
|
+
}
|
|
428
|
+
// Handle type
|
|
429
|
+
const type = schema.type;
|
|
430
|
+
if (Array.isArray(type)) {
|
|
431
|
+
// Expand type array into anyOf union
|
|
432
|
+
const typeSchemas = type.map((t) => {
|
|
433
|
+
const typeSchema = { ...schema, type: t };
|
|
434
|
+
return convertBaseSchema(typeSchema, ctx);
|
|
435
|
+
});
|
|
436
|
+
if (typeSchemas.length === 0) {
|
|
437
|
+
return z.never();
|
|
438
|
+
}
|
|
439
|
+
if (typeSchemas.length === 1) {
|
|
440
|
+
return typeSchemas[0];
|
|
441
|
+
}
|
|
442
|
+
return z.union(typeSchemas);
|
|
443
|
+
}
|
|
444
|
+
if (!type) {
|
|
445
|
+
// No type specified - empty schema (any)
|
|
446
|
+
return z.any();
|
|
447
|
+
}
|
|
448
|
+
let yatspSchema;
|
|
449
|
+
switch (type) {
|
|
450
|
+
case "string": {
|
|
451
|
+
let stringSchema = z.string();
|
|
452
|
+
// Apply format using .check() with Yatsp format functions
|
|
453
|
+
if (schema.format) {
|
|
454
|
+
const format = schema.format;
|
|
455
|
+
// Map common formats to Yatsp check functions
|
|
456
|
+
if (format === "email") {
|
|
457
|
+
stringSchema = stringSchema.check(z.email());
|
|
458
|
+
}
|
|
459
|
+
else if (format === "uri" || format === "uri-reference") {
|
|
460
|
+
stringSchema = stringSchema.check(z.url());
|
|
461
|
+
}
|
|
462
|
+
else if (format === "uuid" || format === "guid") {
|
|
463
|
+
stringSchema = stringSchema.check(z.uuid());
|
|
464
|
+
}
|
|
465
|
+
else if (format === "date-time") {
|
|
466
|
+
stringSchema = stringSchema.check(z.iso.datetime({ offset: true }));
|
|
467
|
+
}
|
|
468
|
+
else if (format === "date") {
|
|
469
|
+
stringSchema = stringSchema.check(z.iso.date());
|
|
470
|
+
}
|
|
471
|
+
else if (format === "time") {
|
|
472
|
+
stringSchema = stringSchema.check(z.regex(fullTime));
|
|
473
|
+
}
|
|
474
|
+
else if (format === "duration") {
|
|
475
|
+
stringSchema = stringSchema.check(z.iso.duration());
|
|
476
|
+
}
|
|
477
|
+
else if (format === "hostname") {
|
|
478
|
+
stringSchema = stringSchema.check(z.hostname());
|
|
479
|
+
}
|
|
480
|
+
else if (format === "ipv4") {
|
|
481
|
+
stringSchema = stringSchema.check(z.ipv4());
|
|
482
|
+
}
|
|
483
|
+
else if (format === "ipv6") {
|
|
484
|
+
stringSchema = stringSchema.check(z.ipv6());
|
|
485
|
+
}
|
|
486
|
+
else if (format === "mac") {
|
|
487
|
+
stringSchema = stringSchema.check(z.mac());
|
|
488
|
+
}
|
|
489
|
+
else if (format === "cidr") {
|
|
490
|
+
stringSchema = stringSchema.check(z.cidrv4());
|
|
491
|
+
}
|
|
492
|
+
else if (format === "cidr-v6") {
|
|
493
|
+
stringSchema = stringSchema.check(z.cidrv6());
|
|
494
|
+
}
|
|
495
|
+
else if (format === "base64") {
|
|
496
|
+
stringSchema = stringSchema.check(z.base64());
|
|
497
|
+
}
|
|
498
|
+
else if (format === "base64url") {
|
|
499
|
+
stringSchema = stringSchema.check(z.base64url());
|
|
500
|
+
}
|
|
501
|
+
else if (format === "e164") {
|
|
502
|
+
stringSchema = stringSchema.check(z.e164());
|
|
503
|
+
}
|
|
504
|
+
else if (format === "credit_card") {
|
|
505
|
+
stringSchema = stringSchema.check(z.creditCard());
|
|
506
|
+
}
|
|
507
|
+
else if (format === "iban") {
|
|
508
|
+
stringSchema = stringSchema.check(z.iban());
|
|
509
|
+
}
|
|
510
|
+
else if (format === "jwt") {
|
|
511
|
+
stringSchema = stringSchema.check(z.jwt());
|
|
512
|
+
}
|
|
513
|
+
else if (format === "emoji") {
|
|
514
|
+
stringSchema = stringSchema.check(z.emoji());
|
|
515
|
+
}
|
|
516
|
+
else if (format === "nanoid") {
|
|
517
|
+
stringSchema = stringSchema.check(z.nanoid());
|
|
518
|
+
}
|
|
519
|
+
else if (format === "cuid") {
|
|
520
|
+
stringSchema = stringSchema.check(z.cuid());
|
|
521
|
+
}
|
|
522
|
+
else if (format === "cuid2") {
|
|
523
|
+
stringSchema = stringSchema.check(z.cuid2());
|
|
524
|
+
}
|
|
525
|
+
else if (format === "ulid") {
|
|
526
|
+
stringSchema = stringSchema.check(z.ulid());
|
|
527
|
+
}
|
|
528
|
+
else if (format === "xid") {
|
|
529
|
+
stringSchema = stringSchema.check(z.xid());
|
|
530
|
+
}
|
|
531
|
+
else if (format === "ksuid") {
|
|
532
|
+
stringSchema = stringSchema.check(z.ksuid());
|
|
533
|
+
}
|
|
534
|
+
// Note: json-string format is not currently supported by Yatsp
|
|
535
|
+
// Custom formats are ignored - keep as plain string
|
|
536
|
+
}
|
|
537
|
+
// Apply constraints
|
|
538
|
+
if (typeof schema.minLength === "number") {
|
|
539
|
+
stringSchema = stringSchema.min(schema.minLength);
|
|
540
|
+
}
|
|
541
|
+
if (typeof schema.maxLength === "number") {
|
|
542
|
+
stringSchema = stringSchema.max(schema.maxLength);
|
|
543
|
+
}
|
|
544
|
+
if (schema.pattern) {
|
|
545
|
+
// JSON Schema patterns are not implicitly anchored (match anywhere in string)
|
|
546
|
+
stringSchema = stringSchema.regex(new RegExp(schema.pattern));
|
|
547
|
+
}
|
|
548
|
+
yatspSchema = stringSchema;
|
|
549
|
+
break;
|
|
550
|
+
}
|
|
551
|
+
case "number":
|
|
552
|
+
case "integer": {
|
|
553
|
+
let numberSchema = type === "integer" ? z.number().int() : z.number();
|
|
554
|
+
// Apply constraints
|
|
555
|
+
// In draft-04, `exclusiveMinimum: true` makes the sibling `minimum` exclusive rather than an independent bound, so the inclusive `.min()` is skipped; emitting it too would be dominated by the exclusive check and report a second, weaker issue.
|
|
556
|
+
if (typeof schema.minimum === "number" && schema.exclusiveMinimum !== true) {
|
|
557
|
+
numberSchema = numberSchema.min(schema.minimum);
|
|
558
|
+
}
|
|
559
|
+
if (typeof schema.maximum === "number" && schema.exclusiveMaximum !== true) {
|
|
560
|
+
numberSchema = numberSchema.max(schema.maximum);
|
|
561
|
+
}
|
|
562
|
+
if (typeof schema.exclusiveMinimum === "number") {
|
|
563
|
+
numberSchema = numberSchema.gt(schema.exclusiveMinimum);
|
|
564
|
+
}
|
|
565
|
+
else if (schema.exclusiveMinimum === true && typeof schema.minimum === "number") {
|
|
566
|
+
numberSchema = numberSchema.gt(schema.minimum);
|
|
567
|
+
}
|
|
568
|
+
if (typeof schema.exclusiveMaximum === "number") {
|
|
569
|
+
numberSchema = numberSchema.lt(schema.exclusiveMaximum);
|
|
570
|
+
}
|
|
571
|
+
else if (schema.exclusiveMaximum === true && typeof schema.maximum === "number") {
|
|
572
|
+
numberSchema = numberSchema.lt(schema.maximum);
|
|
573
|
+
}
|
|
574
|
+
if (typeof schema.multipleOf === "number") {
|
|
575
|
+
numberSchema = numberSchema.multipleOf(schema.multipleOf);
|
|
576
|
+
}
|
|
577
|
+
yatspSchema = numberSchema;
|
|
578
|
+
break;
|
|
579
|
+
}
|
|
580
|
+
case "boolean": {
|
|
581
|
+
yatspSchema = z.boolean();
|
|
582
|
+
break;
|
|
583
|
+
}
|
|
584
|
+
case "null": {
|
|
585
|
+
yatspSchema = z.null();
|
|
586
|
+
break;
|
|
587
|
+
}
|
|
588
|
+
case "object": {
|
|
589
|
+
const shape = {};
|
|
590
|
+
const properties = schema.properties || {};
|
|
591
|
+
const requiredSet = new Set(schema.required || []);
|
|
592
|
+
const additionalSchema = typeof schema.additionalProperties === "object"
|
|
593
|
+
? convertSchema(schema.additionalProperties, ctx)
|
|
594
|
+
: undefined;
|
|
595
|
+
// Convert properties - mark optional ones
|
|
596
|
+
for (const [key, propSchema] of Object.entries(properties)) {
|
|
597
|
+
const propYatspSchema = convertSchema(propSchema, ctx);
|
|
598
|
+
// If not in required array, make it optional. assignProp so a __proto__ key becomes an own property instead of hitting the inherited setter
|
|
599
|
+
assignProp(shape, key, requiredSet.has(key) ? propYatspSchema : propYatspSchema.optional());
|
|
600
|
+
}
|
|
601
|
+
// Handle patternProperties
|
|
602
|
+
if (schema.patternProperties) {
|
|
603
|
+
// patternProperties: keys matching pattern must satisfy corresponding schema. Use loose records so non-matching keys pass through
|
|
604
|
+
const patternProps = schema.patternProperties;
|
|
605
|
+
const patternKeys = Object.keys(patternProps);
|
|
606
|
+
const looseRecords = [];
|
|
607
|
+
for (const pattern of patternKeys) {
|
|
608
|
+
const patternValue = convertSchema(patternProps[pattern], ctx);
|
|
609
|
+
const keySchema = z.string().regex(new RegExp(pattern));
|
|
610
|
+
looseRecords.push(z.looseRecord(keySchema, patternValue));
|
|
611
|
+
}
|
|
612
|
+
// Build intersection: object schema + all pattern property records
|
|
613
|
+
const schemasToIntersect = [];
|
|
614
|
+
if (Object.keys(shape).length > 0) {
|
|
615
|
+
// Use passthrough so patternProperties can validate additional keys
|
|
616
|
+
schemasToIntersect.push(z.object(shape).passthrough());
|
|
617
|
+
}
|
|
618
|
+
schemasToIntersect.push(...looseRecords);
|
|
619
|
+
if (schemasToIntersect.length === 0) {
|
|
620
|
+
yatspSchema = z.object({}).passthrough();
|
|
621
|
+
}
|
|
622
|
+
else if (schemasToIntersect.length === 1) {
|
|
623
|
+
yatspSchema = schemasToIntersect[0];
|
|
624
|
+
}
|
|
625
|
+
else {
|
|
626
|
+
// Chain intersections: (A & B) & C & D ...
|
|
627
|
+
let result = z.intersection(schemasToIntersect[0], schemasToIntersect[1]);
|
|
628
|
+
for (let i = 2; i < schemasToIntersect.length; i++) {
|
|
629
|
+
result = z.intersection(result, schemasToIntersect[i]);
|
|
630
|
+
}
|
|
631
|
+
yatspSchema = result;
|
|
632
|
+
}
|
|
633
|
+
// When additionalProperties is false, reject keys that are neither defined in properties nor matched by any patternProperty.
|
|
634
|
+
if (schema.additionalProperties === false) {
|
|
635
|
+
const propertyKeys = Object.keys(shape);
|
|
636
|
+
const patterns = patternKeys.map((p) => new RegExp(p));
|
|
637
|
+
const basePatternSchema = yatspSchema;
|
|
638
|
+
yatspSchema = yatspSchema.check((payload) => {
|
|
639
|
+
if (!isPlainObject(payload.value))
|
|
640
|
+
return;
|
|
641
|
+
const unrecognized = [];
|
|
642
|
+
for (const key of Object.keys(payload.value)) {
|
|
643
|
+
if (propertyKeys.includes(key))
|
|
644
|
+
continue;
|
|
645
|
+
if (patterns.some((regex) => regex.test(key)))
|
|
646
|
+
continue;
|
|
647
|
+
unrecognized.push(key);
|
|
648
|
+
}
|
|
649
|
+
if (unrecognized.length) {
|
|
650
|
+
payload.issues.push({
|
|
651
|
+
code: "unrecognized_keys",
|
|
652
|
+
keys: unrecognized,
|
|
653
|
+
input: payload.value,
|
|
654
|
+
inst: basePatternSchema,
|
|
655
|
+
});
|
|
656
|
+
}
|
|
657
|
+
});
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
else {
|
|
661
|
+
// Handle additionalProperties. In JSON Schema, additionalProperties defaults to true (allow any extra properties). In Yatsp, objects strip unknown keys by default, so we need to handle this explicitly
|
|
662
|
+
const objectSchema = z.object(shape);
|
|
663
|
+
if (schema.additionalProperties === false) {
|
|
664
|
+
// Strict mode - no extra properties allowed
|
|
665
|
+
yatspSchema = objectSchema.strict();
|
|
666
|
+
}
|
|
667
|
+
else if (additionalSchema) {
|
|
668
|
+
// Extra properties must match the specified schema
|
|
669
|
+
yatspSchema = objectSchema.catchall(additionalSchema);
|
|
670
|
+
}
|
|
671
|
+
else {
|
|
672
|
+
// additionalProperties is true or undefined - allow any extra properties (passthrough)
|
|
673
|
+
yatspSchema = objectSchema.passthrough();
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
// propertyNames constrains key *names* only, and says nothing about which keys are required or how their values validate. Layering it on top of the result keeps properties/patternProperties/additionalProperties composing underneath. `true` allows every name, so it needs no guard.
|
|
677
|
+
const hasKeyGuard = schema.propertyNames !== undefined && schema.propertyNames !== true;
|
|
678
|
+
const minProperties = typeof schema.minProperties === "number" ? schema.minProperties : undefined;
|
|
679
|
+
const maxProperties = typeof schema.maxProperties === "number" ? schema.maxProperties : undefined;
|
|
680
|
+
if (hasKeyGuard || minProperties !== undefined || maxProperties !== undefined) {
|
|
681
|
+
let keySchema;
|
|
682
|
+
if (hasKeyGuard) {
|
|
683
|
+
// Keys are always strings, so a propertyNames subschema that omits `type` still constrains them — without this it would convert to z.any().
|
|
684
|
+
const keyJSONSchema = typeof schema.propertyNames === "object" && schema.propertyNames.type === undefined
|
|
685
|
+
? { type: "string", ...schema.propertyNames }
|
|
686
|
+
: schema.propertyNames;
|
|
687
|
+
keySchema = convertSchema(keyJSONSchema, ctx);
|
|
688
|
+
}
|
|
689
|
+
yatspSchema = checkObjectGuards(yatspSchema, { keySchema, minProperties, maxProperties });
|
|
690
|
+
}
|
|
691
|
+
break;
|
|
692
|
+
}
|
|
693
|
+
case "array": {
|
|
694
|
+
// Check if this is a tuple (prefixItems or items as array)
|
|
695
|
+
const prefixItems = schema.prefixItems;
|
|
696
|
+
const items = schema.items;
|
|
697
|
+
if (prefixItems && Array.isArray(prefixItems)) {
|
|
698
|
+
// Tuple with prefixItems (draft-2020-12)
|
|
699
|
+
const minItems = typeof schema.minItems === "number" ? schema.minItems : 0;
|
|
700
|
+
const tupleItems = prefixItems.map((item) => convertSchema(item, ctx));
|
|
701
|
+
const positionalItems = applyMinItems(tupleItems, minItems);
|
|
702
|
+
const rest = !Array.isArray(items) ? getTupleRest(items, ctx) : undefined;
|
|
703
|
+
const tupleSchema = z.tuple(positionalItems);
|
|
704
|
+
yatspSchema = rest ? tupleSchema.rest(rest) : tupleSchema;
|
|
705
|
+
// Apply minItems/maxItems constraints to tuples
|
|
706
|
+
if (typeof schema.minItems === "number") {
|
|
707
|
+
yatspSchema = yatspSchema.check(z.minLength(schema.minItems));
|
|
708
|
+
}
|
|
709
|
+
if (typeof schema.maxItems === "number") {
|
|
710
|
+
yatspSchema = yatspSchema.check(z.maxLength(schema.maxItems));
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
else if (Array.isArray(items)) {
|
|
714
|
+
// Tuple with items array (draft-7)
|
|
715
|
+
const minItems = typeof schema.minItems === "number" ? schema.minItems : 0;
|
|
716
|
+
const tupleItems = items.map((item) => convertSchema(item, ctx));
|
|
717
|
+
const positionalItems = applyMinItems(tupleItems, minItems);
|
|
718
|
+
const rest = getTupleRest(schema.additionalItems, ctx);
|
|
719
|
+
const tupleSchema = z.tuple(positionalItems);
|
|
720
|
+
yatspSchema = rest ? tupleSchema.rest(rest) : tupleSchema;
|
|
721
|
+
// Apply minItems/maxItems constraints to tuples
|
|
722
|
+
if (typeof schema.minItems === "number") {
|
|
723
|
+
yatspSchema = yatspSchema.check(z.minLength(schema.minItems));
|
|
724
|
+
}
|
|
725
|
+
if (typeof schema.maxItems === "number") {
|
|
726
|
+
yatspSchema = yatspSchema.check(z.maxLength(schema.maxItems));
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
else if (items !== undefined) {
|
|
730
|
+
// Regular array
|
|
731
|
+
const element = convertSchema(items, ctx);
|
|
732
|
+
let arraySchema = z.array(element);
|
|
733
|
+
// Apply constraints
|
|
734
|
+
if (typeof schema.minItems === "number") {
|
|
735
|
+
arraySchema = arraySchema.min(schema.minItems);
|
|
736
|
+
}
|
|
737
|
+
if (typeof schema.maxItems === "number") {
|
|
738
|
+
arraySchema = arraySchema.max(schema.maxItems);
|
|
739
|
+
}
|
|
740
|
+
yatspSchema = arraySchema;
|
|
741
|
+
}
|
|
742
|
+
else {
|
|
743
|
+
// No items specified - array of any
|
|
744
|
+
yatspSchema = z.array(z.any());
|
|
745
|
+
}
|
|
746
|
+
// minContains/maxContains only constrain anything when `contains` itself is present
|
|
747
|
+
if (schema.uniqueItems === true || schema.contains !== undefined) {
|
|
748
|
+
yatspSchema = checkArrayGuards(yatspSchema, {
|
|
749
|
+
uniqueItems: schema.uniqueItems === true,
|
|
750
|
+
containsSchema: schema.contains !== undefined ? convertSchema(schema.contains, ctx) : undefined,
|
|
751
|
+
minContains: typeof schema.minContains === "number" ? schema.minContains : undefined,
|
|
752
|
+
maxContains: typeof schema.maxContains === "number" ? schema.maxContains : undefined,
|
|
753
|
+
});
|
|
754
|
+
}
|
|
755
|
+
break;
|
|
756
|
+
}
|
|
757
|
+
default:
|
|
758
|
+
throw new Error(`Unsupported type: ${type}`);
|
|
759
|
+
}
|
|
760
|
+
return yatspSchema;
|
|
761
|
+
}
|
|
762
|
+
function convertSchema(schema, ctx) {
|
|
763
|
+
if (typeof schema === "boolean") {
|
|
764
|
+
return schema ? z.any() : z.never();
|
|
765
|
+
}
|
|
766
|
+
// Convert base schema first (ignoring composition keywords)
|
|
767
|
+
let baseSchema = convertBaseSchema(schema, ctx);
|
|
768
|
+
const hasExplicitType = schema.type || schema.enum !== undefined || schema.const !== undefined;
|
|
769
|
+
// Process composition keywords LAST (they can appear together)
|
|
770
|
+
// Handle anyOf - wrap base schema with union
|
|
771
|
+
if (schema.anyOf && Array.isArray(schema.anyOf)) {
|
|
772
|
+
const options = schema.anyOf.map((s) => convertSchema(s, ctx));
|
|
773
|
+
const anyOfUnion = z.union(options);
|
|
774
|
+
baseSchema = hasExplicitType ? z.intersection(baseSchema, anyOfUnion) : anyOfUnion;
|
|
775
|
+
}
|
|
776
|
+
// Handle oneOf - exclusive union (exactly one must match)
|
|
777
|
+
if (schema.oneOf && Array.isArray(schema.oneOf)) {
|
|
778
|
+
const options = schema.oneOf.map((s) => convertSchema(s, ctx));
|
|
779
|
+
const oneOfUnion = z.xor(options);
|
|
780
|
+
baseSchema = hasExplicitType ? z.intersection(baseSchema, oneOfUnion) : oneOfUnion;
|
|
781
|
+
}
|
|
782
|
+
// Handle allOf - wrap base schema with intersection
|
|
783
|
+
if (schema.allOf && Array.isArray(schema.allOf)) {
|
|
784
|
+
if (schema.allOf.length === 0) {
|
|
785
|
+
baseSchema = hasExplicitType ? baseSchema : z.any();
|
|
786
|
+
}
|
|
787
|
+
else {
|
|
788
|
+
let result = hasExplicitType ? baseSchema : convertSchema(schema.allOf[0], ctx);
|
|
789
|
+
const startIdx = hasExplicitType ? 0 : 1;
|
|
790
|
+
for (let i = startIdx; i < schema.allOf.length; i++) {
|
|
791
|
+
result = z.intersection(result, convertSchema(schema.allOf[i], ctx));
|
|
792
|
+
}
|
|
793
|
+
baseSchema = result;
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
// Handle nullable (OpenAPI 3.0)
|
|
797
|
+
if (schema.nullable === true && ctx.version === "openapi-3.0") {
|
|
798
|
+
baseSchema = z.nullable(baseSchema);
|
|
799
|
+
}
|
|
800
|
+
// Handle readOnly
|
|
801
|
+
if (schema.readOnly === true) {
|
|
802
|
+
baseSchema = z.readonly(baseSchema);
|
|
803
|
+
}
|
|
804
|
+
// Apply `default` so it wraps the fully-composed schema. This ensures `parse(undefined) -> default` works regardless of which branch of `convertBaseSchema` produced the inner schema (enum/const/not/typed/etc.).
|
|
805
|
+
if (schema.default !== undefined) {
|
|
806
|
+
baseSchema = baseSchema.default(schema.default);
|
|
807
|
+
}
|
|
808
|
+
// Collect non-description annotation metadata into the user-supplied registry. Description is handled separately below via `.describe()` to preserve the contract that `schema.description` reads from globalRegistry.
|
|
809
|
+
const extraMeta = {};
|
|
810
|
+
const coreMetadataKeys = ["$id", "id", "$comment", "$anchor", "$vocabulary", "$dynamicRef", "$dynamicAnchor"];
|
|
811
|
+
for (const key of coreMetadataKeys) {
|
|
812
|
+
if (key in schema) {
|
|
813
|
+
extraMeta[key] = schema[key];
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
const contentMetadataKeys = ["contentEncoding", "contentMediaType", "contentSchema"];
|
|
817
|
+
for (const key of contentMetadataKeys) {
|
|
818
|
+
if (key in schema) {
|
|
819
|
+
extraMeta[key] = schema[key];
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
// `propertyNames` and `contains` are enforced by a guard, which `toJSONSchema` cannot infer, so the original keyword is carried as metadata to keep the round-trip lossless. Only where it was actually applied: on any other type it is inert, and on a `$ref` the metadata would land on the target every reference shares. A carried subschema is copied verbatim while the root `$defs` stay behind, so one holding a `$ref` is dropped rather than emitted as a dangling reference.
|
|
823
|
+
if (schema.type === "object" && schema.$ref === undefined) {
|
|
824
|
+
if (schema.propertyNames !== undefined && !containsRef(schema.propertyNames)) {
|
|
825
|
+
extraMeta.propertyNames = schema.propertyNames;
|
|
826
|
+
}
|
|
827
|
+
for (const key of ["minProperties", "maxProperties"]) {
|
|
828
|
+
if (schema[key] !== undefined)
|
|
829
|
+
extraMeta[key] = schema[key];
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
if (schema.type === "array" && schema.$ref === undefined) {
|
|
833
|
+
if (schema.contains !== undefined && !containsRef(schema.contains)) {
|
|
834
|
+
extraMeta.contains = schema.contains;
|
|
835
|
+
}
|
|
836
|
+
for (const key of ["uniqueItems", "minContains", "maxContains"]) {
|
|
837
|
+
if (schema[key] !== undefined)
|
|
838
|
+
extraMeta[key] = schema[key];
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
for (const key of Object.keys(schema)) {
|
|
842
|
+
if (!RECOGNIZED_KEYS.has(key)) {
|
|
843
|
+
assignProp(extraMeta, key, schema[key]);
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
if (Object.keys(extraMeta).length > 0) {
|
|
847
|
+
ctx.registry.add(baseSchema, extraMeta);
|
|
848
|
+
}
|
|
849
|
+
// Apply description last. `.describe()` clones the schema and sets `_yatsp.parent` on the clone, so registry lookups on the returned reference still resolve `extraMeta` via parent inheritance.
|
|
850
|
+
if (schema.description) {
|
|
851
|
+
baseSchema = baseSchema.describe(schema.description);
|
|
852
|
+
}
|
|
853
|
+
return baseSchema;
|
|
854
|
+
}
|
|
855
|
+
/**
|
|
856
|
+
* Converts a JSON Schema to a Yatsp schema. This function should be considered semi-experimental. It's behavior is liable to change. */
|
|
857
|
+
export function fromJSONSchema(schema, params) {
|
|
858
|
+
// Handle boolean schemas
|
|
859
|
+
if (typeof schema === "boolean") {
|
|
860
|
+
return schema ? z.any() : z.never();
|
|
861
|
+
}
|
|
862
|
+
// Normalize input via a JSON round-trip. This guarantees the converter walks a plain, finite, JSON-valid object graph: cyclic inputs fail here, getter/Proxy-based properties are materialized into static values, and class instances collapse to plain objects.
|
|
863
|
+
let normalized;
|
|
864
|
+
try {
|
|
865
|
+
normalized = JSON.parse(JSON.stringify(schema));
|
|
866
|
+
}
|
|
867
|
+
catch {
|
|
868
|
+
throw new Error("fromJSONSchema input is not valid JSON (possibly cyclic); use $defs/$ref for recursive schemas");
|
|
869
|
+
}
|
|
870
|
+
const version = detectVersion(normalized, params?.defaultTarget);
|
|
871
|
+
const defs = (normalized.$defs || normalized.definitions || {});
|
|
872
|
+
const ctx = {
|
|
873
|
+
version,
|
|
874
|
+
defs,
|
|
875
|
+
refs: new Map(),
|
|
876
|
+
processing: new Set(),
|
|
877
|
+
rootSchema: normalized,
|
|
878
|
+
registry: params?.registry ?? globalRegistry,
|
|
879
|
+
};
|
|
880
|
+
return convertSchema(normalized, ctx);
|
|
881
|
+
}
|