UNPKG

morefun-forerunnerdb

Version:

A NoSQL document store database for browsers and Node.js.

143 lines (108 loc) 6.72 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Source: Procedure.js</title> <script src="scripts/prettify/prettify.js"> </script> <script src="scripts/prettify/lang-css.js"> </script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> </head> <body> <div id="main"> <h1 class="page-title">Source: Procedure.js</h1> <section> <article> <pre class="prettyprint source linenums"><code>"use strict"; var Shared, Db, Procedure; Shared = require('./Shared'); /** * This class handles remote procedure call generation. It is an * extension of the NodeApiServer class and is primarily used there. * It allows procedures to be created that are exposed to remote * clients via the REST interface. Procedures handle their own server * code including responding to clients directly. * @param {String} name The name of the procedure. * @param {Function} method The handler method. * @constructor */ Procedure = function (name, method) { this.init.apply(this, arguments); }; /** * Create a remote procedure call. * @param {String} name The name of the procedure. * @param {Function} method The procedure handler. */ Procedure.prototype.init = function (name, method) { this._name = name; this._method = method; }; // Tell ForerunnerDB about our new module Shared.addModule('Procedure', Procedure); // Mixin some commonly used methods Shared.mixin(Procedure.prototype, 'Mixin.Common'); Shared.mixin(Procedure.prototype, 'Mixin.Events'); /** * Get / set the procedure name. * @name name * @param {String=} name The name to set. */ Shared.synthesize(Procedure.prototype, 'name'); /** * Execute the procedure, passing in the request and response * (req and res) arguments from the server. Procedure methods * are responsible for correctly communicating with the client * and handling response properly. * @param req * @param res * @returns {*} */ Procedure.prototype.exec = function (req, res) { return this._method.call(this, req, res); }; // Grab the collection module for use later Db = Shared.modules.Db; /** * Create or retrieve a procedure by name. * @param {String} name The name of the procedure. * @param {Function=} method If specified, creates a new procedure * with the provided name and method. * @returns {*} */ Db.prototype.procedure = function (name, method) { var self = this; if (name !== undefined) { self._procedure = self._procedure || {}; if (method !== undefined) { if (self.debug()) { console.log(self.logIdentifier() + ' Creating procedure ' + name); } self._procedure[name] = new Procedure(name, method); self.emit('create', self._procedure[name], 'procedure', name); } return self._procedure[name]; } }; // Tell ForerunnerDB that our module has finished loading Shared.finishModule('Procedure'); module.exports = Procedure;</code></pre> </article> </section> </div> <nav> <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="ActiveBucket.html">ActiveBucket</a></li><li><a href="Angular.html">Angular</a></li><li><a href="AutoBind.html">AutoBind</a></li><li><a href="Collection.html">Collection</a></li><li><a href="CollectionGroup.html">CollectionGroup</a></li><li><a href="Core.html">Core</a></li><li><a href="Db.html">Db</a></li><li><a href="Document.html">Document</a></li><li><a href="Grid.html">Grid</a></li><li><a href="Highchart.html">Highchart</a></li><li><a href="Index2d.html">Index2d</a></li><li><a href="IndexBinaryTree.html">IndexBinaryTree</a></li><li><a href="IndexHashMap.html">IndexHashMap</a></li><li><a href="Infinilist.html">Infinilist</a></li><li><a href="KeyValueStore.html">KeyValueStore</a></li><li><a href="Metrics.html">Metrics</a></li><li><a href="OldView.html">OldView</a></li><li><a href="Operation.html">Operation</a></li><li><a href="Overload.html">Overload</a></li><li><a href="Path.html">Path</a></li><li><a href="Persist.html">Persist</a></li><li><a href="Procedure.html">Procedure</a></li><li><a href="ReactorIO.html">ReactorIO</a></li><li><a href="Serialiser.html">Serialiser</a></li><li><a href="Shared.overload.html">overload</a></li><li><a href="View.html">View</a></li></ul><h3>Mixins</h3><ul><li><a href="ChainReactor.html">ChainReactor</a></li><li><a href="Common.html">Common</a></li><li><a href="Constants.html">Constants</a></li><li><a href="Events.html">Events</a></li><li><a href="Matching.html">Matching</a></li><li><a href="global.html#Shared">Shared</a></li><li><a href="Sorting.html">Sorting</a></li><li><a href="Tags.html">Tags</a></li><li><a href="Triggers.html">Triggers</a></li><li><a href="Updating.html">Updating</a></li></ul><h3>Global</h3><ul><li><a href="global.html#%2522boolean,function%2522">"boolean, function"</a></li><li><a href="global.html#%2522object,function%2522">"object, function"</a></li><li><a href="global.html#%2522object,object,function%2522">"object, object, function"</a></li><li><a href="global.html#%2522string,*,function%2522">"string, *, function"</a></li><li><a href="global.html#%2522string,function%2522">"string, function"</a></li><li><a href="global.html#%2522string,object,function%2522">"string, object, function"</a></li><li><a href="global.html#%2522string,object,object,function%2522">"string, object, object, function"</a></li><li><a href="global.html#%2522string,string,function%2522">"string, string, function"</a></li><li><a href="global.html#%2522string,string,object,function%2522">"string, string, object, function"</a></li><li><a href="global.html#%2522string,string,object,object,function%2522">"string, string, object, object, function"</a></li><li><a href="global.html#access">access</a></li><li><a href="global.html#boolean">boolean</a></li><li><a href="global.html#checksum">checksum</a></li><li><a href="global.html#Condition">Condition</a></li><li><a href="global.html#function">function</a></li><li><a href="global.html#MyModule">MyModule</a></li><li><a href="global.html#name">name</a></li><li><a href="global.html#NodeRAS">NodeRAS</a></li><li><a href="global.html#Section">Section</a></li><li><a href="global.html#server">server</a></li><li><a href="global.html#setData">setData</a></li></ul> </nav> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Wed Jun 15 2016 17:25:36 GMT+0100 (BST) </footer> <script> prettyPrint(); </script> <script src="scripts/linenumber.js"> </script> </body> </html>