convex-cms 0.0.2 → 0.0.3
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/admin-dist/nitro.json +15 -0
- package/admin-dist/public/assets/CmsEmptyState-CRswfTzk.js +5 -0
- package/admin-dist/public/assets/CmsPageHeader-CirpXndm.js +1 -0
- package/admin-dist/public/assets/CmsStatusBadge-CbEUpQu-.js +1 -0
- package/admin-dist/public/assets/CmsToolbar-BI2nZOXp.js +1 -0
- package/admin-dist/public/assets/ContentEntryEditor-CBeCyK_m.js +4 -0
- package/admin-dist/public/assets/ErrorState-BIVaWmom.js +1 -0
- package/admin-dist/public/assets/TaxonomyFilter-ChaY6Y_x.js +1 -0
- package/admin-dist/public/assets/_contentTypeId-DQ8k_Rvw.js +1 -0
- package/admin-dist/public/assets/_entryId-CKU_glsK.js +1 -0
- package/admin-dist/public/assets/alert-BXjTqrwQ.js +1 -0
- package/admin-dist/public/assets/badge-hvUOzpVZ.js +1 -0
- package/admin-dist/public/assets/circle-check-big-CF_pR17r.js +1 -0
- package/admin-dist/public/assets/command-DU82cJlt.js +1 -0
- package/admin-dist/public/assets/content-_LXl3pp7.js +1 -0
- package/admin-dist/public/assets/content-types-KjxaXGxY.js +2 -0
- package/admin-dist/public/assets/globals-CS6BZ0zp.css +1 -0
- package/admin-dist/public/assets/index-DNGIZHL-.js +1 -0
- package/admin-dist/public/assets/label-KNtpL71g.js +1 -0
- package/admin-dist/public/assets/link-2-Bw2aI4V4.js +1 -0
- package/admin-dist/public/assets/list-sYepHjt_.js +1 -0
- package/admin-dist/public/assets/main-CKj5yfEi.js +97 -0
- package/admin-dist/public/assets/media-Bkrkffm7.js +1 -0
- package/admin-dist/public/assets/new._contentTypeId-C3LstjNs.js +1 -0
- package/admin-dist/public/assets/plus-DUn8v_Xf.js +1 -0
- package/admin-dist/public/assets/rotate-ccw-DJEoHcRI.js +1 -0
- package/admin-dist/public/assets/scroll-area-DfIlT0in.js +1 -0
- package/admin-dist/public/assets/search-MuAUDJKR.js +1 -0
- package/admin-dist/public/assets/select-BD29IXCI.js +1 -0
- package/admin-dist/public/assets/settings-DmMyn_6A.js +1 -0
- package/admin-dist/public/assets/switch-h3Rrnl5i.js +1 -0
- package/admin-dist/public/assets/tabs-imc8h-Dp.js +1 -0
- package/admin-dist/public/assets/taxonomies-dAsrT65H.js +1 -0
- package/admin-dist/public/assets/textarea-BTy7nwzR.js +1 -0
- package/admin-dist/public/assets/trash-SAWKZZHv.js +1 -0
- package/admin-dist/public/assets/triangle-alert-E52Vfeuh.js +1 -0
- package/admin-dist/public/assets/useBreadcrumbLabel-BECBMCzM.js +1 -0
- package/admin-dist/public/assets/usePermissions-Basjs9BT.js +1 -0
- package/admin-dist/public/favicon.ico +0 -0
- package/admin-dist/server/_chunks/_libs/@date-fns/tz.mjs +217 -0
- package/admin-dist/server/_chunks/_libs/@floating-ui/core.mjs +719 -0
- package/admin-dist/server/_chunks/_libs/@floating-ui/dom.mjs +622 -0
- package/admin-dist/server/_chunks/_libs/@floating-ui/react-dom.mjs +292 -0
- package/admin-dist/server/_chunks/_libs/@floating-ui/utils.mjs +320 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/number.mjs +6 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/primitive.mjs +11 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-arrow.mjs +23 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-avatar.mjs +119 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-checkbox.mjs +270 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-collection.mjs +69 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-compose-refs.mjs +39 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-context.mjs +137 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-dialog.mjs +325 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-direction.mjs +9 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-dismissable-layer.mjs +210 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-dropdown-menu.mjs +253 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-focus-guards.mjs +29 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-focus-scope.mjs +206 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-id.mjs +14 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-label.mjs +23 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-menu.mjs +812 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-popover.mjs +300 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-popper.mjs +286 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-portal.mjs +16 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-presence.mjs +128 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-primitive.mjs +141 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-roving-focus.mjs +224 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-scroll-area.mjs +721 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-select.mjs +1163 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-separator.mjs +28 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-slot.mjs +601 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-switch.mjs +152 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-tabs.mjs +189 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-use-callback-ref.mjs +11 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-use-controllable-state.mjs +69 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-use-effect-event.mjs +1 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-use-escape-keydown.mjs +17 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-use-is-hydrated.mjs +15 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-use-layout-effect.mjs +6 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-use-previous.mjs +14 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-use-size.mjs +39 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-visually-hidden.mjs +33 -0
- package/admin-dist/server/_chunks/_libs/@tanstack/history.mjs +409 -0
- package/admin-dist/server/_chunks/_libs/@tanstack/react-router.mjs +1711 -0
- package/admin-dist/server/_chunks/_libs/@tanstack/react-store.mjs +56 -0
- package/admin-dist/server/_chunks/_libs/@tanstack/router-core.mjs +4829 -0
- package/admin-dist/server/_chunks/_libs/@tanstack/store.mjs +134 -0
- package/admin-dist/server/_chunks/_libs/react-dom.mjs +10781 -0
- package/admin-dist/server/_chunks/_libs/react.mjs +513 -0
- package/admin-dist/server/_libs/aria-hidden.mjs +122 -0
- package/admin-dist/server/_libs/class-variance-authority.mjs +44 -0
- package/admin-dist/server/_libs/clsx.mjs +16 -0
- package/admin-dist/server/_libs/cmdk.mjs +315 -0
- package/admin-dist/server/_libs/convex.mjs +4841 -0
- package/admin-dist/server/_libs/cookie-es.mjs +58 -0
- package/admin-dist/server/_libs/croner.mjs +1 -0
- package/admin-dist/server/_libs/crossws.mjs +1 -0
- package/admin-dist/server/_libs/date-fns.mjs +1716 -0
- package/admin-dist/server/_libs/detect-node-es.mjs +1 -0
- package/admin-dist/server/_libs/get-nonce.mjs +9 -0
- package/admin-dist/server/_libs/h3-v2.mjs +277 -0
- package/admin-dist/server/_libs/h3.mjs +401 -0
- package/admin-dist/server/_libs/hookable.mjs +1 -0
- package/admin-dist/server/_libs/isbot.mjs +20 -0
- package/admin-dist/server/_libs/lucide-react.mjs +850 -0
- package/admin-dist/server/_libs/ohash.mjs +1 -0
- package/admin-dist/server/_libs/react-day-picker.mjs +2201 -0
- package/admin-dist/server/_libs/react-remove-scroll-bar.mjs +82 -0
- package/admin-dist/server/_libs/react-remove-scroll.mjs +328 -0
- package/admin-dist/server/_libs/react-style-singleton.mjs +69 -0
- package/admin-dist/server/_libs/rou3.mjs +8 -0
- package/admin-dist/server/_libs/seroval-plugins.mjs +58 -0
- package/admin-dist/server/_libs/seroval.mjs +1765 -0
- package/admin-dist/server/_libs/srvx.mjs +719 -0
- package/admin-dist/server/_libs/tailwind-merge.mjs +3010 -0
- package/admin-dist/server/_libs/tiny-invariant.mjs +12 -0
- package/admin-dist/server/_libs/tiny-warning.mjs +5 -0
- package/admin-dist/server/_libs/tslib.mjs +39 -0
- package/admin-dist/server/_libs/ufo.mjs +54 -0
- package/admin-dist/server/_libs/unctx.mjs +1 -0
- package/admin-dist/server/_libs/unstorage.mjs +1 -0
- package/admin-dist/server/_libs/use-callback-ref.mjs +66 -0
- package/admin-dist/server/_libs/use-sidecar.mjs +106 -0
- package/admin-dist/server/_libs/use-sync-external-store.mjs +139 -0
- package/admin-dist/server/_libs/zod.mjs +4223 -0
- package/admin-dist/server/_ssr/CmsEmptyState-DU7-7-mV.mjs +290 -0
- package/admin-dist/server/_ssr/CmsPageHeader-CseW0AHm.mjs +24 -0
- package/admin-dist/server/_ssr/CmsStatusBadge-B_pi4KCp.mjs +127 -0
- package/admin-dist/server/_ssr/CmsToolbar-X75ex6ek.mjs +49 -0
- package/admin-dist/server/_ssr/ContentEntryEditor-CepusRsA.mjs +3720 -0
- package/admin-dist/server/_ssr/ErrorState-cI-bKLez.mjs +89 -0
- package/admin-dist/server/_ssr/TaxonomyFilter-Bwrq0-cz.mjs +188 -0
- package/admin-dist/server/_ssr/_contentTypeId-BqYKEcLr.mjs +379 -0
- package/admin-dist/server/_ssr/_entryId-CRfnqeDf.mjs +161 -0
- package/admin-dist/server/_ssr/_tanstack-start-manifest_v-BwDlABVk.mjs +4 -0
- package/admin-dist/server/_ssr/alert-CVt45UUP.mjs +92 -0
- package/admin-dist/server/_ssr/badge-6BsP37vG.mjs +125 -0
- package/admin-dist/server/_ssr/command-fy8epIKf.mjs +128 -0
- package/admin-dist/server/_ssr/config.server-D7JHDcDv.mjs +117 -0
- package/admin-dist/server/_ssr/content-B5RhL7uW.mjs +532 -0
- package/admin-dist/server/_ssr/content-types-BIOqCQYN.mjs +1166 -0
- package/admin-dist/server/_ssr/index-DHSHDPt1.mjs +193 -0
- package/admin-dist/server/_ssr/index.mjs +1275 -0
- package/admin-dist/server/_ssr/label-C8Dko1j7.mjs +22 -0
- package/admin-dist/server/_ssr/media-CSx3XttC.mjs +1832 -0
- package/admin-dist/server/_ssr/new._contentTypeId-DzanEZQM.mjs +144 -0
- package/admin-dist/server/_ssr/router-DDWcF-kt.mjs +1556 -0
- package/admin-dist/server/_ssr/scroll-area-bjPYwhXN.mjs +59 -0
- package/admin-dist/server/_ssr/select-BUhDDf4T.mjs +142 -0
- package/admin-dist/server/_ssr/settings-DAsxnw2q.mjs +348 -0
- package/admin-dist/server/_ssr/start-HYkvq4Ni.mjs +4 -0
- package/admin-dist/server/_ssr/switch-BgyRtQ1Z.mjs +31 -0
- package/admin-dist/server/_ssr/tabs-DzMdRB1A.mjs +628 -0
- package/admin-dist/server/_ssr/taxonomies-C8j8g5Q5.mjs +915 -0
- package/admin-dist/server/_ssr/textarea-9jNeYJSc.mjs +18 -0
- package/admin-dist/server/_ssr/trash-DYMxwhZB.mjs +291 -0
- package/admin-dist/server/_ssr/useBreadcrumbLabel-FNSAr2Ha.mjs +16 -0
- package/admin-dist/server/_ssr/usePermissions-BJGGahrJ.mjs +68 -0
- package/admin-dist/server/favicon.ico +0 -0
- package/admin-dist/server/index.mjs +627 -0
- package/dist/cli/index.js +0 -0
- package/dist/client/admin-config.d.ts +0 -1
- package/dist/client/admin-config.d.ts.map +1 -1
- package/dist/client/admin-config.js +0 -1
- package/dist/client/admin-config.js.map +1 -1
- package/dist/client/adminApi.d.ts.map +1 -1
- package/dist/client/agentTools.d.ts +1237 -135
- package/dist/client/agentTools.d.ts.map +1 -1
- package/dist/client/agentTools.js +33 -9
- package/dist/client/agentTools.js.map +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js.map +1 -1
- package/dist/component/_generated/component.d.ts +9 -0
- package/dist/component/_generated/component.d.ts.map +1 -1
- package/dist/component/mediaAssets.d.ts +35 -0
- package/dist/component/mediaAssets.d.ts.map +1 -1
- package/dist/component/mediaAssets.js +81 -0
- package/dist/component/mediaAssets.js.map +1 -1
- package/dist/test.d.ts.map +1 -1
- package/dist/test.js +2 -1
- package/dist/test.js.map +1 -1
- package/package.json +9 -5
- package/dist/component/auditLog.d.ts +0 -410
- package/dist/component/auditLog.d.ts.map +0 -1
- package/dist/component/auditLog.js +0 -607
- package/dist/component/auditLog.js.map +0 -1
- package/dist/component/types.d.ts +0 -4
- package/dist/component/types.d.ts.map +0 -1
- package/dist/component/types.js +0 -2
- package/dist/component/types.js.map +0 -1
- package/src/cli/commands/admin.ts +0 -104
- package/src/cli/index.ts +0 -21
- package/src/cli/utils/detectConvexUrl.ts +0 -54
- package/src/cli/utils/openBrowser.ts +0 -16
- package/src/client/admin-config.ts +0 -138
- package/src/client/adminApi.ts +0 -942
- package/src/client/agentTools.ts +0 -1311
- package/src/client/argTypes.ts +0 -316
- package/src/client/field-types.ts +0 -187
- package/src/client/index.ts +0 -1301
- package/src/client/queryBuilder.ts +0 -1100
- package/src/client/schema/codegen.ts +0 -500
- package/src/client/schema/defineContentType.ts +0 -501
- package/src/client/schema/index.ts +0 -169
- package/src/client/schema/schemaDrift.ts +0 -574
- package/src/client/schema/typedClient.ts +0 -688
- package/src/client/schema/types.ts +0 -666
- package/src/client/types.ts +0 -723
- package/src/client/workflows.ts +0 -141
- package/src/client/wrapper.ts +0 -4304
- package/src/component/_generated/api.ts +0 -140
- package/src/component/_generated/component.ts +0 -5029
- package/src/component/_generated/dataModel.ts +0 -60
- package/src/component/_generated/server.ts +0 -156
- package/src/component/authorization.ts +0 -647
- package/src/component/authorizationHooks.ts +0 -668
- package/src/component/bulkOperations.ts +0 -687
- package/src/component/contentEntries.ts +0 -1976
- package/src/component/contentEntryMutations.ts +0 -1223
- package/src/component/contentEntryValidation.ts +0 -707
- package/src/component/contentLock.ts +0 -550
- package/src/component/contentTypeMigration.ts +0 -1064
- package/src/component/contentTypeMutations.ts +0 -969
- package/src/component/contentTypes.ts +0 -346
- package/src/component/convex.config.ts +0 -44
- package/src/component/documentTypes.ts +0 -240
- package/src/component/eventEmitter.ts +0 -485
- package/src/component/exportImport.ts +0 -1169
- package/src/component/index.ts +0 -491
- package/src/component/lib/deepReferenceResolver.ts +0 -999
- package/src/component/lib/errors.ts +0 -816
- package/src/component/lib/index.ts +0 -145
- package/src/component/lib/mediaReferenceResolver.ts +0 -495
- package/src/component/lib/metadataExtractor.ts +0 -792
- package/src/component/lib/mutationAuth.ts +0 -199
- package/src/component/lib/queries.ts +0 -79
- package/src/component/lib/ragContentChunker.ts +0 -1371
- package/src/component/lib/referenceResolver.ts +0 -430
- package/src/component/lib/slugGenerator.ts +0 -262
- package/src/component/lib/slugUniqueness.ts +0 -333
- package/src/component/lib/softDelete.ts +0 -44
- package/src/component/localeFallbackChain.ts +0 -673
- package/src/component/localeFields.ts +0 -896
- package/src/component/mediaAssetMutations.ts +0 -725
- package/src/component/mediaAssets.ts +0 -932
- package/src/component/mediaFolderMutations.ts +0 -1046
- package/src/component/mediaUploadMutations.ts +0 -224
- package/src/component/mediaVariantMutations.ts +0 -900
- package/src/component/mediaVariants.ts +0 -793
- package/src/component/ragContentIndexer.ts +0 -1067
- package/src/component/rateLimitHooks.ts +0 -572
- package/src/component/roles.ts +0 -1360
- package/src/component/scheduledPublish.ts +0 -358
- package/src/component/schema.ts +0 -617
- package/src/component/taxonomies.ts +0 -949
- package/src/component/taxonomyMutations.ts +0 -1210
- package/src/component/trash.ts +0 -724
- package/src/component/userContext.ts +0 -898
- package/src/component/validation.ts +0 -1388
- package/src/component/validators.ts +0 -949
- package/src/component/versionMutations.ts +0 -392
- package/src/component/webhookTrigger.ts +0 -1922
- package/src/react/index.ts +0 -898
- package/src/test.ts +0 -1580
|
@@ -0,0 +1,4223 @@
|
|
|
1
|
+
function $constructor(name, initializer2, params) {
|
|
2
|
+
function init(inst, def) {
|
|
3
|
+
if (!inst._zod) {
|
|
4
|
+
Object.defineProperty(inst, "_zod", {
|
|
5
|
+
value: {
|
|
6
|
+
def,
|
|
7
|
+
constr: _,
|
|
8
|
+
traits: /* @__PURE__ */ new Set()
|
|
9
|
+
},
|
|
10
|
+
enumerable: false
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
if (inst._zod.traits.has(name)) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
inst._zod.traits.add(name);
|
|
17
|
+
initializer2(inst, def);
|
|
18
|
+
const proto = _.prototype;
|
|
19
|
+
const keys = Object.keys(proto);
|
|
20
|
+
for (let i = 0; i < keys.length; i++) {
|
|
21
|
+
const k = keys[i];
|
|
22
|
+
if (!(k in inst)) {
|
|
23
|
+
inst[k] = proto[k].bind(inst);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const Parent = params?.Parent ?? Object;
|
|
28
|
+
class Definition extends Parent {
|
|
29
|
+
}
|
|
30
|
+
Object.defineProperty(Definition, "name", { value: name });
|
|
31
|
+
function _(def) {
|
|
32
|
+
var _a2;
|
|
33
|
+
const inst = params?.Parent ? new Definition() : this;
|
|
34
|
+
init(inst, def);
|
|
35
|
+
(_a2 = inst._zod).deferred ?? (_a2.deferred = []);
|
|
36
|
+
for (const fn of inst._zod.deferred) {
|
|
37
|
+
fn();
|
|
38
|
+
}
|
|
39
|
+
return inst;
|
|
40
|
+
}
|
|
41
|
+
Object.defineProperty(_, "init", { value: init });
|
|
42
|
+
Object.defineProperty(_, Symbol.hasInstance, {
|
|
43
|
+
value: (inst) => {
|
|
44
|
+
if (params?.Parent && inst instanceof params.Parent)
|
|
45
|
+
return true;
|
|
46
|
+
return inst?._zod?.traits?.has(name);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
Object.defineProperty(_, "name", { value: name });
|
|
50
|
+
return _;
|
|
51
|
+
}
|
|
52
|
+
class $ZodAsyncError extends Error {
|
|
53
|
+
constructor() {
|
|
54
|
+
super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
class $ZodEncodeError extends Error {
|
|
58
|
+
constructor(name) {
|
|
59
|
+
super(`Encountered unidirectional transform during encode: ${name}`);
|
|
60
|
+
this.name = "ZodEncodeError";
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const globalConfig = {};
|
|
64
|
+
function config(newConfig) {
|
|
65
|
+
return globalConfig;
|
|
66
|
+
}
|
|
67
|
+
function getEnumValues(entries) {
|
|
68
|
+
const numericValues = Object.values(entries).filter((v) => typeof v === "number");
|
|
69
|
+
const values = Object.entries(entries).filter(([k, _]) => numericValues.indexOf(+k) === -1).map(([_, v]) => v);
|
|
70
|
+
return values;
|
|
71
|
+
}
|
|
72
|
+
function jsonStringifyReplacer(_, value) {
|
|
73
|
+
if (typeof value === "bigint")
|
|
74
|
+
return value.toString();
|
|
75
|
+
return value;
|
|
76
|
+
}
|
|
77
|
+
function cached(getter) {
|
|
78
|
+
return {
|
|
79
|
+
get value() {
|
|
80
|
+
{
|
|
81
|
+
const value = getter();
|
|
82
|
+
Object.defineProperty(this, "value", { value });
|
|
83
|
+
return value;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function nullish(input) {
|
|
89
|
+
return input === null || input === void 0;
|
|
90
|
+
}
|
|
91
|
+
function cleanRegex(source) {
|
|
92
|
+
const start = source.startsWith("^") ? 1 : 0;
|
|
93
|
+
const end = source.endsWith("$") ? source.length - 1 : source.length;
|
|
94
|
+
return source.slice(start, end);
|
|
95
|
+
}
|
|
96
|
+
function floatSafeRemainder(val, step) {
|
|
97
|
+
const valDecCount = (val.toString().split(".")[1] || "").length;
|
|
98
|
+
const stepString = step.toString();
|
|
99
|
+
let stepDecCount = (stepString.split(".")[1] || "").length;
|
|
100
|
+
if (stepDecCount === 0 && /\d?e-\d?/.test(stepString)) {
|
|
101
|
+
const match = stepString.match(/\d?e-(\d?)/);
|
|
102
|
+
if (match?.[1]) {
|
|
103
|
+
stepDecCount = Number.parseInt(match[1]);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
|
|
107
|
+
const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
|
|
108
|
+
const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
|
|
109
|
+
return valInt % stepInt / 10 ** decCount;
|
|
110
|
+
}
|
|
111
|
+
const EVALUATING = Symbol("evaluating");
|
|
112
|
+
function defineLazy(object2, key, getter) {
|
|
113
|
+
let value = void 0;
|
|
114
|
+
Object.defineProperty(object2, key, {
|
|
115
|
+
get() {
|
|
116
|
+
if (value === EVALUATING) {
|
|
117
|
+
return void 0;
|
|
118
|
+
}
|
|
119
|
+
if (value === void 0) {
|
|
120
|
+
value = EVALUATING;
|
|
121
|
+
value = getter();
|
|
122
|
+
}
|
|
123
|
+
return value;
|
|
124
|
+
},
|
|
125
|
+
set(v) {
|
|
126
|
+
Object.defineProperty(object2, key, {
|
|
127
|
+
value: v
|
|
128
|
+
// configurable: true,
|
|
129
|
+
});
|
|
130
|
+
},
|
|
131
|
+
configurable: true
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
function assignProp(target, prop, value) {
|
|
135
|
+
Object.defineProperty(target, prop, {
|
|
136
|
+
value,
|
|
137
|
+
writable: true,
|
|
138
|
+
enumerable: true,
|
|
139
|
+
configurable: true
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
function mergeDefs(...defs) {
|
|
143
|
+
const mergedDescriptors = {};
|
|
144
|
+
for (const def of defs) {
|
|
145
|
+
const descriptors = Object.getOwnPropertyDescriptors(def);
|
|
146
|
+
Object.assign(mergedDescriptors, descriptors);
|
|
147
|
+
}
|
|
148
|
+
return Object.defineProperties({}, mergedDescriptors);
|
|
149
|
+
}
|
|
150
|
+
function esc(str) {
|
|
151
|
+
return JSON.stringify(str);
|
|
152
|
+
}
|
|
153
|
+
function slugify(input) {
|
|
154
|
+
return input.toLowerCase().trim().replace(/[^\w\s-]/g, "").replace(/[\s_-]+/g, "-").replace(/^-+|-+$/g, "");
|
|
155
|
+
}
|
|
156
|
+
const captureStackTrace = "captureStackTrace" in Error ? Error.captureStackTrace : (..._args) => {
|
|
157
|
+
};
|
|
158
|
+
function isObject(data) {
|
|
159
|
+
return typeof data === "object" && data !== null && !Array.isArray(data);
|
|
160
|
+
}
|
|
161
|
+
const allowsEval = cached(() => {
|
|
162
|
+
if (typeof navigator !== "undefined" && navigator?.userAgent?.includes("Cloudflare")) {
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
try {
|
|
166
|
+
const F = Function;
|
|
167
|
+
new F("");
|
|
168
|
+
return true;
|
|
169
|
+
} catch (_) {
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
function isPlainObject(o) {
|
|
174
|
+
if (isObject(o) === false)
|
|
175
|
+
return false;
|
|
176
|
+
const ctor = o.constructor;
|
|
177
|
+
if (ctor === void 0)
|
|
178
|
+
return true;
|
|
179
|
+
if (typeof ctor !== "function")
|
|
180
|
+
return true;
|
|
181
|
+
const prot = ctor.prototype;
|
|
182
|
+
if (isObject(prot) === false)
|
|
183
|
+
return false;
|
|
184
|
+
if (Object.prototype.hasOwnProperty.call(prot, "isPrototypeOf") === false) {
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
return true;
|
|
188
|
+
}
|
|
189
|
+
function shallowClone(o) {
|
|
190
|
+
if (isPlainObject(o))
|
|
191
|
+
return { ...o };
|
|
192
|
+
if (Array.isArray(o))
|
|
193
|
+
return [...o];
|
|
194
|
+
return o;
|
|
195
|
+
}
|
|
196
|
+
const propertyKeyTypes = /* @__PURE__ */ new Set(["string", "number", "symbol"]);
|
|
197
|
+
function escapeRegex(str) {
|
|
198
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
199
|
+
}
|
|
200
|
+
function clone(inst, def, params) {
|
|
201
|
+
const cl = new inst._zod.constr(def ?? inst._zod.def);
|
|
202
|
+
if (!def || params?.parent)
|
|
203
|
+
cl._zod.parent = inst;
|
|
204
|
+
return cl;
|
|
205
|
+
}
|
|
206
|
+
function normalizeParams(_params) {
|
|
207
|
+
const params = _params;
|
|
208
|
+
if (!params)
|
|
209
|
+
return {};
|
|
210
|
+
if (typeof params === "string")
|
|
211
|
+
return { error: () => params };
|
|
212
|
+
if (params?.message !== void 0) {
|
|
213
|
+
if (params?.error !== void 0)
|
|
214
|
+
throw new Error("Cannot specify both `message` and `error` params");
|
|
215
|
+
params.error = params.message;
|
|
216
|
+
}
|
|
217
|
+
delete params.message;
|
|
218
|
+
if (typeof params.error === "string")
|
|
219
|
+
return { ...params, error: () => params.error };
|
|
220
|
+
return params;
|
|
221
|
+
}
|
|
222
|
+
function optionalKeys(shape) {
|
|
223
|
+
return Object.keys(shape).filter((k) => {
|
|
224
|
+
return shape[k]._zod.optin === "optional" && shape[k]._zod.optout === "optional";
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
const NUMBER_FORMAT_RANGES = {
|
|
228
|
+
safeint: [Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER],
|
|
229
|
+
int32: [-2147483648, 2147483647],
|
|
230
|
+
uint32: [0, 4294967295],
|
|
231
|
+
float32: [-34028234663852886e22, 34028234663852886e22],
|
|
232
|
+
float64: [-Number.MAX_VALUE, Number.MAX_VALUE]
|
|
233
|
+
};
|
|
234
|
+
function pick(schema, mask) {
|
|
235
|
+
const currDef = schema._zod.def;
|
|
236
|
+
const checks = currDef.checks;
|
|
237
|
+
const hasChecks = checks && checks.length > 0;
|
|
238
|
+
if (hasChecks) {
|
|
239
|
+
throw new Error(".pick() cannot be used on object schemas containing refinements");
|
|
240
|
+
}
|
|
241
|
+
const def = mergeDefs(schema._zod.def, {
|
|
242
|
+
get shape() {
|
|
243
|
+
const newShape = {};
|
|
244
|
+
for (const key in mask) {
|
|
245
|
+
if (!(key in currDef.shape)) {
|
|
246
|
+
throw new Error(`Unrecognized key: "${key}"`);
|
|
247
|
+
}
|
|
248
|
+
if (!mask[key])
|
|
249
|
+
continue;
|
|
250
|
+
newShape[key] = currDef.shape[key];
|
|
251
|
+
}
|
|
252
|
+
assignProp(this, "shape", newShape);
|
|
253
|
+
return newShape;
|
|
254
|
+
},
|
|
255
|
+
checks: []
|
|
256
|
+
});
|
|
257
|
+
return clone(schema, def);
|
|
258
|
+
}
|
|
259
|
+
function omit(schema, mask) {
|
|
260
|
+
const currDef = schema._zod.def;
|
|
261
|
+
const checks = currDef.checks;
|
|
262
|
+
const hasChecks = checks && checks.length > 0;
|
|
263
|
+
if (hasChecks) {
|
|
264
|
+
throw new Error(".omit() cannot be used on object schemas containing refinements");
|
|
265
|
+
}
|
|
266
|
+
const def = mergeDefs(schema._zod.def, {
|
|
267
|
+
get shape() {
|
|
268
|
+
const newShape = { ...schema._zod.def.shape };
|
|
269
|
+
for (const key in mask) {
|
|
270
|
+
if (!(key in currDef.shape)) {
|
|
271
|
+
throw new Error(`Unrecognized key: "${key}"`);
|
|
272
|
+
}
|
|
273
|
+
if (!mask[key])
|
|
274
|
+
continue;
|
|
275
|
+
delete newShape[key];
|
|
276
|
+
}
|
|
277
|
+
assignProp(this, "shape", newShape);
|
|
278
|
+
return newShape;
|
|
279
|
+
},
|
|
280
|
+
checks: []
|
|
281
|
+
});
|
|
282
|
+
return clone(schema, def);
|
|
283
|
+
}
|
|
284
|
+
function extend(schema, shape) {
|
|
285
|
+
if (!isPlainObject(shape)) {
|
|
286
|
+
throw new Error("Invalid input to extend: expected a plain object");
|
|
287
|
+
}
|
|
288
|
+
const checks = schema._zod.def.checks;
|
|
289
|
+
const hasChecks = checks && checks.length > 0;
|
|
290
|
+
if (hasChecks) {
|
|
291
|
+
const existingShape = schema._zod.def.shape;
|
|
292
|
+
for (const key in shape) {
|
|
293
|
+
if (Object.getOwnPropertyDescriptor(existingShape, key) !== void 0) {
|
|
294
|
+
throw new Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.");
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
const def = mergeDefs(schema._zod.def, {
|
|
299
|
+
get shape() {
|
|
300
|
+
const _shape = { ...schema._zod.def.shape, ...shape };
|
|
301
|
+
assignProp(this, "shape", _shape);
|
|
302
|
+
return _shape;
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
return clone(schema, def);
|
|
306
|
+
}
|
|
307
|
+
function safeExtend(schema, shape) {
|
|
308
|
+
if (!isPlainObject(shape)) {
|
|
309
|
+
throw new Error("Invalid input to safeExtend: expected a plain object");
|
|
310
|
+
}
|
|
311
|
+
const def = mergeDefs(schema._zod.def, {
|
|
312
|
+
get shape() {
|
|
313
|
+
const _shape = { ...schema._zod.def.shape, ...shape };
|
|
314
|
+
assignProp(this, "shape", _shape);
|
|
315
|
+
return _shape;
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
return clone(schema, def);
|
|
319
|
+
}
|
|
320
|
+
function merge(a, b) {
|
|
321
|
+
const def = mergeDefs(a._zod.def, {
|
|
322
|
+
get shape() {
|
|
323
|
+
const _shape = { ...a._zod.def.shape, ...b._zod.def.shape };
|
|
324
|
+
assignProp(this, "shape", _shape);
|
|
325
|
+
return _shape;
|
|
326
|
+
},
|
|
327
|
+
get catchall() {
|
|
328
|
+
return b._zod.def.catchall;
|
|
329
|
+
},
|
|
330
|
+
checks: []
|
|
331
|
+
// delete existing checks
|
|
332
|
+
});
|
|
333
|
+
return clone(a, def);
|
|
334
|
+
}
|
|
335
|
+
function partial(Class, schema, mask) {
|
|
336
|
+
const currDef = schema._zod.def;
|
|
337
|
+
const checks = currDef.checks;
|
|
338
|
+
const hasChecks = checks && checks.length > 0;
|
|
339
|
+
if (hasChecks) {
|
|
340
|
+
throw new Error(".partial() cannot be used on object schemas containing refinements");
|
|
341
|
+
}
|
|
342
|
+
const def = mergeDefs(schema._zod.def, {
|
|
343
|
+
get shape() {
|
|
344
|
+
const oldShape = schema._zod.def.shape;
|
|
345
|
+
const shape = { ...oldShape };
|
|
346
|
+
if (mask) {
|
|
347
|
+
for (const key in mask) {
|
|
348
|
+
if (!(key in oldShape)) {
|
|
349
|
+
throw new Error(`Unrecognized key: "${key}"`);
|
|
350
|
+
}
|
|
351
|
+
if (!mask[key])
|
|
352
|
+
continue;
|
|
353
|
+
shape[key] = Class ? new Class({
|
|
354
|
+
type: "optional",
|
|
355
|
+
innerType: oldShape[key]
|
|
356
|
+
}) : oldShape[key];
|
|
357
|
+
}
|
|
358
|
+
} else {
|
|
359
|
+
for (const key in oldShape) {
|
|
360
|
+
shape[key] = Class ? new Class({
|
|
361
|
+
type: "optional",
|
|
362
|
+
innerType: oldShape[key]
|
|
363
|
+
}) : oldShape[key];
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
assignProp(this, "shape", shape);
|
|
367
|
+
return shape;
|
|
368
|
+
},
|
|
369
|
+
checks: []
|
|
370
|
+
});
|
|
371
|
+
return clone(schema, def);
|
|
372
|
+
}
|
|
373
|
+
function required(Class, schema, mask) {
|
|
374
|
+
const def = mergeDefs(schema._zod.def, {
|
|
375
|
+
get shape() {
|
|
376
|
+
const oldShape = schema._zod.def.shape;
|
|
377
|
+
const shape = { ...oldShape };
|
|
378
|
+
if (mask) {
|
|
379
|
+
for (const key in mask) {
|
|
380
|
+
if (!(key in shape)) {
|
|
381
|
+
throw new Error(`Unrecognized key: "${key}"`);
|
|
382
|
+
}
|
|
383
|
+
if (!mask[key])
|
|
384
|
+
continue;
|
|
385
|
+
shape[key] = new Class({
|
|
386
|
+
type: "nonoptional",
|
|
387
|
+
innerType: oldShape[key]
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
} else {
|
|
391
|
+
for (const key in oldShape) {
|
|
392
|
+
shape[key] = new Class({
|
|
393
|
+
type: "nonoptional",
|
|
394
|
+
innerType: oldShape[key]
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
assignProp(this, "shape", shape);
|
|
399
|
+
return shape;
|
|
400
|
+
}
|
|
401
|
+
});
|
|
402
|
+
return clone(schema, def);
|
|
403
|
+
}
|
|
404
|
+
function aborted(x, startIndex = 0) {
|
|
405
|
+
if (x.aborted === true)
|
|
406
|
+
return true;
|
|
407
|
+
for (let i = startIndex; i < x.issues.length; i++) {
|
|
408
|
+
if (x.issues[i]?.continue !== true) {
|
|
409
|
+
return true;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
return false;
|
|
413
|
+
}
|
|
414
|
+
function prefixIssues(path, issues) {
|
|
415
|
+
return issues.map((iss) => {
|
|
416
|
+
var _a2;
|
|
417
|
+
(_a2 = iss).path ?? (_a2.path = []);
|
|
418
|
+
iss.path.unshift(path);
|
|
419
|
+
return iss;
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
function unwrapMessage(message) {
|
|
423
|
+
return typeof message === "string" ? message : message?.message;
|
|
424
|
+
}
|
|
425
|
+
function finalizeIssue(iss, ctx, config2) {
|
|
426
|
+
const full = { ...iss, path: iss.path ?? [] };
|
|
427
|
+
if (!iss.message) {
|
|
428
|
+
const message = unwrapMessage(iss.inst?._zod.def?.error?.(iss)) ?? unwrapMessage(ctx?.error?.(iss)) ?? unwrapMessage(config2.customError?.(iss)) ?? unwrapMessage(config2.localeError?.(iss)) ?? "Invalid input";
|
|
429
|
+
full.message = message;
|
|
430
|
+
}
|
|
431
|
+
delete full.inst;
|
|
432
|
+
delete full.continue;
|
|
433
|
+
if (!ctx?.reportInput) {
|
|
434
|
+
delete full.input;
|
|
435
|
+
}
|
|
436
|
+
return full;
|
|
437
|
+
}
|
|
438
|
+
function getLengthableOrigin(input) {
|
|
439
|
+
if (Array.isArray(input))
|
|
440
|
+
return "array";
|
|
441
|
+
if (typeof input === "string")
|
|
442
|
+
return "string";
|
|
443
|
+
return "unknown";
|
|
444
|
+
}
|
|
445
|
+
function issue(...args) {
|
|
446
|
+
const [iss, input, inst] = args;
|
|
447
|
+
if (typeof iss === "string") {
|
|
448
|
+
return {
|
|
449
|
+
message: iss,
|
|
450
|
+
code: "custom",
|
|
451
|
+
input,
|
|
452
|
+
inst
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
return { ...iss };
|
|
456
|
+
}
|
|
457
|
+
const initializer$1 = (inst, def) => {
|
|
458
|
+
inst.name = "$ZodError";
|
|
459
|
+
Object.defineProperty(inst, "_zod", {
|
|
460
|
+
value: inst._zod,
|
|
461
|
+
enumerable: false
|
|
462
|
+
});
|
|
463
|
+
Object.defineProperty(inst, "issues", {
|
|
464
|
+
value: def,
|
|
465
|
+
enumerable: false
|
|
466
|
+
});
|
|
467
|
+
inst.message = JSON.stringify(def, jsonStringifyReplacer, 2);
|
|
468
|
+
Object.defineProperty(inst, "toString", {
|
|
469
|
+
value: () => inst.message,
|
|
470
|
+
enumerable: false
|
|
471
|
+
});
|
|
472
|
+
};
|
|
473
|
+
const $ZodError = $constructor("$ZodError", initializer$1);
|
|
474
|
+
const $ZodRealError = $constructor("$ZodError", initializer$1, { Parent: Error });
|
|
475
|
+
function flattenError(error, mapper = (issue2) => issue2.message) {
|
|
476
|
+
const fieldErrors = {};
|
|
477
|
+
const formErrors = [];
|
|
478
|
+
for (const sub of error.issues) {
|
|
479
|
+
if (sub.path.length > 0) {
|
|
480
|
+
fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
|
|
481
|
+
fieldErrors[sub.path[0]].push(mapper(sub));
|
|
482
|
+
} else {
|
|
483
|
+
formErrors.push(mapper(sub));
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
return { formErrors, fieldErrors };
|
|
487
|
+
}
|
|
488
|
+
function formatError(error, mapper = (issue2) => issue2.message) {
|
|
489
|
+
const fieldErrors = { _errors: [] };
|
|
490
|
+
const processError = (error2) => {
|
|
491
|
+
for (const issue2 of error2.issues) {
|
|
492
|
+
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
493
|
+
issue2.errors.map((issues) => processError({ issues }));
|
|
494
|
+
} else if (issue2.code === "invalid_key") {
|
|
495
|
+
processError({ issues: issue2.issues });
|
|
496
|
+
} else if (issue2.code === "invalid_element") {
|
|
497
|
+
processError({ issues: issue2.issues });
|
|
498
|
+
} else if (issue2.path.length === 0) {
|
|
499
|
+
fieldErrors._errors.push(mapper(issue2));
|
|
500
|
+
} else {
|
|
501
|
+
let curr = fieldErrors;
|
|
502
|
+
let i = 0;
|
|
503
|
+
while (i < issue2.path.length) {
|
|
504
|
+
const el = issue2.path[i];
|
|
505
|
+
const terminal = i === issue2.path.length - 1;
|
|
506
|
+
if (!terminal) {
|
|
507
|
+
curr[el] = curr[el] || { _errors: [] };
|
|
508
|
+
} else {
|
|
509
|
+
curr[el] = curr[el] || { _errors: [] };
|
|
510
|
+
curr[el]._errors.push(mapper(issue2));
|
|
511
|
+
}
|
|
512
|
+
curr = curr[el];
|
|
513
|
+
i++;
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
};
|
|
518
|
+
processError(error);
|
|
519
|
+
return fieldErrors;
|
|
520
|
+
}
|
|
521
|
+
const _parse = (_Err) => (schema, value, _ctx, _params) => {
|
|
522
|
+
const ctx = _ctx ? Object.assign(_ctx, { async: false }) : { async: false };
|
|
523
|
+
const result = schema._zod.run({ value, issues: [] }, ctx);
|
|
524
|
+
if (result instanceof Promise) {
|
|
525
|
+
throw new $ZodAsyncError();
|
|
526
|
+
}
|
|
527
|
+
if (result.issues.length) {
|
|
528
|
+
const e = new (_params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())));
|
|
529
|
+
captureStackTrace(e, _params?.callee);
|
|
530
|
+
throw e;
|
|
531
|
+
}
|
|
532
|
+
return result.value;
|
|
533
|
+
};
|
|
534
|
+
const _parseAsync = (_Err) => async (schema, value, _ctx, params) => {
|
|
535
|
+
const ctx = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
|
|
536
|
+
let result = schema._zod.run({ value, issues: [] }, ctx);
|
|
537
|
+
if (result instanceof Promise)
|
|
538
|
+
result = await result;
|
|
539
|
+
if (result.issues.length) {
|
|
540
|
+
const e = new (params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())));
|
|
541
|
+
captureStackTrace(e, params?.callee);
|
|
542
|
+
throw e;
|
|
543
|
+
}
|
|
544
|
+
return result.value;
|
|
545
|
+
};
|
|
546
|
+
const _safeParse = (_Err) => (schema, value, _ctx) => {
|
|
547
|
+
const ctx = _ctx ? { ..._ctx, async: false } : { async: false };
|
|
548
|
+
const result = schema._zod.run({ value, issues: [] }, ctx);
|
|
549
|
+
if (result instanceof Promise) {
|
|
550
|
+
throw new $ZodAsyncError();
|
|
551
|
+
}
|
|
552
|
+
return result.issues.length ? {
|
|
553
|
+
success: false,
|
|
554
|
+
error: new (_Err ?? $ZodError)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())))
|
|
555
|
+
} : { success: true, data: result.value };
|
|
556
|
+
};
|
|
557
|
+
const safeParse$1 = /* @__PURE__ */ _safeParse($ZodRealError);
|
|
558
|
+
const _safeParseAsync = (_Err) => async (schema, value, _ctx) => {
|
|
559
|
+
const ctx = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
|
|
560
|
+
let result = schema._zod.run({ value, issues: [] }, ctx);
|
|
561
|
+
if (result instanceof Promise)
|
|
562
|
+
result = await result;
|
|
563
|
+
return result.issues.length ? {
|
|
564
|
+
success: false,
|
|
565
|
+
error: new _Err(result.issues.map((iss) => finalizeIssue(iss, ctx, config())))
|
|
566
|
+
} : { success: true, data: result.value };
|
|
567
|
+
};
|
|
568
|
+
const safeParseAsync$1 = /* @__PURE__ */ _safeParseAsync($ZodRealError);
|
|
569
|
+
const _encode = (_Err) => (schema, value, _ctx) => {
|
|
570
|
+
const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
|
|
571
|
+
return _parse(_Err)(schema, value, ctx);
|
|
572
|
+
};
|
|
573
|
+
const _decode = (_Err) => (schema, value, _ctx) => {
|
|
574
|
+
return _parse(_Err)(schema, value, _ctx);
|
|
575
|
+
};
|
|
576
|
+
const _encodeAsync = (_Err) => async (schema, value, _ctx) => {
|
|
577
|
+
const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
|
|
578
|
+
return _parseAsync(_Err)(schema, value, ctx);
|
|
579
|
+
};
|
|
580
|
+
const _decodeAsync = (_Err) => async (schema, value, _ctx) => {
|
|
581
|
+
return _parseAsync(_Err)(schema, value, _ctx);
|
|
582
|
+
};
|
|
583
|
+
const _safeEncode = (_Err) => (schema, value, _ctx) => {
|
|
584
|
+
const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
|
|
585
|
+
return _safeParse(_Err)(schema, value, ctx);
|
|
586
|
+
};
|
|
587
|
+
const _safeDecode = (_Err) => (schema, value, _ctx) => {
|
|
588
|
+
return _safeParse(_Err)(schema, value, _ctx);
|
|
589
|
+
};
|
|
590
|
+
const _safeEncodeAsync = (_Err) => async (schema, value, _ctx) => {
|
|
591
|
+
const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
|
|
592
|
+
return _safeParseAsync(_Err)(schema, value, ctx);
|
|
593
|
+
};
|
|
594
|
+
const _safeDecodeAsync = (_Err) => async (schema, value, _ctx) => {
|
|
595
|
+
return _safeParseAsync(_Err)(schema, value, _ctx);
|
|
596
|
+
};
|
|
597
|
+
const cuid = /^[cC][^\s-]{8,}$/;
|
|
598
|
+
const cuid2 = /^[0-9a-z]+$/;
|
|
599
|
+
const ulid = /^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/;
|
|
600
|
+
const xid = /^[0-9a-vA-V]{20}$/;
|
|
601
|
+
const ksuid = /^[A-Za-z0-9]{27}$/;
|
|
602
|
+
const nanoid = /^[a-zA-Z0-9_-]{21}$/;
|
|
603
|
+
const duration$1 = /^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/;
|
|
604
|
+
const guid = /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/;
|
|
605
|
+
const uuid = (version2) => {
|
|
606
|
+
if (!version2)
|
|
607
|
+
return /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/;
|
|
608
|
+
return new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${version2}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`);
|
|
609
|
+
};
|
|
610
|
+
const email = /^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;
|
|
611
|
+
const _emoji$1 = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
|
|
612
|
+
function emoji() {
|
|
613
|
+
return new RegExp(_emoji$1, "u");
|
|
614
|
+
}
|
|
615
|
+
const ipv4 = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
|
|
616
|
+
const ipv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/;
|
|
617
|
+
const cidrv4 = /^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/;
|
|
618
|
+
const cidrv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
|
|
619
|
+
const base64 = /^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/;
|
|
620
|
+
const base64url = /^[A-Za-z0-9_-]*$/;
|
|
621
|
+
const e164 = /^\+[1-9]\d{6,14}$/;
|
|
622
|
+
const dateSource = `(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))`;
|
|
623
|
+
const date$1 = /* @__PURE__ */ new RegExp(`^${dateSource}$`);
|
|
624
|
+
function timeSource(args) {
|
|
625
|
+
const hhmm = `(?:[01]\\d|2[0-3]):[0-5]\\d`;
|
|
626
|
+
const regex = typeof args.precision === "number" ? args.precision === -1 ? `${hhmm}` : args.precision === 0 ? `${hhmm}:[0-5]\\d` : `${hhmm}:[0-5]\\d\\.\\d{${args.precision}}` : `${hhmm}(?::[0-5]\\d(?:\\.\\d+)?)?`;
|
|
627
|
+
return regex;
|
|
628
|
+
}
|
|
629
|
+
function time$1(args) {
|
|
630
|
+
return new RegExp(`^${timeSource(args)}$`);
|
|
631
|
+
}
|
|
632
|
+
function datetime$1(args) {
|
|
633
|
+
const time2 = timeSource({ precision: args.precision });
|
|
634
|
+
const opts = ["Z"];
|
|
635
|
+
if (args.local)
|
|
636
|
+
opts.push("");
|
|
637
|
+
if (args.offset)
|
|
638
|
+
opts.push(`([+-](?:[01]\\d|2[0-3]):[0-5]\\d)`);
|
|
639
|
+
const timeRegex = `${time2}(?:${opts.join("|")})`;
|
|
640
|
+
return new RegExp(`^${dateSource}T(?:${timeRegex})$`);
|
|
641
|
+
}
|
|
642
|
+
const string$1 = (params) => {
|
|
643
|
+
const regex = params ? `[\\s\\S]{${params?.minimum ?? 0},${params?.maximum ?? ""}}` : `[\\s\\S]*`;
|
|
644
|
+
return new RegExp(`^${regex}$`);
|
|
645
|
+
};
|
|
646
|
+
const integer = /^-?\d+$/;
|
|
647
|
+
const number$1 = /^-?\d+(?:\.\d+)?$/;
|
|
648
|
+
const boolean$1 = /^(?:true|false)$/i;
|
|
649
|
+
const lowercase = /^[^A-Z]*$/;
|
|
650
|
+
const uppercase = /^[^a-z]*$/;
|
|
651
|
+
const $ZodCheck = /* @__PURE__ */ $constructor("$ZodCheck", (inst, def) => {
|
|
652
|
+
var _a2;
|
|
653
|
+
inst._zod ?? (inst._zod = {});
|
|
654
|
+
inst._zod.def = def;
|
|
655
|
+
(_a2 = inst._zod).onattach ?? (_a2.onattach = []);
|
|
656
|
+
});
|
|
657
|
+
const numericOriginMap = {
|
|
658
|
+
number: "number",
|
|
659
|
+
bigint: "bigint",
|
|
660
|
+
object: "date"
|
|
661
|
+
};
|
|
662
|
+
const $ZodCheckLessThan = /* @__PURE__ */ $constructor("$ZodCheckLessThan", (inst, def) => {
|
|
663
|
+
$ZodCheck.init(inst, def);
|
|
664
|
+
const origin = numericOriginMap[typeof def.value];
|
|
665
|
+
inst._zod.onattach.push((inst2) => {
|
|
666
|
+
const bag = inst2._zod.bag;
|
|
667
|
+
const curr = (def.inclusive ? bag.maximum : bag.exclusiveMaximum) ?? Number.POSITIVE_INFINITY;
|
|
668
|
+
if (def.value < curr) {
|
|
669
|
+
if (def.inclusive)
|
|
670
|
+
bag.maximum = def.value;
|
|
671
|
+
else
|
|
672
|
+
bag.exclusiveMaximum = def.value;
|
|
673
|
+
}
|
|
674
|
+
});
|
|
675
|
+
inst._zod.check = (payload) => {
|
|
676
|
+
if (def.inclusive ? payload.value <= def.value : payload.value < def.value) {
|
|
677
|
+
return;
|
|
678
|
+
}
|
|
679
|
+
payload.issues.push({
|
|
680
|
+
origin,
|
|
681
|
+
code: "too_big",
|
|
682
|
+
maximum: typeof def.value === "object" ? def.value.getTime() : def.value,
|
|
683
|
+
input: payload.value,
|
|
684
|
+
inclusive: def.inclusive,
|
|
685
|
+
inst,
|
|
686
|
+
continue: !def.abort
|
|
687
|
+
});
|
|
688
|
+
};
|
|
689
|
+
});
|
|
690
|
+
const $ZodCheckGreaterThan = /* @__PURE__ */ $constructor("$ZodCheckGreaterThan", (inst, def) => {
|
|
691
|
+
$ZodCheck.init(inst, def);
|
|
692
|
+
const origin = numericOriginMap[typeof def.value];
|
|
693
|
+
inst._zod.onattach.push((inst2) => {
|
|
694
|
+
const bag = inst2._zod.bag;
|
|
695
|
+
const curr = (def.inclusive ? bag.minimum : bag.exclusiveMinimum) ?? Number.NEGATIVE_INFINITY;
|
|
696
|
+
if (def.value > curr) {
|
|
697
|
+
if (def.inclusive)
|
|
698
|
+
bag.minimum = def.value;
|
|
699
|
+
else
|
|
700
|
+
bag.exclusiveMinimum = def.value;
|
|
701
|
+
}
|
|
702
|
+
});
|
|
703
|
+
inst._zod.check = (payload) => {
|
|
704
|
+
if (def.inclusive ? payload.value >= def.value : payload.value > def.value) {
|
|
705
|
+
return;
|
|
706
|
+
}
|
|
707
|
+
payload.issues.push({
|
|
708
|
+
origin,
|
|
709
|
+
code: "too_small",
|
|
710
|
+
minimum: typeof def.value === "object" ? def.value.getTime() : def.value,
|
|
711
|
+
input: payload.value,
|
|
712
|
+
inclusive: def.inclusive,
|
|
713
|
+
inst,
|
|
714
|
+
continue: !def.abort
|
|
715
|
+
});
|
|
716
|
+
};
|
|
717
|
+
});
|
|
718
|
+
const $ZodCheckMultipleOf = /* @__PURE__ */ $constructor("$ZodCheckMultipleOf", (inst, def) => {
|
|
719
|
+
$ZodCheck.init(inst, def);
|
|
720
|
+
inst._zod.onattach.push((inst2) => {
|
|
721
|
+
var _a2;
|
|
722
|
+
(_a2 = inst2._zod.bag).multipleOf ?? (_a2.multipleOf = def.value);
|
|
723
|
+
});
|
|
724
|
+
inst._zod.check = (payload) => {
|
|
725
|
+
if (typeof payload.value !== typeof def.value)
|
|
726
|
+
throw new Error("Cannot mix number and bigint in multiple_of check.");
|
|
727
|
+
const isMultiple = typeof payload.value === "bigint" ? payload.value % def.value === BigInt(0) : floatSafeRemainder(payload.value, def.value) === 0;
|
|
728
|
+
if (isMultiple)
|
|
729
|
+
return;
|
|
730
|
+
payload.issues.push({
|
|
731
|
+
origin: typeof payload.value,
|
|
732
|
+
code: "not_multiple_of",
|
|
733
|
+
divisor: def.value,
|
|
734
|
+
input: payload.value,
|
|
735
|
+
inst,
|
|
736
|
+
continue: !def.abort
|
|
737
|
+
});
|
|
738
|
+
};
|
|
739
|
+
});
|
|
740
|
+
const $ZodCheckNumberFormat = /* @__PURE__ */ $constructor("$ZodCheckNumberFormat", (inst, def) => {
|
|
741
|
+
$ZodCheck.init(inst, def);
|
|
742
|
+
def.format = def.format || "float64";
|
|
743
|
+
const isInt = def.format?.includes("int");
|
|
744
|
+
const origin = isInt ? "int" : "number";
|
|
745
|
+
const [minimum, maximum] = NUMBER_FORMAT_RANGES[def.format];
|
|
746
|
+
inst._zod.onattach.push((inst2) => {
|
|
747
|
+
const bag = inst2._zod.bag;
|
|
748
|
+
bag.format = def.format;
|
|
749
|
+
bag.minimum = minimum;
|
|
750
|
+
bag.maximum = maximum;
|
|
751
|
+
if (isInt)
|
|
752
|
+
bag.pattern = integer;
|
|
753
|
+
});
|
|
754
|
+
inst._zod.check = (payload) => {
|
|
755
|
+
const input = payload.value;
|
|
756
|
+
if (isInt) {
|
|
757
|
+
if (!Number.isInteger(input)) {
|
|
758
|
+
payload.issues.push({
|
|
759
|
+
expected: origin,
|
|
760
|
+
format: def.format,
|
|
761
|
+
code: "invalid_type",
|
|
762
|
+
continue: false,
|
|
763
|
+
input,
|
|
764
|
+
inst
|
|
765
|
+
});
|
|
766
|
+
return;
|
|
767
|
+
}
|
|
768
|
+
if (!Number.isSafeInteger(input)) {
|
|
769
|
+
if (input > 0) {
|
|
770
|
+
payload.issues.push({
|
|
771
|
+
input,
|
|
772
|
+
code: "too_big",
|
|
773
|
+
maximum: Number.MAX_SAFE_INTEGER,
|
|
774
|
+
note: "Integers must be within the safe integer range.",
|
|
775
|
+
inst,
|
|
776
|
+
origin,
|
|
777
|
+
inclusive: true,
|
|
778
|
+
continue: !def.abort
|
|
779
|
+
});
|
|
780
|
+
} else {
|
|
781
|
+
payload.issues.push({
|
|
782
|
+
input,
|
|
783
|
+
code: "too_small",
|
|
784
|
+
minimum: Number.MIN_SAFE_INTEGER,
|
|
785
|
+
note: "Integers must be within the safe integer range.",
|
|
786
|
+
inst,
|
|
787
|
+
origin,
|
|
788
|
+
inclusive: true,
|
|
789
|
+
continue: !def.abort
|
|
790
|
+
});
|
|
791
|
+
}
|
|
792
|
+
return;
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
if (input < minimum) {
|
|
796
|
+
payload.issues.push({
|
|
797
|
+
origin: "number",
|
|
798
|
+
input,
|
|
799
|
+
code: "too_small",
|
|
800
|
+
minimum,
|
|
801
|
+
inclusive: true,
|
|
802
|
+
inst,
|
|
803
|
+
continue: !def.abort
|
|
804
|
+
});
|
|
805
|
+
}
|
|
806
|
+
if (input > maximum) {
|
|
807
|
+
payload.issues.push({
|
|
808
|
+
origin: "number",
|
|
809
|
+
input,
|
|
810
|
+
code: "too_big",
|
|
811
|
+
maximum,
|
|
812
|
+
inclusive: true,
|
|
813
|
+
inst,
|
|
814
|
+
continue: !def.abort
|
|
815
|
+
});
|
|
816
|
+
}
|
|
817
|
+
};
|
|
818
|
+
});
|
|
819
|
+
const $ZodCheckMaxLength = /* @__PURE__ */ $constructor("$ZodCheckMaxLength", (inst, def) => {
|
|
820
|
+
var _a2;
|
|
821
|
+
$ZodCheck.init(inst, def);
|
|
822
|
+
(_a2 = inst._zod.def).when ?? (_a2.when = (payload) => {
|
|
823
|
+
const val = payload.value;
|
|
824
|
+
return !nullish(val) && val.length !== void 0;
|
|
825
|
+
});
|
|
826
|
+
inst._zod.onattach.push((inst2) => {
|
|
827
|
+
const curr = inst2._zod.bag.maximum ?? Number.POSITIVE_INFINITY;
|
|
828
|
+
if (def.maximum < curr)
|
|
829
|
+
inst2._zod.bag.maximum = def.maximum;
|
|
830
|
+
});
|
|
831
|
+
inst._zod.check = (payload) => {
|
|
832
|
+
const input = payload.value;
|
|
833
|
+
const length = input.length;
|
|
834
|
+
if (length <= def.maximum)
|
|
835
|
+
return;
|
|
836
|
+
const origin = getLengthableOrigin(input);
|
|
837
|
+
payload.issues.push({
|
|
838
|
+
origin,
|
|
839
|
+
code: "too_big",
|
|
840
|
+
maximum: def.maximum,
|
|
841
|
+
inclusive: true,
|
|
842
|
+
input,
|
|
843
|
+
inst,
|
|
844
|
+
continue: !def.abort
|
|
845
|
+
});
|
|
846
|
+
};
|
|
847
|
+
});
|
|
848
|
+
const $ZodCheckMinLength = /* @__PURE__ */ $constructor("$ZodCheckMinLength", (inst, def) => {
|
|
849
|
+
var _a2;
|
|
850
|
+
$ZodCheck.init(inst, def);
|
|
851
|
+
(_a2 = inst._zod.def).when ?? (_a2.when = (payload) => {
|
|
852
|
+
const val = payload.value;
|
|
853
|
+
return !nullish(val) && val.length !== void 0;
|
|
854
|
+
});
|
|
855
|
+
inst._zod.onattach.push((inst2) => {
|
|
856
|
+
const curr = inst2._zod.bag.minimum ?? Number.NEGATIVE_INFINITY;
|
|
857
|
+
if (def.minimum > curr)
|
|
858
|
+
inst2._zod.bag.minimum = def.minimum;
|
|
859
|
+
});
|
|
860
|
+
inst._zod.check = (payload) => {
|
|
861
|
+
const input = payload.value;
|
|
862
|
+
const length = input.length;
|
|
863
|
+
if (length >= def.minimum)
|
|
864
|
+
return;
|
|
865
|
+
const origin = getLengthableOrigin(input);
|
|
866
|
+
payload.issues.push({
|
|
867
|
+
origin,
|
|
868
|
+
code: "too_small",
|
|
869
|
+
minimum: def.minimum,
|
|
870
|
+
inclusive: true,
|
|
871
|
+
input,
|
|
872
|
+
inst,
|
|
873
|
+
continue: !def.abort
|
|
874
|
+
});
|
|
875
|
+
};
|
|
876
|
+
});
|
|
877
|
+
const $ZodCheckLengthEquals = /* @__PURE__ */ $constructor("$ZodCheckLengthEquals", (inst, def) => {
|
|
878
|
+
var _a2;
|
|
879
|
+
$ZodCheck.init(inst, def);
|
|
880
|
+
(_a2 = inst._zod.def).when ?? (_a2.when = (payload) => {
|
|
881
|
+
const val = payload.value;
|
|
882
|
+
return !nullish(val) && val.length !== void 0;
|
|
883
|
+
});
|
|
884
|
+
inst._zod.onattach.push((inst2) => {
|
|
885
|
+
const bag = inst2._zod.bag;
|
|
886
|
+
bag.minimum = def.length;
|
|
887
|
+
bag.maximum = def.length;
|
|
888
|
+
bag.length = def.length;
|
|
889
|
+
});
|
|
890
|
+
inst._zod.check = (payload) => {
|
|
891
|
+
const input = payload.value;
|
|
892
|
+
const length = input.length;
|
|
893
|
+
if (length === def.length)
|
|
894
|
+
return;
|
|
895
|
+
const origin = getLengthableOrigin(input);
|
|
896
|
+
const tooBig = length > def.length;
|
|
897
|
+
payload.issues.push({
|
|
898
|
+
origin,
|
|
899
|
+
...tooBig ? { code: "too_big", maximum: def.length } : { code: "too_small", minimum: def.length },
|
|
900
|
+
inclusive: true,
|
|
901
|
+
exact: true,
|
|
902
|
+
input: payload.value,
|
|
903
|
+
inst,
|
|
904
|
+
continue: !def.abort
|
|
905
|
+
});
|
|
906
|
+
};
|
|
907
|
+
});
|
|
908
|
+
const $ZodCheckStringFormat = /* @__PURE__ */ $constructor("$ZodCheckStringFormat", (inst, def) => {
|
|
909
|
+
var _a2, _b;
|
|
910
|
+
$ZodCheck.init(inst, def);
|
|
911
|
+
inst._zod.onattach.push((inst2) => {
|
|
912
|
+
const bag = inst2._zod.bag;
|
|
913
|
+
bag.format = def.format;
|
|
914
|
+
if (def.pattern) {
|
|
915
|
+
bag.patterns ?? (bag.patterns = /* @__PURE__ */ new Set());
|
|
916
|
+
bag.patterns.add(def.pattern);
|
|
917
|
+
}
|
|
918
|
+
});
|
|
919
|
+
if (def.pattern)
|
|
920
|
+
(_a2 = inst._zod).check ?? (_a2.check = (payload) => {
|
|
921
|
+
def.pattern.lastIndex = 0;
|
|
922
|
+
if (def.pattern.test(payload.value))
|
|
923
|
+
return;
|
|
924
|
+
payload.issues.push({
|
|
925
|
+
origin: "string",
|
|
926
|
+
code: "invalid_format",
|
|
927
|
+
format: def.format,
|
|
928
|
+
input: payload.value,
|
|
929
|
+
...def.pattern ? { pattern: def.pattern.toString() } : {},
|
|
930
|
+
inst,
|
|
931
|
+
continue: !def.abort
|
|
932
|
+
});
|
|
933
|
+
});
|
|
934
|
+
else
|
|
935
|
+
(_b = inst._zod).check ?? (_b.check = () => {
|
|
936
|
+
});
|
|
937
|
+
});
|
|
938
|
+
const $ZodCheckRegex = /* @__PURE__ */ $constructor("$ZodCheckRegex", (inst, def) => {
|
|
939
|
+
$ZodCheckStringFormat.init(inst, def);
|
|
940
|
+
inst._zod.check = (payload) => {
|
|
941
|
+
def.pattern.lastIndex = 0;
|
|
942
|
+
if (def.pattern.test(payload.value))
|
|
943
|
+
return;
|
|
944
|
+
payload.issues.push({
|
|
945
|
+
origin: "string",
|
|
946
|
+
code: "invalid_format",
|
|
947
|
+
format: "regex",
|
|
948
|
+
input: payload.value,
|
|
949
|
+
pattern: def.pattern.toString(),
|
|
950
|
+
inst,
|
|
951
|
+
continue: !def.abort
|
|
952
|
+
});
|
|
953
|
+
};
|
|
954
|
+
});
|
|
955
|
+
const $ZodCheckLowerCase = /* @__PURE__ */ $constructor("$ZodCheckLowerCase", (inst, def) => {
|
|
956
|
+
def.pattern ?? (def.pattern = lowercase);
|
|
957
|
+
$ZodCheckStringFormat.init(inst, def);
|
|
958
|
+
});
|
|
959
|
+
const $ZodCheckUpperCase = /* @__PURE__ */ $constructor("$ZodCheckUpperCase", (inst, def) => {
|
|
960
|
+
def.pattern ?? (def.pattern = uppercase);
|
|
961
|
+
$ZodCheckStringFormat.init(inst, def);
|
|
962
|
+
});
|
|
963
|
+
const $ZodCheckIncludes = /* @__PURE__ */ $constructor("$ZodCheckIncludes", (inst, def) => {
|
|
964
|
+
$ZodCheck.init(inst, def);
|
|
965
|
+
const escapedRegex = escapeRegex(def.includes);
|
|
966
|
+
const pattern = new RegExp(typeof def.position === "number" ? `^.{${def.position}}${escapedRegex}` : escapedRegex);
|
|
967
|
+
def.pattern = pattern;
|
|
968
|
+
inst._zod.onattach.push((inst2) => {
|
|
969
|
+
const bag = inst2._zod.bag;
|
|
970
|
+
bag.patterns ?? (bag.patterns = /* @__PURE__ */ new Set());
|
|
971
|
+
bag.patterns.add(pattern);
|
|
972
|
+
});
|
|
973
|
+
inst._zod.check = (payload) => {
|
|
974
|
+
if (payload.value.includes(def.includes, def.position))
|
|
975
|
+
return;
|
|
976
|
+
payload.issues.push({
|
|
977
|
+
origin: "string",
|
|
978
|
+
code: "invalid_format",
|
|
979
|
+
format: "includes",
|
|
980
|
+
includes: def.includes,
|
|
981
|
+
input: payload.value,
|
|
982
|
+
inst,
|
|
983
|
+
continue: !def.abort
|
|
984
|
+
});
|
|
985
|
+
};
|
|
986
|
+
});
|
|
987
|
+
const $ZodCheckStartsWith = /* @__PURE__ */ $constructor("$ZodCheckStartsWith", (inst, def) => {
|
|
988
|
+
$ZodCheck.init(inst, def);
|
|
989
|
+
const pattern = new RegExp(`^${escapeRegex(def.prefix)}.*`);
|
|
990
|
+
def.pattern ?? (def.pattern = pattern);
|
|
991
|
+
inst._zod.onattach.push((inst2) => {
|
|
992
|
+
const bag = inst2._zod.bag;
|
|
993
|
+
bag.patterns ?? (bag.patterns = /* @__PURE__ */ new Set());
|
|
994
|
+
bag.patterns.add(pattern);
|
|
995
|
+
});
|
|
996
|
+
inst._zod.check = (payload) => {
|
|
997
|
+
if (payload.value.startsWith(def.prefix))
|
|
998
|
+
return;
|
|
999
|
+
payload.issues.push({
|
|
1000
|
+
origin: "string",
|
|
1001
|
+
code: "invalid_format",
|
|
1002
|
+
format: "starts_with",
|
|
1003
|
+
prefix: def.prefix,
|
|
1004
|
+
input: payload.value,
|
|
1005
|
+
inst,
|
|
1006
|
+
continue: !def.abort
|
|
1007
|
+
});
|
|
1008
|
+
};
|
|
1009
|
+
});
|
|
1010
|
+
const $ZodCheckEndsWith = /* @__PURE__ */ $constructor("$ZodCheckEndsWith", (inst, def) => {
|
|
1011
|
+
$ZodCheck.init(inst, def);
|
|
1012
|
+
const pattern = new RegExp(`.*${escapeRegex(def.suffix)}$`);
|
|
1013
|
+
def.pattern ?? (def.pattern = pattern);
|
|
1014
|
+
inst._zod.onattach.push((inst2) => {
|
|
1015
|
+
const bag = inst2._zod.bag;
|
|
1016
|
+
bag.patterns ?? (bag.patterns = /* @__PURE__ */ new Set());
|
|
1017
|
+
bag.patterns.add(pattern);
|
|
1018
|
+
});
|
|
1019
|
+
inst._zod.check = (payload) => {
|
|
1020
|
+
if (payload.value.endsWith(def.suffix))
|
|
1021
|
+
return;
|
|
1022
|
+
payload.issues.push({
|
|
1023
|
+
origin: "string",
|
|
1024
|
+
code: "invalid_format",
|
|
1025
|
+
format: "ends_with",
|
|
1026
|
+
suffix: def.suffix,
|
|
1027
|
+
input: payload.value,
|
|
1028
|
+
inst,
|
|
1029
|
+
continue: !def.abort
|
|
1030
|
+
});
|
|
1031
|
+
};
|
|
1032
|
+
});
|
|
1033
|
+
const $ZodCheckOverwrite = /* @__PURE__ */ $constructor("$ZodCheckOverwrite", (inst, def) => {
|
|
1034
|
+
$ZodCheck.init(inst, def);
|
|
1035
|
+
inst._zod.check = (payload) => {
|
|
1036
|
+
payload.value = def.tx(payload.value);
|
|
1037
|
+
};
|
|
1038
|
+
});
|
|
1039
|
+
class Doc {
|
|
1040
|
+
constructor(args = []) {
|
|
1041
|
+
this.content = [];
|
|
1042
|
+
this.indent = 0;
|
|
1043
|
+
if (this)
|
|
1044
|
+
this.args = args;
|
|
1045
|
+
}
|
|
1046
|
+
indented(fn) {
|
|
1047
|
+
this.indent += 1;
|
|
1048
|
+
fn(this);
|
|
1049
|
+
this.indent -= 1;
|
|
1050
|
+
}
|
|
1051
|
+
write(arg) {
|
|
1052
|
+
if (typeof arg === "function") {
|
|
1053
|
+
arg(this, { execution: "sync" });
|
|
1054
|
+
arg(this, { execution: "async" });
|
|
1055
|
+
return;
|
|
1056
|
+
}
|
|
1057
|
+
const content = arg;
|
|
1058
|
+
const lines = content.split("\n").filter((x) => x);
|
|
1059
|
+
const minIndent = Math.min(...lines.map((x) => x.length - x.trimStart().length));
|
|
1060
|
+
const dedented = lines.map((x) => x.slice(minIndent)).map((x) => " ".repeat(this.indent * 2) + x);
|
|
1061
|
+
for (const line of dedented) {
|
|
1062
|
+
this.content.push(line);
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
compile() {
|
|
1066
|
+
const F = Function;
|
|
1067
|
+
const args = this?.args;
|
|
1068
|
+
const content = this?.content ?? [``];
|
|
1069
|
+
const lines = [...content.map((x) => ` ${x}`)];
|
|
1070
|
+
return new F(...args, lines.join("\n"));
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
const version = {
|
|
1074
|
+
major: 4,
|
|
1075
|
+
minor: 3,
|
|
1076
|
+
patch: 6
|
|
1077
|
+
};
|
|
1078
|
+
const $ZodType = /* @__PURE__ */ $constructor("$ZodType", (inst, def) => {
|
|
1079
|
+
var _a2;
|
|
1080
|
+
inst ?? (inst = {});
|
|
1081
|
+
inst._zod.def = def;
|
|
1082
|
+
inst._zod.bag = inst._zod.bag || {};
|
|
1083
|
+
inst._zod.version = version;
|
|
1084
|
+
const checks = [...inst._zod.def.checks ?? []];
|
|
1085
|
+
if (inst._zod.traits.has("$ZodCheck")) {
|
|
1086
|
+
checks.unshift(inst);
|
|
1087
|
+
}
|
|
1088
|
+
for (const ch of checks) {
|
|
1089
|
+
for (const fn of ch._zod.onattach) {
|
|
1090
|
+
fn(inst);
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
if (checks.length === 0) {
|
|
1094
|
+
(_a2 = inst._zod).deferred ?? (_a2.deferred = []);
|
|
1095
|
+
inst._zod.deferred?.push(() => {
|
|
1096
|
+
inst._zod.run = inst._zod.parse;
|
|
1097
|
+
});
|
|
1098
|
+
} else {
|
|
1099
|
+
const runChecks = (payload, checks2, ctx) => {
|
|
1100
|
+
let isAborted = aborted(payload);
|
|
1101
|
+
let asyncResult;
|
|
1102
|
+
for (const ch of checks2) {
|
|
1103
|
+
if (ch._zod.def.when) {
|
|
1104
|
+
const shouldRun = ch._zod.def.when(payload);
|
|
1105
|
+
if (!shouldRun)
|
|
1106
|
+
continue;
|
|
1107
|
+
} else if (isAborted) {
|
|
1108
|
+
continue;
|
|
1109
|
+
}
|
|
1110
|
+
const currLen = payload.issues.length;
|
|
1111
|
+
const _ = ch._zod.check(payload);
|
|
1112
|
+
if (_ instanceof Promise && ctx?.async === false) {
|
|
1113
|
+
throw new $ZodAsyncError();
|
|
1114
|
+
}
|
|
1115
|
+
if (asyncResult || _ instanceof Promise) {
|
|
1116
|
+
asyncResult = (asyncResult ?? Promise.resolve()).then(async () => {
|
|
1117
|
+
await _;
|
|
1118
|
+
const nextLen = payload.issues.length;
|
|
1119
|
+
if (nextLen === currLen)
|
|
1120
|
+
return;
|
|
1121
|
+
if (!isAborted)
|
|
1122
|
+
isAborted = aborted(payload, currLen);
|
|
1123
|
+
});
|
|
1124
|
+
} else {
|
|
1125
|
+
const nextLen = payload.issues.length;
|
|
1126
|
+
if (nextLen === currLen)
|
|
1127
|
+
continue;
|
|
1128
|
+
if (!isAborted)
|
|
1129
|
+
isAborted = aborted(payload, currLen);
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
if (asyncResult) {
|
|
1133
|
+
return asyncResult.then(() => {
|
|
1134
|
+
return payload;
|
|
1135
|
+
});
|
|
1136
|
+
}
|
|
1137
|
+
return payload;
|
|
1138
|
+
};
|
|
1139
|
+
const handleCanaryResult = (canary, payload, ctx) => {
|
|
1140
|
+
if (aborted(canary)) {
|
|
1141
|
+
canary.aborted = true;
|
|
1142
|
+
return canary;
|
|
1143
|
+
}
|
|
1144
|
+
const checkResult = runChecks(payload, checks, ctx);
|
|
1145
|
+
if (checkResult instanceof Promise) {
|
|
1146
|
+
if (ctx.async === false)
|
|
1147
|
+
throw new $ZodAsyncError();
|
|
1148
|
+
return checkResult.then((checkResult2) => inst._zod.parse(checkResult2, ctx));
|
|
1149
|
+
}
|
|
1150
|
+
return inst._zod.parse(checkResult, ctx);
|
|
1151
|
+
};
|
|
1152
|
+
inst._zod.run = (payload, ctx) => {
|
|
1153
|
+
if (ctx.skipChecks) {
|
|
1154
|
+
return inst._zod.parse(payload, ctx);
|
|
1155
|
+
}
|
|
1156
|
+
if (ctx.direction === "backward") {
|
|
1157
|
+
const canary = inst._zod.parse({ value: payload.value, issues: [] }, { ...ctx, skipChecks: true });
|
|
1158
|
+
if (canary instanceof Promise) {
|
|
1159
|
+
return canary.then((canary2) => {
|
|
1160
|
+
return handleCanaryResult(canary2, payload, ctx);
|
|
1161
|
+
});
|
|
1162
|
+
}
|
|
1163
|
+
return handleCanaryResult(canary, payload, ctx);
|
|
1164
|
+
}
|
|
1165
|
+
const result = inst._zod.parse(payload, ctx);
|
|
1166
|
+
if (result instanceof Promise) {
|
|
1167
|
+
if (ctx.async === false)
|
|
1168
|
+
throw new $ZodAsyncError();
|
|
1169
|
+
return result.then((result2) => runChecks(result2, checks, ctx));
|
|
1170
|
+
}
|
|
1171
|
+
return runChecks(result, checks, ctx);
|
|
1172
|
+
};
|
|
1173
|
+
}
|
|
1174
|
+
defineLazy(inst, "~standard", () => ({
|
|
1175
|
+
validate: (value) => {
|
|
1176
|
+
try {
|
|
1177
|
+
const r = safeParse$1(inst, value);
|
|
1178
|
+
return r.success ? { value: r.data } : { issues: r.error?.issues };
|
|
1179
|
+
} catch (_) {
|
|
1180
|
+
return safeParseAsync$1(inst, value).then((r) => r.success ? { value: r.data } : { issues: r.error?.issues });
|
|
1181
|
+
}
|
|
1182
|
+
},
|
|
1183
|
+
vendor: "zod",
|
|
1184
|
+
version: 1
|
|
1185
|
+
}));
|
|
1186
|
+
});
|
|
1187
|
+
const $ZodString = /* @__PURE__ */ $constructor("$ZodString", (inst, def) => {
|
|
1188
|
+
$ZodType.init(inst, def);
|
|
1189
|
+
inst._zod.pattern = [...inst?._zod.bag?.patterns ?? []].pop() ?? string$1(inst._zod.bag);
|
|
1190
|
+
inst._zod.parse = (payload, _) => {
|
|
1191
|
+
if (def.coerce)
|
|
1192
|
+
try {
|
|
1193
|
+
payload.value = String(payload.value);
|
|
1194
|
+
} catch (_2) {
|
|
1195
|
+
}
|
|
1196
|
+
if (typeof payload.value === "string")
|
|
1197
|
+
return payload;
|
|
1198
|
+
payload.issues.push({
|
|
1199
|
+
expected: "string",
|
|
1200
|
+
code: "invalid_type",
|
|
1201
|
+
input: payload.value,
|
|
1202
|
+
inst
|
|
1203
|
+
});
|
|
1204
|
+
return payload;
|
|
1205
|
+
};
|
|
1206
|
+
});
|
|
1207
|
+
const $ZodStringFormat = /* @__PURE__ */ $constructor("$ZodStringFormat", (inst, def) => {
|
|
1208
|
+
$ZodCheckStringFormat.init(inst, def);
|
|
1209
|
+
$ZodString.init(inst, def);
|
|
1210
|
+
});
|
|
1211
|
+
const $ZodGUID = /* @__PURE__ */ $constructor("$ZodGUID", (inst, def) => {
|
|
1212
|
+
def.pattern ?? (def.pattern = guid);
|
|
1213
|
+
$ZodStringFormat.init(inst, def);
|
|
1214
|
+
});
|
|
1215
|
+
const $ZodUUID = /* @__PURE__ */ $constructor("$ZodUUID", (inst, def) => {
|
|
1216
|
+
if (def.version) {
|
|
1217
|
+
const versionMap = {
|
|
1218
|
+
v1: 1,
|
|
1219
|
+
v2: 2,
|
|
1220
|
+
v3: 3,
|
|
1221
|
+
v4: 4,
|
|
1222
|
+
v5: 5,
|
|
1223
|
+
v6: 6,
|
|
1224
|
+
v7: 7,
|
|
1225
|
+
v8: 8
|
|
1226
|
+
};
|
|
1227
|
+
const v = versionMap[def.version];
|
|
1228
|
+
if (v === void 0)
|
|
1229
|
+
throw new Error(`Invalid UUID version: "${def.version}"`);
|
|
1230
|
+
def.pattern ?? (def.pattern = uuid(v));
|
|
1231
|
+
} else
|
|
1232
|
+
def.pattern ?? (def.pattern = uuid());
|
|
1233
|
+
$ZodStringFormat.init(inst, def);
|
|
1234
|
+
});
|
|
1235
|
+
const $ZodEmail = /* @__PURE__ */ $constructor("$ZodEmail", (inst, def) => {
|
|
1236
|
+
def.pattern ?? (def.pattern = email);
|
|
1237
|
+
$ZodStringFormat.init(inst, def);
|
|
1238
|
+
});
|
|
1239
|
+
const $ZodURL = /* @__PURE__ */ $constructor("$ZodURL", (inst, def) => {
|
|
1240
|
+
$ZodStringFormat.init(inst, def);
|
|
1241
|
+
inst._zod.check = (payload) => {
|
|
1242
|
+
try {
|
|
1243
|
+
const trimmed = payload.value.trim();
|
|
1244
|
+
const url = new URL(trimmed);
|
|
1245
|
+
if (def.hostname) {
|
|
1246
|
+
def.hostname.lastIndex = 0;
|
|
1247
|
+
if (!def.hostname.test(url.hostname)) {
|
|
1248
|
+
payload.issues.push({
|
|
1249
|
+
code: "invalid_format",
|
|
1250
|
+
format: "url",
|
|
1251
|
+
note: "Invalid hostname",
|
|
1252
|
+
pattern: def.hostname.source,
|
|
1253
|
+
input: payload.value,
|
|
1254
|
+
inst,
|
|
1255
|
+
continue: !def.abort
|
|
1256
|
+
});
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
if (def.protocol) {
|
|
1260
|
+
def.protocol.lastIndex = 0;
|
|
1261
|
+
if (!def.protocol.test(url.protocol.endsWith(":") ? url.protocol.slice(0, -1) : url.protocol)) {
|
|
1262
|
+
payload.issues.push({
|
|
1263
|
+
code: "invalid_format",
|
|
1264
|
+
format: "url",
|
|
1265
|
+
note: "Invalid protocol",
|
|
1266
|
+
pattern: def.protocol.source,
|
|
1267
|
+
input: payload.value,
|
|
1268
|
+
inst,
|
|
1269
|
+
continue: !def.abort
|
|
1270
|
+
});
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
if (def.normalize) {
|
|
1274
|
+
payload.value = url.href;
|
|
1275
|
+
} else {
|
|
1276
|
+
payload.value = trimmed;
|
|
1277
|
+
}
|
|
1278
|
+
return;
|
|
1279
|
+
} catch (_) {
|
|
1280
|
+
payload.issues.push({
|
|
1281
|
+
code: "invalid_format",
|
|
1282
|
+
format: "url",
|
|
1283
|
+
input: payload.value,
|
|
1284
|
+
inst,
|
|
1285
|
+
continue: !def.abort
|
|
1286
|
+
});
|
|
1287
|
+
}
|
|
1288
|
+
};
|
|
1289
|
+
});
|
|
1290
|
+
const $ZodEmoji = /* @__PURE__ */ $constructor("$ZodEmoji", (inst, def) => {
|
|
1291
|
+
def.pattern ?? (def.pattern = emoji());
|
|
1292
|
+
$ZodStringFormat.init(inst, def);
|
|
1293
|
+
});
|
|
1294
|
+
const $ZodNanoID = /* @__PURE__ */ $constructor("$ZodNanoID", (inst, def) => {
|
|
1295
|
+
def.pattern ?? (def.pattern = nanoid);
|
|
1296
|
+
$ZodStringFormat.init(inst, def);
|
|
1297
|
+
});
|
|
1298
|
+
const $ZodCUID = /* @__PURE__ */ $constructor("$ZodCUID", (inst, def) => {
|
|
1299
|
+
def.pattern ?? (def.pattern = cuid);
|
|
1300
|
+
$ZodStringFormat.init(inst, def);
|
|
1301
|
+
});
|
|
1302
|
+
const $ZodCUID2 = /* @__PURE__ */ $constructor("$ZodCUID2", (inst, def) => {
|
|
1303
|
+
def.pattern ?? (def.pattern = cuid2);
|
|
1304
|
+
$ZodStringFormat.init(inst, def);
|
|
1305
|
+
});
|
|
1306
|
+
const $ZodULID = /* @__PURE__ */ $constructor("$ZodULID", (inst, def) => {
|
|
1307
|
+
def.pattern ?? (def.pattern = ulid);
|
|
1308
|
+
$ZodStringFormat.init(inst, def);
|
|
1309
|
+
});
|
|
1310
|
+
const $ZodXID = /* @__PURE__ */ $constructor("$ZodXID", (inst, def) => {
|
|
1311
|
+
def.pattern ?? (def.pattern = xid);
|
|
1312
|
+
$ZodStringFormat.init(inst, def);
|
|
1313
|
+
});
|
|
1314
|
+
const $ZodKSUID = /* @__PURE__ */ $constructor("$ZodKSUID", (inst, def) => {
|
|
1315
|
+
def.pattern ?? (def.pattern = ksuid);
|
|
1316
|
+
$ZodStringFormat.init(inst, def);
|
|
1317
|
+
});
|
|
1318
|
+
const $ZodISODateTime = /* @__PURE__ */ $constructor("$ZodISODateTime", (inst, def) => {
|
|
1319
|
+
def.pattern ?? (def.pattern = datetime$1(def));
|
|
1320
|
+
$ZodStringFormat.init(inst, def);
|
|
1321
|
+
});
|
|
1322
|
+
const $ZodISODate = /* @__PURE__ */ $constructor("$ZodISODate", (inst, def) => {
|
|
1323
|
+
def.pattern ?? (def.pattern = date$1);
|
|
1324
|
+
$ZodStringFormat.init(inst, def);
|
|
1325
|
+
});
|
|
1326
|
+
const $ZodISOTime = /* @__PURE__ */ $constructor("$ZodISOTime", (inst, def) => {
|
|
1327
|
+
def.pattern ?? (def.pattern = time$1(def));
|
|
1328
|
+
$ZodStringFormat.init(inst, def);
|
|
1329
|
+
});
|
|
1330
|
+
const $ZodISODuration = /* @__PURE__ */ $constructor("$ZodISODuration", (inst, def) => {
|
|
1331
|
+
def.pattern ?? (def.pattern = duration$1);
|
|
1332
|
+
$ZodStringFormat.init(inst, def);
|
|
1333
|
+
});
|
|
1334
|
+
const $ZodIPv4 = /* @__PURE__ */ $constructor("$ZodIPv4", (inst, def) => {
|
|
1335
|
+
def.pattern ?? (def.pattern = ipv4);
|
|
1336
|
+
$ZodStringFormat.init(inst, def);
|
|
1337
|
+
inst._zod.bag.format = `ipv4`;
|
|
1338
|
+
});
|
|
1339
|
+
const $ZodIPv6 = /* @__PURE__ */ $constructor("$ZodIPv6", (inst, def) => {
|
|
1340
|
+
def.pattern ?? (def.pattern = ipv6);
|
|
1341
|
+
$ZodStringFormat.init(inst, def);
|
|
1342
|
+
inst._zod.bag.format = `ipv6`;
|
|
1343
|
+
inst._zod.check = (payload) => {
|
|
1344
|
+
try {
|
|
1345
|
+
new URL(`http://[${payload.value}]`);
|
|
1346
|
+
} catch {
|
|
1347
|
+
payload.issues.push({
|
|
1348
|
+
code: "invalid_format",
|
|
1349
|
+
format: "ipv6",
|
|
1350
|
+
input: payload.value,
|
|
1351
|
+
inst,
|
|
1352
|
+
continue: !def.abort
|
|
1353
|
+
});
|
|
1354
|
+
}
|
|
1355
|
+
};
|
|
1356
|
+
});
|
|
1357
|
+
const $ZodCIDRv4 = /* @__PURE__ */ $constructor("$ZodCIDRv4", (inst, def) => {
|
|
1358
|
+
def.pattern ?? (def.pattern = cidrv4);
|
|
1359
|
+
$ZodStringFormat.init(inst, def);
|
|
1360
|
+
});
|
|
1361
|
+
const $ZodCIDRv6 = /* @__PURE__ */ $constructor("$ZodCIDRv6", (inst, def) => {
|
|
1362
|
+
def.pattern ?? (def.pattern = cidrv6);
|
|
1363
|
+
$ZodStringFormat.init(inst, def);
|
|
1364
|
+
inst._zod.check = (payload) => {
|
|
1365
|
+
const parts = payload.value.split("/");
|
|
1366
|
+
try {
|
|
1367
|
+
if (parts.length !== 2)
|
|
1368
|
+
throw new Error();
|
|
1369
|
+
const [address, prefix] = parts;
|
|
1370
|
+
if (!prefix)
|
|
1371
|
+
throw new Error();
|
|
1372
|
+
const prefixNum = Number(prefix);
|
|
1373
|
+
if (`${prefixNum}` !== prefix)
|
|
1374
|
+
throw new Error();
|
|
1375
|
+
if (prefixNum < 0 || prefixNum > 128)
|
|
1376
|
+
throw new Error();
|
|
1377
|
+
new URL(`http://[${address}]`);
|
|
1378
|
+
} catch {
|
|
1379
|
+
payload.issues.push({
|
|
1380
|
+
code: "invalid_format",
|
|
1381
|
+
format: "cidrv6",
|
|
1382
|
+
input: payload.value,
|
|
1383
|
+
inst,
|
|
1384
|
+
continue: !def.abort
|
|
1385
|
+
});
|
|
1386
|
+
}
|
|
1387
|
+
};
|
|
1388
|
+
});
|
|
1389
|
+
function isValidBase64(data) {
|
|
1390
|
+
if (data === "")
|
|
1391
|
+
return true;
|
|
1392
|
+
if (data.length % 4 !== 0)
|
|
1393
|
+
return false;
|
|
1394
|
+
try {
|
|
1395
|
+
atob(data);
|
|
1396
|
+
return true;
|
|
1397
|
+
} catch {
|
|
1398
|
+
return false;
|
|
1399
|
+
}
|
|
1400
|
+
}
|
|
1401
|
+
const $ZodBase64 = /* @__PURE__ */ $constructor("$ZodBase64", (inst, def) => {
|
|
1402
|
+
def.pattern ?? (def.pattern = base64);
|
|
1403
|
+
$ZodStringFormat.init(inst, def);
|
|
1404
|
+
inst._zod.bag.contentEncoding = "base64";
|
|
1405
|
+
inst._zod.check = (payload) => {
|
|
1406
|
+
if (isValidBase64(payload.value))
|
|
1407
|
+
return;
|
|
1408
|
+
payload.issues.push({
|
|
1409
|
+
code: "invalid_format",
|
|
1410
|
+
format: "base64",
|
|
1411
|
+
input: payload.value,
|
|
1412
|
+
inst,
|
|
1413
|
+
continue: !def.abort
|
|
1414
|
+
});
|
|
1415
|
+
};
|
|
1416
|
+
});
|
|
1417
|
+
function isValidBase64URL(data) {
|
|
1418
|
+
if (!base64url.test(data))
|
|
1419
|
+
return false;
|
|
1420
|
+
const base642 = data.replace(/[-_]/g, (c) => c === "-" ? "+" : "/");
|
|
1421
|
+
const padded = base642.padEnd(Math.ceil(base642.length / 4) * 4, "=");
|
|
1422
|
+
return isValidBase64(padded);
|
|
1423
|
+
}
|
|
1424
|
+
const $ZodBase64URL = /* @__PURE__ */ $constructor("$ZodBase64URL", (inst, def) => {
|
|
1425
|
+
def.pattern ?? (def.pattern = base64url);
|
|
1426
|
+
$ZodStringFormat.init(inst, def);
|
|
1427
|
+
inst._zod.bag.contentEncoding = "base64url";
|
|
1428
|
+
inst._zod.check = (payload) => {
|
|
1429
|
+
if (isValidBase64URL(payload.value))
|
|
1430
|
+
return;
|
|
1431
|
+
payload.issues.push({
|
|
1432
|
+
code: "invalid_format",
|
|
1433
|
+
format: "base64url",
|
|
1434
|
+
input: payload.value,
|
|
1435
|
+
inst,
|
|
1436
|
+
continue: !def.abort
|
|
1437
|
+
});
|
|
1438
|
+
};
|
|
1439
|
+
});
|
|
1440
|
+
const $ZodE164 = /* @__PURE__ */ $constructor("$ZodE164", (inst, def) => {
|
|
1441
|
+
def.pattern ?? (def.pattern = e164);
|
|
1442
|
+
$ZodStringFormat.init(inst, def);
|
|
1443
|
+
});
|
|
1444
|
+
function isValidJWT(token, algorithm = null) {
|
|
1445
|
+
try {
|
|
1446
|
+
const tokensParts = token.split(".");
|
|
1447
|
+
if (tokensParts.length !== 3)
|
|
1448
|
+
return false;
|
|
1449
|
+
const [header] = tokensParts;
|
|
1450
|
+
if (!header)
|
|
1451
|
+
return false;
|
|
1452
|
+
const parsedHeader = JSON.parse(atob(header));
|
|
1453
|
+
if ("typ" in parsedHeader && parsedHeader?.typ !== "JWT")
|
|
1454
|
+
return false;
|
|
1455
|
+
if (!parsedHeader.alg)
|
|
1456
|
+
return false;
|
|
1457
|
+
if (algorithm && (!("alg" in parsedHeader) || parsedHeader.alg !== algorithm))
|
|
1458
|
+
return false;
|
|
1459
|
+
return true;
|
|
1460
|
+
} catch {
|
|
1461
|
+
return false;
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
const $ZodJWT = /* @__PURE__ */ $constructor("$ZodJWT", (inst, def) => {
|
|
1465
|
+
$ZodStringFormat.init(inst, def);
|
|
1466
|
+
inst._zod.check = (payload) => {
|
|
1467
|
+
if (isValidJWT(payload.value, def.alg))
|
|
1468
|
+
return;
|
|
1469
|
+
payload.issues.push({
|
|
1470
|
+
code: "invalid_format",
|
|
1471
|
+
format: "jwt",
|
|
1472
|
+
input: payload.value,
|
|
1473
|
+
inst,
|
|
1474
|
+
continue: !def.abort
|
|
1475
|
+
});
|
|
1476
|
+
};
|
|
1477
|
+
});
|
|
1478
|
+
const $ZodNumber = /* @__PURE__ */ $constructor("$ZodNumber", (inst, def) => {
|
|
1479
|
+
$ZodType.init(inst, def);
|
|
1480
|
+
inst._zod.pattern = inst._zod.bag.pattern ?? number$1;
|
|
1481
|
+
inst._zod.parse = (payload, _ctx) => {
|
|
1482
|
+
if (def.coerce)
|
|
1483
|
+
try {
|
|
1484
|
+
payload.value = Number(payload.value);
|
|
1485
|
+
} catch (_) {
|
|
1486
|
+
}
|
|
1487
|
+
const input = payload.value;
|
|
1488
|
+
if (typeof input === "number" && !Number.isNaN(input) && Number.isFinite(input)) {
|
|
1489
|
+
return payload;
|
|
1490
|
+
}
|
|
1491
|
+
const received = typeof input === "number" ? Number.isNaN(input) ? "NaN" : !Number.isFinite(input) ? "Infinity" : void 0 : void 0;
|
|
1492
|
+
payload.issues.push({
|
|
1493
|
+
expected: "number",
|
|
1494
|
+
code: "invalid_type",
|
|
1495
|
+
input,
|
|
1496
|
+
inst,
|
|
1497
|
+
...received ? { received } : {}
|
|
1498
|
+
});
|
|
1499
|
+
return payload;
|
|
1500
|
+
};
|
|
1501
|
+
});
|
|
1502
|
+
const $ZodNumberFormat = /* @__PURE__ */ $constructor("$ZodNumberFormat", (inst, def) => {
|
|
1503
|
+
$ZodCheckNumberFormat.init(inst, def);
|
|
1504
|
+
$ZodNumber.init(inst, def);
|
|
1505
|
+
});
|
|
1506
|
+
const $ZodBoolean = /* @__PURE__ */ $constructor("$ZodBoolean", (inst, def) => {
|
|
1507
|
+
$ZodType.init(inst, def);
|
|
1508
|
+
inst._zod.pattern = boolean$1;
|
|
1509
|
+
inst._zod.parse = (payload, _ctx) => {
|
|
1510
|
+
if (def.coerce)
|
|
1511
|
+
try {
|
|
1512
|
+
payload.value = Boolean(payload.value);
|
|
1513
|
+
} catch (_) {
|
|
1514
|
+
}
|
|
1515
|
+
const input = payload.value;
|
|
1516
|
+
if (typeof input === "boolean")
|
|
1517
|
+
return payload;
|
|
1518
|
+
payload.issues.push({
|
|
1519
|
+
expected: "boolean",
|
|
1520
|
+
code: "invalid_type",
|
|
1521
|
+
input,
|
|
1522
|
+
inst
|
|
1523
|
+
});
|
|
1524
|
+
return payload;
|
|
1525
|
+
};
|
|
1526
|
+
});
|
|
1527
|
+
const $ZodUnknown = /* @__PURE__ */ $constructor("$ZodUnknown", (inst, def) => {
|
|
1528
|
+
$ZodType.init(inst, def);
|
|
1529
|
+
inst._zod.parse = (payload) => payload;
|
|
1530
|
+
});
|
|
1531
|
+
const $ZodNever = /* @__PURE__ */ $constructor("$ZodNever", (inst, def) => {
|
|
1532
|
+
$ZodType.init(inst, def);
|
|
1533
|
+
inst._zod.parse = (payload, _ctx) => {
|
|
1534
|
+
payload.issues.push({
|
|
1535
|
+
expected: "never",
|
|
1536
|
+
code: "invalid_type",
|
|
1537
|
+
input: payload.value,
|
|
1538
|
+
inst
|
|
1539
|
+
});
|
|
1540
|
+
return payload;
|
|
1541
|
+
};
|
|
1542
|
+
});
|
|
1543
|
+
function handleArrayResult(result, final, index) {
|
|
1544
|
+
if (result.issues.length) {
|
|
1545
|
+
final.issues.push(...prefixIssues(index, result.issues));
|
|
1546
|
+
}
|
|
1547
|
+
final.value[index] = result.value;
|
|
1548
|
+
}
|
|
1549
|
+
const $ZodArray = /* @__PURE__ */ $constructor("$ZodArray", (inst, def) => {
|
|
1550
|
+
$ZodType.init(inst, def);
|
|
1551
|
+
inst._zod.parse = (payload, ctx) => {
|
|
1552
|
+
const input = payload.value;
|
|
1553
|
+
if (!Array.isArray(input)) {
|
|
1554
|
+
payload.issues.push({
|
|
1555
|
+
expected: "array",
|
|
1556
|
+
code: "invalid_type",
|
|
1557
|
+
input,
|
|
1558
|
+
inst
|
|
1559
|
+
});
|
|
1560
|
+
return payload;
|
|
1561
|
+
}
|
|
1562
|
+
payload.value = Array(input.length);
|
|
1563
|
+
const proms = [];
|
|
1564
|
+
for (let i = 0; i < input.length; i++) {
|
|
1565
|
+
const item = input[i];
|
|
1566
|
+
const result = def.element._zod.run({
|
|
1567
|
+
value: item,
|
|
1568
|
+
issues: []
|
|
1569
|
+
}, ctx);
|
|
1570
|
+
if (result instanceof Promise) {
|
|
1571
|
+
proms.push(result.then((result2) => handleArrayResult(result2, payload, i)));
|
|
1572
|
+
} else {
|
|
1573
|
+
handleArrayResult(result, payload, i);
|
|
1574
|
+
}
|
|
1575
|
+
}
|
|
1576
|
+
if (proms.length) {
|
|
1577
|
+
return Promise.all(proms).then(() => payload);
|
|
1578
|
+
}
|
|
1579
|
+
return payload;
|
|
1580
|
+
};
|
|
1581
|
+
});
|
|
1582
|
+
function handlePropertyResult(result, final, key, input, isOptionalOut) {
|
|
1583
|
+
if (result.issues.length) {
|
|
1584
|
+
if (isOptionalOut && !(key in input)) {
|
|
1585
|
+
return;
|
|
1586
|
+
}
|
|
1587
|
+
final.issues.push(...prefixIssues(key, result.issues));
|
|
1588
|
+
}
|
|
1589
|
+
if (result.value === void 0) {
|
|
1590
|
+
if (key in input) {
|
|
1591
|
+
final.value[key] = void 0;
|
|
1592
|
+
}
|
|
1593
|
+
} else {
|
|
1594
|
+
final.value[key] = result.value;
|
|
1595
|
+
}
|
|
1596
|
+
}
|
|
1597
|
+
function normalizeDef(def) {
|
|
1598
|
+
const keys = Object.keys(def.shape);
|
|
1599
|
+
for (const k of keys) {
|
|
1600
|
+
if (!def.shape?.[k]?._zod?.traits?.has("$ZodType")) {
|
|
1601
|
+
throw new Error(`Invalid element at key "${k}": expected a Zod schema`);
|
|
1602
|
+
}
|
|
1603
|
+
}
|
|
1604
|
+
const okeys = optionalKeys(def.shape);
|
|
1605
|
+
return {
|
|
1606
|
+
...def,
|
|
1607
|
+
keys,
|
|
1608
|
+
keySet: new Set(keys),
|
|
1609
|
+
numKeys: keys.length,
|
|
1610
|
+
optionalKeys: new Set(okeys)
|
|
1611
|
+
};
|
|
1612
|
+
}
|
|
1613
|
+
function handleCatchall(proms, input, payload, ctx, def, inst) {
|
|
1614
|
+
const unrecognized = [];
|
|
1615
|
+
const keySet = def.keySet;
|
|
1616
|
+
const _catchall = def.catchall._zod;
|
|
1617
|
+
const t = _catchall.def.type;
|
|
1618
|
+
const isOptionalOut = _catchall.optout === "optional";
|
|
1619
|
+
for (const key in input) {
|
|
1620
|
+
if (keySet.has(key))
|
|
1621
|
+
continue;
|
|
1622
|
+
if (t === "never") {
|
|
1623
|
+
unrecognized.push(key);
|
|
1624
|
+
continue;
|
|
1625
|
+
}
|
|
1626
|
+
const r = _catchall.run({ value: input[key], issues: [] }, ctx);
|
|
1627
|
+
if (r instanceof Promise) {
|
|
1628
|
+
proms.push(r.then((r2) => handlePropertyResult(r2, payload, key, input, isOptionalOut)));
|
|
1629
|
+
} else {
|
|
1630
|
+
handlePropertyResult(r, payload, key, input, isOptionalOut);
|
|
1631
|
+
}
|
|
1632
|
+
}
|
|
1633
|
+
if (unrecognized.length) {
|
|
1634
|
+
payload.issues.push({
|
|
1635
|
+
code: "unrecognized_keys",
|
|
1636
|
+
keys: unrecognized,
|
|
1637
|
+
input,
|
|
1638
|
+
inst
|
|
1639
|
+
});
|
|
1640
|
+
}
|
|
1641
|
+
if (!proms.length)
|
|
1642
|
+
return payload;
|
|
1643
|
+
return Promise.all(proms).then(() => {
|
|
1644
|
+
return payload;
|
|
1645
|
+
});
|
|
1646
|
+
}
|
|
1647
|
+
const $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
|
|
1648
|
+
$ZodType.init(inst, def);
|
|
1649
|
+
const desc = Object.getOwnPropertyDescriptor(def, "shape");
|
|
1650
|
+
if (!desc?.get) {
|
|
1651
|
+
const sh = def.shape;
|
|
1652
|
+
Object.defineProperty(def, "shape", {
|
|
1653
|
+
get: () => {
|
|
1654
|
+
const newSh = { ...sh };
|
|
1655
|
+
Object.defineProperty(def, "shape", {
|
|
1656
|
+
value: newSh
|
|
1657
|
+
});
|
|
1658
|
+
return newSh;
|
|
1659
|
+
}
|
|
1660
|
+
});
|
|
1661
|
+
}
|
|
1662
|
+
const _normalized = cached(() => normalizeDef(def));
|
|
1663
|
+
defineLazy(inst._zod, "propValues", () => {
|
|
1664
|
+
const shape = def.shape;
|
|
1665
|
+
const propValues = {};
|
|
1666
|
+
for (const key in shape) {
|
|
1667
|
+
const field = shape[key]._zod;
|
|
1668
|
+
if (field.values) {
|
|
1669
|
+
propValues[key] ?? (propValues[key] = /* @__PURE__ */ new Set());
|
|
1670
|
+
for (const v of field.values)
|
|
1671
|
+
propValues[key].add(v);
|
|
1672
|
+
}
|
|
1673
|
+
}
|
|
1674
|
+
return propValues;
|
|
1675
|
+
});
|
|
1676
|
+
const isObject$1 = isObject;
|
|
1677
|
+
const catchall = def.catchall;
|
|
1678
|
+
let value;
|
|
1679
|
+
inst._zod.parse = (payload, ctx) => {
|
|
1680
|
+
value ?? (value = _normalized.value);
|
|
1681
|
+
const input = payload.value;
|
|
1682
|
+
if (!isObject$1(input)) {
|
|
1683
|
+
payload.issues.push({
|
|
1684
|
+
expected: "object",
|
|
1685
|
+
code: "invalid_type",
|
|
1686
|
+
input,
|
|
1687
|
+
inst
|
|
1688
|
+
});
|
|
1689
|
+
return payload;
|
|
1690
|
+
}
|
|
1691
|
+
payload.value = {};
|
|
1692
|
+
const proms = [];
|
|
1693
|
+
const shape = value.shape;
|
|
1694
|
+
for (const key of value.keys) {
|
|
1695
|
+
const el = shape[key];
|
|
1696
|
+
const isOptionalOut = el._zod.optout === "optional";
|
|
1697
|
+
const r = el._zod.run({ value: input[key], issues: [] }, ctx);
|
|
1698
|
+
if (r instanceof Promise) {
|
|
1699
|
+
proms.push(r.then((r2) => handlePropertyResult(r2, payload, key, input, isOptionalOut)));
|
|
1700
|
+
} else {
|
|
1701
|
+
handlePropertyResult(r, payload, key, input, isOptionalOut);
|
|
1702
|
+
}
|
|
1703
|
+
}
|
|
1704
|
+
if (!catchall) {
|
|
1705
|
+
return proms.length ? Promise.all(proms).then(() => payload) : payload;
|
|
1706
|
+
}
|
|
1707
|
+
return handleCatchall(proms, input, payload, ctx, _normalized.value, inst);
|
|
1708
|
+
};
|
|
1709
|
+
});
|
|
1710
|
+
const $ZodObjectJIT = /* @__PURE__ */ $constructor("$ZodObjectJIT", (inst, def) => {
|
|
1711
|
+
$ZodObject.init(inst, def);
|
|
1712
|
+
const superParse = inst._zod.parse;
|
|
1713
|
+
const _normalized = cached(() => normalizeDef(def));
|
|
1714
|
+
const generateFastpass = (shape) => {
|
|
1715
|
+
const doc = new Doc(["shape", "payload", "ctx"]);
|
|
1716
|
+
const normalized = _normalized.value;
|
|
1717
|
+
const parseStr = (key) => {
|
|
1718
|
+
const k = esc(key);
|
|
1719
|
+
return `shape[${k}]._zod.run({ value: input[${k}], issues: [] }, ctx)`;
|
|
1720
|
+
};
|
|
1721
|
+
doc.write(`const input = payload.value;`);
|
|
1722
|
+
const ids = /* @__PURE__ */ Object.create(null);
|
|
1723
|
+
let counter = 0;
|
|
1724
|
+
for (const key of normalized.keys) {
|
|
1725
|
+
ids[key] = `key_${counter++}`;
|
|
1726
|
+
}
|
|
1727
|
+
doc.write(`const newResult = {};`);
|
|
1728
|
+
for (const key of normalized.keys) {
|
|
1729
|
+
const id = ids[key];
|
|
1730
|
+
const k = esc(key);
|
|
1731
|
+
const schema = shape[key];
|
|
1732
|
+
const isOptionalOut = schema?._zod?.optout === "optional";
|
|
1733
|
+
doc.write(`const ${id} = ${parseStr(key)};`);
|
|
1734
|
+
if (isOptionalOut) {
|
|
1735
|
+
doc.write(`
|
|
1736
|
+
if (${id}.issues.length) {
|
|
1737
|
+
if (${k} in input) {
|
|
1738
|
+
payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
|
|
1739
|
+
...iss,
|
|
1740
|
+
path: iss.path ? [${k}, ...iss.path] : [${k}]
|
|
1741
|
+
})));
|
|
1742
|
+
}
|
|
1743
|
+
}
|
|
1744
|
+
|
|
1745
|
+
if (${id}.value === undefined) {
|
|
1746
|
+
if (${k} in input) {
|
|
1747
|
+
newResult[${k}] = undefined;
|
|
1748
|
+
}
|
|
1749
|
+
} else {
|
|
1750
|
+
newResult[${k}] = ${id}.value;
|
|
1751
|
+
}
|
|
1752
|
+
|
|
1753
|
+
`);
|
|
1754
|
+
} else {
|
|
1755
|
+
doc.write(`
|
|
1756
|
+
if (${id}.issues.length) {
|
|
1757
|
+
payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
|
|
1758
|
+
...iss,
|
|
1759
|
+
path: iss.path ? [${k}, ...iss.path] : [${k}]
|
|
1760
|
+
})));
|
|
1761
|
+
}
|
|
1762
|
+
|
|
1763
|
+
if (${id}.value === undefined) {
|
|
1764
|
+
if (${k} in input) {
|
|
1765
|
+
newResult[${k}] = undefined;
|
|
1766
|
+
}
|
|
1767
|
+
} else {
|
|
1768
|
+
newResult[${k}] = ${id}.value;
|
|
1769
|
+
}
|
|
1770
|
+
|
|
1771
|
+
`);
|
|
1772
|
+
}
|
|
1773
|
+
}
|
|
1774
|
+
doc.write(`payload.value = newResult;`);
|
|
1775
|
+
doc.write(`return payload;`);
|
|
1776
|
+
const fn = doc.compile();
|
|
1777
|
+
return (payload, ctx) => fn(shape, payload, ctx);
|
|
1778
|
+
};
|
|
1779
|
+
let fastpass;
|
|
1780
|
+
const isObject$1 = isObject;
|
|
1781
|
+
const jit = !globalConfig.jitless;
|
|
1782
|
+
const allowsEval$1 = allowsEval;
|
|
1783
|
+
const fastEnabled = jit && allowsEval$1.value;
|
|
1784
|
+
const catchall = def.catchall;
|
|
1785
|
+
let value;
|
|
1786
|
+
inst._zod.parse = (payload, ctx) => {
|
|
1787
|
+
value ?? (value = _normalized.value);
|
|
1788
|
+
const input = payload.value;
|
|
1789
|
+
if (!isObject$1(input)) {
|
|
1790
|
+
payload.issues.push({
|
|
1791
|
+
expected: "object",
|
|
1792
|
+
code: "invalid_type",
|
|
1793
|
+
input,
|
|
1794
|
+
inst
|
|
1795
|
+
});
|
|
1796
|
+
return payload;
|
|
1797
|
+
}
|
|
1798
|
+
if (jit && fastEnabled && ctx?.async === false && ctx.jitless !== true) {
|
|
1799
|
+
if (!fastpass)
|
|
1800
|
+
fastpass = generateFastpass(def.shape);
|
|
1801
|
+
payload = fastpass(payload, ctx);
|
|
1802
|
+
if (!catchall)
|
|
1803
|
+
return payload;
|
|
1804
|
+
return handleCatchall([], input, payload, ctx, value, inst);
|
|
1805
|
+
}
|
|
1806
|
+
return superParse(payload, ctx);
|
|
1807
|
+
};
|
|
1808
|
+
});
|
|
1809
|
+
function handleUnionResults(results, final, inst, ctx) {
|
|
1810
|
+
for (const result of results) {
|
|
1811
|
+
if (result.issues.length === 0) {
|
|
1812
|
+
final.value = result.value;
|
|
1813
|
+
return final;
|
|
1814
|
+
}
|
|
1815
|
+
}
|
|
1816
|
+
const nonaborted = results.filter((r) => !aborted(r));
|
|
1817
|
+
if (nonaborted.length === 1) {
|
|
1818
|
+
final.value = nonaborted[0].value;
|
|
1819
|
+
return nonaborted[0];
|
|
1820
|
+
}
|
|
1821
|
+
final.issues.push({
|
|
1822
|
+
code: "invalid_union",
|
|
1823
|
+
input: final.value,
|
|
1824
|
+
inst,
|
|
1825
|
+
errors: results.map((result) => result.issues.map((iss) => finalizeIssue(iss, ctx, config())))
|
|
1826
|
+
});
|
|
1827
|
+
return final;
|
|
1828
|
+
}
|
|
1829
|
+
const $ZodUnion = /* @__PURE__ */ $constructor("$ZodUnion", (inst, def) => {
|
|
1830
|
+
$ZodType.init(inst, def);
|
|
1831
|
+
defineLazy(inst._zod, "optin", () => def.options.some((o) => o._zod.optin === "optional") ? "optional" : void 0);
|
|
1832
|
+
defineLazy(inst._zod, "optout", () => def.options.some((o) => o._zod.optout === "optional") ? "optional" : void 0);
|
|
1833
|
+
defineLazy(inst._zod, "values", () => {
|
|
1834
|
+
if (def.options.every((o) => o._zod.values)) {
|
|
1835
|
+
return new Set(def.options.flatMap((option) => Array.from(option._zod.values)));
|
|
1836
|
+
}
|
|
1837
|
+
return void 0;
|
|
1838
|
+
});
|
|
1839
|
+
defineLazy(inst._zod, "pattern", () => {
|
|
1840
|
+
if (def.options.every((o) => o._zod.pattern)) {
|
|
1841
|
+
const patterns = def.options.map((o) => o._zod.pattern);
|
|
1842
|
+
return new RegExp(`^(${patterns.map((p) => cleanRegex(p.source)).join("|")})$`);
|
|
1843
|
+
}
|
|
1844
|
+
return void 0;
|
|
1845
|
+
});
|
|
1846
|
+
const single = def.options.length === 1;
|
|
1847
|
+
const first = def.options[0]._zod.run;
|
|
1848
|
+
inst._zod.parse = (payload, ctx) => {
|
|
1849
|
+
if (single) {
|
|
1850
|
+
return first(payload, ctx);
|
|
1851
|
+
}
|
|
1852
|
+
let async = false;
|
|
1853
|
+
const results = [];
|
|
1854
|
+
for (const option of def.options) {
|
|
1855
|
+
const result = option._zod.run({
|
|
1856
|
+
value: payload.value,
|
|
1857
|
+
issues: []
|
|
1858
|
+
}, ctx);
|
|
1859
|
+
if (result instanceof Promise) {
|
|
1860
|
+
results.push(result);
|
|
1861
|
+
async = true;
|
|
1862
|
+
} else {
|
|
1863
|
+
if (result.issues.length === 0)
|
|
1864
|
+
return result;
|
|
1865
|
+
results.push(result);
|
|
1866
|
+
}
|
|
1867
|
+
}
|
|
1868
|
+
if (!async)
|
|
1869
|
+
return handleUnionResults(results, payload, inst, ctx);
|
|
1870
|
+
return Promise.all(results).then((results2) => {
|
|
1871
|
+
return handleUnionResults(results2, payload, inst, ctx);
|
|
1872
|
+
});
|
|
1873
|
+
};
|
|
1874
|
+
});
|
|
1875
|
+
const $ZodIntersection = /* @__PURE__ */ $constructor("$ZodIntersection", (inst, def) => {
|
|
1876
|
+
$ZodType.init(inst, def);
|
|
1877
|
+
inst._zod.parse = (payload, ctx) => {
|
|
1878
|
+
const input = payload.value;
|
|
1879
|
+
const left = def.left._zod.run({ value: input, issues: [] }, ctx);
|
|
1880
|
+
const right = def.right._zod.run({ value: input, issues: [] }, ctx);
|
|
1881
|
+
const async = left instanceof Promise || right instanceof Promise;
|
|
1882
|
+
if (async) {
|
|
1883
|
+
return Promise.all([left, right]).then(([left2, right2]) => {
|
|
1884
|
+
return handleIntersectionResults(payload, left2, right2);
|
|
1885
|
+
});
|
|
1886
|
+
}
|
|
1887
|
+
return handleIntersectionResults(payload, left, right);
|
|
1888
|
+
};
|
|
1889
|
+
});
|
|
1890
|
+
function mergeValues(a, b) {
|
|
1891
|
+
if (a === b) {
|
|
1892
|
+
return { valid: true, data: a };
|
|
1893
|
+
}
|
|
1894
|
+
if (a instanceof Date && b instanceof Date && +a === +b) {
|
|
1895
|
+
return { valid: true, data: a };
|
|
1896
|
+
}
|
|
1897
|
+
if (isPlainObject(a) && isPlainObject(b)) {
|
|
1898
|
+
const bKeys = Object.keys(b);
|
|
1899
|
+
const sharedKeys = Object.keys(a).filter((key) => bKeys.indexOf(key) !== -1);
|
|
1900
|
+
const newObj = { ...a, ...b };
|
|
1901
|
+
for (const key of sharedKeys) {
|
|
1902
|
+
const sharedValue = mergeValues(a[key], b[key]);
|
|
1903
|
+
if (!sharedValue.valid) {
|
|
1904
|
+
return {
|
|
1905
|
+
valid: false,
|
|
1906
|
+
mergeErrorPath: [key, ...sharedValue.mergeErrorPath]
|
|
1907
|
+
};
|
|
1908
|
+
}
|
|
1909
|
+
newObj[key] = sharedValue.data;
|
|
1910
|
+
}
|
|
1911
|
+
return { valid: true, data: newObj };
|
|
1912
|
+
}
|
|
1913
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
1914
|
+
if (a.length !== b.length) {
|
|
1915
|
+
return { valid: false, mergeErrorPath: [] };
|
|
1916
|
+
}
|
|
1917
|
+
const newArray = [];
|
|
1918
|
+
for (let index = 0; index < a.length; index++) {
|
|
1919
|
+
const itemA = a[index];
|
|
1920
|
+
const itemB = b[index];
|
|
1921
|
+
const sharedValue = mergeValues(itemA, itemB);
|
|
1922
|
+
if (!sharedValue.valid) {
|
|
1923
|
+
return {
|
|
1924
|
+
valid: false,
|
|
1925
|
+
mergeErrorPath: [index, ...sharedValue.mergeErrorPath]
|
|
1926
|
+
};
|
|
1927
|
+
}
|
|
1928
|
+
newArray.push(sharedValue.data);
|
|
1929
|
+
}
|
|
1930
|
+
return { valid: true, data: newArray };
|
|
1931
|
+
}
|
|
1932
|
+
return { valid: false, mergeErrorPath: [] };
|
|
1933
|
+
}
|
|
1934
|
+
function handleIntersectionResults(result, left, right) {
|
|
1935
|
+
const unrecKeys = /* @__PURE__ */ new Map();
|
|
1936
|
+
let unrecIssue;
|
|
1937
|
+
for (const iss of left.issues) {
|
|
1938
|
+
if (iss.code === "unrecognized_keys") {
|
|
1939
|
+
unrecIssue ?? (unrecIssue = iss);
|
|
1940
|
+
for (const k of iss.keys) {
|
|
1941
|
+
if (!unrecKeys.has(k))
|
|
1942
|
+
unrecKeys.set(k, {});
|
|
1943
|
+
unrecKeys.get(k).l = true;
|
|
1944
|
+
}
|
|
1945
|
+
} else {
|
|
1946
|
+
result.issues.push(iss);
|
|
1947
|
+
}
|
|
1948
|
+
}
|
|
1949
|
+
for (const iss of right.issues) {
|
|
1950
|
+
if (iss.code === "unrecognized_keys") {
|
|
1951
|
+
for (const k of iss.keys) {
|
|
1952
|
+
if (!unrecKeys.has(k))
|
|
1953
|
+
unrecKeys.set(k, {});
|
|
1954
|
+
unrecKeys.get(k).r = true;
|
|
1955
|
+
}
|
|
1956
|
+
} else {
|
|
1957
|
+
result.issues.push(iss);
|
|
1958
|
+
}
|
|
1959
|
+
}
|
|
1960
|
+
const bothKeys = [...unrecKeys].filter(([, f]) => f.l && f.r).map(([k]) => k);
|
|
1961
|
+
if (bothKeys.length && unrecIssue) {
|
|
1962
|
+
result.issues.push({ ...unrecIssue, keys: bothKeys });
|
|
1963
|
+
}
|
|
1964
|
+
if (aborted(result))
|
|
1965
|
+
return result;
|
|
1966
|
+
const merged = mergeValues(left.value, right.value);
|
|
1967
|
+
if (!merged.valid) {
|
|
1968
|
+
throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(merged.mergeErrorPath)}`);
|
|
1969
|
+
}
|
|
1970
|
+
result.value = merged.data;
|
|
1971
|
+
return result;
|
|
1972
|
+
}
|
|
1973
|
+
const $ZodRecord = /* @__PURE__ */ $constructor("$ZodRecord", (inst, def) => {
|
|
1974
|
+
$ZodType.init(inst, def);
|
|
1975
|
+
inst._zod.parse = (payload, ctx) => {
|
|
1976
|
+
const input = payload.value;
|
|
1977
|
+
if (!isPlainObject(input)) {
|
|
1978
|
+
payload.issues.push({
|
|
1979
|
+
expected: "record",
|
|
1980
|
+
code: "invalid_type",
|
|
1981
|
+
input,
|
|
1982
|
+
inst
|
|
1983
|
+
});
|
|
1984
|
+
return payload;
|
|
1985
|
+
}
|
|
1986
|
+
const proms = [];
|
|
1987
|
+
const values = def.keyType._zod.values;
|
|
1988
|
+
if (values) {
|
|
1989
|
+
payload.value = {};
|
|
1990
|
+
const recordKeys = /* @__PURE__ */ new Set();
|
|
1991
|
+
for (const key of values) {
|
|
1992
|
+
if (typeof key === "string" || typeof key === "number" || typeof key === "symbol") {
|
|
1993
|
+
recordKeys.add(typeof key === "number" ? key.toString() : key);
|
|
1994
|
+
const result = def.valueType._zod.run({ value: input[key], issues: [] }, ctx);
|
|
1995
|
+
if (result instanceof Promise) {
|
|
1996
|
+
proms.push(result.then((result2) => {
|
|
1997
|
+
if (result2.issues.length) {
|
|
1998
|
+
payload.issues.push(...prefixIssues(key, result2.issues));
|
|
1999
|
+
}
|
|
2000
|
+
payload.value[key] = result2.value;
|
|
2001
|
+
}));
|
|
2002
|
+
} else {
|
|
2003
|
+
if (result.issues.length) {
|
|
2004
|
+
payload.issues.push(...prefixIssues(key, result.issues));
|
|
2005
|
+
}
|
|
2006
|
+
payload.value[key] = result.value;
|
|
2007
|
+
}
|
|
2008
|
+
}
|
|
2009
|
+
}
|
|
2010
|
+
let unrecognized;
|
|
2011
|
+
for (const key in input) {
|
|
2012
|
+
if (!recordKeys.has(key)) {
|
|
2013
|
+
unrecognized = unrecognized ?? [];
|
|
2014
|
+
unrecognized.push(key);
|
|
2015
|
+
}
|
|
2016
|
+
}
|
|
2017
|
+
if (unrecognized && unrecognized.length > 0) {
|
|
2018
|
+
payload.issues.push({
|
|
2019
|
+
code: "unrecognized_keys",
|
|
2020
|
+
input,
|
|
2021
|
+
inst,
|
|
2022
|
+
keys: unrecognized
|
|
2023
|
+
});
|
|
2024
|
+
}
|
|
2025
|
+
} else {
|
|
2026
|
+
payload.value = {};
|
|
2027
|
+
for (const key of Reflect.ownKeys(input)) {
|
|
2028
|
+
if (key === "__proto__")
|
|
2029
|
+
continue;
|
|
2030
|
+
let keyResult = def.keyType._zod.run({ value: key, issues: [] }, ctx);
|
|
2031
|
+
if (keyResult instanceof Promise) {
|
|
2032
|
+
throw new Error("Async schemas not supported in object keys currently");
|
|
2033
|
+
}
|
|
2034
|
+
const checkNumericKey = typeof key === "string" && number$1.test(key) && keyResult.issues.length;
|
|
2035
|
+
if (checkNumericKey) {
|
|
2036
|
+
const retryResult = def.keyType._zod.run({ value: Number(key), issues: [] }, ctx);
|
|
2037
|
+
if (retryResult instanceof Promise) {
|
|
2038
|
+
throw new Error("Async schemas not supported in object keys currently");
|
|
2039
|
+
}
|
|
2040
|
+
if (retryResult.issues.length === 0) {
|
|
2041
|
+
keyResult = retryResult;
|
|
2042
|
+
}
|
|
2043
|
+
}
|
|
2044
|
+
if (keyResult.issues.length) {
|
|
2045
|
+
if (def.mode === "loose") {
|
|
2046
|
+
payload.value[key] = input[key];
|
|
2047
|
+
} else {
|
|
2048
|
+
payload.issues.push({
|
|
2049
|
+
code: "invalid_key",
|
|
2050
|
+
origin: "record",
|
|
2051
|
+
issues: keyResult.issues.map((iss) => finalizeIssue(iss, ctx, config())),
|
|
2052
|
+
input: key,
|
|
2053
|
+
path: [key],
|
|
2054
|
+
inst
|
|
2055
|
+
});
|
|
2056
|
+
}
|
|
2057
|
+
continue;
|
|
2058
|
+
}
|
|
2059
|
+
const result = def.valueType._zod.run({ value: input[key], issues: [] }, ctx);
|
|
2060
|
+
if (result instanceof Promise) {
|
|
2061
|
+
proms.push(result.then((result2) => {
|
|
2062
|
+
if (result2.issues.length) {
|
|
2063
|
+
payload.issues.push(...prefixIssues(key, result2.issues));
|
|
2064
|
+
}
|
|
2065
|
+
payload.value[keyResult.value] = result2.value;
|
|
2066
|
+
}));
|
|
2067
|
+
} else {
|
|
2068
|
+
if (result.issues.length) {
|
|
2069
|
+
payload.issues.push(...prefixIssues(key, result.issues));
|
|
2070
|
+
}
|
|
2071
|
+
payload.value[keyResult.value] = result.value;
|
|
2072
|
+
}
|
|
2073
|
+
}
|
|
2074
|
+
}
|
|
2075
|
+
if (proms.length) {
|
|
2076
|
+
return Promise.all(proms).then(() => payload);
|
|
2077
|
+
}
|
|
2078
|
+
return payload;
|
|
2079
|
+
};
|
|
2080
|
+
});
|
|
2081
|
+
const $ZodEnum = /* @__PURE__ */ $constructor("$ZodEnum", (inst, def) => {
|
|
2082
|
+
$ZodType.init(inst, def);
|
|
2083
|
+
const values = getEnumValues(def.entries);
|
|
2084
|
+
const valuesSet = new Set(values);
|
|
2085
|
+
inst._zod.values = valuesSet;
|
|
2086
|
+
inst._zod.pattern = new RegExp(`^(${values.filter((k) => propertyKeyTypes.has(typeof k)).map((o) => typeof o === "string" ? escapeRegex(o) : o.toString()).join("|")})$`);
|
|
2087
|
+
inst._zod.parse = (payload, _ctx) => {
|
|
2088
|
+
const input = payload.value;
|
|
2089
|
+
if (valuesSet.has(input)) {
|
|
2090
|
+
return payload;
|
|
2091
|
+
}
|
|
2092
|
+
payload.issues.push({
|
|
2093
|
+
code: "invalid_value",
|
|
2094
|
+
values,
|
|
2095
|
+
input,
|
|
2096
|
+
inst
|
|
2097
|
+
});
|
|
2098
|
+
return payload;
|
|
2099
|
+
};
|
|
2100
|
+
});
|
|
2101
|
+
const $ZodTransform = /* @__PURE__ */ $constructor("$ZodTransform", (inst, def) => {
|
|
2102
|
+
$ZodType.init(inst, def);
|
|
2103
|
+
inst._zod.parse = (payload, ctx) => {
|
|
2104
|
+
if (ctx.direction === "backward") {
|
|
2105
|
+
throw new $ZodEncodeError(inst.constructor.name);
|
|
2106
|
+
}
|
|
2107
|
+
const _out = def.transform(payload.value, payload);
|
|
2108
|
+
if (ctx.async) {
|
|
2109
|
+
const output = _out instanceof Promise ? _out : Promise.resolve(_out);
|
|
2110
|
+
return output.then((output2) => {
|
|
2111
|
+
payload.value = output2;
|
|
2112
|
+
return payload;
|
|
2113
|
+
});
|
|
2114
|
+
}
|
|
2115
|
+
if (_out instanceof Promise) {
|
|
2116
|
+
throw new $ZodAsyncError();
|
|
2117
|
+
}
|
|
2118
|
+
payload.value = _out;
|
|
2119
|
+
return payload;
|
|
2120
|
+
};
|
|
2121
|
+
});
|
|
2122
|
+
function handleOptionalResult(result, input) {
|
|
2123
|
+
if (result.issues.length && input === void 0) {
|
|
2124
|
+
return { issues: [], value: void 0 };
|
|
2125
|
+
}
|
|
2126
|
+
return result;
|
|
2127
|
+
}
|
|
2128
|
+
const $ZodOptional = /* @__PURE__ */ $constructor("$ZodOptional", (inst, def) => {
|
|
2129
|
+
$ZodType.init(inst, def);
|
|
2130
|
+
inst._zod.optin = "optional";
|
|
2131
|
+
inst._zod.optout = "optional";
|
|
2132
|
+
defineLazy(inst._zod, "values", () => {
|
|
2133
|
+
return def.innerType._zod.values ? /* @__PURE__ */ new Set([...def.innerType._zod.values, void 0]) : void 0;
|
|
2134
|
+
});
|
|
2135
|
+
defineLazy(inst._zod, "pattern", () => {
|
|
2136
|
+
const pattern = def.innerType._zod.pattern;
|
|
2137
|
+
return pattern ? new RegExp(`^(${cleanRegex(pattern.source)})?$`) : void 0;
|
|
2138
|
+
});
|
|
2139
|
+
inst._zod.parse = (payload, ctx) => {
|
|
2140
|
+
if (def.innerType._zod.optin === "optional") {
|
|
2141
|
+
const result = def.innerType._zod.run(payload, ctx);
|
|
2142
|
+
if (result instanceof Promise)
|
|
2143
|
+
return result.then((r) => handleOptionalResult(r, payload.value));
|
|
2144
|
+
return handleOptionalResult(result, payload.value);
|
|
2145
|
+
}
|
|
2146
|
+
if (payload.value === void 0) {
|
|
2147
|
+
return payload;
|
|
2148
|
+
}
|
|
2149
|
+
return def.innerType._zod.run(payload, ctx);
|
|
2150
|
+
};
|
|
2151
|
+
});
|
|
2152
|
+
const $ZodExactOptional = /* @__PURE__ */ $constructor("$ZodExactOptional", (inst, def) => {
|
|
2153
|
+
$ZodOptional.init(inst, def);
|
|
2154
|
+
defineLazy(inst._zod, "values", () => def.innerType._zod.values);
|
|
2155
|
+
defineLazy(inst._zod, "pattern", () => def.innerType._zod.pattern);
|
|
2156
|
+
inst._zod.parse = (payload, ctx) => {
|
|
2157
|
+
return def.innerType._zod.run(payload, ctx);
|
|
2158
|
+
};
|
|
2159
|
+
});
|
|
2160
|
+
const $ZodNullable = /* @__PURE__ */ $constructor("$ZodNullable", (inst, def) => {
|
|
2161
|
+
$ZodType.init(inst, def);
|
|
2162
|
+
defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
|
|
2163
|
+
defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
|
|
2164
|
+
defineLazy(inst._zod, "pattern", () => {
|
|
2165
|
+
const pattern = def.innerType._zod.pattern;
|
|
2166
|
+
return pattern ? new RegExp(`^(${cleanRegex(pattern.source)}|null)$`) : void 0;
|
|
2167
|
+
});
|
|
2168
|
+
defineLazy(inst._zod, "values", () => {
|
|
2169
|
+
return def.innerType._zod.values ? /* @__PURE__ */ new Set([...def.innerType._zod.values, null]) : void 0;
|
|
2170
|
+
});
|
|
2171
|
+
inst._zod.parse = (payload, ctx) => {
|
|
2172
|
+
if (payload.value === null)
|
|
2173
|
+
return payload;
|
|
2174
|
+
return def.innerType._zod.run(payload, ctx);
|
|
2175
|
+
};
|
|
2176
|
+
});
|
|
2177
|
+
const $ZodDefault = /* @__PURE__ */ $constructor("$ZodDefault", (inst, def) => {
|
|
2178
|
+
$ZodType.init(inst, def);
|
|
2179
|
+
inst._zod.optin = "optional";
|
|
2180
|
+
defineLazy(inst._zod, "values", () => def.innerType._zod.values);
|
|
2181
|
+
inst._zod.parse = (payload, ctx) => {
|
|
2182
|
+
if (ctx.direction === "backward") {
|
|
2183
|
+
return def.innerType._zod.run(payload, ctx);
|
|
2184
|
+
}
|
|
2185
|
+
if (payload.value === void 0) {
|
|
2186
|
+
payload.value = def.defaultValue;
|
|
2187
|
+
return payload;
|
|
2188
|
+
}
|
|
2189
|
+
const result = def.innerType._zod.run(payload, ctx);
|
|
2190
|
+
if (result instanceof Promise) {
|
|
2191
|
+
return result.then((result2) => handleDefaultResult(result2, def));
|
|
2192
|
+
}
|
|
2193
|
+
return handleDefaultResult(result, def);
|
|
2194
|
+
};
|
|
2195
|
+
});
|
|
2196
|
+
function handleDefaultResult(payload, def) {
|
|
2197
|
+
if (payload.value === void 0) {
|
|
2198
|
+
payload.value = def.defaultValue;
|
|
2199
|
+
}
|
|
2200
|
+
return payload;
|
|
2201
|
+
}
|
|
2202
|
+
const $ZodPrefault = /* @__PURE__ */ $constructor("$ZodPrefault", (inst, def) => {
|
|
2203
|
+
$ZodType.init(inst, def);
|
|
2204
|
+
inst._zod.optin = "optional";
|
|
2205
|
+
defineLazy(inst._zod, "values", () => def.innerType._zod.values);
|
|
2206
|
+
inst._zod.parse = (payload, ctx) => {
|
|
2207
|
+
if (ctx.direction === "backward") {
|
|
2208
|
+
return def.innerType._zod.run(payload, ctx);
|
|
2209
|
+
}
|
|
2210
|
+
if (payload.value === void 0) {
|
|
2211
|
+
payload.value = def.defaultValue;
|
|
2212
|
+
}
|
|
2213
|
+
return def.innerType._zod.run(payload, ctx);
|
|
2214
|
+
};
|
|
2215
|
+
});
|
|
2216
|
+
const $ZodNonOptional = /* @__PURE__ */ $constructor("$ZodNonOptional", (inst, def) => {
|
|
2217
|
+
$ZodType.init(inst, def);
|
|
2218
|
+
defineLazy(inst._zod, "values", () => {
|
|
2219
|
+
const v = def.innerType._zod.values;
|
|
2220
|
+
return v ? new Set([...v].filter((x) => x !== void 0)) : void 0;
|
|
2221
|
+
});
|
|
2222
|
+
inst._zod.parse = (payload, ctx) => {
|
|
2223
|
+
const result = def.innerType._zod.run(payload, ctx);
|
|
2224
|
+
if (result instanceof Promise) {
|
|
2225
|
+
return result.then((result2) => handleNonOptionalResult(result2, inst));
|
|
2226
|
+
}
|
|
2227
|
+
return handleNonOptionalResult(result, inst);
|
|
2228
|
+
};
|
|
2229
|
+
});
|
|
2230
|
+
function handleNonOptionalResult(payload, inst) {
|
|
2231
|
+
if (!payload.issues.length && payload.value === void 0) {
|
|
2232
|
+
payload.issues.push({
|
|
2233
|
+
code: "invalid_type",
|
|
2234
|
+
expected: "nonoptional",
|
|
2235
|
+
input: payload.value,
|
|
2236
|
+
inst
|
|
2237
|
+
});
|
|
2238
|
+
}
|
|
2239
|
+
return payload;
|
|
2240
|
+
}
|
|
2241
|
+
const $ZodCatch = /* @__PURE__ */ $constructor("$ZodCatch", (inst, def) => {
|
|
2242
|
+
$ZodType.init(inst, def);
|
|
2243
|
+
defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
|
|
2244
|
+
defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
|
|
2245
|
+
defineLazy(inst._zod, "values", () => def.innerType._zod.values);
|
|
2246
|
+
inst._zod.parse = (payload, ctx) => {
|
|
2247
|
+
if (ctx.direction === "backward") {
|
|
2248
|
+
return def.innerType._zod.run(payload, ctx);
|
|
2249
|
+
}
|
|
2250
|
+
const result = def.innerType._zod.run(payload, ctx);
|
|
2251
|
+
if (result instanceof Promise) {
|
|
2252
|
+
return result.then((result2) => {
|
|
2253
|
+
payload.value = result2.value;
|
|
2254
|
+
if (result2.issues.length) {
|
|
2255
|
+
payload.value = def.catchValue({
|
|
2256
|
+
...payload,
|
|
2257
|
+
error: {
|
|
2258
|
+
issues: result2.issues.map((iss) => finalizeIssue(iss, ctx, config()))
|
|
2259
|
+
},
|
|
2260
|
+
input: payload.value
|
|
2261
|
+
});
|
|
2262
|
+
payload.issues = [];
|
|
2263
|
+
}
|
|
2264
|
+
return payload;
|
|
2265
|
+
});
|
|
2266
|
+
}
|
|
2267
|
+
payload.value = result.value;
|
|
2268
|
+
if (result.issues.length) {
|
|
2269
|
+
payload.value = def.catchValue({
|
|
2270
|
+
...payload,
|
|
2271
|
+
error: {
|
|
2272
|
+
issues: result.issues.map((iss) => finalizeIssue(iss, ctx, config()))
|
|
2273
|
+
},
|
|
2274
|
+
input: payload.value
|
|
2275
|
+
});
|
|
2276
|
+
payload.issues = [];
|
|
2277
|
+
}
|
|
2278
|
+
return payload;
|
|
2279
|
+
};
|
|
2280
|
+
});
|
|
2281
|
+
const $ZodPipe = /* @__PURE__ */ $constructor("$ZodPipe", (inst, def) => {
|
|
2282
|
+
$ZodType.init(inst, def);
|
|
2283
|
+
defineLazy(inst._zod, "values", () => def.in._zod.values);
|
|
2284
|
+
defineLazy(inst._zod, "optin", () => def.in._zod.optin);
|
|
2285
|
+
defineLazy(inst._zod, "optout", () => def.out._zod.optout);
|
|
2286
|
+
defineLazy(inst._zod, "propValues", () => def.in._zod.propValues);
|
|
2287
|
+
inst._zod.parse = (payload, ctx) => {
|
|
2288
|
+
if (ctx.direction === "backward") {
|
|
2289
|
+
const right = def.out._zod.run(payload, ctx);
|
|
2290
|
+
if (right instanceof Promise) {
|
|
2291
|
+
return right.then((right2) => handlePipeResult(right2, def.in, ctx));
|
|
2292
|
+
}
|
|
2293
|
+
return handlePipeResult(right, def.in, ctx);
|
|
2294
|
+
}
|
|
2295
|
+
const left = def.in._zod.run(payload, ctx);
|
|
2296
|
+
if (left instanceof Promise) {
|
|
2297
|
+
return left.then((left2) => handlePipeResult(left2, def.out, ctx));
|
|
2298
|
+
}
|
|
2299
|
+
return handlePipeResult(left, def.out, ctx);
|
|
2300
|
+
};
|
|
2301
|
+
});
|
|
2302
|
+
function handlePipeResult(left, next, ctx) {
|
|
2303
|
+
if (left.issues.length) {
|
|
2304
|
+
left.aborted = true;
|
|
2305
|
+
return left;
|
|
2306
|
+
}
|
|
2307
|
+
return next._zod.run({ value: left.value, issues: left.issues }, ctx);
|
|
2308
|
+
}
|
|
2309
|
+
const $ZodReadonly = /* @__PURE__ */ $constructor("$ZodReadonly", (inst, def) => {
|
|
2310
|
+
$ZodType.init(inst, def);
|
|
2311
|
+
defineLazy(inst._zod, "propValues", () => def.innerType._zod.propValues);
|
|
2312
|
+
defineLazy(inst._zod, "values", () => def.innerType._zod.values);
|
|
2313
|
+
defineLazy(inst._zod, "optin", () => def.innerType?._zod?.optin);
|
|
2314
|
+
defineLazy(inst._zod, "optout", () => def.innerType?._zod?.optout);
|
|
2315
|
+
inst._zod.parse = (payload, ctx) => {
|
|
2316
|
+
if (ctx.direction === "backward") {
|
|
2317
|
+
return def.innerType._zod.run(payload, ctx);
|
|
2318
|
+
}
|
|
2319
|
+
const result = def.innerType._zod.run(payload, ctx);
|
|
2320
|
+
if (result instanceof Promise) {
|
|
2321
|
+
return result.then(handleReadonlyResult);
|
|
2322
|
+
}
|
|
2323
|
+
return handleReadonlyResult(result);
|
|
2324
|
+
};
|
|
2325
|
+
});
|
|
2326
|
+
function handleReadonlyResult(payload) {
|
|
2327
|
+
payload.value = Object.freeze(payload.value);
|
|
2328
|
+
return payload;
|
|
2329
|
+
}
|
|
2330
|
+
const $ZodCustom = /* @__PURE__ */ $constructor("$ZodCustom", (inst, def) => {
|
|
2331
|
+
$ZodCheck.init(inst, def);
|
|
2332
|
+
$ZodType.init(inst, def);
|
|
2333
|
+
inst._zod.parse = (payload, _) => {
|
|
2334
|
+
return payload;
|
|
2335
|
+
};
|
|
2336
|
+
inst._zod.check = (payload) => {
|
|
2337
|
+
const input = payload.value;
|
|
2338
|
+
const r = def.fn(input);
|
|
2339
|
+
if (r instanceof Promise) {
|
|
2340
|
+
return r.then((r2) => handleRefineResult(r2, payload, input, inst));
|
|
2341
|
+
}
|
|
2342
|
+
handleRefineResult(r, payload, input, inst);
|
|
2343
|
+
return;
|
|
2344
|
+
};
|
|
2345
|
+
});
|
|
2346
|
+
function handleRefineResult(result, payload, input, inst) {
|
|
2347
|
+
if (!result) {
|
|
2348
|
+
const _iss = {
|
|
2349
|
+
code: "custom",
|
|
2350
|
+
input,
|
|
2351
|
+
inst,
|
|
2352
|
+
// incorporates params.error into issue reporting
|
|
2353
|
+
path: [...inst._zod.def.path ?? []],
|
|
2354
|
+
// incorporates params.error into issue reporting
|
|
2355
|
+
continue: !inst._zod.def.abort
|
|
2356
|
+
// params: inst._zod.def.params,
|
|
2357
|
+
};
|
|
2358
|
+
if (inst._zod.def.params)
|
|
2359
|
+
_iss.params = inst._zod.def.params;
|
|
2360
|
+
payload.issues.push(issue(_iss));
|
|
2361
|
+
}
|
|
2362
|
+
}
|
|
2363
|
+
var _a;
|
|
2364
|
+
class $ZodRegistry {
|
|
2365
|
+
constructor() {
|
|
2366
|
+
this._map = /* @__PURE__ */ new WeakMap();
|
|
2367
|
+
this._idmap = /* @__PURE__ */ new Map();
|
|
2368
|
+
}
|
|
2369
|
+
add(schema, ..._meta) {
|
|
2370
|
+
const meta = _meta[0];
|
|
2371
|
+
this._map.set(schema, meta);
|
|
2372
|
+
if (meta && typeof meta === "object" && "id" in meta) {
|
|
2373
|
+
this._idmap.set(meta.id, schema);
|
|
2374
|
+
}
|
|
2375
|
+
return this;
|
|
2376
|
+
}
|
|
2377
|
+
clear() {
|
|
2378
|
+
this._map = /* @__PURE__ */ new WeakMap();
|
|
2379
|
+
this._idmap = /* @__PURE__ */ new Map();
|
|
2380
|
+
return this;
|
|
2381
|
+
}
|
|
2382
|
+
remove(schema) {
|
|
2383
|
+
const meta = this._map.get(schema);
|
|
2384
|
+
if (meta && typeof meta === "object" && "id" in meta) {
|
|
2385
|
+
this._idmap.delete(meta.id);
|
|
2386
|
+
}
|
|
2387
|
+
this._map.delete(schema);
|
|
2388
|
+
return this;
|
|
2389
|
+
}
|
|
2390
|
+
get(schema) {
|
|
2391
|
+
const p = schema._zod.parent;
|
|
2392
|
+
if (p) {
|
|
2393
|
+
const pm = { ...this.get(p) ?? {} };
|
|
2394
|
+
delete pm.id;
|
|
2395
|
+
const f = { ...pm, ...this._map.get(schema) };
|
|
2396
|
+
return Object.keys(f).length ? f : void 0;
|
|
2397
|
+
}
|
|
2398
|
+
return this._map.get(schema);
|
|
2399
|
+
}
|
|
2400
|
+
has(schema) {
|
|
2401
|
+
return this._map.has(schema);
|
|
2402
|
+
}
|
|
2403
|
+
}
|
|
2404
|
+
function registry() {
|
|
2405
|
+
return new $ZodRegistry();
|
|
2406
|
+
}
|
|
2407
|
+
(_a = globalThis).__zod_globalRegistry ?? (_a.__zod_globalRegistry = registry());
|
|
2408
|
+
const globalRegistry = globalThis.__zod_globalRegistry;
|
|
2409
|
+
// @__NO_SIDE_EFFECTS__
|
|
2410
|
+
function _string(Class, params) {
|
|
2411
|
+
return new Class({
|
|
2412
|
+
type: "string",
|
|
2413
|
+
...normalizeParams(params)
|
|
2414
|
+
});
|
|
2415
|
+
}
|
|
2416
|
+
// @__NO_SIDE_EFFECTS__
|
|
2417
|
+
function _email(Class, params) {
|
|
2418
|
+
return new Class({
|
|
2419
|
+
type: "string",
|
|
2420
|
+
format: "email",
|
|
2421
|
+
check: "string_format",
|
|
2422
|
+
abort: false,
|
|
2423
|
+
...normalizeParams(params)
|
|
2424
|
+
});
|
|
2425
|
+
}
|
|
2426
|
+
// @__NO_SIDE_EFFECTS__
|
|
2427
|
+
function _guid(Class, params) {
|
|
2428
|
+
return new Class({
|
|
2429
|
+
type: "string",
|
|
2430
|
+
format: "guid",
|
|
2431
|
+
check: "string_format",
|
|
2432
|
+
abort: false,
|
|
2433
|
+
...normalizeParams(params)
|
|
2434
|
+
});
|
|
2435
|
+
}
|
|
2436
|
+
// @__NO_SIDE_EFFECTS__
|
|
2437
|
+
function _uuid(Class, params) {
|
|
2438
|
+
return new Class({
|
|
2439
|
+
type: "string",
|
|
2440
|
+
format: "uuid",
|
|
2441
|
+
check: "string_format",
|
|
2442
|
+
abort: false,
|
|
2443
|
+
...normalizeParams(params)
|
|
2444
|
+
});
|
|
2445
|
+
}
|
|
2446
|
+
// @__NO_SIDE_EFFECTS__
|
|
2447
|
+
function _uuidv4(Class, params) {
|
|
2448
|
+
return new Class({
|
|
2449
|
+
type: "string",
|
|
2450
|
+
format: "uuid",
|
|
2451
|
+
check: "string_format",
|
|
2452
|
+
abort: false,
|
|
2453
|
+
version: "v4",
|
|
2454
|
+
...normalizeParams(params)
|
|
2455
|
+
});
|
|
2456
|
+
}
|
|
2457
|
+
// @__NO_SIDE_EFFECTS__
|
|
2458
|
+
function _uuidv6(Class, params) {
|
|
2459
|
+
return new Class({
|
|
2460
|
+
type: "string",
|
|
2461
|
+
format: "uuid",
|
|
2462
|
+
check: "string_format",
|
|
2463
|
+
abort: false,
|
|
2464
|
+
version: "v6",
|
|
2465
|
+
...normalizeParams(params)
|
|
2466
|
+
});
|
|
2467
|
+
}
|
|
2468
|
+
// @__NO_SIDE_EFFECTS__
|
|
2469
|
+
function _uuidv7(Class, params) {
|
|
2470
|
+
return new Class({
|
|
2471
|
+
type: "string",
|
|
2472
|
+
format: "uuid",
|
|
2473
|
+
check: "string_format",
|
|
2474
|
+
abort: false,
|
|
2475
|
+
version: "v7",
|
|
2476
|
+
...normalizeParams(params)
|
|
2477
|
+
});
|
|
2478
|
+
}
|
|
2479
|
+
// @__NO_SIDE_EFFECTS__
|
|
2480
|
+
function _url(Class, params) {
|
|
2481
|
+
return new Class({
|
|
2482
|
+
type: "string",
|
|
2483
|
+
format: "url",
|
|
2484
|
+
check: "string_format",
|
|
2485
|
+
abort: false,
|
|
2486
|
+
...normalizeParams(params)
|
|
2487
|
+
});
|
|
2488
|
+
}
|
|
2489
|
+
// @__NO_SIDE_EFFECTS__
|
|
2490
|
+
function _emoji(Class, params) {
|
|
2491
|
+
return new Class({
|
|
2492
|
+
type: "string",
|
|
2493
|
+
format: "emoji",
|
|
2494
|
+
check: "string_format",
|
|
2495
|
+
abort: false,
|
|
2496
|
+
...normalizeParams(params)
|
|
2497
|
+
});
|
|
2498
|
+
}
|
|
2499
|
+
// @__NO_SIDE_EFFECTS__
|
|
2500
|
+
function _nanoid(Class, params) {
|
|
2501
|
+
return new Class({
|
|
2502
|
+
type: "string",
|
|
2503
|
+
format: "nanoid",
|
|
2504
|
+
check: "string_format",
|
|
2505
|
+
abort: false,
|
|
2506
|
+
...normalizeParams(params)
|
|
2507
|
+
});
|
|
2508
|
+
}
|
|
2509
|
+
// @__NO_SIDE_EFFECTS__
|
|
2510
|
+
function _cuid(Class, params) {
|
|
2511
|
+
return new Class({
|
|
2512
|
+
type: "string",
|
|
2513
|
+
format: "cuid",
|
|
2514
|
+
check: "string_format",
|
|
2515
|
+
abort: false,
|
|
2516
|
+
...normalizeParams(params)
|
|
2517
|
+
});
|
|
2518
|
+
}
|
|
2519
|
+
// @__NO_SIDE_EFFECTS__
|
|
2520
|
+
function _cuid2(Class, params) {
|
|
2521
|
+
return new Class({
|
|
2522
|
+
type: "string",
|
|
2523
|
+
format: "cuid2",
|
|
2524
|
+
check: "string_format",
|
|
2525
|
+
abort: false,
|
|
2526
|
+
...normalizeParams(params)
|
|
2527
|
+
});
|
|
2528
|
+
}
|
|
2529
|
+
// @__NO_SIDE_EFFECTS__
|
|
2530
|
+
function _ulid(Class, params) {
|
|
2531
|
+
return new Class({
|
|
2532
|
+
type: "string",
|
|
2533
|
+
format: "ulid",
|
|
2534
|
+
check: "string_format",
|
|
2535
|
+
abort: false,
|
|
2536
|
+
...normalizeParams(params)
|
|
2537
|
+
});
|
|
2538
|
+
}
|
|
2539
|
+
// @__NO_SIDE_EFFECTS__
|
|
2540
|
+
function _xid(Class, params) {
|
|
2541
|
+
return new Class({
|
|
2542
|
+
type: "string",
|
|
2543
|
+
format: "xid",
|
|
2544
|
+
check: "string_format",
|
|
2545
|
+
abort: false,
|
|
2546
|
+
...normalizeParams(params)
|
|
2547
|
+
});
|
|
2548
|
+
}
|
|
2549
|
+
// @__NO_SIDE_EFFECTS__
|
|
2550
|
+
function _ksuid(Class, params) {
|
|
2551
|
+
return new Class({
|
|
2552
|
+
type: "string",
|
|
2553
|
+
format: "ksuid",
|
|
2554
|
+
check: "string_format",
|
|
2555
|
+
abort: false,
|
|
2556
|
+
...normalizeParams(params)
|
|
2557
|
+
});
|
|
2558
|
+
}
|
|
2559
|
+
// @__NO_SIDE_EFFECTS__
|
|
2560
|
+
function _ipv4(Class, params) {
|
|
2561
|
+
return new Class({
|
|
2562
|
+
type: "string",
|
|
2563
|
+
format: "ipv4",
|
|
2564
|
+
check: "string_format",
|
|
2565
|
+
abort: false,
|
|
2566
|
+
...normalizeParams(params)
|
|
2567
|
+
});
|
|
2568
|
+
}
|
|
2569
|
+
// @__NO_SIDE_EFFECTS__
|
|
2570
|
+
function _ipv6(Class, params) {
|
|
2571
|
+
return new Class({
|
|
2572
|
+
type: "string",
|
|
2573
|
+
format: "ipv6",
|
|
2574
|
+
check: "string_format",
|
|
2575
|
+
abort: false,
|
|
2576
|
+
...normalizeParams(params)
|
|
2577
|
+
});
|
|
2578
|
+
}
|
|
2579
|
+
// @__NO_SIDE_EFFECTS__
|
|
2580
|
+
function _cidrv4(Class, params) {
|
|
2581
|
+
return new Class({
|
|
2582
|
+
type: "string",
|
|
2583
|
+
format: "cidrv4",
|
|
2584
|
+
check: "string_format",
|
|
2585
|
+
abort: false,
|
|
2586
|
+
...normalizeParams(params)
|
|
2587
|
+
});
|
|
2588
|
+
}
|
|
2589
|
+
// @__NO_SIDE_EFFECTS__
|
|
2590
|
+
function _cidrv6(Class, params) {
|
|
2591
|
+
return new Class({
|
|
2592
|
+
type: "string",
|
|
2593
|
+
format: "cidrv6",
|
|
2594
|
+
check: "string_format",
|
|
2595
|
+
abort: false,
|
|
2596
|
+
...normalizeParams(params)
|
|
2597
|
+
});
|
|
2598
|
+
}
|
|
2599
|
+
// @__NO_SIDE_EFFECTS__
|
|
2600
|
+
function _base64(Class, params) {
|
|
2601
|
+
return new Class({
|
|
2602
|
+
type: "string",
|
|
2603
|
+
format: "base64",
|
|
2604
|
+
check: "string_format",
|
|
2605
|
+
abort: false,
|
|
2606
|
+
...normalizeParams(params)
|
|
2607
|
+
});
|
|
2608
|
+
}
|
|
2609
|
+
// @__NO_SIDE_EFFECTS__
|
|
2610
|
+
function _base64url(Class, params) {
|
|
2611
|
+
return new Class({
|
|
2612
|
+
type: "string",
|
|
2613
|
+
format: "base64url",
|
|
2614
|
+
check: "string_format",
|
|
2615
|
+
abort: false,
|
|
2616
|
+
...normalizeParams(params)
|
|
2617
|
+
});
|
|
2618
|
+
}
|
|
2619
|
+
// @__NO_SIDE_EFFECTS__
|
|
2620
|
+
function _e164(Class, params) {
|
|
2621
|
+
return new Class({
|
|
2622
|
+
type: "string",
|
|
2623
|
+
format: "e164",
|
|
2624
|
+
check: "string_format",
|
|
2625
|
+
abort: false,
|
|
2626
|
+
...normalizeParams(params)
|
|
2627
|
+
});
|
|
2628
|
+
}
|
|
2629
|
+
// @__NO_SIDE_EFFECTS__
|
|
2630
|
+
function _jwt(Class, params) {
|
|
2631
|
+
return new Class({
|
|
2632
|
+
type: "string",
|
|
2633
|
+
format: "jwt",
|
|
2634
|
+
check: "string_format",
|
|
2635
|
+
abort: false,
|
|
2636
|
+
...normalizeParams(params)
|
|
2637
|
+
});
|
|
2638
|
+
}
|
|
2639
|
+
// @__NO_SIDE_EFFECTS__
|
|
2640
|
+
function _isoDateTime(Class, params) {
|
|
2641
|
+
return new Class({
|
|
2642
|
+
type: "string",
|
|
2643
|
+
format: "datetime",
|
|
2644
|
+
check: "string_format",
|
|
2645
|
+
offset: false,
|
|
2646
|
+
local: false,
|
|
2647
|
+
precision: null,
|
|
2648
|
+
...normalizeParams(params)
|
|
2649
|
+
});
|
|
2650
|
+
}
|
|
2651
|
+
// @__NO_SIDE_EFFECTS__
|
|
2652
|
+
function _isoDate(Class, params) {
|
|
2653
|
+
return new Class({
|
|
2654
|
+
type: "string",
|
|
2655
|
+
format: "date",
|
|
2656
|
+
check: "string_format",
|
|
2657
|
+
...normalizeParams(params)
|
|
2658
|
+
});
|
|
2659
|
+
}
|
|
2660
|
+
// @__NO_SIDE_EFFECTS__
|
|
2661
|
+
function _isoTime(Class, params) {
|
|
2662
|
+
return new Class({
|
|
2663
|
+
type: "string",
|
|
2664
|
+
format: "time",
|
|
2665
|
+
check: "string_format",
|
|
2666
|
+
precision: null,
|
|
2667
|
+
...normalizeParams(params)
|
|
2668
|
+
});
|
|
2669
|
+
}
|
|
2670
|
+
// @__NO_SIDE_EFFECTS__
|
|
2671
|
+
function _isoDuration(Class, params) {
|
|
2672
|
+
return new Class({
|
|
2673
|
+
type: "string",
|
|
2674
|
+
format: "duration",
|
|
2675
|
+
check: "string_format",
|
|
2676
|
+
...normalizeParams(params)
|
|
2677
|
+
});
|
|
2678
|
+
}
|
|
2679
|
+
// @__NO_SIDE_EFFECTS__
|
|
2680
|
+
function _number(Class, params) {
|
|
2681
|
+
return new Class({
|
|
2682
|
+
type: "number",
|
|
2683
|
+
checks: [],
|
|
2684
|
+
...normalizeParams(params)
|
|
2685
|
+
});
|
|
2686
|
+
}
|
|
2687
|
+
// @__NO_SIDE_EFFECTS__
|
|
2688
|
+
function _int(Class, params) {
|
|
2689
|
+
return new Class({
|
|
2690
|
+
type: "number",
|
|
2691
|
+
check: "number_format",
|
|
2692
|
+
abort: false,
|
|
2693
|
+
format: "safeint",
|
|
2694
|
+
...normalizeParams(params)
|
|
2695
|
+
});
|
|
2696
|
+
}
|
|
2697
|
+
// @__NO_SIDE_EFFECTS__
|
|
2698
|
+
function _boolean(Class, params) {
|
|
2699
|
+
return new Class({
|
|
2700
|
+
type: "boolean",
|
|
2701
|
+
...normalizeParams(params)
|
|
2702
|
+
});
|
|
2703
|
+
}
|
|
2704
|
+
// @__NO_SIDE_EFFECTS__
|
|
2705
|
+
function _unknown(Class) {
|
|
2706
|
+
return new Class({
|
|
2707
|
+
type: "unknown"
|
|
2708
|
+
});
|
|
2709
|
+
}
|
|
2710
|
+
// @__NO_SIDE_EFFECTS__
|
|
2711
|
+
function _never(Class, params) {
|
|
2712
|
+
return new Class({
|
|
2713
|
+
type: "never",
|
|
2714
|
+
...normalizeParams(params)
|
|
2715
|
+
});
|
|
2716
|
+
}
|
|
2717
|
+
// @__NO_SIDE_EFFECTS__
|
|
2718
|
+
function _lt(value, params) {
|
|
2719
|
+
return new $ZodCheckLessThan({
|
|
2720
|
+
check: "less_than",
|
|
2721
|
+
...normalizeParams(params),
|
|
2722
|
+
value,
|
|
2723
|
+
inclusive: false
|
|
2724
|
+
});
|
|
2725
|
+
}
|
|
2726
|
+
// @__NO_SIDE_EFFECTS__
|
|
2727
|
+
function _lte(value, params) {
|
|
2728
|
+
return new $ZodCheckLessThan({
|
|
2729
|
+
check: "less_than",
|
|
2730
|
+
...normalizeParams(params),
|
|
2731
|
+
value,
|
|
2732
|
+
inclusive: true
|
|
2733
|
+
});
|
|
2734
|
+
}
|
|
2735
|
+
// @__NO_SIDE_EFFECTS__
|
|
2736
|
+
function _gt(value, params) {
|
|
2737
|
+
return new $ZodCheckGreaterThan({
|
|
2738
|
+
check: "greater_than",
|
|
2739
|
+
...normalizeParams(params),
|
|
2740
|
+
value,
|
|
2741
|
+
inclusive: false
|
|
2742
|
+
});
|
|
2743
|
+
}
|
|
2744
|
+
// @__NO_SIDE_EFFECTS__
|
|
2745
|
+
function _gte(value, params) {
|
|
2746
|
+
return new $ZodCheckGreaterThan({
|
|
2747
|
+
check: "greater_than",
|
|
2748
|
+
...normalizeParams(params),
|
|
2749
|
+
value,
|
|
2750
|
+
inclusive: true
|
|
2751
|
+
});
|
|
2752
|
+
}
|
|
2753
|
+
// @__NO_SIDE_EFFECTS__
|
|
2754
|
+
function _multipleOf(value, params) {
|
|
2755
|
+
return new $ZodCheckMultipleOf({
|
|
2756
|
+
check: "multiple_of",
|
|
2757
|
+
...normalizeParams(params),
|
|
2758
|
+
value
|
|
2759
|
+
});
|
|
2760
|
+
}
|
|
2761
|
+
// @__NO_SIDE_EFFECTS__
|
|
2762
|
+
function _maxLength(maximum, params) {
|
|
2763
|
+
const ch = new $ZodCheckMaxLength({
|
|
2764
|
+
check: "max_length",
|
|
2765
|
+
...normalizeParams(params),
|
|
2766
|
+
maximum
|
|
2767
|
+
});
|
|
2768
|
+
return ch;
|
|
2769
|
+
}
|
|
2770
|
+
// @__NO_SIDE_EFFECTS__
|
|
2771
|
+
function _minLength(minimum, params) {
|
|
2772
|
+
return new $ZodCheckMinLength({
|
|
2773
|
+
check: "min_length",
|
|
2774
|
+
...normalizeParams(params),
|
|
2775
|
+
minimum
|
|
2776
|
+
});
|
|
2777
|
+
}
|
|
2778
|
+
// @__NO_SIDE_EFFECTS__
|
|
2779
|
+
function _length(length, params) {
|
|
2780
|
+
return new $ZodCheckLengthEquals({
|
|
2781
|
+
check: "length_equals",
|
|
2782
|
+
...normalizeParams(params),
|
|
2783
|
+
length
|
|
2784
|
+
});
|
|
2785
|
+
}
|
|
2786
|
+
// @__NO_SIDE_EFFECTS__
|
|
2787
|
+
function _regex(pattern, params) {
|
|
2788
|
+
return new $ZodCheckRegex({
|
|
2789
|
+
check: "string_format",
|
|
2790
|
+
format: "regex",
|
|
2791
|
+
...normalizeParams(params),
|
|
2792
|
+
pattern
|
|
2793
|
+
});
|
|
2794
|
+
}
|
|
2795
|
+
// @__NO_SIDE_EFFECTS__
|
|
2796
|
+
function _lowercase(params) {
|
|
2797
|
+
return new $ZodCheckLowerCase({
|
|
2798
|
+
check: "string_format",
|
|
2799
|
+
format: "lowercase",
|
|
2800
|
+
...normalizeParams(params)
|
|
2801
|
+
});
|
|
2802
|
+
}
|
|
2803
|
+
// @__NO_SIDE_EFFECTS__
|
|
2804
|
+
function _uppercase(params) {
|
|
2805
|
+
return new $ZodCheckUpperCase({
|
|
2806
|
+
check: "string_format",
|
|
2807
|
+
format: "uppercase",
|
|
2808
|
+
...normalizeParams(params)
|
|
2809
|
+
});
|
|
2810
|
+
}
|
|
2811
|
+
// @__NO_SIDE_EFFECTS__
|
|
2812
|
+
function _includes(includes, params) {
|
|
2813
|
+
return new $ZodCheckIncludes({
|
|
2814
|
+
check: "string_format",
|
|
2815
|
+
format: "includes",
|
|
2816
|
+
...normalizeParams(params),
|
|
2817
|
+
includes
|
|
2818
|
+
});
|
|
2819
|
+
}
|
|
2820
|
+
// @__NO_SIDE_EFFECTS__
|
|
2821
|
+
function _startsWith(prefix, params) {
|
|
2822
|
+
return new $ZodCheckStartsWith({
|
|
2823
|
+
check: "string_format",
|
|
2824
|
+
format: "starts_with",
|
|
2825
|
+
...normalizeParams(params),
|
|
2826
|
+
prefix
|
|
2827
|
+
});
|
|
2828
|
+
}
|
|
2829
|
+
// @__NO_SIDE_EFFECTS__
|
|
2830
|
+
function _endsWith(suffix, params) {
|
|
2831
|
+
return new $ZodCheckEndsWith({
|
|
2832
|
+
check: "string_format",
|
|
2833
|
+
format: "ends_with",
|
|
2834
|
+
...normalizeParams(params),
|
|
2835
|
+
suffix
|
|
2836
|
+
});
|
|
2837
|
+
}
|
|
2838
|
+
// @__NO_SIDE_EFFECTS__
|
|
2839
|
+
function _overwrite(tx) {
|
|
2840
|
+
return new $ZodCheckOverwrite({
|
|
2841
|
+
check: "overwrite",
|
|
2842
|
+
tx
|
|
2843
|
+
});
|
|
2844
|
+
}
|
|
2845
|
+
// @__NO_SIDE_EFFECTS__
|
|
2846
|
+
function _normalize(form) {
|
|
2847
|
+
return /* @__PURE__ */ _overwrite((input) => input.normalize(form));
|
|
2848
|
+
}
|
|
2849
|
+
// @__NO_SIDE_EFFECTS__
|
|
2850
|
+
function _trim() {
|
|
2851
|
+
return /* @__PURE__ */ _overwrite((input) => input.trim());
|
|
2852
|
+
}
|
|
2853
|
+
// @__NO_SIDE_EFFECTS__
|
|
2854
|
+
function _toLowerCase() {
|
|
2855
|
+
return /* @__PURE__ */ _overwrite((input) => input.toLowerCase());
|
|
2856
|
+
}
|
|
2857
|
+
// @__NO_SIDE_EFFECTS__
|
|
2858
|
+
function _toUpperCase() {
|
|
2859
|
+
return /* @__PURE__ */ _overwrite((input) => input.toUpperCase());
|
|
2860
|
+
}
|
|
2861
|
+
// @__NO_SIDE_EFFECTS__
|
|
2862
|
+
function _slugify() {
|
|
2863
|
+
return /* @__PURE__ */ _overwrite((input) => slugify(input));
|
|
2864
|
+
}
|
|
2865
|
+
// @__NO_SIDE_EFFECTS__
|
|
2866
|
+
function _array(Class, element, params) {
|
|
2867
|
+
return new Class({
|
|
2868
|
+
type: "array",
|
|
2869
|
+
element,
|
|
2870
|
+
// get element() {
|
|
2871
|
+
// return element;
|
|
2872
|
+
// },
|
|
2873
|
+
...normalizeParams(params)
|
|
2874
|
+
});
|
|
2875
|
+
}
|
|
2876
|
+
// @__NO_SIDE_EFFECTS__
|
|
2877
|
+
function _refine(Class, fn, _params) {
|
|
2878
|
+
const schema = new Class({
|
|
2879
|
+
type: "custom",
|
|
2880
|
+
check: "custom",
|
|
2881
|
+
fn,
|
|
2882
|
+
...normalizeParams(_params)
|
|
2883
|
+
});
|
|
2884
|
+
return schema;
|
|
2885
|
+
}
|
|
2886
|
+
// @__NO_SIDE_EFFECTS__
|
|
2887
|
+
function _superRefine(fn) {
|
|
2888
|
+
const ch = /* @__PURE__ */ _check((payload) => {
|
|
2889
|
+
payload.addIssue = (issue$1) => {
|
|
2890
|
+
if (typeof issue$1 === "string") {
|
|
2891
|
+
payload.issues.push(issue(issue$1, payload.value, ch._zod.def));
|
|
2892
|
+
} else {
|
|
2893
|
+
const _issue = issue$1;
|
|
2894
|
+
if (_issue.fatal)
|
|
2895
|
+
_issue.continue = false;
|
|
2896
|
+
_issue.code ?? (_issue.code = "custom");
|
|
2897
|
+
_issue.input ?? (_issue.input = payload.value);
|
|
2898
|
+
_issue.inst ?? (_issue.inst = ch);
|
|
2899
|
+
_issue.continue ?? (_issue.continue = !ch._zod.def.abort);
|
|
2900
|
+
payload.issues.push(issue(_issue));
|
|
2901
|
+
}
|
|
2902
|
+
};
|
|
2903
|
+
return fn(payload.value, payload);
|
|
2904
|
+
});
|
|
2905
|
+
return ch;
|
|
2906
|
+
}
|
|
2907
|
+
// @__NO_SIDE_EFFECTS__
|
|
2908
|
+
function _check(fn, params) {
|
|
2909
|
+
const ch = new $ZodCheck({
|
|
2910
|
+
check: "custom",
|
|
2911
|
+
...normalizeParams(params)
|
|
2912
|
+
});
|
|
2913
|
+
ch._zod.check = fn;
|
|
2914
|
+
return ch;
|
|
2915
|
+
}
|
|
2916
|
+
function initializeContext(params) {
|
|
2917
|
+
let target = params?.target ?? "draft-2020-12";
|
|
2918
|
+
if (target === "draft-4")
|
|
2919
|
+
target = "draft-04";
|
|
2920
|
+
if (target === "draft-7")
|
|
2921
|
+
target = "draft-07";
|
|
2922
|
+
return {
|
|
2923
|
+
processors: params.processors ?? {},
|
|
2924
|
+
metadataRegistry: params?.metadata ?? globalRegistry,
|
|
2925
|
+
target,
|
|
2926
|
+
unrepresentable: params?.unrepresentable ?? "throw",
|
|
2927
|
+
override: params?.override ?? (() => {
|
|
2928
|
+
}),
|
|
2929
|
+
io: params?.io ?? "output",
|
|
2930
|
+
counter: 0,
|
|
2931
|
+
seen: /* @__PURE__ */ new Map(),
|
|
2932
|
+
cycles: params?.cycles ?? "ref",
|
|
2933
|
+
reused: params?.reused ?? "inline",
|
|
2934
|
+
external: params?.external ?? void 0
|
|
2935
|
+
};
|
|
2936
|
+
}
|
|
2937
|
+
function process(schema, ctx, _params = { path: [], schemaPath: [] }) {
|
|
2938
|
+
var _a2;
|
|
2939
|
+
const def = schema._zod.def;
|
|
2940
|
+
const seen = ctx.seen.get(schema);
|
|
2941
|
+
if (seen) {
|
|
2942
|
+
seen.count++;
|
|
2943
|
+
const isCycle = _params.schemaPath.includes(schema);
|
|
2944
|
+
if (isCycle) {
|
|
2945
|
+
seen.cycle = _params.path;
|
|
2946
|
+
}
|
|
2947
|
+
return seen.schema;
|
|
2948
|
+
}
|
|
2949
|
+
const result = { schema: {}, count: 1, cycle: void 0, path: _params.path };
|
|
2950
|
+
ctx.seen.set(schema, result);
|
|
2951
|
+
const overrideSchema = schema._zod.toJSONSchema?.();
|
|
2952
|
+
if (overrideSchema) {
|
|
2953
|
+
result.schema = overrideSchema;
|
|
2954
|
+
} else {
|
|
2955
|
+
const params = {
|
|
2956
|
+
..._params,
|
|
2957
|
+
schemaPath: [..._params.schemaPath, schema],
|
|
2958
|
+
path: _params.path
|
|
2959
|
+
};
|
|
2960
|
+
if (schema._zod.processJSONSchema) {
|
|
2961
|
+
schema._zod.processJSONSchema(ctx, result.schema, params);
|
|
2962
|
+
} else {
|
|
2963
|
+
const _json = result.schema;
|
|
2964
|
+
const processor = ctx.processors[def.type];
|
|
2965
|
+
if (!processor) {
|
|
2966
|
+
throw new Error(`[toJSONSchema]: Non-representable type encountered: ${def.type}`);
|
|
2967
|
+
}
|
|
2968
|
+
processor(schema, ctx, _json, params);
|
|
2969
|
+
}
|
|
2970
|
+
const parent = schema._zod.parent;
|
|
2971
|
+
if (parent) {
|
|
2972
|
+
if (!result.ref)
|
|
2973
|
+
result.ref = parent;
|
|
2974
|
+
process(parent, ctx, params);
|
|
2975
|
+
ctx.seen.get(parent).isParent = true;
|
|
2976
|
+
}
|
|
2977
|
+
}
|
|
2978
|
+
const meta = ctx.metadataRegistry.get(schema);
|
|
2979
|
+
if (meta)
|
|
2980
|
+
Object.assign(result.schema, meta);
|
|
2981
|
+
if (ctx.io === "input" && isTransforming(schema)) {
|
|
2982
|
+
delete result.schema.examples;
|
|
2983
|
+
delete result.schema.default;
|
|
2984
|
+
}
|
|
2985
|
+
if (ctx.io === "input" && result.schema._prefault)
|
|
2986
|
+
(_a2 = result.schema).default ?? (_a2.default = result.schema._prefault);
|
|
2987
|
+
delete result.schema._prefault;
|
|
2988
|
+
const _result = ctx.seen.get(schema);
|
|
2989
|
+
return _result.schema;
|
|
2990
|
+
}
|
|
2991
|
+
function extractDefs(ctx, schema) {
|
|
2992
|
+
const root = ctx.seen.get(schema);
|
|
2993
|
+
if (!root)
|
|
2994
|
+
throw new Error("Unprocessed schema. This is a bug in Zod.");
|
|
2995
|
+
const idToSchema = /* @__PURE__ */ new Map();
|
|
2996
|
+
for (const entry of ctx.seen.entries()) {
|
|
2997
|
+
const id = ctx.metadataRegistry.get(entry[0])?.id;
|
|
2998
|
+
if (id) {
|
|
2999
|
+
const existing = idToSchema.get(id);
|
|
3000
|
+
if (existing && existing !== entry[0]) {
|
|
3001
|
+
throw new Error(`Duplicate schema id "${id}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);
|
|
3002
|
+
}
|
|
3003
|
+
idToSchema.set(id, entry[0]);
|
|
3004
|
+
}
|
|
3005
|
+
}
|
|
3006
|
+
const makeURI = (entry) => {
|
|
3007
|
+
const defsSegment = ctx.target === "draft-2020-12" ? "$defs" : "definitions";
|
|
3008
|
+
if (ctx.external) {
|
|
3009
|
+
const externalId = ctx.external.registry.get(entry[0])?.id;
|
|
3010
|
+
const uriGenerator = ctx.external.uri ?? ((id2) => id2);
|
|
3011
|
+
if (externalId) {
|
|
3012
|
+
return { ref: uriGenerator(externalId) };
|
|
3013
|
+
}
|
|
3014
|
+
const id = entry[1].defId ?? entry[1].schema.id ?? `schema${ctx.counter++}`;
|
|
3015
|
+
entry[1].defId = id;
|
|
3016
|
+
return { defId: id, ref: `${uriGenerator("__shared")}#/${defsSegment}/${id}` };
|
|
3017
|
+
}
|
|
3018
|
+
if (entry[1] === root) {
|
|
3019
|
+
return { ref: "#" };
|
|
3020
|
+
}
|
|
3021
|
+
const uriPrefix = `#`;
|
|
3022
|
+
const defUriPrefix = `${uriPrefix}/${defsSegment}/`;
|
|
3023
|
+
const defId = entry[1].schema.id ?? `__schema${ctx.counter++}`;
|
|
3024
|
+
return { defId, ref: defUriPrefix + defId };
|
|
3025
|
+
};
|
|
3026
|
+
const extractToDef = (entry) => {
|
|
3027
|
+
if (entry[1].schema.$ref) {
|
|
3028
|
+
return;
|
|
3029
|
+
}
|
|
3030
|
+
const seen = entry[1];
|
|
3031
|
+
const { ref, defId } = makeURI(entry);
|
|
3032
|
+
seen.def = { ...seen.schema };
|
|
3033
|
+
if (defId)
|
|
3034
|
+
seen.defId = defId;
|
|
3035
|
+
const schema2 = seen.schema;
|
|
3036
|
+
for (const key in schema2) {
|
|
3037
|
+
delete schema2[key];
|
|
3038
|
+
}
|
|
3039
|
+
schema2.$ref = ref;
|
|
3040
|
+
};
|
|
3041
|
+
if (ctx.cycles === "throw") {
|
|
3042
|
+
for (const entry of ctx.seen.entries()) {
|
|
3043
|
+
const seen = entry[1];
|
|
3044
|
+
if (seen.cycle) {
|
|
3045
|
+
throw new Error(`Cycle detected: #/${seen.cycle?.join("/")}/<root>
|
|
3046
|
+
|
|
3047
|
+
Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`);
|
|
3048
|
+
}
|
|
3049
|
+
}
|
|
3050
|
+
}
|
|
3051
|
+
for (const entry of ctx.seen.entries()) {
|
|
3052
|
+
const seen = entry[1];
|
|
3053
|
+
if (schema === entry[0]) {
|
|
3054
|
+
extractToDef(entry);
|
|
3055
|
+
continue;
|
|
3056
|
+
}
|
|
3057
|
+
if (ctx.external) {
|
|
3058
|
+
const ext = ctx.external.registry.get(entry[0])?.id;
|
|
3059
|
+
if (schema !== entry[0] && ext) {
|
|
3060
|
+
extractToDef(entry);
|
|
3061
|
+
continue;
|
|
3062
|
+
}
|
|
3063
|
+
}
|
|
3064
|
+
const id = ctx.metadataRegistry.get(entry[0])?.id;
|
|
3065
|
+
if (id) {
|
|
3066
|
+
extractToDef(entry);
|
|
3067
|
+
continue;
|
|
3068
|
+
}
|
|
3069
|
+
if (seen.cycle) {
|
|
3070
|
+
extractToDef(entry);
|
|
3071
|
+
continue;
|
|
3072
|
+
}
|
|
3073
|
+
if (seen.count > 1) {
|
|
3074
|
+
if (ctx.reused === "ref") {
|
|
3075
|
+
extractToDef(entry);
|
|
3076
|
+
continue;
|
|
3077
|
+
}
|
|
3078
|
+
}
|
|
3079
|
+
}
|
|
3080
|
+
}
|
|
3081
|
+
function finalize(ctx, schema) {
|
|
3082
|
+
const root = ctx.seen.get(schema);
|
|
3083
|
+
if (!root)
|
|
3084
|
+
throw new Error("Unprocessed schema. This is a bug in Zod.");
|
|
3085
|
+
const flattenRef = (zodSchema) => {
|
|
3086
|
+
const seen = ctx.seen.get(zodSchema);
|
|
3087
|
+
if (seen.ref === null)
|
|
3088
|
+
return;
|
|
3089
|
+
const schema2 = seen.def ?? seen.schema;
|
|
3090
|
+
const _cached = { ...schema2 };
|
|
3091
|
+
const ref = seen.ref;
|
|
3092
|
+
seen.ref = null;
|
|
3093
|
+
if (ref) {
|
|
3094
|
+
flattenRef(ref);
|
|
3095
|
+
const refSeen = ctx.seen.get(ref);
|
|
3096
|
+
const refSchema = refSeen.schema;
|
|
3097
|
+
if (refSchema.$ref && (ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0")) {
|
|
3098
|
+
schema2.allOf = schema2.allOf ?? [];
|
|
3099
|
+
schema2.allOf.push(refSchema);
|
|
3100
|
+
} else {
|
|
3101
|
+
Object.assign(schema2, refSchema);
|
|
3102
|
+
}
|
|
3103
|
+
Object.assign(schema2, _cached);
|
|
3104
|
+
const isParentRef = zodSchema._zod.parent === ref;
|
|
3105
|
+
if (isParentRef) {
|
|
3106
|
+
for (const key in schema2) {
|
|
3107
|
+
if (key === "$ref" || key === "allOf")
|
|
3108
|
+
continue;
|
|
3109
|
+
if (!(key in _cached)) {
|
|
3110
|
+
delete schema2[key];
|
|
3111
|
+
}
|
|
3112
|
+
}
|
|
3113
|
+
}
|
|
3114
|
+
if (refSchema.$ref && refSeen.def) {
|
|
3115
|
+
for (const key in schema2) {
|
|
3116
|
+
if (key === "$ref" || key === "allOf")
|
|
3117
|
+
continue;
|
|
3118
|
+
if (key in refSeen.def && JSON.stringify(schema2[key]) === JSON.stringify(refSeen.def[key])) {
|
|
3119
|
+
delete schema2[key];
|
|
3120
|
+
}
|
|
3121
|
+
}
|
|
3122
|
+
}
|
|
3123
|
+
}
|
|
3124
|
+
const parent = zodSchema._zod.parent;
|
|
3125
|
+
if (parent && parent !== ref) {
|
|
3126
|
+
flattenRef(parent);
|
|
3127
|
+
const parentSeen = ctx.seen.get(parent);
|
|
3128
|
+
if (parentSeen?.schema.$ref) {
|
|
3129
|
+
schema2.$ref = parentSeen.schema.$ref;
|
|
3130
|
+
if (parentSeen.def) {
|
|
3131
|
+
for (const key in schema2) {
|
|
3132
|
+
if (key === "$ref" || key === "allOf")
|
|
3133
|
+
continue;
|
|
3134
|
+
if (key in parentSeen.def && JSON.stringify(schema2[key]) === JSON.stringify(parentSeen.def[key])) {
|
|
3135
|
+
delete schema2[key];
|
|
3136
|
+
}
|
|
3137
|
+
}
|
|
3138
|
+
}
|
|
3139
|
+
}
|
|
3140
|
+
}
|
|
3141
|
+
ctx.override({
|
|
3142
|
+
zodSchema,
|
|
3143
|
+
jsonSchema: schema2,
|
|
3144
|
+
path: seen.path ?? []
|
|
3145
|
+
});
|
|
3146
|
+
};
|
|
3147
|
+
for (const entry of [...ctx.seen.entries()].reverse()) {
|
|
3148
|
+
flattenRef(entry[0]);
|
|
3149
|
+
}
|
|
3150
|
+
const result = {};
|
|
3151
|
+
if (ctx.target === "draft-2020-12") {
|
|
3152
|
+
result.$schema = "https://json-schema.org/draft/2020-12/schema";
|
|
3153
|
+
} else if (ctx.target === "draft-07") {
|
|
3154
|
+
result.$schema = "http://json-schema.org/draft-07/schema#";
|
|
3155
|
+
} else if (ctx.target === "draft-04") {
|
|
3156
|
+
result.$schema = "http://json-schema.org/draft-04/schema#";
|
|
3157
|
+
} else if (ctx.target === "openapi-3.0") ;
|
|
3158
|
+
else ;
|
|
3159
|
+
if (ctx.external?.uri) {
|
|
3160
|
+
const id = ctx.external.registry.get(schema)?.id;
|
|
3161
|
+
if (!id)
|
|
3162
|
+
throw new Error("Schema is missing an `id` property");
|
|
3163
|
+
result.$id = ctx.external.uri(id);
|
|
3164
|
+
}
|
|
3165
|
+
Object.assign(result, root.def ?? root.schema);
|
|
3166
|
+
const defs = ctx.external?.defs ?? {};
|
|
3167
|
+
for (const entry of ctx.seen.entries()) {
|
|
3168
|
+
const seen = entry[1];
|
|
3169
|
+
if (seen.def && seen.defId) {
|
|
3170
|
+
defs[seen.defId] = seen.def;
|
|
3171
|
+
}
|
|
3172
|
+
}
|
|
3173
|
+
if (ctx.external) ;
|
|
3174
|
+
else {
|
|
3175
|
+
if (Object.keys(defs).length > 0) {
|
|
3176
|
+
if (ctx.target === "draft-2020-12") {
|
|
3177
|
+
result.$defs = defs;
|
|
3178
|
+
} else {
|
|
3179
|
+
result.definitions = defs;
|
|
3180
|
+
}
|
|
3181
|
+
}
|
|
3182
|
+
}
|
|
3183
|
+
try {
|
|
3184
|
+
const finalized = JSON.parse(JSON.stringify(result));
|
|
3185
|
+
Object.defineProperty(finalized, "~standard", {
|
|
3186
|
+
value: {
|
|
3187
|
+
...schema["~standard"],
|
|
3188
|
+
jsonSchema: {
|
|
3189
|
+
input: createStandardJSONSchemaMethod(schema, "input", ctx.processors),
|
|
3190
|
+
output: createStandardJSONSchemaMethod(schema, "output", ctx.processors)
|
|
3191
|
+
}
|
|
3192
|
+
},
|
|
3193
|
+
enumerable: false,
|
|
3194
|
+
writable: false
|
|
3195
|
+
});
|
|
3196
|
+
return finalized;
|
|
3197
|
+
} catch (_err) {
|
|
3198
|
+
throw new Error("Error converting schema to JSON.");
|
|
3199
|
+
}
|
|
3200
|
+
}
|
|
3201
|
+
function isTransforming(_schema, _ctx) {
|
|
3202
|
+
const ctx = _ctx ?? { seen: /* @__PURE__ */ new Set() };
|
|
3203
|
+
if (ctx.seen.has(_schema))
|
|
3204
|
+
return false;
|
|
3205
|
+
ctx.seen.add(_schema);
|
|
3206
|
+
const def = _schema._zod.def;
|
|
3207
|
+
if (def.type === "transform")
|
|
3208
|
+
return true;
|
|
3209
|
+
if (def.type === "array")
|
|
3210
|
+
return isTransforming(def.element, ctx);
|
|
3211
|
+
if (def.type === "set")
|
|
3212
|
+
return isTransforming(def.valueType, ctx);
|
|
3213
|
+
if (def.type === "lazy")
|
|
3214
|
+
return isTransforming(def.getter(), ctx);
|
|
3215
|
+
if (def.type === "promise" || def.type === "optional" || def.type === "nonoptional" || def.type === "nullable" || def.type === "readonly" || def.type === "default" || def.type === "prefault") {
|
|
3216
|
+
return isTransforming(def.innerType, ctx);
|
|
3217
|
+
}
|
|
3218
|
+
if (def.type === "intersection") {
|
|
3219
|
+
return isTransforming(def.left, ctx) || isTransforming(def.right, ctx);
|
|
3220
|
+
}
|
|
3221
|
+
if (def.type === "record" || def.type === "map") {
|
|
3222
|
+
return isTransforming(def.keyType, ctx) || isTransforming(def.valueType, ctx);
|
|
3223
|
+
}
|
|
3224
|
+
if (def.type === "pipe") {
|
|
3225
|
+
return isTransforming(def.in, ctx) || isTransforming(def.out, ctx);
|
|
3226
|
+
}
|
|
3227
|
+
if (def.type === "object") {
|
|
3228
|
+
for (const key in def.shape) {
|
|
3229
|
+
if (isTransforming(def.shape[key], ctx))
|
|
3230
|
+
return true;
|
|
3231
|
+
}
|
|
3232
|
+
return false;
|
|
3233
|
+
}
|
|
3234
|
+
if (def.type === "union") {
|
|
3235
|
+
for (const option of def.options) {
|
|
3236
|
+
if (isTransforming(option, ctx))
|
|
3237
|
+
return true;
|
|
3238
|
+
}
|
|
3239
|
+
return false;
|
|
3240
|
+
}
|
|
3241
|
+
if (def.type === "tuple") {
|
|
3242
|
+
for (const item of def.items) {
|
|
3243
|
+
if (isTransforming(item, ctx))
|
|
3244
|
+
return true;
|
|
3245
|
+
}
|
|
3246
|
+
if (def.rest && isTransforming(def.rest, ctx))
|
|
3247
|
+
return true;
|
|
3248
|
+
return false;
|
|
3249
|
+
}
|
|
3250
|
+
return false;
|
|
3251
|
+
}
|
|
3252
|
+
const createToJSONSchemaMethod = (schema, processors = {}) => (params) => {
|
|
3253
|
+
const ctx = initializeContext({ ...params, processors });
|
|
3254
|
+
process(schema, ctx);
|
|
3255
|
+
extractDefs(ctx, schema);
|
|
3256
|
+
return finalize(ctx, schema);
|
|
3257
|
+
};
|
|
3258
|
+
const createStandardJSONSchemaMethod = (schema, io, processors = {}) => (params) => {
|
|
3259
|
+
const { libraryOptions, target } = params ?? {};
|
|
3260
|
+
const ctx = initializeContext({ ...libraryOptions ?? {}, target, io, processors });
|
|
3261
|
+
process(schema, ctx);
|
|
3262
|
+
extractDefs(ctx, schema);
|
|
3263
|
+
return finalize(ctx, schema);
|
|
3264
|
+
};
|
|
3265
|
+
const formatMap = {
|
|
3266
|
+
guid: "uuid",
|
|
3267
|
+
url: "uri",
|
|
3268
|
+
datetime: "date-time",
|
|
3269
|
+
json_string: "json-string",
|
|
3270
|
+
regex: ""
|
|
3271
|
+
// do not set
|
|
3272
|
+
};
|
|
3273
|
+
const stringProcessor = (schema, ctx, _json, _params) => {
|
|
3274
|
+
const json = _json;
|
|
3275
|
+
json.type = "string";
|
|
3276
|
+
const { minimum, maximum, format, patterns, contentEncoding } = schema._zod.bag;
|
|
3277
|
+
if (typeof minimum === "number")
|
|
3278
|
+
json.minLength = minimum;
|
|
3279
|
+
if (typeof maximum === "number")
|
|
3280
|
+
json.maxLength = maximum;
|
|
3281
|
+
if (format) {
|
|
3282
|
+
json.format = formatMap[format] ?? format;
|
|
3283
|
+
if (json.format === "")
|
|
3284
|
+
delete json.format;
|
|
3285
|
+
if (format === "time") {
|
|
3286
|
+
delete json.format;
|
|
3287
|
+
}
|
|
3288
|
+
}
|
|
3289
|
+
if (contentEncoding)
|
|
3290
|
+
json.contentEncoding = contentEncoding;
|
|
3291
|
+
if (patterns && patterns.size > 0) {
|
|
3292
|
+
const regexes = [...patterns];
|
|
3293
|
+
if (regexes.length === 1)
|
|
3294
|
+
json.pattern = regexes[0].source;
|
|
3295
|
+
else if (regexes.length > 1) {
|
|
3296
|
+
json.allOf = [
|
|
3297
|
+
...regexes.map((regex) => ({
|
|
3298
|
+
...ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0" ? { type: "string" } : {},
|
|
3299
|
+
pattern: regex.source
|
|
3300
|
+
}))
|
|
3301
|
+
];
|
|
3302
|
+
}
|
|
3303
|
+
}
|
|
3304
|
+
};
|
|
3305
|
+
const numberProcessor = (schema, ctx, _json, _params) => {
|
|
3306
|
+
const json = _json;
|
|
3307
|
+
const { minimum, maximum, format, multipleOf, exclusiveMaximum, exclusiveMinimum } = schema._zod.bag;
|
|
3308
|
+
if (typeof format === "string" && format.includes("int"))
|
|
3309
|
+
json.type = "integer";
|
|
3310
|
+
else
|
|
3311
|
+
json.type = "number";
|
|
3312
|
+
if (typeof exclusiveMinimum === "number") {
|
|
3313
|
+
if (ctx.target === "draft-04" || ctx.target === "openapi-3.0") {
|
|
3314
|
+
json.minimum = exclusiveMinimum;
|
|
3315
|
+
json.exclusiveMinimum = true;
|
|
3316
|
+
} else {
|
|
3317
|
+
json.exclusiveMinimum = exclusiveMinimum;
|
|
3318
|
+
}
|
|
3319
|
+
}
|
|
3320
|
+
if (typeof minimum === "number") {
|
|
3321
|
+
json.minimum = minimum;
|
|
3322
|
+
if (typeof exclusiveMinimum === "number" && ctx.target !== "draft-04") {
|
|
3323
|
+
if (exclusiveMinimum >= minimum)
|
|
3324
|
+
delete json.minimum;
|
|
3325
|
+
else
|
|
3326
|
+
delete json.exclusiveMinimum;
|
|
3327
|
+
}
|
|
3328
|
+
}
|
|
3329
|
+
if (typeof exclusiveMaximum === "number") {
|
|
3330
|
+
if (ctx.target === "draft-04" || ctx.target === "openapi-3.0") {
|
|
3331
|
+
json.maximum = exclusiveMaximum;
|
|
3332
|
+
json.exclusiveMaximum = true;
|
|
3333
|
+
} else {
|
|
3334
|
+
json.exclusiveMaximum = exclusiveMaximum;
|
|
3335
|
+
}
|
|
3336
|
+
}
|
|
3337
|
+
if (typeof maximum === "number") {
|
|
3338
|
+
json.maximum = maximum;
|
|
3339
|
+
if (typeof exclusiveMaximum === "number" && ctx.target !== "draft-04") {
|
|
3340
|
+
if (exclusiveMaximum <= maximum)
|
|
3341
|
+
delete json.maximum;
|
|
3342
|
+
else
|
|
3343
|
+
delete json.exclusiveMaximum;
|
|
3344
|
+
}
|
|
3345
|
+
}
|
|
3346
|
+
if (typeof multipleOf === "number")
|
|
3347
|
+
json.multipleOf = multipleOf;
|
|
3348
|
+
};
|
|
3349
|
+
const booleanProcessor = (_schema, _ctx, json, _params) => {
|
|
3350
|
+
json.type = "boolean";
|
|
3351
|
+
};
|
|
3352
|
+
const neverProcessor = (_schema, _ctx, json, _params) => {
|
|
3353
|
+
json.not = {};
|
|
3354
|
+
};
|
|
3355
|
+
const unknownProcessor = (_schema, _ctx, _json, _params) => {
|
|
3356
|
+
};
|
|
3357
|
+
const enumProcessor = (schema, _ctx, json, _params) => {
|
|
3358
|
+
const def = schema._zod.def;
|
|
3359
|
+
const values = getEnumValues(def.entries);
|
|
3360
|
+
if (values.every((v) => typeof v === "number"))
|
|
3361
|
+
json.type = "number";
|
|
3362
|
+
if (values.every((v) => typeof v === "string"))
|
|
3363
|
+
json.type = "string";
|
|
3364
|
+
json.enum = values;
|
|
3365
|
+
};
|
|
3366
|
+
const customProcessor = (_schema, ctx, _json, _params) => {
|
|
3367
|
+
if (ctx.unrepresentable === "throw") {
|
|
3368
|
+
throw new Error("Custom types cannot be represented in JSON Schema");
|
|
3369
|
+
}
|
|
3370
|
+
};
|
|
3371
|
+
const transformProcessor = (_schema, ctx, _json, _params) => {
|
|
3372
|
+
if (ctx.unrepresentable === "throw") {
|
|
3373
|
+
throw new Error("Transforms cannot be represented in JSON Schema");
|
|
3374
|
+
}
|
|
3375
|
+
};
|
|
3376
|
+
const arrayProcessor = (schema, ctx, _json, params) => {
|
|
3377
|
+
const json = _json;
|
|
3378
|
+
const def = schema._zod.def;
|
|
3379
|
+
const { minimum, maximum } = schema._zod.bag;
|
|
3380
|
+
if (typeof minimum === "number")
|
|
3381
|
+
json.minItems = minimum;
|
|
3382
|
+
if (typeof maximum === "number")
|
|
3383
|
+
json.maxItems = maximum;
|
|
3384
|
+
json.type = "array";
|
|
3385
|
+
json.items = process(def.element, ctx, { ...params, path: [...params.path, "items"] });
|
|
3386
|
+
};
|
|
3387
|
+
const objectProcessor = (schema, ctx, _json, params) => {
|
|
3388
|
+
const json = _json;
|
|
3389
|
+
const def = schema._zod.def;
|
|
3390
|
+
json.type = "object";
|
|
3391
|
+
json.properties = {};
|
|
3392
|
+
const shape = def.shape;
|
|
3393
|
+
for (const key in shape) {
|
|
3394
|
+
json.properties[key] = process(shape[key], ctx, {
|
|
3395
|
+
...params,
|
|
3396
|
+
path: [...params.path, "properties", key]
|
|
3397
|
+
});
|
|
3398
|
+
}
|
|
3399
|
+
const allKeys = new Set(Object.keys(shape));
|
|
3400
|
+
const requiredKeys = new Set([...allKeys].filter((key) => {
|
|
3401
|
+
const v = def.shape[key]._zod;
|
|
3402
|
+
if (ctx.io === "input") {
|
|
3403
|
+
return v.optin === void 0;
|
|
3404
|
+
} else {
|
|
3405
|
+
return v.optout === void 0;
|
|
3406
|
+
}
|
|
3407
|
+
}));
|
|
3408
|
+
if (requiredKeys.size > 0) {
|
|
3409
|
+
json.required = Array.from(requiredKeys);
|
|
3410
|
+
}
|
|
3411
|
+
if (def.catchall?._zod.def.type === "never") {
|
|
3412
|
+
json.additionalProperties = false;
|
|
3413
|
+
} else if (!def.catchall) {
|
|
3414
|
+
if (ctx.io === "output")
|
|
3415
|
+
json.additionalProperties = false;
|
|
3416
|
+
} else if (def.catchall) {
|
|
3417
|
+
json.additionalProperties = process(def.catchall, ctx, {
|
|
3418
|
+
...params,
|
|
3419
|
+
path: [...params.path, "additionalProperties"]
|
|
3420
|
+
});
|
|
3421
|
+
}
|
|
3422
|
+
};
|
|
3423
|
+
const unionProcessor = (schema, ctx, json, params) => {
|
|
3424
|
+
const def = schema._zod.def;
|
|
3425
|
+
const isExclusive = def.inclusive === false;
|
|
3426
|
+
const options = def.options.map((x, i) => process(x, ctx, {
|
|
3427
|
+
...params,
|
|
3428
|
+
path: [...params.path, isExclusive ? "oneOf" : "anyOf", i]
|
|
3429
|
+
}));
|
|
3430
|
+
if (isExclusive) {
|
|
3431
|
+
json.oneOf = options;
|
|
3432
|
+
} else {
|
|
3433
|
+
json.anyOf = options;
|
|
3434
|
+
}
|
|
3435
|
+
};
|
|
3436
|
+
const intersectionProcessor = (schema, ctx, json, params) => {
|
|
3437
|
+
const def = schema._zod.def;
|
|
3438
|
+
const a = process(def.left, ctx, {
|
|
3439
|
+
...params,
|
|
3440
|
+
path: [...params.path, "allOf", 0]
|
|
3441
|
+
});
|
|
3442
|
+
const b = process(def.right, ctx, {
|
|
3443
|
+
...params,
|
|
3444
|
+
path: [...params.path, "allOf", 1]
|
|
3445
|
+
});
|
|
3446
|
+
const isSimpleIntersection = (val) => "allOf" in val && Object.keys(val).length === 1;
|
|
3447
|
+
const allOf = [
|
|
3448
|
+
...isSimpleIntersection(a) ? a.allOf : [a],
|
|
3449
|
+
...isSimpleIntersection(b) ? b.allOf : [b]
|
|
3450
|
+
];
|
|
3451
|
+
json.allOf = allOf;
|
|
3452
|
+
};
|
|
3453
|
+
const recordProcessor = (schema, ctx, _json, params) => {
|
|
3454
|
+
const json = _json;
|
|
3455
|
+
const def = schema._zod.def;
|
|
3456
|
+
json.type = "object";
|
|
3457
|
+
const keyType = def.keyType;
|
|
3458
|
+
const keyBag = keyType._zod.bag;
|
|
3459
|
+
const patterns = keyBag?.patterns;
|
|
3460
|
+
if (def.mode === "loose" && patterns && patterns.size > 0) {
|
|
3461
|
+
const valueSchema = process(def.valueType, ctx, {
|
|
3462
|
+
...params,
|
|
3463
|
+
path: [...params.path, "patternProperties", "*"]
|
|
3464
|
+
});
|
|
3465
|
+
json.patternProperties = {};
|
|
3466
|
+
for (const pattern of patterns) {
|
|
3467
|
+
json.patternProperties[pattern.source] = valueSchema;
|
|
3468
|
+
}
|
|
3469
|
+
} else {
|
|
3470
|
+
if (ctx.target === "draft-07" || ctx.target === "draft-2020-12") {
|
|
3471
|
+
json.propertyNames = process(def.keyType, ctx, {
|
|
3472
|
+
...params,
|
|
3473
|
+
path: [...params.path, "propertyNames"]
|
|
3474
|
+
});
|
|
3475
|
+
}
|
|
3476
|
+
json.additionalProperties = process(def.valueType, ctx, {
|
|
3477
|
+
...params,
|
|
3478
|
+
path: [...params.path, "additionalProperties"]
|
|
3479
|
+
});
|
|
3480
|
+
}
|
|
3481
|
+
const keyValues = keyType._zod.values;
|
|
3482
|
+
if (keyValues) {
|
|
3483
|
+
const validKeyValues = [...keyValues].filter((v) => typeof v === "string" || typeof v === "number");
|
|
3484
|
+
if (validKeyValues.length > 0) {
|
|
3485
|
+
json.required = validKeyValues;
|
|
3486
|
+
}
|
|
3487
|
+
}
|
|
3488
|
+
};
|
|
3489
|
+
const nullableProcessor = (schema, ctx, json, params) => {
|
|
3490
|
+
const def = schema._zod.def;
|
|
3491
|
+
const inner = process(def.innerType, ctx, params);
|
|
3492
|
+
const seen = ctx.seen.get(schema);
|
|
3493
|
+
if (ctx.target === "openapi-3.0") {
|
|
3494
|
+
seen.ref = def.innerType;
|
|
3495
|
+
json.nullable = true;
|
|
3496
|
+
} else {
|
|
3497
|
+
json.anyOf = [inner, { type: "null" }];
|
|
3498
|
+
}
|
|
3499
|
+
};
|
|
3500
|
+
const nonoptionalProcessor = (schema, ctx, _json, params) => {
|
|
3501
|
+
const def = schema._zod.def;
|
|
3502
|
+
process(def.innerType, ctx, params);
|
|
3503
|
+
const seen = ctx.seen.get(schema);
|
|
3504
|
+
seen.ref = def.innerType;
|
|
3505
|
+
};
|
|
3506
|
+
const defaultProcessor = (schema, ctx, json, params) => {
|
|
3507
|
+
const def = schema._zod.def;
|
|
3508
|
+
process(def.innerType, ctx, params);
|
|
3509
|
+
const seen = ctx.seen.get(schema);
|
|
3510
|
+
seen.ref = def.innerType;
|
|
3511
|
+
json.default = JSON.parse(JSON.stringify(def.defaultValue));
|
|
3512
|
+
};
|
|
3513
|
+
const prefaultProcessor = (schema, ctx, json, params) => {
|
|
3514
|
+
const def = schema._zod.def;
|
|
3515
|
+
process(def.innerType, ctx, params);
|
|
3516
|
+
const seen = ctx.seen.get(schema);
|
|
3517
|
+
seen.ref = def.innerType;
|
|
3518
|
+
if (ctx.io === "input")
|
|
3519
|
+
json._prefault = JSON.parse(JSON.stringify(def.defaultValue));
|
|
3520
|
+
};
|
|
3521
|
+
const catchProcessor = (schema, ctx, json, params) => {
|
|
3522
|
+
const def = schema._zod.def;
|
|
3523
|
+
process(def.innerType, ctx, params);
|
|
3524
|
+
const seen = ctx.seen.get(schema);
|
|
3525
|
+
seen.ref = def.innerType;
|
|
3526
|
+
let catchValue;
|
|
3527
|
+
try {
|
|
3528
|
+
catchValue = def.catchValue(void 0);
|
|
3529
|
+
} catch {
|
|
3530
|
+
throw new Error("Dynamic catch values are not supported in JSON Schema");
|
|
3531
|
+
}
|
|
3532
|
+
json.default = catchValue;
|
|
3533
|
+
};
|
|
3534
|
+
const pipeProcessor = (schema, ctx, _json, params) => {
|
|
3535
|
+
const def = schema._zod.def;
|
|
3536
|
+
const innerType = ctx.io === "input" ? def.in._zod.def.type === "transform" ? def.out : def.in : def.out;
|
|
3537
|
+
process(innerType, ctx, params);
|
|
3538
|
+
const seen = ctx.seen.get(schema);
|
|
3539
|
+
seen.ref = innerType;
|
|
3540
|
+
};
|
|
3541
|
+
const readonlyProcessor = (schema, ctx, json, params) => {
|
|
3542
|
+
const def = schema._zod.def;
|
|
3543
|
+
process(def.innerType, ctx, params);
|
|
3544
|
+
const seen = ctx.seen.get(schema);
|
|
3545
|
+
seen.ref = def.innerType;
|
|
3546
|
+
json.readOnly = true;
|
|
3547
|
+
};
|
|
3548
|
+
const optionalProcessor = (schema, ctx, _json, params) => {
|
|
3549
|
+
const def = schema._zod.def;
|
|
3550
|
+
process(def.innerType, ctx, params);
|
|
3551
|
+
const seen = ctx.seen.get(schema);
|
|
3552
|
+
seen.ref = def.innerType;
|
|
3553
|
+
};
|
|
3554
|
+
const ZodISODateTime = /* @__PURE__ */ $constructor("ZodISODateTime", (inst, def) => {
|
|
3555
|
+
$ZodISODateTime.init(inst, def);
|
|
3556
|
+
ZodStringFormat.init(inst, def);
|
|
3557
|
+
});
|
|
3558
|
+
function datetime(params) {
|
|
3559
|
+
return /* @__PURE__ */ _isoDateTime(ZodISODateTime, params);
|
|
3560
|
+
}
|
|
3561
|
+
const ZodISODate = /* @__PURE__ */ $constructor("ZodISODate", (inst, def) => {
|
|
3562
|
+
$ZodISODate.init(inst, def);
|
|
3563
|
+
ZodStringFormat.init(inst, def);
|
|
3564
|
+
});
|
|
3565
|
+
function date(params) {
|
|
3566
|
+
return /* @__PURE__ */ _isoDate(ZodISODate, params);
|
|
3567
|
+
}
|
|
3568
|
+
const ZodISOTime = /* @__PURE__ */ $constructor("ZodISOTime", (inst, def) => {
|
|
3569
|
+
$ZodISOTime.init(inst, def);
|
|
3570
|
+
ZodStringFormat.init(inst, def);
|
|
3571
|
+
});
|
|
3572
|
+
function time(params) {
|
|
3573
|
+
return /* @__PURE__ */ _isoTime(ZodISOTime, params);
|
|
3574
|
+
}
|
|
3575
|
+
const ZodISODuration = /* @__PURE__ */ $constructor("ZodISODuration", (inst, def) => {
|
|
3576
|
+
$ZodISODuration.init(inst, def);
|
|
3577
|
+
ZodStringFormat.init(inst, def);
|
|
3578
|
+
});
|
|
3579
|
+
function duration(params) {
|
|
3580
|
+
return /* @__PURE__ */ _isoDuration(ZodISODuration, params);
|
|
3581
|
+
}
|
|
3582
|
+
const initializer = (inst, issues) => {
|
|
3583
|
+
$ZodError.init(inst, issues);
|
|
3584
|
+
inst.name = "ZodError";
|
|
3585
|
+
Object.defineProperties(inst, {
|
|
3586
|
+
format: {
|
|
3587
|
+
value: (mapper) => formatError(inst, mapper)
|
|
3588
|
+
// enumerable: false,
|
|
3589
|
+
},
|
|
3590
|
+
flatten: {
|
|
3591
|
+
value: (mapper) => flattenError(inst, mapper)
|
|
3592
|
+
// enumerable: false,
|
|
3593
|
+
},
|
|
3594
|
+
addIssue: {
|
|
3595
|
+
value: (issue2) => {
|
|
3596
|
+
inst.issues.push(issue2);
|
|
3597
|
+
inst.message = JSON.stringify(inst.issues, jsonStringifyReplacer, 2);
|
|
3598
|
+
}
|
|
3599
|
+
// enumerable: false,
|
|
3600
|
+
},
|
|
3601
|
+
addIssues: {
|
|
3602
|
+
value: (issues2) => {
|
|
3603
|
+
inst.issues.push(...issues2);
|
|
3604
|
+
inst.message = JSON.stringify(inst.issues, jsonStringifyReplacer, 2);
|
|
3605
|
+
}
|
|
3606
|
+
// enumerable: false,
|
|
3607
|
+
},
|
|
3608
|
+
isEmpty: {
|
|
3609
|
+
get() {
|
|
3610
|
+
return inst.issues.length === 0;
|
|
3611
|
+
}
|
|
3612
|
+
// enumerable: false,
|
|
3613
|
+
}
|
|
3614
|
+
});
|
|
3615
|
+
};
|
|
3616
|
+
const ZodRealError = $constructor("ZodError", initializer, {
|
|
3617
|
+
Parent: Error
|
|
3618
|
+
});
|
|
3619
|
+
const parse = /* @__PURE__ */ _parse(ZodRealError);
|
|
3620
|
+
const parseAsync = /* @__PURE__ */ _parseAsync(ZodRealError);
|
|
3621
|
+
const safeParse = /* @__PURE__ */ _safeParse(ZodRealError);
|
|
3622
|
+
const safeParseAsync = /* @__PURE__ */ _safeParseAsync(ZodRealError);
|
|
3623
|
+
const encode = /* @__PURE__ */ _encode(ZodRealError);
|
|
3624
|
+
const decode = /* @__PURE__ */ _decode(ZodRealError);
|
|
3625
|
+
const encodeAsync = /* @__PURE__ */ _encodeAsync(ZodRealError);
|
|
3626
|
+
const decodeAsync = /* @__PURE__ */ _decodeAsync(ZodRealError);
|
|
3627
|
+
const safeEncode = /* @__PURE__ */ _safeEncode(ZodRealError);
|
|
3628
|
+
const safeDecode = /* @__PURE__ */ _safeDecode(ZodRealError);
|
|
3629
|
+
const safeEncodeAsync = /* @__PURE__ */ _safeEncodeAsync(ZodRealError);
|
|
3630
|
+
const safeDecodeAsync = /* @__PURE__ */ _safeDecodeAsync(ZodRealError);
|
|
3631
|
+
const ZodType = /* @__PURE__ */ $constructor("ZodType", (inst, def) => {
|
|
3632
|
+
$ZodType.init(inst, def);
|
|
3633
|
+
Object.assign(inst["~standard"], {
|
|
3634
|
+
jsonSchema: {
|
|
3635
|
+
input: createStandardJSONSchemaMethod(inst, "input"),
|
|
3636
|
+
output: createStandardJSONSchemaMethod(inst, "output")
|
|
3637
|
+
}
|
|
3638
|
+
});
|
|
3639
|
+
inst.toJSONSchema = createToJSONSchemaMethod(inst, {});
|
|
3640
|
+
inst.def = def;
|
|
3641
|
+
inst.type = def.type;
|
|
3642
|
+
Object.defineProperty(inst, "_def", { value: def });
|
|
3643
|
+
inst.check = (...checks) => {
|
|
3644
|
+
return inst.clone(mergeDefs(def, {
|
|
3645
|
+
checks: [
|
|
3646
|
+
...def.checks ?? [],
|
|
3647
|
+
...checks.map((ch) => typeof ch === "function" ? { _zod: { check: ch, def: { check: "custom" }, onattach: [] } } : ch)
|
|
3648
|
+
]
|
|
3649
|
+
}), {
|
|
3650
|
+
parent: true
|
|
3651
|
+
});
|
|
3652
|
+
};
|
|
3653
|
+
inst.with = inst.check;
|
|
3654
|
+
inst.clone = (def2, params) => clone(inst, def2, params);
|
|
3655
|
+
inst.brand = () => inst;
|
|
3656
|
+
inst.register = ((reg, meta) => {
|
|
3657
|
+
reg.add(inst, meta);
|
|
3658
|
+
return inst;
|
|
3659
|
+
});
|
|
3660
|
+
inst.parse = (data, params) => parse(inst, data, params, { callee: inst.parse });
|
|
3661
|
+
inst.safeParse = (data, params) => safeParse(inst, data, params);
|
|
3662
|
+
inst.parseAsync = async (data, params) => parseAsync(inst, data, params, { callee: inst.parseAsync });
|
|
3663
|
+
inst.safeParseAsync = async (data, params) => safeParseAsync(inst, data, params);
|
|
3664
|
+
inst.spa = inst.safeParseAsync;
|
|
3665
|
+
inst.encode = (data, params) => encode(inst, data, params);
|
|
3666
|
+
inst.decode = (data, params) => decode(inst, data, params);
|
|
3667
|
+
inst.encodeAsync = async (data, params) => encodeAsync(inst, data, params);
|
|
3668
|
+
inst.decodeAsync = async (data, params) => decodeAsync(inst, data, params);
|
|
3669
|
+
inst.safeEncode = (data, params) => safeEncode(inst, data, params);
|
|
3670
|
+
inst.safeDecode = (data, params) => safeDecode(inst, data, params);
|
|
3671
|
+
inst.safeEncodeAsync = async (data, params) => safeEncodeAsync(inst, data, params);
|
|
3672
|
+
inst.safeDecodeAsync = async (data, params) => safeDecodeAsync(inst, data, params);
|
|
3673
|
+
inst.refine = (check, params) => inst.check(refine(check, params));
|
|
3674
|
+
inst.superRefine = (refinement) => inst.check(superRefine(refinement));
|
|
3675
|
+
inst.overwrite = (fn) => inst.check(/* @__PURE__ */ _overwrite(fn));
|
|
3676
|
+
inst.optional = () => optional(inst);
|
|
3677
|
+
inst.exactOptional = () => exactOptional(inst);
|
|
3678
|
+
inst.nullable = () => nullable(inst);
|
|
3679
|
+
inst.nullish = () => optional(nullable(inst));
|
|
3680
|
+
inst.nonoptional = (params) => nonoptional(inst, params);
|
|
3681
|
+
inst.array = () => array(inst);
|
|
3682
|
+
inst.or = (arg) => union([inst, arg]);
|
|
3683
|
+
inst.and = (arg) => intersection(inst, arg);
|
|
3684
|
+
inst.transform = (tx) => pipe(inst, transform(tx));
|
|
3685
|
+
inst.default = (def2) => _default(inst, def2);
|
|
3686
|
+
inst.prefault = (def2) => prefault(inst, def2);
|
|
3687
|
+
inst.catch = (params) => _catch(inst, params);
|
|
3688
|
+
inst.pipe = (target) => pipe(inst, target);
|
|
3689
|
+
inst.readonly = () => readonly(inst);
|
|
3690
|
+
inst.describe = (description) => {
|
|
3691
|
+
const cl = inst.clone();
|
|
3692
|
+
globalRegistry.add(cl, { description });
|
|
3693
|
+
return cl;
|
|
3694
|
+
};
|
|
3695
|
+
Object.defineProperty(inst, "description", {
|
|
3696
|
+
get() {
|
|
3697
|
+
return globalRegistry.get(inst)?.description;
|
|
3698
|
+
},
|
|
3699
|
+
configurable: true
|
|
3700
|
+
});
|
|
3701
|
+
inst.meta = (...args) => {
|
|
3702
|
+
if (args.length === 0) {
|
|
3703
|
+
return globalRegistry.get(inst);
|
|
3704
|
+
}
|
|
3705
|
+
const cl = inst.clone();
|
|
3706
|
+
globalRegistry.add(cl, args[0]);
|
|
3707
|
+
return cl;
|
|
3708
|
+
};
|
|
3709
|
+
inst.isOptional = () => inst.safeParse(void 0).success;
|
|
3710
|
+
inst.isNullable = () => inst.safeParse(null).success;
|
|
3711
|
+
inst.apply = (fn) => fn(inst);
|
|
3712
|
+
return inst;
|
|
3713
|
+
});
|
|
3714
|
+
const _ZodString = /* @__PURE__ */ $constructor("_ZodString", (inst, def) => {
|
|
3715
|
+
$ZodString.init(inst, def);
|
|
3716
|
+
ZodType.init(inst, def);
|
|
3717
|
+
inst._zod.processJSONSchema = (ctx, json, params) => stringProcessor(inst, ctx, json);
|
|
3718
|
+
const bag = inst._zod.bag;
|
|
3719
|
+
inst.format = bag.format ?? null;
|
|
3720
|
+
inst.minLength = bag.minimum ?? null;
|
|
3721
|
+
inst.maxLength = bag.maximum ?? null;
|
|
3722
|
+
inst.regex = (...args) => inst.check(/* @__PURE__ */ _regex(...args));
|
|
3723
|
+
inst.includes = (...args) => inst.check(/* @__PURE__ */ _includes(...args));
|
|
3724
|
+
inst.startsWith = (...args) => inst.check(/* @__PURE__ */ _startsWith(...args));
|
|
3725
|
+
inst.endsWith = (...args) => inst.check(/* @__PURE__ */ _endsWith(...args));
|
|
3726
|
+
inst.min = (...args) => inst.check(/* @__PURE__ */ _minLength(...args));
|
|
3727
|
+
inst.max = (...args) => inst.check(/* @__PURE__ */ _maxLength(...args));
|
|
3728
|
+
inst.length = (...args) => inst.check(/* @__PURE__ */ _length(...args));
|
|
3729
|
+
inst.nonempty = (...args) => inst.check(/* @__PURE__ */ _minLength(1, ...args));
|
|
3730
|
+
inst.lowercase = (params) => inst.check(/* @__PURE__ */ _lowercase(params));
|
|
3731
|
+
inst.uppercase = (params) => inst.check(/* @__PURE__ */ _uppercase(params));
|
|
3732
|
+
inst.trim = () => inst.check(/* @__PURE__ */ _trim());
|
|
3733
|
+
inst.normalize = (...args) => inst.check(/* @__PURE__ */ _normalize(...args));
|
|
3734
|
+
inst.toLowerCase = () => inst.check(/* @__PURE__ */ _toLowerCase());
|
|
3735
|
+
inst.toUpperCase = () => inst.check(/* @__PURE__ */ _toUpperCase());
|
|
3736
|
+
inst.slugify = () => inst.check(/* @__PURE__ */ _slugify());
|
|
3737
|
+
});
|
|
3738
|
+
const ZodString = /* @__PURE__ */ $constructor("ZodString", (inst, def) => {
|
|
3739
|
+
$ZodString.init(inst, def);
|
|
3740
|
+
_ZodString.init(inst, def);
|
|
3741
|
+
inst.email = (params) => inst.check(/* @__PURE__ */ _email(ZodEmail, params));
|
|
3742
|
+
inst.url = (params) => inst.check(/* @__PURE__ */ _url(ZodURL, params));
|
|
3743
|
+
inst.jwt = (params) => inst.check(/* @__PURE__ */ _jwt(ZodJWT, params));
|
|
3744
|
+
inst.emoji = (params) => inst.check(/* @__PURE__ */ _emoji(ZodEmoji, params));
|
|
3745
|
+
inst.guid = (params) => inst.check(/* @__PURE__ */ _guid(ZodGUID, params));
|
|
3746
|
+
inst.uuid = (params) => inst.check(/* @__PURE__ */ _uuid(ZodUUID, params));
|
|
3747
|
+
inst.uuidv4 = (params) => inst.check(/* @__PURE__ */ _uuidv4(ZodUUID, params));
|
|
3748
|
+
inst.uuidv6 = (params) => inst.check(/* @__PURE__ */ _uuidv6(ZodUUID, params));
|
|
3749
|
+
inst.uuidv7 = (params) => inst.check(/* @__PURE__ */ _uuidv7(ZodUUID, params));
|
|
3750
|
+
inst.nanoid = (params) => inst.check(/* @__PURE__ */ _nanoid(ZodNanoID, params));
|
|
3751
|
+
inst.guid = (params) => inst.check(/* @__PURE__ */ _guid(ZodGUID, params));
|
|
3752
|
+
inst.cuid = (params) => inst.check(/* @__PURE__ */ _cuid(ZodCUID, params));
|
|
3753
|
+
inst.cuid2 = (params) => inst.check(/* @__PURE__ */ _cuid2(ZodCUID2, params));
|
|
3754
|
+
inst.ulid = (params) => inst.check(/* @__PURE__ */ _ulid(ZodULID, params));
|
|
3755
|
+
inst.base64 = (params) => inst.check(/* @__PURE__ */ _base64(ZodBase64, params));
|
|
3756
|
+
inst.base64url = (params) => inst.check(/* @__PURE__ */ _base64url(ZodBase64URL, params));
|
|
3757
|
+
inst.xid = (params) => inst.check(/* @__PURE__ */ _xid(ZodXID, params));
|
|
3758
|
+
inst.ksuid = (params) => inst.check(/* @__PURE__ */ _ksuid(ZodKSUID, params));
|
|
3759
|
+
inst.ipv4 = (params) => inst.check(/* @__PURE__ */ _ipv4(ZodIPv4, params));
|
|
3760
|
+
inst.ipv6 = (params) => inst.check(/* @__PURE__ */ _ipv6(ZodIPv6, params));
|
|
3761
|
+
inst.cidrv4 = (params) => inst.check(/* @__PURE__ */ _cidrv4(ZodCIDRv4, params));
|
|
3762
|
+
inst.cidrv6 = (params) => inst.check(/* @__PURE__ */ _cidrv6(ZodCIDRv6, params));
|
|
3763
|
+
inst.e164 = (params) => inst.check(/* @__PURE__ */ _e164(ZodE164, params));
|
|
3764
|
+
inst.datetime = (params) => inst.check(datetime(params));
|
|
3765
|
+
inst.date = (params) => inst.check(date(params));
|
|
3766
|
+
inst.time = (params) => inst.check(time(params));
|
|
3767
|
+
inst.duration = (params) => inst.check(duration(params));
|
|
3768
|
+
});
|
|
3769
|
+
function string(params) {
|
|
3770
|
+
return /* @__PURE__ */ _string(ZodString, params);
|
|
3771
|
+
}
|
|
3772
|
+
const ZodStringFormat = /* @__PURE__ */ $constructor("ZodStringFormat", (inst, def) => {
|
|
3773
|
+
$ZodStringFormat.init(inst, def);
|
|
3774
|
+
_ZodString.init(inst, def);
|
|
3775
|
+
});
|
|
3776
|
+
const ZodEmail = /* @__PURE__ */ $constructor("ZodEmail", (inst, def) => {
|
|
3777
|
+
$ZodEmail.init(inst, def);
|
|
3778
|
+
ZodStringFormat.init(inst, def);
|
|
3779
|
+
});
|
|
3780
|
+
const ZodGUID = /* @__PURE__ */ $constructor("ZodGUID", (inst, def) => {
|
|
3781
|
+
$ZodGUID.init(inst, def);
|
|
3782
|
+
ZodStringFormat.init(inst, def);
|
|
3783
|
+
});
|
|
3784
|
+
const ZodUUID = /* @__PURE__ */ $constructor("ZodUUID", (inst, def) => {
|
|
3785
|
+
$ZodUUID.init(inst, def);
|
|
3786
|
+
ZodStringFormat.init(inst, def);
|
|
3787
|
+
});
|
|
3788
|
+
const ZodURL = /* @__PURE__ */ $constructor("ZodURL", (inst, def) => {
|
|
3789
|
+
$ZodURL.init(inst, def);
|
|
3790
|
+
ZodStringFormat.init(inst, def);
|
|
3791
|
+
});
|
|
3792
|
+
const ZodEmoji = /* @__PURE__ */ $constructor("ZodEmoji", (inst, def) => {
|
|
3793
|
+
$ZodEmoji.init(inst, def);
|
|
3794
|
+
ZodStringFormat.init(inst, def);
|
|
3795
|
+
});
|
|
3796
|
+
const ZodNanoID = /* @__PURE__ */ $constructor("ZodNanoID", (inst, def) => {
|
|
3797
|
+
$ZodNanoID.init(inst, def);
|
|
3798
|
+
ZodStringFormat.init(inst, def);
|
|
3799
|
+
});
|
|
3800
|
+
const ZodCUID = /* @__PURE__ */ $constructor("ZodCUID", (inst, def) => {
|
|
3801
|
+
$ZodCUID.init(inst, def);
|
|
3802
|
+
ZodStringFormat.init(inst, def);
|
|
3803
|
+
});
|
|
3804
|
+
const ZodCUID2 = /* @__PURE__ */ $constructor("ZodCUID2", (inst, def) => {
|
|
3805
|
+
$ZodCUID2.init(inst, def);
|
|
3806
|
+
ZodStringFormat.init(inst, def);
|
|
3807
|
+
});
|
|
3808
|
+
const ZodULID = /* @__PURE__ */ $constructor("ZodULID", (inst, def) => {
|
|
3809
|
+
$ZodULID.init(inst, def);
|
|
3810
|
+
ZodStringFormat.init(inst, def);
|
|
3811
|
+
});
|
|
3812
|
+
const ZodXID = /* @__PURE__ */ $constructor("ZodXID", (inst, def) => {
|
|
3813
|
+
$ZodXID.init(inst, def);
|
|
3814
|
+
ZodStringFormat.init(inst, def);
|
|
3815
|
+
});
|
|
3816
|
+
const ZodKSUID = /* @__PURE__ */ $constructor("ZodKSUID", (inst, def) => {
|
|
3817
|
+
$ZodKSUID.init(inst, def);
|
|
3818
|
+
ZodStringFormat.init(inst, def);
|
|
3819
|
+
});
|
|
3820
|
+
const ZodIPv4 = /* @__PURE__ */ $constructor("ZodIPv4", (inst, def) => {
|
|
3821
|
+
$ZodIPv4.init(inst, def);
|
|
3822
|
+
ZodStringFormat.init(inst, def);
|
|
3823
|
+
});
|
|
3824
|
+
const ZodIPv6 = /* @__PURE__ */ $constructor("ZodIPv6", (inst, def) => {
|
|
3825
|
+
$ZodIPv6.init(inst, def);
|
|
3826
|
+
ZodStringFormat.init(inst, def);
|
|
3827
|
+
});
|
|
3828
|
+
const ZodCIDRv4 = /* @__PURE__ */ $constructor("ZodCIDRv4", (inst, def) => {
|
|
3829
|
+
$ZodCIDRv4.init(inst, def);
|
|
3830
|
+
ZodStringFormat.init(inst, def);
|
|
3831
|
+
});
|
|
3832
|
+
const ZodCIDRv6 = /* @__PURE__ */ $constructor("ZodCIDRv6", (inst, def) => {
|
|
3833
|
+
$ZodCIDRv6.init(inst, def);
|
|
3834
|
+
ZodStringFormat.init(inst, def);
|
|
3835
|
+
});
|
|
3836
|
+
const ZodBase64 = /* @__PURE__ */ $constructor("ZodBase64", (inst, def) => {
|
|
3837
|
+
$ZodBase64.init(inst, def);
|
|
3838
|
+
ZodStringFormat.init(inst, def);
|
|
3839
|
+
});
|
|
3840
|
+
const ZodBase64URL = /* @__PURE__ */ $constructor("ZodBase64URL", (inst, def) => {
|
|
3841
|
+
$ZodBase64URL.init(inst, def);
|
|
3842
|
+
ZodStringFormat.init(inst, def);
|
|
3843
|
+
});
|
|
3844
|
+
const ZodE164 = /* @__PURE__ */ $constructor("ZodE164", (inst, def) => {
|
|
3845
|
+
$ZodE164.init(inst, def);
|
|
3846
|
+
ZodStringFormat.init(inst, def);
|
|
3847
|
+
});
|
|
3848
|
+
const ZodJWT = /* @__PURE__ */ $constructor("ZodJWT", (inst, def) => {
|
|
3849
|
+
$ZodJWT.init(inst, def);
|
|
3850
|
+
ZodStringFormat.init(inst, def);
|
|
3851
|
+
});
|
|
3852
|
+
const ZodNumber = /* @__PURE__ */ $constructor("ZodNumber", (inst, def) => {
|
|
3853
|
+
$ZodNumber.init(inst, def);
|
|
3854
|
+
ZodType.init(inst, def);
|
|
3855
|
+
inst._zod.processJSONSchema = (ctx, json, params) => numberProcessor(inst, ctx, json);
|
|
3856
|
+
inst.gt = (value, params) => inst.check(/* @__PURE__ */ _gt(value, params));
|
|
3857
|
+
inst.gte = (value, params) => inst.check(/* @__PURE__ */ _gte(value, params));
|
|
3858
|
+
inst.min = (value, params) => inst.check(/* @__PURE__ */ _gte(value, params));
|
|
3859
|
+
inst.lt = (value, params) => inst.check(/* @__PURE__ */ _lt(value, params));
|
|
3860
|
+
inst.lte = (value, params) => inst.check(/* @__PURE__ */ _lte(value, params));
|
|
3861
|
+
inst.max = (value, params) => inst.check(/* @__PURE__ */ _lte(value, params));
|
|
3862
|
+
inst.int = (params) => inst.check(int(params));
|
|
3863
|
+
inst.safe = (params) => inst.check(int(params));
|
|
3864
|
+
inst.positive = (params) => inst.check(/* @__PURE__ */ _gt(0, params));
|
|
3865
|
+
inst.nonnegative = (params) => inst.check(/* @__PURE__ */ _gte(0, params));
|
|
3866
|
+
inst.negative = (params) => inst.check(/* @__PURE__ */ _lt(0, params));
|
|
3867
|
+
inst.nonpositive = (params) => inst.check(/* @__PURE__ */ _lte(0, params));
|
|
3868
|
+
inst.multipleOf = (value, params) => inst.check(/* @__PURE__ */ _multipleOf(value, params));
|
|
3869
|
+
inst.step = (value, params) => inst.check(/* @__PURE__ */ _multipleOf(value, params));
|
|
3870
|
+
inst.finite = () => inst;
|
|
3871
|
+
const bag = inst._zod.bag;
|
|
3872
|
+
inst.minValue = Math.max(bag.minimum ?? Number.NEGATIVE_INFINITY, bag.exclusiveMinimum ?? Number.NEGATIVE_INFINITY) ?? null;
|
|
3873
|
+
inst.maxValue = Math.min(bag.maximum ?? Number.POSITIVE_INFINITY, bag.exclusiveMaximum ?? Number.POSITIVE_INFINITY) ?? null;
|
|
3874
|
+
inst.isInt = (bag.format ?? "").includes("int") || Number.isSafeInteger(bag.multipleOf ?? 0.5);
|
|
3875
|
+
inst.isFinite = true;
|
|
3876
|
+
inst.format = bag.format ?? null;
|
|
3877
|
+
});
|
|
3878
|
+
function number(params) {
|
|
3879
|
+
return /* @__PURE__ */ _number(ZodNumber, params);
|
|
3880
|
+
}
|
|
3881
|
+
const ZodNumberFormat = /* @__PURE__ */ $constructor("ZodNumberFormat", (inst, def) => {
|
|
3882
|
+
$ZodNumberFormat.init(inst, def);
|
|
3883
|
+
ZodNumber.init(inst, def);
|
|
3884
|
+
});
|
|
3885
|
+
function int(params) {
|
|
3886
|
+
return /* @__PURE__ */ _int(ZodNumberFormat, params);
|
|
3887
|
+
}
|
|
3888
|
+
const ZodBoolean = /* @__PURE__ */ $constructor("ZodBoolean", (inst, def) => {
|
|
3889
|
+
$ZodBoolean.init(inst, def);
|
|
3890
|
+
ZodType.init(inst, def);
|
|
3891
|
+
inst._zod.processJSONSchema = (ctx, json, params) => booleanProcessor(inst, ctx, json);
|
|
3892
|
+
});
|
|
3893
|
+
function boolean(params) {
|
|
3894
|
+
return /* @__PURE__ */ _boolean(ZodBoolean, params);
|
|
3895
|
+
}
|
|
3896
|
+
const ZodUnknown = /* @__PURE__ */ $constructor("ZodUnknown", (inst, def) => {
|
|
3897
|
+
$ZodUnknown.init(inst, def);
|
|
3898
|
+
ZodType.init(inst, def);
|
|
3899
|
+
inst._zod.processJSONSchema = (ctx, json, params) => unknownProcessor();
|
|
3900
|
+
});
|
|
3901
|
+
function unknown() {
|
|
3902
|
+
return /* @__PURE__ */ _unknown(ZodUnknown);
|
|
3903
|
+
}
|
|
3904
|
+
const ZodNever = /* @__PURE__ */ $constructor("ZodNever", (inst, def) => {
|
|
3905
|
+
$ZodNever.init(inst, def);
|
|
3906
|
+
ZodType.init(inst, def);
|
|
3907
|
+
inst._zod.processJSONSchema = (ctx, json, params) => neverProcessor(inst, ctx, json);
|
|
3908
|
+
});
|
|
3909
|
+
function never(params) {
|
|
3910
|
+
return /* @__PURE__ */ _never(ZodNever, params);
|
|
3911
|
+
}
|
|
3912
|
+
const ZodArray = /* @__PURE__ */ $constructor("ZodArray", (inst, def) => {
|
|
3913
|
+
$ZodArray.init(inst, def);
|
|
3914
|
+
ZodType.init(inst, def);
|
|
3915
|
+
inst._zod.processJSONSchema = (ctx, json, params) => arrayProcessor(inst, ctx, json, params);
|
|
3916
|
+
inst.element = def.element;
|
|
3917
|
+
inst.min = (minLength, params) => inst.check(/* @__PURE__ */ _minLength(minLength, params));
|
|
3918
|
+
inst.nonempty = (params) => inst.check(/* @__PURE__ */ _minLength(1, params));
|
|
3919
|
+
inst.max = (maxLength, params) => inst.check(/* @__PURE__ */ _maxLength(maxLength, params));
|
|
3920
|
+
inst.length = (len, params) => inst.check(/* @__PURE__ */ _length(len, params));
|
|
3921
|
+
inst.unwrap = () => inst.element;
|
|
3922
|
+
});
|
|
3923
|
+
function array(element, params) {
|
|
3924
|
+
return /* @__PURE__ */ _array(ZodArray, element, params);
|
|
3925
|
+
}
|
|
3926
|
+
const ZodObject = /* @__PURE__ */ $constructor("ZodObject", (inst, def) => {
|
|
3927
|
+
$ZodObjectJIT.init(inst, def);
|
|
3928
|
+
ZodType.init(inst, def);
|
|
3929
|
+
inst._zod.processJSONSchema = (ctx, json, params) => objectProcessor(inst, ctx, json, params);
|
|
3930
|
+
defineLazy(inst, "shape", () => {
|
|
3931
|
+
return def.shape;
|
|
3932
|
+
});
|
|
3933
|
+
inst.keyof = () => _enum(Object.keys(inst._zod.def.shape));
|
|
3934
|
+
inst.catchall = (catchall) => inst.clone({ ...inst._zod.def, catchall });
|
|
3935
|
+
inst.passthrough = () => inst.clone({ ...inst._zod.def, catchall: unknown() });
|
|
3936
|
+
inst.loose = () => inst.clone({ ...inst._zod.def, catchall: unknown() });
|
|
3937
|
+
inst.strict = () => inst.clone({ ...inst._zod.def, catchall: never() });
|
|
3938
|
+
inst.strip = () => inst.clone({ ...inst._zod.def, catchall: void 0 });
|
|
3939
|
+
inst.extend = (incoming) => {
|
|
3940
|
+
return extend(inst, incoming);
|
|
3941
|
+
};
|
|
3942
|
+
inst.safeExtend = (incoming) => {
|
|
3943
|
+
return safeExtend(inst, incoming);
|
|
3944
|
+
};
|
|
3945
|
+
inst.merge = (other) => merge(inst, other);
|
|
3946
|
+
inst.pick = (mask) => pick(inst, mask);
|
|
3947
|
+
inst.omit = (mask) => omit(inst, mask);
|
|
3948
|
+
inst.partial = (...args) => partial(ZodOptional, inst, args[0]);
|
|
3949
|
+
inst.required = (...args) => required(ZodNonOptional, inst, args[0]);
|
|
3950
|
+
});
|
|
3951
|
+
function object(shape, params) {
|
|
3952
|
+
const def = {
|
|
3953
|
+
type: "object",
|
|
3954
|
+
shape: shape ?? {},
|
|
3955
|
+
...normalizeParams(params)
|
|
3956
|
+
};
|
|
3957
|
+
return new ZodObject(def);
|
|
3958
|
+
}
|
|
3959
|
+
const ZodUnion = /* @__PURE__ */ $constructor("ZodUnion", (inst, def) => {
|
|
3960
|
+
$ZodUnion.init(inst, def);
|
|
3961
|
+
ZodType.init(inst, def);
|
|
3962
|
+
inst._zod.processJSONSchema = (ctx, json, params) => unionProcessor(inst, ctx, json, params);
|
|
3963
|
+
inst.options = def.options;
|
|
3964
|
+
});
|
|
3965
|
+
function union(options, params) {
|
|
3966
|
+
return new ZodUnion({
|
|
3967
|
+
type: "union",
|
|
3968
|
+
options,
|
|
3969
|
+
...normalizeParams(params)
|
|
3970
|
+
});
|
|
3971
|
+
}
|
|
3972
|
+
const ZodIntersection = /* @__PURE__ */ $constructor("ZodIntersection", (inst, def) => {
|
|
3973
|
+
$ZodIntersection.init(inst, def);
|
|
3974
|
+
ZodType.init(inst, def);
|
|
3975
|
+
inst._zod.processJSONSchema = (ctx, json, params) => intersectionProcessor(inst, ctx, json, params);
|
|
3976
|
+
});
|
|
3977
|
+
function intersection(left, right) {
|
|
3978
|
+
return new ZodIntersection({
|
|
3979
|
+
type: "intersection",
|
|
3980
|
+
left,
|
|
3981
|
+
right
|
|
3982
|
+
});
|
|
3983
|
+
}
|
|
3984
|
+
const ZodRecord = /* @__PURE__ */ $constructor("ZodRecord", (inst, def) => {
|
|
3985
|
+
$ZodRecord.init(inst, def);
|
|
3986
|
+
ZodType.init(inst, def);
|
|
3987
|
+
inst._zod.processJSONSchema = (ctx, json, params) => recordProcessor(inst, ctx, json, params);
|
|
3988
|
+
inst.keyType = def.keyType;
|
|
3989
|
+
inst.valueType = def.valueType;
|
|
3990
|
+
});
|
|
3991
|
+
function record(keyType, valueType, params) {
|
|
3992
|
+
return new ZodRecord({
|
|
3993
|
+
type: "record",
|
|
3994
|
+
keyType,
|
|
3995
|
+
valueType,
|
|
3996
|
+
...normalizeParams(params)
|
|
3997
|
+
});
|
|
3998
|
+
}
|
|
3999
|
+
const ZodEnum = /* @__PURE__ */ $constructor("ZodEnum", (inst, def) => {
|
|
4000
|
+
$ZodEnum.init(inst, def);
|
|
4001
|
+
ZodType.init(inst, def);
|
|
4002
|
+
inst._zod.processJSONSchema = (ctx, json, params) => enumProcessor(inst, ctx, json);
|
|
4003
|
+
inst.enum = def.entries;
|
|
4004
|
+
inst.options = Object.values(def.entries);
|
|
4005
|
+
const keys = new Set(Object.keys(def.entries));
|
|
4006
|
+
inst.extract = (values, params) => {
|
|
4007
|
+
const newEntries = {};
|
|
4008
|
+
for (const value of values) {
|
|
4009
|
+
if (keys.has(value)) {
|
|
4010
|
+
newEntries[value] = def.entries[value];
|
|
4011
|
+
} else
|
|
4012
|
+
throw new Error(`Key ${value} not found in enum`);
|
|
4013
|
+
}
|
|
4014
|
+
return new ZodEnum({
|
|
4015
|
+
...def,
|
|
4016
|
+
checks: [],
|
|
4017
|
+
...normalizeParams(params),
|
|
4018
|
+
entries: newEntries
|
|
4019
|
+
});
|
|
4020
|
+
};
|
|
4021
|
+
inst.exclude = (values, params) => {
|
|
4022
|
+
const newEntries = { ...def.entries };
|
|
4023
|
+
for (const value of values) {
|
|
4024
|
+
if (keys.has(value)) {
|
|
4025
|
+
delete newEntries[value];
|
|
4026
|
+
} else
|
|
4027
|
+
throw new Error(`Key ${value} not found in enum`);
|
|
4028
|
+
}
|
|
4029
|
+
return new ZodEnum({
|
|
4030
|
+
...def,
|
|
4031
|
+
checks: [],
|
|
4032
|
+
...normalizeParams(params),
|
|
4033
|
+
entries: newEntries
|
|
4034
|
+
});
|
|
4035
|
+
};
|
|
4036
|
+
});
|
|
4037
|
+
function _enum(values, params) {
|
|
4038
|
+
const entries = Array.isArray(values) ? Object.fromEntries(values.map((v) => [v, v])) : values;
|
|
4039
|
+
return new ZodEnum({
|
|
4040
|
+
type: "enum",
|
|
4041
|
+
entries,
|
|
4042
|
+
...normalizeParams(params)
|
|
4043
|
+
});
|
|
4044
|
+
}
|
|
4045
|
+
const ZodTransform = /* @__PURE__ */ $constructor("ZodTransform", (inst, def) => {
|
|
4046
|
+
$ZodTransform.init(inst, def);
|
|
4047
|
+
ZodType.init(inst, def);
|
|
4048
|
+
inst._zod.processJSONSchema = (ctx, json, params) => transformProcessor(inst, ctx);
|
|
4049
|
+
inst._zod.parse = (payload, _ctx) => {
|
|
4050
|
+
if (_ctx.direction === "backward") {
|
|
4051
|
+
throw new $ZodEncodeError(inst.constructor.name);
|
|
4052
|
+
}
|
|
4053
|
+
payload.addIssue = (issue$1) => {
|
|
4054
|
+
if (typeof issue$1 === "string") {
|
|
4055
|
+
payload.issues.push(issue(issue$1, payload.value, def));
|
|
4056
|
+
} else {
|
|
4057
|
+
const _issue = issue$1;
|
|
4058
|
+
if (_issue.fatal)
|
|
4059
|
+
_issue.continue = false;
|
|
4060
|
+
_issue.code ?? (_issue.code = "custom");
|
|
4061
|
+
_issue.input ?? (_issue.input = payload.value);
|
|
4062
|
+
_issue.inst ?? (_issue.inst = inst);
|
|
4063
|
+
payload.issues.push(issue(_issue));
|
|
4064
|
+
}
|
|
4065
|
+
};
|
|
4066
|
+
const output = def.transform(payload.value, payload);
|
|
4067
|
+
if (output instanceof Promise) {
|
|
4068
|
+
return output.then((output2) => {
|
|
4069
|
+
payload.value = output2;
|
|
4070
|
+
return payload;
|
|
4071
|
+
});
|
|
4072
|
+
}
|
|
4073
|
+
payload.value = output;
|
|
4074
|
+
return payload;
|
|
4075
|
+
};
|
|
4076
|
+
});
|
|
4077
|
+
function transform(fn) {
|
|
4078
|
+
return new ZodTransform({
|
|
4079
|
+
type: "transform",
|
|
4080
|
+
transform: fn
|
|
4081
|
+
});
|
|
4082
|
+
}
|
|
4083
|
+
const ZodOptional = /* @__PURE__ */ $constructor("ZodOptional", (inst, def) => {
|
|
4084
|
+
$ZodOptional.init(inst, def);
|
|
4085
|
+
ZodType.init(inst, def);
|
|
4086
|
+
inst._zod.processJSONSchema = (ctx, json, params) => optionalProcessor(inst, ctx, json, params);
|
|
4087
|
+
inst.unwrap = () => inst._zod.def.innerType;
|
|
4088
|
+
});
|
|
4089
|
+
function optional(innerType) {
|
|
4090
|
+
return new ZodOptional({
|
|
4091
|
+
type: "optional",
|
|
4092
|
+
innerType
|
|
4093
|
+
});
|
|
4094
|
+
}
|
|
4095
|
+
const ZodExactOptional = /* @__PURE__ */ $constructor("ZodExactOptional", (inst, def) => {
|
|
4096
|
+
$ZodExactOptional.init(inst, def);
|
|
4097
|
+
ZodType.init(inst, def);
|
|
4098
|
+
inst._zod.processJSONSchema = (ctx, json, params) => optionalProcessor(inst, ctx, json, params);
|
|
4099
|
+
inst.unwrap = () => inst._zod.def.innerType;
|
|
4100
|
+
});
|
|
4101
|
+
function exactOptional(innerType) {
|
|
4102
|
+
return new ZodExactOptional({
|
|
4103
|
+
type: "optional",
|
|
4104
|
+
innerType
|
|
4105
|
+
});
|
|
4106
|
+
}
|
|
4107
|
+
const ZodNullable = /* @__PURE__ */ $constructor("ZodNullable", (inst, def) => {
|
|
4108
|
+
$ZodNullable.init(inst, def);
|
|
4109
|
+
ZodType.init(inst, def);
|
|
4110
|
+
inst._zod.processJSONSchema = (ctx, json, params) => nullableProcessor(inst, ctx, json, params);
|
|
4111
|
+
inst.unwrap = () => inst._zod.def.innerType;
|
|
4112
|
+
});
|
|
4113
|
+
function nullable(innerType) {
|
|
4114
|
+
return new ZodNullable({
|
|
4115
|
+
type: "nullable",
|
|
4116
|
+
innerType
|
|
4117
|
+
});
|
|
4118
|
+
}
|
|
4119
|
+
const ZodDefault = /* @__PURE__ */ $constructor("ZodDefault", (inst, def) => {
|
|
4120
|
+
$ZodDefault.init(inst, def);
|
|
4121
|
+
ZodType.init(inst, def);
|
|
4122
|
+
inst._zod.processJSONSchema = (ctx, json, params) => defaultProcessor(inst, ctx, json, params);
|
|
4123
|
+
inst.unwrap = () => inst._zod.def.innerType;
|
|
4124
|
+
inst.removeDefault = inst.unwrap;
|
|
4125
|
+
});
|
|
4126
|
+
function _default(innerType, defaultValue) {
|
|
4127
|
+
return new ZodDefault({
|
|
4128
|
+
type: "default",
|
|
4129
|
+
innerType,
|
|
4130
|
+
get defaultValue() {
|
|
4131
|
+
return typeof defaultValue === "function" ? defaultValue() : shallowClone(defaultValue);
|
|
4132
|
+
}
|
|
4133
|
+
});
|
|
4134
|
+
}
|
|
4135
|
+
const ZodPrefault = /* @__PURE__ */ $constructor("ZodPrefault", (inst, def) => {
|
|
4136
|
+
$ZodPrefault.init(inst, def);
|
|
4137
|
+
ZodType.init(inst, def);
|
|
4138
|
+
inst._zod.processJSONSchema = (ctx, json, params) => prefaultProcessor(inst, ctx, json, params);
|
|
4139
|
+
inst.unwrap = () => inst._zod.def.innerType;
|
|
4140
|
+
});
|
|
4141
|
+
function prefault(innerType, defaultValue) {
|
|
4142
|
+
return new ZodPrefault({
|
|
4143
|
+
type: "prefault",
|
|
4144
|
+
innerType,
|
|
4145
|
+
get defaultValue() {
|
|
4146
|
+
return typeof defaultValue === "function" ? defaultValue() : shallowClone(defaultValue);
|
|
4147
|
+
}
|
|
4148
|
+
});
|
|
4149
|
+
}
|
|
4150
|
+
const ZodNonOptional = /* @__PURE__ */ $constructor("ZodNonOptional", (inst, def) => {
|
|
4151
|
+
$ZodNonOptional.init(inst, def);
|
|
4152
|
+
ZodType.init(inst, def);
|
|
4153
|
+
inst._zod.processJSONSchema = (ctx, json, params) => nonoptionalProcessor(inst, ctx, json, params);
|
|
4154
|
+
inst.unwrap = () => inst._zod.def.innerType;
|
|
4155
|
+
});
|
|
4156
|
+
function nonoptional(innerType, params) {
|
|
4157
|
+
return new ZodNonOptional({
|
|
4158
|
+
type: "nonoptional",
|
|
4159
|
+
innerType,
|
|
4160
|
+
...normalizeParams(params)
|
|
4161
|
+
});
|
|
4162
|
+
}
|
|
4163
|
+
const ZodCatch = /* @__PURE__ */ $constructor("ZodCatch", (inst, def) => {
|
|
4164
|
+
$ZodCatch.init(inst, def);
|
|
4165
|
+
ZodType.init(inst, def);
|
|
4166
|
+
inst._zod.processJSONSchema = (ctx, json, params) => catchProcessor(inst, ctx, json, params);
|
|
4167
|
+
inst.unwrap = () => inst._zod.def.innerType;
|
|
4168
|
+
inst.removeCatch = inst.unwrap;
|
|
4169
|
+
});
|
|
4170
|
+
function _catch(innerType, catchValue) {
|
|
4171
|
+
return new ZodCatch({
|
|
4172
|
+
type: "catch",
|
|
4173
|
+
innerType,
|
|
4174
|
+
catchValue: typeof catchValue === "function" ? catchValue : () => catchValue
|
|
4175
|
+
});
|
|
4176
|
+
}
|
|
4177
|
+
const ZodPipe = /* @__PURE__ */ $constructor("ZodPipe", (inst, def) => {
|
|
4178
|
+
$ZodPipe.init(inst, def);
|
|
4179
|
+
ZodType.init(inst, def);
|
|
4180
|
+
inst._zod.processJSONSchema = (ctx, json, params) => pipeProcessor(inst, ctx, json, params);
|
|
4181
|
+
inst.in = def.in;
|
|
4182
|
+
inst.out = def.out;
|
|
4183
|
+
});
|
|
4184
|
+
function pipe(in_, out) {
|
|
4185
|
+
return new ZodPipe({
|
|
4186
|
+
type: "pipe",
|
|
4187
|
+
in: in_,
|
|
4188
|
+
out
|
|
4189
|
+
// ...util.normalizeParams(params),
|
|
4190
|
+
});
|
|
4191
|
+
}
|
|
4192
|
+
const ZodReadonly = /* @__PURE__ */ $constructor("ZodReadonly", (inst, def) => {
|
|
4193
|
+
$ZodReadonly.init(inst, def);
|
|
4194
|
+
ZodType.init(inst, def);
|
|
4195
|
+
inst._zod.processJSONSchema = (ctx, json, params) => readonlyProcessor(inst, ctx, json, params);
|
|
4196
|
+
inst.unwrap = () => inst._zod.def.innerType;
|
|
4197
|
+
});
|
|
4198
|
+
function readonly(innerType) {
|
|
4199
|
+
return new ZodReadonly({
|
|
4200
|
+
type: "readonly",
|
|
4201
|
+
innerType
|
|
4202
|
+
});
|
|
4203
|
+
}
|
|
4204
|
+
const ZodCustom = /* @__PURE__ */ $constructor("ZodCustom", (inst, def) => {
|
|
4205
|
+
$ZodCustom.init(inst, def);
|
|
4206
|
+
ZodType.init(inst, def);
|
|
4207
|
+
inst._zod.processJSONSchema = (ctx, json, params) => customProcessor(inst, ctx);
|
|
4208
|
+
});
|
|
4209
|
+
function refine(fn, _params = {}) {
|
|
4210
|
+
return /* @__PURE__ */ _refine(ZodCustom, fn, _params);
|
|
4211
|
+
}
|
|
4212
|
+
function superRefine(fn) {
|
|
4213
|
+
return /* @__PURE__ */ _superRefine(fn);
|
|
4214
|
+
}
|
|
4215
|
+
export {
|
|
4216
|
+
_enum as _,
|
|
4217
|
+
array as a,
|
|
4218
|
+
boolean as b,
|
|
4219
|
+
number as n,
|
|
4220
|
+
object as o,
|
|
4221
|
+
record as r,
|
|
4222
|
+
string as s
|
|
4223
|
+
};
|