@naturalcycles/nodejs-lib 12.76.0 → 12.77.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.
Files changed (95) hide show
  1. package/dist/bin/secrets-gen-key.js +1 -1
  2. package/dist/buffer/buffer.util.js +1 -1
  3. package/dist/colors/colors.js +1 -1
  4. package/dist/fs/kpy.js +1 -1
  5. package/dist/got/getGot.js +2 -2
  6. package/dist/infra/process.util.js +1 -1
  7. package/dist/secret/secrets-decrypt.util.js +1 -1
  8. package/dist/secret/secrets-encrypt.util.js +1 -1
  9. package/dist/security/crypto.util.js +3 -3
  10. package/dist/security/hash.util.d.ts +13 -2
  11. package/dist/security/hash.util.js +35 -9
  12. package/dist/security/secret.util.js +1 -1
  13. package/dist/stream/ndjson/ndjsonMap.js +6 -6
  14. package/dist/stream/ndjson/ndjsonStreamForEach.js +3 -3
  15. package/dist/stream/ndjson/pipelineFromNDJsonFile.d.ts +1 -1
  16. package/dist/stream/ndjson/pipelineFromNDJsonFile.js +2 -2
  17. package/dist/stream/ndjson/pipelineToNDJsonFile.d.ts +1 -1
  18. package/dist/stream/ndjson/pipelineToNDJsonFile.js +2 -2
  19. package/dist/stream/ndjson/transformJsonParse.js +2 -2
  20. package/dist/stream/ndjson/transformToNDJson.js +2 -2
  21. package/dist/stream/pipeline/pipeline.d.ts +1 -1
  22. package/dist/stream/pipeline/pipeline.js +3 -3
  23. package/dist/stream/readable/readableCreate.d.ts +1 -1
  24. package/dist/stream/readable/readableCreate.js +3 -3
  25. package/dist/stream/readable/readableFromArray.d.ts +1 -1
  26. package/dist/stream/readable/readableFromArray.js +2 -2
  27. package/dist/stream/readable/readableMap.js +2 -2
  28. package/dist/stream/stream.model.d.ts +1 -1
  29. package/dist/stream/stream.util.d.ts +1 -1
  30. package/dist/stream/transform/transformBuffer.js +2 -2
  31. package/dist/stream/transform/transformFilter.js +2 -2
  32. package/dist/stream/transform/transformLimit.d.ts +1 -1
  33. package/dist/stream/transform/transformLogProgress.js +4 -4
  34. package/dist/stream/transform/transformMapSimple.js +2 -2
  35. package/dist/stream/transform/transformNoOp.js +2 -2
  36. package/dist/stream/transform/transformTap.js +2 -2
  37. package/dist/stream/transform/transformToArray.js +2 -2
  38. package/dist/stream/transform/transformToString.js +2 -2
  39. package/dist/stream/transform/worker/transformMultiThreaded.js +2 -2
  40. package/dist/stream/writable/writableFork.js +2 -2
  41. package/dist/stream/writable/writableLimit.d.ts +1 -1
  42. package/dist/stream/writable/writableLimit.js +2 -2
  43. package/dist/stream/writable/writablePushToArray.js +2 -2
  44. package/dist/stream/writable/writableVoid.d.ts +1 -1
  45. package/dist/stream/writable/writableVoid.js +2 -2
  46. package/dist/string/inspectAny.d.ts +1 -1
  47. package/dist/string/inspectAny.js +3 -3
  48. package/dist/util/env.util.js +1 -1
  49. package/dist/util/zip.util.d.ts +1 -1
  50. package/dist/util/zip.util.js +6 -6
  51. package/dist/validation/ajv/ajv.util.js +1 -1
  52. package/dist/validation/ajv/ajvSchema.js +1 -1
  53. package/package.json +2 -5
  54. package/src/bin/secrets-gen-key.ts +1 -1
  55. package/src/buffer/buffer.util.ts +1 -1
  56. package/src/colors/colors.ts +1 -1
  57. package/src/fs/kpy.ts +1 -1
  58. package/src/got/getGot.ts +1 -1
  59. package/src/infra/process.util.ts +1 -1
  60. package/src/secret/secrets-decrypt.util.ts +1 -1
  61. package/src/secret/secrets-encrypt.util.ts +1 -1
  62. package/src/security/crypto.util.ts +3 -3
  63. package/src/security/hash.util.ts +33 -7
  64. package/src/security/secret.util.ts +1 -1
  65. package/src/stream/ndjson/ndjsonMap.ts +2 -2
  66. package/src/stream/ndjson/ndjsonStreamForEach.ts +2 -2
  67. package/src/stream/ndjson/pipelineFromNDJsonFile.ts +1 -1
  68. package/src/stream/ndjson/pipelineToNDJsonFile.ts +1 -1
  69. package/src/stream/ndjson/transformJsonParse.ts +1 -1
  70. package/src/stream/ndjson/transformToNDJson.ts +1 -1
  71. package/src/stream/pipeline/pipeline.ts +1 -1
  72. package/src/stream/readable/readableCreate.ts +1 -1
  73. package/src/stream/readable/readableFromArray.ts +1 -1
  74. package/src/stream/readable/readableMap.ts +1 -1
  75. package/src/stream/stream.model.ts +1 -1
  76. package/src/stream/stream.util.ts +1 -1
  77. package/src/stream/transform/transformBuffer.ts +1 -1
  78. package/src/stream/transform/transformFilter.ts +1 -1
  79. package/src/stream/transform/transformLimit.ts +1 -1
  80. package/src/stream/transform/transformLogProgress.ts +2 -2
  81. package/src/stream/transform/transformMapSimple.ts +1 -1
  82. package/src/stream/transform/transformNoOp.ts +1 -1
  83. package/src/stream/transform/transformTap.ts +1 -1
  84. package/src/stream/transform/transformToArray.ts +1 -1
  85. package/src/stream/transform/transformToString.ts +1 -1
  86. package/src/stream/transform/worker/transformMultiThreaded.ts +1 -1
  87. package/src/stream/writable/writableFork.ts +1 -1
  88. package/src/stream/writable/writableLimit.ts +1 -1
  89. package/src/stream/writable/writablePushToArray.ts +1 -1
  90. package/src/stream/writable/writableVoid.ts +1 -1
  91. package/src/string/inspectAny.ts +1 -1
  92. package/src/util/env.util.ts +1 -1
  93. package/src/util/zip.util.ts +3 -3
  94. package/src/validation/ajv/ajv.util.ts +1 -1
  95. package/src/validation/ajv/ajvSchema.ts +1 -1
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- const crypto = require("crypto");
4
+ const crypto = require("node:crypto");
5
5
  const yargs = require("yargs");
