appbuild-oceanbase-console 1.10.3 → 1.11.0

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/cjs/sdk.js CHANGED
@@ -13795,6 +13795,154 @@ exports.AttributeStatus = void 0;
13795
13795
  AttributeStatus["Failed"] = "failed";
13796
13796
  })(exports.AttributeStatus || (exports.AttributeStatus = {}));
13797
13797
 
13798
+ /**
13799
+ * Helper class to generate permission strings for resources.
13800
+ */
13801
+ class Permission {
13802
+ }
13803
+ /**
13804
+ * Generate read permission string for the provided role.
13805
+ *
13806
+ * @param {string} role
13807
+ * @returns {string}
13808
+ */
13809
+ Permission.read = (role) => {
13810
+ return `read("${role}")`;
13811
+ };
13812
+ /**
13813
+ * Generate write permission string for the provided role.
13814
+ *
13815
+ * This is an alias of update, delete, and possibly create.
13816
+ * Don't use write in combination with update, delete, or create.
13817
+ *
13818
+ * @param {string} role
13819
+ * @returns {string}
13820
+ */
13821
+ Permission.write = (role) => {
13822
+ return `write("${role}")`;
13823
+ };
13824
+ /**
13825
+ * Generate create permission string for the provided role.
13826
+ *
13827
+ * @param {string} role
13828
+ * @returns {string}
13829
+ */
13830
+ Permission.create = (role) => {
13831
+ return `create("${role}")`;
13832
+ };
13833
+ /**
13834
+ * Generate update permission string for the provided role.
13835
+ *
13836
+ * @param {string} role
13837
+ * @returns {string}
13838
+ */
13839
+ Permission.update = (role) => {
13840
+ return `update("${role}")`;
13841
+ };
13842
+ /**
13843
+ * Generate delete permission string for the provided role.
13844
+ *
13845
+ * @param {string} role
13846
+ * @returns {string}
13847
+ */
13848
+ Permission.delete = (role) => {
13849
+ return `delete("${role}")`;
13850
+ };
13851
+
13852
+ /**
13853
+ * Helper class to generate role strings for `Permission`.
13854
+ */
13855
+ class Role {
13856
+ /**
13857
+ * Grants access to anyone.
13858
+ *
13859
+ * This includes authenticated and unauthenticated users.
13860
+ *
13861
+ * @returns {string}
13862
+ */
13863
+ static any() {
13864
+ return 'any';
13865
+ }
13866
+ /**
13867
+ * Grants access to a specific user by user ID.
13868
+ *
13869
+ * You can optionally pass verified or unverified for
13870
+ * `status` to target specific types of users.
13871
+ *
13872
+ * @param {string} id
13873
+ * @param {string} status
13874
+ * @returns {string}
13875
+ */
13876
+ static user(id, status = '') {
13877
+ if (status === '') {
13878
+ return `user:${id}`;
13879
+ }
13880
+ return `user:${id}/${status}`;
13881
+ }
13882
+ /**
13883
+ * Grants access to any authenticated or anonymous user.
13884
+ *
13885
+ * You can optionally pass verified or unverified for
13886
+ * `status` to target specific types of users.
13887
+ *
13888
+ * @param {string} status
13889
+ * @returns {string}
13890
+ */
13891
+ static users(status = '') {
13892
+ if (status === '') {
13893
+ return 'users';
13894
+ }
13895
+ return `users/${status}`;
13896
+ }
13897
+ /**
13898
+ * Grants access to any guest user without a session.
13899
+ *
13900
+ * Authenticated users don't have access to this role.
13901
+ *
13902
+ * @returns {string}
13903
+ */
13904
+ static guests() {
13905
+ return 'guests';
13906
+ }
13907
+ /**
13908
+ * Grants access to a team by team ID.
13909
+ *
13910
+ * You can optionally pass a role for `role` to target
13911
+ * team members with the specified role.
13912
+ *
13913
+ * @param {string} id
13914
+ * @param {string} role
13915
+ * @returns {string}
13916
+ */
13917
+ static team(id, role = '') {
13918
+ if (role === '') {
13919
+ return `team:${id}`;
13920
+ }
13921
+ return `team:${id}/${role}`;
13922
+ }
13923
+ /**
13924
+ * Grants access to a specific member of a team.
13925
+ *
13926
+ * When the member is removed from the team, they will
13927
+ * no longer have access.
13928
+ *
13929
+ * @param {string} id
13930
+ * @returns {string}
13931
+ */
13932
+ static member(id) {
13933
+ return `member:${id}`;
13934
+ }
13935
+ /**
13936
+ * Grants access to a user with the specified label.
13937
+ *
13938
+ * @param {string} name
13939
+ * @returns {string}
13940
+ */
13941
+ static label(name) {
13942
+ return `label:${name}`;
13943
+ }
13944
+ }
13945
+
13798
13946
  /**
13799
13947
  * Database Schema Migration Tool
13800
13948
  *
@@ -13807,12 +13955,30 @@ class SchemaMigration {
13807
13955
  constructor(databases) {
13808
13956
  this.databases = databases;
13809
13957
  }
13958
+ /**
13959
+ * Get default permissions for collections (read, create, update, delete all set to 'any')
13960
+ */
13961
+ getDefaultPermissions() {
13962
+ return [
13963
+ Permission.read(Role.any()),
13964
+ Permission.create(Role.any()),
13965
+ Permission.update(Role.any()),
13966
+ Permission.delete(Role.any())
13967
+ ];
13968
+ }
13810
13969
  /**
13811
13970
  * Check if an attribute key is a built-in field that cannot be modified
13812
13971
  * Built-in fields: id, createdAt, updatedAt
13813
13972
  */
