hermium 0.1.9 → 0.2.0

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