diff options
Diffstat (limited to 'app/node_modules')
| -rw-r--r-- | app/node_modules/okquery/index.js | 35 | ||||
| -rw-r--r-- | app/node_modules/okresource/index.js | 41 | ||||
| -rw-r--r-- | app/node_modules/okresource/package.json | 6 | ||||
| -rw-r--r-- | app/node_modules/okview/index.js | 6 |
4 files changed, 41 insertions, 47 deletions
diff --git a/app/node_modules/okquery/index.js b/app/node_modules/okquery/index.js index 22dd74f..f5db3f0 100644 --- a/app/node_modules/okquery/index.js +++ b/app/node_modules/okquery/index.js @@ -8,40 +8,43 @@ function OKQuery(db, options) { options = options || {}; if (!db) throw new Error('No DB provided to query.'); - if (!options.name) - throw new Error('No name type provided to query'); - this.name = options.name; - this.get = createQuery(db, options); + if (!options.type) + throw new Error('No resource type provided to query'); + var type = options.type; + var id = options.id || '*'; + Object.defineProperty(this, 'type', { + value: type, + writable: false + }); + this.get = createQuery(db, type, id); } -function createQuery(db, config) { - var name = config.name; - var id = config.id || '*'; +function createQuery(db, type, id) { if (isDynamic(id)) { - return queryDynamic(db, name); + return queryDynamic(db, type); } else if (isSet(id)) { - return queryAll(db, name); + return queryAll(db, type); } else { - return querySingle(db, name, id); + return querySingle(db, type, id); } } -function queryDynamic(db, name) { +function queryDynamic(db, type) { return function(options) { options = options || {}; - return db.get(name, options.id); + return db.get(type, options.id); } } -function queryAll(db, name) { +function queryAll(db, type) { return function() { - return db.getAll(name); + return db.getAll(type); } } -function querySingle(db, name, id) { +function querySingle(db, type, id) { return function() { - return db.get(name, id); + return db.get(type, id); } } diff --git a/app/node_modules/okresource/index.js b/app/node_modules/okresource/index.js index cfdd389..58b94c2 100644 --- a/app/node_modules/okresource/index.js +++ b/app/node_modules/okresource/index.js @@ -1,14 +1,17 @@ -var Q = require('q'); -var joi = require('joi'); var OKRestEndpoint = require('okrest'); /** * Creates an OKResource types * Takes a resource name and a spec defining the resources attributes. */ -function createResourceClass(name, spec, options) { +function createResourceClass(options) { options = options || {}; - spec = spec || {}; + if (!options.type) + throw new Error('No resource type provided to OKResource') + if (!options.schema) + throw new Error('No schema provided to OKResource'); + var type = options.type; + var schema = options.schema; // All resources have the same default CRUD endpoint var viewClass = options.endpoint || OKRestEndpoint; // Id determines specific resource referenced. @@ -22,14 +25,12 @@ function createResourceClass(name, spec, options) { */ function OKResource(options) { if (!(this instanceof OKResource)) return new OKResource(options); + if (!options.db) + throw new Error('No DB provided to OKResource'); options = options || {}; this.name = name; - if (!name) - throw new Error('No resource type provided to resource!') - var db = this._db = options.db; - if (!db) - throw new Error('No DB provided to resource!'); - this._validator = compileValidator(spec); + this._db = options.db; + this._schema = schema; } /** @@ -40,23 +41,17 @@ function createResourceClass(name, spec, options) { return viewClass(this, options); }; - // OKResource.prototype.get = function() { - // return this._query(); - // }; + OKResource.prototype.assertValid = function(data) { + this._schema.assertValid(data); + } // Expose the resource type on the class constructor - OKResource.type = name; + Object.defineProperty(OKResource, 'type', { + value: type, + writable: false + }); return OKResource; } -/** - * Compiles our schema spec into a schema validator function - */ -function compileValidator(spec) { - // Skip validation for now - var schema = joi.any(); - return schema.validate.bind(schema); -} - module.exports = createResourceClass; diff --git a/app/node_modules/okresource/package.json b/app/node_modules/okresource/package.json index 12fcd26..43824ed 100644 --- a/app/node_modules/okresource/package.json +++ b/app/node_modules/okresource/package.json @@ -7,9 +7,5 @@ "test": "echo \"Error: no test specified\" && exit 1" }, "author": "OKFocus", - "license": "None", - "dependencies": { - "joi": "^6.0.8", - "q": "^1.2.0" - } + "license": "None" } diff --git a/app/node_modules/okview/index.js b/app/node_modules/okview/index.js index a049901..b2a72e8 100644 --- a/app/node_modules/okview/index.js +++ b/app/node_modules/okview/index.js @@ -57,11 +57,11 @@ OKView.prototype.getTemplateData = function(options) { .then(function(results) { var meta = results.shift(); var normalized = results.reduce(function(data, result, i) { - var name = queries[i].name; + var type = queries[i].type; if (isarray(result)) { - data[pluralize(name)] = result; + data[pluralize(type)] = result; } else { - data[name] = result; + data[type] = result; } return data; }, {meta: meta}); |
