appwrite-utils-cli 1.5.2 → 1.6.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/CHANGELOG.md +199 -0
- package/README.md +251 -29
- package/dist/adapters/AdapterFactory.d.ts +10 -3
- package/dist/adapters/AdapterFactory.js +213 -17
- package/dist/adapters/TablesDBAdapter.js +60 -17
- package/dist/backups/operations/bucketBackup.d.ts +19 -0
- package/dist/backups/operations/bucketBackup.js +197 -0
- package/dist/backups/operations/collectionBackup.d.ts +30 -0
- package/dist/backups/operations/collectionBackup.js +201 -0
- package/dist/backups/operations/comprehensiveBackup.d.ts +25 -0
- package/dist/backups/operations/comprehensiveBackup.js +238 -0
- package/dist/backups/schemas/bucketManifest.d.ts +93 -0
- package/dist/backups/schemas/bucketManifest.js +33 -0
- package/dist/backups/schemas/comprehensiveManifest.d.ts +108 -0
- package/dist/backups/schemas/comprehensiveManifest.js +32 -0
- package/dist/backups/tracking/centralizedTracking.d.ts +34 -0
- package/dist/backups/tracking/centralizedTracking.js +274 -0
- package/dist/cli/commands/configCommands.d.ts +8 -0
- package/dist/cli/commands/configCommands.js +160 -0
- package/dist/cli/commands/databaseCommands.d.ts +13 -0
- package/dist/cli/commands/databaseCommands.js +479 -0
- package/dist/cli/commands/functionCommands.d.ts +7 -0
- package/dist/cli/commands/functionCommands.js +289 -0
- package/dist/cli/commands/schemaCommands.d.ts +7 -0
- package/dist/cli/commands/schemaCommands.js +134 -0
- package/dist/cli/commands/transferCommands.d.ts +5 -0
- package/dist/cli/commands/transferCommands.js +384 -0
- package/dist/collections/attributes.d.ts +5 -4
- package/dist/collections/attributes.js +539 -246
- package/dist/collections/indexes.js +39 -37
- package/dist/collections/methods.d.ts +2 -16
- package/dist/collections/methods.js +90 -538
- package/dist/collections/transferOperations.d.ts +7 -0
- package/dist/collections/transferOperations.js +331 -0
- package/dist/collections/wipeOperations.d.ts +16 -0
- package/dist/collections/wipeOperations.js +328 -0
- package/dist/config/configMigration.d.ts +87 -0
- package/dist/config/configMigration.js +390 -0
- package/dist/config/configValidation.d.ts +66 -0
- package/dist/config/configValidation.js +358 -0
- package/dist/config/yamlConfig.d.ts +455 -1
- package/dist/config/yamlConfig.js +145 -52
- package/dist/databases/methods.js +3 -2
- package/dist/databases/setup.d.ts +1 -2
- package/dist/databases/setup.js +9 -87
- package/dist/examples/yamlTerminologyExample.d.ts +42 -0
- package/dist/examples/yamlTerminologyExample.js +269 -0
- package/dist/functions/deployments.js +11 -10
- package/dist/functions/methods.d.ts +1 -1
- package/dist/functions/methods.js +5 -4
- package/dist/init.js +9 -9
- package/dist/interactiveCLI.d.ts +8 -17
- package/dist/interactiveCLI.js +209 -1172
- package/dist/main.js +364 -21
- package/dist/migrations/afterImportActions.js +22 -30
- package/dist/migrations/appwriteToX.js +71 -25
- package/dist/migrations/dataLoader.js +35 -26
- package/dist/migrations/importController.js +29 -30
- package/dist/migrations/relationships.js +13 -12
- package/dist/migrations/services/ImportOrchestrator.js +16 -19
- package/dist/migrations/transfer.js +46 -46
- package/dist/migrations/yaml/YamlImportConfigLoader.d.ts +3 -1
- package/dist/migrations/yaml/YamlImportConfigLoader.js +6 -3
- package/dist/migrations/yaml/YamlImportIntegration.d.ts +9 -3
- package/dist/migrations/yaml/YamlImportIntegration.js +22 -11
- package/dist/migrations/yaml/generateImportSchemas.d.ts +14 -1
- package/dist/migrations/yaml/generateImportSchemas.js +736 -7
- package/dist/schemas/authUser.d.ts +1 -1
- package/dist/setupController.js +3 -2
- package/dist/shared/backupMetadataSchema.d.ts +94 -0
- package/dist/shared/backupMetadataSchema.js +38 -0
- package/dist/shared/backupTracking.d.ts +18 -0
- package/dist/shared/backupTracking.js +176 -0
- package/dist/shared/confirmationDialogs.js +15 -15
- package/dist/shared/errorUtils.d.ts +54 -0
- package/dist/shared/errorUtils.js +95 -0
- package/dist/shared/functionManager.js +20 -19
- package/dist/shared/indexManager.js +12 -11
- package/dist/shared/jsonSchemaGenerator.js +10 -26
- package/dist/shared/logging.d.ts +51 -0
- package/dist/shared/logging.js +70 -0
- package/dist/shared/messageFormatter.d.ts +2 -0
- package/dist/shared/messageFormatter.js +10 -0
- package/dist/shared/migrationHelpers.d.ts +6 -16
- package/dist/shared/migrationHelpers.js +24 -21
- package/dist/shared/operationLogger.d.ts +8 -1
- package/dist/shared/operationLogger.js +11 -24
- package/dist/shared/operationQueue.d.ts +28 -1
- package/dist/shared/operationQueue.js +268 -66
- package/dist/shared/operationsTable.d.ts +26 -0
- package/dist/shared/operationsTable.js +286 -0
- package/dist/shared/operationsTableSchema.d.ts +48 -0
- package/dist/shared/operationsTableSchema.js +35 -0
- package/dist/shared/relationshipExtractor.d.ts +56 -0
- package/dist/shared/relationshipExtractor.js +138 -0
- package/dist/shared/schemaGenerator.d.ts +19 -1
- package/dist/shared/schemaGenerator.js +56 -75
- package/dist/storage/backupCompression.d.ts +20 -0
- package/dist/storage/backupCompression.js +67 -0
- package/dist/storage/methods.d.ts +16 -2
- package/dist/storage/methods.js +98 -14
- package/dist/users/methods.js +9 -8
- package/dist/utils/configDiscovery.d.ts +78 -0
- package/dist/utils/configDiscovery.js +430 -0
- package/dist/utils/directoryUtils.d.ts +22 -0
- package/dist/utils/directoryUtils.js +59 -0
- package/dist/utils/getClientFromConfig.d.ts +17 -8
- package/dist/utils/getClientFromConfig.js +162 -17
- package/dist/utils/helperFunctions.d.ts +16 -2
- package/dist/utils/helperFunctions.js +19 -5
- package/dist/utils/loadConfigs.d.ts +34 -9
- package/dist/utils/loadConfigs.js +236 -316
- package/dist/utils/pathResolvers.d.ts +53 -0
- package/dist/utils/pathResolvers.js +72 -0
- package/dist/utils/projectConfig.d.ts +119 -0
- package/dist/utils/projectConfig.js +171 -0
- package/dist/utils/retryFailedPromises.js +4 -2
- package/dist/utils/sessionAuth.d.ts +48 -0
- package/dist/utils/sessionAuth.js +164 -0
- package/dist/utils/sessionPreservationExample.d.ts +1666 -0
- package/dist/utils/sessionPreservationExample.js +101 -0
- package/dist/utils/setupFiles.js +301 -41
- package/dist/utils/typeGuards.d.ts +35 -0
- package/dist/utils/typeGuards.js +57 -0
- package/dist/utils/versionDetection.js +145 -9
- package/dist/utils/yamlConverter.d.ts +53 -3
- package/dist/utils/yamlConverter.js +232 -13
- package/dist/utils/yamlLoader.d.ts +70 -0
- package/dist/utils/yamlLoader.js +263 -0
- package/dist/utilsController.d.ts +36 -3
- package/dist/utilsController.js +186 -56
- package/package.json +12 -2
- package/src/adapters/AdapterFactory.ts +263 -35
- package/src/adapters/TablesDBAdapter.ts +225 -36
- package/src/backups/operations/bucketBackup.ts +277 -0
- package/src/backups/operations/collectionBackup.ts +310 -0
- package/src/backups/operations/comprehensiveBackup.ts +342 -0
- package/src/backups/schemas/bucketManifest.ts +78 -0
- package/src/backups/schemas/comprehensiveManifest.ts +76 -0
- package/src/backups/tracking/centralizedTracking.ts +352 -0
- package/src/cli/commands/configCommands.ts +194 -0
- package/src/cli/commands/databaseCommands.ts +635 -0
- package/src/cli/commands/functionCommands.ts +379 -0
- package/src/cli/commands/schemaCommands.ts +163 -0
- package/src/cli/commands/transferCommands.ts +457 -0
- package/src/collections/attributes.ts +900 -621
- package/src/collections/attributes.ts.backup +1555 -0
- package/src/collections/indexes.ts +116 -114
- package/src/collections/methods.ts +295 -968
- package/src/collections/transferOperations.ts +516 -0
- package/src/collections/wipeOperations.ts +501 -0
- package/src/config/README.md +274 -0
- package/src/config/configMigration.ts +575 -0
- package/src/config/configValidation.ts +445 -0
- package/src/config/yamlConfig.ts +168 -55
- package/src/databases/methods.ts +3 -2
- package/src/databases/setup.ts +11 -138
- package/src/examples/yamlTerminologyExample.ts +341 -0
- package/src/functions/deployments.ts +14 -12
- package/src/functions/methods.ts +11 -11
- package/src/functions/templates/hono-typescript/README.md +286 -0
- package/src/functions/templates/hono-typescript/package.json +26 -0
- package/src/functions/templates/hono-typescript/src/adapters/request.ts +74 -0
- package/src/functions/templates/hono-typescript/src/adapters/response.ts +106 -0
- package/src/functions/templates/hono-typescript/src/app.ts +180 -0
- package/src/functions/templates/hono-typescript/src/context.ts +103 -0
- package/src/functions/templates/hono-typescript/src/index.ts +54 -0
- package/src/functions/templates/hono-typescript/src/middleware/appwrite.ts +119 -0
- package/src/functions/templates/hono-typescript/tsconfig.json +20 -0
- package/src/functions/templates/typescript-node/package.json +2 -1
- package/src/functions/templates/typescript-node/src/context.ts +103 -0
- package/src/functions/templates/typescript-node/src/index.ts +18 -12
- package/src/functions/templates/uv/pyproject.toml +1 -0
- package/src/functions/templates/uv/src/context.py +125 -0
- package/src/functions/templates/uv/src/index.py +35 -5
- package/src/init.ts +9 -11
- package/src/interactiveCLI.ts +274 -1563
- package/src/main.ts +418 -24
- package/src/migrations/afterImportActions.ts +71 -44
- package/src/migrations/appwriteToX.ts +100 -34
- package/src/migrations/dataLoader.ts +48 -34
- package/src/migrations/importController.ts +44 -39
- package/src/migrations/relationships.ts +28 -18
- package/src/migrations/services/ImportOrchestrator.ts +24 -27
- package/src/migrations/transfer.ts +159 -121
- package/src/migrations/yaml/YamlImportConfigLoader.ts +11 -4
- package/src/migrations/yaml/YamlImportIntegration.ts +47 -20
- package/src/migrations/yaml/generateImportSchemas.ts +751 -12
- package/src/setupController.ts +3 -2
- package/src/shared/backupMetadataSchema.ts +93 -0
- package/src/shared/backupTracking.ts +211 -0
- package/src/shared/confirmationDialogs.ts +19 -19
- package/src/shared/errorUtils.ts +110 -0
- package/src/shared/functionManager.ts +21 -20
- package/src/shared/indexManager.ts +12 -11
- package/src/shared/jsonSchemaGenerator.ts +38 -52
- package/src/shared/logging.ts +75 -0
- package/src/shared/messageFormatter.ts +14 -1
- package/src/shared/migrationHelpers.ts +45 -38
- package/src/shared/operationLogger.ts +11 -36
- package/src/shared/operationQueue.ts +322 -93
- package/src/shared/operationsTable.ts +338 -0
- package/src/shared/operationsTableSchema.ts +60 -0
- package/src/shared/relationshipExtractor.ts +214 -0
- package/src/shared/schemaGenerator.ts +179 -219
- package/src/storage/backupCompression.ts +88 -0
- package/src/storage/methods.ts +131 -34
- package/src/users/methods.ts +11 -9
- package/src/utils/configDiscovery.ts +502 -0
- package/src/utils/directoryUtils.ts +61 -0
- package/src/utils/getClientFromConfig.ts +205 -22
- package/src/utils/helperFunctions.ts +23 -5
- package/src/utils/loadConfigs.ts +313 -345
- package/src/utils/pathResolvers.ts +81 -0
- package/src/utils/projectConfig.ts +299 -0
- package/src/utils/retryFailedPromises.ts +4 -2
- package/src/utils/sessionAuth.ts +230 -0
- package/src/utils/setupFiles.ts +322 -54
- package/src/utils/typeGuards.ts +65 -0
- package/src/utils/versionDetection.ts +218 -64
- package/src/utils/yamlConverter.ts +296 -13
- package/src/utils/yamlLoader.ts +364 -0
- package/src/utilsController.ts +314 -110
- package/tests/README.md +497 -0
- package/tests/adapters/AdapterFactory.test.ts +277 -0
- package/tests/integration/syncOperations.test.ts +463 -0
- package/tests/jest.config.js +25 -0
- package/tests/migration/configMigration.test.ts +546 -0
- package/tests/setup.ts +62 -0
- package/tests/testUtils.ts +340 -0
- package/tests/utils/loadConfigs.test.ts +350 -0
- package/tests/validation/configValidation.test.ts +412 -0
- package/src/utils/schemaStrings.ts +0 -517
@@ -0,0 +1,379 @@
|
|
1
|
+
import inquirer from "inquirer";
|
2
|
+
import { join } from "node:path";
|
3
|
+
import fs from "node:fs";
|
4
|
+
import os from "node:os";
|
5
|
+
import { ulid } from "ulidx";
|
6
|
+
import chalk from "chalk";
|
7
|
+
import { Query } from "node-appwrite";
|
8
|
+
import { MessageFormatter } from "../../shared/messageFormatter.js";
|
9
|
+
import {
|
10
|
+
createFunctionTemplate,
|
11
|
+
deleteFunction,
|
12
|
+
downloadLatestFunctionDeployment,
|
13
|
+
listFunctions,
|
14
|
+
listSpecifications,
|
15
|
+
} from "../../functions/methods.js";
|
16
|
+
import { deployLocalFunction } from "../../functions/deployments.js";
|
17
|
+
import { addFunctionToYamlConfig, findYamlConfig } from "../../config/yamlConfig.js";
|
18
|
+
import { RuntimeSchema, type AppwriteFunction, type Runtime, type Specification } from "appwrite-utils";
|
19
|
+
import type { InteractiveCLI } from "../../interactiveCLI.js";
|
20
|
+
|
21
|
+
export const functionCommands = {
|
22
|
+
async createFunction(cli: InteractiveCLI): Promise<void> {
|
23
|
+
const { name } = await inquirer.prompt([
|
24
|
+
{
|
25
|
+
type: "input",
|
26
|
+
name: "name",
|
27
|
+
message: "Function name:",
|
28
|
+
validate: (input) => input.length > 0,
|
29
|
+
},
|
30
|
+
]);
|
31
|
+
|
32
|
+
const { template } = await inquirer.prompt([
|
33
|
+
{
|
34
|
+
type: "list",
|
35
|
+
name: "template",
|
36
|
+
message: "Select a template:",
|
37
|
+
choices: [
|
38
|
+
{ name: "TypeScript Node.js", value: "typescript-node" },
|
39
|
+
{ name: "TypeScript with Hono Web Framework", value: "hono-typescript" },
|
40
|
+
{ name: "Python with UV", value: "uv" },
|
41
|
+
{ name: "Count Documents in Collection", value: "count-docs-in-collection" },
|
42
|
+
{ name: "None (Empty Function)", value: "none" },
|
43
|
+
],
|
44
|
+
},
|
45
|
+
]);
|
46
|
+
|
47
|
+
// Get template defaults
|
48
|
+
const templateDefaults = (cli as any).getTemplateDefaults(template);
|
49
|
+
|
50
|
+
const { runtime } = await inquirer.prompt([
|
51
|
+
{
|
52
|
+
type: "list",
|
53
|
+
name: "runtime",
|
54
|
+
message: "Select runtime:",
|
55
|
+
choices: Object.values(RuntimeSchema.Values),
|
56
|
+
default: templateDefaults.runtime,
|
57
|
+
},
|
58
|
+
]);
|
59
|
+
|
60
|
+
const specifications = await listSpecifications(
|
61
|
+
(cli as any).controller!.appwriteServer!
|
62
|
+
);
|
63
|
+
const { specification } = await inquirer.prompt([
|
64
|
+
{
|
65
|
+
type: "list",
|
66
|
+
name: "specification",
|
67
|
+
message: "Select specification:",
|
68
|
+
choices: [
|
69
|
+
{ name: "None", value: undefined },
|
70
|
+
...specifications.specifications.map((s: any) => ({
|
71
|
+
name: s.slug,
|
72
|
+
value: s.slug,
|
73
|
+
})),
|
74
|
+
],
|
75
|
+
default: templateDefaults.specification,
|
76
|
+
},
|
77
|
+
]);
|
78
|
+
|
79
|
+
const functionConfig: AppwriteFunction = {
|
80
|
+
$id: ulid(),
|
81
|
+
name,
|
82
|
+
runtime,
|
83
|
+
events: [],
|
84
|
+
execute: ["any"],
|
85
|
+
enabled: true,
|
86
|
+
logging: true,
|
87
|
+
entrypoint: templateDefaults.entrypoint,
|
88
|
+
commands: templateDefaults.commands,
|
89
|
+
specification: specification || templateDefaults.specification,
|
90
|
+
scopes: [],
|
91
|
+
timeout: 15,
|
92
|
+
schedule: "",
|
93
|
+
installationId: "",
|
94
|
+
providerRepositoryId: "",
|
95
|
+
providerBranch: "",
|
96
|
+
providerSilentMode: false,
|
97
|
+
providerRootDirectory: "",
|
98
|
+
templateRepository: "",
|
99
|
+
templateOwner: "",
|
100
|
+
templateRootDirectory: "",
|
101
|
+
};
|
102
|
+
|
103
|
+
if (template !== "none") {
|
104
|
+
await createFunctionTemplate(
|
105
|
+
template as "typescript-node" | "uv" | "count-docs-in-collection" | "hono-typescript",
|
106
|
+
name,
|
107
|
+
"./functions"
|
108
|
+
);
|
109
|
+
}
|
110
|
+
|
111
|
+
// Add to in-memory config
|
112
|
+
if (!(cli as any).controller!.config!.functions) {
|
113
|
+
(cli as any).controller!.config!.functions = [];
|
114
|
+
}
|
115
|
+
(cli as any).controller!.config!.functions.push(functionConfig);
|
116
|
+
|
117
|
+
// If using YAML config, also add to YAML file
|
118
|
+
const yamlConfigPath = findYamlConfig((cli as any).currentDir);
|
119
|
+
if (yamlConfigPath) {
|
120
|
+
try {
|
121
|
+
await addFunctionToYamlConfig(yamlConfigPath, functionConfig);
|
122
|
+
} catch (error) {
|
123
|
+
MessageFormatter.warning(
|
124
|
+
`Function created but failed to update YAML config: ${error instanceof Error ? error.message : error}`,
|
125
|
+
{ prefix: "Functions" }
|
126
|
+
);
|
127
|
+
}
|
128
|
+
}
|
129
|
+
|
130
|
+
MessageFormatter.success("Function created successfully!", { prefix: "Functions" });
|
131
|
+
},
|
132
|
+
|
133
|
+
async deployFunction(cli: InteractiveCLI): Promise<void> {
|
134
|
+
await (cli as any).initControllerIfNeeded();
|
135
|
+
if (!(cli as any).controller?.config) {
|
136
|
+
MessageFormatter.error("Failed to initialize controller or load config", undefined, { prefix: "Functions" });
|
137
|
+
return;
|
138
|
+
}
|
139
|
+
|
140
|
+
const functions = await (cli as any).selectFunctions(
|
141
|
+
"Select function(s) to deploy:",
|
142
|
+
true,
|
143
|
+
true
|
144
|
+
);
|
145
|
+
|
146
|
+
if (!functions?.length) {
|
147
|
+
MessageFormatter.error("No function selected", undefined, { prefix: "Functions" });
|
148
|
+
return;
|
149
|
+
}
|
150
|
+
|
151
|
+
for (const functionConfig of functions) {
|
152
|
+
if (!functionConfig) {
|
153
|
+
MessageFormatter.error("Invalid function configuration", undefined, { prefix: "Functions" });
|
154
|
+
return;
|
155
|
+
}
|
156
|
+
|
157
|
+
// Ensure functions array exists
|
158
|
+
if (!(cli as any).controller.config.functions) {
|
159
|
+
(cli as any).controller.config.functions = [];
|
160
|
+
}
|
161
|
+
|
162
|
+
const functionNameLower = functionConfig.name
|
163
|
+
.toLowerCase()
|
164
|
+
.replace(/\s+/g, "-");
|
165
|
+
|
166
|
+
// Debug logging
|
167
|
+
MessageFormatter.info(`🔍 Function deployment debug:`, { prefix: "Functions" });
|
168
|
+
MessageFormatter.info(` Function name: ${functionConfig.name}`, { prefix: "Functions" });
|
169
|
+
MessageFormatter.info(` Function ID: ${functionConfig.$id}`, { prefix: "Functions" });
|
170
|
+
MessageFormatter.info(` Config dirPath: ${functionConfig.dirPath || 'undefined'}`, { prefix: "Functions" });
|
171
|
+
if (functionConfig.dirPath) {
|
172
|
+
const expandedPath = functionConfig.dirPath.startsWith('~/')
|
173
|
+
? functionConfig.dirPath.replace('~', os.homedir())
|
174
|
+
: functionConfig.dirPath;
|
175
|
+
MessageFormatter.info(` Expanded dirPath: ${expandedPath}`, { prefix: "Functions" });
|
176
|
+
}
|
177
|
+
MessageFormatter.info(` Appwrite folder: ${(cli as any).controller.getAppwriteFolderPath()}`, { prefix: "Functions" });
|
178
|
+
MessageFormatter.info(` Current working dir: ${process.cwd()}`, { prefix: "Functions" });
|
179
|
+
|
180
|
+
// Helper function to expand tilde in paths
|
181
|
+
const expandTildePath = (path: string): string => {
|
182
|
+
if (path.startsWith('~/')) {
|
183
|
+
return path.replace('~', os.homedir());
|
184
|
+
}
|
185
|
+
return path;
|
186
|
+
};
|
187
|
+
|
188
|
+
// Check locations in priority order:
|
189
|
+
const priorityLocations = [
|
190
|
+
// 1. Config dirPath if specified (with tilde expansion)
|
191
|
+
functionConfig.dirPath ? expandTildePath(functionConfig.dirPath) : undefined,
|
192
|
+
// 2. Appwrite config folder/functions/name
|
193
|
+
join(
|
194
|
+
(cli as any).controller.getAppwriteFolderPath()!,
|
195
|
+
"functions",
|
196
|
+
functionNameLower
|
197
|
+
),
|
198
|
+
// 3. Current working directory/functions/name
|
199
|
+
join(process.cwd(), "functions", functionNameLower),
|
200
|
+
// 4. Current working directory/name
|
201
|
+
join(process.cwd(), functionNameLower),
|
202
|
+
].filter((val): val is string => val !== undefined);
|
203
|
+
|
204
|
+
MessageFormatter.info(`🔍 Priority locations to check:`, { prefix: "Functions" });
|
205
|
+
priorityLocations.forEach((loc, i) => {
|
206
|
+
MessageFormatter.info(` ${i + 1}. ${loc}`, { prefix: "Functions" });
|
207
|
+
});
|
208
|
+
|
209
|
+
let functionPath: string | null = null;
|
210
|
+
|
211
|
+
// Check each priority location
|
212
|
+
for (const location of priorityLocations) {
|
213
|
+
MessageFormatter.info(` Checking: ${location} - ${fs.existsSync(location) ? 'EXISTS' : 'NOT FOUND'}`, { prefix: "Functions" });
|
214
|
+
if (fs.existsSync(location)) {
|
215
|
+
MessageFormatter.success(`✅ Found function at: ${location}`, { prefix: "Functions" });
|
216
|
+
functionPath = location;
|
217
|
+
break;
|
218
|
+
}
|
219
|
+
}
|
220
|
+
|
221
|
+
// If not found in priority locations, do a broader search
|
222
|
+
if (!functionPath) {
|
223
|
+
MessageFormatter.info(`Function not found in primary locations, searching subdirectories...`, { prefix: "Functions" });
|
224
|
+
|
225
|
+
// Search in both appwrite config directory and current working directory
|
226
|
+
functionPath = await (cli as any).findFunctionInSubdirectories(
|
227
|
+
[(cli as any).controller.getAppwriteFolderPath()!, process.cwd()],
|
228
|
+
functionNameLower
|
229
|
+
);
|
230
|
+
}
|
231
|
+
|
232
|
+
if (!functionPath) {
|
233
|
+
const { shouldDownload } = await inquirer.prompt([
|
234
|
+
{
|
235
|
+
type: "confirm",
|
236
|
+
name: "shouldDownload",
|
237
|
+
message:
|
238
|
+
"Function not found locally. Would you like to download the latest deployment?",
|
239
|
+
default: false,
|
240
|
+
},
|
241
|
+
]);
|
242
|
+
|
243
|
+
if (shouldDownload) {
|
244
|
+
try {
|
245
|
+
MessageFormatter.progress("Downloading latest deployment...", { prefix: "Functions" });
|
246
|
+
const { path: downloadedPath, function: remoteFunction } =
|
247
|
+
await downloadLatestFunctionDeployment(
|
248
|
+
(cli as any).controller.appwriteServer!,
|
249
|
+
functionConfig.$id,
|
250
|
+
join((cli as any).controller.getAppwriteFolderPath()!, "functions")
|
251
|
+
);
|
252
|
+
MessageFormatter.success(`✨ Function downloaded to ${downloadedPath}`, { prefix: "Functions" });
|
253
|
+
|
254
|
+
functionPath = downloadedPath;
|
255
|
+
functionConfig.dirPath = downloadedPath;
|
256
|
+
|
257
|
+
const existingIndex = (cli as any).controller.config.functions.findIndex(
|
258
|
+
(f: any) => f?.$id === remoteFunction.$id
|
259
|
+
);
|
260
|
+
|
261
|
+
if (existingIndex >= 0) {
|
262
|
+
(cli as any).controller.config.functions[existingIndex].dirPath =
|
263
|
+
downloadedPath;
|
264
|
+
}
|
265
|
+
|
266
|
+
await (cli as any).reloadConfigWithSessionPreservation();
|
267
|
+
} catch (error) {
|
268
|
+
MessageFormatter.error("Failed to download function deployment", error instanceof Error ? error : new Error(String(error)), { prefix: "Functions" });
|
269
|
+
return;
|
270
|
+
}
|
271
|
+
} else {
|
272
|
+
MessageFormatter.error(`Function ${functionConfig.name} not found locally. Cannot deploy.`, undefined, { prefix: "Functions" });
|
273
|
+
return;
|
274
|
+
}
|
275
|
+
}
|
276
|
+
|
277
|
+
if (!(cli as any).controller.appwriteServer) {
|
278
|
+
MessageFormatter.error("Appwrite server not initialized", undefined, { prefix: "Functions" });
|
279
|
+
return;
|
280
|
+
}
|
281
|
+
|
282
|
+
try {
|
283
|
+
await deployLocalFunction(
|
284
|
+
(cli as any).controller.appwriteServer,
|
285
|
+
functionConfig.name,
|
286
|
+
{
|
287
|
+
...functionConfig,
|
288
|
+
dirPath: functionPath,
|
289
|
+
},
|
290
|
+
functionPath
|
291
|
+
);
|
292
|
+
MessageFormatter.success("Function deployed successfully!", { prefix: "Functions" });
|
293
|
+
} catch (error) {
|
294
|
+
MessageFormatter.error("Failed to deploy function", error instanceof Error ? error : new Error(String(error)), { prefix: "Functions" });
|
295
|
+
}
|
296
|
+
}
|
297
|
+
},
|
298
|
+
|
299
|
+
async deleteFunction(cli: InteractiveCLI): Promise<void> {
|
300
|
+
const functions = await (cli as any).selectFunctions(
|
301
|
+
"Select functions to delete:",
|
302
|
+
true,
|
303
|
+
false
|
304
|
+
);
|
305
|
+
|
306
|
+
if (!functions.length) {
|
307
|
+
MessageFormatter.error("No functions selected", undefined, { prefix: "Functions" });
|
308
|
+
return;
|
309
|
+
}
|
310
|
+
|
311
|
+
for (const func of functions) {
|
312
|
+
try {
|
313
|
+
await deleteFunction((cli as any).controller!.appwriteServer!, func.$id);
|
314
|
+
MessageFormatter.success(`✨ Function ${func.name} deleted successfully!`, { prefix: "Functions" });
|
315
|
+
} catch (error) {
|
316
|
+
MessageFormatter.error(`Failed to delete function ${func.name}`, error instanceof Error ? error : new Error(String(error)), { prefix: "Functions" });
|
317
|
+
}
|
318
|
+
}
|
319
|
+
},
|
320
|
+
|
321
|
+
async updateFunctionSpec(cli: InteractiveCLI): Promise<void> {
|
322
|
+
const remoteFunctions = await listFunctions(
|
323
|
+
(cli as any).controller!.appwriteServer!,
|
324
|
+
[Query.limit(1000)]
|
325
|
+
);
|
326
|
+
const localFunctions = (cli as any).getLocalFunctions();
|
327
|
+
|
328
|
+
const allFunctions = [
|
329
|
+
...remoteFunctions.functions,
|
330
|
+
...localFunctions.filter(
|
331
|
+
(f: any) => !remoteFunctions.functions.some((rf: any) => rf.name === f.name)
|
332
|
+
),
|
333
|
+
];
|
334
|
+
|
335
|
+
const functionsToUpdate = await inquirer.prompt([
|
336
|
+
{
|
337
|
+
type: "checkbox",
|
338
|
+
name: "functionId",
|
339
|
+
message: "Select functions to update:",
|
340
|
+
choices: allFunctions.map((f: any) => ({
|
341
|
+
name: `${f.name} (${f.$id})${
|
342
|
+
localFunctions.some((lf: any) => lf.name === f.name)
|
343
|
+
? " (Local)"
|
344
|
+
: " (Remote)"
|
345
|
+
}`,
|
346
|
+
value: f.$id,
|
347
|
+
})),
|
348
|
+
loop: true,
|
349
|
+
},
|
350
|
+
]);
|
351
|
+
|
352
|
+
const specifications = await listSpecifications(
|
353
|
+
(cli as any).controller!.appwriteServer!
|
354
|
+
);
|
355
|
+
const { specification } = await inquirer.prompt([
|
356
|
+
{
|
357
|
+
type: "list",
|
358
|
+
name: "specification",
|
359
|
+
message: "Select new specification:",
|
360
|
+
choices: specifications.specifications.map((s: any) => ({
|
361
|
+
name: `${s.slug}`,
|
362
|
+
value: s.slug,
|
363
|
+
})),
|
364
|
+
},
|
365
|
+
]);
|
366
|
+
|
367
|
+
try {
|
368
|
+
for (const functionId of functionsToUpdate.functionId) {
|
369
|
+
await (cli as any).controller!.updateFunctionSpecifications(
|
370
|
+
functionId,
|
371
|
+
specification
|
372
|
+
);
|
373
|
+
MessageFormatter.success(`Successfully updated function specification to ${specification}`, { prefix: "Functions" });
|
374
|
+
}
|
375
|
+
} catch (error) {
|
376
|
+
MessageFormatter.error("Error updating function specification", error instanceof Error ? error : new Error(String(error)), { prefix: "Functions" });
|
377
|
+
}
|
378
|
+
}
|
379
|
+
};
|
@@ -0,0 +1,163 @@
|
|
1
|
+
import inquirer from "inquirer";
|
2
|
+
import path from "path";
|
3
|
+
import chalk from "chalk";
|
4
|
+
import { MessageFormatter } from "../../shared/messageFormatter.js";
|
5
|
+
import { SchemaGenerator } from "../../shared/schemaGenerator.js";
|
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: "Both TypeScript and JSON schemas", value: "both" },
|
24
|
+
],
|
25
|
+
default: "both",
|
26
|
+
},
|
27
|
+
]);
|
28
|
+
|
29
|
+
// Get the config folder path (where the config file is located)
|
30
|
+
const configFolderPath = (cli as any).controller!.getAppwriteFolderPath();
|
31
|
+
if (!configFolderPath) {
|
32
|
+
MessageFormatter.error("Failed to get config folder path", undefined, { prefix: "Schemas" });
|
33
|
+
return;
|
34
|
+
}
|
35
|
+
|
36
|
+
// Create SchemaGenerator with the correct base path and generate schemas
|
37
|
+
const schemaGenerator = new SchemaGenerator((cli as any).controller!.config!, configFolderPath);
|
38
|
+
schemaGenerator.generateSchemas({ format: schemaType, verbose: true });
|
39
|
+
|
40
|
+
MessageFormatter.success("Schema generation completed", { prefix: "Schemas" });
|
41
|
+
},
|
42
|
+
|
43
|
+
async generateConstants(cli: InteractiveCLI): Promise<void> {
|
44
|
+
MessageFormatter.progress("Generating cross-language constants...", { prefix: "Constants" });
|
45
|
+
|
46
|
+
if (!(cli as any).controller?.config) {
|
47
|
+
MessageFormatter.error("No configuration found", undefined, { prefix: "Constants" });
|
48
|
+
return;
|
49
|
+
}
|
50
|
+
|
51
|
+
// Prompt for languages
|
52
|
+
const { languages } = await inquirer.prompt([
|
53
|
+
{
|
54
|
+
type: "checkbox",
|
55
|
+
name: "languages",
|
56
|
+
message: "Select languages for constants generation:",
|
57
|
+
choices: [
|
58
|
+
{ name: "TypeScript", value: "typescript", checked: true },
|
59
|
+
{ name: "JavaScript", value: "javascript" },
|
60
|
+
{ name: "Python", value: "python" },
|
61
|
+
{ name: "PHP", value: "php" },
|
62
|
+
{ name: "Dart", value: "dart" },
|
63
|
+
{ name: "JSON", value: "json" },
|
64
|
+
{ name: "Environment Variables", value: "env" },
|
65
|
+
],
|
66
|
+
validate: (input) => {
|
67
|
+
if (input.length === 0) {
|
68
|
+
return "Please select at least one language";
|
69
|
+
}
|
70
|
+
return true;
|
71
|
+
},
|
72
|
+
},
|
73
|
+
]);
|
74
|
+
|
75
|
+
// Determine default output directory based on config location
|
76
|
+
const configPath = (cli as any).controller!.getAppwriteFolderPath();
|
77
|
+
const defaultOutputDir = configPath
|
78
|
+
? path.join(configPath, "constants")
|
79
|
+
: path.join(process.cwd(), "constants");
|
80
|
+
|
81
|
+
// Prompt for output directory
|
82
|
+
const { outputDir } = await inquirer.prompt([
|
83
|
+
{
|
84
|
+
type: "input",
|
85
|
+
name: "outputDir",
|
86
|
+
message: "Output directory for constants files:",
|
87
|
+
default: defaultOutputDir,
|
88
|
+
validate: (input) => {
|
89
|
+
if (!input.trim()) {
|
90
|
+
return "Output directory cannot be empty";
|
91
|
+
}
|
92
|
+
return true;
|
93
|
+
},
|
94
|
+
},
|
95
|
+
]);
|
96
|
+
|
97
|
+
try {
|
98
|
+
const { ConstantsGenerator } = await import("../../utils/constantsGenerator.js");
|
99
|
+
const generator = new ConstantsGenerator((cli as any).controller.config);
|
100
|
+
|
101
|
+
MessageFormatter.info(`Generating constants for: ${languages.join(", ")}`, { prefix: "Constants" });
|
102
|
+
await generator.generateFiles(languages, outputDir);
|
103
|
+
|
104
|
+
MessageFormatter.success(`Constants generated in ${outputDir}`, { prefix: "Constants" });
|
105
|
+
} catch (error) {
|
106
|
+
MessageFormatter.error("Failed to generate constants", error instanceof Error ? error : new Error(String(error)), { prefix: "Constants" });
|
107
|
+
}
|
108
|
+
},
|
109
|
+
|
110
|
+
async importData(cli: InteractiveCLI): Promise<void> {
|
111
|
+
MessageFormatter.progress("Importing data...", { prefix: "Import" });
|
112
|
+
|
113
|
+
const { doBackup } = await inquirer.prompt([
|
114
|
+
{
|
115
|
+
type: "confirm",
|
116
|
+
name: "doBackup",
|
117
|
+
message: "Do you want to perform a backup before importing?",
|
118
|
+
default: true,
|
119
|
+
},
|
120
|
+
]);
|
121
|
+
|
122
|
+
const databases = await (cli as any).selectDatabases(
|
123
|
+
await fetchAllDatabases((cli as any).controller!.database!),
|
124
|
+
"Select databases to import data into:",
|
125
|
+
true
|
126
|
+
);
|
127
|
+
|
128
|
+
const collections = await (cli as any).selectCollectionsAndTables(
|
129
|
+
databases[0],
|
130
|
+
(cli as any).controller!.database!,
|
131
|
+
"Select collections/tables to import data into (leave empty for all):",
|
132
|
+
true
|
133
|
+
);
|
134
|
+
|
135
|
+
const { shouldWriteFile } = await inquirer.prompt([
|
136
|
+
{
|
137
|
+
type: "confirm",
|
138
|
+
name: "shouldWriteFile",
|
139
|
+
message: "Do you want to write the imported data to a file?",
|
140
|
+
default: false,
|
141
|
+
},
|
142
|
+
]);
|
143
|
+
|
144
|
+
const options = {
|
145
|
+
databases,
|
146
|
+
collections: collections.map((c: any) => c.name),
|
147
|
+
doBackup,
|
148
|
+
importData: true,
|
149
|
+
shouldWriteFile,
|
150
|
+
};
|
151
|
+
|
152
|
+
try {
|
153
|
+
await (cli as any).controller!.importData(options);
|
154
|
+
MessageFormatter.success("Data import completed successfully", { prefix: "Import" });
|
155
|
+
} catch (error) {
|
156
|
+
MessageFormatter.error("Error importing data", error instanceof Error ? error : new Error(String(error)), { prefix: "Import" });
|
157
|
+
}
|
158
|
+
},
|
159
|
+
|
160
|
+
async setupDirsFiles(cli: InteractiveCLI, withExampleData: boolean = false): Promise<void> {
|
161
|
+
await setupDirsFiles(withExampleData, (cli as any).currentDir);
|
162
|
+
}
|
163
|
+
};
|