@oumla/sdk 0.0.1

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