@naturalcycles/nodejs-lib 13.44.0 → 13.45.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/dist/bin/generate-build-info.js +7 -7
  2. package/dist/bin/json2env.js +2 -2
  3. package/dist/bin/kpy.js +2 -2
  4. package/dist/bin/secrets-decrypt.js +2 -2
  5. package/dist/bin/secrets-encrypt.js +2 -2
  6. package/dist/bin/secrets-gen-key.js +4 -4
  7. package/dist/bin/slack-this.js +2 -2
  8. package/dist/colors/colors.js +2 -2
  9. package/dist/csv/csvReader.d.ts +1 -1
  10. package/dist/csv/csvWriter.d.ts +1 -1
  11. package/dist/csv/transformToCSV.d.ts +3 -3
  12. package/dist/diff/tableDiff.d.ts +1 -1
  13. package/dist/fs/fs2.d.ts +2 -2
  14. package/dist/fs/fs2.js +14 -14
  15. package/dist/fs/json2env.d.ts +1 -1
  16. package/dist/fs/json2env.js +5 -5
  17. package/dist/fs/kpy.js +8 -8
  18. package/dist/index.d.ts +1 -1
  19. package/dist/index.js +2 -2
  20. package/dist/infra/process.util.js +7 -7
  21. package/dist/jwt/jwt.service.d.ts +3 -3
  22. package/dist/jwt/jwt.service.js +5 -5
  23. package/dist/script/runScript.js +3 -3
  24. package/dist/secret/secrets-decrypt.util.js +4 -4
  25. package/dist/secret/secrets-encrypt.util.js +7 -7
  26. package/dist/security/crypto.util.d.ts +1 -1
  27. package/dist/security/crypto.util.js +9 -9
  28. package/dist/security/hash.util.d.ts +1 -1
  29. package/dist/security/hash.util.js +3 -7
  30. package/dist/security/id.util.js +3 -4
  31. package/dist/security/secret.util.d.ts +1 -1
  32. package/dist/security/secret.util.js +6 -7
  33. package/dist/slack/slack.service.d.ts +2 -2
  34. package/dist/slack/slack.service.model.d.ts +2 -2
  35. package/dist/stream/ndjson/ndjsonMap.d.ts +2 -2
  36. package/dist/stream/ndjson/ndjsonStreamForEach.d.ts +2 -2
  37. package/dist/stream/ndjson/transformJsonParse.d.ts +2 -2
  38. package/dist/stream/ndjson/transformToNDJson.d.ts +1 -1
  39. package/dist/stream/pipeline/pipeline.d.ts +3 -2
  40. package/dist/stream/progressLogger.d.ts +2 -2
  41. package/dist/stream/readable/readableCreate.d.ts +2 -2
  42. package/dist/stream/readable/readableForEach.d.ts +3 -3
  43. package/dist/stream/readable/readableFromArray.d.ts +3 -3
  44. package/dist/stream/readable/readableToArray.d.ts +1 -1
  45. package/dist/stream/sizeStack.d.ts +2 -1
  46. package/dist/stream/stream.util.d.ts +2 -2
  47. package/dist/stream/transform/transformChunk.d.ts +1 -1
  48. package/dist/stream/transform/transformFilter.d.ts +3 -3
  49. package/dist/stream/transform/transformLimit.d.ts +3 -3
  50. package/dist/stream/transform/transformLogProgress.d.ts +2 -2
  51. package/dist/stream/transform/transformMap.d.ts +3 -2
  52. package/dist/stream/transform/transformMapSimple.d.ts +3 -2
  53. package/dist/stream/transform/transformMapSync.d.ts +4 -3
  54. package/dist/stream/transform/transformNoOp.d.ts +1 -1
  55. package/dist/stream/transform/transformOffset.d.ts +1 -1
  56. package/dist/stream/transform/transformSplit.d.ts +1 -1
  57. package/dist/stream/transform/transformTap.d.ts +2 -2
  58. package/dist/stream/transform/transformTee.d.ts +1 -1
  59. package/dist/stream/transform/transformThrottle.d.ts +2 -2
  60. package/dist/stream/transform/transformToArray.d.ts +1 -1
  61. package/dist/stream/transform/worker/baseWorkerClass.d.ts +1 -1
  62. package/dist/stream/transform/worker/transformMultiThreaded.d.ts +2 -2
  63. package/dist/stream/writable/writableForEach.d.ts +3 -3
  64. package/dist/stream/writable/writableFork.d.ts +1 -1
  65. package/dist/stream/writable/writableLimit.d.ts +2 -2
  66. package/dist/stream/writable/writablePushToArray.d.ts +1 -1
  67. package/dist/stream/writable/writableVoid.d.ts +2 -2
  68. package/dist/string/inspect.d.ts +2 -2
  69. package/dist/util/buildInfo.util.d.ts +1 -1
  70. package/dist/util/env.util.js +2 -3
  71. package/dist/util/exec2.d.ts +2 -1
  72. package/dist/util/exec2.js +6 -9
  73. package/dist/util/git2.js +6 -7
  74. package/dist/util/lruMemoCache.d.ts +1 -1
  75. package/dist/util/zip.util.d.ts +1 -1
  76. package/dist/util/zip.util.js +5 -5
  77. package/dist/validation/ajv/ajv.util.d.ts +3 -2
  78. package/dist/validation/ajv/ajvSchema.d.ts +2 -2
  79. package/dist/validation/ajv/ajvValidationError.d.ts +2 -1
  80. package/dist/validation/joi/joi.extensions.d.ts +2 -2
  81. package/dist/validation/joi/joi.shared.schemas.d.ts +4 -4
  82. package/dist/validation/joi/joi.validation.error.d.ts +3 -2
  83. package/dist/validation/joi/joi.validation.util.d.ts +1 -1
  84. package/dist/validation/joi/number.extensions.d.ts +2 -2
  85. package/dist/validation/joi/string.extensions.d.ts +3 -3
  86. package/package.json +1 -1
  87. package/src/bin/generate-build-info.ts +4 -4
  88. package/src/bin/json2env.ts +1 -1
  89. package/src/bin/kpy.ts +1 -1
  90. package/src/bin/secrets-decrypt.ts +3 -2
  91. package/src/bin/secrets-encrypt.ts +3 -2
  92. package/src/bin/secrets-gen-key.ts +3 -3
  93. package/src/bin/slack-this.ts +1 -1
  94. package/src/colors/colors.ts +1 -1
  95. package/src/csv/csvReader.ts +2 -1
  96. package/src/csv/csvWriter.ts +2 -1
  97. package/src/csv/transformToCSV.ts +4 -3
  98. package/src/diff/tableDiff.ts +2 -1
  99. package/src/fs/fs2.ts +4 -3
  100. package/src/fs/json2env.ts +2 -2
  101. package/src/fs/kpy.ts +3 -2
  102. package/src/index.ts +1 -1
  103. package/src/infra/process.util.ts +1 -1
  104. package/src/jwt/jwt.service.ts +4 -3
  105. package/src/script/runScript.ts +1 -1
  106. package/src/secret/secrets-decrypt.util.ts +1 -1
  107. package/src/secret/secrets-encrypt.util.ts +2 -2
  108. package/src/security/crypto.util.ts +3 -2
  109. package/src/security/hash.util.ts +4 -6
  110. package/src/security/id.util.ts +3 -3
  111. package/src/security/secret.util.ts +8 -7
  112. package/src/slack/slack.service.model.ts +2 -2
  113. package/src/slack/slack.service.ts +5 -13
  114. package/src/stream/ndjson/ndjsonMap.ts +4 -10
  115. package/src/stream/ndjson/ndjsonStreamForEach.ts +4 -10
  116. package/src/stream/ndjson/transformJsonParse.ts +2 -2
  117. package/src/stream/ndjson/transformToNDJson.ts +1 -1
  118. package/src/stream/pipeline/pipeline.ts +4 -2
  119. package/src/stream/progressLogger.ts +5 -11
  120. package/src/stream/readable/readableCreate.ts +3 -2
  121. package/src/stream/readable/readableForEach.ts +6 -3
  122. package/src/stream/readable/readableFromArray.ts +5 -3
  123. package/src/stream/readable/readableToArray.ts +1 -1
  124. package/src/stream/sizeStack.ts +2 -1
  125. package/src/stream/stream.util.ts +2 -2
  126. package/src/stream/transform/transformChunk.ts +1 -1
  127. package/src/stream/transform/transformFilter.ts +4 -3
  128. package/src/stream/transform/transformLimit.ts +3 -3
  129. package/src/stream/transform/transformLogProgress.ts +3 -2
  130. package/src/stream/transform/transformMap.ts +10 -8
  131. package/src/stream/transform/transformMapSimple.ts +3 -2
  132. package/src/stream/transform/transformMapSync.ts +4 -12
  133. package/src/stream/transform/transformNoOp.ts +1 -1
  134. package/src/stream/transform/transformOffset.ts +1 -1
  135. package/src/stream/transform/transformSplit.ts +1 -1
  136. package/src/stream/transform/transformTap.ts +2 -2
  137. package/src/stream/transform/transformTee.ts +1 -1
  138. package/src/stream/transform/transformThrottle.ts +3 -6
  139. package/src/stream/transform/transformToArray.ts +1 -1
  140. package/src/stream/transform/worker/baseWorkerClass.ts +1 -1
  141. package/src/stream/transform/worker/transformMultiThreaded.ts +4 -3
  142. package/src/stream/writable/writableForEach.ts +5 -3
  143. package/src/stream/writable/writableFork.ts +3 -2
  144. package/src/stream/writable/writableLimit.ts +3 -2
  145. package/src/stream/writable/writablePushToArray.ts +1 -1
  146. package/src/stream/writable/writableVoid.ts +2 -2
  147. package/src/string/inspect.ts +4 -2
  148. package/src/util/buildInfo.util.ts +2 -7
  149. package/src/util/env.util.ts +2 -2
  150. package/src/util/exec2.ts +18 -25
  151. package/src/util/git2.ts +6 -6
  152. package/src/util/lruMemoCache.ts +1 -1
  153. package/src/util/zip.util.ts +2 -1
  154. package/src/validation/ajv/ajv.util.ts +3 -2
  155. package/src/validation/ajv/ajvSchema.ts +3 -4
  156. package/src/validation/ajv/ajvValidationError.ts +2 -1
  157. package/src/validation/joi/joi.extensions.ts +4 -2
  158. package/src/validation/joi/joi.shared.schemas.ts +10 -8
  159. package/src/validation/joi/joi.validation.error.ts +3 -2
  160. package/src/validation/joi/joi.validation.util.ts +3 -2
  161. package/src/validation/joi/number.extensions.ts +2 -2
  162. package/src/validation/joi/string.extensions.ts +4 -3
