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