extra-request 10.0.0 → 10.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/README.md CHANGED
@@ -23,12 +23,13 @@ const res = await fetch(req)
23
23
  ## API
24
24
  ```ts
25
25
  interface IRequestOptions {
26
- url?: URL
27
- headers?: Headers
26
+ url: URL
27
+ headers: Headers
28
28
  payload?: BodyInit
29
29
  signal?: AbortSignal
30
30
  keepalive?: boolean
31
31
  redirect?: RequestRedirect
32
+ cache?: RequestCache
32
33
  }
33
34
 
34
35
  type IRequestOptionsTransformer = (options: IRequestOptions) => RequestOptions
@@ -64,6 +65,14 @@ function patch(...transformers: Array<IRequestOptionsTransformer | Falsy>): Requ
64
65
  function del(...transformers: Array<IRequestOptionsTrransformer | Falsy>): Request
65
66
  ```
66
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
+
67
76
  ### pipeRequestOptionsTransformers
68
77
  ```ts
69
78
  function pipeRequestOptionsTransformers(
@@ -121,6 +130,11 @@ function headers<T extends Record<string, string>>(
121
130
  function host(host: string): IRequestOptionsTransformer
122
131
  ```
123
132
 
133
+ #### hostname
134
+ ```ts
135
+ function hostname(hostname: string): IRequestOptionsTransformer
136
+ ```
137
+
124
138
  #### port
125
139
  ```ts
126
140
  function port(port: number): IRequestOptionsTransformer
@@ -184,15 +198,20 @@ function bearerAuth(token: string): IRequestOptionsTransformer
184
198
 
185
199
  #### keepalive
186
200
  ```ts
187
- function keepalive(val: boolean = true): IRequestOptionsTransformer
201
+ function keepalive(keepalive: boolean = true): IRequestOptionsTransformer
188
202
  ```
189
203
 
190
204
  #### redirect
191
205
  ```ts
192
- function redirect(val: RequestRedirect): IRequestOptionsTransformer
206
+ function redirect(redirect: RequestRedirect): IRequestOptionsTransformer
193
207
  ```
194
208
 
195
209
  #### body
196
210
  ```ts
