copious-transitions
Version:
Framework for working with frameworks
201 lines (169 loc) • 10.4 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: lib/general_dynamic.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_dynamic.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>const AppLifeCycle = require("./general_lifecyle")
const fs = require('fs')
/**
* This class provide a basic interface for carrying out actions required for providing dynamic content.
* Here **Dynamic Content** is taken to mean content that is created by the application in repsonse to a query.
*
* 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 GeneralDynamic extends AppLifeCycle {
constructor(conf) {
super()
//
this.trans_engine = null
this.db = null
this.imported_key_setters = []
}
/**
* This initializer does no more than set the connection to the database.
* @param {object} db
*/
initialize(db) {
this.db = db
}
/**
*
* @param {object} transition_engine - a connect to the transition engine
*/
set_transition_engine(transition_engine) {
this.trans_engine = transition_engine
}
/**
* This method looks for the dynamic asset and may request that some view of it be constructed
* in response to the request that results in a call to this method.
*
* This is called by mime processing.
*
* @param {string} asset
* @param {object} trans_object
* @returns {object}
*/
fetch(asset,trans_object) {
// proecess this asset and return it.
let assetObj = {
'string' : 'not yet implemented',
'mime_type' : 'text/plain'
}
return(assetObj)
}
/**
* This method looks for the dynamic asset and may request that some view of it be constructed
* in response to the request that results in a call to this method.
*
* This is called by transition processing.
*
* Transition processing may require some data to be stored between the primary and secondary action (request).
* This method will produce *stored elements* and *sent elements*.
*
* @param {string} asset
* @param {object} trans_object
* @returns {Array} This array has two elements. The first elements is the data to be sent to the client, the second are elements that are to be cached for a secondary action.
*/
fetch_elements(asset,trans_object) {
return [{},{}]
}
/**
*
* @param {string} key_location
* @param {Function} cb
* @returns {string}
*/
async load_key(key_location,cb) {
if ( !(key_location) || key_location.length === 0 ) {
console.log("Application error: no key loaded for dynamic content: no path in configuration")
process.exit(0)
}
return new Promise((resolve,reject) => {
fs.readFile(key_location,(error,data) => {
if ( error ) {
console.log(error)
throw new Error("Application error: no key loaded for dynamic content")
}
try {
let key = JSON.parse(data.toString())
resolve(key)
} catch (e) {
console.log("ERROR: the application cannot continue when failing to load public key")
process.exit(0)
}
})
})
}
/**
* May be called to set up a list of functions that may be used in an importer function.
*
* @param {string} key
* @param {Array} uses
* @param {Function} setter_fn
*/
add_import(key,uses,setter_fn) {
this.imported_key_setters.push({ "key" : key, "setter_fn" : setter_fn, "uses" : uses })
}
/**
* Called by the general transition engine.
* The general transition engine supplies a function to `import_keys` that uses
* a key and `uses` (an array or map) from each key setter, a descriptor to create a key to use
* in the *setter* function.
*
* The keys and uses are related to cryptographic applications
*
* Each key setter descriptor will have three fields:
* * `key` - some type of crypto key (each an elliptic key for derivation)
* * `setter_fn` - a function that takes the key created by the imported function
* * `uses` - an array of string or descriptors (objects) indicating the function of the key, e.g. signage or verification
*
* The key and the uses are passed to the importer function which produce a key, (a descriptive string)
* The setter, from the `imported_key_setters` element, is then called.
*
* @param {Function} importer_fn
*/
import_keys(importer_fn) {
if ( importer_fn ) {
this.imported_key_setters.forEach(async (keysetter) => {
let key = keysetter.key
let setter = keysetter.setter_fn
let uses = keysetter.uses
let imp_key = await importer_fn(key,uses)
setter(imp_key,this)
})
}
}
}
module.exports = GeneralDynamic
</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>