appwrite-utils-cli 1.7.9 → 1.8.2

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.
Files changed (70) hide show
  1. package/CHANGELOG.md +14 -199
  2. package/README.md +87 -30
  3. package/dist/adapters/AdapterFactory.js +5 -25
  4. package/dist/adapters/DatabaseAdapter.d.ts +17 -2
  5. package/dist/adapters/LegacyAdapter.d.ts +2 -1
  6. package/dist/adapters/LegacyAdapter.js +212 -16
  7. package/dist/adapters/TablesDBAdapter.d.ts +2 -12
  8. package/dist/adapters/TablesDBAdapter.js +261 -57
  9. package/dist/cli/commands/databaseCommands.js +4 -3
  10. package/dist/cli/commands/functionCommands.js +17 -8
  11. package/dist/collections/attributes.js +447 -125
  12. package/dist/collections/methods.js +197 -186
  13. package/dist/collections/tableOperations.d.ts +86 -0
  14. package/dist/collections/tableOperations.js +434 -0
  15. package/dist/collections/transferOperations.d.ts +3 -2
  16. package/dist/collections/transferOperations.js +93 -12
  17. package/dist/config/yamlConfig.d.ts +221 -88
  18. package/dist/examples/yamlTerminologyExample.d.ts +1 -1
  19. package/dist/examples/yamlTerminologyExample.js +6 -3
  20. package/dist/functions/fnConfigDiscovery.d.ts +3 -0
  21. package/dist/functions/fnConfigDiscovery.js +108 -0
  22. package/dist/interactiveCLI.js +18 -15
  23. package/dist/main.js +211 -73
  24. package/dist/migrations/appwriteToX.d.ts +88 -23
  25. package/dist/migrations/comprehensiveTransfer.d.ts +2 -0
  26. package/dist/migrations/comprehensiveTransfer.js +83 -6
  27. package/dist/migrations/dataLoader.d.ts +227 -69
  28. package/dist/migrations/dataLoader.js +3 -3
  29. package/dist/migrations/importController.js +3 -3
  30. package/dist/migrations/relationships.d.ts +8 -2
  31. package/dist/migrations/services/ImportOrchestrator.js +3 -3
  32. package/dist/migrations/transfer.js +159 -37
  33. package/dist/shared/attributeMapper.d.ts +20 -0
  34. package/dist/shared/attributeMapper.js +203 -0
  35. package/dist/shared/selectionDialogs.js +8 -4
  36. package/dist/storage/schemas.d.ts +354 -92
  37. package/dist/utils/configDiscovery.js +4 -3
  38. package/dist/utils/versionDetection.d.ts +0 -4
  39. package/dist/utils/versionDetection.js +41 -173
  40. package/dist/utils/yamlConverter.js +89 -16
  41. package/dist/utils/yamlLoader.d.ts +1 -1
  42. package/dist/utils/yamlLoader.js +6 -2
  43. package/dist/utilsController.js +56 -19
  44. package/package.json +4 -4
  45. package/src/adapters/AdapterFactory.ts +119 -143
  46. package/src/adapters/DatabaseAdapter.ts +18 -3
  47. package/src/adapters/LegacyAdapter.ts +236 -105
  48. package/src/adapters/TablesDBAdapter.ts +773 -643
  49. package/src/cli/commands/databaseCommands.ts +13 -12
  50. package/src/cli/commands/functionCommands.ts +23 -14
  51. package/src/collections/attributes.ts +2054 -1611
  52. package/src/collections/methods.ts +208 -293
  53. package/src/collections/tableOperations.ts +506 -0
  54. package/src/collections/transferOperations.ts +218 -144
  55. package/src/examples/yamlTerminologyExample.ts +10 -5
  56. package/src/functions/fnConfigDiscovery.ts +103 -0
  57. package/src/interactiveCLI.ts +25 -20
  58. package/src/main.ts +549 -194
  59. package/src/migrations/comprehensiveTransfer.ts +126 -50
  60. package/src/migrations/dataLoader.ts +3 -3
  61. package/src/migrations/importController.ts +3 -3
  62. package/src/migrations/services/ImportOrchestrator.ts +3 -3
  63. package/src/migrations/transfer.ts +148 -131
  64. package/src/shared/attributeMapper.ts +229 -0
  65. package/src/shared/selectionDialogs.ts +29 -25
  66. package/src/utils/configDiscovery.ts +9 -3
  67. package/src/utils/versionDetection.ts +74 -228
  68. package/src/utils/yamlConverter.ts +94 -17
  69. package/src/utils/yamlLoader.ts +11 -4
  70. package/src/utilsController.ts +80 -30
@@ -7,14 +7,14 @@
7
7
  */
8
8
 
9
9
  import type { AppwriteConfig } from "appwrite-utils";
