diff --git a/.gitignore b/.gitignore index 3c3629e..001219f 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ node_modules + +# To make npm ignore it +.jj diff --git a/README.md b/README.md new file mode 100644 index 0000000..527142e --- /dev/null +++ b/README.md @@ -0,0 +1,84 @@ +# @promistream/debug + +A stream for debugging pipelines. Logs everything that goes through it, via `console.debug`, and leaves it otherwise untouched. + +Stream characteristics: +- __Promistream version:__ 0 +- __Source stream:__ No +- __Transform stream:__ Yes +- __Sink stream:__ No +- __Buffering:__ None + +Possible errors thrown: +- None (other than those being passed through from upstream). + +## Example + +This example is also included in the package in runnable form as `example.js`. + +```js +"use strict"; + +const pipe = require("@promistream/pipe"); +const fromIterable = require("@promistream/from-iterable"); +const collect = require("@promistream/collect"); +const debug = require("@promistream/debug"); + +(async function () { + let result = await pipe([ + fromIterable([ 1, 2, 3, 4, 5 ]), + debug("example pipeline"), + collect() + ]).read(); + + console.log(result); +})(); +``` + +Example output (see the included screenshot.png for a colorized version): + +``` +[@promistream/debug][example pipeline] read was requested +[@promistream/debug][example pipeline] seen value: 1 +[@promistream/debug][example pipeline] read was requested +[@promistream/debug][example pipeline] seen value: 2 +[@promistream/debug][example pipeline] read was requested +[@promistream/debug][example pipeline] seen value: 3 +[@promistream/debug][example pipeline] read was requested +[@promistream/debug][example pipeline] seen value: 4 +[@promistream/debug][example pipeline] read was requested +[@promistream/debug][example pipeline] seen value: 5 +[@promistream/debug][example pipeline] read was requested +[@promistream/debug][example pipeline] error thrown in read: EndOfStream: End of iterable reached + at /home/sven/projects/promistreams/streams/debug/node_modules/.pnpm/@promistream+from-iterable@0.1.0/node_modules/@promistream/from-iterable/index.js:26:10 + at /home/sven/projects/promistreams/streams/debug/node_modules/.pnpm/@promistream+simple-source@0.1.4/node_modules/@promistream/simple-source/index.js:30:11 + at tryCatcher (/home/sven/projects/promistreams/streams/debug/node_modules/.pnpm/bluebird@3.7.2/node_modules/bluebird/js/release/util.js:16:23) + at Promise.attempt.Promise.try (/home/sven/projects/promistreams/streams/debug/node_modules/.pnpm/bluebird@3.7.2/node_modules/bluebird/js/release/method.js:39:29) + at getValue (/home/sven/projects/promistreams/streams/debug/node_modules/.pnpm/@promistream+simple-source@0.1.4/node_modules/@promistream/simple-source/index.js:29:21) + at /home/sven/projects/promistreams/streams/debug/node_modules/.pnpm/@promistream+simple-source@0.1.4/node_modules/@promistream/simple-source/index.js:83:14 + at tryCatcher (/home/sven/projects/promistreams/streams/debug/node_modules/.pnpm/bluebird@3.7.2/node_modules/bluebird/js/release/util.js:16:23) + at Promise.attempt.Promise.try (/home/sven/projects/promistreams/streams/debug/node_modules/.pnpm/bluebird@3.7.2/node_modules/bluebird/js/release/method.js:39:29) + at Object.produceValue_simpleSource [as read] (/home/sven/projects/promistreams/streams/debug/node_modules/.pnpm/@promistream+simple-source@0.1.4/node_modules/@promistream/simple-source/index.js:61:22) + at produceValue_debug (/home/sven/projects/promistreams/streams/debug/index.js:27:30) + at /home/sven/projects/promistreams/streams/debug/node_modules/.pnpm/@promistream+simple-sink@0.1.1/node_modules/@promistream/simple-sink/index.js:45:20 + at tryCatcher (/home/sven/projects/promistreams/streams/debug/node_modules/.pnpm/bluebird@3.7.2/node_modules/bluebird/js/release/util.js:16:23) + at Promise.attempt.Promise.try (/home/sven/projects/promistreams/streams/debug/node_modules/.pnpm/bluebird@3.7.2/node_modules/bluebird/js/release/method.js:39:29) + at attemptRead (/home/sven/projects/promistreams/streams/debug/node_modules/.pnpm/@promistream+simple-sink@0.1.1/node_modules/@promistream/simple-sink/index.js:44:23) + at /home/sven/projects/promistreams/streams/debug/node_modules/.pnpm/@promistream+simple-sink@0.1.1/node_modules/@promistream/simple-sink/index.js:52:13 + at tryCatcher (/home/sven/projects/promistreams/streams/debug/node_modules/.pnpm/bluebird@3.7.2/node_modules/bluebird/js/release/util.js:16:23) { + _help: 'https://www.npmjs.com/package/error-chain', + _promistreamIsEndOfStreamMarker: true, + _promistreamVersion: 1 +} +[ 1, 2, 3, 4, 5 ] +``` + +## API + +### debug(label) + +Creates a new debug stream. + +- __label:__ *Optional.* The label to prefix the debug output with. Useful for distinguishing different pipelines, when multiple of them have a debug stream inserted at the same time. + +__Returns:__ the new debug stream. diff --git a/package.json b/package.json index c27777a..093d2fd 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,12 @@ "url": "https://git.cryto.net/promistream/debug.git" }, "main": "index.js", + "files": [ + "index.js", + "example.js", + "README.md", + "screenshot.png" + ], "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, diff --git a/screenshot.png b/screenshot.png new file mode 100644 index 0000000..11fd3a5 Binary files /dev/null and b/screenshot.png differ