@naturalcycles/nodejs-lib 12.99.0 → 12.101.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/json2env.js +9 -6
- 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/package.json +1 -1
- package/src/fs/json2env.ts +9 -6
- package/src/index.ts +1 -0
- package/src/stream/readable/readableCreate.ts +1 -1
- package/src/stream/transform/transformTee.ts +45 -0
package/dist/fs/json2env.js
CHANGED
|
@@ -53,24 +53,27 @@ exports.json2env = json2env;
|
|
|
53
53
|
function appendToBashEnv(obj, prefix = '') {
|
|
54
54
|
const { BASH_ENV } = process.env;
|
|
55
55
|
if (BASH_ENV) {
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
const data = objectToShellExport(obj, prefix);
|
|
57
|
+
fs.appendFileSync(BASH_ENV, data);
|
|
58
|
+
console.log(`BASH_ENV file appended (${(0, colors_1.dimGrey)(BASH_ENV)})\n${data}`);
|
|
58
59
|
}
|
|
59
60
|
}
|
|
60
61
|
exports.appendToBashEnv = appendToBashEnv;
|
|
61
62
|
function appendToGithubEnv(obj, prefix = '') {
|
|
62
63
|
const { GITHUB_ENV } = process.env;
|
|
63
64
|
if (GITHUB_ENV) {
|
|
64
|
-
|
|
65
|
-
|
|
65
|
+
const data = objectToGithubActionsEnv(obj, prefix);
|
|
66
|
+
fs.appendFileSync(GITHUB_ENV, data);
|
|
67
|
+
console.log(`GITHUB_ENV file appended (${(0, colors_1.dimGrey)(GITHUB_ENV)})\n${data}`);
|
|
66
68
|
}
|
|
67
69
|
}
|
|
68
70
|
exports.appendToGithubEnv = appendToGithubEnv;
|
|
69
71
|
function appendToGithubOutput(obj, prefix = '') {
|
|
70
72
|
const { GITHUB_OUTPUT } = process.env;
|
|
71
73
|
if (GITHUB_OUTPUT) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
+
const data = objectToGithubActionsEnv(obj, prefix);
|
|
75
|
+
fs.appendFileSync(GITHUB_OUTPUT, data);
|
|
76
|
+
console.log(`GITHUB_OUTPUT file appended (${(0, colors_1.dimGrey)(GITHUB_OUTPUT)})\n${data}`);
|
|
74
77
|
}
|
|
75
78
|
}
|
|
76
79
|
exports.appendToGithubOutput = appendToGithubOutput;
|
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;
|
package/package.json
CHANGED
package/src/fs/json2env.ts
CHANGED
|
@@ -93,24 +93,27 @@ export function json2env(opt: Json2EnvOptions): void {
|
|
|
93
93
|
export function appendToBashEnv(obj: AnyObject, prefix = ''): void {
|
|
94
94
|
const { BASH_ENV } = process.env
|
|
95
95
|
if (BASH_ENV) {
|
|
96
|
-
|
|
97
|
-
|
|
96
|
+
const data = objectToShellExport(obj, prefix)
|
|
97
|
+
fs.appendFileSync(BASH_ENV, data)
|
|
98
|
+
console.log(`BASH_ENV file appended (${dimGrey(BASH_ENV)})\n${data}`)
|
|
98
99
|
}
|
|
99
100
|
}
|
|
100
101
|
|
|
101
102
|
export function appendToGithubEnv(obj: AnyObject, prefix = ''): void {
|
|
102
103
|
const { GITHUB_ENV } = process.env
|
|
103
104
|
if (GITHUB_ENV) {
|
|
104
|
-
|
|
105
|
-
|
|
105
|
+
const data = objectToGithubActionsEnv(obj, prefix)
|
|
106
|
+
fs.appendFileSync(GITHUB_ENV, data)
|
|
107
|
+
console.log(`GITHUB_ENV file appended (${dimGrey(GITHUB_ENV)})\n${data}`)
|
|
106
108
|
}
|
|
107
109
|
}
|
|
108
110
|
|
|
109
111
|
export function appendToGithubOutput(obj: AnyObject, prefix = ''): void {
|
|
110
112
|
const { GITHUB_OUTPUT } = process.env
|
|
111
113
|
if (GITHUB_OUTPUT) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
+
const data = objectToGithubActionsEnv(obj, prefix)
|
|
115
|
+
fs.appendFileSync(GITHUB_OUTPUT, data)
|
|
116
|
+
console.log(`GITHUB_OUTPUT file appended (${dimGrey(GITHUB_OUTPUT)})\n${data}`)
|
|
114
117
|
}
|
|
115
118
|
}
|
|
116
119
|
|
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
|
+
}
|