@ahoo-wang/fetcher 0.8.9 → 0.9.1
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 +7 -12
- package/README.zh-CN.md +7 -12
- package/dist/fetchExchange.d.ts +26 -11
- package/dist/fetchExchange.d.ts.map +1 -1
- package/dist/fetchInterceptor.d.ts +14 -15
- package/dist/fetchInterceptor.d.ts.map +1 -1
- package/dist/fetcher.d.ts +93 -56
- package/dist/fetcher.d.ts.map +1 -1
- package/dist/index.es.js +219 -174
- package/dist/index.umd.js +1 -1
- package/dist/interceptor.d.ts +60 -62
- package/dist/interceptor.d.ts.map +1 -1
- package/dist/requestBodyInterceptor.d.ts +15 -20
- package/dist/requestBodyInterceptor.d.ts.map +1 -1
- package/dist/timeout.d.ts +9 -11
- package/dist/timeout.d.ts.map +1 -1
- package/dist/urlBuilder.d.ts +25 -19
- package/dist/urlBuilder.d.ts.map +1 -1
- package/dist/urlResolveInterceptor.d.ts +7 -13
- package/dist/urlResolveInterceptor.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -139,14 +139,11 @@ const success = fetcher.interceptors.request.use({
|
|
|
139
139
|
name: 'auth-interceptor',
|
|
140
140
|
order: 100,
|
|
141
141
|
intercept(exchange) {
|
|
142
|
-
|
|
143
|
-
...exchange,
|
|
144
|
-
|
|
145
|
-
...exchange.request,
|
|
146
|
-
|
|
147
|
-
...exchange.request.headers,
|
|
148
|
-
Authorization: 'Bearer ' + getAuthToken(),
|
|
149
|
-
},
|
|
142
|
+
exchange.request = {
|
|
143
|
+
...exchange.request,
|
|
144
|
+
headers: {
|
|
145
|
+
...exchange.request.headers,
|
|
146
|
+
Authorization: 'Bearer ' + getAuthToken(),
|
|
150
147
|
},
|
|
151
148
|
};
|
|
152
149
|
},
|
|
@@ -158,7 +155,6 @@ fetcher.interceptors.response.use({
|
|
|
158
155
|
order: 10,
|
|
159
156
|
intercept(exchange) {
|
|
160
157
|
console.log('Response received:', exchange.response?.status);
|
|
161
|
-
return exchange;
|
|
162
158
|
},
|
|
163
159
|
});
|
|
164
160
|
|
|
@@ -172,7 +168,6 @@ fetcher.interceptors.error.use({
|
|
|
172
168
|
} else {
|
|
173
169
|
console.error('Network error:', exchange.error?.message);
|
|
174
170
|
}
|
|
175
|
-
return exchange;
|
|
176
171
|
},
|
|
177
172
|
});
|
|
178
173
|
|
|
@@ -335,7 +330,7 @@ Interceptor interface that defines the basic structure of interceptors.
|
|
|
335
330
|
|
|
336
331
|
**Methods:**
|
|
337
332
|
|
|
338
|
-
- `intercept(exchange: FetchExchange):
|
|
333
|
+
- `intercept(exchange: FetchExchange): void | Promise<void>` - Intercept and process data
|
|
339
334
|
|
|
340
335
|
#### InterceptorManager Class
|
|
341
336
|
|
|
@@ -346,7 +341,7 @@ Interceptor manager for managing multiple interceptors of the same type.
|
|
|
346
341
|
- `use(interceptor: Interceptor): boolean` - Add interceptor, returns whether the addition was successful
|
|
347
342
|
- `eject(name: string): boolean` - Remove interceptor by name, returns whether the removal was successful
|
|
348
343
|
- `clear(): void` - Clear all interceptors
|
|
349
|
-
- `intercept(exchange: FetchExchange): Promise<
|
|
344
|
+
- `intercept(exchange: FetchExchange): Promise<void>` - Execute all interceptors in sequence
|
|
350
345
|
|
|
351
346
|
#### FetcherInterceptors Class
|
|
352
347
|
|
package/README.zh-CN.md
CHANGED
|
@@ -137,14 +137,11 @@ const success = fetcher.interceptors.request.use({
|
|
|
137
137
|
name: 'auth-interceptor',
|
|
138
138
|
order: 100,
|
|
139
139
|
intercept(exchange) {
|
|
140
|
-
|
|
141
|
-
...exchange,
|
|
142
|
-
|
|
143
|
-
...exchange.request,
|
|
144
|
-
|
|
145
|
-
...exchange.request.headers,
|
|
146
|
-
Authorization: 'Bearer ' + getAuthToken(),
|
|
147
|
-
},
|
|
140
|
+
exchange.request = {
|
|
141
|
+
...exchange.request,
|
|
142
|
+
headers: {
|
|
143
|
+
...exchange.request.headers,
|
|
144
|
+
Authorization: 'Bearer ' + getAuthToken(),
|
|
148
145
|
},
|
|
149
146
|
};
|
|
150
147
|
},
|
|
@@ -156,7 +153,6 @@ fetcher.interceptors.response.use({
|
|
|
156
153
|
order: 10,
|
|
157
154
|
intercept(exchange) {
|
|
158
155
|
console.log('收到响应:', exchange.response?.status);
|
|
159
|
-
return exchange;
|
|
160
156
|
},
|
|
161
157
|
});
|
|
162
158
|
|
|
@@ -170,7 +166,6 @@ fetcher.interceptors.error.use({
|
|
|
170
166
|
} else {
|
|
171
167
|
console.error('网络错误:', exchange.error?.message);
|
|
172
168
|
}
|
|
173
|
-
return exchange;
|
|
174
169
|
},
|
|
175
170
|
});
|
|
176
171
|
|
|
@@ -333,7 +328,7 @@ string, options ? : FetcherOptions
|
|
|
333
328
|
|
|
334
329
|
**方法:**
|
|
335
330
|
|
|
336
|
-
- `intercept(exchange: FetchExchange):
|
|
331
|
+
- `intercept(exchange: FetchExchange): void | Promise<void>` - 拦截并处理数据
|
|
337
332
|
|
|
338
333
|
#### InterceptorManager 类
|
|
339
334
|
|
|
@@ -344,7 +339,7 @@ string, options ? : FetcherOptions
|
|
|
344
339
|
- `use(interceptor: Interceptor): boolean` - 添加拦截器,返回是否添加成功
|
|
345
340
|
- `eject(name: string): boolean` - 按名称移除拦截器,返回是否移除成功
|
|
346
341
|
- `clear(): void` - 清除所有拦截器
|
|
347
|
-
- `intercept(exchange: FetchExchange): Promise<
|
|
342
|
+
- `intercept(exchange: FetchExchange): Promise<void>` - 顺序执行所有拦截器
|
|
348
343
|
|
|
349
344
|
#### FetcherInterceptors 类
|
|
350
345
|
|
package/dist/fetchExchange.d.ts
CHANGED
|
@@ -1,25 +1,28 @@
|
|
|
1
1
|
import { Fetcher } from './fetcher';
|
|
2
2
|
import { FetchRequest } from './fetchRequest';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Container for HTTP request/response data that flows through the interceptor chain.
|
|
5
5
|
*
|
|
6
6
|
* Represents the complete exchange object that flows through the interceptor chain.
|
|
7
7
|
* This object contains all the information about a request, response, and any errors
|
|
8
8
|
* that occur during the HTTP request lifecycle. It also provides a mechanism for
|
|
9
9
|
* sharing data between interceptors through the attributes property.
|
|
10
10
|
*
|
|
11
|
+
* FetchExchange instances are unique within a single request scope, meaning each HTTP
|
|
12
|
+
* request creates its own FetchExchange instance that is passed through the interceptor
|
|
13
|
+
* chain for that specific request.
|
|
14
|
+
*
|
|
11
15
|
* @example
|
|
12
16
|
* ```typescript
|
|
13
17
|
* // In a request interceptor
|
|
14
18
|
* const requestInterceptor: Interceptor = {
|
|
15
19
|
* name: 'RequestInterceptor',
|
|
16
20
|
* order: 0,
|
|
17
|
-
*
|
|
21
|
+
* intercept(exchange: FetchExchange) {
|
|
18
22
|
* // Add custom data to share with other interceptors
|
|
19
23
|
* exchange.attributes = exchange.attributes || {};
|
|
20
24
|
* exchange.attributes.startTime = Date.now();
|
|
21
25
|
* exchange.attributes.customHeader = 'my-value';
|
|
22
|
-
* return exchange;
|
|
23
26
|
* }
|
|
24
27
|
* };
|
|
25
28
|
*
|
|
@@ -27,21 +30,20 @@ import { FetchRequest } from './fetchRequest';
|
|
|
27
30
|
* const responseInterceptor: Interceptor = {
|
|
28
31
|
* name: 'ResponseInterceptor',
|
|
29
32
|
* order: 0,
|
|
30
|
-
*
|
|
33
|
+
* intercept(exchange: FetchExchange) {
|
|
31
34
|
* // Access data shared by previous interceptors
|
|
32
35
|
* if (exchange.attributes && exchange.attributes.startTime) {
|
|
33
36
|
* const startTime = exchange.attributes.startTime;
|
|
34
37
|
* const duration = Date.now() - startTime;
|
|
35
38
|
* console.log(`Request took ${duration}ms`);
|
|
36
39
|
* }
|
|
37
|
-
* return exchange;
|
|
38
40
|
* }
|
|
39
41
|
* };
|
|
40
42
|
* ```
|
|
41
43
|
*/
|
|
42
|
-
export
|
|
44
|
+
export declare class FetchExchange {
|
|
43
45
|
/**
|
|
44
|
-
* The Fetcher instance that initiated this exchange
|
|
46
|
+
* The Fetcher instance that initiated this exchange.
|
|
45
47
|
*/
|
|
46
48
|
fetcher: Fetcher;
|
|
47
49
|
/**
|
|
@@ -49,15 +51,15 @@ export interface FetchExchange {
|
|
|
49
51
|
*/
|
|
50
52
|
request: FetchRequest;
|
|
51
53
|
/**
|
|
52
|
-
* The response object, undefined until the request completes successfully
|
|
54
|
+
* The response object, undefined until the request completes successfully.
|
|
53
55
|
*/
|
|
54
56
|
response: Response | undefined;
|
|
55
57
|
/**
|
|
56
|
-
* Any error that occurred during the request processing, undefined if no error occurred
|
|
58
|
+
* Any error that occurred during the request processing, undefined if no error occurred.
|
|
57
59
|
*/
|
|
58
60
|
error: Error | any | undefined;
|
|
59
61
|
/**
|
|
60
|
-
* Shared attributes for passing data between interceptors
|
|
62
|
+
* Shared attributes for passing data between interceptors.
|
|
61
63
|
*
|
|
62
64
|
* This property allows interceptors to share arbitrary data with each other.
|
|
63
65
|
* Interceptors can read from and write to this object to pass information
|
|
@@ -70,6 +72,19 @@ export interface FetchExchange {
|
|
|
70
72
|
* - Consider namespacing your keys (e.g., 'mylib.retryCount' instead of 'retryCount')
|
|
71
73
|
* - Be mindful of memory usage when storing large objects
|
|
72
74
|
*/
|
|
73
|
-
attributes
|
|
75
|
+
attributes: Record<string, any>;
|
|
76
|
+
constructor(fetcher: Fetcher, request: FetchRequest, response?: Response, error?: Error | any);
|
|
77
|
+
/**
|
|
78
|
+
* Checks if the exchange has an error.
|
|
79
|
+
*
|
|
80
|
+
* @returns true if an error is present, false otherwise
|
|
81
|
+
*/
|
|
82
|
+
hasError(): boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Checks if the exchange has a response.
|
|
85
|
+
*
|
|
86
|
+
* @returns true if a response is present, false otherwise
|
|
87
|
+
*/
|
|
88
|
+
hasResponse(): boolean;
|
|
74
89
|
}
|
|
75
90
|
//# sourceMappingURL=fetchExchange.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetchExchange.d.ts","sourceRoot":"","sources":["../src/fetchExchange.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C
|
|
1
|
+
{"version":3,"file":"fetchExchange.d.ts","sourceRoot":"","sources":["../src/fetchExchange.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,qBAAa,aAAa;IACxB;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;IAEjB;;OAEG;IACH,OAAO,EAAE,YAAY,CAAC;IAEtB;;OAEG;IACH,QAAQ,EAAE,QAAQ,GAAG,SAAS,CAAC;IAE/B;;OAEG;IACH,KAAK,EAAE,KAAK,GAAG,GAAG,GAAG,SAAS,CAAC;IAE/B;;;;;;;;;;;;;OAaG;IACH,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAM;gBAGnC,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,YAAY,EACrB,QAAQ,CAAC,EAAE,QAAQ,EACnB,KAAK,CAAC,EAAE,KAAK,GAAG,GAAG;IAQrB;;;;OAIG;IACH,QAAQ,IAAI,OAAO;IAInB;;;;OAIG;IACH,WAAW,IAAI,OAAO;CAGvB"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Interceptor } from './interceptor';
|
|
2
2
|
import { FetchExchange } from './fetchExchange';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Interceptor implementation responsible for executing actual HTTP requests.
|
|
5
5
|
*
|
|
6
6
|
* This is an interceptor implementation responsible for executing actual HTTP requests
|
|
7
7
|
* and handling timeout control. It is the last interceptor in the Fetcher request
|
|
@@ -15,17 +15,15 @@ import { FetchExchange } from './fetchExchange';
|
|
|
15
15
|
*/
|
|
16
16
|
export declare class FetchInterceptor implements Interceptor {
|
|
17
17
|
/**
|
|
18
|
-
* Interceptor name, used to identify and manage interceptor instances
|
|
18
|
+
* Interceptor name, used to identify and manage interceptor instances.
|
|
19
19
|
*
|
|
20
|
-
* @remarks
|
|
21
20
|
* Each interceptor must have a unique name for identification and manipulation
|
|
22
|
-
* within the interceptor manager
|
|
21
|
+
* within the interceptor manager.
|
|
23
22
|
*/
|
|
24
23
|
name: string;
|
|
25
24
|
/**
|
|
26
|
-
* Interceptor execution order, set to near maximum safe integer to ensure last execution
|
|
25
|
+
* Interceptor execution order, set to near maximum safe integer to ensure last execution.
|
|
27
26
|
*
|
|
28
|
-
* @remarks
|
|
29
27
|
* Since this is the interceptor that actually executes HTTP requests, it should
|
|
30
28
|
* execute after all other request interceptors, so its order is set to
|
|
31
29
|
* Number.MAX_SAFE_INTEGER - 100. This ensures that all request preprocessing is
|
|
@@ -34,29 +32,30 @@ export declare class FetchInterceptor implements Interceptor {
|
|
|
34
32
|
*/
|
|
35
33
|
order: number;
|
|
36
34
|
/**
|
|
37
|
-
* Intercept and process HTTP requests
|
|
35
|
+
* Intercept and process HTTP requests.
|
|
38
36
|
*
|
|
39
37
|
* Executes the actual HTTP request and applies timeout control. This is the final
|
|
40
38
|
* step in the request processing chain, responsible for calling the timeoutFetch
|
|
41
39
|
* function to send the network request.
|
|
42
40
|
*
|
|
43
41
|
* @param exchange - Exchange object containing request information
|
|
44
|
-
* @returns Promise<FetchExchange> Processed exchange object containing response information
|
|
45
42
|
*
|
|
46
43
|
* @throws {FetchTimeoutError} Throws timeout exception when request times out
|
|
47
44
|
*
|
|
48
45
|
* @example
|
|
49
46
|
* // Usually called internally by Fetcher
|
|
50
|
-
* const
|
|
51
|
-
*
|
|
52
|
-
*
|
|
47
|
+
* const fetcher = new Fetcher();
|
|
48
|
+
* const exchange = new FetchExchange(
|
|
49
|
+
* fetcher,
|
|
50
|
+
* {
|
|
51
|
+
* url: 'https://api.example.com/users',
|
|
53
52
|
* method: 'GET',
|
|
54
53
|
* timeout: 5000
|
|
55
54
|
* }
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
* console.log(
|
|
55
|
+
* );
|
|
56
|
+
* await fetchInterceptor.intercept(exchange);
|
|
57
|
+
* console.log(exchange.response); // HTTP response object
|
|
59
58
|
*/
|
|
60
|
-
intercept(exchange: FetchExchange): Promise<
|
|
59
|
+
intercept(exchange: FetchExchange): Promise<void>;
|
|
61
60
|
}
|
|
62
61
|
//# sourceMappingURL=fetchInterceptor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetchInterceptor.d.ts","sourceRoot":"","sources":["../src/fetchInterceptor.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;;;;;;;;;;;GAYG;AACH,qBAAa,gBAAiB,YAAW,WAAW;IAClD
|
|
1
|
+
{"version":3,"file":"fetchInterceptor.d.ts","sourceRoot":"","sources":["../src/fetchInterceptor.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;;;;;;;;;;;GAYG;AACH,qBAAa,gBAAiB,YAAW,WAAW;IAClD;;;;;OAKG;IACH,IAAI,SAAsB;IAE1B;;;;;;;;OAQG;IACH,KAAK,SAAiC;IAEtC;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACG,SAAS,CAAC,QAAQ,EAAE,aAAa;CAGxC"}
|
package/dist/fetcher.d.ts
CHANGED
|
@@ -4,7 +4,10 @@ import { FetcherInterceptors } from './interceptor';
|
|
|
4
4
|
import { FetchExchange } from './fetchExchange';
|
|
5
5
|
import { BaseURLCapable, FetchRequest, FetchRequestInit, RequestHeaders, RequestHeadersCapable } from './fetchRequest';
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Configuration options for the Fetcher client.
|
|
8
|
+
*
|
|
9
|
+
* Defines the customizable aspects of a Fetcher instance including base URL,
|
|
10
|
+
* default headers, timeout settings, and interceptors.
|
|
8
11
|
*
|
|
9
12
|
* @example
|
|
10
13
|
* ```typescript
|
|
@@ -21,7 +24,11 @@ export interface FetcherOptions extends BaseURLCapable, RequestHeadersCapable, T
|
|
|
21
24
|
}
|
|
22
25
|
export declare const DEFAULT_OPTIONS: FetcherOptions;
|
|
23
26
|
/**
|
|
24
|
-
* HTTP client
|
|
27
|
+
* HTTP client with support for interceptors, URL building, and timeout control.
|
|
28
|
+
*
|
|
29
|
+
* The Fetcher class provides a flexible and extensible HTTP client implementation
|
|
30
|
+
* that follows the interceptor pattern. It supports URL parameter interpolation,
|
|
31
|
+
* request/response transformation, and timeout handling.
|
|
25
32
|
*
|
|
26
33
|
* @example
|
|
27
34
|
* ```typescript
|
|
@@ -41,108 +48,138 @@ export declare class Fetcher implements UrlBuilderCapable, RequestHeadersCapable
|
|
|
41
48
|
timeout?: number;
|
|
42
49
|
interceptors: FetcherInterceptors;
|
|
43
50
|
/**
|
|
44
|
-
*
|
|
51
|
+
* Initializes a new Fetcher instance with optional configuration.
|
|
52
|
+
*
|
|
53
|
+
* Creates a Fetcher with default settings that can be overridden through the options parameter.
|
|
54
|
+
* If no interceptors are provided, a default set of interceptors will be used.
|
|
45
55
|
*
|
|
46
|
-
* @param options - Fetcher
|
|
56
|
+
* @param options - Configuration options for the Fetcher instance
|
|
47
57
|
*/
|
|
48
58
|
constructor(options?: FetcherOptions);
|
|
49
59
|
/**
|
|
50
|
-
*
|
|
60
|
+
* Executes an HTTP request with the specified URL and options.
|
|
51
61
|
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
62
|
+
* This is the primary method for making HTTP requests. It processes the request
|
|
63
|
+
* through the interceptor chain and returns the resulting Response.
|
|
64
|
+
*
|
|
65
|
+
* @param url - The URL path for the request (relative to baseURL if set)
|
|
66
|
+
* @param request - Request configuration including headers, body, parameters, etc.
|
|
67
|
+
* @returns Promise that resolves to the HTTP response
|
|
68
|
+
* @throws Error if the request fails and no response is generated
|
|
55
69
|
*/
|
|
56
70
|
fetch(url: string, request?: FetchRequestInit): Promise<Response>;
|
|
57
71
|
/**
|
|
58
|
-
*
|
|
72
|
+
* Processes an HTTP request through the Fetcher's internal workflow.
|
|
59
73
|
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
74
|
+
* This method prepares the request by merging headers and timeout settings,
|
|
75
|
+
* creates a FetchExchange object, and passes it through the exchange method
|
|
76
|
+
* for interceptor processing.
|
|
62
77
|
*
|
|
63
|
-
* @
|
|
78
|
+
* @param request - Complete request configuration object
|
|
79
|
+
* @returns Promise that resolves to a FetchExchange containing request/response data
|
|
80
|
+
* @throws Error if an unhandled error occurs during request processing
|
|
64
81
|
*/
|
|
65
82
|
request(request: FetchRequest): Promise<FetchExchange>;
|
|
66
83
|
/**
|
|
67
|
-
*
|
|
84
|
+
* Processes a FetchExchange through the interceptor chain.
|
|
68
85
|
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
* 2. Response interceptors - to process the incoming response
|
|
86
|
+
* Orchestrates the complete request lifecycle by applying interceptors in sequence:
|
|
87
|
+
* 1. Request interceptors - Modify the outgoing request
|
|
88
|
+
* 2. Response interceptors - Process the incoming response
|
|
73
89
|
*
|
|
74
|
-
*
|
|
75
|
-
* If an error
|
|
76
|
-
*
|
|
90
|
+
* Error handling follows this flow:
|
|
91
|
+
* - If an error occurs, error interceptors are invoked
|
|
92
|
+
* - If an error interceptor produces a response, it's returned
|
|
93
|
+
* - Otherwise, the original error is re-thrown
|
|
77
94
|
*
|
|
78
|
-
* @param fetchExchange - The exchange object containing request
|
|
79
|
-
* @returns Promise
|
|
80
|
-
* @throws Error if an error occurs
|
|
95
|
+
* @param fetchExchange - The exchange object containing request and response data
|
|
96
|
+
* @returns Promise resolving to the processed exchange
|
|
97
|
+
* @throws Error if an unhandled error occurs during processing
|
|
81
98
|
*/
|
|
82
99
|
exchange(fetchExchange: FetchExchange): Promise<FetchExchange>;
|
|
83
100
|
/**
|
|
84
|
-
*
|
|
101
|
+
* Internal helper method for making HTTP requests with a specific method.
|
|
102
|
+
*
|
|
103
|
+
* This private method is used by the public HTTP method methods (get, post, etc.)
|
|
104
|
+
* to execute requests with the appropriate HTTP verb.
|
|
85
105
|
*
|
|
86
|
-
* @param method - HTTP method to use
|
|
87
|
-
* @param url -
|
|
88
|
-
* @param request -
|
|
89
|
-
* @returns Promise
|
|
106
|
+
* @param method - The HTTP method to use for the request
|
|
107
|
+
* @param url - The URL path for the request
|
|
108
|
+
* @param request - Additional request options
|
|
109
|
+
* @returns Promise that resolves to the HTTP response
|
|
90
110
|
*/
|
|
91
111
|
private methodFetch;
|
|
92
112
|
/**
|
|
93
|
-
*
|
|
113
|
+
* Makes a GET HTTP request.
|
|
114
|
+
*
|
|
115
|
+
* Convenience method for making GET requests. The request body is omitted
|
|
116
|
+
* as GET requests should not contain a body according to HTTP specification.
|
|
94
117
|
*
|
|
95
|
-
* @param url -
|
|
96
|
-
* @param request - Request options
|
|
97
|
-
* @returns Promise
|
|
118
|
+
* @param url - The URL path for the request
|
|
119
|
+
* @param request - Request options excluding method and body
|
|
120
|
+
* @returns Promise that resolves to the HTTP response
|
|
98
121
|
*/
|
|
99
122
|
get(url: string, request?: Omit<FetchRequestInit, 'method' | 'body'>): Promise<Response>;
|
|
100
123
|
/**
|
|
101
|
-
*
|
|
124
|
+
* Makes a POST HTTP request.
|
|
102
125
|
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
* @
|
|
126
|
+
* Convenience method for making POST requests, commonly used for creating resources.
|
|
127
|
+
*
|
|
128
|
+
* @param url - The URL path for the request
|
|
129
|
+
* @param request - Request options including body and other parameters
|
|
130
|
+
* @returns Promise that resolves to the HTTP response
|
|
106
131
|
*/
|
|
107
132
|
post(url: string, request?: Omit<FetchRequestInit, 'method'>): Promise<Response>;
|
|
108
133
|
/**
|
|
109
|
-
*
|
|
134
|
+
* Makes a PUT HTTP request.
|
|
135
|
+
*
|
|
136
|
+
* Convenience method for making PUT requests, commonly used for updating resources.
|
|
110
137
|
*
|
|
111
|
-
* @param url -
|
|
112
|
-
* @param request - Request options
|
|
113
|
-
* @returns Promise
|
|
138
|
+
* @param url - The URL path for the request
|
|
139
|
+
* @param request - Request options including body and other parameters
|
|
140
|
+
* @returns Promise that resolves to the HTTP response
|
|
114
141
|
*/
|
|
115
142
|
put(url: string, request?: Omit<FetchRequestInit, 'method'>): Promise<Response>;
|
|
116
143
|
/**
|
|
117
|
-
*
|
|
144
|
+
* Makes a DELETE HTTP request.
|
|
145
|
+
*
|
|
146
|
+
* Convenience method for making DELETE requests, commonly used for deleting resources.
|
|
118
147
|
*
|
|
119
|
-
* @param url -
|
|
120
|
-
* @param request - Request options
|
|
121
|
-
* @returns Promise
|
|
148
|
+
* @param url - The URL path for the request
|
|
149
|
+
* @param request - Request options excluding method and body
|
|
150
|
+
* @returns Promise that resolves to the HTTP response
|
|
122
151
|
*/
|
|
123
152
|
delete(url: string, request?: Omit<FetchRequestInit, 'method'>): Promise<Response>;
|
|
124
153
|
/**
|
|
125
|
-
*
|
|
154
|
+
* Makes a PATCH HTTP request.
|
|
126
155
|
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
* @
|
|
156
|
+
* Convenience method for making PATCH requests, commonly used for partial updates.
|
|
157
|
+
*
|
|
158
|
+
* @param url - The URL path for the request
|
|
159
|
+
* @param request - Request options including body and other parameters
|
|
160
|
+
* @returns Promise that resolves to the HTTP response
|
|
130
161
|
*/
|
|
131
162
|
patch(url: string, request?: Omit<FetchRequestInit, 'method'>): Promise<Response>;
|
|
132
163
|
/**
|
|
133
|
-
*
|
|
164
|
+
* Makes a HEAD HTTP request.
|
|
165
|
+
*
|
|
166
|
+
* Convenience method for making HEAD requests, which retrieve headers only.
|
|
167
|
+
* The request body is omitted as HEAD requests should not contain a body.
|
|
134
168
|
*
|
|
135
|
-
* @param url -
|
|
136
|
-
* @param request - Request options
|
|
137
|
-
* @returns Promise
|
|
169
|
+
* @param url - The URL path for the request
|
|
170
|
+
* @param request - Request options excluding method and body
|
|
171
|
+
* @returns Promise that resolves to the HTTP response
|
|
138
172
|
*/
|
|
139
173
|
head(url: string, request?: Omit<FetchRequestInit, 'method' | 'body'>): Promise<Response>;
|
|
140
174
|
/**
|
|
141
|
-
*
|
|
175
|
+
* Makes an OPTIONS HTTP request.
|
|
176
|
+
*
|
|
177
|
+
* Convenience method for making OPTIONS requests, commonly used for CORS preflight.
|
|
178
|
+
* The request body is omitted as OPTIONS requests typically don't contain a body.
|
|
142
179
|
*
|
|
143
|
-
* @param url -
|
|
144
|
-
* @param request - Request options
|
|
145
|
-
* @returns Promise
|
|
180
|
+
* @param url - The URL path for the request
|
|
181
|
+
* @param request - Request options excluding method and body
|
|
182
|
+
* @returns Promise that resolves to the HTTP response
|
|
146
183
|
*/
|
|
147
184
|
options(url: string, request?: Omit<FetchRequestInit, 'method' | 'body'>): Promise<Response>;
|
|
148
185
|
}
|
package/dist/fetcher.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetcher.d.ts","sourceRoot":"","sources":["../src/fetcher.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAkB,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EACL,cAAc,EAEd,YAAY,EACZ,gBAAgB,EAEhB,cAAc,EACd,qBAAqB,EACtB,MAAM,gBAAgB,CAAC;AAGxB
|
|
1
|
+
{"version":3,"file":"fetcher.d.ts","sourceRoot":"","sources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