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