@wecode-team/cms-supabase-api 0.1.29 → 0.1.30

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.js CHANGED
@@ -3557,7 +3557,7 @@ function updateTableData(_x5, _x6) {
3557
3557
  // DELETE - 删除数据
3558
3558
  function _updateTableData() {
3559
3559
  _updateTableData = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(c, tableName) {
3560
- 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;
3560
+ 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, normalizedUpdateData, _response9, result, _response0, response, _response1, _t5, _t6;
3561
3561
  return _regeneratorRuntime.wrap(function (_context3) {
3562
3562
  while (1) switch (_context3.prev = _context3.next) {
3563
3563
  case 0:
@@ -3580,20 +3580,30 @@ function _updateTableData() {
3580
3580
  };
3581
3581
  return _context3.abrupt("return", c.json(_response6, 200));
3582
3582
  case 2:
3583
- _context3.next = 3;
3584
- return dynamicTableService.getDataById(tableName, recordId);
3583
+ if (!(String(recordId).trim().toLowerCase() === "nan")) {
3584
+ _context3.next = 3;
3585
+ break;
3586
+ }
3587
+ _response7 = {
3588
+ success: false,
3589
+ message: "数据 ID 不合法"
3590
+ };
3591
+ return _context3.abrupt("return", c.json(_response7, 200));
3585
3592
  case 3:
3593
+ _context3.next = 4;
3594
+ return dynamicTableService.getDataById(tableName, recordId);
3595
+ case 4:
3586
3596
  existingData = _context3.sent;
3587
3597
  if (existingData) {
3588
- _context3.next = 4;
3598
+ _context3.next = 5;
3589
3599
  break;
3590
3600
  }
3591
- _response7 = {
3601
+ _response8 = {
3592
3602
  success: false,
3593
3603
  message: "数据不存在"
3594
3604
  };
3595
- return _context3.abrupt("return", c.json(_response7, 200));
3596
- case 4:
3605
+ return _context3.abrupt("return", c.json(_response8, 200));
3606
+ case 5:
3597
3607
  // 过滤掉系统字段
3598
3608
  data.created_at, data.updated_at, rawUpdateData = _objectWithoutProperties(data, _excluded3); // 过滤掉空字符串值,避免违反 CHECK 约束
3599
3609
  // 注意:更新时允许 null 值(用于清空字段),但不允许空字符串
@@ -3606,63 +3616,63 @@ function _updateTableData() {
3606
3616
  }
3607
3617
  }
3608
3618
  // 处理 json/jsonb 字段:允许前端传 JSON 字符串
3609
- _context3.next = 5;
3619
+ _context3.next = 6;
3610
3620
  return cmsModelService.findByTableName(tableName);
3611
- case 5:
3621
+ case 6:
3612
3622
  model = _context3.sent;
3613
3623
  normalizedUpdateData = updateData;
3614
3624
  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 = 8;
3625
+ _context3.next = 9;
3616
3626
  break;
3617
3627
  }
3618
- _context3.prev = 6;
3628
+ _context3.prev = 7;
3619
3629
  normalizedUpdateData = normalizeJsonLikeFields(model.json_schema.fields, updateData);
3620
- _context3.next = 8;
3630
+ _context3.next = 9;
3621
3631
  break;
3622
- case 7:
3623
- _context3.prev = 7;
3624
- _t5 = _context3["catch"](6);
3625
- _response8 = {
3632
+ case 8:
3633
+ _context3.prev = 8;
3634
+ _t5 = _context3["catch"](7);
3635
+ _response9 = {
3626
3636
  success: false,
3627
3637
  message: _t5.message
3628
3638
  };
3629
- return _context3.abrupt("return", c.json(_response8, 200));
3630
- case 8:
3631
- _context3.next = 9;
3632
- return dynamicTableService.updateData(tableName, id, normalizedUpdateData);
3639
+ return _context3.abrupt("return", c.json(_response9, 200));
3633
3640
  case 9:
3641
+ _context3.next = 10;
3642
+ return dynamicTableService.updateData(tableName, recordId, normalizedUpdateData);
3643
+ case 10:
3634
3644
  result = _context3.sent;
3635
3645
  if (result) {
3636
- _context3.next = 10;
3646
+ _context3.next = 11;
3637
3647
  break;
3638
3648
  }
3639
- _response9 = {
3649
+ _response0 = {
3640
3650
  success: false,
3641
3651
  message: "数据不存在或更新失败"
3642
3652
  };
3643
- return _context3.abrupt("return", c.json(_response9, 200));
3644
- case 10:
3653
+ return _context3.abrupt("return", c.json(_response0, 200));
3654
+ case 11:
3645
3655
  response = {
3646
3656
  success: true,
3647
3657
  message: "数据更新成功",
3648
3658
  data: result
3649
3659
  };
3650
3660
  return _context3.abrupt("return", c.json(response));
3651
- case 11:
3652
- _context3.prev = 11;
3661
+ case 12:
3662
+ _context3.prev = 12;
3653
3663
  _t6 = _context3["catch"](0);
3654
3664
  console.error("更新数据失败:", _t6);
3655
- _response0 = {
3665
+ _response1 = {
3656
3666
  success: false,
3657
3667
  message: "更新数据失败",
3658
3668
  error: _t6.message
3659
3669
  };
3660
- return _context3.abrupt("return", c.json(_response0, 500));
3661
- case 12:
3670
+ return _context3.abrupt("return", c.json(_response1, 500));
3671
+ case 13:
3662
3672
  case "end":
3663
3673
  return _context3.stop();
3664
3674
  }
3665
- }, _callee3, null, [[0, 11], [6, 7]]);
3675
+ }, _callee3, null, [[0, 12], [7, 8]]);
3666
3676
  }));
