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

parseable

v1.0.16

Published

Parseable allows NodeJS developers to build REST API applications with client-driven (ad hoc, dynamic) queries similar to noBackend platforms.

Downloads

42

Readme

Parseable

Parseable allows NodeJS developers to build REST API applications with client-driven (ad hoc, dynamic) queries similar to noBackend platforms. It is influenced by the features provided by the LoopBack and Parse.com Backend-as-a-Service platforms. Parseable can parse RESTful API endpoint queries into properly structured MongoDB syntax.

##Parseable Middlewares

middleware

  • invokes operationMiddleware and filterMiddleware in sequence

operationMiddleware

  • parse req.body with operationParser

filterMiddleware

  • parse req.query with whereParser, sortParser, limitParser, skipParser, and keysParser in sequence

default values

If req.query does't contain property "limit", Parseble will add it to req.query with value 200. The default value can be changed, e.g.:

  var defaultValues = require('parseable').defaultValues; 
  defaultValues.limit = 100;

Example of using Parseable as a middleware:

  var parseable = require('parseable').middleware;  
  var router = require('express').Router();
    
  router.get('/', function(req, res, next) {
    //raw request:
    console.log(req.query);//{"where":{"a1":{"b1":{"c1":{$gt:10}}}},"sort":{},"skip":0,"keys":"a,b,-c"}
    next();
  });
  
  router.get('/', parseable, function(req, res) {
    //after:
    console.log(req.query);//{"where":{"a1.b1.c1":{$gt:10}},"sort":{},"limit":200,"skip":0,"keys":{a:1,b:1,c:0}}
  });

router.put('/', function(req, res, next) { //raw request: console.log(req.body);//{"field":{"__op": "Increment", "amount": 1234}} next(); });

router.put('/', parseable, function(req, res) { //after: console.log(req.body);//{$inc:{"field":1234}} });

<br />
Multiple Operation:
```javascript
  var parseable = require('parseable').middleware;  
  var router = require('express').Router();
    
  router.put('/', function(req, res, next) {
    //raw request:
    console.log(req.body);//{"field":{"sub_field1":{"__op": "Remove", "object": {"a":1}},"sub_field2":{"__op": "Increment", "amount": 1234}}, "field2":{"__op": "AddUnique", "objects": [1,2,3]}}
    next();
  });
  
  router.put('/', parseable, function(req, res) {
    //after:
    console.log(req.body);//{"$pull":{"field.sub_field1":{"a":1}},"$inc":{"field.sub_field2":1234},"$addToSet":{"field2":{"$each":[1,2,3]}}}
  });

Parseable.operationParser

  var operationParser = require('parseable').operationParser; 
  
  var input = {"field":{"__op": "Increment", "amount": 1234}};

  operationParser(input,function(err,output){
    console.log(output); // {$inc:{"field":1234}}
  });
  • Increment: increment a number field
   input:  {"field":{"__op": "Increment", "amount": 1234}}
   output: {$inc:{"field":1234}}
  • Add: add objects to array field
   input: {"field":{"__op": "Add", "objects": [1,2,3]}}
   output: {$pushAll:{"field":[1,2,3]}}
  • AddUnique: add objects if not existed
   input: {"field":{"__op": "AddUnique", "objects": [1,2,3]}}
   output: {$addToSet:{"field":{$each:[1,2,3]}}}
  • Remove: removes from an existing array all instances of a value or values that match a specified query
   input: {"field":{"__op": "Remove", "object": {"a":1}}}
   output: {$pull:{"field":{"a":1}}}
  • RemoveAll: remove objects from array field
   input: {"field":{"__op": "RemoveAll", "objects": [1,2,3]}}
   output: {$pullAll:{"field":[1,2,3]}}
  • Delete: delete a field
   input: {"field":{"__op": "Delete"}}
   output: {$unset:{"field":""}}
  • Set: replaces the value of a field to the specified value.
   input: {"field":123}
   output: {$set:{field:123}}

Parseable.whereParser:

  var whereParser = require('parseable').whereParser; 
  var input = {"a1":{"b1":{"c1":1}}};

  whereParser(input,function(err,output){
    console.log(output); // {"a1.b1.c1":1}
  });
   input: {"a1":{"b1":{"c1":1}}}
   output: {"a1.b1.c1":1}

   input: "{\"a1\":{\"b1\":{\"c1\":1}}}"
   output: {"a1.b1.c1":1}

   input: {"a1":{"b1":{"c1":[1,2,3],"c2":"abc"},"b2":1},"a2":1}
   output: {"a1.b1.c1":[1,2,3],"a1.b1.c2":"abc","a1.b2":1,"a2":1}

   input: "{'a':123}"
   err:  SyntaxError

Parseable.sortParser :

  var sortParser = require('parseable').sortParser; 

  var input = {"a1":{"b1":{"c1":1}}};

  sortParser(input,function(err,output){
    console.log(output); // {"a1.b1.c1":1}
  });
   input: {"a1":{"b1":{"c1":1}}}
   output: {"a1.b1.c1":1}

   input: "{\"a1\":{\"b1\":{\"c1\":1}}}"
   output: {"a1.b1.c1":1}

   input: {"a1":{"b1":{"c1":1},"b2":-1},"a2":1}
   output: {"a1.b1.c1":1,"a1.b2":-1,"a2":1}

   input: {"a1":{"b1":{"c1":[1,2,3]}}}
   err: "bad sort specification: 1,2,3"

   input: {"a1":{"b1":{"c1":1},"b2":0}}
   err: "bad sort specification: 0"

Parseable.limitParser

Parseable.skipParser

  var limitParser = require('parseable').limitParser; 
  var skipParser = require('parseable').skipParser; 
  
  var input = 123;

  limitParser(input,function(err,output){
    console.log(output); // 123
  });
   input: 123
   output: 123

   input: "123"
   output: 123

   input: 2147483649
   err: value out of range

   input: -2147483649
   err: value out of range

   input: "123a"
   err: SyntaxError

   input: "{limit:123}"
   err: SyntaxError

Parseable.keysParser

  var keysParser = require('parseable').keysParser; 
  
  var input = "foo,-koo";

  keysParser(input,function(err,output){
    console.log(output); // {"foo":1,"koo":0}
  });
   input: "a,b,c,-d"
   output: {a:1,b:1,c:1,d:0}

   input: "a,b,c,,,"
   output: {a:1,b:1,c:1}

   input: 123
   err: "SyntaxError: keys is not string"