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