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