@equinor/fusion-framework-module-http 6.2.1 → 6.2.3
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 +350 -310
- package/dist/esm/configurator.js +2 -2
- package/dist/esm/configurator.js.map +1 -1
- package/dist/esm/errors.js.map +1 -1
- package/dist/esm/lib/client/client-msal.js.map +1 -1
- package/dist/esm/lib/client/client.js.map +1 -1
- package/dist/esm/lib/operators/capitalize-request-method.operator.js +3 -1
- package/dist/esm/lib/operators/capitalize-request-method.operator.js.map +1 -1
- package/dist/esm/lib/operators/fetch-request.schema.js.map +1 -1
- package/dist/esm/lib/operators/http-request-handler.js.map +1 -1
- package/dist/esm/lib/operators/process-operators.js.map +1 -1
- package/dist/esm/lib/operators/request-operator-header.js.map +1 -1
- package/dist/esm/lib/operators/request-validation.operator.js.map +1 -1
- package/dist/esm/lib/selectors/blob-selector.js.map +1 -1
- package/dist/esm/lib/selectors/json-selector.js.map +1 -1
- package/dist/esm/module.js +1 -1
- package/dist/esm/module.js.map +1 -1
- package/dist/esm/provider.js +9 -4
- package/dist/esm/provider.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/lib/operators/process-operators.d.ts +1 -1
- package/dist/types/module.d.ts +3 -3
- package/dist/types/provider.d.ts +10 -3
- package/dist/types/version.d.ts +1 -1
- package/package.json +4 -4
- package/src/configurator.ts +115 -116
- package/src/errors.ts +24 -24
- package/src/lib/client/client-msal.ts +34 -34
- package/src/lib/client/client.ts +298 -298
- package/src/lib/client/types.ts +147 -145
- package/src/lib/operators/capitalize-request-method.operator.ts +11 -9
- package/src/lib/operators/fetch-request.schema.ts +70 -73
- package/src/lib/operators/http-request-handler.ts +11 -11
- package/src/lib/operators/process-operators.ts +88 -88
- package/src/lib/operators/request-operator-header.ts +6 -6
- package/src/lib/operators/request-validation.operator.ts +32 -32
- package/src/lib/operators/types.ts +44 -44
- package/src/lib/selectors/blob-selector.ts +24 -24
- package/src/lib/selectors/json-selector.ts +25 -25
- package/src/module.ts +73 -69
- package/src/provider.ts +141 -139
- package/src/version.ts +1 -1
- package/tests/HttpClient.test.ts +37 -37
- package/tests/operators.test.ts +67 -67
- package/vitest.config.ts +6 -6
package/src/lib/client/client.ts
CHANGED
|
@@ -8,13 +8,13 @@ import { blobSelector, jsonSelector } from '../selectors';
|
|
|
8
8
|
import type { Observable, ObservableInput } from 'rxjs';
|
|
9
9
|
import type { IHttpRequestHandler, IHttpResponseHandler } from '../operators';
|
|
10
10
|
import type {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
BlobResult,
|
|
12
|
+
FetchRequest,
|
|
13
|
+
FetchRequestInit,
|
|
14
|
+
FetchResponse,
|
|
15
|
+
IHttpClient,
|
|
16
|
+
JsonRequest,
|
|
17
|
+
StreamResponse,
|
|
18
18
|
} from './types';
|
|
19
19
|
|
|
20
20
|
import { HttpResponseError } from '../../errors';
|
|
@@ -28,327 +28,327 @@ import { HttpResponseError } from '../../errors';
|
|
|
28
28
|
* @property {IHttpResponseHandler<TResponse>} responseHandler - A handler for customizing the response after it is received.
|
|
29
29
|
*/
|
|
30
30
|
export type HttpClientCreateOptions<
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
TRequest extends FetchRequest = FetchRequest,
|
|
32
|
+
TResponse = Response,
|
|
33
33
|
> = {
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
requestHandler: IHttpRequestHandler<TRequest>;
|
|
35
|
+
responseHandler: IHttpResponseHandler<TResponse>;
|
|
36
36
|
};
|
|
37
37
|
|
|
38
38
|
/** Base http client for executing requests */
|
|
39
39
|
export class HttpClient<
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
TRequest extends FetchRequest = FetchRequest,
|
|
41
|
+
TResponse extends FetchResponse = FetchResponse,
|
|
42
42
|
> implements IHttpClient<TRequest, TResponse>
|
|
43
43
|
{
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
/**
|
|
45
|
+
* A request handler that can be used to customize the request before it is sent.
|
|
46
|
+
* This property is part of the `HttpClientCreateOptions` configuration object used to create an `HttpClient` instance.
|
|
47
|
+
*/
|
|
48
|
+
public readonly requestHandler: IHttpRequestHandler<TRequest>;
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
/**
|
|
51
|
+
* A handler for customizing the response after it is received.
|
|
52
|
+
* This property is part of the `HttpClientCreateOptions` configuration object used to create an `HttpClient` instance.
|
|
53
|
+
*/
|
|
54
|
+
public readonly responseHandler: IHttpResponseHandler<TResponse>;
|
|
55
55
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
56
|
+
/**
|
|
57
|
+
* A stream of requests that are about to be executed.
|
|
58
|
+
* This property is used internally by the `HttpClient` class to manage the lifecycle of requests.
|
|
59
|
+
*/
|
|
60
|
+
protected _request$ = new Subject<TRequest>();
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
62
|
+
/**
|
|
63
|
+
* A stream of responses that have been received.
|
|
64
|
+
* This property is used internally by the `HttpClient` class to manage the lifecycle of responses.
|
|
65
|
+
*/
|
|
66
|
+
protected _response$ = new Subject<TResponse>();
|
|
67
67
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
68
|
+
/**
|
|
69
|
+
* A stream that is used to signal the abortion of requests.
|
|
70
|
+
* This property is used internally by the `HttpClient` class to manage the lifecycle of requests.
|
|
71
|
+
*/
|
|
72
|
+
protected _abort$ = new Subject<void>();
|
|
73
73
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
74
|
+
/**
|
|
75
|
+
* A stream of requests that are about to be executed.
|
|
76
|
+
*/
|
|
77
|
+
public get request$(): Observable<TRequest> {
|
|
78
|
+
return this._request$.asObservable();
|
|
79
|
+
}
|
|
80
80
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
81
|
+
/**
|
|
82
|
+
* A stream of responses that have been received.
|
|
83
|
+
*/
|
|
84
|
+
public get response$(): Observable<TResponse> {
|
|
85
|
+
return this._response$.asObservable();
|
|
86
|
+
}
|
|
87
87
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
88
|
+
constructor(
|
|
89
|
+
public uri: string,
|
|
90
|
+
options?: Partial<HttpClientCreateOptions<TRequest, TResponse>>,
|
|
91
|
+
) {
|
|
92
|
+
this.requestHandler = new HttpRequestHandler<TRequest>(options?.requestHandler);
|
|
93
|
+
this.responseHandler = new HttpResponseHandler<TResponse>(options?.responseHandler);
|
|
94
|
+
this._init();
|
|
95
|
+
}
|
|
96
96
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
97
|
+
/**
|
|
98
|
+
* Internal method called by child classes to perform initialization logic in the constructor.
|
|
99
|
+
* This method is intended to be overridden by child classes to add their own initialization logic.
|
|
100
|
+
* @protected
|
|
101
|
+
* @virtual
|
|
102
|
+
*/
|
|
103
|
+
protected _init(): void {
|
|
104
|
+
// called by children for constructor setup
|
|
105
|
+
}
|
|
106
106
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
107
|
+
/**
|
|
108
|
+
* Fetches data from the specified path and returns a stream response.
|
|
109
|
+
*
|
|
110
|
+
* @param path - The path to fetch data from.
|
|
111
|
+
* @param args - Optional request initialization options, including a custom selector function.
|
|
112
|
+
* @returns A stream response containing the fetched data.
|
|
113
|
+
*/
|
|
114
|
+
public fetch$<T = TResponse>(
|
|
115
|
+
path: string,
|
|
116
|
+
args?: FetchRequestInit<T, TRequest, TResponse>,
|
|
117
|
+
): StreamResponse<T> {
|
|
118
|
+
return this._fetch$(path, args);
|
|
119
|
+
}
|
|
120
120
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
121
|
+
/**
|
|
122
|
+
* Fetches data from the specified path and returns a Promise containing the fetched data.
|
|
123
|
+
*
|
|
124
|
+
* @param path - The path to fetch data from.
|
|
125
|
+
* @param args - Optional request initialization options, including a custom selector function.
|
|
126
|
+
* @returns A Promise containing the fetched data.
|
|
127
|
+
*/
|
|
128
|
+
public fetch<T = TResponse>(
|
|
129
|
+
path: string,
|
|
130
|
+
args?: FetchRequestInit<T, TRequest, TResponse>,
|
|
131
|
+
): Promise<T> {
|
|
132
|
+
return firstValueFrom(this.fetch$<T>(path, args));
|
|
133
|
+
}
|
|
134
134
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
135
|
+
/** @deprecated */
|
|
136
|
+
public fetchAsync<T = TResponse>(
|
|
137
|
+
path: string,
|
|
138
|
+
args?: FetchRequestInit<T, TRequest, TResponse>,
|
|
139
|
+
): Promise<T> {
|
|
140
|
+
return this.fetch(path, args);
|
|
141
|
+
}
|
|
142
142
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
143
|
+
/**
|
|
144
|
+
* Fetches data from the specified path and returns a stream response containing the data in JSON format.
|
|
145
|
+
*
|
|
146
|
+
* @param path - The path to fetch the data from.
|
|
147
|
+
* @param args - Optional request initialization options, including a custom selector function and request body.
|
|
148
|
+
* - `body`: The request body, which will be automatically serialized to JSON if it's an object.
|
|
149
|
+
* - `selector`: A custom selector function to transform the response data. If not provided, the `jsonSelector` function will be used.
|
|
150
|
+
* - `headers`: Additional headers to include in the request. The `Accept` and `Content-Type` headers will be automatically set to `application/json`.
|
|
151
|
+
* @returns A stream response containing the fetched data in JSON format.
|
|
152
|
+
*/
|
|
153
|
+
public json$<T = unknown>(
|
|
154
|
+
path: string,
|
|
155
|
+
args?: FetchRequestInit<T, JsonRequest<TRequest>, TResponse>,
|
|
156
|
+
): StreamResponse<T> {
|
|
157
|
+
const body = typeof args?.body === 'object' ? JSON.stringify(args?.body) : args?.body;
|
|
158
|
+
const selector = args?.selector ?? jsonSelector;
|
|
159
|
+
const headers = new Headers(args?.headers);
|
|
160
|
+
headers.append('Accept', 'application/json');
|
|
161
|
+
headers.append('Content-Type', 'application/json');
|
|
162
|
+
return this.fetch$(path, {
|
|
163
|
+
...args,
|
|
164
|
+
body,
|
|
165
|
+
selector,
|
|
166
|
+
headers,
|
|
167
|
+
} as FetchRequestInit<T, TRequest, TResponse>);
|
|
168
|
+
}
|
|
169
169
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
170
|
+
/**
|
|
171
|
+
* Fetches data from the specified path and returns a Promise containing the fetched data in JSON format.
|
|
172
|
+
*
|
|
173
|
+
* @param path - The path to fetch the data from.
|
|
174
|
+
* @param args - Optional request initialization options, including a custom selector function and request body.
|
|
175
|
+
* - `body`: The request body, which will be automatically serialized to JSON if it's an object.
|
|
176
|
+
* - `selector`: A custom selector function to transform the response data. If not provided, the `jsonSelector` function will be used.
|
|
177
|
+
* - `headers`: Additional headers to include in the request. The `Accept` and `Content-Type` headers will be automatically set to `application/json`.
|
|
178
|
+
* @returns A Promise containing the fetched data in JSON format.
|
|
179
|
+
*/
|
|
180
|
+
public json<T = unknown>(
|
|
181
|
+
path: string,
|
|
182
|
+
args?: FetchRequestInit<T, JsonRequest<TRequest>, TResponse>,
|
|
183
|
+
): Promise<T> {
|
|
184
|
+
return firstValueFrom(this.json$<T>(path, args));
|
|
185
|
+
}
|
|
186
186
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
187
|
+
/**
|
|
188
|
+
* Fetches a blob resource from the specified path and returns a stream response.
|
|
189
|
+
*
|
|
190
|
+
* @param path - The path to the blob resource.
|
|
191
|
+
* @param args - Optional request initialization options, including a custom selector function.
|
|
192
|
+
* @returns A stream response containing the fetched blob data.
|
|
193
|
+
*/
|
|
194
|
+
public blob$<T = BlobResult>(
|
|
195
|
+
path: string,
|
|
196
|
+
args?: FetchRequestInit<T, TRequest, TResponse>,
|
|
197
|
+
): StreamResponse<T> {
|
|
198
|
+
// Get the selector value from the provided args, or use the default blobSelector
|
|
199
|
+
const selector = args?.selector ?? blobSelector;
|
|
200
200
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
201
|
+
// Create the FetchRequestInit object with the provided args and the selector
|
|
202
|
+
const init = {
|
|
203
|
+
...args,
|
|
204
|
+
selector,
|
|
205
|
+
} as FetchRequestInit<T, TRequest, TResponse>;
|
|
206
206
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
207
|
+
// Call the fetch$ method with the provided path and the constructed init object
|
|
208
|
+
return this.fetch$(path, init);
|
|
209
|
+
}
|
|
210
210
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
211
|
+
/**
|
|
212
|
+
* Fetches a blob from the specified path and returns a Promise that resolves to the blob result.
|
|
213
|
+
*
|
|
214
|
+
* @param path - The path to fetch the blob from.
|
|
215
|
+
* @param args - Optional arguments for the fetch request, including request body, headers, and response type.
|
|
216
|
+
* @returns A Promise that resolves to the blob result.
|
|
217
|
+
*/
|
|
218
|
+
public blob<T = BlobResult>(
|
|
219
|
+
path: string,
|
|
220
|
+
args?: FetchRequestInit<T, TRequest, TResponse>,
|
|
221
|
+
): Promise<T> {
|
|
222
|
+
return firstValueFrom(this.blob$(path, args));
|
|
223
|
+
}
|
|
224
224
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
225
|
+
/** @deprecated */
|
|
226
|
+
public jsonAsync<T = unknown>(
|
|
227
|
+
path: string,
|
|
228
|
+
args?: FetchRequestInit<T, JsonRequest<TRequest>, TResponse>,
|
|
229
|
+
): Promise<T> {
|
|
230
|
+
return this.json(path, args);
|
|
231
|
+
}
|
|
232
232
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
233
|
+
/**
|
|
234
|
+
* Executes an HTTP request using the specified method and path.
|
|
235
|
+
*
|
|
236
|
+
* @param method - The HTTP method to use for the request, such as 'fetch', 'json', or 'blob'.
|
|
237
|
+
* @param path - The path to the resource to fetch.
|
|
238
|
+
* @param init - Optional request initialization options, including request body, headers, and response type.
|
|
239
|
+
* @returns The result of the HTTP request, which will be of the same type as the return value of the specified method.
|
|
240
|
+
*/
|
|
241
|
+
public execute<T = TResponse, TMethod extends 'fetch' | 'fetch$' | 'json' | 'json$' = 'fetch'>(
|
|
242
|
+
method: TMethod,
|
|
243
|
+
path: string,
|
|
244
|
+
init?: FetchRequestInit<T, TRequest, TResponse>,
|
|
245
|
+
): ReturnType<IHttpClient[TMethod]> {
|
|
246
|
+
return this[method](path, init) as ReturnType<IHttpClient[TMethod]>;
|
|
247
|
+
}
|
|
248
248
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
249
|
+
/**
|
|
250
|
+
* Aborts any ongoing HTTP requests made by this `IHttpClient` instance.
|
|
251
|
+
* This will trigger the `takeUntil` operator in the `_fetch$` method,
|
|
252
|
+
* causing any in-flight requests to be cancelled.
|
|
253
|
+
*/
|
|
254
|
+
public abort(): void {
|
|
255
|
+
this._abort$.next();
|
|
256
|
+
}
|
|
257
257
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
258
|
+
/**
|
|
259
|
+
* Fetches data from the specified path and returns an Observable that emits the response.
|
|
260
|
+
*
|
|
261
|
+
* @param path - The path to fetch the data from.
|
|
262
|
+
* @param args - Optional arguments for the fetch request, including a response selector function, request body, headers, and response type.
|
|
263
|
+
* @returns {Observable<T>} An Observable that emits the response data.
|
|
264
|
+
*
|
|
265
|
+
* This method handles the following steps:
|
|
266
|
+
* 1. Resolves the full URL by combining the base URI and the provided path.
|
|
267
|
+
* 2. Prepares the request by passing it through the `requestHandler.process()` method.
|
|
268
|
+
* 3. Executes the fetch request using the prepared request.
|
|
269
|
+
* 4. Prepares the response by passing it through the `responseHandler.process()` method.
|
|
270
|
+
* 5. Applies the optional response selector function to transform the response data.
|
|
271
|
+
* 6. Cancels the request if the `_abort$` observable emits.
|
|
272
|
+
*/
|
|
273
|
+
protected _fetch$<T = TResponse>(
|
|
274
|
+
path: string,
|
|
275
|
+
args?: FetchRequestInit<T, TRequest, TResponse>,
|
|
276
|
+
): Observable<T> {
|
|
277
|
+
const { selector, ...options } = args || {};
|
|
278
|
+
const response$ = of({
|
|
279
|
+
...options,
|
|
280
|
+
uri: this._resolveUrl(path),
|
|
281
|
+
} as TRequest).pipe(
|
|
282
|
+
/** prepare request, allow extensions to modify request */
|
|
283
|
+
switchMap((x) => this._prepareRequest(x)),
|
|
284
|
+
/** push request to event buss */
|
|
285
|
+
tap((x) => this._request$.next(x)),
|
|
286
|
+
/** execute request */
|
|
287
|
+
switchMap(({ uri, path: _path, ...init }) => fromFetch(uri, init)),
|
|
288
|
+
/** prepare response, allow extensions to modify response */
|
|
289
|
+
switchMap((x) => this._prepareResponse(x as unknown as TResponse)),
|
|
290
|
+
/** push response to event buss */
|
|
291
|
+
tap((x) => this._response$.next(x)),
|
|
292
292
|
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
293
|
+
/** execute selector */
|
|
294
|
+
switchMap((response) => {
|
|
295
|
+
if (selector) {
|
|
296
|
+
try {
|
|
297
|
+
return selector(response);
|
|
298
|
+
} catch (err) {
|
|
299
|
+
throw new HttpResponseError(
|
|
300
|
+
'failed to execute response selector',
|
|
301
|
+
response as Response,
|
|
302
|
+
{
|
|
303
|
+
cause: err,
|
|
304
|
+
},
|
|
305
|
+
);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
return of(response);
|
|
309
|
+
}),
|
|
310
|
+
/** cancel request on abort signal */
|
|
311
|
+
takeUntil(this._abort$),
|
|
312
|
+
);
|
|
313
|
+
return response$ as unknown as Observable<T>;
|
|
314
|
+
}
|
|
315
315
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
316
|
+
/**
|
|
317
|
+
* Prepares the request by passing it through the `requestHandler.process()` method.
|
|
318
|
+
* This method is an implementation detail of the `_fetch$()` method, and is not part of the public API.
|
|
319
|
+
* It takes a `TRequest` object as input, which represents the request data, and returns an `ObservableInput<TRequest>`,
|
|
320
|
+
* which can be used to further process the request before it is executed.
|
|
321
|
+
*
|
|
322
|
+
* @param init The request data to be processed.
|
|
323
|
+
* @returns An `ObservableInput<TRequest>` that represents the processed request.
|
|
324
|
+
*/
|
|
325
|
+
protected _prepareRequest(init: TRequest): ObservableInput<TRequest> {
|
|
326
|
+
return this.requestHandler.process(init);
|
|
327
|
+
}
|
|
328
328
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
329
|
+
/**
|
|
330
|
+
* Prepares the response by passing it through the `responseHandler.process()` method.
|
|
331
|
+
* This method is an implementation detail of the `_fetch$()` method, and is not part of the public API.
|
|
332
|
+
* It takes a `TResponse` object as input, which represents the response data, and returns an `ObservableInput<TResponse>`,
|
|
333
|
+
* which can be used to further process the response before it is returned.
|
|
334
|
+
*
|
|
335
|
+
* @param response The response data to be processed.
|
|
336
|
+
* @returns An `ObservableInput<TResponse>` that represents the processed response.
|
|
337
|
+
*/
|
|
338
|
+
protected _prepareResponse(response: TResponse): ObservableInput<TResponse> {
|
|
339
|
+
return this.responseHandler.process(response);
|
|
340
|
+
}
|
|
341
341
|
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
342
|
+
/**
|
|
343
|
+
* Resolves the full URL for a given path by combining it with the base URL.
|
|
344
|
+
* This is a protected method and is an implementation detail of the `HttpClient` class.
|
|
345
|
+
*
|
|
346
|
+
* @param path - The path to be resolved.
|
|
347
|
+
* @returns The full URL for the given path.
|
|
348
|
+
*/
|
|
349
|
+
protected _resolveUrl(path: string): string {
|
|
350
|
+
const { origin, pathname: basePath } = new URL(this.uri || window.location.origin);
|
|
351
|
+
const pathname = [basePath, path].join('/').replace(/\/{2,}/g, '/');
|
|
352
|
+
return new URL(pathname, origin).href;
|
|
353
|
+
}
|
|
354
354
|
}
|