@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,2994 @@
|
|
|
1
|
+
import type { $YatspBigIntFormats } from "../core/checks.js";
|
|
2
|
+
import * as core from "../core/index.js";
|
|
3
|
+
import { util, type $YatspNumberFormats } from "../core/index.js";
|
|
4
|
+
import * as processors from "../core/json-schema-processors.js";
|
|
5
|
+
import * as regexes from "../core/regexes.js";
|
|
6
|
+
import type { StandardSchemaWithJSONProps } from "../core/standard-schema.js";
|
|
7
|
+
import { createStandardJSONSchemaMethod, createToJSONSchemaMethod } from "../core/to-json-schema.js";
|
|
8
|
+
import en from "../locales/en.js";
|
|
9
|
+
|
|
10
|
+
import * as checks from "./checks.js";
|
|
11
|
+
import * as parse from "./parse.js";
|
|
12
|
+
|
|
13
|
+
// Register English as the default locale on first YatspType construction. Hooked into the `YatspType` `$constructor` (rather than a top-level `config(en())` in `external.ts`) so bundlers honoring `sideEffects: false` can't tree-shake it out — see #5953, #5725. An explicit `z.config(z.locales.xx())` call wins regardless of order, since this only sets the default when none is present.
|
|
14
|
+
function _ensureDefaultLocale(): void {
|
|
15
|
+
if (!core.globalConfig.localeError) core.config(en());
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// the default memoizer is read by the core container init, which runs before `YatspType.init`, so each container calls this first
|
|
19
|
+
function _ensureDefaultMemoizer(): void {
|
|
20
|
+
if (!core.globalConfig.memoizer) core.config({ memoizer: core.memoizer() });
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Methods live on each concrete constructor's prototype and materialize per instance on first access, so a schema only pays for what it is asked for.
|
|
24
|
+
|
|
25
|
+
///////////////////////////////////////////
|
|
26
|
+
///////////////////////////////////////////
|
|
27
|
+
//////////// ////////////
|
|
28
|
+
//////////// YatspType ////////////
|
|
29
|
+
//////////// ////////////
|
|
30
|
+
///////////////////////////////////////////
|
|
31
|
+
///////////////////////////////////////////
|
|
32
|
+
|
|
33
|
+
export type YatspStandardSchemaWithJSON<T> = StandardSchemaWithJSONProps<core.input<T>, core.output<T>>;
|
|
34
|
+
export interface YatspType<
|
|
35
|
+
out Output = unknown,
|
|
36
|
+
out Input = unknown,
|
|
37
|
+
out Internals extends core.$YatspTypeInternals<Output, Input> = core.$YatspTypeInternals<Output, Input>,
|
|
38
|
+
> extends core.$YatspType<Output, Input, Internals> {
|
|
39
|
+
def: Internals["def"];
|
|
40
|
+
type: Internals["def"]["type"];
|
|
41
|
+
|
|
42
|
+
/** @deprecated Use `.def` instead. */
|
|
43
|
+
_def: Internals["def"];
|
|
44
|
+
/** @deprecated Use `z.output<typeof schema>` instead. */
|
|
45
|
+
_output: Internals["output"];
|
|
46
|
+
/** @deprecated Use `z.input<typeof schema>` instead. */
|
|
47
|
+
_input: Internals["input"];
|
|
48
|
+
|
|
49
|
+
"~standard": YatspStandardSchemaWithJSON<this>;
|
|
50
|
+
/** Converts this schema to a JSON Schema representation. */
|
|
51
|
+
toJSONSchema(params?: core.ToJSONSchemaParams): core.YatspStandardJSONSchemaPayload<this>;
|
|
52
|
+
|
|
53
|
+
// base methods
|
|
54
|
+
check(...checks: (core.CheckFn<core.output<this>> | core.$YatspCheck<core.output<this>>)[]): this;
|
|
55
|
+
with(...checks: (core.CheckFn<core.output<this>> | core.$YatspCheck<core.output<this>>)[]): this;
|
|
56
|
+
clone(def?: Internals["def"], params?: { parent: boolean }): this;
|
|
57
|
+
register<R extends core.$YatspRegistry>(
|
|
58
|
+
registry: R,
|
|
59
|
+
...meta: this extends R["_schema"]
|
|
60
|
+
? undefined extends R["_meta"]
|
|
61
|
+
? [core.$replace<R["_meta"], this>?]
|
|
62
|
+
: [core.$replace<R["_meta"], this>]
|
|
63
|
+
: ["Incompatible schema"]
|
|
64
|
+
): this;
|
|
65
|
+
|
|
66
|
+
brand<T extends PropertyKey = PropertyKey, Dir extends "in" | "out" | "inout" = "out">(
|
|
67
|
+
value?: T
|
|
68
|
+
): PropertyKey extends T ? this : core.$YatspBranded<this, T, Dir>;
|
|
69
|
+
|
|
70
|
+
// parsing
|
|
71
|
+
parse(data: unknown, params?: core.ParseContext<core.$YatspIssue>): core.output<this>;
|
|
72
|
+
safeParse(data: unknown, params?: core.ParseContext<core.$YatspIssue>): parse.YatspSafeParseResult<core.output<this>>;
|
|
73
|
+
parseAsync(data: unknown, params?: core.ParseContext<core.$YatspIssue>): Promise<core.output<this>>;
|
|
74
|
+
safeParseAsync(
|
|
75
|
+
data: unknown,
|
|
76
|
+
params?: core.ParseContext<core.$YatspIssue>
|
|
77
|
+
): Promise<parse.YatspSafeParseResult<core.output<this>>>;
|
|
78
|
+
spa: (
|
|
79
|
+
data: unknown,
|
|
80
|
+
params?: core.ParseContext<core.$YatspIssue>
|
|
81
|
+
) => Promise<parse.YatspSafeParseResult<core.output<this>>>;
|
|
82
|
+
validate(data: unknown, params?: core.ParseContext<core.$YatspIssue>): data is core.input<this>;
|
|
83
|
+
validateAsync(data: unknown, params?: core.ParseContext<core.$YatspIssue>): Promise<boolean>;
|
|
84
|
+
|
|
85
|
+
// encoding/decoding
|
|
86
|
+
encode(data: core.output<this>, params?: core.ParseContext<core.$YatspIssue>): core.input<this>;
|
|
87
|
+
decode(data: core.input<this>, params?: core.ParseContext<core.$YatspIssue>): core.output<this>;
|
|
88
|
+
encodeAsync(data: core.output<this>, params?: core.ParseContext<core.$YatspIssue>): Promise<core.input<this>>;
|
|
89
|
+
decodeAsync(data: core.input<this>, params?: core.ParseContext<core.$YatspIssue>): Promise<core.output<this>>;
|
|
90
|
+
safeEncode(
|
|
91
|
+
data: core.output<this>,
|
|
92
|
+
params?: core.ParseContext<core.$YatspIssue>
|
|
93
|
+
): parse.YatspSafeParseResult<core.input<this>>;
|
|
94
|
+
safeDecode(
|
|
95
|
+
data: core.input<this>,
|
|
96
|
+
params?: core.ParseContext<core.$YatspIssue>
|
|
97
|
+
): parse.YatspSafeParseResult<core.output<this>>;
|
|
98
|
+
safeEncodeAsync(
|
|
99
|
+
data: core.output<this>,
|
|
100
|
+
params?: core.ParseContext<core.$YatspIssue>
|
|
101
|
+
): Promise<parse.YatspSafeParseResult<core.input<this>>>;
|
|
102
|
+
safeDecodeAsync(
|
|
103
|
+
data: core.input<this>,
|
|
104
|
+
params?: core.ParseContext<core.$YatspIssue>
|
|
105
|
+
): Promise<parse.YatspSafeParseResult<core.output<this>>>;
|
|
106
|
+
|
|
107
|
+
// refinements
|
|
108
|
+
refine<Ch extends (arg: core.output<this>) => unknown | Promise<unknown>>(
|
|
109
|
+
check: Ch,
|
|
110
|
+
params?: string | core.$YatspCustomParams
|
|
111
|
+
): Ch extends (arg: any) => arg is infer R ? this & YatspType<R, core.input<this>> : this;
|
|
112
|
+
superRefine(
|
|
113
|
+
refinement: (arg: core.output<this>, ctx: core.$RefinementCtx<core.output<this>>) => void | Promise<void>,
|
|
114
|
+
params?: core.$YatspSuperRefineParams
|
|
115
|
+
): this;
|
|
116
|
+
overwrite(fn: (x: core.output<this>) => core.output<this>): this;
|
|
117
|
+
|
|
118
|
+
// wrappers
|
|
119
|
+
optional(): YatspOptional<this>;
|
|
120
|
+
exactOptional(): YatspExactOptional<this>;
|
|
121
|
+
nonoptional(params?: string | core.$YatspNonOptionalParams): YatspNonOptional<this>;
|
|
122
|
+
nullable(): YatspNullable<this>;
|
|
123
|
+
nullish(): YatspOptional<YatspNullable<this>>;
|
|
124
|
+
default(def: util.NoUndefined<core.output<this>>): YatspDefault<this>;
|
|
125
|
+
default(def: () => util.NoUndefined<core.output<this>>): YatspDefault<this>;
|
|
126
|
+
prefault(def: () => core.input<this>): YatspPrefault<this>;
|
|
127
|
+
prefault(def: core.input<this>): YatspPrefault<this>;
|
|
128
|
+
array(): YatspArray<this>;
|
|
129
|
+
or<T extends core.SomeType>(option: T): YatspUnion<[this, T]>;
|
|
130
|
+
and<T extends core.SomeType>(incoming: T): YatspIntersection<this, T>;
|
|
131
|
+
transform<NewOut>(
|
|
132
|
+
transform: (arg: core.output<this>, ctx: core.$RefinementCtx<core.output<this>>) => NewOut | Promise<NewOut>
|
|
133
|
+
): YatspPipe<this, YatspTransform<Awaited<NewOut>, core.output<this>>>;
|
|
134
|
+
catch(def: core.output<this>): YatspCatch<this>;
|
|
135
|
+
catch(def: (ctx: core.$YatspCatchCtx) => core.output<this>): YatspCatch<this>;
|
|
136
|
+
pipe<T extends core.$YatspType<any, core.output<this>>>(
|
|
137
|
+
target: T | core.$YatspType<any, core.output<this>>
|
|
138
|
+
): YatspPipe<this, T>;
|
|
139
|
+
readonly(): YatspReadonly<this>;
|
|
140
|
+
|
|
141
|
+
/** Returns a new instance that has been registered in `z.globalRegistry` with the specified description */
|
|
142
|
+
describe(description: string): this;
|
|
143
|
+
description?: string;
|
|
144
|
+
/** Returns the metadata associated with this instance in `z.globalRegistry` */
|
|
145
|
+
meta(): core.$replace<core.GlobalMeta, this> | undefined;
|
|
146
|
+
/** Returns a new instance that has been registered in `z.globalRegistry` with the specified metadata */
|
|
147
|
+
meta(data: core.$replace<core.GlobalMeta, this>): this;
|
|
148
|
+
|
|
149
|
+
// helpers
|
|
150
|
+
/** @deprecated Try safe-parsing `undefined` (this is what `isOptional` does internally):
|
|
151
|
+
*
|
|
152
|
+
* ```ts
|
|
153
|
+
* const schema = z.string().optional();
|
|
154
|
+
* const isOptional = schema.safeParse(undefined).success; // true
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
isOptional(): boolean;
|
|
158
|
+
/**
|
|
159
|
+
* @deprecated Try safe-parsing `null` (this is what `isNullable` does internally):
|
|
160
|
+
*
|
|
161
|
+
* ```ts
|
|
162
|
+
* const schema = z.string().nullable();
|
|
163
|
+
* const isNullable = schema.safeParse(null).success; // true
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
isNullable(): boolean;
|
|
167
|
+
apply<T, TArgs extends unknown[] = []>(fn: (schema: this, ...args: TArgs) => T, ...args: TArgs): T;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export interface _YatspType<out Internals extends core.$YatspTypeInternals = core.$YatspTypeInternals>
|
|
171
|
+
extends YatspType<any, any, Internals> {}
|
|
172
|
+
|
|
173
|
+
export const YatspType: core.$constructor<YatspType> = /*@__PURE__*/ core.$constructor<YatspType>(
|
|
174
|
+
"YatspType",
|
|
175
|
+
(inst, def) => {
|
|
176
|
+
_ensureDefaultLocale();
|
|
177
|
+
core.$YatspType.init(inst, def);
|
|
178
|
+
|
|
179
|
+
inst.def = def;
|
|
180
|
+
inst.type = def.type;
|
|
181
|
+
|
|
182
|
+
return inst;
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
check(...chks) {
|
|
186
|
+
const def = this.def;
|
|
187
|
+
return this.clone(
|
|
188
|
+
util.mergeDefs(def, {
|
|
189
|
+
checks: [
|
|
190
|
+
...(def.checks ?? []),
|
|
191
|
+
...chks.map((ch) =>
|
|
192
|
+
typeof ch === "function" ? { _yatsp: { check: ch, def: { check: "custom" }, onattach: [] } } : ch
|
|
193
|
+
),
|
|
194
|
+
],
|
|
195
|
+
}),
|
|
196
|
+
{ parent: true }
|
|
197
|
+
);
|
|
198
|
+
},
|
|
199
|
+
with(...chks) {
|
|
200
|
+
return this.check(...chks);
|
|
201
|
+
},
|
|
202
|
+
clone(def, params) {
|
|
203
|
+
return core.clone(this, def, params);
|
|
204
|
+
},
|
|
205
|
+
brand() {
|
|
206
|
+
return this;
|
|
207
|
+
},
|
|
208
|
+
register(reg, meta) {
|
|
209
|
+
reg.add(this, meta);
|
|
210
|
+
return this;
|
|
211
|
+
},
|
|
212
|
+
refine(check, params) {
|
|
213
|
+
return this.check(refine(check, params));
|
|
214
|
+
},
|
|
215
|
+
superRefine(refinement, params) {
|
|
216
|
+
return this.check(superRefine(refinement, params));
|
|
217
|
+
},
|
|
218
|
+
overwrite(fn) {
|
|
219
|
+
return this.check(checks.overwrite(fn));
|
|
220
|
+
},
|
|
221
|
+
optional() {
|
|
222
|
+
return optional(this);
|
|
223
|
+
},
|
|
224
|
+
exactOptional() {
|
|
225
|
+
return exactOptional(this);
|
|
226
|
+
},
|
|
227
|
+
nullable() {
|
|
228
|
+
return nullable(this);
|
|
229
|
+
},
|
|
230
|
+
nullish() {
|
|
231
|
+
return optional(nullable(this));
|
|
232
|
+
},
|
|
233
|
+
nonoptional(params) {
|
|
234
|
+
return nonoptional(this, params);
|
|
235
|
+
},
|
|
236
|
+
array() {
|
|
237
|
+
return array(this);
|
|
238
|
+
},
|
|
239
|
+
or(arg) {
|
|
240
|
+
return union([this, arg]);
|
|
241
|
+
},
|
|
242
|
+
and(arg) {
|
|
243
|
+
return intersection(this, arg);
|
|
244
|
+
},
|
|
245
|
+
transform(tx) {
|
|
246
|
+
return pipe(this, transform(tx));
|
|
247
|
+
},
|
|
248
|
+
default(d) {
|
|
249
|
+
return _default(this, d);
|
|
250
|
+
},
|
|
251
|
+
prefault(d) {
|
|
252
|
+
return prefault(this, d);
|
|
253
|
+
},
|
|
254
|
+
catch(params) {
|
|
255
|
+
return _catch(this, params);
|
|
256
|
+
},
|
|
257
|
+
pipe(target) {
|
|
258
|
+
return pipe(this, target);
|
|
259
|
+
},
|
|
260
|
+
readonly() {
|
|
261
|
+
return readonly(this);
|
|
262
|
+
},
|
|
263
|
+
describe(description) {
|
|
264
|
+
const cl = this.clone();
|
|
265
|
+
core.globalRegistry.add(cl, { description });
|
|
266
|
+
return cl;
|
|
267
|
+
},
|
|
268
|
+
meta(...args: any[]): any {
|
|
269
|
+
// overloaded: meta() returns the registered metadata, meta(data) returns a clone with `data` registered. The mapped type picks up the second overload, so we accept variadic any-args and return `any` to satisfy both at runtime.
|
|
270
|
+
if (args.length === 0) return core.globalRegistry.get(this);
|
|
271
|
+
const cl = this.clone();
|
|
272
|
+
core.globalRegistry.add(cl, args[0]);
|
|
273
|
+
return cl;
|
|
274
|
+
},
|
|
275
|
+
isOptional() {
|
|
276
|
+
return this.safeParse(undefined).success;
|
|
277
|
+
},
|
|
278
|
+
isNullable() {
|
|
279
|
+
return this.safeParse(null).success;
|
|
280
|
+
},
|
|
281
|
+
apply(fn, ...args) {
|
|
282
|
+
return args.length === 0 ? fn(this) : fn(this, ...args);
|
|
283
|
+
},
|
|
284
|
+
// Overrides core's `~standard` to add `jsonSchema`. Must stay a prototype entry: redefining it per instance demotes instances to dictionary mode.
|
|
285
|
+
get "~standard"(): YatspType["~standard"] {
|
|
286
|
+
return util.hide(this, "~standard", {
|
|
287
|
+
...core.standardProps(this),
|
|
288
|
+
jsonSchema: {
|
|
289
|
+
input: createStandardJSONSchemaMethod(this, "input"),
|
|
290
|
+
output: createStandardJSONSchemaMethod(this, "output"),
|
|
291
|
+
},
|
|
292
|
+
} as YatspType["~standard"]);
|
|
293
|
+
},
|
|
294
|
+
set "~standard"(value: YatspType["~standard"]) {
|
|
295
|
+
util.own(this, "~standard", value);
|
|
296
|
+
},
|
|
297
|
+
parse: function _parse(data, params) {
|
|
298
|
+
return parse.parse(this, data, params, { callee: _parse });
|
|
299
|
+
},
|
|
300
|
+
parseAsync: async function _parseAsync(data, params) {
|
|
301
|
+
return await parse.parseAsync(this, data, params, { callee: _parseAsync });
|
|
302
|
+
},
|
|
303
|
+
safeParse(data, params) {
|
|
304
|
+
return parse.safeParse(this, data, params);
|
|
305
|
+
},
|
|
306
|
+
async safeParseAsync(data, params) {
|
|
307
|
+
return parse.safeParseAsync(this, data, params);
|
|
308
|
+
},
|
|
309
|
+
// `spa` is an alias: same function object as `safeParseAsync`, as before.
|
|
310
|
+
get spa(): YatspType["safeParseAsync"] {
|
|
311
|
+
return this?.safeParseAsync;
|
|
312
|
+
},
|
|
313
|
+
set spa(value: YatspType["safeParseAsync"]) {
|
|
314
|
+
util.own(this, "spa", value);
|
|
315
|
+
},
|
|
316
|
+
validate(data, params) {
|
|
317
|
+
return parse.validate(this, data, params);
|
|
318
|
+
},
|
|
319
|
+
validateAsync(data, params) {
|
|
320
|
+
return parse.validateAsync(this, data, params);
|
|
321
|
+
},
|
|
322
|
+
encode: function _encode(data, params) {
|
|
323
|
+
return parse.encode(this, data, params, { callee: _encode });
|
|
324
|
+
},
|
|
325
|
+
decode: function _decode(data, params) {
|
|
326
|
+
return parse.decode(this, data, params, { callee: _decode });
|
|
327
|
+
},
|
|
328
|
+
encodeAsync: async function _encodeAsync(data, params) {
|
|
329
|
+
return await parse.encodeAsync(this, data, params, { callee: _encodeAsync });
|
|
330
|
+
},
|
|
331
|
+
decodeAsync: async function _decodeAsync(data, params) {
|
|
332
|
+
return await parse.decodeAsync(this, data, params, { callee: _decodeAsync });
|
|
333
|
+
},
|
|
334
|
+
safeEncode(data, params) {
|
|
335
|
+
return parse.safeEncode(this, data, params);
|
|
336
|
+
},
|
|
337
|
+
safeDecode(data, params) {
|
|
338
|
+
return parse.safeDecode(this, data, params);
|
|
339
|
+
},
|
|
340
|
+
async safeEncodeAsync(data, params) {
|
|
341
|
+
return parse.safeEncodeAsync(this, data, params);
|
|
342
|
+
},
|
|
343
|
+
async safeDecodeAsync(data, params) {
|
|
344
|
+
return parse.safeDecodeAsync(this, data, params);
|
|
345
|
+
},
|
|
346
|
+
toJSONSchema(params) {
|
|
347
|
+
return createToJSONSchemaMethod(this, {})(params);
|
|
348
|
+
},
|
|
349
|
+
// Reads through to the registry on every access, so it must not cache.
|
|
350
|
+
get description(): string | undefined {
|
|
351
|
+
return core.globalRegistry.get(this as unknown as YatspType)?.description;
|
|
352
|
+
},
|
|
353
|
+
// No setter: `schema._def = x` throws, as it did when `_def` was a non-writable own property.
|
|
354
|
+
get _def(): core.$YatspTypeDef {
|
|
355
|
+
return (this as unknown as YatspType)._yatsp.def;
|
|
356
|
+
},
|
|
357
|
+
}
|
|
358
|
+
);
|
|
359
|
+
|
|
360
|
+
// YatspString
|
|
361
|
+
export interface _YatspString<T extends core.$YatspStringInternals<unknown> = core.$YatspStringInternals<unknown>>
|
|
362
|
+
extends _YatspType<T> {
|
|
363
|
+
format: string | null;
|
|
364
|
+
minLength: number | null;
|
|
365
|
+
maxLength: number | null;
|
|
366
|
+
|
|
367
|
+
// miscellaneous checks
|
|
368
|
+
regex(regex: RegExp, params?: string | core.$YatspCheckRegexParams): this;
|
|
369
|
+
includes(value: string, params?: string | core.$YatspCheckIncludesParams): this;
|
|
370
|
+
startsWith(value: string, params?: string | core.$YatspCheckStartsWithParams): this;
|
|
371
|
+
endsWith(value: string, params?: string | core.$YatspCheckEndsWithParams): this;
|
|
372
|
+
min(minLength: number, params?: string | core.$YatspCheckMinLengthParams): this;
|
|
373
|
+
max(maxLength: number, params?: string | core.$YatspCheckMaxLengthParams): this;
|
|
374
|
+
length(len: number, params?: string | core.$YatspCheckLengthEqualsParams): this;
|
|
375
|
+
nonempty(params?: string | core.$YatspCheckMinLengthParams): this;
|
|
376
|
+
lowercase(params?: string | core.$YatspCheckLowerCaseParams): this;
|
|
377
|
+
uppercase(params?: string | core.$YatspCheckUpperCaseParams): this;
|
|
378
|
+
|
|
379
|
+
// transforms
|
|
380
|
+
trim(): this;
|
|
381
|
+
normalize(form?: "NFC" | "NFD" | "NFKC" | "NFKD" | (string & {})): this;
|
|
382
|
+
toLowerCase(): this;
|
|
383
|
+
toUpperCase(): this;
|
|
384
|
+
slugify(): this;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/** @internal */
|
|
388
|
+
export const _YatspString: core.$constructor<_YatspString> = /*@__PURE__*/ core.$constructor<_YatspString>(
|
|
389
|
+
"_YatspString",
|
|
390
|
+
(inst, def) => {
|
|
391
|
+
core.$YatspString.init(inst, def);
|
|
392
|
+
YatspType.init(inst, def);
|
|
393
|
+
|
|
394
|
+
inst._yatsp.processJSONSchema = (ctx, json, params) => processors.stringProcessor(inst, ctx, json, params);
|
|
395
|
+
},
|
|
396
|
+
/*@__PURE__*/ util.derived<_YatspString>(
|
|
397
|
+
{
|
|
398
|
+
format: (inst) => processors.aggregateChecks(inst).format ?? null,
|
|
399
|
+
minLength: (inst) => processors.aggregateChecks<number>(inst).minimum ?? null,
|
|
400
|
+
maxLength: (inst) => processors.aggregateChecks<number>(inst).maximum ?? null,
|
|
401
|
+
},
|
|
402
|
+
{
|
|
403
|
+
regex(...args) {
|
|
404
|
+
return this.check((checks.regex as any)(...args));
|
|
405
|
+
},
|
|
406
|
+
includes(...args) {
|
|
407
|
+
return this.check((checks.includes as any)(...args));
|
|
408
|
+
},
|
|
409
|
+
startsWith(...args) {
|
|
410
|
+
return this.check((checks.startsWith as any)(...args));
|
|
411
|
+
},
|
|
412
|
+
endsWith(...args) {
|
|
413
|
+
return this.check((checks.endsWith as any)(...args));
|
|
414
|
+
},
|
|
415
|
+
min(...args) {
|
|
416
|
+
return this.check((checks.minLength as any)(...args));
|
|
417
|
+
},
|
|
418
|
+
max(...args) {
|
|
419
|
+
return this.check((checks.maxLength as any)(...args));
|
|
420
|
+
},
|
|
421
|
+
length(...args) {
|
|
422
|
+
return this.check((checks.length as any)(...args));
|
|
423
|
+
},
|
|
424
|
+
nonempty(...args) {
|
|
425
|
+
return this.check((checks.minLength as any)(1, ...args));
|
|
426
|
+
},
|
|
427
|
+
lowercase(params) {
|
|
428
|
+
return this.check(checks.lowercase(params));
|
|
429
|
+
},
|
|
430
|
+
uppercase(params) {
|
|
431
|
+
return this.check(checks.uppercase(params));
|
|
432
|
+
},
|
|
433
|
+
trim() {
|
|
434
|
+
return this.check(checks.trim());
|
|
435
|
+
},
|
|
436
|
+
normalize(...args) {
|
|
437
|
+
return this.check(checks.normalize(...args));
|
|
438
|
+
},
|
|
439
|
+
toLowerCase() {
|
|
440
|
+
return this.check(checks.toLowerCase());
|
|
441
|
+
},
|
|
442
|
+
toUpperCase() {
|
|
443
|
+
return this.check(checks.toUpperCase());
|
|
444
|
+
},
|
|
445
|
+
slugify() {
|
|
446
|
+
return this.check(checks.slugify());
|
|
447
|
+
},
|
|
448
|
+
}
|
|
449
|
+
)
|
|
450
|
+
);
|
|
451
|
+
|
|
452
|
+
export interface YatspString extends _YatspString<core.$YatspStringInternals<string>> {
|
|
453
|
+
// string format checks
|
|
454
|
+
|
|
455
|
+
/** @deprecated Use `z.email()` instead. */
|
|
456
|
+
email(params?: string | core.$YatspCheckEmailParams): this;
|
|
457
|
+
/** @deprecated Use `z.url()` instead. */
|
|
458
|
+
url(params?: string | core.$YatspCheckURLParams): this;
|
|
459
|
+
/** @deprecated Use `z.jwt()` instead. */
|
|
460
|
+
jwt(params?: string | core.$YatspCheckJWTParams): this;
|
|
461
|
+
/** @deprecated Use `z.emoji()` instead. */
|
|
462
|
+
emoji(params?: string | core.$YatspCheckEmojiParams): this;
|
|
463
|
+
/** @deprecated Use `z.guid()` instead. */
|
|
464
|
+
guid(params?: string | core.$YatspCheckGUIDParams): this;
|
|
465
|
+
/** @deprecated Use `z.uuid()` instead. */
|
|
466
|
+
uuid(params?: string | core.$YatspCheckUUIDParams): this;
|
|
467
|
+
/** @deprecated Use `z.uuid()` instead. */
|
|
468
|
+
uuidv4(params?: string | core.$YatspCheckUUIDParams): this;
|
|
469
|
+
/** @deprecated Use `z.uuid()` instead. */
|
|
470
|
+
uuidv6(params?: string | core.$YatspCheckUUIDParams): this;
|
|
471
|
+
/** @deprecated Use `z.uuid()` instead. */
|
|
472
|
+
uuidv7(params?: string | core.$YatspCheckUUIDParams): this;
|
|
473
|
+
/** @deprecated Use `z.nanoid()` instead. */
|
|
474
|
+
nanoid(params?: string | core.$YatspCheckNanoIDParams): this;
|
|
475
|
+
/** @deprecated Use `z.guid()` instead. */
|
|
476
|
+
guid(params?: string | core.$YatspCheckGUIDParams): this;
|
|
477
|
+
/**
|
|
478
|
+
* @deprecated CUID v1 is deprecated by its authors due to information leakage
|
|
479
|
+
* (timestamps embedded in the id). Use `z.cuid2()` instead.
|
|
480
|
+
* See https://github.com/paralleldrive/cuid.
|
|
481
|
+
*/
|
|
482
|
+
cuid(params?: string | core.$YatspCheckCUIDParams): this;
|
|
483
|
+
/** @deprecated Use `z.cuid2()` instead. */
|
|
484
|
+
cuid2(params?: string | core.$YatspCheckCUID2Params): this;
|
|
485
|
+
/** @deprecated Use `z.ulid()` instead. */
|
|
486
|
+
ulid(params?: string | core.$YatspCheckULIDParams): this;
|
|
487
|
+
/** @deprecated Use `z.base64()` instead. */
|
|
488
|
+
base64(params?: string | core.$YatspCheckBase64Params): this;
|
|
489
|
+
/** @deprecated Use `z.base64url()` instead. */
|
|
490
|
+
base64url(params?: string | core.$YatspCheckBase64URLParams): this;
|
|
491
|
+
// /** @deprecated Use `z.jsonString()` instead. */
|
|
492
|
+
// jsonString(params?: string | core.$YatspCheckJSONStringParams): this;
|
|
493
|
+
/** @deprecated Use `z.xid()` instead. */
|
|
494
|
+
xid(params?: string | core.$YatspCheckXIDParams): this;
|
|
495
|
+
/** @deprecated Use `z.ksuid()` instead. */
|
|
496
|
+
ksuid(params?: string | core.$YatspCheckKSUIDParams): this;
|
|
497
|
+
// /** @deprecated Use `z.ipv4()` or `z.ipv6()` instead. */
|
|
498
|
+
// ip(params?: string | (core.$YatspCheckIPv4Params & { version?: "v4" | "v6" })): YatspUnion<[this, this]>;
|
|
499
|
+
/** @deprecated Use `z.ipv4()` instead. */
|
|
500
|
+
ipv4(params?: string | core.$YatspCheckIPv4Params): this;
|
|
501
|
+
/** @deprecated Use `z.ipv6()` instead. */
|
|
502
|
+
ipv6(params?: string | core.$YatspCheckIPv6Params): this;
|
|
503
|
+
/** @deprecated Use `z.cidrv4()` instead. */
|
|
504
|
+
cidrv4(params?: string | core.$YatspCheckCIDRv4Params): this;
|
|
505
|
+
/** @deprecated Use `z.cidrv6()` instead. */
|
|
506
|
+
cidrv6(params?: string | core.$YatspCheckCIDRv6Params): this;
|
|
507
|
+
/** @deprecated Use `z.e164()` instead. */
|
|
508
|
+
e164(params?: string | core.$YatspCheckE164Params): this;
|
|
509
|
+
|
|
510
|
+
// ISO 8601 checks
|
|
511
|
+
/** @deprecated Use `z.iso.datetime()` instead. */
|
|
512
|
+
datetime(params?: string | core.$YatspCheckISODateTimeParams): this;
|
|
513
|
+
/** @deprecated Use `z.iso.date()` instead. */
|
|
514
|
+
date(params?: string | core.$YatspCheckISODateParams): this;
|
|
515
|
+
/** @deprecated Use `z.iso.time()` instead. */
|
|
516
|
+
time(
|
|
517
|
+
params?:
|
|
518
|
+
| string
|
|
519
|
+
// | {
|
|
520
|
+
// message?: string | undefined;
|
|
521
|
+
// precision?: number | null;
|
|
522
|
+
// }
|
|
523
|
+
| core.$YatspCheckISOTimeParams
|
|
524
|
+
): this;
|
|
525
|
+
/** @deprecated Use `z.iso.duration()` instead. */
|
|
526
|
+
duration(params?: string | core.$YatspCheckISODurationParams): this;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
export const YatspString: core.$constructor<YatspString> = /*@__PURE__*/ core.$constructor<YatspString>(
|
|
530
|
+
"YatspString",
|
|
531
|
+
(inst, def) => {
|
|
532
|
+
core.$YatspString.init(inst, def);
|
|
533
|
+
_YatspString.init(inst, def);
|
|
534
|
+
},
|
|
535
|
+
{
|
|
536
|
+
email(params) {
|
|
537
|
+
return this.check(core._email(YatspEmail, params));
|
|
538
|
+
},
|
|
539
|
+
url(params) {
|
|
540
|
+
return this.check(core._url(YatspURL, params));
|
|
541
|
+
},
|
|
542
|
+
jwt(params) {
|
|
543
|
+
return this.check(core._jwt(YatspJWT, params));
|
|
544
|
+
},
|
|
545
|
+
emoji(params) {
|
|
546
|
+
return this.check(core._emoji(YatspEmoji, params));
|
|
547
|
+
},
|
|
548
|
+
guid(params) {
|
|
549
|
+
return this.check(core._guid(YatspGUID, params));
|
|
550
|
+
},
|
|
551
|
+
uuid(params) {
|
|
552
|
+
return this.check(core._uuid(YatspUUID, params));
|
|
553
|
+
},
|
|
554
|
+
uuidv4(params) {
|
|
555
|
+
return this.check(core._uuidv4(YatspUUID, params));
|
|
556
|
+
},
|
|
557
|
+
uuidv6(params) {
|
|
558
|
+
return this.check(core._uuidv6(YatspUUID, params));
|
|
559
|
+
},
|
|
560
|
+
uuidv7(params) {
|
|
561
|
+
return this.check(core._uuidv7(YatspUUID, params));
|
|
562
|
+
},
|
|
563
|
+
nanoid(params) {
|
|
564
|
+
return this.check(core._nanoid(YatspNanoID, params));
|
|
565
|
+
},
|
|
566
|
+
cuid(params) {
|
|
567
|
+
return this.check(core._cuid(YatspCUID, params));
|
|
568
|
+
},
|
|
569
|
+
cuid2(params) {
|
|
570
|
+
return this.check(core._cuid2(YatspCUID2, params));
|
|
571
|
+
},
|
|
572
|
+
ulid(params) {
|
|
573
|
+
return this.check(core._ulid(YatspULID, params));
|
|
574
|
+
},
|
|
575
|
+
base64(params) {
|
|
576
|
+
return this.check(core._base64(YatspBase64, params));
|
|
577
|
+
},
|
|
578
|
+
base64url(params) {
|
|
579
|
+
return this.check(core._base64url(YatspBase64URL, params));
|
|
580
|
+
},
|
|
581
|
+
xid(params) {
|
|
582
|
+
return this.check(core._xid(YatspXID, params));
|
|
583
|
+
},
|
|
584
|
+
ksuid(params) {
|
|
585
|
+
return this.check(core._ksuid(YatspKSUID, params));
|
|
586
|
+
},
|
|
587
|
+
ipv4(params) {
|
|
588
|
+
return this.check(core._ipv4(YatspIPv4, params));
|
|
589
|
+
},
|
|
590
|
+
ipv6(params) {
|
|
591
|
+
return this.check(core._ipv6(YatspIPv6, params));
|
|
592
|
+
},
|
|
593
|
+
cidrv4(params) {
|
|
594
|
+
return this.check(core._cidrv4(YatspCIDRv4, params));
|
|
595
|
+
},
|
|
596
|
+
cidrv6(params) {
|
|
597
|
+
return this.check(core._cidrv6(YatspCIDRv6, params));
|
|
598
|
+
},
|
|
599
|
+
e164(params) {
|
|
600
|
+
return this.check(core._e164(YatspE164, params));
|
|
601
|
+
},
|
|
602
|
+
datetime(params) {
|
|
603
|
+
return this.check(core._isoDateTime(YatspISODateTime, params as any));
|
|
604
|
+
},
|
|
605
|
+
date(params) {
|
|
606
|
+
return this.check(core._isoDate(YatspISODate, params as any));
|
|
607
|
+
},
|
|
608
|
+
time(params) {
|
|
609
|
+
return this.check(core._isoTime(YatspISOTime, params as any));
|
|
610
|
+
},
|
|
611
|
+
duration(params) {
|
|
612
|
+
return this.check(core._isoDuration(YatspISODuration, params as any));
|
|
613
|
+
},
|
|
614
|
+
}
|
|
615
|
+
);
|
|
616
|
+
|
|
617
|
+
export function string(params?: string | core.$YatspStringParams): YatspString;
|
|
618
|
+
export function string<T extends string>(params?: string | core.$YatspStringParams): core.$YatspType<T, T>;
|
|
619
|
+
export function string(params?: string | core.$YatspStringParams): YatspString {
|
|
620
|
+
return core._string(YatspString, params);
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
// YatspStringFormat
|
|
624
|
+
export interface YatspStringFormat<Format extends string = string>
|
|
625
|
+
extends _YatspString<core.$YatspStringFormatInternals<Format>> {}
|
|
626
|
+
export const YatspStringFormat: core.$constructor<YatspStringFormat> = /*@__PURE__*/ core.$constructor(
|
|
627
|
+
"YatspStringFormat",
|
|
628
|
+
(inst, def) => {
|
|
629
|
+
core.$YatspStringFormat.init(inst, def);
|
|
630
|
+
_YatspString.init(inst, def);
|
|
631
|
+
}
|
|
632
|
+
);
|
|
633
|
+
|
|
634
|
+
//////////////////////////////////////////////
|
|
635
|
+
//////////////////////////////////////////////
|
|
636
|
+
////////// //////////
|
|
637
|
+
////////// YatspISODateTime //////////
|
|
638
|
+
////////// //////////
|
|
639
|
+
//////////////////////////////////////////////
|
|
640
|
+
//////////////////////////////////////////////
|
|
641
|
+
export interface YatspISODateTime extends YatspStringFormat {
|
|
642
|
+
_yatsp: core.$YatspISODateTimeInternals;
|
|
643
|
+
}
|
|
644
|
+
export const YatspISODateTime: core.$constructor<YatspISODateTime> = /*@__PURE__*/ core.$constructor(
|
|
645
|
+
"YatspISODateTime",
|
|
646
|
+
(inst, def) => {
|
|
647
|
+
core.$YatspISODateTime.init(inst, def);
|
|
648
|
+
YatspStringFormat.init(inst, def);
|
|
649
|
+
}
|
|
650
|
+
);
|
|
651
|
+
|
|
652
|
+
//////////////////////////////////////////
|
|
653
|
+
//////////////////////////////////////////
|
|
654
|
+
////////// //////////
|
|
655
|
+
////////// YatspISODate //////////
|
|
656
|
+
////////// //////////
|
|
657
|
+
//////////////////////////////////////////
|
|
658
|
+
//////////////////////////////////////////
|
|
659
|
+
export interface YatspISODate extends YatspStringFormat {
|
|
660
|
+
_yatsp: core.$YatspISODateInternals;
|
|
661
|
+
}
|
|
662
|
+
export const YatspISODate: core.$constructor<YatspISODate> = /*@__PURE__*/ core.$constructor(
|
|
663
|
+
"YatspISODate",
|
|
664
|
+
(inst, def) => {
|
|
665
|
+
core.$YatspISODate.init(inst, def);
|
|
666
|
+
YatspStringFormat.init(inst, def);
|
|
667
|
+
}
|
|
668
|
+
);
|
|
669
|
+
|
|
670
|
+
//////////////////////////////////////////
|
|
671
|
+
//////////////////////////////////////////
|
|
672
|
+
////////// //////////
|
|
673
|
+
////////// YatspISOTime //////////
|
|
674
|
+
////////// //////////
|
|
675
|
+
//////////////////////////////////////////
|
|
676
|
+
//////////////////////////////////////////
|
|
677
|
+
export interface YatspISOTime extends YatspStringFormat {
|
|
678
|
+
_yatsp: core.$YatspISOTimeInternals;
|
|
679
|
+
}
|
|
680
|
+
export const YatspISOTime: core.$constructor<YatspISOTime> = /*@__PURE__*/ core.$constructor(
|
|
681
|
+
"YatspISOTime",
|
|
682
|
+
(inst, def) => {
|
|
683
|
+
core.$YatspISOTime.init(inst, def);
|
|
684
|
+
YatspStringFormat.init(inst, def);
|
|
685
|
+
}
|
|
686
|
+
);
|
|
687
|
+
|
|
688
|
+
//////////////////////////////////////////////
|
|
689
|
+
//////////////////////////////////////////////
|
|
690
|
+
////////// //////////
|
|
691
|
+
////////// YatspISODuration //////////
|
|
692
|
+
////////// //////////
|
|
693
|
+
//////////////////////////////////////////////
|
|
694
|
+
//////////////////////////////////////////////
|
|
695
|
+
export interface YatspISODuration extends YatspStringFormat {
|
|
696
|
+
_yatsp: core.$YatspISODurationInternals;
|
|
697
|
+
}
|
|
698
|
+
export const YatspISODuration: core.$constructor<YatspISODuration> = /*@__PURE__*/ core.$constructor(
|
|
699
|
+
"YatspISODuration",
|
|
700
|
+
(inst, def) => {
|
|
701
|
+
core.$YatspISODuration.init(inst, def);
|
|
702
|
+
YatspStringFormat.init(inst, def);
|
|
703
|
+
}
|
|
704
|
+
);
|
|
705
|
+
|
|
706
|
+
// YatspEmail
|
|
707
|
+
export interface YatspEmail extends YatspStringFormat<"email"> {
|
|
708
|
+
_yatsp: core.$YatspEmailInternals;
|
|
709
|
+
}
|
|
710
|
+
export const YatspEmail: core.$constructor<YatspEmail> = /*@__PURE__*/ core.$constructor("YatspEmail", (inst, def) => {
|
|
711
|
+
// YatspStringFormat.init(inst, def);
|
|
712
|
+
core.$YatspEmail.init(inst, def);
|
|
713
|
+
YatspStringFormat.init(inst, def);
|
|
714
|
+
});
|
|
715
|
+
|
|
716
|
+
export function email(params?: string | core.$YatspEmailParams): YatspEmail {
|
|
717
|
+
return core._email(YatspEmail, params);
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
// YatspGUID
|
|
721
|
+
export interface YatspGUID extends YatspStringFormat<"guid"> {
|
|
722
|
+
_yatsp: core.$YatspGUIDInternals;
|
|
723
|
+
}
|
|
724
|
+
export const YatspGUID: core.$constructor<YatspGUID> = /*@__PURE__*/ core.$constructor("YatspGUID", (inst, def) => {
|
|
725
|
+
// YatspStringFormat.init(inst, def);
|
|
726
|
+
core.$YatspGUID.init(inst, def);
|
|
727
|
+
YatspStringFormat.init(inst, def);
|
|
728
|
+
});
|
|
729
|
+
|
|
730
|
+
export function guid(params?: string | core.$YatspGUIDParams): YatspGUID {
|
|
731
|
+
return core._guid(YatspGUID, params);
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
// YatspUUID
|
|
735
|
+
export interface YatspUUID extends YatspStringFormat<"uuid"> {
|
|
736
|
+
_yatsp: core.$YatspUUIDInternals;
|
|
737
|
+
}
|
|
738
|
+
export const YatspUUID: core.$constructor<YatspUUID> = /*@__PURE__*/ core.$constructor("YatspUUID", (inst, def) => {
|
|
739
|
+
// YatspStringFormat.init(inst, def);
|
|
740
|
+
core.$YatspUUID.init(inst, def);
|
|
741
|
+
YatspStringFormat.init(inst, def);
|
|
742
|
+
});
|
|
743
|
+
|
|
744
|
+
export function uuid(params?: string | core.$YatspUUIDParams): YatspUUID {
|
|
745
|
+
return core._uuid(YatspUUID, params);
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
export function uuidv4(params?: string | core.$YatspUUIDv4Params): YatspUUID {
|
|
749
|
+
return core._uuidv4(YatspUUID, params);
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
// YatspUUIDv6
|
|
753
|
+
|
|
754
|
+
export function uuidv6(params?: string | core.$YatspUUIDv6Params): YatspUUID {
|
|
755
|
+
return core._uuidv6(YatspUUID, params);
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
// YatspUUIDv7
|
|
759
|
+
|
|
760
|
+
export function uuidv7(params?: string | core.$YatspUUIDv7Params): YatspUUID {
|
|
761
|
+
return core._uuidv7(YatspUUID, params);
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
// YatspURL
|
|
765
|
+
export interface YatspURL extends YatspStringFormat<"url"> {
|
|
766
|
+
_yatsp: core.$YatspURLInternals;
|
|
767
|
+
}
|
|
768
|
+
export const YatspURL: core.$constructor<YatspURL> = /*@__PURE__*/ core.$constructor("YatspURL", (inst, def) => {
|
|
769
|
+
// YatspStringFormat.init(inst, def);
|
|
770
|
+
core.$YatspURL.init(inst, def);
|
|
771
|
+
YatspStringFormat.init(inst, def);
|
|
772
|
+
});
|
|
773
|
+
|
|
774
|
+
export function url(params?: string | core.$YatspURLParams): YatspURL {
|
|
775
|
+
return core._url(YatspURL, params);
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
export function httpUrl(params?: string | Omit<core.$YatspURLParams, "protocol" | "hostname">): YatspURL {
|
|
779
|
+
return core._url(YatspURL, {
|
|
780
|
+
protocol: regexes.httpProtocol,
|
|
781
|
+
hostname: regexes.domain,
|
|
782
|
+
...util.normalizeParams(params),
|
|
783
|
+
});
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
// YatspEmoji
|
|
787
|
+
export interface YatspEmoji extends YatspStringFormat<"emoji"> {
|
|
788
|
+
_yatsp: core.$YatspEmojiInternals;
|
|
789
|
+
}
|
|
790
|
+
export const YatspEmoji: core.$constructor<YatspEmoji> = /*@__PURE__*/ core.$constructor("YatspEmoji", (inst, def) => {
|
|
791
|
+
// YatspStringFormat.init(inst, def);
|
|
792
|
+
core.$YatspEmoji.init(inst, def);
|
|
793
|
+
YatspStringFormat.init(inst, def);
|
|
794
|
+
});
|
|
795
|
+
|
|
796
|
+
export function emoji(params?: string | core.$YatspEmojiParams): YatspEmoji {
|
|
797
|
+
return core._emoji(YatspEmoji, params);
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
// YatspNanoID
|
|
801
|
+
export interface YatspNanoID extends YatspStringFormat<"nanoid"> {
|
|
802
|
+
_yatsp: core.$YatspNanoIDInternals;
|
|
803
|
+
}
|
|
804
|
+
export const YatspNanoID: core.$constructor<YatspNanoID> = /*@__PURE__*/ core.$constructor(
|
|
805
|
+
"YatspNanoID",
|
|
806
|
+
(inst, def) => {
|
|
807
|
+
// YatspStringFormat.init(inst, def);
|
|
808
|
+
core.$YatspNanoID.init(inst, def);
|
|
809
|
+
YatspStringFormat.init(inst, def);
|
|
810
|
+
}
|
|
811
|
+
);
|
|
812
|
+
|
|
813
|
+
export function nanoid(params?: string | core.$YatspNanoIDParams): YatspNanoID {
|
|
814
|
+
return core._nanoid(YatspNanoID, params);
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
// YatspCUID
|
|
818
|
+
/**
|
|
819
|
+
* @deprecated CUID v1 is deprecated by its authors due to information leakage
|
|
820
|
+
* (timestamps embedded in the id). Use {@link YatspCUID2} instead.
|
|
821
|
+
* See https://github.com/paralleldrive/cuid.
|
|
822
|
+
*/
|
|
823
|
+
export interface YatspCUID extends YatspStringFormat<"cuid"> {
|
|
824
|
+
_yatsp: core.$YatspCUIDInternals;
|
|
825
|
+
}
|
|
826
|
+
/**
|
|
827
|
+
* @deprecated CUID v1 is deprecated by its authors due to information leakage
|
|
828
|
+
* (timestamps embedded in the id). Use {@link YatspCUID2} instead.
|
|
829
|
+
* See https://github.com/paralleldrive/cuid.
|
|
830
|
+
*/
|
|
831
|
+
export const YatspCUID: core.$constructor<YatspCUID> = /*@__PURE__*/ core.$constructor("YatspCUID", (inst, def) => {
|
|
832
|
+
// YatspStringFormat.init(inst, def);
|
|
833
|
+
core.$YatspCUID.init(inst, def);
|
|
834
|
+
YatspStringFormat.init(inst, def);
|
|
835
|
+
});
|
|
836
|
+
|
|
837
|
+
/**
|
|
838
|
+
* Validates a CUID v1 string.
|
|
839
|
+
*
|
|
840
|
+
* @deprecated CUID v1 is deprecated by its authors due to information leakage
|
|
841
|
+
* (timestamps embedded in the id). Use {@link cuid2 | `z.cuid2()`} instead.
|
|
842
|
+
* See https://github.com/paralleldrive/cuid.
|
|
843
|
+
*/
|
|
844
|
+
export function cuid(params?: string | core.$YatspCUIDParams): YatspCUID {
|
|
845
|
+
return core._cuid(YatspCUID, params);
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
// YatspCUID2
|
|
849
|
+
export interface YatspCUID2 extends YatspStringFormat<"cuid2"> {
|
|
850
|
+
_yatsp: core.$YatspCUID2Internals;
|
|
851
|
+
}
|
|
852
|
+
export const YatspCUID2: core.$constructor<YatspCUID2> = /*@__PURE__*/ core.$constructor("YatspCUID2", (inst, def) => {
|
|
853
|
+
// YatspStringFormat.init(inst, def);
|
|
854
|
+
core.$YatspCUID2.init(inst, def);
|
|
855
|
+
YatspStringFormat.init(inst, def);
|
|
856
|
+
});
|
|
857
|
+
|
|
858
|
+
export function cuid2(params?: string | core.$YatspCUID2Params): YatspCUID2 {
|
|
859
|
+
return core._cuid2(YatspCUID2, params);
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
// YatspULID
|
|
863
|
+
export interface YatspULID extends YatspStringFormat<"ulid"> {
|
|
864
|
+
_yatsp: core.$YatspULIDInternals;
|
|
865
|
+
}
|
|
866
|
+
export const YatspULID: core.$constructor<YatspULID> = /*@__PURE__*/ core.$constructor("YatspULID", (inst, def) => {
|
|
867
|
+
// YatspStringFormat.init(inst, def);
|
|
868
|
+
core.$YatspULID.init(inst, def);
|
|
869
|
+
YatspStringFormat.init(inst, def);
|
|
870
|
+
});
|
|
871
|
+
|
|
872
|
+
export function ulid(params?: string | core.$YatspULIDParams): YatspULID {
|
|
873
|
+
return core._ulid(YatspULID, params);
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
// YatspXID
|
|
877
|
+
export interface YatspXID extends YatspStringFormat<"xid"> {
|
|
878
|
+
_yatsp: core.$YatspXIDInternals;
|
|
879
|
+
}
|
|
880
|
+
export const YatspXID: core.$constructor<YatspXID> = /*@__PURE__*/ core.$constructor("YatspXID", (inst, def) => {
|
|
881
|
+
// YatspStringFormat.init(inst, def);
|
|
882
|
+
core.$YatspXID.init(inst, def);
|
|
883
|
+
YatspStringFormat.init(inst, def);
|
|
884
|
+
});
|
|
885
|
+
|
|
886
|
+
export function xid(params?: string | core.$YatspXIDParams): YatspXID {
|
|
887
|
+
return core._xid(YatspXID, params);
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
// YatspKSUID
|
|
891
|
+
export interface YatspKSUID extends YatspStringFormat<"ksuid"> {
|
|
892
|
+
_yatsp: core.$YatspKSUIDInternals;
|
|
893
|
+
}
|
|
894
|
+
export const YatspKSUID: core.$constructor<YatspKSUID> = /*@__PURE__*/ core.$constructor("YatspKSUID", (inst, def) => {
|
|
895
|
+
// YatspStringFormat.init(inst, def);
|
|
896
|
+
core.$YatspKSUID.init(inst, def);
|
|
897
|
+
YatspStringFormat.init(inst, def);
|
|
898
|
+
});
|
|
899
|
+
|
|
900
|
+
export function ksuid(params?: string | core.$YatspKSUIDParams): YatspKSUID {
|
|
901
|
+
return core._ksuid(YatspKSUID, params);
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
// YatspIP
|
|
905
|
+
// export interface YatspIP extends YatspStringFormat<"ip"> {
|
|
906
|
+
// _yatsp: core.$YatspIPInternals;
|
|
907
|
+
// }
|
|
908
|
+
// export const YatspIP: core.$constructor<YatspIP> = /*@__PURE__*/ core.$constructor("YatspIP", (inst, def) => {
|
|
909
|
+
// // YatspStringFormat.init(inst, def);
|
|
910
|
+
// core.$YatspIP.init(inst, def);
|
|
911
|
+
// YatspStringFormat.init(inst, def);
|
|
912
|
+
// });
|
|
913
|
+
|
|
914
|
+
// export function ip(params?: string | core.$YatspIPParams): YatspIP {
|
|
915
|
+
// return core._ip(YatspIP, params);
|
|
916
|
+
// }
|
|
917
|
+
|
|
918
|
+
// YatspIPv4
|
|
919
|
+
export interface YatspIPv4 extends YatspStringFormat<"ipv4"> {
|
|
920
|
+
_yatsp: core.$YatspIPv4Internals;
|
|
921
|
+
}
|
|
922
|
+
export const YatspIPv4: core.$constructor<YatspIPv4> = /*@__PURE__*/ core.$constructor("YatspIPv4", (inst, def) => {
|
|
923
|
+
// YatspStringFormat.init(inst, def);
|
|
924
|
+
core.$YatspIPv4.init(inst, def);
|
|
925
|
+
YatspStringFormat.init(inst, def);
|
|
926
|
+
});
|
|
927
|
+
|
|
928
|
+
export function ipv4(params?: string | core.$YatspIPv4Params): YatspIPv4 {
|
|
929
|
+
return core._ipv4(YatspIPv4, params);
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
// YatspMAC
|
|
933
|
+
export interface YatspMAC extends YatspStringFormat<"mac"> {
|
|
934
|
+
_yatsp: core.$YatspMACInternals;
|
|
935
|
+
}
|
|
936
|
+
export const YatspMAC: core.$constructor<YatspMAC> = /*@__PURE__*/ core.$constructor("YatspMAC", (inst, def) => {
|
|
937
|
+
// YatspStringFormat.init(inst, def);
|
|
938
|
+
core.$YatspMAC.init(inst, def);
|
|
939
|
+
YatspStringFormat.init(inst, def);
|
|
940
|
+
});
|
|
941
|
+
export function mac(params?: string | core.$YatspMACParams): YatspMAC {
|
|
942
|
+
return core._mac(YatspMAC, params);
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
// YatspIPv6
|
|
946
|
+
export interface YatspIPv6 extends YatspStringFormat<"ipv6"> {
|
|
947
|
+
_yatsp: core.$YatspIPv6Internals;
|
|
948
|
+
}
|
|
949
|
+
export const YatspIPv6: core.$constructor<YatspIPv6> = /*@__PURE__*/ core.$constructor("YatspIPv6", (inst, def) => {
|
|
950
|
+
// YatspStringFormat.init(inst, def);
|
|
951
|
+
core.$YatspIPv6.init(inst, def);
|
|
952
|
+
YatspStringFormat.init(inst, def);
|
|
953
|
+
});
|
|
954
|
+
export function ipv6(params?: string | core.$YatspIPv6Params): YatspIPv6 {
|
|
955
|
+
return core._ipv6(YatspIPv6, params);
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
// YatspCIDRv4
|
|
959
|
+
export interface YatspCIDRv4 extends YatspStringFormat<"cidrv4"> {
|
|
960
|
+
_yatsp: core.$YatspCIDRv4Internals;
|
|
961
|
+
}
|
|
962
|
+
export const YatspCIDRv4: core.$constructor<YatspCIDRv4> = /*@__PURE__*/ core.$constructor(
|
|
963
|
+
"YatspCIDRv4",
|
|
964
|
+
(inst, def) => {
|
|
965
|
+
core.$YatspCIDRv4.init(inst, def);
|
|
966
|
+
YatspStringFormat.init(inst, def);
|
|
967
|
+
}
|
|
968
|
+
);
|
|
969
|
+
|
|
970
|
+
export function cidrv4(params?: string | core.$YatspCIDRv4Params): YatspCIDRv4 {
|
|
971
|
+
return core._cidrv4(YatspCIDRv4, params);
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
// YatspCIDRv6
|
|
975
|
+
export interface YatspCIDRv6 extends YatspStringFormat<"cidrv6"> {
|
|
976
|
+
_yatsp: core.$YatspCIDRv6Internals;
|
|
977
|
+
}
|
|
978
|
+
export const YatspCIDRv6: core.$constructor<YatspCIDRv6> = /*@__PURE__*/ core.$constructor(
|
|
979
|
+
"YatspCIDRv6",
|
|
980
|
+
(inst, def) => {
|
|
981
|
+
core.$YatspCIDRv6.init(inst, def);
|
|
982
|
+
YatspStringFormat.init(inst, def);
|
|
983
|
+
}
|
|
984
|
+
);
|
|
985
|
+
|
|
986
|
+
export function cidrv6(params?: string | core.$YatspCIDRv6Params): YatspCIDRv6 {
|
|
987
|
+
return core._cidrv6(YatspCIDRv6, params);
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
// YatspBase64
|
|
991
|
+
export interface YatspBase64 extends YatspStringFormat<"base64"> {
|
|
992
|
+
_yatsp: core.$YatspBase64Internals;
|
|
993
|
+
}
|
|
994
|
+
export const YatspBase64: core.$constructor<YatspBase64> = /*@__PURE__*/ core.$constructor(
|
|
995
|
+
"YatspBase64",
|
|
996
|
+
(inst, def) => {
|
|
997
|
+
// YatspStringFormat.init(inst, def);
|
|
998
|
+
core.$YatspBase64.init(inst, def);
|
|
999
|
+
YatspStringFormat.init(inst, def);
|
|
1000
|
+
}
|
|
1001
|
+
);
|
|
1002
|
+
export function base64(params?: string | core.$YatspBase64Params): YatspBase64 {
|
|
1003
|
+
return core._base64(YatspBase64, params);
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
// YatspBase64URL
|
|
1007
|
+
export interface YatspBase64URL extends YatspStringFormat<"base64url"> {
|
|
1008
|
+
_yatsp: core.$YatspBase64URLInternals;
|
|
1009
|
+
}
|
|
1010
|
+
export const YatspBase64URL: core.$constructor<YatspBase64URL> = /*@__PURE__*/ core.$constructor(
|
|
1011
|
+
"YatspBase64URL",
|
|
1012
|
+
(inst, def) => {
|
|
1013
|
+
// YatspStringFormat.init(inst, def);
|
|
1014
|
+
core.$YatspBase64URL.init(inst, def);
|
|
1015
|
+
YatspStringFormat.init(inst, def);
|
|
1016
|
+
}
|
|
1017
|
+
);
|
|
1018
|
+
export function base64url(params?: string | core.$YatspBase64URLParams): YatspBase64URL {
|
|
1019
|
+
return core._base64url(YatspBase64URL, params);
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
// YatspE164
|
|
1023
|
+
export interface YatspE164 extends YatspStringFormat<"e164"> {
|
|
1024
|
+
_yatsp: core.$YatspE164Internals;
|
|
1025
|
+
}
|
|
1026
|
+
export const YatspE164: core.$constructor<YatspE164> = /*@__PURE__*/ core.$constructor("YatspE164", (inst, def) => {
|
|
1027
|
+
// YatspStringFormat.init(inst, def);
|
|
1028
|
+
core.$YatspE164.init(inst, def);
|
|
1029
|
+
YatspStringFormat.init(inst, def);
|
|
1030
|
+
});
|
|
1031
|
+
|
|
1032
|
+
export function e164(params?: string | core.$YatspE164Params): YatspE164 {
|
|
1033
|
+
return core._e164(YatspE164, params);
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
// YatspCreditCard
|
|
1037
|
+
export interface YatspCreditCard extends YatspStringFormat<"credit_card"> {
|
|
1038
|
+
_yatsp: core.$YatspCreditCardInternals;
|
|
1039
|
+
}
|
|
1040
|
+
export const YatspCreditCard: core.$constructor<YatspCreditCard> = /*@__PURE__*/ core.$constructor(
|
|
1041
|
+
"YatspCreditCard",
|
|
1042
|
+
(inst, def) => {
|
|
1043
|
+
core.$YatspCreditCard.init(inst, def);
|
|
1044
|
+
YatspStringFormat.init(inst, def);
|
|
1045
|
+
}
|
|
1046
|
+
);
|
|
1047
|
+
|
|
1048
|
+
export function creditCard(params?: string | core.$YatspCreditCardParams): YatspCreditCard {
|
|
1049
|
+
return core._creditCard(YatspCreditCard, params);
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1052
|
+
// YatspIBAN
|
|
1053
|
+
export interface YatspIBAN extends YatspStringFormat<"iban"> {
|
|
1054
|
+
_yatsp: core.$YatspIBANInternals;
|
|
1055
|
+
}
|
|
1056
|
+
export const YatspIBAN: core.$constructor<YatspIBAN> = /*@__PURE__*/ core.$constructor("YatspIBAN", (inst, def) => {
|
|
1057
|
+
core.$YatspIBAN.init(inst, def);
|
|
1058
|
+
YatspStringFormat.init(inst, def);
|
|
1059
|
+
});
|
|
1060
|
+
|
|
1061
|
+
export function iban(params?: string | core.$YatspIBANParams): YatspIBAN {
|
|
1062
|
+
return core._iban(YatspIBAN, params);
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
// YatspJWT
|
|
1066
|
+
export interface YatspJWT extends YatspStringFormat<"jwt"> {
|
|
1067
|
+
_yatsp: core.$YatspJWTInternals;
|
|
1068
|
+
}
|
|
1069
|
+
export const YatspJWT: core.$constructor<YatspJWT> = /*@__PURE__*/ core.$constructor("YatspJWT", (inst, def) => {
|
|
1070
|
+
// YatspStringFormat.init(inst, def);
|
|
1071
|
+
core.$YatspJWT.init(inst, def);
|
|
1072
|
+
YatspStringFormat.init(inst, def);
|
|
1073
|
+
});
|
|
1074
|
+
|
|
1075
|
+
export function jwt(params?: string | core.$YatspJWTParams): YatspJWT {
|
|
1076
|
+
return core._jwt(YatspJWT, params);
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
// YatspCustomStringFormat
|
|
1080
|
+
export interface YatspCustomStringFormat<Format extends string = string>
|
|
1081
|
+
extends YatspStringFormat<Format>,
|
|
1082
|
+
core.$YatspCustomStringFormat<Format> {
|
|
1083
|
+
_yatsp: core.$YatspCustomStringFormatInternals<Format>;
|
|
1084
|
+
"~standard": YatspStandardSchemaWithJSON<this>;
|
|
1085
|
+
}
|
|
1086
|
+
export const YatspCustomStringFormat: core.$constructor<YatspCustomStringFormat> = /*@__PURE__*/ core.$constructor(
|
|
1087
|
+
"YatspCustomStringFormat",
|
|
1088
|
+
(inst, def) => {
|
|
1089
|
+
// YatspStringFormat.init(inst, def);
|
|
1090
|
+
core.$YatspCustomStringFormat.init(inst, def);
|
|
1091
|
+
YatspStringFormat.init(inst, def);
|
|
1092
|
+
}
|
|
1093
|
+
);
|
|
1094
|
+
export function stringFormat<Format extends string>(
|
|
1095
|
+
format: Format,
|
|
1096
|
+
fnOrRegex: ((arg: string) => util.MaybeAsync<unknown>) | RegExp,
|
|
1097
|
+
_params: string | core.$YatspStringFormatParams = {}
|
|
1098
|
+
): YatspCustomStringFormat<Format> {
|
|
1099
|
+
return core._stringFormat(YatspCustomStringFormat, format, fnOrRegex, _params) as any;
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
export function hostname(_params?: string | core.$YatspStringFormatParams): YatspCustomStringFormat<"hostname"> {
|
|
1103
|
+
return core._stringFormat(YatspCustomStringFormat, "hostname", regexes.hostname, _params) as any;
|
|
1104
|
+
}
|
|
1105
|
+
|
|
1106
|
+
export function hex(_params?: string | core.$YatspStringFormatParams): YatspCustomStringFormat<"hex"> {
|
|
1107
|
+
return core._stringFormat(YatspCustomStringFormat, "hex", regexes.hex, _params) as any;
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
export function currencyCode(
|
|
1111
|
+
_params?: string | core.$YatspStringFormatParams
|
|
1112
|
+
): YatspCustomStringFormat<"currency_code"> {
|
|
1113
|
+
return core._stringFormat(YatspCustomStringFormat, "currency_code", regexes.currencyCode, _params) as any;
|
|
1114
|
+
}
|
|
1115
|
+
|
|
1116
|
+
export function hash<Alg extends util.HashAlgorithm, Enc extends util.HashEncoding = "hex">(
|
|
1117
|
+
alg: Alg,
|
|
1118
|
+
params?: {
|
|
1119
|
+
enc?: Enc;
|
|
1120
|
+
} & core.$YatspStringFormatParams
|
|
1121
|
+
): YatspCustomStringFormat<`${Alg}_${Enc}`> {
|
|
1122
|
+
const enc = params?.enc ?? "hex";
|
|
1123
|
+
const format = `${alg}_${enc}` as const;
|
|
1124
|
+
const regex = core.regexes[format as keyof typeof core.regexes] as RegExp;
|
|
1125
|
+
if (!regex) throw new Error(`Unrecognized hash format: ${format}`);
|
|
1126
|
+
return core._stringFormat(YatspCustomStringFormat, format, regex, params) as any;
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1129
|
+
// YatspNumber
|
|
1130
|
+
export interface _YatspNumber<Internals extends core.$YatspNumberInternals = core.$YatspNumberInternals>
|
|
1131
|
+
extends _YatspType<Internals> {
|
|
1132
|
+
gt(value: number, params?: string | core.$YatspCheckGreaterThanParams): this;
|
|
1133
|
+
/** Identical to .min() */
|
|
1134
|
+
gte(value: number, params?: string | core.$YatspCheckGreaterThanParams): this;
|
|
1135
|
+
min(value: number, params?: string | core.$YatspCheckGreaterThanParams): this;
|
|
1136
|
+
lt(value: number, params?: string | core.$YatspCheckLessThanParams): this;
|
|
1137
|
+
/** Identical to .max() */
|
|
1138
|
+
lte(value: number, params?: string | core.$YatspCheckLessThanParams): this;
|
|
1139
|
+
max(value: number, params?: string | core.$YatspCheckLessThanParams): this;
|
|
1140
|
+
/** Consider `z.int()` instead. This API is considered *legacy*; it will never be removed but a better alternative exists. */
|
|
1141
|
+
int(params?: string | core.$YatspCheckNumberFormatParams): this;
|
|
1142
|
+
/** @deprecated This is now identical to `.int()`. Only numbers in the safe integer range are accepted. */
|
|
1143
|
+
safe(params?: string | core.$YatspCheckNumberFormatParams): this;
|
|
1144
|
+
positive(params?: string | core.$YatspCheckGreaterThanParams): this;
|
|
1145
|
+
nonnegative(params?: string | core.$YatspCheckGreaterThanParams): this;
|
|
1146
|
+
negative(params?: string | core.$YatspCheckLessThanParams): this;
|
|
1147
|
+
nonpositive(params?: string | core.$YatspCheckLessThanParams): this;
|
|
1148
|
+
multipleOf(value: number, params?: string | core.$YatspCheckMultipleOfParams): this;
|
|
1149
|
+
/** @deprecated Use `.multipleOf()` instead. */
|
|
1150
|
+
step(value: number, params?: string | core.$YatspCheckMultipleOfParams): this;
|
|
1151
|
+
|
|
1152
|
+
/** @deprecated In v4 and later, z.number() does not allow infinite values by default. This is a no-op. */
|
|
1153
|
+
finite(params?: unknown): this;
|
|
1154
|
+
|
|
1155
|
+
minValue: number | null;
|
|
1156
|
+
maxValue: number | null;
|
|
1157
|
+
/** @deprecated Check the `format` property instead. */
|
|
1158
|
+
isInt: boolean;
|
|
1159
|
+
/** @deprecated Number schemas no longer accept infinite values, so this always returns `true`. */
|
|
1160
|
+
isFinite: boolean;
|
|
1161
|
+
format: string | null;
|
|
1162
|
+
}
|
|
1163
|
+
|
|
1164
|
+
export interface YatspNumber extends _YatspNumber<core.$YatspNumberInternals<number>> {}
|
|
1165
|
+
|
|
1166
|
+
export const YatspNumber: core.$constructor<YatspNumber> = /*@__PURE__*/ core.$constructor<YatspNumber>(
|
|
1167
|
+
"YatspNumber",
|
|
1168
|
+
(inst, def) => {
|
|
1169
|
+
core.$YatspNumber.init(inst, def);
|
|
1170
|
+
|
|
1171
|
+
YatspType.init(inst, def);
|
|
1172
|
+
|
|
1173
|
+
inst._yatsp.processJSONSchema = (ctx, json, params) => processors.numberProcessor(inst, ctx, json, params);
|
|
1174
|
+
inst.isFinite = true;
|
|
1175
|
+
},
|
|
1176
|
+
/*@__PURE__*/ util.derived<YatspNumber>(
|
|
1177
|
+
{
|
|
1178
|
+
minValue: (inst) => {
|
|
1179
|
+
const { minimum, exclusiveMinimum } = processors.aggregateChecks<number>(inst);
|
|
1180
|
+
return Math.max(minimum ?? Number.NEGATIVE_INFINITY, exclusiveMinimum ?? Number.NEGATIVE_INFINITY);
|
|
1181
|
+
},
|
|
1182
|
+
maxValue: (inst) => {
|
|
1183
|
+
const { maximum, exclusiveMaximum } = processors.aggregateChecks<number>(inst);
|
|
1184
|
+
return Math.min(maximum ?? Number.POSITIVE_INFINITY, exclusiveMaximum ?? Number.POSITIVE_INFINITY);
|
|
1185
|
+
},
|
|
1186
|
+
isInt: (inst) => {
|
|
1187
|
+
const { isInt, multipleOf } = processors.aggregateChecks(inst);
|
|
1188
|
+
return !!isInt || !!multipleOf?.some(Number.isSafeInteger);
|
|
1189
|
+
},
|
|
1190
|
+
format: (inst) => processors.aggregateChecks(inst).format ?? null,
|
|
1191
|
+
},
|
|
1192
|
+
{
|
|
1193
|
+
gt(value, params) {
|
|
1194
|
+
return this.check(checks.gt(value, params));
|
|
1195
|
+
},
|
|
1196
|
+
gte(value, params) {
|
|
1197
|
+
return this.check(checks.gte(value, params));
|
|
1198
|
+
},
|
|
1199
|
+
min(value, params) {
|
|
1200
|
+
return this.check(checks.gte(value, params));
|
|
1201
|
+
},
|
|
1202
|
+
lt(value, params) {
|
|
1203
|
+
return this.check(checks.lt(value, params));
|
|
1204
|
+
},
|
|
1205
|
+
lte(value, params) {
|
|
1206
|
+
return this.check(checks.lte(value, params));
|
|
1207
|
+
},
|
|
1208
|
+
max(value, params) {
|
|
1209
|
+
return this.check(checks.lte(value, params));
|
|
1210
|
+
},
|
|
1211
|
+
int(params) {
|
|
1212
|
+
return this.check(int(params));
|
|
1213
|
+
},
|
|
1214
|
+
safe(params) {
|
|
1215
|
+
return this.check(int(params));
|
|
1216
|
+
},
|
|
1217
|
+
positive(params) {
|
|
1218
|
+
return this.check(checks.gt(0, params));
|
|
1219
|
+
},
|
|
1220
|
+
nonnegative(params) {
|
|
1221
|
+
return this.check(checks.gte(0, params));
|
|
1222
|
+
},
|
|
1223
|
+
negative(params) {
|
|
1224
|
+
return this.check(checks.lt(0, params));
|
|
1225
|
+
},
|
|
1226
|
+
nonpositive(params) {
|
|
1227
|
+
return this.check(checks.lte(0, params));
|
|
1228
|
+
},
|
|
1229
|
+
multipleOf(value, params) {
|
|
1230
|
+
return this.check(checks.multipleOf(value, params));
|
|
1231
|
+
},
|
|
1232
|
+
step(value, params) {
|
|
1233
|
+
return this.check(checks.multipleOf(value, params));
|
|
1234
|
+
},
|
|
1235
|
+
finite() {
|
|
1236
|
+
return this;
|
|
1237
|
+
},
|
|
1238
|
+
}
|
|
1239
|
+
)
|
|
1240
|
+
);
|
|
1241
|
+
|
|
1242
|
+
export function number(params?: string | core.$YatspNumberParams): YatspNumber {
|
|
1243
|
+
return core._number(YatspNumber, params);
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1246
|
+
// YatspNumberFormat
|
|
1247
|
+
export interface YatspNumberFormat<Format extends $YatspNumberFormats = $YatspNumberFormats> extends YatspNumber {
|
|
1248
|
+
_yatsp: core.$YatspNumberFormatInternals<Format>;
|
|
1249
|
+
}
|
|
1250
|
+
export const YatspNumberFormat: core.$constructor<YatspNumberFormat> = /*@__PURE__*/ core.$constructor(
|
|
1251
|
+
"YatspNumberFormat",
|
|
1252
|
+
(inst, def) => {
|
|
1253
|
+
core.$YatspNumberFormat.init(inst, def);
|
|
1254
|
+
YatspNumber.init(inst, def);
|
|
1255
|
+
}
|
|
1256
|
+
);
|
|
1257
|
+
|
|
1258
|
+
// int
|
|
1259
|
+
export interface YatspInt extends YatspNumberFormat<"safeint"> {}
|
|
1260
|
+
export function int(params?: string | core.$YatspCheckNumberFormatParams): YatspInt {
|
|
1261
|
+
return core._int(YatspNumberFormat, params) as YatspInt;
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1264
|
+
// float32
|
|
1265
|
+
export interface YatspFloat32 extends YatspNumberFormat<"float32"> {}
|
|
1266
|
+
export function float32(params?: string | core.$YatspCheckNumberFormatParams): YatspFloat32 {
|
|
1267
|
+
return core._float32(YatspNumberFormat, params) as YatspFloat32;
|
|
1268
|
+
}
|
|
1269
|
+
|
|
1270
|
+
// float64
|
|
1271
|
+
export interface YatspFloat64 extends YatspNumberFormat<"float64"> {}
|
|
1272
|
+
export function float64(params?: string | core.$YatspCheckNumberFormatParams): YatspFloat64 {
|
|
1273
|
+
return core._float64(YatspNumberFormat, params) as YatspFloat64;
|
|
1274
|
+
}
|
|
1275
|
+
|
|
1276
|
+
// int32
|
|
1277
|
+
export interface YatspInt32 extends YatspNumberFormat<"int32"> {}
|
|
1278
|
+
export function int32(params?: string | core.$YatspCheckNumberFormatParams): YatspInt32 {
|
|
1279
|
+
return core._int32(YatspNumberFormat, params) as YatspInt32;
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
// uint32
|
|
1283
|
+
export interface YatspUInt32 extends YatspNumberFormat<"uint32"> {}
|
|
1284
|
+
export function uint32(params?: string | core.$YatspCheckNumberFormatParams): YatspUInt32 {
|
|
1285
|
+
return core._uint32(YatspNumberFormat, params) as YatspUInt32;
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
// boolean
|
|
1289
|
+
export interface _YatspBoolean<T extends core.$YatspBooleanInternals = core.$YatspBooleanInternals>
|
|
1290
|
+
extends _YatspType<T> {}
|
|
1291
|
+
export interface YatspBoolean extends _YatspBoolean<core.$YatspBooleanInternals<boolean>> {}
|
|
1292
|
+
export const YatspBoolean: core.$constructor<YatspBoolean> = /*@__PURE__*/ core.$constructor(
|
|
1293
|
+
"YatspBoolean",
|
|
1294
|
+
(inst, def) => {
|
|
1295
|
+
core.$YatspBoolean.init(inst, def);
|
|
1296
|
+
YatspType.init(inst, def);
|
|
1297
|
+
inst._yatsp.processJSONSchema = (ctx, json, params) => processors.booleanProcessor(inst, ctx, json, params);
|
|
1298
|
+
}
|
|
1299
|
+
);
|
|
1300
|
+
|
|
1301
|
+
export function boolean(params?: string | core.$YatspBooleanParams): YatspBoolean {
|
|
1302
|
+
return core._boolean(YatspBoolean, params);
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1305
|
+
// bigint
|
|
1306
|
+
export interface _YatspBigInt<T extends core.$YatspBigIntInternals = core.$YatspBigIntInternals> extends _YatspType<T> {
|
|
1307
|
+
gte(value: bigint, params?: string | core.$YatspCheckGreaterThanParams): this;
|
|
1308
|
+
/** Alias of `.gte()` */
|
|
1309
|
+
min(value: bigint, params?: string | core.$YatspCheckGreaterThanParams): this;
|
|
1310
|
+
gt(value: bigint, params?: string | core.$YatspCheckGreaterThanParams): this;
|
|
1311
|
+
/** Alias of `.lte()` */
|
|
1312
|
+
lte(value: bigint, params?: string | core.$YatspCheckLessThanParams): this;
|
|
1313
|
+
max(value: bigint, params?: string | core.$YatspCheckLessThanParams): this;
|
|
1314
|
+
lt(value: bigint, params?: string | core.$YatspCheckLessThanParams): this;
|
|
1315
|
+
positive(params?: string | core.$YatspCheckGreaterThanParams): this;
|
|
1316
|
+
negative(params?: string | core.$YatspCheckLessThanParams): this;
|
|
1317
|
+
nonpositive(params?: string | core.$YatspCheckLessThanParams): this;
|
|
1318
|
+
nonnegative(params?: string | core.$YatspCheckGreaterThanParams): this;
|
|
1319
|
+
multipleOf(value: bigint, params?: string | core.$YatspCheckMultipleOfParams): this;
|
|
1320
|
+
|
|
1321
|
+
minValue: bigint | null;
|
|
1322
|
+
maxValue: bigint | null;
|
|
1323
|
+
format: string | null;
|
|
1324
|
+
}
|
|
1325
|
+
|
|
1326
|
+
export interface YatspBigInt extends _YatspBigInt<core.$YatspBigIntInternals<bigint>> {}
|
|
1327
|
+
export const YatspBigInt: core.$constructor<YatspBigInt> = /*@__PURE__*/ core.$constructor<YatspBigInt>(
|
|
1328
|
+
"YatspBigInt",
|
|
1329
|
+
(inst, def) => {
|
|
1330
|
+
core.$YatspBigInt.init(inst, def);
|
|
1331
|
+
YatspType.init(inst, def);
|
|
1332
|
+
inst._yatsp.processJSONSchema = (ctx, json, params) => processors.bigintProcessor(inst, ctx, json, params);
|
|
1333
|
+
},
|
|
1334
|
+
/*@__PURE__*/ util.derived<YatspBigInt>(
|
|
1335
|
+
{
|
|
1336
|
+
minValue: (inst) => processors.aggregateChecks<bigint>(inst).minimum ?? null,
|
|
1337
|
+
maxValue: (inst) => processors.aggregateChecks<bigint>(inst).maximum ?? null,
|
|
1338
|
+
format: (inst) => processors.aggregateChecks(inst).format ?? null,
|
|
1339
|
+
},
|
|
1340
|
+
{
|
|
1341
|
+
gte(value, params) {
|
|
1342
|
+
return this.check(checks.gte(value, params));
|
|
1343
|
+
},
|
|
1344
|
+
min(value, params) {
|
|
1345
|
+
return this.check(checks.gte(value, params));
|
|
1346
|
+
},
|
|
1347
|
+
gt(value, params) {
|
|
1348
|
+
return this.check(checks.gt(value, params));
|
|
1349
|
+
},
|
|
1350
|
+
lt(value, params) {
|
|
1351
|
+
return this.check(checks.lt(value, params));
|
|
1352
|
+
},
|
|
1353
|
+
lte(value, params) {
|
|
1354
|
+
return this.check(checks.lte(value, params));
|
|
1355
|
+
},
|
|
1356
|
+
max(value, params) {
|
|
1357
|
+
return this.check(checks.lte(value, params));
|
|
1358
|
+
},
|
|
1359
|
+
positive(params) {
|
|
1360
|
+
return this.check(checks.gt(BigInt(0), params));
|
|
1361
|
+
},
|
|
1362
|
+
negative(params) {
|
|
1363
|
+
return this.check(checks.lt(BigInt(0), params));
|
|
1364
|
+
},
|
|
1365
|
+
nonpositive(params) {
|
|
1366
|
+
return this.check(checks.lte(BigInt(0), params));
|
|
1367
|
+
},
|
|
1368
|
+
nonnegative(params) {
|
|
1369
|
+
return this.check(checks.gte(BigInt(0), params));
|
|
1370
|
+
},
|
|
1371
|
+
multipleOf(value, params) {
|
|
1372
|
+
return this.check(checks.multipleOf(value, params));
|
|
1373
|
+
},
|
|
1374
|
+
}
|
|
1375
|
+
)
|
|
1376
|
+
);
|
|
1377
|
+
|
|
1378
|
+
export function bigint(params?: string | core.$YatspBigIntParams): YatspBigInt {
|
|
1379
|
+
return core._bigint(YatspBigInt, params);
|
|
1380
|
+
}
|
|
1381
|
+
// bigint formats
|
|
1382
|
+
|
|
1383
|
+
// YatspBigIntFormat
|
|
1384
|
+
export interface YatspBigIntFormat<Format extends $YatspBigIntFormats = $YatspBigIntFormats> extends YatspBigInt {
|
|
1385
|
+
_yatsp: core.$YatspBigIntFormatInternals<Format>;
|
|
1386
|
+
}
|
|
1387
|
+
export const YatspBigIntFormat: core.$constructor<YatspBigIntFormat> = /*@__PURE__*/ core.$constructor(
|
|
1388
|
+
"YatspBigIntFormat",
|
|
1389
|
+
(inst, def) => {
|
|
1390
|
+
core.$YatspBigIntFormat.init(inst, def);
|
|
1391
|
+
YatspBigInt.init(inst, def);
|
|
1392
|
+
}
|
|
1393
|
+
);
|
|
1394
|
+
|
|
1395
|
+
// int64
|
|
1396
|
+
export interface YatspInt64 extends YatspBigIntFormat<"int64"> {}
|
|
1397
|
+
export function int64(params?: string | core.$YatspBigIntFormatParams): YatspInt64 {
|
|
1398
|
+
return core._int64(YatspBigIntFormat, params) as YatspInt64;
|
|
1399
|
+
}
|
|
1400
|
+
|
|
1401
|
+
// uint64
|
|
1402
|
+
export interface YatspUInt64 extends YatspBigIntFormat<"uint64"> {}
|
|
1403
|
+
export function uint64(params?: string | core.$YatspBigIntFormatParams): YatspUInt64 {
|
|
1404
|
+
return core._uint64(YatspBigIntFormat, params) as YatspUInt64;
|
|
1405
|
+
}
|
|
1406
|
+
|
|
1407
|
+
// symbol
|
|
1408
|
+
export interface YatspSymbol extends _YatspType<core.$YatspSymbolInternals> {}
|
|
1409
|
+
export const YatspSymbol: core.$constructor<YatspSymbol> = /*@__PURE__*/ core.$constructor(
|
|
1410
|
+
"YatspSymbol",
|
|
1411
|
+
(inst, def) => {
|
|
1412
|
+
core.$YatspSymbol.init(inst, def);
|
|
1413
|
+
YatspType.init(inst, def);
|
|
1414
|
+
inst._yatsp.processJSONSchema = (ctx, json, params) => processors.symbolProcessor(inst, ctx, json, params);
|
|
1415
|
+
}
|
|
1416
|
+
);
|
|
1417
|
+
|
|
1418
|
+
export function symbol(params?: string | core.$YatspSymbolParams): YatspSymbol {
|
|
1419
|
+
return core._symbol(YatspSymbol, params);
|
|
1420
|
+
}
|
|
1421
|
+
|
|
1422
|
+
// YatspUndefined
|
|
1423
|
+
export interface YatspUndefined extends _YatspType<core.$YatspUndefinedInternals> {}
|
|
1424
|
+
export const YatspUndefined: core.$constructor<YatspUndefined> = /*@__PURE__*/ core.$constructor(
|
|
1425
|
+
"YatspUndefined",
|
|
1426
|
+
(inst, def) => {
|
|
1427
|
+
core.$YatspUndefined.init(inst, def);
|
|
1428
|
+
YatspType.init(inst, def);
|
|
1429
|
+
inst._yatsp.processJSONSchema = (ctx, json, params) => processors.undefinedProcessor(inst, ctx, json, params);
|
|
1430
|
+
}
|
|
1431
|
+
);
|
|
1432
|
+
|
|
1433
|
+
function _undefined(params?: string | core.$YatspUndefinedParams): YatspUndefined {
|
|
1434
|
+
return core._undefined(YatspUndefined, params);
|
|
1435
|
+
}
|
|
1436
|
+
export { _undefined as undefined };
|
|
1437
|
+
|
|
1438
|
+
// YatspNull
|
|
1439
|
+
export interface YatspNull extends _YatspType<core.$YatspNullInternals> {}
|
|
1440
|
+
export const YatspNull: core.$constructor<YatspNull> = /*@__PURE__*/ core.$constructor("YatspNull", (inst, def) => {
|
|
1441
|
+
core.$YatspNull.init(inst, def);
|
|
1442
|
+
YatspType.init(inst, def);
|
|
1443
|
+
inst._yatsp.processJSONSchema = (ctx, json, params) => processors.nullProcessor(inst, ctx, json, params);
|
|
1444
|
+
});
|
|
1445
|
+
|
|
1446
|
+
function _null(params?: string | core.$YatspNullParams): YatspNull {
|
|
1447
|
+
return core._null(YatspNull, params);
|
|
1448
|
+
}
|
|
1449
|
+
export { _null as null };
|
|
1450
|
+
|
|
1451
|
+
// YatspAny
|
|
1452
|
+
export interface YatspAny extends _YatspType<core.$YatspAnyInternals> {}
|
|
1453
|
+
export const YatspAny: core.$constructor<YatspAny> = /*@__PURE__*/ core.$constructor("YatspAny", (inst, def) => {
|
|
1454
|
+
core.$YatspAny.init(inst, def);
|
|
1455
|
+
YatspType.init(inst, def);
|
|
1456
|
+
inst._yatsp.processJSONSchema = (ctx, json, params) => processors.anyProcessor(inst, ctx, json, params);
|
|
1457
|
+
});
|
|
1458
|
+
|
|
1459
|
+
export function any(): YatspAny {
|
|
1460
|
+
return core._any(YatspAny);
|
|
1461
|
+
}
|
|
1462
|
+
|
|
1463
|
+
// YatspUnknown
|
|
1464
|
+
export interface YatspUnknown extends _YatspType<core.$YatspUnknownInternals> {}
|
|
1465
|
+
export const YatspUnknown: core.$constructor<YatspUnknown> = /*@__PURE__*/ core.$constructor(
|
|
1466
|
+
"YatspUnknown",
|
|
1467
|
+
(inst, def) => {
|
|
1468
|
+
core.$YatspUnknown.init(inst, def);
|
|
1469
|
+
YatspType.init(inst, def);
|
|
1470
|
+
inst._yatsp.processJSONSchema = (ctx, json, params) => processors.unknownProcessor(inst, ctx, json, params);
|
|
1471
|
+
}
|
|
1472
|
+
);
|
|
1473
|
+
|
|
1474
|
+
export function unknown(): YatspUnknown {
|
|
1475
|
+
return core._unknown(YatspUnknown);
|
|
1476
|
+
}
|
|
1477
|
+
|
|
1478
|
+
// YatspNever
|
|
1479
|
+
export interface YatspNever extends _YatspType<core.$YatspNeverInternals> {}
|
|
1480
|
+
export const YatspNever: core.$constructor<YatspNever> = /*@__PURE__*/ core.$constructor("YatspNever", (inst, def) => {
|
|
1481
|
+
core.$YatspNever.init(inst, def);
|
|
1482
|
+
YatspType.init(inst, def);
|
|
1483
|
+
inst._yatsp.processJSONSchema = (ctx, json, params) => processors.neverProcessor(inst, ctx, json, params);
|
|
1484
|
+
});
|
|
1485
|
+
|
|
1486
|
+
export function never(params?: string | core.$YatspNeverParams): YatspNever {
|
|
1487
|
+
return core._never(YatspNever, params);
|
|
1488
|
+
}
|
|
1489
|
+
|
|
1490
|
+
// YatspVoid
|
|
1491
|
+
export interface YatspVoid extends _YatspType<core.$YatspVoidInternals> {}
|
|
1492
|
+
export const YatspVoid: core.$constructor<YatspVoid> = /*@__PURE__*/ core.$constructor("YatspVoid", (inst, def) => {
|
|
1493
|
+
core.$YatspVoid.init(inst, def);
|
|
1494
|
+
YatspType.init(inst, def);
|
|
1495
|
+
inst._yatsp.processJSONSchema = (ctx, json, params) => processors.voidProcessor(inst, ctx, json, params);
|
|
1496
|
+
});
|
|
1497
|
+
|
|
1498
|
+
function _void(params?: string | core.$YatspVoidParams): YatspVoid {
|
|
1499
|
+
return core._void(YatspVoid, params);
|
|
1500
|
+
}
|
|
1501
|
+
export { _void as void };
|
|
1502
|
+
|
|
1503
|
+
// YatspDate
|
|
1504
|
+
export interface _YatspDate<T extends core.$YatspDateInternals = core.$YatspDateInternals> extends _YatspType<T> {
|
|
1505
|
+
min(value: number | Date, params?: string | core.$YatspCheckGreaterThanParams): this;
|
|
1506
|
+
max(value: number | Date, params?: string | core.$YatspCheckLessThanParams): this;
|
|
1507
|
+
|
|
1508
|
+
/** @deprecated Not recommended. */
|
|
1509
|
+
minDate: Date | null;
|
|
1510
|
+
/** @deprecated Not recommended. */
|
|
1511
|
+
maxDate: Date | null;
|
|
1512
|
+
}
|
|
1513
|
+
|
|
1514
|
+
export interface YatspDate extends _YatspDate<core.$YatspDateInternals<Date>> {}
|
|
1515
|
+
export const YatspDate: core.$constructor<YatspDate> = /*@__PURE__*/ core.$constructor<YatspDate>(
|
|
1516
|
+
"YatspDate",
|
|
1517
|
+
(inst, def) => {
|
|
1518
|
+
core.$YatspDate.init(inst, def);
|
|
1519
|
+
YatspType.init(inst, def);
|
|
1520
|
+
inst._yatsp.processJSONSchema = (ctx, json, params) => processors.dateProcessor(inst, ctx, json, params);
|
|
1521
|
+
|
|
1522
|
+
inst.min = (value, params) => inst.check(checks.gte(value, params));
|
|
1523
|
+
inst.max = (value, params) => inst.check(checks.lte(value, params));
|
|
1524
|
+
},
|
|
1525
|
+
/*@__PURE__*/ util.derived<YatspDate>(
|
|
1526
|
+
{
|
|
1527
|
+
minDate: (inst) => {
|
|
1528
|
+
const { minimum } = processors.aggregateChecks<Date>(inst);
|
|
1529
|
+
return minimum ? new Date(minimum) : null;
|
|
1530
|
+
},
|
|
1531
|
+
maxDate: (inst) => {
|
|
1532
|
+
const { maximum } = processors.aggregateChecks<Date>(inst);
|
|
1533
|
+
return maximum ? new Date(maximum) : null;
|
|
1534
|
+
},
|
|
1535
|
+
},
|
|
1536
|
+
{}
|
|
1537
|
+
)
|
|
1538
|
+
);
|
|
1539
|
+
|
|
1540
|
+
export function date(params?: string | core.$YatspDateParams): YatspDate {
|
|
1541
|
+
return core._date(YatspDate, params);
|
|
1542
|
+
}
|
|
1543
|
+
|
|
1544
|
+
// YatspArray
|
|
1545
|
+
export interface YatspArray<T extends core.SomeType = core.$YatspType>
|
|
1546
|
+
extends _YatspType<core.$YatspArrayInternals<T>>,
|
|
1547
|
+
core.$YatspArray<T> {
|
|
1548
|
+
element: T;
|
|
1549
|
+
min(minLength: number, params?: string | core.$YatspCheckMinLengthParams): this;
|
|
1550
|
+
nonempty(params?: string | core.$YatspCheckMinLengthParams): this;
|
|
1551
|
+
max(maxLength: number, params?: string | core.$YatspCheckMaxLengthParams): this;
|
|
1552
|
+
length(len: number, params?: string | core.$YatspCheckLengthEqualsParams): this;
|
|
1553
|
+
|
|
1554
|
+
unwrap(): T;
|
|
1555
|
+
"~standard": YatspStandardSchemaWithJSON<this>;
|
|
1556
|
+
}
|
|
1557
|
+
export const YatspArray: core.$constructor<YatspArray> = /*@__PURE__*/ core.$constructor<YatspArray>(
|
|
1558
|
+
"YatspArray",
|
|
1559
|
+
(inst, def) => {
|
|
1560
|
+
_ensureDefaultMemoizer();
|
|
1561
|
+
core.$YatspArray.init(inst, def);
|
|
1562
|
+
YatspType.init(inst, def);
|
|
1563
|
+
inst._yatsp.processJSONSchema = (ctx, json, params) => processors.arrayProcessor(inst, ctx, json, params);
|
|
1564
|
+
|
|
1565
|
+
inst.element = def.element;
|
|
1566
|
+
},
|
|
1567
|
+
{
|
|
1568
|
+
min(n, params) {
|
|
1569
|
+
return this.check(checks.minLength(n, params));
|
|
1570
|
+
},
|
|
1571
|
+
nonempty(params) {
|
|
1572
|
+
return this.check(checks.minLength(1, params));
|
|
1573
|
+
},
|
|
1574
|
+
max(n, params) {
|
|
1575
|
+
return this.check(checks.maxLength(n, params));
|
|
1576
|
+
},
|
|
1577
|
+
length(n, params) {
|
|
1578
|
+
return this.check(checks.length(n, params));
|
|
1579
|
+
},
|
|
1580
|
+
unwrap() {
|
|
1581
|
+
return this.element;
|
|
1582
|
+
},
|
|
1583
|
+
}
|
|
1584
|
+
);
|
|
1585
|
+
|
|
1586
|
+
export function array<T extends core.SomeType>(element: T, params?: string | core.$YatspArrayParams): YatspArray<T> {
|
|
1587
|
+
return core._array(YatspArray, element as any, params) as any;
|
|
1588
|
+
}
|
|
1589
|
+
|
|
1590
|
+
// .keyof
|
|
1591
|
+
export function keyof<T extends YatspObject>(schema: T): YatspEnum<util.KeysEnum<T["_yatsp"]["output"]>> {
|
|
1592
|
+
const shape = schema._yatsp.def.shape;
|
|
1593
|
+
return _enum(Object.keys(shape)) as any;
|
|
1594
|
+
}
|
|
1595
|
+
|
|
1596
|
+
// YatspObject
|
|
1597
|
+
|
|
1598
|
+
export type SafeExtendShape<Base extends core.$YatspShape, Ext extends core.$YatspLooseShape> = {
|
|
1599
|
+
[K in keyof Ext]: K extends keyof Base
|
|
1600
|
+
? core.output<Ext[K]> extends core.output<Base[K]>
|
|
1601
|
+
? core.input<Ext[K]> extends core.input<Base[K]>
|
|
1602
|
+
? Ext[K]
|
|
1603
|
+
: never
|
|
1604
|
+
: never
|
|
1605
|
+
: Ext[K];
|
|
1606
|
+
};
|
|
1607
|
+
|
|
1608
|
+
export interface YatspObject<
|
|
1609
|
+
/** @ts-ignore Cast variance */
|
|
1610
|
+
out Shape extends core.$YatspShape = core.$YatspLooseShape,
|
|
1611
|
+
out Config extends core.$YatspObjectConfig = core.$strip,
|
|
1612
|
+
> extends _YatspType<core.$YatspObjectInternals<Shape, Config>>,
|
|
1613
|
+
core.$YatspObject<Shape, Config> {
|
|
1614
|
+
"~standard": YatspStandardSchemaWithJSON<this>;
|
|
1615
|
+
shape: Shape;
|
|
1616
|
+
|
|
1617
|
+
keyof(): YatspEnum<util.ToEnum<keyof Shape & string>>;
|
|
1618
|
+
/** Define a schema to validate all unrecognized keys. This overrides the existing strict/loose behavior. */
|
|
1619
|
+
catchall<T extends core.SomeType>(schema: T): YatspObject<Shape, core.$catchall<T>>;
|
|
1620
|
+
|
|
1621
|
+
/** @deprecated Use `z.looseObject()` or `.loose()` instead. */
|
|
1622
|
+
passthrough(): YatspObject<Shape, core.$loose>;
|
|
1623
|
+
/** Consider `z.looseObject(A.shape)` instead */
|
|
1624
|
+
loose(): YatspObject<Shape, core.$loose>;
|
|
1625
|
+
|
|
1626
|
+
/** Consider `z.strictObject(A.shape)` instead */
|
|
1627
|
+
strict(): YatspObject<Shape, core.$strict>;
|
|
1628
|
+
|
|
1629
|
+
/** This is the default behavior. This method call is likely unnecessary. */
|
|
1630
|
+
strip(): YatspObject<Shape, core.$strip>;
|
|
1631
|
+
|
|
1632
|
+
extend<U extends core.$YatspLooseShape>(shape: U): YatspObject<util.Extend<Shape, util.Writeable<U>>, Config>;
|
|
1633
|
+
|
|
1634
|
+
safeExtend<U extends core.$YatspLooseShape>(
|
|
1635
|
+
shape: SafeExtendShape<Shape, U> & Partial<Record<keyof Shape, core.SomeType>>
|
|
1636
|
+
): YatspObject<util.Extend<Shape, util.Writeable<U>>, Config>;
|
|
1637
|
+
|
|
1638
|
+
/**
|
|
1639
|
+
* @deprecated Use [`A.extend(B.shape)`](https://yatsp.dev/api?id=extend) instead.
|
|
1640
|
+
*/
|
|
1641
|
+
merge<U extends YatspObject>(other: U): YatspObject<util.Extend<Shape, U["shape"]>, U["_yatsp"]["config"]>;
|
|
1642
|
+
|
|
1643
|
+
pick<M extends util.Mask<keyof Shape>>(
|
|
1644
|
+
mask: M & Record<Exclude<keyof M, keyof Shape>, never>
|
|
1645
|
+
): YatspObject<util.Flatten<Pick<Shape, Extract<keyof Shape, keyof M>>>, Config>;
|
|
1646
|
+
|
|
1647
|
+
omit<M extends util.Mask<keyof Shape>>(
|
|
1648
|
+
mask: M & Record<Exclude<keyof M, keyof Shape>, never>
|
|
1649
|
+
): YatspObject<util.Flatten<Omit<Shape, Extract<keyof Shape, keyof M>>>, Config>;
|
|
1650
|
+
|
|
1651
|
+
partial(): YatspObject<
|
|
1652
|
+
{
|
|
1653
|
+
-readonly [k in keyof Shape]: YatspOptional<Shape[k]>;
|
|
1654
|
+
},
|
|
1655
|
+
Config
|
|
1656
|
+
>;
|
|
1657
|
+
partial<M extends util.Mask<keyof Shape>>(
|
|
1658
|
+
mask: M & Record<Exclude<keyof M, keyof Shape>, never>
|
|
1659
|
+
): YatspObject<
|
|
1660
|
+
{
|
|
1661
|
+
-readonly [k in keyof Shape]: k extends keyof M
|
|
1662
|
+
? // Shape[k] extends OptionalInSchema
|
|
1663
|
+
// ? Shape[k]
|
|
1664
|
+
// :
|
|
1665
|
+
YatspOptional<Shape[k]>
|
|
1666
|
+
: Shape[k];
|
|
1667
|
+
},
|
|
1668
|
+
Config
|
|
1669
|
+
>;
|
|
1670
|
+
|
|
1671
|
+
// exactPartial
|
|
1672
|
+
exactPartial(): YatspObject<
|
|
1673
|
+
{
|
|
1674
|
+
-readonly [k in keyof Shape]: YatspExactOptional<Shape[k]>;
|
|
1675
|
+
},
|
|
1676
|
+
Config
|
|
1677
|
+
>;
|
|
1678
|
+
exactPartial<M extends util.Mask<keyof Shape>>(
|
|
1679
|
+
mask: M & Record<Exclude<keyof M, keyof Shape>, never>
|
|
1680
|
+
): YatspObject<
|
|
1681
|
+
{
|
|
1682
|
+
-readonly [k in keyof Shape]: k extends keyof M ? YatspExactOptional<Shape[k]> : Shape[k];
|
|
1683
|
+
},
|
|
1684
|
+
Config
|
|
1685
|
+
>;
|
|
1686
|
+
|
|
1687
|
+
// required
|
|
1688
|
+
required(): YatspObject<
|
|
1689
|
+
{
|
|
1690
|
+
-readonly [k in keyof Shape]: YatspNonOptional<Shape[k]>;
|
|
1691
|
+
},
|
|
1692
|
+
Config
|
|
1693
|
+
>;
|
|
1694
|
+
required<M extends util.Mask<keyof Shape>>(
|
|
1695
|
+
mask: M & Record<Exclude<keyof M, keyof Shape>, never>
|
|
1696
|
+
): YatspObject<
|
|
1697
|
+
{
|
|
1698
|
+
-readonly [k in keyof Shape]: k extends keyof M ? YatspNonOptional<Shape[k]> : Shape[k];
|
|
1699
|
+
},
|
|
1700
|
+
Config
|
|
1701
|
+
>;
|
|
1702
|
+
}
|
|
1703
|
+
|
|
1704
|
+
export const YatspObject: core.$constructor<YatspObject> = /*@__PURE__*/ core.$constructor<YatspObject>(
|
|
1705
|
+
"YatspObject",
|
|
1706
|
+
(inst, def) => {
|
|
1707
|
+
_ensureDefaultMemoizer();
|
|
1708
|
+
core.$YatspObjectJIT.init(inst, def);
|
|
1709
|
+
YatspType.init(inst, def);
|
|
1710
|
+
inst._yatsp.processJSONSchema = (ctx, json, params) => processors.objectProcessor(inst, ctx, json, params);
|
|
1711
|
+
|
|
1712
|
+
util.installLazyProp(inst, "shape", (self) => self._yatsp.def.shape, false);
|
|
1713
|
+
},
|
|
1714
|
+
{
|
|
1715
|
+
keyof() {
|
|
1716
|
+
return _enum(Object.keys(this._yatsp.def.shape));
|
|
1717
|
+
},
|
|
1718
|
+
catchall(catchall) {
|
|
1719
|
+
// `mergeDefs` rather than a spread: spreading reads `shape`, and resolving it can mint a whole fresh subtree
|
|
1720
|
+
return this.clone(util.mergeDefs(this._yatsp.def, { catchall: catchall as any }));
|
|
1721
|
+
},
|
|
1722
|
+
passthrough() {
|
|
1723
|
+
return this.clone(util.mergeDefs(this._yatsp.def, { catchall: unknown() }));
|
|
1724
|
+
},
|
|
1725
|
+
loose() {
|
|
1726
|
+
return this.clone(util.mergeDefs(this._yatsp.def, { catchall: unknown() }));
|
|
1727
|
+
},
|
|
1728
|
+
strict() {
|
|
1729
|
+
return this.clone(util.mergeDefs(this._yatsp.def, { catchall: never() }));
|
|
1730
|
+
},
|
|
1731
|
+
strip() {
|
|
1732
|
+
return this.clone(util.mergeDefs(this._yatsp.def, { catchall: undefined }));
|
|
1733
|
+
},
|
|
1734
|
+
extend(incoming) {
|
|
1735
|
+
return util.extend(this, incoming);
|
|
1736
|
+
},
|
|
1737
|
+
safeExtend(incoming) {
|
|
1738
|
+
return util.safeExtend(this, incoming);
|
|
1739
|
+
},
|
|
1740
|
+
merge(other) {
|
|
1741
|
+
return util.merge(this, other);
|
|
1742
|
+
},
|
|
1743
|
+
pick(mask) {
|
|
1744
|
+
return util.pick(this, mask);
|
|
1745
|
+
},
|
|
1746
|
+
omit(mask) {
|
|
1747
|
+
return util.omit(this, mask);
|
|
1748
|
+
},
|
|
1749
|
+
partial(...args) {
|
|
1750
|
+
return util.partial(YatspOptional, this, args[0]);
|
|
1751
|
+
},
|
|
1752
|
+
exactPartial(...args) {
|
|
1753
|
+
return util.partial(YatspExactOptional, this, args[0], "exactPartial");
|
|
1754
|
+
},
|
|
1755
|
+
required(...args) {
|
|
1756
|
+
return util.required(YatspNonOptional, this, args[0]);
|
|
1757
|
+
},
|
|
1758
|
+
}
|
|
1759
|
+
);
|
|
1760
|
+
|
|
1761
|
+
export function object<T extends core.$YatspLooseShape = Partial<Record<never, core.SomeType>>>(
|
|
1762
|
+
shape?: T,
|
|
1763
|
+
params?: string | core.$YatspObjectParams
|
|
1764
|
+
): YatspObject<util.Writeable<T>, core.$strip> {
|
|
1765
|
+
const def: core.$YatspObjectDef = {
|
|
1766
|
+
type: "object",
|
|
1767
|
+
shape: shape ?? {},
|
|
1768
|
+
...util.normalizeParams(params),
|
|
1769
|
+
};
|
|
1770
|
+
return new YatspObject(def) as any;
|
|
1771
|
+
}
|
|
1772
|
+
|
|
1773
|
+
// strictObject
|
|
1774
|
+
|
|
1775
|
+
export function strictObject<T extends core.$YatspLooseShape>(
|
|
1776
|
+
shape: T,
|
|
1777
|
+
params?: string | core.$YatspObjectParams
|
|
1778
|
+
): YatspObject<util.Writeable<T>, core.$strict> {
|
|
1779
|
+
return new YatspObject({
|
|
1780
|
+
type: "object",
|
|
1781
|
+
shape,
|
|
1782
|
+
catchall: never(),
|
|
1783
|
+
...util.normalizeParams(params),
|
|
1784
|
+
}) as any;
|
|
1785
|
+
}
|
|
1786
|
+
|
|
1787
|
+
// looseObject
|
|
1788
|
+
|
|
1789
|
+
export function looseObject<T extends core.$YatspLooseShape>(
|
|
1790
|
+
shape: T,
|
|
1791
|
+
params?: string | core.$YatspObjectParams
|
|
1792
|
+
): YatspObject<util.Writeable<T>, core.$loose> {
|
|
1793
|
+
return new YatspObject({
|
|
1794
|
+
type: "object",
|
|
1795
|
+
shape,
|
|
1796
|
+
catchall: unknown(),
|
|
1797
|
+
...util.normalizeParams(params),
|
|
1798
|
+
}) as any;
|
|
1799
|
+
}
|
|
1800
|
+
|
|
1801
|
+
// YatspUnion
|
|
1802
|
+
export interface YatspUnion<T extends readonly core.SomeType[] = readonly core.$YatspType[]>
|
|
1803
|
+
extends _YatspType<core.$YatspUnionInternals<T>>,
|
|
1804
|
+
core.$YatspUnion<T> {
|
|
1805
|
+
"~standard": YatspStandardSchemaWithJSON<this>;
|
|
1806
|
+
options: T;
|
|
1807
|
+
}
|
|
1808
|
+
export const YatspUnion: core.$constructor<YatspUnion> = /*@__PURE__*/ core.$constructor("YatspUnion", (inst, def) => {
|
|
1809
|
+
core.$YatspUnion.init(inst, def);
|
|
1810
|
+
YatspType.init(inst, def);
|
|
1811
|
+
inst._yatsp.processJSONSchema = (ctx, json, params) => processors.unionProcessor(inst, ctx, json, params);
|
|
1812
|
+
inst.options = def.options;
|
|
1813
|
+
});
|
|
1814
|
+
|
|
1815
|
+
export function union<const T extends readonly core.SomeType[]>(
|
|
1816
|
+
options: T,
|
|
1817
|
+
params?: string | core.$YatspUnionParams
|
|
1818
|
+
): YatspUnion<T> {
|
|
1819
|
+
return new YatspUnion({
|
|
1820
|
+
type: "union",
|
|
1821
|
+
options: options as any as core.$YatspType[],
|
|
1822
|
+
...util.normalizeParams(params),
|
|
1823
|
+
}) as any;
|
|
1824
|
+
}
|
|
1825
|
+
|
|
1826
|
+
// YatspXor
|
|
1827
|
+
export interface YatspXor<T extends readonly core.SomeType[] = readonly core.$YatspType[]>
|
|
1828
|
+
extends _YatspType<core.$YatspXorInternals<T>>,
|
|
1829
|
+
core.$YatspXor<T> {
|
|
1830
|
+
"~standard": YatspStandardSchemaWithJSON<this>;
|
|
1831
|
+
options: T;
|
|
1832
|
+
}
|
|
1833
|
+
export const YatspXor: core.$constructor<YatspXor> = /*@__PURE__*/ core.$constructor("YatspXor", (inst, def) => {
|
|
1834
|
+
YatspUnion.init(inst, def);
|
|
1835
|
+
core.$YatspXor.init(inst, def);
|
|
1836
|
+
inst._yatsp.processJSONSchema = (ctx, json, params) => processors.unionProcessor(inst, ctx, json, params);
|
|
1837
|
+
inst.options = def.options;
|
|
1838
|
+
});
|
|
1839
|
+
|
|
1840
|
+
/** Creates an exclusive union (XOR) where exactly one option must match.
|
|
1841
|
+
* Unlike regular unions that succeed when any option matches, xor fails if
|
|
1842
|
+
* zero or more than one option matches the input. */
|
|
1843
|
+
export function xor<const T extends readonly core.SomeType[]>(
|
|
1844
|
+
options: T,
|
|
1845
|
+
params?: string | core.$YatspXorParams
|
|
1846
|
+
): YatspXor<T> {
|
|
1847
|
+
return new YatspXor({
|
|
1848
|
+
type: "union",
|
|
1849
|
+
options: options as any as core.$YatspType[],
|
|
1850
|
+
inclusive: false,
|
|
1851
|
+
...util.normalizeParams(params),
|
|
1852
|
+
}) as any;
|
|
1853
|
+
}
|
|
1854
|
+
|
|
1855
|
+
// YatspDiscriminatedUnion
|
|
1856
|
+
export interface YatspDiscriminatedUnion<
|
|
1857
|
+
Options extends readonly core.SomeType[] = readonly core.$YatspType[],
|
|
1858
|
+
Disc extends string = string,
|
|
1859
|
+
> extends YatspUnion<Options>,
|
|
1860
|
+
core.$YatspDiscriminatedUnion<Options, Disc> {
|
|
1861
|
+
"~standard": YatspStandardSchemaWithJSON<this>;
|
|
1862
|
+
_yatsp: core.$YatspDiscriminatedUnionInternals<Options, Disc>;
|
|
1863
|
+
def: core.$YatspDiscriminatedUnionDef<Options, Disc>;
|
|
1864
|
+
}
|
|
1865
|
+
export const YatspDiscriminatedUnion: core.$constructor<YatspDiscriminatedUnion> = /*@__PURE__*/ core.$constructor(
|
|
1866
|
+
"YatspDiscriminatedUnion",
|
|
1867
|
+
(inst, def) => {
|
|
1868
|
+
YatspUnion.init(inst, def);
|
|
1869
|
+
core.$YatspDiscriminatedUnion.init(inst, def);
|
|
1870
|
+
}
|
|
1871
|
+
);
|
|
1872
|
+
|
|
1873
|
+
export function discriminatedUnion<
|
|
1874
|
+
Types extends readonly [core.$YatspTypeDiscriminable, ...core.$YatspTypeDiscriminable[]],
|
|
1875
|
+
Disc extends string,
|
|
1876
|
+
>(
|
|
1877
|
+
discriminator: Disc,
|
|
1878
|
+
options: Types,
|
|
1879
|
+
params?: string | core.$YatspDiscriminatedUnionParams
|
|
1880
|
+
): YatspDiscriminatedUnion<Types, Disc> {
|
|
1881
|
+
// const [options, params] = args;
|
|
1882
|
+
return new YatspDiscriminatedUnion({
|
|
1883
|
+
type: "union",
|
|
1884
|
+
options: options as any as core.$YatspType[],
|
|
1885
|
+
discriminator,
|
|
1886
|
+
...util.normalizeParams(params),
|
|
1887
|
+
}) as any;
|
|
1888
|
+
}
|
|
1889
|
+
|
|
1890
|
+
// YatspIntersection
|
|
1891
|
+
export interface YatspIntersection<A extends core.SomeType = core.$YatspType, B extends core.SomeType = core.$YatspType>
|
|
1892
|
+
extends _YatspType<core.$YatspIntersectionInternals<A, B>>,
|
|
1893
|
+
core.$YatspIntersection<A, B> {
|
|
1894
|
+
"~standard": YatspStandardSchemaWithJSON<this>;
|
|
1895
|
+
}
|
|
1896
|
+
export const YatspIntersection: core.$constructor<YatspIntersection> = /*@__PURE__*/ core.$constructor(
|
|
1897
|
+
"YatspIntersection",
|
|
1898
|
+
(inst, def) => {
|
|
1899
|
+
core.$YatspIntersection.init(inst, def);
|
|
1900
|
+
YatspType.init(inst, def);
|
|
1901
|
+
inst._yatsp.processJSONSchema = (ctx, json, params) => processors.intersectionProcessor(inst, ctx, json, params);
|
|
1902
|
+
}
|
|
1903
|
+
);
|
|
1904
|
+
|
|
1905
|
+
export function intersection<T extends core.SomeType, U extends core.SomeType>(
|
|
1906
|
+
left: T,
|
|
1907
|
+
right: U
|
|
1908
|
+
): YatspIntersection<T, U> {
|
|
1909
|
+
return new YatspIntersection({
|
|
1910
|
+
type: "intersection",
|
|
1911
|
+
left: left as any as core.$YatspType,
|
|
1912
|
+
right: right as any as core.$YatspType,
|
|
1913
|
+
}) as any;
|
|
1914
|
+
}
|
|
1915
|
+
|
|
1916
|
+
// YatspTuple
|
|
1917
|
+
export interface YatspTuple<
|
|
1918
|
+
T extends util.TupleItems = readonly core.$YatspType[],
|
|
1919
|
+
Rest extends core.SomeType | null = core.$YatspType | null,
|
|
1920
|
+
> extends _YatspType<core.$YatspTupleInternals<T, Rest>>,
|
|
1921
|
+
core.$YatspTuple<T, Rest> {
|
|
1922
|
+
"~standard": YatspStandardSchemaWithJSON<this>;
|
|
1923
|
+
rest<Rest extends core.SomeType = core.$YatspType>(rest: Rest): YatspTuple<T, Rest>;
|
|
1924
|
+
partial(): YatspTuple<{ -readonly [k in keyof T]: YatspOptional<T[k]> }, Rest>;
|
|
1925
|
+
}
|
|
1926
|
+
export const YatspTuple: core.$constructor<YatspTuple> = /*@__PURE__*/ core.$constructor<YatspTuple>(
|
|
1927
|
+
"YatspTuple",
|
|
1928
|
+
(inst, def) => {
|
|
1929
|
+
_ensureDefaultMemoizer();
|
|
1930
|
+
core.$YatspTuple.init(inst, def);
|
|
1931
|
+
YatspType.init(inst, def);
|
|
1932
|
+
inst._yatsp.processJSONSchema = (ctx, json, params) => processors.tupleProcessor(inst, ctx, json, params);
|
|
1933
|
+
},
|
|
1934
|
+
{
|
|
1935
|
+
rest(rest) {
|
|
1936
|
+
return this.clone({
|
|
1937
|
+
...this._yatsp.def,
|
|
1938
|
+
rest: rest as any as core.$YatspType,
|
|
1939
|
+
}) as any;
|
|
1940
|
+
},
|
|
1941
|
+
partial() {
|
|
1942
|
+
const def = this._yatsp.def;
|
|
1943
|
+
// a refinement was authored against the full arity; partialing would run it on a shorter array
|
|
1944
|
+
if (def.checks?.length) throw new Error(".partial() cannot be used on tuple schemas containing refinements");
|
|
1945
|
+
return this.clone({
|
|
1946
|
+
...def,
|
|
1947
|
+
items: def.items.map((item) => new YatspOptional({ type: "optional", innerType: item })),
|
|
1948
|
+
}) as any;
|
|
1949
|
+
},
|
|
1950
|
+
}
|
|
1951
|
+
);
|
|
1952
|
+
|
|
1953
|
+
export function tuple<T extends readonly [core.SomeType, ...core.SomeType[]]>(
|
|
1954
|
+
items: T,
|
|
1955
|
+
params?: string | core.$YatspTupleParams
|
|
1956
|
+
): YatspTuple<T, null>;
|
|
1957
|
+
export function tuple<T extends readonly [core.SomeType, ...core.SomeType[]], Rest extends core.SomeType>(
|
|
1958
|
+
items: T,
|
|
1959
|
+
rest: Rest,
|
|
1960
|
+
params?: string | core.$YatspTupleParams
|
|
1961
|
+
): YatspTuple<T, Rest>;
|
|
1962
|
+
export function tuple(items: [], params?: string | core.$YatspTupleParams): YatspTuple<[], null>;
|
|
1963
|
+
export function tuple(
|
|
1964
|
+
items: core.SomeType[],
|
|
1965
|
+
_paramsOrRest?: string | core.$YatspTupleParams | core.SomeType,
|
|
1966
|
+
_params?: string | core.$YatspTupleParams
|
|
1967
|
+
) {
|
|
1968
|
+
const hasRest = _paramsOrRest instanceof core.$YatspType;
|
|
1969
|
+
const params = hasRest ? _params : _paramsOrRest;
|
|
1970
|
+
const rest = hasRest ? _paramsOrRest : null;
|
|
1971
|
+
return new YatspTuple({
|
|
1972
|
+
type: "tuple",
|
|
1973
|
+
items: items as any as core.$YatspType[],
|
|
1974
|
+
rest,
|
|
1975
|
+
...util.normalizeParams(params),
|
|
1976
|
+
});
|
|
1977
|
+
}
|
|
1978
|
+
|
|
1979
|
+
// YatspRecord
|
|
1980
|
+
export interface YatspRecord<
|
|
1981
|
+
Key extends core.$YatspRecordKey = core.$YatspRecordKey,
|
|
1982
|
+
Value extends core.SomeType = core.$YatspType,
|
|
1983
|
+
> extends _YatspType<core.$YatspRecordInternals<Key, Value>>,
|
|
1984
|
+
core.$YatspRecord<Key, Value> {
|
|
1985
|
+
"~standard": YatspStandardSchemaWithJSON<this>;
|
|
1986
|
+
keyType: Key;
|
|
1987
|
+
valueType: Value;
|
|
1988
|
+
}
|
|
1989
|
+
export const YatspRecord: core.$constructor<YatspRecord> = /*@__PURE__*/ core.$constructor(
|
|
1990
|
+
"YatspRecord",
|
|
1991
|
+
(inst, def) => {
|
|
1992
|
+
_ensureDefaultMemoizer();
|
|
1993
|
+
core.$YatspRecord.init(inst, def);
|
|
1994
|
+
YatspType.init(inst, def);
|
|
1995
|
+
inst._yatsp.processJSONSchema = (ctx, json, params) => processors.recordProcessor(inst, ctx, json, params);
|
|
1996
|
+
|
|
1997
|
+
inst.keyType = def.keyType;
|
|
1998
|
+
inst.valueType = def.valueType;
|
|
1999
|
+
}
|
|
2000
|
+
);
|
|
2001
|
+
|
|
2002
|
+
export function record<Key extends core.$YatspRecordKey, Value extends core.SomeType>(
|
|
2003
|
+
keyType: Key,
|
|
2004
|
+
valueType: Value,
|
|
2005
|
+
params?: string | core.$YatspRecordParams
|
|
2006
|
+
): YatspRecord<Key, Value> {
|
|
2007
|
+
// v3-compat: z.record(valueType, params?) — defaults keyType to z.string()
|
|
2008
|
+
if (!valueType || !(valueType as any)._yatsp) {
|
|
2009
|
+
return new YatspRecord({
|
|
2010
|
+
type: "record",
|
|
2011
|
+
keyType: string() as any,
|
|
2012
|
+
valueType: keyType as any as core.$YatspType,
|
|
2013
|
+
...util.normalizeParams(valueType as string | core.$YatspRecordParams | undefined),
|
|
2014
|
+
}) as any;
|
|
2015
|
+
}
|
|
2016
|
+
return new YatspRecord({
|
|
2017
|
+
type: "record",
|
|
2018
|
+
keyType,
|
|
2019
|
+
valueType: valueType as any as core.$YatspType,
|
|
2020
|
+
...util.normalizeParams(params),
|
|
2021
|
+
}) as any;
|
|
2022
|
+
}
|
|
2023
|
+
// type alksjf = core.output<core.$YatspRecordKey>;
|
|
2024
|
+
export function partialRecord<Key extends core.$YatspRecordKey, Value extends core.SomeType>(
|
|
2025
|
+
keyType: Key,
|
|
2026
|
+
valueType: Value,
|
|
2027
|
+
params?: string | core.$YatspRecordParams
|
|
2028
|
+
): YatspRecord<Key & core.$partial, Value> {
|
|
2029
|
+
return new YatspRecord({
|
|
2030
|
+
type: "record",
|
|
2031
|
+
keyType,
|
|
2032
|
+
valueType: valueType as any,
|
|
2033
|
+
...util.normalizeParams(params),
|
|
2034
|
+
partial: true,
|
|
2035
|
+
}) as any;
|
|
2036
|
+
}
|
|
2037
|
+
|
|
2038
|
+
export function looseRecord<Key extends core.$YatspRecordKey, Value extends core.SomeType>(
|
|
2039
|
+
keyType: Key,
|
|
2040
|
+
valueType: Value,
|
|
2041
|
+
params?: string | core.$YatspRecordParams
|
|
2042
|
+
): YatspRecord<Key, Value> {
|
|
2043
|
+
return new YatspRecord({
|
|
2044
|
+
type: "record",
|
|
2045
|
+
keyType,
|
|
2046
|
+
valueType: valueType as any as core.$YatspType,
|
|
2047
|
+
mode: "loose",
|
|
2048
|
+
...util.normalizeParams(params),
|
|
2049
|
+
}) as any;
|
|
2050
|
+
}
|
|
2051
|
+
|
|
2052
|
+
// YatspMap
|
|
2053
|
+
export interface YatspMap<Key extends core.SomeType = core.$YatspType, Value extends core.SomeType = core.$YatspType>
|
|
2054
|
+
extends _YatspType<core.$YatspMapInternals<Key, Value>>,
|
|
2055
|
+
core.$YatspMap<Key, Value> {
|
|
2056
|
+
"~standard": YatspStandardSchemaWithJSON<this>;
|
|
2057
|
+
keyType: Key;
|
|
2058
|
+
valueType: Value;
|
|
2059
|
+
min(minSize: number, params?: string | core.$YatspCheckMinSizeParams): this;
|
|
2060
|
+
nonempty(params?: string | core.$YatspCheckMinSizeParams): this;
|
|
2061
|
+
max(maxSize: number, params?: string | core.$YatspCheckMaxSizeParams): this;
|
|
2062
|
+
size(size: number, params?: string | core.$YatspCheckSizeEqualsParams): this;
|
|
2063
|
+
}
|
|
2064
|
+
export const YatspMap: core.$constructor<YatspMap> = /*@__PURE__*/ core.$constructor("YatspMap", (inst, def) => {
|
|
2065
|
+
_ensureDefaultMemoizer();
|
|
2066
|
+
core.$YatspMap.init(inst, def);
|
|
2067
|
+
YatspType.init(inst, def);
|
|
2068
|
+
inst._yatsp.processJSONSchema = (ctx, json, params) => processors.mapProcessor(inst, ctx, json, params);
|
|
2069
|
+
inst.keyType = def.keyType;
|
|
2070
|
+
inst.valueType = def.valueType;
|
|
2071
|
+
inst.min = (...args) => inst.check(core._minSize(...args));
|
|
2072
|
+
inst.nonempty = (params) => inst.check(core._minSize(1, params));
|
|
2073
|
+
inst.max = (...args) => inst.check(core._maxSize(...args));
|
|
2074
|
+
inst.size = (...args) => inst.check(core._size(...args));
|
|
2075
|
+
});
|
|
2076
|
+
|
|
2077
|
+
export function map<Key extends core.SomeType, Value extends core.SomeType>(
|
|
2078
|
+
keyType: Key,
|
|
2079
|
+
valueType: Value,
|
|
2080
|
+
params?: string | core.$YatspMapParams
|
|
2081
|
+
): YatspMap<Key, Value> {
|
|
2082
|
+
return new YatspMap({
|
|
2083
|
+
type: "map",
|
|
2084
|
+
keyType: keyType as any as core.$YatspType,
|
|
2085
|
+
valueType: valueType as any as core.$YatspType,
|
|
2086
|
+
...util.normalizeParams(params),
|
|
2087
|
+
}) as any;
|
|
2088
|
+
}
|
|
2089
|
+
|
|
2090
|
+
// YatspSet
|
|
2091
|
+
export interface YatspSet<T extends core.SomeType = core.$YatspType>
|
|
2092
|
+
extends _YatspType<core.$YatspSetInternals<T>>,
|
|
2093
|
+
core.$YatspSet<T> {
|
|
2094
|
+
"~standard": YatspStandardSchemaWithJSON<this>;
|
|
2095
|
+
min(minSize: number, params?: string | core.$YatspCheckMinSizeParams): this;
|
|
2096
|
+
nonempty(params?: string | core.$YatspCheckMinSizeParams): this;
|
|
2097
|
+
max(maxSize: number, params?: string | core.$YatspCheckMaxSizeParams): this;
|
|
2098
|
+
size(size: number, params?: string | core.$YatspCheckSizeEqualsParams): this;
|
|
2099
|
+
}
|
|
2100
|
+
export const YatspSet: core.$constructor<YatspSet> = /*@__PURE__*/ core.$constructor("YatspSet", (inst, def) => {
|
|
2101
|
+
_ensureDefaultMemoizer();
|
|
2102
|
+
core.$YatspSet.init(inst, def);
|
|
2103
|
+
YatspType.init(inst, def);
|
|
2104
|
+
inst._yatsp.processJSONSchema = (ctx, json, params) => processors.setProcessor(inst, ctx, json, params);
|
|
2105
|
+
|
|
2106
|
+
inst.min = (...args) => inst.check(core._minSize(...args));
|
|
2107
|
+
inst.nonempty = (params) => inst.check(core._minSize(1, params));
|
|
2108
|
+
inst.max = (...args) => inst.check(core._maxSize(...args));
|
|
2109
|
+
inst.size = (...args) => inst.check(core._size(...args));
|
|
2110
|
+
});
|
|
2111
|
+
|
|
2112
|
+
export function set<Value extends core.SomeType>(
|
|
2113
|
+
valueType: Value,
|
|
2114
|
+
params?: string | core.$YatspSetParams
|
|
2115
|
+
): YatspSet<Value> {
|
|
2116
|
+
return new YatspSet({
|
|
2117
|
+
type: "set",
|
|
2118
|
+
valueType: valueType as any as core.$YatspType,
|
|
2119
|
+
...util.normalizeParams(params),
|
|
2120
|
+
}) as any;
|
|
2121
|
+
}
|
|
2122
|
+
|
|
2123
|
+
// YatspEnum
|
|
2124
|
+
export interface YatspEnum<
|
|
2125
|
+
/** @ts-ignore Cast variance */
|
|
2126
|
+
out T extends util.EnumLike = util.EnumLike,
|
|
2127
|
+
> extends _YatspType<core.$YatspEnumInternals<T>>,
|
|
2128
|
+
core.$YatspEnum<T> {
|
|
2129
|
+
"~standard": YatspStandardSchemaWithJSON<this>;
|
|
2130
|
+
enum: T;
|
|
2131
|
+
options: Array<T[keyof T]>;
|
|
2132
|
+
|
|
2133
|
+
extract<const U extends readonly (keyof T)[]>(
|
|
2134
|
+
values: U,
|
|
2135
|
+
params?: string | core.$YatspEnumParams
|
|
2136
|
+
): YatspEnum<util.Flatten<Pick<T, U[number]>>>;
|
|
2137
|
+
exclude<const U extends readonly (keyof T)[]>(
|
|
2138
|
+
values: U,
|
|
2139
|
+
params?: string | core.$YatspEnumParams
|
|
2140
|
+
): YatspEnum<util.Flatten<Omit<T, U[number]>>>;
|
|
2141
|
+
}
|
|
2142
|
+
export const YatspEnum: core.$constructor<YatspEnum> = /*@__PURE__*/ core.$constructor("YatspEnum", (inst, def) => {
|
|
2143
|
+
core.$YatspEnum.init(inst, def);
|
|
2144
|
+
YatspType.init(inst, def);
|
|
2145
|
+
inst._yatsp.processJSONSchema = (ctx, json, params) => processors.enumProcessor(inst, ctx, json, params);
|
|
2146
|
+
|
|
2147
|
+
inst.enum = def.entries;
|
|
2148
|
+
// reuse the parsed value set so a numeric TS enum's reverse-mapping keys stay out
|
|
2149
|
+
inst.options = [...inst._yatsp.values] as util.EnumValue[];
|
|
2150
|
+
|
|
2151
|
+
const keys = new Set(Object.keys(def.entries));
|
|
2152
|
+
|
|
2153
|
+
inst.extract = (values, params) => {
|
|
2154
|
+
const newEntries: Record<string, any> = {};
|
|
2155
|
+
for (const value of values) {
|
|
2156
|
+
if (keys.has(value)) {
|
|
2157
|
+
newEntries[value] = def.entries[value];
|
|
2158
|
+
} else throw new Error(`Key ${value} not found in enum`);
|
|
2159
|
+
}
|
|
2160
|
+
return new YatspEnum({
|
|
2161
|
+
...def,
|
|
2162
|
+
checks: [],
|
|
2163
|
+
...util.normalizeParams(params),
|
|
2164
|
+
entries: newEntries,
|
|
2165
|
+
}) as any;
|
|
2166
|
+
};
|
|
2167
|
+
|
|
2168
|
+
inst.exclude = (values, params) => {
|
|
2169
|
+
const newEntries: Record<string, any> = { ...def.entries };
|
|
2170
|
+
for (const value of values) {
|
|
2171
|
+
if (keys.has(value)) {
|
|
2172
|
+
delete newEntries[value];
|
|
2173
|
+
} else throw new Error(`Key ${value} not found in enum`);
|
|
2174
|
+
}
|
|
2175
|
+
return new YatspEnum({
|
|
2176
|
+
...def,
|
|
2177
|
+
checks: [],
|
|
2178
|
+
...util.normalizeParams(params),
|
|
2179
|
+
entries: newEntries,
|
|
2180
|
+
}) as any;
|
|
2181
|
+
};
|
|
2182
|
+
});
|
|
2183
|
+
|
|
2184
|
+
function _enum<const T extends readonly string[]>(
|
|
2185
|
+
values: T,
|
|
2186
|
+
params?: string | core.$YatspEnumParams
|
|
2187
|
+
): YatspEnum<util.ToEnum<T[number]>>;
|
|
2188
|
+
function _enum<const T extends util.EnumLike>(entries: T, params?: string | core.$YatspEnumParams): YatspEnum<T>;
|
|
2189
|
+
function _enum(values: any, params?: string | core.$YatspEnumParams) {
|
|
2190
|
+
const entries: any = Array.isArray(values) ? Object.fromEntries(values.map((v) => [v, v])) : values;
|
|
2191
|
+
|
|
2192
|
+
return new YatspEnum({
|
|
2193
|
+
type: "enum",
|
|
2194
|
+
entries,
|
|
2195
|
+
...util.normalizeParams(params),
|
|
2196
|
+
}) as any;
|
|
2197
|
+
}
|
|
2198
|
+
export { _enum as enum };
|
|
2199
|
+
|
|
2200
|
+
/** @deprecated This API has been merged into `z.enum()`. Use `z.enum()` instead.
|
|
2201
|
+
*
|
|
2202
|
+
* ```ts
|
|
2203
|
+
* enum Colors { red, green, blue }
|
|
2204
|
+
* z.enum(Colors);
|
|
2205
|
+
* ```
|
|
2206
|
+
*/
|
|
2207
|
+
export function nativeEnum<T extends util.EnumLike>(entries: T, params?: string | core.$YatspEnumParams): YatspEnum<T> {
|
|
2208
|
+
return new YatspEnum({
|
|
2209
|
+
type: "enum",
|
|
2210
|
+
entries,
|
|
2211
|
+
...util.normalizeParams(params),
|
|
2212
|
+
}) as YatspEnum<T>;
|
|
2213
|
+
}
|
|
2214
|
+
|
|
2215
|
+
// YatspLiteral
|
|
2216
|
+
export interface YatspLiteral<T extends util.Literal = util.Literal>
|
|
2217
|
+
extends _YatspType<core.$YatspLiteralInternals<T>>,
|
|
2218
|
+
core.$YatspLiteral<T> {
|
|
2219
|
+
"~standard": YatspStandardSchemaWithJSON<this>;
|
|
2220
|
+
values: Set<T>;
|
|
2221
|
+
/** @legacy Use `.values` instead. Accessing this property will throw an error if the literal accepts multiple values. */
|
|
2222
|
+
value: T;
|
|
2223
|
+
}
|
|
2224
|
+
export const YatspLiteral: core.$constructor<YatspLiteral> = /*@__PURE__*/ core.$constructor(
|
|
2225
|
+
"YatspLiteral",
|
|
2226
|
+
(inst, def) => {
|
|
2227
|
+
core.$YatspLiteral.init(inst, def);
|
|
2228
|
+
YatspType.init(inst, def);
|
|
2229
|
+
inst._yatsp.processJSONSchema = (ctx, json, params) => processors.literalProcessor(inst, ctx, json, params);
|
|
2230
|
+
inst.values = new Set(def.values);
|
|
2231
|
+
Object.defineProperty(inst, "value", {
|
|
2232
|
+
get() {
|
|
2233
|
+
if (def.values.length > 1) {
|
|
2234
|
+
throw new Error("This schema contains multiple valid literal values. Use `.values` instead.");
|
|
2235
|
+
}
|
|
2236
|
+
return def.values[0];
|
|
2237
|
+
},
|
|
2238
|
+
});
|
|
2239
|
+
}
|
|
2240
|
+
);
|
|
2241
|
+
|
|
2242
|
+
export function literal<const T extends ReadonlyArray<util.Literal>>(
|
|
2243
|
+
value: T,
|
|
2244
|
+
params?: string | core.$YatspLiteralParams
|
|
2245
|
+
): YatspLiteral<T[number]>;
|
|
2246
|
+
export function literal<const T extends util.Literal>(
|
|
2247
|
+
value: T,
|
|
2248
|
+
params?: string | core.$YatspLiteralParams
|
|
2249
|
+
): YatspLiteral<T>;
|
|
2250
|
+
export function literal(value: any, params: any) {
|
|
2251
|
+
return new YatspLiteral({
|
|
2252
|
+
type: "literal",
|
|
2253
|
+
values: Array.isArray(value) ? value : [value],
|
|
2254
|
+
...util.normalizeParams(params),
|
|
2255
|
+
});
|
|
2256
|
+
}
|
|
2257
|
+
|
|
2258
|
+
// YatspFile
|
|
2259
|
+
export interface YatspFile extends _YatspType<core.$YatspFileInternals>, core.$YatspFile {
|
|
2260
|
+
"~standard": YatspStandardSchemaWithJSON<this>;
|
|
2261
|
+
min(size: number, params?: string | core.$YatspCheckMinSizeParams): this;
|
|
2262
|
+
max(size: number, params?: string | core.$YatspCheckMaxSizeParams): this;
|
|
2263
|
+
mime(types: util.MimeTypes | Array<util.MimeTypes>, params?: string | core.$YatspCheckMimeTypeParams): this;
|
|
2264
|
+
}
|
|
2265
|
+
export const YatspFile: core.$constructor<YatspFile> = /*@__PURE__*/ core.$constructor("YatspFile", (inst, def) => {
|
|
2266
|
+
core.$YatspFile.init(inst, def);
|
|
2267
|
+
YatspType.init(inst, def);
|
|
2268
|
+
inst._yatsp.processJSONSchema = (ctx, json, params) => processors.fileProcessor(inst, ctx, json, params);
|
|
2269
|
+
|
|
2270
|
+
inst.min = (size, params) => inst.check(core._minSize(size, params));
|
|
2271
|
+
inst.max = (size, params) => inst.check(core._maxSize(size, params));
|
|
2272
|
+
inst.mime = (types, params) => inst.check(core._mime(Array.isArray(types) ? types : [types], params));
|
|
2273
|
+
});
|
|
2274
|
+
|
|
2275
|
+
export function file(params?: string | core.$YatspFileParams): YatspFile {
|
|
2276
|
+
return core._file(YatspFile, params) as any;
|
|
2277
|
+
}
|
|
2278
|
+
|
|
2279
|
+
// YatspTransform
|
|
2280
|
+
export interface YatspTransform<O = unknown, I = unknown>
|
|
2281
|
+
extends _YatspType<core.$YatspTransformInternals<O, I>>,
|
|
2282
|
+
core.$YatspTransform<O, I> {
|
|
2283
|
+
"~standard": YatspStandardSchemaWithJSON<this>;
|
|
2284
|
+
}
|
|
2285
|
+
export const YatspTransform: core.$constructor<YatspTransform> = /*@__PURE__*/ core.$constructor(
|
|
2286
|
+
"YatspTransform",
|
|
2287
|
+
(inst, def) => {
|
|
2288
|
+
_ensureDefaultMemoizer();
|
|
2289
|
+
core.$YatspTransform.init(inst, def);
|
|
2290
|
+
YatspType.init(inst, def);
|
|
2291
|
+
inst._yatsp.processJSONSchema = (ctx, json, params) => processors.transformProcessor(inst, ctx, json, params);
|
|
2292
|
+
|
|
2293
|
+
inst._yatsp.parse = (payload, _ctx) => {
|
|
2294
|
+
if (_ctx.direction === "backward") {
|
|
2295
|
+
throw new core.$YatspEncodeError(inst.constructor.name);
|
|
2296
|
+
}
|
|
2297
|
+
|
|
2298
|
+
(payload as core.$RefinementCtx).addIssue = (issue) => {
|
|
2299
|
+
if (typeof issue === "string") {
|
|
2300
|
+
payload.issues.push(util.issue(issue, payload.value, def));
|
|
2301
|
+
} else {
|
|
2302
|
+
// for Yatsp 3 backwards compatibility
|
|
2303
|
+
const _issue = issue as any;
|
|
2304
|
+
|
|
2305
|
+
if (_issue.fatal) _issue.continue = false;
|
|
2306
|
+
_issue.code ??= "custom";
|
|
2307
|
+
if (!("input" in _issue)) _issue.input = payload.value;
|
|
2308
|
+
_issue.inst ??= inst;
|
|
2309
|
+
// _issue.continue ??= true;
|
|
2310
|
+
payload.issues.push(util.issue(_issue));
|
|
2311
|
+
}
|
|
2312
|
+
};
|
|
2313
|
+
|
|
2314
|
+
const output = def.transform(payload.value, payload);
|
|
2315
|
+
if (output instanceof Promise) {
|
|
2316
|
+
return output.then((output) => {
|
|
2317
|
+
payload.value = output;
|
|
2318
|
+
return payload;
|
|
2319
|
+
});
|
|
2320
|
+
}
|
|
2321
|
+
payload.value = output;
|
|
2322
|
+
return payload;
|
|
2323
|
+
};
|
|
2324
|
+
}
|
|
2325
|
+
);
|
|
2326
|
+
|
|
2327
|
+
export function transform<I = unknown, O = I>(
|
|
2328
|
+
fn: (input: I, ctx: core.$RefinementCtx) => O
|
|
2329
|
+
): YatspTransform<Awaited<O>, I> {
|
|
2330
|
+
return new YatspTransform({
|
|
2331
|
+
type: "transform",
|
|
2332
|
+
transform: fn as any,
|
|
2333
|
+
}) as any;
|
|
2334
|
+
}
|
|
2335
|
+
|
|
2336
|
+
// YatspOptional
|
|
2337
|
+
export interface YatspOptional<T extends core.SomeType = core.$YatspType>
|
|
2338
|
+
extends _YatspType<core.$YatspOptionalInternals<T>>,
|
|
2339
|
+
core.$YatspOptional<T> {
|
|
2340
|
+
"~standard": YatspStandardSchemaWithJSON<this>;
|
|
2341
|
+
unwrap(): T;
|
|
2342
|
+
}
|
|
2343
|
+
export const YatspOptional: core.$constructor<YatspOptional> = /*@__PURE__*/ core.$constructor(
|
|
2344
|
+
"YatspOptional",
|
|
2345
|
+
(inst, def) => {
|
|
2346
|
+
core.$YatspOptional.init(inst, def);
|
|
2347
|
+
YatspType.init(inst, def);
|
|
2348
|
+
inst._yatsp.processJSONSchema = (ctx, json, params) => processors.optionalProcessor(inst, ctx, json, params);
|
|
2349
|
+
|
|
2350
|
+
inst.unwrap = () => inst._yatsp.def.innerType;
|
|
2351
|
+
}
|
|
2352
|
+
);
|
|
2353
|
+
|
|
2354
|
+
export function optional<T extends core.SomeType>(innerType: T): YatspOptional<T> {
|
|
2355
|
+
return new YatspOptional({
|
|
2356
|
+
type: "optional",
|
|
2357
|
+
innerType: innerType as any as core.$YatspType,
|
|
2358
|
+
}) as any;
|
|
2359
|
+
}
|
|
2360
|
+
|
|
2361
|
+
// YatspExactOptional
|
|
2362
|
+
export interface YatspExactOptional<T extends core.SomeType = core.$YatspType>
|
|
2363
|
+
extends _YatspType<core.$YatspExactOptionalInternals<T>>,
|
|
2364
|
+
core.$YatspExactOptional<T> {
|
|
2365
|
+
"~standard": YatspStandardSchemaWithJSON<this>;
|
|
2366
|
+
unwrap(): T;
|
|
2367
|
+
}
|
|
2368
|
+
export const YatspExactOptional: core.$constructor<YatspExactOptional> = /*@__PURE__*/ core.$constructor(
|
|
2369
|
+
"YatspExactOptional",
|
|
2370
|
+
(inst, def) => {
|
|
2371
|
+
core.$YatspExactOptional.init(inst, def);
|
|
2372
|
+
YatspType.init(inst, def);
|
|
2373
|
+
inst._yatsp.processJSONSchema = (ctx, json, params) => processors.optionalProcessor(inst, ctx, json, params);
|
|
2374
|
+
|
|
2375
|
+
inst.unwrap = () => inst._yatsp.def.innerType;
|
|
2376
|
+
}
|
|
2377
|
+
);
|
|
2378
|
+
|
|
2379
|
+
export function exactOptional<T extends core.SomeType>(innerType: T): YatspExactOptional<T> {
|
|
2380
|
+
return new YatspExactOptional({
|
|
2381
|
+
type: "optional",
|
|
2382
|
+
innerType: innerType as any as core.$YatspType,
|
|
2383
|
+
}) as any;
|
|
2384
|
+
}
|
|
2385
|
+
|
|
2386
|
+
// YatspNullable
|
|
2387
|
+
export interface YatspNullable<T extends core.SomeType = core.$YatspType>
|
|
2388
|
+
extends _YatspType<core.$YatspNullableInternals<T>>,
|
|
2389
|
+
core.$YatspNullable<T> {
|
|
2390
|
+
"~standard": YatspStandardSchemaWithJSON<this>;
|
|
2391
|
+
unwrap(): T;
|
|
2392
|
+
}
|
|
2393
|
+
export const YatspNullable: core.$constructor<YatspNullable> = /*@__PURE__*/ core.$constructor(
|
|
2394
|
+
"YatspNullable",
|
|
2395
|
+
(inst, def) => {
|
|
2396
|
+
core.$YatspNullable.init(inst, def);
|
|
2397
|
+
YatspType.init(inst, def);
|
|
2398
|
+
inst._yatsp.processJSONSchema = (ctx, json, params) => processors.nullableProcessor(inst, ctx, json, params);
|
|
2399
|
+
|
|
2400
|
+
inst.unwrap = () => inst._yatsp.def.innerType;
|
|
2401
|
+
}
|
|
2402
|
+
);
|
|
2403
|
+
|
|
2404
|
+
export function nullable<T extends core.SomeType>(innerType: T): YatspNullable<T> {
|
|
2405
|
+
return new YatspNullable({
|
|
2406
|
+
type: "nullable",
|
|
2407
|
+
innerType: innerType as any as core.$YatspType,
|
|
2408
|
+
}) as any;
|
|
2409
|
+
}
|
|
2410
|
+
|
|
2411
|
+
// nullish
|
|
2412
|
+
export function nullish<T extends core.SomeType>(innerType: T): YatspOptional<YatspNullable<T>> {
|
|
2413
|
+
return optional(nullable(innerType));
|
|
2414
|
+
}
|
|
2415
|
+
|
|
2416
|
+
// YatspDefault
|
|
2417
|
+
export interface YatspDefault<T extends core.SomeType = core.$YatspType>
|
|
2418
|
+
extends _YatspType<core.$YatspDefaultInternals<T>>,
|
|
2419
|
+
core.$YatspDefault<T> {
|
|
2420
|
+
"~standard": YatspStandardSchemaWithJSON<this>;
|
|
2421
|
+
unwrap(): T;
|
|
2422
|
+
/** @deprecated Use `.unwrap()` instead. */
|
|
2423
|
+
removeDefault(): T;
|
|
2424
|
+
}
|
|
2425
|
+
export const YatspDefault: core.$constructor<YatspDefault> = /*@__PURE__*/ core.$constructor(
|
|
2426
|
+
"YatspDefault",
|
|
2427
|
+
(inst, def) => {
|
|
2428
|
+
core.$YatspDefault.init(inst, def);
|
|
2429
|
+
YatspType.init(inst, def);
|
|
2430
|
+
inst._yatsp.processJSONSchema = (ctx, json, params) => processors.defaultProcessor(inst, ctx, json, params);
|
|
2431
|
+
|
|
2432
|
+
inst.unwrap = () => inst._yatsp.def.innerType;
|
|
2433
|
+
inst.removeDefault = inst.unwrap;
|
|
2434
|
+
}
|
|
2435
|
+
);
|
|
2436
|
+
|
|
2437
|
+
export function _default<T extends core.SomeType>(
|
|
2438
|
+
innerType: T,
|
|
2439
|
+
defaultValue: util.NoUndefined<core.output<T>> | (() => util.NoUndefined<core.output<T>>)
|
|
2440
|
+
): YatspDefault<T> {
|
|
2441
|
+
return new YatspDefault({
|
|
2442
|
+
type: "default",
|
|
2443
|
+
innerType: innerType as any as core.$YatspType,
|
|
2444
|
+
get defaultValue() {
|
|
2445
|
+
return typeof defaultValue === "function" ? (defaultValue as Function)() : util.shallowClone(defaultValue);
|
|
2446
|
+
},
|
|
2447
|
+
}) as any;
|
|
2448
|
+
}
|
|
2449
|
+
|
|
2450
|
+
// YatspPrefault
|
|
2451
|
+
export interface YatspPrefault<T extends core.SomeType = core.$YatspType>
|
|
2452
|
+
extends _YatspType<core.$YatspPrefaultInternals<T>>,
|
|
2453
|
+
core.$YatspPrefault<T> {
|
|
2454
|
+
"~standard": YatspStandardSchemaWithJSON<this>;
|
|
2455
|
+
unwrap(): T;
|
|
2456
|
+
}
|
|
2457
|
+
export const YatspPrefault: core.$constructor<YatspPrefault> = /*@__PURE__*/ core.$constructor(
|
|
2458
|
+
"YatspPrefault",
|
|
2459
|
+
(inst, def) => {
|
|
2460
|
+
core.$YatspPrefault.init(inst, def);
|
|
2461
|
+
YatspType.init(inst, def);
|
|
2462
|
+
inst._yatsp.processJSONSchema = (ctx, json, params) => processors.prefaultProcessor(inst, ctx, json, params);
|
|
2463
|
+
inst.unwrap = () => inst._yatsp.def.innerType;
|
|
2464
|
+
}
|
|
2465
|
+
);
|
|
2466
|
+
|
|
2467
|
+
export function prefault<T extends core.SomeType>(
|
|
2468
|
+
innerType: T,
|
|
2469
|
+
defaultValue: core.input<T> | (() => core.input<T>)
|
|
2470
|
+
): YatspPrefault<T> {
|
|
2471
|
+
return new YatspPrefault({
|
|
2472
|
+
type: "prefault",
|
|
2473
|
+
innerType: innerType as any as core.$YatspType,
|
|
2474
|
+
get defaultValue() {
|
|
2475
|
+
return typeof defaultValue === "function" ? (defaultValue as Function)() : util.shallowClone(defaultValue);
|
|
2476
|
+
},
|
|
2477
|
+
}) as any;
|
|
2478
|
+
}
|
|
2479
|
+
|
|
2480
|
+
// YatspNonOptional
|
|
2481
|
+
export interface YatspNonOptional<T extends core.SomeType = core.$YatspType>
|
|
2482
|
+
extends _YatspType<core.$YatspNonOptionalInternals<T>>,
|
|
2483
|
+
core.$YatspNonOptional<T> {
|
|
2484
|
+
"~standard": YatspStandardSchemaWithJSON<this>;
|
|
2485
|
+
unwrap(): T;
|
|
2486
|
+
}
|
|
2487
|
+
export const YatspNonOptional: core.$constructor<YatspNonOptional> = /*@__PURE__*/ core.$constructor(
|
|
2488
|
+
"YatspNonOptional",
|
|
2489
|
+
(inst, def) => {
|
|
2490
|
+
core.$YatspNonOptional.init(inst, def);
|
|
2491
|
+
YatspType.init(inst, def);
|
|
2492
|
+
inst._yatsp.processJSONSchema = (ctx, json, params) => processors.nonoptionalProcessor(inst, ctx, json, params);
|
|
2493
|
+
|
|
2494
|
+
inst.unwrap = () => inst._yatsp.def.innerType;
|
|
2495
|
+
}
|
|
2496
|
+
);
|
|
2497
|
+
|
|
2498
|
+
export function nonoptional<T extends core.SomeType>(
|
|
2499
|
+
innerType: T,
|
|
2500
|
+
params?: string | core.$YatspNonOptionalParams
|
|
2501
|
+
): YatspNonOptional<T> {
|
|
2502
|
+
return new YatspNonOptional({
|
|
2503
|
+
type: "nonoptional",
|
|
2504
|
+
innerType: innerType as any as core.$YatspType,
|
|
2505
|
+
...util.normalizeParams(params),
|
|
2506
|
+
}) as any;
|
|
2507
|
+
}
|
|
2508
|
+
|
|
2509
|
+
// YatspSuccess
|
|
2510
|
+
export interface YatspSuccess<T extends core.SomeType = core.$YatspType>
|
|
2511
|
+
extends _YatspType<core.$YatspSuccessInternals<T>>,
|
|
2512
|
+
core.$YatspSuccess<T> {
|
|
2513
|
+
"~standard": YatspStandardSchemaWithJSON<this>;
|
|
2514
|
+
unwrap(): T;
|
|
2515
|
+
}
|
|
2516
|
+
export const YatspSuccess: core.$constructor<YatspSuccess> = /*@__PURE__*/ core.$constructor(
|
|
2517
|
+
"YatspSuccess",
|
|
2518
|
+
(inst, def) => {
|
|
2519
|
+
core.$YatspSuccess.init(inst, def);
|
|
2520
|
+
YatspType.init(inst, def);
|
|
2521
|
+
inst._yatsp.processJSONSchema = (ctx, json, params) => processors.successProcessor(inst, ctx, json, params);
|
|
2522
|
+
|
|
2523
|
+
inst.unwrap = () => inst._yatsp.def.innerType;
|
|
2524
|
+
}
|
|
2525
|
+
);
|
|
2526
|
+
|
|
2527
|
+
export function success<T extends core.SomeType>(innerType: T): YatspSuccess<T> {
|
|
2528
|
+
return new YatspSuccess({
|
|
2529
|
+
type: "success",
|
|
2530
|
+
innerType: innerType as any as core.$YatspType,
|
|
2531
|
+
}) as any;
|
|
2532
|
+
}
|
|
2533
|
+
|
|
2534
|
+
// YatspCatch
|
|
2535
|
+
export interface YatspCatch<T extends core.SomeType = core.$YatspType>
|
|
2536
|
+
extends _YatspType<core.$YatspCatchInternals<T>>,
|
|
2537
|
+
core.$YatspCatch<T> {
|
|
2538
|
+
"~standard": YatspStandardSchemaWithJSON<this>;
|
|
2539
|
+
unwrap(): T;
|
|
2540
|
+
/** @deprecated Use `.unwrap()` instead. */
|
|
2541
|
+
removeCatch(): T;
|
|
2542
|
+
}
|
|
2543
|
+
export const YatspCatch: core.$constructor<YatspCatch> = /*@__PURE__*/ core.$constructor("YatspCatch", (inst, def) => {
|
|
2544
|
+
core.$YatspCatch.init(inst, def);
|
|
2545
|
+
YatspType.init(inst, def);
|
|
2546
|
+
inst._yatsp.processJSONSchema = (ctx, json, params) => processors.catchProcessor(inst, ctx, json, params);
|
|
2547
|
+
|
|
2548
|
+
inst.unwrap = () => inst._yatsp.def.innerType;
|
|
2549
|
+
inst.removeCatch = inst.unwrap;
|
|
2550
|
+
});
|
|
2551
|
+
|
|
2552
|
+
function _catch<T extends core.SomeType>(
|
|
2553
|
+
innerType: T,
|
|
2554
|
+
catchValue: core.output<T> | ((ctx: core.$YatspCatchCtx) => core.output<T>)
|
|
2555
|
+
): YatspCatch<T> {
|
|
2556
|
+
return new YatspCatch({
|
|
2557
|
+
type: "catch",
|
|
2558
|
+
innerType: innerType as any as core.$YatspType,
|
|
2559
|
+
catchValue: (typeof catchValue === "function" ? catchValue : core.util.constantCatch(catchValue)) as (
|
|
2560
|
+
ctx: core.$YatspCatchCtx
|
|
2561
|
+
) => core.output<T>,
|
|
2562
|
+
}) as any;
|
|
2563
|
+
}
|
|
2564
|
+
export { _catch as catch };
|
|
2565
|
+
|
|
2566
|
+
// YatspNaN
|
|
2567
|
+
export interface YatspNaN extends _YatspType<core.$YatspNaNInternals>, core.$YatspNaN {
|
|
2568
|
+
"~standard": YatspStandardSchemaWithJSON<this>;
|
|
2569
|
+
}
|
|
2570
|
+
export const YatspNaN: core.$constructor<YatspNaN> = /*@__PURE__*/ core.$constructor("YatspNaN", (inst, def) => {
|
|
2571
|
+
core.$YatspNaN.init(inst, def);
|
|
2572
|
+
YatspType.init(inst, def);
|
|
2573
|
+
inst._yatsp.processJSONSchema = (ctx, json, params) => processors.nanProcessor(inst, ctx, json, params);
|
|
2574
|
+
});
|
|
2575
|
+
|
|
2576
|
+
export function nan(params?: string | core.$YatspNaNParams): YatspNaN {
|
|
2577
|
+
return core._nan(YatspNaN, params);
|
|
2578
|
+
}
|
|
2579
|
+
|
|
2580
|
+
// YatspPipe
|
|
2581
|
+
export interface YatspPipe<A extends core.SomeType = core.$YatspType, B extends core.SomeType = core.$YatspType>
|
|
2582
|
+
extends _YatspType<core.$YatspPipeInternals<A, B>>,
|
|
2583
|
+
core.$YatspPipe<A, B> {
|
|
2584
|
+
"~standard": YatspStandardSchemaWithJSON<this>;
|
|
2585
|
+
in: A;
|
|
2586
|
+
out: B;
|
|
2587
|
+
}
|
|
2588
|
+
export const YatspPipe: core.$constructor<YatspPipe> = /*@__PURE__*/ core.$constructor("YatspPipe", (inst, def) => {
|
|
2589
|
+
core.$YatspPipe.init(inst, def);
|
|
2590
|
+
YatspType.init(inst, def);
|
|
2591
|
+
inst._yatsp.processJSONSchema = (ctx, json, params) => processors.pipeProcessor(inst, ctx, json, params);
|
|
2592
|
+
|
|
2593
|
+
inst.in = def.in;
|
|
2594
|
+
inst.out = def.out;
|
|
2595
|
+
});
|
|
2596
|
+
|
|
2597
|
+
export function pipe<
|
|
2598
|
+
const A extends core.SomeType,
|
|
2599
|
+
B extends core.$YatspType<unknown, core.output<A>> = core.$YatspType<unknown, core.output<A>>,
|
|
2600
|
+
>(in_: A, out: B | core.$YatspType<unknown, core.output<A>>): YatspPipe<A, B>;
|
|
2601
|
+
export function pipe(in_: core.SomeType, out: core.SomeType) {
|
|
2602
|
+
return new YatspPipe({
|
|
2603
|
+
type: "pipe",
|
|
2604
|
+
in: in_ as unknown as core.$YatspType,
|
|
2605
|
+
out: out as unknown as core.$YatspType,
|
|
2606
|
+
// ...util.normalizeParams(params),
|
|
2607
|
+
});
|
|
2608
|
+
}
|
|
2609
|
+
|
|
2610
|
+
// YatspCodec
|
|
2611
|
+
export interface YatspCodec<A extends core.SomeType = core.$YatspType, B extends core.SomeType = core.$YatspType>
|
|
2612
|
+
extends YatspPipe<A, B>,
|
|
2613
|
+
core.$YatspCodec<A, B> {
|
|
2614
|
+
"~standard": YatspStandardSchemaWithJSON<this>;
|
|
2615
|
+
_yatsp: core.$YatspCodecInternals<A, B>;
|
|
2616
|
+
def: core.$YatspCodecDef<A, B>;
|
|
2617
|
+
}
|
|
2618
|
+
export const YatspCodec: core.$constructor<YatspCodec> = /*@__PURE__*/ core.$constructor("YatspCodec", (inst, def) => {
|
|
2619
|
+
YatspPipe.init(inst, def);
|
|
2620
|
+
core.$YatspCodec.init(inst, def);
|
|
2621
|
+
});
|
|
2622
|
+
|
|
2623
|
+
export function codec<const A extends core.SomeType, B extends core.SomeType = core.$YatspType>(
|
|
2624
|
+
in_: A,
|
|
2625
|
+
out: B,
|
|
2626
|
+
params: {
|
|
2627
|
+
decode: (value: core.output<A>, payload: core.ParsePayload<core.output<A>>) => core.util.MaybeAsync<core.input<B>>;
|
|
2628
|
+
encode: (value: core.input<B>, payload: core.ParsePayload<core.input<B>>) => core.util.MaybeAsync<core.output<A>>;
|
|
2629
|
+
}
|
|
2630
|
+
): YatspCodec<A, B> {
|
|
2631
|
+
return new YatspCodec({
|
|
2632
|
+
type: "pipe",
|
|
2633
|
+
in: in_ as any as core.$YatspType,
|
|
2634
|
+
out: out as any as core.$YatspType,
|
|
2635
|
+
transform: params.decode as any,
|
|
2636
|
+
reverseTransform: params.encode as any,
|
|
2637
|
+
}) as any;
|
|
2638
|
+
}
|
|
2639
|
+
|
|
2640
|
+
export function invertCodec<A extends core.SomeType, B extends core.SomeType>(
|
|
2641
|
+
codec: YatspCodec<A, B>
|
|
2642
|
+
): YatspCodec<B, A> {
|
|
2643
|
+
const def = codec._yatsp.def;
|
|
2644
|
+
return new YatspCodec({
|
|
2645
|
+
type: "pipe",
|
|
2646
|
+
in: def.out as any,
|
|
2647
|
+
out: def.in as any,
|
|
2648
|
+
transform: def.reverseTransform as any,
|
|
2649
|
+
reverseTransform: def.transform as any,
|
|
2650
|
+
}) as any;
|
|
2651
|
+
}
|
|
2652
|
+
|
|
2653
|
+
// YatspPreprocess
|
|
2654
|
+
export interface YatspPreprocess<B extends core.SomeType = core.$YatspType, I = unknown>
|
|
2655
|
+
extends YatspPipe<core.$YatspTransform<unknown, I>, B>,
|
|
2656
|
+
core.$YatspPreprocess<B, I> {
|
|
2657
|
+
"~standard": YatspStandardSchemaWithJSON<this>;
|
|
2658
|
+
_yatsp: core.$YatspPreprocessInternals<B, I>;
|
|
2659
|
+
def: core.$YatspPreprocessDef<B, I>;
|
|
2660
|
+
}
|
|
2661
|
+
export const YatspPreprocess: core.$constructor<YatspPreprocess> = /*@__PURE__*/ core.$constructor(
|
|
2662
|
+
"YatspPreprocess",
|
|
2663
|
+
(inst, def) => {
|
|
2664
|
+
YatspPipe.init(inst, def);
|
|
2665
|
+
core.$YatspPreprocess.init(inst, def);
|
|
2666
|
+
}
|
|
2667
|
+
);
|
|
2668
|
+
|
|
2669
|
+
// YatspReadonly
|
|
2670
|
+
export interface YatspReadonly<T extends core.SomeType = core.$YatspType>
|
|
2671
|
+
extends _YatspType<core.$YatspReadonlyInternals<T>>,
|
|
2672
|
+
core.$YatspReadonly<T> {
|
|
2673
|
+
"~standard": YatspStandardSchemaWithJSON<this>;
|
|
2674
|
+
unwrap(): T;
|
|
2675
|
+
}
|
|
2676
|
+
export const YatspReadonly: core.$constructor<YatspReadonly> = /*@__PURE__*/ core.$constructor(
|
|
2677
|
+
"YatspReadonly",
|
|
2678
|
+
(inst, def) => {
|
|
2679
|
+
core.$YatspReadonly.init(inst, def);
|
|
2680
|
+
YatspType.init(inst, def);
|
|
2681
|
+
inst._yatsp.processJSONSchema = (ctx, json, params) => processors.readonlyProcessor(inst, ctx, json, params);
|
|
2682
|
+
|
|
2683
|
+
inst.unwrap = () => inst._yatsp.def.innerType;
|
|
2684
|
+
}
|
|
2685
|
+
);
|
|
2686
|
+
|
|
2687
|
+
export function readonly<T extends core.SomeType>(innerType: T): YatspReadonly<T> {
|
|
2688
|
+
return new YatspReadonly({
|
|
2689
|
+
type: "readonly",
|
|
2690
|
+
innerType: innerType as any as core.$YatspType,
|
|
2691
|
+
}) as any;
|
|
2692
|
+
}
|
|
2693
|
+
|
|
2694
|
+
// YatspTemplateLiteral
|
|
2695
|
+
export interface YatspTemplateLiteral<Template extends string = string>
|
|
2696
|
+
extends _YatspType<core.$YatspTemplateLiteralInternals<Template>>,
|
|
2697
|
+
core.$YatspTemplateLiteral<Template> {
|
|
2698
|
+
"~standard": YatspStandardSchemaWithJSON<this>;
|
|
2699
|
+
}
|
|
2700
|
+
export const YatspTemplateLiteral: core.$constructor<YatspTemplateLiteral> = /*@__PURE__*/ core.$constructor(
|
|
2701
|
+
"YatspTemplateLiteral",
|
|
2702
|
+
(inst, def) => {
|
|
2703
|
+
core.$YatspTemplateLiteral.init(inst, def);
|
|
2704
|
+
YatspType.init(inst, def);
|
|
2705
|
+
inst._yatsp.processJSONSchema = (ctx, json, params) => processors.templateLiteralProcessor(inst, ctx, json, params);
|
|
2706
|
+
}
|
|
2707
|
+
);
|
|
2708
|
+
|
|
2709
|
+
export function templateLiteral<const Parts extends core.$YatspTemplateLiteralPart[]>(
|
|
2710
|
+
parts: Parts,
|
|
2711
|
+
params?: string | core.$YatspTemplateLiteralParams
|
|
2712
|
+
): YatspTemplateLiteral<core.$PartsToTemplateLiteral<Parts>> {
|
|
2713
|
+
return new YatspTemplateLiteral({
|
|
2714
|
+
type: "template_literal",
|
|
2715
|
+
parts,
|
|
2716
|
+
...util.normalizeParams(params),
|
|
2717
|
+
}) as any;
|
|
2718
|
+
}
|
|
2719
|
+
|
|
2720
|
+
// YatspLazy
|
|
2721
|
+
export interface YatspLazy<T extends core.SomeType = core.$YatspType>
|
|
2722
|
+
extends _YatspType<core.$YatspLazyInternals<T>>,
|
|
2723
|
+
core.$YatspLazy<T> {
|
|
2724
|
+
"~standard": YatspStandardSchemaWithJSON<this>;
|
|
2725
|
+
unwrap(): T;
|
|
2726
|
+
}
|
|
2727
|
+
export const YatspLazy: core.$constructor<YatspLazy> = /*@__PURE__*/ core.$constructor("YatspLazy", (inst, def) => {
|
|
2728
|
+
core.$YatspLazy.init(inst, def);
|
|
2729
|
+
YatspType.init(inst, def);
|
|
2730
|
+
inst._yatsp.processJSONSchema = (ctx, json, params) => processors.lazyProcessor(inst, ctx, json, params);
|
|
2731
|
+
|
|
2732
|
+
inst.unwrap = () => inst._yatsp.def.getter();
|
|
2733
|
+
});
|
|
2734
|
+
|
|
2735
|
+
export function lazy<T extends core.SomeType>(getter: () => T): YatspLazy<T> {
|
|
2736
|
+
return new YatspLazy({
|
|
2737
|
+
type: "lazy",
|
|
2738
|
+
getter: getter as any,
|
|
2739
|
+
}) as any;
|
|
2740
|
+
}
|
|
2741
|
+
|
|
2742
|
+
// YatspPromise
|
|
2743
|
+
export interface YatspPromise<T extends core.SomeType = core.$YatspType>
|
|
2744
|
+
extends _YatspType<core.$YatspPromiseInternals<T>>,
|
|
2745
|
+
core.$YatspPromise<T> {
|
|
2746
|
+
"~standard": YatspStandardSchemaWithJSON<this>;
|
|
2747
|
+
unwrap(): T;
|
|
2748
|
+
}
|
|
2749
|
+
export const YatspPromise: core.$constructor<YatspPromise> = /*@__PURE__*/ core.$constructor(
|
|
2750
|
+
"YatspPromise",
|
|
2751
|
+
(inst, def) => {
|
|
2752
|
+
core.$YatspPromise.init(inst, def);
|
|
2753
|
+
YatspType.init(inst, def);
|
|
2754
|
+
inst._yatsp.processJSONSchema = (ctx, json, params) => processors.promiseProcessor(inst, ctx, json, params);
|
|
2755
|
+
|
|
2756
|
+
inst.unwrap = () => inst._yatsp.def.innerType;
|
|
2757
|
+
}
|
|
2758
|
+
);
|
|
2759
|
+
|
|
2760
|
+
export function promise<T extends core.SomeType>(innerType: T): YatspPromise<T> {
|
|
2761
|
+
return new YatspPromise({
|
|
2762
|
+
type: "promise",
|
|
2763
|
+
innerType: innerType as any as core.$YatspType,
|
|
2764
|
+
}) as any;
|
|
2765
|
+
}
|
|
2766
|
+
|
|
2767
|
+
// YatspFunction
|
|
2768
|
+
export interface YatspFunction<
|
|
2769
|
+
Args extends core.$YatspFunctionIn = core.$YatspFunctionIn,
|
|
2770
|
+
Returns extends core.$YatspFunctionOut = core.$YatspFunctionOut,
|
|
2771
|
+
> extends _YatspType<core.$YatspFunctionInternals<Args, Returns>>,
|
|
2772
|
+
core.$YatspFunction<Args, Returns> {
|
|
2773
|
+
"~standard": YatspStandardSchemaWithJSON<this>;
|
|
2774
|
+
_def: core.$YatspFunctionDef<Args, Returns>;
|
|
2775
|
+
_input: core.$InferInnerFunctionType<Args, Returns>;
|
|
2776
|
+
_output: core.$InferOuterFunctionType<Args, Returns>;
|
|
2777
|
+
|
|
2778
|
+
input<const Items extends util.TupleItems, const Rest extends core.$YatspFunctionOut = core.$YatspFunctionOut>(
|
|
2779
|
+
args: Items,
|
|
2780
|
+
rest?: Rest
|
|
2781
|
+
): YatspFunction<core.$YatspTuple<Items, Rest>, Returns>;
|
|
2782
|
+
input<NewArgs extends core.$YatspFunctionIn>(args: NewArgs): YatspFunction<NewArgs, Returns>;
|
|
2783
|
+
input(...args: any[]): YatspFunction<any, Returns>;
|
|
2784
|
+
|
|
2785
|
+
output<NewReturns extends core.$YatspType>(output: NewReturns): YatspFunction<Args, NewReturns>;
|
|
2786
|
+
}
|
|
2787
|
+
|
|
2788
|
+
export const YatspFunction: core.$constructor<YatspFunction> = /*@__PURE__*/ core.$constructor(
|
|
2789
|
+
"YatspFunction",
|
|
2790
|
+
(inst, def) => {
|
|
2791
|
+
core.$YatspFunction.init(inst, def);
|
|
2792
|
+
YatspType.init(inst, def);
|
|
2793
|
+
inst._yatsp.processJSONSchema = (ctx, json, params) => processors.functionProcessor(inst, ctx, json, params);
|
|
2794
|
+
}
|
|
2795
|
+
);
|
|
2796
|
+
|
|
2797
|
+
export function _function(): YatspFunction;
|
|
2798
|
+
export function _function<const In extends ReadonlyArray<core.$YatspType>>(params: {
|
|
2799
|
+
input: In;
|
|
2800
|
+
}): YatspFunction<YatspTuple<In, null>, core.$YatspFunctionOut>;
|
|
2801
|
+
export function _function<
|
|
2802
|
+
const In extends ReadonlyArray<core.$YatspType>,
|
|
2803
|
+
const Out extends core.$YatspFunctionOut = core.$YatspFunctionOut,
|
|
2804
|
+
>(params: {
|
|
2805
|
+
input: In;
|
|
2806
|
+
output: Out;
|
|
2807
|
+
}): YatspFunction<YatspTuple<In, null>, Out>;
|
|
2808
|
+
export function _function<const In extends core.$YatspFunctionIn = core.$YatspFunctionIn>(params: {
|
|
2809
|
+
input: In;
|
|
2810
|
+
}): YatspFunction<In, core.$YatspFunctionOut>;
|
|
2811
|
+
export function _function<const Out extends core.$YatspFunctionOut = core.$YatspFunctionOut>(params: {
|
|
2812
|
+
output: Out;
|
|
2813
|
+
}): YatspFunction<core.$YatspFunctionIn, Out>;
|
|
2814
|
+
export function _function<
|
|
2815
|
+
In extends core.$YatspFunctionIn = core.$YatspFunctionIn,
|
|
2816
|
+
Out extends core.$YatspType = core.$YatspType,
|
|
2817
|
+
>(params?: {
|
|
2818
|
+
input: In;
|
|
2819
|
+
output: Out;
|
|
2820
|
+
}): YatspFunction<In, Out>;
|
|
2821
|
+
export function _function(params?: {
|
|
2822
|
+
output?: core.$YatspType;
|
|
2823
|
+
input?: core.$YatspFunctionArgs | Array<core.$YatspType>;
|
|
2824
|
+
}): YatspFunction {
|
|
2825
|
+
return new YatspFunction({
|
|
2826
|
+
type: "function",
|
|
2827
|
+
input: Array.isArray(params?.input) ? tuple(params?.input as any) : (params?.input ?? array(unknown())),
|
|
2828
|
+
output: params?.output ?? unknown(),
|
|
2829
|
+
});
|
|
2830
|
+
}
|
|
2831
|
+
|
|
2832
|
+
export { _function as function };
|
|
2833
|
+
|
|
2834
|
+
// YatspCustom
|
|
2835
|
+
export interface YatspCustom<O = unknown, I = unknown>
|
|
2836
|
+
extends _YatspType<core.$YatspCustomInternals<O, I>>,
|
|
2837
|
+
core.$YatspCustom<O, I> {
|
|
2838
|
+
"~standard": YatspStandardSchemaWithJSON<this>;
|
|
2839
|
+
}
|
|
2840
|
+
export const YatspCustom: core.$constructor<YatspCustom> = /*@__PURE__*/ core.$constructor(
|
|
2841
|
+
"YatspCustom",
|
|
2842
|
+
(inst, def) => {
|
|
2843
|
+
core.$YatspCustom.init(inst, def);
|
|
2844
|
+
YatspType.init(inst, def);
|
|
2845
|
+
inst._yatsp.processJSONSchema = (ctx, json, params) => processors.customProcessor(inst, ctx, json, params);
|
|
2846
|
+
}
|
|
2847
|
+
);
|
|
2848
|
+
|
|
2849
|
+
// custom checks
|
|
2850
|
+
export function check<O = unknown>(fn: core.CheckFn<O>): core.$YatspCheck<O> {
|
|
2851
|
+
const ch = new core.$YatspCheck({
|
|
2852
|
+
check: "custom",
|
|
2853
|
+
// ...util.normalizeParams(params),
|
|
2854
|
+
});
|
|
2855
|
+
|
|
2856
|
+
ch._yatsp.check = fn;
|
|
2857
|
+
return ch;
|
|
2858
|
+
}
|
|
2859
|
+
|
|
2860
|
+
export function custom<O>(
|
|
2861
|
+
fn?: (data: unknown) => unknown,
|
|
2862
|
+
_params?: string | core.$YatspCustomParams | undefined
|
|
2863
|
+
): YatspCustom<O, O> {
|
|
2864
|
+
return core._custom(YatspCustom, fn ?? (() => true), _params) as any;
|
|
2865
|
+
}
|
|
2866
|
+
|
|
2867
|
+
export function refine<T>(
|
|
2868
|
+
fn: (arg: NoInfer<T>) => util.MaybeAsync<unknown>,
|
|
2869
|
+
_params: string | core.$YatspCustomParams = {}
|
|
2870
|
+
): core.$YatspCheck<T> {
|
|
2871
|
+
return core._refine(YatspCustom, fn, _params);
|
|
2872
|
+
}
|
|
2873
|
+
|
|
2874
|
+
// superRefine
|
|
2875
|
+
export function superRefine<T>(
|
|
2876
|
+
fn: (arg: T, payload: core.$RefinementCtx<T>) => void | Promise<void>,
|
|
2877
|
+
params?: core.$YatspSuperRefineParams
|
|
2878
|
+
): core.$YatspCheck<T> {
|
|
2879
|
+
return core._superRefine(fn, params);
|
|
2880
|
+
}
|
|
2881
|
+
|
|
2882
|
+
// Re-export describe and meta from core
|
|
2883
|
+
export const describe = core.describe;
|
|
2884
|
+
export const meta = core.meta;
|
|
2885
|
+
|
|
2886
|
+
type YatspInstanceOfParams = core.Params<
|
|
2887
|
+
YatspCustom,
|
|
2888
|
+
core.$YatspIssueCustom,
|
|
2889
|
+
"type" | "check" | "checks" | "fn" | "abort" | "error" | "params" | "path"
|
|
2890
|
+
>;
|
|
2891
|
+
|
|
2892
|
+
// YatspInstanceOf
|
|
2893
|
+
export interface YatspInstanceOf<T = unknown> extends YatspCustom<T, T> {
|
|
2894
|
+
// the shape is keyed off the instance type, so keys autocomplete and a schema that can't accept the property's type is an error. Methods are excluded: every object literal inherits Object.prototype.toString, which would otherwise collide with the constraint's own toString entry and reject every shape.
|
|
2895
|
+
properties<Shape extends { [k in keyof T as T[k] extends Function ? never : k]?: core.$YatspType<unknown, T[k]> }>(
|
|
2896
|
+
shape: Shape,
|
|
2897
|
+
params?: string | core.$YatspCheckPropertiesParams
|
|
2898
|
+
): YatspInstanceOf<T & core.$InferObjectInput<Shape, {}>>;
|
|
2899
|
+
}
|
|
2900
|
+
export const YatspInstanceOf: core.$constructor<YatspInstanceOf> = /*@__PURE__*/ core.$constructor(
|
|
2901
|
+
"YatspInstanceOf",
|
|
2902
|
+
(inst, def) => {
|
|
2903
|
+
YatspCustom.init(inst, def);
|
|
2904
|
+
},
|
|
2905
|
+
{
|
|
2906
|
+
properties(shape: core.$YatspShape, params?: string | core.$YatspCheckPropertiesParams) {
|
|
2907
|
+
// asserts in place, so the narrowed output type is truthful without a wrapper
|
|
2908
|
+
return this.check(core._properties(shape, params)) as any;
|
|
2909
|
+
},
|
|
2910
|
+
}
|
|
2911
|
+
);
|
|
2912
|
+
|
|
2913
|
+
function _instanceof<T extends typeof util.Class>(
|
|
2914
|
+
cls: T,
|
|
2915
|
+
params: YatspInstanceOfParams = {}
|
|
2916
|
+
): YatspInstanceOf<InstanceType<T>> {
|
|
2917
|
+
const inst = new YatspInstanceOf({
|
|
2918
|
+
type: "custom",
|
|
2919
|
+
check: "custom",
|
|
2920
|
+
fn: (data: unknown) => data instanceof cls,
|
|
2921
|
+
abort: true,
|
|
2922
|
+
...(util.normalizeParams(params) as any),
|
|
2923
|
+
});
|
|
2924
|
+
inst._yatsp.bag.Class = cls;
|
|
2925
|
+
// Override check to emit invalid_type instead of custom
|
|
2926
|
+
inst._yatsp.check = (payload) => {
|
|
2927
|
+
if (!(payload.value instanceof cls)) {
|
|
2928
|
+
payload.issues.push({
|
|
2929
|
+
code: "invalid_type",
|
|
2930
|
+
expected: cls.name,
|
|
2931
|
+
input: payload.value,
|
|
2932
|
+
inst,
|
|
2933
|
+
path: [...(inst._yatsp.def.path ?? [])],
|
|
2934
|
+
});
|
|
2935
|
+
}
|
|
2936
|
+
};
|
|
2937
|
+
return inst as any;
|
|
2938
|
+
}
|
|
2939
|
+
export { _instanceof as instanceof };
|
|
2940
|
+
|
|
2941
|
+
// stringbool
|
|
2942
|
+
export const stringbool: (_params?: string | core.$YatspStringBoolParams) => YatspCodec<YatspString, YatspBoolean> = (
|
|
2943
|
+
...args
|
|
2944
|
+
) =>
|
|
2945
|
+
core._stringbool(
|
|
2946
|
+
{
|
|
2947
|
+
Codec: YatspCodec,
|
|
2948
|
+
Boolean: YatspBoolean,
|
|
2949
|
+
String: YatspString,
|
|
2950
|
+
},
|
|
2951
|
+
...args
|
|
2952
|
+
) as any;
|
|
2953
|
+
|
|
2954
|
+
// json
|
|
2955
|
+
type _YatspJSONSchema = YatspUnion<
|
|
2956
|
+
[
|
|
2957
|
+
YatspString,
|
|
2958
|
+
YatspNumber,
|
|
2959
|
+
YatspBoolean,
|
|
2960
|
+
YatspNull,
|
|
2961
|
+
YatspArray<YatspJSONSchema>,
|
|
2962
|
+
YatspRecord<YatspString, YatspJSONSchema>,
|
|
2963
|
+
]
|
|
2964
|
+
>;
|
|
2965
|
+
type _YatspJSONSchemaInternals = _YatspJSONSchema["_yatsp"];
|
|
2966
|
+
|
|
2967
|
+
export interface YatspJSONSchemaInternals extends _YatspJSONSchemaInternals {
|
|
2968
|
+
output: util.JSONType;
|
|
2969
|
+
input: util.JSONType;
|
|
2970
|
+
}
|
|
2971
|
+
export interface YatspJSONSchema extends _YatspJSONSchema {
|
|
2972
|
+
_yatsp: YatspJSONSchemaInternals;
|
|
2973
|
+
}
|
|
2974
|
+
|
|
2975
|
+
export function json(params?: string | core.$YatspCustomParams): YatspJSONSchema {
|
|
2976
|
+
const jsonSchema: any = lazy(() => {
|
|
2977
|
+
return union([string(params), number(), boolean(), _null(), array(jsonSchema), record(string(), jsonSchema)]);
|
|
2978
|
+
});
|
|
2979
|
+
|
|
2980
|
+
return jsonSchema;
|
|
2981
|
+
}
|
|
2982
|
+
|
|
2983
|
+
// preprocess
|
|
2984
|
+
|
|
2985
|
+
export function preprocess<A, U extends core.SomeType, B = unknown>(
|
|
2986
|
+
fn: (arg: B, ctx: core.$RefinementCtx) => A,
|
|
2987
|
+
schema: U
|
|
2988
|
+
): YatspPreprocess<U, B> {
|
|
2989
|
+
return new YatspPreprocess({
|
|
2990
|
+
type: "pipe",
|
|
2991
|
+
in: transform(fn as any) as any as core.$YatspTransform,
|
|
2992
|
+
out: schema as any as core.$YatspType,
|
|
2993
|
+
}) as any;
|
|
2994
|
+
}
|