UNPKG

copious-transitions

Version:
189 lines (154 loc) 10.9 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Source: lib/general_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/general_endpoint_server.js</h1> <section> <article> <pre class="prettyprint source linenums"><code> const AppLifeCycle = require("./general_lifecyle") const DEFAULT_TRANSITION_ENDPOINT = "./transition-endpoint-server" /** * * The most basic version of this transition engine is an endpoint manager. * This * * especially useful for uploaders or other types of processes that * use a backend servrer conversation in order to expose validated endpoints * to the user facing services (web servers) * * NOTE: all the base classes in /lib return the class and do not return an instance. Explore the applications and * the reader will find that the descendant modules export instances. The classes provided by copious-transitions must * be extended by an application. * * @memberof base */ class EndpointManager extends AppLifeCycle { constructor() { super() this.trans_processor = false this.user_processor = false this.endpoint_service = false this.web_sockets = false } /** * Give the enpoint to the contractual * @param {object} trans_processor * @param {object} user_processor * @param {object} mime_processor */ set_contractual_filters(trans_processor,user_processor,mime_processor) { this.trans_processor = trans_processor this.user_processor = user_processor this.mime_processor = mime_processor } /** * Accepts a reference to the application supplied web socket server manager and sets the `web_sockets` field to it. * * @param {object} web_sockets - the reference to the application supplied web socket server manager. */ set_ws(web_sockets) { this.web_sockets = web_sockets } /** * Checks for the `transition_endpoint` field on the configuration object (conf). * * If the `transition_endpoint` field is an object, this assumes that the object is a configuration * that can be passed to `initialize_endpoint_services`. * * @param {object} conf * @param {object} db */ initialize(conf,db) { this.conf = conf this.db = db if ( (conf.transition_endpoint !== undefined) &amp;&amp; (typeof conf.transition_endpoint === 'object') ) { this.initialize_endpoint_services(conf.transition_endpoint) } } /** * Creates a transition endpoint based on the class determined by configuration. * The field `endpoint_module` (i.e. `conf.transition_endpoint.endpoint_module`) provides * the name of the module to require if it is supplied. If it is not mentioned, then * the default transition endpoint will be used. * * (Applications seeking to supply an endpoint server for transition processing should overrided the default.) * * An instance of the class will be created. The creation of this class will result in a listening server on a tls port. * * Once the class is created and no error has been encountered, * the transition handler and the mime handler may be set. (Note: the user processes is not handled through the endpoint server.) * * Any version of this method should call upon the transion processor for using the endpoint transition. * Also, it should call upon the mime handler to access static assets. The methods called will be the following: * * * `endpoint_transition` * * `static_asset_handler` * * In the supplied handlers, a server id is required to be included in the message object coming from a message relay client. * The message object will be passed on to the contractual module handling the use case (transition or mime). * * Finally, the results are passed back to the message hanlder the called the transition/mime handler. * The message handler will handle the client message response. * * * @param {object} conf * @returns {object} */ initialize_endpoint_services(conf) { if ( conf === undefined ) return // let TransitionalEndpoint = require((conf.endpoint_module !== undefined) ? conf.endpoint_module : DEFAULT_TRANSITION_ENDPOINT) if ( TransitionalEndpoint !== undefined ) { this.endpoint_service = new TransitionalEndpoint(conf) this.endpoint_service.set_transition_handler(async (transition,msg_obj) => { // called from app_message_handler (see endpoint service message-relay-services) let server_id = msg_obj ? msg_obj.server_id : false if ( server_id &amp;&amp; this.trans_processor ) { // transitional let result = await this.trans_processor.endpoint_transition(transition,msg_obj) return result[1] // this will send back the JSON object without HTTP status codes } }) this.endpoint_service.set_mime_handler(async (asset,msg_obj) => { // called from app_message_handler (see endpoint service message-relay-services) let server_id = msg_obj ? msg_obj.server_id : false if ( server_id &amp;&amp; this.this.mime_processor ) { // transitional msg_obj._x_c$trns_path = "set_mime_handler" let result = await this.this.mime_processor.static_asset_handler(asset,msg_obj) return [result[1] ,result[2]] // [1] is mime type object, [2] is a string determined by the app } }) } else { throw new Error("general endpoint server: no TransitionalEndpoint class type provided by configuration or default") } // return {} } } module.exports = EndpointManager </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>