good-json-schema-filter

2.0.0 • Public • Published

good-json-schema-filter

A Good log object transform stream which filters via json-schema

standard travis npm

Installation:

npm i good-json-schema-filter --save

What problem does this solve?

This library allows you to omit keys or entire log objects matched via json-schema syntax.

Example

const Stream = require('stream')
const SafeJson = require('good-squeeze').SafeJson
const GoodJsonSchemaFilter = require('../')
 
const mockLogStream = new Stream.Readable({objectMode: true})
mockLogStream._read = () => {}
 
const transform = new GoodJsonSchemaFilter({
  rules: [
    {
      name: 'omit-log-object-keys-example-rule',
      test: {
        properties: {
          type: {
            enum: ['filtered-type-omitted-keys']
          }
        },
        required: [
          'type'
        ]
      },
      action: {
        // omit's the foo and bar property
        omit: ['foo', 'bar']
      }
    }, {
      name: 'omit-log-object-example-rule',
      test: {
        properties: {
          type: {
            enum: ['this-will-not-make-it-through']
          }
        },
        required: [
          'type'
        ]
      },
      action: {
        // omits the entire object
        omit: true
      }
    }
  ]
})
 
mockLogStream
  .pipe(transform)
  .pipe(new SafeJson())
  .pipe(process.stdout)
 
mockLogStream.push({type: 'this-will-not-make-it-through', foo: 'bar', bar: 'bar'})
mockLogStream.push({type: 'filtered-type-omitted-keys', foo: 'bar', bar: 'bar'})
mockLogStream.push({type: 'this-will-be-passed-through', foo: 'bar', baz: 'bar'})

This prints:

{"type":"filtered-type-omitted-keys"}
{"type":"this-will-be-passed-through","foo":"bar","baz":"bar"}

Package Sidebar

Install

npm i good-json-schema-filter

Weekly Downloads

3

Version

2.0.0

License

ISC

Last publish

Collaborators

  • max.nachlinger