appwrite-utils-cli 0.0.19 → 0.0.20

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.
@@ -59,6 +59,7 @@ export class ImportController {
59
59
  await this.importCollections(db);
60
60
  await resolveAndUpdateRelationships(db.$id, this.database, this.config);
61
61
  await this.executePostImportActions(db.$id);
62
+ await this.executePostImportActions(db.$id);
62
63
  console.log(`---------------------------------`);
63
64
  console.log(`Finished import data for database: ${db.name}`);
64
65
  console.log(`---------------------------------`);
@@ -207,23 +208,19 @@ export class ImportController {
207
208
  const attributeMappingsWithActions = this.getAttributeMappingsWithActions(importDef.attributeMappings, afterImportActionContext, finalItem);
208
209
  if (attributeMappingsWithActions.some((m) => m.postImportActions)) {
209
210
  logger.info(`Pushing to post-import actions queue for ${context.docId}`);
210
- // const afterImportOperationContext = ContextObject.parse({
211
- // dbId: db.$id,
212
- // collectionId: collection.$id,
213
- // finalItem: finalItem,
214
- // attributeMappings: attributeMappingsWithActions,
215
- // context: afterImportActionContext,
216
- // });
217
- // await createOrFindAfterImportOperation(
218
- // this.database,
219
- // context.collId,
220
- // afterImportOperationContext
221
- // );
222
- this.postImportActionsQueue.push({
223
- context: afterImportActionContext,
211
+ const afterImportOperationContext = ContextObject.parse({
212
+ dbId: db.$id,
213
+ collectionId: collection.$id,
224
214
  finalItem: finalItem,
225
215
  attributeMappings: attributeMappingsWithActions,
216
+ context: afterImportActionContext,
226
217
  });
218
+ await createOrFindAfterImportOperation(this.database, context.collId, afterImportOperationContext);
219
+ // this.postImportActionsQueue.push({
220
+ // context: afterImportActionContext,
221
+ // finalItem: finalItem,
222
+ // attributeMappings: attributeMappingsWithActions,
223
+ // });
227
224
  }
228
225
  }));
229
226
  results.forEach((result) => {
@@ -318,33 +315,41 @@ export class ImportController {
318
315
  });
319
316
  }
320
317
  async executePostImportActions(dbId) {
321
- let actionQueue = [];
322
- for (const action of this.postImportActionsQueue) {
323
- actionQueue.push(this.importDataActions.executeAfterImportActions(action.finalItem, action.attributeMappings, action.context));
324
- }
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)
318
+ // let actionQueue: Promise<any>[] = [];
319
+ // for (const action of this.postImportActionsQueue) {
320
+ // actionQueue.push(
321
+ // this.importDataActions.executeAfterImportActions(
322
+ // action.finalItem,
323
+ // action.attributeMappings,
324
+ // action.context
325
+ // )
340
326
  // );
341
327
  // }
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
- // });
328
+ // const BATCH_LIMIT = 5;
329
+ // const splitQueue = _.chunk(actionQueue, BATCH_LIMIT);
330
+ // for (const queue of splitQueue) {
331
+ // const results = await Promise.allSettled(queue);
332
+ // results.forEach((result) => {
333
+ // if (result.status === "rejected") {
334
+ // console.error("An action promise was rejected:", result.reason);
335
+ // logger.error(
336
+ // `An action promise was rejected: ${
337
+ // result.reason
338
+ // } -- ${JSON.stringify(result)}`
339
+ // );
340
+ // }
341
+ // });
342
+ // }
343
+ const collectionActionsPromises = [];
344
+ for (const collection of this.config.collections) {
345
+ collectionActionsPromises.push(this.executeActionsInParallel(dbId, collection));
346
+ }
347
+ const results = await Promise.allSettled(collectionActionsPromises);
348
+ results.forEach((result) => {
349
+ if (result.status === "rejected") {
350
+ console.error("A process batch promise was rejected:", result.reason);
351
+ }
352
+ });
348
353
  }
