@orioro/util 0.6.0 → 0.7.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 +18 -4
- package/dist/promise/batchFn.d.ts +2 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -523,7 +523,8 @@ function batchFn(itemFn, _a) {
|
|
|
523
523
|
skip = _b.skip,
|
|
524
524
|
_d = _b.retry,
|
|
525
525
|
retry = _d === void 0 ? false : _d,
|
|
526
|
-
timeout = _b.timeout
|
|
526
|
+
timeout = _b.timeout,
|
|
527
|
+
rollback = _b.rollback;
|
|
527
528
|
//
|
|
528
529
|
// Optionally wrap itemFn into timeout
|
|
529
530
|
//
|
|
@@ -550,11 +551,11 @@ function batchFn(itemFn, _a) {
|
|
|
550
551
|
});
|
|
551
552
|
return [4 /*yield*/, Promise.all(batchItems.map(function (item) {
|
|
552
553
|
return __awaiter(_this, void 0, void 0, function () {
|
|
553
|
-
var itemSkip, itemResult, _a, err_1;
|
|
554
|
+
var itemSkip, itemResult, _a, err_1, rollbackErr_1;
|
|
554
555
|
return __generator(this, function (_b) {
|
|
555
556
|
switch (_b.label) {
|
|
556
557
|
case 0:
|
|
557
|
-
_b.trys.push([0, 5,,
|
|
558
|
+
_b.trys.push([0, 5,, 10]);
|
|
558
559
|
promise.emit('itemStart', {
|
|
559
560
|
batch: batch,
|
|
560
561
|
item: item
|
|
@@ -601,8 +602,21 @@ function batchFn(itemFn, _a) {
|
|
|
601
602
|
item: item,
|
|
602
603
|
result: err_1
|
|
603
604
|
});
|
|
604
|
-
return [
|
|
605
|
+
if (!(typeof rollback === 'function')) return [3 /*break*/, 9];
|
|
606
|
+
_b.label = 6;
|
|
605
607
|
case 6:
|
|
608
|
+
_b.trys.push([6, 8,, 9]);
|
|
609
|
+
return [4 /*yield*/, rollback(item, err_1)];
|
|
610
|
+
case 7:
|
|
611
|
+
_b.sent();
|
|
612
|
+
return [3 /*break*/, 9];
|
|
613
|
+
case 8:
|
|
614
|
+
rollbackErr_1 = _b.sent();
|
|
615
|
+
console.error('Failure rolling back', rollbackErr_1);
|
|
616
|
+
return [3 /*break*/, 9];
|
|
617
|
+
case 9:
|
|
618
|
+
return [2 /*return*/, err_1];
|
|
619
|
+
case 10:
|
|
606
620
|
return [2 /*return*/];
|
|
607
621
|
}
|
|
608
622
|
});
|
|
@@ -5,6 +5,7 @@ type BatchFnOptions = {
|
|
|
5
5
|
batchSize?: number;
|
|
6
6
|
retry?: BackoffOptions | boolean;
|
|
7
7
|
timeout?: number | false;
|
|
8
|
+
rollback?: (input: any, err: any) => Promise<any> | any;
|
|
8
9
|
};
|
|
9
10
|
type Batch = {
|
|
10
11
|
index: number;
|
|
@@ -40,7 +41,7 @@ type EventTypes = {
|
|
|
40
41
|
}) => void;
|
|
41
42
|
error: (err: Error) => void;
|
|
42
43
|
};
|
|
43
|
-
export declare function batchFn(itemFn: (input: any) => Promise<any> | any, { batchSize, skip, retry, timeout }?: BatchFnOptions): (items: any[]) => PromiseLikeEventEmitter<any[], EventTypes>;
|
|
44
|
+
export declare function batchFn(itemFn: (input: any) => Promise<any> | any, { batchSize, skip, retry, timeout, rollback, }?: BatchFnOptions): (items: any[]) => PromiseLikeEventEmitter<any[], EventTypes>;
|
|
44
45
|
type ParsedBatchResults = {
|
|
45
46
|
results: any[];
|
|
46
47
|
errors: Error[];
|