From e01c2a20352d252e40ea133d0f4665b2e7513582 Mon Sep 17 00:00:00 2001 From: Sean Fridman Date: Thu, 9 Apr 2015 18:48:10 -0400 Subject: Lil fixes + defensive programming --- app/node_modules/okquery/index.js | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'app/node_modules/okquery/index.js') 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); -- cgit v1.2.3-70-g09d2