@naturalcycles/nodejs-lib 14.0.2 → 14.2.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/fs/kpy.js +4 -3
- package/dist/index.d.ts +3 -4
- package/dist/index.js +2 -2
- package/dist/log/log.util.js +1 -1
- package/dist/script/runScript.d.ts +1 -0
- package/dist/script/runScript.js +25 -9
- package/dist/secret/secrets-decrypt.util.js +3 -2
- package/dist/secret/secrets-encrypt.util.js +3 -2
- package/dist/stream/transform/worker/transformMultiThreaded.js +1 -5
- package/dist/validation/ajv/ajv.util.d.ts +2 -2
- package/dist/validation/ajv/ajv.util.js +3 -2
- package/dist/validation/ajv/ajvSchema.js +3 -1
- package/package.json +2 -3
- package/src/fs/kpy.ts +4 -3
- package/src/index.ts +2 -4
- package/src/log/log.util.ts +1 -1
- package/src/script/runScript.ts +30 -11
- package/src/secret/secrets-decrypt.util.ts +3 -2
- package/src/secret/secrets-encrypt.util.ts +3 -2
- package/src/stream/transform/worker/transformMultiThreaded.ts +1 -6
- package/src/validation/ajv/ajv.util.ts +8 -4
- package/src/validation/ajv/ajvSchema.ts +3 -1
package/dist/fs/kpy.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { _since, localTime } from '@naturalcycles/js-lib';
|
|
3
|
+
import { glob, globSync } from 'tinyglobby';
|
|
3
4
|
import { boldWhite, dimGrey, grey, yellow } from '../colors/colors.js';
|
|
4
|
-
import {
|
|
5
|
+
import { fs2 } from './fs2.js';
|
|
5
6
|
export async function kpy(opt) {
|
|
6
7
|
const started = localTime.nowUnixMillis();
|
|
7
8
|
kpyPrepare(opt);
|
|
8
|
-
const filenames = await
|
|
9
|
+
const filenames = await glob(opt.inputPatterns, {
|
|
9
10
|
cwd: opt.baseDir,
|
|
10
11
|
dot: opt.dotfiles,
|
|
11
12
|
});
|
|
@@ -34,7 +35,7 @@ export async function kpy(opt) {
|
|
|
34
35
|
export function kpySync(opt) {
|
|
35
36
|
const started = localTime.nowUnixMillis();
|
|
36
37
|
kpyPrepare(opt);
|
|
37
|
-
const filenames =
|
|
38
|
+
const filenames = globSync(opt.inputPatterns, {
|
|
38
39
|
cwd: opt.baseDir,
|
|
39
40
|
dot: opt.dotfiles,
|
|
40
41
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import Ajv from 'ajv';
|
|
2
|
-
|
|
3
|
-
import fastGlob from 'fast-glob';
|
|
2
|
+
export { glob, globSync } from 'tinyglobby';
|
|
4
3
|
import type { AlternativesSchema, AnySchema, ArraySchema, BinarySchema, BooleanSchema, DateSchema, FunctionSchema, ObjectSchema, ValidationErrorItem } from 'joi';
|
|
5
4
|
export * from './buffer/buffer.util.js';
|
|
6
5
|
export * from './colors/colors.js';
|
|
@@ -73,5 +72,5 @@ export * from './validation/joi/joi.validation.error.js';
|
|
|
73
72
|
export * from './validation/joi/joi.validation.util.js';
|
|
74
73
|
export type { StringSchema } from './validation/joi/string.extensions.js';
|
|
75
74
|
export * from './yargs.util.js';
|
|
76
|
-
export type { AlternativesSchema, AnySchema, ArraySchema, BinarySchema, BooleanSchema, DateSchema,
|
|
77
|
-
export { Ajv
|
|
75
|
+
export type { AlternativesSchema, AnySchema, ArraySchema, BinarySchema, BooleanSchema, DateSchema, FunctionSchema, ObjectSchema, ValidationErrorItem, };
|
|
76
|
+
export { Ajv };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Ajv from 'ajv';
|
|
2
|
-
|
|
2
|
+
export { glob, globSync } from 'tinyglobby';
|
|
3
3
|
export * from './buffer/buffer.util.js';
|
|
4
4
|
export * from './colors/colors.js';
|
|
5
5
|
export * from './csv/csvReader.js';
|
|
@@ -70,4 +70,4 @@ export * from './validation/joi/joi.shared.schemas.js';
|
|
|
70
70
|
export * from './validation/joi/joi.validation.error.js';
|
|
71
71
|
export * from './validation/joi/joi.validation.util.js';
|
|
72
72
|
export * from './yargs.util.js';
|
|
73
|
-
export { Ajv
|
|
73
|
+
export { Ajv };
|
package/dist/log/log.util.js
CHANGED
package/dist/script/runScript.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import 'dotenv/config';
|
|
1
2
|
import os from 'node:os';
|
|
2
3
|
import { pDelay, setGlobalStringifyFunction } from '@naturalcycles/js-lib';
|
|
3
4
|
import { dimGrey } from '../colors/colors.js';
|
|
@@ -22,7 +23,7 @@ const { DEBUG_RUN_SCRIPT } = process.env;
|
|
|
22
23
|
* Set env DEBUG_RUN_SCRIPT for extra debugging.
|
|
23
24
|
*/
|
|
24
25
|
export function runScript(fn, opt = {}) {
|
|
25
|
-
|
|
26
|
+
checkAndlogEnvironment();
|
|
26
27
|
setGlobalStringifyFunction(inspectStringifyFn);
|
|
27
28
|
const { logger = console, noExit, registerUncaughtExceptionHandlers = true } = opt;
|
|
28
29
|
if (registerUncaughtExceptionHandlers || DEBUG_RUN_SCRIPT) {
|
|
@@ -40,7 +41,6 @@ export function runScript(fn, opt = {}) {
|
|
|
40
41
|
// fake timeout, to ensure node.js process won't exit until runScript main promise is resolved
|
|
41
42
|
const timeout = setTimeout(() => { }, 10000000);
|
|
42
43
|
void (async () => {
|
|
43
|
-
await import('dotenv/config');
|
|
44
44
|
try {
|
|
45
45
|
await fn();
|
|
46
46
|
await pDelay(); // to ensure all async operations are completed
|
|
@@ -62,24 +62,40 @@ export function runScript(fn, opt = {}) {
|
|
|
62
62
|
}
|
|
63
63
|
})();
|
|
64
64
|
}
|
|
65
|
-
function
|
|
66
|
-
const { platform, arch, versions: { node }, env: { CPU_LIMIT, NODE_OPTIONS }, } = process;
|
|
65
|
+
function checkAndlogEnvironment() {
|
|
66
|
+
const { platform, arch, versions: { node }, env: { CPU_LIMIT, NODE_OPTIONS, TZ }, } = process;
|
|
67
67
|
const cpuLimit = Number(CPU_LIMIT) || undefined;
|
|
68
68
|
const availableParallelism = os.availableParallelism?.();
|
|
69
69
|
const cpus = os.cpus().length;
|
|
70
|
-
console.log(dimGrey(
|
|
70
|
+
console.log(dimGrey(formatObject({
|
|
71
71
|
node: `${node} ${platform} ${arch}`,
|
|
72
|
-
NODE_OPTIONS: NODE_OPTIONS || 'not defined',
|
|
73
72
|
cpus,
|
|
74
73
|
availableParallelism,
|
|
75
74
|
cpuLimit,
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
|
|
75
|
+
}) +
|
|
76
|
+
'\n' +
|
|
77
|
+
formatObject({
|
|
78
|
+
NODE_OPTIONS: NODE_OPTIONS || 'not defined',
|
|
79
|
+
TZ,
|
|
80
|
+
})));
|
|
79
81
|
if (!NODE_OPTIONS) {
|
|
80
82
|
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`);
|
|
81
83
|
}
|
|
82
84
|
else if (NODE_OPTIONS.includes('max_old')) {
|
|
83
85
|
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"`);
|
|
84
86
|
}
|
|
87
|
+
if (!TZ) {
|
|
88
|
+
console.error([
|
|
89
|
+
'!!! TZ environment variable is required to be set, but was not set.',
|
|
90
|
+
'The runScript will exit and not continue further because of that,',
|
|
91
|
+
'please ensure the TZ variable and try again.',
|
|
92
|
+
'If you are running locally, you can add TZ=UTC to the local .env file.',
|
|
93
|
+
].join('\n'));
|
|
94
|
+
process.exit(1);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function formatObject(obj) {
|
|
98
|
+
return Object.entries(obj)
|
|
99
|
+
.map(([k, v]) => `${k}: ${v}`)
|
|
100
|
+
.join(', ');
|
|
85
101
|
}
|
|
@@ -1,8 +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 { globSync } from 'tinyglobby';
|
|
4
5
|
import { dimGrey, yellow } from '../colors/colors.js';
|
|
5
|
-
import {
|
|
6
|
+
import { fs2 } from '../fs/fs2.js';
|
|
6
7
|
import { decryptObject, decryptRandomIVBuffer } from '../security/crypto.util.js';
|
|
7
8
|
// Debug it like this:
|
|
8
9
|
// yarn tsx scripts/./src/bin/secrets-encrypt.ts --file ./src/test/secrets2.plain.json --jsonMode --encKey MPd/30v0Zcce4I5mfwF4NSXrpTYD9OO4/fIqw6rjNiWp2b1GN9Xm8nQZqr7c9kKSsATqtwe0HkJFDUGzDSow44GDgDICgB1u1rGa5eNqtxnOVGRR+lIinCvN/1OnpjzeoJy2bStXPj1DKx8anMqgA8SoOZdlWRNSkEeZlolru8Ey0ujZo22dfwMyRIEniLcqvBm/iMiAkV82fn/TxYw05GarAoJcrfPeDBvuOXsARnMCyX18qTFL0iojxeTU8JHxr8TX3eXDq9cJJmridEKlwRIAzADwtetI4ttlP8lwJj1pmgsBIN3iqYssZYCkZ3HMV6BoEc7LTI5z/45rKrAT1A==
|
|
@@ -16,7 +17,7 @@ import { decryptObject, decryptRandomIVBuffer } from '../security/crypto.util.js
|
|
|
16
17
|
export function secretsDecrypt(dir, file, encKeyBuffer, del = false, jsonMode = false) {
|
|
17
18
|
// If `file` is provided - only this one file is used
|
|
18
19
|
const patterns = file ? [file] : dir.map(d => `${d}/**/*.enc`);
|
|
19
|
-
const filenames =
|
|
20
|
+
const filenames = globSync(patterns);
|
|
20
21
|
filenames.forEach(filename => {
|
|
21
22
|
let plainFilename;
|
|
22
23
|
if (jsonMode) {
|
|
@@ -1,8 +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 { globSync } from 'tinyglobby';
|
|
4
5
|
import { dimGrey, yellow } from '../colors/colors.js';
|
|
5
|
-
import {
|
|
6
|
+
import { fs2 } from '../fs/fs2.js';
|
|
6
7
|
import { encryptObject, encryptRandomIVBuffer } from '../security/crypto.util.js';
|
|
7
8
|
/**
|
|
8
9
|
* Encrypts all files in given directory (except *.enc), saves encrypted versions as filename.ext.enc.
|
|
@@ -15,7 +16,7 @@ export function secretsEncrypt(pattern, file, encKeyBuffer, del = false, jsonMod
|
|
|
15
16
|
...pattern,
|
|
16
17
|
`!**/*.enc`, // excluding already encoded
|
|
17
18
|
];
|
|
18
|
-
const filenames =
|
|
19
|
+
const filenames = globSync(patterns);
|
|
19
20
|
let encFilename;
|
|
20
21
|
filenames.forEach(filename => {
|
|
21
22
|
if (jsonMode) {
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import { dirname } from 'node:path';
|
|
2
|
-
import { fileURLToPath } from 'node:url';
|
|
3
1
|
import { Worker } from 'node:worker_threads';
|
|
4
2
|
import { _range, pDefer } from '@naturalcycles/js-lib';
|
|
5
3
|
import through2Concurrent from 'through2-concurrent';
|
|
6
|
-
const
|
|
7
|
-
const __dirname = dirname(__filename);
|
|
8
|
-
const workerProxyFilePath = `${__dirname}/workerClassProxy.js`;
|
|
4
|
+
const workerProxyFilePath = `${import.meta.dirname}/workerClassProxy.js`;
|
|
9
5
|
/**
|
|
10
6
|
* Spawns a pool of Workers (threads).
|
|
11
7
|
* Distributes (using round-robin, equally) all inputs over Workers.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { JsonSchema } from '@naturalcycles/js-lib';
|
|
2
|
-
import type {
|
|
2
|
+
import type { GlobOptions } from 'tinyglobby';
|
|
3
3
|
import type { AjvSchemaCfg } from './ajvSchema.js';
|
|
4
4
|
import { AjvSchema } from './ajvSchema.js';
|
|
5
5
|
/**
|
|
@@ -10,7 +10,7 @@ import { AjvSchema } from './ajvSchema.js';
|
|
|
10
10
|
*
|
|
11
11
|
* @experimental
|
|
12
12
|
*/
|
|
13
|
-
export declare function readJsonSchemas(patterns: string | string[], opt?:
|
|
13
|
+
export declare function readJsonSchemas(patterns: string | string[], opt?: Omit<GlobOptions, 'patterns'>): JsonSchema[];
|
|
14
14
|
/**
|
|
15
15
|
* Reads json schemas from given dir (glob pattern).
|
|
16
16
|
* Creates new AjvSchema for each of them (ajv validates them upon creation).
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { globSync } from 'tinyglobby';
|
|
2
|
+
import { fs2 } from '../../fs/fs2.js';
|
|
2
3
|
import { AjvSchema } from './ajvSchema.js';
|
|
3
4
|
/**
|
|
4
5
|
* Does fs.readFileSync + JSON.parse for ALL files matching the passed `glob` pattern.
|
|
@@ -9,7 +10,7 @@ import { AjvSchema } from './ajvSchema.js';
|
|
|
9
10
|
* @experimental
|
|
10
11
|
*/
|
|
11
12
|
export function readJsonSchemas(patterns, opt) {
|
|
12
|
-
return
|
|
13
|
+
return globSync(patterns, opt).map(fileName => fs2.readJson(fileName));
|
|
13
14
|
}
|
|
14
15
|
/**
|
|
15
16
|
* Reads json schemas from given dir (glob pattern).
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { _filterNullishValues, _isObject, _substringBefore, JsonSchemaAnyBuilder, } from '@naturalcycles/js-lib';
|
|
2
|
-
import {
|
|
2
|
+
import { fs2 } from '../../fs/fs2.js';
|
|
3
|
+
import { _inspect } from '../../string/inspect.js';
|
|
4
|
+
import { requireFileToExist } from '../../util/env.util.js';
|
|
3
5
|
import { AjvValidationError } from './ajvValidationError.js';
|
|
4
6
|
import { getAjv } from './getAjv.js';
|
|
5
7
|
/**
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/nodejs-lib",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "14.0
|
|
4
|
+
"version": "14.2.0",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"prepare": "husky",
|
|
7
7
|
"build": "dev-lib build",
|
|
@@ -30,12 +30,12 @@
|
|
|
30
30
|
"ajv-keywords": "^5",
|
|
31
31
|
"chalk": "^5",
|
|
32
32
|
"dotenv": "^16",
|
|
33
|
-
"fast-glob": "^3",
|
|
34
33
|
"joi": "^17",
|
|
35
34
|
"js-yaml": "^4",
|
|
36
35
|
"jsonwebtoken": "^9",
|
|
37
36
|
"lru-cache": "^11",
|
|
38
37
|
"through2-concurrent": "^2",
|
|
38
|
+
"tinyglobby": "^0.2",
|
|
39
39
|
"yargs": "^17"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
@@ -43,7 +43,6 @@
|
|
|
43
43
|
"@naturalcycles/dev-lib": "^18",
|
|
44
44
|
"@types/node": "^22",
|
|
45
45
|
"@types/through2-concurrent": "^2",
|
|
46
|
-
"@vitest/coverage-v8": "^3",
|
|
47
46
|
"tsx": "^4",
|
|
48
47
|
"vitest": "^3"
|
|
49
48
|
},
|
package/src/fs/kpy.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
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 { glob, globSync } from 'tinyglobby'
|
|
4
5
|
import { boldWhite, dimGrey, grey, yellow } from '../colors/colors.js'
|
|
5
|
-
import {
|
|
6
|
+
import { fs2 } from './fs2.js'
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Everything defaults to `undefined`.
|
|
@@ -48,7 +49,7 @@ export async function kpy(opt: KpyOptions): Promise<void> {
|
|
|
48
49
|
|
|
49
50
|
kpyPrepare(opt)
|
|
50
51
|
|
|
51
|
-
const filenames = await
|
|
52
|
+
const filenames = await glob(opt.inputPatterns!, {
|
|
52
53
|
cwd: opt.baseDir,
|
|
53
54
|
dot: opt.dotfiles,
|
|
54
55
|
})
|
|
@@ -87,7 +88,7 @@ export function kpySync(opt: KpyOptions): void {
|
|
|
87
88
|
|
|
88
89
|
kpyPrepare(opt)
|
|
89
90
|
|
|
90
|
-
const filenames =
|
|
91
|
+
const filenames = globSync(opt.inputPatterns!, {
|
|
91
92
|
cwd: opt.baseDir,
|
|
92
93
|
dot: opt.dotfiles,
|
|
93
94
|
})
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import Ajv from 'ajv'
|
|
2
|
-
|
|
3
|
-
import fastGlob from 'fast-glob'
|
|
2
|
+
export { glob, globSync } from 'tinyglobby'
|
|
4
3
|
import type {
|
|
5
4
|
AlternativesSchema,
|
|
6
5
|
AnySchema,
|
|
@@ -91,7 +90,6 @@ export type {
|
|
|
91
90
|
BinarySchema,
|
|
92
91
|
BooleanSchema,
|
|
93
92
|
DateSchema,
|
|
94
|
-
FastGlobOptions,
|
|
95
93
|
FunctionSchema,
|
|
96
94
|
ObjectSchema,
|
|
97
95
|
ValidationErrorItem,
|
|
@@ -100,4 +98,4 @@ export type {
|
|
|
100
98
|
// StringSchema,
|
|
101
99
|
}
|
|
102
100
|
|
|
103
|
-
export { Ajv
|
|
101
|
+
export { Ajv }
|
package/src/log/log.util.ts
CHANGED
package/src/script/runScript.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import 'dotenv/config'
|
|
1
2
|
import os from 'node:os'
|
|
2
|
-
import type { CommonLogger } from '@naturalcycles/js-lib'
|
|
3
|
+
import type { AnyObject, CommonLogger } from '@naturalcycles/js-lib'
|
|
3
4
|
import { pDelay, setGlobalStringifyFunction } from '@naturalcycles/js-lib'
|
|
4
5
|
import { dimGrey } from '../colors/colors.js'
|
|
5
6
|
import { inspectStringifyFn } from '../string/inspect.js'
|
|
@@ -45,7 +46,7 @@ const { DEBUG_RUN_SCRIPT } = process.env
|
|
|
45
46
|
* Set env DEBUG_RUN_SCRIPT for extra debugging.
|
|
46
47
|
*/
|
|
47
48
|
export function runScript(fn: (...args: any[]) => any, opt: RunScriptOptions = {}): void {
|
|
48
|
-
|
|
49
|
+
checkAndlogEnvironment()
|
|
49
50
|
setGlobalStringifyFunction(inspectStringifyFn)
|
|
50
51
|
|
|
51
52
|
const { logger = console, noExit, registerUncaughtExceptionHandlers = true } = opt
|
|
@@ -68,8 +69,6 @@ export function runScript(fn: (...args: any[]) => any, opt: RunScriptOptions = {
|
|
|
68
69
|
const timeout = setTimeout(() => {}, 10000000)
|
|
69
70
|
|
|
70
71
|
void (async () => {
|
|
71
|
-
await import('dotenv/config')
|
|
72
|
-
|
|
73
72
|
try {
|
|
74
73
|
await fn()
|
|
75
74
|
|
|
@@ -92,12 +91,12 @@ export function runScript(fn: (...args: any[]) => any, opt: RunScriptOptions = {
|
|
|
92
91
|
})()
|
|
93
92
|
}
|
|
94
93
|
|
|
95
|
-
function
|
|
94
|
+
function checkAndlogEnvironment(): void {
|
|
96
95
|
const {
|
|
97
96
|
platform,
|
|
98
97
|
arch,
|
|
99
98
|
versions: { node },
|
|
100
|
-
env: { CPU_LIMIT, NODE_OPTIONS },
|
|
99
|
+
env: { CPU_LIMIT, NODE_OPTIONS, TZ },
|
|
101
100
|
} = process
|
|
102
101
|
|
|
103
102
|
const cpuLimit = Number(CPU_LIMIT) || undefined
|
|
@@ -105,15 +104,17 @@ function logEnvironment(): void {
|
|
|
105
104
|
const cpus = os.cpus().length
|
|
106
105
|
console.log(
|
|
107
106
|
dimGrey(
|
|
108
|
-
|
|
107
|
+
formatObject({
|
|
109
108
|
node: `${node} ${platform} ${arch}`,
|
|
110
|
-
NODE_OPTIONS: NODE_OPTIONS || 'not defined',
|
|
111
109
|
cpus,
|
|
112
110
|
availableParallelism,
|
|
113
111
|
cpuLimit,
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
|
|
112
|
+
}) +
|
|
113
|
+
'\n' +
|
|
114
|
+
formatObject({
|
|
115
|
+
NODE_OPTIONS: NODE_OPTIONS || 'not defined',
|
|
116
|
+
TZ,
|
|
117
|
+
}),
|
|
117
118
|
),
|
|
118
119
|
)
|
|
119
120
|
|
|
@@ -126,4 +127,22 @@ function logEnvironment(): void {
|
|
|
126
127
|
`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"`,
|
|
127
128
|
)
|
|
128
129
|
}
|
|
130
|
+
|
|
131
|
+
if (!TZ) {
|
|
132
|
+
console.error(
|
|
133
|
+
[
|
|
134
|
+
'!!! TZ environment variable is required to be set, but was not set.',
|
|
135
|
+
'The runScript will exit and not continue further because of that,',
|
|
136
|
+
'please ensure the TZ variable and try again.',
|
|
137
|
+
'If you are running locally, you can add TZ=UTC to the local .env file.',
|
|
138
|
+
].join('\n'),
|
|
139
|
+
)
|
|
140
|
+
process.exit(1)
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function formatObject(obj: AnyObject): string {
|
|
145
|
+
return Object.entries(obj)
|
|
146
|
+
.map(([k, v]) => `${k}: ${v}`)
|
|
147
|
+
.join(', ')
|
|
129
148
|
}
|
|
@@ -1,8 +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 { globSync } from 'tinyglobby'
|
|
4
5
|
import { dimGrey, yellow } from '../colors/colors.js'
|
|
5
|
-
import {
|
|
6
|
+
import { fs2 } from '../fs/fs2.js'
|
|
6
7
|
import { decryptObject, decryptRandomIVBuffer } from '../security/crypto.util.js'
|
|
7
8
|
|
|
8
9
|
export interface DecryptCLIOptions {
|
|
@@ -34,7 +35,7 @@ export function secretsDecrypt(
|
|
|
34
35
|
// If `file` is provided - only this one file is used
|
|
35
36
|
const patterns = file ? [file] : dir.map(d => `${d}/**/*.enc`)
|
|
36
37
|
|
|
37
|
-
const filenames =
|
|
38
|
+
const filenames = globSync(patterns)
|
|
38
39
|
|
|
39
40
|
filenames.forEach(filename => {
|
|
40
41
|
let plainFilename: string
|
|
@@ -1,8 +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 { globSync } from 'tinyglobby'
|
|
4
5
|
import { dimGrey, yellow } from '../colors/colors.js'
|
|
5
|
-
import {
|
|
6
|
+
import { fs2 } from '../fs/fs2.js'
|
|
6
7
|
import { encryptObject, encryptRandomIVBuffer } from '../security/crypto.util.js'
|
|
7
8
|
|
|
8
9
|
export interface EncryptCLIOptions {
|
|
@@ -30,7 +31,7 @@ export function secretsEncrypt(
|
|
|
30
31
|
...pattern,
|
|
31
32
|
`!**/*.enc`, // excluding already encoded
|
|
32
33
|
]
|
|
33
|
-
const filenames =
|
|
34
|
+
const filenames = globSync(patterns)
|
|
34
35
|
let encFilename: string
|
|
35
36
|
|
|
36
37
|
filenames.forEach(filename => {
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { dirname } from 'node:path'
|
|
2
|
-
import { fileURLToPath } from 'node:url'
|
|
3
1
|
import { Worker } from 'node:worker_threads'
|
|
4
2
|
import type { AnyObject, DeferredPromise } from '@naturalcycles/js-lib'
|
|
5
3
|
import { _range, pDefer } from '@naturalcycles/js-lib'
|
|
@@ -7,9 +5,6 @@ import through2Concurrent from 'through2-concurrent'
|
|
|
7
5
|
import type { TransformTyped } from '../../stream.model.js'
|
|
8
6
|
import type { WorkerInput, WorkerOutput } from './transformMultiThreaded.model.js'
|
|
9
7
|
|
|
10
|
-
const __filename = fileURLToPath(import.meta.url)
|
|
11
|
-
const __dirname = dirname(__filename)
|
|
12
|
-
|
|
13
8
|
export interface TransformMultiThreadedOptions {
|
|
14
9
|
/**
|
|
15
10
|
* Absolute path to a js file with worker code
|
|
@@ -37,7 +32,7 @@ export interface TransformMultiThreadedOptions {
|
|
|
37
32
|
workerData?: AnyObject
|
|
38
33
|
}
|
|
39
34
|
|
|
40
|
-
const workerProxyFilePath = `${
|
|
35
|
+
const workerProxyFilePath = `${import.meta.dirname}/workerClassProxy.js`
|
|
41
36
|
|
|
42
37
|
/**
|
|
43
38
|
* Spawns a pool of Workers (threads).
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { JsonSchema } from '@naturalcycles/js-lib'
|
|
2
|
-
import type {
|
|
3
|
-
import {
|
|
2
|
+
import type { GlobOptions } from 'tinyglobby'
|
|
3
|
+
import { globSync } from 'tinyglobby'
|
|
4
|
+
import { fs2 } from '../../fs/fs2.js'
|
|
4
5
|
import type { AjvSchemaCfg } from './ajvSchema.js'
|
|
5
6
|
import { AjvSchema } from './ajvSchema.js'
|
|
6
7
|
|
|
@@ -12,8 +13,11 @@ import { AjvSchema } from './ajvSchema.js'
|
|
|
12
13
|
*
|
|
13
14
|
* @experimental
|
|
14
15
|
*/
|
|
15
|
-
export function readJsonSchemas(
|
|
16
|
-
|
|
16
|
+
export function readJsonSchemas(
|
|
17
|
+
patterns: string | string[],
|
|
18
|
+
opt?: Omit<GlobOptions, 'patterns'>,
|
|
19
|
+
): JsonSchema[] {
|
|
20
|
+
return globSync(patterns, opt).map(fileName => fs2.readJson(fileName))
|
|
17
21
|
}
|
|
18
22
|
|
|
19
23
|
/**
|
|
@@ -6,7 +6,9 @@ import {
|
|
|
6
6
|
JsonSchemaAnyBuilder,
|
|
7
7
|
} from '@naturalcycles/js-lib'
|
|
8
8
|
import type { Ajv, ValidateFunction } from 'ajv'
|
|
9
|
-
import {
|
|
9
|
+
import { fs2 } from '../../fs/fs2.js'
|
|
10
|
+
import { _inspect } from '../../string/inspect.js'
|
|
11
|
+
import { requireFileToExist } from '../../util/env.util.js'
|
|
10
12
|
import { AjvValidationError } from './ajvValidationError.js'
|
|
11
13
|
import { getAjv } from './getAjv.js'
|
|
12
14
|
|