{"name":"pino-abstract-transport","version":"2.0.0","description":"Write Pino transports easily","main":"index.js","scripts":{"prepare":"husky install","test":"standard | snazzy && tap test/*.test.js  && tsd","test-ci":"standard | snazzy && tap test/*.test.js --coverage-report=lcovonly && tsd"},"repository":{"type":"git","url":"git+https://github.com/pinojs/pino-abstract-transport.git"},"keywords":["pino","transport"],"author":{"name":"Matteo Collina","email":"hello@matteocollina.com"},"license":"MIT","bugs":{"url":"https://github.com/pinojs/pino-abstract-transport/issues"},"homepage":"https://github.com/pinojs/pino-abstract-transport#readme","dependencies":{"split2":"^4.0.0"},"devDependencies":{"@types/node":"^20.1.0","husky":"^9.0.6","snazzy":"^9.0.0","standard":"^17.0.0","tap":"^16.0.0","thread-stream":"^2.6.0","tsd":"^0.31.0"},"tsd":{"directory":"./test/types"},"_id":"pino-abstract-transport@2.0.0","gitHead":"e7861ecbbfdcc52f7b3be5ca41722c62b410f271","types":"./index.d.ts","_nodeVersion":"20.16.0","_npmVersion":"10.8.1","dist":{"integrity":"sha512-F63x5tizV6WCh4R6RHyi2Ml+M70DNRXt/+HANowMflpgGFMAym/VKm6G7ZOQRjqN7XbGxK1Lg9t6ZrtzOaivMw==","shasum":"de241578406ac7b8a33ce0d77ae6e8a0b3b68a60","tarball":"http://registry-npm.ywwl.com/pino-abstract-transport/download/pino-abstract-transport-2.0.0.tgz","fileCount":15,"unpackedSize":38204,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIELbSINbDlu1Pxj8ruq9pDSYeXmPoMKkOhHYlMmvuGdnAiAOu1ndL2z8Dba7P6FzSyaaC1CpfcV0H+yogoVMkWeq1g=="}],"size":8459,"noattachment":false,"key":"/pino-abstract-transport/-/pino-abstract-transport-2.0.0.tgz"},"_npmUser":{"name":"matteo.collina","email":"hello@matteocollina.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/pino-abstract-transport_2.0.0_1725347658035_0.19132059967505644"},"_hasShrinkwrap":false,"readme":"# pino-abstract-transport\n[![npm version](https://img.shields.io/npm/v/pino-abstract-transport)](https://www.npmjs.com/package/pino-abstract-transport)\n[![Build Status](https://img.shields.io/github/actions/workflow/status/pinojs/pino-abstract-transport/ci.yml?branch=main)](https://github.com/pinojs/pino-abstract-transport/actions)\n[![Coverage Status](https://coveralls.io/repos/github/pinojs/pino-abstract-transport/badge.svg?branch=main)](https://coveralls.io/github/pinojs/pino-abstract-transport?branch=main)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/)\n\nWrite Pino transports easily.\n\n## Install\n\n```sh\nnpm i pino-abstract-transport\n```\n\n## Usage\n\n```js\nimport build from 'pino-abstract-transport'\n\nexport default async function (opts) {\n  return build(async function (source) {\n    for await (let obj of source) {\n      console.log(obj)\n    }\n  })\n}\n```\n\nor in CommonJS and streams:\n\n```js\n'use strict'\n\nconst build = require('pino-abstract-transport')\n\nmodule.exports = function (opts) {\n  return build(function (source) {\n    source.on('data', function (obj) {\n      console.log(obj)\n    })\n  })\n}\n```\n\n## Typescript usage\n\nInstall the type definitions for node. Make sure the major version of the type definitions matches the node version you are using.\n\n#### Node 16\n\n```sh\nnpm i -D @types/node@16\n```\n\n## API\n\n### build(fn, opts) => Stream\n\nCreate a [`split2`](http://npm.im/split2) instance and returns it.\nThis same instance is also passed to the given function, which is called\nsynchronously.\n\nIf `opts.transform` is `true`, `pino-abstract-transform` will \nwrap the split2 instance and the returned stream using [`duplexify`](https://www.npmjs.com/package/duplexify),\nso they can be concatenated into multiple transports.\n\n#### Events emitted\n\nIn addition to all events emitted by a [`Readable`](https://nodejs.org/api/stream.html#stream_class_stream_readable)\nstream, it emits the following events:\n\n* `unknown` where an unparsable line is found, both the line and optional error is emitted.\n\n#### Options\n\n* `parse` an option to change to data format passed to build function. When this option is set to `lines`,\n  the data is passed as a string, otherwise the data is passed as an object. Default: `undefined`.\n\n* `close(err, cb)` a function that is called to shutdown the transport. It's called both on error and non-error shutdowns.\n  It can also return a promise. In this case discard the the `cb` argument.\n\n* `parseLine(line)` a function that is used to parse line received from `pino`.\n\n* `expectPinoConfig` a boolean that indicates if the transport expects Pino to add some of its configuration to the stream. Default: `false`.\n\n## Example\n\n### custom parseLine\n\nYou can allow custom `parseLine` from users while providing a simple and safe default parseLine.\n\n```js\n'use strict'\n\nconst build = require('pino-abstract-transport')\n\nfunction defaultParseLine (line) {\n  const obj = JSON.parse(line)\n  // property foo will be added on each line\n  obj.foo = 'bar'\n  return obj\n}\n\nmodule.exports = function (opts) {\n  const parseLine = typeof opts.parseLine === 'function' ? opts.parseLine : defaultParseLine\n  return build(function (source) {\n    source.on('data', function (obj) {\n      console.log(obj)\n    })\n  }, {\n    parseLine: parseLine\n  })\n}\n```\n\n### Stream concatenation / pipeline\n\nYou can pipeline multiple transports:\n\n```js\nconst build = require('pino-abstract-transport')\nconst { Transform, pipeline } = require('stream')\n\nfunction buildTransform () {\n  return build(function (source) {\n    return new Transform({\n      objectMode: true,\n      autoDestroy: true,\n      transform (line, enc, cb) {\n        line.service = 'bob'\n        cb(null, JSON.stringify(line))\n      }\n    })\n  }, { enablePipelining: true })\n}\n\nfunction buildDestination () {\n  return build(function (source) {\n    source.on('data', function (obj) {\n      console.log(obj)\n    })\n  })\n}\n\npipeline(process.stdin, buildTransform(), buildDestination(), function (err) {\n  console.log('pipeline completed!', err)\n})\n```\n\n### Using pino config\n\nSetting `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.\n\nWhen used with an incompatible version of pino, the stream will immediately error.\n\n```js\nimport build from 'pino-abstract-transport'\n\nexport default function (opts) {\n  return build(async function (source) {\n    for await (const obj of source) {\n      console.log(`[${source.levels.labels[obj.level]}]: ${obj[source.messageKey]}`)\n    }\n  }, {\n    expectPinoConfig: true\n  })\n}\n```\n\n## License\n\nMIT\n","publish_time":1725347658315,"maintainers":[{"name":"matteo.collina","email":"hello@matteocollina.com"}],"_cnpm_publish_time":1725347658315,"dist-tags":{"latest":"3.0.0"}}