appwrite-utils-cli 0.9.0 → 0.9.3
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 +41 -0
- package/dist/interactiveCLI.d.ts +3 -2
- package/dist/interactiveCLI.js +18 -13
- package/dist/main.js +121 -109
- package/dist/migrations/transfer.js +1 -1
- package/dist/setupCommands.d.ts +1 -0
- package/dist/setupCommands.js +1 -0
- package/dist/utils/schemaStrings.js +37 -37
- package/dist/utils/setupFiles.d.ts +1 -1
- package/dist/utils/setupFiles.js +2 -2
- package/package.json +53 -53
- package/src/collections/attributes.ts +483 -483
- package/src/collections/indexes.ts +53 -53
- package/src/collections/methods.ts +331 -331
- package/src/interactiveCLI.ts +771 -767
- package/src/main.ts +126 -112
- package/src/migrations/helper.ts +40 -40
- package/src/migrations/transfer.ts +608 -608
- package/src/setupCommands.ts +0 -0
- package/src/storage/methods.ts +371 -371
- package/src/storage/schemas.ts +205 -205
- package/src/utils/getClientFromConfig.ts +17 -17
- package/src/utils/retryFailedPromises.ts +27 -27
- package/src/utils/schemaStrings.ts +473 -473
- package/src/utils/setupFiles.ts +5 -2
package/src/main.ts
CHANGED
@@ -33,133 +33,147 @@ interface CliOptions {
|
|
33
33
|
remoteEndpoint?: string;
|
34
34
|
remoteProjectId?: string;
|
35
35
|
remoteApiKey?: string;
|
36
|
+
setup?: boolean;
|
36
37
|
}
|
37
38
|
|
38
39
|
type ParsedArgv = ArgumentsCamelCase<CliOptions>;
|
39
40
|
|
40
41
|
const argv = yargs(hideBin(process.argv))
|
41
|
-
.
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
42
|
+
.option("it", {
|
43
|
+
alias: ["interactive", "i"],
|
44
|
+
type: "boolean",
|
45
|
+
description: "Run in interactive mode",
|
46
|
+
})
|
47
|
+
.option("dbIds", {
|
48
|
+
type: "string",
|
49
|
+
description: "Comma-separated list of database IDs to operate on",
|
50
|
+
})
|
51
|
+
.option("collectionIds", {
|
52
|
+
alias: ["collIds"],
|
53
|
+
type: "string",
|
54
|
+
description: "Comma-separated list of collection IDs to operate on",
|
55
|
+
})
|
56
|
+
.option("bucketIds", {
|
57
|
+
type: "string",
|
58
|
+
description: "Comma-separated list of bucket IDs to operate on",
|
59
|
+
})
|
60
|
+
.option("wipe", {
|
61
|
+
choices: ["all", "docs", "users"] as const,
|
62
|
+
description:
|
63
|
+
"Wipe data (all: everything, docs: only documents, users: only user data)",
|
64
|
+
})
|
65
|
+
.option("generate", {
|
66
|
+
type: "boolean",
|
67
|
+
description: "Generate TypeScript schemas from database schemas",
|
68
|
+
})
|
69
|
+
.option("import", {
|
70
|
+
type: "boolean",
|
71
|
+
description: "Import data into your databases",
|
72
|
+
})
|
73
|
+
.option("backup", {
|
74
|
+
type: "boolean",
|
75
|
+
description: "Perform a backup of your databases",
|
76
|
+
})
|
77
|
+
.option("writeData", {
|
78
|
+
type: "boolean",
|
79
|
+
description: "Write converted imported data to file",
|
80
|
+
})
|
81
|
+
.option("push", {
|
82
|
+
type: "boolean",
|
83
|
+
description:
|
84
|
+
"Push your local Appwrite config to your configured Appwrite Project",
|
85
|
+
})
|
86
|
+
.option("sync", {
|
87
|
+
type: "boolean",
|
88
|
+
description:
|
89
|
+
"Synchronize by pulling your Appwrite config from your configured Appwrite Project",
|
90
|
+
})
|
91
|
+
.option("endpoint", {
|
92
|
+
type: "string",
|
93
|
+
description: "Set the Appwrite endpoint",
|
94
|
+
})
|
95
|
+
.option("projectId", {
|
96
|
+
type: "string",
|
97
|
+
description: "Set the Appwrite project ID",
|
98
|
+
})
|
99
|
+
.option("apiKey", {
|
100
|
+
type: "string",
|
101
|
+
description: "Set the Appwrite API key",
|
102
|
+
})
|
103
|
+
.option("transfer", {
|
104
|
+
type: "boolean",
|
105
|
+
description: "Transfer data between databases or collections",
|
106
|
+
})
|
107
|
+
.option("fromDbId", {
|
108
|
+
alias: ["fromDb"],
|
109
|
+
type: "string",
|
110
|
+
description: "Set the source database ID for transfer",
|
111
|
+
})
|
112
|
+
.option("toDbId", {
|
113
|
+
alias: ["toDb"],
|
114
|
+
type: "string",
|
115
|
+
description: "Set the destination database ID for transfer",
|
116
|
+
})
|
117
|
+
.option("fromCollectionId", {
|
118
|
+
alias: ["fromCollId", "fromColl"],
|
119
|
+
type: "string",
|
120
|
+
description: "Set the source collection ID for transfer",
|
121
|
+
})
|
122
|
+
.option("toCollectionId", {
|
123
|
+
alias: ["toCollId", "toColl"],
|
124
|
+
type: "string",
|
125
|
+
description: "Set the destination collection ID for transfer",
|
126
|
+
})
|
127
|
+
.option("fromBucketId", {
|
128
|
+
alias: ["fromBucket"],
|
129
|
+
type: "string",
|
130
|
+
description: "Set the source bucket ID for transfer",
|
131
|
+
})
|
132
|
+
.option("toBucketId", {
|
133
|
+
alias: ["toBucket"],
|
134
|
+
type: "string",
|
135
|
+
description: "Set the destination bucket ID for transfer",
|
136
|
+
})
|
137
|
+
.option("remoteEndpoint", {
|
138
|
+
type: "string",
|
139
|
+
description: "Set the remote Appwrite endpoint for transfers",
|
140
|
+
})
|
141
|
+
.option("remoteProjectId", {
|
142
|
+
type: "string",
|
143
|
+
description: "Set the remote Appwrite project ID for transfers",
|
144
|
+
})
|
145
|
+
.option("remoteApiKey", {
|
146
|
+
type: "string",
|
147
|
+
description: "Set the remote Appwrite API key for transfers",
|
148
|
+
})
|
149
|
+
.option("setup", {
|
150
|
+
type: "boolean",
|
151
|
+
description: "Setup the project with example data",
|
150
152
|
})
|
151
153
|
.help()
|
152
154
|
.parse();
|
153
155
|
|
154
156
|
async function main() {
|
155
157
|
const parsedArgv = (await argv) as ParsedArgv;
|
156
|
-
|
157
|
-
await controller.init();
|
158
|
+
let controller: UtilsController | undefined;
|
158
159
|
|
159
160
|
if (parsedArgv.it) {
|
160
|
-
|
161
|
+
try {
|
162
|
+
controller = new UtilsController(process.cwd());
|
163
|
+
await controller.init();
|
164
|
+
} catch (error: any) {
|
165
|
+
// If it fails, that means there's no config, more than likely
|
166
|
+
console.log(
|
167
|
+
"No config found, you probably need to create the setup files"
|
168
|
+
);
|
169
|
+
}
|
170
|
+
const cli = new InteractiveCLI(process.cwd());
|
161
171
|
await cli.run();
|
162
172
|
} else {
|
173
|
+
if (!controller) {
|
174
|
+
controller = new UtilsController(process.cwd());
|
175
|
+
await controller.init();
|
176
|
+
}
|
163
177
|
// Handle non-interactive mode with the new options
|
164
178
|
const options: SetupOptions = {
|
165
179
|
databases: parsedArgv.dbIds
|
package/src/migrations/helper.ts
CHANGED
@@ -1,40 +1,40 @@
|
|
1
|
-
import type { Databases, Models } from "node-appwrite";
|
2
|
-
import type { OperationCreate } from "../storage/schemas.js";
|
3
|
-
import { tryAwaitWithRetry } from "appwrite-utils";
|
4
|
-
import { ulid } from "ulidx";
|
5
|
-
|
6
|
-
export const logOperation = async (
|
7
|
-
db: Databases,
|
8
|
-
dbId: string,
|
9
|
-
operationDetails: OperationCreate,
|
10
|
-
operationId?: string
|
11
|
-
): Promise<Models.Document> => {
|
12
|
-
try {
|
13
|
-
let operation;
|
14
|
-
if (operationId) {
|
15
|
-
// Update existing operation log
|
16
|
-
operation = await tryAwaitWithRetry(
|
17
|
-
async () =>
|
18
|
-
await db.updateDocument(
|
19
|
-
"migrations",
|
20
|
-
"currentOperations",
|
21
|
-
operationId,
|
22
|
-
operationDetails
|
23
|
-
)
|
24
|
-
);
|
25
|
-
} else {
|
26
|
-
// Create new operation log
|
27
|
-
operation = await db.createDocument(
|
28
|
-
"migrations",
|
29
|
-
"currentOperations",
|
30
|
-
ulid(),
|
31
|
-
operationDetails
|
32
|
-
);
|
33
|
-
}
|
34
|
-
console.log(`Operation logged: ${operation.$id}`);
|
35
|
-
return operation;
|
36
|
-
} catch (error) {
|
37
|
-
console.error(`Error logging operation: ${error}`);
|
38
|
-
throw error;
|
39
|
-
}
|
40
|
-
};
|
1
|
+
import type { Databases, Models } from "node-appwrite";
|
2
|
+
import type { OperationCreate } from "../storage/schemas.js";
|
3
|
+
import { tryAwaitWithRetry } from "appwrite-utils";
|
4
|
+
import { ulid } from "ulidx";
|
5
|
+
|
6
|
+
export const logOperation = async (
|
7
|
+
db: Databases,
|
8
|
+
dbId: string,
|
9
|
+
operationDetails: OperationCreate,
|
10
|
+
operationId?: string
|
11
|
+
): Promise<Models.Document> => {
|
12
|
+
try {
|
13
|
+
let operation;
|
14
|
+
if (operationId) {
|
15
|
+
// Update existing operation log
|
16
|
+
operation = await tryAwaitWithRetry(
|
17
|
+
async () =>
|
18
|
+
await db.updateDocument(
|
19
|
+
"migrations",
|
20
|
+
"currentOperations",
|
21
|
+
operationId,
|
22
|
+
operationDetails
|
23
|
+
)
|
24
|
+
);
|
25
|
+
} else {
|
26
|
+
// Create new operation log
|
27
|
+
operation = await db.createDocument(
|
28
|
+
"migrations",
|
29
|
+
"currentOperations",
|
30
|
+
ulid(),
|
31
|
+
operationDetails
|
32
|
+
);
|
33
|
+
}
|
34
|
+
console.log(`Operation logged: ${operation.$id}`);
|
35
|
+
return operation;
|
36
|
+
} catch (error) {
|
37
|
+
console.error(`Error logging operation: ${error}`);
|
38
|
+
throw error;
|
39
|
+
}
|
40
|
+
};
|