@remotion/studio 4.0.259 → 4.0.260

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