10
- import { detectAppwriteVersionCached, isVersionAtLeast, type ApiMode, type VersionDetectionResult } from "../utils/versionDetection.js";
11
- import type { DatabaseAdapter } from './DatabaseAdapter.js';
12
- import { TablesDBAdapter } from './TablesDBAdapter.js';
13
- import { LegacyAdapter } from './LegacyAdapter.js';
14
- import { logger } from '../shared/logging.js';
15
- import { getClientWithAuth } from '../utils/getClientFromConfig.js';
16
- import { isValidSessionCookie } from '../utils/sessionAuth.js';
17
- import { MessageFormatter } from '../shared/messageFormatter.js';
10
+ import { detectAppwriteVersionCached, isVersionAtLeast, type ApiMode, type VersionDetectionResult } from "../utils/versionDetection.js";
11
+ import type { DatabaseAdapter } from './DatabaseAdapter.js';
12
+ import { TablesDBAdapter } from './TablesDBAdapter.js';
13
+ import { LegacyAdapter } from './LegacyAdapter.js';
14
+ import { logger } from '../shared/logging.js';
15
+ import { isValidSessionCookie } from '../utils/sessionAuth.js';
16
+ import { MessageFormatter } from '../shared/messageFormatter.js';
17
+ import { Client } from 'node-appwrite';
18
18
 
