@verdocs/web-sdk 2.1.4 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/dist/cjs/Profiles-244e8254.js +95 -0
  2. package/dist/cjs/loader.cjs.js +1 -1
  3. package/dist/cjs/verdocs-auth.cjs.entry.js +3 -44
  4. package/dist/cjs/verdocs-button_2.cjs.entry.js +65 -0
  5. package/dist/cjs/{verdocs-checkbox_5.cjs.entry.js → verdocs-checkbox_4.cjs.entry.js} +0 -39
  6. package/dist/cjs/verdocs-settings-organization_2.cjs.entry.js +4383 -0
  7. package/dist/cjs/verdocs-settings.cjs.entry.js +42 -0
  8. package/dist/cjs/verdocs-web-sdk.cjs.js +1 -1
  9. package/dist/collection/collection-manifest.json +3 -0
  10. package/dist/collection/components/embeds/verdocs-settings/verdocs-settings.css +29 -0
  11. package/dist/collection/components/embeds/verdocs-settings/verdocs-settings.js +98 -0
  12. package/dist/collection/components/embeds/verdocs-settings/verdocs-settings.stories.js +10 -0
  13. package/dist/collection/components/settings/verdocs-settings-organization/TimeZones.js +144 -0
  14. package/dist/collection/components/settings/verdocs-settings-organization/verdocs-settings-organization.css +33 -0
  15. package/dist/collection/components/settings/verdocs-settings-organization/verdocs-settings-organization.js +226 -0
  16. package/dist/collection/components/settings/verdocs-settings-organization/verdocs-settings-organization.stories.js +13 -0
  17. package/dist/collection/components/settings/verdocs-settings-profile/verdocs-settings-profile.css +33 -0
  18. package/dist/collection/components/settings/verdocs-settings-profile/verdocs-settings-profile.js +187 -0
  19. package/dist/collection/components/settings/verdocs-settings-profile/verdocs-settings-profile.stories.js +13 -0
  20. package/dist/components/EnvelopeStore.js +1 -1
  21. package/dist/components/Organizations.js +32 -0
  22. package/dist/components/Profiles.js +57 -0
  23. package/dist/components/TemplateStore.js +1 -1
  24. package/dist/components/index.d.ts +3 -0
  25. package/dist/components/index.js +3 -0
  26. package/dist/components/index3.js +3979 -168
  27. package/dist/components/index4.js +194 -0
  28. package/dist/components/verdocs-auth.js +2 -42
  29. package/dist/components/verdocs-settings-organization.d.ts +11 -0
  30. package/dist/components/verdocs-settings-organization.js +6 -0
  31. package/dist/components/verdocs-settings-organization2.js +331 -0
  32. package/dist/components/verdocs-settings-profile.d.ts +11 -0
  33. package/dist/components/verdocs-settings-profile.js +6 -0
  34. package/dist/components/verdocs-settings-profile2.js +142 -0
  35. package/dist/components/verdocs-settings.d.ts +11 -0
  36. package/dist/components/verdocs-settings.js +101 -0
  37. package/dist/custom-elements.json +1975 -0
  38. package/dist/docs.json +234 -1
  39. package/dist/esm/Profiles-7645e6f1.js +88 -0
  40. package/dist/esm/loader.js +1 -1
  41. package/dist/esm/verdocs-auth.entry.js +1 -42
  42. package/dist/esm/verdocs-button_2.entry.js +60 -0
  43. package/dist/esm/{verdocs-checkbox_5.entry.js → verdocs-checkbox_4.entry.js} +1 -39
  44. package/dist/esm/verdocs-settings-organization_2.entry.js +4378 -0
  45. package/dist/esm/verdocs-settings.entry.js +38 -0
  46. package/dist/esm/verdocs-web-sdk.js +1 -1
  47. package/dist/esm-es5/Profiles-7645e6f1.js +1 -0
  48. package/dist/esm-es5/loader.js +1 -1
  49. package/dist/esm-es5/verdocs-auth.entry.js +1 -1
  50. package/dist/esm-es5/verdocs-button_2.entry.js +1 -0
  51. package/dist/esm-es5/verdocs-checkbox_4.entry.js +1 -0
  52. package/dist/esm-es5/verdocs-settings-organization_2.entry.js +1 -0
  53. package/dist/esm-es5/verdocs-settings.entry.js +1 -0
  54. package/dist/esm-es5/verdocs-web-sdk.js +1 -1
  55. package/dist/types/components/embeds/verdocs-settings/verdocs-settings.d.ts +22 -0
  56. package/dist/types/components/embeds/verdocs-settings/verdocs-settings.stories.d.ts +4 -0
  57. package/dist/types/components/settings/verdocs-settings-organization/TimeZones.d.ts +1 -0
  58. package/dist/types/components/settings/verdocs-settings-organization/verdocs-settings-organization.d.ts +42 -0
  59. package/dist/types/components/settings/verdocs-settings-organization/verdocs-settings-organization.stories.d.ts +6 -0
  60. package/dist/types/components/settings/verdocs-settings-profile/verdocs-settings-profile.d.ts +38 -0
  61. package/dist/types/components/settings/verdocs-settings-profile/verdocs-settings-profile.stories.d.ts +6 -0
  62. package/dist/types/components.d.ts +96 -0
  63. package/dist/verdocs-web-sdk/p-075dc36d.js +1 -0
  64. package/dist/verdocs-web-sdk/p-0fecb805.entry.js +1 -0
  65. package/dist/verdocs-web-sdk/p-144d4ed1.system.entry.js +1 -0
  66. package/dist/verdocs-web-sdk/p-229a6849.entry.js +1 -0
  67. package/dist/verdocs-web-sdk/p-40361f22.entry.js +1 -0
  68. package/dist/verdocs-web-sdk/p-4821f318.system.entry.js +1 -0
  69. package/dist/verdocs-web-sdk/p-647cdb84.system.js +1 -1
  70. package/dist/verdocs-web-sdk/p-888adbc2.system.entry.js +1 -0
  71. package/dist/verdocs-web-sdk/p-cbebc039.system.js +1 -0
  72. package/dist/verdocs-web-sdk/p-ce22913a.entry.js +1 -0
  73. package/dist/verdocs-web-sdk/p-de192808.system.entry.js +1 -0
  74. package/dist/verdocs-web-sdk/p-e9d2b68a.entry.js +1 -0
  75. package/dist/verdocs-web-sdk/p-febebe69.system.entry.js +1 -0
  76. package/dist/verdocs-web-sdk/verdocs-web-sdk.esm.js +1 -1
  77. package/package.json +3 -2
  78. package/dist/cjs/verdocs-button.cjs.entry.js +0 -26
  79. package/dist/esm/verdocs-button.entry.js +0 -22
  80. package/dist/esm-es5/verdocs-button.entry.js +0 -1
  81. package/dist/esm-es5/verdocs-checkbox_5.entry.js +0 -1
  82. package/dist/verdocs-web-sdk/p-25916fc3.entry.js +0 -1
  83. package/dist/verdocs-web-sdk/p-300a240d.entry.js +0 -1
  84. package/dist/verdocs-web-sdk/p-5e5eb075.system.entry.js +0 -1
  85. package/dist/verdocs-web-sdk/p-606e0405.entry.js +0 -1
  86. package/dist/verdocs-web-sdk/p-b75d3b7f.system.entry.js +0 -1
  87. package/dist/verdocs-web-sdk/p-fbabbcea.system.entry.js +0 -1
