keq 2.1.2 → 2.2.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/CHANGELOG.md +7 -0
- package/README.md +17 -5
- package/dist/esm/src/create-request.js +2 -0
- package/dist/esm/src/keq.d.ts +1 -0
- package/dist/esm/src/keq.js +4 -0
- package/dist/esm/src/middlewares/timeout-middleware.d.ts +2 -0
- package/dist/esm/src/middlewares/timeout-middleware.js +19 -0
- package/dist/esm/src/types/keq-options.d.ts +2 -0
- package/dist/esm/src/types/keq-timeout.d.ts +3 -0
- package/dist/esm/src/types/keq-timeout.js +1 -0
- package/dist/umd/src/create-request.js +3 -1
- package/dist/umd/src/keq.d.ts +1 -0
- package/dist/umd/src/keq.js +4 -0
- package/dist/umd/src/middlewares/timeout-middleware.d.ts +2 -0
- package/dist/umd/src/middlewares/timeout-middleware.js +33 -0
- package/dist/umd/src/types/keq-options.d.ts +2 -0
- package/dist/umd/src/types/keq-timeout.d.ts +3 -0
- package/dist/umd/src/types/keq-timeout.js +12 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [2.2.0](https://github.com/keq-request/keq/compare/v2.1.2...v2.2.0) (2024-02-04)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* add .timeout(millisecond) ([b99009b](https://github.com/keq-request/keq/commit/b99009b6eb4a017d648a29a8b34b478dc22320ee))
|
|
11
|
+
|
|
5
12
|
## [2.1.2](https://github.com/keq-request/keq/compare/v2.1.1...v2.1.2) (2024-01-17)
|
|
6
13
|
|
|
7
14
|
|
package/README.md
CHANGED
|
@@ -6,10 +6,12 @@
|
|
|
6
6
|
<h1 align="center" style="text-align: center">KEQ</h1>
|
|
7
7
|
<!-- title -->
|
|
8
8
|
|
|
9
|
-
[
|
|
10
|
-
|
|
11
|
-
[![
|
|
12
|
-
[![
|
|
9
|
+
[npm]: https://www.npmjs.com/package/keq
|
|
10
|
+
|
|
11
|
+
[][npm]
|
|
12
|
+
[][npm]
|
|
13
|
+
[][npm]
|
|
14
|
+
[][npm]
|
|
13
15
|
[](https://codecov.io/gh/keq-request/keq)
|
|
14
16
|
|
|
15
17
|
<!-- description -->
|
|
@@ -353,6 +355,17 @@ await request
|
|
|
353
355
|
| `fetchAPI` | Replace the defaulted `fetch` function used by `Keq`. |
|
|
354
356
|
|
|
355
357
|
<!-- ###### The options with **DEPRECATED** will be removed in next major version -->
|
|
358
|
+
|
|
359
|
+
### Timeout
|
|
360
|
+
|
|
361
|
+
Keq has built-in timeout function.
|
|
362
|
+
|
|
363
|
+
```typescript
|
|
364
|
+
await request
|
|
365
|
+
.get("http://test.com")
|
|
366
|
+
// 5000 milliseconds
|
|
367
|
+
.timeout(5000)
|
|
368
|
+
```
|
|
356
369
|
|
|
357
370
|
### Flow Control
|
|
358
371
|
|
|
@@ -399,7 +412,6 @@ request
|
|
|
399
412
|
.followControl("serial", 'animal')
|
|
400
413
|
.end()
|
|
401
414
|
```
|
|
402
|
-
|
|
403
415
|
|
|
404
416
|
### Middleware
|
|
405
417
|
|
|
@@ -9,6 +9,7 @@ import { proxyResponseMiddleware } from './middlewares/proxy-response-middleware
|
|
|
9
9
|
import { retryMiddleware } from './middlewares/retry-middleware';
|
|
10
10
|
import { serialFlowControlMiddleware } from './middlewares/serial-flow-control-middleware.js';
|
|
11
11
|
import { KeqRouter } from './router/keq-router.js';
|
|
12
|
+
import { timeoutMiddleware } from './middlewares/timeout-middleware.js';
|
|
12
13
|
export function createRequest(options) {
|
|
13
14
|
let baseOrigin = options?.baseOrigin;
|
|
14
15
|
if (isBrowser() && !baseOrigin)
|
|
@@ -16,6 +17,7 @@ export function createRequest(options) {
|
|
|
16
17
|
const appendMiddlewares = options?.initMiddlewares ? [...options.initMiddlewares] : [
|
|
17
18
|
serialFlowControlMiddleware(),
|
|
18
19
|
abortFlowControlMiddleware(),
|
|
20
|
+
timeoutMiddleware(),
|
|
19
21
|
proxyResponseMiddleware(),
|
|
20
22
|
fetchArgumentsMiddleware(),
|
|
21
23
|
retryMiddleware(),
|
package/dist/esm/src/keq.d.ts
CHANGED
package/dist/esm/src/keq.js
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export function timeoutMiddleware() {
|
|
2
|
+
return async (ctx, next) => {
|
|
3
|
+
if (!ctx.options.timeout || ctx.options.timeout.millisecond <= 0) {
|
|
4
|
+
await next();
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
if (ctx.request.signal) {
|
|
8
|
+
console.warn('[keq] request signal had be set manual, abort follow control will not take effect');
|
|
9
|
+
await next();
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const timeoutSignal = new AbortController();
|
|
13
|
+
ctx.request.signal = timeoutSignal.signal;
|
|
14
|
+
setTimeout(() => {
|
|
15
|
+
timeoutSignal.abort('timeout');
|
|
16
|
+
}, ctx.options.timeout.millisecond);
|
|
17
|
+
await next();
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { KeqFlowControl } from './keq-flow-control.js';
|
|
2
2
|
import { KeqRetryDelay } from './keq-retry-delay';
|
|
3
3
|
import { KeqRetryOn } from './keq-retry-on';
|
|
4
|
+
import { KeqTimeout } from './keq-timeout.js';
|
|
4
5
|
export interface KeqBuildInOptions {
|
|
5
6
|
/**
|
|
6
7
|
* replace the default fetch api
|
|
@@ -29,6 +30,7 @@ export interface KeqBuildInOptions {
|
|
|
29
30
|
pathname: string;
|
|
30
31
|
};
|
|
31
32
|
flowControl?: KeqFlowControl;
|
|
33
|
+
timeout?: KeqTimeout;
|
|
32
34
|
}
|
|
33
35
|
export interface KeqOptionsWithFullResponse extends KeqBuildInOptions {
|
|
34
36
|
resolveWithFullResponse: true;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
if (v !== undefined) module.exports = v;
|
|
5
5
|
}
|
|
6
6
|
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports", "whatwg-url", "./is/is-browser", "./keq", "./middlewares/abort-flow-control-middleware.js", "./middlewares/fetch-arguments-middleware", "./middlewares/fetch-middleware", "./middlewares/proxy-response-middleware", "./middlewares/retry-middleware", "./middlewares/serial-flow-control-middleware.js", "./router/keq-router.js"], factory);
|
|
7
|
+
define(["require", "exports", "whatwg-url", "./is/is-browser", "./keq", "./middlewares/abort-flow-control-middleware.js", "./middlewares/fetch-arguments-middleware", "./middlewares/fetch-middleware", "./middlewares/proxy-response-middleware", "./middlewares/retry-middleware", "./middlewares/serial-flow-control-middleware.js", "./router/keq-router.js", "./middlewares/timeout-middleware.js"], factory);
|
|
8
8
|
}
|
|
9
9
|
})(function (require, exports) {
|
|
10
10
|
"use strict";
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
const retry_middleware_1 = require("./middlewares/retry-middleware");
|
|
22
22
|
const serial_flow_control_middleware_js_1 = require("./middlewares/serial-flow-control-middleware.js");
|
|
23
23
|
const keq_router_js_1 = require("./router/keq-router.js");
|
|
24
|
+
const timeout_middleware_js_1 = require("./middlewares/timeout-middleware.js");
|
|
24
25
|
function createRequest(options) {
|
|
25
26
|
let baseOrigin = options?.baseOrigin;
|
|
26
27
|
if ((0, is_browser_1.isBrowser)() && !baseOrigin)
|
|
@@ -28,6 +29,7 @@
|
|
|
28
29
|
const appendMiddlewares = options?.initMiddlewares ? [...options.initMiddlewares] : [
|
|
29
30
|
(0, serial_flow_control_middleware_js_1.serialFlowControlMiddleware)(),
|
|
30
31
|
(0, abort_flow_control_middleware_js_1.abortFlowControlMiddleware)(),
|
|
32
|
+
(0, timeout_middleware_js_1.timeoutMiddleware)(),
|
|
31
33
|
(0, proxy_response_middleware_1.proxyResponseMiddleware)(),
|
|
32
34
|
(0, fetch_arguments_middleware_1.fetchArgumentsMiddleware)(),
|
|
33
35
|
(0, retry_middleware_1.retryMiddleware)(),
|
package/dist/umd/src/keq.d.ts
CHANGED
package/dist/umd/src/keq.js
CHANGED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.timeoutMiddleware = void 0;
|
|
13
|
+
function timeoutMiddleware() {
|
|
14
|
+
return async (ctx, next) => {
|
|
15
|
+
if (!ctx.options.timeout || ctx.options.timeout.millisecond <= 0) {
|
|
16
|
+
await next();
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (ctx.request.signal) {
|
|
20
|
+
console.warn('[keq] request signal had be set manual, abort follow control will not take effect');
|
|
21
|
+
await next();
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const timeoutSignal = new AbortController();
|
|
25
|
+
ctx.request.signal = timeoutSignal.signal;
|
|
26
|
+
setTimeout(() => {
|
|
27
|
+
timeoutSignal.abort('timeout');
|
|
28
|
+
}, ctx.options.timeout.millisecond);
|
|
29
|
+
await next();
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
exports.timeoutMiddleware = timeoutMiddleware;
|
|
33
|
+
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { KeqFlowControl } from './keq-flow-control.js';
|
|
2
2
|
import { KeqRetryDelay } from './keq-retry-delay';
|
|
3
3
|
import { KeqRetryOn } from './keq-retry-on';
|
|
4
|
+
import { KeqTimeout } from './keq-timeout.js';
|
|
4
5
|
export interface KeqBuildInOptions {
|
|
5
6
|
/**
|
|
6
7
|
* replace the default fetch api
|
|
@@ -29,6 +30,7 @@ export interface KeqBuildInOptions {
|
|
|
29
30
|
pathname: string;
|
|
30
31
|
};
|
|
31
32
|
flowControl?: KeqFlowControl;
|
|
33
|
+
timeout?: KeqTimeout;
|
|
32
34
|
}
|
|
33
35
|
export interface KeqOptionsWithFullResponse extends KeqBuildInOptions {
|
|
34
36
|
resolveWithFullResponse: true;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
});
|