UNPKG

copious-transitions

Version:
156 lines (127 loc) 8.85 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Source: lib/transition-endpoint-server.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: lib/transition-endpoint-server.js</h1> <section> <article> <pre class="prettyprint source linenums"><code>// const {ServeMessageEndpoint} = require("message-relay-services") // /** * This class provides a interface to transition processing for requests (JSON) * being delivered by backend services implemented as applications of the * message-relay-services module. * * @memberof base */ class UserMessageEndpoint extends ServeMessageEndpoint { constructor(conf) { // super(conf) // this._transition_handler = false this._mime_handler = false } // ---- ---- ---- ---- ---- ---- ---- ---- ---- /** * This method gives the caller the opportunity to set the handler for handling * transtions (similar to POST methods) * * @param {Function} handler */ set_transition_handler(handler) { // default set in general-transition-engine (must be in configuration -- transition-endpoint) if ( typeof handler === 'function' ) { this._transition_handler = handler } } /** * This method gives the caller the opportunity to set the handler for handling * mime data requests. (similar to GET methods) * * @param {Function} handler */ set_mime_handler(handler) { if ( typeof handler === 'function' ) { this._mime_handler = handler } } // /** * This method is the override of the `app_message_handler` defined in the super class ServeMessageEndpoint. * * This message handler implements the responses to `_tx_op`s 'G' (get) and 'S' (set). * A 'G' message that is properly setup will result in a call to the mime handler that had to be set by the application. * A 'S' message that is properly setup will result in a call to the transtion handler that had to be set by the application. * * In most cases, it can be expected that the methods found in contractuals will be the handlers that are set to the * parameters of this class. * * @param {object} msg_obj * @returns {object} */ async app_message_handler(msg_obj) { let op = msg_obj._tx_op let result = "OK" let user_id = msg_obj._user_dir_key ? msg_obj[msg_obj._user_dir_key] : msg_obj._id if ( this.create_OK &amp;&amp; !!(user_id) ) { await this.ensure_user_directories(user_id) // is this needed here? } msg_obj._id = user_id // switch ( op ) { case 'G' : { // get user information let stat = "ERR" if ( this._mime_handler ) { let asset = msg_obj.asset let [mime,value] = this._mime_handler(asset,msg_obj) return({ "status" : "OK", "data" : value, "mime" : mime, "explain" : "get", "when" : Date.now() }) } return({ "status" : stat, "data" : false, "explain" : "get", "when" : Date.now() }) } case 'D' : { // delete user from everywhere if all ref counts gones. // don't do this here... break } case 'S' : { // or send if ( this._transition_handler ) { let transition = msg_obj.transition return this._transition_handler(transition,msg_obj) } break } default : { break } } // return({ "status" : result, "explain" : "op performed", "when" : Date.now(), "_tracking" : msg_obj._tracking }) } } module.exports = UserMessageEndpoint </code></pre> </article> </section> </div> <nav> <h2><a href="index.html">Home</a></h2><h3>Namespaces</h3><ul><li><a href="Contractual.html">Contractual</a></li><li><a href="CopiousTransitions.html">CopiousTransitions</a></li><li><a href="DefaultDB.html">DefaultDB</a></li><li><a href="base.html">base</a></li><li><a href="field_validators.html">field_validators</a></li></ul><h3>Classes</h3><ul><li><a href="Contractual.LocalTObjectCache.html">LocalTObjectCache</a></li><li><a href="Contractual.MimeHandling.html">MimeHandling</a></li><li><a href="Contractual.TransitionHandling.html">TransitionHandling</a></li><li><a href="Contractual.UserHandling.html">UserHandling</a></li><li><a href="CopiousTransitions.CopiousTransitions.html">CopiousTransitions</a></li><li><a href="DefaultDB.CustomizationMethodsByApplication.html">CustomizationMethodsByApplication</a></li><li><a href="DefaultDB.FauxInMemStore.html">FauxInMemStore</a></li><li><a href="DefaultDB.FileMapper.html">FileMapper</a></li><li><a href="DefaultDB.FilesAndRelays.html">FilesAndRelays</a></li><li><a href="DefaultDB.FilesAndRelays_base.html">FilesAndRelays_base</a></li><li><a href="DefaultDB.LocalStaticDB.html">LocalStaticDB</a></li><li><a href="DefaultDB.LocalStorageLifeCycle.html">LocalStorageLifeCycle</a></li><li><a href="DefaultDB.LocalStorageSerialization.html">LocalStorageSerialization</a></li><li><a href="DefaultDB.PageableMemStoreElement.html">PageableMemStoreElement</a></li><li><a href="DefaultDB.PersistenceContracts.html">PersistenceContracts</a></li><li><a href="DefaultDB.RemoteMessaging.html">RemoteMessaging</a></li><li><a href="DefaultDB.StaticDBDefault.html">StaticDBDefault</a></li><li><a href="GeneralUserDBWrapperImpl.html">GeneralUserDBWrapperImpl</a></li><li><a href="SessionTokenManager.html">SessionTokenManager</a></li><li><a href="base.DBClass.html">DBClass</a></li><li><a href="base.EndpointManager.html">EndpointManager</a></li><li><a href="base.GeneralAppLifeCycle.html">GeneralAppLifeCycle</a></li><li><a href="base.GeneralAuth.html">GeneralAuth</a></li><li><a href="base.GeneralBusiness.html">GeneralBusiness</a></li><li><a href="base.GeneralDynamic.html">GeneralDynamic</a></li><li><a href="base.GeneralMiddleWare.html">GeneralMiddleWare</a></li><li><a href="base.GeneralStatic.html">GeneralStatic</a></li><li><a href="base.GeneralTransitionEngImpl.html">GeneralTransitionEngImpl</a></li><li><a href="base.SessionManager.html">SessionManager</a></li><li><a href="base.SessionManager_Lite.html">SessionManager_Lite</a></li><li><a href="base.TaggedTransition.html">TaggedTransition</a></li><li><a href="base.TokenTables.html">TokenTables</a></li><li><a href="base.UserMessageEndpoint.html">UserMessageEndpoint</a></li><li><a href="base.WebSocketManager.html">WebSocketManager</a></li><li><a href="field_validators.DataLookupField.html">DataLookupField</a></li><li><a href="field_validators.EmailField.html">EmailField</a></li><li><a href="field_validators.EmailVerifyField.html">EmailVerifyField</a></li><li><a href="field_validators.FieldTest.html">FieldTest</a></li><li><a href="field_validators.FieldValidatorTools.html">FieldValidatorTools</a></li><li><a href="field_validators.ForeignAuth.html">ForeignAuth</a></li><li><a href="field_validators.GeneralValidator.html">GeneralValidator</a></li><li><a href="field_validators.LengthyAlphabetField.html">LengthyAlphabetField</a></li><li><a href="field_validators.LengthyDigitalField.html">LengthyDigitalField</a></li><li><a href="field_validators.LengthyField.html">LengthyField</a></li><li><a href="field_validators.LengthyStringField.html">LengthyStringField</a></li><li><a href="field_validators.PasswordField.html">PasswordField</a></li><li><a href="field_validators.PasswordVerifyField.html">PasswordVerifyField</a></li><li><a href="field_validators.TypeCheckField.html">TypeCheckField</a></li></ul><h3>Global</h3><ul><li><a href="global.html#generate_password_block">generate_password_block</a></li><li><a href="global.html#load_configuration">load_configuration</a></li><li><a href="global.html#load_parameters">load_parameters</a></li><li><a href="global.html#module_top">module_top</a></li></ul> </nav> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Tue Oct 31 2023 17:32:59 GMT-0700 (Pacific Daylight Time) </footer> <script> prettyPrint(); </script> <script src="scripts/linenumber.js"> </script> </body> </html>