appwrite-utils-cli 0.10.86 → 1.0.1

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 (178) hide show
  1. package/.appwrite/.yaml_schemas/appwrite-config.schema.json +380 -0
  2. package/.appwrite/.yaml_schemas/collection.schema.json +255 -0
  3. package/.appwrite/collections/Categories.yaml +182 -0
  4. package/.appwrite/collections/ExampleCollection.yaml +36 -0
  5. package/.appwrite/collections/Posts.yaml +227 -0
  6. package/.appwrite/collections/Users.yaml +149 -0
  7. package/.appwrite/config.yaml +109 -0
  8. package/.appwrite/import/README.md +148 -0
  9. package/.appwrite/import/categories-import.yaml +129 -0
  10. package/.appwrite/import/posts-import.yaml +208 -0
  11. package/.appwrite/import/users-import.yaml +130 -0
  12. package/.appwrite/importData/categories.json +194 -0
  13. package/.appwrite/importData/posts.json +270 -0
  14. package/.appwrite/importData/users.json +220 -0
  15. package/.appwrite/schemas/categories.json +128 -0
  16. package/.appwrite/schemas/exampleCollection.json +52 -0
  17. package/.appwrite/schemas/posts.json +173 -0
  18. package/.appwrite/schemas/users.json +125 -0
  19. package/README.md +260 -33
  20. package/dist/collections/attributes.js +3 -2
  21. package/dist/collections/methods.js +56 -38
  22. package/dist/config/yamlConfig.d.ts +501 -0
  23. package/dist/config/yamlConfig.js +452 -0
  24. package/dist/databases/setup.d.ts +6 -0
  25. package/dist/databases/setup.js +119 -0
  26. package/dist/functions/methods.d.ts +1 -1
  27. package/dist/functions/methods.js +5 -2
  28. package/dist/functions/openapi.d.ts +4 -0
  29. package/dist/functions/openapi.js +60 -0
  30. package/dist/interactiveCLI.d.ts +5 -0
  31. package/dist/interactiveCLI.js +194 -49
  32. package/dist/main.js +91 -30
  33. package/dist/migrations/afterImportActions.js +2 -2
  34. package/dist/migrations/appwriteToX.d.ts +10 -0
  35. package/dist/migrations/appwriteToX.js +15 -4
  36. package/dist/migrations/backup.d.ts +16 -16
  37. package/dist/migrations/dataLoader.d.ts +83 -1
  38. package/dist/migrations/dataLoader.js +4 -4
  39. package/dist/migrations/importController.js +25 -18
  40. package/dist/migrations/importDataActions.js +2 -2
  41. package/dist/migrations/logging.d.ts +9 -1
  42. package/dist/migrations/logging.js +41 -22
  43. package/dist/migrations/migrationHelper.d.ts +4 -4
  44. package/dist/migrations/relationships.js +1 -1
  45. package/dist/migrations/services/DataTransformationService.d.ts +55 -0
  46. package/dist/migrations/services/DataTransformationService.js +158 -0
  47. package/dist/migrations/services/FileHandlerService.d.ts +75 -0
  48. package/dist/migrations/services/FileHandlerService.js +236 -0
  49. package/dist/migrations/services/ImportOrchestrator.d.ts +97 -0
  50. package/dist/migrations/services/ImportOrchestrator.js +488 -0
  51. package/dist/migrations/services/RateLimitManager.d.ts +138 -0
  52. package/dist/migrations/services/RateLimitManager.js +279 -0
  53. package/dist/migrations/services/RelationshipResolver.d.ts +120 -0
  54. package/dist/migrations/services/RelationshipResolver.js +332 -0
  55. package/dist/migrations/services/UserMappingService.d.ts +109 -0
  56. package/dist/migrations/services/UserMappingService.js +277 -0
  57. package/dist/migrations/services/ValidationService.d.ts +74 -0
  58. package/dist/migrations/services/ValidationService.js +260 -0
  59. package/dist/migrations/transfer.d.ts +0 -6
  60. package/dist/migrations/transfer.js +16 -132
  61. package/dist/migrations/yaml/YamlImportConfigLoader.d.ts +384 -0
  62. package/dist/migrations/yaml/YamlImportConfigLoader.js +375 -0
  63. package/dist/migrations/yaml/YamlImportIntegration.d.ts +87 -0
  64. package/dist/migrations/yaml/YamlImportIntegration.js +330 -0
  65. package/dist/migrations/yaml/generateImportSchemas.d.ts +17 -0
  66. package/dist/migrations/yaml/generateImportSchemas.js +575 -0
  67. package/dist/schemas/authUser.d.ts +9 -9
  68. package/dist/shared/attributeManager.d.ts +17 -0
  69. package/dist/shared/attributeManager.js +273 -0
  70. package/dist/shared/confirmationDialogs.d.ts +75 -0
  71. package/dist/shared/confirmationDialogs.js +236 -0
  72. package/dist/shared/functionManager.d.ts +48 -0
  73. package/dist/shared/functionManager.js +322 -0
  74. package/dist/shared/indexManager.d.ts +24 -0
  75. package/dist/shared/indexManager.js +150 -0
  76. package/dist/shared/jsonSchemaGenerator.d.ts +51 -0
  77. package/dist/shared/jsonSchemaGenerator.js +313 -0
  78. package/dist/shared/logging.d.ts +10 -0
  79. package/dist/shared/logging.js +46 -0
  80. package/dist/shared/messageFormatter.d.ts +37 -0
  81. package/dist/shared/messageFormatter.js +152 -0
  82. package/dist/shared/migrationHelpers.d.ts +173 -0
  83. package/dist/shared/migrationHelpers.js +142 -0
  84. package/dist/shared/operationLogger.d.ts +3 -0
  85. package/dist/shared/operationLogger.js +25 -0
  86. package/dist/shared/operationQueue.d.ts +13 -0
  87. package/dist/shared/operationQueue.js +79 -0
  88. package/dist/shared/progressManager.d.ts +62 -0
  89. package/dist/shared/progressManager.js +215 -0
  90. package/dist/shared/schemaGenerator.d.ts +18 -0
  91. package/dist/shared/schemaGenerator.js +523 -0
  92. package/dist/storage/methods.d.ts +3 -1
  93. package/dist/storage/methods.js +144 -55
  94. package/dist/storage/schemas.d.ts +56 -16
  95. package/dist/types.d.ts +2 -2
  96. package/dist/types.js +1 -1
  97. package/dist/users/methods.d.ts +16 -0
  98. package/dist/users/methods.js +276 -0
  99. package/dist/utils/configMigration.d.ts +1 -0
  100. package/dist/utils/configMigration.js +156 -0
  101. package/dist/utils/dataConverters.d.ts +46 -0
  102. package/dist/utils/dataConverters.js +139 -0
  103. package/dist/utils/loadConfigs.d.ts +15 -4
  104. package/dist/utils/loadConfigs.js +377 -51
  105. package/dist/utils/schemaStrings.js +2 -1
  106. package/dist/utils/setupFiles.d.ts +2 -1
  107. package/dist/utils/setupFiles.js +723 -28
  108. package/dist/utils/validationRules.d.ts +43 -0
  109. package/dist/utils/validationRules.js +42 -0
  110. package/dist/utils/yamlConverter.d.ts +48 -0
  111. package/dist/utils/yamlConverter.js +98 -0
  112. package/dist/utilsController.js +65 -43
  113. package/package.json +19 -15
  114. package/src/collections/attributes.ts +3 -2
  115. package/src/collections/methods.ts +85 -51
  116. package/src/config/yamlConfig.ts +488 -0
  117. package/src/{migrations/setupDatabase.ts → databases/setup.ts} +11 -5
  118. package/src/functions/methods.ts +8 -4
  119. package/src/functions/templates/count-docs-in-collection/package.json +25 -0
  120. package/src/functions/templates/count-docs-in-collection/tsconfig.json +28 -0
  121. package/src/functions/templates/typescript-node/package.json +24 -0
  122. package/src/functions/templates/typescript-node/tsconfig.json +28 -0
  123. package/src/functions/templates/uv/README.md +31 -0
  124. package/src/functions/templates/uv/pyproject.toml +29 -0
  125. package/src/interactiveCLI.ts +226 -61
  126. package/src/main.ts +111 -37
  127. package/src/migrations/afterImportActions.ts +2 -2
  128. package/src/migrations/appwriteToX.ts +17 -4
  129. package/src/migrations/dataLoader.ts +4 -4
  130. package/src/migrations/importController.ts +30 -22
  131. package/src/migrations/importDataActions.ts +2 -2
  132. package/src/migrations/relationships.ts +1 -1
  133. package/src/migrations/services/DataTransformationService.ts +196 -0
  134. package/src/migrations/services/FileHandlerService.ts +311 -0
  135. package/src/migrations/services/ImportOrchestrator.ts +669 -0
  136. package/src/migrations/services/RateLimitManager.ts +363 -0
  137. package/src/migrations/services/RelationshipResolver.ts +461 -0
  138. package/src/migrations/services/UserMappingService.ts +345 -0
  139. package/src/migrations/services/ValidationService.ts +349 -0
  140. package/src/migrations/transfer.ts +22 -228
  141. package/src/migrations/yaml/YamlImportConfigLoader.ts +427 -0
  142. package/src/migrations/yaml/YamlImportIntegration.ts +419 -0
  143. package/src/migrations/yaml/generateImportSchemas.ts +589 -0
  144. package/src/shared/attributeManager.ts +429 -0
  145. package/src/shared/confirmationDialogs.ts +327 -0
  146. package/src/shared/functionManager.ts +515 -0
  147. package/src/shared/indexManager.ts +253 -0
  148. package/src/shared/jsonSchemaGenerator.ts +403 -0
  149. package/src/shared/logging.ts +74 -0
  150. package/src/shared/messageFormatter.ts +195 -0
  151. package/src/{migrations/migrationHelper.ts → shared/migrationHelpers.ts} +22 -4
  152. package/src/{migrations/helper.ts → shared/operationLogger.ts} +7 -2
  153. package/src/{migrations/queue.ts → shared/operationQueue.ts} +1 -1
  154. package/src/shared/progressManager.ts +278 -0
  155. package/src/{migrations/schemaStrings.ts → shared/schemaGenerator.ts} +71 -17
  156. package/src/storage/methods.ts +199 -78
  157. package/src/types.ts +2 -2
  158. package/src/{migrations/users.ts → users/methods.ts} +2 -2
  159. package/src/utils/configMigration.ts +212 -0
  160. package/src/utils/loadConfigs.ts +414 -52
  161. package/src/utils/schemaStrings.ts +2 -1
  162. package/src/utils/setupFiles.ts +742 -40
  163. package/src/{migrations → utils}/validationRules.ts +1 -1
  164. package/src/utils/yamlConverter.ts +131 -0
  165. package/src/utilsController.ts +75 -54
  166. package/src/functions/templates/poetry/README.md +0 -30
  167. package/src/functions/templates/poetry/pyproject.toml +0 -16
  168. package/src/migrations/attributes.ts +0 -561
  169. package/src/migrations/backup.ts +0 -205
  170. package/src/migrations/databases.ts +0 -39
  171. package/src/migrations/dbHelpers.ts +0 -92
  172. package/src/migrations/indexes.ts +0 -40
  173. package/src/migrations/logging.ts +0 -29
  174. package/src/migrations/storage.ts +0 -538
  175. /package/src/{migrations → functions}/openapi.ts +0 -0
  176. /package/src/functions/templates/{poetry → uv}/src/__init__.py +0 -0
  177. /package/src/functions/templates/{poetry → uv}/src/index.py +0 -0
  178. /package/src/{migrations/converters.ts → utils/dataConverters.ts} +0 -0
