appwrite-utils-cli 0.0.285 → 0.9.0
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 +122 -96
- package/dist/collections/attributes.d.ts +4 -0
- package/dist/collections/attributes.js +224 -0
- package/dist/collections/indexes.d.ts +4 -0
- package/dist/collections/indexes.js +27 -0
- package/dist/collections/methods.d.ts +16 -0
- package/dist/collections/methods.js +216 -0
- package/dist/databases/methods.d.ts +6 -0
- package/dist/databases/methods.js +33 -0
- package/dist/interactiveCLI.d.ts +19 -0
- package/dist/interactiveCLI.js +555 -0
- package/dist/main.js +227 -62
- package/dist/migrations/afterImportActions.js +37 -40
- package/dist/migrations/appwriteToX.d.ts +26 -25
- package/dist/migrations/appwriteToX.js +42 -6
- package/dist/migrations/attributes.js +21 -20
- package/dist/migrations/backup.d.ts +93 -87
- package/dist/migrations/collections.d.ts +6 -0
- package/dist/migrations/collections.js +149 -20
- package/dist/migrations/converters.d.ts +2 -18
- package/dist/migrations/converters.js +13 -2
- package/dist/migrations/dataLoader.d.ts +276 -161
- package/dist/migrations/dataLoader.js +535 -292
- package/dist/migrations/databases.js +8 -2
- package/dist/migrations/helper.d.ts +3 -0
- package/dist/migrations/helper.js +21 -0
- package/dist/migrations/importController.d.ts +5 -2
- package/dist/migrations/importController.js +125 -88
- package/dist/migrations/importDataActions.d.ts +9 -1
- package/dist/migrations/importDataActions.js +15 -3
- package/dist/migrations/indexes.js +3 -2
- package/dist/migrations/logging.js +20 -8
- package/dist/migrations/migrationHelper.d.ts +9 -4
- package/dist/migrations/migrationHelper.js +6 -5
- package/dist/migrations/openapi.d.ts +1 -1
- package/dist/migrations/openapi.js +33 -18
- package/dist/migrations/queue.js +3 -2
- package/dist/migrations/relationships.d.ts +2 -2
- package/dist/migrations/schemaStrings.js +53 -41
- package/dist/migrations/setupDatabase.d.ts +2 -4
- package/dist/migrations/setupDatabase.js +24 -105
- package/dist/migrations/storage.d.ts +3 -1
- package/dist/migrations/storage.js +110 -16
- package/dist/migrations/transfer.d.ts +30 -0
- package/dist/migrations/transfer.js +337 -0
- package/dist/migrations/users.d.ts +2 -1
- package/dist/migrations/users.js +78 -43
- package/dist/schemas/authUser.d.ts +2 -2
- package/dist/storage/methods.d.ts +15 -0
- package/dist/storage/methods.js +207 -0
- package/dist/storage/schemas.d.ts +687 -0
- package/dist/storage/schemas.js +175 -0
- package/dist/utils/getClientFromConfig.d.ts +4 -0
- package/dist/utils/getClientFromConfig.js +16 -0
- package/dist/utils/helperFunctions.d.ts +11 -1
- package/dist/utils/helperFunctions.js +38 -0
- package/dist/utils/retryFailedPromises.d.ts +2 -0
- package/dist/utils/retryFailedPromises.js +21 -0
- package/dist/utils/schemaStrings.d.ts +13 -0
- package/dist/utils/schemaStrings.js +403 -0
- package/dist/utils/setupFiles.js +110 -61
- package/dist/utilsController.d.ts +40 -22
- package/dist/utilsController.js +164 -84
- package/package.json +13 -15
- package/src/collections/attributes.ts +483 -0
- package/src/collections/indexes.ts +53 -0
- package/src/collections/methods.ts +331 -0
- package/src/databases/methods.ts +47 -0
- package/src/init.ts +64 -64
- package/src/interactiveCLI.ts +767 -0
- package/src/main.ts +292 -83
- package/src/migrations/afterImportActions.ts +553 -490
- package/src/migrations/appwriteToX.ts +237 -174
- package/src/migrations/attributes.ts +483 -422
- package/src/migrations/backup.ts +205 -205
- package/src/migrations/collections.ts +545 -300
- package/src/migrations/converters.ts +161 -150
- package/src/migrations/dataLoader.ts +1615 -1304
- package/src/migrations/databases.ts +44 -25
- package/src/migrations/dbHelpers.ts +92 -92
- package/src/migrations/helper.ts +40 -0
- package/src/migrations/importController.ts +448 -384
- package/src/migrations/importDataActions.ts +315 -307
- package/src/migrations/indexes.ts +40 -37
- package/src/migrations/logging.ts +29 -16
- package/src/migrations/migrationHelper.ts +207 -201
- package/src/migrations/openapi.ts +83 -70
- package/src/migrations/queue.ts +118 -119
- package/src/migrations/relationships.ts +324 -324
- package/src/migrations/schemaStrings.ts +472 -460
- package/src/migrations/setupDatabase.ts +118 -219
- package/src/migrations/storage.ts +538 -358
- package/src/migrations/transfer.ts +608 -0
- package/src/migrations/users.ts +362 -285
- package/src/migrations/validationRules.ts +63 -63
- package/src/schemas/authUser.ts +23 -23
- package/src/setup.ts +8 -8
- package/src/storage/methods.ts +371 -0
- package/src/storage/schemas.ts +205 -0
- package/src/types.ts +9 -9
- package/src/utils/getClientFromConfig.ts +17 -0
- package/src/utils/helperFunctions.ts +181 -127
- package/src/utils/index.ts +2 -2
- package/src/utils/loadConfigs.ts +59 -59
- package/src/utils/retryFailedPromises.ts +27 -0
- package/src/utils/schemaStrings.ts +473 -0
- package/src/utils/setupFiles.ts +228 -182
- package/src/utilsController.ts +325 -194
- package/tsconfig.json +37 -37
package/src/main.ts
CHANGED
@@ -1,83 +1,292 @@
|
|
1
|
-
#!/usr/bin/env node
|
2
|
-
import
|
3
|
-
import {
|
4
|
-
|
5
|
-
|
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
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
-
|
1
|
+
#!/usr/bin/env node
|
2
|
+
import yargs from "yargs";
|
3
|
+
import { type ArgumentsCamelCase } from "yargs";
|
4
|
+
import { hideBin } from "yargs/helpers";
|
5
|
+
import { InteractiveCLI } from "./interactiveCLI.js";
|
6
|
+
import { UtilsController, type SetupOptions } from "./utilsController.js";
|
7
|
+
import type { TransferOptions } from "./migrations/transfer.js";
|
8
|
+
import { Databases, Storage, type Models } from "node-appwrite";
|
9
|
+
import { getClient } from "./utils/getClientFromConfig.js";
|
10
|
+
|
11
|
+
interface CliOptions {
|
12
|
+
it?: boolean;
|
13
|
+
dbIds?: string;
|
14
|
+
collectionIds?: string;
|
15
|
+
bucketIds?: string;
|
16
|
+
wipe?: "all" | "docs" | "users";
|
17
|
+
generate?: boolean;
|
18
|
+
import?: boolean;
|
19
|
+
backup?: boolean;
|
20
|
+
writeData?: boolean;
|
21
|
+
push?: boolean;
|
22
|
+
sync?: boolean;
|
23
|
+
endpoint?: string;
|
24
|
+
projectId?: string;
|
25
|
+
apiKey?: string;
|
26
|
+
transfer?: boolean;
|
27
|
+
fromDbId?: string;
|
28
|
+
toDbId?: string;
|
29
|
+
fromCollectionId?: string;
|
30
|
+
toCollectionId?: string;
|
31
|
+
fromBucketId?: string;
|
32
|
+
toBucketId?: string;
|
33
|
+
remoteEndpoint?: string;
|
34
|
+
remoteProjectId?: string;
|
35
|
+
remoteApiKey?: string;
|
36
|
+
}
|
37
|
+
|
38
|
+
type ParsedArgv = ArgumentsCamelCase<CliOptions>;
|
39
|
+
|
40
|
+
const argv = yargs(hideBin(process.argv))
|
41
|
+
.command("migrate", "Run Appwrite migrations", (yargs) => {
|
42
|
+
return yargs
|
43
|
+
.option("it", {
|
44
|
+
alias: ["interactive", "i"],
|
45
|
+
type: "boolean",
|
46
|
+
description: "Run in interactive mode",
|
47
|
+
})
|
48
|
+
.option("dbIds", {
|
49
|
+
type: "string",
|
50
|
+
description: "Comma-separated list of database IDs to operate on",
|
51
|
+
})
|
52
|
+
.option("collectionIds", {
|
53
|
+
alias: ["collIds"],
|
54
|
+
type: "string",
|
55
|
+
description: "Comma-separated list of collection IDs to operate on",
|
56
|
+
})
|
57
|
+
.option("bucketIds", {
|
58
|
+
type: "string",
|
59
|
+
description: "Comma-separated list of bucket IDs to operate on",
|
60
|
+
})
|
61
|
+
.option("wipe", {
|
62
|
+
choices: ["all", "docs", "users"] as const,
|
63
|
+
description:
|
64
|
+
"Wipe data (all: everything, docs: only documents, users: only user data)",
|
65
|
+
})
|
66
|
+
.option("generate", {
|
67
|
+
type: "boolean",
|
68
|
+
description: "Generate TypeScript schemas from database schemas",
|
69
|
+
})
|
70
|
+
.option("import", {
|
71
|
+
type: "boolean",
|
72
|
+
description: "Import data into your databases",
|
73
|
+
})
|
74
|
+
.option("backup", {
|
75
|
+
type: "boolean",
|
76
|
+
description: "Perform a backup of your databases",
|
77
|
+
})
|
78
|
+
.option("writeData", {
|
79
|
+
type: "boolean",
|
80
|
+
description: "Write converted imported data to file",
|
81
|
+
})
|
82
|
+
.option("push", {
|
83
|
+
type: "boolean",
|
84
|
+
description:
|
85
|
+
"Push your local Appwrite config to your configured Appwrite Project",
|
86
|
+
})
|
87
|
+
.option("sync", {
|
88
|
+
type: "boolean",
|
89
|
+
description:
|
90
|
+
"Synchronize by pulling your Appwrite config from your configured Appwrite Project",
|
91
|
+
})
|
92
|
+
.option("endpoint", {
|
93
|
+
type: "string",
|
94
|
+
description: "Set the Appwrite endpoint",
|
95
|
+
})
|
96
|
+
.option("projectId", {
|
97
|
+
type: "string",
|
98
|
+
description: "Set the Appwrite project ID",
|
99
|
+
})
|
100
|
+
.option("apiKey", {
|
101
|
+
type: "string",
|
102
|
+
description: "Set the Appwrite API key",
|
103
|
+
})
|
104
|
+
.option("transfer", {
|
105
|
+
type: "boolean",
|
106
|
+
description: "Transfer data between databases or collections",
|
107
|
+
})
|
108
|
+
.option("fromDbId", {
|
109
|
+
alias: ["fromDb"],
|
110
|
+
type: "string",
|
111
|
+
description: "Set the source database ID for transfer",
|
112
|
+
})
|
113
|
+
.option("toDbId", {
|
114
|
+
alias: ["toDb"],
|
115
|
+
type: "string",
|
116
|
+
description: "Set the destination database ID for transfer",
|
117
|
+
})
|
118
|
+
.option("fromCollectionId", {
|
119
|
+
alias: ["fromCollId", "fromColl"],
|
120
|
+
type: "string",
|
121
|
+
description: "Set the source collection ID for transfer",
|
122
|
+
})
|
123
|
+
.option("toCollectionId", {
|
124
|
+
alias: ["toCollId", "toColl"],
|
125
|
+
type: "string",
|
126
|
+
description: "Set the destination collection ID for transfer",
|
127
|
+
})
|
128
|
+
.option("fromBucketId", {
|
129
|
+
alias: ["fromBucket"],
|
130
|
+
type: "string",
|
131
|
+
description: "Set the source bucket ID for transfer",
|
132
|
+
})
|
133
|
+
.option("toBucketId", {
|
134
|
+
alias: ["toBucket"],
|
135
|
+
type: "string",
|
136
|
+
description: "Set the destination bucket ID for transfer",
|
137
|
+
})
|
138
|
+
.option("remoteEndpoint", {
|
139
|
+
type: "string",
|
140
|
+
description: "Set the remote Appwrite endpoint for transfers",
|
141
|
+
})
|
142
|
+
.option("remoteProjectId", {
|
143
|
+
type: "string",
|
144
|
+
description: "Set the remote Appwrite project ID for transfers",
|
145
|
+
})
|
146
|
+
.option("remoteApiKey", {
|
147
|
+
type: "string",
|
148
|
+
description: "Set the remote Appwrite API key for transfers",
|
149
|
+
});
|
150
|
+
})
|
151
|
+
.help()
|
152
|
+
.parse();
|
153
|
+
|
154
|
+
async function main() {
|
155
|
+
const parsedArgv = (await argv) as ParsedArgv;
|
156
|
+
const controller = new UtilsController(process.cwd());
|
157
|
+
await controller.init();
|
158
|
+
|
159
|
+
if (parsedArgv.it) {
|
160
|
+
const cli = new InteractiveCLI(process.cwd(), controller);
|
161
|
+
await cli.run();
|
162
|
+
} else {
|
163
|
+
// Handle non-interactive mode with the new options
|
164
|
+
const options: SetupOptions = {
|
165
|
+
databases: parsedArgv.dbIds
|
166
|
+
? await controller.getDatabasesByIds(
|
167
|
+
parsedArgv.dbIds.replace(" ", "").split(",")
|
168
|
+
)
|
169
|
+
: undefined,
|
170
|
+
collections: parsedArgv.collectionIds
|
171
|
+
? parsedArgv.collectionIds.replace(" ", "").split(",")
|
172
|
+
: undefined,
|
173
|
+
doBackup: parsedArgv.backup,
|
174
|
+
wipeDatabase: parsedArgv.wipe === "all" || parsedArgv.wipe === "docs",
|
175
|
+
wipeDocumentStorage: parsedArgv.wipe === "all",
|
176
|
+
wipeUsers: parsedArgv.wipe === "all" || parsedArgv.wipe === "users",
|
177
|
+
generateSchemas: parsedArgv.generate,
|
178
|
+
importData: parsedArgv.import,
|
179
|
+
checkDuplicates: false,
|
180
|
+
shouldWriteFile: parsedArgv.writeData,
|
181
|
+
};
|
182
|
+
|
183
|
+
if (parsedArgv.push) {
|
184
|
+
await controller.syncDb();
|
185
|
+
}
|
186
|
+
|
187
|
+
if (
|
188
|
+
options.wipeDatabase ||
|
189
|
+
options.wipeDocumentStorage ||
|
190
|
+
options.wipeUsers
|
191
|
+
) {
|
192
|
+
if (options.wipeDatabase) {
|
193
|
+
for (const db of options.databases || []) {
|
194
|
+
await controller.wipeDatabase(db);
|
195
|
+
}
|
196
|
+
}
|
197
|
+
if (options.wipeDocumentStorage && parsedArgv.bucketIds) {
|
198
|
+
for (const bucketId of parsedArgv.bucketIds.split(",")) {
|
199
|
+
await controller.wipeDocumentStorage(bucketId);
|
200
|
+
}
|
201
|
+
}
|
202
|
+
if (options.wipeUsers) {
|
203
|
+
await controller.wipeUsers();
|
204
|
+
}
|
205
|
+
}
|
206
|
+
|
207
|
+
if (options.doBackup) {
|
208
|
+
for (const db of options.databases || []) {
|
209
|
+
await controller.backupDatabase(db);
|
210
|
+
}
|
211
|
+
}
|
212
|
+
|
213
|
+
if (options.generateSchemas) {
|
214
|
+
await controller.generateSchemas();
|
215
|
+
}
|
216
|
+
|
217
|
+
if (options.importData) {
|
218
|
+
await controller.importData(options);
|
219
|
+
}
|
220
|
+
|
221
|
+
if (parsedArgv.transfer) {
|
222
|
+
const isRemote = !!parsedArgv.remoteEndpoint;
|
223
|
+
const fromDb = await controller.getDatabasesByIds([parsedArgv.fromDbId!]);
|
224
|
+
let toDb: Models.Database | undefined;
|
225
|
+
let targetDatabases: Databases | undefined;
|
226
|
+
let targetStorage: Storage | undefined;
|
227
|
+
|
228
|
+
if (isRemote) {
|
229
|
+
if (
|
230
|
+
!parsedArgv.remoteEndpoint ||
|
231
|
+
!parsedArgv.remoteProjectId ||
|
232
|
+
!parsedArgv.remoteApiKey
|
233
|
+
) {
|
234
|
+
throw new Error("Remote transfer details are missing");
|
235
|
+
}
|
236
|
+
const remoteClient = getClient(
|
237
|
+
parsedArgv.remoteEndpoint,
|
238
|
+
parsedArgv.remoteProjectId,
|
239
|
+
parsedArgv.remoteApiKey
|
240
|
+
);
|
241
|
+
targetDatabases = new Databases(remoteClient);
|
242
|
+
targetStorage = new Storage(remoteClient);
|
243
|
+
const remoteDbs = await targetDatabases.list();
|
244
|
+
toDb = remoteDbs.databases.find((db) => db.$id === parsedArgv.toDbId);
|
245
|
+
} else {
|
246
|
+
toDb = (await controller.getDatabasesByIds([parsedArgv.toDbId!]))[0];
|
247
|
+
}
|
248
|
+
|
249
|
+
if (!fromDb[0] || !toDb) {
|
250
|
+
throw new Error("Source or target database not found");
|
251
|
+
}
|
252
|
+
|
253
|
+
let sourceBucket, targetBucket;
|
254
|
+
if (parsedArgv.fromBucketId) {
|
255
|
+
sourceBucket = await controller.storage?.getBucket(
|
256
|
+
parsedArgv.fromBucketId
|
257
|
+
);
|
258
|
+
}
|
259
|
+
if (parsedArgv.toBucketId) {
|
260
|
+
if (isRemote) {
|
261
|
+
targetBucket = await targetStorage?.getBucket(parsedArgv.toBucketId);
|
262
|
+
} else {
|
263
|
+
targetBucket = await controller.storage?.getBucket(
|
264
|
+
parsedArgv.toBucketId
|
265
|
+
);
|
266
|
+
}
|
267
|
+
}
|
268
|
+
|
269
|
+
const transferOptions: TransferOptions = {
|
270
|
+
isRemote,
|
271
|
+
fromDb: fromDb[0],
|
272
|
+
targetDb: toDb,
|
273
|
+
transferEndpoint: parsedArgv.remoteEndpoint,
|
274
|
+
transferProject: parsedArgv.remoteProjectId,
|
275
|
+
transferKey: parsedArgv.remoteApiKey,
|
276
|
+
sourceBucket: sourceBucket,
|
277
|
+
targetBucket: targetBucket,
|
278
|
+
};
|
279
|
+
|
280
|
+
await controller.transferData(transferOptions);
|
281
|
+
}
|
282
|
+
|
283
|
+
if (parsedArgv.sync) {
|
284
|
+
await controller.synchronizeConfigurations(options.databases);
|
285
|
+
}
|
286
|
+
}
|
287
|
+
}
|
288
|
+
|
289
|
+
main().catch((error) => {
|
290
|
+
console.error("An error occurred:", error);
|
291
|
+
process.exit(1);
|
292
|
+
});
|