UNPKG

graph-common

Version:
51 lines (43 loc) 1.36 kB
(function() { var Query; Query = (function() { function Query(node, action, data) { var _ref; this.node = node; if (typeof this.node === 'object' && node.node && node.action && typeof node.node === 'string' && typeof node.action === 'string') { data = this.node.data; action = this.node.action; this.node = this.node.node; } this.action = action; if ((_ref = this.action) !== 'create' && _ref !== 'read' && _ref !== 'update' && _ref !== 'delete') { this.action = 'read'; } this.data = data; } Query.prototype.run = function(callback) { return this.route(callback); }; Query.prototype.route = function(callback) { var self; this.graph.verbose('Query> routing:', this.current_router); if (this.current_router) { self = this; return this.current_router.router.route(this, function() { if (!self.past_routers) { self.past_routers = []; } self.past_routers.push(self.current_router); self.current_router = self.routers.shift(); if (self.current_router) { return self.route(callback); } else { return callback(self); } }); } }; return Query; })(); module.exports = Query; }).call(this);