@wecode-team/cms-supabase-api 0.1.29 → 0.1.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/handlers/analytics.d.ts +11 -0
- package/dist/index.esm.js +468 -399
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +468 -399
- package/dist/index.js.map +1 -1
- package/dist/services/dynamic-table.service.d.ts +5 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1053,7 +1053,72 @@ var DynamicTableService = /*#__PURE__*/function () {
|
|
|
1053
1053
|
_classCallCheck(this, DynamicTableService);
|
|
1054
1054
|
this.supabase = getSupabase();
|
|
1055
1055
|
}
|
|
1056
|
+
/**
|
|
1057
|
+
* 默认按 created_at 倒序(新数据在前)。
|
|
1058
|
+
* 兼容:如果表不存在 created_at 字段,则回退按 id 倒序。
|
|
1059
|
+
*/
|
|
1056
1060
|
return _createClass(DynamicTableService, [{
|
|
1061
|
+
key: "orderByCreatedAtOrFallback",
|
|
1062
|
+
value: (function () {
|
|
1063
|
+
var _orderByCreatedAtOrFallback = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(buildQuery, offset, limit) {
|
|
1064
|
+
var _first$error;
|
|
1065
|
+
var first, msg, isMissingCreatedAt, second;
|
|
1066
|
+
return _regeneratorRuntime.wrap(function (_context) {
|
|
1067
|
+
while (1) switch (_context.prev = _context.next) {
|
|
1068
|
+
case 0:
|
|
1069
|
+
_context.next = 1;
|
|
1070
|
+
return buildQuery().order("created_at", {
|
|
1071
|
+
ascending: false
|
|
1072
|
+
}).order("id", {
|
|
1073
|
+
ascending: false
|
|
1074
|
+
}).range(offset, offset + limit - 1);
|
|
1075
|
+
case 1:
|
|
1076
|
+
first = _context.sent;
|
|
1077
|
+
if (first.error) {
|
|
1078
|
+
_context.next = 2;
|
|
1079
|
+
break;
|
|
1080
|
+
}
|
|
1081
|
+
return _context.abrupt("return", {
|
|
1082
|
+
data: first.data || [],
|
|
1083
|
+
count: first.count || 0
|
|
1084
|
+
});
|
|
1085
|
+
case 2:
|
|
1086
|
+
msg = String(((_first$error = first.error) === null || _first$error === void 0 ? void 0 : _first$error.message) || "");
|
|
1087
|
+
isMissingCreatedAt = msg.includes("created_at") || msg.toLowerCase().includes("column") || msg.toLowerCase().includes("does not exist");
|
|
1088
|
+
if (isMissingCreatedAt) {
|
|
1089
|
+
_context.next = 3;
|
|
1090
|
+
break;
|
|
1091
|
+
}
|
|
1092
|
+
throw first.error;
|
|
1093
|
+
case 3:
|
|
1094
|
+
_context.next = 4;
|
|
1095
|
+
return buildQuery().order("id", {
|
|
1096
|
+
ascending: false
|
|
1097
|
+
}).range(offset, offset + limit - 1);
|
|
1098
|
+
case 4:
|
|
1099
|
+
second = _context.sent;
|
|
1100
|
+
if (!second.error) {
|
|
1101
|
+
_context.next = 5;
|
|
1102
|
+
break;
|
|
1103
|
+
}
|
|
1104
|
+
throw second.error;
|
|
1105
|
+
case 5:
|
|
1106
|
+
return _context.abrupt("return", {
|
|
1107
|
+
data: second.data || [],
|
|
1108
|
+
count: second.count || 0
|
|
1109
|
+
});
|
|
1110
|
+
case 6:
|
|
1111
|
+
case "end":
|
|
1112
|
+
return _context.stop();
|
|
1113
|
+
}
|
|
1114
|
+
}, _callee);
|
|
1115
|
+
}));
|
|
1116
|
+
function orderByCreatedAtOrFallback(_x, _x2, _x3) {
|
|
1117
|
+
return _orderByCreatedAtOrFallback.apply(this, arguments);
|
|
1118
|
+
}
|
|
1119
|
+
return orderByCreatedAtOrFallback;
|
|
1120
|
+
}())
|
|
1121
|
+
}, {
|
|
1057
1122
|
key: "applySupabaseFilters",
|
|
1058
1123
|
value: function applySupabaseFilters(query, filters) {
|
|
1059
1124
|
if (!filters || filters.length === 0) return query;
|
|
@@ -1129,12 +1194,12 @@ var DynamicTableService = /*#__PURE__*/function () {
|
|
|
1129
1194
|
}, {
|
|
1130
1195
|
key: "createTable",
|
|
1131
1196
|
value: (function () {
|
|
1132
|
-
var _createTable = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function
|
|
1197
|
+
var _createTable = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(tableName, schema, baseTableName) {
|
|
1133
1198
|
var tablePrefix, createTableSQL, foreignKeys, _yield$this$supabase$, error, _t;
|
|
1134
|
-
return _regeneratorRuntime.wrap(function (
|
|
1135
|
-
while (1) switch (
|
|
1199
|
+
return _regeneratorRuntime.wrap(function (_context2) {
|
|
1200
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
1136
1201
|
case 0:
|
|
1137
|
-
|
|
1202
|
+
_context2.prev = 0;
|
|
1138
1203
|
// 计算表名前缀(用于关联表)
|
|
1139
1204
|
tablePrefix = baseTableName ? this.extractTablePrefix(tableName, baseTableName) : ""; // 构建CREATE TABLE SQL语句
|
|
1140
1205
|
createTableSQL = "CREATE TABLE IF NOT EXISTS \"".concat(tableName, "\" (\n");
|
|
@@ -1187,33 +1252,33 @@ var DynamicTableService = /*#__PURE__*/function () {
|
|
|
1187
1252
|
}
|
|
1188
1253
|
createTableSQL += "\n);";
|
|
1189
1254
|
// 执行创建表的SQL
|
|
1190
|
-
|
|
1255
|
+
_context2.next = 1;
|
|
1191
1256
|
return this.supabase.rpc("execute_sql", {
|
|
1192
1257
|
sql_query: createTableSQL
|
|
1193
1258
|
});
|
|
1194
1259
|
case 1:
|
|
1195
|
-
_yield$this$supabase$ =
|
|
1260
|
+
_yield$this$supabase$ = _context2.sent;
|
|
1196
1261
|
error = _yield$this$supabase$.error;
|
|
1197
1262
|
if (!error) {
|
|
1198
|
-
|
|
1263
|
+
_context2.next = 2;
|
|
1199
1264
|
break;
|
|
1200
1265
|
}
|
|
1201
1266
|
throw error;
|
|
1202
1267
|
case 2:
|
|
1203
1268
|
console.log("\u8868 ".concat(tableName, " \u521B\u5EFA\u6210\u529F"));
|
|
1204
|
-
return
|
|
1269
|
+
return _context2.abrupt("return", true);
|
|
1205
1270
|
case 3:
|
|
1206
|
-
|
|
1207
|
-
_t =
|
|
1271
|
+
_context2.prev = 3;
|
|
1272
|
+
_t = _context2["catch"](0);
|
|
1208
1273
|
console.error("\u521B\u5EFA\u8868 ".concat(tableName, " \u5931\u8D25:"), _t);
|
|
1209
|
-
return
|
|
1274
|
+
return _context2.abrupt("return", false);
|
|
1210
1275
|
case 4:
|
|
1211
1276
|
case "end":
|
|
1212
|
-
return
|
|
1277
|
+
return _context2.stop();
|
|
1213
1278
|
}
|
|
1214
|
-
},
|
|
1279
|
+
}, _callee2, this, [[0, 3]]);
|
|
1215
1280
|
}));
|
|
1216
|
-
function createTable(
|
|
1281
|
+
function createTable(_x4, _x5, _x6) {
|
|
1217
1282
|
return _createTable.apply(this, arguments);
|
|
1218
1283
|
}
|
|
1219
1284
|
return createTable;
|
|
@@ -1225,39 +1290,39 @@ var DynamicTableService = /*#__PURE__*/function () {
|
|
|
1225
1290
|
}, {
|
|
1226
1291
|
key: "dropTable",
|
|
1227
1292
|
value: (function () {
|
|
1228
|
-
var _dropTable = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function
|
|
1293
|
+
var _dropTable = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(tableName) {
|
|
1229
1294
|
var _yield$this$supabase$2, error, _t2;
|
|
1230
|
-
return _regeneratorRuntime.wrap(function (
|
|
1231
|
-
while (1) switch (
|
|
1295
|
+
return _regeneratorRuntime.wrap(function (_context3) {
|
|
1296
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
1232
1297
|
case 0:
|
|
1233
|
-
|
|
1234
|
-
|
|
1298
|
+
_context3.prev = 0;
|
|
1299
|
+
_context3.next = 1;
|
|
1235
1300
|
return this.supabase.rpc("execute_sql", {
|
|
1236
1301
|
sql_query: "DROP TABLE IF EXISTS \"".concat(tableName, "\";")
|
|
1237
1302
|
});
|
|
1238
1303
|
case 1:
|
|
1239
|
-
_yield$this$supabase$2 =
|
|
1304
|
+
_yield$this$supabase$2 = _context3.sent;
|
|
1240
1305
|
error = _yield$this$supabase$2.error;
|
|
1241
1306
|
if (!error) {
|
|
1242
|
-
|
|
1307
|
+
_context3.next = 2;
|
|
1243
1308
|
break;
|
|
1244
1309
|
}
|
|
1245
1310
|
throw error;
|
|
1246
1311
|
case 2:
|
|
1247
1312
|
console.log("\u8868 ".concat(tableName, " \u5220\u9664\u6210\u529F"));
|
|
1248
|
-
return
|
|
1313
|
+
return _context3.abrupt("return", true);
|
|
1249
1314
|
case 3:
|
|
1250
|
-
|
|
1251
|
-
_t2 =
|
|
1315
|
+
_context3.prev = 3;
|
|
1316
|
+
_t2 = _context3["catch"](0);
|
|
1252
1317
|
console.error("\u5220\u9664\u8868 ".concat(tableName, " \u5931\u8D25:"), _t2);
|
|
1253
|
-
return
|
|
1318
|
+
return _context3.abrupt("return", false);
|
|
1254
1319
|
case 4:
|
|
1255
1320
|
case "end":
|
|
1256
|
-
return
|
|
1321
|
+
return _context3.stop();
|
|
1257
1322
|
}
|
|
1258
|
-
},
|
|
1323
|
+
}, _callee3, this, [[0, 3]]);
|
|
1259
1324
|
}));
|
|
1260
|
-
function dropTable(
|
|
1325
|
+
function dropTable(_x7) {
|
|
1261
1326
|
return _dropTable.apply(this, arguments);
|
|
1262
1327
|
}
|
|
1263
1328
|
return dropTable;
|
|
@@ -1270,12 +1335,12 @@ var DynamicTableService = /*#__PURE__*/function () {
|
|
|
1270
1335
|
}, {
|
|
1271
1336
|
key: "dropAllForeignKeys",
|
|
1272
1337
|
value: (function () {
|
|
1273
|
-
var _dropAllForeignKeys = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function
|
|
1338
|
+
var _dropAllForeignKeys = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(tableName) {
|
|
1274
1339
|
var parts, baseTableName, dropFKSQL, _yield$this$supabase$3, error, _t3;
|
|
1275
|
-
return _regeneratorRuntime.wrap(function (
|
|
1276
|
-
while (1) switch (
|
|
1340
|
+
return _regeneratorRuntime.wrap(function (_context4) {
|
|
1341
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
1277
1342
|
case 0:
|
|
1278
|
-
|
|
1343
|
+
_context4.prev = 0;
|
|
1279
1344
|
// 获取可能的基础表名(去掉前缀)
|
|
1280
1345
|
// 例如:jjj231122a342_posts -> posts
|
|
1281
1346
|
parts = tableName.split('_');
|
|
@@ -1283,34 +1348,34 @@ var DynamicTableService = /*#__PURE__*/function () {
|
|
|
1283
1348
|
dropFKSQL = "\n DO $$\n DECLARE\n r RECORD;\n BEGIN\n -- \u5C1D\u8BD5\u5339\u914D\u5B8C\u6574\u8868\u540D\n FOR r IN (\n SELECT tc.constraint_name\n FROM information_schema.table_constraints tc\n WHERE tc.table_name = '".concat(tableName, "'\n AND tc.constraint_type = 'FOREIGN KEY'\n )\n LOOP\n EXECUTE 'ALTER TABLE \"").concat(tableName, "\" DROP CONSTRAINT IF EXISTS \"' || r.constraint_name || '\"';\n RAISE NOTICE 'Dropped constraint: %', r.constraint_name;\n END LOOP;\n \n -- \u5C1D\u8BD5\u5339\u914D\u57FA\u7840\u8868\u540D\u7684\u7EA6\u675F\uFF08\u7EA6\u675F\u540D\u53EF\u80FD\u4E0D\u5305\u542B\u524D\u7F00\uFF09\n FOR r IN (\n SELECT tc.constraint_name\n FROM information_schema.table_constraints tc\n WHERE tc.table_name = '").concat(tableName, "'\n AND tc.constraint_type = 'FOREIGN KEY'\n AND tc.constraint_name LIKE '").concat(baseTableName, "%'\n )\n LOOP\n EXECUTE 'ALTER TABLE \"").concat(tableName, "\" DROP CONSTRAINT IF EXISTS \"' || r.constraint_name || '\"';\n RAISE NOTICE 'Dropped constraint (base match): %', r.constraint_name;\n END LOOP;\n END $$;\n ");
|
|
1284
1349
|
console.log("\u5C1D\u8BD5\u5220\u9664\u8868 ".concat(tableName, " \u7684\u5916\u952E\u7EA6\u675F..."));
|
|
1285
1350
|
console.log("\u57FA\u7840\u8868\u540D: ".concat(baseTableName));
|
|
1286
|
-
|
|
1351
|
+
_context4.next = 1;
|
|
1287
1352
|
return this.supabase.rpc("execute_sql", {
|
|
1288
1353
|
sql_query: dropFKSQL
|
|
1289
1354
|
});
|
|
1290
1355
|
case 1:
|
|
1291
|
-
_yield$this$supabase$3 =
|
|
1356
|
+
_yield$this$supabase$3 = _context4.sent;
|
|
1292
1357
|
error = _yield$this$supabase$3.error;
|
|
1293
1358
|
if (!error) {
|
|
1294
|
-
|
|
1359
|
+
_context4.next = 2;
|
|
1295
1360
|
break;
|
|
1296
1361
|
}
|
|
1297
1362
|
console.error("execute_sql \u9519\u8BEF:", error);
|
|
1298
1363
|
throw error;
|
|
1299
1364
|
case 2:
|
|
1300
1365
|
console.log("\u8868 ".concat(tableName, " \u7684\u5916\u952E\u7EA6\u675F\u5220\u9664\u64CD\u4F5C\u5DF2\u6267\u884C"));
|
|
1301
|
-
return
|
|
1366
|
+
return _context4.abrupt("return", true);
|
|
1302
1367
|
case 3:
|
|
1303
|
-
|
|
1304
|
-
_t3 =
|
|
1368
|
+
_context4.prev = 3;
|
|
1369
|
+
_t3 = _context4["catch"](0);
|
|
1305
1370
|
console.error("\u5220\u9664\u8868 ".concat(tableName, " \u5916\u952E\u7EA6\u675F\u5931\u8D25:"), _t3);
|
|
1306
|
-
return
|
|
1371
|
+
return _context4.abrupt("return", false);
|
|
1307
1372
|
case 4:
|
|
1308
1373
|
case "end":
|
|
1309
|
-
return
|
|
1374
|
+
return _context4.stop();
|
|
1310
1375
|
}
|
|
1311
|
-
},
|
|
1376
|
+
}, _callee4, this, [[0, 3]]);
|
|
1312
1377
|
}));
|
|
1313
|
-
function dropAllForeignKeys(
|
|
1378
|
+
function dropAllForeignKeys(_x8) {
|
|
1314
1379
|
return _dropAllForeignKeys.apply(this, arguments);
|
|
1315
1380
|
}
|
|
1316
1381
|
return dropAllForeignKeys;
|
|
@@ -1322,41 +1387,41 @@ var DynamicTableService = /*#__PURE__*/function () {
|
|
|
1322
1387
|
}, {
|
|
1323
1388
|
key: "dropForeignKeyByName",
|
|
1324
1389
|
value: (function () {
|
|
1325
|
-
var _dropForeignKeyByName = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function
|
|
1390
|
+
var _dropForeignKeyByName = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5(tableName, constraintName) {
|
|
1326
1391
|
var dropSQL, _yield$this$supabase$4, error, _t4;
|
|
1327
|
-
return _regeneratorRuntime.wrap(function (
|
|
1328
|
-
while (1) switch (
|
|
1392
|
+
return _regeneratorRuntime.wrap(function (_context5) {
|
|
1393
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
1329
1394
|
case 0:
|
|
1330
|
-
|
|
1395
|
+
_context5.prev = 0;
|
|
1331
1396
|
dropSQL = "ALTER TABLE \"".concat(tableName, "\" DROP CONSTRAINT IF EXISTS \"").concat(constraintName, "\";");
|
|
1332
1397
|
console.log("\u5220\u9664\u7EA6\u675F: ".concat(constraintName, " from ").concat(tableName));
|
|
1333
|
-
|
|
1398
|
+
_context5.next = 1;
|
|
1334
1399
|
return this.supabase.rpc("execute_sql", {
|
|
1335
1400
|
sql_query: dropSQL
|
|
1336
1401
|
});
|
|
1337
1402
|
case 1:
|
|
1338
|
-
_yield$this$supabase$4 =
|
|
1403
|
+
_yield$this$supabase$4 = _context5.sent;
|
|
1339
1404
|
error = _yield$this$supabase$4.error;
|
|
1340
1405
|
if (!error) {
|
|
1341
|
-
|
|
1406
|
+
_context5.next = 2;
|
|
1342
1407
|
break;
|
|
1343
1408
|
}
|
|
1344
1409
|
throw error;
|
|
1345
1410
|
case 2:
|
|
1346
1411
|
console.log("\u5916\u952E\u7EA6\u675F ".concat(constraintName, " \u5DF2\u5220\u9664"));
|
|
1347
|
-
return
|
|
1412
|
+
return _context5.abrupt("return", true);
|
|
1348
1413
|
case 3:
|
|
1349
|
-
|
|
1350
|
-
_t4 =
|
|
1414
|
+
_context5.prev = 3;
|
|
1415
|
+
_t4 = _context5["catch"](0);
|
|
1351
1416
|
console.error("\u5220\u9664\u5916\u952E\u7EA6\u675F ".concat(constraintName, " \u5931\u8D25:"), _t4);
|
|
1352
|
-
return
|
|
1417
|
+
return _context5.abrupt("return", false);
|
|
1353
1418
|
case 4:
|
|
1354
1419
|
case "end":
|
|
1355
|
-
return
|
|
1420
|
+
return _context5.stop();
|
|
1356
1421
|
}
|
|
1357
|
-
},
|
|
1422
|
+
}, _callee5, this, [[0, 3]]);
|
|
1358
1423
|
}));
|
|
1359
|
-
function dropForeignKeyByName(
|
|
1424
|
+
function dropForeignKeyByName(_x9, _x0) {
|
|
1360
1425
|
return _dropForeignKeyByName.apply(this, arguments);
|
|
1361
1426
|
}
|
|
1362
1427
|
return dropForeignKeyByName;
|
|
@@ -1368,39 +1433,39 @@ var DynamicTableService = /*#__PURE__*/function () {
|
|
|
1368
1433
|
}, {
|
|
1369
1434
|
key: "dropForeignKey",
|
|
1370
1435
|
value: (function () {
|
|
1371
|
-
var _dropForeignKey = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function
|
|
1436
|
+
var _dropForeignKey = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6(tableName, constraintName) {
|
|
1372
1437
|
var _yield$this$supabase$5, error, _t5;
|
|
1373
|
-
return _regeneratorRuntime.wrap(function (
|
|
1374
|
-
while (1) switch (
|
|
1438
|
+
return _regeneratorRuntime.wrap(function (_context6) {
|
|
1439
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
1375
1440
|
case 0:
|
|
1376
|
-
|
|
1377
|
-
|
|
1441
|
+
_context6.prev = 0;
|
|
1442
|
+
_context6.next = 1;
|
|
1378
1443
|
return this.supabase.rpc("execute_sql", {
|
|
1379
1444
|
sql_query: "ALTER TABLE \"".concat(tableName, "\" DROP CONSTRAINT IF EXISTS \"").concat(constraintName, "\";")
|
|
1380
1445
|
});
|
|
1381
1446
|
case 1:
|
|
1382
|
-
_yield$this$supabase$5 =
|
|
1447
|
+
_yield$this$supabase$5 = _context6.sent;
|
|
1383
1448
|
error = _yield$this$supabase$5.error;
|
|
1384
1449
|
if (!error) {
|
|
1385
|
-
|
|
1450
|
+
_context6.next = 2;
|
|
1386
1451
|
break;
|
|
1387
1452
|
}
|
|
1388
1453
|
throw error;
|
|
1389
1454
|
case 2:
|
|
1390
1455
|
console.log("\u5916\u952E\u7EA6\u675F ".concat(constraintName, " \u5DF2\u4ECE\u8868 ").concat(tableName, " \u5220\u9664"));
|
|
1391
|
-
return
|
|
1456
|
+
return _context6.abrupt("return", true);
|
|
1392
1457
|
case 3:
|
|
1393
|
-
|
|
1394
|
-
_t5 =
|
|
1458
|
+
_context6.prev = 3;
|
|
1459
|
+
_t5 = _context6["catch"](0);
|
|
1395
1460
|
console.error("\u5220\u9664\u5916\u952E\u7EA6\u675F\u5931\u8D25:", _t5);
|
|
1396
|
-
return
|
|
1461
|
+
return _context6.abrupt("return", false);
|
|
1397
1462
|
case 4:
|
|
1398
1463
|
case "end":
|
|
1399
|
-
return
|
|
1464
|
+
return _context6.stop();
|
|
1400
1465
|
}
|
|
1401
|
-
},
|
|
1466
|
+
}, _callee6, this, [[0, 3]]);
|
|
1402
1467
|
}));
|
|
1403
|
-
function dropForeignKey(
|
|
1468
|
+
function dropForeignKey(_x1, _x10) {
|
|
1404
1469
|
return _dropForeignKey.apply(this, arguments);
|
|
1405
1470
|
}
|
|
1406
1471
|
return dropForeignKey;
|
|
@@ -1412,39 +1477,39 @@ var DynamicTableService = /*#__PURE__*/function () {
|
|
|
1412
1477
|
}, {
|
|
1413
1478
|
key: "tableExists",
|
|
1414
1479
|
value: (function () {
|
|
1415
|
-
var _tableExists = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function
|
|
1480
|
+
var _tableExists = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee7(tableName) {
|
|
1416
1481
|
var _yield$this$supabase$6, data, error, _t6;
|
|
1417
|
-
return _regeneratorRuntime.wrap(function (
|
|
1418
|
-
while (1) switch (
|
|
1482
|
+
return _regeneratorRuntime.wrap(function (_context7) {
|
|
1483
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
1419
1484
|
case 0:
|
|
1420
|
-
|
|
1421
|
-
|
|
1485
|
+
_context7.prev = 0;
|
|
1486
|
+
_context7.next = 1;
|
|
1422
1487
|
return this.supabase.rpc("check_table_exists", {
|
|
1423
1488
|
table_name: tableName
|
|
1424
1489
|
});
|
|
1425
1490
|
case 1:
|
|
1426
|
-
_yield$this$supabase$6 =
|
|
1491
|
+
_yield$this$supabase$6 = _context7.sent;
|
|
1427
1492
|
data = _yield$this$supabase$6.data;
|
|
1428
1493
|
error = _yield$this$supabase$6.error;
|
|
1429
1494
|
if (!error) {
|
|
1430
|
-
|
|
1495
|
+
_context7.next = 2;
|
|
1431
1496
|
break;
|
|
1432
1497
|
}
|
|
1433
1498
|
throw error;
|
|
1434
1499
|
case 2:
|
|
1435
|
-
return
|
|
1500
|
+
return _context7.abrupt("return", data || false);
|
|
1436
1501
|
case 3:
|
|
1437
|
-
|
|
1438
|
-
_t6 =
|
|
1502
|
+
_context7.prev = 3;
|
|
1503
|
+
_t6 = _context7["catch"](0);
|
|
1439
1504
|
console.error("\u68C0\u67E5\u8868 ".concat(tableName, " \u662F\u5426\u5B58\u5728\u5931\u8D25:"), _t6);
|
|
1440
|
-
return
|
|
1505
|
+
return _context7.abrupt("return", false);
|
|
1441
1506
|
case 4:
|
|
1442
1507
|
case "end":
|
|
1443
|
-
return
|
|
1508
|
+
return _context7.stop();
|
|
1444
1509
|
}
|
|
1445
|
-
},
|
|
1510
|
+
}, _callee7, this, [[0, 3]]);
|
|
1446
1511
|
}));
|
|
1447
|
-
function tableExists(
|
|
1512
|
+
function tableExists(_x11) {
|
|
1448
1513
|
return _tableExists.apply(this, arguments);
|
|
1449
1514
|
}
|
|
1450
1515
|
return tableExists;
|
|
@@ -1456,39 +1521,39 @@ var DynamicTableService = /*#__PURE__*/function () {
|
|
|
1456
1521
|
}, {
|
|
1457
1522
|
key: "getTableStructure",
|
|
1458
1523
|
value: (function () {
|
|
1459
|
-
var _getTableStructure = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function
|
|
1524
|
+
var _getTableStructure = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee8(tableName) {
|
|
1460
1525
|
var _yield$this$supabase$7, data, error, _t7;
|
|
1461
|
-
return _regeneratorRuntime.wrap(function (
|
|
1462
|
-
while (1) switch (
|
|
1526
|
+
return _regeneratorRuntime.wrap(function (_context8) {
|
|
1527
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
1463
1528
|
case 0:
|
|
1464
|
-
|
|
1465
|
-
|
|
1529
|
+
_context8.prev = 0;
|
|
1530
|
+
_context8.next = 1;
|
|
1466
1531
|
return this.supabase.rpc("get_table_structure", {
|
|
1467
1532
|
table_name: tableName
|
|
1468
1533
|
});
|
|
1469
1534
|
case 1:
|
|
1470
|
-
_yield$this$supabase$7 =
|
|
1535
|
+
_yield$this$supabase$7 = _context8.sent;
|
|
1471
1536
|
data = _yield$this$supabase$7.data;
|
|
1472
1537
|
error = _yield$this$supabase$7.error;
|
|
1473
1538
|
if (!error) {
|
|
1474
|
-
|
|
1539
|
+
_context8.next = 2;
|
|
1475
1540
|
break;
|
|
1476
1541
|
}
|
|
1477
1542
|
throw error;
|
|
1478
1543
|
case 2:
|
|
1479
|
-
return
|
|
1544
|
+
return _context8.abrupt("return", data);
|
|
1480
1545
|
case 3:
|
|
1481
|
-
|
|
1482
|
-
_t7 =
|
|
1546
|
+
_context8.prev = 3;
|
|
1547
|
+
_t7 = _context8["catch"](0);
|
|
1483
1548
|
console.error("\u83B7\u53D6\u8868 ".concat(tableName, " \u7ED3\u6784\u5931\u8D25:"), _t7);
|
|
1484
|
-
return
|
|
1549
|
+
return _context8.abrupt("return", null);
|
|
1485
1550
|
case 4:
|
|
1486
1551
|
case "end":
|
|
1487
|
-
return
|
|
1552
|
+
return _context8.stop();
|
|
1488
1553
|
}
|
|
1489
|
-
},
|
|
1554
|
+
}, _callee8, this, [[0, 3]]);
|
|
1490
1555
|
}));
|
|
1491
|
-
function getTableStructure(
|
|
1556
|
+
function getTableStructure(_x12) {
|
|
1492
1557
|
return _getTableStructure.apply(this, arguments);
|
|
1493
1558
|
}
|
|
1494
1559
|
return getTableStructure;
|
|
@@ -1500,12 +1565,12 @@ var DynamicTableService = /*#__PURE__*/function () {
|
|
|
1500
1565
|
}, {
|
|
1501
1566
|
key: "executeQuery",
|
|
1502
1567
|
value: (function () {
|
|
1503
|
-
var _executeQuery = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function
|
|
1568
|
+
var _executeQuery = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee9(sql, values) {
|
|
1504
1569
|
var finalSql, _yield$this$supabase$8, data, error, _t8;
|
|
1505
|
-
return _regeneratorRuntime.wrap(function (
|
|
1506
|
-
while (1) switch (
|
|
1570
|
+
return _regeneratorRuntime.wrap(function (_context9) {
|
|
1571
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
1507
1572
|
case 0:
|
|
1508
|
-
|
|
1573
|
+
_context9.prev = 0;
|
|
1509
1574
|
// 如果有参数,需要先替换占位符
|
|
1510
1575
|
finalSql = sql;
|
|
1511
1576
|
if (values && values.length > 0) {
|
|
@@ -1514,34 +1579,34 @@ var DynamicTableService = /*#__PURE__*/function () {
|
|
|
1514
1579
|
finalSql = finalSql.replace("?", placeholder);
|
|
1515
1580
|
});
|
|
1516
1581
|
}
|
|
1517
|
-
|
|
1582
|
+
_context9.next = 1;
|
|
1518
1583
|
return this.supabase.rpc("execute_sql_with_params", {
|
|
1519
1584
|
sql_query: finalSql,
|
|
1520
1585
|
params: values || []
|
|
1521
1586
|
});
|
|
1522
1587
|
case 1:
|
|
1523
|
-
_yield$this$supabase$8 =
|
|
1588
|
+
_yield$this$supabase$8 = _context9.sent;
|
|
1524
1589
|
data = _yield$this$supabase$8.data;
|
|
1525
1590
|
error = _yield$this$supabase$8.error;
|
|
1526
1591
|
if (!error) {
|
|
1527
|
-
|
|
1592
|
+
_context9.next = 2;
|
|
1528
1593
|
break;
|
|
1529
1594
|
}
|
|
1530
1595
|
throw error;
|
|
1531
1596
|
case 2:
|
|
1532
|
-
return
|
|
1597
|
+
return _context9.abrupt("return", data);
|
|
1533
1598
|
case 3:
|
|
1534
|
-
|
|
1535
|
-
_t8 =
|
|
1599
|
+
_context9.prev = 3;
|
|
1600
|
+
_t8 = _context9["catch"](0);
|
|
1536
1601
|
console.error("执行 SQL 查询失败:", _t8);
|
|
1537
1602
|
throw _t8;
|
|
1538
1603
|
case 4:
|
|
1539
1604
|
case "end":
|
|
1540
|
-
return
|
|
1605
|
+
return _context9.stop();
|
|
1541
1606
|
}
|
|
1542
|
-
},
|
|
1607
|
+
}, _callee9, this, [[0, 3]]);
|
|
1543
1608
|
}));
|
|
1544
|
-
function executeQuery(
|
|
1609
|
+
function executeQuery(_x13, _x14) {
|
|
1545
1610
|
return _executeQuery.apply(this, arguments);
|
|
1546
1611
|
}
|
|
1547
1612
|
return executeQuery;
|
|
@@ -1553,72 +1618,67 @@ var DynamicTableService = /*#__PURE__*/function () {
|
|
|
1553
1618
|
}, {
|
|
1554
1619
|
key: "getTableData",
|
|
1555
1620
|
value: (function () {
|
|
1556
|
-
var _getTableData = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function
|
|
1621
|
+
var _getTableData = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee0(tableName) {
|
|
1622
|
+
var _this = this;
|
|
1557
1623
|
var page,
|
|
1558
1624
|
limit,
|
|
1559
1625
|
where,
|
|
1560
1626
|
filters,
|
|
1561
1627
|
offset,
|
|
1562
|
-
|
|
1563
|
-
_yield$
|
|
1628
|
+
buildQuery,
|
|
1629
|
+
_yield$this$orderByCr,
|
|
1564
1630
|
data,
|
|
1565
|
-
error,
|
|
1566
1631
|
count,
|
|
1567
|
-
|
|
1632
|
+
_args0 = arguments,
|
|
1568
1633
|
_t9;
|
|
1569
|
-
return _regeneratorRuntime.wrap(function (
|
|
1570
|
-
while (1) switch (
|
|
1634
|
+
return _regeneratorRuntime.wrap(function (_context0) {
|
|
1635
|
+
while (1) switch (_context0.prev = _context0.next) {
|
|
1571
1636
|
case 0:
|
|
1572
|
-
page =
|
|
1573
|
-
limit =
|
|
1574
|
-
where =
|
|
1575
|
-
filters =
|
|
1576
|
-
|
|
1577
|
-
offset = (page - 1) * limit;
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
}
|
|
1637
|
+
page = _args0.length > 1 && _args0[1] !== undefined ? _args0[1] : 1;
|
|
1638
|
+
limit = _args0.length > 2 && _args0[2] !== undefined ? _args0[2] : 10;
|
|
1639
|
+
where = _args0.length > 3 ? _args0[3] : undefined;
|
|
1640
|
+
filters = _args0.length > 4 ? _args0[4] : undefined;
|
|
1641
|
+
_context0.prev = 1;
|
|
1642
|
+
offset = (page - 1) * limit;
|
|
1643
|
+
buildQuery = function buildQuery() {
|
|
1644
|
+
// 构建查询
|
|
1645
|
+
var query = _this.supabase.from(tableName).select("*", {
|
|
1646
|
+
count: "exact"
|
|
1647
|
+
});
|
|
1648
|
+
// 添加 filters(AND)
|
|
1649
|
+
query = _this.applySupabaseFilters(query, filters);
|
|
1650
|
+
// 添加where条件
|
|
1651
|
+
if (where) {
|
|
1652
|
+
// 这里简化处理,实际使用中可能需要更复杂的where解析
|
|
1653
|
+
query = query.or(where);
|
|
1654
|
+
}
|
|
1655
|
+
return query;
|
|
1656
|
+
};
|
|
1657
|
+
_context0.next = 2;
|
|
1658
|
+
return this.orderByCreatedAtOrFallback(buildQuery, offset, limit);
|
|
1592
1659
|
case 2:
|
|
1593
|
-
_yield$
|
|
1594
|
-
data = _yield$
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
if (!error) {
|
|
1598
|
-
_context9.next = 3;
|
|
1599
|
-
break;
|
|
1600
|
-
}
|
|
1601
|
-
throw error;
|
|
1602
|
-
case 3:
|
|
1603
|
-
return _context9.abrupt("return", {
|
|
1660
|
+
_yield$this$orderByCr = _context0.sent;
|
|
1661
|
+
data = _yield$this$orderByCr.data;
|
|
1662
|
+
count = _yield$this$orderByCr.count;
|
|
1663
|
+
return _context0.abrupt("return", {
|
|
1604
1664
|
data: data || [],
|
|
1605
1665
|
total: count || 0,
|
|
1606
1666
|
page: page,
|
|
1607
1667
|
limit: limit,
|
|
1608
1668
|
totalPages: Math.ceil((count || 0) / limit)
|
|
1609
1669
|
});
|
|
1610
|
-
case
|
|
1611
|
-
|
|
1612
|
-
_t9 =
|
|
1670
|
+
case 3:
|
|
1671
|
+
_context0.prev = 3;
|
|
1672
|
+
_t9 = _context0["catch"](1);
|
|
1613
1673
|
console.error("\u83B7\u53D6\u8868 ".concat(tableName, " \u6570\u636E\u5931\u8D25:"), _t9);
|
|
1614
1674
|
throw _t9;
|
|
1615
|
-
case
|
|
1675
|
+
case 4:
|
|
1616
1676
|
case "end":
|
|
1617
|
-
return
|
|
1677
|
+
return _context0.stop();
|
|
1618
1678
|
}
|
|
1619
|
-
},
|
|
1679
|
+
}, _callee0, this, [[1, 3]]);
|
|
1620
1680
|
}));
|
|
1621
|
-
function getTableData(
|
|
1681
|
+
function getTableData(_x15) {
|
|
1622
1682
|
return _getTableData.apply(this, arguments);
|
|
1623
1683
|
}
|
|
1624
1684
|
return getTableData;
|
|
@@ -1630,77 +1690,71 @@ var DynamicTableService = /*#__PURE__*/function () {
|
|
|
1630
1690
|
}, {
|
|
1631
1691
|
key: "getTableDataWithSearch",
|
|
1632
1692
|
value: (function () {
|
|
1633
|
-
var _getTableDataWithSearch = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function
|
|
1693
|
+
var _getTableDataWithSearch = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee1(tableName) {
|
|
1694
|
+
var _this2 = this;
|
|
1634
1695
|
var page,
|
|
1635
1696
|
limit,
|
|
1636
1697
|
searchableFields,
|
|
1637
1698
|
searchValue,
|
|
1638
1699
|
filters,
|
|
1639
1700
|
offset,
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
_yield$query$order$ra2,
|
|
1701
|
+
buildQuery,
|
|
1702
|
+
_yield$this$orderByCr2,
|
|
1643
1703
|
data,
|
|
1644
|
-
error,
|
|
1645
1704
|
count,
|
|
1646
|
-
|
|
1705
|
+
_args1 = arguments,
|
|
1647
1706
|
_t0;
|
|
1648
|
-
return _regeneratorRuntime.wrap(function (
|
|
1649
|
-
while (1) switch (
|
|
1707
|
+
return _regeneratorRuntime.wrap(function (_context1) {
|
|
1708
|
+
while (1) switch (_context1.prev = _context1.next) {
|
|
1650
1709
|
case 0:
|
|
1651
|
-
page =
|
|
1652
|
-
limit =
|
|
1653
|
-
searchableFields =
|
|
1654
|
-
searchValue =
|
|
1655
|
-
filters =
|
|
1656
|
-
|
|
1657
|
-
offset = (page - 1) * limit;
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
}
|
|
1710
|
+
page = _args1.length > 1 && _args1[1] !== undefined ? _args1[1] : 1;
|
|
1711
|
+
limit = _args1.length > 2 && _args1[2] !== undefined ? _args1[2] : 10;
|
|
1712
|
+
searchableFields = _args1.length > 3 ? _args1[3] : undefined;
|
|
1713
|
+
searchValue = _args1.length > 4 ? _args1[4] : undefined;
|
|
1714
|
+
filters = _args1.length > 5 ? _args1[5] : undefined;
|
|
1715
|
+
_context1.prev = 1;
|
|
1716
|
+
offset = (page - 1) * limit;
|
|
1717
|
+
buildQuery = function buildQuery() {
|
|
1718
|
+
// 构建查询
|
|
1719
|
+
var query = _this2.supabase.from(tableName).select("*", {
|
|
1720
|
+
count: "exact"
|
|
1721
|
+
});
|
|
1722
|
+
// 添加 filters(AND)
|
|
1723
|
+
query = _this2.applySupabaseFilters(query, filters);
|
|
1724
|
+
// 构建搜索条件:使用Supabase的ilike操作符
|
|
1725
|
+
if (searchableFields.length > 0) {
|
|
1726
|
+
var searchConditions = searchableFields.map(function (field) {
|
|
1727
|
+
return "".concat(field, ".ilike.%").concat(searchValue, "%");
|
|
1728
|
+
}).join(",");
|
|
1729
|
+
query = query.or(searchConditions);
|
|
1730
|
+
}
|
|
1731
|
+
return query;
|
|
1732
|
+
};
|
|
1733
|
+
_context1.next = 2;
|
|
1734
|
+
return this.orderByCreatedAtOrFallback(buildQuery, offset, limit);
|
|
1674
1735
|
case 2:
|
|
1675
|
-
_yield$
|
|
1676
|
-
data = _yield$
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
if (!error) {
|
|
1680
|
-
_context0.next = 3;
|
|
1681
|
-
break;
|
|
1682
|
-
}
|
|
1683
|
-
throw error;
|
|
1684
|
-
case 3:
|
|
1685
|
-
return _context0.abrupt("return", {
|
|
1736
|
+
_yield$this$orderByCr2 = _context1.sent;
|
|
1737
|
+
data = _yield$this$orderByCr2.data;
|
|
1738
|
+
count = _yield$this$orderByCr2.count;
|
|
1739
|
+
return _context1.abrupt("return", {
|
|
1686
1740
|
data: data || [],
|
|
1687
1741
|
total: count || 0,
|
|
1688
1742
|
page: page,
|
|
1689
1743
|
limit: limit,
|
|
1690
1744
|
totalPages: Math.ceil((count || 0) / limit)
|
|
1691
1745
|
});
|
|
1692
|
-
case
|
|
1693
|
-
|
|
1694
|
-
_t0 =
|
|
1746
|
+
case 3:
|
|
1747
|
+
_context1.prev = 3;
|
|
1748
|
+
_t0 = _context1["catch"](1);
|
|
1695
1749
|
console.error("\u83B7\u53D6\u8868 ".concat(tableName, " \u641C\u7D22\u6570\u636E\u5931\u8D25:"), _t0);
|
|
1696
1750
|
throw _t0;
|
|
1697
|
-
case
|
|
1751
|
+
case 4:
|
|
1698
1752
|
case "end":
|
|
1699
|
-
return
|
|
1753
|
+
return _context1.stop();
|
|
1700
1754
|
}
|
|
1701
|
-
},
|
|
1755
|
+
}, _callee1, this, [[1, 3]]);
|
|
1702
1756
|
}));
|
|
1703
|
-
function getTableDataWithSearch(
|
|
1757
|
+
function getTableDataWithSearch(_x16) {
|
|
1704
1758
|
return _getTableDataWithSearch.apply(this, arguments);
|
|
1705
1759
|
}
|
|
1706
1760
|
return getTableDataWithSearch;
|
|
@@ -1712,7 +1766,7 @@ var DynamicTableService = /*#__PURE__*/function () {
|
|
|
1712
1766
|
}, {
|
|
1713
1767
|
key: "insertData",
|
|
1714
1768
|
value: (function () {
|
|
1715
|
-
var _insertData = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function
|
|
1769
|
+
var _insertData = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee10(tableName, data) {
|
|
1716
1770
|
var autoFixForeignKey,
|
|
1717
1771
|
_yield$this$supabase$9,
|
|
1718
1772
|
result,
|
|
@@ -1722,25 +1776,25 @@ var DynamicTableService = /*#__PURE__*/function () {
|
|
|
1722
1776
|
constraintName,
|
|
1723
1777
|
dropResult,
|
|
1724
1778
|
_dropResult,
|
|
1725
|
-
|
|
1779
|
+
_args10 = arguments,
|
|
1726
1780
|
_t1;
|
|
1727
|
-
return _regeneratorRuntime.wrap(function (
|
|
1728
|
-
while (1) switch (
|
|
1781
|
+
return _regeneratorRuntime.wrap(function (_context10) {
|
|
1782
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
1729
1783
|
case 0:
|
|
1730
|
-
autoFixForeignKey =
|
|
1731
|
-
|
|
1732
|
-
|
|
1784
|
+
autoFixForeignKey = _args10.length > 2 && _args10[2] !== undefined ? _args10[2] : true;
|
|
1785
|
+
_context10.prev = 1;
|
|
1786
|
+
_context10.next = 2;
|
|
1733
1787
|
return this.supabase.from(tableName).insert(data).select().single();
|
|
1734
1788
|
case 2:
|
|
1735
|
-
_yield$this$supabase$9 =
|
|
1789
|
+
_yield$this$supabase$9 = _context10.sent;
|
|
1736
1790
|
result = _yield$this$supabase$9.data;
|
|
1737
1791
|
error = _yield$this$supabase$9.error;
|
|
1738
1792
|
if (!error) {
|
|
1739
|
-
|
|
1793
|
+
_context10.next = 10;
|
|
1740
1794
|
break;
|
|
1741
1795
|
}
|
|
1742
1796
|
if (!(autoFixForeignKey && error.code === '23503' && (_error$message = error.message) !== null && _error$message !== void 0 && _error$message.includes('foreign key constraint'))) {
|
|
1743
|
-
|
|
1797
|
+
_context10.next = 9;
|
|
1744
1798
|
break;
|
|
1745
1799
|
}
|
|
1746
1800
|
console.log("\u68C0\u6D4B\u5230\u5916\u952E\u7EA6\u675F\u9519\u8BEF\uFF0C\u5C1D\u8BD5\u81EA\u52A8\u5220\u9664\u5916\u952E\u7EA6\u675F\u5E76\u91CD\u8BD5...");
|
|
@@ -1749,59 +1803,59 @@ var DynamicTableService = /*#__PURE__*/function () {
|
|
|
1749
1803
|
// 格式: violates foreign key constraint "constraint_name"
|
|
1750
1804
|
constraintMatch = error.message.match(/foreign key constraint "([^"]+)"/);
|
|
1751
1805
|
if (!(constraintMatch && constraintMatch[1])) {
|
|
1752
|
-
|
|
1806
|
+
_context10.next = 6;
|
|
1753
1807
|
break;
|
|
1754
1808
|
}
|
|
1755
1809
|
constraintName = constraintMatch[1];
|
|
1756
1810
|
console.log("\u63D0\u53D6\u5230\u7EA6\u675F\u540D: ".concat(constraintName));
|
|
1757
1811
|
// 直接删除该约束
|
|
1758
|
-
|
|
1812
|
+
_context10.next = 3;
|
|
1759
1813
|
return this.dropForeignKeyByName(tableName, constraintName);
|
|
1760
1814
|
case 3:
|
|
1761
|
-
dropResult =
|
|
1815
|
+
dropResult = _context10.sent;
|
|
1762
1816
|
if (!dropResult) {
|
|
1763
|
-
|
|
1817
|
+
_context10.next = 5;
|
|
1764
1818
|
break;
|
|
1765
1819
|
}
|
|
1766
1820
|
console.log("\u5916\u952E\u7EA6\u675F ".concat(constraintName, " \u5DF2\u5220\u9664\uFF0C\u91CD\u8BD5\u63D2\u5165\u6570\u636E..."));
|
|
1767
1821
|
// 重试插入,但这次不再自动修复(避免无限循环)
|
|
1768
|
-
|
|
1822
|
+
_context10.next = 4;
|
|
1769
1823
|
return this.insertData(tableName, data, false);
|
|
1770
1824
|
case 4:
|
|
1771
|
-
return
|
|
1825
|
+
return _context10.abrupt("return", _context10.sent);
|
|
1772
1826
|
case 5:
|
|
1773
|
-
|
|
1827
|
+
_context10.next = 9;
|
|
1774
1828
|
break;
|
|
1775
1829
|
case 6:
|
|
1776
|
-
|
|
1830
|
+
_context10.next = 7;
|
|
1777
1831
|
return this.dropAllForeignKeys(tableName);
|
|
1778
1832
|
case 7:
|
|
1779
|
-
_dropResult =
|
|
1833
|
+
_dropResult = _context10.sent;
|
|
1780
1834
|
if (!_dropResult) {
|
|
1781
|
-
|
|
1835
|
+
_context10.next = 9;
|
|
1782
1836
|
break;
|
|
1783
1837
|
}
|
|
1784
1838
|
console.log("\u5916\u952E\u7EA6\u675F\u5DF2\u5220\u9664\uFF0C\u91CD\u8BD5\u63D2\u5165\u6570\u636E...");
|
|
1785
|
-
|
|
1839
|
+
_context10.next = 8;
|
|
1786
1840
|
return this.insertData(tableName, data, false);
|
|
1787
1841
|
case 8:
|
|
1788
|
-
return
|
|
1842
|
+
return _context10.abrupt("return", _context10.sent);
|
|
1789
1843
|
case 9:
|
|
1790
1844
|
throw error;
|
|
1791
1845
|
case 10:
|
|
1792
|
-
return
|
|
1846
|
+
return _context10.abrupt("return", result);
|
|
1793
1847
|
case 11:
|
|
1794
|
-
|
|
1795
|
-
_t1 =
|
|
1848
|
+
_context10.prev = 11;
|
|
1849
|
+
_t1 = _context10["catch"](1);
|
|
1796
1850
|
console.error("\u63D2\u5165\u6570\u636E\u5230\u8868 ".concat(tableName, " \u5931\u8D25:"), _t1);
|
|
1797
1851
|
throw _t1;
|
|
1798
1852
|
case 12:
|
|
1799
1853
|
case "end":
|
|
1800
|
-
return
|
|
1854
|
+
return _context10.stop();
|
|
1801
1855
|
}
|
|
1802
|
-
},
|
|
1856
|
+
}, _callee10, this, [[1, 11]]);
|
|
1803
1857
|
}));
|
|
1804
|
-
function insertData(
|
|
1858
|
+
function insertData(_x17, _x18) {
|
|
1805
1859
|
return _insertData.apply(this, arguments);
|
|
1806
1860
|
}
|
|
1807
1861
|
return insertData;
|
|
@@ -1814,7 +1868,7 @@ var DynamicTableService = /*#__PURE__*/function () {
|
|
|
1814
1868
|
}, {
|
|
1815
1869
|
key: "updateData",
|
|
1816
1870
|
value: (function () {
|
|
1817
|
-
var _updateData = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function
|
|
1871
|
+
var _updateData = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee11(tableName, id, data) {
|
|
1818
1872
|
var autoFixForeignKey,
|
|
1819
1873
|
_yield$this$supabase$0,
|
|
1820
1874
|
result,
|
|
@@ -1824,25 +1878,25 @@ var DynamicTableService = /*#__PURE__*/function () {
|
|
|
1824
1878
|
constraintName,
|
|
1825
1879
|
dropResult,
|
|
1826
1880
|
_dropResult2,
|
|
1827
|
-
|
|
1881
|
+
_args11 = arguments,
|
|
1828
1882
|
_t10;
|
|
1829
|
-
return _regeneratorRuntime.wrap(function (
|
|
1830
|
-
while (1) switch (
|
|
1883
|
+
return _regeneratorRuntime.wrap(function (_context11) {
|
|
1884
|
+
while (1) switch (_context11.prev = _context11.next) {
|
|
1831
1885
|
case 0:
|
|
1832
|
-
autoFixForeignKey =
|
|
1833
|
-
|
|
1834
|
-
|
|
1886
|
+
autoFixForeignKey = _args11.length > 3 && _args11[3] !== undefined ? _args11[3] : true;
|
|
1887
|
+
_context11.prev = 1;
|
|
1888
|
+
_context11.next = 2;
|
|
1835
1889
|
return this.supabase.from(tableName).update(data).eq("id", id).select().single();
|
|
1836
1890
|
case 2:
|
|
1837
|
-
_yield$this$supabase$0 =
|
|
1891
|
+
_yield$this$supabase$0 = _context11.sent;
|
|
1838
1892
|
result = _yield$this$supabase$0.data;
|
|
1839
1893
|
error = _yield$this$supabase$0.error;
|
|
1840
1894
|
if (!error) {
|
|
1841
|
-
|
|
1895
|
+
_context11.next = 10;
|
|
1842
1896
|
break;
|
|
1843
1897
|
}
|
|
1844
1898
|
if (!(autoFixForeignKey && error.code === '23503' && (_error$message2 = error.message) !== null && _error$message2 !== void 0 && _error$message2.includes('foreign key constraint'))) {
|
|
1845
|
-
|
|
1899
|
+
_context11.next = 9;
|
|
1846
1900
|
break;
|
|
1847
1901
|
}
|
|
1848
1902
|
console.log("\u68C0\u6D4B\u5230\u5916\u952E\u7EA6\u675F\u9519\u8BEF\uFF0C\u5C1D\u8BD5\u81EA\u52A8\u5220\u9664\u5916\u952E\u7EA6\u675F\u5E76\u91CD\u8BD5...");
|
|
@@ -1850,58 +1904,58 @@ var DynamicTableService = /*#__PURE__*/function () {
|
|
|
1850
1904
|
// 尝试从错误消息中提取约束名
|
|
1851
1905
|
constraintMatch = error.message.match(/foreign key constraint "([^"]+)"/);
|
|
1852
1906
|
if (!(constraintMatch && constraintMatch[1])) {
|
|
1853
|
-
|
|
1907
|
+
_context11.next = 6;
|
|
1854
1908
|
break;
|
|
1855
1909
|
}
|
|
1856
1910
|
constraintName = constraintMatch[1];
|
|
1857
1911
|
console.log("\u63D0\u53D6\u5230\u7EA6\u675F\u540D: ".concat(constraintName));
|
|
1858
1912
|
// 直接删除该约束
|
|
1859
|
-
|
|
1913
|
+
_context11.next = 3;
|
|
1860
1914
|
return this.dropForeignKeyByName(tableName, constraintName);
|
|
1861
1915
|
case 3:
|
|
1862
|
-
dropResult =
|
|
1916
|
+
dropResult = _context11.sent;
|
|
1863
1917
|
if (!dropResult) {
|
|
1864
|
-
|
|
1918
|
+
_context11.next = 5;
|
|
1865
1919
|
break;
|
|
1866
1920
|
}
|
|
1867
1921
|
console.log("\u5916\u952E\u7EA6\u675F ".concat(constraintName, " \u5DF2\u5220\u9664\uFF0C\u91CD\u8BD5\u66F4\u65B0\u6570\u636E..."));
|
|
1868
|
-
|
|
1922
|
+
_context11.next = 4;
|
|
1869
1923
|
return this.updateData(tableName, id, data, false);
|
|
1870
1924
|
case 4:
|
|
1871
|
-
return
|
|
1925
|
+
return _context11.abrupt("return", _context11.sent);
|
|
1872
1926
|
case 5:
|
|
1873
|
-
|
|
1927
|
+
_context11.next = 9;
|
|
1874
1928
|
break;
|
|
1875
1929
|
case 6:
|
|
1876
|
-
|
|
1930
|
+
_context11.next = 7;
|
|
1877
1931
|
return this.dropAllForeignKeys(tableName);
|
|
1878
1932
|
case 7:
|
|
1879
|
-
_dropResult2 =
|
|
1933
|
+
_dropResult2 = _context11.sent;
|
|
1880
1934
|
if (!_dropResult2) {
|
|
1881
|
-
|
|
1935
|
+
_context11.next = 9;
|
|
1882
1936
|
break;
|
|
1883
1937
|
}
|
|
1884
1938
|
console.log("\u5916\u952E\u7EA6\u675F\u5DF2\u5220\u9664\uFF0C\u91CD\u8BD5\u66F4\u65B0\u6570\u636E...");
|
|
1885
|
-
|
|
1939
|
+
_context11.next = 8;
|
|
1886
1940
|
return this.updateData(tableName, id, data, false);
|
|
1887
1941
|
case 8:
|
|
1888
|
-
return
|
|
1942
|
+
return _context11.abrupt("return", _context11.sent);
|
|
1889
1943
|
case 9:
|
|
1890
1944
|
throw error;
|
|
1891
1945
|
case 10:
|
|
1892
|
-
return
|
|
1946
|
+
return _context11.abrupt("return", result);
|
|
1893
1947
|
case 11:
|
|
1894
|
-
|
|
1895
|
-
_t10 =
|
|
1948
|
+
_context11.prev = 11;
|
|
1949
|
+
_t10 = _context11["catch"](1);
|
|
1896
1950
|
console.error("\u66F4\u65B0\u8868 ".concat(tableName, " \u6570\u636E\u5931\u8D25:"), _t10);
|
|
1897
1951
|
throw _t10;
|
|
1898
1952
|
case 12:
|
|
1899
1953
|
case "end":
|
|
1900
|
-
return
|
|
1954
|
+
return _context11.stop();
|
|
1901
1955
|
}
|
|
1902
|
-
},
|
|
1956
|
+
}, _callee11, this, [[1, 11]]);
|
|
1903
1957
|
}));
|
|
1904
|
-
function updateData(
|
|
1958
|
+
function updateData(_x19, _x20, _x21) {
|
|
1905
1959
|
return _updateData.apply(this, arguments);
|
|
1906
1960
|
}
|
|
1907
1961
|
return updateData;
|
|
@@ -1914,37 +1968,37 @@ var DynamicTableService = /*#__PURE__*/function () {
|
|
|
1914
1968
|
}, {
|
|
1915
1969
|
key: "deleteData",
|
|
1916
1970
|
value: (function () {
|
|
1917
|
-
var _deleteData = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function
|
|
1971
|
+
var _deleteData = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee12(tableName, id) {
|
|
1918
1972
|
var _yield$this$supabase$1, result, error, _t11;
|
|
1919
|
-
return _regeneratorRuntime.wrap(function (
|
|
1920
|
-
while (1) switch (
|
|
1973
|
+
return _regeneratorRuntime.wrap(function (_context12) {
|
|
1974
|
+
while (1) switch (_context12.prev = _context12.next) {
|
|
1921
1975
|
case 0:
|
|
1922
|
-
|
|
1923
|
-
|
|
1976
|
+
_context12.prev = 0;
|
|
1977
|
+
_context12.next = 1;
|
|
1924
1978
|
return this.supabase.from(tableName)["delete"]().eq("id", id).select().single();
|
|
1925
1979
|
case 1:
|
|
1926
|
-
_yield$this$supabase$1 =
|
|
1980
|
+
_yield$this$supabase$1 = _context12.sent;
|
|
1927
1981
|
result = _yield$this$supabase$1.data;
|
|
1928
1982
|
error = _yield$this$supabase$1.error;
|
|
1929
1983
|
if (!error) {
|
|
1930
|
-
|
|
1984
|
+
_context12.next = 2;
|
|
1931
1985
|
break;
|
|
1932
1986
|
}
|
|
1933
1987
|
throw error;
|
|
1934
1988
|
case 2:
|
|
1935
|
-
return
|
|
1989
|
+
return _context12.abrupt("return", result);
|
|
1936
1990
|
case 3:
|
|
1937
|
-
|
|
1938
|
-
_t11 =
|
|
1991
|
+
_context12.prev = 3;
|
|
1992
|
+
_t11 = _context12["catch"](0);
|
|
1939
1993
|
console.error("\u5220\u9664\u8868 ".concat(tableName, " \u6570\u636E\u5931\u8D25:"), _t11);
|
|
1940
1994
|
throw _t11;
|
|
1941
1995
|
case 4:
|
|
1942
1996
|
case "end":
|
|
1943
|
-
return
|
|
1997
|
+
return _context12.stop();
|
|
1944
1998
|
}
|
|
1945
|
-
},
|
|
1999
|
+
}, _callee12, this, [[0, 3]]);
|
|
1946
2000
|
}));
|
|
1947
|
-
function deleteData(
|
|
2001
|
+
function deleteData(_x22, _x23) {
|
|
1948
2002
|
return _deleteData.apply(this, arguments);
|
|
1949
2003
|
}
|
|
1950
2004
|
return deleteData;
|
|
@@ -1957,43 +2011,43 @@ var DynamicTableService = /*#__PURE__*/function () {
|
|
|
1957
2011
|
}, {
|
|
1958
2012
|
key: "getDataById",
|
|
1959
2013
|
value: (function () {
|
|
1960
|
-
var _getDataById = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function
|
|
2014
|
+
var _getDataById = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee13(tableName, id) {
|
|
1961
2015
|
var _yield$this$supabase$10, data, error, _t12;
|
|
1962
|
-
return _regeneratorRuntime.wrap(function (
|
|
1963
|
-
while (1) switch (
|
|
2016
|
+
return _regeneratorRuntime.wrap(function (_context13) {
|
|
2017
|
+
while (1) switch (_context13.prev = _context13.next) {
|
|
1964
2018
|
case 0:
|
|
1965
|
-
|
|
1966
|
-
|
|
2019
|
+
_context13.prev = 0;
|
|
2020
|
+
_context13.next = 1;
|
|
1967
2021
|
return this.supabase.from(tableName).select("*").eq("id", id).single();
|
|
1968
2022
|
case 1:
|
|
1969
|
-
_yield$this$supabase$10 =
|
|
2023
|
+
_yield$this$supabase$10 = _context13.sent;
|
|
1970
2024
|
data = _yield$this$supabase$10.data;
|
|
1971
2025
|
error = _yield$this$supabase$10.error;
|
|
1972
2026
|
if (!error) {
|
|
1973
|
-
|
|
2027
|
+
_context13.next = 3;
|
|
1974
2028
|
break;
|
|
1975
2029
|
}
|
|
1976
2030
|
if (!(error.code === "PGRST116")) {
|
|
1977
|
-
|
|
2031
|
+
_context13.next = 2;
|
|
1978
2032
|
break;
|
|
1979
2033
|
}
|
|
1980
|
-
return
|
|
2034
|
+
return _context13.abrupt("return", null);
|
|
1981
2035
|
case 2:
|
|
1982
2036
|
throw error;
|
|
1983
2037
|
case 3:
|
|
1984
|
-
return
|
|
2038
|
+
return _context13.abrupt("return", data);
|
|
1985
2039
|
case 4:
|
|
1986
|
-
|
|
1987
|
-
_t12 =
|
|
2040
|
+
_context13.prev = 4;
|
|
2041
|
+
_t12 = _context13["catch"](0);
|
|
1988
2042
|
console.error("\u83B7\u53D6\u8868 ".concat(tableName, " \u5355\u6761\u6570\u636E\u5931\u8D25:"), _t12);
|
|
1989
2043
|
throw _t12;
|
|
1990
2044
|
case 5:
|
|
1991
2045
|
case "end":
|
|
1992
|
-
return
|
|
2046
|
+
return _context13.stop();
|
|
1993
2047
|
}
|
|
1994
|
-
},
|
|
2048
|
+
}, _callee13, this, [[0, 4]]);
|
|
1995
2049
|
}));
|
|
1996
|
-
function getDataById(
|
|
2050
|
+
function getDataById(_x24, _x25) {
|
|
1997
2051
|
return _getDataById.apply(this, arguments);
|
|
1998
2052
|
}
|
|
1999
2053
|
return getDataById;
|
|
@@ -2007,47 +2061,47 @@ var DynamicTableService = /*#__PURE__*/function () {
|
|
|
2007
2061
|
}, {
|
|
2008
2062
|
key: "getRelationOptions",
|
|
2009
2063
|
value: (function () {
|
|
2010
|
-
var _getRelationOptions = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function
|
|
2064
|
+
var _getRelationOptions = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee14(params) {
|
|
2011
2065
|
var tableName, _params$displayField, displayField, _params$limit, limit, search, query, _yield$query, data, error, _t13;
|
|
2012
|
-
return _regeneratorRuntime.wrap(function (
|
|
2013
|
-
while (1) switch (
|
|
2066
|
+
return _regeneratorRuntime.wrap(function (_context14) {
|
|
2067
|
+
while (1) switch (_context14.prev = _context14.next) {
|
|
2014
2068
|
case 0:
|
|
2015
|
-
|
|
2069
|
+
_context14.prev = 0;
|
|
2016
2070
|
tableName = params.tableName, _params$displayField = params.displayField, displayField = _params$displayField === void 0 ? 'name' : _params$displayField, _params$limit = params.limit, limit = _params$limit === void 0 ? 100 : _params$limit, search = params.search; // 构建查询,获取所有字段(Supabase 动态字段选择类型推断有问题)
|
|
2017
2071
|
query = this.supabase.from(tableName).select('*').limit(limit); // 如果有搜索条件,添加模糊搜索
|
|
2018
2072
|
if (search) {
|
|
2019
2073
|
query = query.ilike(displayField, "%".concat(search, "%"));
|
|
2020
2074
|
}
|
|
2021
|
-
|
|
2075
|
+
_context14.next = 1;
|
|
2022
2076
|
return query;
|
|
2023
2077
|
case 1:
|
|
2024
|
-
_yield$query =
|
|
2078
|
+
_yield$query = _context14.sent;
|
|
2025
2079
|
data = _yield$query.data;
|
|
2026
2080
|
error = _yield$query.error;
|
|
2027
2081
|
if (!error) {
|
|
2028
|
-
|
|
2082
|
+
_context14.next = 2;
|
|
2029
2083
|
break;
|
|
2030
2084
|
}
|
|
2031
2085
|
throw error;
|
|
2032
2086
|
case 2:
|
|
2033
|
-
return
|
|
2087
|
+
return _context14.abrupt("return", (data || []).map(function (item) {
|
|
2034
2088
|
return _objectSpread$2({
|
|
2035
2089
|
id: item.id,
|
|
2036
2090
|
label: item[displayField] || "ID: ".concat(item.id)
|
|
2037
2091
|
}, item);
|
|
2038
2092
|
}));
|
|
2039
2093
|
case 3:
|
|
2040
|
-
|
|
2041
|
-
_t13 =
|
|
2094
|
+
_context14.prev = 3;
|
|
2095
|
+
_t13 = _context14["catch"](0);
|
|
2042
2096
|
console.error("\u83B7\u53D6\u5173\u8054\u8868 ".concat(params.tableName, " \u9009\u9879\u5931\u8D25:"), _t13);
|
|
2043
2097
|
throw _t13;
|
|
2044
2098
|
case 4:
|
|
2045
2099
|
case "end":
|
|
2046
|
-
return
|
|
2100
|
+
return _context14.stop();
|
|
2047
2101
|
}
|
|
2048
|
-
},
|
|
2102
|
+
}, _callee14, this, [[0, 3]]);
|
|
2049
2103
|
}));
|
|
2050
|
-
function getRelationOptions(
|
|
2104
|
+
function getRelationOptions(_x26) {
|
|
2051
2105
|
return _getRelationOptions.apply(this, arguments);
|
|
2052
2106
|
}
|
|
2053
2107
|
return getRelationOptions;
|
|
@@ -2064,25 +2118,26 @@ var DynamicTableService = /*#__PURE__*/function () {
|
|
|
2064
2118
|
}, {
|
|
2065
2119
|
key: "getTableDataWithRelations",
|
|
2066
2120
|
value: (function () {
|
|
2067
|
-
var _getTableDataWithRelations = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function
|
|
2121
|
+
var _getTableDataWithRelations = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee15(tableName, schema) {
|
|
2122
|
+
var _this3 = this;
|
|
2068
2123
|
var page,
|
|
2069
2124
|
limit,
|
|
2070
2125
|
offset,
|
|
2071
2126
|
selectFields,
|
|
2072
2127
|
relationFields,
|
|
2073
2128
|
relationSelects,
|
|
2074
|
-
|
|
2129
|
+
buildQuery,
|
|
2130
|
+
_yield$this$orderByCr3,
|
|
2075
2131
|
data,
|
|
2076
|
-
error,
|
|
2077
2132
|
count,
|
|
2078
|
-
|
|
2133
|
+
_args15 = arguments,
|
|
2079
2134
|
_t14;
|
|
2080
|
-
return _regeneratorRuntime.wrap(function (
|
|
2081
|
-
while (1) switch (
|
|
2135
|
+
return _regeneratorRuntime.wrap(function (_context15) {
|
|
2136
|
+
while (1) switch (_context15.prev = _context15.next) {
|
|
2082
2137
|
case 0:
|
|
2083
|
-
page =
|
|
2084
|
-
limit =
|
|
2085
|
-
|
|
2138
|
+
page = _args15.length > 2 && _args15[2] !== undefined ? _args15[2] : 1;
|
|
2139
|
+
limit = _args15.length > 3 && _args15[3] !== undefined ? _args15[3] : 10;
|
|
2140
|
+
_context15.prev = 1;
|
|
2086
2141
|
offset = (page - 1) * limit; // 构建 select 语句,包含关联表数据
|
|
2087
2142
|
selectFields = '*';
|
|
2088
2143
|
relationFields = schema.filter(function (f) {
|
|
@@ -2098,42 +2153,36 @@ var DynamicTableService = /*#__PURE__*/function () {
|
|
|
2098
2153
|
});
|
|
2099
2154
|
selectFields = "*, ".concat(relationSelects.join(', '));
|
|
2100
2155
|
}
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2156
|
+
buildQuery = function buildQuery() {
|
|
2157
|
+
return _this3.supabase.from(tableName).select(selectFields, {
|
|
2158
|
+
count: "exact"
|
|
2159
|
+
});
|
|
2160
|
+
};
|
|
2161
|
+
_context15.next = 2;
|
|
2162
|
+
return this.orderByCreatedAtOrFallback(buildQuery, offset, limit);
|
|
2107
2163
|
case 2:
|
|
2108
|
-
_yield$this$
|
|
2109
|
-
data = _yield$this$
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
if (!error) {
|
|
2113
|
-
_context14.next = 3;
|
|
2114
|
-
break;
|
|
2115
|
-
}
|
|
2116
|
-
throw error;
|
|
2117
|
-
case 3:
|
|
2118
|
-
return _context14.abrupt("return", {
|
|
2164
|
+
_yield$this$orderByCr3 = _context15.sent;
|
|
2165
|
+
data = _yield$this$orderByCr3.data;
|
|
2166
|
+
count = _yield$this$orderByCr3.count;
|
|
2167
|
+
return _context15.abrupt("return", {
|
|
2119
2168
|
data: data || [],
|
|
2120
2169
|
total: count || 0,
|
|
2121
2170
|
page: page,
|
|
2122
2171
|
limit: limit,
|
|
2123
2172
|
totalPages: Math.ceil((count || 0) / limit)
|
|
2124
2173
|
});
|
|
2125
|
-
case
|
|
2126
|
-
|
|
2127
|
-
_t14 =
|
|
2174
|
+
case 3:
|
|
2175
|
+
_context15.prev = 3;
|
|
2176
|
+
_t14 = _context15["catch"](1);
|
|
2128
2177
|
console.error("\u83B7\u53D6\u8868 ".concat(tableName, " \u5173\u8054\u6570\u636E\u5931\u8D25:"), _t14);
|
|
2129
2178
|
throw _t14;
|
|
2130
|
-
case
|
|
2179
|
+
case 4:
|
|
2131
2180
|
case "end":
|
|
2132
|
-
return
|
|
2181
|
+
return _context15.stop();
|
|
2133
2182
|
}
|
|
2134
|
-
},
|
|
2183
|
+
}, _callee15, this, [[1, 3]]);
|
|
2135
2184
|
}));
|
|
2136
|
-
function getTableDataWithRelations(
|
|
2185
|
+
function getTableDataWithRelations(_x27, _x28) {
|
|
2137
2186
|
return _getTableDataWithRelations.apply(this, arguments);
|
|
2138
2187
|
}
|
|
2139
2188
|
return getTableDataWithRelations;
|
|
@@ -3557,7 +3606,7 @@ function updateTableData(_x5, _x6) {
|
|
|
3557
3606
|
// DELETE - 删除数据
|
|
3558
3607
|
function _updateTableData() {
|
|
3559
3608
|
_updateTableData = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(c, tableName) {
|
|
3560
|
-
var _model$json_schema3, dynamicTableService, cmsModelService, body, id, data, recordId, _response6, existingData,
|
|
3609
|
+
var _model$json_schema3, dynamicTableService, cmsModelService, body, id, data, recordId, _response6, _response7, existingData, _response8, rawUpdateData, updateData, _i3, _Object$entries3, _Object$entries3$_i, key, value, model, _response9, result, _response0, response, _response1, _t5, _t6;
|
|
3561
3610
|
return _regeneratorRuntime.wrap(function (_context3) {
|
|
3562
3611
|
while (1) switch (_context3.prev = _context3.next) {
|
|
3563
3612
|
case 0:
|
|
@@ -3580,20 +3629,30 @@ function _updateTableData() {
|
|
|
3580
3629
|
};
|
|
3581
3630
|
return _context3.abrupt("return", c.json(_response6, 200));
|
|
3582
3631
|
case 2:
|
|
3583
|
-
|
|
3584
|
-
|
|
3632
|
+
if (!(String(recordId).trim().toLowerCase() === "nan")) {
|
|
3633
|
+
_context3.next = 3;
|
|
3634
|
+
break;
|
|
3635
|
+
}
|
|
3636
|
+
_response7 = {
|
|
3637
|
+
success: false,
|
|
3638
|
+
message: "数据 ID 不合法"
|
|
3639
|
+
};
|
|
3640
|
+
return _context3.abrupt("return", c.json(_response7, 200));
|
|
3585
3641
|
case 3:
|
|
3642
|
+
_context3.next = 4;
|
|
3643
|
+
return dynamicTableService.getDataById(tableName, recordId);
|
|
3644
|
+
case 4:
|
|
3586
3645
|
existingData = _context3.sent;
|
|
3587
3646
|
if (existingData) {
|
|
3588
|
-
_context3.next =
|
|
3647
|
+
_context3.next = 5;
|
|
3589
3648
|
break;
|
|
3590
3649
|
}
|
|
3591
|
-
|
|
3650
|
+
_response8 = {
|
|
3592
3651
|
success: false,
|
|
3593
3652
|
message: "数据不存在"
|
|
3594
3653
|
};
|
|
3595
|
-
return _context3.abrupt("return", c.json(
|
|
3596
|
-
case
|
|
3654
|
+
return _context3.abrupt("return", c.json(_response8, 200));
|
|
3655
|
+
case 5:
|
|
3597
3656
|
// 过滤掉系统字段
|
|
3598
3657
|
data.created_at, data.updated_at, rawUpdateData = _objectWithoutProperties(data, _excluded3); // 过滤掉空字符串值,避免违反 CHECK 约束
|
|
3599
3658
|
// 注意:更新时允许 null 值(用于清空字段),但不允许空字符串
|
|
@@ -3606,63 +3665,62 @@ function _updateTableData() {
|
|
|
3606
3665
|
}
|
|
3607
3666
|
}
|
|
3608
3667
|
// 处理 json/jsonb 字段:允许前端传 JSON 字符串
|
|
3609
|
-
_context3.next =
|
|
3668
|
+
_context3.next = 6;
|
|
3610
3669
|
return cmsModelService.findByTableName(tableName);
|
|
3611
|
-
case
|
|
3670
|
+
case 6:
|
|
3612
3671
|
model = _context3.sent;
|
|
3613
|
-
normalizedUpdateData = updateData;
|
|
3614
3672
|
if (!(model !== null && model !== void 0 && (_model$json_schema3 = model.json_schema) !== null && _model$json_schema3 !== void 0 && _model$json_schema3.fields)) {
|
|
3615
|
-
_context3.next =
|
|
3673
|
+
_context3.next = 9;
|
|
3616
3674
|
break;
|
|
3617
3675
|
}
|
|
3618
|
-
_context3.prev = 6;
|
|
3619
|
-
normalizedUpdateData = normalizeJsonLikeFields(model.json_schema.fields, updateData);
|
|
3620
|
-
_context3.next = 8;
|
|
3621
|
-
break;
|
|
3622
|
-
case 7:
|
|
3623
3676
|
_context3.prev = 7;
|
|
3624
|
-
|
|
3625
|
-
|
|
3677
|
+
normalizeJsonLikeFields(model.json_schema.fields, updateData);
|
|
3678
|
+
_context3.next = 9;
|
|
3679
|
+
break;
|
|
3680
|
+
case 8:
|
|
3681
|
+
_context3.prev = 8;
|
|
3682
|
+
_t5 = _context3["catch"](7);
|
|
3683
|
+
_response9 = {
|
|
3626
3684
|
success: false,
|
|
3627
3685
|
message: _t5.message
|
|
3628
3686
|
};
|
|
3629
|
-
return _context3.abrupt("return", c.json(
|
|
3630
|
-
case 8:
|
|
3631
|
-
_context3.next = 9;
|
|
3632
|
-
return dynamicTableService.updateData(tableName, id, normalizedUpdateData);
|
|
3687
|
+
return _context3.abrupt("return", c.json(_response9, 200));
|
|
3633
3688
|
case 9:
|
|
3689
|
+
_context3.next = 10;
|
|
3690
|
+
return dynamicTableService.updateData(tableName, id, updateData);
|
|
3691
|
+
case 10:
|
|
3634
3692
|
result = _context3.sent;
|
|
3635
3693
|
if (result) {
|
|
3636
|
-
_context3.next =
|
|
3694
|
+
_context3.next = 11;
|
|
3637
3695
|
break;
|
|
3638
3696
|
}
|
|
3639
|
-
|
|
3697
|
+
_response0 = {
|
|
3640
3698
|
success: false,
|
|
3641
3699
|
message: "数据不存在或更新失败"
|
|
3642
3700
|
};
|
|
3643
|
-
return _context3.abrupt("return", c.json(
|
|
3644
|
-
case
|
|
3701
|
+
return _context3.abrupt("return", c.json(_response0, 200));
|
|
3702
|
+
case 11:
|
|
3645
3703
|
response = {
|
|
3646
3704
|
success: true,
|
|
3647
3705
|
message: "数据更新成功",
|
|
3648
3706
|
data: result
|
|
3649
3707
|
};
|
|
3650
3708
|
return _context3.abrupt("return", c.json(response));
|
|
3651
|
-
case
|
|
3652
|
-
_context3.prev =
|
|
3709
|
+
case 12:
|
|
3710
|
+
_context3.prev = 12;
|
|
3653
3711
|
_t6 = _context3["catch"](0);
|
|
3654
3712
|
console.error("更新数据失败:", _t6);
|
|
3655
|
-
|
|
3713
|
+
_response1 = {
|
|
3656
3714
|
success: false,
|
|
3657
3715
|
message: "更新数据失败",
|
|
3658
3716
|
error: _t6.message
|
|
3659
3717
|
};
|
|
3660
|
-
return _context3.abrupt("return", c.json(
|
|
3661
|
-
case
|
|
3718
|
+
return _context3.abrupt("return", c.json(_response1, 500));
|
|
3719
|
+
case 13:
|
|
3662
3720
|
case "end":
|
|
3663
3721
|
return _context3.stop();
|
|
3664
3722
|
}
|
|
3665
|
-
}, _callee3, null, [[0,
|
|
3723
|
+
}, _callee3, null, [[0, 12], [7, 8]]);
|
|
3666
3724
|
}));
|
|
3667
3725
|
return _updateTableData.apply(this, arguments);
|
|
3668
3726
|
}
|
|
@@ -3672,7 +3730,7 @@ function deleteTableData(_x7, _x8) {
|
|
|
3672
3730
|
// GET - 获取关联表选项列表 (用于下拉选择)
|
|
3673
3731
|
function _deleteTableData() {
|
|
3674
3732
|
_deleteTableData = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(c, tableName) {
|
|
3675
|
-
var dynamicTableService, id,
|
|
3733
|
+
var dynamicTableService, id, _response10, recordId, _response11, existingData, _response12, result, response, _response13, _t7;
|
|
3676
3734
|
return _regeneratorRuntime.wrap(function (_context4) {
|
|
3677
3735
|
while (1) switch (_context4.prev = _context4.next) {
|
|
3678
3736
|
case 0:
|
|
@@ -3683,29 +3741,40 @@ function _deleteTableData() {
|
|
|
3683
3741
|
_context4.next = 1;
|
|
3684
3742
|
break;
|
|
3685
3743
|
}
|
|
3686
|
-
|
|
3744
|
+
_response10 = {
|
|
3687
3745
|
success: false,
|
|
3688
3746
|
message: "缺少数据 ID"
|
|
3689
3747
|
};
|
|
3690
|
-
return _context4.abrupt("return", c.json(
|
|
3748
|
+
return _context4.abrupt("return", c.json(_response10, 200));
|
|
3691
3749
|
case 1:
|
|
3692
|
-
|
|
3693
|
-
|
|
3750
|
+
recordId = parseId(String(id));
|
|
3751
|
+
if (!(recordId === null || String(recordId).trim().toLowerCase() === "nan")) {
|
|
3752
|
+
_context4.next = 2;
|
|
3753
|
+
break;
|
|
3754
|
+
}
|
|
3755
|
+
_response11 = {
|
|
3756
|
+
success: false,
|
|
3757
|
+
message: "数据 ID 不合法"
|
|
3758
|
+
};
|
|
3759
|
+
return _context4.abrupt("return", c.json(_response11, 200));
|
|
3694
3760
|
case 2:
|
|
3761
|
+
_context4.next = 3;
|
|
3762
|
+
return dynamicTableService.getDataById(tableName, recordId);
|
|
3763
|
+
case 3:
|
|
3695
3764
|
existingData = _context4.sent;
|
|
3696
3765
|
if (existingData) {
|
|
3697
|
-
_context4.next =
|
|
3766
|
+
_context4.next = 4;
|
|
3698
3767
|
break;
|
|
3699
3768
|
}
|
|
3700
|
-
|
|
3769
|
+
_response12 = {
|
|
3701
3770
|
success: false,
|
|
3702
3771
|
message: "数据不存在"
|
|
3703
3772
|
};
|
|
3704
|
-
return _context4.abrupt("return", c.json(
|
|
3705
|
-
case 3:
|
|
3706
|
-
_context4.next = 4;
|
|
3707
|
-
return dynamicTableService.deleteData(tableName, parseInt(id));
|
|
3773
|
+
return _context4.abrupt("return", c.json(_response12, 200));
|
|
3708
3774
|
case 4:
|
|
3775
|
+
_context4.next = 5;
|
|
3776
|
+
return dynamicTableService.deleteData(tableName, recordId);
|
|
3777
|
+
case 5:
|
|
3709
3778
|
result = _context4.sent;
|
|
3710
3779
|
response = {
|
|
3711
3780
|
success: true,
|
|
@@ -3713,21 +3782,21 @@ function _deleteTableData() {
|
|
|
3713
3782
|
data: result
|
|
3714
3783
|
};
|
|
3715
3784
|
return _context4.abrupt("return", c.json(response));
|
|
3716
|
-
case
|
|
3717
|
-
_context4.prev =
|
|
3785
|
+
case 6:
|
|
3786
|
+
_context4.prev = 6;
|
|
3718
3787
|
_t7 = _context4["catch"](0);
|
|
3719
3788
|
console.error("删除数据失败:", _t7);
|
|
3720
|
-
|
|
3789
|
+
_response13 = {
|
|
3721
3790
|
success: false,
|
|
3722
3791
|
message: "删除数据失败",
|
|
3723
3792
|
error: _t7.message
|
|
3724
3793
|
};
|
|
3725
|
-
return _context4.abrupt("return", c.json(
|
|
3726
|
-
case
|
|
3794
|
+
return _context4.abrupt("return", c.json(_response13, 500));
|
|
3795
|
+
case 7:
|
|
3727
3796
|
case "end":
|
|
3728
3797
|
return _context4.stop();
|
|
3729
3798
|
}
|
|
3730
|
-
}, _callee4, null, [[0,
|
|
3799
|
+
}, _callee4, null, [[0, 6]]);
|
|
3731
3800
|
}));
|
|
3732
3801
|
return _deleteTableData.apply(this, arguments);
|
|
3733
3802
|
}
|
|
@@ -3737,7 +3806,7 @@ function getRelationOptions(_x9, _x0) {
|
|
|
3737
3806
|
// GET - 获取表数据(带关联数据)
|
|
3738
3807
|
function _getRelationOptions() {
|
|
3739
3808
|
_getRelationOptions = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5(c, tableName) {
|
|
3740
|
-
var dynamicTableService, displayField, limit, search, params, options, response,
|
|
3809
|
+
var dynamicTableService, displayField, limit, search, params, options, response, _response14, _t8;
|
|
3741
3810
|
return _regeneratorRuntime.wrap(function (_context5) {
|
|
3742
3811
|
while (1) switch (_context5.prev = _context5.next) {
|
|
3743
3812
|
case 0:
|
|
@@ -3765,12 +3834,12 @@ function _getRelationOptions() {
|
|
|
3765
3834
|
_context5.prev = 2;
|
|
3766
3835
|
_t8 = _context5["catch"](0);
|
|
3767
3836
|
console.error("获取关联选项失败:", _t8);
|
|
3768
|
-
|
|
3837
|
+
_response14 = {
|
|
3769
3838
|
success: false,
|
|
3770
3839
|
message: "获取关联选项失败",
|
|
3771
3840
|
error: _t8.message
|
|
3772
3841
|
};
|
|
3773
|
-
return _context5.abrupt("return", c.json(
|
|
3842
|
+
return _context5.abrupt("return", c.json(_response14, 500));
|
|
3774
3843
|
case 3:
|
|
3775
3844
|
case "end":
|
|
3776
3845
|
return _context5.stop();
|
|
@@ -3786,7 +3855,7 @@ function getTableDataWithRelations(_x1, _x10) {
|
|
|
3786
3855
|
// 用于解决外键约束引用错误表的问题
|
|
3787
3856
|
function _getTableDataWithRelations() {
|
|
3788
3857
|
_getTableDataWithRelations = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6(c, tableName) {
|
|
3789
|
-
var dynamicTableService, cmsModelService, page, limit, model, result, response, hasRelations, _result,
|
|
3858
|
+
var dynamicTableService, cmsModelService, page, limit, model, result, response, hasRelations, _result, _response15, _result2, _response16, _response17, _t9;
|
|
3790
3859
|
return _regeneratorRuntime.wrap(function (_context6) {
|
|
3791
3860
|
while (1) switch (_context6.prev = _context6.next) {
|
|
3792
3861
|
case 0:
|
|
@@ -3825,21 +3894,21 @@ function _getTableDataWithRelations() {
|
|
|
3825
3894
|
return dynamicTableService.getTableDataWithRelations(tableName, model.json_schema.fields, page, limit);
|
|
3826
3895
|
case 4:
|
|
3827
3896
|
_result = _context6.sent;
|
|
3828
|
-
|
|
3897
|
+
_response15 = {
|
|
3829
3898
|
success: true,
|
|
3830
3899
|
data: _result
|
|
3831
3900
|
};
|
|
3832
|
-
return _context6.abrupt("return", c.json(
|
|
3901
|
+
return _context6.abrupt("return", c.json(_response15, 200));
|
|
3833
3902
|
case 5:
|
|
3834
3903
|
_context6.next = 6;
|
|
3835
3904
|
return dynamicTableService.getTableData(tableName, page, limit);
|
|
3836
3905
|
case 6:
|
|
3837
3906
|
_result2 = _context6.sent;
|
|
3838
|
-
|
|
3907
|
+
_response16 = {
|
|
3839
3908
|
success: true,
|
|
3840
3909
|
data: _result2
|
|
3841
3910
|
};
|
|
3842
|
-
return _context6.abrupt("return", c.json(
|
|
3911
|
+
return _context6.abrupt("return", c.json(_response16, 200));
|
|
3843
3912
|
case 7:
|
|
3844
3913
|
_context6.next = 9;
|
|
3845
3914
|
break;
|
|
@@ -3847,12 +3916,12 @@ function _getTableDataWithRelations() {
|
|
|
3847
3916
|
_context6.prev = 8;
|
|
3848
3917
|
_t9 = _context6["catch"](0);
|
|
3849
3918
|
console.error("获取关联数据失败:", _t9);
|
|
3850
|
-
|
|
3919
|
+
_response17 = {
|
|
3851
3920
|
success: false,
|
|
3852
3921
|
message: "获取关联数据失败",
|
|
3853
3922
|
error: _t9.message
|
|
3854
3923
|
};
|
|
3855
|
-
return _context6.abrupt("return", c.json(
|
|
3924
|
+
return _context6.abrupt("return", c.json(_response17, 500));
|
|
3856
3925
|
case 9:
|
|
3857
3926
|
case "end":
|
|
3858
3927
|
return _context6.stop();
|
|
@@ -3866,7 +3935,7 @@ function dropForeignKeys(_x11, _x12) {
|
|
|
3866
3935
|
}
|
|
3867
3936
|
function _dropForeignKeys() {
|
|
3868
3937
|
_dropForeignKeys = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee7(c, tableName) {
|
|
3869
|
-
var dynamicTableService, result, response,
|
|
3938
|
+
var dynamicTableService, result, response, _response18, _response19, _t0;
|
|
3870
3939
|
return _regeneratorRuntime.wrap(function (_context7) {
|
|
3871
3940
|
while (1) switch (_context7.prev = _context7.next) {
|
|
3872
3941
|
case 0:
|
|
@@ -3886,11 +3955,11 @@ function _dropForeignKeys() {
|
|
|
3886
3955
|
};
|
|
3887
3956
|
return _context7.abrupt("return", c.json(response, 200));
|
|
3888
3957
|
case 2:
|
|
3889
|
-
|
|
3958
|
+
_response18 = {
|
|
3890
3959
|
success: false,
|
|
3891
3960
|
message: "删除外键约束失败"
|
|
3892
3961
|
};
|
|
3893
|
-
return _context7.abrupt("return", c.json(
|
|
3962
|
+
return _context7.abrupt("return", c.json(_response18, 500));
|
|
3894
3963
|
case 3:
|
|
3895
3964
|
_context7.next = 5;
|
|
3896
3965
|
break;
|
|
@@ -3898,12 +3967,12 @@ function _dropForeignKeys() {
|
|
|
3898
3967
|
_context7.prev = 4;
|
|
3899
3968
|
_t0 = _context7["catch"](0);
|
|
3900
3969
|
console.error("删除外键约束失败:", _t0);
|
|
3901
|
-
|
|
3970
|
+
_response19 = {
|
|
3902
3971
|
success: false,
|
|
3903
3972
|
message: "删除外键约束失败",
|
|
3904
3973
|
error: _t0.message
|
|
3905
3974
|
};
|
|
3906
|
-
return _context7.abrupt("return", c.json(
|
|
3975
|
+
return _context7.abrupt("return", c.json(_response19, 500));
|
|
3907
3976
|
case 5:
|
|
3908
3977
|
case "end":
|
|
3909
3978
|
return _context7.stop();
|