appwrite-utils-cli 1.11.0 → 1.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (250) hide show
  1. package/{src/adapters/index.ts → dist/adapters/index.d.ts} +0 -1
  2. package/dist/adapters/index.js +10 -0
  3. package/dist/backups/operations/bucketBackup.d.ts +19 -0
  4. package/dist/backups/operations/bucketBackup.js +197 -0
  5. package/dist/backups/operations/collectionBackup.d.ts +30 -0
  6. package/dist/backups/operations/collectionBackup.js +201 -0
  7. package/dist/backups/operations/comprehensiveBackup.d.ts +25 -0
  8. package/dist/backups/operations/comprehensiveBackup.js +238 -0
  9. package/dist/backups/schemas/bucketManifest.d.ts +93 -0
  10. package/dist/backups/schemas/bucketManifest.js +33 -0
  11. package/dist/backups/schemas/comprehensiveManifest.d.ts +108 -0
  12. package/dist/backups/schemas/comprehensiveManifest.js +32 -0
  13. package/dist/backups/tracking/centralizedTracking.d.ts +34 -0
  14. package/dist/backups/tracking/centralizedTracking.js +274 -0
  15. package/dist/cli/commands/configCommands.d.ts +8 -0
  16. package/dist/cli/commands/configCommands.js +210 -0
  17. package/dist/cli/commands/databaseCommands.d.ts +14 -0
  18. package/dist/cli/commands/databaseCommands.js +696 -0
  19. package/dist/cli/commands/functionCommands.d.ts +7 -0
  20. package/dist/cli/commands/functionCommands.js +330 -0
  21. package/dist/cli/commands/importFileCommands.d.ts +7 -0
  22. package/dist/cli/commands/importFileCommands.js +674 -0
  23. package/dist/cli/commands/schemaCommands.d.ts +7 -0
  24. package/dist/cli/commands/schemaCommands.js +169 -0
  25. package/dist/cli/commands/storageCommands.d.ts +5 -0
  26. package/dist/cli/commands/storageCommands.js +142 -0
  27. package/dist/cli/commands/transferCommands.d.ts +5 -0
  28. package/dist/cli/commands/transferCommands.js +382 -0
  29. package/dist/collections/columns.d.ts +13 -0
  30. package/dist/collections/columns.js +1339 -0
  31. package/dist/collections/indexes.d.ts +12 -0
  32. package/dist/collections/indexes.js +215 -0
  33. package/dist/collections/methods.d.ts +19 -0
  34. package/dist/collections/methods.js +605 -0
  35. package/dist/collections/tableOperations.d.ts +87 -0
  36. package/dist/collections/tableOperations.js +466 -0
  37. package/dist/collections/transferOperations.d.ts +8 -0
  38. package/dist/collections/transferOperations.js +411 -0
  39. package/dist/collections/wipeOperations.d.ts +17 -0
  40. package/dist/collections/wipeOperations.js +306 -0
  41. package/dist/databases/methods.d.ts +6 -0
  42. package/dist/databases/methods.js +35 -0
  43. package/dist/databases/setup.d.ts +5 -0
  44. package/dist/databases/setup.js +45 -0
  45. package/dist/examples/yamlTerminologyExample.d.ts +42 -0
  46. package/dist/examples/yamlTerminologyExample.js +272 -0
  47. package/dist/functions/deployments.d.ts +4 -0
  48. package/dist/functions/deployments.js +146 -0
  49. package/dist/functions/fnConfigDiscovery.d.ts +3 -0
  50. package/dist/functions/fnConfigDiscovery.js +108 -0
  51. package/dist/functions/methods.d.ts +16 -0
  52. package/dist/functions/methods.js +174 -0
  53. package/dist/init.d.ts +2 -0
  54. package/dist/init.js +57 -0
  55. package/dist/interactiveCLI.d.ts +36 -0
  56. package/dist/interactiveCLI.js +952 -0
  57. package/dist/main.d.ts +2 -0
  58. package/dist/main.js +1125 -0
  59. package/dist/migrations/afterImportActions.d.ts +17 -0
  60. package/dist/migrations/afterImportActions.js +305 -0
  61. package/dist/migrations/appwriteToX.d.ts +211 -0
  62. package/dist/migrations/appwriteToX.js +493 -0
  63. package/dist/migrations/comprehensiveTransfer.d.ts +147 -0
  64. package/dist/migrations/comprehensiveTransfer.js +1315 -0
  65. package/dist/migrations/dataLoader.d.ts +755 -0
  66. package/dist/migrations/dataLoader.js +1272 -0
  67. package/dist/migrations/importController.d.ts +25 -0
  68. package/dist/migrations/importController.js +283 -0
  69. package/dist/migrations/importDataActions.d.ts +50 -0
  70. package/dist/migrations/importDataActions.js +230 -0
  71. package/dist/migrations/relationships.d.ts +29 -0
  72. package/dist/migrations/relationships.js +203 -0
  73. package/dist/migrations/services/DataTransformationService.d.ts +55 -0
  74. package/dist/migrations/services/DataTransformationService.js +158 -0
  75. package/dist/migrations/services/FileHandlerService.d.ts +75 -0
  76. package/dist/migrations/services/FileHandlerService.js +236 -0
  77. package/dist/migrations/services/ImportOrchestrator.d.ts +99 -0
  78. package/dist/migrations/services/ImportOrchestrator.js +493 -0
  79. package/dist/migrations/services/RateLimitManager.d.ts +138 -0
  80. package/dist/migrations/services/RateLimitManager.js +279 -0
  81. package/dist/migrations/services/RelationshipResolver.d.ts +120 -0
  82. package/dist/migrations/services/RelationshipResolver.js +332 -0
  83. package/dist/migrations/services/UserMappingService.d.ts +109 -0
  84. package/dist/migrations/services/UserMappingService.js +277 -0
  85. package/dist/migrations/services/ValidationService.d.ts +74 -0
  86. package/dist/migrations/services/ValidationService.js +260 -0
  87. package/dist/migrations/transfer.d.ts +30 -0
  88. package/dist/migrations/transfer.js +661 -0
  89. package/dist/migrations/yaml/YamlImportConfigLoader.d.ts +131 -0
  90. package/dist/migrations/yaml/YamlImportConfigLoader.js +383 -0
  91. package/dist/migrations/yaml/YamlImportIntegration.d.ts +93 -0
  92. package/dist/migrations/yaml/YamlImportIntegration.js +341 -0
  93. package/dist/migrations/yaml/generateImportSchemas.d.ts +30 -0
  94. package/dist/migrations/yaml/generateImportSchemas.js +1327 -0
  95. package/dist/schemas/authUser.d.ts +24 -0
  96. package/dist/schemas/authUser.js +17 -0
  97. package/dist/setup.d.ts +2 -0
  98. package/{src/setup.ts → dist/setup.js} +0 -3
  99. package/dist/setupCommands.d.ts +58 -0
  100. package/dist/setupCommands.js +489 -0
  101. package/dist/setupController.d.ts +9 -0
  102. package/dist/setupController.js +34 -0
  103. package/dist/shared/backupMetadataSchema.d.ts +94 -0
  104. package/dist/shared/backupMetadataSchema.js +38 -0
  105. package/dist/shared/backupTracking.d.ts +18 -0
  106. package/dist/shared/backupTracking.js +176 -0
  107. package/dist/shared/confirmationDialogs.d.ts +75 -0
  108. package/dist/shared/confirmationDialogs.js +236 -0
  109. package/dist/shared/migrationHelpers.d.ts +61 -0
  110. package/dist/shared/migrationHelpers.js +145 -0
  111. package/{src/shared/operationLogger.ts → dist/shared/operationLogger.d.ts} +1 -11
  112. package/dist/shared/operationLogger.js +12 -0
  113. package/dist/shared/operationQueue.d.ts +40 -0
  114. package/dist/shared/operationQueue.js +310 -0
  115. package/dist/shared/operationsTable.d.ts +26 -0
  116. package/dist/shared/operationsTable.js +287 -0
  117. package/dist/shared/operationsTableSchema.d.ts +48 -0
  118. package/dist/shared/operationsTableSchema.js +35 -0
  119. package/dist/shared/progressManager.d.ts +62 -0
  120. package/dist/shared/progressManager.js +215 -0
  121. package/dist/shared/relationshipExtractor.d.ts +56 -0
  122. package/dist/shared/relationshipExtractor.js +138 -0
  123. package/dist/shared/selectionDialogs.d.ts +220 -0
  124. package/dist/shared/selectionDialogs.js +588 -0
  125. package/dist/storage/backupCompression.d.ts +20 -0
  126. package/dist/storage/backupCompression.js +67 -0
  127. package/dist/storage/methods.d.ts +44 -0
  128. package/dist/storage/methods.js +475 -0
  129. package/dist/storage/schemas.d.ts +842 -0
  130. package/dist/storage/schemas.js +175 -0
  131. package/dist/tables/indexManager.d.ts +65 -0
  132. package/dist/tables/indexManager.js +294 -0
  133. package/{src/types.ts → dist/types.d.ts} +1 -6
  134. package/dist/types.js +3 -0
  135. package/dist/users/methods.d.ts +16 -0
  136. package/dist/users/methods.js +276 -0
  137. package/dist/utils/configMigration.d.ts +1 -0
  138. package/dist/utils/configMigration.js +261 -0
  139. package/dist/utils/index.js +2 -0
  140. package/dist/utils/loadConfigs.d.ts +50 -0
  141. package/dist/utils/loadConfigs.js +357 -0
  142. package/dist/utils/setupFiles.d.ts +4 -0
  143. package/dist/utils/setupFiles.js +1190 -0
  144. package/dist/utilsController.d.ts +114 -0
  145. package/dist/utilsController.js +898 -0
  146. package/package.json +6 -3
  147. package/CHANGELOG.md +0 -35
  148. package/CONFIG_TODO.md +0 -1189
  149. package/SELECTION_DIALOGS.md +0 -146
  150. package/SERVICE_IMPLEMENTATION_REPORT.md +0 -462
  151. package/scripts/copy-templates.ts +0 -23
  152. package/src/backups/operations/bucketBackup.ts +0 -277
  153. package/src/backups/operations/collectionBackup.ts +0 -310
  154. package/src/backups/operations/comprehensiveBackup.ts +0 -342
  155. package/src/backups/schemas/bucketManifest.ts +0 -78
  156. package/src/backups/schemas/comprehensiveManifest.ts +0 -76
  157. package/src/backups/tracking/centralizedTracking.ts +0 -352
  158. package/src/cli/commands/configCommands.ts +0 -265
  159. package/src/cli/commands/databaseCommands.ts +0 -931
  160. package/src/cli/commands/functionCommands.ts +0 -419
  161. package/src/cli/commands/importFileCommands.ts +0 -815
  162. package/src/cli/commands/schemaCommands.ts +0 -200
  163. package/src/cli/commands/storageCommands.ts +0 -151
  164. package/src/cli/commands/transferCommands.ts +0 -454
  165. package/src/collections/attributes.ts.backup +0 -1555
  166. package/src/collections/columns.ts +0 -2025
  167. package/src/collections/indexes.ts +0 -350
  168. package/src/collections/methods.ts +0 -714
  169. package/src/collections/tableOperations.ts +0 -542
  170. package/src/collections/transferOperations.ts +0 -589
  171. package/src/collections/wipeOperations.ts +0 -449
  172. package/src/databases/methods.ts +0 -49
  173. package/src/databases/setup.ts +0 -77
  174. package/src/examples/yamlTerminologyExample.ts +0 -346
  175. package/src/functions/deployments.ts +0 -221
  176. package/src/functions/fnConfigDiscovery.ts +0 -103
  177. package/src/functions/methods.ts +0 -284
  178. package/src/init.ts +0 -62
  179. package/src/interactiveCLI.ts +0 -1201
  180. package/src/main.ts +0 -1517
  181. package/src/migrations/afterImportActions.ts +0 -579
  182. package/src/migrations/appwriteToX.ts +0 -668
  183. package/src/migrations/comprehensiveTransfer.ts +0 -2285
  184. package/src/migrations/dataLoader.ts +0 -1729
  185. package/src/migrations/importController.ts +0 -440
  186. package/src/migrations/importDataActions.ts +0 -315
  187. package/src/migrations/relationships.ts +0 -333
  188. package/src/migrations/services/DataTransformationService.ts +0 -196
  189. package/src/migrations/services/FileHandlerService.ts +0 -311
  190. package/src/migrations/services/ImportOrchestrator.ts +0 -675
  191. package/src/migrations/services/RateLimitManager.ts +0 -363
  192. package/src/migrations/services/RelationshipResolver.ts +0 -461
  193. package/src/migrations/services/UserMappingService.ts +0 -345
  194. package/src/migrations/services/ValidationService.ts +0 -349
  195. package/src/migrations/transfer.ts +0 -1113
  196. package/src/migrations/yaml/YamlImportConfigLoader.ts +0 -439
  197. package/src/migrations/yaml/YamlImportIntegration.ts +0 -446
  198. package/src/migrations/yaml/generateImportSchemas.ts +0 -1354
  199. package/src/schemas/authUser.ts +0 -23
  200. package/src/setupCommands.ts +0 -602
  201. package/src/setupController.ts +0 -43
  202. package/src/shared/backupMetadataSchema.ts +0 -93
  203. package/src/shared/backupTracking.ts +0 -211
  204. package/src/shared/confirmationDialogs.ts +0 -327
  205. package/src/shared/migrationHelpers.ts +0 -232
  206. package/src/shared/operationQueue.ts +0 -376
  207. package/src/shared/operationsTable.ts +0 -338
  208. package/src/shared/operationsTableSchema.ts +0 -60
  209. package/src/shared/progressManager.ts +0 -278
  210. package/src/shared/relationshipExtractor.ts +0 -214
  211. package/src/shared/selectionDialogs.ts +0 -802
  212. package/src/storage/backupCompression.ts +0 -88
  213. package/src/storage/methods.ts +0 -711
  214. package/src/storage/schemas.ts +0 -205
  215. package/src/tables/indexManager.ts +0 -409
  216. package/src/types/node-appwrite-tablesdb.d.ts +0 -44
  217. package/src/users/methods.ts +0 -358
  218. package/src/utils/configMigration.ts +0 -348
  219. package/src/utils/loadConfigs.ts +0 -457
  220. package/src/utils/setupFiles.ts +0 -1236
  221. package/src/utilsController.ts +0 -1263
  222. package/tests/README.md +0 -497
  223. package/tests/adapters/AdapterFactory.test.ts +0 -277
  224. package/tests/integration/syncOperations.test.ts +0 -463
  225. package/tests/jest.config.js +0 -25
  226. package/tests/migration/configMigration.test.ts +0 -546
  227. package/tests/setup.ts +0 -62
  228. package/tests/testUtils.ts +0 -340
  229. package/tests/utils/loadConfigs.test.ts +0 -350
  230. package/tests/validation/configValidation.test.ts +0 -412
  231. package/tsconfig.json +0 -44
  232. /package/{src → dist}/functions/templates/count-docs-in-collection/README.md +0 -0
  233. /package/{src → dist}/functions/templates/count-docs-in-collection/src/main.ts +0 -0
  234. /package/{src → dist}/functions/templates/count-docs-in-collection/src/request.ts +0 -0
  235. /package/{src → dist}/functions/templates/hono-typescript/README.md +0 -0
  236. /package/{src → dist}/functions/templates/hono-typescript/src/adapters/request.ts +0 -0
  237. /package/{src → dist}/functions/templates/hono-typescript/src/adapters/response.ts +0 -0
  238. /package/{src → dist}/functions/templates/hono-typescript/src/app.ts +0 -0
  239. /package/{src → dist}/functions/templates/hono-typescript/src/context.ts +0 -0
  240. /package/{src → dist}/functions/templates/hono-typescript/src/main.ts +0 -0
  241. /package/{src → dist}/functions/templates/hono-typescript/src/middleware/appwrite.ts +0 -0
  242. /package/{src → dist}/functions/templates/typescript-node/README.md +0 -0
  243. /package/{src → dist}/functions/templates/typescript-node/src/context.ts +0 -0
  244. /package/{src → dist}/functions/templates/typescript-node/src/main.ts +0 -0
  245. /package/{src → dist}/functions/templates/uv/README.md +0 -0
  246. /package/{src → dist}/functions/templates/uv/pyproject.toml +0 -0
  247. /package/{src → dist}/functions/templates/uv/src/__init__.py +0 -0
  248. /package/{src → dist}/functions/templates/uv/src/context.py +0 -0
  249. /package/{src → dist}/functions/templates/uv/src/main.py +0 -0
  250. /package/{src/utils/index.ts → dist/utils/index.d.ts} +0 -0
