Installations
npm install @diotoborg/vero-atque
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
20.17.0
NPM Version
10.8.2
Score
72
Supply Chain
100
Quality
86.2
Maintenance
100
Vulnerability
100
License
Releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
diotoborg
Download Statistics
Total Downloads
5,771
Last Day
1
Last Week
273
Last Month
1,756
Last Year
5,771
GitHub Statistics
2,267 Commits
1 Watching
1 Branches
1 Contributors
Package Meta Information
Latest Version
4.8.88
Package Id
@diotoborg/vero-atque@4.8.88
Unpacked Size
183.71 kB
Size
95.40 kB
File Count
492
NPM Version
10.8.2
Node Version
20.17.0
Publised On
01 Sept 2024
Total Downloads
Cumulative downloads
Total Downloads
5,771
Last day
-98%
1
Compared to previous day
Last week
-38.2%
273
Compared to previous week
Last month
-3.1%
1,756
Compared to previous month
Last year
0%
5,771
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
29
@diotoborg/vero-atque
Write Pino transports easily.
Install
1npm i @diotoborg/vero-atque
Usage
1import build from '@diotoborg/vero-atque' 2 3export default async function (opts) { 4 return build(async function (source) { 5 for await (let obj of source) { 6 console.log(obj) 7 } 8 }) 9}
or in CommonJS and streams:
1'use strict' 2 3const build = require('@diotoborg/vero-atque') 4 5module.exports = function (opts) { 6 return build(function (source) { 7 source.on('data', function (obj) { 8 console.log(obj) 9 }) 10 }) 11}
Typescript usage
Install the type definitions for node. Make sure the major version of the type definitions matches the node version you are using.
Node 16
1npm i -D @types/node@16
API
build(fn, opts) => Stream
Create a split2
instance and returns it.
This same instance is also passed to the given function, which is called
synchronously.
If opts.transform
is true
, pino-abstract-transform
will
wrap the split2 instance and the returned stream using duplexify
,
so they can be concatenated into multiple transports.
Events emitted
In addition to all events emitted by a Readable
stream, it emits the following events:
unknown
where an unparsable line is found, both the line and optional error is emitted.
Options
-
parse
an option to change to data format passed to build function. When this option is set tolines
, the data is passed as a string, otherwise the data is passed as an object. Default:undefined
. -
close(err, cb)
a function that is called to shutdown the transport. It's called both on error and non-error shutdowns. It can also return a promise. In this case discard the thecb
argument. -
parseLine(line)
a function that is used to parse line received frompino
. -
expectPinoConfig
a boolean that indicates if the transport expects Pino to add some of its configuration to the stream. Default:false
.
Example
custom parseLine
You can allow custom parseLine
from users while providing a simple and safe default parseLine.
1'use strict' 2 3const build = require('@diotoborg/vero-atque') 4 5function defaultParseLine (line) { 6 const obj = JSON.parse(line) 7 // property foo will be added on each line 8 obj.foo = 'bar' 9 return obj 10} 11 12module.exports = function (opts) { 13 const parseLine = typeof opts.parseLine === 'function' ? opts.parseLine : defaultParseLine 14 return build(function (source) { 15 source.on('data', function (obj) { 16 console.log(obj) 17 }) 18 }, { 19 parseLine: parseLine 20 }) 21}
Stream concatenation / pipeline
You can pipeline multiple transports:
1const build = require('@diotoborg/vero-atque') 2const { Transform, pipeline } = require('stream') 3 4function buildTransform () { 5 return build(function (source) { 6 return new Transform({ 7 objectMode: true, 8 autoDestroy: true, 9 transform (line, enc, cb) { 10 line.service = 'bob' 11 cb(null, JSON.stringify(line)) 12 } 13 }) 14 }, { enablePipelining: true }) 15} 16 17function buildDestination () { 18 return build(function (source) { 19 source.on('data', function (obj) { 20 console.log(obj) 21 }) 22 }) 23} 24 25pipeline(process.stdin, buildTransform(), buildDestination(), function (err) { 26 console.log('pipeline completed!', err) 27})
Using pino config
Setting expectPinoConfig
to true
will make the transport wait for pino to send its configuration before starting to process logs. It will add levels
, messageKey
and errorKey
to the stream.
When used with an incompatible version of pino, the stream will immediately error.
1import build from '@diotoborg/vero-atque' 2 3export default function (opts) { 4 return build(async function (source) { 5 for await (const obj of source) { 6 console.log(`[${source.levels.labels[obj.level]}]: ${obj[source.messageKey]}`) 7 } 8 }, { 9 expectPinoConfig: true 10 }) 11}
License
MIT
![Empty State](/_next/static/media/empty.e5fae2e5.png)
No vulnerabilities found.
![Empty State](/_next/static/media/empty.e5fae2e5.png)
No security vulnerabilities found.