6
6
  const colors_1 = require("../colors");
7
7
  const script_1 = require("../script");
@@ -7,7 +7,7 @@ exports._chunkBuffer = void 0;
7
7
  function _chunkBuffer(buf, size) {
8
8
  const out = [];
9
9
  for (let i = 0; i < buf.length; i += size) {
10
- out.push(buf.slice(i, i + size));
10
+ out.push(buf.subarray(i, i + size));
11
11
  }
12
12
  return out;
13
13
  }
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.hasColors = void 0;
4
- const tty = require("tty");
4
+ const tty = require("node:tty");
5
5
  /**
6
6
  * Based on: https://github.com/sindresorhus/yoctocolors/pull/5
7
7
  *
package/dist/fs/kpy.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.kpySync = exports.kpy = void 0;
4
- const path = require("path");
4
+ const path = require("node:path");
5
5
  const js_lib_1 = require("@naturalcycles/js-lib");
6
6
  const cpFile = require("cp-file");
7
7
  const fs = require("fs-extra");
@@ -1,7 +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
+ const node_url_1 = require("node:url");
5
5
  const js_lib_1 = require("@naturalcycles/js-lib");
6
6
  const got_1 = require("got");
7
7
  const __1 = require("..");
@@ -246,7 +246,7 @@ function gotAfterResponseHook(opt = {}) {
246
246
  }
247
247
  function getShortUrl(opt, url, prefixUrl) {
248
248
  if (url.password) {
249
- url = new url_1.URL(url.toString()); // prevent original url mutation
249
+ url = new node_url_1.URL(url.toString()); // prevent original url mutation
250
250
  url.password = '[redacted]';
251
251
  }
252
252
  let shortUrl = url.toString();
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.processSharedUtil = exports.memoryUsageFull = exports.memoryUsage = void 0;
4
- const os = require("os");
4
+ const os = require("node:os");
5
5
  const js_lib_1 = require("@naturalcycles/js-lib");
6
6
  /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
7
7
  function memoryUsage() {
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.secretsDecrypt = void 0;
4
- const path = require("path");
4
+ const path = require("node:path");
5
5
  const js_lib_1 = require("@naturalcycles/js-lib");
6
6
  const fs = require("fs-extra");
7
7
  const colors_1 = require("../colors");
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.secretsEncrypt = void 0;
4
- const path = require("path");
4
+ const path = require("node:path");
5
5
  const js_lib_1 = require("@naturalcycles/js-lib");
6
6
  const fs = require("fs-extra");
7
7
  const colors_1 = require("../colors");
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.encryptString = exports.decryptString = exports.encryptObject = exports.decryptObject = exports.decryptRandomIVBuffer = exports.encryptRandomIVBuffer = void 0;
4
- const crypto = require("crypto");
4
+ const crypto = require("node:crypto");
5
5
  const js_lib_1 = require("@naturalcycles/js-lib");
6
6
  const hash_util_1 = require("./hash.util");
7
7
  const algorithm = 'aes-256-cbc';
@@ -24,8 +24,8 @@ function decryptRandomIVBuffer(input, secretKeyBase64) {
24
24
  // md5 to match aes-256 key length of 32 bytes
25
25
  const key = (0, hash_util_1.md5)(Buffer.from(secretKeyBase64, 'base64'));
26
26
  // iv is first 16 bytes of encrypted buffer, the rest is payload
27
- const iv = input.slice(0, 16);
28
- const payload = input.slice(16);
27
+ const iv = input.subarray(0, 16);
28
+ const payload = input.subarray(16);
29
29
  const decipher = crypto.createDecipheriv(algorithm, key, iv);
30
30
  return Buffer.concat([decipher.update(payload), decipher.final()]);
31
31
  }
@@ -1,9 +1,20 @@
1
1
  /// <reference types="node" />
2
2
  export declare function md5(s: string | Buffer): string;
3
+ export declare function md5AsBase64(s: string | Buffer): string;
3
4
  export declare function md5AsBuffer(s: string | Buffer): Buffer;
5
+ export declare function sha256(s: string | Buffer): string;
6
+ export declare function sha256AsBase64(s: string | Buffer): string;
7
+ export declare function sha256AsBuffer(s: string | Buffer): Buffer;
4
8
  export declare function hash(s: string | Buffer, algorithm: string): string;
5
9
  export declare function hashAsBuffer(s: string | Buffer, algorithm: string): Buffer;
6
- export declare function stringToBase64(s: string): string;
10
+ export declare function base64(s: string | Buffer): string;
7
11
  export declare function base64ToString(strBase64: string): string;
8
- export declare function bufferToBase64(b: Buffer): string;
9
12
  export declare function base64ToBuffer(strBase64: string): Buffer;
13
+ /**
14
+ * @deprecated use `base64`
15
+ */
16
+ export declare function stringToBase64(s: string): string;
17
+ /**
18
+ * @deprecated use `base64`
19
+ */
20
+ export declare function bufferToBase64(b: Buffer): string;
@@ -1,15 +1,31 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.base64ToBuffer = exports.bufferToBase64 = exports.base64ToString = exports.stringToBase64 = exports.hashAsBuffer = exports.hash = exports.md5AsBuffer = exports.md5 = void 0;
4
- const crypto = require("crypto");
3
+ exports.bufferToBase64 = exports.stringToBase64 = exports.base64ToBuffer = exports.base64ToString = exports.base64 = exports.hashAsBuffer = exports.hash = exports.sha256AsBuffer = exports.sha256AsBase64 = exports.sha256 = exports.md5AsBuffer = exports.md5AsBase64 = exports.md5 = void 0;
4
+ const crypto = require("node:crypto");
5
5
  function md5(s) {
6
6
  return hash(s, 'md5');
7
7
  }
