appwrite-utils-cli 1.7.7 → 1.7.9

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 (65) hide show
  1. package/SELECTION_DIALOGS.md +146 -0
  2. package/dist/cli/commands/databaseCommands.js +89 -23
  3. package/dist/config/services/ConfigLoaderService.d.ts +7 -0
  4. package/dist/config/services/ConfigLoaderService.js +47 -1
  5. package/dist/functions/deployments.js +5 -23
  6. package/dist/functions/methods.js +4 -2
  7. package/dist/functions/pathResolution.d.ts +37 -0
  8. package/dist/functions/pathResolution.js +185 -0
  9. package/dist/functions/templates/count-docs-in-collection/README.md +54 -0
  10. package/dist/functions/templates/count-docs-in-collection/package.json +25 -0
  11. package/dist/functions/templates/count-docs-in-collection/src/main.ts +159 -0
  12. package/dist/functions/templates/count-docs-in-collection/src/request.ts +9 -0
  13. package/dist/functions/templates/count-docs-in-collection/tsconfig.json +28 -0
  14. package/dist/functions/templates/hono-typescript/README.md +286 -0
  15. package/dist/functions/templates/hono-typescript/package.json +26 -0
  16. package/dist/functions/templates/hono-typescript/src/adapters/request.ts +74 -0
  17. package/dist/functions/templates/hono-typescript/src/adapters/response.ts +106 -0
  18. package/dist/functions/templates/hono-typescript/src/app.ts +180 -0
  19. package/dist/functions/templates/hono-typescript/src/context.ts +103 -0
  20. package/dist/functions/templates/hono-typescript/src/index.ts +54 -0
  21. package/dist/functions/templates/hono-typescript/src/middleware/appwrite.ts +119 -0
  22. package/dist/functions/templates/hono-typescript/tsconfig.json +20 -0
  23. package/dist/functions/templates/typescript-node/README.md +32 -0
  24. package/dist/functions/templates/typescript-node/package.json +25 -0
  25. package/dist/functions/templates/typescript-node/src/context.ts +103 -0
  26. package/dist/functions/templates/typescript-node/src/index.ts +29 -0
  27. package/dist/functions/templates/typescript-node/tsconfig.json +28 -0
  28. package/dist/functions/templates/uv/README.md +31 -0
  29. package/dist/functions/templates/uv/pyproject.toml +30 -0
  30. package/dist/functions/templates/uv/src/__init__.py +0 -0
  31. package/dist/functions/templates/uv/src/context.py +125 -0
  32. package/dist/functions/templates/uv/src/index.py +46 -0
  33. package/dist/main.js +175 -4
  34. package/dist/migrations/appwriteToX.d.ts +27 -2
  35. package/dist/migrations/appwriteToX.js +293 -69
  36. package/dist/migrations/yaml/YamlImportConfigLoader.d.ts +1 -1
  37. package/dist/migrations/yaml/generateImportSchemas.js +23 -8
  38. package/dist/shared/schemaGenerator.js +25 -12
  39. package/dist/shared/selectionDialogs.d.ts +214 -0
  40. package/dist/shared/selectionDialogs.js +540 -0
  41. package/dist/utils/configDiscovery.d.ts +4 -4
  42. package/dist/utils/configDiscovery.js +66 -30
  43. package/dist/utils/yamlConverter.d.ts +1 -0
  44. package/dist/utils/yamlConverter.js +26 -3
  45. package/dist/utilsController.d.ts +7 -1
  46. package/dist/utilsController.js +198 -17
  47. package/package.json +4 -2
  48. package/scripts/copy-templates.ts +23 -0
  49. package/src/cli/commands/databaseCommands.ts +133 -34
  50. package/src/config/services/ConfigLoaderService.ts +62 -1
  51. package/src/functions/deployments.ts +10 -35
  52. package/src/functions/methods.ts +4 -2
  53. package/src/functions/pathResolution.ts +227 -0
  54. package/src/main.ts +276 -34
  55. package/src/migrations/appwriteToX.ts +385 -90
  56. package/src/migrations/yaml/generateImportSchemas.ts +26 -8
  57. package/src/shared/schemaGenerator.ts +29 -12
  58. package/src/shared/selectionDialogs.ts +745 -0
  59. package/src/utils/configDiscovery.ts +83 -39
  60. package/src/utils/yamlConverter.ts +29 -3
  61. package/src/utilsController.ts +250 -22
  62. package/dist/utils/schemaStrings.d.ts +0 -14
  63. package/dist/utils/schemaStrings.js +0 -428
  64. package/dist/utils/sessionPreservationExample.d.ts +0 -1666
  65. package/dist/utils/sessionPreservationExample.js +0 -101
