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