appwrite-utils-cli 1.7.7 → 1.7.8

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.
@@ -0,0 +1,716 @@
1
+ import inquirer from "inquirer";
2
+ import chalk from "chalk";
3
+ import type { Models } from "node-appwrite";
4
+ import { MessageFormatter } from "./messageFormatter.js";
5
+ import { logger } from "./logging.js";
6
+
7
+ /**
8
+ * Interface for sync selection summary
9
+ */
10
+ export interface SyncSelectionSummary {
11
+ databases: DatabaseSelection[];
12
+ buckets: BucketSelection[];
13
+ totalDatabases: number;
14
+ totalTables: number;
15
+ totalBuckets: number;
16
+ newItems: {
17
+ databases: number;
18
+ tables: number;
19
+ buckets: number;
20
+ };
21
+ existingItems: {
22
+ databases: number;
23
+ tables: number;
24
+ buckets: number;
25
+ };
26
+ }
27
+
28
+ /**
29
+ * Database selection with associated tables
30
+ */
31
+ export interface DatabaseSelection {
32
+ databaseId: string;
33
+ databaseName: string;
34
+ tableIds: string[];
35
+ tableNames: string[];
36
+ isNew: boolean;
37
+ }
38
+
39
+ /**
40
+ * Bucket selection with associated database
41
+ */
42
+ export interface BucketSelection {
43
+ bucketId: string;
44
+ bucketName: string;
45
+ databaseId?: string;
46
+ databaseName?: string;
47
+ isNew: boolean;
48
+ }
49
+
50
+ /**
51
+ * Options for database selection
52
+ */
53
+ export interface DatabaseSelectionOptions {
54
+ showSelectAll?: boolean;
55
+ allowNewOnly?: boolean;
56
+ defaultSelected?: string[];
57
+ }
58
+
59
+ /**
60
+ * Options for table selection
61
+ */
62
+ export interface TableSelectionOptions {
63
+ showSelectAll?: boolean;
64
+ allowNewOnly?: boolean;
65
+ defaultSelected?: string[];
66
+ showDatabaseContext?: boolean;
67
+ }
68
+
69
+ /**
70
+ * Options for bucket selection
71
+ */
72
+ export interface BucketSelectionOptions {
73
+ showSelectAll?: boolean;
74
+ allowNewOnly?: boolean;
75
+ defaultSelected?: string[];
76
+ groupByDatabase?: boolean;
77
+ }
78
+
79
+ /**
80
+ * Response from existing config prompt
81
+ */
82
+ export interface ExistingConfigResponse {
83
+ syncExisting: boolean;
84
+ modifyConfiguration: boolean;
85
+ }
86
+
87
+ /**
88
+ * Comprehensive selection dialog system for enhanced sync flow
89
+ *
90
+ * This class provides interactive dialogs for selecting databases, tables/collections,
91
+ * and storage buckets during sync operations. It supports both new and existing
92
+ * configurations with visual indicators and comprehensive confirmation flows.
93
+ *
94
+ * @example
95
+ * ```typescript
96
+ * import { SelectionDialogs } from './shared/selectionDialogs.js';
97
+ * import type { Models } from 'node-appwrite';
98
+ *
99
+ * // Example usage in a sync command
100
+ * const availableDatabases: Models.Database[] = await getAvailableDatabases();
101
+ * const configuredDatabases = config.databases || [];
102
+ *
103
+ * // Prompt about existing configuration
104
+ * const { syncExisting, modifyConfiguration } = await SelectionDialogs.promptForExistingConfig(configuredDatabases);
105
+ *
106
+ * if (modifyConfiguration) {
107
+ * // Select databases
108
+ * const selectedDatabaseIds = await SelectionDialogs.selectDatabases(
109
+ * availableDatabases,
110
+ * configuredDatabases,
111
+ * { showSelectAll: true, allowNewOnly: !syncExisting }
112
+ * );
113
+ *
114
+ * // For each database, select tables
115
+ * const tableSelectionsMap = new Map<string, string[]>();
116
+ * const availableTablesMap = new Map<string, any[]>();
117
+ *
118
+ * for (const databaseId of selectedDatabaseIds) {
119
+ * const database = availableDatabases.find(db => db.$id === databaseId)!;
120
+ * const availableTables = await getTablesForDatabase(databaseId);
121
+ * const configuredTables = getConfiguredTablesForDatabase(databaseId);
122
+ *
123
+ * availableTablesMap.set(databaseId, availableTables);
124
+ *
125
+ * const selectedTableIds = await SelectionDialogs.selectTablesForDatabase(
126
+ * databaseId,
127
+ * database.name,
128
+ * availableTables,
129
+ * configuredTables,
130
+ * { showSelectAll: true, allowNewOnly: !syncExisting }
131
+ * );
132
+ *
133
+ * tableSelectionsMap.set(databaseId, selectedTableIds);
134
+ * }
135
+ *
136
+ * // Select buckets
137
+ * const availableBuckets = await getAvailableBuckets();
138
+ * const configuredBuckets = config.buckets || [];
139
+ * const selectedBucketIds = await SelectionDialogs.selectBucketsForDatabases(
140
+ * selectedDatabaseIds,
141
+ * availableBuckets,
142
+ * configuredBuckets,
143
+ * { showSelectAll: true, groupByDatabase: true }
144
+ * );
145
+ *
146
+ * // Create selection objects
147
+ * const databaseSelections = SelectionDialogs.createDatabaseSelection(
148
+ * selectedDatabaseIds,
149
+ * availableDatabases,
150
+ * tableSelectionsMap,
151
+ * configuredDatabases,
152
+ * availableTablesMap
153
+ * );
154
+ *
155
+ * const bucketSelections = SelectionDialogs.createBucketSelection(
156
+ * selectedBucketIds,
157
+ * availableBuckets,
158
+ * configuredBuckets,
159
+ * availableDatabases
160
+ * );
161
+ *
162
+ * // Show final confirmation
163
+ * const selectionSummary = SelectionDialogs.createSyncSelectionSummary(
164
+ * databaseSelections,
165
+ * bucketSelections
166
+ * );
167
+ *
168
+ * const confirmed = await SelectionDialogs.confirmSyncSelection(selectionSummary);
169
+ *
170
+ * if (confirmed) {
171
+ * // Proceed with sync operation
172
+ * await performSync(databaseSelections, bucketSelections);
173
+ * }
174
+ * }
175
+ * ```
176
+ */
177
+ export class SelectionDialogs {
178
+ /**
179
+ * Prompts user about existing configuration
180
+ */
181
+ static async promptForExistingConfig(configuredItems: any[]): Promise<ExistingConfigResponse> {
182
+ if (configuredItems.length === 0) {
183
+ return { syncExisting: false, modifyConfiguration: true };
184
+ }
185
+
186
+ MessageFormatter.section("Existing Configuration Found");
187
+ MessageFormatter.info(`Found ${configuredItems.length} configured items.`, { skipLogging: true });
188
+
189
+ const { syncExisting } = await inquirer.prompt([{
190
+ type: 'confirm',
191
+ name: 'syncExisting',
192
+ message: 'Sync existing configured items?',
193
+ default: true
194
+ }]);
195
+
196
+ if (!syncExisting) {
197
+ return { syncExisting: false, modifyConfiguration: true };
198
+ }
199
+
200
+ const { modifyConfiguration } = await inquirer.prompt([{
201
+ type: 'confirm',
202
+ name: 'modifyConfiguration',
203
+ message: 'Add/remove items from configuration?',
204
+ default: false
205
+ }]);
206
+
207
+ return { syncExisting, modifyConfiguration };
208
+ }
209
+
210
+ /**
211
+ * Shows database selection dialog with indicators for configured vs new databases
212
+ */
213
+ static async selectDatabases(
214
+ availableDatabases: Models.Database[],
215
+ configuredDatabases: any[],
216
+ options: DatabaseSelectionOptions = {}
217
+ ): Promise<string[]> {
218
+ const {
219
+ showSelectAll = true,
220
+ allowNewOnly = false,
221
+ defaultSelected = []
222
+ } = options;
223
+
224
+ MessageFormatter.section("Database Selection");
225
+
226
+ const configuredIds = new Set(configuredDatabases.map(db => db.$id || db.id));
227
+
228
+ let choices: any[] = [];
229
+
230
+ if (showSelectAll && availableDatabases.length > 1) {
231
+ choices.push({
232
+ name: chalk.green.bold('📋 Select All Databases'),
233
+ value: '__SELECT_ALL__',
234
+ short: 'All databases'
235
+ });
236
+ }
237
+
238
+ availableDatabases.forEach(database => {
239
+ const isConfigured = configuredIds.has(database.$id);
240
+ const status = isConfigured ? chalk.green('✅') : chalk.blue('○');
241
+ const name = `${status} ${database.name} (${database.$id})`;
242
+
243
+ if (allowNewOnly && isConfigured) {
244
+ return; // Skip configured databases if only allowing new ones
245
+ }
246
+
247
+ choices.push({
248
+ name,
249
+ value: database.$id,
250
+ short: database.name,
251
+ checked: defaultSelected.includes(database.$id) || (!allowNewOnly && isConfigured)
252
+ });
253
+ });
254
+
255
+ if (choices.length === 0) {
256
+ MessageFormatter.warning("No databases available for selection.", { skipLogging: true });
257
+ return [];
258
+ }
259
+
260
+ const { selectedDatabaseIds } = await inquirer.prompt([{
261
+ type: 'checkbox',
262
+ name: 'selectedDatabaseIds',
263
+ message: 'Select databases to sync:',
264
+ choices,
265
+ validate: (input: string[]) => {
266
+ if (input.length === 0) {
267
+ return chalk.red('Please select at least one database.');
268
+ }
269
+ if (input.includes('__SELECT_ALL__') && input.length > 1) {
270
+ return chalk.red('Cannot select "Select All" with individual databases.');
271
+ }
272
+ return true;
273
+ }
274
+ }]);
275
+
276
+ // Handle select all
277
+ if (selectedDatabaseIds.includes('__SELECT_ALL__')) {
278
+ const allIds = availableDatabases.map(db => db.$id);
279
+ if (allowNewOnly) {
280
+ return allIds.filter(id => !configuredIds.has(id));
281
+ }
282
+ return allIds;
283
+ }
284
+
285
+ return selectedDatabaseIds;
286
+ }
287
+
288
+ /**
289
+ * Shows table/collection selection dialog for a specific database
290
+ */
291
+ static async selectTablesForDatabase(
292
+ databaseId: string,
293
+ databaseName: string,
294
+ availableTables: any[],
295
+ configuredTables: any[],
296
+ options: TableSelectionOptions = {}
297
+ ): Promise<string[]> {
298
+ const {
299
+ showSelectAll = true,
300
+ allowNewOnly = false,
301
+ defaultSelected = [],
302
+ showDatabaseContext = true
303
+ } = options;
304
+
305
+ if (showDatabaseContext) {
306
+ MessageFormatter.section(`Table Selection for ${databaseName}`);
307
+ }
308
+
309
+ const configuredIds = new Set(configuredTables.map(table => table.$id || table.id));
310
+
311
+ let choices: any[] = [];
312
+
313
+ if (showSelectAll && availableTables.length > 1) {
314
+ choices.push({
315
+ name: chalk.green.bold('📋 Select All Tables'),
316
+ value: '__SELECT_ALL__',
317
+ short: 'All tables'
318
+ });
319
+ }
320
+
321
+ availableTables.forEach(table => {
322
+ const isConfigured = configuredIds.has(table.$id);
323
+ const status = isConfigured ? chalk.green('✅') : chalk.blue('○');
324
+ const name = `${status} ${table.name} (${table.$id})`;
325
+
326
+ if (allowNewOnly && isConfigured) {
327
+ return; // Skip configured tables if only allowing new ones
328
+ }
329
+
330
+ choices.push({
331
+ name,
332
+ value: table.$id,
333
+ short: table.name,
334
+ checked: defaultSelected.includes(table.$id) || (!allowNewOnly && isConfigured)
335
+ });
336
+ });
337
+
338
+ if (choices.length === 0) {
339
+ MessageFormatter.warning(`No tables available for database: ${databaseName}`, { skipLogging: true });
340
+ return [];
341
+ }
342
+
343
+ const { selectedTableIds } = await inquirer.prompt([{
344
+ type: 'checkbox',
345
+ name: 'selectedTableIds',
346
+ message: `Select tables to sync for ${databaseName}:`,
347
+ choices,
348
+ validate: (input: string[]) => {
349
+ if (input.length === 0) {
350
+ return chalk.red('Please select at least one table.');
351
+ }
352
+ if (input.includes('__SELECT_ALL__') && input.length > 1) {
353
+ return chalk.red('Cannot select "Select All" with individual tables.');
354
+ }
355
+ return true;
356
+ }
357
+ }]);
358
+
359
+ // Handle select all
360
+ if (selectedTableIds.includes('__SELECT_ALL__')) {
361
+ const allIds = availableTables.map(table => table.$id);
362
+ if (allowNewOnly) {
363
+ return allIds.filter(id => !configuredIds.has(id));
364
+ }
365
+ return allIds;
366
+ }
367
+
368
+ return selectedTableIds;
369
+ }
370
+
371
+ /**
372
+ * Shows bucket selection dialog for selected databases
373
+ */
374
+ static async selectBucketsForDatabases(
375
+ selectedDatabaseIds: string[],
376
+ availableBuckets: any[],
377
+ configuredBuckets: any[],
378
+ options: BucketSelectionOptions = {}
379
+ ): Promise<string[]> {
380
+ const {
381
+ showSelectAll = true,
382
+ allowNewOnly = false,
383
+ defaultSelected = [],
384
+ groupByDatabase = true
385
+ } = options;
386
+
387
+ MessageFormatter.section("Storage Bucket Selection");
388
+
389
+ const configuredIds = new Set(configuredBuckets.map(bucket => bucket.$id || bucket.id));
390
+
391
+ // Filter buckets that are associated with selected databases
392
+ const relevantBuckets = availableBuckets.filter(bucket => {
393
+ if (selectedDatabaseIds.length === 0) return true; // If no databases selected, show all buckets
394
+ return selectedDatabaseIds.includes(bucket.databaseId) || !bucket.databaseId;
395
+ });
396
+
397
+ if (relevantBuckets.length === 0) {
398
+ MessageFormatter.warning("No storage buckets available for selected databases.", { skipLogging: true });
399
+ return [];
400
+ }
401
+
402
+ let choices: any[] = [];
403
+
404
+ if (showSelectAll && relevantBuckets.length > 1) {
405
+ choices.push({
406
+ name: chalk.green.bold('📋 Select All Buckets'),
407
+ value: '__SELECT_ALL__',
408
+ short: 'All buckets'
409
+ });
410
+ }
411
+
412
+ if (groupByDatabase) {
413
+ // Group buckets by database
414
+ const bucketsByDatabase = new Map<string, any[]>();
415
+
416
+ relevantBuckets.forEach(bucket => {
417
+ const dbId = bucket.databaseId || 'ungrouped';
418
+ if (!bucketsByDatabase.has(dbId)) {
419
+ bucketsByDatabase.set(dbId, []);
420
+ }
421
+ bucketsByDatabase.get(dbId)!.push(bucket);
422
+ });
423
+
424
+ // Add buckets grouped by database
425
+ selectedDatabaseIds.forEach(dbId => {
426
+ const buckets = bucketsByDatabase.get(dbId) || [];
427
+ if (buckets.length > 0) {
428
+ choices.push(new inquirer.Separator(chalk.cyan(`📁 Database: ${dbId}`)));
429
+
430
+ buckets.forEach(bucket => {
431
+ const isConfigured = configuredIds.has(bucket.$id);
432
+ const status = isConfigured ? chalk.green('✅') : chalk.blue('○');
433
+ const name = `${status} ${bucket.name} (${bucket.$id})`;
434
+
435
+ if (allowNewOnly && isConfigured) {
436
+ return; // Skip configured buckets if only allowing new ones
437
+ }
438
+
439
+ choices.push({
440
+ name: ` ${name}`,
441
+ value: bucket.$id,
442
+ short: bucket.name,
443
+ checked: defaultSelected.includes(bucket.$id) || (!allowNewOnly && isConfigured)
444
+ });
445
+ });
446
+ }
447
+ });
448
+
449
+ // Add ungrouped buckets
450
+ const ungroupedBuckets = bucketsByDatabase.get('ungrouped') || [];
451
+ if (ungroupedBuckets.length > 0) {
452
+ choices.push(new inquirer.Separator(chalk.cyan('📁 General Storage')));
453
+
454
+ ungroupedBuckets.forEach(bucket => {
455
+ const isConfigured = configuredIds.has(bucket.$id);
456
+ const status = isConfigured ? chalk.green('✅') : chalk.blue('○');
457
+ const name = `${status} ${bucket.name} (${bucket.$id})`;
458
+
459
+ if (allowNewOnly && isConfigured) {
460
+ return; // Skip configured buckets if only allowing new ones
461
+ }
462
+
463
+ choices.push({
464
+ name: ` ${name}`,
465
+ value: bucket.$id,
466
+ short: bucket.name,
467
+ checked: defaultSelected.includes(bucket.$id) || (!allowNewOnly && isConfigured)
468
+ });
469
+ });
470
+ }
471
+ } else {
472
+ // Flat list of buckets
473
+ relevantBuckets.forEach(bucket => {
474
+ const isConfigured = configuredIds.has(bucket.$id);
475
+ const status = isConfigured ? chalk.green('✅') : chalk.blue('○');
476
+ const dbContext = bucket.databaseId ? ` [${bucket.databaseId}]` : '';
477
+ const name = `${status} ${bucket.name} (${bucket.$id})${dbContext}`;
478
+
479
+ if (allowNewOnly && isConfigured) {
480
+ return; // Skip configured buckets if only allowing new ones
481
+ }
482
+
483
+ choices.push({
484
+ name,
485
+ value: bucket.$id,
486
+ short: bucket.name,
487
+ checked: defaultSelected.includes(bucket.$id) || (!allowNewOnly && isConfigured)
488
+ });
489
+ });
490
+ }
491
+
492
+ const { selectedBucketIds } = await inquirer.prompt([{
493
+ type: 'checkbox',
494
+ name: 'selectedBucketIds',
495
+ message: 'Select storage buckets to sync:',
496
+ choices,
497
+ validate: (input: string[]) => {
498
+ if (input.length === 0) {
499
+ return chalk.yellow('No storage buckets selected. Continue with databases only?') || true;
500
+ }
501
+ if (input.includes('__SELECT_ALL__') && input.length > 1) {
502
+ return chalk.red('Cannot select "Select All" with individual buckets.');
503
+ }
504
+ return true;
505
+ }
506
+ }]);
507
+
508
+ // Handle select all
509
+ if (selectedBucketIds && selectedBucketIds.includes('__SELECT_ALL__')) {
510
+ const allIds = relevantBuckets.map(bucket => bucket.$id);
511
+ if (allowNewOnly) {
512
+ return allIds.filter(id => !configuredIds.has(id));
513
+ }
514
+ return allIds;
515
+ }
516
+
517
+ return selectedBucketIds || [];
518
+ }
519
+
520
+ /**
521
+ * Shows final confirmation dialog with sync selection summary
522
+ */
523
+ static async confirmSyncSelection(selectionSummary: SyncSelectionSummary): Promise<boolean> {
524
+ MessageFormatter.banner("Sync Selection Summary", "Review your selections before proceeding");
525
+
526
+ // Database summary
527
+ console.log(chalk.bold.cyan("\n📊 Databases:"));
528
+ console.log(` Total: ${selectionSummary.totalDatabases}`);
529
+ console.log(` ${chalk.green('✅ Configured')}: ${selectionSummary.existingItems.databases}`);
530
+ console.log(` ${chalk.blue('○ New')}: ${selectionSummary.newItems.databases}`);
531
+
532
+ if (selectionSummary.databases.length > 0) {
533
+ console.log(chalk.gray("\n Selected databases:"));
534
+ selectionSummary.databases.forEach(db => {
535
+ const status = db.isNew ? chalk.blue('○') : chalk.green('✅');
536
+ console.log(` ${status} ${db.databaseName} (${db.tableNames.length} tables)`);
537
+ });
538
+ }
539
+
540
+ // Table summary
541
+ console.log(chalk.bold.cyan("\n📋 Tables/Collections:"));
542
+ console.log(` Total: ${selectionSummary.totalTables}`);
543
+ console.log(` ${chalk.green('✅ Configured')}: ${selectionSummary.existingItems.tables}`);
544
+ console.log(` ${chalk.blue('○ New')}: ${selectionSummary.newItems.tables}`);
545
+
546
+ // Bucket summary
547
+ console.log(chalk.bold.cyan("\n🪣 Storage Buckets:"));
548
+ console.log(` Total: ${selectionSummary.totalBuckets}`);
549
+ console.log(` ${chalk.green('✅ Configured')}: ${selectionSummary.existingItems.buckets}`);
550
+ console.log(` ${chalk.blue('○ New')}: ${selectionSummary.newItems.buckets}`);
551
+
552
+ if (selectionSummary.buckets.length > 0) {
553
+ console.log(chalk.gray("\n Selected buckets:"));
554
+ selectionSummary.buckets.forEach(bucket => {
555
+ const status = bucket.isNew ? chalk.blue('○') : chalk.green('✅');
556
+ const dbContext = bucket.databaseName ? ` [${bucket.databaseName}]` : '';
557
+ console.log(` ${status} ${bucket.bucketName}${dbContext}`);
558
+ });
559
+ }
560
+
561
+ console.log(); // Add spacing
562
+
563
+ const { confirmed } = await inquirer.prompt([{
564
+ type: 'confirm',
565
+ name: 'confirmed',
566
+ message: chalk.green.bold('Proceed with sync operation?'),
567
+ default: true
568
+ }]);
569
+
570
+ if (confirmed) {
571
+ MessageFormatter.success("Sync operation confirmed.", { skipLogging: true });
572
+ logger.info("Sync selection confirmed", {
573
+ databases: selectionSummary.totalDatabases,
574
+ tables: selectionSummary.totalTables,
575
+ buckets: selectionSummary.totalBuckets
576
+ });
577
+ } else {
578
+ MessageFormatter.warning("Sync operation cancelled.", { skipLogging: true });
579
+ logger.info("Sync selection cancelled by user");
580
+ }
581
+
582
+ return confirmed;
583
+ }
584
+
585
+ /**
586
+ * Creates a sync selection summary from selected items
587
+ */
588
+ static createSyncSelectionSummary(
589
+ databaseSelections: DatabaseSelection[],
590
+ bucketSelections: BucketSelection[]
591
+ ): SyncSelectionSummary {
592
+ const totalDatabases = databaseSelections.length;
593
+ const totalTables = databaseSelections.reduce((sum, db) => sum + db.tableIds.length, 0);
594
+ const totalBuckets = bucketSelections.length;
595
+
596
+ const newDatabases = databaseSelections.filter(db => db.isNew).length;
597
+ const newTables = databaseSelections.reduce((sum, db) =>
598
+ sum + db.tableIds.length, 0); // TODO: Track which tables are new
599
+ const newBuckets = bucketSelections.filter(bucket => bucket.isNew).length;
600
+
601
+ const existingDatabases = totalDatabases - newDatabases;
602
+ const existingTables = totalTables - newTables;
603
+ const existingBuckets = totalBuckets - newBuckets;
604
+
605
+ return {
606
+ databases: databaseSelections,
607
+ buckets: bucketSelections,
608
+ totalDatabases,
609
+ totalTables,
610
+ totalBuckets,
611
+ newItems: {
612
+ databases: newDatabases,
613
+ tables: newTables,
614
+ buckets: newBuckets
615
+ },
616
+ existingItems: {
617
+ databases: existingDatabases,
618
+ tables: existingTables,
619
+ buckets: existingBuckets
620
+ }
621
+ };
622
+ }
623
+
624
+ /**
625
+ * Helper method to create database selection objects
626
+ */
627
+ static createDatabaseSelection(
628
+ selectedDatabaseIds: string[],
629
+ availableDatabases: Models.Database[],
630
+ tableSelectionsMap: Map<string, string[]>,
631
+ configuredDatabases: any[],
632
+ availableTablesMap: Map<string, any[]> = new Map()
633
+ ): DatabaseSelection[] {
634
+ const configuredIds = new Set(configuredDatabases.map(db => db.$id || db.id));
635
+
636
+ return selectedDatabaseIds.map(databaseId => {
637
+ const database = availableDatabases.find(db => db.$id === databaseId);
638
+ if (!database) {
639
+ throw new Error(`Database with ID ${databaseId} not found in available databases`);
640
+ }
641
+
642
+ const tableIds = tableSelectionsMap.get(databaseId) || [];
643
+ const tables = availableTablesMap.get(databaseId) || [];
644
+ const tableNames: string[] = tables.map(table => table.name || table.$id || `Table-${table.$id}`);
645
+
646
+ return {
647
+ databaseId,
648
+ databaseName: database.name,
649
+ tableIds,
650
+ tableNames,
651
+ isNew: !configuredIds.has(databaseId)
652
+ };
653
+ });
654
+ }
655
+
656
+ /**
657
+ * Helper method to create bucket selection objects
658
+ */
659
+ static createBucketSelection(
660
+ selectedBucketIds: string[],
661
+ availableBuckets: any[],
662
+ configuredBuckets: any[],
663
+ availableDatabases: Models.Database[]
664
+ ): BucketSelection[] {
665
+ const configuredIds = new Set(configuredBuckets.map(bucket => bucket.$id || bucket.id));
666
+
667
+ return selectedBucketIds.map(bucketId => {
668
+ const bucket = availableBuckets.find(b => b.$id === bucketId);
669
+ if (!bucket) {
670
+ throw new Error(`Bucket with ID ${bucketId} not found in available buckets`);
671
+ }
672
+
673
+ const database = bucket.databaseId ?
674
+ availableDatabases.find(db => db.$id === bucket.databaseId) : undefined;
675
+
676
+ return {
677
+ bucketId,
678
+ bucketName: bucket.name,
679
+ databaseId: bucket.databaseId,
680
+ databaseName: database?.name,
681
+ isNew: !configuredIds.has(bucketId)
682
+ };
683
+ });
684
+ }
685
+
686
+ /**
687
+ * Shows a progress message during selection operations
688
+ */
689
+ static showProgress(message: string): void {
690
+ MessageFormatter.progress(message, { skipLogging: true });
691
+ }
692
+
693
+ /**
694
+ * Shows an error message and handles graceful cancellation
695
+ */
696
+ static showError(message: string, error?: Error): void {
697
+ MessageFormatter.error(message, error, { skipLogging: true });
698
+ logger.error(`Selection dialog error: ${message}`, { error: error?.message });
699
+ }
700
+
701
+ /**
702
+ * Shows a warning message
703
+ */
704
+ static showWarning(message: string): void {
705
+ MessageFormatter.warning(message, { skipLogging: true });
706
+ logger.warn(`Selection dialog warning: ${message}`);
707
+ }
708
+
709
+ /**
710
+ * Shows a success message
711
+ */
712
+ static showSuccess(message: string): void {
713
+ MessageFormatter.success(message, { skipLogging: true });
714
+ logger.info(`Selection dialog success: ${message}`);
715
+ }
716
+ }