cleanup JSDOC & generate md + html, md is pushed in the repo

Timothée Rebours 3 years ago
parent 2c409d5b67
commit 76acd75588
  1. 122
      docs/Cursor.md
  2. 454
      docs/Datastore.md
  3. 61
      docs/Executor.md
  4. 61
      docs/Index.md
  5. 165
      docs/Persistence.md
  6. 22
      docs/Waterfall.md
  7. 10
      docs/customUtilsBrowser.md
  8. 10
      docs/customUtilsNode.md
  9. 155
      docs/globals.md
  10. 73
      docs/model.md
  11. 289
      docs/storage.md
  12. 190
      docs/storageBrowser.md
  13. 188
      docs/storageReactNative.md
  14. 39
      docs/utils.md
  15. 31
      jsdoc2md.js
  16. 73
      lib/cursor.js
  17. 218
      lib/datastore.js
  18. 1
      lib/persistence.js

@ -2,14 +2,17 @@
## Cursor ⇐ <code>Promise</code> ## Cursor ⇐ <code>Promise</code>
<p>Manage access to data, be it to find, update or remove it.</p> <p>Manage access to data, be it to find, update or remove it.</p>
<p>It extends Promise so that its methods are chainable &amp; awaitable.</p> <p>It extends <code>Promise</code> so that its methods (which return <code>this</code>) are chainable &amp; awaitable.</p>
**Kind**: global class **Kind**: global class
**Extends**: <code>Promise</code> **Extends**: <code>Promise</code>
* [Cursor](#Cursor) ⇐ <code>Promise</code> * [Cursor](#Cursor) ⇐ <code>Promise</code>
* [new Cursor(db, query, [execFn], [async])](#new_Cursor_new) * [new Cursor(db, query, [execFn], [hasCallback])](#new_Cursor_new)
* _instance_ * _instance_
* [.db](#Cursor+db) : [<code>Datastore</code>](#Datastore)
* [.query](#Cursor+query) : [<code>query</code>](#query)
* [.hasCallback](#Cursor+hasCallback) : <code>boolean</code>
* [.limit(limit)](#Cursor+limit) ⇒ [<code>Cursor</code>](#Cursor) * [.limit(limit)](#Cursor+limit) ⇒ [<code>Cursor</code>](#Cursor)
* [.skip(skip)](#Cursor+skip) ⇒ [<code>Cursor</code>](#Cursor) * [.skip(skip)](#Cursor+skip) ⇒ [<code>Cursor</code>](#Cursor)
* [.sort(sortQuery)](#Cursor+sort) ⇒ [<code>Cursor</code>](#Cursor) * [.sort(sortQuery)](#Cursor+sort) ⇒ [<code>Cursor</code>](#Cursor)
@ -20,33 +23,48 @@
* [.exec(_callback)](#Cursor+exec) * [.exec(_callback)](#Cursor+exec)
* [.execAsync()](#Cursor+execAsync) ⇒ <code>Promise.&lt;(Array.&lt;document&gt;\|\*)&gt;</code> * [.execAsync()](#Cursor+execAsync) ⇒ <code>Promise.&lt;(Array.&lt;document&gt;\|\*)&gt;</code>
* _inner_ * _inner_
* [~execFn](#Cursor..execFn) : <code>function</code> * [~execFnWithCallback](#Cursor..execFnWithCallback) : <code>function</code>
* [~execFnAsync](#Cursor..execFnAsync) ⇒ <code>Promise</code> * [~execFnWithoutCallback](#Cursor..execFnWithoutCallback) ⇒ <code>Promise</code> \| <code>\*</code>
* [~execCallback](#Cursor..execCallback) : <code>function</code> * [~execCallback](#Cursor..execCallback) : <code>function</code>
<a name="new_Cursor_new"></a> <a name="new_Cursor_new"></a>
### new Cursor(db, query, [execFn], [async]) ### new Cursor(db, query, [execFn], [hasCallback])
<p>Create a new cursor for this collection</p> <p>Create a new cursor for this collection</p>
**Params**
| Param | Type | Default | Description | - db [<code>Datastore</code>](#Datastore) - <p>The datastore this cursor is bound to</p>
| --- | --- | --- | --- | - query [<code>query</code>](#query) - <p>The query this cursor will operate on</p>
| db | [<code>Datastore</code>](#Datastore) | | <p>The datastore this cursor is bound to</p> | - [execFn] [<code>execFnWithoutCallback</code>](#Cursor..execFnWithoutCallback) | [<code>execFnWithCallback</code>](#Cursor..execFnWithCallback) - <p>Handler to be executed after cursor has found the results and before the callback passed to find/findOne/update/remove</p>
| query | [<code>query</code>](#query) | | <p>The query this cursor will operate on</p> | - [hasCallback] <code>boolean</code> <code> = true</code> - <p>If false, specifies that the <code>execFn</code> is of type [execFnWithoutCallback](#Cursor..execFnWithoutCallback) rather than [execFnWithCallback](#Cursor..execFnWithCallback).</p>
| [execFn] | [<code>execFn</code>](#Cursor..execFn) \| [<code>execFnAsync</code>](#Cursor..execFnAsync) | | <p>Handler to be executed after cursor has found the results and before the callback passed to find/findOne/update/remove</p> |
| [async] | <code>boolean</code> | <code>false</code> | <p>If true, specifies that the <code>execFn</code> is of type [execFnAsync](#Cursor..execFnAsync) rather than [execFn](#Cursor..execFn).</p> |
<a name="Cursor+db"></a>
### cursor.db : [<code>Datastore</code>](#Datastore)
**Kind**: instance property of [<code>Cursor</code>](#Cursor)
**Access**: protected
<a name="Cursor+query"></a>
### cursor.query : [<code>query</code>](#query)
**Kind**: instance property of [<code>Cursor</code>](#Cursor)
**Access**: protected
<a name="Cursor+hasCallback"></a>
### cursor.hasCallback : <code>boolean</code>
<p>Determines if the [Cursor#execFn](Cursor#execFn) is an [execFnWithoutCallback](#Cursor..execFnWithoutCallback) or not.</p>
**Kind**: instance property of [<code>Cursor</code>](#Cursor)
**Access**: protected
<a name="Cursor+limit"></a> <a name="Cursor+limit"></a>
### cursor.limit(limit) ⇒ [<code>Cursor</code>](#Cursor) ### cursor.limit(limit) ⇒ [<code>Cursor</code>](#Cursor)
<p>Set a limit to the number of results</p> <p>Set a limit to the number of results</p>
**Kind**: instance method of [<code>Cursor</code>](#Cursor) **Kind**: instance method of [<code>Cursor</code>](#Cursor)
**Params**
| Param | Type | - limit <code>Number</code>
| --- | --- |
| limit | <code>Number</code> |
<a name="Cursor+skip"></a> <a name="Cursor+skip"></a>
@ -54,10 +72,9 @@
<p>Skip a number of results</p> <p>Skip a number of results</p>
**Kind**: instance method of [<code>Cursor</code>](#Cursor) **Kind**: instance method of [<code>Cursor</code>](#Cursor)
**Params**
| Param | Type | - skip <code>Number</code>
| --- | --- |
| skip | <code>Number</code> |
<a name="Cursor+sort"></a> <a name="Cursor+sort"></a>
@ -65,10 +82,9 @@
<p>Sort results of the query</p> <p>Sort results of the query</p>
**Kind**: instance method of [<code>Cursor</code>](#Cursor) **Kind**: instance method of [<code>Cursor</code>](#Cursor)
**Params**
| Param | Type | Description | - sortQuery <code>Object.&lt;string, number&gt;</code> - <p>sortQuery is { field: order }, field can use the dot-notation, order is 1 for ascending and -1 for descending</p>
| --- | --- | --- |
| sortQuery | <code>Object.&lt;string, number&gt;</code> | <p>sortQuery is { field: order }, field can use the dot-notation, order is 1 for ascending and -1 for descending</p> |
<a name="Cursor+projection"></a> <a name="Cursor+projection"></a>
@ -76,21 +92,22 @@
<p>Add the use of a projection</p> <p>Add the use of a projection</p>
**Kind**: instance method of [<code>Cursor</code>](#Cursor) **Kind**: instance method of [<code>Cursor</code>](#Cursor)
**Params**
| Param | Type | Description | - projection <code>Object.&lt;string, number&gt;</code> - <p>MongoDB-style projection. {} means take all fields. Then it's { key1: 1, key2: 1 } to take only key1 and key2
| --- | --- | --- | { key1: 0, key2: 0 } to omit only key1 and key2. Except _id, you can't mix takes and omits.</p>
| projection | <code>Object.&lt;string, number&gt;</code> | <p>MongoDB-style projection. {} means take all fields. Then it's { key1: 1, key2: 1 } to take only key1 and key2 { key1: 0, key2: 0 } to omit only key1 and key2. Except _id, you can't mix takes and omits.</p> |
<a name="Cursor+project"></a> <a name="Cursor+project"></a>
### cursor.project(candidates) ⇒ [<code>Array.&lt;document&gt;</code>](#document) ### cursor.project(candidates) ⇒ [<code>Array.&lt;document&gt;</code>](#document)
<p>Apply the projection</p> <p>Apply the projection.</p>
<p>This is an internal function. You should use [execAsync](#Cursor+execAsync) or [exec](#Cursor+exec).</p>
**Kind**: instance method of [<code>Cursor</code>](#Cursor) **Kind**: instance method of [<code>Cursor</code>](#Cursor)
**Access**: protected
**Params**
| Param | Type | - candidates [<code>Array.&lt;document&gt;</code>](#document)
| --- | --- |
| candidates | [<code>Array.&lt;document&gt;</code>](#document) |
<a name="Cursor+_execAsync"></a> <a name="Cursor+_execAsync"></a>
@ -104,14 +121,15 @@ This is an internal function, use execAsync which uses the executor</p>
### cursor.\_exec(_callback) ### cursor.\_exec(_callback)
<p>Get all matching elements <p>Get all matching elements
Will return pointers to matched elements (shallow copies), returning full copies is the role of find or findOne Will return pointers to matched elements (shallow copies), returning full copies is the role of find or findOne</p>
This is an internal function, use exec which uses the executor</p> <p>This is an internal function, use [exec](#Cursor+exec) which uses the [executor](#Datastore+executor).</p>
**Kind**: instance method of [<code>Cursor</code>](#Cursor) **Kind**: instance method of [<code>Cursor</code>](#Cursor)
**Access**: protected
**See**: Cursor#exec
**Params**
| Param | Type | - _callback [<code>execCallback</code>](#Cursor..execCallback)
| --- | --- |
| _callback | [<code>execCallback</code>](#Cursor..execCallback) |
<a name="Cursor+exec"></a> <a name="Cursor+exec"></a>
@ -120,44 +138,44 @@ This is an internal function, use exec which uses the executor</p>
Will return pointers to matched elements (shallow copies), returning full copies is the role of find or findOne</p> Will return pointers to matched elements (shallow copies), returning full copies is the role of find or findOne</p>
**Kind**: instance method of [<code>Cursor</code>](#Cursor) **Kind**: instance method of [<code>Cursor</code>](#Cursor)
**Params**
| Param | Type | - _callback [<code>execCallback</code>](#Cursor..execCallback)
| --- | --- |
| _callback | [<code>execCallback</code>](#Cursor..execCallback) |
<a name="Cursor+execAsync"></a> <a name="Cursor+execAsync"></a>
### cursor.execAsync() ⇒ <code>Promise.&lt;(Array.&lt;document&gt;\|\*)&gt;</code> ### cursor.execAsync() ⇒ <code>Promise.&lt;(Array.&lt;document&gt;\|\*)&gt;</code>
<p>Get all matching elements <p>Async version of [exec](#Cursor+exec).</p>
Will return pointers to matched elements (shallow copies), returning full copies is the role of find or findOne</p>
**Kind**: instance method of [<code>Cursor</code>](#Cursor) **Kind**: instance method of [<code>Cursor</code>](#Cursor)
<a name="Cursor..execFn"></a> **See**: Cursor#exec
<a name="Cursor..execFnWithCallback"></a>
### Cursor~execFnWithCallback : <code>function</code>
<p>Has a callback</p>
### Cursor~execFn : <code>function</code>
**Kind**: inner typedef of [<code>Cursor</code>](#Cursor) **Kind**: inner typedef of [<code>Cursor</code>](#Cursor)
**Params**
- err <code>Error</code>
- res [<code>?Array.&lt;document&gt;</code>](#document) | [<code>document</code>](#document)
| Param | Type | <a name="Cursor..execFnWithoutCallback"></a>
| --- | --- |
| err | <code>Error</code> |
| res | [<code>?Array.&lt;document&gt;</code>](#document) \| [<code>document</code>](#document) |
<a name="Cursor..execFnAsync"></a> ### Cursor~execFnWithoutCallback ⇒ <code>Promise</code> \| <code>\*</code>
<p>Does not have a callback, may return a Promise.</p>
### Cursor~execFnAsync ⇒ <code>Promise</code>
**Kind**: inner typedef of [<code>Cursor</code>](#Cursor) **Kind**: inner typedef of [<code>Cursor</code>](#Cursor)
**Params**
| Param | Type | - res [<code>?Array.&lt;document&gt;</code>](#document) | [<code>document</code>](#document)
| --- | --- |
| res | [<code>?Array.&lt;document&gt;</code>](#document) \| [<code>document</code>](#document) |
<a name="Cursor..execCallback"></a> <a name="Cursor..execCallback"></a>
### Cursor~execCallback : <code>function</code> ### Cursor~execCallback : <code>function</code>
**Kind**: inner typedef of [<code>Cursor</code>](#Cursor) **Kind**: inner typedef of [<code>Cursor</code>](#Cursor)
**Params**
| Param | Type | Description | - err <code>Error</code>
| --- | --- | --- | - res [<code>Array.&lt;document&gt;</code>](#document) | <code>\*</code> - <p>If an execFn was given to the Cursor, then the type of this parameter is the one returned by the execFn.</p>
| err | <code>Error</code> | |
| res | [<code>Array.&lt;document&gt;</code>](#document) \| <code>\*</code> | <p>If an execFn was given to the Cursor, then the type of this parameter is the one returned by the execFn.</p> |

@ -5,37 +5,46 @@
**Kind**: global class **Kind**: global class
**Extends**: <code>EventEmitter</code> **Extends**: <code>EventEmitter</code>
**Emits**: <code>Datastore.event:&quot;compaction.done&quot;</code> **Emits**: <code>Datastore#event:&quot;compaction.done&quot;</code>
* [Datastore](#Datastore) ⇐ <code>EventEmitter</code> * [Datastore](#Datastore) ⇐ <code>EventEmitter</code>
* [new Datastore(options)](#new_Datastore_new) * [new Datastore(options)](#new_Datastore_new)
* _instance_ * _instance_
* [.inMemoryOnly](#Datastore+inMemoryOnly) : <code>boolean</code>
* [.autoload](#Datastore+autoload) : <code>boolean</code>
* [.timestampData](#Datastore+timestampData) : <code>boolean</code>
* [.filename](#Datastore+filename) : <code>string</code>
* [.persistence](#Datastore+persistence) : [<code>Persistence</code>](#Persistence) * [.persistence](#Datastore+persistence) : [<code>Persistence</code>](#Persistence)
* [.executor](#Datastore+executor) : [<code>Executor</code>](#Executor) * [.executor](#Datastore+executor) : [<code>Executor</code>](#Executor)
* [.indexes](#Datastore+indexes) : <code>Object.&lt;string, Index&gt;</code>
* [.ttlIndexes](#Datastore+ttlIndexes) : <code>Object.&lt;string, number&gt;</code>
* [.autoloadPromise](#Datastore+autoloadPromise) : <code>Promise</code> * [.autoloadPromise](#Datastore+autoloadPromise) : <code>Promise</code>
* [.compareStrings()](#Datastore+compareStrings) : [<code>compareStrings</code>](#compareStrings)
* [.loadDatabase(callback)](#Datastore+loadDatabase) * [.loadDatabase(callback)](#Datastore+loadDatabase)
* [.loadDatabaseAsync()](#Datastore+loadDatabaseAsync) ⇒ <code>Promise</code> * [.loadDatabaseAsync()](#Datastore+loadDatabaseAsync) ⇒ <code>Promise</code>
* [.getAllData()](#Datastore+getAllData) ⇒ [<code>Array.&lt;document&gt;</code>](#document) * [.getAllData()](#Datastore+getAllData) ⇒ [<code>Array.&lt;document&gt;</code>](#document)
* [.resetIndexes()](#Datastore+resetIndexes) * [.resetIndexes(newData)](#Datastore+resetIndexes)
* [.ensureIndex(options, callback)](#Datastore+ensureIndex) * [.ensureIndex(options, callback)](#Datastore+ensureIndex)
* [.ensureIndexAsync(options)](#Datastore+ensureIndexAsync) ⇒ <code>Promise.&lt;void&gt;</code> * [.ensureIndexAsync(options)](#Datastore+ensureIndexAsync) ⇒ <code>Promise.&lt;void&gt;</code>
* [.removeIndex(fieldName, callback)](#Datastore+removeIndex) * [.removeIndex(fieldName, callback)](#Datastore+removeIndex)
* [.removeIndexAsync(fieldName)](#Datastore+removeIndexAsync) ⇒ <code>Promise.&lt;void&gt;</code> * [.removeIndexAsync(fieldName)](#Datastore+removeIndexAsync) ⇒ <code>Promise.&lt;void&gt;</code>
* [.addToIndexes(doc)](#Datastore+addToIndexes)
* [.removeFromIndexes(doc)](#Datastore+removeFromIndexes) * [.removeFromIndexes(doc)](#Datastore+removeFromIndexes)
* [.updateIndexes(oldDoc, [newDoc])](#Datastore+updateIndexes) * [.updateIndexes(oldDoc, [newDoc])](#Datastore+updateIndexes)
* [.getCandidates(query, [dontExpireStaleDocs], callback)](#Datastore+getCandidates)
* [.getCandidatesAsync(query, [dontExpireStaleDocs])](#Datastore+getCandidatesAsync) ⇒ <code>Promise.&lt;Array.&lt;document&gt;&gt;</code>
* [.insertAsync(newDoc)](#Datastore+insertAsync) ⇒ [<code>Promise.&lt;document&gt;</code>](#document) * [.insertAsync(newDoc)](#Datastore+insertAsync) ⇒ [<code>Promise.&lt;document&gt;</code>](#document)
* [.count(query, [callback])](#Datastore+count) ⇒ <code>Cursor.&lt;number&gt;</code> \| <code>undefined</code> * [.count(query, [callback])](#Datastore+count) ⇒ <code>Cursor.&lt;number&gt;</code> \| <code>undefined</code>
* [.countAsync(query)](#Datastore+countAsync) ⇒ <code>Cursor.&lt;number&gt;</code> * [.countAsync(query)](#Datastore+countAsync) ⇒ <code>Cursor.&lt;number&gt;</code>
* [.find(query, [projection], [callback])](#Datastore+find) ⇒ <code>Cursor.&lt;Array.&lt;document&gt;&gt;</code> \| <code>undefined</code> * [.find(query, [projection], [callback])](#Datastore+find) ⇒ <code>Cursor.&lt;Array.&lt;document&gt;&gt;</code> \| <code>undefined</code>
* [.findAsync(query, [projection])](#Datastore+findAsync) ⇒ <code>Cursor.&lt;Array.&lt;document&gt;&gt;</code> * [.findAsync(query, [projection])](#Datastore+findAsync) ⇒ <code>Cursor.&lt;Array.&lt;document&gt;&gt;</code>
* [.findOne(query, projection, callback)](#Datastore+findOne) ⇒ [<code>Cursor.&lt;document&gt;</code>](#document) \| <code>undefined</code> * [.findOne(query, [projection], [callback])](#Datastore+findOne) ⇒ [<code>Cursor.&lt;document&gt;</code>](#document) \| <code>undefined</code>
* [.findOneAsync(query, projection)](#Datastore+findOneAsync) ⇒ [<code>Cursor.&lt;document&gt;</code>](#document) * [.findOneAsync(query, projection)](#Datastore+findOneAsync) ⇒ [<code>Cursor.&lt;document&gt;</code>](#document)
* [.update(query, update, [options], [cb])](#Datastore+update) * [.update(query, update, [options|], [cb])](#Datastore+update)
* [.updateAsync(query, update, [options])](#Datastore+updateAsync) ⇒ <code>Promise.&lt;{numAffected: number, affectedDocuments: (Array.&lt;document&gt;\|document\|null), upsert: boolean}&gt;</code> * [.updateAsync(query, update, [options])](#Datastore+updateAsync) ⇒ <code>Promise.&lt;{numAffected: number, affectedDocuments: (Array.&lt;document&gt;\|document\|null), upsert: boolean}&gt;</code>
* [.remove(query, [options], [cb])](#Datastore+remove) * [.remove(query, [options], [cb])](#Datastore+remove)
* [.removeAsync(query, [options])](#Datastore+removeAsync) ⇒ <code>Promise.&lt;number&gt;</code> * [.removeAsync(query, [options])](#Datastore+removeAsync) ⇒ <code>Promise.&lt;number&gt;</code>
* _static_ * ["event:compaction.done"](#Datastore+event_compaction.done)
* ["event:compaction.done"](#Datastore.event_compaction.done)
* _inner_ * _inner_
* [~countCallback](#Datastore..countCallback) : <code>function</code> * [~countCallback](#Datastore..countCallback) : <code>function</code>
* [~findOneCallback](#Datastore..findOneCallback) : <code>function</code> * [~findOneCallback](#Datastore..findOneCallback) : <code>function</code>
@ -51,21 +60,76 @@ function fetches the data from datafile and prepares the database. <strong>Don't
datastore, no command (insert, find, update, remove) will be executed before <code>loadDatabase</code> is called, so make sure datastore, no command (insert, find, update, remove) will be executed before <code>loadDatabase</code> is called, so make sure
to call it yourself or use the <code>autoload</code> option.</p> to call it yourself or use the <code>autoload</code> option.</p>
**Params**
- options <code>object</code> | <code>string</code> - <p>Can be an object or a string. If options is a string, the behavior is the same as in
v0.6: it will be interpreted as <code>options.filename</code>. <strong>Giving a string is deprecated, and will be removed in the
next major version.</strong></p>
- [.filename] <code>string</code> <code> = null</code> - <p>Path to the file where the data is persisted. If left blank, the datastore is
automatically considered in-memory only. It cannot end with a <code>~</code> which is used in the temporary files NeDB uses to
perform crash-safe writes.</p>
- [.inMemoryOnly] <code>boolean</code> <code> = false</code> - <p>If set to true, no data will be written in storage.</p>
- [.timestampData] <code>boolean</code> <code> = false</code> - <p>If set to true, createdAt and updatedAt will be created and
populated automatically (if not specified by user)</p>
- [.autoload] <code>boolean</code> <code> = false</code> - <p>If used, the database will automatically be loaded from the datafile
upon creation (you don't need to call <code>loadDatabase</code>). Any command issued before load is finished is buffered and
will be executed when load is done. When autoloading is done, you can either use the <code>onload</code> callback, or you can
use <code>this.autoloadPromise</code> which resolves (or rejects) when autloading is done.</p>
- [.onload] <code>function</code> - <p>If you use autoloading, this is the handler called after the <code>loadDatabase</code>. It
takes one <code>error</code> argument. If you use autoloading without specifying this handler, and an error happens during
load, an error will be thrown.</p>
- [.beforeDeserialization] <code>function</code> - <p>Hook you can use to transform data after it was serialized and
before it is written to disk. Can be used for example to encrypt data before writing database to disk. This
function takes a string as parameter (one line of an NeDB data file) and outputs the transformed string, <strong>which
must absolutely not contain a <code>\n</code> character</strong> (or data will be lost).</p>
- [.afterSerialization] <code>function</code> - <p>Inverse of <code>afterSerialization</code>. Make sure to include both and not
just one, or you risk data loss. For the same reason, make sure both functions are inverses of one another. Some
failsafe mechanisms are in place to prevent data loss if you misuse the serialization hooks: NeDB checks that never
one is declared without the other, and checks that they are reverse of one another by testing on random strings of
various lengths. In addition, if too much data is detected as corrupt, NeDB will refuse to start as it could mean
you're not using the deserialization hook corresponding to the serialization hook used before.</p>
- [.corruptAlertThreshold] <code>number</code> <code> = 0.1</code> - <p>Between 0 and 1, defaults to 10%. NeDB will refuse to start
if more than this percentage of the datafile is corrupt. 0 means you don't tolerate any corruption, 1 means you
don't care.</p>
- [.compareStrings] [<code>compareStrings</code>](#compareStrings) - <p>If specified, it overrides default string comparison which is not
well adapted to non-US characters in particular accented letters. Native <code>localCompare</code> will most of the time be
the right choice.</p>
- [.nodeWebkitAppName] <code>string</code> - <p><strong>Deprecated:</strong> if you are using NeDB from whithin a Node Webkit app,
specify its name (the same one you use in the <code>package.json</code>) in this field and the <code>filename</code> will be relative to
the directory Node Webkit uses to store the rest of the application's data (local storage etc.). It works on Linux,
OS X and Windows. Now that you can use <code>require('nw.gui').App.dataPath</code> in Node Webkit to get the path to the data
directory for your application, you should not use this option anymore and it will be removed.</p>
<a name="Datastore+inMemoryOnly"></a>
### datastore.inMemoryOnly : <code>boolean</code>
<p>Determines if the <code>Datastore</code> keeps data in-memory, or if it saves it in storage. Is not read after
instanciation.</p>
| Param | Type | Default | Description | **Kind**: instance property of [<code>Datastore</code>](#Datastore)
| --- | --- | --- | --- | **Access**: protected
| options | <code>object</code> \| <code>string</code> | | <p>Can be an object or a string. If options is a string, the behavior is the same as in v0.6: it will be interpreted as <code>options.filename</code>. <strong>Giving a string is deprecated, and will be removed in the next major version.</strong></p> | <a name="Datastore+autoload"></a>
| [options.filename] | <code>string</code> | <code>null</code> | <p>Path to the file where the data is persisted. If left blank, the datastore is automatically considered in-memory only. It cannot end with a <code>~</code> which is used in the temporary files NeDB uses to perform crash-safe writes.</p> |
| [options.inMemoryOnly] | <code>boolean</code> | <code>false</code> | <p>If set to true, no data will be written in storage.</p> | ### datastore.autoload : <code>boolean</code>
| [options.timestampData] | <code>boolean</code> | <code>false</code> | <p>If set to true, createdAt and updatedAt will be created and populated automatically (if not specified by user)</p> | <p>Determines if the <code>Datastore</code> should autoload the database upon instantiation. Is not read after instanciation.</p>
| [options.autoload] | <code>boolean</code> | <code>false</code> | <p>If used, the database will automatically be loaded from the datafile upon creation (you don't need to call <code>loadDatabase</code>). Any command issued before load is finished is buffered and will be executed when load is done. When autoloading is done, you can either use the <code>onload</code> callback, or you can use <code>this.autoloadPromise</code> which resolves (or rejects) when autloading is done.</p> |
| [options.onload] | <code>function</code> | | <p>If you use autoloading, this is the handler called after the <code>loadDatabase</code>. It takes one <code>error</code> argument. If you use autoloading without specifying this handler, and an error happens during load, an error will be thrown.</p> | **Kind**: instance property of [<code>Datastore</code>](#Datastore)
| [options.beforeDeserialization] | <code>function</code> | | <p>Hook you can use to transform data after it was serialized and before it is written to disk. Can be used for example to encrypt data before writing database to disk. This function takes a string as parameter (one line of an NeDB data file) and outputs the transformed string, <strong>which must absolutely not contain a <code>\n</code> character</strong> (or data will be lost).</p> | **Access**: protected
| [options.afterSerialization] | <code>function</code> | | <p>Inverse of <code>afterSerialization</code>. Make sure to include both and not just one, or you risk data loss. For the same reason, make sure both functions are inverses of one another. Some failsafe mechanisms are in place to prevent data loss if you misuse the serialization hooks: NeDB checks that never one is declared without the other, and checks that they are reverse of one another by testing on random strings of various lengths. In addition, if too much data is detected as corrupt, NeDB will refuse to start as it could mean you're not using the deserialization hook corresponding to the serialization hook used before.</p> | <a name="Datastore+timestampData"></a>
| [options.corruptAlertThreshold] | <code>number</code> | <code>0.1</code> | <p>Between 0 and 1, defaults to 10%. NeDB will refuse to start if more than this percentage of the datafile is corrupt. 0 means you don't tolerate any corruption, 1 means you don't care.</p> |
| [options.compareStrings] | [<code>compareStrings</code>](#compareStrings) | | <p>If specified, it overrides default string comparison which is not well adapted to non-US characters in particular accented letters. Native <code>localCompare</code> will most of the time be the right choice.</p> | ### datastore.timestampData : <code>boolean</code>
| [options.nodeWebkitAppName] | <code>string</code> | | <p><strong>Deprecated:</strong> if you are using NeDB from whithin a Node Webkit app, specify its name (the same one you use in the <code>package.json</code>) in this field and the <code>filename</code> will be relative to the directory Node Webkit uses to store the rest of the application's data (local storage etc.). It works on Linux, OS X and Windows. Now that you can use <code>require('nw.gui').App.dataPath</code> in Node Webkit to get the path to the data directory for your application, you should not use this option anymore and it will be removed.</p> | <p>Determines if the <code>Datastore</code> should add <code>createdAt</code> and <code>updatedAt</code> fields automatically if not set by the user.</p>
**Kind**: instance property of [<code>Datastore</code>](#Datastore)
**Access**: protected
<a name="Datastore+filename"></a>
### datastore.filename : <code>string</code>
<p>If null, it means <code>inMemoryOnly</code> is <code>true</code>. The <code>filename</code> is the name given to the storage module. Is not read
after instanciation.</p>
**Kind**: instance property of [<code>Datastore</code>](#Datastore)
**Access**: protected
<a name="Datastore+persistence"></a> <a name="Datastore+persistence"></a>
### datastore.persistence : [<code>Persistence</code>](#Persistence) ### datastore.persistence : [<code>Persistence</code>](#Persistence)
@ -80,6 +144,23 @@ produced by the <code>Datastore</code> and by <code>this.persistence.compactData
to ensure operations are performed sequentially in the database.</p> to ensure operations are performed sequentially in the database.</p>
**Kind**: instance property of [<code>Datastore</code>](#Datastore) **Kind**: instance property of [<code>Datastore</code>](#Datastore)
**Access**: protected
<a name="Datastore+indexes"></a>
### datastore.indexes : <code>Object.&lt;string, Index&gt;</code>
<p>Indexed by field name, dot notation can be used.
_id is always indexed and since _ids are generated randomly the underlying binary search tree is always well-balanced</p>
**Kind**: instance property of [<code>Datastore</code>](#Datastore)
**Access**: protected
<a name="Datastore+ttlIndexes"></a>
### datastore.ttlIndexes : <code>Object.&lt;string, number&gt;</code>
<p>Stores the time to live (TTL) of the indexes created. The key represents the field name, the value the number of
seconds after which data with this index field should be removed.</p>
**Kind**: instance property of [<code>Datastore</code>](#Datastore)
**Access**: protected
<a name="Datastore+autoloadPromise"></a> <a name="Datastore+autoloadPromise"></a>
### datastore.autoloadPromise : <code>Promise</code> ### datastore.autoloadPromise : <code>Promise</code>
@ -87,35 +168,47 @@ to ensure operations are performed sequentially in the database.</p>
<p>The onload callback is not awaited by this Promise, it is started immediately after that.</p> <p>The onload callback is not awaited by this Promise, it is started immediately after that.</p>
**Kind**: instance property of [<code>Datastore</code>](#Datastore) **Kind**: instance property of [<code>Datastore</code>](#Datastore)
<a name="Datastore+compareStrings"></a>
### datastore.compareStrings() : [<code>compareStrings</code>](#compareStrings)
<p>Overrides default string comparison which is not well adapted to non-US characters in particular accented
letters. Native <code>localCompare</code> will most of the time be the right choice</p>
**Kind**: instance method of [<code>Datastore</code>](#Datastore)
**Access**: protected
<a name="Datastore+loadDatabase"></a> <a name="Datastore+loadDatabase"></a>
### datastore.loadDatabase(callback) ### datastore.loadDatabase(callback)
<p>Load the database from the datafile, and trigger the execution of buffered commands if any.</p> <p>Load the database from the datafile, and trigger the execution of buffered commands if any.</p>
**Kind**: instance method of [<code>Datastore</code>](#Datastore) **Kind**: instance method of [<code>Datastore</code>](#Datastore)
**Params**
| Param | Type | - callback <code>function</code>
| --- | --- |
| callback | <code>function</code> |
<a name="Datastore+loadDatabaseAsync"></a> <a name="Datastore+loadDatabaseAsync"></a>
### datastore.loadDatabaseAsync() ⇒ <code>Promise</code> ### datastore.loadDatabaseAsync() ⇒ <code>Promise</code>
<p>Load the database from the datafile, and trigger the execution of buffered commands if any.</p> <p>Async version of [loadDatabase](#Datastore+loadDatabase).</p>
**Kind**: instance method of [<code>Datastore</code>](#Datastore) **Kind**: instance method of [<code>Datastore</code>](#Datastore)
**See**: Datastore#loadDatabase
<a name="Datastore+getAllData"></a> <a name="Datastore+getAllData"></a>
### datastore.getAllData() ⇒ [<code>Array.&lt;document&gt;</code>](#document) ### datastore.getAllData() ⇒ [<code>Array.&lt;document&gt;</code>](#document)
<p>Get an array of all the data in the database</p> <p>Get an array of all the data in the database.</p>
**Kind**: instance method of [<code>Datastore</code>](#Datastore) **Kind**: instance method of [<code>Datastore</code>](#Datastore)
<a name="Datastore+resetIndexes"></a> <a name="Datastore+resetIndexes"></a>
### datastore.resetIndexes() ### datastore.resetIndexes(newData)
<p>Reset all currently defined indexes</p> <p>Reset all currently defined indexes.</p>
**Kind**: instance method of [<code>Datastore</code>](#Datastore) **Kind**: instance method of [<code>Datastore</code>](#Datastore)
**Params**
- newData [<code>document</code>](#document) | [<code>?Array.&lt;document&gt;</code>](#document)
<a name="Datastore+ensureIndex"></a> <a name="Datastore+ensureIndex"></a>
### datastore.ensureIndex(options, callback) ### datastore.ensureIndex(options, callback)
@ -125,33 +218,29 @@ executor.
Previous versions said explicitly the callback was optional, it is now recommended setting one.</p> Previous versions said explicitly the callback was optional, it is now recommended setting one.</p>
**Kind**: instance method of [<code>Datastore</code>](#Datastore) **Kind**: instance method of [<code>Datastore</code>](#Datastore)
**Params**
| Param | Type | Default | Description | - options <code>object</code>
| --- | --- | --- | --- | - .fieldName <code>string</code> - <p>Name of the field to index. Use the dot notation to index a field in a nested document.</p>
| options | <code>object</code> | | | - [.unique] <code>boolean</code> <code> = false</code> - <p>Enforce field uniqueness. Note that a unique index will raise an error if you try to index two documents for which the field is not defined.</p>
| options.fieldName | <code>string</code> | | <p>Name of the field to index. Use the dot notation to index a field in a nested document.</p> | - [.sparse] <code>boolean</code> <code> = false</code> - <p>don't index documents for which the field is not defined. Use this option along with &quot;unique&quot; if you want to accept multiple documents for which it is not defined.</p>
| [options.unique] | <code>boolean</code> | <code>false</code> | <p>Enforce field uniqueness. Note that a unique index will raise an error if you try to index two documents for which the field is not defined.</p> | - [.expireAfterSeconds] <code>number</code> - <p>if set, the created index is a TTL (time to live) index, that will automatically remove documents when the system date becomes larger than the date on the indexed field plus <code>expireAfterSeconds</code>. Documents where the indexed field is not specified or not a <code>Date</code> object are ignored</p>
| [options.sparse] | <code>boolean</code> | <code>false</code> | <p>don't index documents for which the field is not defined. Use this option along with &quot;unique&quot; if you want to accept multiple documents for which it is not defined.</p> | - callback [<code>NoParamCallback</code>](#NoParamCallback) - <p>Callback, signature: err</p>
| [options.expireAfterSeconds] | <code>number</code> | | <p>if set, the created index is a TTL (time to live) index, that will automatically remove documents when the system date becomes larger than the date on the indexed field plus <code>expireAfterSeconds</code>. Documents where the indexed field is not specified or not a <code>Date</code> object are ignored</p> |
| callback | [<code>NoParamCallback</code>](#NoParamCallback) | | <p>Callback, signature: err</p> |
<a name="Datastore+ensureIndexAsync"></a> <a name="Datastore+ensureIndexAsync"></a>
### datastore.ensureIndexAsync(options) ⇒ <code>Promise.&lt;void&gt;</code> ### datastore.ensureIndexAsync(options) ⇒ <code>Promise.&lt;void&gt;</code>
<p>Ensure an index is kept for this field. Same parameters as lib/indexes <p>Async version of [ensureIndex](#Datastore+ensureIndex).</p>
This function acts synchronously on the indexes, however the persistence of the indexes is deferred with the
executor.
Previous versions said explicitly the callback was optional, it is now recommended setting one.</p>
**Kind**: instance method of [<code>Datastore</code>](#Datastore) **Kind**: instance method of [<code>Datastore</code>](#Datastore)
**See**: Datastore#ensureIndex
**Params**
| Param | Type | Default | Description | - options <code>object</code>
| --- | --- | --- | --- | - .fieldName <code>string</code> - <p>Name of the field to index. Use the dot notation to index a field in a nested document.</p>
| options | <code>object</code> | | | - [.unique] <code>boolean</code> <code> = false</code> - <p>Enforce field uniqueness. Note that a unique index will raise an error if you try to index two documents for which the field is not defined.</p>
| options.fieldName | <code>string</code> | | <p>Name of the field to index. Use the dot notation to index a field in a nested document.</p> | - [.sparse] <code>boolean</code> <code> = false</code> - <p>Don't index documents for which the field is not defined. Use this option along with &quot;unique&quot; if you want to accept multiple documents for which it is not defined.</p>
| [options.unique] | <code>boolean</code> | <code>false</code> | <p>Enforce field uniqueness. Note that a unique index will raise an error if you try to index two documents for which the field is not defined.</p> | - [.expireAfterSeconds] <code>number</code> - <p>If set, the created index is a TTL (time to live) index, that will automatically remove documents when the system date becomes larger than the date on the indexed field plus <code>expireAfterSeconds</code>. Documents where the indexed field is not specified or not a <code>Date</code> object are ignored</p>
| [options.sparse] | <code>boolean</code> | <code>false</code> | <p>Don't index documents for which the field is not defined. Use this option along with &quot;unique&quot; if you want to accept multiple documents for which it is not defined.</p> |
| [options.expireAfterSeconds] | <code>number</code> | | <p>If set, the created index is a TTL (time to live) index, that will automatically remove documents when the system date becomes larger than the date on the indexed field plus <code>expireAfterSeconds</code>. Documents where the indexed field is not specified or not a <code>Date</code> object are ignored</p> |
<a name="Datastore+removeIndex"></a> <a name="Datastore+removeIndex"></a>
@ -160,84 +249,131 @@ Previous versions said explicitly the callback was optional, it is now recommend
Previous versions said explicitly the callback was optional, it is now recommended setting one.</p> Previous versions said explicitly the callback was optional, it is now recommended setting one.</p>
**Kind**: instance method of [<code>Datastore</code>](#Datastore) **Kind**: instance method of [<code>Datastore</code>](#Datastore)
**Params**
| Param | Type | Description | - fieldName <code>string</code> - <p>Field name of the index to remove. Use the dot notation to remove an index referring to a
| --- | --- | --- | field in a nested document.</p>
| fieldName | <code>string</code> | <p>Field name of the index to remove. Use the dot notation to remove an index referring to a field in a nested document.</p> | - callback [<code>NoParamCallback</code>](#NoParamCallback) - <p>Optional callback, signature: err</p>
| callback | [<code>NoParamCallback</code>](#NoParamCallback) | <p>Optional callback, signature: err</p> |
<a name="Datastore+removeIndexAsync"></a> <a name="Datastore+removeIndexAsync"></a>
### datastore.removeIndexAsync(fieldName) ⇒ <code>Promise.&lt;void&gt;</code> ### datastore.removeIndexAsync(fieldName) ⇒ <code>Promise.&lt;void&gt;</code>
<p>Remove an index <p>Async version of [removeIndex](#Datastore+removeIndex).</p>
Previous versions said explicitly the callback was optional, it is now recommended setting one.</p>
**Kind**: instance method of [<code>Datastore</code>](#Datastore)
**See**: Datastore#removeIndex
**Params**
- fieldName <code>string</code> - <p>Field name of the index to remove. Use the dot notation to remove an index referring to a
field in a nested document.</p>
<a name="Datastore+addToIndexes"></a>
### datastore.addToIndexes(doc)
<p>Add one or several document(s) to all indexes.</p>
<p>This is an internal function.</p>
**Kind**: instance method of [<code>Datastore</code>](#Datastore) **Kind**: instance method of [<code>Datastore</code>](#Datastore)
**Access**: protected
**Params**
| Param | Type | Description | - doc [<code>document</code>](#document)
| --- | --- | --- |
| fieldName | <code>string</code> | <p>Field name of the index to remove. Use the dot notation to remove an index referring to a field in a nested document.</p> |
<a name="Datastore+removeFromIndexes"></a> <a name="Datastore+removeFromIndexes"></a>
### datastore.removeFromIndexes(doc) ### datastore.removeFromIndexes(doc)
<p>Remove one or several document(s) from all indexes</p> <p>Remove one or several document(s) from all indexes.</p>
<p>This is an internal function.</p>
**Kind**: instance method of [<code>Datastore</code>](#Datastore) **Kind**: instance method of [<code>Datastore</code>](#Datastore)
**Access**: protected
**Params**
| Param | Type | - doc [<code>document</code>](#document)
| --- | --- |
| doc | [<code>document</code>](#document) |
<a name="Datastore+updateIndexes"></a> <a name="Datastore+updateIndexes"></a>
### datastore.updateIndexes(oldDoc, [newDoc]) ### datastore.updateIndexes(oldDoc, [newDoc])
<p>Update one or several documents in all indexes <p>Update one or several documents in all indexes.</p>
To update multiple documents, oldDoc must be an array of { oldDoc, newDoc } pairs <p>To update multiple documents, oldDoc must be an array of { oldDoc, newDoc } pairs.</p>
If one update violates a constraint, all changes are rolled back</p> <p>If one update violates a constraint, all changes are rolled back.</p>
<p>This is an internal function.</p>
**Kind**: instance method of [<code>Datastore</code>](#Datastore)
**Params**
- oldDoc [<code>document</code>](#document) | <code>Array.&lt;{oldDoc: document, newDoc: document}&gt;</code> - <p>Document to update, or an <code>Array</code> of
<code>{oldDoc, newDoc}</code> pairs.</p>
- [newDoc] [<code>document</code>](#document) - <p>Document to replace the oldDoc with. If the first argument is an <code>Array</code> of
<code>{oldDoc, newDoc}</code> pairs, this second argument is ignored.</p>
<a name="Datastore+getCandidates"></a>
### datastore.getCandidates(query, [dontExpireStaleDocs], callback)
<p>Return the list of candidates for a given query
Crude implementation for now, we return the candidates given by the first usable index if any
We try the following query types, in this order: basic match, $in match, comparison match
One way to make it better would be to enable the use of multiple indexes if the first usable index
returns too much data. I may do it in the future.</p>
<p>Returned candidates will be scanned to find and remove all expired documents</p>
<p>This is an internal function.</p>
**Kind**: instance method of [<code>Datastore</code>](#Datastore) **Kind**: instance method of [<code>Datastore</code>](#Datastore)
**Access**: protected
**Params**
| Param | Type | Description | - query [<code>query</code>](#query)
| --- | --- | --- | - [dontExpireStaleDocs] <code>boolean</code> | <code>function</code> <code> = false</code> - <p>If true don't remove stale docs. Useful for the remove
| oldDoc | [<code>document</code>](#document) \| <code>Array.&lt;{oldDoc: document, newDoc: document}&gt;</code> | <p>Document to update, or an <code>Array</code> of <code>{oldDoc, newDoc}</code> pairs.</p> | function which shouldn't be impacted by expirations. If argument is not given, it is used as the callback.</p>
| [newDoc] | [<code>document</code>](#document) | <p>Document to replace the oldDoc with. If the first argument is an <code>Array</code> of <code>{oldDoc, newDoc}</code> pairs, this second argument is ignored.</p> | - callback [<code>MultipleDocumentsCallback</code>](#MultipleDocumentsCallback) - <p>Signature err, candidates</p>
<a name="Datastore+getCandidatesAsync"></a>
### datastore.getCandidatesAsync(query, [dontExpireStaleDocs]) ⇒ <code>Promise.&lt;Array.&lt;document&gt;&gt;</code>
<p>Async version of [getCandidates](#Datastore+getCandidates).</p>
<p>This is an internal function.</p>
**Kind**: instance method of [<code>Datastore</code>](#Datastore)
**Returns**: <code>Promise.&lt;Array.&lt;document&gt;&gt;</code> - <p>candidates</p>
**Access**: protected
**See**: Datastore#getCandidates
**Params**
- query [<code>query</code>](#query)
- [dontExpireStaleDocs] <code>boolean</code> <code> = false</code> - <p>If true don't remove stale docs. Useful for the remove function
which shouldn't be impacted by expirations.</p>
<a name="Datastore+insertAsync"></a> <a name="Datastore+insertAsync"></a>
### datastore.insertAsync(newDoc) ⇒ [<code>Promise.&lt;document&gt;</code>](#document) ### datastore.insertAsync(newDoc) ⇒ [<code>Promise.&lt;document&gt;</code>](#document)
<p>Insert a new document <p>Async version of [Datastore#insert](Datastore#insert).</p>
Private Use Datastore.insertAsync which has the same signature</p>
**Kind**: instance method of [<code>Datastore</code>](#Datastore) **Kind**: instance method of [<code>Datastore</code>](#Datastore)
**Params**
| Param | Type | - newDoc [<code>document</code>](#document) | [<code>Array.&lt;document&gt;</code>](#document)
| --- | --- |
| newDoc | [<code>document</code>](#document) \| [<code>Array.&lt;document&gt;</code>](#document) |
<a name="Datastore+count"></a> <a name="Datastore+count"></a>
### datastore.count(query, [callback]) ⇒ <code>Cursor.&lt;number&gt;</code> \| <code>undefined</code> ### datastore.count(query, [callback]) ⇒ <code>Cursor.&lt;number&gt;</code> \| <code>undefined</code>
<p>Count all documents matching the query</p> <p>Count all documents matching the query.</p>
**Kind**: instance method of [<code>Datastore</code>](#Datastore) **Kind**: instance method of [<code>Datastore</code>](#Datastore)
**Params**
| Param | Type | Description | - query [<code>query</code>](#query) - <p>MongoDB-style query</p>
| --- | --- | --- | - [callback] [<code>countCallback</code>](#Datastore..countCallback) - <p>If given, the function will return undefined, otherwise it will return the Cursor.</p>
| query | [<code>query</code>](#query) | <p>MongoDB-style query</p> |
| [callback] | [<code>countCallback</code>](#Datastore..countCallback) | <p>If given, the function will return undefined, otherwise it will return the Cursor.</p> |
<a name="Datastore+countAsync"></a> <a name="Datastore+countAsync"></a>
### datastore.countAsync(query) ⇒ <code>Cursor.&lt;number&gt;</code> ### datastore.countAsync(query) ⇒ <code>Cursor.&lt;number&gt;</code>
<p>Count all documents matching the query</p> <p>Async version of [count](#Datastore+count).</p>
**Kind**: instance method of [<code>Datastore</code>](#Datastore) **Kind**: instance method of [<code>Datastore</code>](#Datastore)
**Returns**: <code>Cursor.&lt;number&gt;</code> - <p>count</p> **Returns**: <code>Cursor.&lt;number&gt;</code> - <p>count</p>
**Params**
| Param | Type | Description | - query [<code>query</code>](#query) - <p>MongoDB-style query</p>
| --- | --- | --- |
| query | [<code>query</code>](#query) | <p>MongoDB-style query</p> |
<a name="Datastore+find"></a> <a name="Datastore+find"></a>
@ -246,83 +382,105 @@ Private Use Datastore.insertAsync which has the same signature</p>
If no callback is passed, we return the cursor so that user can limit, skip and finally exec</p> If no callback is passed, we return the cursor so that user can limit, skip and finally exec</p>
**Kind**: instance method of [<code>Datastore</code>](#Datastore) **Kind**: instance method of [<code>Datastore</code>](#Datastore)
**Params**
| Param | Type | Default | Description | - query [<code>query</code>](#query) - <p>MongoDB-style query</p>
| --- | --- | --- | --- | - [projection] [<code>projection</code>](#projection) | [<code>MultipleDocumentsCallback</code>](#MultipleDocumentsCallback) <code> = {}</code> - <p>MongoDB-style projection. If not given, will be
| query | [<code>query</code>](#query) | | <p>MongoDB-style query</p> | interpreted as the callback.</p>
| [projection] | [<code>projection</code>](#projection) \| [<code>MultipleDocumentsCallback</code>](#MultipleDocumentsCallback) | <code>{}</code> | <p>MongoDB-style projection. If not given, will be interpreted as the callback.</p> | - [callback] [<code>MultipleDocumentsCallback</code>](#MultipleDocumentsCallback) - <p>Optional callback, signature: err, docs</p>
| [callback] | [<code>MultipleDocumentsCallback</code>](#MultipleDocumentsCallback) | | <p>Optional callback, signature: err, docs</p> |
<a name="Datastore+findAsync"></a> <a name="Datastore+findAsync"></a>
### datastore.findAsync(query, [projection]) ⇒ <code>Cursor.&lt;Array.&lt;document&gt;&gt;</code> ### datastore.findAsync(query, [projection]) ⇒ <code>Cursor.&lt;Array.&lt;document&gt;&gt;</code>
<p>Find all documents matching the query <p>Async version of [find](#Datastore+find).</p>
If no callback is passed, we return the cursor so that user can limit, skip and finally exec</p>
**Kind**: instance method of [<code>Datastore</code>](#Datastore) **Kind**: instance method of [<code>Datastore</code>](#Datastore)
**Params**
| Param | Type | Default | Description | - query [<code>query</code>](#query) - <p>MongoDB-style query</p>
| --- | --- | --- | --- | - [projection] [<code>projection</code>](#projection) <code> = {}</code> - <p>MongoDB-style projection</p>
| query | [<code>query</code>](#query) | | <p>MongoDB-style query</p> |
| [projection] | [<code>projection</code>](#projection) | <code>{}</code> | <p>MongoDB-style projection</p> |
<a name="Datastore+findOne"></a> <a name="Datastore+findOne"></a>
### datastore.findOne(query, projection, callback) ⇒ [<code>Cursor.&lt;document&gt;</code>](#document) \| <code>undefined</code> ### datastore.findOne(query, [projection], [callback]) ⇒ [<code>Cursor.&lt;document&gt;</code>](#document) \| <code>undefined</code>
<p>Find one document matching the query</p> <p>Find one document matching the query.</p>
**Kind**: instance method of [<code>Datastore</code>](#Datastore) **Kind**: instance method of [<code>Datastore</code>](#Datastore)
**Params**
| Param | Type | Description | - query [<code>query</code>](#query) - <p>MongoDB-style query</p>
| --- | --- | --- | - [projection] [<code>projection</code>](#projection) | [<code>SingleDocumentCallback</code>](#SingleDocumentCallback) <code> = {}</code> - <p>MongoDB-style projection</p>
| query | [<code>query</code>](#query) | <p>MongoDB-style query</p> | - [callback] [<code>SingleDocumentCallback</code>](#SingleDocumentCallback) - <p>Optional callback, signature: err, doc</p>
| projection | [<code>projection</code>](#projection) | <p>MongoDB-style projection</p> |
| callback | [<code>SingleDocumentCallback</code>](#SingleDocumentCallback) | <p>Optional callback, signature: err, doc</p> |
<a name="Datastore+findOneAsync"></a> <a name="Datastore+findOneAsync"></a>
### datastore.findOneAsync(query, projection) ⇒ [<code>Cursor.&lt;document&gt;</code>](#document) ### datastore.findOneAsync(query, projection) ⇒ [<code>Cursor.&lt;document&gt;</code>](#document)
<p>Find one document matching the query</p> <p>Async version of [findOne](#Datastore+findOne).</p>
**Kind**: instance method of [<code>Datastore</code>](#Datastore) **Kind**: instance method of [<code>Datastore</code>](#Datastore)
**See**: Datastore#findOne
**Params**
| Param | Type | Description | - query [<code>query</code>](#query) - <p>MongoDB-style query</p>
| --- | --- | --- | - projection [<code>projection</code>](#projection) - <p>MongoDB-style projection</p>
| query | [<code>query</code>](#query) | <p>MongoDB-style query</p> |
| projection | [<code>projection</code>](#projection) | <p>MongoDB-style projection</p> |
<a name="Datastore+update"></a> <a name="Datastore+update"></a>
### datastore.update(query, update, [options], [cb]) ### datastore.update(query, update, [options|], [cb])
<p>Update all docs matching query.</p> <p>Update all docs matching query.</p>
**Kind**: instance method of [<code>Datastore</code>](#Datastore) **Kind**: instance method of [<code>Datastore</code>](#Datastore)
**Params**
| Param | Type | Default | Description | - query [<code>query</code>](#query) - <p>is the same kind of finding query you use with <code>find</code> and <code>findOne</code></p>
| --- | --- | --- | --- | - update [<code>document</code>](#document) | <code>\*</code> - <p>specifies how the documents should be modified. It is either a new document or a
| query | [<code>query</code>](#query) | | <p>is the same kind of finding query you use with <code>find</code> and <code>findOne</code></p> | set of modifiers (you cannot use both together, it doesn't make sense!):</p>
| update | [<code>document</code>](#document) \| <code>update</code> | | <p>specifies how the documents should be modified. It is either a new document or a set of modifiers (you cannot use both together, it doesn't make sense!):</p> <ul> <li>A new document will replace the matched docs</li> <li>The modifiers create the fields they need to modify if they don't exist, and you can apply them to subdocs. Available field modifiers are <code>$set</code> to change a field's value, <code>$unset</code> to delete a field, <code>$inc</code> to increment a field's value and <code>$min</code>/<code>$max</code> to change field's value, only if provided value is less/greater than current value. To work on arrays, you have <code>$push</code>, <code>$pop</code>, <code>$addToSet</code>, <code>$pull</code>, and the special <code>$each</code> and <code>$slice</code>.</li> </ul> | <ul>
| [options] | <code>Object</code> | | <p>Optional options</p> | <li>A new document will replace the matched docs</li>
| [options.multi] | <code>boolean</code> | <code>false</code> | <p>If true, can update multiple documents</p> | <li>The modifiers create the fields they need to modify if they don't exist, and you can apply them to subdocs.
| [options.upsert] | <code>boolean</code> | <code>false</code> | <p>If true, can insert a new document corresponding to the <code>update</code> rules if your <code>query</code> doesn't match anything. If your <code>update</code> is a simple object with no modifiers, it is the inserted document. In the other case, the <code>query</code> is stripped from all operator recursively, and the <code>update</code> is applied to it.</p> | Available field modifiers are <code>$set</code> to change a field's value, <code>$unset</code> to delete a field, <code>$inc</code> to increment a
| [options.returnUpdatedDocs] | <code>boolean</code> | <code>false</code> | <p>(not Mongo-DB compatible) If true and update is not an upsert, will return the array of documents matched by the find query and updated. Updated documents will be returned even if the update did not actually modify them.</p> | field's value and <code>$min</code>/<code>$max</code> to change field's value, only if provided value is less/greater than current
| [cb] | [<code>updateCallback</code>](#Datastore..updateCallback) | <code>() &#x3D;&gt; {}</code> | <p>Optional callback</p> | value. To work on arrays, you have <code>$push</code>, <code>$pop</code>, <code>$addToSet</code>, <code>$pull</code>, and the special <code>$each</code> and <code>$slice</code>.</li>
</ul>
- [options|] <code>Object</code> | [<code>updateCallback</code>](#Datastore..updateCallback) - <p>Optional options</p>
- [.multi] <code>boolean</code> <code> = false</code> - <p>If true, can update multiple documents</p>
- [.upsert] <code>boolean</code> <code> = false</code> - <p>If true, can insert a new document corresponding to the <code>update</code> rules if
your <code>query</code> doesn't match anything. If your <code>update</code> is a simple object with no modifiers, it is the inserted
document. In the other case, the <code>query</code> is stripped from all operator recursively, and the <code>update</code> is applied to
it.</p>
- [.returnUpdatedDocs] <code>boolean</code> <code> = false</code> - <p>(not Mongo-DB compatible) If true and update is not an upsert,
will return the array of documents matched by the find query and updated. Updated documents will be returned even
if the update did not actually modify them.</p>
- [cb] [<code>updateCallback</code>](#Datastore..updateCallback) <code> = () &#x3D;&gt; {}</code> - <p>Optional callback</p>
<a name="Datastore+updateAsync"></a> <a name="Datastore+updateAsync"></a>
### datastore.updateAsync(query, update, [options]) ⇒ <code>Promise.&lt;{numAffected: number, affectedDocuments: (Array.&lt;document&gt;\|document\|null), upsert: boolean}&gt;</code> ### datastore.updateAsync(query, update, [options]) ⇒ <code>Promise.&lt;{numAffected: number, affectedDocuments: (Array.&lt;document&gt;\|document\|null), upsert: boolean}&gt;</code>
<p>Update all docs matching query.</p> <p>Async version of [update](#Datastore+update).</p>
**Kind**: instance method of [<code>Datastore</code>](#Datastore) **Kind**: instance method of [<code>Datastore</code>](#Datastore)
**See**: Datastore#update
**Params**
| Param | Type | Default | Description | - query [<code>query</code>](#query) - <p>is the same kind of finding query you use with <code>find</code> and <code>findOne</code></p>
| --- | --- | --- | --- | - update [<code>document</code>](#document) | <code>\*</code> - <p>specifies how the documents should be modified. It is either a new document or a
| query | [<code>query</code>](#query) | | <p>is the same kind of finding query you use with <code>find</code> and <code>findOne</code></p> | set of modifiers (you cannot use both together, it doesn't make sense!):</p>
| update | [<code>document</code>](#document) \| <code>update</code> | | <p>specifies how the documents should be modified. It is either a new document or a set of modifiers (you cannot use both together, it doesn't make sense!):</p> <ul> <li>A new document will replace the matched docs</li> <li>The modifiers create the fields they need to modify if they don't exist, and you can apply them to subdocs. Available field modifiers are <code>$set</code> to change a field's value, <code>$unset</code> to delete a field, <code>$inc</code> to increment a field's value and <code>$min</code>/<code>$max</code> to change field's value, only if provided value is less/greater than current value. To work on arrays, you have <code>$push</code>, <code>$pop</code>, <code>$addToSet</code>, <code>$pull</code>, and the special <code>$each</code> and <code>$slice</code>.</li> </ul> | <ul>
| [options] | <code>Object</code> | | <p>Optional options</p> | <li>A new document will replace the matched docs</li>
| [options.multi] | <code>boolean</code> | <code>false</code> | <p>If true, can update multiple documents</p> | <li>The modifiers create the fields they need to modify if they don't exist, and you can apply them to subdocs.
| [options.upsert] | <code>boolean</code> | <code>false</code> | <p>If true, can insert a new document corresponding to the <code>update</code> rules if your <code>query</code> doesn't match anything. If your <code>update</code> is a simple object with no modifiers, it is the inserted document. In the other case, the <code>query</code> is stripped from all operator recursively, and the <code>update</code> is applied to it.</p> | Available field modifiers are <code>$set</code> to change a field's value, <code>$unset</code> to delete a field, <code>$inc</code> to increment a
| [options.returnUpdatedDocs] | <code>boolean</code> | <code>false</code> | <p>(not Mongo-DB compatible) If true and update is not an upsert, will return the array of documents matched by the find query and updated. Updated documents will be returned even if the update did not actually modify them.</p> | field's value and <code>$min</code>/<code>$max</code> to change field's value, only if provided value is less/greater than current
value. To work on arrays, you have <code>$push</code>, <code>$pop</code>, <code>$addToSet</code>, <code>$pull</code>, and the special <code>$each</code> and <code>$slice</code>.</li>
</ul>
- [options] <code>Object</code> <code> = {}</code> - <p>Optional options</p>
- [.multi] <code>boolean</code> <code> = false</code> - <p>If true, can update multiple documents</p>
- [.upsert] <code>boolean</code> <code> = false</code> - <p>If true, can insert a new document corresponding to the <code>update</code> rules if
your <code>query</code> doesn't match anything. If your <code>update</code> is a simple object with no modifiers, it is the inserted
document. In the other case, the <code>query</code> is stripped from all operator recursively, and the <code>update</code> is applied to
it.</p>
- [.returnUpdatedDocs] <code>boolean</code> <code> = false</code> - <p>(not Mongo-DB compatible) If true and update is not an upsert,
will return the array of documents matched by the find query and updated. Updated documents will be returned even
if the update did not actually modify them.</p>
<a name="Datastore+remove"></a> <a name="Datastore+remove"></a>
@ -330,13 +488,12 @@ If no callback is passed, we return the cursor so that user can limit, skip and
<p>Remove all docs matching the query.</p> <p>Remove all docs matching the query.</p>
**Kind**: instance method of [<code>Datastore</code>](#Datastore) **Kind**: instance method of [<code>Datastore</code>](#Datastore)
**Params**
| Param | Type | Default | Description | - query [<code>query</code>](#query)
| --- | --- | --- | --- | - [options] <code>object</code> | [<code>removeCallback</code>](#Datastore..removeCallback) <code> = {}</code> - <p>Optional options</p>
| query | [<code>query</code>](#query) | | | - [.multi] <code>boolean</code> <code> = false</code> - <p>If true, can update multiple documents</p>
| [options] | <code>object</code> | | <p>Optional options</p> | - [cb] [<code>removeCallback</code>](#Datastore..removeCallback) <code> = () &#x3D;&gt; {}</code> - <p>Optional callback</p>
| [options.multi] | <code>boolean</code> | <code>false</code> | <p>If true, can update multiple documents</p> |
| [cb] | [<code>removeCallback</code>](#Datastore..removeCallback) | <code>() &#x3D;&gt; {}</code> | <p>Optional callback, signature: err, numRemoved</p> |
<a name="Datastore+removeAsync"></a> <a name="Datastore+removeAsync"></a>
@ -346,14 +503,13 @@ Use Datastore.removeAsync which has the same signature</p>
**Kind**: instance method of [<code>Datastore</code>](#Datastore) **Kind**: instance method of [<code>Datastore</code>](#Datastore)
**Returns**: <code>Promise.&lt;number&gt;</code> - <p>How many documents were removed</p> **Returns**: <code>Promise.&lt;number&gt;</code> - <p>How many documents were removed</p>
**Params**
| Param | Type | Default | Description | - query [<code>query</code>](#query)
| --- | --- | --- | --- | - [options] <code>object</code> <code> = {}</code> - <p>Optional options</p>
| query | [<code>query</code>](#query) | | | - [.multi] <code>boolean</code> <code> = false</code> - <p>If true, can update multiple documents</p>
| [options] | <code>object</code> | | <p>Optional options</p> |
| [options.multi] | <code>boolean</code> | <code>false</code> | <p>If true, can update multiple documents</p> |
<a name="Datastore.event_compaction.done"></a> <a name="Datastore+event_compaction.done"></a>
### "event:compaction.done" ### "event:compaction.done"
<p>Compaction event. Happens when the Datastore's Persistence has been compacted. <p>Compaction event. Happens when the Datastore's Persistence has been compacted.
@ -365,21 +521,19 @@ It happens when calling <code>datastore.persistence.compactDatafile</code>, whic
### Datastore~countCallback : <code>function</code> ### Datastore~countCallback : <code>function</code>
**Kind**: inner typedef of [<code>Datastore</code>](#Datastore) **Kind**: inner typedef of [<code>Datastore</code>](#Datastore)
**Params**
| Param | Type | - err <code>Error</code>
| --- | --- | - count <code>number</code>
| err | <code>Error</code> |
| count | <code>number</code> |
<a name="Datastore..findOneCallback"></a> <a name="Datastore..findOneCallback"></a>
### Datastore~findOneCallback : <code>function</code> ### Datastore~findOneCallback : <code>function</code>
**Kind**: inner typedef of [<code>Datastore</code>](#Datastore) **Kind**: inner typedef of [<code>Datastore</code>](#Datastore)
**Params**
| Param | Type | - err <code>Error</code>
| --- | --- | - doc [<code>document</code>](#document)
| err | <code>Error</code> |
| doc | [<code>document</code>](#document) |
<a name="Datastore..updateCallback"></a> <a name="Datastore..updateCallback"></a>
@ -400,21 +554,19 @@ or running another find query on the whole dataset to check its size. Both optio
was necessary.</p> was necessary.</p>
**Kind**: inner typedef of [<code>Datastore</code>](#Datastore) **Kind**: inner typedef of [<code>Datastore</code>](#Datastore)
**Params**
| Param | Type | - err <code>Error</code>
| --- | --- | - numAffected <code>number</code>
| err | <code>Error</code> | - affectedDocuments [<code>?Array.&lt;document&gt;</code>](#document) | [<code>document</code>](#document)
| numAffected | <code>number</code> | - upsert <code>boolean</code>
| affectedDocuments | [<code>?Array.&lt;document&gt;</code>](#document) \| [<code>document</code>](#document) |
| upsert | <code>boolean</code> |
<a name="Datastore..removeCallback"></a> <a name="Datastore..removeCallback"></a>
### Datastore~removeCallback : <code>function</code> ### Datastore~removeCallback : <code>function</code>
**Kind**: inner typedef of [<code>Datastore</code>](#Datastore) **Kind**: inner typedef of [<code>Datastore</code>](#Datastore)
**Params**
| Param | Type | - err <code>Error</code>
| --- | --- | - numRemoved <code>number</code>
| err | <code>Error</code> |
| numRemoved | <code>number</code> |

@ -8,10 +8,6 @@ Has an option for a buffer that can be triggered afterwards.</p>
* [Executor](#Executor) * [Executor](#Executor)
* [new Executor()](#new_Executor_new) * [new Executor()](#new_Executor_new)
* [.ready](#Executor+ready) : <code>boolean</code>
* [.queue](#Executor+queue) : [<code>Waterfall</code>](#Waterfall)
* [.buffer](#Executor+buffer) : [<code>Waterfall</code>](#Waterfall)
* [._triggerBuffer()](#Executor+_triggerBuffer)
* [.push(task, [forceQueuing])](#Executor+push) * [.push(task, [forceQueuing])](#Executor+push)
* [.pushAsync(task, [forceQueuing])](#Executor+pushAsync) ⇒ <code>Promise.&lt;\*&gt;</code> * [.pushAsync(task, [forceQueuing])](#Executor+pushAsync) ⇒ <code>Promise.&lt;\*&gt;</code>
* [.processBuffer()](#Executor+processBuffer) * [.processBuffer()](#Executor+processBuffer)
@ -21,35 +17,6 @@ Has an option for a buffer that can be triggered afterwards.</p>
### new Executor() ### new Executor()
<p>Instantiates a new Executor.</p> <p>Instantiates a new Executor.</p>
<a name="Executor+ready"></a>
### executor.ready : <code>boolean</code>
<p>If this.ready is <code>false</code>, then every task pushed will be buffered until this.processBuffer is called.</p>
**Kind**: instance property of [<code>Executor</code>](#Executor)
**Access**: protected
<a name="Executor+queue"></a>
### executor.queue : [<code>Waterfall</code>](#Waterfall)
<p>The main queue</p>
**Kind**: instance property of [<code>Executor</code>](#Executor)
**Access**: protected
<a name="Executor+buffer"></a>
### executor.buffer : [<code>Waterfall</code>](#Waterfall)
<p>The buffer queue</p>
**Kind**: instance property of [<code>Executor</code>](#Executor)
**Access**: protected
<a name="Executor+_triggerBuffer"></a>
### executor.\_triggerBuffer()
<p>Method to trigger the buffer processing.</p>
<p>Do not be use directly, use <code>this.processBuffer</code> instead.</p>
**Kind**: instance method of [<code>Executor</code>](#Executor)
**Access**: protected
<a name="Executor+push"></a> <a name="Executor+push"></a>
### executor.push(task, [forceQueuing]) ### executor.push(task, [forceQueuing])
@ -57,27 +24,29 @@ Has an option for a buffer that can be triggered afterwards.</p>
If not, buffer task for later processing</p> If not, buffer task for later processing</p>
**Kind**: instance method of [<code>Executor</code>](#Executor) **Kind**: instance method of [<code>Executor</code>](#Executor)
**Params**
| Param | Type | Default | Description | - task <code>Object</code>
| --- | --- | --- | --- | - .this <code>Object</code> - <p>Object to use as this</p>
| task | <code>Object</code> | | | - .fn <code>function</code> - <p>Function to execute</p>
| task.this | <code>Object</code> | | <p>Object to use as this</p> | - .arguments <code>Array</code> - <p>Array of arguments, IMPORTANT: only the last argument may be a function
| task.fn | <code>function</code> | | <p>Function to execute</p> | (the callback) and the last argument cannot be false/undefined/null</p>
| task.arguments | <code>Array</code> | | <p>Array of arguments, IMPORTANT: only the last argument may be a function (the callback) and the last argument cannot be false/undefined/null</p> | - [forceQueuing] <code>Boolean</code> <code> = false</code> - <p>Optional (defaults to false) force executor to queue task even if it is not ready</p>
| [forceQueuing] | <code>Boolean</code> | <code>false</code> | <p>Optional (defaults to false) force executor to queue task even if it is not ready</p> |
<a name="Executor+pushAsync"></a> <a name="Executor+pushAsync"></a>
### executor.pushAsync(task, [forceQueuing]) ⇒ <code>Promise.&lt;\*&gt;</code> ### executor.pushAsync(task, [forceQueuing]) ⇒ <code>Promise.&lt;\*&gt;</code>
<p>If executor is ready, queue task (and process it immediately if executor was idle) <p>Async version of [push](#Executor+push).
If not, buffer task for later processing</p> This version is way simpler than its callbackEquivalent: you give it an async function <code>task</code>, it is executed when
all the previous tasks are done, and then resolves or rejects and when it is finished with its original result or
error.</p>
**Kind**: instance method of [<code>Executor</code>](#Executor) **Kind**: instance method of [<code>Executor</code>](#Executor)
**See**: Executor#push
**Params**
| Param | Type | Default | - task [<code>AsyncFunction</code>](#AsyncFunction)
| --- | --- | --- | - [forceQueuing] <code>boolean</code> <code> = false</code>
| task | <code>function</code> | |
| [forceQueuing] | <code>boolean</code> | <code>false</code> |
<a name="Executor+processBuffer"></a> <a name="Executor+processBuffer"></a>

@ -29,13 +29,12 @@ fields to be undefined</p>
All methods on an index guarantee that either the whole operation was successful and the index changed All methods on an index guarantee that either the whole operation was successful and the index changed
or the operation was unsuccessful and an error is thrown while the index is unchanged</p> or the operation was unsuccessful and an error is thrown while the index is unchanged</p>
**Params**
| Param | Type | Default | Description | - options <code>object</code>
| --- | --- | --- | --- | - .fieldName <code>string</code> - <p>On which field should the index apply (can use dot notation to index on sub fields)</p>
| options | <code>object</code> | | | - [.unique] <code>boolean</code> <code> = false</code> - <p>Enforces a unique constraint</p>
| options.fieldName | <code>string</code> | | <p>On which field should the index apply (can use dot notation to index on sub fields)</p> | - [.sparse] <code>boolean</code> <code> = false</code> - <p>Allows a sparse index (we can have documents for which fieldName is <code>undefined</code>)</p>
| [options.unique] | <code>boolean</code> | <code>false</code> | <p>Enforces a unique constraint</p> |
| [options.sparse] | <code>boolean</code> | <code>false</code> | <p>Allows a sparse index (we can have documents for which fieldName is <code>undefined</code>)</p> |
<a name="Index+fieldName"></a> <a name="Index+fieldName"></a>
@ -73,10 +72,10 @@ or the operation was unsuccessful and an error is thrown while the index is unch
<p>Reset an index</p> <p>Reset an index</p>
**Kind**: instance method of [<code>Index</code>](#Index) **Kind**: instance method of [<code>Index</code>](#Index)
**Params**
| Param | Type | Description | - [newData] [<code>document</code>](#document) | [<code>?Array.&lt;document&gt;</code>](#document) - <p>Data to initialize the index with. If an error is thrown during
| --- | --- | --- | insertion, the index is not modified.</p>
| [newData] | [<code>document</code>](#document) \| [<code>?Array.&lt;document&gt;</code>](#document) | <p>Data to initialize the index with. If an error is thrown during insertion, the index is not modified.</p> |
<a name="Index+insert"></a> <a name="Index+insert"></a>
@ -86,10 +85,9 @@ If an array is passed, we insert all its elements (if one insertion fails the in
O(log(n))</p> O(log(n))</p>
**Kind**: instance method of [<code>Index</code>](#Index) **Kind**: instance method of [<code>Index</code>](#Index)
**Params**
| Param | Type | Description | - doc [<code>document</code>](#document) | [<code>Array.&lt;document&gt;</code>](#document) - <p>The document, or array of documents, to insert.</p>
| --- | --- | --- |
| doc | [<code>document</code>](#document) \| [<code>Array.&lt;document&gt;</code>](#document) | <p>The document, or array of documents, to insert.</p> |
<a name="Index+remove"></a> <a name="Index+remove"></a>
@ -100,10 +98,9 @@ The remove operation is safe with regards to the 'unique' constraint
O(log(n))</p> O(log(n))</p>
**Kind**: instance method of [<code>Index</code>](#Index) **Kind**: instance method of [<code>Index</code>](#Index)
**Params**
| Param | Type | Description | - doc [<code>Array.&lt;document&gt;</code>](#document) | [<code>document</code>](#document) - <p>The document, or Array of documents, to remove.</p>
| --- | --- | --- |
| doc | [<code>Array.&lt;document&gt;</code>](#document) \| [<code>document</code>](#document) | <p>The document, or Array of documents, to remove.</p> |
<a name="Index+update"></a> <a name="Index+update"></a>
@ -113,11 +110,12 @@ If a constraint is violated, changes are rolled back and an error thrown
Naive implementation, still in O(log(n))</p> Naive implementation, still in O(log(n))</p>
**Kind**: instance method of [<code>Index</code>](#Index) **Kind**: instance method of [<code>Index</code>](#Index)
**Params**
| Param | Type | Description | - oldDoc [<code>document</code>](#document) | <code>Array.&lt;{oldDoc: document, newDoc: document}&gt;</code> - <p>Document to update, or an <code>Array</code> of
| --- | --- | --- | <code>{oldDoc, newDoc}</code> pairs.</p>
| oldDoc | [<code>document</code>](#document) \| <code>Array.&lt;{oldDoc: document, newDoc: document}&gt;</code> | <p>Document to update, or an <code>Array</code> of <code>{oldDoc, newDoc}</code> pairs.</p> | - [newDoc] [<code>document</code>](#document) - <p>Document to replace the oldDoc with. If the first argument is an <code>Array</code> of
| [newDoc] | [<code>document</code>](#document) | <p>Document to replace the oldDoc with. If the first argument is an <code>Array</code> of <code>{oldDoc, newDoc}</code> pairs, this second argument is ignored.</p> | <code>{oldDoc, newDoc}</code> pairs, this second argument is ignored.</p>
<a name="Index+revertUpdate"></a> <a name="Index+revertUpdate"></a>
@ -125,11 +123,10 @@ Naive implementation, still in O(log(n))</p>
<p>Revert an update</p> <p>Revert an update</p>
**Kind**: instance method of [<code>Index</code>](#Index) **Kind**: instance method of [<code>Index</code>](#Index)
**Params**
| Param | Type | Description | - oldDoc [<code>document</code>](#document) | <code>Array.&lt;{oldDoc: document, newDoc: document}&gt;</code> - <p>Document to revert to, or an <code>Array</code> of <code>{oldDoc, newDoc}</code> pairs.</p>
| --- | --- | --- | - [newDoc] [<code>document</code>](#document) - <p>Document to revert from. If the first argument is an Array of {oldDoc, newDoc}, this second argument is ignored.</p>
| oldDoc | [<code>document</code>](#document) \| <code>Array.&lt;{oldDoc: document, newDoc: document}&gt;</code> | <p>Document to revert to, or an <code>Array</code> of <code>{oldDoc, newDoc}</code> pairs.</p> |
| [newDoc] | [<code>document</code>](#document) | <p>Document to revert from. If the first argument is an Array of {oldDoc, newDoc}, this second argument is ignored.</p> |
<a name="Index+getMatching"></a> <a name="Index+getMatching"></a>
@ -137,10 +134,9 @@ Naive implementation, still in O(log(n))</p>
<p>Get all documents in index whose key match value (if it is a Thing) or one of the elements of value (if it is an array of Things)</p> <p>Get all documents in index whose key match value (if it is a Thing) or one of the elements of value (if it is an array of Things)</p>
**Kind**: instance method of [<code>Index</code>](#Index) **Kind**: instance method of [<code>Index</code>](#Index)
**Params**
| Param | Type | Description | - value <code>Array.&lt;\*&gt;</code> | <code>\*</code> - <p>Value to match the key against</p>
| --- | --- | --- |
| value | <code>Array.&lt;\*&gt;</code> \| <code>\*</code> | <p>Value to match the key against</p> |
<a name="Index+getBetweenBounds"></a> <a name="Index+getBetweenBounds"></a>
@ -149,14 +145,13 @@ Naive implementation, still in O(log(n))</p>
Documents are sorted by key</p> Documents are sorted by key</p>
**Kind**: instance method of [<code>Index</code>](#Index) **Kind**: instance method of [<code>Index</code>](#Index)
**Params**
| Param | Type | Description | - query <code>object</code> - <p>An object with at least one matcher among $gt, $gte, $lt, $lte.</p>
| --- | --- | --- | - [.$gt] <code>\*</code> - <p>Greater than matcher.</p>
| query | <code>object</code> | <p>An object with at least one matcher among $gt, $gte, $lt, $lte.</p> | - [.$gte] <code>\*</code> - <p>Greater than or equal matcher.</p>
| [query.$gt] | <code>\*</code> | <p>Greater than matcher.</p> | - [.$lt] <code>\*</code> - <p>Lower than matcher.</p>
| [query.$gte] | <code>\*</code> | <p>Greater than or equal matcher.</p> | - [.$lte] <code>\*</code> - <p>Lower than or equal matcher.</p>
| [query.$lt] | <code>\*</code> | <p>Lower than matcher.</p> |
| [query.$lte] | <code>\*</code> | <p>Lower than or equal matcher.</p> |
<a name="Index+getAll"></a> <a name="Index+getAll"></a>

@ -8,7 +8,7 @@
* [Persistence](#Persistence) * [Persistence](#Persistence)
* [new Persistence()](#new_Persistence_new) * [new Persistence()](#new_Persistence_new)
* _instance_ * _instance_
* [.persistCachedDatabase(callback)](#Persistence+persistCachedDatabase) * [.persistCachedDatabase([callback])](#Persistence+persistCachedDatabase)
* [.persistCachedDatabaseAsync()](#Persistence+persistCachedDatabaseAsync) ⇒ <code>Promise.&lt;void&gt;</code> * [.persistCachedDatabaseAsync()](#Persistence+persistCachedDatabaseAsync) ⇒ <code>Promise.&lt;void&gt;</code>
* [.compactDatafile([callback])](#Persistence+compactDatafile) * [.compactDatafile([callback])](#Persistence+compactDatafile)
* [.compactDatafileAsync()](#Persistence+compactDatafileAsync) * [.compactDatafileAsync()](#Persistence+compactDatafileAsync)
@ -33,70 +33,69 @@
### new Persistence() ### new Persistence()
<p>Create a new Persistence object for database options.db</p> <p>Create a new Persistence object for database options.db</p>
**Params**
| Param | Type | Description | - .db [<code>Datastore</code>](#Datastore)
| --- | --- | --- | - [.corruptAlertThreshold] <code>Number</code> - <p>Optional, threshold after which an alert is thrown if too much data is corrupt</p>
| options.db | [<code>Datastore</code>](#Datastore) | | - [.nodeWebkitAppName] <code>string</code> - <p>Optional, specify the name of your NW app if you want options.filename to be relative to the directory where Node Webkit stores application data such as cookies and local storage (the best place to store data in my opinion)</p>
| [options.corruptAlertThreshold] | <code>Number</code> | <p>Optional, threshold after which an alert is thrown if too much data is corrupt</p> | - [.beforeDeserialization] [<code>serializationHook</code>](#serializationHook) - <p>Hook you can use to transform data after it was serialized and before it is written to disk.</p>
| [options.nodeWebkitAppName] | <code>string</code> | <p>Optional, specify the name of your NW app if you want options.filename to be relative to the directory where Node Webkit stores application data such as cookies and local storage (the best place to store data in my opinion)</p> | - [.afterSerialization] [<code>serializationHook</code>](#serializationHook) - <p>Inverse of <code>afterSerialization</code>.</p>
| [options.beforeDeserialization] | <code>function</code> | <p>Hook you can use to transform data after it was serialized and before it is written to disk.</p> |
| [options.afterSerialization] | <code>function</code> | <p>Inverse of <code>afterSerialization</code>.</p> |
<a name="Persistence+persistCachedDatabase"></a> <a name="Persistence+persistCachedDatabase"></a>
### persistence.persistCachedDatabase(callback) ### persistence.persistCachedDatabase([callback])
<p>Persist cached database <p>Persist cached database
This serves as a compaction function since the cache always contains only the number of documents in the collection This serves as a compaction function since the cache always contains only the number of documents in the collection
while the data file is append-only so it may grow larger while the data file is append-only so it may grow larger</p>
This is an internal function, use compactDataFile which uses the executor</p> <p>This is an internal function, use [compactDatafile](#Persistence+compactDatafile) which uses the [executor](#Datastore+executor).</p>
**Kind**: instance method of [<code>Persistence</code>](#Persistence) **Kind**: instance method of [<code>Persistence</code>](#Persistence)
**Access**: protected
**Params**
| Param | Type | Description | - [callback] [<code>NoParamCallback</code>](#NoParamCallback) <code> = () &#x3D;&gt; {}</code>
| --- | --- | --- |
| callback | [<code>NoParamCallback</code>](#NoParamCallback) | <p>Optional callback, signature: err</p> |
<a name="Persistence+persistCachedDatabaseAsync"></a> <a name="Persistence+persistCachedDatabaseAsync"></a>
### persistence.persistCachedDatabaseAsync() ⇒ <code>Promise.&lt;void&gt;</code> ### persistence.persistCachedDatabaseAsync() ⇒ <code>Promise.&lt;void&gt;</code>
<p>Persist cached database <p>Async version of [persistCachedDatabase](#Persistence+persistCachedDatabase).</p>
This serves as a compaction function since the cache always contains only the number of documents in the collection <p>This is an internal function, use [compactDatafileAsync](#Persistence+compactDatafileAsync) which uses the [executor](#Datastore+executor).</p>
while the data file is append-only so it may grow larger
This is an internal function, use compactDataFileAsync which uses the executor</p>
**Kind**: instance method of [<code>Persistence</code>](#Persistence) **Kind**: instance method of [<code>Persistence</code>](#Persistence)
**Access**: protected
**See**: Persistence#persistCachedDatabase
<a name="Persistence+compactDatafile"></a> <a name="Persistence+compactDatafile"></a>
### persistence.compactDatafile([callback]) ### persistence.compactDatafile([callback])
<p>Queue a rewrite of the datafile</p> <p>Queue a rewrite of the datafile</p>
**Kind**: instance method of [<code>Persistence</code>](#Persistence) **Kind**: instance method of [<code>Persistence</code>](#Persistence)
**See**: Persistence#persistCachedDatabase
**Params**
| Param | Type | Default | Description | - [callback] [<code>NoParamCallback</code>](#NoParamCallback) <code> = () &#x3D;&gt; {}</code>
| --- | --- | --- | --- |
| [callback] | [<code>NoParamCallback</code>](#NoParamCallback) | <code>() &#x3D;&gt; {}</code> | <p>Optional callback, signature: err</p> |
<a name="Persistence+compactDatafileAsync"></a> <a name="Persistence+compactDatafileAsync"></a>
### persistence.compactDatafileAsync() ### persistence.compactDatafileAsync()
<p>Queue a rewrite of the datafile</p> <p>Async version of [compactDatafile](#Persistence+compactDatafile).</p>
**Kind**: instance method of [<code>Persistence</code>](#Persistence) **Kind**: instance method of [<code>Persistence</code>](#Persistence)
**See**: Persistence#compactDatafile
<a name="Persistence+setAutocompactionInterval"></a> <a name="Persistence+setAutocompactionInterval"></a>
### persistence.setAutocompactionInterval(interval) ### persistence.setAutocompactionInterval(interval)
<p>Set automatic compaction every interval ms</p> <p>Set automatic compaction every <code>interval</code> ms</p>
**Kind**: instance method of [<code>Persistence</code>](#Persistence) **Kind**: instance method of [<code>Persistence</code>](#Persistence)
**Params**
| Param | Type | Description | - interval <code>Number</code> - <p>in milliseconds, with an enforced minimum of 5000 milliseconds</p>
| --- | --- | --- |
| interval | <code>Number</code> | <p>in milliseconds, with an enforced minimum of 5 seconds</p> |
<a name="Persistence+stopAutocompaction"></a> <a name="Persistence+stopAutocompaction"></a>
### persistence.stopAutocompaction() ### persistence.stopAutocompaction()
<p>Stop autocompaction (do nothing if autocompaction was not running)</p> <p>Stop autocompaction (do nothing if automatic compaction was not running)</p>
**Kind**: instance method of [<code>Persistence</code>](#Persistence) **Kind**: instance method of [<code>Persistence</code>](#Persistence)
<a name="Persistence+persistNewState"></a> <a name="Persistence+persistNewState"></a>
@ -104,59 +103,68 @@ This is an internal function, use compactDataFileAsync which uses the executor</
### persistence.persistNewState(newDocs, [callback]) ### persistence.persistNewState(newDocs, [callback])
<p>Persist new state for the given newDocs (can be insertion, update or removal) <p>Persist new state for the given newDocs (can be insertion, update or removal)
Use an append-only format</p> Use an append-only format</p>
<p>Do not use directly, it should only used by a [Datastore](#Datastore) instance.</p>
**Kind**: instance method of [<code>Persistence</code>](#Persistence) **Kind**: instance method of [<code>Persistence</code>](#Persistence)
**Access**: protected
**Params**
| Param | Type | Default | Description | - newDocs <code>Array.&lt;string&gt;</code> - <p>Can be empty if no doc was updated/removed</p>
| --- | --- | --- | --- | - [callback] [<code>NoParamCallback</code>](#NoParamCallback) <code> = () &#x3D;&gt; {}</code>
| newDocs | <code>Array.&lt;string&gt;</code> | | <p>Can be empty if no doc was updated/removed</p> |
| [callback] | [<code>NoParamCallback</code>](#NoParamCallback) | <code>() &#x3D;&gt; {}</code> | <p>Optional, signature: err</p> |
<a name="Persistence+persistNewStateAsync"></a> <a name="Persistence+persistNewStateAsync"></a>
### persistence.persistNewStateAsync(newDocs) ⇒ <code>Promise</code> ### persistence.persistNewStateAsync(newDocs) ⇒ <code>Promise</code>
<p>Persist new state for the given newDocs (can be insertion, update or removal) <p>Async version of [persistNewState](#Persistence+persistNewState)</p>
Use an append-only format</p> <p>Do not use directly, it should only used by a [Datastore](#Datastore) instance.</p>
**Kind**: instance method of [<code>Persistence</code>](#Persistence) **Kind**: instance method of [<code>Persistence</code>](#Persistence)
**See**: Persistence#persistNewState
**Params**
| Param | Type | Description | - newDocs [<code>Array.&lt;document&gt;</code>](#document) - <p>Can be empty if no doc was updated/removed</p>
| --- | --- | --- |
| newDocs | [<code>Array.&lt;document&gt;</code>](#document) | <p>Can be empty if no doc was updated/removed</p> |
<a name="Persistence+treatRawData"></a> <a name="Persistence+treatRawData"></a>
### persistence.treatRawData(rawData) ⇒ <code>Object</code> ### persistence.treatRawData(rawData) ⇒ <code>Object</code>
<p>From a database's raw data, return the corresponding machine understandable collection</p> <p>From a database's raw data, return the corresponding machine understandable collection.</p>
<p>Do not use directly, it should only used by a [Datastore](#Datastore) instance.</p>
**Kind**: instance method of [<code>Persistence</code>](#Persistence) **Kind**: instance method of [<code>Persistence</code>](#Persistence)
**Access**: protected
**Params**
| Param | Type | Description | - rawData <code>string</code> - <p>database file</p>
| --- | --- | --- |
| rawData | <code>string</code> | <p>database file</p> |
<a name="Persistence+treatRawStream"></a> <a name="Persistence+treatRawStream"></a>
### persistence.treatRawStream(rawStream, cb) ### persistence.treatRawStream(rawStream, cb)
<p>From a database's raw data stream, return the corresponding machine understandable collection</p> <p>From a database's raw data stream, return the corresponding machine understandable collection
Is only used by a [Datastore](#Datastore) instance.</p>
<p>Is only used in the Node.js version, since [React-Native](#module_storageReactNative) &amp;
[browser](#module_storageBrowser) storage modules don't provide an equivalent of
[readFileStream](#module_storage.readFileStream).</p>
<p>Do not use directly, it should only used by a [Datastore](#Datastore) instance.</p>
**Kind**: instance method of [<code>Persistence</code>](#Persistence) **Kind**: instance method of [<code>Persistence</code>](#Persistence)
**Access**: protected
**Params**
| Param | Type | - rawStream <code>Readable</code>
| --- | --- | - cb [<code>treatRawStreamCallback</code>](#Persistence..treatRawStreamCallback)
| rawStream | <code>Readable</code> |
| cb | [<code>treatRawStreamCallback</code>](#Persistence..treatRawStreamCallback) |
<a name="Persistence+treatRawStreamAsync"></a> <a name="Persistence+treatRawStreamAsync"></a>
### persistence.treatRawStreamAsync(rawStream) ⇒ <code>Promise.&lt;{data: Array.&lt;document&gt;, indexes: Object.&lt;string, rawIndex&gt;}&gt;</code> ### persistence.treatRawStreamAsync(rawStream) ⇒ <code>Promise.&lt;{data: Array.&lt;document&gt;, indexes: Object.&lt;string, rawIndex&gt;}&gt;</code>
<p>From a database's raw data stream, return the corresponding machine understandable collection</p> <p>Async version of [treatRawStream](#Persistence+treatRawStream).</p>
<p>Do not use directly, it should only used by a [Datastore](#Datastore) instance.</p>
**Kind**: instance method of [<code>Persistence</code>](#Persistence) **Kind**: instance method of [<code>Persistence</code>](#Persistence)
**Access**: protected
**See**: Persistence#treatRawStream
**Params**
| Param | Type | - rawStream <code>Readable</code>
| --- | --- |
| rawStream | <code>Readable</code> |
<a name="Persistence+loadDatabase"></a> <a name="Persistence+loadDatabase"></a>
@ -165,54 +173,47 @@ Use an append-only format</p>
<ol> <ol>
<li>Create all indexes</li> <li>Create all indexes</li>
<li>Insert all data</li> <li>Insert all data</li>
<li>Compact the database <li>Compact the database</li>
This means pulling data out of the data file or creating it if it doesn't exist
Also, all data is persisted right away, which has the effect of compacting the database file
This operation is very quick at startup for a big collection (60ms for ~10k docs)</li>
</ol> </ol>
<p>This means pulling data out of the data file or creating it if it doesn't exist
Also, all data is persisted right away, which has the effect of compacting the database file
This operation is very quick at startup for a big collection (60ms for ~10k docs)</p>
<p>Do not use directly as it does not use the [Executor](Datastore.executor), use [loadDatabase](#Datastore+loadDatabase) instead.</p>
**Kind**: instance method of [<code>Persistence</code>](#Persistence) **Kind**: instance method of [<code>Persistence</code>](#Persistence)
**Access**: protected
**Params**
| Param | Type | Description | - callback [<code>NoParamCallback</code>](#NoParamCallback)
| --- | --- | --- |
| callback | [<code>NoParamCallback</code>](#NoParamCallback) | <p>Optional callback, signature: err</p> |
<a name="Persistence+loadDatabaseAsync"></a> <a name="Persistence+loadDatabaseAsync"></a>
### persistence.loadDatabaseAsync() ⇒ <code>Promise.&lt;void&gt;</code> ### persistence.loadDatabaseAsync() ⇒ <code>Promise.&lt;void&gt;</code>
<p>Load the database</p> <p>Async version of [loadDatabase](#Persistence+loadDatabase)</p>
<ol>
<li>Create all indexes</li>
<li>Insert all data</li>
<li>Compact the database
This means pulling data out of the data file or creating it if it doesn't exist
Also, all data is persisted right away, which has the effect of compacting the database file
This operation is very quick at startup for a big collection (60ms for ~10k docs)</li>
</ol>
**Kind**: instance method of [<code>Persistence</code>](#Persistence) **Kind**: instance method of [<code>Persistence</code>](#Persistence)
**See**: Persistence#loadDatabase
<a name="Persistence.ensureDirectoryExists"></a> <a name="Persistence.ensureDirectoryExists"></a>
### Persistence.ensureDirectoryExists(dir, [callback]) ### Persistence.ensureDirectoryExists(dir, [callback])
<p>Check if a directory stat and create it on the fly if it is not the case</p> <p>Check if a directory stat and create it on the fly if it is not the case.</p>
**Kind**: static method of [<code>Persistence</code>](#Persistence) **Kind**: static method of [<code>Persistence</code>](#Persistence)
**Params**
| Param | Type | Default | Description | - dir <code>string</code>
| --- | --- | --- | --- | - [callback] [<code>NoParamCallback</code>](#NoParamCallback) <code> = () &#x3D;&gt; {}</code>
| dir | <code>string</code> | | |
| [callback] | [<code>NoParamCallback</code>](#NoParamCallback) | <code>() &#x3D;&gt; {}</code> | <p>optional callback, signature: err</p> |
<a name="Persistence.ensureDirectoryExistsAsync"></a> <a name="Persistence.ensureDirectoryExistsAsync"></a>
### Persistence.ensureDirectoryExistsAsync(dir) ⇒ <code>Promise.&lt;void&gt;</code> ### Persistence.ensureDirectoryExistsAsync(dir) ⇒ <code>Promise.&lt;void&gt;</code>
<p>Check if a directory stat and create it on the fly if it is not the case</p> <p>Async version of [ensureDirectoryExists](#Persistence.ensureDirectoryExists).</p>
**Kind**: static method of [<code>Persistence</code>](#Persistence) **Kind**: static method of [<code>Persistence</code>](#Persistence)
**See**: Persistence.ensureDirectoryExists
**Params**
| Param | Type | - dir <code>string</code>
| --- | --- |
| dir | <code>string</code> |
<a name="Persistence.getNWAppFilename"></a> <a name="Persistence.getNWAppFilename"></a>
@ -223,19 +224,19 @@ This operation is very quick at startup for a big collection (60ms for ~10k docs
data for this application. Probably the best place to store data</p> data for this application. Probably the best place to store data</p>
**Kind**: static method of [<code>Persistence</code>](#Persistence) **Kind**: static method of [<code>Persistence</code>](#Persistence)
**Params**
| Param | Type | - appName <code>string</code>
| --- | --- | - relativeFilename <code>string</code>
| appName | <code>string</code> |
| relativeFilename | <code>string</code> |
<a name="Persistence..treatRawStreamCallback"></a> <a name="Persistence..treatRawStreamCallback"></a>
### Persistence~treatRawStreamCallback : <code>function</code> ### Persistence~treatRawStreamCallback : <code>function</code>
**Kind**: inner typedef of [<code>Persistence</code>](#Persistence) **Kind**: inner typedef of [<code>Persistence</code>](#Persistence)
**Params**
| Param | Type | - err <code>Error</code>
| --- | --- | - data <code>object</code>
| err | <code>Error</code> | - .data [<code>Array.&lt;document&gt;</code>](#document)
| data | <code>Object</code> | - .indexes <code>Object.&lt;string, rawIndex&gt;</code>

@ -1,11 +1,12 @@
<a name="Waterfall"></a> <a name="Waterfall"></a>
## Waterfall ## Waterfall
<p>Responsible for sequentially executing actions on the database</p>
**Kind**: global class **Kind**: global class
* [Waterfall](#Waterfall) * [Waterfall](#Waterfall)
* [new Waterfall()](#new_Waterfall_new) * [new Waterfall()](#new_Waterfall_new)
* [._guardian](#Waterfall+_guardian) : <code>Promise</code>
* [.guardian](#Waterfall+guardian) ⇒ <code>Promise</code> * [.guardian](#Waterfall+guardian) ⇒ <code>Promise</code>
* [.waterfall(func)](#Waterfall+waterfall) ⇒ [<code>AsyncFunction</code>](#AsyncFunction) * [.waterfall(func)](#Waterfall+waterfall) ⇒ [<code>AsyncFunction</code>](#AsyncFunction)
* [.chain(promise)](#Waterfall+chain) ⇒ <code>Promise</code> * [.chain(promise)](#Waterfall+chain) ⇒ <code>Promise</code>
@ -15,15 +16,6 @@
### new Waterfall() ### new Waterfall()
<p>Instantiate a new Waterfall.</p> <p>Instantiate a new Waterfall.</p>
<a name="Waterfall+_guardian"></a>
### waterfall.\_guardian : <code>Promise</code>
<p>This is the internal Promise object which resolves when all the tasks of the <code>Waterfall</code> are done.</p>
<p>It will change any time <code>this.waterfall</code> is called.</p>
<p>Use [guardian](#Waterfall+guardian) instead which retrievethe latest version of the guardian.</p>
**Kind**: instance property of [<code>Waterfall</code>](#Waterfall)
**Access**: protected
<a name="Waterfall+guardian"></a> <a name="Waterfall+guardian"></a>
### waterfall.guardian ⇒ <code>Promise</code> ### waterfall.guardian ⇒ <code>Promise</code>
@ -35,10 +27,9 @@
### waterfall.waterfall(func) ⇒ [<code>AsyncFunction</code>](#AsyncFunction) ### waterfall.waterfall(func) ⇒ [<code>AsyncFunction</code>](#AsyncFunction)
**Kind**: instance method of [<code>Waterfall</code>](#Waterfall) **Kind**: instance method of [<code>Waterfall</code>](#Waterfall)
**Params**
| Param | Type | - func [<code>AsyncFunction</code>](#AsyncFunction)
| --- | --- |
| func | [<code>AsyncFunction</code>](#AsyncFunction) |
<a name="Waterfall+chain"></a> <a name="Waterfall+chain"></a>
@ -46,8 +37,7 @@
<p>Shorthand for chaining a promise to the Waterfall</p> <p>Shorthand for chaining a promise to the Waterfall</p>
**Kind**: instance method of [<code>Waterfall</code>](#Waterfall) **Kind**: instance method of [<code>Waterfall</code>](#Waterfall)
**Params**
| Param | Type | - promise <code>Promise</code>
| --- | --- |
| promise | <code>Promise</code> |

@ -17,10 +17,9 @@ https://github.com/dominictarr/crypto-browserify
NOTE: Math.random() does not guarantee &quot;cryptographic quality&quot; but we actually don't need it</p> NOTE: Math.random() does not guarantee &quot;cryptographic quality&quot; but we actually don't need it</p>
**Kind**: inner method of [<code>customUtilsBrowser</code>](#module_customUtilsBrowser) **Kind**: inner method of [<code>customUtilsBrowser</code>](#module_customUtilsBrowser)
**Params**
| Param | Type | Description | - size <code>number</code> - <p>in bytes</p>
| --- | --- | --- |
| size | <code>number</code> | <p>in bytes</p> |
<a name="module_customUtilsBrowser..byteArrayToBase64"></a> <a name="module_customUtilsBrowser..byteArrayToBase64"></a>
@ -29,8 +28,7 @@ NOTE: Math.random() does not guarantee &quot;cryptographic quality&quot; but we
https://github.com/beatgammit/base64-js/</p> https://github.com/beatgammit/base64-js/</p>
**Kind**: inner method of [<code>customUtilsBrowser</code>](#module_customUtilsBrowser) **Kind**: inner method of [<code>customUtilsBrowser</code>](#module_customUtilsBrowser)
**Params**
| Param | Type | - uint8 <code>array</code>
| --- | --- |
| uint8 | <code>array</code> |

@ -20,10 +20,9 @@ The probability of a collision is extremely small (need 3*10^12 documents to hav
See http://en.wikipedia.org/wiki/Birthday_problem</p> See http://en.wikipedia.org/wiki/Birthday_problem</p>
**Kind**: static method of [<code>customUtilsNode</code>](#module_customUtilsNode) **Kind**: static method of [<code>customUtilsNode</code>](#module_customUtilsNode)
**Params**
| Param | Type | - len <code>number</code>
| --- | --- |
| len | <code>number</code> |
<a name="module_customUtilsNode.uid"></a> <a name="module_customUtilsNode.uid"></a>
@ -36,8 +35,7 @@ The probability of a collision is extremely small (need 3*10^12 documents to hav
See http://en.wikipedia.org/wiki/Birthday_problem</p> See http://en.wikipedia.org/wiki/Birthday_problem</p>
**Kind**: static method of [<code>customUtilsNode</code>](#module_customUtilsNode) **Kind**: static method of [<code>customUtilsNode</code>](#module_customUtilsNode)
**Params**
| Param | Type | - len <code>number</code>
| --- | --- |
| len | <code>number</code> |

@ -0,0 +1,155 @@
<a name="NoParamCallback"></a>
## NoParamCallback : <code>function</code>
<p>Callback with no parameter</p>
**Kind**: global typedef
**Params**
- err <code>Error</code>
<a name="compareStrings"></a>
## compareStrings ⇒ <code>number</code>
<p>String comparison function.</p>
<pre class="prettyprint source"><code> if (a &lt; b) return -1
if (a > b) return 1
return 0
</code></pre>
**Kind**: global typedef
**Params**
- a <code>string</code>
- b <code>string</code>
<a name="MultipleDocumentsCallback"></a>
## MultipleDocumentsCallback : <code>function</code>
<p>Callback that returns an Array of documents</p>
**Kind**: global typedef
**Params**
- err <code>Error</code>
- docs [<code>Array.&lt;document&gt;</code>](#document)
<a name="SingleDocumentCallback"></a>
## SingleDocumentCallback : <code>function</code>
<p>Callback that returns a single document</p>
**Kind**: global typedef
**Params**
- err <code>Error</code>
- docs [<code>document</code>](#document)
<a name="AsyncFunction"></a>
## AsyncFunction ⇒ <code>Promise.&lt;\*&gt;</code>
<p>Generic async function</p>
**Kind**: global typedef
**Params**
- ...args <code>\*</code>
<a name="document"></a>
## document : <code>Object.&lt;string, \*&gt;</code>
<p>Generic document in NeDB.
It consists of an Object with anything you want inside.</p>
**Kind**: global typedef
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| [_id] | <code>string</code> | <p>Internal <code>_id</code> of the document, which can be <code>null</code> or undefined at some points (when not inserted yet for example).</p> |
<a name="query"></a>
## query : <code>Object.&lt;string, \*&gt;</code>
<p>Nedb query.</p>
<p>Each key of a query references a field name, which can use the dot-notation to reference subfields inside nested
documents, arrays, arrays of subdocuments and to match a specific element of an array.</p>
<p>Each value of a query can be one of the following:</p>
<ul>
<li><code>string</code>: matches all documents which have this string as value for the referenced field name</li>
<li><code>number</code>: matches all documents which have this number as value for the referenced field name</li>
<li><code>Regexp</code>: matches all documents which have a value that matches the given <code>Regexp</code> for the referenced field name</li>
<li><code>object</code>: matches all documents which have this object as deep-value for the referenced field name</li>
<li>Comparison operators: the syntax is <code>{ field: { $op: value } }</code> where <code>$op</code> is any comparison operator:
<ul>
<li><code>$lt</code>, <code>$lte</code>: less than, less than or equal</li>
<li><code>$gt</code>, <code>$gte</code>: greater than, greater than or equal</li>
<li><code>$in</code>: member of. <code>value</code> must be an array of values</li>
<li><code>$ne</code>, <code>$nin</code>: not equal, not a member of</li>
<li><code>$stat</code>: checks whether the document posses the property <code>field</code>. <code>value</code> should be true or false</li>
<li><code>$regex</code>: checks whether a string is matched by the regular expression. Contrary to MongoDB, the use of
<code>$options</code> with <code>$regex</code> is not supported, because it doesn't give you more power than regex flags. Basic
queries are more readable so only use the <code>$regex</code> operator when you need to use another operator with it</li>
<li><code>$size</code>: if the referenced filed is an Array, matches on the size of the array</li>
<li><code>$elemMatch</code>: matches if at least one array element matches the sub-query entirely</li>
</ul>
</li>
<li>Logical operators: You can combine queries using logical operators:
<ul>
<li>For <code>$or</code> and <code>$and</code>, the syntax is <code>{ $op: [query1, query2, ...] }</code>.</li>
<li>For <code>$not</code>, the syntax is <code>{ $not: query }</code></li>
<li>For <code>$where</code>, the syntax is:</li>
</ul>
<pre class="prettyprint source"><code>{ $where: function () {
// object is 'this'
// return a boolean
} }
</code></pre>
</li>
</ul>
**Kind**: global typedef
<a name="projection"></a>
## projection : <code>Object.&lt;string, (0\|1)&gt;</code>
<p>Nedb projection.</p>
<p>You can give <code>find</code> and <code>findOne</code> an optional second argument, <code>projections</code>.
The syntax is the same as MongoDB: <code>{ a: 1, b: 1 }</code> to return only the <code>a</code>
and <code>b</code> fields, <code>{ a: 0, b: 0 }</code> to omit these two fields. You cannot use both
modes at the time, except for <code>_id</code> which is by default always returned and
which you can choose to omit. You can project on nested documents.</p>
<p>To reference subfields, you can use the dot-notation.</p>
**Kind**: global typedef
<a name="serializationHook"></a>
## serializationHook ⇒ <code>string</code>
<p>The <code>beforeDeserialization</code>and <code>afterDeserialization</code> callbacks should</p>
**Kind**: global typedef
**Params**
- x <code>string</code>
<a name="rawIndex"></a>
## rawIndex
**Kind**: global typedef
**Properties**
| Name | Type |
| --- | --- |
| fieldName | <code>string</code> |
| [unique] | <code>boolean</code> |
| [sparse] | <code>boolean</code> |

@ -32,10 +32,9 @@ Querying, update</p>
Works by applying the above checkKey function to all fields recursively</p> Works by applying the above checkKey function to all fields recursively</p>
**Kind**: static method of [<code>model</code>](#module_model) **Kind**: static method of [<code>model</code>](#module_model)
**Params**
| Param | Type | - obj [<code>document</code>](#document) | [<code>Array.&lt;document&gt;</code>](#document)
| --- | --- |
| obj | [<code>document</code>](#document) \| [<code>Array.&lt;document&gt;</code>](#document) |
<a name="module_model.serialize"></a> <a name="module_model.serialize"></a>
@ -48,10 +47,9 @@ Accepted primitive types: Number, String, Boolean, Date, null
Accepted secondary types: Objects, Arrays</p> Accepted secondary types: Objects, Arrays</p>
**Kind**: static method of [<code>model</code>](#module_model) **Kind**: static method of [<code>model</code>](#module_model)
**Params**
| Param | Type | - obj [<code>document</code>](#document)
| --- | --- |
| obj | [<code>document</code>](#document) |
<a name="module_model.deserialize"></a> <a name="module_model.deserialize"></a>
@ -60,10 +58,9 @@ Accepted secondary types: Objects, Arrays</p>
Return the object itself</p> Return the object itself</p>
**Kind**: static method of [<code>model</code>](#module_model) **Kind**: static method of [<code>model</code>](#module_model)
**Params**
| Param | Type | - rawData <code>string</code>
| --- | --- |
| rawData | <code>string</code> |
<a name="module_model.compareThings"></a> <a name="module_model.compareThings"></a>
@ -76,12 +73,11 @@ If two objects dont have the same type, the (arbitrary) type hierarchy is: undef
Return -1 if a &lt; b, 1 if a &gt; b and 0 if a = b (note that equality here is NOT the same as defined in areThingsEqual!)</p> Return -1 if a &lt; b, 1 if a &gt; b and 0 if a = b (note that equality here is NOT the same as defined in areThingsEqual!)</p>
**Kind**: static method of [<code>model</code>](#module_model) **Kind**: static method of [<code>model</code>](#module_model)
**Params**
| Param | Type | Description | - a <code>\*</code>
| --- | --- | --- | - b <code>\*</code>
| a | <code>\*</code> | | - [_compareStrings] [<code>compareStrings</code>](#compareStrings) - <p>String comparing function, returning -1, 0 or 1, overriding default string comparison (useful for languages with accented letters)</p>
| b | <code>\*</code> | |
| [_compareStrings] | [<code>compareStrings</code>](#compareStrings) | <p>String comparing function, returning -1, 0 or 1, overriding default string comparison (useful for languages with accented letters)</p> |
<a name="module_model.modify"></a> <a name="module_model.modify"></a>
@ -89,11 +85,10 @@ Return -1 if a &lt; b, 1 if a &gt; b and 0 if a = b (note that equality here is
<p>Modify a DB object according to an update query</p> <p>Modify a DB object according to an update query</p>
**Kind**: static method of [<code>model</code>](#module_model) **Kind**: static method of [<code>model</code>](#module_model)
**Params**
| Param | Type | - obj [<code>document</code>](#document)
| --- | --- | - updateQuery [<code>query</code>](#query)
| obj | [<code>document</code>](#document) |
| updateQuery | [<code>query</code>](#query) |
<a name="module_model.getDotValue"></a> <a name="module_model.getDotValue"></a>
@ -101,11 +96,10 @@ Return -1 if a &lt; b, 1 if a &gt; b and 0 if a = b (note that equality here is
<p>Get a value from object with dot notation</p> <p>Get a value from object with dot notation</p>
**Kind**: static method of [<code>model</code>](#module_model) **Kind**: static method of [<code>model</code>](#module_model)
**Params**
| Param | Type | - obj <code>object</code>
| --- | --- | - field <code>string</code>
| obj | <code>object</code> |
| field | <code>string</code> |
<a name="module_model.areThingsEqual"></a> <a name="module_model.areThingsEqual"></a>
@ -116,11 +110,10 @@ In the case of object, we check deep equality
Returns true if they are, false otherwise</p> Returns true if they are, false otherwise</p>
**Kind**: static method of [<code>model</code>](#module_model) **Kind**: static method of [<code>model</code>](#module_model)
**Params**
| Param | Type | - a <code>\*</code>
| --- | --- | - a <code>\*</code>
| a | <code>\*</code> |
| a | <code>\*</code> |
<a name="module_model.match"></a> <a name="module_model.match"></a>
@ -128,11 +121,10 @@ Returns true if they are, false otherwise</p>
<p>Tell if a given document matches a query</p> <p>Tell if a given document matches a query</p>
**Kind**: static method of [<code>model</code>](#module_model) **Kind**: static method of [<code>model</code>](#module_model)
**Params**
| Param | Type | Description | - obj [<code>document</code>](#document) - <p>Document to check</p>
| --- | --- | --- | - query [<code>query</code>](#query)
| obj | [<code>document</code>](#document) | <p>Document to check</p> |
| query | [<code>query</code>](#query) | |
<a name="module_model..modifierFunctions"></a> <a name="module_model..modifierFunctions"></a>
@ -189,29 +181,26 @@ Returns true if they are, false otherwise</p>
### model~modifierFunction : <code>function</code> ### model~modifierFunction : <code>function</code>
**Kind**: inner typedef of [<code>model</code>](#module_model) **Kind**: inner typedef of [<code>model</code>](#module_model)
**Params**
| Param | Type | Description | - obj <code>Object</code> - <p>The model to modify</p>
| --- | --- | --- | - field <code>String</code> - <p>Can contain dots, in that case that means we will set a subfield recursively</p>
| obj | <code>Object</code> | <p>The model to modify</p> | - value [<code>document</code>](#document)
| field | <code>String</code> | <p>Can contain dots, in that case that means we will set a subfield recursively</p> |
| value | [<code>document</code>](#document) | |
<a name="module_model..comparisonOperator"></a> <a name="module_model..comparisonOperator"></a>
### model~comparisonOperator ⇒ <code>boolean</code> ### model~comparisonOperator ⇒ <code>boolean</code>
**Kind**: inner typedef of [<code>model</code>](#module_model) **Kind**: inner typedef of [<code>model</code>](#module_model)
**Params**
| Param | Type | Description | - a <code>\*</code> - <p>Value in the object</p>
| --- | --- | --- | - b <code>\*</code> - <p>Value in the query</p>
| a | <code>\*</code> | <p>Value in the object</p> |
| b | <code>\*</code> | <p>Value in the query</p> |
<a name="module_model..whereCallback"></a> <a name="module_model..whereCallback"></a>
### model~whereCallback ⇒ <code>boolean</code> ### model~whereCallback ⇒ <code>boolean</code>
**Kind**: inner typedef of [<code>model</code>](#module_model) **Kind**: inner typedef of [<code>model</code>](#module_model)
**Params**
| Param | Type | - obj [<code>document</code>](#document)
| --- | --- |
| obj | [<code>document</code>](#document) |

@ -1,12 +1,14 @@
<a name="module_storage"></a> <a name="module_storage"></a>
## storage ## storage
<p>Way data is stored for this database <p>Way data is stored for this database.
For a Node.js/Node Webkit database it's the file system This version is the Node.js/Node Webkit version.
For a browser-side database it's localforage, which uses the best backend available (IndexedDB then WebSQL then localStorage) It's essentially fs, mkdirp and crash safe write and read functions.</p>
For a react-native database, we use @react-native-async-storage/async-storage</p>
<p>This version is the Node.js/Node Webkit version **See**
It's essentially fs, mkdirp and crash safe write and read functions</p>
- module:storageBrowser
- module:storageReactNative
* [storage](#module_storage) * [storage](#module_storage)
@ -31,7 +33,7 @@ It's essentially fs, mkdirp and crash safe write and read functions</p>
* [.ensureFileDoesntExist(file, callback)](#module_storage.ensureFileDoesntExist) * [.ensureFileDoesntExist(file, callback)](#module_storage.ensureFileDoesntExist)
* [.flushToStorage(options, callback)](#module_storage.flushToStorage) * [.flushToStorage(options, callback)](#module_storage.flushToStorage)
* [.flushToStorageAsync(options)](#module_storage.flushToStorageAsync) ⇒ <code>Promise.&lt;void&gt;</code> * [.flushToStorageAsync(options)](#module_storage.flushToStorageAsync) ⇒ <code>Promise.&lt;void&gt;</code>
* [.writeFileLines(filename, lines, callback)](#module_storage.writeFileLines) * [.writeFileLines(filename, lines, [callback])](#module_storage.writeFileLines)
* [.writeFileLinesAsync(filename, lines)](#module_storage.writeFileLinesAsync) ⇒ <code>Promise.&lt;void&gt;</code> * [.writeFileLinesAsync(filename, lines)](#module_storage.writeFileLinesAsync) ⇒ <code>Promise.&lt;void&gt;</code>
* [.crashSafeWriteFileLines(filename, lines, [callback])](#module_storage.crashSafeWriteFileLines) * [.crashSafeWriteFileLines(filename, lines, [callback])](#module_storage.crashSafeWriteFileLines)
* [.crashSafeWriteFileLinesAsync(filename, lines)](#module_storage.crashSafeWriteFileLinesAsync) ⇒ <code>Promise.&lt;void&gt;</code> * [.crashSafeWriteFileLinesAsync(filename, lines)](#module_storage.crashSafeWriteFileLinesAsync) ⇒ <code>Promise.&lt;void&gt;</code>
@ -43,327 +45,316 @@ It's essentially fs, mkdirp and crash safe write and read functions</p>
<a name="module_storage.exists"></a> <a name="module_storage.exists"></a>
### storage.exists(file, cb) ### storage.exists(file, cb)
<p>Callback returns true if file exists</p> <p>Callback returns true if file exists.</p>
**Kind**: static method of [<code>storage</code>](#module_storage) **Kind**: static method of [<code>storage</code>](#module_storage)
**Params**
| Param | Type | - file <code>string</code>
| --- | --- | - cb [<code>existsCallback</code>](#module_storage..existsCallback)
| file | <code>string</code> |
| cb | [<code>existsCallback</code>](#module_storage..existsCallback) |
<a name="module_storage.existsAsync"></a> <a name="module_storage.existsAsync"></a>
### storage.existsAsync(file) ⇒ <code>Promise.&lt;boolean&gt;</code> ### storage.existsAsync(file) ⇒ <code>Promise.&lt;boolean&gt;</code>
<p>Returns Promise<true> if file exists</p> <p>Async version of [exists](#module_storage.exists).</p>
**Kind**: static method of [<code>storage</code>](#module_storage) **Kind**: static method of [<code>storage</code>](#module_storage)
**See**: module:storage.exists
**Params**
| Param | Type | - file <code>string</code>
| --- | --- |
| file | <code>string</code> |
<a name="module_storage.rename"></a> <a name="module_storage.rename"></a>
### storage.rename(oldPath, newPath, c) ⇒ <code>void</code> ### storage.rename(oldPath, newPath, c) ⇒ <code>void</code>
<p>Node.js' fs.rename</p> <p>Node.js' [fs.rename](https://nodejs.org/api/fs.html#fsrenameoldpath-newpath-callback).</p>
**Kind**: static method of [<code>storage</code>](#module_storage) **Kind**: static method of [<code>storage</code>](#module_storage)
**Params**
| Param | Type | - oldPath <code>string</code>
| --- | --- | - newPath <code>string</code>
| oldPath | <code>string</code> | - c [<code>NoParamCallback</code>](#NoParamCallback)
| newPath | <code>string</code> |
| c | [<code>NoParamCallback</code>](#NoParamCallback) |
<a name="module_storage.renameAsync"></a> <a name="module_storage.renameAsync"></a>
### storage.renameAsync(oldPath, newPath) ⇒ <code>Promise.&lt;void&gt;</code> ### storage.renameAsync(oldPath, newPath) ⇒ <code>Promise.&lt;void&gt;</code>
<p>Node.js' fs.promises.rename</p> <p>Async version of [rename](#module_storage.rename).</p>
**Kind**: static method of [<code>storage</code>](#module_storage) **Kind**: static method of [<code>storage</code>](#module_storage)
**See**: module:storage.rename
**Params**
| Param | Type | - oldPath <code>string</code>
| --- | --- | - newPath <code>string</code>
| oldPath | <code>string</code> |
| newPath | <code>string</code> |
<a name="module_storage.writeFile"></a> <a name="module_storage.writeFile"></a>
### storage.writeFile(path, data, options, callback) ### storage.writeFile(path, data, options, callback)
<p>Node.js' fs.writeFile</p> <p>Node.js' [fs.writeFile](https://nodejs.org/api/fs.html#fswritefilefile-data-options-callback).</p>
**Kind**: static method of [<code>storage</code>](#module_storage) **Kind**: static method of [<code>storage</code>](#module_storage)
**Params**
| Param | Type | - path <code>string</code>
| --- | --- | - data <code>string</code>
| path | <code>string</code> | - options <code>object</code>
| data | <code>string</code> | - callback <code>function</code>
| options | <code>object</code> |
| callback | <code>function</code> |
<a name="module_storage.writeFileAsync"></a> <a name="module_storage.writeFileAsync"></a>
### storage.writeFileAsync(path, data, [options]) ⇒ <code>Promise.&lt;void&gt;</code> ### storage.writeFileAsync(path, data, [options]) ⇒ <code>Promise.&lt;void&gt;</code>
<p>Node.js' fs.promises.writeFile</p> <p>Async version of [writeFile](#module_storage.writeFile).</p>
**Kind**: static method of [<code>storage</code>](#module_storage) **Kind**: static method of [<code>storage</code>](#module_storage)
**See**: module:storage.writeFile
**Params**
| Param | Type | - path <code>string</code>
| --- | --- | - data <code>string</code>
| path | <code>string</code> | - [options] <code>object</code>
| data | <code>string</code> |
| [options] | <code>object</code> |
<a name="module_storage.writeFileStream"></a> <a name="module_storage.writeFileStream"></a>
### storage.writeFileStream(path, [options]) ⇒ <code>fs.WriteStream</code> ### storage.writeFileStream(path, [options]) ⇒ <code>fs.WriteStream</code>
<p>Node.js' fs.createWriteStream</p> <p>Node.js' [fs.createWriteStream](https://nodejs.org/api/fs.html#fscreatewritestreampath-options).</p>
**Kind**: static method of [<code>storage</code>](#module_storage) **Kind**: static method of [<code>storage</code>](#module_storage)
**Params**
| Param | Type | - path <code>string</code>
| --- | --- | - [options] <code>Object</code>
| path | <code>string</code> |
| [options] | <code>Object</code> |
<a name="module_storage.unlink"></a> <a name="module_storage.unlink"></a>
### storage.unlink(path, callback) ### storage.unlink(path, callback)
<p>Node.js' fs.unlink</p> <p>Node.js' [fs.unlink](https://nodejs.org/api/fs.html#fsunlinkpath-callback).</p>
**Kind**: static method of [<code>storage</code>](#module_storage) **Kind**: static method of [<code>storage</code>](#module_storage)
**Params**
| Param | Type | - path <code>string</code>
| --- | --- | - callback <code>function</code>
| path | <code>string</code> |
| callback | <code>function</code> |
<a name="module_storage.unlinkAsync"></a> <a name="module_storage.unlinkAsync"></a>
### storage.unlinkAsync(path) ⇒ <code>Promise.&lt;void&gt;</code> ### storage.unlinkAsync(path) ⇒ <code>Promise.&lt;void&gt;</code>
<p>Node.js' fs.promises.unlink</p> <p>Async version of [unlink](#module_storage.unlink).</p>
**Kind**: static method of [<code>storage</code>](#module_storage) **Kind**: static method of [<code>storage</code>](#module_storage)
**See**: module:storage.unlink
**Params**
| Param | Type | - path <code>string</code>
| --- | --- |
| path | <code>string</code> |
<a name="module_storage.appendFile"></a> <a name="module_storage.appendFile"></a>
### storage.appendFile(path, data, options, callback) ### storage.appendFile(path, data, options, callback)
<p>Node.js' fs.appendFile</p> <p>Node.js' [fs.appendFile](https://nodejs.org/api/fs.html#fsappendfilepath-data-options-callback).</p>
**Kind**: static method of [<code>storage</code>](#module_storage) **Kind**: static method of [<code>storage</code>](#module_storage)
**Params**
| Param | Type | - path <code>string</code>
| --- | --- | - data <code>string</code>
| path | <code>string</code> | - options <code>object</code>
| data | <code>string</code> | - callback <code>function</code>
| options | <code>object</code> |
| callback | <code>function</code> |
<a name="module_storage.appendFileAsync"></a> <a name="module_storage.appendFileAsync"></a>
### storage.appendFileAsync(path, data, [options]) ⇒ <code>Promise.&lt;void&gt;</code> ### storage.appendFileAsync(path, data, [options]) ⇒ <code>Promise.&lt;void&gt;</code>
<p>Node.js' fs.promises.appendFile</p> <p>Async version of [appendFile](#module_storage.appendFile).</p>
**Kind**: static method of [<code>storage</code>](#module_storage) **Kind**: static method of [<code>storage</code>](#module_storage)
**See**: module:storage.appendFile
**Params**
| Param | Type | - path <code>string</code>
| --- | --- | - data <code>string</code>
| path | <code>string</code> | - [options] <code>object</code>
| data | <code>string</code> |
| [options] | <code>object</code> |
<a name="module_storage.readFile"></a> <a name="module_storage.readFile"></a>
### storage.readFile(path, options, callback) ### storage.readFile(path, options, callback)
<p>Node.js' fs.readFile</p> <p>Node.js' [fs.readFile](https://nodejs.org/api/fs.html#fsreadfilepath-options-callback)</p>
**Kind**: static method of [<code>storage</code>](#module_storage) **Kind**: static method of [<code>storage</code>](#module_storage)
**Params**
| Param | Type | - path <code>string</code>
| --- | --- | - options <code>object</code>
| path | <code>string</code> | - callback <code>function</code>
| options | <code>object</code> |
| callback | <code>function</code> |
<a name="module_storage.readFileAsync"></a> <a name="module_storage.readFileAsync"></a>
### storage.readFileAsync(path, [options]) ⇒ <code>Promise.&lt;Buffer&gt;</code> ### storage.readFileAsync(path, [options]) ⇒ <code>Promise.&lt;Buffer&gt;</code>
<p>Node.js' fs.promises.readFile</p> <p>Async version of [readFile](#module_storage.readFile).</p>
**Kind**: static method of [<code>storage</code>](#module_storage) **Kind**: static method of [<code>storage</code>](#module_storage)
**See**: module:storage.readFile
**Params**
| Param | Type | - path <code>string</code>
| --- | --- | - [options] <code>object</code>
| path | <code>string</code> |
| [options] | <code>object</code> |
<a name="module_storage.readFileStream"></a> <a name="module_storage.readFileStream"></a>
### storage.readFileStream(path, [options]) ⇒ <code>fs.ReadStream</code> ### storage.readFileStream(path, [options]) ⇒ <code>fs.ReadStream</code>
<p>Node.js' fs.createReadStream</p> <p>Node.js' [fs.createReadStream](https://nodejs.org/api/fs.html#fscreatereadstreampath-options).</p>
**Kind**: static method of [<code>storage</code>](#module_storage) **Kind**: static method of [<code>storage</code>](#module_storage)
**Params**
| Param | Type | - path <code>string</code>
| --- | --- | - [options] <code>Object</code>
| path | <code>string</code> |
| [options] | <code>Object</code> |
<a name="module_storage.mkdir"></a> <a name="module_storage.mkdir"></a>
### storage.mkdir(path, options, callback) ### storage.mkdir(path, options, callback)
<p>Node.js' fs.mkdir</p> <p>Node.js' [fs.mkdir](https://nodejs.org/api/fs.html#fsmkdirpath-options-callback).</p>
**Kind**: static method of [<code>storage</code>](#module_storage) **Kind**: static method of [<code>storage</code>](#module_storage)
**Params**
| Param | Type | - path <code>string</code>
| --- | --- | - options <code>object</code>
| path | <code>string</code> | - callback <code>function</code>
| options | <code>object</code> |
| callback | <code>function</code> |
<a name="module_storage.mkdirAsync"></a> <a name="module_storage.mkdirAsync"></a>
### storage.mkdirAsync(path, options) ⇒ <code>Promise.&lt;(void\|string)&gt;</code> ### storage.mkdirAsync(path, options) ⇒ <code>Promise.&lt;(void\|string)&gt;</code>
<p>Node.js' fs.promises.mkdir</p> <p>Async version of [mkdir](#module_storage.mkdir).</p>
**Kind**: static method of [<code>storage</code>](#module_storage) **Kind**: static method of [<code>storage</code>](#module_storage)
**See**: module:storage.mkdir
**Params**
| Param | Type | - path <code>string</code>
| --- | --- | - options <code>object</code>
| path | <code>string</code> |
| options | <code>object</code> |
<a name="module_storage.ensureFileDoesntExistAsync"></a> <a name="module_storage.ensureFileDoesntExistAsync"></a>
### storage.ensureFileDoesntExistAsync(file) ⇒ <code>Promise.&lt;void&gt;</code> ### storage.ensureFileDoesntExistAsync(file) ⇒ <code>Promise.&lt;void&gt;</code>
<p>Async version of [ensureFileDoesntExist](#module_storage.ensureFileDoesntExist)</p>
**Kind**: static method of [<code>storage</code>](#module_storage) **Kind**: static method of [<code>storage</code>](#module_storage)
**See**: module:storage.ensureFileDoesntExist
**Params**
| Param | Type | - file <code>string</code>
| --- | --- |
| file | <code>string</code> |
<a name="module_storage.ensureFileDoesntExist"></a> <a name="module_storage.ensureFileDoesntExist"></a>
### storage.ensureFileDoesntExist(file, callback) ### storage.ensureFileDoesntExist(file, callback)
<p>Removes file if it exists.</p>
**Kind**: static method of [<code>storage</code>](#module_storage) **Kind**: static method of [<code>storage</code>](#module_storage)
**Params**
| Param | Type | - file <code>string</code>
| --- | --- | - callback [<code>NoParamCallback</code>](#NoParamCallback)
| file | <code>string</code> |
| callback | [<code>NoParamCallback</code>](#NoParamCallback) |
<a name="module_storage.flushToStorage"></a> <a name="module_storage.flushToStorage"></a>
### storage.flushToStorage(options, callback) ### storage.flushToStorage(options, callback)
<p>Flush data in OS buffer to storage if corresponding option is set</p> <p>Flush data in OS buffer to storage if corresponding option is set.</p>
**Kind**: static method of [<code>storage</code>](#module_storage) **Kind**: static method of [<code>storage</code>](#module_storage)
**Params**
| Param | Type | Default | Description | - options <code>object</code> | <code>string</code> - <p>If options is a string, it is assumed that the flush of the file (not dir) called options was requested</p>
| --- | --- | --- | --- | - [.filename] <code>string</code>
| options | <code>object</code> \| <code>string</code> | | <p>If options is a string, it is assumed that the flush of the file (not dir) called options was requested</p> | - [.isDir] <code>boolean</code> <code> = false</code> - <p>Optional, defaults to false</p>
| [options.filename] | <code>string</code> | | | - callback [<code>NoParamCallback</code>](#NoParamCallback)
| [options.isDir] | <code>boolean</code> | <code>false</code> | <p>Optional, defaults to false</p> |
| callback | [<code>NoParamCallback</code>](#NoParamCallback) | | |
<a name="module_storage.flushToStorageAsync"></a> <a name="module_storage.flushToStorageAsync"></a>
### storage.flushToStorageAsync(options) ⇒ <code>Promise.&lt;void&gt;</code> ### storage.flushToStorageAsync(options) ⇒ <code>Promise.&lt;void&gt;</code>
<p>Flush data in OS buffer to storage if corresponding option is set</p> <p>Async version of [flushToStorage](#module_storage.flushToStorage).</p>
**Kind**: static method of [<code>storage</code>](#module_storage) **Kind**: static method of [<code>storage</code>](#module_storage)
**See**: module:storage.flushToStorage
**Params**
| Param | Type | Default | Description | - options <code>object</code> | <code>string</code>
| --- | --- | --- | --- | - [.filename] <code>string</code>
| options | <code>object</code> \| <code>string</code> | | <p>If options is a string, it is assumed that the flush of the file (not dir) called options was requested</p> | - [.isDir] <code>boolean</code> <code> = false</code>
| [options.filename] | <code>string</code> | | |
| [options.isDir] | <code>boolean</code> | <code>false</code> | <p>Optional, defaults to false</p> |
<a name="module_storage.writeFileLines"></a> <a name="module_storage.writeFileLines"></a>
### storage.writeFileLines(filename, lines, callback) ### storage.writeFileLines(filename, lines, [callback])
<p>Fully write or rewrite the datafile</p> <p>Fully write or rewrite the datafile.</p>
**Kind**: static method of [<code>storage</code>](#module_storage) **Kind**: static method of [<code>storage</code>](#module_storage)
**Params**
| Param | Type | - filename <code>string</code>
| --- | --- | - lines <code>Array.&lt;string&gt;</code>
| filename | <code>string</code> | - [callback] [<code>NoParamCallback</code>](#NoParamCallback) <code> = () &#x3D;&gt; {}</code>
| lines | <code>Array.&lt;string&gt;</code> |
| callback | [<code>NoParamCallback</code>](#NoParamCallback) |
<a name="module_storage.writeFileLinesAsync"></a> <a name="module_storage.writeFileLinesAsync"></a>
### storage.writeFileLinesAsync(filename, lines) ⇒ <code>Promise.&lt;void&gt;</code> ### storage.writeFileLinesAsync(filename, lines) ⇒ <code>Promise.&lt;void&gt;</code>
<p>Fully write or rewrite the datafile</p> <p>Async version of [writeFileLines](#module_storage.writeFileLines).</p>
**Kind**: static method of [<code>storage</code>](#module_storage) **Kind**: static method of [<code>storage</code>](#module_storage)
**See**: module:storage.writeFileLines
**Params**
| Param | Type | - filename <code>string</code>
| --- | --- | - lines <code>Array.&lt;string&gt;</code>
| filename | <code>string</code> |
| lines | <code>Array.&lt;string&gt;</code> |
<a name="module_storage.crashSafeWriteFileLines"></a> <a name="module_storage.crashSafeWriteFileLines"></a>
### storage.crashSafeWriteFileLines(filename, lines, [callback]) ### storage.crashSafeWriteFileLines(filename, lines, [callback])
<p>Fully write or rewrite the datafile, immune to crashes during the write operation (data will not be lost)</p> <p>Fully write or rewrite the datafile, immune to crashes during the write operation (data will not be lost).</p>
**Kind**: static method of [<code>storage</code>](#module_storage) **Kind**: static method of [<code>storage</code>](#module_storage)
**Params**
| Param | Type | Description | - filename <code>string</code>
| --- | --- | --- | - lines <code>Array.&lt;string&gt;</code>
| filename | <code>string</code> | | - [callback] [<code>NoParamCallback</code>](#NoParamCallback) - <p>Optional callback, signature: err</p>
| lines | <code>Array.&lt;string&gt;</code> | |
| [callback] | [<code>NoParamCallback</code>](#NoParamCallback) | <p>Optional callback, signature: err</p> |
<a name="module_storage.crashSafeWriteFileLinesAsync"></a> <a name="module_storage.crashSafeWriteFileLinesAsync"></a>
### storage.crashSafeWriteFileLinesAsync(filename, lines) ⇒ <code>Promise.&lt;void&gt;</code> ### storage.crashSafeWriteFileLinesAsync(filename, lines) ⇒ <code>Promise.&lt;void&gt;</code>
<p>Fully write or rewrite the datafile, immune to crashes during the write operation (data will not be lost)</p> <p>Async version of [crashSafeWriteFileLines](#module_storage.crashSafeWriteFileLines).</p>
**Kind**: static method of [<code>storage</code>](#module_storage) **Kind**: static method of [<code>storage</code>](#module_storage)
**See**: module:storage.crashSafeWriteFileLines
**Params**
| Param | Type | - filename <code>string</code>
| --- | --- | - lines <code>Array.&lt;string&gt;</code>
| filename | <code>string</code> |
| lines | <code>Array.&lt;string&gt;</code> |
<a name="module_storage.ensureDatafileIntegrity"></a> <a name="module_storage.ensureDatafileIntegrity"></a>
### storage.ensureDatafileIntegrity(filename, callback) ### storage.ensureDatafileIntegrity(filename, callback)
<p>Ensure the datafile contains all the data, even if there was a crash during a full file write</p> <p>Ensure the datafile contains all the data, even if there was a crash during a full file write.</p>
**Kind**: static method of [<code>storage</code>](#module_storage) **Kind**: static method of [<code>storage</code>](#module_storage)
**Params**
| Param | Type | Description | - filename <code>string</code>
| --- | --- | --- | - callback [<code>NoParamCallback</code>](#NoParamCallback) - <p>signature: err</p>
| filename | <code>string</code> | |
| callback | [<code>NoParamCallback</code>](#NoParamCallback) | <p>signature: err</p> |
<a name="module_storage.ensureDatafileIntegrityAsync"></a> <a name="module_storage.ensureDatafileIntegrityAsync"></a>
### storage.ensureDatafileIntegrityAsync(filename) ⇒ <code>Promise.&lt;void&gt;</code> ### storage.ensureDatafileIntegrityAsync(filename) ⇒ <code>Promise.&lt;void&gt;</code>
<p>Ensure the datafile contains all the data, even if there was a crash during a full file write</p> <p>Async version of [ensureDatafileIntegrity](#module_storage.ensureDatafileIntegrity).</p>
**Kind**: static method of [<code>storage</code>](#module_storage) **Kind**: static method of [<code>storage</code>](#module_storage)
**See**: module:storage.ensureDatafileIntegrity
**Params**
| Param | Type | - filename <code>string</code>
| --- | --- |
| filename | <code>string</code> |
<a name="module_storage..existsCallback"></a> <a name="module_storage..existsCallback"></a>
### storage~existsCallback : <code>function</code> ### storage~existsCallback : <code>function</code>
**Kind**: inner typedef of [<code>storage</code>](#module_storage) **Kind**: inner typedef of [<code>storage</code>](#module_storage)
**Params**
| Param | Type | - exists <code>boolean</code>
| --- | --- |
| exists | <code>boolean</code> |

@ -1,10 +1,13 @@
<a name="module_storageBrowser"></a> <a name="module_storageBrowser"></a>
## storageBrowser ## storageBrowser
<p>Way data is stored for this database <p>Way data is stored for this database</p>
For a Node.js/Node Webkit database it's the file system <p>This version is the browser version and uses [localforage](https://github.com/localForage/localForage) which chooses the best option depending on user browser (IndexedDB then WebSQL then localStorage).</p>
For a browser-side database it's localforage which chooses the best option depending on user browser (IndexedDB then WebSQL then localStorage)</p>
<p>This version is the browser version</p> **See**
- module:storage
- module:storageReactNative
* [storageBrowser](#module_storageBrowser) * [storageBrowser](#module_storageBrowser)
@ -33,37 +36,37 @@ For a browser-side database it's localforage which chooses the best option depen
<a name="module_storageBrowser.existsAsync"></a> <a name="module_storageBrowser.existsAsync"></a>
### storageBrowser.existsAsync(file) ⇒ <code>Promise.&lt;boolean&gt;</code> ### storageBrowser.existsAsync(file) ⇒ <code>Promise.&lt;boolean&gt;</code>
<p>Returns Promise<true> if file exists</p> <p>Returns Promise<true> if file exists.</p>
<p>Async version of [exists](#module_storageBrowser.exists).</p>
**Kind**: static method of [<code>storageBrowser</code>](#module_storageBrowser) **Kind**: static method of [<code>storageBrowser</code>](#module_storageBrowser)
**See**: module:storageBrowser.exists
**Params**
| Param | Type | - file <code>string</code>
| --- | --- |
| file | <code>string</code> |
<a name="module_storageBrowser.exists"></a> <a name="module_storageBrowser.exists"></a>
### storageBrowser.exists(file, cb) ### storageBrowser.exists(file, cb)
<p>Callback returns true if file exists</p> <p>Callback returns true if file exists.</p>
**Kind**: static method of [<code>storageBrowser</code>](#module_storageBrowser) **Kind**: static method of [<code>storageBrowser</code>](#module_storageBrowser)
**Params**
| Param | Type | - file <code>string</code>
| --- | --- | - cb [<code>existsCallback</code>](#module_storageBrowser..existsCallback)
| file | <code>string</code> |
| cb | [<code>existsCallback</code>](#module_storageBrowser..existsCallback) |
<a name="module_storageBrowser.renameAsync"></a> <a name="module_storageBrowser.renameAsync"></a>
### storageBrowser.renameAsync(oldPath, newPath) ⇒ <code>Promise.&lt;void&gt;</code> ### storageBrowser.renameAsync(oldPath, newPath) ⇒ <code>Promise.&lt;void&gt;</code>
<p>Moves the item from one path to another</p> <p>Async version of [rename](#module_storageBrowser.rename).</p>
**Kind**: static method of [<code>storageBrowser</code>](#module_storageBrowser) **Kind**: static method of [<code>storageBrowser</code>](#module_storageBrowser)
**See**: module:storageBrowser.rename
**Params**
| Param | Type | - oldPath <code>string</code>
| --- | --- | - newPath <code>string</code>
| oldPath | <code>string</code> |
| newPath | <code>string</code> |
<a name="module_storageBrowser.rename"></a> <a name="module_storageBrowser.rename"></a>
@ -71,25 +74,24 @@ For a browser-side database it's localforage which chooses the best option depen
<p>Moves the item from one path to another</p> <p>Moves the item from one path to another</p>
**Kind**: static method of [<code>storageBrowser</code>](#module_storageBrowser) **Kind**: static method of [<code>storageBrowser</code>](#module_storageBrowser)
**Params**
| Param | Type | - oldPath <code>string</code>
| --- | --- | - newPath <code>string</code>
| oldPath | <code>string</code> | - c [<code>NoParamCallback</code>](#NoParamCallback)
| newPath | <code>string</code> |
| c | [<code>NoParamCallback</code>](#NoParamCallback) |
<a name="module_storageBrowser.writeFileAsync"></a> <a name="module_storageBrowser.writeFileAsync"></a>
### storageBrowser.writeFileAsync(file, data, [options]) ⇒ <code>Promise.&lt;void&gt;</code> ### storageBrowser.writeFileAsync(file, data, [options]) ⇒ <code>Promise.&lt;void&gt;</code>
<p>Saves the item at given path</p> <p>Async version of [writeFile](#module_storageBrowser.writeFile).</p>
**Kind**: static method of [<code>storageBrowser</code>](#module_storageBrowser) **Kind**: static method of [<code>storageBrowser</code>](#module_storageBrowser)
**See**: module:storageBrowser.writeFile
**Params**
| Param | Type | - file <code>string</code>
| --- | --- | - data <code>string</code>
| file | <code>string</code> | - [options] <code>object</code>
| data | <code>string</code> |
| [options] | <code>object</code> |
<a name="module_storageBrowser.writeFile"></a> <a name="module_storageBrowser.writeFile"></a>
@ -97,26 +99,25 @@ For a browser-side database it's localforage which chooses the best option depen
<p>Saves the item at given path</p> <p>Saves the item at given path</p>
**Kind**: static method of [<code>storageBrowser</code>](#module_storageBrowser) **Kind**: static method of [<code>storageBrowser</code>](#module_storageBrowser)
**Params**
| Param | Type | - path <code>string</code>
| --- | --- | - data <code>string</code>
| path | <code>string</code> | - options <code>object</code>
| data | <code>string</code> | - callback <code>function</code>
| options | <code>object</code> |
| callback | <code>function</code> |
<a name="module_storageBrowser.appendFileAsync"></a> <a name="module_storageBrowser.appendFileAsync"></a>
### storageBrowser.appendFileAsync(filename, toAppend, [options]) ⇒ <code>Promise.&lt;void&gt;</code> ### storageBrowser.appendFileAsync(filename, toAppend, [options]) ⇒ <code>Promise.&lt;void&gt;</code>
<p>Append to the item at given path</p> <p>Async version of [appendFile](#module_storageBrowser.appendFile).</p>
**Kind**: static method of [<code>storageBrowser</code>](#module_storageBrowser) **Kind**: static method of [<code>storageBrowser</code>](#module_storageBrowser)
**See**: module:storageBrowser.appendFile
**Params**
| Param | Type | - filename <code>string</code>
| --- | --- | - toAppend <code>string</code>
| filename | <code>string</code> | - [options] <code>object</code>
| toAppend | <code>string</code> |
| [options] | <code>object</code> |
<a name="module_storageBrowser.appendFile"></a> <a name="module_storageBrowser.appendFile"></a>
@ -124,25 +125,24 @@ For a browser-side database it's localforage which chooses the best option depen
<p>Append to the item at given path</p> <p>Append to the item at given path</p>
**Kind**: static method of [<code>storageBrowser</code>](#module_storageBrowser) **Kind**: static method of [<code>storageBrowser</code>](#module_storageBrowser)
**Params**
| Param | Type | - filename <code>string</code>
| --- | --- | - toAppend <code>string</code>
| filename | <code>string</code> | - [options] <code>object</code>
| toAppend | <code>string</code> | - callback <code>function</code>
| [options] | <code>object</code> |
| callback | <code>function</code> |
<a name="module_storageBrowser.readFileAsync"></a> <a name="module_storageBrowser.readFileAsync"></a>
### storageBrowser.readFileAsync(filename, [options]) ⇒ <code>Promise.&lt;Buffer&gt;</code> ### storageBrowser.readFileAsync(filename, [options]) ⇒ <code>Promise.&lt;Buffer&gt;</code>
<p>Read data at given path</p> <p>Async version of [readFile](#module_storageBrowser.readFile).</p>
**Kind**: static method of [<code>storageBrowser</code>](#module_storageBrowser) **Kind**: static method of [<code>storageBrowser</code>](#module_storageBrowser)
**See**: module:storageBrowser.readFile
**Params**
| Param | Type | - filename <code>string</code>
| --- | --- | - [options] <code>object</code>
| filename | <code>string</code> |
| [options] | <code>object</code> |
<a name="module_storageBrowser.readFile"></a> <a name="module_storageBrowser.readFile"></a>
@ -150,23 +150,22 @@ For a browser-side database it's localforage which chooses the best option depen
<p>Read data at given path</p> <p>Read data at given path</p>
**Kind**: static method of [<code>storageBrowser</code>](#module_storageBrowser) **Kind**: static method of [<code>storageBrowser</code>](#module_storageBrowser)
**Params**
| Param | Type | - filename <code>string</code>
| --- | --- | - options <code>object</code>
| filename | <code>string</code> | - callback <code>function</code>
| options | <code>object</code> |
| callback | <code>function</code> |
<a name="module_storageBrowser.unlinkAsync"></a> <a name="module_storageBrowser.unlinkAsync"></a>
### storageBrowser.unlinkAsync(filename) ⇒ <code>Promise.&lt;void&gt;</code> ### storageBrowser.unlinkAsync(filename) ⇒ <code>Promise.&lt;void&gt;</code>
<p>Remove the data at given path</p> <p>Async version of [unlink](#module_storageBrowser.unlink).</p>
**Kind**: static method of [<code>storageBrowser</code>](#module_storageBrowser) **Kind**: static method of [<code>storageBrowser</code>](#module_storageBrowser)
**See**: module:storageBrowser.unlink
**Params**
| Param | Type | - filename <code>string</code>
| --- | --- |
| filename | <code>string</code> |
<a name="module_storageBrowser.unlink"></a> <a name="module_storageBrowser.unlink"></a>
@ -174,73 +173,66 @@ For a browser-side database it's localforage which chooses the best option depen
<p>Remove the data at given path</p> <p>Remove the data at given path</p>
**Kind**: static method of [<code>storageBrowser</code>](#module_storageBrowser) **Kind**: static method of [<code>storageBrowser</code>](#module_storageBrowser)
**Params**
| Param | Type | - path <code>string</code>
| --- | --- | - callback <code>function</code>
| path | <code>string</code> |
| callback | <code>function</code> |
<a name="module_storageBrowser.mkdirAsync"></a> <a name="module_storageBrowser.mkdirAsync"></a>
### storageBrowser.mkdirAsync(path, [options]) ⇒ <code>Promise.&lt;(void\|string)&gt;</code> ### storageBrowser.mkdirAsync(path, [options]) ⇒ <code>Promise.&lt;(void\|string)&gt;</code>
<p>Shim for storage.mkdirAsync, nothing to do, no directories will be used on the browser</p> <p>Shim for [mkdirAsync](#module_storage.mkdirAsync), nothing to do, no directories will be used on the browser.</p>
**Kind**: static method of [<code>storageBrowser</code>](#module_storageBrowser) **Kind**: static method of [<code>storageBrowser</code>](#module_storageBrowser)
**Params**
| Param | Type | - path <code>string</code>
| --- | --- | - [options] <code>object</code>
| path | <code>string</code> |
| [options] | <code>object</code> |
<a name="module_storageBrowser.mkdir"></a> <a name="module_storageBrowser.mkdir"></a>
### storageBrowser.mkdir(path, options, callback) ### storageBrowser.mkdir(path, options, callback)
<p>Shim for storage.mkdir, nothing to do, no directories will be used on the browser</p> <p>Shim for [mkdir](#module_storage.mkdir), nothing to do, no directories will be used on the browser.</p>
**Kind**: static method of [<code>storageBrowser</code>](#module_storageBrowser) **Kind**: static method of [<code>storageBrowser</code>](#module_storageBrowser)
**Params**
| Param | Type | - path <code>string</code>
| --- | --- | - options <code>object</code>
| path | <code>string</code> | - callback <code>function</code>
| options | <code>object</code> |
| callback | <code>function</code> |
<a name="module_storageBrowser.ensureDatafileIntegrityAsync"></a> <a name="module_storageBrowser.ensureDatafileIntegrityAsync"></a>
### storageBrowser.ensureDatafileIntegrityAsync(filename) ⇒ <code>Promise.&lt;void&gt;</code> ### storageBrowser.ensureDatafileIntegrityAsync(filename) ⇒ <code>Promise.&lt;void&gt;</code>
<p>Ensure the datafile contains all the data, even if there was a crash during a full file write <p>Shim for [ensureDatafileIntegrityAsync](#module_storage.ensureDatafileIntegrityAsync), nothing to do, no data corruption possible in the browser.</p>
Nothing to do, no data corruption possible in the browser</p>
**Kind**: static method of [<code>storageBrowser</code>](#module_storageBrowser) **Kind**: static method of [<code>storageBrowser</code>](#module_storageBrowser)
**Params**
| Param | Type | - filename <code>string</code>
| --- | --- |
| filename | <code>string</code> |
<a name="module_storageBrowser.ensureDatafileIntegrity"></a> <a name="module_storageBrowser.ensureDatafileIntegrity"></a>
### storageBrowser.ensureDatafileIntegrity(filename, callback) ### storageBrowser.ensureDatafileIntegrity(filename, callback)
<p>Ensure the datafile contains all the data, even if there was a crash during a full file write <p>Shim for [ensureDatafileIntegrity](#module_storage.ensureDatafileIntegrity), nothing to do, no data corruption possible in the browser.</p>
Nothing to do, no data corruption possible in the browser</p>
**Kind**: static method of [<code>storageBrowser</code>](#module_storageBrowser) **Kind**: static method of [<code>storageBrowser</code>](#module_storageBrowser)
**Params**
| Param | Type | Description | - filename <code>string</code>
| --- | --- | --- | - callback [<code>NoParamCallback</code>](#NoParamCallback) - <p>signature: err</p>
| filename | <code>string</code> | |
| callback | [<code>NoParamCallback</code>](#NoParamCallback) | <p>signature: err</p> |
<a name="module_storageBrowser.crashSafeWriteFileLinesAsync"></a> <a name="module_storageBrowser.crashSafeWriteFileLinesAsync"></a>
### storageBrowser.crashSafeWriteFileLinesAsync(filename, lines) ⇒ <code>Promise.&lt;void&gt;</code> ### storageBrowser.crashSafeWriteFileLinesAsync(filename, lines) ⇒ <code>Promise.&lt;void&gt;</code>
<p>Fully write or rewrite the datafile, immune to crashes during the write operation (data will not be lost)</p> <p>Async version of [crashSafeWriteFileLines](#module_storageBrowser.crashSafeWriteFileLines).</p>
**Kind**: static method of [<code>storageBrowser</code>](#module_storageBrowser) **Kind**: static method of [<code>storageBrowser</code>](#module_storageBrowser)
**See**: module:storageBrowser.crashSafeWriteFileLines
**Params**
| Param | Type | - filename <code>string</code>
| --- | --- | - lines <code>Array.&lt;string&gt;</code>
| filename | <code>string</code> |
| lines | <code>Array.&lt;string&gt;</code> |
<a name="module_storageBrowser.crashSafeWriteFileLines"></a> <a name="module_storageBrowser.crashSafeWriteFileLines"></a>
@ -248,19 +240,17 @@ Nothing to do, no data corruption possible in the browser</p>
<p>Fully write or rewrite the datafile, immune to crashes during the write operation (data will not be lost)</p> <p>Fully write or rewrite the datafile, immune to crashes during the write operation (data will not be lost)</p>
**Kind**: static method of [<code>storageBrowser</code>](#module_storageBrowser) **Kind**: static method of [<code>storageBrowser</code>](#module_storageBrowser)
**Params**
| Param | Type | Description | - filename <code>string</code>
| --- | --- | --- | - lines <code>Array.&lt;string&gt;</code>
| filename | <code>string</code> | | - [callback] [<code>NoParamCallback</code>](#NoParamCallback) - <p>Optional callback, signature: err</p>
| lines | <code>Array.&lt;string&gt;</code> | |
| [callback] | [<code>NoParamCallback</code>](#NoParamCallback) | <p>Optional callback, signature: err</p> |
<a name="module_storageBrowser..existsCallback"></a> <a name="module_storageBrowser..existsCallback"></a>
### storageBrowser~existsCallback : <code>function</code> ### storageBrowser~existsCallback : <code>function</code>
**Kind**: inner typedef of [<code>storageBrowser</code>](#module_storageBrowser) **Kind**: inner typedef of [<code>storageBrowser</code>](#module_storageBrowser)
**Params**
| Param | Type | - exists <code>boolean</code>
| --- | --- |
| exists | <code>boolean</code> |

@ -1,11 +1,13 @@
<a name="module_storageReactNative"></a> <a name="module_storageReactNative"></a>
## storageReactNative ## storageReactNative
<p>Way data is stored for this database <p>Way data is stored for this database</p>
For a Node.js/Node Webkit database it's the file system <p>This version is the React-Native version and uses [@react-native-async-storage/async-storage](https://github.com/react-native-async-storage/async-storage).</p>
For a browser-side database it's localforage, which uses the best backend available (IndexedDB then WebSQL then localStorage)
For a react-native database, we use @react-native-async-storage/async-storage</p> **See**
<p>This version is the react-native version</p>
- module:storageBrowser
- module:storageReactNative
* [storageReactNative](#module_storageReactNative) * [storageReactNative](#module_storageReactNative)
@ -34,13 +36,13 @@ For a react-native database, we use @react-native-async-storage/async-storage</p
<a name="module_storageReactNative.existsAsync"></a> <a name="module_storageReactNative.existsAsync"></a>
### storageReactNative.existsAsync(file) ⇒ <code>Promise.&lt;boolean&gt;</code> ### storageReactNative.existsAsync(file) ⇒ <code>Promise.&lt;boolean&gt;</code>
<p>Returns Promise<true> if file exists</p> <p>Async version of [exists](#module_storageReactNative.exists).</p>
**Kind**: static method of [<code>storageReactNative</code>](#module_storageReactNative) **Kind**: static method of [<code>storageReactNative</code>](#module_storageReactNative)
**See**: module:storageReactNative.exists
**Params**
| Param | Type | - file <code>string</code>
| --- | --- |
| file | <code>string</code> |
<a name="module_storageReactNative.exists"></a> <a name="module_storageReactNative.exists"></a>
@ -48,23 +50,22 @@ For a react-native database, we use @react-native-async-storage/async-storage</p
<p>Callback returns true if file exists</p> <p>Callback returns true if file exists</p>
**Kind**: static method of [<code>storageReactNative</code>](#module_storageReactNative) **Kind**: static method of [<code>storageReactNative</code>](#module_storageReactNative)
**Params**
| Param | Type | - file <code>string</code>
| --- | --- | - cb [<code>existsCallback</code>](#module_storageReactNative..existsCallback)
| file | <code>string</code> |
| cb | [<code>existsCallback</code>](#module_storageReactNative..existsCallback) |
<a name="module_storageReactNative.renameAsync"></a> <a name="module_storageReactNative.renameAsync"></a>
### storageReactNative.renameAsync(oldPath, newPath) ⇒ <code>Promise.&lt;void&gt;</code> ### storageReactNative.renameAsync(oldPath, newPath) ⇒ <code>Promise.&lt;void&gt;</code>
<p>Moves the item from one path to another</p> <p>Async version of [rename](#module_storageReactNative.rename).</p>
**Kind**: static method of [<code>storageReactNative</code>](#module_storageReactNative) **Kind**: static method of [<code>storageReactNative</code>](#module_storageReactNative)
**See**: module:storageReactNative.rename
**Params**
| Param | Type | - oldPath <code>string</code>
| --- | --- | - newPath <code>string</code>
| oldPath | <code>string</code> |
| newPath | <code>string</code> |
<a name="module_storageReactNative.rename"></a> <a name="module_storageReactNative.rename"></a>
@ -72,25 +73,24 @@ For a react-native database, we use @react-native-async-storage/async-storage</p
<p>Moves the item from one path to another</p> <p>Moves the item from one path to another</p>
**Kind**: static method of [<code>storageReactNative</code>](#module_storageReactNative) **Kind**: static method of [<code>storageReactNative</code>](#module_storageReactNative)
**Params**
| Param | Type | - oldPath <code>string</code>
| --- | --- | - newPath <code>string</code>
| oldPath | <code>string</code> | - c [<code>NoParamCallback</code>](#NoParamCallback)
| newPath | <code>string</code> |
| c | [<code>NoParamCallback</code>](#NoParamCallback) |
<a name="module_storageReactNative.writeFileAsync"></a> <a name="module_storageReactNative.writeFileAsync"></a>
### storageReactNative.writeFileAsync(file, data, [options]) ⇒ <code>Promise.&lt;void&gt;</code> ### storageReactNative.writeFileAsync(file, data, [options]) ⇒ <code>Promise.&lt;void&gt;</code>
<p>Saves the item at given path</p> <p>Async version of [writeFile](#module_storageReactNative.writeFile).</p>
**Kind**: static method of [<code>storageReactNative</code>](#module_storageReactNative) **Kind**: static method of [<code>storageReactNative</code>](#module_storageReactNative)
**See**: module:storageReactNative.writeFile
**Params**
| Param | Type | - file <code>string</code>
| --- | --- | - data <code>string</code>
| file | <code>string</code> | - [options] <code>object</code>
| data | <code>string</code> |
| [options] | <code>object</code> |
<a name="module_storageReactNative.writeFile"></a> <a name="module_storageReactNative.writeFile"></a>
@ -98,26 +98,25 @@ For a react-native database, we use @react-native-async-storage/async-storage</p
<p>Saves the item at given path</p> <p>Saves the item at given path</p>
**Kind**: static method of [<code>storageReactNative</code>](#module_storageReactNative) **Kind**: static method of [<code>storageReactNative</code>](#module_storageReactNative)
**Params**
| Param | Type | - path <code>string</code>
| --- | --- | - data <code>string</code>
| path | <code>string</code> | - options <code>object</code>
| data | <code>string</code> | - callback <code>function</code>
| options | <code>object</code> |
| callback | <code>function</code> |
<a name="module_storageReactNative.appendFileAsync"></a> <a name="module_storageReactNative.appendFileAsync"></a>
### storageReactNative.appendFileAsync(filename, toAppend, [options]) ⇒ <code>Promise.&lt;void&gt;</code> ### storageReactNative.appendFileAsync(filename, toAppend, [options]) ⇒ <code>Promise.&lt;void&gt;</code>
<p>Append to the item at given path</p> <p>Async version of [appendFile](#module_storageReactNative.appendFile).</p>
**Kind**: static method of [<code>storageReactNative</code>](#module_storageReactNative) **Kind**: static method of [<code>storageReactNative</code>](#module_storageReactNative)
**See**: module:storageReactNative.appendFile
**Params**
| Param | Type | - filename <code>string</code>
| --- | --- | - toAppend <code>string</code>
| filename | <code>string</code> | - [options] <code>object</code>
| toAppend | <code>string</code> |
| [options] | <code>object</code> |
<a name="module_storageReactNative.appendFile"></a> <a name="module_storageReactNative.appendFile"></a>
@ -125,25 +124,24 @@ For a react-native database, we use @react-native-async-storage/async-storage</p
<p>Append to the item at given path</p> <p>Append to the item at given path</p>
**Kind**: static method of [<code>storageReactNative</code>](#module_storageReactNative) **Kind**: static method of [<code>storageReactNative</code>](#module_storageReactNative)
**Params**
| Param | Type | - filename <code>string</code>
| --- | --- | - toAppend <code>string</code>
| filename | <code>string</code> | - [options] <code>object</code>
| toAppend | <code>string</code> | - callback <code>function</code>
| [options] | <code>object</code> |
| callback | <code>function</code> |
<a name="module_storageReactNative.readFileAsync"></a> <a name="module_storageReactNative.readFileAsync"></a>
### storageReactNative.readFileAsync(filename, [options]) ⇒ <code>Promise.&lt;string&gt;</code> ### storageReactNative.readFileAsync(filename, [options]) ⇒ <code>Promise.&lt;string&gt;</code>
<p>Read data at given path</p> <p>Async version of [readFile](#module_storageReactNative.readFile).</p>
**Kind**: static method of [<code>storageReactNative</code>](#module_storageReactNative) **Kind**: static method of [<code>storageReactNative</code>](#module_storageReactNative)
**See**: module:storageReactNative.readFile
**Params**
| Param | Type | - filename <code>string</code>
| --- | --- | - [options] <code>object</code>
| filename | <code>string</code> |
| [options] | <code>object</code> |
<a name="module_storageReactNative.readFile"></a> <a name="module_storageReactNative.readFile"></a>
@ -151,23 +149,22 @@ For a react-native database, we use @react-native-async-storage/async-storage</p
<p>Read data at given path</p> <p>Read data at given path</p>
**Kind**: static method of [<code>storageReactNative</code>](#module_storageReactNative) **Kind**: static method of [<code>storageReactNative</code>](#module_storageReactNative)
**Params**
| Param | Type | - filename <code>string</code>
| --- | --- | - options <code>object</code>
| filename | <code>string</code> | - callback <code>function</code>
| options | <code>object</code> |
| callback | <code>function</code> |
<a name="module_storageReactNative.unlinkAsync"></a> <a name="module_storageReactNative.unlinkAsync"></a>
### storageReactNative.unlinkAsync(filename) ⇒ <code>Promise.&lt;void&gt;</code> ### storageReactNative.unlinkAsync(filename) ⇒ <code>Promise.&lt;void&gt;</code>
<p>Remove the data at given path</p> <p>Async version of [unlink](#module_storageReactNative.unlink).</p>
**Kind**: static method of [<code>storageReactNative</code>](#module_storageReactNative) **Kind**: static method of [<code>storageReactNative</code>](#module_storageReactNative)
**See**: module:storageReactNative.unlink
**Params**
| Param | Type | - filename <code>string</code>
| --- | --- |
| filename | <code>string</code> |
<a name="module_storageReactNative.unlink"></a> <a name="module_storageReactNative.unlink"></a>
@ -175,73 +172,66 @@ For a react-native database, we use @react-native-async-storage/async-storage</p
<p>Remove the data at given path</p> <p>Remove the data at given path</p>
**Kind**: static method of [<code>storageReactNative</code>](#module_storageReactNative) **Kind**: static method of [<code>storageReactNative</code>](#module_storageReactNative)
**Params**
| Param | Type | - path <code>string</code>
| --- | --- | - callback <code>function</code>
| path | <code>string</code> |
| callback | <code>function</code> |
<a name="module_storageReactNative.mkdirAsync"></a> <a name="module_storageReactNative.mkdirAsync"></a>
### storageReactNative.mkdirAsync(dir, [options]) ⇒ <code>Promise.&lt;(void\|string)&gt;</code> ### storageReactNative.mkdirAsync(dir, [options]) ⇒ <code>Promise.&lt;(void\|string)&gt;</code>
<p>Shim for storage.mkdirAsync, nothing to do, no directories will be used on the browser</p> <p>Shim for [mkdirAsync](#module_storage.mkdirAsync), nothing to do, no directories will be used on the browser.</p>
**Kind**: static method of [<code>storageReactNative</code>](#module_storageReactNative) **Kind**: static method of [<code>storageReactNative</code>](#module_storageReactNative)
**Params**
| Param | Type | - dir <code>string</code>
| --- | --- | - [options] <code>object</code>
| dir | <code>string</code> |
| [options] | <code>object</code> |
<a name="module_storageReactNative.mkdir"></a> <a name="module_storageReactNative.mkdir"></a>
### storageReactNative.mkdir(path, options, callback) ### storageReactNative.mkdir(path, options, callback)
<p>Shim for storage.mkdir, nothing to do, no directories will be used on the browser</p> <p>Shim for [mkdir](#module_storage.mkdir), nothing to do, no directories will be used on the browser.</p>
**Kind**: static method of [<code>storageReactNative</code>](#module_storageReactNative) **Kind**: static method of [<code>storageReactNative</code>](#module_storageReactNative)
**Params**
| Param | Type | - path <code>string</code>
| --- | --- | - options <code>object</code>
| path | <code>string</code> | - callback <code>function</code>
| options | <code>object</code> |
| callback | <code>function</code> |
<a name="module_storageReactNative.ensureDatafileIntegrityAsync"></a> <a name="module_storageReactNative.ensureDatafileIntegrityAsync"></a>
### storageReactNative.ensureDatafileIntegrityAsync(filename) ⇒ <code>Promise.&lt;void&gt;</code> ### storageReactNative.ensureDatafileIntegrityAsync(filename) ⇒ <code>Promise.&lt;void&gt;</code>
<p>Ensure the datafile contains all the data, even if there was a crash during a full file write <p>Shim for [ensureDatafileIntegrityAsync](#module_storage.ensureDatafileIntegrityAsync), nothing to do, no data corruption possible in the browser.</p>
Nothing to do, no data corruption possible in the browser</p>
**Kind**: static method of [<code>storageReactNative</code>](#module_storageReactNative) **Kind**: static method of [<code>storageReactNative</code>](#module_storageReactNative)
**Params**
| Param | Type | - filename <code>string</code>
| --- | --- |
| filename | <code>string</code> |
<a name="module_storageReactNative.ensureDatafileIntegrity"></a> <a name="module_storageReactNative.ensureDatafileIntegrity"></a>
### storageReactNative.ensureDatafileIntegrity(filename, callback) ### storageReactNative.ensureDatafileIntegrity(filename, callback)
<p>Ensure the datafile contains all the data, even if there was a crash during a full file write <p>Shim for [ensureDatafileIntegrity](#module_storage.ensureDatafileIntegrity), nothing to do, no data corruption possible in the browser.</p>
Nothing to do, no data corruption possible in the browser</p>
**Kind**: static method of [<code>storageReactNative</code>](#module_storageReactNative) **Kind**: static method of [<code>storageReactNative</code>](#module_storageReactNative)
**Params**
| Param | Type | Description | - filename <code>string</code>
| --- | --- | --- | - callback [<code>NoParamCallback</code>](#NoParamCallback) - <p>signature: err</p>
| filename | <code>string</code> | |
| callback | [<code>NoParamCallback</code>](#NoParamCallback) | <p>signature: err</p> |
<a name="module_storageReactNative.crashSafeWriteFileLinesAsync"></a> <a name="module_storageReactNative.crashSafeWriteFileLinesAsync"></a>
### storageReactNative.crashSafeWriteFileLinesAsync(filename, lines) ⇒ <code>Promise.&lt;void&gt;</code> ### storageReactNative.crashSafeWriteFileLinesAsync(filename, lines) ⇒ <code>Promise.&lt;void&gt;</code>
<p>Fully write or rewrite the datafile, immune to crashes during the write operation (data will not be lost)</p> <p>Async version of [crashSafeWriteFileLines](#module_storageReactNative.crashSafeWriteFileLines).</p>
**Kind**: static method of [<code>storageReactNative</code>](#module_storageReactNative) **Kind**: static method of [<code>storageReactNative</code>](#module_storageReactNative)
**See**: module:storageReactNative.crashSafeWriteFileLines
**Params**
| Param | Type | - filename <code>string</code>
| --- | --- | - lines <code>Array.&lt;string&gt;</code>
| filename | <code>string</code> |
| lines | <code>Array.&lt;string&gt;</code> |
<a name="module_storageReactNative.crashSafeWriteFileLines"></a> <a name="module_storageReactNative.crashSafeWriteFileLines"></a>
@ -249,19 +239,17 @@ Nothing to do, no data corruption possible in the browser</p>
<p>Fully write or rewrite the datafile, immune to crashes during the write operation (data will not be lost)</p> <p>Fully write or rewrite the datafile, immune to crashes during the write operation (data will not be lost)</p>
**Kind**: static method of [<code>storageReactNative</code>](#module_storageReactNative) **Kind**: static method of [<code>storageReactNative</code>](#module_storageReactNative)
**Params**
| Param | Type | Description | - filename <code>string</code>
| --- | --- | --- | - lines <code>Array.&lt;string&gt;</code>
| filename | <code>string</code> | | - [callback] [<code>NoParamCallback</code>](#NoParamCallback) - <p>Optional callback, signature: err</p>
| lines | <code>Array.&lt;string&gt;</code> | |
| [callback] | [<code>NoParamCallback</code>](#NoParamCallback) | <p>Optional callback, signature: err</p> |
<a name="module_storageReactNative..existsCallback"></a> <a name="module_storageReactNative..existsCallback"></a>
### storageReactNative~existsCallback : <code>function</code> ### storageReactNative~existsCallback : <code>function</code>
**Kind**: inner typedef of [<code>storageReactNative</code>](#module_storageReactNative) **Kind**: inner typedef of [<code>storageReactNative</code>](#module_storageReactNative)
**Params**
| Param | Type | - exists <code>boolean</code>
| --- | --- |
| exists | <code>boolean</code> |

@ -18,50 +18,47 @@ This replaces the underscore dependency.</p>
### utils.uniq(array, [iteratee]) ⇒ <code>Array</code> ### utils.uniq(array, [iteratee]) ⇒ <code>Array</code>
<p>Produces a duplicate-free version of the array, using === to test object equality. In particular only the first <p>Produces a duplicate-free version of the array, using === to test object equality. In particular only the first
occurrence of each value is kept. If you want to compute unique items based on a transformation, pass an iteratee occurrence of each value is kept. If you want to compute unique items based on a transformation, pass an iteratee
function. function.</p>
Heavily inspired by https://underscorejs.org/#uniq</p> <p>Heavily inspired by [https://underscorejs.org/#uniq](https://underscorejs.org/#uniq).</p>
**Kind**: static method of [<code>utils</code>](#module_utils) **Kind**: static method of [<code>utils</code>](#module_utils)
**Params**
| Param | Type | Description | - array <code>Array</code>
| --- | --- | --- | - [iteratee] <code>function</code> - <p>transformation applied to every element before checking for duplicates. This will not
| array | <code>Array</code> | | transform the items in the result.</p>
| [iteratee] | <code>function</code> | <p>transformation applied to every element before checking for duplicates. This will not transform the items in the result.</p> |
<a name="module_utils.isDate"></a> <a name="module_utils.isDate"></a>
### utils.isDate(d) ⇒ <code>boolean</code> ### utils.isDate(d) ⇒ <code>boolean</code>
<p>Returns true if d is a Date. <p>Returns true if d is a Date.</p>
Heavily inspired by https://underscorejs.org/#isDate</p> <p>Heavily inspired by [https://underscorejs.org/#isDate](https://underscorejs.org/#isDate).</p>
**Kind**: static method of [<code>utils</code>](#module_utils) **Kind**: static method of [<code>utils</code>](#module_utils)
**Params**
| Param | Type | - d <code>\*</code>
| --- | --- |
| d | <code>\*</code> |
<a name="module_utils.isRegExp"></a> <a name="module_utils.isRegExp"></a>
### utils.isRegExp(re) ⇒ <code>boolean</code> ### utils.isRegExp(re) ⇒ <code>boolean</code>
<p>Returns true if re is a RegExp. <p>Returns true if re is a RegExp.</p>
Heavily inspired by https://underscorejs.org/#isRegExp</p> <p>Heavily inspired by [https://underscorejs.org/#isRegExp](https://underscorejs.org/#isRegExp).</p>
**Kind**: static method of [<code>utils</code>](#module_utils) **Kind**: static method of [<code>utils</code>](#module_utils)
**Params**
| Param | Type | - re <code>\*</code>
| --- | --- |
| re | <code>\*</code> |
<a name="module_utils..isObject"></a> <a name="module_utils..isObject"></a>
### utils~isObject(arg) ⇒ <code>boolean</code> ### utils~isObject(arg) ⇒ <code>boolean</code>
<p>Returns true if arg is an Object. Note that JavaScript arrays and functions are objects, while (normal) strings <p>Returns true if arg is an Object. Note that JavaScript arrays and functions are objects, while (normal) strings
and numbers are not. and numbers are not.</p>
Heavily inspired by https://underscorejs.org/#isObject</p> <p>Heavily inspired by [https://underscorejs.org/#isObject](https://underscorejs.org/#isObject).</p>
**Kind**: inner method of [<code>utils</code>](#module_utils) **Kind**: inner method of [<code>utils</code>](#module_utils)
**Params**
| Param | Type | - arg <code>\*</code>
| --- | --- |
| arg | <code>\*</code> |

@ -15,6 +15,10 @@ const getJsdocDataOptions = {
'no-cache': true 'no-cache': true
} }
const renderOptions = {
'param-list-format': 'list'
}
fs.rmdirSync(outputDir, { recursive: true }) // clean docs dir fs.rmdirSync(outputDir, { recursive: true }) // clean docs dir
fs.mkdirSync(outputDir) // make docs dir fs.mkdirSync(outputDir) // make docs dir
@ -22,15 +26,24 @@ fs.mkdirSync(outputDir) // make docs dir
const templateData = jsdoc2md.getTemplateDataSync(getJsdocDataOptions) const templateData = jsdoc2md.getTemplateDataSync(getJsdocDataOptions)
/* reduce templateData to an array of class names */ /* reduce templateData to an array of class names */
const classNames = templateData.filter(({ kind }) => kind === 'class').map(({ name }) => name) const classNames = templateData
.filter(({ kind, access }) => kind === 'class' && access !== 'private')
.map(({ name }) => name)
const moduleNames = templateData
.filter(({ kind, access }) => kind === 'module' && access !== 'private')
.map(({ name }) => name)
const moduleNames = templateData.filter(({ kind }) => kind === 'module').map(({ name }) => name) const rest = templateData
.filter(({ name }) => !moduleNames.includes(name) && !classNames.includes(name))
.filter(({ scope, access }) => scope === 'global' && access !== 'private')
.map(({ id }) => id)
/* create a documentation file for each class */ /* create a documentation file for each class */
for (const className of classNames) { for (const className of classNames) {
const template = `{{#class name="${className}"}}{{>docs}}{{/class}}` const template = `{{#class name="${className}"}}{{>docs}}{{/class}}`
console.log(`rendering ${className}, template: ${template}`) console.log(`rendering ${className}, template: ${template}`)
const output = jsdoc2md.renderSync({ data: templateData, template: template }) const output = jsdoc2md.renderSync({ ...renderOptions, data: templateData, template: template })
fs.writeFileSync(path.resolve(outputDir, `${className}.md`), output) fs.writeFileSync(path.resolve(outputDir, `${className}.md`), output)
} }
@ -38,6 +51,16 @@ for (const className of classNames) {
for (const moduleName of moduleNames) { for (const moduleName of moduleNames) {
const template = `{{#module name="${moduleName}"}}{{>docs}}{{/module}}` const template = `{{#module name="${moduleName}"}}{{>docs}}{{/module}}`
console.log(`rendering ${moduleName}, template: ${template}`) console.log(`rendering ${moduleName}, template: ${template}`)
const output = jsdoc2md.renderSync({ data: templateData, template: template }) const output = jsdoc2md.renderSync({ ...renderOptions, data: templateData, template: template })
fs.writeFileSync(path.resolve(outputDir, `${moduleName}.md`), output) fs.writeFileSync(path.resolve(outputDir, `${moduleName}.md`), output)
} }
let template = ''
for (const id of rest) {
template += `{{#identifier name="${id}"}}{{>docs}}{{/identifier}}\n`
}
console.log(`rendering globals, template: ${template}`)
const output = jsdoc2md.renderSync({ ...renderOptions, data: templateData, template: template })
fs.writeFileSync(path.resolve(outputDir, 'globals.md'), output)
// TODO rewrite links between files

@ -2,21 +2,23 @@ const model = require('./model.js')
const { callbackify, promisify } = require('util') const { callbackify, promisify } = require('util')
/** /**
* @callback Cursor~execFn * Has a callback
* @callback Cursor~execFnWithCallback
* @param {?Error} err * @param {?Error} err
* @param {?document[]|?document} res * @param {?document[]|?document} res
*/ */
/** /**
* @callback Cursor~execFnAsync * Does not have a callback, may return a Promise.
* @callback Cursor~execFnWithoutCallback
* @param {?document[]|?document} res * @param {?document[]|?document} res
* @return {Promise} * @return {Promise|*}
*/ */
/** /**
* Manage access to data, be it to find, update or remove it. * Manage access to data, be it to find, update or remove it.
* *
* It extends Promise so that its methods are chainable & awaitable. * It extends `Promise` so that its methods (which return `this`) are chainable & awaitable.
* @extends Promise * @extends Promise
*/ */
class Cursor { class Cursor {
@ -24,18 +26,55 @@ class Cursor {
* Create a new cursor for this collection * Create a new cursor for this collection
* @param {Datastore} db - The datastore this cursor is bound to * @param {Datastore} db - The datastore this cursor is bound to
* @param {query} query - The query this cursor will operate on * @param {query} query - The query this cursor will operate on
* @param {Cursor~execFn|Cursor~execFnAsync} [execFn] - Handler to be executed after cursor has found the results and before the callback passed to find/findOne/update/remove * @param {Cursor~execFnWithoutCallback|Cursor~execFnWithCallback} [execFn] - Handler to be executed after cursor has found the results and before the callback passed to find/findOne/update/remove
* @param {boolean} [async = false] If true, specifies that the `execFn` is of type {@link Cursor~execFnAsync} rather than {@link Cursor~execFn}. * @param {boolean} [hasCallback = true] If false, specifies that the `execFn` is of type {@link Cursor~execFnWithoutCallback} rather than {@link Cursor~execFnWithCallback}.
* */
constructor (db, query, execFn, hasCallback = true) {
/**
* @protected
* @type {Datastore}
*/ */
constructor (db, query, execFn, async = false) {
this.db = db this.db = db
/**
* @protected
* @type {query}
*/
this.query = query || {} this.query = query || {}
/**
* The handler to be executed after cursor has found the results.
* @type {Cursor~execFnWithoutCallback|Cursor~execFnWithCallback|undefined}
* @protected
*/
if (execFn) this.execFn = execFn if (execFn) this.execFn = execFn
if (async) this.async = true /**
* Determines if the {@link Cursor#execFn} is an {@link Cursor~execFnWithoutCallback} or not.
* @protected
* @type {boolean}
*/
this.hasCallback = hasCallback
/**
* @see Cursor#limit
* @type {undefined|number}
* @private
*/
this._limit = undefined this._limit = undefined
/**
* @see Cursor#skip
* @type {undefined|number}
* @private
*/
this._skip = undefined this._skip = undefined
/**
* @see Cursor#sort
* @type {undefined|Object.<string, number>}
* @private
*/
this._sort = undefined this._sort = undefined
/**
* @see Cursor#projection
* @type {undefined|Object.<string, number>}
* @private
*/
this._projection = undefined this._projection = undefined
} }
@ -81,9 +120,12 @@ class Cursor {
} }
/** /**
* Apply the projection * Apply the projection.
*
* This is an internal function. You should use {@link Cursor#execAsync} or {@link Cursor#exec}.
* @param {document[]} candidates * @param {document[]} candidates
* @return {document[]} * @return {document[]}
* @protected
*/ */
project (candidates) { project (candidates) {
const res = [] const res = []
@ -185,7 +227,7 @@ class Cursor {
} catch (e) { } catch (e) {
error = e error = e
} }
if (this.execFn && !this.async) return promisify(this.execFn)(error, res) if (this.execFn && this.hasCallback) return promisify(this.execFn)(error, res)
else if (error) throw error else if (error) throw error
else if (this.execFn) return this.execFn(res) else if (this.execFn) return this.execFn(res)
else return res else return res
@ -200,8 +242,11 @@ class Cursor {
/** /**
* Get all matching elements * Get all matching elements
* Will return pointers to matched elements (shallow copies), returning full copies is the role of find or findOne * Will return pointers to matched elements (shallow copies), returning full copies is the role of find or findOne
* This is an internal function, use exec which uses the executor *
* This is an internal function, use {@link Cursor#exec} which uses the [executor]{@link Datastore#executor}.
* @param {Cursor~execCallback} _callback * @param {Cursor~execCallback} _callback
* @protected
* @see Cursor#exec
*/ */
_exec (_callback) { _exec (_callback) {
callbackify(this._execAsync.bind(this))(_callback) callbackify(this._execAsync.bind(this))(_callback)
@ -217,10 +262,10 @@ class Cursor {
} }
/** /**
* Get all matching elements * Async version of {@link Cursor#exec}.
* Will return pointers to matched elements (shallow copies), returning full copies is the role of find or findOne
* @return {Promise<document[]|*>} * @return {Promise<document[]|*>}
* @async * @async
* @see Cursor#exec
*/ */
execAsync () { execAsync () {
return this.db.executor.pushAsync(() => this._execAsync()) return this.db.executor.pushAsync(() => this._execAsync())

@ -53,7 +53,7 @@ const { isDate } = require('./utils.js')
* It happens when calling `datastore.persistence.compactDatafile`, which is called periodically if you have called * It happens when calling `datastore.persistence.compactDatafile`, which is called periodically if you have called
* `datastore.persistence.setAutocompactionInterval`. * `datastore.persistence.setAutocompactionInterval`.
* *
* @event Datastore.event:"compaction.done" * @event Datastore#event:"compaction.done"
* @type {undefined} * @type {undefined}
*/ */
@ -175,7 +175,7 @@ class Datastore extends EventEmitter {
* OS X and Windows. Now that you can use `require('nw.gui').App.dataPath` in Node Webkit to get the path to the data * OS X and Windows. Now that you can use `require('nw.gui').App.dataPath` in Node Webkit to get the path to the data
* directory for your application, you should not use this option anymore and it will be removed. * directory for your application, you should not use this option anymore and it will be removed.
* *
* @fires Datastore.event:"compaction.done" * @fires Datastore#event:"compaction.done"
*/ */
constructor (options) { constructor (options) {
super() super()
@ -194,19 +194,19 @@ class Datastore extends EventEmitter {
* Determines if the `Datastore` keeps data in-memory, or if it saves it in storage. Is not read after * Determines if the `Datastore` keeps data in-memory, or if it saves it in storage. Is not read after
* instanciation. * instanciation.
* @type {boolean} * @type {boolean}
* @private * @protected
*/ */
this.inMemoryOnly = options.inMemoryOnly || false this.inMemoryOnly = options.inMemoryOnly || false
/** /**
* Determines if the `Datastore` should autoload the database upon instantiation. Is not read after instanciation. * Determines if the `Datastore` should autoload the database upon instantiation. Is not read after instanciation.
* @type {boolean} * @type {boolean}
* @private * @protected
*/ */
this.autoload = options.autoload || false this.autoload = options.autoload || false
/** /**
* Determines if the `Datastore` should add `createdAt` and `updatedAt` fields automatically if not set by the user. * Determines if the `Datastore` should add `createdAt` and `updatedAt` fields automatically if not set by the user.
* @type {boolean} * @type {boolean}
* @private * @protected
*/ */
this.timestampData = options.timestampData || false this.timestampData = options.timestampData || false
} }
@ -217,7 +217,7 @@ class Datastore extends EventEmitter {
* If null, it means `inMemoryOnly` is `true`. The `filename` is the name given to the storage module. Is not read * If null, it means `inMemoryOnly` is `true`. The `filename` is the name given to the storage module. Is not read
* after instanciation. * after instanciation.
* @type {?string} * @type {?string}
* @private * @protected
*/ */
this.filename = null this.filename = null
this.inMemoryOnly = true this.inMemoryOnly = true
@ -230,7 +230,8 @@ class Datastore extends EventEmitter {
* Overrides default string comparison which is not well adapted to non-US characters in particular accented * Overrides default string comparison which is not well adapted to non-US characters in particular accented
* letters. Native `localCompare` will most of the time be the right choice * letters. Native `localCompare` will most of the time be the right choice
* @type {compareStrings} * @type {compareStrings}
* @private * @function
* @protected
*/ */
this.compareStrings = options.compareStrings this.compareStrings = options.compareStrings
@ -254,6 +255,7 @@ class Datastore extends EventEmitter {
* produced by the `Datastore` and by `this.persistence.compactDataFile` & `this.persistence.compactDataFileAsync` * produced by the `Datastore` and by `this.persistence.compactDataFile` & `this.persistence.compactDataFileAsync`
* to ensure operations are performed sequentially in the database. * to ensure operations are performed sequentially in the database.
* @type {Executor} * @type {Executor}
* @protected
*/ */
this.executor = new Executor() this.executor = new Executor()
if (this.inMemoryOnly) this.executor.ready = true if (this.inMemoryOnly) this.executor.ready = true
@ -262,7 +264,7 @@ class Datastore extends EventEmitter {
* Indexed by field name, dot notation can be used. * Indexed by field name, dot notation can be used.
* _id is always indexed and since _ids are generated randomly the underlying binary search tree is always well-balanced * _id is always indexed and since _ids are generated randomly the underlying binary search tree is always well-balanced
* @type {Object.<string, Index>} * @type {Object.<string, Index>}
* @private * @protected
*/ */
this.indexes = {} this.indexes = {}
this.indexes._id = new Index({ fieldName: '_id', unique: true }) this.indexes._id = new Index({ fieldName: '_id', unique: true })
@ -270,7 +272,7 @@ class Datastore extends EventEmitter {
* Stores the time to live (TTL) of the indexes created. The key represents the field name, the value the number of * Stores the time to live (TTL) of the indexes created. The key represents the field name, the value the number of
* seconds after which data with this index field should be removed. * seconds after which data with this index field should be removed.
* @type {Object.<string, number>} * @type {Object.<string, number>}
* @private * @protected
*/ */
this.ttlIndexes = {} this.ttlIndexes = {}
@ -303,16 +305,17 @@ class Datastore extends EventEmitter {
} }
/** /**
* Load the database from the datafile, and trigger the execution of buffered commands if any. * Async version of {@link Datastore#loadDatabase}.
* @async * @async
* @return {Promise} * @return {Promise}
* @see Datastore#loadDatabase
*/ */
loadDatabaseAsync () { loadDatabaseAsync () {
return this.executor.pushAsync(() => this.persistence.loadDatabaseAsync(), true) return this.executor.pushAsync(() => this.persistence.loadDatabaseAsync(), true)
} }
/** /**
* Get an array of all the data in the database * Get an array of all the data in the database.
* @return {document[]} * @return {document[]}
*/ */
getAllData () { getAllData () {
@ -320,7 +323,8 @@ class Datastore extends EventEmitter {
} }
/** /**
* Reset all currently defined indexes * Reset all currently defined indexes.
* @param {?document|?document[]} newData
*/ */
resetIndexes (newData) { resetIndexes (newData) {
for (const index of Object.values(this.indexes)) { for (const index of Object.values(this.indexes)) {
@ -346,16 +350,14 @@ class Datastore extends EventEmitter {
} }
/** /**
* Ensure an index is kept for this field. Same parameters as lib/indexes * Async version of {@link Datastore#ensureIndex}.
* This function acts synchronously on the indexes, however the persistence of the indexes is deferred with the
* executor.
* Previous versions said explicitly the callback was optional, it is now recommended setting one.
* @param {object} options * @param {object} options
* @param {string} options.fieldName Name of the field to index. Use the dot notation to index a field in a nested document. * @param {string} options.fieldName Name of the field to index. Use the dot notation to index a field in a nested document.
* @param {boolean} [options.unique = false] Enforce field uniqueness. Note that a unique index will raise an error if you try to index two documents for which the field is not defined. * @param {boolean} [options.unique = false] Enforce field uniqueness. Note that a unique index will raise an error if you try to index two documents for which the field is not defined.
* @param {boolean} [options.sparse = false] Don't index documents for which the field is not defined. Use this option along with "unique" if you want to accept multiple documents for which it is not defined. * @param {boolean} [options.sparse = false] Don't index documents for which the field is not defined. Use this option along with "unique" if you want to accept multiple documents for which it is not defined.
* @param {number} [options.expireAfterSeconds] - If set, the created index is a TTL (time to live) index, that will automatically remove documents when the system date becomes larger than the date on the indexed field plus `expireAfterSeconds`. Documents where the indexed field is not specified or not a `Date` object are ignored * @param {number} [options.expireAfterSeconds] - If set, the created index is a TTL (time to live) index, that will automatically remove documents when the system date becomes larger than the date on the indexed field plus `expireAfterSeconds`. Documents where the indexed field is not specified or not a `Date` object are ignored
* @return {Promise<void>} * @return {Promise<void>}
* @see Datastore#ensureIndex
*/ */
// TODO: contrary to what is said in the JSDoc, this function should probably be called through the executor, it persists a new state // TODO: contrary to what is said in the JSDoc, this function should probably be called through the executor, it persists a new state
async ensureIndexAsync (options = {}) { async ensureIndexAsync (options = {}) {
@ -393,11 +395,11 @@ class Datastore extends EventEmitter {
} }
/** /**
* Remove an index * Async version of {@link Datastore#removeIndex}.
* Previous versions said explicitly the callback was optional, it is now recommended setting one.
* @param {string} fieldName Field name of the index to remove. Use the dot notation to remove an index referring to a * @param {string} fieldName Field name of the index to remove. Use the dot notation to remove an index referring to a
* field in a nested document. * field in a nested document.
* @return {Promise<void>} * @return {Promise<void>}
* @see Datastore#removeIndex
*/ */
// TODO: contrary to what is said in the JSDoc, this function should probably be called through the executor, it persists a new state // TODO: contrary to what is said in the JSDoc, this function should probably be called through the executor, it persists a new state
async removeIndexAsync (fieldName) { async removeIndexAsync (fieldName) {
@ -407,9 +409,11 @@ class Datastore extends EventEmitter {
} }
/** /**
* Add one or several document(s) to all indexes * Add one or several document(s) to all indexes.
*
* This is an internal function.
* @param {document} doc * @param {document} doc
* @private * @protected
*/ */
addToIndexes (doc) { addToIndexes (doc) {
let failingIndex let failingIndex
@ -437,8 +441,11 @@ class Datastore extends EventEmitter {
} }
/** /**
* Remove one or several document(s) from all indexes * Remove one or several document(s) from all indexes.
*
* This is an internal function.
* @param {document} doc * @param {document} doc
* @protected
*/ */
removeFromIndexes (doc) { removeFromIndexes (doc) {
for (const index of Object.values(this.indexes)) { for (const index of Object.values(this.indexes)) {
@ -447,9 +454,13 @@ class Datastore extends EventEmitter {
} }
/** /**
* Update one or several documents in all indexes * Update one or several documents in all indexes.
* To update multiple documents, oldDoc must be an array of { oldDoc, newDoc } pairs *
* If one update violates a constraint, all changes are rolled back * To update multiple documents, oldDoc must be an array of { oldDoc, newDoc } pairs.
*
* If one update violates a constraint, all changes are rolled back.
*
* This is an internal function.
* @param {document|Array.<{oldDoc: document, newDoc: document}>} oldDoc Document to update, or an `Array` of * @param {document|Array.<{oldDoc: document, newDoc: document}>} oldDoc Document to update, or an `Array` of
* `{oldDoc, newDoc}` pairs. * `{oldDoc, newDoc}` pairs.
* @param {document} [newDoc] Document to replace the oldDoc with. If the first argument is an `Array` of * @param {document} [newDoc] Document to replace the oldDoc with. If the first argument is an `Array` of
@ -528,12 +539,13 @@ class Datastore extends EventEmitter {
* *
* Returned candidates will be scanned to find and remove all expired documents * Returned candidates will be scanned to find and remove all expired documents
* *
* This is an internal function.
* @param {query} query * @param {query} query
* @param {boolean|function} [dontExpireStaleDocs = false] If true don't remove stale docs. Useful for the remove * @param {boolean|function} [dontExpireStaleDocs = false] If true don't remove stale docs. Useful for the remove
* function which shouldn't be impacted by expirations. If argument is not given, it is used as the callback. * function which shouldn't be impacted by expirations. If argument is not given, it is used as the callback.
* @param {MultipleDocumentsCallback} callback Signature err, candidates * @param {MultipleDocumentsCallback} callback Signature err, candidates
* *
* @private * @protected
*/ */
getCandidates (query, dontExpireStaleDocs, callback) { getCandidates (query, dontExpireStaleDocs, callback) {
if (typeof dontExpireStaleDocs === 'function') { if (typeof dontExpireStaleDocs === 'function') {
@ -545,20 +557,15 @@ class Datastore extends EventEmitter {
} }
/** /**
* Return the list of candidates for a given query * Async version of {@link Datastore#getCandidates}.
* Crude implementation for now, we return the candidates given by the first usable index if any
* We try the following query types, in this order: basic match, $in match, comparison match
* One way to make it better would be to enable the use of multiple indexes if the first usable index
* returns too much data. I may do it in the future.
*
* Returned candidates will be scanned to find and remove all expired documents
* *
* This is an internal function.
* @param {query} query * @param {query} query
* @param {boolean} [dontExpireStaleDocs = false] If true don't remove stale docs. Useful for the remove function * @param {boolean} [dontExpireStaleDocs = false] If true don't remove stale docs. Useful for the remove function
* which shouldn't be impacted by expirations. * which shouldn't be impacted by expirations.
* @return {Promise<document[]>} candidates * @return {Promise<document[]>} candidates
* * @see Datastore#getCandidates
* @private * @protected
*/ */
async getCandidatesAsync (query, dontExpireStaleDocs = false) { async getCandidatesAsync (query, dontExpireStaleDocs = false) {
const validDocs = [] const validDocs = []
@ -583,22 +590,22 @@ class Datastore extends EventEmitter {
/** /**
* Insert a new document * Insert a new document
* Private Use Datastore.insert which has the same signature * This is an internal function, use {@link Datastore#insert} which has the same signature.
* @param {document|document[]} newDoc * @param {document|document[]} newDoc
* @param {SingleDocumentCallback} [callback = () => {}] Optional callback, signature: err, insertedDoc * @param {SingleDocumentCallback} callback
* *
* @private * @private
*/ */
_insert (newDoc, callback = () => {}) { _insert (newDoc, callback) {
return callbackify(this._insertAsync.bind(this))(newDoc, callback) return callbackify(this._insertAsync.bind(this))(newDoc, callback)
} }
/** /**
* Insert a new document * Async version of {@link Datastore#_insert}.
* Private Use Datastore.insertAsync which has the same signature
* @param {document|document[]} newDoc * @param {document|document[]} newDoc
* @return {Promise<document|document[]>} * @return {Promise<document|document[]>}
* @private * @private
* @see Datastore#_insert
*/ */
async _insertAsync (newDoc) { async _insertAsync (newDoc) {
const preparedDoc = this._prepareDocumentForInsertion(newDoc) const preparedDoc = this._prepareDocumentForInsertion(newDoc)
@ -685,26 +692,24 @@ class Datastore extends EventEmitter {
} }
/** /**
* Insert a new document * Insert a new document.
* Private Use Datastore.insert which has the same signature
* @param {document|document[]} newDoc * @param {document|document[]} newDoc
* @param {SingleDocumentCallback} [callback = () => {}] Optional callback, signature: err, insertedDoc * @param {SingleDocumentCallback} [callback = () => {}] Optional callback, signature: err, insertedDoc
* *
* @private * @private
*/ */
insert (...args) { insert (newDoc, callback = () => {}) {
this.executor.push({ this: this, fn: this._insert, arguments: args }) this.executor.push({ this: this, fn: this._insert, arguments: [newDoc, callback] })
} }
/** /**
* Insert a new document * Async version of {@link Datastore#insert}.
* Private Use Datastore.insertAsync which has the same signature
* @param {document|document[]} newDoc * @param {document|document[]} newDoc
* @return {Promise<document>} * @return {Promise<document>}
* @async * @async
*/ */
insertAsync (...args) { insertAsync (newDoc) {
return this.executor.pushAsync(() => this._insertAsync(...args)) return this.executor.pushAsync(() => this._insertAsync(newDoc))
} }
/** /**
@ -714,7 +719,7 @@ class Datastore extends EventEmitter {
*/ */
/** /**
* Count all documents matching the query * Count all documents matching the query.
* @param {query} query MongoDB-style query * @param {query} query MongoDB-style query
* @param {Datastore~countCallback} [callback] If given, the function will return undefined, otherwise it will return the Cursor. * @param {Datastore~countCallback} [callback] If given, the function will return undefined, otherwise it will return the Cursor.
* @return {Cursor<number>|undefined} * @return {Cursor<number>|undefined}
@ -727,13 +732,13 @@ class Datastore extends EventEmitter {
} }
/** /**
* Count all documents matching the query * Async version of {@link Datastore#count}.
* @param {query} query MongoDB-style query * @param {query} query MongoDB-style query
* @return {Cursor<number>} count * @return {Cursor<number>} count
* @async * @async
*/ */
countAsync (query) { countAsync (query) {
return new Cursor(this, query, async docs => docs.length, true) // this is a trick, Cursor itself is a thenable, which allows to await it return new Cursor(this, query, async docs => docs.length, false)
} }
/** /**
@ -763,15 +768,14 @@ class Datastore extends EventEmitter {
} }
/** /**
* Find all documents matching the query * Async version of {@link Datastore#find}.
* If no callback is passed, we return the cursor so that user can limit, skip and finally exec
* @param {query} query MongoDB-style query * @param {query} query MongoDB-style query
* @param {projection} [projection = {}] MongoDB-style projection * @param {projection} [projection = {}] MongoDB-style projection
* @return {Cursor<document[]>} * @return {Cursor<document[]>}
* @async * @async
*/ */
findAsync (query, projection = {}) { findAsync (query, projection = {}) {
const cursor = new Cursor(this, query, docs => docs.map(doc => model.deepCopy(doc)), true) const cursor = new Cursor(this, query, docs => docs.map(doc => model.deepCopy(doc)), false)
cursor.projection(projection) cursor.projection(projection)
return cursor return cursor
@ -784,10 +788,10 @@ class Datastore extends EventEmitter {
*/ */
/** /**
* Find one document matching the query * Find one document matching the query.
* @param {query} query MongoDB-style query * @param {query} query MongoDB-style query
* @param {projection} projection MongoDB-style projection * @param {projection|SingleDocumentCallback} [projection = {}] MongoDB-style projection
* @param {SingleDocumentCallback} callback Optional callback, signature: err, doc * @param {SingleDocumentCallback} [callback] Optional callback, signature: err, doc
* @return {Cursor<document>|undefined} * @return {Cursor<document>|undefined}
*/ */
findOne (query, projection, callback) { findOne (query, projection, callback) {
@ -808,13 +812,14 @@ class Datastore extends EventEmitter {
} }
/** /**
* Find one document matching the query * Async version of {@link Datastore#findOne}.
* @param {query} query MongoDB-style query * @param {query} query MongoDB-style query
* @param {projection} projection MongoDB-style projection * @param {projection} projection MongoDB-style projection
* @return {Cursor<document>} * @return {Cursor<document>}
* @see Datastore#findOne
*/ */
findOneAsync (query, projection = {}) { findOneAsync (query, projection = {}) {
const cursor = new Cursor(this, query, docs => docs.length === 1 ? model.deepCopy(docs[0]) : null, true) const cursor = new Cursor(this, query, docs => docs.length === 1 ? model.deepCopy(docs[0]) : null, false)
cursor.projection(projection).limit(1) cursor.projection(projection).limit(1)
return cursor return cursor
@ -843,7 +848,8 @@ class Datastore extends EventEmitter {
/** /**
* Update all docs matching query. * Update all docs matching query.
* Use Datastore.update which has the same signature *
* Use {@link Datastore#update} which has the same signature.
* @param {query} query is the same kind of finding query you use with `find` and `findOne` * @param {query} query is the same kind of finding query you use with `find` and `findOne`
* @param {document|update} update specifies how the documents should be modified. It is either a new document or a * @param {document|update} update specifies how the documents should be modified. It is either a new document or a
* set of modifiers (you cannot use both together, it doesn't make sense!): * set of modifiers (you cannot use both together, it doesn't make sense!):
@ -852,7 +858,7 @@ class Datastore extends EventEmitter {
* Available field modifiers are `$set` to change a field's value, `$unset` to delete a field, `$inc` to increment a * Available field modifiers are `$set` to change a field's value, `$unset` to delete a field, `$inc` to increment a
* field's value and `$min`/`$max` to change field's value, only if provided value is less/greater than current * field's value and `$min`/`$max` to change field's value, only if provided value is less/greater than current
* value. To work on arrays, you have `$push`, `$pop`, `$addToSet`, `$pull`, and the special `$each` and `$slice`. * value. To work on arrays, you have `$push`, `$pop`, `$addToSet`, `$pull`, and the special `$each` and `$slice`.
* @param {object|Datastore~updateCallback} [options] Optional options. If not given, is interpreted as the callback. * @param {object} [options] Optional options. If not given, is interpreted as the callback.
* @param {boolean} [options.multi = false] If true, can update multiple documents * @param {boolean} [options.multi = false] If true, can update multiple documents
* @param {boolean} [options.upsert = false] If true, can insert a new document corresponding to the `update` rules if * @param {boolean} [options.upsert = false] If true, can insert a new document corresponding to the `update` rules if
* your `query` doesn't match anything. If your `update` is a simple object with no modifiers, it is the inserted * your `query` doesn't match anything. If your `update` is a simple object with no modifiers, it is the inserted
@ -861,17 +867,11 @@ class Datastore extends EventEmitter {
* @param {boolean} [options.returnUpdatedDocs = false] (not Mongo-DB compatible) If true and update is not an upsert, * @param {boolean} [options.returnUpdatedDocs = false] (not Mongo-DB compatible) If true and update is not an upsert,
* will return the array of documents matched by the find query and updated. Updated documents will be returned even * will return the array of documents matched by the find query and updated. Updated documents will be returned even
* if the update did not actually modify them. * if the update did not actually modify them.
* @param {Datastore~updateCallback} [cb = () => {}] Optional callback * @param {Datastore~updateCallback} callback
* *
* @private * @private
*/ */
_update (query, update, options, cb) { _update (query, update, options, callback) {
if (typeof options === 'function') {
cb = options
options = {}
}
const callback = cb || (() => {})
const _callback = (err, res = {}) => { const _callback = (err, res = {}) => {
callback(err, res.numAffected, res.affectedDocuments, res.upsert) callback(err, res.numAffected, res.affectedDocuments, res.upsert)
} }
@ -879,8 +879,9 @@ class Datastore extends EventEmitter {
} }
/** /**
* Update all docs matching query. * Async version of {@link Datastore#_update}.
* Use Datastore.updateAsync which has the same signature *
* Use {@link Datastore#updateAsync} which has the same signature.
* @param {query} query is the same kind of finding query you use with `find` and `findOne` * @param {query} query is the same kind of finding query you use with `find` and `findOne`
* @param {document|update} update specifies how the documents should be modified. It is either a new document or a * @param {document|update} update specifies how the documents should be modified. It is either a new document or a
* set of modifiers (you cannot use both together, it doesn't make sense!): * set of modifiers (you cannot use both together, it doesn't make sense!):
@ -889,7 +890,7 @@ class Datastore extends EventEmitter {
* Available field modifiers are `$set` to change a field's value, `$unset` to delete a field, `$inc` to increment a * Available field modifiers are `$set` to change a field's value, `$unset` to delete a field, `$inc` to increment a
* field's value and `$min`/`$max` to change field's value, only if provided value is less/greater than current * field's value and `$min`/`$max` to change field's value, only if provided value is less/greater than current
* value. To work on arrays, you have `$push`, `$pop`, `$addToSet`, `$pull`, and the special `$each` and `$slice`. * value. To work on arrays, you have `$push`, `$pop`, `$addToSet`, `$pull`, and the special `$each` and `$slice`.
* @param {Object} [options] Optional options * @param {Object} options options
* @param {boolean} [options.multi = false] If true, can update multiple documents * @param {boolean} [options.multi = false] If true, can update multiple documents
* @param {boolean} [options.upsert = false] If true, can insert a new document corresponding to the `update` rules if * @param {boolean} [options.upsert = false] If true, can insert a new document corresponding to the `update` rules if
* your `query` doesn't match anything. If your `update` is a simple object with no modifiers, it is the inserted * your `query` doesn't match anything. If your `update` is a simple object with no modifiers, it is the inserted
@ -900,16 +901,16 @@ class Datastore extends EventEmitter {
* if the update did not actually modify them. * if the update did not actually modify them.
* *
* @return {Promise<{numAffected: number, affectedDocuments: document[]|document|null, upsert: boolean}>} * @return {Promise<{numAffected: number, affectedDocuments: document[]|document|null, upsert: boolean}>}
* * @see Datastore#_update
* @private * @private
*/ */
async _updateAsync (query, update, options = {}) { async _updateAsync (query, update, options) {
const multi = options.multi !== undefined ? options.multi : false const multi = options.multi !== undefined ? options.multi : false
const upsert = options.upsert !== undefined ? options.upsert : false const upsert = options.upsert !== undefined ? options.upsert : false
// If upsert option is set, check whether we need to insert the doc // If upsert option is set, check whether we need to insert the doc
if (upsert) { if (upsert) {
const cursor = new Cursor(this, query, x => x, true) const cursor = new Cursor(this, query, x => x, false)
// Need to use an internal function not tied to the executor to avoid deadlock // Need to use an internal function not tied to the executor to avoid deadlock
const docs = await cursor.limit(1)._execAsync() const docs = await cursor.limit(1)._execAsync()
@ -970,14 +971,14 @@ class Datastore extends EventEmitter {
/** /**
* Update all docs matching query. * Update all docs matching query.
* @param {query} query is the same kind of finding query you use with `find` and `findOne` * @param {query} query is the same kind of finding query you use with `find` and `findOne`
* @param {document|update} update specifies how the documents should be modified. It is either a new document or a * @param {document|*} update specifies how the documents should be modified. It is either a new document or a
* set of modifiers (you cannot use both together, it doesn't make sense!): * set of modifiers (you cannot use both together, it doesn't make sense!):
* - A new document will replace the matched docs * - A new document will replace the matched docs
* - The modifiers create the fields they need to modify if they don't exist, and you can apply them to subdocs. * - The modifiers create the fields they need to modify if they don't exist, and you can apply them to subdocs.
* Available field modifiers are `$set` to change a field's value, `$unset` to delete a field, `$inc` to increment a * Available field modifiers are `$set` to change a field's value, `$unset` to delete a field, `$inc` to increment a
* field's value and `$min`/`$max` to change field's value, only if provided value is less/greater than current * field's value and `$min`/`$max` to change field's value, only if provided value is less/greater than current
* value. To work on arrays, you have `$push`, `$pop`, `$addToSet`, `$pull`, and the special `$each` and `$slice`. * value. To work on arrays, you have `$push`, `$pop`, `$addToSet`, `$pull`, and the special `$each` and `$slice`.
* @param {Object} [options] Optional options * @param {Object|Datastore~updateCallback} [options|] Optional options
* @param {boolean} [options.multi = false] If true, can update multiple documents * @param {boolean} [options.multi = false] If true, can update multiple documents
* @param {boolean} [options.upsert = false] If true, can insert a new document corresponding to the `update` rules if * @param {boolean} [options.upsert = false] If true, can insert a new document corresponding to the `update` rules if
* your `query` doesn't match anything. If your `update` is a simple object with no modifiers, it is the inserted * your `query` doesn't match anything. If your `update` is a simple object with no modifiers, it is the inserted
@ -989,21 +990,26 @@ class Datastore extends EventEmitter {
* @param {Datastore~updateCallback} [cb = () => {}] Optional callback * @param {Datastore~updateCallback} [cb = () => {}] Optional callback
* *
*/ */
update (...args) { update (query, update, options, cb) {
this.executor.push({ this: this, fn: this._update, arguments: args }) if (typeof options === 'function') {
cb = options
options = {}
}
const callback = cb || (() => {})
this.executor.push({ this: this, fn: this._update, arguments: [query, update, options, callback] })
} }
/** /**
* Update all docs matching query. * Async version of {@link Datastore#update}.
* @param {query} query is the same kind of finding query you use with `find` and `findOne` * @param {query} query is the same kind of finding query you use with `find` and `findOne`
* @param {document|update} update specifies how the documents should be modified. It is either a new document or a * @param {document|*} update specifies how the documents should be modified. It is either a new document or a
* set of modifiers (you cannot use both together, it doesn't make sense!): * set of modifiers (you cannot use both together, it doesn't make sense!):
* - A new document will replace the matched docs * - A new document will replace the matched docs
* - The modifiers create the fields they need to modify if they don't exist, and you can apply them to subdocs. * - The modifiers create the fields they need to modify if they don't exist, and you can apply them to subdocs.
* Available field modifiers are `$set` to change a field's value, `$unset` to delete a field, `$inc` to increment a * Available field modifiers are `$set` to change a field's value, `$unset` to delete a field, `$inc` to increment a
* field's value and `$min`/`$max` to change field's value, only if provided value is less/greater than current * field's value and `$min`/`$max` to change field's value, only if provided value is less/greater than current
* value. To work on arrays, you have `$push`, `$pop`, `$addToSet`, `$pull`, and the special `$each` and `$slice`. * value. To work on arrays, you have `$push`, `$pop`, `$addToSet`, `$pull`, and the special `$each` and `$slice`.
* @param {Object} [options] Optional options * @param {Object} [options = {}] Optional options
* @param {boolean} [options.multi = false] If true, can update multiple documents * @param {boolean} [options.multi = false] If true, can update multiple documents
* @param {boolean} [options.upsert = false] If true, can insert a new document corresponding to the `update` rules if * @param {boolean} [options.upsert = false] If true, can insert a new document corresponding to the `update` rules if
* your `query` doesn't match anything. If your `update` is a simple object with no modifiers, it is the inserted * your `query` doesn't match anything. If your `update` is a simple object with no modifiers, it is the inserted
@ -1014,9 +1020,10 @@ class Datastore extends EventEmitter {
* if the update did not actually modify them. * if the update did not actually modify them.
* @async * @async
* @return {Promise<{numAffected: number, affectedDocuments: document[]|document|null, upsert: boolean}>} * @return {Promise<{numAffected: number, affectedDocuments: document[]|document|null, upsert: boolean}>}
* @see Datastore#update
*/ */
updateAsync (...args) { updateAsync (query, update, options = {}) {
return this.executor.pushAsync(() => this._updateAsync(...args)) return this.executor.pushAsync(() => this._updateAsync(query, update, options))
} }
/** /**
@ -1027,33 +1034,31 @@ class Datastore extends EventEmitter {
/** /**
* Remove all docs matching the query. * Remove all docs matching the query.
* Use Datastore.remove which has the same signature *
* For now very naive implementation (similar to update) * Use {@link Datastore#remove} which has the same signature.
*
* For now very naive implementation (similar to update).
* @param {query} query * @param {query} query
* @param {object} [options] Optional options * @param {object} options options
* @param {boolean} [options.multi = false] If true, can update multiple documents * @param {boolean} [options.multi = false] If true, can update multiple documents
* @param {Datastore~removeCallback} [cb = () => {}] * @param {Datastore~removeCallback} callback
* * @see Datastore#remove
* @private * @private
*/ */
_remove (query, options, cb) { _remove (query, options, callback) {
if (typeof options === 'function') {
cb = options
options = {}
}
const callback = cb || (() => {})
callbackify(this._removeAsync.bind(this))(query, options, callback) callbackify(this._removeAsync.bind(this))(query, options, callback)
} }
/** /**
* Remove all docs matching the query. * Async version of {@link Datastore#_remove}.
* Use Datastore.removeAsync which has the same signature *
* Use {@link Datastore#removeAsync} which has the same signature.
* @param {query} query * @param {query} query
* @param {object} [options] Optional options * @param {object} [options] Optional options
* @param {boolean} [options.multi = false] If true, can update multiple documents * @param {boolean} [options.multi = false] If true, can update multiple documents
* @return {Promise<number>} How many documents were removed * @return {Promise<number>} How many documents were removed
* @private * @private
* @see Datastore#_remove
*/ */
async _removeAsync (query, options = {}) { async _removeAsync (query, options = {}) {
const multi = options.multi !== undefined ? options.multi : false const multi = options.multi !== undefined ? options.multi : false
@ -1077,25 +1082,30 @@ class Datastore extends EventEmitter {
/** /**
* Remove all docs matching the query. * Remove all docs matching the query.
* @param {query} query * @param {query} query
* @param {object} [options] Optional options * @param {object|Datastore~removeCallback} [options={}] Optional options
* @param {boolean} [options.multi = false] If true, can update multiple documents * @param {boolean} [options.multi = false] If true, can update multiple documents
* @param {Datastore~removeCallback} [cb = () => {}] Optional callback, signature: err, numRemoved * @param {Datastore~removeCallback} [cb = () => {}] Optional callback
*/ */
remove (...args) { remove (query, options, cb) {
this.executor.push({ this: this, fn: this._remove, arguments: args }) if (typeof options === 'function') {
cb = options
options = {}
}
const callback = cb || (() => {})
this.executor.push({ this: this, fn: this._remove, arguments: [query, options, callback] })
} }
/** /**
* Remove all docs matching the query. * Remove all docs matching the query.
* Use Datastore.removeAsync which has the same signature * Use Datastore.removeAsync which has the same signature
* @param {query} query * @param {query} query
* @param {object} [options] Optional options * @param {object} [options={}] Optional options
* @param {boolean} [options.multi = false] If true, can update multiple documents * @param {boolean} [options.multi = false] If true, can update multiple documents
* @return {Promise<number>} How many documents were removed * @return {Promise<number>} How many documents were removed
* @async * @async
*/ */
removeAsync (...args) { removeAsync (query, options = {}) {
return this.executor.pushAsync(() => this._removeAsync(...args)) return this.executor.pushAsync(() => this._removeAsync(query, options))
} }
} }

@ -164,7 +164,6 @@ class Persistence {
* Do not use directly, it should only used by a {@link Datastore} instance. * Do not use directly, it should only used by a {@link Datastore} instance.
* @param {document[]} newDocs Can be empty if no doc was updated/removed * @param {document[]} newDocs Can be empty if no doc was updated/removed
* @return {Promise} * @return {Promise}
* @protected
* @see Persistence#persistNewState * @see Persistence#persistNewState
*/ */
async persistNewStateAsync (newDocs) { async persistNewStateAsync (newDocs) {

Loading…
Cancel
Save