extra-request 9.0.1 → 10.1.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/README.md +20 -8
- package/lib/request.d.ts +1 -0
- package/lib/request.js +1 -1
- package/lib/request.js.map +1 -1
- package/lib/transformers/body.d.ts +1 -1
- package/lib/transformers/body.js +2 -2
- package/lib/transformers/body.js.map +1 -1
- package/lib/transformers/cache.d.ts +2 -0
- package/lib/transformers/cache.js +9 -0
- package/lib/transformers/cache.js.map +1 -0
- package/lib/transformers/index.d.ts +24 -23
- package/lib/transformers/index.js +24 -23
- package/lib/transformers/index.js.map +1 -1
- package/lib/transformers/keepalive.d.ts +1 -1
- package/lib/transformers/keepalive.js +2 -2
- package/lib/transformers/keepalive.js.map +1 -1
- package/lib/transformers/redirect.d.ts +1 -1
- package/lib/transformers/redirect.js +2 -2
- package/lib/transformers/redirect.js.map +1 -1
- package/lib/types.d.ts +2 -1
- package/package.json +20 -21
- package/src/request.ts +2 -2
- package/src/transformers/body.ts +2 -2
- package/src/transformers/cache.ts +10 -0
- package/src/transformers/index.ts +24 -23
- package/src/transformers/keepalive.ts +2 -2
- package/src/transformers/redirect.ts +2 -2
- package/src/types.ts +2 -7
package/README.md
CHANGED
|
@@ -23,14 +23,13 @@ const res = await fetch(req)
|
|
|
23
23
|
## API
|
|
24
24
|
```ts
|
|
25
25
|
interface IRequestOptions {
|
|
26
|
-
url
|
|
27
|
-
headers
|
|
28
|
-
payload?:
|
|
29
|
-
| BodyInit // WHATWG
|
|
30
|
-
| NodeJS.ReadableStream // node-fetch
|
|
26
|
+
url: URL
|
|
27
|
+
headers: Headers
|
|
28
|
+
payload?: BodyInit
|
|
31
29
|
signal?: AbortSignal
|
|
32
30
|
keepalive?: boolean
|
|
33
31
|
redirect?: RequestRedirect
|
|
32
|
+
cache?: RequestCache
|
|
34
33
|
}
|
|
35
34
|
|
|
36
35
|
type IRequestOptionsTransformer = (options: IRequestOptions) => RequestOptions
|
|
@@ -66,6 +65,14 @@ function patch(...transformers: Array<IRequestOptionsTransformer | Falsy>): Requ
|
|
|
66
65
|
function del(...transformers: Array<IRequestOptionsTrransformer | Falsy>): Request
|
|
67
66
|
```
|
|
68
67
|
|
|
68
|
+
### request
|
|
69
|
+
```ts
|
|
70
|
+
function request(
|
|
71
|
+
method: 'GET' | 'HEAD' | 'PUT' | 'POST' | 'PATCH' | 'DELETE'
|
|
72
|
+
, ...transformers: Array<IRequestOptionsTransformer | Falsy>
|
|
73
|
+
): Request
|
|
74
|
+
```
|
|
75
|
+
|
|
69
76
|
### pipeRequestOptionsTransformers
|
|
70
77
|
```ts
|
|
71
78
|
function pipeRequestOptionsTransformers(
|
|
@@ -186,15 +193,20 @@ function bearerAuth(token: string): IRequestOptionsTransformer
|
|
|
186
193
|
|
|
187
194
|
#### keepalive
|
|
188
195
|
```ts
|
|
189
|
-
function keepalive(
|
|
196
|
+
function keepalive(keepalive: boolean = true): IRequestOptionsTransformer
|
|
190
197
|
```
|
|
191
198
|
|
|
192
199
|
#### redirect
|
|
193
200
|
```ts
|
|
194
|
-
function redirect(
|
|
201
|
+
function redirect(redirect: RequestRedirect): IRequestOptionsTransformer
|
|
195
202
|
```
|
|
196
203
|
|
|
197
204
|
#### body
|
|
198
205
|
```ts
|
|
199
|
-
function body(
|
|
206
|
+
function body(body: BodyInit): IRequestOptionsTransformer
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
####
|
|
210
|
+
```ts
|
|
211
|
+
function cache(cache: RequestCache): IRequestOptionsTransformer
|
|
200
212
|
```
|
package/lib/request.d.ts
CHANGED
|
@@ -6,3 +6,4 @@ export declare function post(...transformers: Array<IRequestOptionsTransformer |
|
|
|
6
6
|
export declare function put(...transformers: Array<IRequestOptionsTransformer | Falsy>): Request;
|
|
7
7
|
export declare function patch(...transformers: Array<IRequestOptionsTransformer | Falsy>): Request;
|
|
8
8
|
export declare function del(...transformers: Array<IRequestOptionsTransformer | Falsy>): Request;
|
|
9
|
+
export declare function request(method: 'GET' | 'HEAD' | 'PUT' | 'POST' | 'PATCH' | 'DELETE', ...transformers: Array<IRequestOptionsTransformer | Falsy>): Request;
|
package/lib/request.js
CHANGED
|
@@ -18,7 +18,7 @@ export function patch(...transformers) {
|
|
|
18
18
|
export function del(...transformers) {
|
|
19
19
|
return request('DELETE', ...transformers);
|
|
20
20
|
}
|
|
21
|
-
function request(method, ...transformers) {
|
|
21
|
+
export function request(method, ...transformers) {
|
|
22
22
|
const requestOptions = pipeRequestOptionsTransformers(...transformers);
|
|
23
23
|
const headers = new Headers(requestOptions.headers);
|
|
24
24
|
return new Request(requestOptions.url.href, {
|
package/lib/request.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.js","sourceRoot":"","sources":["../src/request.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAE9C,OAAO,EAAE,8BAA8B,EAAE,+CAAiD;AAG1F,MAAM,UAAU,GAAG,CAAC,GAAG,YAAuD;IAC5E,OAAO,OAAO,CAAC,KAAK,EAAE,GAAG,YAAY,CAAC,CAAA;AACxC,CAAC;AAED,MAAM,UAAU,IAAI,CAAC,GAAG,YAAuD;IAC7E,OAAO,OAAO,CAAC,MAAM,EAAE,GAAG,YAAY,CAAC,CAAA;AACzC,CAAC;AAED,MAAM,UAAU,IAAI,CAAC,GAAG,YAAuD;IAC7E,OAAO,OAAO,CAAC,MAAM,EAAE,GAAG,YAAY,CAAC,CAAA;AACzC,CAAC;AAED,MAAM,UAAU,GAAG,CAAC,GAAG,YAAuD;IAC5E,OAAO,OAAO,CAAC,KAAK,EAAE,GAAG,YAAY,CAAC,CAAA;AACxC,CAAC;AAED,MAAM,UAAU,KAAK,CAAC,GAAG,YAAuD;IAC9E,OAAO,OAAO,CAAC,OAAO,EAAE,GAAG,YAAY,CAAC,CAAA;AAC1C,CAAC;AAED,MAAM,UAAU,GAAG,CAAC,GAAG,YAAuD;IAC5E,OAAO,OAAO,CAAC,QAAQ,EAAE,GAAG,YAAY,CAAC,CAAA;AAC3C,CAAC;AAED,
|
|
1
|
+
{"version":3,"file":"request.js","sourceRoot":"","sources":["../src/request.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAE9C,OAAO,EAAE,8BAA8B,EAAE,+CAAiD;AAG1F,MAAM,UAAU,GAAG,CAAC,GAAG,YAAuD;IAC5E,OAAO,OAAO,CAAC,KAAK,EAAE,GAAG,YAAY,CAAC,CAAA;AACxC,CAAC;AAED,MAAM,UAAU,IAAI,CAAC,GAAG,YAAuD;IAC7E,OAAO,OAAO,CAAC,MAAM,EAAE,GAAG,YAAY,CAAC,CAAA;AACzC,CAAC;AAED,MAAM,UAAU,IAAI,CAAC,GAAG,YAAuD;IAC7E,OAAO,OAAO,CAAC,MAAM,EAAE,GAAG,YAAY,CAAC,CAAA;AACzC,CAAC;AAED,MAAM,UAAU,GAAG,CAAC,GAAG,YAAuD;IAC5E,OAAO,OAAO,CAAC,KAAK,EAAE,GAAG,YAAY,CAAC,CAAA;AACxC,CAAC;AAED,MAAM,UAAU,KAAK,CAAC,GAAG,YAAuD;IAC9E,OAAO,OAAO,CAAC,OAAO,EAAE,GAAG,YAAY,CAAC,CAAA;AAC1C,CAAC;AAED,MAAM,UAAU,GAAG,CAAC,GAAG,YAAuD;IAC5E,OAAO,OAAO,CAAC,QAAQ,EAAE,GAAG,YAAY,CAAC,CAAA;AAC3C,CAAC;AAED,MAAM,UAAU,OAAO,CACrB,MAA4D,EAC5D,GAAG,YAAuD;IAE1D,MAAM,cAAc,GAAG,8BAA8B,CAAC,GAAG,YAAY,CAAC,CAAA;IACtE,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,cAAc,CAAC,OAAO,CAAC,CAAA;IAEnD,OAAO,IAAI,OAAO,CAAC,cAAc,CAAC,GAAG,CAAC,IAAI,EAAE;QAC1C,MAAM;QACN,OAAO;QACP,MAAM,EAAE,cAAc,CAAC,MAAM;QAC7B,IAAI,EAAE,cAAc,CAAC,OAAO;QAC5B,SAAS,EAAE,cAAc,CAAC,SAAS;QACnC,QAAQ,EAAE,cAAc,CAAC,QAAQ;KAClC,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { IRequestOptionsTransformer } from "../types.js";
|
|
2
|
-
export declare function body(
|
|
2
|
+
export declare function body(body: BodyInit): IRequestOptionsTransformer;
|
package/lib/transformers/body.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"body.js","sourceRoot":"","sources":["../../src/transformers/body.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"body.js","sourceRoot":"","sources":["../../src/transformers/body.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,IAAI,CAAC,IAAc;IACjC,OAAO,CAAC,OAAwB,EAAE,EAAE;QAClC,OAAO;YACL,GAAG,OAAO;YACV,OAAO,EAAE,IAAI;SACd,CAAA;IACH,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../../src/transformers/cache.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,KAAK,CAAC,KAAmB;IACvC,OAAO,CAAC,OAAwB,EAAE,EAAE;QAClC,OAAO;YACL,GAAG,OAAO;YACV,KAAK;SACN,CAAA;IACH,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -1,23 +1,24 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
8
|
-
export * from
|
|
9
|
-
export * from
|
|
10
|
-
export * from
|
|
11
|
-
export * from
|
|
12
|
-
export * from
|
|
13
|
-
export * from
|
|
14
|
-
export * from
|
|
15
|
-
export * from
|
|
16
|
-
export * from
|
|
17
|
-
export * from
|
|
18
|
-
export * from
|
|
19
|
-
export * from
|
|
20
|
-
export * from
|
|
21
|
-
export * from
|
|
22
|
-
export * from
|
|
23
|
-
export * from
|
|
1
|
+
export * from './url.js';
|
|
2
|
+
export * from './text.js';
|
|
3
|
+
export * from './json.js';
|
|
4
|
+
export * from './csv.js';
|
|
5
|
+
export * from './header.js';
|
|
6
|
+
export * from './append-header.js';
|
|
7
|
+
export * from './headers.js';
|
|
8
|
+
export * from './accept.js';
|
|
9
|
+
export * from './host.js';
|
|
10
|
+
export * from './port.js';
|
|
11
|
+
export * from './pathname.js';
|
|
12
|
+
export * from './append-pathname.js';
|
|
13
|
+
export * from './search.js';
|
|
14
|
+
export * from './search-param.js';
|
|
15
|
+
export * from './search-params.js';
|
|
16
|
+
export * from './append-search-param.js';
|
|
17
|
+
export * from './form-data-field.js';
|
|
18
|
+
export * from './basic-auth.js';
|
|
19
|
+
export * from './bearer-auth.js';
|
|
20
|
+
export * from './signal.js';
|
|
21
|
+
export * from './keepalive.js';
|
|
22
|
+
export * from './redirect.js';
|
|
23
|
+
export * from './body.js';
|
|
24
|
+
export * from './cache.js';
|
|
@@ -1,24 +1,25 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
8
|
-
export * from
|
|
9
|
-
export * from
|
|
10
|
-
export * from
|
|
11
|
-
export * from
|
|
12
|
-
export * from
|
|
13
|
-
export * from
|
|
14
|
-
export * from
|
|
15
|
-
export * from
|
|
16
|
-
export * from
|
|
17
|
-
export * from
|
|
18
|
-
export * from
|
|
19
|
-
export * from
|
|
20
|
-
export * from
|
|
21
|
-
export * from
|
|
22
|
-
export * from
|
|
23
|
-
export * from
|
|
1
|
+
export * from './url.js';
|
|
2
|
+
export * from './text.js';
|
|
3
|
+
export * from './json.js';
|
|
4
|
+
export * from './csv.js';
|
|
5
|
+
export * from './header.js';
|
|
6
|
+
export * from './append-header.js';
|
|
7
|
+
export * from './headers.js';
|
|
8
|
+
export * from './accept.js';
|
|
9
|
+
export * from './host.js';
|
|
10
|
+
export * from './port.js';
|
|
11
|
+
export * from './pathname.js';
|
|
12
|
+
export * from './append-pathname.js';
|
|
13
|
+
export * from './search.js';
|
|
14
|
+
export * from './search-param.js';
|
|
15
|
+
export * from './search-params.js';
|
|
16
|
+
export * from './append-search-param.js';
|
|
17
|
+
export * from './form-data-field.js';
|
|
18
|
+
export * from './basic-auth.js';
|
|
19
|
+
export * from './bearer-auth.js';
|
|
20
|
+
export * from './signal.js';
|
|
21
|
+
export * from './keepalive.js';
|
|
22
|
+
export * from './redirect.js';
|
|
23
|
+
export * from './body.js';
|
|
24
|
+
export * from './cache.js';
|
|
24
25
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/transformers/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/transformers/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AAExB,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA;AAExB,cAAc,aAAa,CAAA;AAC3B,cAAc,oBAAoB,CAAA;AAClC,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAE3B,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AACzB,cAAc,eAAe,CAAA;AAC7B,cAAc,sBAAsB,CAAA;AACpC,cAAc,aAAa,CAAA;AAC3B,cAAc,mBAAmB,CAAA;AACjC,cAAc,oBAAoB,CAAA;AAClC,cAAc,0BAA0B,CAAA;AAExC,cAAc,sBAAsB,CAAA;AAEpC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,kBAAkB,CAAA;AAEhC,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,eAAe,CAAA;AAC7B,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { IRequestOptionsTransformer } from "../types.js";
|
|
2
|
-
export declare function keepalive(
|
|
2
|
+
export declare function keepalive(keepalive?: boolean): IRequestOptionsTransformer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keepalive.js","sourceRoot":"","sources":["../../src/transformers/keepalive.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,SAAS,CAAC,
|
|
1
|
+
{"version":3,"file":"keepalive.js","sourceRoot":"","sources":["../../src/transformers/keepalive.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,SAAS,CAAC,YAAqB,IAAI;IACjD,OAAO,CAAC,OAAwB,EAAE,EAAE;QAClC,OAAO;YACL,GAAG,OAAO;YACV,SAAS;SACV,CAAA;IACH,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { IRequestOptionsTransformer } from "../types.js";
|
|
2
|
-
export declare function redirect(
|
|
2
|
+
export declare function redirect(redirect: RequestRedirect): IRequestOptionsTransformer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redirect.js","sourceRoot":"","sources":["../../src/transformers/redirect.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,QAAQ,CAAC,
|
|
1
|
+
{"version":3,"file":"redirect.js","sourceRoot":"","sources":["../../src/transformers/redirect.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,QAAQ,CAAC,QAAyB;IAChD,OAAO,CAAC,OAAwB,EAAE,EAAE;QAClC,OAAO;YACL,GAAG,OAAO;YACV,QAAQ;SACT,CAAA;IACH,CAAC,CAAA;AACH,CAAC"}
|
package/lib/types.d.ts
CHANGED
|
@@ -2,8 +2,9 @@ export type IRequestOptionsTransformer = (options: IRequestOptions) => IRequestO
|
|
|
2
2
|
export interface IRequestOptions {
|
|
3
3
|
url: URL;
|
|
4
4
|
headers: Headers;
|
|
5
|
-
payload?: BodyInit
|
|
5
|
+
payload?: BodyInit;
|
|
6
6
|
signal?: AbortSignal;
|
|
7
7
|
keepalive?: boolean;
|
|
8
8
|
redirect?: RequestRedirect;
|
|
9
|
+
cache?: RequestCache;
|
|
9
10
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "extra-request",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "10.1.0",
|
|
4
4
|
"description": "Utilities for Request",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
28
|
"engines": {
|
|
29
|
-
"node": ">=
|
|
29
|
+
"node": ">=22"
|
|
30
30
|
},
|
|
31
31
|
"repository": "git@github.com:BlackGlory/extra-request.git",
|
|
32
32
|
"author": "BlackGlory <woshenmedoubuzhidao@blackglory.me>",
|
|
@@ -47,37 +47,36 @@
|
|
|
47
47
|
}
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@commitlint/cli": "^19.
|
|
51
|
-
"@commitlint/config-conventional": "^19.
|
|
52
|
-
"@eslint/js": "^9.
|
|
53
|
-
"@types/
|
|
54
|
-
"@types/papaparse": "^5.3.15",
|
|
50
|
+
"@commitlint/cli": "^19.8.1",
|
|
51
|
+
"@commitlint/config-conventional": "^19.8.1",
|
|
52
|
+
"@eslint/js": "^9.29.0",
|
|
53
|
+
"@types/papaparse": "^5.3.16",
|
|
55
54
|
"cross-env": "^7.0.3",
|
|
56
|
-
"eslint": "^9.
|
|
57
|
-
"extra-fetch": "^
|
|
58
|
-
"extra-filesystem": "^0.5.
|
|
55
|
+
"eslint": "^9.29.0",
|
|
56
|
+
"extra-fetch": "^5.0.1",
|
|
57
|
+
"extra-filesystem": "^0.5.2",
|
|
59
58
|
"husky": "4",
|
|
60
59
|
"npm-run-all": "^4.1.5",
|
|
61
|
-
"rimraf": "
|
|
60
|
+
"rimraf": "6.0.1",
|
|
62
61
|
"standard-version": "^9.5.0",
|
|
63
|
-
"ts-patch": "^3.
|
|
62
|
+
"ts-patch": "^3.3.0",
|
|
64
63
|
"tslib": "^2.8.1",
|
|
65
|
-
"typescript": "5.
|
|
66
|
-
"typescript-eslint": "^8.
|
|
67
|
-
"typescript-transform-paths": "^3.5.
|
|
68
|
-
"vite": "^6.
|
|
69
|
-
"vite-tsconfig-paths": "^5.1.
|
|
70
|
-
"vitest": "^2.
|
|
64
|
+
"typescript": "5.8.3",
|
|
65
|
+
"typescript-eslint": "^8.34.0",
|
|
66
|
+
"typescript-transform-paths": "^3.5.5",
|
|
67
|
+
"vite": "^6.3.5",
|
|
68
|
+
"vite-tsconfig-paths": "^5.1.4",
|
|
69
|
+
"vitest": "^3.2.3"
|
|
71
70
|
},
|
|
72
71
|
"dependencies": {
|
|
73
72
|
"@blackglory/prelude": "^0.4.0",
|
|
74
|
-
"extra-utils": "^5.
|
|
73
|
+
"extra-utils": "^5.19.0",
|
|
75
74
|
"js-base64": "^3.7.7",
|
|
76
75
|
"justypes": "^4.4.1",
|
|
77
|
-
"papaparse": "^5.
|
|
76
|
+
"papaparse": "^5.5.3",
|
|
78
77
|
"url-operator": "^0.3.1"
|
|
79
78
|
},
|
|
80
79
|
"peerDependencies": {
|
|
81
|
-
"extra-fetch": "^
|
|
80
|
+
"extra-fetch": "^5.0.1"
|
|
82
81
|
}
|
|
83
82
|
}
|
package/src/request.ts
CHANGED
|
@@ -27,7 +27,7 @@ export function del(...transformers: Array<IRequestOptionsTransformer | Falsy>):
|
|
|
27
27
|
return request('DELETE', ...transformers)
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
function request(
|
|
30
|
+
export function request(
|
|
31
31
|
method: 'GET' | 'HEAD' | 'PUT' | 'POST' | 'PATCH' | 'DELETE'
|
|
32
32
|
, ...transformers: Array<IRequestOptionsTransformer | Falsy>
|
|
33
33
|
): Request {
|
|
@@ -38,7 +38,7 @@ function request(
|
|
|
38
38
|
method
|
|
39
39
|
, headers
|
|
40
40
|
, signal: requestOptions.signal
|
|
41
|
-
, body: requestOptions.payload
|
|
41
|
+
, body: requestOptions.payload
|
|
42
42
|
, keepalive: requestOptions.keepalive
|
|
43
43
|
, redirect: requestOptions.redirect
|
|
44
44
|
})
|
package/src/transformers/body.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { IRequestOptions, IRequestOptionsTransformer } from '@src/types.js'
|
|
2
2
|
|
|
3
|
-
export function body(
|
|
3
|
+
export function body(body: BodyInit): IRequestOptionsTransformer {
|
|
4
4
|
return (options: IRequestOptions) => {
|
|
5
5
|
return {
|
|
6
6
|
...options
|
|
7
|
-
, payload:
|
|
7
|
+
, payload: body
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
}
|
|
@@ -1,29 +1,30 @@
|
|
|
1
|
-
export * from '
|
|
1
|
+
export * from './url.js'
|
|
2
2
|
|
|
3
|
-
export * from '
|
|
4
|
-
export * from '
|
|
5
|
-
export * from '
|
|
3
|
+
export * from './text.js'
|
|
4
|
+
export * from './json.js'
|
|
5
|
+
export * from './csv.js'
|
|
6
6
|
|
|
7
|
-
export * from '
|
|
8
|
-
export * from '
|
|
9
|
-
export * from '
|
|
10
|
-
export * from '
|
|
7
|
+
export * from './header.js'
|
|
8
|
+
export * from './append-header.js'
|
|
9
|
+
export * from './headers.js'
|
|
10
|
+
export * from './accept.js'
|
|
11
11
|
|
|
12
|
-
export * from '
|
|
13
|
-
export * from '
|
|
14
|
-
export * from '
|
|
15
|
-
export * from '
|
|
16
|
-
export * from '
|
|
17
|
-
export * from '
|
|
18
|
-
export * from '
|
|
19
|
-
export * from '
|
|
12
|
+
export * from './host.js'
|
|
13
|
+
export * from './port.js'
|
|
14
|
+
export * from './pathname.js'
|
|
15
|
+
export * from './append-pathname.js'
|
|
16
|
+
export * from './search.js'
|
|
17
|
+
export * from './search-param.js'
|
|
18
|
+
export * from './search-params.js'
|
|
19
|
+
export * from './append-search-param.js'
|
|
20
20
|
|
|
21
|
-
export * from '
|
|
21
|
+
export * from './form-data-field.js'
|
|
22
22
|
|
|
23
|
-
export * from '
|
|
24
|
-
export * from '
|
|
23
|
+
export * from './basic-auth.js'
|
|
24
|
+
export * from './bearer-auth.js'
|
|
25
25
|
|
|
26
|
-
export * from '
|
|
27
|
-
export * from '
|
|
28
|
-
export * from '
|
|
29
|
-
export * from '
|
|
26
|
+
export * from './signal.js'
|
|
27
|
+
export * from './keepalive.js'
|
|
28
|
+
export * from './redirect.js'
|
|
29
|
+
export * from './body.js'
|
|
30
|
+
export * from './cache.js'
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { IRequestOptionsTransformer, IRequestOptions } from '@src/types.js'
|
|
2
2
|
|
|
3
|
-
export function keepalive(
|
|
3
|
+
export function keepalive(keepalive: boolean = true): IRequestOptionsTransformer {
|
|
4
4
|
return (options: IRequestOptions) => {
|
|
5
5
|
return {
|
|
6
6
|
...options
|
|
7
|
-
, keepalive
|
|
7
|
+
, keepalive
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { IRequestOptions, IRequestOptionsTransformer } from '@src/types.js'
|
|
2
2
|
|
|
3
|
-
export function redirect(
|
|
3
|
+
export function redirect(redirect: RequestRedirect): IRequestOptionsTransformer {
|
|
4
4
|
return (options: IRequestOptions) => {
|
|
5
5
|
return {
|
|
6
6
|
...options
|
|
7
|
-
, redirect
|
|
7
|
+
, redirect
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
}
|
package/src/types.ts
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
export type IRequestOptionsTransformer = (options: IRequestOptions) => IRequestOptions
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Q: Why not use `Request` interface?
|
|
5
|
-
* A: Because `Request['body']` is `ReadableStream`,
|
|
6
|
-
* it is very difficult to use.
|
|
7
|
-
*
|
|
8
4
|
* Q: Why not use `RequestInit` interface?
|
|
9
5
|
* A: Because `RequestInit` has no `url` property,
|
|
10
6
|
* and its optional properties are not suitable for our cases.
|
|
@@ -12,10 +8,9 @@ export type IRequestOptionsTransformer = (options: IRequestOptions) => IRequestO
|
|
|
12
8
|
export interface IRequestOptions {
|
|
13
9
|
url: URL
|
|
14
10
|
headers: Headers
|
|
15
|
-
payload?:
|
|
16
|
-
| BodyInit // WHATWG
|
|
17
|
-
| NodeJS.ReadableStream // node-fetch
|
|
11
|
+
payload?: BodyInit
|
|
18
12
|
signal?: AbortSignal
|
|
19
13
|
keepalive?: boolean
|
|
20
14
|
redirect?: RequestRedirect
|
|
15
|
+
cache?: RequestCache
|
|
21
16
|
}
|