@oumla/sdk 0.0.4 → 1.0.0

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