@wecode-team/cms-supabase-api 0.1.45-beta.0 → 0.1.45-beta.1

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
@@ -6630,37 +6630,6 @@ function buildFieldStatus(values) {
6630
6630
  }];
6631
6631
  }));
6632
6632
  }
6633
- function ensureConfigsTable(_x) {
6634
- return _ensureConfigsTable.apply(this, arguments);
6635
- }
6636
- function _ensureConfigsTable() {
6637
- _ensureConfigsTable = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(tableName) {
6638
- var supabase, createTableSQL, _yield$supabase$rpc, error;
6639
- return _regeneratorRuntime.wrap(function (_context) {
6640
- while (1) switch (_context.prev = _context.next) {
6641
- case 0:
6642
- supabase = getSupabase();
6643
- createTableSQL = "\n CREATE TABLE IF NOT EXISTS \"".concat(tableName, "\" (\n id SERIAL PRIMARY KEY,\n namespace TEXT NOT NULL UNIQUE,\n values JSONB NOT NULL DEFAULT '{}'::jsonb,\n created_at TIMESTAMPTZ DEFAULT NOW(),\n updated_at TIMESTAMPTZ DEFAULT NOW()\n );\n ");
6644
- _context.next = 1;
6645
- return supabase.rpc("execute_sql", {
6646
- sql_query: createTableSQL
6647
- });
6648
- case 1:
6649
- _yield$supabase$rpc = _context.sent;
6650
- error = _yield$supabase$rpc.error;
6651
- if (!error) {
6652
- _context.next = 2;
6653
- break;
6654
- }
6655
- throw error;
6656
- case 2:
6657
- case "end":
6658
- return _context.stop();
6659
- }
6660
- }, _callee);
6661
- }));
6662
- return _ensureConfigsTable.apply(this, arguments);
6663
- }
6664
6633
  function validateNamespace(namespace) {
6665
6634
  if (!namespace) return "缺少 namespace";
6666
6635
  if (!CONFIG_NAMESPACE_RE.test(namespace)) {
@@ -6714,29 +6683,26 @@ function _getConfig() {
6714
6683
  return _context2.abrupt("return", c.json(_response2, 200));
6715
6684
  case 2:
6716
6685
  tableName = getConfigsTableName(sessionId);
6717
- _context2.next = 3;
6718
- return ensureConfigsTable(tableName);
6719
- case 3:
6720
6686
  supabase = getSupabase();
6721
- _context2.next = 4;
6687
+ _context2.next = 3;
6722
6688
  return supabase.from(tableName).select("*").eq("namespace", namespace).maybeSingle();
6723
- case 4:
6689
+ case 3:
6724
6690
  _yield$supabase$from$ = _context2.sent;
6725
6691
  data = _yield$supabase$from$.data;
6726
6692
  error = _yield$supabase$from$.error;
6727
6693
  if (!error) {
6728
- _context2.next = 5;
6694
+ _context2.next = 4;
6729
6695
  break;
6730
6696
  }
6731
6697
  throw error;
6732
- case 5:
6698
+ case 4:
6733
6699
  response = {
6734
6700
  success: true,
6735
6701
  data: toConfigResponse(data, namespace)
6736
6702
  };
6737
6703
  return _context2.abrupt("return", c.json(response, 200));
6738
- case 6:
6739
- _context2.prev = 6;
6704
+ case 5:
6705
+ _context2.prev = 5;
6740
6706
  _t = _context2["catch"](0);
6741
6707
  console.error("获取配置失败:", _t);
6742
6708
  _response3 = {
@@ -6745,11 +6711,11 @@ function _getConfig() {
6745
6711
  error: _t.message
6746
6712
  };
6747
6713
  return _context2.abrupt("return", c.json(_response3, 500));
6748
- case 7:
6714
+ case 6:
6749
6715
  case "end":
6750
6716
  return _context2.stop();
6751
6717
  }
6752
- }, _callee2, null, [[0, 6]]);
6718
+ }, _callee2, null, [[0, 5]]);
6753
6719
  }));
6754
6720
  return _getConfig.apply(this, arguments);
6755
6721
  }
@@ -6793,24 +6759,21 @@ function _updateConfig() {
6793
6759
  return _context3.abrupt("return", c.json(_response5, 200));
6794
6760
  case 3:
6795
6761
  tableName = getConfigsTableName(sessionId);
6796
- _context3.next = 4;
6797
- return ensureConfigsTable(tableName);
6798
- case 4:
6799
6762
  supabase = getSupabase();
6800
- _context3.next = 5;
6763
+ _context3.next = 4;
6801
6764
  return supabase.from(tableName).select("values").eq("namespace", namespace).maybeSingle();
6802
- case 5:
6765
+ case 4:
6803
6766
  _yield$supabase$from$2 = _context3.sent;
6804
6767
  existing = _yield$supabase$from$2.data;
6805
6768
  existingError = _yield$supabase$from$2.error;
6806
6769
  if (!existingError) {
6807
- _context3.next = 6;
6770
+ _context3.next = 5;
6808
6771
  break;
6809
6772
  }
6810
6773
  throw existingError;
6811
- case 6:
6774
+ case 5:
6812
6775
  nextValues = _objectSpread(_objectSpread({}, normalizeValues(existing === null || existing === void 0 ? void 0 : existing.values)), values);
6813
- _context3.next = 7;
6776
+ _context3.next = 6;
6814
6777
  return supabase.from(tableName).upsert({
6815
6778
  namespace: namespace,
6816
6779
  values: nextValues,
@@ -6818,24 +6781,24 @@ function _updateConfig() {
6818
6781
  }, {
6819
6782
  onConflict: "namespace"
6820
6783
  }).select("*").single();
6821
- case 7:
6784
+ case 6:
6822
6785
  _yield$supabase$from$3 = _context3.sent;
6823
6786
  data = _yield$supabase$from$3.data;
6824
6787
  error = _yield$supabase$from$3.error;
6825
6788
  if (!error) {
6826
- _context3.next = 8;
6789
+ _context3.next = 7;
6827
6790
  break;
6828
6791
  }
6829
6792
  throw error;
6830
- case 8:
6793
+ case 7:
6831
6794
  response = {
6832
6795
  success: true,
6833
6796
  message: "配置保存成功",
6834
6797
  data: toConfigResponse(data, namespace)
6835
6798
  };
6836
6799
  return _context3.abrupt("return", c.json(response, 200));
6837
- case 9:
6838
- _context3.prev = 9;
6800
+ case 8:
6801
+ _context3.prev = 8;
6839
6802
  _t2 = _context3["catch"](0);
6840
6803
  console.error("保存配置失败:", _t2);
6841
6804
  _response6 = {
@@ -6844,11 +6807,11 @@ function _updateConfig() {
6844
6807
  error: _t2.message
6845
6808
  };
6846
6809
  return _context3.abrupt("return", c.json(_response6, 500));
6847
- case 10:
6810
+ case 9:
6848
6811
  case "end":
6849
6812
  return _context3.stop();
6850
6813
  }
6851
- }, _callee3, null, [[0, 9]]);
6814
+ }, _callee3, null, [[0, 8]]);
6852
6815
  }));
6853
6816
  return _updateConfig.apply(this, arguments);
6854
6817
  }