Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the ability to build a transport using a transform #25

Merged
merged 7 commits into from
Oct 2, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ Create a [`split2`](http://npm.im/split2) instance and returns it.
This same instance is also passed to the given function, which is called
synchronously.

If `fn` returns a [`Readable`](https://nodejs.org/api/stream.html#stream_class_stream_readable), we will
wrap that readable and the split2 instance using [`duplexify`](https://www.npmjs.com/package/duplexify),
If `opts.transform` is `true`, `pino-abstract-transform` will
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

opts.enablePipelining?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
If `opts.transform` is `true`, `pino-abstract-transform` will
If `opts.enablePipelining` is `true`, `pino-abstract-transform` will

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
If `opts.transform` is `true`, `pino-abstract-transform` will
If `opts.enablePipelining` is `true`, `pino-abstract-transform` will

wrap the split2 instance and the returned stream using [`duplexify`](https://www.npmjs.com/package/duplexify),
so they can be concatenated into multiple transports.

#### Events emitted
Expand Down Expand Up @@ -119,7 +119,7 @@ function buildTransform () {
cb(null, JSON.stringify(line))
}
})
})
}, { transform: true })
}

function buildDestination () {
Expand All @@ -130,7 +130,7 @@ function buildDestination () {
})
}

pipeline(buildTransform(), buildDestination(), function (err) {
pipeline(process.stdin, buildTransform(), buildDestination(), function (err) {
console.log('pipeline completed!', err)
})
```
Expand Down
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@ module.exports = function build (fn, opts = {}) {

// set it to null to not retain a reference to the promise
res = null
} else if (res && typeof res.read === 'function') {
return duplexify(stream, res)
} else if (opts.transform) {
return duplexify(stream, res, {
objectMode: true
})
}

return stream
Expand Down
2 changes: 1 addition & 1 deletion test/base.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ test('support Transform streams', ({ same, plan, error }) => {
pipeline(source, transform, () => {})

return transform
})
}, { transform: true })

const stream2 = build(function (source) {
source.on('data', function (line) {
Expand Down