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