From 7d15bc8a49121dd85171d7837c4f6a97a7e096dc Mon Sep 17 00:00:00 2001 From: Sean Fridman Date: Fri, 3 Apr 2015 12:39:01 -0400 Subject: Beef up resource abstraction --- app/index.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'app/index.js') diff --git a/app/index.js b/app/index.js index 29dcfd0..6d057d3 100644 --- a/app/index.js +++ b/app/index.js @@ -56,19 +56,22 @@ OKCMS.prototype._createSchemas = function(schemaConfig) { OKCMS.prototype._createResources = function(resourceConfig, db, schemaCache) { resourceConfig = resourceConfig || {}; - return resourceConfig.map(function(config) { + var typeCache = {}; + return resourceConfig.reduce(function(cache, config) { var type = config.type; var schema = schemaCache[type]; if (!schema) throw new Error('Resource config references nonexistent schema'); - // If no id is provided, default to "select all" - var id = config.id || '*'; - return OKResource({ + // If we already created resource class, just skip + if (cache[type]) + return cache; + cache[type] = OKResource({ type: type, - id: id, + db: db, schema: schema }) - }); + return cache; + }, {}); }; OKCMS.prototype._createViews = function(viewConfig, db, -- cgit v1.2.3-70-g09d2