@learncard/helpers 1.0.3 → 1.0.4

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