npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

validate-reql

v0.2.2

Published

allows validation of rethinkdb reql queries using a whitelist of reql validators. this was specifically designed to work w/ rethinkdb-primus.

Downloads

22

Readme

validate-reql Build Status js-standard-style

allows validation of rethinkdb reql queries using a whitelist of reql validators. this was specifically designed to work w/ rethinkdb-primus.

Installation

npm i --save rethinkdb-validator

Usage

Validate ReQL using a whitelist of exact ReQL queries.

Example: test if reql is in reql whitelist

var validateReql = require('validate-reql')
var r = require('rethinkdb')

var reql = r
  .table('hello')
  .insert({ foo: 'bar' }, { durable: true })
var whitelist = [
  r
  .table('hello')
  .insert({ foo: 'bar' }, { durable: true })
]
validateReql(reql, whitelist).then(function () {
  // pass!
}).catch(...)

// Failure Cases
var reql1 = r
  .table('hello')
  .insert({ foo: 'bar' })
validateReql(reql, whitelist).catch(function (err) {
  // err is an instance of ValidationError - require('validate-reql').ValidationError
  console.log(err) // [ ValidationError: "query" mismatch ]
})

Validate ReQL using custom validation

rethinkdb-validator monkey patches rethinkdb w/ some new methods

Example: Custom validation using refs: r.rvRef and rvValidate

// Place r.rvRef('<name>') in place of ReQL you want to manually validate in your whitelist ReQL // Note: if the actual value from the ReQL is a sequence of ReQL you will have to test it as Rethink AST

var validateReql = require('validate-reql')
var r = require('rethinkdb')

var reql = r
  .table('hello')
  .insert({ foo: 'bar' }, { durable: true })
var whitelist = [
  r
  .table('hello')
  .insert(r.rvRef('update'), r.rvRef('updateRef'))
  .rvValidate(function (refs) {
    console.log(refs.update) // { foo: 'bar' }
    console.log(refs.updateRef) // { durable: true }
    return true // return a boolean or promise
  })
]
validateReql(reql, whitelist).then(function () {
  // pass!
}).catch(...)
// Failure Cases
var whitelist2 = [
  r
  .table('hello')
  .insert(r.rvRef('update'), r.rvRef('updateRef'))
  .rvValidate(function (refs) {
    console.log(refs.update) // { foo: 'bar' }
    console.log(refs.updateRef) // { durable: true }
    // return a boolean or promise
    return true // pass
    return false // results in [ ValidationError: custom validation failed ], require('validate-reql/lib/errors/validate.js')
    return Promise.resolve() // pass
    return Promise.reject(new Error('boom')) // results in [ Error: boom ]
  })
]
validateReql(reql, whitelist2).catch(function (err) {
  console.log(err) // scenarios outlined above
})

Example: Custom validation using property tests

// Place r.rvTest(func) in place of ReQL you want to manually validate inline in your whitelist ReQL

var validateReql = require('validate-reql')
var r = require('rethinkdb')

var reql = r
  .table('hello')
  .insert({ foo: 'bar' })
var whitelist = [
  r
  .table('hello')
  .insert(r.rvTest(function (value, refs) {
    console.log(value) // { foo: 'bar' }
    console.log(refs) // {} note: be careful using refs in here, they may not have been read yet
    // return a boolean or promise
    return true // pass
    return false // results in [ ValidationError: custom validation failed ], require('validate-reql/lib/errors/validate.js')
    return Promise.resolve() // pass
    return Promise.reject(new Error('boom')) // results in [ Error: boom ]
  }))
]
validateReql(reql, whitelist).catch(function (err) {
  console.log(err) // scenarios outlined above
})

Credits

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

License

MIT