@design-edito/tools 0.1.55 → 0.1.56

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