appwrite-utils-cli 0.10.85 → 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 +261 -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 +196 -52
  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 +230 -63
  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
@@ -1,11 +1,13 @@
1
1
  export declare class InteractiveCLI {
2
2
  private currentDir;
3
3
  private controller;
4
+ private isUsingTypeScriptConfig;
4
5
  constructor(currentDir: string);
5
6
  run(): Promise<void>;
6
7
  private initControllerIfNeeded;
7
8
  private selectDatabases;
8
9
  private selectCollections;
10
+ private getTemplateDefaults;
9
11
  private createFunction;
10
12
  private findFunctionInSubdirectories;
11
13
  private deployFunction;
@@ -28,4 +30,7 @@ export declare class InteractiveCLI {
28
30
  private getLocalDatabases;
29
31
  private reloadConfig;
30
32
  private updateFunctionSpec;
33
+ private detectConfigurationType;
34
+ private buildChoicesList;
35
+ private migrateTypeScriptConfig;
31
36
  }
@@ -14,9 +14,15 @@ import { createFunctionTemplate, deleteFunction, downloadLatestFunctionDeploymen
14
14
  import { deployLocalFunction } from "./functions/deployments.js";
15
15
  import { join } from "node:path";
16
16
  import fs from "node:fs";
17
- import { SchemaGenerator } from "./migrations/schemaStrings.js";
17
+ import { SchemaGenerator } from "./shared/schemaGenerator.js";
18
+ import { ConfirmationDialogs } from "./shared/confirmationDialogs.js";
19
+ import { MessageFormatter } from "./shared/messageFormatter.js";
20
+ import { migrateConfig } from "./utils/configMigration.js";
21
+ import { findAppwriteConfig } from "./utils/loadConfigs.js";
22
+ import { findYamlConfig, addFunctionToYamlConfig } from "./config/yamlConfig.js";
18
23
  var CHOICES;
19
24
  (function (CHOICES) {
25
+ CHOICES["MIGRATE_CONFIG"] = "\uD83D\uDD04 Migrate TypeScript config to YAML (.appwrite structure)";
20
26
  CHOICES["CREATE_COLLECTION_CONFIG"] = "Create collection config file";
21
27
  CHOICES["CREATE_FUNCTION"] = "Create a new function, from scratch or using a template";
22
28
  CHOICES["DEPLOY_FUNCTION"] = "Deploy function(s)";
@@ -38,24 +44,37 @@ var CHOICES;
38
44
  export class InteractiveCLI {
39
45
  currentDir;
40
46
  controller;
47
+ isUsingTypeScriptConfig = false;
41
48
  constructor(currentDir) {
42
49
  this.currentDir = currentDir;
43
50
  }
44
51
  async run() {
45
- console.log(chalk.green("Welcome to Appwrite Utils CLI Tool by Zach Handley"));
46
- console.log(chalk.blue("For more information, visit https://github.com/zachhandley/AppwriteUtils"));
52
+ MessageFormatter.banner("Appwrite Utils CLI", "Welcome to Appwrite Utils CLI Tool by Zach Handley");
53
+ MessageFormatter.info("For more information, visit https://github.com/zachhandley/AppwriteUtils");
54
+ // Detect configuration type
55
+ try {
56
+ await this.detectConfigurationType();
57
+ }
58
+ catch (error) {
59
+ // Continue if detection fails
60
+ this.isUsingTypeScriptConfig = false;
61
+ }
47
62
  while (true) {
63
+ // Build choices array dynamically based on config type
64
+ const choices = this.buildChoicesList();
48
65
  const { action } = await inquirer.prompt([
49
66
  {
50
67
  type: "list",
51
68
  name: "action",
52
69
  message: chalk.yellow("What would you like to do?"),
53
- choices: Object.values(CHOICES),
70
+ choices,
54
71
  },
55
72
  ]);
56
73
  switch (action) {
74
+ case CHOICES.MIGRATE_CONFIG:
75
+ await this.migrateTypeScriptConfig();
76
+ break;
57
77
  case CHOICES.CREATE_COLLECTION_CONFIG:
58
- await this.initControllerIfNeeded();
59
78
  await this.createCollectionConfig();
60
79
  break;
61
80
  case CHOICES.CREATE_FUNCTION:
@@ -117,7 +136,7 @@ export class InteractiveCLI {
117
136
  await this.updateFunctionSpec();
118
137
  break;
119
138
  case CHOICES.EXIT:
120
- console.log(chalk.green("Goodbye!"));
139
+ MessageFormatter.success("Goodbye!");
121
140
  process.exit(0);
122
141
  }
123
142
  }
@@ -145,7 +164,10 @@ export class InteractiveCLI {
145
164
  }
146
165
  return acc;
147
166
  }, [])
148
- .filter((db) => db.name.toLowerCase() !== "migrations");
167
+ .filter((db) => {
168
+ const useMigrations = this.controller?.config?.useMigrations ?? true;
169
+ return useMigrations || db.name.toLowerCase() !== "migrations";
170
+ });
149
171
  const hasLocalAndRemote = allDatabases.some((db) => configDatabases.some((c) => c.name === db.name)) &&
150
172
  allDatabases.some((db) => !configDatabases.some((c) => c.name === db.name));
151
173
  const choices = allDatabases
@@ -159,7 +181,10 @@ export class InteractiveCLI {
159
181
  : ""),
160
182
  value: db,
161
183
  }))
162
- .filter((db) => db.name.toLowerCase() !== "migrations");
184
+ .filter((db) => {
185
+ const useMigrations = this.controller?.config?.useMigrations ?? true;
186
+ return useMigrations || db.name.toLowerCase() !== "migrations";
187
+ });
163
188
  const { selectedDatabases } = await inquirer.prompt([
164
189
  {
165
190
  type: multiSelect ? "checkbox" : "list",
@@ -172,11 +197,10 @@ export class InteractiveCLI {
172
197
  ]);
173
198
  return selectedDatabases;
174
199
  }
175
- async selectCollections(database, databasesClient, message, multiSelect = true, preferLocal = false) {
200
+ async selectCollections(database, databasesClient, message, multiSelect = true, preferLocal = false, shouldFilterByDatabase = false) {
176
201
  await this.initControllerIfNeeded();
177
202
  const configCollections = this.getLocalCollections();
178
203
  let remoteCollections = [];
179
- let shouldFilterByDatabase = true;
180
204
  const dbExists = await databasesClient.list([
181
205
  Query.equal("name", database.name),
182
206
  ]);
@@ -226,6 +250,34 @@ export class InteractiveCLI {
226
250
  ]);
227
251
  return selectedCollections;
228
252
  }
253
+ getTemplateDefaults(template) {
254
+ const defaults = {
255
+ "typescript-node": {
256
+ runtime: "node-21.0",
257
+ entrypoint: "src/index.ts",
258
+ commands: "npm install && npm run build",
259
+ specification: "s-0.5vcpu-512mb",
260
+ },
261
+ "uv": {
262
+ runtime: "python-3.12",
263
+ entrypoint: "src/index.py",
264
+ commands: "uv sync && uv build",
265
+ specification: "s-0.5vcpu-512mb",
266
+ },
267
+ "count-docs-in-collection": {
268
+ runtime: "node-21.0",
269
+ entrypoint: "src/main.ts",
270
+ commands: "npm install && npm run build",
271
+ specification: "s-1vcpu-512mb",
272
+ },
273
+ };
274
+ return defaults[template] || {
275
+ runtime: "node-21.0",
276
+ entrypoint: "",
277
+ commands: "",
278
+ specification: "s-0.5vcpu-512mb",
279
+ };
280
+ }
229
281
  async createFunction() {
230
282
  const { name } = await inquirer.prompt([
231
283
  {
@@ -241,19 +293,22 @@ export class InteractiveCLI {
241
293
  name: "template",
242
294
  message: "Select a template:",
243
295
  choices: [
244
- "typescript-node",
245
- "poetry",
246
- "count-docs-in-collection",
247
- "none",
296
+ { name: "TypeScript Node.js", value: "typescript-node" },
297
+ { name: "Python with UV", value: "uv" },
298
+ { name: "Count Documents in Collection", value: "count-docs-in-collection" },
299
+ { name: "None (Empty Function)", value: "none" },
248
300
  ],
249
301
  },
250
302
  ]);
303
+ // Get template defaults
304
+ const templateDefaults = this.getTemplateDefaults(template);
251
305
  const { runtime } = await inquirer.prompt([
252
306
  {
253
307
  type: "list",
254
308
  name: "runtime",
255
309
  message: "Select runtime:",
256
310
  choices: Object.values(RuntimeSchema.Values),
311
+ default: templateDefaults.runtime,
257
312
  },
258
313
  ]);
259
314
  const specifications = await listSpecifications(this.controller.appwriteServer);
@@ -269,6 +324,7 @@ export class InteractiveCLI {
269
324
  value: s.slug,
270
325
  })),
271
326
  ],
327
+ default: templateDefaults.specification,
272
328
  },
273
329
  ]);
