@learncard/simple-signing-plugin 1.0.3

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