@@ -0,0 +1,327 @@
1
+ import inquirer from "inquirer";
2
+ import chalk from "chalk";
3
+ import { MessageFormatter } from "./messageFormatter.js";
4
+
5
+ export interface DestructiveOperationOptions {
6
+ operation: string;
7
+ targets: string[];
8
+ consequences?: string[];
9
+ requireExplicitConfirmation?: boolean;
10
+ confirmationText?: string;
11
+ skipConfirmation?: boolean;
12
+ }
13
+
14
+ export interface BackupPromptOptions {
15
+ operation: string;
16
+ targets: string[];
17
+ recommendBackup?: boolean;
18
+ backupMessage?: string;
19
+ }
20
+
21
+ export class ConfirmationDialogs {
22
+ /**
23
+ * Shows a confirmation dialog for destructive operations
24
+ */
25
+ static async confirmDestructiveOperation(options: DestructiveOperationOptions): Promise<boolean> {
26
+ if (options.skipConfirmation) {
27
+ return true;
28
+ }
29
+
30
+ MessageFormatter.warning(`You are about to perform a destructive operation:`);
31
+ console.log(chalk.red.bold(` Operation: ${options.operation}`));
32
+ console.log(chalk.yellow(` Targets: ${options.targets.join(", ")}`));
33
+
34
+ if (options.consequences && options.consequences.length > 0) {
35
+ console.log(chalk.red("\n This will:"));
36
+ options.consequences.forEach(consequence => {
37
+ console.log(chalk.red(` • ${consequence}`));
38
+ });
39
+ }
40
+
41
+ console.log(chalk.red("\n ⚠️ THIS ACTION CANNOT BE UNDONE!"));
42
+
43
+ if (options.requireExplicitConfirmation && options.confirmationText) {
44
+ const { confirmation } = await inquirer.prompt([{
45
+ type: 'input',
46
+ name: 'confirmation',
47
+ message: chalk.red(`Type "${options.confirmationText}" to confirm:`),
48
+ validate: (input: string) => {
49
+ return input === options.confirmationText ||
50
+ chalk.red(`Please type exactly: ${options.confirmationText}`);
51
+ }
52
+ }]);
53
+
54
+ return confirmation === options.confirmationText;
55
+ } else {
56
+ const { confirmed } = await inquirer.prompt([{
57
+ type: 'confirm',
58
+ name: 'confirmed',
59
+ message: chalk.red('Are you absolutely sure you want to continue?'),
60
+ default: false
61
+ }]);
62
+
63
+ return confirmed;
64
+ }
65
+ }
66
+
67
+ /**
68
+ * Prompts user about creating a backup before a destructive operation
69
+ */
70
+ static async promptForBackup(options: BackupPromptOptions): Promise<'yes' | 'no' | 'skip'> {
71
+ const message = options.backupMessage ||
72
+ `Create a backup before performing ${options.operation} on: ${options.targets.join(", ")}?`;
73
+
74
+ console.log(chalk.blue("\n🛡️ Backup Recommendation"));
75
+ if (options.recommendBackup !== false) {
76
+ console.log(chalk.yellow(" It's strongly recommended to create a backup before proceeding."));
77
+ }
78
+
79
+ const { choice } = await inquirer.prompt([{
80
+ type: 'list',
81
+ name: 'choice',
82
+ message,
83
+ choices: [
84
+ { name: '🛡️ Yes, create backup first', value: 'yes' },
85
+ { name: '⚠️ No, proceed without backup', value: 'no' },
86
+ { name: '❌ Cancel operation', value: 'skip' }
87
+ ],
88
+ default: 'yes'
89
+ }]);
90
+
91
+ return choice;
92
+ }
93
+
94
+ /**
95
+ * Shows a final confirmation before proceeding with an operation
96
+ */
97
+ static async finalConfirmation(operation: string, details?: string[]): Promise<boolean> {
98
+ console.log(chalk.green(`\n✅ Ready to perform: ${chalk.bold(operation)}`));
99
+
100
+ if (details && details.length > 0) {
101
+ console.log(chalk.gray(" Details:"));
102
+ details.forEach(detail => {
103
+ console.log(chalk.gray(` • ${detail}`));
104
+ });
105
+ }
106
+
107
+ const { proceed } = await inquirer.prompt([{
108
+ type: 'confirm',
109
+ name: 'proceed',
110
+ message: 'Proceed with this operation?',
111
+ default: true
112
+ }]);
113
+
114
+ return proceed;
115
+ }
116
+
117
+ /**
118
+ * Specialized confirmation for database wiping
119
+ */
120
+ static async confirmDatabaseWipe(databaseNames: string[], options: {
121
+ includeStorage?: boolean;
122
+ includeUsers?: boolean;
123
+ skipConfirmation?: boolean;
124
+ } = {}): Promise<boolean> {
125
+ const consequences = [
126
+ "Delete all documents in the specified databases",
127
+ "Remove all collections and their data",
128
+ ];
129
+
130
+ if (options.includeStorage) {
131
+ consequences.push("Delete all files in associated storage buckets");
132
+ }
133
+
134
+ if (options.includeUsers) {
135
+ consequences.push("Delete all user accounts");
136
+ }
137
+
138
+ return this.confirmDestructiveOperation({
139
+ operation: "Database Wipe",
140
+ targets: databaseNames,
141
+ consequences,
142
+ requireExplicitConfirmation: true,
143
+ confirmationText: "DELETE ALL DATA",
144
+ skipConfirmation: options.skipConfirmation,
145
+ });
146
+ }
147
+
148
+ /**
149
+ * Specialized confirmation for collection wiping
150
+ */
151
+ static async confirmCollectionWipe(
152
+ databaseName: string,
153
+ collectionNames: string[],
154
+ options: { skipConfirmation?: boolean } = {}
155
+ ): Promise<boolean> {
156
+ return this.confirmDestructiveOperation({
157
+ operation: "Collection Wipe",
158
+ targets: collectionNames.map(name => `${databaseName}.${name}`),
159
+ consequences: [
160
+ "Delete all documents in the specified collections",
161
+ "Keep the collection structure intact",
162
+ ],
163
+ requireExplicitConfirmation: collectionNames.length > 5,
164
+ confirmationText: "DELETE DOCUMENTS",
165
+ skipConfirmation: options.skipConfirmation,
166
+ });
167
+ }
168
+
169
+ /**
170
+ * Specialized confirmation for function deployment
171
+ */
172
+ static async confirmFunctionDeployment(
173
+ functionNames: string[],
174
+ options: {
175
+ isProduction?: boolean;
176
+ hasBreakingChanges?: boolean;
177
+ skipConfirmation?: boolean;
178
+ } = {}
179
+ ): Promise<boolean> {
180
+ if (options.skipConfirmation) {
181
+ return true;
182
+ }
183
+
184
+ const consequences = ["Replace existing function code"];
185
+
186
+ if (options.isProduction) {
187
+ consequences.push("Affect production environment");
188
+ }
189
+
190
+ if (options.hasBreakingChanges) {
191
+ consequences.push("Potentially break existing integrations");
192
+ }
193
+
194
+ return this.confirmDestructiveOperation({
195
+ operation: "Function Deployment",
196
+ targets: functionNames,
197
+ consequences: consequences.length > 1 ? consequences : undefined,
198
+ requireExplicitConfirmation: options.isProduction || options.hasBreakingChanges,
199
+ confirmationText: options.isProduction ? "DEPLOY TO PRODUCTION" : "DEPLOY",
200
+ });
201
+ }
202
+
203
+ /**
204
+ * Shows operation summary and asks for final confirmation
205
+ */
206
+ static async showOperationSummary(
207
+ title: string,
208
+ summary: Record<string, string | number | string[]>,
209
+ options: {
210
+ confirmationRequired?: boolean;
211
+ warningMessage?: string;
212
+ } = {}
213
+ ): Promise<boolean> {
214
+ MessageFormatter.section(`${title} Summary`);
215
+
216
+ Object.entries(summary).forEach(([key, value]) => {
217
+ const formattedKey = key.replace(/([A-Z])/g, ' $1').replace(/^./, str => str.toUpperCase());
218
+
219
+ if (Array.isArray(value)) {
220
+ console.log(`${chalk.gray("●")} ${formattedKey}:`);
221
+ value.forEach(item => {
222
+ console.log(` ${chalk.gray("•")} ${item}`);
223
+ });
224
+ } else {
225
+ console.log(`${chalk.gray("●")} ${formattedKey}: ${chalk.cyan(String(value))}`);
226
+ }
227
+ });
228
+
229
+ if (options.warningMessage) {
230
+ console.log(chalk.yellow(`\n⚠️ ${options.warningMessage}`));
231
+ }
232
+
233
+ if (options.confirmationRequired !== false) {
234
+ const { confirmed } = await inquirer.prompt([{
235
+ type: 'confirm',
236
+ name: 'confirmed',
237
+ message: 'Continue with this operation?',
238
+ default: true
239
+ }]);
240
+
241
+ return confirmed;
242
+ }
243
+
244
+ return true;
245
+ }
246
+
247
+ /**
248
+ * Interactive selection with confirmation
249
+ */
250
+ static async selectWithConfirmation<T>(
251
+ items: T[],
252
+ options: {
253
+ message: string;
254
+ displayProperty?: keyof T;
255
+ multiSelect?: boolean;
256
+ confirmMessage?: string;
257
+ validator?: (selection: T[]) => string | true;
258
+ }
259
+ ): Promise<T[]> {
260
+ const choices = items.map((item, index) => ({
261
+ name: options.displayProperty ? String(item[options.displayProperty]) : String(item),
262
+ value: item,
263
+ }));
264
+
265
+ const prompt = options.multiSelect ? 'checkbox' : 'list';
266
+ const { selection } = await inquirer.prompt([{
267
+ type: prompt,
268
+ name: 'selection',
269
+ message: options.message,
270
+ choices,
271
+ validate: options.validator ? (input: T[]) => {
272
+ const result = options.validator!(Array.isArray(input) ? input : [input]);
273
+ return result;
274
+ } : undefined,
275
+ }]);
276
+
277
+ const selectedItems = Array.isArray(selection) ? selection : [selection];
278
+
279
+ if (options.confirmMessage) {
280
+ const confirmMessage = options.confirmMessage.replace(
281
+ '{count}',
282
+ selectedItems.length.toString()
283
+ );
284
+
285
+ const { confirmed } = await inquirer.prompt([{
286
+ type: 'confirm',
287
+ name: 'confirmed',
288
+ message: confirmMessage,
289
+ default: true
290
+ }]);
291
+
292
+ if (!confirmed) {
293
+ return [];
294
+ }
295
+ }
296
+
297
+ return selectedItems;
298
+ }
299
+
300
+ /**
301
+ * Confirms overwriting an existing file or directory
302
+ */
303
+ static async confirmOverwrite(target: string): Promise<boolean> {
304
+ const { confirmed } = await inquirer.prompt([{
305
+ type: 'confirm',
306
+ name: 'confirmed',
307
+ message: chalk.yellow(`${target} already exists. Overwrite?`),
308
+ default: false
309
+ }]);
310
+
311
+ return confirmed;
312
+ }
313
+
314
+ /**
315
+ * Confirms removal of a file
316
+ */
317
+ static async confirmRemoval(target: string): Promise<boolean> {
318
+ const { confirmed } = await inquirer.prompt([{
319
+ type: 'confirm',
320
+ name: 'confirmed',
321
+ message: chalk.red(target),
322
+ default: false
323
+ }]);
324
+
325
+ return confirmed;
326
+ }
327
+ }