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.
- package/SELECTION_DIALOGS.md +146 -0
- package/dist/cli/commands/databaseCommands.js +90 -23
- package/dist/main.js +175 -4
- package/dist/migrations/appwriteToX.d.ts +27 -2
- package/dist/migrations/appwriteToX.js +293 -69
- package/dist/migrations/yaml/YamlImportConfigLoader.d.ts +1 -1
- package/dist/migrations/yaml/generateImportSchemas.js +23 -8
- package/dist/shared/schemaGenerator.js +25 -12
- package/dist/shared/selectionDialogs.d.ts +214 -0
- package/dist/shared/selectionDialogs.js +516 -0
- package/dist/utils/configDiscovery.d.ts +4 -4
- package/dist/utils/configDiscovery.js +66 -30
- package/dist/utils/yamlConverter.d.ts +1 -0
- package/dist/utils/yamlConverter.js +26 -3
- package/dist/utilsController.d.ts +6 -1
- package/dist/utilsController.js +91 -2
- package/package.json +1 -1
- package/src/cli/commands/databaseCommands.ts +134 -34
- package/src/main.ts +276 -34
- package/src/migrations/appwriteToX.ts +385 -90
- package/src/migrations/yaml/generateImportSchemas.ts +26 -8
- package/src/shared/schemaGenerator.ts +29 -12
- package/src/shared/selectionDialogs.ts +716 -0
- package/src/utils/configDiscovery.ts +83 -39
- package/src/utils/yamlConverter.ts +29 -3
- package/src/utilsController.ts +116 -4
|
@@ -0,0 +1,516 @@
|
|
|
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) {
|
|
363
|
+
MessageFormatter.banner("Sync Selection Summary", "Review your selections before proceeding");
|
|
364
|
+
// Database summary
|
|
365
|
+
console.log(chalk.bold.cyan("\n📊 Databases:"));
|
|
366
|
+
console.log(` Total: ${selectionSummary.totalDatabases}`);
|
|
367
|
+
console.log(` ${chalk.green('✅ Configured')}: ${selectionSummary.existingItems.databases}`);
|
|
368
|
+
console.log(` ${chalk.blue('○ New')}: ${selectionSummary.newItems.databases}`);
|
|
369
|
+
if (selectionSummary.databases.length > 0) {
|
|
370
|
+
console.log(chalk.gray("\n Selected databases:"));
|
|
371
|
+
selectionSummary.databases.forEach(db => {
|
|
372
|
+
const status = db.isNew ? chalk.blue('○') : chalk.green('✅');
|
|
373
|
+
console.log(` ${status} ${db.databaseName} (${db.tableNames.length} tables)`);
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
// Table summary
|
|
377
|
+
console.log(chalk.bold.cyan("\n📋 Tables/Collections:"));
|
|
378
|
+
console.log(` Total: ${selectionSummary.totalTables}`);
|
|
379
|
+
console.log(` ${chalk.green('✅ Configured')}: ${selectionSummary.existingItems.tables}`);
|
|
380
|
+
console.log(` ${chalk.blue('○ New')}: ${selectionSummary.newItems.tables}`);
|
|
381
|
+
// Bucket summary
|
|
382
|
+
console.log(chalk.bold.cyan("\n🪣 Storage Buckets:"));
|
|
383
|
+
console.log(` Total: ${selectionSummary.totalBuckets}`);
|
|
384
|
+
console.log(` ${chalk.green('✅ Configured')}: ${selectionSummary.existingItems.buckets}`);
|
|
385
|
+
console.log(` ${chalk.blue('○ New')}: ${selectionSummary.newItems.buckets}`);
|
|
386
|
+
if (selectionSummary.buckets.length > 0) {
|
|
387
|
+
console.log(chalk.gray("\n Selected buckets:"));
|
|
388
|
+
selectionSummary.buckets.forEach(bucket => {
|
|
389
|
+
const status = bucket.isNew ? chalk.blue('○') : chalk.green('✅');
|
|
390
|
+
const dbContext = bucket.databaseName ? ` [${bucket.databaseName}]` : '';
|
|
391
|
+
console.log(` ${status} ${bucket.bucketName}${dbContext}`);
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
console.log(); // Add spacing
|
|
395
|
+
const { confirmed } = await inquirer.prompt([{
|
|
396
|
+
type: 'confirm',
|
|
397
|
+
name: 'confirmed',
|
|
398
|
+
message: chalk.green.bold('Proceed with sync operation?'),
|
|
399
|
+
default: true
|
|
400
|
+
}]);
|
|
401
|
+
if (confirmed) {
|
|
402
|
+
MessageFormatter.success("Sync operation confirmed.", { skipLogging: true });
|
|
403
|
+
logger.info("Sync selection confirmed", {
|
|
404
|
+
databases: selectionSummary.totalDatabases,
|
|
405
|
+
tables: selectionSummary.totalTables,
|
|
406
|
+
buckets: selectionSummary.totalBuckets
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
else {
|
|
410
|
+
MessageFormatter.warning("Sync operation cancelled.", { skipLogging: true });
|
|
411
|
+
logger.info("Sync selection cancelled by user");
|
|
412
|
+
}
|
|
413
|
+
return confirmed;
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* Creates a sync selection summary from selected items
|
|
417
|
+
*/
|
|
418
|
+
static createSyncSelectionSummary(databaseSelections, bucketSelections) {
|
|
419
|
+
const totalDatabases = databaseSelections.length;
|
|
420
|
+
const totalTables = databaseSelections.reduce((sum, db) => sum + db.tableIds.length, 0);
|
|
421
|
+
const totalBuckets = bucketSelections.length;
|
|
422
|
+
const newDatabases = databaseSelections.filter(db => db.isNew).length;
|
|
423
|
+
const newTables = databaseSelections.reduce((sum, db) => sum + db.tableIds.length, 0); // TODO: Track which tables are new
|
|
424
|
+
const newBuckets = bucketSelections.filter(bucket => bucket.isNew).length;
|
|
425
|
+
const existingDatabases = totalDatabases - newDatabases;
|
|
426
|
+
const existingTables = totalTables - newTables;
|
|
427
|
+
const existingBuckets = totalBuckets - newBuckets;
|
|
428
|
+
return {
|
|
429
|
+
databases: databaseSelections,
|
|
430
|
+
buckets: bucketSelections,
|
|
431
|
+
totalDatabases,
|
|
432
|
+
totalTables,
|
|
433
|
+
totalBuckets,
|
|
434
|
+
newItems: {
|
|
435
|
+
databases: newDatabases,
|
|
436
|
+
tables: newTables,
|
|
437
|
+
buckets: newBuckets
|
|
438
|
+
},
|
|
439
|
+
existingItems: {
|
|
440
|
+
databases: existingDatabases,
|
|
441
|
+
tables: existingTables,
|
|
442
|
+
buckets: existingBuckets
|
|
443
|
+
}
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* Helper method to create database selection objects
|
|
448
|
+
*/
|
|
449
|
+
static createDatabaseSelection(selectedDatabaseIds, availableDatabases, tableSelectionsMap, configuredDatabases, availableTablesMap = new Map()) {
|
|
450
|
+
const configuredIds = new Set(configuredDatabases.map(db => db.$id || db.id));
|
|
451
|
+
return selectedDatabaseIds.map(databaseId => {
|
|
452
|
+
const database = availableDatabases.find(db => db.$id === databaseId);
|
|
453
|
+
if (!database) {
|
|
454
|
+
throw new Error(`Database with ID ${databaseId} not found in available databases`);
|
|
455
|
+
}
|
|
456
|
+
const tableIds = tableSelectionsMap.get(databaseId) || [];
|
|
457
|
+
const tables = availableTablesMap.get(databaseId) || [];
|
|
458
|
+
const tableNames = tables.map(table => table.name || table.$id || `Table-${table.$id}`);
|
|
459
|
+
return {
|
|
460
|
+
databaseId,
|
|
461
|
+
databaseName: database.name,
|
|
462
|
+
tableIds,
|
|
463
|
+
tableNames,
|
|
464
|
+
isNew: !configuredIds.has(databaseId)
|
|
465
|
+
};
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
/**
|
|
469
|
+
* Helper method to create bucket selection objects
|
|
470
|
+
*/
|
|
471
|
+
static createBucketSelection(selectedBucketIds, availableBuckets, configuredBuckets, availableDatabases) {
|
|
472
|
+
const configuredIds = new Set(configuredBuckets.map(bucket => bucket.$id || bucket.id));
|
|
473
|
+
return selectedBucketIds.map(bucketId => {
|
|
474
|
+
const bucket = availableBuckets.find(b => b.$id === bucketId);
|
|
475
|
+
if (!bucket) {
|
|
476
|
+
throw new Error(`Bucket with ID ${bucketId} not found in available buckets`);
|
|
477
|
+
}
|
|
478
|
+
const database = bucket.databaseId ?
|
|
479
|
+
availableDatabases.find(db => db.$id === bucket.databaseId) : undefined;
|
|
480
|
+
return {
|
|
481
|
+
bucketId,
|
|
482
|
+
bucketName: bucket.name,
|
|
483
|
+
databaseId: bucket.databaseId,
|
|
484
|
+
databaseName: database?.name,
|
|
485
|
+
isNew: !configuredIds.has(bucketId)
|
|
486
|
+
};
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* Shows a progress message during selection operations
|
|
491
|
+
*/
|
|
492
|
+
static showProgress(message) {
|
|
493
|
+
MessageFormatter.progress(message, { skipLogging: true });
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* Shows an error message and handles graceful cancellation
|
|
497
|
+
*/
|
|
498
|
+
static showError(message, error) {
|
|
499
|
+
MessageFormatter.error(message, error, { skipLogging: true });
|
|
500
|
+
logger.error(`Selection dialog error: ${message}`, { error: error?.message });
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* Shows a warning message
|
|
504
|
+
*/
|
|
505
|
+
static showWarning(message) {
|
|
506
|
+
MessageFormatter.warning(message, { skipLogging: true });
|
|
507
|
+
logger.warn(`Selection dialog warning: ${message}`);
|
|
508
|
+
}
|
|
509
|
+
/**
|
|
510
|
+
* Shows a success message
|
|
511
|
+
*/
|
|
512
|
+
static showSuccess(message) {
|
|
513
|
+
MessageFormatter.success(message, { skipLogging: true });
|
|
514
|
+
logger.info(`Selection dialog success: ${message}`);
|
|
515
|
+
}
|
|
516
|
+
}
|
|
@@ -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
|
|
30
|
+
* Loads a YAML table file and converts it to CollectionCreate format
|
|
31
31
|
* @param filePath Path to the YAML table file
|
|
32
|
-
* @returns
|
|
32
|
+
* @returns CollectionCreate object or null if loading fails
|
|
33
33
|
*/
|
|
34
|
-
export declare const loadYamlTable: (filePath: string) =>
|
|
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:
|
|
57
|
+
tables: CollectionCreate[];
|
|
58
58
|
loadedNames: Set<string>;
|
|
59
59
|
conflicts: Array<{
|
|
60
60
|
name: string;
|
|
@@ -135,6 +135,45 @@ const YamlCollectionSchema = z.object({
|
|
|
135
135
|
})).optional().default([]),
|
|
136
136
|
importDefs: z.array(z.any()).optional().default([])
|
|
137
137
|
});
|
|
138
|
+
// YAML Table Schema - Supports table-specific terminology
|
|
139
|
+
const YamlTableSchema = z.object({
|
|
140
|
+
name: z.string(),
|
|
141
|
+
id: z.string().optional(),
|
|
142
|
+
rowSecurity: z.boolean().default(false), // Tables use rowSecurity
|
|
143
|
+
enabled: z.boolean().default(true),
|
|
144
|
+
permissions: z.array(z.object({
|
|
145
|
+
permission: z.string(),
|
|
146
|
+
target: z.string()
|
|
147
|
+
})).optional().default([]),
|
|
148
|
+
columns: z.array(// Tables use columns terminology
|
|
149
|
+
z.object({
|
|
150
|
+
key: z.string(),
|
|
151
|
+
type: z.string(),
|
|
152
|
+
size: z.number().optional(),
|
|
153
|
+
required: z.boolean().default(false),
|
|
154
|
+
array: z.boolean().optional(),
|
|
155
|
+
encrypted: z.boolean().optional(), // Tables support encrypted property
|
|
156
|
+
default: z.any().optional(),
|
|
157
|
+
min: z.number().optional(),
|
|
158
|
+
max: z.number().optional(),
|
|
159
|
+
elements: z.array(z.string()).optional(),
|
|
160
|
+
relatedTable: z.string().optional(), // Tables use relatedTable
|
|
161
|
+
relationType: z.string().optional(),
|
|
162
|
+
twoWay: z.boolean().optional(),
|
|
163
|
+
twoWayKey: z.string().optional(),
|
|
164
|
+
onDelete: z.string().optional(),
|
|
165
|
+
side: z.string().optional(),
|
|
166
|
+
encrypt: z.boolean().optional(),
|
|
167
|
+
format: z.string().optional()
|
|
168
|
+
})).optional().default([]),
|
|
169
|
+
indexes: z.array(z.object({
|
|
170
|
+
key: z.string(),
|
|
171
|
+
type: z.string(),
|
|
172
|
+
columns: z.array(z.string()), // Tables use columns in indexes
|
|
173
|
+
orders: z.array(z.string()).optional()
|
|
174
|
+
})).optional().default([]),
|
|
175
|
+
importDefs: z.array(z.any()).optional().default([])
|
|
176
|
+
});
|
|
138
177
|
/**
|
|
139
178
|
* Loads a YAML collection file and converts it to CollectionCreate format
|
|
140
179
|
* @param filePath Path to the YAML collection file
|
|
@@ -190,55 +229,52 @@ export const loadYamlCollection = (filePath) => {
|
|
|
190
229
|
}
|
|
191
230
|
};
|
|
192
231
|
/**
|
|
193
|
-
* Loads a YAML table file and converts it to
|
|
232
|
+
* Loads a YAML table file and converts it to CollectionCreate format
|
|
194
233
|
* @param filePath Path to the YAML table file
|
|
195
|
-
* @returns
|
|
234
|
+
* @returns CollectionCreate object or null if loading fails
|
|
196
235
|
*/
|
|
197
236
|
export const loadYamlTable = (filePath) => {
|
|
198
237
|
try {
|
|
199
238
|
const fileContent = fs.readFileSync(filePath, "utf8");
|
|
200
239
|
const yamlData = yaml.load(fileContent);
|
|
201
|
-
//
|
|
202
|
-
const parsedTable =
|
|
203
|
-
// Convert YAML table to
|
|
240
|
+
// Use the new table-specific schema
|
|
241
|
+
const parsedTable = YamlTableSchema.parse(yamlData);
|
|
242
|
+
// Convert YAML table to CollectionCreate format (internal representation)
|
|
204
243
|
const table = {
|
|
205
244
|
name: parsedTable.name,
|
|
206
|
-
|
|
207
|
-
documentSecurity: parsedTable.documentSecurity
|
|
245
|
+
$id: yamlData.tableId || parsedTable.id || parsedTable.name.toLowerCase().replace(/\s+/g, '_'),
|
|
246
|
+
documentSecurity: parsedTable.rowSecurity, // Convert rowSecurity to documentSecurity
|
|
208
247
|
enabled: parsedTable.enabled,
|
|
209
248
|
$permissions: parsedTable.permissions.map(p => ({
|
|
210
249
|
permission: p.permission,
|
|
211
250
|
target: p.target
|
|
212
251
|
})),
|
|
213
|
-
attributes: parsedTable.
|
|
214
|
-
key:
|
|
215
|
-
type:
|
|
216
|
-
size:
|
|
217
|
-
required:
|
|
218
|
-
array:
|
|
219
|
-
xdefault:
|
|
220
|
-
min:
|
|
221
|
-
max:
|
|
222
|
-
elements:
|
|
223
|
-
relatedCollection:
|
|
224
|
-
relationType:
|
|
225
|
-
twoWay:
|
|
226
|
-
twoWayKey:
|
|
227
|
-
onDelete:
|
|
228
|
-
side:
|
|
229
|
-
encrypted:
|
|
230
|
-
format:
|
|
252
|
+
attributes: parsedTable.columns.map(col => ({
|
|
253
|
+
key: col.key,
|
|
254
|
+
type: col.type,
|
|
255
|
+
size: col.size,
|
|
256
|
+
required: col.required,
|
|
257
|
+
array: col.array,
|
|
258
|
+
xdefault: col.default,
|
|
259
|
+
min: col.min,
|
|
260
|
+
max: col.max,
|
|
261
|
+
elements: col.elements,
|
|
262
|
+
relatedCollection: col.relatedTable, // Convert relatedTable to relatedCollection
|
|
263
|
+
relationType: col.relationType,
|
|
264
|
+
twoWay: col.twoWay,
|
|
265
|
+
twoWayKey: col.twoWayKey,
|
|
266
|
+
onDelete: col.onDelete,
|
|
267
|
+
side: col.side,
|
|
268
|
+
encrypted: col.encrypted || col.encrypt, // Support both encrypted and encrypt
|
|
269
|
+
format: col.format
|
|
231
270
|
})),
|
|
232
271
|
indexes: parsedTable.indexes.map(idx => ({
|
|
233
272
|
key: idx.key,
|
|
234
273
|
type: idx.type,
|
|
235
|
-
attributes: idx.attributes
|
|
274
|
+
attributes: idx.columns, // Convert columns to attributes
|
|
236
275
|
orders: idx.orders
|
|
237
276
|
})),
|
|
238
|
-
importDefs: parsedTable.importDefs
|
|
239
|
-
databaseId: yamlData.databaseId,
|
|
240
|
-
// Add backward compatibility field
|
|
241
|
-
$id: yamlData.$id || parsedTable.id
|
|
277
|
+
importDefs: parsedTable.importDefs || []
|
|
242
278
|
};
|
|
243
279
|
return table;
|
|
244
280
|
}
|