@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.
- package/dist/bin/generate-build-info.js +15 -18
- package/dist/bin/json2env.js +6 -9
- package/dist/bin/kpy.js +6 -9
- package/dist/bin/secrets-decrypt.d.ts +1 -1
- package/dist/bin/secrets-decrypt.js +9 -12
- package/dist/bin/secrets-encrypt.d.ts +1 -1
- package/dist/bin/secrets-encrypt.js +9 -12
- package/dist/bin/secrets-gen-key.js +8 -11
- package/dist/bin/slack-this.js +6 -9
- package/dist/buffer/buffer.util.js +1 -4
- package/dist/colors/colors.d.ts +26 -27
- package/dist/colors/colors.js +29 -33
- package/dist/csv/csvReader.js +4 -8
- package/dist/csv/csvWriter.js +7 -12
- package/dist/csv/transformToCSV.d.ts +2 -2
- package/dist/csv/transformToCSV.js +5 -8
- package/dist/diff/tableDiff.js +4 -7
- package/dist/fs/fs2.d.ts +1 -1
- package/dist/fs/fs2.js +88 -94
- package/dist/fs/json2env.js +18 -28
- package/dist/fs/kpy.js +28 -33
- package/dist/index.d.ts +71 -71
- package/dist/index.js +73 -78
- package/dist/infra/process.util.js +23 -28
- package/dist/jwt/jwt.service.js +17 -21
- package/dist/log/log.util.js +4 -7
- package/dist/script/runScript.js +11 -15
- package/dist/secret/secrets-decrypt.util.js +18 -22
- package/dist/secret/secrets-encrypt.util.js +17 -21
- package/dist/security/crypto.util.js +24 -34
- package/dist/security/hash.util.js +19 -37
- package/dist/security/id.util.js +11 -18
- package/dist/security/nanoid.js +15 -20
- package/dist/security/secret.util.js +20 -30
- package/dist/slack/slack.service.d.ts +1 -1
- package/dist/slack/slack.service.js +13 -16
- package/dist/slack/slack.service.model.d.ts +1 -1
- package/dist/slack/slack.service.model.js +1 -2
- package/dist/stream/ndjson/ndjson.model.js +10 -16
- package/dist/stream/ndjson/ndjsonMap.d.ts +1 -1
- package/dist/stream/ndjson/ndjsonMap.js +11 -14
- package/dist/stream/ndjson/ndjsonStreamForEach.d.ts +1 -1
- package/dist/stream/ndjson/ndjsonStreamForEach.js +9 -12
- package/dist/stream/ndjson/transformJsonParse.d.ts +1 -1
- package/dist/stream/ndjson/transformJsonParse.js +4 -9
- package/dist/stream/ndjson/transformToNDJson.d.ts +1 -1
- package/dist/stream/ndjson/transformToNDJson.js +5 -8
- package/dist/stream/pipeline/pipeline.js +13 -17
- package/dist/stream/progressLogger.d.ts +1 -1
- package/dist/stream/progressLogger.js +32 -28
- package/dist/stream/readable/readableCreate.d.ts +1 -1
- package/dist/stream/readable/readableCreate.js +5 -9
- package/dist/stream/readable/readableForEach.d.ts +2 -2
- package/dist/stream/readable/readableForEach.js +7 -11
- package/dist/stream/readable/readableFromArray.d.ts +1 -1
- package/dist/stream/readable/readableFromArray.js +4 -7
- package/dist/stream/readable/readableToArray.d.ts +1 -1
- package/dist/stream/readable/readableToArray.js +1 -4
- package/dist/stream/sizeStack.js +9 -12
- package/dist/stream/stream.model.js +1 -2
- package/dist/stream/stream.util.js +1 -4
- package/dist/stream/transform/transformChunk.d.ts +1 -1
- package/dist/stream/transform/transformChunk.js +3 -6
- package/dist/stream/transform/transformFilter.d.ts +2 -2
- package/dist/stream/transform/transformFilter.js +6 -10
- package/dist/stream/transform/transformLimit.d.ts +2 -2
- package/dist/stream/transform/transformLimit.js +6 -11
- package/dist/stream/transform/transformLogProgress.d.ts +2 -2
- package/dist/stream/transform/transformLogProgress.js +5 -8
- package/dist/stream/transform/transformMap.d.ts +1 -1
- package/dist/stream/transform/transformMap.js +18 -22
- package/dist/stream/transform/transformMapSimple.d.ts +1 -1
- package/dist/stream/transform/transformMapSimple.js +6 -9
- package/dist/stream/transform/transformMapSync.d.ts +3 -3
- package/dist/stream/transform/transformMapSync.js +14 -19
- package/dist/stream/transform/transformNoOp.d.ts +1 -1
- package/dist/stream/transform/transformNoOp.js +3 -6
- package/dist/stream/transform/transformOffset.d.ts +1 -1
- package/dist/stream/transform/transformOffset.js +5 -8
- package/dist/stream/transform/transformSplit.d.ts +1 -1
- package/dist/stream/transform/transformSplit.js +5 -9
- package/dist/stream/transform/transformTap.d.ts +1 -1
- package/dist/stream/transform/transformTap.js +3 -6
- package/dist/stream/transform/transformTee.d.ts +1 -1
- package/dist/stream/transform/transformTee.js +7 -10
- package/dist/stream/transform/transformThrottle.d.ts +1 -1
- package/dist/stream/transform/transformThrottle.js +9 -12
- package/dist/stream/transform/transformToArray.d.ts +1 -1
- package/dist/stream/transform/transformToArray.js +3 -6
- package/dist/stream/transform/worker/baseWorkerClass.d.ts +1 -1
- package/dist/stream/transform/worker/baseWorkerClass.js +2 -5
- package/dist/stream/transform/worker/transformMultiThreaded.d.ts +1 -1
- package/dist/stream/transform/worker/transformMultiThreaded.js +12 -11
- package/dist/stream/transform/worker/transformMultiThreaded.model.js +1 -2
- package/dist/stream/transform/worker/workerClassProxy.js +6 -4
- package/dist/stream/writable/writableForEach.d.ts +2 -2
- package/dist/stream/writable/writableForEach.js +6 -10
- package/dist/stream/writable/writableFork.d.ts +1 -1
- package/dist/stream/writable/writableFork.js +6 -9
- package/dist/stream/writable/writableLimit.d.ts +1 -1
- package/dist/stream/writable/writableLimit.js +3 -6
- package/dist/stream/writable/writablePushToArray.d.ts +1 -1
- package/dist/stream/writable/writablePushToArray.js +3 -6
- package/dist/stream/writable/writableVoid.d.ts +1 -1
- package/dist/stream/writable/writableVoid.js +3 -6
- package/dist/string/inspect.js +8 -13
- package/dist/util/buildInfo.util.js +12 -15
- package/dist/util/env.util.js +5 -9
- package/dist/util/exec2.js +17 -21
- package/dist/util/git2.js +17 -20
- package/dist/util/lruMemoCache.js +4 -7
- package/dist/util/zip.util.js +14 -25
- package/dist/validation/ajv/ajv.util.d.ts +3 -3
- package/dist/validation/ajv/ajv.util.js +6 -10
- package/dist/validation/ajv/ajvSchema.d.ts +2 -2
- package/dist/validation/ajv/ajvSchema.js +17 -18
- package/dist/validation/ajv/ajvValidationError.js +2 -6
- package/dist/validation/ajv/getAjv.d.ts +1 -1
- package/dist/validation/ajv/getAjv.js +9 -9
- package/dist/validation/joi/joi.extensions.d.ts +2 -2
- package/dist/validation/joi/joi.extensions.js +6 -10
- package/dist/validation/joi/joi.model.js +1 -2
- package/dist/validation/joi/joi.shared.schemas.d.ts +2 -2
- package/dist/validation/joi/joi.shared.schemas.js +61 -74
- package/dist/validation/joi/joi.validation.error.js +2 -6
- package/dist/validation/joi/joi.validation.util.d.ts +1 -1
- package/dist/validation/joi/joi.validation.util.js +10 -17
- package/dist/validation/joi/number.extensions.js +1 -4
- package/dist/validation/joi/string.extensions.js +4 -7
- package/dist/yargs.util.js +5 -8
- package/package.json +5 -4
- package/src/bin/generate-build-info.ts +3 -3
- package/src/bin/json2env.ts +2 -2
- package/src/bin/kpy.ts +2 -2
- package/src/bin/secrets-decrypt.ts +7 -8
- package/src/bin/secrets-encrypt.ts +7 -8
- package/src/bin/secrets-gen-key.ts +2 -2
- package/src/bin/slack-this.ts +2 -2
- package/src/csv/transformToCSV.ts +3 -3
- package/src/fs/fs2.ts +4 -4
- package/src/fs/json2env.ts +2 -2
- package/src/fs/kpy.ts +2 -2
- package/src/index.ts +71 -71
- package/src/jwt/jwt.service.ts +2 -2
- package/src/log/log.util.ts +1 -1
- package/src/script/runScript.ts +4 -3
- package/src/secret/secrets-decrypt.util.ts +3 -3
- package/src/secret/secrets-encrypt.util.ts +3 -3
- package/src/security/crypto.util.ts +1 -1
- package/src/security/id.util.ts +1 -1
- package/src/security/secret.util.ts +2 -2
- package/src/slack/slack.service.model.ts +1 -1
- package/src/slack/slack.service.ts +3 -3
- package/src/stream/ndjson/ndjson.model.ts +1 -1
- package/src/stream/ndjson/ndjsonMap.ts +2 -2
- package/src/stream/ndjson/ndjsonStreamForEach.ts +2 -2
- package/src/stream/ndjson/transformJsonParse.ts +1 -1
- package/src/stream/ndjson/transformToNDJson.ts +1 -1
- package/src/stream/pipeline/pipeline.ts +1 -1
- package/src/stream/progressLogger.ts +3 -3
- package/src/stream/readable/readableCreate.ts +1 -1
- package/src/stream/readable/readableForEach.ts +4 -4
- package/src/stream/readable/readableFromArray.ts +1 -1
- package/src/stream/readable/readableToArray.ts +1 -1
- package/src/stream/sizeStack.ts +2 -2
- package/src/stream/transform/transformChunk.ts +1 -1
- package/src/stream/transform/transformFilter.ts +3 -3
- package/src/stream/transform/transformLimit.ts +3 -3
- package/src/stream/transform/transformLogProgress.ts +3 -3
- package/src/stream/transform/transformMap.ts +5 -5
- package/src/stream/transform/transformMapSimple.ts +1 -1
- package/src/stream/transform/transformMapSync.ts +5 -5
- package/src/stream/transform/transformNoOp.ts +1 -1
- package/src/stream/transform/transformOffset.ts +2 -2
- package/src/stream/transform/transformSplit.ts +1 -1
- package/src/stream/transform/transformTap.ts +1 -1
- package/src/stream/transform/transformTee.ts +3 -3
- package/src/stream/transform/transformThrottle.ts +1 -1
- package/src/stream/transform/transformToArray.ts +1 -1
- package/src/stream/transform/worker/baseWorkerClass.ts +1 -1
- package/src/stream/transform/worker/transformMultiThreaded.ts +8 -3
- package/src/stream/transform/worker/workerClassProxy.js +6 -4
- package/src/stream/writable/writableForEach.ts +3 -3
- package/src/stream/writable/writableFork.ts +3 -3
- package/src/stream/writable/writableLimit.ts +1 -1
- package/src/stream/writable/writablePushToArray.ts +1 -1
- package/src/stream/writable/writableVoid.ts +1 -1
- package/src/util/buildInfo.util.ts +2 -2
- package/src/util/exec2.ts +1 -1
- package/src/util/git2.ts +2 -2
- package/src/validation/ajv/ajv.util.ts +4 -4
- package/src/validation/ajv/ajvSchema.ts +4 -5
- package/src/validation/ajv/getAjv.ts +7 -3
- package/src/validation/joi/joi.extensions.ts +4 -4
- package/src/validation/joi/joi.shared.schemas.ts +3 -3
- package/src/validation/joi/joi.validation.util.ts +2 -2
- package/src/yargs.util.ts +1 -0
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BaseWorkerClass = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* Class to be extended, to be used with `transformMultiThreaded`
|
|
6
3
|
*/
|
|
7
|
-
class BaseWorkerClass {
|
|
4
|
+
export class BaseWorkerClass {
|
|
5
|
+
workerData;
|
|
8
6
|
constructor(workerData) {
|
|
9
7
|
this.workerData = workerData;
|
|
10
8
|
}
|
|
11
9
|
}
|
|
12
|
-
exports.BaseWorkerClass = BaseWorkerClass;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AnyObject } from '@naturalcycles/js-lib';
|
|
2
|
-
import type { TransformTyped } from '../../stream.model';
|
|
2
|
+
import type { TransformTyped } from '../../stream.model.js';
|
|
3
3
|
export interface TransformMultiThreadedOptions {
|
|
4
4
|
/**
|
|
5
5
|
* Absolute path to a js file with worker code
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
1
|
+
import { dirname } from 'node:path';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import { Worker } from 'node:worker_threads';
|
|
4
|
+
import { _range, pDefer } from '@naturalcycles/js-lib';
|
|
5
|
+
import through2Concurrent from 'through2-concurrent';
|
|
6
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
7
|
+
const __dirname = dirname(__filename);
|
|
7
8
|
const workerProxyFilePath = `${__dirname}/workerClassProxy.js`;
|
|
8
9
|
/**
|
|
9
10
|
* Spawns a pool of Workers (threads).
|
|
@@ -11,7 +12,7 @@ const workerProxyFilePath = `${__dirname}/workerClassProxy.js`;
|
|
|
11
12
|
* Workers emit 1 output for each 1 input.
|
|
12
13
|
* Output of Workers is passed down the stream. Order is RANDOM (since it's a multi-threaded environment).
|
|
13
14
|
*/
|
|
14
|
-
function transformMultiThreaded(opt) {
|
|
15
|
+
export function transformMultiThreaded(opt) {
|
|
15
16
|
const { workerFile, poolSize = 2, workerData } = opt;
|
|
16
17
|
const maxConcurrency = opt.concurrency || poolSize;
|
|
17
18
|
const highWaterMark = Math.max(16, maxConcurrency);
|
|
@@ -23,9 +24,9 @@ function transformMultiThreaded(opt) {
|
|
|
23
24
|
const workerDonePromises = [];
|
|
24
25
|
const messageDonePromises = {};
|
|
25
26
|
let index = -1; // input chunk index, will start from 0
|
|
26
|
-
const workers =
|
|
27
|
-
workerDonePromises.push(
|
|
28
|
-
const worker = new
|
|
27
|
+
const workers = _range(0, poolSize).map(workerIndex => {
|
|
28
|
+
workerDonePromises.push(pDefer());
|
|
29
|
+
const worker = new Worker(workerProxyFilePath, {
|
|
29
30
|
workerData: {
|
|
30
31
|
workerIndex,
|
|
31
32
|
workerFile, // pass it, so workerProxy can require() it
|
|
@@ -75,7 +76,7 @@ function transformMultiThreaded(opt) {
|
|
|
75
76
|
// Freezing the index, because it may change due to concurrency
|
|
76
77
|
const currentIndex = ++index;
|
|
77
78
|
// Create the unresolved promise (to avait)
|
|
78
|
-
messageDonePromises[currentIndex] =
|
|
79
|
+
messageDonePromises[currentIndex] = pDefer();
|
|
79
80
|
const worker = workers[currentIndex % poolSize]; // round-robin
|
|
80
81
|
worker.postMessage({
|
|
81
82
|
index: currentIndex,
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const started = Date.now()
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import { workerData, parentPort } from 'node:worker_threads'
|
|
3
|
+
import { inspect } from 'node:util'
|
|
4
4
|
const { workerFile, workerIndex, logEvery = 1000, metric = 'worker' } = workerData || {}
|
|
5
5
|
|
|
6
6
|
if (!workerFile) {
|
|
@@ -12,11 +12,13 @@ if (!workerFile) {
|
|
|
12
12
|
try {
|
|
13
13
|
// require('esbuild-register') // alternative
|
|
14
14
|
// require('ts-node/register/transpile-only')
|
|
15
|
-
require('tsx/cjs/api').register() // https://tsx.is/dev-api/register-cjs
|
|
15
|
+
// require('tsx/cjs/api').register() // https://tsx.is/dev-api/register-cjs
|
|
16
|
+
const { register } = await import('tsx/esm/api')
|
|
17
|
+
register() // https://tsx.is/dev-api/register-esm
|
|
16
18
|
// require('tsconfig-paths/register')
|
|
17
19
|
} catch {} // require if exists
|
|
18
20
|
|
|
19
|
-
const { WorkerClass } =
|
|
21
|
+
const { WorkerClass } = await import(workerFile)
|
|
20
22
|
const worker = new WorkerClass(workerData)
|
|
21
23
|
|
|
22
24
|
console.log(`${metric}#${workerIndex} loaded in ${Date.now() - started} ms`)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AsyncMapper, Mapper } from '@naturalcycles/js-lib';
|
|
2
|
-
import type { TransformMapOptions } from '
|
|
3
|
-
import type { WritableTyped } from '../stream.model';
|
|
2
|
+
import type { TransformMapOptions } from '../../index.js';
|
|
3
|
+
import type { WritableTyped } from '../stream.model.js';
|
|
4
4
|
/**
|
|
5
5
|
* Just an alias to transformMap that declares OUT as void.
|
|
6
6
|
*/
|
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.writableForEach = writableForEach;
|
|
4
|
-
exports.writableForEachSync = writableForEachSync;
|
|
5
|
-
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
6
|
-
const __1 = require("../..");
|
|
1
|
+
import { _passNothingPredicate } from '@naturalcycles/js-lib';
|
|
2
|
+
import { transformMap, transformMapSync } from '../../index.js';
|
|
7
3
|
/**
|
|
8
4
|
* Just an alias to transformMap that declares OUT as void.
|
|
9
5
|
*/
|
|
10
|
-
function writableForEach(mapper, opt = {}) {
|
|
11
|
-
return
|
|
6
|
+
export function writableForEach(mapper, opt = {}) {
|
|
7
|
+
return transformMap(mapper, { ...opt, predicate: _passNothingPredicate });
|
|
12
8
|
}
|
|
13
9
|
/**
|
|
14
10
|
* Just an alias to transformMap that declares OUT as void.
|
|
15
11
|
*/
|
|
16
|
-
function writableForEachSync(mapper, opt = {}) {
|
|
17
|
-
return
|
|
12
|
+
export function writableForEachSync(mapper, opt = {}) {
|
|
13
|
+
return transformMapSync(mapper, { ...opt, predicate: _passNothingPredicate });
|
|
18
14
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { TransformOptions, WritableTyped } from '../stream.model';
|
|
1
|
+
import type { TransformOptions, WritableTyped } from '../stream.model.js';
|
|
2
2
|
/**
|
|
3
3
|
* Allows "forking" a stream inside pipeline into a number of pipeline chains (2 or more).
|
|
4
4
|
* Currently does NOT (!) maintain backpressure.
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.writableFork = writableFork;
|
|
4
|
-
const node_stream_1 = require("node:stream");
|
|
5
|
-
const __1 = require("../..");
|
|
1
|
+
import { Writable } from 'node:stream';
|
|
2
|
+
import { _pipeline, readableCreate } from '../../index.js';
|
|
6
3
|
/**
|
|
7
4
|
* Allows "forking" a stream inside pipeline into a number of pipeline chains (2 or more).
|
|
8
5
|
* Currently does NOT (!) maintain backpressure.
|
|
@@ -11,17 +8,17 @@ const __1 = require("../..");
|
|
|
11
8
|
*
|
|
12
9
|
* @experimental
|
|
13
10
|
*/
|
|
14
|
-
function writableFork(chains, opt) {
|
|
11
|
+
export function writableFork(chains, opt) {
|
|
15
12
|
const readables = [];
|
|
16
13
|
const allChainsDone = Promise.all(chains.map(async (chain) => {
|
|
17
|
-
const readable =
|
|
14
|
+
const readable = readableCreate();
|
|
18
15
|
readables.push(readable);
|
|
19
|
-
return await
|
|
16
|
+
return await _pipeline([readable, ...chain]);
|
|
20
17
|
})).catch(err => {
|
|
21
18
|
console.error(err); // ensure the error is logged
|
|
22
19
|
throw err;
|
|
23
20
|
});
|
|
24
|
-
return new
|
|
21
|
+
return new Writable({
|
|
25
22
|
objectMode: true,
|
|
26
23
|
...opt,
|
|
27
24
|
write(chunk, _, cb) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Readable } from 'node:stream';
|
|
2
|
-
import type { WritableTyped } from '../stream.model';
|
|
2
|
+
import type { WritableTyped } from '../stream.model.js';
|
|
3
3
|
/**
|
|
4
4
|
* Allows to stop the Readable stream after the pipeline has processed X number of rows.
|
|
5
5
|
* It counts OUTPUT rows (not input), because this Writable is always at the end of the Pipeline.
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.writableLimit = writableLimit;
|
|
4
|
-
const node_stream_1 = require("node:stream");
|
|
1
|
+
import { Writable } from 'node:stream';
|
|
5
2
|
/**
|
|
6
3
|
* Allows to stop the Readable stream after the pipeline has processed X number of rows.
|
|
7
4
|
* It counts OUTPUT rows (not input), because this Writable is always at the end of the Pipeline.
|
|
8
5
|
* It ensures that everything has been processed before issuing a STOP on the readable.
|
|
9
6
|
*/
|
|
10
|
-
function writableLimit(readable, limit) {
|
|
7
|
+
export function writableLimit(readable, limit) {
|
|
11
8
|
let i = 0;
|
|
12
|
-
return new
|
|
9
|
+
return new Writable({
|
|
13
10
|
objectMode: true,
|
|
14
11
|
write(_chunk, _, cb) {
|
|
15
12
|
if (limit === 0)
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.writablePushToArray = writablePushToArray;
|
|
4
|
-
const node_stream_1 = require("node:stream");
|
|
1
|
+
import { Writable } from 'node:stream';
|
|
5
2
|
/**
|
|
6
3
|
* Will push all results to `arr`, will emit nothing in the end.
|
|
7
4
|
*/
|
|
8
|
-
function writablePushToArray(arr, opt = {}) {
|
|
9
|
-
return new
|
|
5
|
+
export function writablePushToArray(arr, opt = {}) {
|
|
6
|
+
return new Writable({
|
|
10
7
|
objectMode: true,
|
|
11
8
|
...opt,
|
|
12
9
|
write(chunk, _, cb) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Writable } from 'node:stream';
|
|
2
2
|
import type { DeferredPromise } from '@naturalcycles/js-lib';
|
|
3
|
-
import type { TransformOptions } from '../stream.model';
|
|
3
|
+
import type { TransformOptions } from '../stream.model.js';
|
|
4
4
|
export interface WritableVoidOptions extends TransformOptions {
|
|
5
5
|
/**
|
|
6
6
|
* If set - it will be Resolved when the Stream is done (after final.cb)
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.writableVoid = writableVoid;
|
|
4
|
-
const node_stream_1 = require("node:stream");
|
|
1
|
+
import { Writable } from 'node:stream';
|
|
5
2
|
/**
|
|
6
3
|
* Use as a "null-terminator" of stream.pipeline.
|
|
7
4
|
* It consumes the stream as quickly as possible without doing anything.
|
|
8
5
|
* Put it in the end of your pipeline in case it ends with Transform that needs a consumer.
|
|
9
6
|
*/
|
|
10
|
-
function writableVoid(opt = {}) {
|
|
11
|
-
return new
|
|
7
|
+
export function writableVoid(opt = {}) {
|
|
8
|
+
return new Writable({
|
|
12
9
|
objectMode: true,
|
|
13
10
|
...opt,
|
|
14
11
|
write(_chunk, _, cb) {
|
package/dist/string/inspect.js
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.inspectAny = exports.inspectStringifyFn = void 0;
|
|
4
|
-
exports._inspect = _inspect;
|
|
5
|
-
const node_util_1 = require("node:util");
|
|
6
|
-
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
1
|
+
import { inspect } from 'node:util';
|
|
2
|
+
import { _stringify } from '@naturalcycles/js-lib';
|
|
7
3
|
const INSPECT_OPT = {
|
|
8
4
|
breakLength: 80, // default: ??
|
|
9
5
|
depth: 10, // default: 2
|
|
@@ -11,8 +7,7 @@ const INSPECT_OPT = {
|
|
|
11
7
|
/**
|
|
12
8
|
* Just a convenience export of a const that fulfills the JsonStringifyFunction interface.
|
|
13
9
|
*/
|
|
14
|
-
const inspectStringifyFn = obj =>
|
|
15
|
-
exports.inspectStringifyFn = inspectStringifyFn;
|
|
10
|
+
export const inspectStringifyFn = obj => inspect(obj, INSPECT_OPT);
|
|
16
11
|
/**
|
|
17
12
|
* Transforms ANY to human-readable string (via util.inspect mainly).
|
|
18
13
|
* Safe (no error throwing).
|
|
@@ -30,17 +25,17 @@ exports.inspectStringifyFn = inspectStringifyFn;
|
|
|
30
25
|
*
|
|
31
26
|
* Based on `_stringify` from `js-lib`, just replaced `JSON.stringify` with `util.inspect`.
|
|
32
27
|
*/
|
|
33
|
-
function _inspect(obj, opt = {}) {
|
|
28
|
+
export function _inspect(obj, opt = {}) {
|
|
34
29
|
// Inspect handles functions better
|
|
35
30
|
if (typeof obj === 'function') {
|
|
36
|
-
return
|
|
31
|
+
return inspect(obj, {
|
|
37
32
|
...INSPECT_OPT,
|
|
38
33
|
...opt,
|
|
39
34
|
});
|
|
40
35
|
}
|
|
41
|
-
return
|
|
36
|
+
return _stringify(obj, {
|
|
42
37
|
...opt,
|
|
43
|
-
stringifyFn: obj =>
|
|
38
|
+
stringifyFn: obj => inspect(obj, {
|
|
44
39
|
...INSPECT_OPT,
|
|
45
40
|
...opt,
|
|
46
41
|
}),
|
|
@@ -49,4 +44,4 @@ function _inspect(obj, opt = {}) {
|
|
|
49
44
|
/**
|
|
50
45
|
* @deprecated renamed to _inspect
|
|
51
46
|
*/
|
|
52
|
-
|
|
47
|
+
export const inspectAny = _inspect;
|
|
@@ -1,29 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const git2_1 = require("./git2");
|
|
7
|
-
function generateBuildInfo(opt = {}) {
|
|
8
|
-
const now = js_lib_1.localTime.orNow(opt.overrideTimestamp);
|
|
1
|
+
import { _filterUndefinedValues, localTime } from '@naturalcycles/js-lib';
|
|
2
|
+
import { fs2 } from '../fs/fs2.js';
|
|
3
|
+
import { git2 } from './git2.js';
|
|
4
|
+
export function generateBuildInfo(opt = {}) {
|
|
5
|
+
const now = localTime.orNow(opt.overrideTimestamp);
|
|
9
6
|
const ts = now.unix;
|
|
10
|
-
const rev =
|
|
11
|
-
const branchName = opt.overrideBranchName ||
|
|
12
|
-
const repoName =
|
|
13
|
-
const tsCommit =
|
|
7
|
+
const rev = git2.getCurrentCommitSha();
|
|
8
|
+
const branchName = opt.overrideBranchName || git2.getCurrentBranchName();
|
|
9
|
+
const repoName = git2.getCurrentRepoName();
|
|
10
|
+
const tsCommit = git2.getCurrentCommitTimestamp();
|
|
14
11
|
const ver = [now.toStringCompact(), repoName, branchName, rev].join('_');
|
|
15
12
|
let { APP_ENV: env } = process.env;
|
|
16
13
|
if (!env) {
|
|
17
14
|
// Attempt to read `envByBranch` from package.json root
|
|
18
15
|
try {
|
|
19
|
-
if (
|
|
20
|
-
const packageJson =
|
|
16
|
+
if (fs2.pathExists('package.json')) {
|
|
17
|
+
const packageJson = fs2.readJson('package.json');
|
|
21
18
|
env = packageJson?.['envByBranch']?.[branchName] || packageJson?.['envByBranch']?.['*'];
|
|
22
19
|
}
|
|
23
20
|
}
|
|
24
21
|
catch { }
|
|
25
22
|
}
|
|
26
|
-
return
|
|
23
|
+
return _filterUndefinedValues({
|
|
27
24
|
ts,
|
|
28
25
|
tsCommit,
|
|
29
26
|
repoName,
|
package/dist/util/env.util.js
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.requireEnvKeys = requireEnvKeys;
|
|
4
|
-
exports.requireFileToExist = requireFileToExist;
|
|
5
|
-
require("dotenv/config"); // ensure .env is read before requiring keys
|
|
6
|
-
const node_fs_1 = require("node:fs");
|
|
1
|
+
import 'dotenv/config'; // ensure .env is read before requiring keys
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
7
3
|
/**
|
|
8
4
|
* @example
|
|
9
5
|
*
|
|
@@ -11,7 +7,7 @@ const node_fs_1 = require("node:fs");
|
|
|
11
7
|
*
|
|
12
8
|
* Will throw if any of the passed keys is not defined.
|
|
13
9
|
*/
|
|
14
|
-
function requireEnvKeys(...keys) {
|
|
10
|
+
export function requireEnvKeys(...keys) {
|
|
15
11
|
// eslint-disable-next-line unicorn/no-array-reduce
|
|
16
12
|
return keys.reduce((r, k) => {
|
|
17
13
|
const v = process.env[k];
|
|
@@ -21,8 +17,8 @@ function requireEnvKeys(...keys) {
|
|
|
21
17
|
return r;
|
|
22
18
|
}, {});
|
|
23
19
|
}
|
|
24
|
-
function requireFileToExist(filePath) {
|
|
25
|
-
if (!
|
|
20
|
+
export function requireFileToExist(filePath) {
|
|
21
|
+
if (!existsSync(filePath)) {
|
|
26
22
|
throw new Error(`Required file should exist: ${filePath}`);
|
|
27
23
|
}
|
|
28
24
|
}
|
package/dist/util/exec2.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const node_child_process_1 = require("node:child_process");
|
|
5
|
-
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
6
|
-
const colors_1 = require("../colors/colors");
|
|
1
|
+
import { execSync, spawn, spawnSync } from 'node:child_process';
|
|
2
|
+
import { _since, AppError } from '@naturalcycles/js-lib';
|
|
3
|
+
import { dimGrey, dimRed, hasColors, white } from '../colors/colors.js';
|
|
7
4
|
/**
|
|
8
5
|
* Set of utility functions to work with Spawn / Exec.
|
|
9
6
|
*
|
|
@@ -41,13 +38,13 @@ class Exec2 {
|
|
|
41
38
|
* log: true
|
|
42
39
|
*/
|
|
43
40
|
spawn(cmd, opt = {}) {
|
|
44
|
-
const { shell = true, cwd, env, passProcessEnv = true, forceColor =
|
|
41
|
+
const { shell = true, cwd, env, passProcessEnv = true, forceColor = hasColors } = opt;
|
|
45
42
|
opt.log ??= true; // by default log should be true, as we are printing the output
|
|
46
43
|
opt.logStart ??= opt.log;
|
|
47
44
|
opt.logFinish ??= opt.log;
|
|
48
45
|
const started = Date.now();
|
|
49
46
|
this.logStart(cmd, opt);
|
|
50
|
-
const r =
|
|
47
|
+
const r = spawnSync(cmd, opt.args, {
|
|
51
48
|
encoding: 'utf8',
|
|
52
49
|
stdio: 'inherit',
|
|
53
50
|
shell,
|
|
@@ -88,7 +85,7 @@ class Exec2 {
|
|
|
88
85
|
const started = Date.now();
|
|
89
86
|
this.logStart(cmd, opt);
|
|
90
87
|
try {
|
|
91
|
-
const s =
|
|
88
|
+
const s = execSync(cmd, {
|
|
92
89
|
encoding: 'utf8',
|
|
93
90
|
// stdio: 'inherit', // no, otherwise we don't get the output returned
|
|
94
91
|
stdio: undefined,
|
|
@@ -130,14 +127,14 @@ class Exec2 {
|
|
|
130
127
|
* log: true
|
|
131
128
|
*/
|
|
132
129
|
async spawnAsync(cmd, opt = {}) {
|
|
133
|
-
const { shell = true, cwd, env, passProcessEnv = true, forceColor =
|
|
130
|
+
const { shell = true, cwd, env, passProcessEnv = true, forceColor = hasColors } = opt;
|
|
134
131
|
opt.log ??= true; // by default log should be true, as we are printing the output
|
|
135
132
|
opt.logStart ??= opt.log;
|
|
136
133
|
opt.logFinish ??= opt.log;
|
|
137
134
|
const started = Date.now();
|
|
138
135
|
this.logStart(cmd, opt);
|
|
139
136
|
await new Promise((resolve, reject) => {
|
|
140
|
-
const p =
|
|
137
|
+
const p = spawn(cmd, opt.args || [], {
|
|
141
138
|
shell,
|
|
142
139
|
cwd,
|
|
143
140
|
stdio: 'inherit',
|
|
@@ -177,7 +174,7 @@ class Exec2 {
|
|
|
177
174
|
* log: true
|
|
178
175
|
*/
|
|
179
176
|
async spawnAsyncAndReturn(cmd, opt = {}) {
|
|
180
|
-
const { shell = true, printWhileRunning = true, collectOutputWhileRunning = true, throwOnNonZeroCode = true, cwd, env, passProcessEnv = true, forceColor =
|
|
177
|
+
const { shell = true, printWhileRunning = true, collectOutputWhileRunning = true, throwOnNonZeroCode = true, cwd, env, passProcessEnv = true, forceColor = hasColors, } = opt;
|
|
181
178
|
opt.log ??= printWhileRunning; // by default log should be true, as we are printing the output
|
|
182
179
|
opt.logStart ??= opt.log;
|
|
183
180
|
opt.logFinish ??= opt.log;
|
|
@@ -186,7 +183,7 @@ class Exec2 {
|
|
|
186
183
|
let stdout = '';
|
|
187
184
|
let stderr = '';
|
|
188
185
|
return await new Promise((resolve, reject) => {
|
|
189
|
-
const p =
|
|
186
|
+
const p = spawn(cmd, opt.args || [], {
|
|
190
187
|
shell,
|
|
191
188
|
cwd,
|
|
192
189
|
env: {
|
|
@@ -233,8 +230,8 @@ class Exec2 {
|
|
|
233
230
|
if (!opt.logStart)
|
|
234
231
|
return;
|
|
235
232
|
console.log([
|
|
236
|
-
|
|
237
|
-
|
|
233
|
+
dimGrey(...Object.entries(opt.env || {}).map(([k, v]) => [k, v].join('='))),
|
|
234
|
+
white(opt.name || cmd),
|
|
238
235
|
...((!opt.name && opt.args) || []),
|
|
239
236
|
]
|
|
240
237
|
.filter(Boolean)
|
|
@@ -244,19 +241,18 @@ class Exec2 {
|
|
|
244
241
|
if (isSuccessful && !opt.logFinish)
|
|
245
242
|
return;
|
|
246
243
|
console.log([
|
|
247
|
-
|
|
244
|
+
white(opt.name || cmd),
|
|
248
245
|
...((!opt.name && opt.args) || []),
|
|
249
|
-
|
|
250
|
-
!isSuccessful &&
|
|
246
|
+
dimGrey('took ' + _since(started)),
|
|
247
|
+
!isSuccessful && dimGrey('and ') + dimRed('failed'),
|
|
251
248
|
]
|
|
252
249
|
.filter(Boolean)
|
|
253
250
|
.join(' '));
|
|
254
251
|
}
|
|
255
252
|
}
|
|
256
|
-
|
|
257
|
-
class SpawnError extends
|
|
253
|
+
export const exec2 = new Exec2();
|
|
254
|
+
export class SpawnError extends AppError {
|
|
258
255
|
constructor(message, data) {
|
|
259
256
|
super(message, data, { name: 'SpawnError' });
|
|
260
257
|
}
|
|
261
258
|
}
|
|
262
|
-
exports.SpawnError = SpawnError;
|
package/dist/util/git2.js
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const node_path_1 = require("node:path");
|
|
6
|
-
const colors_1 = require("../colors/colors");
|
|
7
|
-
const exec2_1 = require("./exec2");
|
|
1
|
+
import { execSync } from 'node:child_process';
|
|
2
|
+
import { basename } from 'node:path';
|
|
3
|
+
import { grey } from '../colors/colors.js';
|
|
4
|
+
import { exec2 } from './exec2.js';
|
|
8
5
|
/**
|
|
9
6
|
* Set of utility functions to work with git.
|
|
10
7
|
*/
|
|
11
8
|
class Git2 {
|
|
12
9
|
getLastGitCommitMsg() {
|
|
13
|
-
return
|
|
10
|
+
return exec2.exec('git log -1 --pretty=%B');
|
|
14
11
|
}
|
|
15
12
|
commitMessageToTitleMessage(msg) {
|
|
16
13
|
const firstLine = msg.split('\n')[0];
|
|
@@ -20,7 +17,7 @@ class Git2 {
|
|
|
20
17
|
hasUncommittedChanges() {
|
|
21
18
|
// git diff-index --quiet HEAD -- || echo "untracked"
|
|
22
19
|
try {
|
|
23
|
-
|
|
20
|
+
execSync('git diff-index --quiet HEAD --', {
|
|
24
21
|
encoding: 'utf8',
|
|
25
22
|
});
|
|
26
23
|
return false;
|
|
@@ -37,9 +34,9 @@ class Git2 {
|
|
|
37
34
|
const cmd = `git commit -a --no-verify -m "${msg}"`;
|
|
38
35
|
// const cmd = `git`
|
|
39
36
|
// const args = ['commit', '-a', '--no-verify', '-m', msg]
|
|
40
|
-
console.log(
|
|
37
|
+
console.log(grey(cmd));
|
|
41
38
|
try {
|
|
42
|
-
|
|
39
|
+
execSync(cmd, {
|
|
43
40
|
stdio: 'inherit',
|
|
44
41
|
});
|
|
45
42
|
return true;
|
|
@@ -54,14 +51,14 @@ class Git2 {
|
|
|
54
51
|
isAhead() {
|
|
55
52
|
// ahead=`git rev-list HEAD --not --remotes | wc -l | awk '{print $1}'`
|
|
56
53
|
const cmd = `git rev-list HEAD --not --remotes | wc -l | awk '{print $1}'`;
|
|
57
|
-
const stdout =
|
|
54
|
+
const stdout = exec2.exec(cmd);
|
|
58
55
|
// console.log(`gitIsAhead: ${stdout}`)
|
|
59
56
|
return Number(stdout) > 0;
|
|
60
57
|
}
|
|
61
58
|
pull() {
|
|
62
59
|
const cmd = 'git pull';
|
|
63
60
|
try {
|
|
64
|
-
|
|
61
|
+
execSync(cmd, {
|
|
65
62
|
stdio: 'inherit',
|
|
66
63
|
});
|
|
67
64
|
}
|
|
@@ -74,21 +71,21 @@ class Git2 {
|
|
|
74
71
|
if (branchName) {
|
|
75
72
|
cmd += ` --set-upstream origin ${branchName}`;
|
|
76
73
|
}
|
|
77
|
-
|
|
74
|
+
exec2.spawn(cmd, { logStart: true });
|
|
78
75
|
}
|
|
79
76
|
getCurrentCommitSha(full = false) {
|
|
80
|
-
const sha =
|
|
77
|
+
const sha = exec2.exec('git rev-parse HEAD');
|
|
81
78
|
return full ? sha : sha.slice(0, 7);
|
|
82
79
|
}
|
|
83
80
|
getCurrentCommitTimestamp() {
|
|
84
|
-
return Number(
|
|
81
|
+
return Number(exec2.exec('git log -1 --format=%ct'));
|
|
85
82
|
}
|
|
86
83
|
getCurrentBranchName() {
|
|
87
|
-
return
|
|
84
|
+
return exec2.exec('git rev-parse --abbrev-ref HEAD');
|
|
88
85
|
}
|
|
89
86
|
getCurrentRepoName() {
|
|
90
|
-
const originUrl =
|
|
91
|
-
return
|
|
87
|
+
const originUrl = exec2.exec('git config --get remote.origin.url');
|
|
88
|
+
return basename(originUrl, '.git');
|
|
92
89
|
}
|
|
93
90
|
}
|
|
94
|
-
|
|
91
|
+
export const git2 = new Git2();
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LRUMemoCache = void 0;
|
|
4
|
-
const lru_cache_1 = require("lru-cache");
|
|
1
|
+
import { LRUCache } from 'lru-cache';
|
|
5
2
|
/**
|
|
6
3
|
* @example
|
|
7
4
|
* Use it like this:
|
|
@@ -9,13 +6,14 @@ const lru_cache_1 = require("lru-cache");
|
|
|
9
6
|
* @_Memo({ cacheFactory: () => new LRUMemoCache({...}) })
|
|
10
7
|
* method1 ()
|
|
11
8
|
*/
|
|
12
|
-
class LRUMemoCache {
|
|
9
|
+
export class LRUMemoCache {
|
|
13
10
|
constructor(opt) {
|
|
14
|
-
this.lru = new
|
|
11
|
+
this.lru = new LRUCache({
|
|
15
12
|
max: 100,
|
|
16
13
|
...opt,
|
|
17
14
|
});
|
|
18
15
|
}
|
|
16
|
+
lru;
|
|
19
17
|
has(k) {
|
|
20
18
|
return this.lru.has(k);
|
|
21
19
|
}
|
|
@@ -29,4 +27,3 @@ class LRUMemoCache {
|
|
|
29
27
|
this.lru.clear();
|
|
30
28
|
}
|
|
31
29
|
}
|
|
32
|
-
exports.LRUMemoCache = LRUMemoCache;
|