@naturalcycles/nodejs-lib 12.34.0 → 12.38.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.
Files changed (65) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/dist/fs/kpy.js +1 -1
  3. package/dist/index.d.ts +2 -1
  4. package/dist/index.js +4 -2
  5. package/dist/infra/process.util.js +1 -1
  6. package/dist/log/debug.js +14 -13
  7. package/dist/secret/secrets-decrypt.util.js +1 -1
  8. package/dist/secret/secrets-encrypt.util.js +1 -1
  9. package/dist/security/secret.util.js +1 -0
  10. package/dist/stream/ndjson/ndjsonMap.js +1 -1
  11. package/dist/stream/ndjson/ndjsonStreamForEach.js +1 -1
  12. package/dist/stream/ndjson/pipelineFromNDJsonFile.js +2 -3
  13. package/dist/stream/ndjson/pipelineToNDJsonFile.js +1 -1
  14. package/dist/stream/ndjson/transformToNDJson.js +1 -1
  15. package/dist/stream/readable/readableFromArray.d.ts +1 -1
  16. package/dist/stream/readable/readableFromArray.js +1 -1
  17. package/dist/stream/transform/transformLogProgress.d.ts +9 -2
  18. package/dist/stream/transform/transformLogProgress.js +8 -4
  19. package/dist/stream/transform/transformMap.d.ts +0 -8
  20. package/dist/stream/transform/transformMap.js +2 -3
  21. package/dist/stream/transform/transformMapSimple.js +1 -1
  22. package/dist/stream/transform/transformMapSync.js +1 -1
  23. package/dist/stream/transform/transformNoOp.d.ts +7 -0
  24. package/dist/stream/transform/transformNoOp.js +18 -0
  25. package/dist/stream/transform/worker/transformMultiThreaded.d.ts +2 -2
  26. package/dist/stream/transform/worker/transformMultiThreaded.js +2 -3
  27. package/dist/string/inspectAny.d.ts +1 -1
  28. package/dist/string/inspectAny.js +2 -2
  29. package/dist/util/zip.util.d.ts +8 -0
  30. package/dist/util/zip.util.js +8 -0
  31. package/dist/validation/ajv/ajvSchema.js +1 -1
  32. package/dist/validation/joi/joi.extensions.js +1 -0
  33. package/dist/validation/joi/number.extensions.js +0 -1
  34. package/dist/validation/joi/string.extensions.js +0 -1
  35. package/package.json +1 -1
  36. package/src/fs/kpy.ts +1 -1
  37. package/src/got/getGot.ts +1 -1
  38. package/src/index.ts +2 -0
  39. package/src/infra/process.util.ts +1 -1
  40. package/src/log/debug.ts +14 -13
  41. package/src/secret/secrets-decrypt.util.ts +1 -1
  42. package/src/secret/secrets-encrypt.util.ts +1 -1
  43. package/src/security/secret.util.ts +2 -1
  44. package/src/stream/ndjson/ndjsonMap.ts +1 -1
  45. package/src/stream/ndjson/ndjsonStreamForEach.ts +1 -1
  46. package/src/stream/ndjson/pipelineFromNDJsonFile.ts +2 -3
  47. package/src/stream/ndjson/pipelineToNDJsonFile.ts +1 -1
  48. package/src/stream/ndjson/transformJsonParse.ts +1 -1
  49. package/src/stream/ndjson/transformToNDJson.ts +1 -1
  50. package/src/stream/readable/readableFromArray.ts +1 -1
  51. package/src/stream/transform/transformFilter.ts +1 -1
  52. package/src/stream/transform/transformLogProgress.ts +18 -5
  53. package/src/stream/transform/transformMap.ts +2 -16
  54. package/src/stream/transform/transformMapSimple.ts +1 -1
  55. package/src/stream/transform/transformMapSync.ts +1 -1
  56. package/src/stream/transform/transformNoOp.ts +16 -0
  57. package/src/stream/transform/transformTap.ts +1 -1
  58. package/src/stream/transform/worker/transformMultiThreaded.ts +4 -5
  59. package/src/string/inspectAny.ts +2 -2
  60. package/src/util/zip.util.ts +8 -0
  61. package/src/validation/ajv/ajv.util.ts +1 -1
  62. package/src/validation/ajv/ajvSchema.ts +1 -1
  63. package/src/validation/joi/joi.extensions.ts +1 -0
  64. package/src/validation/joi/number.extensions.ts +0 -1
  65. package/src/validation/joi/string.extensions.ts +0 -1