3667
3677
  return _updateTableData.apply(this, arguments);
3668
3678
  }
@@ -3672,7 +3682,7 @@ function deleteTableData(_x7, _x8) {
3672
3682
  // GET - 获取关联表选项列表 (用于下拉选择)
3673
3683
  function _deleteTableData() {
3674
3684
  _deleteTableData = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(c, tableName) {
3675
- var dynamicTableService, id, _response1, existingData, _response10, result, response, _response11, _t7;
3685
+ var dynamicTableService, id, _response10, recordId, _response11, existingData, _response12, result, response, _response13, _t7;
3676
3686
  return _regeneratorRuntime.wrap(function (_context4) {
3677
3687
  while (1) switch (_context4.prev = _context4.next) {
3678
3688
  case 0:
@@ -3683,29 +3693,40 @@ function _deleteTableData() {
3683
3693
  _context4.next = 1;
3684
3694
  break;
3685
3695
  }
3686
- _response1 = {
3696
+ _response10 = {
3687
3697
  success: false,
3688
3698
  message: "缺少数据 ID"
3689
3699
  };
3690
- return _context4.abrupt("return", c.json(_response1, 200));
3700
+ return _context4.abrupt("return", c.json(_response10, 200));
3691
3701
  case 1:
3692
- _context4.next = 2;
3693
- return dynamicTableService.getDataById(tableName, parseInt(id));
3702
+ recordId = parseId(String(id));
3703
+ if (!(recordId === null || String(recordId).trim().toLowerCase() === "nan")) {
3704
+ _context4.next = 2;
3705
+ break;
3706
+ }
3707
+ _response11 = {
3708
+ success: false,
3709
+ message: "数据 ID 不合法"
3710
+ };
3711
+ return _context4.abrupt("return", c.json(_response11, 200));
3694
3712
  case 2:
3713
+ _context4.next = 3;
3714
+ return dynamicTableService.getDataById(tableName, recordId);
3715
+ case 3:
3695
3716
  existingData = _context4.sent;
3696
3717
  if (existingData) {
3697
- _context4.next = 3;
3718
+ _context4.next = 4;
3698
3719
  break;
3699
3720
  }
3700
- _response10 = {
3721
+ _response12 = {
3701
3722
  success: false,
3702
3723
  message: "数据不存在"
3703
3724
  };
3704
- return _context4.abrupt("return", c.json(_response10, 200));
3705
- case 3:
3706
- _context4.next = 4;
3707
- return dynamicTableService.deleteData(tableName, parseInt(id));
3725
+ return _context4.abrupt("return", c.json(_response12, 200));
3708
3726
  case 4:
3727
+ _context4.next = 5;
3728
+ return dynamicTableService.deleteData(tableName, recordId);
3729
+ case 5:
3709
3730
  result = _context4.sent;
3710
3731
  response = {
3711
3732
  success: true,
@@ -3713,21 +3734,21 @@ function _deleteTableData() {
3713
3734
  data: result
3714
3735
  };
3715
3736
  return _context4.abrupt("return", c.json(response));
3716
- case 5:
3717
- _context4.prev = 5;
3737
+ case 6:
3738
+ _context4.prev = 6;
3718
3739
  _t7 = _context4["catch"](0);
3719
3740
  console.error("删除数据失败:", _t7);
3720
- _response11 = {
3741
+ _response13 = {
3721
3742
  success: false,
3722
3743
  message: "删除数据失败",
3723
3744
  error: _t7.message
3724
3745
  };
3725
- return _context4.abrupt("return", c.json(_response11, 500));
3726
- case 6:
3746
+ return _context4.abrupt("return", c.json(_response13, 500));
3747
+ case 7:
3727
3748
  case "end":
3728
3749
  return _context4.stop();
3729
3750
  }
3730
- }, _callee4, null, [[0, 5]]);
3751
+ }, _callee4, null, [[0, 6]]);
3731
3752
  }));
3732
3753
  return _deleteTableData.apply(this, arguments);
3733
3754
  }
@@ -3737,7 +3758,7 @@ function getRelationOptions(_x9, _x0) {
3737
3758
  // GET - 获取表数据(带关联数据)
3738
3759
  function _getRelationOptions() {
3739
3760
  _getRelationOptions = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5(c, tableName) {
3740
- var dynamicTableService, displayField, limit, search, params, options, response, _response12, _t8;
3761
+ var dynamicTableService, displayField, limit, search, params, options, response, _response14, _t8;
3741
3762
  return _regeneratorRuntime.wrap(function (_context5) {
3742
3763
  while (1) switch (_context5.prev = _context5.next) {
3743
3764
  case 0:
@@ -3765,12 +3786,12 @@ function _getRelationOptions() {
3765
3786
  _context5.prev = 2;
3766
3787
  _t8 = _context5["catch"](0);
3767
3788
  console.error("获取关联选项失败:", _t8);
3768
- _response12 = {
3789
+ _response14 = {
3769
3790
  success: false,
3770
3791
  message: "获取关联选项失败",
3771
3792
  error: _t8.message
3772
3793
  };
3773
- return _context5.abrupt("return", c.json(_response12, 500));
3794
+ return _context5.abrupt("return", c.json(_response14, 500));
3774
3795
  case 3:
3775
3796
  case "end":
3776
3797
  return _context5.stop();
@@ -3786,7 +3807,7 @@ function getTableDataWithRelations(_x1, _x10) {
3786
3807
  // 用于解决外键约束引用错误表的问题
3787
3808
  function _getTableDataWithRelations() {
3788
3809
  _getTableDataWithRelations = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6(c, tableName) {
3789
- var dynamicTableService, cmsModelService, page, limit, model, result, response, hasRelations, _result, _response13, _result2, _response14, _response15, _t9;
3810
+ var dynamicTableService, cmsModelService, page, limit, model, result, response, hasRelations, _result, _response15, _result2, _response16, _response17, _t9;
3790
3811
  return _regeneratorRuntime.wrap(function (_context6) {
3791
3812
  while (1) switch (_context6.prev = _context6.next) {
3792
3813
  case 0:
@@ -3825,21 +3846,21 @@ function _getTableDataWithRelations() {
3825
3846
  return dynamicTableService.getTableDataWithRelations(tableName, model.json_schema.fields, page, limit);
3826
3847
  case 4:
3827
3848
  _result = _context6.sent;
3828
- _response13 = {
3849
+ _response15 = {
3829
3850
  success: true,
3830
3851
  data: _result
3831
3852
  };
3832
- return _context6.abrupt("return", c.json(_response13, 200));
3853
+ return _context6.abrupt("return", c.json(_response15, 200));
3833
3854
  case 5:
3834
3855
  _context6.next = 6;
3835
3856
  return dynamicTableService.getTableData(tableName, page, limit);
3836
3857
  case 6:
3837
3858
  _result2 = _context6.sent;
3838
- _response14 = {
3859
+ _response16 = {
3839
3860
  success: true,
3840
3861
  data: _result2
3841
3862
  };
3842
- return _context6.abrupt("return", c.json(_response14, 200));
3863
+ return _context6.abrupt("return", c.json(_response16, 200));
3843
3864
  case 7:
3844
3865
  _context6.next = 9;
3845
3866
  break;
@@ -3847,12 +3868,12 @@ function _getTableDataWithRelations() {
3847
3868
  _context6.prev = 8;
3848
3869
  _t9 = _context6["catch"](0);
3849
3870
  console.error("获取关联数据失败:", _t9);
3850
- _response15 = {
3871
+ _response17 = {
3851
3872
  success: false,
3852
3873
  message: "获取关联数据失败",
3853
3874
  error: _t9.message
3854
3875
  };
3855
- return _context6.abrupt("return", c.json(_response15, 500));
3876
+ return _context6.abrupt("return", c.json(_response17, 500));
3856
3877
  case 9:
3857
3878
  case "end":
3858
3879
  return _context6.stop();
@@ -3866,7 +3887,7 @@ function dropForeignKeys(_x11, _x12) {
3866
3887
  }
3867
3888
  function _dropForeignKeys() {
3868
3889
  _dropForeignKeys = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee7(c, tableName) {
3869
- var dynamicTableService, result, response, _response16, _response17, _t0;
3890
+ var dynamicTableService, result, response, _response18, _response19, _t0;
3870
3891
  return _regeneratorRuntime.wrap(function (_context7) {
3871
3892
  while (1) switch (_context7.prev = _context7.next) {
3872
3893
  case 0:
@@ -3886,11 +3907,11 @@ function _dropForeignKeys() {
3886
3907
  };
3887
3908
  return _context7.abrupt("return", c.json(response, 200));
3888
3909
  case 2:
3889
- _response16 = {
3910
+ _response18 = {
3890
3911
  success: false,
3891
3912
  message: "删除外键约束失败"
3892
3913
  };
3893
- return _context7.abrupt("return", c.json(_response16, 500));
3914
+ return _context7.abrupt("return", c.json(_response18, 500));
3894
3915
  case 3:
3895
3916
  _context7.next = 5;
3896
3917
  break;
@@ -3898,12 +3919,12 @@ function _dropForeignKeys() {
3898
3919
  _context7.prev = 4;
3899
3920
  _t0 = _context7["catch"](0);
3900
3921
  console.error("删除外键约束失败:", _t0);
3901
- _response17 = {
3922
+ _response19 = {
3902
3923
  success: false,
3903
3924
  message: "删除外键约束失败",
3904
3925
  error: _t0.message
3905
3926
  };
3906
- return _context7.abrupt("return", c.json(_response17, 500));
3927
+ return _context7.abrupt("return", c.json(_response19, 500));
3907
3928
  case 5:
3908
3929
  case "end":
3909
3930
  return _context7.stop();