@naturalcycles/nodejs-lib 13.41.1 → 13.43.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.
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/script/runScript.js +28 -0
- package/dist/secret/secrets-decrypt.util.js +4 -4
- package/dist/yargs.util.d.ts +6 -0
- package/dist/yargs.util.js +14 -0
- package/package.json +15 -13
- package/src/index.ts +1 -0
- package/src/script/runScript.ts +43 -0
- package/src/secret/secrets-decrypt.util.ts +4 -4
- package/src/yargs.util.ts +11 -0
package/dist/index.d.ts
CHANGED
|
@@ -72,5 +72,6 @@ export * from './validation/joi/joi.shared.schemas';
|
|
|
72
72
|
export * from './validation/joi/joi.validation.error';
|
|
73
73
|
export * from './validation/joi/joi.validation.util';
|
|
74
74
|
export type { StringSchema } from './validation/joi/string.extensions';
|
|
75
|
+
export * from './yargs.util';
|
|
75
76
|
export type { AlternativesSchema, AnySchema, ArraySchema, BinarySchema, BooleanSchema, DateSchema, FastGlobOptions, FunctionSchema, ObjectSchema, ValidationErrorItem, };
|
|
76
77
|
export { Ajv, fastGlob };
|
package/dist/index.js
CHANGED
|
@@ -75,3 +75,4 @@ tslib_1.__exportStar(require("./validation/joi/joi.model"), exports);
|
|
|
75
75
|
tslib_1.__exportStar(require("./validation/joi/joi.shared.schemas"), exports);
|
|
76
76
|
tslib_1.__exportStar(require("./validation/joi/joi.validation.error"), exports);
|
|
77
77
|
tslib_1.__exportStar(require("./validation/joi/joi.validation.util"), exports);
|
|
78
|
+
tslib_1.__exportStar(require("./yargs.util"), exports);
|
package/dist/script/runScript.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.runScript = runScript;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const node_os_1 = tslib_1.__importDefault(require("node:os"));
|
|
6
|
+
const node_util_1 = require("node:util");
|
|
4
7
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
5
8
|
const inspect_1 = require("../string/inspect");
|
|
6
9
|
const { DEBUG_RUN_SCRIPT } = process.env;
|
|
@@ -23,6 +26,7 @@ const { DEBUG_RUN_SCRIPT } = process.env;
|
|
|
23
26
|
* Set env DEBUG_RUN_SCRIPT for extra debugging.
|
|
24
27
|
*/
|
|
25
28
|
function runScript(fn, opt = {}) {
|
|
29
|
+
logEnvironment();
|
|
26
30
|
(0, js_lib_1.setGlobalStringifyFunction)(inspect_1.inspectStringifyFn);
|
|
27
31
|
const { logger = console, noExit, registerUncaughtExceptionHandlers = true } = opt;
|
|
28
32
|
if (registerUncaughtExceptionHandlers || DEBUG_RUN_SCRIPT) {
|
|
@@ -61,3 +65,27 @@ function runScript(fn, opt = {}) {
|
|
|
61
65
|
}
|
|
62
66
|
})();
|
|
63
67
|
}
|
|
68
|
+
function logEnvironment() {
|
|
69
|
+
const { platform, arch, versions: { node }, env: { CPU_LIMIT, NODE_OPTIONS = 'not defined' }, } = process;
|
|
70
|
+
const cpuLimit = Number(CPU_LIMIT) || undefined;
|
|
71
|
+
const availableParallelism = node_os_1.default.availableParallelism?.();
|
|
72
|
+
const cpus = node_os_1.default.cpus().length;
|
|
73
|
+
console.log(dimGrey(Object.entries({
|
|
74
|
+
node: `${node} ${platform} ${arch}`,
|
|
75
|
+
NODE_OPTIONS,
|
|
76
|
+
cpus,
|
|
77
|
+
availableParallelism,
|
|
78
|
+
cpuLimit,
|
|
79
|
+
})
|
|
80
|
+
.map(([k, v]) => `${k}: ${v}`)
|
|
81
|
+
.join(', ')));
|
|
82
|
+
if (!NODE_OPTIONS) {
|
|
83
|
+
console.warn(`NODE_OPTIONS env variable is not defined. You may run into out-of-memory issues when running memory-intensive scripts. It's recommended to set it to:\n--max-old-space-size=12000`);
|
|
84
|
+
}
|
|
85
|
+
else if (NODE_OPTIONS.includes('max_old')) {
|
|
86
|
+
console.warn(`It looks like you're using "max_old_space_size" syntax with underscores instead of dashes - it's WRONG and doesn't work in environment variables. Strongly advised to rename it to "max-old-space-size"`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function dimGrey(s) {
|
|
90
|
+
return (0, node_util_1.styleText)(['dim', 'grey'], s);
|
|
91
|
+
}
|
|
@@ -9,10 +9,10 @@ const colors_1 = require("../colors/colors");
|
|
|
9
9
|
const index_1 = require("../index");
|
|
10
10
|
const crypto_util_1 = require("../security/crypto.util");
|
|
11
11
|
// Debug it like this:
|
|
12
|
-
// yarn
|
|
13
|
-
// yarn
|
|
14
|
-
// yarn
|
|
15
|
-
// yarn
|
|
12
|
+
// yarn tsx scripts/./src/bin/secrets-encrypt.ts --file ./src/test/secrets2.plain.json --jsonMode --encKey MPd/30v0Zcce4I5mfwF4NSXrpTYD9OO4/fIqw6rjNiWp2b1GN9Xm8nQZqr7c9kKSsATqtwe0HkJFDUGzDSow44GDgDICgB1u1rGa5eNqtxnOVGRR+lIinCvN/1OnpjzeoJy2bStXPj1DKx8anMqgA8SoOZdlWRNSkEeZlolru8Ey0ujZo22dfwMyRIEniLcqvBm/iMiAkV82fn/TxYw05GarAoJcrfPeDBvuOXsARnMCyX18qTFL0iojxeTU8JHxr8TX3eXDq9cJJmridEKlwRIAzADwtetI4ttlP8lwJj1pmgsBIN3iqYssZYCkZ3HMV6BoEc7LTI5z/45rKrAT1A==
|
|
13
|
+
// yarn tsx scripts/./src/bin/secrets-decrypt.ts --file ./src/test/secrets2.json --jsonMode --encKey MPd/30v0Zcce4I5mfwF4NSXrpTYD9OO4/fIqw6rjNiWp2b1GN9Xm8nQZqr7c9kKSsATqtwe0HkJFDUGzDSow44GDgDICgB1u1rGa5eNqtxnOVGRR+lIinCvN/1OnpjzeoJy2bStXPj1DKx8anMqgA8SoOZdlWRNSkEeZlolru8Ey0ujZo22dfwMyRIEniLcqvBm/iMiAkV82fn/TxYw05GarAoJcrfPeDBvuOXsARnMCyX18qTFL0iojxeTU8JHxr8TX3eXDq9cJJmridEKlwRIAzADwtetI4ttlP8lwJj1pmgsBIN3iqYssZYCkZ3HMV6BoEc7LTI5z/45rKrAT1A==
|
|
14
|
+
// yarn tsx scripts/./src/bin/secrets-encrypt.ts --file ./src/test/secrets.json -encKey MPd/30v0Zcce4I5mfwF4NSXrpTYD9OO4/fIqw6rjNiWp2b1GN9Xm8nQZqr7c9kKSsATqtwe0HkJFDUGzDSow44GDgDICgB1u1rGa5eNqtxnOVGRR+lIinCvN/1OnpjzeoJy2bStXPj1DKx8anMqgA8SoOZdlWRNSkEeZlolru8Ey0ujZo22dfwMyRIEniLcqvBm/iMiAkV82fn/TxYw05GarAoJcrfPeDBvuOXsARnMCyX18qTFL0iojxeTU8JHxr8TX3eXDq9cJJmridEKlwRIAzADwtetI4ttlP8lwJj1pmgsBIN3iqYssZYCkZ3HMV6BoEc7LTI5z/45rKrAT1A==
|
|
15
|
+
// yarn tsx scripts/./src/bin/secrets-decrypt.ts --file ./src/test/secrets.json.enc -encKey MPd/30v0Zcce4I5mfwF4NSXrpTYD9OO4/fIqw6rjNiWp2b1GN9Xm8nQZqr7c9kKSsATqtwe0HkJFDUGzDSow44GDgDICgB1u1rGa5eNqtxnOVGRR+lIinCvN/1OnpjzeoJy2bStXPj1DKx8anMqgA8SoOZdlWRNSkEeZlolru8Ey0ujZo22dfwMyRIEniLcqvBm/iMiAkV82fn/TxYw05GarAoJcrfPeDBvuOXsARnMCyX18qTFL0iojxeTU8JHxr8TX3eXDq9cJJmridEKlwRIAzADwtetI4ttlP8lwJj1pmgsBIN3iqYssZYCkZ3HMV6BoEc7LTI5z/45rKrAT1A==
|
|
16
16
|
/**
|
|
17
17
|
* Decrypts all files in given directory (*.enc), saves decrypted versions without ending `.enc`.
|
|
18
18
|
* Using provided encKey.
|
|
@@ -0,0 +1,14 @@
|
|
|
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");
|
|
7
|
+
/**
|
|
8
|
+
* Quick yargs helper to make it work in esm.
|
|
9
|
+
* It also allows to not have yargs and `@types/yargs` to be declared as dependencies.
|
|
10
|
+
*/
|
|
11
|
+
// 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));
|
|
14
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/nodejs-lib",
|
|
3
|
-
"version": "13.
|
|
3
|
+
"version": "13.43.0",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"prepare": "husky",
|
|
6
6
|
"build": "dev-lib build",
|
|
@@ -10,19 +10,20 @@
|
|
|
10
10
|
"lbt": "dev-lib lbt",
|
|
11
11
|
"docs-serve": "vuepress dev docs",
|
|
12
12
|
"docs-build": "vuepress build docs",
|
|
13
|
-
"slack-this-debug": "
|
|
14
|
-
"secrets-gen-key-debug": "
|
|
15
|
-
"secrets-encrypt-debug": "
|
|
16
|
-
"secrets-decrypt-debug": "
|
|
17
|
-
"kpy-debug": "
|
|
18
|
-
"kpy-debug2": "
|
|
19
|
-
"kpy-debug3": "
|
|
20
|
-
"json2env-debug": "
|
|
13
|
+
"slack-this-debug": "tsx ./src/bin/slack-this.ts --channel test --msg 'Hello slack!'",
|
|
14
|
+
"secrets-gen-key-debug": "tsx ./src/bin/secrets-gen-key.ts",
|
|
15
|
+
"secrets-encrypt-debug": "tsx ./src/bin/secrets-encrypt.ts",
|
|
16
|
+
"secrets-decrypt-debug": "tsx ./src/bin/secrets-decrypt.ts",
|
|
17
|
+
"kpy-debug": "tsx ./src/bin/kpy.ts --verbose scripts tmp/scripts",
|
|
18
|
+
"kpy-debug2": "tsx ./src/bin/kpy.ts --verbose scripts bench non-ex non-ex/** colors* tmp/scripts",
|
|
19
|
+
"kpy-debug3": "tsx ./src/bin/kpy.ts --verbose src colors csv stream non-ex non-ex/** tmp/src",
|
|
20
|
+
"json2env-debug": "tsx ./src/bin/json2env.ts ./src/test/someFile.json"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@naturalcycles/js-lib": "^14",
|
|
24
24
|
"@types/js-yaml": "^4",
|
|
25
25
|
"@types/jsonwebtoken": "^9",
|
|
26
|
+
"@types/yargs": "^16",
|
|
26
27
|
"ajv": "^8",
|
|
27
28
|
"ajv-formats": "^3",
|
|
28
29
|
"ajv-keywords": "^5",
|
|
@@ -38,11 +39,12 @@
|
|
|
38
39
|
},
|
|
39
40
|
"devDependencies": {
|
|
40
41
|
"@naturalcycles/bench-lib": "^3",
|
|
41
|
-
"@naturalcycles/dev-lib": "^
|
|
42
|
+
"@naturalcycles/dev-lib": "^16",
|
|
42
43
|
"@types/node": "^22",
|
|
43
44
|
"@types/through2-concurrent": "^2",
|
|
44
|
-
"@
|
|
45
|
-
"
|
|
45
|
+
"@vitest/coverage-v8": "^3",
|
|
46
|
+
"tsx": "^4",
|
|
47
|
+
"vitest": "^3"
|
|
46
48
|
},
|
|
47
49
|
"bin": {
|
|
48
50
|
"kpy": "dist/bin/kpy.js",
|
|
@@ -71,7 +73,7 @@
|
|
|
71
73
|
"url": "https://github.com/NaturalCycles/nodejs-lib"
|
|
72
74
|
},
|
|
73
75
|
"engines": {
|
|
74
|
-
"node": ">=22.
|
|
76
|
+
"node": ">=22.12.0"
|
|
75
77
|
},
|
|
76
78
|
"description": "Standard library for Node.js",
|
|
77
79
|
"author": "Natural Cycles Team",
|
package/src/index.ts
CHANGED
|
@@ -82,6 +82,7 @@ export * from './validation/joi/joi.shared.schemas'
|
|
|
82
82
|
export * from './validation/joi/joi.validation.error'
|
|
83
83
|
export * from './validation/joi/joi.validation.util'
|
|
84
84
|
export type { StringSchema } from './validation/joi/string.extensions'
|
|
85
|
+
export * from './yargs.util'
|
|
85
86
|
|
|
86
87
|
export type {
|
|
87
88
|
AlternativesSchema,
|
package/src/script/runScript.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import os from 'node:os'
|
|
2
|
+
import { styleText } from 'node:util'
|
|
1
3
|
import type { CommonLogger } from '@naturalcycles/js-lib'
|
|
2
4
|
import { pDelay, setGlobalStringifyFunction } from '@naturalcycles/js-lib'
|
|
3
5
|
import { inspectStringifyFn } from '../string/inspect'
|
|
@@ -43,6 +45,7 @@ const { DEBUG_RUN_SCRIPT } = process.env
|
|
|
43
45
|
* Set env DEBUG_RUN_SCRIPT for extra debugging.
|
|
44
46
|
*/
|
|
45
47
|
export function runScript(fn: (...args: any[]) => any, opt: RunScriptOptions = {}): void {
|
|
48
|
+
logEnvironment()
|
|
46
49
|
setGlobalStringifyFunction(inspectStringifyFn)
|
|
47
50
|
|
|
48
51
|
const { logger = console, noExit, registerUncaughtExceptionHandlers = true } = opt
|
|
@@ -86,3 +89,43 @@ export function runScript(fn: (...args: any[]) => any, opt: RunScriptOptions = {
|
|
|
86
89
|
}
|
|
87
90
|
})()
|
|
88
91
|
}
|
|
92
|
+
|
|
93
|
+
function logEnvironment(): void {
|
|
94
|
+
const {
|
|
95
|
+
platform,
|
|
96
|
+
arch,
|
|
97
|
+
versions: { node },
|
|
98
|
+
env: { CPU_LIMIT, NODE_OPTIONS = 'not defined' },
|
|
99
|
+
} = process
|
|
100
|
+
|
|
101
|
+
const cpuLimit = Number(CPU_LIMIT) || undefined
|
|
102
|
+
const availableParallelism = os.availableParallelism?.()
|
|
103
|
+
const cpus = os.cpus().length
|
|
104
|
+
console.log(
|
|
105
|
+
dimGrey(
|
|
106
|
+
Object.entries({
|
|
107
|
+
node: `${node} ${platform} ${arch}`,
|
|
108
|
+
NODE_OPTIONS,
|
|
109
|
+
cpus,
|
|
110
|
+
availableParallelism,
|
|
111
|
+
cpuLimit,
|
|
112
|
+
})
|
|
113
|
+
.map(([k, v]) => `${k}: ${v}`)
|
|
114
|
+
.join(', '),
|
|
115
|
+
),
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
if (!NODE_OPTIONS) {
|
|
119
|
+
console.warn(
|
|
120
|
+
`NODE_OPTIONS env variable is not defined. You may run into out-of-memory issues when running memory-intensive scripts. It's recommended to set it to:\n--max-old-space-size=12000`,
|
|
121
|
+
)
|
|
122
|
+
} else if (NODE_OPTIONS.includes('max_old')) {
|
|
123
|
+
console.warn(
|
|
124
|
+
`It looks like you're using "max_old_space_size" syntax with underscores instead of dashes - it's WRONG and doesn't work in environment variables. Strongly advised to rename it to "max-old-space-size"`,
|
|
125
|
+
)
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function dimGrey(s: string): string {
|
|
130
|
+
return styleText(['dim', 'grey'], s)
|
|
131
|
+
}
|
|
@@ -14,11 +14,11 @@ export interface DecryptCLIOptions {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
// Debug it like this:
|
|
17
|
-
// yarn
|
|
18
|
-
// yarn
|
|
17
|
+
// yarn tsx scripts/./src/bin/secrets-encrypt.ts --file ./src/test/secrets2.plain.json --jsonMode --encKey MPd/30v0Zcce4I5mfwF4NSXrpTYD9OO4/fIqw6rjNiWp2b1GN9Xm8nQZqr7c9kKSsATqtwe0HkJFDUGzDSow44GDgDICgB1u1rGa5eNqtxnOVGRR+lIinCvN/1OnpjzeoJy2bStXPj1DKx8anMqgA8SoOZdlWRNSkEeZlolru8Ey0ujZo22dfwMyRIEniLcqvBm/iMiAkV82fn/TxYw05GarAoJcrfPeDBvuOXsARnMCyX18qTFL0iojxeTU8JHxr8TX3eXDq9cJJmridEKlwRIAzADwtetI4ttlP8lwJj1pmgsBIN3iqYssZYCkZ3HMV6BoEc7LTI5z/45rKrAT1A==
|
|
18
|
+
// yarn tsx scripts/./src/bin/secrets-decrypt.ts --file ./src/test/secrets2.json --jsonMode --encKey MPd/30v0Zcce4I5mfwF4NSXrpTYD9OO4/fIqw6rjNiWp2b1GN9Xm8nQZqr7c9kKSsATqtwe0HkJFDUGzDSow44GDgDICgB1u1rGa5eNqtxnOVGRR+lIinCvN/1OnpjzeoJy2bStXPj1DKx8anMqgA8SoOZdlWRNSkEeZlolru8Ey0ujZo22dfwMyRIEniLcqvBm/iMiAkV82fn/TxYw05GarAoJcrfPeDBvuOXsARnMCyX18qTFL0iojxeTU8JHxr8TX3eXDq9cJJmridEKlwRIAzADwtetI4ttlP8lwJj1pmgsBIN3iqYssZYCkZ3HMV6BoEc7LTI5z/45rKrAT1A==
|
|
19
19
|
|
|
20
|
-
// yarn
|
|
21
|
-
// yarn
|
|
20
|
+
// yarn tsx scripts/./src/bin/secrets-encrypt.ts --file ./src/test/secrets.json -encKey MPd/30v0Zcce4I5mfwF4NSXrpTYD9OO4/fIqw6rjNiWp2b1GN9Xm8nQZqr7c9kKSsATqtwe0HkJFDUGzDSow44GDgDICgB1u1rGa5eNqtxnOVGRR+lIinCvN/1OnpjzeoJy2bStXPj1DKx8anMqgA8SoOZdlWRNSkEeZlolru8Ey0ujZo22dfwMyRIEniLcqvBm/iMiAkV82fn/TxYw05GarAoJcrfPeDBvuOXsARnMCyX18qTFL0iojxeTU8JHxr8TX3eXDq9cJJmridEKlwRIAzADwtetI4ttlP8lwJj1pmgsBIN3iqYssZYCkZ3HMV6BoEc7LTI5z/45rKrAT1A==
|
|
21
|
+
// yarn tsx scripts/./src/bin/secrets-decrypt.ts --file ./src/test/secrets.json.enc -encKey MPd/30v0Zcce4I5mfwF4NSXrpTYD9OO4/fIqw6rjNiWp2b1GN9Xm8nQZqr7c9kKSsATqtwe0HkJFDUGzDSow44GDgDICgB1u1rGa5eNqtxnOVGRR+lIinCvN/1OnpjzeoJy2bStXPj1DKx8anMqgA8SoOZdlWRNSkEeZlolru8Ey0ujZo22dfwMyRIEniLcqvBm/iMiAkV82fn/TxYw05GarAoJcrfPeDBvuOXsARnMCyX18qTFL0iojxeTU8JHxr8TX3eXDq9cJJmridEKlwRIAzADwtetI4ttlP8lwJj1pmgsBIN3iqYssZYCkZ3HMV6BoEc7LTI5z/45rKrAT1A==
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* Decrypts all files in given directory (*.enc), saves decrypted versions without ending `.enc`.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import yargs from 'yargs'
|
|
2
|
+
import { hideBin } from 'yargs/helpers'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Quick yargs helper to make it work in esm.
|
|
6
|
+
* It also allows to not have yargs and `@types/yargs` to be declared as dependencies.
|
|
7
|
+
*/
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type, @typescript-eslint/explicit-module-boundary-types
|
|
9
|
+
export function _yargs() {
|
|
10
|
+
return yargs(hideBin(process.argv))
|
|
11
|
+
}
|