274
330
  const functionConfig = {
@@ -279,22 +335,40 @@ export class InteractiveCLI {
279
335
  execute: ["any"],
280
336
  enabled: true,
281
337
  logging: true,
282
- entrypoint: template === "none" ? "src/index.ts" : undefined,
283
- specification,
284
- predeployCommands: template.includes("typescript")
285
- ? ["npm install", "npm run build"]
286
- : undefined,
287
- deployDir: template.includes("typescript") ? "dist" : undefined,
338
+ entrypoint: templateDefaults.entrypoint,
339
+ commands: templateDefaults.commands,
340
+ specification: specification || templateDefaults.specification,
341
+ scopes: [],
342
+ timeout: 15,
343
+ schedule: "",
344
+ installationId: "",
345
+ providerRepositoryId: "",
346
+ providerBranch: "",
347
+ providerSilentMode: false,
348
+ providerRootDirectory: "",
349
+ templateRepository: "",
350
+ templateOwner: "",
351
+ templateRootDirectory: "",
288
352
  };
289
353
  if (template !== "none") {
290
354
  await createFunctionTemplate(template, name, "./functions");
291
355
  }
292
- // Add to config
356
+ // Add to in-memory config
293
357
  if (!this.controller.config.functions) {
294
358
  this.controller.config.functions = [];
295
359
  }
296
360
  this.controller.config.functions.push(functionConfig);
297
- console.log(chalk.green("✨ Function created successfully!"));
361
+ // If using YAML config, also add to YAML file
362
+ const yamlConfigPath = findYamlConfig(this.currentDir);
363
+ if (yamlConfigPath) {
364
+ try {
365
+ await addFunctionToYamlConfig(yamlConfigPath, functionConfig);
366
+ }
367
+ catch (error) {
368
+ MessageFormatter.warning(`Function created but failed to update YAML config: ${error instanceof Error ? error.message : error}`, { prefix: "Functions" });
369
+ }
370
+ }
371
+ MessageFormatter.success("Function created successfully!", { prefix: "Functions" });
298
372
  }
