appwrite-utils-cli 1.5.2 → 1.6.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/CHANGELOG.md +199 -0
- package/README.md +251 -29
- package/dist/adapters/AdapterFactory.d.ts +10 -3
- package/dist/adapters/AdapterFactory.js +213 -17
- package/dist/adapters/TablesDBAdapter.js +60 -17
- package/dist/backups/operations/bucketBackup.d.ts +19 -0
- package/dist/backups/operations/bucketBackup.js +197 -0
- package/dist/backups/operations/collectionBackup.d.ts +30 -0
- package/dist/backups/operations/collectionBackup.js +201 -0
- package/dist/backups/operations/comprehensiveBackup.d.ts +25 -0
- package/dist/backups/operations/comprehensiveBackup.js +238 -0
- package/dist/backups/schemas/bucketManifest.d.ts +93 -0
- package/dist/backups/schemas/bucketManifest.js +33 -0
- package/dist/backups/schemas/comprehensiveManifest.d.ts +108 -0
- package/dist/backups/schemas/comprehensiveManifest.js +32 -0
- package/dist/backups/tracking/centralizedTracking.d.ts +34 -0
- package/dist/backups/tracking/centralizedTracking.js +274 -0
- package/dist/cli/commands/configCommands.d.ts +8 -0
- package/dist/cli/commands/configCommands.js +160 -0
- package/dist/cli/commands/databaseCommands.d.ts +13 -0
- package/dist/cli/commands/databaseCommands.js +478 -0
- package/dist/cli/commands/functionCommands.d.ts +7 -0
- package/dist/cli/commands/functionCommands.js +289 -0
- package/dist/cli/commands/schemaCommands.d.ts +7 -0
- package/dist/cli/commands/schemaCommands.js +134 -0
- package/dist/cli/commands/transferCommands.d.ts +5 -0
- package/dist/cli/commands/transferCommands.js +384 -0
- package/dist/collections/attributes.d.ts +5 -4
- package/dist/collections/attributes.js +539 -246
- package/dist/collections/indexes.js +39 -37
- package/dist/collections/methods.d.ts +2 -16
- package/dist/collections/methods.js +90 -538
- package/dist/collections/transferOperations.d.ts +7 -0
- package/dist/collections/transferOperations.js +331 -0
- package/dist/collections/wipeOperations.d.ts +16 -0
- package/dist/collections/wipeOperations.js +328 -0
- package/dist/config/configMigration.d.ts +87 -0
- package/dist/config/configMigration.js +390 -0
- package/dist/config/configValidation.d.ts +66 -0
- package/dist/config/configValidation.js +358 -0
- package/dist/config/yamlConfig.d.ts +455 -1
- package/dist/config/yamlConfig.js +145 -52
- package/dist/databases/methods.js +3 -2
- package/dist/databases/setup.d.ts +1 -2
- package/dist/databases/setup.js +9 -87
- package/dist/examples/yamlTerminologyExample.d.ts +42 -0
- package/dist/examples/yamlTerminologyExample.js +269 -0
- package/dist/functions/deployments.js +11 -10
- package/dist/functions/methods.d.ts +1 -1
- package/dist/functions/methods.js +5 -4
- package/dist/init.js +9 -9
- package/dist/interactiveCLI.d.ts +8 -17
- package/dist/interactiveCLI.js +181 -1172
- package/dist/main.js +364 -21
- package/dist/migrations/afterImportActions.js +22 -30
- package/dist/migrations/appwriteToX.js +71 -25
- package/dist/migrations/dataLoader.js +35 -26
- package/dist/migrations/importController.js +29 -30
- package/dist/migrations/relationships.js +13 -12
- package/dist/migrations/services/ImportOrchestrator.js +16 -19
- package/dist/migrations/transfer.js +46 -46
- package/dist/migrations/yaml/YamlImportConfigLoader.d.ts +3 -1
- package/dist/migrations/yaml/YamlImportConfigLoader.js +6 -3
- package/dist/migrations/yaml/YamlImportIntegration.d.ts +9 -3
- package/dist/migrations/yaml/YamlImportIntegration.js +22 -11
- package/dist/migrations/yaml/generateImportSchemas.d.ts +14 -1
- package/dist/migrations/yaml/generateImportSchemas.js +736 -7
- package/dist/schemas/authUser.d.ts +1 -1
- package/dist/setupController.js +3 -2
- package/dist/shared/backupMetadataSchema.d.ts +94 -0
- package/dist/shared/backupMetadataSchema.js +38 -0
- package/dist/shared/backupTracking.d.ts +18 -0
- package/dist/shared/backupTracking.js +176 -0
- package/dist/shared/confirmationDialogs.js +15 -15
- package/dist/shared/errorUtils.d.ts +54 -0
- package/dist/shared/errorUtils.js +95 -0
- package/dist/shared/functionManager.js +20 -19
- package/dist/shared/indexManager.js +12 -11
- package/dist/shared/jsonSchemaGenerator.js +10 -26
- package/dist/shared/logging.d.ts +51 -0
- package/dist/shared/logging.js +70 -0
- package/dist/shared/messageFormatter.d.ts +2 -0
- package/dist/shared/messageFormatter.js +10 -0
- package/dist/shared/migrationHelpers.d.ts +6 -16
- package/dist/shared/migrationHelpers.js +24 -21
- package/dist/shared/operationLogger.d.ts +8 -1
- package/dist/shared/operationLogger.js +11 -24
- package/dist/shared/operationQueue.d.ts +28 -1
- package/dist/shared/operationQueue.js +268 -66
- package/dist/shared/operationsTable.d.ts +26 -0
- package/dist/shared/operationsTable.js +286 -0
- package/dist/shared/operationsTableSchema.d.ts +48 -0
- package/dist/shared/operationsTableSchema.js +35 -0
- package/dist/shared/relationshipExtractor.d.ts +56 -0
- package/dist/shared/relationshipExtractor.js +138 -0
- package/dist/shared/schemaGenerator.d.ts +19 -1
- package/dist/shared/schemaGenerator.js +56 -75
- package/dist/storage/backupCompression.d.ts +20 -0
- package/dist/storage/backupCompression.js +67 -0
- package/dist/storage/methods.d.ts +16 -2
- package/dist/storage/methods.js +98 -14
- package/dist/users/methods.js +9 -8
- package/dist/utils/configDiscovery.d.ts +78 -0
- package/dist/utils/configDiscovery.js +430 -0
- package/dist/utils/directoryUtils.d.ts +22 -0
- package/dist/utils/directoryUtils.js +59 -0
- package/dist/utils/getClientFromConfig.d.ts +17 -8
- package/dist/utils/getClientFromConfig.js +162 -17
- package/dist/utils/helperFunctions.d.ts +16 -2
- package/dist/utils/helperFunctions.js +19 -5
- package/dist/utils/loadConfigs.d.ts +34 -9
- package/dist/utils/loadConfigs.js +236 -316
- package/dist/utils/pathResolvers.d.ts +53 -0
- package/dist/utils/pathResolvers.js +72 -0
- package/dist/utils/projectConfig.d.ts +119 -0
- package/dist/utils/projectConfig.js +171 -0
- package/dist/utils/retryFailedPromises.js +4 -2
- package/dist/utils/sessionAuth.d.ts +48 -0
- package/dist/utils/sessionAuth.js +164 -0
- package/dist/utils/sessionPreservationExample.d.ts +1666 -0
- package/dist/utils/sessionPreservationExample.js +101 -0
- package/dist/utils/setupFiles.js +301 -41
- package/dist/utils/typeGuards.d.ts +35 -0
- package/dist/utils/typeGuards.js +57 -0
- package/dist/utils/versionDetection.js +145 -9
- package/dist/utils/yamlConverter.d.ts +53 -3
- package/dist/utils/yamlConverter.js +232 -13
- package/dist/utils/yamlLoader.d.ts +70 -0
- package/dist/utils/yamlLoader.js +263 -0
- package/dist/utilsController.d.ts +36 -3
- package/dist/utilsController.js +186 -56
- package/package.json +12 -2
- package/src/adapters/AdapterFactory.ts +263 -35
- package/src/adapters/TablesDBAdapter.ts +225 -36
- package/src/backups/operations/bucketBackup.ts +277 -0
- package/src/backups/operations/collectionBackup.ts +310 -0
- package/src/backups/operations/comprehensiveBackup.ts +342 -0
- package/src/backups/schemas/bucketManifest.ts +78 -0
- package/src/backups/schemas/comprehensiveManifest.ts +76 -0
- package/src/backups/tracking/centralizedTracking.ts +352 -0
- package/src/cli/commands/configCommands.ts +194 -0
- package/src/cli/commands/databaseCommands.ts +635 -0
- package/src/cli/commands/functionCommands.ts +379 -0
- package/src/cli/commands/schemaCommands.ts +163 -0
- package/src/cli/commands/transferCommands.ts +457 -0
- package/src/collections/attributes.ts +900 -621
- package/src/collections/attributes.ts.backup +1555 -0
- package/src/collections/indexes.ts +116 -114
- package/src/collections/methods.ts +295 -968
- package/src/collections/transferOperations.ts +516 -0
- package/src/collections/wipeOperations.ts +501 -0
- package/src/config/README.md +274 -0
- package/src/config/configMigration.ts +575 -0
- package/src/config/configValidation.ts +445 -0
- package/src/config/yamlConfig.ts +168 -55
- package/src/databases/methods.ts +3 -2
- package/src/databases/setup.ts +11 -138
- package/src/examples/yamlTerminologyExample.ts +341 -0
- package/src/functions/deployments.ts +14 -12
- package/src/functions/methods.ts +11 -11
- package/src/functions/templates/hono-typescript/README.md +286 -0
- package/src/functions/templates/hono-typescript/package.json +26 -0
- package/src/functions/templates/hono-typescript/src/adapters/request.ts +74 -0
- package/src/functions/templates/hono-typescript/src/adapters/response.ts +106 -0
- package/src/functions/templates/hono-typescript/src/app.ts +180 -0
- package/src/functions/templates/hono-typescript/src/context.ts +103 -0
- package/src/functions/templates/hono-typescript/src/index.ts +54 -0
- package/src/functions/templates/hono-typescript/src/middleware/appwrite.ts +119 -0
- package/src/functions/templates/hono-typescript/tsconfig.json +20 -0
- package/src/functions/templates/typescript-node/package.json +2 -1
- package/src/functions/templates/typescript-node/src/context.ts +103 -0
- package/src/functions/templates/typescript-node/src/index.ts +18 -12
- package/src/functions/templates/uv/pyproject.toml +1 -0
- package/src/functions/templates/uv/src/context.py +125 -0
- package/src/functions/templates/uv/src/index.py +35 -5
- package/src/init.ts +9 -11
- package/src/interactiveCLI.ts +278 -1596
- package/src/main.ts +418 -24
- package/src/migrations/afterImportActions.ts +71 -44
- package/src/migrations/appwriteToX.ts +100 -34
- package/src/migrations/dataLoader.ts +48 -34
- package/src/migrations/importController.ts +44 -39
- package/src/migrations/relationships.ts +28 -18
- package/src/migrations/services/ImportOrchestrator.ts +24 -27
- package/src/migrations/transfer.ts +159 -121
- package/src/migrations/yaml/YamlImportConfigLoader.ts +11 -4
- package/src/migrations/yaml/YamlImportIntegration.ts +47 -20
- package/src/migrations/yaml/generateImportSchemas.ts +751 -12
- package/src/setupController.ts +3 -2
- package/src/shared/backupMetadataSchema.ts +93 -0
- package/src/shared/backupTracking.ts +211 -0
- package/src/shared/confirmationDialogs.ts +19 -19
- package/src/shared/errorUtils.ts +110 -0
- package/src/shared/functionManager.ts +21 -20
- package/src/shared/indexManager.ts +12 -11
- package/src/shared/jsonSchemaGenerator.ts +38 -52
- package/src/shared/logging.ts +75 -0
- package/src/shared/messageFormatter.ts +14 -1
- package/src/shared/migrationHelpers.ts +45 -38
- package/src/shared/operationLogger.ts +11 -36
- package/src/shared/operationQueue.ts +322 -93
- package/src/shared/operationsTable.ts +338 -0
- package/src/shared/operationsTableSchema.ts +60 -0
- package/src/shared/relationshipExtractor.ts +214 -0
- package/src/shared/schemaGenerator.ts +179 -219
- package/src/storage/backupCompression.ts +88 -0
- package/src/storage/methods.ts +131 -34
- package/src/users/methods.ts +11 -9
- package/src/utils/configDiscovery.ts +502 -0
- package/src/utils/directoryUtils.ts +61 -0
- package/src/utils/getClientFromConfig.ts +205 -22
- package/src/utils/helperFunctions.ts +23 -5
- package/src/utils/loadConfigs.ts +313 -345
- package/src/utils/pathResolvers.ts +81 -0
- package/src/utils/projectConfig.ts +299 -0
- package/src/utils/retryFailedPromises.ts +4 -2
- package/src/utils/sessionAuth.ts +230 -0
- package/src/utils/setupFiles.ts +322 -54
- package/src/utils/typeGuards.ts +65 -0
- package/src/utils/versionDetection.ts +218 -64
- package/src/utils/yamlConverter.ts +296 -13
- package/src/utils/yamlLoader.ts +364 -0
- package/src/utilsController.ts +314 -110
- package/tests/README.md +497 -0
- package/tests/adapters/AdapterFactory.test.ts +277 -0
- package/tests/integration/syncOperations.test.ts +463 -0
- package/tests/jest.config.js +25 -0
- package/tests/migration/configMigration.test.ts +546 -0
- package/tests/setup.ts +62 -0
- package/tests/testUtils.ts +340 -0
- package/tests/utils/loadConfigs.test.ts +350 -0
- package/tests/validation/configValidation.test.ts +412 -0
- package/src/utils/schemaStrings.ts +0 -517
@@ -5,9 +5,13 @@
|
|
5
5
|
* based on version detection and configuration. It handles dynamic SDK imports
|
6
6
|
* and provides a single entry point for all database operations.
|
7
7
|
*/
|
8
|
-
import { detectAppwriteVersionCached } from "../utils/versionDetection.js";
|
8
|
+
import { detectAppwriteVersionCached, isVersionAtLeast } from "../utils/versionDetection.js";
|
9
9
|
import { TablesDBAdapter } from './TablesDBAdapter.js';
|
10
10
|
import { LegacyAdapter } from './LegacyAdapter.js';
|
11
|
+
import { logger } from '../shared/logging.js';
|
12
|
+
import { getClientWithAuth } from '../utils/getClientFromConfig.js';
|
13
|
+
import { isValidSessionCookie } from '../utils/sessionAuth.js';
|
14
|
+
import { MessageFormatter } from '../shared/messageFormatter.js';
|
11
15
|
/**
|
12
16
|
* AdapterFactory - Main factory class for creating database adapters
|
13
17
|
*/
|
@@ -18,11 +22,32 @@ export class AdapterFactory {
|
|
18
22
|
* Create a database adapter based on configuration and detection
|
19
23
|
*/
|
20
24
|
static async create(config) {
|
25
|
+
const startTime = Date.now();
|
26
|
+
// Validate authentication configuration
|
27
|
+
this.validateAuthConfig(config);
|
21
28
|
const cacheKey = `${config.appwriteEndpoint}:${config.appwriteProject}:${config.apiMode || 'auto'}`;
|
29
|
+
logger.info('Creating database adapter', {
|
30
|
+
endpoint: config.appwriteEndpoint,
|
31
|
+
project: config.appwriteProject,
|
32
|
+
requestedApiMode: config.apiMode || 'auto',
|
33
|
+
authMethod: config.authMethod || 'auto',
|
34
|
+
hasSessionCookie: !!config.sessionCookie,
|
35
|
+
hasPreConfiguredClient: !!config.preConfiguredClient,
|
36
|
+
forceRefresh: config.forceRefresh,
|
37
|
+
cacheKey,
|
38
|
+
operation: 'AdapterFactory.create'
|
39
|
+
});
|
22
40
|
// Check cache first (unless force refresh)
|
23
41
|
if (!config.forceRefresh) {
|
24
42
|
const cached = this.getCachedAdapter(cacheKey);
|
25
43
|
if (cached) {
|
44
|
+
const cacheAge = Date.now() - cached.timestamp;
|
45
|
+
logger.info('Using cached adapter', {
|
46
|
+
cacheKey,
|
47
|
+
cacheAge,
|
48
|
+
apiMode: cached.adapter.getApiMode(),
|
49
|
+
operation: 'AdapterFactory.create'
|
50
|
+
});
|
26
51
|
return {
|
27
52
|
adapter: cached.adapter,
|
28
53
|
apiMode: cached.adapter.getApiMode(),
|
@@ -36,16 +61,67 @@ export class AdapterFactory {
|
|
36
61
|
if (config.apiMode && config.apiMode !== 'auto') {
|
37
62
|
// Use explicitly configured mode
|
38
63
|
apiMode = config.apiMode;
|
64
|
+
logger.info('Using explicitly configured API mode', {
|
65
|
+
apiMode,
|
66
|
+
endpoint: config.appwriteEndpoint,
|
67
|
+
operation: 'AdapterFactory.create'
|
68
|
+
});
|
39
69
|
}
|
40
70
|
else {
|
41
71
|
// Auto-detect API mode
|
42
|
-
|
72
|
+
logger.info('Starting API mode auto-detection', {
|
73
|
+
endpoint: config.appwriteEndpoint,
|
74
|
+
project: config.appwriteProject,
|
75
|
+
forceRefresh: config.forceRefresh,
|
76
|
+
operation: 'AdapterFactory.create'
|
77
|
+
});
|
78
|
+
const detectionStartTime = Date.now();
|
79
|
+
// For version detection, we need some form of authentication
|
80
|
+
const authKey = config.appwriteKey || '';
|
81
|
+
detectionResult = await detectAppwriteVersionCached(config.appwriteEndpoint, config.appwriteProject, authKey, config.forceRefresh);
|
82
|
+
const detectionDuration = Date.now() - detectionStartTime;
|
43
83
|
apiMode = detectionResult.apiMode;
|
84
|
+
logger.info('API mode detection completed', {
|
85
|
+
apiMode,
|
86
|
+
detectionMethod: detectionResult.detectionMethod,
|
87
|
+
confidence: detectionResult.confidence,
|
88
|
+
serverVersion: detectionResult.serverVersion,
|
89
|
+
detectionDuration,
|
90
|
+
endpoint: config.appwriteEndpoint,
|
91
|
+
operation: 'AdapterFactory.create'
|
92
|
+
});
|
93
|
+
// Add version-based safety check to prevent using TablesDB on old servers
|
94
|
+
if (detectionResult.serverVersion &&
|
95
|
+
!isVersionAtLeast(detectionResult.serverVersion, '1.8.0') &&
|
96
|
+
apiMode === 'tablesdb') {
|
97
|
+
logger.warn('Overriding TablesDB detection - server version too old', {
|
98
|
+
serverVersion: detectionResult.serverVersion,
|
99
|
+
detectedMode: apiMode,
|
100
|
+
overrideMode: 'legacy',
|
101
|
+
operation: 'AdapterFactory.create'
|
102
|
+
});
|
103
|
+
apiMode = 'legacy';
|
104
|
+
}
|
44
105
|
}
|
45
106
|
// Create appropriate adapter
|
107
|
+
logger.info('Creating adapter instance', {
|
108
|
+
apiMode,
|
109
|
+
endpoint: config.appwriteEndpoint,
|
110
|
+
operation: 'AdapterFactory.create'
|
111
|
+
});
|
112
|
+
const adapterStartTime = Date.now();
|
46
113
|
const result = await this.createAdapter(config, apiMode);
|
114
|
+
const adapterDuration = Date.now() - adapterStartTime;
|
47
115
|
// Cache the result
|
48
116
|
this.setCachedAdapter(cacheKey, result.adapter);
|
117
|
+
const totalDuration = Date.now() - startTime;
|
118
|
+
logger.info('Adapter creation completed', {
|
119
|
+
apiMode,
|
120
|
+
adapterDuration,
|
121
|
+
totalDuration,
|
122
|
+
cached: true,
|
123
|
+
operation: 'AdapterFactory.create'
|
124
|
+
});
|
49
125
|
return {
|
50
126
|
...result,
|
51
127
|
apiMode,
|
@@ -79,20 +155,67 @@ export class AdapterFactory {
|
|
79
155
|
* Create TablesDB adapter with dynamic import
|
80
156
|
*/
|
81
157
|
static async createTablesDBAdapter(config) {
|
158
|
+
const startTime = Date.now();
|
82
159
|
try {
|
160
|
+
logger.info('Loading TablesDB SDK', {
|
161
|
+
endpoint: config.appwriteEndpoint,
|
162
|
+
operation: 'createTablesDBAdapter'
|
163
|
+
});
|
83
164
|
// Dynamic import of TablesDB SDK
|
165
|
+
const importStartTime = Date.now();
|
84
166
|
const { Client, TablesDB } = await import('node-appwrite-tablesdb');
|
85
|
-
const
|
86
|
-
|
87
|
-
|
88
|
-
|
167
|
+
const importDuration = Date.now() - importStartTime;
|
168
|
+
logger.debug('TablesDB SDK import successful', {
|
169
|
+
importDuration,
|
170
|
+
operation: 'createTablesDBAdapter'
|
171
|
+
});
|
172
|
+
// Use pre-configured client or create session-aware client with TablesDB Client
|
173
|
+
let client;
|
174
|
+
if (config.preConfiguredClient) {
|
175
|
+
client = config.preConfiguredClient;
|
176
|
+
}
|
177
|
+
else {
|
178
|
+
client = new Client()
|
179
|
+
.setEndpoint(config.appwriteEndpoint)
|
180
|
+
.setProject(config.appwriteProject);
|
181
|
+
// Set authentication method based on priority
|
182
|
+
if (config.sessionCookie && isValidSessionCookie(config.sessionCookie)) {
|
183
|
+
client.setSession(config.sessionCookie);
|
184
|
+
logger.debug('Using session authentication for TablesDB adapter', {
|
185
|
+
project: config.appwriteProject,
|
186
|
+
operation: 'createTablesDBAdapter'
|
187
|
+
});
|
188
|
+
}
|
189
|
+
else if (config.appwriteKey) {
|
190
|
+
client.setKey(config.appwriteKey);
|
191
|
+
logger.debug('Using API key authentication for TablesDB adapter', {
|
192
|
+
project: config.appwriteProject,
|
193
|
+
operation: 'createTablesDBAdapter'
|
194
|
+
});
|
195
|
+
}
|
196
|
+
}
|
89
197
|
const tablesDB = new TablesDB(client);
|
90
198
|
const adapter = new TablesDBAdapter(tablesDB);
|
199
|
+
const totalDuration = Date.now() - startTime;
|
200
|
+
logger.info('TablesDB adapter created successfully', {
|
201
|
+
totalDuration,
|
202
|
+
importDuration,
|
203
|
+
endpoint: config.appwriteEndpoint,
|
204
|
+
operation: 'createTablesDBAdapter'
|
205
|
+
});
|
91
206
|
return { adapter, client };
|
92
207
|
}
|
93
208
|
catch (error) {
|
94
|
-
|
95
|
-
|
209
|
+
const errorDuration = Date.now() - startTime;
|
210
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
211
|
+
MessageFormatter.warning('Failed to create TablesDB adapter - falling back to legacy', { prefix: "Adapter" });
|
212
|
+
logger.warn('TablesDB adapter creation failed, falling back to legacy', {
|
213
|
+
error: errorMessage,
|
214
|
+
errorDuration,
|
215
|
+
endpoint: config.appwriteEndpoint,
|
216
|
+
operation: 'createTablesDBAdapter'
|
217
|
+
});
|
218
|
+
// Fallback to legacy adapter if TablesDB creation fails
|
96
219
|
return this.createLegacyAdapter(config);
|
97
220
|
}
|
98
221
|
}
|
@@ -100,19 +223,66 @@ export class AdapterFactory {
|
|
100
223
|
* Create Legacy adapter with dynamic import
|
101
224
|
*/
|
102
225
|
static async createLegacyAdapter(config) {
|
226
|
+
const startTime = Date.now();
|
103
227
|
try {
|
228
|
+
logger.info('Loading legacy Appwrite SDK', {
|
229
|
+
endpoint: config.appwriteEndpoint,
|
230
|
+
operation: 'createLegacyAdapter'
|
231
|
+
});
|
104
232
|
// Dynamic import of legacy SDK
|
233
|
+
const importStartTime = Date.now();
|
105
234
|
const { Client, Databases } = await import('node-appwrite');
|
106
|
-
const
|
107
|
-
|
108
|
-
|
109
|
-
|
235
|
+
const importDuration = Date.now() - importStartTime;
|
236
|
+
logger.debug('Legacy SDK import successful', {
|
237
|
+
importDuration,
|
238
|
+
operation: 'createLegacyAdapter'
|
239
|
+
});
|
240
|
+
// Use pre-configured client or create session-aware client with Legacy Client
|
241
|
+
let client;
|
242
|
+
if (config.preConfiguredClient) {
|
243
|
+
client = config.preConfiguredClient;
|
244
|
+
}
|
245
|
+
else {
|
246
|
+
client = new Client()
|
247
|
+
.setEndpoint(config.appwriteEndpoint)
|
248
|
+
.setProject(config.appwriteProject);
|
249
|
+
// Set authentication method based on priority
|
250
|
+
if (config.sessionCookie && isValidSessionCookie(config.sessionCookie)) {
|
251
|
+
client.setSession(config.sessionCookie);
|
252
|
+
logger.debug('Using session authentication for Legacy adapter', {
|
253
|
+
project: config.appwriteProject,
|
254
|
+
operation: 'createLegacyAdapter'
|
255
|
+
});
|
256
|
+
}
|
257
|
+
else if (config.appwriteKey) {
|
258
|
+
client.setKey(config.appwriteKey);
|
259
|
+
logger.debug('Using API key authentication for Legacy adapter', {
|
260
|
+
project: config.appwriteProject,
|
261
|
+
operation: 'createLegacyAdapter'
|
262
|
+
});
|
263
|
+
}
|
264
|
+
}
|
110
265
|
const databases = new Databases(client);
|
111
266
|
const adapter = new LegacyAdapter(databases);
|
267
|
+
const totalDuration = Date.now() - startTime;
|
268
|
+
logger.info('Legacy adapter created successfully', {
|
269
|
+
totalDuration,
|
270
|
+
importDuration,
|
271
|
+
endpoint: config.appwriteEndpoint,
|
272
|
+
operation: 'createLegacyAdapter'
|
273
|
+
});
|
112
274
|
return { adapter, client };
|
113
275
|
}
|
114
276
|
catch (error) {
|
115
|
-
|
277
|
+
const errorDuration = Date.now() - startTime;
|
278
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
279
|
+
logger.error('Failed to load legacy Appwrite SDK', {
|
280
|
+
error: errorMessage,
|
281
|
+
errorDuration,
|
282
|
+
endpoint: config.appwriteEndpoint,
|
283
|
+
operation: 'createLegacyAdapter'
|
284
|
+
});
|
285
|
+
throw new Error(`Failed to load legacy Appwrite SDK: ${errorMessage}`);
|
116
286
|
}
|
117
287
|
}
|
118
288
|
/**
|
@@ -145,6 +315,31 @@ export class AdapterFactory {
|
|
145
315
|
static clearCache() {
|
146
316
|
this.cache.clear();
|
147
317
|
}
|
318
|
+
/**
|
319
|
+
* Validate authentication configuration
|
320
|
+
*/
|
321
|
+
static validateAuthConfig(config) {
|
322
|
+
const hasApiKey = config.appwriteKey && config.appwriteKey.trim().length > 0;
|
323
|
+
const hasSessionCookie = config.sessionCookie && isValidSessionCookie(config.sessionCookie);
|
324
|
+
const hasPreConfiguredClient = !!config.preConfiguredClient;
|
325
|
+
// Must have at least one authentication method
|
326
|
+
if (!hasApiKey && !hasSessionCookie && !hasPreConfiguredClient) {
|
327
|
+
throw new Error(`No valid authentication method provided for project ${config.appwriteProject}. ` +
|
328
|
+
`Please provide an API key, session cookie, or pre-configured client.`);
|
329
|
+
}
|
330
|
+
// Validate session cookie format if provided
|
331
|
+
if (config.sessionCookie && !isValidSessionCookie(config.sessionCookie)) {
|
332
|
+
throw new Error(`Invalid session cookie format provided for project ${config.appwriteProject}. ` +
|
333
|
+
`Session cookie must be a valid JWT token.`);
|
334
|
+
}
|
335
|
+
logger.debug('Authentication configuration validated', {
|
336
|
+
hasApiKey,
|
337
|
+
hasSessionCookie,
|
338
|
+
hasPreConfiguredClient,
|
339
|
+
authMethod: config.authMethod || 'auto',
|
340
|
+
operation: 'validateAuthConfig'
|
341
|
+
});
|
342
|
+
}
|
148
343
|
/**
|
149
344
|
* Test connection and API capabilities
|
150
345
|
*/
|
@@ -185,20 +380,21 @@ export class AdapterFactory {
|
|
185
380
|
/**
|
186
381
|
* Convenience function for quick adapter creation
|
187
382
|
*/
|
188
|
-
export async function createDatabaseAdapter(endpoint, project, apiKey, mode = 'auto') {
|
383
|
+
export async function createDatabaseAdapter(endpoint, project, apiKey, mode = 'auto', sessionCookie) {
|
189
384
|
const result = await AdapterFactory.create({
|
190
385
|
appwriteEndpoint: endpoint,
|
191
386
|
appwriteProject: project,
|
192
387
|
appwriteKey: apiKey,
|
193
|
-
apiMode: mode
|
388
|
+
apiMode: mode,
|
389
|
+
sessionCookie
|
194
390
|
});
|
195
391
|
return result.adapter;
|
196
392
|
}
|
197
393
|
/**
|
198
394
|
* Helper function to get adapter metadata without creating full adapter
|
199
395
|
*/
|
200
|
-
export async function getApiCapabilities(endpoint, project, apiKey) {
|
201
|
-
const adapter = await createDatabaseAdapter(endpoint, project, apiKey, 'auto');
|
396
|
+
export async function getApiCapabilities(endpoint, project, apiKey, sessionCookie) {
|
397
|
+
const adapter = await createDatabaseAdapter(endpoint, project, apiKey, 'auto', sessionCookie);
|
202
398
|
const metadata = adapter.getMetadata();
|
203
399
|
const capabilities = [];
|
204
400
|
if (metadata.capabilities.bulkOperations)
|
@@ -32,7 +32,14 @@ export class TablesDBAdapter extends BaseAdapter {
|
|
32
32
|
}
|
33
33
|
async createRow(params) {
|
34
34
|
try {
|
35
|
-
|
35
|
+
// Remap 'id' to 'rowId' for TablesDB SDK compatibility
|
36
|
+
const result = await this.tablesDB.createRow({
|
37
|
+
databaseId: params.databaseId,
|
38
|
+
tableId: params.tableId,
|
39
|
+
rowId: params.id,
|
40
|
+
data: params.data,
|
41
|
+
permissions: params.permissions
|
42
|
+
});
|
36
43
|
return {
|
37
44
|
data: result,
|
38
45
|
rows: [result]
|
@@ -44,7 +51,7 @@ export class TablesDBAdapter extends BaseAdapter {
|
|
44
51
|
}
|
45
52
|
async updateRow(params) {
|
46
53
|
try {
|
47
|
-
const result = await this.tablesDB.updateRow(params);
|
54
|
+
const result = await this.tablesDB.updateRow(params.databaseId, params.tableId, params.id, params.data, params.permissions || []);
|
48
55
|
return {
|
49
56
|
data: result,
|
50
57
|
rows: [result]
|
@@ -56,7 +63,7 @@ export class TablesDBAdapter extends BaseAdapter {
|
|
56
63
|
}
|
57
64
|
async deleteRow(params) {
|
58
65
|
try {
|
59
|
-
const result = await this.tablesDB.deleteRow(params);
|
66
|
+
const result = await this.tablesDB.deleteRow(params.databaseId, params.tableId, params.id);
|
60
67
|
return { data: result };
|
61
68
|
}
|
62
69
|
catch (error) {
|
@@ -65,7 +72,7 @@ export class TablesDBAdapter extends BaseAdapter {
|
|
65
72
|
}
|
66
73
|
async getRow(params) {
|
67
74
|
try {
|
68
|
-
const result = await this.tablesDB.getRow(params);
|
75
|
+
const result = await this.tablesDB.getRow(params.databaseId, params.tableId, params.id);
|
69
76
|
return {
|
70
77
|
data: result,
|
71
78
|
rows: [result]
|
@@ -91,7 +98,8 @@ export class TablesDBAdapter extends BaseAdapter {
|
|
91
98
|
}
|
92
99
|
async createTable(params) {
|
93
100
|
try {
|
94
|
-
const result = await this.tablesDB.createTable(params
|
101
|
+
const result = await this.tablesDB.createTable(params.databaseId, params.id, // tableId
|
102
|
+
params.name, params.permissions || [], params.documentSecurity ?? false, params.enabled ?? true);
|
95
103
|
return {
|
96
104
|
data: result,
|
97
105
|
tables: [result]
|
@@ -103,7 +111,8 @@ export class TablesDBAdapter extends BaseAdapter {
|
|
103
111
|
}
|
104
112
|
async updateTable(params) {
|
105
113
|
try {
|
106
|
-
const result = await this.tablesDB.updateTable(params
|
114
|
+
const result = await this.tablesDB.updateTable(params.databaseId, params.id, // tableId
|
115
|
+
params.name, params.permissions, params.documentSecurity, params.enabled);
|
107
116
|
return {
|
108
117
|
data: result,
|
109
118
|
tables: [result]
|
@@ -115,7 +124,7 @@ export class TablesDBAdapter extends BaseAdapter {
|
|
115
124
|
}
|
116
125
|
async deleteTable(params) {
|
117
126
|
try {
|
118
|
-
const result = await this.tablesDB.deleteTable(params);
|
127
|
+
const result = await this.tablesDB.deleteTable(params.databaseId, params.tableId);
|
119
128
|
return { data: result };
|
120
129
|
}
|
121
130
|
catch (error) {
|
@@ -124,7 +133,7 @@ export class TablesDBAdapter extends BaseAdapter {
|
|
124
133
|
}
|
125
134
|
async getTable(params) {
|
126
135
|
try {
|
127
|
-
const result = await this.tablesDB.getTable(params);
|
136
|
+
const result = await this.tablesDB.getTable(params.databaseId, params.tableId);
|
128
137
|
return {
|
129
138
|
data: result,
|
130
139
|
tables: [result]
|
@@ -149,7 +158,7 @@ export class TablesDBAdapter extends BaseAdapter {
|
|
149
158
|
}
|
150
159
|
async createIndex(params) {
|
151
160
|
try {
|
152
|
-
const result = await this.tablesDB.createIndex(params);
|
161
|
+
const result = await this.tablesDB.createIndex(params.databaseId, params.tableId, params.key, params.type, params.attributes, params.orders || []);
|
153
162
|
return { data: result };
|
154
163
|
}
|
155
164
|
catch (error) {
|
@@ -158,7 +167,7 @@ export class TablesDBAdapter extends BaseAdapter {
|
|
158
167
|
}
|
159
168
|
async deleteIndex(params) {
|
160
169
|
try {
|
161
|
-
const result = await this.tablesDB.deleteIndex(params);
|
170
|
+
const result = await this.tablesDB.deleteIndex(params.databaseId, params.tableId, params.key);
|
162
171
|
return { data: result };
|
163
172
|
}
|
164
173
|
catch (error) {
|
@@ -168,9 +177,43 @@ export class TablesDBAdapter extends BaseAdapter {
|
|
168
177
|
// Attribute Operations
|
169
178
|
async createAttribute(params) {
|
170
179
|
try {
|
171
|
-
//
|
172
|
-
|
173
|
-
|
180
|
+
// TablesDB uses type-specific attribute methods like the legacy SDK
|
181
|
+
let result;
|
182
|
+
switch (params.type.toLowerCase()) {
|
183
|
+
case 'string':
|
184
|
+
result = await this.tablesDB.createStringAttribute(params.databaseId, params.tableId, params.key, params.size || 255, params.required ?? false, params.default, params.array ?? false, params.encrypt ?? false);
|
185
|
+
break;
|
186
|
+
case 'integer':
|
187
|
+
result = await this.tablesDB.createIntegerAttribute(params.databaseId, params.tableId, params.key, params.required ?? false, params.min, params.max, params.default, params.array ?? false);
|
188
|
+
break;
|
189
|
+
case 'float':
|
190
|
+
case 'double':
|
191
|
+
result = await this.tablesDB.createFloatAttribute(params.databaseId, params.tableId, params.key, params.required ?? false, params.min, params.max, params.default, params.array ?? false);
|
192
|
+
break;
|
193
|
+
case 'boolean':
|
194
|
+
result = await this.tablesDB.createBooleanAttribute(params.databaseId, params.tableId, params.key, params.required ?? false, params.default, params.array ?? false);
|
195
|
+
break;
|
196
|
+
case 'datetime':
|
197
|
+
result = await this.tablesDB.createDatetimeAttribute(params.databaseId, params.tableId, params.key, params.required ?? false, params.default, params.array ?? false);
|
198
|
+
break;
|
199
|
+
case 'email':
|
200
|
+
result = await this.tablesDB.createEmailAttribute(params.databaseId, params.tableId, params.key, params.required ?? false, params.default, params.array ?? false);
|
201
|
+
break;
|
202
|
+
case 'enum':
|
203
|
+
result = await this.tablesDB.createEnumAttribute(params.databaseId, params.tableId, params.key, params.elements || [], params.required ?? false, params.default, params.array ?? false);
|
204
|
+
break;
|
205
|
+
case 'ip':
|
206
|
+
result = await this.tablesDB.createIpAttribute(params.databaseId, params.tableId, params.key, params.required ?? false, params.default, params.array ?? false);
|
207
|
+
break;
|
208
|
+
case 'url':
|
209
|
+
result = await this.tablesDB.createUrlAttribute(params.databaseId, params.tableId, params.key, params.required ?? false, params.default, params.array ?? false);
|
210
|
+
break;
|
211
|
+
case 'relationship':
|
212
|
+
result = await this.tablesDB.createRelationshipAttribute(params.databaseId, params.tableId, params.key, params.relatedCollection || '', params.type || 'oneToOne', params.twoWay ?? false, params.onDelete || 'restrict');
|
213
|
+
break;
|
214
|
+
default:
|
215
|
+
throw new AdapterError(`Unsupported attribute type: ${params.type}`, 'UNSUPPORTED_ATTRIBUTE_TYPE');
|
216
|
+
}
|
174
217
|
return { data: result };
|
175
218
|
}
|
176
219
|
catch (error) {
|
@@ -179,8 +222,9 @@ export class TablesDBAdapter extends BaseAdapter {
|
|
179
222
|
}
|
180
223
|
async updateAttribute(params) {
|
181
224
|
try {
|
182
|
-
|
183
|
-
|
225
|
+
// TablesDB uses type-specific update methods or generic updateAttribute with positional params
|
226
|
+
// Try type-specific first, fallback to generic
|
227
|
+
const result = await this.tablesDB.updateStringAttribute(params.databaseId, params.tableId, params.key, params.required ?? false, params.default);
|
184
228
|
return { data: result };
|
185
229
|
}
|
186
230
|
catch (error) {
|
@@ -189,8 +233,7 @@ export class TablesDBAdapter extends BaseAdapter {
|
|
189
233
|
}
|
190
234
|
async deleteAttribute(params) {
|
191
235
|
try {
|
192
|
-
const
|
193
|
-
const result = await fn.call(this.tablesDB, params);
|
236
|
+
const result = await this.tablesDB.deleteAttribute(params.databaseId, params.tableId, params.key);
|
194
237
|
return { data: result };
|
195
238
|
}
|
196
239
|
catch (error) {
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import type { Storage } from "node-appwrite";
|
2
|
+
export interface BucketBackupOptions {
|
3
|
+
compressionLevel?: number;
|
4
|
+
parallelDownloads?: number;
|
5
|
+
onProgress?: (current: number, total: number, fileName: string) => void;
|
6
|
+
}
|
7
|
+
export interface BucketBackupResult {
|
8
|
+
backupFileId: string;
|
9
|
+
manifestFileId: string;
|
10
|
+
fileCount: number;
|
11
|
+
totalSizeBytes: number;
|
12
|
+
zipSizeBytes: number;
|
13
|
+
status: 'completed' | 'partial' | 'failed';
|
14
|
+
errors?: string[];
|
15
|
+
}
|
16
|
+
/**
|
17
|
+
* Downloads all files from a bucket in parallel and creates a ZIP backup
|
18
|
+
*/
|
19
|
+
export declare function backupBucket(storage: Storage, bucketId: string, backupBucketId: string, options?: BucketBackupOptions): Promise<BucketBackupResult>;
|