@@ -0,0 +1,540 @@
1
+ import inquirer from "inquirer";
2
+ import chalk from "chalk";
3
+ import { MessageFormatter } from "./messageFormatter.js";
4
+ import { logger } from "./logging.js";
5
+ /**
6
+ * Comprehensive selection dialog system for enhanced sync flow
7
+ *
8
+ * This class provides interactive dialogs for selecting databases, tables/collections,
9
+ * and storage buckets during sync operations. It supports both new and existing
10
+ * configurations with visual indicators and comprehensive confirmation flows.
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * import { SelectionDialogs } from './shared/selectionDialogs.js';
15
+ * import type { Models } from 'node-appwrite';
16
+ *
17
+ * // Example usage in a sync command
18
+ * const availableDatabases: Models.Database[] = await getAvailableDatabases();
19
+ * const configuredDatabases = config.databases || [];
20
+ *
21
+ * // Prompt about existing configuration
22
+ * const { syncExisting, modifyConfiguration } = await SelectionDialogs.promptForExistingConfig(configuredDatabases);
23
+ *
24
+ * if (modifyConfiguration) {
25
+ * // Select databases
26
+ * const selectedDatabaseIds = await SelectionDialogs.selectDatabases(
27
+ * availableDatabases,
28
+ * configuredDatabases,
29
+ * { showSelectAll: true, allowNewOnly: !syncExisting }
30
+ * );
31
+ *
32
+ * // For each database, select tables
33
+ * const tableSelectionsMap = new Map<string, string[]>();
34
+ * const availableTablesMap = new Map<string, any[]>();
35
+ *
36
+ * for (const databaseId of selectedDatabaseIds) {
37
+ * const database = availableDatabases.find(db => db.$id === databaseId)!;
38
+ * const availableTables = await getTablesForDatabase(databaseId);
39
+ * const configuredTables = getConfiguredTablesForDatabase(databaseId);
40
+ *
41
+ * availableTablesMap.set(databaseId, availableTables);
42
+ *
43
+ * const selectedTableIds = await SelectionDialogs.selectTablesForDatabase(
44
+ * databaseId,
45
+ * database.name,
46
+ * availableTables,
47
+ * configuredTables,
48
+ * { showSelectAll: true, allowNewOnly: !syncExisting }
49
+ * );
50
+ *
51
+ * tableSelectionsMap.set(databaseId, selectedTableIds);
52
+ * }
53
+ *
54
+ * // Select buckets
55
+ * const availableBuckets = await getAvailableBuckets();
56
+ * const configuredBuckets = config.buckets || [];
57
+ * const selectedBucketIds = await SelectionDialogs.selectBucketsForDatabases(
58
+ * selectedDatabaseIds,
59
+ * availableBuckets,
60
+ * configuredBuckets,
61
+ * { showSelectAll: true, groupByDatabase: true }
62
+ * );
63
+ *
64
+ * // Create selection objects
65
+ * const databaseSelections = SelectionDialogs.createDatabaseSelection(
66
+ * selectedDatabaseIds,
67
+ * availableDatabases,
68
+ * tableSelectionsMap,
69
+ * configuredDatabases,
70
+ * availableTablesMap
71
+ * );
72
+ *
73
+ * const bucketSelections = SelectionDialogs.createBucketSelection(
74
+ * selectedBucketIds,
75
+ * availableBuckets,
76
+ * configuredBuckets,
77
+ * availableDatabases
78
+ * );
79
+ *
80
+ * // Show final confirmation
81
+ * const selectionSummary = SelectionDialogs.createSyncSelectionSummary(
82
+ * databaseSelections,
83
+ * bucketSelections
84
+ * );
85
+ *
86
+ * const confirmed = await SelectionDialogs.confirmSyncSelection(selectionSummary);
87
+ *
88
+ * if (confirmed) {
89
+ * // Proceed with sync operation
90
+ * await performSync(databaseSelections, bucketSelections);
91
+ * }
92
+ * }
93
+ * ```
94
+ */
95
+ export class SelectionDialogs {
96
+ /**
97
+ * Prompts user about existing configuration
98
+ */
99
+ static async promptForExistingConfig(configuredItems) {
100
+ if (configuredItems.length === 0) {
101
+ return { syncExisting: false, modifyConfiguration: true };
102
+ }
103
+ MessageFormatter.section("Existing Configuration Found");
104
+ MessageFormatter.info(`Found ${configuredItems.length} configured items.`, { skipLogging: true });
105
+ const { syncExisting } = await inquirer.prompt([{
106
+ type: 'confirm',
107
+ name: 'syncExisting',
108
+ message: 'Sync existing configured items?',
109
+ default: true
110
+ }]);
111
+ if (!syncExisting) {
112
+ return { syncExisting: false, modifyConfiguration: true };
113
+ }
114
+ const { modifyConfiguration } = await inquirer.prompt([{
115
+ type: 'confirm',
116
+ name: 'modifyConfiguration',
117
+ message: 'Add/remove items from configuration?',
118
+ default: false
119
+ }]);
120
+ return { syncExisting, modifyConfiguration };
121
+ }
122
+ /**
123
+ * Shows database selection dialog with indicators for configured vs new databases
124
+ */
125
+ static async selectDatabases(availableDatabases, configuredDatabases, options = {}) {
126
+ const { showSelectAll = true, allowNewOnly = false, defaultSelected = [] } = options;
127
+ MessageFormatter.section("Database Selection");
128
+ const configuredIds = new Set(configuredDatabases.map(db => db.$id || db.id));
129
+ let choices = [];
130
+ if (showSelectAll && availableDatabases.length > 1) {
131
+ choices.push({
132
+ name: chalk.green.bold('📋 Select All Databases'),
133
+ value: '__SELECT_ALL__',
134
+ short: 'All databases'
135
+ });
136
+ }
137
+ availableDatabases.forEach(database => {
138
+ const isConfigured = configuredIds.has(database.$id);
139
+ const status = isConfigured ? chalk.green('✅') : chalk.blue('○');
140
+ const name = `${status} ${database.name} (${database.$id})`;
141
+ if (allowNewOnly && isConfigured) {
142
+ return; // Skip configured databases if only allowing new ones
143
+ }
144
+ choices.push({
145
+ name,
146
+ value: database.$id,
147
+ short: database.name,
148
+ checked: defaultSelected.includes(database.$id) || (!allowNewOnly && isConfigured)
149
+ });
150
+ });
151
+ if (choices.length === 0) {
152
+ MessageFormatter.warning("No databases available for selection.", { skipLogging: true });
153
+ return [];
154
+ }
155
+ const { selectedDatabaseIds } = await inquirer.prompt([{
156
+ type: 'checkbox',
157
+ name: 'selectedDatabaseIds',
158
+ message: 'Select databases to sync:',
159
+ choices,
160
+ validate: (input) => {
161
+ if (input.length === 0) {
162
+ return chalk.red('Please select at least one database.');
163
+ }
164
+ if (input.includes('__SELECT_ALL__') && input.length > 1) {
165
+ return chalk.red('Cannot select "Select All" with individual databases.');
166
+ }
167
+ return true;
168
+ }
169
+ }]);
170
+ // Handle select all
171
+ if (selectedDatabaseIds.includes('__SELECT_ALL__')) {
172
+ const allIds = availableDatabases.map(db => db.$id);
173
+ if (allowNewOnly) {
174
+ return allIds.filter(id => !configuredIds.has(id));
175
+ }
176
+ return allIds;
177
+ }
178
+ return selectedDatabaseIds;
179
+ }
180
+ /**
181
+ * Shows table/collection selection dialog for a specific database
182
+ */
183
+ static async selectTablesForDatabase(databaseId, databaseName, availableTables, configuredTables, options = {}) {
184
+ const { showSelectAll = true, allowNewOnly = false, defaultSelected = [], showDatabaseContext = true } = options;
185
+ if (showDatabaseContext) {
186
+ MessageFormatter.section(`Table Selection for ${databaseName}`);
187
+ }
188
+ const configuredIds = new Set(configuredTables.map(table => table.$id || table.id));
189
+ let choices = [];
190
+ if (showSelectAll && availableTables.length > 1) {
191
+ choices.push({
192
+ name: chalk.green.bold('📋 Select All Tables'),
193
+ value: '__SELECT_ALL__',
194
+ short: 'All tables'
195
+ });
196
+ }
197
+ availableTables.forEach(table => {
198
+ const isConfigured = configuredIds.has(table.$id);
199
+ const status = isConfigured ? chalk.green('✅') : chalk.blue('○');
200
+ const name = `${status} ${table.name} (${table.$id})`;
201
+ if (allowNewOnly && isConfigured) {
202
+ return; // Skip configured tables if only allowing new ones
203
+ }
204
+ choices.push({
205
+ name,
206
+ value: table.$id,
207
+ short: table.name,
208
+ checked: defaultSelected.includes(table.$id) || (!allowNewOnly && isConfigured)
209
+ });
210
+ });
211
+ if (choices.length === 0) {
212
+ MessageFormatter.warning(`No tables available for database: ${databaseName}`, { skipLogging: true });
213
+ return [];
214
+ }
215
+ const { selectedTableIds } = await inquirer.prompt([{
216
+ type: 'checkbox',
217
+ name: 'selectedTableIds',
218
+ message: `Select tables to sync for ${databaseName}:`,
219
+ choices,
220
+ validate: (input) => {
221
+ if (input.length === 0) {
222
+ return chalk.red('Please select at least one table.');
223
+ }
224
+ if (input.includes('__SELECT_ALL__') && input.length > 1) {
225
+ return chalk.red('Cannot select "Select All" with individual tables.');
226
+ }
227
+ return true;
228
+ }
229
+ }]);
230
+ // Handle select all
231
+ if (selectedTableIds.includes('__SELECT_ALL__')) {
232
+ const allIds = availableTables.map(table => table.$id);
233
+ if (allowNewOnly) {
234
+ return allIds.filter(id => !configuredIds.has(id));
235
+ }
236
+ return allIds;
237
+ }
238
+ return selectedTableIds;
239
+ }
240
+ /**
241
+ * Shows bucket selection dialog for selected databases
242
+ */
243
+ static async selectBucketsForDatabases(selectedDatabaseIds, availableBuckets, configuredBuckets, options = {}) {
244
+ const { showSelectAll = true, allowNewOnly = false, defaultSelected = [], groupByDatabase = true } = options;
245
+ MessageFormatter.section("Storage Bucket Selection");
246
+ const configuredIds = new Set(configuredBuckets.map(bucket => bucket.$id || bucket.id));
247
+ // Filter buckets that are associated with selected databases
248
+ const relevantBuckets = availableBuckets.filter(bucket => {
249
+ if (selectedDatabaseIds.length === 0)
250
+ return true; // If no databases selected, show all buckets
251
+ return selectedDatabaseIds.includes(bucket.databaseId) || !bucket.databaseId;
252
+ });
253
+ if (relevantBuckets.length === 0) {
254
+ MessageFormatter.warning("No storage buckets available for selected databases.", { skipLogging: true });
255
+ return [];
256
+ }
257
+ let choices = [];
258
+ if (showSelectAll && relevantBuckets.length > 1) {
259
+ choices.push({
260
+ name: chalk.green.bold('📋 Select All Buckets'),
261
+ value: '__SELECT_ALL__',
262
+ short: 'All buckets'
263
+ });
264
+ }
265
+ if (groupByDatabase) {
266
+ // Group buckets by database
267
+ const bucketsByDatabase = new Map();
268
+ relevantBuckets.forEach(bucket => {
269
+ const dbId = bucket.databaseId || 'ungrouped';
270
+ if (!bucketsByDatabase.has(dbId)) {
271
+ bucketsByDatabase.set(dbId, []);
272
+ }
273
+ bucketsByDatabase.get(dbId).push(bucket);
274
+ });
275
+ // Add buckets grouped by database
276
+ selectedDatabaseIds.forEach(dbId => {
277
+ const buckets = bucketsByDatabase.get(dbId) || [];
278
+ if (buckets.length > 0) {
279
+ choices.push(new inquirer.Separator(chalk.cyan(`📁 Database: ${dbId}`)));
280
+ buckets.forEach(bucket => {
281
+ const isConfigured = configuredIds.has(bucket.$id);
282
+ const status = isConfigured ? chalk.green('✅') : chalk.blue('○');
283
+ const name = `${status} ${bucket.name} (${bucket.$id})`;
284
+ if (allowNewOnly && isConfigured) {
285
+ return; // Skip configured buckets if only allowing new ones
286
+ }
287
+ choices.push({
288
+ name: ` ${name}`,
289
+ value: bucket.$id,
290
+ short: bucket.name,
291
+ checked: defaultSelected.includes(bucket.$id) || (!allowNewOnly && isConfigured)
292
+ });
293
+ });
294
+ }
295
+ });
296
+ // Add ungrouped buckets
297
+ const ungroupedBuckets = bucketsByDatabase.get('ungrouped') || [];
298
+ if (ungroupedBuckets.length > 0) {
299
+ choices.push(new inquirer.Separator(chalk.cyan('📁 General Storage')));
300
+ ungroupedBuckets.forEach(bucket => {
301
+ const isConfigured = configuredIds.has(bucket.$id);
302
+ const status = isConfigured ? chalk.green('✅') : chalk.blue('○');
303
+ const name = `${status} ${bucket.name} (${bucket.$id})`;
304
+ if (allowNewOnly && isConfigured) {
305
+ return; // Skip configured buckets if only allowing new ones
306
+ }
307
+ choices.push({
308
+ name: ` ${name}`,
309
+ value: bucket.$id,
310
+ short: bucket.name,
311
+ checked: defaultSelected.includes(bucket.$id) || (!allowNewOnly && isConfigured)
312
+ });
313
+ });
314
+ }
315
+ }
316
+ else {
317
+ // Flat list of buckets
318
+ relevantBuckets.forEach(bucket => {
319
+ const isConfigured = configuredIds.has(bucket.$id);
320
+ const status = isConfigured ? chalk.green('✅') : chalk.blue('○');
321
+ const dbContext = bucket.databaseId ? ` [${bucket.databaseId}]` : '';
322
+ const name = `${status} ${bucket.name} (${bucket.$id})${dbContext}`;
323
+ if (allowNewOnly && isConfigured) {
324
+ return; // Skip configured buckets if only allowing new ones
325
+ }
326
+ choices.push({
327
+ name,
328
+ value: bucket.$id,
329
+ short: bucket.name,
330
+ checked: defaultSelected.includes(bucket.$id) || (!allowNewOnly && isConfigured)
331
+ });
332
+ });
333
+ }
334
+ const { selectedBucketIds } = await inquirer.prompt([{
335
+ type: 'checkbox',
336
+ name: 'selectedBucketIds',
337
+ message: 'Select storage buckets to sync:',
338
+ choices,
339
+ validate: (input) => {
340
+ if (input.length === 0) {
341
+ return chalk.yellow('No storage buckets selected. Continue with databases only?') || true;
342
+ }
343
+ if (input.includes('__SELECT_ALL__') && input.length > 1) {
344
+ return chalk.red('Cannot select "Select All" with individual buckets.');
345
+ }
346
+ return true;
347
+ }
348
+ }]);
349
+ // Handle select all
350
+ if (selectedBucketIds && selectedBucketIds.includes('__SELECT_ALL__')) {
351
+ const allIds = relevantBuckets.map(bucket => bucket.$id);
352
+ if (allowNewOnly) {
353
+ return allIds.filter(id => !configuredIds.has(id));
354
+ }
355
+ return allIds;
356
+ }
357
+ return selectedBucketIds || [];
358
+ }
359
+ /**
360
+ * Shows final confirmation dialog with sync selection summary
361
+ */
362
+ static async confirmSyncSelection(selectionSummary, operationType = 'sync') {
363
+ const labels = {
364
+ push: {
365
+ banner: "Push Selection Summary",
366
+ subtitle: "Review selections before pushing to Appwrite",
367
+ confirm: "Proceed with push operation?",
368
+ success: "Push operation confirmed.",
369
+ cancel: "Push operation cancelled."
370
+ },
371
+ pull: {
372
+ banner: "Pull Selection Summary",
373
+ subtitle: "Review selections before pulling from Appwrite",
374
+ confirm: "Proceed with pull operation?",
375
+ success: "Pull operation confirmed.",
376
+ cancel: "Pull operation cancelled."
377
+ },
378
+ sync: {
379
+ banner: "Sync Selection Summary",
380
+ subtitle: "Review your selections before proceeding",
381
+ confirm: "Proceed with sync operation?",
382
+ success: "Sync operation confirmed.",
383
+ cancel: "Sync operation cancelled."
384
+ }
385
+ };
386
+ const label = labels[operationType];
387
+ MessageFormatter.banner(label.banner, label.subtitle);
388
+ // Database summary
389
+ console.log(chalk.bold.cyan("\n📊 Databases:"));
390
+ console.log(` Total: ${selectionSummary.totalDatabases}`);
391
+ console.log(` ${chalk.green('✅ Configured')}: ${selectionSummary.existingItems.databases}`);
392
+ console.log(` ${chalk.blue('○ New')}: ${selectionSummary.newItems.databases}`);
393
+ if (selectionSummary.databases.length > 0) {
394
+ console.log(chalk.gray("\n Selected databases:"));
395
+ selectionSummary.databases.forEach(db => {
396
+ const status = db.isNew ? chalk.blue('○') : chalk.green('✅');
397
+ console.log(` ${status} ${db.databaseName} (${db.tableNames.length} tables)`);
398
+ });
399
+ }
400
+ // Table summary
401
+ console.log(chalk.bold.cyan("\n📋 Tables/Collections:"));
402
+ console.log(` Total: ${selectionSummary.totalTables}`);
403
+ console.log(` ${chalk.green('✅ Configured')}: ${selectionSummary.existingItems.tables}`);
404
+ console.log(` ${chalk.blue('○ New')}: ${selectionSummary.newItems.tables}`);
405
+ // Bucket summary
406
+ console.log(chalk.bold.cyan("\n🪣 Storage Buckets:"));
407
+ console.log(` Total: ${selectionSummary.totalBuckets}`);
408
+ console.log(` ${chalk.green('✅ Configured')}: ${selectionSummary.existingItems.buckets}`);
409
+ console.log(` ${chalk.blue('○ New')}: ${selectionSummary.newItems.buckets}`);
410
+ if (selectionSummary.buckets.length > 0) {
411
+ console.log(chalk.gray("\n Selected buckets:"));
412
+ selectionSummary.buckets.forEach(bucket => {
413
+ const status = bucket.isNew ? chalk.blue('○') : chalk.green('✅');
414
+ const dbContext = bucket.databaseName ? ` [${bucket.databaseName}]` : '';
415
+ console.log(` ${status} ${bucket.bucketName}${dbContext}`);
416
+ });
417
+ }
418
+ console.log(); // Add spacing
419
+ const { confirmed } = await inquirer.prompt([{
420
+ type: 'confirm',
421
+ name: 'confirmed',
422
+ message: chalk.green.bold(label.confirm),
423
+ default: true
424
+ }]);
425
+ if (confirmed) {
426
+ MessageFormatter.success(label.success, { skipLogging: true });
427
+ logger.info(`${operationType} selection confirmed`, {
428
+ databases: selectionSummary.totalDatabases,
429
+ tables: selectionSummary.totalTables,
430
+ buckets: selectionSummary.totalBuckets
431
+ });
432
+ }
433
+ else {
434
+ MessageFormatter.warning(label.cancel, { skipLogging: true });
435
+ logger.info(`${operationType} selection cancelled by user`);
436
+ }
437
+ return confirmed;
438
+ }
439
+ /**
440
+ * Creates a sync selection summary from selected items
441
+ */
442
+ static createSyncSelectionSummary(databaseSelections, bucketSelections) {
443
+ const totalDatabases = databaseSelections.length;
444
+ const totalTables = databaseSelections.reduce((sum, db) => sum + db.tableIds.length, 0);
445
+ const totalBuckets = bucketSelections.length;
446
+ const newDatabases = databaseSelections.filter(db => db.isNew).length;
447
+ const newTables = databaseSelections.reduce((sum, db) => sum + db.tableIds.length, 0); // TODO: Track which tables are new
448
+ const newBuckets = bucketSelections.filter(bucket => bucket.isNew).length;
449
+ const existingDatabases = totalDatabases - newDatabases;
450
+ const existingTables = totalTables - newTables;
451
+ const existingBuckets = totalBuckets - newBuckets;
452
+ return {
453
+ databases: databaseSelections,
454
+ buckets: bucketSelections,
455
+ totalDatabases,
456
+ totalTables,
457
+ totalBuckets,
458
+ newItems: {
459
+ databases: newDatabases,
460
+ tables: newTables,
461
+ buckets: newBuckets
462
+ },
463
+ existingItems: {
464
+ databases: existingDatabases,
465
+ tables: existingTables,
466
+ buckets: existingBuckets
467
+ }
468
+ };
469
+ }
470
+ /**
471
+ * Helper method to create database selection objects
472
+ */
473
+ static createDatabaseSelection(selectedDatabaseIds, availableDatabases, tableSelectionsMap, configuredDatabases, availableTablesMap = new Map()) {
474
+ const configuredIds = new Set(configuredDatabases.map(db => db.$id || db.id));
475
+ return selectedDatabaseIds.map(databaseId => {
476
+ const database = availableDatabases.find(db => db.$id === databaseId);
477
+ if (!database) {
478
+ throw new Error(`Database with ID ${databaseId} not found in available databases`);
479
+ }
480
+ const tableIds = tableSelectionsMap.get(databaseId) || [];
481
+ const tables = availableTablesMap.get(databaseId) || [];
482
+ const tableNames = tables.map(table => table.name || table.$id || `Table-${table.$id}`);
483
+ return {
484
+ databaseId,
485
+ databaseName: database.name,
486
+ tableIds,
487
+ tableNames,
488
+ isNew: !configuredIds.has(databaseId)
489
+ };
490
+ });
491
+ }
492
+ /**
493
+ * Helper method to create bucket selection objects
494
+ */
495
+ static createBucketSelection(selectedBucketIds, availableBuckets, configuredBuckets, availableDatabases) {
496
+ const configuredIds = new Set(configuredBuckets.map(bucket => bucket.$id || bucket.id));
497
+ return selectedBucketIds.map(bucketId => {
498
+ const bucket = availableBuckets.find(b => b.$id === bucketId);
499
+ if (!bucket) {
500
+ throw new Error(`Bucket with ID ${bucketId} not found in available buckets`);
501
+ }
502
+ const database = bucket.databaseId ?
503
+ availableDatabases.find(db => db.$id === bucket.databaseId) : undefined;
504
+ return {
505
+ bucketId,
506
+ bucketName: bucket.name,
507
+ databaseId: bucket.databaseId,
508
+ databaseName: database?.name,
509
+ isNew: !configuredIds.has(bucketId)
510
+ };
511
+ });
512
+ }
513
+ /**
514
+ * Shows a progress message during selection operations
515
+ */
516
+ static showProgress(message) {
517
+ MessageFormatter.progress(message, { skipLogging: true });
518
+ }
519
+ /**
520
+ * Shows an error message and handles graceful cancellation
521
+ */
522
+ static showError(message, error) {
523
+ MessageFormatter.error(message, error, { skipLogging: true });
524
+ logger.error(`Selection dialog error: ${message}`, { error: error?.message });
525
+ }
526
+ /**
527
+ * Shows a warning message
528
+ */
529
+ static showWarning(message) {
530
+ MessageFormatter.warning(message, { skipLogging: true });
531
+ logger.warn(`Selection dialog warning: ${message}`);
532
+ }
533
+ /**
534
+ * Shows a success message
535
+ */
536
+ static showSuccess(message) {
537
+ MessageFormatter.success(message, { skipLogging: true });
538
+ logger.info(`Selection dialog success: ${message}`);
539
+ }
540
+ }
@@ -27,11 +27,11 @@ export declare const findFunctionsDir: (dir: string, depth?: number) => string |
27
27
  */
28
28
  export declare const loadYamlCollection: (filePath: string) => CollectionCreate | null;
29
29
  /**
30
- * Loads a YAML table file and converts it to table format
30
+ * Loads a YAML table file and converts it to CollectionCreate format
31
31
  * @param filePath Path to the YAML table file
32
- * @returns Table object or null if loading fails
32
+ * @returns CollectionCreate object or null if loading fails
33
33
  */
34
- export declare const loadYamlTable: (filePath: string) => any | null;
34
+ export declare const loadYamlTable: (filePath: string) => CollectionCreate | null;
35
35
  /**
36
36
  * Result of discovering collections from a directory
37
37
  */
@@ -54,7 +54,7 @@ export declare const discoverCollections: (collectionsDir: string) => Promise<Co
54
54
  * Result of discovering tables from a directory
55
55
  */
56
56
  export interface TableDiscoveryResult {
57
- tables: any[];
57
+ tables: CollectionCreate[];
58
58
  loadedNames: Set<string>;
59
59
  conflicts: Array<{
60
60
  name: string;