@naturalcycles/nodejs-lib 12.98.3 → 12.100.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 +8 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/stream/readable/readableCreate.d.ts +1 -1
- package/dist/stream/readable/readableCreate.js +1 -1
- package/dist/stream/transform/transformTee.d.ts +14 -0
- package/dist/stream/transform/transformTee.js +39 -0
- package/dist/util/buildInfo.util.d.ts +8 -2
- package/dist/util/buildInfo.util.js +2 -2
- package/package.json +1 -1
- package/src/bin/generate-build-info.ts +8 -2
- package/src/csv/csvWriter.ts +1 -1
- package/src/index.ts +1 -0
- package/src/slack/slack.service.ts +1 -1
- package/src/stream/readable/readableCreate.ts +1 -1
- package/src/stream/transform/transformTee.ts +45 -0
- package/src/util/buildInfo.util.ts +16 -3
|
@@ -8,13 +8,19 @@ const fs_1 = require("../fs");
|
|
|
8
8
|
const script_1 = require("../script");
|
|
9
9
|
const buildInfo_util_1 = require("../util/buildInfo.util");
|
|
10
10
|
(0, script_1.runScript)(async () => {
|
|
11
|
-
const { dir } = yargs.options({
|
|
11
|
+
const { dir, overrideTimestamp } = yargs.options({
|
|
12
12
|
dir: {
|
|
13
13
|
type: 'string',
|
|
14
14
|
desc: 'Output directory',
|
|
15
15
|
},
|
|
16
|
+
overrideTimestamp: {
|
|
17
|
+
type: 'number',
|
|
18
|
+
desc: 'This unix timestamp will be used instead of "current time"',
|
|
19
|
+
},
|
|
16
20
|
}).argv;
|
|
17
|
-
const buildInfo = (0, buildInfo_util_1.generateBuildInfo)(
|
|
21
|
+
const buildInfo = (0, buildInfo_util_1.generateBuildInfo)({
|
|
22
|
+
overrideTimestamp,
|
|
23
|
+
});
|
|
18
24
|
console.log(buildInfo);
|
|
19
25
|
if (dir)
|
|
20
26
|
fs.mkdirSync(dir, { recursive: true });
|
package/dist/index.d.ts
CHANGED
|
@@ -51,6 +51,7 @@ export * from './stream/transform/transformSplit';
|
|
|
51
51
|
export * from './stream/transform/transformTap';
|
|
52
52
|
export * from './stream/transform/transformToArray';
|
|
53
53
|
export * from './stream/transform/transformToString';
|
|
54
|
+
export * from './stream/transform/transformTee';
|
|
54
55
|
export * from './stream/transform/worker/baseWorkerClass';
|
|
55
56
|
export * from './stream/transform/worker/transformMultiThreaded';
|
|
56
57
|
export * from './stream/transform/worker/transformMultiThreaded.model';
|
package/dist/index.js
CHANGED
|
@@ -56,6 +56,7 @@ tslib_1.__exportStar(require("./stream/transform/transformSplit"), exports);
|
|
|
56
56
|
tslib_1.__exportStar(require("./stream/transform/transformTap"), exports);
|
|
57
57
|
tslib_1.__exportStar(require("./stream/transform/transformToArray"), exports);
|
|
58
58
|
tslib_1.__exportStar(require("./stream/transform/transformToString"), exports);
|
|
59
|
+
tslib_1.__exportStar(require("./stream/transform/transformTee"), exports);
|
|
59
60
|
tslib_1.__exportStar(require("./stream/transform/worker/baseWorkerClass"), exports);
|
|
60
61
|
tslib_1.__exportStar(require("./stream/transform/worker/transformMultiThreaded"), exports);
|
|
61
62
|
tslib_1.__exportStar(require("./stream/transform/worker/transformMultiThreaded.model"), exports);
|
|
@@ -9,7 +9,7 @@ import { ReadableTyped } from '../stream.model';
|
|
|
9
9
|
*
|
|
10
10
|
* Caution!
|
|
11
11
|
* The implementation of this Readable is not fully compliant,
|
|
12
|
-
* e.g the read() method doesn't return anything, so, it will
|
|
12
|
+
* e.g the read() method doesn't return anything, so, it will hang the Node process (or cause it to process.exit(0))
|
|
13
13
|
* if read() will be called AFTER everything was pushed and Readable is closed (by pushing `null`).
|
|
14
14
|
* Beware of it when e.g doing unit testing! Jest prefers to hang (not exit-0).
|
|
15
15
|
*
|
|
@@ -10,7 +10,7 @@ const node_stream_1 = require("node:stream");
|
|
|
10
10
|
*
|
|
11
11
|
* Caution!
|
|
12
12
|
* The implementation of this Readable is not fully compliant,
|
|
13
|
-
* e.g the read() method doesn't return anything, so, it will
|
|
13
|
+
* e.g the read() method doesn't return anything, so, it will hang the Node process (or cause it to process.exit(0))
|
|
14
14
|
* if read() will be called AFTER everything was pushed and Readable is closed (by pushing `null`).
|
|
15
15
|
* Beware of it when e.g doing unit testing! Jest prefers to hang (not exit-0).
|
|
16
16
|
*
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { TransformTyped } from '../stream.model';
|
|
3
|
+
type AnyStream = NodeJS.WritableStream | NodeJS.ReadWriteStream;
|
|
4
|
+
/**
|
|
5
|
+
* Allows to "tee"/"fork" away from the "main pipeline" into the "secondary pipeline".
|
|
6
|
+
*
|
|
7
|
+
* Important, that the main pipeline works "as normal", keeps backpressure, etc.
|
|
8
|
+
* Secondary pipeline DOES NOT keep backpressure.
|
|
9
|
+
* Therefor, the "slowest" pipeline should be made Primary (to keep backpressure).
|
|
10
|
+
*
|
|
11
|
+
* @experimental
|
|
12
|
+
*/
|
|
13
|
+
export declare function transformTee<T>(streams: AnyStream[]): TransformTyped<T>;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformTee = void 0;
|
|
4
|
+
const node_stream_1 = require("node:stream");
|
|
5
|
+
const pipeline_1 = require("../pipeline/pipeline");
|
|
6
|
+
const readableCreate_1 = require("../readable/readableCreate");
|
|
7
|
+
/**
|
|
8
|
+
* Allows to "tee"/"fork" away from the "main pipeline" into the "secondary pipeline".
|
|
9
|
+
*
|
|
10
|
+
* Important, that the main pipeline works "as normal", keeps backpressure, etc.
|
|
11
|
+
* Secondary pipeline DOES NOT keep backpressure.
|
|
12
|
+
* Therefor, the "slowest" pipeline should be made Primary (to keep backpressure).
|
|
13
|
+
*
|
|
14
|
+
* @experimental
|
|
15
|
+
*/
|
|
16
|
+
function transformTee(streams) {
|
|
17
|
+
const readable = (0, readableCreate_1.readableCreate)();
|
|
18
|
+
const secondPipelinePromise = (0, pipeline_1._pipeline)([readable, ...streams]);
|
|
19
|
+
return new node_stream_1.Transform({
|
|
20
|
+
objectMode: true,
|
|
21
|
+
transform(chunk, _, cb) {
|
|
22
|
+
// pass to the "secondary" pipeline
|
|
23
|
+
readable.push(chunk);
|
|
24
|
+
// pass through to the "main" pipeline
|
|
25
|
+
cb(null, chunk);
|
|
26
|
+
},
|
|
27
|
+
async final(cb) {
|
|
28
|
+
console.log('transformTee final');
|
|
29
|
+
// Pushing null "closes"/ends the secondary pipeline correctly
|
|
30
|
+
readable.push(null);
|
|
31
|
+
// Second pipeline is expected to finish now, let's await it
|
|
32
|
+
await secondPipelinePromise;
|
|
33
|
+
console.log('transformTee final secondPipeline done');
|
|
34
|
+
// Because second pipeline is done - now we can signal main pipeline to be done as well
|
|
35
|
+
cb();
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
exports.transformTee = transformTee;
|
|
@@ -1,2 +1,8 @@
|
|
|
1
|
-
import { BuildInfo } from '@naturalcycles/js-lib';
|
|
2
|
-
export
|
|
1
|
+
import { BuildInfo, UnixTimestampNumber } from '@naturalcycles/js-lib';
|
|
2
|
+
export interface GenerateBuildInfoOptions {
|
|
3
|
+
/**
|
|
4
|
+
* If set - this timestamp will be used, instead of "current time".
|
|
5
|
+
*/
|
|
6
|
+
overrideTimestamp?: UnixTimestampNumber;
|
|
7
|
+
}
|
|
8
|
+
export declare function generateBuildInfo(opt?: GenerateBuildInfoOptions): BuildInfo;
|
|
@@ -4,8 +4,8 @@ exports.generateBuildInfo = void 0;
|
|
|
4
4
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
5
5
|
const fs_util_1 = require("../fs/fs.util");
|
|
6
6
|
const git_util_1 = require("./git.util");
|
|
7
|
-
function generateBuildInfo() {
|
|
8
|
-
const now = (0, js_lib_1.localTime)();
|
|
7
|
+
function generateBuildInfo(opt = {}) {
|
|
8
|
+
const now = (0, js_lib_1.localTime)(opt.overrideTimestamp);
|
|
9
9
|
const ts = now.unix();
|
|
10
10
|
const rev = (0, git_util_1.gitCurrentCommitSha)();
|
|
11
11
|
const branchName = (0, git_util_1.gitCurrentBranchName)();
|
package/package.json
CHANGED
|
@@ -8,14 +8,20 @@ import { runScript } from '../script'
|
|
|
8
8
|
import { generateBuildInfo } from '../util/buildInfo.util'
|
|
9
9
|
|
|
10
10
|
runScript(async () => {
|
|
11
|
-
const { dir } = yargs.options({
|
|
11
|
+
const { dir, overrideTimestamp } = yargs.options({
|
|
12
12
|
dir: {
|
|
13
13
|
type: 'string',
|
|
14
14
|
desc: 'Output directory',
|
|
15
15
|
},
|
|
16
|
+
overrideTimestamp: {
|
|
17
|
+
type: 'number',
|
|
18
|
+
desc: 'This unix timestamp will be used instead of "current time"',
|
|
19
|
+
},
|
|
16
20
|
}).argv
|
|
17
21
|
|
|
18
|
-
const buildInfo = generateBuildInfo(
|
|
22
|
+
const buildInfo = generateBuildInfo({
|
|
23
|
+
overrideTimestamp,
|
|
24
|
+
})
|
|
19
25
|
console.log(buildInfo)
|
|
20
26
|
|
|
21
27
|
if (dir) fs.mkdirSync(dir, { recursive: true })
|
package/src/csv/csvWriter.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -51,6 +51,7 @@ export * from './stream/transform/transformSplit'
|
|
|
51
51
|
export * from './stream/transform/transformTap'
|
|
52
52
|
export * from './stream/transform/transformToArray'
|
|
53
53
|
export * from './stream/transform/transformToString'
|
|
54
|
+
export * from './stream/transform/transformTee'
|
|
54
55
|
export * from './stream/transform/worker/baseWorkerClass'
|
|
55
56
|
export * from './stream/transform/worker/transformMultiThreaded'
|
|
56
57
|
export * from './stream/transform/worker/transformMultiThreaded.model'
|
|
@@ -9,7 +9,7 @@ import { ReadableTyped } from '../stream.model'
|
|
|
9
9
|
*
|
|
10
10
|
* Caution!
|
|
11
11
|
* The implementation of this Readable is not fully compliant,
|
|
12
|
-
* e.g the read() method doesn't return anything, so, it will
|
|
12
|
+
* e.g the read() method doesn't return anything, so, it will hang the Node process (or cause it to process.exit(0))
|
|
13
13
|
* if read() will be called AFTER everything was pushed and Readable is closed (by pushing `null`).
|
|
14
14
|
* Beware of it when e.g doing unit testing! Jest prefers to hang (not exit-0).
|
|
15
15
|
*
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Transform } from 'node:stream'
|
|
2
|
+
import { _pipeline } from '../pipeline/pipeline'
|
|
3
|
+
import { readableCreate } from '../readable/readableCreate'
|
|
4
|
+
import { TransformTyped } from '../stream.model'
|
|
5
|
+
|
|
6
|
+
type AnyStream = NodeJS.WritableStream | NodeJS.ReadWriteStream
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Allows to "tee"/"fork" away from the "main pipeline" into the "secondary pipeline".
|
|
10
|
+
*
|
|
11
|
+
* Important, that the main pipeline works "as normal", keeps backpressure, etc.
|
|
12
|
+
* Secondary pipeline DOES NOT keep backpressure.
|
|
13
|
+
* Therefor, the "slowest" pipeline should be made Primary (to keep backpressure).
|
|
14
|
+
*
|
|
15
|
+
* @experimental
|
|
16
|
+
*/
|
|
17
|
+
export function transformTee<T>(streams: AnyStream[]): TransformTyped<T> {
|
|
18
|
+
const readable = readableCreate<T>()
|
|
19
|
+
|
|
20
|
+
const secondPipelinePromise = _pipeline([readable, ...streams])
|
|
21
|
+
|
|
22
|
+
return new Transform({
|
|
23
|
+
objectMode: true,
|
|
24
|
+
transform(chunk: T, _, cb) {
|
|
25
|
+
// pass to the "secondary" pipeline
|
|
26
|
+
readable.push(chunk)
|
|
27
|
+
|
|
28
|
+
// pass through to the "main" pipeline
|
|
29
|
+
cb(null, chunk)
|
|
30
|
+
},
|
|
31
|
+
async final(cb) {
|
|
32
|
+
console.log('transformTee final')
|
|
33
|
+
|
|
34
|
+
// Pushing null "closes"/ends the secondary pipeline correctly
|
|
35
|
+
readable.push(null)
|
|
36
|
+
|
|
37
|
+
// Second pipeline is expected to finish now, let's await it
|
|
38
|
+
await secondPipelinePromise
|
|
39
|
+
console.log('transformTee final secondPipeline done')
|
|
40
|
+
|
|
41
|
+
// Because second pipeline is done - now we can signal main pipeline to be done as well
|
|
42
|
+
cb()
|
|
43
|
+
},
|
|
44
|
+
})
|
|
45
|
+
}
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
_filterUndefinedValues,
|
|
3
|
+
AnyObject,
|
|
4
|
+
BuildInfo,
|
|
5
|
+
localTime,
|
|
6
|
+
UnixTimestampNumber,
|
|
7
|
+
} from '@naturalcycles/js-lib'
|
|
2
8
|
import { _pathExistsSync, _readJsonSync } from '../fs/fs.util'
|
|
3
9
|
import {
|
|
4
10
|
gitCurrentBranchName,
|
|
@@ -7,8 +13,15 @@ import {
|
|
|
7
13
|
gitCurrentRepoName,
|
|
8
14
|
} from './git.util'
|
|
9
15
|
|
|
10
|
-
export
|
|
11
|
-
|
|
16
|
+
export interface GenerateBuildInfoOptions {
|
|
17
|
+
/**
|
|
18
|
+
* If set - this timestamp will be used, instead of "current time".
|
|
19
|
+
*/
|
|
20
|
+
overrideTimestamp?: UnixTimestampNumber
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function generateBuildInfo(opt: GenerateBuildInfoOptions = {}): BuildInfo {
|
|
24
|
+
const now = localTime(opt.overrideTimestamp)
|
|
12
25
|
const ts = now.unix()
|
|
13
26
|
|
|
14
27
|
const rev = gitCurrentCommitSha()
|