appwrite-utils-cli 0.0.273 → 0.0.275
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 +5 -39
- package/dist/init.d.ts +2 -0
- package/dist/init.js +57 -0
- package/dist/main.js +62 -100
- package/dist/migrations/afterImportActions.d.ts +1 -4
- package/dist/migrations/afterImportActions.js +1 -0
- package/dist/migrations/appwriteToX.d.ts +46 -46
- package/dist/migrations/appwriteToX.js +6 -2
- package/dist/migrations/attributes.d.ts +1 -1
- package/dist/migrations/attributes.js +98 -70
- package/dist/migrations/backup.d.ts +240 -240
- package/dist/migrations/backup.js +1 -1
- package/dist/migrations/collections.d.ts +1 -1
- package/dist/migrations/collections.js +5 -5
- package/dist/migrations/converters.d.ts +9 -127
- package/dist/migrations/converters.js +1 -504
- package/dist/migrations/dataLoader.d.ts +470 -453
- package/dist/migrations/dataLoader.js +19 -1
- package/dist/migrations/dbHelpers.d.ts +1 -1
- package/dist/migrations/dbHelpers.js +3 -0
- package/dist/migrations/importController.d.ts +1 -1
- package/dist/migrations/importController.js +4 -7
- package/dist/migrations/importDataActions.d.ts +4 -6
- package/dist/migrations/importDataActions.js +6 -4
- package/dist/migrations/indexes.d.ts +1 -1
- package/dist/migrations/indexes.js +1 -1
- package/dist/migrations/migrationHelper.d.ts +29 -29
- package/dist/migrations/migrationHelper.js +1 -1
- package/dist/migrations/openapi.d.ts +1 -1
- package/dist/migrations/openapi.js +4 -1
- package/dist/migrations/queue.d.ts +1 -1
- package/dist/migrations/relationships.d.ts +5 -5
- package/dist/migrations/relationships.js +3 -0
- package/dist/migrations/schemaStrings.d.ts +2 -2
- package/dist/migrations/schemaStrings.js +93 -8
- package/dist/migrations/setupDatabase.d.ts +1 -1
- package/dist/migrations/setupDatabase.js +1 -1
- package/dist/migrations/storage.d.ts +1 -1
- package/dist/migrations/users.d.ts +1 -1
- package/dist/schemas/authUser.d.ts +12 -10
- package/dist/types.d.ts +0 -5
- package/dist/types.js +0 -2
- package/dist/utils/helperFunctions.d.ts +2 -3
- package/dist/utils/loadConfigs.d.ts +13 -0
- package/dist/utils/loadConfigs.js +47 -0
- package/dist/utils/setupFiles.d.ts +1 -0
- package/dist/utils/setupFiles.js +98 -223
- package/dist/utilsController.d.ts +1 -3
- package/dist/utilsController.js +14 -18
- package/package.json +9 -2
- package/src/init.ts +64 -0
- package/src/main.ts +73 -98
- package/src/migrations/afterImportActions.ts +1 -5
- package/src/migrations/appwriteToX.ts +6 -2
- package/src/migrations/attributes.ts +198 -145
- package/src/migrations/backup.ts +1 -1
- package/src/migrations/collections.ts +6 -12
- package/src/migrations/converters.ts +1 -540
- package/src/migrations/dataLoader.ts +19 -2
- package/src/migrations/dbHelpers.ts +4 -1
- package/src/migrations/importController.ts +5 -15
- package/src/migrations/importDataActions.ts +10 -14
- package/src/migrations/indexes.ts +1 -1
- package/src/migrations/migrationHelper.ts +1 -1
- package/src/migrations/openapi.ts +4 -1
- package/src/migrations/queue.ts +1 -1
- package/src/migrations/relationships.ts +4 -1
- package/src/migrations/schemaStrings.ts +106 -9
- package/src/migrations/setupDatabase.ts +1 -1
- package/src/migrations/storage.ts +1 -1
- package/src/migrations/users.ts +1 -1
- package/src/types.ts +0 -5
- package/src/utils/helperFunctions.ts +2 -3
- package/src/utils/loadConfigs.ts +55 -0
- package/src/utils/setupFiles.ts +114 -225
- package/src/utilsController.ts +27 -35
- package/src/migrations/schema.ts +0 -748
package/src/main.ts
CHANGED
@@ -1,106 +1,81 @@
|
|
1
1
|
#!/usr/bin/env node
|
2
|
+
import { program } from "commander";
|
2
3
|
import { UtilsController } from "./utilsController.js";
|
3
4
|
|
4
|
-
|
5
|
+
// Setup the main CLI program
|
6
|
+
program
|
7
|
+
.version("1.0.0")
|
8
|
+
.description("Utility CLI for Appwrite configurations and operations")
|
9
|
+
.option("--endpoint <endpoint>", "Set the Appwrite endpoint", undefined)
|
10
|
+
.option("--project <project>", "Set the Appwrite project ID", undefined)
|
11
|
+
.option("--key <key>", "Set the Appwrite API key", undefined)
|
12
|
+
.option("--backup", "Perform a backup before executing the command", false)
|
13
|
+
.option("--dev", "Run in development environment", false)
|
14
|
+
.option("--prod", "Run in production environment", false)
|
15
|
+
.option("--staging", "Run in staging environment", false)
|
16
|
+
.option("--sync", "Synchronize configurations", false)
|
17
|
+
.option("--wipe", "Wipe databases", false)
|
18
|
+
.option("--wipe-docs", "Wipe documents", false)
|
19
|
+
.option("--wipe-users", "Wipe users", false)
|
20
|
+
.option("--generate", "Generate schemas", false)
|
21
|
+
.option("--import", "Import data", false)
|
22
|
+
.option("--write-data", "Write data to file", false)
|
23
|
+
.option("-h, --help", "Display help for command", false);
|
5
24
|
|
6
|
-
|
25
|
+
program.on("--help", () => {
|
26
|
+
console.log("");
|
27
|
+
console.log("Examples:");
|
28
|
+
console.log(
|
29
|
+
" $ npx appwrite-utils-cli appwrite-migrate --sync --endpoint https://appwrite.example.com --project 123456 --key 7890"
|
30
|
+
);
|
31
|
+
console.log(
|
32
|
+
" $ npx appwrite-utils-cli appwrite-migrate --sync --dev --backup"
|
33
|
+
);
|
34
|
+
console.log(
|
35
|
+
" $ npx appwrite-utils-cli appwrite-migrate --wipe --wipe-docs --wipe-users --dev"
|
36
|
+
);
|
37
|
+
console.log(
|
38
|
+
" $ npx appwrite-utils-cli appwrite-migrate --generate --import --write-data --dev"
|
39
|
+
);
|
40
|
+
console.log(
|
41
|
+
" $ npx appwrite-utils-cli appwrite-migrate --sync --generate --import --write-data --dev --backup"
|
42
|
+
);
|
43
|
+
console.log(" $ npx appwrite-utils-cli appwrite-create");
|
44
|
+
console.log(
|
45
|
+
"For more information, visit https://github.com/zachhandley/appwrite-utils"
|
46
|
+
);
|
47
|
+
console.log("");
|
48
|
+
});
|
49
|
+
|
50
|
+
// Parse and handle options
|
51
|
+
program.action(async (options) => {
|
7
52
|
const controller = new UtilsController();
|
53
|
+
try {
|
54
|
+
// Convert Commander options to the format expected by UtilsController
|
55
|
+
const setupOptions = {
|
56
|
+
sync: options.sync,
|
57
|
+
runProd: options.prod,
|
58
|
+
runStaging: options.staging,
|
59
|
+
runDev: options.dev,
|
60
|
+
doBackup: options.backup,
|
61
|
+
wipeDatabases: options.wipe,
|
62
|
+
wipeDocumentStorage: options.wipeDocs,
|
63
|
+
wipeUsers: options.wipeUsers,
|
64
|
+
generateSchemas: options.generate,
|
65
|
+
generateMockData: false, // Assuming this needs to be set based on other conditions
|
66
|
+
importData: options.import,
|
67
|
+
checkDuplicates: false, // Assuming this needs to be set based on other conditions
|
68
|
+
shouldWriteFile: options.writeData,
|
69
|
+
endpoint: options.endpoint,
|
70
|
+
project: options.project,
|
71
|
+
key: options.key,
|
72
|
+
};
|
8
73
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
let doBackup = false;
|
14
|
-
let wipeDatabases = false;
|
15
|
-
let wipeUsers = false;
|
16
|
-
let generateSchemas = false;
|
17
|
-
let importData = false;
|
18
|
-
let wipeDocuments = false;
|
19
|
-
let shouldWriteFile = false;
|
20
|
-
let endpoint: string | undefined;
|
21
|
-
let project: string | undefined;
|
22
|
-
let key: string | undefined;
|
23
|
-
if (args.includes("--sync")) {
|
24
|
-
sync = true;
|
25
|
-
}
|
26
|
-
if (args.includes("--prod")) {
|
27
|
-
runProd = true;
|
28
|
-
}
|
29
|
-
if (args.includes("--staging")) {
|
30
|
-
runStaging = true;
|
31
|
-
}
|
32
|
-
if (args.includes("--dev")) {
|
33
|
-
runDev = true;
|
34
|
-
}
|
35
|
-
if (args.includes("--wipe")) {
|
36
|
-
wipeDatabases = true;
|
37
|
-
}
|
38
|
-
if (args.includes("--wipe-docs") || args.includes("--wipeDocs")) {
|
39
|
-
wipeDocuments = true;
|
40
|
-
}
|
41
|
-
if (args.includes("--generate")) {
|
42
|
-
generateSchemas = true;
|
43
|
-
}
|
44
|
-
if (args.includes("--import")) {
|
45
|
-
importData = true;
|
46
|
-
}
|
47
|
-
if (args.includes("--backup")) {
|
48
|
-
doBackup = true;
|
49
|
-
}
|
50
|
-
if (args.includes("--wipe-users") || args.includes("--wipeUsers")) {
|
51
|
-
wipeUsers = true;
|
52
|
-
}
|
53
|
-
if (args.includes("--write-data") || args.includes("--writeData")) {
|
54
|
-
shouldWriteFile = true;
|
55
|
-
}
|
56
|
-
if (args.includes("--endpoint")) {
|
57
|
-
endpoint = args[args.indexOf("--endpoint") + 1];
|
58
|
-
}
|
59
|
-
if (args.includes("--project")) {
|
60
|
-
project = args[args.indexOf("--project") + 1];
|
61
|
-
}
|
62
|
-
if (args.includes("--key")) {
|
63
|
-
key = args[args.indexOf("--key") + 1];
|
64
|
-
}
|
65
|
-
if (args.includes("--init")) {
|
66
|
-
await controller.run({
|
67
|
-
sync: sync,
|
68
|
-
runProd: runProd,
|
69
|
-
runStaging: runStaging,
|
70
|
-
runDev: runDev,
|
71
|
-
doBackup: doBackup,
|
72
|
-
wipeDatabases: wipeDatabases,
|
73
|
-
wipeUsers: wipeUsers,
|
74
|
-
wipeDocumentStorage: wipeDocuments,
|
75
|
-
generateSchemas: true,
|
76
|
-
generateMockData: false,
|
77
|
-
importData: false,
|
78
|
-
checkDuplicates: false,
|
79
|
-
shouldWriteFile: shouldWriteFile,
|
80
|
-
endpoint: endpoint,
|
81
|
-
project: project,
|
82
|
-
key: key,
|
83
|
-
});
|
84
|
-
} else {
|
85
|
-
await controller.run({
|
86
|
-
sync: sync,
|
87
|
-
runProd: runProd,
|
88
|
-
runStaging: runStaging,
|
89
|
-
runDev: runDev,
|
90
|
-
doBackup: doBackup,
|
91
|
-
wipeDatabases: wipeDatabases,
|
92
|
-
wipeDocumentStorage: wipeDocuments,
|
93
|
-
generateSchemas: generateSchemas,
|
94
|
-
generateMockData: false,
|
95
|
-
wipeUsers: wipeUsers,
|
96
|
-
importData: importData,
|
97
|
-
checkDuplicates: false,
|
98
|
-
shouldWriteFile: shouldWriteFile,
|
99
|
-
endpoint: endpoint,
|
100
|
-
project: project,
|
101
|
-
key: key,
|
102
|
-
});
|
74
|
+
await controller.run(setupOptions);
|
75
|
+
console.log("Operation completed successfully.");
|
76
|
+
} catch (error) {
|
77
|
+
console.error("Error during operation:", error);
|
103
78
|
}
|
104
|
-
}
|
79
|
+
});
|
105
80
|
|
106
|
-
|
81
|
+
program.parse(process.argv);
|
@@ -7,11 +7,11 @@ import {
|
|
7
7
|
type Models,
|
8
8
|
Client,
|
9
9
|
} from "node-appwrite";
|
10
|
-
import type { AppwriteConfig } from "./schema.js";
|
11
10
|
import path from "path";
|
12
11
|
import fs from "fs";
|
13
12
|
import os from "os";
|
14
13
|
import { logger } from "./logging.js";
|
14
|
+
import { type AfterImportActions, type AppwriteConfig } from "appwrite-utils";
|
15
15
|
|
16
16
|
export const getDatabaseFromConfig = (config: AppwriteConfig) => {
|
17
17
|
if (!config.appwriteClient) {
|
@@ -33,10 +33,6 @@ export const getStorageFromConfig = (config: AppwriteConfig) => {
|
|
33
33
|
return new Storage(config.appwriteClient!);
|
34
34
|
};
|
35
35
|
|
36
|
-
export interface AfterImportActions {
|
37
|
-
[key: string]: (config: AppwriteConfig, ...args: any[]) => Promise<any>;
|
38
|
-
}
|
39
|
-
|
40
36
|
export const afterImportActions = {
|
41
37
|
updateCreatedDocument: async (
|
42
38
|
config: AppwriteConfig,
|
@@ -12,7 +12,7 @@ import {
|
|
12
12
|
permissionsSchema,
|
13
13
|
attributesSchema,
|
14
14
|
indexesSchema,
|
15
|
-
} from "
|
15
|
+
} from "appwrite-utils";
|
16
16
|
import { getDatabaseFromConfig } from "./afterImportActions.js";
|
17
17
|
|
18
18
|
export class AppwriteToX {
|
@@ -72,6 +72,9 @@ export class AppwriteToX {
|
|
72
72
|
|
73
73
|
// Loop through each collection in the current database
|
74
74
|
for (const collection of collections) {
|
75
|
+
if (!updatedConfig.collections) {
|
76
|
+
updatedConfig.collections = [];
|
77
|
+
}
|
75
78
|
const existingCollectionIndex = updatedConfig.collections.findIndex(
|
76
79
|
(c) => c.name === collection.name
|
77
80
|
);
|
@@ -128,6 +131,7 @@ export class AppwriteToX {
|
|
128
131
|
|
129
132
|
// Prepare the collection object to be added or updated
|
130
133
|
const collToPush = collectionSchema.parse({
|
134
|
+
$id: collection.$id,
|
131
135
|
name: collection.name,
|
132
136
|
enabled: collection.enabled,
|
133
137
|
documentSecurity: collection.documentSecurity,
|
@@ -161,7 +165,7 @@ export class AppwriteToX {
|
|
161
165
|
this.updatedConfig,
|
162
166
|
this.appwriteFolderPath
|
163
167
|
);
|
164
|
-
generator.
|
168
|
+
generator.updateTsSchemas();
|
165
169
|
generator.generateSchemas();
|
166
170
|
}
|
167
171
|
}
|