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.
- package/.appwrite/.yaml_schemas/appwrite-config.schema.json +380 -0
- package/.appwrite/.yaml_schemas/collection.schema.json +255 -0
- package/.appwrite/collections/Categories.yaml +182 -0
- package/.appwrite/collections/ExampleCollection.yaml +36 -0
- package/.appwrite/collections/Posts.yaml +227 -0
- package/.appwrite/collections/Users.yaml +149 -0
- package/.appwrite/config.yaml +109 -0
- package/.appwrite/import/README.md +148 -0
- package/.appwrite/import/categories-import.yaml +129 -0
- package/.appwrite/import/posts-import.yaml +208 -0
- package/.appwrite/import/users-import.yaml +130 -0
- package/.appwrite/importData/categories.json +194 -0
- package/.appwrite/importData/posts.json +270 -0
- package/.appwrite/importData/users.json +220 -0
- package/.appwrite/schemas/categories.json +128 -0
- package/.appwrite/schemas/exampleCollection.json +52 -0
- package/.appwrite/schemas/posts.json +173 -0
- package/.appwrite/schemas/users.json +125 -0
- package/README.md +260 -33
- package/dist/collections/attributes.js +3 -2
- package/dist/collections/methods.js +56 -38
- package/dist/config/yamlConfig.d.ts +501 -0
- package/dist/config/yamlConfig.js +452 -0
- package/dist/databases/setup.d.ts +6 -0
- package/dist/databases/setup.js +119 -0
- package/dist/functions/methods.d.ts +1 -1
- package/dist/functions/methods.js +5 -2
- package/dist/functions/openapi.d.ts +4 -0
- package/dist/functions/openapi.js +60 -0
- package/dist/interactiveCLI.d.ts +5 -0
- package/dist/interactiveCLI.js +194 -49
- package/dist/main.js +91 -30
- package/dist/migrations/afterImportActions.js +2 -2
- package/dist/migrations/appwriteToX.d.ts +10 -0
- package/dist/migrations/appwriteToX.js +15 -4
- package/dist/migrations/backup.d.ts +16 -16
- package/dist/migrations/dataLoader.d.ts +83 -1
- package/dist/migrations/dataLoader.js +4 -4
- package/dist/migrations/importController.js +25 -18
- package/dist/migrations/importDataActions.js +2 -2
- package/dist/migrations/logging.d.ts +9 -1
- package/dist/migrations/logging.js +41 -22
- package/dist/migrations/migrationHelper.d.ts +4 -4
- package/dist/migrations/relationships.js +1 -1
- package/dist/migrations/services/DataTransformationService.d.ts +55 -0
- package/dist/migrations/services/DataTransformationService.js +158 -0
- package/dist/migrations/services/FileHandlerService.d.ts +75 -0
- package/dist/migrations/services/FileHandlerService.js +236 -0
- package/dist/migrations/services/ImportOrchestrator.d.ts +97 -0
- package/dist/migrations/services/ImportOrchestrator.js +488 -0
- package/dist/migrations/services/RateLimitManager.d.ts +138 -0
- package/dist/migrations/services/RateLimitManager.js +279 -0
- package/dist/migrations/services/RelationshipResolver.d.ts +120 -0
- package/dist/migrations/services/RelationshipResolver.js +332 -0
- package/dist/migrations/services/UserMappingService.d.ts +109 -0
- package/dist/migrations/services/UserMappingService.js +277 -0
- package/dist/migrations/services/ValidationService.d.ts +74 -0
- package/dist/migrations/services/ValidationService.js +260 -0
- package/dist/migrations/transfer.d.ts +0 -6
- package/dist/migrations/transfer.js +16 -132
- package/dist/migrations/yaml/YamlImportConfigLoader.d.ts +384 -0
- package/dist/migrations/yaml/YamlImportConfigLoader.js +375 -0
- package/dist/migrations/yaml/YamlImportIntegration.d.ts +87 -0
- package/dist/migrations/yaml/YamlImportIntegration.js +330 -0
- package/dist/migrations/yaml/generateImportSchemas.d.ts +17 -0
- package/dist/migrations/yaml/generateImportSchemas.js +575 -0
- package/dist/schemas/authUser.d.ts +9 -9
- package/dist/shared/attributeManager.d.ts +17 -0
- package/dist/shared/attributeManager.js +273 -0
- package/dist/shared/confirmationDialogs.d.ts +75 -0
- package/dist/shared/confirmationDialogs.js +236 -0
- package/dist/shared/functionManager.d.ts +48 -0
- package/dist/shared/functionManager.js +322 -0
- package/dist/shared/indexManager.d.ts +24 -0
- package/dist/shared/indexManager.js +150 -0
- package/dist/shared/jsonSchemaGenerator.d.ts +51 -0
- package/dist/shared/jsonSchemaGenerator.js +313 -0
- package/dist/shared/logging.d.ts +10 -0
- package/dist/shared/logging.js +46 -0
- package/dist/shared/messageFormatter.d.ts +37 -0
- package/dist/shared/messageFormatter.js +152 -0
- package/dist/shared/migrationHelpers.d.ts +173 -0
- package/dist/shared/migrationHelpers.js +142 -0
- package/dist/shared/operationLogger.d.ts +3 -0
- package/dist/shared/operationLogger.js +25 -0
- package/dist/shared/operationQueue.d.ts +13 -0
- package/dist/shared/operationQueue.js +79 -0
- package/dist/shared/progressManager.d.ts +62 -0
- package/dist/shared/progressManager.js +215 -0
- package/dist/shared/schemaGenerator.d.ts +18 -0
- package/dist/shared/schemaGenerator.js +523 -0
- package/dist/storage/methods.d.ts +3 -1
- package/dist/storage/methods.js +144 -55
- package/dist/storage/schemas.d.ts +56 -16
- package/dist/types.d.ts +2 -2
- package/dist/types.js +1 -1
- package/dist/users/methods.d.ts +16 -0
- package/dist/users/methods.js +276 -0
- package/dist/utils/configMigration.d.ts +1 -0
- package/dist/utils/configMigration.js +156 -0
- package/dist/utils/dataConverters.d.ts +46 -0
- package/dist/utils/dataConverters.js +139 -0
- package/dist/utils/loadConfigs.d.ts +15 -4
- package/dist/utils/loadConfigs.js +377 -51
- package/dist/utils/schemaStrings.js +2 -1
- package/dist/utils/setupFiles.d.ts +2 -1
- package/dist/utils/setupFiles.js +723 -28
- package/dist/utils/validationRules.d.ts +43 -0
- package/dist/utils/validationRules.js +42 -0
- package/dist/utils/yamlConverter.d.ts +48 -0
- package/dist/utils/yamlConverter.js +98 -0
- package/dist/utilsController.js +65 -43
- package/package.json +19 -15
- package/src/collections/attributes.ts +3 -2
- package/src/collections/methods.ts +85 -51
- package/src/config/yamlConfig.ts +488 -0
- package/src/{migrations/setupDatabase.ts → databases/setup.ts} +11 -5
- package/src/functions/methods.ts +8 -4
- package/src/functions/templates/count-docs-in-collection/package.json +25 -0
- package/src/functions/templates/count-docs-in-collection/tsconfig.json +28 -0
- package/src/functions/templates/typescript-node/package.json +24 -0
- package/src/functions/templates/typescript-node/tsconfig.json +28 -0
- package/src/functions/templates/uv/README.md +31 -0
- package/src/functions/templates/uv/pyproject.toml +29 -0
- package/src/interactiveCLI.ts +226 -61
- package/src/main.ts +111 -37
- package/src/migrations/afterImportActions.ts +2 -2
- package/src/migrations/appwriteToX.ts +17 -4
- package/src/migrations/dataLoader.ts +4 -4
- package/src/migrations/importController.ts +30 -22
- package/src/migrations/importDataActions.ts +2 -2
- package/src/migrations/relationships.ts +1 -1
- package/src/migrations/services/DataTransformationService.ts +196 -0
- package/src/migrations/services/FileHandlerService.ts +311 -0
- package/src/migrations/services/ImportOrchestrator.ts +669 -0
- package/src/migrations/services/RateLimitManager.ts +363 -0
- package/src/migrations/services/RelationshipResolver.ts +461 -0
- package/src/migrations/services/UserMappingService.ts +345 -0
- package/src/migrations/services/ValidationService.ts +349 -0
- package/src/migrations/transfer.ts +22 -228
- package/src/migrations/yaml/YamlImportConfigLoader.ts +427 -0
- package/src/migrations/yaml/YamlImportIntegration.ts +419 -0
- package/src/migrations/yaml/generateImportSchemas.ts +589 -0
- package/src/shared/attributeManager.ts +429 -0
- package/src/shared/confirmationDialogs.ts +327 -0
- package/src/shared/functionManager.ts +515 -0
- package/src/shared/indexManager.ts +253 -0
- package/src/shared/jsonSchemaGenerator.ts +403 -0
- package/src/shared/logging.ts +74 -0
- package/src/shared/messageFormatter.ts +195 -0
- package/src/{migrations/migrationHelper.ts → shared/migrationHelpers.ts} +22 -4
- package/src/{migrations/helper.ts → shared/operationLogger.ts} +7 -2
- package/src/{migrations/queue.ts → shared/operationQueue.ts} +1 -1
- package/src/shared/progressManager.ts +278 -0
- package/src/{migrations/schemaStrings.ts → shared/schemaGenerator.ts} +71 -17
- package/src/storage/methods.ts +199 -78
- package/src/types.ts +2 -2
- package/src/{migrations/users.ts → users/methods.ts} +2 -2
- package/src/utils/configMigration.ts +212 -0
- package/src/utils/loadConfigs.ts +414 -52
- package/src/utils/schemaStrings.ts +2 -1
- package/src/utils/setupFiles.ts +742 -40
- package/src/{migrations → utils}/validationRules.ts +1 -1
- package/src/utils/yamlConverter.ts +131 -0
- package/src/utilsController.ts +75 -54
- package/src/functions/templates/poetry/README.md +0 -30
- package/src/functions/templates/poetry/pyproject.toml +0 -16
- package/src/migrations/attributes.ts +0 -561
- package/src/migrations/backup.ts +0 -205
- package/src/migrations/databases.ts +0 -39
- package/src/migrations/dbHelpers.ts +0 -92
- package/src/migrations/indexes.ts +0 -40
- package/src/migrations/logging.ts +0 -29
- package/src/migrations/storage.ts +0 -538
- /package/src/{migrations → functions}/openapi.ts +0 -0
- /package/src/functions/templates/{poetry → uv}/src/__init__.py +0 -0
- /package/src/functions/templates/{poetry → uv}/src/index.py +0 -0
- /package/src/{migrations/converters.ts → utils/dataConverters.ts} +0 -0
package/dist/interactiveCLI.d.ts
CHANGED
@@ -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
|
}
|
package/dist/interactiveCLI.js
CHANGED
@@ -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 "./
|
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
|
-
|
46
|
-
|
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
|
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
|
-
|
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) =>
|
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) =>
|
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",
|
@@ -225,6 +250,34 @@ export class InteractiveCLI {
|
|
225
250
|
]);
|
226
251
|
return selectedCollections;
|
227
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
|
+
}
|
228
281
|
async createFunction() {
|
229
282
|
const { name } = await inquirer.prompt([
|
230
283
|
{
|
@@ -240,19 +293,22 @@ export class InteractiveCLI {
|
|
240
293
|
name: "template",
|
241
294
|
message: "Select a template:",
|
242
295
|
choices: [
|
243
|
-
"typescript-node",
|
244
|
-
"
|
245
|
-
"count-docs-in-collection",
|
246
|
-
"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" },
|
247
300
|
],
|
248
301
|
},
|
249
302
|
]);
|
303
|
+
// Get template defaults
|
304
|
+
const templateDefaults = this.getTemplateDefaults(template);
|
250
305
|
const { runtime } = await inquirer.prompt([
|
251
306
|
{
|
252
307
|
type: "list",
|
253
308
|
name: "runtime",
|
254
309
|
message: "Select runtime:",
|
255
310
|
choices: Object.values(RuntimeSchema.Values),
|
311
|
+
default: templateDefaults.runtime,
|
256
312
|
},
|
257
313
|
]);
|
258
314
|
const specifications = await listSpecifications(this.controller.appwriteServer);
|
@@ -268,6 +324,7 @@ export class InteractiveCLI {
|
|
268
324
|
value: s.slug,
|
269
325
|
})),
|
270
326
|
],
|
327
|
+
default: templateDefaults.specification,
|
271
328
|
},
|
272
329
|
]);
|
273
330
|
const functionConfig = {
|
@@ -278,22 +335,40 @@ export class InteractiveCLI {
|
|
278
335
|
execute: ["any"],
|
279
336
|
enabled: true,
|
280
337
|
logging: true,
|
281
|
-
entrypoint:
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
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: "",
|
287
352
|
};
|
288
353
|
if (template !== "none") {
|
289
354
|
await createFunctionTemplate(template, name, "./functions");
|
290
355
|
}
|
291
|
-
// Add to config
|
356
|
+
// Add to in-memory config
|
292
357
|
if (!this.controller.config.functions) {
|
293
358
|
this.controller.config.functions = [];
|
294
359
|
}
|
295
360
|
this.controller.config.functions.push(functionConfig);
|
296
|
-
|
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" });
|
297
372
|
}
|
298
373
|
async findFunctionInSubdirectories(basePaths, functionName) {
|
299
374
|
// Common locations to check first
|
@@ -455,7 +530,7 @@ export class InteractiveCLI {
|
|
455
530
|
...functionConfig,
|
456
531
|
dirPath: functionPath,
|
457
532
|
});
|
458
|
-
|
533
|
+
MessageFormatter.success("Function deployed successfully!", { prefix: "Functions" });
|
459
534
|
}
|
460
535
|
catch (error) {
|
461
536
|
console.error(chalk.red("Failed to deploy function:"), error);
|
@@ -995,7 +1070,7 @@ export class InteractiveCLI {
|
|
995
1070
|
console.log(chalk.yellow(`Backing up database: ${db.name}`));
|
996
1071
|
await this.controller.backupDatabase(db);
|
997
1072
|
}
|
998
|
-
|
1073
|
+
MessageFormatter.success("Database backup completed", { prefix: "Backup" });
|
999
1074
|
}
|
1000
1075
|
async wipeDatabase() {
|
1001
1076
|
if (!this.controller.database || !this.controller.storage) {
|
@@ -1020,16 +1095,13 @@ export class InteractiveCLI {
|
|
1020
1095
|
default: false,
|
1021
1096
|
},
|
1022
1097
|
]);
|
1023
|
-
const
|
1024
|
-
|
1025
|
-
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1029
|
-
}
|
1030
|
-
]);
|
1031
|
-
if (confirm) {
|
1032
|
-
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" });
|
1033
1105
|
for (const db of selectedDatabases) {
|
1034
1106
|
await this.controller.wipeDatabase(db);
|
1035
1107
|
}
|
@@ -1039,10 +1111,10 @@ export class InteractiveCLI {
|
|
1039
1111
|
if (wipeUsers) {
|
1040
1112
|
await this.controller.wipeUsers();
|
1041
1113
|
}
|
1042
|
-
|
1114
|
+
MessageFormatter.success("Wipe operation completed", { prefix: "Wipe" });
|
1043
1115
|
}
|
1044
1116
|
else {
|
1045
|
-
|
1117
|
+
MessageFormatter.info("Wipe operation cancelled", { prefix: "Wipe" });
|
1046
1118
|
}
|
1047
1119
|
}
|
1048
1120
|
async wipeCollections() {
|
@@ -1053,31 +1125,47 @@ export class InteractiveCLI {
|
|
1053
1125
|
const selectedDatabases = await this.selectDatabases(databases, "Select the database(s) containing the collections to wipe:", true);
|
1054
1126
|
for (const database of selectedDatabases) {
|
1055
1127
|
const collections = await this.selectCollections(database, this.controller.database, `Select collections to wipe from ${database.name}:`, true, undefined, true);
|
1056
|
-
const
|
1057
|
-
|
1058
|
-
|
1059
|
-
|
1060
|
-
message: chalk.red(`Are you sure you want to wipe the selected collections from ${database.name}? This action cannot be undone.`),
|
1061
|
-
default: false,
|
1062
|
-
},
|
1063
|
-
]);
|
1064
|
-
if (confirm) {
|
1065
|
-
console.log(chalk.yellow(`Wiping selected collections from ${database.name}...`));
|
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" });
|
1066
1132
|
for (const collection of collections) {
|
1067
1133
|
await this.controller.wipeCollection(database, collection);
|
1068
|
-
|
1134
|
+
MessageFormatter.success(`Collection ${collection.name} wiped successfully`, { prefix: "Wipe" });
|
1069
1135
|
}
|
1070
1136
|
}
|
1071
1137
|
else {
|
1072
|
-
|
1138
|
+
MessageFormatter.info(`Wipe operation cancelled for ${database.name}`, { prefix: "Wipe" });
|
1073
1139
|
}
|
1074
1140
|
}
|
1075
|
-
|
1141
|
+
MessageFormatter.success("Wipe collections operation completed", { prefix: "Wipe" });
|
1076
1142
|
}
|
1077
1143
|
async generateSchemas() {
|
1078
1144
|
console.log(chalk.yellow("Generating schemas..."));
|
1079
|
-
|
1080
|
-
|
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" });
|
1081
1169
|
}
|
1082
1170
|
async importData() {
|
1083
1171
|
console.log(chalk.yellow("Importing data..."));
|
@@ -1294,4 +1382,61 @@ export class InteractiveCLI {
|
|
1294
1382
|
console.error(chalk.red("Error updating function specification:"), error);
|
1295
1383
|
}
|
1296
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
|
+
}
|
1297
1442
|
}
|