349
354
  async executeActionsInParallel(dbId, collection) {
350
355
  const collectionExists = await checkForCollection(this.database, dbId, collection);
@@ -69,11 +69,7 @@ export const getAfterImportOperations = async (database, collectionId) => {
69
69
  export const setAllPendingAfterImportActionsToReady = async (database, dbId, collectionId) => {
70
70
  let lastDocumentId;
71
71
  do {
72
- const query = [
73
- Query.equal("collectionId", collectionId),
74
- Query.equal("status", "pending"),
75
- Query.limit(100),
76
- ];
72
+ const query = [Query.equal("collectionId", collectionId), Query.limit(100)];
77
73
  if (lastDocumentId) {
78
74
  query.push(Query.cursorAfter(lastDocumentId));
79
75
  }
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.19",
4
+ "version": "0.0.20",
5
5
  "main": "src/main.ts",
6
6
  "type": "module",
7
7
  "repository": {
@@ -104,6 +104,7 @@ export class ImportController {
104
104
  await this.importCollections(db);
105
105
  await resolveAndUpdateRelationships(db.$id, this.database!, this.config!);
106
106
  await this.executePostImportActions(db.$id);
107
+ await this.executePostImportActions(db.$id);
107
108
  console.log(`---------------------------------`);
108
109
  console.log(`Finished import data for database: ${db.name}`);
109
110
  console.log(`---------------------------------`);
@@ -357,23 +358,23 @@ export class ImportController {
357
358
  logger.info(
358
359
  `Pushing to post-import actions queue for ${context.docId}`
359
360
  );
360
- // const afterImportOperationContext = ContextObject.parse({
361
- // dbId: db.$id,
362
- // collectionId: collection.$id,
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,
361
+ const afterImportOperationContext = ContextObject.parse({
362
+ dbId: db.$id,
363
+ collectionId: collection.$id,
374
364
  finalItem: finalItem,
375
365
  attributeMappings: attributeMappingsWithActions,
366
+ context: afterImportActionContext,
376
367
  });
368
+ await createOrFindAfterImportOperation(
369
+ this.database,
370
+ context.collId,
371
+ afterImportOperationContext
372
+ );
373
+ // this.postImportActionsQueue.push({
374
+ // context: afterImportActionContext,
375
+ // finalItem: finalItem,
376
+ // attributeMappings: attributeMappingsWithActions,
377
+ // });
377
378
  }
378
379
  })
379
380
  );
@@ -512,43 +513,43 @@ export class ImportController {
512
513
  }
513
514
 
514
515
  async executePostImportActions(dbId: string) {
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
- )
523
- );
524
- }
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)
516
+ // let actionQueue: Promise<any>[] = [];
517
+ // for (const action of this.postImportActionsQueue) {
518
+ // actionQueue.push(
519
+ // this.importDataActions.executeAfterImportActions(
520
+ // action.finalItem,
521
+ // action.attributeMappings,
522
+ // action.context
523
+ // )
544
524
  // );
545
525
  // }
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
- // });
526
+ // const BATCH_LIMIT = 5;
527
+ // const splitQueue = _.chunk(actionQueue, BATCH_LIMIT);
528
+ // for (const queue of splitQueue) {
529
+ // const results = await Promise.allSettled(queue);
530
+ // results.forEach((result) => {
531
+ // if (result.status === "rejected") {
532
+ // console.error("An action promise was rejected:", result.reason);
533
+ // logger.error(
534
+ // `An action promise was rejected: ${
535
+ // result.reason
536
+ // } -- ${JSON.stringify(result)}`
537
+ // );
538
+ // }
539
+ // });
540
+ // }
541
+ const collectionActionsPromises = [];
542
+ for (const collection of this.config.collections) {
543
+ collectionActionsPromises.push(
544
+ this.executeActionsInParallel(dbId, collection)
545
+ );
546
+ }
547
+ const results = await Promise.allSettled(collectionActionsPromises);
548
+ results.forEach((result) => {
549
+ if (result.status === "rejected") {
550
+ console.error("A process batch promise was rejected:", result.reason);
551
+ }
552
+ });
552
553
  }
553
554
 
554
555
  async executeActionsInParallel(dbId: string, collection: ConfigCollection) {
@@ -111,11 +111,7 @@ export const setAllPendingAfterImportActionsToReady = async (
111
111
  ) => {
112
112
  let lastDocumentId: string | undefined;
113
113
  do {
114
- const query = [
115
- Query.equal("collectionId", collectionId),
116
- Query.equal("status", "pending"),
117
- Query.limit(100),
118
- ];
114
+ const query = [Query.equal("collectionId", collectionId), Query.limit(100)];
119
115
 
120
116
  if (lastDocumentId) {
121
117
  query.push(Query.cursorAfter(lastDocumentId));