@izara_project/izara-core-library-asynchronous-flow 1.0.25 → 1.0.27

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/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "author": "Sven Mason <thebarbariansven@gmail.com>",
4
4
  "license": "AGPL-3.0-or-later",
5
5
  "homepage": "https://bitbucket.org/izara-core-libraries/izara-core-library-asynchronous-flow#readme",
6
- "version": "1.0.25",
6
+ "version": "1.0.27",
7
7
  "description": "Shared asynchronous flow logic",
8
8
  "type": "module",
9
9
  "main": "index.js",
@@ -300,17 +300,7 @@ export async function findAwaitingMultipleStepByPending(
300
300
  return listAwaitingSteps.Items;
301
301
  }
302
302
 
303
- /**
304
- * Same as checkAllAwaitingStepsFinished but writes errors/additionalAttributes to the *_ByPending row.
305
- * @async
306
- * @param {IzContext} _izContext
307
- * @param {string} pendingStepId
308
- * @param {string|null} [currentAwaitingStepId=null]
309
- * @param {any[]} [errorsFound=[]]
310
- * @param {Attrs} [additionalAttributes={}]
311
- * @returns {Promise<boolean>}
312
- */
313
- export async function checkAllAwaitingStepsFinished(
303
+ export async function checkAllAwaitingStepsFinishedShared(
314
304
  _izContext,
315
305
  pendingStepId,
316
306
  currentAwaitingStepId = null,
@@ -338,6 +328,35 @@ export async function checkAllAwaitingStepsFinished(
338
328
  }
339
329
  );
340
330
  }
