@greenarmor/ges-mcp-server 0.3.5 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bundle/server.js CHANGED
@@ -1,4 +1,9 @@
1
1
  #!/usr/bin/env node
2
+ var __defProp = Object.defineProperty;
3
+ var __export = (target, all) => {
4
+ for (var name in all)
5
+ __defProp(target, name, { get: all[name], enumerable: true });
6
+ };
2
7
 
3
8
  // src/server.ts
4
9
  import * as readline from "node:readline";
@@ -1044,60 +1049,4352 @@ function getPacksForProjectType(projectType) {
1044
1049
  }
1045
1050
 
1046
1051
  // ../scoring-engine/dist/index.js
1052
+ var SEVERITY_WEIGHTS = {
1053
+ critical: 10,
1054
+ high: 7,
1055
+ medium: 4,
1056
+ low: 1
1057
+ };
1058
+ var STATUS_CREDIT = {
1059
+ pass: 1,
1060
+ warning: 0.5,
1061
+ fail: 0,
1062
+ "not-implemented": 0,
1063
+ "not-applicable": 1
1064
+ };
1065
+ var SEVERITY_PENALTY = {
1066
+ critical: 12,
1067
+ high: 7,
1068
+ medium: 4,
1069
+ low: 1
1070
+ };
1071
+ function computeGrade(score) {
1072
+ if (score >= 90)
1073
+ return "A";
1074
+ if (score >= 80)
1075
+ return "B";
1076
+ if (score >= 65)
1077
+ return "C";
1078
+ if (score >= 50)
1079
+ return "D";
1080
+ return "F";
1081
+ }
1082
+ function emptySeverityBucket() {
1083
+ return { total: 0, passed: 0, failed: 0, warning: 0, not_implemented: 0 };
1084
+ }
1085
+ function buildSeverityBreakdown(controls) {
1086
+ const breakdown = {
1087
+ critical: emptySeverityBucket(),
1088
+ high: emptySeverityBucket(),
1089
+ medium: emptySeverityBucket(),
1090
+ low: emptySeverityBucket()
1091
+ };
1092
+ for (const c of controls) {
1093
+ const bucket = breakdown[c.severity];
1094
+ bucket.total++;
1095
+ if (c.status === "pass" || c.status === "not-applicable") {
1096
+ bucket.passed++;
1097
+ } else if (c.status === "warning") {
1098
+ bucket.warning++;
1099
+ } else if (c.status === "fail") {
1100
+ bucket.failed++;
1101
+ } else {
1102
+ bucket.not_implemented++;
1103
+ }
1104
+ }
1105
+ return breakdown;
1106
+ }
1107
+ function computeWeightedScore(controls) {
1108
+ if (controls.length === 0)
1109
+ return { score: 0, maxPossible: 0 };
1110
+ let earned = 0;
1111
+ let maxPossible = 0;
1112
+ for (const c of controls) {
1113
+ const weight = SEVERITY_WEIGHTS[c.severity];
1114
+ const credit = STATUS_CREDIT[c.status] ?? 0;
1115
+ earned += weight * credit;
1116
+ maxPossible += weight;
1117
+ }
1118
+ const score = maxPossible > 0 ? Math.round(earned / maxPossible * 100) : 0;
1119
+ return { score, maxPossible };
1120
+ }
1121
+ function countCriticalFailures(controls) {
1122
+ return controls.filter((c) => c.severity === "critical" && (c.status === "fail" || c.status === "not-implemented")).length;
1123
+ }
1047
1124
  function scoreByFramework(controls, frameworks) {
1048
1125
  const result = {};
1049
1126
  for (const fw of frameworks) {
1050
1127
  const fwControls = controls.filter((c) => c.framework === fw);
1051
- const total = fwControls.length;
1052
- const passed = fwControls.filter((c) => c.status === "pass").length;
1128
+ const { score, maxPossible } = computeWeightedScore(fwControls);
1129
+ const breakdown = buildSeverityBreakdown(fwControls);
1130
+ const passed = fwControls.filter((c) => c.status === "pass" || c.status === "not-applicable").length;
1053
1131
  const failed = fwControls.filter((c) => c.status === "fail").length;
1054
1132
  const warning = fwControls.filter((c) => c.status === "warning").length;
1055
1133
  const notApplicable = fwControls.filter((c) => c.status === "not-applicable").length;
1056
- const score = total > 0 ? Math.round((passed + notApplicable) / total * 100) : 0;
1134
+ const notImplemented = fwControls.filter((c) => c.status === "not-implemented").length;
1135
+ const criticalFailures = countCriticalFailures(fwControls);
1136
+ let adjustedScore = score;
1137
+ if (criticalFailures > 0 && adjustedScore > 0) {
1138
+ const cap = Math.max(0, 75 - criticalFailures * 8);
1139
+ adjustedScore = Math.min(adjustedScore, cap);
1140
+ }
1057
1141
  result[fw] = {
1058
1142
  framework: fw,
1059
- score,
1060
- total_controls: total,
1143
+ score: adjustedScore,
1144
+ grade: computeGrade(adjustedScore),
1145
+ total_controls: fwControls.length,
1061
1146
  passed_controls: passed,
1062
1147
  failed_controls: failed,
1063
1148
  warning_controls: warning,
1064
1149
  not_applicable: notApplicable,
1150
+ not_implemented: notImplemented,
1151
+ severity_breakdown: breakdown,
1152
+ critical_failures: criticalFailures,
1153
+ max_possible_score: maxPossible,
1065
1154
  evaluated_at: (/* @__PURE__ */ new Date()).toISOString()
1066
1155
  };
1067
1156
  }
1068
1157
  return result;
1069
1158
  }
1159
+ function computeAuditImpact(findings) {
1160
+ const critical = findings.filter((f) => f.severity === "critical").length;
1161
+ const high = findings.filter((f) => f.severity === "high").length;
1162
+ const medium = findings.filter((f) => f.severity === "medium").length;
1163
+ const low = findings.filter((f) => f.severity === "low").length;
1164
+ const totalDeduction = Math.min(100, critical * SEVERITY_PENALTY.critical + high * SEVERITY_PENALTY.high + medium * SEVERITY_PENALTY.medium + low * SEVERITY_PENALTY.low);
1165
+ return {
1166
+ total_deduction: totalDeduction,
1167
+ critical_findings: critical,
1168
+ high_findings: high,
1169
+ medium_findings: medium,
1170
+ low_findings: low
1171
+ };
1172
+ }
1070
1173
  function computeOverallScore(frameworkScores) {
1071
1174
  const scores = Object.values(frameworkScores);
1072
1175
  if (scores.length === 0)
1073
1176
  return 0;
1074
- const total = scores.reduce((sum, s) => sum + s.score, 0);
1075
- return Math.round(total / scores.length);
1177
+ let totalWeight = 0;
1178
+ let weightedSum = 0;
1179
+ for (const s of scores) {
1180
+ const weight = Math.max(1, s.total_controls);
1181
+ weightedSum += s.score * weight;
1182
+ totalWeight += weight;
1183
+ }
1184
+ return totalWeight > 0 ? Math.round(weightedSum / totalWeight) : 0;
1076
1185
  }
