@wecode-team/cms-supabase-api 0.1.46 → 0.1.47

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
@@ -6634,7 +6634,7 @@ function validateConfigSessionId(sessionId) {
6634
6634
  return null;
6635
6635
  }
6636
6636
  function getConfigsTableName(sessionId) {
6637
- return "".concat(sessionId, "__config__");
6637
+ return "".concat(sessionId.replace('-', '_'), "__config__");
6638
6638
  }
6639
6639
  function normalizeValues(values) {
6640
6640
  if (!values || _typeof$1(values) !== "object" || Array.isArray(values)) {
@@ -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)) {
@@ -6701,138 +6670,132 @@ function toConfigResponse(row, fallbackNamespace) {
6701
6670
  updated_at: row === null || row === void 0 ? void 0 : row.updated_at
6702
6671
  };
6703
6672
  }
6704
- function getConfig(_x2) {
6673
+ function getConfig(_x) {
6705
6674
  return _getConfig.apply(this, arguments);
6706
6675
  }
6707
6676
  function _getConfig() {
6708
- _getConfig = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(c) {
6677
+ _getConfig = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(c) {
6709
6678
  var namespace, namespaceError, _response, sessionId, sessionError, _response2, tableName, supabase, _yield$supabase$from$, data, error, response, _response3, _t;
6710
- return _regeneratorRuntime.wrap(function (_context2) {
6711
- while (1) switch (_context2.prev = _context2.next) {
6679
+ return _regeneratorRuntime.wrap(function (_context) {
6680
+ while (1) switch (_context.prev = _context.next) {
6712
6681
  case 0:
6713
- _context2.prev = 0;
6682
+ _context.prev = 0;
6714
6683
  namespace = (c.req.query("namespace") || "").trim();
6715
6684
  namespaceError = validateNamespace(namespace);
6716
6685
  if (!namespaceError) {
6717
- _context2.next = 1;
6686
+ _context.next = 1;
6718
6687
  break;
6719
6688
  }
6720
6689
  _response = {
6721
6690
  success: false,
6722
6691
  message: namespaceError
6723
6692
  };
6724
- return _context2.abrupt("return", c.json(_response, 200));
6693
+ return _context.abrupt("return", c.json(_response, 200));
6725
6694
  case 1:
6726
6695
  sessionId = getConfigSessionId(c);
6727
6696
  sessionError = validateConfigSessionId(sessionId);
6728
6697
  if (!sessionError) {
6729
- _context2.next = 2;
6698
+ _context.next = 2;
6730
6699
  break;
6731
6700
  }
6732
6701
  _response2 = {
6733
6702
  success: false,
6734
6703
  message: sessionError
6735
6704
  };
6736
- return _context2.abrupt("return", c.json(_response2, 200));
6705
+ return _context.abrupt("return", c.json(_response2, 200));
6737
6706
  case 2:
6738
- tableName = getConfigsTableName(sessionId);
6739
- _context2.next = 3;
6740
- return ensureConfigsTable(tableName);
6741
- case 3:
6707
+ tableName = getConfigsTableName(sessionId); // await ensureConfigsTable(tableName)
6742
6708
  supabase = getSupabase();
6743
- _context2.next = 4;
6709
+ _context.next = 3;
6744
6710
  return supabase.from(tableName).select("*").eq("namespace", namespace).maybeSingle();
6745
- case 4:
6746
- _yield$supabase$from$ = _context2.sent;
6711
+ case 3:
6712
+ _yield$supabase$from$ = _context.sent;
6747
6713
  data = _yield$supabase$from$.data;
6748
6714
  error = _yield$supabase$from$.error;
6749
6715
  if (!error) {
6750
- _context2.next = 5;
6716
+ _context.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
- return _context2.abrupt("return", c.json(response, 200));
6760
- case 6:
6761
- _context2.prev = 6;
6762
- _t = _context2["catch"](0);
6725
+ return _context.abrupt("return", c.json(response, 200));
6726
+ case 5:
6727
+ _context.prev = 5;
6728
+ _t = _context["catch"](0);
6763
6729
  console.error("获取配置失败:", _t);
6764
6730
  _response3 = {
6765
6731
  success: false,
6766
6732
  message: "获取配置失败",
6767
6733
  error: _t.message
6768
6734
  };
6769
- return _context2.abrupt("return", c.json(_response3, 500));
6770
- case 7:
6735
+ return _context.abrupt("return", c.json(_response3, 500));
6736
+ case 6:
6771
6737
  case "end":
6772
- return _context2.stop();
6738
+ return _context.stop();
6773
6739
  }
6774
- }, _callee2, null, [[0, 6]]);
6740
+ }, _callee, null, [[0, 5]]);
6775
6741
  }));
6776
6742
  return _getConfig.apply(this, arguments);
6777
6743
  }
6778
- function updateConfig(_x3) {
6744
+ function updateConfig(_x2) {
6779
6745
  return _updateConfig.apply(this, arguments);
6780
6746
  }
6781
6747
  function _updateConfig() {
6782
- _updateConfig = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(c) {
6748
+ _updateConfig = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(c) {
6783
6749
  var namespace, namespaceError, _response4, body, values, sessionId, sessionError, _response5, tableName, supabase, _yield$supabase$from$2, existing, existingError, nextValues, _yield$supabase$from$3, data, error, response, _response6, _t2;
6784
- return _regeneratorRuntime.wrap(function (_context3) {
6785
- while (1) switch (_context3.prev = _context3.next) {
6750
+ return _regeneratorRuntime.wrap(function (_context2) {
6751
+ while (1) switch (_context2.prev = _context2.next) {
6786
6752
  case 0:
6787
- _context3.prev = 0;
6753
+ _context2.prev = 0;
6788
6754
  namespace = (c.req.param("namespace") || "").trim();
6789
6755
  namespaceError = validateNamespace(namespace);
6790
6756
  if (!namespaceError) {
6791
- _context3.next = 1;
6757
+ _context2.next = 1;
6792
6758
  break;
6793
6759
  }
6794
6760
  _response4 = {
6795
6761
  success: false,
6796
6762
  message: namespaceError
6797
6763
  };
6798
- return _context3.abrupt("return", c.json(_response4, 200));
6764
+ return _context2.abrupt("return", c.json(_response4, 200));
6799
6765
  case 1:
6800
- _context3.next = 2;
6766
+ _context2.next = 2;
6801
6767
  return c.req.json();
6802
6768
  case 2:
6803
- body = _context3.sent;
6769
+ body = _context2.sent;
6804
6770
  values = normalizeValues(body === null || body === void 0 ? void 0 : body.values);
6805
6771
  sessionId = getConfigSessionId(c);
6806
6772
  sessionError = validateConfigSessionId(sessionId);
6807
6773
  if (!sessionError) {
6808
- _context3.next = 3;
6774
+ _context2.next = 3;
6809
6775
  break;
6810
6776
  }
6811
6777
  _response5 = {
6812
6778
  success: false,
6813
6779
  message: sessionError
6814
6780
  };
6815
- return _context3.abrupt("return", c.json(_response5, 200));
6781
+ return _context2.abrupt("return", c.json(_response5, 200));
6816
6782
  case 3:
6817
- tableName = getConfigsTableName(sessionId);
6818
- _context3.next = 4;
6819
- return ensureConfigsTable(tableName);
6820
- case 4:
6783
+ tableName = getConfigsTableName(sessionId); // await ensureConfigsTable(tableName)
6821
6784
  supabase = getSupabase();
6822
- _context3.next = 5;
6785
+ _context2.next = 4;
6823
6786
  return supabase.from(tableName).select("values").eq("namespace", namespace).maybeSingle();
6824
- case 5:
6825
- _yield$supabase$from$2 = _context3.sent;
6787
+ case 4:
6788
+ _yield$supabase$from$2 = _context2.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
+ _context2.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
+ _context2.next = 6;
6836
6799
  return supabase.from(tableName).upsert({
6837
6800
  namespace: namespace,
6838
6801
  values: nextValues,
@@ -6840,37 +6803,37 @@ function _updateConfig() {
6840
6803
  }, {
6841
6804
  onConflict: "namespace"
6842
6805
  }).select("*").single();
6843
- case 7:
6844
- _yield$supabase$from$3 = _context3.sent;
6806
+ case 6:
6807
+ _yield$supabase$from$3 = _context2.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
+ _context2.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
- return _context3.abrupt("return", c.json(response, 200));
6859
- case 9:
6860
- _context3.prev = 9;
6861
- _t2 = _context3["catch"](0);
6821
+ return _context2.abrupt("return", c.json(response, 200));
6822
+ case 8:
6823
+ _context2.prev = 8;
6824
+ _t2 = _context2["catch"](0);
6862
6825
  console.error("保存配置失败:", _t2);
6863
6826
  _response6 = {
6864
6827
  success: false,
6865
6828
  message: "保存配置失败",
6866
6829
  error: _t2.message
6867
6830
  };
6868
- return _context3.abrupt("return", c.json(_response6, 500));
6869
- case 10:
6831
+ return _context2.abrupt("return", c.json(_response6, 500));
6832
+ case 9:
6870
6833
  case "end":
6871
- return _context3.stop();
6834
+ return _context2.stop();
6872
6835
  }
6873
- }, _callee3, null, [[0, 9]]);
6836
+ }, _callee2, null, [[0, 8]]);
6874
6837
  }));
6875
6838
  return _updateConfig.apply(this, arguments);
6876
6839
  }