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