@opentiny/next-sdk 0.3.3 → 0.4.1

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 (134) hide show
  1. package/agent/AgentModelProvider.ts +78 -81
  2. package/agent/type.ts +6 -9
  3. package/agent/utils/getAISDKTools.ts +0 -1
  4. package/agent/utils/getBuiltinMcpTools.ts +7 -7
  5. package/core.ts +1 -3
  6. package/dist/SimulatorMask-BHVXyogh-iNUb4dyF.js +361 -0
  7. package/dist/agent/type.d.ts +4 -12
  8. package/dist/agent/utils/getBuiltinMcpTools.d.ts +3 -3
  9. package/dist/core.d.ts +1 -1
  10. package/dist/core.js +18 -18
  11. package/dist/index-CXK8CcKq.js +6076 -0
  12. package/dist/index.d.ts +2 -4
  13. package/dist/index.js +57 -2783
  14. package/dist/initialize-builtin-WebMCP-rALfqS-o.js +6389 -0
  15. package/dist/page-tools/a11y/build.d.ts +11 -0
  16. package/dist/page-tools/a11y/constants.d.ts +9 -0
  17. package/dist/page-tools/a11y/search.d.ts +17 -0
  18. package/dist/page-tools/a11y/types.d.ts +104 -0
  19. package/dist/page-tools/a11y/utils.d.ts +34 -0
  20. package/dist/page-tools/a11y/vnode.d.ts +37 -0
  21. package/dist/page-tools/a11y-tree.d.ts +12 -0
  22. package/dist/page-tools/bridge.d.ts +0 -6
  23. package/dist/page-tools/constants.d.ts +22 -0
  24. package/dist/page-tools/context.d.ts +28 -0
  25. package/dist/page-tools/handlers/browserState.d.ts +8 -0
  26. package/dist/page-tools/handlers/click.d.ts +8 -0
  27. package/dist/page-tools/handlers/executeJavascript.d.ts +8 -0
  28. package/dist/page-tools/handlers/fill.d.ts +8 -0
  29. package/dist/page-tools/handlers/scroll.d.ts +8 -0
  30. package/dist/page-tools/handlers/searchTree.d.ts +8 -0
  31. package/dist/page-tools/handlers/select.d.ts +8 -0
  32. package/dist/page-tools/initialize-builtin-WebMCP.d.ts +1 -0
  33. package/dist/page-tools/page-agent-highlight/index.d.ts +9 -0
  34. package/dist/page-tools/page-agent-mask/SimulatorMask.d.ts +14 -0
  35. package/dist/page-tools/page-agent-mask/checkDarkMode.d.ts +5 -0
  36. package/dist/page-tools/page-agent-tool.d.ts +4 -0
  37. package/dist/page-tools/page-state-cache.d.ts +36 -0
  38. package/dist/page-tools/schema.d.ts +43 -0
  39. package/dist/page-tools/utils/dom.d.ts +6 -0
  40. package/dist/page-tools/utils/scroll.d.ts +15 -0
  41. package/dist/runtime.d.ts +4 -0
  42. package/dist/runtime.js +744 -0
  43. package/dist/utils/builtinProxy.d.ts +1 -1
  44. package/index.ts +2 -19
  45. package/package.json +14 -18
  46. package/page-tools/a11y/build.ts +70 -0
  47. package/page-tools/a11y/constants.ts +110 -0
  48. package/page-tools/a11y/search.ts +129 -0
  49. package/page-tools/a11y/types.ts +108 -0
  50. package/page-tools/a11y/utils.ts +266 -0
  51. package/page-tools/a11y/vnode.ts +229 -0
  52. package/page-tools/a11y-tree.ts +13 -0
  53. package/page-tools/bridge.ts +49 -15
  54. package/page-tools/constants.ts +72 -0
  55. package/page-tools/context.ts +13 -0
  56. package/page-tools/handlers/browserState.ts +12 -0
  57. package/page-tools/handlers/click.ts +26 -0
  58. package/page-tools/handlers/executeJavascript.ts +22 -0
  59. package/page-tools/handlers/fill.ts +60 -0
  60. package/page-tools/handlers/scroll.ts +66 -0
  61. package/page-tools/handlers/searchTree.ts +30 -0
  62. package/page-tools/handlers/select.ts +34 -0
  63. package/page-tools/initialize-builtin-WebMCP.ts +20 -0
  64. package/page-tools/page-agent-highlight/index.ts +198 -0
  65. package/page-tools/page-agent-mask/SimulatorMask.module.css +14 -0
  66. package/page-tools/page-agent-mask/SimulatorMask.ts +279 -0
  67. package/page-tools/page-agent-mask/checkDarkMode.ts +181 -0
  68. package/page-tools/page-agent-mask/cursor-border.svg +3 -0
  69. package/page-tools/page-agent-mask/cursor-fill.svg +5 -0
  70. package/page-tools/page-agent-mask/cursor.module.css +70 -0
  71. package/page-tools/page-agent-prompt.md +139 -0
  72. package/page-tools/page-agent-tool.ts +175 -0
  73. package/page-tools/page-state-cache.ts +78 -0
  74. package/page-tools/schema.ts +51 -0
  75. package/page-tools/utils/dom.ts +155 -0
  76. package/page-tools/utils/scroll.ts +58 -0
  77. package/runtime.ts +13 -0
  78. package/utils/builtinProxy.ts +45 -13
  79. package/vite.config.runtime.ts +22 -0
  80. package/vite.config.ts +52 -8
  81. package/McpSdk.ts +0 -14
  82. package/WebAgent.ts +0 -5
  83. package/WebMcp.ts +0 -20
  84. package/Zod.ts +0 -1
  85. package/dist/AgentModelProvider-CwqOT28f.js +0 -4198
  86. package/dist/McpSdk.d.ts +0 -14
  87. package/dist/WebAgent.d.ts +0 -5
  88. package/dist/WebMcp.d.ts +0 -20
  89. package/dist/Zod.d.ts +0 -1
  90. package/dist/index.es.dev.js +0 -53427
  91. package/dist/index.es.js +0 -42147
  92. package/dist/index.umd.dev.js +0 -53820
  93. package/dist/index.umd.js +0 -814
  94. package/dist/mcpsdk@1.25.3.dev.js +0 -22621
  95. package/dist/mcpsdk@1.25.3.es.dev.js +0 -22619
  96. package/dist/mcpsdk@1.25.3.es.js +0 -16802
  97. package/dist/mcpsdk@1.25.3.js +0 -43
  98. package/dist/transport/ExtensionClientTransport.d.ts +0 -24
  99. package/dist/transport/ExtensionContentServerTransport.d.ts +0 -39
  100. package/dist/transport/ExtensionPageServerTransport.d.ts +0 -36
  101. package/dist/transport/messages.d.ts +0 -9
  102. package/dist/vite.config.mcpSdk.d.ts +0 -2
  103. package/dist/vite.config.webAgent.d.ts +0 -2
  104. package/dist/vite.config.webMcp.d.ts +0 -2
  105. package/dist/vite.config.webMcpFull.d.ts +0 -2
  106. package/dist/vite.config.zod.d.ts +0 -2
  107. package/dist/webagent.dev.js +0 -47597
  108. package/dist/webagent.es.dev.js +0 -47204
  109. package/dist/webagent.es.js +0 -37494
  110. package/dist/webagent.js +0 -634
  111. package/dist/webmcp-full.dev.js +0 -24430
  112. package/dist/webmcp-full.es.dev.js +0 -24426
  113. package/dist/webmcp-full.es.js +0 -18333
  114. package/dist/webmcp-full.js +0 -43
  115. package/dist/webmcp.dev.js +0 -1595
  116. package/dist/webmcp.es.dev.js +0 -1589
  117. package/dist/webmcp.es.js +0 -1406
  118. package/dist/webmcp.js +0 -1
  119. package/dist/zod@3.25.76.dev.js +0 -4037
  120. package/dist/zod@3.25.76.es.dev.js +0 -4033
  121. package/dist/zod@3.25.76.es.js +0 -2945
  122. package/dist/zod@3.25.76.js +0 -1
  123. package/transport/ExtensionClientTransport.ts +0 -100
  124. package/transport/ExtensionContentServerTransport.ts +0 -162
  125. package/transport/ExtensionPageServerTransport.ts +0 -149
  126. package/transport/messages.ts +0 -63
  127. package/vite-build-tsc.ts +0 -63
  128. package/vite-env.d.ts +0 -5
  129. package/vite.config.mcpSdk.ts +0 -28
  130. package/vite.config.webAgent.ts +0 -19
  131. package/vite.config.webMcp.ts +0 -40
  132. package/vite.config.webMcpFull.ts +0 -19
  133. package/vite.config.zod.ts +0 -23
  134. /package/dist/{vite-build-tsc.d.ts → vite.config.runtime.d.ts} +0 -0
