@bitbeater/ecma-utils 2.10.0 → 2.10.1
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/net/http/http.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export type OnRetryParams = {
|
|
2
2
|
request: Request | string | URL;
|
|
3
3
|
requestInit?: RequestInit;
|
|
4
|
-
options?: RequestOptions;
|
|
5
4
|
response?: Response;
|
|
6
5
|
error?: Error;
|
|
7
6
|
retryCount: number;
|
|
@@ -18,23 +17,19 @@ export interface HttpRetryOptions {
|
|
|
18
17
|
maxRetries?: number;
|
|
19
18
|
onRetry?: RetryCallBack;
|
|
20
19
|
}
|
|
21
|
-
export interface
|
|
22
|
-
retry?: HttpRetryOptions;
|
|
23
|
-
timeout?: number;
|
|
24
|
-
}
|
|
25
|
-
export interface HttpRequest extends Request {
|
|
20
|
+
export interface HttpRequestInit extends RequestInit {
|
|
26
21
|
timeout?: number;
|
|
27
22
|
retry?: HttpRetryOptions;
|
|
28
23
|
}
|
|
29
|
-
type HttpRequestInput = Request | string | URL;
|
|
24
|
+
export type HttpRequestInput = Request | string | URL;
|
|
30
25
|
/**
|
|
31
|
-
*
|
|
26
|
+
* @abstraction http is a wrapper around the Fetch API that adds support for request timeouts and retries.
|
|
32
27
|
* @param request
|
|
33
28
|
* @param requestInit
|
|
34
|
-
* @
|
|
35
|
-
* @
|
|
29
|
+
* @returns Promise<Response>
|
|
30
|
+
* @throws HttpError - if the response status is not ok (2xx).
|
|
31
|
+
* @throws Error - if the request fails due to network errors.
|
|
36
32
|
*/
|
|
37
|
-
export declare function http(request: HttpRequestInput, requestInit?:
|
|
38
|
-
export declare function toURL(httpRequest:
|
|
39
|
-
export {};
|
|
33
|
+
export declare function http(request: HttpRequestInput, requestInit?: HttpRequestInit): Promise<Response>;
|
|
34
|
+
export declare function toURL(httpRequest: HttpRequestInput): URL;
|
|
40
35
|
//# sourceMappingURL=http.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/net/http/http.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,aAAa,GAAG;IAC3B,OAAO,EAAE,OAAO,GAAG,MAAM,GAAG,GAAG,CAAC;IAChC,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/net/http/http.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,aAAa,GAAG;IAC3B,OAAO,EAAE,OAAO,GAAG,MAAM,GAAG,GAAG,CAAC;IAChC,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,WAAW,EAAE,aAAa,KAAK,IAAI,GAAG,IAAI,CAAC;AAExE,MAAM,WAAW,gBAAgB;IAChC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,aAAa,CAAC;CACxB;AAID,MAAM,WAAW,eAAgB,SAAQ,WAAW;IACnD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,gBAAgB,CAAC;CACzB;AAED,MAAM,MAAM,gBAAgB,GAAG,OAAO,GAAG,MAAM,GAAG,GAAG,CAAC;AAGtD;;;;;;;GAOG;AACH,wBAAgB,IAAI,CAAC,OAAO,EAAE,gBAAgB,EAAE,WAAW,GAAE,eAAoB,GAAG,OAAO,CAAC,QAAQ,CAAC,CAuCpG;AAED,wBAAgB,KAAK,CAAC,WAAW,EAAE,gBAAgB,GAAG,GAAG,CAGxD"}
|
package/dist/net/http/http.js
CHANGED
|
@@ -6,17 +6,18 @@ const math_1 = require("../../math");
|
|
|
6
6
|
const promises_1 = require("../../promises");
|
|
7
7
|
const errors_1 = require("./errors");
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* @abstraction http is a wrapper around the Fetch API that adds support for request timeouts and retries.
|
|
10
10
|
* @param request
|
|
11
11
|
* @param requestInit
|
|
12
|
-
* @
|
|
13
|
-
* @
|
|
12
|
+
* @returns Promise<Response>
|
|
13
|
+
* @throws HttpError - if the response status is not ok (2xx).
|
|
14
|
+
* @throws Error - if the request fails due to network errors.
|
|
14
15
|
*/
|
|
15
|
-
function http(request, requestInit = {}
|
|
16
|
-
const { reqTimeOutTimer, controller } = requestTimeout(
|
|
16
|
+
function http(request, requestInit = {}) {
|
|
17
|
+
const { reqTimeOutTimer, controller } = requestTimeout(requestInit);
|
|
17
18
|
let retryCount = 0;
|
|
18
|
-
const maxRetries = (0, math_1.parseIntOrZero)(
|
|
19
|
-
const retryDelay = (0, math_1.parseIntOrZero)(
|
|
19
|
+
const maxRetries = (0, math_1.parseIntOrZero)(requestInit?.retry?.maxRetries);
|
|
20
|
+
const retryDelay = (0, math_1.parseIntOrZero)(requestInit?.retry?.retryDelay);
|
|
20
21
|
if (requestInit.signal)
|
|
21
22
|
controller?.signal?.addEventListener('abort', e => requestInit.signal?.dispatchEvent(e));
|
|
22
23
|
else
|
|
@@ -37,7 +38,7 @@ function http(request, requestInit = {}, options) {
|
|
|
37
38
|
if (retryCount >= maxRetries - 1)
|
|
38
39
|
throw error;
|
|
39
40
|
retryCount++;
|
|
40
|
-
const abort =
|
|
41
|
+
const abort = requestInit?.retry?.onRetry?.({ request, requestInit, retryCount, error, response });
|
|
41
42
|
if (abort)
|
|
42
43
|
throw error;
|
|
43
44
|
return (0, promises_1.delay)(retryDelay).then(() => doRequest());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../../src/net/http/http.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"http.js","sourceRo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