api-def 0.9.1 → 0.9.3
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/cjs/Api.d.ts +35 -35
- package/cjs/Api.js +140 -144
- package/cjs/ApiConstants.d.ts +58 -58
- package/cjs/ApiConstants.js +55 -55
- package/cjs/ApiTypes.d.ts +103 -103
- package/cjs/ApiTypes.js +4 -4
- package/cjs/ApiUtils.d.ts +6 -6
- package/cjs/ApiUtils.js +51 -53
- package/cjs/Endpoint.d.ts +52 -52
- package/cjs/Endpoint.js +104 -108
- package/cjs/EndpointBuilder.d.ts +14 -14
- package/cjs/EndpointBuilder.js +46 -46
- package/cjs/MockingTypes.d.ts +30 -30
- package/cjs/MockingTypes.js +2 -2
- package/cjs/QueryHandling.d.ts +3 -3
- package/cjs/QueryHandling.js +24 -24
- package/cjs/RequestConfig.d.ts +2 -2
- package/cjs/RequestConfig.js +74 -74
- package/cjs/RequestContext.d.ts +48 -48
- package/cjs/RequestContext.js +235 -238
- package/cjs/RequestError.d.ts +30 -30
- package/cjs/RequestError.js +47 -47
- package/cjs/Requester.d.ts +3 -3
- package/cjs/Requester.js +335 -336
- package/cjs/TextDecoding.d.ts +1 -1
- package/cjs/TextDecoding.js +152 -139
- package/cjs/UtilTypes.d.ts +5 -5
- package/cjs/UtilTypes.js +2 -2
- package/cjs/Utils.d.ts +15 -15
- package/cjs/Utils.js +79 -77
- package/cjs/Validation.d.ts +8 -8
- package/cjs/Validation.js +2 -2
- package/cjs/backend/AxiosRequestBackend.d.ts +13 -13
- package/cjs/backend/AxiosRequestBackend.js +99 -99
- package/cjs/backend/FetchRequestBackend.d.ts +15 -15
- package/cjs/backend/FetchRequestBackend.js +203 -202
- package/cjs/backend/MockRequestBackend.d.ts +11 -11
- package/cjs/backend/MockRequestBackend.js +164 -164
- package/cjs/backend/RequestBackend.d.ts +19 -19
- package/cjs/backend/RequestBackend.js +2 -2
- package/cjs/cache/CacheBackend.d.ts +6 -6
- package/cjs/cache/CacheBackend.js +2 -2
- package/cjs/cache/Caching.d.ts +10 -10
- package/cjs/cache/Caching.js +88 -88
- package/cjs/cache/LocalForageCacheBackend.d.ts +9 -9
- package/cjs/cache/LocalForageCacheBackend.js +24 -24
- package/cjs/cache/LocalStorageCacheBackend.d.ts +7 -7
- package/cjs/cache/LocalStorageCacheBackend.js +77 -77
- package/cjs/index.d.ts +13 -13
- package/cjs/index.js +41 -41
- package/cjs/middleware/CacheMiddleware.d.ts +7 -7
- package/cjs/middleware/CacheMiddleware.js +107 -107
- package/cjs/middleware/LoggingMiddleware.d.ts +6 -6
- package/cjs/middleware/LoggingMiddleware.js +82 -88
- package/cjs/util/retry/index.d.ts +3 -3
- package/cjs/util/retry/index.js +52 -52
- package/cjs/util/retry/lib/retry.d.ts +3 -3
- package/cjs/util/retry/lib/retry.js +50 -54
- package/cjs/util/retry/lib/retryOperation.d.ts +27 -27
- package/cjs/util/retry/lib/retryOperation.js +130 -134
- package/esm/Api.d.ts +35 -35
- package/esm/Api.js +92 -98
- package/esm/ApiConstants.d.ts +58 -58
- package/esm/ApiConstants.js +52 -52
- package/esm/ApiTypes.d.ts +103 -103
- package/esm/ApiTypes.js +1 -1
- package/esm/ApiUtils.d.ts +6 -6
- package/esm/ApiUtils.js +43 -45
- package/esm/Endpoint.d.ts +52 -52
- package/esm/Endpoint.js +66 -70
- package/esm/EndpointBuilder.d.ts +14 -14
- package/esm/EndpointBuilder.js +31 -31
- package/esm/MockingTypes.d.ts +30 -30
- package/esm/MockingTypes.js +1 -1
- package/esm/QueryHandling.d.ts +3 -3
- package/esm/QueryHandling.js +19 -19
- package/esm/RequestConfig.d.ts +2 -2
- package/esm/RequestConfig.js +56 -56
- package/esm/RequestContext.d.ts +48 -48
- package/esm/RequestContext.js +167 -170
- package/esm/RequestError.d.ts +30 -30
- package/esm/RequestError.js +42 -42
- package/esm/Requester.d.ts +3 -3
- package/esm/Requester.js +252 -253
- package/esm/TextDecoding.d.ts +1 -1
- package/esm/TextDecoding.js +148 -135
- package/esm/UtilTypes.d.ts +5 -5
- package/esm/UtilTypes.js +1 -1
- package/esm/Utils.d.ts +15 -15
- package/esm/Utils.js +66 -68
- package/esm/Validation.d.ts +8 -8
- package/esm/Validation.js +1 -1
- package/esm/backend/AxiosRequestBackend.d.ts +13 -13
- package/esm/backend/AxiosRequestBackend.js +62 -62
- package/esm/backend/FetchRequestBackend.d.ts +15 -15
- package/esm/backend/FetchRequestBackend.js +136 -136
- package/esm/backend/MockRequestBackend.d.ts +11 -11
- package/esm/backend/MockRequestBackend.js +116 -116
- package/esm/backend/RequestBackend.d.ts +19 -19
- package/esm/backend/RequestBackend.js +1 -1
- package/esm/cache/CacheBackend.d.ts +6 -6
- package/esm/cache/CacheBackend.js +1 -1
- package/esm/cache/Caching.d.ts +10 -10
- package/esm/cache/Caching.js +39 -39
- package/esm/cache/LocalForageCacheBackend.d.ts +9 -9
- package/esm/cache/LocalForageCacheBackend.js +20 -20
- package/esm/cache/LocalStorageCacheBackend.d.ts +7 -7
- package/esm/cache/LocalStorageCacheBackend.js +32 -32
- package/esm/index.d.ts +13 -13
- package/esm/index.js +14 -15
- package/esm/middleware/CacheMiddleware.d.ts +7 -7
- package/esm/middleware/CacheMiddleware.js +58 -58
- package/esm/middleware/LoggingMiddleware.d.ts +6 -6
- package/esm/middleware/LoggingMiddleware.js +77 -83
- package/esm/util/retry/index.d.ts +3 -3
- package/esm/util/retry/index.js +50 -50
- package/esm/util/retry/lib/retry.d.ts +3 -3
- package/esm/util/retry/lib/retry.js +35 -39
- package/esm/util/retry/lib/retryOperation.d.ts +27 -27
- package/esm/util/retry/lib/retryOperation.js +126 -132
- package/package.json +19 -34
|
@@ -1,88 +1,82 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var _a;
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var LogType;
|
|
8
|
-
(function (LogType) {
|
|
9
|
-
LogType[LogType["Info"] = 0] = "Info";
|
|
10
|
-
LogType[LogType["Success"] = 1] = "Success";
|
|
11
|
-
LogType[LogType["Error"] = 2] = "Error";
|
|
12
|
-
LogType[LogType["Warn"] = 3] = "Warn";
|
|
13
|
-
})(LogType || (LogType = {}));
|
|
14
|
-
var COLOR_MAP = (_a = {},
|
|
15
|
-
_a[LogType.Error] = "#c8646c",
|
|
16
|
-
_a[LogType.Info] = "#85a6c7",
|
|
17
|
-
_a[LogType.Success] = "#a9c490",
|
|
18
|
-
_a[LogType.Warn] = "#d19a66",
|
|
19
|
-
_a);
|
|
20
|
-
var diagnoseError = function (error) {
|
|
21
|
-
if (!error.response) {
|
|
22
|
-
if (ApiUtils.isNetworkError(error)) {
|
|
23
|
-
return { message: "network issue", error: error };
|
|
24
|
-
}
|
|
25
|
-
if (ApiUtils.isCancelledError(error)) {
|
|
26
|
-
return { message: "cancelled", error: error };
|
|
27
|
-
}
|
|
28
|
-
return { message: "client-side error", error: error };
|
|
29
|
-
}
|
|
30
|
-
var _a = error.response, status = _a.status, data = _a.data;
|
|
31
|
-
var code = data === null || data === void 0 ? void 0 : data.code;
|
|
32
|
-
return {
|
|
33
|
-
message: "responded with ".concat(status).concat(code ? " (".concat(code, ")") : ""),
|
|
34
|
-
response: error.response,
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
|
-
var formatTime = function (time) {
|
|
38
|
-
return "".concat(Utils.padNumber(time.getHours(), 2), ":").concat(Utils.padNumber(time.getMinutes(), 2), ":").concat(Utils.padNumber(time.getSeconds(), 2), ".").concat(Utils.padNumber(time.getMilliseconds(), 3));
|
|
39
|
-
};
|
|
40
|
-
var log = function (context, type, message, config, objects) {
|
|
41
|
-
if (typeof config.predicate === "function" && !config.predicate()) {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
var color = COLOR_MAP[type];
|
|
45
|
-
var timestamp = formatTime(new Date());
|
|
46
|
-
var args = [
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
},
|
|
72
|
-
_a[ApiConstants_1.RequestEvent.
|
|
73
|
-
if (context.error) {
|
|
74
|
-
var _a = diagnoseError(context.error), error = _a.error, message = _a.message;
|
|
75
|
-
log(context, LogType.
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
},
|
|
86
|
-
_a;
|
|
87
|
-
};
|
|
88
|
-
exports.default = LoggingMiddleware;
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
var ApiConstants_1 = require("../ApiConstants");
|
|
5
|
+
var ApiUtils = require("../ApiUtils");
|
|
6
|
+
var Utils = require("../Utils");
|
|
7
|
+
var LogType;
|
|
8
|
+
(function (LogType) {
|
|
9
|
+
LogType[LogType["Info"] = 0] = "Info";
|
|
10
|
+
LogType[LogType["Success"] = 1] = "Success";
|
|
11
|
+
LogType[LogType["Error"] = 2] = "Error";
|
|
12
|
+
LogType[LogType["Warn"] = 3] = "Warn";
|
|
13
|
+
})(LogType || (LogType = {}));
|
|
14
|
+
var COLOR_MAP = (_a = {},
|
|
15
|
+
_a[LogType.Error] = "#c8646c",
|
|
16
|
+
_a[LogType.Info] = "#85a6c7",
|
|
17
|
+
_a[LogType.Success] = "#a9c490",
|
|
18
|
+
_a[LogType.Warn] = "#d19a66",
|
|
19
|
+
_a);
|
|
20
|
+
var diagnoseError = function (error) {
|
|
21
|
+
if (!error.response) {
|
|
22
|
+
if (ApiUtils.isNetworkError(error)) {
|
|
23
|
+
return { message: "network issue", error: error };
|
|
24
|
+
}
|
|
25
|
+
if (ApiUtils.isCancelledError(error)) {
|
|
26
|
+
return { message: "cancelled", error: error };
|
|
27
|
+
}
|
|
28
|
+
return { message: "client-side error", error: error };
|
|
29
|
+
}
|
|
30
|
+
var _a = error.response, status = _a.status, data = _a.data;
|
|
31
|
+
var code = data === null || data === void 0 ? void 0 : data.code;
|
|
32
|
+
return {
|
|
33
|
+
message: "responded with ".concat(status).concat(code ? " (".concat(code, ")") : ""),
|
|
34
|
+
response: error.response,
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
var formatTime = function (time) {
|
|
38
|
+
return "".concat(Utils.padNumber(time.getHours(), 2), ":").concat(Utils.padNumber(time.getMinutes(), 2), ":").concat(Utils.padNumber(time.getSeconds(), 2), ".").concat(Utils.padNumber(time.getMilliseconds(), 3));
|
|
39
|
+
};
|
|
40
|
+
var log = function (context, type, message, config, objects) {
|
|
41
|
+
if (typeof config.predicate === "function" && !config.predicate()) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
var color = COLOR_MAP[type];
|
|
45
|
+
var timestamp = formatTime(new Date());
|
|
46
|
+
var args = ["%cnetwork %c[".concat(context.api.name, "] ").concat(context.method.toUpperCase(), " ").concat(context.path, " %c").concat(message, " %c@ ").concat(timestamp), "color:gray", "color:auto", "color:".concat(color), "color:gray"];
|
|
47
|
+
/* eslint-disable-next-line no-console */
|
|
48
|
+
console.groupCollapsed.apply(console, args);
|
|
49
|
+
/* eslint-disable-next-line no-console */
|
|
50
|
+
console.log(Utils.assign({ context: context }, objects || {}));
|
|
51
|
+
/* eslint-disable-next-line no-console */
|
|
52
|
+
console.groupEnd();
|
|
53
|
+
};
|
|
54
|
+
var LoggingMiddleware = function (config) {
|
|
55
|
+
var _a;
|
|
56
|
+
if (config === void 0) { config = {}; }
|
|
57
|
+
return _a = {},
|
|
58
|
+
_a[ApiConstants_1.RequestEvent.BeforeSend] = function (context) {
|
|
59
|
+
log(context, LogType.Info, context.stats.attempt > 1 ? "retrying" : "sending", config);
|
|
60
|
+
},
|
|
61
|
+
_a[ApiConstants_1.RequestEvent.Success] = function (context) {
|
|
62
|
+
var _a;
|
|
63
|
+
var cacheSource = context.cacheInfo.source;
|
|
64
|
+
log(context, LogType.Success, "responded with ".concat((_a = context.response) === null || _a === void 0 ? void 0 : _a.status).concat(cacheSource ? " (cached by ".concat(cacheSource, ")") : ""), config);
|
|
65
|
+
},
|
|
66
|
+
_a[ApiConstants_1.RequestEvent.Error] = function (context) {
|
|
67
|
+
if (context.error) {
|
|
68
|
+
var _a = diagnoseError(context.error), error = _a.error, message = _a.message;
|
|
69
|
+
log(context, LogType.Warn, "error on attempt ".concat(context.stats.attempt, " - ").concat(message), config, { error: error });
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
_a[ApiConstants_1.RequestEvent.UnrecoverableError] = function (context) {
|
|
73
|
+
if (context.error) {
|
|
74
|
+
var _a = diagnoseError(context.error), error = _a.error, message = _a.message;
|
|
75
|
+
log(context, LogType.Error, "failed - ".concat(message), config, {
|
|
76
|
+
error: error,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
_a;
|
|
81
|
+
};
|
|
82
|
+
exports.default = LoggingMiddleware;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { RetryFunction, RetryOptions } from "./interfaces";
|
|
2
|
-
declare const retry: <A>(fn: RetryFunction<A>, opts: RetryOptions) => Promise<A>;
|
|
3
|
-
export default retry;
|
|
1
|
+
import { RetryFunction, RetryOptions } from "./interfaces";
|
|
2
|
+
declare const retry: <A>(fn: RetryFunction<A>, opts: RetryOptions) => Promise<A>;
|
|
3
|
+
export default retry;
|
package/cjs/util/retry/index.js
CHANGED
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var retrier = require("./lib/retry");
|
|
4
|
-
// Retry is just transplanted from here:
|
|
5
|
-
// https://www.npmjs.com/package/retry (lib), and
|
|
6
|
-
// https://www.npmjs.com/package/async-retry (RetryFunction)
|
|
7
|
-
// ---
|
|
8
|
-
var retry = function (fn, opts) {
|
|
9
|
-
return new Promise(function (resolve, reject) {
|
|
10
|
-
var options = opts || {};
|
|
11
|
-
if (!("randomize" in options)) {
|
|
12
|
-
options.randomize = true;
|
|
13
|
-
}
|
|
14
|
-
var op = retrier.operation(options);
|
|
15
|
-
// We allow the user to abort retrying
|
|
16
|
-
// this makes sense in the cases where
|
|
17
|
-
// knowledge is obtained that retrying
|
|
18
|
-
// would be futile (e.g.: auth errors)
|
|
19
|
-
var bail = function (err) {
|
|
20
|
-
reject(err || new Error("Aborted"));
|
|
21
|
-
};
|
|
22
|
-
var onError = function (err, num) {
|
|
23
|
-
if (err.bail) {
|
|
24
|
-
bail(err);
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
if (!op.retry(err)) {
|
|
28
|
-
reject(op.mainError());
|
|
29
|
-
}
|
|
30
|
-
else if (options.onRetry) {
|
|
31
|
-
options.onRetry(err, num);
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
var runAttempt = function (num) {
|
|
35
|
-
var val;
|
|
36
|
-
try {
|
|
37
|
-
val = fn(bail, num);
|
|
38
|
-
}
|
|
39
|
-
catch (err) {
|
|
40
|
-
onError(err, num);
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
Promise.resolve(val)
|
|
44
|
-
.then(resolve)
|
|
45
|
-
.catch(function catchIt(err) {
|
|
46
|
-
onError(err, num);
|
|
47
|
-
});
|
|
48
|
-
};
|
|
49
|
-
op.attempt(runAttempt);
|
|
50
|
-
});
|
|
51
|
-
};
|
|
52
|
-
exports.default = retry;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var retrier = require("./lib/retry");
|
|
4
|
+
// Retry is just transplanted from here:
|
|
5
|
+
// https://www.npmjs.com/package/retry (lib), and
|
|
6
|
+
// https://www.npmjs.com/package/async-retry (RetryFunction)
|
|
7
|
+
// ---
|
|
8
|
+
var retry = function (fn, opts) {
|
|
9
|
+
return new Promise(function (resolve, reject) {
|
|
10
|
+
var options = opts || {};
|
|
11
|
+
if (!("randomize" in options)) {
|
|
12
|
+
options.randomize = true;
|
|
13
|
+
}
|
|
14
|
+
var op = retrier.operation(options);
|
|
15
|
+
// We allow the user to abort retrying
|
|
16
|
+
// this makes sense in the cases where
|
|
17
|
+
// knowledge is obtained that retrying
|
|
18
|
+
// would be futile (e.g.: auth errors)
|
|
19
|
+
var bail = function (err) {
|
|
20
|
+
reject(err || new Error("Aborted"));
|
|
21
|
+
};
|
|
22
|
+
var onError = function (err, num) {
|
|
23
|
+
if (err.bail) {
|
|
24
|
+
bail(err);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (!op.retry(err)) {
|
|
28
|
+
reject(op.mainError());
|
|
29
|
+
}
|
|
30
|
+
else if (options.onRetry) {
|
|
31
|
+
options.onRetry(err, num);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
var runAttempt = function (num) {
|
|
35
|
+
var val;
|
|
36
|
+
try {
|
|
37
|
+
val = fn(bail, num);
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
onError(err, num);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
Promise.resolve(val)
|
|
44
|
+
.then(resolve)
|
|
45
|
+
.catch(function catchIt(err) {
|
|
46
|
+
onError(err, num);
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
op.attempt(runAttempt);
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
exports.default = retry;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { RetryOptions } from "../interfaces";
|
|
2
|
-
import RetryOperation from "./retryOperation";
|
|
3
|
-
export declare const operation: (options: RetryOptions) => RetryOperation;
|
|
1
|
+
import { RetryOptions } from "../interfaces";
|
|
2
|
+
import RetryOperation from "./retryOperation";
|
|
3
|
+
export declare const operation: (options: RetryOptions) => RetryOperation;
|
|
@@ -1,54 +1,50 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.operation = void 0;
|
|
15
|
-
var retryOperation_1 = require("./retryOperation");
|
|
16
|
-
var operation = function (options) {
|
|
17
|
-
var timeouts = _timeouts(options);
|
|
18
|
-
return
|
|
19
|
-
forever: options && (options.forever || options.retries === Infinity),
|
|
20
|
-
unref: options
|
|
21
|
-
maxRetryTime: options
|
|
22
|
-
})
|
|
23
|
-
};
|
|
24
|
-
exports.operation = operation;
|
|
25
|
-
var _timeouts = function (options) {
|
|
26
|
-
var _a;
|
|
27
|
-
var createTimeout = function (attempt, opts) {
|
|
28
|
-
var random =
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
var
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return a - b;
|
|
52
|
-
});
|
|
53
|
-
return (timeouts);
|
|
54
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.operation = void 0;
|
|
15
|
+
var retryOperation_1 = require("./retryOperation");
|
|
16
|
+
var operation = function (options) {
|
|
17
|
+
var timeouts = _timeouts(options);
|
|
18
|
+
return new retryOperation_1.default(timeouts, {
|
|
19
|
+
forever: options && (options.forever || options.retries === Infinity),
|
|
20
|
+
unref: options === null || options === void 0 ? void 0 : options.unref,
|
|
21
|
+
maxRetryTime: options === null || options === void 0 ? void 0 : options.maxRetryTime,
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
exports.operation = operation;
|
|
25
|
+
var _timeouts = function (options) {
|
|
26
|
+
var _a;
|
|
27
|
+
var createTimeout = function (attempt, opts) {
|
|
28
|
+
var random = opts.randomize ? Math.random() + 1 : 1;
|
|
29
|
+
var timeout = Math.round(random * Math.max(opts.minTimeout, 1) * Math.pow(opts.factor, attempt));
|
|
30
|
+
timeout = Math.min(timeout, opts.maxTimeout);
|
|
31
|
+
return timeout;
|
|
32
|
+
};
|
|
33
|
+
var defaultRetries = 10;
|
|
34
|
+
var opts = __assign({ retries: defaultRetries, factor: 2, minTimeout: 1 * 1000, maxTimeout: Infinity, randomize: false }, options);
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
36
|
+
if (opts.minTimeout > opts.maxTimeout) {
|
|
37
|
+
throw new Error("minTimeout is greater than maxTimeout");
|
|
38
|
+
}
|
|
39
|
+
var timeouts = [];
|
|
40
|
+
var numRetries = (_a = opts.retries) !== null && _a !== void 0 ? _a : defaultRetries;
|
|
41
|
+
for (var i = 0; i < numRetries; i++) {
|
|
42
|
+
timeouts.push(createTimeout(i, opts));
|
|
43
|
+
}
|
|
44
|
+
if ((options === null || options === void 0 ? void 0 : options.forever) && !timeouts.length) {
|
|
45
|
+
timeouts.push(createTimeout(numRetries, opts));
|
|
46
|
+
}
|
|
47
|
+
// sort the array numerically ascending
|
|
48
|
+
timeouts.sort(function (a, b) { return a - b; });
|
|
49
|
+
return timeouts;
|
|
50
|
+
};
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
export default RetryOperation;
|
|
2
|
-
declare function RetryOperation(timeouts: any, options: any): void;
|
|
3
|
-
declare class RetryOperation {
|
|
4
|
-
constructor(timeouts: any, options: any);
|
|
5
|
-
_originalTimeouts: any;
|
|
6
|
-
_timeouts: any;
|
|
7
|
-
_options: any;
|
|
8
|
-
_maxRetryTime: any;
|
|
9
|
-
_fn: any;
|
|
10
|
-
_errors: any[];
|
|
11
|
-
_attempts: number;
|
|
12
|
-
_operationTimeout: any;
|
|
13
|
-
_operationTimeoutCb: any;
|
|
14
|
-
_timeout: NodeJS.Timeout | null;
|
|
15
|
-
_operationStart: number | null;
|
|
16
|
-
_timer: NodeJS.Timeout | null;
|
|
17
|
-
_cachedTimeouts: any;
|
|
18
|
-
reset(): void;
|
|
19
|
-
stop(): void;
|
|
20
|
-
retry(err: any): boolean;
|
|
21
|
-
attempt(fn: any, timeoutOps: any): void;
|
|
22
|
-
try(fn: any): void;
|
|
23
|
-
start: (fn: any) => void;
|
|
24
|
-
errors(): any[];
|
|
25
|
-
attempts(): number;
|
|
26
|
-
mainError(): any;
|
|
27
|
-
}
|
|
1
|
+
export default RetryOperation;
|
|
2
|
+
declare function RetryOperation(timeouts: any, options: any): void;
|
|
3
|
+
declare class RetryOperation {
|
|
4
|
+
constructor(timeouts: any, options: any);
|
|
5
|
+
_originalTimeouts: any;
|
|
6
|
+
_timeouts: any;
|
|
7
|
+
_options: any;
|
|
8
|
+
_maxRetryTime: any;
|
|
9
|
+
_fn: any;
|
|
10
|
+
_errors: any[];
|
|
11
|
+
_attempts: number;
|
|
12
|
+
_operationTimeout: any;
|
|
13
|
+
_operationTimeoutCb: any;
|
|
14
|
+
_timeout: NodeJS.Timeout | null;
|
|
15
|
+
_operationStart: number | null;
|
|
16
|
+
_timer: NodeJS.Timeout | null;
|
|
17
|
+
_cachedTimeouts: any;
|
|
18
|
+
reset(): void;
|
|
19
|
+
stop(): void;
|
|
20
|
+
retry(err: any): boolean;
|
|
21
|
+
attempt(fn: any, timeoutOps: any): void;
|
|
22
|
+
try(fn: any): void;
|
|
23
|
+
start: (fn: any) => void;
|
|
24
|
+
errors(): any[];
|
|
25
|
+
attempts(): number;
|
|
26
|
+
mainError(): any;
|
|
27
|
+
}
|