diff options
| author | Sean Fridman <fridman@mail.sfsu.edu> | 2015-04-09 18:48:10 -0400 |
|---|---|---|
| committer | Sean Fridman <fridman@mail.sfsu.edu> | 2015-04-09 20:19:27 -0400 |
| commit | e01c2a20352d252e40ea133d0f4665b2e7513582 (patch) | |
| tree | 81cf004f6be5c0de43d84400a9f7d78a54502cb0 /app/node_modules/okquery/index.js | |
| parent | a6e734472853328cca725acbbcad0416763e934e (diff) | |
Lil fixes + defensive programming
Diffstat (limited to 'app/node_modules/okquery/index.js')
| -rw-r--r-- | app/node_modules/okquery/index.js | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/app/node_modules/okquery/index.js b/app/node_modules/okquery/index.js index 2d93e2a..89c8b73 100644 --- a/app/node_modules/okquery/index.js +++ b/app/node_modules/okquery/index.js @@ -1,3 +1,4 @@ +var cloneDeep = require('lodash.clonedeep'); var assign = require('object-assign'); var isobject = require('lodash.isobject'); var Q = require('q'); @@ -16,6 +17,9 @@ function OKQuery(options) { var resource = options.resource; var type = resource.type; var query = options.query || '*'; + // Ensure immutability + if (isobject(query)) + query = cloneDeep(query); Object.defineProperty(this, 'resource', { value: resource, @@ -55,6 +59,9 @@ function createQuery(resource, query, options) { function queryComplex(resource, query) { var dynamicProp; + // Query is an object specifying key value pairs against which + // to match DB entries. Iterate through and check if any of the values + // is unbound e.g. :id var notDynamic = Object.keys(query).every(function(prop) { var matcher = query[prop]; if (isDynamic(matcher)) { @@ -71,6 +78,8 @@ function queryComplex(resource, query) { } } else { return function(id) { + // Bind the dynamic property to its value + // and add the pair to the query var dynamicQuery = {}; dynamicQuery[dynamicProp] = id; var query = assign({}, query, dynamicQuery); |
