UNPKG

regard

Version:

Sugar-interface to access multiple data sources.

49 lines (34 loc) 966 B
var _ = require('lodash'); var exports = module.exports = Request; function Request(key) { if (!(this instanceof Request)) { return new Request(key); } this.args = undefined; this.context = undefined; this.endpoint = undefined; this.handler = undefined; this.key = key; this.path = undefined; } Request.prototype.init = function (endpoint, handler, args) { this.args = args; this.context = resolveRequestContext(endpoint); this.endpoint = endpoint; this.handler = handler; this.path = resolveRequestPath(endpoint); }; function resolveRequestContext(endpoint) { var context = []; endpoint.walk(context, 'context'); context.unshift(endpoint.connector.context); context = _(context).compact().value(); context = _.reduce(context, _.merge, {}); return context; } function resolveRequestPath(endpoint) { var path = []; endpoint.walk(path, 'path'); path = _(path).compact().value().join('/'); return path; }