appbuild-oceanbase-console 1.10.2 → 1.10.4
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 +358 -169
- package/dist/cjs/sdk.js.map +1 -1
- package/dist/esm/sdk.js +358 -169
- package/dist/esm/sdk.js.map +1 -1
- package/dist/iife/sdk.js +358 -169
- package/package.json +1 -1
- package/types/migrations.d.ts +35 -0
- package/dist/cjs/package.json +0 -3
- package/dist/esm/package.json +0 -3
package/dist/esm/sdk.js
CHANGED
|
@@ -13793,6 +13793,154 @@ var AttributeStatus;
|
|
|
13793
13793
|
AttributeStatus["Failed"] = "failed";
|
|
13794
13794
|
})(AttributeStatus || (AttributeStatus = {}));
|
|
13795
13795
|
|
|
13796
|
+
/**
|
|
13797
|
+
* Helper class to generate permission strings for resources.
|
|
13798
|
+
*/
|
|
13799
|
+
class Permission {
|
|
13800
|
+
}
|
|
13801
|
+
/**
|
|
13802
|
+
* Generate read permission string for the provided role.
|
|
13803
|
+
*
|
|
13804
|
+
* @param {string} role
|
|
13805
|
+
* @returns {string}
|
|
13806
|
+
*/
|
|
13807
|
+
Permission.read = (role) => {
|
|
13808
|
+
return `read("${role}")`;
|
|
13809
|
+
};
|
|
13810
|
+
/**
|
|
13811
|
+
* Generate write permission string for the provided role.
|
|
13812
|
+
*
|
|
13813
|
+
* This is an alias of update, delete, and possibly create.
|
|
13814
|
+
* Don't use write in combination with update, delete, or create.
|
|
13815
|
+
*
|
|
13816
|
+
* @param {string} role
|
|
13817
|
+
* @returns {string}
|
|
13818
|
+
*/
|
|
13819
|
+
Permission.write = (role) => {
|
|
13820
|
+
return `write("${role}")`;
|
|
13821
|
+
};
|
|
13822
|
+
/**
|
|
13823
|
+
* Generate create permission string for the provided role.
|
|
13824
|
+
*
|
|
13825
|
+
* @param {string} role
|
|
13826
|
+
* @returns {string}
|
|
13827
|
+
*/
|
|
13828
|
+
Permission.create = (role) => {
|
|
13829
|
+
return `create("${role}")`;
|
|
13830
|
+
};
|
|
13831
|
+
/**
|
|
13832
|
+
* Generate update permission string for the provided role.
|
|
13833
|
+
*
|
|
13834
|
+
* @param {string} role
|
|
13835
|
+
* @returns {string}
|
|
13836
|
+
*/
|
|
13837
|
+
Permission.update = (role) => {
|
|
13838
|
+
return `update("${role}")`;
|
|
13839
|
+
};
|
|
13840
|
+
/**
|
|
13841
|
+
* Generate delete permission string for the provided role.
|
|
13842
|
+
*
|
|
13843
|
+
* @param {string} role
|
|
13844
|
+
* @returns {string}
|
|
13845
|
+
*/
|
|
13846
|
+
Permission.delete = (role) => {
|
|
13847
|
+
return `delete("${role}")`;
|
|
13848
|
+
};
|
|
13849
|
+
|
|
13850
|
+
/**
|
|
13851
|
+
* Helper class to generate role strings for `Permission`.
|
|
13852
|
+
*/
|
|
13853
|
+
class Role {
|
|
13854
|
+
/**
|
|
13855
|
+
* Grants access to anyone.
|
|
13856
|
+
*
|
|
13857
|
+
* This includes authenticated and unauthenticated users.
|
|
13858
|
+
*
|
|
13859
|
+
* @returns {string}
|
|
13860
|
+
*/
|
|
13861
|
+
static any() {
|
|
13862
|
+
return 'any';
|
|
13863
|
+
}
|
|
13864
|
+
/**
|
|
13865
|
+
* Grants access to a specific user by user ID.
|
|
13866
|
+
*
|
|
13867
|
+
* You can optionally pass verified or unverified for
|
|
13868
|
+
* `status` to target specific types of users.
|
|
13869
|
+
*
|
|
13870
|
+
* @param {string} id
|
|
13871
|
+
* @param {string} status
|
|
13872
|
+
* @returns {string}
|
|
13873
|
+
*/
|
|
13874
|
+
static user(id, status = '') {
|
|
13875
|
+
if (status === '') {
|
|
13876
|
+
return `user:${id}`;
|
|
13877
|
+
}
|
|
13878
|
+
return `user:${id}/${status}`;
|
|
13879
|
+
}
|
|
13880
|
+
/**
|
|
13881
|
+
* Grants access to any authenticated or anonymous user.
|
|
13882
|
+
*
|
|
13883
|
+
* You can optionally pass verified or unverified for
|
|
13884
|
+
* `status` to target specific types of users.
|
|
13885
|
+
*
|
|
13886
|
+
* @param {string} status
|
|
13887
|
+
* @returns {string}
|
|
13888
|
+
*/
|
|
13889
|
+
static users(status = '') {
|
|
13890
|
+
if (status === '') {
|
|
13891
|
+
return 'users';
|
|
13892
|
+
}
|
|
13893
|
+
return `users/${status}`;
|
|
13894
|
+
}
|
|
13895
|
+
/**
|
|
13896
|
+
* Grants access to any guest user without a session.
|
|
13897
|
+
*
|
|
13898
|
+
* Authenticated users don't have access to this role.
|
|
13899
|
+
*
|
|
13900
|
+
* @returns {string}
|
|
13901
|
+
*/
|
|
13902
|
+
static guests() {
|
|
13903
|
+
return 'guests';
|
|
13904
|
+
}
|
|
13905
|
+
/**
|
|
13906
|
+
* Grants access to a team by team ID.
|
|
13907
|
+
*
|
|
13908
|
+
* You can optionally pass a role for `role` to target
|
|
13909
|
+
* team members with the specified role.
|
|
13910
|
+
*
|
|
13911
|
+
* @param {string} id
|
|
13912
|
+
* @param {string} role
|
|
13913
|
+
* @returns {string}
|
|
13914
|
+
*/
|
|
13915
|
+
static team(id, role = '') {
|
|
13916
|
+
if (role === '') {
|
|
13917
|
+
return `team:${id}`;
|
|
13918
|
+
}
|
|
13919
|
+
return `team:${id}/${role}`;
|
|
13920
|
+
}
|
|
13921
|
+
/**
|
|
13922
|
+
* Grants access to a specific member of a team.
|
|
13923
|
+
*
|
|
13924
|
+
* When the member is removed from the team, they will
|
|
13925
|
+
* no longer have access.
|
|
13926
|
+
*
|
|
13927
|
+
* @param {string} id
|
|
13928
|
+
* @returns {string}
|
|
13929
|
+
*/
|
|
13930
|
+
static member(id) {
|
|
13931
|
+
return `member:${id}`;
|
|
13932
|
+
}
|
|
13933
|
+
/**
|
|
13934
|
+
* Grants access to a user with the specified label.
|
|
13935
|
+
*
|
|
13936
|
+
* @param {string} name
|
|
13937
|
+
* @returns {string}
|
|
13938
|
+
*/
|
|
13939
|
+
static label(name) {
|
|
13940
|
+
return `label:${name}`;
|
|
13941
|
+
}
|
|
13942
|
+
}
|
|
13943
|
+
|
|
13796
13944
|
/**
|
|
13797
13945
|
* Database Schema Migration Tool
|
|
13798
13946
|
*
|
|
@@ -13805,6 +13953,45 @@ class SchemaMigration {
|
|
|
13805
13953
|
constructor(databases) {
|
|
13806
13954
|
this.databases = databases;
|
|
13807
13955
|
}
|
|
13956
|
+
/**
|
|
13957
|
+
* Get default permissions for collections (read, create, update, delete all set to 'any')
|
|
13958
|
+
*/
|
|
13959
|
+
getDefaultPermissions() {
|
|
13960
|
+
return [
|
|
13961
|
+
Permission.read(Role.any()),
|
|
13962
|
+
Permission.create(Role.any()),
|
|
13963
|
+
Permission.update(Role.any()),
|
|
13964
|
+
Permission.delete(Role.any())
|
|
13965
|
+
];
|
|
13966
|
+
}
|
|
13967
|
+
/**
|
|
13968
|
+
* Check if an attribute key is a built-in field that cannot be modified
|
|
13969
|
+
* Built-in fields include:
|
|
13970
|
+
* - Fields starting with '$' prefix (e.g., $id, $createdAt, $updatedAt)
|
|
13971
|
+
* - Legacy field names: id, createdAt, updatedAt
|
|
13972
|
+
*/
|
|
13973
|
+
isBuiltInAttribute(key) {
|
|
13974
|
+
// Check if starts with '$' prefix (all system/built-in fields)
|
|
13975
|
+
if (key.startsWith('$')) {
|
|
13976
|
+
return true;
|
|
13977
|
+
}
|
|
13978
|
+
// Legacy field names for backwards compatibility
|
|
13979
|
+
return key === 'id' || key === 'createdAt' || key === 'updatedAt';
|
|
13980
|
+
}
|
|
13981
|
+
/**
|
|
13982
|
+
* Check if an index key is a built-in index that cannot be modified
|
|
13983
|
+
* Built-in indexes start with '$' prefix
|
|
13984
|
+
*/
|
|
13985
|
+
isBuiltInIndex(key) {
|
|
13986
|
+
return key.startsWith('$');
|
|
13987
|
+
}
|
|
13988
|
+
/**
|
|
13989
|
+
* Check if an index contains any built-in attributes
|
|
13990
|
+
* Built-in fields cannot have indexes created or deleted
|
|
13991
|
+
*/
|
|
13992
|
+
indexContainsBuiltInAttributes(index) {
|
|
13993
|
+
return index.attributes.some(attr => this.isBuiltInAttribute(attr));
|
|
13994
|
+
}
|
|
13808
13995
|
/**
|
|
13809
13996
|
* Generate migration plan by comparing current database state with target schema
|
|
13810
13997
|
*/
|
|
@@ -13814,9 +14001,30 @@ class SchemaMigration {
|
|
|
13814
14001
|
// Store schema for later use in execution
|
|
13815
14002
|
this._currentSchema = schema;
|
|
13816
14003
|
const operations = [];
|
|
14004
|
+
const skippedBuiltIns = [];
|
|
14005
|
+
// If databaseId is empty, create a database with id "default"
|
|
14006
|
+
let databaseId = schema.databaseId;
|
|
14007
|
+
if (!databaseId || databaseId.trim() === '') {
|
|
14008
|
+
databaseId = 'default';
|
|
14009
|
+
try {
|
|
14010
|
+
yield this.databases.create({
|
|
14011
|
+
databaseId: databaseId,
|
|
14012
|
+
name: 'default',
|
|
14013
|
+
enabled: true
|
|
14014
|
+
});
|
|
14015
|
+
}
|
|
14016
|
+
catch (error) {
|
|
14017
|
+
// If database already exists, that's fine
|
|
14018
|
+
if (!(error instanceof AppwriteException && error.code === 409)) {
|
|
14019
|
+
throw error;
|
|
14020
|
+
}
|
|
14021
|
+
}
|
|
14022
|
+
// Update schema.databaseId for later use
|
|
14023
|
+
schema.databaseId = databaseId;
|
|
14024
|
+
}
|
|
13817
14025
|
// Get current tables
|
|
13818
14026
|
const currentTables = yield this.databases.listTables({
|
|
13819
|
-
databaseId:
|
|
14027
|
+
databaseId: databaseId,
|
|
13820
14028
|
total: true
|
|
13821
14029
|
});
|
|
13822
14030
|
const currentTablesMap = new Map();
|
|
@@ -13839,6 +14047,16 @@ class SchemaMigration {
|
|
|
13839
14047
|
// For new tables, create all attributes and indexes
|
|
13840
14048
|
// Process target attributes
|
|
13841
14049
|
for (const targetAttr of targetCollection.attributes) {
|
|
14050
|
+
// Skip built-in attributes (starting with '$' or legacy names)
|
|
14051
|
+
if (this.isBuiltInAttribute(targetAttr.key)) {
|
|
14052
|
+
skippedBuiltIns.push({
|
|
14053
|
+
collectionId: collectionId,
|
|
14054
|
+
key: targetAttr.key,
|
|
14055
|
+
type: 'attribute',
|
|
14056
|
+
reason: `Built-in column '${targetAttr.key}' is automatically managed by the system`
|
|
14057
|
+
});
|
|
14058
|
+
continue;
|
|
14059
|
+
}
|
|
13842
14060
|
operations.push({
|
|
13843
14061
|
type: 'createAttribute',
|
|
13844
14062
|
databaseId: schema.databaseId,
|
|
@@ -13850,6 +14068,26 @@ class SchemaMigration {
|
|
|
13850
14068
|
// Process target indexes
|
|
13851
14069
|
if (targetCollection.indexes) {
|
|
13852
14070
|
for (const targetIndex of targetCollection.indexes) {
|
|
14071
|
+
// Skip built-in indexes (starting with '$')
|
|
14072
|
+
if (this.isBuiltInIndex(targetIndex.key)) {
|
|
14073
|
+
skippedBuiltIns.push({
|
|
14074
|
+
collectionId: collectionId,
|
|
14075
|
+
key: targetIndex.key,
|
|
14076
|
+
type: 'index',
|
|
14077
|
+
reason: `Built-in index '${targetIndex.key}' is automatically managed by the system`
|
|
14078
|
+
});
|
|
14079
|
+
continue;
|
|
14080
|
+
}
|
|
14081
|
+
// Skip indexes that contain built-in attributes
|
|
14082
|
+
if (this.indexContainsBuiltInAttributes(targetIndex)) {
|
|
14083
|
+
skippedBuiltIns.push({
|
|
14084
|
+
collectionId: collectionId,
|
|
14085
|
+
key: targetIndex.key,
|
|
14086
|
+
type: 'index',
|
|
14087
|
+
reason: `Index '${targetIndex.key}' references built-in columns and is automatically managed`
|
|
14088
|
+
});
|
|
14089
|
+
continue;
|
|
14090
|
+
}
|
|
13853
14091
|
operations.push({
|
|
13854
14092
|
type: 'createIndex',
|
|
13855
14093
|
databaseId: schema.databaseId,
|
|
@@ -13886,6 +14124,16 @@ class SchemaMigration {
|
|
|
13886
14124
|
});
|
|
13887
14125
|
// Process target attributes
|
|
13888
14126
|
for (const targetAttr of targetCollection.attributes) {
|
|
14127
|
+
// Skip built-in attributes (starting with '$' or legacy names)
|
|
14128
|
+
if (this.isBuiltInAttribute(targetAttr.key)) {
|
|
14129
|
+
skippedBuiltIns.push({
|
|
14130
|
+
collectionId: collectionId,
|
|
14131
|
+
key: targetAttr.key,
|
|
14132
|
+
type: 'attribute',
|
|
14133
|
+
reason: `Built-in column '${targetAttr.key}' is automatically managed by the system`
|
|
14134
|
+
});
|
|
14135
|
+
continue;
|
|
14136
|
+
}
|
|
13889
14137
|
const currentCol = currentColumnsMap.get(targetAttr.key);
|
|
13890
14138
|
if (!currentCol) {
|
|
13891
14139
|
// Column doesn't exist - create it
|
|
@@ -13921,6 +14169,11 @@ class SchemaMigration {
|
|
|
13921
14169
|
}
|
|
13922
14170
|
// Check for columns to delete (columns in current but not in target)
|
|
13923
14171
|
for (const [key, currentAttr] of currentColumnsMap.entries()) {
|
|
14172
|
+
// Skip built-in attributes (starting with '$' or legacy names)
|
|
14173
|
+
if (this.isBuiltInAttribute(key)) {
|
|
14174
|
+
// Don't add to skippedBuiltIns here since these are existing columns, not from target schema
|
|
14175
|
+
continue;
|
|
14176
|
+
}
|
|
13924
14177
|
const targetAttr = targetCollection.attributes.find(a => a.key === key);
|
|
13925
14178
|
if (!targetAttr) {
|
|
13926
14179
|
operations.push({
|
|
@@ -13945,6 +14198,26 @@ class SchemaMigration {
|
|
|
13945
14198
|
});
|
|
13946
14199
|
// Process target indexes
|
|
13947
14200
|
for (const targetIndex of targetCollection.indexes) {
|
|
14201
|
+
// Skip built-in indexes (starting with '$')
|
|
14202
|
+
if (this.isBuiltInIndex(targetIndex.key)) {
|
|
14203
|
+
skippedBuiltIns.push({
|
|
14204
|
+
collectionId: collectionId,
|
|
14205
|
+
key: targetIndex.key,
|
|
14206
|
+
type: 'index',
|
|
14207
|
+
reason: `Built-in index '${targetIndex.key}' is automatically managed by the system`
|
|
14208
|
+
});
|
|
14209
|
+
continue;
|
|
14210
|
+
}
|
|
14211
|
+
// Skip indexes that contain built-in attributes
|
|
14212
|
+
if (this.indexContainsBuiltInAttributes(targetIndex)) {
|
|
14213
|
+
skippedBuiltIns.push({
|
|
14214
|
+
collectionId: collectionId,
|
|
14215
|
+
key: targetIndex.key,
|
|
14216
|
+
type: 'index',
|
|
14217
|
+
reason: `Index '${targetIndex.key}' references built-in columns and is automatically managed`
|
|
14218
|
+
});
|
|
14219
|
+
continue;
|
|
14220
|
+
}
|
|
13948
14221
|
const currentIndex = currentIndexesMap.get(targetIndex.key);
|
|
13949
14222
|
if (!currentIndex) {
|
|
13950
14223
|
// Index doesn't exist - create it
|
|
@@ -13980,6 +14253,17 @@ class SchemaMigration {
|
|
|
13980
14253
|
}
|
|
13981
14254
|
// Check for indexes to delete
|
|
13982
14255
|
for (const [key, currentIndex] of currentIndexesMap.entries()) {
|
|
14256
|
+
// Skip built-in indexes (starting with '$')
|
|
14257
|
+
if (this.isBuiltInIndex(key)) {
|
|
14258
|
+
// Don't add to skippedBuiltIns here since these are existing indexes, not from target schema
|
|
14259
|
+
continue;
|
|
14260
|
+
}
|
|
14261
|
+
// Skip indexes that contain built-in attributes
|
|
14262
|
+
const indexAttributes = currentIndex.columns || [];
|
|
14263
|
+
if (indexAttributes.some((attr) => this.isBuiltInAttribute(attr))) {
|
|
14264
|
+
// Don't add to skippedBuiltIns here since these are existing indexes
|
|
14265
|
+
continue;
|
|
14266
|
+
}
|
|
13983
14267
|
const targetIndex = targetCollection.indexes.find(i => i.key === key);
|
|
13984
14268
|
if (!targetIndex) {
|
|
13985
14269
|
operations.push({
|
|
@@ -14019,7 +14303,8 @@ class SchemaMigration {
|
|
|
14019
14303
|
};
|
|
14020
14304
|
return {
|
|
14021
14305
|
operations,
|
|
14022
|
-
summary
|
|
14306
|
+
summary,
|
|
14307
|
+
skippedBuiltIns
|
|
14023
14308
|
};
|
|
14024
14309
|
});
|
|
14025
14310
|
}
|
|
@@ -14124,6 +14409,25 @@ class SchemaMigration {
|
|
|
14124
14409
|
plan.operations.forEach((op, index) => {
|
|
14125
14410
|
console.log(`${index + 1}. [${op.type}] ${op.reason}`);
|
|
14126
14411
|
});
|
|
14412
|
+
// Display skipped built-in items
|
|
14413
|
+
if (plan.skippedBuiltIns && plan.skippedBuiltIns.length > 0) {
|
|
14414
|
+
console.log('\n=== SKIPPED BUILT-IN ITEMS ===');
|
|
14415
|
+
console.log('The following items are built-in (starting with "$") and automatically managed by the system:');
|
|
14416
|
+
const skippedAttributes = plan.skippedBuiltIns.filter(item => item.type === 'attribute');
|
|
14417
|
+
const skippedIndexes = plan.skippedBuiltIns.filter(item => item.type === 'index');
|
|
14418
|
+
if (skippedAttributes.length > 0) {
|
|
14419
|
+
console.log('\nBuilt-in Columns:');
|
|
14420
|
+
skippedAttributes.forEach(item => {
|
|
14421
|
+
console.log(` - [${item.collectionId}] ${item.key}: ${item.reason}`);
|
|
14422
|
+
});
|
|
14423
|
+
}
|
|
14424
|
+
if (skippedIndexes.length > 0) {
|
|
14425
|
+
console.log('\nBuilt-in Indexes:');
|
|
14426
|
+
skippedIndexes.forEach(item => {
|
|
14427
|
+
console.log(` - [${item.collectionId}] ${item.key}: ${item.reason}`);
|
|
14428
|
+
});
|
|
14429
|
+
}
|
|
14430
|
+
}
|
|
14127
14431
|
return;
|
|
14128
14432
|
}
|
|
14129
14433
|
// Store schema for use in executeOperation
|
|
@@ -14302,7 +14606,7 @@ class SchemaMigration {
|
|
|
14302
14606
|
* Execute a single migration operation
|
|
14303
14607
|
*/
|
|
14304
14608
|
executeOperation(operation) {
|
|
14305
|
-
var _a, _b, _c, _d;
|
|
14609
|
+
var _a, _b, _c, _d, _e, _f;
|
|
14306
14610
|
return __awaiter(this, void 0, void 0, function* () {
|
|
14307
14611
|
switch (operation.type) {
|
|
14308
14612
|
case 'createCollection':
|
|
@@ -14315,7 +14619,7 @@ class SchemaMigration {
|
|
|
14315
14619
|
name: operation.collectionName,
|
|
14316
14620
|
rowSecurity: (_a = targetCollection === null || targetCollection === void 0 ? void 0 : targetCollection.documentSecurity) !== null && _a !== void 0 ? _a : false,
|
|
14317
14621
|
enabled: (_b = targetCollection === null || targetCollection === void 0 ? void 0 : targetCollection.enabled) !== null && _b !== void 0 ? _b : true,
|
|
14318
|
-
permissions: targetCollection === null || targetCollection === void 0 ? void 0 : targetCollection.permissions
|
|
14622
|
+
permissions: (_c = targetCollection === null || targetCollection === void 0 ? void 0 : targetCollection.permissions) !== null && _c !== void 0 ? _c : this.getDefaultPermissions()
|
|
14319
14623
|
});
|
|
14320
14624
|
break;
|
|
14321
14625
|
case 'updateCollection':
|
|
@@ -14326,9 +14630,9 @@ class SchemaMigration {
|
|
|
14326
14630
|
databaseId: operation.databaseId,
|
|
14327
14631
|
tableId: operation.collectionId,
|
|
14328
14632
|
name: operation.collectionName || operation.collectionId,
|
|
14329
|
-
rowSecurity: (
|
|
14330
|
-
enabled: (
|
|
14331
|
-
permissions: updateTargetCollection === null || updateTargetCollection === void 0 ? void 0 : updateTargetCollection.permissions
|
|
14633
|
+
rowSecurity: (_d = updateTargetCollection === null || updateTargetCollection === void 0 ? void 0 : updateTargetCollection.documentSecurity) !== null && _d !== void 0 ? _d : false,
|
|
14634
|
+
enabled: (_e = updateTargetCollection === null || updateTargetCollection === void 0 ? void 0 : updateTargetCollection.enabled) !== null && _e !== void 0 ? _e : true,
|
|
14635
|
+
permissions: (_f = updateTargetCollection === null || updateTargetCollection === void 0 ? void 0 : updateTargetCollection.permissions) !== null && _f !== void 0 ? _f : this.getDefaultPermissions()
|
|
14332
14636
|
});
|
|
14333
14637
|
break;
|
|
14334
14638
|
case 'deleteCollection':
|
|
@@ -14341,12 +14645,22 @@ class SchemaMigration {
|
|
|
14341
14645
|
if (!operation.attribute) {
|
|
14342
14646
|
throw new Error('Attribute definition missing for createAttribute operation');
|
|
14343
14647
|
}
|
|
14648
|
+
// Skip built-in attributes (id, createdAt, updatedAt)
|
|
14649
|
+
if (this.isBuiltInAttribute(operation.attribute.key)) {
|
|
14650
|
+
console.log(`Skipping createAttribute for built-in field: ${operation.attribute.key}`);
|
|
14651
|
+
break;
|
|
14652
|
+
}
|
|
14344
14653
|
yield this.createAttribute(operation.databaseId, operation.collectionId, operation.attribute);
|
|
14345
14654
|
break;
|
|
14346
14655
|
case 'deleteAttribute':
|
|
14347
14656
|
if (!operation.attributeKey) {
|
|
14348
14657
|
throw new Error('Column key missing for deleteAttribute operation');
|
|
14349
14658
|
}
|
|
14659
|
+
// Skip built-in attributes (id, createdAt, updatedAt)
|
|
14660
|
+
if (this.isBuiltInAttribute(operation.attributeKey)) {
|
|
14661
|
+
console.log(`Skipping deleteAttribute for built-in field: ${operation.attributeKey}`);
|
|
14662
|
+
break;
|
|
14663
|
+
}
|
|
14350
14664
|
yield this.databases.deleteColumn({
|
|
14351
14665
|
databaseId: operation.databaseId,
|
|
14352
14666
|
tableId: operation.collectionId,
|
|
@@ -14359,6 +14673,16 @@ class SchemaMigration {
|
|
|
14359
14673
|
if (!operation.index) {
|
|
14360
14674
|
throw new Error('Index definition missing for createIndex operation');
|
|
14361
14675
|
}
|
|
14676
|
+
// Skip built-in indexes (starting with '$')
|
|
14677
|
+
if (this.isBuiltInIndex(operation.index.key)) {
|
|
14678
|
+
console.log(`Skipping createIndex for built-in index: ${operation.index.key}`);
|
|
14679
|
+
break;
|
|
14680
|
+
}
|
|
14681
|
+
// Skip indexes that contain built-in attributes
|
|
14682
|
+
if (this.indexContainsBuiltInAttributes(operation.index)) {
|
|
14683
|
+
console.log(`Skipping createIndex for index ${operation.index.key} because it contains built-in attributes`);
|
|
14684
|
+
break;
|
|
14685
|
+
}
|
|
14362
14686
|
// Wait for all attributes used in the index to be available
|
|
14363
14687
|
yield this.waitForAttributesAvailable(operation.databaseId, operation.collectionId, operation.index.attributes);
|
|
14364
14688
|
yield this.databases.createIndex({
|
|
@@ -14375,6 +14699,11 @@ class SchemaMigration {
|
|
|
14375
14699
|
if (!operation.indexKey) {
|
|
14376
14700
|
throw new Error('Index key missing for deleteIndex operation');
|
|
14377
14701
|
}
|
|
14702
|
+
// Skip built-in indexes (starting with '$')
|
|
14703
|
+
if (this.isBuiltInIndex(operation.indexKey)) {
|
|
14704
|
+
console.log(`Skipping deleteIndex for built-in index: ${operation.indexKey}`);
|
|
14705
|
+
break;
|
|
14706
|
+
}
|
|
14378
14707
|
// Check if index exists before deleting
|
|
14379
14708
|
try {
|
|
14380
14709
|
const indexesList = yield this.databases.listIndexes({
|
|
@@ -14382,12 +14711,18 @@ class SchemaMigration {
|
|
|
14382
14711
|
tableId: operation.collectionId,
|
|
14383
14712
|
total: true
|
|
14384
14713
|
});
|
|
14385
|
-
const
|
|
14386
|
-
if (!
|
|
14714
|
+
const indexToDelete = indexesList.indexes.find(idx => idx.key === operation.indexKey);
|
|
14715
|
+
if (!indexToDelete) {
|
|
14387
14716
|
// Index doesn't exist, skip deletion
|
|
14388
14717
|
console.log(`Index ${operation.indexKey} does not exist, skipping deletion`);
|
|
14389
14718
|
break;
|
|
14390
14719
|
}
|
|
14720
|
+
// Check if index contains built-in attributes
|
|
14721
|
+
const indexAttributes = indexToDelete.columns || [];
|
|
14722
|
+
if (indexAttributes.some((attr) => this.isBuiltInAttribute(attr))) {
|
|
14723
|
+
console.log(`Skipping deleteIndex for index ${operation.indexKey} because it contains built-in attributes`);
|
|
14724
|
+
break;
|
|
14725
|
+
}
|
|
14391
14726
|
}
|
|
14392
14727
|
catch (error) {
|
|
14393
14728
|
// If we can't list indexes, try to delete anyway (might fail gracefully)
|
|
@@ -14415,45 +14750,47 @@ class SchemaMigration {
|
|
|
14415
14750
|
key: attr.key,
|
|
14416
14751
|
required: attr.required
|
|
14417
14752
|
};
|
|
14753
|
+
// Required fields cannot have default values
|
|
14754
|
+
const defaultParams = attr.required ? {} : (attr.default !== undefined ? { xdefault: attr.default } : {});
|
|
14418
14755
|
switch (attr.type) {
|
|
14419
14756
|
case 'string':
|
|
14420
|
-
yield this.databases.createStringColumn(Object.assign(Object.assign({}, baseParams), { size: attr.size || 255,
|
|
14757
|
+
yield this.databases.createStringColumn(Object.assign(Object.assign(Object.assign(Object.assign({}, baseParams), { size: attr.size || 255 }), defaultParams), { array: attr.array, encrypt: attr.encrypt }));
|
|
14421
14758
|
break;
|
|
14422
14759
|
case 'integer':
|
|
14423
|
-
yield this.databases.createIntegerColumn(Object.assign(Object.assign({}, baseParams), { min: attr.min, max: attr.max,
|
|
14760
|
+
yield this.databases.createIntegerColumn(Object.assign(Object.assign(Object.assign(Object.assign({}, baseParams), { min: attr.min, max: attr.max }), defaultParams), { array: attr.array }));
|
|
14424
14761
|
break;
|
|
14425
14762
|
case 'float':
|
|
14426
|
-
yield this.databases.createFloatColumn(Object.assign(Object.assign({}, baseParams), { min: attr.min, max: attr.max,
|
|
14763
|
+
yield this.databases.createFloatColumn(Object.assign(Object.assign(Object.assign(Object.assign({}, baseParams), { min: attr.min, max: attr.max }), defaultParams), { array: attr.array }));
|
|
14427
14764
|
break;
|
|
14428
14765
|
case 'boolean':
|
|
14429
|
-
yield this.databases.createBooleanColumn(Object.assign(Object.assign({}, baseParams), {
|
|
14766
|
+
yield this.databases.createBooleanColumn(Object.assign(Object.assign(Object.assign({}, baseParams), defaultParams), { array: attr.array }));
|
|
14430
14767
|
break;
|
|
14431
14768
|
case 'datetime':
|
|
14432
|
-
yield this.databases.createDatetimeColumn(Object.assign(Object.assign({}, baseParams), {
|
|
14769
|
+
yield this.databases.createDatetimeColumn(Object.assign(Object.assign(Object.assign({}, baseParams), defaultParams), { array: attr.array }));
|
|
14433
14770
|
break;
|
|
14434
14771
|
case 'email':
|
|
14435
|
-
yield this.databases.createEmailColumn(Object.assign(Object.assign({}, baseParams), {
|
|
14772
|
+
yield this.databases.createEmailColumn(Object.assign(Object.assign(Object.assign({}, baseParams), defaultParams), { array: attr.array }));
|
|
14436
14773
|
break;
|
|
14437
14774
|
case 'enum':
|
|
14438
14775
|
if (!attr.elements) {
|
|
14439
14776
|
throw new Error('Enum column requires elements array');
|
|
14440
14777
|
}
|
|
14441
|
-
yield this.databases.createEnumColumn(Object.assign(Object.assign({}, baseParams), { elements: attr.elements,
|
|
14778
|
+
yield this.databases.createEnumColumn(Object.assign(Object.assign(Object.assign(Object.assign({}, baseParams), { elements: attr.elements }), defaultParams), { array: attr.array }));
|
|
14442
14779
|
break;
|
|
14443
14780
|
case 'url':
|
|
14444
|
-
yield this.databases.createUrlColumn(Object.assign(Object.assign({}, baseParams), {
|
|
14781
|
+
yield this.databases.createUrlColumn(Object.assign(Object.assign(Object.assign({}, baseParams), defaultParams), { array: attr.array }));
|
|
14445
14782
|
break;
|
|
14446
14783
|
case 'ip':
|
|
14447
|
-
yield this.databases.createIpColumn(Object.assign(Object.assign({}, baseParams), {
|
|
14784
|
+
yield this.databases.createIpColumn(Object.assign(Object.assign(Object.assign({}, baseParams), defaultParams), { array: attr.array }));
|
|
14448
14785
|
break;
|
|
14449
14786
|
case 'point':
|
|
14450
|
-
yield this.databases.createPointColumn(Object.assign(Object.assign({}, baseParams),
|
|
14787
|
+
yield this.databases.createPointColumn(Object.assign(Object.assign({}, baseParams), defaultParams));
|
|
14451
14788
|
break;
|
|
14452
14789
|
case 'line':
|
|
14453
|
-
yield this.databases.createLineColumn(Object.assign(Object.assign({}, baseParams),
|
|
14790
|
+
yield this.databases.createLineColumn(Object.assign(Object.assign({}, baseParams), defaultParams));
|
|
14454
14791
|
break;
|
|
14455
14792
|
case 'polygon':
|
|
14456
|
-
yield this.databases.createPolygonColumn(Object.assign(Object.assign({}, baseParams),
|
|
14793
|
+
yield this.databases.createPolygonColumn(Object.assign(Object.assign({}, baseParams), defaultParams));
|
|
14457
14794
|
break;
|
|
14458
14795
|
case 'relationship':
|
|
14459
14796
|
if (!attr.relatedCollectionId) {
|
|
@@ -25588,154 +25925,6 @@ class Realtime {
|
|
|
25588
25925
|
}
|
|
25589
25926
|
}
|
|
25590
25927
|
|
|
25591
|
-
/**
|
|
25592
|
-
* Helper class to generate permission strings for resources.
|
|
25593
|
-
*/
|
|
25594
|
-
class Permission {
|
|
25595
|
-
}
|
|
25596
|
-
/**
|
|
25597
|
-
* Generate read permission string for the provided role.
|
|
25598
|
-
*
|
|
25599
|
-
* @param {string} role
|
|
25600
|
-
* @returns {string}
|
|
25601
|
-
*/
|
|
25602
|
-
Permission.read = (role) => {
|
|
25603
|
-
return `read("${role}")`;
|
|
25604
|
-
};
|
|
25605
|
-
/**
|
|
25606
|
-
* Generate write permission string for the provided role.
|
|
25607
|
-
*
|
|
25608
|
-
* This is an alias of update, delete, and possibly create.
|
|
25609
|
-
* Don't use write in combination with update, delete, or create.
|
|
25610
|
-
*
|
|
25611
|
-
* @param {string} role
|
|
25612
|
-
* @returns {string}
|
|
25613
|
-
*/
|
|
25614
|
-
Permission.write = (role) => {
|
|
25615
|
-
return `write("${role}")`;
|
|
25616
|
-
};
|
|
25617
|
-
/**
|
|
25618
|
-
* Generate create permission string for the provided role.
|
|
25619
|
-
*
|
|
25620
|
-
* @param {string} role
|
|
25621
|
-
* @returns {string}
|
|
25622
|
-
*/
|
|
25623
|
-
Permission.create = (role) => {
|
|
25624
|
-
return `create("${role}")`;
|
|
25625
|
-
};
|
|
25626
|
-
/**
|
|
25627
|
-
* Generate update permission string for the provided role.
|
|
25628
|
-
*
|
|
25629
|
-
* @param {string} role
|
|
25630
|
-
* @returns {string}
|
|
25631
|
-
*/
|
|
25632
|
-
Permission.update = (role) => {
|
|
25633
|
-
return `update("${role}")`;
|
|
25634
|
-
};
|
|
25635
|
-
/**
|
|
25636
|
-
* Generate delete permission string for the provided role.
|
|
25637
|
-
*
|
|
25638
|
-
* @param {string} role
|
|
25639
|
-
* @returns {string}
|
|
25640
|
-
*/
|
|
25641
|
-
Permission.delete = (role) => {
|
|
25642
|
-
return `delete("${role}")`;
|
|
25643
|
-
};
|
|
25644
|
-
|
|
25645
|
-
/**
|
|
25646
|
-
* Helper class to generate role strings for `Permission`.
|
|
25647
|
-
*/
|
|
25648
|
-
class Role {
|
|
25649
|
-
/**
|
|
25650
|
-
* Grants access to anyone.
|
|
25651
|
-
*
|
|
25652
|
-
* This includes authenticated and unauthenticated users.
|
|
25653
|
-
*
|
|
25654
|
-
* @returns {string}
|
|
25655
|
-
*/
|
|
25656
|
-
static any() {
|
|
25657
|
-
return 'any';
|
|
25658
|
-
}
|
|
25659
|
-
/**
|
|
25660
|
-
* Grants access to a specific user by user ID.
|
|
25661
|
-
*
|
|
25662
|
-
* You can optionally pass verified or unverified for
|
|
25663
|
-
* `status` to target specific types of users.
|
|
25664
|
-
*
|
|
25665
|
-
* @param {string} id
|
|
25666
|
-
* @param {string} status
|
|
25667
|
-
* @returns {string}
|
|
25668
|
-
*/
|
|
25669
|
-
static user(id, status = '') {
|
|
25670
|
-
if (status === '') {
|
|
25671
|
-
return `user:${id}`;
|
|
25672
|
-
}
|
|
25673
|
-
return `user:${id}/${status}`;
|
|
25674
|
-
}
|
|
25675
|
-
/**
|
|
25676
|
-
* Grants access to any authenticated or anonymous user.
|
|
25677
|
-
*
|
|
25678
|
-
* You can optionally pass verified or unverified for
|
|
25679
|
-
* `status` to target specific types of users.
|
|
25680
|
-
*
|
|
25681
|
-
* @param {string} status
|
|
25682
|
-
* @returns {string}
|
|
25683
|
-
*/
|
|
25684
|
-
static users(status = '') {
|
|
25685
|
-
if (status === '') {
|
|
25686
|
-
return 'users';
|
|
25687
|
-
}
|
|
25688
|
-
return `users/${status}`;
|
|
25689
|
-
}
|
|
25690
|
-
/**
|
|
25691
|
-
* Grants access to any guest user without a session.
|
|
25692
|
-
*
|
|
25693
|
-
* Authenticated users don't have access to this role.
|
|
25694
|
-
*
|
|
25695
|
-
* @returns {string}
|
|
25696
|
-
*/
|
|
25697
|
-
static guests() {
|
|
25698
|
-
return 'guests';
|
|
25699
|
-
}
|
|
25700
|
-
/**
|
|
25701
|
-
* Grants access to a team by team ID.
|
|
25702
|
-
*
|
|
25703
|
-
* You can optionally pass a role for `role` to target
|
|
25704
|
-
* team members with the specified role.
|
|
25705
|
-
*
|
|
25706
|
-
* @param {string} id
|
|
25707
|
-
* @param {string} role
|
|
25708
|
-
* @returns {string}
|
|
25709
|
-
*/
|
|
25710
|
-
static team(id, role = '') {
|
|
25711
|
-
if (role === '') {
|
|
25712
|
-
return `team:${id}`;
|
|
25713
|
-
}
|
|
25714
|
-
return `team:${id}/${role}`;
|
|
25715
|
-
}
|
|
25716
|
-
/**
|
|
25717
|
-
* Grants access to a specific member of a team.
|
|
25718
|
-
*
|
|
25719
|
-
* When the member is removed from the team, they will
|
|
25720
|
-
* no longer have access.
|
|
25721
|
-
*
|
|
25722
|
-
* @param {string} id
|
|
25723
|
-
* @returns {string}
|
|
25724
|
-
*/
|
|
25725
|
-
static member(id) {
|
|
25726
|
-
return `member:${id}`;
|
|
25727
|
-
}
|
|
25728
|
-
/**
|
|
25729
|
-
* Grants access to a user with the specified label.
|
|
25730
|
-
*
|
|
25731
|
-
* @param {string} name
|
|
25732
|
-
* @returns {string}
|
|
25733
|
-
*/
|
|
25734
|
-
static label(name) {
|
|
25735
|
-
return `label:${name}`;
|
|
25736
|
-
}
|
|
25737
|
-
}
|
|
25738
|
-
|
|
25739
25928
|
var _a, _ID_hexTimestamp;
|
|
25740
25929
|
/**
|
|
25741
25930
|
* Helper class to generate ID strings for resources.
|