summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/node_modules/okutil/index.js40
-rw-r--r--app/node_modules/okutil/package.json16
2 files changed, 56 insertions, 0 deletions
diff --git a/app/node_modules/okutil/index.js b/app/node_modules/okutil/index.js
new file mode 100644
index 0000000..bef085c
--- /dev/null
+++ b/app/node_modules/okutil/index.js
@@ -0,0 +1,40 @@
+var isarray = require('lodash.isarray');
+var pluralize = require('pluralize');
+var Q = require('q');
+
+/**
+ * OKUtils!
+ * Cross cutting concerns n stuff
+ */
+module.exports = {
+
+ /**
+ * Takes a meta data query and an array of resource queries
+ * and returns a promise for an object merging all queried
+ * data, pluralizing keys where necessary.
+ *
+ * Lil bit convoluted, sorry.
+ */
+ fetchTemplateData: function fetchTemplateData(meta, queries, options) {
+ return Q.promise(function(resolve, reject) {
+ return Q.all(
+ [meta.get()].concat(queries.map(function(query) {
+ return query.get(options);
+ })))
+ .then(function(results) {
+ var metadata = results.shift();
+ var normalized = results.reduce(function(data, result, i) {
+ var type = queries[i].type;
+ if (isarray(result)) {
+ data[pluralize(type)] = result;
+ } else {
+ data[type] = result;
+ }
+ return data;
+ }, {meta: metadata});
+ resolve(normalized);
+ }, reject);
+ });
+ }
+
+};
diff --git a/app/node_modules/okutil/package.json b/app/node_modules/okutil/package.json
new file mode 100644
index 0000000..36d5c1e
--- /dev/null
+++ b/app/node_modules/okutil/package.json
@@ -0,0 +1,16 @@
+{
+ "name": "okutil",
+ "version": "1.0.0",
+ "description": "pragmatic!",
+ "main": "index.js",
+ "scripts": {
+ "test": "echo \"Error: no test specified\" && exit 1"
+ },
+ "author": "OKFocus",
+ "license": "None",
+ "dependencies": {
+ "lodash.isarray": "^3.0.1",
+ "pluralize": "^1.1.2",
+ "q": "^1.2.0"
+ }
+}