forked from public/fvtt-cthulhu-eternal
Initial import with skill sheet working
This commit is contained in:
57
node_modules/nedb-promises/.eslintrc.js
generated
vendored
Normal file
57
node_modules/nedb-promises/.eslintrc.js
generated
vendored
Normal file
@ -0,0 +1,57 @@
|
||||
module.exports = {
|
||||
env: {
|
||||
commonjs: true,
|
||||
es2021: true,
|
||||
node: true,
|
||||
jest: true,
|
||||
},
|
||||
extends: 'eslint:recommended',
|
||||
parserOptions: {
|
||||
ecmaVersion: 13,
|
||||
},
|
||||
rules: {
|
||||
'array-bracket-spacing': ['error', 'never'],
|
||||
'array-element-newline': ['error', 'consistent'],
|
||||
'arrow-spacing': ['error', { before: true, after: true }],
|
||||
'arrow-parens': ['error', 'always'],
|
||||
'block-spacing': ['error', 'always'],
|
||||
'brace-style': ['error', '1tbs', { allowSingleLine: true }],
|
||||
'comma-dangle': ['error', 'always-multiline'],
|
||||
'comma-spacing': ['error', { before: false, after: true }],
|
||||
'comma-style': ['error', 'last'],
|
||||
'computed-property-spacing': ['error', 'never'],
|
||||
'default-case-last': ['error'],
|
||||
'dot-location': ['error', 'property'],
|
||||
'func-call-spacing': ['error', 'never'],
|
||||
'function-call-argument-newline': ['error', 'consistent'],
|
||||
'eol-last': ['error', 'always'],
|
||||
'indent': ['error', 4],
|
||||
'key-spacing': ['error', { mode: 'strict' }],
|
||||
'keyword-spacing': ['error', { before: true, after: true }],
|
||||
'linebreak-style': ['error', 'unix'],
|
||||
'no-multi-spaces': 'error',
|
||||
'no-multiple-empty-lines': ['error', { max: 1, maxBOF: 0, maxEOF: 1 }],
|
||||
'no-nested-ternary': 'error',
|
||||
'no-new-object': 'error',
|
||||
'no-new-wrappers': 'error',
|
||||
'no-octal-escape': 'error',
|
||||
'no-return-await': 'error',
|
||||
'no-tabs': 'error',
|
||||
'no-throw-literal': 'error',
|
||||
'no-use-before-define': ['error', { functions: false, classes: true, variables: true }],
|
||||
'no-whitespace-before-property': 'error',
|
||||
'object-curly-spacing': ['error', 'always'],
|
||||
'operator-linebreak': ['error', 'before'],
|
||||
'padded-blocks': ['error', 'never'],
|
||||
'prefer-promise-reject-errors': 'error',
|
||||
'prefer-rest-params': 'error',
|
||||
'prefer-spread': 'error',
|
||||
'prefer-template': 'error',
|
||||
'quote-props': ['error', 'consistent-as-needed'],
|
||||
'quotes': ['error', 'single'],
|
||||
'rest-spread-spacing': ['error', 'never'],
|
||||
'semi': ['error', 'always'],
|
||||
'space-before-function-paren': ['error', { anonymous: 'never', named: 'never', asyncArrow: 'always' }],
|
||||
'template-curly-spacing': ['error', 'never'],
|
||||
},
|
||||
};
|
11
node_modules/nedb-promises/.github/stale.yml
generated
vendored
Normal file
11
node_modules/nedb-promises/.github/stale.yml
generated
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
daysUntilStale: 60
|
||||
daysUntilClose: 7
|
||||
exemptLabels:
|
||||
- pinned
|
||||
- security
|
||||
staleLabel: stale
|
||||
markComment: >
|
||||
This issue has been automatically marked as stale because it has not had
|
||||
recent activity. It will be closed if no further activity occurs. Thank you
|
||||
for your contributions.
|
||||
closeComment: false
|
82
node_modules/nedb-promises/CHANGELOG.md
generated
vendored
Normal file
82
node_modules/nedb-promises/CHANGELOG.md
generated
vendored
Normal file
@ -0,0 +1,82 @@
|
||||
# Changelog
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## 6.2.2
|
||||
### Fixed
|
||||
- Vulnerable dependencies.
|
||||
|
||||
## 6.2.1
|
||||
### Fixed
|
||||
- Updated TypeScript declarations to match the current API.
|
||||
|
||||
## 6.2.0
|
||||
### Added
|
||||
- `Datastore.removeOne` and `Datastore.removeMany` aliases.
|
||||
- MongoDB compatibility methods (`Datastore.insertOne`, `Datastore.insertMany`, `Datastore.updateOne`, `Datastore.updateMany`, `Datastore.deleteOne`, `Datastore.deleteMany`).
|
||||
|
||||
## 6.1.0
|
||||
### Updated
|
||||
- Code to use the async API instead of callbacks.
|
||||
|
||||
### Fixed
|
||||
- Vulnerable dependencies.
|
||||
|
||||
## 6.0.3
|
||||
### Fixed
|
||||
- Vulnerable dependencies.
|
||||
|
||||
## 6.0.2
|
||||
### Fixed
|
||||
- TypeScript declaration `update` result when `upsert` and `multi` is set to `true`.
|
||||
|
||||
## 6.0.1
|
||||
### Updated
|
||||
- Class description in the TypeScript declaration file.
|
||||
|
||||
## 6.0.0
|
||||
### Added
|
||||
- `Cursor.project` method.
|
||||
|
||||
### Changed
|
||||
- Major TypeScript declaration overhaul.
|
||||
|
||||
## 5.0.1 - 5.0.3
|
||||
### Fixed
|
||||
- Vulnerable dependencies.
|
||||
|
||||
### Updated
|
||||
- Code style.
|
||||
- Some documentation issues.
|
||||
|
||||
## 5.0.0
|
||||
### Updated
|
||||
- Switched from `nedb` to `@seald-io/nedb`, to solve vulnerability issues.
|
||||
|
||||
## 4.1.4 - 4.1.6
|
||||
### Fixed
|
||||
- Vulnerable dependencies.
|
||||
|
||||
## 4.1.1 - 4.1.3
|
||||
### Updated
|
||||
- TypeScript definition file.
|
||||
|
||||
## 4.1.0
|
||||
### Added
|
||||
- `compactionDone` event from nedb's `compaction.done`
|
||||
|
||||
## 4.0.4
|
||||
### Updated
|
||||
- Vulnerable dependencies.
|
||||
- Tabs to spaces in code.
|
||||
- TypeScript definition file.
|
||||
|
||||
## 4.0.1
|
||||
### Updated
|
||||
- Vulnerable dependencies.
|
||||
|
||||
## 4.0.0
|
||||
### Updated
|
||||
- The [findOne](https://github.com/bajankristof/nedb-promises/blob/master/docs.md#Datastore+findOne) and [count](https://github.com/bajankristof/nedb-promises/blob/master/docs.md#Datastore+count) `Datastore` methods now return a `Cursor` object instead of a `Promise`, allowing users to e.g.: find the most recently updated document, etc.
|
21
node_modules/nedb-promises/LICENSE
generated
vendored
Normal file
21
node_modules/nedb-promises/LICENSE
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2021 Kristóf Baján
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
99
node_modules/nedb-promises/README.md
generated
vendored
Normal file
99
node_modules/nedb-promises/README.md
generated
vendored
Normal file
@ -0,0 +1,99 @@
|
||||

|
||||
|
||||
A dead-simple promise wrapper for [nedb](https://github.com/louischatriot/nedb#readme).
|
||||
|
||||
Check out the [docs](https://github.com/bajankristof/nedb-promises/blob/master/docs.md).
|
||||
|
||||
##### IMPORTANT
|
||||
**As of `nedb-promises` `5.0.0` [nedb](https://github.com/louischatriot/nedb#readme) package has been replaced with a fork of the original package, [@seald-io/nedb](https://github.com/seald/nedb) to solve some vulnerability issues originating from `nedb`!**
|
||||
|
||||
```js
|
||||
const Datastore = require('nedb-promises')
|
||||
let datastore = Datastore.create('/path/to/db.db')
|
||||
|
||||
// #1
|
||||
datastore.find({ field: true })
|
||||
.then(...)
|
||||
.catch(...)
|
||||
|
||||
// #2
|
||||
datastore.find({ field: true })
|
||||
.exec(...)
|
||||
.then(...)
|
||||
.catch(...)
|
||||
|
||||
// #1 and #2 are equivalent
|
||||
|
||||
datastore.findOne({ field: true })
|
||||
.then(...)
|
||||
.catch(...)
|
||||
|
||||
datastore.insert({ doc: 'yourdoc' })
|
||||
.then(...)
|
||||
.catch(...)
|
||||
|
||||
// or in an async function
|
||||
async function findSorted(page, perPage = 10) {
|
||||
return await datastore.find(...)
|
||||
.sort(...)
|
||||
.limit(perPage)
|
||||
.skip(page * perPage)
|
||||
}
|
||||
```
|
||||
|
||||
### Installation
|
||||
```sh
|
||||
npm install --save nedb-promises
|
||||
```
|
||||
|
||||
### Usage
|
||||
Everything works as the original module, with a couple of exceptions:
|
||||
* There are no callbacks.
|
||||
* `loadDatabase` has been renamed to [`load`](https://github.com/bajankristof/nedb-promises/blob/master/docs.md#Datastore+load).
|
||||
* The cursor's `projection` method has been renamed to [`project`](https://github.com/bajankristof/nedb-promises/blob/master/docs.md#Cursor+project).
|
||||
* You should call `Datastore.create(...)` instead of `new Datastore(...)`. This way you can access the original [nedb](https://github.com/louischatriot/nedb#readme) properties, such as `datastore.persistence`.
|
||||
* As of v2.0.0 the module supports events 😎... Check out the [docs about events](https://github.com/bajankristof/nedb-promises/blob/master/docs.md#Datastore)!
|
||||
|
||||
Check out the [original docs](https://github.com/louischatriot/nedb#readme)!
|
||||
|
||||
#### load( )
|
||||
You don't need to call this as the module will automatically detect if the datastore has been loaded or not upon calling any other method.
|
||||
```js
|
||||
const Datastore = require('nedb-promises')
|
||||
let datastore = Datastore.create('/path/to/db.db')
|
||||
datastore.load(...)
|
||||
.then(...)
|
||||
.catch(...)
|
||||
```
|
||||
|
||||
#### find( [query], [projection] ), findOne( [query], [projection] ), count( [query] )
|
||||
These methods will return a Cursor object that works the same way it did before except when you call "exec" it takes no arguments and returns a Promise.
|
||||
The cool thing about this implementation of the Cursor is that it behaves like a Promise. Meaning that you can `await` it and you can call `.then()` on it.
|
||||
|
||||
```js
|
||||
const Datastore = require('nedb-promises')
|
||||
let datastore = Datastore.create('/path/to/db.db')
|
||||
|
||||
//outside Promise chain
|
||||
datastore.find(...)
|
||||
.then(...)
|
||||
.catch(...)
|
||||
|
||||
//insinde Promise chain
|
||||
datastore.insert(...)
|
||||
.then(() => {
|
||||
return datastore.find(...)
|
||||
})
|
||||
.then(
|
||||
// use the retrieved documents
|
||||
)
|
||||
|
||||
;(async () => {
|
||||
await datastore.find(...).sort(...).limit()
|
||||
})()
|
||||
```
|
||||
|
||||
#### other( ... )
|
||||
All the other methods will take the same arguments as they did before (except the callback) and will return a Promise.
|
||||
|
||||
Check out the [docs](https://github.com/bajankristof/nedb-promises/blob/master/docs.md).
|
673
node_modules/nedb-promises/docs.md
generated
vendored
Normal file
673
node_modules/nedb-promises/docs.md
generated
vendored
Normal file
@ -0,0 +1,673 @@
|
||||
## Classes
|
||||
|
||||
<dl>
|
||||
<dt><a href="#Cursor">Cursor</a></dt>
|
||||
<dd></dd>
|
||||
<dt><a href="#Datastore">Datastore</a></dt>
|
||||
<dd></dd>
|
||||
</dl>
|
||||
|
||||
<a name="Cursor"></a>
|
||||
|
||||
## Cursor
|
||||
**Kind**: global class
|
||||
|
||||
* [Cursor](#Cursor)
|
||||
* [.sort()](#Cursor+sort) ⇒ [<code>Cursor</code>](#Cursor)
|
||||
* [.skip()](#Cursor+skip) ⇒ [<code>Cursor</code>](#Cursor)
|
||||
* [.limit()](#Cursor+limit) ⇒ [<code>Cursor</code>](#Cursor)
|
||||
* [.project()](#Cursor+project) ⇒ [<code>Cursor</code>](#Cursor)
|
||||
* [.exec()](#Cursor+exec) ⇒ <code>Promise.<Array.<Object>></code>
|
||||
* [.then(fulfilled, [rejected])](#Cursor+then) ⇒ <code>Promise</code>
|
||||
* [.catch(rejected)](#Cursor+catch) ⇒ <code>Promise</code>
|
||||
|
||||
<a name="Cursor+sort"></a>
|
||||
|
||||
### cursor.sort() ⇒ [<code>Cursor</code>](#Cursor)
|
||||
Sort the queried documents.
|
||||
|
||||
See: https://github.com/louischatriot/nedb#sorting-and-paginating
|
||||
|
||||
**Kind**: instance method of [<code>Cursor</code>](#Cursor)
|
||||
<a name="Cursor+skip"></a>
|
||||
|
||||
### cursor.skip() ⇒ [<code>Cursor</code>](#Cursor)
|
||||
Skip some of the queried documents.
|
||||
|
||||
See: https://github.com/louischatriot/nedb#sorting-and-paginating
|
||||
|
||||
**Kind**: instance method of [<code>Cursor</code>](#Cursor)
|
||||
<a name="Cursor+limit"></a>
|
||||
|
||||
### cursor.limit() ⇒ [<code>Cursor</code>](#Cursor)
|
||||
Limit the queried documents.
|
||||
|
||||
See: https://github.com/louischatriot/nedb#sorting-and-paginating
|
||||
|
||||
**Kind**: instance method of [<code>Cursor</code>](#Cursor)
|
||||
<a name="Cursor+project"></a>
|
||||
|
||||
### cursor.project() ⇒ [<code>Cursor</code>](#Cursor)
|
||||
Set the document projection.
|
||||
|
||||
See: https://github.com/louischatriot/nedb#projections
|
||||
|
||||
**Kind**: instance method of [<code>Cursor</code>](#Cursor)
|
||||
<a name="Cursor+exec"></a>
|
||||
|
||||
### cursor.exec() ⇒ <code>Promise.<Array.<Object>></code>
|
||||
Execute the cursor.
|
||||
|
||||
Since the Cursor has a `then` and a `catch` method
|
||||
JavaScript identifies it as a thenable object
|
||||
thus you can await it in async functions.
|
||||
|
||||
**Kind**: instance method of [<code>Cursor</code>](#Cursor)
|
||||
**Example**
|
||||
```js
|
||||
// in an async function
|
||||
await datastore.find(...)
|
||||
.sort(...)
|
||||
.limit(...)
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
// the previous is the same as:
|
||||
await datastore.find(...)
|
||||
.sort(...)
|
||||
.limit(...)
|
||||
.exec()
|
||||
```
|
||||
<a name="Cursor+then"></a>
|
||||
|
||||
### cursor.then(fulfilled, [rejected]) ⇒ <code>Promise</code>
|
||||
Execute the cursor and set promise callbacks.
|
||||
|
||||
For more information visit:
|
||||
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then
|
||||
|
||||
**Kind**: instance method of [<code>Cursor</code>](#Cursor)
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Param</th><th>Type</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>fulfilled</td><td><code>function</code></td>
|
||||
</tr><tr>
|
||||
<td>[rejected]</td><td><code>function</code></td>
|
||||
</tr> </tbody>
|
||||
</table>
|
||||
|
||||
<a name="Cursor+catch"></a>
|
||||
|
||||
### cursor.catch(rejected) ⇒ <code>Promise</code>
|
||||
Execute the cursor and set promise error callback.
|
||||
|
||||
For more information visit:
|
||||
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch
|
||||
|
||||
**Kind**: instance method of [<code>Cursor</code>](#Cursor)
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Param</th><th>Type</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>rejected</td><td><code>function</code></td>
|
||||
</tr> </tbody>
|
||||
</table>
|
||||
|
||||
<a name="Datastore"></a>
|
||||
|
||||
## Datastore
|
||||
**Kind**: global class
|
||||
**Summary**: As of v2.0.0 the Datastore class extends node's built
|
||||
in EventEmitter class and implements each method as an event
|
||||
plus additional error events. It also inherits the `compaction.done`
|
||||
event from nedb but for consistency, in this library the event
|
||||
was renamed to `compactionDone`.
|
||||
|
||||
All event callbacks will be passed the same type of values,
|
||||
the first being the datastore, then the operation result (if there is any)
|
||||
and then the arguments of the called method. (Check out the first example!)
|
||||
|
||||
All events have a matching error event that goes by the name of `${method}Error`,
|
||||
for example `findError` or `loadError`. The callbacks of these events will receive
|
||||
the same parameters as the normal event handlers except that instead of the
|
||||
operation result there will be an operation error. (Check out the second example!)
|
||||
|
||||
A generic `__error__` event is also available. This event will be emitted at any of
|
||||
the above error events. The callbacks of this event will receive the same parameters
|
||||
as the specific error event handlers except that there will be one more parameter
|
||||
passed between the datastore and the error object, that being the name of the method
|
||||
that failed. (Check out the third example!)
|
||||
|
||||
* [Datastore](#Datastore)
|
||||
* [new Datastore([pathOrOptions])](#new_Datastore_new)
|
||||
* _instance_
|
||||
* [.load()](#Datastore+load) ⇒ <code>Promise.<undefined></code>
|
||||
* [.find([query], [projection])](#Datastore+find) ⇒ [<code>Cursor</code>](#Cursor)
|
||||
* [.findOne([query], [projection])](#Datastore+findOne) ⇒ [<code>Cursor</code>](#Cursor)
|
||||
* [.insert(docs)](#Datastore+insert) ⇒ <code>Promise.<(Object\|Array.<Object>)></code>
|
||||
* [.insertOne(doc)](#Datastore+insertOne) ⇒ <code>Promise.<Object></code>
|
||||
* [.insertMany(docs)](#Datastore+insertMany) ⇒ <code>Promise.<Array.<Object>></code>
|
||||
* [.update(query, update, [options])](#Datastore+update) ⇒ <code>Promise.<(number\|Object\|Array.<Object>)></code>
|
||||
* [.updateOne(query, update, [options])](#Datastore+updateOne) ⇒ <code>Promise.<(number\|Object)></code>
|
||||
* [.updateMany(query, update, [options])](#Datastore+updateMany) ⇒ <code>Promise.<(number\|Array.<Object>)></code>
|
||||
* [.remove([query], [options])](#Datastore+remove) ⇒ <code>Promise.<number></code>
|
||||
* [.removeOne([query], [options])](#Datastore+removeOne) ⇒ <code>Promise.<number></code>
|
||||
* [.removeMany([query], [options])](#Datastore+removeMany) ⇒ <code>Promise.<number></code>
|
||||
* [.deleteOne([query], [options])](#Datastore+deleteOne) ⇒ <code>Promise.<number></code>
|
||||
* [.deleteMany([query], [options])](#Datastore+deleteMany) ⇒ <code>Promise.<number></code>
|
||||
* [.count([query])](#Datastore+count) ⇒ [<code>Cursor</code>](#Cursor)
|
||||
* [.ensureIndex(options)](#Datastore+ensureIndex) ⇒ <code>Promise.<undefined></code>
|
||||
* [.removeIndex(field)](#Datastore+removeIndex) ⇒ <code>Promise.<undefined></code>
|
||||
* _static_
|
||||
* [.create([pathOrOptions])](#Datastore.create) ⇒ <code>Proxy.<static></code>
|
||||
|
||||
<a name="new_Datastore_new"></a>
|
||||
|
||||
### new Datastore([pathOrOptions])
|
||||
Datastore constructor...
|
||||
|
||||
You should use `Datastore.create(...)` instead
|
||||
of `new Datastore(...)`. With that you can access
|
||||
the original datastore's properties such as `datastore.persistence`.
|
||||
|
||||
Create a Datastore instance.
|
||||
|
||||
Note that the datastore will be created
|
||||
relative to `process.cwd()`
|
||||
(unless an absolute path was passed).
|
||||
|
||||
It's basically the same as the original:
|
||||
https://github.com/louischatriot/nedb#creatingloading-a-database
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Param</th><th>Type</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>[pathOrOptions]</td><td><code>string</code> | <code>Object</code></td>
|
||||
</tr> </tbody>
|
||||
</table>
|
||||
|
||||
**Example**
|
||||
```js
|
||||
let datastore = Datastore.create()
|
||||
datastore.on('update', (datastore, result, query, update, options) => {
|
||||
})
|
||||
datastore.on('load', (datastore) => {
|
||||
// this event doesn't have a result
|
||||
})
|
||||
datastore.on('ensureIndex', (datastore, options) => {
|
||||
// this event doesn't have a result
|
||||
// but it has the options argument which will be passed to the
|
||||
// event handlers
|
||||
})
|
||||
datastore.on('compactionDone', (datastore) => {
|
||||
// inherited from nedb's compaction.done event
|
||||
})
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
let datastore = Datastore.create()
|
||||
datastore.on('updateError', (datastore, error, query, update, options) => {
|
||||
})
|
||||
datastore.on('loadError', (datastore, error) => {
|
||||
})
|
||||
datastore.on('ensureIndexError', (datastore, error, options) => {
|
||||
})
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
let datastore = Datastore.create()
|
||||
datastore.on('__error__', (datastore, event, error, ...args) => {
|
||||
// for example
|
||||
// datastore, 'find', error, [{ foo: 'bar' }, {}]
|
||||
})
|
||||
```
|
||||
<a name="Datastore+load"></a>
|
||||
|
||||
### datastore.load() ⇒ <code>Promise.<undefined></code>
|
||||
Load the datastore.
|
||||
|
||||
Note that you don't necessarily have to call
|
||||
this method to load the datastore as it will
|
||||
automatically be called and awaited on any
|
||||
operation issued against the datastore
|
||||
(i.e.: `find`, `findOne`, etc.).
|
||||
|
||||
**Kind**: instance method of [<code>Datastore</code>](#Datastore)
|
||||
<a name="Datastore+find"></a>
|
||||
|
||||
### datastore.find([query], [projection]) ⇒ [<code>Cursor</code>](#Cursor)
|
||||
Find documents that match the specified `query`.
|
||||
|
||||
It's basically the same as the original:
|
||||
https://github.com/louischatriot/nedb#finding-documents
|
||||
|
||||
There are differences minor in how the cursor works though.
|
||||
|
||||
**Kind**: instance method of [<code>Datastore</code>](#Datastore)
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Param</th><th>Type</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>[query]</td><td><code>Object</code></td>
|
||||
</tr><tr>
|
||||
<td>[projection]</td><td><code>Object</code></td>
|
||||
</tr> </tbody>
|
||||
</table>
|
||||
|
||||
**Example**
|
||||
```js
|
||||
datastore.find({ ... }).sort({ ... }).exec().then(...)
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
datastore.find({ ... }).sort({ ... }).then(...)
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
// in an async function
|
||||
await datastore.find({ ... }).sort({ ... })
|
||||
```
|
||||
<a name="Datastore+findOne"></a>
|
||||
|
||||
### datastore.findOne([query], [projection]) ⇒ [<code>Cursor</code>](#Cursor)
|
||||
Find a document that matches the specified `query`.
|
||||
|
||||
It's basically the same as the original:
|
||||
https://github.com/louischatriot/nedb#finding-documents
|
||||
|
||||
**Kind**: instance method of [<code>Datastore</code>](#Datastore)
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Param</th><th>Type</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>[query]</td><td><code>Object</code></td>
|
||||
</tr><tr>
|
||||
<td>[projection]</td><td><code>Object</code></td>
|
||||
</tr> </tbody>
|
||||
</table>
|
||||
|
||||
**Example**
|
||||
```js
|
||||
datastore.findOne({ ... }).then(...)
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
// in an async function
|
||||
await datastore.findOne({ ... }).sort({ ... })
|
||||
```
|
||||
<a name="Datastore+insert"></a>
|
||||
|
||||
### datastore.insert(docs) ⇒ <code>Promise.<(Object\|Array.<Object>)></code>
|
||||
Insert a document or documents.
|
||||
|
||||
It's basically the same as the original:
|
||||
https://github.com/louischatriot/nedb#inserting-documents
|
||||
|
||||
**Kind**: instance method of [<code>Datastore</code>](#Datastore)
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Param</th><th>Type</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>docs</td><td><code>Object</code> | <code>Array.<Object></code></td>
|
||||
</tr> </tbody>
|
||||
</table>
|
||||
|
||||
<a name="Datastore+insertOne"></a>
|
||||
|
||||
### datastore.insertOne(doc) ⇒ <code>Promise.<Object></code>
|
||||
Insert a single document.
|
||||
|
||||
This is just an alias for `insert` with object destructuring
|
||||
to ensure a single document.
|
||||
|
||||
**Kind**: instance method of [<code>Datastore</code>](#Datastore)
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Param</th><th>Type</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>doc</td><td><code>Object</code></td>
|
||||
</tr> </tbody>
|
||||
</table>
|
||||
|
||||
<a name="Datastore+insertMany"></a>
|
||||
|
||||
### datastore.insertMany(docs) ⇒ <code>Promise.<Array.<Object>></code>
|
||||
Insert multiple documents.
|
||||
|
||||
This is just an alias for `insert` with array destructuring
|
||||
to ensure multiple documents.
|
||||
|
||||
**Kind**: instance method of [<code>Datastore</code>](#Datastore)
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Param</th><th>Type</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>docs</td><td><code>Array.<Object></code></td>
|
||||
</tr> </tbody>
|
||||
</table>
|
||||
|
||||
<a name="Datastore+update"></a>
|
||||
|
||||
### datastore.update(query, update, [options]) ⇒ <code>Promise.<(number\|Object\|Array.<Object>)></code>
|
||||
Update documents that match the specified `query`.
|
||||
|
||||
It's basically the same as the original:
|
||||
https://github.com/louischatriot/nedb#updating-documents
|
||||
|
||||
If you set `options.returnUpdatedDocs`,
|
||||
the returned promise will resolve with
|
||||
an object (if `options.multi` is `false`) or
|
||||
with an array of objects.
|
||||
|
||||
**Kind**: instance method of [<code>Datastore</code>](#Datastore)
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Param</th><th>Type</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>query</td><td><code>Object</code></td>
|
||||
</tr><tr>
|
||||
<td>update</td><td><code>Object</code></td>
|
||||
</tr><tr>
|
||||
<td>[options]</td><td><code>Object</code></td>
|
||||
</tr> </tbody>
|
||||
</table>
|
||||
|
||||
<a name="Datastore+updateOne"></a>
|
||||
|
||||
### datastore.updateOne(query, update, [options]) ⇒ <code>Promise.<(number\|Object)></code>
|
||||
Update a single document that matches the specified `query`.
|
||||
|
||||
This is just an alias for `update` with `options.multi` set to `false`.
|
||||
|
||||
**Kind**: instance method of [<code>Datastore</code>](#Datastore)
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Param</th><th>Type</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>query</td><td><code>Object</code></td>
|
||||
</tr><tr>
|
||||
<td>update</td><td><code>Object</code></td>
|
||||
</tr><tr>
|
||||
<td>[options]</td><td><code>Object</code></td>
|
||||
</tr> </tbody>
|
||||
</table>
|
||||
|
||||
<a name="Datastore+updateMany"></a>
|
||||
|
||||
### datastore.updateMany(query, update, [options]) ⇒ <code>Promise.<(number\|Array.<Object>)></code>
|
||||
Update multiple documents that match the specified `query`.
|
||||
|
||||
This is just an alias for `update` with `options.multi` set to `true`.
|
||||
|
||||
**Kind**: instance method of [<code>Datastore</code>](#Datastore)
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Param</th><th>Type</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>query</td><td><code>Object</code></td>
|
||||
</tr><tr>
|
||||
<td>update</td><td><code>Object</code></td>
|
||||
</tr><tr>
|
||||
<td>[options]</td><td><code>Object</code></td>
|
||||
</tr> </tbody>
|
||||
</table>
|
||||
|
||||
<a name="Datastore+remove"></a>
|
||||
|
||||
### datastore.remove([query], [options]) ⇒ <code>Promise.<number></code>
|
||||
Remove documents that match the specified `query`.
|
||||
|
||||
It's basically the same as the original:
|
||||
https://github.com/louischatriot/nedb#removing-documents
|
||||
|
||||
**Kind**: instance method of [<code>Datastore</code>](#Datastore)
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Param</th><th>Type</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>[query]</td><td><code>Object</code></td>
|
||||
</tr><tr>
|
||||
<td>[options]</td><td><code>Object</code></td>
|
||||
</tr> </tbody>
|
||||
</table>
|
||||
|
||||
<a name="Datastore+removeOne"></a>
|
||||
|
||||
### datastore.removeOne([query], [options]) ⇒ <code>Promise.<number></code>
|
||||
Remove the first document that matches the specified `query`.
|
||||
|
||||
This is just an alias for `remove` with `options.multi` set to `false`.
|
||||
|
||||
**Kind**: instance method of [<code>Datastore</code>](#Datastore)
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Param</th><th>Type</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>[query]</td><td><code>Object</code></td>
|
||||
</tr><tr>
|
||||
<td>[options]</td><td><code>Object</code></td>
|
||||
</tr> </tbody>
|
||||
</table>
|
||||
|
||||
<a name="Datastore+removeMany"></a>
|
||||
|
||||
### datastore.removeMany([query], [options]) ⇒ <code>Promise.<number></code>
|
||||
Remove all documents that match the specified `query`.
|
||||
|
||||
This is just an alias for `remove` with `options.multi` set to `true`.
|
||||
|
||||
**Kind**: instance method of [<code>Datastore</code>](#Datastore)
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Param</th><th>Type</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>[query]</td><td><code>Object</code></td>
|
||||
</tr><tr>
|
||||
<td>[options]</td><td><code>Object</code></td>
|
||||
</tr> </tbody>
|
||||
</table>
|
||||
|
||||
<a name="Datastore+deleteOne"></a>
|
||||
|
||||
### datastore.deleteOne([query], [options]) ⇒ <code>Promise.<number></code>
|
||||
Remove the first document that matches the specified `query`.
|
||||
|
||||
This is just an alias for `removeOne`.
|
||||
|
||||
**Kind**: instance method of [<code>Datastore</code>](#Datastore)
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Param</th><th>Type</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>[query]</td><td><code>Object</code></td>
|
||||
</tr><tr>
|
||||
<td>[options]</td><td><code>Object</code></td>
|
||||
</tr> </tbody>
|
||||
</table>
|
||||
|
||||
<a name="Datastore+deleteMany"></a>
|
||||
|
||||
### datastore.deleteMany([query], [options]) ⇒ <code>Promise.<number></code>
|
||||
Remove all documents that match the specified `query`.
|
||||
|
||||
This is just an alias for `removeMany`.
|
||||
|
||||
**Kind**: instance method of [<code>Datastore</code>](#Datastore)
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Param</th><th>Type</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>[query]</td><td><code>Object</code></td>
|
||||
</tr><tr>
|
||||
<td>[options]</td><td><code>Object</code></td>
|
||||
</tr> </tbody>
|
||||
</table>
|
||||
|
||||
<a name="Datastore+count"></a>
|
||||
|
||||
### datastore.count([query]) ⇒ [<code>Cursor</code>](#Cursor)
|
||||
Count documents matching the specified `query`.
|
||||
|
||||
It's basically the same as the original:
|
||||
https://github.com/louischatriot/nedb#counting-documents
|
||||
|
||||
**Kind**: instance method of [<code>Datastore</code>](#Datastore)
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Param</th><th>Type</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>[query]</td><td><code>Object</code></td>
|
||||
</tr> </tbody>
|
||||
</table>
|
||||
|
||||
**Example**
|
||||
```js
|
||||
datastore.count({ ... }).limit(...).then(...)
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
// in an async function
|
||||
await datastore.count({ ... })
|
||||
// or
|
||||
await datastore.count({ ... }).sort(...).limit(...)
|
||||
```
|
||||
<a name="Datastore+ensureIndex"></a>
|
||||
|
||||
### datastore.ensureIndex(options) ⇒ <code>Promise.<undefined></code>
|
||||
https://github.com/louischatriot/nedb#indexing
|
||||
|
||||
**Kind**: instance method of [<code>Datastore</code>](#Datastore)
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Param</th><th>Type</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>options</td><td><code>Object</code></td>
|
||||
</tr> </tbody>
|
||||
</table>
|
||||
|
||||
<a name="Datastore+removeIndex"></a>
|
||||
|
||||
### datastore.removeIndex(field) ⇒ <code>Promise.<undefined></code>
|
||||
https://github.com/louischatriot/nedb#indexing
|
||||
|
||||
**Kind**: instance method of [<code>Datastore</code>](#Datastore)
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Param</th><th>Type</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>field</td><td><code>string</code></td>
|
||||
</tr> </tbody>
|
||||
</table>
|
||||
|
||||
<a name="Datastore.create"></a>
|
||||
|
||||
### Datastore.create([pathOrOptions]) ⇒ <code>Proxy.<static></code>
|
||||
Create a database instance.
|
||||
|
||||
Use this over `new Datastore(...)` to access
|
||||
original nedb datastore properties, such as
|
||||
`datastore.persistence`.
|
||||
|
||||
Note that this method only creates the `Datastore`
|
||||
class instance, not the datastore file itself.
|
||||
The file will only be created once an operation
|
||||
is issued against the datastore or if you call
|
||||
the `load` instance method explicitly.
|
||||
|
||||
The path (if specified) will be relative to `process.cwd()`
|
||||
(unless an absolute path was passed).
|
||||
|
||||
For more information visit:
|
||||
https://github.com/louischatriot/nedb#creatingloading-a-database
|
||||
|
||||
**Kind**: static method of [<code>Datastore</code>](#Datastore)
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Param</th><th>Type</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>[pathOrOptions]</td><td><code>string</code> | <code>Object</code></td>
|
||||
</tr> </tbody>
|
||||
</table>
|
||||
|
720
node_modules/nedb-promises/index.d.ts
generated
vendored
Normal file
720
node_modules/nedb-promises/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,720 @@
|
||||
import { EventEmitter } from 'events';
|
||||
|
||||
declare namespace NeDB {
|
||||
type Query = {
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
type Update = {
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
type Projection<TSchema> = {
|
||||
[p in keyof TSchema]?: number;
|
||||
}
|
||||
|
||||
interface Persistence {
|
||||
/**
|
||||
* Under the hood, NeDB's persistence uses an append-only format, meaning
|
||||
* that all updates and deletes actually result in lines added at the end
|
||||
* of the datafile, for performance reasons. The database is automatically
|
||||
* compacted (i.e. put back in the one-line-per-document format) every
|
||||
* time you load each database within your application.
|
||||
*
|
||||
* You can manually call the compaction function with
|
||||
* `datastore.persistence.compactDatafile` which takes no argument. It
|
||||
* queues a compaction of the datafile in the executor, to be executed
|
||||
* sequentially after all pending operations. The datastore will fire a
|
||||
* compaction.done event once compaction is finished.
|
||||
*/
|
||||
compactDatafile(): void;
|
||||
|
||||
/**
|
||||
* Set automatic compaction at a regular `interval` in milliseconds (a
|
||||
* minimum of 5s is enforced).
|
||||
*/
|
||||
setAutocompactionInterval(interval: number): void;
|
||||
|
||||
/**
|
||||
* Stop automatic compaction with
|
||||
* `datastore.persistence.stopAutocompaction()`.
|
||||
*/
|
||||
stopAutocompaction(): void;
|
||||
}
|
||||
|
||||
interface AbstractCursor<TSchema> {
|
||||
/**
|
||||
* Sort the queried documents.
|
||||
*
|
||||
* See: https://github.com/louischatriot/nedb#sorting-and-paginating
|
||||
*/
|
||||
sort(query: any): this;
|
||||
|
||||
/**
|
||||
* Skip some of the queried documents.
|
||||
*
|
||||
* See: https://github.com/louischatriot/nedb#sorting-and-paginating
|
||||
*/
|
||||
skip(n: number): this;
|
||||
|
||||
/**
|
||||
* Limit the queried documents.
|
||||
*
|
||||
* See: https://github.com/louischatriot/nedb#sorting-and-paginating
|
||||
*/
|
||||
limit(n: number): this;
|
||||
|
||||
/**
|
||||
* Set the document projection.
|
||||
*
|
||||
* See: https://github.com/louischatriot/nedb#projections
|
||||
*/
|
||||
project(projection: Projection<TSchema>): this;
|
||||
}
|
||||
|
||||
interface FindCursor<TSchema> extends AbstractCursor<TSchema>, Promise<TSchema[]> {
|
||||
/**
|
||||
* Execute the cursor.
|
||||
*
|
||||
* Since the Cursor has a `then` and a `catch` method
|
||||
* JavaScript identifies it as a thenable object
|
||||
* thus you can await it in async functions.
|
||||
*
|
||||
* @example
|
||||
* // in an async function
|
||||
* await datastore.find(...)
|
||||
* .sort(...)
|
||||
* .limit(...)
|
||||
*
|
||||
* @example
|
||||
* // the previous is the same as:
|
||||
* await datastore.find(...)
|
||||
* .sort(...)
|
||||
* .limit(...)
|
||||
* .exec()
|
||||
*/
|
||||
exec(): Promise<TSchema[]>;
|
||||
}
|
||||
|
||||
interface FindOneCursor<TSchema> extends AbstractCursor<TSchema>, Promise<TSchema | null> {
|
||||
/**
|
||||
* Execute the cursor.
|
||||
*
|
||||
* Since the Cursor has a `then` and a `catch` method
|
||||
* JavaScript identifies it as a thenable object
|
||||
* thus you can await it in async functions.
|
||||
*
|
||||
* @example
|
||||
* // in an async function
|
||||
* await datastore.find(...)
|
||||
* .sort(...)
|
||||
* .limit(...)
|
||||
*
|
||||
* @example
|
||||
* // the previous is the same as:
|
||||
* await datastore.find(...)
|
||||
* .sort(...)
|
||||
* .limit(...)
|
||||
* .exec()
|
||||
*/
|
||||
exec(): Promise<TSchema | null>;
|
||||
}
|
||||
|
||||
type DatastoreOptions = {
|
||||
/**
|
||||
* 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 `~` which is used in the temporary files NeDB uses to perform
|
||||
* crash-safe writes.
|
||||
*/
|
||||
filename?: string;
|
||||
|
||||
/**
|
||||
* As the name implies...
|
||||
*
|
||||
* Defaults to `false`.
|
||||
*/
|
||||
inMemoryOnly?: boolean;
|
||||
|
||||
/**
|
||||
* Timestamp the insertion and last update of all documents, with the
|
||||
* fields createdAt and updatedAt. User-specified values override
|
||||
* automatic generation, usually useful for testing.
|
||||
*
|
||||
* Defaults to `false`.
|
||||
*/
|
||||
timestampData?: boolean;
|
||||
|
||||
/**
|
||||
* If used, the database will automatically be loaded from the datafile
|
||||
* upon creation (you don't need to call `load`). Any command issued
|
||||
* before load is finished is buffered and will be executed when load is
|
||||
* done.
|
||||
*
|
||||
* Defaults to `false`.
|
||||
*/
|
||||
autoload?: boolean;
|
||||
|
||||
/**
|
||||
* If you use autoloading, this is the handler called after `load`. It
|
||||
* takes one error argument. If you use autoloading without specifying
|
||||
* this handler, and an error happens during load, an error will be
|
||||
* thrown.
|
||||
*/
|
||||
onload?(error: Error): any;
|
||||
|
||||
/**
|
||||
* 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,
|
||||
* which must absolutely not contain a `\n` character (or data will be
|
||||
* lost).
|
||||
*/
|
||||
afterSerialization?(line: string): string;
|
||||
|
||||
/**
|
||||
* Inverse of afterSerialization. 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.
|
||||
*/
|
||||
beforeDeserialization?(line: string): string;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
corruptAlertThreshold?: number;
|
||||
|
||||
/**
|
||||
* Compares strings `a` and `b` and returns -1, 0 or 1. If specified, it
|
||||
* overrides default string comparison which is not well adapted to non-US
|
||||
* characters in particular accented letters. Native `localCompare` will
|
||||
* most of the time be the right choice.
|
||||
*/
|
||||
compareStrings?(a: string, b: string): number;
|
||||
|
||||
/**
|
||||
* If you are using NeDB from whithin a Node Webkit app, specify its name
|
||||
* (the same one you use in the package.json) in this field and the
|
||||
* filename 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
|
||||
* `require('nw.gui').App.dataPath` in Node Webkit to get the path to the
|
||||
* data directory for your application, you should not use this option
|
||||
* anymore and it will be removed.
|
||||
* @deprecated
|
||||
*/
|
||||
nodeWebkitAppName?: string;
|
||||
}
|
||||
|
||||
type UpdateOptions = {
|
||||
/**
|
||||
* Allows the modification of several documents if set to `true`.
|
||||
*
|
||||
* Defaults to `false`.
|
||||
*/
|
||||
multi?: boolean;
|
||||
|
||||
/**
|
||||
* If you want to insert a new document corresponding to the `update` rules
|
||||
* if your `query` doesn't match anything. If your `update` is a simple object
|
||||
* with no modifiers, it is the inserted document. In the other case, the
|
||||
* `query` is stripped from all operator recursively, and the `update` is
|
||||
* applied to it.
|
||||
*
|
||||
* Defaults to `false`.
|
||||
*/
|
||||
upsert?: boolean;
|
||||
|
||||
/**
|
||||
* (Not MongoDB-compatible) If set to true and update is not an upsert,
|
||||
* will return the document or the array of documents (when multi is set
|
||||
* to `true`) matched by the find query and updated. Updated documents
|
||||
* will be returned even if the update did not actually modify them.
|
||||
*
|
||||
* Defaults to `false`.
|
||||
*/
|
||||
returnUpdatedDocs?: boolean;
|
||||
}
|
||||
|
||||
type RemoveOptions = {
|
||||
/**
|
||||
* Allows the removal of multiple documents if set to true.
|
||||
*
|
||||
* Defaults to `false`.
|
||||
*/
|
||||
multi?: boolean;
|
||||
}
|
||||
|
||||
type IndexOptions = {
|
||||
/**
|
||||
* The name of the field to index. Use the dot notation to index a field
|
||||
* in a nested document.
|
||||
*/
|
||||
fieldName: string;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
unique?: boolean;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
sparse?: boolean;
|
||||
|
||||
/**
|
||||
* If set, the created index is a TTL (time to live) index, that will
|
||||
* automatically remove documents when the system date becomes larger than
|
||||
* the date on the indexed field plus `expireAfterSeconds`. Documents where
|
||||
* the indexed field is not specified or not a Date object are ignored.
|
||||
*/
|
||||
expireAfterSeconds?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* @summary
|
||||
* As of v2.0.0 the Datastore class extends node's built
|
||||
* in EventEmitter class and implements each method as an event
|
||||
* plus additional error events. It also inherits the `compaction.done`
|
||||
* event from nedb but for consistency, in this library the event
|
||||
* was renamed to `compactionDone`.
|
||||
*
|
||||
* All event callbacks will be passed the same type of values,
|
||||
* the first being the datastore, then the operation result (if there is any)
|
||||
* and then the arguments of the called method. (Check out the first example!)
|
||||
*
|
||||
* All events have a matching error event that goes by the name of `${method}Error`,
|
||||
* for example `findError` or `loadError`. The callbacks of these events will receive
|
||||
* the same parameters as the normal event handlers except that instead of the
|
||||
* operation result there will be an operation error. (Check out the second example!)
|
||||
*
|
||||
* A generic `__error__` event is also available. This event will be emitted at any of
|
||||
* the above error events. The callbacks of this event will receive the same parameters
|
||||
* as the specific error event handlers except that there will be one more parameter
|
||||
* passed between the datastore and the error object, that being the name of the method
|
||||
* that failed. (Check out the third example!)
|
||||
*
|
||||
* @example
|
||||
* let datastore = Datastore.create()
|
||||
* datastore.on('update', (datastore, result, query, update, options) => {
|
||||
* })
|
||||
* datastore.on('load', (datastore) => {
|
||||
* // this event doesn't have a result
|
||||
* })
|
||||
* datastore.on('ensureIndex', (datastore, options) => {
|
||||
* // this event doesn't have a result
|
||||
* // but it has the options argument which will be passed to the
|
||||
* // event handlers
|
||||
* })
|
||||
* datastore.on('compactionDone', (datastore) => {
|
||||
* // inherited from nedb's compaction.done event
|
||||
* })
|
||||
*
|
||||
* @example
|
||||
* let datastore = Datastore.create()
|
||||
* datastore.on('updateError', (datastore, error, query, update, options) => {
|
||||
* })
|
||||
* datastore.on('loadError', (datastore, error) => {
|
||||
* })
|
||||
* datastore.on('ensureIndexError', (datastore, error, options) => {
|
||||
* })
|
||||
*
|
||||
* @example
|
||||
* let datastore = Datastore.create()
|
||||
* datastore.on('__error__', (datastore, event, error, ...args) => {
|
||||
* // for example
|
||||
* // datastore, 'find', error, [{ foo: 'bar' }, {}]
|
||||
* })
|
||||
*
|
||||
* @class
|
||||
*/
|
||||
class Datastore<TDocument> extends EventEmitter {
|
||||
persistence: Persistence;
|
||||
|
||||
private constructor();
|
||||
|
||||
/**
|
||||
* Create a database instance.
|
||||
*
|
||||
* Use this over `new Datastore(...)` to access
|
||||
* original nedb datastore properties, such as
|
||||
* `datastore.persistence`.
|
||||
*
|
||||
* Note that this method only creates the `Datastore`
|
||||
* class instance, not the datastore file itself.
|
||||
* The file will only be created once an operation
|
||||
* is issued against the datastore or if you call
|
||||
* the `load` instance method explicitly.
|
||||
*
|
||||
* The path (if specified) will be relative to `process.cwd()`
|
||||
* (unless an absolute path was passed).
|
||||
*
|
||||
* For more information visit:
|
||||
* https://github.com/louischatriot/nedb#creatingloading-a-database
|
||||
*/
|
||||
static create(
|
||||
pathOrOptions: DatastoreOptions & { timestampData: true },
|
||||
): Datastore<{ _id: string, createdAt: Date, updatedAt: Date }>;
|
||||
/**
|
||||
* Create a database instance.
|
||||
*
|
||||
* Use this over `new Datastore(...)` to access
|
||||
* original nedb datastore properties, such as
|
||||
* `datastore.persistence`.
|
||||
*
|
||||
* Note that this method only creates the `Datastore`
|
||||
* class instance, not the datastore file itself.
|
||||
* The file will only be created once an operation
|
||||
* is issued against the datastore or if you call
|
||||
* the `load` instance method explicitly.
|
||||
*
|
||||
* The path (if specified) will be relative to `process.cwd()`
|
||||
* (unless an absolute path was passed).
|
||||
*
|
||||
* For more information visit:
|
||||
* https://github.com/louischatriot/nedb#creatingloading-a-database
|
||||
*/
|
||||
static create(
|
||||
pathOrOptions?: string | DatastoreOptions,
|
||||
): Datastore<{ _id: string }>;
|
||||
|
||||
/**
|
||||
* Load the datastore.
|
||||
*
|
||||
* Note that you don't necessarily have to call
|
||||
* this method to load the datastore as it will
|
||||
* automatically be called and awaited on any
|
||||
* operation issued against the datastore
|
||||
* (i.e.: `find`, `findOne`, etc.).
|
||||
*/
|
||||
load(): Promise<void>;
|
||||
|
||||
/**
|
||||
* Find documents that match the specified `query`.
|
||||
*
|
||||
* It's basically the same as the original:
|
||||
* https://github.com/louischatriot/nedb#finding-documents
|
||||
*
|
||||
* There are differences minor in how the cursor works though.
|
||||
*
|
||||
* @example
|
||||
* datastore.find({ ... }).sort({ ... }).exec().then(...)
|
||||
*
|
||||
* @example
|
||||
* datastore.find({ ... }).sort({ ... }).then(...)
|
||||
*
|
||||
* @example
|
||||
* // in an async function
|
||||
* await datastore.find({ ... }).sort({ ... })
|
||||
*/
|
||||
find<TSchema>(
|
||||
query: Query,
|
||||
projection?: Projection<TDocument & TSchema>,
|
||||
): FindCursor<TDocument & TSchema>;
|
||||
|
||||
/**
|
||||
* Find a document that matches the specified `query`.
|
||||
*
|
||||
* It's basically the same as the original:
|
||||
* https://github.com/louischatriot/nedb#finding-documents
|
||||
*
|
||||
* @example
|
||||
* datastore.findOne({ ... }).then(...)
|
||||
*
|
||||
* @example
|
||||
* // in an async function
|
||||
* await datastore.findOne({ ... }).sort({ ... })
|
||||
*/
|
||||
findOne<TSchema>(
|
||||
query: Query,
|
||||
projection?: Projection<TDocument & TSchema>,
|
||||
): FindOneCursor<TDocument & TSchema>;
|
||||
|
||||
/**
|
||||
* Insert a document.
|
||||
*
|
||||
* It's basically the same as the original:
|
||||
* https://github.com/louischatriot/nedb#inserting-documents
|
||||
*/
|
||||
insert<TSchema>(
|
||||
docs: TSchema,
|
||||
): Promise<TDocument & TSchema>;
|
||||
/**
|
||||
* Insert an array of documents.
|
||||
*
|
||||
* It's basically the same as the original:
|
||||
* https://github.com/louischatriot/nedb#inserting-documents
|
||||
*/
|
||||
insert<TSchema>(
|
||||
docs: TSchema[],
|
||||
): Promise<(TDocument & TSchema)[]>;
|
||||
|
||||
/**
|
||||
* Insert a single document.
|
||||
*
|
||||
* This is just an alias for `insert` with object destructuring
|
||||
* to ensure a single document.
|
||||
*/
|
||||
insertOne<TSchema>(
|
||||
doc: TSchema,
|
||||
): Promise<TDocument & TSchema>;
|
||||
|
||||
/**
|
||||
* Insert multiple documents.
|
||||
*
|
||||
* This is just an alias for `insert` with array destructuring
|
||||
* to ensure multiple documents.
|
||||
*/
|
||||
insertMany<TSchema>(
|
||||
docs: TSchema[],
|
||||
): Promise<(TDocument & TSchema)[]>;
|
||||
|
||||
/**
|
||||
* Update documents that match the specified `query`.
|
||||
*
|
||||
* It's basically the same as the original:
|
||||
* https://github.com/louischatriot/nedb#updating-documents
|
||||
*
|
||||
* If you set `options.returnUpdatedDocs`,
|
||||
* the returned promise will resolve with
|
||||
* an object (if `options.multi` is `false`) or
|
||||
* with an array of objects.
|
||||
*/
|
||||
update<TSchema>(
|
||||
query: Query,
|
||||
update: Update,
|
||||
options: UpdateOptions & { returnUpdatedDocs: true; upsert: true; multi?: false },
|
||||
): Promise<TDocument & TSchema>;
|
||||
/**
|
||||
* Update documents that match the specified `query`.
|
||||
*
|
||||
* It's basically the same as the original:
|
||||
* https://github.com/louischatriot/nedb#updating-documents
|
||||
*
|
||||
* If you set `options.returnUpdatedDocs`,
|
||||
* the returned promise will resolve with
|
||||
* an object (if `options.multi` is `false`) or
|
||||
* with an array of objects.
|
||||
*/
|
||||
update<TSchema>(
|
||||
query: Query,
|
||||
update: Update,
|
||||
options: UpdateOptions & { returnUpdatedDocs: true; upsert: true; multi: true },
|
||||
): Promise<(TDocument & TSchema)[] | (TDocument & TSchema)>;
|
||||
/**
|
||||
* Update documents that match the specified `query`.
|
||||
*
|
||||
* It's basically the same as the original:
|
||||
* https://github.com/louischatriot/nedb#updating-documents
|
||||
*
|
||||
* If you set `options.returnUpdatedDocs`,
|
||||
* the returned promise will resolve with
|
||||
* an object (if `options.multi` is `false`) or
|
||||
* with an array of objects.
|
||||
*/
|
||||
update<TSchema>(
|
||||
query: Query,
|
||||
update: Update,
|
||||
options: UpdateOptions & { returnUpdatedDocs: true; upsert?: false; multi?: false },
|
||||
): Promise<(TDocument & TSchema) | null>;
|
||||
/**
|
||||
* Update documents that match the specified `query`.
|
||||
*
|
||||
* It's basically the same as the original:
|
||||
* https://github.com/louischatriot/nedb#updating-documents
|
||||
*
|
||||
* If you set `options.returnUpdatedDocs`,
|
||||
* the returned promise will resolve with
|
||||
* an object (if `options.multi` is `false`) or
|
||||
* with an array of objects.
|
||||
*/
|
||||
update<TSchema>(
|
||||
query: Query,
|
||||
update: Update,
|
||||
options: UpdateOptions & { returnUpdatedDocs: true; multi: true },
|
||||
): Promise<(TDocument & TSchema)[]>;
|
||||
/**
|
||||
* Update documents that match the specified `query`.
|
||||
*
|
||||
* It's basically the same as the original:
|
||||
* https://github.com/louischatriot/nedb#updating-documents
|
||||
*
|
||||
* If you set `options.returnUpdatedDocs`,
|
||||
* the returned promise will resolve with
|
||||
* an object (if `options.multi` is `false`) or
|
||||
* with an array of objects.
|
||||
*/
|
||||
update<TSchema>(
|
||||
query: Query,
|
||||
update: Update,
|
||||
options?: UpdateOptions,
|
||||
): Promise<number>;
|
||||
/**
|
||||
* Update documents that match the specified `query`.
|
||||
*
|
||||
* It's basically the same as the original:
|
||||
* https://github.com/louischatriot/nedb#updating-documents
|
||||
*
|
||||
* If you set `options.returnUpdatedDocs`,
|
||||
* the returned promise will resolve with
|
||||
* an object (if `options.multi` is `false`) or
|
||||
* with an array of objects.
|
||||
*/
|
||||
update(
|
||||
query: Query,
|
||||
update: Update,
|
||||
options?: UpdateOptions,
|
||||
): Promise<number>;
|
||||
|
||||
/**
|
||||
* Update a single document that matches the specified `query`.
|
||||
*
|
||||
* This is just an alias for `update` with `options.multi` set to `false`.
|
||||
*/
|
||||
updateOne<TSchema>(
|
||||
query: Query,
|
||||
update: Update,
|
||||
options: UpdateOptions & { returnUpdatedDocs: true; upsert: true },
|
||||
): Promise<TDocument & TSchema>;
|
||||
/**
|
||||
* Update a single document that matches the specified `query`.
|
||||
*
|
||||
* This is just an alias for `update` with `options.multi` set to `false`.
|
||||
*/
|
||||
updateOne<TSchema>(
|
||||
query: Query,
|
||||
update: Update,
|
||||
options: UpdateOptions & { returnUpdatedDocs: true; upsert?: false },
|
||||
): Promise<(TDocument & TSchema) | null>;
|
||||
/**
|
||||
* Update a single document that matches the specified `query`.
|
||||
*
|
||||
* This is just an alias for `update` with `options.multi` set to `false`.
|
||||
*/
|
||||
updateOne<TSchema>(
|
||||
query: Query,
|
||||
update: Update,
|
||||
options?: UpdateOptions,
|
||||
): Promise<number>;
|
||||
/**
|
||||
* Update a single document that matches the specified `query`.
|
||||
*
|
||||
* This is just an alias for `update` with `options.multi` set to `false`.
|
||||
*/
|
||||
updateOne(
|
||||
query: Query,
|
||||
update: Update,
|
||||
options?: UpdateOptions,
|
||||
): Promise<number>;
|
||||
|
||||
/**
|
||||
* Update multiple documents that match the specified `query`.
|
||||
*
|
||||
* This is just an alias for `update` with `options.multi` set to `true`.
|
||||
*/
|
||||
updateMany<TSchema>(
|
||||
query: Query,
|
||||
update: Update,
|
||||
options: UpdateOptions & { returnUpdatedDocs: true; upsert: true },
|
||||
): Promise<(TDocument & TSchema)[] | (TDocument & TSchema)>;
|
||||
/**
|
||||
* Update multiple documents that match the specified `query`.
|
||||
*
|
||||
* This is just an alias for `update` with `options.multi` set to `true`.
|
||||
*/
|
||||
updateMany<TSchema>(
|
||||
query: Query,
|
||||
update: Update,
|
||||
options: UpdateOptions & { returnUpdatedDocs: true },
|
||||
): Promise<(TDocument & TSchema)[]>;
|
||||
/**
|
||||
* Update multiple documents that match the specified `query`.
|
||||
*
|
||||
* This is just an alias for `update` with `options.multi` set to `true`.
|
||||
*/
|
||||
updateMany<TSchema>(
|
||||
query: Query,
|
||||
update: Update,
|
||||
options?: UpdateOptions,
|
||||
): Promise<number>;
|
||||
/**
|
||||
* Update multiple documents that match the specified `query`.
|
||||
*
|
||||
* This is just an alias for `update` with `options.multi` set to `true`.
|
||||
*/
|
||||
updateMany(
|
||||
query: Query,
|
||||
update: Update,
|
||||
options?: UpdateOptions,
|
||||
): Promise<number>;
|
||||
|
||||
/**
|
||||
* Remove documents that match the specified `query`.
|
||||
*
|
||||
* It's basically the same as the original:
|
||||
* https://github.com/louischatriot/nedb#removing-documents
|
||||
*/
|
||||
remove(query: Query, options: RemoveOptions): Promise<number>;
|
||||
|
||||
/**
|
||||
* Remove the first document that matches the specified `query`.
|
||||
*
|
||||
* This is just an alias for `remove` with `options.multi` set to `false`.
|
||||
*/
|
||||
removeOne(query: Query, options: RemoveOptions): Promise<number>;
|
||||
|
||||
/**
|
||||
* Remove all documents that match the specified `query`.
|
||||
*
|
||||
* This is just an alias for `remove` with `options.multi` set to `true`.
|
||||
*/
|
||||
removeMany(query: Query, options: RemoveOptions): Promise<number>;
|
||||
|
||||
/**
|
||||
* Remove the first document that matches the specified `query`.
|
||||
*
|
||||
* This is just an alias for `removeOne`.
|
||||
*/
|
||||
deleteOne(query: Query, options: RemoveOptions): Promise<number>;
|
||||
|
||||
/**
|
||||
* Remove all documents that match the specified `query`.
|
||||
*
|
||||
* This is just an alias for `removeMany`.
|
||||
*/
|
||||
deleteMany(query: Query, options: RemoveOptions): Promise<number>;
|
||||
|
||||
/**
|
||||
* Count documents matching the specified `query`.
|
||||
*/
|
||||
count(query: Query): Promise<number>;
|
||||
|
||||
/**
|
||||
* Ensure an index is kept for this field. Same parameters as lib/indexes
|
||||
* For now this function is synchronous, we need to test how much time it
|
||||
* takes We use an async API for consistency with the rest of the code.
|
||||
*/
|
||||
ensureIndex(options: IndexOptions): Promise<void>;
|
||||
|
||||
/**
|
||||
* Remove an index.
|
||||
*/
|
||||
removeIndex(fieldName: string): Promise<void>;
|
||||
}
|
||||
}
|
||||
|
||||
export = NeDB.Datastore;
|
1
node_modules/nedb-promises/index.js
generated
vendored
Normal file
1
node_modules/nedb-promises/index.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
module.exports = require('./src/Datastore');
|
1
node_modules/nedb-promises/logo.svg
generated
vendored
Normal file
1
node_modules/nedb-promises/logo.svg
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg width="100%" height="100%" viewBox="0 0 332 83" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:1.41421;"><rect x="0" y="0" width="331.299" height="82.382" style="fill:#2e3746;"/><g transform="matrix(0.75,0,0,0.75,-160.487,-1726.9)"><text x="245.348px" y="2370.35px" style="font-family:'AvenirNext-Medium', 'Avenir Next', sans-serif;font-weight:500;font-size:50px;fill:#a7c965;">n<tspan x="276.948px 308.098px 342.348px " y="2370.35px 2370.35px 2370.35px ">edb</tspan></text><text x="376.648px" y="2370.35px" style="font-family:'AvenirNext-Medium', 'Avenir Next', sans-serif;font-weight:500;font-size:50px;fill:#7b7f8e;">-</text><text x="395.148px" y="2370.35px" style="font-family:'AvenirNext-Medium', 'Avenir Next', sans-serif;font-weight:500;font-size:50px;fill:#fff;">p<tspan x="429.348px 449.048px 482.048px 528.898px 544.348px 569.048px 600.198px " y="2370.35px 2370.35px 2370.35px 2370.35px 2370.35px 2370.35px 2370.35px ">romises</tspan></text></g></svg>
|
After Width: | Height: | Size: 1.3 KiB |
36
node_modules/nedb-promises/package.json
generated
vendored
Normal file
36
node_modules/nedb-promises/package.json
generated
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
{
|
||||
"name": "nedb-promises",
|
||||
"version": "6.2.3",
|
||||
"description": "A dead-simple promise wrapper for nedb.",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"docs": "jsdoc2md ./src/*.js > docs.md --no-gfm",
|
||||
"test": "jest",
|
||||
"test:watch": "jest --watchAll",
|
||||
"lint": "eslint .",
|
||||
"lint:fix": "eslint . --fix"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/bajankristof/nedb-promises.git"
|
||||
},
|
||||
"keywords": [
|
||||
"nedb",
|
||||
"promises",
|
||||
"promise"
|
||||
],
|
||||
"author": "Kristóf Baján",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/bajankristof/nedb-promises/issues"
|
||||
},
|
||||
"homepage": "https://github.com/bajankristof/nedb-promises#readme",
|
||||
"dependencies": {
|
||||
"@seald-io/nedb": "^4.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^8.6.0",
|
||||
"jest": "^29.0.3",
|
||||
"jsdoc-to-markdown": "^8.0.0"
|
||||
}
|
||||
}
|
154
node_modules/nedb-promises/src/Cursor.js
generated
vendored
Normal file
154
node_modules/nedb-promises/src/Cursor.js
generated
vendored
Normal file
@ -0,0 +1,154 @@
|
||||
const OriginalCursor = require('@seald-io/nedb/lib/cursor');
|
||||
|
||||
/**
|
||||
* @class
|
||||
*/
|
||||
class Cursor {
|
||||
constructor(datastore, op, ...args) {
|
||||
const cursor = datastore.__original[op](...args);
|
||||
if (!(cursor instanceof OriginalCursor)) {
|
||||
throw new TypeError(`Unexpected ${typeof original}, expected: Cursor (nedb/lib/cursor)`);
|
||||
}
|
||||
|
||||
Object.defineProperties(this, {
|
||||
__original: {
|
||||
configurable: false,
|
||||
enumerable: false,
|
||||
writable: false,
|
||||
value: cursor,
|
||||
},
|
||||
|
||||
__datastore: {
|
||||
configurable: false,
|
||||
enumerable: false,
|
||||
writable: false,
|
||||
value: datastore,
|
||||
},
|
||||
|
||||
__op: {
|
||||
configurable: false,
|
||||
enumerable: false,
|
||||
writable: false,
|
||||
value: op,
|
||||
},
|
||||
|
||||
__args: {
|
||||
configurable: false,
|
||||
enumerable: false,
|
||||
writable: false,
|
||||
value: args,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort the queried documents.
|
||||
*
|
||||
* See: https://github.com/louischatriot/nedb#sorting-and-paginating
|
||||
*
|
||||
* @return {Cursor}
|
||||
*/
|
||||
sort(...args) {
|
||||
this.__original.sort(...args);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Skip some of the queried documents.
|
||||
*
|
||||
* See: https://github.com/louischatriot/nedb#sorting-and-paginating
|
||||
*
|
||||
* @return {Cursor}
|
||||
*/
|
||||
skip(...args) {
|
||||
this.__original.skip(...args);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Limit the queried documents.
|
||||
*
|
||||
* See: https://github.com/louischatriot/nedb#sorting-and-paginating
|
||||
*
|
||||
* @return {Cursor}
|
||||
*/
|
||||
limit(...args) {
|
||||
this.__original.limit(...args);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the document projection.
|
||||
*
|
||||
* See: https://github.com/louischatriot/nedb#projections
|
||||
*
|
||||
* @return {Cursor}
|
||||
*/
|
||||
project(...args) {
|
||||
this.__original.projection(...args);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the cursor.
|
||||
*
|
||||
* Since the Cursor has a `then` and a `catch` method
|
||||
* JavaScript identifies it as a thenable object
|
||||
* thus you can await it in async functions.
|
||||
*
|
||||
* @example
|
||||
* // in an async function
|
||||
* await datastore.find(...)
|
||||
* .sort(...)
|
||||
* .limit(...)
|
||||
*
|
||||
* @example
|
||||
* // the previous is the same as:
|
||||
* await datastore.find(...)
|
||||
* .sort(...)
|
||||
* .limit(...)
|
||||
* .exec()
|
||||
*
|
||||
* @return {Promise<Object[]>}
|
||||
*/
|
||||
async exec() {
|
||||
await this.__datastore.load();
|
||||
try {
|
||||
const result = await this.__original.execAsync();
|
||||
this.__datastore.broadcastSuccess(this.__op, result, ...this.__args);
|
||||
return result;
|
||||
} catch (error) {
|
||||
this.__datastore.broadcastError(this.__op, error, ...this.__args);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the cursor and set promise callbacks.
|
||||
*
|
||||
* For more information visit:
|
||||
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then
|
||||
*
|
||||
* @param {Function} fulfilled
|
||||
* @param {Function} [rejected]
|
||||
* @return {Promise}
|
||||
*/
|
||||
then(fulfilled, rejected) {
|
||||
return this.exec().then(fulfilled, rejected);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the cursor and set promise error callback.
|
||||
*
|
||||
* For more information visit:
|
||||
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch
|
||||
*
|
||||
* @param {Function} rejected
|
||||
* @return {Promise}
|
||||
*/
|
||||
catch(rejected) {
|
||||
return this.exec().catch(rejected);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Cursor;
|
497
node_modules/nedb-promises/src/Datastore.js
generated
vendored
Normal file
497
node_modules/nedb-promises/src/Datastore.js
generated
vendored
Normal file
@ -0,0 +1,497 @@
|
||||
const EventEmitter = require('events');
|
||||
const OriginalDatastore = require('@seald-io/nedb');
|
||||
const Cursor = require('./Cursor');
|
||||
|
||||
/**
|
||||
* @summary
|
||||
* As of v2.0.0 the Datastore class extends node's built
|
||||
* in EventEmitter class and implements each method as an event
|
||||
* plus additional error events. It also inherits the `compaction.done`
|
||||
* event from nedb but for consistency, in this library the event
|
||||
* was renamed to `compactionDone`.
|
||||
*
|
||||
* All event callbacks will be passed the same type of values,
|
||||
* the first being the datastore, then the operation result (if there is any)
|
||||
* and then the arguments of the called method. (Check out the first example!)
|
||||
*
|
||||
* All events have a matching error event that goes by the name of `${method}Error`,
|
||||
* for example `findError` or `loadError`. The callbacks of these events will receive
|
||||
* the same parameters as the normal event handlers except that instead of the
|
||||
* operation result there will be an operation error. (Check out the second example!)
|
||||
*
|
||||
* A generic `__error__` event is also available. This event will be emitted at any of
|
||||
* the above error events. The callbacks of this event will receive the same parameters
|
||||
* as the specific error event handlers except that there will be one more parameter
|
||||
* passed between the datastore and the error object, that being the name of the method
|
||||
* that failed. (Check out the third example!)
|
||||
*
|
||||
* @example
|
||||
* let datastore = Datastore.create()
|
||||
* datastore.on('update', (datastore, result, query, update, options) => {
|
||||
* })
|
||||
* datastore.on('load', (datastore) => {
|
||||
* // this event doesn't have a result
|
||||
* })
|
||||
* datastore.on('ensureIndex', (datastore, options) => {
|
||||
* // this event doesn't have a result
|
||||
* // but it has the options argument which will be passed to the
|
||||
* // event handlers
|
||||
* })
|
||||
* datastore.on('compactionDone', (datastore) => {
|
||||
* // inherited from nedb's compaction.done event
|
||||
* })
|
||||
*
|
||||
* @example
|
||||
* let datastore = Datastore.create()
|
||||
* datastore.on('updateError', (datastore, error, query, update, options) => {
|
||||
* })
|
||||
* datastore.on('loadError', (datastore, error) => {
|
||||
* })
|
||||
* datastore.on('ensureIndexError', (datastore, error, options) => {
|
||||
* })
|
||||
*
|
||||
* @example
|
||||
* let datastore = Datastore.create()
|
||||
* datastore.on('__error__', (datastore, event, error, ...args) => {
|
||||
* // for example
|
||||
* // datastore, 'find', error, [{ foo: 'bar' }, {}]
|
||||
* })
|
||||
*
|
||||
* @class
|
||||
*/
|
||||
class Datastore extends EventEmitter {
|
||||
/**
|
||||
* Create a database instance.
|
||||
*
|
||||
* Use this over `new Datastore(...)` to access
|
||||
* original nedb datastore properties, such as
|
||||
* `datastore.persistence`.
|
||||
*
|
||||
* Note that this method only creates the `Datastore`
|
||||
* class instance, not the datastore file itself.
|
||||
* The file will only be created once an operation
|
||||
* is issued against the datastore or if you call
|
||||
* the `load` instance method explicitly.
|
||||
*
|
||||
* The path (if specified) will be relative to `process.cwd()`
|
||||
* (unless an absolute path was passed).
|
||||
*
|
||||
* For more information visit:
|
||||
* https://github.com/louischatriot/nedb#creatingloading-a-database
|
||||
*
|
||||
* @param {string|Object} [pathOrOptions]
|
||||
* @return {Proxy<static>}
|
||||
*/
|
||||
static create(pathOrOptions) {
|
||||
return new Proxy(new this(pathOrOptions), {
|
||||
get(target, key) {
|
||||
return target[key]
|
||||
? target[key]
|
||||
: target.__original[key];
|
||||
},
|
||||
|
||||
set(target, key, value) {
|
||||
return Object.prototype.hasOwnProperty.call(target.__original, key)
|
||||
? (target.__original[key] = value)
|
||||
: (target[key] = value);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Datastore constructor...
|
||||
*
|
||||
* You should use `Datastore.create(...)` instead
|
||||
* of `new Datastore(...)`. With that you can access
|
||||
* the original datastore's properties such as `datastore.persistence`.
|
||||
*
|
||||
* Create a Datastore instance.
|
||||
*
|
||||
* Note that the datastore will be created
|
||||
* relative to `process.cwd()`
|
||||
* (unless an absolute path was passed).
|
||||
*
|
||||
* It's basically the same as the original:
|
||||
* https://github.com/louischatriot/nedb#creatingloading-a-database
|
||||
*
|
||||
* @param {string|Object} [pathOrOptions]
|
||||
* @return {static}
|
||||
*/
|
||||
constructor(pathOrOptions) {
|
||||
super();
|
||||
|
||||
const datastore = new OriginalDatastore(
|
||||
typeof pathOrOptions === 'string'
|
||||
? { filename: pathOrOptions }
|
||||
: pathOrOptions,
|
||||
);
|
||||
|
||||
Object.defineProperties(this, {
|
||||
__loaded: {
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
value: null,
|
||||
},
|
||||
|
||||
__original: {
|
||||
configurable: true,
|
||||
enumerable: false,
|
||||
writable: false,
|
||||
value: datastore,
|
||||
},
|
||||
});
|
||||
|
||||
this.__original.on('compaction.done', () => {
|
||||
this.emit('compactionDone', this);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the datastore.
|
||||
*
|
||||
* Note that you don't necessarily have to call
|
||||
* this method to load the datastore as it will
|
||||
* automatically be called and awaited on any
|
||||
* operation issued against the datastore
|
||||
* (i.e.: `find`, `findOne`, etc.).
|
||||
*
|
||||
* @return {Promise<undefined>}
|
||||
*/
|
||||
load() {
|
||||
if ( ! (this.__loaded instanceof Promise)) {
|
||||
this.__loaded = this.__original.loadDatabaseAsync()
|
||||
.then(() => this.broadcastSuccess('load'))
|
||||
.catch((error) => { this.broadcastError('load', error); throw error; });
|
||||
}
|
||||
|
||||
return this.__loaded;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find documents that match the specified `query`.
|
||||
*
|
||||
* It's basically the same as the original:
|
||||
* https://github.com/louischatriot/nedb#finding-documents
|
||||
*
|
||||
* There are differences minor in how the cursor works though.
|
||||
*
|
||||
* @example
|
||||
* datastore.find({ ... }).sort({ ... }).exec().then(...)
|
||||
*
|
||||
* @example
|
||||
* datastore.find({ ... }).sort({ ... }).then(...)
|
||||
*
|
||||
* @example
|
||||
* // in an async function
|
||||
* await datastore.find({ ... }).sort({ ... })
|
||||
*
|
||||
* @param {Object} [query]
|
||||
* @param {Object} [projection]
|
||||
* @return {Cursor}
|
||||
*/
|
||||
find(query = {}, projection) {
|
||||
if (typeof projection === 'function') {
|
||||
projection = {};
|
||||
}
|
||||
|
||||
return new Cursor(this, 'find', query, projection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a document that matches the specified `query`.
|
||||
*
|
||||
* It's basically the same as the original:
|
||||
* https://github.com/louischatriot/nedb#finding-documents
|
||||
*
|
||||
* @example
|
||||
* datastore.findOne({ ... }).then(...)
|
||||
*
|
||||
* @example
|
||||
* // in an async function
|
||||
* await datastore.findOne({ ... }).sort({ ... })
|
||||
*
|
||||
* @param {Object} [query]
|
||||
* @param {Object} [projection]
|
||||
* @return {Cursor}
|
||||
*/
|
||||
findOne(query = {}, projection) {
|
||||
if (typeof projection === 'function') {
|
||||
projection = {};
|
||||
}
|
||||
|
||||
return new Cursor(this, 'findOne', query, projection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert a document or documents.
|
||||
*
|
||||
* It's basically the same as the original:
|
||||
* https://github.com/louischatriot/nedb#inserting-documents
|
||||
*
|
||||
* @param {Object|Object[]} docs
|
||||
* @return {Promise<Object|Object[]>}
|
||||
*/
|
||||
async insert(docs) {
|
||||
await this.load();
|
||||
try {
|
||||
const result = await this.__original.insertAsync(docs);
|
||||
this.broadcastSuccess('insert', docs);
|
||||
return result;
|
||||
} catch (error) {
|
||||
this.broadcastError('insert', error, docs);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert a single document.
|
||||
*
|
||||
* This is just an alias for `insert` with object destructuring
|
||||
* to ensure a single document.
|
||||
*
|
||||
* @param {Object} doc
|
||||
* @return {Promise<Object>}
|
||||
*/
|
||||
insertOne({ ...doc }) {
|
||||
return this.insert(doc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert multiple documents.
|
||||
*
|
||||
* This is just an alias for `insert` with array destructuring
|
||||
* to ensure multiple documents.
|
||||
*
|
||||
* @param {Object[]} docs
|
||||
* @return {Promise<Object[]>}
|
||||
*/
|
||||
insertMany([...docs]) {
|
||||
return this.insert(docs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update documents that match the specified `query`.
|
||||
*
|
||||
* It's basically the same as the original:
|
||||
* https://github.com/louischatriot/nedb#updating-documents
|
||||
*
|
||||
* If you set `options.returnUpdatedDocs`,
|
||||
* the returned promise will resolve with
|
||||
* an object (if `options.multi` is `false`) or
|
||||
* with an array of objects.
|
||||
*
|
||||
* @param {Object} query
|
||||
* @param {Object} update
|
||||
* @param {Object} [options]
|
||||
* @return {Promise<number|Object|Object[]>}
|
||||
*/
|
||||
async update(query, update, options = {}) {
|
||||
await this.load();
|
||||
try {
|
||||
const { numAffected, affectedDocuments } = await this.__original.updateAsync(query, update, options);
|
||||
const result = options.returnUpdatedDocs ? affectedDocuments : numAffected;
|
||||
this.broadcastSuccess('update', result, query, update, options);
|
||||
return result;
|
||||
} catch (error) {
|
||||
this.broadcastError('update', error, query, update, options);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a single document that matches the specified `query`.
|
||||
*
|
||||
* This is just an alias for `update` with `options.multi` set to `false`.
|
||||
*
|
||||
* @param {Object} query
|
||||
* @param {Object} update
|
||||
* @param {Object} [options]
|
||||
*
|
||||
* @return {Promise<number|Object>}
|
||||
*/
|
||||
updateOne(query, update, options = {}) {
|
||||
return this.update(query, update, { ...options, multi: false });
|
||||
}
|
||||
|
||||
/**
|
||||
* Update multiple documents that match the specified `query`.
|
||||
*
|
||||
* This is just an alias for `update` with `options.multi` set to `true`.
|
||||
*
|
||||
* @param {Object} query
|
||||
* @param {Object} update
|
||||
* @param {Object} [options]
|
||||
*
|
||||
* @return {Promise<number|Object[]>}
|
||||
*/
|
||||
updateMany(query, update, options = {}) {
|
||||
return this.update(query, update, { ...options, multi: true });
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove documents that match the specified `query`.
|
||||
*
|
||||
* It's basically the same as the original:
|
||||
* https://github.com/louischatriot/nedb#removing-documents
|
||||
*
|
||||
* @param {Object} [query]
|
||||
* @param {Object} [options]
|
||||
* @return {Promise<number>}
|
||||
*/
|
||||
async remove(query = {}, options = {}) {
|
||||
await this.load();
|
||||
try {
|
||||
const result = await this.__original.removeAsync(query, options);
|
||||
this.broadcastSuccess('remove', result, query, options);
|
||||
return result;
|
||||
} catch (error) {
|
||||
this.broadcastError('remove', error, query, options);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the first document that matches the specified `query`.
|
||||
*
|
||||
* This is just an alias for `remove` with `options.multi` set to `false`.
|
||||
*
|
||||
* @param {Object} [query]
|
||||
* @param {Object} [options]
|
||||
*
|
||||
* @return {Promise<number>}
|
||||
*/
|
||||
removeOne(query, options = {}) {
|
||||
return this.remove(query, { ...options, multi: false });
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all documents that match the specified `query`.
|
||||
*
|
||||
* This is just an alias for `remove` with `options.multi` set to `true`.
|
||||
*
|
||||
* @param {Object} [query]
|
||||
* @param {Object} [options]
|
||||
*
|
||||
* @return {Promise<number>}
|
||||
*/
|
||||
removeMany(query, options = {}) {
|
||||
return this.remove(query, { ...options, multi: true });
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the first document that matches the specified `query`.
|
||||
*
|
||||
* This is just an alias for `removeOne`.
|
||||
*
|
||||
* @param {Object} [query]
|
||||
* @param {Object} [options]
|
||||
*
|
||||
* @return {Promise<number>}
|
||||
*/
|
||||
deleteOne(query, options) {
|
||||
return this.removeOne(query, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all documents that match the specified `query`.
|
||||
*
|
||||
* This is just an alias for `removeMany`.
|
||||
*
|
||||
* @param {Object} [query]
|
||||
* @param {Object} [options]
|
||||
*
|
||||
* @return {Promise<number>}
|
||||
*/
|
||||
deleteMany(query, options) {
|
||||
return this.removeMany(query, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Count documents matching the specified `query`.
|
||||
*
|
||||
* It's basically the same as the original:
|
||||
* https://github.com/louischatriot/nedb#counting-documents
|
||||
*
|
||||
* @example
|
||||
* datastore.count({ ... }).limit(...).then(...)
|
||||
*
|
||||
* @example
|
||||
* // in an async function
|
||||
* await datastore.count({ ... })
|
||||
* // or
|
||||
* await datastore.count({ ... }).sort(...).limit(...)
|
||||
*
|
||||
* @param {Object} [query]
|
||||
* @return {Cursor}
|
||||
*/
|
||||
count(query = {}) {
|
||||
return new Cursor(this, 'count', query);
|
||||
}
|
||||
|
||||
/**
|
||||
* https://github.com/louischatriot/nedb#indexing
|
||||
*
|
||||
* @param {Object} options
|
||||
* @return {Promise<undefined>}
|
||||
*/
|
||||
async ensureIndex(options) {
|
||||
try {
|
||||
const result = await this.__original.ensureIndexAsync(options);
|
||||
this.broadcastSuccess('ensureIndex', result, options);
|
||||
return result;
|
||||
} catch (error) {
|
||||
this.broadcastError('ensureIndex', error, options);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* https://github.com/louischatriot/nedb#indexing
|
||||
*
|
||||
* @param {string} field
|
||||
* @return {Promise<undefined>}
|
||||
*/
|
||||
async removeIndex(field) {
|
||||
try {
|
||||
const result = await this.__original.removeIndexAsync(field);
|
||||
this.broadcastSuccess('removeIndex', result, field);
|
||||
return result;
|
||||
} catch (error) {
|
||||
this.broadcastError('removeIndex', error, field);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Broadcasts operation success messages.
|
||||
*
|
||||
* @param {string} op
|
||||
* @param {*} result
|
||||
* @param {...*} args
|
||||
*
|
||||
* @return {undefined}
|
||||
* @private
|
||||
*/
|
||||
broadcastSuccess(op, result, ...args) {
|
||||
this.emit(op, this, result, ...args);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Broadcasts operation error messages.
|
||||
*
|
||||
* @param {string} op
|
||||
* @param {Error} error
|
||||
* @param {...*} args
|
||||
*
|
||||
* @return {undefined}
|
||||
* @private
|
||||
*/
|
||||
broadcastError(op, error, ...args) {
|
||||
this.emit(`${op}Error`, this, error, ...args);
|
||||
this.emit('__error__', this, op, error, ...args);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Datastore;
|
29
node_modules/nedb-promises/test/a.create.test.js
generated
vendored
Normal file
29
node_modules/nedb-promises/test/a.create.test.js
generated
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
const fs = require('fs');
|
||||
const Datastore = require('../src/Datastore');
|
||||
|
||||
describe('testing datastore creation', () => {
|
||||
describe('new Datastore(\'foo.db\')', () => {
|
||||
it('should create foo.db based on string filename', async () => {
|
||||
const datastore = Datastore.create('foo.db');
|
||||
await datastore.load();
|
||||
expect(fs.existsSync('foo.db')).toBe(true);
|
||||
fs.unlinkSync('foo.db');
|
||||
});
|
||||
});
|
||||
|
||||
describe('new Datastore({ filename: \'bar.db\' })', () => {
|
||||
it('sould create bar.db based on object parameters', async () => {
|
||||
const datastore = Datastore.create({ filename: 'bar.db' });
|
||||
await datastore.load();
|
||||
expect(fs.existsSync('bar.db')).toBe(true);
|
||||
fs.unlinkSync('bar.db');
|
||||
});
|
||||
});
|
||||
|
||||
describe('new Datastore()', () => {
|
||||
it('should create in memory only database', () => {
|
||||
const datastore = Datastore.create();
|
||||
expect(datastore.inMemoryOnly).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
27
node_modules/nedb-promises/test/b.insert.test.js
generated
vendored
Normal file
27
node_modules/nedb-promises/test/b.insert.test.js
generated
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
const Datastore = require('../src/Datastore');
|
||||
|
||||
describe('testing document insertion', () => {
|
||||
const docs = [
|
||||
{ name: '1st document' },
|
||||
{ name: '2nd document' },
|
||||
{ name: '3rd document' },
|
||||
];
|
||||
|
||||
describe('single', () => {
|
||||
it('should insert single document', async () => {
|
||||
const datastore = Datastore.create();
|
||||
const insertedDoc = await datastore.insert(docs[0]);
|
||||
expect(insertedDoc).toMatchObject({ name: '1st document' });
|
||||
expect(insertedDoc).toHaveProperty('_id');
|
||||
});
|
||||
});
|
||||
|
||||
describe('bulk', () => {
|
||||
it('should insert multiple documents', async () => {
|
||||
const datastore = Datastore.create();
|
||||
const insertedDocs = await datastore.insert(docs);
|
||||
expect(insertedDocs.length).toBe(3);
|
||||
expect(insertedDocs).toMatchObject(docs);
|
||||
});
|
||||
});
|
||||
});
|
43
node_modules/nedb-promises/test/c.find.test.js
generated
vendored
Normal file
43
node_modules/nedb-promises/test/c.find.test.js
generated
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
const Datastore = require('../src/Datastore');
|
||||
|
||||
describe('testing document finding', () => {
|
||||
const docs = [
|
||||
{ name: '1st document' },
|
||||
{ name: '2nd document' },
|
||||
{ name: '3rd document' },
|
||||
];
|
||||
|
||||
const datastore = Datastore.create();
|
||||
beforeEach(() => datastore.insert(docs));
|
||||
afterEach(() => datastore.remove({}, { multi: true }));
|
||||
|
||||
describe('single', () => {
|
||||
it('should find the first inserted doc', async () => {
|
||||
const foundDoc = await datastore.findOne();
|
||||
expect(foundDoc).toHaveProperty('_id');
|
||||
expect(foundDoc).toHaveProperty('name');
|
||||
expect(foundDoc.name).toMatch(/^(1st|2nd|3rd) document$/);
|
||||
});
|
||||
|
||||
it('should find the last inserted doc when sorting backwards', async () => {
|
||||
const foundDoc = await datastore.findOne().sort({ name: -1 });
|
||||
expect(foundDoc).toHaveProperty('_id');
|
||||
expect(foundDoc).toHaveProperty('name');
|
||||
expect(foundDoc.name).toBe('3rd document');
|
||||
});
|
||||
});
|
||||
|
||||
describe('bulk', () => {
|
||||
it('should find all inserted docs', async () => {
|
||||
const foundDocs = await datastore.find().sort({ name: 1 }).exec();
|
||||
expect(foundDocs).toMatchObject(docs);
|
||||
});
|
||||
});
|
||||
|
||||
describe('find().then()', () => {
|
||||
it('should find all inserted docs', async () => {
|
||||
const foundDocs = await datastore.find().sort({ name: 1 });
|
||||
expect(foundDocs).toMatchObject(docs);
|
||||
});
|
||||
});
|
||||
});
|
70
node_modules/nedb-promises/test/d.update.test.js
generated
vendored
Normal file
70
node_modules/nedb-promises/test/d.update.test.js
generated
vendored
Normal file
@ -0,0 +1,70 @@
|
||||
const Datastore = require('../src/Datastore');
|
||||
|
||||
describe('testing document update', () => {
|
||||
const docs = [
|
||||
{ name: '1st document' },
|
||||
{ name: '2nd document' },
|
||||
{ name: '3rd document' },
|
||||
];
|
||||
|
||||
const datastore = Datastore.create();
|
||||
beforeEach(() => datastore.insert(docs));
|
||||
afterEach(() => datastore.remove({}, { multi: true }));
|
||||
|
||||
describe('single', () => {
|
||||
it('should update single document', async () => {
|
||||
const { _id } = await datastore.findOne({ name: /^1st/ });
|
||||
const numAffected = await datastore.update({ name: /^1st/ }, { test: true }, { multi: false });
|
||||
expect(numAffected).toBe(1);
|
||||
const affectedDoc = await datastore.findOne({ test: true });
|
||||
expect(affectedDoc).toMatchObject({ _id, test: true });
|
||||
});
|
||||
});
|
||||
|
||||
describe('single with returnUpdatedDocs', () => {
|
||||
it('should update and return single document', async () => {
|
||||
const { _id } = await datastore.findOne({ name: /^1st/ });
|
||||
const affectedDoc = await datastore.update(
|
||||
{ name: '1st document' },
|
||||
{ test: true },
|
||||
{ multi: false, returnUpdatedDocs: true },
|
||||
);
|
||||
|
||||
expect(affectedDoc).toMatchObject({ _id, test: true });
|
||||
});
|
||||
});
|
||||
|
||||
describe('bulk', () => {
|
||||
it('should update multiple documents', async () => {
|
||||
const numAffected = await datastore.update(
|
||||
{ name: { $regex: /^1st|2nd/ } },
|
||||
{ $set: { test: true } },
|
||||
{ multi: true },
|
||||
);
|
||||
|
||||
expect(numAffected).toBe(2);
|
||||
const affectedDocs = await datastore.find({ test: true });
|
||||
expect(affectedDocs.length).toBe(2);
|
||||
affectedDocs.forEach((affectedDoc) => {
|
||||
expect(affectedDoc.name.match(/^1st|2nd/)).toBeTruthy();
|
||||
expect(affectedDoc.test).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('bulk with returnUpdatedDocs', () => {
|
||||
it('should update and return multiple documents', async () => {
|
||||
const affectedDocs = await datastore.update(
|
||||
{ name: { $regex: /^2nd|3rd/ } },
|
||||
{ $set: { test: true } },
|
||||
{ multi: true, returnUpdatedDocs: true },
|
||||
);
|
||||
|
||||
expect(affectedDocs.length).toBe(2);
|
||||
affectedDocs.forEach((affectedDoc) => {
|
||||
expect(affectedDoc.name.match(/^2nd|3rd/)).toBeTruthy();
|
||||
expect(affectedDoc.test).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
25
node_modules/nedb-promises/test/e.count.test.js
generated
vendored
Normal file
25
node_modules/nedb-promises/test/e.count.test.js
generated
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
const Datastore = require('../src/Datastore');
|
||||
|
||||
describe('testing document counting', () => {
|
||||
const docs = [
|
||||
{ name: '1st document' },
|
||||
{ name: '2nd document' },
|
||||
{ name: '3rd document' },
|
||||
];
|
||||
|
||||
const datastore = Datastore.create();
|
||||
beforeEach(() => datastore.insert(docs));
|
||||
afterEach(() => datastore.remove({}, { multi: true }));
|
||||
|
||||
describe('count', () => {
|
||||
it('should get the count of the docs', async () => {
|
||||
const count = await datastore.count();
|
||||
expect(count).toBe(3);
|
||||
});
|
||||
|
||||
it('should get the count of the docs when limiting', async () => {
|
||||
const count = await datastore.count().limit(2);
|
||||
expect(count).toBe(2);
|
||||
});
|
||||
});
|
||||
});
|
16
node_modules/nedb-promises/test/f.proxy.test.js
generated
vendored
Normal file
16
node_modules/nedb-promises/test/f.proxy.test.js
generated
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
const Cursor = require('../src/Cursor');
|
||||
const Datastore = require('../src/Datastore');
|
||||
const Persistence = require('@seald-io/nedb/lib/persistence');
|
||||
|
||||
describe('testing datastore proxy', () => {
|
||||
const datastore = Datastore.create('test.db');
|
||||
|
||||
it('should not affect promise returns', () => {
|
||||
expect(datastore.find({}) instanceof Cursor).toBe(true);
|
||||
expect(datastore.insert({ proxy: true }) instanceof Promise).toBe(true);
|
||||
});
|
||||
|
||||
it('should return original datastore values', () => {
|
||||
expect(datastore.persistence instanceof Persistence).toBe(true);
|
||||
});
|
||||
});
|
62
node_modules/nedb-promises/test/g.mongocompat.test.js
generated
vendored
Normal file
62
node_modules/nedb-promises/test/g.mongocompat.test.js
generated
vendored
Normal file
@ -0,0 +1,62 @@
|
||||
const Datastore = require('../src/Datastore');
|
||||
|
||||
describe('testing MongoDB compatibility methods', () => {
|
||||
describe('insertOne', () => {
|
||||
it('should insert a single document event when passed an array', async () => {
|
||||
const datastore = Datastore.create();
|
||||
const result = await datastore.insertOne([{ foo: true }, { bar: false }]);
|
||||
expect(Array.isArray(result)).toBe(false);
|
||||
expect(result['0']).toEqual({ foo: true });
|
||||
expect(await datastore.count()).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('insertMany', () => {
|
||||
it('should throw when passed a non-iterable value', async () => {
|
||||
const datastore = Datastore.create();
|
||||
expect(() => datastore.insertMany({})).toThrow();
|
||||
});
|
||||
|
||||
it('should insert the specified documents otherwise', async () => {
|
||||
const datastore = Datastore.create();
|
||||
await datastore.insertMany([{}, {}]);
|
||||
expect(await datastore.count()).toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('updateOne', () => {
|
||||
it('should update a single document', async () => {
|
||||
const datastore = Datastore.create();
|
||||
await datastore.insert([{}, {}]);
|
||||
await datastore.updateOne({}, { $set: { foo: true } }, { multi: true });
|
||||
expect(await datastore.count({ foo: true })).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('updateMany', () => {
|
||||
it('should update multiple documents', async () => {
|
||||
const datastore = Datastore.create();
|
||||
await datastore.insert([{}, {}]);
|
||||
await datastore.updateMany({}, { $set: { foo: true } }, { multi: false });
|
||||
expect(await datastore.count({ foo: true })).toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('deleteOne', () => {
|
||||
it('should update a single document', async () => {
|
||||
const datastore = Datastore.create();
|
||||
await datastore.insert([{}, {}]);
|
||||
await datastore.deleteOne({}, { multi: true });
|
||||
expect(await datastore.count()).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('deleteMany', () => {
|
||||
it('should update multiple documents', async () => {
|
||||
const datastore = Datastore.create();
|
||||
await datastore.insert([{}, {}]);
|
||||
await datastore.deleteMany({}, { multi: false });
|
||||
expect(await datastore.count()).toBe(0);
|
||||
});
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user