@learncard/didkey-plugin 1.0.0

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