{"name":"pino-abstract-transport","version":"3.0.0","keywords":["pino","transport"],"author":{"name":"Matteo Collina","email":"hello@matteocollina.com"},"license":"MIT","_id":"pino-abstract-transport@3.0.0","maintainers":[{"name":"matteo.collina","email":"hello@matteocollina.com"},{"name":"jsumners","email":"james.sumners@gmail.com"},{"name":"watson","email":"w@tson.dk"}],"homepage":"https://github.com/pinojs/pino-abstract-transport#readme","bugs":{"url":"https://github.com/pinojs/pino-abstract-transport/issues"},"tsd":{"directory":"./test/types"},"dist":{"shasum":"b21e5f33a297e8c4c915c62b3ce5dd4a87a52c23","tarball":"http://registry-npm.ywwl.com/pino-abstract-transport/download/pino-abstract-transport-3.0.0.tgz","fileCount":16,"integrity":"sha512-wlfUczU+n7Hy/Ha5j9a/gZNy7We5+cXp8YL+X+PG8S0KXxw7n/JXA3c46Y0zQznIJ83URJiwy7Lh56WLokNuxg==","signatures":[{"sig":"MEUCIQCYcSChooYBt0QVQmm6IF6Ud7l+s4dXXpplft+37syM7QIgZZUamI9BTPfc//dvMaBVESWMvDAKt6WfpBWQXM2TNs4=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":39716,"size":8703,"noattachment":false,"key":"/pino-abstract-transport/-/pino-abstract-transport-3.0.0.tgz"},"main":"index.js","types":"./index.d.ts","gitHead":"11556d6e141366ca7cbe1138ce8ddef72eaa2558","scripts":{"test":"standard | snazzy && borp --check-coverage 'test/*.test.js'  && tsd","prepare":"husky install","test-ci":"npm test"},"_npmUser":{"name":"jsumners","email":"james.sumners@gmail.com"},"repository":{"url":"git+https://github.com/pinojs/pino-abstract-transport.git","type":"git"},"_npmVersion":"11.5.1","description":"Write Pino transports easily","directories":{},"_nodeVersion":"24.7.0","dependencies":{"split2":"^4.0.0"},"_hasShrinkwrap":false,"devDependencies":{"tsd":"^0.31.0","borp":"^0.20.2","husky":"^9.0.6","snazzy":"^9.0.0","standard":"^17.0.0","@types/node":"^20.1.0","thread-stream":"^3.1.0","@matteo.collina/tspl":"^0.2.0"},"_npmOperationalInternal":{"tmp":"tmp/pino-abstract-transport_3.0.0_1759753266346_0.6955896566209769","host":"s3://npm-registry-packages-npm-production"},"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[![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":1759753266579,"_cnpm_publish_time":1759753266579,"dist-tags":{"latest":"3.0.0"}}