jsonapi-store-relationaldb
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -0,1 +1,3 @@ | ||
- 2016-05-31 - v1.2.0 | ||
- 2016-05-31 - Use latest `jsonapi-server` processed filter | ||
- 2016-05-13 - v1.1.0 | ||
@@ -2,0 +4,0 @@ - 2016-05-13 - Support `jsonapi-server` v1.2 |
@@ -8,2 +8,3 @@ "use strict"; | ||
var Joi = require("joi"); | ||
var semver = require("semver"); | ||
var _ = { | ||
@@ -15,3 +16,6 @@ pick: require("lodash.pick"), | ||
var MIN_SERVER_VERSION = "1.10.0"; | ||
var SqlStore = module.exports = function SqlStore(config) { | ||
SqlStore._checkMinServerVersion(); | ||
this.config = config; | ||
@@ -27,2 +31,10 @@ }; | ||
SqlStore._checkMinServerVersion = function() { | ||
var serverVersion = require('jsonapi-server')._version; | ||
if (!serverVersion) return; | ||
if (semver.lt(serverVersion, MIN_SERVER_VERSION)) { | ||
throw new Error("This version of jsonapi-store-mongodb requires jsonapi-server>=" + MIN_SERVER_VERSION + "."); | ||
} | ||
}; | ||
/** | ||
@@ -143,2 +155,3 @@ initialise gets invoked once for each resource that uses this hander. | ||
if (attribute._type === "number") model[attributeName] = { type: Sequelize.INTEGER, allowNull: true }; | ||
if (attribute._type === "boolean") model[attributeName] = { type: Sequelize.BOOLEAN, allowNull: true }; | ||
}); | ||
@@ -258,31 +271,38 @@ | ||
var attributesToFilter = _.omit(request.params.filter, Object.keys(self.relations)); | ||
var searchBlock = self._recurseOverSearchBlock(attributesToFilter); | ||
var attributesToFilter = _.omit(request.params.processedFilter, Object.keys(self.relations)); | ||
var searchBlock = SqlStore._getSearchBlock(attributesToFilter); | ||
return searchBlock; | ||
}; | ||
SqlStore.prototype._recurseOverSearchBlock = function(obj) { | ||
var self = this; | ||
if (!obj) return { }; | ||
SqlStore._scalarFilterElementToWhereObj = function(element) { | ||
var value = element.value; | ||
if (!element.operator) return value; | ||
var whereObj = { | ||
">": { $gt: value }, | ||
"<": { $lt: value }, | ||
"~": { $like: value }, | ||
":": { $like: "%" + value + "%" } | ||
}[element.operator]; | ||
return whereObj; | ||
}; | ||
SqlStore._filterElementToSearchBlock = function(filterElement) { | ||
if (!filterElement) return { }; | ||
var whereObjs = filterElement.map(function(scalarFilterElement) { | ||
return SqlStore._scalarFilterElementToWhereObj(scalarFilterElement); | ||
}); | ||
if (!whereObjs.length) return { }; | ||
if (filterElement.length === 1) { | ||
return whereObjs[0]; | ||
} | ||
return { $or: whereObjs }; | ||
}; | ||
SqlStore._getSearchBlock = function(filter) { | ||
if (!filter) return { }; | ||
var searchBlock = { }; | ||
Object.keys(obj).forEach(function(attributeName) { | ||
var textToMatch = obj[attributeName]; | ||
if (textToMatch instanceof Array) { | ||
searchBlock[attributeName] = { $or: textToMatch.map(function(i) { | ||
return self._recurseOverSearchBlock({ i: i }).i; | ||
}) }; | ||
} else if (textToMatch instanceof Object) { | ||
// Do nothing, its a nested filter | ||
} else if (textToMatch[0] === ">") { | ||
searchBlock[attributeName] = { $gt: textToMatch.substring(1) }; | ||
} else if (textToMatch[0] === "<") { | ||
searchBlock[attributeName] = { $lt: textToMatch.substring(1) }; | ||
} else if (textToMatch[0] === "~") { | ||
searchBlock[attributeName] = { $like: textToMatch.substring(1) }; | ||
} else if (textToMatch[0] === ":") { | ||
searchBlock[attributeName] = { $like: "%" + textToMatch.substring(1) + "%" }; | ||
} else { | ||
searchBlock[attributeName] = textToMatch; | ||
} | ||
Object.keys(filter).forEach(function(attributeName) { | ||
var filterElement = filter[attributeName]; | ||
searchBlock[attributeName] = SqlStore._filterElementToSearchBlock(filterElement); | ||
}); | ||
@@ -289,0 +309,0 @@ |
{ | ||
"name": "jsonapi-store-relationaldb", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Relational data store for jsonapi-server.", | ||
@@ -25,21 +25,22 @@ "keywords": [ | ||
"dependencies": { | ||
"async": "1.5.0", | ||
"debug": "2.2.0", | ||
"async": "^1.5.2", | ||
"debug": "^2.2.0", | ||
"joi": "6.10.1", | ||
"lodash.assign": "4.0.8", | ||
"lodash.omit": "4.2.1", | ||
"lodash.pick": "4.2.0", | ||
"sequelize": "3.23.0" | ||
"lodash.assign": "^4.0.9", | ||
"lodash.omit": "^4.3.0", | ||
"lodash.pick": "^4.2.1", | ||
"semver": "^5.1.0", | ||
"sequelize": "^3.23.3" | ||
}, | ||
"devDependencies": { | ||
"blanket": "1.1.9", | ||
"coveralls": "2.11.9", | ||
"eslint": "2.9.0", | ||
"jsonapi-server": "1.2.0", | ||
"mocha": "2.4.5", | ||
"mocha-lcov-reporter": "1.2.0", | ||
"mocha-performance": "0.1.1", | ||
"mysql": "2.10.2", | ||
"plato": "1.5.0", | ||
"v8-profiler": "5.6.4" | ||
"coveralls": "^2.11.9", | ||
"eslint": "^2.11.0", | ||
"jsonapi-server": "^1.10.0", | ||
"mocha": "^2.5.3", | ||
"mocha-lcov-reporter": "^1.2.0", | ||
"mocha-performance": "^0.1.1", | ||
"mysql": "^2.10.2", | ||
"plato": "^1.5.0", | ||
"v8-profiler": "^5.6.5" | ||
}, | ||
@@ -46,0 +47,0 @@ "scripts": { |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
1543185
73
15402
3
8
+ Addedsemver@^5.1.0
+ Addedasync@1.5.2(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedlodash.assign@4.2.0(transitive)
+ Addedlodash.omit@4.5.0(transitive)
+ Addedlodash.pick@4.4.0(transitive)
+ Addedsequelize@3.35.1(transitive)
+ Addeduuid@3.4.0(transitive)
+ Addedvalidator@5.7.0(transitive)
- Removedasync@1.5.0(transitive)
- Removeddebug@2.2.0(transitive)
- Removeddepd@1.1.0(transitive)
- Removedlodash@4.11.2(transitive)
- Removedlodash._basedifference@4.4.1(transitive)
- Removedlodash._baseflatten@4.2.1(transitive)
- Removedlodash._setcache@4.1.3(transitive)
- Removedlodash.assign@4.0.8(transitive)
- Removedlodash.keys@4.2.0(transitive)
- Removedlodash.keysin@4.2.0(transitive)
- Removedlodash.omit@4.2.1(transitive)
- Removedlodash.pick@4.2.0(transitive)
- Removedlodash.rest@4.0.5(transitive)
- Removedms@0.7.1(transitive)
- Removednode-uuid@1.4.8(transitive)
- Removedsequelize@3.23.0(transitive)
- Removedvalidator@4.9.0(transitive)
Updatedasync@^1.5.2
Updateddebug@^2.2.0
Updatedlodash.assign@^4.0.9
Updatedlodash.omit@^4.3.0
Updatedlodash.pick@^4.2.1
Updatedsequelize@^3.23.3