@ahoo-wang/fetcher 1.5.9 → 1.6.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/dist/fetcher.d.ts +42 -23
- package/dist/fetcher.d.ts.map +1 -1
- package/dist/index.es.js +246 -226
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
package/dist/fetcher.d.ts
CHANGED
|
@@ -60,21 +60,6 @@ export declare class Fetcher implements UrlBuilderCapable, RequestHeadersCapable
|
|
|
60
60
|
* @param options - Configuration options for the Fetcher instance
|
|
61
61
|
*/
|
|
62
62
|
constructor(options?: FetcherOptions);
|
|
63
|
-
/**
|
|
64
|
-
* Executes an HTTP request with the specified URL and options.
|
|
65
|
-
*
|
|
66
|
-
* This is the primary method for making HTTP requests. It processes the request
|
|
67
|
-
* through the interceptor chain and returns the resulting Response.
|
|
68
|
-
*
|
|
69
|
-
* @param url - The URL path for the request (relative to baseURL if set)
|
|
70
|
-
* @param request - Request configuration including headers, body, parameters, etc.
|
|
71
|
-
* @param attributes - Optional shared attributes that can be accessed by interceptors
|
|
72
|
-
* throughout the request lifecycle. These attributes allow passing
|
|
73
|
-
* custom data between different interceptors.
|
|
74
|
-
* @returns Promise that resolves to the HTTP response
|
|
75
|
-
* @throws FetchError if the request fails and no response is generated
|
|
76
|
-
*/
|
|
77
|
-
fetch(url: string, request?: FetchRequestInit, attributes?: Record<string, any>): Promise<Response>;
|
|
78
63
|
/**
|
|
79
64
|
* Processes an HTTP request through the Fetcher's internal workflow.
|
|
80
65
|
*
|
|
@@ -91,7 +76,25 @@ export declare class Fetcher implements UrlBuilderCapable, RequestHeadersCapable
|
|
|
91
76
|
* @returns Promise that resolves to the extracted result based on resultExtractor
|
|
92
77
|
* @throws Error if an unhandled error occurs during request processing
|
|
93
78
|
*/
|
|
94
|
-
request<R = FetchExchange>(request: FetchRequest, resultExtractor?: ResultExtractor<
|
|
79
|
+
request<R = FetchExchange>(request: FetchRequest, resultExtractor?: ResultExtractor<any>, attributes?: Record<string, any>): Promise<R>;
|
|
80
|
+
/**
|
|
81
|
+
* Executes an HTTP request with the specified URL and options.
|
|
82
|
+
*
|
|
83
|
+
* This is the primary method for making HTTP requests. It processes the request
|
|
84
|
+
* through the interceptor chain and returns the resulting Response.
|
|
85
|
+
*
|
|
86
|
+
* @param url - The URL path for the request (relative to baseURL if set)
|
|
87
|
+
* @param request - Request configuration including headers, body, parameters, etc.
|
|
88
|
+
* @param resultExtractor - Function to extract the desired result from the exchange.
|
|
89
|
+
* Defaults to ExchangeResultExtractor which returns the entire exchange object.
|
|
90
|
+
* @param attributes - Optional shared attributes that can be accessed by interceptors
|
|
91
|
+
* throughout the request lifecycle. These attributes allow passing
|
|
92
|
+
* custom data between different interceptors.
|
|
93
|
+
|
|
94
|
+
* @returns Promise that resolves to the HTTP response
|
|
95
|
+
* @throws FetchError if the request fails and no response is generated
|
|
96
|
+
*/
|
|
97
|
+
fetch<R = Response>(url: string, request?: FetchRequestInit, resultExtractor?: ResultExtractor<any>, attributes?: Record<string, any>): Promise<R>;
|
|
95
98
|
/**
|
|
96
99
|
* Internal helper method for making HTTP requests with a specific method.
|
|
97
100
|
*
|
|
@@ -101,6 +104,8 @@ export declare class Fetcher implements UrlBuilderCapable, RequestHeadersCapable
|
|
|
101
104
|
* @param method - The HTTP method to use for the request
|
|
102
105
|
* @param url - The URL path for the request
|
|
103
106
|
* @param request - Additional request options
|
|
107
|
+
* @param resultExtractor - Function to extract the desired result from the exchange.
|
|
108
|
+
* Defaults to ExchangeResultExtractor which returns the entire exchange object.
|
|
104
109
|
* @param attributes - Optional shared attributes that can be accessed by interceptors
|
|
105
110
|
* throughout the request lifecycle. These attributes allow passing
|
|
106
111
|
* custom data between different interceptors.
|
|
@@ -115,12 +120,14 @@ export declare class Fetcher implements UrlBuilderCapable, RequestHeadersCapable
|
|
|
115
120
|
*
|
|
116
121
|
* @param url - The URL path for the request
|
|
117
122
|
* @param request - Request options excluding method and body
|
|
123
|
+
* @param resultExtractor - Function to extract the desired result from the exchange.
|
|
124
|
+
* Defaults to ExchangeResultExtractor which returns the entire exchange object.
|
|
118
125
|
* @param attributes - Optional shared attributes that can be accessed by interceptors
|
|
119
126
|
* throughout the request lifecycle. These attributes allow passing
|
|
120
127
|
* custom data between different interceptors.
|
|
121
128
|
* @returns Promise that resolves to the HTTP response
|
|
122
129
|
*/
|
|
123
|
-
get(url: string, request?: Omit<FetchRequestInit, 'method' | 'body'>, attributes?: Record<string, any>): Promise<
|
|
130
|
+
get<R = Response>(url: string, request?: Omit<FetchRequestInit, 'method' | 'body'>, resultExtractor?: ResultExtractor<any>, attributes?: Record<string, any>): Promise<R>;
|
|
124
131
|
/**
|
|
125
132
|
* Makes a POST HTTP request.
|
|
126
133
|
*
|
|
@@ -128,12 +135,14 @@ export declare class Fetcher implements UrlBuilderCapable, RequestHeadersCapable
|
|
|
128
135
|
*
|
|
129
136
|
* @param url - The URL path for the request
|
|
130
137
|
* @param request - Request options including body and other parameters
|
|
138
|
+
* @param resultExtractor - Function to extract the desired result from the exchange.
|
|
139
|
+
* Defaults to ExchangeResultExtractor which returns the entire exchange object.
|
|
131
140
|
* @param attributes - Optional shared attributes that can be accessed by interceptors
|
|
132
141
|
* throughout the request lifecycle. These attributes allow passing
|
|
133
142
|
* custom data between different interceptors.
|
|
134
143
|
* @returns Promise that resolves to the HTTP response
|
|
135
144
|
*/
|
|
136
|
-
post(url: string, request?: Omit<FetchRequestInit, 'method'>, attributes?: Record<string, any>): Promise<
|
|
145
|
+
post<R = Response>(url: string, request?: Omit<FetchRequestInit, 'method'>, resultExtractor?: ResultExtractor<any>, attributes?: Record<string, any>): Promise<R>;
|
|
137
146
|
/**
|
|
138
147
|
* Makes a PUT HTTP request.
|
|
139
148
|
*
|
|
@@ -141,12 +150,14 @@ export declare class Fetcher implements UrlBuilderCapable, RequestHeadersCapable
|
|
|
141
150
|
*
|
|
142
151
|
* @param url - The URL path for the request
|
|
143
152
|
* @param request - Request options including body and other parameters
|
|
153
|
+
* @param resultExtractor - Function to extract the desired result from the exchange.
|
|
154
|
+
* Defaults to ExchangeResultExtractor which returns the entire exchange object.
|
|
144
155
|
* @param attributes - Optional shared attributes that can be accessed by interceptors
|
|
145
156
|
* throughout the request lifecycle. These attributes allow passing
|
|
146
157
|
* custom data between different interceptors.
|
|
147
158
|
* @returns Promise that resolves to the HTTP response
|
|
148
159
|
*/
|
|
149
|
-
put(url: string, request?: Omit<FetchRequestInit, 'method'>, attributes?: Record<string, any>): Promise<
|
|
160
|
+
put<R = Response>(url: string, request?: Omit<FetchRequestInit, 'method'>, resultExtractor?: ResultExtractor<any>, attributes?: Record<string, any>): Promise<R>;
|
|
150
161
|
/**
|
|
151
162
|
* Makes a DELETE HTTP request.
|
|
152
163
|
*
|
|
@@ -154,12 +165,14 @@ export declare class Fetcher implements UrlBuilderCapable, RequestHeadersCapable
|
|
|
154
165
|
*
|
|
155
166
|
* @param url - The URL path for the request
|
|
156
167
|
* @param request - Request options excluding method and body
|
|
168
|
+
* @param resultExtractor - Function to extract the desired result from the exchange.
|
|
169
|
+
* Defaults to ExchangeResultExtractor which returns the entire exchange object.
|
|
157
170
|
* @param attributes - Optional shared attributes that can be accessed by interceptors
|
|
158
171
|
* throughout the request lifecycle. These attributes allow passing
|
|
159
172
|
* custom data between different interceptors.
|
|
160
173
|
* @returns Promise that resolves to the HTTP response
|
|
161
174
|
*/
|
|
162
|
-
delete(url: string, request?: Omit<FetchRequestInit, 'method'>, attributes?: Record<string, any>): Promise<
|
|
175
|
+
delete<R = Response>(url: string, request?: Omit<FetchRequestInit, 'method'>, resultExtractor?: ResultExtractor<any>, attributes?: Record<string, any>): Promise<R>;
|
|
163
176
|
/**
|
|
164
177
|
* Makes a PATCH HTTP request.
|
|
165
178
|
*
|
|
@@ -167,12 +180,14 @@ export declare class Fetcher implements UrlBuilderCapable, RequestHeadersCapable
|
|
|
167
180
|
*
|
|
168
181
|
* @param url - The URL path for the request
|
|
169
182
|
* @param request - Request options including body and other parameters
|
|
183
|
+
* @param resultExtractor - Function to extract the desired result from the exchange.
|
|
184
|
+
* Defaults to ExchangeResultExtractor which returns the entire exchange object.
|
|
170
185
|
* @param attributes - Optional shared attributes that can be accessed by interceptors
|
|
171
186
|
* throughout the request lifecycle. These attributes allow passing
|
|
172
187
|
* custom data between different interceptors.
|
|
173
188
|
* @returns Promise that resolves to the HTTP response
|
|
174
189
|
*/
|
|
175
|
-
patch(url: string, request?: Omit<FetchRequestInit, 'method'>, attributes?: Record<string, any>): Promise<
|
|
190
|
+
patch<R = Response>(url: string, request?: Omit<FetchRequestInit, 'method'>, resultExtractor?: ResultExtractor<any>, attributes?: Record<string, any>): Promise<R>;
|
|
176
191
|
/**
|
|
177
192
|
* Makes a HEAD HTTP request.
|
|
178
193
|
*
|
|
@@ -181,12 +196,14 @@ export declare class Fetcher implements UrlBuilderCapable, RequestHeadersCapable
|
|
|
181
196
|
*
|
|
182
197
|
* @param url - The URL path for the request
|
|
183
198
|
* @param request - Request options excluding method and body
|
|
199
|
+
* @param resultExtractor - Function to extract the desired result from the exchange.
|
|
200
|
+
* Defaults to ExchangeResultExtractor which returns the entire exchange object.
|
|
184
201
|
* @param attributes - Optional shared attributes that can be accessed by interceptors
|
|
185
202
|
* throughout the request lifecycle. These attributes allow passing
|
|
186
203
|
* custom data between different interceptors.
|
|
187
204
|
* @returns Promise that resolves to the HTTP response
|
|
188
205
|
*/
|
|
189
|
-
head(url: string, request?: Omit<FetchRequestInit, 'method' | 'body'>, attributes?: Record<string, any>): Promise<
|
|
206
|
+
head<R = Response>(url: string, request?: Omit<FetchRequestInit, 'method' | 'body'>, resultExtractor?: ResultExtractor<any>, attributes?: Record<string, any>): Promise<R>;
|
|
190
207
|
/**
|
|
191
208
|
* Makes an OPTIONS HTTP request.
|
|
192
209
|
*
|
|
@@ -195,11 +212,13 @@ export declare class Fetcher implements UrlBuilderCapable, RequestHeadersCapable
|
|
|
195
212
|
*
|
|
196
213
|
* @param url - The URL path for the request
|
|
197
214
|
* @param request - Request options excluding method and body
|
|
215
|
+
* @param resultExtractor - Function to extract the desired result from the exchange.
|
|
216
|
+
* Defaults to ExchangeResultExtractor which returns the entire exchange object.
|
|
198
217
|
* @param attributes - Optional shared attributes that can be accessed by interceptors
|
|
199
218
|
* throughout the request lifecycle. These attributes allow passing
|
|
200
219
|
* custom data between different interceptors.
|
|
201
220
|
* @returns Promise that resolves to the HTTP response
|
|
202
221
|
*/
|
|
203
|
-
options(url: string, request?: Omit<FetchRequestInit, 'method' | 'body'>, attributes?: Record<string, any>): Promise<
|
|
222
|
+
options<R = Response>(url: string, request?: Omit<FetchRequestInit, 'method' | 'body'>, resultExtractor?: ResultExtractor<any>, attributes?: Record<string, any>): Promise<R>;
|
|
204
223
|
}
|
|
205
224
|
//# sourceMappingURL=fetcher.d.ts.map
|
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,KAAK,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAClE,OAAO,EAAkB,KAAK,cAAc,EAAE,MAAM,WAAW,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,KAAK,EACV,cAAc,EACd,YAAY,EACZ,gBAAgB,EAChB,cAAc,EACd,qBAAqB,EACtB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,eAAe,EAAoB,MAAM,mBAAmB,CAAC;AAEtE;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,WAAW,cACf,SAAQ,cAAc,EACpB,qBAAqB,EACrB,cAAc;IAChB,gBAAg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