@naturalcycles/nodejs-lib 13.45.3 → 14.0.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 (197) hide show
  1. package/dist/bin/generate-build-info.js +15 -18
  2. package/dist/bin/json2env.js +6 -9
  3. package/dist/bin/kpy.js +6 -9
  4. package/dist/bin/secrets-decrypt.d.ts +1 -1
  5. package/dist/bin/secrets-decrypt.js +9 -12
  6. package/dist/bin/secrets-encrypt.d.ts +1 -1
  7. package/dist/bin/secrets-encrypt.js +9 -12
  8. package/dist/bin/secrets-gen-key.js +8 -11
  9. package/dist/bin/slack-this.js +6 -9
  10. package/dist/buffer/buffer.util.js +1 -4
  11. package/dist/colors/colors.d.ts +26 -27
  12. package/dist/colors/colors.js +29 -33
  13. package/dist/csv/csvReader.js +4 -8
  14. package/dist/csv/csvWriter.js +7 -12
  15. package/dist/csv/transformToCSV.d.ts +2 -2
  16. package/dist/csv/transformToCSV.js +5 -8
  17. package/dist/diff/tableDiff.js +4 -7
  18. package/dist/fs/fs2.d.ts +1 -1
  19. package/dist/fs/fs2.js +88 -94
  20. package/dist/fs/json2env.js +18 -28
  21. package/dist/fs/kpy.js +28 -33
  22. package/dist/index.d.ts +71 -71
  23. package/dist/index.js +73 -78
  24. package/dist/infra/process.util.js +23 -28
  25. package/dist/jwt/jwt.service.js +17 -21
  26. package/dist/log/log.util.js +4 -7
  27. package/dist/script/runScript.js +11 -15
  28. package/dist/secret/secrets-decrypt.util.js +18 -22
  29. package/dist/secret/secrets-encrypt.util.js +17 -21
  30. package/dist/security/crypto.util.js +24 -34
  31. package/dist/security/hash.util.js +19 -37
  32. package/dist/security/id.util.js +11 -18
  33. package/dist/security/nanoid.js +15 -20
  34. package/dist/security/secret.util.js +20 -30
  35. package/dist/slack/slack.service.d.ts +1 -1
  36. package/dist/slack/slack.service.js +13 -16
  37. package/dist/slack/slack.service.model.d.ts +1 -1
  38. package/dist/slack/slack.service.model.js +1 -2
  39. package/dist/stream/ndjson/ndjson.model.js +10 -16
  40. package/dist/stream/ndjson/ndjsonMap.d.ts +1 -1
  41. package/dist/stream/ndjson/ndjsonMap.js +11 -14
  42. package/dist/stream/ndjson/ndjsonStreamForEach.d.ts +1 -1
  43. package/dist/stream/ndjson/ndjsonStreamForEach.js +9 -12
  44. package/dist/stream/ndjson/transformJsonParse.d.ts +1 -1
  45. package/dist/stream/ndjson/transformJsonParse.js +4 -9
  46. package/dist/stream/ndjson/transformToNDJson.d.ts +1 -1
  47. package/dist/stream/ndjson/transformToNDJson.js +5 -8
  48. package/dist/stream/pipeline/pipeline.js +13 -17
  49. package/dist/stream/progressLogger.d.ts +1 -1
  50. package/dist/stream/progressLogger.js +32 -28
  51. package/dist/stream/readable/readableCreate.d.ts +1 -1
  52. package/dist/stream/readable/readableCreate.js +5 -9
  53. package/dist/stream/readable/readableForEach.d.ts +2 -2
  54. package/dist/stream/readable/readableForEach.js +7 -11
  55. package/dist/stream/readable/readableFromArray.d.ts +1 -1
  56. package/dist/stream/readable/readableFromArray.js +4 -7
  57. package/dist/stream/readable/readableToArray.d.ts +1 -1
  58. package/dist/stream/readable/readableToArray.js +1 -4
  59. package/dist/stream/sizeStack.js +9 -12
  60. package/dist/stream/stream.model.js +1 -2
  61. package/dist/stream/stream.util.js +1 -4
  62. package/dist/stream/transform/transformChunk.d.ts +1 -1
  63. package/dist/stream/transform/transformChunk.js +3 -6
  64. package/dist/stream/transform/transformFilter.d.ts +2 -2
  65. package/dist/stream/transform/transformFilter.js +6 -10
  66. package/dist/stream/transform/transformLimit.d.ts +2 -2
  67. package/dist/stream/transform/transformLimit.js +6 -11
  68. package/dist/stream/transform/transformLogProgress.d.ts +2 -2
  69. package/dist/stream/transform/transformLogProgress.js +5 -8
  70. package/dist/stream/transform/transformMap.d.ts +1 -1
  71. package/dist/stream/transform/transformMap.js +18 -22
  72. package/dist/stream/transform/transformMapSimple.d.ts +1 -1
  73. package/dist/stream/transform/transformMapSimple.js +6 -9
  74. package/dist/stream/transform/transformMapSync.d.ts +3 -3
  75. package/dist/stream/transform/transformMapSync.js +14 -19
  76. package/dist/stream/transform/transformNoOp.d.ts +1 -1
  77. package/dist/stream/transform/transformNoOp.js +3 -6
  78. package/dist/stream/transform/transformOffset.d.ts +1 -1
  79. package/dist/stream/transform/transformOffset.js +5 -8
  80. package/dist/stream/transform/transformSplit.d.ts +1 -1
  81. package/dist/stream/transform/transformSplit.js +5 -9
  82. package/dist/stream/transform/transformTap.d.ts +1 -1
  83. package/dist/stream/transform/transformTap.js +3 -6
  84. package/dist/stream/transform/transformTee.d.ts +1 -1
  85. package/dist/stream/transform/transformTee.js +7 -10
  86. package/dist/stream/transform/transformThrottle.d.ts +1 -1
  87. package/dist/stream/transform/transformThrottle.js +9 -12
  88. package/dist/stream/transform/transformToArray.d.ts +1 -1
  89. package/dist/stream/transform/transformToArray.js +3 -6
  90. package/dist/stream/transform/worker/baseWorkerClass.d.ts +1 -1
  91. package/dist/stream/transform/worker/baseWorkerClass.js +2 -5
  92. package/dist/stream/transform/worker/transformMultiThreaded.d.ts +1 -1
  93. package/dist/stream/transform/worker/transformMultiThreaded.js +12 -11
  94. package/dist/stream/transform/worker/transformMultiThreaded.model.js +1 -2
  95. package/dist/stream/transform/worker/workerClassProxy.js +6 -4
  96. package/dist/stream/writable/writableForEach.d.ts +2 -2
  97. package/dist/stream/writable/writableForEach.js +6 -10
  98. package/dist/stream/writable/writableFork.d.ts +1 -1
  99. package/dist/stream/writable/writableFork.js +6 -9
  100. package/dist/stream/writable/writableLimit.d.ts +1 -1
  101. package/dist/stream/writable/writableLimit.js +3 -6
  102. package/dist/stream/writable/writablePushToArray.d.ts +1 -1
  103. package/dist/stream/writable/writablePushToArray.js +3 -6
  104. package/dist/stream/writable/writableVoid.d.ts +1 -1
  105. package/dist/stream/writable/writableVoid.js +3 -6
  106. package/dist/string/inspect.js +8 -13
  107. package/dist/util/buildInfo.util.js +12 -15
  108. package/dist/util/env.util.js +5 -9
  109. package/dist/util/exec2.js +17 -21
  110. package/dist/util/git2.js +17 -20
  111. package/dist/util/lruMemoCache.js +4 -7
  112. package/dist/util/zip.util.js +14 -25
  113. package/dist/validation/ajv/ajv.util.d.ts +3 -3
  114. package/dist/validation/ajv/ajv.util.js +6 -10
  115. package/dist/validation/ajv/ajvSchema.d.ts +2 -2
  116. package/dist/validation/ajv/ajvSchema.js +17 -18
  117. package/dist/validation/ajv/ajvValidationError.js +2 -6
  118. package/dist/validation/ajv/getAjv.d.ts +1 -1
  119. package/dist/validation/ajv/getAjv.js +9 -9
  120. package/dist/validation/joi/joi.extensions.d.ts +2 -2
  121. package/dist/validation/joi/joi.extensions.js +6 -10
  122. package/dist/validation/joi/joi.model.js +1 -2
  123. package/dist/validation/joi/joi.shared.schemas.d.ts +2 -2
  124. package/dist/validation/joi/joi.shared.schemas.js +61 -74
  125. package/dist/validation/joi/joi.validation.error.js +2 -6
  126. package/dist/validation/joi/joi.validation.util.d.ts +1 -1
  127. package/dist/validation/joi/joi.validation.util.js +10 -17
  128. package/dist/validation/joi/number.extensions.js +1 -4
  129. package/dist/validation/joi/string.extensions.js +4 -7
  130. package/dist/yargs.util.js +5 -8
  131. package/package.json +5 -4
  132. package/src/bin/generate-build-info.ts +3 -3
  133. package/src/bin/json2env.ts +2 -2
  134. package/src/bin/kpy.ts +2 -2
  135. package/src/bin/secrets-decrypt.ts +7 -8
  136. package/src/bin/secrets-encrypt.ts +7 -8
  137. package/src/bin/secrets-gen-key.ts +2 -2
  138. package/src/bin/slack-this.ts +2 -2
  139. package/src/csv/transformToCSV.ts +3 -3
  140. package/src/fs/fs2.ts +4 -4
  141. package/src/fs/json2env.ts +2 -2
  142. package/src/fs/kpy.ts +2 -2
  143. package/src/index.ts +71 -71
  144. package/src/jwt/jwt.service.ts +2 -2
  145. package/src/log/log.util.ts +1 -1
  146. package/src/script/runScript.ts +4 -3
  147. package/src/secret/secrets-decrypt.util.ts +3 -3
  148. package/src/secret/secrets-encrypt.util.ts +3 -3
  149. package/src/security/crypto.util.ts +1 -1
  150. package/src/security/id.util.ts +1 -1
  151. package/src/security/secret.util.ts +2 -2
  152. package/src/slack/slack.service.model.ts +1 -1
  153. package/src/slack/slack.service.ts +3 -3
  154. package/src/stream/ndjson/ndjson.model.ts +1 -1
  155. package/src/stream/ndjson/ndjsonMap.ts +2 -2
  156. package/src/stream/ndjson/ndjsonStreamForEach.ts +2 -2
  157. package/src/stream/ndjson/transformJsonParse.ts +1 -1
  158. package/src/stream/ndjson/transformToNDJson.ts +1 -1
  159. package/src/stream/pipeline/pipeline.ts +1 -1
  160. package/src/stream/progressLogger.ts +3 -3
  161. package/src/stream/readable/readableCreate.ts +1 -1
  162. package/src/stream/readable/readableForEach.ts +4 -4
  163. package/src/stream/readable/readableFromArray.ts +1 -1
  164. package/src/stream/readable/readableToArray.ts +1 -1
  165. package/src/stream/sizeStack.ts +2 -2
  166. package/src/stream/transform/transformChunk.ts +1 -1
  167. package/src/stream/transform/transformFilter.ts +3 -3
  168. package/src/stream/transform/transformLimit.ts +3 -3
  169. package/src/stream/transform/transformLogProgress.ts +3 -3
  170. package/src/stream/transform/transformMap.ts +5 -5
  171. package/src/stream/transform/transformMapSimple.ts +1 -1
  172. package/src/stream/transform/transformMapSync.ts +5 -5
  173. package/src/stream/transform/transformNoOp.ts +1 -1
  174. package/src/stream/transform/transformOffset.ts +2 -2
  175. package/src/stream/transform/transformSplit.ts +1 -1
  176. package/src/stream/transform/transformTap.ts +1 -1
  177. package/src/stream/transform/transformTee.ts +3 -3
  178. package/src/stream/transform/transformThrottle.ts +1 -1
  179. package/src/stream/transform/transformToArray.ts +1 -1
  180. package/src/stream/transform/worker/baseWorkerClass.ts +1 -1
  181. package/src/stream/transform/worker/transformMultiThreaded.ts +8 -3
  182. package/src/stream/transform/worker/workerClassProxy.js +6 -4
  183. package/src/stream/writable/writableForEach.ts +3 -3
  184. package/src/stream/writable/writableFork.ts +3 -3
  185. package/src/stream/writable/writableLimit.ts +1 -1
  186. package/src/stream/writable/writablePushToArray.ts +1 -1
  187. package/src/stream/writable/writableVoid.ts +1 -1
  188. package/src/util/buildInfo.util.ts +2 -2
  189. package/src/util/exec2.ts +1 -1
  190. package/src/util/git2.ts +2 -2
  191. package/src/validation/ajv/ajv.util.ts +4 -4
  192. package/src/validation/ajv/ajvSchema.ts +4 -5
  193. package/src/validation/ajv/getAjv.ts +7 -3
  194. package/src/validation/joi/joi.extensions.ts +4 -4
  195. package/src/validation/joi/joi.shared.schemas.ts +3 -3
  196. package/src/validation/joi/joi.validation.util.ts +2 -2
  197. package/src/yargs.util.ts +1 -0
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /*
3
2
  * Does 2 things:
4
3
  * 1. Validates the value according to Schema passed.
@@ -6,14 +5,8 @@
6
5
  *
7
6
  * "Converts" mean e.g trims all strings from leading/trailing spaces.
8
7
  */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.validate = validate;