19
19
  export interface AdapterFactoryConfig {
20
20
  appwriteEndpoint: string;
@@ -201,73 +201,61 @@ export class AdapterFactory {
201
201
  /**
202
202
  * Create TablesDB adapter with dynamic import
203
203
  */
204
- private static async createTablesDBAdapter(
205
- config: AdapterFactoryConfig
206
- ): Promise<{ adapter: DatabaseAdapter; client: any }> {
207
- const startTime = Date.now();
208
-
209
- try {
210
- logger.info('Loading TablesDB SDK', {
211
- endpoint: config.appwriteEndpoint,
212
- operation: 'createTablesDBAdapter'
213
- });
214
-
215
- // Dynamic import of TablesDB SDK
216
- const importStartTime = Date.now();
217
- const { Client, TablesDB } = await import('node-appwrite-tablesdb');
218
- const importDuration = Date.now() - importStartTime;
219
-
220
- logger.debug('TablesDB SDK import successful', {
221
- importDuration,
222
- operation: 'createTablesDBAdapter'
223
- });
224
-
225
- // Use pre-configured client or create session-aware client with TablesDB Client
226
- let client: any;
227
- if (config.preConfiguredClient) {
228
- client = config.preConfiguredClient;
229
- } else {
230
- client = new Client()
231
- .setEndpoint(config.appwriteEndpoint)
232
- .setProject(config.appwriteProject);
233
-
234
- // Set authentication method with mode headers
235
- // Prefer session with admin mode, fallback to API key with default mode
236
- if (config.sessionCookie && isValidSessionCookie(config.sessionCookie)) {
237
- client.setSession(config.sessionCookie);
238
- client.headers['X-Appwrite-Mode'] = 'admin';
239
- logger.debug('Using session authentication for TablesDB adapter', {
240
- project: config.appwriteProject,
241
- operation: 'createTablesDBAdapter'
242
- });
243
- } else if (config.appwriteKey) {
244
- client.setKey(config.appwriteKey);
245
- client.headers['X-Appwrite-Mode'] = 'default';
246
- logger.debug('Using API key authentication for TablesDB adapter', {
247
- project: config.appwriteProject,
248
- operation: 'createTablesDBAdapter'
249
- });
250
- } else {
251
- throw new Error("No authentication available for adapter");
252
- }
253
- }
254
-
255
- const tablesDB = new TablesDB(client);
256
- const adapter = new TablesDBAdapter(tablesDB);
257
-
258
- const totalDuration = Date.now() - startTime;
259
- logger.info('TablesDB adapter created successfully', {
260
- totalDuration,
261
- importDuration,
262
- endpoint: config.appwriteEndpoint,
263
- operation: 'createTablesDBAdapter'
264
- });
265
-
266
- return { adapter, client };
267
-
268
- } catch (error) {
269
- const errorDuration = Date.now() - startTime;
270
- const errorMessage = error instanceof Error ? error.message : 'Unknown error';
204
+ private static async createTablesDBAdapter(
205
+ config: AdapterFactoryConfig
206
+ ): Promise<{ adapter: DatabaseAdapter; client: any }> {
207
+ const startTime = Date.now();
208
+
209
+ try {
210
+ logger.info('Creating TablesDB adapter (static SDK imports)', {
211
+ endpoint: config.appwriteEndpoint,
212
+ operation: 'createTablesDBAdapter'
213
+ });
214
+
215
+ // Use pre-configured client or create session-aware client with TablesDB Client
216
+ let client: any;
217
+ if (config.preConfiguredClient) {
218
+ client = config.preConfiguredClient;
219
+ } else {
220
+ client = new Client()
221
+ .setEndpoint(config.appwriteEndpoint)
222
+ .setProject(config.appwriteProject);
223
+
224
+ // Set authentication method with mode headers
225
+ // Prefer session with admin mode, fallback to API key with default mode
226
+ if (config.sessionCookie && isValidSessionCookie(config.sessionCookie)) {
227
+ client.setSession(config.sessionCookie);
228
+ client.headers['X-Appwrite-Mode'] = 'admin';
229
+ logger.debug('Using session authentication for TablesDB adapter', {
230
+ project: config.appwriteProject,
231
+ operation: 'createTablesDBAdapter'
232
+ });
233
+ } else if (config.appwriteKey) {
234
+ client.setKey(config.appwriteKey);
235
+ client.headers['X-Appwrite-Mode'] = 'default';
236
+ logger.debug('Using API key authentication for TablesDB adapter', {
237
+ project: config.appwriteProject,
238
+ operation: 'createTablesDBAdapter'
239
+ });
240
+ } else {
241
+ throw new Error("No authentication available for adapter");
242
+ }
243
+ }
244
+
245
+ const adapter = new TablesDBAdapter(client);
246
+
247
+ const totalDuration = Date.now() - startTime;
248
+ logger.info('TablesDB adapter created successfully', {
249
+ totalDuration,
250
+ endpoint: config.appwriteEndpoint,
251
+ operation: 'createTablesDBAdapter'
252
+ });
253
+
254
+ return { adapter, client };
255
+
256
+ } catch (error) {
257
+ const errorDuration = Date.now() - startTime;
258
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error';
271
259
 
272
260
  MessageFormatter.warning('Failed to create TablesDB adapter - falling back to legacy', { prefix: "Adapter" });
273
261
 
@@ -286,73 +274,61 @@ export class AdapterFactory {
286
274
  /**
287
275
  * Create Legacy adapter with dynamic import
288
276
  */
289
- private static async createLegacyAdapter(
290
- config: AdapterFactoryConfig
291
- ): Promise<{ adapter: DatabaseAdapter; client: any }> {
292
- const startTime = Date.now();
293
-
294
- try {
295
- logger.info('Loading legacy Appwrite SDK', {
296
- endpoint: config.appwriteEndpoint,
297
- operation: 'createLegacyAdapter'
298
- });
299
-
300
- // Dynamic import of legacy SDK
301
- const importStartTime = Date.now();
302
- const { Client, Databases } = await import('node-appwrite');
303
- const importDuration = Date.now() - importStartTime;
304
-
305
- logger.debug('Legacy SDK import successful', {
306
- importDuration,
307
- operation: 'createLegacyAdapter'
308
- });
309
-
310
- // Use pre-configured client or create session-aware client with Legacy Client
311
- let client: any;
312
- if (config.preConfiguredClient) {
313
- client = config.preConfiguredClient;
314
- } else {
315
- client = new Client()
316
- .setEndpoint(config.appwriteEndpoint)
317
- .setProject(config.appwriteProject);
318
-
319
- // Set authentication method with mode headers
320
- // Prefer session with admin mode, fallback to API key with default mode
321
- if (config.sessionCookie && isValidSessionCookie(config.sessionCookie)) {
322
- (client as any).setSession(config.sessionCookie);
323
- client.headers['X-Appwrite-Mode'] = 'admin';
324
- logger.debug('Using session authentication for Legacy adapter', {
325
- project: config.appwriteProject,
326
- operation: 'createLegacyAdapter'
327
- });
328
- } else if (config.appwriteKey) {
329
- client.setKey(config.appwriteKey);
330
- client.headers['X-Appwrite-Mode'] = 'default';
331
- logger.debug('Using API key authentication for Legacy adapter', {
332
- project: config.appwriteProject,
333
- operation: 'createLegacyAdapter'
334
- });
335
- } else {
336
- throw new Error("No authentication available for adapter");
337
- }
338
- }
339
-
340
- const databases = new Databases(client);
341
- const adapter = new LegacyAdapter(databases);
342
-
343
- const totalDuration = Date.now() - startTime;
344
- logger.info('Legacy adapter created successfully', {
345
- totalDuration,
346
- importDuration,
347
- endpoint: config.appwriteEndpoint,
348
- operation: 'createLegacyAdapter'
349
- });
350
-
351
- return { adapter, client };
352
-
353
- } catch (error) {
354
- const errorDuration = Date.now() - startTime;
355
- const errorMessage = error instanceof Error ? error.message : 'Unknown error';
277
+ private static async createLegacyAdapter(
278
+ config: AdapterFactoryConfig
279
+ ): Promise<{ adapter: DatabaseAdapter; client: any }> {
280
+ const startTime = Date.now();
281
+
282
+ try {
283
+ logger.info('Creating legacy adapter (static SDK imports)', {
284
+ endpoint: config.appwriteEndpoint,
285
+ operation: 'createLegacyAdapter'
286
+ });
287
+
288
+ // Use pre-configured client or create session-aware client with Legacy Client
289
+ let client: any;
290
+ if (config.preConfiguredClient) {
291
+ client = config.preConfiguredClient;
292
+ } else {
293
+ client = new Client()
294
+ .setEndpoint(config.appwriteEndpoint)
295
+ .setProject(config.appwriteProject);
296
+
297
+ // Set authentication method with mode headers
298
+ // Prefer session with admin mode, fallback to API key with default mode
299
+ if (config.sessionCookie && isValidSessionCookie(config.sessionCookie)) {
300
+ (client as any).setSession(config.sessionCookie);
301
+ client.headers['X-Appwrite-Mode'] = 'admin';
302
+ logger.debug('Using session authentication for Legacy adapter', {
303
+ project: config.appwriteProject,
304
+ operation: 'createLegacyAdapter'
305
+ });
306
+ } else if (config.appwriteKey) {
307
+ client.setKey(config.appwriteKey);
308
+ client.headers['X-Appwrite-Mode'] = 'default';
309
+ logger.debug('Using API key authentication for Legacy adapter', {
310
+ project: config.appwriteProject,
311
+ operation: 'createLegacyAdapter'
312
+ });
313
+ } else {
314
+ throw new Error("No authentication available for adapter");
315
+ }
316
+ }
317
+
318
+ const adapter = new LegacyAdapter(client);
319
+
320
+ const totalDuration = Date.now() - startTime;
321
+ logger.info('Legacy adapter created successfully', {
322
+ totalDuration,
323
+ endpoint: config.appwriteEndpoint,
324
+ operation: 'createLegacyAdapter'
325
+ });
326
+
327
+ return { adapter, client };
328
+
329
+ } catch (error) {
330
+ const errorDuration = Date.now() - startTime;
331
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error';
356
332
 
357
333
  logger.error('Failed to load legacy Appwrite SDK', {
358
334
  error: errorMessage,
@@ -531,4 +507,4 @@ export async function getApiCapabilities(
531
507
  terminology: metadata.terminology,
532
508
  capabilities
533
509
  };
534
- }
510
+ }
@@ -6,6 +6,7 @@
6
6
  * code uses TablesDB-style method signatures for consistency.
7
7
  */
8
8
 
9
+ import type { Client } from "node-appwrite";
9
10
  import type { ApiMode } from "../utils/versionDetection.js";
10
11
 
11
12
  // Base parameter types using TablesDB terminology
@@ -43,6 +44,7 @@ export interface CreateTableParams {
43
44
  name: string;
44
45
  permissions?: string[];
45
46
  documentSecurity?: boolean;
47
+ rowSecurity?: boolean;
46
48
  enabled?: boolean;
47
49
  }
48
50
 
@@ -52,6 +54,7 @@ export interface UpdateTableParams {
52
54
  name: string;
53
55
  permissions?: string[];
54
56
  documentSecurity?: boolean;
57
+ rowSecurity?: boolean;
55
58
  enabled?: boolean;
56
59
  }
57
60
 
@@ -131,8 +134,20 @@ export interface UpdateAttributeParams {
131
134
  databaseId: string;
132
135
  tableId: string;
133
136
  key: string;
137
+ type?: string;
134
138
  required?: boolean;
135
139
  default?: any;
140
+ size?: number;
141
+ min?: number;
142
+ max?: number;
143
+ array?: boolean;
144
+ encrypt?: boolean;
145
+ elements?: string[];
146
+ relatedCollection?: string;
147
+ relationType?: string;
148
+ twoWay?: boolean;
149
+ twoWayKey?: string;
150
+ onDelete?: string;
136
151
  }
137
152
 
138
153
  export interface DeleteAttributeParams {
@@ -217,10 +232,10 @@ export interface DatabaseAdapter {
217
232
  * Base adapter class with common functionality
218
233
  */
219
234
  export abstract class BaseAdapter implements DatabaseAdapter {
220
- protected client: any;
235
+ protected client: Client;
221
236
  protected apiMode: ApiMode;
222
237
 
223
- constructor(client: any, apiMode: ApiMode) {
238
+ constructor(client: Client, apiMode: ApiMode) {
224
239
  this.client = client;
225
240
  this.apiMode = apiMode;
226
241
  }
@@ -288,4 +303,4 @@ export class UnsupportedOperationError extends AdapterError {
288
303
  );
289
304
  this.name = 'UnsupportedOperationError';
290
305
  }
291
- }
306
+ }