299
373
  async findFunctionInSubdirectories(basePaths, functionName) {
300
374
  // Common locations to check first
@@ -456,7 +530,7 @@ export class InteractiveCLI {
456
530
  ...functionConfig,
457
531
  dirPath: functionPath,
458
532
  });
459
- console.log(chalk.green("Function deployed successfully!"));
533
+ MessageFormatter.success("Function deployed successfully!", { prefix: "Functions" });
460
534
  }
461
535
  catch (error) {
462
536
  console.error(chalk.red("Failed to deploy function:"), error);
@@ -996,7 +1070,7 @@ export class InteractiveCLI {
996
1070
  console.log(chalk.yellow(`Backing up database: ${db.name}`));
997
1071
  await this.controller.backupDatabase(db);
998
1072
  }
999
- console.log(chalk.green("Database backup completed."));
1073
+ MessageFormatter.success("Database backup completed", { prefix: "Backup" });
1000
1074
  }
1001
1075
  async wipeDatabase() {
1002
1076
  if (!this.controller.database || !this.controller.storage) {
@@ -1021,16 +1095,13 @@ export class InteractiveCLI {
1021
1095
  default: false,
1022
1096
  },
1023
1097
  ]);
1024
- const { confirm } = await inquirer.prompt([
1025
- {
1026
- type: "confirm",
1027
- name: "confirm",
1028
- message: chalk.red("Are you sure you want to wipe the selected items? This action cannot be undone."),
1029
- default: false,
1030
- },
1031
- ]);
1032
- if (confirm) {
1033
- console.log(chalk.yellow("Wiping selected items..."));
1098
+ const databaseNames = selectedDatabases.map(db => db.name);
1099
+ const confirmed = await ConfirmationDialogs.confirmDatabaseWipe(databaseNames, {
1100
+ includeStorage: selectedStorage.length > 0,
1101
+ includeUsers: wipeUsers
1102
+ });
1103
+ if (confirmed) {
1104
+ MessageFormatter.info("Starting wipe operation...", { prefix: "Wipe" });
1034
1105
  for (const db of selectedDatabases) {
1035
1106
  await this.controller.wipeDatabase(db);
1036
1107
  }
@@ -1040,10 +1111,10 @@ export class InteractiveCLI {
1040
1111
  if (wipeUsers) {
1041
1112
  await this.controller.wipeUsers();
1042
1113
  }
1043
- console.log(chalk.green("Wipe operation completed."));
1114
+ MessageFormatter.success("Wipe operation completed", { prefix: "Wipe" });
1044
1115
  }
1045
1116
  else {
1046
- console.log(chalk.blue("Wipe operation cancelled."));
1117
+ MessageFormatter.info("Wipe operation cancelled", { prefix: "Wipe" });
1047
1118
  }
1048
1119
  }
1049
1120
  async wipeCollections() {
@@ -1053,32 +1124,48 @@ export class InteractiveCLI {
1053
1124
  const databases = await fetchAllDatabases(this.controller.database);
1054
1125
  const selectedDatabases = await this.selectDatabases(databases, "Select the database(s) containing the collections to wipe:", true);
1055
1126
  for (const database of selectedDatabases) {
1056
- const collections = await this.selectCollections(database, this.controller.database, `Select collections to wipe from ${database.name}:`, true);
1057
- const { confirm } = await inquirer.prompt([
1058
- {
1059
- type: "confirm",
1060
- name: "confirm",
1061
- message: chalk.red(`Are you sure you want to wipe the selected collections from ${database.name}? This action cannot be undone.`),
1062
- default: false,
1063
- },
1064
- ]);
1065
- if (confirm) {
1066
- console.log(chalk.yellow(`Wiping selected collections from ${database.name}...`));
1127
+ const collections = await this.selectCollections(database, this.controller.database, `Select collections to wipe from ${database.name}:`, true, undefined, true);
1128
+ const collectionNames = collections.map(c => c.name);
1129
+ const confirmed = await ConfirmationDialogs.confirmCollectionWipe(database.name, collectionNames);
1130
+ if (confirmed) {
1131
+ MessageFormatter.info(`Wiping selected collections from ${database.name}...`, { prefix: "Wipe" });
1067
1132
  for (const collection of collections) {
1068
1133
  await this.controller.wipeCollection(database, collection);
1069
- console.log(chalk.green(`Collection ${collection.name} wiped successfully.`));
1134
+ MessageFormatter.success(`Collection ${collection.name} wiped successfully`, { prefix: "Wipe" });
1070
1135
  }
1071
1136
  }
1072
1137
  else {
1073
- console.log(chalk.blue(`Wipe operation cancelled for ${database.name}.`));
1138
+ MessageFormatter.info(`Wipe operation cancelled for ${database.name}`, { prefix: "Wipe" });
1074
1139
  }
1075
1140
  }
1076
- console.log(chalk.green("Wipe collections operation completed."));
1141
+ MessageFormatter.success("Wipe collections operation completed", { prefix: "Wipe" });
1077
1142
  }
1078
1143
  async generateSchemas() {
1079
1144
  console.log(chalk.yellow("Generating schemas..."));
1080
- await this.controller.generateSchemas();
1081
- console.log(chalk.green("Schema generation completed."));
1145
+ // Prompt user for schema type preference
1146
+ const { schemaType } = await inquirer.prompt([
1147
+ {
1148
+ type: "list",
1149
+ name: "schemaType",
1150
+ message: "What type of schemas would you like to generate?",
1151
+ choices: [
1152
+ { name: "TypeScript (Zod) schemas", value: "zod" },
1153
+ { name: "JSON schemas", value: "json" },
1154
+ { name: "Both TypeScript and JSON schemas", value: "both" },
1155
+ ],
1156
+ default: "both",
1157
+ },
1158
+ ]);
1159
+ // Get the config folder path (where the config file is located)
1160
+ const configFolderPath = this.controller.getAppwriteFolderPath();
1161
+ if (!configFolderPath) {
1162
+ MessageFormatter.error("Failed to get config folder path", undefined, { prefix: "Schemas" });
1163
+ return;
1164
+ }
1165
+ // Create SchemaGenerator with the correct base path and generate schemas
1166
+ const schemaGenerator = new SchemaGenerator(this.controller.config, configFolderPath);
1167
+ schemaGenerator.generateSchemas({ format: schemaType, verbose: true });
1168
+ MessageFormatter.success("Schema generation completed", { prefix: "Schemas" });
1082
1169
  }
1083
1170
  async importData() {
1084
1171
  console.log(chalk.yellow("Importing data..."));
@@ -1295,4 +1382,61 @@ export class InteractiveCLI {
1295
1382
  console.error(chalk.red("Error updating function specification:"), error);
1296
1383
  }
1297
1384
  }
1385
+ async detectConfigurationType() {
1386
+ try {
1387
+ // Check for YAML config first
1388
+ const yamlConfigPath = findYamlConfig(this.currentDir);
1389
+ if (yamlConfigPath) {
1390
+ this.isUsingTypeScriptConfig = false;
1391
+ MessageFormatter.info("Using YAML configuration", { prefix: "Config" });
1392
+ return;
1393
+ }
1394
+ // Then check for TypeScript config
1395
+ const configPath = findAppwriteConfig(this.currentDir);
1396
+ if (configPath && configPath.endsWith('.ts')) {
1397
+ this.isUsingTypeScriptConfig = true;
1398
+ MessageFormatter.info("TypeScript configuration detected", { prefix: "Config" });
1399
+ MessageFormatter.info("Consider migrating to YAML for better organization", { prefix: "Config" });
1400
+ return;
1401
+ }
1402
+ // No config found
1403
+ this.isUsingTypeScriptConfig = false;
1404
+ MessageFormatter.info("No configuration file found", { prefix: "Config" });
1405
+ }
1406
+ catch (error) {
1407
+ // Silently handle detection errors and continue
1408
+ this.isUsingTypeScriptConfig = false;
1409
+ }
1410
+ }
1411
+ buildChoicesList() {
1412
+ const allChoices = Object.values(CHOICES);
1413
+ if (this.isUsingTypeScriptConfig) {
1414
+ // Place migration option at the top when TS config is detected
1415
+ return [
1416
+ CHOICES.MIGRATE_CONFIG,
1417
+ ...allChoices.filter(choice => choice !== CHOICES.MIGRATE_CONFIG)
1418
+ ];
1419
+ }
1420
+ else {
1421
+ // Hide migration option when using YAML config
1422
+ return allChoices.filter(choice => choice !== CHOICES.MIGRATE_CONFIG);
1423
+ }
1424
+ }
1425
+ async migrateTypeScriptConfig() {
1426
+ try {
1427
+ MessageFormatter.info("Starting TypeScript to YAML configuration migration...", { prefix: "Migration" });
1428
+ // Perform the migration
1429
+ await migrateConfig(this.currentDir);
1430
+ // Reset the detection flag
1431
+ this.isUsingTypeScriptConfig = false;
1432
+ // Reset the controller to pick up the new config
1433
+ this.controller = undefined;
1434
+ MessageFormatter.success("Migration completed successfully!", { prefix: "Migration" });
1435
+ MessageFormatter.info("Your configuration has been migrated to the .appwrite directory structure", { prefix: "Migration" });
1436
+ MessageFormatter.info("You can now use YAML configuration for easier management", { prefix: "Migration" });
1437
+ }
1438
+ catch (error) {
1439
+ MessageFormatter.error("Migration failed", error instanceof Error ? error : new Error(String(error)), { prefix: "Migration" });
1440
+ }
1441
+ }
1298
1442
  }