drizzle-kit 0.20.16 → 0.20.17-0d9aa5f

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. package/bin.cjs +69120 -38874
  2. package/cli/commands/migrate.d.ts +123 -106
  3. package/cli/commands/mysqlIntrospect.d.ts +2 -71
  4. package/cli/commands/mysqlPushUtils.d.ts +4 -8
  5. package/cli/commands/pgIntrospect.d.ts +6 -70
  6. package/cli/commands/pgPushUtils.d.ts +3 -6
  7. package/cli/commands/sqliteIntrospect.d.ts +13 -17
  8. package/cli/commands/sqlitePushUtils.d.ts +4 -10
  9. package/cli/commands/utils.d.ts +39 -255
  10. package/cli/connections.d.ts +13 -0
  11. package/cli/utils.d.ts +13 -0
  12. package/cli/validations/cli.d.ts +169 -0
  13. package/cli/validations/common.d.ts +208 -7
  14. package/cli/validations/mysql.d.ts +6 -342
  15. package/cli/validations/outputs.d.ts +2 -0
  16. package/cli/validations/pg.d.ts +16 -408
  17. package/cli/validations/sqlite.d.ts +22 -0
  18. package/cli/views.d.ts +7 -5
  19. package/global.d.ts +3 -1
  20. package/index.d.mts +25 -17
  21. package/index.d.ts +25 -17
  22. package/index.js +1 -0
  23. package/introspect-sqlite.d.ts +2 -2
  24. package/jsonDiffer.d.ts +14 -29
  25. package/jsonStatements.d.ts +38 -11
  26. package/package.json +28 -51
  27. package/payload.d.mts +5 -5
  28. package/payload.d.ts +5 -5
  29. package/payload.js +16621 -33841
  30. package/payload.mjs +16673 -33904
  31. package/schemaValidator.d.ts +72 -69
  32. package/serializer/mysqlImports.d.ts +3 -7
  33. package/serializer/mysqlSchema.d.ts +1404 -587
  34. package/serializer/mysqlSerializer.d.ts +6 -6
  35. package/serializer/pgImports.d.ts +2 -2
  36. package/serializer/pgSchema.d.ts +1260 -801
  37. package/serializer/pgSerializer.d.ts +2 -2
  38. package/serializer/sqliteImports.d.ts +2 -4
  39. package/serializer/sqliteSchema.d.ts +144 -570
  40. package/serializer/sqliteSerializer.d.ts +4 -4
  41. package/serializer/studio.d.ts +51 -0
  42. package/snapshotsDiffer.d.ts +2334 -1057
  43. package/utils/words.d.ts +1 -1
  44. package/utils-studio.d.mts +0 -1
  45. package/utils-studio.d.ts +0 -1
  46. package/utils-studio.js +3817 -169
  47. package/utils-studio.mjs +3817 -172
  48. package/utils.d.ts +20 -141
  49. package/utils.js +3899 -7070
  50. package/utils.mjs +3972 -7143
  51. package/cli/commands/mysqlUp.d.ts +0 -4
  52. package/cli/commands/pgConnect.d.ts +0 -5
  53. package/cli/commands/pgUp.d.ts +0 -4
  54. package/cli/commands/sqliteUtils.d.ts +0 -162
  55. package/cli/commands/upFolders.d.ts +0 -27
  56. package/drivers/index.d.ts +0 -39
  57. package/introspect-mysql.d.ts +0 -9
  58. package/introspect-pg.d.ts +0 -12
