appwrite-utils-cli 0.9.993 → 0.9.995

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 (46) hide show
  1. package/README.md +1 -2
  2. package/dist/collections/methods.js +6 -4
  3. package/dist/functions/deployments.d.ts +4 -0
  4. package/dist/functions/deployments.js +114 -0
  5. package/dist/functions/methods.d.ts +13 -8
  6. package/dist/functions/methods.js +74 -20
  7. package/dist/functions/templates/count-docs-in-collection/src/main.d.ts +21 -0
  8. package/dist/functions/templates/count-docs-in-collection/src/main.js +114 -0
  9. package/dist/functions/templates/count-docs-in-collection/src/request.d.ts +15 -0
  10. package/dist/functions/templates/count-docs-in-collection/src/request.js +6 -0
  11. package/dist/functions/templates/typescript-node/src/index.d.ts +11 -0
  12. package/dist/functions/templates/typescript-node/src/index.js +11 -0
  13. package/dist/interactiveCLI.d.ts +6 -0
  14. package/dist/interactiveCLI.js +437 -32
  15. package/dist/main.js +0 -0
  16. package/dist/migrations/appwriteToX.js +32 -1
  17. package/dist/migrations/schemaStrings.d.ts +1 -0
  18. package/dist/migrations/schemaStrings.js +74 -2
  19. package/dist/migrations/transfer.js +112 -123
  20. package/dist/utils/loadConfigs.d.ts +1 -0
  21. package/dist/utils/loadConfigs.js +19 -0
  22. package/dist/utils/schemaStrings.js +27 -0
  23. package/dist/utilsController.d.ts +5 -1
  24. package/dist/utilsController.js +54 -2
  25. package/package.json +57 -55
  26. package/src/collections/methods.ts +29 -10
  27. package/src/functions/deployments.ts +190 -0
  28. package/src/functions/methods.ts +295 -235
  29. package/src/functions/templates/count-docs-in-collection/README.md +54 -0
  30. package/src/functions/templates/count-docs-in-collection/src/main.ts +159 -0
  31. package/src/functions/templates/count-docs-in-collection/src/request.ts +9 -0
  32. package/src/functions/templates/poetry/README.md +30 -0
  33. package/src/functions/templates/poetry/pyproject.toml +16 -0
  34. package/src/functions/templates/poetry/src/__init__.py +0 -0
  35. package/src/functions/templates/poetry/src/index.py +16 -0
  36. package/src/functions/templates/typescript-node/README.md +32 -0
  37. package/src/functions/templates/typescript-node/src/index.ts +23 -0
  38. package/src/interactiveCLI.ts +606 -47
  39. package/src/migrations/appwriteToX.ts +44 -1
  40. package/src/migrations/schemaStrings.ts +83 -2
  41. package/src/migrations/transfer.ts +280 -207
  42. package/src/setupController.ts +41 -41
  43. package/src/utils/loadConfigs.ts +24 -0
  44. package/src/utils/schemaStrings.ts +27 -0
  45. package/src/utilsController.ts +63 -3
  46. package/tsconfig.json +8 -1
@@ -21,9 +21,12 @@ import {
21
21
  attributesSchema,
22
22
  indexesSchema,
23
23
  parseAttribute,
24
+ type Runtime,
25
+ type Specification,
24
26
  } from "appwrite-utils";
25
27
  import { getDatabaseFromConfig } from "./afterImportActions.js";
26
28
  import { listBuckets } from "../storage/methods.js";
29
+ import { listFunctions } from "../functions/methods.js";
27
30
 
28
31
  export class AppwriteToX {
29
32
  config: AppwriteConfig;
@@ -222,7 +225,47 @@ export class AppwriteToX {
222
225
  antivirus: bucket.antivirus,
223
226
  }));
224
227
 
225
- this.updatedConfig = updatedConfig;
228
+ const remoteFunctions = await listFunctions(this.config.appwriteClient!, [
229
+ Query.limit(1000),
230
+ ]);
231
+ const functionDeployments = await Promise.all(
232
+ remoteFunctions.functions.map(async (func) => {
233
+ const deployments =
234
+ await this.config.appwriteClient!.functions.listDeployments(
235
+ func.$id,
236
+ [Query.orderDesc("$createdAt"), Query.limit(1)]
237
+ );
238
+ return {
239
+ function: func,
240
+ schemaStrings: deployments.deployments[0]?.schemaStrings || [],
241
+ };
242
+ })
243
+ );
244
+
245
+ this.updatedConfig.functions = functionDeployments.map(
246
+ ({ function: func, schemaStrings }) => ({
247
+ $id: func.$id,
248
+ name: func.name,
249
+ runtime: func.runtime as Runtime,
250
+ execute: func.execute,
251
+ events: func.events || [],
252
+ schedule: func.schedule || "",
253
+ timeout: func.timeout || 15,
254
+ enabled: func.enabled !== false,
255
+ logging: func.logging !== false,
256
+ entrypoint: func.entrypoint || "src/index.ts",
257
+ commands: func.commands || "npm install",
258
+ dirPath: `functions/${func.name}`,
259
+ specification: func.specification as Specification,
260
+ schemaStrings,
261
+ })
262
+ );
263
+
264
+ // Make sure to update the config with all changes
265
+ this.updatedConfig = {
266
+ ...updatedConfig,
267
+ functions: this.updatedConfig.functions,
268
+ };
226
269
  }
