keq 5.0.0-alpha.5 → 5.0.0-alpha.7
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 +191 -240
- package/jest.browser.config.ts +22 -0
- package/jest.config.cts +22 -0
- package/package.json +21 -24
- package/dist/index.cjs.js +0 -1115
- package/dist/index.d.ts +0 -1
- package/dist/index.esm.js +0 -1082
- package/dist/package.json +0 -65
- package/dist/src/constant.d.ts +0 -2
- package/dist/src/core.d.ts +0 -36
- package/dist/src/create-request.d.ts +0 -9
- package/dist/src/exception/exception.d.ts +0 -4
- package/dist/src/exception/invalid-arguments.exception.d.ts +0 -4
- package/dist/src/index.d.ts +0 -23
- package/dist/src/is/is-array-buffer.d.ts +0 -1
- package/dist/src/is/is-blob.d.ts +0 -4
- package/dist/src/is/is-browser.d.ts +0 -1
- package/dist/src/is/is-buffer.d.ts +0 -1
- package/dist/src/is/is-file.d.ts +0 -1
- package/dist/src/is/is-form-data.d.ts +0 -1
- package/dist/src/is/is-function.d.ts +0 -1
- package/dist/src/is/is-headers.d.ts +0 -1
- package/dist/src/is/is-object.d.ts +0 -1
- package/dist/src/is/is-readable-stream.d.ts +0 -1
- package/dist/src/is/is-string.d.ts +0 -1
- package/dist/src/is/is-url-search-params.d.ts +0 -1
- package/dist/src/keq.d.ts +0 -93
- package/dist/src/middlewares/abort-flow-control-middleware.d.ts +0 -2
- package/dist/src/middlewares/fetch-arguments-middleware.d.ts +0 -2
- package/dist/src/middlewares/fetch-middleware.d.ts +0 -5
- package/dist/src/middlewares/proxy-response-middleware.d.ts +0 -2
- package/dist/src/middlewares/retry-middleware.d.ts +0 -2
- package/dist/src/middlewares/serial-flow-control-middleware.d.ts +0 -2
- package/dist/src/middlewares/timeout-middleware.d.ts +0 -2
- package/dist/src/request.d.ts +0 -1
- package/dist/src/router/keq-host-route.d.ts +0 -2
- package/dist/src/router/keq-location-route.d.ts +0 -2
- package/dist/src/router/keq-method-route.d.ts +0 -2
- package/dist/src/router/keq-module-route.d.ts +0 -2
- package/dist/src/router/keq-pathname-route.d.ts +0 -2
- package/dist/src/router/keq-router.d.ts +0 -12
- package/dist/src/types/content-type.d.ts +0 -2
- package/dist/src/types/exclude-property.d.ts +0 -3
- package/dist/src/types/extract-property.d.ts +0 -3
- package/dist/src/types/keq-context-request.d.ts +0 -18
- package/dist/src/types/keq-context.d.ts +0 -62
- package/dist/src/types/keq-events.d.ts +0 -8
- package/dist/src/types/keq-flow-control.d.ts +0 -7
- package/dist/src/types/keq-global.d.ts +0 -6
- package/dist/src/types/keq-init.d.ts +0 -2
- package/dist/src/types/keq-middleware.d.ts +0 -3
- package/dist/src/types/keq-next.d.ts +0 -1
- package/dist/src/types/keq-operation.d.ts +0 -44
- package/dist/src/types/keq-options.d.ts +0 -55
- package/dist/src/types/keq-query-value.d.ts +0 -6
- package/dist/src/types/keq-request.d.ts +0 -32
- package/dist/src/types/keq-resolve-with-mode.d.ts +0 -1
- package/dist/src/types/keq-retry.d.ts +0 -3
- package/dist/src/types/keq-route.d.ts +0 -2
- package/dist/src/types/keq-timeout.d.ts +0 -3
- package/dist/src/util/base64.d.ts +0 -2
- package/dist/src/util/clone-body.d.ts +0 -1
- package/dist/src/util/compile-url.d.ts +0 -1
- package/dist/src/util/compose-middleware.d.ts +0 -2
- package/dist/src/util/compose-route.d.ts +0 -2
- package/dist/src/util/create-response-proxy.d.ts +0 -1
- package/dist/src/util/fix-content-type.d.ts +0 -3
- package/dist/src/util/get-unique-code-identifier.d.ts +0 -1
- package/dist/src/util/is-valid-header-value.d.ts +0 -1
- package/dist/src/util/merge-keq-request-body.d.ts +0 -2
- package/dist/src/util/shallow-clone.d.ts +0 -4
- package/project.json +0 -16
- package/tsconfig.json +0 -28
- package/tsconfig.lib.json +0 -15
package/dist/package.json
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "keq",
|
|
3
|
-
"version": "5.0.0-alpha.4",
|
|
4
|
-
"description": "Request API write by Typescript for flexibility, readability, and a low learning curve.",
|
|
5
|
-
"keywords": [
|
|
6
|
-
"request",
|
|
7
|
-
"superagent",
|
|
8
|
-
"fetch",
|
|
9
|
-
"node",
|
|
10
|
-
"nodejs",
|
|
11
|
-
"browser",
|
|
12
|
-
"middleware",
|
|
13
|
-
"middlewares",
|
|
14
|
-
"axios",
|
|
15
|
-
"got"
|
|
16
|
-
],
|
|
17
|
-
"license": "MIT",
|
|
18
|
-
"author": "Val.istar.Guo <val.istar.guo@gmail.com>",
|
|
19
|
-
"main": "./index.cjs.js",
|
|
20
|
-
"module": "./index.esm.js",
|
|
21
|
-
"types": "dist/index.d.ts",
|
|
22
|
-
"exports": {
|
|
23
|
-
"require": "./dist/index.cjs.js",
|
|
24
|
-
"import": "./dist/index.esm.js"
|
|
25
|
-
},
|
|
26
|
-
"homepage": "https://github.com/keq-request/keq#readme",
|
|
27
|
-
"bugs": {
|
|
28
|
-
"url": "https://github.com/keq-request/keq/issues"
|
|
29
|
-
},
|
|
30
|
-
"repository": {
|
|
31
|
-
"type": "git",
|
|
32
|
-
"url": "git+https://github.com/keq-request/keq.git"
|
|
33
|
-
},
|
|
34
|
-
"scripts": {
|
|
35
|
-
"build": "nx rollup:build",
|
|
36
|
-
"test": "nx jest:test",
|
|
37
|
-
"test:update": "nx jest:test -u"
|
|
38
|
-
},
|
|
39
|
-
"dependencies": {
|
|
40
|
-
"fastq": "^1.17.1",
|
|
41
|
-
"minimatch": "^9.0.4",
|
|
42
|
-
"mitt": "^3.0.1",
|
|
43
|
-
"qs": "^6.13.1",
|
|
44
|
-
"ts-custom-error": "^3.3.1",
|
|
45
|
-
"type-fest": "^4.30.2"
|
|
46
|
-
},
|
|
47
|
-
"devDependencies": {
|
|
48
|
-
"@buka/eslint-config": "^2.1.1",
|
|
49
|
-
"@jest/globals": "^29.7.0",
|
|
50
|
-
"@types/clone": "^2.1.4",
|
|
51
|
-
"@types/minimatch": "^5.1.2",
|
|
52
|
-
"@types/node": "^20.14.1",
|
|
53
|
-
"@types/qs": "^6.9.17",
|
|
54
|
-
"eslint": "^9.13.0",
|
|
55
|
-
"jest": "^29.7.0",
|
|
56
|
-
"jest-environment-jsdom": "^29.7.0",
|
|
57
|
-
"jest-mock": "^29.7.0",
|
|
58
|
-
"ts-jest": "^29.1.5",
|
|
59
|
-
"ts-node": "^10.9.2",
|
|
60
|
-
"typescript": "5.4.5"
|
|
61
|
-
},
|
|
62
|
-
"engines": {
|
|
63
|
-
"node": ">=20.0.0"
|
|
64
|
-
}
|
|
65
|
-
}
|
package/dist/src/constant.d.ts
DELETED
package/dist/src/core.d.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import type { KeqContextOptions } from './types/keq-context.js';
|
|
2
|
-
import type { KeqMiddleware } from './types/keq-middleware.js';
|
|
3
|
-
import type { KeqInit } from './types/keq-init.js';
|
|
4
|
-
import type { KeqEvents, KeqListeners } from './types/keq-events.js';
|
|
5
|
-
import type { KeqContextRequest } from './types/keq-context-request.js';
|
|
6
|
-
/**
|
|
7
|
-
* @description Keq 核心 API,发送请求必要的原子化的API
|
|
8
|
-
*/
|
|
9
|
-
export declare class Core<OUTPUT> {
|
|
10
|
-
/**
|
|
11
|
-
* The unique identifier of the request's location in the code
|
|
12
|
-
*/
|
|
13
|
-
__identifier__: string;
|
|
14
|
-
private requestPromise?;
|
|
15
|
-
protected requestContext: Omit<KeqContextRequest, 'abort' | '__url__'>;
|
|
16
|
-
protected __listeners__: KeqListeners;
|
|
17
|
-
protected __global__: Record<string, any>;
|
|
18
|
-
protected __prepend_middlewares__: KeqMiddleware[];
|
|
19
|
-
protected __append_middlewares__: KeqMiddleware[];
|
|
20
|
-
protected __options__: KeqContextOptions;
|
|
21
|
-
constructor(url: URL, init: KeqInit, identifier: string, global?: Record<string, any>);
|
|
22
|
-
prependMiddlewares(...middlewares: KeqMiddleware[]): this;
|
|
23
|
-
appendMiddlewares(...middlewares: KeqMiddleware[]): this;
|
|
24
|
-
on<K extends keyof KeqEvents>(event: K, listener: (data: KeqEvents[K]) => void): this;
|
|
25
|
-
private run;
|
|
26
|
-
end(): Promise<OUTPUT>;
|
|
27
|
-
/**
|
|
28
|
-
* Attaches callbacks for the resolution and/or rejection of the Promise.
|
|
29
|
-
* @param onfulfilled The callback to execute when the Promise is resolved.
|
|
30
|
-
* @param onrejected The callback to execute when the Promise is rejected.
|
|
31
|
-
* @returns A Promise for the completion of which ever callback is executed.
|
|
32
|
-
*/
|
|
33
|
-
then<TResult1 = OUTPUT, TResult2 = never>(onfulfilled?: ((value: OUTPUT) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<TResult1 | TResult2>;
|
|
34
|
-
catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined | null): Promise<OUTPUT | TResult>;
|
|
35
|
-
finally(onfinally?: (() => void) | undefined | null): Promise<OUTPUT>;
|
|
36
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { KeqMiddleware } from './types/keq-middleware.js';
|
|
2
|
-
import type { KeqRequest } from './types/keq-request.js';
|
|
3
|
-
import type { KeqOperations } from './types/keq-operation.js';
|
|
4
|
-
interface CreateRequestOptions {
|
|
5
|
-
initMiddlewares?: KeqMiddleware[];
|
|
6
|
-
baseOrigin?: string;
|
|
7
|
-
}
|
|
8
|
-
export declare function createRequest<OPERATIONS extends KeqOperations>(options?: CreateRequestOptions): KeqRequest<OPERATIONS>;
|
|
9
|
-
export {};
|
package/dist/src/index.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export { createRequest } from './create-request.js';
|
|
2
|
-
export { Keq } from './keq.js';
|
|
3
|
-
export { request } from './request.js';
|
|
4
|
-
export { composeMiddleware } from './util/compose-middleware.js';
|
|
5
|
-
export { composeRoute } from './util/compose-route.js';
|
|
6
|
-
export { createResponseProxy } from './util/create-response-proxy.js';
|
|
7
|
-
export type { KeqContext, KeqContextOptions } from './types/keq-context.js';
|
|
8
|
-
export type { KeqMiddleware } from './types/keq-middleware.js';
|
|
9
|
-
export type { KeqNext } from './types/keq-next.js';
|
|
10
|
-
export type { KeqOptions } from './types/keq-options.js';
|
|
11
|
-
export type { KeqInit } from './types/keq-init.js';
|
|
12
|
-
export type { KeqRequest } from './types/keq-request.js';
|
|
13
|
-
export type { KeqRoute } from './types/keq-route.js';
|
|
14
|
-
export type { KeqGlobal } from './types/keq-global.js';
|
|
15
|
-
export type { KeqEvents } from './types/keq-events.js';
|
|
16
|
-
export type { KeqRetryOn, KeqRetryDelay } from './types/keq-retry.js';
|
|
17
|
-
export type { KeqOperations, KeqOperation, KeqBaseOperation } from './types/keq-operation.js';
|
|
18
|
-
export { keqHostRoute } from './router/keq-host-route.js';
|
|
19
|
-
export { keqLocationRoute } from './router/keq-location-route.js';
|
|
20
|
-
export { keqMethodRoute } from './router/keq-method-route.js';
|
|
21
|
-
export { keqModuleRoute } from './router/keq-module-route.js';
|
|
22
|
-
export { keqPathnameRoute } from './router/keq-pathname-route.js';
|
|
23
|
-
export { KeqRouter } from './router/keq-router.js';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function isArrayBuffer(body: any): body is ArrayBuffer;
|
package/dist/src/is/is-blob.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function isBrowser(): boolean;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function isBuffer(obj: any): obj is Buffer;
|
package/dist/src/is/is-file.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function isFile(object: any): object is File;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function isFormData(object: any): object is FormData;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function isFunction(value: any): boolean;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function isHeaders(obj: any): obj is Headers;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function isObject(value: any): boolean;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function isReadableStream(body: any): body is ReadableStream;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function isString(value: any): boolean;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function isUrlSearchParams(obj: any): obj is URLSearchParams;
|
package/dist/src/keq.d.ts
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { Core } from './core.js';
|
|
2
|
-
import { KeqFlowControlMode, KeqFlowControlSignal } from './types/keq-flow-control.js';
|
|
3
|
-
import type { KeqRetryOn, KeqRetryDelay } from './types/keq-retry.js';
|
|
4
|
-
import type { KeqMiddleware } from './types/keq-middleware.js';
|
|
5
|
-
import type { KeqOptionsParameter, KeqOptionsReturnType } from './types/keq-options.js';
|
|
6
|
-
import type { CommonContentType, ShorthandContentType } from './types/content-type.js';
|
|
7
|
-
import type { KeqContextOptions } from './types/keq-context.js';
|
|
8
|
-
import type { ExtractFields, ExtractFiles, KeqBaseOperation, KeqOperation } from './types/keq-operation.js';
|
|
9
|
-
import type { KeqContextRequestBody } from './types/keq-context-request.js';
|
|
10
|
-
import { KeqQueryObject, KeqQueryValue } from './types/keq-query-value.js';
|
|
11
|
-
/**
|
|
12
|
-
* @description Keq 扩展 API,人性化的常用的API
|
|
13
|
-
*/
|
|
14
|
-
export declare class Keq<OUTPUT, OPERATION extends Omit<KeqOperation, 'responseBody'> = KeqBaseOperation> extends Core<OUTPUT> {
|
|
15
|
-
use(...middlewares: KeqMiddleware[]): this;
|
|
16
|
-
option<K extends keyof KeqOptionsReturnType<OUTPUT>>(key: K, value?: KeqOptionsParameter[K]): KeqOptionsReturnType<OUTPUT>[K];
|
|
17
|
-
option(key: string, value?: any): this;
|
|
18
|
-
options(opts: KeqContextOptions): this;
|
|
19
|
-
/**
|
|
20
|
-
* Set request header
|
|
21
|
-
*
|
|
22
|
-
* @description 设置请求头
|
|
23
|
-
*/
|
|
24
|
-
set<K extends 'strict'>(headers: OPERATION['requestHeaders']): this;
|
|
25
|
-
set<K extends 'strict', T extends keyof OPERATION['requestHeaders']>(name: T, value: OPERATION['requestHeaders'][T]): this;
|
|
26
|
-
set<T extends keyof KeqBaseOperation['requestHeaders']>(name: T, value: KeqBaseOperation['requestHeaders'][T]): this;
|
|
27
|
-
set(headers: Headers): this;
|
|
28
|
-
set(headers: Record<string, string>): this;
|
|
29
|
-
set(name: string, value: string | number): this;
|
|
30
|
-
/**
|
|
31
|
-
* Set request query/searchParams
|
|
32
|
-
*/
|
|
33
|
-
query<K extends 'strict'>(key: OPERATION['requestQuery']): this;
|
|
34
|
-
query<K extends 'strict', T extends keyof OPERATION['requestQuery']>(key: T, value: OPERATION['requestQuery'][T]): this;
|
|
35
|
-
query(key: KeqQueryObject): this;
|
|
36
|
-
query(key: string, value: KeqQueryValue): this;
|
|
37
|
-
/**
|
|
38
|
-
* Set request route params
|
|
39
|
-
*/
|
|
40
|
-
params<K extends 'strict'>(key: OPERATION['requestParams']): this;
|
|
41
|
-
params<K extends 'strict', T extends keyof OPERATION['requestParams']>(key: T, value: OPERATION['requestParams'][T]): this;
|
|
42
|
-
params(key: Record<string, string | number>): this;
|
|
43
|
-
params(key: string, value: string | number): this;
|
|
44
|
-
/**
|
|
45
|
-
* Set request body
|
|
46
|
-
*/
|
|
47
|
-
body(value: KeqContextRequestBody): this;
|
|
48
|
-
/**
|
|
49
|
-
* Setting the Content-Type
|
|
50
|
-
*/
|
|
51
|
-
type(contentType: ShorthandContentType): this;
|
|
52
|
-
type(contentType: CommonContentType): this;
|
|
53
|
-
type(contentType: string): this;
|
|
54
|
-
/**
|
|
55
|
-
* Http Basic Authentication
|
|
56
|
-
*/
|
|
57
|
-
auth(username: string, password: string): this;
|
|
58
|
-
private setTypeIfEmpty;
|
|
59
|
-
/**
|
|
60
|
-
* set request body
|
|
61
|
-
*/
|
|
62
|
-
send<K extends 'strict'>(value: OPERATION['requestBody']): this;
|
|
63
|
-
send(value: object): this;
|
|
64
|
-
send(value: FormData): this;
|
|
65
|
-
send(value: URLSearchParams): this;
|
|
66
|
-
send(value: Array<any>): this;
|
|
67
|
-
send(value: string): this;
|
|
68
|
-
field<T extends keyof ExtractFields<OPERATION>>(arg1: T, value: ExtractFields<OPERATION>[T]): this;
|
|
69
|
-
field(arg1: ExtractFields<OPERATION>): this;
|
|
70
|
-
field(arg1: string, value: string | string[]): this;
|
|
71
|
-
field(arg1: Record<string, string>): this;
|
|
72
|
-
attach<T extends keyof ExtractFiles<OPERATION>>(key: T, value: Blob | File | Buffer, filename: string): this;
|
|
73
|
-
attach<T extends keyof ExtractFiles<OPERATION>>(key: T, value: Blob | File | Buffer): this;
|
|
74
|
-
attach(key: string, value: Blob | File | Buffer, filename: string): this;
|
|
75
|
-
attach(key: string, value: Blob | File | Buffer): this;
|
|
76
|
-
/**
|
|
77
|
-
*
|
|
78
|
-
* @param retryTimes Max number of retries per call
|
|
79
|
-
* @param retryDelay Initial value used to calculate the retry in milliseconds (This is still randomized following the randomization factor)
|
|
80
|
-
* @param retryCallback Will be called after request failed
|
|
81
|
-
*/
|
|
82
|
-
retry(retryTimes: number, retryDelay?: KeqRetryDelay, retryOn?: KeqRetryOn): Keq<OUTPUT>;
|
|
83
|
-
redirect(mod: RequestRedirect): this;
|
|
84
|
-
credentials(mod: RequestCredentials): this;
|
|
85
|
-
mode(mod: RequestMode): this;
|
|
86
|
-
flowControl(mode: KeqFlowControlMode, signal?: KeqFlowControlSignal): this;
|
|
87
|
-
timeout(milliseconds: number): this;
|
|
88
|
-
resolveWith(m: 'response'): Keq<Response>;
|
|
89
|
-
resolveWith(m: 'array-buffer'): Keq<ArrayBuffer>;
|
|
90
|
-
resolveWith(m: 'blob'): Keq<Blob>;
|
|
91
|
-
resolveWith(m: 'text'): Keq<string>;
|
|
92
|
-
resolveWith<U = any>(m: 'json' | 'form-data'): Keq<U>;
|
|
93
|
-
}
|
package/dist/src/request.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const request: import("./index.js").KeqRequest<import("./index.js").KeqOperations>;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { KeqMiddleware } from '~/types/keq-middleware.js';
|
|
2
|
-
import type { KeqRoute } from '~/types/keq-route.js';
|
|
3
|
-
export declare class KeqRouter {
|
|
4
|
-
private readonly prependMiddlewares;
|
|
5
|
-
constructor(prependMiddlewares?: KeqMiddleware[]);
|
|
6
|
-
route(route: KeqRoute, ...middlewares: KeqMiddleware[]): this;
|
|
7
|
-
host(host: string, ...middlewares: KeqMiddleware[]): this;
|
|
8
|
-
method(method: string, ...middlewares: KeqMiddleware[]): this;
|
|
9
|
-
pathname(pathname: string, ...middlewares: KeqMiddleware[]): this;
|
|
10
|
-
location(...middlewares: KeqMiddleware[]): this;
|
|
11
|
-
module(moduleName: string, ...middlewares: KeqMiddleware[]): this;
|
|
12
|
-
}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
export type ShorthandContentType = 'json' | 'form-data' | 'form' | 'jpeg' | 'bmp' | 'apng' | 'gif' | 'x-icon' | 'png' | 'webp' | 'tiff' | 'svg' | 'xml' | 'html' | 'css';
|
|
2
|
-
export type CommonContentType = 'application/json' | 'multipart/form-data' | 'application/x-www-form-urlencoded' | 'image/jpeg' | 'image/bmp' | 'image/apng' | 'image/gif' | 'image/x-icon' | 'image/png' | 'image/webp' | 'image/tiff' | 'image/svg+xml' | 'text/xml' | 'text/html' | 'text/css';
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export type KeqContextRequestMethod = 'get' | 'post' | 'put' | 'delete' | 'head' | 'patch' | 'options';
|
|
2
|
-
export type KeqContextRequestBody = BodyInit | object | Array<any> | undefined;
|
|
3
|
-
export interface KeqContextRequest {
|
|
4
|
-
url: URL;
|
|
5
|
-
routeParams: Record<string, string>;
|
|
6
|
-
readonly __url__: Readonly<URL>;
|
|
7
|
-
method: KeqContextRequestMethod;
|
|
8
|
-
headers: Headers;
|
|
9
|
-
body: KeqContextRequestBody;
|
|
10
|
-
cache?: RequestCache;
|
|
11
|
-
credentials?: RequestCredentials;
|
|
12
|
-
integrity?: string;
|
|
13
|
-
keepalive?: boolean;
|
|
14
|
-
mode?: RequestMode;
|
|
15
|
-
redirect?: RequestRedirect;
|
|
16
|
-
referrer?: string;
|
|
17
|
-
referrerPolicy?: ReferrerPolicy;
|
|
18
|
-
}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { ABORT_PROPERTY, OUTPUT_PROPERTY } from '../constant.js';
|
|
2
|
-
import type { Emitter } from 'mitt';
|
|
3
|
-
import type { KeqOptionsParameter } from './keq-options.js';
|
|
4
|
-
import type { KeqEvents } from './keq-events.js';
|
|
5
|
-
import type { KeqGlobal } from './keq-global.js';
|
|
6
|
-
import type { KeqContextRequest } from './keq-context-request.js';
|
|
7
|
-
export interface KeqContextOptions extends KeqOptionsParameter {
|
|
8
|
-
[key: string]: any;
|
|
9
|
-
}
|
|
10
|
-
export interface KeqContext {
|
|
11
|
-
/**
|
|
12
|
-
* Middleware metadata
|
|
13
|
-
*
|
|
14
|
-
* This property does not share between middlewares
|
|
15
|
-
* And will be destroyed after the middleware finish
|
|
16
|
-
*
|
|
17
|
-
* next: to prevent someone invoke `next()` multiple times or forgetting await
|
|
18
|
-
*/
|
|
19
|
-
readonly metadata: {
|
|
20
|
-
finished: boolean;
|
|
21
|
-
entryNextTimes: number;
|
|
22
|
-
outNextTimes: number;
|
|
23
|
-
};
|
|
24
|
-
[ABORT_PROPERTY]?: AbortController;
|
|
25
|
-
abort: (reason: any) => void;
|
|
26
|
-
/**
|
|
27
|
-
* The unique identifier of the request's location in the code
|
|
28
|
-
* @readonly
|
|
29
|
-
*/
|
|
30
|
-
readonly identifier: string;
|
|
31
|
-
readonly emitter: Emitter<Omit<KeqEvents, never>>;
|
|
32
|
-
options: KeqContextOptions;
|
|
33
|
-
/**
|
|
34
|
-
* keq request context
|
|
35
|
-
*/
|
|
36
|
-
readonly request: KeqContextRequest;
|
|
37
|
-
/**
|
|
38
|
-
* original response
|
|
39
|
-
*/
|
|
40
|
-
res?: Response;
|
|
41
|
-
/**
|
|
42
|
-
* proxy response
|
|
43
|
-
*/
|
|
44
|
-
response?: Response;
|
|
45
|
-
/**
|
|
46
|
-
* the result get by user
|
|
47
|
-
*/
|
|
48
|
-
output: any;
|
|
49
|
-
[OUTPUT_PROPERTY]?: any;
|
|
50
|
-
/**
|
|
51
|
-
* share data between requests
|
|
52
|
-
*/
|
|
53
|
-
readonly global: KeqGlobal;
|
|
54
|
-
/**
|
|
55
|
-
* Fetch API Arguments
|
|
56
|
-
*/
|
|
57
|
-
fetchArguments?: [RequestInfo | string, RequestInit];
|
|
58
|
-
/**
|
|
59
|
-
* extends by middleware
|
|
60
|
-
* */
|
|
61
|
-
[key: string]: any;
|
|
62
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { KeqContext } from './keq-context.js';
|
|
2
|
-
export interface KeqFlowControl {
|
|
3
|
-
mode: 'abort' | 'serial';
|
|
4
|
-
signal: string | ((ctx: KeqContext) => string);
|
|
5
|
-
}
|
|
6
|
-
export type KeqFlowControlMode = KeqFlowControl['mode'];
|
|
7
|
-
export type KeqFlowControlSignal = KeqFlowControl['signal'];
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { queueAsPromised } from 'fastq';
|
|
2
|
-
import type { KeqNext } from './keq-next.js';
|
|
3
|
-
export interface KeqGlobal {
|
|
4
|
-
abortFlowControl?: Record<string, ((reason: any) => void) | undefined>;
|
|
5
|
-
serialFlowControl?: Record<string, queueAsPromised<KeqNext, void>>;
|
|
6
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type KeqNext = () => Promise<void> | void;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { ExtractProperty } from './extract-property.js';
|
|
2
|
-
import { KeqContextRequestMethod } from './keq-context-request.js';
|
|
3
|
-
import { KeqQueryObject } from './keq-query-value.js';
|
|
4
|
-
export interface KeqOperation {
|
|
5
|
-
requestParams: {
|
|
6
|
-
[key: string]: string | number;
|
|
7
|
-
};
|
|
8
|
-
requestQuery: KeqQueryObject;
|
|
9
|
-
requestHeaders: {
|
|
10
|
-
[key: string]: string | number;
|
|
11
|
-
};
|
|
12
|
-
requestBody: FormData | URLSearchParams | object | Array<any> | string;
|
|
13
|
-
responseBody: any;
|
|
14
|
-
}
|
|
15
|
-
export type ExtractFields<T extends Pick<KeqOperation, 'requestBody'>> = ExtractProperty<Exclude<Extract<T['requestBody'], object>, FormData | URLSearchParams | Array<any>>, string>;
|
|
16
|
-
export type ExtractFiles<T extends Pick<KeqOperation, 'requestBody'>> = ExtractProperty<Exclude<Extract<T['requestBody'], object>, FormData | URLSearchParams | Array<any>>, Buffer | Blob | File>;
|
|
17
|
-
export interface KeqOperations {
|
|
18
|
-
[url: string]: {
|
|
19
|
-
[method in KeqContextRequestMethod]?: KeqOperation;
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
export type FlattenOperations<T extends KeqOperations, M extends KeqContextRequestMethod> = {
|
|
23
|
-
[P in keyof T as T[P][M] extends KeqOperation ? P : never]: T[P][M] extends KeqOperation ? T[P][M] : never;
|
|
24
|
-
};
|
|
25
|
-
export interface KeqBaseOperation extends KeqOperation {
|
|
26
|
-
url: string;
|
|
27
|
-
method: KeqContextRequestMethod;
|
|
28
|
-
output: any;
|
|
29
|
-
requestParams: {
|
|
30
|
-
[key: string]: string;
|
|
31
|
-
};
|
|
32
|
-
requestQuery: KeqQueryObject;
|
|
33
|
-
requestHeaders: {
|
|
34
|
-
'content-type': string;
|
|
35
|
-
cookie: string;
|
|
36
|
-
host: string;
|
|
37
|
-
authorization: string;
|
|
38
|
-
'cache-control': string;
|
|
39
|
-
'content-encoding': string;
|
|
40
|
-
referer: string;
|
|
41
|
-
'user-agent': string;
|
|
42
|
-
};
|
|
43
|
-
requestBody: FormData | URLSearchParams | object | Array<any> | string;
|
|
44
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import type { Keq } from '~/keq.js';
|
|
2
|
-
import type { KeqFlowControl } from './keq-flow-control.js';
|
|
3
|
-
import type { KeqResolveMethod } from './keq-resolve-with-mode.js';
|
|
4
|
-
import type { KeqRetryOn, KeqRetryDelay } from './keq-retry.js';
|
|
5
|
-
import type { KeqTimeout } from './keq-timeout.js';
|
|
6
|
-
import { ExcludeProperty } from './exclude-property.js';
|
|
7
|
-
export interface KeqOptions<T> {
|
|
8
|
-
/**
|
|
9
|
-
* replace the default fetch api
|
|
10
|
-
* default use node-fetch@2 in node and window.fetch in browser
|
|
11
|
-
*/
|
|
12
|
-
fetchAPI(value: typeof fetch): Keq<T>;
|
|
13
|
-
/**
|
|
14
|
-
* get response object, defaulted `false`
|
|
15
|
-
* @deprecated use `resolveWith` instead
|
|
16
|
-
* */
|
|
17
|
-
resolveWithFullResponse(value: boolean): Keq<Response>;
|
|
18
|
-
/**
|
|
19
|
-
* how to resolve the response body
|
|
20
|
-
* @description 如何解析响应体
|
|
21
|
-
* @default 'intelligent'
|
|
22
|
-
*/
|
|
23
|
-
resolveWith(value: KeqResolveMethod): Keq<T>;
|
|
24
|
-
/**
|
|
25
|
-
* The request retry times
|
|
26
|
-
* @description 重试次数
|
|
27
|
-
*/
|
|
28
|
-
retryTimes(value: number): Keq<T>;
|
|
29
|
-
/**
|
|
30
|
-
* The request retry interval time
|
|
31
|
-
* @description 重试间隔时间
|
|
32
|
-
*/
|
|
33
|
-
retryDelay(value: KeqRetryDelay): Keq<T>;
|
|
34
|
-
/**
|
|
35
|
-
* Custom retry condition
|
|
36
|
-
* @description 自定义重试条件
|
|
37
|
-
*/
|
|
38
|
-
retryOn(value: KeqRetryOn): Keq<T>;
|
|
39
|
-
module(value: {
|
|
40
|
-
name: string;
|
|
41
|
-
pathname: string;
|
|
42
|
-
}): Keq<T>;
|
|
43
|
-
flowControl(value: KeqFlowControl): Keq<T>;
|
|
44
|
-
timeout(value: KeqTimeout): Keq<T>;
|
|
45
|
-
}
|
|
46
|
-
type ReturnType<T> = T extends (...args: any[]) => infer R ? R : never;
|
|
47
|
-
type FirstArgType<T> = T extends (arg1: infer P, ...args: any[]) => any ? P : never;
|
|
48
|
-
type ExcludeNeverProperty<T> = ExcludeProperty<T, never>;
|
|
49
|
-
export type KeqOptionsParameter = ExcludeNeverProperty<{
|
|
50
|
-
[key in keyof KeqOptions<any>]?: FirstArgType<KeqOptions<any>[key]>;
|
|
51
|
-
}>;
|
|
52
|
-
export type KeqOptionsReturnType<T> = ExcludeNeverProperty<{
|
|
53
|
-
[key in keyof KeqOptions<T>]: ReturnType<KeqOptions<T>[key]>;
|
|
54
|
-
}>;
|
|
55
|
-
export {};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export type KeqQueryPrimitive = string | number | null | bigint | undefined;
|
|
2
|
-
export type KeqQueryObject = {
|
|
3
|
-
[Key in string]: KeqQueryValue | undefined;
|
|
4
|
-
};
|
|
5
|
-
export type KeqQueryArray = KeqQueryValue[];
|
|
6
|
-
export type KeqQueryValue = KeqQueryPrimitive | KeqQueryArray | KeqQueryObject;
|