13814
13973
  isBuiltInAttribute(key) {
13815
- return key === 'id' || key === 'createdAt' || key === 'updatedAt';
13974
+ return key === 'id' || key === 'createdAt' || key === 'updatedAt' || key === '$id' || key === '$createdAt' || key === '$updatedAt';
13975
+ }
13976
+ /**
13977
+ * Check if an index contains any built-in attributes
13978
+ * Built-in fields cannot have indexes created or deleted
13979
+ */
13980
+ indexContainsBuiltInAttributes(index) {
13981
+ return index.attributes.some(attr => this.isBuiltInAttribute(attr));
13816
13982
  }
13817
13983
  /**
13818
13984
  * Generate migration plan by comparing current database state with target schema
@@ -13883,6 +14049,11 @@ class SchemaMigration {
13883
14049
  // Process target indexes
13884
14050
  if (targetCollection.indexes) {
13885
14051
  for (const targetIndex of targetCollection.indexes) {
14052
+ // Skip indexes that contain built-in attributes
14053
+ if (this.indexContainsBuiltInAttributes(targetIndex)) {
14054
+ console.log(`Skipping index ${targetIndex.key} because it contains built-in attributes`);
14055
+ continue;
14056
+ }
13886
14057
  operations.push({
13887
14058
  type: 'createIndex',
13888
14059
  databaseId: schema.databaseId,
@@ -13986,6 +14157,11 @@ class SchemaMigration {
13986
14157
  });
13987
14158
  // Process target indexes
13988
14159
  for (const targetIndex of targetCollection.indexes) {
14160
+ // Skip indexes that contain built-in attributes
14161
+ if (this.indexContainsBuiltInAttributes(targetIndex)) {
14162
+ console.log(`Skipping index ${targetIndex.key} because it contains built-in attributes`);
14163
+ continue;
14164
+ }
13989
14165
  const currentIndex = currentIndexesMap.get(targetIndex.key);
13990
14166
  if (!currentIndex) {
13991
14167
  // Index doesn't exist - create it
@@ -14021,6 +14197,12 @@ class SchemaMigration {
14021
14197
  }
14022
14198
  // Check for indexes to delete
14023
14199
  for (const [key, currentIndex] of currentIndexesMap.entries()) {
14200
+ // Skip indexes that contain built-in attributes
14201
+ const indexAttributes = currentIndex.columns || [];
14202
+ if (indexAttributes.some((attr) => this.isBuiltInAttribute(attr))) {
14203
+ console.log(`Skipping deletion of index ${key} because it contains built-in attributes`);
14204
+ continue;
14205
+ }
14024
14206
  const targetIndex = targetCollection.indexes.find(i => i.key === key);
14025
14207
  if (!targetIndex) {
14026
14208
  operations.push({
@@ -14343,7 +14525,7 @@ class SchemaMigration {
14343
14525
  * Execute a single migration operation
14344
14526
  */