@@ -0,0 +1,4383 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const index = require('./index-1d5fc518.js');
6
+ require('./Types-f89f9116.js');
7
+ const Profiles = require('./Profiles-244e8254.js');
8
+ const VerdocsEndpoint = require('./VerdocsEndpoint-45deeb6a.js');
9
+ const utils = require('./utils-fe5b1d83.js');
10
+ const Toast = require('./Toast-06880504.js');
11
+ require('./_commonjsHelpers-0c557e26.js');
12
+ require('./Envelopes-19ff627a.js');
13
+ require('./Files-4bdc0c0f.js');
14
+ require('./Types-ee5afdf8.js');
15
+ require('./index-7c19ba1d.js');
16
+
17
+ var util;
18
+ (function (util) {
19
+ util.assertEqual = (val) => val;
20
+ function assertIs(_arg) { }
21
+ util.assertIs = assertIs;
22
+ function assertNever(_x) {
23
+ throw new Error();
24
+ }
25
+ util.assertNever = assertNever;
26
+ util.arrayToEnum = (items) => {
27
+ const obj = {};
28
+ for (const item of items) {
29
+ obj[item] = item;
30
+ }
31
+ return obj;
32
+ };
33
+ util.getValidEnumValues = (obj) => {
34
+ const validKeys = util.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
35
+ const filtered = {};
36
+ for (const k of validKeys) {
37
+ filtered[k] = obj[k];
38
+ }
39
+ return util.objectValues(filtered);
40
+ };
41
+ util.objectValues = (obj) => {
42
+ return util.objectKeys(obj).map(function (e) {
43
+ return obj[e];
44
+ });
45
+ };
46
+ util.objectKeys = typeof Object.keys === "function" // eslint-disable-line ban/ban
47
+ ? (obj) => Object.keys(obj) // eslint-disable-line ban/ban
48
+ : (object) => {
49
+ const keys = [];
50
+ for (const key in object) {
51
+ if (Object.prototype.hasOwnProperty.call(object, key)) {
52
+ keys.push(key);
53
+ }
54
+ }
55
+ return keys;
56
+ };
57
+ util.find = (arr, checker) => {
58
+ for (const item of arr) {
59
+ if (checker(item))
60
+ return item;
61
+ }
62
+ return undefined;
63
+ };
64
+ util.isInteger = typeof Number.isInteger === "function"
65
+ ? (val) => Number.isInteger(val) // eslint-disable-line ban/ban
66
+ : (val) => typeof val === "number" && isFinite(val) && Math.floor(val) === val;
67
+ function joinValues(array, separator = " | ") {
68
+ return array
69
+ .map((val) => (typeof val === "string" ? `'${val}'` : val))
70
+ .join(separator);
71
+ }
72
+ util.joinValues = joinValues;
73
+ util.jsonStringifyReplacer = (_, value) => {
74
+ if (typeof value === "bigint") {
75
+ return value.toString();
76
+ }
77
+ return value;
78
+ };
79
+ })(util || (util = {}));
80
+ var objectUtil;
81
+ (function (objectUtil) {
82
+ objectUtil.mergeShapes = (first, second) => {
83
+ return {
84
+ ...first,
85
+ ...second, // second overwrites first
86
+ };
87
+ };
88
+ })(objectUtil || (objectUtil = {}));
89
+ const ZodParsedType = util.arrayToEnum([
90
+ "string",
91
+ "nan",
92
+ "number",
93
+ "integer",
94
+ "float",
95
+ "boolean",
96
+ "date",
97
+ "bigint",
98
+ "symbol",
99
+ "function",
100
+ "undefined",
101
+ "null",
102
+ "array",
103
+ "object",
104
+ "unknown",
105
+ "promise",
106
+ "void",
107
+ "never",
108
+ "map",
109
+ "set",
110
+ ]);
111
+ const getParsedType = (data) => {
112
+ const t = typeof data;
113
+ switch (t) {
114
+ case "undefined":
115
+ return ZodParsedType.undefined;
116
+ case "string":
117
+ return ZodParsedType.string;
118
+ case "number":
119
+ return isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
120
+ case "boolean":
121
+ return ZodParsedType.boolean;
122
+ case "function":
123
+ return ZodParsedType.function;
124
+ case "bigint":
125
+ return ZodParsedType.bigint;
126
+ case "symbol":
127
+ return ZodParsedType.symbol;
128
+ case "object":
129
+ if (Array.isArray(data)) {
130
+ return ZodParsedType.array;
131
+ }
132
+ if (data === null) {
133
+ return ZodParsedType.null;
134
+ }
135
+ if (data.then &&
136
+ typeof data.then === "function" &&
137
+ data.catch &&
138
+ typeof data.catch === "function") {
139
+ return ZodParsedType.promise;
140
+ }
141
+ if (typeof Map !== "undefined" && data instanceof Map) {
142
+ return ZodParsedType.map;
143
+ }
144
+ if (typeof Set !== "undefined" && data instanceof Set) {
145
+ return ZodParsedType.set;
146
+ }
147
+ if (typeof Date !== "undefined" && data instanceof Date) {
148
+ return ZodParsedType.date;
149
+ }
150
+ return ZodParsedType.object;
151
+ default:
152
+ return ZodParsedType.unknown;
153
+ }
154
+ };
155
+
156
+ const ZodIssueCode = util.arrayToEnum([
157
+ "invalid_type",
158
+ "invalid_literal",
159
+ "custom",
160
+ "invalid_union",
161
+ "invalid_union_discriminator",
162
+ "invalid_enum_value",
163
+ "unrecognized_keys",
164
+ "invalid_arguments",
165
+ "invalid_return_type",
166
+ "invalid_date",
167
+ "invalid_string",
168
+ "too_small",
169
+ "too_big",
170
+ "invalid_intersection_types",
171
+ "not_multiple_of",
172
+ "not_finite",
173
+ ]);
174
+ const quotelessJson = (obj) => {
175
+ const json = JSON.stringify(obj, null, 2);
176
+ return json.replace(/"([^"]+)":/g, "$1:");
177
+ };
178
+ class ZodError extends Error {
179
+ constructor(issues) {
180
+ super();
181
+ this.issues = [];
182
+ this.addIssue = (sub) => {
183
+ this.issues = [...this.issues, sub];
184
+ };
185
+ this.addIssues = (subs = []) => {
186
+ this.issues = [...this.issues, ...subs];
187
+ };
188
+ const actualProto = new.target.prototype;
189
+ if (Object.setPrototypeOf) {
190
+ // eslint-disable-next-line ban/ban
191
+ Object.setPrototypeOf(this, actualProto);
192
+ }
193
+ else {
194
+ this.__proto__ = actualProto;
195
+ }
196
+ this.name = "ZodError";
197
+ this.issues = issues;
198
+ }
199
+ get errors() {
200
+ return this.issues;
201
+ }
202
+ format(_mapper) {
203
+ const mapper = _mapper ||
204
+ function (issue) {
205
+ return issue.message;
206
+ };
207
+ const fieldErrors = { _errors: [] };
208
+ const processError = (error) => {
209
+ for (const issue of error.issues) {
210
+ if (issue.code === "invalid_union") {
211
+ issue.unionErrors.map(processError);
212
+ }
213
+ else if (issue.code === "invalid_return_type") {
214
+ processError(issue.returnTypeError);
215
+ }
216
+ else if (issue.code === "invalid_arguments") {
217
+ processError(issue.argumentsError);
218
+ }
219
+ else if (issue.path.length === 0) {
220
+ fieldErrors._errors.push(mapper(issue));
221
+ }
222
+ else {
223
+ let curr = fieldErrors;
224
+ let i = 0;
225
+ while (i < issue.path.length) {
226
+ const el = issue.path[i];
227
+ const terminal = i === issue.path.length - 1;
228
+ if (!terminal) {
229
+ curr[el] = curr[el] || { _errors: [] };
230
+ // if (typeof el === "string") {
231
+ // curr[el] = curr[el] || { _errors: [] };
232
+ // } else if (typeof el === "number") {
233
+ // const errorArray: any = [];
234
+ // errorArray._errors = [];
235
+ // curr[el] = curr[el] || errorArray;
236
+ // }
237
+ }
238
+ else {
239
+ curr[el] = curr[el] || { _errors: [] };
240
+ curr[el]._errors.push(mapper(issue));
241
+ }
242
+ curr = curr[el];
243
+ i++;
244
+ }
245
+ }
246
+ }
247
+ };
248
+ processError(this);
249
+ return fieldErrors;
250
+ }
251
+ toString() {
252
+ return this.message;
253
+ }
254
+ get message() {
255
+ return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2);
256
+ }
257
+ get isEmpty() {
258
+ return this.issues.length === 0;
259
+ }
260
+ flatten(mapper = (issue) => issue.message) {
261
+ const fieldErrors = {};
262
+ const formErrors = [];
263
+ for (const sub of this.issues) {
264
+ if (sub.path.length > 0) {
265
+ fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
266
+ fieldErrors[sub.path[0]].push(mapper(sub));
267
+ }
268
+ else {
269
+ formErrors.push(mapper(sub));
270
+ }
271
+ }
272
+ return { formErrors, fieldErrors };
273
+ }
274
+ get formErrors() {
275
+ return this.flatten();
276
+ }
277
+ }
278
+ ZodError.create = (issues) => {
279
+ const error = new ZodError(issues);
280
+ return error;
281
+ };
282
+
283
+ const errorMap = (issue, _ctx) => {
284
+ let message;
285
+ switch (issue.code) {
286
+ case ZodIssueCode.invalid_type:
287
+ if (issue.received === ZodParsedType.undefined) {
288
+ message = "Required";
289
+ }
290
+ else {
291
+ message = `Expected ${issue.expected}, received ${issue.received}`;
292
+ }
293
+ break;
294
+ case ZodIssueCode.invalid_literal:
295
+ message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util.jsonStringifyReplacer)}`;
296
+ break;
297
+ case ZodIssueCode.unrecognized_keys:
298
+ message = `Unrecognized key(s) in object: ${util.joinValues(issue.keys, ", ")}`;
299
+ break;
300
+ case ZodIssueCode.invalid_union:
301
+ message = `Invalid input`;
302
+ break;
303
+ case ZodIssueCode.invalid_union_discriminator:
304
+ message = `Invalid discriminator value. Expected ${util.joinValues(issue.options)}`;
305
+ break;
306
+ case ZodIssueCode.invalid_enum_value:
307
+ message = `Invalid enum value. Expected ${util.joinValues(issue.options)}, received '${issue.received}'`;
308
+ break;
309
+ case ZodIssueCode.invalid_arguments:
310
+ message = `Invalid function arguments`;
311
+ break;
312
+ case ZodIssueCode.invalid_return_type:
313
+ message = `Invalid function return type`;
314
+ break;
315
+ case ZodIssueCode.invalid_date:
316
+ message = `Invalid date`;
317
+ break;
318
+ case ZodIssueCode.invalid_string:
319
+ if (typeof issue.validation === "object") {
320
+ if ("includes" in issue.validation) {
321
+ message = `Invalid input: must include "${issue.validation.includes}"`;
322
+ if (typeof issue.validation.position === "number") {
323
+ message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`;
324
+ }
325
+ }
326
+ else if ("startsWith" in issue.validation) {
327
+ message = `Invalid input: must start with "${issue.validation.startsWith}"`;
328
+ }
329
+ else if ("endsWith" in issue.validation) {
330
+ message = `Invalid input: must end with "${issue.validation.endsWith}"`;
331
+ }
332
+ else {
333
+ util.assertNever(issue.validation);
334
+ }
335
+ }
336
+ else if (issue.validation !== "regex") {
337
+ message = `Invalid ${issue.validation}`;
338
+ }
339
+ else {
340
+ message = "Invalid";
341
+ }
342
+ break;
343
+ case ZodIssueCode.too_small:
344
+ if (issue.type === "array")
345
+ message = `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`;
346
+ else if (issue.type === "string")
347
+ message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
348
+ else if (issue.type === "number")
349
+ message = `Number must be ${issue.exact
350
+ ? `exactly equal to `
351
+ : issue.inclusive
352
+ ? `greater than or equal to `
353
+ : `greater than `}${issue.minimum}`;
354
+ else if (issue.type === "date")
355
+ message = `Date must be ${issue.exact
356
+ ? `exactly equal to `
357
+ : issue.inclusive
358
+ ? `greater than or equal to `
359
+ : `greater than `}${new Date(Number(issue.minimum))}`;
360
+ else
361
+ message = "Invalid input";
362
+ break;
363
+ case ZodIssueCode.too_big:
364
+ if (issue.type === "array")
365
+ message = `Array must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`;
366
+ else if (issue.type === "string")
367
+ message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
368
+ else if (issue.type === "number")
369
+ message = `Number must be ${issue.exact
370
+ ? `exactly`
371
+ : issue.inclusive
372
+ ? `less than or equal to`
373
+ : `less than`} ${issue.maximum}`;
374
+ else if (issue.type === "bigint")
375
+ message = `BigInt must be ${issue.exact
376
+ ? `exactly`
377
+ : issue.inclusive
378
+ ? `less than or equal to`
379
+ : `less than`} ${issue.maximum}`;
380
+ else if (issue.type === "date")
381
+ message = `Date must be ${issue.exact
382
+ ? `exactly`
383
+ : issue.inclusive
384
+ ? `smaller than or equal to`
385
+ : `smaller than`} ${new Date(Number(issue.maximum))}`;
386
+ else
387
+ message = "Invalid input";
388
+ break;
389
+ case ZodIssueCode.custom:
390
+ message = `Invalid input`;
391
+ break;
392
+ case ZodIssueCode.invalid_intersection_types:
393
+ message = `Intersection results could not be merged`;
394
+ break;
395
+ case ZodIssueCode.not_multiple_of:
396
+ message = `Number must be a multiple of ${issue.multipleOf}`;
397
+ break;
398
+ case ZodIssueCode.not_finite:
399
+ message = "Number must be finite";
400
+ break;
401
+ default:
402
+ message = _ctx.defaultError;
403
+ util.assertNever(issue);
404
+ }
405
+ return { message };
406
+ };
407
+
408
+ let overrideErrorMap = errorMap;
409
+ function setErrorMap(map) {
410
+ overrideErrorMap = map;
411
+ }
412
+ function getErrorMap() {
413
+ return overrideErrorMap;
414
+ }
415
+
416
+ const makeIssue = (params) => {
417
+ const { data, path, errorMaps, issueData } = params;
418
+ const fullPath = [...path, ...(issueData.path || [])];
419
+ const fullIssue = {
420
+ ...issueData,
421
+ path: fullPath,
422
+ };
423
+ let errorMessage = "";
424
+ const maps = errorMaps
425
+ .filter((m) => !!m)
426
+ .slice()
427
+ .reverse();
428
+ for (const map of maps) {
429
+ errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
430
+ }
431
+ return {
432
+ ...issueData,
433
+ path: fullPath,
434
+ message: issueData.message || errorMessage,
435
+ };
436
+ };
437
+ const EMPTY_PATH = [];
438
+ function addIssueToContext(ctx, issueData) {
439
+ const issue = makeIssue({
440
+ issueData: issueData,
441
+ data: ctx.data,
442
+ path: ctx.path,
443
+ errorMaps: [
444
+ ctx.common.contextualErrorMap,
445
+ ctx.schemaErrorMap,
446
+ getErrorMap(),
447
+ errorMap, // then global default map
448
+ ].filter((x) => !!x),
449
+ });
450
+ ctx.common.issues.push(issue);
451
+ }
452
+ class ParseStatus {
453
+ constructor() {
454
+ this.value = "valid";
455
+ }
456
+ dirty() {
457
+ if (this.value === "valid")
458
+ this.value = "dirty";
459
+ }
460
+ abort() {
461
+ if (this.value !== "aborted")
462
+ this.value = "aborted";
463
+ }
464
+ static mergeArray(status, results) {
465
+ const arrayValue = [];
466
+ for (const s of results) {
467
+ if (s.status === "aborted")
468
+ return INVALID;
469
+ if (s.status === "dirty")
470
+ status.dirty();
471
+ arrayValue.push(s.value);
472
+ }
473
+ return { status: status.value, value: arrayValue };
474
+ }
475
+ static async mergeObjectAsync(status, pairs) {
476
+ const syncPairs = [];
477
+ for (const pair of pairs) {
478
+ syncPairs.push({
479
+ key: await pair.key,
480
+ value: await pair.value,
481
+ });
482
+ }
483
+ return ParseStatus.mergeObjectSync(status, syncPairs);
484
+ }
485
+ static mergeObjectSync(status, pairs) {
486
+ const finalObject = {};
487
+ for (const pair of pairs) {
488
+ const { key, value } = pair;
489
+ if (key.status === "aborted")
490
+ return INVALID;
491
+ if (value.status === "aborted")
492
+ return INVALID;
493
+ if (key.status === "dirty")
494
+ status.dirty();
495
+ if (value.status === "dirty")
496
+ status.dirty();
497
+ if (key.value !== "__proto__" &&
498
+ (typeof value.value !== "undefined" || pair.alwaysSet)) {
499
+ finalObject[key.value] = value.value;
500
+ }
501
+ }
502
+ return { status: status.value, value: finalObject };
503
+ }
504
+ }
505
+ const INVALID = Object.freeze({
506
+ status: "aborted",
507
+ });
508
+ const DIRTY = (value) => ({ status: "dirty", value });
509
+ const OK = (value) => ({ status: "valid", value });
510
+ const isAborted = (x) => x.status === "aborted";
511
+ const isDirty = (x) => x.status === "dirty";
512
+ const isValid = (x) => x.status === "valid";
513
+ const isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
514
+
515
+ var errorUtil;
516
+ (function (errorUtil) {
517
+ errorUtil.errToObj = (message) => typeof message === "string" ? { message } : message || {};
518
+ errorUtil.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
519
+ })(errorUtil || (errorUtil = {}));
520
+
521
+ class ParseInputLazyPath {
522
+ constructor(parent, value, path, key) {
523
+ this._cachedPath = [];
524
+ this.parent = parent;
525
+ this.data = value;
526
+ this._path = path;
527
+ this._key = key;
528
+ }
529
+ get path() {
530
+ if (!this._cachedPath.length) {
531
+ if (this._key instanceof Array) {
532
+ this._cachedPath.push(...this._path, ...this._key);
533
+ }
534
+ else {
535
+ this._cachedPath.push(...this._path, this._key);
536
+ }
537
+ }
538
+ return this._cachedPath;
539
+ }
540
+ }
541
+ const handleResult = (ctx, result) => {
542
+ if (isValid(result)) {
543
+ return { success: true, data: result.value };
544
+ }
545
+ else {
546
+ if (!ctx.common.issues.length) {
547
+ throw new Error("Validation failed but no issues detected.");
548
+ }
549
+ return {
550
+ success: false,
551
+ get error() {
552
+ if (this._error)
553
+ return this._error;
554
+ const error = new ZodError(ctx.common.issues);
555
+ this._error = error;
556
+ return this._error;
557
+ },
558
+ };
559
+ }
560
+ };
561
+ function processCreateParams(params) {
562
+ if (!params)
563
+ return {};
564
+ const { errorMap, invalid_type_error, required_error, description } = params;
565
+ if (errorMap && (invalid_type_error || required_error)) {
566
+ throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
567
+ }
568
+ if (errorMap)
569
+ return { errorMap: errorMap, description };
570
+ const customMap = (iss, ctx) => {
571
+ if (iss.code !== "invalid_type")
572
+ return { message: ctx.defaultError };
573
+ if (typeof ctx.data === "undefined") {
574
+ return { message: required_error !== null && required_error !== void 0 ? required_error : ctx.defaultError };
575
+ }
576
+ return { message: invalid_type_error !== null && invalid_type_error !== void 0 ? invalid_type_error : ctx.defaultError };
577
+ };
578
+ return { errorMap: customMap, description };
579
+ }
580
+ class ZodType {
581
+ constructor(def) {
582
+ /** Alias of safeParseAsync */
583
+ this.spa = this.safeParseAsync;
584
+ this._def = def;
585
+ this.parse = this.parse.bind(this);
586
+ this.safeParse = this.safeParse.bind(this);
587
+ this.parseAsync = this.parseAsync.bind(this);
588
+ this.safeParseAsync = this.safeParseAsync.bind(this);
589
+ this.spa = this.spa.bind(this);
590
+ this.refine = this.refine.bind(this);
591
+ this.refinement = this.refinement.bind(this);
592
+ this.superRefine = this.superRefine.bind(this);
593
+ this.optional = this.optional.bind(this);
594
+ this.nullable = this.nullable.bind(this);
595
+ this.nullish = this.nullish.bind(this);
596
+ this.array = this.array.bind(this);
597
+ this.promise = this.promise.bind(this);
598
+ this.or = this.or.bind(this);
599
+ this.and = this.and.bind(this);
600
+ this.transform = this.transform.bind(this);
601
+ this.brand = this.brand.bind(this);
602
+ this.default = this.default.bind(this);
603
+ this.catch = this.catch.bind(this);
604
+ this.describe = this.describe.bind(this);
605
+ this.pipe = this.pipe.bind(this);
606
+ this.readonly = this.readonly.bind(this);
607
+ this.isNullable = this.isNullable.bind(this);
608
+ this.isOptional = this.isOptional.bind(this);
609
+ }
610
+ get description() {
611
+ return this._def.description;
612
+ }
613
+ _getType(input) {
614
+ return getParsedType(input.data);
615
+ }
616
+ _getOrReturnCtx(input, ctx) {
617
+ return (ctx || {
618
+ common: input.parent.common,
619
+ data: input.data,
620
+ parsedType: getParsedType(input.data),
621
+ schemaErrorMap: this._def.errorMap,
622
+ path: input.path,
623
+ parent: input.parent,
624
+ });
625
+ }
626
+ _processInputParams(input) {
627
+ return {
628
+ status: new ParseStatus(),
629
+ ctx: {
630
+ common: input.parent.common,
631
+ data: input.data,
632
+ parsedType: getParsedType(input.data),
633
+ schemaErrorMap: this._def.errorMap,
634
+ path: input.path,
635
+ parent: input.parent,
636
+ },
637
+ };
638
+ }
639
+ _parseSync(input) {
640
+ const result = this._parse(input);
641
+ if (isAsync(result)) {
642
+ throw new Error("Synchronous parse encountered promise.");
643
+ }
644
+ return result;
645
+ }
646
+ _parseAsync(input) {
647
+ const result = this._parse(input);
648
+ return Promise.resolve(result);
649
+ }
650
+ parse(data, params) {
651
+ const result = this.safeParse(data, params);
652
+ if (result.success)
653
+ return result.data;
654
+ throw result.error;
655
+ }
656
+ safeParse(data, params) {
657
+ var _a;
658
+ const ctx = {
659
+ common: {
660
+ issues: [],
661
+ async: (_a = params === null || params === void 0 ? void 0 : params.async) !== null && _a !== void 0 ? _a : false,
662
+ contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
663
+ },
664
+ path: (params === null || params === void 0 ? void 0 : params.path) || [],
665
+ schemaErrorMap: this._def.errorMap,
666
+ parent: null,
667
+ data,
668
+ parsedType: getParsedType(data),
669
+ };
670
+ const result = this._parseSync({ data, path: ctx.path, parent: ctx });
671
+ return handleResult(ctx, result);
672
+ }
673
+ async parseAsync(data, params) {
674
+ const result = await this.safeParseAsync(data, params);
675
+ if (result.success)
676
+ return result.data;
677
+ throw result.error;
678
+ }
679
+ async safeParseAsync(data, params) {
680
+ const ctx = {
681
+ common: {
682
+ issues: [],
683
+ contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
684
+ async: true,
685
+ },
686
+ path: (params === null || params === void 0 ? void 0 : params.path) || [],
687
+ schemaErrorMap: this._def.errorMap,
688
+ parent: null,
689
+ data,
690
+ parsedType: getParsedType(data),
691
+ };
692
+ const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
693
+ const result = await (isAsync(maybeAsyncResult)
694
+ ? maybeAsyncResult
695
+ : Promise.resolve(maybeAsyncResult));
696
+ return handleResult(ctx, result);
697
+ }
698
+ refine(check, message) {
699
+ const getIssueProperties = (val) => {
700
+ if (typeof message === "string" || typeof message === "undefined") {
701
+ return { message };
702
+ }
703
+ else if (typeof message === "function") {
704
+ return message(val);
705
+ }
706
+ else {
707
+ return message;
708
+ }
709
+ };
710
+ return this._refinement((val, ctx) => {
711
+ const result = check(val);
712
+ const setError = () => ctx.addIssue({
713
+ code: ZodIssueCode.custom,
714
+ ...getIssueProperties(val),
715
+ });
716
+ if (typeof Promise !== "undefined" && result instanceof Promise) {
717
+ return result.then((data) => {
718
+ if (!data) {
719
+ setError();
720
+ return false;
721
+ }
722
+ else {
723
+ return true;
724
+ }
725
+ });
726
+ }
727
+ if (!result) {
728
+ setError();
729
+ return false;
730
+ }
731
+ else {
732
+ return true;
733
+ }
734
+ });
735
+ }
736
+ refinement(check, refinementData) {
737
+ return this._refinement((val, ctx) => {
738
+ if (!check(val)) {
739
+ ctx.addIssue(typeof refinementData === "function"
740
+ ? refinementData(val, ctx)
741
+ : refinementData);
742
+ return false;
743
+ }
744
+ else {
745
+ return true;
746
+ }
747
+ });
748
+ }
749
+ _refinement(refinement) {
750
+ return new ZodEffects({
751
+ schema: this,
752
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
753
+ effect: { type: "refinement", refinement },
754
+ });
755
+ }
756
+ superRefine(refinement) {
757
+ return this._refinement(refinement);
758
+ }
759
+ optional() {
760
+ return ZodOptional.create(this, this._def);
761
+ }
762
+ nullable() {
763
+ return ZodNullable.create(this, this._def);
764
+ }
765
+ nullish() {
766
+ return this.nullable().optional();
767
+ }
768
+ array() {
769
+ return ZodArray.create(this, this._def);
770
+ }
771
+ promise() {
772
+ return ZodPromise.create(this, this._def);
773
+ }
774
+ or(option) {
775
+ return ZodUnion.create([this, option], this._def);
776
+ }
777
+ and(incoming) {
778
+ return ZodIntersection.create(this, incoming, this._def);
779
+ }
780
+ transform(transform) {
781
+ return new ZodEffects({
782
+ ...processCreateParams(this._def),
783
+ schema: this,
784
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
785
+ effect: { type: "transform", transform },
786
+ });
787
+ }
788
+ default(def) {
789
+ const defaultValueFunc = typeof def === "function" ? def : () => def;
790
+ return new ZodDefault({
791
+ ...processCreateParams(this._def),
792
+ innerType: this,
793
+ defaultValue: defaultValueFunc,
794
+ typeName: ZodFirstPartyTypeKind.ZodDefault,
795
+ });
796
+ }
797
+ brand() {
798
+ return new ZodBranded({
799
+ typeName: ZodFirstPartyTypeKind.ZodBranded,
800
+ type: this,
801
+ ...processCreateParams(this._def),
802
+ });
803
+ }
804
+ catch(def) {
805
+ const catchValueFunc = typeof def === "function" ? def : () => def;
806
+ return new ZodCatch({
807
+ ...processCreateParams(this._def),
808
+ innerType: this,
809
+ catchValue: catchValueFunc,
810
+ typeName: ZodFirstPartyTypeKind.ZodCatch,
811
+ });
812
+ }
813
+ describe(description) {
814
+ const This = this.constructor;
815
+ return new This({
816
+ ...this._def,
817
+ description,
818
+ });
819
+ }
820
+ pipe(target) {
821
+ return ZodPipeline.create(this, target);
822
+ }
823
+ readonly() {
824
+ return ZodReadonly.create(this);
825
+ }
826
+ isOptional() {
827
+ return this.safeParse(undefined).success;
828
+ }
829
+ isNullable() {
830
+ return this.safeParse(null).success;
831
+ }
832
+ }
833
+ const cuidRegex = /^c[^\s-]{8,}$/i;
834
+ const cuid2Regex = /^[a-z][a-z0-9]*$/;
835
+ const ulidRegex = /[0-9A-HJKMNP-TV-Z]{26}/;
836
+ // const uuidRegex =
837
+ // /^([a-f0-9]{8}-[a-f0-9]{4}-[1-5][a-f0-9]{3}-[a-f0-9]{4}-[a-f0-9]{12}|00000000-0000-0000-0000-000000000000)$/i;
838
+ const uuidRegex = /^[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;
839
+ // from https://stackoverflow.com/a/46181/1550155
840
+ // old version: too slow, didn't support unicode
841
+ // const emailRegex = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i;
842
+ //old email regex
843
+ // const emailRegex = /^(([^<>()[\].,;:\s@"]+(\.[^<>()[\].,;:\s@"]+)*)|(".+"))@((?!-)([^<>()[\].,;:\s@"]+\.)+[^<>()[\].,;:\s@"]{1,})[^-<>()[\].,;:\s@"]$/i;
844
+ // eslint-disable-next-line
845
+ // const emailRegex =
846
+ // /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\])|(\[IPv6:(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))\])|([A-Za-z0-9]([A-Za-z0-9-]*[A-Za-z0-9])*(\.[A-Za-z]{2,})+))$/;
847
+ // const emailRegex =
848
+ // /^[a-zA-Z0-9\.\!\#\$\%\&\'\*\+\/\=\?\^\_\`\{\|\}\~\-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
849
+ // const emailRegex =
850
+ // /^(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/i;
851
+ const emailRegex = /^([A-Z0-9_+-]+\.?)*[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
852
+ // const emailRegex =
853
+ // /^[a-z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-z0-9-]+(?:\.[a-z0-9\-]+)*$/i;
854
+ // from https://thekevinscott.com/emojis-in-javascript/#writing-a-regular-expression
855
+ const emojiRegex = /^(\p{Extended_Pictographic}|\p{Emoji_Component})+$/u;
856
+ const ipv4Regex = /^(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))$/;
857
+ const ipv6Regex = /^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/;
858
+ // Adapted from https://stackoverflow.com/a/3143231
859
+ const datetimeRegex = (args) => {
860
+ if (args.precision) {
861
+ if (args.offset) {
862
+ return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
863
+ }
864
+ else {
865
+ return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}Z$`);
866
+ }
867
+ }
868
+ else if (args.precision === 0) {
869
+ if (args.offset) {
870
+ return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
871
+ }
872
+ else {
873
+ return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$`);
874
+ }
875
+ }
876
+ else {
877
+ if (args.offset) {
878
+ return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
879
+ }
880
+ else {
881
+ return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$`);
882
+ }
883
+ }
884
+ };
885
+ function isValidIP(ip, version) {
886
+ if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
887
+ return true;
888
+ }
889
+ if ((version === "v6" || !version) && ipv6Regex.test(ip)) {
890
+ return true;
891
+ }
892
+ return false;
893
+ }
894
+ class ZodString extends ZodType {
895
+ constructor() {
896
+ super(...arguments);
897
+ this._regex = (regex, validation, message) => this.refinement((data) => regex.test(data), {
898
+ validation,
899
+ code: ZodIssueCode.invalid_string,
900
+ ...errorUtil.errToObj(message),
901
+ });
902
+ /**
903
+ * @deprecated Use z.string().min(1) instead.
904
+ * @see {@link ZodString.min}
905
+ */
906
+ this.nonempty = (message) => this.min(1, errorUtil.errToObj(message));
907
+ this.trim = () => new ZodString({
908
+ ...this._def,
909
+ checks: [...this._def.checks, { kind: "trim" }],
910
+ });
911
+ this.toLowerCase = () => new ZodString({
912
+ ...this._def,
913
+ checks: [...this._def.checks, { kind: "toLowerCase" }],
914
+ });
915
+ this.toUpperCase = () => new ZodString({
916
+ ...this._def,
917
+ checks: [...this._def.checks, { kind: "toUpperCase" }],
918
+ });
919
+ }
920
+ _parse(input) {
921
+ if (this._def.coerce) {
922
+ input.data = String(input.data);
923
+ }
924
+ const parsedType = this._getType(input);
925
+ if (parsedType !== ZodParsedType.string) {
926
+ const ctx = this._getOrReturnCtx(input);
927
+ addIssueToContext(ctx, {
928
+ code: ZodIssueCode.invalid_type,
929
+ expected: ZodParsedType.string,
930
+ received: ctx.parsedType,
931
+ }
932
+ //
933
+ );
934
+ return INVALID;
935
+ }
936
+ const status = new ParseStatus();
937
+ let ctx = undefined;
938
+ for (const check of this._def.checks) {
939
+ if (check.kind === "min") {
940
+ if (input.data.length < check.value) {
941
+ ctx = this._getOrReturnCtx(input, ctx);
942
+ addIssueToContext(ctx, {
943
+ code: ZodIssueCode.too_small,
944
+ minimum: check.value,
945
+ type: "string",
946
+ inclusive: true,
947
+ exact: false,
948
+ message: check.message,
949
+ });
950
+ status.dirty();
951
+ }
952
+ }
953
+ else if (check.kind === "max") {
954
+ if (input.data.length > check.value) {
955
+ ctx = this._getOrReturnCtx(input, ctx);
956
+ addIssueToContext(ctx, {
957
+ code: ZodIssueCode.too_big,
958
+ maximum: check.value,
959
+ type: "string",
960
+ inclusive: true,
961
+ exact: false,
962
+ message: check.message,
963
+ });
964
+ status.dirty();
965
+ }
966
+ }
967
+ else if (check.kind === "length") {
968
+ const tooBig = input.data.length > check.value;
969
+ const tooSmall = input.data.length < check.value;
970
+ if (tooBig || tooSmall) {
971
+ ctx = this._getOrReturnCtx(input, ctx);
972
+ if (tooBig) {
973
+ addIssueToContext(ctx, {
974
+ code: ZodIssueCode.too_big,
975
+ maximum: check.value,
976
+ type: "string",
977
+ inclusive: true,
978
+ exact: true,
979
+ message: check.message,
980
+ });
981
+ }
982
+ else if (tooSmall) {
983
+ addIssueToContext(ctx, {
984
+ code: ZodIssueCode.too_small,
985
+ minimum: check.value,
986
+ type: "string",
987
+ inclusive: true,
988
+ exact: true,
989
+ message: check.message,
990
+ });
991
+ }
992
+ status.dirty();
993
+ }
994
+ }
995
+ else if (check.kind === "email") {
996
+ if (!emailRegex.test(input.data)) {
997
+ ctx = this._getOrReturnCtx(input, ctx);
998
+ addIssueToContext(ctx, {
999
+ validation: "email",
1000
+ code: ZodIssueCode.invalid_string,
1001
+ message: check.message,
1002
+ });
1003
+ status.dirty();
1004
+ }
1005
+ }
1006
+ else if (check.kind === "emoji") {
1007
+ if (!emojiRegex.test(input.data)) {
1008
+ ctx = this._getOrReturnCtx(input, ctx);
1009
+ addIssueToContext(ctx, {
1010
+ validation: "emoji",
1011
+ code: ZodIssueCode.invalid_string,
1012
+ message: check.message,
1013
+ });
1014
+ status.dirty();
1015
+ }
1016
+ }
1017
+ else if (check.kind === "uuid") {
1018
+ if (!uuidRegex.test(input.data)) {
1019
+ ctx = this._getOrReturnCtx(input, ctx);
1020
+ addIssueToContext(ctx, {
1021
+ validation: "uuid",
1022
+ code: ZodIssueCode.invalid_string,
1023
+ message: check.message,
1024
+ });
1025
+ status.dirty();
1026
+ }
1027
+ }
1028
+ else if (check.kind === "cuid") {
1029
+ if (!cuidRegex.test(input.data)) {
1030
+ ctx = this._getOrReturnCtx(input, ctx);
1031
+ addIssueToContext(ctx, {
1032
+ validation: "cuid",
1033
+ code: ZodIssueCode.invalid_string,
1034
+ message: check.message,
1035
+ });
1036
+ status.dirty();
1037
+ }
1038
+ }
1039
+ else if (check.kind === "cuid2") {
1040
+ if (!cuid2Regex.test(input.data)) {
1041
+ ctx = this._getOrReturnCtx(input, ctx);
1042
+ addIssueToContext(ctx, {
1043
+ validation: "cuid2",
1044
+ code: ZodIssueCode.invalid_string,
1045
+ message: check.message,
1046
+ });
1047
+ status.dirty();
1048
+ }
1049
+ }
1050
+ else if (check.kind === "ulid") {
1051
+ if (!ulidRegex.test(input.data)) {
1052
+ ctx = this._getOrReturnCtx(input, ctx);
1053
+ addIssueToContext(ctx, {
1054
+ validation: "ulid",
1055
+ code: ZodIssueCode.invalid_string,
1056
+ message: check.message,
1057
+ });
1058
+ status.dirty();
1059
+ }
1060
+ }
1061
+ else if (check.kind === "url") {
1062
+ try {
1063
+ new URL(input.data);
1064
+ }
1065
+ catch (_a) {
1066
+ ctx = this._getOrReturnCtx(input, ctx);
1067
+ addIssueToContext(ctx, {
1068
+ validation: "url",
1069
+ code: ZodIssueCode.invalid_string,
1070
+ message: check.message,
1071
+ });
1072
+ status.dirty();
1073
+ }
1074
+ }
1075
+ else if (check.kind === "regex") {
1076
+ check.regex.lastIndex = 0;
1077
+ const testResult = check.regex.test(input.data);
1078
+ if (!testResult) {
1079
+ ctx = this._getOrReturnCtx(input, ctx);
1080
+ addIssueToContext(ctx, {
1081
+ validation: "regex",
1082
+ code: ZodIssueCode.invalid_string,
1083
+ message: check.message,
1084
+ });
1085
+ status.dirty();
1086
+ }
1087
+ }
1088
+ else if (check.kind === "trim") {
1089
+ input.data = input.data.trim();
1090
+ }
1091
+ else if (check.kind === "includes") {
1092
+ if (!input.data.includes(check.value, check.position)) {
1093
+ ctx = this._getOrReturnCtx(input, ctx);
1094
+ addIssueToContext(ctx, {
1095
+ code: ZodIssueCode.invalid_string,
1096
+ validation: { includes: check.value, position: check.position },
1097
+ message: check.message,
1098
+ });
1099
+ status.dirty();
1100
+ }
1101
+ }
1102
+ else if (check.kind === "toLowerCase") {
1103
+ input.data = input.data.toLowerCase();
1104
+ }
1105
+ else if (check.kind === "toUpperCase") {
1106
+ input.data = input.data.toUpperCase();
1107
+ }
1108
+ else if (check.kind === "startsWith") {
1109
+ if (!input.data.startsWith(check.value)) {
1110
+ ctx = this._getOrReturnCtx(input, ctx);
1111
+ addIssueToContext(ctx, {
1112
+ code: ZodIssueCode.invalid_string,
1113
+ validation: { startsWith: check.value },
1114
+ message: check.message,
1115
+ });
1116
+ status.dirty();
1117
+ }
1118
+ }
1119
+ else if (check.kind === "endsWith") {
1120
+ if (!input.data.endsWith(check.value)) {
1121
+ ctx = this._getOrReturnCtx(input, ctx);
1122
+ addIssueToContext(ctx, {
1123
+ code: ZodIssueCode.invalid_string,
1124
+ validation: { endsWith: check.value },
1125
+ message: check.message,
1126
+ });
1127
+ status.dirty();
1128
+ }
1129
+ }
1130
+ else if (check.kind === "datetime") {
1131
+ const regex = datetimeRegex(check);
1132
+ if (!regex.test(input.data)) {
1133
+ ctx = this._getOrReturnCtx(input, ctx);
1134
+ addIssueToContext(ctx, {
1135
+ code: ZodIssueCode.invalid_string,
1136
+ validation: "datetime",
1137
+ message: check.message,
1138
+ });
1139
+ status.dirty();
1140
+ }
1141
+ }
1142
+ else if (check.kind === "ip") {
1143
+ if (!isValidIP(input.data, check.version)) {
1144
+ ctx = this._getOrReturnCtx(input, ctx);
1145
+ addIssueToContext(ctx, {
1146
+ validation: "ip",
1147
+ code: ZodIssueCode.invalid_string,
1148
+ message: check.message,
1149
+ });
1150
+ status.dirty();
1151
+ }
1152
+ }
1153
+ else {
1154
+ util.assertNever(check);
1155
+ }
1156
+ }
1157
+ return { status: status.value, value: input.data };
1158
+ }
1159
+ _addCheck(check) {
1160
+ return new ZodString({
1161
+ ...this._def,
1162
+ checks: [...this._def.checks, check],
1163
+ });
1164
+ }
1165
+ email(message) {
1166
+ return this._addCheck({ kind: "email", ...errorUtil.errToObj(message) });
1167
+ }
1168
+ url(message) {
1169
+ return this._addCheck({ kind: "url", ...errorUtil.errToObj(message) });
1170
+ }
1171
+ emoji(message) {
1172
+ return this._addCheck({ kind: "emoji", ...errorUtil.errToObj(message) });
1173
+ }
1174
+ uuid(message) {
1175
+ return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
1176
+ }
1177
+ cuid(message) {
1178
+ return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
1179
+ }
1180
+ cuid2(message) {
1181
+ return this._addCheck({ kind: "cuid2", ...errorUtil.errToObj(message) });
1182
+ }
1183
+ ulid(message) {
1184
+ return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) });
1185
+ }
1186
+ ip(options) {
1187
+ return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
1188
+ }
1189
+ datetime(options) {
1190
+ var _a;
1191
+ if (typeof options === "string") {
1192
+ return this._addCheck({
1193
+ kind: "datetime",
1194
+ precision: null,
1195
+ offset: false,
1196
+ message: options,
1197
+ });
1198
+ }
1199
+ return this._addCheck({
1200
+ kind: "datetime",
1201
+ precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
1202
+ offset: (_a = options === null || options === void 0 ? void 0 : options.offset) !== null && _a !== void 0 ? _a : false,
1203
+ ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message),
1204
+ });
1205
+ }
1206
+ regex(regex, message) {
1207
+ return this._addCheck({
1208
+ kind: "regex",
1209
+ regex: regex,
1210
+ ...errorUtil.errToObj(message),
1211
+ });
1212
+ }
1213
+ includes(value, options) {
1214
+ return this._addCheck({
1215
+ kind: "includes",
1216
+ value: value,
1217
+ position: options === null || options === void 0 ? void 0 : options.position,
1218
+ ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message),
1219
+ });
1220
+ }
1221
+ startsWith(value, message) {
1222
+ return this._addCheck({
1223
+ kind: "startsWith",
1224
+ value: value,
1225
+ ...errorUtil.errToObj(message),
1226
+ });
1227
+ }
1228
+ endsWith(value, message) {
1229
+ return this._addCheck({
1230
+ kind: "endsWith",
1231
+ value: value,
1232
+ ...errorUtil.errToObj(message),
1233
+ });
1234
+ }
1235
+ min(minLength, message) {
1236
+ return this._addCheck({
1237
+ kind: "min",
1238
+ value: minLength,
1239
+ ...errorUtil.errToObj(message),
1240
+ });
1241
+ }
1242
+ max(maxLength, message) {
1243
+ return this._addCheck({
1244
+ kind: "max",
1245
+ value: maxLength,
1246
+ ...errorUtil.errToObj(message),
1247
+ });
1248
+ }
1249
+ length(len, message) {
1250
+ return this._addCheck({
1251
+ kind: "length",
1252
+ value: len,
1253
+ ...errorUtil.errToObj(message),
1254
+ });
1255
+ }
1256
+ get isDatetime() {
1257
+ return !!this._def.checks.find((ch) => ch.kind === "datetime");
1258
+ }
1259
+ get isEmail() {
1260
+ return !!this._def.checks.find((ch) => ch.kind === "email");
1261
+ }
1262
+ get isURL() {
1263
+ return !!this._def.checks.find((ch) => ch.kind === "url");
1264
+ }
1265
+ get isEmoji() {
1266
+ return !!this._def.checks.find((ch) => ch.kind === "emoji");
1267
+ }
1268
+ get isUUID() {
1269
+ return !!this._def.checks.find((ch) => ch.kind === "uuid");
1270
+ }
1271
+ get isCUID() {
1272
+ return !!this._def.checks.find((ch) => ch.kind === "cuid");
1273
+ }
1274
+ get isCUID2() {
1275
+ return !!this._def.checks.find((ch) => ch.kind === "cuid2");
1276
+ }
1277
+ get isULID() {
1278
+ return !!this._def.checks.find((ch) => ch.kind === "ulid");
1279
+ }
1280
+ get isIP() {
1281
+ return !!this._def.checks.find((ch) => ch.kind === "ip");
1282
+ }
1283
+ get minLength() {
1284
+ let min = null;
1285
+ for (const ch of this._def.checks) {
1286
+ if (ch.kind === "min") {
1287
+ if (min === null || ch.value > min)
1288
+ min = ch.value;
1289
+ }
1290
+ }
1291
+ return min;
1292
+ }
1293
+ get maxLength() {
1294
+ let max = null;
1295
+ for (const ch of this._def.checks) {
1296
+ if (ch.kind === "max") {
1297
+ if (max === null || ch.value < max)
1298
+ max = ch.value;
1299
+ }
1300
+ }
1301
+ return max;
1302
+ }
1303
+ }
1304
+ ZodString.create = (params) => {
1305
+ var _a;
1306
+ return new ZodString({
1307
+ checks: [],
1308
+ typeName: ZodFirstPartyTypeKind.ZodString,
1309
+ coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
1310
+ ...processCreateParams(params),
1311
+ });
1312
+ };
1313
+ // https://stackoverflow.com/questions/3966484/why-does-modulus-operator-return-fractional-number-in-javascript/31711034#31711034
1314
+ function floatSafeRemainder(val, step) {
1315
+ const valDecCount = (val.toString().split(".")[1] || "").length;
1316
+ const stepDecCount = (step.toString().split(".")[1] || "").length;
1317
+ const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
1318
+ const valInt = parseInt(val.toFixed(decCount).replace(".", ""));
1319
+ const stepInt = parseInt(step.toFixed(decCount).replace(".", ""));
1320
+ return (valInt % stepInt) / Math.pow(10, decCount);
1321
+ }
1322
+ class ZodNumber extends ZodType {
1323
+ constructor() {
1324
+ super(...arguments);
1325
+ this.min = this.gte;
1326
+ this.max = this.lte;
1327
+ this.step = this.multipleOf;
1328
+ }
1329
+ _parse(input) {
1330
+ if (this._def.coerce) {
1331
+ input.data = Number(input.data);
1332
+ }
1333
+ const parsedType = this._getType(input);
1334
+ if (parsedType !== ZodParsedType.number) {
1335
+ const ctx = this._getOrReturnCtx(input);
1336
+ addIssueToContext(ctx, {
1337
+ code: ZodIssueCode.invalid_type,
1338
+ expected: ZodParsedType.number,
1339
+ received: ctx.parsedType,
1340
+ });
1341
+ return INVALID;
1342
+ }
1343
+ let ctx = undefined;
1344
+ const status = new ParseStatus();
1345
+ for (const check of this._def.checks) {
1346
+ if (check.kind === "int") {
1347
+ if (!util.isInteger(input.data)) {
1348
+ ctx = this._getOrReturnCtx(input, ctx);
1349
+ addIssueToContext(ctx, {
1350
+ code: ZodIssueCode.invalid_type,
1351
+ expected: "integer",
1352
+ received: "float",
1353
+ message: check.message,
1354
+ });
1355
+ status.dirty();
1356
+ }
1357
+ }
1358
+ else if (check.kind === "min") {
1359
+ const tooSmall = check.inclusive
1360
+ ? input.data < check.value
1361
+ : input.data <= check.value;
1362
+ if (tooSmall) {
1363
+ ctx = this._getOrReturnCtx(input, ctx);
1364
+ addIssueToContext(ctx, {
1365
+ code: ZodIssueCode.too_small,
1366
+ minimum: check.value,
1367
+ type: "number",
1368
+ inclusive: check.inclusive,
1369
+ exact: false,
1370
+ message: check.message,
1371
+ });
1372
+ status.dirty();
1373
+ }
1374
+ }
1375
+ else if (check.kind === "max") {
1376
+ const tooBig = check.inclusive
1377
+ ? input.data > check.value
1378
+ : input.data >= check.value;
1379
+ if (tooBig) {
1380
+ ctx = this._getOrReturnCtx(input, ctx);
1381
+ addIssueToContext(ctx, {
1382
+ code: ZodIssueCode.too_big,
1383
+ maximum: check.value,
1384
+ type: "number",
1385
+ inclusive: check.inclusive,
1386
+ exact: false,
1387
+ message: check.message,
1388
+ });
1389
+ status.dirty();
1390
+ }
1391
+ }
1392
+ else if (check.kind === "multipleOf") {
1393
+ if (floatSafeRemainder(input.data, check.value) !== 0) {
1394
+ ctx = this._getOrReturnCtx(input, ctx);
1395
+ addIssueToContext(ctx, {
1396
+ code: ZodIssueCode.not_multiple_of,
1397
+ multipleOf: check.value,
1398
+ message: check.message,
1399
+ });
1400
+ status.dirty();
1401
+ }
1402
+ }
1403
+ else if (check.kind === "finite") {
1404
+ if (!Number.isFinite(input.data)) {
1405
+ ctx = this._getOrReturnCtx(input, ctx);
1406
+ addIssueToContext(ctx, {
1407
+ code: ZodIssueCode.not_finite,
1408
+ message: check.message,
1409
+ });
1410
+ status.dirty();
1411
+ }
1412
+ }
1413
+ else {
1414
+ util.assertNever(check);
1415
+ }
1416
+ }
1417
+ return { status: status.value, value: input.data };
1418
+ }
1419
+ gte(value, message) {
1420
+ return this.setLimit("min", value, true, errorUtil.toString(message));
1421
+ }
1422
+ gt(value, message) {
1423
+ return this.setLimit("min", value, false, errorUtil.toString(message));
1424
+ }
1425
+ lte(value, message) {
1426
+ return this.setLimit("max", value, true, errorUtil.toString(message));
1427
+ }
1428
+ lt(value, message) {
1429
+ return this.setLimit("max", value, false, errorUtil.toString(message));
1430
+ }
1431
+ setLimit(kind, value, inclusive, message) {
1432
+ return new ZodNumber({
1433
+ ...this._def,
1434
+ checks: [
1435
+ ...this._def.checks,
1436
+ {
1437
+ kind,
1438
+ value,
1439
+ inclusive,
1440
+ message: errorUtil.toString(message),
1441
+ },
1442
+ ],
1443
+ });
1444
+ }
1445
+ _addCheck(check) {
1446
+ return new ZodNumber({
1447
+ ...this._def,
1448
+ checks: [...this._def.checks, check],
1449
+ });
1450
+ }
1451
+ int(message) {
1452
+ return this._addCheck({
1453
+ kind: "int",
1454
+ message: errorUtil.toString(message),
1455
+ });
1456
+ }
1457
+ positive(message) {
1458
+ return this._addCheck({
1459
+ kind: "min",
1460
+ value: 0,
1461
+ inclusive: false,
1462
+ message: errorUtil.toString(message),
1463
+ });
1464
+ }
1465
+ negative(message) {
1466
+ return this._addCheck({
1467
+ kind: "max",
1468
+ value: 0,
1469
+ inclusive: false,
1470
+ message: errorUtil.toString(message),
1471
+ });
1472
+ }
1473
+ nonpositive(message) {
1474
+ return this._addCheck({
1475
+ kind: "max",
1476
+ value: 0,
1477
+ inclusive: true,
1478
+ message: errorUtil.toString(message),
1479
+ });
1480
+ }
1481
+ nonnegative(message) {
1482
+ return this._addCheck({
1483
+ kind: "min",
1484
+ value: 0,
1485
+ inclusive: true,
1486
+ message: errorUtil.toString(message),
1487
+ });
1488
+ }
1489
+ multipleOf(value, message) {
1490
+ return this._addCheck({
1491
+ kind: "multipleOf",
1492
+ value: value,
1493
+ message: errorUtil.toString(message),
1494
+ });
1495
+ }
1496
+ finite(message) {
1497
+ return this._addCheck({
1498
+ kind: "finite",
1499
+ message: errorUtil.toString(message),
1500
+ });
1501
+ }
1502
+ safe(message) {
1503
+ return this._addCheck({
1504
+ kind: "min",
1505
+ inclusive: true,
1506
+ value: Number.MIN_SAFE_INTEGER,
1507
+ message: errorUtil.toString(message),
1508
+ })._addCheck({
1509
+ kind: "max",
1510
+ inclusive: true,
1511
+ value: Number.MAX_SAFE_INTEGER,
1512
+ message: errorUtil.toString(message),
1513
+ });
1514
+ }
1515
+ get minValue() {
1516
+ let min = null;
1517
+ for (const ch of this._def.checks) {
1518
+ if (ch.kind === "min") {
1519
+ if (min === null || ch.value > min)
1520
+ min = ch.value;
1521
+ }
1522
+ }
1523
+ return min;
1524
+ }
1525
+ get maxValue() {
1526
+ let max = null;
1527
+ for (const ch of this._def.checks) {
1528
+ if (ch.kind === "max") {
1529
+ if (max === null || ch.value < max)
1530
+ max = ch.value;
1531
+ }
1532
+ }
1533
+ return max;
1534
+ }
1535
+ get isInt() {
1536
+ return !!this._def.checks.find((ch) => ch.kind === "int" ||
1537
+ (ch.kind === "multipleOf" && util.isInteger(ch.value)));
1538
+ }
1539
+ get isFinite() {
1540
+ let max = null, min = null;
1541
+ for (const ch of this._def.checks) {
1542
+ if (ch.kind === "finite" ||
1543
+ ch.kind === "int" ||
1544
+ ch.kind === "multipleOf") {
1545
+ return true;
1546
+ }
1547
+ else if (ch.kind === "min") {
1548
+ if (min === null || ch.value > min)
1549
+ min = ch.value;
1550
+ }
1551
+ else if (ch.kind === "max") {
1552
+ if (max === null || ch.value < max)
1553
+ max = ch.value;
1554
+ }
1555
+ }
1556
+ return Number.isFinite(min) && Number.isFinite(max);
1557
+ }
1558
+ }
1559
+ ZodNumber.create = (params) => {
1560
+ return new ZodNumber({
1561
+ checks: [],
1562
+ typeName: ZodFirstPartyTypeKind.ZodNumber,
1563
+ coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
1564
+ ...processCreateParams(params),
1565
+ });
1566
+ };
1567
+ class ZodBigInt extends ZodType {
1568
+ constructor() {
1569
+ super(...arguments);
1570
+ this.min = this.gte;
1571
+ this.max = this.lte;
1572
+ }
1573
+ _parse(input) {
1574
+ if (this._def.coerce) {
1575
+ input.data = BigInt(input.data);
1576
+ }
1577
+ const parsedType = this._getType(input);
1578
+ if (parsedType !== ZodParsedType.bigint) {
1579
+ const ctx = this._getOrReturnCtx(input);
1580
+ addIssueToContext(ctx, {
1581
+ code: ZodIssueCode.invalid_type,
1582
+ expected: ZodParsedType.bigint,
1583
+ received: ctx.parsedType,
1584
+ });
1585
+ return INVALID;
1586
+ }
1587
+ let ctx = undefined;
1588
+ const status = new ParseStatus();
1589
+ for (const check of this._def.checks) {
1590
+ if (check.kind === "min") {
1591
+ const tooSmall = check.inclusive
1592
+ ? input.data < check.value
1593
+ : input.data <= check.value;
1594
+ if (tooSmall) {
1595
+ ctx = this._getOrReturnCtx(input, ctx);
1596
+ addIssueToContext(ctx, {
1597
+ code: ZodIssueCode.too_small,
1598
+ type: "bigint",
1599
+ minimum: check.value,
1600
+ inclusive: check.inclusive,
1601
+ message: check.message,
1602
+ });
1603
+ status.dirty();
1604
+ }
1605
+ }
1606
+ else if (check.kind === "max") {
1607
+ const tooBig = check.inclusive
1608
+ ? input.data > check.value
1609
+ : input.data >= check.value;
1610
+ if (tooBig) {
1611
+ ctx = this._getOrReturnCtx(input, ctx);
1612
+ addIssueToContext(ctx, {
1613
+ code: ZodIssueCode.too_big,
1614
+ type: "bigint",
1615
+ maximum: check.value,
1616
+ inclusive: check.inclusive,
1617
+ message: check.message,
1618
+ });
1619
+ status.dirty();
1620
+ }
1621
+ }
1622
+ else if (check.kind === "multipleOf") {
1623
+ if (input.data % check.value !== BigInt(0)) {
1624
+ ctx = this._getOrReturnCtx(input, ctx);
1625
+ addIssueToContext(ctx, {
1626
+ code: ZodIssueCode.not_multiple_of,
1627
+ multipleOf: check.value,
1628
+ message: check.message,
1629
+ });
1630
+ status.dirty();
1631
+ }
1632
+ }
1633
+ else {
1634
+ util.assertNever(check);
1635
+ }
1636
+ }
1637
+ return { status: status.value, value: input.data };
1638
+ }
1639
+ gte(value, message) {
1640
+ return this.setLimit("min", value, true, errorUtil.toString(message));
1641
+ }
1642
+ gt(value, message) {
1643
+ return this.setLimit("min", value, false, errorUtil.toString(message));
1644
+ }
1645
+ lte(value, message) {
1646
+ return this.setLimit("max", value, true, errorUtil.toString(message));
1647
+ }
1648
+ lt(value, message) {
1649
+ return this.setLimit("max", value, false, errorUtil.toString(message));
1650
+ }
1651
+ setLimit(kind, value, inclusive, message) {
1652
+ return new ZodBigInt({
1653
+ ...this._def,
1654
+ checks: [
1655
+ ...this._def.checks,
1656
+ {
1657
+ kind,
1658
+ value,
1659
+ inclusive,
1660
+ message: errorUtil.toString(message),
1661
+ },
1662
+ ],
1663
+ });
1664
+ }
1665
+ _addCheck(check) {
1666
+ return new ZodBigInt({
1667
+ ...this._def,
1668
+ checks: [...this._def.checks, check],
1669
+ });
1670
+ }
1671
+ positive(message) {
1672
+ return this._addCheck({
1673
+ kind: "min",
1674
+ value: BigInt(0),
1675
+ inclusive: false,
1676
+ message: errorUtil.toString(message),
1677
+ });
1678
+ }
1679
+ negative(message) {
1680
+ return this._addCheck({
1681
+ kind: "max",
1682
+ value: BigInt(0),
1683
+ inclusive: false,
1684
+ message: errorUtil.toString(message),
1685
+ });
1686
+ }
1687
+ nonpositive(message) {
1688
+ return this._addCheck({
1689
+ kind: "max",
1690
+ value: BigInt(0),
1691
+ inclusive: true,
1692
+ message: errorUtil.toString(message),
1693
+ });
1694
+ }
1695
+ nonnegative(message) {
1696
+ return this._addCheck({
1697
+ kind: "min",
1698
+ value: BigInt(0),
1699
+ inclusive: true,
1700
+ message: errorUtil.toString(message),
1701
+ });
1702
+ }
1703
+ multipleOf(value, message) {
1704
+ return this._addCheck({
1705
+ kind: "multipleOf",
1706
+ value,
1707
+ message: errorUtil.toString(message),
1708
+ });
1709
+ }
1710
+ get minValue() {
1711
+ let min = null;
1712
+ for (const ch of this._def.checks) {
1713
+ if (ch.kind === "min") {
1714
+ if (min === null || ch.value > min)
1715
+ min = ch.value;
1716
+ }
1717
+ }
1718
+ return min;
1719
+ }
1720
+ get maxValue() {
1721
+ let max = null;
1722
+ for (const ch of this._def.checks) {
1723
+ if (ch.kind === "max") {
1724
+ if (max === null || ch.value < max)
1725
+ max = ch.value;
1726
+ }
1727
+ }
1728
+ return max;
1729
+ }
1730
+ }
1731
+ ZodBigInt.create = (params) => {
1732
+ var _a;
1733
+ return new ZodBigInt({
1734
+ checks: [],
1735
+ typeName: ZodFirstPartyTypeKind.ZodBigInt,
1736
+ coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
1737
+ ...processCreateParams(params),
1738
+ });
1739
+ };
1740
+ class ZodBoolean extends ZodType {
1741
+ _parse(input) {
1742
+ if (this._def.coerce) {
1743
+ input.data = Boolean(input.data);
1744
+ }
1745
+ const parsedType = this._getType(input);
1746
+ if (parsedType !== ZodParsedType.boolean) {
1747
+ const ctx = this._getOrReturnCtx(input);
1748
+ addIssueToContext(ctx, {
1749
+ code: ZodIssueCode.invalid_type,
1750
+ expected: ZodParsedType.boolean,
1751
+ received: ctx.parsedType,
1752
+ });
1753
+ return INVALID;
1754
+ }
1755
+ return OK(input.data);
1756
+ }
1757
+ }
1758
+ ZodBoolean.create = (params) => {
1759
+ return new ZodBoolean({
1760
+ typeName: ZodFirstPartyTypeKind.ZodBoolean,
1761
+ coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
1762
+ ...processCreateParams(params),
1763
+ });
1764
+ };
1765
+ class ZodDate extends ZodType {
1766
+ _parse(input) {
1767
+ if (this._def.coerce) {
1768
+ input.data = new Date(input.data);
1769
+ }
1770
+ const parsedType = this._getType(input);
1771
+ if (parsedType !== ZodParsedType.date) {
1772
+ const ctx = this._getOrReturnCtx(input);
1773
+ addIssueToContext(ctx, {
1774
+ code: ZodIssueCode.invalid_type,
1775
+ expected: ZodParsedType.date,
1776
+ received: ctx.parsedType,
1777
+ });
1778
+ return INVALID;
1779
+ }
1780
+ if (isNaN(input.data.getTime())) {
1781
+ const ctx = this._getOrReturnCtx(input);
1782
+ addIssueToContext(ctx, {
1783
+ code: ZodIssueCode.invalid_date,
1784
+ });
1785
+ return INVALID;
1786
+ }
1787
+ const status = new ParseStatus();
1788
+ let ctx = undefined;
1789
+ for (const check of this._def.checks) {
1790
+ if (check.kind === "min") {
1791
+ if (input.data.getTime() < check.value) {
1792
+ ctx = this._getOrReturnCtx(input, ctx);
1793
+ addIssueToContext(ctx, {
1794
+ code: ZodIssueCode.too_small,
1795
+ message: check.message,
1796
+ inclusive: true,
1797
+ exact: false,
1798
+ minimum: check.value,
1799
+ type: "date",
1800
+ });
1801
+ status.dirty();
1802
+ }
1803
+ }
1804
+ else if (check.kind === "max") {
1805
+ if (input.data.getTime() > check.value) {
1806
+ ctx = this._getOrReturnCtx(input, ctx);
1807
+ addIssueToContext(ctx, {
1808
+ code: ZodIssueCode.too_big,
1809
+ message: check.message,
1810
+ inclusive: true,
1811
+ exact: false,
1812
+ maximum: check.value,
1813
+ type: "date",
1814
+ });
1815
+ status.dirty();
1816
+ }
1817
+ }
1818
+ else {
1819
+ util.assertNever(check);
1820
+ }
1821
+ }
1822
+ return {
1823
+ status: status.value,
1824
+ value: new Date(input.data.getTime()),
1825
+ };
1826
+ }
1827
+ _addCheck(check) {
1828
+ return new ZodDate({
1829
+ ...this._def,
1830
+ checks: [...this._def.checks, check],
1831
+ });
1832
+ }
1833
+ min(minDate, message) {
1834
+ return this._addCheck({
1835
+ kind: "min",
1836
+ value: minDate.getTime(),
1837
+ message: errorUtil.toString(message),
1838
+ });
1839
+ }
1840
+ max(maxDate, message) {
1841
+ return this._addCheck({
1842
+ kind: "max",
1843
+ value: maxDate.getTime(),
1844
+ message: errorUtil.toString(message),
1845
+ });
1846
+ }
1847
+ get minDate() {
1848
+ let min = null;
1849
+ for (const ch of this._def.checks) {
1850
+ if (ch.kind === "min") {
1851
+ if (min === null || ch.value > min)
1852
+ min = ch.value;
1853
+ }
1854
+ }
1855
+ return min != null ? new Date(min) : null;
1856
+ }
1857
+ get maxDate() {
1858
+ let max = null;
1859
+ for (const ch of this._def.checks) {
1860
+ if (ch.kind === "max") {
1861
+ if (max === null || ch.value < max)
1862
+ max = ch.value;
1863
+ }
1864
+ }
1865
+ return max != null ? new Date(max) : null;
1866
+ }
1867
+ }
1868
+ ZodDate.create = (params) => {
1869
+ return new ZodDate({
1870
+ checks: [],
1871
+ coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
1872
+ typeName: ZodFirstPartyTypeKind.ZodDate,
1873
+ ...processCreateParams(params),
1874
+ });
1875
+ };
1876
+ class ZodSymbol extends ZodType {
1877
+ _parse(input) {
1878
+ const parsedType = this._getType(input);
1879
+ if (parsedType !== ZodParsedType.symbol) {
1880
+ const ctx = this._getOrReturnCtx(input);
1881
+ addIssueToContext(ctx, {
1882
+ code: ZodIssueCode.invalid_type,
1883
+ expected: ZodParsedType.symbol,
1884
+ received: ctx.parsedType,
1885
+ });
1886
+ return INVALID;
1887
+ }
1888
+ return OK(input.data);
1889
+ }
1890
+ }
1891
+ ZodSymbol.create = (params) => {
1892
+ return new ZodSymbol({
1893
+ typeName: ZodFirstPartyTypeKind.ZodSymbol,
1894
+ ...processCreateParams(params),
1895
+ });
1896
+ };
1897
+ class ZodUndefined extends ZodType {
1898
+ _parse(input) {
1899
+ const parsedType = this._getType(input);
1900
+ if (parsedType !== ZodParsedType.undefined) {
1901
+ const ctx = this._getOrReturnCtx(input);
1902
+ addIssueToContext(ctx, {
1903
+ code: ZodIssueCode.invalid_type,
1904
+ expected: ZodParsedType.undefined,
1905
+ received: ctx.parsedType,
1906
+ });
1907
+ return INVALID;
1908
+ }
1909
+ return OK(input.data);
1910
+ }
1911
+ }
1912
+ ZodUndefined.create = (params) => {
1913
+ return new ZodUndefined({
1914
+ typeName: ZodFirstPartyTypeKind.ZodUndefined,
1915
+ ...processCreateParams(params),
1916
+ });
1917
+ };
1918
+ class ZodNull extends ZodType {
1919
+ _parse(input) {
1920
+ const parsedType = this._getType(input);
1921
+ if (parsedType !== ZodParsedType.null) {
1922
+ const ctx = this._getOrReturnCtx(input);
1923
+ addIssueToContext(ctx, {
1924
+ code: ZodIssueCode.invalid_type,
1925
+ expected: ZodParsedType.null,
1926
+ received: ctx.parsedType,
1927
+ });
1928
+ return INVALID;
1929
+ }
1930
+ return OK(input.data);
1931
+ }
1932
+ }
1933
+ ZodNull.create = (params) => {
1934
+ return new ZodNull({
1935
+ typeName: ZodFirstPartyTypeKind.ZodNull,
1936
+ ...processCreateParams(params),
1937
+ });
1938
+ };
1939
+ class ZodAny extends ZodType {
1940
+ constructor() {
1941
+ super(...arguments);
1942
+ // to prevent instances of other classes from extending ZodAny. this causes issues with catchall in ZodObject.
1943
+ this._any = true;
1944
+ }
1945
+ _parse(input) {
1946
+ return OK(input.data);
1947
+ }
1948
+ }
1949
+ ZodAny.create = (params) => {
1950
+ return new ZodAny({
1951
+ typeName: ZodFirstPartyTypeKind.ZodAny,
1952
+ ...processCreateParams(params),
1953
+ });
1954
+ };
1955
+ class ZodUnknown extends ZodType {
1956
+ constructor() {
1957
+ super(...arguments);
1958
+ // required
1959
+ this._unknown = true;
1960
+ }
1961
+ _parse(input) {
1962
+ return OK(input.data);
1963
+ }
1964
+ }
1965
+ ZodUnknown.create = (params) => {
1966
+ return new ZodUnknown({
1967
+ typeName: ZodFirstPartyTypeKind.ZodUnknown,
1968
+ ...processCreateParams(params),
1969
+ });
1970
+ };
1971
+ class ZodNever extends ZodType {
1972
+ _parse(input) {
1973
+ const ctx = this._getOrReturnCtx(input);
1974
+ addIssueToContext(ctx, {
1975
+ code: ZodIssueCode.invalid_type,
1976
+ expected: ZodParsedType.never,
1977
+ received: ctx.parsedType,
1978
+ });
1979
+ return INVALID;
1980
+ }
1981
+ }
1982
+ ZodNever.create = (params) => {
1983
+ return new ZodNever({
1984
+ typeName: ZodFirstPartyTypeKind.ZodNever,
1985
+ ...processCreateParams(params),
1986
+ });
1987
+ };
1988
+ class ZodVoid extends ZodType {
1989
+ _parse(input) {
1990
+ const parsedType = this._getType(input);
1991
+ if (parsedType !== ZodParsedType.undefined) {
1992
+ const ctx = this._getOrReturnCtx(input);
1993
+ addIssueToContext(ctx, {
1994
+ code: ZodIssueCode.invalid_type,
1995
+ expected: ZodParsedType.void,
1996
+ received: ctx.parsedType,
1997
+ });
1998
+ return INVALID;
1999
+ }
2000
+ return OK(input.data);
2001
+ }
2002
+ }
2003
+ ZodVoid.create = (params) => {
2004
+ return new ZodVoid({
2005
+ typeName: ZodFirstPartyTypeKind.ZodVoid,
2006
+ ...processCreateParams(params),
2007
+ });
2008
+ };
2009
+ class ZodArray extends ZodType {
2010
+ _parse(input) {
2011
+ const { ctx, status } = this._processInputParams(input);
2012
+ const def = this._def;
2013
+ if (ctx.parsedType !== ZodParsedType.array) {
2014
+ addIssueToContext(ctx, {
2015
+ code: ZodIssueCode.invalid_type,
2016
+ expected: ZodParsedType.array,
2017
+ received: ctx.parsedType,
2018
+ });
2019
+ return INVALID;
2020
+ }
2021
+ if (def.exactLength !== null) {
2022
+ const tooBig = ctx.data.length > def.exactLength.value;
2023
+ const tooSmall = ctx.data.length < def.exactLength.value;
2024
+ if (tooBig || tooSmall) {
2025
+ addIssueToContext(ctx, {
2026
+ code: tooBig ? ZodIssueCode.too_big : ZodIssueCode.too_small,
2027
+ minimum: (tooSmall ? def.exactLength.value : undefined),
2028
+ maximum: (tooBig ? def.exactLength.value : undefined),
2029
+ type: "array",
2030
+ inclusive: true,
2031
+ exact: true,
2032
+ message: def.exactLength.message,
2033
+ });
2034
+ status.dirty();
2035
+ }
2036
+ }
2037
+ if (def.minLength !== null) {
2038
+ if (ctx.data.length < def.minLength.value) {
2039
+ addIssueToContext(ctx, {
2040
+ code: ZodIssueCode.too_small,
2041
+ minimum: def.minLength.value,
2042
+ type: "array",
2043
+ inclusive: true,
2044
+ exact: false,
2045
+ message: def.minLength.message,
2046
+ });
2047
+ status.dirty();
2048
+ }
2049
+ }
2050
+ if (def.maxLength !== null) {
2051
+ if (ctx.data.length > def.maxLength.value) {
2052
+ addIssueToContext(ctx, {
2053
+ code: ZodIssueCode.too_big,
2054
+ maximum: def.maxLength.value,
2055
+ type: "array",
2056
+ inclusive: true,
2057
+ exact: false,
2058
+ message: def.maxLength.message,
2059
+ });
2060
+ status.dirty();
2061
+ }
2062
+ }
2063
+ if (ctx.common.async) {
2064
+ return Promise.all([...ctx.data].map((item, i) => {
2065
+ return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
2066
+ })).then((result) => {
2067
+ return ParseStatus.mergeArray(status, result);
2068
+ });
2069
+ }
2070
+ const result = [...ctx.data].map((item, i) => {
2071
+ return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
2072
+ });
2073
+ return ParseStatus.mergeArray(status, result);
2074
+ }
2075
+ get element() {
2076
+ return this._def.type;
2077
+ }
2078
+ min(minLength, message) {
2079
+ return new ZodArray({
2080
+ ...this._def,
2081
+ minLength: { value: minLength, message: errorUtil.toString(message) },
2082
+ });
2083
+ }
2084
+ max(maxLength, message) {
2085
+ return new ZodArray({
2086
+ ...this._def,
2087
+ maxLength: { value: maxLength, message: errorUtil.toString(message) },
2088
+ });
2089
+ }
2090
+ length(len, message) {
2091
+ return new ZodArray({
2092
+ ...this._def,
2093
+ exactLength: { value: len, message: errorUtil.toString(message) },
2094
+ });
2095
+ }
2096
+ nonempty(message) {
2097
+ return this.min(1, message);
2098
+ }
2099
+ }
2100
+ ZodArray.create = (schema, params) => {
2101
+ return new ZodArray({
2102
+ type: schema,
2103
+ minLength: null,
2104
+ maxLength: null,
2105
+ exactLength: null,
2106
+ typeName: ZodFirstPartyTypeKind.ZodArray,
2107
+ ...processCreateParams(params),
2108
+ });
2109
+ };
2110
+ function deepPartialify(schema) {
2111
+ if (schema instanceof ZodObject) {
2112
+ const newShape = {};
2113
+ for (const key in schema.shape) {
2114
+ const fieldSchema = schema.shape[key];
2115
+ newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
2116
+ }
2117
+ return new ZodObject({
2118
+ ...schema._def,
2119
+ shape: () => newShape,
2120
+ });
2121
+ }
2122
+ else if (schema instanceof ZodArray) {
2123
+ return new ZodArray({
2124
+ ...schema._def,
2125
+ type: deepPartialify(schema.element),
2126
+ });
2127
+ }
2128
+ else if (schema instanceof ZodOptional) {
2129
+ return ZodOptional.create(deepPartialify(schema.unwrap()));
2130
+ }
2131
+ else if (schema instanceof ZodNullable) {
2132
+ return ZodNullable.create(deepPartialify(schema.unwrap()));
2133
+ }
2134
+ else if (schema instanceof ZodTuple) {
2135
+ return ZodTuple.create(schema.items.map((item) => deepPartialify(item)));
2136
+ }
2137
+ else {
2138
+ return schema;
2139
+ }
2140
+ }
2141
+ class ZodObject extends ZodType {
2142
+ constructor() {
2143
+ super(...arguments);
2144
+ this._cached = null;
2145
+ /**
2146
+ * @deprecated In most cases, this is no longer needed - unknown properties are now silently stripped.
2147
+ * If you want to pass through unknown properties, use `.passthrough()` instead.
2148
+ */
2149
+ this.nonstrict = this.passthrough;
2150
+ // extend<
2151
+ // Augmentation extends ZodRawShape,
2152
+ // NewOutput extends util.flatten<{
2153
+ // [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
2154
+ // ? Augmentation[k]["_output"]
2155
+ // : k extends keyof Output
2156
+ // ? Output[k]
2157
+ // : never;
2158
+ // }>,
2159
+ // NewInput extends util.flatten<{
2160
+ // [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
2161
+ // ? Augmentation[k]["_input"]
2162
+ // : k extends keyof Input
2163
+ // ? Input[k]
2164
+ // : never;
2165
+ // }>
2166
+ // >(
2167
+ // augmentation: Augmentation
2168
+ // ): ZodObject<
2169
+ // extendShape<T, Augmentation>,
2170
+ // UnknownKeys,
2171
+ // Catchall,
2172
+ // NewOutput,
2173
+ // NewInput
2174
+ // > {
2175
+ // return new ZodObject({
2176
+ // ...this._def,
2177
+ // shape: () => ({
2178
+ // ...this._def.shape(),
2179
+ // ...augmentation,
2180
+ // }),
2181
+ // }) as any;
2182
+ // }
2183
+ /**
2184
+ * @deprecated Use `.extend` instead
2185
+ * */
2186
+ this.augment = this.extend;
2187
+ }
2188
+ _getCached() {
2189
+ if (this._cached !== null)
2190
+ return this._cached;
2191
+ const shape = this._def.shape();
2192
+ const keys = util.objectKeys(shape);
2193
+ return (this._cached = { shape, keys });
2194
+ }
2195
+ _parse(input) {
2196
+ const parsedType = this._getType(input);
2197
+ if (parsedType !== ZodParsedType.object) {
2198
+ const ctx = this._getOrReturnCtx(input);
2199
+ addIssueToContext(ctx, {
2200
+ code: ZodIssueCode.invalid_type,
2201
+ expected: ZodParsedType.object,
2202
+ received: ctx.parsedType,
2203
+ });
2204
+ return INVALID;
2205
+ }
2206
+ const { status, ctx } = this._processInputParams(input);
2207
+ const { shape, keys: shapeKeys } = this._getCached();
2208
+ const extraKeys = [];
2209
+ if (!(this._def.catchall instanceof ZodNever &&
2210
+ this._def.unknownKeys === "strip")) {
2211
+ for (const key in ctx.data) {
2212
+ if (!shapeKeys.includes(key)) {
2213
+ extraKeys.push(key);
2214
+ }
2215
+ }
2216
+ }
2217
+ const pairs = [];
2218
+ for (const key of shapeKeys) {
2219
+ const keyValidator = shape[key];
2220
+ const value = ctx.data[key];
2221
+ pairs.push({
2222
+ key: { status: "valid", value: key },
2223
+ value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
2224
+ alwaysSet: key in ctx.data,
2225
+ });
2226
+ }
2227
+ if (this._def.catchall instanceof ZodNever) {
2228
+ const unknownKeys = this._def.unknownKeys;
2229
+ if (unknownKeys === "passthrough") {
2230
+ for (const key of extraKeys) {
2231
+ pairs.push({
2232
+ key: { status: "valid", value: key },
2233
+ value: { status: "valid", value: ctx.data[key] },
2234
+ });
2235
+ }
2236
+ }
2237
+ else if (unknownKeys === "strict") {
2238
+ if (extraKeys.length > 0) {
2239
+ addIssueToContext(ctx, {
2240
+ code: ZodIssueCode.unrecognized_keys,
2241
+ keys: extraKeys,
2242
+ });
2243
+ status.dirty();
2244
+ }
2245
+ }
2246
+ else if (unknownKeys === "strip") ;
2247
+ else {
2248
+ throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
2249
+ }
2250
+ }
2251
+ else {
2252
+ // run catchall validation
2253
+ const catchall = this._def.catchall;
2254
+ for (const key of extraKeys) {
2255
+ const value = ctx.data[key];
2256
+ pairs.push({
2257
+ key: { status: "valid", value: key },
2258
+ value: catchall._parse(new ParseInputLazyPath(ctx, value, ctx.path, key) //, ctx.child(key), value, getParsedType(value)
2259
+ ),
2260
+ alwaysSet: key in ctx.data,
2261
+ });
2262
+ }
2263
+ }
2264
+ if (ctx.common.async) {
2265
+ return Promise.resolve()
2266
+ .then(async () => {
2267
+ const syncPairs = [];
2268
+ for (const pair of pairs) {
2269
+ const key = await pair.key;
2270
+ syncPairs.push({
2271
+ key,
2272
+ value: await pair.value,
2273
+ alwaysSet: pair.alwaysSet,
2274
+ });
2275
+ }
2276
+ return syncPairs;
2277
+ })
2278
+ .then((syncPairs) => {
2279
+ return ParseStatus.mergeObjectSync(status, syncPairs);
2280
+ });
2281
+ }
2282
+ else {
2283
+ return ParseStatus.mergeObjectSync(status, pairs);
2284
+ }
2285
+ }
2286
+ get shape() {
2287
+ return this._def.shape();
2288
+ }
2289
+ strict(message) {
2290
+ return new ZodObject({
2291
+ ...this._def,
2292
+ unknownKeys: "strict",
2293
+ ...(message !== undefined
2294
+ ? {
2295
+ errorMap: (issue, ctx) => {
2296
+ var _a, _b, _c, _d;
2297
+ const defaultError = (_c = (_b = (_a = this._def).errorMap) === null || _b === void 0 ? void 0 : _b.call(_a, issue, ctx).message) !== null && _c !== void 0 ? _c : ctx.defaultError;
2298
+ if (issue.code === "unrecognized_keys")
2299
+ return {
2300
+ message: (_d = errorUtil.errToObj(message).message) !== null && _d !== void 0 ? _d : defaultError,
2301
+ };
2302
+ return {
2303
+ message: defaultError,
2304
+ };
2305
+ },
2306
+ }
2307
+ : {}),
2308
+ });
2309
+ }
2310
+ strip() {
2311
+ return new ZodObject({
2312
+ ...this._def,
2313
+ unknownKeys: "strip",
2314
+ });
2315
+ }
2316
+ passthrough() {
2317
+ return new ZodObject({
2318
+ ...this._def,
2319
+ unknownKeys: "passthrough",
2320
+ });
2321
+ }
2322
+ // const AugmentFactory =
2323
+ // <Def extends ZodObjectDef>(def: Def) =>
2324
+ // <Augmentation extends ZodRawShape>(
2325
+ // augmentation: Augmentation
2326
+ // ): ZodObject<
2327
+ // extendShape<ReturnType<Def["shape"]>, Augmentation>,
2328
+ // Def["unknownKeys"],
2329
+ // Def["catchall"]
2330
+ // > => {
2331
+ // return new ZodObject({
2332
+ // ...def,
2333
+ // shape: () => ({
2334
+ // ...def.shape(),
2335
+ // ...augmentation,
2336
+ // }),
2337
+ // }) as any;
2338
+ // };
2339
+ extend(augmentation) {
2340
+ return new ZodObject({
2341
+ ...this._def,
2342
+ shape: () => ({
2343
+ ...this._def.shape(),
2344
+ ...augmentation,
2345
+ }),
2346
+ });
2347
+ }
2348
+ /**
2349
+ * Prior to zod@1.0.12 there was a bug in the
2350
+ * inferred type of merged objects. Please
2351
+ * upgrade if you are experiencing issues.
2352
+ */
2353
+ merge(merging) {
2354
+ const merged = new ZodObject({
2355
+ unknownKeys: merging._def.unknownKeys,
2356
+ catchall: merging._def.catchall,
2357
+ shape: () => ({
2358
+ ...this._def.shape(),
2359
+ ...merging._def.shape(),
2360
+ }),
2361
+ typeName: ZodFirstPartyTypeKind.ZodObject,
2362
+ });
2363
+ return merged;
2364
+ }
2365
+ // merge<
2366
+ // Incoming extends AnyZodObject,
2367
+ // Augmentation extends Incoming["shape"],
2368
+ // NewOutput extends {
2369
+ // [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
2370
+ // ? Augmentation[k]["_output"]
2371
+ // : k extends keyof Output
2372
+ // ? Output[k]
2373
+ // : never;
2374
+ // },
2375
+ // NewInput extends {
2376
+ // [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
2377
+ // ? Augmentation[k]["_input"]
2378
+ // : k extends keyof Input
2379
+ // ? Input[k]
2380
+ // : never;
2381
+ // }
2382
+ // >(
2383
+ // merging: Incoming
2384
+ // ): ZodObject<
2385
+ // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
2386
+ // Incoming["_def"]["unknownKeys"],
2387
+ // Incoming["_def"]["catchall"],
2388
+ // NewOutput,
2389
+ // NewInput
2390
+ // > {
2391
+ // const merged: any = new ZodObject({
2392
+ // unknownKeys: merging._def.unknownKeys,
2393
+ // catchall: merging._def.catchall,
2394
+ // shape: () =>
2395
+ // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
2396
+ // typeName: ZodFirstPartyTypeKind.ZodObject,
2397
+ // }) as any;
2398
+ // return merged;
2399
+ // }
2400
+ setKey(key, schema) {
2401
+ return this.augment({ [key]: schema });
2402
+ }
2403
+ // merge<Incoming extends AnyZodObject>(
2404
+ // merging: Incoming
2405
+ // ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
2406
+ // ZodObject<
2407
+ // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
2408
+ // Incoming["_def"]["unknownKeys"],
2409
+ // Incoming["_def"]["catchall"]
2410
+ // > {
2411
+ // // const mergedShape = objectUtil.mergeShapes(
2412
+ // // this._def.shape(),
2413
+ // // merging._def.shape()
2414
+ // // );
2415
+ // const merged: any = new ZodObject({
2416
+ // unknownKeys: merging._def.unknownKeys,
2417
+ // catchall: merging._def.catchall,
2418
+ // shape: () =>
2419
+ // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
2420
+ // typeName: ZodFirstPartyTypeKind.ZodObject,
2421
+ // }) as any;
2422
+ // return merged;
2423
+ // }
2424
+ catchall(index) {
2425
+ return new ZodObject({
2426
+ ...this._def,
2427
+ catchall: index,
2428
+ });
2429
+ }
2430
+ pick(mask) {
2431
+ const shape = {};
2432
+ util.objectKeys(mask).forEach((key) => {
2433
+ if (mask[key] && this.shape[key]) {
2434
+ shape[key] = this.shape[key];
2435
+ }
2436
+ });
2437
+ return new ZodObject({
2438
+ ...this._def,
2439
+ shape: () => shape,
2440
+ });
2441
+ }
2442
+ omit(mask) {
2443
+ const shape = {};
2444
+ util.objectKeys(this.shape).forEach((key) => {
2445
+ if (!mask[key]) {
2446
+ shape[key] = this.shape[key];
2447
+ }
2448
+ });
2449
+ return new ZodObject({
2450
+ ...this._def,
2451
+ shape: () => shape,
2452
+ });
2453
+ }
2454
+ /**
2455
+ * @deprecated
2456
+ */
2457
+ deepPartial() {
2458
+ return deepPartialify(this);
2459
+ }
2460
+ partial(mask) {
2461
+ const newShape = {};
2462
+ util.objectKeys(this.shape).forEach((key) => {
2463
+ const fieldSchema = this.shape[key];
2464
+ if (mask && !mask[key]) {
2465
+ newShape[key] = fieldSchema;
2466
+ }
2467
+ else {
2468
+ newShape[key] = fieldSchema.optional();
2469
+ }
2470
+ });
2471
+ return new ZodObject({
2472
+ ...this._def,
2473
+ shape: () => newShape,
2474
+ });
2475
+ }
2476
+ required(mask) {
2477
+ const newShape = {};
2478
+ util.objectKeys(this.shape).forEach((key) => {
2479
+ if (mask && !mask[key]) {
2480
+ newShape[key] = this.shape[key];
2481
+ }
2482
+ else {
2483
+ const fieldSchema = this.shape[key];
2484
+ let newField = fieldSchema;
2485
+ while (newField instanceof ZodOptional) {
2486
+ newField = newField._def.innerType;
2487
+ }
2488
+ newShape[key] = newField;
2489
+ }
2490
+ });
2491
+ return new ZodObject({
2492
+ ...this._def,
2493
+ shape: () => newShape,
2494
+ });
2495
+ }
2496
+ keyof() {
2497
+ return createZodEnum(util.objectKeys(this.shape));
2498
+ }
2499
+ }
2500
+ ZodObject.create = (shape, params) => {
2501
+ return new ZodObject({
2502
+ shape: () => shape,
2503
+ unknownKeys: "strip",
2504
+ catchall: ZodNever.create(),
2505
+ typeName: ZodFirstPartyTypeKind.ZodObject,
2506
+ ...processCreateParams(params),
2507
+ });
2508
+ };
2509
+ ZodObject.strictCreate = (shape, params) => {
2510
+ return new ZodObject({
2511
+ shape: () => shape,
2512
+ unknownKeys: "strict",
2513
+ catchall: ZodNever.create(),
2514
+ typeName: ZodFirstPartyTypeKind.ZodObject,
2515
+ ...processCreateParams(params),
2516
+ });
2517
+ };
2518
+ ZodObject.lazycreate = (shape, params) => {
2519
+ return new ZodObject({
2520
+ shape,
2521
+ unknownKeys: "strip",
2522
+ catchall: ZodNever.create(),
2523
+ typeName: ZodFirstPartyTypeKind.ZodObject,
2524
+ ...processCreateParams(params),
2525
+ });
2526
+ };
2527
+ class ZodUnion extends ZodType {
2528
+ _parse(input) {
2529
+ const { ctx } = this._processInputParams(input);
2530
+ const options = this._def.options;
2531
+ function handleResults(results) {
2532
+ // return first issue-free validation if it exists
2533
+ for (const result of results) {
2534
+ if (result.result.status === "valid") {
2535
+ return result.result;
2536
+ }
2537
+ }
2538
+ for (const result of results) {
2539
+ if (result.result.status === "dirty") {
2540
+ // add issues from dirty option
2541
+ ctx.common.issues.push(...result.ctx.common.issues);
2542
+ return result.result;
2543
+ }
2544
+ }
2545
+ // return invalid
2546
+ const unionErrors = results.map((result) => new ZodError(result.ctx.common.issues));
2547
+ addIssueToContext(ctx, {
2548
+ code: ZodIssueCode.invalid_union,
2549
+ unionErrors,
2550
+ });
2551
+ return INVALID;
2552
+ }
2553
+ if (ctx.common.async) {
2554
+ return Promise.all(options.map(async (option) => {
2555
+ const childCtx = {
2556
+ ...ctx,
2557
+ common: {
2558
+ ...ctx.common,
2559
+ issues: [],
2560
+ },
2561
+ parent: null,
2562
+ };
2563
+ return {
2564
+ result: await option._parseAsync({
2565
+ data: ctx.data,
2566
+ path: ctx.path,
2567
+ parent: childCtx,
2568
+ }),
2569
+ ctx: childCtx,
2570
+ };
2571
+ })).then(handleResults);
2572
+ }
2573
+ else {
2574
+ let dirty = undefined;
2575
+ const issues = [];
2576
+ for (const option of options) {
2577
+ const childCtx = {
2578
+ ...ctx,
2579
+ common: {
2580
+ ...ctx.common,
2581
+ issues: [],
2582
+ },
2583
+ parent: null,
2584
+ };
2585
+ const result = option._parseSync({
2586
+ data: ctx.data,
2587
+ path: ctx.path,
2588
+ parent: childCtx,
2589
+ });
2590
+ if (result.status === "valid") {
2591
+ return result;
2592
+ }
2593
+ else if (result.status === "dirty" && !dirty) {
2594
+ dirty = { result, ctx: childCtx };
2595
+ }
2596
+ if (childCtx.common.issues.length) {
2597
+ issues.push(childCtx.common.issues);
2598
+ }
2599
+ }
2600
+ if (dirty) {
2601
+ ctx.common.issues.push(...dirty.ctx.common.issues);
2602
+ return dirty.result;
2603
+ }
2604
+ const unionErrors = issues.map((issues) => new ZodError(issues));
2605
+ addIssueToContext(ctx, {
2606
+ code: ZodIssueCode.invalid_union,
2607
+ unionErrors,
2608
+ });
2609
+ return INVALID;
2610
+ }
2611
+ }
2612
+ get options() {
2613
+ return this._def.options;
2614
+ }
2615
+ }
2616
+ ZodUnion.create = (types, params) => {
2617
+ return new ZodUnion({
2618
+ options: types,
2619
+ typeName: ZodFirstPartyTypeKind.ZodUnion,
2620
+ ...processCreateParams(params),
2621
+ });
2622
+ };
2623
+ /////////////////////////////////////////////////////
2624
+ /////////////////////////////////////////////////////
2625
+ ////////// //////////
2626
+ ////////// ZodDiscriminatedUnion //////////
2627
+ ////////// //////////
2628
+ /////////////////////////////////////////////////////
2629
+ /////////////////////////////////////////////////////
2630
+ const getDiscriminator = (type) => {
2631
+ if (type instanceof ZodLazy) {
2632
+ return getDiscriminator(type.schema);
2633
+ }
2634
+ else if (type instanceof ZodEffects) {
2635
+ return getDiscriminator(type.innerType());
2636
+ }
2637
+ else if (type instanceof ZodLiteral) {
2638
+ return [type.value];
2639
+ }
2640
+ else if (type instanceof ZodEnum) {
2641
+ return type.options;
2642
+ }
2643
+ else if (type instanceof ZodNativeEnum) {
2644
+ // eslint-disable-next-line ban/ban
2645
+ return Object.keys(type.enum);
2646
+ }
2647
+ else if (type instanceof ZodDefault) {
2648
+ return getDiscriminator(type._def.innerType);
2649
+ }
2650
+ else if (type instanceof ZodUndefined) {
2651
+ return [undefined];
2652
+ }
2653
+ else if (type instanceof ZodNull) {
2654
+ return [null];
2655
+ }
2656
+ else {
2657
+ return null;
2658
+ }
2659
+ };
2660
+ class ZodDiscriminatedUnion extends ZodType {
2661
+ _parse(input) {
2662
+ const { ctx } = this._processInputParams(input);
2663
+ if (ctx.parsedType !== ZodParsedType.object) {
2664
+ addIssueToContext(ctx, {
2665
+ code: ZodIssueCode.invalid_type,
2666
+ expected: ZodParsedType.object,
2667
+ received: ctx.parsedType,
2668
+ });
2669
+ return INVALID;
2670
+ }
2671
+ const discriminator = this.discriminator;
2672
+ const discriminatorValue = ctx.data[discriminator];
2673
+ const option = this.optionsMap.get(discriminatorValue);
2674
+ if (!option) {
2675
+ addIssueToContext(ctx, {
2676
+ code: ZodIssueCode.invalid_union_discriminator,
2677
+ options: Array.from(this.optionsMap.keys()),
2678
+ path: [discriminator],
2679
+ });
2680
+ return INVALID;
2681
+ }
2682
+ if (ctx.common.async) {
2683
+ return option._parseAsync({
2684
+ data: ctx.data,
2685
+ path: ctx.path,
2686
+ parent: ctx,
2687
+ });
2688
+ }
2689
+ else {
2690
+ return option._parseSync({
2691
+ data: ctx.data,
2692
+ path: ctx.path,
2693
+ parent: ctx,
2694
+ });
2695
+ }
2696
+ }
2697
+ get discriminator() {
2698
+ return this._def.discriminator;
2699
+ }
2700
+ get options() {
2701
+ return this._def.options;
2702
+ }
2703
+ get optionsMap() {
2704
+ return this._def.optionsMap;
2705
+ }
2706
+ /**
2707
+ * The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
2708
+ * However, it only allows a union of objects, all of which need to share a discriminator property. This property must
2709
+ * have a different value for each object in the union.
2710
+ * @param discriminator the name of the discriminator property
2711
+ * @param types an array of object schemas
2712
+ * @param params
2713
+ */
2714
+ static create(discriminator, options, params) {
2715
+ // Get all the valid discriminator values
2716
+ const optionsMap = new Map();
2717
+ // try {
2718
+ for (const type of options) {
2719
+ const discriminatorValues = getDiscriminator(type.shape[discriminator]);
2720
+ if (!discriminatorValues) {
2721
+ throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
2722
+ }
2723
+ for (const value of discriminatorValues) {
2724
+ if (optionsMap.has(value)) {
2725
+ throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
2726
+ }
2727
+ optionsMap.set(value, type);
2728
+ }
2729
+ }
2730
+ return new ZodDiscriminatedUnion({
2731
+ typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
2732
+ discriminator,
2733
+ options,
2734
+ optionsMap,
2735
+ ...processCreateParams(params),
2736
+ });
2737
+ }
2738
+ }
2739
+ function mergeValues(a, b) {
2740
+ const aType = getParsedType(a);
2741
+ const bType = getParsedType(b);
2742
+ if (a === b) {
2743
+ return { valid: true, data: a };
2744
+ }
2745
+ else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
2746
+ const bKeys = util.objectKeys(b);
2747
+ const sharedKeys = util
2748
+ .objectKeys(a)
2749
+ .filter((key) => bKeys.indexOf(key) !== -1);
2750
+ const newObj = { ...a, ...b };
2751
+ for (const key of sharedKeys) {
2752
+ const sharedValue = mergeValues(a[key], b[key]);
2753
+ if (!sharedValue.valid) {
2754
+ return { valid: false };
2755
+ }
2756
+ newObj[key] = sharedValue.data;
2757
+ }
2758
+ return { valid: true, data: newObj };
2759
+ }
2760
+ else if (aType === ZodParsedType.array && bType === ZodParsedType.array) {
2761
+ if (a.length !== b.length) {
2762
+ return { valid: false };
2763
+ }
2764
+ const newArray = [];
2765
+ for (let index = 0; index < a.length; index++) {
2766
+ const itemA = a[index];
2767
+ const itemB = b[index];
2768
+ const sharedValue = mergeValues(itemA, itemB);
2769
+ if (!sharedValue.valid) {
2770
+ return { valid: false };
2771
+ }
2772
+ newArray.push(sharedValue.data);
2773
+ }
2774
+ return { valid: true, data: newArray };
2775
+ }
2776
+ else if (aType === ZodParsedType.date &&
2777
+ bType === ZodParsedType.date &&
2778
+ +a === +b) {
2779
+ return { valid: true, data: a };
2780
+ }
2781
+ else {
2782
+ return { valid: false };
2783
+ }
2784
+ }
2785
+ class ZodIntersection extends ZodType {
2786
+ _parse(input) {
2787
+ const { status, ctx } = this._processInputParams(input);
2788
+ const handleParsed = (parsedLeft, parsedRight) => {
2789
+ if (isAborted(parsedLeft) || isAborted(parsedRight)) {
2790
+ return INVALID;
2791
+ }
2792
+ const merged = mergeValues(parsedLeft.value, parsedRight.value);
2793
+ if (!merged.valid) {
2794
+ addIssueToContext(ctx, {
2795
+ code: ZodIssueCode.invalid_intersection_types,
2796
+ });
2797
+ return INVALID;
2798
+ }
2799
+ if (isDirty(parsedLeft) || isDirty(parsedRight)) {
2800
+ status.dirty();
2801
+ }
2802
+ return { status: status.value, value: merged.data };
2803
+ };
2804
+ if (ctx.common.async) {
2805
+ return Promise.all([
2806
+ this._def.left._parseAsync({
2807
+ data: ctx.data,
2808
+ path: ctx.path,
2809
+ parent: ctx,
2810
+ }),
2811
+ this._def.right._parseAsync({
2812
+ data: ctx.data,
2813
+ path: ctx.path,
2814
+ parent: ctx,
2815
+ }),
2816
+ ]).then(([left, right]) => handleParsed(left, right));
2817
+ }
2818
+ else {
2819
+ return handleParsed(this._def.left._parseSync({
2820
+ data: ctx.data,
2821
+ path: ctx.path,
2822
+ parent: ctx,
2823
+ }), this._def.right._parseSync({
2824
+ data: ctx.data,
2825
+ path: ctx.path,
2826
+ parent: ctx,
2827
+ }));
2828
+ }
2829
+ }
2830
+ }
2831
+ ZodIntersection.create = (left, right, params) => {
2832
+ return new ZodIntersection({
2833
+ left: left,
2834
+ right: right,
2835
+ typeName: ZodFirstPartyTypeKind.ZodIntersection,
2836
+ ...processCreateParams(params),
2837
+ });
2838
+ };
2839
+ class ZodTuple extends ZodType {
2840
+ _parse(input) {
2841
+ const { status, ctx } = this._processInputParams(input);
2842
+ if (ctx.parsedType !== ZodParsedType.array) {
2843
+ addIssueToContext(ctx, {
2844
+ code: ZodIssueCode.invalid_type,
2845
+ expected: ZodParsedType.array,
2846
+ received: ctx.parsedType,
2847
+ });
2848
+ return INVALID;
2849
+ }
2850
+ if (ctx.data.length < this._def.items.length) {
2851
+ addIssueToContext(ctx, {
2852
+ code: ZodIssueCode.too_small,
2853
+ minimum: this._def.items.length,
2854
+ inclusive: true,
2855
+ exact: false,
2856
+ type: "array",
2857
+ });
2858
+ return INVALID;
2859
+ }
2860
+ const rest = this._def.rest;
2861
+ if (!rest && ctx.data.length > this._def.items.length) {
2862
+ addIssueToContext(ctx, {
2863
+ code: ZodIssueCode.too_big,
2864
+ maximum: this._def.items.length,
2865
+ inclusive: true,
2866
+ exact: false,
2867
+ type: "array",
2868
+ });
2869
+ status.dirty();
2870
+ }
2871
+ const items = [...ctx.data]
2872
+ .map((item, itemIndex) => {
2873
+ const schema = this._def.items[itemIndex] || this._def.rest;
2874
+ if (!schema)
2875
+ return null;
2876
+ return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
2877
+ })
2878
+ .filter((x) => !!x); // filter nulls
2879
+ if (ctx.common.async) {
2880
+ return Promise.all(items).then((results) => {
2881
+ return ParseStatus.mergeArray(status, results);
2882
+ });
2883
+ }
2884
+ else {
2885
+ return ParseStatus.mergeArray(status, items);
2886
+ }
2887
+ }
2888
+ get items() {
2889
+ return this._def.items;
2890
+ }
2891
+ rest(rest) {
2892
+ return new ZodTuple({
2893
+ ...this._def,
2894
+ rest,
2895
+ });
2896
+ }
2897
+ }
2898
+ ZodTuple.create = (schemas, params) => {
2899
+ if (!Array.isArray(schemas)) {
2900
+ throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
2901
+ }
2902
+ return new ZodTuple({
2903
+ items: schemas,
2904
+ typeName: ZodFirstPartyTypeKind.ZodTuple,
2905
+ rest: null,
2906
+ ...processCreateParams(params),
2907
+ });
2908
+ };
2909
+ class ZodRecord extends ZodType {
2910
+ get keySchema() {
2911
+ return this._def.keyType;
2912
+ }
2913
+ get valueSchema() {
2914
+ return this._def.valueType;
2915
+ }
2916
+ _parse(input) {
2917
+ const { status, ctx } = this._processInputParams(input);
2918
+ if (ctx.parsedType !== ZodParsedType.object) {
2919
+ addIssueToContext(ctx, {
2920
+ code: ZodIssueCode.invalid_type,
2921
+ expected: ZodParsedType.object,
2922
+ received: ctx.parsedType,
2923
+ });
2924
+ return INVALID;
2925
+ }
2926
+ const pairs = [];
2927
+ const keyType = this._def.keyType;
2928
+ const valueType = this._def.valueType;
2929
+ for (const key in ctx.data) {
2930
+ pairs.push({
2931
+ key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
2932
+ value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
2933
+ });
2934
+ }
2935
+ if (ctx.common.async) {
2936
+ return ParseStatus.mergeObjectAsync(status, pairs);
2937
+ }
2938
+ else {
2939
+ return ParseStatus.mergeObjectSync(status, pairs);
2940
+ }
2941
+ }
2942
+ get element() {
2943
+ return this._def.valueType;
2944
+ }
2945
+ static create(first, second, third) {
2946
+ if (second instanceof ZodType) {
2947
+ return new ZodRecord({
2948
+ keyType: first,
2949
+ valueType: second,
2950
+ typeName: ZodFirstPartyTypeKind.ZodRecord,
2951
+ ...processCreateParams(third),
2952
+ });
2953
+ }
2954
+ return new ZodRecord({
2955
+ keyType: ZodString.create(),
2956
+ valueType: first,
2957
+ typeName: ZodFirstPartyTypeKind.ZodRecord,
2958
+ ...processCreateParams(second),
2959
+ });
2960
+ }
2961
+ }
2962
+ class ZodMap extends ZodType {
2963
+ get keySchema() {
2964
+ return this._def.keyType;
2965
+ }
2966
+ get valueSchema() {
2967
+ return this._def.valueType;
2968
+ }
2969
+ _parse(input) {
2970
+ const { status, ctx } = this._processInputParams(input);
2971
+ if (ctx.parsedType !== ZodParsedType.map) {
2972
+ addIssueToContext(ctx, {
2973
+ code: ZodIssueCode.invalid_type,
2974
+ expected: ZodParsedType.map,
2975
+ received: ctx.parsedType,
2976
+ });
2977
+ return INVALID;
2978
+ }
2979
+ const keyType = this._def.keyType;
2980
+ const valueType = this._def.valueType;
2981
+ const pairs = [...ctx.data.entries()].map(([key, value], index) => {
2982
+ return {
2983
+ key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index, "key"])),
2984
+ value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index, "value"])),
2985
+ };
2986
+ });
2987
+ if (ctx.common.async) {
2988
+ const finalMap = new Map();
2989
+ return Promise.resolve().then(async () => {
2990
+ for (const pair of pairs) {
2991
+ const key = await pair.key;
2992
+ const value = await pair.value;
2993
+ if (key.status === "aborted" || value.status === "aborted") {
2994
+ return INVALID;
2995
+ }
2996
+ if (key.status === "dirty" || value.status === "dirty") {
2997
+ status.dirty();
2998
+ }
2999
+ finalMap.set(key.value, value.value);
3000
+ }
3001
+ return { status: status.value, value: finalMap };
3002
+ });
3003
+ }
3004
+ else {
3005
+ const finalMap = new Map();
3006
+ for (const pair of pairs) {
3007
+ const key = pair.key;
3008
+ const value = pair.value;
3009
+ if (key.status === "aborted" || value.status === "aborted") {
3010
+ return INVALID;
3011
+ }
3012
+ if (key.status === "dirty" || value.status === "dirty") {
3013
+ status.dirty();
3014
+ }
3015
+ finalMap.set(key.value, value.value);
3016
+ }
3017
+ return { status: status.value, value: finalMap };
3018
+ }
3019
+ }
3020
+ }
3021
+ ZodMap.create = (keyType, valueType, params) => {
3022
+ return new ZodMap({
3023
+ valueType,
3024
+ keyType,
3025
+ typeName: ZodFirstPartyTypeKind.ZodMap,
3026
+ ...processCreateParams(params),
3027
+ });
3028
+ };
3029
+ class ZodSet extends ZodType {
3030
+ _parse(input) {
3031
+ const { status, ctx } = this._processInputParams(input);
3032
+ if (ctx.parsedType !== ZodParsedType.set) {
3033
+ addIssueToContext(ctx, {
3034
+ code: ZodIssueCode.invalid_type,
3035
+ expected: ZodParsedType.set,
3036
+ received: ctx.parsedType,
3037
+ });
3038
+ return INVALID;
3039
+ }
3040
+ const def = this._def;
3041
+ if (def.minSize !== null) {
3042
+ if (ctx.data.size < def.minSize.value) {
3043
+ addIssueToContext(ctx, {
3044
+ code: ZodIssueCode.too_small,
3045
+ minimum: def.minSize.value,
3046
+ type: "set",
3047
+ inclusive: true,
3048
+ exact: false,
3049
+ message: def.minSize.message,
3050
+ });
3051
+ status.dirty();
3052
+ }
3053
+ }
3054
+ if (def.maxSize !== null) {
3055
+ if (ctx.data.size > def.maxSize.value) {
3056
+ addIssueToContext(ctx, {
3057
+ code: ZodIssueCode.too_big,
3058
+ maximum: def.maxSize.value,
3059
+ type: "set",
3060
+ inclusive: true,
3061
+ exact: false,
3062
+ message: def.maxSize.message,
3063
+ });
3064
+ status.dirty();
3065
+ }
3066
+ }
3067
+ const valueType = this._def.valueType;
3068
+ function finalizeSet(elements) {
3069
+ const parsedSet = new Set();
3070
+ for (const element of elements) {
3071
+ if (element.status === "aborted")
3072
+ return INVALID;
3073
+ if (element.status === "dirty")
3074
+ status.dirty();
3075
+ parsedSet.add(element.value);
3076
+ }
3077
+ return { status: status.value, value: parsedSet };
3078
+ }
3079
+ const elements = [...ctx.data.values()].map((item, i) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
3080
+ if (ctx.common.async) {
3081
+ return Promise.all(elements).then((elements) => finalizeSet(elements));
3082
+ }
3083
+ else {
3084
+ return finalizeSet(elements);
3085
+ }
3086
+ }
3087
+ min(minSize, message) {
3088
+ return new ZodSet({
3089
+ ...this._def,
3090
+ minSize: { value: minSize, message: errorUtil.toString(message) },
3091
+ });
3092
+ }
3093
+ max(maxSize, message) {
3094
+ return new ZodSet({
3095
+ ...this._def,
3096
+ maxSize: { value: maxSize, message: errorUtil.toString(message) },
3097
+ });
3098
+ }
3099
+ size(size, message) {
3100
+ return this.min(size, message).max(size, message);
3101
+ }
3102
+ nonempty(message) {
3103
+ return this.min(1, message);
3104
+ }
3105
+ }
3106
+ ZodSet.create = (valueType, params) => {
3107
+ return new ZodSet({
3108
+ valueType,
3109
+ minSize: null,
3110
+ maxSize: null,
3111
+ typeName: ZodFirstPartyTypeKind.ZodSet,
3112
+ ...processCreateParams(params),
3113
+ });
3114
+ };
3115
+ class ZodFunction extends ZodType {
3116
+ constructor() {
3117
+ super(...arguments);
3118
+ this.validate = this.implement;
3119
+ }
3120
+ _parse(input) {
3121
+ const { ctx } = this._processInputParams(input);
3122
+ if (ctx.parsedType !== ZodParsedType.function) {
3123
+ addIssueToContext(ctx, {
3124
+ code: ZodIssueCode.invalid_type,
3125
+ expected: ZodParsedType.function,
3126
+ received: ctx.parsedType,
3127
+ });
3128
+ return INVALID;
3129
+ }
3130
+ function makeArgsIssue(args, error) {
3131
+ return makeIssue({
3132
+ data: args,
3133
+ path: ctx.path,
3134
+ errorMaps: [
3135
+ ctx.common.contextualErrorMap,
3136
+ ctx.schemaErrorMap,
3137
+ getErrorMap(),
3138
+ errorMap,
3139
+ ].filter((x) => !!x),
3140
+ issueData: {
3141
+ code: ZodIssueCode.invalid_arguments,
3142
+ argumentsError: error,
3143
+ },
3144
+ });
3145
+ }
3146
+ function makeReturnsIssue(returns, error) {
3147
+ return makeIssue({
3148
+ data: returns,
3149
+ path: ctx.path,
3150
+ errorMaps: [
3151
+ ctx.common.contextualErrorMap,
3152
+ ctx.schemaErrorMap,
3153
+ getErrorMap(),
3154
+ errorMap,
3155
+ ].filter((x) => !!x),
3156
+ issueData: {
3157
+ code: ZodIssueCode.invalid_return_type,
3158
+ returnTypeError: error,
3159
+ },
3160
+ });
3161
+ }
3162
+ const params = { errorMap: ctx.common.contextualErrorMap };
3163
+ const fn = ctx.data;
3164
+ if (this._def.returns instanceof ZodPromise) {
3165
+ // Would love a way to avoid disabling this rule, but we need
3166
+ // an alias (using an arrow function was what caused 2651).
3167
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
3168
+ const me = this;
3169
+ return OK(async function (...args) {
3170
+ const error = new ZodError([]);
3171
+ const parsedArgs = await me._def.args
3172
+ .parseAsync(args, params)
3173
+ .catch((e) => {
3174
+ error.addIssue(makeArgsIssue(args, e));
3175
+ throw error;
3176
+ });
3177
+ const result = await Reflect.apply(fn, this, parsedArgs);
3178
+ const parsedReturns = await me._def.returns._def.type
3179
+ .parseAsync(result, params)
3180
+ .catch((e) => {
3181
+ error.addIssue(makeReturnsIssue(result, e));
3182
+ throw error;
3183
+ });
3184
+ return parsedReturns;
3185
+ });
3186
+ }
3187
+ else {
3188
+ // Would love a way to avoid disabling this rule, but we need
3189
+ // an alias (using an arrow function was what caused 2651).
3190
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
3191
+ const me = this;
3192
+ return OK(function (...args) {
3193
+ const parsedArgs = me._def.args.safeParse(args, params);
3194
+ if (!parsedArgs.success) {
3195
+ throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
3196
+ }
3197
+ const result = Reflect.apply(fn, this, parsedArgs.data);
3198
+ const parsedReturns = me._def.returns.safeParse(result, params);
3199
+ if (!parsedReturns.success) {
3200
+ throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
3201
+ }
3202
+ return parsedReturns.data;
3203
+ });
3204
+ }
3205
+ }
3206
+ parameters() {
3207
+ return this._def.args;
3208
+ }
3209
+ returnType() {
3210
+ return this._def.returns;
3211
+ }
3212
+ args(...items) {
3213
+ return new ZodFunction({
3214
+ ...this._def,
3215
+ args: ZodTuple.create(items).rest(ZodUnknown.create()),
3216
+ });
3217
+ }
3218
+ returns(returnType) {
3219
+ return new ZodFunction({
3220
+ ...this._def,
3221
+ returns: returnType,
3222
+ });
3223
+ }
3224
+ implement(func) {
3225
+ const validatedFunc = this.parse(func);
3226
+ return validatedFunc;
3227
+ }
3228
+ strictImplement(func) {
3229
+ const validatedFunc = this.parse(func);
3230
+ return validatedFunc;
3231
+ }
3232
+ static create(args, returns, params) {
3233
+ return new ZodFunction({
3234
+ args: (args
3235
+ ? args
3236
+ : ZodTuple.create([]).rest(ZodUnknown.create())),
3237
+ returns: returns || ZodUnknown.create(),
3238
+ typeName: ZodFirstPartyTypeKind.ZodFunction,
3239
+ ...processCreateParams(params),
3240
+ });
3241
+ }
3242
+ }
3243
+ class ZodLazy extends ZodType {
3244
+ get schema() {
3245
+ return this._def.getter();
3246
+ }
3247
+ _parse(input) {
3248
+ const { ctx } = this._processInputParams(input);
3249
+ const lazySchema = this._def.getter();
3250
+ return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx });
3251
+ }
3252
+ }
3253
+ ZodLazy.create = (getter, params) => {
3254
+ return new ZodLazy({
3255
+ getter: getter,
3256
+ typeName: ZodFirstPartyTypeKind.ZodLazy,
3257
+ ...processCreateParams(params),
3258
+ });
3259
+ };
3260
+ class ZodLiteral extends ZodType {
3261
+ _parse(input) {
3262
+ if (input.data !== this._def.value) {
3263
+ const ctx = this._getOrReturnCtx(input);
3264
+ addIssueToContext(ctx, {
3265
+ received: ctx.data,
3266
+ code: ZodIssueCode.invalid_literal,
3267
+ expected: this._def.value,
3268
+ });
3269
+ return INVALID;
3270
+ }
3271
+ return { status: "valid", value: input.data };
3272
+ }
3273
+ get value() {
3274
+ return this._def.value;
3275
+ }
3276
+ }
3277
+ ZodLiteral.create = (value, params) => {
3278
+ return new ZodLiteral({
3279
+ value: value,
3280
+ typeName: ZodFirstPartyTypeKind.ZodLiteral,
3281
+ ...processCreateParams(params),
3282
+ });
3283
+ };
3284
+ function createZodEnum(values, params) {
3285
+ return new ZodEnum({
3286
+ values,
3287
+ typeName: ZodFirstPartyTypeKind.ZodEnum,
3288
+ ...processCreateParams(params),
3289
+ });
3290
+ }
3291
+ class ZodEnum extends ZodType {
3292
+ _parse(input) {
3293
+ if (typeof input.data !== "string") {
3294
+ const ctx = this._getOrReturnCtx(input);
3295
+ const expectedValues = this._def.values;
3296
+ addIssueToContext(ctx, {
3297
+ expected: util.joinValues(expectedValues),
3298
+ received: ctx.parsedType,
3299
+ code: ZodIssueCode.invalid_type,
3300
+ });
3301
+ return INVALID;
3302
+ }
3303
+ if (this._def.values.indexOf(input.data) === -1) {
3304
+ const ctx = this._getOrReturnCtx(input);
3305
+ const expectedValues = this._def.values;
3306
+ addIssueToContext(ctx, {
3307
+ received: ctx.data,
3308
+ code: ZodIssueCode.invalid_enum_value,
3309
+ options: expectedValues,
3310
+ });
3311
+ return INVALID;
3312
+ }
3313
+ return OK(input.data);
3314
+ }
3315
+ get options() {
3316
+ return this._def.values;
3317
+ }
3318
+ get enum() {
3319
+ const enumValues = {};
3320
+ for (const val of this._def.values) {
3321
+ enumValues[val] = val;
3322
+ }
3323
+ return enumValues;
3324
+ }
3325
+ get Values() {
3326
+ const enumValues = {};
3327
+ for (const val of this._def.values) {
3328
+ enumValues[val] = val;
3329
+ }
3330
+ return enumValues;
3331
+ }
3332
+ get Enum() {
3333
+ const enumValues = {};
3334
+ for (const val of this._def.values) {
3335
+ enumValues[val] = val;
3336
+ }
3337
+ return enumValues;
3338
+ }
3339
+ extract(values) {
3340
+ return ZodEnum.create(values);
3341
+ }
3342
+ exclude(values) {
3343
+ return ZodEnum.create(this.options.filter((opt) => !values.includes(opt)));
3344
+ }
3345
+ }
3346
+ ZodEnum.create = createZodEnum;
3347
+ class ZodNativeEnum extends ZodType {
3348
+ _parse(input) {
3349
+ const nativeEnumValues = util.getValidEnumValues(this._def.values);
3350
+ const ctx = this._getOrReturnCtx(input);
3351
+ if (ctx.parsedType !== ZodParsedType.string &&
3352
+ ctx.parsedType !== ZodParsedType.number) {
3353
+ const expectedValues = util.objectValues(nativeEnumValues);
3354
+ addIssueToContext(ctx, {
3355
+ expected: util.joinValues(expectedValues),
3356
+ received: ctx.parsedType,
3357
+ code: ZodIssueCode.invalid_type,
3358
+ });
3359
+ return INVALID;
3360
+ }
3361
+ if (nativeEnumValues.indexOf(input.data) === -1) {
3362
+ const expectedValues = util.objectValues(nativeEnumValues);
3363
+ addIssueToContext(ctx, {
3364
+ received: ctx.data,
3365
+ code: ZodIssueCode.invalid_enum_value,
3366
+ options: expectedValues,
3367
+ });
3368
+ return INVALID;
3369
+ }
3370
+ return OK(input.data);
3371
+ }
3372
+ get enum() {
3373
+ return this._def.values;
3374
+ }
3375
+ }
3376
+ ZodNativeEnum.create = (values, params) => {
3377
+ return new ZodNativeEnum({
3378
+ values: values,
3379
+ typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
3380
+ ...processCreateParams(params),
3381
+ });
3382
+ };
3383
+ class ZodPromise extends ZodType {
3384
+ unwrap() {
3385
+ return this._def.type;
3386
+ }
3387
+ _parse(input) {
3388
+ const { ctx } = this._processInputParams(input);
3389
+ if (ctx.parsedType !== ZodParsedType.promise &&
3390
+ ctx.common.async === false) {
3391
+ addIssueToContext(ctx, {
3392
+ code: ZodIssueCode.invalid_type,
3393
+ expected: ZodParsedType.promise,
3394
+ received: ctx.parsedType,
3395
+ });
3396
+ return INVALID;
3397
+ }
3398
+ const promisified = ctx.parsedType === ZodParsedType.promise
3399
+ ? ctx.data
3400
+ : Promise.resolve(ctx.data);
3401
+ return OK(promisified.then((data) => {
3402
+ return this._def.type.parseAsync(data, {
3403
+ path: ctx.path,
3404
+ errorMap: ctx.common.contextualErrorMap,
3405
+ });
3406
+ }));
3407
+ }
3408
+ }
3409
+ ZodPromise.create = (schema, params) => {
3410
+ return new ZodPromise({
3411
+ type: schema,
3412
+ typeName: ZodFirstPartyTypeKind.ZodPromise,
3413
+ ...processCreateParams(params),
3414
+ });
3415
+ };
3416
+ class ZodEffects extends ZodType {
3417
+ innerType() {
3418
+ return this._def.schema;
3419
+ }
3420
+ sourceType() {
3421
+ return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects
3422
+ ? this._def.schema.sourceType()
3423
+ : this._def.schema;
3424
+ }
3425
+ _parse(input) {
3426
+ const { status, ctx } = this._processInputParams(input);
3427
+ const effect = this._def.effect || null;
3428
+ const checkCtx = {
3429
+ addIssue: (arg) => {
3430
+ addIssueToContext(ctx, arg);
3431
+ if (arg.fatal) {
3432
+ status.abort();
3433
+ }
3434
+ else {
3435
+ status.dirty();
3436
+ }
3437
+ },
3438
+ get path() {
3439
+ return ctx.path;
3440
+ },
3441
+ };
3442
+ checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
3443
+ if (effect.type === "preprocess") {
3444
+ const processed = effect.transform(ctx.data, checkCtx);
3445
+ if (ctx.common.issues.length) {
3446
+ return {
3447
+ status: "dirty",
3448
+ value: ctx.data,
3449
+ };
3450
+ }
3451
+ if (ctx.common.async) {
3452
+ return Promise.resolve(processed).then((processed) => {
3453
+ return this._def.schema._parseAsync({
3454
+ data: processed,
3455
+ path: ctx.path,
3456
+ parent: ctx,
3457
+ });
3458
+ });
3459
+ }
3460
+ else {
3461
+ return this._def.schema._parseSync({
3462
+ data: processed,
3463
+ path: ctx.path,
3464
+ parent: ctx,
3465
+ });
3466
+ }
3467
+ }
3468
+ if (effect.type === "refinement") {
3469
+ const executeRefinement = (acc
3470
+ // effect: RefinementEffect<any>
3471
+ ) => {
3472
+ const result = effect.refinement(acc, checkCtx);
3473
+ if (ctx.common.async) {
3474
+ return Promise.resolve(result);
3475
+ }
3476
+ if (result instanceof Promise) {
3477
+ throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
3478
+ }
3479
+ return acc;
3480
+ };
3481
+ if (ctx.common.async === false) {
3482
+ const inner = this._def.schema._parseSync({
3483
+ data: ctx.data,
3484
+ path: ctx.path,
3485
+ parent: ctx,
3486
+ });
3487
+ if (inner.status === "aborted")
3488
+ return INVALID;
3489
+ if (inner.status === "dirty")
3490
+ status.dirty();
3491
+ // return value is ignored
3492
+ executeRefinement(inner.value);
3493
+ return { status: status.value, value: inner.value };
3494
+ }
3495
+ else {
3496
+ return this._def.schema
3497
+ ._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx })
3498
+ .then((inner) => {
3499
+ if (inner.status === "aborted")
3500
+ return INVALID;
3501
+ if (inner.status === "dirty")
3502
+ status.dirty();
3503
+ return executeRefinement(inner.value).then(() => {
3504
+ return { status: status.value, value: inner.value };
3505
+ });
3506
+ });
3507
+ }
3508
+ }
3509
+ if (effect.type === "transform") {
3510
+ if (ctx.common.async === false) {
3511
+ const base = this._def.schema._parseSync({
3512
+ data: ctx.data,
3513
+ path: ctx.path,
3514
+ parent: ctx,
3515
+ });
3516
+ if (!isValid(base))
3517
+ return base;
3518
+ const result = effect.transform(base.value, checkCtx);
3519
+ if (result instanceof Promise) {
3520
+ throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
3521
+ }
3522
+ return { status: status.value, value: result };
3523
+ }
3524
+ else {
3525
+ return this._def.schema
3526
+ ._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx })
3527
+ .then((base) => {
3528
+ if (!isValid(base))
3529
+ return base;
3530
+ return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({ status: status.value, value: result }));
3531
+ });
3532
+ }
3533
+ }
3534
+ util.assertNever(effect);
3535
+ }
3536
+ }
3537
+ ZodEffects.create = (schema, effect, params) => {
3538
+ return new ZodEffects({
3539
+ schema,
3540
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
3541
+ effect,
3542
+ ...processCreateParams(params),
3543
+ });
3544
+ };
3545
+ ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
3546
+ return new ZodEffects({
3547
+ schema,
3548
+ effect: { type: "preprocess", transform: preprocess },
3549
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
3550
+ ...processCreateParams(params),
3551
+ });
3552
+ };
3553
+ class ZodOptional extends ZodType {
3554
+ _parse(input) {
3555
+ const parsedType = this._getType(input);
3556
+ if (parsedType === ZodParsedType.undefined) {
3557
+ return OK(undefined);
3558
+ }
3559
+ return this._def.innerType._parse(input);
3560
+ }
3561
+ unwrap() {
3562
+ return this._def.innerType;
3563
+ }
3564
+ }
3565
+ ZodOptional.create = (type, params) => {
3566
+ return new ZodOptional({
3567
+ innerType: type,
3568
+ typeName: ZodFirstPartyTypeKind.ZodOptional,
3569
+ ...processCreateParams(params),
3570
+ });
3571
+ };
3572
+ class ZodNullable extends ZodType {
3573
+ _parse(input) {
3574
+ const parsedType = this._getType(input);
3575
+ if (parsedType === ZodParsedType.null) {
3576
+ return OK(null);
3577
+ }
3578
+ return this._def.innerType._parse(input);
3579
+ }
3580
+ unwrap() {
3581
+ return this._def.innerType;
3582
+ }
3583
+ }
3584
+ ZodNullable.create = (type, params) => {
3585
+ return new ZodNullable({
3586
+ innerType: type,
3587
+ typeName: ZodFirstPartyTypeKind.ZodNullable,
3588
+ ...processCreateParams(params),
3589
+ });
3590
+ };
3591
+ class ZodDefault extends ZodType {
3592
+ _parse(input) {
3593
+ const { ctx } = this._processInputParams(input);
3594
+ let data = ctx.data;
3595
+ if (ctx.parsedType === ZodParsedType.undefined) {
3596
+ data = this._def.defaultValue();
3597
+ }
3598
+ return this._def.innerType._parse({
3599
+ data,
3600
+ path: ctx.path,
3601
+ parent: ctx,
3602
+ });
3603
+ }
3604
+ removeDefault() {
3605
+ return this._def.innerType;
3606
+ }
3607
+ }
3608
+ ZodDefault.create = (type, params) => {
3609
+ return new ZodDefault({
3610
+ innerType: type,
3611
+ typeName: ZodFirstPartyTypeKind.ZodDefault,
3612
+ defaultValue: typeof params.default === "function"
3613
+ ? params.default
3614
+ : () => params.default,
3615
+ ...processCreateParams(params),
3616
+ });
3617
+ };
3618
+ class ZodCatch extends ZodType {
3619
+ _parse(input) {
3620
+ const { ctx } = this._processInputParams(input);
3621
+ // newCtx is used to not collect issues from inner types in ctx
3622
+ const newCtx = {
3623
+ ...ctx,
3624
+ common: {
3625
+ ...ctx.common,
3626
+ issues: [],
3627
+ },
3628
+ };
3629
+ const result = this._def.innerType._parse({
3630
+ data: newCtx.data,
3631
+ path: newCtx.path,
3632
+ parent: {
3633
+ ...newCtx,
3634
+ },
3635
+ });
3636
+ if (isAsync(result)) {
3637
+ return result.then((result) => {
3638
+ return {
3639
+ status: "valid",
3640
+ value: result.status === "valid"
3641
+ ? result.value
3642
+ : this._def.catchValue({
3643
+ get error() {
3644
+ return new ZodError(newCtx.common.issues);
3645
+ },
3646
+ input: newCtx.data,
3647
+ }),
3648
+ };
3649
+ });
3650
+ }
3651
+ else {
3652
+ return {
3653
+ status: "valid",
3654
+ value: result.status === "valid"
3655
+ ? result.value
3656
+ : this._def.catchValue({
3657
+ get error() {
3658
+ return new ZodError(newCtx.common.issues);
3659
+ },
3660
+ input: newCtx.data,
3661
+ }),
3662
+ };
3663
+ }
3664
+ }
3665
+ removeCatch() {
3666
+ return this._def.innerType;
3667
+ }
3668
+ }
3669
+ ZodCatch.create = (type, params) => {
3670
+ return new ZodCatch({
3671
+ innerType: type,
3672
+ typeName: ZodFirstPartyTypeKind.ZodCatch,
3673
+ catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
3674
+ ...processCreateParams(params),
3675
+ });
3676
+ };
3677
+ class ZodNaN extends ZodType {
3678
+ _parse(input) {
3679
+ const parsedType = this._getType(input);
3680
+ if (parsedType !== ZodParsedType.nan) {
3681
+ const ctx = this._getOrReturnCtx(input);
3682
+ addIssueToContext(ctx, {
3683
+ code: ZodIssueCode.invalid_type,
3684
+ expected: ZodParsedType.nan,
3685
+ received: ctx.parsedType,
3686
+ });
3687
+ return INVALID;
3688
+ }
3689
+ return { status: "valid", value: input.data };
3690
+ }
3691
+ }
3692
+ ZodNaN.create = (params) => {
3693
+ return new ZodNaN({
3694
+ typeName: ZodFirstPartyTypeKind.ZodNaN,
3695
+ ...processCreateParams(params),
3696
+ });
3697
+ };
3698
+ const BRAND = Symbol("zod_brand");
3699
+ class ZodBranded extends ZodType {
3700
+ _parse(input) {
3701
+ const { ctx } = this._processInputParams(input);
3702
+ const data = ctx.data;
3703
+ return this._def.type._parse({
3704
+ data,
3705
+ path: ctx.path,
3706
+ parent: ctx,
3707
+ });
3708
+ }
3709
+ unwrap() {
3710
+ return this._def.type;
3711
+ }
3712
+ }
3713
+ class ZodPipeline extends ZodType {
3714
+ _parse(input) {
3715
+ const { status, ctx } = this._processInputParams(input);
3716
+ if (ctx.common.async) {
3717
+ const handleAsync = async () => {
3718
+ const inResult = await this._def.in._parseAsync({
3719
+ data: ctx.data,
3720
+ path: ctx.path,
3721
+ parent: ctx,
3722
+ });
3723
+ if (inResult.status === "aborted")
3724
+ return INVALID;
3725
+ if (inResult.status === "dirty") {
3726
+ status.dirty();
3727
+ return DIRTY(inResult.value);
3728
+ }
3729
+ else {
3730
+ return this._def.out._parseAsync({
3731
+ data: inResult.value,
3732
+ path: ctx.path,
3733
+ parent: ctx,
3734
+ });
3735
+ }
3736
+ };
3737
+ return handleAsync();
3738
+ }
3739
+ else {
3740
+ const inResult = this._def.in._parseSync({
3741
+ data: ctx.data,
3742
+ path: ctx.path,
3743
+ parent: ctx,
3744
+ });
3745
+ if (inResult.status === "aborted")
3746
+ return INVALID;
3747
+ if (inResult.status === "dirty") {
3748
+ status.dirty();
3749
+ return {
3750
+ status: "dirty",
3751
+ value: inResult.value,
3752
+ };
3753
+ }
3754
+ else {
3755
+ return this._def.out._parseSync({
3756
+ data: inResult.value,
3757
+ path: ctx.path,
3758
+ parent: ctx,
3759
+ });
3760
+ }
3761
+ }
3762
+ }
3763
+ static create(a, b) {
3764
+ return new ZodPipeline({
3765
+ in: a,
3766
+ out: b,
3767
+ typeName: ZodFirstPartyTypeKind.ZodPipeline,
3768
+ });
3769
+ }
3770
+ }
3771
+ class ZodReadonly extends ZodType {
3772
+ _parse(input) {
3773
+ const result = this._def.innerType._parse(input);
3774
+ if (isValid(result)) {
3775
+ result.value = Object.freeze(result.value);
3776
+ }
3777
+ return result;
3778
+ }
3779
+ }
3780
+ ZodReadonly.create = (type, params) => {
3781
+ return new ZodReadonly({
3782
+ innerType: type,
3783
+ typeName: ZodFirstPartyTypeKind.ZodReadonly,
3784
+ ...processCreateParams(params),
3785
+ });
3786
+ };
3787
+ const custom = (check, params = {},
3788
+ /*
3789
+ * @deprecated
3790
+ *
3791
+ * Pass `fatal` into the params object instead:
3792
+ *
3793
+ * ```ts
3794
+ * z.string().custom((val) => val.length > 5, { fatal: false })
3795
+ * ```
3796
+ *
3797
+ */
3798
+ fatal) => {
3799
+ if (check)
3800
+ return ZodAny.create().superRefine((data, ctx) => {
3801
+ var _a, _b;
3802
+ if (!check(data)) {
3803
+ const p = typeof params === "function"
3804
+ ? params(data)
3805
+ : typeof params === "string"
3806
+ ? { message: params }
3807
+ : params;
3808
+ const _fatal = (_b = (_a = p.fatal) !== null && _a !== void 0 ? _a : fatal) !== null && _b !== void 0 ? _b : true;
3809
+ const p2 = typeof p === "string" ? { message: p } : p;
3810
+ ctx.addIssue({ code: "custom", ...p2, fatal: _fatal });
3811
+ }
3812
+ });
3813
+ return ZodAny.create();
3814
+ };
3815
+ const late = {
3816
+ object: ZodObject.lazycreate,
3817
+ };
3818
+ var ZodFirstPartyTypeKind;
3819
+ (function (ZodFirstPartyTypeKind) {
3820
+ ZodFirstPartyTypeKind["ZodString"] = "ZodString";
3821
+ ZodFirstPartyTypeKind["ZodNumber"] = "ZodNumber";
3822
+ ZodFirstPartyTypeKind["ZodNaN"] = "ZodNaN";
3823
+ ZodFirstPartyTypeKind["ZodBigInt"] = "ZodBigInt";
3824
+ ZodFirstPartyTypeKind["ZodBoolean"] = "ZodBoolean";
3825
+ ZodFirstPartyTypeKind["ZodDate"] = "ZodDate";
3826
+ ZodFirstPartyTypeKind["ZodSymbol"] = "ZodSymbol";
3827
+ ZodFirstPartyTypeKind["ZodUndefined"] = "ZodUndefined";
3828
+ ZodFirstPartyTypeKind["ZodNull"] = "ZodNull";
3829
+ ZodFirstPartyTypeKind["ZodAny"] = "ZodAny";
3830
+ ZodFirstPartyTypeKind["ZodUnknown"] = "ZodUnknown";
3831
+ ZodFirstPartyTypeKind["ZodNever"] = "ZodNever";
3832
+ ZodFirstPartyTypeKind["ZodVoid"] = "ZodVoid";
3833
+ ZodFirstPartyTypeKind["ZodArray"] = "ZodArray";
3834
+ ZodFirstPartyTypeKind["ZodObject"] = "ZodObject";
3835
+ ZodFirstPartyTypeKind["ZodUnion"] = "ZodUnion";
3836
+ ZodFirstPartyTypeKind["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
3837
+ ZodFirstPartyTypeKind["ZodIntersection"] = "ZodIntersection";
3838
+ ZodFirstPartyTypeKind["ZodTuple"] = "ZodTuple";
3839
+ ZodFirstPartyTypeKind["ZodRecord"] = "ZodRecord";
3840
+ ZodFirstPartyTypeKind["ZodMap"] = "ZodMap";
3841
+ ZodFirstPartyTypeKind["ZodSet"] = "ZodSet";
3842
+ ZodFirstPartyTypeKind["ZodFunction"] = "ZodFunction";
3843
+ ZodFirstPartyTypeKind["ZodLazy"] = "ZodLazy";
3844
+ ZodFirstPartyTypeKind["ZodLiteral"] = "ZodLiteral";
3845
+ ZodFirstPartyTypeKind["ZodEnum"] = "ZodEnum";
3846
+ ZodFirstPartyTypeKind["ZodEffects"] = "ZodEffects";
3847
+ ZodFirstPartyTypeKind["ZodNativeEnum"] = "ZodNativeEnum";
3848
+ ZodFirstPartyTypeKind["ZodOptional"] = "ZodOptional";
3849
+ ZodFirstPartyTypeKind["ZodNullable"] = "ZodNullable";
3850
+ ZodFirstPartyTypeKind["ZodDefault"] = "ZodDefault";
3851
+ ZodFirstPartyTypeKind["ZodCatch"] = "ZodCatch";
3852
+ ZodFirstPartyTypeKind["ZodPromise"] = "ZodPromise";
3853
+ ZodFirstPartyTypeKind["ZodBranded"] = "ZodBranded";
3854
+ ZodFirstPartyTypeKind["ZodPipeline"] = "ZodPipeline";
3855
+ ZodFirstPartyTypeKind["ZodReadonly"] = "ZodReadonly";
3856
+ })(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
3857
+ const instanceOfType = (
3858
+ // const instanceOfType = <T extends new (...args: any[]) => any>(
3859
+ cls, params = {
3860
+ message: `Input not instance of ${cls.name}`,
3861
+ }) => custom((data) => data instanceof cls, params);
3862
+ const stringType = ZodString.create;
3863
+ const numberType = ZodNumber.create;
3864
+ const nanType = ZodNaN.create;
3865
+ const bigIntType = ZodBigInt.create;
3866
+ const booleanType = ZodBoolean.create;
3867
+ const dateType = ZodDate.create;
3868
+ const symbolType = ZodSymbol.create;
3869
+ const undefinedType = ZodUndefined.create;
3870
+ const nullType = ZodNull.create;
3871
+ const anyType = ZodAny.create;
3872
+ const unknownType = ZodUnknown.create;
3873
+ const neverType = ZodNever.create;
3874
+ const voidType = ZodVoid.create;
3875
+ const arrayType = ZodArray.create;
3876
+ const objectType = ZodObject.create;
3877
+ const strictObjectType = ZodObject.strictCreate;
3878
+ const unionType = ZodUnion.create;
3879
+ const discriminatedUnionType = ZodDiscriminatedUnion.create;
3880
+ const intersectionType = ZodIntersection.create;
3881
+ const tupleType = ZodTuple.create;
3882
+ const recordType = ZodRecord.create;
3883
+ const mapType = ZodMap.create;
3884
+ const setType = ZodSet.create;
3885
+ const functionType = ZodFunction.create;
3886
+ const lazyType = ZodLazy.create;
3887
+ const literalType = ZodLiteral.create;
3888
+ const enumType = ZodEnum.create;
3889
+ const nativeEnumType = ZodNativeEnum.create;
3890
+ const promiseType = ZodPromise.create;
3891
+ const effectsType = ZodEffects.create;
3892
+ const optionalType = ZodOptional.create;
3893
+ const nullableType = ZodNullable.create;
3894
+ const preprocessType = ZodEffects.createWithPreprocess;
3895
+ const pipelineType = ZodPipeline.create;
3896
+ const ostring = () => stringType().optional();
3897
+ const onumber = () => numberType().optional();
3898
+ const oboolean = () => booleanType().optional();
3899
+ const coerce = {
3900
+ string: ((arg) => ZodString.create({ ...arg, coerce: true })),
3901
+ number: ((arg) => ZodNumber.create({ ...arg, coerce: true })),
3902
+ boolean: ((arg) => ZodBoolean.create({
3903
+ ...arg,
3904
+ coerce: true,
3905
+ })),
3906
+ bigint: ((arg) => ZodBigInt.create({ ...arg, coerce: true })),
3907
+ date: ((arg) => ZodDate.create({ ...arg, coerce: true })),
3908
+ };
3909
+ const NEVER = INVALID;
3910
+
3911
+ var z = /*#__PURE__*/Object.freeze({
3912
+ __proto__: null,
3913
+ defaultErrorMap: errorMap,
3914
+ setErrorMap: setErrorMap,
3915
+ getErrorMap: getErrorMap,
3916
+ makeIssue: makeIssue,
3917
+ EMPTY_PATH: EMPTY_PATH,
3918
+ addIssueToContext: addIssueToContext,
3919
+ ParseStatus: ParseStatus,
3920
+ INVALID: INVALID,
3921
+ DIRTY: DIRTY,
3922
+ OK: OK,
3923
+ isAborted: isAborted,
3924
+ isDirty: isDirty,
3925
+ isValid: isValid,
3926
+ isAsync: isAsync,
3927
+ get util () { return util; },
3928
+ get objectUtil () { return objectUtil; },
3929
+ ZodParsedType: ZodParsedType,
3930
+ getParsedType: getParsedType,
3931
+ ZodType: ZodType,
3932
+ ZodString: ZodString,
3933
+ ZodNumber: ZodNumber,
3934
+ ZodBigInt: ZodBigInt,
3935
+ ZodBoolean: ZodBoolean,
3936
+ ZodDate: ZodDate,
3937
+ ZodSymbol: ZodSymbol,
3938
+ ZodUndefined: ZodUndefined,
3939
+ ZodNull: ZodNull,
3940
+ ZodAny: ZodAny,
3941
+ ZodUnknown: ZodUnknown,
3942
+ ZodNever: ZodNever,
3943
+ ZodVoid: ZodVoid,
3944
+ ZodArray: ZodArray,
3945
+ ZodObject: ZodObject,
3946
+ ZodUnion: ZodUnion,
3947
+ ZodDiscriminatedUnion: ZodDiscriminatedUnion,
3948
+ ZodIntersection: ZodIntersection,
3949
+ ZodTuple: ZodTuple,
3950
+ ZodRecord: ZodRecord,
3951
+ ZodMap: ZodMap,
3952
+ ZodSet: ZodSet,
3953
+ ZodFunction: ZodFunction,
3954
+ ZodLazy: ZodLazy,
3955
+ ZodLiteral: ZodLiteral,
3956
+ ZodEnum: ZodEnum,
3957
+ ZodNativeEnum: ZodNativeEnum,
3958
+ ZodPromise: ZodPromise,
3959
+ ZodEffects: ZodEffects,
3960
+ ZodTransformer: ZodEffects,
3961
+ ZodOptional: ZodOptional,
3962
+ ZodNullable: ZodNullable,
3963
+ ZodDefault: ZodDefault,
3964
+ ZodCatch: ZodCatch,
3965
+ ZodNaN: ZodNaN,
3966
+ BRAND: BRAND,
3967
+ ZodBranded: ZodBranded,
3968
+ ZodPipeline: ZodPipeline,
3969
+ ZodReadonly: ZodReadonly,
3970
+ custom: custom,
3971
+ Schema: ZodType,
3972
+ ZodSchema: ZodType,
3973
+ late: late,
3974
+ get ZodFirstPartyTypeKind () { return ZodFirstPartyTypeKind; },
3975
+ coerce: coerce,
3976
+ any: anyType,
3977
+ array: arrayType,
3978
+ bigint: bigIntType,
3979
+ boolean: booleanType,
3980
+ date: dateType,
3981
+ discriminatedUnion: discriminatedUnionType,
3982
+ effect: effectsType,
3983
+ 'enum': enumType,
3984
+ 'function': functionType,
3985
+ 'instanceof': instanceOfType,
3986
+ intersection: intersectionType,
3987
+ lazy: lazyType,
3988
+ literal: literalType,
3989
+ map: mapType,
3990
+ nan: nanType,
3991
+ nativeEnum: nativeEnumType,
3992
+ never: neverType,
3993
+ 'null': nullType,
3994
+ nullable: nullableType,
3995
+ number: numberType,
3996
+ object: objectType,
3997
+ oboolean: oboolean,
3998
+ onumber: onumber,
3999
+ optional: optionalType,
4000
+ ostring: ostring,
4001
+ pipeline: pipelineType,
4002
+ preprocess: preprocessType,
4003
+ promise: promiseType,
4004
+ record: recordType,
4005
+ set: setType,
4006
+ strictObject: strictObjectType,
4007
+ string: stringType,
4008
+ symbol: symbolType,
4009
+ transformer: effectsType,
4010
+ tuple: tupleType,
4011
+ 'undefined': undefinedType,
4012
+ union: unionType,
4013
+ unknown: unknownType,
4014
+ 'void': voidType,
4015
+ NEVER: NEVER,
4016
+ ZodIssueCode: ZodIssueCode,
4017
+ quotelessJson: quotelessJson,
4018
+ ZodError: ZodError
4019
+ });
4020
+
4021
+ const TimeZones = [
4022
+ ['International Date Line West', 'GMT-11:00', '(GMT-11:00) International Date Line West'],
4023
+ ['Midway Island', 'GMT-11:00', '(GMT-11:00) Midway Island'],
4024
+ ['Samoa', 'GMT-11:00', '(GMT-11:00) Samoa'],
4025
+ ['Hawaii', 'GMT-10:00', '(GMT-10:00) Hawaii'],
4026
+ ['Alaska', 'GMT-09:00', '(GMT-09:00) Alaska'],
4027
+ ['Pacific Time (US & Canada)', 'GMT-08:00', '(GMT-08:00) Pacific Time (US & Canada)'],
4028
+ ['Tijuana', 'GMT-08:00', '(GMT-08:00) Tijuana'],
4029
+ ['Arizona', 'GMT-07:00', '(GMT-07:00) Arizona'],
4030
+ ['Chihuahua', 'GMT-07:00', '(GMT-07:00) Chihuahua'],
4031
+ ['Mazatlan', 'GMT-07:00', '(GMT-07:00) Mazatlan'],
4032
+ ['Mountain Time (US & Canada)', 'GMT-07:00', '(GMT-07:00) Mountain Time (US & Canada)'],
4033
+ ['Central America', 'GMT-06:00', '(GMT-06:00) Central America'],
4034
+ ['Central Time (US & Canada)', 'GMT-06:00', '(GMT-06:00) Central Time (US & Canada)'],
4035
+ ['Guadalajara', 'GMT-06:00', '(GMT-06:00) Guadalajara'],
4036
+ ['Mexico City', 'GMT-06:00', '(GMT-06:00) Mexico City'],
4037
+ ['Monterrey', 'GMT-06:00', '(GMT-06:00) Monterrey'],
4038
+ ['Saskatchewan', 'GMT-06:00', '(GMT-06:00) Saskatchewan'],
4039
+ ['Bogota', 'GMT-05:00', '(GMT-05:00) Bogota'],
4040
+ ['Eastern Time (US & Canada)', 'GMT-05:00', '(GMT-05:00) Eastern Time (US & Canada)'],
4041
+ ['Indiana (East)', 'GMT-05:00', '(GMT-05:00) Indiana (East)'],
4042
+ ['Lima', 'GMT-05:00', '(GMT-05:00) Lima'],
4043
+ ['Quito', 'GMT-05:00', '(GMT-05:00) Quito'],
4044
+ ['Caracas', 'GMT-04:30', '(GMT-04:30) Caracas'],
4045
+ ['Atlantic Time (Canada)', 'GMT-04:00', '(GMT-04:00) Atlantic Time (Canada)'],
4046
+ ['Georgetown', 'GMT-04:00', '(GMT-04:00) Georgetown'],
4047
+ ['La Paz', 'GMT-04:00', '(GMT-04:00) La Paz'],
4048
+ ['Santiago', 'GMT-04:00', '(GMT-04:00) Santiago'],
4049
+ ['Newfoundland', 'GMT-03:30', '(GMT-03:30) Newfoundland'],
4050
+ ['Brasilia', 'GMT-03:00', '(GMT-03:00) Brasilia'],
4051
+ ['Buenos Aires', 'GMT-03:00', '(GMT-03:00) Buenos Aires'],
4052
+ ['Greenland', 'GMT-03:00', '(GMT-03:00) Greenland'],
4053
+ ['Mid-Atlantic', 'GMT-02:00', '(GMT-02:00) Mid-Atlantic'],
4054
+ ['Azores', 'GMT-01:00', '(GMT-01:00) Azores'],
4055
+ ['Cape Verde Is.', 'GMT-01:00', '(GMT-01:00) Cape Verde Is.'],
4056
+ ['Casablanca', 'GMT+00:00', '(GMT+00:00) Casablanca'],
4057
+ ['Dublin', 'GMT+00:00', '(GMT+00:00) Dublin'],
4058
+ ['Edinburgh', 'GMT+00:00', '(GMT+00:00) Edinburgh'],
4059
+ ['Lisbon', 'GMT+00:00', '(GMT+00:00) Lisbon'],
4060
+ ['London', 'GMT+00:00', '(GMT+00:00) London'],
4061
+ ['Monrovia', 'GMT+00:00', '(GMT+00:00) Monrovia'],
4062
+ ['UTC', 'GMT+00:00', '(GMT+00:00) UTC'],
4063
+ ['Amsterdam', 'GMT+01:00', '(GMT+01:00) Amsterdam'],
4064
+ ['Belgrade', 'GMT+01:00', '(GMT+01:00) Belgrade'],
4065
+ ['Berlin', 'GMT+01:00', '(GMT+01:00) Berlin'],
4066
+ ['Bern', 'GMT+01:00', '(GMT+01:00) Bern'],
4067
+ ['Bratislava', 'GMT+01:00', '(GMT+01:00) Bratislava'],
4068
+ ['Brussels', 'GMT+01:00', '(GMT+01:00) Brussels'],
4069
+ ['Budapest', 'GMT+01:00', '(GMT+01:00) Budapest'],
4070
+ ['Copenhagen', 'GMT+01:00', '(GMT+01:00) Copenhagen'],
4071
+ ['Ljubljana', 'GMT+01:00', '(GMT+01:00) Ljubljana'],
4072
+ ['Madrid', 'GMT+01:00', '(GMT+01:00) Madrid'],
4073
+ ['Paris', 'GMT+01:00', '(GMT+01:00) Paris'],
4074
+ ['Prague', 'GMT+01:00', '(GMT+01:00) Prague'],
4075
+ ['Rome', 'GMT+01:00', '(GMT+01:00) Rome'],
4076
+ ['Sarajevo', 'GMT+01:00', '(GMT+01:00) Sarajevo'],
4077
+ ['Skopje', 'GMT+01:00', '(GMT+01:00) Skopje'],
4078
+ ['Stockholm', 'GMT+01:00', '(GMT+01:00) Stockholm'],
4079
+ ['Vienna', 'GMT+01:00', '(GMT+01:00) Vienna'],
4080
+ ['Warsaw', 'GMT+01:00', '(GMT+01:00) Warsaw'],
4081
+ ['West Central Africa', '(GMT+01:00', '(GMT+01:00) West Central Africa'],
4082
+ ['Zagreb', 'GMT+01:00', '(GMT+01:00) Zagreb'],
4083
+ ['Athens', 'GMT+02:00', '(GMT+02:00) Athens'],
4084
+ ['Bucharest', 'GMT+02:00', '(GMT+02:00) Bucharest'],
4085
+ ['Cairo', 'GMT+02:00', '(GMT+02:00) Cairo'],
4086
+ ['Harare', 'GMT+02:00', '(GMT+02:00) Harare'],
4087
+ ['Helsinki', 'GMT+02:00', '(GMT+02:00) Helsinki'],
4088
+ ['Istanbul', 'GMT+02:00', '(GMT+02:00) Istanbul'],
4089
+ ['Jerusalem', 'GMT+02:00', '(GMT+02:00) Jerusalem'],
4090
+ ['Kyiv', 'GMT+02:00', '(GMT+02:00) Kyiv'],
4091
+ ['Minsk', 'GMT+02:00', '(GMT+02:00) Minsk'],
4092
+ ['Pretoria', 'GMT+02:00', '(GMT+02:00) Pretoria'],
4093
+ ['Riga', 'GMT+02:00', '(GMT+02:00) Riga'],
4094
+ ['Sofia', 'GMT+02:00', '(GMT+02:00) Sofia'],
4095
+ ['Tallinn', 'GMT+02:00', '(GMT+02:00) Tallinn'],
4096
+ ['Vilnius', 'GMT+02:00', '(GMT+02:00) Vilnius'],
4097
+ ['Baghdad', 'GMT+03:00', '(GMT+03:00) Baghdad'],
4098
+ ['Kuwait', 'GMT+03:00', '(GMT+03:00) Kuwait'],
4099
+ ['Moscow', 'GMT+03:00', '(GMT+03:00) Moscow'],
4100
+ ['Nairobi', 'GMT+03:00', '(GMT+03:00) Nairobi'],
4101
+ ['Riyadh', 'GMT+03:00', '(GMT+03:00) Riyadh'],
4102
+ ['St. Petersburg', 'GMT+03:00', '(GMT+03:00) St. Petersburg'],
4103
+ ['Volgograd', 'GMT+03:00', '(GMT+03:00) Volgograd'],
4104
+ ['Tehran', 'GMT+03:30', '(GMT+03:30) Tehran'],
4105
+ ['Abu Dhabi', 'GMT+04:00', '(GMT+04:00) Abu Dhabi'],
4106
+ ['Baku', 'GMT+04:00', '(GMT+04:00) Baku'],
4107
+ ['Muscat', 'GMT+04:00', '(GMT+04:00) Muscat'],
4108
+ ['Tbilisi', 'GMT+04:00', '(GMT+04:00) Tbilisi'],
4109
+ ['Yerevan', 'GMT+04:00', '(GMT+04:00) Yerevan'],
4110
+ ['Kabul', 'GMT+04:30', '(GMT+04:30) Kabul'],
4111
+ ['Ekaterinburg', 'GMT+05:00', '(GMT+05:00) Ekaterinburg'],
4112
+ ['Islamabad', 'GMT+05:00', '(GMT+05:00) Islamabad'],
4113
+ ['Karachi', 'GMT+05:00', '(GMT+05:00) Karachi'],
4114
+ ['Tashkent', 'GMT+05:00', '(GMT+05:00) Tashkent'],
4115
+ ['Chennai', 'GMT+05:30', '(GMT+05:30) Chennai'],
4116
+ ['Kolkata', 'GMT+05:30', '(GMT+05:30) Kolkata'],
4117
+ ['Mumbai', 'GMT+05:30', '(GMT+05:30) Mumbai'],
4118
+ ['New Delhi', 'GMT+05:30', '(GMT+05:30) New Delhi'],
4119
+ ['Sri Jayawardenepura', 'GMT+05:30', '(GMT+05:30) Sri Jayawardenepura'],
4120
+ ['Kathmandu', 'GMT+05:45', '(GMT+05:45) Kathmandu'],
4121
+ ['Almaty', 'GMT+06:00', '(GMT+06:00) Almaty'],
4122
+ ['Astana', 'GMT+06:00', '(GMT+06:00) Astana'],
4123
+ ['Dhaka', 'GMT+06:00', '(GMT+06:00) Dhaka'],
4124
+ ['Novosibirsk', 'GMT+06:00', '(GMT+06:00) Novosibirsk'],
4125
+ ['Rangoon', 'GMT+06:30', '(GMT+06:30) Rangoon'],
4126
+ ['Bangkok', 'GMT+07:00', '(GMT+07:00) Bangkok'],
4127
+ ['Hanoi', 'GMT+07:00', '(GMT+07:00) Hanoi'],
4128
+ ['Jakarta', 'GMT+07:00', '(GMT+07:00) Jakarta'],
4129
+ ['Krasnoyarsk', 'GMT+07:00', '(GMT+07:00) Krasnoyarsk'],
4130
+ ['Beijing', 'GMT+08:00', '(GMT+08:00) Beijing'],
4131
+ ['Chongqing', 'GMT+08:00', '(GMT+08:00) Chongqing'],
4132
+ ['Hong Kong', 'GMT+08:00', '(GMT+08:00) Hong Kong'],
4133
+ ['Irkutsk', 'GMT+08:00', '(GMT+08:00) Irkutsk'],
4134
+ ['Kuala Lumpur', 'GMT+08:00', '(GMT+08:00) Kuala Lumpur'],
4135
+ ['Perth', 'GMT+08:00', '(GMT+08:00) Perth'],
4136
+ ['Singapore', 'GMT+08:00', '(GMT+08:00) Singapore'],
4137
+ ['Taipei', 'GMT+08:00', '(GMT+08:00) Taipei'],
4138
+ ['Ulaan Bataar', 'GMT+08:00', '(GMT+08:00) Ulaan Bataar'],
4139
+ ['Urumqi', 'GMT+08:00', '(GMT+08:00) Urumqi'],
4140
+ ['Osaka', 'GMT+09:00', '(GMT+09:00) Osaka'],
4141
+ ['Sapporo', 'GMT+09:00', '(GMT+09:00) Sapporo'],
4142
+ ['Seoul', 'GMT+09:00', '(GMT+09:00) Seoul'],
4143
+ ['Tokyo', 'GMT+09:00', '(GMT+09:00) Tokyo'],
4144
+ ['Yakutsk', 'GMT+09:00', '(GMT+09:00) Yakutsk'],
4145
+ ['Adelaide', 'GMT+09:30', '(GMT+09:30) Adelaide'],
4146
+ ['Darwin', 'GMT+09:30', '(GMT+09:30) Darwin'],
4147
+ ['Brisbane', 'GMT+10:00', '(GMT+10:00) Brisbane'],
4148
+ ['Canberra', 'GMT+10:00', '(GMT+10:00) Canberra'],
4149
+ ['Guam', 'GMT+10:00', '(GMT+10:00) Guam'],
4150
+ ['Hobart', 'GMT+10:00', '(GMT+10:00) Hobart'],
4151
+ ['Melbourne', 'GMT+10:00', '(GMT+10:00) Melbourne'],
4152
+ ['Port Moresby', 'GMT+10:00', '(GMT+10:00) Port Moresby'],
4153
+ ['Sydney', 'GMT+10:00', '(GMT+10:00) Sydney'],
4154
+ ['Vladivostok', 'GMT+10:00', '(GMT+10:00) Vladivostok'],
4155
+ ['Kamchatka', 'GMT+11:00', '(GMT+11:00) Kamchatka'],
4156
+ ['Magadan', 'GMT+11:00', '(GMT+11:00) Magadan'],
4157
+ ['New Caledonia', 'GMT+11:00', '(GMT+11:00) New Caledonia'],
4158
+ ['Solomon Is.', 'GMT+11:00', '(GMT+11:00) Solomon Is.'],
4159
+ ['Auckland', 'GMT+12:00', '(GMT+12:00) Auckland'],
4160
+ ['Fiji', 'GMT+12:00', '(GMT+12:00) Fiji'],
4161
+ ['Marshall Is.', 'GMT+12:00', '(GMT+12:00) Marshall Is.'],
4162
+ ['Wellington', 'GMT+12:00', '(GMT+12:00) Wellington'],
4163
+ ["Nuku'alofa", 'GMT+13:00', "(GMT+13:00) Nuku'alofa"],
4164
+ ];
4165
+
4166
+ const verdocsSettingsOrganizationCss = "verdocs-settings-organization{display:-ms-flexbox;display:flex;padding:10px;font-size:18px;-ms-flex-wrap:nowrap;flex-wrap:nowrap;border-radius:6px;color:#33364b;-ms-flex-direction:column;flex-direction:column;font-family:\"Inter\", \"Barlow\", sans-serif}verdocs-settings-organization .columns{gap:20px;display:-ms-flexbox;display:flex;-ms-flex-wrap:wrap;flex-wrap:wrap;-ms-flex-direction:row;flex-direction:row}verdocs-settings-organization .column{-ms-flex:1;flex:1;display:-ms-flexbox;display:flex;-ms-flex-direction:column;flex-direction:column}verdocs-settings-organization verdocs-text-input{margin:10px 0}verdocs-settings-organization verdocs-text-input input{height:32px}@media screen and (max-width: 600px){verdocs-settings-organization .columns{gap:0;-ms-flex-direction:column;flex-direction:column}}";
4167
+
4168
+ const timeZoneOptions = TimeZones.map(tz => ({ value: tz[2], label: tz[2] }));
4169
+ const schema$1 = z.object({
4170
+ name: z.string().trim().min(1, 'Name is required').max(30),
4171
+ business_name: z.string().trim().max(30).optional(),
4172
+ contact_email: z.string().trim().email('Invalid email').optional().or(z.literal('')),
4173
+ phone: z.preprocess(val => utils.convertToE164(String(val).trim()), z.string().optional()),
4174
+ address: z.string().trim().max(30).optional(),
4175
+ address2: z.string().trim().max(30).optional(),
4176
+ timezone: z.string().trim().optional(),
4177
+ url: z.string().trim().optional(),
4178
+ });
4179
+ const VerdocsSettingsOrganization = class {
4180
+ constructor(hostRef) {
4181
+ index.registerInstance(this, hostRef);
4182
+ this.sdkError = index.createEvent(this, "sdkError", 7);
4183
+ this.organizationUpdated = index.createEvent(this, "organizationUpdated", 7);
4184
+ this.endpoint = VerdocsEndpoint.VerdocsEndpoint.getDefault();
4185
+ this.valid = false;
4186
+ this.dirty = false;
4187
+ this.submitting = false;
4188
+ this.name = '';
4189
+ this.business_name = '';
4190
+ this.contact_email = '';
4191
+ this.phone = '';
4192
+ this.address = '';
4193
+ this.address2 = '';
4194
+ this.timezone = '';
4195
+ this.url = '';
4196
+ }
4197
+ componentWillLoad() {
4198
+ this.endpoint.loadSession();
4199
+ if (!this.endpoint.session) {
4200
+ console.log('[SETTINGS] Must be authenticated');
4201
+ return;
4202
+ }
4203
+ }
4204
+ async componentDidLoad() {
4205
+ const organization = await Profiles.getOrganization(this.endpoint, this.endpoint.session.organization_id);
4206
+ console.log('[SETTINGS] Loaded organization', organization);
4207
+ this.resetForm(organization);
4208
+ }
4209
+ resetForm(organization) {
4210
+ this.name = organization.name;
4211
+ this.business_name = organization.business_name;
4212
+ this.contact_email = organization.contact_email;
4213
+ this.phone = organization.phone;
4214
+ this.address = organization.address;
4215
+ this.address2 = organization.address2;
4216
+ this.timezone = organization.timezone;
4217
+ this.url = organization.url;
4218
+ this.dirty = false;
4219
+ this.valid = true;
4220
+ }
4221
+ handleSubmit(e) {
4222
+ e.preventDefault();
4223
+ e.stopPropagation();
4224
+ Profiles.updateOrganization(VerdocsEndpoint.VerdocsEndpoint.getDefault(), this.endpoint.session.organization_id, {
4225
+ name: this.name,
4226
+ business_name: this.business_name,
4227
+ contact_email: this.contact_email,
4228
+ phone: this.phone,
4229
+ address: this.address,
4230
+ address2: this.address2,
4231
+ timezone: this.timezone,
4232
+ url: this.url,
4233
+ })
4234
+ .then(newOrganization => {
4235
+ var _a;
4236
+ console.log('[SETTINGS] Update result', newOrganization);
4237
+ (_a = this.organizationUpdated) === null || _a === void 0 ? void 0 : _a.emit({ endpoint: this.endpoint, organization: newOrganization });
4238
+ this.resetForm(newOrganization);
4239
+ })
4240
+ .catch(e => Toast.VerdocsToast(`Error updating organization: ${e.message}`, { style: 'error' }));
4241
+ }
4242
+ processFields() {
4243
+ const validation = schema$1.safeParse({
4244
+ name: this.name,
4245
+ business_name: this.business_name,
4246
+ contact_email: this.contact_email,
4247
+ phone: this.phone,
4248
+ address: this.address,
4249
+ address2: this.address2,
4250
+ timezone: this.timezone,
4251
+ url: this.url,
4252
+ });
4253
+ console.log('[SETTINGS] Validation result', validation);
4254
+ this.valid = validation.success;
4255
+ this.dirty = true;
4256
+ }
4257
+ render() {
4258
+ if (!this.endpoint.session) {
4259
+ console.log('[SETTINGS] Must be authenticated');
4260
+ return index.h(index.Host, { class: "authentication-required" }, "Must be authenticated");
4261
+ }
4262
+ return (index.h(index.Host, null, index.h("h1", null, "Organization Profile"), index.h("form", { onSubmit: e => this.handleSubmit(e) }, index.h("div", { class: "columns" }, index.h("div", { class: "column" }, index.h("verdocs-text-input", { id: "verdocs-organization-name", value: this.name, autocomplete: "off", label: "Name", required: true, placeholder: "Enter your organization's name...", onInput: (e) => (this.name = e.target.value), onFocusout: (e) => {
4263
+ this.name = e.target.value.trim();
4264
+ this.processFields();
4265
+ } }), index.h("verdocs-text-input", { id: "verdocs-organization-business-name", value: this.business_name, autocomplete: "off", label: "d/b/a", placeholder: "Enter your d/b/a, if any...", onInput: (e) => (this.business_name = e.target.value), onFocusout: (e) => {
4266
+ this.business_name = e.target.value.trim();
4267
+ this.processFields();
4268
+ } }), index.h("verdocs-text-input", { id: "verdocs-organization-url", value: this.url, autocomplete: "off", label: "Web URL", placeholder: "Enter your Web URL...", onInput: (e) => (this.url = e.target.value), onFocusout: (e) => {
4269
+ this.url = e.target.value.trim();
4270
+ this.processFields();
4271
+ } }), index.h("verdocs-text-input", { id: "verdocs-organization-phone", value: this.phone, autocomplete: "off", label: "Phone Number", placeholder: "Enter your phone number...", onInput: (e) => (this.phone = e.target.value), onFocusout: (e) => {
4272
+ this.phone = e.target.value.trim();
4273
+ this.processFields();
4274
+ } })), index.h("div", { class: "column" }, index.h("verdocs-text-input", { id: "verdocs-organization-address", value: this.address, autocomplete: "off", label: "Address", required: true, placeholder: "Enter your address...", onInput: (e) => (this.address = e.target.value), onFocusout: (e) => {
4275
+ this.address = e.target.value.trim();
4276
+ this.processFields();
4277
+ } }), index.h("verdocs-text-input", { id: "verdocs-organization-address", value: this.address2, autocomplete: "off", label: "Address 2", required: true, placeholder: "Address line 2...", onInput: (e) => (this.address2 = e.target.value), onFocusout: (e) => {
4278
+ this.address2 = e.target.value.trim();
4279
+ this.processFields();
4280
+ } }), index.h("verdocs-text-input", { id: "verdocs-organization-address2", value: this.address2, clearable: true, autocomplete: "off", label: "Address 2", placeholder: "Enter your address...", onInput: (e) => (this.address2 = e.target.value), onFocusout: (e) => {
4281
+ this.address2 = e.target.value.trim();
4282
+ this.processFields();
4283
+ } }), index.h("verdocs-text-input", { id: "verdocs-organization-email", value: this.contact_email, clearable: true, autocomplete: "off", label: "Contact Email", placeholder: "Enter your contact email address...", onInput: (e) => (this.contact_email = e.target.value), onFocusout: (e) => {
4284
+ this.contact_email = e.target.value.trim();
4285
+ this.processFields();
4286
+ } }), index.h("verdocs-select-input", { options: timeZoneOptions, value: this.timezone, label: "Time Zone" }))), index.h("verdocs-button", { type: "submit", label: "Save", size: "normal", disabled: this.submitting || !this.dirty }))));
4287
+ }
4288
+ };
4289
+ VerdocsSettingsOrganization.style = verdocsSettingsOrganizationCss;
4290
+
4291
+ const verdocsSettingsProfileCss = "verdocs-settings-profile{display:-ms-flexbox;display:flex;padding:10px;font-size:18px;-ms-flex-wrap:nowrap;flex-wrap:nowrap;border-radius:6px;color:#33364b;-ms-flex-direction:column;flex-direction:column;font-family:\"Inter\", \"Barlow\", sans-serif}verdocs-settings-profile .columns{gap:20px;display:-ms-flexbox;display:flex;-ms-flex-wrap:wrap;flex-wrap:wrap;-ms-flex-direction:row;flex-direction:row}verdocs-settings-profile .column{-ms-flex:1;flex:1;display:-ms-flexbox;display:flex;-ms-flex-direction:column;flex-direction:column}verdocs-settings-profile verdocs-text-input{margin:10px 0}verdocs-settings-profile verdocs-text-input input{height:32px}@media screen and (max-width: 600px){verdocs-settings-profile .columns{gap:0;-ms-flex-direction:column;flex-direction:column}}";
4292
+
4293
+ const schema = z.object({
4294
+ first_name: z.string().trim().min(1, 'First name is required').max(30),
4295
+ last_name: z.string().trim().min(1, 'Last name is required').max(30),
4296
+ email: z.string().trim().email('Invalid email').min(1, 'Email is required'),
4297
+ phone: z.preprocess(val => utils.convertToE164(String(val).trim()), z.string()),
4298
+ });
4299
+ const VerdocsSettingsProfile = class {
4300
+ constructor(hostRef) {
4301
+ index.registerInstance(this, hostRef);
4302
+ this.sdkError = index.createEvent(this, "sdkError", 7);
4303
+ this.profileUpdated = index.createEvent(this, "profileUpdated", 7);
4304
+ this.endpoint = VerdocsEndpoint.VerdocsEndpoint.getDefault();
4305
+ this.valid = false;
4306
+ this.dirty = false;
4307
+ this.submitting = false;
4308
+ this.first_name = '';
4309
+ this.last_name = '';
4310
+ this.email = '';
4311
+ this.phone = '';
4312
+ }
4313
+ componentWillLoad() {
4314
+ this.endpoint.loadSession();
4315
+ if (!this.endpoint.session) {
4316
+ console.log('[SETTINGS] Must be authenticated');
4317
+ return;
4318
+ }
4319
+ }
4320
+ async componentDidLoad() {
4321
+ const profile = await Profiles.getCurrentProfile(this.endpoint);
4322
+ console.log('[SETTINGS] Loaded profile', profile);
4323
+ this.resetForm(profile);
4324
+ }
4325
+ resetForm(profile) {
4326
+ this.first_name = profile.first_name;
4327
+ this.last_name = profile.last_name;
4328
+ this.email = profile.email;
4329
+ this.phone = profile.phone;
4330
+ this.dirty = false;
4331
+ this.valid = true;
4332
+ }
4333
+ handleSubmit(e) {
4334
+ e.preventDefault();
4335
+ e.stopPropagation();
4336
+ Profiles.updateProfile(VerdocsEndpoint.VerdocsEndpoint.getDefault(), this.endpoint.session.profile_id, {
4337
+ first_name: this.first_name,
4338
+ last_name: this.last_name,
4339
+ phone: this.phone,
4340
+ })
4341
+ .then(newProfile => {
4342
+ var _a;
4343
+ console.log('[SETTINGS] Update result', newProfile);
4344
+ (_a = this.profileUpdated) === null || _a === void 0 ? void 0 : _a.emit({ endpoint: this.endpoint, profile: newProfile });
4345
+ this.resetForm(newProfile);
4346
+ })
4347
+ .catch(e => Toast.VerdocsToast(`Error updating profile: ${e.message}`, { style: 'error' }));
4348
+ }
4349
+ processFields() {
4350
+ const validation = schema.safeParse({
4351
+ first_name: this.first_name,
4352
+ last_name: this.last_name,
4353
+ email: this.email,
4354
+ phone: this.phone,
4355
+ });
4356
+ console.log('[SETTINGS] Validation result', validation);
4357
+ this.valid = validation.success;
4358
+ this.dirty = true;
4359
+ }
4360
+ render() {
4361
+ if (!this.endpoint.session) {
4362
+ console.log('[SETTINGS] Must be authenticated');
4363
+ return index.h(index.Host, { class: "authentication-required" }, "Must be authenticated");
4364
+ }
4365
+ return (index.h(index.Host, null, index.h("h1", null, "My Profile"), index.h("form", { onSubmit: e => this.handleSubmit(e) }, index.h("div", { class: "columns" }, index.h("div", { class: "column" }, index.h("verdocs-text-input", { id: "verdocs-profile-first-name", value: this.first_name, autocomplete: "off", label: "First Name", required: true, placeholder: "Enter your first name...", onInput: (e) => (this.first_name = e.target.value), onFocusout: (e) => {
4366
+ this.first_name = e.target.value.trim();
4367
+ this.processFields();
4368
+ } }), index.h("verdocs-text-input", { id: "verdocs-profile-last-name", value: this.last_name, autocomplete: "off", label: "Last Name", required: true, placeholder: "Enter your last name...", onInput: (e) => (this.last_name = e.target.value), onFocusout: (e) => {
4369
+ this.last_name = e.target.value.trim();
4370
+ this.processFields();
4371
+ } })), index.h("div", { class: "column" }, index.h("verdocs-text-input", { id: "verdocs-profile-email", value: this.email, autocomplete: "off", label: "Email Address", required: true, disabled: true, placeholder: "Enter your email address...", onInput: (e) => (this.email = e.target.value), onFocusout: (e) => {
4372
+ this.email = e.target.value.trim();
4373
+ this.processFields();
4374
+ } }), index.h("verdocs-text-input", { id: "verdocs-profile-phone", value: this.phone, clearable: true, autocomplete: "off", label: "Phone Number", placeholder: "Enter your phone number...", onInput: (e) => (this.phone = e.target.value), onFocusout: (e) => {
4375
+ this.phone = e.target.value.trim();
4376
+ this.processFields();
4377
+ } }))), index.h("verdocs-button", { type: "submit", label: "Save", size: "normal", disabled: this.submitting || !this.dirty }))));
4378
+ }
4379
+ };
4380
+ VerdocsSettingsProfile.style = verdocsSettingsProfileCss;
4381
+
4382
+ exports.verdocs_settings_organization = VerdocsSettingsOrganization;
4383
+ exports.verdocs_settings_profile = VerdocsSettingsProfile;