8
8
  exports.md5 = md5;
9
+ function md5AsBase64(s) {
10
+ return hashAsBuffer(s, 'md5').toString('base64');
11
+ }
12
+ exports.md5AsBase64 = md5AsBase64;
9
13
  function md5AsBuffer(s) {
10
14
  return hashAsBuffer(s, 'md5');
11
15
  }
12
16
  exports.md5AsBuffer = md5AsBuffer;
17
+ function sha256(s) {
18
+ return hash(s, 'sha256');
19
+ }
20
+ exports.sha256 = sha256;
21
+ function sha256AsBase64(s) {
22
+ return hashAsBuffer(s, 'sha256').toString('base64');
23
+ }
24
+ exports.sha256AsBase64 = sha256AsBase64;
25
+ function sha256AsBuffer(s) {
26
+ return hashAsBuffer(s, 'sha256');
27
+ }
28
+ exports.sha256AsBuffer = sha256AsBuffer;
13
29
  function hash(s, algorithm) {
14
30
  return crypto.createHash(algorithm).update(s).digest('hex');
15
31
  }
@@ -18,19 +34,29 @@ function hashAsBuffer(s, algorithm) {
18
34
  return crypto.createHash(algorithm).update(s).digest();
19
35
  }
20
36
  exports.hashAsBuffer = hashAsBuffer;