package/CHANGELOG.md CHANGED
@@ -1,3 +1,31 @@
1
+ # [12.38.0](https://github.com/NaturalCycles/nodejs-lib/compare/v12.37.0...v12.38.0) (2021-10-06)
2
+
3
+
4
+ ### Features
5
+
6
+ * TransformLogOptions.peakRSS to log peak rss ([4602565](https://github.com/NaturalCycles/nodejs-lib/commit/4602565c8e52d17d8bd975f73e0f2bd6df03cf8b))
7
+
8
+ # [12.37.0](https://github.com/NaturalCycles/nodejs-lib/compare/v12.36.0...v12.37.0) (2021-10-04)
9
+
10
+
11
+ ### Features
12
+
13
+ * cleanup, support only objectMode=true in transformMap ([540b397](https://github.com/NaturalCycles/nodejs-lib/commit/540b3972eaa5d1a630c53af6d0f5af1e4e22b6ba))
14
+
15
+ # [12.36.0](https://github.com/NaturalCycles/nodejs-lib/compare/v12.35.0...v12.36.0) (2021-10-04)
16
+
17
+
18
+ ### Features
19
+
20
+ * transformNoOp ([14e50ec](https://github.com/NaturalCycles/nodejs-lib/commit/14e50ecb78923464b3665e9317837bb78ad6add1))
21
+
22
+ # [12.35.0](https://github.com/NaturalCycles/nodejs-lib/compare/v12.34.0...v12.35.0) (2021-10-01)
23
+
24
+
25
+ ### Features
26
+
27
+ * inspectAny depth defaults to 10 now (was: 6) ([601f0b2](https://github.com/NaturalCycles/nodejs-lib/commit/601f0b29220e84de2feed2b3648313093e6c3f59))
28
+
1
29
  # [12.34.0](https://github.com/NaturalCycles/nodejs-lib/compare/v12.33.4...v12.34.0) (2021-09-10)
2
30
 
3
31
 
package/dist/fs/kpy.js CHANGED
@@ -1,12 +1,12 @@
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
5
  const js_lib_1 = require("@naturalcycles/js-lib");
5
6
  const cpFile = require("cp-file");
6
7
  const fs = require("fs-extra");
7
8
  const globby = require("globby");
8
9
  const moveFile = require("move-file");
9
- const path = require("path");
10
10
  const colors_1 = require("../colors");
11
11
  async function kpy(opt) {
12
12
  const started = Date.now();
package/dist/index.d.ts CHANGED
@@ -36,6 +36,7 @@ import { transformLimit } from './stream/transform/transformLimit';
36
36
  import { transformLogProgress, TransformLogProgressOptions } from './stream/transform/transformLogProgress';
37
37
  import { transformMap, TransformMapOptions } from './stream/transform/transformMap';
38
38
  import { transformMapSimple } from './stream/transform/transformMapSimple';
39
+ import { transformNoOp } from './stream/transform/transformNoOp';
39
40
  import { transformMapSync, TransformMapSyncOptions } from './stream/transform/transformMapSync';
40
41
  import { transformSplit } from './stream/transform/transformSplit';
41
42
  import { transformTap } from './stream/transform/transformTap';
@@ -62,4 +63,4 @@ import { anyObjectSchema, anySchema, arraySchema, binarySchema, booleanDefaultTo
62
63
  import { JoiValidationError, JoiValidationErrorData } from './validation/joi/joi.validation.error';
63
64
  import { convert, getValidationResult, isValid, JoiValidationResult, undefinedIfInvalid, validate } from './validation/joi/joi.validation.util';
64
65
  export type { JoiValidationErrorData, JoiValidationResult, ValidationErrorItem, ExtendedJoi, SchemaTyped, AnySchema, AnySchemaTyped, ArraySchemaTyped, BooleanSchemaTyped, NumberSchemaTyped, ObjectSchemaTyped, StringSchemaTyped, IDebug, IDebugger, SlackServiceCfg, SlackMessage, SlackMessageProps, SlackApiBody, SlackMessagePrefixHook, ReadableTyped, WritableTyped, TransformTyped, PipelineFromNDJsonFileOptions, PipelineToNDJsonFileOptions, TransformJsonParseOptions, TransformToNDJsonOptions, TransformMapOptions, TransformMapSyncOptions, NDJSONStreamForEachOptions, TransformOptions, TransformLogProgressOptions, TransformMultiThreadedOptions, WorkerClassInterface, WorkerInput, WorkerOutput, TableDiffOptions, InspectAnyOptions, Got, GetGotOptions, AfterResponseHook, BeforeErrorHook, BeforeRequestHook, AjvValidationOptions, AjvSchemaCfg, AjvValidationErrorData, };
65
- export { JoiValidationError, validate, getValidationResult, isValid, undefinedIfInvalid, convert, Joi, booleanSchema, booleanDefaultToFalseSchema, stringSchema, numberSchema, integerSchema, percentageSchema, dateStringSchema, arraySchema, binarySchema, objectSchema, anySchema, anyObjectSchema, idSchema, unixTimestampSchema, verSchema, emailSchema, SEM_VER_PATTERN, semVerSchema, userAgentSchema, utcOffsetSchema, ipAddressSchema, slugSchema, urlSchema, processSharedUtil, zipBuffer, gzipBuffer, unzipBuffer, gunzipBuffer, zipString, gzipString, unzipToString, gunzipToString, requireEnvKeys, requireFileToExist, LRUMemoCache, stringId, stringIdAsync, stringIdUnsafe, ALPHABET_NUMBER, ALPHABET_LOWERCASE, ALPHABET_UPPERCASE, ALPHABET_ALPHANUMERIC_LOWERCASE, ALPHABET_ALPHANUMERIC_UPPERCASE, ALPHABET_ALPHANUMERIC, md5, hash, stringToBase64, base64ToString, bufferToBase64, base64ToBuffer, Debug, DebugLogLevel, getSecretMap, setSecretMap, loadSecretsFromEnv, loadSecretsFromJsonFile, removeSecretsFromEnv, secret, secretOptional, memoryUsage, memoryUsageFull, SlackService, slackDefaultMessagePrefixHook, readableCreate, readableFrom, readableFromArray, readableToArray, readableForEach, readableForEachSync, readableMap, readableMapToArray, _pipeline, transformBuffer, ndJsonFileRead, ndJsonFileWrite, ndjsonStreamForEach, pipelineFromNDJsonFile, pipelineToNDJsonFile, NDJsonStats, streamToNDJsonFile, transformJsonParse, bufferReviver, transformToNDJson, transformFilter, transformFilterSync, transformMap, transformMapSync, transformMapSimple, writableForEach, writablePushToArray, transformSplit, transformToString, transformToArray, transformTap, transformLogProgress, transformLimit, writableVoid, writableFork, transformMultiThreaded, BaseWorkerClass, tableDiff, inspectAny, getGot, HTTPError, TimeoutError, _chunkBuffer, Ajv, getAjv, AjvSchema, AjvValidationError, readJsonSchemas, readAjvSchemas, };
66
+ export { JoiValidationError, validate, getValidationResult, isValid, undefinedIfInvalid, convert, Joi, booleanSchema, booleanDefaultToFalseSchema, stringSchema, numberSchema, integerSchema, percentageSchema, dateStringSchema, arraySchema, binarySchema, objectSchema, anySchema, anyObjectSchema, idSchema, unixTimestampSchema, verSchema, emailSchema, SEM_VER_PATTERN, semVerSchema, userAgentSchema, utcOffsetSchema, ipAddressSchema, slugSchema, urlSchema, processSharedUtil, zipBuffer, gzipBuffer, unzipBuffer, gunzipBuffer, zipString, gzipString, unzipToString, gunzipToString, requireEnvKeys, requireFileToExist, LRUMemoCache, stringId, stringIdAsync, stringIdUnsafe, ALPHABET_NUMBER, ALPHABET_LOWERCASE, ALPHABET_UPPERCASE, ALPHABET_ALPHANUMERIC_LOWERCASE, ALPHABET_ALPHANUMERIC_UPPERCASE, ALPHABET_ALPHANUMERIC, md5, hash, stringToBase64, base64ToString, bufferToBase64, base64ToBuffer, Debug, DebugLogLevel, getSecretMap, setSecretMap, loadSecretsFromEnv, loadSecretsFromJsonFile, removeSecretsFromEnv, secret, secretOptional, memoryUsage, memoryUsageFull, SlackService, slackDefaultMessagePrefixHook, readableCreate, readableFrom, readableFromArray, readableToArray, readableForEach, readableForEachSync, readableMap, readableMapToArray, _pipeline, transformBuffer, ndJsonFileRead, ndJsonFileWrite, ndjsonStreamForEach, pipelineFromNDJsonFile, pipelineToNDJsonFile, NDJsonStats, streamToNDJsonFile, transformJsonParse, bufferReviver, transformToNDJson, transformFilter, transformFilterSync, transformMap, transformMapSync, transformMapSimple, transformNoOp, writableForEach, writablePushToArray, transformSplit, transformToString, transformToArray, transformTap, transformLogProgress, transformLimit, writableVoid, writableFork, transformMultiThreaded, BaseWorkerClass, tableDiff, inspectAny, getGot, HTTPError, TimeoutError, _chunkBuffer, Ajv, getAjv, AjvSchema, AjvValidationError, readJsonSchemas, readAjvSchemas, };
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ALPHABET_ALPHANUMERIC_UPPERCASE = exports.ALPHABET_ALPHANUMERIC_LOWERCASE = exports.ALPHABET_UPPERCASE = exports.ALPHABET_LOWERCASE = exports.ALPHABET_NUMBER = exports.stringIdUnsafe = exports.stringIdAsync = exports.stringId = exports.LRUMemoCache = exports.requireFileToExist = exports.requireEnvKeys = exports.gunzipToString = exports.unzipToString = exports.gzipString = exports.zipString = exports.gunzipBuffer = exports.unzipBuffer = exports.gzipBuffer = exports.zipBuffer = exports.processSharedUtil = exports.urlSchema = exports.slugSchema = exports.ipAddressSchema = exports.utcOffsetSchema = exports.userAgentSchema = exports.semVerSchema = exports.SEM_VER_PATTERN = exports.emailSchema = exports.verSchema = exports.unixTimestampSchema = exports.idSchema = exports.anyObjectSchema = exports.anySchema = exports.objectSchema = exports.binarySchema = exports.arraySchema = exports.dateStringSchema = exports.percentageSchema = exports.integerSchema = exports.numberSchema = exports.stringSchema = exports.booleanDefaultToFalseSchema = exports.booleanSchema = exports.Joi = exports.convert = exports.undefinedIfInvalid = exports.isValid = exports.getValidationResult = exports.validate = exports.JoiValidationError = void 0;
4
- exports.transformToArray = exports.transformToString = exports.transformSplit = exports.writablePushToArray = exports.writableForEach = exports.transformMapSimple = exports.transformMapSync = exports.transformMap = exports.transformFilterSync = exports.transformFilter = exports.transformToNDJson = exports.bufferReviver = exports.transformJsonParse = exports.streamToNDJsonFile = exports.NDJsonStats = exports.pipelineToNDJsonFile = exports.pipelineFromNDJsonFile = exports.ndjsonStreamForEach = exports.ndJsonFileWrite = exports.ndJsonFileRead = exports.transformBuffer = exports._pipeline = exports.readableMapToArray = exports.readableMap = exports.readableForEachSync = exports.readableForEach = exports.readableToArray = exports.readableFromArray = exports.readableFrom = exports.readableCreate = exports.slackDefaultMessagePrefixHook = exports.SlackService = exports.memoryUsageFull = exports.memoryUsage = exports.secretOptional = exports.secret = exports.removeSecretsFromEnv = exports.loadSecretsFromJsonFile = exports.loadSecretsFromEnv = exports.setSecretMap = exports.getSecretMap = exports.DebugLogLevel = exports.Debug = exports.base64ToBuffer = exports.bufferToBase64 = exports.base64ToString = exports.stringToBase64 = exports.hash = exports.md5 = exports.ALPHABET_ALPHANUMERIC = void 0;
5
- exports.readAjvSchemas = exports.readJsonSchemas = exports.AjvValidationError = exports.AjvSchema = exports.getAjv = exports.Ajv = exports._chunkBuffer = exports.TimeoutError = exports.HTTPError = exports.getGot = exports.inspectAny = exports.tableDiff = exports.BaseWorkerClass = exports.transformMultiThreaded = exports.writableFork = exports.writableVoid = exports.transformLimit = exports.transformLogProgress = exports.transformTap = void 0;
4
+ exports.transformToString = exports.transformSplit = exports.writablePushToArray = exports.writableForEach = exports.transformNoOp = exports.transformMapSimple = exports.transformMapSync = exports.transformMap = exports.transformFilterSync = exports.transformFilter = exports.transformToNDJson = exports.bufferReviver = exports.transformJsonParse = exports.streamToNDJsonFile = exports.NDJsonStats = exports.pipelineToNDJsonFile = exports.pipelineFromNDJsonFile = exports.ndjsonStreamForEach = exports.ndJsonFileWrite = exports.ndJsonFileRead = exports.transformBuffer = exports._pipeline = exports.readableMapToArray = exports.readableMap = exports.readableForEachSync = exports.readableForEach = exports.readableToArray = exports.readableFromArray = exports.readableFrom = exports.readableCreate = exports.slackDefaultMessagePrefixHook = exports.SlackService = exports.memoryUsageFull = exports.memoryUsage = exports.secretOptional = exports.secret = exports.removeSecretsFromEnv = exports.loadSecretsFromJsonFile = exports.loadSecretsFromEnv = exports.setSecretMap = exports.getSecretMap = exports.DebugLogLevel = exports.Debug = exports.base64ToBuffer = exports.bufferToBase64 = exports.base64ToString = exports.stringToBase64 = exports.hash = exports.md5 = exports.ALPHABET_ALPHANUMERIC = void 0;
5
+ exports.readAjvSchemas = exports.readJsonSchemas = exports.AjvValidationError = exports.AjvSchema = exports.getAjv = exports.Ajv = exports._chunkBuffer = exports.TimeoutError = exports.HTTPError = exports.getGot = exports.inspectAny = exports.tableDiff = exports.BaseWorkerClass = exports.transformMultiThreaded = exports.writableFork = exports.writableVoid = exports.transformLimit = exports.transformLogProgress = exports.transformTap = exports.transformToArray = void 0;
6
6
  const ajv_1 = require("ajv");
7
7
  exports.Ajv = ajv_1.default;
8
8
  const got_1 = require("got");
@@ -97,6 +97,8 @@ const transformMap_1 = require("./stream/transform/transformMap");
97
97
  Object.defineProperty(exports, "transformMap", { enumerable: true, get: function () { return transformMap_1.transformMap; } });
98
98
  const transformMapSimple_1 = require("./stream/transform/transformMapSimple");
99
99
  Object.defineProperty(exports, "transformMapSimple", { enumerable: true, get: function () { return transformMapSimple_1.transformMapSimple; } });
100
+ const transformNoOp_1 = require("./stream/transform/transformNoOp");
101
+ Object.defineProperty(exports, "transformNoOp", { enumerable: true, get: function () { return transformNoOp_1.transformNoOp; } });
100
102
  const transformMapSync_1 = require("./stream/transform/transformMapSync");
101
103
  Object.defineProperty(exports, "transformMapSync", { enumerable: true, get: function () { return transformMapSync_1.transformMapSync; } });
102
104
  const transformSplit_1 = require("./stream/transform/transformSplit");
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.processSharedUtil = exports.memoryUsageFull = exports.memoryUsage = void 0;
4
- const js_lib_1 = require("@naturalcycles/js-lib");
5
4
  const os = require("os");
5
+ const js_lib_1 = require("@naturalcycles/js-lib");
6
6
  /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
7
7
  function memoryUsage() {
8
8
  const { rss, external, heapUsed, heapTotal } = process.memoryUsage();
package/dist/log/debug.js CHANGED
@@ -8,27 +8,28 @@ var DebugLogLevel;
8
8
  DebugLogLevel["warn"] = "warn";
9
9
  DebugLogLevel["error"] = "error";
10
10
  })(DebugLogLevel = exports.DebugLogLevel || (exports.DebugLogLevel = {}));
11
- const OriginalDebug = require('debug');
11
+ const originalDebug = require('debug');
12
+ // eslint-disable-next-line @typescript-eslint/naming-convention
12
13
  exports.Debug = ((namespace) => {
13
- const instance = OriginalDebug(namespace);
14
+ const instance = originalDebug(namespace);
14
15
  instance.log = console.log.bind(console); // this enables colors for objects
15
16
  instance.info = instance.bind(instance);
16
- const instanceDebug = OriginalDebug([namespace, 'debug'].join(':'));
17
+ const instanceDebug = originalDebug([namespace, 'debug'].join(':'));
17
18
  instanceDebug.log = console.debug.bind(console);
18
19
  instance.debug = instanceDebug.bind(instanceDebug);
19
- const instanceWarn = OriginalDebug([namespace, 'warn'].join(':'));
20
+ const instanceWarn = originalDebug([namespace, 'warn'].join(':'));
20
21
  instanceWarn.log = console.warn.bind(console);
21
22
  instance.warn = instanceWarn.bind(instanceWarn);
22
- const instanceError = OriginalDebug([namespace, 'error'].join(':'));
23
+ const instanceError = originalDebug([namespace, 'error'].join(':'));
23
24
  instanceError.log = console.error.bind(console);
24
25
  instance.error = instanceError.bind(instanceError);
25
26
  return instance;
26
27
  });
27
- exports.Debug.coerce = OriginalDebug.coerce.bind(OriginalDebug);
28
- exports.Debug.disable = OriginalDebug.disable.bind(OriginalDebug);
29
- exports.Debug.enable = OriginalDebug.enable.bind(OriginalDebug);
30
- exports.Debug.enabled = OriginalDebug.enabled.bind(OriginalDebug);
31
- exports.Debug.log = OriginalDebug.log.bind(OriginalDebug);
32
- exports.Debug.names = OriginalDebug.names;
33
- exports.Debug.skips = OriginalDebug.skips;
34
- exports.Debug.formatters = OriginalDebug.formatters;
28
+ exports.Debug.coerce = originalDebug.coerce.bind(originalDebug);
29
+ exports.Debug.disable = originalDebug.disable.bind(originalDebug);
30
+ exports.Debug.enable = originalDebug.enable.bind(originalDebug);
31
+ exports.Debug.enabled = originalDebug.enabled.bind(originalDebug);
32
+ exports.Debug.log = originalDebug.log.bind(originalDebug);
33
+ exports.Debug.names = originalDebug.names;
34
+ exports.Debug.skips = originalDebug.skips;
35
+ exports.Debug.formatters = originalDebug.formatters;
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.secretsDecrypt = void 0;
4
+ const path = require("path");
4
5
  const fs = require("fs-extra");
5
6
  const globby = require("globby");
6
- const path = require("path");
7
7
  const colors_1 = require("../colors");
8
8
  const crypto_util_1 = require("../security/crypto.util");
9
9
  /**
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.secretsEncrypt = void 0;
4
+ const path = require("path");
4
5
  const fs = require("fs-extra");
5
6
  const globby = require("globby");
6
- const path = require("path");
7
7
  const colors_1 = require("../colors");
8
8
  const crypto_util_1 = require("../security/crypto.util");
9
9
  /**
@@ -42,6 +42,7 @@ exports.removeSecretsFromEnv = removeSecretsFromEnv;
42
42
  *
43
43
  * If SECRET_ENCRYPTION_KEY argument is passed - will decrypt the contents of the file first, before parsing it as JSON.
44
44
  */
45
+ // eslint-disable-next-line @typescript-eslint/naming-convention
45
46
  function loadSecretsFromJsonFile(filePath, SECRET_ENCRYPTION_KEY) {
46
47
  if (!fs.existsSync(filePath)) {
47
48
  throw new Error(`loadSecretsFromPlainJsonFile() cannot load from path: ${filePath}`);
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ndjsonMap = void 0;
4
- const js_lib_1 = require("@naturalcycles/js-lib");
5
4
  const fs_1 = require("fs");
6
5
  const path = require("path");
7
6
  const zlib_1 = require("zlib");
7
+ const js_lib_1 = require("@naturalcycles/js-lib");
8
8
  const __1 = require("../..");
9
9
  /**
10
10
  * Unzips input file automatically, if it ends with `.gz`.
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ndjsonStreamForEach = void 0;
4
- const js_lib_1 = require("@naturalcycles/js-lib");
5
4
  const fs = require("fs");
6
5
  const zlib_1 = require("zlib");
6
+ const js_lib_1 = require("@naturalcycles/js-lib");
7
7
  const __1 = require("../..");
8
8
  /**
9
9
  * Convenience function to `forEach` through an ndjson file.
@@ -1,11 +1,10 @@
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
5
  const js_lib_1 = require("@naturalcycles/js-lib");
5
6
  const fs = require("fs-extra");
6
- const zlib_1 = require("zlib");
7
7
  const __1 = require("../..");
8
- const __2 = require("../..");
9
8
  const colors_1 = require("../../colors");
10
9
  const ndjson_model_1 = require("./ndjson.model");
11
10
  const transformJsonParse_1 = require("./transformJsonParse");
@@ -21,7 +20,7 @@ async function pipelineFromNDJsonFile(streams, opt) {
21
20
  await (0, __1._pipeline)([
22
21
  fs.createReadStream(filePath),
23
22
  ...(gzip ? [(0, zlib_1.createUnzip)(opt.zlibOptions)] : []),
24
- (0, __2.transformSplit)(separator),
23
+ (0, __1.transformSplit)(separator),
25
24
  (0, transformJsonParse_1.transformJsonParse)(opt),
26
25
  (0, __1.transformTap)(() => rows++),
27
26
  ...streams,
@@ -1,9 +1,9 @@
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
5
  const js_lib_1 = require("@naturalcycles/js-lib");
5
6
  const fs = require("fs-extra");
6
- const zlib_1 = require("zlib");
7
7
  const __1 = require("../..");
8
8
  const colors_1 = require("../../colors");
9
9
  const ndjson_model_1 = require("./ndjson.model");
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.transformToNDJson = void 0;
4
- const js_lib_1 = require("@naturalcycles/js-lib");
5
4
  const stream_1 = require("stream");
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
  */
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
- import { AsyncMapper } from '@naturalcycles/js-lib';
3
2
  import { ReadableOptions } from 'stream';
3
+ import { AsyncMapper } from '@naturalcycles/js-lib';
4
4
  import { ReadableTyped } from '../stream.model';
5
5
  /**
6
6
  * Create Readable from Array.
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.readableFromArray = void 0;
4
- const js_lib_1 = require("@naturalcycles/js-lib");
5
4
  const stream_1 = require("stream");
5
+ const js_lib_1 = require("@naturalcycles/js-lib");
6
6
  /**
7
7
  * Create Readable from Array.
8
8
  * Supports a `mapper` function (async) that you can use to e.g create a timer-emitting-readable.
@@ -24,6 +24,12 @@ export interface TransformLogProgressOptions<IN = any> extends TransformOptions
24
24
  * @default true
25
25
  */
26
26
  rss?: boolean;
27
+ /**
28
+ * Incude Peak RSS in log.
29
+ *
30
+ * @default false
31
+ */
32
+ peakRSS?: boolean;
27
33
  /**
28
34
  * Include `external` in log.
29
35
  *
@@ -50,15 +56,16 @@ export interface TransformLogProgressOptions<IN = any> extends TransformOptions
50
56
  */
51
57
  logRPS?: boolean;
52
58
  /**
53
- * @default true
54
59
  * Set to false to disable logging progress
60
+ *
61
+ * @default true
55
62
  */
56
63
  logProgress?: boolean;
57
64
  /**
58
65
  * Log progress event Nth record that is _processed_ (went through mapper).
66
+ * Set to 0 to disable logging.
59
67
  *
60
68
  * @default 1000
61
- * Set to 0 to disable logging.
62
69
  */
63
70
  logEvery?: number;
64
71
  /**
@@ -1,20 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.transformLogProgress = void 0;
4
- const js_lib_1 = require("@naturalcycles/js-lib");
5
- const time_lib_1 = require("@naturalcycles/time-lib");
6
4
  const stream_1 = require("stream");
7
5
  const util_1 = require("util");
6
+ const js_lib_1 = require("@naturalcycles/js-lib");
7
+ const time_lib_1 = require("@naturalcycles/time-lib");
8
8
  const colors_1 = require("../../colors");
9
9
  const inspectOpt = {
10
10
  colors: true,
11
- breakLength: 200,
11
+ breakLength: 300,
12
12
  };
13
13
  /**
14
14
  * Pass-through transform that optionally logs progress.
15
15
  */
16
16
  function transformLogProgress(opt = {}) {
17
- const { metric = 'progress', heapTotal: logHeapTotal = false, heapUsed: logHeapUsed = true, rss: logRss = true, logRPS = true, logEvery = 1000, extra, } = opt;
17
+ const { metric = 'progress', heapTotal: logHeapTotal = false, heapUsed: logHeapUsed = true, rss: logRss = true, peakRSS: logPeakRSS = false, logRPS = true, logEvery = 1000, extra, } = opt;
18
18
  const logProgress = opt.logProgress !== false && logEvery !== 0; // true by default
19
19
  const logEvery10 = logEvery * 10;
20
20
  const started = Date.now();
@@ -22,6 +22,7 @@ function transformLogProgress(opt = {}) {
22
22
  const sma = new js_lib_1.SimpleMovingAverage(10); // over last 10 seconds
23
23
  let processedLastSecond = 0;
24
24
  let progress = 0;
25
+ let peakRSS = 0;
25
26
  logStats(); // initial
26
27
  return new stream_1.Transform({
27
28
  objectMode: true,
@@ -49,12 +50,15 @@ function transformLogProgress(opt = {}) {
49
50
  lastSecondStarted = now;
50
51
  processedLastSecond = 0;
51
52
  const rps10 = Math.round(sma.push(lastRPS));
53
+ if (mem.rss > peakRSS)
54
+ peakRSS = mem.rss;
52
55
  console.log((0, util_1.inspect)({
53
56
  [final ? `${metric}_final` : metric]: progress,
54
57
  ...(extra ? extra(chunk, progress) : {}),
55
58
  ...(logHeapUsed ? { heapUsed: (0, js_lib_1._mb)(mem.heapUsed) } : {}),
56
59
  ...(logHeapTotal ? { heapTotal: (0, js_lib_1._mb)(mem.heapTotal) } : {}),
57
60
  ...(logRss ? { rss: (0, js_lib_1._mb)(mem.rss) } : {}),
61
+ ...(logPeakRSS ? { peakRSS: (0, js_lib_1._mb)(peakRSS) } : {}),
58
62
  ...(opt.rssMinusHeap ? { rssMinusHeap: (0, js_lib_1._mb)(mem.rss - mem.heapTotal) } : {}),
59
63
  ...(opt.external ? { external: (0, js_lib_1._mb)(mem.external) } : {}),
60
64
  ...(opt.arrayBuffers ? { arrayBuffers: (0, js_lib_1._mb)(mem.arrayBuffers || 0) } : {}),
@@ -1,10 +1,6 @@
1
1
  import { AsyncMapper, AsyncPredicate, ErrorMode } from '@naturalcycles/js-lib';
2
2
  import { TransformTyped } from '../stream.model';
3
3
  export interface TransformMapOptions<IN = any, OUT = IN> {
4
- /**
5
- * @default true
6
- */
7
- objectMode?: boolean;
8
4
  /**
9
5
  * @default false
10
6
  * Set true to support "multiMap" - possibility to return [] and emit 1 result for each item in the array.
@@ -44,10 +40,6 @@ export interface TransformMapOptions<IN = any, OUT = IN> {
44
40
  * If defined - called BEFORE `final()` callback is called.
45
41
  */
46
42
  beforeFinal?: () => any;
47
- /**
48
- * If defined - called AFTER final chunk was processed.
49
- */
50
- afterFinal?: () => any;
51
43
  }
52
44
  export declare function notNullishPredicate(item: any): boolean;
53
45
  /**
@@ -21,12 +21,12 @@ exports.notNullishPredicate = notNullishPredicate;
21
21
  * If an Array is returned by `mapper` - it will be flattened and multiple results will be emitted from it. Tested by Array.isArray().
22
22
  */
23
23
  function transformMap(mapper, opt = {}) {
24
- const { concurrency = 16, predicate = notNullishPredicate, errorMode = js_lib_1.ErrorMode.THROW_IMMEDIATELY, flattenArrayOutput, onError, beforeFinal, afterFinal, metric = 'stream', objectMode = true, } = opt;
24
+ const { concurrency = 16, predicate = notNullishPredicate, errorMode = js_lib_1.ErrorMode.THROW_IMMEDIATELY, flattenArrayOutput, onError, beforeFinal, metric = 'stream', } = opt;
25
25
  let index = -1;
26
26
  let isRejected = false;
27
27
  let errors = 0;
28
28
  const collectedErrors = []; // only used if errorMode == THROW_AGGREGATED
29
- return (objectMode ? through2Concurrent.obj : through2Concurrent)({
29
+ return through2Concurrent.obj({
30
30
  maxConcurrency: concurrency,
31
31
  // autoDestroy: true,
32
32
  async final(cb) {
@@ -41,7 +41,6 @@ function transformMap(mapper, opt = {}) {
41
41
  // emit no error
42
42
  cb();
43
43
  }
44
- afterFinal?.(); // call afterFinal if defined (optional invokation operator)
45
44
  },
46
45
  }, async function transformMapFn(chunk, _encoding, cb) {
47
46
  index++;
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.transformMapSimple = void 0;
4
- const js_lib_1 = require("@naturalcycles/js-lib");
5
4
  const stream_1 = require("stream");
5
+ const js_lib_1 = require("@naturalcycles/js-lib");
6
6
  /**
7
7
  * Simplest version of `transformMap`.
8
8
  * errorMode: IMMEDIATE
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.transformMapSync = void 0;
4
- const js_lib_1 = require("@naturalcycles/js-lib");
5
4
  const stream_1 = require("stream");
5
+ const js_lib_1 = require("@naturalcycles/js-lib");
6
6
  const colors_1 = require("../../colors");
7
7
  const transformMap_1 = require("./transformMap");
8
8
  /**
@@ -0,0 +1,7 @@
1
+ import { TransformTyped } from '../stream.model';
2
+ /**
3
+ * Transform that does nothing (pass the data through).
4
+ * Can be used e.g to convert "not-valid" stream (e.g one that `transformMap` is producing)
5
+ * into a "valid" stream (that implements async-iteration interface).
6
+ */
7
+ export declare function transformNoOp<T = any>(): TransformTyped<T, T>;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.transformNoOp = void 0;
4
+ const stream_1 = require("stream");
5
+ /**
6
+ * Transform that does nothing (pass the data through).
7
+ * Can be used e.g to convert "not-valid" stream (e.g one that `transformMap` is producing)
8
+ * into a "valid" stream (that implements async-iteration interface).
9
+ */
10
+ function transformNoOp() {
11
+ return new stream_1.Transform({
12
+ objectMode: true,
13
+ transform(chunk, _encoding, cb) {
14
+ cb(null, chunk);
15
+ },
16
+ });
17
+ }
18
+ exports.transformNoOp = transformNoOp;
@@ -1,5 +1,5 @@
1
- import { TransformOptions, TransformTyped } from '../../stream.model';
2
- export interface TransformMultiThreadedOptions extends TransformOptions {
1
+ import { TransformTyped } from '../../stream.model';
2
+ export interface TransformMultiThreadedOptions {
3
3
  /**
4
4
  * Absolute path to a js file with worker code
5
5
  */
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.transformMultiThreaded = void 0;
4
+ const worker_threads_1 = require("worker_threads");
4
5
  const js_lib_1 = require("@naturalcycles/js-lib");
5
6
  const through2Concurrent = require("through2-concurrent");
6
- const worker_threads_1 = require("worker_threads");
7
7
  const workerProxyFilePath = `${__dirname}/workerClassProxy.js`;
8
8
  /**
9
9
  * Spawns a pool of Workers (threads).
@@ -15,7 +15,6 @@ function transformMultiThreaded(opt) {
15
15
  const { workerFile, poolSize = 2, workerData } = opt;
16
16
  const maxConcurrency = opt.concurrency || poolSize;
17
17
  const highWaterMark = Math.max(16, maxConcurrency);
18
- const objectMode = opt.objectMode !== false; // default true
19
18
  console.log({
20
19
  poolSize,
21
20
  maxConcurrency,
@@ -56,7 +55,7 @@ function transformMultiThreaded(opt) {
56
55
  });
57
56
  return worker;
58
57
  });
59
- return (objectMode ? through2Concurrent.obj : through2Concurrent)({
58
+ return through2Concurrent.obj({
60
59
  maxConcurrency,
61
60
  highWaterMark,
62
61
  async final(cb) {
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
- import { StringifyAnyOptions } from '@naturalcycles/js-lib';
3
2
  import { InspectOptions } from 'util';
3
+ import { StringifyAnyOptions } from '@naturalcycles/js-lib';
4
4
  export interface InspectAnyOptions extends StringifyAnyOptions, InspectOptions {
5
5
  }
6
6
  /**
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.inspectAny = void 0;
4
- const js_lib_1 = require("@naturalcycles/js-lib");
5
4
  const util_1 = require("util");
5
+ const js_lib_1 = require("@naturalcycles/js-lib");
6
6
  const INSPECT_OPT = {
7
7
  breakLength: 80,
8
- depth: 6, // default: 2
8
+ depth: 10, // default: 2
9
9
  };
10
10
  /**
11
11
  * Transforms ANY to human-readable string (via util.inspect mainly).
@@ -1,6 +1,14 @@
1
1
  /// <reference types="node" />
2
2
  import { ZlibOptions } from 'zlib';
3
+ /**
4
+ * zipBuffer uses `deflate`.
5
+ * It's 9 bytes shorter than gzip.
6
+ */
3
7
  export declare function zipBuffer(buf: Buffer, options?: ZlibOptions): Promise<Buffer>;
8
+ /**
9
+ * gzipBuffer uses `gzip`
10
+ * It's 9 bytes longer than deflate.
11
+ */
4
12
  export declare function gzipBuffer(buf: Buffer, options?: ZlibOptions): Promise<Buffer>;
5
13
  export declare function unzipBuffer(buf: Buffer, options?: ZlibOptions): Promise<Buffer>;
6
14
  export declare function gunzipBuffer(buf: Buffer, options?: ZlibOptions): Promise<Buffer>;
@@ -8,10 +8,18 @@ const inflate = (0, util_1.promisify)(zlib.inflate.bind(zlib));
8
8
  const gzip = (0, util_1.promisify)(zlib.gzip.bind(zlib));
9
9
  const gunzip = (0, util_1.promisify)(zlib.gunzip.bind(zlib));
10
10
  // string > zip
11
+ /**
12
+ * zipBuffer uses `deflate`.
13
+ * It's 9 bytes shorter than gzip.
14
+ */
11
15
  async function zipBuffer(buf, options = {}) {
12
16
  return await deflate(buf, options);
13
17
  }
14
18
  exports.zipBuffer = zipBuffer;
19
+ /**
20
+ * gzipBuffer uses `gzip`
21
+ * It's 9 bytes longer than deflate.
22
+ */
15
23
  async function gzipBuffer(buf, options = {}) {
16
24
  return await gzip(buf, options);
17
25
  }
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AjvSchema = void 0;
4
- const js_lib_1 = require("@naturalcycles/js-lib");
5
4
  const fs = require("fs");
5
+ const js_lib_1 = require("@naturalcycles/js-lib");
6
6
  const index_1 = require("../../index");
7
7
  const ajvValidationError_1 = require("./ajvValidationError");
8
8
  const getAjv_1 = require("./getAjv");
@@ -7,6 +7,7 @@ const string_extensions_1 = require("./string.extensions");
7
7
  /**
8
8
  * This is the only right place to import Joi from
9
9
  */
10
+ // eslint-disable-next-line @typescript-eslint/naming-convention
10
11
  exports.Joi = JoiLib.defaults(schema => {
11
12
  // hack to prevent infinite recursion due to .empty('') where '' is a stringSchema itself
12
13
  if (schema.type === 'string') {
@@ -16,7 +16,6 @@ function numberExtensions(joi) {
16
16
  dividable: {
17
17
  multi: true,
18
18
  method(q) {
19
- // tslint:disable-next-line:no-invalid-this
20
19
  return this.$_addRule({
21
20
  name: 'dividable',
22
21
  args: { q },
@@ -15,7 +15,6 @@ function stringExtensions(joi) {
15
15
  rules: {
16
16
  dateString: {
17
17
  method(min, max) {
18
- // tslint:disable-next-line:no-invalid-this
19
18
  return this.$_addRule({
20
19
  name: 'dateString',
21
20
  args: { min, max },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/nodejs-lib",
3
- "version": "12.34.0",
3
+ "version": "12.38.0",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "docs-serve": "vuepress dev docs",
package/src/fs/kpy.ts CHANGED
@@ -1,9 +1,9 @@
1
+ import * as path from 'path'
1
2
  import { _since } from '@naturalcycles/js-lib'
2
3
  import * as cpFile from 'cp-file'
3
4
  import * as fs from 'fs-extra'
4
5
  import * as globby from 'globby'
5
6
  import * as moveFile from 'move-file'
6
- import * as path from 'path'
7
7
  import { boldWhite, dimGrey, grey, yellow } from '../colors'
8
8
 
9
9
  /**
package/src/got/getGot.ts CHANGED
@@ -1,6 +1,6 @@
1
+ import { URL } from 'url'
1
2
  import { _jsonParseIfPossible, _since } from '@naturalcycles/js-lib'
2
3
  import got, { AfterResponseHook, BeforeErrorHook, BeforeRequestHook, Got, HTTPError } from 'got'
3
- import { URL } from 'url'
4
4
  import { inspectAny } from '..'
5
5
  import { dimGrey, grey, red, yellow } from '../colors'
6
6
  import { GetGotOptions, GotRequestContext } from './got.model'
package/src/index.ts CHANGED
@@ -88,6 +88,7 @@ import {
88
88
  } from './stream/transform/transformLogProgress'
89
89
  import { transformMap, TransformMapOptions } from './stream/transform/transformMap'
90
90
  import { transformMapSimple } from './stream/transform/transformMapSimple'
91
+ import { transformNoOp } from './stream/transform/transformNoOp'
91
92
  import { transformMapSync, TransformMapSyncOptions } from './stream/transform/transformMapSync'
92
93
  import { transformSplit } from './stream/transform/transformSplit'
93
94
  import { transformTap } from './stream/transform/transformTap'
@@ -309,6 +310,7 @@ export {
309
310
  transformMap,
310
311
  transformMapSync,
311
312
  transformMapSimple,
313
+ transformNoOp,
312
314
  writableForEach,
313
315
  writablePushToArray,
314
316
  transformSplit,
@@ -1,5 +1,5 @@
1
- import { _mb } from '@naturalcycles/js-lib'
2
1
  import * as os from 'os'
2
+ import { _mb } from '@naturalcycles/js-lib'
3
3
 
4
4
  /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
5
5
 
package/src/log/debug.ts CHANGED
@@ -40,32 +40,33 @@ export enum DebugLogLevel {
40
40
  error = 'error',
41
41
  }
42
42
 
43
- const OriginalDebug = require('debug') as IDebug
43
+ const originalDebug = require('debug') as IDebug
44
44
 
45
+ // eslint-disable-next-line @typescript-eslint/naming-convention
45
46
  export const Debug = ((namespace: string) => {
46
- const instance = OriginalDebug(namespace)
47
+ const instance = originalDebug(namespace)
47
48
  instance.log = console.log.bind(console) // this enables colors for objects
48
49
  instance.info = instance.bind(instance)
49
50
 
50
- const instanceDebug = OriginalDebug([namespace, 'debug'].join(':'))
51
+ const instanceDebug = originalDebug([namespace, 'debug'].join(':'))
51
52
  instanceDebug.log = console.debug.bind(console)
52
53
  instance.debug = instanceDebug.bind(instanceDebug)
53
54
 
54
- const instanceWarn = OriginalDebug([namespace, 'warn'].join(':'))
55
+ const instanceWarn = originalDebug([namespace, 'warn'].join(':'))
55
56
  instanceWarn.log = console.warn.bind(console)
56
57
  instance.warn = instanceWarn.bind(instanceWarn)
57
58
 
58
- const instanceError = OriginalDebug([namespace, 'error'].join(':'))
59
+ const instanceError = originalDebug([namespace, 'error'].join(':'))
59
60
  instanceError.log = console.error.bind(console)
60
61
  instance.error = instanceError.bind(instanceError)
61
62
 
62
63
  return instance
63
64
  }) as IDebug
64
- Debug.coerce = OriginalDebug.coerce.bind(OriginalDebug)
65
- Debug.disable = OriginalDebug.disable.bind(OriginalDebug)
66
- Debug.enable = OriginalDebug.enable.bind(OriginalDebug)
67
- Debug.enabled = OriginalDebug.enabled.bind(OriginalDebug)
68
- Debug.log = OriginalDebug.log.bind(OriginalDebug)
69
- Debug.names = OriginalDebug.names
70
- Debug.skips = OriginalDebug.skips
71
- Debug.formatters = OriginalDebug.formatters
65
+ Debug.coerce = originalDebug.coerce.bind(originalDebug)
66
+ Debug.disable = originalDebug.disable.bind(originalDebug)
67
+ Debug.enable = originalDebug.enable.bind(originalDebug)
68
+ Debug.enabled = originalDebug.enabled.bind(originalDebug)
69
+ Debug.log = originalDebug.log.bind(originalDebug)
70
+ Debug.names = originalDebug.names
71
+ Debug.skips = originalDebug.skips
72
+ Debug.formatters = originalDebug.formatters
@@ -1,6 +1,6 @@
1
+ import * as path from 'path'
1
2
  import * as fs from 'fs-extra'
2
3
  import globby = require('globby')
3
- import * as path from 'path'
4
4
  import { dimGrey, yellow } from '../colors'
5
5
  import { decryptRandomIVBuffer } from '../security/crypto.util'
6
6
 
@@ -1,6 +1,6 @@
1
+ import * as path from 'path'
1
2
  import * as fs from 'fs-extra'
2
3
  import globby = require('globby')
3
- import * as path from 'path'
4
4
  import { dimGrey, yellow } from '../colors'
5
5
  import { encryptRandomIVBuffer } from '../security/crypto.util'
6
6
 
@@ -1,5 +1,5 @@
1
- import { StringMap } from '@naturalcycles/js-lib'
2
1
  import * as fs from 'fs'
2
+ import { StringMap } from '@naturalcycles/js-lib'
3
3
  import { base64ToString, Debug } from '..'
4
4
  import { decryptRandomIVBuffer } from './crypto.util'
5
5
 
@@ -50,6 +50,7 @@ export function removeSecretsFromEnv(): void {
50
50
  *
51
51
  * If SECRET_ENCRYPTION_KEY argument is passed - will decrypt the contents of the file first, before parsing it as JSON.
52
52
  */
53
+ // eslint-disable-next-line @typescript-eslint/naming-convention
53
54
  export function loadSecretsFromJsonFile(filePath: string, SECRET_ENCRYPTION_KEY?: string): void {
54
55
  if (!fs.existsSync(filePath)) {
55
56
  throw new Error(`loadSecretsFromPlainJsonFile() cannot load from path: ${filePath}`)
@@ -1,7 +1,7 @@
1
- import { AsyncMapper, ErrorMode } from '@naturalcycles/js-lib'
2
1
  import { createReadStream, createWriteStream } from 'fs'
3
2
  import * as path from 'path'
4
3
  import { createGzip, createUnzip } from 'zlib'
4
+ import { AsyncMapper, ErrorMode } from '@naturalcycles/js-lib'
5
5
  import {
6
6
  requireFileToExist,
7
7
  transformJsonParse,
@@ -1,6 +1,6 @@
1
- import { AsyncMapper, ErrorMode } from '@naturalcycles/js-lib'
2
1
  import * as fs from 'fs'
3
2
  import { createUnzip } from 'zlib'
3
+ import { AsyncMapper, ErrorMode } from '@naturalcycles/js-lib'
4
4
  import {
5
5
  requireFileToExist,
6
6
  transformJsonParse,
@@ -1,8 +1,7 @@
1
+ import { createUnzip, ZlibOptions } from 'zlib'
1
2
  import { _hb } from '@naturalcycles/js-lib'
2
3
  import * as fs from 'fs-extra'
3
- import { createUnzip, ZlibOptions } from 'zlib'
4
- import { transformTap, _pipeline } from '../..'
5
- import { transformSplit } from '../..'
4
+ import { transformTap, _pipeline, transformSplit } from '../..'
6
5
  import { dimWhite, grey } from '../../colors'
7
6
  import { NDJsonStats } from './ndjson.model'
8
7
  import { transformJsonParse, TransformJsonParseOptions } from './transformJsonParse'
@@ -1,6 +1,6 @@
1
+ import { createGzip, ZlibOptions } from 'zlib'
1
2
  import { AppError } from '@naturalcycles/js-lib'
2
3
  import * as fs from 'fs-extra'
3
- import { createGzip, ZlibOptions } from 'zlib'
4
4
  import { transformTap, _pipeline } from '../..'
5
5
  import { grey } from '../../colors'
6
6
  import { NDJsonStats } from './ndjson.model'
@@ -1,5 +1,5 @@
1
- import { Reviver } from '@naturalcycles/js-lib'
2
1
  import { Transform } from 'stream'
2
+ import { Reviver } from '@naturalcycles/js-lib'
3
3
  import { TransformTyped } from '../stream.model'
4
4
 
5
5
  export interface TransformJsonParseOptions {
@@ -1,5 +1,5 @@
1
- import { _sortObjectDeep } from '@naturalcycles/js-lib'
2
1
  import { Transform } from 'stream'
2
+ import { _sortObjectDeep } from '@naturalcycles/js-lib'
3
3
  import { TransformTyped } from '../stream.model'
4
4
 
5
5
  export interface TransformToNDJsonOptions {
@@ -1,5 +1,5 @@
1
- import { AsyncMapper, pMap, _passthroughMapper } from '@naturalcycles/js-lib'
2
1
  import { Readable, ReadableOptions } from 'stream'
2
+ import { AsyncMapper, pMap, _passthroughMapper } from '@naturalcycles/js-lib'
3
3
  import { ReadableTyped } from '../stream.model'
4
4
 
5
5
  /**
@@ -1,5 +1,5 @@
1
- import { AsyncPredicate, Predicate } from '@naturalcycles/js-lib'
2
1
  import { Transform } from 'stream'
2
+ import { AsyncPredicate, Predicate } from '@naturalcycles/js-lib'
3
3
  import { TransformOptions, TransformTyped } from '../stream.model'
4
4
 
5
5
  /**
@@ -1,7 +1,7 @@
1
- import { SimpleMovingAverage, _mb, _since } from '@naturalcycles/js-lib'
2
- import { dayjs } from '@naturalcycles/time-lib'
3
1
  import { Transform } from 'stream'
4
2
  import { inspect, InspectOptions } from 'util'
3
+ import { SimpleMovingAverage, _mb, _since } from '@naturalcycles/js-lib'
4
+ import { dayjs } from '@naturalcycles/time-lib'
5
5
  import { boldWhite, dimGrey, white, yellow } from '../../colors'
6
6
  import { TransformOptions, TransformTyped } from '../stream.model'
7
7
 
@@ -34,6 +34,13 @@ export interface TransformLogProgressOptions<IN = any> extends TransformOptions
34
34
  */
35
35
  rss?: boolean
36
36
 
37
+ /**
38
+ * Incude Peak RSS in log.
39
+ *
40
+ * @default false
41
+ */
42
+ peakRSS?: boolean
43
+
37
44
  /**
38
45
  * Include `external` in log.
39
46
  *
@@ -64,16 +71,17 @@ export interface TransformLogProgressOptions<IN = any> extends TransformOptions
64
71
  logRPS?: boolean
65
72
 
66
73
  /**
67
- * @default true
68
74
  * Set to false to disable logging progress
75
+ *
76
+ * @default true
69
77
  */
70
78
  logProgress?: boolean
71
79
 
72
80
  /**
73
81
  * Log progress event Nth record that is _processed_ (went through mapper).
82
+ * Set to 0 to disable logging.
74
83
  *
75
84
  * @default 1000
76
- * Set to 0 to disable logging.
77
85
  */
78
86
  logEvery?: number
79
87
 
@@ -87,7 +95,7 @@ export interface TransformLogProgressOptions<IN = any> extends TransformOptions
87
95
 
88
96
  const inspectOpt: InspectOptions = {
89
97
  colors: true,
90
- breakLength: 200,
98
+ breakLength: 300,
91
99
  }
92
100
 
93
101
  /**
@@ -101,6 +109,7 @@ export function transformLogProgress<IN = any>(
101
109
  heapTotal: logHeapTotal = false,
102
110
  heapUsed: logHeapUsed = true,
103
111
  rss: logRss = true,
112
+ peakRSS: logPeakRSS = false,
104
113
  logRPS = true,
105
114
  logEvery = 1000,
106
115
  extra,
@@ -113,6 +122,7 @@ export function transformLogProgress<IN = any>(
113
122
  const sma = new SimpleMovingAverage(10) // over last 10 seconds
114
123
  let processedLastSecond = 0
115
124
  let progress = 0
125
+ let peakRSS = 0
116
126
 
117
127
  logStats() // initial
118
128
 
@@ -138,6 +148,7 @@ export function transformLogProgress<IN = any>(
138
148
 
139
149
  function logStats(chunk?: IN, final = false, tenx = false): void {
140
150
  if (!logProgress) return
151
+
141
152
  const mem = process.memoryUsage()
142
153
 
143
154
  const now = Date.now()
@@ -147,6 +158,7 @@ export function transformLogProgress<IN = any>(
147
158
  processedLastSecond = 0
148
159
 
149
160
  const rps10 = Math.round(sma.push(lastRPS))
161
+ if (mem.rss > peakRSS) peakRSS = mem.rss
150
162
 
151
163
  console.log(
152
164
  inspect(
@@ -156,6 +168,7 @@ export function transformLogProgress<IN = any>(
156
168
  ...(logHeapUsed ? { heapUsed: _mb(mem.heapUsed) } : {}),
157
169
  ...(logHeapTotal ? { heapTotal: _mb(mem.heapTotal) } : {}),
158
170
  ...(logRss ? { rss: _mb(mem.rss) } : {}),
171
+ ...(logPeakRSS ? { peakRSS: _mb(peakRSS) } : {}),
159
172
  ...(opt.rssMinusHeap ? { rssMinusHeap: _mb(mem.rss - mem.heapTotal) } : {}),
160
173
  ...(opt.external ? { external: _mb(mem.external) } : {}),
161
174
  ...(opt.arrayBuffers ? { arrayBuffers: _mb(mem.arrayBuffers || 0) } : {}),
@@ -1,3 +1,4 @@
1
+ import { Transform } from 'stream'
1
2
  import {
2
3
  AggregatedError,
3
4
  AsyncMapper,
@@ -5,17 +6,11 @@ import {
5
6
  ErrorMode,
6
7
  pFilter,
7
8
  } from '@naturalcycles/js-lib'
8
- import { Transform } from 'stream'
9
9
  import through2Concurrent = require('through2-concurrent')
10
10
  import { yellow } from '../../colors'
11
11
  import { TransformTyped } from '../stream.model'
12
12
 
13
13
  export interface TransformMapOptions<IN = any, OUT = IN> {
14
- /**
15
- * @default true
16
- */
17
- objectMode?: boolean
18
-
19
14
  /**
20
15
  * @default false
21
16
  * Set true to support "multiMap" - possibility to return [] and emit 1 result for each item in the array.
@@ -61,11 +56,6 @@ export interface TransformMapOptions<IN = any, OUT = IN> {
61
56
  * If defined - called BEFORE `final()` callback is called.
62
57
  */
63
58
  beforeFinal?: () => any
64
-
65
- /**
66
- * If defined - called AFTER final chunk was processed.
67
- */
68
- afterFinal?: () => any
69
59
  }
70
60
 
71
61
  export function notNullishPredicate(item: any): boolean {
@@ -95,9 +85,7 @@ export function transformMap<IN = any, OUT = IN>(
95
85
  flattenArrayOutput,
96
86
  onError,
97
87
  beforeFinal,
98
- afterFinal,
99
88
  metric = 'stream',
100
- objectMode = true,
101
89
  } = opt
102
90
 
103
91
  let index = -1
@@ -105,7 +93,7 @@ export function transformMap<IN = any, OUT = IN>(
105
93
  let errors = 0
106
94
  const collectedErrors: Error[] = [] // only used if errorMode == THROW_AGGREGATED
107
95
 
108
- return (objectMode ? through2Concurrent.obj : through2Concurrent)(
96
+ return through2Concurrent.obj(
109
97
  {
110
98
  maxConcurrency: concurrency,
111
99
  // autoDestroy: true,
@@ -123,8 +111,6 @@ export function transformMap<IN = any, OUT = IN>(
123
111
  // emit no error
124
112
  cb()
125
113
  }
126
-
127
- afterFinal?.() // call afterFinal if defined (optional invokation operator)
128
114
  },
129
115
  },
130
116
  async function transformMapFn(
@@ -1,5 +1,5 @@
1
- import { ErrorMode, Mapper } from '@naturalcycles/js-lib'
2
1
  import { Transform } from 'stream'
2
+ import { ErrorMode, Mapper } from '@naturalcycles/js-lib'
3
3
  import { TransformTyped } from '../stream.model'
4
4
 
5
5
  export interface TransformMapSimpleOptions {
@@ -1,5 +1,5 @@
1
- import { AggregatedError, ErrorMode, Mapper, Predicate } from '@naturalcycles/js-lib'
2
1
  import { Transform } from 'stream'
2
+ import { AggregatedError, ErrorMode, Mapper, Predicate } from '@naturalcycles/js-lib'
3
3
  import { yellow } from '../../colors'
4
4
  import { TransformTyped } from '../stream.model'
5
5
  import { notNullishPredicate } from './transformMap'
@@ -0,0 +1,16 @@
1
+ import { Transform } from 'stream'
2
+ import { TransformTyped } from '../stream.model'
3
+
4
+ /**
5
+ * Transform that does nothing (pass the data through).
6
+ * Can be used e.g to convert "not-valid" stream (e.g one that `transformMap` is producing)
7
+ * into a "valid" stream (that implements async-iteration interface).
8
+ */
9
+ export function transformNoOp<T = any>(): TransformTyped<T, T> {
10
+ return new Transform({
11
+ objectMode: true,
12
+ transform(chunk: T, _encoding, cb) {
13
+ cb(null, chunk)
14
+ },
15
+ })
16
+ }
@@ -1,5 +1,5 @@
1
- import { AsyncMapper } from '@naturalcycles/js-lib'
2
1
  import { Transform } from 'stream'
2
+ import { AsyncMapper } from '@naturalcycles/js-lib'
3
3
  import { TransformOptions, TransformTyped } from '../stream.model'
4
4
 
5
5
  /**
@@ -1,12 +1,12 @@
1
+ import { Worker } from 'worker_threads'
1
2
  import { DeferredPromise, pDefer, _range } from '@naturalcycles/js-lib'
2
3
  import through2Concurrent = require('through2-concurrent')
3
- import { Worker } from 'worker_threads'
4
- import { TransformOptions, TransformTyped } from '../../stream.model'
4
+ import { TransformTyped } from '../../stream.model'
5
5
  import { WorkerInput, WorkerOutput } from './transformMultiThreaded.model'
6
6
 
7
7
  /* eslint-disable unicorn/require-post-message-target-origin */
8
8
 
9
- export interface TransformMultiThreadedOptions extends TransformOptions {
9
+ export interface TransformMultiThreadedOptions {
10
10
  /**
11
11
  * Absolute path to a js file with worker code
12
12
  */
@@ -47,7 +47,6 @@ export function transformMultiThreaded<IN, OUT>(
47
47
  const { workerFile, poolSize = 2, workerData } = opt
48
48
  const maxConcurrency = opt.concurrency || poolSize
49
49
  const highWaterMark = Math.max(16, maxConcurrency)
50
- const objectMode = opt.objectMode !== false // default true
51
50
 
52
51
  console.log({
53
52
  poolSize,
@@ -97,7 +96,7 @@ export function transformMultiThreaded<IN, OUT>(
97
96
  return worker
98
97
  })
99
98
 
100
- return (objectMode ? through2Concurrent.obj : through2Concurrent)(
99
+ return through2Concurrent.obj(
101
100
  {
102
101
  maxConcurrency,
103
102
  highWaterMark,
@@ -1,11 +1,11 @@
1
- import { StringifyAnyOptions, _stringifyAny } from '@naturalcycles/js-lib'
2
1
  import { inspect, InspectOptions } from 'util'
2
+ import { StringifyAnyOptions, _stringifyAny } from '@naturalcycles/js-lib'
3
3
 
4
4
  export interface InspectAnyOptions extends StringifyAnyOptions, InspectOptions {}
5
5
 
6
6
  const INSPECT_OPT: InspectOptions = {
7
7
  breakLength: 80, // default: ??
8
- depth: 6, // default: 2
8
+ depth: 10, // default: 2
9
9
  }
10
10
 
11
11
  /**
@@ -8,10 +8,18 @@ const gzip = promisify(zlib.gzip.bind(zlib))
8
8
  const gunzip = promisify(zlib.gunzip.bind(zlib))
9
9
 
10
10
  // string > zip
11
+ /**
12
+ * zipBuffer uses `deflate`.
13
+ * It's 9 bytes shorter than gzip.
14
+ */
11
15
  export async function zipBuffer(buf: Buffer, options: ZlibOptions = {}): Promise<Buffer> {
12
16
  return await deflate(buf, options)
13
17
  }
14
18
 
19
+ /**
20
+ * gzipBuffer uses `gzip`
21
+ * It's 9 bytes longer than deflate.
22
+ */
15
23
  export async function gzipBuffer(buf: Buffer, options: ZlibOptions = {}): Promise<Buffer> {
16
24
  return await gzip(buf, options)
17
25
  }
@@ -1,5 +1,5 @@
1
- import { JsonSchema } from '@naturalcycles/js-lib'
2
1
  import * as fs from 'fs'
2
+ import { JsonSchema } from '@naturalcycles/js-lib'
3
3
  import { GlobbyOptions } from 'globby'
4
4
  import * as globby from 'globby'
5
5
  import { AjvSchema, AjvSchemaCfg } from './ajvSchema'
@@ -1,3 +1,4 @@
1
+ import * as fs from 'fs'
1
2
  import {
2
3
  JsonSchema,
3
4
  JsonSchemaAnyBuilder,
@@ -7,7 +8,6 @@ import {
7
8
  _substringBefore,
8
9
  } from '@naturalcycles/js-lib'
9
10
  import Ajv, { ValidateFunction } from 'ajv'
10
- import * as fs from 'fs'
11
11
  import { inspectAny, requireFileToExist } from '../../index'
12
12
  import { AjvValidationError } from './ajvValidationError'
13
13
  import { getAjv } from './getAjv'
@@ -13,6 +13,7 @@ export interface ExtendedJoi extends JoiLib.Root {
13
13
  /**
14
14
  * This is the only right place to import Joi from
15
15
  */
16
+ // eslint-disable-next-line @typescript-eslint/naming-convention
16
17
  export const Joi: ExtendedJoi = JoiLib.defaults(schema => {
17
18
  // hack to prevent infinite recursion due to .empty('') where '' is a stringSchema itself
18
19
  if (schema.type === 'string') {
@@ -21,7 +21,6 @@ export function numberExtensions(joi: typeof Joi): Extension {
21
21
  dividable: {
22
22
  multi: true,
23
23
  method(q: number) {
24
- // tslint:disable-next-line:no-invalid-this
25
24
  return this.$_addRule({
26
25
  name: 'dividable',
27
26
  args: { q },
@@ -25,7 +25,6 @@ export function stringExtensions(joi: typeof Joi): Extension {
25
25
  rules: {
26
26
  dateString: {
27
27
  method(min?: string, max?: string) {
28
- // tslint:disable-next-line:no-invalid-this
29
28
  return this.$_addRule({
30
29
  name: 'dateString',
31
30
  args: { min, max } as DateStringParams,