@naturalcycles/js-lib 14.139.0 → 14.139.2

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.
@@ -3,8 +3,6 @@ import type { FetcherAfterResponseHook, FetcherBeforeRequestHook, FetcherBeforeR
3
3
  /**
4
4
  * Experimental wrapper around Fetch.
5
5
  * Works in both Browser and Node, using `globalThis.fetch`.
6
- *
7
- * @experimental
8
6
  */
9
7
  export declare class Fetcher {
10
8
  private constructor();
@@ -20,8 +20,6 @@ const defRetryOptions = {
20
20
  /**
21
21
  * Experimental wrapper around Fetch.
22
22
  * Works in both Browser and Node, using `globalThis.fetch`.
23
- *
24
- * @experimental
25
23
  */
26
24
  class Fetcher {
27
25
  constructor(cfg = {}) {
@@ -121,7 +119,6 @@ class Fetcher {
121
119
  },
122
120
  signature,
123
121
  };
124
- /* eslint-disable no-await-in-loop */
125
122
  while (!res.retryStatus.retryStopped) {
126
123
  const started = Date.now();
127
124
  if (this.cfg.logRequest) {
@@ -141,6 +138,8 @@ class Fetcher {
141
138
  // For example, CORS error would result in "TypeError: failed to fetch" here
142
139
  res.err = err;
143
140
  res.ok = false;
141
+ // important to set it to undefined, otherwise it can keep the previous value (from previous try)
142
+ res.fetchResponse = undefined;
144
143
  }
145
144
  res.statusFamily = this.getStatusFamily(res);
146
145
  if (res.fetchResponse?.ok) {
@@ -340,7 +339,8 @@ class Fetcher {
340
339
  retryPost: false,
341
340
  retry4xx: false,
342
341
  retry5xx: true,
343
- logger: console,
342
+ // logger: console, Danger! doing this mutates console!
343
+ logger: cfg.logger || console,
344
344
  debug,
345
345
  logRequest: debug,
346
346
  logRequestBody: debug,
@@ -355,7 +355,7 @@ class Fetcher {
355
355
  credentials: cfg.credentials,
356
356
  },
357
357
  hooks: {},
358
- }, (0, object_util_1._omit)(cfg, ['method', 'credentials', 'headers']));
358
+ }, (0, object_util_1._omit)(cfg, ['method', 'credentials', 'headers', 'logger']));
359
359
  norm.init.headers = (0, object_util_1._mapKeys)(norm.init.headers, k => k.toLowerCase());
360
360
  return norm;
361
361
  }
@@ -25,7 +25,7 @@ async function pRetry(fn, opt = {}) {
25
25
  const fname = name || fn.name || 'pRetry function';
26
26
  let delay = initialDelay;
27
27
  let attempt = 0;
28
- /* eslint-disable no-await-in-loop, no-constant-condition */
28
+ /* eslint-disable no-constant-condition */
29
29
  while (true) {
30
30
  const started = Date.now();
31
31
  try {
package/dist/seq/seq.js CHANGED
@@ -149,7 +149,6 @@ function _seq(initialValue, nextFn) {
149
149
  return Sequence.create(initialValue, nextFn);
150
150
  }
151
151
  exports._seq = _seq;
152
- /* eslint-disable no-await-in-loop */
153
152
  /**
154
153
  * Experimental.
155
154
  * Feasibility to be proven.
@@ -18,8 +18,6 @@ const defRetryOptions = {
18
18
  /**
19
19
  * Experimental wrapper around Fetch.
20
20
  * Works in both Browser and Node, using `globalThis.fetch`.
21
- *
22
- * @experimental
23
21
  */
24
22
  export class Fetcher {
25
23
  constructor(cfg = {}) {
@@ -129,7 +127,6 @@ export class Fetcher {
129
127
  },
130
128
  signature,
131
129
  };
132
- /* eslint-disable no-await-in-loop */
133
130
  while (!res.retryStatus.retryStopped) {
134
131
  const started = Date.now();
135
132
  if (this.cfg.logRequest) {
@@ -149,6 +146,8 @@ export class Fetcher {
149
146
  // For example, CORS error would result in "TypeError: failed to fetch" here
150
147
  res.err = err;
151
148
  res.ok = false;
149
+ // important to set it to undefined, otherwise it can keep the previous value (from previous try)
150
+ res.fetchResponse = undefined;
152
151
  }
153
152
  res.statusFamily = this.getStatusFamily(res);
154
153
  if ((_g = res.fetchResponse) === null || _g === void 0 ? void 0 : _g.ok) {
@@ -382,7 +381,8 @@ export class Fetcher {
382
381
  retryPost: false,
383
382
  retry4xx: false,
384
383
  retry5xx: true,
385
- logger: console,
384
+ // logger: console, Danger! doing this mutates console!
385
+ logger: cfg.logger || console,
386
386
  debug,
387
387
  logRequest: debug,
388
388
  logRequestBody: debug,
@@ -397,7 +397,7 @@ export class Fetcher {
397
397
  credentials: cfg.credentials,
398
398
  },
399
399
  hooks: {},
400
- }, _omit(cfg, ['method', 'credentials', 'headers']));
400
+ }, _omit(cfg, ['method', 'credentials', 'headers', 'logger']));
401
401
  norm.init.headers = _mapKeys(norm.init.headers, k => k.toLowerCase());
402
402
  return norm;
403
403
  }
@@ -21,7 +21,7 @@ export async function pRetry(fn, opt = {}) {
21
21
  const fname = name || fn.name || 'pRetry function';
22
22
  let delay = initialDelay;
23
23
  let attempt = 0;
24
- /* eslint-disable no-await-in-loop, no-constant-condition */
24
+ /* eslint-disable no-constant-condition */
25
25
  while (true) {
26
26
  const started = Date.now();
27
27
  try {
@@ -144,7 +144,6 @@ export class Sequence {
144
144
  export function _seq(initialValue, nextFn) {
145
145
  return Sequence.create(initialValue, nextFn);
146
146
  }
147
- /* eslint-disable no-await-in-loop */
148
147
  /**
149
148
  * Experimental.
150
149
  * Feasibility to be proven.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
- "version": "14.139.0",
3
+ "version": "14.139.2",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "build-prod": "build-prod-esm-cjs",
@@ -39,8 +39,6 @@ const defRetryOptions: FetcherRetryOptions = {
39
39
  /**
40
40
  * Experimental wrapper around Fetch.
41
41
  * Works in both Browser and Node, using `globalThis.fetch`.
42
- *
43
- * @experimental
44
42
  */
45
43
  export class Fetcher {
46
44
  private constructor(cfg: FetcherCfg & FetcherOptions = {}) {
@@ -184,7 +182,6 @@ export class Fetcher {
184
182
  signature,
185
183
  } as FetcherResponse<any>
186
184
 
187
- /* eslint-disable no-await-in-loop */
188
185
  while (!res.retryStatus.retryStopped) {
189
186
  const started = Date.now()
190
187
 
@@ -207,6 +204,8 @@ export class Fetcher {
207
204
  // For example, CORS error would result in "TypeError: failed to fetch" here
208
205
  res.err = err as Error
209
206
  res.ok = false
207
+ // important to set it to undefined, otherwise it can keep the previous value (from previous try)
208
+ res.fetchResponse = undefined
210
209
  }
211
210
  res.statusFamily = this.getStatusFamily(res)
212
211
 
@@ -435,7 +434,8 @@ export class Fetcher {
435
434
  retryPost: false,
436
435
  retry4xx: false,
437
436
  retry5xx: true,
438
- logger: console,
437
+ // logger: console, Danger! doing this mutates console!
438
+ logger: cfg.logger || console,
439
439
  debug,
440
440
  logRequest: debug,
441
441
  logRequestBody: debug,
@@ -451,7 +451,7 @@ export class Fetcher {
451
451
  },
452
452
  hooks: {},
453
453
  },
454
- _omit(cfg, ['method', 'credentials', 'headers']),
454
+ _omit(cfg, ['method', 'credentials', 'headers', 'logger']),
455
455
  )
456
456
 
457
457
  norm.init.headers = _mapKeys(norm.init.headers, k => k.toLowerCase())
@@ -128,7 +128,7 @@ export async function pRetry<T>(
128
128
  let delay = initialDelay
129
129
  let attempt = 0
130
130
 
131
- /* eslint-disable no-await-in-loop, no-constant-condition */
131
+ /* eslint-disable no-constant-condition */
132
132
  while (true) {
133
133
  const started = Date.now()
134
134
 
package/src/seq/seq.ts CHANGED
@@ -158,8 +158,6 @@ export function _seq<T>(initialValue: T | typeof END, nextFn: AbortableMapper<T,
158
158
  return Sequence.create(initialValue, nextFn)
159
159
  }
160
160
 
161
- /* eslint-disable no-await-in-loop */
162
-
163
161
  /**
164
162
  * Experimental.
165
163
  * Feasibility to be proven.