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,169 @@
1
+ import inquirer from "inquirer";
2
+ import path from "path";
3
+ import chalk from "chalk";
4
+ import { MessageFormatter } from 'appwrite-utils-helpers';
5
+ import { SchemaGenerator } from 'appwrite-utils-helpers';
6
+ import { setupDirsFiles } from "../../utils/setupFiles.js";
7
+ import { fetchAllDatabases } from "../../databases/methods.js";
8
+ export const schemaCommands = {
9
+ async generateSchemas(cli) {
10
+ MessageFormatter.progress("Generating schemas...", { prefix: "Schemas" });
11
+ // Prompt user for schema type preference
12
+ const { schemaType } = await inquirer.prompt([
13
+ {
14
+ type: "list",
15
+ name: "schemaType",
16
+ message: "What type of schemas would you like to generate?",
17
+ choices: [
18
+ { name: "TypeScript (Zod) schemas", value: "zod" },
19
+ { name: "JSON schemas", value: "json" },
20
+ { name: "Python (Pydantic) models", value: "pydantic" },
21
+ { name: "TypeScript + JSON", value: "both" },
22
+ { name: "All (Zod, JSON, Pydantic)", value: "all" },
23
+ ],
24
+ default: "all",
25
+ },
26
+ ]);
27
+ // Get the config folder path (where the config file is located)
28
+ const configFolderPath = cli.controller.getAppwriteFolderPath();
29
+ if (!configFolderPath) {
30
+ MessageFormatter.error("Failed to get config folder path", undefined, { prefix: "Schemas" });
31
+ return;
32
+ }
33
+ // Prompt for schema output directory (optional override)
34
+ const defaultSchemaOut = path.join(configFolderPath, cli.controller.config?.schemaConfig?.outputDirectory || 'schemas');
35
+ const { schemaOutDir } = await inquirer.prompt([
36
+ {
37
+ type: 'input',
38
+ name: 'schemaOutDir',
39
+ message: 'Output directory for schemas:',
40
+ default: defaultSchemaOut,
41
+ validate: (input) => input && input.trim().length > 0 ? true : 'Please provide an output directory',
42
+ }
43
+ ]);
44
+ // Create SchemaGenerator with the correct base path and generate schemas
45
+ const schemaGenerator = new SchemaGenerator(cli.controller.config, configFolderPath);
46
+ const outDirRel = path.isAbsolute(schemaOutDir) ? schemaOutDir : path.relative(configFolderPath, schemaOutDir);
47
+ await schemaGenerator.generateSchemas({ format: schemaType, verbose: true, outputDir: outDirRel });
48
+ MessageFormatter.success("Schema generation completed", { prefix: "Schemas" });
49
+ },
50
+ async generateConstants(cli) {
51
+ MessageFormatter.progress("Generating cross-language constants...", { prefix: "Constants" });
52
+ if (!cli.controller?.config) {
53
+ MessageFormatter.error("No configuration found", undefined, { prefix: "Constants" });
54
+ return;
55
+ }
56
+ // Prompt for languages
57
+ const { languages } = await inquirer.prompt([
58
+ {
59
+ type: "checkbox",
60
+ name: "languages",
61
+ message: "Select languages for constants generation:",
62
+ choices: [
63
+ { name: "TypeScript", value: "typescript", checked: true },
64
+ { name: "JavaScript", value: "javascript" },
65
+ { name: "Python", value: "python" },
66
+ { name: "PHP", value: "php" },
67
+ { name: "Dart", value: "dart" },
68
+ { name: "JSON", value: "json" },
69
+ { name: "Environment Variables", value: "env" },
70
+ ],
71
+ validate: (input) => {
72
+ if (input.length === 0) {
73
+ return "Please select at least one language";
74
+ }
75
+ return true;
76
+ },
77
+ },
78
+ ]);
79
+ // Prompt for which constants to include
80
+ const { includeWhat } = await inquirer.prompt([
81
+ {
82
+ type: 'checkbox',
83
+ name: 'includeWhat',
84
+ message: 'Select which constants to generate:',
85
+ choices: [
86
+ { name: 'Databases', value: 'databases', checked: true },
87
+ { name: 'Collections/Tables', value: 'collections', checked: true },
88
+ { name: 'Buckets', value: 'buckets', checked: true },
89
+ { name: 'Functions', value: 'functions', checked: true },
90
+ ],
91
+ validate: (input) => input.length > 0 ? true : 'Select at least one category',
92
+ }
93
+ ]);
94
+ // Determine default output directory based on config location
95
+ const configPath = cli.controller.getAppwriteFolderPath();
96
+ const defaultOutputDir = configPath
97
+ ? path.join(configPath, "constants")
98
+ : path.join(process.cwd(), "constants");
99
+ // Prompt for output directory
100
+ const { outputDir } = await inquirer.prompt([
101
+ {
102
+ type: "input",
103
+ name: "outputDir",
104
+ message: "Output directory for constants files:",
105
+ default: defaultOutputDir,
106
+ validate: (input) => {
107
+ if (!input.trim()) {
108
+ return "Output directory cannot be empty";
109
+ }
110
+ return true;
111
+ },
112
+ },
113
+ ]);
114
+ try {
115
+ const { ConstantsGenerator } = await import("appwrite-utils-helpers");
116
+ const generator = new ConstantsGenerator(cli.controller.config);
117
+ const include = {
118
+ databases: includeWhat.includes('databases'),
119
+ collections: includeWhat.includes('collections'),
120
+ buckets: includeWhat.includes('buckets'),
121
+ functions: includeWhat.includes('functions'),
122
+ };
123
+ MessageFormatter.info(`Generating constants for: ${languages.join(", ")}`, { prefix: "Constants" });
124
+ await generator.generateFiles(languages, outputDir, include);
125
+ MessageFormatter.success(`Constants generated in ${outputDir}`, { prefix: "Constants" });
126
+ }
127
+ catch (error) {
128
+ MessageFormatter.error("Failed to generate constants", error instanceof Error ? error : new Error(String(error)), { prefix: "Constants" });
129
+ }
130
+ },
131
+ async importData(cli) {
132
+ MessageFormatter.progress("Importing data...", { prefix: "Import" });
133
+ const { doBackup } = await inquirer.prompt([
134
+ {
135
+ type: "confirm",
136
+ name: "doBackup",
137
+ message: "Do you want to perform a backup before importing?",
138
+ default: true,
139
+ },
140
+ ]);
141
+ const databases = await cli.selectDatabases(await fetchAllDatabases(cli.controller.database), "Select databases to import data into:", true);
142
+ const collections = await cli.selectCollectionsAndTables(databases[0], cli.controller.database, "Select collections/tables to import data into (leave empty for all):", true);
143
+ const { shouldWriteFile } = await inquirer.prompt([
144
+ {
145
+ type: "confirm",
146
+ name: "shouldWriteFile",
147
+ message: "Do you want to write the imported data to a file?",
148
+ default: false,
149
+ },
150
+ ]);
151
+ const options = {
152
+ databases,
153
+ collections: collections.map((c) => c.name),
154
+ doBackup,
155
+ importData: true,
156
+ shouldWriteFile,
157
+ };
158
+ try {
159
+ await cli.controller.importData(options);
160
+ MessageFormatter.success("Data import completed successfully", { prefix: "Import" });
161
+ }
162
+ catch (error) {
163
+ MessageFormatter.error("Error importing data", error instanceof Error ? error : new Error(String(error)), { prefix: "Import" });
164
+ }
165
+ },
166
+ async setupDirsFiles(cli, withExampleData = false) {
167
+ await setupDirsFiles(withExampleData, cli.currentDir);
168
+ }
169
+ };
@@ -0,0 +1,5 @@
1
+ import type { InteractiveCLI } from "../../interactiveCLI.js";
2
+ export declare const storageCommands: {
3
+ createBucket(cli: InteractiveCLI): Promise<void>;
4
+ deleteBuckets(cli: InteractiveCLI): Promise<void>;
5
+ };
@@ -0,0 +1,142 @@
1
+ import inquirer from "inquirer";
2
+ import chalk from "chalk";
3
+ import { Storage, Permission, Role, Compression } from "node-appwrite";
4
+ import { MessageFormatter } from 'appwrite-utils-helpers';
5
+ import { listBuckets, createBucket as createBucketApi, deleteBucket as deleteBucketApi } from "../../storage/methods.js";
6
+ import { writeYamlConfig, ConfigManager } from "appwrite-utils-helpers";
7
+ export const storageCommands = {
8
+ async createBucket(cli) {
9
+ const storage = cli.controller.storage;
10
+ if (!storage) {
11
+ MessageFormatter.error("Storage client not initialized", undefined, { prefix: "Buckets" });
12
+ return;
13
+ }
14
+ const answers = await inquirer.prompt([
15
+ { type: 'input', name: 'name', message: 'Bucket name:', validate: (v) => v?.trim()?.length > 0 || 'Required' },
16
+ { type: 'input', name: 'id', message: 'Bucket ID (optional):' },
17
+ { type: 'confirm', name: 'publicRead', message: 'Public read access?', default: false },
18
+ { type: 'confirm', name: 'fileSecurity', message: 'Enable file-level security?', default: false },
19
+ { type: 'confirm', name: 'enabled', message: 'Enable bucket?', default: true },
20
+ { type: 'number', name: 'maximumFileSize', message: 'Max file size (bytes, optional):', default: undefined },
21
+ { type: 'input', name: 'allowedFileExtensions', message: 'Allowed extensions (comma separated, optional):', default: '' },
22
+ { type: 'list', name: 'compression', message: 'Compression:', choices: ['none', 'gzip', 'zstd'], default: 'none' },
23
+ { type: 'confirm', name: 'encryption', message: 'Enable encryption?', default: false },
24
+ { type: 'confirm', name: 'antivirus', message: 'Enable antivirus?', default: false },
25
+ ]);
26
+ const permissions = [];
27
+ if (answers.publicRead)
28
+ permissions.push(Permission.read(Role.any()));
29
+ const bucketInput = {
30
+ name: answers.name,
31
+ $permissions: permissions,
32
+ fileSecurity: !!answers.fileSecurity,
33
+ enabled: !!answers.enabled,
34
+ maximumFileSize: answers.maximumFileSize || undefined,
35
+ allowedFileExtensions: String(answers.allowedFileExtensions || '')
36
+ .split(',')
37
+ .map((s) => s.trim())
38
+ .filter(Boolean),
39
+ compression: answers.compression,
40
+ encryption: !!answers.encryption,
41
+ antivirus: !!answers.antivirus,
42
+ };
43
+ try {
44
+ const created = await createBucketApi(storage, bucketInput, answers.id || undefined);
45
+ MessageFormatter.success(`Bucket '${answers.name}' created`, { prefix: 'Buckets' });
46
+ // Update in-memory config and persist to YAML as a global bucket entry
47
+ const controller = cli.controller;
48
+ controller.config.buckets = controller.config.buckets || [];
49
+ controller.config.buckets.push({
50
+ $id: created.$id || answers.id || bucketInput.name,
51
+ name: bucketInput.name,
52
+ permissions: [],
53
+ fileSecurity: bucketInput.fileSecurity,
54
+ enabled: bucketInput.enabled,
55
+ maximumFileSize: bucketInput.maximumFileSize,
56
+ allowedFileExtensions: bucketInput.allowedFileExtensions,
57
+ compression: bucketInput.compression,
58
+ encryption: bucketInput.encryption,
59
+ antivirus: bucketInput.antivirus,
60
+ });
61
+ const cfgMgr = ConfigManager.getInstance();
62
+ const cfgPath = cfgMgr.getConfigPath();
63
+ if (cfgPath && /\.ya?ml$/i.test(cfgPath)) {
64
+ await writeYamlConfig(cfgPath, controller.config);
65
+ MessageFormatter.info(`Added bucket to config.yaml`, { prefix: 'Buckets' });
66
+ }
67
+ else {
68
+ MessageFormatter.warning(`Config is not YAML; updated in-memory only. Please update your TypeScript config manually.`, { prefix: 'Buckets' });
69
+ }
70
+ }
71
+ catch (e) {
72
+ MessageFormatter.error('Failed to create bucket', e instanceof Error ? e : new Error(String(e)), { prefix: 'Buckets' });
73
+ }
74
+ },
75
+ async deleteBuckets(cli) {
76
+ const storage = cli.controller.storage;
77
+ if (!storage) {
78
+ MessageFormatter.error("Storage client not initialized", undefined, { prefix: "Buckets" });
79
+ return;
80
+ }
81
+ try {
82
+ const res = await listBuckets(storage);
83
+ const buckets = res.buckets || [];
84
+ if (buckets.length === 0) {
85
+ MessageFormatter.info('No buckets found', { prefix: 'Buckets' });
86
+ return;
87
+ }
88
+ const { toDelete } = await inquirer.prompt([
89
+ {
90
+ type: 'checkbox',
91
+ name: 'toDelete',
92
+ message: chalk.red('Select buckets to delete:'),
93
+ choices: buckets.map((b) => ({ name: `${b.name} (${b.$id})`, value: b.$id })),
94
+ pageSize: 10,
95
+ }
96
+ ]);
97
+ if (!toDelete || toDelete.length === 0) {
98
+ MessageFormatter.info('No buckets selected', { prefix: 'Buckets' });
99
+ return;
100
+ }
101
+ const { confirm } = await inquirer.prompt([
102
+ { type: 'confirm', name: 'confirm', message: `Delete ${toDelete.length} bucket(s)?`, default: false }
103
+ ]);
104
+ if (!confirm)
105
+ return;
106
+ const controller = cli.controller;
107
+ for (const id of toDelete) {
108
+ try {
109
+ await deleteBucketApi(storage, id);
110
+ MessageFormatter.success(`Deleted bucket ${id}`, { prefix: 'Buckets' });
111
+ // Remove from in-memory config (global buckets)
112
+ if (Array.isArray(controller.config.buckets)) {
113
+ controller.config.buckets = controller.config.buckets.filter((b) => b.$id !== id);
114
+ }
115
+ // Clear database-linked bucket references if matching
116
+ if (Array.isArray(controller.config.databases)) {
117
+ controller.config.databases = controller.config.databases.map((db) => ({
118
+ ...db,
119
+ bucket: db.bucket && db.bucket.$id === id ? undefined : db.bucket,
120
+ }));
121
+ }
122
+ }
123
+ catch (e) {
124
+ MessageFormatter.error(`Failed to delete bucket ${id}`, e instanceof Error ? e : new Error(String(e)), { prefix: 'Buckets' });
125
+ }
126
+ }
127
+ // Persist YAML changes
128
+ const cfgMgr = ConfigManager.getInstance();
129
+ const cfgPath = cfgMgr.getConfigPath();
130
+ if (cfgPath && /\.ya?ml$/i.test(cfgPath)) {
131
+ await writeYamlConfig(cfgPath, controller.config);
132
+ MessageFormatter.info(`Updated config.yaml after deletion`, { prefix: 'Buckets' });
133
+ }
134
+ else {
135
+ MessageFormatter.warning(`Config is not YAML; updated in-memory only. Please update your TypeScript config manually.`, { prefix: 'Buckets' });
136
+ }
137
+ }
138
+ catch (e) {
139
+ MessageFormatter.error('Failed to list buckets', e instanceof Error ? e : new Error(String(e)), { prefix: 'Buckets' });
140
+ }
141
+ }
142
+ };
@@ -0,0 +1,5 @@
1
+ import type { InteractiveCLI } from "../../interactiveCLI.js";
2
+ export declare const transferCommands: {
3
+ transferData(cli: InteractiveCLI): Promise<void>;
4
+ comprehensiveTransfer(cli: InteractiveCLI): Promise<void>;
5
+ };