14345
14527
  executeOperation(operation) {
14346
- var _a, _b, _c, _d;
14528
+ var _a, _b, _c, _d, _e, _f;
14347
14529
  return __awaiter(this, void 0, void 0, function* () {
14348
14530
  switch (operation.type) {
14349
14531
  case 'createCollection':
@@ -14356,7 +14538,7 @@ class SchemaMigration {
14356
14538
  name: operation.collectionName,
14357
14539
  rowSecurity: (_a = targetCollection === null || targetCollection === void 0 ? void 0 : targetCollection.documentSecurity) !== null && _a !== void 0 ? _a : false,
14358
14540
  enabled: (_b = targetCollection === null || targetCollection === void 0 ? void 0 : targetCollection.enabled) !== null && _b !== void 0 ? _b : true,
14359
- permissions: targetCollection === null || targetCollection === void 0 ? void 0 : targetCollection.permissions
14541
+ permissions: (_c = targetCollection === null || targetCollection === void 0 ? void 0 : targetCollection.permissions) !== null && _c !== void 0 ? _c : this.getDefaultPermissions()
14360
14542
  });
14361
14543
  break;
14362
14544
  case 'updateCollection':
@@ -14367,9 +14549,9 @@ class SchemaMigration {
14367
14549
  databaseId: operation.databaseId,
14368
14550
  tableId: operation.collectionId,
14369
14551
  name: operation.collectionName || operation.collectionId,
14370
- rowSecurity: (_c = updateTargetCollection === null || updateTargetCollection === void 0 ? void 0 : updateTargetCollection.documentSecurity) !== null && _c !== void 0 ? _c : false,
14371
- enabled: (_d = updateTargetCollection === null || updateTargetCollection === void 0 ? void 0 : updateTargetCollection.enabled) !== null && _d !== void 0 ? _d : true,
14372
- permissions: updateTargetCollection === null || updateTargetCollection === void 0 ? void 0 : updateTargetCollection.permissions
14552
+ rowSecurity: (_d = updateTargetCollection === null || updateTargetCollection === void 0 ? void 0 : updateTargetCollection.documentSecurity) !== null && _d !== void 0 ? _d : false,
14553
+ enabled: (_e = updateTargetCollection === null || updateTargetCollection === void 0 ? void 0 : updateTargetCollection.enabled) !== null && _e !== void 0 ? _e : true,
14554
+ permissions: (_f = updateTargetCollection === null || updateTargetCollection === void 0 ? void 0 : updateTargetCollection.permissions) !== null && _f !== void 0 ? _f : this.getDefaultPermissions()
14373
14555
  });
14374
14556
  break;
14375
14557
  case 'deleteCollection':
@@ -14410,6 +14592,11 @@ class SchemaMigration {
14410
14592
  if (!operation.index) {
14411
14593
  throw new Error('Index definition missing for createIndex operation');
14412
14594
  }
14595
+ // Skip indexes that contain built-in attributes
14596
+ if (this.indexContainsBuiltInAttributes(operation.index)) {
14597
+ console.log(`Skipping createIndex for index ${operation.index.key} because it contains built-in attributes`);
14598
+ break;
14599
+ }
14413
14600
  // Wait for all attributes used in the index to be available
14414
14601
  yield this.waitForAttributesAvailable(operation.databaseId, operation.collectionId, operation.index.attributes);
14415
14602
  yield this.databases.createIndex({
@@ -14433,12 +14620,18 @@ class SchemaMigration {
14433
14620
  tableId: operation.collectionId,
14434
14621
  total: true
14435
14622
  });
14436
- const indexExists = indexesList.indexes.some(idx => idx.key === operation.indexKey);
14437
- if (!indexExists) {
14623
+ const indexToDelete = indexesList.indexes.find(idx => idx.key === operation.indexKey);
14624
+ if (!indexToDelete) {
14438
14625
  // Index doesn't exist, skip deletion
14439
14626
  console.log(`Index ${operation.indexKey} does not exist, skipping deletion`);
14440
14627
  break;
14441
14628
  }
14629
+ // Check if index contains built-in attributes
14630
+ const indexAttributes = indexToDelete.columns || [];
14631
+ if (indexAttributes.some((attr) => this.isBuiltInAttribute(attr))) {
14632
+ console.log(`Skipping deleteIndex for index ${operation.indexKey} because it contains built-in attributes`);
14633
+ break;
14634
+ }
14442
14635
  }
14443
14636
  catch (error) {
14444
14637
  // If we can't list indexes, try to delete anyway (might fail gracefully)
@@ -25641,154 +25834,6 @@ class Realtime {
25641
25834
  }
25642
25835
  }
25643
25836
 
25644
- /**
25645
- * Helper class to generate permission strings for resources.
25646
- */
25647
- class Permission {
25648
- }
25649
- /**
25650
- * Generate read permission string for the provided role.
25651
- *
25652
- * @param {string} role
25653
- * @returns {string}
25654
- */
25655
- Permission.read = (role) => {
25656
- return `read("${role}")`;
25657
- };
25658
- /**
25659
- * Generate write permission string for the provided role.
25660
- *
25661
- * This is an alias of update, delete, and possibly create.
25662
- * Don't use write in combination with update, delete, or create.
25663
- *
25664
- * @param {string} role
25665
- * @returns {string}
25666
- */
25667
- Permission.write = (role) => {
25668
- return `write("${role}")`;
25669
- };
25670
- /**
25671
- * Generate create permission string for the provided role.
25672
- *
25673
- * @param {string} role
25674
- * @returns {string}
25675
- */
25676
- Permission.create = (role) => {
25677
- return `create("${role}")`;
25678
- };
25679
- /**
25680
- * Generate update permission string for the provided role.
25681
- *
25682
- * @param {string} role
25683
- * @returns {string}
25684
- */
25685
- Permission.update = (role) => {
25686
- return `update("${role}")`;
25687
- };
25688
- /**
25689
- * Generate delete permission string for the provided role.
25690
- *
25691
- * @param {string} role
25692
- * @returns {string}
25693
- */
25694
- Permission.delete = (role) => {
25695
- return `delete("${role}")`;
25696
- };
25697
-
25698
- /**
25699
- * Helper class to generate role strings for `Permission`.
25700
- */
25701
- class Role {
25702
- /**
25703
- * Grants access to anyone.
25704
- *
25705
- * This includes authenticated and unauthenticated users.
25706
- *
25707
- * @returns {string}
25708
- */
25709
- static any() {
25710
- return 'any';
25711
- }
25712
- /**
25713
- * Grants access to a specific user by user ID.
25714
- *
25715
- * You can optionally pass verified or unverified for
25716
- * `status` to target specific types of users.
25717
- *
25718
- * @param {string} id
25719
- * @param {string} status
25720
- * @returns {string}
25721
- */
25722
- static user(id, status = '') {
25723
- if (status === '') {
25724
- return `user:${id}`;
25725
- }
25726
- return `user:${id}/${status}`;
25727
- }
25728
- /**
25729
- * Grants access to any authenticated or anonymous user.
25730
- *
25731
- * You can optionally pass verified or unverified for
25732
- * `status` to target specific types of users.
25733
- *
25734
- * @param {string} status
25735
- * @returns {string}
25736
- */
25737
- static users(status = '') {
25738
- if (status === '') {
25739
- return 'users';
25740
- }
25741
- return `users/${status}`;
25742
- }
25743
- /**
25744
- * Grants access to any guest user without a session.
25745
- *
25746
- * Authenticated users don't have access to this role.
25747
- *
25748
- * @returns {string}
25749
- */
25750
- static guests() {
25751
- return 'guests';
25752
- }
25753
- /**
25754
- * Grants access to a team by team ID.
25755
- *
25756
- * You can optionally pass a role for `role` to target
25757
- * team members with the specified role.
25758
- *
25759
- * @param {string} id
25760
- * @param {string} role
25761
- * @returns {string}
25762
- */
25763
- static team(id, role = '') {
25764
- if (role === '') {
25765
- return `team:${id}`;
25766
- }
25767
- return `team:${id}/${role}`;
25768
- }
25769
- /**
25770
- * Grants access to a specific member of a team.
25771
- *
25772
- * When the member is removed from the team, they will
25773
- * no longer have access.
25774
- *
25775
- * @param {string} id
25776
- * @returns {string}
25777
- */
25778
- static member(id) {
25779
- return `member:${id}`;
25780
- }
25781
- /**
25782
- * Grants access to a user with the specified label.
25783
- *
25784
- * @param {string} name
25785
- * @returns {string}
25786
- */
25787
- static label(name) {
25788
- return `label:${name}`;
25789
- }
25790
- }
25791
-
25792
25837
  var _a, _ID_hexTimestamp;
25793
25838
  /**
25794
25839
  * Helper class to generate ID strings for resources.
@@ -27610,8 +27655,16 @@ exports.MessageStatus = void 0;
27610
27655
  MessageStatus["Failed"] = "failed";
27611
27656
  })(exports.MessageStatus || (exports.MessageStatus = {}));
27612
27657
 
27658
+ // 全局默认 API endpoint 配置
27659
+ let defaultApiEndpoint = null;
27660
+ function setDefaultApiEndpoint(endpoint) {
27661
+ if (!endpoint.startsWith('http://') && !endpoint.startsWith('https://')) {
27662
+ throw new Error('Invalid endpoint URL: ' + endpoint);
27663
+ }
27664
+ defaultApiEndpoint = endpoint;
27665
+ }
27613
27666
  function getApiEndpoint(region) {
27614
- return 'https://appbuild.oceanbase.com/v1';
27667
+ return defaultApiEndpoint || 'https://appbuild.oceanbase.com/v1';
27615
27668
  }
27616
27669
  function createConsoleSdk(client) {
27617
27670
  return {
@@ -27760,4 +27813,5 @@ exports.Vcs = Vcs;
27760
27813
  exports.getApiEndpoint = getApiEndpoint;
27761
27814
  exports.realtime = realtime;
27762
27815
  exports.sdk = sdk;
27816
+ exports.setDefaultApiEndpoint = setDefaultApiEndpoint;
27763
27817
  //# sourceMappingURL=sdk.js.map