express-query-params
Advanced tools
Comparing version 1.0.2 to 1.1.0
@@ -12,2 +12,8 @@ const DEFAULT_OPTIONS = { | ||
const options = { ...DEFAULT_OPTIONS, ...customOptions } | ||
if ( | ||
options.format === 'sequelize' | ||
&& !options.sequelizeOp | ||
) throw new Error('Format `sequelize` requires option `sequelizeOp`') | ||
const parser = require(`../formats/${options.format}`)(options) | ||
@@ -14,0 +20,0 @@ |
@@ -27,2 +27,2 @@ /* | ||
exports.trimOperators = raw => raw.replace(OPERATOR_TRIM_REGEX, '') | ||
exports.trimOperators = raw => String(raw).replace(OPERATOR_TRIM_REGEX, '') |
{ | ||
"name": "express-query-params", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"description": "Express.js middleware implementing the API Query Spec, converting the params to SQL or a Mongo query", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -55,3 +55,5 @@ # Express Query Params | ||
// Accepts `mongo` or `sql` - defaults to `mongo` | ||
/* | ||
Accepts `mongo`, `sql` or `sequelize` - defaults to `mongo` | ||
*/ | ||
format: 'mongo', | ||
@@ -83,8 +85,9 @@ | ||
So far, this middleware supports `mongodb` and `sql` as output formats. | ||
So far, this middleware supports `mongodb`, `sql` and `sequelize` as output formats. | ||
* In case of `mongodb`, the output is a javascript object that can be used to query MongoDb. | ||
* In case of `sql`, it will output an object with the following props: | ||
* `mongodb` the output is a javascript object that can be used to query MongoDb. | ||
* `sql` it will output an object with the following props: | ||
* `query` - this contains a tokenised query (ie. `$1` replaces raw params) | ||
* `values` - this is an array of typecast values you can use in your query runner to coincide with the `query` prop | ||
* `sequelize` outputs an object usable as a where clause in a Sequelize lookup | ||
@@ -91,0 +94,0 @@ ## A Note About v1 |
@@ -5,3 +5,2 @@ /* global test expect */ | ||
const getQuery = require('../query') | ||
const { DEFAULT_OPTIONS } = require('../../lib') | ||
@@ -38,4 +37,4 @@ const correctQuery = { | ||
test('req.query -> Mongo', () => { | ||
const parsedQuery = mongoParser(DEFAULT_OPTIONS)(getQuery) | ||
const parsedQuery = mongoParser({ blacklistParams: [ 'limit' ] })(getQuery) | ||
expect(parsedQuery).toEqual(correctQuery) | ||
}) |
@@ -5,3 +5,2 @@ /* global test expect */ | ||
const getQuery = require('../query') | ||
const { DEFAULT_OPTIONS } = require('../../lib') | ||
@@ -52,3 +51,3 @@ const correctValues = [ | ||
test('req.query -> SQL', () => { | ||
const { query, values } = sqlParser(DEFAULT_OPTIONS)(getQuery) | ||
const { query, values } = sqlParser({ blacklistParams: [ 'limit' ] })(getQuery) | ||
@@ -55,0 +54,0 @@ expect(query).toBe(correctQuery) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
143837
20
488
109