@common.js/p-retry 5.1.2 → 6.0.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/README.md +1 -1
- package/index.d.ts +6 -10
- package/index.js +49 -65
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
|
|
3
3
|
The [p-retry](https://www.npmjs.com/package/p-retry) package exported as CommonJS modules.
|
|
4
4
|
|
|
5
|
-
Exported from [p-retry@
|
|
5
|
+
Exported from [p-retry@6.0.0](https://www.npmjs.com/package/p-retry/v/6.0.0) using https://github.com/etienne-martin/common.js.
|
package/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {OperationOptions} from 'retry';
|
|
1
|
+
import {type OperationOptions} from 'retry';
|
|
2
2
|
|
|
3
3
|
export class AbortError extends Error {
|
|
4
4
|
readonly name: 'AbortError';
|
|
@@ -12,12 +12,12 @@ export class AbortError extends Error {
|
|
|
12
12
|
constructor(message: string | Error);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
export
|
|
15
|
+
export type FailedAttemptError = {
|
|
16
16
|
readonly attemptNumber: number;
|
|
17
17
|
readonly retriesLeft: number;
|
|
18
|
-
}
|
|
18
|
+
} & Error;
|
|
19
19
|
|
|
20
|
-
export
|
|
20
|
+
export type Options = {
|
|
21
21
|
/**
|
|
22
22
|
Callback invoked on each retry. Receives the error thrown by `input` as the first argument with properties `attemptNumber` and `retriesLeft` which indicate the current attempt number and the number of attempts left, respectively.
|
|
23
23
|
|
|
@@ -44,10 +44,6 @@ export interface Options extends OperationOptions {
|
|
|
44
44
|
/**
|
|
45
45
|
You can abort retrying using [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController).
|
|
46
46
|
|
|
47
|
-
When `AbortController.abort(reason)` is called, the promise will be rejected with `reason` as the error message.
|
|
48
|
-
|
|
49
|
-
*Requires Node.js 16 or later.*
|
|
50
|
-
|
|
51
47
|
```
|
|
52
48
|
import pRetry from 'p-retry';
|
|
53
49
|
|
|
@@ -55,7 +51,7 @@ export interface Options extends OperationOptions {
|
|
|
55
51
|
const controller = new AbortController();
|
|
56
52
|
|
|
57
53
|
cancelButton.addEventListener('click', () => {
|
|
58
|
-
controller.abort('User clicked cancel button');
|
|
54
|
+
controller.abort(new Error('User clicked cancel button'));
|
|
59
55
|
});
|
|
60
56
|
|
|
61
57
|
try {
|
|
@@ -67,7 +63,7 @@ export interface Options extends OperationOptions {
|
|
|
67
63
|
```
|
|
68
64
|
*/
|
|
69
65
|
readonly signal?: AbortSignal;
|
|
70
|
-
}
|
|
66
|
+
} & OperationOptions;
|
|
71
67
|
|
|
72
68
|
/**
|
|
73
69
|
Returns a `Promise` that is fulfilled when calling `input` returns a fulfilled promise. If calling `input` returns a rejected promise, `input` is called again until the max retries are reached, it then rejects with the last rejection reason.
|
package/index.js
CHANGED
|
@@ -347,9 +347,6 @@ var decorateErrorWithCounts = function(error, attemptNumber, options) {
|
|
|
347
347
|
var isNetworkError = function(errorMessage) {
|
|
348
348
|
return networkErrorMsgs.has(errorMessage);
|
|
349
349
|
};
|
|
350
|
-
var getDOMException = function(errorMessage) {
|
|
351
|
-
return globalThis.DOMException === undefined ? new Error(errorMessage) : new DOMException(errorMessage);
|
|
352
|
-
};
|
|
353
350
|
function pRetry(input, options) {
|
|
354
351
|
return _pRetry.apply(this, arguments);
|
|
355
352
|
}
|
|
@@ -364,9 +361,24 @@ function _pRetry() {
|
|
|
364
361
|
retries: 10
|
|
365
362
|
}, options);
|
|
366
363
|
var operation = _retry.default.operation(options);
|
|
364
|
+
var abortHandler = function() {
|
|
365
|
+
var ref;
|
|
366
|
+
operation.stop();
|
|
367
|
+
reject((ref = options.signal) === null || ref === void 0 ? void 0 : ref.reason);
|
|
368
|
+
};
|
|
369
|
+
if (options.signal && !options.signal.aborted) {
|
|
370
|
+
options.signal.addEventListener("abort", abortHandler, {
|
|
371
|
+
once: true
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
var cleanUp = function() {
|
|
375
|
+
var ref;
|
|
376
|
+
(ref = options.signal) === null || ref === void 0 ? void 0 : ref.removeEventListener("abort", abortHandler);
|
|
377
|
+
operation.stop();
|
|
378
|
+
};
|
|
367
379
|
operation.attempt(function() {
|
|
368
380
|
var _ref = _asyncToGenerator(function(attemptNumber) {
|
|
369
|
-
var error,
|
|
381
|
+
var result, error, finalError;
|
|
370
382
|
return __generator(this, function(_state) {
|
|
371
383
|
switch(_state.label){
|
|
372
384
|
case 0:
|
|
@@ -374,86 +386,67 @@ function _pRetry() {
|
|
|
374
386
|
0,
|
|
375
387
|
2,
|
|
376
388
|
,
|
|
377
|
-
|
|
389
|
+
7
|
|
378
390
|
]);
|
|
379
391
|
return [
|
|
380
392
|
4,
|
|
381
393
|
input(attemptNumber)
|
|
382
394
|
];
|
|
383
395
|
case 1:
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
396
|
+
result = _state.sent();
|
|
397
|
+
cleanUp();
|
|
398
|
+
resolve(result);
|
|
387
399
|
return [
|
|
388
400
|
3,
|
|
389
|
-
|
|
401
|
+
7
|
|
390
402
|
];
|
|
391
403
|
case 2:
|
|
392
404
|
error = _state.sent();
|
|
393
|
-
|
|
394
|
-
reject(new TypeError('Non-error was thrown: "'.concat(error, '". You should only throw errors.')));
|
|
395
|
-
return [
|
|
396
|
-
2
|
|
397
|
-
];
|
|
398
|
-
}
|
|
399
|
-
if (!_instanceof(error, AbortError)) return [
|
|
400
|
-
3,
|
|
401
|
-
3
|
|
402
|
-
];
|
|
403
|
-
operation.stop();
|
|
404
|
-
reject(error.originalError);
|
|
405
|
-
return [
|
|
406
|
-
3,
|
|
407
|
-
9
|
|
408
|
-
];
|
|
405
|
+
_state.label = 3;
|
|
409
406
|
case 3:
|
|
410
|
-
if (!(_instanceof(error, TypeError) && !isNetworkError(error.message))) return [
|
|
411
|
-
3,
|
|
412
|
-
4
|
|
413
|
-
];
|
|
414
|
-
operation.stop();
|
|
415
|
-
reject(error);
|
|
416
|
-
return [
|
|
417
|
-
3,
|
|
418
|
-
9
|
|
419
|
-
];
|
|
420
|
-
case 4:
|
|
421
|
-
decorateErrorWithCounts(error, attemptNumber, options);
|
|
422
|
-
_state.label = 5;
|
|
423
|
-
case 5:
|
|
424
407
|
_state.trys.push([
|
|
408
|
+
3,
|
|
425
409
|
5,
|
|
426
|
-
7,
|
|
427
410
|
,
|
|
428
|
-
|
|
411
|
+
6
|
|
429
412
|
]);
|
|
413
|
+
if (!_instanceof(error, Error)) {
|
|
414
|
+
throw new TypeError('Non-error was thrown: "'.concat(error, '". You should only throw errors.'));
|
|
415
|
+
}
|
|
416
|
+
if (_instanceof(error, AbortError)) {
|
|
417
|
+
throw error.originalError;
|
|
418
|
+
}
|
|
419
|
+
if (_instanceof(error, TypeError) && !isNetworkError(error.message)) {
|
|
420
|
+
throw error;
|
|
421
|
+
}
|
|
430
422
|
return [
|
|
431
423
|
4,
|
|
432
|
-
options.onFailedAttempt(error)
|
|
424
|
+
options.onFailedAttempt(decorateErrorWithCounts(error, attemptNumber, options))
|
|
433
425
|
];
|
|
434
|
-
case
|
|
426
|
+
case 4:
|
|
435
427
|
_state.sent();
|
|
428
|
+
if (!operation.retry(error)) {
|
|
429
|
+
throw operation.mainError();
|
|
430
|
+
}
|
|
436
431
|
return [
|
|
437
432
|
3,
|
|
438
|
-
|
|
433
|
+
6
|
|
439
434
|
];
|
|
440
|
-
case
|
|
441
|
-
|
|
442
|
-
|
|
435
|
+
case 5:
|
|
436
|
+
finalError = _state.sent();
|
|
437
|
+
decorateErrorWithCounts(finalError, attemptNumber, options);
|
|
438
|
+
cleanUp();
|
|
439
|
+
reject(finalError);
|
|
443
440
|
return [
|
|
444
|
-
|
|
441
|
+
3,
|
|
442
|
+
6
|
|
445
443
|
];
|
|
446
|
-
case
|
|
447
|
-
if (!operation.retry(error)) {
|
|
448
|
-
reject(operation.mainError());
|
|
449
|
-
}
|
|
450
|
-
_state.label = 9;
|
|
451
|
-
case 9:
|
|
444
|
+
case 6:
|
|
452
445
|
return [
|
|
453
446
|
3,
|
|
454
|
-
|
|
447
|
+
7
|
|
455
448
|
];
|
|
456
|
-
case
|
|
449
|
+
case 7:
|
|
457
450
|
return [
|
|
458
451
|
2
|
|
459
452
|
];
|
|
@@ -464,15 +457,6 @@ function _pRetry() {
|
|
|
464
457
|
return _ref.apply(this, arguments);
|
|
465
458
|
};
|
|
466
459
|
}());
|
|
467
|
-
if (options.signal && !options.signal.aborted) {
|
|
468
|
-
options.signal.addEventListener("abort", function() {
|
|
469
|
-
operation.stop();
|
|
470
|
-
var reason = options.signal.reason === undefined ? getDOMException("The operation was aborted.") : options.signal.reason;
|
|
471
|
-
reject(_instanceof(reason, Error) ? reason : getDOMException(reason));
|
|
472
|
-
}, {
|
|
473
|
-
once: true
|
|
474
|
-
});
|
|
475
|
-
}
|
|
476
460
|
})
|
|
477
461
|
];
|
|
478
462
|
});
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@common.js/p-retry",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0",
|
|
4
4
|
"description": "p-retry package exported as CommonJS modules",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "etienne-martin/common.js",
|
|
7
7
|
"funding": "https://github.com/sponsors/sindresorhus",
|
|
8
8
|
"type": "commonjs",
|
|
9
9
|
"engines": {
|
|
10
|
-
"node": "
|
|
10
|
+
"node": ">=16.17"
|
|
11
11
|
},
|
|
12
12
|
"scripts": {
|
|
13
13
|
"test": "xo && ava && tsd"
|
|
@@ -17,14 +17,14 @@
|
|
|
17
17
|
"index.d.ts"
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@types/retry": "0.12.
|
|
20
|
+
"@types/retry": "0.12.2",
|
|
21
21
|
"retry": "^0.13.1"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"ava": "^
|
|
25
|
-
"delay": "^
|
|
26
|
-
"tsd": "^0.
|
|
27
|
-
"xo": "^0.
|
|
24
|
+
"ava": "^5.3.1",
|
|
25
|
+
"delay": "^6.0.0",
|
|
26
|
+
"tsd": "^0.28.1",
|
|
27
|
+
"xo": "^0.56.0"
|
|
28
28
|
},
|
|
29
29
|
"homepage": "https://github.com/etienne-martin/common.js#readme",
|
|
30
30
|
"main": "./index.js"
|