@@ -1,2945 +0,0 @@
1
- var v;
2
- (function(r) {
3
- r.assertEqual = (n) => {
4
- };
5
- function e(n) {
6
- }
7
- r.assertIs = e;
8
- function t(n) {
9
- throw new Error();
10
- }
11
- r.assertNever = t, r.arrayToEnum = (n) => {
12
- const a = {};
13
- for (const i of n)
14
- a[i] = i;
15
- return a;
16
- }, r.getValidEnumValues = (n) => {
17
- const a = r.objectKeys(n).filter((o) => typeof n[n[o]] != "number"), i = {};
18
- for (const o of a)
19
- i[o] = n[o];
20
- return r.objectValues(i);
21
- }, r.objectValues = (n) => r.objectKeys(n).map(function(a) {
22
- return n[a];
23
- }), r.objectKeys = typeof Object.keys == "function" ? (n) => Object.keys(n) : (n) => {
24
- const a = [];
25
- for (const i in n)
26
- Object.prototype.hasOwnProperty.call(n, i) && a.push(i);
27
- return a;
28
- }, r.find = (n, a) => {
29
- for (const i of n)
30
- if (a(i))
31
- return i;
32
- }, r.isInteger = typeof Number.isInteger == "function" ? (n) => Number.isInteger(n) : (n) => typeof n == "number" && Number.isFinite(n) && Math.floor(n) === n;
33
- function s(n, a = " | ") {
34
- return n.map((i) => typeof i == "string" ? `'${i}'` : i).join(a);
35
- }
36
- r.joinValues = s, r.jsonStringifyReplacer = (n, a) => typeof a == "bigint" ? a.toString() : a;
37
- })(v || (v = {}));
38
- var _e;
39
- (function(r) {
40
- r.mergeShapes = (e, t) => ({
41
- ...e,
42
- ...t
43
- // second overwrites first
44
- });
45
- })(_e || (_e = {}));
46
- const u = v.arrayToEnum([
47
- "string",
48
- "nan",
49
- "number",
50
- "integer",
51
- "float",
52
- "boolean",
53
- "date",
54
- "bigint",
55
- "symbol",
56
- "function",
57
- "undefined",
58
- "null",
59
- "array",
60
- "object",
61
- "unknown",
62
- "promise",
63
- "void",
64
- "never",
65
- "map",
66
- "set"
67
- ]), j = (r) => {
68
- switch (typeof r) {
69
- case "undefined":
70
- return u.undefined;
71
- case "string":
72
- return u.string;
73
- case "number":
74
- return Number.isNaN(r) ? u.nan : u.number;
75
- case "boolean":
76
- return u.boolean;
77
- case "function":
78
- return u.function;
79
- case "bigint":
80
- return u.bigint;
81
- case "symbol":
82
- return u.symbol;
83
- case "object":
84
- return Array.isArray(r) ? u.array : r === null ? u.null : r.then && typeof r.then == "function" && r.catch && typeof r.catch == "function" ? u.promise : typeof Map < "u" && r instanceof Map ? u.map : typeof Set < "u" && r instanceof Set ? u.set : typeof Date < "u" && r instanceof Date ? u.date : u.object;
85
- default:
86
- return u.unknown;
87
- }
88
- }, c = v.arrayToEnum([
89
- "invalid_type",
90
- "invalid_literal",
91
- "custom",
92
- "invalid_union",
93
- "invalid_union_discriminator",
94
- "invalid_enum_value",
95
- "unrecognized_keys",
96
- "invalid_arguments",
97
- "invalid_return_type",
98
- "invalid_date",
99
- "invalid_string",
100
- "too_small",
101
- "too_big",
102
- "invalid_intersection_types",
103
- "not_multiple_of",
104
- "not_finite"
105
- ]), $e = (r) => JSON.stringify(r, null, 2).replace(/"([^"]+)":/g, "$1:");
106
- class w extends Error {
107
- get errors() {
108
- return this.issues;
109
- }
110
- constructor(e) {
111
- super(), this.issues = [], this.addIssue = (s) => {
112
- this.issues = [...this.issues, s];
113
- }, this.addIssues = (s = []) => {
114
- this.issues = [...this.issues, ...s];
115
- };
116
- const t = new.target.prototype;
117
- Object.setPrototypeOf ? Object.setPrototypeOf(this, t) : this.__proto__ = t, this.name = "ZodError", this.issues = e;
118
- }
119
- format(e) {
120
- const t = e || function(a) {
121
- return a.message;
122
- }, s = { _errors: [] }, n = (a) => {
123
- for (const i of a.issues)
124
- if (i.code === "invalid_union")
125
- i.unionErrors.map(n);
126
- else if (i.code === "invalid_return_type")
127
- n(i.returnTypeError);
128
- else if (i.code === "invalid_arguments")
129
- n(i.argumentsError);
130
- else if (i.path.length === 0)
131
- s._errors.push(t(i));
132
- else {
133
- let o = s, f = 0;
134
- for (; f < i.path.length; ) {
135
- const l = i.path[f];
136
- f === i.path.length - 1 ? (o[l] = o[l] || { _errors: [] }, o[l]._errors.push(t(i))) : o[l] = o[l] || { _errors: [] }, o = o[l], f++;
137
- }
138
- }
139
- };
140
- return n(this), s;
141
- }
142
- static assert(e) {
143
- if (!(e instanceof w))
144
- throw new Error(`Not a ZodError: ${e}`);
145
- }
146
- toString() {
147
- return this.message;
148
- }
149
- get message() {
150
- return JSON.stringify(this.issues, v.jsonStringifyReplacer, 2);
151
- }
152
- get isEmpty() {
153
- return this.issues.length === 0;
154
- }
155
- flatten(e = (t) => t.message) {
156
- const t = {}, s = [];
157
- for (const n of this.issues)
158
- if (n.path.length > 0) {
159
- const a = n.path[0];
160
- t[a] = t[a] || [], t[a].push(e(n));
161
- } else
162
- s.push(e(n));
163
- return { formErrors: s, fieldErrors: t };
164
- }
165
- get formErrors() {
166
- return this.flatten();
167
- }
168
- }
169
- w.create = (r) => new w(r);
170
- const W = (r, e) => {
171
- let t;
172
- switch (r.code) {
173
- case c.invalid_type:
174
- r.received === u.undefined ? t = "Required" : t = `Expected ${r.expected}, received ${r.received}`;
175
- break;
176
- case c.invalid_literal:
177
- t = `Invalid literal value, expected ${JSON.stringify(r.expected, v.jsonStringifyReplacer)}`;
178
- break;
179
- case c.unrecognized_keys:
180
- t = `Unrecognized key(s) in object: ${v.joinValues(r.keys, ", ")}`;
181
- break;
182
- case c.invalid_union:
183
- t = "Invalid input";
184
- break;
185
- case c.invalid_union_discriminator:
186
- t = `Invalid discriminator value. Expected ${v.joinValues(r.options)}`;
187
- break;
188
- case c.invalid_enum_value:
189
- t = `Invalid enum value. Expected ${v.joinValues(r.options)}, received '${r.received}'`;
190
- break;
191
- case c.invalid_arguments:
192
- t = "Invalid function arguments";
193
- break;
194
- case c.invalid_return_type:
195
- t = "Invalid function return type";
196
- break;
197
- case c.invalid_date:
198
- t = "Invalid date";
199
- break;
200
- case c.invalid_string:
201
- typeof r.validation == "object" ? "includes" in r.validation ? (t = `Invalid input: must include "${r.validation.includes}"`, typeof r.validation.position == "number" && (t = `${t} at one or more positions greater than or equal to ${r.validation.position}`)) : "startsWith" in r.validation ? t = `Invalid input: must start with "${r.validation.startsWith}"` : "endsWith" in r.validation ? t = `Invalid input: must end with "${r.validation.endsWith}"` : v.assertNever(r.validation) : r.validation !== "regex" ? t = `Invalid ${r.validation}` : t = "Invalid";
202
- break;
203
- case c.too_small:
204
- r.type === "array" ? t = `Array must contain ${r.exact ? "exactly" : r.inclusive ? "at least" : "more than"} ${r.minimum} element(s)` : r.type === "string" ? t = `String must contain ${r.exact ? "exactly" : r.inclusive ? "at least" : "over"} ${r.minimum} character(s)` : r.type === "number" ? t = `Number must be ${r.exact ? "exactly equal to " : r.inclusive ? "greater than or equal to " : "greater than "}${r.minimum}` : r.type === "bigint" ? t = `Number must be ${r.exact ? "exactly equal to " : r.inclusive ? "greater than or equal to " : "greater than "}${r.minimum}` : r.type === "date" ? t = `Date must be ${r.exact ? "exactly equal to " : r.inclusive ? "greater than or equal to " : "greater than "}${new Date(Number(r.minimum))}` : t = "Invalid input";
205
- break;
206
- case c.too_big:
207
- r.type === "array" ? t = `Array must contain ${r.exact ? "exactly" : r.inclusive ? "at most" : "less than"} ${r.maximum} element(s)` : r.type === "string" ? t = `String must contain ${r.exact ? "exactly" : r.inclusive ? "at most" : "under"} ${r.maximum} character(s)` : r.type === "number" ? t = `Number must be ${r.exact ? "exactly" : r.inclusive ? "less than or equal to" : "less than"} ${r.maximum}` : r.type === "bigint" ? t = `BigInt must be ${r.exact ? "exactly" : r.inclusive ? "less than or equal to" : "less than"} ${r.maximum}` : r.type === "date" ? t = `Date must be ${r.exact ? "exactly" : r.inclusive ? "smaller than or equal to" : "smaller than"} ${new Date(Number(r.maximum))}` : t = "Invalid input";
208
- break;
209
- case c.custom:
210
- t = "Invalid input";
211
- break;
212
- case c.invalid_intersection_types:
213
- t = "Intersection results could not be merged";
214
- break;
215
- case c.not_multiple_of:
216
- t = `Number must be a multiple of ${r.multipleOf}`;
217
- break;
218
- case c.not_finite:
219
- t = "Number must be finite";
220
- break;
221
- default:
222
- t = e.defaultError, v.assertNever(r);
223
- }
224
- return { message: t };
225
- };
226
- let Se = W;
227
- function Me(r) {
228
- Se = r;
229
- }
230
- function ce() {
231
- return Se;
232
- }
233
- const de = (r) => {
234
- const { data: e, path: t, errorMaps: s, issueData: n } = r, a = [...t, ...n.path || []], i = {
235
- ...n,
236
- path: a
237
- };
238
- if (n.message !== void 0)
239
- return {
240
- ...n,
241
- path: a,
242
- message: n.message
243
- };
244
- let o = "";
245
- const f = s.filter((l) => !!l).slice().reverse();
246
- for (const l of f)
247
- o = l(i, { data: e, defaultError: o }).message;
248
- return {
249
- ...n,
250
- path: a,
251
- message: o
252
- };
253
- }, Ve = [];
254
- function d(r, e) {
255
- const t = ce(), s = de({
256
- issueData: e,
257
- data: r.data,
258
- path: r.path,
259
- errorMaps: [
260
- r.common.contextualErrorMap,
261
- // contextual error map is first priority
262
- r.schemaErrorMap,
263
- // then schema-bound map if available
264
- t,
265
- // then global override map
266
- t === W ? void 0 : W
267
- // then global default map
268
- ].filter((n) => !!n)
269
- });
270
- r.common.issues.push(s);
271
- }
272
- class k {
273
- constructor() {
274
- this.value = "valid";
275
- }
276
- dirty() {
277
- this.value === "valid" && (this.value = "dirty");
278
- }
279
- abort() {
280
- this.value !== "aborted" && (this.value = "aborted");
281
- }
282
- static mergeArray(e, t) {
283
- const s = [];
284
- for (const n of t) {
285
- if (n.status === "aborted")
286
- return p;
287
- n.status === "dirty" && e.dirty(), s.push(n.value);
288
- }
289
- return { status: e.value, value: s };
290
- }
291
- static async mergeObjectAsync(e, t) {
292
- const s = [];
293
- for (const n of t) {
294
- const a = await n.key, i = await n.value;
295
- s.push({
296
- key: a,
297
- value: i
298
- });
299
- }
300
- return k.mergeObjectSync(e, s);
301
- }
302
- static mergeObjectSync(e, t) {
303
- const s = {};
304
- for (const n of t) {
305
- const { key: a, value: i } = n;
306
- if (a.status === "aborted" || i.status === "aborted")
307
- return p;
308
- a.status === "dirty" && e.dirty(), i.status === "dirty" && e.dirty(), a.value !== "__proto__" && (typeof i.value < "u" || n.alwaysSet) && (s[a.value] = i.value);
309
- }
310
- return { status: e.value, value: s };
311
- }
312
- }
313
- const p = Object.freeze({
314
- status: "aborted"
315
- }), B = (r) => ({ status: "dirty", value: r }), b = (r) => ({ status: "valid", value: r }), ge = (r) => r.status === "aborted", ve = (r) => r.status === "dirty", z = (r) => r.status === "valid", Y = (r) => typeof Promise < "u" && r instanceof Promise;
316
- var h;
317
- (function(r) {
318
- r.errToObj = (e) => typeof e == "string" ? { message: e } : e || {}, r.toString = (e) => typeof e == "string" ? e : e?.message;
319
- })(h || (h = {}));
320
- class N {
321
- constructor(e, t, s, n) {
322
- this._cachedPath = [], this.parent = e, this.data = t, this._path = s, this._key = n;
323
- }
324
- get path() {
325
- return this._cachedPath.length || (Array.isArray(this._key) ? this._cachedPath.push(...this._path, ...this._key) : this._cachedPath.push(...this._path, this._key)), this._cachedPath;
326
- }
327
- }
328
- const we = (r, e) => {
329
- if (z(e))
330
- return { success: !0, data: e.value };
331
- if (!r.common.issues.length)
332
- throw new Error("Validation failed but no issues detected.");
333
- return {
334
- success: !1,
335
- get error() {
336
- if (this._error)
337
- return this._error;
338
- const t = new w(r.common.issues);
339
- return this._error = t, this._error;
340
- }
341
- };
342
- };
343
- function y(r) {
344
- if (!r)
345
- return {};
346
- const { errorMap: e, invalid_type_error: t, required_error: s, description: n } = r;
347
- if (e && (t || s))
348
- throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
349
- return e ? { errorMap: e, description: n } : { errorMap: (i, o) => {
350
- const { message: f } = r;
351
- return i.code === "invalid_enum_value" ? { message: f ?? o.defaultError } : typeof o.data > "u" ? { message: f ?? s ?? o.defaultError } : i.code !== "invalid_type" ? { message: o.defaultError } : { message: f ?? t ?? o.defaultError };
352
- }, description: n };
353
- }
354
- class _ {
355
- get description() {
356
- return this._def.description;
357
- }
358
- _getType(e) {
359
- return j(e.data);
360
- }
361
- _getOrReturnCtx(e, t) {
362
- return t || {
363
- common: e.parent.common,
364
- data: e.data,
365
- parsedType: j(e.data),
366
- schemaErrorMap: this._def.errorMap,
367
- path: e.path,
368
- parent: e.parent
369
- };
370
- }
371
- _processInputParams(e) {
372
- return {
373
- status: new k(),
374
- ctx: {
375
- common: e.parent.common,
376
- data: e.data,
377
- parsedType: j(e.data),
378
- schemaErrorMap: this._def.errorMap,
379
- path: e.path,
380
- parent: e.parent
381
- }
382
- };
383
- }
384
- _parseSync(e) {
385
- const t = this._parse(e);
386
- if (Y(t))
387
- throw new Error("Synchronous parse encountered promise.");
388
- return t;
389
- }
390
- _parseAsync(e) {
391
- const t = this._parse(e);
392
- return Promise.resolve(t);
393
- }
394
- parse(e, t) {
395
- const s = this.safeParse(e, t);
396
- if (s.success)
397
- return s.data;
398
- throw s.error;
399
- }
400
- safeParse(e, t) {
401
- const s = {
402
- common: {
403
- issues: [],
404
- async: t?.async ?? !1,
405
- contextualErrorMap: t?.errorMap
406
- },
407
- path: t?.path || [],
408
- schemaErrorMap: this._def.errorMap,
409
- parent: null,
410
- data: e,
411
- parsedType: j(e)
412
- }, n = this._parseSync({ data: e, path: s.path, parent: s });
413
- return we(s, n);
414
- }
415
- "~validate"(e) {
416
- const t = {
417
- common: {
418
- issues: [],
419
- async: !!this["~standard"].async
420
- },
421
- path: [],
422
- schemaErrorMap: this._def.errorMap,
423
- parent: null,
424
- data: e,
425
- parsedType: j(e)
426
- };
427
- if (!this["~standard"].async)
428
- try {
429
- const s = this._parseSync({ data: e, path: [], parent: t });
430
- return z(s) ? {
431
- value: s.value
432
- } : {
433
- issues: t.common.issues
434
- };
435
- } catch (s) {
436
- s?.message?.toLowerCase()?.includes("encountered") && (this["~standard"].async = !0), t.common = {
437
- issues: [],
438
- async: !0
439
- };
440
- }
441
- return this._parseAsync({ data: e, path: [], parent: t }).then((s) => z(s) ? {
442
- value: s.value
443
- } : {
444
- issues: t.common.issues
445
- });
446
- }
447
- async parseAsync(e, t) {
448
- const s = await this.safeParseAsync(e, t);
449
- if (s.success)
450
- return s.data;
451
- throw s.error;
452
- }
453
- async safeParseAsync(e, t) {
454
- const s = {
455
- common: {
456
- issues: [],
457
- contextualErrorMap: t?.errorMap,
458
- async: !0
459
- },
460
- path: t?.path || [],
461
- schemaErrorMap: this._def.errorMap,
462
- parent: null,
463
- data: e,
464
- parsedType: j(e)
465
- }, n = this._parse({ data: e, path: s.path, parent: s }), a = await (Y(n) ? n : Promise.resolve(n));
466
- return we(s, a);
467
- }
468
- refine(e, t) {
469
- const s = (n) => typeof t == "string" || typeof t > "u" ? { message: t } : typeof t == "function" ? t(n) : t;
470
- return this._refinement((n, a) => {
471
- const i = e(n), o = () => a.addIssue({
472
- code: c.custom,
473
- ...s(n)
474
- });
475
- return typeof Promise < "u" && i instanceof Promise ? i.then((f) => f ? !0 : (o(), !1)) : i ? !0 : (o(), !1);
476
- });
477
- }
478
- refinement(e, t) {
479
- return this._refinement((s, n) => e(s) ? !0 : (n.addIssue(typeof t == "function" ? t(s, n) : t), !1));
480
- }
481
- _refinement(e) {
482
- return new O({
483
- schema: this,
484
- typeName: m.ZodEffects,
485
- effect: { type: "refinement", refinement: e }
486
- });
487
- }
488
- superRefine(e) {
489
- return this._refinement(e);
490
- }
491
- constructor(e) {
492
- this.spa = this.safeParseAsync, this._def = e, this.parse = this.parse.bind(this), this.safeParse = this.safeParse.bind(this), this.parseAsync = this.parseAsync.bind(this), this.safeParseAsync = this.safeParseAsync.bind(this), this.spa = this.spa.bind(this), this.refine = this.refine.bind(this), this.refinement = this.refinement.bind(this), this.superRefine = this.superRefine.bind(this), this.optional = this.optional.bind(this), this.nullable = this.nullable.bind(this), this.nullish = this.nullish.bind(this), this.array = this.array.bind(this), this.promise = this.promise.bind(this), this.or = this.or.bind(this), this.and = this.and.bind(this), this.transform = this.transform.bind(this), this.brand = this.brand.bind(this), this.default = this.default.bind(this), this.catch = this.catch.bind(this), this.describe = this.describe.bind(this), this.pipe = this.pipe.bind(this), this.readonly = this.readonly.bind(this), this.isNullable = this.isNullable.bind(this), this.isOptional = this.isOptional.bind(this), this["~standard"] = {
493
- version: 1,
494
- vendor: "zod",
495
- validate: (t) => this["~validate"](t)
496
- };
497
- }
498
- optional() {
499
- return A.create(this, this._def);
500
- }
501
- nullable() {
502
- return V.create(this, this._def);
503
- }
504
- nullish() {
505
- return this.nullable().optional();
506
- }
507
- array() {
508
- return S.create(this);
509
- }
510
- promise() {
511
- return J.create(this, this._def);
512
- }
513
- or(e) {
514
- return X.create([this, e], this._def);
515
- }
516
- and(e) {
517
- return K.create(this, e, this._def);
518
- }
519
- transform(e) {
520
- return new O({
521
- ...y(this._def),
522
- schema: this,
523
- typeName: m.ZodEffects,
524
- effect: { type: "transform", transform: e }
525
- });
526
- }
527
- default(e) {
528
- const t = typeof e == "function" ? e : () => e;
529
- return new ne({
530
- ...y(this._def),
531
- innerType: this,
532
- defaultValue: t,
533
- typeName: m.ZodDefault
534
- });
535
- }
536
- brand() {
537
- return new ke({
538
- typeName: m.ZodBranded,
539
- type: this,
540
- ...y(this._def)
541
- });
542
- }
543
- catch(e) {
544
- const t = typeof e == "function" ? e : () => e;
545
- return new ae({
546
- ...y(this._def),
547
- innerType: this,
548
- catchValue: t,
549
- typeName: m.ZodCatch
550
- });
551
- }
552
- describe(e) {
553
- const t = this.constructor;
554
- return new t({
555
- ...this._def,
556
- description: e
557
- });
558
- }
559
- pipe(e) {
560
- return oe.create(this, e);
561
- }
562
- readonly() {
563
- return ie.create(this);
564
- }
565
- isOptional() {
566
- return this.safeParse(void 0).success;
567
- }
568
- isNullable() {
569
- return this.safeParse(null).success;
570
- }
571
- }
572
- const Pe = /^c[^\s-]{8,}$/i, ze = /^[0-9a-z]+$/, Le = /^[0-9A-HJKMNP-TV-Z]{26}$/i, De = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i, Ue = /^[a-z0-9_-]{21}$/i, Be = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/, Fe = /^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/, We = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i, qe = "^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";
573
- let ye;
574
- const Je = /^(?:(?: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])$/, Ye = /^(?:(?: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])\/(3[0-2]|[12]?[0-9])$/, He = /^(([0-9a-fA-F]{1,4}:){7,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}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/, Ge = /^(([0-9a-fA-F]{1,4}:){7,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}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/, Qe = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/, Xe = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/, Oe = "((\\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])))", Ke = new RegExp(`^${Oe}$`);
575
- function Ae(r) {
576
- let e = "[0-5]\\d";
577
- r.precision ? e = `${e}\\.\\d{${r.precision}}` : r.precision == null && (e = `${e}(\\.\\d+)?`);
578
- const t = r.precision ? "+" : "?";
579
- return `([01]\\d|2[0-3]):[0-5]\\d(:${e})${t}`;
580
- }
581
- function et(r) {
582
- return new RegExp(`^${Ae(r)}$`);
583
- }
584
- function Ne(r) {
585
- let e = `${Oe}T${Ae(r)}`;
586
- const t = [];
587
- return t.push(r.local ? "Z?" : "Z"), r.offset && t.push("([+-]\\d{2}:?\\d{2})"), e = `${e}(${t.join("|")})`, new RegExp(`^${e}$`);
588
- }
589
- function tt(r, e) {
590
- return !!((e === "v4" || !e) && Je.test(r) || (e === "v6" || !e) && He.test(r));
591
- }
592
- function rt(r, e) {
593
- if (!Be.test(r))
594
- return !1;
595
- try {
596
- const [t] = r.split(".");
597
- if (!t)
598
- return !1;
599
- const s = t.replace(/-/g, "+").replace(/_/g, "/").padEnd(t.length + (4 - t.length % 4) % 4, "="), n = JSON.parse(atob(s));
600
- return !(typeof n != "object" || n === null || "typ" in n && n?.typ !== "JWT" || !n.alg || e && n.alg !== e);
601
- } catch {
602
- return !1;
603
- }
604
- }
605
- function st(r, e) {
606
- return !!((e === "v4" || !e) && Ye.test(r) || (e === "v6" || !e) && Ge.test(r));
607
- }
608
- class C extends _ {
609
- _parse(e) {
610
- if (this._def.coerce && (e.data = String(e.data)), this._getType(e) !== u.string) {
611
- const a = this._getOrReturnCtx(e);
612
- return d(a, {
613
- code: c.invalid_type,
614
- expected: u.string,
615
- received: a.parsedType
616
- }), p;
617
- }
618
- const s = new k();
619
- let n;
620
- for (const a of this._def.checks)
621
- if (a.kind === "min")
622
- e.data.length < a.value && (n = this._getOrReturnCtx(e, n), d(n, {
623
- code: c.too_small,
624
- minimum: a.value,
625
- type: "string",
626
- inclusive: !0,
627
- exact: !1,
628
- message: a.message
629
- }), s.dirty());
630
- else if (a.kind === "max")
631
- e.data.length > a.value && (n = this._getOrReturnCtx(e, n), d(n, {
632
- code: c.too_big,
633
- maximum: a.value,
634
- type: "string",
635
- inclusive: !0,
636
- exact: !1,
637
- message: a.message
638
- }), s.dirty());
639
- else if (a.kind === "length") {
640
- const i = e.data.length > a.value, o = e.data.length < a.value;
641
- (i || o) && (n = this._getOrReturnCtx(e, n), i ? d(n, {
642
- code: c.too_big,
643
- maximum: a.value,
644
- type: "string",
645
- inclusive: !0,
646
- exact: !0,
647
- message: a.message
648
- }) : o && d(n, {
649
- code: c.too_small,
650
- minimum: a.value,
651
- type: "string",
652
- inclusive: !0,
653
- exact: !0,
654
- message: a.message
655
- }), s.dirty());
656
- } else if (a.kind === "email")
657
- We.test(e.data) || (n = this._getOrReturnCtx(e, n), d(n, {
658
- validation: "email",
659
- code: c.invalid_string,
660
- message: a.message
661
- }), s.dirty());
662
- else if (a.kind === "emoji")
663
- ye || (ye = new RegExp(qe, "u")), ye.test(e.data) || (n = this._getOrReturnCtx(e, n), d(n, {
664
- validation: "emoji",
665
- code: c.invalid_string,
666
- message: a.message
667
- }), s.dirty());
668
- else if (a.kind === "uuid")
669
- De.test(e.data) || (n = this._getOrReturnCtx(e, n), d(n, {
670
- validation: "uuid",
671
- code: c.invalid_string,
672
- message: a.message
673
- }), s.dirty());
674
- else if (a.kind === "nanoid")
675
- Ue.test(e.data) || (n = this._getOrReturnCtx(e, n), d(n, {
676
- validation: "nanoid",
677
- code: c.invalid_string,
678
- message: a.message
679
- }), s.dirty());
680
- else if (a.kind === "cuid")
681
- Pe.test(e.data) || (n = this._getOrReturnCtx(e, n), d(n, {
682
- validation: "cuid",
683
- code: c.invalid_string,
684
- message: a.message
685
- }), s.dirty());
686
- else if (a.kind === "cuid2")
687
- ze.test(e.data) || (n = this._getOrReturnCtx(e, n), d(n, {
688
- validation: "cuid2",
689
- code: c.invalid_string,
690
- message: a.message
691
- }), s.dirty());
692
- else if (a.kind === "ulid")
693
- Le.test(e.data) || (n = this._getOrReturnCtx(e, n), d(n, {
694
- validation: "ulid",
695
- code: c.invalid_string,
696
- message: a.message
697
- }), s.dirty());
698
- else if (a.kind === "url")
699
- try {
700
- new URL(e.data);
701
- } catch {
702
- n = this._getOrReturnCtx(e, n), d(n, {
703
- validation: "url",
704
- code: c.invalid_string,
705
- message: a.message
706
- }), s.dirty();
707
- }
708
- else a.kind === "regex" ? (a.regex.lastIndex = 0, a.regex.test(e.data) || (n = this._getOrReturnCtx(e, n), d(n, {
709
- validation: "regex",
710
- code: c.invalid_string,
711
- message: a.message
712
- }), s.dirty())) : a.kind === "trim" ? e.data = e.data.trim() : a.kind === "includes" ? e.data.includes(a.value, a.position) || (n = this._getOrReturnCtx(e, n), d(n, {
713
- code: c.invalid_string,
714
- validation: { includes: a.value, position: a.position },
715
- message: a.message
716
- }), s.dirty()) : a.kind === "toLowerCase" ? e.data = e.data.toLowerCase() : a.kind === "toUpperCase" ? e.data = e.data.toUpperCase() : a.kind === "startsWith" ? e.data.startsWith(a.value) || (n = this._getOrReturnCtx(e, n), d(n, {
717
- code: c.invalid_string,
718
- validation: { startsWith: a.value },
719
- message: a.message
720
- }), s.dirty()) : a.kind === "endsWith" ? e.data.endsWith(a.value) || (n = this._getOrReturnCtx(e, n), d(n, {
721
- code: c.invalid_string,
722
- validation: { endsWith: a.value },
723
- message: a.message
724
- }), s.dirty()) : a.kind === "datetime" ? Ne(a).test(e.data) || (n = this._getOrReturnCtx(e, n), d(n, {
725
- code: c.invalid_string,
726
- validation: "datetime",
727
- message: a.message
728
- }), s.dirty()) : a.kind === "date" ? Ke.test(e.data) || (n = this._getOrReturnCtx(e, n), d(n, {
729
- code: c.invalid_string,
730
- validation: "date",
731
- message: a.message
732
- }), s.dirty()) : a.kind === "time" ? et(a).test(e.data) || (n = this._getOrReturnCtx(e, n), d(n, {
733
- code: c.invalid_string,
734
- validation: "time",
735
- message: a.message
736
- }), s.dirty()) : a.kind === "duration" ? Fe.test(e.data) || (n = this._getOrReturnCtx(e, n), d(n, {
737
- validation: "duration",
738
- code: c.invalid_string,
739
- message: a.message
740
- }), s.dirty()) : a.kind === "ip" ? tt(e.data, a.version) || (n = this._getOrReturnCtx(e, n), d(n, {
741
- validation: "ip",
742
- code: c.invalid_string,
743
- message: a.message
744
- }), s.dirty()) : a.kind === "jwt" ? rt(e.data, a.alg) || (n = this._getOrReturnCtx(e, n), d(n, {
745
- validation: "jwt",
746
- code: c.invalid_string,
747
- message: a.message
748
- }), s.dirty()) : a.kind === "cidr" ? st(e.data, a.version) || (n = this._getOrReturnCtx(e, n), d(n, {
749
- validation: "cidr",
750
- code: c.invalid_string,
751
- message: a.message
752
- }), s.dirty()) : a.kind === "base64" ? Qe.test(e.data) || (n = this._getOrReturnCtx(e, n), d(n, {
753
- validation: "base64",
754
- code: c.invalid_string,
755
- message: a.message
756
- }), s.dirty()) : a.kind === "base64url" ? Xe.test(e.data) || (n = this._getOrReturnCtx(e, n), d(n, {
757
- validation: "base64url",
758
- code: c.invalid_string,
759
- message: a.message
760
- }), s.dirty()) : v.assertNever(a);
761
- return { status: s.value, value: e.data };
762
- }
763
- _regex(e, t, s) {
764
- return this.refinement((n) => e.test(n), {
765
- validation: t,
766
- code: c.invalid_string,
767
- ...h.errToObj(s)
768
- });
769
- }
770
- _addCheck(e) {
771
- return new C({
772
- ...this._def,
773
- checks: [...this._def.checks, e]
774
- });
775
- }
776
- email(e) {
777
- return this._addCheck({ kind: "email", ...h.errToObj(e) });
778
- }
779
- url(e) {
780
- return this._addCheck({ kind: "url", ...h.errToObj(e) });
781
- }
782
- emoji(e) {
783
- return this._addCheck({ kind: "emoji", ...h.errToObj(e) });
784
- }
785
- uuid(e) {
786
- return this._addCheck({ kind: "uuid", ...h.errToObj(e) });
787
- }
788
- nanoid(e) {
789
- return this._addCheck({ kind: "nanoid", ...h.errToObj(e) });
790
- }
791
- cuid(e) {
792
- return this._addCheck({ kind: "cuid", ...h.errToObj(e) });
793
- }
794
- cuid2(e) {
795
- return this._addCheck({ kind: "cuid2", ...h.errToObj(e) });
796
- }
797
- ulid(e) {
798
- return this._addCheck({ kind: "ulid", ...h.errToObj(e) });
799
- }
800
- base64(e) {
801
- return this._addCheck({ kind: "base64", ...h.errToObj(e) });
802
- }
803
- base64url(e) {
804
- return this._addCheck({
805
- kind: "base64url",
806
- ...h.errToObj(e)
807
- });
808
- }
809
- jwt(e) {
810
- return this._addCheck({ kind: "jwt", ...h.errToObj(e) });
811
- }
812
- ip(e) {
813
- return this._addCheck({ kind: "ip", ...h.errToObj(e) });
814
- }
815
- cidr(e) {
816
- return this._addCheck({ kind: "cidr", ...h.errToObj(e) });
817
- }
818
- datetime(e) {
819
- return typeof e == "string" ? this._addCheck({
820
- kind: "datetime",
821
- precision: null,
822
- offset: !1,
823
- local: !1,
824
- message: e
825
- }) : this._addCheck({
826
- kind: "datetime",
827
- precision: typeof e?.precision > "u" ? null : e?.precision,
828
- offset: e?.offset ?? !1,
829
- local: e?.local ?? !1,
830
- ...h.errToObj(e?.message)
831
- });
832
- }
833
- date(e) {
834
- return this._addCheck({ kind: "date", message: e });
835
- }
836
- time(e) {
837
- return typeof e == "string" ? this._addCheck({
838
- kind: "time",
839
- precision: null,
840
- message: e
841
- }) : this._addCheck({
842
- kind: "time",
843
- precision: typeof e?.precision > "u" ? null : e?.precision,
844
- ...h.errToObj(e?.message)
845
- });
846
- }
847
- duration(e) {
848
- return this._addCheck({ kind: "duration", ...h.errToObj(e) });
849
- }
850
- regex(e, t) {
851
- return this._addCheck({
852
- kind: "regex",
853
- regex: e,
854
- ...h.errToObj(t)
855
- });
856
- }
857
- includes(e, t) {
858
- return this._addCheck({
859
- kind: "includes",
860
- value: e,
861
- position: t?.position,
862
- ...h.errToObj(t?.message)
863
- });
864
- }
865
- startsWith(e, t) {
866
- return this._addCheck({
867
- kind: "startsWith",
868
- value: e,
869
- ...h.errToObj(t)
870
- });
871
- }
872
- endsWith(e, t) {
873
- return this._addCheck({
874
- kind: "endsWith",
875
- value: e,
876
- ...h.errToObj(t)
877
- });
878
- }
879
- min(e, t) {
880
- return this._addCheck({
881
- kind: "min",
882
- value: e,
883
- ...h.errToObj(t)
884
- });
885
- }
886
- max(e, t) {
887
- return this._addCheck({
888
- kind: "max",
889
- value: e,
890
- ...h.errToObj(t)
891
- });
892
- }
893
- length(e, t) {
894
- return this._addCheck({
895
- kind: "length",
896
- value: e,
897
- ...h.errToObj(t)
898
- });
899
- }
900
- /**
901
- * Equivalent to `.min(1)`
902
- */
903
- nonempty(e) {
904
- return this.min(1, h.errToObj(e));
905
- }
906
- trim() {
907
- return new C({
908
- ...this._def,
909
- checks: [...this._def.checks, { kind: "trim" }]
910
- });
911
- }
912
- toLowerCase() {
913
- return new C({
914
- ...this._def,
915
- checks: [...this._def.checks, { kind: "toLowerCase" }]
916
- });
917
- }
918
- toUpperCase() {
919
- return new C({
920
- ...this._def,
921
- checks: [...this._def.checks, { kind: "toUpperCase" }]
922
- });
923
- }
924
- get isDatetime() {
925
- return !!this._def.checks.find((e) => e.kind === "datetime");
926
- }
927
- get isDate() {
928
- return !!this._def.checks.find((e) => e.kind === "date");
929
- }
930
- get isTime() {
931
- return !!this._def.checks.find((e) => e.kind === "time");
932
- }
933
- get isDuration() {
934
- return !!this._def.checks.find((e) => e.kind === "duration");
935
- }
936
- get isEmail() {
937
- return !!this._def.checks.find((e) => e.kind === "email");
938
- }
939
- get isURL() {
940
- return !!this._def.checks.find((e) => e.kind === "url");
941
- }
942
- get isEmoji() {
943
- return !!this._def.checks.find((e) => e.kind === "emoji");
944
- }
945
- get isUUID() {
946
- return !!this._def.checks.find((e) => e.kind === "uuid");
947
- }
948
- get isNANOID() {
949
- return !!this._def.checks.find((e) => e.kind === "nanoid");
950
- }
951
- get isCUID() {
952
- return !!this._def.checks.find((e) => e.kind === "cuid");
953
- }
954
- get isCUID2() {
955
- return !!this._def.checks.find((e) => e.kind === "cuid2");
956
- }
957
- get isULID() {
958
- return !!this._def.checks.find((e) => e.kind === "ulid");
959
- }
960
- get isIP() {
961
- return !!this._def.checks.find((e) => e.kind === "ip");
962
- }
963
- get isCIDR() {
964
- return !!this._def.checks.find((e) => e.kind === "cidr");
965
- }
966
- get isBase64() {
967
- return !!this._def.checks.find((e) => e.kind === "base64");
968
- }
969
- get isBase64url() {
970
- return !!this._def.checks.find((e) => e.kind === "base64url");
971
- }
972
- get minLength() {
973
- let e = null;
974
- for (const t of this._def.checks)
975
- t.kind === "min" && (e === null || t.value > e) && (e = t.value);
976
- return e;
977
- }
978
- get maxLength() {
979
- let e = null;
980
- for (const t of this._def.checks)
981
- t.kind === "max" && (e === null || t.value < e) && (e = t.value);
982
- return e;
983
- }
984
- }
985
- C.create = (r) => new C({
986
- checks: [],
987
- typeName: m.ZodString,
988
- coerce: r?.coerce ?? !1,
989
- ...y(r)
990
- });
991
- function nt(r, e) {
992
- const t = (r.toString().split(".")[1] || "").length, s = (e.toString().split(".")[1] || "").length, n = t > s ? t : s, a = Number.parseInt(r.toFixed(n).replace(".", "")), i = Number.parseInt(e.toFixed(n).replace(".", ""));
993
- return a % i / 10 ** n;
994
- }
995
- class I extends _ {
996
- constructor() {
997
- super(...arguments), this.min = this.gte, this.max = this.lte, this.step = this.multipleOf;
998
- }
999
- _parse(e) {
1000
- if (this._def.coerce && (e.data = Number(e.data)), this._getType(e) !== u.number) {
1001
- const a = this._getOrReturnCtx(e);
1002
- return d(a, {
1003
- code: c.invalid_type,
1004
- expected: u.number,
1005
- received: a.parsedType
1006
- }), p;
1007
- }
1008
- let s;
1009
- const n = new k();
1010
- for (const a of this._def.checks)
1011
- a.kind === "int" ? v.isInteger(e.data) || (s = this._getOrReturnCtx(e, s), d(s, {
1012
- code: c.invalid_type,
1013
- expected: "integer",
1014
- received: "float",
1015
- message: a.message
1016
- }), n.dirty()) : a.kind === "min" ? (a.inclusive ? e.data < a.value : e.data <= a.value) && (s = this._getOrReturnCtx(e, s), d(s, {
1017
- code: c.too_small,
1018
- minimum: a.value,
1019
- type: "number",
1020
- inclusive: a.inclusive,
1021
- exact: !1,
1022
- message: a.message
1023
- }), n.dirty()) : a.kind === "max" ? (a.inclusive ? e.data > a.value : e.data >= a.value) && (s = this._getOrReturnCtx(e, s), d(s, {
1024
- code: c.too_big,
1025
- maximum: a.value,
1026
- type: "number",
1027
- inclusive: a.inclusive,
1028
- exact: !1,
1029
- message: a.message
1030
- }), n.dirty()) : a.kind === "multipleOf" ? nt(e.data, a.value) !== 0 && (s = this._getOrReturnCtx(e, s), d(s, {
1031
- code: c.not_multiple_of,
1032
- multipleOf: a.value,
1033
- message: a.message
1034
- }), n.dirty()) : a.kind === "finite" ? Number.isFinite(e.data) || (s = this._getOrReturnCtx(e, s), d(s, {
1035
- code: c.not_finite,
1036
- message: a.message
1037
- }), n.dirty()) : v.assertNever(a);
1038
- return { status: n.value, value: e.data };
1039
- }
1040
- gte(e, t) {
1041
- return this.setLimit("min", e, !0, h.toString(t));
1042
- }
1043
- gt(e, t) {
1044
- return this.setLimit("min", e, !1, h.toString(t));
1045
- }
1046
- lte(e, t) {
1047
- return this.setLimit("max", e, !0, h.toString(t));
1048
- }
1049
- lt(e, t) {
1050
- return this.setLimit("max", e, !1, h.toString(t));
1051
- }
1052
- setLimit(e, t, s, n) {
1053
- return new I({
1054
- ...this._def,
1055
- checks: [
1056
- ...this._def.checks,
1057
- {
1058
- kind: e,
1059
- value: t,
1060
- inclusive: s,
1061
- message: h.toString(n)
1062
- }
1063
- ]
1064
- });
1065
- }
1066
- _addCheck(e) {
1067
- return new I({
1068
- ...this._def,
1069
- checks: [...this._def.checks, e]
1070
- });
1071
- }
1072
- int(e) {
1073
- return this._addCheck({
1074
- kind: "int",
1075
- message: h.toString(e)
1076
- });
1077
- }
1078
- positive(e) {
1079
- return this._addCheck({
1080
- kind: "min",
1081
- value: 0,
1082
- inclusive: !1,
1083
- message: h.toString(e)
1084
- });
1085
- }
1086
- negative(e) {
1087
- return this._addCheck({
1088
- kind: "max",
1089
- value: 0,
1090
- inclusive: !1,
1091
- message: h.toString(e)
1092
- });
1093
- }
1094
- nonpositive(e) {
1095
- return this._addCheck({
1096
- kind: "max",
1097
- value: 0,
1098
- inclusive: !0,
1099
- message: h.toString(e)
1100
- });
1101
- }
1102
- nonnegative(e) {
1103
- return this._addCheck({
1104
- kind: "min",
1105
- value: 0,
1106
- inclusive: !0,
1107
- message: h.toString(e)
1108
- });
1109
- }
1110
- multipleOf(e, t) {
1111
- return this._addCheck({
1112
- kind: "multipleOf",
1113
- value: e,
1114
- message: h.toString(t)
1115
- });
1116
- }
1117
- finite(e) {
1118
- return this._addCheck({
1119
- kind: "finite",
1120
- message: h.toString(e)
1121
- });
1122
- }
1123
- safe(e) {
1124
- return this._addCheck({
1125
- kind: "min",
1126
- inclusive: !0,
1127
- value: Number.MIN_SAFE_INTEGER,
1128
- message: h.toString(e)
1129
- })._addCheck({
1130
- kind: "max",
1131
- inclusive: !0,
1132
- value: Number.MAX_SAFE_INTEGER,
1133
- message: h.toString(e)
1134
- });
1135
- }
1136
- get minValue() {
1137
- let e = null;
1138
- for (const t of this._def.checks)
1139
- t.kind === "min" && (e === null || t.value > e) && (e = t.value);
1140
- return e;
1141
- }
1142
- get maxValue() {
1143
- let e = null;
1144
- for (const t of this._def.checks)
1145
- t.kind === "max" && (e === null || t.value < e) && (e = t.value);
1146
- return e;
1147
- }
1148
- get isInt() {
1149
- return !!this._def.checks.find((e) => e.kind === "int" || e.kind === "multipleOf" && v.isInteger(e.value));
1150
- }
1151
- get isFinite() {
1152
- let e = null, t = null;
1153
- for (const s of this._def.checks) {
1154
- if (s.kind === "finite" || s.kind === "int" || s.kind === "multipleOf")
1155
- return !0;
1156
- s.kind === "min" ? (t === null || s.value > t) && (t = s.value) : s.kind === "max" && (e === null || s.value < e) && (e = s.value);
1157
- }
1158
- return Number.isFinite(t) && Number.isFinite(e);
1159
- }
1160
- }
1161
- I.create = (r) => new I({
1162
- checks: [],
1163
- typeName: m.ZodNumber,
1164
- coerce: r?.coerce || !1,
1165
- ...y(r)
1166
- });
1167
- class $ extends _ {
1168
- constructor() {
1169
- super(...arguments), this.min = this.gte, this.max = this.lte;
1170
- }
1171
- _parse(e) {
1172
- if (this._def.coerce)
1173
- try {
1174
- e.data = BigInt(e.data);
1175
- } catch {
1176
- return this._getInvalidInput(e);
1177
- }
1178
- if (this._getType(e) !== u.bigint)
1179
- return this._getInvalidInput(e);
1180
- let s;
1181
- const n = new k();
1182
- for (const a of this._def.checks)
1183
- a.kind === "min" ? (a.inclusive ? e.data < a.value : e.data <= a.value) && (s = this._getOrReturnCtx(e, s), d(s, {
1184
- code: c.too_small,
1185
- type: "bigint",
1186
- minimum: a.value,
1187
- inclusive: a.inclusive,
1188
- message: a.message
1189
- }), n.dirty()) : a.kind === "max" ? (a.inclusive ? e.data > a.value : e.data >= a.value) && (s = this._getOrReturnCtx(e, s), d(s, {
1190
- code: c.too_big,
1191
- type: "bigint",
1192
- maximum: a.value,
1193
- inclusive: a.inclusive,
1194
- message: a.message
1195
- }), n.dirty()) : a.kind === "multipleOf" ? e.data % a.value !== BigInt(0) && (s = this._getOrReturnCtx(e, s), d(s, {
1196
- code: c.not_multiple_of,
1197
- multipleOf: a.value,
1198
- message: a.message
1199
- }), n.dirty()) : v.assertNever(a);
1200
- return { status: n.value, value: e.data };
1201
- }
1202
- _getInvalidInput(e) {
1203
- const t = this._getOrReturnCtx(e);
1204
- return d(t, {
1205
- code: c.invalid_type,
1206
- expected: u.bigint,
1207
- received: t.parsedType
1208
- }), p;
1209
- }
1210
- gte(e, t) {
1211
- return this.setLimit("min", e, !0, h.toString(t));
1212
- }
1213
- gt(e, t) {
1214
- return this.setLimit("min", e, !1, h.toString(t));
1215
- }
1216
- lte(e, t) {
1217
- return this.setLimit("max", e, !0, h.toString(t));
1218
- }
1219
- lt(e, t) {
1220
- return this.setLimit("max", e, !1, h.toString(t));
1221
- }
1222
- setLimit(e, t, s, n) {
1223
- return new $({
1224
- ...this._def,
1225
- checks: [
1226
- ...this._def.checks,
1227
- {
1228
- kind: e,
1229
- value: t,
1230
- inclusive: s,
1231
- message: h.toString(n)
1232
- }
1233
- ]
1234
- });
1235
- }
1236
- _addCheck(e) {
1237
- return new $({
1238
- ...this._def,
1239
- checks: [...this._def.checks, e]
1240
- });
1241
- }
1242
- positive(e) {
1243
- return this._addCheck({
1244
- kind: "min",
1245
- value: BigInt(0),
1246
- inclusive: !1,
1247
- message: h.toString(e)
1248
- });
1249
- }
1250
- negative(e) {
1251
- return this._addCheck({
1252
- kind: "max",
1253
- value: BigInt(0),
1254
- inclusive: !1,
1255
- message: h.toString(e)
1256
- });
1257
- }
1258
- nonpositive(e) {
1259
- return this._addCheck({
1260
- kind: "max",
1261
- value: BigInt(0),
1262
- inclusive: !0,
1263
- message: h.toString(e)
1264
- });
1265
- }
1266
- nonnegative(e) {
1267
- return this._addCheck({
1268
- kind: "min",
1269
- value: BigInt(0),
1270
- inclusive: !0,
1271
- message: h.toString(e)
1272
- });
1273
- }
1274
- multipleOf(e, t) {
1275
- return this._addCheck({
1276
- kind: "multipleOf",
1277
- value: e,
1278
- message: h.toString(t)
1279
- });
1280
- }
1281
- get minValue() {
1282
- let e = null;
1283
- for (const t of this._def.checks)
1284
- t.kind === "min" && (e === null || t.value > e) && (e = t.value);
1285
- return e;
1286
- }
1287
- get maxValue() {
1288
- let e = null;
1289
- for (const t of this._def.checks)
1290
- t.kind === "max" && (e === null || t.value < e) && (e = t.value);
1291
- return e;
1292
- }
1293
- }
1294
- $.create = (r) => new $({
1295
- checks: [],
1296
- typeName: m.ZodBigInt,
1297
- coerce: r?.coerce ?? !1,
1298
- ...y(r)
1299
- });
1300
- class H extends _ {
1301
- _parse(e) {
1302
- if (this._def.coerce && (e.data = !!e.data), this._getType(e) !== u.boolean) {
1303
- const s = this._getOrReturnCtx(e);
1304
- return d(s, {
1305
- code: c.invalid_type,
1306
- expected: u.boolean,
1307
- received: s.parsedType
1308
- }), p;
1309
- }
1310
- return b(e.data);
1311
- }
1312
- }
1313
- H.create = (r) => new H({
1314
- typeName: m.ZodBoolean,
1315
- coerce: r?.coerce || !1,
1316
- ...y(r)
1317
- });
1318
- class L extends _ {
1319
- _parse(e) {
1320
- if (this._def.coerce && (e.data = new Date(e.data)), this._getType(e) !== u.date) {
1321
- const a = this._getOrReturnCtx(e);
1322
- return d(a, {
1323
- code: c.invalid_type,
1324
- expected: u.date,
1325
- received: a.parsedType
1326
- }), p;
1327
- }
1328
- if (Number.isNaN(e.data.getTime())) {
1329
- const a = this._getOrReturnCtx(e);
1330
- return d(a, {
1331
- code: c.invalid_date
1332
- }), p;
1333
- }
1334
- const s = new k();
1335
- let n;
1336
- for (const a of this._def.checks)
1337
- a.kind === "min" ? e.data.getTime() < a.value && (n = this._getOrReturnCtx(e, n), d(n, {
1338
- code: c.too_small,
1339
- message: a.message,
1340
- inclusive: !0,
1341
- exact: !1,
1342
- minimum: a.value,
1343
- type: "date"
1344
- }), s.dirty()) : a.kind === "max" ? e.data.getTime() > a.value && (n = this._getOrReturnCtx(e, n), d(n, {
1345
- code: c.too_big,
1346
- message: a.message,
1347
- inclusive: !0,
1348
- exact: !1,
1349
- maximum: a.value,
1350
- type: "date"
1351
- }), s.dirty()) : v.assertNever(a);
1352
- return {
1353
- status: s.value,
1354
- value: new Date(e.data.getTime())
1355
- };
1356
- }
1357
- _addCheck(e) {
1358
- return new L({
1359
- ...this._def,
1360
- checks: [...this._def.checks, e]
1361
- });
1362
- }
1363
- min(e, t) {
1364
- return this._addCheck({
1365
- kind: "min",
1366
- value: e.getTime(),
1367
- message: h.toString(t)
1368
- });
1369
- }
1370
- max(e, t) {
1371
- return this._addCheck({
1372
- kind: "max",
1373
- value: e.getTime(),
1374
- message: h.toString(t)
1375
- });
1376
- }
1377
- get minDate() {
1378
- let e = null;
1379
- for (const t of this._def.checks)
1380
- t.kind === "min" && (e === null || t.value > e) && (e = t.value);
1381
- return e != null ? new Date(e) : null;
1382
- }
1383
- get maxDate() {
1384
- let e = null;
1385
- for (const t of this._def.checks)
1386
- t.kind === "max" && (e === null || t.value < e) && (e = t.value);
1387
- return e != null ? new Date(e) : null;
1388
- }
1389
- }
1390
- L.create = (r) => new L({
1391
- checks: [],
1392
- coerce: r?.coerce || !1,
1393
- typeName: m.ZodDate,
1394
- ...y(r)
1395
- });
1396
- class ue extends _ {
1397
- _parse(e) {
1398
- if (this._getType(e) !== u.symbol) {
1399
- const s = this._getOrReturnCtx(e);
1400
- return d(s, {
1401
- code: c.invalid_type,
1402
- expected: u.symbol,
1403
- received: s.parsedType
1404
- }), p;
1405
- }
1406
- return b(e.data);
1407
- }
1408
- }
1409
- ue.create = (r) => new ue({
1410
- typeName: m.ZodSymbol,
1411
- ...y(r)
1412
- });
1413
- class G extends _ {
1414
- _parse(e) {
1415
- if (this._getType(e) !== u.undefined) {
1416
- const s = this._getOrReturnCtx(e);
1417
- return d(s, {
1418
- code: c.invalid_type,
1419
- expected: u.undefined,
1420
- received: s.parsedType
1421
- }), p;
1422
- }
1423
- return b(e.data);
1424
- }
1425
- }
1426
- G.create = (r) => new G({
1427
- typeName: m.ZodUndefined,
1428
- ...y(r)
1429
- });
1430
- class Q extends _ {
1431
- _parse(e) {
1432
- if (this._getType(e) !== u.null) {
1433
- const s = this._getOrReturnCtx(e);
1434
- return d(s, {
1435
- code: c.invalid_type,
1436
- expected: u.null,
1437
- received: s.parsedType
1438
- }), p;
1439
- }
1440
- return b(e.data);
1441
- }
1442
- }
1443
- Q.create = (r) => new Q({
1444
- typeName: m.ZodNull,
1445
- ...y(r)
1446
- });
1447
- class q extends _ {
1448
- constructor() {
1449
- super(...arguments), this._any = !0;
1450
- }
1451
- _parse(e) {
1452
- return b(e.data);
1453
- }
1454
- }
1455
- q.create = (r) => new q({
1456
- typeName: m.ZodAny,
1457
- ...y(r)
1458
- });
1459
- class P extends _ {
1460
- constructor() {
1461
- super(...arguments), this._unknown = !0;
1462
- }
1463
- _parse(e) {
1464
- return b(e.data);
1465
- }
1466
- }
1467
- P.create = (r) => new P({
1468
- typeName: m.ZodUnknown,
1469
- ...y(r)
1470
- });
1471
- class E extends _ {
1472
- _parse(e) {
1473
- const t = this._getOrReturnCtx(e);
1474
- return d(t, {
1475
- code: c.invalid_type,
1476
- expected: u.never,
1477
- received: t.parsedType
1478
- }), p;
1479
- }
1480
- }
1481
- E.create = (r) => new E({
1482
- typeName: m.ZodNever,
1483
- ...y(r)
1484
- });
1485
- class le extends _ {
1486
- _parse(e) {
1487
- if (this._getType(e) !== u.undefined) {
1488
- const s = this._getOrReturnCtx(e);
1489
- return d(s, {
1490
- code: c.invalid_type,
1491
- expected: u.void,
1492
- received: s.parsedType
1493
- }), p;
1494
- }
1495
- return b(e.data);
1496
- }
1497
- }
1498
- le.create = (r) => new le({
1499
- typeName: m.ZodVoid,
1500
- ...y(r)
1501
- });
1502
- class S extends _ {
1503
- _parse(e) {
1504
- const { ctx: t, status: s } = this._processInputParams(e), n = this._def;
1505
- if (t.parsedType !== u.array)
1506
- return d(t, {
1507
- code: c.invalid_type,
1508
- expected: u.array,
1509
- received: t.parsedType
1510
- }), p;
1511
- if (n.exactLength !== null) {
1512
- const i = t.data.length > n.exactLength.value, o = t.data.length < n.exactLength.value;
1513
- (i || o) && (d(t, {
1514
- code: i ? c.too_big : c.too_small,
1515
- minimum: o ? n.exactLength.value : void 0,
1516
- maximum: i ? n.exactLength.value : void 0,
1517
- type: "array",
1518
- inclusive: !0,
1519
- exact: !0,
1520
- message: n.exactLength.message
1521
- }), s.dirty());
1522
- }
1523
- if (n.minLength !== null && t.data.length < n.minLength.value && (d(t, {
1524
- code: c.too_small,
1525
- minimum: n.minLength.value,
1526
- type: "array",
1527
- inclusive: !0,
1528
- exact: !1,
1529
- message: n.minLength.message
1530
- }), s.dirty()), n.maxLength !== null && t.data.length > n.maxLength.value && (d(t, {
1531
- code: c.too_big,
1532
- maximum: n.maxLength.value,
1533
- type: "array",
1534
- inclusive: !0,
1535
- exact: !1,
1536
- message: n.maxLength.message
1537
- }), s.dirty()), t.common.async)
1538
- return Promise.all([...t.data].map((i, o) => n.type._parseAsync(new N(t, i, t.path, o)))).then((i) => k.mergeArray(s, i));
1539
- const a = [...t.data].map((i, o) => n.type._parseSync(new N(t, i, t.path, o)));
1540
- return k.mergeArray(s, a);
1541
- }
1542
- get element() {
1543
- return this._def.type;
1544
- }
1545
- min(e, t) {
1546
- return new S({
1547
- ...this._def,
1548
- minLength: { value: e, message: h.toString(t) }
1549
- });
1550
- }
1551
- max(e, t) {
1552
- return new S({
1553
- ...this._def,
1554
- maxLength: { value: e, message: h.toString(t) }
1555
- });
1556
- }
1557
- length(e, t) {
1558
- return new S({
1559
- ...this._def,
1560
- exactLength: { value: e, message: h.toString(t) }
1561
- });
1562
- }
1563
- nonempty(e) {
1564
- return this.min(1, e);
1565
- }
1566
- }
1567
- S.create = (r, e) => new S({
1568
- type: r,
1569
- minLength: null,
1570
- maxLength: null,
1571
- exactLength: null,
1572
- typeName: m.ZodArray,
1573
- ...y(e)
1574
- });
1575
- function U(r) {
1576
- if (r instanceof x) {
1577
- const e = {};
1578
- for (const t in r.shape) {
1579
- const s = r.shape[t];
1580
- e[t] = A.create(U(s));
1581
- }
1582
- return new x({
1583
- ...r._def,
1584
- shape: () => e
1585
- });
1586
- } else return r instanceof S ? new S({
1587
- ...r._def,
1588
- type: U(r.element)
1589
- }) : r instanceof A ? A.create(U(r.unwrap())) : r instanceof V ? V.create(U(r.unwrap())) : r instanceof Z ? Z.create(r.items.map((e) => U(e))) : r;
1590
- }
1591
- class x extends _ {
1592
- constructor() {
1593
- super(...arguments), this._cached = null, this.nonstrict = this.passthrough, this.augment = this.extend;
1594
- }
1595
- _getCached() {
1596
- if (this._cached !== null)
1597
- return this._cached;
1598
- const e = this._def.shape(), t = v.objectKeys(e);
1599
- return this._cached = { shape: e, keys: t }, this._cached;
1600
- }
1601
- _parse(e) {
1602
- if (this._getType(e) !== u.object) {
1603
- const l = this._getOrReturnCtx(e);
1604
- return d(l, {
1605
- code: c.invalid_type,
1606
- expected: u.object,
1607
- received: l.parsedType
1608
- }), p;
1609
- }
1610
- const { status: s, ctx: n } = this._processInputParams(e), { shape: a, keys: i } = this._getCached(), o = [];
1611
- if (!(this._def.catchall instanceof E && this._def.unknownKeys === "strip"))
1612
- for (const l in n.data)
1613
- i.includes(l) || o.push(l);
1614
- const f = [];
1615
- for (const l of i) {
1616
- const g = a[l], T = n.data[l];
1617
- f.push({
1618
- key: { status: "valid", value: l },
1619
- value: g._parse(new N(n, T, n.path, l)),
1620
- alwaysSet: l in n.data
1621
- });
1622
- }
1623
- if (this._def.catchall instanceof E) {
1624
- const l = this._def.unknownKeys;
1625
- if (l === "passthrough")
1626
- for (const g of o)
1627
- f.push({
1628
- key: { status: "valid", value: g },
1629
- value: { status: "valid", value: n.data[g] }
1630
- });
1631
- else if (l === "strict")
1632
- o.length > 0 && (d(n, {
1633
- code: c.unrecognized_keys,
1634
- keys: o
1635
- }), s.dirty());
1636
- else if (l !== "strip") throw new Error("Internal ZodObject error: invalid unknownKeys value.");
1637
- } else {
1638
- const l = this._def.catchall;
1639
- for (const g of o) {
1640
- const T = n.data[g];
1641
- f.push({
1642
- key: { status: "valid", value: g },
1643
- value: l._parse(
1644
- new N(n, T, n.path, g)
1645
- //, ctx.child(key), value, getParsedType(value)
1646
- ),
1647
- alwaysSet: g in n.data
1648
- });
1649
- }
1650
- }
1651
- return n.common.async ? Promise.resolve().then(async () => {
1652
- const l = [];
1653
- for (const g of f) {
1654
- const T = await g.key, be = await g.value;
1655
- l.push({
1656
- key: T,
1657
- value: be,
1658
- alwaysSet: g.alwaysSet
1659
- });
1660
- }
1661
- return l;
1662
- }).then((l) => k.mergeObjectSync(s, l)) : k.mergeObjectSync(s, f);
1663
- }
1664
- get shape() {
1665
- return this._def.shape();
1666
- }
1667
- strict(e) {
1668
- return h.errToObj, new x({
1669
- ...this._def,
1670
- unknownKeys: "strict",
1671
- ...e !== void 0 ? {
1672
- errorMap: (t, s) => {
1673
- const n = this._def.errorMap?.(t, s).message ?? s.defaultError;
1674
- return t.code === "unrecognized_keys" ? {
1675
- message: h.errToObj(e).message ?? n
1676
- } : {
1677
- message: n
1678
- };
1679
- }
1680
- } : {}
1681
- });
1682
- }
1683
- strip() {
1684
- return new x({
1685
- ...this._def,
1686
- unknownKeys: "strip"
1687
- });
1688
- }
1689
- passthrough() {
1690
- return new x({
1691
- ...this._def,
1692
- unknownKeys: "passthrough"
1693
- });
1694
- }
1695
- // const AugmentFactory =
1696
- // <Def extends ZodObjectDef>(def: Def) =>
1697
- // <Augmentation extends ZodRawShape>(
1698
- // augmentation: Augmentation
1699
- // ): ZodObject<
1700
- // extendShape<ReturnType<Def["shape"]>, Augmentation>,
1701
- // Def["unknownKeys"],
1702
- // Def["catchall"]
1703
- // > => {
1704
- // return new ZodObject({
1705
- // ...def,
1706
- // shape: () => ({
1707
- // ...def.shape(),
1708
- // ...augmentation,
1709
- // }),
1710
- // }) as any;
1711
- // };
1712
- extend(e) {
1713
- return new x({
1714
- ...this._def,
1715
- shape: () => ({
1716
- ...this._def.shape(),
1717
- ...e
1718
- })
1719
- });
1720
- }
1721
- /**
1722
- * Prior to zod@1.0.12 there was a bug in the
1723
- * inferred type of merged objects. Please
1724
- * upgrade if you are experiencing issues.
1725
- */
1726
- merge(e) {
1727
- return new x({
1728
- unknownKeys: e._def.unknownKeys,
1729
- catchall: e._def.catchall,
1730
- shape: () => ({
1731
- ...this._def.shape(),
1732
- ...e._def.shape()
1733
- }),
1734
- typeName: m.ZodObject
1735
- });
1736
- }
1737
- // merge<
1738
- // Incoming extends AnyZodObject,
1739
- // Augmentation extends Incoming["shape"],
1740
- // NewOutput extends {
1741
- // [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
1742
- // ? Augmentation[k]["_output"]
1743
- // : k extends keyof Output
1744
- // ? Output[k]
1745
- // : never;
1746
- // },
1747
- // NewInput extends {
1748
- // [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
1749
- // ? Augmentation[k]["_input"]
1750
- // : k extends keyof Input
1751
- // ? Input[k]
1752
- // : never;
1753
- // }
1754
- // >(
1755
- // merging: Incoming
1756
- // ): ZodObject<
1757
- // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
1758
- // Incoming["_def"]["unknownKeys"],
1759
- // Incoming["_def"]["catchall"],
1760
- // NewOutput,
1761
- // NewInput
1762
- // > {
1763
- // const merged: any = new ZodObject({
1764
- // unknownKeys: merging._def.unknownKeys,
1765
- // catchall: merging._def.catchall,
1766
- // shape: () =>
1767
- // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
1768
- // typeName: ZodFirstPartyTypeKind.ZodObject,
1769
- // }) as any;
1770
- // return merged;
1771
- // }
1772
- setKey(e, t) {
1773
- return this.augment({ [e]: t });
1774
- }
1775
- // merge<Incoming extends AnyZodObject>(
1776
- // merging: Incoming
1777
- // ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
1778
- // ZodObject<
1779
- // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
1780
- // Incoming["_def"]["unknownKeys"],
1781
- // Incoming["_def"]["catchall"]
1782
- // > {
1783
- // // const mergedShape = objectUtil.mergeShapes(
1784
- // // this._def.shape(),
1785
- // // merging._def.shape()
1786
- // // );
1787
- // const merged: any = new ZodObject({
1788
- // unknownKeys: merging._def.unknownKeys,
1789
- // catchall: merging._def.catchall,
1790
- // shape: () =>
1791
- // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
1792
- // typeName: ZodFirstPartyTypeKind.ZodObject,
1793
- // }) as any;
1794
- // return merged;
1795
- // }
1796
- catchall(e) {
1797
- return new x({
1798
- ...this._def,
1799
- catchall: e
1800
- });
1801
- }
1802
- pick(e) {
1803
- const t = {};
1804
- for (const s of v.objectKeys(e))
1805
- e[s] && this.shape[s] && (t[s] = this.shape[s]);
1806
- return new x({
1807
- ...this._def,
1808
- shape: () => t
1809
- });
1810
- }
1811
- omit(e) {
1812
- const t = {};
1813
- for (const s of v.objectKeys(this.shape))
1814
- e[s] || (t[s] = this.shape[s]);
1815
- return new x({
1816
- ...this._def,
1817
- shape: () => t
1818
- });
1819
- }
1820
- /**
1821
- * @deprecated
1822
- */
1823
- deepPartial() {
1824
- return U(this);
1825
- }
1826
- partial(e) {
1827
- const t = {};
1828
- for (const s of v.objectKeys(this.shape)) {
1829
- const n = this.shape[s];
1830
- e && !e[s] ? t[s] = n : t[s] = n.optional();
1831
- }
1832
- return new x({
1833
- ...this._def,
1834
- shape: () => t
1835
- });
1836
- }
1837
- required(e) {
1838
- const t = {};
1839
- for (const s of v.objectKeys(this.shape))
1840
- if (e && !e[s])
1841
- t[s] = this.shape[s];
1842
- else {
1843
- let a = this.shape[s];
1844
- for (; a instanceof A; )
1845
- a = a._def.innerType;
1846
- t[s] = a;
1847
- }
1848
- return new x({
1849
- ...this._def,
1850
- shape: () => t
1851
- });
1852
- }
1853
- keyof() {
1854
- return Ze(v.objectKeys(this.shape));
1855
- }
1856
- }
1857
- x.create = (r, e) => new x({
1858
- shape: () => r,
1859
- unknownKeys: "strip",
1860
- catchall: E.create(),
1861
- typeName: m.ZodObject,
1862
- ...y(e)
1863
- });
1864
- x.strictCreate = (r, e) => new x({
1865
- shape: () => r,
1866
- unknownKeys: "strict",
1867
- catchall: E.create(),
1868
- typeName: m.ZodObject,
1869
- ...y(e)
1870
- });
1871
- x.lazycreate = (r, e) => new x({
1872
- shape: r,
1873
- unknownKeys: "strip",
1874
- catchall: E.create(),
1875
- typeName: m.ZodObject,
1876
- ...y(e)
1877
- });
1878
- class X extends _ {
1879
- _parse(e) {
1880
- const { ctx: t } = this._processInputParams(e), s = this._def.options;
1881
- function n(a) {
1882
- for (const o of a)
1883
- if (o.result.status === "valid")
1884
- return o.result;
1885
- for (const o of a)
1886
- if (o.result.status === "dirty")
1887
- return t.common.issues.push(...o.ctx.common.issues), o.result;
1888
- const i = a.map((o) => new w(o.ctx.common.issues));
1889
- return d(t, {
1890
- code: c.invalid_union,
1891
- unionErrors: i
1892
- }), p;
1893
- }
1894
- if (t.common.async)
1895
- return Promise.all(s.map(async (a) => {
1896
- const i = {
1897
- ...t,
1898
- common: {
1899
- ...t.common,
1900
- issues: []
1901
- },
1902
- parent: null
1903
- };
1904
- return {
1905
- result: await a._parseAsync({
1906
- data: t.data,
1907
- path: t.path,
1908
- parent: i
1909
- }),
1910
- ctx: i
1911
- };
1912
- })).then(n);
1913
- {
1914
- let a;
1915
- const i = [];
1916
- for (const f of s) {
1917
- const l = {
1918
- ...t,
1919
- common: {
1920
- ...t.common,
1921
- issues: []
1922
- },
1923
- parent: null
1924
- }, g = f._parseSync({
1925
- data: t.data,
1926
- path: t.path,
1927
- parent: l
1928
- });
1929
- if (g.status === "valid")
1930
- return g;
1931
- g.status === "dirty" && !a && (a = { result: g, ctx: l }), l.common.issues.length && i.push(l.common.issues);
1932
- }
1933
- if (a)
1934
- return t.common.issues.push(...a.ctx.common.issues), a.result;
1935
- const o = i.map((f) => new w(f));
1936
- return d(t, {
1937
- code: c.invalid_union,
1938
- unionErrors: o
1939
- }), p;
1940
- }
1941
- }
1942
- get options() {
1943
- return this._def.options;
1944
- }
1945
- }
1946
- X.create = (r, e) => new X({
1947
- options: r,
1948
- typeName: m.ZodUnion,
1949
- ...y(e)
1950
- });
1951
- const R = (r) => r instanceof te ? R(r.schema) : r instanceof O ? R(r.innerType()) : r instanceof re ? [r.value] : r instanceof M ? r.options : r instanceof se ? v.objectValues(r.enum) : r instanceof ne ? R(r._def.innerType) : r instanceof G ? [void 0] : r instanceof Q ? [null] : r instanceof A ? [void 0, ...R(r.unwrap())] : r instanceof V ? [null, ...R(r.unwrap())] : r instanceof ke || r instanceof ie ? R(r.unwrap()) : r instanceof ae ? R(r._def.innerType) : [];
1952
- class pe extends _ {
1953
- _parse(e) {
1954
- const { ctx: t } = this._processInputParams(e);
1955
- if (t.parsedType !== u.object)
1956
- return d(t, {
1957
- code: c.invalid_type,
1958
- expected: u.object,
1959
- received: t.parsedType
1960
- }), p;
1961
- const s = this.discriminator, n = t.data[s], a = this.optionsMap.get(n);
1962
- return a ? t.common.async ? a._parseAsync({
1963
- data: t.data,
1964
- path: t.path,
1965
- parent: t
1966
- }) : a._parseSync({
1967
- data: t.data,
1968
- path: t.path,
1969
- parent: t
1970
- }) : (d(t, {
1971
- code: c.invalid_union_discriminator,
1972
- options: Array.from(this.optionsMap.keys()),
1973
- path: [s]
1974
- }), p);
1975
- }
1976
- get discriminator() {
1977
- return this._def.discriminator;
1978
- }
1979
- get options() {
1980
- return this._def.options;
1981
- }
1982
- get optionsMap() {
1983
- return this._def.optionsMap;
1984
- }
1985
- /**
1986
- * The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
1987
- * However, it only allows a union of objects, all of which need to share a discriminator property. This property must
1988
- * have a different value for each object in the union.
1989
- * @param discriminator the name of the discriminator property
1990
- * @param types an array of object schemas
1991
- * @param params
1992
- */
1993
- static create(e, t, s) {
1994
- const n = /* @__PURE__ */ new Map();
1995
- for (const a of t) {
1996
- const i = R(a.shape[e]);
1997
- if (!i.length)
1998
- throw new Error(`A discriminator value for key \`${e}\` could not be extracted from all schema options`);
1999
- for (const o of i) {
2000
- if (n.has(o))
2001
- throw new Error(`Discriminator property ${String(e)} has duplicate value ${String(o)}`);
2002
- n.set(o, a);
2003
- }
2004
- }
2005
- return new pe({
2006
- typeName: m.ZodDiscriminatedUnion,
2007
- discriminator: e,
2008
- options: t,
2009
- optionsMap: n,
2010
- ...y(s)
2011
- });
2012
- }
2013
- }
2014
- function xe(r, e) {
2015
- const t = j(r), s = j(e);
2016
- if (r === e)
2017
- return { valid: !0, data: r };
2018
- if (t === u.object && s === u.object) {
2019
- const n = v.objectKeys(e), a = v.objectKeys(r).filter((o) => n.indexOf(o) !== -1), i = { ...r, ...e };
2020
- for (const o of a) {
2021
- const f = xe(r[o], e[o]);
2022
- if (!f.valid)
2023
- return { valid: !1 };
2024
- i[o] = f.data;
2025
- }
2026
- return { valid: !0, data: i };
2027
- } else if (t === u.array && s === u.array) {
2028
- if (r.length !== e.length)
2029
- return { valid: !1 };
2030
- const n = [];
2031
- for (let a = 0; a < r.length; a++) {
2032
- const i = r[a], o = e[a], f = xe(i, o);
2033
- if (!f.valid)
2034
- return { valid: !1 };
2035
- n.push(f.data);
2036
- }
2037
- return { valid: !0, data: n };
2038
- } else return t === u.date && s === u.date && +r == +e ? { valid: !0, data: r } : { valid: !1 };
2039
- }
2040
- class K extends _ {
2041
- _parse(e) {
2042
- const { status: t, ctx: s } = this._processInputParams(e), n = (a, i) => {
2043
- if (ge(a) || ge(i))
2044
- return p;
2045
- const o = xe(a.value, i.value);
2046
- return o.valid ? ((ve(a) || ve(i)) && t.dirty(), { status: t.value, value: o.data }) : (d(s, {
2047
- code: c.invalid_intersection_types
2048
- }), p);
2049
- };
2050
- return s.common.async ? Promise.all([
2051
- this._def.left._parseAsync({
2052
- data: s.data,
2053
- path: s.path,
2054
- parent: s
2055
- }),
2056
- this._def.right._parseAsync({
2057
- data: s.data,
2058
- path: s.path,
2059
- parent: s
2060
- })
2061
- ]).then(([a, i]) => n(a, i)) : n(this._def.left._parseSync({
2062
- data: s.data,
2063
- path: s.path,
2064
- parent: s
2065
- }), this._def.right._parseSync({
2066
- data: s.data,
2067
- path: s.path,
2068
- parent: s
2069
- }));
2070
- }
2071
- }
2072
- K.create = (r, e, t) => new K({
2073
- left: r,
2074
- right: e,
2075
- typeName: m.ZodIntersection,
2076
- ...y(t)
2077
- });
2078
- class Z extends _ {
2079
- _parse(e) {
2080
- const { status: t, ctx: s } = this._processInputParams(e);
2081
- if (s.parsedType !== u.array)
2082
- return d(s, {
2083
- code: c.invalid_type,
2084
- expected: u.array,
2085
- received: s.parsedType
2086
- }), p;
2087
- if (s.data.length < this._def.items.length)
2088
- return d(s, {
2089
- code: c.too_small,
2090
- minimum: this._def.items.length,
2091
- inclusive: !0,
2092
- exact: !1,
2093
- type: "array"
2094
- }), p;
2095
- !this._def.rest && s.data.length > this._def.items.length && (d(s, {
2096
- code: c.too_big,
2097
- maximum: this._def.items.length,
2098
- inclusive: !0,
2099
- exact: !1,
2100
- type: "array"
2101
- }), t.dirty());
2102
- const a = [...s.data].map((i, o) => {
2103
- const f = this._def.items[o] || this._def.rest;
2104
- return f ? f._parse(new N(s, i, s.path, o)) : null;
2105
- }).filter((i) => !!i);
2106
- return s.common.async ? Promise.all(a).then((i) => k.mergeArray(t, i)) : k.mergeArray(t, a);
2107
- }
2108
- get items() {
2109
- return this._def.items;
2110
- }
2111
- rest(e) {
2112
- return new Z({
2113
- ...this._def,
2114
- rest: e
2115
- });
2116
- }
2117
- }
2118
- Z.create = (r, e) => {
2119
- if (!Array.isArray(r))
2120
- throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
2121
- return new Z({
2122
- items: r,
2123
- typeName: m.ZodTuple,
2124
- rest: null,
2125
- ...y(e)
2126
- });
2127
- };
2128
- class ee extends _ {
2129
- get keySchema() {
2130
- return this._def.keyType;
2131
- }
2132
- get valueSchema() {
2133
- return this._def.valueType;
2134
- }
2135
- _parse(e) {
2136
- const { status: t, ctx: s } = this._processInputParams(e);
2137
- if (s.parsedType !== u.object)
2138
- return d(s, {
2139
- code: c.invalid_type,
2140
- expected: u.object,
2141
- received: s.parsedType
2142
- }), p;
2143
- const n = [], a = this._def.keyType, i = this._def.valueType;
2144
- for (const o in s.data)
2145
- n.push({
2146
- key: a._parse(new N(s, o, s.path, o)),
2147
- value: i._parse(new N(s, s.data[o], s.path, o)),
2148
- alwaysSet: o in s.data
2149
- });
2150
- return s.common.async ? k.mergeObjectAsync(t, n) : k.mergeObjectSync(t, n);
2151
- }
2152
- get element() {
2153
- return this._def.valueType;
2154
- }
2155
- static create(e, t, s) {
2156
- return t instanceof _ ? new ee({
2157
- keyType: e,
2158
- valueType: t,
2159
- typeName: m.ZodRecord,
2160
- ...y(s)
2161
- }) : new ee({
2162
- keyType: C.create(),
2163
- valueType: e,
2164
- typeName: m.ZodRecord,
2165
- ...y(t)
2166
- });
2167
- }
2168
- }
2169
- class fe extends _ {
2170
- get keySchema() {
2171
- return this._def.keyType;
2172
- }
2173
- get valueSchema() {
2174
- return this._def.valueType;
2175
- }
2176
- _parse(e) {
2177
- const { status: t, ctx: s } = this._processInputParams(e);
2178
- if (s.parsedType !== u.map)
2179
- return d(s, {
2180
- code: c.invalid_type,
2181
- expected: u.map,
2182
- received: s.parsedType
2183
- }), p;
2184
- const n = this._def.keyType, a = this._def.valueType, i = [...s.data.entries()].map(([o, f], l) => ({
2185
- key: n._parse(new N(s, o, s.path, [l, "key"])),
2186
- value: a._parse(new N(s, f, s.path, [l, "value"]))
2187
- }));
2188
- if (s.common.async) {
2189
- const o = /* @__PURE__ */ new Map();
2190
- return Promise.resolve().then(async () => {
2191
- for (const f of i) {
2192
- const l = await f.key, g = await f.value;
2193
- if (l.status === "aborted" || g.status === "aborted")
2194
- return p;
2195
- (l.status === "dirty" || g.status === "dirty") && t.dirty(), o.set(l.value, g.value);
2196
- }
2197
- return { status: t.value, value: o };
2198
- });
2199
- } else {
2200
- const o = /* @__PURE__ */ new Map();
2201
- for (const f of i) {
2202
- const l = f.key, g = f.value;
2203
- if (l.status === "aborted" || g.status === "aborted")
2204
- return p;
2205
- (l.status === "dirty" || g.status === "dirty") && t.dirty(), o.set(l.value, g.value);
2206
- }
2207
- return { status: t.value, value: o };
2208
- }
2209
- }
2210
- }
2211
- fe.create = (r, e, t) => new fe({
2212
- valueType: e,
2213
- keyType: r,
2214
- typeName: m.ZodMap,
2215
- ...y(t)
2216
- });
2217
- class D extends _ {
2218
- _parse(e) {
2219
- const { status: t, ctx: s } = this._processInputParams(e);
2220
- if (s.parsedType !== u.set)
2221
- return d(s, {
2222
- code: c.invalid_type,
2223
- expected: u.set,
2224
- received: s.parsedType
2225
- }), p;
2226
- const n = this._def;
2227
- n.minSize !== null && s.data.size < n.minSize.value && (d(s, {
2228
- code: c.too_small,
2229
- minimum: n.minSize.value,
2230
- type: "set",
2231
- inclusive: !0,
2232
- exact: !1,
2233
- message: n.minSize.message
2234
- }), t.dirty()), n.maxSize !== null && s.data.size > n.maxSize.value && (d(s, {
2235
- code: c.too_big,
2236
- maximum: n.maxSize.value,
2237
- type: "set",
2238
- inclusive: !0,
2239
- exact: !1,
2240
- message: n.maxSize.message
2241
- }), t.dirty());
2242
- const a = this._def.valueType;
2243
- function i(f) {
2244
- const l = /* @__PURE__ */ new Set();
2245
- for (const g of f) {
2246
- if (g.status === "aborted")
2247
- return p;
2248
- g.status === "dirty" && t.dirty(), l.add(g.value);
2249
- }
2250
- return { status: t.value, value: l };
2251
- }
2252
- const o = [...s.data.values()].map((f, l) => a._parse(new N(s, f, s.path, l)));
2253
- return s.common.async ? Promise.all(o).then((f) => i(f)) : i(o);
2254
- }
2255
- min(e, t) {
2256
- return new D({
2257
- ...this._def,
2258
- minSize: { value: e, message: h.toString(t) }
2259
- });
2260
- }
2261
- max(e, t) {
2262
- return new D({
2263
- ...this._def,
2264
- maxSize: { value: e, message: h.toString(t) }
2265
- });
2266
- }
2267
- size(e, t) {
2268
- return this.min(e, t).max(e, t);
2269
- }
2270
- nonempty(e) {
2271
- return this.min(1, e);
2272
- }
2273
- }
2274
- D.create = (r, e) => new D({
2275
- valueType: r,
2276
- minSize: null,
2277
- maxSize: null,
2278
- typeName: m.ZodSet,
2279
- ...y(e)
2280
- });
2281
- class F extends _ {
2282
- constructor() {
2283
- super(...arguments), this.validate = this.implement;
2284
- }
2285
- _parse(e) {
2286
- const { ctx: t } = this._processInputParams(e);
2287
- if (t.parsedType !== u.function)
2288
- return d(t, {
2289
- code: c.invalid_type,
2290
- expected: u.function,
2291
- received: t.parsedType
2292
- }), p;
2293
- function s(o, f) {
2294
- return de({
2295
- data: o,
2296
- path: t.path,
2297
- errorMaps: [t.common.contextualErrorMap, t.schemaErrorMap, ce(), W].filter((l) => !!l),
2298
- issueData: {
2299
- code: c.invalid_arguments,
2300
- argumentsError: f
2301
- }
2302
- });
2303
- }
2304
- function n(o, f) {
2305
- return de({
2306
- data: o,
2307
- path: t.path,
2308
- errorMaps: [t.common.contextualErrorMap, t.schemaErrorMap, ce(), W].filter((l) => !!l),
2309
- issueData: {
2310
- code: c.invalid_return_type,
2311
- returnTypeError: f
2312
- }
2313
- });
2314
- }
2315
- const a = { errorMap: t.common.contextualErrorMap }, i = t.data;
2316
- if (this._def.returns instanceof J) {
2317
- const o = this;
2318
- return b(async function(...f) {
2319
- const l = new w([]), g = await o._def.args.parseAsync(f, a).catch((me) => {
2320
- throw l.addIssue(s(f, me)), l;
2321
- }), T = await Reflect.apply(i, this, g);
2322
- return await o._def.returns._def.type.parseAsync(T, a).catch((me) => {
2323
- throw l.addIssue(n(T, me)), l;
2324
- });
2325
- });
2326
- } else {
2327
- const o = this;
2328
- return b(function(...f) {
2329
- const l = o._def.args.safeParse(f, a);
2330
- if (!l.success)
2331
- throw new w([s(f, l.error)]);
2332
- const g = Reflect.apply(i, this, l.data), T = o._def.returns.safeParse(g, a);
2333
- if (!T.success)
2334
- throw new w([n(g, T.error)]);
2335
- return T.data;
2336
- });
2337
- }
2338
- }
2339
- parameters() {
2340
- return this._def.args;
2341
- }
2342
- returnType() {
2343
- return this._def.returns;
2344
- }
2345
- args(...e) {
2346
- return new F({
2347
- ...this._def,
2348
- args: Z.create(e).rest(P.create())
2349
- });
2350
- }
2351
- returns(e) {
2352
- return new F({
2353
- ...this._def,
2354
- returns: e
2355
- });
2356
- }
2357
- implement(e) {
2358
- return this.parse(e);
2359
- }
2360
- strictImplement(e) {
2361
- return this.parse(e);
2362
- }
2363
- static create(e, t, s) {
2364
- return new F({
2365
- args: e || Z.create([]).rest(P.create()),
2366
- returns: t || P.create(),
2367
- typeName: m.ZodFunction,
2368
- ...y(s)
2369
- });
2370
- }
2371
- }
2372
- class te extends _ {
2373
- get schema() {
2374
- return this._def.getter();
2375
- }
2376
- _parse(e) {
2377
- const { ctx: t } = this._processInputParams(e);
2378
- return this._def.getter()._parse({ data: t.data, path: t.path, parent: t });
2379
- }
2380
- }
2381
- te.create = (r, e) => new te({
2382
- getter: r,
2383
- typeName: m.ZodLazy,
2384
- ...y(e)
2385
- });
2386
- class re extends _ {
2387
- _parse(e) {
2388
- if (e.data !== this._def.value) {
2389
- const t = this._getOrReturnCtx(e);
2390
- return d(t, {
2391
- received: t.data,
2392
- code: c.invalid_literal,
2393
- expected: this._def.value
2394
- }), p;
2395
- }
2396
- return { status: "valid", value: e.data };
2397
- }
2398
- get value() {
2399
- return this._def.value;
2400
- }
2401
- }
2402
- re.create = (r, e) => new re({
2403
- value: r,
2404
- typeName: m.ZodLiteral,
2405
- ...y(e)
2406
- });
2407
- function Ze(r, e) {
2408
- return new M({
2409
- values: r,
2410
- typeName: m.ZodEnum,
2411
- ...y(e)
2412
- });
2413
- }
2414
- class M extends _ {
2415
- _parse(e) {
2416
- if (typeof e.data != "string") {
2417
- const t = this._getOrReturnCtx(e), s = this._def.values;
2418
- return d(t, {
2419
- expected: v.joinValues(s),
2420
- received: t.parsedType,
2421
- code: c.invalid_type
2422
- }), p;
2423
- }
2424
- if (this._cache || (this._cache = new Set(this._def.values)), !this._cache.has(e.data)) {
2425
- const t = this._getOrReturnCtx(e), s = this._def.values;
2426
- return d(t, {
2427
- received: t.data,
2428
- code: c.invalid_enum_value,
2429
- options: s
2430
- }), p;
2431
- }
2432
- return b(e.data);
2433
- }
2434
- get options() {
2435
- return this._def.values;
2436
- }
2437
- get enum() {
2438
- const e = {};
2439
- for (const t of this._def.values)
2440
- e[t] = t;
2441
- return e;
2442
- }
2443
- get Values() {
2444
- const e = {};
2445
- for (const t of this._def.values)
2446
- e[t] = t;
2447
- return e;
2448
- }
2449
- get Enum() {
2450
- const e = {};
2451
- for (const t of this._def.values)
2452
- e[t] = t;
2453
- return e;
2454
- }
2455
- extract(e, t = this._def) {
2456
- return M.create(e, {
2457
- ...this._def,
2458
- ...t
2459
- });
2460
- }
2461
- exclude(e, t = this._def) {
2462
- return M.create(this.options.filter((s) => !e.includes(s)), {
2463
- ...this._def,
2464
- ...t
2465
- });
2466
- }
2467
- }
2468
- M.create = Ze;
2469
- class se extends _ {
2470
- _parse(e) {
2471
- const t = v.getValidEnumValues(this._def.values), s = this._getOrReturnCtx(e);
2472
- if (s.parsedType !== u.string && s.parsedType !== u.number) {
2473
- const n = v.objectValues(t);
2474
- return d(s, {
2475
- expected: v.joinValues(n),
2476
- received: s.parsedType,
2477
- code: c.invalid_type
2478
- }), p;
2479
- }
2480
- if (this._cache || (this._cache = new Set(v.getValidEnumValues(this._def.values))), !this._cache.has(e.data)) {
2481
- const n = v.objectValues(t);
2482
- return d(s, {
2483
- received: s.data,
2484
- code: c.invalid_enum_value,
2485
- options: n
2486
- }), p;
2487
- }
2488
- return b(e.data);
2489
- }
2490
- get enum() {
2491
- return this._def.values;
2492
- }
2493
- }
2494
- se.create = (r, e) => new se({
2495
- values: r,
2496
- typeName: m.ZodNativeEnum,
2497
- ...y(e)
2498
- });
2499
- class J extends _ {
2500
- unwrap() {
2501
- return this._def.type;
2502
- }
2503
- _parse(e) {
2504
- const { ctx: t } = this._processInputParams(e);
2505
- if (t.parsedType !== u.promise && t.common.async === !1)
2506
- return d(t, {
2507
- code: c.invalid_type,
2508
- expected: u.promise,
2509
- received: t.parsedType
2510
- }), p;
2511
- const s = t.parsedType === u.promise ? t.data : Promise.resolve(t.data);
2512
- return b(s.then((n) => this._def.type.parseAsync(n, {
2513
- path: t.path,
2514
- errorMap: t.common.contextualErrorMap
2515
- })));
2516
- }
2517
- }
2518
- J.create = (r, e) => new J({
2519
- type: r,
2520
- typeName: m.ZodPromise,
2521
- ...y(e)
2522
- });
2523
- class O extends _ {
2524
- innerType() {
2525
- return this._def.schema;
2526
- }
2527
- sourceType() {
2528
- return this._def.schema._def.typeName === m.ZodEffects ? this._def.schema.sourceType() : this._def.schema;
2529
- }
2530
- _parse(e) {
2531
- const { status: t, ctx: s } = this._processInputParams(e), n = this._def.effect || null, a = {
2532
- addIssue: (i) => {
2533
- d(s, i), i.fatal ? t.abort() : t.dirty();
2534
- },
2535
- get path() {
2536
- return s.path;
2537
- }
2538
- };
2539
- if (a.addIssue = a.addIssue.bind(a), n.type === "preprocess") {
2540
- const i = n.transform(s.data, a);
2541
- if (s.common.async)
2542
- return Promise.resolve(i).then(async (o) => {
2543
- if (t.value === "aborted")
2544
- return p;
2545
- const f = await this._def.schema._parseAsync({
2546
- data: o,
2547
- path: s.path,
2548
- parent: s
2549
- });
2550
- return f.status === "aborted" ? p : f.status === "dirty" || t.value === "dirty" ? B(f.value) : f;
2551
- });
2552
- {
2553
- if (t.value === "aborted")
2554
- return p;
2555
- const o = this._def.schema._parseSync({
2556
- data: i,
2557
- path: s.path,
2558
- parent: s
2559
- });
2560
- return o.status === "aborted" ? p : o.status === "dirty" || t.value === "dirty" ? B(o.value) : o;
2561
- }
2562
- }
2563
- if (n.type === "refinement") {
2564
- const i = (o) => {
2565
- const f = n.refinement(o, a);
2566
- if (s.common.async)
2567
- return Promise.resolve(f);
2568
- if (f instanceof Promise)
2569
- throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
2570
- return o;
2571
- };
2572
- if (s.common.async === !1) {
2573
- const o = this._def.schema._parseSync({
2574
- data: s.data,
2575
- path: s.path,
2576
- parent: s
2577
- });
2578
- return o.status === "aborted" ? p : (o.status === "dirty" && t.dirty(), i(o.value), { status: t.value, value: o.value });
2579
- } else
2580
- return this._def.schema._parseAsync({ data: s.data, path: s.path, parent: s }).then((o) => o.status === "aborted" ? p : (o.status === "dirty" && t.dirty(), i(o.value).then(() => ({ status: t.value, value: o.value }))));
2581
- }
2582
- if (n.type === "transform")
2583
- if (s.common.async === !1) {
2584
- const i = this._def.schema._parseSync({
2585
- data: s.data,
2586
- path: s.path,
2587
- parent: s
2588
- });
2589
- if (!z(i))
2590
- return p;
2591
- const o = n.transform(i.value, a);
2592
- if (o instanceof Promise)
2593
- throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");
2594
- return { status: t.value, value: o };
2595
- } else
2596
- return this._def.schema._parseAsync({ data: s.data, path: s.path, parent: s }).then((i) => z(i) ? Promise.resolve(n.transform(i.value, a)).then((o) => ({
2597
- status: t.value,
2598
- value: o
2599
- })) : p);
2600
- v.assertNever(n);
2601
- }
2602
- }
2603
- O.create = (r, e, t) => new O({
2604
- schema: r,
2605
- typeName: m.ZodEffects,
2606
- effect: e,
2607
- ...y(t)
2608
- });
2609
- O.createWithPreprocess = (r, e, t) => new O({
2610
- schema: e,
2611
- effect: { type: "preprocess", transform: r },
2612
- typeName: m.ZodEffects,
2613
- ...y(t)
2614
- });
2615
- class A extends _ {
2616
- _parse(e) {
2617
- return this._getType(e) === u.undefined ? b(void 0) : this._def.innerType._parse(e);
2618
- }
2619
- unwrap() {
2620
- return this._def.innerType;
2621
- }
2622
- }
2623
- A.create = (r, e) => new A({
2624
- innerType: r,
2625
- typeName: m.ZodOptional,
2626
- ...y(e)
2627
- });
2628
- class V extends _ {
2629
- _parse(e) {
2630
- return this._getType(e) === u.null ? b(null) : this._def.innerType._parse(e);
2631
- }
2632
- unwrap() {
2633
- return this._def.innerType;
2634
- }
2635
- }
2636
- V.create = (r, e) => new V({
2637
- innerType: r,
2638
- typeName: m.ZodNullable,
2639
- ...y(e)
2640
- });
2641
- class ne extends _ {
2642
- _parse(e) {
2643
- const { ctx: t } = this._processInputParams(e);
2644
- let s = t.data;
2645
- return t.parsedType === u.undefined && (s = this._def.defaultValue()), this._def.innerType._parse({
2646
- data: s,
2647
- path: t.path,
2648
- parent: t
2649
- });
2650
- }
2651
- removeDefault() {
2652
- return this._def.innerType;
2653
- }
2654
- }
2655
- ne.create = (r, e) => new ne({
2656
- innerType: r,
2657
- typeName: m.ZodDefault,
2658
- defaultValue: typeof e.default == "function" ? e.default : () => e.default,
2659
- ...y(e)
2660
- });
2661
- class ae extends _ {
2662
- _parse(e) {
2663
- const { ctx: t } = this._processInputParams(e), s = {
2664
- ...t,
2665
- common: {
2666
- ...t.common,
2667
- issues: []
2668
- }
2669
- }, n = this._def.innerType._parse({
2670
- data: s.data,
2671
- path: s.path,
2672
- parent: {
2673
- ...s
2674
- }
2675
- });
2676
- return Y(n) ? n.then((a) => ({
2677
- status: "valid",
2678
- value: a.status === "valid" ? a.value : this._def.catchValue({
2679
- get error() {
2680
- return new w(s.common.issues);
2681
- },
2682
- input: s.data
2683
- })
2684
- })) : {
2685
- status: "valid",
2686
- value: n.status === "valid" ? n.value : this._def.catchValue({
2687
- get error() {
2688
- return new w(s.common.issues);
2689
- },
2690
- input: s.data
2691
- })
2692
- };
2693
- }
2694
- removeCatch() {
2695
- return this._def.innerType;
2696
- }
2697
- }
2698
- ae.create = (r, e) => new ae({
2699
- innerType: r,
2700
- typeName: m.ZodCatch,
2701
- catchValue: typeof e.catch == "function" ? e.catch : () => e.catch,
2702
- ...y(e)
2703
- });
2704
- class he extends _ {
2705
- _parse(e) {
2706
- if (this._getType(e) !== u.nan) {
2707
- const s = this._getOrReturnCtx(e);
2708
- return d(s, {
2709
- code: c.invalid_type,
2710
- expected: u.nan,
2711
- received: s.parsedType
2712
- }), p;
2713
- }
2714
- return { status: "valid", value: e.data };
2715
- }
2716
- }
2717
- he.create = (r) => new he({
2718
- typeName: m.ZodNaN,
2719
- ...y(r)
2720
- });
2721
- const at = Symbol("zod_brand");
2722
- class ke extends _ {
2723
- _parse(e) {
2724
- const { ctx: t } = this._processInputParams(e), s = t.data;
2725
- return this._def.type._parse({
2726
- data: s,
2727
- path: t.path,
2728
- parent: t
2729
- });
2730
- }
2731
- unwrap() {
2732
- return this._def.type;
2733
- }
2734
- }
2735
- class oe extends _ {
2736
- _parse(e) {
2737
- const { status: t, ctx: s } = this._processInputParams(e);
2738
- if (s.common.async)
2739
- return (async () => {
2740
- const a = await this._def.in._parseAsync({
2741
- data: s.data,
2742
- path: s.path,
2743
- parent: s
2744
- });
2745
- return a.status === "aborted" ? p : a.status === "dirty" ? (t.dirty(), B(a.value)) : this._def.out._parseAsync({
2746
- data: a.value,
2747
- path: s.path,
2748
- parent: s
2749
- });
2750
- })();
2751
- {
2752
- const n = this._def.in._parseSync({
2753
- data: s.data,
2754
- path: s.path,
2755
- parent: s
2756
- });
2757
- return n.status === "aborted" ? p : n.status === "dirty" ? (t.dirty(), {
2758
- status: "dirty",
2759
- value: n.value
2760
- }) : this._def.out._parseSync({
2761
- data: n.value,
2762
- path: s.path,
2763
- parent: s
2764
- });
2765
- }
2766
- }
2767
- static create(e, t) {
2768
- return new oe({
2769
- in: e,
2770
- out: t,
2771
- typeName: m.ZodPipeline
2772
- });
2773
- }
2774
- }
2775
- class ie extends _ {
2776
- _parse(e) {
2777
- const t = this._def.innerType._parse(e), s = (n) => (z(n) && (n.value = Object.freeze(n.value)), n);
2778
- return Y(t) ? t.then((n) => s(n)) : s(t);
2779
- }
2780
- unwrap() {
2781
- return this._def.innerType;
2782
- }
2783
- }
2784
- ie.create = (r, e) => new ie({
2785
- innerType: r,
2786
- typeName: m.ZodReadonly,
2787
- ...y(e)
2788
- });
2789
- function Te(r, e) {
2790
- const t = typeof r == "function" ? r(e) : typeof r == "string" ? { message: r } : r;
2791
- return typeof t == "string" ? { message: t } : t;
2792
- }
2793
- function Re(r, e = {}, t) {
2794
- return r ? q.create().superRefine((s, n) => {
2795
- const a = r(s);
2796
- if (a instanceof Promise)
2797
- return a.then((i) => {
2798
- if (!i) {
2799
- const o = Te(e, s), f = o.fatal ?? t ?? !0;
2800
- n.addIssue({ code: "custom", ...o, fatal: f });
2801
- }
2802
- });
2803
- if (!a) {
2804
- const i = Te(e, s), o = i.fatal ?? t ?? !0;
2805
- n.addIssue({ code: "custom", ...i, fatal: o });
2806
- }
2807
- }) : q.create();
2808
- }
2809
- const it = {
2810
- object: x.lazycreate
2811
- };
2812
- var m;
2813
- (function(r) {
2814
- r.ZodString = "ZodString", r.ZodNumber = "ZodNumber", r.ZodNaN = "ZodNaN", r.ZodBigInt = "ZodBigInt", r.ZodBoolean = "ZodBoolean", r.ZodDate = "ZodDate", r.ZodSymbol = "ZodSymbol", r.ZodUndefined = "ZodUndefined", r.ZodNull = "ZodNull", r.ZodAny = "ZodAny", r.ZodUnknown = "ZodUnknown", r.ZodNever = "ZodNever", r.ZodVoid = "ZodVoid", r.ZodArray = "ZodArray", r.ZodObject = "ZodObject", r.ZodUnion = "ZodUnion", r.ZodDiscriminatedUnion = "ZodDiscriminatedUnion", r.ZodIntersection = "ZodIntersection", r.ZodTuple = "ZodTuple", r.ZodRecord = "ZodRecord", r.ZodMap = "ZodMap", r.ZodSet = "ZodSet", r.ZodFunction = "ZodFunction", r.ZodLazy = "ZodLazy", r.ZodLiteral = "ZodLiteral", r.ZodEnum = "ZodEnum", r.ZodEffects = "ZodEffects", r.ZodNativeEnum = "ZodNativeEnum", r.ZodOptional = "ZodOptional", r.ZodNullable = "ZodNullable", r.ZodDefault = "ZodDefault", r.ZodCatch = "ZodCatch", r.ZodPromise = "ZodPromise", r.ZodBranded = "ZodBranded", r.ZodPipeline = "ZodPipeline", r.ZodReadonly = "ZodReadonly";
2815
- })(m || (m = {}));
2816
- const ot = (r, e = {
2817
- message: `Input not instance of ${r.name}`
2818
- }) => Re((t) => t instanceof r, e), je = C.create, Ee = I.create, ct = he.create, dt = $.create, Ie = H.create, ut = L.create, lt = ue.create, ft = G.create, ht = Q.create, pt = q.create, mt = P.create, yt = E.create, _t = le.create, gt = S.create, vt = x.create, xt = x.strictCreate, kt = X.create, bt = pe.create, wt = K.create, Tt = Z.create, Ct = ee.create, St = fe.create, Ot = D.create, At = F.create, Nt = te.create, Zt = re.create, Rt = M.create, jt = se.create, Et = J.create, Ce = O.create, It = A.create, $t = V.create, Mt = O.createWithPreprocess, Vt = oe.create, Pt = () => je().optional(), zt = () => Ee().optional(), Lt = () => Ie().optional(), Dt = {
2819
- string: ((r) => C.create({ ...r, coerce: !0 })),
2820
- number: ((r) => I.create({ ...r, coerce: !0 })),
2821
- boolean: ((r) => H.create({
2822
- ...r,
2823
- coerce: !0
2824
- })),
2825
- bigint: ((r) => $.create({ ...r, coerce: !0 })),
2826
- date: ((r) => L.create({ ...r, coerce: !0 }))
2827
- }, Ut = p, Bt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
2828
- __proto__: null,
2829
- BRAND: at,
2830
- DIRTY: B,
2831
- EMPTY_PATH: Ve,
2832
- INVALID: p,
2833
- NEVER: Ut,
2834
- OK: b,
2835
- ParseStatus: k,
2836
- Schema: _,
2837
- ZodAny: q,
2838
- ZodArray: S,
2839
- ZodBigInt: $,
2840
- ZodBoolean: H,
2841
- ZodBranded: ke,
2842
- ZodCatch: ae,
2843
- ZodDate: L,
2844
- ZodDefault: ne,
2845
- ZodDiscriminatedUnion: pe,
2846
- ZodEffects: O,
2847
- ZodEnum: M,
2848
- ZodError: w,
2849
- get ZodFirstPartyTypeKind() {
2850
- return m;
2851
- },
2852
- ZodFunction: F,
2853
- ZodIntersection: K,
2854
- ZodIssueCode: c,
2855
- ZodLazy: te,
2856
- ZodLiteral: re,
2857
- ZodMap: fe,
2858
- ZodNaN: he,
2859
- ZodNativeEnum: se,
2860
- ZodNever: E,
2861
- ZodNull: Q,
2862
- ZodNullable: V,
2863
- ZodNumber: I,
2864
- ZodObject: x,
2865
- ZodOptional: A,
2866
- ZodParsedType: u,
2867
- ZodPipeline: oe,
2868
- ZodPromise: J,
2869
- ZodReadonly: ie,
2870
- ZodRecord: ee,
2871
- ZodSchema: _,
2872
- ZodSet: D,
2873
- ZodString: C,
2874
- ZodSymbol: ue,
2875
- ZodTransformer: O,
2876
- ZodTuple: Z,
2877
- ZodType: _,
2878
- ZodUndefined: G,
2879
- ZodUnion: X,
2880
- ZodUnknown: P,
2881
- ZodVoid: le,
2882
- addIssueToContext: d,
2883
- any: pt,
2884
- array: gt,
2885
- bigint: dt,
2886
- boolean: Ie,
2887
- coerce: Dt,
2888
- custom: Re,
2889
- date: ut,
2890
- datetimeRegex: Ne,
2891
- defaultErrorMap: W,
2892
- discriminatedUnion: bt,
2893
- effect: Ce,
2894
- enum: Rt,
2895
- function: At,
2896
- getErrorMap: ce,
2897
- getParsedType: j,
2898
- instanceof: ot,
2899
- intersection: wt,
2900
- isAborted: ge,
2901
- isAsync: Y,
2902
- isDirty: ve,
2903
- isValid: z,
2904
- late: it,
2905
- lazy: Nt,
2906
- literal: Zt,
2907
- makeIssue: de,
2908
- map: St,
2909
- nan: ct,
2910
- nativeEnum: jt,
2911
- never: yt,
2912
- null: ht,
2913
- nullable: $t,
2914
- number: Ee,
2915
- object: vt,
2916
- get objectUtil() {
2917
- return _e;
2918
- },
2919
- oboolean: Lt,
2920
- onumber: zt,
2921
- optional: It,
2922
- ostring: Pt,
2923
- pipeline: Vt,
2924
- preprocess: Mt,
2925
- promise: Et,
2926
- quotelessJson: $e,
2927
- record: Ct,
2928
- set: Ot,
2929
- setErrorMap: Me,
2930
- strictObject: xt,
2931
- string: je,
2932
- symbol: lt,
2933
- transformer: Ce,
2934
- tuple: Tt,
2935
- undefined: ft,
2936
- union: kt,
2937
- unknown: mt,
2938
- get util() {
2939
- return v;
2940
- },
2941
- void: _t
2942
- }, Symbol.toStringTag, { value: "Module" }));
2943
- export {
2944
- Bt as z
2945
- };