UNPKG

copious-transitions

Version:
2,118 lines (569 loc) 30.2 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Class: LocalStaticDB</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">Class: LocalStaticDB</h1> <section> <header> <h2><span class="attribs"><span class="type-signature"></span></span> <span class="ancestors"><a href="DefaultDB.html">DefaultDB</a>.</span>LocalStaticDB<span class="signature">()</span><span class="type-signature"></span></h2> <div class="class-description"><p>This is a local storage implementation for those applications that do not supply their own in overriding the general DB methods given by the class DBClass nor by configuring a replacement for this class.</p> <p>This class extends FilesAndRelays which will attempt to port stored object out to an external DB, connected via the message service relay.</p> <p>One property of this storage class is that data is updated by the last writer. There is no mechanism for consensus exposed by this stack. Local copies can be inconsistent with remote entries. It is possible that an intermediary process can handle consistency, or a derived class might handle consistency. Part of the reason for this state of affairs is that the code here is provided for default usage of the Copious Transitions stack; it is not provided to solve a universal problem. Yet, it might provide some basic logic that can be used to interface with more universal architectures.</p> <p>On the other hand, there is a pub/sub mechanism that may be configured. And, a subclass of this class may implement <code>app_subscription_handler</code>. One possibility for the implementation of that method may be to take in copies of known entries and recitfy the differences when they arive and also to put in new entries without much extra effort.</p> <p>This implementation stores data, all entries, in a file and reloads it later. Large objects, those that can be sent through communication channels without relying on special streaming or P2P architectures, are stored in their own files, but a representation of the data, including the name of the file it is in, is stored in a PageableMemStoreElement element.</p> <p>The handling of data persisted between runs is introduced by extending LocalStorageSerialization.</p> <p>In this object storage, there is an assumption made about fields in the object. Object are expected to have or end up with about three different fields.</p> <p>At least locally, the object will have a local identity or if not that some field indicating an owner of the object: <code>_whokey</code> Another id would be a wide area id (or univsersal id): <code>_id</code>. It is expected that objects anywhere would be stored with such an id. Then, the objects will have a hash (most likely a hash of the object data) stored in <code>_key</code>.</p> <p>This stack expects that globally the two keys <code>_id</code> and <code>_key</code> will be part of the object. And, this stack will add <code>_whokey</code> locally.</p> <p>However, if the object cannot be found by those two keys, then this stack may search the wider area for the object using the local key with the assumption that the local key is made up of some salient feature of the object. For example, it actaully might be the case that just one object is stored per owner, or perhaps <code>_whokey</code> and <code>_key</code> are the same universal hash. (It may be the case that all three fields are the same.)</p></div> </header> <article> <div class="container-overview"> <h2>Constructor</h2> <h4 class="name" id="LocalStaticDB"><span class="type-signature"></span>new LocalStaticDB<span class="signature">()</span><span class="type-signature"></span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="custom_storage_static_db.js.html">custom_storage/static_db.js</a>, <a href="custom_storage_static_db.js.html#line473">line 473</a> </li></ul></dd> </dl> </div> <h3 class="subsection-title">Methods</h3> <h4 class="name" id="application_hash_key"><span class="type-signature"></span>application_hash_key<span class="signature">(obj)</span><span class="type-signature"> &rarr; {string}</span></h4> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>obj</code></td> <td class="type"> <span class="param-type">object</span> </td> <td class="description last"></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="custom_storage_static_db.js.html">custom_storage/static_db.js</a>, <a href="custom_storage_static_db.js.html#line580">line 580</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> <ul> <li>value in a field <code>_key</code>, which is expected to be the hash of the data</li> </ul> </div> <dl> <dt> Type </dt> <dd> <span class="param-type">string</span> </dd> </dl> <h4 class="name" id="del_key_value"><span class="type-signature"></span>del_key_value<span class="signature">(whokey)</span><span class="type-signature"> &rarr; {boolean}</span></h4> <div class="description"> <p>Clear out the local knowledge of this object. Requests the wider area to forget the object. Removes any files associated with the object.</p> <p>The call to <em>delete</em></p> </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>whokey</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last"><p>named this to emphasize that this stack is usually used just for user objects.</p></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="custom_storage_static_db.js.html">custom_storage/static_db.js</a>, <a href="custom_storage_static_db.js.html#line712">line 712</a> </li></ul></dd> </dl> <h5>Returns:</h5> <dl> <dt> Type </dt> <dd> <span class="param-type">boolean</span> </dd> </dl> <h4 class="name" id="flat_object"><span class="type-signature"></span>flat_object<span class="signature">(obj)</span><span class="type-signature"> &rarr; {string}</span></h4> <div class="description"> <p>Stringify the object -- some implementations might want to use some other method to turn an object into a packed array.</p> </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>obj</code></td> <td class="type"> <span class="param-type">object</span> </td> <td class="description last"></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="custom_storage_static_db.js.html">custom_storage/static_db.js</a>, <a href="custom_storage_static_db.js.html#line567">line 567</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> <ul> <li>the stringified object</li> </ul> </div> <dl> <dt> Type </dt> <dd> <span class="param-type">string</span> </dd> </dl> <h4 class="name" id="flat_object_size"><span class="type-signature"></span>flat_object_size<span class="signature">(obj)</span><span class="type-signature"> &rarr; {Number}</span></h4> <div class="description"> <p>Add up all the fields values of an object that have a length field.</p> </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>obj</code></td> <td class="type"> <span class="param-type">object</span> </td> <td class="description last"></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="custom_storage_static_db.js.html">custom_storage/static_db.js</a>, <a href="custom_storage_static_db.js.html#line551">line 551</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> <ul> <li>object size</li> </ul> </div> <dl> <dt> Type </dt> <dd> <span class="param-type">Number</span> </dd> </dl> <h4 class="name" id="get_key_value"><span class="type-signature">(async) </span>get_key_value<span class="signature">(whokey)</span><span class="type-signature"> &rarr; {object}</span></h4> <div class="description"> <p>Returns the object that can be found by the key.</p> <p>Searches for the id of the data object by using a local identity, where the id mapped by the whokey refers to a universal wide area identity of the data.</p> <p>If a local copy cannot be found it searches the wide area using the application defined field and the <code>whokey</code> as its value.</p> <p>Otherwise, it finds one and tries to load its psme (PageableMemStoreElement). The object returned to the application will be stored with the psme. If the object is not large, it should be in the storage map, <code>_storage_map</code>. The method <code>findOne</code> will return the object from <code>_storage_map</code> which is defined in the super class. Also, it <code>_storage_map</code> is out of sync, then <code>findOne</code> will bring it back to sync (and take longer).</p> </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>whokey</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last"></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="custom_storage_static_db.js.html">custom_storage/static_db.js</a>, <a href="custom_storage_static_db.js.html#line675">line 675</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> <ul> <li>the value stored</li> </ul> </div> <dl> <dt> Type </dt> <dd> <span class="param-type">object</span> </dd> </dl> <h4 class="name" id="has"><span class="type-signature"></span>has<span class="signature">(whokey)</span><span class="type-signature"> &rarr; {string|boolean}</span></h4> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>whokey</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last"></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="custom_storage_static_db.js.html">custom_storage/static_db.js</a>, <a href="custom_storage_static_db.js.html#line521">line 521</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> <ul> <li>returns fals if the elementis not in the <code>_whokey_to_ids</code> map. Otherwise, the id.</li> </ul> </div> <dl> <dt> Type </dt> <dd> <span class="param-type">string</span> | <span class="param-type">boolean</span> </dd> </dl> <h4 class="name" id="hash"><span class="type-signature"></span>hash<span class="signature">(data)</span><span class="type-signature"> &rarr; {string}</span></h4> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>data</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last"></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="custom_storage_static_db.js.html">custom_storage/static_db.js</a>, <a href="custom_storage_static_db.js.html#line531">line 531</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> <p>the hash of the data</p> </div> <dl> <dt> Type </dt> <dd> <span class="param-type">string</span> </dd> </dl> <h4 class="name" id="hash_from_persitence"><span class="type-signature"></span>hash_from_persitence<span class="signature">(obj)</span><span class="type-signature"> &rarr; {string}</span></h4> <div class="description"> <p>Returns the intrinsic hash key</p> </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>obj</code></td> <td class="type"> <span class="param-type">object</span> </td> <td class="description last"></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="custom_storage_static_db.js.html">custom_storage/static_db.js</a>, <a href="custom_storage_static_db.js.html#line589">line 589</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> <ul> <li>object hash</li> </ul> </div> <dl> <dt> Type </dt> <dd> <span class="param-type">string</span> </dd> </dl> <h4 class="name" id="initialize"><span class="type-signature"></span>initialize<span class="signature">(conf)</span><span class="type-signature"></span></h4> <div class="description"> <p>Calls the initializer for FilesAndRelays and the immediate LocalStorageSerialization</p> </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>conf</code></td> <td class="type"> <span class="param-type">object</span> </td> <td class="description last"></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="custom_storage_static_db.js.html">custom_storage/static_db.js</a>, <a href="custom_storage_static_db.js.html#line495">line 495</a> </li></ul></dd> </dl> <h4 class="name" id="newer"><span class="type-signature"></span>newer<span class="signature">(remote_obj, up_obj)</span><span class="type-signature"> &rarr; {boolean}</span></h4> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>remote_obj</code></td> <td class="type"> <span class="param-type">object</span> </td> <td class="description last"></td> </tr> <tr> <td class="name"><code>up_obj</code></td> <td class="type"> <span class="param-type">object</span> </td> <td class="description last"></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="custom_storage_static_db.js.html">custom_storage/static_db.js</a>, <a href="custom_storage_static_db.js.html#line542">line 542</a> </li></ul></dd> </dl> <h5>Returns:</h5> <dl> <dt> Type </dt> <dd> <span class="param-type">boolean</span> </dd> </dl> <h4 class="name" id="setPersistence"><span class="type-signature"></span>setPersistence<span class="signature">(presistence_db)</span><span class="type-signature"></span></h4> <div class="description"> <p>quite possibly another DB made fore keeping objects around for a long time will be used</p> </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>presistence_db</code></td> <td class="type"> <span class="param-type">*</span> </td> <td class="description last"></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="custom_storage_static_db.js.html">custom_storage/static_db.js</a>, <a href="custom_storage_static_db.js.html#line512">line 512</a> </li></ul></dd> </dl> <h4 class="name" id="set_key_value"><span class="type-signature">(async) </span>set_key_value<span class="signature">(whokey, data)</span><span class="type-signature"> &rarr; {boolean}</span></h4> <div class="description"> <p>Searches for the id of the data object by using a local identity, where the id mapped by the whokey refers to a universal wide area identity of the data.</p> <p>If it finds a local copy of the object, it will check to see if the local persistence storage keeps a copy. Given there is a local copy, this method calls <code>get_key_value</code> primarily for loadging instances of PageableMemStoreElement as it is already established the object exists.</p> <p>If it does not find a local copy of the object, it will check to see if the larger world knows about it. Without a local copy, the object <code>_id</code> cannot be known, so it searches for the object using the <code>whokey</code> using the field <code>_whokey_field</code>, which is hopefully known universally. (It is expected the application has standardized some field and way of obtaining a universal id for the objects stored here.) The search performed is the same as in <code>get_key_value</code>, however this method attempts to update the object data. It calls <code>load_missing_or_update</code> to perform this operation.</p> <p>Once the knowledge of the object is established, it will make sure the data is updated and synced with the local disk.</p> <p>If the object has not been seen anywhere, this method will store it as a the definitive entry and send out to the wider area.</p> </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>whokey</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last"></td> </tr> <tr> <td class="name"><code>data</code></td> <td class="type"> <span class="param-type">object</span> </td> <td class="description last"></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="custom_storage_static_db.js.html">custom_storage/static_db.js</a>, <a href="custom_storage_static_db.js.html#line618">line 618</a> </li></ul></dd> </dl> <h5>Returns:</h5> <dl> <dt> Type </dt> <dd> <span class="param-type">boolean</span> </dd> </dl> </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>