21
- function stringToBase64(s) {
22
- return Buffer.from(s, 'utf8').toString('base64');
37
+ function base64(s) {
38
+ return (Buffer.isBuffer(s) ? s : Buffer.from(s, 'utf8')).toString('base64');
23
39
  }
24
- exports.stringToBase64 = stringToBase64;
40
+ exports.base64 = base64;
25
41
  function base64ToString(strBase64) {
26
42
  return Buffer.from(strBase64, 'base64').toString('utf8');
27
43
  }
28
44
  exports.base64ToString = base64ToString;
29
- function bufferToBase64(b) {
30
- return b.toString('base64');
31
- }
32
- exports.bufferToBase64 = bufferToBase64;
33
45
  function base64ToBuffer(strBase64) {
34
46
  return Buffer.from(strBase64, 'base64');
35
47
  }
36
48
  exports.base64ToBuffer = base64ToBuffer;
49
+ /**
50
+ * @deprecated use `base64`
51
+ */
52
+ function stringToBase64(s) {
53
+ return Buffer.from(s, 'utf8').toString('base64');
54
+ }
55
+ exports.stringToBase64 = stringToBase64;
56
+ /**
57
+ * @deprecated use `base64`
58
+ */
59
+ function bufferToBase64(b) {
60
+ return b.toString('base64');
61
+ }
62
+ exports.bufferToBase64 = bufferToBase64;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.setSecretMap = exports.getSecretMap = exports.secretOptional = exports.secret = exports.loadSecretsFromEncryptedJsonFileValues = exports.loadSecretsFromEncryptedJsonFile = exports.removeSecretsFromEnv = exports.loadSecretsFromEnv = void 0;
4
- const fs = require("fs");
4
+ const fs = require("node:fs");
5
5
  const js_lib_1 = require("@naturalcycles/js-lib");
6
6
  const __1 = require("..");
7
7
  const crypto_util_1 = require("./crypto.util");
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ndjsonMap = void 0;
4
- const fs_1 = require("fs");
5
- const zlib_1 = require("zlib");
4
+ const node_fs_1 = require("node:fs");
5
+ const node_zlib_1 = require("node:zlib");
6
6
  const js_lib_1 = require("@naturalcycles/js-lib");
7
7
  const __1 = require("../..");
8
8
  /**
@@ -16,9 +16,9 @@ async function ndjsonMap(mapper, opt) {
16
16
  inputFilePath,
17
17
  outputFilePath,
18
18
  });
19
- const transformUnzip = inputFilePath.endsWith('.gz') ? [(0, zlib_1.createUnzip)()] : [];
20
- const transformZip = outputFilePath.endsWith('.gz') ? [(0, zlib_1.createGzip)()] : [];
21
- const readable = (0, fs_1.createReadStream)(inputFilePath);
19
+ const transformUnzip = inputFilePath.endsWith('.gz') ? [(0, node_zlib_1.createUnzip)()] : [];
20
+ const transformZip = outputFilePath.endsWith('.gz') ? [(0, node_zlib_1.createGzip)()] : [];
21
+ const readable = (0, node_fs_1.createReadStream)(inputFilePath);
22
22
  await (0, __1._pipeline)([
23
23
  readable,
24
24
  ...transformUnzip,
@@ -35,7 +35,7 @@ async function ndjsonMap(mapper, opt) {
35
35
  (0, __1.transformLogProgress)({ metric: 'saved', logEvery: logEveryOutput }),
36
36
  (0, __1.transformToNDJson)(),
37
37
  ...transformZip,
38
- (0, fs_1.createWriteStream)(outputFilePath),
38
+ (0, node_fs_1.createWriteStream)(outputFilePath),
39
39
  ]);
40
40
  }
41
41
  exports.ndjsonMap = ndjsonMap;
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ndjsonStreamForEach = void 0;
4
- const fs = require("fs");
5
- const zlib_1 = require("zlib");
4
+ const fs = require("node:fs");
5
+ const node_zlib_1 = require("node:zlib");
6
6
  const js_lib_1 = require("@naturalcycles/js-lib");
7
7
  const __1 = require("../..");
8
8
  /**
@@ -10,7 +10,7 @@ const __1 = require("../..");
10
10
  */
11
11
  async function ndjsonStreamForEach(mapper, opt) {
12
12
  (0, __1.requireFileToExist)(opt.inputFilePath);
13
- const transformUnzip = opt.inputFilePath.endsWith('.gz') ? [(0, zlib_1.createUnzip)()] : [];
13
+ const transformUnzip = opt.inputFilePath.endsWith('.gz') ? [(0, node_zlib_1.createUnzip)()] : [];
14
14
  await (0, __1._pipeline)([
15
15
  fs.createReadStream(opt.inputFilePath),
16
16
  ...transformUnzip,
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
- import { ZlibOptions } from 'zlib';
3
+ import { ZlibOptions } from 'node:zlib';
4
4
  import { NDJsonStats } from './ndjson.model';
5
5
  import { TransformJsonParseOptions } from './transformJsonParse';
6
6
  export interface PipelineFromNDJsonFileOptions extends TransformJsonParseOptions {
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.pipelineFromNDJsonFile = void 0;
4
- const zlib_1 = require("zlib");
4
+ const node_zlib_1 = require("node:zlib");
5
5
  const js_lib_1 = require("@naturalcycles/js-lib");
6
6
  const fs = require("fs-extra");
7
7
  const __1 = require("../..");
@@ -19,7 +19,7 @@ async function pipelineFromNDJsonFile(streams, opt) {
19
19
  console.log(`<< ${(0, colors_1.grey)(filePath)} ${(0, colors_1.dimWhite)((0, js_lib_1._hb)(sizeBytes))} started...`);
20
20
  await (0, __1._pipeline)([
21
21
  fs.createReadStream(filePath),
22
- ...(gzip ? [(0, zlib_1.createUnzip)(opt.zlibOptions)] : []),
22
+ ...(gzip ? [(0, node_zlib_1.createUnzip)(opt.zlibOptions)] : []),
23
23
  (0, __1.transformSplit)(separator),
24
24
  (0, transformJsonParse_1.transformJsonParse)(opt),
25
25
  (0, __1.transformTap)(() => rows++),
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
- import { ZlibOptions } from 'zlib';
3
+ import { ZlibOptions } from 'node:zlib';
4
4
  import { NDJsonStats } from './ndjson.model';
5
5
  import { TransformToNDJsonOptions } from './transformToNDJson';
6
6
  export interface PipelineToNDJsonFileOptions extends TransformToNDJsonOptions {
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.pipelineToNDJsonFile = void 0;
4
- const zlib_1 = require("zlib");
4
+ const node_zlib_1 = require("node:zlib");
5
5
  const js_lib_1 = require("@naturalcycles/js-lib");
6
6
  const fs = require("fs-extra");
7
7
  const __1 = require("../..");
@@ -26,7 +26,7 @@ async function pipelineToNDJsonFile(streams, opt) {
26
26
  ...streams,
27
27
  (0, __1.transformTap)(() => rows++),
28
28
  (0, transformToNDJson_1.transformToNDJson)(opt),
29
- ...(gzip ? [(0, zlib_1.createGzip)(opt.zlibOptions)] : []),
29
+ ...(gzip ? [(0, node_zlib_1.createGzip)(opt.zlibOptions)] : []),
30
30
  fs.createWriteStream(filePath),
31
31
  ]);
32
32
  const { size: sizeBytes } = fs.statSync(filePath);
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.bufferReviver = exports.transformJsonParse = void 0;
4
- const stream_1 = require("stream");
4
+ const node_stream_1 = require("node:stream");
5
5
  /**
6
6
  * Transforms chunks of JSON strings/Buffers (objectMode=false) into parsed objects (readableObjectMode=true).
7
7
  *
@@ -18,7 +18,7 @@ const stream_1 = require("stream");
18
18
  */
19
19
  function transformJsonParse(opt = {}) {
20
20
  const { strict = true, reviver } = opt;
21
- return new stream_1.Transform({
21
+ return new node_stream_1.Transform({
22
22
  writableObjectMode: false,
23
23
  readableObjectMode: true,
24
24
  transform(chunk, _, cb) {
@@ -1,14 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.transformToNDJson = void 0;
4
- const stream_1 = require("stream");
4
+ const node_stream_1 = require("node:stream");
5
5
  const js_lib_1 = require("@naturalcycles/js-lib");
6
6
  /**
7
7
  * Transforms objects (objectMode=true) into chunks \n-terminated JSON strings (readableObjectMode=false).
8
8
  */
9
9
  function transformToNDJson(opt = {}) {
10
10
  const { strict = true, separator = '\n', sortObjects = false, useFlatstr = false } = opt;
11
- return new stream_1.Transform({
11
+ return new node_stream_1.Transform({
12
12
  writableObjectMode: true,
13
13
  readableObjectMode: false,
14
14
  transform(chunk, _, cb) {
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
- import { Readable, Transform } from 'stream';
3
+ import { Readable, Transform } from 'node:stream';
4
4
  import { DeferredPromise } from '@naturalcycles/js-lib';
5
5
  declare type AnyStream = NodeJS.ReadableStream | NodeJS.WritableStream | NodeJS.ReadWriteStream;
6
6
  export interface PipelineOptions {
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AbortableTransform = exports._pipelineToArray = exports._pipeline = void 0;
4
- const stream_1 = require("stream");
4
+ const node_stream_1 = require("node:stream");
5
5
  const js_lib_1 = require("@naturalcycles/js-lib");
6
6
  const index_1 = require("../../index");
7
7
  /**
@@ -53,7 +53,7 @@ async function _pipeline(streams, opt = {}) {
53
53
  });
54
54
  }
55
55
  return new Promise((resolve, reject) => {
56
- (0, stream_1.pipeline)(first, ...rest, (err) => {
56
+ (0, node_stream_1.pipeline)(first, ...rest, (err) => {
57
57
  if (err) {
58
58
  if (opt.allowClose && err?.code === 'ERR_STREAM_PREMATURE_CLOSE') {
59
59
  console.log('_pipeline closed (as expected)');
@@ -77,6 +77,6 @@ async function _pipelineToArray(streams, opt = {}) {
77
77
  return a;
78
78
  }
79
79
  exports._pipelineToArray = _pipelineToArray;
80
- class AbortableTransform extends stream_1.Transform {
80
+ class AbortableTransform extends node_stream_1.Transform {
81
81
  }
82
82
  exports.AbortableTransform = AbortableTransform;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { ReadableOptions } from 'stream';
2
+ import { ReadableOptions } from 'node:stream';
3
3
  import { ReadableTyped } from '../stream.model';
4
4
  /**
5
5
  * Convenience function to create a Readable that can be pushed into (similar to RxJS Subject).
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.readableFrom = exports.readableCreate = void 0;
4
- const stream_1 = require("stream");
4
+ const node_stream_1 = require("node:stream");
5
5
  /**
6
6
  * Convenience function to create a Readable that can be pushed into (similar to RxJS Subject).
7
7
  * Push `null` to it to complete (similar to RxJS `.complete()`).
@@ -17,7 +17,7 @@ const stream_1 = require("stream");
17
17
  * @deprecated because of the caution above
18
18
  */
19
19
  function readableCreate(items = [], opt) {
20
- const readable = new stream_1.Readable({
20
+ const readable = new node_stream_1.Readable({
21
21
  objectMode: true,
22
22
  ...opt,
23
23
  read() { }, // Caution, if this is called and Readable has not finished yet (null wasn't pushed) - it'll hang the process!
@@ -32,6 +32,6 @@ exports.readableCreate = readableCreate;
32
32
  * Convenience type-safe wrapper around Readable.from() that infers the Type of input.
33
33
  */
34
34
  function readableFrom(items, opt) {
35
- return stream_1.Readable.from(items, opt);
35
+ return node_stream_1.Readable.from(items, opt);
36
36
  }
37
37
  exports.readableFrom = readableFrom;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { ReadableOptions } from 'stream';
2
+ import { ReadableOptions } from 'node:stream';
3
3
  import { AbortableAsyncMapper } from '@naturalcycles/js-lib';
4
4
  import { ReadableTyped } from '../stream.model';
5
5
  /**
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.readableFromArray = void 0;
4
- const stream_1 = require("stream");
4
+ const node_stream_1 = require("node:stream");
5
5
  const js_lib_1 = require("@naturalcycles/js-lib");
6
6
  /**
7
7
  * Create Readable from Array.
@@ -11,7 +11,7 @@ const js_lib_1 = require("@naturalcycles/js-lib");
11
11
  */
12
12
  function readableFromArray(items, mapper = js_lib_1._passthroughMapper, opt) {
13
13
  let i = -1;
14
- return new stream_1.Readable({
14
+ return new node_stream_1.Readable({
15
15
  objectMode: true,
16
16
  ...opt,
17
17
  async read() {
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.readableMap = void 0;
4
- const stream_1 = require("stream");
4
+ const node_stream_1 = require("node:stream");
5
5
  const js_lib_1 = require("@naturalcycles/js-lib");
6
6
  function readableMap(readable, mapper) {
7
7
  let i = -1;
8
8
  // todo: check if we need to handle errors somehow specifically
9
- return readable.pipe(new stream_1.Transform({
9
+ return readable.pipe(new node_stream_1.Transform({
10
10
  objectMode: true,
11
11
  async transform(chunk, _enc, cb) {
12
12
  try {
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { Readable, Transform, Writable } from 'stream';
2
+ import { Readable, Transform, Writable } from 'node:stream';
3
3
  export interface ReadableTyped<T> extends Readable {
4
4
  }
5
5
  export interface WritableTyped<T> extends Writable {
@@ -1,4 +1,4 @@
1
1
  /// <reference types="node" />
2
- import { Readable } from 'stream';
2
+ import { Readable } from 'node:stream';
3
3
  import { CommonLogger } from '@naturalcycles/js-lib';
4
4
  export declare function pipelineClose(name: string, readableDownstream: Readable, sourceReadable: Readable | undefined, streamDone: Promise<void> | undefined, logger: CommonLogger): void;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.transformBuffer = void 0;
4
- const stream_1 = require("stream");
4
+ const node_stream_1 = require("node:stream");
5
5
  /**
6
6
  * Similar to RxJS bufferCount()
7
7
  *
@@ -10,7 +10,7 @@ const stream_1 = require("stream");
10
10
  function transformBuffer(opt) {
11
11
  const { batchSize } = opt;
12
12
  let buf = [];
13
- return new stream_1.Transform({
13
+ return new node_stream_1.Transform({
14
14
  objectMode: true,
15
15
  ...opt,
16
16
  transform(chunk, _, cb) {
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.transformFilterSync = exports.transformFilter = void 0;
4
- const stream_1 = require("stream");
4
+ const node_stream_1 = require("node:stream");
5
5
  const transformMap_1 = require("./transformMap");
6
6
  /**
7
7
  * Just a convenience wrapper around `transformMap` that has built-in predicate filtering support.
@@ -18,7 +18,7 @@ exports.transformFilter = transformFilter;
18
18
  */
19
19
  function transformFilterSync(predicate, opt = {}) {
20
20
  let index = 0;
21
- return new stream_1.Transform({
21
+ return new node_stream_1.Transform({
22
22
  objectMode: true,
23
23
  ...opt,
24
24
  transform(chunk, _, cb) {
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { Readable } from 'stream';
2
+ import { Readable } from 'node:stream';
3
3
  import { CommonLogger } from '@naturalcycles/js-lib';
4
4
  import { AbortableTransform } from '../../index';
5
5
  import { TransformOptions, TransformTyped } from '../stream.model';
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.transformLogProgress = void 0;
4
- const stream_1 = require("stream");
5
- const util_1 = require("util");
4
+ const node_stream_1 = require("node:stream");
5
+ const node_util_1 = require("node:util");
6
6
  const js_lib_1 = require("@naturalcycles/js-lib");
7
7
  const colors_1 = require("../../colors");
8
8
  const colors_2 = require("../../colors/colors");
@@ -27,7 +27,7 @@ function transformLogProgress(opt = {}) {
27
27
  const sizes = logSizes ? new sizeStack_1.SizeStack('json', logSizesBuffer) : undefined;
28
28
  const sizesZipped = logZippedSizes ? new sizeStack_1.SizeStack('json.gz', logSizesBuffer) : undefined;
29
29
  logStats(); // initial
30
- return new stream_1.Transform({
30
+ return new node_stream_1.Transform({
31
31
  objectMode: true,
32
32
  ...opt,
33
33
  transform(chunk, _, cb) {
@@ -81,7 +81,7 @@ function transformLogProgress(opt = {}) {
81
81
  o.arrayBuffers = (0, js_lib_1._mb)(mem.arrayBuffers || 0);
82
82
  if (logRPS)
83
83
  Object.assign(o, { rps10, rpsTotal });
84
- logger.log((0, util_1.inspect)(o, inspectOpt));
84
+ logger.log((0, node_util_1.inspect)(o, inspectOpt));
85
85
  if (sizes?.items.length) {
86
86
  logger.log(sizes.getStats());
87
87
  if (sizesZipped?.items.length) {
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.transformMapSimple = void 0;
4
- const stream_1 = require("stream");
4
+ const node_stream_1 = require("node:stream");
5
5
  const js_lib_1 = require("@naturalcycles/js-lib");
6
6
  /**
7
7
  * Simplest version of `transformMap`.
@@ -15,7 +15,7 @@ const js_lib_1 = require("@naturalcycles/js-lib");
15
15
  function transformMapSimple(mapper, opt = {}) {
16
16
  let index = -1;
17
17
  const { errorMode = js_lib_1.ErrorMode.THROW_IMMEDIATELY, logger = console } = opt;
18
- return new stream_1.Transform({
18
+ return new node_stream_1.Transform({
19
19
  objectMode: true,
20
20
  transform(chunk, _, cb) {
21
21
  try {
@@ -1,14 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.transformNoOp = void 0;
4
- const stream_1 = require("stream");
4
+ const node_stream_1 = require("node:stream");
5
5
  /**
6
6
  * Transform that does nothing (pass the data through).
7
7
  * Can be used e.g to convert "not-valid" stream (e.g one that `transformMap` is producing)
8
8
  * into a "valid" stream (that implements async-iteration interface).
9
9
  */
10
10
  function transformNoOp() {
11
- return new stream_1.Transform({
11
+ return new node_stream_1.Transform({
12
12
  objectMode: true,
13
13
  transform(chunk, _, cb) {
14
14
  cb(null, chunk);
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.transformTap = void 0;
4
- const stream_1 = require("stream");
4
+ const node_stream_1 = require("node:stream");
5
5
  /**
6
6
  * Similar to RxJS `tap` - allows to run a function for each stream item, without affecting the result.
7
7
  * Item is passed through to the output.
@@ -11,7 +11,7 @@ const stream_1 = require("stream");
11
11
  function transformTap(fn, opt = {}) {
12
12
  const { logger = console } = opt;
13
13
  let index = -1;
14
- return new stream_1.Transform({
14
+ return new node_stream_1.Transform({
15
15
  objectMode: true,
16
16
  ...opt,
17
17
  async transform(chunk, _, cb) {
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.transformToArray = void 0;
4
- const stream_1 = require("stream");
4
+ const node_stream_1 = require("node:stream");
5
5
  /**
6
6
  * Will collect all stream results in the array (keeping it in memory) and emit in the end as one result.
7
7
  */
8
8
  function transformToArray(opt = {}) {
9
9
  const res = [];
10
- return new stream_1.Transform({
10
+ return new node_stream_1.Transform({
11
11
  objectMode: true,
12
12
  ...opt,
13
13
  transform(chunk, _, cb) {