@naturalcycles/nodejs-lib 12.69.0 → 12.71.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.
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getGot = void 0;
4
+ const url_1 = require("url");
4
5
  const js_lib_1 = require("@naturalcycles/js-lib");
5
6
  const got_1 = require("got");
6
7
  const __1 = require("..");
@@ -180,7 +181,9 @@ function gotBeforeRetryHook(opt) {
180
181
  const statusCode = err?.response?.statusCode || 0;
181
182
  if (statusCode && statusCode < 300) {
182
183
  // todo: possibly remove the log message completely in the future
183
- opt.logger.log(`skipping got.beforeRetry hook as statusCode is ${statusCode}, err.msg is ${err?.message}`);
184
+ // opt.logger!.log(
185
+ // `skipping got.beforeRetry hook as statusCode is ${statusCode}, err.msg is ${err?.message}`,
186
+ // )
184
187
  return;
185
188
  }
186
189
  const { method, url, prefixUrl } = options;
@@ -242,6 +245,10 @@ function gotAfterResponseHook(opt = {}) {
242
245
  };
243
246
  }
244
247
  function getShortUrl(opt, url, prefixUrl) {
248
+ if (url.password) {
249
+ url = new url_1.URL(url.toString()); // prevent original url mutation
250
+ url.password = '[redacted]';
251
+ }
245
252
  let shortUrl = url.toString();
246
253
  if (opt.logWithSearchParams === false) {
247
254
  shortUrl = shortUrl.split('?')[0];
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import { ZlibOptions } from 'zlib';
3
4
  import { NDJsonStats } from './ndjson.model';
4
5
  import { TransformJsonParseOptions } from './transformJsonParse';
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import { ZlibOptions } from 'zlib';
3
4
  import { NDJsonStats } from './ndjson.model';
4
5
  import { TransformToNDJsonOptions } from './transformToNDJson';
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import { Readable, Transform } from 'stream';
3
4
  import { DeferredPromise } from '@naturalcycles/js-lib';
4
5
  declare type AnyStream = NodeJS.ReadableStream | NodeJS.WritableStream | NodeJS.ReadWriteStream;
@@ -29,7 +29,7 @@ export interface TransformMapOptions<IN = any, OUT = IN> {
29
29
  * If defined - will be called on every error happening in the stream.
30
30
  * Called BEFORE observable will emit error (unless skipErrors is set to true).
31
31
  */
32
- onError?: (err: unknown, input: IN) => any;
32
+ onError?: (err: Error, input: IN) => any;
33
33
  /**
34
34
  * Progress metric
35
35
  *
@@ -67,7 +67,7 @@ function transformMap(mapper, opt = {}) {
67
67
  logErrorStats();
68
68
  if (onError) {
69
69
  try {
70
- onError(err, chunk);
70
+ onError((0, js_lib_1._anyToError)(err), chunk);
71
71
  }
72
72
  catch { }
73
73
  }
@@ -27,7 +27,7 @@ export interface TransformMapSyncOptions<IN = any, OUT = IN> {
27
27
  * If defined - will be called on every error happening in the stream.
28
28
  * Called BEFORE observable will emit error (unless skipErrors is set to true).
29
29
  */
30
- onError?: (err: unknown, input: IN) => any;
30
+ onError?: (err: Error, input: IN) => any;
31
31
  /**
32
32
  * Progress metric
33
33
  *
@@ -50,7 +50,7 @@ function transformMapSync(mapper, opt = {}) {
50
50
  logErrorStats();
51
51
  if (onError) {
52
52
  try {
53
- onError(err, chunk);
53
+ onError((0, js_lib_1._anyToError)(err), chunk);
54
54
  }
55
55
  catch { }
56
56
  }
@@ -1,5 +1,5 @@
1
1
  import { MemoCache } from '@naturalcycles/js-lib';
2
- import LRUCache = require('lru-cache');
2
+ import * as LRUCache from 'lru-cache';
3
3
  export declare type LRUMemoCacheOptions<KEY, VALUE> = Partial<LRUCache.Options<KEY, VALUE>>;
4
4
  /**
5
5
  * @example
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import { ZlibOptions } from 'zlib';
3
4
  /**
4
5
  * deflateBuffer uses `deflate`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/nodejs-lib",
3
- "version": "12.69.0",
3
+ "version": "12.71.0",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "docs-serve": "vuepress dev docs",
@@ -15,7 +15,6 @@
15
15
  },
16
16
  "dependencies": {
17
17
  "@naturalcycles/js-lib": "^14.0.0",
18
- "@types/lru-cache": "^7.4.0",
19
18
  "@types/through2-concurrent": "^2.0.0",
20
19
  "ajv": "^8.6.2",
21
20
  "ajv-formats": "^2.1.0",
@@ -42,7 +41,7 @@
42
41
  "@naturalcycles/dev-lib": "^12.0.0",
43
42
  "@types/node": "^17.0.0",
44
43
  "@types/yargs": "^16.0.0",
45
- "jest": "^27.0.1",
44
+ "jest": "^28.0.3",
46
45
  "nock": "^13.0.2",
47
46
  "patch-package": "^6.2.1",
48
47
  "prettier": "^2.0.0",
package/src/got/getGot.ts CHANGED
@@ -207,9 +207,9 @@ function gotBeforeRetryHook(opt: GetGotOptions): BeforeRetryHook {
207
207
 
208
208
  if (statusCode && statusCode < 300) {
209
209
  // todo: possibly remove the log message completely in the future
210
- opt.logger!.log(
211
- `skipping got.beforeRetry hook as statusCode is ${statusCode}, err.msg is ${err?.message}`,
212
- )
210
+ // opt.logger!.log(
211
+ // `skipping got.beforeRetry hook as statusCode is ${statusCode}, err.msg is ${err?.message}`,
212
+ // )
213
213
  return
214
214
  }
215
215
 
@@ -284,6 +284,11 @@ function gotAfterResponseHook(opt: GetGotOptions = {}): AfterResponseHook {
284
284
  }
285
285
 
286
286
  function getShortUrl(opt: GetGotOptions, url: URL, prefixUrl?: string): string {
287
+ if (url.password) {
288
+ url = new URL(url.toString()) // prevent original url mutation
289
+ url.password = '[redacted]'
290
+ }
291
+
287
292
  let shortUrl = url.toString()
288
293
 
289
294
  if (opt.logWithSearchParams === false) {
@@ -1,4 +1,5 @@
1
1
  import {
2
+ _anyToError,
2
3
  AbortableAsyncMapper,
3
4
  AggregatedError,
4
5
  AsyncPredicate,
@@ -47,7 +48,7 @@ export interface TransformMapOptions<IN = any, OUT = IN> {
47
48
  * If defined - will be called on every error happening in the stream.
48
49
  * Called BEFORE observable will emit error (unless skipErrors is set to true).
49
50
  */
50
- onError?: (err: unknown, input: IN) => any
51
+ onError?: (err: Error, input: IN) => any
51
52
 
52
53
  /**
53
54
  * Progress metric
@@ -144,7 +145,7 @@ export function transformMap<IN = any, OUT = IN>(
144
145
 
145
146
  if (onError) {
146
147
  try {
147
- onError(err, chunk)
148
+ onError(_anyToError(err), chunk)
148
149
  } catch {}
149
150
  }
150
151
 
@@ -1,4 +1,5 @@
1
1
  import {
2
+ _anyToError,
2
3
  AggregatedError,
3
4
  CommonLogger,
4
5
  END,
@@ -42,7 +43,7 @@ export interface TransformMapSyncOptions<IN = any, OUT = IN> {
42
43
  * If defined - will be called on every error happening in the stream.
43
44
  * Called BEFORE observable will emit error (unless skipErrors is set to true).
44
45
  */
45
- onError?: (err: unknown, input: IN) => any
46
+ onError?: (err: Error, input: IN) => any
46
47
 
47
48
  /**
48
49
  * Progress metric
@@ -116,7 +117,7 @@ export function transformMapSync<IN = any, OUT = IN>(
116
117
 
117
118
  if (onError) {
118
119
  try {
119
- onError(err, chunk)
120
+ onError(_anyToError(err), chunk)
120
121
  } catch {}
121
122
  }
122
123
 
@@ -1,5 +1,5 @@
1
1
  import { MemoCache } from '@naturalcycles/js-lib'
2
- import LRUCache = require('lru-cache')
2
+ import * as LRUCache from 'lru-cache'
3
3
 
4
4
  // Partial, to be able to provide default `max`
5
5
  export type LRUMemoCacheOptions<KEY, VALUE> = Partial<LRUCache.Options<KEY, VALUE>>