@konker.dev/neverthrow-r-utils 0.0.1
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/LICENSE +15 -0
- package/README.md +3 -0
- 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 +8 -0
- package/dist/hash.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.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/PromiseDependentWritableStream.d.ts +10 -0
- package/dist/stream/PromiseDependentWritableStream.d.ts.map +1 -0
- package/dist/stream/PromiseDependentWritableStream.js +10 -0
- package/dist/stream/PromiseDependentWritableStream.js.map +1 -0
- package/dist/stream/PromiseDependentWritableStream.test.d.ts +2 -0
- package/dist/stream/PromiseDependentWritableStream.test.d.ts.map +1 -0
- package/dist/stream/PromiseDependentWritableStream.test.js +15 -0
- package/dist/stream/PromiseDependentWritableStream.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 +51 -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 +67 -0
- package/dist/stream/index.test.js.map +1 -0
- package/package.json +111 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Konrad Markus <mail@konker.dev>
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
10
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
11
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
|
12
|
+
SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
13
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
|
14
|
+
OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
|
15
|
+
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
ADDED
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,CAAC,eAAe,GAAG,MAAM,CAEnF"}
|
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,CAAuC;IACzE,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 { type ResultR } from '@konker.dev/neverthrow-r';
|
|
2
|
+
export declare const md5Hex: (s: string) => ResultR<unknown, string, Error>;
|
|
3
|
+
export declare const sha256Hex: (s: string) => ResultR<unknown, string, Error>;
|
|
4
|
+
export declare const sha256HmacHex: (s: string, secret: string) => ResultR<unknown, 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":"AAEA,OAAO,EAAc,KAAK,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAIpE,eAAO,MAAM,MAAM,GAAI,GAAG,MAAM,KAAG,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CACoC,CAAC;AAEtG,eAAO,MAAM,SAAS,GAAI,GAAG,MAAM,KAAG,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CACoC,CAAC;AAEzG,eAAO,MAAM,aAAa,GAAI,GAAG,MAAM,EAAE,QAAQ,MAAM,KAAG,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CACwB,CAAC"}
|
package/dist/hash.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import { fromResult } from '@konker.dev/neverthrow-r';
|
|
3
|
+
import { toError } from '@konker.dev/tiny-error-fp/lib';
|
|
4
|
+
import { Result } from 'neverthrow';
|
|
5
|
+
export const md5Hex = (s) => fromResult(Result.fromThrowable(() => crypto.createHash('md5').update(s).digest('hex'), toError)());
|
|
6
|
+
export const sha256Hex = (s) => fromResult(Result.fromThrowable(() => crypto.createHash('sha256').update(s).digest('hex'), toError)());
|
|
7
|
+
export const sha256HmacHex = (s, secret) => fromResult(Result.fromThrowable(() => crypto.createHmac('sha256', secret).update(s).digest('hex'), toError)());
|
|
8
|
+
//# 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,UAAU,EAAgB,MAAM,0BAA0B,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEpC,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,CAAS,EAAmC,EAAE,CACnE,UAAU,CAAC,MAAM,CAAC,aAAa,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;AAEtG,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAS,EAAmC,EAAE,CACtE,UAAU,CAAC,MAAM,CAAC,aAAa,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;AAEzG,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAS,EAAE,MAAc,EAAmC,EAAE,CAC1F,UAAU,CAAC,MAAM,CAAC,aAAa,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from './array.js';
|
|
2
|
+
export * from './hash.js';
|
|
3
|
+
export * from './stream/index.js';
|
|
4
|
+
export * from './stream/BufferWriteableStream.js';
|
|
5
|
+
export * from './stream/ChildProcessStreamPipe.js';
|
|
6
|
+
export * from './stream/PromiseDependentWritableStream.js';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,mBAAmB,CAAC;AAElC,cAAc,mCAAmC,CAAC;AAClD,cAAc,oCAAoC,CAAC;AACnD,cAAc,4CAA4C,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from './array.js';
|
|
2
|
+
export * from './hash.js';
|
|
3
|
+
export * from './stream/index.js';
|
|
4
|
+
export * from './stream/BufferWriteableStream.js';
|
|
5
|
+
export * from './stream/ChildProcessStreamPipe.js';
|
|
6
|
+
export * from './stream/PromiseDependentWritableStream.js';
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,mBAAmB,CAAC;AAElC,cAAc,mCAAmC,CAAC;AAClD,cAAc,oCAAoC,CAAC;AACnD,cAAc,4CAA4C,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,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ot":"","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(async () => {
|
|
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(async () => {
|
|
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,CAAC,CAAC;QAEnC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,aAAa,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;IAC7D,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6CAA6C,EAAE,KAAK,IAAI,EAAE;QAC3D,MAAM,MAAM,GAAG,IAAI,IAAI,CAAC,sBAAsB,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,oBAAoB,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAA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,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,KAAK,IAAI,EAAE;YAChB,OAAO,yBAAyB,CAAC,SAAS,CAAC,CAAC;QAC9C,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;IACnB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Writable } from 'node:stream';
|
|
2
|
+
import { PassThrough } from 'node:stream';
|
|
3
|
+
/**
|
|
4
|
+
* A Writable stream which can have an external promise injected into it.
|
|
5
|
+
* The purpose of this is so that the stream can be kept alive until the promise resolves.
|
|
6
|
+
*/
|
|
7
|
+
export declare class PromiseDependentWritableStream extends PassThrough implements Writable {
|
|
8
|
+
promise: Promise<unknown> | undefined;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=PromiseDependentWritableStream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PromiseDependentWritableStream.d.ts","sourceRoot":"","sources":["../../src/stream/PromiseDependentWritableStream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C;;;GAGG;AAEH,qBAAa,8BAA+B,SAAQ,WAAY,YAAW,QAAQ;IACjF,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC;CACvC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { PassThrough } from 'node:stream';
|
|
2
|
+
/**
|
|
3
|
+
* A Writable stream which can have an external promise injected into it.
|
|
4
|
+
* The purpose of this is so that the stream can be kept alive until the promise resolves.
|
|
5
|
+
*/
|
|
6
|
+
// eslint-disable-next-line fp/no-class
|
|
7
|
+
export class PromiseDependentWritableStream extends PassThrough {
|
|
8
|
+
promise;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=PromiseDependentWritableStream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PromiseDependentWritableStream.js","sourceRoot":"","sources":["../../src/stream/PromiseDependentWritableStream.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C;;;GAGG;AACH,uCAAuC;AACvC,MAAM,OAAO,8BAA+B,SAAQ,WAAW;IAC7D,OAAO,CAA+B;CACvC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PromiseDependentWritableStream.test.d.ts","sourceRoot":"","sources":["../../src/stream/PromiseDependentWritableStream.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Writable } from 'stream';
|
|
2
|
+
import { describe, expect, it } from 'vitest';
|
|
3
|
+
import { PromiseDependentWritableStream } from './PromiseDependentWritableStream.js';
|
|
4
|
+
describe('PromiseDependentWritableStream', () => {
|
|
5
|
+
it('should be a Writable stream', () => {
|
|
6
|
+
expect(new PromiseDependentWritableStream()).toBeInstanceOf(Writable);
|
|
7
|
+
});
|
|
8
|
+
it('should store the promise', () => {
|
|
9
|
+
const promiseDependentWritableStream = new PromiseDependentWritableStream();
|
|
10
|
+
const p = Promise.resolve('test');
|
|
11
|
+
promiseDependentWritableStream.promise = p;
|
|
12
|
+
expect(promiseDependentWritableStream.promise).toBe(p);
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
//# sourceMappingURL=PromiseDependentWritableStream.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PromiseDependentWritableStream.test.js","sourceRoot":"","sources":["../../src/stream/PromiseDependentWritableStream.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAE9C,OAAO,EAAE,8BAA8B,EAAE,MAAM,qCAAqC,CAAC;AAErF,QAAQ,CAAC,gCAAgC,EAAE,GAAG,EAAE;IAC9C,EAAE,CAAC,6BAA6B,EAAE,GAAG,EAAE;QACrC,MAAM,CAAC,IAAI,8BAA8B,EAAE,CAAC,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;IACxE,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,0BAA0B,EAAE,GAAG,EAAE;QAClC,MAAM,8BAA8B,GAAG,IAAI,8BAA8B,EAAE,CAAC;QAC5E,MAAM,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAElC,8BAA8B,CAAC,OAAO,GAAG,CAAC,CAAC;QAC3C,MAAM,CAAC,8BAA8B,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACzD,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 { type ResultAsyncR } from '@konker.dev/neverthrow-r';
|
|
4
|
+
/**
|
|
5
|
+
* Consume a readStream
|
|
6
|
+
* @param readStream
|
|
7
|
+
*/
|
|
8
|
+
export declare function readStreamToBuffer(readStream: Readable | ReadableStream): ResultAsyncR<unknown, 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): ResultAsyncR<unknown, 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): ResultAsyncR<unknown, 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;AAEtD,OAAO,EAAmB,KAAK,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAM9E;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,QAAQ,GAAG,cAAc,GAAG,YAAY,CAAC,OAAO,EAAE,UAAU,EAAE,KAAK,CAAC,CAelH;AAED;;GAEG;AACH,wBAAsB,yBAAyB,CAAC,WAAW,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAKpF;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,QAAQ,GAAG,YAAY,CAAC,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,CAE5F;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,GAAG,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,CAkBnH"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { fromResultAsync } from '@konker.dev/neverthrow-r';
|
|
2
|
+
import { toError } from '@konker.dev/tiny-error-fp/lib';
|
|
3
|
+
import { ResultAsync } from 'neverthrow';
|
|
4
|
+
import { stringToUint8Array } from '../array.js';
|
|
5
|
+
/**
|
|
6
|
+
* Consume a readStream
|
|
7
|
+
* @param readStream
|
|
8
|
+
*/
|
|
9
|
+
export function readStreamToBuffer(readStream) {
|
|
10
|
+
return fromResultAsync(ResultAsync.fromPromise((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
|
+
return chunks.reduce((acc, val) => new Uint8Array([...acc, ...val]), new Uint8Array());
|
|
17
|
+
})(), toError));
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Wait for a writable stream to finish
|
|
21
|
+
*/
|
|
22
|
+
export async function waitForWriteStreamPromise(writeStream) {
|
|
23
|
+
return new Promise((resolve, reject) => {
|
|
24
|
+
writeStream.on('finish', resolve);
|
|
25
|
+
writeStream.on('error', reject);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Wait for a writable stream to finish
|
|
30
|
+
*/
|
|
31
|
+
export function waitForWriteStream(writeStream) {
|
|
32
|
+
return fromResultAsync(ResultAsync.fromPromise(waitForWriteStreamPromise(writeStream), toError));
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Wait for a readable stream to fully pipe to a write-stream
|
|
36
|
+
*/
|
|
37
|
+
export function waitForStreamPipe(readStream, writeStream) {
|
|
38
|
+
return fromResultAsync(ResultAsync.fromPromise(new Promise((resolve, reject) => {
|
|
39
|
+
// eslint-disable-next-line fp/no-let
|
|
40
|
+
let size = 0;
|
|
41
|
+
readStream.on('data', (data) => {
|
|
42
|
+
size = size + data.length;
|
|
43
|
+
});
|
|
44
|
+
readStream.on('error', reject);
|
|
45
|
+
writeStream.on('finish', () => resolve(size));
|
|
46
|
+
writeStream.on('error', reject);
|
|
47
|
+
readStream.pipe(writeStream);
|
|
48
|
+
readStream.resume();
|
|
49
|
+
}), toError));
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/stream/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAAqB,MAAM,0BAA0B,CAAC;AAC9E,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEjD;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAAC,UAAqC;IACtE,OAAO,eAAe,CACpB,WAAW,CAAC,WAAW,CACrB,CAAC,KAAK,IAAI,EAAE;QACV,MAAM,MAAM,GAAsB,EAAE,CAAC;QACrC,uCAAuC;QACvC,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,UAAU,EAAE,CAAC;YACrC,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;QAC7F,CAAC;QAED,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;IACzF,CAAC,CAAC,EAAE,EACJ,OAAO,CACR,CACF,CAAC;AACJ,CAAC;AAED;;GAEG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ot":"","sources":["../../src/stream/index.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { PassThrough, Readable } from 'node:stream';
|
|
2
|
+
import { describe, expect, it } from 'vitest';
|
|
3
|
+
import { arrayBufferToString } from '../array.js';
|
|
4
|
+
import { BufferWriteableStream } from './BufferWriteableStream.js';
|
|
5
|
+
import * as unit from './index.js';
|
|
6
|
+
describe('stream utils', () => {
|
|
7
|
+
describe('readStreamToBuffer', () => {
|
|
8
|
+
it('should resolve as expected', async () => {
|
|
9
|
+
const readStream = Readable.from('konker');
|
|
10
|
+
const data = await unit.readStreamToBuffer(readStream)(undefined);
|
|
11
|
+
expect(data._unsafeUnwrap()).toEqual(new Uint8Array(Buffer.from('konker')));
|
|
12
|
+
expect(arrayBufferToString(data._unsafeUnwrap())).toEqual('konker');
|
|
13
|
+
});
|
|
14
|
+
it('should resolve as expected', async () => {
|
|
15
|
+
const readStream = Readable.from(Buffer.from('konker'));
|
|
16
|
+
const data = await unit.readStreamToBuffer(readStream)(undefined);
|
|
17
|
+
expect(arrayBufferToString(data._unsafeUnwrap())).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
|
+
const data = await unit.readStreamToBuffer(readStream)(undefined);
|
|
25
|
+
expect(data._unsafeUnwrapErr()).toBeInstanceOf(Error);
|
|
26
|
+
expect(data._unsafeUnwrapErr().message).toEqual('Boom!');
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
describe('waitForWriteStreamPromise', () => {
|
|
30
|
+
it('should work as expected', async () => {
|
|
31
|
+
const readStream = Readable.from('konker');
|
|
32
|
+
const writeStream = new BufferWriteableStream();
|
|
33
|
+
readStream.pipe(writeStream);
|
|
34
|
+
await unit.waitForWriteStreamPromise(writeStream);
|
|
35
|
+
expect(writeStream.string).toEqual('konker');
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
describe('waitForWriteStream', () => {
|
|
39
|
+
it('should work as expected', async () => {
|
|
40
|
+
const readStream = Readable.from('konker');
|
|
41
|
+
const writeStream = new BufferWriteableStream();
|
|
42
|
+
readStream.pipe(writeStream);
|
|
43
|
+
const result = await unit.waitForWriteStream(writeStream)(undefined);
|
|
44
|
+
expect(result._unsafeUnwrap()).toBeUndefined();
|
|
45
|
+
expect(writeStream.string).toEqual('konker');
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
describe('waitForStreamPipe', () => {
|
|
49
|
+
it('should resolve as expected', async () => {
|
|
50
|
+
const readStream = Readable.from('konker');
|
|
51
|
+
const writeStream = new PassThrough();
|
|
52
|
+
const data = await unit.waitForStreamPipe(readStream, writeStream)(undefined);
|
|
53
|
+
expect(data._unsafeUnwrap()).toEqual(6);
|
|
54
|
+
});
|
|
55
|
+
it('should reject as expected', async () => {
|
|
56
|
+
const readStream = Readable.from('konker');
|
|
57
|
+
const writeStream = new PassThrough();
|
|
58
|
+
writeStream.on('data', () => {
|
|
59
|
+
writeStream.emit('error', new Error('Boom!'));
|
|
60
|
+
});
|
|
61
|
+
const data = await unit.waitForStreamPipe(readStream, writeStream)(undefined);
|
|
62
|
+
expect(data._unsafeUnwrapErr()).toBeInstanceOf(Error);
|
|
63
|
+
expect(data._unsafeUnwrapErr().message).toEqual('Boom!');
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
//# 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,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAE9C,OAAO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AgB,EAAE,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAC3D,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@konker.dev/neverthrow-r-utils",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"author": "Konrad Markus <mail@konker.dev>",
|
|
6
|
+
"license": "ISC",
|
|
7
|
+
"description": "Utils for neverthrow and @konker.dev/neverthrow-r.",
|
|
8
|
+
"homepage": "https://konker.dev/",
|
|
9
|
+
"keywords": [
|
|
10
|
+
"node",
|
|
11
|
+
"neverthrow",
|
|
12
|
+
"neverthrow-r",
|
|
13
|
+
"typescript",
|
|
14
|
+
"functional-programming"
|
|
15
|
+
],
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/konker/konker.dev/packages/neverthrow-r-utils"
|
|
19
|
+
},
|
|
20
|
+
"exports": {
|
|
21
|
+
"./package.json": "./package.json",
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"import": "./dist/index.js"
|
|
25
|
+
},
|
|
26
|
+
"./stream/BufferWriteableStream": {
|
|
27
|
+
"types": "./dist/stream/BufferWriteableStream.d.ts",
|
|
28
|
+
"import": "./dist/stream/BufferWriteableStream.js"
|
|
29
|
+
},
|
|
30
|
+
"./stream/ChildProcessStreamPipe": {
|
|
31
|
+
"types": "./dist/stream/ChildProcessStreamPipe.d.ts",
|
|
32
|
+
"import": "./dist/stream/ChildProcessStreamPipe.js"
|
|
33
|
+
},
|
|
34
|
+
"./stream": {
|
|
35
|
+
"types": "./dist/stream/index.d.ts",
|
|
36
|
+
"import": "./dist/stream/index.js"
|
|
37
|
+
},
|
|
38
|
+
"./stream/PromiseDependentWritableStream": {
|
|
39
|
+
"types": "./dist/stream/PromiseDependentWritableStream.d.ts",
|
|
40
|
+
"import": "./dist/stream/PromiseDependentWritableStream.js"
|
|
41
|
+
},
|
|
42
|
+
"./array": {
|
|
43
|
+
"types": "./dist/array.d.ts",
|
|
44
|
+
"import": "./dist/array.js"
|
|
45
|
+
},
|
|
46
|
+
"./hash": {
|
|
47
|
+
"types": "./dist/hash.d.ts",
|
|
48
|
+
"import": "./dist/hash.js"
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"files": [
|
|
52
|
+
"dist/**/*",
|
|
53
|
+
"!dist/**/*.test.*"
|
|
54
|
+
],
|
|
55
|
+
"main": "dist/index.js",
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@arethetypeswrong/cli": "^0.18.2",
|
|
58
|
+
"@effect/language-service": "^0.86.1",
|
|
59
|
+
"@eslint/compat": "^2.0.1",
|
|
60
|
+
"@eslint/js": "^9.39.2",
|
|
61
|
+
"@konker.dev/common-config": "^0.8.0",
|
|
62
|
+
"@types/node": "^25.8.0",
|
|
63
|
+
"@vitest/coverage-istanbul": "^4.1.6",
|
|
64
|
+
"aws-sdk-client-mock": "^4.1.0",
|
|
65
|
+
"aws-sdk-client-mock-vitest": "^7.0.1",
|
|
66
|
+
"eslint": "^9.39.2",
|
|
67
|
+
"eslint-plugin-fp": "^2.3.0",
|
|
68
|
+
"eslint-plugin-prettier": "^5.5.5",
|
|
69
|
+
"eslint-plugin-simple-import-sort": "^12.1.1",
|
|
70
|
+
"eslint-plugin-sort-destructure-keys": "^2.0.0",
|
|
71
|
+
"leasot": "^14.4.0",
|
|
72
|
+
"madge": "^8.0.0",
|
|
73
|
+
"prettier": "^3.8.3",
|
|
74
|
+
"tsx": "^4.22.1",
|
|
75
|
+
"type-coverage": "^2.29.7",
|
|
76
|
+
"typedoc": "^0.28.15",
|
|
77
|
+
"typedoc-plugin-markdown": "^4.4.0",
|
|
78
|
+
"typescript": "^5.9.3",
|
|
79
|
+
"typescript-eslint": "^8.52.0",
|
|
80
|
+
"vitest": "^4.1.6",
|
|
81
|
+
"zod": "^3.23.0"
|
|
82
|
+
},
|
|
83
|
+
"dependencies": {
|
|
84
|
+
"neverthrow": "^8.2.0",
|
|
85
|
+
"@konker.dev/neverthrow-r": "0.0.1",
|
|
86
|
+
"@konker.dev/tiny-error-fp": "0.1.12"
|
|
87
|
+
},
|
|
88
|
+
"scripts": {
|
|
89
|
+
"test": "vitest run --coverage",
|
|
90
|
+
"clean": "rm -rf dist && rm -f tsconfig.tsbuildinfo",
|
|
91
|
+
"typecheck": "tsc --noEmit",
|
|
92
|
+
"build": "pnpm run clean && tsc",
|
|
93
|
+
"type-coverage-check": "type-coverage --detail --at-least 97",
|
|
94
|
+
"circular-check": "madge --extensions ts --circular --no-color --no-spinner --warning src",
|
|
95
|
+
"eslint-check": "eslint --max-warnings=0 '**/*.{ts,js,json}'",
|
|
96
|
+
"eslint-fix": "npx eslint --fix||true",
|
|
97
|
+
"generated-exports-check": "npx --package=@konker.dev/common-config generate-exports-verify `pwd`",
|
|
98
|
+
"docs-generate": "typedoc",
|
|
99
|
+
"generated-docs-check": "pnpm run docs-generate && git diff --exit-code docs/reference",
|
|
100
|
+
"exports-check": "NPM_CONFIG_CACHE=.npm-cache attw --pack . --ignore-rules=cjs-resolves-to-esm --profile=esm-only",
|
|
101
|
+
"fixme-check": "leasot --exit-nicely --skip-unsupported src",
|
|
102
|
+
"prettier-check": "npx prettier --check --ignore-path .gitignore --ignore-path .prettierignore '**/*.{css,html,js,ts,json,md,yaml,yml}'",
|
|
103
|
+
"prettier-fix": "pnpm run prettier-check --write",
|
|
104
|
+
"lint-check": "pnpm run eslint-check && pnpm run prettier-check && pnpm run circular-check && pnpm run fixme-check",
|
|
105
|
+
"lint-fix": "pnpm run eslint-fix && pnpm run prettier-fix",
|
|
106
|
+
"pre-push": "pnpm run lint-check && pnpm run typecheck",
|
|
107
|
+
"codecov": "npx --package=@konker.dev/common-config codecov-upload `pwd` '@konker.dev/neverthrow-r-utils'",
|
|
108
|
+
"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 generated-docs-check && pnpm run exports-check && pnpm run fixme-check",
|
|
109
|
+
"cd": "pnpm run build && npx --package=@konker.dev/common-config npm-publish-if-version-not-exists `pwd`"
|
|
110
|
+
}
|
|
111
|
+
}
|