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/README.md
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
## Features
|
8
8
|
|
9
|
-
- **Easy Configuration**: Initialize your Appwrite project configurations
|
9
|
+
- **Easy Configuration**: Initialize your Appwrite project configurations interactively directly from the command line.
|
10
10
|
- **Database Migrations**: Control the migration process with options to target production, staging, or development environments.
|
11
11
|
- **Schema Generation**: Generate and manage TypeScript schemas directly from your Appwrite database schemas.
|
12
12
|
- **Data Import**: Facilitate the import of data into your Appwrite databases with comprehensive command-line support.
|
@@ -35,26 +35,12 @@ After installation, you can access the tool directly from your command line usin
|
|
35
35
|
|
36
36
|
### Initialization
|
37
37
|
|
38
|
-
|
38
|
+
Interactively set up your Appwrite project with necessary configurations:
|
39
39
|
|
40
40
|
```bash
|
41
|
-
npx --package=appwrite-utils-cli@latest appwrite-
|
41
|
+
npx --package=appwrite-utils-cli@latest appwrite-init
|
42
42
|
```
|
43
43
|
|
44
|
-
To generate an example configuration file:
|
45
|
-
|
46
|
-
```bash
|
47
|
-
appwrite-setup --example
|
48
|
-
```
|
49
|
-
|
50
|
-
To synchronize your `appwriteConfig.yaml` with your Appwrite Database, first you must run the setup command and enter your Appwrite instances details in the `projectId`, `endpoint`, and `apiKey`, then run the following
|
51
|
-
|
52
|
-
```bash
|
53
|
-
npx --package=appwrite-utils-cli@latest appwrite-migrate -- --sync
|
54
|
-
```
|
55
|
-
|
56
|
-
This will initialize your config and generate schemas for your database using ZOD to `src/appwrite/schemas`
|
57
|
-
|
58
44
|
### Running Migrations and Tasks
|
59
45
|
|
60
46
|
Run migration and management tasks with specific flags according to your needs:
|
@@ -80,28 +66,6 @@ Replace `--args` with the appropriate options:
|
|
80
66
|
- `--project`: Set a different project ID for the migration target
|
81
67
|
- `--key`: Set a different API key for the migration target
|
82
68
|
|
83
|
-
For example, to run migrations in a development environment and import data:
|
84
|
-
|
85
|
-
```bash
|
86
|
-
npx --package=appwrite-utils-cli@latest appwrite-migrate --dev --import
|
87
|
-
```
|
88
|
-
|
89
|
-
To initialize your project, generate schemas, but not import data:
|
90
|
-
|
91
|
-
```bash
|
92
|
-
npx --package=appwrite-utils-cli@latest appwrite-migrate --init
|
93
|
-
```
|
94
|
-
|
95
|
-
To sync:
|
96
|
-
|
97
|
-
```bash
|
98
|
-
# If you have no appwriteConfig
|
99
|
-
npx --package=appwrite-utils-cli@latest appwrite-migrate --init
|
100
|
-
|
101
|
-
# Otherwise, you can remove everything in the config file down to the word collections, just leave your Databases, then run
|
102
|
-
npx --package=appwrite-utils-cli@latest appwrite-migrate --sync
|
103
|
-
```
|
104
|
-
|
105
69
|
### OpenAPI Generation (almost done, in progress)
|
106
70
|
|
107
71
|
Recently, I have also added an optional OpenAPI generation for each attribute in the schema. This is because I needed it and because I felt it would be nice to have. This is done using [this package](https://github.com/asteasolutions/zod-to-openapi), many thanks to them.
|
@@ -118,6 +82,8 @@ This setup ensures that developers have robust tools at their fingertips to mana
|
|
118
82
|
|
119
83
|
### Changelog
|
120
84
|
|
85
|
+
- 0.0.275: THINGS ARE NOW IN TYPESCRIPT WOOHOO. No but for reaal, super happy to report that everything has been converted to TypeScript, just way too many changes, I hope you enjoy it!
|
86
|
+
- 0.0.274: Small improvement for attribute handling, rather than getting it every attribute, I check the collections attributes
|
121
87
|
- 0.0.273: Small fix for relationship attribute comparisons
|
122
88
|
- 0.0.272: That's what I get for not testing lmao, also updated logic for checking for existing attributes to take the `format` into consideration from the database (URL's are not of `type: "url"`, they are of `format: "url"`)
|
123
89
|
- 0.0.271: Small change to update attributes that are different from each other by deleting the attribute and recreating, as we cannot update most things
|
package/dist/init.d.ts
ADDED
package/dist/init.js
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
#!/usr/bin/env node
|
2
|
+
import inquirer from "inquirer";
|
3
|
+
import { createEmptyCollection, setupDirsFiles } from "./utils/setupFiles.js";
|
4
|
+
console.log("Welcome to Appwrite Utils CLI Tool by Zach Handley");
|
5
|
+
console.log("For more information, visit https://github.com/zachhandley/appwrite-utils");
|
6
|
+
async function main() {
|
7
|
+
const answers = await inquirer.prompt([
|
8
|
+
{
|
9
|
+
type: "list",
|
10
|
+
name: "action",
|
11
|
+
message: "What would you like to do?",
|
12
|
+
choices: [
|
13
|
+
"Create collection config file",
|
14
|
+
"Create function (not available)",
|
15
|
+
"Setup directories and files",
|
16
|
+
"Setup directories and files with example data",
|
17
|
+
"Exit",
|
18
|
+
],
|
19
|
+
},
|
20
|
+
]);
|
21
|
+
switch (answers.action) {
|
22
|
+
case "Create collection config file":
|
23
|
+
const { collectionName } = await inquirer.prompt([
|
24
|
+
{
|
25
|
+
type: "input",
|
26
|
+
name: "collectionName",
|
27
|
+
message: "Enter the name of the collection:",
|
28
|
+
validate: (input) => input.trim() !== "" || "Collection name cannot be empty.",
|
29
|
+
},
|
30
|
+
]);
|
31
|
+
console.log(`Creating collection config file for '${collectionName}'...`);
|
32
|
+
createEmptyCollection(collectionName);
|
33
|
+
break;
|
34
|
+
case "Create function (not available)":
|
35
|
+
console.log("This feature is not available yet.");
|
36
|
+
break;
|
37
|
+
case "Setup directories and files":
|
38
|
+
console.log("Setting up directories and files...");
|
39
|
+
setupDirsFiles(false); // Assuming false means no example data
|
40
|
+
break;
|
41
|
+
case "Setup directories and files with example data":
|
42
|
+
console.log("Setting up directories and files with example data...");
|
43
|
+
setupDirsFiles(true); // Assuming false means no example data
|
44
|
+
break;
|
45
|
+
case "Exit":
|
46
|
+
console.log("Exiting...");
|
47
|
+
process.exit(0);
|
48
|
+
break;
|
49
|
+
default:
|
50
|
+
console.log("Invalid option, please try again.");
|
51
|
+
break;
|
52
|
+
}
|
53
|
+
}
|
54
|
+
main().catch((error) => {
|
55
|
+
console.error("An error occurred:", error);
|
56
|
+
process.exit(1);
|
57
|
+
});
|
package/dist/main.js
CHANGED
@@ -1,103 +1,65 @@
|
|
1
1
|
#!/usr/bin/env node
|
2
|
+
import { program } from "commander";
|
2
3
|
import { UtilsController } from "./utilsController.js";
|
3
|
-
|
4
|
-
|
4
|
+
// Setup the main CLI program
|
5
|
+
program
|
6
|
+
.version("1.0.0")
|
7
|
+
.description("Utility CLI for Appwrite configurations and operations")
|
8
|
+
.option("--endpoint <endpoint>", "Set the Appwrite endpoint", undefined)
|
9
|
+
.option("--project <project>", "Set the Appwrite project ID", undefined)
|
10
|
+
.option("--key <key>", "Set the Appwrite API key", undefined)
|
11
|
+
.option("--backup", "Perform a backup before executing the command", false)
|
12
|
+
.option("--dev", "Run in development environment", false)
|
13
|
+
.option("--prod", "Run in production environment", false)
|
14
|
+
.option("--staging", "Run in staging environment", false)
|
15
|
+
.option("--sync", "Synchronize configurations", false)
|
16
|
+
.option("--wipe", "Wipe databases", false)
|
17
|
+
.option("--wipe-docs", "Wipe documents", false)
|
18
|
+
.option("--wipe-users", "Wipe users", false)
|
19
|
+
.option("--generate", "Generate schemas", false)
|
20
|
+
.option("--import", "Import data", false)
|
21
|
+
.option("--write-data", "Write data to file", false)
|
22
|
+
.option("-h, --help", "Display help for command", false);
|
23
|
+
program.on("--help", () => {
|
24
|
+
console.log("");
|
25
|
+
console.log("Examples:");
|
26
|
+
console.log(" $ npx appwrite-utils-cli appwrite-migrate --sync --endpoint https://appwrite.example.com --project 123456 --key 7890");
|
27
|
+
console.log(" $ npx appwrite-utils-cli appwrite-migrate --sync --dev --backup");
|
28
|
+
console.log(" $ npx appwrite-utils-cli appwrite-migrate --wipe --wipe-docs --wipe-users --dev");
|
29
|
+
console.log(" $ npx appwrite-utils-cli appwrite-migrate --generate --import --write-data --dev");
|
30
|
+
console.log(" $ npx appwrite-utils-cli appwrite-migrate --sync --generate --import --write-data --dev --backup");
|
31
|
+
console.log(" $ npx appwrite-utils-cli appwrite-create");
|
32
|
+
console.log("For more information, visit https://github.com/zachhandley/appwrite-utils");
|
33
|
+
console.log("");
|
34
|
+
});
|
35
|
+
// Parse and handle options
|
36
|
+
program.action(async (options) => {
|
5
37
|
const controller = new UtilsController();
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
}
|
29
|
-
|
30
|
-
|
31
|
-
}
|
32
|
-
|
33
|
-
|
34
|
-
}
|
35
|
-
if (args.includes("--wipe-docs") || args.includes("--wipeDocs")) {
|
36
|
-
wipeDocuments = true;
|
37
|
-
}
|
38
|
-
if (args.includes("--generate")) {
|
39
|
-
generateSchemas = true;
|
40
|
-
}
|
41
|
-
if (args.includes("--import")) {
|
42
|
-
importData = true;
|
43
|
-
}
|
44
|
-
if (args.includes("--backup")) {
|
45
|
-
doBackup = true;
|
46
|
-
}
|
47
|
-
if (args.includes("--wipe-users") || args.includes("--wipeUsers")) {
|
48
|
-
wipeUsers = true;
|
49
|
-
}
|
50
|
-
if (args.includes("--write-data") || args.includes("--writeData")) {
|
51
|
-
shouldWriteFile = true;
|
52
|
-
}
|
53
|
-
if (args.includes("--endpoint")) {
|
54
|
-
endpoint = args[args.indexOf("--endpoint") + 1];
|
55
|
-
}
|
56
|
-
if (args.includes("--project")) {
|
57
|
-
project = args[args.indexOf("--project") + 1];
|
58
|
-
}
|
59
|
-
if (args.includes("--key")) {
|
60
|
-
key = args[args.indexOf("--key") + 1];
|
61
|
-
}
|
62
|
-
if (args.includes("--init")) {
|
63
|
-
await controller.run({
|
64
|
-
sync: sync,
|
65
|
-
runProd: runProd,
|
66
|
-
runStaging: runStaging,
|
67
|
-
runDev: runDev,
|
68
|
-
doBackup: doBackup,
|
69
|
-
wipeDatabases: wipeDatabases,
|
70
|
-
wipeUsers: wipeUsers,
|
71
|
-
wipeDocumentStorage: wipeDocuments,
|
72
|
-
generateSchemas: true,
|
73
|
-
generateMockData: false,
|
74
|
-
importData: false,
|
75
|
-
checkDuplicates: false,
|
76
|
-
shouldWriteFile: shouldWriteFile,
|
77
|
-
endpoint: endpoint,
|
78
|
-
project: project,
|
79
|
-
key: key,
|
80
|
-
});
|
81
|
-
}
|
82
|
-
else {
|
83
|
-
await controller.run({
|
84
|
-
sync: sync,
|
85
|
-
runProd: runProd,
|
86
|
-
runStaging: runStaging,
|
87
|
-
runDev: runDev,
|
88
|
-
doBackup: doBackup,
|
89
|
-
wipeDatabases: wipeDatabases,
|
90
|
-
wipeDocumentStorage: wipeDocuments,
|
91
|
-
generateSchemas: generateSchemas,
|
92
|
-
generateMockData: false,
|
93
|
-
wipeUsers: wipeUsers,
|
94
|
-
importData: importData,
|
95
|
-
checkDuplicates: false,
|
96
|
-
shouldWriteFile: shouldWriteFile,
|
97
|
-
endpoint: endpoint,
|
98
|
-
project: project,
|
99
|
-
key: key,
|
100
|
-
});
|
101
|
-
}
|
102
|
-
}
|
103
|
-
main().catch(console.error);
|
38
|
+
try {
|
39
|
+
// Convert Commander options to the format expected by UtilsController
|
40
|
+
const setupOptions = {
|
41
|
+
sync: options.sync,
|
42
|
+
runProd: options.prod,
|
43
|
+
runStaging: options.staging,
|
44
|
+
runDev: options.dev,
|
45
|
+
doBackup: options.backup,
|
46
|
+
wipeDatabases: options.wipe,
|
47
|
+
wipeDocumentStorage: options.wipeDocs,
|
48
|
+
wipeUsers: options.wipeUsers,
|
49
|
+
generateSchemas: options.generate,
|
50
|
+
generateMockData: false, // Assuming this needs to be set based on other conditions
|
51
|
+
importData: options.import,
|
52
|
+
checkDuplicates: false, // Assuming this needs to be set based on other conditions
|
53
|
+
shouldWriteFile: options.writeData,
|
54
|
+
endpoint: options.endpoint,
|
55
|
+
project: options.project,
|
56
|
+
key: options.key,
|
57
|
+
};
|
58
|
+
await controller.run(setupOptions);
|
59
|
+
console.log("Operation completed successfully.");
|
60
|
+
}
|
61
|
+
catch (error) {
|
62
|
+
console.error("Error during operation:", error);
|
63
|
+
}
|
64
|
+
});
|
65
|
+
program.parse(process.argv);
|
@@ -1,10 +1,7 @@
|
|
1
1
|
import { Databases, Storage, type Models } from "node-appwrite";
|
2
|
-
import type
|
2
|
+
import { type AppwriteConfig } from "appwrite-utils";
|
3
3
|
export declare const getDatabaseFromConfig: (config: AppwriteConfig) => Databases;
|
4
4
|
export declare const getStorageFromConfig: (config: AppwriteConfig) => Storage;
|
5
|
-
export interface AfterImportActions {
|
6
|
-
[key: string]: (config: AppwriteConfig, ...args: any[]) => Promise<any>;
|
7
|
-
}
|
8
5
|
export declare const afterImportActions: {
|
9
6
|
updateCreatedDocument: (config: AppwriteConfig, dbId: string, collId: string, docId: string, data: any) => Promise<void>;
|
10
7
|
checkAndUpdateFieldInDocument: (config: AppwriteConfig, dbId: string, collId: string, docId: string, fieldName: string, oldFieldValue: any, newFieldValue: any) => Promise<void>;
|
@@ -3,6 +3,7 @@ import path from "path";
|
|
3
3
|
import fs from "fs";
|
4
4
|
import os from "os";
|
5
5
|
import { logger } from "./logging.js";
|
6
|
+
import {} from "appwrite-utils";
|
6
7
|
export const getDatabaseFromConfig = (config) => {
|
7
8
|
if (!config.appwriteClient) {
|
8
9
|
config.appwriteClient = new Client()
|
@@ -1,93 +1,91 @@
|
|
1
1
|
import { type Models } from "node-appwrite";
|
2
|
-
import { type AppwriteConfig } from "
|
2
|
+
import { type AppwriteConfig } from "appwrite-utils";
|
3
3
|
export declare class AppwriteToX {
|
4
4
|
config: AppwriteConfig;
|
5
5
|
updatedConfig: AppwriteConfig;
|
6
6
|
collToAttributeMap: Map<string, ({
|
7
|
-
key: string;
|
8
7
|
type: "string";
|
9
|
-
|
10
|
-
required: boolean;
|
11
|
-
array: boolean;
|
8
|
+
key: string;
|
12
9
|
size: number;
|
10
|
+
array?: boolean | undefined;
|
11
|
+
error?: string | undefined;
|
12
|
+
required?: boolean | undefined;
|
13
13
|
xdefault?: string | null | undefined;
|
14
14
|
encrypted?: boolean | undefined;
|
15
15
|
format?: string | null | undefined;
|
16
|
-
description?: string | Record<string, string> |
|
16
|
+
description?: string | Record<string, string> | undefined;
|
17
17
|
} | {
|
18
|
-
key: string;
|
19
18
|
type: "integer";
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
max?: number | undefined;
|
19
|
+
key: string;
|
20
|
+
array?: boolean | undefined;
|
21
|
+
error?: string | undefined;
|
22
|
+
required?: boolean | undefined;
|
25
23
|
xdefault?: number | null | undefined;
|
26
24
|
description?: string | Record<string, string> | null | undefined;
|
27
|
-
} | {
|
28
|
-
key: string;
|
29
|
-
type: "float";
|
30
|
-
error: string;
|
31
|
-
required: boolean;
|
32
|
-
array: boolean;
|
33
25
|
min?: number | undefined;
|
34
26
|
max?: number | undefined;
|
27
|
+
} | {
|
28
|
+
type: "float";
|
29
|
+
key: string;
|
30
|
+
array?: boolean | undefined;
|
31
|
+
error?: string | undefined;
|
32
|
+
required?: boolean | undefined;
|
35
33
|
xdefault?: number | null | undefined;
|
36
34
|
description?: string | Record<string, string> | null | undefined;
|
35
|
+
min?: number | undefined;
|
36
|
+
max?: number | undefined;
|
37
37
|
} | {
|
38
|
-
key: string;
|
39
38
|
type: "boolean";
|
40
|
-
|
41
|
-
|
42
|
-
|
39
|
+
key: string;
|
40
|
+
array?: boolean | undefined;
|
41
|
+
error?: string | undefined;
|
42
|
+
required?: boolean | undefined;
|
43
43
|
xdefault?: boolean | null | undefined;
|
44
44
|
description?: string | Record<string, string> | null | undefined;
|
45
45
|
} | {
|
46
|
-
key: string;
|
47
46
|
type: "datetime";
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
key: string;
|
48
|
+
array?: boolean | undefined;
|
49
|
+
error?: string | undefined;
|
50
|
+
required?: boolean | undefined;
|
51
51
|
xdefault?: string | null | undefined;
|
52
52
|
description?: string | Record<string, string> | null | undefined;
|
53
53
|
} | {
|
54
|
-
key: string;
|
55
54
|
type: "email";
|
56
|
-
|
57
|
-
|
58
|
-
|
55
|
+
key: string;
|
56
|
+
array?: boolean | undefined;
|
57
|
+
error?: string | undefined;
|
58
|
+
required?: boolean | undefined;
|
59
59
|
xdefault?: string | null | undefined;
|
60
60
|
description?: string | Record<string, string> | null | undefined;
|
61
61
|
} | {
|
62
|
-
key: string;
|
63
62
|
type: "ip";
|
64
|
-
|
65
|
-
|
66
|
-
|
63
|
+
key: string;
|
64
|
+
array?: boolean | undefined;
|
65
|
+
error?: string | undefined;
|
66
|
+
required?: boolean | undefined;
|
67
67
|
xdefault?: string | null | undefined;
|
68
68
|
description?: string | Record<string, string> | null | undefined;
|
69
69
|
} | {
|
70
|
-
key: string;
|
71
70
|
type: "url";
|
72
|
-
|
73
|
-
|
74
|
-
|
71
|
+
key: string;
|
72
|
+
array?: boolean | undefined;
|
73
|
+
error?: string | undefined;
|
74
|
+
required?: boolean | undefined;
|
75
75
|
xdefault?: string | null | undefined;
|
76
76
|
description?: string | Record<string, string> | null | undefined;
|
77
77
|
} | {
|
78
|
-
key: string;
|
79
78
|
type: "enum";
|
80
|
-
|
81
|
-
required: boolean;
|
82
|
-
array: boolean;
|
79
|
+
key: string;
|
83
80
|
elements: string[];
|
81
|
+
array?: boolean | undefined;
|
82
|
+
error?: string | undefined;
|
83
|
+
required?: boolean | undefined;
|
84
84
|
xdefault?: string | null | undefined;
|
85
85
|
description?: string | Record<string, string> | null | undefined;
|
86
86
|
} | {
|
87
|
-
key: string;
|
88
87
|
type: "relationship";
|
89
|
-
|
90
|
-
required: boolean;
|
88
|
+
key: string;
|
91
89
|
relatedCollection: string;
|
92
90
|
relationType: "oneToMany" | "manyToOne" | "oneToOne" | "manyToMany";
|
93
91
|
twoWay: boolean;
|
@@ -95,11 +93,13 @@ export declare class AppwriteToX {
|
|
95
93
|
onDelete: "setNull" | "cascade" | "restrict";
|
96
94
|
side: "parent" | "child";
|
97
95
|
array?: boolean | undefined;
|
96
|
+
error?: string | undefined;
|
97
|
+
required?: boolean | undefined;
|
98
|
+
description?: string | Record<string, string> | null | undefined;
|
98
99
|
importMapping?: {
|
99
100
|
originalIdField: string;
|
100
101
|
targetField?: string | undefined;
|
101
102
|
} | undefined;
|
102
|
-
description?: string | Record<string, string> | null | undefined;
|
103
103
|
})[]>;
|
104
104
|
appwriteFolderPath: string;
|
105
105
|
constructor(config: AppwriteConfig, appwriteFolderPath: string);
|
@@ -2,7 +2,7 @@ import { SchemaGenerator } from "./schemaStrings.js";
|
|
2
2
|
import { Databases, Query } from "node-appwrite";
|
3
3
|
import { fetchAllCollections } from "./collections.js";
|
4
4
|
import { fetchAllDatabases } from "./databases.js";
|
5
|
-
import { collectionSchema, attributeSchema, AppwriteConfigSchema, permissionsSchema, attributesSchema, indexesSchema, } from "
|
5
|
+
import { collectionSchema, attributeSchema, AppwriteConfigSchema, permissionsSchema, attributesSchema, indexesSchema, } from "appwrite-utils";
|
6
6
|
import { getDatabaseFromConfig } from "./afterImportActions.js";
|
7
7
|
export class AppwriteToX {
|
8
8
|
config;
|
@@ -52,6 +52,9 @@ export class AppwriteToX {
|
|
52
52
|
const collections = await fetchAllCollections(database.$id, db);
|
53
53
|
// Loop through each collection in the current database
|
54
54
|
for (const collection of collections) {
|
55
|
+
if (!updatedConfig.collections) {
|
56
|
+
updatedConfig.collections = [];
|
57
|
+
}
|
55
58
|
const existingCollectionIndex = updatedConfig.collections.findIndex((c) => c.name === collection.name);
|
56
59
|
// Parse the collection permissions and attributes
|
57
60
|
const collPermissions = this.parsePermissionsArray(collection.$permissions);
|
@@ -86,6 +89,7 @@ export class AppwriteToX {
|
|
86
89
|
const collIndexes = indexesSchema.parse(collection.indexes);
|
87
90
|
// Prepare the collection object to be added or updated
|
88
91
|
const collToPush = collectionSchema.parse({
|
92
|
+
$id: collection.$id,
|
89
93
|
name: collection.name,
|
90
94
|
enabled: collection.enabled,
|
91
95
|
documentSecurity: collection.documentSecurity,
|
@@ -111,7 +115,7 @@ export class AppwriteToX {
|
|
111
115
|
async toSchemas() {
|
112
116
|
await this.appwriteSync(this.config);
|
113
117
|
const generator = new SchemaGenerator(this.updatedConfig, this.appwriteFolderPath);
|
114
|
-
generator.
|
118
|
+
generator.updateTsSchemas();
|
115
119
|
generator.generateSchemas();
|
116
120
|
}
|
117
121
|
}
|
@@ -1,4 +1,4 @@
|
|
1
1
|
import { type Databases, type Models } from "node-appwrite";
|
2
|
-
import { type Attribute } from "
|
2
|
+
import { type Attribute } from "appwrite-utils";
|
3
3
|
export declare const createOrUpdateAttribute: (db: Databases, dbId: string, collection: Models.Collection, attribute: Attribute) => Promise<void>;
|
4
4
|
export declare const createUpdateCollectionAttributes: (db: Databases, dbId: string, collection: Models.Collection, attributes: Attribute[]) => Promise<void>;
|