@orioro/util 0.3.0 → 0.4.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/dist/index.mjs CHANGED
@@ -2,6 +2,7 @@ import EventEmitter from 'eventemitter3';
2
2
  import copy from 'fast-copy';
3
3
  import { getProperty, setProperty } from 'dot-prop';
4
4
  import traverse from 'traverse';
5
+ import { backOff } from 'exponential-backoff';
5
6
 
6
7
  function _typeof(o) {
7
8
  "@babel/helpers - typeof";
@@ -477,11 +478,13 @@ function arrayChunk(array, chunkSize) {
477
478
  }
478
479
 
479
480
  var SKIPPED = Symbol();
480
- function batchFn(fn, _a) {
481
+ function batchFn(itemFn, _a) {
481
482
  var _b = _a === void 0 ? {} : _a,
482
483
  _c = _b.batchSize,
483
484
  batchSize = _c === void 0 ? 10 : _c,
484
- skip = _b.skip;
485
+ skip = _b.skip,
486
+ _d = _b.retry,
487
+ retry = _d === void 0 ? false : _d;
485
488
  return function batchExec(items) {
486
489
  var _this = this;
487
490
  var batches = arrayChunk(items, batchSize);
@@ -526,7 +529,11 @@ function batchFn(fn, _a) {
526
529
  _a = SKIPPED;
527
530
  return [3 /*break*/, 4];
528
531
  case 2:
529
- return [4 /*yield*/, fn(item)];
532
+ return [4 /*yield*/, retry === true ? backOff(function () {
533
+ return itemFn(item);
534
+ }) : _typeof(retry) === 'object' && retry !== null ? backOff(function () {
535
+ return itemFn(item);
536
+ }, retry) : itemFn(item)];
530
537
  case 3:
531
538
  _a = _b.sent();
532
539
  _b.label = 4;
@@ -1,7 +1,9 @@
1
1
  import { PromiseLikeEventEmitter } from '../PromiseLikeEventEmitter';
2
+ import { BackoffOptions } from 'exponential-backoff';
2
3
  type BatchFnOptions = {
3
4
  skip?: (input: any) => Promise<boolean> | boolean;
4
5
  batchSize?: number;
6
+ retry?: BackoffOptions | boolean;
5
7
  };
6
8
  type Batch = {
7
9
  index: number;
@@ -37,7 +39,7 @@ type EventTypes = {
37
39
  }) => void;
38
40
  error: (err: Error) => void;
39
41
  };
40
- export declare function batchFn(fn: (input: any) => Promise<any> | any, { batchSize, skip }?: BatchFnOptions): (items: any[]) => PromiseLikeEventEmitter<any[], EventTypes>;
42
+ export declare function batchFn(itemFn: (input: any) => Promise<any> | any, { batchSize, skip, retry }?: BatchFnOptions): (items: any[]) => PromiseLikeEventEmitter<any[], EventTypes>;
41
43
  type ParsedBatchResults = {
42
44
  results: any[];
43
45
  errors: Error[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orioro/util",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "packageManager": "yarn@4.0.2",
5
5
  "type": "module",
6
6
  "main": "dist/index.mjs",
@@ -34,6 +34,7 @@
34
34
  "dependencies": {
35
35
  "dot-prop": "^8.0.2",
36
36
  "eventemitter3": "^5.0.1",
37
+ "exponential-backoff": "^3.1.1",
37
38
  "fast-copy": "^3.0.2",
38
39
  "traverse": "^0.6.9",
39
40
  "type-fest": "^4.18.1"