package/dist/util/git2.js CHANGED
@@ -1,9 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.git2 = void 0;
4
- const tslib_1 = require("tslib");
5
- const node_child_process_1 = tslib_1.__importDefault(require("node:child_process"));
6
- const node_path_1 = tslib_1.__importDefault(require("node:path"));
4
+ const node_child_process_1 = require("node:child_process");
5
+ const node_path_1 = require("node:path");
7
6
  const colors_1 = require("../colors/colors");
8
7
  const exec2_1 = require("./exec2");
9
8
  /**
@@ -21,7 +20,7 @@ class Git2 {
21
20
  hasUncommittedChanges() {
22
21
  // git diff-index --quiet HEAD -- || echo "untracked"
23
22
  try {
24
- node_child_process_1.default.execSync('git diff-index --quiet HEAD --', {
23
+ (0, node_child_process_1.execSync)('git diff-index --quiet HEAD --', {
25
24
  encoding: 'utf8',
26
25
  });
27
26
  return false;
@@ -40,7 +39,7 @@ class Git2 {
40
39
  // const args = ['commit', '-a', '--no-verify', '-m', msg]
41
40
  console.log((0, colors_1.grey)(cmd));
42
41
  try {
43
- node_child_process_1.default.execSync(cmd, {
42
+ (0, node_child_process_1.execSync)(cmd, {
44
43
  stdio: 'inherit',
45
44
  });
46
45
  return true;
@@ -62,7 +61,7 @@ class Git2 {
62
61
  pull() {
63
62
  const cmd = 'git pull';
64
63
  try {
65
- node_child_process_1.default.execSync(cmd, {
64
+ (0, node_child_process_1.execSync)(cmd, {
66
65
  stdio: 'inherit',
67
66
  });
68
67
  }
@@ -89,7 +88,7 @@ class Git2 {
89
88
  }
90
89
  getCurrentRepoName() {
91
90
  const originUrl = exec2_1.exec2.exec('git config --get remote.origin.url');
92
- return node_path_1.default.basename(originUrl, '.git');
91
+ return (0, node_path_1.basename)(originUrl, '.git');
93
92
  }
94
93
  }
95
94
  exports.git2 = new Git2();
@@ -1,4 +1,4 @@
1
- import { MemoCache } from '@naturalcycles/js-lib';
1
+ import type { MemoCache } from '@naturalcycles/js-lib';
2
2
  import { LRUCache } from 'lru-cache';
3
3
  export type LRUMemoCacheOptions<KEY, VALUE> = Partial<LRUCache.Options<KEY, VALUE, any>>;
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { ZlibOptions } from 'node:zlib';
1
+ import type { ZlibOptions } from 'node:zlib';
2
2
  /**
3
3
  * deflateBuffer uses `deflate`.
4
4
  * It's 9 bytes shorter than `gzip`.
@@ -10,11 +10,11 @@ exports.gzipString = gzipString;
10
10
  exports.gunzipToString = gunzipToString;
11
11
  const tslib_1 = require("tslib");
12
12
  const node_util_1 = require("node:util");
13
- const node_zlib_1 = tslib_1.__importDefault(require("node:zlib"));
14
- const deflate = (0, node_util_1.promisify)(node_zlib_1.default.deflate.bind(node_zlib_1.default));
15
- const inflate = (0, node_util_1.promisify)(node_zlib_1.default.inflate.bind(node_zlib_1.default));
16
- const gzip = (0, node_util_1.promisify)(node_zlib_1.default.gzip.bind(node_zlib_1.default));
17
- const gunzip = (0, node_util_1.promisify)(node_zlib_1.default.gunzip.bind(node_zlib_1.default));
13
+ const zlib = tslib_1.__importStar(require("node:zlib"));
14
+ const deflate = (0, node_util_1.promisify)(zlib.deflate.bind(zlib));
15
+ const inflate = (0, node_util_1.promisify)(zlib.inflate.bind(zlib));
16
+ const gzip = (0, node_util_1.promisify)(zlib.gzip.bind(zlib));
17
+ const gunzip = (0, node_util_1.promisify)(zlib.gunzip.bind(zlib));
18
18
  // string > compressed buffer
19
19
  /**
20
20
  * deflateBuffer uses `deflate`.
@@ -1,6 +1,7 @@
1
- import { JsonSchema } from '@naturalcycles/js-lib';
1
+ import type { JsonSchema } from '@naturalcycles/js-lib';
2
2
  import type { FastGlobOptions } from '../..';
3
- import { AjvSchema, AjvSchemaCfg } from './ajvSchema';
3
+ import type { AjvSchemaCfg } from './ajvSchema';
4
+ import { AjvSchema } from './ajvSchema';
4
5
  /**
5
6
  * Does fs.readFileSync + JSON.parse for ALL files matching the passed `glob` pattern.
6
7
  * E.g `someDir/**\/*.schema.json`
@@ -1,5 +1,5 @@
1
- import { CommonLogger, JsonSchema, JsonSchemaBuilder } from '@naturalcycles/js-lib';
2
- import Ajv from 'ajv';
1
+ import type { CommonLogger, JsonSchema, JsonSchemaBuilder } from '@naturalcycles/js-lib';
2
+ import type Ajv from 'ajv';
3
3
  import { AjvValidationError } from './ajvValidationError';
4
4
  export interface AjvValidationOptions {
5
5
  objectName?: string;
@@ -1,4 +1,5 @@
1
- import { AppError, ErrorData } from '@naturalcycles/js-lib';
1
+ import type { ErrorData } from '@naturalcycles/js-lib';
2
+ import { AppError } from '@naturalcycles/js-lib';
2
3
  import type { ErrorObject } from 'ajv';
3
4
  export interface AjvValidationErrorData extends ErrorData {
4
5
  errors: ErrorObject[];
@@ -1,6 +1,6 @@
1
1
  import JoiLib from 'joi';
2
- import { NumberSchema } from './number.extensions';
3
- import { StringSchema } from './string.extensions';
2
+ import type { NumberSchema } from './number.extensions';
3
+ import type { StringSchema } from './string.extensions';
4
4
  export interface ExtendedJoi extends JoiLib.Root {
5
5
  string: <TSchema = string>() => StringSchema<TSchema>;
6
6
  number: <TSchema = number>() => NumberSchema<TSchema>;
@@ -1,7 +1,7 @@
1
- import { BaseDBEntity, IANATimezone, IsoDateTime, NumberEnum, StringEnum, UnixTimestamp, UnixTimestampMillis } from '@naturalcycles/js-lib';
2
- import { AlternativesSchema, AnySchema, ArraySchema, ObjectSchema } from 'joi';
3
- import { NumberSchema } from './number.extensions';
4
- import { StringSchema } from './string.extensions';
1
+ import type { BaseDBEntity, IANATimezone, IsoDateTime, NumberEnum, StringEnum, UnixTimestamp, UnixTimestampMillis } from '@naturalcycles/js-lib';
2
+ import type { AlternativesSchema, AnySchema, ArraySchema, ObjectSchema } from 'joi';
3
+ import type { NumberSchema } from './number.extensions';
4
+ import type { StringSchema } from './string.extensions';
5
5
  export declare const booleanSchema: import("joi").BooleanSchema<boolean>;
6
6
  export declare const booleanDefaultToFalseSchema: import("joi").BooleanSchema<boolean>;
7
7
  export declare const stringSchema: StringSchema<string>;
@@ -1,5 +1,6 @@
1
- import { AppError, ErrorData } from '@naturalcycles/js-lib';
2
- import { ValidationErrorItem } from 'joi';
1
+ import type { ErrorData } from '@naturalcycles/js-lib';
2
+ import { AppError } from '@naturalcycles/js-lib';
3
+ import type { ValidationErrorItem } from 'joi';
3
4
  /**
4
5
  * Example of ValidationErrorItem:
5
6
  *
@@ -1,4 +1,4 @@
1
- import { AnySchema, ValidationOptions } from 'joi';
1
+ import type { AnySchema, ValidationOptions } from 'joi';
2
2
  import { JoiValidationError } from './joi.validation.error';
3
3
  export interface JoiValidationResult<T = any> {
4
4
  value: T;
@@ -1,5 +1,5 @@
1
- import type Joi from 'joi';
2
- import { Extension, NumberSchema as JoiNumberSchema } from 'joi';
1
+ import type * as Joi from 'joi';
2
+ import type { Extension, NumberSchema as JoiNumberSchema } from 'joi';
3
3
  export interface NumberSchema<TSchema = number> extends JoiNumberSchema<TSchema> {
4
4
  dividable: (q: number) => this;
5
5
  }
@@ -1,6 +1,6 @@
1
- import { IsoDate } from '@naturalcycles/js-lib';
2
- import type Joi from 'joi';
3
- import { Extension, StringSchema as JoiStringSchema } from 'joi';
1
+ import type { IsoDate } from '@naturalcycles/js-lib';
2
+ import type * as Joi from 'joi';
3
+ import type { Extension, StringSchema as JoiStringSchema } from 'joi';
4
4
  export interface StringSchema<TSchema = string> extends JoiStringSchema<TSchema> {
5
5
  dateString: (min?: IsoDate | 'today', max?: IsoDate | 'today') => StringSchema<IsoDate>;
6
6
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/nodejs-lib",
3
- "version": "13.44.0",
3
+ "version": "13.45.2",
4
4
  "scripts": {
5
5
  "prepare": "husky",
6
6
  "build": "dev-lib build",
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import fs from 'node:fs'
4
- import path from 'node:path'
5
- import { UnixTimestamp } from '@naturalcycles/js-lib'
6
- import yargs from 'yargs'
3
+ import * as fs from 'node:fs'
4
+ import * as path from 'node:path'
5
+ import type { UnixTimestamp } from '@naturalcycles/js-lib'
6
+ import * as yargs from 'yargs'
7
7
  import { appendToBashEnv, appendToGithubEnv, appendToGithubOutput } from '../fs/json2env'
8
8
  import { runScript } from '../script/runScript'
9
9
  import { generateBuildInfo } from '../util/buildInfo.util'
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import yargs from 'yargs'
3
+ import * as yargs from 'yargs'
4
4
  import { json2env } from '../fs/json2env'
5
5
  import { runScript } from '../script/runScript'
6
6
 
package/src/bin/kpy.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import yargs from 'yargs'
3
+ import * as yargs from 'yargs'
4
4
  import { kpySync } from '../fs/kpy'
5
5
  import { runScript } from '../script/runScript'
6
6
 
@@ -1,9 +1,10 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import yargs from 'yargs'
3
+ import * as yargs from 'yargs'
4
4
  import { dimGrey } from '../colors/colors'
5
5
  import { runScript } from '../script/runScript'
6
- import { DecryptCLIOptions, secretsDecrypt } from '../secret/secrets-decrypt.util'
6
+ import type { DecryptCLIOptions } from '../secret/secrets-decrypt.util'
7
+ import { secretsDecrypt } from '../secret/secrets-decrypt.util'
7
8
 
8
9
  runScript(() => {
9
10
  const { dir, file, encKeyBuffer, del, jsonMode } = getDecryptCLIOptions()
@@ -1,9 +1,10 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import yargs from 'yargs'
3
+ import * as yargs from 'yargs'
4
4
  import { dimGrey } from '../colors/colors'
5
5
  import { runScript } from '../script/runScript'
6
- import { EncryptCLIOptions, secretsEncrypt } from '../secret/secrets-encrypt.util'
6
+ import type { EncryptCLIOptions } from '../secret/secrets-encrypt.util'
7
+ import { secretsEncrypt } from '../secret/secrets-encrypt.util'
7
8
 
8
9
  runScript(() => {
9
10
  const { pattern, file, encKeyBuffer, del, jsonMode } = getEncryptCLIOptions()
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import crypto from 'node:crypto'
4
- import yargs from 'yargs'
3
+ import { randomBytes } from 'node:crypto'
4
+ import * as yargs from 'yargs'
5
5
  import { dimGrey } from '../colors/colors'
6
6
  import { runScript } from '../script/runScript'
7
7
 
@@ -11,7 +11,7 @@ runScript(() => {
11
11
  default: 256,
12
12
  }).argv
13
13
 
14
- const key = crypto.randomBytes(sizeBytes).toString('base64')
14
+ const key = randomBytes(sizeBytes).toString('base64')
15
15
 
16
16
  console.log(dimGrey('\nSECRET_ENCRYPTION_KEY:\n'))
17
17
  console.log(key, '\n')
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import yargs from 'yargs'
3
+ import * as yargs from 'yargs'
4
4
  import { SlackService } from '..'
5
5
  import { runScript } from '../script/runScript'
6
6
 
@@ -1,4 +1,4 @@
1
- import tty from 'node:tty'
1
+ import * as tty from 'node:tty'
2
2
  import chalk from 'chalk'
3
3
 
4
4
  export { chalk }
@@ -1,6 +1,7 @@
1
1
  // Inspired by: https://gist.github.com/Jezternz/c8e9fafc2c114e079829974e3764db75
2
2
 
3
- import { _assert, AnyObject } from '@naturalcycles/js-lib'
3
+ import type { AnyObject } from '@naturalcycles/js-lib'
4
+ import { _assert } from '@naturalcycles/js-lib'
4
5
 
5
6
  export interface CSVReaderConfig {
6
7
  /**
@@ -1,6 +1,7 @@
1
1
  // Inspired by: https://github.com/ryu1kn/csv-writer/
2
2
 
3
- import { _assert, AnyObject } from '@naturalcycles/js-lib'
3
+ import type { AnyObject } from '@naturalcycles/js-lib'
4
+ import { _assert } from '@naturalcycles/js-lib'
4
5
 
5
6
  export interface CSVWriterConfig {
6
7
  /**
@@ -1,7 +1,8 @@
1
1
  import { Transform } from 'node:stream'
2
- import { AnyObject } from '@naturalcycles/js-lib'
3
- import { TransformTyped } from '../stream/stream.model'
4
- import { CSVWriter, CSVWriterConfig } from './csvWriter'
2
+ import type { AnyObject } from '@naturalcycles/js-lib'
3
+ import type { TransformTyped } from '../stream/stream.model'
4
+ import type { CSVWriterConfig } from './csvWriter'
5
+ import { CSVWriter } from './csvWriter'
5
6
 
6
7
  export interface TransformToCSVOptions extends CSVWriterConfig {
7
8
  /**
@@ -1,4 +1,5 @@
1
- import { _truncate, AnyObject } from '@naturalcycles/js-lib'
1
+ import type { AnyObject } from '@naturalcycles/js-lib'
2
+ import { _truncate } from '@naturalcycles/js-lib'
2
3
 
3
4
  export interface TableDiffOptions {
4
5
  /**
package/src/fs/fs2.ts CHANGED
@@ -17,12 +17,13 @@ Credit to: fs-extra (https://github.com/jprichardson/node-fs-extra)
17
17
  import type { RmOptions, Stats } from 'node:fs'
18
18
  import fs from 'node:fs'
19
19
  import fsp from 'node:fs/promises'
20
- import path from 'node:path'
20
+ import * as path from 'node:path'
21
21
  import { createGzip, createUnzip } from 'node:zlib'
22
22
  import { _isTruthy, _jsonParse } from '@naturalcycles/js-lib'
23
- import yaml, { DumpOptions } from 'js-yaml'
23
+ import type { DumpOptions } from 'js-yaml'
24
+ import * as yaml from 'js-yaml'
24
25
  import { transformToNDJson } from '../stream/ndjson/transformToNDJson'
25
- import { ReadableTyped, TransformTyped } from '../stream/stream.model'
26
+ import type { ReadableTyped, TransformTyped } from '../stream/stream.model'
26
27
  import { transformSplitOnNewline } from '../stream/transform/transformSplit'
27
28
  import { requireFileToExist } from '../util/env.util'
28
29
 
@@ -1,5 +1,5 @@
1
- import fs from 'node:fs'
2
- import { AnyObject } from '@naturalcycles/js-lib'
1
+ import * as fs from 'node:fs'
2
+ import type { AnyObject } from '@naturalcycles/js-lib'
3
3
  import { dimGrey } from '../colors/colors'
4
4
  import { fs2 } from './fs2'
5
5
 
package/src/fs/kpy.ts CHANGED
@@ -1,5 +1,6 @@
1
- import path from 'node:path'
2
- import { _since, localTime, UnixTimestampMillis } from '@naturalcycles/js-lib'
1
+ import * as path from 'node:path'
2
+ import type { UnixTimestampMillis } from '@naturalcycles/js-lib'
3
+ import { _since, localTime } from '@naturalcycles/js-lib'
3
4
  import { boldWhite, dimGrey, grey, yellow } from '../colors/colors'
4
5
  import { fastGlob, fs2 } from '../index'
5
6
 
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- import Ajv from 'ajv'
1
+ import * as Ajv from 'ajv'
2
2
  import type { Options as FastGlobOptions } from 'fast-glob'
3
3
  import fastGlob from 'fast-glob'
4
4
  import type {
@@ -1,4 +1,4 @@
1
- import os from 'node:os'
1
+ import * as os from 'node:os'
2
2
  import { _mb } from '@naturalcycles/js-lib'
3
3
 
4
4
  export function memoryUsage(): {
@@ -1,7 +1,8 @@
1
- import { _assert, _errorDataAppend, AnyObject, ErrorData, JWTString } from '@naturalcycles/js-lib'
2
- import { AnySchema } from 'joi'
1
+ import type { AnyObject, ErrorData, JWTString } from '@naturalcycles/js-lib'
2
+ import { _assert, _errorDataAppend } from '@naturalcycles/js-lib'
3
+ import type { AnySchema } from 'joi'
3
4
  import type { Algorithm, JwtHeader, SignOptions, VerifyOptions } from 'jsonwebtoken'
4
- import jsonwebtoken from 'jsonwebtoken'
5
+ import * as jsonwebtoken from 'jsonwebtoken'
5
6
  import { anyObjectSchema } from '../validation/joi/joi.shared.schemas'
6
7
  import { validate } from '../validation/joi/joi.validation.util'
7
8
  export { jsonwebtoken }
@@ -1,4 +1,4 @@
1
- import os from 'node:os'
1
+ import * as os from 'node:os'
2
2
  import type { CommonLogger } from '@naturalcycles/js-lib'
3
3
  import { pDelay, setGlobalStringifyFunction } from '@naturalcycles/js-lib'
4
4
  import { dimGrey } from '../colors/colors'
@@ -1,5 +1,5 @@
1
1
  import fs from 'node:fs'
2
- import path from 'node:path'
2
+ import * as path from 'node:path'
3
3
  import { _assert } from '@naturalcycles/js-lib'
4
4
  import { dimGrey, yellow } from '../colors/colors'
5
5
  import { fastGlob, fs2 } from '../index'
@@ -1,5 +1,5 @@
1
- import fs from 'node:fs'
2
- import path from 'node:path'
1
+ import * as fs from 'node:fs'
2
+ import * as path from 'node:path'
3
3
  import { _assert } from '@naturalcycles/js-lib'
4
4
  import { dimGrey, yellow } from '../colors/colors'
5
5
  import { fastGlob, fs2 } from '../index'
@@ -1,5 +1,6 @@
1
- import crypto from 'node:crypto'
2
- import { _stringMapEntries, Base64String, StringMap } from '@naturalcycles/js-lib'
1
+ import * as crypto from 'node:crypto'
2
+ import type { Base64String, StringMap } from '@naturalcycles/js-lib'
3
+ import { _stringMapEntries } from '@naturalcycles/js-lib'
3
4
  import { md5AsBuffer, sha256AsBuffer } from './hash.util'
4
5
 
5
6
  const algorithm = 'aes-256-cbc'
@@ -1,4 +1,5 @@
1
- import crypto, { BinaryToTextEncoding } from 'node:crypto'
1
+ import type { BinaryToTextEncoding } from 'node:crypto'
2
+ import { hash as cryptoHash } from 'node:crypto'
2
3
  import type { Base64String, Base64UrlString } from '@naturalcycles/js-lib'
3
4
 
4
5
  export function md5(s: string | Buffer, outputEncoding: BinaryToTextEncoding = 'hex'): string {
@@ -22,14 +23,11 @@ export function hash(
22
23
  algorithm: string,
23
24
  outputEncoding: BinaryToTextEncoding = 'hex',
24
25
  ): string {
25
- // https://github.com/nodejs/node/blob/main/doc/changelogs/CHANGELOG_V20.md#crypto-implement-cryptohash
26
- // Note: crypto.hash is Node 20.12+
27
- return crypto.hash(algorithm, s, outputEncoding)
26
+ return cryptoHash(algorithm, s, outputEncoding)
28
27
  }
29
28
 
30
29
  export function hashAsBuffer(s: string | Buffer, algorithm: string): Buffer {
31
- // Note: crypto.hash is Node 20.12+
32
- return crypto.hash(algorithm, s, 'buffer')
30
+ return cryptoHash(algorithm, s, 'buffer')
33
31
  }
34
32
 
35
33
  export function base64(s: string | Buffer): Base64String {
@@ -1,4 +1,4 @@
1
- import crypto from 'node:crypto'
1
+ import { randomBytes } from 'node:crypto'
2
2
  import {
3
3
  ALPHABET_ALPHANUMERIC,
4
4
  ALPHABET_ALPHANUMERIC_LOWERCASE,
@@ -30,7 +30,7 @@ export const stringIdBase62: () => string = nanoIdCustomAlphabet(ALPHABET_ALPHAN
30
30
  * Dividable by 4 lengths produce ids with no padding `=` characters, which is optimal.
31
31
  */
