drizzle-kit 0.20.14-a77266f → 0.20.14-b6f235e
Sign up to get free protection for your applications and to get access to all the features.
- package/bin.cjs +21882 -21527
- package/cli/commands/migrate.d.ts +121 -97
- package/cli/commands/mysqlIntrospect.d.ts +8 -14
- package/cli/commands/mysqlPushUtils.d.ts +2 -2
- package/cli/commands/pgConnect.d.ts +1 -1
- package/cli/commands/pgIntrospect.d.ts +18 -11
- package/cli/commands/pgPushUtils.d.ts +2 -2
- package/cli/commands/sqliteIntrospect.d.ts +9 -9
- package/cli/commands/sqlitePushUtils.d.ts +3 -3
- package/cli/commands/utils.d.ts +15 -259
- package/cli/validations/cli.d.ts +107 -0
- package/cli/validations/common.d.ts +205 -7
- package/cli/validations/mysql.d.ts +6 -1
- package/cli/validations/pg.d.ts +6 -1
- package/cli/validations/sqlite.d.ts +382 -0
- package/cli/views.d.ts +7 -5
- package/global.d.ts +3 -1
- package/index.d.mts +8 -6
- package/index.d.ts +8 -6
- package/index.js +1 -0
- package/introspect-mysql.d.ts +1 -1
- package/introspect-pg.d.ts +5 -2
- package/introspect-sqlite.d.ts +1 -1
- package/jsonDiffer.d.ts +14 -29
- package/jsonStatements.d.ts +38 -11
- package/package.json +18 -50
- package/payload.js +8053 -8337
- package/payload.mjs +9022 -9312
- package/schemaValidator.d.ts +73 -70
- package/serializer/mysqlImports.d.ts +3 -7
- package/serializer/mysqlSchema.d.ts +1624 -493
- package/serializer/mysqlSerializer.d.ts +4 -4
- package/serializer/pgImports.d.ts +2 -2
- package/serializer/pgSchema.d.ts +1260 -801
- package/serializer/sqliteImports.d.ts +2 -4
- package/serializer/sqliteSchema.d.ts +144 -570
- package/serializer/sqliteSerializer.d.ts +3 -3
- package/snapshotsDiffer.d.ts +1908 -1050
- package/utils/words.d.ts +1 -1
- package/utils-studio.js +4147 -83
- package/utils-studio.mjs +4147 -83
- package/utils.d.ts +6 -140
- package/utils.js +3903 -7064
- package/utils.mjs +3982 -7143
- package/cli/commands/mysqlUp.d.ts +0 -4
- package/cli/commands/pgUp.d.ts +0 -4
- package/cli/commands/sqliteUtils.d.ts +0 -162
- package/cli/commands/upFolders.d.ts +0 -27
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
|
359
|
-
if (
|
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,
|
367
|
-
endIndex =
|
368
|
-
|
369
|
-
} while (
|
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,
|
374
|
+
function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index4) {
|
374
375
|
let endIndex = 0;
|
375
376
|
let returnValue = "";
|
376
377
|
do {
|
377
|
-
const gotCR = string[
|
378
|
-
returnValue += string.slice(endIndex, gotCR ?
|
379
|
-
endIndex =
|
380
|
-
|
381
|
-
} while (
|
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
|
}
|
@@ -1072,12 +1073,3706 @@ 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, schemaInternalV6, 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
|
+
schemaInternalV6 = objectType({
|
4327
|
+
version: literalType("6"),
|
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
|
+
schemaInternal = objectType({
|
4337
|
+
version: literalType("6"),
|
4338
|
+
dialect,
|
4339
|
+
tables: recordType(stringType(), table),
|
4340
|
+
_meta: objectType({
|
4341
|
+
tables: recordType(stringType(), stringType()),
|
4342
|
+
columns: recordType(stringType(), stringType())
|
4343
|
+
}),
|
4344
|
+
internal: kitInternals
|
4345
|
+
}).strict();
|
4346
|
+
schemaV3 = schemaInternalV3.merge(schemaHash);
|
4347
|
+
schemaV4 = schemaInternalV4.merge(schemaHash);
|
4348
|
+
schemaV5 = schemaInternalV5.merge(schemaHash);
|
4349
|
+
schema = schemaInternal.merge(schemaHash);
|
4350
|
+
tableSquashedV4 = objectType({
|
4351
|
+
name: stringType(),
|
4352
|
+
schema: stringType().optional(),
|
4353
|
+
columns: recordType(stringType(), column),
|
4354
|
+
indexes: recordType(stringType(), stringType()),
|
4355
|
+
foreignKeys: recordType(stringType(), stringType())
|
4356
|
+
}).strict();
|
4357
|
+
tableSquashed = objectType({
|
4358
|
+
name: stringType(),
|
4359
|
+
columns: recordType(stringType(), column),
|
4360
|
+
indexes: recordType(stringType(), stringType()),
|
4361
|
+
foreignKeys: recordType(stringType(), stringType()),
|
4362
|
+
compositePrimaryKeys: recordType(stringType(), stringType()),
|
4363
|
+
uniqueConstraints: recordType(stringType(), stringType()).default({})
|
4364
|
+
}).strict();
|
4365
|
+
schemaSquashed = objectType({
|
4366
|
+
version: literalType("5"),
|
4367
|
+
dialect,
|
4368
|
+
tables: recordType(stringType(), tableSquashed)
|
4369
|
+
}).strict();
|
4370
|
+
schemaSquashedV4 = objectType({
|
4371
|
+
version: literalType("4"),
|
4372
|
+
dialect,
|
4373
|
+
tables: recordType(stringType(), tableSquashedV4),
|
4374
|
+
schemas: recordType(stringType(), stringType())
|
4375
|
+
}).strict();
|
4376
|
+
mysqlSchema = schema;
|
4377
|
+
mysqlSchemaV5 = schemaV5;
|
4378
|
+
backwardCompatibleMysqlSchema = unionType([mysqlSchemaV5, schema]);
|
4379
|
+
dryMySql = mysqlSchema.parse({
|
4380
|
+
version: snapshotVersion,
|
4381
|
+
dialect: "mysql",
|
4382
|
+
id: originUUID,
|
4383
|
+
prevId: "",
|
4384
|
+
tables: {},
|
4385
|
+
schemas: {},
|
4386
|
+
_meta: {
|
4387
|
+
schemas: {},
|
4388
|
+
tables: {},
|
4389
|
+
columns: {}
|
4390
|
+
}
|
4391
|
+
});
|
4392
|
+
}
|
4393
|
+
});
|
4394
|
+
|
4395
|
+
// src/serializer/pgSchema.ts
|
4396
|
+
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;
|
4397
|
+
var init_pgSchema = __esm({
|
4398
|
+
"src/serializer/pgSchema.ts"() {
|
4399
|
+
"use strict";
|
4400
|
+
init_global();
|
4401
|
+
init_lib();
|
4402
|
+
indexV2 = objectType({
|
4403
|
+
name: stringType(),
|
4404
|
+
columns: recordType(
|
4405
|
+
stringType(),
|
4406
|
+
objectType({
|
4407
|
+
name: stringType()
|
4408
|
+
})
|
4409
|
+
),
|
4410
|
+
isUnique: booleanType()
|
4411
|
+
}).strict();
|
4412
|
+
columnV2 = objectType({
|
4413
|
+
name: stringType(),
|
4414
|
+
type: stringType(),
|
4415
|
+
primaryKey: booleanType(),
|
4416
|
+
notNull: booleanType(),
|
4417
|
+
default: anyType().optional(),
|
4418
|
+
references: stringType().optional()
|
4419
|
+
}).strict();
|
4420
|
+
tableV2 = objectType({
|
4421
|
+
name: stringType(),
|
4422
|
+
columns: recordType(stringType(), columnV2),
|
4423
|
+
indexes: recordType(stringType(), indexV2)
|
4424
|
+
}).strict();
|
4425
|
+
enumSchemaV1 = objectType({
|
4426
|
+
name: stringType(),
|
4427
|
+
values: recordType(stringType(), stringType())
|
4428
|
+
}).strict();
|
4429
|
+
enumSchema = objectType({
|
4430
|
+
name: stringType(),
|
4431
|
+
schema: stringType(),
|
4432
|
+
values: stringType().array()
|
4433
|
+
}).strict();
|
4434
|
+
pgSchemaV2 = objectType({
|
4435
|
+
version: literalType("2"),
|
4436
|
+
tables: recordType(stringType(), tableV2),
|
4437
|
+
enums: recordType(stringType(), enumSchemaV1)
|
4438
|
+
}).strict();
|
4439
|
+
references = objectType({
|
4440
|
+
foreignKeyName: stringType(),
|
4441
|
+
table: stringType(),
|
4442
|
+
column: stringType(),
|
4443
|
+
onDelete: stringType().optional(),
|
4444
|
+
onUpdate: stringType().optional()
|
4445
|
+
}).strict();
|
4446
|
+
columnV1 = objectType({
|
4447
|
+
name: stringType(),
|
4448
|
+
type: stringType(),
|
4449
|
+
primaryKey: booleanType(),
|
4450
|
+
notNull: booleanType(),
|
4451
|
+
default: anyType().optional(),
|
4452
|
+
references: references.optional()
|
4453
|
+
}).strict();
|
4454
|
+
tableV1 = objectType({
|
4455
|
+
name: stringType(),
|
4456
|
+
columns: recordType(stringType(), columnV1),
|
4457
|
+
indexes: recordType(stringType(), indexV2)
|
4458
|
+
}).strict();
|
4459
|
+
pgSchemaV1 = objectType({
|
4460
|
+
version: literalType("1"),
|
4461
|
+
tables: recordType(stringType(), tableV1),
|
4462
|
+
enums: recordType(stringType(), enumSchemaV1)
|
4463
|
+
}).strict();
|
4464
|
+
index2 = objectType({
|
4465
|
+
name: stringType(),
|
4466
|
+
columns: stringType().array(),
|
4467
|
+
isUnique: booleanType()
|
4468
|
+
}).strict();
|
4469
|
+
fk2 = objectType({
|
4470
|
+
name: stringType(),
|
4471
|
+
tableFrom: stringType(),
|
4472
|
+
columnsFrom: stringType().array(),
|
4473
|
+
tableTo: stringType(),
|
4474
|
+
schemaTo: stringType().optional(),
|
4475
|
+
columnsTo: stringType().array(),
|
4476
|
+
onUpdate: stringType().optional(),
|
4477
|
+
onDelete: stringType().optional()
|
4478
|
+
}).strict();
|
4479
|
+
column2 = objectType({
|
4480
|
+
name: stringType(),
|
4481
|
+
type: stringType(),
|
4482
|
+
typeSchema: stringType().optional(),
|
4483
|
+
primaryKey: booleanType(),
|
4484
|
+
notNull: booleanType(),
|
4485
|
+
default: anyType().optional(),
|
4486
|
+
isUnique: anyType().optional(),
|
4487
|
+
uniqueName: stringType().optional(),
|
4488
|
+
nullsNotDistinct: booleanType().optional()
|
4489
|
+
}).strict();
|
4490
|
+
tableV32 = objectType({
|
4491
|
+
name: stringType(),
|
4492
|
+
columns: recordType(stringType(), column2),
|
4493
|
+
indexes: recordType(stringType(), index2),
|
4494
|
+
foreignKeys: recordType(stringType(), fk2)
|
4495
|
+
}).strict();
|
4496
|
+
compositePK2 = objectType({
|
4497
|
+
name: stringType(),
|
4498
|
+
columns: stringType().array()
|
4499
|
+
}).strict();
|
4500
|
+
uniqueConstraint2 = objectType({
|
4501
|
+
name: stringType(),
|
4502
|
+
columns: stringType().array(),
|
4503
|
+
nullsNotDistinct: booleanType()
|
4504
|
+
}).strict();
|
4505
|
+
tableV42 = objectType({
|
4506
|
+
name: stringType(),
|
4507
|
+
schema: stringType(),
|
4508
|
+
columns: recordType(stringType(), column2),
|
4509
|
+
indexes: recordType(stringType(), index2),
|
4510
|
+
foreignKeys: recordType(stringType(), fk2)
|
4511
|
+
}).strict();
|
4512
|
+
table2 = objectType({
|
4513
|
+
name: stringType(),
|
4514
|
+
schema: stringType(),
|
4515
|
+
columns: recordType(stringType(), column2),
|
4516
|
+
indexes: recordType(stringType(), index2),
|
4517
|
+
foreignKeys: recordType(stringType(), fk2),
|
4518
|
+
compositePrimaryKeys: recordType(stringType(), compositePK2),
|
4519
|
+
uniqueConstraints: recordType(stringType(), uniqueConstraint2).default({})
|
4520
|
+
}).strict();
|
4521
|
+
schemaHash2 = objectType({
|
4522
|
+
id: stringType(),
|
4523
|
+
prevId: stringType()
|
4524
|
+
});
|
4525
|
+
kitInternals2 = objectType({
|
4526
|
+
tables: recordType(
|
4527
|
+
stringType(),
|
4528
|
+
objectType({
|
4529
|
+
columns: recordType(
|
4530
|
+
stringType(),
|
4531
|
+
objectType({
|
4532
|
+
isArray: booleanType().optional(),
|
4533
|
+
dimensions: numberType().optional(),
|
4534
|
+
rawType: stringType().optional()
|
4535
|
+
}).optional()
|
4536
|
+
)
|
4537
|
+
}).optional()
|
4538
|
+
)
|
4539
|
+
}).optional();
|
4540
|
+
pgSchemaInternalV3 = objectType({
|
4541
|
+
version: literalType("3"),
|
4542
|
+
dialect: literalType("pg"),
|
4543
|
+
tables: recordType(stringType(), tableV32),
|
4544
|
+
enums: recordType(stringType(), enumSchemaV1)
|
4545
|
+
}).strict();
|
4546
|
+
pgSchemaInternalV4 = objectType({
|
4547
|
+
version: literalType("4"),
|
4548
|
+
dialect: literalType("pg"),
|
4549
|
+
tables: recordType(stringType(), tableV42),
|
4550
|
+
enums: recordType(stringType(), enumSchemaV1),
|
4551
|
+
schemas: recordType(stringType(), stringType())
|
4552
|
+
}).strict();
|
4553
|
+
pgSchemaInternalV5 = objectType({
|
4554
|
+
version: literalType("5"),
|
4555
|
+
dialect: literalType("pg"),
|
4556
|
+
tables: recordType(stringType(), table2),
|
4557
|
+
enums: recordType(stringType(), enumSchemaV1),
|
4558
|
+
schemas: recordType(stringType(), stringType()),
|
4559
|
+
_meta: objectType({
|
4560
|
+
schemas: recordType(stringType(), stringType()),
|
4561
|
+
tables: recordType(stringType(), stringType()),
|
4562
|
+
columns: recordType(stringType(), stringType())
|
4563
|
+
}),
|
4564
|
+
internal: kitInternals2
|
4565
|
+
}).strict();
|
4566
|
+
pgSchemaExternal = objectType({
|
4567
|
+
version: literalType("5"),
|
4568
|
+
dialect: literalType("pg"),
|
4569
|
+
tables: arrayType(table2),
|
4570
|
+
enums: arrayType(enumSchemaV1),
|
4571
|
+
schemas: arrayType(objectType({ name: stringType() })),
|
4572
|
+
_meta: objectType({
|
4573
|
+
schemas: recordType(stringType(), stringType()),
|
4574
|
+
tables: recordType(stringType(), stringType()),
|
4575
|
+
columns: recordType(stringType(), stringType())
|
4576
|
+
})
|
4577
|
+
}).strict();
|
4578
|
+
pgSchemaInternal = objectType({
|
4579
|
+
version: literalType("6"),
|
4580
|
+
dialect: literalType("pg"),
|
4581
|
+
tables: recordType(stringType(), table2),
|
4582
|
+
enums: recordType(stringType(), enumSchema),
|
4583
|
+
schemas: recordType(stringType(), stringType()),
|
4584
|
+
_meta: objectType({
|
4585
|
+
schemas: recordType(stringType(), stringType()),
|
4586
|
+
tables: recordType(stringType(), stringType()),
|
4587
|
+
columns: recordType(stringType(), stringType())
|
4588
|
+
}),
|
4589
|
+
internal: kitInternals2
|
4590
|
+
}).strict();
|
4591
|
+
tableSquashed2 = objectType({
|
4592
|
+
name: stringType(),
|
4593
|
+
schema: stringType(),
|
4594
|
+
columns: recordType(stringType(), column2),
|
4595
|
+
indexes: recordType(stringType(), stringType()),
|
4596
|
+
foreignKeys: recordType(stringType(), stringType()),
|
4597
|
+
compositePrimaryKeys: recordType(stringType(), stringType()),
|
4598
|
+
uniqueConstraints: recordType(stringType(), stringType())
|
4599
|
+
}).strict();
|
4600
|
+
tableSquashedV42 = objectType({
|
4601
|
+
name: stringType(),
|
4602
|
+
schema: stringType(),
|
4603
|
+
columns: recordType(stringType(), column2),
|
4604
|
+
indexes: recordType(stringType(), stringType()),
|
4605
|
+
foreignKeys: recordType(stringType(), stringType())
|
4606
|
+
}).strict();
|
4607
|
+
pgSchemaSquashedV4 = objectType({
|
4608
|
+
version: literalType("4"),
|
4609
|
+
dialect: enumType(["pg"]),
|
4610
|
+
tables: recordType(stringType(), tableSquashedV42),
|
4611
|
+
enums: recordType(stringType(), enumSchemaV1),
|
4612
|
+
schemas: recordType(stringType(), stringType())
|
4613
|
+
}).strict();
|
4614
|
+
pgSchemaSquashed = objectType({
|
4615
|
+
version: literalType("6"),
|
4616
|
+
dialect: enumType(["pg"]),
|
4617
|
+
tables: recordType(stringType(), tableSquashed2),
|
4618
|
+
enums: recordType(stringType(), enumSchema),
|
4619
|
+
schemas: recordType(stringType(), stringType())
|
4620
|
+
}).strict();
|
4621
|
+
pgSchemaV3 = pgSchemaInternalV3.merge(schemaHash2);
|
4622
|
+
pgSchemaV4 = pgSchemaInternalV4.merge(schemaHash2);
|
4623
|
+
pgSchemaV5 = pgSchemaInternalV5.merge(schemaHash2);
|
4624
|
+
pgSchema2 = pgSchemaInternal.merge(schemaHash2);
|
4625
|
+
backwardCompatiblePgSchema = unionType([pgSchemaV5, pgSchema2]);
|
4626
|
+
dryPg = pgSchema2.parse({
|
4627
|
+
version: snapshotVersion,
|
4628
|
+
dialect: "pg",
|
4629
|
+
id: originUUID,
|
4630
|
+
prevId: "",
|
4631
|
+
tables: {},
|
4632
|
+
enums: {},
|
4633
|
+
schemas: {},
|
4634
|
+
_meta: {
|
4635
|
+
schemas: {},
|
4636
|
+
tables: {},
|
4637
|
+
columns: {}
|
4638
|
+
}
|
4639
|
+
});
|
4640
|
+
}
|
4641
|
+
});
|
4642
|
+
|
4643
|
+
// src/serializer/sqliteSchema.ts
|
4644
|
+
var index3, fk3, compositePK3, column3, tableV33, uniqueConstraint3, table3, dialect2, schemaHash3, schemaInternalV32, schemaInternalV42, latestVersion, schemaInternal2, schemaV32, schemaV42, schema2, tableSquashed3, schemaSquashed2, drySQLite;
|
4645
|
+
var init_sqliteSchema = __esm({
|
4646
|
+
"src/serializer/sqliteSchema.ts"() {
|
4647
|
+
"use strict";
|
4648
|
+
init_global();
|
4649
|
+
init_lib();
|
4650
|
+
index3 = objectType({
|
4651
|
+
name: stringType(),
|
4652
|
+
columns: stringType().array(),
|
4653
|
+
where: stringType().optional(),
|
4654
|
+
isUnique: booleanType()
|
4655
|
+
}).strict();
|
4656
|
+
fk3 = objectType({
|
4657
|
+
name: stringType(),
|
4658
|
+
tableFrom: stringType(),
|
4659
|
+
columnsFrom: stringType().array(),
|
4660
|
+
tableTo: stringType(),
|
4661
|
+
columnsTo: stringType().array(),
|
4662
|
+
onUpdate: stringType().optional(),
|
4663
|
+
onDelete: stringType().optional()
|
4664
|
+
}).strict();
|
4665
|
+
compositePK3 = objectType({
|
4666
|
+
columns: stringType().array(),
|
4667
|
+
name: stringType().optional()
|
4668
|
+
}).strict();
|
4669
|
+
column3 = objectType({
|
4670
|
+
name: stringType(),
|
4671
|
+
type: stringType(),
|
4672
|
+
primaryKey: booleanType(),
|
4673
|
+
notNull: booleanType(),
|
4674
|
+
autoincrement: booleanType().optional(),
|
4675
|
+
default: anyType().optional()
|
4676
|
+
}).strict();
|
4677
|
+
tableV33 = objectType({
|
4678
|
+
name: stringType(),
|
4679
|
+
columns: recordType(stringType(), column3),
|
4680
|
+
indexes: recordType(stringType(), index3),
|
4681
|
+
foreignKeys: recordType(stringType(), fk3)
|
4682
|
+
}).strict();
|
4683
|
+
uniqueConstraint3 = objectType({
|
4684
|
+
name: stringType(),
|
4685
|
+
columns: stringType().array()
|
4686
|
+
}).strict();
|
4687
|
+
table3 = objectType({
|
4688
|
+
name: stringType(),
|
4689
|
+
columns: recordType(stringType(), column3),
|
4690
|
+
indexes: recordType(stringType(), index3),
|
4691
|
+
foreignKeys: recordType(stringType(), fk3),
|
4692
|
+
compositePrimaryKeys: recordType(stringType(), compositePK3),
|
4693
|
+
uniqueConstraints: recordType(stringType(), uniqueConstraint3).default({})
|
4694
|
+
}).strict();
|
4695
|
+
dialect2 = enumType(["sqlite"]);
|
4696
|
+
schemaHash3 = objectType({
|
4697
|
+
id: stringType(),
|
4698
|
+
prevId: stringType()
|
4699
|
+
}).strict();
|
4700
|
+
schemaInternalV32 = objectType({
|
4701
|
+
version: literalType("3"),
|
4702
|
+
dialect: dialect2,
|
4703
|
+
tables: recordType(stringType(), tableV33),
|
4704
|
+
enums: objectType({})
|
4705
|
+
}).strict();
|
4706
|
+
schemaInternalV42 = objectType({
|
4707
|
+
version: literalType("4"),
|
4708
|
+
dialect: dialect2,
|
4709
|
+
tables: recordType(stringType(), table3),
|
4710
|
+
enums: objectType({})
|
4711
|
+
}).strict();
|
4712
|
+
latestVersion = literalType("5");
|
4713
|
+
schemaInternal2 = objectType({
|
4714
|
+
version: latestVersion,
|
4715
|
+
dialect: dialect2,
|
4716
|
+
tables: recordType(stringType(), table3),
|
4717
|
+
enums: objectType({}),
|
4718
|
+
_meta: objectType({
|
4719
|
+
tables: recordType(stringType(), stringType()),
|
4720
|
+
columns: recordType(stringType(), stringType())
|
4721
|
+
})
|
4722
|
+
}).strict();
|
4723
|
+
schemaV32 = schemaInternalV32.merge(schemaHash3).strict();
|
4724
|
+
schemaV42 = schemaInternalV42.merge(schemaHash3).strict();
|
4725
|
+
schema2 = schemaInternal2.merge(schemaHash3).strict();
|
4726
|
+
tableSquashed3 = objectType({
|
4727
|
+
name: stringType(),
|
4728
|
+
columns: recordType(stringType(), column3),
|
4729
|
+
indexes: recordType(stringType(), stringType()),
|
4730
|
+
foreignKeys: recordType(stringType(), stringType()),
|
4731
|
+
compositePrimaryKeys: recordType(stringType(), stringType()),
|
4732
|
+
uniqueConstraints: recordType(stringType(), stringType()).default({})
|
4733
|
+
}).strict();
|
4734
|
+
schemaSquashed2 = objectType({
|
4735
|
+
version: latestVersion,
|
4736
|
+
dialect: dialect2,
|
4737
|
+
tables: recordType(stringType(), tableSquashed3),
|
4738
|
+
enums: anyType()
|
4739
|
+
}).strict();
|
4740
|
+
drySQLite = schema2.parse({
|
4741
|
+
version: "5",
|
4742
|
+
dialect: "sqlite",
|
4743
|
+
id: originUUID,
|
4744
|
+
prevId: "",
|
4745
|
+
tables: {},
|
4746
|
+
enums: {},
|
4747
|
+
_meta: {
|
4748
|
+
tables: {},
|
4749
|
+
columns: {}
|
4750
|
+
}
|
4751
|
+
});
|
4752
|
+
}
|
4753
|
+
});
|
4754
|
+
|
4755
|
+
// src/utils.ts
|
4756
|
+
var init_utils = __esm({
|
4757
|
+
"src/utils.ts"() {
|
4758
|
+
"use strict";
|
4759
|
+
init_views();
|
4760
|
+
init_mysqlSchema();
|
4761
|
+
init_pgSchema();
|
4762
|
+
init_sqliteSchema();
|
4763
|
+
init_source();
|
4764
|
+
init_global();
|
4765
|
+
}
|
4766
|
+
});
|
4767
|
+
|
1075
4768
|
// src/cli/views.ts
|
1076
4769
|
var import_hanji;
|
1077
4770
|
var init_views = __esm({
|
1078
4771
|
"src/cli/views.ts"() {
|
4772
|
+
"use strict";
|
1079
4773
|
init_source();
|
1080
4774
|
import_hanji = __toESM(require_hanji());
|
4775
|
+
init_utils();
|
1081
4776
|
}
|
1082
4777
|
});
|
1083
4778
|
|
@@ -1085,6 +4780,7 @@ var init_views = __esm({
|
|
1085
4780
|
var glob;
|
1086
4781
|
var init_serializer = __esm({
|
1087
4782
|
"src/serializer/index.ts"() {
|
4783
|
+
"use strict";
|
1088
4784
|
glob = __toESM(require("glob"));
|
1089
4785
|
init_source();
|
1090
4786
|
init_views();
|
@@ -1094,12 +4790,14 @@ var init_serializer = __esm({
|
|
1094
4790
|
// src/cli/validations/outputs.ts
|
1095
4791
|
var init_outputs = __esm({
|
1096
4792
|
"src/cli/validations/outputs.ts"() {
|
4793
|
+
"use strict";
|
1097
4794
|
init_source();
|
1098
4795
|
}
|
1099
4796
|
});
|
1100
4797
|
|
1101
4798
|
// src/serializer/sqliteSerializer.ts
|
1102
4799
|
function mapSqlToSqliteType(sqlType) {
|
4800
|
+
const lowered = sqlType.toLowerCase();
|
1103
4801
|
if ([
|
1104
4802
|
"int",
|
1105
4803
|
"integer",
|
@@ -1111,39 +4809,43 @@ function mapSqlToSqliteType(sqlType) {
|
|
1111
4809
|
"unsigned big int",
|
1112
4810
|
"int2",
|
1113
4811
|
"int8"
|
1114
|
-
].
|
4812
|
+
].some((it) => lowered.startsWith(it))) {
|
1115
4813
|
return "integer";
|
1116
4814
|
} else if ([
|
1117
4815
|
"character",
|
1118
4816
|
"varchar",
|
1119
|
-
"
|
4817
|
+
"varying character",
|
4818
|
+
"national varying character",
|
1120
4819
|
"nchar",
|
1121
4820
|
"native character",
|
1122
4821
|
"nvarchar",
|
1123
4822
|
"text",
|
1124
4823
|
"clob"
|
1125
|
-
].some((it) =>
|
4824
|
+
].some((it) => lowered.startsWith(it))) {
|
4825
|
+
const match2 = lowered.match(/\d+/);
|
4826
|
+
if (match2) {
|
4827
|
+
return `text(${match2[0]})`;
|
4828
|
+
}
|
1126
4829
|
return "text";
|
1127
|
-
} else if (
|
4830
|
+
} else if (lowered.startsWith("blob")) {
|
1128
4831
|
return "blob";
|
1129
|
-
} else if (["real", "double", "double precision", "float"].
|
1130
|
-
sqlType.toLowerCase()
|
1131
|
-
)) {
|
4832
|
+
} else if (["real", "double", "double precision", "float"].some((it) => lowered.startsWith(it))) {
|
1132
4833
|
return "real";
|
1133
4834
|
} else {
|
1134
4835
|
return "numeric";
|
1135
4836
|
}
|
1136
4837
|
}
|
1137
|
-
var import_drizzle_orm, import_sqlite_core2,
|
4838
|
+
var import_drizzle_orm, import_sqlite_core2, dialect3, fromDatabase;
|
1138
4839
|
var init_sqliteSerializer = __esm({
|
1139
4840
|
"src/serializer/sqliteSerializer.ts"() {
|
4841
|
+
"use strict";
|
1140
4842
|
import_drizzle_orm = require("drizzle-orm");
|
1141
4843
|
import_sqlite_core2 = require("drizzle-orm/sqlite-core");
|
1142
4844
|
init_serializer();
|
1143
4845
|
init_outputs();
|
1144
4846
|
init_source();
|
1145
|
-
|
1146
|
-
fromDatabase = async (db, tablesFilter = (
|
4847
|
+
dialect3 = new import_sqlite_core2.SQLiteSyncDialect();
|
4848
|
+
fromDatabase = async (db, tablesFilter = (table4) => true, progressCallback) => {
|
1147
4849
|
const result = {};
|
1148
4850
|
const columns = await db.query(
|
1149
4851
|
`SELECT
|
@@ -1164,23 +4866,23 @@ var init_sqliteSerializer = __esm({
|
|
1164
4866
|
let indexesCount = 0;
|
1165
4867
|
let foreignKeysCount = 0;
|
1166
4868
|
const tableToPk = {};
|
1167
|
-
for (const
|
1168
|
-
if (!tablesFilter(
|
4869
|
+
for (const column4 of columns) {
|
4870
|
+
if (!tablesFilter(column4.tableName))
|
1169
4871
|
continue;
|
1170
4872
|
columnsCount += 1;
|
1171
4873
|
if (progressCallback) {
|
1172
4874
|
progressCallback("columns", columnsCount, "fetching");
|
1173
4875
|
}
|
1174
|
-
const tableName =
|
4876
|
+
const tableName = column4.tableName;
|
1175
4877
|
tablesCount.add(tableName);
|
1176
4878
|
if (progressCallback) {
|
1177
4879
|
progressCallback("tables", tablesCount.size, "fetching");
|
1178
4880
|
}
|
1179
|
-
const columnName =
|
1180
|
-
const isNotNull =
|
1181
|
-
const columnType =
|
1182
|
-
const isPrimary =
|
1183
|
-
const columnDefault =
|
4881
|
+
const columnName = column4.columnName;
|
4882
|
+
const isNotNull = column4.notNull === 1;
|
4883
|
+
const columnType = column4.columnType;
|
4884
|
+
const isPrimary = column4.pk !== 0;
|
4885
|
+
const columnDefault = column4.defaultValue;
|
1184
4886
|
const isAutoincrement = isPrimary && tablesWithSeq.includes(tableName);
|
1185
4887
|
if (isPrimary) {
|
1186
4888
|
if (typeof tableToPk[tableName] === "undefined") {
|
@@ -1189,7 +4891,7 @@ var init_sqliteSerializer = __esm({
|
|
1189
4891
|
tableToPk[tableName].push(columnName);
|
1190
4892
|
}
|
1191
4893
|
}
|
1192
|
-
const
|
4894
|
+
const table4 = result[tableName];
|
1193
4895
|
const newColumn = {
|
1194
4896
|
default: columnDefault === null ? void 0 : /^-?[\d.]+(?:e-?\d+)?$/.test(columnDefault) ? Number(columnDefault) : ["CURRENT_TIME", "CURRENT_DATE", "CURRENT_TIMESTAMP"].includes(
|
1195
4897
|
columnDefault
|
@@ -1203,7 +4905,7 @@ var init_sqliteSerializer = __esm({
|
|
1203
4905
|
primaryKey: false,
|
1204
4906
|
notNull: isNotNull
|
1205
4907
|
};
|
1206
|
-
if (!
|
4908
|
+
if (!table4) {
|
1207
4909
|
result[tableName] = {
|
1208
4910
|
name: tableName,
|
1209
4911
|
columns: {
|
@@ -1552,16 +5254,17 @@ var require_brace_expansion = __commonJS({
|
|
1552
5254
|
});
|
1553
5255
|
|
1554
5256
|
// src/serializer/pgSerializer.ts
|
1555
|
-
var import_pg_core2, import_pg_core3, import_drizzle_orm2,
|
5257
|
+
var import_pg_core2, import_pg_core3, import_drizzle_orm2, dialect4, trimChar, fromDatabase2, columnToDefault, defaultForColumn;
|
1556
5258
|
var init_pgSerializer = __esm({
|
1557
5259
|
"src/serializer/pgSerializer.ts"() {
|
5260
|
+
"use strict";
|
1558
5261
|
import_pg_core2 = require("drizzle-orm/pg-core");
|
1559
5262
|
import_pg_core3 = require("drizzle-orm/pg-core");
|
1560
5263
|
import_drizzle_orm2 = require("drizzle-orm");
|
1561
5264
|
init_serializer();
|
1562
5265
|
init_source();
|
1563
5266
|
init_outputs();
|
1564
|
-
|
5267
|
+
dialect4 = new import_pg_core2.PgDialect();
|
1565
5268
|
trimChar = (str, char) => {
|
1566
5269
|
let start = 0;
|
1567
5270
|
let end = str.length;
|
@@ -1571,7 +5274,7 @@ var init_pgSerializer = __esm({
|
|
1571
5274
|
--end;
|
1572
5275
|
return start > 0 || end < str.length ? str.substring(start, end) : str.toString();
|
1573
5276
|
};
|
1574
|
-
fromDatabase2 = async (db, tablesFilter = (
|
5277
|
+
fromDatabase2 = async (db, tablesFilter = () => true, schemaFilters, progressCallback) => {
|
1575
5278
|
const result = {};
|
1576
5279
|
const internals = { tables: {} };
|
1577
5280
|
const where = schemaFilters.map((t) => `table_schema = '${t}'`).join(" or ");
|
@@ -1679,14 +5382,14 @@ var init_pgSerializer = __esm({
|
|
1679
5382
|
if (progressCallback) {
|
1680
5383
|
progressCallback("fks", foreignKeysCount, "fetching");
|
1681
5384
|
}
|
1682
|
-
for (const
|
1683
|
-
const columnFrom =
|
1684
|
-
const tableTo =
|
1685
|
-
const columnTo =
|
1686
|
-
const schemaTo =
|
1687
|
-
const foreignKeyName =
|
1688
|
-
const onUpdate =
|
1689
|
-
const onDelete =
|
5385
|
+
for (const fk4 of tableForeignKeys) {
|
5386
|
+
const columnFrom = fk4.column_name;
|
5387
|
+
const tableTo = fk4.foreign_table_name;
|
5388
|
+
const columnTo = fk4.foreign_column_name;
|
5389
|
+
const schemaTo = fk4.foreign_table_schema;
|
5390
|
+
const foreignKeyName = fk4.constraint_name;
|
5391
|
+
const onUpdate = fk4.update_rule.toLowerCase();
|
5392
|
+
const onDelete = fk4.delete_rule.toLowerCase();
|
1690
5393
|
if (typeof foreignKeysToReturn[foreignKeyName] !== "undefined") {
|
1691
5394
|
foreignKeysToReturn[foreignKeyName].columnsFrom.push(columnFrom);
|
1692
5395
|
foreignKeysToReturn[foreignKeyName].columnsTo.push(columnTo);
|
@@ -1793,6 +5496,8 @@ var init_pgSerializer = __esm({
|
|
1793
5496
|
columnToReturn[columnName] = {
|
1794
5497
|
name: columnName,
|
1795
5498
|
type: columnTypeMapped,
|
5499
|
+
typeSchema: "...",
|
5500
|
+
// TODO: add schema when type is enum
|
1796
5501
|
primaryKey: primaryKey.length === 1 && cprimaryKey.length < 2,
|
1797
5502
|
// default: isSerial ? undefined : defaultValue,
|
1798
5503
|
notNull: columnResponse.is_nullable === "NO"
|
@@ -1884,12 +5589,15 @@ var init_pgSerializer = __esm({
|
|
1884
5589
|
for (const dbEnum of allEnums) {
|
1885
5590
|
const enumName = dbEnum.enum_name;
|
1886
5591
|
const enumValue = dbEnum.enum_value;
|
1887
|
-
|
1888
|
-
|
5592
|
+
const enumSchema2 = dbEnum.enum_schema || "public";
|
5593
|
+
const key = `${enumSchema2}.${enumName}`;
|
5594
|
+
if (enumsToReturn[key] !== void 0 && enumsToReturn[key] !== null) {
|
5595
|
+
enumsToReturn[enumName].values.push(enumValue);
|
1889
5596
|
} else {
|
1890
5597
|
enumsToReturn[enumName] = {
|
1891
5598
|
name: enumName,
|
1892
|
-
values:
|
5599
|
+
values: [enumValue],
|
5600
|
+
schema: enumSchema2
|
1893
5601
|
};
|
1894
5602
|
}
|
1895
5603
|
}
|
@@ -1898,7 +5606,7 @@ var init_pgSerializer = __esm({
|
|
1898
5606
|
}
|
1899
5607
|
const schemasObject = Object.fromEntries([...schemas].map((it) => [it, it]));
|
1900
5608
|
return {
|
1901
|
-
version: "
|
5609
|
+
version: "6",
|
1902
5610
|
dialect: "pg",
|
1903
5611
|
tables: result,
|
1904
5612
|
enums: enumsToReturn,
|
@@ -1931,37 +5639,37 @@ var init_pgSerializer = __esm({
|
|
1931
5639
|
// json: "::json",
|
1932
5640
|
"character(": "::bpchar"
|
1933
5641
|
};
|
1934
|
-
defaultForColumn = (
|
1935
|
-
if (
|
5642
|
+
defaultForColumn = (column4) => {
|
5643
|
+
if (column4.data_type === "serial" || column4.data_type === "smallserial" || column4.data_type === "bigserial") {
|
1936
5644
|
return void 0;
|
1937
5645
|
}
|
1938
5646
|
const hasDifferentDefaultCast = Object.keys(columnToDefault).find(
|
1939
|
-
(it) =>
|
5647
|
+
(it) => column4.data_type.startsWith(it)
|
1940
5648
|
);
|
1941
|
-
if (
|
5649
|
+
if (column4.column_default === null) {
|
1942
5650
|
return void 0;
|
1943
5651
|
}
|
1944
|
-
const columnDefaultAsString =
|
5652
|
+
const columnDefaultAsString = column4.column_default.toString();
|
1945
5653
|
if (columnDefaultAsString.endsWith(
|
1946
|
-
hasDifferentDefaultCast ? columnToDefault[hasDifferentDefaultCast] :
|
5654
|
+
hasDifferentDefaultCast ? columnToDefault[hasDifferentDefaultCast] : column4.data_type
|
1947
5655
|
)) {
|
1948
|
-
const nonPrefixPart =
|
1949
|
-
const rt =
|
1950
|
-
if (/^-?[\d.]+(?:e-?\d+)?$/.test(rt) && !
|
5656
|
+
const nonPrefixPart = column4.column_default.length - (hasDifferentDefaultCast ? columnToDefault[hasDifferentDefaultCast] : `::${column4.data_type}`).length - 1;
|
5657
|
+
const rt = column4.column_default.toString().substring(1, nonPrefixPart);
|
5658
|
+
if (/^-?[\d.]+(?:e-?\d+)?$/.test(rt) && !column4.data_type.startsWith("numeric")) {
|
1951
5659
|
return Number(rt);
|
1952
|
-
} else if (
|
5660
|
+
} else if (column4.data_type === "json" || column4.data_type === "jsonb") {
|
1953
5661
|
const jsonWithoutSpaces = JSON.stringify(JSON.parse(rt));
|
1954
|
-
return `'${jsonWithoutSpaces}'${hasDifferentDefaultCast ? columnToDefault[hasDifferentDefaultCast] : `::${
|
1955
|
-
} else if (
|
1956
|
-
return
|
5662
|
+
return `'${jsonWithoutSpaces}'${hasDifferentDefaultCast ? columnToDefault[hasDifferentDefaultCast] : `::${column4.data_type}`}`;
|
5663
|
+
} else if (column4.data_type === "boolean") {
|
5664
|
+
return column4.column_default === "true";
|
1957
5665
|
} else {
|
1958
5666
|
return `'${rt}'`;
|
1959
5667
|
}
|
1960
5668
|
} else {
|
1961
|
-
if (/^-?[\d.]+(?:e-?\d+)?$/.test(columnDefaultAsString) && !
|
5669
|
+
if (/^-?[\d.]+(?:e-?\d+)?$/.test(columnDefaultAsString) && !column4.data_type.startsWith("numeric")) {
|
1962
5670
|
return Number(columnDefaultAsString);
|
1963
|
-
} else if (
|
1964
|
-
return
|
5671
|
+
} else if (column4.data_type === "boolean") {
|
5672
|
+
return column4.column_default === "true";
|
1965
5673
|
} else {
|
1966
5674
|
return `${columnDefaultAsString}`;
|
1967
5675
|
}
|
@@ -1970,10 +5678,368 @@ var init_pgSerializer = __esm({
|
|
1970
5678
|
}
|
1971
5679
|
});
|
1972
5680
|
|
5681
|
+
// node_modules/.pnpm/pluralize@8.0.0/node_modules/pluralize/pluralize.js
|
5682
|
+
var require_pluralize = __commonJS({
|
5683
|
+
"node_modules/.pnpm/pluralize@8.0.0/node_modules/pluralize/pluralize.js"(exports, module2) {
|
5684
|
+
(function(root, pluralize) {
|
5685
|
+
if (typeof require === "function" && typeof exports === "object" && typeof module2 === "object") {
|
5686
|
+
module2.exports = pluralize();
|
5687
|
+
} else if (typeof define === "function" && define.amd) {
|
5688
|
+
define(function() {
|
5689
|
+
return pluralize();
|
5690
|
+
});
|
5691
|
+
} else {
|
5692
|
+
root.pluralize = pluralize();
|
5693
|
+
}
|
5694
|
+
})(exports, function() {
|
5695
|
+
var pluralRules = [];
|
5696
|
+
var singularRules = [];
|
5697
|
+
var uncountables = {};
|
5698
|
+
var irregularPlurals = {};
|
5699
|
+
var irregularSingles = {};
|
5700
|
+
function sanitizeRule(rule) {
|
5701
|
+
if (typeof rule === "string") {
|
5702
|
+
return new RegExp("^" + rule + "$", "i");
|
5703
|
+
}
|
5704
|
+
return rule;
|
5705
|
+
}
|
5706
|
+
function restoreCase(word, token) {
|
5707
|
+
if (word === token)
|
5708
|
+
return token;
|
5709
|
+
if (word === word.toLowerCase())
|
5710
|
+
return token.toLowerCase();
|
5711
|
+
if (word === word.toUpperCase())
|
5712
|
+
return token.toUpperCase();
|
5713
|
+
if (word[0] === word[0].toUpperCase()) {
|
5714
|
+
return token.charAt(0).toUpperCase() + token.substr(1).toLowerCase();
|
5715
|
+
}
|
5716
|
+
return token.toLowerCase();
|
5717
|
+
}
|
5718
|
+
function interpolate(str, args) {
|
5719
|
+
return str.replace(/\$(\d{1,2})/g, function(match2, index4) {
|
5720
|
+
return args[index4] || "";
|
5721
|
+
});
|
5722
|
+
}
|
5723
|
+
function replace(word, rule) {
|
5724
|
+
return word.replace(rule[0], function(match2, index4) {
|
5725
|
+
var result = interpolate(rule[1], arguments);
|
5726
|
+
if (match2 === "") {
|
5727
|
+
return restoreCase(word[index4 - 1], result);
|
5728
|
+
}
|
5729
|
+
return restoreCase(match2, result);
|
5730
|
+
});
|
5731
|
+
}
|
5732
|
+
function sanitizeWord(token, word, rules) {
|
5733
|
+
if (!token.length || uncountables.hasOwnProperty(token)) {
|
5734
|
+
return word;
|
5735
|
+
}
|
5736
|
+
var len = rules.length;
|
5737
|
+
while (len--) {
|
5738
|
+
var rule = rules[len];
|
5739
|
+
if (rule[0].test(word))
|
5740
|
+
return replace(word, rule);
|
5741
|
+
}
|
5742
|
+
return word;
|
5743
|
+
}
|
5744
|
+
function replaceWord(replaceMap, keepMap, rules) {
|
5745
|
+
return function(word) {
|
5746
|
+
var token = word.toLowerCase();
|
5747
|
+
if (keepMap.hasOwnProperty(token)) {
|
5748
|
+
return restoreCase(word, token);
|
5749
|
+
}
|
5750
|
+
if (replaceMap.hasOwnProperty(token)) {
|
5751
|
+
return restoreCase(word, replaceMap[token]);
|
5752
|
+
}
|
5753
|
+
return sanitizeWord(token, word, rules);
|
5754
|
+
};
|
5755
|
+
}
|
5756
|
+
function checkWord(replaceMap, keepMap, rules, bool) {
|
5757
|
+
return function(word) {
|
5758
|
+
var token = word.toLowerCase();
|
5759
|
+
if (keepMap.hasOwnProperty(token))
|
5760
|
+
return true;
|
5761
|
+
if (replaceMap.hasOwnProperty(token))
|
5762
|
+
return false;
|
5763
|
+
return sanitizeWord(token, token, rules) === token;
|
5764
|
+
};
|
5765
|
+
}
|
5766
|
+
function pluralize(word, count, inclusive) {
|
5767
|
+
var pluralized = count === 1 ? pluralize.singular(word) : pluralize.plural(word);
|
5768
|
+
return (inclusive ? count + " " : "") + pluralized;
|
5769
|
+
}
|
5770
|
+
pluralize.plural = replaceWord(
|
5771
|
+
irregularSingles,
|
5772
|
+
irregularPlurals,
|
5773
|
+
pluralRules
|
5774
|
+
);
|
5775
|
+
pluralize.isPlural = checkWord(
|
5776
|
+
irregularSingles,
|
5777
|
+
irregularPlurals,
|
5778
|
+
pluralRules
|
5779
|
+
);
|
5780
|
+
pluralize.singular = replaceWord(
|
5781
|
+
irregularPlurals,
|
5782
|
+
irregularSingles,
|
5783
|
+
singularRules
|
5784
|
+
);
|
5785
|
+
pluralize.isSingular = checkWord(
|
5786
|
+
irregularPlurals,
|
5787
|
+
irregularSingles,
|
5788
|
+
singularRules
|
5789
|
+
);
|
5790
|
+
pluralize.addPluralRule = function(rule, replacement) {
|
5791
|
+
pluralRules.push([sanitizeRule(rule), replacement]);
|
5792
|
+
};
|
5793
|
+
pluralize.addSingularRule = function(rule, replacement) {
|
5794
|
+
singularRules.push([sanitizeRule(rule), replacement]);
|
5795
|
+
};
|
5796
|
+
pluralize.addUncountableRule = function(word) {
|
5797
|
+
if (typeof word === "string") {
|
5798
|
+
uncountables[word.toLowerCase()] = true;
|
5799
|
+
return;
|
5800
|
+
}
|
5801
|
+
pluralize.addPluralRule(word, "$0");
|
5802
|
+
pluralize.addSingularRule(word, "$0");
|
5803
|
+
};
|
5804
|
+
pluralize.addIrregularRule = function(single, plural2) {
|
5805
|
+
plural2 = plural2.toLowerCase();
|
5806
|
+
single = single.toLowerCase();
|
5807
|
+
irregularSingles[single] = plural2;
|
5808
|
+
irregularPlurals[plural2] = single;
|
5809
|
+
};
|
5810
|
+
[
|
5811
|
+
// Pronouns.
|
5812
|
+
["I", "we"],
|
5813
|
+
["me", "us"],
|
5814
|
+
["he", "they"],
|
5815
|
+
["she", "they"],
|
5816
|
+
["them", "them"],
|
5817
|
+
["myself", "ourselves"],
|
5818
|
+
["yourself", "yourselves"],
|
5819
|
+
["itself", "themselves"],
|
5820
|
+
["herself", "themselves"],
|
5821
|
+
["himself", "themselves"],
|
5822
|
+
["themself", "themselves"],
|
5823
|
+
["is", "are"],
|
5824
|
+
["was", "were"],
|
5825
|
+
["has", "have"],
|
5826
|
+
["this", "these"],
|
5827
|
+
["that", "those"],
|
5828
|
+
// Words ending in with a consonant and `o`.
|
5829
|
+
["echo", "echoes"],
|
5830
|
+
["dingo", "dingoes"],
|
5831
|
+
["volcano", "volcanoes"],
|
5832
|
+
["tornado", "tornadoes"],
|
5833
|
+
["torpedo", "torpedoes"],
|
5834
|
+
// Ends with `us`.
|
5835
|
+
["genus", "genera"],
|
5836
|
+
["viscus", "viscera"],
|
5837
|
+
// Ends with `ma`.
|
5838
|
+
["stigma", "stigmata"],
|
5839
|
+
["stoma", "stomata"],
|
5840
|
+
["dogma", "dogmata"],
|
5841
|
+
["lemma", "lemmata"],
|
5842
|
+
["schema", "schemata"],
|
5843
|
+
["anathema", "anathemata"],
|
5844
|
+
// Other irregular rules.
|
5845
|
+
["ox", "oxen"],
|
5846
|
+
["axe", "axes"],
|
5847
|
+
["die", "dice"],
|
5848
|
+
["yes", "yeses"],
|
5849
|
+
["foot", "feet"],
|
5850
|
+
["eave", "eaves"],
|
5851
|
+
["goose", "geese"],
|
5852
|
+
["tooth", "teeth"],
|
5853
|
+
["quiz", "quizzes"],
|
5854
|
+
["human", "humans"],
|
5855
|
+
["proof", "proofs"],
|
5856
|
+
["carve", "carves"],
|
5857
|
+
["valve", "valves"],
|
5858
|
+
["looey", "looies"],
|
5859
|
+
["thief", "thieves"],
|
5860
|
+
["groove", "grooves"],
|
5861
|
+
["pickaxe", "pickaxes"],
|
5862
|
+
["passerby", "passersby"]
|
5863
|
+
].forEach(function(rule) {
|
5864
|
+
return pluralize.addIrregularRule(rule[0], rule[1]);
|
5865
|
+
});
|
5866
|
+
[
|
5867
|
+
[/s?$/i, "s"],
|
5868
|
+
[/[^\u0000-\u007F]$/i, "$0"],
|
5869
|
+
[/([^aeiou]ese)$/i, "$1"],
|
5870
|
+
[/(ax|test)is$/i, "$1es"],
|
5871
|
+
[/(alias|[^aou]us|t[lm]as|gas|ris)$/i, "$1es"],
|
5872
|
+
[/(e[mn]u)s?$/i, "$1s"],
|
5873
|
+
[/([^l]ias|[aeiou]las|[ejzr]as|[iu]am)$/i, "$1"],
|
5874
|
+
[/(alumn|syllab|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/i, "$1i"],
|
5875
|
+
[/(alumn|alg|vertebr)(?:a|ae)$/i, "$1ae"],
|
5876
|
+
[/(seraph|cherub)(?:im)?$/i, "$1im"],
|
5877
|
+
[/(her|at|gr)o$/i, "$1oes"],
|
5878
|
+
[/(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|automat|quor)(?:a|um)$/i, "$1a"],
|
5879
|
+
[/(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)(?:a|on)$/i, "$1a"],
|
5880
|
+
[/sis$/i, "ses"],
|
5881
|
+
[/(?:(kni|wi|li)fe|(ar|l|ea|eo|oa|hoo)f)$/i, "$1$2ves"],
|
5882
|
+
[/([^aeiouy]|qu)y$/i, "$1ies"],
|
5883
|
+
[/([^ch][ieo][ln])ey$/i, "$1ies"],
|
5884
|
+
[/(x|ch|ss|sh|zz)$/i, "$1es"],
|
5885
|
+
[/(matr|cod|mur|sil|vert|ind|append)(?:ix|ex)$/i, "$1ices"],
|
5886
|
+
[/\b((?:tit)?m|l)(?:ice|ouse)$/i, "$1ice"],
|
5887
|
+
[/(pe)(?:rson|ople)$/i, "$1ople"],
|
5888
|
+
[/(child)(?:ren)?$/i, "$1ren"],
|
5889
|
+
[/eaux$/i, "$0"],
|
5890
|
+
[/m[ae]n$/i, "men"],
|
5891
|
+
["thou", "you"]
|
5892
|
+
].forEach(function(rule) {
|
5893
|
+
return pluralize.addPluralRule(rule[0], rule[1]);
|
5894
|
+
});
|
5895
|
+
[
|
5896
|
+
[/s$/i, ""],
|
5897
|
+
[/(ss)$/i, "$1"],
|
5898
|
+
[/(wi|kni|(?:after|half|high|low|mid|non|night|[^\w]|^)li)ves$/i, "$1fe"],
|
5899
|
+
[/(ar|(?:wo|[ae])l|[eo][ao])ves$/i, "$1f"],
|
5900
|
+
[/ies$/i, "y"],
|
5901
|
+
[/\b([pl]|zomb|(?:neck|cross)?t|coll|faer|food|gen|goon|group|lass|talk|goal|cut)ies$/i, "$1ie"],
|
5902
|
+
[/\b(mon|smil)ies$/i, "$1ey"],
|
5903
|
+
[/\b((?:tit)?m|l)ice$/i, "$1ouse"],
|
5904
|
+
[/(seraph|cherub)im$/i, "$1"],
|
5905
|
+
[/(x|ch|ss|sh|zz|tto|go|cho|alias|[^aou]us|t[lm]as|gas|(?:her|at|gr)o|[aeiou]ris)(?:es)?$/i, "$1"],
|
5906
|
+
[/(analy|diagno|parenthe|progno|synop|the|empha|cri|ne)(?:sis|ses)$/i, "$1sis"],
|
5907
|
+
[/(movie|twelve|abuse|e[mn]u)s$/i, "$1"],
|
5908
|
+
[/(test)(?:is|es)$/i, "$1is"],
|
5909
|
+
[/(alumn|syllab|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/i, "$1us"],
|
5910
|
+
[/(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|quor)a$/i, "$1um"],
|
5911
|
+
[/(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)a$/i, "$1on"],
|
5912
|
+
[/(alumn|alg|vertebr)ae$/i, "$1a"],
|
5913
|
+
[/(cod|mur|sil|vert|ind)ices$/i, "$1ex"],
|
5914
|
+
[/(matr|append)ices$/i, "$1ix"],
|
5915
|
+
[/(pe)(rson|ople)$/i, "$1rson"],
|
5916
|
+
[/(child)ren$/i, "$1"],
|
5917
|
+
[/(eau)x?$/i, "$1"],
|
5918
|
+
[/men$/i, "man"]
|
5919
|
+
].forEach(function(rule) {
|
5920
|
+
return pluralize.addSingularRule(rule[0], rule[1]);
|
5921
|
+
});
|
5922
|
+
[
|
5923
|
+
// Singular words with no plurals.
|
5924
|
+
"adulthood",
|
5925
|
+
"advice",
|
5926
|
+
"agenda",
|
5927
|
+
"aid",
|
5928
|
+
"aircraft",
|
5929
|
+
"alcohol",
|
5930
|
+
"ammo",
|
5931
|
+
"analytics",
|
5932
|
+
"anime",
|
5933
|
+
"athletics",
|
5934
|
+
"audio",
|
5935
|
+
"bison",
|
5936
|
+
"blood",
|
5937
|
+
"bream",
|
5938
|
+
"buffalo",
|
5939
|
+
"butter",
|
5940
|
+
"carp",
|
5941
|
+
"cash",
|
5942
|
+
"chassis",
|
5943
|
+
"chess",
|
5944
|
+
"clothing",
|
5945
|
+
"cod",
|
5946
|
+
"commerce",
|
5947
|
+
"cooperation",
|
5948
|
+
"corps",
|
5949
|
+
"debris",
|
5950
|
+
"diabetes",
|
5951
|
+
"digestion",
|
5952
|
+
"elk",
|
5953
|
+
"energy",
|
5954
|
+
"equipment",
|
5955
|
+
"excretion",
|
5956
|
+
"expertise",
|
5957
|
+
"firmware",
|
5958
|
+
"flounder",
|
5959
|
+
"fun",
|
5960
|
+
"gallows",
|
5961
|
+
"garbage",
|
5962
|
+
"graffiti",
|
5963
|
+
"hardware",
|
5964
|
+
"headquarters",
|
5965
|
+
"health",
|
5966
|
+
"herpes",
|
5967
|
+
"highjinks",
|
5968
|
+
"homework",
|
5969
|
+
"housework",
|
5970
|
+
"information",
|
5971
|
+
"jeans",
|
5972
|
+
"justice",
|
5973
|
+
"kudos",
|
5974
|
+
"labour",
|
5975
|
+
"literature",
|
5976
|
+
"machinery",
|
5977
|
+
"mackerel",
|
5978
|
+
"mail",
|
5979
|
+
"media",
|
5980
|
+
"mews",
|
5981
|
+
"moose",
|
5982
|
+
"music",
|
5983
|
+
"mud",
|
5984
|
+
"manga",
|
5985
|
+
"news",
|
5986
|
+
"only",
|
5987
|
+
"personnel",
|
5988
|
+
"pike",
|
5989
|
+
"plankton",
|
5990
|
+
"pliers",
|
5991
|
+
"police",
|
5992
|
+
"pollution",
|
5993
|
+
"premises",
|
5994
|
+
"rain",
|
5995
|
+
"research",
|
5996
|
+
"rice",
|
5997
|
+
"salmon",
|
5998
|
+
"scissors",
|
5999
|
+
"series",
|
6000
|
+
"sewage",
|
6001
|
+
"shambles",
|
6002
|
+
"shrimp",
|
6003
|
+
"software",
|
6004
|
+
"species",
|
6005
|
+
"staff",
|
6006
|
+
"swine",
|
6007
|
+
"tennis",
|
6008
|
+
"traffic",
|
6009
|
+
"transportation",
|
6010
|
+
"trout",
|
6011
|
+
"tuna",
|
6012
|
+
"wealth",
|
6013
|
+
"welfare",
|
6014
|
+
"whiting",
|
6015
|
+
"wildebeest",
|
6016
|
+
"wildlife",
|
6017
|
+
"you",
|
6018
|
+
/pok[eé]mon$/i,
|
6019
|
+
// Regexes.
|
6020
|
+
/[^aeiou]ese$/i,
|
6021
|
+
// "chinese", "japanese"
|
6022
|
+
/deer$/i,
|
6023
|
+
// "deer", "reindeer"
|
6024
|
+
/fish$/i,
|
6025
|
+
// "fish", "blowfish", "angelfish"
|
6026
|
+
/measles$/i,
|
6027
|
+
/o[iu]s$/i,
|
6028
|
+
// "carnivorous"
|
6029
|
+
/pox$/i,
|
6030
|
+
// "chickpox", "smallpox"
|
6031
|
+
/sheep$/i
|
6032
|
+
].forEach(pluralize.addUncountableRule);
|
6033
|
+
return pluralize;
|
6034
|
+
});
|
6035
|
+
}
|
6036
|
+
});
|
6037
|
+
|
1973
6038
|
// src/drivers/index.ts
|
1974
6039
|
var import_drizzle_orm4, DrizzleDbClient, DrizzleORMPgClient, TursoSqlite;
|
1975
6040
|
var init_drivers = __esm({
|
1976
6041
|
"src/drivers/index.ts"() {
|
6042
|
+
"use strict";
|
1977
6043
|
import_drizzle_orm4 = require("drizzle-orm");
|
1978
6044
|
DrizzleDbClient = class {
|
1979
6045
|
constructor(db) {
|
@@ -2017,9 +6083,9 @@ module.exports = __toCommonJS(utils_studio_exports);
|
|
2017
6083
|
// src/serializer/schemaToDrizzle.ts
|
2018
6084
|
var import_pg_core = require("drizzle-orm/pg-core");
|
2019
6085
|
var import_sqlite_core = require("drizzle-orm/sqlite-core");
|
2020
|
-
var pgSchemaToDrizzle = (
|
6086
|
+
var pgSchemaToDrizzle = (schema3, schemaName) => {
|
2021
6087
|
const tables = {};
|
2022
|
-
Object.values(
|
6088
|
+
Object.values(schema3.tables).forEach((t) => {
|
2023
6089
|
const columns = {};
|
2024
6090
|
Object.values(t.columns).forEach((c) => {
|
2025
6091
|
const columnName = c.name;
|
@@ -2119,9 +6185,9 @@ var pgSchemaToDrizzle = (schema, schemaName) => {
|
|
2119
6185
|
});
|
2120
6186
|
return tables;
|
2121
6187
|
};
|
2122
|
-
var sqliteSchemaToDrizzle = (
|
6188
|
+
var sqliteSchemaToDrizzle = (schema3) => {
|
2123
6189
|
const tables = {};
|
2124
|
-
Object.values(
|
6190
|
+
Object.values(schema3.tables).forEach((t) => {
|
2125
6191
|
const columns = {};
|
2126
6192
|
Object.values(t.columns).forEach((c) => {
|
2127
6193
|
const columnName = c.name;
|
@@ -2166,11 +6232,7 @@ var sqliteSchemaToDrizzle = (schema) => {
|
|
2166
6232
|
|
2167
6233
|
// src/cli/commands/sqliteIntrospect.ts
|
2168
6234
|
init_views();
|
2169
|
-
|
2170
|
-
// src/global.ts
|
2171
|
-
var originUUID = "00000000-0000-0000-0000-000000000000";
|
2172
|
-
|
2173
|
-
// src/cli/commands/sqliteIntrospect.ts
|
6235
|
+
init_global();
|
2174
6236
|
init_sqliteSerializer();
|
2175
6237
|
|
2176
6238
|
// node_modules/.pnpm/camelcase@7.0.1/node_modules/camelcase/index.js
|
@@ -2187,17 +6249,17 @@ var preserveCamelCase = (string, toLowerCase, toUpperCase, preserveConsecutiveUp
|
|
2187
6249
|
let isLastCharUpper = false;
|
2188
6250
|
let isLastLastCharUpper = false;
|
2189
6251
|
let isLastLastCharPreserved = false;
|
2190
|
-
for (let
|
2191
|
-
const character = string[
|
2192
|
-
isLastLastCharPreserved =
|
6252
|
+
for (let index4 = 0; index4 < string.length; index4++) {
|
6253
|
+
const character = string[index4];
|
6254
|
+
isLastLastCharPreserved = index4 > 2 ? string[index4 - 3] === "-" : true;
|
2193
6255
|
if (isLastCharLower && UPPERCASE.test(character)) {
|
2194
|
-
string = string.slice(0,
|
6256
|
+
string = string.slice(0, index4) + "-" + string.slice(index4);
|
2195
6257
|
isLastCharLower = false;
|
2196
6258
|
isLastLastCharUpper = isLastCharUpper;
|
2197
6259
|
isLastCharUpper = true;
|
2198
|
-
|
6260
|
+
index4++;
|
2199
6261
|
} else if (isLastCharUpper && isLastLastCharUpper && LOWERCASE.test(character) && (!isLastLastCharPreserved || preserveConsecutiveUppercase2)) {
|
2200
|
-
string = string.slice(0,
|
6262
|
+
string = string.slice(0, index4 - 1) + "-" + string.slice(index4 - 1);
|
2201
6263
|
isLastLastCharUpper = isLastCharUpper;
|
2202
6264
|
isLastCharUpper = false;
|
2203
6265
|
isLastCharLower = true;
|
@@ -2272,7 +6334,7 @@ String.prototype.camelCase = function() {
|
|
2272
6334
|
return camelCase(String(this));
|
2273
6335
|
};
|
2274
6336
|
String.prototype.concatIf = function(it, condition) {
|
2275
|
-
return condition ? `${this}${it}` : this;
|
6337
|
+
return condition ? `${this}${it}` : String(this);
|
2276
6338
|
};
|
2277
6339
|
Array.prototype.random = function() {
|
2278
6340
|
return this[~~(Math.random() * this.length)];
|
@@ -3341,8 +7403,8 @@ var sqlitePushIntrospect = async (client, filters) => {
|
|
3341
7403
|
return false;
|
3342
7404
|
};
|
3343
7405
|
const res = await fromDatabase(client, filter2);
|
3344
|
-
const
|
3345
|
-
return { schema };
|
7406
|
+
const schema3 = { id: originUUID, prevId: "", ...res };
|
7407
|
+
return { schema: schema3 };
|
3346
7408
|
};
|
3347
7409
|
|
3348
7410
|
// src/cli/commands/pgIntrospect.ts
|
@@ -3352,10 +7414,12 @@ init_pgSerializer();
|
|
3352
7414
|
|
3353
7415
|
// src/introspect-pg.ts
|
3354
7416
|
var import_drizzle_orm3 = require("drizzle-orm");
|
7417
|
+
var import_pluralize = __toESM(require_pluralize());
|
3355
7418
|
var import_relations = require("drizzle-orm/relations");
|
3356
7419
|
init_pgSerializer();
|
3357
7420
|
|
3358
7421
|
// src/cli/commands/pgIntrospect.ts
|
7422
|
+
init_global();
|
3359
7423
|
var pgPushIntrospect = async (connection, filters, schemaFilters) => {
|
3360
7424
|
const { client } = connection;
|
3361
7425
|
const matchers = filters.map((it) => {
|
@@ -3372,8 +7436,8 @@ var pgPushIntrospect = async (connection, filters, schemaFilters) => {
|
|
3372
7436
|
return false;
|
3373
7437
|
};
|
3374
7438
|
const res = await fromDatabase2(client, filter2, schemaFilters);
|
3375
|
-
const
|
3376
|
-
const { internal, ...schemaWithoutInternals } =
|
7439
|
+
const schema3 = { id: originUUID, prevId: "", ...res };
|
7440
|
+
const { internal, ...schemaWithoutInternals } = schema3;
|
3377
7441
|
return { schema: schemaWithoutInternals };
|
3378
7442
|
};
|
3379
7443
|
|