summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/node_modules/okresource/index.js21
-rw-r--r--app/node_modules/okresource/package.json1
-rw-r--r--app/node_modules/okschema/index.js10
-rw-r--r--app/node_modules/okschema/package.json2
4 files changed, 20 insertions, 14 deletions
diff --git a/app/node_modules/okresource/index.js b/app/node_modules/okresource/index.js
index 94d8cfb..5a643de 100644
--- a/app/node_modules/okresource/index.js
+++ b/app/node_modules/okresource/index.js
@@ -1,4 +1,5 @@
var assign = require('object-assign');
+var cloneDeep = require('cloneDeep');
var Q = require('q');
/**
@@ -18,15 +19,16 @@ function OKResource(options) {
throw new Error('No DB provided to OKResource');
var schema = options.schema;
+ var spec = schema.spec;
// Iterate through spec to find field which will act as the
// resource id in da db.
- var idField = Object.keys(schema.spec).reduce(function(idField, prop) {
- var spec = schema.spec[prop];
- if (spec.id)
+ var idField = Object.keys(spec).reduce(function(idField, prop) {
+ var propSpec = spec[prop];
+ if (propSpec.id)
idField = prop;
return idField;
// If schema has a prop called 'id', default to that one
- }, schema.spec.id && 'id');
+ }, spec.id && 'id');
if (!idField)
throw new Error('Bad schema: no ID field');
@@ -37,8 +39,9 @@ function OKResource(options) {
// Define properties which are part of the API
Object.defineProperty(this, 'spec', {
- value: schema.spec,
- writable: false,
+ get: function() {
+ return schema.spec;
+ },
enumerable: true
});
@@ -190,7 +193,7 @@ function OKResourceInstance(resource, options) {
// conceptually at all times since they are derived from app
// configuration, but may not actually be present
// in the database and need custom logic to handle this.
- var staticData = assign({}, options.static);
+ var staticData = cloneDeep(options.static);
var id = staticData[resource.idField];
if (!id)
throw new Error(
@@ -204,9 +207,9 @@ function OKResourceInstance(resource, options) {
resource.get(id).then(function(data) {
// Note the assign call. Don't expose private references!
if (data) {
- resolve(assign({}, data, staticData));
+ resolve(assign({}, data, cloneDeep(staticData)));
} else {
- resolve(assign({}, staticData));
+ resolve(assign({}, cloneDeep(staticData)));
}
}).fail(reject);
});
diff --git a/app/node_modules/okresource/package.json b/app/node_modules/okresource/package.json
index 7f19c9b..7b1dfbb 100644
--- a/app/node_modules/okresource/package.json
+++ b/app/node_modules/okresource/package.json
@@ -9,6 +9,7 @@
"author": "OKFocus",
"license": "None",
"dependencies": {
+ "lodash.clonedeep": "^3.0.0",
"object-assign": "^2.0.0",
"q": "^1.2.0"
}
diff --git a/app/node_modules/okschema/index.js b/app/node_modules/okschema/index.js
index 8871a99..4b215d1 100644
--- a/app/node_modules/okschema/index.js
+++ b/app/node_modules/okschema/index.js
@@ -1,4 +1,4 @@
-var assign = require('object-assign');
+var cloneDeep = require('lodash.clonedeep');
var mschema = require('mschema');
var v = require('validator');
@@ -68,7 +68,7 @@ function OKSchema(spec) {
if (!(this instanceof OKSchema)) return new OKSchema(spec);
if (!spec)
throw new Error('No spec provided to OKSchema');
- spec = assign({}, spec);
+ spec = cloneDeep(spec);
// Cache the mschema version of our spec
this._mschemaSpec = Object.keys(spec).reduce(function(cache, prop) {
// If custom type, return its parent spec
@@ -83,8 +83,10 @@ function OKSchema(spec) {
}, {});
Object.defineProperty(this, 'spec', {
- value: spec,
- writable: false
+ get: function() {
+ return cloneDeep(spec);
+ },
+ enumerable: true
});
}
diff --git a/app/node_modules/okschema/package.json b/app/node_modules/okschema/package.json
index 21214fa..21a7c67 100644
--- a/app/node_modules/okschema/package.json
+++ b/app/node_modules/okschema/package.json
@@ -9,8 +9,8 @@
"author": "OKFocus",
"license": "None",
"dependencies": {
+ "lodash.clonedeep": "^3.0.0",
"mschema": "^0.5.5",
- "object-assign": "^2.0.0",
"validator": "^3.37.0"
}
}