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