1.2.1 • Published 7 years ago

rethinkdb-validator-stream v1.2.1

Weekly downloads
4
License
MIT
Repository
github
Last release
7 years ago

rethinkdb-validator-stream Build Status js-standard-style

Validate rethinkdb queries streaming to the socket

Installation

npm i --save rethinkdb-validator-stream

Usage

var createValidatorStream = require('rethinkdb-validator-stream')

var astStream = ... // incoming ast stream
var socket = ... // rethinkdb socket connection
var replyStream = ... // outgoing reply stream

var opts = {
  db: 'database', // optional, specify database requirement for all queries
  whitelist: [
    // exact reql query or reql validator,
    // see `http://github.com/tjmehta/validate-reql` for examples
  ]
}
var validatorStream = createValidatorStream(opts)

// incoming pipeline
astStream.pipe(validatorStream).pipe(socket)
// handle validation errors
validatorStream.on('error', function (err) {
  // handle err
  // if you want to send a rethinkdb ClientError to the reply stream,
  // checkout https://github.com/tjmehta/rethinkdb-stream-chunker (responseStream.insertClientError)
})
// outgoign pipeline
socket.pipe(replyStream)

Credits

Thank you Mike Mintz! Code is heavily inspired by rethinkdb-websocket-server

License

MIT