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