1077
- function generateScoreFile(controls, frameworks) {
1186
+ function generateScoreFile(controls, frameworks, findings) {
1078
1187
  const frameworkScores = scoreByFramework(controls, frameworks);
1079
- const overall = computeOverallScore(frameworkScores);
1188
+ let overall = computeOverallScore(frameworkScores);
1189
+ let auditImpact;
1190
+ if (findings && findings.length > 0) {
1191
+ auditImpact = computeAuditImpact(findings);
1192
+ overall = Math.max(0, overall - auditImpact.total_deduction);
1193
+ }
1080
1194
  return {
1081
1195
  overall,
1196
+ overall_grade: computeGrade(overall),
1082
1197
  frameworks: frameworkScores,
1198
+ audit_impact: auditImpact,
1083
1199
  evaluated_at: (/* @__PURE__ */ new Date()).toISOString()
1084
1200
  };
1085
1201
  }
1086
1202
  function formatScoreOutput(score) {
1087
1203
  const lines = [];
1088
1204
  lines.push("");
1205
+ lines.push(" \u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557");
1206
+ lines.push(" \u2551 COMPLIANCE SCORE REPORT \u2551");
1207
+ lines.push(" \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D");
1208
+ lines.push("");
1089
1209
  for (const [fw, data] of Object.entries(score.frameworks)) {
1090
1210
  const padding = Math.max(1, 20 - fw.length);
1091
1211
  const dots = ".".repeat(padding);
1092
- lines.push(` ${fw} ${dots} ${data.score}%`);
1212
+ const gradeTag = `[${data.grade}]`;
1213
+ lines.push(` ${fw} ${dots} ${String(data.score).padStart(3)}% ${gradeTag}`);
1214
+ if (data.critical_failures > 0) {
1215
+ lines.push(` \u26A0 ${data.critical_failures} critical control(s) failed`);
1216
+ }
1217
+ const sb = data.severity_breakdown;
1218
+ const parts = [];
1219
+ if (sb.critical.total > 0)
1220
+ parts.push(`${sb.critical.passed}/${sb.critical.total} critical`);
1221
+ if (sb.high.total > 0)
1222
+ parts.push(`${sb.high.passed}/${sb.high.total} high`);
1223
+ if (sb.medium.total > 0)
1224
+ parts.push(`${sb.medium.passed}/${sb.medium.total} medium`);
1225
+ if (sb.low.total > 0)
1226
+ parts.push(`${sb.low.passed}/${sb.low.total} low`);
1227
+ if (parts.length > 0)
1228
+ lines.push(` ${parts.join(" \xB7 ")}`);
1093
1229
  }
1230
+ lines.push(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
1094
1231
  const overallPadding = Math.max(1, 20 - "Overall".length);
1095
1232
  const overallDots = ".".repeat(overallPadding);
1096
- lines.push(` Overall ${overallDots} ${score.overall}%`);
1233
+ lines.push(` Overall ${overallDots} ${String(score.overall).padStart(3)}% [${score.overall_grade}]`);
1234
+ if (score.audit_impact) {
1235
+ const ai = score.audit_impact;
1236
+ lines.push("");
1237
+ lines.push(" Audit Findings Impact:");
1238
+ lines.push(` Critical: ${ai.critical_findings} \xB7 High: ${ai.high_findings} \xB7 Medium: ${ai.medium_findings} \xB7 Low: ${ai.low_findings}`);
1239
+ lines.push(` Score deduction: -${ai.total_deduction}%`);
1240
+ }
1097
1241
  lines.push("");
1098
1242
  return lines.join("\n");
1099
1243
  }
1100
1244
 
1245
+ // ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/external.js
1246
+ var external_exports = {};
1247
+ __export(external_exports, {
1248
+ BRAND: () => BRAND,
1249
+ DIRTY: () => DIRTY,
1250
+ EMPTY_PATH: () => EMPTY_PATH,
1251
+ INVALID: () => INVALID,
1252
+ NEVER: () => NEVER,
1253
+ OK: () => OK,
1254
+ ParseStatus: () => ParseStatus,
1255
+ Schema: () => ZodType,
1256
+ ZodAny: () => ZodAny,
1257
+ ZodArray: () => ZodArray,
1258
+ ZodBigInt: () => ZodBigInt,
1259
+ ZodBoolean: () => ZodBoolean,
1260
+ ZodBranded: () => ZodBranded,
1261
+ ZodCatch: () => ZodCatch,
1262
+ ZodDate: () => ZodDate,
1263
+ ZodDefault: () => ZodDefault,
1264
+ ZodDiscriminatedUnion: () => ZodDiscriminatedUnion,
1265
+ ZodEffects: () => ZodEffects,
1266
+ ZodEnum: () => ZodEnum,
1267
+ ZodError: () => ZodError,
1268
+ ZodFirstPartyTypeKind: () => ZodFirstPartyTypeKind,
1269
+ ZodFunction: () => ZodFunction,
1270
+ ZodIntersection: () => ZodIntersection,
1271
+ ZodIssueCode: () => ZodIssueCode,
1272
+ ZodLazy: () => ZodLazy,
1273
+ ZodLiteral: () => ZodLiteral,
1274
+ ZodMap: () => ZodMap,
1275
+ ZodNaN: () => ZodNaN,
1276
+ ZodNativeEnum: () => ZodNativeEnum,
1277
+ ZodNever: () => ZodNever,
1278
+ ZodNull: () => ZodNull,
1279
+ ZodNullable: () => ZodNullable,
1280
+ ZodNumber: () => ZodNumber,
1281
+ ZodObject: () => ZodObject,
1282
+ ZodOptional: () => ZodOptional,
1283
+ ZodParsedType: () => ZodParsedType,
1284
+ ZodPipeline: () => ZodPipeline,
1285
+ ZodPromise: () => ZodPromise,
1286
+ ZodReadonly: () => ZodReadonly,
1287
+ ZodRecord: () => ZodRecord,
1288
+ ZodSchema: () => ZodType,
1289
+ ZodSet: () => ZodSet,
1290
+ ZodString: () => ZodString,
1291
+ ZodSymbol: () => ZodSymbol,
1292
+ ZodTransformer: () => ZodEffects,
1293
+ ZodTuple: () => ZodTuple,
1294
+ ZodType: () => ZodType,
1295
+ ZodUndefined: () => ZodUndefined,
1296
+ ZodUnion: () => ZodUnion,
1297
+ ZodUnknown: () => ZodUnknown,
1298
+ ZodVoid: () => ZodVoid,
1299
+ addIssueToContext: () => addIssueToContext,
1300
+ any: () => anyType,
1301
+ array: () => arrayType,
1302
+ bigint: () => bigIntType,
1303
+ boolean: () => booleanType,
1304
+ coerce: () => coerce,
1305
+ custom: () => custom,
1306
+ date: () => dateType,
1307
+ datetimeRegex: () => datetimeRegex,
1308
+ defaultErrorMap: () => en_default,
1309
+ discriminatedUnion: () => discriminatedUnionType,
1310
+ effect: () => effectsType,
1311
+ enum: () => enumType,
1312
+ function: () => functionType,
1313
+ getErrorMap: () => getErrorMap,
1314
+ getParsedType: () => getParsedType,
1315
+ instanceof: () => instanceOfType,
1316
+ intersection: () => intersectionType,
1317
+ isAborted: () => isAborted,
1318
+ isAsync: () => isAsync,
1319
+ isDirty: () => isDirty,
1320
+ isValid: () => isValid,
1321
+ late: () => late,
1322
+ lazy: () => lazyType,
1323
+ literal: () => literalType,
1324
+ makeIssue: () => makeIssue,
1325
+ map: () => mapType,
1326
+ nan: () => nanType,
1327
+ nativeEnum: () => nativeEnumType,
1328
+ never: () => neverType,
1329
+ null: () => nullType,
1330
+ nullable: () => nullableType,
1331
+ number: () => numberType,
1332
+ object: () => objectType,
1333
+ objectUtil: () => objectUtil,
1334
+ oboolean: () => oboolean,
1335
+ onumber: () => onumber,
1336
+ optional: () => optionalType,
1337
+ ostring: () => ostring,
1338
+ pipeline: () => pipelineType,
1339
+ preprocess: () => preprocessType,
1340
+ promise: () => promiseType,
1341
+ quotelessJson: () => quotelessJson,
1342
+ record: () => recordType,
1343
+ set: () => setType,
1344
+ setErrorMap: () => setErrorMap,
1345
+ strictObject: () => strictObjectType,
1346
+ string: () => stringType,
1347
+ symbol: () => symbolType,
1348
+ transformer: () => effectsType,
1349
+ tuple: () => tupleType,
1350
+ undefined: () => undefinedType,
1351
+ union: () => unionType,
1352
+ unknown: () => unknownType,
1353
+ util: () => util,
1354
+ void: () => voidType
1355
+ });
1356
+
1357
+ // ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/util.js
1358
+ var util;
1359
+ (function(util2) {
1360
+ util2.assertEqual = (_) => {
1361
+ };
1362
+ function assertIs(_arg) {
1363
+ }
1364
+ util2.assertIs = assertIs;
1365
+ function assertNever(_x) {
1366
+ throw new Error();
1367
+ }
1368
+ util2.assertNever = assertNever;
1369
+ util2.arrayToEnum = (items) => {
1370
+ const obj = {};
1371
+ for (const item of items) {
1372
+ obj[item] = item;
1373
+ }
1374
+ return obj;
1375
+ };
1376
+ util2.getValidEnumValues = (obj) => {
1377
+ const validKeys = util2.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
1378
+ const filtered = {};
1379
+ for (const k of validKeys) {
1380
+ filtered[k] = obj[k];
1381
+ }
1382
+ return util2.objectValues(filtered);
1383
+ };
1384
+ util2.objectValues = (obj) => {
1385
+ return util2.objectKeys(obj).map(function(e) {
1386
+ return obj[e];
1387
+ });
1388
+ };
1389
+ util2.objectKeys = typeof Object.keys === "function" ? (obj) => Object.keys(obj) : (object) => {
1390
+ const keys = [];
1391
+ for (const key in object) {
1392
+ if (Object.prototype.hasOwnProperty.call(object, key)) {
1393
+ keys.push(key);
1394
+ }
1395
+ }
1396
+ return keys;
1397
+ };
1398
+ util2.find = (arr, checker) => {
1399
+ for (const item of arr) {
1400
+ if (checker(item))
1401
+ return item;
1402
+ }
1403
+ return void 0;
1404
+ };
1405
+ util2.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && Number.isFinite(val) && Math.floor(val) === val;
1406
+ function joinValues(array, separator = " | ") {
1407
+ return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
1408
+ }
1409
+ util2.joinValues = joinValues;
1410
+ util2.jsonStringifyReplacer = (_, value) => {
1411
+ if (typeof value === "bigint") {
1412
+ return value.toString();
1413
+ }
1414
+ return value;
1415
+ };
1416
+ })(util || (util = {}));
1417
+ var objectUtil;
1418
+ (function(objectUtil2) {
1419
+ objectUtil2.mergeShapes = (first, second) => {
1420
+ return {
1421
+ ...first,
1422
+ ...second
1423
+ // second overwrites first
1424
+ };
1425
+ };
1426
+ })(objectUtil || (objectUtil = {}));
1427
+ var ZodParsedType = util.arrayToEnum([
1428
+ "string",
1429
+ "nan",
1430
+ "number",
1431
+ "integer",
1432
+ "float",
1433
+ "boolean",
1434
+ "date",
1435
+ "bigint",
1436
+ "symbol",
1437
+ "function",
1438
+ "undefined",
1439
+ "null",
1440
+ "array",
1441
+ "object",
1442
+ "unknown",
1443
+ "promise",
1444
+ "void",
1445
+ "never",
1446
+ "map",
1447
+ "set"
1448
+ ]);
1449
+ var getParsedType = (data) => {
1450
+ const t = typeof data;
1451
+ switch (t) {
1452
+ case "undefined":
1453
+ return ZodParsedType.undefined;
1454
+ case "string":
1455
+ return ZodParsedType.string;
1456
+ case "number":
1457
+ return Number.isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
1458
+ case "boolean":
1459
+ return ZodParsedType.boolean;
1460
+ case "function":
1461
+ return ZodParsedType.function;
1462
+ case "bigint":
1463
+ return ZodParsedType.bigint;
1464
+ case "symbol":
1465
+ return ZodParsedType.symbol;
1466
+ case "object":
1467
+ if (Array.isArray(data)) {
1468
+ return ZodParsedType.array;
1469
+ }
1470
+ if (data === null) {
1471
+ return ZodParsedType.null;
1472
+ }
1473
+ if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") {
1474
+ return ZodParsedType.promise;
1475
+ }
1476
+ if (typeof Map !== "undefined" && data instanceof Map) {
1477
+ return ZodParsedType.map;
1478
+ }
1479
+ if (typeof Set !== "undefined" && data instanceof Set) {
1480
+ return ZodParsedType.set;
1481
+ }
1482
+ if (typeof Date !== "undefined" && data instanceof Date) {
1483
+ return ZodParsedType.date;
1484
+ }
1485
+ return ZodParsedType.object;
1486
+ default:
1487
+ return ZodParsedType.unknown;
1488
+ }
1489
+ };
1490
+
1491
+ // ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/ZodError.js
1492
+ var ZodIssueCode = util.arrayToEnum([
1493
+ "invalid_type",
1494
+ "invalid_literal",
1495
+ "custom",
1496
+ "invalid_union",
1497
+ "invalid_union_discriminator",
1498
+ "invalid_enum_value",
1499
+ "unrecognized_keys",
1500
+ "invalid_arguments",
1501
+ "invalid_return_type",
1502
+ "invalid_date",
1503
+ "invalid_string",
1504
+ "too_small",
1505
+ "too_big",
1506
+ "invalid_intersection_types",
1507
+ "not_multiple_of",
1508
+ "not_finite"
1509
+ ]);
1510
+ var quotelessJson = (obj) => {
1511
+ const json = JSON.stringify(obj, null, 2);
1512
+ return json.replace(/"([^"]+)":/g, "$1:");
1513
+ };
1514
+ var ZodError = class _ZodError extends Error {
1515
+ get errors() {
1516
+ return this.issues;
1517
+ }
1518
+ constructor(issues) {
1519
+ super();
1520
+ this.issues = [];
1521
+ this.addIssue = (sub) => {
1522
+ this.issues = [...this.issues, sub];
1523
+ };
1524
+ this.addIssues = (subs = []) => {
1525
+ this.issues = [...this.issues, ...subs];
1526
+ };
1527
+ const actualProto = new.target.prototype;
1528
+ if (Object.setPrototypeOf) {
1529
+ Object.setPrototypeOf(this, actualProto);
1530
+ } else {
1531
+ this.__proto__ = actualProto;
1532
+ }
1533
+ this.name = "ZodError";
1534
+ this.issues = issues;
1535
+ }
1536
+ format(_mapper) {
1537
+ const mapper = _mapper || function(issue) {
1538
+ return issue.message;
1539
+ };
1540
+ const fieldErrors = { _errors: [] };
1541
+ const processError = (error) => {
1542
+ for (const issue of error.issues) {
1543
+ if (issue.code === "invalid_union") {
1544
+ issue.unionErrors.map(processError);
1545
+ } else if (issue.code === "invalid_return_type") {
1546
+ processError(issue.returnTypeError);
1547
+ } else if (issue.code === "invalid_arguments") {
1548
+ processError(issue.argumentsError);
1549
+ } else if (issue.path.length === 0) {
1550
+ fieldErrors._errors.push(mapper(issue));
1551
+ } else {
1552
+ let curr = fieldErrors;
1553
+ let i = 0;
1554
+ while (i < issue.path.length) {
1555
+ const el = issue.path[i];
1556
+ const terminal = i === issue.path.length - 1;
1557
+ if (!terminal) {
1558
+ curr[el] = curr[el] || { _errors: [] };
1559
+ } else {
1560
+ curr[el] = curr[el] || { _errors: [] };
1561
+ curr[el]._errors.push(mapper(issue));
1562
+ }
1563
+ curr = curr[el];
1564
+ i++;
1565
+ }
1566
+ }
1567
+ }
1568
+ };
1569
+ processError(this);
1570
+ return fieldErrors;
1571
+ }
1572
+ static assert(value) {
1573
+ if (!(value instanceof _ZodError)) {
1574
+ throw new Error(`Not a ZodError: ${value}`);
1575
+ }
1576
+ }
1577
+ toString() {
1578
+ return this.message;
1579
+ }
1580
+ get message() {
1581
+ return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2);
1582
+ }
1583
+ get isEmpty() {
1584
+ return this.issues.length === 0;
1585
+ }
1586
+ flatten(mapper = (issue) => issue.message) {
1587
+ const fieldErrors = {};
1588
+ const formErrors = [];
1589
+ for (const sub of this.issues) {
1590
+ if (sub.path.length > 0) {
1591
+ const firstEl = sub.path[0];
1592
+ fieldErrors[firstEl] = fieldErrors[firstEl] || [];
1593
+ fieldErrors[firstEl].push(mapper(sub));
1594
+ } else {
1595
+ formErrors.push(mapper(sub));
1596
+ }
1597
+ }
1598
+ return { formErrors, fieldErrors };
1599
+ }
1600
+ get formErrors() {
1601
+ return this.flatten();
1602
+ }
1603
+ };
1604
+ ZodError.create = (issues) => {
1605
+ const error = new ZodError(issues);
1606
+ return error;
1607
+ };
1608
+
1609
+ // ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/locales/en.js
1610
+ var errorMap = (issue, _ctx) => {
1611
+ let message;
1612
+ switch (issue.code) {
1613
+ case ZodIssueCode.invalid_type:
1614
+ if (issue.received === ZodParsedType.undefined) {
1615
+ message = "Required";
1616
+ } else {
1617
+ message = `Expected ${issue.expected}, received ${issue.received}`;
1618
+ }
1619
+ break;
1620
+ case ZodIssueCode.invalid_literal:
1621
+ message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util.jsonStringifyReplacer)}`;
1622
+ break;
1623
+ case ZodIssueCode.unrecognized_keys:
1624
+ message = `Unrecognized key(s) in object: ${util.joinValues(issue.keys, ", ")}`;
1625
+ break;
1626
+ case ZodIssueCode.invalid_union:
1627
+ message = `Invalid input`;
1628
+ break;
1629
+ case ZodIssueCode.invalid_union_discriminator:
1630
+ message = `Invalid discriminator value. Expected ${util.joinValues(issue.options)}`;
1631
+ break;
1632
+ case ZodIssueCode.invalid_enum_value:
1633
+ message = `Invalid enum value. Expected ${util.joinValues(issue.options)}, received '${issue.received}'`;
1634
+ break;
1635
+ case ZodIssueCode.invalid_arguments:
1636
+ message = `Invalid function arguments`;
1637
+ break;
1638
+ case ZodIssueCode.invalid_return_type:
1639
+ message = `Invalid function return type`;
1640
+ break;
1641
+ case ZodIssueCode.invalid_date:
1642
+ message = `Invalid date`;
1643
+ break;
1644
+ case ZodIssueCode.invalid_string:
1645
+ if (typeof issue.validation === "object") {
1646
+ if ("includes" in issue.validation) {
1647
+ message = `Invalid input: must include "${issue.validation.includes}"`;
1648
+ if (typeof issue.validation.position === "number") {
1649
+ message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`;
1650
+ }
1651
+ } else if ("startsWith" in issue.validation) {
1652
+ message = `Invalid input: must start with "${issue.validation.startsWith}"`;
1653
+ } else if ("endsWith" in issue.validation) {
1654
+ message = `Invalid input: must end with "${issue.validation.endsWith}"`;
1655
+ } else {
1656
+ util.assertNever(issue.validation);
1657
+ }
1658
+ } else if (issue.validation !== "regex") {
1659
+ message = `Invalid ${issue.validation}`;
1660
+ } else {
1661
+ message = "Invalid";
1662
+ }
1663
+ break;
1664
+ case ZodIssueCode.too_small:
1665
+ if (issue.type === "array")
1666
+ message = `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`;
1667
+ else if (issue.type === "string")
1668
+ message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
1669
+ else if (issue.type === "number")
1670
+ message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
1671
+ else if (issue.type === "bigint")
1672
+ message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
1673
+ else if (issue.type === "date")
1674
+ message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue.minimum))}`;
1675
+ else
1676
+ message = "Invalid input";
1677
+ break;
1678
+ case ZodIssueCode.too_big:
1679
+ if (issue.type === "array")
1680
+ message = `Array must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`;
1681
+ else if (issue.type === "string")
1682
+ message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
1683
+ else if (issue.type === "number")
1684
+ message = `Number must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
1685
+ else if (issue.type === "bigint")
1686
+ message = `BigInt must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
1687
+ else if (issue.type === "date")
1688
+ message = `Date must be ${issue.exact ? `exactly` : issue.inclusive ? `smaller than or equal to` : `smaller than`} ${new Date(Number(issue.maximum))}`;
1689
+ else
1690
+ message = "Invalid input";
1691
+ break;
1692
+ case ZodIssueCode.custom:
1693
+ message = `Invalid input`;
1694
+ break;
1695
+ case ZodIssueCode.invalid_intersection_types:
1696
+ message = `Intersection results could not be merged`;
1697
+ break;
1698
+ case ZodIssueCode.not_multiple_of:
1699
+ message = `Number must be a multiple of ${issue.multipleOf}`;
1700
+ break;
1701
+ case ZodIssueCode.not_finite:
1702
+ message = "Number must be finite";
1703
+ break;
1704
+ default:
1705
+ message = _ctx.defaultError;
1706
+ util.assertNever(issue);
1707
+ }
1708
+ return { message };
1709
+ };
1710
+ var en_default = errorMap;
1711
+
1712
+ // ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/errors.js
1713
+ var overrideErrorMap = en_default;
1714
+ function setErrorMap(map) {
1715
+ overrideErrorMap = map;
1716
+ }
1717
+ function getErrorMap() {
1718
+ return overrideErrorMap;
1719
+ }
1720
+
1721
+ // ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/parseUtil.js
1722
+ var makeIssue = (params) => {
1723
+ const { data, path: path2, errorMaps, issueData } = params;
1724
+ const fullPath = [...path2, ...issueData.path || []];
1725
+ const fullIssue = {
1726
+ ...issueData,
1727
+ path: fullPath
1728
+ };
1729
+ if (issueData.message !== void 0) {
1730
+ return {
1731
+ ...issueData,
1732
+ path: fullPath,
1733
+ message: issueData.message
1734
+ };
1735
+ }
1736
+ let errorMessage = "";
1737
+ const maps = errorMaps.filter((m) => !!m).slice().reverse();
1738
+ for (const map of maps) {
1739
+ errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
1740
+ }
1741
+ return {
1742
+ ...issueData,
1743
+ path: fullPath,
1744
+ message: errorMessage
1745
+ };
1746
+ };
1747
+ var EMPTY_PATH = [];
1748
+ function addIssueToContext(ctx, issueData) {
1749
+ const overrideMap = getErrorMap();
1750
+ const issue = makeIssue({
1751
+ issueData,
1752
+ data: ctx.data,
1753
+ path: ctx.path,
1754
+ errorMaps: [
1755
+ ctx.common.contextualErrorMap,
1756
+ // contextual error map is first priority
1757
+ ctx.schemaErrorMap,
1758
+ // then schema-bound map if available
1759
+ overrideMap,
1760
+ // then global override map
1761
+ overrideMap === en_default ? void 0 : en_default
1762
+ // then global default map
1763
+ ].filter((x) => !!x)
1764
+ });
1765
+ ctx.common.issues.push(issue);
1766
+ }
1767
+ var ParseStatus = class _ParseStatus {
1768
+ constructor() {
1769
+ this.value = "valid";
1770
+ }
1771
+ dirty() {
1772
+ if (this.value === "valid")
1773
+ this.value = "dirty";
1774
+ }
1775
+ abort() {
1776
+ if (this.value !== "aborted")
1777
+ this.value = "aborted";
1778
+ }
1779
+ static mergeArray(status, results) {
1780
+ const arrayValue = [];
1781
+ for (const s of results) {
1782
+ if (s.status === "aborted")
1783
+ return INVALID;
1784
+ if (s.status === "dirty")
1785
+ status.dirty();
1786
+ arrayValue.push(s.value);
1787
+ }
1788
+ return { status: status.value, value: arrayValue };
1789
+ }
1790
+ static async mergeObjectAsync(status, pairs) {
1791
+ const syncPairs = [];
1792
+ for (const pair of pairs) {
1793
+ const key = await pair.key;
1794
+ const value = await pair.value;
1795
+ syncPairs.push({
1796
+ key,
1797
+ value
1798
+ });
1799
+ }
1800
+ return _ParseStatus.mergeObjectSync(status, syncPairs);
1801
+ }
1802
+ static mergeObjectSync(status, pairs) {
1803
+ const finalObject = {};
1804
+ for (const pair of pairs) {
1805
+ const { key, value } = pair;
1806
+ if (key.status === "aborted")
1807
+ return INVALID;
1808
+ if (value.status === "aborted")
1809
+ return INVALID;
1810
+ if (key.status === "dirty")
1811
+ status.dirty();
1812
+ if (value.status === "dirty")
1813
+ status.dirty();
1814
+ if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) {
1815
+ finalObject[key.value] = value.value;
1816
+ }
1817
+ }
1818
+ return { status: status.value, value: finalObject };
1819
+ }
1820
+ };
1821
+ var INVALID = Object.freeze({
1822
+ status: "aborted"
1823
+ });
1824
+ var DIRTY = (value) => ({ status: "dirty", value });
1825
+ var OK = (value) => ({ status: "valid", value });
1826
+ var isAborted = (x) => x.status === "aborted";
1827
+ var isDirty = (x) => x.status === "dirty";
1828
+ var isValid = (x) => x.status === "valid";
1829
+ var isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
1830
+
1831
+ // ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/errorUtil.js
1832
+ var errorUtil;
1833
+ (function(errorUtil2) {
1834
+ errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
1835
+ errorUtil2.toString = (message) => typeof message === "string" ? message : message?.message;
1836
+ })(errorUtil || (errorUtil = {}));
1837
+
1838
+ // ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/types.js
1839
+ var ParseInputLazyPath = class {
1840
+ constructor(parent, value, path2, key) {
1841
+ this._cachedPath = [];
1842
+ this.parent = parent;
1843
+ this.data = value;
1844
+ this._path = path2;
1845
+ this._key = key;
1846
+ }
1847
+ get path() {
1848
+ if (!this._cachedPath.length) {
1849
+ if (Array.isArray(this._key)) {
1850
+ this._cachedPath.push(...this._path, ...this._key);
1851
+ } else {
1852
+ this._cachedPath.push(...this._path, this._key);
1853
+ }
1854
+ }
1855
+ return this._cachedPath;
1856
+ }
1857
+ };
1858
+ var handleResult = (ctx, result) => {
1859
+ if (isValid(result)) {
1860
+ return { success: true, data: result.value };
1861
+ } else {
1862
+ if (!ctx.common.issues.length) {
1863
+ throw new Error("Validation failed but no issues detected.");
1864
+ }
1865
+ return {
1866
+ success: false,
1867
+ get error() {
1868
+ if (this._error)
1869
+ return this._error;
1870
+ const error = new ZodError(ctx.common.issues);
1871
+ this._error = error;
1872
+ return this._error;
1873
+ }
1874
+ };
1875
+ }
1876
+ };
1877
+ function processCreateParams(params) {
1878
+ if (!params)
1879
+ return {};
1880
+ const { errorMap: errorMap2, invalid_type_error, required_error, description } = params;
1881
+ if (errorMap2 && (invalid_type_error || required_error)) {
1882
+ throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
1883
+ }
1884
+ if (errorMap2)
1885
+ return { errorMap: errorMap2, description };
1886
+ const customMap = (iss, ctx) => {
1887
+ const { message } = params;
1888
+ if (iss.code === "invalid_enum_value") {
1889
+ return { message: message ?? ctx.defaultError };
1890
+ }
1891
+ if (typeof ctx.data === "undefined") {
1892
+ return { message: message ?? required_error ?? ctx.defaultError };
1893
+ }
1894
+ if (iss.code !== "invalid_type")
1895
+ return { message: ctx.defaultError };
1896
+ return { message: message ?? invalid_type_error ?? ctx.defaultError };
1897
+ };
1898
+ return { errorMap: customMap, description };
1899
+ }
1900
+ var ZodType = class {
1901
+ get description() {
1902
+ return this._def.description;
1903
+ }
1904
+ _getType(input) {
1905
+ return getParsedType(input.data);
1906
+ }
1907
+ _getOrReturnCtx(input, ctx) {
1908
+ return ctx || {
1909
+ common: input.parent.common,
1910
+ data: input.data,
1911
+ parsedType: getParsedType(input.data),
1912
+ schemaErrorMap: this._def.errorMap,
1913
+ path: input.path,
1914
+ parent: input.parent
1915
+ };
1916
+ }
1917
+ _processInputParams(input) {
1918
+ return {
1919
+ status: new ParseStatus(),
1920
+ ctx: {
1921
+ common: input.parent.common,
1922
+ data: input.data,
1923
+ parsedType: getParsedType(input.data),
1924
+ schemaErrorMap: this._def.errorMap,
1925
+ path: input.path,
1926
+ parent: input.parent
1927
+ }
1928
+ };
1929
+ }
1930
+ _parseSync(input) {
1931
+ const result = this._parse(input);
1932
+ if (isAsync(result)) {
1933
+ throw new Error("Synchronous parse encountered promise.");
1934
+ }
1935
+ return result;
1936
+ }
1937
+ _parseAsync(input) {
1938
+ const result = this._parse(input);
1939
+ return Promise.resolve(result);
1940
+ }
1941
+ parse(data, params) {
1942
+ const result = this.safeParse(data, params);
1943
+ if (result.success)
1944
+ return result.data;
1945
+ throw result.error;
1946
+ }
1947
+ safeParse(data, params) {
1948
+ const ctx = {
1949
+ common: {
1950
+ issues: [],
1951
+ async: params?.async ?? false,
1952
+ contextualErrorMap: params?.errorMap
1953
+ },
1954
+ path: params?.path || [],
1955
+ schemaErrorMap: this._def.errorMap,
1956
+ parent: null,
1957
+ data,
1958
+ parsedType: getParsedType(data)
1959
+ };
1960
+ const result = this._parseSync({ data, path: ctx.path, parent: ctx });
1961
+ return handleResult(ctx, result);
1962
+ }
1963
+ "~validate"(data) {
1964
+ const ctx = {
1965
+ common: {
1966
+ issues: [],
1967
+ async: !!this["~standard"].async
1968
+ },
1969
+ path: [],
1970
+ schemaErrorMap: this._def.errorMap,
1971
+ parent: null,
1972
+ data,
1973
+ parsedType: getParsedType(data)
1974
+ };
1975
+ if (!this["~standard"].async) {
1976
+ try {
1977
+ const result = this._parseSync({ data, path: [], parent: ctx });
1978
+ return isValid(result) ? {
1979
+ value: result.value
1980
+ } : {
1981
+ issues: ctx.common.issues
1982
+ };
1983
+ } catch (err) {
1984
+ if (err?.message?.toLowerCase()?.includes("encountered")) {
1985
+ this["~standard"].async = true;
1986
+ }
1987
+ ctx.common = {
1988
+ issues: [],
1989
+ async: true
1990
+ };
1991
+ }
1992
+ }
1993
+ return this._parseAsync({ data, path: [], parent: ctx }).then((result) => isValid(result) ? {
1994
+ value: result.value
1995
+ } : {
1996
+ issues: ctx.common.issues
1997
+ });
1998
+ }
1999
+ async parseAsync(data, params) {
2000
+ const result = await this.safeParseAsync(data, params);
2001
+ if (result.success)
2002
+ return result.data;
2003
+ throw result.error;
2004
+ }
2005
+ async safeParseAsync(data, params) {
2006
+ const ctx = {
2007
+ common: {
2008
+ issues: [],
2009
+ contextualErrorMap: params?.errorMap,
2010
+ async: true
2011
+ },
2012
+ path: params?.path || [],
2013
+ schemaErrorMap: this._def.errorMap,
2014
+ parent: null,
2015
+ data,
2016
+ parsedType: getParsedType(data)
2017
+ };
2018
+ const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
2019
+ const result = await (isAsync(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult));
2020
+ return handleResult(ctx, result);
2021
+ }
2022
+ refine(check, message) {
2023
+ const getIssueProperties = (val) => {
2024
+ if (typeof message === "string" || typeof message === "undefined") {
2025
+ return { message };
2026
+ } else if (typeof message === "function") {
2027
+ return message(val);
2028
+ } else {
2029
+ return message;
2030
+ }
2031
+ };
2032
+ return this._refinement((val, ctx) => {
2033
+ const result = check(val);
2034
+ const setError = () => ctx.addIssue({
2035
+ code: ZodIssueCode.custom,
2036
+ ...getIssueProperties(val)
2037
+ });
2038
+ if (typeof Promise !== "undefined" && result instanceof Promise) {
2039
+ return result.then((data) => {
2040
+ if (!data) {
2041
+ setError();
2042
+ return false;
2043
+ } else {
2044
+ return true;
2045
+ }
2046
+ });
2047
+ }
2048
+ if (!result) {
2049
+ setError();
2050
+ return false;
2051
+ } else {
2052
+ return true;
2053
+ }
2054
+ });
2055
+ }
2056
+ refinement(check, refinementData) {
2057
+ return this._refinement((val, ctx) => {
2058
+ if (!check(val)) {
2059
+ ctx.addIssue(typeof refinementData === "function" ? refinementData(val, ctx) : refinementData);
2060
+ return false;
2061
+ } else {
2062
+ return true;
2063
+ }
2064
+ });
2065
+ }
2066
+ _refinement(refinement) {
2067
+ return new ZodEffects({
2068
+ schema: this,
2069
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
2070
+ effect: { type: "refinement", refinement }
2071
+ });
2072
+ }
2073
+ superRefine(refinement) {
2074
+ return this._refinement(refinement);
2075
+ }
2076
+ constructor(def) {
2077
+ this.spa = this.safeParseAsync;
2078
+ this._def = def;
2079
+ this.parse = this.parse.bind(this);
2080
+ this.safeParse = this.safeParse.bind(this);
2081
+ this.parseAsync = this.parseAsync.bind(this);
2082
+ this.safeParseAsync = this.safeParseAsync.bind(this);
2083
+ this.spa = this.spa.bind(this);
2084
+ this.refine = this.refine.bind(this);
2085
+ this.refinement = this.refinement.bind(this);
2086
+ this.superRefine = this.superRefine.bind(this);
2087
+ this.optional = this.optional.bind(this);
2088
+ this.nullable = this.nullable.bind(this);
2089
+ this.nullish = this.nullish.bind(this);
2090
+ this.array = this.array.bind(this);
2091
+ this.promise = this.promise.bind(this);
2092
+ this.or = this.or.bind(this);
2093
+ this.and = this.and.bind(this);
2094
+ this.transform = this.transform.bind(this);
2095
+ this.brand = this.brand.bind(this);
2096
+ this.default = this.default.bind(this);
2097
+ this.catch = this.catch.bind(this);
2098
+ this.describe = this.describe.bind(this);
2099
+ this.pipe = this.pipe.bind(this);
2100
+ this.readonly = this.readonly.bind(this);
2101
+ this.isNullable = this.isNullable.bind(this);
2102
+ this.isOptional = this.isOptional.bind(this);
2103
+ this["~standard"] = {
2104
+ version: 1,
2105
+ vendor: "zod",
2106
+ validate: (data) => this["~validate"](data)
2107
+ };
2108
+ }
2109
+ optional() {
2110
+ return ZodOptional.create(this, this._def);
2111
+ }
2112
+ nullable() {
2113
+ return ZodNullable.create(this, this._def);
2114
+ }
2115
+ nullish() {
2116
+ return this.nullable().optional();
2117
+ }
2118
+ array() {
2119
+ return ZodArray.create(this);
2120
+ }
2121
+ promise() {
2122
+ return ZodPromise.create(this, this._def);
2123
+ }
2124
+ or(option) {
2125
+ return ZodUnion.create([this, option], this._def);
2126
+ }
2127
+ and(incoming) {
2128
+ return ZodIntersection.create(this, incoming, this._def);
2129
+ }
2130
+ transform(transform) {
2131
+ return new ZodEffects({
2132
+ ...processCreateParams(this._def),
2133
+ schema: this,
2134
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
2135
+ effect: { type: "transform", transform }
2136
+ });
2137
+ }
2138
+ default(def) {
2139
+ const defaultValueFunc = typeof def === "function" ? def : () => def;
2140
+ return new ZodDefault({
2141
+ ...processCreateParams(this._def),
2142
+ innerType: this,
2143
+ defaultValue: defaultValueFunc,
2144
+ typeName: ZodFirstPartyTypeKind.ZodDefault
2145
+ });
2146
+ }
2147
+ brand() {
2148
+ return new ZodBranded({
2149
+ typeName: ZodFirstPartyTypeKind.ZodBranded,
2150
+ type: this,
2151
+ ...processCreateParams(this._def)
2152
+ });
2153
+ }
2154
+ catch(def) {
2155
+ const catchValueFunc = typeof def === "function" ? def : () => def;
2156
+ return new ZodCatch({
2157
+ ...processCreateParams(this._def),
2158
+ innerType: this,
2159
+ catchValue: catchValueFunc,
2160
+ typeName: ZodFirstPartyTypeKind.ZodCatch
2161
+ });
2162
+ }
2163
+ describe(description) {
2164
+ const This = this.constructor;
2165
+ return new This({
2166
+ ...this._def,
2167
+ description
2168
+ });
2169
+ }
2170
+ pipe(target) {
2171
+ return ZodPipeline.create(this, target);
2172
+ }
2173
+ readonly() {
2174
+ return ZodReadonly.create(this);
2175
+ }
2176
+ isOptional() {
2177
+ return this.safeParse(void 0).success;
2178
+ }
2179
+ isNullable() {
2180
+ return this.safeParse(null).success;
2181
+ }
2182
+ };
2183
+ var cuidRegex = /^c[^\s-]{8,}$/i;
2184
+ var cuid2Regex = /^[0-9a-z]+$/;
2185
+ var ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
2186
+ var uuidRegex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i;
2187
+ var nanoidRegex = /^[a-z0-9_-]{21}$/i;
2188
+ var jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
2189
+ var durationRegex = /^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/;
2190
+ var emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
2191
+ var _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
2192
+ var emojiRegex;
2193
+ var ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
2194
+ var ipv4CidrRegex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/;
2195
+ var ipv6Regex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/;
2196
+ var ipv6CidrRegex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
2197
+ var base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
2198
+ var base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
2199
+ var dateRegexSource = `((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))`;
2200
+ var dateRegex = new RegExp(`^${dateRegexSource}$`);
2201
+ function timeRegexSource(args) {
2202
+ let secondsRegexSource = `[0-5]\\d`;
2203
+ if (args.precision) {
2204
+ secondsRegexSource = `${secondsRegexSource}\\.\\d{${args.precision}}`;
2205
+ } else if (args.precision == null) {
2206
+ secondsRegexSource = `${secondsRegexSource}(\\.\\d+)?`;
2207
+ }
2208
+ const secondsQuantifier = args.precision ? "+" : "?";
2209
+ return `([01]\\d|2[0-3]):[0-5]\\d(:${secondsRegexSource})${secondsQuantifier}`;
2210
+ }
2211
+ function timeRegex(args) {
2212
+ return new RegExp(`^${timeRegexSource(args)}$`);
2213
+ }
2214
+ function datetimeRegex(args) {
2215
+ let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
2216
+ const opts = [];
2217
+ opts.push(args.local ? `Z?` : `Z`);
2218
+ if (args.offset)
2219
+ opts.push(`([+-]\\d{2}:?\\d{2})`);
2220
+ regex = `${regex}(${opts.join("|")})`;
2221
+ return new RegExp(`^${regex}$`);
2222
+ }
2223
+ function isValidIP(ip, version) {
2224
+ if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
2225
+ return true;
2226
+ }
2227
+ if ((version === "v6" || !version) && ipv6Regex.test(ip)) {
2228
+ return true;
2229
+ }
2230
+ return false;
2231
+ }
2232
+ function isValidJWT(jwt, alg) {
2233
+ if (!jwtRegex.test(jwt))
2234
+ return false;
2235
+ try {
2236
+ const [header] = jwt.split(".");
2237
+ if (!header)
2238
+ return false;
2239
+ const base64 = header.replace(/-/g, "+").replace(/_/g, "/").padEnd(header.length + (4 - header.length % 4) % 4, "=");
2240
+ const decoded = JSON.parse(atob(base64));
2241
+ if (typeof decoded !== "object" || decoded === null)
2242
+ return false;
2243
+ if ("typ" in decoded && decoded?.typ !== "JWT")
2244
+ return false;
2245
+ if (!decoded.alg)
2246
+ return false;
2247
+ if (alg && decoded.alg !== alg)
2248
+ return false;
2249
+ return true;
2250
+ } catch {
2251
+ return false;
2252
+ }
2253
+ }
2254
+ function isValidCidr(ip, version) {
2255
+ if ((version === "v4" || !version) && ipv4CidrRegex.test(ip)) {
2256
+ return true;
2257
+ }
2258
+ if ((version === "v6" || !version) && ipv6CidrRegex.test(ip)) {
2259
+ return true;
2260
+ }
2261
+ return false;
2262
+ }
2263
+ var ZodString = class _ZodString extends ZodType {
2264
+ _parse(input) {
2265
+ if (this._def.coerce) {
2266
+ input.data = String(input.data);
2267
+ }
2268
+ const parsedType = this._getType(input);
2269
+ if (parsedType !== ZodParsedType.string) {
2270
+ const ctx2 = this._getOrReturnCtx(input);
2271
+ addIssueToContext(ctx2, {
2272
+ code: ZodIssueCode.invalid_type,
2273
+ expected: ZodParsedType.string,
2274
+ received: ctx2.parsedType
2275
+ });
2276
+ return INVALID;
2277
+ }
2278
+ const status = new ParseStatus();
2279
+ let ctx = void 0;
2280
+ for (const check of this._def.checks) {
2281
+ if (check.kind === "min") {
2282
+ if (input.data.length < check.value) {
2283
+ ctx = this._getOrReturnCtx(input, ctx);
2284
+ addIssueToContext(ctx, {
2285
+ code: ZodIssueCode.too_small,
2286
+ minimum: check.value,
2287
+ type: "string",
2288
+ inclusive: true,
2289
+ exact: false,
2290
+ message: check.message
2291
+ });
2292
+ status.dirty();
2293
+ }
2294
+ } else if (check.kind === "max") {
2295
+ if (input.data.length > check.value) {
2296
+ ctx = this._getOrReturnCtx(input, ctx);
2297
+ addIssueToContext(ctx, {
2298
+ code: ZodIssueCode.too_big,
2299
+ maximum: check.value,
2300
+ type: "string",
2301
+ inclusive: true,
2302
+ exact: false,
2303
+ message: check.message
2304
+ });
2305
+ status.dirty();
2306
+ }
2307
+ } else if (check.kind === "length") {
2308
+ const tooBig = input.data.length > check.value;
2309
+ const tooSmall = input.data.length < check.value;
2310
+ if (tooBig || tooSmall) {
2311
+ ctx = this._getOrReturnCtx(input, ctx);
2312
+ if (tooBig) {
2313
+ addIssueToContext(ctx, {
2314
+ code: ZodIssueCode.too_big,
2315
+ maximum: check.value,
2316
+ type: "string",
2317
+ inclusive: true,
2318
+ exact: true,
2319
+ message: check.message
2320
+ });
2321
+ } else if (tooSmall) {
2322
+ addIssueToContext(ctx, {
2323
+ code: ZodIssueCode.too_small,
2324
+ minimum: check.value,
2325
+ type: "string",
2326
+ inclusive: true,
2327
+ exact: true,
2328
+ message: check.message
2329
+ });
2330
+ }
2331
+ status.dirty();
2332
+ }
2333
+ } else if (check.kind === "email") {
2334
+ if (!emailRegex.test(input.data)) {
2335
+ ctx = this._getOrReturnCtx(input, ctx);
2336
+ addIssueToContext(ctx, {
2337
+ validation: "email",
2338
+ code: ZodIssueCode.invalid_string,
2339
+ message: check.message
2340
+ });
2341
+ status.dirty();
2342
+ }
2343
+ } else if (check.kind === "emoji") {
2344
+ if (!emojiRegex) {
2345
+ emojiRegex = new RegExp(_emojiRegex, "u");
2346
+ }
2347
+ if (!emojiRegex.test(input.data)) {
2348
+ ctx = this._getOrReturnCtx(input, ctx);
2349
+ addIssueToContext(ctx, {
2350
+ validation: "emoji",
2351
+ code: ZodIssueCode.invalid_string,
2352
+ message: check.message
2353
+ });
2354
+ status.dirty();
2355
+ }
2356
+ } else if (check.kind === "uuid") {
2357
+ if (!uuidRegex.test(input.data)) {
2358
+ ctx = this._getOrReturnCtx(input, ctx);
2359
+ addIssueToContext(ctx, {
2360
+ validation: "uuid",
2361
+ code: ZodIssueCode.invalid_string,
2362
+ message: check.message
2363
+ });
2364
+ status.dirty();
2365
+ }
2366
+ } else if (check.kind === "nanoid") {
2367
+ if (!nanoidRegex.test(input.data)) {
2368
+ ctx = this._getOrReturnCtx(input, ctx);
2369
+ addIssueToContext(ctx, {
2370
+ validation: "nanoid",
2371
+ code: ZodIssueCode.invalid_string,
2372
+ message: check.message
2373
+ });
2374
+ status.dirty();
2375
+ }
2376
+ } else if (check.kind === "cuid") {
2377
+ if (!cuidRegex.test(input.data)) {
2378
+ ctx = this._getOrReturnCtx(input, ctx);
2379
+ addIssueToContext(ctx, {
2380
+ validation: "cuid",
2381
+ code: ZodIssueCode.invalid_string,
2382
+ message: check.message
2383
+ });
2384
+ status.dirty();
2385
+ }
2386
+ } else if (check.kind === "cuid2") {
2387
+ if (!cuid2Regex.test(input.data)) {
2388
+ ctx = this._getOrReturnCtx(input, ctx);
2389
+ addIssueToContext(ctx, {
2390
+ validation: "cuid2",
2391
+ code: ZodIssueCode.invalid_string,
2392
+ message: check.message
2393
+ });
2394
+ status.dirty();
2395
+ }
2396
+ } else if (check.kind === "ulid") {
2397
+ if (!ulidRegex.test(input.data)) {
2398
+ ctx = this._getOrReturnCtx(input, ctx);
2399
+ addIssueToContext(ctx, {
2400
+ validation: "ulid",
2401
+ code: ZodIssueCode.invalid_string,
2402
+ message: check.message
2403
+ });
2404
+ status.dirty();
2405
+ }
2406
+ } else if (check.kind === "url") {
2407
+ try {
2408
+ new URL(input.data);
2409
+ } catch {
2410
+ ctx = this._getOrReturnCtx(input, ctx);
2411
+ addIssueToContext(ctx, {
2412
+ validation: "url",
2413
+ code: ZodIssueCode.invalid_string,
2414
+ message: check.message
2415
+ });
2416
+ status.dirty();
2417
+ }
2418
+ } else if (check.kind === "regex") {
2419
+ check.regex.lastIndex = 0;
2420
+ const testResult = check.regex.test(input.data);
2421
+ if (!testResult) {
2422
+ ctx = this._getOrReturnCtx(input, ctx);
2423
+ addIssueToContext(ctx, {
2424
+ validation: "regex",
2425
+ code: ZodIssueCode.invalid_string,
2426
+ message: check.message
2427
+ });
2428
+ status.dirty();
2429
+ }
2430
+ } else if (check.kind === "trim") {
2431
+ input.data = input.data.trim();
2432
+ } else if (check.kind === "includes") {
2433
+ if (!input.data.includes(check.value, check.position)) {
2434
+ ctx = this._getOrReturnCtx(input, ctx);
2435
+ addIssueToContext(ctx, {
2436
+ code: ZodIssueCode.invalid_string,
2437
+ validation: { includes: check.value, position: check.position },
2438
+ message: check.message
2439
+ });
2440
+ status.dirty();
2441
+ }
2442
+ } else if (check.kind === "toLowerCase") {
2443
+ input.data = input.data.toLowerCase();
2444
+ } else if (check.kind === "toUpperCase") {
2445
+ input.data = input.data.toUpperCase();
2446
+ } else if (check.kind === "startsWith") {
2447
+ if (!input.data.startsWith(check.value)) {
2448
+ ctx = this._getOrReturnCtx(input, ctx);
2449
+ addIssueToContext(ctx, {
2450
+ code: ZodIssueCode.invalid_string,
2451
+ validation: { startsWith: check.value },
2452
+ message: check.message
2453
+ });
2454
+ status.dirty();
2455
+ }
2456
+ } else if (check.kind === "endsWith") {
2457
+ if (!input.data.endsWith(check.value)) {
2458
+ ctx = this._getOrReturnCtx(input, ctx);
2459
+ addIssueToContext(ctx, {
2460
+ code: ZodIssueCode.invalid_string,
2461
+ validation: { endsWith: check.value },
2462
+ message: check.message
2463
+ });
2464
+ status.dirty();
2465
+ }
2466
+ } else if (check.kind === "datetime") {
2467
+ const regex = datetimeRegex(check);
2468
+ if (!regex.test(input.data)) {
2469
+ ctx = this._getOrReturnCtx(input, ctx);
2470
+ addIssueToContext(ctx, {
2471
+ code: ZodIssueCode.invalid_string,
2472
+ validation: "datetime",
2473
+ message: check.message
2474
+ });
2475
+ status.dirty();
2476
+ }
2477
+ } else if (check.kind === "date") {
2478
+ const regex = dateRegex;
2479
+ if (!regex.test(input.data)) {
2480
+ ctx = this._getOrReturnCtx(input, ctx);
2481
+ addIssueToContext(ctx, {
2482
+ code: ZodIssueCode.invalid_string,
2483
+ validation: "date",
2484
+ message: check.message
2485
+ });
2486
+ status.dirty();
2487
+ }
2488
+ } else if (check.kind === "time") {
2489
+ const regex = timeRegex(check);
2490
+ if (!regex.test(input.data)) {
2491
+ ctx = this._getOrReturnCtx(input, ctx);
2492
+ addIssueToContext(ctx, {
2493
+ code: ZodIssueCode.invalid_string,
2494
+ validation: "time",
2495
+ message: check.message
2496
+ });
2497
+ status.dirty();
2498
+ }
2499
+ } else if (check.kind === "duration") {
2500
+ if (!durationRegex.test(input.data)) {
2501
+ ctx = this._getOrReturnCtx(input, ctx);
2502
+ addIssueToContext(ctx, {
2503
+ validation: "duration",
2504
+ code: ZodIssueCode.invalid_string,
2505
+ message: check.message
2506
+ });
2507
+ status.dirty();
2508
+ }
2509
+ } else if (check.kind === "ip") {
2510
+ if (!isValidIP(input.data, check.version)) {
2511
+ ctx = this._getOrReturnCtx(input, ctx);
2512
+ addIssueToContext(ctx, {
2513
+ validation: "ip",
2514
+ code: ZodIssueCode.invalid_string,
2515
+ message: check.message
2516
+ });
2517
+ status.dirty();
2518
+ }
2519
+ } else if (check.kind === "jwt") {
2520
+ if (!isValidJWT(input.data, check.alg)) {
2521
+ ctx = this._getOrReturnCtx(input, ctx);
2522
+ addIssueToContext(ctx, {
2523
+ validation: "jwt",
2524
+ code: ZodIssueCode.invalid_string,
2525
+ message: check.message
2526
+ });
2527
+ status.dirty();
2528
+ }
2529
+ } else if (check.kind === "cidr") {
2530
+ if (!isValidCidr(input.data, check.version)) {
2531
+ ctx = this._getOrReturnCtx(input, ctx);
2532
+ addIssueToContext(ctx, {
2533
+ validation: "cidr",
2534
+ code: ZodIssueCode.invalid_string,
2535
+ message: check.message
2536
+ });
2537
+ status.dirty();
2538
+ }
2539
+ } else if (check.kind === "base64") {
2540
+ if (!base64Regex.test(input.data)) {
2541
+ ctx = this._getOrReturnCtx(input, ctx);
2542
+ addIssueToContext(ctx, {
2543
+ validation: "base64",
2544
+ code: ZodIssueCode.invalid_string,
2545
+ message: check.message
2546
+ });
2547
+ status.dirty();
2548
+ }
2549
+ } else if (check.kind === "base64url") {
2550
+ if (!base64urlRegex.test(input.data)) {
2551
+ ctx = this._getOrReturnCtx(input, ctx);
2552
+ addIssueToContext(ctx, {
2553
+ validation: "base64url",
2554
+ code: ZodIssueCode.invalid_string,
2555
+ message: check.message
2556
+ });
2557
+ status.dirty();
2558
+ }
2559
+ } else {
2560
+ util.assertNever(check);
2561
+ }
2562
+ }
2563
+ return { status: status.value, value: input.data };
2564
+ }
2565
+ _regex(regex, validation, message) {
2566
+ return this.refinement((data) => regex.test(data), {
2567
+ validation,
2568
+ code: ZodIssueCode.invalid_string,
2569
+ ...errorUtil.errToObj(message)
2570
+ });
2571
+ }
2572
+ _addCheck(check) {
2573
+ return new _ZodString({
2574
+ ...this._def,
2575
+ checks: [...this._def.checks, check]
2576
+ });
2577
+ }
2578
+ email(message) {
2579
+ return this._addCheck({ kind: "email", ...errorUtil.errToObj(message) });
2580
+ }
2581
+ url(message) {
2582
+ return this._addCheck({ kind: "url", ...errorUtil.errToObj(message) });
2583
+ }
2584
+ emoji(message) {
2585
+ return this._addCheck({ kind: "emoji", ...errorUtil.errToObj(message) });
2586
+ }
2587
+ uuid(message) {
2588
+ return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
2589
+ }
2590
+ nanoid(message) {
2591
+ return this._addCheck({ kind: "nanoid", ...errorUtil.errToObj(message) });
2592
+ }
2593
+ cuid(message) {
2594
+ return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
2595
+ }
2596
+ cuid2(message) {
2597
+ return this._addCheck({ kind: "cuid2", ...errorUtil.errToObj(message) });
2598
+ }
2599
+ ulid(message) {
2600
+ return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) });
2601
+ }
2602
+ base64(message) {
2603
+ return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
2604
+ }
2605
+ base64url(message) {
2606
+ return this._addCheck({
2607
+ kind: "base64url",
2608
+ ...errorUtil.errToObj(message)
2609
+ });
2610
+ }
2611
+ jwt(options) {
2612
+ return this._addCheck({ kind: "jwt", ...errorUtil.errToObj(options) });
2613
+ }
2614
+ ip(options) {
2615
+ return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
2616
+ }
2617
+ cidr(options) {
2618
+ return this._addCheck({ kind: "cidr", ...errorUtil.errToObj(options) });
2619
+ }
2620
+ datetime(options) {
2621
+ if (typeof options === "string") {
2622
+ return this._addCheck({
2623
+ kind: "datetime",
2624
+ precision: null,
2625
+ offset: false,
2626
+ local: false,
2627
+ message: options
2628
+ });
2629
+ }
2630
+ return this._addCheck({
2631
+ kind: "datetime",
2632
+ precision: typeof options?.precision === "undefined" ? null : options?.precision,
2633
+ offset: options?.offset ?? false,
2634
+ local: options?.local ?? false,
2635
+ ...errorUtil.errToObj(options?.message)
2636
+ });
2637
+ }
2638
+ date(message) {
2639
+ return this._addCheck({ kind: "date", message });
2640
+ }
2641
+ time(options) {
2642
+ if (typeof options === "string") {
2643
+ return this._addCheck({
2644
+ kind: "time",
2645
+ precision: null,
2646
+ message: options
2647
+ });
2648
+ }
2649
+ return this._addCheck({
2650
+ kind: "time",
2651
+ precision: typeof options?.precision === "undefined" ? null : options?.precision,
2652
+ ...errorUtil.errToObj(options?.message)
2653
+ });
2654
+ }
2655
+ duration(message) {
2656
+ return this._addCheck({ kind: "duration", ...errorUtil.errToObj(message) });
2657
+ }
2658
+ regex(regex, message) {
2659
+ return this._addCheck({
2660
+ kind: "regex",
2661
+ regex,
2662
+ ...errorUtil.errToObj(message)
2663
+ });
2664
+ }
2665
+ includes(value, options) {
2666
+ return this._addCheck({
2667
+ kind: "includes",
2668
+ value,
2669
+ position: options?.position,
2670
+ ...errorUtil.errToObj(options?.message)
2671
+ });
2672
+ }
2673
+ startsWith(value, message) {
2674
+ return this._addCheck({
2675
+ kind: "startsWith",
2676
+ value,
2677
+ ...errorUtil.errToObj(message)
2678
+ });
2679
+ }
2680
+ endsWith(value, message) {
2681
+ return this._addCheck({
2682
+ kind: "endsWith",
2683
+ value,
2684
+ ...errorUtil.errToObj(message)
2685
+ });
2686
+ }
2687
+ min(minLength, message) {
2688
+ return this._addCheck({
2689
+ kind: "min",
2690
+ value: minLength,
2691
+ ...errorUtil.errToObj(message)
2692
+ });
2693
+ }
2694
+ max(maxLength, message) {
2695
+ return this._addCheck({
2696
+ kind: "max",
2697
+ value: maxLength,
2698
+ ...errorUtil.errToObj(message)
2699
+ });
2700
+ }
2701
+ length(len, message) {
2702
+ return this._addCheck({
2703
+ kind: "length",
2704
+ value: len,
2705
+ ...errorUtil.errToObj(message)
2706
+ });
2707
+ }
2708
+ /**
2709
+ * Equivalent to `.min(1)`
2710
+ */
2711
+ nonempty(message) {
2712
+ return this.min(1, errorUtil.errToObj(message));
2713
+ }
2714
+ trim() {
2715
+ return new _ZodString({
2716
+ ...this._def,
2717
+ checks: [...this._def.checks, { kind: "trim" }]
2718
+ });
2719
+ }
2720
+ toLowerCase() {
2721
+ return new _ZodString({
2722
+ ...this._def,
2723
+ checks: [...this._def.checks, { kind: "toLowerCase" }]
2724
+ });
2725
+ }
2726
+ toUpperCase() {
2727
+ return new _ZodString({
2728
+ ...this._def,
2729
+ checks: [...this._def.checks, { kind: "toUpperCase" }]
2730
+ });
2731
+ }
2732
+ get isDatetime() {
2733
+ return !!this._def.checks.find((ch) => ch.kind === "datetime");
2734
+ }
2735
+ get isDate() {
2736
+ return !!this._def.checks.find((ch) => ch.kind === "date");
2737
+ }
2738
+ get isTime() {
2739
+ return !!this._def.checks.find((ch) => ch.kind === "time");
2740
+ }
2741
+ get isDuration() {
2742
+ return !!this._def.checks.find((ch) => ch.kind === "duration");
2743
+ }
2744
+ get isEmail() {
2745
+ return !!this._def.checks.find((ch) => ch.kind === "email");
2746
+ }
2747
+ get isURL() {
2748
+ return !!this._def.checks.find((ch) => ch.kind === "url");
2749
+ }
2750
+ get isEmoji() {
2751
+ return !!this._def.checks.find((ch) => ch.kind === "emoji");
2752
+ }
2753
+ get isUUID() {
2754
+ return !!this._def.checks.find((ch) => ch.kind === "uuid");
2755
+ }
2756
+ get isNANOID() {
2757
+ return !!this._def.checks.find((ch) => ch.kind === "nanoid");
2758
+ }
2759
+ get isCUID() {
2760
+ return !!this._def.checks.find((ch) => ch.kind === "cuid");
2761
+ }
2762
+ get isCUID2() {
2763
+ return !!this._def.checks.find((ch) => ch.kind === "cuid2");
2764
+ }
2765
+ get isULID() {
2766
+ return !!this._def.checks.find((ch) => ch.kind === "ulid");
2767
+ }
2768
+ get isIP() {
2769
+ return !!this._def.checks.find((ch) => ch.kind === "ip");
2770
+ }
2771
+ get isCIDR() {
2772
+ return !!this._def.checks.find((ch) => ch.kind === "cidr");
2773
+ }
2774
+ get isBase64() {
2775
+ return !!this._def.checks.find((ch) => ch.kind === "base64");
2776
+ }
2777
+ get isBase64url() {
2778
+ return !!this._def.checks.find((ch) => ch.kind === "base64url");
2779
+ }
2780
+ get minLength() {
2781
+ let min = null;
2782
+ for (const ch of this._def.checks) {
2783
+ if (ch.kind === "min") {
2784
+ if (min === null || ch.value > min)
2785
+ min = ch.value;
2786
+ }
2787
+ }
2788
+ return min;
2789
+ }
2790
+ get maxLength() {
2791
+ let max = null;
2792
+ for (const ch of this._def.checks) {
2793
+ if (ch.kind === "max") {
2794
+ if (max === null || ch.value < max)
2795
+ max = ch.value;
2796
+ }
2797
+ }
2798
+ return max;
2799
+ }
2800
+ };
2801
+ ZodString.create = (params) => {
2802
+ return new ZodString({
2803
+ checks: [],
2804
+ typeName: ZodFirstPartyTypeKind.ZodString,
2805
+ coerce: params?.coerce ?? false,
2806
+ ...processCreateParams(params)
2807
+ });
2808
+ };
2809
+ function floatSafeRemainder(val, step) {
2810
+ const valDecCount = (val.toString().split(".")[1] || "").length;
2811
+ const stepDecCount = (step.toString().split(".")[1] || "").length;
2812
+ const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
2813
+ const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
2814
+ const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
2815
+ return valInt % stepInt / 10 ** decCount;
2816
+ }
2817
+ var ZodNumber = class _ZodNumber extends ZodType {
2818
+ constructor() {
2819
+ super(...arguments);
2820
+ this.min = this.gte;
2821
+ this.max = this.lte;
2822
+ this.step = this.multipleOf;
2823
+ }
2824
+ _parse(input) {
2825
+ if (this._def.coerce) {
2826
+ input.data = Number(input.data);
2827
+ }
2828
+ const parsedType = this._getType(input);
2829
+ if (parsedType !== ZodParsedType.number) {
2830
+ const ctx2 = this._getOrReturnCtx(input);
2831
+ addIssueToContext(ctx2, {
2832
+ code: ZodIssueCode.invalid_type,
2833
+ expected: ZodParsedType.number,
2834
+ received: ctx2.parsedType
2835
+ });
2836
+ return INVALID;
2837
+ }
2838
+ let ctx = void 0;
2839
+ const status = new ParseStatus();
2840
+ for (const check of this._def.checks) {
2841
+ if (check.kind === "int") {
2842
+ if (!util.isInteger(input.data)) {
2843
+ ctx = this._getOrReturnCtx(input, ctx);
2844
+ addIssueToContext(ctx, {
2845
+ code: ZodIssueCode.invalid_type,
2846
+ expected: "integer",
2847
+ received: "float",
2848
+ message: check.message
2849
+ });
2850
+ status.dirty();
2851
+ }
2852
+ } else if (check.kind === "min") {
2853
+ const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
2854
+ if (tooSmall) {
2855
+ ctx = this._getOrReturnCtx(input, ctx);
2856
+ addIssueToContext(ctx, {
2857
+ code: ZodIssueCode.too_small,
2858
+ minimum: check.value,
2859
+ type: "number",
2860
+ inclusive: check.inclusive,
2861
+ exact: false,
2862
+ message: check.message
2863
+ });
2864
+ status.dirty();
2865
+ }
2866
+ } else if (check.kind === "max") {
2867
+ const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
2868
+ if (tooBig) {
2869
+ ctx = this._getOrReturnCtx(input, ctx);
2870
+ addIssueToContext(ctx, {
2871
+ code: ZodIssueCode.too_big,
2872
+ maximum: check.value,
2873
+ type: "number",
2874
+ inclusive: check.inclusive,
2875
+ exact: false,
2876
+ message: check.message
2877
+ });
2878
+ status.dirty();
2879
+ }
2880
+ } else if (check.kind === "multipleOf") {
2881
+ if (floatSafeRemainder(input.data, check.value) !== 0) {
2882
+ ctx = this._getOrReturnCtx(input, ctx);
2883
+ addIssueToContext(ctx, {
2884
+ code: ZodIssueCode.not_multiple_of,
2885
+ multipleOf: check.value,
2886
+ message: check.message
2887
+ });
2888
+ status.dirty();
2889
+ }
2890
+ } else if (check.kind === "finite") {
2891
+ if (!Number.isFinite(input.data)) {
2892
+ ctx = this._getOrReturnCtx(input, ctx);
2893
+ addIssueToContext(ctx, {
2894
+ code: ZodIssueCode.not_finite,
2895
+ message: check.message
2896
+ });
2897
+ status.dirty();
2898
+ }
2899
+ } else {
2900
+ util.assertNever(check);
2901
+ }
2902
+ }
2903
+ return { status: status.value, value: input.data };
2904
+ }
2905
+ gte(value, message) {
2906
+ return this.setLimit("min", value, true, errorUtil.toString(message));
2907
+ }
2908
+ gt(value, message) {
2909
+ return this.setLimit("min", value, false, errorUtil.toString(message));
2910
+ }
2911
+ lte(value, message) {
2912
+ return this.setLimit("max", value, true, errorUtil.toString(message));
2913
+ }
2914
+ lt(value, message) {
2915
+ return this.setLimit("max", value, false, errorUtil.toString(message));
2916
+ }
2917
+ setLimit(kind, value, inclusive, message) {
2918
+ return new _ZodNumber({
2919
+ ...this._def,
2920
+ checks: [
2921
+ ...this._def.checks,
2922
+ {
2923
+ kind,
2924
+ value,
2925
+ inclusive,
2926
+ message: errorUtil.toString(message)
2927
+ }
2928
+ ]
2929
+ });
2930
+ }
2931
+ _addCheck(check) {
2932
+ return new _ZodNumber({
2933
+ ...this._def,
2934
+ checks: [...this._def.checks, check]
2935
+ });
2936
+ }
2937
+ int(message) {
2938
+ return this._addCheck({
2939
+ kind: "int",
2940
+ message: errorUtil.toString(message)
2941
+ });
2942
+ }
2943
+ positive(message) {
2944
+ return this._addCheck({
2945
+ kind: "min",
2946
+ value: 0,
2947
+ inclusive: false,
2948
+ message: errorUtil.toString(message)
2949
+ });
2950
+ }
2951
+ negative(message) {
2952
+ return this._addCheck({
2953
+ kind: "max",
2954
+ value: 0,
2955
+ inclusive: false,
2956
+ message: errorUtil.toString(message)
2957
+ });
2958
+ }
2959
+ nonpositive(message) {
2960
+ return this._addCheck({
2961
+ kind: "max",
2962
+ value: 0,
2963
+ inclusive: true,
2964
+ message: errorUtil.toString(message)
2965
+ });
2966
+ }
2967
+ nonnegative(message) {
2968
+ return this._addCheck({
2969
+ kind: "min",
2970
+ value: 0,
2971
+ inclusive: true,
2972
+ message: errorUtil.toString(message)
2973
+ });
2974
+ }
2975
+ multipleOf(value, message) {
2976
+ return this._addCheck({
2977
+ kind: "multipleOf",
2978
+ value,
2979
+ message: errorUtil.toString(message)
2980
+ });
2981
+ }
2982
+ finite(message) {
2983
+ return this._addCheck({
2984
+ kind: "finite",
2985
+ message: errorUtil.toString(message)
2986
+ });
2987
+ }
2988
+ safe(message) {
2989
+ return this._addCheck({
2990
+ kind: "min",
2991
+ inclusive: true,
2992
+ value: Number.MIN_SAFE_INTEGER,
2993
+ message: errorUtil.toString(message)
2994
+ })._addCheck({
2995
+ kind: "max",
2996
+ inclusive: true,
2997
+ value: Number.MAX_SAFE_INTEGER,
2998
+ message: errorUtil.toString(message)
2999
+ });
3000
+ }
3001
+ get minValue() {
3002
+ let min = null;
3003
+ for (const ch of this._def.checks) {
3004
+ if (ch.kind === "min") {
3005
+ if (min === null || ch.value > min)
3006
+ min = ch.value;
3007
+ }
3008
+ }
3009
+ return min;
3010
+ }
3011
+ get maxValue() {
3012
+ let max = null;
3013
+ for (const ch of this._def.checks) {
3014
+ if (ch.kind === "max") {
3015
+ if (max === null || ch.value < max)
3016
+ max = ch.value;
3017
+ }
3018
+ }
3019
+ return max;
3020
+ }
3021
+ get isInt() {
3022
+ return !!this._def.checks.find((ch) => ch.kind === "int" || ch.kind === "multipleOf" && util.isInteger(ch.value));
3023
+ }
3024
+ get isFinite() {
3025
+ let max = null;
3026
+ let min = null;
3027
+ for (const ch of this._def.checks) {
3028
+ if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf") {
3029
+ return true;
3030
+ } else if (ch.kind === "min") {
3031
+ if (min === null || ch.value > min)
3032
+ min = ch.value;
3033
+ } else if (ch.kind === "max") {
3034
+ if (max === null || ch.value < max)
3035
+ max = ch.value;
3036
+ }
3037
+ }
3038
+ return Number.isFinite(min) && Number.isFinite(max);
3039
+ }
3040
+ };
3041
+ ZodNumber.create = (params) => {
3042
+ return new ZodNumber({
3043
+ checks: [],
3044
+ typeName: ZodFirstPartyTypeKind.ZodNumber,
3045
+ coerce: params?.coerce || false,
3046
+ ...processCreateParams(params)
3047
+ });
3048
+ };
3049
+ var ZodBigInt = class _ZodBigInt extends ZodType {
3050
+ constructor() {
3051
+ super(...arguments);
3052
+ this.min = this.gte;
3053
+ this.max = this.lte;
3054
+ }
3055
+ _parse(input) {
3056
+ if (this._def.coerce) {
3057
+ try {
3058
+ input.data = BigInt(input.data);
3059
+ } catch {
3060
+ return this._getInvalidInput(input);
3061
+ }
3062
+ }
3063
+ const parsedType = this._getType(input);
3064
+ if (parsedType !== ZodParsedType.bigint) {
3065
+ return this._getInvalidInput(input);
3066
+ }
3067
+ let ctx = void 0;
3068
+ const status = new ParseStatus();
3069
+ for (const check of this._def.checks) {
3070
+ if (check.kind === "min") {
3071
+ const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
3072
+ if (tooSmall) {
3073
+ ctx = this._getOrReturnCtx(input, ctx);
3074
+ addIssueToContext(ctx, {
3075
+ code: ZodIssueCode.too_small,
3076
+ type: "bigint",
3077
+ minimum: check.value,
3078
+ inclusive: check.inclusive,
3079
+ message: check.message
3080
+ });
3081
+ status.dirty();
3082
+ }
3083
+ } else if (check.kind === "max") {
3084
+ const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
3085
+ if (tooBig) {
3086
+ ctx = this._getOrReturnCtx(input, ctx);
3087
+ addIssueToContext(ctx, {
3088
+ code: ZodIssueCode.too_big,
3089
+ type: "bigint",
3090
+ maximum: check.value,
3091
+ inclusive: check.inclusive,
3092
+ message: check.message
3093
+ });
3094
+ status.dirty();
3095
+ }
3096
+ } else if (check.kind === "multipleOf") {
3097
+ if (input.data % check.value !== BigInt(0)) {
3098
+ ctx = this._getOrReturnCtx(input, ctx);
3099
+ addIssueToContext(ctx, {
3100
+ code: ZodIssueCode.not_multiple_of,
3101
+ multipleOf: check.value,
3102
+ message: check.message
3103
+ });
3104
+ status.dirty();
3105
+ }
3106
+ } else {
3107
+ util.assertNever(check);
3108
+ }
3109
+ }
3110
+ return { status: status.value, value: input.data };
3111
+ }
3112
+ _getInvalidInput(input) {
3113
+ const ctx = this._getOrReturnCtx(input);
3114
+ addIssueToContext(ctx, {
3115
+ code: ZodIssueCode.invalid_type,
3116
+ expected: ZodParsedType.bigint,
3117
+ received: ctx.parsedType
3118
+ });
3119
+ return INVALID;
3120
+ }
3121
+ gte(value, message) {
3122
+ return this.setLimit("min", value, true, errorUtil.toString(message));
3123
+ }
3124
+ gt(value, message) {
3125
+ return this.setLimit("min", value, false, errorUtil.toString(message));
3126
+ }
3127
+ lte(value, message) {
3128
+ return this.setLimit("max", value, true, errorUtil.toString(message));
3129
+ }
3130
+ lt(value, message) {
3131
+ return this.setLimit("max", value, false, errorUtil.toString(message));
3132
+ }
3133
+ setLimit(kind, value, inclusive, message) {
3134
+ return new _ZodBigInt({
3135
+ ...this._def,
3136
+ checks: [
3137
+ ...this._def.checks,
3138
+ {
3139
+ kind,
3140
+ value,
3141
+ inclusive,
3142
+ message: errorUtil.toString(message)
3143
+ }
3144
+ ]
3145
+ });
3146
+ }
3147
+ _addCheck(check) {
3148
+ return new _ZodBigInt({
3149
+ ...this._def,
3150
+ checks: [...this._def.checks, check]
3151
+ });
3152
+ }
3153
+ positive(message) {
3154
+ return this._addCheck({
3155
+ kind: "min",
3156
+ value: BigInt(0),
3157
+ inclusive: false,
3158
+ message: errorUtil.toString(message)
3159
+ });
3160
+ }
3161
+ negative(message) {
3162
+ return this._addCheck({
3163
+ kind: "max",
3164
+ value: BigInt(0),
3165
+ inclusive: false,
3166
+ message: errorUtil.toString(message)
3167
+ });
3168
+ }
3169
+ nonpositive(message) {
3170
+ return this._addCheck({
3171
+ kind: "max",
3172
+ value: BigInt(0),
3173
+ inclusive: true,
3174
+ message: errorUtil.toString(message)
3175
+ });
3176
+ }
3177
+ nonnegative(message) {
3178
+ return this._addCheck({
3179
+ kind: "min",
3180
+ value: BigInt(0),
3181
+ inclusive: true,
3182
+ message: errorUtil.toString(message)
3183
+ });
3184
+ }
3185
+ multipleOf(value, message) {
3186
+ return this._addCheck({
3187
+ kind: "multipleOf",
3188
+ value,
3189
+ message: errorUtil.toString(message)
3190
+ });
3191
+ }
3192
+ get minValue() {
3193
+ let min = null;
3194
+ for (const ch of this._def.checks) {
3195
+ if (ch.kind === "min") {
3196
+ if (min === null || ch.value > min)
3197
+ min = ch.value;
3198
+ }
3199
+ }
3200
+ return min;
3201
+ }
3202
+ get maxValue() {
3203
+ let max = null;
3204
+ for (const ch of this._def.checks) {
3205
+ if (ch.kind === "max") {
3206
+ if (max === null || ch.value < max)
3207
+ max = ch.value;
3208
+ }
3209
+ }
3210
+ return max;
3211
+ }
3212
+ };
3213
+ ZodBigInt.create = (params) => {
3214
+ return new ZodBigInt({
3215
+ checks: [],
3216
+ typeName: ZodFirstPartyTypeKind.ZodBigInt,
3217
+ coerce: params?.coerce ?? false,
3218
+ ...processCreateParams(params)
3219
+ });
3220
+ };
3221
+ var ZodBoolean = class extends ZodType {
3222
+ _parse(input) {
3223
+ if (this._def.coerce) {
3224
+ input.data = Boolean(input.data);
3225
+ }
3226
+ const parsedType = this._getType(input);
3227
+ if (parsedType !== ZodParsedType.boolean) {
3228
+ const ctx = this._getOrReturnCtx(input);
3229
+ addIssueToContext(ctx, {
3230
+ code: ZodIssueCode.invalid_type,
3231
+ expected: ZodParsedType.boolean,
3232
+ received: ctx.parsedType
3233
+ });
3234
+ return INVALID;
3235
+ }
3236
+ return OK(input.data);
3237
+ }
3238
+ };
3239
+ ZodBoolean.create = (params) => {
3240
+ return new ZodBoolean({
3241
+ typeName: ZodFirstPartyTypeKind.ZodBoolean,
3242
+ coerce: params?.coerce || false,
3243
+ ...processCreateParams(params)
3244
+ });
3245
+ };
3246
+ var ZodDate = class _ZodDate extends ZodType {
3247
+ _parse(input) {
3248
+ if (this._def.coerce) {
3249
+ input.data = new Date(input.data);
3250
+ }
3251
+ const parsedType = this._getType(input);
3252
+ if (parsedType !== ZodParsedType.date) {
3253
+ const ctx2 = this._getOrReturnCtx(input);
3254
+ addIssueToContext(ctx2, {
3255
+ code: ZodIssueCode.invalid_type,
3256
+ expected: ZodParsedType.date,
3257
+ received: ctx2.parsedType
3258
+ });
3259
+ return INVALID;
3260
+ }
3261
+ if (Number.isNaN(input.data.getTime())) {
3262
+ const ctx2 = this._getOrReturnCtx(input);
3263
+ addIssueToContext(ctx2, {
3264
+ code: ZodIssueCode.invalid_date
3265
+ });
3266
+ return INVALID;
3267
+ }
3268
+ const status = new ParseStatus();
3269
+ let ctx = void 0;
3270
+ for (const check of this._def.checks) {
3271
+ if (check.kind === "min") {
3272
+ if (input.data.getTime() < check.value) {
3273
+ ctx = this._getOrReturnCtx(input, ctx);
3274
+ addIssueToContext(ctx, {
3275
+ code: ZodIssueCode.too_small,
3276
+ message: check.message,
3277
+ inclusive: true,
3278
+ exact: false,
3279
+ minimum: check.value,
3280
+ type: "date"
3281
+ });
3282
+ status.dirty();
3283
+ }
3284
+ } else if (check.kind === "max") {
3285
+ if (input.data.getTime() > check.value) {
3286
+ ctx = this._getOrReturnCtx(input, ctx);
3287
+ addIssueToContext(ctx, {
3288
+ code: ZodIssueCode.too_big,
3289
+ message: check.message,
3290
+ inclusive: true,
3291
+ exact: false,
3292
+ maximum: check.value,
3293
+ type: "date"
3294
+ });
3295
+ status.dirty();
3296
+ }
3297
+ } else {
3298
+ util.assertNever(check);
3299
+ }
3300
+ }
3301
+ return {
3302
+ status: status.value,
3303
+ value: new Date(input.data.getTime())
3304
+ };
3305
+ }
3306
+ _addCheck(check) {
3307
+ return new _ZodDate({
3308
+ ...this._def,
3309
+ checks: [...this._def.checks, check]
3310
+ });
3311
+ }
3312
+ min(minDate, message) {
3313
+ return this._addCheck({
3314
+ kind: "min",
3315
+ value: minDate.getTime(),
3316
+ message: errorUtil.toString(message)
3317
+ });
3318
+ }
3319
+ max(maxDate, message) {
3320
+ return this._addCheck({
3321
+ kind: "max",
3322
+ value: maxDate.getTime(),
3323
+ message: errorUtil.toString(message)
3324
+ });
3325
+ }
3326
+ get minDate() {
3327
+ let min = null;
3328
+ for (const ch of this._def.checks) {
3329
+ if (ch.kind === "min") {
3330
+ if (min === null || ch.value > min)
3331
+ min = ch.value;
3332
+ }
3333
+ }
3334
+ return min != null ? new Date(min) : null;
3335
+ }
3336
+ get maxDate() {
3337
+ let max = null;
3338
+ for (const ch of this._def.checks) {
3339
+ if (ch.kind === "max") {
3340
+ if (max === null || ch.value < max)
3341
+ max = ch.value;
3342
+ }
3343
+ }
3344
+ return max != null ? new Date(max) : null;
3345
+ }
3346
+ };
3347
+ ZodDate.create = (params) => {
3348
+ return new ZodDate({
3349
+ checks: [],
3350
+ coerce: params?.coerce || false,
3351
+ typeName: ZodFirstPartyTypeKind.ZodDate,
3352
+ ...processCreateParams(params)
3353
+ });
3354
+ };
3355
+ var ZodSymbol = class extends ZodType {
3356
+ _parse(input) {
3357
+ const parsedType = this._getType(input);
3358
+ if (parsedType !== ZodParsedType.symbol) {
3359
+ const ctx = this._getOrReturnCtx(input);
3360
+ addIssueToContext(ctx, {
3361
+ code: ZodIssueCode.invalid_type,
3362
+ expected: ZodParsedType.symbol,
3363
+ received: ctx.parsedType
3364
+ });
3365
+ return INVALID;
3366
+ }
3367
+ return OK(input.data);
3368
+ }
3369
+ };
3370
+ ZodSymbol.create = (params) => {
3371
+ return new ZodSymbol({
3372
+ typeName: ZodFirstPartyTypeKind.ZodSymbol,
3373
+ ...processCreateParams(params)
3374
+ });
3375
+ };
3376
+ var ZodUndefined = class extends ZodType {
3377
+ _parse(input) {
3378
+ const parsedType = this._getType(input);
3379
+ if (parsedType !== ZodParsedType.undefined) {
3380
+ const ctx = this._getOrReturnCtx(input);
3381
+ addIssueToContext(ctx, {
3382
+ code: ZodIssueCode.invalid_type,
3383
+ expected: ZodParsedType.undefined,
3384
+ received: ctx.parsedType
3385
+ });
3386
+ return INVALID;
3387
+ }
3388
+ return OK(input.data);
3389
+ }
3390
+ };
3391
+ ZodUndefined.create = (params) => {
3392
+ return new ZodUndefined({
3393
+ typeName: ZodFirstPartyTypeKind.ZodUndefined,
3394
+ ...processCreateParams(params)
3395
+ });
3396
+ };
3397
+ var ZodNull = class extends ZodType {
3398
+ _parse(input) {
3399
+ const parsedType = this._getType(input);
3400
+ if (parsedType !== ZodParsedType.null) {
3401
+ const ctx = this._getOrReturnCtx(input);
3402
+ addIssueToContext(ctx, {
3403
+ code: ZodIssueCode.invalid_type,
3404
+ expected: ZodParsedType.null,
3405
+ received: ctx.parsedType
3406
+ });
3407
+ return INVALID;
3408
+ }
3409
+ return OK(input.data);
3410
+ }
3411
+ };
3412
+ ZodNull.create = (params) => {
3413
+ return new ZodNull({
3414
+ typeName: ZodFirstPartyTypeKind.ZodNull,
3415
+ ...processCreateParams(params)
3416
+ });
3417
+ };
3418
+ var ZodAny = class extends ZodType {
3419
+ constructor() {
3420
+ super(...arguments);
3421
+ this._any = true;
3422
+ }
3423
+ _parse(input) {
3424
+ return OK(input.data);
3425
+ }
3426
+ };
3427
+ ZodAny.create = (params) => {
3428
+ return new ZodAny({
3429
+ typeName: ZodFirstPartyTypeKind.ZodAny,
3430
+ ...processCreateParams(params)
3431
+ });
3432
+ };
3433
+ var ZodUnknown = class extends ZodType {
3434
+ constructor() {
3435
+ super(...arguments);
3436
+ this._unknown = true;
3437
+ }
3438
+ _parse(input) {
3439
+ return OK(input.data);
3440
+ }
3441
+ };
3442
+ ZodUnknown.create = (params) => {
3443
+ return new ZodUnknown({
3444
+ typeName: ZodFirstPartyTypeKind.ZodUnknown,
3445
+ ...processCreateParams(params)
3446
+ });
3447
+ };
3448
+ var ZodNever = class extends ZodType {
3449
+ _parse(input) {
3450
+ const ctx = this._getOrReturnCtx(input);
3451
+ addIssueToContext(ctx, {
3452
+ code: ZodIssueCode.invalid_type,
3453
+ expected: ZodParsedType.never,
3454
+ received: ctx.parsedType
3455
+ });
3456
+ return INVALID;
3457
+ }
3458
+ };
3459
+ ZodNever.create = (params) => {
3460
+ return new ZodNever({
3461
+ typeName: ZodFirstPartyTypeKind.ZodNever,
3462
+ ...processCreateParams(params)
3463
+ });
3464
+ };
3465
+ var ZodVoid = class extends ZodType {
3466
+ _parse(input) {
3467
+ const parsedType = this._getType(input);
3468
+ if (parsedType !== ZodParsedType.undefined) {
3469
+ const ctx = this._getOrReturnCtx(input);
3470
+ addIssueToContext(ctx, {
3471
+ code: ZodIssueCode.invalid_type,
3472
+ expected: ZodParsedType.void,
3473
+ received: ctx.parsedType
3474
+ });
3475
+ return INVALID;
3476
+ }
3477
+ return OK(input.data);
3478
+ }
3479
+ };
3480
+ ZodVoid.create = (params) => {
3481
+ return new ZodVoid({
3482
+ typeName: ZodFirstPartyTypeKind.ZodVoid,
3483
+ ...processCreateParams(params)
3484
+ });
3485
+ };
3486
+ var ZodArray = class _ZodArray extends ZodType {
3487
+ _parse(input) {
3488
+ const { ctx, status } = this._processInputParams(input);
3489
+ const def = this._def;
3490
+ if (ctx.parsedType !== ZodParsedType.array) {
3491
+ addIssueToContext(ctx, {
3492
+ code: ZodIssueCode.invalid_type,
3493
+ expected: ZodParsedType.array,
3494
+ received: ctx.parsedType
3495
+ });
3496
+ return INVALID;
3497
+ }
3498
+ if (def.exactLength !== null) {
3499
+ const tooBig = ctx.data.length > def.exactLength.value;
3500
+ const tooSmall = ctx.data.length < def.exactLength.value;
3501
+ if (tooBig || tooSmall) {
3502
+ addIssueToContext(ctx, {
3503
+ code: tooBig ? ZodIssueCode.too_big : ZodIssueCode.too_small,
3504
+ minimum: tooSmall ? def.exactLength.value : void 0,
3505
+ maximum: tooBig ? def.exactLength.value : void 0,
3506
+ type: "array",
3507
+ inclusive: true,
3508
+ exact: true,
3509
+ message: def.exactLength.message
3510
+ });
3511
+ status.dirty();
3512
+ }
3513
+ }
3514
+ if (def.minLength !== null) {
3515
+ if (ctx.data.length < def.minLength.value) {
3516
+ addIssueToContext(ctx, {
3517
+ code: ZodIssueCode.too_small,
3518
+ minimum: def.minLength.value,
3519
+ type: "array",
3520
+ inclusive: true,
3521
+ exact: false,
3522
+ message: def.minLength.message
3523
+ });
3524
+ status.dirty();
3525
+ }
3526
+ }
3527
+ if (def.maxLength !== null) {
3528
+ if (ctx.data.length > def.maxLength.value) {
3529
+ addIssueToContext(ctx, {
3530
+ code: ZodIssueCode.too_big,
3531
+ maximum: def.maxLength.value,
3532
+ type: "array",
3533
+ inclusive: true,
3534
+ exact: false,
3535
+ message: def.maxLength.message
3536
+ });
3537
+ status.dirty();
3538
+ }
3539
+ }
3540
+ if (ctx.common.async) {
3541
+ return Promise.all([...ctx.data].map((item, i) => {
3542
+ return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
3543
+ })).then((result2) => {
3544
+ return ParseStatus.mergeArray(status, result2);
3545
+ });
3546
+ }
3547
+ const result = [...ctx.data].map((item, i) => {
3548
+ return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
3549
+ });
3550
+ return ParseStatus.mergeArray(status, result);
3551
+ }
3552
+ get element() {
3553
+ return this._def.type;
3554
+ }
3555
+ min(minLength, message) {
3556
+ return new _ZodArray({
3557
+ ...this._def,
3558
+ minLength: { value: minLength, message: errorUtil.toString(message) }
3559
+ });
3560
+ }
3561
+ max(maxLength, message) {
3562
+ return new _ZodArray({
3563
+ ...this._def,
3564
+ maxLength: { value: maxLength, message: errorUtil.toString(message) }
3565
+ });
3566
+ }
3567
+ length(len, message) {
3568
+ return new _ZodArray({
3569
+ ...this._def,
3570
+ exactLength: { value: len, message: errorUtil.toString(message) }
3571
+ });
3572
+ }
3573
+ nonempty(message) {
3574
+ return this.min(1, message);
3575
+ }
3576
+ };
3577
+ ZodArray.create = (schema, params) => {
3578
+ return new ZodArray({
3579
+ type: schema,
3580
+ minLength: null,
3581
+ maxLength: null,
3582
+ exactLength: null,
3583
+ typeName: ZodFirstPartyTypeKind.ZodArray,
3584
+ ...processCreateParams(params)
3585
+ });
3586
+ };
3587
+ function deepPartialify(schema) {
3588
+ if (schema instanceof ZodObject) {
3589
+ const newShape = {};
3590
+ for (const key in schema.shape) {
3591
+ const fieldSchema = schema.shape[key];
3592
+ newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
3593
+ }
3594
+ return new ZodObject({
3595
+ ...schema._def,
3596
+ shape: () => newShape
3597
+ });
3598
+ } else if (schema instanceof ZodArray) {
3599
+ return new ZodArray({
3600
+ ...schema._def,
3601
+ type: deepPartialify(schema.element)
3602
+ });
3603
+ } else if (schema instanceof ZodOptional) {
3604
+ return ZodOptional.create(deepPartialify(schema.unwrap()));
3605
+ } else if (schema instanceof ZodNullable) {
3606
+ return ZodNullable.create(deepPartialify(schema.unwrap()));
3607
+ } else if (schema instanceof ZodTuple) {
3608
+ return ZodTuple.create(schema.items.map((item) => deepPartialify(item)));
3609
+ } else {
3610
+ return schema;
3611
+ }
3612
+ }
3613
+ var ZodObject = class _ZodObject extends ZodType {
3614
+ constructor() {
3615
+ super(...arguments);
3616
+ this._cached = null;
3617
+ this.nonstrict = this.passthrough;
3618
+ this.augment = this.extend;
3619
+ }
3620
+ _getCached() {
3621
+ if (this._cached !== null)
3622
+ return this._cached;
3623
+ const shape = this._def.shape();
3624
+ const keys = util.objectKeys(shape);
3625
+ this._cached = { shape, keys };
3626
+ return this._cached;
3627
+ }
3628
+ _parse(input) {
3629
+ const parsedType = this._getType(input);
3630
+ if (parsedType !== ZodParsedType.object) {
3631
+ const ctx2 = this._getOrReturnCtx(input);
3632
+ addIssueToContext(ctx2, {
3633
+ code: ZodIssueCode.invalid_type,
3634
+ expected: ZodParsedType.object,
3635
+ received: ctx2.parsedType
3636
+ });
3637
+ return INVALID;
3638
+ }
3639
+ const { status, ctx } = this._processInputParams(input);
3640
+ const { shape, keys: shapeKeys } = this._getCached();
3641
+ const extraKeys = [];
3642
+ if (!(this._def.catchall instanceof ZodNever && this._def.unknownKeys === "strip")) {
3643
+ for (const key in ctx.data) {
3644
+ if (!shapeKeys.includes(key)) {
3645
+ extraKeys.push(key);
3646
+ }
3647
+ }
3648
+ }
3649
+ const pairs = [];
3650
+ for (const key of shapeKeys) {
3651
+ const keyValidator = shape[key];
3652
+ const value = ctx.data[key];
3653
+ pairs.push({
3654
+ key: { status: "valid", value: key },
3655
+ value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
3656
+ alwaysSet: key in ctx.data
3657
+ });
3658
+ }
3659
+ if (this._def.catchall instanceof ZodNever) {
3660
+ const unknownKeys = this._def.unknownKeys;
3661
+ if (unknownKeys === "passthrough") {
3662
+ for (const key of extraKeys) {
3663
+ pairs.push({
3664
+ key: { status: "valid", value: key },
3665
+ value: { status: "valid", value: ctx.data[key] }
3666
+ });
3667
+ }
3668
+ } else if (unknownKeys === "strict") {
3669
+ if (extraKeys.length > 0) {
3670
+ addIssueToContext(ctx, {
3671
+ code: ZodIssueCode.unrecognized_keys,
3672
+ keys: extraKeys
3673
+ });
3674
+ status.dirty();
3675
+ }
3676
+ } else if (unknownKeys === "strip") {
3677
+ } else {
3678
+ throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
3679
+ }
3680
+ } else {
3681
+ const catchall = this._def.catchall;
3682
+ for (const key of extraKeys) {
3683
+ const value = ctx.data[key];
3684
+ pairs.push({
3685
+ key: { status: "valid", value: key },
3686
+ value: catchall._parse(
3687
+ new ParseInputLazyPath(ctx, value, ctx.path, key)
3688
+ //, ctx.child(key), value, getParsedType(value)
3689
+ ),
3690
+ alwaysSet: key in ctx.data
3691
+ });
3692
+ }
3693
+ }
3694
+ if (ctx.common.async) {
3695
+ return Promise.resolve().then(async () => {
3696
+ const syncPairs = [];
3697
+ for (const pair of pairs) {
3698
+ const key = await pair.key;
3699
+ const value = await pair.value;
3700
+ syncPairs.push({
3701
+ key,
3702
+ value,
3703
+ alwaysSet: pair.alwaysSet
3704
+ });
3705
+ }
3706
+ return syncPairs;
3707
+ }).then((syncPairs) => {
3708
+ return ParseStatus.mergeObjectSync(status, syncPairs);
3709
+ });
3710
+ } else {
3711
+ return ParseStatus.mergeObjectSync(status, pairs);
3712
+ }
3713
+ }
3714
+ get shape() {
3715
+ return this._def.shape();
3716
+ }
3717
+ strict(message) {
3718
+ errorUtil.errToObj;
3719
+ return new _ZodObject({
3720
+ ...this._def,
3721
+ unknownKeys: "strict",
3722
+ ...message !== void 0 ? {
3723
+ errorMap: (issue, ctx) => {
3724
+ const defaultError = this._def.errorMap?.(issue, ctx).message ?? ctx.defaultError;
3725
+ if (issue.code === "unrecognized_keys")
3726
+ return {
3727
+ message: errorUtil.errToObj(message).message ?? defaultError
3728
+ };
3729
+ return {
3730
+ message: defaultError
3731
+ };
3732
+ }
3733
+ } : {}
3734
+ });
3735
+ }
3736
+ strip() {
3737
+ return new _ZodObject({
3738
+ ...this._def,
3739
+ unknownKeys: "strip"
3740
+ });
3741
+ }
3742
+ passthrough() {
3743
+ return new _ZodObject({
3744
+ ...this._def,
3745
+ unknownKeys: "passthrough"
3746
+ });
3747
+ }
3748
+ // const AugmentFactory =
3749
+ // <Def extends ZodObjectDef>(def: Def) =>
3750
+ // <Augmentation extends ZodRawShape>(
3751
+ // augmentation: Augmentation
3752
+ // ): ZodObject<
3753
+ // extendShape<ReturnType<Def["shape"]>, Augmentation>,
3754
+ // Def["unknownKeys"],
3755
+ // Def["catchall"]
3756
+ // > => {
3757
+ // return new ZodObject({
3758
+ // ...def,
3759
+ // shape: () => ({
3760
+ // ...def.shape(),
3761
+ // ...augmentation,
3762
+ // }),
3763
+ // }) as any;
3764
+ // };
3765
+ extend(augmentation) {
3766
+ return new _ZodObject({
3767
+ ...this._def,
3768
+ shape: () => ({
3769
+ ...this._def.shape(),
3770
+ ...augmentation
3771
+ })
3772
+ });
3773
+ }
3774
+ /**
3775
+ * Prior to zod@1.0.12 there was a bug in the
3776
+ * inferred type of merged objects. Please
3777
+ * upgrade if you are experiencing issues.
3778
+ */
3779
+ merge(merging) {
3780
+ const merged = new _ZodObject({
3781
+ unknownKeys: merging._def.unknownKeys,
3782
+ catchall: merging._def.catchall,
3783
+ shape: () => ({
3784
+ ...this._def.shape(),
3785
+ ...merging._def.shape()
3786
+ }),
3787
+ typeName: ZodFirstPartyTypeKind.ZodObject
3788
+ });
3789
+ return merged;
3790
+ }
3791
+ // merge<
3792
+ // Incoming extends AnyZodObject,
3793
+ // Augmentation extends Incoming["shape"],
3794
+ // NewOutput extends {
3795
+ // [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
3796
+ // ? Augmentation[k]["_output"]
3797
+ // : k extends keyof Output
3798
+ // ? Output[k]
3799
+ // : never;
3800
+ // },
3801
+ // NewInput extends {
3802
+ // [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
3803
+ // ? Augmentation[k]["_input"]
3804
+ // : k extends keyof Input
3805
+ // ? Input[k]
3806
+ // : never;
3807
+ // }
3808
+ // >(
3809
+ // merging: Incoming
3810
+ // ): ZodObject<
3811
+ // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
3812
+ // Incoming["_def"]["unknownKeys"],
3813
+ // Incoming["_def"]["catchall"],
3814
+ // NewOutput,
3815
+ // NewInput
3816
+ // > {
3817
+ // const merged: any = new ZodObject({
3818
+ // unknownKeys: merging._def.unknownKeys,
3819
+ // catchall: merging._def.catchall,
3820
+ // shape: () =>
3821
+ // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
3822
+ // typeName: ZodFirstPartyTypeKind.ZodObject,
3823
+ // }) as any;
3824
+ // return merged;
3825
+ // }
3826
+ setKey(key, schema) {
3827
+ return this.augment({ [key]: schema });
3828
+ }
3829
+ // merge<Incoming extends AnyZodObject>(
3830
+ // merging: Incoming
3831
+ // ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
3832
+ // ZodObject<
3833
+ // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
3834
+ // Incoming["_def"]["unknownKeys"],
3835
+ // Incoming["_def"]["catchall"]
3836
+ // > {
3837
+ // // const mergedShape = objectUtil.mergeShapes(
3838
+ // // this._def.shape(),
3839
+ // // merging._def.shape()
3840
+ // // );
3841
+ // const merged: any = new ZodObject({
3842
+ // unknownKeys: merging._def.unknownKeys,
3843
+ // catchall: merging._def.catchall,
3844
+ // shape: () =>
3845
+ // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
3846
+ // typeName: ZodFirstPartyTypeKind.ZodObject,
3847
+ // }) as any;
3848
+ // return merged;
3849
+ // }
3850
+ catchall(index) {
3851
+ return new _ZodObject({
3852
+ ...this._def,
3853
+ catchall: index
3854
+ });
3855
+ }
3856
+ pick(mask) {
3857
+ const shape = {};
3858
+ for (const key of util.objectKeys(mask)) {
3859
+ if (mask[key] && this.shape[key]) {
3860
+ shape[key] = this.shape[key];
3861
+ }
3862
+ }
3863
+ return new _ZodObject({
3864
+ ...this._def,
3865
+ shape: () => shape
3866
+ });
3867
+ }
3868
+ omit(mask) {
3869
+ const shape = {};
3870
+ for (const key of util.objectKeys(this.shape)) {
3871
+ if (!mask[key]) {
3872
+ shape[key] = this.shape[key];
3873
+ }
3874
+ }
3875
+ return new _ZodObject({
3876
+ ...this._def,
3877
+ shape: () => shape
3878
+ });
3879
+ }
3880
+ /**
3881
+ * @deprecated
3882
+ */
3883
+ deepPartial() {
3884
+ return deepPartialify(this);
3885
+ }
3886
+ partial(mask) {
3887
+ const newShape = {};
3888
+ for (const key of util.objectKeys(this.shape)) {
3889
+ const fieldSchema = this.shape[key];
3890
+ if (mask && !mask[key]) {
3891
+ newShape[key] = fieldSchema;
3892
+ } else {
3893
+ newShape[key] = fieldSchema.optional();
3894
+ }
3895
+ }
3896
+ return new _ZodObject({
3897
+ ...this._def,
3898
+ shape: () => newShape
3899
+ });
3900
+ }
3901
+ required(mask) {
3902
+ const newShape = {};
3903
+ for (const key of util.objectKeys(this.shape)) {
3904
+ if (mask && !mask[key]) {
3905
+ newShape[key] = this.shape[key];
3906
+ } else {
3907
+ const fieldSchema = this.shape[key];
3908
+ let newField = fieldSchema;
3909
+ while (newField instanceof ZodOptional) {
3910
+ newField = newField._def.innerType;
3911
+ }
3912
+ newShape[key] = newField;
3913
+ }
3914
+ }
3915
+ return new _ZodObject({
3916
+ ...this._def,
3917
+ shape: () => newShape
3918
+ });
3919
+ }
3920
+ keyof() {
3921
+ return createZodEnum(util.objectKeys(this.shape));
3922
+ }
3923
+ };
3924
+ ZodObject.create = (shape, params) => {
3925
+ return new ZodObject({
3926
+ shape: () => shape,
3927
+ unknownKeys: "strip",
3928
+ catchall: ZodNever.create(),
3929
+ typeName: ZodFirstPartyTypeKind.ZodObject,
3930
+ ...processCreateParams(params)
3931
+ });
3932
+ };
3933
+ ZodObject.strictCreate = (shape, params) => {
3934
+ return new ZodObject({
3935
+ shape: () => shape,
3936
+ unknownKeys: "strict",
3937
+ catchall: ZodNever.create(),
3938
+ typeName: ZodFirstPartyTypeKind.ZodObject,
3939
+ ...processCreateParams(params)
3940
+ });
3941
+ };
3942
+ ZodObject.lazycreate = (shape, params) => {
3943
+ return new ZodObject({
3944
+ shape,
3945
+ unknownKeys: "strip",
3946
+ catchall: ZodNever.create(),
3947
+ typeName: ZodFirstPartyTypeKind.ZodObject,
3948
+ ...processCreateParams(params)
3949
+ });
3950
+ };
3951
+ var ZodUnion = class extends ZodType {
3952
+ _parse(input) {
3953
+ const { ctx } = this._processInputParams(input);
3954
+ const options = this._def.options;
3955
+ function handleResults(results) {
3956
+ for (const result of results) {
3957
+ if (result.result.status === "valid") {
3958
+ return result.result;
3959
+ }
3960
+ }
3961
+ for (const result of results) {
3962
+ if (result.result.status === "dirty") {
3963
+ ctx.common.issues.push(...result.ctx.common.issues);
3964
+ return result.result;
3965
+ }
3966
+ }
3967
+ const unionErrors = results.map((result) => new ZodError(result.ctx.common.issues));
3968
+ addIssueToContext(ctx, {
3969
+ code: ZodIssueCode.invalid_union,
3970
+ unionErrors
3971
+ });
3972
+ return INVALID;
3973
+ }
3974
+ if (ctx.common.async) {
3975
+ return Promise.all(options.map(async (option) => {
3976
+ const childCtx = {
3977
+ ...ctx,
3978
+ common: {
3979
+ ...ctx.common,
3980
+ issues: []
3981
+ },
3982
+ parent: null
3983
+ };
3984
+ return {
3985
+ result: await option._parseAsync({
3986
+ data: ctx.data,
3987
+ path: ctx.path,
3988
+ parent: childCtx
3989
+ }),
3990
+ ctx: childCtx
3991
+ };
3992
+ })).then(handleResults);
3993
+ } else {
3994
+ let dirty = void 0;
3995
+ const issues = [];
3996
+ for (const option of options) {
3997
+ const childCtx = {
3998
+ ...ctx,
3999
+ common: {
4000
+ ...ctx.common,
4001
+ issues: []
4002
+ },
4003
+ parent: null
4004
+ };
4005
+ const result = option._parseSync({
4006
+ data: ctx.data,
4007
+ path: ctx.path,
4008
+ parent: childCtx
4009
+ });
4010
+ if (result.status === "valid") {
4011
+ return result;
4012
+ } else if (result.status === "dirty" && !dirty) {
4013
+ dirty = { result, ctx: childCtx };
4014
+ }
4015
+ if (childCtx.common.issues.length) {
4016
+ issues.push(childCtx.common.issues);
4017
+ }
4018
+ }
4019
+ if (dirty) {
4020
+ ctx.common.issues.push(...dirty.ctx.common.issues);
4021
+ return dirty.result;
4022
+ }
4023
+ const unionErrors = issues.map((issues2) => new ZodError(issues2));
4024
+ addIssueToContext(ctx, {
4025
+ code: ZodIssueCode.invalid_union,
4026
+ unionErrors
4027
+ });
4028
+ return INVALID;
4029
+ }
4030
+ }
4031
+ get options() {
4032
+ return this._def.options;
4033
+ }
4034
+ };
4035
+ ZodUnion.create = (types, params) => {
4036
+ return new ZodUnion({
4037
+ options: types,
4038
+ typeName: ZodFirstPartyTypeKind.ZodUnion,
4039
+ ...processCreateParams(params)
4040
+ });
4041
+ };
4042
+ var getDiscriminator = (type) => {
4043
+ if (type instanceof ZodLazy) {
4044
+ return getDiscriminator(type.schema);
4045
+ } else if (type instanceof ZodEffects) {
4046
+ return getDiscriminator(type.innerType());
4047
+ } else if (type instanceof ZodLiteral) {
4048
+ return [type.value];
4049
+ } else if (type instanceof ZodEnum) {
4050
+ return type.options;
4051
+ } else if (type instanceof ZodNativeEnum) {
4052
+ return util.objectValues(type.enum);
4053
+ } else if (type instanceof ZodDefault) {
4054
+ return getDiscriminator(type._def.innerType);
4055
+ } else if (type instanceof ZodUndefined) {
4056
+ return [void 0];
4057
+ } else if (type instanceof ZodNull) {
4058
+ return [null];
4059
+ } else if (type instanceof ZodOptional) {
4060
+ return [void 0, ...getDiscriminator(type.unwrap())];
4061
+ } else if (type instanceof ZodNullable) {
4062
+ return [null, ...getDiscriminator(type.unwrap())];
4063
+ } else if (type instanceof ZodBranded) {
4064
+ return getDiscriminator(type.unwrap());
4065
+ } else if (type instanceof ZodReadonly) {
4066
+ return getDiscriminator(type.unwrap());
4067
+ } else if (type instanceof ZodCatch) {
4068
+ return getDiscriminator(type._def.innerType);
4069
+ } else {
4070
+ return [];
4071
+ }
4072
+ };
4073
+ var ZodDiscriminatedUnion = class _ZodDiscriminatedUnion extends ZodType {
4074
+ _parse(input) {
4075
+ const { ctx } = this._processInputParams(input);
4076
+ if (ctx.parsedType !== ZodParsedType.object) {
4077
+ addIssueToContext(ctx, {
4078
+ code: ZodIssueCode.invalid_type,
4079
+ expected: ZodParsedType.object,
4080
+ received: ctx.parsedType
4081
+ });
4082
+ return INVALID;
4083
+ }
4084
+ const discriminator = this.discriminator;
4085
+ const discriminatorValue = ctx.data[discriminator];
4086
+ const option = this.optionsMap.get(discriminatorValue);
4087
+ if (!option) {
4088
+ addIssueToContext(ctx, {
4089
+ code: ZodIssueCode.invalid_union_discriminator,
4090
+ options: Array.from(this.optionsMap.keys()),
4091
+ path: [discriminator]
4092
+ });
4093
+ return INVALID;
4094
+ }
4095
+ if (ctx.common.async) {
4096
+ return option._parseAsync({
4097
+ data: ctx.data,
4098
+ path: ctx.path,
4099
+ parent: ctx
4100
+ });
4101
+ } else {
4102
+ return option._parseSync({
4103
+ data: ctx.data,
4104
+ path: ctx.path,
4105
+ parent: ctx
4106
+ });
4107
+ }
4108
+ }
4109
+ get discriminator() {
4110
+ return this._def.discriminator;
4111
+ }
4112
+ get options() {
4113
+ return this._def.options;
4114
+ }
4115
+ get optionsMap() {
4116
+ return this._def.optionsMap;
4117
+ }
4118
+ /**
4119
+ * The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
4120
+ * However, it only allows a union of objects, all of which need to share a discriminator property. This property must
4121
+ * have a different value for each object in the union.
4122
+ * @param discriminator the name of the discriminator property
4123
+ * @param types an array of object schemas
4124
+ * @param params
4125
+ */
4126
+ static create(discriminator, options, params) {
4127
+ const optionsMap = /* @__PURE__ */ new Map();
4128
+ for (const type of options) {
4129
+ const discriminatorValues = getDiscriminator(type.shape[discriminator]);
4130
+ if (!discriminatorValues.length) {
4131
+ throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
4132
+ }
4133
+ for (const value of discriminatorValues) {
4134
+ if (optionsMap.has(value)) {
4135
+ throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
4136
+ }
4137
+ optionsMap.set(value, type);
4138
+ }
4139
+ }
4140
+ return new _ZodDiscriminatedUnion({
4141
+ typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
4142
+ discriminator,
4143
+ options,
4144
+ optionsMap,
4145
+ ...processCreateParams(params)
4146
+ });
4147
+ }
4148
+ };
4149
+ function mergeValues(a, b) {
4150
+ const aType = getParsedType(a);
4151
+ const bType = getParsedType(b);
4152
+ if (a === b) {
4153
+ return { valid: true, data: a };
4154
+ } else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
4155
+ const bKeys = util.objectKeys(b);
4156
+ const sharedKeys = util.objectKeys(a).filter((key) => bKeys.indexOf(key) !== -1);
4157
+ const newObj = { ...a, ...b };
4158
+ for (const key of sharedKeys) {
4159
+ const sharedValue = mergeValues(a[key], b[key]);
4160
+ if (!sharedValue.valid) {
4161
+ return { valid: false };
4162
+ }
4163
+ newObj[key] = sharedValue.data;
4164
+ }
4165
+ return { valid: true, data: newObj };
4166
+ } else if (aType === ZodParsedType.array && bType === ZodParsedType.array) {
4167
+ if (a.length !== b.length) {
4168
+ return { valid: false };
4169
+ }
4170
+ const newArray = [];
4171
+ for (let index = 0; index < a.length; index++) {
4172
+ const itemA = a[index];
4173
+ const itemB = b[index];
4174
+ const sharedValue = mergeValues(itemA, itemB);
4175
+ if (!sharedValue.valid) {
4176
+ return { valid: false };
4177
+ }
4178
+ newArray.push(sharedValue.data);
4179
+ }
4180
+ return { valid: true, data: newArray };
4181
+ } else if (aType === ZodParsedType.date && bType === ZodParsedType.date && +a === +b) {
4182
+ return { valid: true, data: a };
4183
+ } else {
4184
+ return { valid: false };
4185
+ }
4186
+ }
4187
+ var ZodIntersection = class extends ZodType {
4188
+ _parse(input) {
4189
+ const { status, ctx } = this._processInputParams(input);
4190
+ const handleParsed = (parsedLeft, parsedRight) => {
4191
+ if (isAborted(parsedLeft) || isAborted(parsedRight)) {
4192
+ return INVALID;
4193
+ }
4194
+ const merged = mergeValues(parsedLeft.value, parsedRight.value);
4195
+ if (!merged.valid) {
4196
+ addIssueToContext(ctx, {
4197
+ code: ZodIssueCode.invalid_intersection_types
4198
+ });
4199
+ return INVALID;
4200
+ }
4201
+ if (isDirty(parsedLeft) || isDirty(parsedRight)) {
4202
+ status.dirty();
4203
+ }
4204
+ return { status: status.value, value: merged.data };
4205
+ };
4206
+ if (ctx.common.async) {
4207
+ return Promise.all([
4208
+ this._def.left._parseAsync({
4209
+ data: ctx.data,
4210
+ path: ctx.path,
4211
+ parent: ctx
4212
+ }),
4213
+ this._def.right._parseAsync({
4214
+ data: ctx.data,
4215
+ path: ctx.path,
4216
+ parent: ctx
4217
+ })
4218
+ ]).then(([left, right]) => handleParsed(left, right));
4219
+ } else {
4220
+ return handleParsed(this._def.left._parseSync({
4221
+ data: ctx.data,
4222
+ path: ctx.path,
4223
+ parent: ctx
4224
+ }), this._def.right._parseSync({
4225
+ data: ctx.data,
4226
+ path: ctx.path,
4227
+ parent: ctx
4228
+ }));
4229
+ }
4230
+ }
4231
+ };
4232
+ ZodIntersection.create = (left, right, params) => {
4233
+ return new ZodIntersection({
4234
+ left,
4235
+ right,
4236
+ typeName: ZodFirstPartyTypeKind.ZodIntersection,
4237
+ ...processCreateParams(params)
4238
+ });
4239
+ };
4240
+ var ZodTuple = class _ZodTuple extends ZodType {
4241
+ _parse(input) {
4242
+ const { status, ctx } = this._processInputParams(input);
4243
+ if (ctx.parsedType !== ZodParsedType.array) {
4244
+ addIssueToContext(ctx, {
4245
+ code: ZodIssueCode.invalid_type,
4246
+ expected: ZodParsedType.array,
4247
+ received: ctx.parsedType
4248
+ });
4249
+ return INVALID;
4250
+ }
4251
+ if (ctx.data.length < this._def.items.length) {
4252
+ addIssueToContext(ctx, {
4253
+ code: ZodIssueCode.too_small,
4254
+ minimum: this._def.items.length,
4255
+ inclusive: true,
4256
+ exact: false,
4257
+ type: "array"
4258
+ });
4259
+ return INVALID;
4260
+ }
4261
+ const rest = this._def.rest;
4262
+ if (!rest && ctx.data.length > this._def.items.length) {
4263
+ addIssueToContext(ctx, {
4264
+ code: ZodIssueCode.too_big,
4265
+ maximum: this._def.items.length,
4266
+ inclusive: true,
4267
+ exact: false,
4268
+ type: "array"
4269
+ });
4270
+ status.dirty();
4271
+ }
4272
+ const items = [...ctx.data].map((item, itemIndex) => {
4273
+ const schema = this._def.items[itemIndex] || this._def.rest;
4274
+ if (!schema)
4275
+ return null;
4276
+ return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
4277
+ }).filter((x) => !!x);
4278
+ if (ctx.common.async) {
4279
+ return Promise.all(items).then((results) => {
4280
+ return ParseStatus.mergeArray(status, results);
4281
+ });
4282
+ } else {
4283
+ return ParseStatus.mergeArray(status, items);
4284
+ }
4285
+ }
4286
+ get items() {
4287
+ return this._def.items;
4288
+ }
4289
+ rest(rest) {
4290
+ return new _ZodTuple({
4291
+ ...this._def,
4292
+ rest
4293
+ });
4294
+ }
4295
+ };
4296
+ ZodTuple.create = (schemas, params) => {
4297
+ if (!Array.isArray(schemas)) {
4298
+ throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
4299
+ }
4300
+ return new ZodTuple({
4301
+ items: schemas,
4302
+ typeName: ZodFirstPartyTypeKind.ZodTuple,
4303
+ rest: null,
4304
+ ...processCreateParams(params)
4305
+ });
4306
+ };
4307
+ var ZodRecord = class _ZodRecord extends ZodType {
4308
+ get keySchema() {
4309
+ return this._def.keyType;
4310
+ }
4311
+ get valueSchema() {
4312
+ return this._def.valueType;
4313
+ }
4314
+ _parse(input) {
4315
+ const { status, ctx } = this._processInputParams(input);
4316
+ if (ctx.parsedType !== ZodParsedType.object) {
4317
+ addIssueToContext(ctx, {
4318
+ code: ZodIssueCode.invalid_type,
4319
+ expected: ZodParsedType.object,
4320
+ received: ctx.parsedType
4321
+ });
4322
+ return INVALID;
4323
+ }
4324
+ const pairs = [];
4325
+ const keyType = this._def.keyType;
4326
+ const valueType = this._def.valueType;
4327
+ for (const key in ctx.data) {
4328
+ pairs.push({
4329
+ key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
4330
+ value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
4331
+ alwaysSet: key in ctx.data
4332
+ });
4333
+ }
4334
+ if (ctx.common.async) {
4335
+ return ParseStatus.mergeObjectAsync(status, pairs);
4336
+ } else {
4337
+ return ParseStatus.mergeObjectSync(status, pairs);
4338
+ }
4339
+ }
4340
+ get element() {
4341
+ return this._def.valueType;
4342
+ }
4343
+ static create(first, second, third) {
4344
+ if (second instanceof ZodType) {
4345
+ return new _ZodRecord({
4346
+ keyType: first,
4347
+ valueType: second,
4348
+ typeName: ZodFirstPartyTypeKind.ZodRecord,
4349
+ ...processCreateParams(third)
4350
+ });
4351
+ }
4352
+ return new _ZodRecord({
4353
+ keyType: ZodString.create(),
4354
+ valueType: first,
4355
+ typeName: ZodFirstPartyTypeKind.ZodRecord,
4356
+ ...processCreateParams(second)
4357
+ });
4358
+ }
4359
+ };
4360
+ var ZodMap = class extends ZodType {
4361
+ get keySchema() {
4362
+ return this._def.keyType;
4363
+ }
4364
+ get valueSchema() {
4365
+ return this._def.valueType;
4366
+ }
4367
+ _parse(input) {
4368
+ const { status, ctx } = this._processInputParams(input);
4369
+ if (ctx.parsedType !== ZodParsedType.map) {
4370
+ addIssueToContext(ctx, {
4371
+ code: ZodIssueCode.invalid_type,
4372
+ expected: ZodParsedType.map,
4373
+ received: ctx.parsedType
4374
+ });
4375
+ return INVALID;
4376
+ }
4377
+ const keyType = this._def.keyType;
4378
+ const valueType = this._def.valueType;
4379
+ const pairs = [...ctx.data.entries()].map(([key, value], index) => {
4380
+ return {
4381
+ key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index, "key"])),
4382
+ value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index, "value"]))
4383
+ };
4384
+ });
4385
+ if (ctx.common.async) {
4386
+ const finalMap = /* @__PURE__ */ new Map();
4387
+ return Promise.resolve().then(async () => {
4388
+ for (const pair of pairs) {
4389
+ const key = await pair.key;
4390
+ const value = await pair.value;
4391
+ if (key.status === "aborted" || value.status === "aborted") {
4392
+ return INVALID;
4393
+ }
4394
+ if (key.status === "dirty" || value.status === "dirty") {
4395
+ status.dirty();
4396
+ }
4397
+ finalMap.set(key.value, value.value);
4398
+ }
4399
+ return { status: status.value, value: finalMap };
4400
+ });
4401
+ } else {
4402
+ const finalMap = /* @__PURE__ */ new Map();
4403
+ for (const pair of pairs) {
4404
+ const key = pair.key;
4405
+ const value = pair.value;
4406
+ if (key.status === "aborted" || value.status === "aborted") {
4407
+ return INVALID;
4408
+ }
4409
+ if (key.status === "dirty" || value.status === "dirty") {
4410
+ status.dirty();
4411
+ }
4412
+ finalMap.set(key.value, value.value);
4413
+ }
4414
+ return { status: status.value, value: finalMap };
4415
+ }
4416
+ }
4417
+ };
4418
+ ZodMap.create = (keyType, valueType, params) => {
4419
+ return new ZodMap({
4420
+ valueType,
4421
+ keyType,
4422
+ typeName: ZodFirstPartyTypeKind.ZodMap,
4423
+ ...processCreateParams(params)
4424
+ });
4425
+ };
4426
+ var ZodSet = class _ZodSet extends ZodType {
4427
+ _parse(input) {
4428
+ const { status, ctx } = this._processInputParams(input);
4429
+ if (ctx.parsedType !== ZodParsedType.set) {
4430
+ addIssueToContext(ctx, {
4431
+ code: ZodIssueCode.invalid_type,
4432
+ expected: ZodParsedType.set,
4433
+ received: ctx.parsedType
4434
+ });
4435
+ return INVALID;
4436
+ }
4437
+ const def = this._def;
4438
+ if (def.minSize !== null) {
4439
+ if (ctx.data.size < def.minSize.value) {
4440
+ addIssueToContext(ctx, {
4441
+ code: ZodIssueCode.too_small,
4442
+ minimum: def.minSize.value,
4443
+ type: "set",
4444
+ inclusive: true,
4445
+ exact: false,
4446
+ message: def.minSize.message
4447
+ });
4448
+ status.dirty();
4449
+ }
4450
+ }
4451
+ if (def.maxSize !== null) {
4452
+ if (ctx.data.size > def.maxSize.value) {
4453
+ addIssueToContext(ctx, {
4454
+ code: ZodIssueCode.too_big,
4455
+ maximum: def.maxSize.value,
4456
+ type: "set",
4457
+ inclusive: true,
4458
+ exact: false,
4459
+ message: def.maxSize.message
4460
+ });
4461
+ status.dirty();
4462
+ }
4463
+ }
4464
+ const valueType = this._def.valueType;
4465
+ function finalizeSet(elements2) {
4466
+ const parsedSet = /* @__PURE__ */ new Set();
4467
+ for (const element of elements2) {
4468
+ if (element.status === "aborted")
4469
+ return INVALID;
4470
+ if (element.status === "dirty")
4471
+ status.dirty();
4472
+ parsedSet.add(element.value);
4473
+ }
4474
+ return { status: status.value, value: parsedSet };
4475
+ }
4476
+ const elements = [...ctx.data.values()].map((item, i) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
4477
+ if (ctx.common.async) {
4478
+ return Promise.all(elements).then((elements2) => finalizeSet(elements2));
4479
+ } else {
4480
+ return finalizeSet(elements);
4481
+ }
4482
+ }
4483
+ min(minSize, message) {
4484
+ return new _ZodSet({
4485
+ ...this._def,
4486
+ minSize: { value: minSize, message: errorUtil.toString(message) }
4487
+ });
4488
+ }
4489
+ max(maxSize, message) {
4490
+ return new _ZodSet({
4491
+ ...this._def,
4492
+ maxSize: { value: maxSize, message: errorUtil.toString(message) }
4493
+ });
4494
+ }
4495
+ size(size, message) {
4496
+ return this.min(size, message).max(size, message);
4497
+ }
4498
+ nonempty(message) {
4499
+ return this.min(1, message);
4500
+ }
4501
+ };
4502
+ ZodSet.create = (valueType, params) => {
4503
+ return new ZodSet({
4504
+ valueType,
4505
+ minSize: null,
4506
+ maxSize: null,
4507
+ typeName: ZodFirstPartyTypeKind.ZodSet,
4508
+ ...processCreateParams(params)
4509
+ });
4510
+ };
4511
+ var ZodFunction = class _ZodFunction extends ZodType {
4512
+ constructor() {
4513
+ super(...arguments);
4514
+ this.validate = this.implement;
4515
+ }
4516
+ _parse(input) {
4517
+ const { ctx } = this._processInputParams(input);
4518
+ if (ctx.parsedType !== ZodParsedType.function) {
4519
+ addIssueToContext(ctx, {
4520
+ code: ZodIssueCode.invalid_type,
4521
+ expected: ZodParsedType.function,
4522
+ received: ctx.parsedType
4523
+ });
4524
+ return INVALID;
4525
+ }
4526
+ function makeArgsIssue(args, error) {
4527
+ return makeIssue({
4528
+ data: args,
4529
+ path: ctx.path,
4530
+ errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), en_default].filter((x) => !!x),
4531
+ issueData: {
4532
+ code: ZodIssueCode.invalid_arguments,
4533
+ argumentsError: error
4534
+ }
4535
+ });
4536
+ }
4537
+ function makeReturnsIssue(returns, error) {
4538
+ return makeIssue({
4539
+ data: returns,
4540
+ path: ctx.path,
4541
+ errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), en_default].filter((x) => !!x),
4542
+ issueData: {
4543
+ code: ZodIssueCode.invalid_return_type,
4544
+ returnTypeError: error
4545
+ }
4546
+ });
4547
+ }
4548
+ const params = { errorMap: ctx.common.contextualErrorMap };
4549
+ const fn = ctx.data;
4550
+ if (this._def.returns instanceof ZodPromise) {
4551
+ const me = this;
4552
+ return OK(async function(...args) {
4553
+ const error = new ZodError([]);
4554
+ const parsedArgs = await me._def.args.parseAsync(args, params).catch((e) => {
4555
+ error.addIssue(makeArgsIssue(args, e));
4556
+ throw error;
4557
+ });
4558
+ const result = await Reflect.apply(fn, this, parsedArgs);
4559
+ const parsedReturns = await me._def.returns._def.type.parseAsync(result, params).catch((e) => {
4560
+ error.addIssue(makeReturnsIssue(result, e));
4561
+ throw error;
4562
+ });
4563
+ return parsedReturns;
4564
+ });
4565
+ } else {
4566
+ const me = this;
4567
+ return OK(function(...args) {
4568
+ const parsedArgs = me._def.args.safeParse(args, params);
4569
+ if (!parsedArgs.success) {
4570
+ throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
4571
+ }
4572
+ const result = Reflect.apply(fn, this, parsedArgs.data);
4573
+ const parsedReturns = me._def.returns.safeParse(result, params);
4574
+ if (!parsedReturns.success) {
4575
+ throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
4576
+ }
4577
+ return parsedReturns.data;
4578
+ });
4579
+ }
4580
+ }
4581
+ parameters() {
4582
+ return this._def.args;
4583
+ }
4584
+ returnType() {
4585
+ return this._def.returns;
4586
+ }
4587
+ args(...items) {
4588
+ return new _ZodFunction({
4589
+ ...this._def,
4590
+ args: ZodTuple.create(items).rest(ZodUnknown.create())
4591
+ });
4592
+ }
4593
+ returns(returnType) {
4594
+ return new _ZodFunction({
4595
+ ...this._def,
4596
+ returns: returnType
4597
+ });
4598
+ }
4599
+ implement(func) {
4600
+ const validatedFunc = this.parse(func);
4601
+ return validatedFunc;
4602
+ }
4603
+ strictImplement(func) {
4604
+ const validatedFunc = this.parse(func);
4605
+ return validatedFunc;
4606
+ }
4607
+ static create(args, returns, params) {
4608
+ return new _ZodFunction({
4609
+ args: args ? args : ZodTuple.create([]).rest(ZodUnknown.create()),
4610
+ returns: returns || ZodUnknown.create(),
4611
+ typeName: ZodFirstPartyTypeKind.ZodFunction,
4612
+ ...processCreateParams(params)
4613
+ });
4614
+ }
4615
+ };
4616
+ var ZodLazy = class extends ZodType {
4617
+ get schema() {
4618
+ return this._def.getter();
4619
+ }
4620
+ _parse(input) {
4621
+ const { ctx } = this._processInputParams(input);
4622
+ const lazySchema = this._def.getter();
4623
+ return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx });
4624
+ }
4625
+ };
4626
+ ZodLazy.create = (getter, params) => {
4627
+ return new ZodLazy({
4628
+ getter,
4629
+ typeName: ZodFirstPartyTypeKind.ZodLazy,
4630
+ ...processCreateParams(params)
4631
+ });
4632
+ };
4633
+ var ZodLiteral = class extends ZodType {
4634
+ _parse(input) {
4635
+ if (input.data !== this._def.value) {
4636
+ const ctx = this._getOrReturnCtx(input);
4637
+ addIssueToContext(ctx, {
4638
+ received: ctx.data,
4639
+ code: ZodIssueCode.invalid_literal,
4640
+ expected: this._def.value
4641
+ });
4642
+ return INVALID;
4643
+ }
4644
+ return { status: "valid", value: input.data };
4645
+ }
4646
+ get value() {
4647
+ return this._def.value;
4648
+ }
4649
+ };
4650
+ ZodLiteral.create = (value, params) => {
4651
+ return new ZodLiteral({
4652
+ value,
4653
+ typeName: ZodFirstPartyTypeKind.ZodLiteral,
4654
+ ...processCreateParams(params)
4655
+ });
4656
+ };
4657
+ function createZodEnum(values, params) {
4658
+ return new ZodEnum({
4659
+ values,
4660
+ typeName: ZodFirstPartyTypeKind.ZodEnum,
4661
+ ...processCreateParams(params)
4662
+ });
4663
+ }
4664
+ var ZodEnum = class _ZodEnum extends ZodType {
4665
+ _parse(input) {
4666
+ if (typeof input.data !== "string") {
4667
+ const ctx = this._getOrReturnCtx(input);
4668
+ const expectedValues = this._def.values;
4669
+ addIssueToContext(ctx, {
4670
+ expected: util.joinValues(expectedValues),
4671
+ received: ctx.parsedType,
4672
+ code: ZodIssueCode.invalid_type
4673
+ });
4674
+ return INVALID;
4675
+ }
4676
+ if (!this._cache) {
4677
+ this._cache = new Set(this._def.values);
4678
+ }
4679
+ if (!this._cache.has(input.data)) {
4680
+ const ctx = this._getOrReturnCtx(input);
4681
+ const expectedValues = this._def.values;
4682
+ addIssueToContext(ctx, {
4683
+ received: ctx.data,
4684
+ code: ZodIssueCode.invalid_enum_value,
4685
+ options: expectedValues
4686
+ });
4687
+ return INVALID;
4688
+ }
4689
+ return OK(input.data);
4690
+ }
4691
+ get options() {
4692
+ return this._def.values;
4693
+ }
4694
+ get enum() {
4695
+ const enumValues = {};
4696
+ for (const val of this._def.values) {
4697
+ enumValues[val] = val;
4698
+ }
4699
+ return enumValues;
4700
+ }
4701
+ get Values() {
4702
+ const enumValues = {};
4703
+ for (const val of this._def.values) {
4704
+ enumValues[val] = val;
4705
+ }
4706
+ return enumValues;
4707
+ }
4708
+ get Enum() {
4709
+ const enumValues = {};
4710
+ for (const val of this._def.values) {
4711
+ enumValues[val] = val;
4712
+ }
4713
+ return enumValues;
4714
+ }
4715
+ extract(values, newDef = this._def) {
4716
+ return _ZodEnum.create(values, {
4717
+ ...this._def,
4718
+ ...newDef
4719
+ });
4720
+ }
4721
+ exclude(values, newDef = this._def) {
4722
+ return _ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
4723
+ ...this._def,
4724
+ ...newDef
4725
+ });
4726
+ }
4727
+ };
4728
+ ZodEnum.create = createZodEnum;
4729
+ var ZodNativeEnum = class extends ZodType {
4730
+ _parse(input) {
4731
+ const nativeEnumValues = util.getValidEnumValues(this._def.values);
4732
+ const ctx = this._getOrReturnCtx(input);
4733
+ if (ctx.parsedType !== ZodParsedType.string && ctx.parsedType !== ZodParsedType.number) {
4734
+ const expectedValues = util.objectValues(nativeEnumValues);
4735
+ addIssueToContext(ctx, {
4736
+ expected: util.joinValues(expectedValues),
4737
+ received: ctx.parsedType,
4738
+ code: ZodIssueCode.invalid_type
4739
+ });
4740
+ return INVALID;
4741
+ }
4742
+ if (!this._cache) {
4743
+ this._cache = new Set(util.getValidEnumValues(this._def.values));
4744
+ }
4745
+ if (!this._cache.has(input.data)) {
4746
+ const expectedValues = util.objectValues(nativeEnumValues);
4747
+ addIssueToContext(ctx, {
4748
+ received: ctx.data,
4749
+ code: ZodIssueCode.invalid_enum_value,
4750
+ options: expectedValues
4751
+ });
4752
+ return INVALID;
4753
+ }
4754
+ return OK(input.data);
4755
+ }
4756
+ get enum() {
4757
+ return this._def.values;
4758
+ }
4759
+ };
4760
+ ZodNativeEnum.create = (values, params) => {
4761
+ return new ZodNativeEnum({
4762
+ values,
4763
+ typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
4764
+ ...processCreateParams(params)
4765
+ });
4766
+ };
4767
+ var ZodPromise = class extends ZodType {
4768
+ unwrap() {
4769
+ return this._def.type;
4770
+ }
4771
+ _parse(input) {
4772
+ const { ctx } = this._processInputParams(input);
4773
+ if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === false) {
4774
+ addIssueToContext(ctx, {
4775
+ code: ZodIssueCode.invalid_type,
4776
+ expected: ZodParsedType.promise,
4777
+ received: ctx.parsedType
4778
+ });
4779
+ return INVALID;
4780
+ }
4781
+ const promisified = ctx.parsedType === ZodParsedType.promise ? ctx.data : Promise.resolve(ctx.data);
4782
+ return OK(promisified.then((data) => {
4783
+ return this._def.type.parseAsync(data, {
4784
+ path: ctx.path,
4785
+ errorMap: ctx.common.contextualErrorMap
4786
+ });
4787
+ }));
4788
+ }
4789
+ };
4790
+ ZodPromise.create = (schema, params) => {
4791
+ return new ZodPromise({
4792
+ type: schema,
4793
+ typeName: ZodFirstPartyTypeKind.ZodPromise,
4794
+ ...processCreateParams(params)
4795
+ });
4796
+ };
4797
+ var ZodEffects = class extends ZodType {
4798
+ innerType() {
4799
+ return this._def.schema;
4800
+ }
4801
+ sourceType() {
4802
+ return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects ? this._def.schema.sourceType() : this._def.schema;
4803
+ }
4804
+ _parse(input) {
4805
+ const { status, ctx } = this._processInputParams(input);
4806
+ const effect = this._def.effect || null;
4807
+ const checkCtx = {
4808
+ addIssue: (arg) => {
4809
+ addIssueToContext(ctx, arg);
4810
+ if (arg.fatal) {
4811
+ status.abort();
4812
+ } else {
4813
+ status.dirty();
4814
+ }
4815
+ },
4816
+ get path() {
4817
+ return ctx.path;
4818
+ }
4819
+ };
4820
+ checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
4821
+ if (effect.type === "preprocess") {
4822
+ const processed = effect.transform(ctx.data, checkCtx);
4823
+ if (ctx.common.async) {
4824
+ return Promise.resolve(processed).then(async (processed2) => {
4825
+ if (status.value === "aborted")
4826
+ return INVALID;
4827
+ const result = await this._def.schema._parseAsync({
4828
+ data: processed2,
4829
+ path: ctx.path,
4830
+ parent: ctx
4831
+ });
4832
+ if (result.status === "aborted")
4833
+ return INVALID;
4834
+ if (result.status === "dirty")
4835
+ return DIRTY(result.value);
4836
+ if (status.value === "dirty")
4837
+ return DIRTY(result.value);
4838
+ return result;
4839
+ });
4840
+ } else {
4841
+ if (status.value === "aborted")
4842
+ return INVALID;
4843
+ const result = this._def.schema._parseSync({
4844
+ data: processed,
4845
+ path: ctx.path,
4846
+ parent: ctx
4847
+ });
4848
+ if (result.status === "aborted")
4849
+ return INVALID;
4850
+ if (result.status === "dirty")
4851
+ return DIRTY(result.value);
4852
+ if (status.value === "dirty")
4853
+ return DIRTY(result.value);
4854
+ return result;
4855
+ }
4856
+ }
4857
+ if (effect.type === "refinement") {
4858
+ const executeRefinement = (acc) => {
4859
+ const result = effect.refinement(acc, checkCtx);
4860
+ if (ctx.common.async) {
4861
+ return Promise.resolve(result);
4862
+ }
4863
+ if (result instanceof Promise) {
4864
+ throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
4865
+ }
4866
+ return acc;
4867
+ };
4868
+ if (ctx.common.async === false) {
4869
+ const inner = this._def.schema._parseSync({
4870
+ data: ctx.data,
4871
+ path: ctx.path,
4872
+ parent: ctx
4873
+ });
4874
+ if (inner.status === "aborted")
4875
+ return INVALID;
4876
+ if (inner.status === "dirty")
4877
+ status.dirty();
4878
+ executeRefinement(inner.value);
4879
+ return { status: status.value, value: inner.value };
4880
+ } else {
4881
+ return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((inner) => {
4882
+ if (inner.status === "aborted")
4883
+ return INVALID;
4884
+ if (inner.status === "dirty")
4885
+ status.dirty();
4886
+ return executeRefinement(inner.value).then(() => {
4887
+ return { status: status.value, value: inner.value };
4888
+ });
4889
+ });
4890
+ }
4891
+ }
4892
+ if (effect.type === "transform") {
4893
+ if (ctx.common.async === false) {
4894
+ const base = this._def.schema._parseSync({
4895
+ data: ctx.data,
4896
+ path: ctx.path,
4897
+ parent: ctx
4898
+ });
4899
+ if (!isValid(base))
4900
+ return INVALID;
4901
+ const result = effect.transform(base.value, checkCtx);
4902
+ if (result instanceof Promise) {
4903
+ throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
4904
+ }
4905
+ return { status: status.value, value: result };
4906
+ } else {
4907
+ return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((base) => {
4908
+ if (!isValid(base))
4909
+ return INVALID;
4910
+ return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({
4911
+ status: status.value,
4912
+ value: result
4913
+ }));
4914
+ });
4915
+ }
4916
+ }
4917
+ util.assertNever(effect);
4918
+ }
4919
+ };
4920
+ ZodEffects.create = (schema, effect, params) => {
4921
+ return new ZodEffects({
4922
+ schema,
4923
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
4924
+ effect,
4925
+ ...processCreateParams(params)
4926
+ });
4927
+ };
4928
+ ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
4929
+ return new ZodEffects({
4930
+ schema,
4931
+ effect: { type: "preprocess", transform: preprocess },
4932
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
4933
+ ...processCreateParams(params)
4934
+ });
4935
+ };
4936
+ var ZodOptional = class extends ZodType {
4937
+ _parse(input) {
4938
+ const parsedType = this._getType(input);
4939
+ if (parsedType === ZodParsedType.undefined) {
4940
+ return OK(void 0);
4941
+ }
4942
+ return this._def.innerType._parse(input);
4943
+ }
4944
+ unwrap() {
4945
+ return this._def.innerType;
4946
+ }
4947
+ };
4948
+ ZodOptional.create = (type, params) => {
4949
+ return new ZodOptional({
4950
+ innerType: type,
4951
+ typeName: ZodFirstPartyTypeKind.ZodOptional,
4952
+ ...processCreateParams(params)
4953
+ });
4954
+ };
4955
+ var ZodNullable = class extends ZodType {
4956
+ _parse(input) {
4957
+ const parsedType = this._getType(input);
4958
+ if (parsedType === ZodParsedType.null) {
4959
+ return OK(null);
4960
+ }
4961
+ return this._def.innerType._parse(input);
4962
+ }
4963
+ unwrap() {
4964
+ return this._def.innerType;
4965
+ }
4966
+ };
4967
+ ZodNullable.create = (type, params) => {
4968
+ return new ZodNullable({
4969
+ innerType: type,
4970
+ typeName: ZodFirstPartyTypeKind.ZodNullable,
4971
+ ...processCreateParams(params)
4972
+ });
4973
+ };
4974
+ var ZodDefault = class extends ZodType {
4975
+ _parse(input) {
4976
+ const { ctx } = this._processInputParams(input);
4977
+ let data = ctx.data;
4978
+ if (ctx.parsedType === ZodParsedType.undefined) {
4979
+ data = this._def.defaultValue();
4980
+ }
4981
+ return this._def.innerType._parse({
4982
+ data,
4983
+ path: ctx.path,
4984
+ parent: ctx
4985
+ });
4986
+ }
4987
+ removeDefault() {
4988
+ return this._def.innerType;
4989
+ }
4990
+ };
4991
+ ZodDefault.create = (type, params) => {
4992
+ return new ZodDefault({
4993
+ innerType: type,
4994
+ typeName: ZodFirstPartyTypeKind.ZodDefault,
4995
+ defaultValue: typeof params.default === "function" ? params.default : () => params.default,
4996
+ ...processCreateParams(params)
4997
+ });
4998
+ };
4999
+ var ZodCatch = class extends ZodType {
5000
+ _parse(input) {
5001
+ const { ctx } = this._processInputParams(input);
5002
+ const newCtx = {
5003
+ ...ctx,
5004
+ common: {
5005
+ ...ctx.common,
5006
+ issues: []
5007
+ }
5008
+ };
5009
+ const result = this._def.innerType._parse({
5010
+ data: newCtx.data,
5011
+ path: newCtx.path,
5012
+ parent: {
5013
+ ...newCtx
5014
+ }
5015
+ });
5016
+ if (isAsync(result)) {
5017
+ return result.then((result2) => {
5018
+ return {
5019
+ status: "valid",
5020
+ value: result2.status === "valid" ? result2.value : this._def.catchValue({
5021
+ get error() {
5022
+ return new ZodError(newCtx.common.issues);
5023
+ },
5024
+ input: newCtx.data
5025
+ })
5026
+ };
5027
+ });
5028
+ } else {
5029
+ return {
5030
+ status: "valid",
5031
+ value: result.status === "valid" ? result.value : this._def.catchValue({
5032
+ get error() {
5033
+ return new ZodError(newCtx.common.issues);
5034
+ },
5035
+ input: newCtx.data
5036
+ })
5037
+ };
5038
+ }
5039
+ }
5040
+ removeCatch() {
5041
+ return this._def.innerType;
5042
+ }
5043
+ };
5044
+ ZodCatch.create = (type, params) => {
5045
+ return new ZodCatch({
5046
+ innerType: type,
5047
+ typeName: ZodFirstPartyTypeKind.ZodCatch,
5048
+ catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
5049
+ ...processCreateParams(params)
5050
+ });
5051
+ };
5052
+ var ZodNaN = class extends ZodType {
5053
+ _parse(input) {
5054
+ const parsedType = this._getType(input);
5055
+ if (parsedType !== ZodParsedType.nan) {
5056
+ const ctx = this._getOrReturnCtx(input);
5057
+ addIssueToContext(ctx, {
5058
+ code: ZodIssueCode.invalid_type,
5059
+ expected: ZodParsedType.nan,
5060
+ received: ctx.parsedType
5061
+ });
5062
+ return INVALID;
5063
+ }
5064
+ return { status: "valid", value: input.data };
5065
+ }
5066
+ };
5067
+ ZodNaN.create = (params) => {
5068
+ return new ZodNaN({
5069
+ typeName: ZodFirstPartyTypeKind.ZodNaN,
5070
+ ...processCreateParams(params)
5071
+ });
5072
+ };
5073
+ var BRAND = /* @__PURE__ */ Symbol("zod_brand");
5074
+ var ZodBranded = class extends ZodType {
5075
+ _parse(input) {
5076
+ const { ctx } = this._processInputParams(input);
5077
+ const data = ctx.data;
5078
+ return this._def.type._parse({
5079
+ data,
5080
+ path: ctx.path,
5081
+ parent: ctx
5082
+ });
5083
+ }
5084
+ unwrap() {
5085
+ return this._def.type;
5086
+ }
5087
+ };
5088
+ var ZodPipeline = class _ZodPipeline extends ZodType {
5089
+ _parse(input) {
5090
+ const { status, ctx } = this._processInputParams(input);
5091
+ if (ctx.common.async) {
5092
+ const handleAsync = async () => {
5093
+ const inResult = await this._def.in._parseAsync({
5094
+ data: ctx.data,
5095
+ path: ctx.path,
5096
+ parent: ctx
5097
+ });
5098
+ if (inResult.status === "aborted")
5099
+ return INVALID;
5100
+ if (inResult.status === "dirty") {
5101
+ status.dirty();
5102
+ return DIRTY(inResult.value);
5103
+ } else {
5104
+ return this._def.out._parseAsync({
5105
+ data: inResult.value,
5106
+ path: ctx.path,
5107
+ parent: ctx
5108
+ });
5109
+ }
5110
+ };
5111
+ return handleAsync();
5112
+ } else {
5113
+ const inResult = this._def.in._parseSync({
5114
+ data: ctx.data,
5115
+ path: ctx.path,
5116
+ parent: ctx
5117
+ });
5118
+ if (inResult.status === "aborted")
5119
+ return INVALID;
5120
+ if (inResult.status === "dirty") {
5121
+ status.dirty();
5122
+ return {
5123
+ status: "dirty",
5124
+ value: inResult.value
5125
+ };
5126
+ } else {
5127
+ return this._def.out._parseSync({
5128
+ data: inResult.value,
5129
+ path: ctx.path,
5130
+ parent: ctx
5131
+ });
5132
+ }
5133
+ }
5134
+ }
5135
+ static create(a, b) {
5136
+ return new _ZodPipeline({
5137
+ in: a,
5138
+ out: b,
5139
+ typeName: ZodFirstPartyTypeKind.ZodPipeline
5140
+ });
5141
+ }
5142
+ };
5143
+ var ZodReadonly = class extends ZodType {
5144
+ _parse(input) {
5145
+ const result = this._def.innerType._parse(input);
5146
+ const freeze = (data) => {
5147
+ if (isValid(data)) {
5148
+ data.value = Object.freeze(data.value);
5149
+ }
5150
+ return data;
5151
+ };
5152
+ return isAsync(result) ? result.then((data) => freeze(data)) : freeze(result);
5153
+ }
5154
+ unwrap() {
5155
+ return this._def.innerType;
5156
+ }
5157
+ };
5158
+ ZodReadonly.create = (type, params) => {
5159
+ return new ZodReadonly({
5160
+ innerType: type,
5161
+ typeName: ZodFirstPartyTypeKind.ZodReadonly,
5162
+ ...processCreateParams(params)
5163
+ });
5164
+ };
5165
+ function cleanParams(params, data) {
5166
+ const p = typeof params === "function" ? params(data) : typeof params === "string" ? { message: params } : params;
5167
+ const p2 = typeof p === "string" ? { message: p } : p;
5168
+ return p2;
5169
+ }
5170
+ function custom(check, _params = {}, fatal) {
5171
+ if (check)
5172
+ return ZodAny.create().superRefine((data, ctx) => {
5173
+ const r = check(data);
5174
+ if (r instanceof Promise) {
5175
+ return r.then((r2) => {
5176
+ if (!r2) {
5177
+ const params = cleanParams(_params, data);
5178
+ const _fatal = params.fatal ?? fatal ?? true;
5179
+ ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
5180
+ }
5181
+ });
5182
+ }
5183
+ if (!r) {
5184
+ const params = cleanParams(_params, data);
5185
+ const _fatal = params.fatal ?? fatal ?? true;
5186
+ ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
5187
+ }
5188
+ return;
5189
+ });
5190
+ return ZodAny.create();
5191
+ }
5192
+ var late = {
5193
+ object: ZodObject.lazycreate
5194
+ };
5195
+ var ZodFirstPartyTypeKind;
5196
+ (function(ZodFirstPartyTypeKind2) {
5197
+ ZodFirstPartyTypeKind2["ZodString"] = "ZodString";
5198
+ ZodFirstPartyTypeKind2["ZodNumber"] = "ZodNumber";
5199
+ ZodFirstPartyTypeKind2["ZodNaN"] = "ZodNaN";
5200
+ ZodFirstPartyTypeKind2["ZodBigInt"] = "ZodBigInt";
5201
+ ZodFirstPartyTypeKind2["ZodBoolean"] = "ZodBoolean";
5202
+ ZodFirstPartyTypeKind2["ZodDate"] = "ZodDate";
5203
+ ZodFirstPartyTypeKind2["ZodSymbol"] = "ZodSymbol";
5204
+ ZodFirstPartyTypeKind2["ZodUndefined"] = "ZodUndefined";
5205
+ ZodFirstPartyTypeKind2["ZodNull"] = "ZodNull";
5206
+ ZodFirstPartyTypeKind2["ZodAny"] = "ZodAny";
5207
+ ZodFirstPartyTypeKind2["ZodUnknown"] = "ZodUnknown";
5208
+ ZodFirstPartyTypeKind2["ZodNever"] = "ZodNever";
5209
+ ZodFirstPartyTypeKind2["ZodVoid"] = "ZodVoid";
5210
+ ZodFirstPartyTypeKind2["ZodArray"] = "ZodArray";
5211
+ ZodFirstPartyTypeKind2["ZodObject"] = "ZodObject";
5212
+ ZodFirstPartyTypeKind2["ZodUnion"] = "ZodUnion";
5213
+ ZodFirstPartyTypeKind2["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
5214
+ ZodFirstPartyTypeKind2["ZodIntersection"] = "ZodIntersection";
5215
+ ZodFirstPartyTypeKind2["ZodTuple"] = "ZodTuple";
5216
+ ZodFirstPartyTypeKind2["ZodRecord"] = "ZodRecord";
5217
+ ZodFirstPartyTypeKind2["ZodMap"] = "ZodMap";
5218
+ ZodFirstPartyTypeKind2["ZodSet"] = "ZodSet";
5219
+ ZodFirstPartyTypeKind2["ZodFunction"] = "ZodFunction";
5220
+ ZodFirstPartyTypeKind2["ZodLazy"] = "ZodLazy";
5221
+ ZodFirstPartyTypeKind2["ZodLiteral"] = "ZodLiteral";
5222
+ ZodFirstPartyTypeKind2["ZodEnum"] = "ZodEnum";
5223
+ ZodFirstPartyTypeKind2["ZodEffects"] = "ZodEffects";
5224
+ ZodFirstPartyTypeKind2["ZodNativeEnum"] = "ZodNativeEnum";
5225
+ ZodFirstPartyTypeKind2["ZodOptional"] = "ZodOptional";
5226
+ ZodFirstPartyTypeKind2["ZodNullable"] = "ZodNullable";
5227
+ ZodFirstPartyTypeKind2["ZodDefault"] = "ZodDefault";
5228
+ ZodFirstPartyTypeKind2["ZodCatch"] = "ZodCatch";
5229
+ ZodFirstPartyTypeKind2["ZodPromise"] = "ZodPromise";
5230
+ ZodFirstPartyTypeKind2["ZodBranded"] = "ZodBranded";
5231
+ ZodFirstPartyTypeKind2["ZodPipeline"] = "ZodPipeline";
5232
+ ZodFirstPartyTypeKind2["ZodReadonly"] = "ZodReadonly";
5233
+ })(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
5234
+ var instanceOfType = (cls, params = {
5235
+ message: `Input not instance of ${cls.name}`
5236
+ }) => custom((data) => data instanceof cls, params);
5237
+ var stringType = ZodString.create;
5238
+ var numberType = ZodNumber.create;
5239
+ var nanType = ZodNaN.create;
5240
+ var bigIntType = ZodBigInt.create;
5241
+ var booleanType = ZodBoolean.create;
5242
+ var dateType = ZodDate.create;
5243
+ var symbolType = ZodSymbol.create;
5244
+ var undefinedType = ZodUndefined.create;
5245
+ var nullType = ZodNull.create;
5246
+ var anyType = ZodAny.create;
5247
+ var unknownType = ZodUnknown.create;
5248
+ var neverType = ZodNever.create;
5249
+ var voidType = ZodVoid.create;
5250
+ var arrayType = ZodArray.create;
5251
+ var objectType = ZodObject.create;
5252
+ var strictObjectType = ZodObject.strictCreate;
5253
+ var unionType = ZodUnion.create;
5254
+ var discriminatedUnionType = ZodDiscriminatedUnion.create;
5255
+ var intersectionType = ZodIntersection.create;
5256
+ var tupleType = ZodTuple.create;
5257
+ var recordType = ZodRecord.create;
5258
+ var mapType = ZodMap.create;
5259
+ var setType = ZodSet.create;
5260
+ var functionType = ZodFunction.create;
5261
+ var lazyType = ZodLazy.create;
5262
+ var literalType = ZodLiteral.create;
5263
+ var enumType = ZodEnum.create;
5264
+ var nativeEnumType = ZodNativeEnum.create;
5265
+ var promiseType = ZodPromise.create;
5266
+ var effectsType = ZodEffects.create;
5267
+ var optionalType = ZodOptional.create;
5268
+ var nullableType = ZodNullable.create;
5269
+ var preprocessType = ZodEffects.createWithPreprocess;
5270
+ var pipelineType = ZodPipeline.create;
5271
+ var ostring = () => stringType().optional();
5272
+ var onumber = () => numberType().optional();
5273
+ var oboolean = () => booleanType().optional();
5274
+ var coerce = {
5275
+ string: ((arg) => ZodString.create({ ...arg, coerce: true })),
5276
+ number: ((arg) => ZodNumber.create({ ...arg, coerce: true })),
5277
+ boolean: ((arg) => ZodBoolean.create({
5278
+ ...arg,
5279
+ coerce: true
5280
+ })),
5281
+ bigint: ((arg) => ZodBigInt.create({ ...arg, coerce: true })),
5282
+ date: ((arg) => ZodDate.create({ ...arg, coerce: true }))
5283
+ };
5284
+ var NEVER = INVALID;
5285
+
5286
+ // ../core/dist/schemas/index.js
5287
+ var ProjectTypeSchema = external_exports.enum([
5288
+ "saas",
5289
+ "ai-application",
5290
+ "mcp-server",
5291
+ "blockchain",
5292
+ "wallet",
5293
+ "government-system",
5294
+ "healthcare-system",
5295
+ "event-platform",
5296
+ "photo-storage-platform",
5297
+ "vulnerability-scanner",
5298
+ "generic-web-application",
5299
+ "api-backend",
5300
+ "mobile-application"
5301
+ ]);
5302
+ var FrameworkNameSchema = external_exports.enum([
5303
+ "GDPR",
5304
+ "OWASP",
5305
+ "CIS",
5306
+ "NIST",
5307
+ "ISO27001",
5308
+ "ISO27701"
5309
+ ]);
5310
+ var DataClassificationSchema = external_exports.enum([
5311
+ "public",
5312
+ "internal",
5313
+ "confidential",
5314
+ "restricted"
5315
+ ]);
5316
+ var ControlStatusSchema = external_exports.enum([
5317
+ "pass",
5318
+ "fail",
5319
+ "warning",
5320
+ "not-applicable",
5321
+ "not-implemented"
5322
+ ]);
5323
+ var ReportFormatSchema = external_exports.enum(["markdown", "html", "pdf"]);
5324
+ var RequirementConfigSchema = external_exports.object({
5325
+ required: external_exports.boolean(),
5326
+ level: external_exports.enum(["mandatory", "recommended", "optional"]).optional(),
5327
+ notes: external_exports.string().optional()
5328
+ });
5329
+ var ProjectConfigSchema = external_exports.object({
5330
+ project_name: external_exports.string().min(1),
5331
+ project_type: ProjectTypeSchema,
5332
+ frameworks: external_exports.array(FrameworkNameSchema).min(1),
5333
+ requirements: external_exports.object({
5334
+ encryption: RequirementConfigSchema,
5335
+ mfa: RequirementConfigSchema,
5336
+ audit_logs: RequirementConfigSchema,
5337
+ backups: RequirementConfigSchema,
5338
+ retention_policy: RequirementConfigSchema,
5339
+ vulnerability_scanning: RequirementConfigSchema,
5340
+ authentication: RequirementConfigSchema,
5341
+ authorization: RequirementConfigSchema,
5342
+ secrets_management: RequirementConfigSchema,
5343
+ logging: RequirementConfigSchema,
5344
+ monitoring: RequirementConfigSchema,
5345
+ data_classification: RequirementConfigSchema,
5346
+ disaster_recovery: RequirementConfigSchema,
5347
+ incident_response: RequirementConfigSchema,
5348
+ privacy_controls: RequirementConfigSchema
5349
+ }),
5350
+ created_at: external_exports.string(),
5351
+ version: external_exports.string()
5352
+ });
5353
+ var ControlCheckSchema = external_exports.object({
5354
+ id: external_exports.string(),
5355
+ description: external_exports.string(),
5356
+ status: ControlStatusSchema,
5357
+ evidence: external_exports.string().optional()
5358
+ });
5359
+ var ControlSchema = external_exports.object({
5360
+ id: external_exports.string(),
5361
+ name: external_exports.string(),
5362
+ description: external_exports.string(),
5363
+ category: external_exports.string(),
5364
+ framework: FrameworkNameSchema,
5365
+ article: external_exports.string().optional(),
5366
+ status: ControlStatusSchema.default("not-implemented"),
5367
+ severity: external_exports.enum(["critical", "high", "medium", "low"]),
5368
+ implementation_guidance: external_exports.string(),
5369
+ checks: external_exports.array(ControlCheckSchema)
5370
+ });
5371
+ var AuditEntrySchema = external_exports.object({
5372
+ userId: external_exports.string(),
5373
+ action: external_exports.string(),
5374
+ resource: external_exports.string(),
5375
+ timestamp: external_exports.string(),
5376
+ ipAddress: external_exports.string(),
5377
+ metadata: external_exports.record(external_exports.unknown()).optional()
5378
+ });
5379
+ var ReportOptionsSchema = external_exports.object({
5380
+ format: ReportFormatSchema,
5381
+ title: external_exports.string(),
5382
+ include_executive_summary: external_exports.boolean(),
5383
+ include_risk_assessment: external_exports.boolean(),
5384
+ include_compliance: external_exports.boolean(),
5385
+ include_security: external_exports.boolean()
5386
+ });
5387
+
5388
+ // ../core/dist/constants/index.js
5389
+ import { createRequire } from "node:module";
5390
+ import * as url from "node:url";
5391
+ import * as path from "node:path";
5392
+ var __filename = url.fileURLToPath(import.meta.url);
5393
+ var __dirname = path.dirname(__filename);
5394
+ var require2 = createRequire(import.meta.url);
5395
+ var pkg = require2("../../package.json");
5396
+ var GESF_VERSION = pkg.version;
5397
+
1101
5398
  // src/server.ts
1102
5399
  var TOOLS = [
1103
5400
  {
@@ -1182,7 +5479,7 @@ function handleRequest(request) {
1182
5479
  capabilities: { tools: {} },
1183
5480
  serverInfo: {
1184
5481
  name: "gesf-mcp-server",
1185
- version: "0.3.3"
5482
+ version: GESF_VERSION
1186
5483
  }
1187
5484
  }
1188
5485
  };