@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.js CHANGED
@@ -6652,37 +6652,6 @@ function buildFieldStatus(values) {
6652
6652
  }];
6653
6653
  }));
6654
6654
  }
6655
- function ensureConfigsTable(_x) {
6656
- return _ensureConfigsTable.apply(this, arguments);
6657
- }
6658
- function _ensureConfigsTable() {
6659
- _ensureConfigsTable = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(tableName) {
6660
- var supabase, createTableSQL, _yield$supabase$rpc, error;
6661
- return _regeneratorRuntime.wrap(function (_context) {
6662
- while (1) switch (_context.prev = _context.next) {
6663
- case 0:
6664
- supabase = getSupabase();
6665
- 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 ");
6666
- _context.next = 1;
6667
- return supabase.rpc("execute_sql", {
6668
- sql_query: createTableSQL
6669
- });
6670
- case 1:
6671
- _yield$supabase$rpc = _context.sent;
6672
- error = _yield$supabase$rpc.error;
6673
- if (!error) {
6674
- _context.next = 2;
6675
- break;
6676
- }
6677
- throw error;
6678
- case 2:
6679
- case "end":
6680
- return _context.stop();
6681
- }
6682
- }, _callee);
6683
- }));
6684
- return _ensureConfigsTable.apply(this, arguments);
6685
- }
6686
6655
  function validateNamespace(namespace) {
6687
6656
  if (!namespace) return "缺少 namespace";
6688
6657
  if (!CONFIG_NAMESPACE_RE.test(namespace)) {
@@ -6736,29 +6705,26 @@ function _getConfig() {
6736
6705
  return _context2.abrupt("return", c.json(_response2, 200));
6737
6706
  case 2:
6738
6707
  tableName = getConfigsTableName(sessionId);
6739
- _context2.next = 3;
6740
- return ensureConfigsTable(tableName);
6741
- case 3:
6742
6708
  supabase = getSupabase();
6743
- _context2.next = 4;
6709
+ _context2.next = 3;
6744
6710
  return supabase.from(tableName).select("*").eq("namespace", namespace).maybeSingle();
6745
- case 4:
6711
+ case 3:
6746
6712
  _yield$supabase$from$ = _context2.sent;
6747
6713
  data = _yield$supabase$from$.data;
6748
6714
  error = _yield$supabase$from$.error;
6749
6715
  if (!error) {
6750
- _context2.next = 5;
6716
+ _context2.next = 4;
6751
6717
  break;
6752
6718
  }
6753
6719
  throw error;
6754
- case 5:
6720
+ case 4:
6755
6721
  response = {
6756
6722
  success: true,
6757
6723
  data: toConfigResponse(data, namespace)
6758
6724
  };
6759
6725
  return _context2.abrupt("return", c.json(response, 200));
6760
- case 6:
6761
- _context2.prev = 6;
6726
+ case 5:
6727
+ _context2.prev = 5;
6762
6728
  _t = _context2["catch"](0);
6763
6729
  console.error("获取配置失败:", _t);
6764
6730
  _response3 = {
@@ -6767,11 +6733,11 @@ function _getConfig() {
6767
6733
  error: _t.message
6768
6734
  };
6769
6735
  return _context2.abrupt("return", c.json(_response3, 500));
6770
- case 7:
6736
+ case 6:
6771
6737
  case "end":
6772
6738
  return _context2.stop();
6773
6739
  }
6774
- }, _callee2, null, [[0, 6]]);
6740
+ }, _callee2, null, [[0, 5]]);
6775
6741
  }));
6776
6742
  return _getConfig.apply(this, arguments);
6777
6743
  }
@@ -6815,24 +6781,21 @@ function _updateConfig() {
6815
6781
  return _context3.abrupt("return", c.json(_response5, 200));
6816
6782
  case 3:
6817
6783
  tableName = getConfigsTableName(sessionId);
6818
- _context3.next = 4;
6819
- return ensureConfigsTable(tableName);
6820
- case 4:
6821
6784
  supabase = getSupabase();
6822
- _context3.next = 5;
6785
+ _context3.next = 4;
6823
6786
  return supabase.from(tableName).select("values").eq("namespace", namespace).maybeSingle();
6824
- case 5:
6787
+ case 4:
6825
6788
  _yield$supabase$from$2 = _context3.sent;
6826
6789
  existing = _yield$supabase$from$2.data;
6827
6790
  existingError = _yield$supabase$from$2.error;
6828
6791
  if (!existingError) {
6829
- _context3.next = 6;
6792
+ _context3.next = 5;
6830
6793
  break;
6831
6794
  }
6832
6795
  throw existingError;
6833
- case 6:
6796
+ case 5:
6834
6797
  nextValues = _objectSpread(_objectSpread({}, normalizeValues(existing === null || existing === void 0 ? void 0 : existing.values)), values);
6835
- _context3.next = 7;
6798
+ _context3.next = 6;
6836
6799
  return supabase.from(tableName).upsert({
6837
6800
  namespace: namespace,
6838
6801
  values: nextValues,
@@ -6840,24 +6803,24 @@ function _updateConfig() {
6840
6803
  }, {
6841
6804
  onConflict: "namespace"
6842
6805
  }).select("*").single();
6843
- case 7:
6806
+ case 6:
6844
6807
  _yield$supabase$from$3 = _context3.sent;
6845
6808
  data = _yield$supabase$from$3.data;
6846
6809
  error = _yield$supabase$from$3.error;
6847
6810
  if (!error) {
6848
- _context3.next = 8;
6811
+ _context3.next = 7;
6849
6812
  break;
6850
6813
  }
6851
6814
  throw error;
6852
- case 8:
6815
+ case 7:
6853
6816
  response = {
6854
6817
  success: true,
6855
6818
  message: "配置保存成功",
6856
6819
  data: toConfigResponse(data, namespace)
6857
6820
  };
6858
6821
  return _context3.abrupt("return", c.json(response, 200));
6859
- case 9:
6860
- _context3.prev = 9;
6822
+ case 8:
6823
+ _context3.prev = 8;
6861
6824
  _t2 = _context3["catch"](0);
6862
6825
  console.error("保存配置失败:", _t2);
6863
6826
  _response6 = {
@@ -6866,11 +6829,11 @@ function _updateConfig() {
6866
6829
  error: _t2.message
6867
6830
  };
6868
6831
  return _context3.abrupt("return", c.json(_response6, 500));
6869
- case 10:
6832
+ case 9:
6870
6833
  case "end":
6871
6834
  return _context3.stop();
6872
6835
  }
6873
- }, _callee3, null, [[0, 9]]);
6836
+ }, _callee3, null, [[0, 8]]);
6874
6837
  }));
6875
6838
  return _updateConfig.apply(this, arguments);
6876
6839
  }