@naturalcycles/js-lib 15.29.1 → 15.30.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.
@@ -34,10 +34,10 @@ export function _ms(millis) {
34
34
  // <1 sec
35
35
  if (millis < 1000)
36
36
  return `${Math.round(millis)} ms`;
37
- // < 5 sec
38
- if (millis < 5000) {
37
+ // < 10 sec
38
+ if (millis < 10_000) {
39
39
  const s = millis / 1000;
40
- return `${Math.trunc(s) === s ? s : s.toFixed(3)} sec`;
40
+ return `${s.toFixed(2)} sec`;
41
41
  }
42
42
  const sec = Math.floor(millis / 1000) % 60;
43
43
  const min = Math.floor(millis / (60 * 1000)) % 60;
@@ -624,6 +624,7 @@ export class Fetcher {
624
624
  }),
625
625
  credentials: cfg.credentials,
626
626
  redirect: cfg.redirect,
627
+ dispatcher: cfg.dispatcher,
627
628
  },
628
629
  hooks: {},
629
630
  throwHttpErrors: true,
@@ -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>, Omit<FetcherRequest, 'started' | 'fullUrl' | 'logRequest' | 'logRequestBody' | 'logResponse' | 'logResponseBody' | 'debug' | 'redirect' | 'credentials' | 'throwHttpErrors' | 'errorData'> {
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,9 +1,10 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
3
  "type": "module",
4
- "version": "15.29.1",
4
+ "version": "15.30.1",
5
5
  "dependencies": {
6
6
  "tslib": "^2",
7
+ "undici": "^7",
7
8
  "zod": "^4"
8
9
  },
9
10
  "devDependencies": {
@@ -41,10 +41,10 @@ export function _ms(millis: NumberOfMilliseconds): string {
41
41
  // <1 sec
42
42
  if (millis < 1000) return `${Math.round(millis)} ms`
43
43
 
44
- // < 5 sec
45
- if (millis < 5000) {
44
+ // < 10 sec
45
+ if (millis < 10_000) {
46
46
  const s = millis / 1000
47
- return `${Math.trunc(s) === s ? s : s.toFixed(3)} sec`
47
+ return `${s.toFixed(2)} sec`
48
48
  }
49
49
 
50
50
  const sec = Math.floor(millis / 1000) % 60
@@ -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> {
@@ -750,6 +750,7 @@ export class Fetcher {
750
750
  }),
751
751
  credentials: cfg.credentials,
752
752
  redirect: cfg.redirect,
753
+ dispatcher: cfg.dispatcher,
753
754
  },
754
755
  hooks: {},
755
756
  throwHttpErrors: true,