227
270
 
228
271
  async toSchemas(databases?: Models.Database[]) {
@@ -9,6 +9,7 @@ import fs from "fs";
9
9
  import path from "path";
10
10
  import { dump } from "js-yaml";
11
11
  import { getDatabaseFromConfig } from "./afterImportActions.js";
12
+ import { ulid } from "ulidx";
12
13
 
13
14
  interface RelationshipDetail {
14
15
  parentCollection: string;
@@ -32,7 +33,9 @@ export class SchemaGenerator {
32
33
 
33
34
  public updateTsSchemas(): void {
34
35
  const collections = this.config.collections;
36
+ const functions = this.config.functions || [];
35
37
  delete this.config.collections;
38
+ delete this.config.functions;
36
39
 
37
40
  const configPath = path.join(this.appwriteFolderPath, "appwriteConfig.ts");
38
41
  const configContent = `import { type AppwriteConfig } from "appwrite-utils";
@@ -48,8 +51,37 @@ export class SchemaGenerator {
48
51
  enableMockData: ${this.config.enableMockData},
49
52
  documentBucketId: "${this.config.documentBucketId}",
50
53
  usersCollectionName: "${this.config.usersCollectionName}",
51
- databases: ${JSON.stringify(this.config.databases)},
52
- buckets: ${JSON.stringify(this.config.buckets)}
54
+ databases: ${JSON.stringify(this.config.databases, null, 4)},
55
+ buckets: ${JSON.stringify(this.config.buckets, null, 4)},
56
+ functions: ${JSON.stringify(
57
+ functions.map((func) => ({
58
+ functionId: func.$id || ulid(),
59
+ name: func.name,
60
+ runtime: func.runtime,
61
+ path: func.dirPath || `functions/${func.name}`,
62
+ entrypoint: func.entrypoint || "src/index.ts",
63
+ execute: func.execute,
64
+ events: func.events || [],
65
+ schedule: func.schedule || "",
66
+ timeout: func.timeout || 15,
67
+ enabled: func.enabled !== false,
68
+ logging: func.logging !== false,
69
+ commands: func.commands || "npm install",
70
+ scopes: func.scopes || [],
71
+ installationId: func.installationId,
72
+ providerRepositoryId: func.providerRepositoryId,
73
+ providerBranch: func.providerBranch,
74
+ providerSilentMode: func.providerSilentMode,
75
+ providerRootDirectory: func.providerRootDirectory,
76
+ specification: func.specification,
77
+ ...(func.predeployCommands
78
+ ? { predeployCommands: func.predeployCommands }
79
+ : {}),
80
+ ...(func.deployDir ? { deployDir: func.deployDir } : {}),
81
+ })),
82
+ null,
83
+ 4
84
+ )}
53
85
  };
54
86
 
55
87
  export default appwriteConfig;
@@ -140,6 +172,55 @@ export class SchemaGenerator {
140
172
  });
141
173
  }
142
174
 
175
+ public updateConfig(config: AppwriteConfig): void {
176
+ const configPath = path.join(this.appwriteFolderPath, "appwriteConfig.ts");
177
+ const configContent = `import { type AppwriteConfig } from "appwrite-utils";
178
+
179
+ const appwriteConfig: AppwriteConfig = {
180
+ appwriteEndpoint: "${config.appwriteEndpoint}",
181
+ appwriteProject: "${config.appwriteProject}",
182
+ appwriteKey: "${config.appwriteKey}",
183
+ enableBackups: ${config.enableBackups},
184
+ backupInterval: ${config.backupInterval},
185
+ backupRetention: ${config.backupRetention},
186
+ enableBackupCleanup: ${config.enableBackupCleanup},
187
+ enableMockData: ${config.enableMockData},
188
+ documentBucketId: "${config.documentBucketId}",
189
+ usersCollectionName: "${config.usersCollectionName}",
190
+ databases: ${JSON.stringify(config.databases, null, 4)},
191
+ buckets: ${JSON.stringify(config.buckets, null, 4)},
192
+ functions: ${JSON.stringify(
193
+ config.functions?.map((func) => ({
194
+ $id: func.$id || ulid(),
195
+ name: func.name,
196
+ runtime: func.runtime,
197
+ dirPath: func.dirPath || `functions/${func.name}`,
198
+ entrypoint: func.entrypoint || "src/index.ts",
199
+ execute: func.execute || [],
200
+ events: func.events || [],
201
+ schedule: func.schedule || "",
202
+ timeout: func.timeout || 15,
203
+ enabled: func.enabled !== false,
204
+ logging: func.logging !== false,
205
+ commands: func.commands || "npm install",
206
+ scopes: func.scopes || [],
207
+ installationId: func.installationId,
208
+ providerRepositoryId: func.providerRepositoryId,
209
+ providerBranch: func.providerBranch,
210
+ providerSilentMode: func.providerSilentMode,
211
+ providerRootDirectory: func.providerRootDirectory,
212
+ specification: func.specification,
213
+ })),
214
+ null,
215
+ 4
216
+ )}
217
+ };
218
+
219
+ export default appwriteConfig;
220
+ `;
221
+ fs.writeFileSync(configPath, configContent, { encoding: "utf-8" });
222
+ }
223
+
143
224
  private extractRelationships(): void {
144
225
  if (!this.config.collections) {
145
226
  return;