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

pouchdb-validation-lib

v1.2.2

Published

A PouchDB plug-in that allows you to re-use your CouchDB validate_doc_update functions on the client side.

Downloads

7

Readme

pouchdb-validation

Build Status Dependency Status devDependency Status

A PouchDB plug-in that allows you to re-use your CouchDB validate_doc_update functions on the client side.

A browser version is available.

First, make sure you understand how validation functions work in CouchDB. A good start is the CouchDB guide entry on validation functions.

Usage

First, you need to register the plug-in with PouchDB. That can be done using the PouchDB.plugin() function. In NodeJS, you can just pass in the result of the require() function. In the browser, you pass in the browser object name given above.

An example (using the list plug-in):

//NodeJS (and Browserify)
PouchDB.plugin(require("pouchdb-validation"));

//Browser - after the JavaScript file containing the plug-in has been
//included via a script tag (or something similar).
PouchDB.plugin(Validation);

All functions have two ways of returning the output to the user. One is a callback parameter, which should have the signature (err, resp). The other is the Promise all functions return. PouchDB itself uses the same system.

db.validatingPut(doc[, options[, callback]])

Exactly the same as the db.put function, but checks with all validation functions ('validate_doc_update') in all design documents of the current database if it is ok to save doc. In short, this method acts more like its CouchDB equivalent than the original PouchDB version does. The only thing you get to see of it is a few extra errors, i.e. of the 'unauthorized' or the 'forbidden' type. It also has a few extra options (defaults are shown):

  • secObj: e.g.:

    {
       admins: {
          names: [],
          roles: []
       },
       members: {
          names: [],
          roles: []
       }
    }
  • userCtx: e.g.:

    {
       db: "test_db",
       name: "username",
       roles: [
          "_admin"
       ]
    }
  • checkHttp: Set this to true if you want to validate HTTP database documents offline too. Unnecessary for CouchDB, but handy for e.g. pouchdb-express-router, which doesn't validate itself.

db.validatingPost(doc[, options[, callback]])

See the db.validatingPut() function.

db.validatingRemove(doc[, options[, callback]])

See the db.validatingPut() function.

db.validatingBulkDocs(bulkDocs[, options[, callback]])

See the db.validatingPut() function. Returns an array, like db.bulkDocs(). The all_or_nothing attribute on bulkDocs is unsupported. Also, the result array might not be in the same order as the passed in documents.

db.validatingPutAttachment(docId, attachmentId, rev, attachment, type[, options[, callback]])

See the db.validatingPut() function. Output is the same as db.putAttachment() (except for a few extra errors being possible.)

db.validatingRemoveAttachment(docId, attachmentId, rev[, options[, callback]])

See the db.validatingPut() function. Output is the same as db.removeAttachment() (except for a few extra errors being possible.)

db.installValidationMethods()

Installs the validation methods on this database. In other words, the db.* methods are replaced by their db.validating* counterparts. This method is always synchronous.

Throws: an error if the methods are already installed. Returns: nothing

db.uninstallValidationMethods()

Undoes what db.installValidationMethods did. This method is always synchronous.

Throws: an error if the methods aren't currently installed. Returns: nothing

License

Apache-2.0