mdat-plugin-tldraw 1.0.0

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