@naturalcycles/js-lib 15.29.1 → 15.30.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/http/fetcher.js +1 -0
- package/dist/http/fetcher.model.d.ts +18 -1
- package/package.json +2 -1
- package/src/http/fetcher.model.ts +19 -1
- package/src/http/fetcher.ts +1 -0
package/dist/http/fetcher.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/// <reference lib="es2022" preserve="true" />
|
|
2
2
|
/// <reference lib="dom" preserve="true" />
|
|
3
|
+
import type { Dispatcher } from 'undici';
|
|
3
4
|
import type { ErrorData } from '../error/error.model.js';
|
|
4
5
|
import type { CommonLogger } from '../log/commonLogger.js';
|
|
5
6
|
import type { AnyObject, NumberOfMilliseconds, Promisable, Reviver, UnixTimestampMillis } from '../types.js';
|
|
6
7
|
import type { HttpMethod, HttpStatusFamily } from './http.model.js';
|
|
7
|
-
export interface FetcherNormalizedCfg extends Required<FetcherCfg
|
|
8
|
+
export interface FetcherNormalizedCfg extends Required<Omit<FetcherCfg, 'dispatcher'>>, Omit<FetcherRequest, 'started' | 'fullUrl' | 'logRequest' | 'logRequestBody' | 'logResponse' | 'logResponseBody' | 'debug' | 'redirect' | 'credentials' | 'throwHttpErrors' | 'errorData'> {
|
|
8
9
|
logger: CommonLogger;
|
|
9
10
|
searchParams: Record<string, any>;
|
|
10
11
|
}
|
|
@@ -16,6 +17,10 @@ export type FetcherBeforeRetryHook = <BODY = unknown>(res: FetcherResponse<BODY>
|
|
|
16
17
|
* Cannot cancel/prevent the error - AfterResponseHook can be used for that instead.
|
|
17
18
|
*/
|
|
18
19
|
export type FetcherOnErrorHook = (err: Error) => Promisable<void>;
|
|
20
|
+
/**
|
|
21
|
+
* FetcherCfg: configuration of the Fetcher instance. One per instance.
|
|
22
|
+
* FetcherOptions: options for a single request. One per request.
|
|
23
|
+
*/
|
|
19
24
|
export interface FetcherCfg {
|
|
20
25
|
/**
|
|
21
26
|
* Should **not** contain trailing slash.
|
|
@@ -83,6 +88,13 @@ export interface FetcherCfg {
|
|
|
83
88
|
*/
|
|
84
89
|
logger?: CommonLogger;
|
|
85
90
|
throwHttpErrors?: boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Pass an Undici Dispatcher.
|
|
93
|
+
* (Node.js only)
|
|
94
|
+
*
|
|
95
|
+
* @experimental
|
|
96
|
+
*/
|
|
97
|
+
dispatcher?: Dispatcher;
|
|
86
98
|
}
|
|
87
99
|
export interface FetcherRetryStatus {
|
|
88
100
|
retryAttempt: number;
|
|
@@ -131,6 +143,10 @@ export interface FetcherGraphQLOptions extends FetcherOptions {
|
|
|
131
143
|
*/
|
|
132
144
|
unwrapObject?: string;
|
|
133
145
|
}
|
|
146
|
+
/**
|
|
147
|
+
* FetcherCfg: configuration of the Fetcher instance. One per instance.
|
|
148
|
+
* FetcherOptions: options for a single request. One per request.
|
|
149
|
+
*/
|
|
134
150
|
export interface FetcherOptions {
|
|
135
151
|
method?: HttpMethod;
|
|
136
152
|
/**
|
|
@@ -237,6 +253,7 @@ export interface FetcherOptions {
|
|
|
237
253
|
export type RequestInitNormalized = Omit<RequestInit, 'method' | 'headers'> & {
|
|
238
254
|
method: HttpMethod;
|
|
239
255
|
headers: Record<string, any>;
|
|
256
|
+
dispatcher?: Dispatcher;
|
|
240
257
|
};
|
|
241
258
|
export interface FetcherSuccessResponse<BODY = unknown> {
|
|
242
259
|
ok: true;
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference lib="es2022" preserve="true" />
|
|
2
2
|
/// <reference lib="dom" preserve="true" />
|
|
3
3
|
|
|
4
|
+
import type { Dispatcher } from 'undici'
|
|
4
5
|
import type { ErrorData } from '../error/error.model.js'
|
|
5
6
|
import type { CommonLogger } from '../log/commonLogger.js'
|
|
6
7
|
import type {
|
|
@@ -13,7 +14,7 @@ import type {
|
|
|
13
14
|
import type { HttpMethod, HttpStatusFamily } from './http.model.js'
|
|
14
15
|
|
|
15
16
|
export interface FetcherNormalizedCfg
|
|
16
|
-
extends Required<FetcherCfg
|
|
17
|
+
extends Required<Omit<FetcherCfg, 'dispatcher'>>,
|
|
17
18
|
Omit<
|
|
18
19
|
FetcherRequest,
|
|
19
20
|
| 'started'
|
|
@@ -45,6 +46,10 @@ export type FetcherBeforeRetryHook = <BODY = unknown>(
|
|
|
45
46
|
*/
|
|
46
47
|
export type FetcherOnErrorHook = (err: Error) => Promisable<void>
|
|
47
48
|
|
|
49
|
+
/**
|
|
50
|
+
* FetcherCfg: configuration of the Fetcher instance. One per instance.
|
|
51
|
+
* FetcherOptions: options for a single request. One per request.
|
|
52
|
+
*/
|
|
48
53
|
export interface FetcherCfg {
|
|
49
54
|
/**
|
|
50
55
|
* Should **not** contain trailing slash.
|
|
@@ -120,6 +125,14 @@ export interface FetcherCfg {
|
|
|
120
125
|
logger?: CommonLogger
|
|
121
126
|
|
|
122
127
|
throwHttpErrors?: boolean
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Pass an Undici Dispatcher.
|
|
131
|
+
* (Node.js only)
|
|
132
|
+
*
|
|
133
|
+
* @experimental
|
|
134
|
+
*/
|
|
135
|
+
dispatcher?: Dispatcher
|
|
123
136
|
}
|
|
124
137
|
|
|
125
138
|
export interface FetcherRetryStatus {
|
|
@@ -174,6 +187,10 @@ export interface FetcherGraphQLOptions extends FetcherOptions {
|
|
|
174
187
|
unwrapObject?: string
|
|
175
188
|
}
|
|
176
189
|
|
|
190
|
+
/**
|
|
191
|
+
* FetcherCfg: configuration of the Fetcher instance. One per instance.
|
|
192
|
+
* FetcherOptions: options for a single request. One per request.
|
|
193
|
+
*/
|
|
177
194
|
export interface FetcherOptions {
|
|
178
195
|
method?: HttpMethod
|
|
179
196
|
|
|
@@ -303,6 +320,7 @@ export interface FetcherOptions {
|
|
|
303
320
|
export type RequestInitNormalized = Omit<RequestInit, 'method' | 'headers'> & {
|
|
304
321
|
method: HttpMethod
|
|
305
322
|
headers: Record<string, any>
|
|
323
|
+
dispatcher?: Dispatcher
|
|
306
324
|
}
|
|
307
325
|
|
|
308
326
|
export interface FetcherSuccessResponse<BODY = unknown> {
|