@getquick/content 0.4.2 → 0.5.1

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