197
- function body(val: BodyInit): IRequestOptionsTransformer
211
+ function body(body: BodyInit): IRequestOptionsTransformer
212
+ ```
213
+
214
+ #### cache
215
+ ```ts
216
+ function cache(cache: RequestCache): IRequestOptionsTransformer
198
217
  ```
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, {
@@ -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,SAAS,OAAO,CACd,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,OAAc;QACnC,SAAS,EAAE,cAAc,CAAC,SAAS;QACnC,QAAQ,EAAE,cAAc,CAAC,QAAQ;KAClC,CAAC,CAAA;AACJ,CAAC"}
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(val: BodyInit): IRequestOptionsTransformer;
2
+ export declare function body(body: BodyInit): IRequestOptionsTransformer;
@@ -1,8 +1,8 @@
1
- export function body(val) {
1
+ export function body(body) {
2
2
  return (options) => {
3
3
  return {
4
4
  ...options,
5
- payload: val
5
+ payload: body
6
6
  };
7
7
  };
8
8
  }
@@ -1 +1 @@
1
- {"version":3,"file":"body.js","sourceRoot":"","sources":["../../src/transformers/body.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,IAAI,CAAC,GAAa;IAChC,OAAO,CAAC,OAAwB,EAAE,EAAE;QAClC,OAAO;YACL,GAAG,OAAO;YACV,OAAO,EAAE,GAAG;SACb,CAAA;IACH,CAAC,CAAA;AACH,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,2 @@
1
+ import { IRequestOptionsTransformer } from "../types.js";
2
+ export declare function cache(cache: RequestCache): IRequestOptionsTransformer;
@@ -0,0 +1,9 @@
1
+ export function cache(cache) {
2
+ return (options) => {
3
+ return {
4
+ ...options,
5
+ cache
6
+ };
7
+ };
8
+ }
9
+ //# sourceMappingURL=cache.js.map
@@ -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"}
@@ -0,0 +1,2 @@
1
+ import { IRequestOptionsTransformer } from "../types.js";
2
+ export declare function hostname(hostname: string): IRequestOptionsTransformer;
@@ -0,0 +1,10 @@
1
+ import { setHostname } from 'url-operator';
2
+ export function hostname(hostname) {
3
+ return (options) => {
4
+ return {
5
+ ...options,
6
+ url: setHostname(options.url, hostname)
7
+ };
8
+ };
9
+ }
10
+ //# sourceMappingURL=hostname.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hostname.js","sourceRoot":"","sources":["../../src/transformers/hostname.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAE1C,MAAM,UAAU,QAAQ,CAAC,QAAgB;IACvC,OAAO,CAAC,OAAwB,EAAE,EAAE;QAClC,OAAO;YACL,GAAG,OAAO;YACV,GAAG,EAAE,WAAW,CAAC,OAAO,CAAC,GAAG,EAAE,QAAQ,CAAC;SACxC,CAAA;IACH,CAAC,CAAA;AACH,CAAC"}
@@ -1,23 +1,25 @@
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";
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 './hostname.js';
11
+ export * from './port.js';
12
+ export * from './pathname.js';
13
+ export * from './append-pathname.js';
14
+ export * from './search.js';
15
+ export * from './search-param.js';
16
+ export * from './search-params.js';
17
+ export * from './append-search-param.js';
18
+ export * from './form-data-field.js';
19
+ export * from './basic-auth.js';
20
+ export * from './bearer-auth.js';
21
+ export * from './signal.js';
22
+ export * from './keepalive.js';
23
+ export * from './redirect.js';
24
+ export * from './body.js';
25
+ export * from './cache.js';
@@ -1,24 +1,26 @@
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";
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 './hostname.js';
11
+ export * from './port.js';
12
+ export * from './pathname.js';
13
+ export * from './append-pathname.js';
14
+ export * from './search.js';
15
+ export * from './search-param.js';
16
+ export * from './search-params.js';
17
+ export * from './append-search-param.js';
18
+ export * from './form-data-field.js';
19
+ export * from './basic-auth.js';
20
+ export * from './bearer-auth.js';
21
+ export * from './signal.js';
22
+ export * from './keepalive.js';
23
+ export * from './redirect.js';
24
+ export * from './body.js';
25
+ export * from './cache.js';
24
26
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/transformers/index.ts"],"names":[],"mappings":"AAAA,yBAAoC;AAEpC,0BAAqC;AACrC,0BAAqC;AACrC,yBAAoC;AAEpC,4BAAuC;AACvC,mCAA8C;AAC9C,6BAAwC;AACxC,4BAAuC;AAEvC,0BAAqC;AACrC,0BAAqC;AACrC,8BAAyC;AACzC,qCAAgD;AAChD,4BAAuC;AACvC,kCAA6C;AAC7C,mCAA8C;AAC9C,yCAAoD;AAEpD,qCAAgD;AAEhD,gCAA2C;AAC3C,iCAA4C;AAE5C,4BAAuC;AACvC,+BAA0C;AAC1C,8BAAyC;AACzC,0BAAqC"}
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,eAAe,CAAA;AAC7B,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(val?: boolean): IRequestOptionsTransformer;
2
+ export declare function keepalive(keepalive?: boolean): IRequestOptionsTransformer;
@@ -1,8 +1,8 @@
1
- export function keepalive(val = true) {
1
+ export function keepalive(keepalive = true) {
2
2
  return (options) => {
3
3
  return {
4
4
  ...options,
5
- keepalive: val
5
+ keepalive
6
6
  };
7
7
  };
8
8
  }
@@ -1 +1 @@
1
- {"version":3,"file":"keepalive.js","sourceRoot":"","sources":["../../src/transformers/keepalive.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,SAAS,CAAC,MAAe,IAAI;IAC3C,OAAO,CAAC,OAAwB,EAAE,EAAE;QAClC,OAAO;YACL,GAAG,OAAO;YACV,SAAS,EAAE,GAAG;SACf,CAAA;IACH,CAAC,CAAA;AACH,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(val: RequestRedirect): IRequestOptionsTransformer;
2
+ export declare function redirect(redirect: RequestRedirect): IRequestOptionsTransformer;
@@ -1,8 +1,8 @@
1
- export function redirect(val) {
1
+ export function redirect(redirect) {
2
2
  return (options) => {
3
3
  return {
4
4
  ...options,
5
- redirect: val
5
+ redirect
6
6
  };
7
7
  };
8
8
  }
@@ -1 +1 @@
1
- {"version":3,"file":"redirect.js","sourceRoot":"","sources":["../../src/transformers/redirect.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,QAAQ,CAAC,GAAoB;IAC3C,OAAO,CAAC,OAAwB,EAAE,EAAE;QAClC,OAAO;YACL,GAAG,OAAO;YACV,QAAQ,EAAE,GAAG;SACd,CAAA;IACH,CAAC,CAAA;AACH,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
@@ -6,4 +6,5 @@ export interface IRequestOptions {
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": "10.0.0",
3
+ "version": "10.2.0",
4
4
  "description": "Utilities for Request",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -70,11 +70,11 @@
70
70
  },
71
71
  "dependencies": {
72
72
  "@blackglory/prelude": "^0.4.0",
73
- "extra-utils": "^5.19.0",
73
+ "extra-utils": "^5.20.0",
74
74
  "js-base64": "^3.7.7",
75
75
  "justypes": "^4.4.1",
76
76
  "papaparse": "^5.5.3",
77
- "url-operator": "^0.3.1"
77
+ "url-operator": "^0.3.2"
78
78
  },
79
79
  "peerDependencies": {
80
80
  "extra-fetch": "^5.0.1"
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 as any
41
+ , body: requestOptions.payload
42
42
  , keepalive: requestOptions.keepalive
43
43
  , redirect: requestOptions.redirect
44
44
  })
@@ -1,10 +1,10 @@
1
1
  import { IRequestOptions, IRequestOptionsTransformer } from '@src/types.js'
2
2
 
3
- export function body(val: BodyInit): IRequestOptionsTransformer {
3
+ export function body(body: BodyInit): IRequestOptionsTransformer {
4
4
  return (options: IRequestOptions) => {
5
5
  return {
6
6
  ...options
7
- , payload: val
7
+ , payload: body
8
8
  }
9
9
  }
10
10
  }
@@ -0,0 +1,10 @@
1
+ import { IRequestOptions, IRequestOptionsTransformer } from '@src/types.js'
2
+
3
+ export function cache(cache: RequestCache): IRequestOptionsTransformer {
4
+ return (options: IRequestOptions) => {
5
+ return {
6
+ ...options
7
+ , cache
8
+ }
9
+ }
10
+ }
@@ -0,0 +1,11 @@
1
+ import { IRequestOptions, IRequestOptionsTransformer } from '@src/types.js'
2
+ import { setHostname } from 'url-operator'
3
+
4
+ export function hostname(hostname: string): IRequestOptionsTransformer {
5
+ return (options: IRequestOptions) => {
6
+ return {
7
+ ...options
8
+ , url: setHostname(options.url, hostname)
9
+ }
10
+ }
11
+ }
@@ -1,29 +1,31 @@
1
- export * from '@transformers/url.js'
1
+ export * from './url.js'
2
2
 
3
- export * from '@transformers/text.js'
4
- export * from '@transformers/json.js'
5
- export * from '@transformers/csv.js'
3
+ export * from './text.js'
4
+ export * from './json.js'
5
+ export * from './csv.js'
6
6
 
7
- export * from '@transformers/header.js'
8
- export * from '@transformers/append-header.js'
9
- export * from '@transformers/headers.js'
10
- export * from '@transformers/accept.js'
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 '@transformers/host.js'
13
- export * from '@transformers/port.js'
14
- export * from '@transformers/pathname.js'
15
- export * from '@transformers/append-pathname.js'
16
- export * from '@transformers/search.js'
17
- export * from '@transformers/search-param.js'
18
- export * from '@transformers/search-params.js'
19
- export * from '@transformers/append-search-param.js'
12
+ export * from './host.js'
13
+ export * from './hostname.js'
14
+ export * from './port.js'
15
+ export * from './pathname.js'
16
+ export * from './append-pathname.js'
17
+ export * from './search.js'
18
+ export * from './search-param.js'
19
+ export * from './search-params.js'
20
+ export * from './append-search-param.js'
20
21
 
21
- export * from '@transformers/form-data-field.js'
22
+ export * from './form-data-field.js'
22
23
 
23
- export * from '@transformers/basic-auth.js'
24
- export * from '@transformers/bearer-auth.js'
24
+ export * from './basic-auth.js'
25
+ export * from './bearer-auth.js'
25
26
 
26
- export * from '@transformers/signal.js'
27
- export * from '@transformers/keepalive.js'
28
- export * from '@transformers/redirect.js'
29
- export * from '@transformers/body.js'
27
+ export * from './signal.js'
28
+ export * from './keepalive.js'
29
+ export * from './redirect.js'
30
+ export * from './body.js'
31
+ export * from './cache.js'
@@ -1,10 +1,10 @@
1
1
  import { IRequestOptionsTransformer, IRequestOptions } from '@src/types.js'
2
2
 
3
- export function keepalive(val: boolean = true): IRequestOptionsTransformer {
3
+ export function keepalive(keepalive: boolean = true): IRequestOptionsTransformer {
4
4
  return (options: IRequestOptions) => {
5
5
  return {
6
6
  ...options
7
- , keepalive: val
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(val: RequestRedirect): IRequestOptionsTransformer {
3
+ export function redirect(redirect: RequestRedirect): IRequestOptionsTransformer {
4
4
  return (options: IRequestOptions) => {
5
5
  return {
6
6
  ...options
7
- , redirect: val
7
+ , redirect
8
8
  }
9
9
  }
10
10
  }
package/src/types.ts CHANGED
@@ -1,14 +1,8 @@
1
1
  export type IRequestOptionsTransformer = (options: IRequestOptions) => IRequestOptions
2
2
 
3
- /**
4
- * Q: Why not use `Request` interface?
5
- * A: Because `Request['body']` is `ReadableStream`,
6
- * it is very difficult to use.
7
- *
8
- * Q: Why not use `RequestInit` interface?
9
- * A: Because `RequestInit` has no `url` property,
10
- * and its optional properties are not suitable for our cases.
11
- */
3
+ // 为什么不使用`RequestInit`接口:
4
+ // - `RequestInit`没有`url`属性.
5
+ // - `RequestInit`的类型更不明确, 例如`headers`的类型是`HeadersInit`, 不便处理.
12
6
  export interface IRequestOptions {
13
7
  url: URL
14
8
  headers: Headers
@@ -16,4 +10,5 @@ export interface IRequestOptions {
16
10
  signal?: AbortSignal
17
11
  keepalive?: boolean
18
12
  redirect?: RequestRedirect
13
+ cache?: RequestCache
19
14
  }