11
- exports.getValidationResult = getValidationResult;
12
- exports.isValid = isValid;
13
- exports.undefinedIfInvalid = undefinedIfInvalid;
14
- exports.convert = convert;
15
- const js_lib_1 = require("@naturalcycles/js-lib");
16
- const joi_validation_error_1 = require("./joi.validation.error");
8
+ import { _hb, _isObject, _truncateMiddle } from '@naturalcycles/js-lib';
9
+ import { JoiValidationError } from './joi.validation.error.js';
17
10
  // Strip colors in production (for e.g Sentry reporting)
18
11
  // const stripColors = process.env.NODE_ENV === 'production' || !!process.env.GAE_INSTANCE
19
12
  // Currently colors do more bad than good, so let's strip them always for now
@@ -44,7 +37,7 @@ const defaultOptions = {
44
37
  *
45
38
  * If `schema` is undefined - returns value as is.
46
39
  */
47
- function validate(input, schema, objectName, opt = {}) {
40
+ export function validate(input, schema, objectName, opt = {}) {
48
41
  const { value: returnValue, error } = getValidationResult(input, schema, objectName, opt);
49
42
  if (error) {
50
43
  throw error;
@@ -58,7 +51,7 @@ function validate(input, schema, objectName, opt = {}) {
58
51
  *
59
52
  * If `schema` is undefined - returns value as is.
60
53
  */
61
- function getValidationResult(input, schema, objectName, options = {}) {
54
+ export function getValidationResult(input, schema, objectName, options = {}) {
62
55
  if (!schema)
63
56
  return { value: input };
64
57
  const { value, error } = schema.validate(input, {
@@ -76,13 +69,13 @@ function getValidationResult(input, schema, objectName, options = {}) {
76
69
  /**
77
70
  * Convenience function that returns true if !error.
78
71
  */
79
- function isValid(input, schema) {
72
+ export function isValid(input, schema) {
80
73
  if (!schema)
81
74
  return true;
82
75
  const { error } = schema.validate(input, defaultOptions);
83
76
  return !error;
84
77
  }
85
- function undefinedIfInvalid(input, schema) {
78
+ export function undefinedIfInvalid(input, schema) {
86
79
  if (!schema)
87
80
  return input;
88
81
  const { value, error } = schema.validate(input, defaultOptions);
@@ -93,7 +86,7 @@ function undefinedIfInvalid(input, schema) {
93
86
  *
94
87
  * @returns converted value
95
88
  */
96
- function convert(input, schema) {
89
+ export function convert(input, schema) {
97
90
  if (!schema)
98
91
  return input;
99
92
  const { value } = schema.validate(input, defaultOptions);
@@ -101,7 +94,7 @@ function convert(input, schema) {
101
94
  }
102
95
  function createError(value, err, objectName) {
103
96
  const tokens = [];
104
- const objectId = (0, js_lib_1._isObject)(value) ? value['id'] : undefined;
97
+ const objectId = _isObject(value) ? value['id'] : undefined;
105
98
  if (objectId || objectName) {
106
99
  objectName ||= value?.constructor?.name;
107
100
  tokens.push('Invalid ' + [objectName, objectId].filter(Boolean).join('.'));
@@ -123,7 +116,7 @@ function createError(value, err, objectName) {
123
116
  tokens.push(`... ${err.details.length} errors in total`);
124
117
  tokens.push('');
125
118
  }
126
- tokens.push((0, js_lib_1._truncateMiddle)(annotation, 4000, `\n... ${(0, js_lib_1._hb)(annotation.length)} message truncated ...\n`));
119
+ tokens.push(_truncateMiddle(annotation, 4000, `\n... ${_hb(annotation.length)} message truncated ...\n`));
127
120
  const msg = tokens.join('\n');
128
121
  const data = {
129
122
  joiValidationErrorItems: err.details,
@@ -138,5 +131,5 @@ function createError(value, err, objectName) {
138
131
  enumerable: false,
139
132
  value: annotation,
140
133
  });
141
- return new joi_validation_error_1.JoiValidationError(msg, data);
134
+ return new JoiValidationError(msg, data);
142
135
  }
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.numberExtensions = numberExtensions;
4
- function numberExtensions(joi) {
1
+ export function numberExtensions(joi) {
5
2
  return {
6
3
  base: joi.number(),
7
4
  type: 'number',
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.stringExtensions = stringExtensions;
4
- const js_lib_1 = require("@naturalcycles/js-lib");
5
- function stringExtensions(joi) {
1
+ import { localTime } from '@naturalcycles/js-lib';
2
+ export function stringExtensions(joi) {
6
3
  return {
7
4
  type: 'string',
8
5
  base: joi.string(),
@@ -94,7 +91,7 @@ function getTodayStrPlus15() {
94
91
  return todayStrPlusCached;
95
92
  }
96
93
  lastCheckedPlus = now;
97
- return (todayStrPlusCached = js_lib_1.localTime.now().plus(15, 'hour').toISODate());
94
+ return (todayStrPlusCached = localTime.now().plus(15, 'hour').toISODate());
98
95
  }
99
96
  function getTodayStrMinus15() {
100
97
  const now = Date.now();
@@ -103,5 +100,5 @@ function getTodayStrMinus15() {
103
100
  return todayStrMinusCached;
104
101
  }
105
102
  lastCheckedMinus = now;
106
- return (todayStrMinusCached = js_lib_1.localTime.now().plus(-15, 'hour').toISODate());
103
+ return (todayStrMinusCached = localTime.now().plus(-15, 'hour').toISODate());
107
104
  }
@@ -1,14 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports._yargs = _yargs;
4
- const tslib_1 = require("tslib");
5
- const yargs_1 = tslib_1.__importDefault(require("yargs"));
6
- const helpers_1 = require("yargs/helpers");
1
+ import yargs from 'yargs';
2
+ // @ts-expect-error yargs types disagree with runtime
3
+ import { hideBin } from 'yargs/helpers';
7
4
  /**
8
5
  * Quick yargs helper to make it work in esm.
9
6
  * It also allows to not have yargs and `@types/yargs` to be declared as dependencies.
10
7
  */
11
8
  // eslint-disable-next-line @typescript-eslint/explicit-function-return-type, @typescript-eslint/explicit-module-boundary-types
12
- function _yargs() {
13
- return (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv));
9
+ export function _yargs() {
10
+ return yargs(hideBin(process.argv));
14
11
  }
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/nodejs-lib",
3
- "version": "13.45.3",
3
+ "type": "module",
4
+ "version": "14.0.0",
4
5
  "scripts": {
5
6
  "prepare": "husky",
6
7
  "build": "dev-lib build",
@@ -27,7 +28,7 @@
27
28
  "ajv": "^8",
28
29
  "ajv-formats": "^3",
29
30
  "ajv-keywords": "^5",
30
- "chalk": "^4",
31
+ "chalk": "^5",
31
32
  "dotenv": "^16",
32
33
  "fast-glob": "^3",
33
34
  "joi": "^17",
@@ -38,8 +39,8 @@
38
39
  "yargs": "^17"
39
40
  },
40
41
  "devDependencies": {
41
- "@naturalcycles/bench-lib": "^3",
42
- "@naturalcycles/dev-lib": "^17",
42
+ "@naturalcycles/bench-lib": "^4",
43
+ "@naturalcycles/dev-lib": "^18",
43
44
  "@types/node": "^22",
44
45
  "@types/through2-concurrent": "^2",
45
46
  "@vitest/coverage-v8": "^3",
@@ -4,9 +4,9 @@ import fs from 'node:fs'
4
4
  import path from 'node:path'
5
5
  import type { UnixTimestamp } from '@naturalcycles/js-lib'
6
6
  import yargs from 'yargs'
7
- import { appendToBashEnv, appendToGithubEnv, appendToGithubOutput } from '../fs/json2env'
8
- import { runScript } from '../script/runScript'
9
- import { generateBuildInfo } from '../util/buildInfo.util'
7
+ import { appendToBashEnv, appendToGithubEnv, appendToGithubOutput } from '../fs/json2env.js'
8
+ import { runScript } from '../script/runScript.js'
9
+ import { generateBuildInfo } from '../util/buildInfo.util.js'
10
10
 
11
11
  runScript(async () => {
12
12
  const { dir, overrideTimestamp } = yargs.options({
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import yargs from 'yargs'
4
- import { json2env } from '../fs/json2env'
5
- import { runScript } from '../script/runScript'
4
+ import { json2env } from '../fs/json2env.js'
5
+ import { runScript } from '../script/runScript.js'
6
6
 
7
7
  runScript(() => {
8
8
  const { argv } = yargs.demandCommand(1).options({
package/src/bin/kpy.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import yargs from 'yargs'
4
- import { kpySync } from '../fs/kpy'
5
- import { runScript } from '../script/runScript'
4
+ import { kpySync } from '../fs/kpy.js'
5
+ import { runScript } from '../script/runScript.js'
6
6
 
7
7
  runScript(() => {
8
8
  const {
@@ -1,10 +1,11 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import yargs from 'yargs'
4
- import { dimGrey } from '../colors/colors'
5
- import { runScript } from '../script/runScript'
6
- import type { DecryptCLIOptions } from '../secret/secrets-decrypt.util'
7
- import { secretsDecrypt } from '../secret/secrets-decrypt.util'
3
+ import 'dotenv/config'
4
+ import { dimGrey } from '../colors/colors.js'
5
+ import { runScript } from '../script/runScript.js'
6
+ import type { DecryptCLIOptions } from '../secret/secrets-decrypt.util.js'
7
+ import { secretsDecrypt } from '../secret/secrets-decrypt.util.js'
8
+ import { _yargs } from '../yargs.util.js'
8
9
 
9
10
  runScript(() => {
10
11
  const { dir, file, encKeyBuffer, del, jsonMode } = getDecryptCLIOptions()
@@ -13,9 +14,7 @@ runScript(() => {
13
14
  })
14
15
 
15
16
  function getDecryptCLIOptions(): DecryptCLIOptions {
16
- require('dotenv').config()
17
-
18
- let { dir, file, encKey, encKeyVar, del, jsonMode } = yargs.options({
17
+ let { dir, file, encKey, encKeyVar, del, jsonMode } = _yargs().options({
19
18
  dir: {
20
19
  type: 'array',
21
20
  desc: 'Directory with secrets. Can be many',
@@ -1,10 +1,11 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import yargs from 'yargs'
4
- import { dimGrey } from '../colors/colors'
5
- import { runScript } from '../script/runScript'
6
- import type { EncryptCLIOptions } from '../secret/secrets-encrypt.util'
7
- import { secretsEncrypt } from '../secret/secrets-encrypt.util'
3
+ import 'dotenv/config'
4
+ import { dimGrey } from '../colors/colors.js'
5
+ import { runScript } from '../script/runScript.js'
6
+ import type { EncryptCLIOptions } from '../secret/secrets-encrypt.util.js'
7
+ import { secretsEncrypt } from '../secret/secrets-encrypt.util.js'
8
+ import { _yargs } from '../yargs.util.js'
8
9
 
9
10
  runScript(() => {
10
11
  const { pattern, file, encKeyBuffer, del, jsonMode } = getEncryptCLIOptions()
@@ -13,9 +14,7 @@ runScript(() => {
13
14
  })
14
15
 
15
16
  function getEncryptCLIOptions(): EncryptCLIOptions {
16
- require('dotenv').config()
17
-
18
- let { pattern, file, encKey, encKeyVar, del, jsonMode } = yargs.options({
17
+ let { pattern, file, encKey, encKeyVar, del, jsonMode } = _yargs().options({
19
18
  pattern: {
20
19
  type: 'string',
21
20
  array: true,
@@ -2,8 +2,8 @@
2
2
 
3
3
  import { randomBytes } from 'node:crypto'
4
4
  import yargs from 'yargs'
5
- import { dimGrey } from '../colors/colors'
6
- import { runScript } from '../script/runScript'
5
+ import { dimGrey } from '../colors/colors.js'
6
+ import { runScript } from '../script/runScript.js'
7
7
 
8
8
  runScript(() => {
9
9
  const { sizeBytes } = yargs.option('sizeBytes', {
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import yargs from 'yargs'
4
- import { SlackService } from '..'
5
- import { runScript } from '../script/runScript'
4
+ import { SlackService } from '../index.js'
5
+ import { runScript } from '../script/runScript.js'
6
6
 
7
7
  runScript(async () => {
8
8
  const {
@@ -1,8 +1,8 @@
1
1
  import { Transform } from 'node:stream'
2
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'
3
+ import type { TransformTyped } from '../stream/stream.model.js'
4
+ import type { CSVWriterConfig } from './csvWriter.js'
5
+ import { CSVWriter } from './csvWriter.js'
6
6
 
7
7
  export interface TransformToCSVOptions extends CSVWriterConfig {
8
8
  /**
package/src/fs/fs2.ts CHANGED
@@ -22,10 +22,10 @@ import { createGzip, createUnzip } from 'node:zlib'
22
22
  import { _isTruthy, _jsonParse } from '@naturalcycles/js-lib'
23
23
  import type { DumpOptions } from 'js-yaml'
24
24
  import yaml from 'js-yaml'
25
- import { transformToNDJson } from '../stream/ndjson/transformToNDJson'
26
- import type { ReadableTyped, TransformTyped } from '../stream/stream.model'
27
- import { transformSplitOnNewline } from '../stream/transform/transformSplit'
28
- import { requireFileToExist } from '../util/env.util'
25
+ import { transformToNDJson } from '../stream/ndjson/transformToNDJson.js'
26
+ import type { ReadableTyped, TransformTyped } from '../stream/stream.model.js'
27
+ import { transformSplitOnNewline } from '../stream/transform/transformSplit.js'
28
+ import { requireFileToExist } from '../util/env.util.js'
29
29
 
30
30
  /**
31
31
  * fs2 conveniently groups filesystem functions together.
@@ -1,7 +1,7 @@
1
1
  import fs from 'node:fs'
2
2
  import type { AnyObject } from '@naturalcycles/js-lib'
3
- import { dimGrey } from '../colors/colors'
4
- import { fs2 } from './fs2'
3
+ import { dimGrey } from '../colors/colors.js'
4
+ import { fs2 } from './fs2.js'
5
5
 
6
6
  export interface Json2EnvOptions {
7
7
  jsonPath: string
package/src/fs/kpy.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import path from 'node:path'
2
2
  import type { UnixTimestampMillis } from '@naturalcycles/js-lib'
3
3
  import { _since, localTime } from '@naturalcycles/js-lib'
4
- import { boldWhite, dimGrey, grey, yellow } from '../colors/colors'
5
- import { fastGlob, fs2 } from '../index'
4
+ import { boldWhite, dimGrey, grey, yellow } from '../colors/colors.js'
5
+ import { fastGlob, fs2 } from '../index.js'
6
6
 
7
7
  /**
8
8
  * Everything defaults to `undefined`.
package/src/index.ts CHANGED
@@ -12,77 +12,77 @@ import type {
12
12
  ObjectSchema,
13
13
  ValidationErrorItem,
14
14
  } from 'joi'
15
- export * from './buffer/buffer.util'
16
- export * from './colors/colors'
17
- export * from './csv/csvReader'
18
- export * from './csv/csvWriter'
19
- export * from './csv/transformToCSV'
20
- export * from './diff/tableDiff'
21
- export * from './fs/fs2'
22
- export * from './fs/json2env'
23
- export * from './fs/kpy'
24
- export * from './infra/process.util'
25
- export * from './jwt/jwt.service'
26
- export * from './log/log.util'
27
- export * from './script/runScript'
28
- export * from './security/crypto.util'
29
- export * from './security/hash.util'
30
- export * from './security/id.util'
31
- export * from './security/nanoid'
32
- export * from './security/secret.util'
33
- export * from './slack/slack.service'
34
- export * from './slack/slack.service.model'
35
- export * from './stream/ndjson/ndjson.model'
36
- export * from './stream/ndjson/ndjsonMap'
37
- export * from './stream/ndjson/ndjsonStreamForEach'
38
- export * from './stream/ndjson/transformJsonParse'
39
- export * from './stream/ndjson/transformToNDJson'
40
- export * from './stream/pipeline/pipeline'
41
- export * from './stream/progressLogger'
42
- export * from './stream/readable/readableCreate'
43
- export * from './stream/readable/readableForEach'
44
- export * from './stream/readable/readableFromArray'
45
- export * from './stream/readable/readableToArray'
46
- export * from './stream/stream.model'
47
- export * from './stream/transform/transformChunk'
48
- export * from './stream/transform/transformFilter'
49
- export * from './stream/transform/transformLimit'
50
- export * from './stream/transform/transformLogProgress'
51
- export * from './stream/transform/transformMap'
52
- export * from './stream/transform/transformMapSimple'
53
- export * from './stream/transform/transformMapSync'
54
- export * from './stream/transform/transformNoOp'
55
- export * from './stream/transform/transformOffset'
56
- export * from './stream/transform/transformSplit'
57
- export * from './stream/transform/transformTap'
58
- export * from './stream/transform/transformTee'
59
- export * from './stream/transform/transformThrottle'
60
- export * from './stream/transform/transformToArray'
61
- export * from './stream/transform/worker/baseWorkerClass'
62
- export * from './stream/transform/worker/transformMultiThreaded'
63
- export * from './stream/transform/worker/transformMultiThreaded.model'
64
- export * from './stream/writable/writableForEach'
65
- export * from './stream/writable/writableFork'
66
- export * from './stream/writable/writablePushToArray'
67
- export * from './stream/writable/writableVoid'
68
- export * from './string/inspect'
69
- export * from './util/buildInfo.util'
70
- export * from './util/env.util'
71
- export * from './util/exec2'
72
- export * from './util/git2'
73
- export * from './util/lruMemoCache'
74
- export * from './util/zip.util'
75
- export * from './validation/ajv/ajv.util'
76
- export * from './validation/ajv/ajvSchema'
77
- export * from './validation/ajv/ajvValidationError'
78
- export * from './validation/ajv/getAjv'
79
- export * from './validation/joi/joi.extensions'
80
- export * from './validation/joi/joi.model'
81
- export * from './validation/joi/joi.shared.schemas'
82
- export * from './validation/joi/joi.validation.error'
83
- export * from './validation/joi/joi.validation.util'
84
- export type { StringSchema } from './validation/joi/string.extensions'
85
- export * from './yargs.util'
15
+ export * from './buffer/buffer.util.js'
16
+ export * from './colors/colors.js'
17
+ export * from './csv/csvReader.js'
18
+ export * from './csv/csvWriter.js'
19
+ export * from './csv/transformToCSV.js'
20
+ export * from './diff/tableDiff.js'
21
+ export * from './fs/fs2.js'
22
+ export * from './fs/json2env.js'
23
+ export * from './fs/kpy.js'
24
+ export * from './infra/process.util.js'
25
+ export * from './jwt/jwt.service.js'
26
+ export * from './log/log.util.js'
27
+ export * from './script/runScript.js'
28
+ export * from './security/crypto.util.js'
29
+ export * from './security/hash.util.js'
30
+ export * from './security/id.util.js'
31
+ export * from './security/nanoid.js'
32
+ export * from './security/secret.util.js'
33
+ export * from './slack/slack.service.js'
34
+ export * from './slack/slack.service.model.js'
35
+ export * from './stream/ndjson/ndjson.model.js'
36
+ export * from './stream/ndjson/ndjsonMap.js'
37
+ export * from './stream/ndjson/ndjsonStreamForEach.js'
38
+ export * from './stream/ndjson/transformJsonParse.js'
39
+ export * from './stream/ndjson/transformToNDJson.js'
40
+ export * from './stream/pipeline/pipeline.js'
41
+ export * from './stream/progressLogger.js'
42
+ export * from './stream/readable/readableCreate.js'
43
+ export * from './stream/readable/readableForEach.js'
44
+ export * from './stream/readable/readableFromArray.js'
45
+ export * from './stream/readable/readableToArray.js'
46
+ export * from './stream/stream.model.js'
47
+ export * from './stream/transform/transformChunk.js'
48
+ export * from './stream/transform/transformFilter.js'
49
+ export * from './stream/transform/transformLimit.js'
50
+ export * from './stream/transform/transformLogProgress.js'
51
+ export * from './stream/transform/transformMap.js'
52
+ export * from './stream/transform/transformMapSimple.js'
53
+ export * from './stream/transform/transformMapSync.js'
54
+ export * from './stream/transform/transformNoOp.js'
55
+ export * from './stream/transform/transformOffset.js'
56
+ export * from './stream/transform/transformSplit.js'
57
+ export * from './stream/transform/transformTap.js'
58
+ export * from './stream/transform/transformTee.js'
59
+ export * from './stream/transform/transformThrottle.js'
60
+ export * from './stream/transform/transformToArray.js'
61
+ export * from './stream/transform/worker/baseWorkerClass.js'
62
+ export * from './stream/transform/worker/transformMultiThreaded.js'
63
+ export * from './stream/transform/worker/transformMultiThreaded.model.js'
64
+ export * from './stream/writable/writableForEach.js'
65
+ export * from './stream/writable/writableFork.js'
66
+ export * from './stream/writable/writablePushToArray.js'
67
+ export * from './stream/writable/writableVoid.js'
68
+ export * from './string/inspect.js'
69
+ export * from './util/buildInfo.util.js'
70
+ export * from './util/env.util.js'
71
+ export * from './util/exec2.js'
72
+ export * from './util/git2.js'
73
+ export * from './util/lruMemoCache.js'
74
+ export * from './util/zip.util.js'
75
+ export * from './validation/ajv/ajv.util.js'
76
+ export * from './validation/ajv/ajvSchema.js'
77
+ export * from './validation/ajv/ajvValidationError.js'
78
+ export * from './validation/ajv/getAjv.js'
79
+ export * from './validation/joi/joi.extensions.js'
80
+ export * from './validation/joi/joi.model.js'
81
+ export * from './validation/joi/joi.shared.schemas.js'
82
+ export * from './validation/joi/joi.validation.error.js'
83
+ export * from './validation/joi/joi.validation.util.js'
84
+ export type { StringSchema } from './validation/joi/string.extensions.js'
85
+ export * from './yargs.util.js'
86
86
 
87
87
  export type {
88
88
  AlternativesSchema,
@@ -3,8 +3,8 @@ import { _assert, _errorDataAppend } from '@naturalcycles/js-lib'
3
3
  import type { AnySchema } from 'joi'
4
4
  import type { Algorithm, JwtHeader, SignOptions, VerifyOptions } from 'jsonwebtoken'
5
5
  import jsonwebtoken from 'jsonwebtoken'
6
- import { anyObjectSchema } from '../validation/joi/joi.shared.schemas'
7
- import { validate } from '../validation/joi/joi.validation.util'
6
+ import { anyObjectSchema } from '../validation/joi/joi.shared.schemas.js'
7
+ import { validate } from '../validation/joi/joi.validation.util.js'
8
8
  export { jsonwebtoken }
9
9
  export type { Algorithm, JwtHeader, SignOptions, VerifyOptions }
10
10
 
@@ -1,5 +1,5 @@
1
1
  import { commonLoggerCreate } from '@naturalcycles/js-lib'
2
- import { _inspect } from '../index'
2
+ import { _inspect } from '../index.js'
3
3
 
4
4
  /**
5
5
  * CommonLogger that logs to process.stdout directly (bypassing console.log).
@@ -1,8 +1,8 @@
1
1
  import os from 'node:os'
2
2
  import type { CommonLogger } from '@naturalcycles/js-lib'
3
3
  import { pDelay, setGlobalStringifyFunction } from '@naturalcycles/js-lib'
4
- import { dimGrey } from '../colors/colors'
5
- import { inspectStringifyFn } from '../string/inspect'
4
+ import { dimGrey } from '../colors/colors.js'
5
+ import { inspectStringifyFn } from '../string/inspect.js'
6
6
 
7
7
  export interface RunScriptOptions {
8
8
  /**
@@ -45,7 +45,6 @@ const { DEBUG_RUN_SCRIPT } = process.env
45
45
  * Set env DEBUG_RUN_SCRIPT for extra debugging.
46
46
  */
47
47
  export function runScript(fn: (...args: any[]) => any, opt: RunScriptOptions = {}): void {
48
- require('dotenv').config()
49
48
  logEnvironment()
50
49
  setGlobalStringifyFunction(inspectStringifyFn)
51
50
 
@@ -69,6 +68,8 @@ export function runScript(fn: (...args: any[]) => any, opt: RunScriptOptions = {
69
68
  const timeout = setTimeout(() => {}, 10000000)
70
69
 
71
70
  void (async () => {
71
+ await import('dotenv/config')
72
+
72
73
  try {
73
74
  await fn()
74
75
 
@@ -1,9 +1,9 @@
1
1
  import fs from 'node:fs'
2
2
  import path from 'node:path'
3
3
  import { _assert } from '@naturalcycles/js-lib'
4
- import { dimGrey, yellow } from '../colors/colors'
5
- import { fastGlob, fs2 } from '../index'
6
- import { decryptObject, decryptRandomIVBuffer } from '../security/crypto.util'
4
+ import { dimGrey, yellow } from '../colors/colors.js'
5
+ import { fastGlob, fs2 } from '../index.js'
6
+ import { decryptObject, decryptRandomIVBuffer } from '../security/crypto.util.js'
7
7
 
8
8
  export interface DecryptCLIOptions {
9
9
  dir: string[]
@@ -1,9 +1,9 @@
1
1
  import fs from 'node:fs'
2
2
  import path from 'node:path'
3
3
  import { _assert } from '@naturalcycles/js-lib'
4
- import { dimGrey, yellow } from '../colors/colors'
5
- import { fastGlob, fs2 } from '../index'
6
- import { encryptObject, encryptRandomIVBuffer } from '../security/crypto.util'
4
+ import { dimGrey, yellow } from '../colors/colors.js'
5
+ import { fastGlob, fs2 } from '../index.js'
6
+ import { encryptObject, encryptRandomIVBuffer } from '../security/crypto.util.js'
7
7
 
8
8
  export interface EncryptCLIOptions {
9
9
  pattern: string[]
@@ -1,7 +1,7 @@
1
1
  import crypto from 'node:crypto'
2
2
  import type { Base64String, StringMap } from '@naturalcycles/js-lib'
3
3
  import { _stringMapEntries } from '@naturalcycles/js-lib'
4
- import { md5AsBuffer, sha256AsBuffer } from './hash.util'
4
+ import { md5AsBuffer, sha256AsBuffer } from './hash.util.js'
5
5
 
6
6
  const algorithm = 'aes-256-cbc'
7
7
 
@@ -4,7 +4,7 @@ import {
4
4
  ALPHABET_ALPHANUMERIC_LOWERCASE,
5
5
  ALPHABET_NONAMBIGUOUS,
6
6
  nanoIdCustomAlphabet,
7
- } from './nanoid'
7
+ } from './nanoid.js'
8
8
 
9
9
  /**
10
10
  * Generate cryptographically-secure string id.
@@ -1,7 +1,7 @@
1
1
  import { existsSync, readFileSync } from 'node:fs'
2
2
  import type { Base64String, StringMap } from '@naturalcycles/js-lib'
3
3
  import { _assert, _jsonParseIfPossible } from '@naturalcycles/js-lib'
4
- import { decryptObject, decryptRandomIVBuffer } from './crypto.util'
4
+ import { decryptObject, decryptRandomIVBuffer } from './crypto.util.js'
5
5
 
6
6
  let loaded = false
7
7
 
@@ -14,7 +14,7 @@ const secretMap: StringMap = {}
14
14
  * Does NOT delete previous secrets from secretMap.
15
15
  */
16
16
  export function loadSecretsFromEnv(): void {
17
- require('dotenv').config() // ensure .env is loaded
17
+ // require('dotenv').config() // ensure .env is loaded
18
18
 
19
19
  const secrets: StringMap = {}
20
20
  Object.keys(process.env)
@@ -1,5 +1,5 @@
1
1
  import type { AnyObject, CommonLogger } from '@naturalcycles/js-lib'
2
- import type { InspectAnyOptions } from '..'
2
+ import type { InspectAnyOptions } from '../index.js'
3
3
 
4
4
  /**
5
5
  * Properties that exists both in SlackApiBody (as per Slack API) and SlackMessage (our abstraction).
@@ -1,13 +1,13 @@
1
1
  import type { AnyObject, CommonLogger, CommonLogLevel, Fetcher } from '@naturalcycles/js-lib'
2
2
  import { _omit, commonLoggerMinLevel, getFetcher, localTime, PQueue } from '@naturalcycles/js-lib'
3
- import type { InspectAnyOptions } from '..'
4
- import { _inspect } from '..'
3
+ import type { InspectAnyOptions } from '../index.js'
4
+ import { _inspect } from '../index.js'
5
5
  import type {
6
6
  SlackApiBody,
7
7
  SlackAttachmentField,
8
8
  SlackMessage,
9
9
  SlackServiceCfg,
10
- } from './slack.service.model'
10
+ } from './slack.service.model.js'
11
11
 
12
12
  const GAE = !!process.env['GAE_INSTANCE']
13
13