@@ -0,0 +1,588 @@
1
+ import inquirer from "inquirer";
2
+ import chalk from "chalk";
3
+ import { MessageFormatter } from 'appwrite-utils-helpers';
4
+ import { logger } from 'appwrite-utils-helpers';
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
+ // Do not preselect anything unless explicitly provided
149
+ checked: defaultSelected.includes(database.$id)
150
+ });
151
+ });
152
+ if (choices.length === 0) {
153
+ MessageFormatter.warning("No databases available for selection.", { skipLogging: true });
154
+ return [];
155
+ }
156
+ const { selectedDatabaseIds } = await inquirer.prompt([{
157
+ type: 'checkbox',
158
+ name: 'selectedDatabaseIds',
159
+ message: 'Select databases to sync:',
160
+ choices,
161
+ validate: (input) => {
162
+ if (input.length === 0) {
163
+ return chalk.red('Please select at least one database.');
164
+ }
165
+ if (input.includes('__SELECT_ALL__') && input.length > 1) {
166
+ return chalk.red('Cannot select "Select All" with individual databases.');
167
+ }
168
+ return true;
169
+ }
170
+ }]);
171
+ // Handle select all
172
+ if (selectedDatabaseIds.includes('__SELECT_ALL__')) {
173
+ const allIds = availableDatabases.map(db => db.$id);
174
+ if (allowNewOnly) {
175
+ return allIds.filter(id => !configuredIds.has(id));
176
+ }
177
+ return allIds;
178
+ }
179
+ return selectedDatabaseIds;
180
+ }
181
+ /**
182
+ * Shows table/collection selection dialog for a specific database
183
+ */
184
+ static async selectTablesForDatabase(databaseId, databaseName, availableTables, configuredTables, options = {}) {
185
+ const { showSelectAll = true, allowNewOnly = false, defaultSelected = [], showDatabaseContext = true } = options;
186
+ if (showDatabaseContext) {
187
+ MessageFormatter.section(`Table Selection for ${databaseName}`);
188
+ }
189
+ const configuredIds = new Set(configuredTables.map(table => table.$id || table.id || table.tableId || table.name));
190
+ let choices = [];
191
+ if (showSelectAll && availableTables.length > 1) {
192
+ choices.push({
193
+ name: chalk.green.bold('📋 Select All Tables'),
194
+ value: '__SELECT_ALL__',
195
+ short: 'All tables'
196
+ });
197
+ }
198
+ availableTables.forEach(table => {
199
+ const tableId = table.$id || table.id || table.tableId || table.name;
200
+ const isConfigured = configuredIds.has(tableId);
201
+ const status = isConfigured ? chalk.green('✅') : chalk.blue('○');
202
+ const name = `${status} ${table.name} (${tableId})`;
203
+ if (allowNewOnly && isConfigured) {
204
+ return; // Skip configured tables if only allowing new ones
205
+ }
206
+ choices.push({
207
+ name,
208
+ value: tableId,
209
+ short: table.name,
210
+ // Do not preselect anything unless explicitly provided
211
+ checked: defaultSelected.includes(tableId)
212
+ });
213
+ });
214
+ if (choices.length === 0) {
215
+ MessageFormatter.warning(`No tables available for database: ${databaseName}`, { skipLogging: true });
216
+ return [];
217
+ }
218
+ const { selectedTableIds } = await inquirer.prompt([{
219
+ type: 'checkbox',
220
+ name: 'selectedTableIds',
221
+ message: `Select tables to sync for ${databaseName}:`,
222
+ choices,
223
+ validate: (input) => {
224
+ if (input.length === 0) {
225
+ return chalk.red('Please select at least one table.');
226
+ }
227
+ if (input.includes('__SELECT_ALL__') && input.length > 1) {
228
+ return chalk.red('Cannot select "Select All" with individual tables.');
229
+ }
230
+ return true;
231
+ }
232
+ }]);
233
+ // Handle select all
234
+ if (selectedTableIds.includes('__SELECT_ALL__')) {
235
+ const allIds = availableTables.map(table => table.$id || table.id || table.tableId || table.name);
236
+ if (allowNewOnly) {
237
+ return allIds.filter(id => !configuredIds.has(id));
238
+ }
239
+ return allIds;
240
+ }
241
+ return selectedTableIds;
242
+ }
243
+ /**
244
+ * Shows bucket selection dialog for selected databases
245
+ */
246
+ static async selectBucketsForDatabases(selectedDatabaseIds, availableBuckets, configuredBuckets, options = {}) {
247
+ const { showSelectAll = true, allowNewOnly = false, defaultSelected = [], groupByDatabase = true } = options;
248
+ MessageFormatter.section("Storage Bucket Selection");
249
+ const configuredIds = new Set(configuredBuckets.map(bucket => bucket.$id || bucket.id));
250
+ // Filter buckets that are associated with selected databases
251
+ const relevantBuckets = availableBuckets.filter(bucket => {
252
+ if (selectedDatabaseIds.length === 0)
253
+ return true; // If no databases selected, show all buckets
254
+ return selectedDatabaseIds.includes(bucket.databaseId) || !bucket.databaseId;
255
+ });
256
+ if (relevantBuckets.length === 0) {
257
+ MessageFormatter.warning("No storage buckets available for selected databases.", { skipLogging: true });
258
+ return [];
259
+ }
260
+ let choices = [];
261
+ if (showSelectAll && relevantBuckets.length > 1) {
262
+ choices.push({
263
+ name: chalk.green.bold('📋 Select All Buckets'),
264
+ value: '__SELECT_ALL__',
265
+ short: 'All buckets'
266
+ });
267
+ }
268
+ if (groupByDatabase) {
269
+ // Group buckets by database
270
+ const bucketsByDatabase = new Map();
271
+ relevantBuckets.forEach(bucket => {
272
+ const dbId = bucket.databaseId || 'ungrouped';
273
+ if (!bucketsByDatabase.has(dbId)) {
274
+ bucketsByDatabase.set(dbId, []);
275
+ }
276
+ bucketsByDatabase.get(dbId).push(bucket);
277
+ });
278
+ // Add buckets grouped by database
279
+ selectedDatabaseIds.forEach(dbId => {
280
+ const buckets = bucketsByDatabase.get(dbId) || [];
281
+ if (buckets.length > 0) {
282
+ choices.push(new inquirer.Separator(chalk.cyan(`📁 Database: ${dbId}`)));
283
+ buckets.forEach(bucket => {
284
+ const isConfigured = configuredIds.has(bucket.$id);
285
+ const status = isConfigured ? chalk.green('✅') : chalk.blue('○');
286
+ const name = `${status} ${bucket.name} (${bucket.$id})`;
287
+ if (allowNewOnly && isConfigured) {
288
+ return; // Skip configured buckets if only allowing new ones
289
+ }
290
+ choices.push({
291
+ name: ` ${name}`,
292
+ value: bucket.$id,
293
+ short: bucket.name,
294
+ // Do not preselect anything unless explicitly provided
295
+ checked: defaultSelected.includes(bucket.$id)
296
+ });
297
+ });
298
+ }
299
+ });
300
+ // Add ungrouped buckets
301
+ const ungroupedBuckets = bucketsByDatabase.get('ungrouped') || [];
302
+ if (ungroupedBuckets.length > 0) {
303
+ choices.push(new inquirer.Separator(chalk.cyan('📁 General Storage')));
304
+ ungroupedBuckets.forEach(bucket => {
305
+ const isConfigured = configuredIds.has(bucket.$id);
306
+ const status = isConfigured ? chalk.green('✅') : chalk.blue('○');
307
+ const name = `${status} ${bucket.name} (${bucket.$id})`;
308
+ if (allowNewOnly && isConfigured) {
309
+ return; // Skip configured buckets if only allowing new ones
310
+ }
311
+ choices.push({
312
+ name: ` ${name}`,
313
+ value: bucket.$id,
314
+ short: bucket.name,
315
+ checked: defaultSelected.includes(bucket.$id) || (!allowNewOnly && isConfigured)
316
+ });
317
+ });
318
+ }
319
+ }
320
+ else {
321
+ // Flat list of buckets
322
+ relevantBuckets.forEach(bucket => {
323
+ const isConfigured = configuredIds.has(bucket.$id);
324
+ const status = isConfigured ? chalk.green('✅') : chalk.blue('○');
325
+ const dbContext = bucket.databaseId ? ` [${bucket.databaseId}]` : '';
326
+ const name = `${status} ${bucket.name} (${bucket.$id})${dbContext}`;
327
+ if (allowNewOnly && isConfigured) {
328
+ return; // Skip configured buckets if only allowing new ones
329
+ }
330
+ choices.push({
331
+ name,
332
+ value: bucket.$id,
333
+ short: bucket.name,
334
+ // Do not preselect anything unless explicitly provided
335
+ checked: defaultSelected.includes(bucket.$id)
336
+ });
337
+ });
338
+ }
339
+ const { selectedBucketIds } = await inquirer.prompt([{
340
+ type: 'checkbox',
341
+ name: 'selectedBucketIds',
342
+ message: 'Select storage buckets to sync:',
343
+ choices,
344
+ validate: (input) => {
345
+ if (input.length === 0) {
346
+ return chalk.yellow('No storage buckets selected. Continue with databases only?') || true;
347
+ }
348
+ if (input.includes('__SELECT_ALL__') && input.length > 1) {
349
+ return chalk.red('Cannot select "Select All" with individual buckets.');
350
+ }
351
+ return true;
352
+ }
353
+ }]);
354
+ // Handle select all
355
+ if (selectedBucketIds && selectedBucketIds.includes('__SELECT_ALL__')) {
356
+ const allIds = relevantBuckets.map(bucket => bucket.$id);
357
+ if (allowNewOnly) {
358
+ return allIds.filter(id => !configuredIds.has(id));
359
+ }
360
+ return allIds;
361
+ }
362
+ return selectedBucketIds || [];
363
+ }
364
+ /**
365
+ * Shows bucket selection for push operations with merged local+remote buckets.
366
+ * Unlike selectBucketsForDatabases, this shows all buckets as a flat list
367
+ * with source indicators (Local only, Remote only, Configured).
368
+ */
369
+ static async selectBucketsForPush(mergedBuckets, configuredBuckets, options = {}) {
370
+ MessageFormatter.section("Storage Bucket Selection");
371
+ if (mergedBuckets.length === 0) {
372
+ MessageFormatter.warning("No storage buckets found (local or remote).", { skipLogging: true });
373
+ return [];
374
+ }
375
+ const choices = mergedBuckets.map(bucket => {
376
+ let status;
377
+ let suffix = '';
378
+ if (bucket._isLocalOnly) {
379
+ status = chalk.yellow('*');
380
+ suffix = chalk.yellow(' (Local only - will be created)');
381
+ }
382
+ else if (bucket._isRemoteOnly) {
383
+ status = chalk.blue('○');
384
+ suffix = chalk.blue(' (Remote only)');
385
+ }
386
+ else {
387
+ status = chalk.green('✅');
388
+ suffix = chalk.green(' (Configured)');
389
+ }
390
+ return {
391
+ name: `${status} ${bucket.name} (${bucket.$id})${suffix}`,
392
+ value: bucket.$id,
393
+ short: bucket.name,
394
+ };
395
+ });
396
+ const { selectedBucketIds } = await inquirer.prompt([{
397
+ type: 'checkbox',
398
+ name: 'selectedBucketIds',
399
+ message: 'Select storage buckets to push:',
400
+ choices,
401
+ }]);
402
+ return selectedBucketIds || [];
403
+ }
404
+ /**
405
+ * Shows final confirmation dialog with sync selection summary
406
+ */
407
+ static async confirmSyncSelection(selectionSummary, operationType = 'sync') {
408
+ const labels = {
409
+ push: {
410
+ banner: "Push Selection Summary",
411
+ subtitle: "Review selections before pushing to Appwrite",
412
+ confirm: "Proceed with push operation?",
413
+ success: "Push operation confirmed.",
414
+ cancel: "Push operation cancelled."
415
+ },
416
+ pull: {
417
+ banner: "Pull Selection Summary",
418
+ subtitle: "Review selections before pulling from Appwrite",
419
+ confirm: "Proceed with pull operation?",
420
+ success: "Pull operation confirmed.",
421
+ cancel: "Pull operation cancelled."
422
+ },
423
+ sync: {
424
+ banner: "Sync Selection Summary",
425
+ subtitle: "Review your selections before proceeding",
426
+ confirm: "Proceed with sync operation?",
427
+ success: "Sync operation confirmed.",
428
+ cancel: "Sync operation cancelled."
429
+ }
430
+ };
431
+ const label = labels[operationType];
432
+ MessageFormatter.banner(label.banner, label.subtitle);
433
+ // Database summary
434
+ console.log(chalk.bold.cyan("\n📊 Databases:"));
435
+ console.log(` Total: ${selectionSummary.totalDatabases}`);
436
+ console.log(` ${chalk.green('✅ Configured')}: ${selectionSummary.existingItems.databases}`);
437
+ console.log(` ${chalk.blue('○ New')}: ${selectionSummary.newItems.databases}`);
438
+ if (selectionSummary.databases.length > 0) {
439
+ console.log(chalk.gray("\n Selected databases:"));
440
+ selectionSummary.databases.forEach(db => {
441
+ const status = db.isNew ? chalk.blue('○') : chalk.green('✅');
442
+ console.log(` ${status} ${db.databaseName} (${db.tableNames.length} tables)`);
443
+ });
444
+ }
445
+ // Table summary
446
+ console.log(chalk.bold.cyan("\n📋 Tables:"));
447
+ console.log(` Total: ${selectionSummary.totalTables}`);
448
+ console.log(` ${chalk.green('✅ Configured')}: ${selectionSummary.existingItems.tables}`);
449
+ console.log(` ${chalk.blue('○ New')}: ${selectionSummary.newItems.tables}`);
450
+ // Bucket summary
451
+ console.log(chalk.bold.cyan("\n🪣 Storage Buckets:"));
452
+ console.log(` Total: ${selectionSummary.totalBuckets}`);
453
+ console.log(` ${chalk.green('✅ Configured')}: ${selectionSummary.existingItems.buckets}`);
454
+ console.log(` ${chalk.blue('○ New')}: ${selectionSummary.newItems.buckets}`);
455
+ if (selectionSummary.buckets.length > 0) {
456
+ console.log(chalk.gray("\n Selected buckets:"));
457
+ selectionSummary.buckets.forEach(bucket => {
458
+ const status = bucket.isNew ? chalk.blue('○') : chalk.green('✅');
459
+ const dbContext = bucket.databaseName ? ` [${bucket.databaseName}]` : '';
460
+ console.log(` ${status} ${bucket.bucketName}${dbContext}`);
461
+ });
462
+ }
463
+ console.log(); // Add spacing
464
+ const { confirmed } = await inquirer.prompt([{
465
+ type: 'confirm',
466
+ name: 'confirmed',
467
+ message: chalk.green.bold(label.confirm),
468
+ default: true
469
+ }]);
470
+ if (confirmed) {
471
+ MessageFormatter.success(label.success, { skipLogging: true });
472
+ logger.info(`${operationType} selection confirmed`, {
473
+ databases: selectionSummary.totalDatabases,
474
+ tables: selectionSummary.totalTables,
475
+ buckets: selectionSummary.totalBuckets
476
+ });
477
+ }
478
+ else {
479
+ MessageFormatter.warning(label.cancel, { skipLogging: true });
480
+ logger.info(`${operationType} selection cancelled by user`);
481
+ }
482
+ return confirmed;
483
+ }
484
+ /**
485
+ * Creates a sync selection summary from selected items
486
+ */
487
+ static createSyncSelectionSummary(databaseSelections, bucketSelections) {
488
+ const totalDatabases = databaseSelections.length;
489
+ const totalTables = databaseSelections.reduce((sum, db) => sum + db.tableIds.length, 0);
490
+ const totalBuckets = bucketSelections.length;
491
+ const newDatabases = databaseSelections.filter(db => db.isNew).length;
492
+ const newTables = databaseSelections.reduce((sum, db) => sum + db.tableIds.length, 0); // TODO: Track which tables are new
493
+ const newBuckets = bucketSelections.filter(bucket => bucket.isNew).length;
494
+ const existingDatabases = totalDatabases - newDatabases;
495
+ const existingTables = totalTables - newTables;
496
+ const existingBuckets = totalBuckets - newBuckets;
497
+ return {
498
+ databases: databaseSelections,
499
+ buckets: bucketSelections,
500
+ totalDatabases,
501
+ totalTables,
502
+ totalBuckets,
503
+ newItems: {
504
+ databases: newDatabases,
505
+ tables: newTables,
506
+ buckets: newBuckets
507
+ },
508
+ existingItems: {
509
+ databases: existingDatabases,
510
+ tables: existingTables,
511
+ buckets: existingBuckets
512
+ }
513
+ };
514
+ }
515
+ /**
516
+ * Helper method to create database selection objects
517
+ */
518
+ static createDatabaseSelection(selectedDatabaseIds, availableDatabases, tableSelectionsMap, configuredDatabases, availableTablesMap = new Map()) {
519
+ const configuredIds = new Set(configuredDatabases.map(db => db.$id || db.id));
520
+ return selectedDatabaseIds.map(databaseId => {
521
+ const database = availableDatabases.find(db => db.$id === databaseId);
522
+ if (!database) {
523
+ throw new Error(`Database with ID ${databaseId} not found in available databases`);
524
+ }
525
+ const tableIds = tableSelectionsMap.get(databaseId) || [];
526
+ const tables = availableTablesMap.get(databaseId) || [];
527
+ const tableNames = tables.map(table => table.name || table.$id || `Table-${table.$id}`);
528
+ return {
529
+ databaseId,
530
+ databaseName: database.name,
531
+ tableIds,
532
+ tableNames,
533
+ isNew: !configuredIds.has(databaseId)
534
+ };
535
+ });
536
+ }
537
+ /**
538
+ * Helper method to create bucket selection objects
539
+ */
540
+ static createBucketSelection(selectedBucketIds, availableBuckets, configuredBuckets, availableDatabases) {
541
+ const configuredIds = new Set(configuredBuckets.map(bucket => bucket.$id || bucket.id));
542
+ return selectedBucketIds.map(bucketId => {
543
+ // Look up in availableBuckets first, then fall back to configuredBuckets
544
+ // (handles merged lists where local-only buckets may only be in configuredBuckets)
545
+ const bucket = availableBuckets.find(b => b.$id === bucketId)
546
+ || configuredBuckets.find(b => (b.$id || b.id) === bucketId);
547
+ if (!bucket) {
548
+ throw new Error(`Bucket with ID ${bucketId} not found in available or configured buckets`);
549
+ }
550
+ const database = bucket.databaseId ?
551
+ availableDatabases.find(db => db.$id === bucket.databaseId) : undefined;
552
+ return {
553
+ bucketId,
554
+ bucketName: bucket.name,
555
+ databaseId: bucket.databaseId,
556
+ databaseName: database?.name,
557
+ isNew: bucket._isLocalOnly || !configuredIds.has(bucketId)
558
+ };
559
+ });
560
+ }
561
+ /**
562
+ * Shows a progress message during selection operations
563
+ */
564
+ static showProgress(message) {
565
+ MessageFormatter.progress(message, { skipLogging: true });
566
+ }
567
+ /**
568
+ * Shows an error message and handles graceful cancellation
569
+ */
570
+ static showError(message, error) {
571
+ MessageFormatter.error(message, error, { skipLogging: true });
572
+ logger.error(`Selection dialog error: ${message}`, { error: error?.message });
573
+ }
574
+ /**
575
+ * Shows a warning message
576
+ */
577
+ static showWarning(message) {
578
+ MessageFormatter.warning(message, { skipLogging: true });
579
+ logger.warn(`Selection dialog warning: ${message}`);
580
+ }
581
+ /**
582
+ * Shows a success message
583
+ */
584
+ static showSuccess(message) {
585
+ MessageFormatter.success(message, { skipLogging: true });
586
+ logger.info(`Selection dialog success: ${message}`);
587
+ }
588
+ }
@@ -0,0 +1,20 @@
1
+ import type { BackupCreate } from "./schemas.js";
2
+ export interface BackupCompressionOptions {
3
+ includeFiles?: boolean;
4
+ compressionLevel?: number;
5
+ }
6
+ /**
7
+ * Creates a compressed ZIP backup from backup data
8
+ *
9
+ * Structure:
10
+ * - metadata.json (backup metadata)
11
+ * - database.json (database config)
12
+ * - collections/*.json (one file per collection)
13
+ * - documents/*.json (one file per collection's documents)
14
+ * - files/ (optional, if includeFiles is true)
15
+ */
16
+ export declare function createBackupZip(backupData: BackupCreate, options?: BackupCompressionOptions): Promise<Buffer>;
17
+ /**
18
+ * Estimates compression ratio for backup data
19
+ */
20
+ export declare function estimateCompressedSize(uncompressedSize: number, format?: string): number;
@@ -0,0 +1,67 @@
1
+ import JSZip from "jszip";
2
+ /**
3
+ * Creates a compressed ZIP backup from backup data
4
+ *
5
+ * Structure:
6
+ * - metadata.json (backup metadata)
7
+ * - database.json (database config)
8
+ * - collections/*.json (one file per collection)
9
+ * - documents/*.json (one file per collection's documents)
10
+ * - files/ (optional, if includeFiles is true)
11
+ */
12
+ export async function createBackupZip(backupData, options = {}) {
13
+ const zip = new JSZip();
14
+ const compressionLevel = options.compressionLevel ?? 6;
15
+ // Add metadata.json
16
+ const metadata = {
17
+ version: "1.0",
18
+ createdAt: new Date().toISOString(),
19
+ databaseId: JSON.parse(backupData.database).$id,
20
+ format: "zip",
21
+ includesFiles: options.includeFiles ?? false
22
+ };
23
+ zip.file("metadata.json", JSON.stringify(metadata, null, 2));
24
+ // Add database.json
25
+ zip.file("database.json", backupData.database);
26
+ // Add collections/*.json
27
+ const collectionsFolder = zip.folder("collections");
28
+ if (collectionsFolder) {
29
+ backupData.collections.forEach((collectionStr, index) => {
30
+ const collection = JSON.parse(collectionStr);
31
+ collectionsFolder.file(`${collection.$id || `collection_${index}`}.json`, collectionStr);
32
+ });
33
+ }
34
+ // Add documents/*.json
35
+ const documentsFolder = zip.folder("documents");
36
+ if (documentsFolder) {
37
+ backupData.documents.forEach((docBatch) => {
38
+ const collectionId = docBatch.collectionId;
39
+ documentsFolder.file(`${collectionId}.json`, docBatch.data);
40
+ });
41
+ }
42
+ // TODO: Add files support in future task (C3.5)
43
+ if (options.includeFiles) {
44
+ // Placeholder for file backup support
45
+ const filesFolder = zip.folder("files");
46
+ if (filesFolder) {
47
+ filesFolder.file("file-manifest.json", JSON.stringify({
48
+ note: "File backup not yet implemented"
49
+ }, null, 2));
50
+ }
51
+ }
52
+ // Generate ZIP buffer
53
+ const buffer = await zip.generateAsync({
54
+ type: "nodebuffer",
55
+ compression: "DEFLATE",
56
+ compressionOptions: { level: compressionLevel }
57
+ });
58
+ return buffer;
59
+ }
60
+ /**
61
+ * Estimates compression ratio for backup data
62
+ */
63
+ export function estimateCompressedSize(uncompressedSize, format = "json") {
64
+ // JSON typically compresses to 20-30% of original size with gzip
65
+ const compressionRatio = format === "json" ? 0.25 : 0.5;
66
+ return Math.ceil(uncompressedSize * compressionRatio);
67
+ }