mirror of https://github.com/seald/nedb
parent
0e9e5c7f4d
commit
efef10e0e9
@ -0,0 +1,163 @@ |
||||
<a name="Cursor"></a> |
||||
|
||||
## Cursor ⇐ <code>Promise</code> |
||||
<p>Manage access to data, be it to find, update or remove it.</p> |
||||
<p>It extends Promise so that its methods are chainable & awaitable.</p> |
||||
|
||||
**Kind**: global class |
||||
**Extends**: <code>Promise</code> |
||||
|
||||
* [Cursor](#Cursor) ⇐ <code>Promise</code> |
||||
* [new Cursor(db, query, [execFn], [async])](#new_Cursor_new) |
||||
* _instance_ |
||||
* [.limit(limit)](#Cursor+limit) ⇒ [<code>Cursor</code>](#Cursor) |
||||
* [.skip(skip)](#Cursor+skip) ⇒ [<code>Cursor</code>](#Cursor) |
||||
* [.sort(sortQuery)](#Cursor+sort) ⇒ [<code>Cursor</code>](#Cursor) |
||||
* [.projection(projection)](#Cursor+projection) ⇒ [<code>Cursor</code>](#Cursor) |
||||
* [.project(candidates)](#Cursor+project) ⇒ [<code>Array.<document></code>](#document) |
||||
* [._execAsync()](#Cursor+_execAsync) ⇒ [<code>Array.<document></code>](#document) \| <code>Promise.<\*></code> |
||||
* [._exec(_callback)](#Cursor+_exec) |
||||
* [.exec(_callback)](#Cursor+exec) |
||||
* [.execAsync()](#Cursor+execAsync) ⇒ <code>Promise.<(Array.<document>\|\*)></code> |
||||
* _inner_ |
||||
* [~execFn](#Cursor..execFn) : <code>function</code> |
||||
* [~execFnAsync](#Cursor..execFnAsync) ⇒ <code>Promise</code> |
||||
* [~execCallback](#Cursor..execCallback) : <code>function</code> |
||||
|
||||
<a name="new_Cursor_new"></a> |
||||
|
||||
### new Cursor(db, query, [execFn], [async]) |
||||
<p>Create a new cursor for this collection</p> |
||||
|
||||
|
||||
| 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> | |
||||
| [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+limit"></a> |
||||
|
||||
### cursor.limit(limit) ⇒ [<code>Cursor</code>](#Cursor) |
||||
<p>Set a limit to the number of results</p> |
||||
|
||||
**Kind**: instance method of [<code>Cursor</code>](#Cursor) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| limit | <code>Number</code> | |
||||
|
||||
<a name="Cursor+skip"></a> |
||||
|
||||
### cursor.skip(skip) ⇒ [<code>Cursor</code>](#Cursor) |
||||
<p>Skip a number of results</p> |
||||
|
||||
**Kind**: instance method of [<code>Cursor</code>](#Cursor) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| skip | <code>Number</code> | |
||||
|
||||
<a name="Cursor+sort"></a> |
||||
|
||||
### cursor.sort(sortQuery) ⇒ [<code>Cursor</code>](#Cursor) |
||||
<p>Sort results of the query</p> |
||||
|
||||
**Kind**: instance method of [<code>Cursor</code>](#Cursor) |
||||
|
||||
| Param | Type | Description | |
||||
| --- | --- | --- | |
||||
| sortQuery | <code>Object.<string, number></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> |
||||
|
||||
### cursor.projection(projection) ⇒ [<code>Cursor</code>](#Cursor) |
||||
<p>Add the use of a projection</p> |
||||
|
||||
**Kind**: instance method of [<code>Cursor</code>](#Cursor) |
||||
|
||||
| Param | Type | Description | |
||||
| --- | --- | --- | |
||||
| projection | <code>Object.<string, number></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> |
||||
|
||||
### cursor.project(candidates) ⇒ [<code>Array.<document></code>](#document) |
||||
<p>Apply the projection</p> |
||||
|
||||
**Kind**: instance method of [<code>Cursor</code>](#Cursor) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| candidates | [<code>Array.<document></code>](#document) | |
||||
|
||||
<a name="Cursor+_execAsync"></a> |
||||
|
||||
### cursor.\_execAsync() ⇒ [<code>Array.<document></code>](#document) \| <code>Promise.<\*></code> |
||||
<p>Get all matching elements |
||||
Will return pointers to matched elements (shallow copies), returning full copies is the role of find or findOne |
||||
This is an internal function, use execAsync which uses the executor</p> |
||||
|
||||
**Kind**: instance method of [<code>Cursor</code>](#Cursor) |
||||
<a name="Cursor+_exec"></a> |
||||
|
||||
### cursor.\_exec(_callback) |
||||
<p>Get all matching elements |
||||
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</p> |
||||
|
||||
**Kind**: instance method of [<code>Cursor</code>](#Cursor) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| _callback | [<code>execCallback</code>](#Cursor..execCallback) | |
||||
|
||||
<a name="Cursor+exec"></a> |
||||
|
||||
### cursor.exec(_callback) |
||||
<p>Get all matching elements |
||||
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) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| _callback | [<code>execCallback</code>](#Cursor..execCallback) | |
||||
|
||||
<a name="Cursor+execAsync"></a> |
||||
|
||||
### cursor.execAsync() ⇒ <code>Promise.<(Array.<document>\|\*)></code> |
||||
<p>Get all matching elements |
||||
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) |
||||
<a name="Cursor..execFn"></a> |
||||
|
||||
### Cursor~execFn : <code>function</code> |
||||
**Kind**: inner typedef of [<code>Cursor</code>](#Cursor) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| err | <code>Error</code> | |
||||
| res | [<code>?Array.<document></code>](#document) \| [<code>document</code>](#document) | |
||||
|
||||
<a name="Cursor..execFnAsync"></a> |
||||
|
||||
### Cursor~execFnAsync ⇒ <code>Promise</code> |
||||
**Kind**: inner typedef of [<code>Cursor</code>](#Cursor) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| res | [<code>?Array.<document></code>](#document) \| [<code>document</code>](#document) | |
||||
|
||||
<a name="Cursor..execCallback"></a> |
||||
|
||||
### Cursor~execCallback : <code>function</code> |
||||
**Kind**: inner typedef of [<code>Cursor</code>](#Cursor) |
||||
|
||||
| Param | Type | Description | |
||||
| --- | --- | --- | |
||||
| err | <code>Error</code> | | |
||||
| res | [<code>Array.<document></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> | |
||||
|
@ -0,0 +1,420 @@ |
||||
<a name="Datastore"></a> |
||||
|
||||
## Datastore ⇐ <code>EventEmitter</code> |
||||
<p>The <code>Datastore</code> class is the main class of NeDB.</p> |
||||
|
||||
**Kind**: global class |
||||
**Extends**: <code>EventEmitter</code> |
||||
**Emits**: <code>Datastore.event:"compaction.done"</code> |
||||
|
||||
* [Datastore](#Datastore) ⇐ <code>EventEmitter</code> |
||||
* [new Datastore(options)](#new_Datastore_new) |
||||
* _instance_ |
||||
* [.persistence](#Datastore+persistence) : [<code>Persistence</code>](#Persistence) |
||||
* [.executor](#Datastore+executor) : [<code>Executor</code>](#Executor) |
||||
* [.autoloadPromise](#Datastore+autoloadPromise) : <code>Promise</code> |
||||
* [.loadDatabase(callback)](#Datastore+loadDatabase) |
||||
* [.loadDatabaseAsync()](#Datastore+loadDatabaseAsync) ⇒ <code>Promise</code> |
||||
* [.getAllData()](#Datastore+getAllData) ⇒ [<code>Array.<document></code>](#document) |
||||
* [.resetIndexes()](#Datastore+resetIndexes) |
||||
* [.ensureIndex(options, callback)](#Datastore+ensureIndex) |
||||
* [.ensureIndexAsync(options)](#Datastore+ensureIndexAsync) ⇒ <code>Promise.<void></code> |
||||
* [.removeIndex(fieldName, callback)](#Datastore+removeIndex) |
||||
* [.removeIndexAsync(fieldName)](#Datastore+removeIndexAsync) ⇒ <code>Promise.<void></code> |
||||
* [.removeFromIndexes(doc)](#Datastore+removeFromIndexes) |
||||
* [.updateIndexes(oldDoc, [newDoc])](#Datastore+updateIndexes) |
||||
* [.insertAsync(newDoc)](#Datastore+insertAsync) ⇒ [<code>Promise.<document></code>](#document) |
||||
* [.count(query, [callback])](#Datastore+count) ⇒ <code>Cursor.<number></code> \| <code>undefined</code> |
||||
* [.countAsync(query)](#Datastore+countAsync) ⇒ <code>Cursor.<number></code> |
||||
* [.find(query, [projection], [callback])](#Datastore+find) ⇒ <code>Cursor.<Array.<document>></code> \| <code>undefined</code> |
||||
* [.findAsync(query, [projection])](#Datastore+findAsync) ⇒ <code>Cursor.<Array.<document>></code> |
||||
* [.findOne(query, projection, callback)](#Datastore+findOne) ⇒ [<code>Cursor.<document></code>](#document) \| <code>undefined</code> |
||||
* [.findOneAsync(query, projection)](#Datastore+findOneAsync) ⇒ [<code>Cursor.<document></code>](#document) |
||||
* [.update(query, update, [options], [cb])](#Datastore+update) |
||||
* [.updateAsync(query, update, [options])](#Datastore+updateAsync) ⇒ <code>Promise.<{numAffected: number, affectedDocuments: (Array.<document>\|document\|null), upsert: boolean}></code> |
||||
* [.remove(query, [options], [cb])](#Datastore+remove) |
||||
* [.removeAsync(query, [options])](#Datastore+removeAsync) ⇒ <code>Promise.<number></code> |
||||
* _static_ |
||||
* ["event:compaction.done"](#Datastore.event_compaction.done) |
||||
* _inner_ |
||||
* [~countCallback](#Datastore..countCallback) : <code>function</code> |
||||
* [~findOneCallback](#Datastore..findOneCallback) : <code>function</code> |
||||
* [~updateCallback](#Datastore..updateCallback) : <code>function</code> |
||||
* [~removeCallback](#Datastore..removeCallback) : <code>function</code> |
||||
|
||||
<a name="new_Datastore_new"></a> |
||||
|
||||
### new Datastore(options) |
||||
<p>Create a new collection, either persistent or in-memory.</p> |
||||
<p>If you use a persistent datastore without the <code>autoload</code> option, you need to call <code>loadDatabase</code> manually. This |
||||
function fetches the data from datafile and prepares the database. <strong>Don't forget it!</strong> If you use a persistent |
||||
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> |
||||
|
||||
|
||||
| Param | Type | Default | Description | |
||||
| --- | --- | --- | --- | |
||||
| 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> | |
||||
| [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> | |
||||
| [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> | |
||||
| [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> | |
||||
| [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> | |
||||
| [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> | |
||||
| [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> | |
||||
| [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> | |
||||
|
||||
<a name="Datastore+persistence"></a> |
||||
|
||||
### datastore.persistence : [<code>Persistence</code>](#Persistence) |
||||
<p>The <code>Persistence</code> instance for this <code>Datastore</code>.</p> |
||||
|
||||
**Kind**: instance property of [<code>Datastore</code>](#Datastore) |
||||
<a name="Datastore+executor"></a> |
||||
|
||||
### datastore.executor : [<code>Executor</code>](#Executor) |
||||
<p>The <code>Executor</code> instance for this <code>Datastore</code>. It is used in all methods exposed by the <code>Datastore</code>, any <code>Cursor</code> |
||||
produced by the <code>Datastore</code> and by <code>this.persistence.compactDataFile</code> & <code>this.persistence.compactDataFileAsync</code> |
||||
to ensure operations are performed sequentially in the database.</p> |
||||
|
||||
**Kind**: instance property of [<code>Datastore</code>](#Datastore) |
||||
<a name="Datastore+autoloadPromise"></a> |
||||
|
||||
### datastore.autoloadPromise : <code>Promise</code> |
||||
<p>A Promise that resolves when the autoload has finished.</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) |
||||
<a name="Datastore+loadDatabase"></a> |
||||
|
||||
### datastore.loadDatabase(callback) |
||||
<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) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| callback | <code>function</code> | |
||||
|
||||
<a name="Datastore+loadDatabaseAsync"></a> |
||||
|
||||
### datastore.loadDatabaseAsync() ⇒ <code>Promise</code> |
||||
<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) |
||||
<a name="Datastore+getAllData"></a> |
||||
|
||||
### datastore.getAllData() ⇒ [<code>Array.<document></code>](#document) |
||||
<p>Get an array of all the data in the database</p> |
||||
|
||||
**Kind**: instance method of [<code>Datastore</code>](#Datastore) |
||||
<a name="Datastore+resetIndexes"></a> |
||||
|
||||
### datastore.resetIndexes() |
||||
<p>Reset all currently defined indexes</p> |
||||
|
||||
**Kind**: instance method of [<code>Datastore</code>](#Datastore) |
||||
<a name="Datastore+ensureIndex"></a> |
||||
|
||||
### datastore.ensureIndex(options, callback) |
||||
<p>Ensure an index is kept for this field. Same parameters as lib/indexes |
||||
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) |
||||
|
||||
| Param | Type | Default | Description | |
||||
| --- | --- | --- | --- | |
||||
| options | <code>object</code> | | | |
||||
| 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> | |
||||
| [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> | |
||||
| [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 "unique" 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> | |
||||
| callback | [<code>NoParamCallback</code>](#NoParamCallback) | | <p>Callback, signature: err</p> | |
||||
|
||||
<a name="Datastore+ensureIndexAsync"></a> |
||||
|
||||
### datastore.ensureIndexAsync(options) ⇒ <code>Promise.<void></code> |
||||
<p>Ensure an index is kept for this field. Same parameters as lib/indexes |
||||
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) |
||||
|
||||
| Param | Type | Default | Description | |
||||
| --- | --- | --- | --- | |
||||
| options | <code>object</code> | | | |
||||
| 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> | |
||||
| [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> | |
||||
| [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 "unique" 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> |
||||
|
||||
### datastore.removeIndex(fieldName, callback) |
||||
<p>Remove an index |
||||
Previous versions said explicitly the callback was optional, it is now recommended setting one.</p> |
||||
|
||||
**Kind**: instance method of [<code>Datastore</code>](#Datastore) |
||||
|
||||
| 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> | |
||||
| callback | [<code>NoParamCallback</code>](#NoParamCallback) | <p>Optional callback, signature: err</p> | |
||||
|
||||
<a name="Datastore+removeIndexAsync"></a> |
||||
|
||||
### datastore.removeIndexAsync(fieldName) ⇒ <code>Promise.<void></code> |
||||
<p>Remove an index |
||||
Previous versions said explicitly the callback was optional, it is now recommended setting one.</p> |
||||
|
||||
**Kind**: instance method of [<code>Datastore</code>](#Datastore) |
||||
|
||||
| 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> | |
||||
|
||||
<a name="Datastore+removeFromIndexes"></a> |
||||
|
||||
### datastore.removeFromIndexes(doc) |
||||
<p>Remove one or several document(s) from all indexes</p> |
||||
|
||||
**Kind**: instance method of [<code>Datastore</code>](#Datastore) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| doc | [<code>document</code>](#document) | |
||||
|
||||
<a name="Datastore+updateIndexes"></a> |
||||
|
||||
### datastore.updateIndexes(oldDoc, [newDoc]) |
||||
<p>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</p> |
||||
|
||||
**Kind**: instance method of [<code>Datastore</code>](#Datastore) |
||||
|
||||
| Param | Type | Description | |
||||
| --- | --- | --- | |
||||
| oldDoc | [<code>document</code>](#document) \| <code>Array.<{oldDoc: document, newDoc: document}></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+insertAsync"></a> |
||||
|
||||
### datastore.insertAsync(newDoc) ⇒ [<code>Promise.<document></code>](#document) |
||||
<p>Insert a new document |
||||
Private Use Datastore.insertAsync which has the same signature</p> |
||||
|
||||
**Kind**: instance method of [<code>Datastore</code>](#Datastore) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| newDoc | [<code>document</code>](#document) \| [<code>Array.<document></code>](#document) | |
||||
|
||||
<a name="Datastore+count"></a> |
||||
|
||||
### datastore.count(query, [callback]) ⇒ <code>Cursor.<number></code> \| <code>undefined</code> |
||||
<p>Count all documents matching the query</p> |
||||
|
||||
**Kind**: instance method of [<code>Datastore</code>](#Datastore) |
||||
|
||||
| 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> | |
||||
|
||||
<a name="Datastore+countAsync"></a> |
||||
|
||||
### datastore.countAsync(query) ⇒ <code>Cursor.<number></code> |
||||
<p>Count all documents matching the query</p> |
||||
|
||||
**Kind**: instance method of [<code>Datastore</code>](#Datastore) |
||||
**Returns**: <code>Cursor.<number></code> - <p>count</p> |
||||
|
||||
| Param | Type | Description | |
||||
| --- | --- | --- | |
||||
| query | [<code>query</code>](#query) | <p>MongoDB-style query</p> | |
||||
|
||||
<a name="Datastore+find"></a> |
||||
|
||||
### datastore.find(query, [projection], [callback]) ⇒ <code>Cursor.<Array.<document>></code> \| <code>undefined</code> |
||||
<p>Find all documents matching the query |
||||
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) |
||||
|
||||
| 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 interpreted as the callback.</p> | |
||||
| [callback] | [<code>MultipleDocumentsCallback</code>](#MultipleDocumentsCallback) | | <p>Optional callback, signature: err, docs</p> | |
||||
|
||||
<a name="Datastore+findAsync"></a> |
||||
|
||||
### datastore.findAsync(query, [projection]) ⇒ <code>Cursor.<Array.<document>></code> |
||||
<p>Find all documents matching the query |
||||
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) |
||||
|
||||
| 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> | |
||||
|
||||
<a name="Datastore+findOne"></a> |
||||
|
||||
### datastore.findOne(query, projection, callback) ⇒ [<code>Cursor.<document></code>](#document) \| <code>undefined</code> |
||||
<p>Find one document matching the query</p> |
||||
|
||||
**Kind**: instance method of [<code>Datastore</code>](#Datastore) |
||||
|
||||
| Param | Type | Description | |
||||
| --- | --- | --- | |
||||
| query | [<code>query</code>](#query) | <p>MongoDB-style query</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> |
||||
|
||||
### datastore.findOneAsync(query, projection) ⇒ [<code>Cursor.<document></code>](#document) |
||||
<p>Find one document matching the query</p> |
||||
|
||||
**Kind**: instance method of [<code>Datastore</code>](#Datastore) |
||||
|
||||
| Param | Type | Description | |
||||
| --- | --- | --- | |
||||
| 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> |
||||
|
||||
### datastore.update(query, update, [options], [cb]) |
||||
<p>Update all docs matching query.</p> |
||||
|
||||
**Kind**: instance method of [<code>Datastore</code>](#Datastore) |
||||
|
||||
| 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>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> | |
||||
| [options] | <code>Object</code> | | <p>Optional options</p> | |
||||
| [options.multi] | <code>boolean</code> | <code>false</code> | <p>If true, can update multiple documents</p> | |
||||
| [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> | |
||||
| [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> | |
||||
| [cb] | [<code>updateCallback</code>](#Datastore..updateCallback) | <code>() => {}</code> | <p>Optional callback</p> | |
||||
|
||||
<a name="Datastore+updateAsync"></a> |
||||
|
||||
### datastore.updateAsync(query, update, [options]) ⇒ <code>Promise.<{numAffected: number, affectedDocuments: (Array.<document>\|document\|null), upsert: boolean}></code> |
||||
<p>Update all docs matching query.</p> |
||||
|
||||
**Kind**: instance method of [<code>Datastore</code>](#Datastore) |
||||
|
||||
| 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>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> | |
||||
| [options] | <code>Object</code> | | <p>Optional options</p> | |
||||
| [options.multi] | <code>boolean</code> | <code>false</code> | <p>If true, can update multiple documents</p> | |
||||
| [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> | |
||||
| [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> | |
||||
|
||||
<a name="Datastore+remove"></a> |
||||
|
||||
### datastore.remove(query, [options], [cb]) |
||||
<p>Remove all docs matching the query.</p> |
||||
|
||||
**Kind**: instance method of [<code>Datastore</code>](#Datastore) |
||||
|
||||
| Param | Type | Default | Description | |
||||
| --- | --- | --- | --- | |
||||
| query | [<code>query</code>](#query) | | | |
||||
| [options] | <code>object</code> | | <p>Optional options</p> | |
||||
| [options.multi] | <code>boolean</code> | <code>false</code> | <p>If true, can update multiple documents</p> | |
||||
| [cb] | [<code>removeCallback</code>](#Datastore..removeCallback) | <code>() => {}</code> | <p>Optional callback, signature: err, numRemoved</p> | |
||||
|
||||
<a name="Datastore+removeAsync"></a> |
||||
|
||||
### datastore.removeAsync(query, [options]) ⇒ <code>Promise.<number></code> |
||||
<p>Remove all docs matching the query. |
||||
Use Datastore.removeAsync which has the same signature</p> |
||||
|
||||
**Kind**: instance method of [<code>Datastore</code>](#Datastore) |
||||
**Returns**: <code>Promise.<number></code> - <p>How many documents were removed</p> |
||||
|
||||
| Param | Type | Default | Description | |
||||
| --- | --- | --- | --- | |
||||
| query | [<code>query</code>](#query) | | | |
||||
| [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> |
||||
|
||||
### "event:compaction.done" |
||||
<p>Compaction event. Happens when the Datastore's Persistence has been compacted. |
||||
It happens when calling <code>datastore.persistence.compactDatafile</code>, which is called periodically if you have called |
||||
<code>datastore.persistence.setAutocompactionInterval</code>.</p> |
||||
|
||||
**Kind**: event emitted by [<code>Datastore</code>](#Datastore) |
||||
<a name="Datastore..countCallback"></a> |
||||
|
||||
### Datastore~countCallback : <code>function</code> |
||||
**Kind**: inner typedef of [<code>Datastore</code>](#Datastore) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| err | <code>Error</code> | |
||||
| count | <code>number</code> | |
||||
|
||||
<a name="Datastore..findOneCallback"></a> |
||||
|
||||
### Datastore~findOneCallback : <code>function</code> |
||||
**Kind**: inner typedef of [<code>Datastore</code>](#Datastore) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| err | <code>Error</code> | |
||||
| doc | [<code>document</code>](#document) | |
||||
|
||||
<a name="Datastore..updateCallback"></a> |
||||
|
||||
### Datastore~updateCallback : <code>function</code> |
||||
<p>If update was an upsert, <code>upsert</code> flag is set to true, <code>affectedDocuments</code> can be one of the following:</p> |
||||
<ul> |
||||
<li>For an upsert, the upserted document</li> |
||||
<li>For an update with returnUpdatedDocs option false, null</li> |
||||
<li>For an update with returnUpdatedDocs true and multi false, the updated document</li> |
||||
<li>For an update with returnUpdatedDocs true and multi true, the array of updated documents</li> |
||||
</ul> |
||||
<p><strong>WARNING:</strong> The API was changed between v1.7.4 and v1.8, for consistency and readability reasons. Prior and |
||||
including to v1.7.4, the callback signature was (err, numAffected, updated) where updated was the updated document |
||||
in case of an upsert or the array of updated documents for an update if the returnUpdatedDocs option was true. That |
||||
meant that the type of affectedDocuments in a non multi update depended on whether there was an upsert or not, |
||||
leaving only two ways for the user to check whether an upsert had occured: checking the type of affectedDocuments |
||||
or running another find query on the whole dataset to check its size. Both options being ugly, the breaking change |
||||
was necessary.</p> |
||||
|
||||
**Kind**: inner typedef of [<code>Datastore</code>](#Datastore) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| err | <code>Error</code> | |
||||
| numAffected | <code>number</code> | |
||||
| affectedDocuments | [<code>?Array.<document></code>](#document) \| [<code>document</code>](#document) | |
||||
| upsert | <code>boolean</code> | |
||||
|
||||
<a name="Datastore..removeCallback"></a> |
||||
|
||||
### Datastore~removeCallback : <code>function</code> |
||||
**Kind**: inner typedef of [<code>Datastore</code>](#Datastore) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| err | <code>Error</code> | |
||||
| numRemoved | <code>number</code> | |
||||
|
@ -0,0 +1,88 @@ |
||||
<a name="Executor"></a> |
||||
|
||||
## Executor |
||||
<p>Executes operations sequentially. |
||||
Has an option for a buffer that can be triggered afterwards.</p> |
||||
|
||||
**Kind**: global class |
||||
|
||||
* [Executor](#Executor) |
||||
* [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) |
||||
* [.pushAsync(task, [forceQueuing])](#Executor+pushAsync) ⇒ <code>Promise.<\*></code> |
||||
* [.processBuffer()](#Executor+processBuffer) |
||||
|
||||
<a name="new_Executor_new"></a> |
||||
|
||||
### new Executor() |
||||
<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> |
||||
|
||||
### executor.push(task, [forceQueuing]) |
||||
<p>If executor is ready, queue task (and process it immediately if executor was idle) |
||||
If not, buffer task for later processing</p> |
||||
|
||||
**Kind**: instance method of [<code>Executor</code>](#Executor) |
||||
|
||||
| Param | Type | Default | Description | |
||||
| --- | --- | --- | --- | |
||||
| task | <code>Object</code> | | | |
||||
| task.this | <code>Object</code> | | <p>Object to use as this</p> | |
||||
| task.fn | <code>function</code> | | <p>Function to execute</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> | |
||||
|
||||
<a name="Executor+pushAsync"></a> |
||||
|
||||
### executor.pushAsync(task, [forceQueuing]) ⇒ <code>Promise.<\*></code> |
||||
<p>If executor is ready, queue task (and process it immediately if executor was idle) |
||||
If not, buffer task for later processing</p> |
||||
|
||||
**Kind**: instance method of [<code>Executor</code>](#Executor) |
||||
|
||||
| Param | Type | Default | |
||||
| --- | --- | --- | |
||||
| task | <code>function</code> | | |
||||
| [forceQueuing] | <code>boolean</code> | <code>false</code> | |
||||
|
||||
<a name="Executor+processBuffer"></a> |
||||
|
||||
### executor.processBuffer() |
||||
<p>Queue all tasks in buffer (in the same order they came in) |
||||
Automatically sets executor as ready</p> |
||||
|
||||
**Kind**: instance method of [<code>Executor</code>](#Executor) |
@ -0,0 +1,166 @@ |
||||
<a name="Index"></a> |
||||
|
||||
## Index |
||||
<p>Indexes on field names, with atomic operations and which can optionally enforce a unique constraint or allow indexed |
||||
fields to be undefined</p> |
||||
|
||||
**Kind**: global class |
||||
|
||||
* [Index](#Index) |
||||
* [new Index(options)](#new_Index_new) |
||||
* [.fieldName](#Index+fieldName) : <code>string</code> |
||||
* [.unique](#Index+unique) : <code>boolean</code> |
||||
* [.sparse](#Index+sparse) : <code>boolean</code> |
||||
* [.treeOptions](#Index+treeOptions) : <code>Object</code> |
||||
* [.tree](#Index+tree) : <code>AVLTree</code> |
||||
* [.reset([newData])](#Index+reset) |
||||
* [.insert(doc)](#Index+insert) |
||||
* [.remove(doc)](#Index+remove) |
||||
* [.update(oldDoc, [newDoc])](#Index+update) |
||||
* [.revertUpdate(oldDoc, [newDoc])](#Index+revertUpdate) |
||||
* [.getMatching(value)](#Index+getMatching) ⇒ [<code>Array.<document></code>](#document) |
||||
* [.getBetweenBounds(query)](#Index+getBetweenBounds) ⇒ [<code>Array.<document></code>](#document) |
||||
* [.getAll()](#Index+getAll) ⇒ [<code>Array.<document></code>](#document) |
||||
|
||||
<a name="new_Index_new"></a> |
||||
|
||||
### new Index(options) |
||||
<p>Create a new index |
||||
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> |
||||
|
||||
|
||||
| Param | Type | Default | Description | |
||||
| --- | --- | --- | --- | |
||||
| options | <code>object</code> | | | |
||||
| options.fieldName | <code>string</code> | | <p>On which field should the index apply (can use dot notation to index on sub fields)</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> |
||||
|
||||
### index.fieldName : <code>string</code> |
||||
<p>On which field the index applies to (may use dot notation to index on sub fields).</p> |
||||
|
||||
**Kind**: instance property of [<code>Index</code>](#Index) |
||||
<a name="Index+unique"></a> |
||||
|
||||
### index.unique : <code>boolean</code> |
||||
<p>Defines if the index enforces a unique constraint for this index.</p> |
||||
|
||||
**Kind**: instance property of [<code>Index</code>](#Index) |
||||
<a name="Index+sparse"></a> |
||||
|
||||
### index.sparse : <code>boolean</code> |
||||
<p>Defines if we can have documents for which fieldName is <code>undefined</code></p> |
||||
|
||||
**Kind**: instance property of [<code>Index</code>](#Index) |
||||
<a name="Index+treeOptions"></a> |
||||
|
||||
### index.treeOptions : <code>Object</code> |
||||
<p>Options object given to the underlying BinarySearchTree.</p> |
||||
|
||||
**Kind**: instance property of [<code>Index</code>](#Index) |
||||
<a name="Index+tree"></a> |
||||
|
||||
### index.tree : <code>AVLTree</code> |
||||
<p>Underlying BinarySearchTree for this index. Uses an AVLTree for optimization.</p> |
||||
|
||||
**Kind**: instance property of [<code>Index</code>](#Index) |
||||
<a name="Index+reset"></a> |
||||
|
||||
### index.reset([newData]) |
||||
<p>Reset an index</p> |
||||
|
||||
**Kind**: instance method of [<code>Index</code>](#Index) |
||||
|
||||
| Param | Type | Description | |
||||
| --- | --- | --- | |
||||
| [newData] | [<code>document</code>](#document) \| [<code>?Array.<document></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> |
||||
|
||||
### index.insert(doc) |
||||
<p>Insert a new document in the index |
||||
If an array is passed, we insert all its elements (if one insertion fails the index is not modified) |
||||
O(log(n))</p> |
||||
|
||||
**Kind**: instance method of [<code>Index</code>](#Index) |
||||
|
||||
| Param | Type | Description | |
||||
| --- | --- | --- | |
||||
| doc | [<code>document</code>](#document) \| [<code>Array.<document></code>](#document) | <p>The document, or array of documents, to insert.</p> | |
||||
|
||||
<a name="Index+remove"></a> |
||||
|
||||
### index.remove(doc) |
||||
<p>Removes a document from the index. |
||||
If an array is passed, we remove all its elements |
||||
The remove operation is safe with regards to the 'unique' constraint |
||||
O(log(n))</p> |
||||
|
||||
**Kind**: instance method of [<code>Index</code>](#Index) |
||||
|
||||
| Param | Type | Description | |
||||
| --- | --- | --- | |
||||
| doc | [<code>Array.<document></code>](#document) \| [<code>document</code>](#document) | <p>The document, or Array of documents, to remove.</p> | |
||||
|
||||
<a name="Index+update"></a> |
||||
|
||||
### index.update(oldDoc, [newDoc]) |
||||
<p>Update a document in the index |
||||
If a constraint is violated, changes are rolled back and an error thrown |
||||
Naive implementation, still in O(log(n))</p> |
||||
|
||||
**Kind**: instance method of [<code>Index</code>](#Index) |
||||
|
||||
| Param | Type | Description | |
||||
| --- | --- | --- | |
||||
| oldDoc | [<code>document</code>](#document) \| <code>Array.<{oldDoc: document, newDoc: document}></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="Index+revertUpdate"></a> |
||||
|
||||
### index.revertUpdate(oldDoc, [newDoc]) |
||||
<p>Revert an update</p> |
||||
|
||||
**Kind**: instance method of [<code>Index</code>](#Index) |
||||
|
||||
| Param | Type | Description | |
||||
| --- | --- | --- | |
||||
| oldDoc | [<code>document</code>](#document) \| <code>Array.<{oldDoc: document, newDoc: document}></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> |
||||
|
||||
### index.getMatching(value) ⇒ [<code>Array.<document></code>](#document) |
||||
<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) |
||||
|
||||
| Param | Type | Description | |
||||
| --- | --- | --- | |
||||
| value | <code>Array.<\*></code> \| <code>\*</code> | <p>Value to match the key against</p> | |
||||
|
||||
<a name="Index+getBetweenBounds"></a> |
||||
|
||||
### index.getBetweenBounds(query) ⇒ [<code>Array.<document></code>](#document) |
||||
<p>Get all documents in index whose key is between bounds are they are defined by query |
||||
Documents are sorted by key</p> |
||||
|
||||
**Kind**: instance method of [<code>Index</code>](#Index) |
||||
|
||||
| Param | Type | Description | |
||||
| --- | --- | --- | |
||||
| query | <code>object</code> | <p>An object with at least one matcher among $gt, $gte, $lt, $lte.</p> | |
||||
| [query.$gt] | <code>\*</code> | <p>Greater than matcher.</p> | |
||||
| [query.$gte] | <code>\*</code> | <p>Greater 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> |
||||
|
||||
### index.getAll() ⇒ [<code>Array.<document></code>](#document) |
||||
<p>Get all elements in the index</p> |
||||
|
||||
**Kind**: instance method of [<code>Index</code>](#Index) |
@ -0,0 +1,241 @@ |
||||
<a name="Persistence"></a> |
||||
|
||||
## Persistence |
||||
<p>Handle every persistence-related task</p> |
||||
|
||||
**Kind**: global class |
||||
|
||||
* [Persistence](#Persistence) |
||||
* [new Persistence()](#new_Persistence_new) |
||||
* _instance_ |
||||
* [.persistCachedDatabase(callback)](#Persistence+persistCachedDatabase) |
||||
* [.persistCachedDatabaseAsync()](#Persistence+persistCachedDatabaseAsync) ⇒ <code>Promise.<void></code> |
||||
* [.compactDatafile([callback])](#Persistence+compactDatafile) |
||||
* [.compactDatafileAsync()](#Persistence+compactDatafileAsync) |
||||
* [.setAutocompactionInterval(interval)](#Persistence+setAutocompactionInterval) |
||||
* [.stopAutocompaction()](#Persistence+stopAutocompaction) |
||||
* [.persistNewState(newDocs, [callback])](#Persistence+persistNewState) |
||||
* [.persistNewStateAsync(newDocs)](#Persistence+persistNewStateAsync) ⇒ <code>Promise</code> |
||||
* [.treatRawData(rawData)](#Persistence+treatRawData) ⇒ <code>Object</code> |
||||
* [.treatRawStream(rawStream, cb)](#Persistence+treatRawStream) |
||||
* [.treatRawStreamAsync(rawStream)](#Persistence+treatRawStreamAsync) ⇒ <code>Promise.<{data: Array.<document>, indexes: Object.<string, rawIndex>}></code> |
||||
* [.loadDatabase(callback)](#Persistence+loadDatabase) |
||||
* [.loadDatabaseAsync()](#Persistence+loadDatabaseAsync) ⇒ <code>Promise.<void></code> |
||||
* _static_ |
||||
* [.ensureDirectoryExists(dir, [callback])](#Persistence.ensureDirectoryExists) |
||||
* [.ensureDirectoryExistsAsync(dir)](#Persistence.ensureDirectoryExistsAsync) ⇒ <code>Promise.<void></code> |
||||
* ~~[.getNWAppFilename(appName, relativeFilename)](#Persistence.getNWAppFilename) ⇒ <code>string</code>~~ |
||||
* _inner_ |
||||
* [~treatRawStreamCallback](#Persistence..treatRawStreamCallback) : <code>function</code> |
||||
|
||||
<a name="new_Persistence_new"></a> |
||||
|
||||
### new Persistence() |
||||
<p>Create a new Persistence object for database options.db</p> |
||||
|
||||
|
||||
| Param | Type | Description | |
||||
| --- | --- | --- | |
||||
| options.db | [<code>Datastore</code>](#Datastore) | | |
||||
| [options.corruptAlertThreshold] | <code>Number</code> | <p>Optional, threshold after which an alert is thrown if too much data is corrupt</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> | |
||||
| [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> |
||||
|
||||
### persistence.persistCachedDatabase(callback) |
||||
<p>Persist cached database |
||||
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 |
||||
This is an internal function, use compactDataFile which uses the executor</p> |
||||
|
||||
**Kind**: instance method of [<code>Persistence</code>](#Persistence) |
||||
|
||||
| Param | Type | Description | |
||||
| --- | --- | --- | |
||||
| callback | [<code>NoParamCallback</code>](#NoParamCallback) | <p>Optional callback, signature: err</p> | |
||||
|
||||
<a name="Persistence+persistCachedDatabaseAsync"></a> |
||||
|
||||
### persistence.persistCachedDatabaseAsync() ⇒ <code>Promise.<void></code> |
||||
<p>Persist cached database |
||||
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 |
||||
This is an internal function, use compactDataFileAsync which uses the executor</p> |
||||
|
||||
**Kind**: instance method of [<code>Persistence</code>](#Persistence) |
||||
<a name="Persistence+compactDatafile"></a> |
||||
|
||||
### persistence.compactDatafile([callback]) |
||||
<p>Queue a rewrite of the datafile</p> |
||||
|
||||
**Kind**: instance method of [<code>Persistence</code>](#Persistence) |
||||
|
||||
| Param | Type | Default | Description | |
||||
| --- | --- | --- | --- | |
||||
| [callback] | [<code>NoParamCallback</code>](#NoParamCallback) | <code>() => {}</code> | <p>Optional callback, signature: err</p> | |
||||
|
||||
<a name="Persistence+compactDatafileAsync"></a> |
||||
|
||||
### persistence.compactDatafileAsync() |
||||
<p>Queue a rewrite of the datafile</p> |
||||
|
||||
**Kind**: instance method of [<code>Persistence</code>](#Persistence) |
||||
<a name="Persistence+setAutocompactionInterval"></a> |
||||
|
||||
### persistence.setAutocompactionInterval(interval) |
||||
<p>Set automatic compaction every interval ms</p> |
||||
|
||||
**Kind**: instance method of [<code>Persistence</code>](#Persistence) |
||||
|
||||
| Param | Type | Description | |
||||
| --- | --- | --- | |
||||
| interval | <code>Number</code> | <p>in milliseconds, with an enforced minimum of 5 seconds</p> | |
||||
|
||||
<a name="Persistence+stopAutocompaction"></a> |
||||
|
||||
### persistence.stopAutocompaction() |
||||
<p>Stop autocompaction (do nothing if autocompaction was not running)</p> |
||||
|
||||
**Kind**: instance method of [<code>Persistence</code>](#Persistence) |
||||
<a name="Persistence+persistNewState"></a> |
||||
|
||||
### persistence.persistNewState(newDocs, [callback]) |
||||
<p>Persist new state for the given newDocs (can be insertion, update or removal) |
||||
Use an append-only format</p> |
||||
|
||||
**Kind**: instance method of [<code>Persistence</code>](#Persistence) |
||||
|
||||
| Param | Type | Default | Description | |
||||
| --- | --- | --- | --- | |
||||
| newDocs | <code>Array.<string></code> | | <p>Can be empty if no doc was updated/removed</p> | |
||||
| [callback] | [<code>NoParamCallback</code>](#NoParamCallback) | <code>() => {}</code> | <p>Optional, signature: err</p> | |
||||
|
||||
<a name="Persistence+persistNewStateAsync"></a> |
||||
|
||||
### persistence.persistNewStateAsync(newDocs) ⇒ <code>Promise</code> |
||||
<p>Persist new state for the given newDocs (can be insertion, update or removal) |
||||
Use an append-only format</p> |
||||
|
||||
**Kind**: instance method of [<code>Persistence</code>](#Persistence) |
||||
|
||||
| Param | Type | Description | |
||||
| --- | --- | --- | |
||||
| newDocs | [<code>Array.<document></code>](#document) | <p>Can be empty if no doc was updated/removed</p> | |
||||
|
||||
<a name="Persistence+treatRawData"></a> |
||||
|
||||
### persistence.treatRawData(rawData) ⇒ <code>Object</code> |
||||
<p>From a database's raw data, return the corresponding machine understandable collection</p> |
||||
|
||||
**Kind**: instance method of [<code>Persistence</code>](#Persistence) |
||||
|
||||
| Param | Type | Description | |
||||
| --- | --- | --- | |
||||
| rawData | <code>string</code> | <p>database file</p> | |
||||
|
||||
<a name="Persistence+treatRawStream"></a> |
||||
|
||||
### persistence.treatRawStream(rawStream, cb) |
||||
<p>From a database's raw data stream, return the corresponding machine understandable collection</p> |
||||
|
||||
**Kind**: instance method of [<code>Persistence</code>](#Persistence) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| rawStream | <code>Readable</code> | |
||||
| cb | [<code>treatRawStreamCallback</code>](#Persistence..treatRawStreamCallback) | |
||||
|
||||
<a name="Persistence+treatRawStreamAsync"></a> |
||||
|
||||
### persistence.treatRawStreamAsync(rawStream) ⇒ <code>Promise.<{data: Array.<document>, indexes: Object.<string, rawIndex>}></code> |
||||
<p>From a database's raw data stream, return the corresponding machine understandable collection</p> |
||||
|
||||
**Kind**: instance method of [<code>Persistence</code>](#Persistence) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| rawStream | <code>Readable</code> | |
||||
|
||||
<a name="Persistence+loadDatabase"></a> |
||||
|
||||
### persistence.loadDatabase(callback) |
||||
<p>Load the database</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) |
||||
|
||||
| Param | Type | Description | |
||||
| --- | --- | --- | |
||||
| callback | [<code>NoParamCallback</code>](#NoParamCallback) | <p>Optional callback, signature: err</p> | |
||||
|
||||
<a name="Persistence+loadDatabaseAsync"></a> |
||||
|
||||
### persistence.loadDatabaseAsync() ⇒ <code>Promise.<void></code> |
||||
<p>Load the database</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) |
||||
<a name="Persistence.ensureDirectoryExists"></a> |
||||
|
||||
### Persistence.ensureDirectoryExists(dir, [callback]) |
||||
<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) |
||||
|
||||
| Param | Type | Default | Description | |
||||
| --- | --- | --- | --- | |
||||
| dir | <code>string</code> | | | |
||||
| [callback] | [<code>NoParamCallback</code>](#NoParamCallback) | <code>() => {}</code> | <p>optional callback, signature: err</p> | |
||||
|
||||
<a name="Persistence.ensureDirectoryExistsAsync"></a> |
||||
|
||||
### Persistence.ensureDirectoryExistsAsync(dir) ⇒ <code>Promise.<void></code> |
||||
<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) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| dir | <code>string</code> | |
||||
|
||||
<a name="Persistence.getNWAppFilename"></a> |
||||
|
||||
### ~~Persistence.getNWAppFilename(appName, relativeFilename) ⇒ <code>string</code>~~ |
||||
***Deprecated*** |
||||
|
||||
<p>Return the path the datafile if the given filename is relative to the directory where Node Webkit stores |
||||
data for this application. Probably the best place to store data</p> |
||||
|
||||
**Kind**: static method of [<code>Persistence</code>](#Persistence) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| appName | <code>string</code> | |
||||
| relativeFilename | <code>string</code> | |
||||
|
||||
<a name="Persistence..treatRawStreamCallback"></a> |
||||
|
||||
### Persistence~treatRawStreamCallback : <code>function</code> |
||||
**Kind**: inner typedef of [<code>Persistence</code>](#Persistence) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| err | <code>Error</code> | |
||||
| data | <code>Object</code> | |
||||
|
@ -0,0 +1,53 @@ |
||||
<a name="Waterfall"></a> |
||||
|
||||
## Waterfall |
||||
**Kind**: global class |
||||
|
||||
* [Waterfall](#Waterfall) |
||||
* [new Waterfall()](#new_Waterfall_new) |
||||
* [._guardian](#Waterfall+_guardian) : <code>Promise</code> |
||||
* [.guardian](#Waterfall+guardian) ⇒ <code>Promise</code> |
||||
* [.waterfall(func)](#Waterfall+waterfall) ⇒ [<code>AsyncFunction</code>](#AsyncFunction) |
||||
* [.chain(promise)](#Waterfall+chain) ⇒ <code>Promise</code> |
||||
|
||||
<a name="new_Waterfall_new"></a> |
||||
|
||||
### new Waterfall() |
||||
<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> |
||||
|
||||
### waterfall.guardian ⇒ <code>Promise</code> |
||||
<p>Getter that gives a Promise which resolves when all tasks up to when this function is called are done.</p> |
||||
<p>This Promise cannot reject.</p> |
||||
|
||||
**Kind**: instance property of [<code>Waterfall</code>](#Waterfall) |
||||
<a name="Waterfall+waterfall"></a> |
||||
|
||||
### waterfall.waterfall(func) ⇒ [<code>AsyncFunction</code>](#AsyncFunction) |
||||
**Kind**: instance method of [<code>Waterfall</code>](#Waterfall) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| func | [<code>AsyncFunction</code>](#AsyncFunction) | |
||||
|
||||
<a name="Waterfall+chain"></a> |
||||
|
||||
### waterfall.chain(promise) ⇒ <code>Promise</code> |
||||
<p>Shorthand for chaining a promise to the Waterfall</p> |
||||
|
||||
**Kind**: instance method of [<code>Waterfall</code>](#Waterfall) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| promise | <code>Promise</code> | |
||||
|
@ -0,0 +1,36 @@ |
||||
<a name="module_customUtilsBrowser"></a> |
||||
|
||||
## customUtilsBrowser |
||||
<p>Utility functions that need to be reimplemented for each environment. |
||||
This is the version for the browser & React-Native</p> |
||||
|
||||
|
||||
* [customUtilsBrowser](#module_customUtilsBrowser) |
||||
* [~randomBytes(size)](#module_customUtilsBrowser..randomBytes) ⇒ <code>array.<number></code> |
||||
* [~byteArrayToBase64(uint8)](#module_customUtilsBrowser..byteArrayToBase64) ⇒ <code>string</code> |
||||
|
||||
<a name="module_customUtilsBrowser..randomBytes"></a> |
||||
|
||||
### customUtilsBrowser~randomBytes(size) ⇒ <code>array.<number></code> |
||||
<p>Taken from the crypto-browserify module |
||||
https://github.com/dominictarr/crypto-browserify |
||||
NOTE: Math.random() does not guarantee "cryptographic quality" but we actually don't need it</p> |
||||
|
||||
**Kind**: inner method of [<code>customUtilsBrowser</code>](#module_customUtilsBrowser) |
||||
|
||||
| Param | Type | Description | |
||||
| --- | --- | --- | |
||||
| size | <code>number</code> | <p>in bytes</p> | |
||||
|
||||
<a name="module_customUtilsBrowser..byteArrayToBase64"></a> |
||||
|
||||
### customUtilsBrowser~byteArrayToBase64(uint8) ⇒ <code>string</code> |
||||
<p>Taken from the base64-js module |
||||
https://github.com/beatgammit/base64-js/</p> |
||||
|
||||
**Kind**: inner method of [<code>customUtilsBrowser</code>](#module_customUtilsBrowser) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| uint8 | <code>array</code> | |
||||
|
@ -0,0 +1,43 @@ |
||||
<a name="module_customUtilsNode"></a> |
||||
|
||||
## customUtilsNode |
||||
<p>Utility functions that need to be reimplemented for each environment. |
||||
This is the version for Node.js</p> |
||||
|
||||
|
||||
* [customUtilsNode](#module_customUtilsNode) |
||||
* [.uid(len)](#module_customUtilsNode.uid) ⇒ <code>string</code> |
||||
* [.uid(len)](#module_customUtilsNode.uid) ⇒ <code>string</code> |
||||
|
||||
<a name="module_customUtilsNode.uid"></a> |
||||
|
||||
### customUtilsNode.uid(len) ⇒ <code>string</code> |
||||
<p>Return a random alphanumerical string of length len |
||||
There is a very small probability (less than 1/1,000,000) for the length to be less than len |
||||
(il the base64 conversion yields too many pluses and slashes) but |
||||
that's not an issue here |
||||
The probability of a collision is extremely small (need 3*10^12 documents to have one chance in a million of a collision) |
||||
See http://en.wikipedia.org/wiki/Birthday_problem</p> |
||||
|
||||
**Kind**: static method of [<code>customUtilsNode</code>](#module_customUtilsNode) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| len | <code>number</code> | |
||||
|
||||
<a name="module_customUtilsNode.uid"></a> |
||||
|
||||
### customUtilsNode.uid(len) ⇒ <code>string</code> |
||||
<p>Return a random alphanumerical string of length len |
||||
There is a very small probability (less than 1/1,000,000) for the length to be less than len |
||||
(il the base64 conversion yields too many pluses and slashes) but |
||||
that's not an issue here |
||||
The probability of a collision is extremely small (need 3*10^12 documents to have one chance in a million of a collision) |
||||
See http://en.wikipedia.org/wiki/Birthday_problem</p> |
||||
|
||||
**Kind**: static method of [<code>customUtilsNode</code>](#module_customUtilsNode) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| len | <code>number</code> | |
||||
|
@ -0,0 +1,217 @@ |
||||
<a name="module_model"></a> |
||||
|
||||
## model |
||||
<p>Handle models (i.e. docs) |
||||
Serialization/deserialization |
||||
Copying |
||||
Querying, update</p> |
||||
|
||||
|
||||
* [model](#module_model) |
||||
* _static_ |
||||
* [.checkObject(obj)](#module_model.checkObject) |
||||
* [.serialize(obj)](#module_model.serialize) ⇒ <code>string</code> |
||||
* [.deserialize(rawData)](#module_model.deserialize) ⇒ [<code>document</code>](#document) |
||||
* [.compareThings(a, b, [_compareStrings])](#module_model.compareThings) ⇒ <code>number</code> |
||||
* [.modify(obj, updateQuery)](#module_model.modify) ⇒ [<code>document</code>](#document) |
||||
* [.getDotValue(obj, field)](#module_model.getDotValue) ⇒ <code>\*</code> |
||||
* [.areThingsEqual(a, a)](#module_model.areThingsEqual) ⇒ <code>boolean</code> |
||||
* [.match(obj, query)](#module_model.match) ⇒ <code>boolean</code> |
||||
* _inner_ |
||||
* [~modifierFunctions](#module_model..modifierFunctions) : <code>enum</code> |
||||
* [~comparisonFunctions](#module_model..comparisonFunctions) : <code>enum</code> |
||||
* [~logicalOperators](#module_model..logicalOperators) |
||||
* [~modifierFunction](#module_model..modifierFunction) : <code>function</code> |
||||
* [~comparisonOperator](#module_model..comparisonOperator) ⇒ <code>boolean</code> |
||||
* [~whereCallback](#module_model..whereCallback) ⇒ <code>boolean</code> |
||||
|
||||
<a name="module_model.checkObject"></a> |
||||
|
||||
### model.checkObject(obj) |
||||
<p>Check a DB object and throw an error if it's not valid |
||||
Works by applying the above checkKey function to all fields recursively</p> |
||||
|
||||
**Kind**: static method of [<code>model</code>](#module_model) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| obj | [<code>document</code>](#document) \| [<code>Array.<document></code>](#document) | |
||||
|
||||
<a name="module_model.serialize"></a> |
||||
|
||||
### model.serialize(obj) ⇒ <code>string</code> |
||||
<p>Serialize an object to be persisted to a one-line string |
||||
For serialization/deserialization, we use the native JSON parser and not eval or Function |
||||
That gives us less freedom but data entered in the database may come from users |
||||
so eval and the like are not safe |
||||
Accepted primitive types: Number, String, Boolean, Date, null |
||||
Accepted secondary types: Objects, Arrays</p> |
||||
|
||||
**Kind**: static method of [<code>model</code>](#module_model) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| obj | [<code>document</code>](#document) | |
||||
|
||||
<a name="module_model.deserialize"></a> |
||||
|
||||
### model.deserialize(rawData) ⇒ [<code>document</code>](#document) |
||||
<p>From a one-line representation of an object generate by the serialize function |
||||
Return the object itself</p> |
||||
|
||||
**Kind**: static method of [<code>model</code>](#module_model) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| rawData | <code>string</code> | |
||||
|
||||
<a name="module_model.compareThings"></a> |
||||
|
||||
### model.compareThings(a, b, [_compareStrings]) ⇒ <code>number</code> |
||||
<p>Compare { things U undefined } |
||||
Things are defined as any native types (string, number, boolean, null, date) and objects |
||||
We need to compare with undefined as it will be used in indexes |
||||
In the case of objects and arrays, we deep-compare |
||||
If two objects dont have the same type, the (arbitrary) type hierarchy is: undefined, null, number, strings, boolean, dates, arrays, objects |
||||
Return -1 if a < b, 1 if a > 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) |
||||
|
||||
| Param | Type | Description | |
||||
| --- | --- | --- | |
||||
| a | <code>\*</code> | | |
||||
| 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> |
||||
|
||||
### model.modify(obj, updateQuery) ⇒ [<code>document</code>](#document) |
||||
<p>Modify a DB object according to an update query</p> |
||||
|
||||
**Kind**: static method of [<code>model</code>](#module_model) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| obj | [<code>document</code>](#document) | |
||||
| updateQuery | [<code>query</code>](#query) | |
||||
|
||||
<a name="module_model.getDotValue"></a> |
||||
|
||||
### model.getDotValue(obj, field) ⇒ <code>\*</code> |
||||
<p>Get a value from object with dot notation</p> |
||||
|
||||
**Kind**: static method of [<code>model</code>](#module_model) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| obj | <code>object</code> | |
||||
| field | <code>string</code> | |
||||
|
||||
<a name="module_model.areThingsEqual"></a> |
||||
|
||||
### model.areThingsEqual(a, a) ⇒ <code>boolean</code> |
||||
<p>Check whether 'things' are equal |
||||
Things are defined as any native types (string, number, boolean, null, date) and objects |
||||
In the case of object, we check deep equality |
||||
Returns true if they are, false otherwise</p> |
||||
|
||||
**Kind**: static method of [<code>model</code>](#module_model) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| a | <code>\*</code> | |
||||
| a | <code>\*</code> | |
||||
|
||||
<a name="module_model.match"></a> |
||||
|
||||
### model.match(obj, query) ⇒ <code>boolean</code> |
||||
<p>Tell if a given document matches a query</p> |
||||
|
||||
**Kind**: static method of [<code>model</code>](#module_model) |
||||
|
||||
| Param | Type | Description | |
||||
| --- | --- | --- | |
||||
| obj | [<code>document</code>](#document) | <p>Document to check</p> | |
||||
| query | [<code>query</code>](#query) | | |
||||
|
||||
<a name="module_model..modifierFunctions"></a> |
||||
|
||||
### model~modifierFunctions : <code>enum</code> |
||||
**Kind**: inner enum of [<code>model</code>](#module_model) |
||||
**Properties** |
||||
|
||||
| Name | Type | Default | Description | |
||||
| --- | --- | --- | --- | |
||||
| $set | <code>modifierFunction</code> | <code></code> | <p>Set a field to a new value</p> | |
||||
| $unset | <code>modifierFunction</code> | <code></code> | <p>Unset a field</p> | |
||||
| $min | <code>modifierFunction</code> | <code></code> | <p>Updates the value of the field, only if specified field is smaller than the current value of the field</p> | |
||||
| $max | <code>modifierFunction</code> | <code></code> | <p>Updates the value of the field, only if specified field is greater than the current value of the field</p> | |
||||
| $inc | <code>modifierFunction</code> | <code></code> | <p>Increment a numeric field's value</p> | |
||||
| $pull | <code>modifierFunction</code> | <code></code> | <p>Removes all instances of a value from an existing array</p> | |
||||
| $pop | <code>modifierFunction</code> | <code></code> | <p>Remove the first or last element of an array</p> | |
||||
| $addToSet | <code>modifierFunction</code> | <code></code> | <p>Add an element to an array field only if it is not already in it No modification if the element is already in the array Note that it doesn't check whether the original array contains duplicates</p> | |
||||
| $push | <code>modifierFunction</code> | <code></code> | <p>Push an element to the end of an array field Optional modifier $each instead of value to push several values Optional modifier $slice to slice the resulting array, see https://docs.mongodb.org/manual/reference/operator/update/slice/ Difference with MongoDB: if $slice is specified and not $each, we act as if value is an empty array</p> | |
||||
|
||||
<a name="module_model..comparisonFunctions"></a> |
||||
|
||||
### model~comparisonFunctions : <code>enum</code> |
||||
**Kind**: inner enum of [<code>model</code>](#module_model) |
||||
**Properties** |
||||
|
||||
| Name | Type | Default | Description | |
||||
| --- | --- | --- | --- | |
||||
| $lt | <code>comparisonOperator</code> | <code></code> | <p>Lower than</p> | |
||||
| $lte | <code>comparisonOperator</code> | <code></code> | <p>Lower than or equals</p> | |
||||
| $gt | <code>comparisonOperator</code> | <code></code> | <p>Greater than</p> | |
||||
| $gte | <code>comparisonOperator</code> | <code></code> | <p>Greater than or equals</p> | |
||||
| $ne | <code>comparisonOperator</code> | <code></code> | <p>Does not equal</p> | |
||||
| $in | <code>comparisonOperator</code> | <code></code> | <p>Is in Array</p> | |
||||
| $nin | <code>comparisonOperator</code> | <code></code> | <p>Is not in Array</p> | |
||||
| $regex | <code>comparisonOperator</code> | <code></code> | <p>Matches Regexp</p> | |
||||
| $exists | <code>comparisonOperator</code> | <code></code> | <p>Returns true if field exists</p> | |
||||
| $size | <code>comparisonOperator</code> | <code></code> | <p>Specific to Arrays, returns true if a length equals b</p> | |
||||
| $elemMatch | <code>comparisonOperator</code> | <code></code> | <p>Specific to Arrays, returns true if some elements of a match the query b</p> | |
||||
|
||||
<a name="module_model..logicalOperators"></a> |
||||
|
||||
### model~logicalOperators |
||||
**Kind**: inner enum of [<code>model</code>](#module_model) |
||||
**Properties** |
||||
|
||||
| Name | Default | Description | |
||||
| --- | --- | --- | |
||||
| $or | <code></code> | <p>Match any of the subqueries</p> | |
||||
| $and | <code></code> | <p>Match all of the subqueries</p> | |
||||
| $not | <code></code> | <p>Inverted match of the query</p> | |
||||
| $where | <code></code> | <p>Use a function to match</p> | |
||||
|
||||
<a name="module_model..modifierFunction"></a> |
||||
|
||||
### model~modifierFunction : <code>function</code> |
||||
**Kind**: inner typedef of [<code>model</code>](#module_model) |
||||
|
||||
| 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> | |
||||
| value | [<code>document</code>](#document) | | |
||||
|
||||
<a name="module_model..comparisonOperator"></a> |
||||
|
||||
### model~comparisonOperator ⇒ <code>boolean</code> |
||||
**Kind**: inner typedef of [<code>model</code>](#module_model) |
||||
|
||||
| Param | Type | Description | |
||||
| --- | --- | --- | |
||||
| a | <code>\*</code> | <p>Value in the object</p> | |
||||
| b | <code>\*</code> | <p>Value in the query</p> | |
||||
|
||||
<a name="module_model..whereCallback"></a> |
||||
|
||||
### model~whereCallback ⇒ <code>boolean</code> |
||||
**Kind**: inner typedef of [<code>model</code>](#module_model) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| obj | [<code>document</code>](#document) | |
||||
|
@ -0,0 +1,369 @@ |
||||
<a name="module_storage"></a> |
||||
|
||||
## storage |
||||
<p>Way data is stored for this database |
||||
For a Node.js/Node Webkit database it's the file system |
||||
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> |
||||
<p>This version is the Node.js/Node Webkit version |
||||
It's essentially fs, mkdirp and crash safe write and read functions</p> |
||||
|
||||
|
||||
* [storage](#module_storage) |
||||
* _static_ |
||||
* [.exists(file, cb)](#module_storage.exists) |
||||
* [.existsAsync(file)](#module_storage.existsAsync) ⇒ <code>Promise.<boolean></code> |
||||
* [.rename(oldPath, newPath, c)](#module_storage.rename) ⇒ <code>void</code> |
||||
* [.renameAsync(oldPath, newPath)](#module_storage.renameAsync) ⇒ <code>Promise.<void></code> |
||||
* [.writeFile(path, data, options, callback)](#module_storage.writeFile) |
||||
* [.writeFileAsync(path, data, [options])](#module_storage.writeFileAsync) ⇒ <code>Promise.<void></code> |
||||
* [.writeFileStream(path, [options])](#module_storage.writeFileStream) ⇒ <code>fs.WriteStream</code> |
||||
* [.unlink(path, callback)](#module_storage.unlink) |
||||
* [.unlinkAsync(path)](#module_storage.unlinkAsync) ⇒ <code>Promise.<void></code> |
||||
* [.appendFile(path, data, options, callback)](#module_storage.appendFile) |
||||
* [.appendFileAsync(path, data, [options])](#module_storage.appendFileAsync) ⇒ <code>Promise.<void></code> |
||||
* [.readFile(path, options, callback)](#module_storage.readFile) |
||||
* [.readFileAsync(path, [options])](#module_storage.readFileAsync) ⇒ <code>Promise.<Buffer></code> |
||||
* [.readFileStream(path, [options])](#module_storage.readFileStream) ⇒ <code>fs.ReadStream</code> |
||||
* [.mkdir(path, options, callback)](#module_storage.mkdir) |
||||
* [.mkdirAsync(path, options)](#module_storage.mkdirAsync) ⇒ <code>Promise.<(void\|string)></code> |
||||
* [.ensureFileDoesntExistAsync(file)](#module_storage.ensureFileDoesntExistAsync) ⇒ <code>Promise.<void></code> |
||||
* [.ensureFileDoesntExist(file, callback)](#module_storage.ensureFileDoesntExist) |
||||
* [.flushToStorage(options, callback)](#module_storage.flushToStorage) |
||||
* [.flushToStorageAsync(options)](#module_storage.flushToStorageAsync) ⇒ <code>Promise.<void></code> |
||||
* [.writeFileLines(filename, lines, callback)](#module_storage.writeFileLines) |
||||
* [.writeFileLinesAsync(filename, lines)](#module_storage.writeFileLinesAsync) ⇒ <code>Promise.<void></code> |
||||
* [.crashSafeWriteFileLines(filename, lines, [callback])](#module_storage.crashSafeWriteFileLines) |
||||
* [.crashSafeWriteFileLinesAsync(filename, lines)](#module_storage.crashSafeWriteFileLinesAsync) ⇒ <code>Promise.<void></code> |
||||
* [.ensureDatafileIntegrity(filename, callback)](#module_storage.ensureDatafileIntegrity) |
||||
* [.ensureDatafileIntegrityAsync(filename)](#module_storage.ensureDatafileIntegrityAsync) ⇒ <code>Promise.<void></code> |
||||
* _inner_ |
||||
* [~existsCallback](#module_storage..existsCallback) : <code>function</code> |
||||
|
||||
<a name="module_storage.exists"></a> |
||||
|
||||
### storage.exists(file, cb) |
||||
<p>Callback returns true if file exists</p> |
||||
|
||||
**Kind**: static method of [<code>storage</code>](#module_storage) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| file | <code>string</code> | |
||||
| cb | [<code>existsCallback</code>](#module_storage..existsCallback) | |
||||
|
||||
<a name="module_storage.existsAsync"></a> |
||||
|
||||
### storage.existsAsync(file) ⇒ <code>Promise.<boolean></code> |
||||
<p>Returns Promise<true> if file exists</p> |
||||
|
||||
**Kind**: static method of [<code>storage</code>](#module_storage) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| file | <code>string</code> | |
||||
|
||||
<a name="module_storage.rename"></a> |
||||
|
||||
### storage.rename(oldPath, newPath, c) ⇒ <code>void</code> |
||||
<p>Node.js' fs.rename</p> |
||||
|
||||
**Kind**: static method of [<code>storage</code>](#module_storage) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| oldPath | <code>string</code> | |
||||
| newPath | <code>string</code> | |
||||
| c | [<code>NoParamCallback</code>](#NoParamCallback) | |
||||
|
||||
<a name="module_storage.renameAsync"></a> |
||||
|
||||
### storage.renameAsync(oldPath, newPath) ⇒ <code>Promise.<void></code> |
||||
<p>Node.js' fs.promises.rename</p> |
||||
|
||||
**Kind**: static method of [<code>storage</code>](#module_storage) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| oldPath | <code>string</code> | |
||||
| newPath | <code>string</code> | |
||||
|
||||
<a name="module_storage.writeFile"></a> |
||||
|
||||
### storage.writeFile(path, data, options, callback) |
||||
<p>Node.js' fs.writeFile</p> |
||||
|
||||
**Kind**: static method of [<code>storage</code>](#module_storage) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| path | <code>string</code> | |
||||
| data | <code>string</code> | |
||||
| options | <code>object</code> | |
||||
| callback | <code>function</code> | |
||||
|
||||
<a name="module_storage.writeFileAsync"></a> |
||||
|
||||
### storage.writeFileAsync(path, data, [options]) ⇒ <code>Promise.<void></code> |
||||
<p>Node.js' fs.promises.writeFile</p> |
||||
|
||||
**Kind**: static method of [<code>storage</code>](#module_storage) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| path | <code>string</code> | |
||||
| data | <code>string</code> | |
||||
| [options] | <code>object</code> | |
||||
|
||||
<a name="module_storage.writeFileStream"></a> |
||||
|
||||
### storage.writeFileStream(path, [options]) ⇒ <code>fs.WriteStream</code> |
||||
<p>Node.js' fs.createWriteStream</p> |
||||
|
||||
**Kind**: static method of [<code>storage</code>](#module_storage) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| path | <code>string</code> | |
||||
| [options] | <code>Object</code> | |
||||
|
||||
<a name="module_storage.unlink"></a> |
||||
|
||||
### storage.unlink(path, callback) |
||||
<p>Node.js' fs.unlink</p> |
||||
|
||||
**Kind**: static method of [<code>storage</code>](#module_storage) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| path | <code>string</code> | |
||||
| callback | <code>function</code> | |
||||
|
||||
<a name="module_storage.unlinkAsync"></a> |
||||
|
||||
### storage.unlinkAsync(path) ⇒ <code>Promise.<void></code> |
||||
<p>Node.js' fs.promises.unlink</p> |
||||
|
||||
**Kind**: static method of [<code>storage</code>](#module_storage) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| path | <code>string</code> | |
||||
|
||||
<a name="module_storage.appendFile"></a> |
||||
|
||||
### storage.appendFile(path, data, options, callback) |
||||
<p>Node.js' fs.appendFile</p> |
||||
|
||||
**Kind**: static method of [<code>storage</code>](#module_storage) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| path | <code>string</code> | |
||||
| data | <code>string</code> | |
||||
| options | <code>object</code> | |
||||
| callback | <code>function</code> | |
||||
|
||||
<a name="module_storage.appendFileAsync"></a> |
||||
|
||||
### storage.appendFileAsync(path, data, [options]) ⇒ <code>Promise.<void></code> |
||||
<p>Node.js' fs.promises.appendFile</p> |
||||
|
||||
**Kind**: static method of [<code>storage</code>](#module_storage) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| path | <code>string</code> | |
||||
| data | <code>string</code> | |
||||
| [options] | <code>object</code> | |
||||
|
||||
<a name="module_storage.readFile"></a> |
||||
|
||||
### storage.readFile(path, options, callback) |
||||
<p>Node.js' fs.readFile</p> |
||||
|
||||
**Kind**: static method of [<code>storage</code>](#module_storage) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| path | <code>string</code> | |
||||
| options | <code>object</code> | |
||||
| callback | <code>function</code> | |
||||
|
||||
<a name="module_storage.readFileAsync"></a> |
||||
|
||||
### storage.readFileAsync(path, [options]) ⇒ <code>Promise.<Buffer></code> |
||||
<p>Node.js' fs.promises.readFile</p> |
||||
|
||||
**Kind**: static method of [<code>storage</code>](#module_storage) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| path | <code>string</code> | |
||||
| [options] | <code>object</code> | |
||||
|
||||
<a name="module_storage.readFileStream"></a> |
||||
|
||||
### storage.readFileStream(path, [options]) ⇒ <code>fs.ReadStream</code> |
||||
<p>Node.js' fs.createReadStream</p> |
||||
|
||||
**Kind**: static method of [<code>storage</code>](#module_storage) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| path | <code>string</code> | |
||||
| [options] | <code>Object</code> | |
||||
|
||||
<a name="module_storage.mkdir"></a> |
||||
|
||||
### storage.mkdir(path, options, callback) |
||||
<p>Node.js' fs.mkdir</p> |
||||
|
||||
**Kind**: static method of [<code>storage</code>](#module_storage) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| path | <code>string</code> | |
||||
| options | <code>object</code> | |
||||
| callback | <code>function</code> | |
||||
|
||||
<a name="module_storage.mkdirAsync"></a> |
||||
|
||||
### storage.mkdirAsync(path, options) ⇒ <code>Promise.<(void\|string)></code> |
||||
<p>Node.js' fs.promises.mkdir</p> |
||||
|
||||
**Kind**: static method of [<code>storage</code>](#module_storage) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| path | <code>string</code> | |
||||
| options | <code>object</code> | |
||||
|
||||
<a name="module_storage.ensureFileDoesntExistAsync"></a> |
||||
|
||||
### storage.ensureFileDoesntExistAsync(file) ⇒ <code>Promise.<void></code> |
||||
**Kind**: static method of [<code>storage</code>](#module_storage) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| file | <code>string</code> | |
||||
|
||||
<a name="module_storage.ensureFileDoesntExist"></a> |
||||
|
||||
### storage.ensureFileDoesntExist(file, callback) |
||||
**Kind**: static method of [<code>storage</code>](#module_storage) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| file | <code>string</code> | |
||||
| callback | [<code>NoParamCallback</code>](#NoParamCallback) | |
||||
|
||||
<a name="module_storage.flushToStorage"></a> |
||||
|
||||
### storage.flushToStorage(options, callback) |
||||
<p>Flush data in OS buffer to storage if corresponding option is set</p> |
||||
|
||||
**Kind**: static method of [<code>storage</code>](#module_storage) |
||||
|
||||
| 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> | |
||||
| [options.filename] | <code>string</code> | | | |
||||
| [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> |
||||
|
||||
### storage.flushToStorageAsync(options) ⇒ <code>Promise.<void></code> |
||||
<p>Flush data in OS buffer to storage if corresponding option is set</p> |
||||
|
||||
**Kind**: static method of [<code>storage</code>](#module_storage) |
||||
|
||||
| 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> | |
||||
| [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> |
||||
|
||||
### storage.writeFileLines(filename, lines, callback) |
||||
<p>Fully write or rewrite the datafile</p> |
||||
|
||||
**Kind**: static method of [<code>storage</code>](#module_storage) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| filename | <code>string</code> | |
||||
| lines | <code>Array.<string></code> | |
||||
| callback | [<code>NoParamCallback</code>](#NoParamCallback) | |
||||
|
||||
<a name="module_storage.writeFileLinesAsync"></a> |
||||
|
||||
### storage.writeFileLinesAsync(filename, lines) ⇒ <code>Promise.<void></code> |
||||
<p>Fully write or rewrite the datafile</p> |
||||
|
||||
**Kind**: static method of [<code>storage</code>](#module_storage) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| filename | <code>string</code> | |
||||
| lines | <code>Array.<string></code> | |
||||
|
||||
<a name="module_storage.crashSafeWriteFileLines"></a> |
||||
|
||||
### 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> |
||||
|
||||
**Kind**: static method of [<code>storage</code>](#module_storage) |
||||
|
||||
| Param | Type | Description | |
||||
| --- | --- | --- | |
||||
| filename | <code>string</code> | | |
||||
| lines | <code>Array.<string></code> | | |
||||
| [callback] | [<code>NoParamCallback</code>](#NoParamCallback) | <p>Optional callback, signature: err</p> | |
||||
|
||||
<a name="module_storage.crashSafeWriteFileLinesAsync"></a> |
||||
|
||||
### storage.crashSafeWriteFileLinesAsync(filename, lines) ⇒ <code>Promise.<void></code> |
||||
<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) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| filename | <code>string</code> | |
||||
| lines | <code>Array.<string></code> | |
||||
|
||||
<a name="module_storage.ensureDatafileIntegrity"></a> |
||||
|
||||
### storage.ensureDatafileIntegrity(filename, callback) |
||||
<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) |
||||
|
||||
| Param | Type | Description | |
||||
| --- | --- | --- | |
||||
| filename | <code>string</code> | | |
||||
| callback | [<code>NoParamCallback</code>](#NoParamCallback) | <p>signature: err</p> | |
||||
|
||||
<a name="module_storage.ensureDatafileIntegrityAsync"></a> |
||||
|
||||
### storage.ensureDatafileIntegrityAsync(filename) ⇒ <code>Promise.<void></code> |
||||
<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) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| filename | <code>string</code> | |
||||
|
||||
<a name="module_storage..existsCallback"></a> |
||||
|
||||
### storage~existsCallback : <code>function</code> |
||||
**Kind**: inner typedef of [<code>storage</code>](#module_storage) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| exists | <code>boolean</code> | |
||||
|
@ -0,0 +1,266 @@ |
||||
<a name="module_storageBrowser"></a> |
||||
|
||||
## storageBrowser |
||||
<p>Way data is stored for this database |
||||
For a Node.js/Node Webkit database it's the file system |
||||
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> |
||||
|
||||
|
||||
* [storageBrowser](#module_storageBrowser) |
||||
* _static_ |
||||
* [.existsAsync(file)](#module_storageBrowser.existsAsync) ⇒ <code>Promise.<boolean></code> |
||||
* [.exists(file, cb)](#module_storageBrowser.exists) |
||||
* [.renameAsync(oldPath, newPath)](#module_storageBrowser.renameAsync) ⇒ <code>Promise.<void></code> |
||||
* [.rename(oldPath, newPath, c)](#module_storageBrowser.rename) ⇒ <code>void</code> |
||||
* [.writeFileAsync(file, data, [options])](#module_storageBrowser.writeFileAsync) ⇒ <code>Promise.<void></code> |
||||
* [.writeFile(path, data, options, callback)](#module_storageBrowser.writeFile) |
||||
* [.appendFileAsync(filename, toAppend, [options])](#module_storageBrowser.appendFileAsync) ⇒ <code>Promise.<void></code> |
||||
* [.appendFile(filename, toAppend, [options], callback)](#module_storageBrowser.appendFile) |
||||
* [.readFileAsync(filename, [options])](#module_storageBrowser.readFileAsync) ⇒ <code>Promise.<Buffer></code> |
||||
* [.readFile(filename, options, callback)](#module_storageBrowser.readFile) |
||||
* [.unlinkAsync(filename)](#module_storageBrowser.unlinkAsync) ⇒ <code>Promise.<void></code> |
||||
* [.unlink(path, callback)](#module_storageBrowser.unlink) |
||||
* [.mkdirAsync(path, [options])](#module_storageBrowser.mkdirAsync) ⇒ <code>Promise.<(void\|string)></code> |
||||
* [.mkdir(path, options, callback)](#module_storageBrowser.mkdir) |
||||
* [.ensureDatafileIntegrityAsync(filename)](#module_storageBrowser.ensureDatafileIntegrityAsync) ⇒ <code>Promise.<void></code> |
||||
* [.ensureDatafileIntegrity(filename, callback)](#module_storageBrowser.ensureDatafileIntegrity) |
||||
* [.crashSafeWriteFileLinesAsync(filename, lines)](#module_storageBrowser.crashSafeWriteFileLinesAsync) ⇒ <code>Promise.<void></code> |
||||
* [.crashSafeWriteFileLines(filename, lines, [callback])](#module_storageBrowser.crashSafeWriteFileLines) |
||||
* _inner_ |
||||
* [~existsCallback](#module_storageBrowser..existsCallback) : <code>function</code> |
||||
|
||||
<a name="module_storageBrowser.existsAsync"></a> |
||||
|
||||
### storageBrowser.existsAsync(file) ⇒ <code>Promise.<boolean></code> |
||||
<p>Returns Promise<true> if file exists</p> |
||||
|
||||
**Kind**: static method of [<code>storageBrowser</code>](#module_storageBrowser) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| file | <code>string</code> | |
||||
|
||||
<a name="module_storageBrowser.exists"></a> |
||||
|
||||
### storageBrowser.exists(file, cb) |
||||
<p>Callback returns true if file exists</p> |
||||
|
||||
**Kind**: static method of [<code>storageBrowser</code>](#module_storageBrowser) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| file | <code>string</code> | |
||||
| cb | [<code>existsCallback</code>](#module_storageBrowser..existsCallback) | |
||||
|
||||
<a name="module_storageBrowser.renameAsync"></a> |
||||
|
||||
### storageBrowser.renameAsync(oldPath, newPath) ⇒ <code>Promise.<void></code> |
||||
<p>Moves the item from one path to another</p> |
||||
|
||||
**Kind**: static method of [<code>storageBrowser</code>](#module_storageBrowser) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| oldPath | <code>string</code> | |
||||
| newPath | <code>string</code> | |
||||
|
||||
<a name="module_storageBrowser.rename"></a> |
||||
|
||||
### storageBrowser.rename(oldPath, newPath, c) ⇒ <code>void</code> |
||||
<p>Moves the item from one path to another</p> |
||||
|
||||
**Kind**: static method of [<code>storageBrowser</code>](#module_storageBrowser) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| oldPath | <code>string</code> | |
||||
| newPath | <code>string</code> | |
||||
| c | [<code>NoParamCallback</code>](#NoParamCallback) | |
||||
|
||||
<a name="module_storageBrowser.writeFileAsync"></a> |
||||
|
||||
### storageBrowser.writeFileAsync(file, data, [options]) ⇒ <code>Promise.<void></code> |
||||
<p>Saves the item at given path</p> |
||||
|
||||
**Kind**: static method of [<code>storageBrowser</code>](#module_storageBrowser) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| file | <code>string</code> | |
||||
| data | <code>string</code> | |
||||
| [options] | <code>object</code> | |
||||
|
||||
<a name="module_storageBrowser.writeFile"></a> |
||||
|
||||
### storageBrowser.writeFile(path, data, options, callback) |
||||
<p>Saves the item at given path</p> |
||||
|
||||
**Kind**: static method of [<code>storageBrowser</code>](#module_storageBrowser) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| path | <code>string</code> | |
||||
| data | <code>string</code> | |
||||
| options | <code>object</code> | |
||||
| callback | <code>function</code> | |
||||
|
||||
<a name="module_storageBrowser.appendFileAsync"></a> |
||||
|
||||
### storageBrowser.appendFileAsync(filename, toAppend, [options]) ⇒ <code>Promise.<void></code> |
||||
<p>Append to the item at given path</p> |
||||
|
||||
**Kind**: static method of [<code>storageBrowser</code>](#module_storageBrowser) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| filename | <code>string</code> | |
||||
| toAppend | <code>string</code> | |
||||
| [options] | <code>object</code> | |
||||
|
||||
<a name="module_storageBrowser.appendFile"></a> |
||||
|
||||
### storageBrowser.appendFile(filename, toAppend, [options], callback) |
||||
<p>Append to the item at given path</p> |
||||
|
||||
**Kind**: static method of [<code>storageBrowser</code>](#module_storageBrowser) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| filename | <code>string</code> | |
||||
| toAppend | <code>string</code> | |
||||
| [options] | <code>object</code> | |
||||
| callback | <code>function</code> | |
||||
|
||||
<a name="module_storageBrowser.readFileAsync"></a> |
||||
|
||||
### storageBrowser.readFileAsync(filename, [options]) ⇒ <code>Promise.<Buffer></code> |
||||
<p>Read data at given path</p> |
||||
|
||||
**Kind**: static method of [<code>storageBrowser</code>](#module_storageBrowser) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| filename | <code>string</code> | |
||||
| [options] | <code>object</code> | |
||||
|
||||
<a name="module_storageBrowser.readFile"></a> |
||||
|
||||
### storageBrowser.readFile(filename, options, callback) |
||||
<p>Read data at given path</p> |
||||
|
||||
**Kind**: static method of [<code>storageBrowser</code>](#module_storageBrowser) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| filename | <code>string</code> | |
||||
| options | <code>object</code> | |
||||
| callback | <code>function</code> | |
||||
|
||||
<a name="module_storageBrowser.unlinkAsync"></a> |
||||
|
||||
### storageBrowser.unlinkAsync(filename) ⇒ <code>Promise.<void></code> |
||||
<p>Remove the data at given path</p> |
||||
|
||||
**Kind**: static method of [<code>storageBrowser</code>](#module_storageBrowser) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| filename | <code>string</code> | |
||||
|
||||
<a name="module_storageBrowser.unlink"></a> |
||||
|
||||
### storageBrowser.unlink(path, callback) |
||||
<p>Remove the data at given path</p> |
||||
|
||||
**Kind**: static method of [<code>storageBrowser</code>](#module_storageBrowser) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| path | <code>string</code> | |
||||
| callback | <code>function</code> | |
||||
|
||||
<a name="module_storageBrowser.mkdirAsync"></a> |
||||
|
||||
### storageBrowser.mkdirAsync(path, [options]) ⇒ <code>Promise.<(void\|string)></code> |
||||
<p>Shim for storage.mkdirAsync, nothing to do, no directories will be used on the browser</p> |
||||
|
||||
**Kind**: static method of [<code>storageBrowser</code>](#module_storageBrowser) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| path | <code>string</code> | |
||||
| [options] | <code>object</code> | |
||||
|
||||
<a name="module_storageBrowser.mkdir"></a> |
||||
|
||||
### storageBrowser.mkdir(path, options, callback) |
||||
<p>Shim for storage.mkdir, nothing to do, no directories will be used on the browser</p> |
||||
|
||||
**Kind**: static method of [<code>storageBrowser</code>](#module_storageBrowser) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| path | <code>string</code> | |
||||
| options | <code>object</code> | |
||||
| callback | <code>function</code> | |
||||
|
||||
<a name="module_storageBrowser.ensureDatafileIntegrityAsync"></a> |
||||
|
||||
### storageBrowser.ensureDatafileIntegrityAsync(filename) ⇒ <code>Promise.<void></code> |
||||
<p>Ensure the datafile contains all the data, even if there was a crash during a full file write |
||||
Nothing to do, no data corruption possible in the browser</p> |
||||
|
||||
**Kind**: static method of [<code>storageBrowser</code>](#module_storageBrowser) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| filename | <code>string</code> | |
||||
|
||||
<a name="module_storageBrowser.ensureDatafileIntegrity"></a> |
||||
|
||||
### storageBrowser.ensureDatafileIntegrity(filename, callback) |
||||
<p>Ensure the datafile contains all the data, even if there was a crash during a full file write |
||||
Nothing to do, no data corruption possible in the browser</p> |
||||
|
||||
**Kind**: static method of [<code>storageBrowser</code>](#module_storageBrowser) |
||||
|
||||
| Param | Type | Description | |
||||
| --- | --- | --- | |
||||
| filename | <code>string</code> | | |
||||
| callback | [<code>NoParamCallback</code>](#NoParamCallback) | <p>signature: err</p> | |
||||
|
||||
<a name="module_storageBrowser.crashSafeWriteFileLinesAsync"></a> |
||||
|
||||
### storageBrowser.crashSafeWriteFileLinesAsync(filename, lines) ⇒ <code>Promise.<void></code> |
||||
<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) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| filename | <code>string</code> | |
||||
| lines | <code>Array.<string></code> | |
||||
|
||||
<a name="module_storageBrowser.crashSafeWriteFileLines"></a> |
||||
|
||||
### storageBrowser.crashSafeWriteFileLines(filename, lines, [callback]) |
||||
<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) |
||||
|
||||
| Param | Type | Description | |
||||
| --- | --- | --- | |
||||
| filename | <code>string</code> | | |
||||
| lines | <code>Array.<string></code> | | |
||||
| [callback] | [<code>NoParamCallback</code>](#NoParamCallback) | <p>Optional callback, signature: err</p> | |
||||
|
||||
<a name="module_storageBrowser..existsCallback"></a> |
||||
|
||||
### storageBrowser~existsCallback : <code>function</code> |
||||
**Kind**: inner typedef of [<code>storageBrowser</code>](#module_storageBrowser) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| exists | <code>boolean</code> | |
||||
|
@ -0,0 +1,267 @@ |
||||
<a name="module_storageReactNative"></a> |
||||
|
||||
## storageReactNative |
||||
<p>Way data is stored for this database |
||||
For a Node.js/Node Webkit database it's the file system |
||||
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> |
||||
<p>This version is the react-native version</p> |
||||
|
||||
|
||||
* [storageReactNative](#module_storageReactNative) |
||||
* _static_ |
||||
* [.existsAsync(file)](#module_storageReactNative.existsAsync) ⇒ <code>Promise.<boolean></code> |
||||
* [.exists(file, cb)](#module_storageReactNative.exists) |
||||
* [.renameAsync(oldPath, newPath)](#module_storageReactNative.renameAsync) ⇒ <code>Promise.<void></code> |
||||
* [.rename(oldPath, newPath, c)](#module_storageReactNative.rename) ⇒ <code>void</code> |
||||
* [.writeFileAsync(file, data, [options])](#module_storageReactNative.writeFileAsync) ⇒ <code>Promise.<void></code> |
||||
* [.writeFile(path, data, options, callback)](#module_storageReactNative.writeFile) |
||||
* [.appendFileAsync(filename, toAppend, [options])](#module_storageReactNative.appendFileAsync) ⇒ <code>Promise.<void></code> |
||||
* [.appendFile(filename, toAppend, [options], callback)](#module_storageReactNative.appendFile) |
||||
* [.readFileAsync(filename, [options])](#module_storageReactNative.readFileAsync) ⇒ <code>Promise.<string></code> |
||||
* [.readFile(filename, options, callback)](#module_storageReactNative.readFile) |
||||
* [.unlinkAsync(filename)](#module_storageReactNative.unlinkAsync) ⇒ <code>Promise.<void></code> |
||||
* [.unlink(path, callback)](#module_storageReactNative.unlink) |
||||
* [.mkdirAsync(dir, [options])](#module_storageReactNative.mkdirAsync) ⇒ <code>Promise.<(void\|string)></code> |
||||
* [.mkdir(path, options, callback)](#module_storageReactNative.mkdir) |
||||
* [.ensureDatafileIntegrityAsync(filename)](#module_storageReactNative.ensureDatafileIntegrityAsync) ⇒ <code>Promise.<void></code> |
||||
* [.ensureDatafileIntegrity(filename, callback)](#module_storageReactNative.ensureDatafileIntegrity) |
||||
* [.crashSafeWriteFileLinesAsync(filename, lines)](#module_storageReactNative.crashSafeWriteFileLinesAsync) ⇒ <code>Promise.<void></code> |
||||
* [.crashSafeWriteFileLines(filename, lines, [callback])](#module_storageReactNative.crashSafeWriteFileLines) |
||||
* _inner_ |
||||
* [~existsCallback](#module_storageReactNative..existsCallback) : <code>function</code> |
||||
|
||||
<a name="module_storageReactNative.existsAsync"></a> |
||||
|
||||
### storageReactNative.existsAsync(file) ⇒ <code>Promise.<boolean></code> |
||||
<p>Returns Promise<true> if file exists</p> |
||||
|
||||
**Kind**: static method of [<code>storageReactNative</code>](#module_storageReactNative) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| file | <code>string</code> | |
||||
|
||||
<a name="module_storageReactNative.exists"></a> |
||||
|
||||
### storageReactNative.exists(file, cb) |
||||
<p>Callback returns true if file exists</p> |
||||
|
||||
**Kind**: static method of [<code>storageReactNative</code>](#module_storageReactNative) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| file | <code>string</code> | |
||||
| cb | [<code>existsCallback</code>](#module_storageReactNative..existsCallback) | |
||||
|
||||
<a name="module_storageReactNative.renameAsync"></a> |
||||
|
||||
### storageReactNative.renameAsync(oldPath, newPath) ⇒ <code>Promise.<void></code> |
||||
<p>Moves the item from one path to another</p> |
||||
|
||||
**Kind**: static method of [<code>storageReactNative</code>](#module_storageReactNative) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| oldPath | <code>string</code> | |
||||
| newPath | <code>string</code> | |
||||
|
||||
<a name="module_storageReactNative.rename"></a> |
||||
|
||||
### storageReactNative.rename(oldPath, newPath, c) ⇒ <code>void</code> |
||||
<p>Moves the item from one path to another</p> |
||||
|
||||
**Kind**: static method of [<code>storageReactNative</code>](#module_storageReactNative) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| oldPath | <code>string</code> | |
||||
| newPath | <code>string</code> | |
||||
| c | [<code>NoParamCallback</code>](#NoParamCallback) | |
||||
|
||||
<a name="module_storageReactNative.writeFileAsync"></a> |
||||
|
||||
### storageReactNative.writeFileAsync(file, data, [options]) ⇒ <code>Promise.<void></code> |
||||
<p>Saves the item at given path</p> |
||||
|
||||
**Kind**: static method of [<code>storageReactNative</code>](#module_storageReactNative) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| file | <code>string</code> | |
||||
| data | <code>string</code> | |
||||
| [options] | <code>object</code> | |
||||
|
||||
<a name="module_storageReactNative.writeFile"></a> |
||||
|
||||
### storageReactNative.writeFile(path, data, options, callback) |
||||
<p>Saves the item at given path</p> |
||||
|
||||
**Kind**: static method of [<code>storageReactNative</code>](#module_storageReactNative) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| path | <code>string</code> | |
||||
| data | <code>string</code> | |
||||
| options | <code>object</code> | |
||||
| callback | <code>function</code> | |
||||
|
||||
<a name="module_storageReactNative.appendFileAsync"></a> |
||||
|
||||
### storageReactNative.appendFileAsync(filename, toAppend, [options]) ⇒ <code>Promise.<void></code> |
||||
<p>Append to the item at given path</p> |
||||
|
||||
**Kind**: static method of [<code>storageReactNative</code>](#module_storageReactNative) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| filename | <code>string</code> | |
||||
| toAppend | <code>string</code> | |
||||
| [options] | <code>object</code> | |
||||
|
||||
<a name="module_storageReactNative.appendFile"></a> |
||||
|
||||
### storageReactNative.appendFile(filename, toAppend, [options], callback) |
||||
<p>Append to the item at given path</p> |
||||
|
||||
**Kind**: static method of [<code>storageReactNative</code>](#module_storageReactNative) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| filename | <code>string</code> | |
||||
| toAppend | <code>string</code> | |
||||
| [options] | <code>object</code> | |
||||
| callback | <code>function</code> | |
||||
|
||||
<a name="module_storageReactNative.readFileAsync"></a> |
||||
|
||||
### storageReactNative.readFileAsync(filename, [options]) ⇒ <code>Promise.<string></code> |
||||
<p>Read data at given path</p> |
||||
|
||||
**Kind**: static method of [<code>storageReactNative</code>](#module_storageReactNative) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| filename | <code>string</code> | |
||||
| [options] | <code>object</code> | |
||||
|
||||
<a name="module_storageReactNative.readFile"></a> |
||||
|
||||
### storageReactNative.readFile(filename, options, callback) |
||||
<p>Read data at given path</p> |
||||
|
||||
**Kind**: static method of [<code>storageReactNative</code>](#module_storageReactNative) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| filename | <code>string</code> | |
||||
| options | <code>object</code> | |
||||
| callback | <code>function</code> | |
||||
|
||||
<a name="module_storageReactNative.unlinkAsync"></a> |
||||
|
||||
### storageReactNative.unlinkAsync(filename) ⇒ <code>Promise.<void></code> |
||||
<p>Remove the data at given path</p> |
||||
|
||||
**Kind**: static method of [<code>storageReactNative</code>](#module_storageReactNative) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| filename | <code>string</code> | |
||||
|
||||
<a name="module_storageReactNative.unlink"></a> |
||||
|
||||
### storageReactNative.unlink(path, callback) |
||||
<p>Remove the data at given path</p> |
||||
|
||||
**Kind**: static method of [<code>storageReactNative</code>](#module_storageReactNative) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| path | <code>string</code> | |
||||
| callback | <code>function</code> | |
||||
|
||||
<a name="module_storageReactNative.mkdirAsync"></a> |
||||
|
||||
### storageReactNative.mkdirAsync(dir, [options]) ⇒ <code>Promise.<(void\|string)></code> |
||||
<p>Shim for storage.mkdirAsync, nothing to do, no directories will be used on the browser</p> |
||||
|
||||
**Kind**: static method of [<code>storageReactNative</code>](#module_storageReactNative) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| dir | <code>string</code> | |
||||
| [options] | <code>object</code> | |
||||
|
||||
<a name="module_storageReactNative.mkdir"></a> |
||||
|
||||
### storageReactNative.mkdir(path, options, callback) |
||||
<p>Shim for storage.mkdir, nothing to do, no directories will be used on the browser</p> |
||||
|
||||
**Kind**: static method of [<code>storageReactNative</code>](#module_storageReactNative) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| path | <code>string</code> | |
||||
| options | <code>object</code> | |
||||
| callback | <code>function</code> | |
||||
|
||||
<a name="module_storageReactNative.ensureDatafileIntegrityAsync"></a> |
||||
|
||||
### storageReactNative.ensureDatafileIntegrityAsync(filename) ⇒ <code>Promise.<void></code> |
||||
<p>Ensure the datafile contains all the data, even if there was a crash during a full file write |
||||
Nothing to do, no data corruption possible in the browser</p> |
||||
|
||||
**Kind**: static method of [<code>storageReactNative</code>](#module_storageReactNative) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| filename | <code>string</code> | |
||||
|
||||
<a name="module_storageReactNative.ensureDatafileIntegrity"></a> |
||||
|
||||
### storageReactNative.ensureDatafileIntegrity(filename, callback) |
||||
<p>Ensure the datafile contains all the data, even if there was a crash during a full file write |
||||
Nothing to do, no data corruption possible in the browser</p> |
||||
|
||||
**Kind**: static method of [<code>storageReactNative</code>](#module_storageReactNative) |
||||
|
||||
| Param | Type | Description | |
||||
| --- | --- | --- | |
||||
| filename | <code>string</code> | | |
||||
| callback | [<code>NoParamCallback</code>](#NoParamCallback) | <p>signature: err</p> | |
||||
|
||||
<a name="module_storageReactNative.crashSafeWriteFileLinesAsync"></a> |
||||
|
||||
### storageReactNative.crashSafeWriteFileLinesAsync(filename, lines) ⇒ <code>Promise.<void></code> |
||||
<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) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| filename | <code>string</code> | |
||||
| lines | <code>Array.<string></code> | |
||||
|
||||
<a name="module_storageReactNative.crashSafeWriteFileLines"></a> |
||||
|
||||
### storageReactNative.crashSafeWriteFileLines(filename, lines, [callback]) |
||||
<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) |
||||
|
||||
| Param | Type | Description | |
||||
| --- | --- | --- | |
||||
| filename | <code>string</code> | | |
||||
| lines | <code>Array.<string></code> | | |
||||
| [callback] | [<code>NoParamCallback</code>](#NoParamCallback) | <p>Optional callback, signature: err</p> | |
||||
|
||||
<a name="module_storageReactNative..existsCallback"></a> |
||||
|
||||
### storageReactNative~existsCallback : <code>function</code> |
||||
**Kind**: inner typedef of [<code>storageReactNative</code>](#module_storageReactNative) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| exists | <code>boolean</code> | |
||||
|
@ -0,0 +1,67 @@ |
||||
<a name="module_utils"></a> |
||||
|
||||
## utils |
||||
<p>Utility functions for all environments. |
||||
This replaces the underscore dependency.</p> |
||||
|
||||
|
||||
* [utils](#module_utils) |
||||
* _static_ |
||||
* [.uniq(array, [iteratee])](#module_utils.uniq) ⇒ <code>Array</code> |
||||
* [.isDate(d)](#module_utils.isDate) ⇒ <code>boolean</code> |
||||
* [.isRegExp(re)](#module_utils.isRegExp) ⇒ <code>boolean</code> |
||||
* _inner_ |
||||
* [~isObject(arg)](#module_utils..isObject) ⇒ <code>boolean</code> |
||||
|
||||
<a name="module_utils.uniq"></a> |
||||
|
||||
### 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 |
||||
occurrence of each value is kept. If you want to compute unique items based on a transformation, pass an iteratee |
||||
function. |
||||
Heavily inspired by https://underscorejs.org/#uniq</p> |
||||
|
||||
**Kind**: static method of [<code>utils</code>](#module_utils) |
||||
|
||||
| Param | Type | Description | |
||||
| --- | --- | --- | |
||||
| array | <code>Array</code> | | |
||||
| [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> |
||||
|
||||
### utils.isDate(d) ⇒ <code>boolean</code> |
||||
<p>Returns true if d is a Date. |
||||
Heavily inspired by https://underscorejs.org/#isDate</p> |
||||
|
||||
**Kind**: static method of [<code>utils</code>](#module_utils) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| d | <code>\*</code> | |
||||
|
||||
<a name="module_utils.isRegExp"></a> |
||||
|
||||
### utils.isRegExp(re) ⇒ <code>boolean</code> |
||||
<p>Returns true if re is a RegExp. |
||||
Heavily inspired by https://underscorejs.org/#isRegExp</p> |
||||
|
||||
**Kind**: static method of [<code>utils</code>](#module_utils) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| re | <code>\*</code> | |
||||
|
||||
<a name="module_utils..isObject"></a> |
||||
|
||||
### 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 |
||||
and numbers are not. |
||||
Heavily inspired by https://underscorejs.org/#isObject</p> |
||||
|
||||
**Kind**: inner method of [<code>utils</code>](#module_utils) |
||||
|
||||
| Param | Type | |
||||
| --- | --- | |
||||
| arg | <code>\*</code> | |
||||
|
@ -0,0 +1,8 @@ |
||||
'use strict' |
||||
|
||||
module.exports = { |
||||
plugins: ['plugins/markdown'], |
||||
source: { |
||||
include: ['./lib', './browser-version/lib'] |
||||
} |
||||
} |
@ -0,0 +1,43 @@ |
||||
'use strict' |
||||
const jsdoc2md = require('jsdoc-to-markdown') |
||||
const fs = require('fs') |
||||
const path = require('path') |
||||
|
||||
const jsdocConf = './jsdoc.conf.js' |
||||
|
||||
/* output path */ |
||||
const outputDir = './docs' |
||||
|
||||
const getJsdocDataOptions = { |
||||
/* same inpout path as jsdoc */ |
||||
files: require(jsdocConf).source.include, |
||||
configure: './jsdoc.conf.js', |
||||
'no-cache': true |
||||
} |
||||
|
||||
fs.rmdirSync(outputDir, { recursive: true }) // clean docs dir
|
||||
fs.mkdirSync(outputDir) // make docs dir
|
||||
|
||||
/* get template data */ |
||||
const templateData = jsdoc2md.getTemplateDataSync(getJsdocDataOptions) |
||||
|
||||
/* reduce templateData to an array of class names */ |
||||
const classNames = templateData.filter(({kind}) => kind === 'class').map(({name}) => name) |
||||
|
||||
const moduleNames = templateData.filter(({kind}) => kind === 'module').map(({name}) => name) |
||||
|
||||
/* create a documentation file for each class */ |
||||
for (const className of classNames) { |
||||
const template = `{{#class name="${className}"}}{{>docs}}{{/class}}` |
||||
console.log(`rendering ${className}, template: ${template}`) |
||||
const output = jsdoc2md.renderSync({ data: templateData, template: template }) |
||||
fs.writeFileSync(path.resolve(outputDir, `${className}.md`), output) |
||||
} |
||||
|
||||
/* create a documentation file for each module */ |
||||
for (const moduleName of moduleNames) { |
||||
const template = `{{#module name="${moduleName}"}}{{>docs}}{{/module}}` |
||||
console.log(`rendering ${moduleName}, template: ${template}`) |
||||
const output = jsdoc2md.renderSync({ data: templateData, template: template }) |
||||
fs.writeFileSync(path.resolve(outputDir, `${moduleName}.md`), output) |
||||
} |
@ -0,0 +1,58 @@ |
||||
require('../jsdoc.conf') |
||||
|
||||
class Waterfall { |
||||
/** |
||||
* Instantiate a new Waterfall. |
||||
*/ |
||||
constructor () { |
||||
/** |
||||
* This is the internal Promise object which resolves when all the tasks of the `Waterfall` are done. |
||||
* |
||||
* It will change any time `this.waterfall` is called. |
||||
* |
||||
* Use {@link Waterfall#guardian} instead which retrievethe latest version of the guardian. |
||||
* @type {Promise} |
||||
* @protected |
||||
*/ |
||||
this._guardian = Promise.resolve() |
||||
} |
||||
|
||||
/** |
||||
* Getter that gives a Promise which resolves when all tasks up to when this function is called are done. |
||||
* |
||||
* This Promise cannot reject. |
||||
* @return {Promise} |
||||
*/ |
||||
get guardian () { |
||||
return this._guardian |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param {AsyncFunction} func |
||||
* @return {AsyncFunction} |
||||
*/ |
||||
waterfall (func) { |
||||
return (...args) => { |
||||
this._guardian = this.guardian.then(() => { |
||||
return func(...args) |
||||
.then(result => ({ error: false, result }), result => ({ error: true, result })) |
||||
}) |
||||
return this.guardian.then(({ error, result }) => { |
||||
if (error) return Promise.reject(result) |
||||
else return Promise.resolve(result) |
||||
}) |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Shorthand for chaining a promise to the Waterfall |
||||
* @param {Promise} promise |
||||
* @return {Promise} |
||||
*/ |
||||
chain (promise) { |
||||
return this.waterfall(() => promise)() |
||||
} |
||||
} |
||||
|
||||
module.exports = Waterfall |
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue