UNPKG

forerunnerdb

Version:

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

2,204 lines (557 loc) 29.8 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Class: Persist</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: Persist</h1> <section> <header> <h2>Persist</h2> </header> <article> <div class="container-overview"> <h4 class="name" id="Persist"><span class="type-signature"></span>new Persist<span class="signature">()</span><span class="type-signature"></span></h4> <div class="description"> The persistent storage class handles loading and saving data to browser storage. </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Persist.js.html">Persist.js</a>, <a href="Persist.js.html#line26">line 26</a> </li></ul></dd> </dl> </div> <h3 class="subsection-title">Methods</h3> <ul><li><a href="#addStep"><span class="type-signature">(static) </span>addStep<span class="signature">(encode, decode, index<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></a></li><li><a href="#addStep"><span class="type-signature">(static) </span>addStep<span class="signature">(encode, decode)</span><span class="type-signature"></span></a></li><li><a href="#addStep"><span class="type-signature">(static) </span>addStep<span class="signature">(obj)</span><span class="type-signature"></span></a></li><li><a href="#decode"><span class="type-signature"></span>decode<span class="signature">(val, finished)</span><span class="type-signature"></span></a></li><li><a href="#driver"><span class="type-signature"></span>driver<span class="signature">(val)</span><span class="type-signature"> &rarr; {*}</span></a></li><li><a href="#drop"><span class="type-signature"></span>drop<span class="signature">(key, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></a></li><li><a href="#encode"><span class="type-signature"></span>encode<span class="signature">(val, finished)</span><span class="type-signature"></span></a></li><li><a href="#init"><span class="type-signature"></span>init<span class="signature">(db)</span><span class="type-signature"></span></a></li><li><a href="#load"><span class="type-signature"></span>load<span class="signature">(key, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></a></li><li><a href="#mode"><span class="type-signature"></span>mode<span class="signature">(type)</span><span class="type-signature"> &rarr; {*}</span></a></li><li><a href="#persistedSize"><span class="type-signature"></span>persistedSize<span class="signature">(target, callback)</span><span class="type-signature"></span></a></li><li><a href="#save"><span class="type-signature"></span>save<span class="signature">(key, data, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></a></li></ul> <h4 class="name" id=".addStep"><span class="type-signature">(static) </span>addStep<span class="signature">(encode, decode, index<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4> <div class="description"> Adds an encode/decode step to the persistent storage system so that you can add custom functionality. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>encode</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="attributes"> </td> <td class="description last">The encode method called with the data from the previous encode step. When your method is complete it MUST call the callback method. If you provide anything other than false to the err parameter the encoder will fail and throw an error.</td> </tr> <tr> <td class="name"><code>decode</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="attributes"> </td> <td class="description last">The decode method called with the data from the previous decode step. When your method is complete it MUST call the callback method. If you provide anything other than false to the err parameter the decoder will fail and throw an error.</td> </tr> <tr> <td class="name"><code>index</code></td> <td class="type"> <span class="param-type">Number</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last">Optional index to add the encoder step to. This allows you to place a step before or after other existing steps. If not provided your step is placed last in the list of steps. For instance if you are providing an encryption step it makes sense to place this last since all previous steps will then have their data encrypted by your final step.</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Persist.js.html">Persist.js</a>, <a href="Persist.js.html#line251">line 251</a> </li></ul></dd> </dl> <h4 class="name" id=".addStep"><span class="type-signature">(static) </span>addStep<span class="signature">(encode, decode)</span><span class="type-signature"></span></h4> <div class="description"> Adds an encode/decode step to the persistent storage system so that you can add custom functionality. </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>encode</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="description last">The encode method called with the data from the previous encode step. When your method is complete it MUST call the callback method. If you provide anything other than false to the err parameter the encoder will fail and throw an error.</td> </tr> <tr> <td class="name"><code>decode</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="description last">The decode method called with the data from the previous decode step. When your method is complete it MUST call the callback method. If you provide anything other than false to the err parameter the decoder will fail and throw an error.</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Persist.js.html">Persist.js</a>, <a href="Persist.js.html#line233">line 233</a> </li></ul></dd> </dl> <h4 class="name" id=".addStep"><span class="type-signature">(static) </span>addStep<span class="signature">(obj)</span><span class="type-signature"></span></h4> <div class="description"> Adds an encode/decode step to the persistent storage system so that you can add custom functionality. </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">function</span> </td> <td class="description last">The object to encode / decode.</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Persist.js.html">Persist.js</a>, <a href="Persist.js.html#line222">line 222</a> </li></ul></dd> </dl> <h4 class="name" id="decode"><span class="type-signature"></span>decode<span class="signature">(val, finished)</span><span class="type-signature"></span></h4> <div class="description"> Starts a decode waterfall process. </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>val</code></td> <td class="type"> <span class="param-type">*</span> </td> <td class="description last">The data to be decoded.</td> </tr> <tr> <td class="name"><code>finished</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="description last">The callback to pass final data to.</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Persist.js.html">Persist.js</a>, <a href="Persist.js.html#line201">line 201</a> </li></ul></dd> </dl> <h4 class="name" id="driver"><span class="type-signature"></span>driver<span class="signature">(val)</span><span class="type-signature"> &rarr; {*}</span></h4> <div class="description"> Gets / sets the driver used when persisting data. </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>val</code></td> <td class="type"> <span class="param-type">String</span> </td> <td class="description last">Specify the driver type (LOCALSTORAGE, WEBSQL or INDEXEDDB)</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Persist.js.html">Persist.js</a>, <a href="Persist.js.html#line171">line 171</a> </li></ul></dd> </dl> <h5>Returns:</h5> <dl> <dt> Type </dt> <dd> <span class="param-type">*</span> </dd> </dl> <h4 class="name" id="drop"><span class="type-signature"></span>drop<span class="signature">(key, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4> <div class="description"> Deletes data in persistent storage stored under the passed key. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>key</code></td> <td class="type"> <span class="param-type">String</span> </td> <td class="attributes"> </td> <td class="description last">The key to drop data for in the storage.</td> </tr> <tr> <td class="name"><code>callback</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last">The method to call when the data is dropped.</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Persist.js.html">Persist.js</a>, <a href="Persist.js.html#line457">line 457</a> </li></ul></dd> </dl> <h4 class="name" id="encode"><span class="type-signature"></span>encode<span class="signature">(val, finished)</span><span class="type-signature"></span></h4> <div class="description"> Starts an encode waterfall process. </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>val</code></td> <td class="type"> <span class="param-type">*</span> </td> <td class="description last">The data to be encoded.</td> </tr> <tr> <td class="name"><code>finished</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="description last">The callback to pass final data to.</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Persist.js.html">Persist.js</a>, <a href="Persist.js.html#line212">line 212</a> </li></ul></dd> </dl> <h4 class="name" id="init"><span class="type-signature"></span>init<span class="signature">(db)</span><span class="type-signature"></span></h4> <div class="description"> The init method that can be overridden or extended. </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>db</code></td> <td class="type"> <span class="param-type"><a href="Db.html">Db</a></span> </td> <td class="description last">The ForerunnerDB database instance.</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Persist.js.html">Persist.js</a>, <a href="Persist.js.html#line39">line 39</a> </li></ul></dd> </dl> <h4 class="name" id="load"><span class="type-signature"></span>load<span class="signature">(key, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4> <div class="description"> Loads and decodes data from the passed key. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>key</code></td> <td class="type"> <span class="param-type">String</span> </td> <td class="attributes"> </td> <td class="description last">The key to retrieve data from in the persistent storage.</td> </tr> <tr> <td class="name"><code>callback</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last">The method to call when the load process has completed.</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Persist.js.html">Persist.js</a>, <a href="Persist.js.html#line430">line 430</a> </li></ul></dd> </dl> <h4 class="name" id="mode"><span class="type-signature"></span>mode<span class="signature">(type)</span><span class="type-signature"> &rarr; {*}</span></h4> <div class="description"> Gets / sets the persistent storage mode (the library used to persist data to the browser - defaults to localForage). </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>type</code></td> <td class="type"> <span class="param-type">String</span> </td> <td class="description last">The library to use for storage. Defaults to localForage.</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Persist.js.html">Persist.js</a>, <a href="Persist.js.html#line156">line 156</a> </li></ul></dd> </dl> <h5>Returns:</h5> <dl> <dt> Type </dt> <dd> <span class="param-type">*</span> </dd> </dl> <h4 class="name" id="persistedSize"><span class="type-signature"></span>persistedSize<span class="signature">(target, callback)</span><span class="type-signature"></span></h4> <div class="description"> determine byte size of a persisted object, either entire DB or specific collection </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>target</code></td> <td class="type"> <span class="param-type">string</span> | <span class="param-type">object</span> </td> <td class="description last">either a string (collection name) or an object (DB)</td> </tr> <tr> <td class="name"><code>callback</code></td> <td class="type"> <span class="param-type"><a href="global.html#persistedSizeCallback">persistedSizeCallback</a></span> </td> <td class="description last">method to call when size determination is done - mandatory for obtaining a result!</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Persist.js.html">Persist.js</a>, <a href="Persist.js.html#line512">line 512</a> </li></ul></dd> </dl> <h4 class="name" id="save"><span class="type-signature"></span>save<span class="signature">(key, data, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4> <div class="description"> Encodes passed data and then stores it in the browser's persistent storage layer. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>key</code></td> <td class="type"> <span class="param-type">String</span> </td> <td class="attributes"> </td> <td class="description last">The key to store the data under in the persistent storage.</td> </tr> <tr> <td class="name"><code>data</code></td> <td class="type"> <span class="param-type">Object</span> </td> <td class="attributes"> </td> <td class="description last">The data to store under the key.</td> </tr> <tr> <td class="name"><code>callback</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last">The method to call when the save process has completed.</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Persist.js.html">Persist.js</a>, <a href="Persist.js.html#line396">line 396</a> </li></ul></dd> </dl> <h3 class="subsection-title">Members</h3> <ul><li><a href="#localforage"><span class="type-signature"></span>localforage<span class="type-signature"></span></a></li></ul> <h4 class="name" id="localforage"><span class="type-signature"></span>localforage<span class="type-signature"></span></h4> <div class="description"> The local forage library. </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Persist.js.html">Persist.js</a>, <a href="Persist.js.html#line33">line 33</a> </li></ul></dd> </dl> </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="Condition.html">Condition</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="MyModule.html">MyModule</a></li><li><a href="NodeApiClient.html">NodeApiClient</a></li><li><a href="NodeApiServer.html">NodeApiServer</a></li><li><a href="NodeRAS.html">NodeRAS</a></li><li><a href="Odm.html">Odm</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="Overview.html">Overview</a></li><li><a href="Overview_init.html">init</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="Section.html">Section</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="Shared.html">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><a href="global.html">Global</a></h3> </nav> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Thu Mar 01 2018 11:34:23 GMT+0000 (GMT) </footer> <script> prettyPrint(); </script> <script src="scripts/linenumber.js"> </script> </body> </html>