appwrite-utils-cli 0.0.17 → 0.0.19
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.
|
@@ -11,6 +11,7 @@ export declare class ImportController {
|
|
|
11
11
|
private setupOptions;
|
|
12
12
|
private documentCache;
|
|
13
13
|
private batchLimit;
|
|
14
|
+
private postImportActionsQueue;
|
|
14
15
|
constructor(config: AppwriteConfig, database: Databases, storage: Storage, appwriteFolderPath: string, importDataActions: ImportDataActions, setupOptions: SetupOptions);
|
|
15
16
|
run(): Promise<void>;
|
|
16
17
|
importCollections(db: ConfigDatabase): Promise<void>;
|
|
@@ -21,11 +21,7 @@ export class ImportController {
|
|
|
21
21
|
setupOptions;
|
|
22
22
|
documentCache;
|
|
23
23
|
batchLimit = 25; // Define batch size limit
|
|
24
|
-
|
|
25
|
-
// context: any;
|
|
26
|
-
// finalItem: any;
|
|
27
|
-
// attributeMappings: AttributeMappings;
|
|
28
|
-
// }[] = [];
|
|
24
|
+
postImportActionsQueue = [];
|
|
29
25
|
constructor(config, database, storage, appwriteFolderPath, importDataActions, setupOptions) {
|
|
30
26
|
this.config = config;
|
|
31
27
|
this.database = database;
|
|
@@ -211,19 +207,23 @@ export class ImportController {
|
|
|
211
207
|
const attributeMappingsWithActions = this.getAttributeMappingsWithActions(importDef.attributeMappings, afterImportActionContext, finalItem);
|
|
212
208
|
if (attributeMappingsWithActions.some((m) => m.postImportActions)) {
|
|
213
209
|
logger.info(`Pushing to post-import actions queue for ${context.docId}`);
|
|
214
|
-
const afterImportOperationContext = ContextObject.parse({
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
finalItem: finalItem,
|
|
218
|
-
attributeMappings: attributeMappingsWithActions,
|
|
219
|
-
context: afterImportActionContext,
|
|
220
|
-
});
|
|
221
|
-
await createOrFindAfterImportOperation(this.database, context.collId, afterImportOperationContext);
|
|
222
|
-
// this.postImportActionsQueue.push({
|
|
223
|
-
// context: afterImportActionContext,
|
|
210
|
+
// const afterImportOperationContext = ContextObject.parse({
|
|
211
|
+
// dbId: db.$id,
|
|
212
|
+
// collectionId: collection.$id,
|
|
224
213
|
// finalItem: finalItem,
|
|
225
214
|
// attributeMappings: attributeMappingsWithActions,
|
|
215
|
+
// context: afterImportActionContext,
|
|
226
216
|
// });
|
|
217
|
+
// await createOrFindAfterImportOperation(
|
|
218
|
+
// this.database,
|
|
219
|
+
// context.collId,
|
|
220
|
+
// afterImportOperationContext
|
|
221
|
+
// );
|
|
222
|
+
this.postImportActionsQueue.push({
|
|
223
|
+
context: afterImportActionContext,
|
|
224
|
+
finalItem: finalItem,
|
|
225
|
+
attributeMappings: attributeMappingsWithActions,
|
|
226
|
+
});
|
|
227
227
|
}
|
|
228
228
|
}));
|
|
229
229
|
results.forEach((result) => {
|
|
@@ -318,16 +318,33 @@ export class ImportController {
|
|
|
318
318
|
});
|
|
319
319
|
}
|
|
320
320
|
async executePostImportActions(dbId) {
|
|
321
|
-
|
|
322
|
-
for (const
|
|
323
|
-
|
|
321
|
+
let actionQueue = [];
|
|
322
|
+
for (const action of this.postImportActionsQueue) {
|
|
323
|
+
actionQueue.push(this.importDataActions.executeAfterImportActions(action.finalItem, action.attributeMappings, action.context));
|
|
324
324
|
}
|
|
325
|
-
const
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
325
|
+
const BATCH_LIMIT = 20;
|
|
326
|
+
const splitQueue = _.chunk(actionQueue, BATCH_LIMIT);
|
|
327
|
+
for (const queue of splitQueue) {
|
|
328
|
+
const results = await Promise.allSettled(queue);
|
|
329
|
+
results.forEach((result) => {
|
|
330
|
+
if (result.status === "rejected") {
|
|
331
|
+
console.error("An action promise was rejected:", result.reason);
|
|
332
|
+
logger.error(`An action promise was rejected: ${result.reason} -- ${JSON.stringify(result)}`);
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
// const collectionActionsPromises = [];
|
|
337
|
+
// for (const collection of this.config.collections) {
|
|
338
|
+
// collectionActionsPromises.push(
|
|
339
|
+
// this.executeActionsInParallel(dbId, collection)
|
|
340
|
+
// );
|
|
341
|
+
// }
|
|
342
|
+
// const results = await Promise.allSettled(collectionActionsPromises);
|
|
343
|
+
// results.forEach((result) => {
|
|
344
|
+
// if (result.status === "rejected") {
|
|
345
|
+
// console.error("A process batch promise was rejected:", result.reason);
|
|
346
|
+
// }
|
|
347
|
+
// });
|
|
331
348
|
}
|
|
332
349
|
async executeActionsInParallel(dbId, collection) {
|
|
333
350
|
const collectionExists = await checkForCollection(this.database, dbId, collection);
|
|
@@ -193,7 +193,7 @@ export class ImportDataActions {
|
|
|
193
193
|
resolvedString = resolvedString.replace(match[0], value);
|
|
194
194
|
}
|
|
195
195
|
else {
|
|
196
|
-
logger.warn(`Failed to resolve ${template} in context: `, context);
|
|
196
|
+
logger.warn(`Failed to resolve ${template} in context: `, JSON.stringify({ ...context, ...item }, null, 2));
|
|
197
197
|
}
|
|
198
198
|
}
|
|
199
199
|
// console.log(`Resolved string: ${resolvedString}`);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "appwrite-utils-cli",
|
|
3
3
|
"description": "Appwrite Utility Functions to help with database management, data conversion, data import, migrations, and much more. Meant to be used as a CLI tool, I do not recommend installing this in frontend environments.",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.19",
|
|
5
5
|
"main": "src/main.ts",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"repository": {
|
|
@@ -47,11 +47,11 @@ export class ImportController {
|
|
|
47
47
|
private setupOptions: SetupOptions;
|
|
48
48
|
private documentCache: Map<string, any>;
|
|
49
49
|
private batchLimit: number = 25; // Define batch size limit
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
private postImportActionsQueue: {
|
|
51
|
+
context: any;
|
|
52
|
+
finalItem: any;
|
|
53
|
+
attributeMappings: AttributeMappings;
|
|
54
|
+
}[] = [];
|
|
55
55
|
|
|
56
56
|
constructor(
|
|
57
57
|
config: AppwriteConfig,
|
|
@@ -357,23 +357,23 @@ export class ImportController {
|
|
|
357
357
|
logger.info(
|
|
358
358
|
`Pushing to post-import actions queue for ${context.docId}`
|
|
359
359
|
);
|
|
360
|
-
const afterImportOperationContext = ContextObject.parse({
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
finalItem: finalItem,
|
|
364
|
-
attributeMappings: attributeMappingsWithActions,
|
|
365
|
-
context: afterImportActionContext,
|
|
366
|
-
});
|
|
367
|
-
await createOrFindAfterImportOperation(
|
|
368
|
-
this.database,
|
|
369
|
-
context.collId,
|
|
370
|
-
afterImportOperationContext
|
|
371
|
-
);
|
|
372
|
-
// this.postImportActionsQueue.push({
|
|
373
|
-
// context: afterImportActionContext,
|
|
360
|
+
// const afterImportOperationContext = ContextObject.parse({
|
|
361
|
+
// dbId: db.$id,
|
|
362
|
+
// collectionId: collection.$id,
|
|
374
363
|
// finalItem: finalItem,
|
|
375
364
|
// attributeMappings: attributeMappingsWithActions,
|
|
365
|
+
// context: afterImportActionContext,
|
|
376
366
|
// });
|
|
367
|
+
// await createOrFindAfterImportOperation(
|
|
368
|
+
// this.database,
|
|
369
|
+
// context.collId,
|
|
370
|
+
// afterImportOperationContext
|
|
371
|
+
// );
|
|
372
|
+
this.postImportActionsQueue.push({
|
|
373
|
+
context: afterImportActionContext,
|
|
374
|
+
finalItem: finalItem,
|
|
375
|
+
attributeMappings: attributeMappingsWithActions,
|
|
376
|
+
});
|
|
377
377
|
}
|
|
378
378
|
})
|
|
379
379
|
);
|
|
@@ -512,18 +512,43 @@ export class ImportController {
|
|
|
512
512
|
}
|
|
513
513
|
|
|
514
514
|
async executePostImportActions(dbId: string) {
|
|
515
|
-
|
|
516
|
-
for (const
|
|
517
|
-
|
|
518
|
-
this.
|
|
515
|
+
let actionQueue: Promise<any>[] = [];
|
|
516
|
+
for (const action of this.postImportActionsQueue) {
|
|
517
|
+
actionQueue.push(
|
|
518
|
+
this.importDataActions.executeAfterImportActions(
|
|
519
|
+
action.finalItem,
|
|
520
|
+
action.attributeMappings,
|
|
521
|
+
action.context
|
|
522
|
+
)
|
|
519
523
|
);
|
|
520
524
|
}
|
|
521
|
-
const
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
525
|
+
const BATCH_LIMIT = 20;
|
|
526
|
+
const splitQueue = _.chunk(actionQueue, BATCH_LIMIT);
|
|
527
|
+
for (const queue of splitQueue) {
|
|
528
|
+
const results = await Promise.allSettled(queue);
|
|
529
|
+
results.forEach((result) => {
|
|
530
|
+
if (result.status === "rejected") {
|
|
531
|
+
console.error("An action promise was rejected:", result.reason);
|
|
532
|
+
logger.error(
|
|
533
|
+
`An action promise was rejected: ${
|
|
534
|
+
result.reason
|
|
535
|
+
} -- ${JSON.stringify(result)}`
|
|
536
|
+
);
|
|
537
|
+
}
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
// const collectionActionsPromises = [];
|
|
541
|
+
// for (const collection of this.config.collections) {
|
|
542
|
+
// collectionActionsPromises.push(
|
|
543
|
+
// this.executeActionsInParallel(dbId, collection)
|
|
544
|
+
// );
|
|
545
|
+
// }
|
|
546
|
+
// const results = await Promise.allSettled(collectionActionsPromises);
|
|
547
|
+
// results.forEach((result) => {
|
|
548
|
+
// if (result.status === "rejected") {
|
|
549
|
+
// console.error("A process batch promise was rejected:", result.reason);
|
|
550
|
+
// }
|
|
551
|
+
// });
|
|
527
552
|
}
|
|
528
553
|
|
|
529
554
|
async executeActionsInParallel(dbId: string, collection: ConfigCollection) {
|
|
@@ -285,7 +285,10 @@ export class ImportDataActions {
|
|
|
285
285
|
: resolvedValue;
|
|
286
286
|
resolvedString = resolvedString.replace(match[0], value);
|
|
287
287
|
} else {
|
|
288
|
-
logger.warn(
|
|
288
|
+
logger.warn(
|
|
289
|
+
`Failed to resolve ${template} in context: `,
|
|
290
|
+
JSON.stringify({ ...context, ...item }, null, 2)
|
|
291
|
+
);
|
|
289
292
|
}
|
|
290
293
|
}
|
|
291
294
|
// console.log(`Resolved string: ${resolvedString}`);
|