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