drizzle-kit 0.20.16 → 0.20.17-14a4eaa

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