package/utils-studio.mjs CHANGED
@@ -357,30 +357,30 @@ var init_supports_color = __esm({
357
357
 
358
358
  // node_modules/.pnpm/chalk@5.2.0/node_modules/chalk/source/utilities.js
359
359
  function stringReplaceAll(string, substring, replacer) {
360
- let index = string.indexOf(substring);
361
- if (index === -1) {
360
+ let index4 = string.indexOf(substring);
361
+ if (index4 === -1) {
362
362
  return string;
363
363
  }
364
364
  const substringLength = substring.length;
365
365
  let endIndex = 0;
366
366
  let returnValue = "";
367
367
  do {
368
- returnValue += string.slice(endIndex, index) + substring + replacer;
369
- endIndex = index + substringLength;
370
- index = string.indexOf(substring, endIndex);
371
- } while (index !== -1);
368
+ returnValue += string.slice(endIndex, index4) + substring + replacer;
369
+ endIndex = index4 + substringLength;
370
+ index4 = string.indexOf(substring, endIndex);
371
+ } while (index4 !== -1);
372
372
  returnValue += string.slice(endIndex);
373
373
  return returnValue;
374
374
  }
375
- function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {
375
+ function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index4) {
376
376
  let endIndex = 0;
377
377
  let returnValue = "";
378
378
  do {
379
- const gotCR = string[index - 1] === "\r";
380
- returnValue += string.slice(endIndex, gotCR ? index - 1 : index) + prefix + (gotCR ? "\r\n" : "\n") + postfix;
381
- endIndex = index + 1;
382
- index = string.indexOf("\n", endIndex);
383
- } while (index !== -1);
379
+ const gotCR = string[index4 - 1] === "\r";
380
+ returnValue += string.slice(endIndex, gotCR ? index4 - 1 : index4) + prefix + (gotCR ? "\r\n" : "\n") + postfix;
381
+ endIndex = index4 + 1;
382
+ index4 = string.indexOf("\n", endIndex);
383
+ } while (index4 !== -1);
384
384
  returnValue += string.slice(endIndex);
385
385
  return returnValue;
386
386
  }
@@ -1056,7 +1056,7 @@ var require_hanji = __commonJS({
1056
1056
  return;
1057
1057
  }
1058
1058
  exports.render = render2;
1059
- function renderWithTask3(view, task) {
1059
+ function renderWithTask2(view, task) {
1060
1060
  return __awaiter(this, void 0, void 0, function* () {
1061
1061
  const terminal = new TaskTerminal(view, process.stdout);
1062
1062
  terminal.requestLayout();
@@ -1065,7 +1065,7 @@ var require_hanji = __commonJS({
1065
1065
  return result;
1066
1066
  });
1067
1067
  }
1068
- exports.renderWithTask = renderWithTask3;
1068
+ exports.renderWithTask = renderWithTask2;
1069
1069
  var terminateHandler;
1070
1070
  function onTerminate(callback) {
1071
1071
  terminateHandler = callback;
@@ -1074,12 +1074,3696 @@ var require_hanji = __commonJS({
1074
1074
  }
1075
1075
  });
1076
1076
 
1077
+ // src/global.ts
1078
+ var originUUID, snapshotVersion;
1079
+ var init_global = __esm({
1080
+ "src/global.ts"() {
1081
+ "use strict";
1082
+ originUUID = "00000000-0000-0000-0000-000000000000";
1083
+ snapshotVersion = "6";
1084
+ }
1085
+ });
1086
+
1087
+ // node_modules/.pnpm/zod@3.20.2/node_modules/zod/lib/index.mjs
1088
+ function getErrorMap() {
1089
+ return overrideErrorMap;
1090
+ }
1091
+ function addIssueToContext(ctx, issueData) {
1092
+ const issue = makeIssue({
1093
+ issueData,
1094
+ data: ctx.data,
1095
+ path: ctx.path,
1096
+ errorMaps: [
1097
+ ctx.common.contextualErrorMap,
1098
+ ctx.schemaErrorMap,
1099
+ getErrorMap(),
1100
+ errorMap
1101
+ // then global default map
1102
+ ].filter((x) => !!x)
1103
+ });
1104
+ ctx.common.issues.push(issue);
1105
+ }
1106
+ function processCreateParams(params) {
1107
+ if (!params)
1108
+ return {};
1109
+ const { errorMap: errorMap2, invalid_type_error, required_error, description } = params;
1110
+ if (errorMap2 && (invalid_type_error || required_error)) {
1111
+ throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
1112
+ }
1113
+ if (errorMap2)
1114
+ return { errorMap: errorMap2, description };
1115
+ const customMap = (iss, ctx) => {
1116
+ if (iss.code !== "invalid_type")
1117
+ return { message: ctx.defaultError };
1118
+ if (typeof ctx.data === "undefined") {
1119
+ return { message: required_error !== null && required_error !== void 0 ? required_error : ctx.defaultError };
1120
+ }
1121
+ return { message: invalid_type_error !== null && invalid_type_error !== void 0 ? invalid_type_error : ctx.defaultError };
1122
+ };
1123
+ return { errorMap: customMap, description };
1124
+ }
1125
+ function floatSafeRemainder(val, step) {
1126
+ const valDecCount = (val.toString().split(".")[1] || "").length;
1127
+ const stepDecCount = (step.toString().split(".")[1] || "").length;
1128
+ const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
1129
+ const valInt = parseInt(val.toFixed(decCount).replace(".", ""));
1130
+ const stepInt = parseInt(step.toFixed(decCount).replace(".", ""));
1131
+ return valInt % stepInt / Math.pow(10, decCount);
1132
+ }
1133
+ function deepPartialify(schema3) {
1134
+ if (schema3 instanceof ZodObject) {
1135
+ const newShape = {};
1136
+ for (const key in schema3.shape) {
1137
+ const fieldSchema = schema3.shape[key];
1138
+ newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
1139
+ }
1140
+ return new ZodObject({
1141
+ ...schema3._def,
1142
+ shape: () => newShape
1143
+ });
1144
+ } else if (schema3 instanceof ZodArray) {
1145
+ return ZodArray.create(deepPartialify(schema3.element));
1146
+ } else if (schema3 instanceof ZodOptional) {
1147
+ return ZodOptional.create(deepPartialify(schema3.unwrap()));
1148
+ } else if (schema3 instanceof ZodNullable) {
1149
+ return ZodNullable.create(deepPartialify(schema3.unwrap()));
1150
+ } else if (schema3 instanceof ZodTuple) {
1151
+ return ZodTuple.create(schema3.items.map((item) => deepPartialify(item)));
1152
+ } else {
1153
+ return schema3;
1154
+ }
1155
+ }
1156
+ function mergeValues(a, b) {
1157
+ const aType = getParsedType(a);
1158
+ const bType = getParsedType(b);
1159
+ if (a === b) {
1160
+ return { valid: true, data: a };
1161
+ } else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
1162
+ const bKeys = util.objectKeys(b);
1163
+ const sharedKeys = util.objectKeys(a).filter((key) => bKeys.indexOf(key) !== -1);
1164
+ const newObj = { ...a, ...b };
1165
+ for (const key of sharedKeys) {
1166
+ const sharedValue = mergeValues(a[key], b[key]);
1167
+ if (!sharedValue.valid) {
1168
+ return { valid: false };
1169
+ }
1170
+ newObj[key] = sharedValue.data;
1171
+ }
1172
+ return { valid: true, data: newObj };
1173
+ } else if (aType === ZodParsedType.array && bType === ZodParsedType.array) {
1174
+ if (a.length !== b.length) {
1175
+ return { valid: false };
1176
+ }
1177
+ const newArray = [];
1178
+ for (let index4 = 0; index4 < a.length; index4++) {
1179
+ const itemA = a[index4];
1180
+ const itemB = b[index4];
1181
+ const sharedValue = mergeValues(itemA, itemB);
1182
+ if (!sharedValue.valid) {
1183
+ return { valid: false };
1184
+ }
1185
+ newArray.push(sharedValue.data);
1186
+ }
1187
+ return { valid: true, data: newArray };
1188
+ } else if (aType === ZodParsedType.date && bType === ZodParsedType.date && +a === +b) {
1189
+ return { valid: true, data: a };
1190
+ } else {
1191
+ return { valid: false };
1192
+ }
1193
+ }
1194
+ function createZodEnum(values, params) {
1195
+ return new ZodEnum({
1196
+ values,
1197
+ typeName: ZodFirstPartyTypeKind.ZodEnum,
1198
+ ...processCreateParams(params)
1199
+ });
1200
+ }
1201
+ var util, ZodParsedType, getParsedType, ZodIssueCode, ZodError, errorMap, overrideErrorMap, makeIssue, ParseStatus, INVALID, DIRTY, OK, isAborted, isDirty, isValid, isAsync, errorUtil, ParseInputLazyPath, handleResult, ZodType, cuidRegex, uuidRegex, emailRegex, datetimeRegex, ZodString, ZodNumber, ZodBigInt, ZodBoolean, ZodDate, ZodSymbol, ZodUndefined, ZodNull, ZodAny, ZodUnknown, ZodNever, ZodVoid, ZodArray, objectUtil, AugmentFactory, ZodObject, ZodUnion, getDiscriminator, ZodDiscriminatedUnion, ZodIntersection, ZodTuple, ZodRecord, ZodMap, ZodSet, ZodFunction, ZodLazy, ZodLiteral, ZodEnum, ZodNativeEnum, ZodPromise, ZodEffects, ZodOptional, ZodNullable, ZodDefault, ZodCatch, ZodNaN, BRAND, ZodBranded, ZodPipeline, late, ZodFirstPartyTypeKind, stringType, numberType, nanType, bigIntType, booleanType, dateType, symbolType, undefinedType, nullType, anyType, unknownType, neverType, voidType, arrayType, objectType, strictObjectType, unionType, discriminatedUnionType, intersectionType, tupleType, recordType, mapType, setType, functionType, lazyType, literalType, enumType, nativeEnumType, promiseType, effectsType, optionalType, nullableType, preprocessType, pipelineType;
1202
+ var init_lib = __esm({
1203
+ "node_modules/.pnpm/zod@3.20.2/node_modules/zod/lib/index.mjs"() {
1204
+ (function(util2) {
1205
+ util2.assertEqual = (val) => val;
1206
+ function assertIs(_arg) {
1207
+ }
1208
+ util2.assertIs = assertIs;
1209
+ function assertNever(_x) {
1210
+ throw new Error();
1211
+ }
1212
+ util2.assertNever = assertNever;
1213
+ util2.arrayToEnum = (items) => {
1214
+ const obj = {};
1215
+ for (const item of items) {
1216
+ obj[item] = item;
1217
+ }
1218
+ return obj;
1219
+ };
1220
+ util2.getValidEnumValues = (obj) => {
1221
+ const validKeys = util2.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
1222
+ const filtered = {};
1223
+ for (const k of validKeys) {
1224
+ filtered[k] = obj[k];
1225
+ }
1226
+ return util2.objectValues(filtered);
1227
+ };
1228
+ util2.objectValues = (obj) => {
1229
+ return util2.objectKeys(obj).map(function(e) {
1230
+ return obj[e];
1231
+ });
1232
+ };
1233
+ util2.objectKeys = typeof Object.keys === "function" ? (obj) => Object.keys(obj) : (object) => {
1234
+ const keys = [];
1235
+ for (const key in object) {
1236
+ if (Object.prototype.hasOwnProperty.call(object, key)) {
1237
+ keys.push(key);
1238
+ }
1239
+ }
1240
+ return keys;
1241
+ };
1242
+ util2.find = (arr, checker) => {
1243
+ for (const item of arr) {
1244
+ if (checker(item))
1245
+ return item;
1246
+ }
1247
+ return void 0;
1248
+ };
1249
+ util2.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && isFinite(val) && Math.floor(val) === val;
1250
+ function joinValues(array, separator = " | ") {
1251
+ return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
1252
+ }
1253
+ util2.joinValues = joinValues;
1254
+ util2.jsonStringifyReplacer = (_, value) => {
1255
+ if (typeof value === "bigint") {
1256
+ return value.toString();
1257
+ }
1258
+ return value;
1259
+ };
1260
+ })(util || (util = {}));
1261
+ ZodParsedType = util.arrayToEnum([
1262
+ "string",
1263
+ "nan",
1264
+ "number",
1265
+ "integer",
1266
+ "float",
1267
+ "boolean",
1268
+ "date",
1269
+ "bigint",
1270
+ "symbol",
1271
+ "function",
1272
+ "undefined",
1273
+ "null",
1274
+ "array",
1275
+ "object",
1276
+ "unknown",
1277
+ "promise",
1278
+ "void",
1279
+ "never",
1280
+ "map",
1281
+ "set"
1282
+ ]);
1283
+ getParsedType = (data) => {
1284
+ const t = typeof data;
1285
+ switch (t) {
1286
+ case "undefined":
1287
+ return ZodParsedType.undefined;
1288
+ case "string":
1289
+ return ZodParsedType.string;
1290
+ case "number":
1291
+ return isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
1292
+ case "boolean":
1293
+ return ZodParsedType.boolean;
1294
+ case "function":
1295
+ return ZodParsedType.function;
1296
+ case "bigint":
1297
+ return ZodParsedType.bigint;
1298
+ case "symbol":
1299
+ return ZodParsedType.symbol;
1300
+ case "object":
1301
+ if (Array.isArray(data)) {
1302
+ return ZodParsedType.array;
1303
+ }
1304
+ if (data === null) {
1305
+ return ZodParsedType.null;
1306
+ }
1307
+ if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") {
1308
+ return ZodParsedType.promise;
1309
+ }
1310
+ if (typeof Map !== "undefined" && data instanceof Map) {
1311
+ return ZodParsedType.map;
1312
+ }
1313
+ if (typeof Set !== "undefined" && data instanceof Set) {
1314
+ return ZodParsedType.set;
1315
+ }
1316
+ if (typeof Date !== "undefined" && data instanceof Date) {
1317
+ return ZodParsedType.date;
1318
+ }
1319
+ return ZodParsedType.object;
1320
+ default:
1321
+ return ZodParsedType.unknown;
1322
+ }
1323
+ };
1324
+ ZodIssueCode = util.arrayToEnum([
1325
+ "invalid_type",
1326
+ "invalid_literal",
1327
+ "custom",
1328
+ "invalid_union",
1329
+ "invalid_union_discriminator",
1330
+ "invalid_enum_value",
1331
+ "unrecognized_keys",
1332
+ "invalid_arguments",
1333
+ "invalid_return_type",
1334
+ "invalid_date",
1335
+ "invalid_string",
1336
+ "too_small",
1337
+ "too_big",
1338
+ "invalid_intersection_types",
1339
+ "not_multiple_of",
1340
+ "not_finite"
1341
+ ]);
1342
+ ZodError = class extends Error {
1343
+ constructor(issues) {
1344
+ super();
1345
+ this.issues = [];
1346
+ this.addIssue = (sub) => {
1347
+ this.issues = [...this.issues, sub];
1348
+ };
1349
+ this.addIssues = (subs = []) => {
1350
+ this.issues = [...this.issues, ...subs];
1351
+ };
1352
+ const actualProto = new.target.prototype;
1353
+ if (Object.setPrototypeOf) {
1354
+ Object.setPrototypeOf(this, actualProto);
1355
+ } else {
1356
+ this.__proto__ = actualProto;
1357
+ }
1358
+ this.name = "ZodError";
1359
+ this.issues = issues;
1360
+ }
1361
+ get errors() {
1362
+ return this.issues;
1363
+ }
1364
+ format(_mapper) {
1365
+ const mapper = _mapper || function(issue) {
1366
+ return issue.message;
1367
+ };
1368
+ const fieldErrors = { _errors: [] };
1369
+ const processError = (error2) => {
1370
+ for (const issue of error2.issues) {
1371
+ if (issue.code === "invalid_union") {
1372
+ issue.unionErrors.map(processError);
1373
+ } else if (issue.code === "invalid_return_type") {
1374
+ processError(issue.returnTypeError);
1375
+ } else if (issue.code === "invalid_arguments") {
1376
+ processError(issue.argumentsError);
1377
+ } else if (issue.path.length === 0) {
1378
+ fieldErrors._errors.push(mapper(issue));
1379
+ } else {
1380
+ let curr = fieldErrors;
1381
+ let i = 0;
1382
+ while (i < issue.path.length) {
1383
+ const el = issue.path[i];
1384
+ const terminal = i === issue.path.length - 1;
1385
+ if (!terminal) {
1386
+ curr[el] = curr[el] || { _errors: [] };
1387
+ } else {
1388
+ curr[el] = curr[el] || { _errors: [] };
1389
+ curr[el]._errors.push(mapper(issue));
1390
+ }
1391
+ curr = curr[el];
1392
+ i++;
1393
+ }
1394
+ }
1395
+ }
1396
+ };
1397
+ processError(this);
1398
+ return fieldErrors;
1399
+ }
1400
+ toString() {
1401
+ return this.message;
1402
+ }
1403
+ get message() {
1404
+ return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2);
1405
+ }
1406
+ get isEmpty() {
1407
+ return this.issues.length === 0;
1408
+ }
1409
+ flatten(mapper = (issue) => issue.message) {
1410
+ const fieldErrors = {};
1411
+ const formErrors = [];
1412
+ for (const sub of this.issues) {
1413
+ if (sub.path.length > 0) {
1414
+ fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
1415
+ fieldErrors[sub.path[0]].push(mapper(sub));
1416
+ } else {
1417
+ formErrors.push(mapper(sub));
1418
+ }
1419
+ }
1420
+ return { formErrors, fieldErrors };
1421
+ }
1422
+ get formErrors() {
1423
+ return this.flatten();
1424
+ }
1425
+ };
1426
+ ZodError.create = (issues) => {
1427
+ const error2 = new ZodError(issues);
1428
+ return error2;
1429
+ };
1430
+ errorMap = (issue, _ctx) => {
1431
+ let message;
1432
+ switch (issue.code) {
1433
+ case ZodIssueCode.invalid_type:
1434
+ if (issue.received === ZodParsedType.undefined) {
1435
+ message = "Required";
1436
+ } else {
1437
+ message = `Expected ${issue.expected}, received ${issue.received}`;
1438
+ }
1439
+ break;
1440
+ case ZodIssueCode.invalid_literal:
1441
+ message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util.jsonStringifyReplacer)}`;
1442
+ break;
1443
+ case ZodIssueCode.unrecognized_keys:
1444
+ message = `Unrecognized key(s) in object: ${util.joinValues(issue.keys, ", ")}`;
1445
+ break;
1446
+ case ZodIssueCode.invalid_union:
1447
+ message = `Invalid input`;
1448
+ break;
1449
+ case ZodIssueCode.invalid_union_discriminator:
1450
+ message = `Invalid discriminator value. Expected ${util.joinValues(issue.options)}`;
1451
+ break;
1452
+ case ZodIssueCode.invalid_enum_value:
1453
+ message = `Invalid enum value. Expected ${util.joinValues(issue.options)}, received '${issue.received}'`;
1454
+ break;
1455
+ case ZodIssueCode.invalid_arguments:
1456
+ message = `Invalid function arguments`;
1457
+ break;
1458
+ case ZodIssueCode.invalid_return_type:
1459
+ message = `Invalid function return type`;
1460
+ break;
1461
+ case ZodIssueCode.invalid_date:
1462
+ message = `Invalid date`;
1463
+ break;
1464
+ case ZodIssueCode.invalid_string:
1465
+ if (typeof issue.validation === "object") {
1466
+ if ("startsWith" in issue.validation) {
1467
+ message = `Invalid input: must start with "${issue.validation.startsWith}"`;
1468
+ } else if ("endsWith" in issue.validation) {
1469
+ message = `Invalid input: must end with "${issue.validation.endsWith}"`;
1470
+ } else {
1471
+ util.assertNever(issue.validation);
1472
+ }
1473
+ } else if (issue.validation !== "regex") {
1474
+ message = `Invalid ${issue.validation}`;
1475
+ } else {
1476
+ message = "Invalid";
1477
+ }
1478
+ break;
1479
+ case ZodIssueCode.too_small:
1480
+ if (issue.type === "array")
1481
+ message = `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`;
1482
+ else if (issue.type === "string")
1483
+ message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
1484
+ else if (issue.type === "number")
1485
+ message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
1486
+ else if (issue.type === "date")
1487
+ message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(issue.minimum)}`;
1488
+ else
1489
+ message = "Invalid input";
1490
+ break;
1491
+ case ZodIssueCode.too_big:
1492
+ if (issue.type === "array")
1493
+ message = `Array must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`;
1494
+ else if (issue.type === "string")
1495
+ message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
1496
+ else if (issue.type === "number")
1497
+ message = `Number must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
1498
+ else if (issue.type === "date")
1499
+ message = `Date must be ${issue.exact ? `exactly` : issue.inclusive ? `smaller than or equal to` : `smaller than`} ${new Date(issue.maximum)}`;
1500
+ else
1501
+ message = "Invalid input";
1502
+ break;
1503
+ case ZodIssueCode.custom:
1504
+ message = `Invalid input`;
1505
+ break;
1506
+ case ZodIssueCode.invalid_intersection_types:
1507
+ message = `Intersection results could not be merged`;
1508
+ break;
1509
+ case ZodIssueCode.not_multiple_of:
1510
+ message = `Number must be a multiple of ${issue.multipleOf}`;
1511
+ break;
1512
+ case ZodIssueCode.not_finite:
1513
+ message = "Number must be finite";
1514
+ break;
1515
+ default:
1516
+ message = _ctx.defaultError;
1517
+ util.assertNever(issue);
1518
+ }
1519
+ return { message };
1520
+ };
1521
+ overrideErrorMap = errorMap;
1522
+ makeIssue = (params) => {
1523
+ const { data, path: path2, errorMaps, issueData } = params;
1524
+ const fullPath = [...path2, ...issueData.path || []];
1525
+ const fullIssue = {
1526
+ ...issueData,
1527
+ path: fullPath
1528
+ };
1529
+ let errorMessage = "";
1530
+ const maps = errorMaps.filter((m) => !!m).slice().reverse();
1531
+ for (const map of maps) {
1532
+ errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
1533
+ }
1534
+ return {
1535
+ ...issueData,
1536
+ path: fullPath,
1537
+ message: issueData.message || errorMessage
1538
+ };
1539
+ };
1540
+ ParseStatus = class _ParseStatus {
1541
+ constructor() {
1542
+ this.value = "valid";
1543
+ }
1544
+ dirty() {
1545
+ if (this.value === "valid")
1546
+ this.value = "dirty";
1547
+ }
1548
+ abort() {
1549
+ if (this.value !== "aborted")
1550
+ this.value = "aborted";
1551
+ }
1552
+ static mergeArray(status, results) {
1553
+ const arrayValue = [];
1554
+ for (const s of results) {
1555
+ if (s.status === "aborted")
1556
+ return INVALID;
1557
+ if (s.status === "dirty")
1558
+ status.dirty();
1559
+ arrayValue.push(s.value);
1560
+ }
1561
+ return { status: status.value, value: arrayValue };
1562
+ }
1563
+ static async mergeObjectAsync(status, pairs) {
1564
+ const syncPairs = [];
1565
+ for (const pair of pairs) {
1566
+ syncPairs.push({
1567
+ key: await pair.key,
1568
+ value: await pair.value
1569
+ });
1570
+ }
1571
+ return _ParseStatus.mergeObjectSync(status, syncPairs);
1572
+ }
1573
+ static mergeObjectSync(status, pairs) {
1574
+ const finalObject = {};
1575
+ for (const pair of pairs) {
1576
+ const { key, value } = pair;
1577
+ if (key.status === "aborted")
1578
+ return INVALID;
1579
+ if (value.status === "aborted")
1580
+ return INVALID;
1581
+ if (key.status === "dirty")
1582
+ status.dirty();
1583
+ if (value.status === "dirty")
1584
+ status.dirty();
1585
+ if (typeof value.value !== "undefined" || pair.alwaysSet) {
1586
+ finalObject[key.value] = value.value;
1587
+ }
1588
+ }
1589
+ return { status: status.value, value: finalObject };
1590
+ }
1591
+ };
1592
+ INVALID = Object.freeze({
1593
+ status: "aborted"
1594
+ });
1595
+ DIRTY = (value) => ({ status: "dirty", value });
1596
+ OK = (value) => ({ status: "valid", value });
1597
+ isAborted = (x) => x.status === "aborted";
1598
+ isDirty = (x) => x.status === "dirty";
1599
+ isValid = (x) => x.status === "valid";
1600
+ isAsync = (x) => typeof Promise !== void 0 && x instanceof Promise;
1601
+ (function(errorUtil2) {
1602
+ errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
1603
+ errorUtil2.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
1604
+ })(errorUtil || (errorUtil = {}));
1605
+ ParseInputLazyPath = class {
1606
+ constructor(parent, value, path2, key) {
1607
+ this.parent = parent;
1608
+ this.data = value;
1609
+ this._path = path2;
1610
+ this._key = key;
1611
+ }
1612
+ get path() {
1613
+ return this._path.concat(this._key);
1614
+ }
1615
+ };
1616
+ handleResult = (ctx, result) => {
1617
+ if (isValid(result)) {
1618
+ return { success: true, data: result.value };
1619
+ } else {
1620
+ if (!ctx.common.issues.length) {
1621
+ throw new Error("Validation failed but no issues detected.");
1622
+ }
1623
+ const error2 = new ZodError(ctx.common.issues);
1624
+ return { success: false, error: error2 };
1625
+ }
1626
+ };
1627
+ ZodType = class {
1628
+ constructor(def) {
1629
+ this.spa = this.safeParseAsync;
1630
+ this._def = def;
1631
+ this.parse = this.parse.bind(this);
1632
+ this.safeParse = this.safeParse.bind(this);
1633
+ this.parseAsync = this.parseAsync.bind(this);
1634
+ this.safeParseAsync = this.safeParseAsync.bind(this);
1635
+ this.spa = this.spa.bind(this);
1636
+ this.refine = this.refine.bind(this);
1637
+ this.refinement = this.refinement.bind(this);
1638
+ this.superRefine = this.superRefine.bind(this);
1639
+ this.optional = this.optional.bind(this);
1640
+ this.nullable = this.nullable.bind(this);
1641
+ this.nullish = this.nullish.bind(this);
1642
+ this.array = this.array.bind(this);
1643
+ this.promise = this.promise.bind(this);
1644
+ this.or = this.or.bind(this);
1645
+ this.and = this.and.bind(this);
1646
+ this.transform = this.transform.bind(this);
1647
+ this.brand = this.brand.bind(this);
1648
+ this.default = this.default.bind(this);
1649
+ this.catch = this.catch.bind(this);
1650
+ this.describe = this.describe.bind(this);
1651
+ this.pipe = this.pipe.bind(this);
1652
+ this.isNullable = this.isNullable.bind(this);
1653
+ this.isOptional = this.isOptional.bind(this);
1654
+ }
1655
+ get description() {
1656
+ return this._def.description;
1657
+ }
1658
+ _getType(input) {
1659
+ return getParsedType(input.data);
1660
+ }
1661
+ _getOrReturnCtx(input, ctx) {
1662
+ return ctx || {
1663
+ common: input.parent.common,
1664
+ data: input.data,
1665
+ parsedType: getParsedType(input.data),
1666
+ schemaErrorMap: this._def.errorMap,
1667
+ path: input.path,
1668
+ parent: input.parent
1669
+ };
1670
+ }
1671
+ _processInputParams(input) {
1672
+ return {
1673
+ status: new ParseStatus(),
1674
+ ctx: {
1675
+ common: input.parent.common,
1676
+ data: input.data,
1677
+ parsedType: getParsedType(input.data),
1678
+ schemaErrorMap: this._def.errorMap,
1679
+ path: input.path,
1680
+ parent: input.parent
1681
+ }
1682
+ };
1683
+ }
1684
+ _parseSync(input) {
1685
+ const result = this._parse(input);
1686
+ if (isAsync(result)) {
1687
+ throw new Error("Synchronous parse encountered promise.");
1688
+ }
1689
+ return result;
1690
+ }
1691
+ _parseAsync(input) {
1692
+ const result = this._parse(input);
1693
+ return Promise.resolve(result);
1694
+ }
1695
+ parse(data, params) {
1696
+ const result = this.safeParse(data, params);
1697
+ if (result.success)
1698
+ return result.data;
1699
+ throw result.error;
1700
+ }
1701
+ safeParse(data, params) {
1702
+ var _a;
1703
+ const ctx = {
1704
+ common: {
1705
+ issues: [],
1706
+ async: (_a = params === null || params === void 0 ? void 0 : params.async) !== null && _a !== void 0 ? _a : false,
1707
+ contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap
1708
+ },
1709
+ path: (params === null || params === void 0 ? void 0 : params.path) || [],
1710
+ schemaErrorMap: this._def.errorMap,
1711
+ parent: null,
1712
+ data,
1713
+ parsedType: getParsedType(data)
1714
+ };
1715
+ const result = this._parseSync({ data, path: ctx.path, parent: ctx });
1716
+ return handleResult(ctx, result);
1717
+ }
1718
+ async parseAsync(data, params) {
1719
+ const result = await this.safeParseAsync(data, params);
1720
+ if (result.success)
1721
+ return result.data;
1722
+ throw result.error;
1723
+ }
1724
+ async safeParseAsync(data, params) {
1725
+ const ctx = {
1726
+ common: {
1727
+ issues: [],
1728
+ contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
1729
+ async: true
1730
+ },
1731
+ path: (params === null || params === void 0 ? void 0 : params.path) || [],
1732
+ schemaErrorMap: this._def.errorMap,
1733
+ parent: null,
1734
+ data,
1735
+ parsedType: getParsedType(data)
1736
+ };
1737
+ const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
1738
+ const result = await (isAsync(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult));
1739
+ return handleResult(ctx, result);
1740
+ }
1741
+ refine(check, message) {
1742
+ const getIssueProperties = (val) => {
1743
+ if (typeof message === "string" || typeof message === "undefined") {
1744
+ return { message };
1745
+ } else if (typeof message === "function") {
1746
+ return message(val);
1747
+ } else {
1748
+ return message;
1749
+ }
1750
+ };
1751
+ return this._refinement((val, ctx) => {
1752
+ const result = check(val);
1753
+ const setError = () => ctx.addIssue({
1754
+ code: ZodIssueCode.custom,
1755
+ ...getIssueProperties(val)
1756
+ });
1757
+ if (typeof Promise !== "undefined" && result instanceof Promise) {
1758
+ return result.then((data) => {
1759
+ if (!data) {
1760
+ setError();
1761
+ return false;
1762
+ } else {
1763
+ return true;
1764
+ }
1765
+ });
1766
+ }
1767
+ if (!result) {
1768
+ setError();
1769
+ return false;
1770
+ } else {
1771
+ return true;
1772
+ }
1773
+ });
1774
+ }
1775
+ refinement(check, refinementData) {
1776
+ return this._refinement((val, ctx) => {
1777
+ if (!check(val)) {
1778
+ ctx.addIssue(typeof refinementData === "function" ? refinementData(val, ctx) : refinementData);
1779
+ return false;
1780
+ } else {
1781
+ return true;
1782
+ }
1783
+ });
1784
+ }
1785
+ _refinement(refinement) {
1786
+ return new ZodEffects({
1787
+ schema: this,
1788
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
1789
+ effect: { type: "refinement", refinement }
1790
+ });
1791
+ }
1792
+ superRefine(refinement) {
1793
+ return this._refinement(refinement);
1794
+ }
1795
+ optional() {
1796
+ return ZodOptional.create(this);
1797
+ }
1798
+ nullable() {
1799
+ return ZodNullable.create(this);
1800
+ }
1801
+ nullish() {
1802
+ return this.optional().nullable();
1803
+ }
1804
+ array() {
1805
+ return ZodArray.create(this);
1806
+ }
1807
+ promise() {
1808
+ return ZodPromise.create(this);
1809
+ }
1810
+ or(option) {
1811
+ return ZodUnion.create([this, option]);
1812
+ }
1813
+ and(incoming) {
1814
+ return ZodIntersection.create(this, incoming);
1815
+ }
1816
+ transform(transform) {
1817
+ return new ZodEffects({
1818
+ schema: this,
1819
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
1820
+ effect: { type: "transform", transform }
1821
+ });
1822
+ }
1823
+ default(def) {
1824
+ const defaultValueFunc = typeof def === "function" ? def : () => def;
1825
+ return new ZodDefault({
1826
+ innerType: this,
1827
+ defaultValue: defaultValueFunc,
1828
+ typeName: ZodFirstPartyTypeKind.ZodDefault
1829
+ });
1830
+ }
1831
+ brand() {
1832
+ return new ZodBranded({
1833
+ typeName: ZodFirstPartyTypeKind.ZodBranded,
1834
+ type: this,
1835
+ ...processCreateParams(void 0)
1836
+ });
1837
+ }
1838
+ catch(def) {
1839
+ const defaultValueFunc = typeof def === "function" ? def : () => def;
1840
+ return new ZodCatch({
1841
+ innerType: this,
1842
+ defaultValue: defaultValueFunc,
1843
+ typeName: ZodFirstPartyTypeKind.ZodCatch
1844
+ });
1845
+ }
1846
+ describe(description) {
1847
+ const This = this.constructor;
1848
+ return new This({
1849
+ ...this._def,
1850
+ description
1851
+ });
1852
+ }
1853
+ pipe(target) {
1854
+ return ZodPipeline.create(this, target);
1855
+ }
1856
+ isOptional() {
1857
+ return this.safeParse(void 0).success;
1858
+ }
1859
+ isNullable() {
1860
+ return this.safeParse(null).success;
1861
+ }
1862
+ };
1863
+ cuidRegex = /^c[^\s-]{8,}$/i;
1864
+ uuidRegex = /^([a-f0-9]{8}-[a-f0-9]{4}-[1-5][a-f0-9]{3}-[a-f0-9]{4}-[a-f0-9]{12}|00000000-0000-0000-0000-000000000000)$/i;
1865
+ emailRegex = /^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i;
1866
+ datetimeRegex = (args) => {
1867
+ if (args.precision) {
1868
+ if (args.offset) {
1869
+ return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}(([+-]\\d{2}:\\d{2})|Z)$`);
1870
+ } else {
1871
+ return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}Z$`);
1872
+ }
1873
+ } else if (args.precision === 0) {
1874
+ if (args.offset) {
1875
+ return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(([+-]\\d{2}:\\d{2})|Z)$`);
1876
+ } else {
1877
+ return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$`);
1878
+ }
1879
+ } else {
1880
+ if (args.offset) {
1881
+ return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(([+-]\\d{2}:\\d{2})|Z)$`);
1882
+ } else {
1883
+ return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$`);
1884
+ }
1885
+ }
1886
+ };
1887
+ ZodString = class _ZodString extends ZodType {
1888
+ constructor() {
1889
+ super(...arguments);
1890
+ this._regex = (regex, validation, message) => this.refinement((data) => regex.test(data), {
1891
+ validation,
1892
+ code: ZodIssueCode.invalid_string,
1893
+ ...errorUtil.errToObj(message)
1894
+ });
1895
+ this.nonempty = (message) => this.min(1, errorUtil.errToObj(message));
1896
+ this.trim = () => new _ZodString({
1897
+ ...this._def,
1898
+ checks: [...this._def.checks, { kind: "trim" }]
1899
+ });
1900
+ }
1901
+ _parse(input) {
1902
+ if (this._def.coerce) {
1903
+ input.data = String(input.data);
1904
+ }
1905
+ const parsedType = this._getType(input);
1906
+ if (parsedType !== ZodParsedType.string) {
1907
+ const ctx2 = this._getOrReturnCtx(input);
1908
+ addIssueToContext(
1909
+ ctx2,
1910
+ {
1911
+ code: ZodIssueCode.invalid_type,
1912
+ expected: ZodParsedType.string,
1913
+ received: ctx2.parsedType
1914
+ }
1915
+ //
1916
+ );
1917
+ return INVALID;
1918
+ }
1919
+ const status = new ParseStatus();
1920
+ let ctx = void 0;
1921
+ for (const check of this._def.checks) {
1922
+ if (check.kind === "min") {
1923
+ if (input.data.length < check.value) {
1924
+ ctx = this._getOrReturnCtx(input, ctx);
1925
+ addIssueToContext(ctx, {
1926
+ code: ZodIssueCode.too_small,
1927
+ minimum: check.value,
1928
+ type: "string",
1929
+ inclusive: true,
1930
+ exact: false,
1931
+ message: check.message
1932
+ });
1933
+ status.dirty();
1934
+ }
1935
+ } else if (check.kind === "max") {
1936
+ if (input.data.length > check.value) {
1937
+ ctx = this._getOrReturnCtx(input, ctx);
1938
+ addIssueToContext(ctx, {
1939
+ code: ZodIssueCode.too_big,
1940
+ maximum: check.value,
1941
+ type: "string",
1942
+ inclusive: true,
1943
+ exact: false,
1944
+ message: check.message
1945
+ });
1946
+ status.dirty();
1947
+ }
1948
+ } else if (check.kind === "length") {
1949
+ const tooBig = input.data.length > check.value;
1950
+ const tooSmall = input.data.length < check.value;
1951
+ if (tooBig || tooSmall) {
1952
+ ctx = this._getOrReturnCtx(input, ctx);
1953
+ if (tooBig) {
1954
+ addIssueToContext(ctx, {
1955
+ code: ZodIssueCode.too_big,
1956
+ maximum: check.value,
1957
+ type: "string",
1958
+ inclusive: true,
1959
+ exact: true,
1960
+ message: check.message
1961
+ });
1962
+ } else if (tooSmall) {
1963
+ addIssueToContext(ctx, {
1964
+ code: ZodIssueCode.too_small,
1965
+ minimum: check.value,
1966
+ type: "string",
1967
+ inclusive: true,
1968
+ exact: true,
1969
+ message: check.message
1970
+ });
1971
+ }
1972
+ status.dirty();
1973
+ }
1974
+ } else if (check.kind === "email") {
1975
+ if (!emailRegex.test(input.data)) {
1976
+ ctx = this._getOrReturnCtx(input, ctx);
1977
+ addIssueToContext(ctx, {
1978
+ validation: "email",
1979
+ code: ZodIssueCode.invalid_string,
1980
+ message: check.message
1981
+ });
1982
+ status.dirty();
1983
+ }
1984
+ } else if (check.kind === "uuid") {
1985
+ if (!uuidRegex.test(input.data)) {
1986
+ ctx = this._getOrReturnCtx(input, ctx);
1987
+ addIssueToContext(ctx, {
1988
+ validation: "uuid",
1989
+ code: ZodIssueCode.invalid_string,
1990
+ message: check.message
1991
+ });
1992
+ status.dirty();
1993
+ }
1994
+ } else if (check.kind === "cuid") {
1995
+ if (!cuidRegex.test(input.data)) {
1996
+ ctx = this._getOrReturnCtx(input, ctx);
1997
+ addIssueToContext(ctx, {
1998
+ validation: "cuid",
1999
+ code: ZodIssueCode.invalid_string,
2000
+ message: check.message
2001
+ });
2002
+ status.dirty();
2003
+ }
2004
+ } else if (check.kind === "url") {
2005
+ try {
2006
+ new URL(input.data);
2007
+ } catch (_a) {
2008
+ ctx = this._getOrReturnCtx(input, ctx);
2009
+ addIssueToContext(ctx, {
2010
+ validation: "url",
2011
+ code: ZodIssueCode.invalid_string,
2012
+ message: check.message
2013
+ });
2014
+ status.dirty();
2015
+ }
2016
+ } else if (check.kind === "regex") {
2017
+ check.regex.lastIndex = 0;
2018
+ const testResult = check.regex.test(input.data);
2019
+ if (!testResult) {
2020
+ ctx = this._getOrReturnCtx(input, ctx);
2021
+ addIssueToContext(ctx, {
2022
+ validation: "regex",
2023
+ code: ZodIssueCode.invalid_string,
2024
+ message: check.message
2025
+ });
2026
+ status.dirty();
2027
+ }
2028
+ } else if (check.kind === "trim") {
2029
+ input.data = input.data.trim();
2030
+ } else if (check.kind === "startsWith") {
2031
+ if (!input.data.startsWith(check.value)) {
2032
+ ctx = this._getOrReturnCtx(input, ctx);
2033
+ addIssueToContext(ctx, {
2034
+ code: ZodIssueCode.invalid_string,
2035
+ validation: { startsWith: check.value },
2036
+ message: check.message
2037
+ });
2038
+ status.dirty();
2039
+ }
2040
+ } else if (check.kind === "endsWith") {
2041
+ if (!input.data.endsWith(check.value)) {
2042
+ ctx = this._getOrReturnCtx(input, ctx);
2043
+ addIssueToContext(ctx, {
2044
+ code: ZodIssueCode.invalid_string,
2045
+ validation: { endsWith: check.value },
2046
+ message: check.message
2047
+ });
2048
+ status.dirty();
2049
+ }
2050
+ } else if (check.kind === "datetime") {
2051
+ const regex = datetimeRegex(check);
2052
+ if (!regex.test(input.data)) {
2053
+ ctx = this._getOrReturnCtx(input, ctx);
2054
+ addIssueToContext(ctx, {
2055
+ code: ZodIssueCode.invalid_string,
2056
+ validation: "datetime",
2057
+ message: check.message
2058
+ });
2059
+ status.dirty();
2060
+ }
2061
+ } else {
2062
+ util.assertNever(check);
2063
+ }
2064
+ }
2065
+ return { status: status.value, value: input.data };
2066
+ }
2067
+ _addCheck(check) {
2068
+ return new _ZodString({
2069
+ ...this._def,
2070
+ checks: [...this._def.checks, check]
2071
+ });
2072
+ }
2073
+ email(message) {
2074
+ return this._addCheck({ kind: "email", ...errorUtil.errToObj(message) });
2075
+ }
2076
+ url(message) {
2077
+ return this._addCheck({ kind: "url", ...errorUtil.errToObj(message) });
2078
+ }
2079
+ uuid(message) {
2080
+ return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
2081
+ }
2082
+ cuid(message) {
2083
+ return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
2084
+ }
2085
+ datetime(options) {
2086
+ var _a;
2087
+ if (typeof options === "string") {
2088
+ return this._addCheck({
2089
+ kind: "datetime",
2090
+ precision: null,
2091
+ offset: false,
2092
+ message: options
2093
+ });
2094
+ }
2095
+ return this._addCheck({
2096
+ kind: "datetime",
2097
+ precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
2098
+ offset: (_a = options === null || options === void 0 ? void 0 : options.offset) !== null && _a !== void 0 ? _a : false,
2099
+ ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message)
2100
+ });
2101
+ }
2102
+ regex(regex, message) {
2103
+ return this._addCheck({
2104
+ kind: "regex",
2105
+ regex,
2106
+ ...errorUtil.errToObj(message)
2107
+ });
2108
+ }
2109
+ startsWith(value, message) {
2110
+ return this._addCheck({
2111
+ kind: "startsWith",
2112
+ value,
2113
+ ...errorUtil.errToObj(message)
2114
+ });
2115
+ }
2116
+ endsWith(value, message) {
2117
+ return this._addCheck({
2118
+ kind: "endsWith",
2119
+ value,
2120
+ ...errorUtil.errToObj(message)
2121
+ });
2122
+ }
2123
+ min(minLength, message) {
2124
+ return this._addCheck({
2125
+ kind: "min",
2126
+ value: minLength,
2127
+ ...errorUtil.errToObj(message)
2128
+ });
2129
+ }
2130
+ max(maxLength, message) {
2131
+ return this._addCheck({
2132
+ kind: "max",
2133
+ value: maxLength,
2134
+ ...errorUtil.errToObj(message)
2135
+ });
2136
+ }
2137
+ length(len, message) {
2138
+ return this._addCheck({
2139
+ kind: "length",
2140
+ value: len,
2141
+ ...errorUtil.errToObj(message)
2142
+ });
2143
+ }
2144
+ get isDatetime() {
2145
+ return !!this._def.checks.find((ch) => ch.kind === "datetime");
2146
+ }
2147
+ get isEmail() {
2148
+ return !!this._def.checks.find((ch) => ch.kind === "email");
2149
+ }
2150
+ get isURL() {
2151
+ return !!this._def.checks.find((ch) => ch.kind === "url");
2152
+ }
2153
+ get isUUID() {
2154
+ return !!this._def.checks.find((ch) => ch.kind === "uuid");
2155
+ }
2156
+ get isCUID() {
2157
+ return !!this._def.checks.find((ch) => ch.kind === "cuid");
2158
+ }
2159
+ get minLength() {
2160
+ let min = null;
2161
+ for (const ch of this._def.checks) {
2162
+ if (ch.kind === "min") {
2163
+ if (min === null || ch.value > min)
2164
+ min = ch.value;
2165
+ }
2166
+ }
2167
+ return min;
2168
+ }
2169
+ get maxLength() {
2170
+ let max = null;
2171
+ for (const ch of this._def.checks) {
2172
+ if (ch.kind === "max") {
2173
+ if (max === null || ch.value < max)
2174
+ max = ch.value;
2175
+ }
2176
+ }
2177
+ return max;
2178
+ }
2179
+ };
2180
+ ZodString.create = (params) => {
2181
+ var _a;
2182
+ return new ZodString({
2183
+ checks: [],
2184
+ typeName: ZodFirstPartyTypeKind.ZodString,
2185
+ coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
2186
+ ...processCreateParams(params)
2187
+ });
2188
+ };
2189
+ ZodNumber = class _ZodNumber extends ZodType {
2190
+ constructor() {
2191
+ super(...arguments);
2192
+ this.min = this.gte;
2193
+ this.max = this.lte;
2194
+ this.step = this.multipleOf;
2195
+ }
2196
+ _parse(input) {
2197
+ if (this._def.coerce) {
2198
+ input.data = Number(input.data);
2199
+ }
2200
+ const parsedType = this._getType(input);
2201
+ if (parsedType !== ZodParsedType.number) {
2202
+ const ctx2 = this._getOrReturnCtx(input);
2203
+ addIssueToContext(ctx2, {
2204
+ code: ZodIssueCode.invalid_type,
2205
+ expected: ZodParsedType.number,
2206
+ received: ctx2.parsedType
2207
+ });
2208
+ return INVALID;
2209
+ }
2210
+ let ctx = void 0;
2211
+ const status = new ParseStatus();
2212
+ for (const check of this._def.checks) {
2213
+ if (check.kind === "int") {
2214
+ if (!util.isInteger(input.data)) {
2215
+ ctx = this._getOrReturnCtx(input, ctx);
2216
+ addIssueToContext(ctx, {
2217
+ code: ZodIssueCode.invalid_type,
2218
+ expected: "integer",
2219
+ received: "float",
2220
+ message: check.message
2221
+ });
2222
+ status.dirty();
2223
+ }
2224
+ } else if (check.kind === "min") {
2225
+ const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
2226
+ if (tooSmall) {
2227
+ ctx = this._getOrReturnCtx(input, ctx);
2228
+ addIssueToContext(ctx, {
2229
+ code: ZodIssueCode.too_small,
2230
+ minimum: check.value,
2231
+ type: "number",
2232
+ inclusive: check.inclusive,
2233
+ exact: false,
2234
+ message: check.message
2235
+ });
2236
+ status.dirty();
2237
+ }
2238
+ } else if (check.kind === "max") {
2239
+ const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
2240
+ if (tooBig) {
2241
+ ctx = this._getOrReturnCtx(input, ctx);
2242
+ addIssueToContext(ctx, {
2243
+ code: ZodIssueCode.too_big,
2244
+ maximum: check.value,
2245
+ type: "number",
2246
+ inclusive: check.inclusive,
2247
+ exact: false,
2248
+ message: check.message
2249
+ });
2250
+ status.dirty();
2251
+ }
2252
+ } else if (check.kind === "multipleOf") {
2253
+ if (floatSafeRemainder(input.data, check.value) !== 0) {
2254
+ ctx = this._getOrReturnCtx(input, ctx);
2255
+ addIssueToContext(ctx, {
2256
+ code: ZodIssueCode.not_multiple_of,
2257
+ multipleOf: check.value,
2258
+ message: check.message
2259
+ });
2260
+ status.dirty();
2261
+ }
2262
+ } else if (check.kind === "finite") {
2263
+ if (!Number.isFinite(input.data)) {
2264
+ ctx = this._getOrReturnCtx(input, ctx);
2265
+ addIssueToContext(ctx, {
2266
+ code: ZodIssueCode.not_finite,
2267
+ message: check.message
2268
+ });
2269
+ status.dirty();
2270
+ }
2271
+ } else {
2272
+ util.assertNever(check);
2273
+ }
2274
+ }
2275
+ return { status: status.value, value: input.data };
2276
+ }
2277
+ gte(value, message) {
2278
+ return this.setLimit("min", value, true, errorUtil.toString(message));
2279
+ }
2280
+ gt(value, message) {
2281
+ return this.setLimit("min", value, false, errorUtil.toString(message));
2282
+ }
2283
+ lte(value, message) {
2284
+ return this.setLimit("max", value, true, errorUtil.toString(message));
2285
+ }
2286
+ lt(value, message) {
2287
+ return this.setLimit("max", value, false, errorUtil.toString(message));
2288
+ }
2289
+ setLimit(kind, value, inclusive, message) {
2290
+ return new _ZodNumber({
2291
+ ...this._def,
2292
+ checks: [
2293
+ ...this._def.checks,
2294
+ {
2295
+ kind,
2296
+ value,
2297
+ inclusive,
2298
+ message: errorUtil.toString(message)
2299
+ }
2300
+ ]
2301
+ });
2302
+ }
2303
+ _addCheck(check) {
2304
+ return new _ZodNumber({
2305
+ ...this._def,
2306
+ checks: [...this._def.checks, check]
2307
+ });
2308
+ }
2309
+ int(message) {
2310
+ return this._addCheck({
2311
+ kind: "int",
2312
+ message: errorUtil.toString(message)
2313
+ });
2314
+ }
2315
+ positive(message) {
2316
+ return this._addCheck({
2317
+ kind: "min",
2318
+ value: 0,
2319
+ inclusive: false,
2320
+ message: errorUtil.toString(message)
2321
+ });
2322
+ }
2323
+ negative(message) {
2324
+ return this._addCheck({
2325
+ kind: "max",
2326
+ value: 0,
2327
+ inclusive: false,
2328
+ message: errorUtil.toString(message)
2329
+ });
2330
+ }
2331
+ nonpositive(message) {
2332
+ return this._addCheck({
2333
+ kind: "max",
2334
+ value: 0,
2335
+ inclusive: true,
2336
+ message: errorUtil.toString(message)
2337
+ });
2338
+ }
2339
+ nonnegative(message) {
2340
+ return this._addCheck({
2341
+ kind: "min",
2342
+ value: 0,
2343
+ inclusive: true,
2344
+ message: errorUtil.toString(message)
2345
+ });
2346
+ }
2347
+ multipleOf(value, message) {
2348
+ return this._addCheck({
2349
+ kind: "multipleOf",
2350
+ value,
2351
+ message: errorUtil.toString(message)
2352
+ });
2353
+ }
2354
+ finite(message) {
2355
+ return this._addCheck({
2356
+ kind: "finite",
2357
+ message: errorUtil.toString(message)
2358
+ });
2359
+ }
2360
+ get minValue() {
2361
+ let min = null;
2362
+ for (const ch of this._def.checks) {
2363
+ if (ch.kind === "min") {
2364
+ if (min === null || ch.value > min)
2365
+ min = ch.value;
2366
+ }
2367
+ }
2368
+ return min;
2369
+ }
2370
+ get maxValue() {
2371
+ let max = null;
2372
+ for (const ch of this._def.checks) {
2373
+ if (ch.kind === "max") {
2374
+ if (max === null || ch.value < max)
2375
+ max = ch.value;
2376
+ }
2377
+ }
2378
+ return max;
2379
+ }
2380
+ get isInt() {
2381
+ return !!this._def.checks.find((ch) => ch.kind === "int");
2382
+ }
2383
+ };
2384
+ ZodNumber.create = (params) => {
2385
+ return new ZodNumber({
2386
+ checks: [],
2387
+ typeName: ZodFirstPartyTypeKind.ZodNumber,
2388
+ coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
2389
+ ...processCreateParams(params)
2390
+ });
2391
+ };
2392
+ ZodBigInt = class extends ZodType {
2393
+ _parse(input) {
2394
+ if (this._def.coerce) {
2395
+ input.data = BigInt(input.data);
2396
+ }
2397
+ const parsedType = this._getType(input);
2398
+ if (parsedType !== ZodParsedType.bigint) {
2399
+ const ctx = this._getOrReturnCtx(input);
2400
+ addIssueToContext(ctx, {
2401
+ code: ZodIssueCode.invalid_type,
2402
+ expected: ZodParsedType.bigint,
2403
+ received: ctx.parsedType
2404
+ });
2405
+ return INVALID;
2406
+ }
2407
+ return OK(input.data);
2408
+ }
2409
+ };
2410
+ ZodBigInt.create = (params) => {
2411
+ var _a;
2412
+ return new ZodBigInt({
2413
+ typeName: ZodFirstPartyTypeKind.ZodBigInt,
2414
+ coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
2415
+ ...processCreateParams(params)
2416
+ });
2417
+ };
2418
+ ZodBoolean = class extends ZodType {
2419
+ _parse(input) {
2420
+ if (this._def.coerce) {
2421
+ input.data = Boolean(input.data);
2422
+ }
2423
+ const parsedType = this._getType(input);
2424
+ if (parsedType !== ZodParsedType.boolean) {
2425
+ const ctx = this._getOrReturnCtx(input);
2426
+ addIssueToContext(ctx, {
2427
+ code: ZodIssueCode.invalid_type,
2428
+ expected: ZodParsedType.boolean,
2429
+ received: ctx.parsedType
2430
+ });
2431
+ return INVALID;
2432
+ }
2433
+ return OK(input.data);
2434
+ }
2435
+ };
2436
+ ZodBoolean.create = (params) => {
2437
+ return new ZodBoolean({
2438
+ typeName: ZodFirstPartyTypeKind.ZodBoolean,
2439
+ coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
2440
+ ...processCreateParams(params)
2441
+ });
2442
+ };
2443
+ ZodDate = class _ZodDate extends ZodType {
2444
+ _parse(input) {
2445
+ if (this._def.coerce) {
2446
+ input.data = new Date(input.data);
2447
+ }
2448
+ const parsedType = this._getType(input);
2449
+ if (parsedType !== ZodParsedType.date) {
2450
+ const ctx2 = this._getOrReturnCtx(input);
2451
+ addIssueToContext(ctx2, {
2452
+ code: ZodIssueCode.invalid_type,
2453
+ expected: ZodParsedType.date,
2454
+ received: ctx2.parsedType
2455
+ });
2456
+ return INVALID;
2457
+ }
2458
+ if (isNaN(input.data.getTime())) {
2459
+ const ctx2 = this._getOrReturnCtx(input);
2460
+ addIssueToContext(ctx2, {
2461
+ code: ZodIssueCode.invalid_date
2462
+ });
2463
+ return INVALID;
2464
+ }
2465
+ const status = new ParseStatus();
2466
+ let ctx = void 0;
2467
+ for (const check of this._def.checks) {
2468
+ if (check.kind === "min") {
2469
+ if (input.data.getTime() < check.value) {
2470
+ ctx = this._getOrReturnCtx(input, ctx);
2471
+ addIssueToContext(ctx, {
2472
+ code: ZodIssueCode.too_small,
2473
+ message: check.message,
2474
+ inclusive: true,
2475
+ exact: false,
2476
+ minimum: check.value,
2477
+ type: "date"
2478
+ });
2479
+ status.dirty();
2480
+ }
2481
+ } else if (check.kind === "max") {
2482
+ if (input.data.getTime() > check.value) {
2483
+ ctx = this._getOrReturnCtx(input, ctx);
2484
+ addIssueToContext(ctx, {
2485
+ code: ZodIssueCode.too_big,
2486
+ message: check.message,
2487
+ inclusive: true,
2488
+ exact: false,
2489
+ maximum: check.value,
2490
+ type: "date"
2491
+ });
2492
+ status.dirty();
2493
+ }
2494
+ } else {
2495
+ util.assertNever(check);
2496
+ }
2497
+ }
2498
+ return {
2499
+ status: status.value,
2500
+ value: new Date(input.data.getTime())
2501
+ };
2502
+ }
2503
+ _addCheck(check) {
2504
+ return new _ZodDate({
2505
+ ...this._def,
2506
+ checks: [...this._def.checks, check]
2507
+ });
2508
+ }
2509
+ min(minDate, message) {
2510
+ return this._addCheck({
2511
+ kind: "min",
2512
+ value: minDate.getTime(),
2513
+ message: errorUtil.toString(message)
2514
+ });
2515
+ }
2516
+ max(maxDate, message) {
2517
+ return this._addCheck({
2518
+ kind: "max",
2519
+ value: maxDate.getTime(),
2520
+ message: errorUtil.toString(message)
2521
+ });
2522
+ }
2523
+ get minDate() {
2524
+ let min = null;
2525
+ for (const ch of this._def.checks) {
2526
+ if (ch.kind === "min") {
2527
+ if (min === null || ch.value > min)
2528
+ min = ch.value;
2529
+ }
2530
+ }
2531
+ return min != null ? new Date(min) : null;
2532
+ }
2533
+ get maxDate() {
2534
+ let max = null;
2535
+ for (const ch of this._def.checks) {
2536
+ if (ch.kind === "max") {
2537
+ if (max === null || ch.value < max)
2538
+ max = ch.value;
2539
+ }
2540
+ }
2541
+ return max != null ? new Date(max) : null;
2542
+ }
2543
+ };
2544
+ ZodDate.create = (params) => {
2545
+ return new ZodDate({
2546
+ checks: [],
2547
+ coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
2548
+ typeName: ZodFirstPartyTypeKind.ZodDate,
2549
+ ...processCreateParams(params)
2550
+ });
2551
+ };
2552
+ ZodSymbol = class extends ZodType {
2553
+ _parse(input) {
2554
+ const parsedType = this._getType(input);
2555
+ if (parsedType !== ZodParsedType.symbol) {
2556
+ const ctx = this._getOrReturnCtx(input);
2557
+ addIssueToContext(ctx, {
2558
+ code: ZodIssueCode.invalid_type,
2559
+ expected: ZodParsedType.symbol,
2560
+ received: ctx.parsedType
2561
+ });
2562
+ return INVALID;
2563
+ }
2564
+ return OK(input.data);
2565
+ }
2566
+ };
2567
+ ZodSymbol.create = (params) => {
2568
+ return new ZodSymbol({
2569
+ typeName: ZodFirstPartyTypeKind.ZodSymbol,
2570
+ ...processCreateParams(params)
2571
+ });
2572
+ };
2573
+ ZodUndefined = class extends ZodType {
2574
+ _parse(input) {
2575
+ const parsedType = this._getType(input);
2576
+ if (parsedType !== ZodParsedType.undefined) {
2577
+ const ctx = this._getOrReturnCtx(input);
2578
+ addIssueToContext(ctx, {
2579
+ code: ZodIssueCode.invalid_type,
2580
+ expected: ZodParsedType.undefined,
2581
+ received: ctx.parsedType
2582
+ });
2583
+ return INVALID;
2584
+ }
2585
+ return OK(input.data);
2586
+ }
2587
+ };
2588
+ ZodUndefined.create = (params) => {
2589
+ return new ZodUndefined({
2590
+ typeName: ZodFirstPartyTypeKind.ZodUndefined,
2591
+ ...processCreateParams(params)
2592
+ });
2593
+ };
2594
+ ZodNull = class extends ZodType {
2595
+ _parse(input) {
2596
+ const parsedType = this._getType(input);
2597
+ if (parsedType !== ZodParsedType.null) {
2598
+ const ctx = this._getOrReturnCtx(input);
2599
+ addIssueToContext(ctx, {
2600
+ code: ZodIssueCode.invalid_type,
2601
+ expected: ZodParsedType.null,
2602
+ received: ctx.parsedType
2603
+ });
2604
+ return INVALID;
2605
+ }
2606
+ return OK(input.data);
2607
+ }
2608
+ };
2609
+ ZodNull.create = (params) => {
2610
+ return new ZodNull({
2611
+ typeName: ZodFirstPartyTypeKind.ZodNull,
2612
+ ...processCreateParams(params)
2613
+ });
2614
+ };
2615
+ ZodAny = class extends ZodType {
2616
+ constructor() {
2617
+ super(...arguments);
2618
+ this._any = true;
2619
+ }
2620
+ _parse(input) {
2621
+ return OK(input.data);
2622
+ }
2623
+ };
2624
+ ZodAny.create = (params) => {
2625
+ return new ZodAny({
2626
+ typeName: ZodFirstPartyTypeKind.ZodAny,
2627
+ ...processCreateParams(params)
2628
+ });
2629
+ };
2630
+ ZodUnknown = class extends ZodType {
2631
+ constructor() {
2632
+ super(...arguments);
2633
+ this._unknown = true;
2634
+ }
2635
+ _parse(input) {
2636
+ return OK(input.data);
2637
+ }
2638
+ };
2639
+ ZodUnknown.create = (params) => {
2640
+ return new ZodUnknown({
2641
+ typeName: ZodFirstPartyTypeKind.ZodUnknown,
2642
+ ...processCreateParams(params)
2643
+ });
2644
+ };
2645
+ ZodNever = class extends ZodType {
2646
+ _parse(input) {
2647
+ const ctx = this._getOrReturnCtx(input);
2648
+ addIssueToContext(ctx, {
2649
+ code: ZodIssueCode.invalid_type,
2650
+ expected: ZodParsedType.never,
2651
+ received: ctx.parsedType
2652
+ });
2653
+ return INVALID;
2654
+ }
2655
+ };
2656
+ ZodNever.create = (params) => {
2657
+ return new ZodNever({
2658
+ typeName: ZodFirstPartyTypeKind.ZodNever,
2659
+ ...processCreateParams(params)
2660
+ });
2661
+ };
2662
+ ZodVoid = class extends ZodType {
2663
+ _parse(input) {
2664
+ const parsedType = this._getType(input);
2665
+ if (parsedType !== ZodParsedType.undefined) {
2666
+ const ctx = this._getOrReturnCtx(input);
2667
+ addIssueToContext(ctx, {
2668
+ code: ZodIssueCode.invalid_type,
2669
+ expected: ZodParsedType.void,
2670
+ received: ctx.parsedType
2671
+ });
2672
+ return INVALID;
2673
+ }
2674
+ return OK(input.data);
2675
+ }
2676
+ };
2677
+ ZodVoid.create = (params) => {
2678
+ return new ZodVoid({
2679
+ typeName: ZodFirstPartyTypeKind.ZodVoid,
2680
+ ...processCreateParams(params)
2681
+ });
2682
+ };
2683
+ ZodArray = class _ZodArray extends ZodType {
2684
+ _parse(input) {
2685
+ const { ctx, status } = this._processInputParams(input);
2686
+ const def = this._def;
2687
+ if (ctx.parsedType !== ZodParsedType.array) {
2688
+ addIssueToContext(ctx, {
2689
+ code: ZodIssueCode.invalid_type,
2690
+ expected: ZodParsedType.array,
2691
+ received: ctx.parsedType
2692
+ });
2693
+ return INVALID;
2694
+ }
2695
+ if (def.exactLength !== null) {
2696
+ const tooBig = ctx.data.length > def.exactLength.value;
2697
+ const tooSmall = ctx.data.length < def.exactLength.value;
2698
+ if (tooBig || tooSmall) {
2699
+ addIssueToContext(ctx, {
2700
+ code: tooBig ? ZodIssueCode.too_big : ZodIssueCode.too_small,
2701
+ minimum: tooSmall ? def.exactLength.value : void 0,
2702
+ maximum: tooBig ? def.exactLength.value : void 0,
2703
+ type: "array",
2704
+ inclusive: true,
2705
+ exact: true,
2706
+ message: def.exactLength.message
2707
+ });
2708
+ status.dirty();
2709
+ }
2710
+ }
2711
+ if (def.minLength !== null) {
2712
+ if (ctx.data.length < def.minLength.value) {
2713
+ addIssueToContext(ctx, {
2714
+ code: ZodIssueCode.too_small,
2715
+ minimum: def.minLength.value,
2716
+ type: "array",
2717
+ inclusive: true,
2718
+ exact: false,
2719
+ message: def.minLength.message
2720
+ });
2721
+ status.dirty();
2722
+ }
2723
+ }
2724
+ if (def.maxLength !== null) {
2725
+ if (ctx.data.length > def.maxLength.value) {
2726
+ addIssueToContext(ctx, {
2727
+ code: ZodIssueCode.too_big,
2728
+ maximum: def.maxLength.value,
2729
+ type: "array",
2730
+ inclusive: true,
2731
+ exact: false,
2732
+ message: def.maxLength.message
2733
+ });
2734
+ status.dirty();
2735
+ }
2736
+ }
2737
+ if (ctx.common.async) {
2738
+ return Promise.all(ctx.data.map((item, i) => {
2739
+ return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
2740
+ })).then((result2) => {
2741
+ return ParseStatus.mergeArray(status, result2);
2742
+ });
2743
+ }
2744
+ const result = ctx.data.map((item, i) => {
2745
+ return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
2746
+ });
2747
+ return ParseStatus.mergeArray(status, result);
2748
+ }
2749
+ get element() {
2750
+ return this._def.type;
2751
+ }
2752
+ min(minLength, message) {
2753
+ return new _ZodArray({
2754
+ ...this._def,
2755
+ minLength: { value: minLength, message: errorUtil.toString(message) }
2756
+ });
2757
+ }
2758
+ max(maxLength, message) {
2759
+ return new _ZodArray({
2760
+ ...this._def,
2761
+ maxLength: { value: maxLength, message: errorUtil.toString(message) }
2762
+ });
2763
+ }
2764
+ length(len, message) {
2765
+ return new _ZodArray({
2766
+ ...this._def,
2767
+ exactLength: { value: len, message: errorUtil.toString(message) }
2768
+ });
2769
+ }
2770
+ nonempty(message) {
2771
+ return this.min(1, message);
2772
+ }
2773
+ };
2774
+ ZodArray.create = (schema3, params) => {
2775
+ return new ZodArray({
2776
+ type: schema3,
2777
+ minLength: null,
2778
+ maxLength: null,
2779
+ exactLength: null,
2780
+ typeName: ZodFirstPartyTypeKind.ZodArray,
2781
+ ...processCreateParams(params)
2782
+ });
2783
+ };
2784
+ (function(objectUtil2) {
2785
+ objectUtil2.mergeShapes = (first, second) => {
2786
+ return {
2787
+ ...first,
2788
+ ...second
2789
+ // second overwrites first
2790
+ };
2791
+ };
2792
+ })(objectUtil || (objectUtil = {}));
2793
+ AugmentFactory = (def) => (augmentation) => {
2794
+ return new ZodObject({
2795
+ ...def,
2796
+ shape: () => ({
2797
+ ...def.shape(),
2798
+ ...augmentation
2799
+ })
2800
+ });
2801
+ };
2802
+ ZodObject = class _ZodObject extends ZodType {
2803
+ constructor() {
2804
+ super(...arguments);
2805
+ this._cached = null;
2806
+ this.nonstrict = this.passthrough;
2807
+ this.augment = AugmentFactory(this._def);
2808
+ this.extend = AugmentFactory(this._def);
2809
+ }
2810
+ _getCached() {
2811
+ if (this._cached !== null)
2812
+ return this._cached;
2813
+ const shape = this._def.shape();
2814
+ const keys = util.objectKeys(shape);
2815
+ return this._cached = { shape, keys };
2816
+ }
2817
+ _parse(input) {
2818
+ const parsedType = this._getType(input);
2819
+ if (parsedType !== ZodParsedType.object) {
2820
+ const ctx2 = this._getOrReturnCtx(input);
2821
+ addIssueToContext(ctx2, {
2822
+ code: ZodIssueCode.invalid_type,
2823
+ expected: ZodParsedType.object,
2824
+ received: ctx2.parsedType
2825
+ });
2826
+ return INVALID;
2827
+ }
2828
+ const { status, ctx } = this._processInputParams(input);
2829
+ const { shape, keys: shapeKeys } = this._getCached();
2830
+ const extraKeys = [];
2831
+ if (!(this._def.catchall instanceof ZodNever && this._def.unknownKeys === "strip")) {
2832
+ for (const key in ctx.data) {
2833
+ if (!shapeKeys.includes(key)) {
2834
+ extraKeys.push(key);
2835
+ }
2836
+ }
2837
+ }
2838
+ const pairs = [];
2839
+ for (const key of shapeKeys) {
2840
+ const keyValidator = shape[key];
2841
+ const value = ctx.data[key];
2842
+ pairs.push({
2843
+ key: { status: "valid", value: key },
2844
+ value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
2845
+ alwaysSet: key in ctx.data
2846
+ });
2847
+ }
2848
+ if (this._def.catchall instanceof ZodNever) {
2849
+ const unknownKeys = this._def.unknownKeys;
2850
+ if (unknownKeys === "passthrough") {
2851
+ for (const key of extraKeys) {
2852
+ pairs.push({
2853
+ key: { status: "valid", value: key },
2854
+ value: { status: "valid", value: ctx.data[key] }
2855
+ });
2856
+ }
2857
+ } else if (unknownKeys === "strict") {
2858
+ if (extraKeys.length > 0) {
2859
+ addIssueToContext(ctx, {
2860
+ code: ZodIssueCode.unrecognized_keys,
2861
+ keys: extraKeys
2862
+ });
2863
+ status.dirty();
2864
+ }
2865
+ } else if (unknownKeys === "strip")
2866
+ ;
2867
+ else {
2868
+ throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
2869
+ }
2870
+ } else {
2871
+ const catchall = this._def.catchall;
2872
+ for (const key of extraKeys) {
2873
+ const value = ctx.data[key];
2874
+ pairs.push({
2875
+ key: { status: "valid", value: key },
2876
+ value: catchall._parse(
2877
+ new ParseInputLazyPath(ctx, value, ctx.path, key)
2878
+ //, ctx.child(key), value, getParsedType(value)
2879
+ ),
2880
+ alwaysSet: key in ctx.data
2881
+ });
2882
+ }
2883
+ }
2884
+ if (ctx.common.async) {
2885
+ return Promise.resolve().then(async () => {
2886
+ const syncPairs = [];
2887
+ for (const pair of pairs) {
2888
+ const key = await pair.key;
2889
+ syncPairs.push({
2890
+ key,
2891
+ value: await pair.value,
2892
+ alwaysSet: pair.alwaysSet
2893
+ });
2894
+ }
2895
+ return syncPairs;
2896
+ }).then((syncPairs) => {
2897
+ return ParseStatus.mergeObjectSync(status, syncPairs);
2898
+ });
2899
+ } else {
2900
+ return ParseStatus.mergeObjectSync(status, pairs);
2901
+ }
2902
+ }
2903
+ get shape() {
2904
+ return this._def.shape();
2905
+ }
2906
+ strict(message) {
2907
+ errorUtil.errToObj;
2908
+ return new _ZodObject({
2909
+ ...this._def,
2910
+ unknownKeys: "strict",
2911
+ ...message !== void 0 ? {
2912
+ errorMap: (issue, ctx) => {
2913
+ var _a, _b, _c, _d;
2914
+ 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;
2915
+ if (issue.code === "unrecognized_keys")
2916
+ return {
2917
+ message: (_d = errorUtil.errToObj(message).message) !== null && _d !== void 0 ? _d : defaultError
2918
+ };
2919
+ return {
2920
+ message: defaultError
2921
+ };
2922
+ }
2923
+ } : {}
2924
+ });
2925
+ }
2926
+ strip() {
2927
+ return new _ZodObject({
2928
+ ...this._def,
2929
+ unknownKeys: "strip"
2930
+ });
2931
+ }
2932
+ passthrough() {
2933
+ return new _ZodObject({
2934
+ ...this._def,
2935
+ unknownKeys: "passthrough"
2936
+ });
2937
+ }
2938
+ setKey(key, schema3) {
2939
+ return this.augment({ [key]: schema3 });
2940
+ }
2941
+ /**
2942
+ * Prior to zod@1.0.12 there was a bug in the
2943
+ * inferred type of merged objects. Please
2944
+ * upgrade if you are experiencing issues.
2945
+ */
2946
+ merge(merging) {
2947
+ const merged = new _ZodObject({
2948
+ unknownKeys: merging._def.unknownKeys,
2949
+ catchall: merging._def.catchall,
2950
+ shape: () => objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
2951
+ typeName: ZodFirstPartyTypeKind.ZodObject
2952
+ });
2953
+ return merged;
2954
+ }
2955
+ catchall(index4) {
2956
+ return new _ZodObject({
2957
+ ...this._def,
2958
+ catchall: index4
2959
+ });
2960
+ }
2961
+ pick(mask) {
2962
+ const shape = {};
2963
+ util.objectKeys(mask).map((key) => {
2964
+ if (this.shape[key])
2965
+ shape[key] = this.shape[key];
2966
+ });
2967
+ return new _ZodObject({
2968
+ ...this._def,
2969
+ shape: () => shape
2970
+ });
2971
+ }
2972
+ omit(mask) {
2973
+ const shape = {};
2974
+ util.objectKeys(this.shape).map((key) => {
2975
+ if (util.objectKeys(mask).indexOf(key) === -1) {
2976
+ shape[key] = this.shape[key];
2977
+ }
2978
+ });
2979
+ return new _ZodObject({
2980
+ ...this._def,
2981
+ shape: () => shape
2982
+ });
2983
+ }
2984
+ deepPartial() {
2985
+ return deepPartialify(this);
2986
+ }
2987
+ partial(mask) {
2988
+ const newShape = {};
2989
+ if (mask) {
2990
+ util.objectKeys(this.shape).map((key) => {
2991
+ if (util.objectKeys(mask).indexOf(key) === -1) {
2992
+ newShape[key] = this.shape[key];
2993
+ } else {
2994
+ newShape[key] = this.shape[key].optional();
2995
+ }
2996
+ });
2997
+ return new _ZodObject({
2998
+ ...this._def,
2999
+ shape: () => newShape
3000
+ });
3001
+ } else {
3002
+ for (const key in this.shape) {
3003
+ const fieldSchema = this.shape[key];
3004
+ newShape[key] = fieldSchema.optional();
3005
+ }
3006
+ }
3007
+ return new _ZodObject({
3008
+ ...this._def,
3009
+ shape: () => newShape
3010
+ });
3011
+ }
3012
+ required(mask) {
3013
+ const newShape = {};
3014
+ if (mask) {
3015
+ util.objectKeys(this.shape).map((key) => {
3016
+ if (util.objectKeys(mask).indexOf(key) === -1) {
3017
+ newShape[key] = this.shape[key];
3018
+ } else {
3019
+ const fieldSchema = this.shape[key];
3020
+ let newField = fieldSchema;
3021
+ while (newField instanceof ZodOptional) {
3022
+ newField = newField._def.innerType;
3023
+ }
3024
+ newShape[key] = newField;
3025
+ }
3026
+ });
3027
+ } else {
3028
+ for (const key in this.shape) {
3029
+ const fieldSchema = this.shape[key];
3030
+ let newField = fieldSchema;
3031
+ while (newField instanceof ZodOptional) {
3032
+ newField = newField._def.innerType;
3033
+ }
3034
+ newShape[key] = newField;
3035
+ }
3036
+ }
3037
+ return new _ZodObject({
3038
+ ...this._def,
3039
+ shape: () => newShape
3040
+ });
3041
+ }
3042
+ keyof() {
3043
+ return createZodEnum(util.objectKeys(this.shape));
3044
+ }
3045
+ };
3046
+ ZodObject.create = (shape, params) => {
3047
+ return new ZodObject({
3048
+ shape: () => shape,
3049
+ unknownKeys: "strip",
3050
+ catchall: ZodNever.create(),
3051
+ typeName: ZodFirstPartyTypeKind.ZodObject,
3052
+ ...processCreateParams(params)
3053
+ });
3054
+ };
3055
+ ZodObject.strictCreate = (shape, params) => {
3056
+ return new ZodObject({
3057
+ shape: () => shape,
3058
+ unknownKeys: "strict",
3059
+ catchall: ZodNever.create(),
3060
+ typeName: ZodFirstPartyTypeKind.ZodObject,
3061
+ ...processCreateParams(params)
3062
+ });
3063
+ };
3064
+ ZodObject.lazycreate = (shape, params) => {
3065
+ return new ZodObject({
3066
+ shape,
3067
+ unknownKeys: "strip",
3068
+ catchall: ZodNever.create(),
3069
+ typeName: ZodFirstPartyTypeKind.ZodObject,
3070
+ ...processCreateParams(params)
3071
+ });
3072
+ };
3073
+ ZodUnion = class extends ZodType {
3074
+ _parse(input) {
3075
+ const { ctx } = this._processInputParams(input);
3076
+ const options = this._def.options;
3077
+ function handleResults(results) {
3078
+ for (const result of results) {
3079
+ if (result.result.status === "valid") {
3080
+ return result.result;
3081
+ }
3082
+ }
3083
+ for (const result of results) {
3084
+ if (result.result.status === "dirty") {
3085
+ ctx.common.issues.push(...result.ctx.common.issues);
3086
+ return result.result;
3087
+ }
3088
+ }
3089
+ const unionErrors = results.map((result) => new ZodError(result.ctx.common.issues));
3090
+ addIssueToContext(ctx, {
3091
+ code: ZodIssueCode.invalid_union,
3092
+ unionErrors
3093
+ });
3094
+ return INVALID;
3095
+ }
3096
+ if (ctx.common.async) {
3097
+ return Promise.all(options.map(async (option) => {
3098
+ const childCtx = {
3099
+ ...ctx,
3100
+ common: {
3101
+ ...ctx.common,
3102
+ issues: []
3103
+ },
3104
+ parent: null
3105
+ };
3106
+ return {
3107
+ result: await option._parseAsync({
3108
+ data: ctx.data,
3109
+ path: ctx.path,
3110
+ parent: childCtx
3111
+ }),
3112
+ ctx: childCtx
3113
+ };
3114
+ })).then(handleResults);
3115
+ } else {
3116
+ let dirty = void 0;
3117
+ const issues = [];
3118
+ for (const option of options) {
3119
+ const childCtx = {
3120
+ ...ctx,
3121
+ common: {
3122
+ ...ctx.common,
3123
+ issues: []
3124
+ },
3125
+ parent: null
3126
+ };
3127
+ const result = option._parseSync({
3128
+ data: ctx.data,
3129
+ path: ctx.path,
3130
+ parent: childCtx
3131
+ });
3132
+ if (result.status === "valid") {
3133
+ return result;
3134
+ } else if (result.status === "dirty" && !dirty) {
3135
+ dirty = { result, ctx: childCtx };
3136
+ }
3137
+ if (childCtx.common.issues.length) {
3138
+ issues.push(childCtx.common.issues);
3139
+ }
3140
+ }
3141
+ if (dirty) {
3142
+ ctx.common.issues.push(...dirty.ctx.common.issues);
3143
+ return dirty.result;
3144
+ }
3145
+ const unionErrors = issues.map((issues2) => new ZodError(issues2));
3146
+ addIssueToContext(ctx, {
3147
+ code: ZodIssueCode.invalid_union,
3148
+ unionErrors
3149
+ });
3150
+ return INVALID;
3151
+ }
3152
+ }
3153
+ get options() {
3154
+ return this._def.options;
3155
+ }
3156
+ };
3157
+ ZodUnion.create = (types, params) => {
3158
+ return new ZodUnion({
3159
+ options: types,
3160
+ typeName: ZodFirstPartyTypeKind.ZodUnion,
3161
+ ...processCreateParams(params)
3162
+ });
3163
+ };
3164
+ getDiscriminator = (type) => {
3165
+ if (type instanceof ZodLazy) {
3166
+ return getDiscriminator(type.schema);
3167
+ } else if (type instanceof ZodEffects) {
3168
+ return getDiscriminator(type.innerType());
3169
+ } else if (type instanceof ZodLiteral) {
3170
+ return [type.value];
3171
+ } else if (type instanceof ZodEnum) {
3172
+ return type.options;
3173
+ } else if (type instanceof ZodNativeEnum) {
3174
+ return Object.keys(type.enum);
3175
+ } else if (type instanceof ZodDefault) {
3176
+ return getDiscriminator(type._def.innerType);
3177
+ } else if (type instanceof ZodUndefined) {
3178
+ return [void 0];
3179
+ } else if (type instanceof ZodNull) {
3180
+ return [null];
3181
+ } else {
3182
+ return null;
3183
+ }
3184
+ };
3185
+ ZodDiscriminatedUnion = class _ZodDiscriminatedUnion extends ZodType {
3186
+ _parse(input) {
3187
+ const { ctx } = this._processInputParams(input);
3188
+ if (ctx.parsedType !== ZodParsedType.object) {
3189
+ addIssueToContext(ctx, {
3190
+ code: ZodIssueCode.invalid_type,
3191
+ expected: ZodParsedType.object,
3192
+ received: ctx.parsedType
3193
+ });
3194
+ return INVALID;
3195
+ }
3196
+ const discriminator = this.discriminator;
3197
+ const discriminatorValue = ctx.data[discriminator];
3198
+ const option = this.optionsMap.get(discriminatorValue);
3199
+ if (!option) {
3200
+ addIssueToContext(ctx, {
3201
+ code: ZodIssueCode.invalid_union_discriminator,
3202
+ options: Array.from(this.optionsMap.keys()),
3203
+ path: [discriminator]
3204
+ });
3205
+ return INVALID;
3206
+ }
3207
+ if (ctx.common.async) {
3208
+ return option._parseAsync({
3209
+ data: ctx.data,
3210
+ path: ctx.path,
3211
+ parent: ctx
3212
+ });
3213
+ } else {
3214
+ return option._parseSync({
3215
+ data: ctx.data,
3216
+ path: ctx.path,
3217
+ parent: ctx
3218
+ });
3219
+ }
3220
+ }
3221
+ get discriminator() {
3222
+ return this._def.discriminator;
3223
+ }
3224
+ get options() {
3225
+ return this._def.options;
3226
+ }
3227
+ get optionsMap() {
3228
+ return this._def.optionsMap;
3229
+ }
3230
+ /**
3231
+ * The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
3232
+ * However, it only allows a union of objects, all of which need to share a discriminator property. This property must
3233
+ * have a different value for each object in the union.
3234
+ * @param discriminator the name of the discriminator property
3235
+ * @param types an array of object schemas
3236
+ * @param params
3237
+ */
3238
+ static create(discriminator, options, params) {
3239
+ const optionsMap = /* @__PURE__ */ new Map();
3240
+ for (const type of options) {
3241
+ const discriminatorValues = getDiscriminator(type.shape[discriminator]);
3242
+ if (!discriminatorValues) {
3243
+ throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
3244
+ }
3245
+ for (const value of discriminatorValues) {
3246
+ if (optionsMap.has(value)) {
3247
+ throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
3248
+ }
3249
+ optionsMap.set(value, type);
3250
+ }
3251
+ }
3252
+ return new _ZodDiscriminatedUnion({
3253
+ typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
3254
+ discriminator,
3255
+ options,
3256
+ optionsMap,
3257
+ ...processCreateParams(params)
3258
+ });
3259
+ }
3260
+ };
3261
+ ZodIntersection = class extends ZodType {
3262
+ _parse(input) {
3263
+ const { status, ctx } = this._processInputParams(input);
3264
+ const handleParsed = (parsedLeft, parsedRight) => {
3265
+ if (isAborted(parsedLeft) || isAborted(parsedRight)) {
3266
+ return INVALID;
3267
+ }
3268
+ const merged = mergeValues(parsedLeft.value, parsedRight.value);
3269
+ if (!merged.valid) {
3270
+ addIssueToContext(ctx, {
3271
+ code: ZodIssueCode.invalid_intersection_types
3272
+ });
3273
+ return INVALID;
3274
+ }
3275
+ if (isDirty(parsedLeft) || isDirty(parsedRight)) {
3276
+ status.dirty();
3277
+ }
3278
+ return { status: status.value, value: merged.data };
3279
+ };
3280
+ if (ctx.common.async) {
3281
+ return Promise.all([
3282
+ this._def.left._parseAsync({
3283
+ data: ctx.data,
3284
+ path: ctx.path,
3285
+ parent: ctx
3286
+ }),
3287
+ this._def.right._parseAsync({
3288
+ data: ctx.data,
3289
+ path: ctx.path,
3290
+ parent: ctx
3291
+ })
3292
+ ]).then(([left, right]) => handleParsed(left, right));
3293
+ } else {
3294
+ return handleParsed(this._def.left._parseSync({
3295
+ data: ctx.data,
3296
+ path: ctx.path,
3297
+ parent: ctx
3298
+ }), this._def.right._parseSync({
3299
+ data: ctx.data,
3300
+ path: ctx.path,
3301
+ parent: ctx
3302
+ }));
3303
+ }
3304
+ }
3305
+ };
3306
+ ZodIntersection.create = (left, right, params) => {
3307
+ return new ZodIntersection({
3308
+ left,
3309
+ right,
3310
+ typeName: ZodFirstPartyTypeKind.ZodIntersection,
3311
+ ...processCreateParams(params)
3312
+ });
3313
+ };
3314
+ ZodTuple = class _ZodTuple extends ZodType {
3315
+ _parse(input) {
3316
+ const { status, ctx } = this._processInputParams(input);
3317
+ if (ctx.parsedType !== ZodParsedType.array) {
3318
+ addIssueToContext(ctx, {
3319
+ code: ZodIssueCode.invalid_type,
3320
+ expected: ZodParsedType.array,
3321
+ received: ctx.parsedType
3322
+ });
3323
+ return INVALID;
3324
+ }
3325
+ if (ctx.data.length < this._def.items.length) {
3326
+ addIssueToContext(ctx, {
3327
+ code: ZodIssueCode.too_small,
3328
+ minimum: this._def.items.length,
3329
+ inclusive: true,
3330
+ exact: false,
3331
+ type: "array"
3332
+ });
3333
+ return INVALID;
3334
+ }
3335
+ const rest = this._def.rest;
3336
+ if (!rest && ctx.data.length > this._def.items.length) {
3337
+ addIssueToContext(ctx, {
3338
+ code: ZodIssueCode.too_big,
3339
+ maximum: this._def.items.length,
3340
+ inclusive: true,
3341
+ exact: false,
3342
+ type: "array"
3343
+ });
3344
+ status.dirty();
3345
+ }
3346
+ const items = ctx.data.map((item, itemIndex) => {
3347
+ const schema3 = this._def.items[itemIndex] || this._def.rest;
3348
+ if (!schema3)
3349
+ return null;
3350
+ return schema3._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
3351
+ }).filter((x) => !!x);
3352
+ if (ctx.common.async) {
3353
+ return Promise.all(items).then((results) => {
3354
+ return ParseStatus.mergeArray(status, results);
3355
+ });
3356
+ } else {
3357
+ return ParseStatus.mergeArray(status, items);
3358
+ }
3359
+ }
3360
+ get items() {
3361
+ return this._def.items;
3362
+ }
3363
+ rest(rest) {
3364
+ return new _ZodTuple({
3365
+ ...this._def,
3366
+ rest
3367
+ });
3368
+ }
3369
+ };
3370
+ ZodTuple.create = (schemas, params) => {
3371
+ if (!Array.isArray(schemas)) {
3372
+ throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
3373
+ }
3374
+ return new ZodTuple({
3375
+ items: schemas,
3376
+ typeName: ZodFirstPartyTypeKind.ZodTuple,
3377
+ rest: null,
3378
+ ...processCreateParams(params)
3379
+ });
3380
+ };
3381
+ ZodRecord = class _ZodRecord extends ZodType {
3382
+ get keySchema() {
3383
+ return this._def.keyType;
3384
+ }
3385
+ get valueSchema() {
3386
+ return this._def.valueType;
3387
+ }
3388
+ _parse(input) {
3389
+ const { status, ctx } = this._processInputParams(input);
3390
+ if (ctx.parsedType !== ZodParsedType.object) {
3391
+ addIssueToContext(ctx, {
3392
+ code: ZodIssueCode.invalid_type,
3393
+ expected: ZodParsedType.object,
3394
+ received: ctx.parsedType
3395
+ });
3396
+ return INVALID;
3397
+ }
3398
+ const pairs = [];
3399
+ const keyType = this._def.keyType;
3400
+ const valueType = this._def.valueType;
3401
+ for (const key in ctx.data) {
3402
+ pairs.push({
3403
+ key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
3404
+ value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key))
3405
+ });
3406
+ }
3407
+ if (ctx.common.async) {
3408
+ return ParseStatus.mergeObjectAsync(status, pairs);
3409
+ } else {
3410
+ return ParseStatus.mergeObjectSync(status, pairs);
3411
+ }
3412
+ }
3413
+ get element() {
3414
+ return this._def.valueType;
3415
+ }
3416
+ static create(first, second, third) {
3417
+ if (second instanceof ZodType) {
3418
+ return new _ZodRecord({
3419
+ keyType: first,
3420
+ valueType: second,
3421
+ typeName: ZodFirstPartyTypeKind.ZodRecord,
3422
+ ...processCreateParams(third)
3423
+ });
3424
+ }
3425
+ return new _ZodRecord({
3426
+ keyType: ZodString.create(),
3427
+ valueType: first,
3428
+ typeName: ZodFirstPartyTypeKind.ZodRecord,
3429
+ ...processCreateParams(second)
3430
+ });
3431
+ }
3432
+ };
3433
+ ZodMap = class extends ZodType {
3434
+ _parse(input) {
3435
+ const { status, ctx } = this._processInputParams(input);
3436
+ if (ctx.parsedType !== ZodParsedType.map) {
3437
+ addIssueToContext(ctx, {
3438
+ code: ZodIssueCode.invalid_type,
3439
+ expected: ZodParsedType.map,
3440
+ received: ctx.parsedType
3441
+ });
3442
+ return INVALID;
3443
+ }
3444
+ const keyType = this._def.keyType;
3445
+ const valueType = this._def.valueType;
3446
+ const pairs = [...ctx.data.entries()].map(([key, value], index4) => {
3447
+ return {
3448
+ key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index4, "key"])),
3449
+ value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index4, "value"]))
3450
+ };
3451
+ });
3452
+ if (ctx.common.async) {
3453
+ const finalMap = /* @__PURE__ */ new Map();
3454
+ return Promise.resolve().then(async () => {
3455
+ for (const pair of pairs) {
3456
+ const key = await pair.key;
3457
+ const value = await pair.value;
3458
+ if (key.status === "aborted" || value.status === "aborted") {
3459
+ return INVALID;
3460
+ }
3461
+ if (key.status === "dirty" || value.status === "dirty") {
3462
+ status.dirty();
3463
+ }
3464
+ finalMap.set(key.value, value.value);
3465
+ }
3466
+ return { status: status.value, value: finalMap };
3467
+ });
3468
+ } else {
3469
+ const finalMap = /* @__PURE__ */ new Map();
3470
+ for (const pair of pairs) {
3471
+ const key = pair.key;
3472
+ const value = pair.value;
3473
+ if (key.status === "aborted" || value.status === "aborted") {
3474
+ return INVALID;
3475
+ }
3476
+ if (key.status === "dirty" || value.status === "dirty") {
3477
+ status.dirty();
3478
+ }
3479
+ finalMap.set(key.value, value.value);
3480
+ }
3481
+ return { status: status.value, value: finalMap };
3482
+ }
3483
+ }
3484
+ };
3485
+ ZodMap.create = (keyType, valueType, params) => {
3486
+ return new ZodMap({
3487
+ valueType,
3488
+ keyType,
3489
+ typeName: ZodFirstPartyTypeKind.ZodMap,
3490
+ ...processCreateParams(params)
3491
+ });
3492
+ };
3493
+ ZodSet = class _ZodSet extends ZodType {
3494
+ _parse(input) {
3495
+ const { status, ctx } = this._processInputParams(input);
3496
+ if (ctx.parsedType !== ZodParsedType.set) {
3497
+ addIssueToContext(ctx, {
3498
+ code: ZodIssueCode.invalid_type,
3499
+ expected: ZodParsedType.set,
3500
+ received: ctx.parsedType
3501
+ });
3502
+ return INVALID;
3503
+ }
3504
+ const def = this._def;
3505
+ if (def.minSize !== null) {
3506
+ if (ctx.data.size < def.minSize.value) {
3507
+ addIssueToContext(ctx, {
3508
+ code: ZodIssueCode.too_small,
3509
+ minimum: def.minSize.value,
3510
+ type: "set",
3511
+ inclusive: true,
3512
+ exact: false,
3513
+ message: def.minSize.message
3514
+ });
3515
+ status.dirty();
3516
+ }
3517
+ }
3518
+ if (def.maxSize !== null) {
3519
+ if (ctx.data.size > def.maxSize.value) {
3520
+ addIssueToContext(ctx, {
3521
+ code: ZodIssueCode.too_big,
3522
+ maximum: def.maxSize.value,
3523
+ type: "set",
3524
+ inclusive: true,
3525
+ exact: false,
3526
+ message: def.maxSize.message
3527
+ });
3528
+ status.dirty();
3529
+ }
3530
+ }
3531
+ const valueType = this._def.valueType;
3532
+ function finalizeSet(elements2) {
3533
+ const parsedSet = /* @__PURE__ */ new Set();
3534
+ for (const element of elements2) {
3535
+ if (element.status === "aborted")
3536
+ return INVALID;
3537
+ if (element.status === "dirty")
3538
+ status.dirty();
3539
+ parsedSet.add(element.value);
3540
+ }
3541
+ return { status: status.value, value: parsedSet };
3542
+ }
3543
+ const elements = [...ctx.data.values()].map((item, i) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
3544
+ if (ctx.common.async) {
3545
+ return Promise.all(elements).then((elements2) => finalizeSet(elements2));
3546
+ } else {
3547
+ return finalizeSet(elements);
3548
+ }
3549
+ }
3550
+ min(minSize, message) {
3551
+ return new _ZodSet({
3552
+ ...this._def,
3553
+ minSize: { value: minSize, message: errorUtil.toString(message) }
3554
+ });
3555
+ }
3556
+ max(maxSize, message) {
3557
+ return new _ZodSet({
3558
+ ...this._def,
3559
+ maxSize: { value: maxSize, message: errorUtil.toString(message) }
3560
+ });
3561
+ }
3562
+ size(size, message) {
3563
+ return this.min(size, message).max(size, message);
3564
+ }
3565
+ nonempty(message) {
3566
+ return this.min(1, message);
3567
+ }
3568
+ };
3569
+ ZodSet.create = (valueType, params) => {
3570
+ return new ZodSet({
3571
+ valueType,
3572
+ minSize: null,
3573
+ maxSize: null,
3574
+ typeName: ZodFirstPartyTypeKind.ZodSet,
3575
+ ...processCreateParams(params)
3576
+ });
3577
+ };
3578
+ ZodFunction = class _ZodFunction extends ZodType {
3579
+ constructor() {
3580
+ super(...arguments);
3581
+ this.validate = this.implement;
3582
+ }
3583
+ _parse(input) {
3584
+ const { ctx } = this._processInputParams(input);
3585
+ if (ctx.parsedType !== ZodParsedType.function) {
3586
+ addIssueToContext(ctx, {
3587
+ code: ZodIssueCode.invalid_type,
3588
+ expected: ZodParsedType.function,
3589
+ received: ctx.parsedType
3590
+ });
3591
+ return INVALID;
3592
+ }
3593
+ function makeArgsIssue(args, error2) {
3594
+ return makeIssue({
3595
+ data: args,
3596
+ path: ctx.path,
3597
+ errorMaps: [
3598
+ ctx.common.contextualErrorMap,
3599
+ ctx.schemaErrorMap,
3600
+ getErrorMap(),
3601
+ errorMap
3602
+ ].filter((x) => !!x),
3603
+ issueData: {
3604
+ code: ZodIssueCode.invalid_arguments,
3605
+ argumentsError: error2
3606
+ }
3607
+ });
3608
+ }
3609
+ function makeReturnsIssue(returns, error2) {
3610
+ return makeIssue({
3611
+ data: returns,
3612
+ path: ctx.path,
3613
+ errorMaps: [
3614
+ ctx.common.contextualErrorMap,
3615
+ ctx.schemaErrorMap,
3616
+ getErrorMap(),
3617
+ errorMap
3618
+ ].filter((x) => !!x),
3619
+ issueData: {
3620
+ code: ZodIssueCode.invalid_return_type,
3621
+ returnTypeError: error2
3622
+ }
3623
+ });
3624
+ }
3625
+ const params = { errorMap: ctx.common.contextualErrorMap };
3626
+ const fn = ctx.data;
3627
+ if (this._def.returns instanceof ZodPromise) {
3628
+ return OK(async (...args) => {
3629
+ const error2 = new ZodError([]);
3630
+ const parsedArgs = await this._def.args.parseAsync(args, params).catch((e) => {
3631
+ error2.addIssue(makeArgsIssue(args, e));
3632
+ throw error2;
3633
+ });
3634
+ const result = await fn(...parsedArgs);
3635
+ const parsedReturns = await this._def.returns._def.type.parseAsync(result, params).catch((e) => {
3636
+ error2.addIssue(makeReturnsIssue(result, e));
3637
+ throw error2;
3638
+ });
3639
+ return parsedReturns;
3640
+ });
3641
+ } else {
3642
+ return OK((...args) => {
3643
+ const parsedArgs = this._def.args.safeParse(args, params);
3644
+ if (!parsedArgs.success) {
3645
+ throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
3646
+ }
3647
+ const result = fn(...parsedArgs.data);
3648
+ const parsedReturns = this._def.returns.safeParse(result, params);
3649
+ if (!parsedReturns.success) {
3650
+ throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
3651
+ }
3652
+ return parsedReturns.data;
3653
+ });
3654
+ }
3655
+ }
3656
+ parameters() {
3657
+ return this._def.args;
3658
+ }
3659
+ returnType() {
3660
+ return this._def.returns;
3661
+ }
3662
+ args(...items) {
3663
+ return new _ZodFunction({
3664
+ ...this._def,
3665
+ args: ZodTuple.create(items).rest(ZodUnknown.create())
3666
+ });
3667
+ }
3668
+ returns(returnType) {
3669
+ return new _ZodFunction({
3670
+ ...this._def,
3671
+ returns: returnType
3672
+ });
3673
+ }
3674
+ implement(func) {
3675
+ const validatedFunc = this.parse(func);
3676
+ return validatedFunc;
3677
+ }
3678
+ strictImplement(func) {
3679
+ const validatedFunc = this.parse(func);
3680
+ return validatedFunc;
3681
+ }
3682
+ static create(args, returns, params) {
3683
+ return new _ZodFunction({
3684
+ args: args ? args : ZodTuple.create([]).rest(ZodUnknown.create()),
3685
+ returns: returns || ZodUnknown.create(),
3686
+ typeName: ZodFirstPartyTypeKind.ZodFunction,
3687
+ ...processCreateParams(params)
3688
+ });
3689
+ }
3690
+ };
3691
+ ZodLazy = class extends ZodType {
3692
+ get schema() {
3693
+ return this._def.getter();
3694
+ }
3695
+ _parse(input) {
3696
+ const { ctx } = this._processInputParams(input);
3697
+ const lazySchema = this._def.getter();
3698
+ return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx });
3699
+ }
3700
+ };
3701
+ ZodLazy.create = (getter, params) => {
3702
+ return new ZodLazy({
3703
+ getter,
3704
+ typeName: ZodFirstPartyTypeKind.ZodLazy,
3705
+ ...processCreateParams(params)
3706
+ });
3707
+ };
3708
+ ZodLiteral = class extends ZodType {
3709
+ _parse(input) {
3710
+ if (input.data !== this._def.value) {
3711
+ const ctx = this._getOrReturnCtx(input);
3712
+ addIssueToContext(ctx, {
3713
+ code: ZodIssueCode.invalid_literal,
3714
+ expected: this._def.value
3715
+ });
3716
+ return INVALID;
3717
+ }
3718
+ return { status: "valid", value: input.data };
3719
+ }
3720
+ get value() {
3721
+ return this._def.value;
3722
+ }
3723
+ };
3724
+ ZodLiteral.create = (value, params) => {
3725
+ return new ZodLiteral({
3726
+ value,
3727
+ typeName: ZodFirstPartyTypeKind.ZodLiteral,
3728
+ ...processCreateParams(params)
3729
+ });
3730
+ };
3731
+ ZodEnum = class extends ZodType {
3732
+ _parse(input) {
3733
+ if (typeof input.data !== "string") {
3734
+ const ctx = this._getOrReturnCtx(input);
3735
+ const expectedValues = this._def.values;
3736
+ addIssueToContext(ctx, {
3737
+ expected: util.joinValues(expectedValues),
3738
+ received: ctx.parsedType,
3739
+ code: ZodIssueCode.invalid_type
3740
+ });
3741
+ return INVALID;
3742
+ }
3743
+ if (this._def.values.indexOf(input.data) === -1) {
3744
+ const ctx = this._getOrReturnCtx(input);
3745
+ const expectedValues = this._def.values;
3746
+ addIssueToContext(ctx, {
3747
+ received: ctx.data,
3748
+ code: ZodIssueCode.invalid_enum_value,
3749
+ options: expectedValues
3750
+ });
3751
+ return INVALID;
3752
+ }
3753
+ return OK(input.data);
3754
+ }
3755
+ get options() {
3756
+ return this._def.values;
3757
+ }
3758
+ get enum() {
3759
+ const enumValues = {};
3760
+ for (const val of this._def.values) {
3761
+ enumValues[val] = val;
3762
+ }
3763
+ return enumValues;
3764
+ }
3765
+ get Values() {
3766
+ const enumValues = {};
3767
+ for (const val of this._def.values) {
3768
+ enumValues[val] = val;
3769
+ }
3770
+ return enumValues;
3771
+ }
3772
+ get Enum() {
3773
+ const enumValues = {};
3774
+ for (const val of this._def.values) {
3775
+ enumValues[val] = val;
3776
+ }
3777
+ return enumValues;
3778
+ }
3779
+ };
3780
+ ZodEnum.create = createZodEnum;
3781
+ ZodNativeEnum = class extends ZodType {
3782
+ _parse(input) {
3783
+ const nativeEnumValues = util.getValidEnumValues(this._def.values);
3784
+ const ctx = this._getOrReturnCtx(input);
3785
+ if (ctx.parsedType !== ZodParsedType.string && ctx.parsedType !== ZodParsedType.number) {
3786
+ const expectedValues = util.objectValues(nativeEnumValues);
3787
+ addIssueToContext(ctx, {
3788
+ expected: util.joinValues(expectedValues),
3789
+ received: ctx.parsedType,
3790
+ code: ZodIssueCode.invalid_type
3791
+ });
3792
+ return INVALID;
3793
+ }
3794
+ if (nativeEnumValues.indexOf(input.data) === -1) {
3795
+ const expectedValues = util.objectValues(nativeEnumValues);
3796
+ addIssueToContext(ctx, {
3797
+ received: ctx.data,
3798
+ code: ZodIssueCode.invalid_enum_value,
3799
+ options: expectedValues
3800
+ });
3801
+ return INVALID;
3802
+ }
3803
+ return OK(input.data);
3804
+ }
3805
+ get enum() {
3806
+ return this._def.values;
3807
+ }
3808
+ };
3809
+ ZodNativeEnum.create = (values, params) => {
3810
+ return new ZodNativeEnum({
3811
+ values,
3812
+ typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
3813
+ ...processCreateParams(params)
3814
+ });
3815
+ };
3816
+ ZodPromise = class extends ZodType {
3817
+ _parse(input) {
3818
+ const { ctx } = this._processInputParams(input);
3819
+ if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === false) {
3820
+ addIssueToContext(ctx, {
3821
+ code: ZodIssueCode.invalid_type,
3822
+ expected: ZodParsedType.promise,
3823
+ received: ctx.parsedType
3824
+ });
3825
+ return INVALID;
3826
+ }
3827
+ const promisified = ctx.parsedType === ZodParsedType.promise ? ctx.data : Promise.resolve(ctx.data);
3828
+ return OK(promisified.then((data) => {
3829
+ return this._def.type.parseAsync(data, {
3830
+ path: ctx.path,
3831
+ errorMap: ctx.common.contextualErrorMap
3832
+ });
3833
+ }));
3834
+ }
3835
+ };
3836
+ ZodPromise.create = (schema3, params) => {
3837
+ return new ZodPromise({
3838
+ type: schema3,
3839
+ typeName: ZodFirstPartyTypeKind.ZodPromise,
3840
+ ...processCreateParams(params)
3841
+ });
3842
+ };
3843
+ ZodEffects = class extends ZodType {
3844
+ innerType() {
3845
+ return this._def.schema;
3846
+ }
3847
+ sourceType() {
3848
+ return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects ? this._def.schema.sourceType() : this._def.schema;
3849
+ }
3850
+ _parse(input) {
3851
+ const { status, ctx } = this._processInputParams(input);
3852
+ const effect = this._def.effect || null;
3853
+ if (effect.type === "preprocess") {
3854
+ const processed = effect.transform(ctx.data);
3855
+ if (ctx.common.async) {
3856
+ return Promise.resolve(processed).then((processed2) => {
3857
+ return this._def.schema._parseAsync({
3858
+ data: processed2,
3859
+ path: ctx.path,
3860
+ parent: ctx
3861
+ });
3862
+ });
3863
+ } else {
3864
+ return this._def.schema._parseSync({
3865
+ data: processed,
3866
+ path: ctx.path,
3867
+ parent: ctx
3868
+ });
3869
+ }
3870
+ }
3871
+ const checkCtx = {
3872
+ addIssue: (arg) => {
3873
+ addIssueToContext(ctx, arg);
3874
+ if (arg.fatal) {
3875
+ status.abort();
3876
+ } else {
3877
+ status.dirty();
3878
+ }
3879
+ },
3880
+ get path() {
3881
+ return ctx.path;
3882
+ }
3883
+ };
3884
+ checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
3885
+ if (effect.type === "refinement") {
3886
+ const executeRefinement = (acc) => {
3887
+ const result = effect.refinement(acc, checkCtx);
3888
+ if (ctx.common.async) {
3889
+ return Promise.resolve(result);
3890
+ }
3891
+ if (result instanceof Promise) {
3892
+ throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
3893
+ }
3894
+ return acc;
3895
+ };
3896
+ if (ctx.common.async === false) {
3897
+ const inner = this._def.schema._parseSync({
3898
+ data: ctx.data,
3899
+ path: ctx.path,
3900
+ parent: ctx
3901
+ });
3902
+ if (inner.status === "aborted")
3903
+ return INVALID;
3904
+ if (inner.status === "dirty")
3905
+ status.dirty();
3906
+ executeRefinement(inner.value);
3907
+ return { status: status.value, value: inner.value };
3908
+ } else {
3909
+ return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((inner) => {
3910
+ if (inner.status === "aborted")
3911
+ return INVALID;
3912
+ if (inner.status === "dirty")
3913
+ status.dirty();
3914
+ return executeRefinement(inner.value).then(() => {
3915
+ return { status: status.value, value: inner.value };
3916
+ });
3917
+ });
3918
+ }
3919
+ }
3920
+ if (effect.type === "transform") {
3921
+ if (ctx.common.async === false) {
3922
+ const base = this._def.schema._parseSync({
3923
+ data: ctx.data,
3924
+ path: ctx.path,
3925
+ parent: ctx
3926
+ });
3927
+ if (!isValid(base))
3928
+ return base;
3929
+ const result = effect.transform(base.value, checkCtx);
3930
+ if (result instanceof Promise) {
3931
+ throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
3932
+ }
3933
+ return { status: status.value, value: result };
3934
+ } else {
3935
+ return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((base) => {
3936
+ if (!isValid(base))
3937
+ return base;
3938
+ return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({ status: status.value, value: result }));
3939
+ });
3940
+ }
3941
+ }
3942
+ util.assertNever(effect);
3943
+ }
3944
+ };
3945
+ ZodEffects.create = (schema3, effect, params) => {
3946
+ return new ZodEffects({
3947
+ schema: schema3,
3948
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
3949
+ effect,
3950
+ ...processCreateParams(params)
3951
+ });
3952
+ };
3953
+ ZodEffects.createWithPreprocess = (preprocess, schema3, params) => {
3954
+ return new ZodEffects({
3955
+ schema: schema3,
3956
+ effect: { type: "preprocess", transform: preprocess },
3957
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
3958
+ ...processCreateParams(params)
3959
+ });
3960
+ };
3961
+ ZodOptional = class extends ZodType {
3962
+ _parse(input) {
3963
+ const parsedType = this._getType(input);
3964
+ if (parsedType === ZodParsedType.undefined) {
3965
+ return OK(void 0);
3966
+ }
3967
+ return this._def.innerType._parse(input);
3968
+ }
3969
+ unwrap() {
3970
+ return this._def.innerType;
3971
+ }
3972
+ };
3973
+ ZodOptional.create = (type, params) => {
3974
+ return new ZodOptional({
3975
+ innerType: type,
3976
+ typeName: ZodFirstPartyTypeKind.ZodOptional,
3977
+ ...processCreateParams(params)
3978
+ });
3979
+ };
3980
+ ZodNullable = class extends ZodType {
3981
+ _parse(input) {
3982
+ const parsedType = this._getType(input);
3983
+ if (parsedType === ZodParsedType.null) {
3984
+ return OK(null);
3985
+ }
3986
+ return this._def.innerType._parse(input);
3987
+ }
3988
+ unwrap() {
3989
+ return this._def.innerType;
3990
+ }
3991
+ };
3992
+ ZodNullable.create = (type, params) => {
3993
+ return new ZodNullable({
3994
+ innerType: type,
3995
+ typeName: ZodFirstPartyTypeKind.ZodNullable,
3996
+ ...processCreateParams(params)
3997
+ });
3998
+ };
3999
+ ZodDefault = class extends ZodType {
4000
+ _parse(input) {
4001
+ const { ctx } = this._processInputParams(input);
4002
+ let data = ctx.data;
4003
+ if (ctx.parsedType === ZodParsedType.undefined) {
4004
+ data = this._def.defaultValue();
4005
+ }
4006
+ return this._def.innerType._parse({
4007
+ data,
4008
+ path: ctx.path,
4009
+ parent: ctx
4010
+ });
4011
+ }
4012
+ removeDefault() {
4013
+ return this._def.innerType;
4014
+ }
4015
+ };
4016
+ ZodDefault.create = (type, params) => {
4017
+ return new ZodDefault({
4018
+ innerType: type,
4019
+ typeName: ZodFirstPartyTypeKind.ZodDefault,
4020
+ defaultValue: typeof params.default === "function" ? params.default : () => params.default,
4021
+ ...processCreateParams(params)
4022
+ });
4023
+ };
4024
+ ZodCatch = class extends ZodType {
4025
+ _parse(input) {
4026
+ const { ctx } = this._processInputParams(input);
4027
+ const result = this._def.innerType._parse({
4028
+ data: ctx.data,
4029
+ path: ctx.path,
4030
+ parent: ctx
4031
+ });
4032
+ if (isAsync(result)) {
4033
+ return result.then((result2) => {
4034
+ return {
4035
+ status: "valid",
4036
+ value: result2.status === "valid" ? result2.value : this._def.defaultValue()
4037
+ };
4038
+ });
4039
+ } else {
4040
+ return {
4041
+ status: "valid",
4042
+ value: result.status === "valid" ? result.value : this._def.defaultValue()
4043
+ };
4044
+ }
4045
+ }
4046
+ removeDefault() {
4047
+ return this._def.innerType;
4048
+ }
4049
+ };
4050
+ ZodCatch.create = (type, params) => {
4051
+ return new ZodCatch({
4052
+ innerType: type,
4053
+ typeName: ZodFirstPartyTypeKind.ZodCatch,
4054
+ defaultValue: typeof params.default === "function" ? params.default : () => params.default,
4055
+ ...processCreateParams(params)
4056
+ });
4057
+ };
4058
+ ZodNaN = class extends ZodType {
4059
+ _parse(input) {
4060
+ const parsedType = this._getType(input);
4061
+ if (parsedType !== ZodParsedType.nan) {
4062
+ const ctx = this._getOrReturnCtx(input);
4063
+ addIssueToContext(ctx, {
4064
+ code: ZodIssueCode.invalid_type,
4065
+ expected: ZodParsedType.nan,
4066
+ received: ctx.parsedType
4067
+ });
4068
+ return INVALID;
4069
+ }
4070
+ return { status: "valid", value: input.data };
4071
+ }
4072
+ };
4073
+ ZodNaN.create = (params) => {
4074
+ return new ZodNaN({
4075
+ typeName: ZodFirstPartyTypeKind.ZodNaN,
4076
+ ...processCreateParams(params)
4077
+ });
4078
+ };
4079
+ BRAND = Symbol("zod_brand");
4080
+ ZodBranded = class extends ZodType {
4081
+ _parse(input) {
4082
+ const { ctx } = this._processInputParams(input);
4083
+ const data = ctx.data;
4084
+ return this._def.type._parse({
4085
+ data,
4086
+ path: ctx.path,
4087
+ parent: ctx
4088
+ });
4089
+ }
4090
+ unwrap() {
4091
+ return this._def.type;
4092
+ }
4093
+ };
4094
+ ZodPipeline = class _ZodPipeline extends ZodType {
4095
+ _parse(input) {
4096
+ const { status, ctx } = this._processInputParams(input);
4097
+ if (ctx.common.async) {
4098
+ const handleAsync = async () => {
4099
+ const inResult = await this._def.in._parseAsync({
4100
+ data: ctx.data,
4101
+ path: ctx.path,
4102
+ parent: ctx
4103
+ });
4104
+ if (inResult.status === "aborted")
4105
+ return INVALID;
4106
+ if (inResult.status === "dirty") {
4107
+ status.dirty();
4108
+ return DIRTY(inResult.value);
4109
+ } else {
4110
+ return this._def.out._parseAsync({
4111
+ data: inResult.value,
4112
+ path: ctx.path,
4113
+ parent: ctx
4114
+ });
4115
+ }
4116
+ };
4117
+ return handleAsync();
4118
+ } else {
4119
+ const inResult = this._def.in._parseSync({
4120
+ data: ctx.data,
4121
+ path: ctx.path,
4122
+ parent: ctx
4123
+ });
4124
+ if (inResult.status === "aborted")
4125
+ return INVALID;
4126
+ if (inResult.status === "dirty") {
4127
+ status.dirty();
4128
+ return {
4129
+ status: "dirty",
4130
+ value: inResult.value
4131
+ };
4132
+ } else {
4133
+ return this._def.out._parseSync({
4134
+ data: inResult.value,
4135
+ path: ctx.path,
4136
+ parent: ctx
4137
+ });
4138
+ }
4139
+ }
4140
+ }
4141
+ static create(a, b) {
4142
+ return new _ZodPipeline({
4143
+ in: a,
4144
+ out: b,
4145
+ typeName: ZodFirstPartyTypeKind.ZodPipeline
4146
+ });
4147
+ }
4148
+ };
4149
+ late = {
4150
+ object: ZodObject.lazycreate
4151
+ };
4152
+ (function(ZodFirstPartyTypeKind2) {
4153
+ ZodFirstPartyTypeKind2["ZodString"] = "ZodString";
4154
+ ZodFirstPartyTypeKind2["ZodNumber"] = "ZodNumber";
4155
+ ZodFirstPartyTypeKind2["ZodNaN"] = "ZodNaN";
4156
+ ZodFirstPartyTypeKind2["ZodBigInt"] = "ZodBigInt";
4157
+ ZodFirstPartyTypeKind2["ZodBoolean"] = "ZodBoolean";
4158
+ ZodFirstPartyTypeKind2["ZodDate"] = "ZodDate";
4159
+ ZodFirstPartyTypeKind2["ZodSymbol"] = "ZodSymbol";
4160
+ ZodFirstPartyTypeKind2["ZodUndefined"] = "ZodUndefined";
4161
+ ZodFirstPartyTypeKind2["ZodNull"] = "ZodNull";
4162
+ ZodFirstPartyTypeKind2["ZodAny"] = "ZodAny";
4163
+ ZodFirstPartyTypeKind2["ZodUnknown"] = "ZodUnknown";
4164
+ ZodFirstPartyTypeKind2["ZodNever"] = "ZodNever";
4165
+ ZodFirstPartyTypeKind2["ZodVoid"] = "ZodVoid";
4166
+ ZodFirstPartyTypeKind2["ZodArray"] = "ZodArray";
4167
+ ZodFirstPartyTypeKind2["ZodObject"] = "ZodObject";
4168
+ ZodFirstPartyTypeKind2["ZodUnion"] = "ZodUnion";
4169
+ ZodFirstPartyTypeKind2["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
4170
+ ZodFirstPartyTypeKind2["ZodIntersection"] = "ZodIntersection";
4171
+ ZodFirstPartyTypeKind2["ZodTuple"] = "ZodTuple";
4172
+ ZodFirstPartyTypeKind2["ZodRecord"] = "ZodRecord";
4173
+ ZodFirstPartyTypeKind2["ZodMap"] = "ZodMap";
4174
+ ZodFirstPartyTypeKind2["ZodSet"] = "ZodSet";
4175
+ ZodFirstPartyTypeKind2["ZodFunction"] = "ZodFunction";
4176
+ ZodFirstPartyTypeKind2["ZodLazy"] = "ZodLazy";
4177
+ ZodFirstPartyTypeKind2["ZodLiteral"] = "ZodLiteral";
4178
+ ZodFirstPartyTypeKind2["ZodEnum"] = "ZodEnum";
4179
+ ZodFirstPartyTypeKind2["ZodEffects"] = "ZodEffects";
4180
+ ZodFirstPartyTypeKind2["ZodNativeEnum"] = "ZodNativeEnum";
4181
+ ZodFirstPartyTypeKind2["ZodOptional"] = "ZodOptional";
4182
+ ZodFirstPartyTypeKind2["ZodNullable"] = "ZodNullable";
4183
+ ZodFirstPartyTypeKind2["ZodDefault"] = "ZodDefault";
4184
+ ZodFirstPartyTypeKind2["ZodCatch"] = "ZodCatch";
4185
+ ZodFirstPartyTypeKind2["ZodPromise"] = "ZodPromise";
4186
+ ZodFirstPartyTypeKind2["ZodBranded"] = "ZodBranded";
4187
+ ZodFirstPartyTypeKind2["ZodPipeline"] = "ZodPipeline";
4188
+ })(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
4189
+ stringType = ZodString.create;
4190
+ numberType = ZodNumber.create;
4191
+ nanType = ZodNaN.create;
4192
+ bigIntType = ZodBigInt.create;
4193
+ booleanType = ZodBoolean.create;
4194
+ dateType = ZodDate.create;
4195
+ symbolType = ZodSymbol.create;
4196
+ undefinedType = ZodUndefined.create;
4197
+ nullType = ZodNull.create;
4198
+ anyType = ZodAny.create;
4199
+ unknownType = ZodUnknown.create;
4200
+ neverType = ZodNever.create;
4201
+ voidType = ZodVoid.create;
4202
+ arrayType = ZodArray.create;
4203
+ objectType = ZodObject.create;
4204
+ strictObjectType = ZodObject.strictCreate;
4205
+ unionType = ZodUnion.create;
4206
+ discriminatedUnionType = ZodDiscriminatedUnion.create;
4207
+ intersectionType = ZodIntersection.create;
4208
+ tupleType = ZodTuple.create;
4209
+ recordType = ZodRecord.create;
4210
+ mapType = ZodMap.create;
4211
+ setType = ZodSet.create;
4212
+ functionType = ZodFunction.create;
4213
+ lazyType = ZodLazy.create;
4214
+ literalType = ZodLiteral.create;
4215
+ enumType = ZodEnum.create;
4216
+ nativeEnumType = ZodNativeEnum.create;
4217
+ promiseType = ZodPromise.create;
4218
+ effectsType = ZodEffects.create;
4219
+ optionalType = ZodOptional.create;
4220
+ nullableType = ZodNullable.create;
4221
+ preprocessType = ZodEffects.createWithPreprocess;
4222
+ pipelineType = ZodPipeline.create;
4223
+ }
4224
+ });
4225
+
4226
+ // src/serializer/mysqlSchema.ts
4227
+ var index, fk, column, tableV3, compositePK, uniqueConstraint, tableV4, table, kitInternals, dialect, schemaHash, schemaInternalV3, schemaInternalV4, schemaInternalV5, schemaInternal, schemaV3, schemaV4, schemaV5, schema, tableSquashedV4, tableSquashed, schemaSquashed, schemaSquashedV4, mysqlSchema, mysqlSchemaV5, backwardCompatibleMysqlSchema, dryMySql;
4228
+ var init_mysqlSchema = __esm({
4229
+ "src/serializer/mysqlSchema.ts"() {
4230
+ "use strict";
4231
+ init_global();
4232
+ init_lib();
4233
+ index = objectType({
4234
+ name: stringType(),
4235
+ columns: stringType().array(),
4236
+ isUnique: booleanType(),
4237
+ using: enumType(["btree", "hash"]).optional(),
4238
+ algorithm: enumType(["default", "inplace", "copy"]).optional(),
4239
+ lock: enumType(["default", "none", "shared", "exclusive"]).optional()
4240
+ }).strict();
4241
+ fk = objectType({
4242
+ name: stringType(),
4243
+ tableFrom: stringType(),
4244
+ columnsFrom: stringType().array(),
4245
+ tableTo: stringType(),
4246
+ columnsTo: stringType().array(),
4247
+ onUpdate: stringType().optional(),
4248
+ onDelete: stringType().optional()
4249
+ }).strict();
4250
+ column = objectType({
4251
+ name: stringType(),
4252
+ type: stringType(),
4253
+ primaryKey: booleanType(),
4254
+ notNull: booleanType(),
4255
+ autoincrement: booleanType().optional(),
4256
+ default: anyType().optional(),
4257
+ onUpdate: anyType().optional()
4258
+ }).strict();
4259
+ tableV3 = objectType({
4260
+ name: stringType(),
4261
+ columns: recordType(stringType(), column),
4262
+ indexes: recordType(stringType(), index),
4263
+ foreignKeys: recordType(stringType(), fk)
4264
+ }).strict();
4265
+ compositePK = objectType({
4266
+ name: stringType(),
4267
+ columns: stringType().array()
4268
+ }).strict();
4269
+ uniqueConstraint = objectType({
4270
+ name: stringType(),
4271
+ columns: stringType().array()
4272
+ }).strict();
4273
+ tableV4 = objectType({
4274
+ name: stringType(),
4275
+ schema: stringType().optional(),
4276
+ columns: recordType(stringType(), column),
4277
+ indexes: recordType(stringType(), index),
4278
+ foreignKeys: recordType(stringType(), fk)
4279
+ }).strict();
4280
+ table = objectType({
4281
+ name: stringType(),
4282
+ columns: recordType(stringType(), column),
4283
+ indexes: recordType(stringType(), index),
4284
+ foreignKeys: recordType(stringType(), fk),
4285
+ compositePrimaryKeys: recordType(stringType(), compositePK),
4286
+ uniqueConstraints: recordType(stringType(), uniqueConstraint).default({})
4287
+ }).strict();
4288
+ kitInternals = objectType({
4289
+ tables: recordType(
4290
+ stringType(),
4291
+ objectType({
4292
+ columns: recordType(
4293
+ stringType(),
4294
+ objectType({ isDefaultAnExpression: booleanType().optional() }).optional()
4295
+ )
4296
+ }).optional()
4297
+ )
4298
+ }).optional();
4299
+ dialect = literalType("mysql");
4300
+ schemaHash = objectType({
4301
+ id: stringType(),
4302
+ prevId: stringType()
4303
+ });
4304
+ schemaInternalV3 = objectType({
4305
+ version: literalType("3"),
4306
+ dialect,
4307
+ tables: recordType(stringType(), tableV3)
4308
+ }).strict();
4309
+ schemaInternalV4 = objectType({
4310
+ version: literalType("4"),
4311
+ dialect,
4312
+ tables: recordType(stringType(), tableV4),
4313
+ schemas: recordType(stringType(), stringType())
4314
+ }).strict();
4315
+ schemaInternalV5 = objectType({
4316
+ version: literalType("5"),
4317
+ dialect,
4318
+ tables: recordType(stringType(), table),
4319
+ schemas: recordType(stringType(), stringType()),
4320
+ _meta: objectType({
4321
+ schemas: recordType(stringType(), stringType()),
4322
+ tables: recordType(stringType(), stringType()),
4323
+ columns: recordType(stringType(), stringType())
4324
+ }),
4325
+ internal: kitInternals
4326
+ }).strict();
4327
+ schemaInternal = objectType({
4328
+ version: literalType("5"),
4329
+ dialect,
4330
+ tables: recordType(stringType(), table),
4331
+ _meta: objectType({
4332
+ tables: recordType(stringType(), stringType()),
4333
+ columns: recordType(stringType(), stringType())
4334
+ }),
4335
+ internal: kitInternals
4336
+ }).strict();
4337
+ schemaV3 = schemaInternalV3.merge(schemaHash);
4338
+ schemaV4 = schemaInternalV4.merge(schemaHash);
4339
+ schemaV5 = schemaInternalV5.merge(schemaHash);
4340
+ schema = schemaInternal.merge(schemaHash);
4341
+ tableSquashedV4 = objectType({
4342
+ name: stringType(),
4343
+ schema: stringType().optional(),
4344
+ columns: recordType(stringType(), column),
4345
+ indexes: recordType(stringType(), stringType()),
4346
+ foreignKeys: recordType(stringType(), stringType())
4347
+ }).strict();
4348
+ tableSquashed = objectType({
4349
+ name: stringType(),
4350
+ columns: recordType(stringType(), column),
4351
+ indexes: recordType(stringType(), stringType()),
4352
+ foreignKeys: recordType(stringType(), stringType()),
4353
+ compositePrimaryKeys: recordType(stringType(), stringType()),
4354
+ uniqueConstraints: recordType(stringType(), stringType()).default({})
4355
+ }).strict();
4356
+ schemaSquashed = objectType({
4357
+ version: literalType("5"),
4358
+ dialect,
4359
+ tables: recordType(stringType(), tableSquashed)
4360
+ }).strict();
4361
+ schemaSquashedV4 = objectType({
4362
+ version: literalType("4"),
4363
+ dialect,
4364
+ tables: recordType(stringType(), tableSquashedV4),
4365
+ schemas: recordType(stringType(), stringType())
4366
+ }).strict();
4367
+ mysqlSchema = schema;
4368
+ mysqlSchemaV5 = schemaV5;
4369
+ backwardCompatibleMysqlSchema = unionType([mysqlSchemaV5, schema]);
4370
+ dryMySql = mysqlSchema.parse({
4371
+ version: "5",
4372
+ dialect: "mysql",
4373
+ id: originUUID,
4374
+ prevId: "",
4375
+ tables: {},
4376
+ schemas: {},
4377
+ _meta: {
4378
+ schemas: {},
4379
+ tables: {},
4380
+ columns: {}
4381
+ }
4382
+ });
4383
+ }
4384
+ });
4385
+
4386
+ // src/serializer/pgSchema.ts
4387
+ var indexV2, columnV2, tableV2, enumSchemaV1, enumSchema, pgSchemaV2, references, columnV1, tableV1, pgSchemaV1, index2, fk2, column2, tableV32, compositePK2, uniqueConstraint2, tableV42, table2, schemaHash2, kitInternals2, pgSchemaInternalV3, pgSchemaInternalV4, pgSchemaInternalV5, pgSchemaExternal, pgSchemaInternal, tableSquashed2, tableSquashedV42, pgSchemaSquashedV4, pgSchemaSquashed, pgSchemaV3, pgSchemaV4, pgSchemaV5, pgSchema2, backwardCompatiblePgSchema, dryPg;
4388
+ var init_pgSchema = __esm({
4389
+ "src/serializer/pgSchema.ts"() {
4390
+ "use strict";
4391
+ init_global();
4392
+ init_lib();
4393
+ indexV2 = objectType({
4394
+ name: stringType(),
4395
+ columns: recordType(
4396
+ stringType(),
4397
+ objectType({
4398
+ name: stringType()
4399
+ })
4400
+ ),
4401
+ isUnique: booleanType()
4402
+ }).strict();
4403
+ columnV2 = objectType({
4404
+ name: stringType(),
4405
+ type: stringType(),
4406
+ primaryKey: booleanType(),
4407
+ notNull: booleanType(),
4408
+ default: anyType().optional(),
4409
+ references: stringType().optional()
4410
+ }).strict();
4411
+ tableV2 = objectType({
4412
+ name: stringType(),
4413
+ columns: recordType(stringType(), columnV2),
4414
+ indexes: recordType(stringType(), indexV2)
4415
+ }).strict();
4416
+ enumSchemaV1 = objectType({
4417
+ name: stringType(),
4418
+ values: recordType(stringType(), stringType())
4419
+ }).strict();
4420
+ enumSchema = objectType({
4421
+ name: stringType(),
4422
+ schema: stringType(),
4423
+ values: stringType().array()
4424
+ }).strict();
4425
+ pgSchemaV2 = objectType({
4426
+ version: literalType("2"),
4427
+ tables: recordType(stringType(), tableV2),
4428
+ enums: recordType(stringType(), enumSchemaV1)
4429
+ }).strict();
4430
+ references = objectType({
4431
+ foreignKeyName: stringType(),
4432
+ table: stringType(),
4433
+ column: stringType(),
4434
+ onDelete: stringType().optional(),
4435
+ onUpdate: stringType().optional()
4436
+ }).strict();
4437
+ columnV1 = objectType({
4438
+ name: stringType(),
4439
+ type: stringType(),
4440
+ primaryKey: booleanType(),
4441
+ notNull: booleanType(),
4442
+ default: anyType().optional(),
4443
+ references: references.optional()
4444
+ }).strict();
4445
+ tableV1 = objectType({
4446
+ name: stringType(),
4447
+ columns: recordType(stringType(), columnV1),
4448
+ indexes: recordType(stringType(), indexV2)
4449
+ }).strict();
4450
+ pgSchemaV1 = objectType({
4451
+ version: literalType("1"),
4452
+ tables: recordType(stringType(), tableV1),
4453
+ enums: recordType(stringType(), enumSchemaV1)
4454
+ }).strict();
4455
+ index2 = objectType({
4456
+ name: stringType(),
4457
+ columns: stringType().array(),
4458
+ isUnique: booleanType()
4459
+ }).strict();
4460
+ fk2 = objectType({
4461
+ name: stringType(),
4462
+ tableFrom: stringType(),
4463
+ columnsFrom: stringType().array(),
4464
+ tableTo: stringType(),
4465
+ schemaTo: stringType().optional(),
4466
+ columnsTo: stringType().array(),
4467
+ onUpdate: stringType().optional(),
4468
+ onDelete: stringType().optional()
4469
+ }).strict();
4470
+ column2 = objectType({
4471
+ name: stringType(),
4472
+ type: stringType(),
4473
+ typeSchema: stringType().optional(),
4474
+ primaryKey: booleanType(),
4475
+ notNull: booleanType(),
4476
+ default: anyType().optional(),
4477
+ isUnique: anyType().optional(),
4478
+ uniqueName: stringType().optional(),
4479
+ nullsNotDistinct: booleanType().optional()
4480
+ }).strict();
4481
+ tableV32 = objectType({
4482
+ name: stringType(),
4483
+ columns: recordType(stringType(), column2),
4484
+ indexes: recordType(stringType(), index2),
4485
+ foreignKeys: recordType(stringType(), fk2)
4486
+ }).strict();
4487
+ compositePK2 = objectType({
4488
+ name: stringType(),
4489
+ columns: stringType().array()
4490
+ }).strict();
4491
+ uniqueConstraint2 = objectType({
4492
+ name: stringType(),
4493
+ columns: stringType().array(),
4494
+ nullsNotDistinct: booleanType()
4495
+ }).strict();
4496
+ tableV42 = objectType({
4497
+ name: stringType(),
4498
+ schema: stringType(),
4499
+ columns: recordType(stringType(), column2),
4500
+ indexes: recordType(stringType(), index2),
4501
+ foreignKeys: recordType(stringType(), fk2)
4502
+ }).strict();
4503
+ table2 = objectType({
4504
+ name: stringType(),
4505
+ schema: stringType(),
4506
+ columns: recordType(stringType(), column2),
4507
+ indexes: recordType(stringType(), index2),
4508
+ foreignKeys: recordType(stringType(), fk2),
4509
+ compositePrimaryKeys: recordType(stringType(), compositePK2),
4510
+ uniqueConstraints: recordType(stringType(), uniqueConstraint2).default({})
4511
+ }).strict();
4512
+ schemaHash2 = objectType({
4513
+ id: stringType(),
4514
+ prevId: stringType()
4515
+ });
4516
+ kitInternals2 = objectType({
4517
+ tables: recordType(
4518
+ stringType(),
4519
+ objectType({
4520
+ columns: recordType(
4521
+ stringType(),
4522
+ objectType({
4523
+ isArray: booleanType().optional(),
4524
+ dimensions: numberType().optional(),
4525
+ rawType: stringType().optional()
4526
+ }).optional()
4527
+ )
4528
+ }).optional()
4529
+ )
4530
+ }).optional();
4531
+ pgSchemaInternalV3 = objectType({
4532
+ version: literalType("3"),
4533
+ dialect: literalType("pg"),
4534
+ tables: recordType(stringType(), tableV32),
4535
+ enums: recordType(stringType(), enumSchemaV1)
4536
+ }).strict();
4537
+ pgSchemaInternalV4 = objectType({
4538
+ version: literalType("4"),
4539
+ dialect: literalType("pg"),
4540
+ tables: recordType(stringType(), tableV42),
4541
+ enums: recordType(stringType(), enumSchemaV1),
4542
+ schemas: recordType(stringType(), stringType())
4543
+ }).strict();
4544
+ pgSchemaInternalV5 = objectType({
4545
+ version: literalType("5"),
4546
+ dialect: literalType("pg"),
4547
+ tables: recordType(stringType(), table2),
4548
+ enums: recordType(stringType(), enumSchemaV1),
4549
+ schemas: recordType(stringType(), stringType()),
4550
+ _meta: objectType({
4551
+ schemas: recordType(stringType(), stringType()),
4552
+ tables: recordType(stringType(), stringType()),
4553
+ columns: recordType(stringType(), stringType())
4554
+ }),
4555
+ internal: kitInternals2
4556
+ }).strict();
4557
+ pgSchemaExternal = objectType({
4558
+ version: literalType("5"),
4559
+ dialect: literalType("pg"),
4560
+ tables: arrayType(table2),
4561
+ enums: arrayType(enumSchemaV1),
4562
+ schemas: arrayType(objectType({ name: stringType() })),
4563
+ _meta: objectType({
4564
+ schemas: recordType(stringType(), stringType()),
4565
+ tables: recordType(stringType(), stringType()),
4566
+ columns: recordType(stringType(), stringType())
4567
+ })
4568
+ }).strict();
4569
+ pgSchemaInternal = objectType({
4570
+ version: literalType("6"),
4571
+ dialect: literalType("pg"),
4572
+ tables: recordType(stringType(), table2),
4573
+ enums: recordType(stringType(), enumSchema),
4574
+ schemas: recordType(stringType(), stringType()),
4575
+ _meta: objectType({
4576
+ schemas: recordType(stringType(), stringType()),
4577
+ tables: recordType(stringType(), stringType()),
4578
+ columns: recordType(stringType(), stringType())
4579
+ }),
4580
+ internal: kitInternals2
4581
+ }).strict();
4582
+ tableSquashed2 = objectType({
4583
+ name: stringType(),
4584
+ schema: stringType(),
4585
+ columns: recordType(stringType(), column2),
4586
+ indexes: recordType(stringType(), stringType()),
4587
+ foreignKeys: recordType(stringType(), stringType()),
4588
+ compositePrimaryKeys: recordType(stringType(), stringType()),
4589
+ uniqueConstraints: recordType(stringType(), stringType())
4590
+ }).strict();
4591
+ tableSquashedV42 = objectType({
4592
+ name: stringType(),
4593
+ schema: stringType(),
4594
+ columns: recordType(stringType(), column2),
4595
+ indexes: recordType(stringType(), stringType()),
4596
+ foreignKeys: recordType(stringType(), stringType())
4597
+ }).strict();
4598
+ pgSchemaSquashedV4 = objectType({
4599
+ version: literalType("4"),
4600
+ dialect: enumType(["pg"]),
4601
+ tables: recordType(stringType(), tableSquashedV42),
4602
+ enums: recordType(stringType(), enumSchemaV1),
4603
+ schemas: recordType(stringType(), stringType())
4604
+ }).strict();
4605
+ pgSchemaSquashed = objectType({
4606
+ version: literalType("6"),
4607
+ dialect: enumType(["pg"]),
4608
+ tables: recordType(stringType(), tableSquashed2),
4609
+ enums: recordType(stringType(), enumSchema),
4610
+ schemas: recordType(stringType(), stringType())
4611
+ }).strict();
4612
+ pgSchemaV3 = pgSchemaInternalV3.merge(schemaHash2);
4613
+ pgSchemaV4 = pgSchemaInternalV4.merge(schemaHash2);
4614
+ pgSchemaV5 = pgSchemaInternalV5.merge(schemaHash2);
4615
+ pgSchema2 = pgSchemaInternal.merge(schemaHash2);
4616
+ backwardCompatiblePgSchema = unionType([pgSchemaV5, pgSchema2]);
4617
+ dryPg = pgSchema2.parse({
4618
+ version: snapshotVersion,
4619
+ dialect: "pg",
4620
+ id: originUUID,
4621
+ prevId: "",
4622
+ tables: {},
4623
+ enums: {},
4624
+ schemas: {},
4625
+ _meta: {
4626
+ schemas: {},
4627
+ tables: {},
4628
+ columns: {}
4629
+ }
4630
+ });
4631
+ }
4632
+ });
4633
+
4634
+ // src/serializer/sqliteSchema.ts
4635
+ var index3, fk3, compositePK3, column3, tableV33, uniqueConstraint3, table3, dialect2, schemaHash3, schemaInternalV32, schemaInternalV42, latestVersion, schemaInternal2, schemaV32, schemaV42, schema2, tableSquashed3, schemaSquashed2, drySQLite;
4636
+ var init_sqliteSchema = __esm({
4637
+ "src/serializer/sqliteSchema.ts"() {
4638
+ "use strict";
4639
+ init_global();
4640
+ init_lib();
4641
+ index3 = objectType({
4642
+ name: stringType(),
4643
+ columns: stringType().array(),
4644
+ where: stringType().optional(),
4645
+ isUnique: booleanType()
4646
+ }).strict();
4647
+ fk3 = objectType({
4648
+ name: stringType(),
4649
+ tableFrom: stringType(),
4650
+ columnsFrom: stringType().array(),
4651
+ tableTo: stringType(),
4652
+ columnsTo: stringType().array(),
4653
+ onUpdate: stringType().optional(),
4654
+ onDelete: stringType().optional()
4655
+ }).strict();
4656
+ compositePK3 = objectType({
4657
+ columns: stringType().array(),
4658
+ name: stringType().optional()
4659
+ }).strict();
4660
+ column3 = objectType({
4661
+ name: stringType(),
4662
+ type: stringType(),
4663
+ primaryKey: booleanType(),
4664
+ notNull: booleanType(),
4665
+ autoincrement: booleanType().optional(),
4666
+ default: anyType().optional()
4667
+ }).strict();
4668
+ tableV33 = objectType({
4669
+ name: stringType(),
4670
+ columns: recordType(stringType(), column3),
4671
+ indexes: recordType(stringType(), index3),
4672
+ foreignKeys: recordType(stringType(), fk3)
4673
+ }).strict();
4674
+ uniqueConstraint3 = objectType({
4675
+ name: stringType(),
4676
+ columns: stringType().array()
4677
+ }).strict();
4678
+ table3 = objectType({
4679
+ name: stringType(),
4680
+ columns: recordType(stringType(), column3),
4681
+ indexes: recordType(stringType(), index3),
4682
+ foreignKeys: recordType(stringType(), fk3),
4683
+ compositePrimaryKeys: recordType(stringType(), compositePK3),
4684
+ uniqueConstraints: recordType(stringType(), uniqueConstraint3).default({})
4685
+ }).strict();
4686
+ dialect2 = enumType(["sqlite"]);
4687
+ schemaHash3 = objectType({
4688
+ id: stringType(),
4689
+ prevId: stringType()
4690
+ }).strict();
4691
+ schemaInternalV32 = objectType({
4692
+ version: literalType("3"),
4693
+ dialect: dialect2,
4694
+ tables: recordType(stringType(), tableV33),
4695
+ enums: objectType({})
4696
+ }).strict();
4697
+ schemaInternalV42 = objectType({
4698
+ version: literalType("4"),
4699
+ dialect: dialect2,
4700
+ tables: recordType(stringType(), table3),
4701
+ enums: objectType({})
4702
+ }).strict();
4703
+ latestVersion = literalType("5");
4704
+ schemaInternal2 = objectType({
4705
+ version: latestVersion,
4706
+ dialect: dialect2,
4707
+ tables: recordType(stringType(), table3),
4708
+ enums: objectType({}),
4709
+ _meta: objectType({
4710
+ tables: recordType(stringType(), stringType()),
4711
+ columns: recordType(stringType(), stringType())
4712
+ })
4713
+ }).strict();
4714
+ schemaV32 = schemaInternalV32.merge(schemaHash3).strict();
4715
+ schemaV42 = schemaInternalV42.merge(schemaHash3).strict();
4716
+ schema2 = schemaInternal2.merge(schemaHash3).strict();
4717
+ tableSquashed3 = objectType({
4718
+ name: stringType(),
4719
+ columns: recordType(stringType(), column3),
4720
+ indexes: recordType(stringType(), stringType()),
4721
+ foreignKeys: recordType(stringType(), stringType()),
4722
+ compositePrimaryKeys: recordType(stringType(), stringType()),
4723
+ uniqueConstraints: recordType(stringType(), stringType()).default({})
4724
+ }).strict();
4725
+ schemaSquashed2 = objectType({
4726
+ version: latestVersion,
4727
+ dialect: dialect2,
4728
+ tables: recordType(stringType(), tableSquashed3),
4729
+ enums: anyType()
4730
+ }).strict();
4731
+ drySQLite = schema2.parse({
4732
+ version: "5",
4733
+ dialect: "sqlite",
4734
+ id: originUUID,
4735
+ prevId: "",
4736
+ tables: {},
4737
+ enums: {},
4738
+ _meta: {
4739
+ tables: {},
4740
+ columns: {}
4741
+ }
4742
+ });
4743
+ }
4744
+ });
4745
+
4746
+ // src/utils.ts
4747
+ var init_utils = __esm({
4748
+ "src/utils.ts"() {
4749
+ "use strict";
4750
+ init_views();
4751
+ init_mysqlSchema();
4752
+ init_pgSchema();
4753
+ init_sqliteSchema();
4754
+ init_source();
4755
+ init_global();
4756
+ }
4757
+ });
4758
+
1077
4759
  // src/cli/views.ts
1078
4760
  var import_hanji;
1079
4761
  var init_views = __esm({
1080
4762
  "src/cli/views.ts"() {
4763
+ "use strict";
1081
4764
  init_source();
1082
4765
  import_hanji = __toESM(require_hanji());
4766
+ init_utils();
1083
4767
  }
1084
4768
  });
1085
4769
 
@@ -1087,6 +4771,7 @@ var init_views = __esm({
1087
4771
  import * as glob from "glob";
1088
4772
  var init_serializer = __esm({
1089
4773
  "src/serializer/index.ts"() {
4774
+ "use strict";
1090
4775
  init_source();
1091
4776
  init_views();
1092
4777
  }
@@ -1095,6 +4780,7 @@ var init_serializer = __esm({
1095
4780
  // src/cli/validations/outputs.ts
1096
4781
  var init_outputs = __esm({
1097
4782
  "src/cli/validations/outputs.ts"() {
4783
+ "use strict";
1098
4784
  init_source();
1099
4785
  }
1100
4786
  });
@@ -1108,6 +4794,7 @@ import {
1108
4794
  uniqueKeyName
1109
4795
  } from "drizzle-orm/sqlite-core";
1110
4796
  function mapSqlToSqliteType(sqlType) {
4797
+ const lowered = sqlType.toLowerCase();
1111
4798
  if ([
1112
4799
  "int",
1113
4800
  "integer",
@@ -1119,37 +4806,41 @@ function mapSqlToSqliteType(sqlType) {
1119
4806
  "unsigned big int",
1120
4807
  "int2",
1121
4808
  "int8"
1122
- ].includes(sqlType.toLowerCase())) {
4809
+ ].some((it) => lowered.startsWith(it))) {
1123
4810
  return "integer";
1124
4811
  } else if ([
1125
4812
  "character",
1126
4813
  "varchar",
1127
- "vatying character",
4814
+ "varying character",
4815
+ "national varying character",
1128
4816
  "nchar",
1129
4817
  "native character",
1130
4818
  "nvarchar",
1131
4819
  "text",
1132
4820
  "clob"
1133
- ].some((it) => it.startsWith(sqlType.toLowerCase()))) {
4821
+ ].some((it) => lowered.startsWith(it))) {
4822
+ const match2 = lowered.match(/\d+/);
4823
+ if (match2) {
4824
+ return `text(${match2[0]})`;
4825
+ }
1134
4826
  return "text";
1135
- } else if (sqlType.toLowerCase() === "blob") {
4827
+ } else if (lowered.startsWith("blob")) {
1136
4828
  return "blob";
1137
- } else if (["real", "double", "double precision", "float"].includes(
1138
- sqlType.toLowerCase()
1139
- )) {
4829
+ } else if (["real", "double", "double precision", "float"].some((it) => lowered.startsWith(it))) {
1140
4830
  return "real";
1141
4831
  } else {
1142
4832
  return "numeric";
1143
4833
  }
1144
4834
  }
1145
- var dialect, fromDatabase;
4835
+ var dialect3, fromDatabase;
1146
4836
  var init_sqliteSerializer = __esm({
1147
4837
  "src/serializer/sqliteSerializer.ts"() {
4838
+ "use strict";
1148
4839
  init_serializer();
1149
4840
  init_outputs();
1150
4841
  init_source();
1151
- dialect = new SQLiteSyncDialect();
1152
- fromDatabase = async (db, tablesFilter = (table) => true, progressCallback) => {
4842
+ dialect3 = new SQLiteSyncDialect();
4843
+ fromDatabase = async (db, tablesFilter = (table4) => true, progressCallback) => {
1153
4844
  const result = {};
1154
4845
  const columns = await db.query(
1155
4846
  `SELECT
@@ -1170,23 +4861,23 @@ var init_sqliteSerializer = __esm({
1170
4861
  let indexesCount = 0;
1171
4862
  let foreignKeysCount = 0;
1172
4863
  const tableToPk = {};
1173
- for (const column of columns) {
1174
- if (!tablesFilter(column.tableName))
4864
+ for (const column4 of columns) {
4865
+ if (!tablesFilter(column4.tableName))
1175
4866
  continue;
1176
4867
  columnsCount += 1;
1177
4868
  if (progressCallback) {
1178
4869
  progressCallback("columns", columnsCount, "fetching");
1179
4870
  }
1180
- const tableName = column.tableName;
4871
+ const tableName = column4.tableName;
1181
4872
  tablesCount.add(tableName);
1182
4873
  if (progressCallback) {
1183
4874
  progressCallback("tables", tablesCount.size, "fetching");
1184
4875
  }
1185
- const columnName = column.columnName;
1186
- const isNotNull = column.notNull === 1;
1187
- const columnType = column.columnType;
1188
- const isPrimary = column.pk !== 0;
1189
- const columnDefault = column.defaultValue;
4876
+ const columnName = column4.columnName;
4877
+ const isNotNull = column4.notNull === 1;
4878
+ const columnType = column4.columnType;
4879
+ const isPrimary = column4.pk !== 0;
4880
+ const columnDefault = column4.defaultValue;
1190
4881
  const isAutoincrement = isPrimary && tablesWithSeq.includes(tableName);
1191
4882
  if (isPrimary) {
1192
4883
  if (typeof tableToPk[tableName] === "undefined") {
@@ -1195,7 +4886,7 @@ var init_sqliteSerializer = __esm({
1195
4886
  tableToPk[tableName].push(columnName);
1196
4887
  }
1197
4888
  }
1198
- const table = result[tableName];
4889
+ const table4 = result[tableName];
1199
4890
  const newColumn = {
1200
4891
  default: columnDefault === null ? void 0 : /^-?[\d.]+(?:e-?\d+)?$/.test(columnDefault) ? Number(columnDefault) : ["CURRENT_TIME", "CURRENT_DATE", "CURRENT_TIMESTAMP"].includes(
1201
4892
  columnDefault
@@ -1209,7 +4900,7 @@ var init_sqliteSerializer = __esm({
1209
4900
  primaryKey: false,
1210
4901
  notNull: isNotNull
1211
4902
  };
1212
- if (!table) {
4903
+ if (!table4) {
1213
4904
  result[tableName] = {
1214
4905
  name: tableName,
1215
4906
  columns: {
@@ -1560,17 +5251,19 @@ var require_brace_expansion = __commonJS({
1560
5251
  // src/serializer/pgSerializer.ts
1561
5252
  import {
1562
5253
  PgDialect,
5254
+ PgEnumColumn,
1563
5255
  uniqueKeyName as uniqueKeyName2
1564
5256
  } from "drizzle-orm/pg-core";
1565
5257
  import { getTableConfig as getTableConfig2 } from "drizzle-orm/pg-core";
1566
5258
  import { is as is2, SQL as SQL2, getTableName as getTableName2 } from "drizzle-orm";
1567
- var dialect2, trimChar, fromDatabase2, columnToDefault, defaultForColumn;
5259
+ var dialect4, trimChar, fromDatabase2, columnToDefault, defaultForColumn;
1568
5260
  var init_pgSerializer = __esm({
1569
5261
  "src/serializer/pgSerializer.ts"() {
5262
+ "use strict";
1570
5263
  init_serializer();
1571
5264
  init_source();
1572
5265
  init_outputs();
1573
- dialect2 = new PgDialect();
5266
+ dialect4 = new PgDialect();
1574
5267
  trimChar = (str, char) => {
1575
5268
  let start = 0;
1576
5269
  let end = str.length;
@@ -1580,12 +5273,12 @@ var init_pgSerializer = __esm({
1580
5273
  --end;
1581
5274
  return start > 0 || end < str.length ? str.substring(start, end) : str.toString();
1582
5275
  };
1583
- fromDatabase2 = async (db, tablesFilter = (table) => true, schemaFilters, progressCallback) => {
5276
+ fromDatabase2 = async (db, tablesFilter = () => true, schemaFilters, progressCallback) => {
1584
5277
  const result = {};
1585
5278
  const internals = { tables: {} };
1586
5279
  const where = schemaFilters.map((t) => `table_schema = '${t}'`).join(" or ");
1587
5280
  const allTables = await db.query(
1588
- `SELECT table_schema, table_name FROM information_schema.tables WHERE ${where};`
5281
+ `SELECT table_schema, table_name FROM information_schema.tables${where === "" ? "" : ` WHERE ${where}`};`
1589
5282
  );
1590
5283
  const schemas = new Set(allTables.map((it) => it.table_schema));
1591
5284
  schemas.delete("public");
@@ -1605,6 +5298,35 @@ var init_pgSerializer = __esm({
1605
5298
  let indexesCount = 0;
1606
5299
  let foreignKeysCount = 0;
1607
5300
  let tableCount = 0;
5301
+ const allEnums = await db.query(
5302
+ `select n.nspname as enum_schema,
5303
+ t.typname as enum_name,
5304
+ e.enumlabel as enum_value,
5305
+ e.enumsortorder as sort_order
5306
+ from pg_type t
5307
+ join pg_enum e on t.oid = e.enumtypid
5308
+ join pg_catalog.pg_namespace n ON n.oid = t.typnamespace
5309
+ order by enum_schema, enum_name, sort_order;`
5310
+ );
5311
+ const enumsToReturn = {};
5312
+ for (const dbEnum of allEnums) {
5313
+ const enumName = dbEnum.enum_name;
5314
+ const enumValue = dbEnum.enum_value;
5315
+ const enumSchema2 = dbEnum.enum_schema || "public";
5316
+ const key = `${enumSchema2}.${enumName}`;
5317
+ if (enumsToReturn[key] !== void 0 && enumsToReturn[key] !== null) {
5318
+ enumsToReturn[key].values.push(enumValue);
5319
+ } else {
5320
+ enumsToReturn[key] = {
5321
+ name: enumName,
5322
+ values: [enumValue],
5323
+ schema: enumSchema2
5324
+ };
5325
+ }
5326
+ }
5327
+ if (progressCallback) {
5328
+ progressCallback("enums", Object.keys(enumsToReturn).length, "done");
5329
+ }
1608
5330
  const all = allTables.map((row) => {
1609
5331
  return new Promise(async (res, rej) => {
1610
5332
  const tableName = row.table_name;
@@ -1637,7 +5359,7 @@ var init_pgSerializer = __esm({
1637
5359
  WHEN 'int2'::regtype THEN 'smallserial'
1638
5360
  END
1639
5361
  ELSE format_type(a.atttypid, a.atttypmod)
1640
- END AS data_type, INFORMATION_SCHEMA.COLUMNS.table_name, INFORMATION_SCHEMA.COLUMNS.column_name, INFORMATION_SCHEMA.COLUMNS.column_default, INFORMATION_SCHEMA.COLUMNS.data_type as additional_dt
5362
+ END AS data_type, INFORMATION_SCHEMA.COLUMNS.table_name, INFORMATION_SCHEMA.COLUMNS.column_name, INFORMATION_SCHEMA.COLUMNS.column_default, INFORMATION_SCHEMA.COLUMNS.data_type as additional_dt, INFORMATION_SCHEMA.COLUMNS.udt_name as enum_name
1641
5363
  FROM pg_attribute a
1642
5364
  JOIN INFORMATION_SCHEMA.COLUMNS ON INFORMATION_SCHEMA.COLUMNS.column_name = a.attname
1643
5365
  WHERE a.attrelid = '"${tableSchema}"."${tableName}"'::regclass and INFORMATION_SCHEMA.COLUMNS.table_name = '${tableName}' and INFORMATION_SCHEMA.COLUMNS.table_schema = '${tableSchema}'
@@ -1688,14 +5410,14 @@ var init_pgSerializer = __esm({
1688
5410
  if (progressCallback) {
1689
5411
  progressCallback("fks", foreignKeysCount, "fetching");
1690
5412
  }
1691
- for (const fk of tableForeignKeys) {
1692
- const columnFrom = fk.column_name;
1693
- const tableTo = fk.foreign_table_name;
1694
- const columnTo = fk.foreign_column_name;
1695
- const schemaTo = fk.foreign_table_schema;
1696
- const foreignKeyName = fk.constraint_name;
1697
- const onUpdate = fk.update_rule.toLowerCase();
1698
- const onDelete = fk.delete_rule.toLowerCase();
5413
+ for (const fk4 of tableForeignKeys) {
5414
+ const columnFrom = fk4.column_name;
5415
+ const tableTo = fk4.foreign_table_name;
5416
+ const columnTo = fk4.foreign_column_name;
5417
+ const schemaTo = fk4.foreign_table_schema;
5418
+ const foreignKeyName = fk4.constraint_name;
5419
+ const onUpdate = fk4.update_rule.toLowerCase();
5420
+ const onDelete = fk4.delete_rule.toLowerCase();
1699
5421
  if (typeof foreignKeysToReturn[foreignKeyName] !== "undefined") {
1700
5422
  foreignKeysToReturn[foreignKeyName].columnsFrom.push(columnFrom);
1701
5423
  foreignKeysToReturn[foreignKeyName].columnsTo.push(columnTo);
@@ -1738,6 +5460,7 @@ var init_pgSerializer = __esm({
1738
5460
  const columnName = columnResponse.attname;
1739
5461
  const columnAdditionalDT = columnResponse.additional_dt;
1740
5462
  const columnDimensions = columnResponse.array_dimensions;
5463
+ const enumType2 = columnResponse.enum_name;
1741
5464
  let columnType = columnResponse.data_type;
1742
5465
  const primaryKey = tableConstraints.filter(
1743
5466
  (mapRow) => columnName === mapRow.column_name && mapRow.constraint_type === "PRIMARY KEY"
@@ -1801,7 +5524,8 @@ var init_pgSerializer = __esm({
1801
5524
  columnTypeMapped = trimChar(columnTypeMapped, '"');
1802
5525
  columnToReturn[columnName] = {
1803
5526
  name: columnName,
1804
- type: columnTypeMapped,
5527
+ type: columnAdditionalDT === "USER-DEFINED" ? enumType2 : columnTypeMapped,
5528
+ typeSchema: enumsToReturn[`${tableSchema}.${enumType2}`] !== void 0 ? enumsToReturn[`${tableSchema}.${enumType2}`].schema : void 0,
1805
5529
  primaryKey: primaryKey.length === 1 && cprimaryKey.length < 2,
1806
5530
  // default: isSerial ? undefined : defaultValue,
1807
5531
  notNull: columnResponse.is_nullable === "NO"
@@ -1836,16 +5560,16 @@ var init_pgSerializer = __esm({
1836
5560
  );
1837
5561
  const idxsInConsteraint = dbIndexFromConstraint.filter((it) => it.generated_by_constraint === 1).map((it) => it.index_name);
1838
5562
  for (const dbIndex of dbIndexes) {
1839
- const indexName2 = dbIndex.index_name;
5563
+ const indexName = dbIndex.index_name;
1840
5564
  const indexColumnName = dbIndex.column_name;
1841
5565
  const indexIsUnique = dbIndex.is_unique;
1842
- if (idxsInConsteraint.includes(indexName2))
5566
+ if (idxsInConsteraint.includes(indexName))
1843
5567
  continue;
1844
- if (typeof indexToReturn[indexName2] !== "undefined") {
1845
- indexToReturn[indexName2].columns.push(indexColumnName);
5568
+ if (typeof indexToReturn[indexName] !== "undefined") {
5569
+ indexToReturn[indexName].columns.push(indexColumnName);
1846
5570
  } else {
1847
- indexToReturn[indexName2] = {
1848
- name: indexName2,
5571
+ indexToReturn[indexName] = {
5572
+ name: indexName,
1849
5573
  columns: [indexColumnName],
1850
5574
  isUnique: indexIsUnique
1851
5575
  };
@@ -1855,7 +5579,7 @@ var init_pgSerializer = __esm({
1855
5579
  if (progressCallback) {
1856
5580
  progressCallback("indexes", indexesCount, "fetching");
1857
5581
  }
1858
- result[tableName] = {
5582
+ result[`${tableSchema}.${tableName}`] = {
1859
5583
  name: tableName,
1860
5584
  schema: tableSchema !== "public" ? tableSchema : "",
1861
5585
  columns: columnToReturn,
@@ -1881,33 +5605,9 @@ var init_pgSerializer = __esm({
1881
5605
  progressCallback("indexes", indexesCount, "done");
1882
5606
  progressCallback("fks", foreignKeysCount, "done");
1883
5607
  }
1884
- const allEnums = await db.query(
1885
- `select n.nspname as enum_schema,
1886
- t.typname as enum_name,
1887
- e.enumlabel as enum_value
1888
- from pg_type t
1889
- join pg_enum e on t.oid = e.enumtypid
1890
- join pg_catalog.pg_namespace n ON n.oid = t.typnamespace;`
1891
- );
1892
- const enumsToReturn = {};
1893
- for (const dbEnum of allEnums) {
1894
- const enumName = dbEnum.enum_name;
1895
- const enumValue = dbEnum.enum_value;
1896
- if (enumsToReturn[enumName] !== void 0 && enumsToReturn[enumName] !== null) {
1897
- enumsToReturn[enumName].values[enumValue] = enumValue;
1898
- } else {
1899
- enumsToReturn[enumName] = {
1900
- name: enumName,
1901
- values: { [enumValue]: enumValue }
1902
- };
1903
- }
1904
- }
1905
- if (progressCallback) {
1906
- progressCallback("enums", Object.keys(enumsToReturn).length, "done");
1907
- }
1908
5608
  const schemasObject = Object.fromEntries([...schemas].map((it) => [it, it]));
1909
5609
  return {
1910
- version: "5",
5610
+ version: "6",
1911
5611
  dialect: "pg",
1912
5612
  tables: result,
1913
5613
  enums: enumsToReturn,
@@ -1940,37 +5640,37 @@ var init_pgSerializer = __esm({
1940
5640
  // json: "::json",
1941
5641
  "character(": "::bpchar"
1942
5642
  };
1943
- defaultForColumn = (column) => {
1944
- if (column.data_type === "serial" || column.data_type === "smallserial" || column.data_type === "bigserial") {
5643
+ defaultForColumn = (column4) => {
5644
+ if (column4.data_type === "serial" || column4.data_type === "smallserial" || column4.data_type === "bigserial") {
1945
5645
  return void 0;
1946
5646
  }
1947
5647
  const hasDifferentDefaultCast = Object.keys(columnToDefault).find(
1948
- (it) => column.data_type.startsWith(it)
5648
+ (it) => column4.data_type.startsWith(it)
1949
5649
  );
1950
- if (column.column_default === null) {
5650
+ if (column4.column_default === null) {
1951
5651
  return void 0;
1952
5652
  }
1953
- const columnDefaultAsString = column.column_default.toString();
5653
+ const columnDefaultAsString = column4.column_default.toString();
1954
5654
  if (columnDefaultAsString.endsWith(
1955
- hasDifferentDefaultCast ? columnToDefault[hasDifferentDefaultCast] : column.data_type
5655
+ hasDifferentDefaultCast ? columnToDefault[hasDifferentDefaultCast] : column4.data_type
1956
5656
  )) {
1957
- const nonPrefixPart = column.column_default.length - (hasDifferentDefaultCast ? columnToDefault[hasDifferentDefaultCast] : `::${column.data_type}`).length - 1;
1958
- const rt = column.column_default.toString().substring(1, nonPrefixPart);
1959
- if (/^-?[\d.]+(?:e-?\d+)?$/.test(rt) && !column.data_type.startsWith("numeric")) {
5657
+ const nonPrefixPart = column4.column_default.length - (hasDifferentDefaultCast ? columnToDefault[hasDifferentDefaultCast] : `::${column4.data_type}`).length - 1;
5658
+ const rt = column4.column_default.toString().substring(1, nonPrefixPart);
5659
+ if (/^-?[\d.]+(?:e-?\d+)?$/.test(rt) && !column4.data_type.startsWith("numeric")) {
1960
5660
  return Number(rt);
1961
- } else if (column.data_type === "json" || column.data_type === "jsonb") {
5661
+ } else if (column4.data_type === "json" || column4.data_type === "jsonb") {
1962
5662
  const jsonWithoutSpaces = JSON.stringify(JSON.parse(rt));
1963
- return `'${jsonWithoutSpaces}'${hasDifferentDefaultCast ? columnToDefault[hasDifferentDefaultCast] : `::${column.data_type}`}`;
1964
- } else if (column.data_type === "boolean") {
1965
- return column.column_default === "true";
5663
+ return `'${jsonWithoutSpaces}'${hasDifferentDefaultCast ? columnToDefault[hasDifferentDefaultCast] : `::${column4.data_type}`}`;
5664
+ } else if (column4.data_type === "boolean") {
5665
+ return column4.column_default === "true";
1966
5666
  } else {
1967
5667
  return `'${rt}'`;
1968
5668
  }
1969
5669
  } else {
1970
- if (/^-?[\d.]+(?:e-?\d+)?$/.test(columnDefaultAsString) && !column.data_type.startsWith("numeric")) {
5670
+ if (/^-?[\d.]+(?:e-?\d+)?$/.test(columnDefaultAsString) && !column4.data_type.startsWith("numeric")) {
1971
5671
  return Number(columnDefaultAsString);
1972
- } else if (column.data_type === "boolean") {
1973
- return column.column_default === "true";
5672
+ } else if (column4.data_type === "boolean") {
5673
+ return column4.column_default === "true";
1974
5674
  } else {
1975
5675
  return `${columnDefaultAsString}`;
1976
5676
  }
@@ -1979,38 +5679,6 @@ var init_pgSerializer = __esm({
1979
5679
  }
1980
5680
  });
1981
5681
 
1982
- // src/drivers/index.ts
1983
- import { sql } from "drizzle-orm";
1984
- var DrizzleDbClient, DrizzleORMPgClient, TursoSqlite;
1985
- var init_drivers = __esm({
1986
- "src/drivers/index.ts"() {
1987
- DrizzleDbClient = class {
1988
- constructor(db) {
1989
- this.db = db;
1990
- }
1991
- };
1992
- DrizzleORMPgClient = class extends DrizzleDbClient {
1993
- async query(query, values) {
1994
- const res = await this.db.execute(sql.raw(query));
1995
- return res.rows;
1996
- }
1997
- async run(query) {
1998
- const res = await this.db.execute(sql.raw(query));
1999
- return res.rows;
2000
- }
2001
- };
2002
- TursoSqlite = class extends DrizzleDbClient {
2003
- async run(query) {
2004
- await this.db.execute(query);
2005
- }
2006
- async query(query) {
2007
- const res = await this.db.execute(query);
2008
- return res.rows;
2009
- }
2010
- };
2011
- }
2012
- });
2013
-
2014
5682
  // src/serializer/schemaToDrizzle.ts
2015
5683
  import {
2016
5684
  customType,
@@ -2051,9 +5719,9 @@ import {
2051
5719
  sqliteTable,
2052
5720
  PrimaryKeyBuilder as SQLitePrimaryKeyBuilder
2053
5721
  } from "drizzle-orm/sqlite-core";
2054
- var pgSchemaToDrizzle = (schema, schemaName) => {
5722
+ var pgSchemaToDrizzle = (schema3, schemaName) => {
2055
5723
  const tables = {};
2056
- Object.values(schema.tables).forEach((t) => {
5724
+ Object.values(schema3.tables).forEach((t) => {
2057
5725
  const columns = {};
2058
5726
  Object.values(t.columns).forEach((c) => {
2059
5727
  const columnName = c.name;
@@ -2153,9 +5821,9 @@ var pgSchemaToDrizzle = (schema, schemaName) => {
2153
5821
  });
2154
5822
  return tables;
2155
5823
  };
2156
- var sqliteSchemaToDrizzle = (schema) => {
5824
+ var sqliteSchemaToDrizzle = (schema3) => {
2157
5825
  const tables = {};
2158
- Object.values(schema.tables).forEach((t) => {
5826
+ Object.values(schema3.tables).forEach((t) => {
2159
5827
  const columns = {};
2160
5828
  Object.values(t.columns).forEach((c) => {
2161
5829
  const columnName = c.name;
@@ -2200,11 +5868,7 @@ var sqliteSchemaToDrizzle = (schema) => {
2200
5868
 
2201
5869
  // src/cli/commands/sqliteIntrospect.ts
2202
5870
  init_views();
2203
-
2204
- // src/global.ts
2205
- var originUUID = "00000000-0000-0000-0000-000000000000";
2206
-
2207
- // src/cli/commands/sqliteIntrospect.ts
5871
+ init_global();
2208
5872
  init_sqliteSerializer();
2209
5873
 
2210
5874
  // node_modules/.pnpm/camelcase@7.0.1/node_modules/camelcase/index.js
@@ -2221,17 +5885,17 @@ var preserveCamelCase = (string, toLowerCase, toUpperCase, preserveConsecutiveUp
2221
5885
  let isLastCharUpper = false;
2222
5886
  let isLastLastCharUpper = false;
2223
5887
  let isLastLastCharPreserved = false;
2224
- for (let index = 0; index < string.length; index++) {
2225
- const character = string[index];
2226
- isLastLastCharPreserved = index > 2 ? string[index - 3] === "-" : true;
5888
+ for (let index4 = 0; index4 < string.length; index4++) {
5889
+ const character = string[index4];
5890
+ isLastLastCharPreserved = index4 > 2 ? string[index4 - 3] === "-" : true;
2227
5891
  if (isLastCharLower && UPPERCASE.test(character)) {
2228
- string = string.slice(0, index) + "-" + string.slice(index);
5892
+ string = string.slice(0, index4) + "-" + string.slice(index4);
2229
5893
  isLastCharLower = false;
2230
5894
  isLastLastCharUpper = isLastCharUpper;
2231
5895
  isLastCharUpper = true;
2232
- index++;
5896
+ index4++;
2233
5897
  } else if (isLastCharUpper && isLastLastCharUpper && LOWERCASE.test(character) && (!isLastLastCharPreserved || preserveConsecutiveUppercase2)) {
2234
- string = string.slice(0, index - 1) + "-" + string.slice(index - 1);
5898
+ string = string.slice(0, index4 - 1) + "-" + string.slice(index4 - 1);
2235
5899
  isLastLastCharUpper = isLastCharUpper;
2236
5900
  isLastCharUpper = false;
2237
5901
  isLastCharLower = true;
@@ -2306,7 +5970,7 @@ String.prototype.camelCase = function() {
2306
5970
  return camelCase(String(this));
2307
5971
  };
2308
5972
  String.prototype.concatIf = function(it, condition) {
2309
- return condition ? `${this}${it}` : this;
5973
+ return condition ? `${this}${it}` : String(this);
2310
5974
  };
2311
5975
  Array.prototype.random = function() {
2312
5976
  return this[~~(Math.random() * this.length)];
@@ -3360,7 +7024,7 @@ minimatch.unescape = unescape;
3360
7024
 
3361
7025
  // src/cli/commands/sqliteIntrospect.ts
3362
7026
  var import_hanji2 = __toESM(require_hanji());
3363
- var sqlitePushIntrospect = async (client, filters) => {
7027
+ var sqlitePushIntrospect = async (db, filters) => {
3364
7028
  const matchers = filters.map((it) => {
3365
7029
  return new Minimatch(it);
3366
7030
  });
@@ -3374,29 +7038,15 @@ var sqlitePushIntrospect = async (client, filters) => {
3374
7038
  }
3375
7039
  return false;
3376
7040
  };
3377
- const res = await fromDatabase(client, filter2);
3378
- const schema = { id: originUUID, prevId: "", ...res };
3379
- return { schema };
7041
+ const res = await fromDatabase(db, filter2);
7042
+ const schema3 = { id: originUUID, prevId: "", ...res };
7043
+ return { schema: schema3 };
3380
7044
  };
3381
7045
 
3382
7046
  // src/cli/commands/pgIntrospect.ts
3383
- var import_hanji3 = __toESM(require_hanji());
3384
- init_views();
3385
- init_pgSerializer();
3386
-
3387
- // src/introspect-pg.ts
3388
- import { getTableName as getTableName3, is as is3 } from "drizzle-orm";
3389
- import {
3390
- createTableRelationsHelpers,
3391
- extractTablesRelationalConfig,
3392
- Many,
3393
- One
3394
- } from "drizzle-orm/relations";
3395
7047
  init_pgSerializer();
3396
-
3397
- // src/cli/commands/pgIntrospect.ts
3398
- var pgPushIntrospect = async (connection, filters, schemaFilters) => {
3399
- const { client } = connection;
7048
+ init_global();
7049
+ var pgPushIntrospect = async (db, filters, schemaFilters) => {
3400
7050
  const matchers = filters.map((it) => {
3401
7051
  return new Minimatch(it);
3402
7052
  });
@@ -3410,17 +7060,12 @@ var pgPushIntrospect = async (connection, filters, schemaFilters) => {
3410
7060
  }
3411
7061
  return false;
3412
7062
  };
3413
- const res = await fromDatabase2(client, filter2, schemaFilters);
3414
- const schema = { id: originUUID, prevId: "", ...res };
3415
- const { internal, ...schemaWithoutInternals } = schema;
7063
+ const res = await fromDatabase2(db, filter2, schemaFilters);
7064
+ const schema3 = { id: originUUID, prevId: "", ...res };
7065
+ const { internal, ...schemaWithoutInternals } = schema3;
3416
7066
  return { schema: schemaWithoutInternals };
3417
7067
  };
3418
-
3419
- // src/utils-studio.ts
3420
- init_drivers();
3421
7068
  export {
3422
- DrizzleORMPgClient,
3423
- TursoSqlite,
3424
7069
  pgSchemaToDrizzle as drizzleSchemaPg,
3425
7070
  sqliteSchemaToDrizzle as drizzleSchemaSQLite,
3426
7071
  pgPushIntrospect,