@konker.dev/tiny-utils-fp 0.0.1 → 0.1.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/README.md +3 -38
- package/dist/array.d.ts +3 -0
- package/dist/array.d.ts.map +1 -0
- package/dist/array.js +7 -0
- package/dist/array.js.map +1 -0
- package/dist/hash.d.ts +5 -0
- package/dist/hash.d.ts.map +1 -0
- package/dist/hash.js +16 -0
- package/dist/hash.js.map +1 -0
- package/dist/stream/BufferWriteableStream.d.ts +27 -0
- package/dist/stream/BufferWriteableStream.d.ts.map +1 -0
- package/dist/stream/BufferWriteableStream.js +40 -0
- package/dist/stream/BufferWriteableStream.js.map +1 -0
- package/dist/stream/BufferWriteableStream.test.d.ts +2 -0
- package/dist/stream/BufferWriteableStream.test.d.ts.map +1 -0
- package/dist/stream/BufferWriteableStream.test.js +21 -0
- package/dist/stream/BufferWriteableStream.test.js.map +1 -0
- package/dist/stream/ChildProcessStreamPipe.d.ts +22 -0
- package/dist/stream/ChildProcessStreamPipe.d.ts.map +1 -0
- package/dist/stream/ChildProcessStreamPipe.js +93 -0
- package/dist/stream/ChildProcessStreamPipe.js.map +1 -0
- package/dist/stream/ChildProcessStreamPipe.test.d.ts +2 -0
- package/dist/stream/ChildProcessStreamPipe.test.d.ts.map +1 -0
- package/dist/stream/ChildProcessStreamPipe.test.js +70 -0
- package/dist/stream/ChildProcessStreamPipe.test.js.map +1 -0
- package/dist/stream/index.d.ts +21 -0
- package/dist/stream/index.d.ts.map +1 -0
- package/dist/stream/index.js +63 -0
- package/dist/stream/index.js.map +1 -0
- package/dist/stream/index.test.d.ts +2 -0
- package/dist/stream/index.test.d.ts.map +1 -0
- package/dist/stream/index.test.js +62 -0
- package/dist/stream/index.test.js.map +1 -0
- package/package.json +62 -45
- package/dist/index.d.ts +0 -4
- package/dist/index.js +0 -48
- package/dist/index.js.map +0 -1
package/README.md
CHANGED
|
@@ -2,44 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
General utility functions for [Node.js](https://nodejs.org/) based on [Effect-TS](https://www.effect.website/)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
FIXME: test coverage for `src/stream/ChildProcessStreamPipe.ts`
|
|
6
|
+
|
|
7
|
+

|
|
6
8
|
[](https://www.npmjs.com/package/@konker.dev/tiny-utils-fp)
|
|
7
9
|
[](https://github.com/konkerdotdev/tiny-utils-fp/actions/workflows/ci.yml)
|
|
8
10
|
[](https://codecov.io/gh/konkerdotdev/tiny-utils-fp)
|
|
9
|
-
|
|
10
|
-
## Usage
|
|
11
|
-
|
|
12
|
-
Copy the contents of this repo, and:
|
|
13
|
-
|
|
14
|
-
- Search and replace files for `YOUR_SRC_DIR_COULD_BE_DOT` and substitute for the desired source directory
|
|
15
|
-
- Edit package.json `staticFiles` property as needed
|
|
16
|
-
- Run `pnpm install`
|
|
17
|
-
- Run `git init`
|
|
18
|
-
- Run: `pnpm dlx husky-init && pnpm install`
|
|
19
|
-
- Replace this with your actual README.md
|
|
20
|
-
- Replace ISC.LICENSE as needed
|
|
21
|
-
- Amend .github/workflows/cd.yml to replace `PATH_TO_PACKAGE_JSON`
|
|
22
|
-
- Remember:
|
|
23
|
-
- README.md title / content
|
|
24
|
-
- package.json name
|
|
25
|
-
- package.json description
|
|
26
|
-
|
|
27
|
-
## For An Existing Project
|
|
28
|
-
|
|
29
|
-
- Copy the following. merging as necessary:
|
|
30
|
-
- .editorconfig
|
|
31
|
-
- .eslintignore
|
|
32
|
-
- .eslintrc.json
|
|
33
|
-
- .madgerc
|
|
34
|
-
- .nvmrc
|
|
35
|
-
- .prettierignore
|
|
36
|
-
- .prettierrc
|
|
37
|
-
- gulpfile.mjs
|
|
38
|
-
- jest.config.ts
|
|
39
|
-
- Replaces jest.config.js if applicable
|
|
40
|
-
- tsconfig.json
|
|
41
|
-
- Search and replace for `YOUR_SRC_DIR_COULD_BE_DOT`
|
|
42
|
-
- Merge .gitignore
|
|
43
|
-
- Copy over dev dependencies not already present
|
|
44
|
-
- Copy over dependencies not already present
|
|
45
|
-
- LICENSE
|
package/dist/array.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../src/array.ts"],"names":[],"mappings":"AAAA,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,UAAU,CAEjE;AAED,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,WAAW,GAAG,MAAM,CAE1D"}
|
package/dist/array.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array.js","sourceRoot":"","sources":["../src/array.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,kBAAkB,CAAC,CAAkB;IACnD,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAC7C,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,CAAc;IAChD,OAAO,IAAI,WAAW,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AAC5C,CAAC"}
|
package/dist/hash.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import * as Effect from 'effect/Effect';
|
|
2
|
+
export declare const md5Hex: (s: string) => Effect.Effect<string, Error>;
|
|
3
|
+
export declare const sha256Hex: (s: string) => Effect.Effect<string, Error>;
|
|
4
|
+
export declare const sha256HmacHex: (s: string, secret: string) => Effect.Effect<string, Error>;
|
|
5
|
+
//# sourceMappingURL=hash.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../src/hash.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,eAAO,MAAM,MAAM,MAAO,MAAM,KAAG,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAI1D,CAAC;AAEL,eAAO,MAAM,SAAS,MAAO,MAAM,KAAG,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAI7D,CAAC;AAEL,eAAO,MAAM,aAAa,MAAO,MAAM,UAAU,MAAM,KAAG,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAIjF,CAAC"}
|
package/dist/hash.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import { toError } from '@konker.dev/tiny-error-fp/lib';
|
|
3
|
+
import * as Effect from 'effect/Effect';
|
|
4
|
+
export const md5Hex = (s) => Effect.try({
|
|
5
|
+
try: () => crypto.createHash('md5').update(s).digest('hex'),
|
|
6
|
+
catch: toError,
|
|
7
|
+
});
|
|
8
|
+
export const sha256Hex = (s) => Effect.try({
|
|
9
|
+
try: () => crypto.createHash('sha256').update(s).digest('hex'),
|
|
10
|
+
catch: toError,
|
|
11
|
+
});
|
|
12
|
+
export const sha256HmacHex = (s, secret) => Effect.try({
|
|
13
|
+
try: () => crypto.createHmac('sha256', secret).update(s).digest('hex'),
|
|
14
|
+
catch: toError,
|
|
15
|
+
});
|
|
16
|
+
//# sourceMappingURL=hash.js.map
|
package/dist/hash.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.js","sourceRoot":"","sources":["../src/hash.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AAEjC,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AACxD,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,CAAS,EAAgC,EAAE,CAChE,MAAM,CAAC,GAAG,CAAC;IACT,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;IAC3D,KAAK,EAAE,OAAO;CACf,CAAC,CAAC;AAEL,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAS,EAAgC,EAAE,CACnE,MAAM,CAAC,GAAG,CAAC;IACT,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;IAC9D,KAAK,EAAE,OAAO;CACf,CAAC,CAAC;AAEL,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAS,EAAE,MAAc,EAAgC,EAAE,CACvF,MAAM,CAAC,GAAG,CAAC;IACT,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;IACtE,KAAK,EAAE,OAAO;CACf,CAAC,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Writable } from 'node:stream';
|
|
2
|
+
/**
|
|
3
|
+
* Simplistic implementation of a Writeable which stores the data in a Buffer
|
|
4
|
+
* The contents can be extracted as a Buffer or as a UTF-8 string.
|
|
5
|
+
*
|
|
6
|
+
* Mainly useful for testing stream based code. If something like this is
|
|
7
|
+
* needed for production use, consider a more comprehensive/optimized
|
|
8
|
+
* implementation such as: https://github.com/samcday/node-stream-buffer
|
|
9
|
+
*/
|
|
10
|
+
export declare class BufferWriteableStream extends Writable {
|
|
11
|
+
readonly bufferList: Array<Buffer>;
|
|
12
|
+
constructor();
|
|
13
|
+
_write(chunk: never, _encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
|
|
14
|
+
/**
|
|
15
|
+
* Get the current size of the data in the buffer
|
|
16
|
+
*/
|
|
17
|
+
get size(): number;
|
|
18
|
+
/**
|
|
19
|
+
* Get the underlying buffer for this stream
|
|
20
|
+
*/
|
|
21
|
+
get buffer(): Buffer;
|
|
22
|
+
/**
|
|
23
|
+
* Get the contents of the buffer as a UTF-8 string
|
|
24
|
+
*/
|
|
25
|
+
get string(): string;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=BufferWriteableStream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BufferWriteableStream.d.ts","sourceRoot":"","sources":["../../src/stream/BufferWriteableStream.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC;;;;;;;GAOG;AACH,qBAAa,qBAAsB,SAAQ,QAAQ;IACjD,QAAQ,CAAC,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;;IAO1B,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,QAAQ,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI,KAAK,IAAI,GAAG,IAAI;IAKxG;;OAEG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;OAEG;IACH,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED;;OAEG;IACH,IAAI,MAAM,IAAI,MAAM,CAEnB;CACF"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/* eslint-disable fp/no-class,fp/no-unused-expression,fp/no-nil,fp/no-mutating-methods,fp/no-this,fp/no-mutation */
|
|
2
|
+
import { Writable } from 'node:stream';
|
|
3
|
+
/**
|
|
4
|
+
* Simplistic implementation of a Writeable which stores the data in a Buffer
|
|
5
|
+
* The contents can be extracted as a Buffer or as a UTF-8 string.
|
|
6
|
+
*
|
|
7
|
+
* Mainly useful for testing stream based code. If something like this is
|
|
8
|
+
* needed for production use, consider a more comprehensive/optimized
|
|
9
|
+
* implementation such as: https://github.com/samcday/node-stream-buffer
|
|
10
|
+
*/
|
|
11
|
+
export class BufferWriteableStream extends Writable {
|
|
12
|
+
bufferList;
|
|
13
|
+
constructor() {
|
|
14
|
+
super();
|
|
15
|
+
this.bufferList = [];
|
|
16
|
+
}
|
|
17
|
+
_write(chunk, _encoding, callback) {
|
|
18
|
+
this.bufferList.push(Buffer.from(chunk));
|
|
19
|
+
callback();
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Get the current size of the data in the buffer
|
|
23
|
+
*/
|
|
24
|
+
get size() {
|
|
25
|
+
return this.bufferList.reduce((acc, val) => acc + val.length, 0);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Get the underlying buffer for this stream
|
|
29
|
+
*/
|
|
30
|
+
get buffer() {
|
|
31
|
+
return Buffer.concat(this.bufferList);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Get the contents of the buffer as a UTF-8 string
|
|
35
|
+
*/
|
|
36
|
+
get string() {
|
|
37
|
+
return this.buffer.toString('utf8');
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=BufferWriteableStream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BufferWriteableStream.js","sourceRoot":"","sources":["../../src/stream/BufferWriteableStream.ts"],"names":[],"mappings":"AAAA,mHAAmH;AACnH,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC;;;;;;;GAOG;AACH,MAAM,OAAO,qBAAsB,SAAQ,QAAQ;IACxC,UAAU,CAAgB;IAEnC;QACE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;IACvB,CAAC;IAEQ,MAAM,CAAC,KAAY,EAAE,SAAyB,EAAE,QAAwC;QAC/F,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;QACzC,QAAQ,EAAE,CAAC;IACb,CAAC;IAED;;OAEG;IACH,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,GAAG,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IACnE,CAAC;IAED;;OAEG;IACH,IAAI,MAAM;QACR,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACxC,CAAC;IAED;;OAEG;IACH,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IACtC,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BufferWriteableStream.test.d.ts","sourceRoot":"","sources":["../../src/stream/BufferWriteableStream.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import * as unit from './BufferWriteableStream.js';
|
|
3
|
+
describe('BufferWriteableStream', () => {
|
|
4
|
+
const TEST_STRING_1 = 'hoi noi broin coi';
|
|
5
|
+
const TEST_STRING_2 = 'three blind mice';
|
|
6
|
+
it('should work as expected', () => {
|
|
7
|
+
const actual = new unit.BufferWriteableStream();
|
|
8
|
+
actual.write(TEST_STRING_1);
|
|
9
|
+
actual.end();
|
|
10
|
+
expect(actual.size).toEqual(TEST_STRING_1.length);
|
|
11
|
+
expect(actual.string).toEqual(TEST_STRING_1);
|
|
12
|
+
});
|
|
13
|
+
it('should work as expected', () => {
|
|
14
|
+
const actual = new unit.BufferWriteableStream();
|
|
15
|
+
actual.write(TEST_STRING_2);
|
|
16
|
+
actual.end();
|
|
17
|
+
expect(actual.size).toEqual(TEST_STRING_2.length);
|
|
18
|
+
expect(actual.string).toEqual(TEST_STRING_2);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
//# sourceMappingURL=BufferWriteableStream.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BufferWriteableStream.test.js","sourceRoot":"","sources":["../../src/stream/BufferWriteableStream.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAE9C,OAAO,KAAK,IAAI,MAAM,4BAA4B,CAAC;AAEnD,QAAQ,CAAC,uBAAuB,EAAE,GAAG,EAAE;IACrC,MAAM,aAAa,GAAG,mBAAmB,CAAC;IAC1C,MAAM,aAAa,GAAG,kBAAkB,CAAC;IAEzC,EAAE,CAAC,yBAAyB,EAAE,GAAG,EAAE;QACjC,MAAM,MAAM,GAAG,IAAI,IAAI,CAAC,qBAAqB,EAAE,CAAC;QAChD,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;QAC5B,MAAM,CAAC,GAAG,EAAE,CAAC;QAEb,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QAClD,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IAC/C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,yBAAyB,EAAE,GAAG,EAAE;QACjC,MAAM,MAAM,GAAG,IAAI,IAAI,CAAC,qBAAqB,EAAE,CAAC;QAChD,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;QAC5B,MAAM,CAAC,GAAG,EAAE,CAAC;QAEb,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QAClD,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IAC/C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ChildProcessWithoutNullStreams } from 'node:child_process';
|
|
2
|
+
import type { TransformCallback } from 'node:stream';
|
|
3
|
+
import { Stream } from 'node:stream';
|
|
4
|
+
export declare class ChildProcessStreamPipe extends Stream.Transform {
|
|
5
|
+
readonly cmd: string;
|
|
6
|
+
readonly _args: Array<string>;
|
|
7
|
+
_input: string;
|
|
8
|
+
_output: string;
|
|
9
|
+
_execStarted: boolean;
|
|
10
|
+
_childProcess: ChildProcessWithoutNullStreams | undefined;
|
|
11
|
+
constructor(cmd: string, args?: Array<string>);
|
|
12
|
+
_transform(chunk: unknown, encoding: BufferEncoding, callback: TransformCallback): void;
|
|
13
|
+
_flush(callback: (error?: Error | null) => void): void;
|
|
14
|
+
resume(): this;
|
|
15
|
+
input(s: string): ChildProcessStreamPipe;
|
|
16
|
+
output(s: string): ChildProcessStreamPipe;
|
|
17
|
+
arg(arg: string): ChildProcessStreamPipe;
|
|
18
|
+
get args(): Array<string>;
|
|
19
|
+
exec(): void;
|
|
20
|
+
onError(err: unknown | undefined): void;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=ChildProcessStreamPipe.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChildProcessStreamPipe.d.ts","sourceRoot":"","sources":["../../src/stream/ChildProcessStreamPipe.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,oBAAoB,CAAC;AAEzE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAOrC,qBAAa,sBAAuB,SAAQ,MAAM,CAAC,SAAS;IAC1D,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,OAAO,CAAC;IACtB,aAAa,EAAE,8BAA8B,GAAG,SAAS,CAAC;gBAE9C,GAAG,EAAE,MAAM,EAAE,IAAI,GAAE,KAAK,CAAC,MAAM,CAAM;IAUxC,UAAU,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,QAAQ,EAAE,iBAAiB,GAAG,IAAI;IAUvF,MAAM,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI,KAAK,IAAI,GAAG,IAAI;IAStD,MAAM;IAQf,KAAK,CAAC,CAAC,EAAE,MAAM,GAAG,sBAAsB;IAKxC,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,sBAAsB;IAKzC,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,sBAAsB;IAKxC,IAAI,IAAI,IAAI,KAAK,CAAC,MAAM,CAAC,CAExB;IAED,IAAI,IAAI,IAAI;IAwBZ,OAAO,CAAC,GAAG,EAAE,OAAO,GAAG,SAAS;CAKjC"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { Stream } from 'node:stream';
|
|
3
|
+
import { isNativeError } from 'node:util/types';
|
|
4
|
+
/*
|
|
5
|
+
* See: https://www.jameskerr.blog/posts/pipe-nodejs-readable-stream-into-child-process/
|
|
6
|
+
* See: https://www.npmjs.com/package/imagemagick-stream
|
|
7
|
+
*/
|
|
8
|
+
export class ChildProcessStreamPipe extends Stream.Transform {
|
|
9
|
+
cmd;
|
|
10
|
+
_args;
|
|
11
|
+
_input;
|
|
12
|
+
_output;
|
|
13
|
+
_execStarted;
|
|
14
|
+
_childProcess;
|
|
15
|
+
constructor(cmd, args = []) {
|
|
16
|
+
super();
|
|
17
|
+
this.cmd = cmd;
|
|
18
|
+
this._input = '-';
|
|
19
|
+
this._output = '-';
|
|
20
|
+
this._args = args;
|
|
21
|
+
this._execStarted = false;
|
|
22
|
+
}
|
|
23
|
+
_transform(chunk, encoding, callback) {
|
|
24
|
+
if (!this.destroyed && this._childProcess?.stdin.write(chunk, encoding)) {
|
|
25
|
+
process.nextTick(callback);
|
|
26
|
+
}
|
|
27
|
+
else if (!this.destroyed) {
|
|
28
|
+
this._childProcess?.stdin.once('drain', callback);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
callback();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
_flush(callback) {
|
|
35
|
+
this._childProcess?.stdin.end();
|
|
36
|
+
if (this._childProcess?.stdout.destroyed) {
|
|
37
|
+
callback();
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
this._childProcess?.stdout.on('close', () => callback());
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
resume() {
|
|
44
|
+
if (!this._execStarted) {
|
|
45
|
+
this.exec();
|
|
46
|
+
}
|
|
47
|
+
this._execStarted = true;
|
|
48
|
+
return super.resume();
|
|
49
|
+
}
|
|
50
|
+
input(s) {
|
|
51
|
+
this._input = s;
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
output(s) {
|
|
55
|
+
this._output = s;
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
arg(arg) {
|
|
59
|
+
this._args.push(arg);
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
get args() {
|
|
63
|
+
return this._args.flatMap((x) => x.split(' '));
|
|
64
|
+
}
|
|
65
|
+
exec() {
|
|
66
|
+
const onError = this.onError.bind(this);
|
|
67
|
+
try {
|
|
68
|
+
this._childProcess = spawn(this.cmd, [this._input, ...this.args, this._output]);
|
|
69
|
+
this._childProcess.on('error', onError);
|
|
70
|
+
this._childProcess.stdout.on('data', (data) => this.push(data));
|
|
71
|
+
this._childProcess.stdin?.on('error', (e) => {
|
|
72
|
+
if (!!e && typeof e === 'object' && 'code' in e && e.code === 'EPIPE') {
|
|
73
|
+
this.emit('end');
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
onError(e);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
this._childProcess.stdout.on('error', onError);
|
|
80
|
+
this._childProcess.stderr.on('error', onError);
|
|
81
|
+
this._childProcess.stderr.on('data', (data) => onError(new Error(data.toString())));
|
|
82
|
+
}
|
|
83
|
+
catch (e) {
|
|
84
|
+
onError(e);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
onError(err) {
|
|
88
|
+
const errorErr = isNativeError(err) ? err : new Error(String(err));
|
|
89
|
+
this.destroy(errorErr);
|
|
90
|
+
this.emit('end');
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=ChildProcessStreamPipe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChildProcessStreamPipe.js","sourceRoot":"","sources":["../../src/stream/ChildProcessStreamPipe.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;;GAGG;AACH,MAAM,OAAO,sBAAuB,SAAQ,MAAM,CAAC,SAAS;IACjD,GAAG,CAAS;IACZ,KAAK,CAAgB;IAC9B,MAAM,CAAS;IACf,OAAO,CAAS;IAChB,YAAY,CAAU;IACtB,aAAa,CAA6C;IAE1D,YAAY,GAAW,EAAE,OAAsB,EAAE;QAC/C,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC;QAClB,IAAI,CAAC,OAAO,GAAG,GAAG,CAAC;QACnB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC;IAC5B,CAAC;IAEQ,UAAU,CAAC,KAAc,EAAE,QAAwB,EAAE,QAA2B;QACvF,IAAI,CAAC,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,aAAa,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,QAAQ,CAAC,EAAE,CAAC;YACxE,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QAC7B,CAAC;aAAM,IAAI,CAAC,IAAI,CAAC,SAAS,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IACH,CAAC;IAED,OAAO,CAAC,GAAwB;QAC9B,MAAM,QAAQ,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;QACnE,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACvB,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACnB,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChildProcessStreamPipe.test.d.ts","sourceRoot":"","sources":["../../src/stream/ChildProcessStreamPipe.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import * as childProcess from 'node:child_process';
|
|
2
|
+
import { PassThrough, Readable } from 'node:stream';
|
|
3
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
4
|
+
import { BufferWriteableStream } from './BufferWriteableStream.js';
|
|
5
|
+
import * as unit from './ChildProcessStreamPipe.js';
|
|
6
|
+
import { waitForWriteStreamPromise } from './index.js';
|
|
7
|
+
describe('ChildProcessStreamPipe', () => {
|
|
8
|
+
const TEST_S = 'hoi noi broin coi';
|
|
9
|
+
it('should formulate args as expected', () => {
|
|
10
|
+
const actual = new unit.ChildProcessStreamPipe('sed', []);
|
|
11
|
+
actual.arg('-foo bar').arg('-baz');
|
|
12
|
+
expect(actual.args).toStrictEqual(['-foo', 'bar', '-baz']);
|
|
13
|
+
});
|
|
14
|
+
it('should work as expected in the success case', async () => {
|
|
15
|
+
const actual = new unit.ChildProcessStreamPipe('sed', ['-e', 's/\\(.*\\)/\\U\\1/']).input('-').output('-');
|
|
16
|
+
const inStream = Readable.from(TEST_S);
|
|
17
|
+
const outStream = new BufferWriteableStream();
|
|
18
|
+
inStream.pipe(actual).pipe(outStream);
|
|
19
|
+
await waitForWriteStreamPromise(outStream);
|
|
20
|
+
actual._flush(vi.fn());
|
|
21
|
+
expect(outStream.string).toEqual('HOI NOI BROIN COI');
|
|
22
|
+
});
|
|
23
|
+
// Test fails due to Unhandled error
|
|
24
|
+
// FIXME: Needs further work
|
|
25
|
+
it.skip('should work as expected with a stdin error', async () => {
|
|
26
|
+
const actual = new unit.ChildProcessStreamPipe('sed', ['-e', 's/\\(.*\\)/\\U\\1/']).input('-').output('-');
|
|
27
|
+
const inStream = Readable.from(TEST_S);
|
|
28
|
+
const outStream = new BufferWriteableStream();
|
|
29
|
+
inStream.pipe(actual).pipe(outStream);
|
|
30
|
+
actual._childProcess?.stdin.emit('error', new Error('BOOM!'));
|
|
31
|
+
await waitForWriteStreamPromise(outStream);
|
|
32
|
+
expect(outStream.string).toEqual('');
|
|
33
|
+
});
|
|
34
|
+
it('should work as expected with a stdin EPIPE error', async () => {
|
|
35
|
+
const actual = new unit.ChildProcessStreamPipe('sed', ['-e', 's/\\(.*\\)/\\U\\1/']).input('-').output('-');
|
|
36
|
+
const inStream = Readable.from(TEST_S);
|
|
37
|
+
const outStream = new BufferWriteableStream();
|
|
38
|
+
inStream.pipe(actual).pipe(outStream);
|
|
39
|
+
actual._childProcess?.stdin.emit('error', { code: 'EPIPE' });
|
|
40
|
+
await waitForWriteStreamPromise(outStream);
|
|
41
|
+
expect(outStream.string).toEqual('');
|
|
42
|
+
});
|
|
43
|
+
// Test fails with: TypeError: Cannot redefine property: spawn
|
|
44
|
+
// FIXME: Needs more work
|
|
45
|
+
it.skip('should work as expected in error case', () => {
|
|
46
|
+
vi.spyOn(childProcess, 'spawn').mockImplementationOnce(() => {
|
|
47
|
+
throw new Error('BOOM!');
|
|
48
|
+
});
|
|
49
|
+
const inStream = Readable.from(TEST_S);
|
|
50
|
+
const outStream = new PassThrough();
|
|
51
|
+
const actual = new unit.ChildProcessStreamPipe('cat', ['/tmp/LICENSE']);
|
|
52
|
+
inStream.pipe(actual).pipe(outStream);
|
|
53
|
+
expect(() => {
|
|
54
|
+
return waitForWriteStreamPromise(outStream);
|
|
55
|
+
}).toBeDefined();
|
|
56
|
+
});
|
|
57
|
+
// Causes Unhandled error, but still passes.
|
|
58
|
+
// Plus is not really a proper test for errors due to tricky stream stuff
|
|
59
|
+
// FIXME: Needs further work
|
|
60
|
+
it.skip('should work as expected in error case', () => {
|
|
61
|
+
const inStream = Readable.from(TEST_S);
|
|
62
|
+
const outStream = new PassThrough();
|
|
63
|
+
const actual = new unit.ChildProcessStreamPipe('cat', ['/tmp/doesnotexist']);
|
|
64
|
+
inStream.pipe(actual).pipe(outStream);
|
|
65
|
+
expect(() => {
|
|
66
|
+
return waitForWriteStreamPromise(outStream);
|
|
67
|
+
}).toBeDefined();
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
//# sourceMappingURL=ChildProcessStreamPipe.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChildProcessStreamPipe.test.js","sourceRoot":"","sources":["../../src/stream/ChildProcessStreamPipe.test.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,YAAY,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEpD,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAElD,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,KAAK,IAAI,MAAM,6BAA6B,CAAC;AACpD,OAAO,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAEvD,QAAQ,CAAC,wBAAwB,EAAE,GAAG,EAAE;IACtC,MAAM,MAAM,GAAG,mBAA4B,CAAC;IAE5C,EAAE,CAAC,mCAAmC,EAAE,GAAG,EAAE;QAC3C,MAAM,MAAM,GAAG,IAAI,IAAI,CAAC,sBAAsB,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAC1D,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,MAAM,C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AQ,GAAG,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACvC,MAAM,SAAS,GAAG,IAAI,WAAW,EAAE,CAAC;QACpC,MAAM,MAAM,GAAG,IAAI,IAAI,CAAC,sBAAsB,CAAC,KAAK,EAAE,CAAC,cAAc,CAAC,CAAC,CAAC;QACxE,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAEtC,MAAM,CAAC,GAAG,EAAE;YACV,OAAO,yBAAyB,CAAC,SAAS,CAAC,CAAC;QAC9C,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;IACnB,CAAC,CAAC,CAAC;IAEH,4CAA4C;IAC5C,yEAAyE;IACzE,4BAA4B;IAC5B,EAAE,CAAC,IAAI,CAAC,uCAAuC,EAAE,GAAG,EAAE;QACpD,MAAM,QAAQ,GAAG,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACvC,MAAM,SAAS,GAAG,IAAI,WAAW,EAAE,CAAC;QACpC,MAAM,MAAM,GAAG,IAAI,IAAI,CAAC,sBAAsB,CAAC,KAAK,EAAE,CAAC,mBAAmB,CAAC,CAAC,CAAC;QAC7E,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAEtC,MAAM,CAAC,GAAG,EAAE;YACV,OAAO,yBAAyB,CAAC,SAAS,CAAC,CAAC;QAC9C,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;IACnB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Readable, Writable } from 'node:stream';
|
|
2
|
+
import type { ReadableStream } from 'node:stream/web';
|
|
3
|
+
import * as Effect from 'effect/Effect';
|
|
4
|
+
/**
|
|
5
|
+
* Consume a readStream
|
|
6
|
+
* @param readStream
|
|
7
|
+
*/
|
|
8
|
+
export declare function readStreamToBuffer(readStream: Readable | ReadableStream): Effect.Effect<Uint8Array, Error>;
|
|
9
|
+
/**
|
|
10
|
+
* Wait for a writable stream to finish
|
|
11
|
+
*/
|
|
12
|
+
export declare function waitForWriteStreamPromise(writeStream: Writable): Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Wait for a writable stream to finish
|
|
15
|
+
*/
|
|
16
|
+
export declare function waitForWriteStream(writeStream: Writable): Effect.Effect<void, Error>;
|
|
17
|
+
/**
|
|
18
|
+
* Wait for a readable stream to fully pipe to a write-stream
|
|
19
|
+
*/
|
|
20
|
+
export declare function waitForStreamPipe(readStream: Readable, writeStream: Writable): Effect.Effect<number, Error>;
|
|
21
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/stream/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAGtD,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAIxC;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,QAAQ,GAAG,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,KAAK,CAAC,CAc1G;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,WAAW,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAK9E;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CASpF;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAiB3G"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { toError } from '@konker.dev/tiny-error-fp/lib';
|
|
2
|
+
import * as Effect from 'effect/Effect';
|
|
3
|
+
import { stringToUint8Array } from '../array.js';
|
|
4
|
+
/**
|
|
5
|
+
* Consume a readStream
|
|
6
|
+
* @param readStream
|
|
7
|
+
*/
|
|
8
|
+
export function readStreamToBuffer(readStream) {
|
|
9
|
+
return Effect.tryPromise({
|
|
10
|
+
try: async () => {
|
|
11
|
+
const chunks = [];
|
|
12
|
+
// eslint-disable-next-line fp/no-loops
|
|
13
|
+
for await (const chunk of readStream) {
|
|
14
|
+
chunks.push(typeof chunk === 'string' ? stringToUint8Array(chunk) : new Uint8Array(chunk));
|
|
15
|
+
}
|
|
16
|
+
// Merge chunks
|
|
17
|
+
return chunks.reduce((acc, val) => new Uint8Array([...acc, ...val]), new Uint8Array());
|
|
18
|
+
},
|
|
19
|
+
catch: toError,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Wait for a writable stream to finish
|
|
24
|
+
*/
|
|
25
|
+
export function waitForWriteStreamPromise(writeStream) {
|
|
26
|
+
return new Promise((resolve, reject) => {
|
|
27
|
+
writeStream.on('finish', resolve);
|
|
28
|
+
writeStream.on('error', reject);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Wait for a writable stream to finish
|
|
33
|
+
*/
|
|
34
|
+
export function waitForWriteStream(writeStream) {
|
|
35
|
+
return Effect.tryPromise({
|
|
36
|
+
try: () => new Promise((resolve, reject) => {
|
|
37
|
+
writeStream.on('finish', resolve);
|
|
38
|
+
writeStream.on('error', reject);
|
|
39
|
+
}),
|
|
40
|
+
catch: toError,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Wait for a readable stream to fully pipe to a write-stream
|
|
45
|
+
*/
|
|
46
|
+
export function waitForStreamPipe(readStream, writeStream) {
|
|
47
|
+
return Effect.tryPromise({
|
|
48
|
+
try: () => new Promise((resolve, reject) => {
|
|
49
|
+
// eslint-disable-next-line fp/no-let
|
|
50
|
+
let size = 0;
|
|
51
|
+
readStream.on('data', (data) => {
|
|
52
|
+
size = size + data.length;
|
|
53
|
+
});
|
|
54
|
+
readStream.on('error', reject);
|
|
55
|
+
writeStream.on('finish', () => resolve(size));
|
|
56
|
+
writeStream.on('error', reject);
|
|
57
|
+
readStream.pipe(writeStream);
|
|
58
|
+
readStream.resume();
|
|
59
|
+
}),
|
|
60
|
+
catch: toError,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/stream/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AACxD,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEjD;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAAC,UAAqC;IACtE,OAAO,MAAM,CAAC,UAAU,CAAC;QACvB,GAAG,EAAE,KAAK,IAAI,EAAE;YACd,MAAM,MAAM,GAAsB,EAAE,CAAC;YACrC,uCAAuC;YACvC,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,UAAU,EAAE,CAAC;gBACrC,MAAM,CAAC,IAAI,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;YAC7F,CAAC;YAED,eAAe;YACf,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,IAAI,UAAU,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,GAAG,CAAC,CAAC,EAAE,IAAI,UAAU,EAAE,CAAC,CAAC;QACzF,CAAC;Q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AAC;YAC9C,WAAW,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;YAChC,UAAU,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;YAC7B,UAAU,CAAC,MAAM,EAAE,CAAC;QACtB,CAAC,CAAC;QACJ,KAAK,EAAE,OAAO;KACf,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../src/stream/index.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { PassThrough, Readable } from 'node:stream';
|
|
2
|
+
import * as Effect from 'effect/Effect';
|
|
3
|
+
import { describe, expect, it } from 'vitest';
|
|
4
|
+
import { arrayBufferToString } from '../array.js';
|
|
5
|
+
import { BufferWriteableStream } from './BufferWriteableStream.js';
|
|
6
|
+
import * as unit from './index.js';
|
|
7
|
+
describe('stream utils', () => {
|
|
8
|
+
describe('readStreamToBuffer', () => {
|
|
9
|
+
it('should resolve as expected', async () => {
|
|
10
|
+
const readStream = Readable.from('konker');
|
|
11
|
+
const data = await Effect.runPromise(unit.readStreamToBuffer(readStream));
|
|
12
|
+
expect(arrayBufferToString(data)).toEqual('konker');
|
|
13
|
+
});
|
|
14
|
+
it('should resolve as expected', async () => {
|
|
15
|
+
const readStream = Readable.from(Buffer.from('konker'));
|
|
16
|
+
const data = await Effect.runPromise(unit.readStreamToBuffer(readStream));
|
|
17
|
+
expect(arrayBufferToString(data)).toEqual('konker');
|
|
18
|
+
});
|
|
19
|
+
it('should reject as expected', async () => {
|
|
20
|
+
const readStream = Readable.from('konker');
|
|
21
|
+
readStream.on('data', () => {
|
|
22
|
+
readStream.emit('error', new Error('Boom!'));
|
|
23
|
+
});
|
|
24
|
+
await expect(Effect.runPromise(unit.readStreamToBuffer(readStream))).rejects.toThrow('Boom!');
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
describe('waitForWriteStreamPromise', () => {
|
|
28
|
+
it('should work as expected', async () => {
|
|
29
|
+
const readStream = Readable.from('konker');
|
|
30
|
+
const writeStream = new BufferWriteableStream();
|
|
31
|
+
readStream.pipe(writeStream);
|
|
32
|
+
await unit.waitForWriteStreamPromise(writeStream);
|
|
33
|
+
expect(writeStream.string).toEqual('konker');
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
describe('waitForWriteStream', () => {
|
|
37
|
+
it('should work as expected', async () => {
|
|
38
|
+
const readStream = Readable.from('konker');
|
|
39
|
+
const writeStream = new BufferWriteableStream();
|
|
40
|
+
readStream.pipe(writeStream);
|
|
41
|
+
await Effect.runPromise(unit.waitForWriteStream(writeStream));
|
|
42
|
+
expect(writeStream.string).toEqual('konker');
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
describe('waitForStreamPipe', () => {
|
|
46
|
+
it('should resolve as expected', async () => {
|
|
47
|
+
const readStream = Readable.from('konker');
|
|
48
|
+
const writeStream = new PassThrough();
|
|
49
|
+
const data = await Effect.runPromise(unit.waitForStreamPipe(readStream, writeStream));
|
|
50
|
+
expect(data).toEqual(6);
|
|
51
|
+
});
|
|
52
|
+
it('should reject as expected', async () => {
|
|
53
|
+
const readStream = Readable.from('konker');
|
|
54
|
+
const writeStream = new PassThrough();
|
|
55
|
+
writeStream.on('data', () => {
|
|
56
|
+
writeStream.emit('error', new Error('Boom!'));
|
|
57
|
+
});
|
|
58
|
+
await expect(Effect.runPromise(unit.waitForStreamPipe(readStream, writeStream))).rejects.toThrow('Boom!');
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
//# sourceMappingURL=index.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.test.js","sourceRoot":"","sources":["../../src/stream/index.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEpD,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;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GAAG,EAAE;QACjC,EAAE,CAAC,4BAA4B,EAAE,KAAK,IAAI,EAAE;YAC1C,MAAM,UAAU,GAAG,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC3C,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC;YAEtC,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,iBAAiB,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC,CAAC;YACtF,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QAC1B,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,2BAA2B,EAAE,KAAK,IAAI,EAAE;YACzC,MAAM,UAAU,GAAG,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC3C,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC;YACtC,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE;gBAC1B,WAAW,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;YAChD,CAAC,CAAC,CAAC;YAEH,MAAM,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,iBAAiB,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAC5G,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,77 +1,94 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@konker.dev/tiny-utils-fp",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"author": "Konrad Markus <mail@konker.dev>",
|
|
5
|
-
"description": "General utility functions for Node.js TypeScript projects based on Effect-ts",
|
|
6
6
|
"license": "ISC",
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"dist/**/*",
|
|
10
|
-
"!dist/**/*.test.*"
|
|
11
|
-
],
|
|
12
|
-
"repository": {
|
|
13
|
-
"type": "git",
|
|
14
|
-
"url": "https://github.com/konkerdotdev/tiny-utils-fp"
|
|
15
|
-
},
|
|
7
|
+
"description": "General utility functions for Node.js TypeScript projects based on Effect-ts",
|
|
8
|
+
"homepage": "https://konker.dev/",
|
|
16
9
|
"keywords": [
|
|
17
10
|
"node",
|
|
18
|
-
"
|
|
11
|
+
"utils",
|
|
19
12
|
"typescript",
|
|
20
13
|
"functional-programming",
|
|
21
14
|
"effect-ts"
|
|
22
15
|
],
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/konker.dev/packages/tiny-utils-fp"
|
|
19
|
+
},
|
|
20
|
+
"exports": {
|
|
21
|
+
"./package.json": "./package.json",
|
|
22
|
+
"./stream/BufferWriteableStream": {
|
|
23
|
+
"types": "./dist/stream/BufferWriteableStream.d.ts",
|
|
24
|
+
"import": "./dist/stream/BufferWriteableStream.js"
|
|
25
|
+
},
|
|
26
|
+
"./stream/ChildProcessStreamPipe": {
|
|
27
|
+
"types": "./dist/stream/ChildProcessStreamPipe.d.ts",
|
|
28
|
+
"import": "./dist/stream/ChildProcessStreamPipe.js"
|
|
29
|
+
},
|
|
30
|
+
"./stream": {
|
|
31
|
+
"types": "./dist/stream/index.d.ts",
|
|
32
|
+
"import": "./dist/stream/index.js"
|
|
33
|
+
},
|
|
34
|
+
"./array": {
|
|
35
|
+
"types": "./dist/array.d.ts",
|
|
36
|
+
"import": "./dist/array.js"
|
|
37
|
+
},
|
|
38
|
+
"./hash": {
|
|
39
|
+
"types": "./dist/hash.d.ts",
|
|
40
|
+
"import": "./dist/hash.js"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"files": [
|
|
44
|
+
"dist/**/*",
|
|
45
|
+
"!dist/**/*.test.*"
|
|
46
|
+
],
|
|
47
|
+
"main": "dist/index.js",
|
|
23
48
|
"dependencies": {
|
|
24
|
-
"
|
|
25
|
-
"@konker.dev/
|
|
26
|
-
"@konker.dev/tiny-error-fp": "^0.0.7",
|
|
27
|
-
"effect": "^3.5.3"
|
|
49
|
+
"effect": "^3.11.2",
|
|
50
|
+
"@konker.dev/tiny-error-fp": "0.1.0"
|
|
28
51
|
},
|
|
29
52
|
"devDependencies": {
|
|
53
|
+
"@arethetypeswrong/cli": "^0.17.1",
|
|
30
54
|
"@effect/language-service": "^0.1.0",
|
|
31
|
-
"@
|
|
32
|
-
"@
|
|
33
|
-
"@
|
|
34
|
-
"@
|
|
35
|
-
"@
|
|
36
|
-
"eslint": "^
|
|
37
|
-
"eslint-config-prettier": "^9.1.0",
|
|
38
|
-
"eslint-import-resolver-typescript": "^3.6.1",
|
|
39
|
-
"eslint-plugin-deprecation": "^2.0.0",
|
|
55
|
+
"@eslint/compat": "^1.2.4",
|
|
56
|
+
"@eslint/js": "^9.17.0",
|
|
57
|
+
"@konker.dev/common-config": "^0.1.0",
|
|
58
|
+
"@types/node": "^20.17.10",
|
|
59
|
+
"@vitest/coverage-istanbul": "^2.1.8",
|
|
60
|
+
"eslint": "^9.17.0",
|
|
40
61
|
"eslint-plugin-fp": "^2.3.0",
|
|
41
|
-
"eslint-plugin-
|
|
42
|
-
"eslint-plugin-json": "^3.1.0",
|
|
43
|
-
"eslint-plugin-prettier": "^5.1.3",
|
|
62
|
+
"eslint-plugin-prettier": "^5.2.1",
|
|
44
63
|
"eslint-plugin-simple-import-sort": "^12.1.1",
|
|
45
64
|
"eslint-plugin-sort-destructure-keys": "^1.6.0",
|
|
46
|
-
"gulp": "^4.0.2",
|
|
47
|
-
"husky": "^9.0.11",
|
|
48
|
-
"jest": "^29.7.0",
|
|
49
65
|
"leasot": "^13.3.0",
|
|
50
66
|
"madge": "^6.1.0",
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
67
|
+
"prettier": "^3.4.2",
|
|
68
|
+
"tsx": "^4.19.2",
|
|
69
|
+
"type-coverage": "^2.29.7",
|
|
70
|
+
"typescript": "^5.7.2",
|
|
71
|
+
"typescript-eslint": "^8.18.0",
|
|
72
|
+
"vitest": "^2.1.8"
|
|
57
73
|
},
|
|
58
|
-
"staticFiles": [],
|
|
59
74
|
"scripts": {
|
|
60
|
-
"test": "
|
|
75
|
+
"test": "vitest run --coverage",
|
|
61
76
|
"clean": "rm -rf dist && rm -f tsconfig.tsbuildinfo",
|
|
62
77
|
"typecheck": "tsc --noEmit",
|
|
63
|
-
"build": "pnpm run clean && tsc
|
|
64
|
-
"type-coverage-check": "type-coverage --detail --at-least 100",
|
|
65
|
-
"circular-check": "madge --extensions ts --circular --no-color --no-spinner --warning
|
|
78
|
+
"build": "pnpm run clean && tsc",
|
|
79
|
+
"type-coverage-check": "type-coverage --detail --at-least 100 --ignore-files src/index.test.ts --ignore-files src/stream/index.ts",
|
|
80
|
+
"circular-check": "madge --extensions ts --circular --no-color --no-spinner --warning src",
|
|
66
81
|
"eslint-check": "eslint --max-warnings=0 '**/*.{ts,js,json}'",
|
|
67
|
-
"fixme-check": "leasot --exit-nicely --skip-unsupported --ignore node_modules src",
|
|
68
82
|
"eslint-fix": "npx eslint --fix||true",
|
|
83
|
+
"generated-exports-check": "npx --package=@konker.dev/common-config generate-exports-verify packages/tiny-utils-fp",
|
|
84
|
+
"exports-check": "attw --pack . --ignore-rules=cjs-resolves-to-esm --profile=node16",
|
|
85
|
+
"fixme-check": "leasot --exit-nicely --skip-unsupported src",
|
|
69
86
|
"prettier-check": "npx prettier --check --ignore-path .gitignore --ignore-path .prettierignore '**/*.{css,html,js,ts,json,md,yaml,yml}'",
|
|
70
87
|
"prettier-fix": "pnpm run prettier-check --write",
|
|
71
88
|
"lint-check": "pnpm run eslint-check && pnpm run prettier-check && pnpm run circular-check && pnpm run fixme-check",
|
|
72
89
|
"lint-fix": "pnpm run eslint-fix && pnpm run prettier-fix",
|
|
73
90
|
"pre-push": "pnpm run lint-check && pnpm run typecheck",
|
|
74
|
-
"ci": "pnpm run lint-check && pnpm run typecheck && pnpm run type-coverage-check && pnpm run test && pnpm run build && pnpm run fixme-check",
|
|
75
|
-
"cd": "pnpm run build && pnpm publish --access public"
|
|
91
|
+
"ci": "pnpm run lint-check && pnpm run typecheck && pnpm run type-coverage-check && pnpm run test && pnpm run build && pnpm run generated-exports-check && pnpm run exports-check && pnpm run fixme-check",
|
|
92
|
+
"cd": "pnpm run build && pnpm publish --access public --force"
|
|
76
93
|
}
|
|
77
94
|
}
|
package/dist/index.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import * as P from '@konker.dev/effect-ts-prelude';
|
|
2
|
-
export declare const md5Hex: (s: string) => P.Effect.Effect<string, Error>;
|
|
3
|
-
export declare const sha256Hex: (s: string) => P.Effect.Effect<string, Error>;
|
|
4
|
-
export declare const sha256HmacHex: (s: string, secret: string) => P.Effect.Effect<string, Error>;
|
package/dist/index.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.sha256HmacHex = exports.sha256Hex = exports.md5Hex = void 0;
|
|
30
|
-
const P = __importStar(require("@konker.dev/effect-ts-prelude"));
|
|
31
|
-
const lib_1 = require("@konker.dev/tiny-error-fp/dist/lib");
|
|
32
|
-
const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
33
|
-
const md5Hex = (s) => P.Effect.try({
|
|
34
|
-
try: () => node_crypto_1.default.createHash('md5').update(s).digest('hex'),
|
|
35
|
-
catch: lib_1.toError,
|
|
36
|
-
});
|
|
37
|
-
exports.md5Hex = md5Hex;
|
|
38
|
-
const sha256Hex = (s) => P.Effect.try({
|
|
39
|
-
try: () => node_crypto_1.default.createHash('sha256').update(s).digest('hex'),
|
|
40
|
-
catch: lib_1.toError,
|
|
41
|
-
});
|
|
42
|
-
exports.sha256Hex = sha256Hex;
|
|
43
|
-
const sha256HmacHex = (s, secret) => P.Effect.try({
|
|
44
|
-
try: () => node_crypto_1.default.createHmac('sha256', secret).update(s).digest('hex'),
|
|
45
|
-
catch: lib_1.toError,
|
|
46
|
-
});
|
|
47
|
-
exports.sha256HmacHex = sha256HmacHex;
|
|
48
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iEAAmD;AAEnD,4DAA6D;AAC7D,8DAAiC;AAE1B,MAAM,MAAM,GAAG,CAAC,CAAS,EAAkC,EAAE,CAClE,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC;IACX,GAAG,EAAE,GAAG,EAAE,CAAC,qBAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;IAC3D,KAAK,EAAE,aAAO;CACf,CAAC,CAAC;AAJQ,QAAA,MAAM,UAId;AAEE,MAAM,SAAS,GAAG,CAAC,CAAS,EAAkC,EAAE,CACrE,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC;IACX,GAAG,EAAE,GAAG,EAAE,CAAC,qBAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;IAC9D,KAAK,EAAE,aAAO;CACf,CAAC,CAAC;AAJQ,QAAA,SAAS,aAIjB;AAEE,MAAM,aAAa,GAAG,CAAC,CAAS,EAAE,MAAc,EAAkC,EAAE,CACzF,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC;IACX,GAAG,EAAE,GAAG,EAAE,CAAC,qBAAM,CAAC,UAAU,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;IACtE,KAAK,EAAE,aAAO;CACf,CAAC,CAAC;AAJQ,QAAA,aAAa,iBAIrB"}
|