@elizaos/core 1.0.0-alpha.44 → 1.0.0-alpha.46

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