331
+ }
332
+
333
+
334
+ /**
335
+ * Same as checkAllAwaitingStepsFinished but writes errors/additionalAttributes to the *_ByPending row.
336
+ * @async
337
+ * @param {IzContext} _izContext
338
+ * @param {string} pendingStepId
339
+ * @param {string|null} [currentAwaitingStepId=null]
340
+ * @param {any[]} [errorsFound=[]]
341
+ * @param {Attrs} [additionalAttributes={}]
342
+ * @returns {Promise<boolean>}
343
+ */
344
+ export async function checkAllAwaitingStepsFinished(
345
+ _izContext,
346
+ pendingStepId,
347
+ currentAwaitingStepId = null,
348
+ errorsFound = [],
349
+ additionalAttributes = {}
350
+ ) {
351
+
352
+ await checkAllAwaitingStepsFinishedShared(
353
+ _izContext,
354
+ pendingStepId,
355
+ currentAwaitingStepId = null,
356
+ errorsFound = [],
357
+ additionalAttributes = {}
358
+ );
359
+
341
360
  let listPendingStepIds = await dynamodbSharedLib.query(
342
361
  _izContext,
343
362
  dynamodbSharedLib.tableName(_izContext, 'AwaitingMultipleStepByPending'),
@@ -367,6 +386,67 @@ export async function checkAllAwaitingStepsFinished(
367
386
  return true; // all passed
368
387
  }
369
388
 
389
+
390
+ /**
391
+ * Checks if all awaiting steps for a pending step are complete after marking the current one as complete.
392
+ * If all steps are finished, it returns `true` and an object containing the `additionalAttributes` from each of the completed steps, indexed by their `awaitingStepId`.
393
+ * If any other step is not yet complete, it returns `[false, null]`.
394
+ * @async
395
+ * @param {IzContext} _izContext
396
+ * @param {string} pendingStepId
397
+ * @param {string|null} [currentAwaitingStepId=null] - The step that has just finished.
398
+ * @param {any[]} [errorsFound=[]]
399
+ * @param {Attrs} [additionalAttributes={}]
400
+ * @returns {Promise<[boolean, Record<string, any>|null]>} A tuple indicating completion status and the collected attributes, or null if not all steps are complete.
401
+ */
402
+ export async function checkAllAwaitingStepsFinishedWithReturnParams(
403
+ _izContext,
404
+ pendingStepId,
405
+ currentAwaitingStepId = null,
406
+ errorsFound = [],
407
+ additionalAttributes = {}
408
+ ) {
409
+
410
+ await checkAllAwaitingStepsFinishedShared(
411
+ _izContext,
412
+ pendingStepId,
413
+ currentAwaitingStepId = null,
414
+ errorsFound = [],
415
+ additionalAttributes = {}
416
+ );
417
+
418
+ const awaitingStepItems = await dynamodbSharedLib.query(
419
+ _izContext,
420
+ dynamodbSharedLib.tableName(_izContext, 'AwaitingMultipleStepByPending'),
421
+ { pendingStepId },
422
+ {
423
+ limit: 50
424
+ }
425
+ );
426
+
427
+ _izContext.logger.debug('awaitingStepItems:::', awaitingStepItems);
428
+
429
+ const collectedAttributes = {};
430
+ const collectedErrors = [];
431
+
432
+ for (const item of awaitingStepItems.Items) {
433
+ if (item.awaitingStepId !== currentAwaitingStepId && !item.complete) {
434
+ return [false, null, []];
435
+ }
436
+
437
+ if (item.errorsFound?.length > 0) {
438
+ collectedErrors.push(...item.errorsFound);
439
+ }
440
+
441
+ if (item.additionalAttributes) {
442
+ collectedAttributes[item.awaitingStepId] = item.additionalAttributes;
443
+ }
444
+ }
445
+
446
+ return [true, collectedAttributes, collectedErrors];
447
+ }
448
+
449
+
370
450
  /**
371
451
  * Remove all awaiting records for a given pendingStepId from both tables.
372
452
  * @async
@@ -487,77 +567,4 @@ export async function removeAwaitingMultipleStep(
487
567
  );
488
568
  }
489
569
  await Promise.all(promiseArray);
490
- }
491
-
492
- /**
493
- * Checks if all awaiting steps for a pending step are complete after marking the current one as complete.
494
- * If all steps are finished, it returns `true` and an object containing the `additionalAttributes` from each of the completed steps, keyed by their `awaitingStepId`.
495
- * If any other step is not yet complete, it returns `[false, null]`.
496
- * @async
497
- * @param {IzContext} _izContext
498
- * @param {string} pendingStepId
499
- * @param {string|null} [currentAwaitingStepId=null] - The step that has just finished.
500
- * @param {any[]} [errorsFound=[]]
501
- * @param {Attrs} [additionalAttributes={}]
502
- * @returns {Promise<[boolean, Record<string, any>|null]>} A tuple indicating completion status and the collected attributes, or null if not all steps are complete.
503
- */
504
- export async function syncAndCheckStepsCompletion(
505
- _izContext,
506
- pendingStepId,
507
- currentAwaitingStepId = null,
508
- errorsFound = [],
509
- additionalAttributes = {}
510
- ) {
511
- _izContext.logger.debug(
512
- 'Lib:checkAllAwaitingMultipleStepsFinishedWithErrorAndReturnAdditionalAttributes',
513
- {
514
- pendingStepId,
515
- currentAwaitingStepId,
516
- errorsFound,
517
- additionalAttributes
518
- }
519
- );
520
-
521
- if (currentAwaitingStepId) {
522
- await dynamodbSharedLib.updateItem(
523
- _izContext,
524
- dynamodbSharedLib.tableName(_izContext, 'AwaitingMultipleStepByPending'),
525
- { pendingStepId, awaitingStepId: currentAwaitingStepId },
526
- {
527
- complete: true,
528
- errorsFound,
529
- additionalAttributes
530
- }
531
- );
532
- }
533
-
534
- const awaitingStepItems = await dynamodbSharedLib.query(
535
- _izContext,
536
- dynamodbSharedLib.tableName(_izContext, 'AwaitingMultipleStepByPending'),
537
- { pendingStepId },
538
- {
539
- limit: 50
540
- }
541
- );
542
-
543
- _izContext.logger.debug('awaitingStepItems:::', awaitingStepItems);
544
-
545
- const collectedAttributes = {};
546
- const collectedErrors = [];
547
-
548
- for (const item of awaitingStepItems.Items) {
549
- if (item.awaitingStepId !== currentAwaitingStepId && !item.complete) {
550
- return [false, null, []];
551
- }
552
-
553
- if (item.errorsFound?.length > 0) {
554
- collectedErrors.push(...item.errorsFound);
555
- }
556
-
557
- if (item.additionalAttributes) {
558
- collectedAttributes[item.awaitingStepId] = item.additionalAttributes;
559
- }
560
- }
561
-
562
- return [true, collectedAttributes, collectedErrors];
563
- }
570
+ }