keq 2.7.4 → 2.8.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 +14 -0
- package/README.md +1 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/src/core.d.ts +5 -1
- package/dist/esm/src/core.js +8 -2
- package/dist/esm/src/create-request.js +10 -9
- package/dist/esm/src/is/is-blob.js +1 -0
- package/dist/esm/src/is/is-buffer.js +1 -0
- package/dist/esm/src/is/is-file.js +1 -0
- package/dist/esm/src/is/is-form-data.js +1 -0
- package/dist/esm/src/is/is-function.js +1 -0
- package/dist/esm/src/is/is-headers.js +1 -0
- package/dist/esm/src/is/is-object.js +1 -0
- package/dist/esm/src/is/is-url-search-params.js +1 -0
- package/dist/esm/src/keq.js +2 -3
- package/dist/esm/src/types/keq-context.d.ts +26 -10
- package/dist/esm/src/types/keq-context.js +1 -0
- package/dist/esm/src/util/assign-keq-request-body.js +1 -1
- package/dist/esm/src/util/clone-body.js +1 -0
- package/dist/esm/src/util/get-unique-code-identifier.d.ts +1 -1
- package/dist/esm/src/util/get-unique-code-identifier.js +1 -1
- package/dist/esm/src/util/shallow-clone.js +1 -0
- package/dist/umd/package.json +1 -0
- package/dist/umd/src/core.d.ts +5 -1
- package/dist/umd/src/core.js +8 -2
- package/dist/umd/src/create-request.js +11 -10
- package/dist/umd/src/is/is-blob.js +1 -0
- package/dist/umd/src/is/is-buffer.js +1 -0
- package/dist/umd/src/is/is-file.js +1 -0
- package/dist/umd/src/is/is-form-data.js +1 -0
- package/dist/umd/src/is/is-function.js +1 -0
- package/dist/umd/src/is/is-headers.js +1 -0
- package/dist/umd/src/is/is-object.js +1 -0
- package/dist/umd/src/is/is-url-search-params.js +1 -0
- package/dist/umd/src/keq.js +3 -4
- package/dist/umd/src/types/keq-context.d.ts +26 -10
- package/dist/umd/src/types/keq-context.js +1 -0
- package/dist/umd/src/util/assign-keq-request-body.js +1 -1
- package/dist/umd/src/util/clone-body.js +1 -0
- package/dist/umd/src/util/get-unique-code-identifier.d.ts +1 -1
- package/dist/umd/src/util/get-unique-code-identifier.js +1 -1
- package/dist/umd/src/util/shallow-clone.js +1 -0
- package/package.json +16 -17
- package/.node-version +0 -1
- package/.vscode/settings.json +0 -5
- package/__tests__/node/abort.spec.ts +0 -110
- package/__tests__/node/request.ts +0 -51
- package/__tests__/node/resolve-with-mode.spec.ts +0 -48
- package/__tests__/node/retry.spec.ts +0 -35
- package/__tests__/node/send-request-with-body.spec.ts +0 -107
- package/__tests__/node/send-simple-request.spec.ts +0 -121
- package/__tests__/node/timeout.spec.ts +0 -48
- package/__tests__/setup.ts +0 -32
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,20 @@
|
|
|
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.8.0](https://github.com/keq-request/keq/compare/v2.7.5...v2.8.0) (2024-09-11)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* add the unique identifier of the request's location in the code ([e9eb95f](https://github.com/keq-request/keq/commit/e9eb95fc09bfaf59884379be9b50962660c9574f))
|
|
11
|
+
|
|
12
|
+
## [2.7.5](https://github.com/keq-request/keq/compare/v2.7.4...v2.7.5) (2024-09-10)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
* cannot import esm ([e6c1cfb](https://github.com/keq-request/keq/commit/e6c1cfb3c283e7cd3d44cd7d60d30aaf7a380ecc))
|
|
18
|
+
|
|
5
19
|
## [2.7.4](https://github.com/keq-request/keq/compare/v2.7.3...v2.7.4) (2024-08-19)
|
|
6
20
|
|
|
7
21
|
|
package/README.md
CHANGED
|
@@ -526,6 +526,7 @@ Keq's context object has many parameters. The following lists all the built-in c
|
|
|
526
526
|
| `context.res` | The origin [`Response`][Response MDN] Class. It will be undefined before run `await next()` or error throwed. |
|
|
527
527
|
| `context.response` | Cloned from `ctx.res`. |
|
|
528
528
|
| `context.output` | Custom return value of `await request()`。 It only take effect when `resolveWith` is not set or set to 'intelligent'. **This property is writeonly.** |
|
|
529
|
+
| `content.identifier` | The unique identifier of the request's location in the code. It is used as default key of FlowControl and Cache.
|
|
529
530
|
|
|
530
531
|
#### .useRouter()
|
|
531
532
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type": "module"}
|
package/dist/esm/src/core.d.ts
CHANGED
|
@@ -7,6 +7,10 @@ import type { KeqContextRequest } from './types/keq-context-request.js';
|
|
|
7
7
|
* @description Keq 核心 API,发送请求必要的原子化的API
|
|
8
8
|
*/
|
|
9
9
|
export declare class Core<OUTPUT> {
|
|
10
|
+
/**
|
|
11
|
+
* The unique identifier of the request's location in the code
|
|
12
|
+
*/
|
|
13
|
+
__identifier__: string;
|
|
10
14
|
private requestPromise?;
|
|
11
15
|
protected requestContext: Omit<KeqContextRequest, 'abort' | '__url__'>;
|
|
12
16
|
protected __listeners__: KeqListeners;
|
|
@@ -14,7 +18,7 @@ export declare class Core<OUTPUT> {
|
|
|
14
18
|
protected __prepend_middlewares__: KeqMiddleware[];
|
|
15
19
|
protected __append_middlewares__: KeqMiddleware[];
|
|
16
20
|
protected __options__: KeqContextOptions;
|
|
17
|
-
constructor(url: URL, init: KeqInit, global?: Record<string, any>);
|
|
21
|
+
constructor(url: URL, init: KeqInit, identifier: string, global?: Record<string, any>);
|
|
18
22
|
prependMiddlewares(...middlewares: KeqMiddleware[]): this;
|
|
19
23
|
appendMiddlewares(...middlewares: KeqMiddleware[]): this;
|
|
20
24
|
on<K extends keyof KeqEvents>(event: K, listener: (data: KeqEvents[K]) => void): this;
|
package/dist/esm/src/core.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
1
2
|
import mitt from 'mitt';
|
|
2
3
|
import { Exception } from './exception/exception.js';
|
|
3
4
|
import { cloneBody } from './util/clone-body.js';
|
|
@@ -9,6 +10,10 @@ import { compileUrl } from './util/compile-url.js';
|
|
|
9
10
|
* @description Keq 核心 API,发送请求必要的原子化的API
|
|
10
11
|
*/
|
|
11
12
|
export class Core {
|
|
13
|
+
/**
|
|
14
|
+
* The unique identifier of the request's location in the code
|
|
15
|
+
*/
|
|
16
|
+
__identifier__;
|
|
12
17
|
requestPromise;
|
|
13
18
|
requestContext;
|
|
14
19
|
__listeners__ = {};
|
|
@@ -19,8 +24,9 @@ export class Core {
|
|
|
19
24
|
resolveWithFullResponse: false,
|
|
20
25
|
resolveWith: 'intelligent',
|
|
21
26
|
};
|
|
22
|
-
constructor(url, init, global = {}) {
|
|
27
|
+
constructor(url, init, identifier, global = {}) {
|
|
23
28
|
this.__global__ = global;
|
|
29
|
+
this.__identifier__ = identifier;
|
|
24
30
|
this.requestContext = {
|
|
25
31
|
method: 'get',
|
|
26
32
|
headers: new Headers(),
|
|
@@ -80,6 +86,7 @@ export class Core {
|
|
|
80
86
|
entryNextTimes: 0,
|
|
81
87
|
outNextTimes: 0,
|
|
82
88
|
},
|
|
89
|
+
identifier: this.__identifier__,
|
|
83
90
|
emitter,
|
|
84
91
|
request: requestContext,
|
|
85
92
|
options,
|
|
@@ -99,7 +106,6 @@ export class Core {
|
|
|
99
106
|
},
|
|
100
107
|
};
|
|
101
108
|
const middleware = composeMiddleware([...this.__prepend_middlewares__, ...this.__append_middlewares__]);
|
|
102
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
103
109
|
await middleware(ctx, async function emptyNext() { });
|
|
104
110
|
const output = ctx[OUTPUT_PROPERTY];
|
|
105
111
|
if (ctx.options.resolveWithFullResponse || ctx.options.resolveWith === 'response') {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
import { isBrowser } from './is/is-browser.js';
|
|
3
3
|
import { Keq } from './keq.js';
|
|
4
4
|
import { abortFlowControlMiddleware } from './middlewares/abort-flow-control-middleware.js';
|
|
@@ -9,6 +9,7 @@ import { retryMiddleware } from './middlewares/retry-middleware.js';
|
|
|
9
9
|
import { serialFlowControlMiddleware } from './middlewares/serial-flow-control-middleware.js';
|
|
10
10
|
import { KeqRouter } from './router/keq-router.js';
|
|
11
11
|
import { timeoutMiddleware } from './middlewares/timeout-middleware.js';
|
|
12
|
+
import { getUniqueCodeIdentifier } from './util/get-unique-code-identifier.js';
|
|
12
13
|
export function createRequest(options) {
|
|
13
14
|
let baseOrigin = options?.baseOrigin;
|
|
14
15
|
if (!baseOrigin) {
|
|
@@ -42,7 +43,7 @@ export function createRequest(options) {
|
|
|
42
43
|
};
|
|
43
44
|
const router = new KeqRouter(prependMiddlewares);
|
|
44
45
|
const request = function (url, init) {
|
|
45
|
-
const keq = new Keq(formatUrl(url), { ...init }, global);
|
|
46
|
+
const keq = new Keq(formatUrl(url), { ...init }, getUniqueCodeIdentifier(1), global);
|
|
46
47
|
keq.appendMiddlewares(...appendMiddlewares);
|
|
47
48
|
keq.prependMiddlewares(...prependMiddlewares);
|
|
48
49
|
return keq;
|
|
@@ -55,44 +56,44 @@ export function createRequest(options) {
|
|
|
55
56
|
return router;
|
|
56
57
|
};
|
|
57
58
|
request.get = function (url) {
|
|
58
|
-
const keq = new Keq(formatUrl(url), { method: 'get' }, global);
|
|
59
|
+
const keq = new Keq(formatUrl(url), { method: 'get' }, getUniqueCodeIdentifier(1), global);
|
|
59
60
|
keq.appendMiddlewares(...appendMiddlewares);
|
|
60
61
|
keq.prependMiddlewares(...prependMiddlewares);
|
|
61
62
|
return keq;
|
|
62
63
|
};
|
|
63
64
|
request.put = function (url) {
|
|
64
|
-
const keq = new Keq(formatUrl(url), { method: 'put' }, global);
|
|
65
|
+
const keq = new Keq(formatUrl(url), { method: 'put' }, getUniqueCodeIdentifier(1), global);
|
|
65
66
|
keq.appendMiddlewares(...appendMiddlewares);
|
|
66
67
|
keq.prependMiddlewares(...prependMiddlewares);
|
|
67
68
|
return keq;
|
|
68
69
|
};
|
|
69
70
|
request.delete = function (url) {
|
|
70
|
-
const keq = new Keq(formatUrl(url), { method: 'delete' }, global);
|
|
71
|
+
const keq = new Keq(formatUrl(url), { method: 'delete' }, getUniqueCodeIdentifier(1), global);
|
|
71
72
|
keq.appendMiddlewares(...appendMiddlewares);
|
|
72
73
|
keq.prependMiddlewares(...prependMiddlewares);
|
|
73
74
|
return keq;
|
|
74
75
|
};
|
|
75
76
|
request.del = request.delete;
|
|
76
77
|
request.post = function (url) {
|
|
77
|
-
const keq = new Keq(formatUrl(url), { method: 'post' }, global);
|
|
78
|
+
const keq = new Keq(formatUrl(url), { method: 'post' }, getUniqueCodeIdentifier(1), global);
|
|
78
79
|
keq.appendMiddlewares(...appendMiddlewares);
|
|
79
80
|
keq.prependMiddlewares(...prependMiddlewares);
|
|
80
81
|
return keq;
|
|
81
82
|
};
|
|
82
83
|
request.head = function (url) {
|
|
83
|
-
const keq = new Keq(formatUrl(url), { method: 'head' }, global);
|
|
84
|
+
const keq = new Keq(formatUrl(url), { method: 'head' }, getUniqueCodeIdentifier(1), global);
|
|
84
85
|
keq.appendMiddlewares(...appendMiddlewares);
|
|
85
86
|
keq.prependMiddlewares(...prependMiddlewares);
|
|
86
87
|
return keq;
|
|
87
88
|
};
|
|
88
89
|
request.patch = function (url) {
|
|
89
|
-
const keq = new Keq(formatUrl(url), { method: 'patch' }, global);
|
|
90
|
+
const keq = new Keq(formatUrl(url), { method: 'patch' }, getUniqueCodeIdentifier(1), global);
|
|
90
91
|
keq.appendMiddlewares(...appendMiddlewares);
|
|
91
92
|
keq.prependMiddlewares(...prependMiddlewares);
|
|
92
93
|
return keq;
|
|
93
94
|
};
|
|
94
95
|
request.options = function (url) {
|
|
95
|
-
const keq = new Keq(formatUrl(url), { method: 'options' }, global);
|
|
96
|
+
const keq = new Keq(formatUrl(url), { method: 'options' }, getUniqueCodeIdentifier(1), global);
|
|
96
97
|
keq.appendMiddlewares(...appendMiddlewares);
|
|
97
98
|
keq.prependMiddlewares(...prependMiddlewares);
|
|
98
99
|
return keq;
|
package/dist/esm/src/keq.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
1
2
|
import { Core } from './core.js';
|
|
2
3
|
import { Exception } from './exception/exception.js';
|
|
3
4
|
import { InvalidArgumentsExceptions } from './exception/invalid-arguments.exception.js';
|
|
@@ -10,7 +11,6 @@ import { isUrlSearchParams } from './is/is-url-search-params.js';
|
|
|
10
11
|
import { assignKeqRequestBody } from './util/assign-keq-request-body.js';
|
|
11
12
|
import { base64Encode } from './util/base64.js';
|
|
12
13
|
import { fixContentType } from './util/fix-content-type.js';
|
|
13
|
-
import { getUniqueCodeIdentifier } from './util/get-unique-code-identifier.js';
|
|
14
14
|
import { isValidHeaderValue } from './util/is-valid-header-value.js';
|
|
15
15
|
/**
|
|
16
16
|
* @description Keq 扩展 API,人性化的常用的API
|
|
@@ -189,7 +189,7 @@ export class Keq extends Core {
|
|
|
189
189
|
return this;
|
|
190
190
|
}
|
|
191
191
|
flowControl(mode, signal) {
|
|
192
|
-
const sig = signal ? signal :
|
|
192
|
+
const sig = signal ? signal : this.__identifier__;
|
|
193
193
|
if (!sig) {
|
|
194
194
|
throw new Exception('please set signal to .flowControl()');
|
|
195
195
|
}
|
|
@@ -206,7 +206,6 @@ export class Keq extends Core {
|
|
|
206
206
|
}
|
|
207
207
|
resolveWith(m) {
|
|
208
208
|
this.option('resolveWith', m);
|
|
209
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
210
209
|
return this;
|
|
211
210
|
}
|
|
212
211
|
}
|
|
@@ -21,31 +21,47 @@ export interface KeqContext {
|
|
|
21
21
|
};
|
|
22
22
|
[ABORT_PROPERTY]?: AbortController;
|
|
23
23
|
abort: (reason: any) => void;
|
|
24
|
-
emitter: Emitter<Omit<KeqEvents, never>>;
|
|
25
|
-
options: KeqContextOptions;
|
|
26
24
|
/**
|
|
27
|
-
*
|
|
25
|
+
* The unique identifier of the request's location in the code
|
|
28
26
|
*/
|
|
29
|
-
|
|
27
|
+
identifier: string;
|
|
28
|
+
emitter: Emitter<Omit<KeqEvents, never>>;
|
|
29
|
+
options: KeqContextOptions;
|
|
30
30
|
/**
|
|
31
31
|
* keq request context
|
|
32
32
|
*/
|
|
33
33
|
request: KeqContextRequest;
|
|
34
|
-
/**
|
|
34
|
+
/**
|
|
35
|
+
* original response
|
|
36
|
+
*/
|
|
35
37
|
res?: Response;
|
|
36
|
-
/**
|
|
38
|
+
/**
|
|
39
|
+
* proxy response
|
|
40
|
+
*/
|
|
37
41
|
response?: Response;
|
|
38
|
-
/**
|
|
42
|
+
/**
|
|
43
|
+
* the result get by user
|
|
44
|
+
*/
|
|
39
45
|
output: any;
|
|
40
46
|
[OUTPUT_PROPERTY]?: any;
|
|
41
|
-
/**
|
|
47
|
+
/**
|
|
48
|
+
* share data between requests
|
|
49
|
+
*/
|
|
42
50
|
global: KeqGlobal;
|
|
43
|
-
/**
|
|
51
|
+
/**
|
|
52
|
+
* retry information, undefined is no retry
|
|
53
|
+
*/
|
|
44
54
|
retry?: {
|
|
45
55
|
attempt: number;
|
|
46
56
|
error: unknown | null;
|
|
47
57
|
delay: number;
|
|
48
58
|
};
|
|
49
|
-
/**
|
|
59
|
+
/**
|
|
60
|
+
* Fetch API Arguments
|
|
61
|
+
*/
|
|
62
|
+
fetchArguments?: [RequestInfo | string, RequestInit];
|
|
63
|
+
/**
|
|
64
|
+
* extends by middleware
|
|
65
|
+
* */
|
|
50
66
|
[key: string]: any;
|
|
51
67
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
import { Exception } from '../exception/exception.js';
|
|
3
3
|
import { OverwriteArrayBodyException } from '../exception/overwrite-array-body.exception.js';
|
|
4
4
|
import { isFormData } from '../is/is-form-data.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function getUniqueCodeIdentifier(depth?: number): string
|
|
1
|
+
export declare function getUniqueCodeIdentifier(depth?: number): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type": "commonjs"}
|
package/dist/umd/src/core.d.ts
CHANGED
|
@@ -7,6 +7,10 @@ import type { KeqContextRequest } from './types/keq-context-request.js';
|
|
|
7
7
|
* @description Keq 核心 API,发送请求必要的原子化的API
|
|
8
8
|
*/
|
|
9
9
|
export declare class Core<OUTPUT> {
|
|
10
|
+
/**
|
|
11
|
+
* The unique identifier of the request's location in the code
|
|
12
|
+
*/
|
|
13
|
+
__identifier__: string;
|
|
10
14
|
private requestPromise?;
|
|
11
15
|
protected requestContext: Omit<KeqContextRequest, 'abort' | '__url__'>;
|
|
12
16
|
protected __listeners__: KeqListeners;
|
|
@@ -14,7 +18,7 @@ export declare class Core<OUTPUT> {
|
|
|
14
18
|
protected __prepend_middlewares__: KeqMiddleware[];
|
|
15
19
|
protected __append_middlewares__: KeqMiddleware[];
|
|
16
20
|
protected __options__: KeqContextOptions;
|
|
17
|
-
constructor(url: URL, init: KeqInit, global?: Record<string, any>);
|
|
21
|
+
constructor(url: URL, init: KeqInit, identifier: string, global?: Record<string, any>);
|
|
18
22
|
prependMiddlewares(...middlewares: KeqMiddleware[]): this;
|
|
19
23
|
appendMiddlewares(...middlewares: KeqMiddleware[]): this;
|
|
20
24
|
on<K extends keyof KeqEvents>(event: K, listener: (data: KeqEvents[K]) => void): this;
|
package/dist/umd/src/core.js
CHANGED
|
@@ -13,6 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
"use strict";
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.Core = void 0;
|
|
16
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
16
17
|
const mitt_1 = __importDefault(require("mitt"));
|
|
17
18
|
const exception_js_1 = require("./exception/exception.js");
|
|
18
19
|
const clone_body_js_1 = require("./util/clone-body.js");
|
|
@@ -24,6 +25,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
24
25
|
* @description Keq 核心 API,发送请求必要的原子化的API
|
|
25
26
|
*/
|
|
26
27
|
class Core {
|
|
28
|
+
/**
|
|
29
|
+
* The unique identifier of the request's location in the code
|
|
30
|
+
*/
|
|
31
|
+
__identifier__;
|
|
27
32
|
requestPromise;
|
|
28
33
|
requestContext;
|
|
29
34
|
__listeners__ = {};
|
|
@@ -34,8 +39,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
34
39
|
resolveWithFullResponse: false,
|
|
35
40
|
resolveWith: 'intelligent',
|
|
36
41
|
};
|
|
37
|
-
constructor(url, init, global = {}) {
|
|
42
|
+
constructor(url, init, identifier, global = {}) {
|
|
38
43
|
this.__global__ = global;
|
|
44
|
+
this.__identifier__ = identifier;
|
|
39
45
|
this.requestContext = {
|
|
40
46
|
method: 'get',
|
|
41
47
|
headers: new Headers(),
|
|
@@ -95,6 +101,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
95
101
|
entryNextTimes: 0,
|
|
96
102
|
outNextTimes: 0,
|
|
97
103
|
},
|
|
104
|
+
identifier: this.__identifier__,
|
|
98
105
|
emitter,
|
|
99
106
|
request: requestContext,
|
|
100
107
|
options,
|
|
@@ -114,7 +121,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
114
121
|
},
|
|
115
122
|
};
|
|
116
123
|
const middleware = (0, compose_middleware_js_1.composeMiddleware)([...this.__prepend_middlewares__, ...this.__append_middlewares__]);
|
|
117
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
118
124
|
await middleware(ctx, async function emptyNext() { });
|
|
119
125
|
const output = ctx[constant_js_1.OUTPUT_PROPERTY];
|
|
120
126
|
if (ctx.options.resolveWithFullResponse || ctx.options.resolveWith === 'response') {
|
|
@@ -4,13 +4,13 @@
|
|
|
4
4
|
if (v !== undefined) module.exports = v;
|
|
5
5
|
}
|
|
6
6
|
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports", "./is/is-browser.js", "./keq.js", "./middlewares/abort-flow-control-middleware.js", "./middlewares/fetch-arguments-middleware.js", "./middlewares/fetch-middleware.js", "./middlewares/proxy-response-middleware.js", "./middlewares/retry-middleware.js", "./middlewares/serial-flow-control-middleware.js", "./router/keq-router.js", "./middlewares/timeout-middleware.js"], factory);
|
|
7
|
+
define(["require", "exports", "./is/is-browser.js", "./keq.js", "./middlewares/abort-flow-control-middleware.js", "./middlewares/fetch-arguments-middleware.js", "./middlewares/fetch-middleware.js", "./middlewares/proxy-response-middleware.js", "./middlewares/retry-middleware.js", "./middlewares/serial-flow-control-middleware.js", "./router/keq-router.js", "./middlewares/timeout-middleware.js", "./util/get-unique-code-identifier.js"], factory);
|
|
8
8
|
}
|
|
9
9
|
})(function (require, exports) {
|
|
10
10
|
"use strict";
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.createRequest = void 0;
|
|
13
|
-
/* eslint-disable @typescript-eslint/no-
|
|
13
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
14
14
|
const is_browser_js_1 = require("./is/is-browser.js");
|
|
15
15
|
const keq_js_1 = require("./keq.js");
|
|
16
16
|
const abort_flow_control_middleware_js_1 = require("./middlewares/abort-flow-control-middleware.js");
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
const serial_flow_control_middleware_js_1 = require("./middlewares/serial-flow-control-middleware.js");
|
|
22
22
|
const keq_router_js_1 = require("./router/keq-router.js");
|
|
23
23
|
const timeout_middleware_js_1 = require("./middlewares/timeout-middleware.js");
|
|
24
|
+
const get_unique_code_identifier_js_1 = require("./util/get-unique-code-identifier.js");
|
|
24
25
|
function createRequest(options) {
|
|
25
26
|
let baseOrigin = options?.baseOrigin;
|
|
26
27
|
if (!baseOrigin) {
|
|
@@ -54,7 +55,7 @@
|
|
|
54
55
|
};
|
|
55
56
|
const router = new keq_router_js_1.KeqRouter(prependMiddlewares);
|
|
56
57
|
const request = function (url, init) {
|
|
57
|
-
const keq = new keq_js_1.Keq(formatUrl(url), { ...init }, global);
|
|
58
|
+
const keq = new keq_js_1.Keq(formatUrl(url), { ...init }, (0, get_unique_code_identifier_js_1.getUniqueCodeIdentifier)(1), global);
|
|
58
59
|
keq.appendMiddlewares(...appendMiddlewares);
|
|
59
60
|
keq.prependMiddlewares(...prependMiddlewares);
|
|
60
61
|
return keq;
|
|
@@ -67,44 +68,44 @@
|
|
|
67
68
|
return router;
|
|
68
69
|
};
|
|
69
70
|
request.get = function (url) {
|
|
70
|
-
const keq = new keq_js_1.Keq(formatUrl(url), { method: 'get' }, global);
|
|
71
|
+
const keq = new keq_js_1.Keq(formatUrl(url), { method: 'get' }, (0, get_unique_code_identifier_js_1.getUniqueCodeIdentifier)(1), global);
|
|
71
72
|
keq.appendMiddlewares(...appendMiddlewares);
|
|
72
73
|
keq.prependMiddlewares(...prependMiddlewares);
|
|
73
74
|
return keq;
|
|
74
75
|
};
|
|
75
76
|
request.put = function (url) {
|
|
76
|
-
const keq = new keq_js_1.Keq(formatUrl(url), { method: 'put' }, global);
|
|
77
|
+
const keq = new keq_js_1.Keq(formatUrl(url), { method: 'put' }, (0, get_unique_code_identifier_js_1.getUniqueCodeIdentifier)(1), global);
|
|
77
78
|
keq.appendMiddlewares(...appendMiddlewares);
|
|
78
79
|
keq.prependMiddlewares(...prependMiddlewares);
|
|
79
80
|
return keq;
|
|
80
81
|
};
|
|
81
82
|
request.delete = function (url) {
|
|
82
|
-
const keq = new keq_js_1.Keq(formatUrl(url), { method: 'delete' }, global);
|
|
83
|
+
const keq = new keq_js_1.Keq(formatUrl(url), { method: 'delete' }, (0, get_unique_code_identifier_js_1.getUniqueCodeIdentifier)(1), global);
|
|
83
84
|
keq.appendMiddlewares(...appendMiddlewares);
|
|
84
85
|
keq.prependMiddlewares(...prependMiddlewares);
|
|
85
86
|
return keq;
|
|
86
87
|
};
|
|
87
88
|
request.del = request.delete;
|
|
88
89
|
request.post = function (url) {
|
|
89
|
-
const keq = new keq_js_1.Keq(formatUrl(url), { method: 'post' }, global);
|
|
90
|
+
const keq = new keq_js_1.Keq(formatUrl(url), { method: 'post' }, (0, get_unique_code_identifier_js_1.getUniqueCodeIdentifier)(1), global);
|
|
90
91
|
keq.appendMiddlewares(...appendMiddlewares);
|
|
91
92
|
keq.prependMiddlewares(...prependMiddlewares);
|
|
92
93
|
return keq;
|
|
93
94
|
};
|
|
94
95
|
request.head = function (url) {
|
|
95
|
-
const keq = new keq_js_1.Keq(formatUrl(url), { method: 'head' }, global);
|
|
96
|
+
const keq = new keq_js_1.Keq(formatUrl(url), { method: 'head' }, (0, get_unique_code_identifier_js_1.getUniqueCodeIdentifier)(1), global);
|
|
96
97
|
keq.appendMiddlewares(...appendMiddlewares);
|
|
97
98
|
keq.prependMiddlewares(...prependMiddlewares);
|
|
98
99
|
return keq;
|
|
99
100
|
};
|
|
100
101
|
request.patch = function (url) {
|
|
101
|
-
const keq = new keq_js_1.Keq(formatUrl(url), { method: 'patch' }, global);
|
|
102
|
+
const keq = new keq_js_1.Keq(formatUrl(url), { method: 'patch' }, (0, get_unique_code_identifier_js_1.getUniqueCodeIdentifier)(1), global);
|
|
102
103
|
keq.appendMiddlewares(...appendMiddlewares);
|
|
103
104
|
keq.prependMiddlewares(...prependMiddlewares);
|
|
104
105
|
return keq;
|
|
105
106
|
};
|
|
106
107
|
request.options = function (url) {
|
|
107
|
-
const keq = new keq_js_1.Keq(formatUrl(url), { method: 'options' }, global);
|
|
108
|
+
const keq = new keq_js_1.Keq(formatUrl(url), { method: 'options' }, (0, get_unique_code_identifier_js_1.getUniqueCodeIdentifier)(1), global);
|
|
108
109
|
keq.appendMiddlewares(...appendMiddlewares);
|
|
109
110
|
keq.prependMiddlewares(...prependMiddlewares);
|
|
110
111
|
return keq;
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"use strict";
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.isBlob = void 0;
|
|
13
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
13
14
|
const is_function_js_1 = require("./is-function.js");
|
|
14
15
|
const is_object_js_1 = require("./is-object.js");
|
|
15
16
|
const is_string_js_1 = require("./is-string.js");
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"use strict";
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.isBuffer = void 0;
|
|
13
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
13
14
|
const is_browser_1 = require("./is-browser");
|
|
14
15
|
function isBuffer(obj) {
|
|
15
16
|
return (0, is_browser_1.isBrowser)() ? false : Buffer.isBuffer(obj);
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"use strict";
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.isFile = void 0;
|
|
13
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
13
14
|
const is_blob_js_1 = require("./is-blob.js");
|
|
14
15
|
const is_browser_js_1 = require("./is-browser.js");
|
|
15
16
|
function isFile(object) {
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"use strict";
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.isFormData = void 0;
|
|
13
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
13
14
|
const is_function_js_1 = require("./is-function.js");
|
|
14
15
|
const is_object_js_1 = require("./is-object.js");
|
|
15
16
|
function isFormData(object) {
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"use strict";
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.isHeaders = void 0;
|
|
13
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
13
14
|
const is_function_js_1 = require("./is-function.js");
|
|
14
15
|
const is_object_js_1 = require("./is-object.js");
|
|
15
16
|
function isHeaders(obj) {
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"use strict";
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.isUrlSearchParams = void 0;
|
|
13
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
13
14
|
const is_function_js_1 = require("./is-function.js");
|
|
14
15
|
const is_object_js_1 = require("./is-object.js");
|
|
15
16
|
function isUrlSearchParams(obj) {
|
package/dist/umd/src/keq.js
CHANGED
|
@@ -4,12 +4,13 @@
|
|
|
4
4
|
if (v !== undefined) module.exports = v;
|
|
5
5
|
}
|
|
6
6
|
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports", "./core.js", "./exception/exception.js", "./exception/invalid-arguments.exception.js", "./is/is-blob.js", "./is/is-file.js", "./is/is-form-data.js", "./is/is-headers.js", "./is/is-buffer.js", "./is/is-url-search-params.js", "./util/assign-keq-request-body.js", "./util/base64.js", "./util/fix-content-type.js", "./util/
|
|
7
|
+
define(["require", "exports", "./core.js", "./exception/exception.js", "./exception/invalid-arguments.exception.js", "./is/is-blob.js", "./is/is-file.js", "./is/is-form-data.js", "./is/is-headers.js", "./is/is-buffer.js", "./is/is-url-search-params.js", "./util/assign-keq-request-body.js", "./util/base64.js", "./util/fix-content-type.js", "./util/is-valid-header-value.js"], factory);
|
|
8
8
|
}
|
|
9
9
|
})(function (require, exports) {
|
|
10
10
|
"use strict";
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.Keq = void 0;
|
|
13
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
13
14
|
const core_js_1 = require("./core.js");
|
|
14
15
|
const exception_js_1 = require("./exception/exception.js");
|
|
15
16
|
const invalid_arguments_exception_js_1 = require("./exception/invalid-arguments.exception.js");
|
|
@@ -22,7 +23,6 @@
|
|
|
22
23
|
const assign_keq_request_body_js_1 = require("./util/assign-keq-request-body.js");
|
|
23
24
|
const base64_js_1 = require("./util/base64.js");
|
|
24
25
|
const fix_content_type_js_1 = require("./util/fix-content-type.js");
|
|
25
|
-
const get_unique_code_identifier_js_1 = require("./util/get-unique-code-identifier.js");
|
|
26
26
|
const is_valid_header_value_js_1 = require("./util/is-valid-header-value.js");
|
|
27
27
|
/**
|
|
28
28
|
* @description Keq 扩展 API,人性化的常用的API
|
|
@@ -201,7 +201,7 @@
|
|
|
201
201
|
return this;
|
|
202
202
|
}
|
|
203
203
|
flowControl(mode, signal) {
|
|
204
|
-
const sig = signal ? signal :
|
|
204
|
+
const sig = signal ? signal : this.__identifier__;
|
|
205
205
|
if (!sig) {
|
|
206
206
|
throw new exception_js_1.Exception('please set signal to .flowControl()');
|
|
207
207
|
}
|
|
@@ -218,7 +218,6 @@
|
|
|
218
218
|
}
|
|
219
219
|
resolveWith(m) {
|
|
220
220
|
this.option('resolveWith', m);
|
|
221
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
222
221
|
return this;
|
|
223
222
|
}
|
|
224
223
|
}
|