appwrite-utils-cli 0.9.993 → 0.9.994
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/README.md +1 -2
- package/dist/collections/methods.js +6 -4
- package/dist/functions/deployments.d.ts +4 -0
- package/dist/functions/deployments.js +114 -0
- package/dist/functions/methods.d.ts +13 -8
- package/dist/functions/methods.js +74 -20
- package/dist/functions/templates/count-docs-in-collection/src/main.d.ts +21 -0
- package/dist/functions/templates/count-docs-in-collection/src/main.js +114 -0
- package/dist/functions/templates/count-docs-in-collection/src/request.d.ts +15 -0
- package/dist/functions/templates/count-docs-in-collection/src/request.js +6 -0
- package/dist/functions/templates/typescript-node/src/index.d.ts +11 -0
- package/dist/functions/templates/typescript-node/src/index.js +11 -0
- package/dist/interactiveCLI.d.ts +6 -0
- package/dist/interactiveCLI.js +437 -32
- package/dist/main.js +0 -0
- package/dist/migrations/appwriteToX.js +32 -1
- package/dist/migrations/schemaStrings.d.ts +1 -0
- package/dist/migrations/schemaStrings.js +74 -2
- package/dist/migrations/transfer.js +112 -123
- package/dist/utils/loadConfigs.d.ts +1 -0
- package/dist/utils/loadConfigs.js +19 -0
- package/dist/utils/schemaStrings.js +27 -0
- package/dist/utilsController.d.ts +5 -1
- package/dist/utilsController.js +54 -2
- package/package.json +57 -55
- package/src/collections/methods.ts +29 -10
- package/src/functions/deployments.ts +190 -0
- package/src/functions/methods.ts +295 -235
- package/src/functions/templates/count-docs-in-collection/README.md +54 -0
- package/src/functions/templates/count-docs-in-collection/src/main.ts +159 -0
- package/src/functions/templates/count-docs-in-collection/src/request.ts +9 -0
- package/src/functions/templates/poetry/README.md +30 -0
- package/src/functions/templates/poetry/pyproject.toml +16 -0
- package/src/functions/templates/poetry/src/__init__.py +0 -0
- package/src/functions/templates/poetry/src/index.py +16 -0
- package/src/functions/templates/typescript-node/README.md +32 -0
- package/src/functions/templates/typescript-node/src/index.ts +23 -0
- package/src/interactiveCLI.ts +606 -47
- package/src/migrations/appwriteToX.ts +44 -1
- package/src/migrations/schemaStrings.ts +83 -2
- package/src/migrations/transfer.ts +280 -207
- package/src/setupController.ts +41 -41
- package/src/utils/loadConfigs.ts +24 -0
- package/src/utils/schemaStrings.ts +27 -0
- package/src/utilsController.ts +63 -3
- package/tsconfig.json +8 -1
package/src/utils/loadConfigs.ts
CHANGED
@@ -3,6 +3,7 @@ import fs from "fs";
|
|
3
3
|
import { type AppwriteConfig, type Collection } from "appwrite-utils";
|
4
4
|
import { register } from "tsx/esm/api"; // Import the register function
|
5
5
|
import { pathToFileURL } from "node:url";
|
6
|
+
import chalk from "chalk";
|
6
7
|
|
7
8
|
/**
|
8
9
|
* Recursively searches for a file named 'appwriteConfig.ts' starting from the given directory.
|
@@ -73,3 +74,26 @@ export const loadConfig = async (
|
|
73
74
|
unregister(); // Unregister tsx when done
|
74
75
|
}
|
75
76
|
};
|
77
|
+
|
78
|
+
export const findFunctionsDir = (dir: string): string | null => {
|
79
|
+
if (dir === "node_modules") {
|
80
|
+
return null;
|
81
|
+
}
|
82
|
+
|
83
|
+
const files = fs.readdirSync(dir, { withFileTypes: true });
|
84
|
+
|
85
|
+
for (const entry of files) {
|
86
|
+
if (!entry.isDirectory() || entry.name === "node_modules") {
|
87
|
+
continue;
|
88
|
+
}
|
89
|
+
|
90
|
+
if (entry.name === "functions") {
|
91
|
+
return path.join(dir, entry.name);
|
92
|
+
}
|
93
|
+
|
94
|
+
const result = findFunctionsDir(path.join(dir, entry.name));
|
95
|
+
if (result) return result;
|
96
|
+
}
|
97
|
+
|
98
|
+
return null;
|
99
|
+
};
|
@@ -9,6 +9,8 @@ import { z } from "zod";
|
|
9
9
|
import fs from "fs";
|
10
10
|
import path from "path";
|
11
11
|
import { dump } from "js-yaml";
|
12
|
+
import { findFunctionsDir } from "./loadConfigs.js";
|
13
|
+
import { ulid } from "ulidx";
|
12
14
|
// import { getClientFromConfig } from "./getClientFromConfig.js";
|
13
15
|
|
14
16
|
interface RelationshipDetail {
|
@@ -33,7 +35,9 @@ export class SchemaGenerator {
|
|
33
35
|
|
34
36
|
public updateTsSchemas(): void {
|
35
37
|
const collections = this.config.collections;
|
38
|
+
const functions = this.config.functions || [];
|
36
39
|
delete this.config.collections;
|
40
|
+
delete this.config.functions;
|
37
41
|
|
38
42
|
const configPath = path.join(this.appwriteFolderPath, "appwriteConfig.ts");
|
39
43
|
const configContent = `import { type AppwriteConfig } from "appwrite-utils";
|
@@ -51,6 +55,29 @@ export class SchemaGenerator {
|
|
51
55
|
usersCollectionName: "${this.config.usersCollectionName}",
|
52
56
|
databases: ${JSON.stringify(this.config.databases)},
|
53
57
|
buckets: ${JSON.stringify(this.config.buckets)},
|
58
|
+
functions: ${JSON.stringify(functions.map(func => ({
|
59
|
+
functionId: func.$id || ulid(),
|
60
|
+
name: func.name,
|
61
|
+
runtime: func.runtime,
|
62
|
+
path: func.dirPath || `functions/${func.name}`,
|
63
|
+
entrypoint: func.entrypoint || 'src/index.ts',
|
64
|
+
execute: func.execute,
|
65
|
+
events: func.events || [],
|
66
|
+
schedule: func.schedule || '',
|
67
|
+
timeout: func.timeout || 15,
|
68
|
+
enabled: func.enabled !== false,
|
69
|
+
logging: func.logging !== false,
|
70
|
+
commands: func.commands || 'npm install',
|
71
|
+
scopes: func.scopes || [],
|
72
|
+
installationId: func.installationId,
|
73
|
+
providerRepositoryId: func.providerRepositoryId,
|
74
|
+
providerBranch: func.providerBranch,
|
75
|
+
providerSilentMode: func.providerSilentMode,
|
76
|
+
providerRootDirectory: func.providerRootDirectory,
|
77
|
+
specification: func.specification,
|
78
|
+
...(func.predeployCommands ? { predeployCommands: func.predeployCommands } : {}),
|
79
|
+
...(func.deployDir ? { deployDir: func.deployDir } : {})
|
80
|
+
})), null, 2)}
|
54
81
|
};
|
55
82
|
|
56
83
|
export default appwriteConfig;
|
package/src/utilsController.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { Client, Databases, Query, Storage, type Models } from "node-appwrite";
|
2
|
-
import { type AppwriteConfig, type Specification } from "appwrite-utils";
|
3
|
-
import { loadConfig, findAppwriteConfig } from "./utils/loadConfigs.js";
|
2
|
+
import { type AppwriteConfig, type AppwriteFunction, type Specification } from "appwrite-utils";
|
3
|
+
import { loadConfig, findAppwriteConfig, findFunctionsDir } from "./utils/loadConfigs.js";
|
4
4
|
import { UsersController } from "./migrations/users.js";
|
5
5
|
import { AppwriteToX } from "./migrations/appwriteToX.js";
|
6
6
|
import { ImportController } from "./migrations/importController.js";
|
@@ -42,8 +42,10 @@ import {
|
|
42
42
|
} from "./migrations/transfer.js";
|
43
43
|
import { getClient } from "./utils/getClientFromConfig.js";
|
44
44
|
import { fetchAllDatabases } from "./migrations/databases.js";
|
45
|
-
import { updateFunctionSpecifications } from "./functions/methods.js";
|
45
|
+
import { listFunctions, updateFunctionSpecifications } from "./functions/methods.js";
|
46
46
|
import chalk from "chalk";
|
47
|
+
import { deployLocalFunction } from "./functions/deployments.js";
|
48
|
+
import fs from "node:fs";
|
47
49
|
|
48
50
|
export interface SetupOptions {
|
49
51
|
databases?: Models.Database[];
|
@@ -181,6 +183,64 @@ export class UtilsController {
|
|
181
183
|
);
|
182
184
|
}
|
183
185
|
|
186
|
+
async listAllFunctions() {
|
187
|
+
await this.init();
|
188
|
+
if (!this.appwriteServer) throw new Error("Appwrite server not initialized");
|
189
|
+
const { functions } = await listFunctions(this.appwriteServer, [Query.limit(1000)]);
|
190
|
+
return functions;
|
191
|
+
}
|
192
|
+
|
193
|
+
async findFunctionDirectories() {
|
194
|
+
const functionsDir = findFunctionsDir(this.appwriteFolderPath);
|
195
|
+
if (!functionsDir) return new Map();
|
196
|
+
|
197
|
+
const functionDirMap = new Map<string, string>();
|
198
|
+
const entries = fs.readdirSync(functionsDir, { withFileTypes: true });
|
199
|
+
|
200
|
+
for (const entry of entries) {
|
201
|
+
if (entry.isDirectory()) {
|
202
|
+
const functionPath = path.join(functionsDir, entry.name);
|
203
|
+
// Match with config functions by name
|
204
|
+
if (this.config?.functions) {
|
205
|
+
const matchingFunc = this.config.functions.find(
|
206
|
+
f => f.name.toLowerCase() === entry.name.toLowerCase()
|
207
|
+
);
|
208
|
+
if (matchingFunc) {
|
209
|
+
functionDirMap.set(matchingFunc.name, functionPath);
|
210
|
+
}
|
211
|
+
}
|
212
|
+
}
|
213
|
+
}
|
214
|
+
return functionDirMap;
|
215
|
+
}
|
216
|
+
|
217
|
+
async deployFunction(functionName: string, functionPath?: string, functionConfig?: AppwriteFunction) {
|
218
|
+
await this.init();
|
219
|
+
if (!this.appwriteServer) throw new Error("Appwrite server not initialized");
|
220
|
+
|
221
|
+
if (!functionConfig) {
|
222
|
+
functionConfig = this.config?.functions?.find(f => f.name === functionName);
|
223
|
+
}
|
224
|
+
if (!functionConfig) throw new Error(`Function ${functionName} not found in config`);
|
225
|
+
|
226
|
+
await deployLocalFunction(this.appwriteServer, functionName, functionConfig, functionPath);
|
227
|
+
}
|
228
|
+
|
229
|
+
async syncFunctions() {
|
230
|
+
await this.init();
|
231
|
+
if (!this.appwriteServer) throw new Error("Appwrite server not initialized");
|
232
|
+
|
233
|
+
const localFunctions = this.config?.functions || [];
|
234
|
+
const remoteFunctions = await listFunctions(this.appwriteServer, [Query.limit(1000)]);
|
235
|
+
|
236
|
+
for (const localFunction of localFunctions) {
|
237
|
+
console.log(chalk.blue(`Syncing function ${localFunction.name}...`));
|
238
|
+
await this.deployFunction(localFunction.name);
|
239
|
+
}
|
240
|
+
|
241
|
+
console.log(chalk.green("✨ All functions synchronized successfully!"));
|
242
|
+
}
|
243
|
+
|
184
244
|
async wipeDatabase(database: Models.Database, wipeBucket: boolean = false) {
|
185
245
|
await this.init();
|
186
246
|
if (!this.database) throw new Error("Database not initialized");
|
package/tsconfig.json
CHANGED
@@ -33,5 +33,12 @@
|
|
33
33
|
"declaration": true
|
34
34
|
},
|
35
35
|
"include": ["src/**/*"],
|
36
|
-
"exclude": [
|
36
|
+
"exclude": [
|
37
|
+
"node_modules",
|
38
|
+
"dist",
|
39
|
+
"src/appwrite",
|
40
|
+
"src/functions/templates",
|
41
|
+
"src/_test/appwrite",
|
42
|
+
"example/*"
|
43
|
+
]
|
37
44
|
}
|