32
32
  export function stringIdBase64(size = 16): string {
33
- return crypto.randomBytes(size * 0.75).toString('base64')
33
+ return randomBytes(size * 0.75).toString('base64')
34
34
  }
35
35
 
36
36
  /**
@@ -42,7 +42,7 @@ export function stringIdBase64(size = 16): string {
42
42
  * Base64url always produces strings without a padding character `=`, by design.
43
43
  */
44
44
  export function stringIdBase64Url(size = 16): string {
45
- return crypto.randomBytes(size * 0.75).toString('base64url')
45
+ return randomBytes(size * 0.75).toString('base64url')
46
46
  }
47
47
 
48
48
  /**
@@ -1,5 +1,6 @@
1
- import fs from 'node:fs'
2
- import { _assert, _jsonParseIfPossible, Base64String, StringMap } from '@naturalcycles/js-lib'
1
+ import { existsSync, readFileSync } from 'node:fs'
2
+ import type { Base64String, StringMap } from '@naturalcycles/js-lib'
3
+ import { _assert, _jsonParseIfPossible } from '@naturalcycles/js-lib'
3
4
  import { decryptObject, decryptRandomIVBuffer } from './crypto.util'
4
5
 
5
6
  let loaded = false
@@ -54,19 +55,19 @@ export function loadSecretsFromEncryptedJsonFile(
54
55
  secretEncryptionKey?: Base64String,
55
56
  ): void {
56
57
  _assert(
57
- fs.existsSync(filePath),
58
+ existsSync(filePath),
58
59
  `loadSecretsFromEncryptedJsonFile() cannot load from path: ${filePath}`,
59
60
  )
60
61
 
61
62
  let secrets: StringMap
62
63
 
63
64
  if (secretEncryptionKey) {
64
- const buf = fs.readFileSync(filePath)
65
+ const buf = readFileSync(filePath)
65
66
  const encKeyBuffer = Buffer.from(secretEncryptionKey, 'base64')
66
67
  const plain = decryptRandomIVBuffer(buf, encKeyBuffer).toString('utf8')
67
68
  secrets = JSON.parse(plain)
68
69
  } else {
69
- secrets = JSON.parse(fs.readFileSync(filePath, 'utf8'))
70
+ secrets = JSON.parse(readFileSync(filePath, 'utf8'))
70
71
  }
71
72
 
72
73
  Object.entries(secrets).forEach(([k, v]) => (secretMap[k.toUpperCase()] = v))
@@ -88,11 +89,11 @@ export function loadSecretsFromEncryptedJsonFileValues(
88
89
  secretEncryptionKey?: Base64String,
89
90
  ): void {
90
91
  _assert(
91
- fs.existsSync(filePath),
92
+ existsSync(filePath),
92
93
  `loadSecretsFromEncryptedJsonFileValues() cannot load from path: ${filePath}`,
93
94
  )
94
95
 
95
- let secrets: StringMap = JSON.parse(fs.readFileSync(filePath, 'utf8'))
96
+ let secrets: StringMap = JSON.parse(readFileSync(filePath, 'utf8'))
96
97
 
97
98
  if (secretEncryptionKey) {
98
99
  const encKeyBuffer = Buffer.from(secretEncryptionKey, 'base64')
@@ -1,5 +1,5 @@
1
- import { AnyObject, CommonLogger } from '@naturalcycles/js-lib'
2
- import { InspectAnyOptions } from '..'
1
+ import type { AnyObject, CommonLogger } from '@naturalcycles/js-lib'
2
+ import type { InspectAnyOptions } from '..'
3
3
 
4
4
  /**
5
5
  * Properties that exists both in SlackApiBody (as per Slack API) and SlackMessage (our abstraction).
@@ -1,16 +1,8 @@
1
- import {
2
- _omit,
3
- AnyObject,
4
- CommonLogger,
5
- commonLoggerMinLevel,
6
- CommonLogLevel,
7
- Fetcher,
8
- getFetcher,
9
- localTime,
10
- PQueue,
11
- } from '@naturalcycles/js-lib'
12
- import { _inspect, InspectAnyOptions } from '..'
13
- import {
1
+ import type { AnyObject, CommonLogger, CommonLogLevel, Fetcher } from '@naturalcycles/js-lib'
2
+ import { _omit, commonLoggerMinLevel, getFetcher, localTime, PQueue } from '@naturalcycles/js-lib'
3
+ import type { InspectAnyOptions } from '..'
4
+ import { _inspect } from '..'
5
+ import type {
14
6
  SlackApiBody,
15
7
  SlackAttachmentField,
16
8
  SlackMessage,
@@ -1,13 +1,7 @@
1
- import { AbortableAsyncMapper, ErrorMode } from '@naturalcycles/js-lib'
2
- import {
3
- _pipeline,
4
- fs2,
5
- transformLimit,
6
- transformLogProgress,
7
- TransformLogProgressOptions,
8
- transformMap,
9
- TransformMapOptions,
10
- } from '../..'
1
+ import type { AbortableAsyncMapper } from '@naturalcycles/js-lib'
2
+ import { ErrorMode } from '@naturalcycles/js-lib'
3
+ import type { TransformLogProgressOptions, TransformMapOptions } from '../..'
4
+ import { _pipeline, fs2, transformLimit, transformLogProgress, transformMap } from '../..'
11
5
 
12
6
  export interface NDJSONMapOptions<IN = any, OUT = IN>
13
7
  extends TransformMapOptions<IN, OUT>,
@@ -1,13 +1,7 @@
1
- import { AbortableAsyncMapper, ErrorMode } from '@naturalcycles/js-lib'
2
- import {
3
- _pipeline,
4
- fs2,
5
- transformLogProgress,
6
- TransformLogProgressOptions,
7
- transformMap,
8
- TransformMapOptions,
9
- writableVoid,
10
- } from '../..'
1
+ import type { AbortableAsyncMapper } from '@naturalcycles/js-lib'
2
+ import { ErrorMode } from '@naturalcycles/js-lib'
3
+ import type { TransformLogProgressOptions, TransformMapOptions } from '../..'
4
+ import { _pipeline, fs2, transformLogProgress, transformMap, writableVoid } from '../..'
11
5
 
12
6
  export interface NDJSONStreamForEachOptions<IN = any>
13
7
  extends TransformMapOptions<IN, void>,
@@ -1,6 +1,6 @@
1
1
  import { Transform } from 'node:stream'
2
- import { Reviver } from '@naturalcycles/js-lib'
3
- import { TransformTyped } from '../stream.model'
2
+ import type { Reviver } from '@naturalcycles/js-lib'
3
+ import type { TransformTyped } from '../stream.model'
4
4
 
5
5
  export interface TransformJsonParseOptions {
6
6
  /**
@@ -1,6 +1,6 @@
1
1
  import { Transform } from 'node:stream'
2
2
  import { _sortObjectDeep } from '@naturalcycles/js-lib'
3
- import { TransformTyped } from '../stream.model'
3
+ import type { TransformTyped } from '../stream.model'
4
4
 
5
5
  export interface TransformToNDJsonOptions {
6
6
  /**
@@ -1,6 +1,8 @@
1
- import { Readable, Transform, Writable } from 'node:stream'
1
+ import type { Readable, Writable } from 'node:stream'
2
+ import { Transform } from 'node:stream'
2
3
  import { pipeline } from 'node:stream/promises'
3
- import { _last, AnyFunction, DeferredPromise, pDefer } from '@naturalcycles/js-lib'
4
+ import type { AnyFunction, DeferredPromise } from '@naturalcycles/js-lib'
5
+ import { _last, pDefer } from '@naturalcycles/js-lib'
4
6
  import { writablePushToArray } from '../writable/writablePushToArray'
5
7
 
6
8
  type AnyStream = NodeJS.ReadableStream | NodeJS.WritableStream | NodeJS.ReadWriteStream