├── .github ├── contributing.md ├── issue_template.md ├── pull_request_template.md └── workflows │ ├── nodejs.yml │ └── update-dependencies.yml ├── .gitignore ├── .mocharc.json ├── .nycrc ├── CHANGELOG.md ├── LICENSE ├── README.md ├── package-lock.json ├── package.json ├── src ├── adapter.ts └── index.ts ├── test └── index.test.ts ├── tsconfig-base.json └── tsconfig.json /.github/contributing.md: -------------------------------------------------------------------------------- 1 | # Contributing to Feathers 2 | 3 | Thank you for contributing to Feathers! :heart: :tada: 4 | 5 | This repo is the main core and where most issues are reported. Feathers embraces modularity and is broken up across many repos. To make this easier to manage we currently use [Zenhub](https://www.zenhub.com/) for issue triage and visibility. They have a free browser plugin you can install so that you can see what is in flight at any time, but of course you also always see current issues in Github. 6 | 7 | ## Report a bug 8 | 9 | Before creating an issue please make sure you have checked out the docs, specifically the [FAQ](https://docs.feathersjs.com/help/faq.html) section. You might want to also try searching Github. It's pretty likely someone has already asked a similar question. 10 | 11 | If you haven't found your answer please feel free to join our [slack channel](http://slack.feathersjs.com), create an issue on Github, or post on [Stackoverflow](http://stackoverflow.com) using the `feathers` or `feathersjs` tag. We try our best to monitor Stackoverflow but you're likely to get more immediate responses in Slack and Github. 12 | 13 | Issues can be reported in the [issue tracker](https://github.com/feathersjs/feathers/issues). Since feathers combines many modules it can be hard for us to assess the root cause without knowing which modules are being used and what your configuration looks like, so **it helps us immensely if you can link to a simple example that reproduces your issue**. 14 | 15 | ## Report a Security Concern 16 | 17 | We take security very seriously at Feathers. We welcome any peer review of our 100% open source code to ensure nobody's Feathers app is ever compromised or hacked. As a web application developer you are responsible for any security breaches. We do our very best to make sure Feathers is as secure as possible by default. 18 | 19 | In order to give the community time to respond and upgrade we strongly urge you report all security issues to us. Send one of the core team members a PM in [Slack](http://slack.feathersjs.com) or email us at hello@feathersjs.com with details and we will respond ASAP. 20 | 21 | For full details refer to our [Security docs](https://docs.feathersjs.com/SECURITY.html). 22 | 23 | ## Pull Requests 24 | 25 | We :heart: pull requests and we're continually working to make it as easy as possible for people to contribute, including a [Plugin Generator](https://github.com/feathersjs/generator-feathers-plugin) and a [common test suite](https://github.com/feathersjs/feathers-service-tests) for database adapters. 26 | 27 | We prefer small pull requests with minimal code changes. The smaller they are the easier they are to review and merge. A core team member will pick up your PR and review it as soon as they can. They may ask for changes or reject your pull request. This is not a reflection of you as an engineer or a person. Please accept feedback graciously as we will also try to be sensitive when providing it. 28 | 29 | Although we generally accept many PRs they can be rejected for many reasons. We will be as transparent as possible but it may simply be that you do not have the same context or information regarding the roadmap that the core team members have. We value the time you take to put together any contributions so we pledge to always be respectful of that time and will try to be as open as possible so that you don't waste it. :smile: 30 | 31 | **All PRs (except documentation) should be accompanied with tests and pass the linting rules.** 32 | 33 | ### Code style 34 | 35 | Before running the tests from the `test/` folder `npm test` will run ESlint. You can check your code changes individually by running `npm run lint`. 36 | 37 | ### ES6 compilation 38 | 39 | Feathers uses [Babel](https://babeljs.io/) to leverage the latest developments of the JavaScript language. All code and samples are currently written in ES2015. To transpile the code in this repository run 40 | 41 | > npm run compile 42 | 43 | __Note:__ `npm test` will run the compilation automatically before the tests. 44 | 45 | ### Tests 46 | 47 | [Mocha](http://mochajs.org/) tests are located in the `test/` folder and can be run using the `npm run mocha` or `npm test` (with ESLint and code coverage) command. 48 | 49 | ### Documentation 50 | 51 | Feathers documentation is contained in Markdown files in the [feathers-docs](https://github.com/feathersjs/feathers-docs) repository. To change the documentation submit a pull request to that repo, referencing any other PR if applicable, and the docs will be updated with the next release. 52 | 53 | ## External Modules 54 | 55 | If you're written something awesome for Feathers, the Feathers ecosystem, or using Feathers please add it to the [showcase](https://docs.feathersjs.com/why/showcase.html). You also might want to check out the [Plugin Generator](https://github.com/feathersjs/generator-feathers-plugin) that can be used to scaffold plugins to be Feathers compliant from the start. 56 | 57 | If you think it would be a good core module then please contact one of the Feathers core team members in [Slack](http://slack.feathersjs.com) and we can discuss whether it belongs in core and how to get it there. :beers: 58 | 59 | ## Contributor Code of Conduct 60 | 61 | As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities. 62 | 63 | We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion. 64 | 65 | Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct. 66 | 67 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team. 68 | 69 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers. 70 | 71 | This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/) 72 | -------------------------------------------------------------------------------- /.github/issue_template.md: -------------------------------------------------------------------------------- 1 | ### Steps to reproduce 2 | 3 | (First please check that this issue is not already solved as [described 4 | here](https://github.com/feathersjs/feathers/blob/master/.github/contributing.md#report-a-bug)) 5 | 6 | - [ ] Tell us what broke. The more detailed the better. 7 | - [ ] If you can, please create a simple example that reproduces the issue and link to a gist, jsbin, repo, etc. 8 | 9 | ### Expected behavior 10 | Tell us what should happen 11 | 12 | ### Actual behavior 13 | Tell us what happens instead 14 | 15 | ### System configuration 16 | 17 | Tell us about the applicable parts of your setup. 18 | 19 | **Module versions** (especially the part that's not working): 20 | 21 | **NodeJS version**: 22 | 23 | **Operating System**: 24 | 25 | **Browser Version**: 26 | 27 | **React Native Version**: 28 | 29 | **Module Loader**: -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | ### Summary 2 | 3 | (If you have not already please refer to the contributing guideline as [described 4 | here](https://github.com/feathersjs/feathers/blob/master/.github/contributing.md#pull-requests)) 5 | 6 | - [ ] Tell us about the problem your pull request is solving. 7 | - [ ] Are there any open issues that are related to this? 8 | - [ ] Is this PR dependent on PRs in other repos? 9 | 10 | If so, please mention them to keep the conversations linked together. 11 | 12 | ### Other Information 13 | 14 | If there's anything else that's important and relevant to your pull 15 | request, mention that information here. This could include 16 | benchmarks, or other information. 17 | 18 | Your PR will be reviewed by a core team member and they will work with you to get your changes merged in a timely manner. If merged your PR will automatically be added to the changelog in the next release. 19 | 20 | If your changes involve documentation updates please mention that and link the appropriate PR in [feathers-docs](https://github.com/feathersjs/feathers-docs). 21 | 22 | Thanks for contributing to Feathers! :heart: -------------------------------------------------------------------------------- /.github/workflows/nodejs.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | build: 7 | 8 | runs-on: ubuntu-latest 9 | 10 | strategy: 11 | matrix: 12 | node-version: [18, 'latest'] 13 | 14 | steps: 15 | - uses: actions/checkout@v2 16 | - name: Start MongoDB 17 | uses: supercharge/mongodb-github-action@1.6.0 18 | with: 19 | mongodb-version: 4.4 20 | mongodb-replica-set: test-rs 21 | - name: Use Node.js ${{ matrix.node-version }} 22 | uses: actions/setup-node@v4 23 | with: 24 | node-version: ${{ matrix.node-version }} 25 | - run: npm install 26 | - run: npm test 27 | env: 28 | CI: true 29 | -------------------------------------------------------------------------------- /.github/workflows/update-dependencies.yml: -------------------------------------------------------------------------------- 1 | name: Update dependencies 2 | 3 | on: 4 | schedule: 5 | - cron: '0 0 1 * *' 6 | workflow_dispatch: 7 | jobs: 8 | update-dependencies: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@v2 12 | - name: Use Node.js 13 | uses: actions/setup-node@v1 14 | with: 15 | node-version: '15.x' 16 | - run: npm ci 17 | - run: | 18 | git config user.name "GitHub Actions Bot" 19 | git config user.email "hello@feathersjs.com" 20 | git checkout -b update-dependencies-$GITHUB_RUN_ID 21 | - run: | 22 | npm run update-dependencies 23 | npm install 24 | - run: | 25 | git commit -am "chore(dependencies): Update dependencies" 26 | git push origin update-dependencies-$GITHUB_RUN_ID 27 | - run: | 28 | gh pr create --title "chore(dependencies): Update all dependencies" --body "" 29 | env: 30 | GITHUB_TOKEN: ${{secrets.CI_ACCESS_TOKEN}} 31 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | 3 | # Logs 4 | logs 5 | *.log 6 | 7 | # Runtime data 8 | pids 9 | *.pid 10 | *.seed 11 | 12 | # Directory for instrumented libs generated by jscoverage/JSCover 13 | lib-cov 14 | 15 | # Coverage directory used by tools like istanbul 16 | coverage 17 | 18 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 19 | .grunt 20 | 21 | # Compiled binary addons (http://nodejs.org/api/addons.html) 22 | build/Release 23 | 24 | # Dependency directory 25 | # Commenting this out is preferred by some people, see 26 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git- 27 | node_modules 28 | 29 | # Users Environment Variables 30 | .lock-wscript 31 | 32 | dist/ 33 | db-data/ 34 | 35 | # TypeScript compiled files 36 | lib/ -------------------------------------------------------------------------------- /.mocharc.json: -------------------------------------------------------------------------------- 1 | { 2 | "timeout": 30000, 3 | "require": ["ts-node/register", "source-map-support/register"], 4 | "reporter": "Dot", 5 | "extension": ".test.ts", 6 | "exit": true 7 | } 8 | -------------------------------------------------------------------------------- /.nycrc: -------------------------------------------------------------------------------- 1 | { 2 | "verbose": false, 3 | "tempDirectory": "./coverage/.tmp", 4 | "semistandard": { 5 | "env": [ 6 | "mocha" 7 | ] 8 | }, 9 | "extension": [ 10 | ".ts", 11 | ".tsx", 12 | ".js" 13 | ], 14 | "exclude": [ 15 | "**/test/*" 16 | ], 17 | "print": "detail", 18 | "reporter": [ 19 | "html", 20 | "text", 21 | "text-summary", 22 | "lcov" 23 | ], 24 | "watermarks": { 25 | "statements": [ 26 | 70, 27 | 90 28 | ], 29 | "lines": [ 30 | 70, 31 | 90 32 | ], 33 | "functions": [ 34 | 70, 35 | 90 36 | ], 37 | "branches": [ 38 | 70, 39 | 90 40 | ] 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## [v7.0.1](https://github.com/feathersjs-ecosystem/feathers-nedb/tree/v7.0.1) (2023-11-28) 4 | 5 | [Full Changelog](https://github.com/feathersjs-ecosystem/feathers-nedb/compare/v7.0.0...v7.0.1) 6 | 7 | ## [v7.0.0](https://github.com/feathersjs-ecosystem/feathers-nedb/tree/v7.0.0) (2023-11-27) 8 | 9 | [Full Changelog](https://github.com/feathersjs-ecosystem/feathers-nedb/compare/v6.0.0...v7.0.0) 10 | 11 | **Merged pull requests:** 12 | 13 | - make nedb work with feathers 5 [\#145](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/145) ([rmanibus](https://github.com/rmanibus)) 14 | - docs: Deprecate [\#138](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/138) ([FossPrime](https://github.com/FossPrime)) 15 | - chore\(dependencies\): Update all dependencies [\#128](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/128) ([daffl](https://github.com/daffl)) 16 | - chore\(dependencies\): Update all dependencies [\#127](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/127) ([daffl](https://github.com/daffl)) 17 | - chore\(dependencies\): Update all dependencies [\#126](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/126) ([daffl](https://github.com/daffl)) 18 | - chore\(dependencies\): Update all dependencies [\#125](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/125) ([daffl](https://github.com/daffl)) 19 | - Update README.md [\#123](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/123) ([fratzinger](https://github.com/fratzinger)) 20 | - chore\(dependencies\): Update all dependencies [\#121](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/121) ([daffl](https://github.com/daffl)) 21 | - chore\(dependencies\): Update all dependencies [\#120](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/120) ([daffl](https://github.com/daffl)) 22 | - chore\(dependencies\): Update all dependencies [\#119](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/119) ([daffl](https://github.com/daffl)) 23 | 24 | ## [v6.0.0](https://github.com/feathersjs-ecosystem/feathers-nedb/tree/v6.0.0) (2021-12-15) 25 | 26 | [Full Changelog](https://github.com/feathersjs-ecosystem/feathers-nedb/compare/v5.1.0...v6.0.0) 27 | 28 | **Closed issues:** 29 | 30 | - Switch to Promise based API [\#115](https://github.com/feathersjs-ecosystem/feathers-nedb/issues/115) 31 | - Find request returns all entries whatever the params [\#114](https://github.com/feathersjs-ecosystem/feathers-nedb/issues/114) 32 | - An in-range update of @feathersjs/adapter-commons is breaking the build 🚨 [\#109](https://github.com/feathersjs-ecosystem/feathers-nedb/issues/109) 33 | - An in-range update of @feathersjs/adapter-commons is breaking the build 🚨 [\#104](https://github.com/feathersjs-ecosystem/feathers-nedb/issues/104) 34 | 35 | **Merged pull requests:** 36 | 37 | - Upgrade plugin infrastructure, dependencies and use maintained NeDB fork [\#118](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/118) ([daffl](https://github.com/daffl)) 38 | - Update dtslint to the latest version 🚀 [\#111](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/111) ([greenkeeper[bot]](https://github.com/apps/greenkeeper)) 39 | - Update all dependencies and Types version [\#110](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/110) ([daffl](https://github.com/daffl)) 40 | - Update dtslint to the latest version 🚀 [\#108](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/108) ([greenkeeper[bot]](https://github.com/apps/greenkeeper)) 41 | - Update dtslint to version 1.0.2 [\#107](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/107) ([daffl](https://github.com/daffl)) 42 | - Greenkeeper/@feathersjs/adapter commons 4.3.8 [\#105](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/105) ([daffl](https://github.com/daffl)) 43 | 44 | ## [v5.1.0](https://github.com/feathersjs-ecosystem/feathers-nedb/tree/v5.1.0) (2019-10-07) 45 | 46 | [Full Changelog](https://github.com/feathersjs-ecosystem/feathers-nedb/compare/v5.0.2...v5.1.0) 47 | 48 | **Merged pull requests:** 49 | 50 | - Update all dependencies [\#103](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/103) ([daffl](https://github.com/daffl)) 51 | 52 | ## [v5.0.2](https://github.com/feathersjs-ecosystem/feathers-nedb/tree/v5.0.2) (2019-09-29) 53 | 54 | [Full Changelog](https://github.com/feathersjs-ecosystem/feathers-nedb/compare/v5.0.1...v5.0.2) 55 | 56 | **Closed issues:** 57 | 58 | - $select just '\_id' broken [\#100](https://github.com/feathersjs-ecosystem/feathers-nedb/issues/100) 59 | 60 | **Merged pull requests:** 61 | 62 | - Fix to allow selecting only \_id [\#102](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/102) ([daffl](https://github.com/daffl)) 63 | - Pass entity type to AdapterService\ and update dependencies [\#101](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/101) ([daffl](https://github.com/daffl)) 64 | - Update semistandard to the latest version 🚀 [\#99](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/99) ([greenkeeper[bot]](https://github.com/apps/greenkeeper)) 65 | - Update dtslint to the latest version 🚀 [\#98](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/98) ([greenkeeper[bot]](https://github.com/apps/greenkeeper)) 66 | 67 | ## [v5.0.1](https://github.com/feathersjs-ecosystem/feathers-nedb/tree/v5.0.1) (2019-07-15) 68 | 69 | [Full Changelog](https://github.com/feathersjs-ecosystem/feathers-nedb/compare/v5.0.0...v5.0.1) 70 | 71 | **Merged pull requests:** 72 | 73 | - TS: Fix NeDB import Type [\#97](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/97) ([daffl](https://github.com/daffl)) 74 | 75 | ## [v5.0.0](https://github.com/feathersjs-ecosystem/feathers-nedb/tree/v5.0.0) (2019-07-05) 76 | 77 | [Full Changelog](https://github.com/feathersjs-ecosystem/feathers-nedb/compare/v4.0.2...v5.0.0) 78 | 79 | **Merged pull requests:** 80 | 81 | - Add TypeScript definitions and upgrade tests to Feathers 4 [\#96](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/96) ([daffl](https://github.com/daffl)) 82 | - Add default params for \_ methods [\#95](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/95) ([daffl](https://github.com/daffl)) 83 | - Update mocha to the latest version 🚀 [\#94](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/94) ([greenkeeper[bot]](https://github.com/apps/greenkeeper)) 84 | - Update Readme [\#81](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/81) ([toddgeist](https://github.com/toddgeist)) 85 | 86 | ## [v4.0.2](https://github.com/feathersjs-ecosystem/feathers-nedb/tree/v4.0.2) (2019-06-29) 87 | 88 | [Full Changelog](https://github.com/feathersjs-ecosystem/feathers-nedb/compare/v4.0.1...v4.0.2) 89 | 90 | **Closed issues:** 91 | 92 | - Breaks on 3.1 to 4.0 but nothing in readme to indicate what they are [\#93](https://github.com/feathersjs-ecosystem/feathers-nedb/issues/93) 93 | - upsert option with ID remapping is broken [\#91](https://github.com/feathersjs-ecosystem/feathers-nedb/issues/91) 94 | 95 | ## [v4.0.1](https://github.com/feathersjs-ecosystem/feathers-nedb/tree/v4.0.1) (2019-01-12) 96 | 97 | [Full Changelog](https://github.com/feathersjs-ecosystem/feathers-nedb/compare/v4.0.0...v4.0.1) 98 | 99 | **Merged pull requests:** 100 | 101 | - Update @feathersjs/adapter-commons to the latest version 🚀 [\#92](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/92) ([greenkeeper[bot]](https://github.com/apps/greenkeeper)) 102 | 103 | ## [v4.0.0](https://github.com/feathersjs-ecosystem/feathers-nedb/tree/v4.0.0) (2018-12-17) 104 | 105 | [Full Changelog](https://github.com/feathersjs-ecosystem/feathers-nedb/compare/v3.1.0...v4.0.0) 106 | 107 | **Closed issues:** 108 | 109 | - An in-range update of @feathersjs/socketio is breaking the build 🚨 [\#88](https://github.com/feathersjs-ecosystem/feathers-nedb/issues/88) 110 | 111 | **Merged pull requests:** 112 | 113 | - Update to @feathersjs/adapter-commons and drop Node 6 [\#90](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/90) ([daffl](https://github.com/daffl)) 114 | 115 | ## [v3.1.0](https://github.com/feathersjs-ecosystem/feathers-nedb/tree/v3.1.0) (2018-06-26) 116 | 117 | [Full Changelog](https://github.com/feathersjs-ecosystem/feathers-nedb/compare/v3.0.1...v3.1.0) 118 | 119 | **Merged pull requests:** 120 | 121 | - add getModel method to allow overriding the Model at runtime [\#86](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/86) ([j2L4e](https://github.com/j2L4e)) 122 | - Update shx to the latest version 🚀 [\#85](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/85) ([greenkeeper[bot]](https://github.com/apps/greenkeeper)) 123 | 124 | ## [v3.0.1](https://github.com/feathersjs-ecosystem/feathers-nedb/tree/v3.0.1) (2018-06-03) 125 | 126 | [Full Changelog](https://github.com/feathersjs-ecosystem/feathers-nedb/compare/v3.0.0...v3.0.1) 127 | 128 | **Closed issues:** 129 | 130 | - Cant update nedb record [\#82](https://github.com/feathersjs-ecosystem/feathers-nedb/issues/82) 131 | - Typescript support [\#80](https://github.com/feathersjs-ecosystem/feathers-nedb/issues/80) 132 | 133 | **Merged pull requests:** 134 | 135 | - Update uberproto to the latest version 🚀 [\#84](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/84) ([greenkeeper[bot]](https://github.com/apps/greenkeeper)) 136 | - Increase timeout to fix tests [\#79](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/79) ([daffl](https://github.com/daffl)) 137 | - Update mocha to the latest version 🚀 [\#78](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/78) ([greenkeeper[bot]](https://github.com/apps/greenkeeper)) 138 | - Update semistandard to the latest version 🚀 [\#77](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/77) ([greenkeeper[bot]](https://github.com/apps/greenkeeper)) 139 | 140 | ## [v3.0.0](https://github.com/feathersjs-ecosystem/feathers-nedb/tree/v3.0.0) (2017-12-02) 141 | 142 | [Full Changelog](https://github.com/feathersjs-ecosystem/feathers-nedb/compare/v2.7.0...v3.0.0) 143 | 144 | **Merged pull requests:** 145 | 146 | - Upgrade to Feathers Buzzard \(v3\) [\#76](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/76) ([daffl](https://github.com/daffl)) 147 | - Update to new plugin infrastructure [\#75](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/75) ([daffl](https://github.com/daffl)) 148 | - Update mocha to the latest version 🚀 [\#74](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/74) ([greenkeeper[bot]](https://github.com/apps/greenkeeper)) 149 | 150 | ## [v2.7.0](https://github.com/feathersjs-ecosystem/feathers-nedb/tree/v2.7.0) (2017-08-17) 151 | 152 | [Full Changelog](https://github.com/feathersjs-ecosystem/feathers-nedb/compare/v2.6.2...v2.7.0) 153 | 154 | **Closed issues:** 155 | 156 | - An in-range update of feathers-errors is breaking the build 🚨 [\#68](https://github.com/feathersjs-ecosystem/feathers-nedb/issues/68) 157 | - Can't use $select without including id field [\#66](https://github.com/feathersjs-ecosystem/feathers-nedb/issues/66) 158 | - Support special operators in PATCH [\#65](https://github.com/feathersjs-ecosystem/feathers-nedb/issues/65) 159 | 160 | **Merged pull requests:** 161 | 162 | - Test and fix for excluding id field if it is not selected [\#73](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/73) ([daffl](https://github.com/daffl)) 163 | - Fix and tests for patch to allow NeDB modifiers [\#72](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/72) ([daffl](https://github.com/daffl)) 164 | - Fixing broken docs links [\#71](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/71) ([corymsmith](https://github.com/corymsmith)) 165 | - fix import of feathers-nedb in README.md example [\#70](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/70) ([arve0](https://github.com/arve0)) 166 | - update links to current documentation [\#69](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/69) ([arve0](https://github.com/arve0)) 167 | - Update chai to the latest version 🚀 [\#67](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/67) ([greenkeeper[bot]](https://github.com/apps/greenkeeper)) 168 | - Update feathers-socketio to the latest version 🚀 [\#64](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/64) ([greenkeeper[bot]](https://github.com/apps/greenkeeper)) 169 | - Update feathers-service-tests to the latest version 🚀 [\#63](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/63) ([greenkeeper[bot]](https://github.com/apps/greenkeeper)) 170 | - Update semistandard to the latest version 🚀 [\#62](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/62) ([greenkeeper[bot]](https://github.com/apps/greenkeeper)) 171 | - Update dependencies to enable Greenkeeper 🌴 [\#61](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/61) ([greenkeeper[bot]](https://github.com/apps/greenkeeper)) 172 | 173 | ## [v2.6.2](https://github.com/feathersjs-ecosystem/feathers-nedb/tree/v2.6.2) (2017-03-26) 174 | 175 | [Full Changelog](https://github.com/feathersjs-ecosystem/feathers-nedb/compare/v2.6.1...v2.6.2) 176 | 177 | **Closed issues:** 178 | 179 | - Can't use modifiers in update method after upgrade to 2.6.1 [\#59](https://github.com/feathersjs-ecosystem/feathers-nedb/issues/59) 180 | 181 | **Merged pull requests:** 182 | 183 | - Allow NeDB modifiers but keep upsert compatibility [\#60](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/60) ([daffl](https://github.com/daffl)) 184 | 185 | ## [v2.6.1](https://github.com/feathersjs-ecosystem/feathers-nedb/tree/v2.6.1) (2017-02-22) 186 | 187 | [Full Changelog](https://github.com/feathersjs-ecosystem/feathers-nedb/compare/v2.6.0...v2.6.1) 188 | 189 | **Closed issues:** 190 | 191 | - Upsert options not working [\#57](https://github.com/feathersjs-ecosystem/feathers-nedb/issues/57) 192 | - Switch to using NeDB-core [\#56](https://github.com/feathersjs-ecosystem/feathers-nedb/issues/56) 193 | - Does feathers-nedb use compactDatafile ? [\#55](https://github.com/feathersjs-ecosystem/feathers-nedb/issues/55) 194 | - service.remove\(null\) does not remove all items [\#54](https://github.com/feathersjs-ecosystem/feathers-nedb/issues/54) 195 | 196 | **Merged pull requests:** 197 | 198 | - Allow params.nedb upsert [\#58](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/58) ([daffl](https://github.com/daffl)) 199 | 200 | ## [v2.6.0](https://github.com/feathersjs-ecosystem/feathers-nedb/tree/v2.6.0) (2016-11-12) 201 | 202 | [Full Changelog](https://github.com/feathersjs-ecosystem/feathers-nedb/compare/v2.5.1...v2.6.0) 203 | 204 | **Closed issues:** 205 | 206 | - Support $select for gets [\#44](https://github.com/feathersjs-ecosystem/feathers-nedb/issues/44) 207 | 208 | **Merged pull requests:** 209 | 210 | - Update feathers-service-tests to version 0.9.0 🚀 [\#52](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/52) ([greenkeeperio-bot](https://github.com/greenkeeperio-bot)) 211 | - babel-preset-es2015@6.18.0 breaks build ⚠️ [\#51](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/51) ([greenkeeperio-bot](https://github.com/greenkeeperio-bot)) 212 | - jshint —\> semistandard [\#48](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/48) ([corymsmith](https://github.com/corymsmith)) 213 | - jshint@2.9.4 breaks build 🚨 [\#47](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/47) ([greenkeeperio-bot](https://github.com/greenkeeperio-bot)) 214 | - Update code coverage settings [\#46](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/46) ([daffl](https://github.com/daffl)) 215 | - adding code coverage reporting [\#45](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/45) ([ekryski](https://github.com/ekryski)) 216 | 217 | ## [v2.5.1](https://github.com/feathersjs-ecosystem/feathers-nedb/tree/v2.5.1) (2016-09-21) 218 | 219 | [Full Changelog](https://github.com/feathersjs-ecosystem/feathers-nedb/compare/v2.5.0...v2.5.1) 220 | 221 | **Closed issues:** 222 | 223 | - patch\(\) method doesn't call 'patched' event handler. [\#39](https://github.com/feathersjs-ecosystem/feathers-nedb/issues/39) 224 | 225 | **Merged pull requests:** 226 | 227 | - Patch and create multiple [\#40](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/40) ([greenkeeperio-bot](https://github.com/greenkeeperio-bot)) 228 | 229 | ## [v2.5.0](https://github.com/feathersjs-ecosystem/feathers-nedb/tree/v2.5.0) (2016-09-12) 230 | 231 | [Full Changelog](https://github.com/feathersjs-ecosystem/feathers-nedb/compare/v2.4.1...v2.5.0) 232 | 233 | **Closed issues:** 234 | 235 | - Patch duplicates records [\#35](https://github.com/feathersjs-ecosystem/feathers-nedb/issues/35) 236 | 237 | **Merged pull requests:** 238 | 239 | - chore\(package\): update mocha to version 3.0.1 [\#38](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/38) ([daffl](https://github.com/daffl)) 240 | - Update service tests, id and events option [\#37](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/37) ([greenkeeperio-bot](https://github.com/greenkeeperio-bot)) 241 | - Update mocha to version 3.0.0 🚀 [\#34](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/34) ([greenkeeperio-bot](https://github.com/greenkeeperio-bot)) 242 | 243 | ## [v2.4.1](https://github.com/feathersjs-ecosystem/feathers-nedb/tree/v2.4.1) (2016-07-21) 244 | 245 | [Full Changelog](https://github.com/feathersjs-ecosystem/feathers-nedb/compare/v2.4.0...v2.4.1) 246 | 247 | **Closed issues:** 248 | 249 | - Get $not support working. [\#6](https://github.com/feathersjs-ecosystem/feathers-nedb/issues/6) 250 | 251 | **Merged pull requests:** 252 | 253 | - Update async to version 2.0.0 🚀 [\#33](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/33) ([greenkeeperio-bot](https://github.com/greenkeeperio-bot)) 254 | - Update feathers-query-filters to version 2.0.0 🚀 [\#32](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/32) ([greenkeeperio-bot](https://github.com/greenkeeperio-bot)) 255 | - feathers-service-tests@0.6.2 breaks build 🚨 [\#31](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/31) ([greenkeeperio-bot](https://github.com/greenkeeperio-bot)) 256 | 257 | ## [v2.4.0](https://github.com/feathersjs-ecosystem/feathers-nedb/tree/v2.4.0) (2016-07-08) 258 | 259 | [Full Changelog](https://github.com/feathersjs-ecosystem/feathers-nedb/compare/v2.3.0...v2.4.0) 260 | 261 | **Closed issues:** 262 | 263 | - Update and patch manipulate data object [\#29](https://github.com/feathersjs-ecosystem/feathers-nedb/issues/29) 264 | 265 | **Merged pull requests:** 266 | 267 | - feathers-service-tests@0.6.1 breaks build 🚨 [\#30](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/30) ([greenkeeperio-bot](https://github.com/greenkeeperio-bot)) 268 | 269 | ## [v2.3.0](https://github.com/feathersjs-ecosystem/feathers-nedb/tree/v2.3.0) (2016-06-17) 270 | 271 | [Full Changelog](https://github.com/feathersjs-ecosystem/feathers-nedb/compare/v2.2.3...v2.3.0) 272 | 273 | **Closed issues:** 274 | 275 | - Support $search [\#13](https://github.com/feathersjs-ecosystem/feathers-nedb/issues/13) 276 | 277 | **Merged pull requests:** 278 | 279 | - Update feathers-service-tests to version 0.6.0 🚀 [\#28](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/28) ([greenkeeperio-bot](https://github.com/greenkeeperio-bot)) 280 | - mocha@2.5.0 breaks build 🚨 [\#27](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/27) ([greenkeeperio-bot](https://github.com/greenkeeperio-bot)) 281 | - Update babel-plugin-add-module-exports to version 0.2.0 🚀 [\#26](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/26) ([greenkeeperio-bot](https://github.com/greenkeeperio-bot)) 282 | - babel-cli@6.8.0 breaks build 🚨 [\#25](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/25) ([greenkeeperio-bot](https://github.com/greenkeeperio-bot)) 283 | - feathers-rest@1.3.0 breaks build 🚨 [\#23](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/23) ([greenkeeperio-bot](https://github.com/greenkeeperio-bot)) 284 | - nsp@2.3.2 breaks build 🚨 [\#22](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/22) ([greenkeeperio-bot](https://github.com/greenkeeperio-bot)) 285 | - fix errors in update and patch with custom id [\#20](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/20) ([farwayer](https://github.com/farwayer)) 286 | 287 | ## [v2.2.3](https://github.com/feathersjs-ecosystem/feathers-nedb/tree/v2.2.3) (2016-04-02) 288 | 289 | [Full Changelog](https://github.com/feathersjs-ecosystem/feathers-nedb/compare/v2.2.2...v2.2.3) 290 | 291 | **Closed issues:** 292 | 293 | - Support Hooks on Initialization [\#18](https://github.com/feathersjs-ecosystem/feathers-nedb/issues/18) 294 | 295 | **Merged pull requests:** 296 | 297 | - Custom id in multiOptions [\#19](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/19) ([farwayer](https://github.com/farwayer)) 298 | 299 | ## [v2.2.2](https://github.com/feathersjs-ecosystem/feathers-nedb/tree/v2.2.2) (2016-02-24) 300 | 301 | [Full Changelog](https://github.com/feathersjs-ecosystem/feathers-nedb/compare/v2.2.1...v2.2.2) 302 | 303 | **Merged pull requests:** 304 | 305 | - bumping feathers errors version [\#17](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/17) ([ekryski](https://github.com/ekryski)) 306 | 307 | ## [v2.2.1](https://github.com/feathersjs-ecosystem/feathers-nedb/tree/v2.2.1) (2016-02-22) 308 | 309 | [Full Changelog](https://github.com/feathersjs-ecosystem/feathers-nedb/compare/v2.2.0...v2.2.1) 310 | 311 | **Merged pull requests:** 312 | 313 | - Example update [\#16](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/16) ([ekryski](https://github.com/ekryski)) 314 | 315 | ## [v2.2.0](https://github.com/feathersjs-ecosystem/feathers-nedb/tree/v2.2.0) (2016-02-21) 316 | 317 | [Full Changelog](https://github.com/feathersjs-ecosystem/feathers-nedb/compare/v2.1.0...v2.2.0) 318 | 319 | **Closed issues:** 320 | 321 | - Should support options.id attribute [\#14](https://github.com/feathersjs-ecosystem/feathers-nedb/issues/14) 322 | 323 | **Merged pull requests:** 324 | 325 | - adding back the options.id field. Closes \#14. [\#15](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/15) ([ekryski](https://github.com/ekryski)) 326 | 327 | ## [v2.1.0](https://github.com/feathersjs-ecosystem/feathers-nedb/tree/v2.1.0) (2016-01-31) 328 | 329 | [Full Changelog](https://github.com/feathersjs-ecosystem/feathers-nedb/compare/v2.0.3...v2.1.0) 330 | 331 | **Merged pull requests:** 332 | 333 | - Use internal methods instead of service methods directly [\#12](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/12) ([daffl](https://github.com/daffl)) 334 | 335 | ## [v2.0.3](https://github.com/feathersjs-ecosystem/feathers-nedb/tree/v2.0.3) (2016-01-23) 336 | 337 | [Full Changelog](https://github.com/feathersjs-ecosystem/feathers-nedb/compare/v2.0.2...v2.0.3) 338 | 339 | **Closed issues:** 340 | 341 | - id mapping does not work? [\#11](https://github.com/feathersjs-ecosystem/feathers-nedb/issues/11) 342 | - Updating documents [\#5](https://github.com/feathersjs-ecosystem/feathers-nedb/issues/5) 343 | 344 | ## [v2.0.2](https://github.com/feathersjs-ecosystem/feathers-nedb/tree/v2.0.2) (2016-01-22) 345 | 346 | [Full Changelog](https://github.com/feathersjs-ecosystem/feathers-nedb/compare/v2.0.1...v2.0.2) 347 | 348 | **Merged pull requests:** 349 | 350 | - Adding nsp check [\#10](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/10) ([marshallswain](https://github.com/marshallswain)) 351 | 352 | ## [v2.0.1](https://github.com/feathersjs-ecosystem/feathers-nedb/tree/v2.0.1) (2016-01-12) 353 | 354 | [Full Changelog](https://github.com/feathersjs-ecosystem/feathers-nedb/compare/v2.0.0...v2.0.1) 355 | 356 | **Closed issues:** 357 | 358 | - NeDB ids are not sequential but ordered alphabetically by default [\#9](https://github.com/feathersjs-ecosystem/feathers-nedb/issues/9) 359 | 360 | ## [v2.0.0](https://github.com/feathersjs-ecosystem/feathers-nedb/tree/v2.0.0) (2016-01-06) 361 | 362 | [Full Changelog](https://github.com/feathersjs-ecosystem/feathers-nedb/compare/v1.2.0...v2.0.0) 363 | 364 | **Closed issues:** 365 | 366 | - how to add validation to nedb? [\#7](https://github.com/feathersjs-ecosystem/feathers-nedb/issues/7) 367 | 368 | **Merged pull requests:** 369 | 370 | - Migration to new service tests and ES6 [\#8](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/8) ([daffl](https://github.com/daffl)) 371 | - Migrating to shared feathers-service-tests suite [\#4](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/4) ([daffl](https://github.com/daffl)) 372 | 373 | ## [v1.2.0](https://github.com/feathersjs-ecosystem/feathers-nedb/tree/v1.2.0) (2015-11-08) 374 | 375 | [Full Changelog](https://github.com/feathersjs-ecosystem/feathers-nedb/compare/v1.0.1...v1.2.0) 376 | 377 | ## [v1.0.1](https://github.com/feathersjs-ecosystem/feathers-nedb/tree/v1.0.1) (2015-10-25) 378 | 379 | [Full Changelog](https://github.com/feathersjs-ecosystem/feathers-nedb/compare/v1.0.0...v1.0.1) 380 | 381 | ## [v1.0.0](https://github.com/feathersjs-ecosystem/feathers-nedb/tree/v1.0.0) (2015-07-27) 382 | 383 | [Full Changelog](https://github.com/feathersjs-ecosystem/feathers-nedb/compare/v0.1.1...v1.0.0) 384 | 385 | ## [v0.1.1](https://github.com/feathersjs-ecosystem/feathers-nedb/tree/v0.1.1) (2015-07-27) 386 | 387 | [Full Changelog](https://github.com/feathersjs-ecosystem/feathers-nedb/compare/v0.1.0...v0.1.1) 388 | 389 | **Closed issues:** 390 | 391 | - Setup Travis CI [\#2](https://github.com/feathersjs-ecosystem/feathers-nedb/issues/2) 392 | - Use common initialization for database adapters [\#1](https://github.com/feathersjs-ecosystem/feathers-nedb/issues/1) 393 | 394 | **Merged pull requests:** 395 | 396 | - Plugin consistency [\#3](https://github.com/feathersjs-ecosystem/feathers-nedb/pull/3) ([ekryski](https://github.com/ekryski)) 397 | 398 | ## [v0.1.0](https://github.com/feathersjs-ecosystem/feathers-nedb/tree/v0.1.0) (2015-07-07) 399 | 400 | [Full Changelog](https://github.com/feathersjs-ecosystem/feathers-nedb/compare/15c2365facb62c5ff9d631778fd89dcbe2bd63b3...v0.1.0) 401 | 402 | 403 | 404 | \* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)* 405 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2021 FeathersJS 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # feathers-nedb 2 | 3 | [![Download Status](https://img.shields.io/npm/dm/feathers-nedb.svg?style=flat-square)](https://www.npmjs.com/package/feathers-nedb) 4 | 5 | [feathers-nedb](https://github.com/feathersjs-ecosystem/feathers-nedb/) is a database service adapter for [NeDB](https://github.com/seald/nedb), an embedded datastore with a [MongoDB](https://www.mongodb.org/) like API. NeDB can store data in-memory or on the filesystem which makes it useful as a persistent storage without a separate database server. 6 | 7 | ```bash 8 | $ npm install --save @seald-io/nedb feathers-nedb 9 | ``` 10 | 11 | > **Important:** `feathers-nedb` implements the [Feathers Common database adapter API](https://docs.feathersjs.com/api/databases/common.html) and [querying syntax](https://docs.feathersjs.com/api/databases/querying.html). 12 | 13 | ## API 14 | 15 | ### `service(options)` 16 | 17 | Returns a new service instance initialized with the given options. `Model` has to be an NeDB database instance. 18 | 19 | ```js 20 | const NeDB = require("@seald-io/nedb"); 21 | const service = require("feathers-nedb"); 22 | 23 | // Create a NeDB instance 24 | const Model = new NeDB({ 25 | filename: "./data/messages.db", 26 | autoload: true, 27 | }); 28 | 29 | app.use("/messages", service({ Model })); 30 | app.use("/messages", service({ Model, id, events, paginate })); 31 | ``` 32 | 33 | **Options:** 34 | 35 | - `Model` (**required**) - The NeDB database instance. See the [NeDB API](https://github.com/seald/nedb#documentation) for more information. 36 | - `id` (_optional_, default: `'_id'`) - The name of the id field property. By design, NeDB will always add an `_id` property. 37 | - `events` (_optional_) - A list of [custom service events](https://docs.feathersjs.com/api/events.html#custom-events) sent by this service 38 | - `paginate` (_optional_) - A [pagination object](https://docs.feathersjs.com/api/databases/common.html#pagination) containing a `default` and `max` page size 39 | - `whitelist` (_optional_) - A list of additional query parameters to allow (e.g. `[ '$regex' ]`) 40 | - `multi` (_optional_) - Allow `create` with arrays and `update` and `remove` with `id` null to change multiple items. Can be `true` for all methods or an array of multi methods (e.g. `[ 'remove', 'create' ]`) 41 | 42 | ### params.nedb 43 | 44 | When making a [service method](https://docs.feathersjs.com/api/services.html) call, `params` can contain an `nedb` property which allows to pass additional [NeDB options](https://github.com/seald/nedb#updating-documents), for example to allow `upsert`: 45 | 46 | ```js 47 | app.service("messages").update( 48 | "someid", 49 | { 50 | text: "This message will be either created or updated", 51 | }, 52 | { 53 | nedb: { upsert: true }, 54 | } 55 | ); 56 | ``` 57 | 58 | ### use of params on client 59 | 60 | On client you can't pass anything other than a query as the parameter. So you need to do it like this. 61 | 62 | ```js 63 | // client side 64 | app.service("messages").update( 65 | "someid", 66 | { 67 | text: "This message will be either created or updated", 68 | }, 69 | { 70 | query: { nedb: { upsert: true } }, 71 | } 72 | ); 73 | ``` 74 | 75 | then add a hook to the service to move the nedb options to the params object 76 | 77 | ```js 78 | (ctx) => { 79 | const nedb = ctx.params.query.nedb; 80 | if (nedb) { 81 | ctx.params.nedb = nedb; 82 | delete ctx.params.query.nedb; 83 | } 84 | return ctx; 85 | }; 86 | ``` 87 | 88 | ## Example 89 | 90 | Here is an example of a Feathers server with a `messages` NeDB service that supports pagination and persists to `db-data/messages`: 91 | 92 | ``` 93 | $ npm install @feathersjs/feathers @feathersjs/errors @feathersjs/express @feathersjs/socketio feathers-nedb nedb 94 | ``` 95 | 96 | In `app.js`: 97 | 98 | ```js 99 | const feathers = require("@feathersjs/feathers"); 100 | const express = require("@feathersjs/express"); 101 | const socketio = require("@feathersjs/socketio"); 102 | 103 | const NeDB = require("@seald-io/nedb"); 104 | const service = require("feathers-nedb"); 105 | 106 | const db = new NeDB({ 107 | filename: "./db-data/messages", 108 | autoload: true, 109 | }); 110 | 111 | // Create an Express compatible Feathers application instance. 112 | const app = express(feathers()); 113 | // Turn on JSON parser for REST services 114 | app.use(express.json()); 115 | // Turn on URL-encoded parser for REST services 116 | app.use(express.urlencoded({ extended: true })); 117 | // Enable REST services 118 | app.configure(express.rest()); 119 | // Enable Socket.io services 120 | app.configure(socketio()); 121 | // Connect to the db, create and register a Feathers service. 122 | app.use( 123 | "/messages", 124 | service({ 125 | Model: db, 126 | paginate: { 127 | default: 2, 128 | max: 4, 129 | }, 130 | }) 131 | ); 132 | // Set up default error handler 133 | app.use(express.errorHandler()); 134 | 135 | // Create a dummy Message 136 | app 137 | .service("messages") 138 | .create({ 139 | text: "Message created on server", 140 | }) 141 | .then((message) => console.log("Created message", message)); 142 | 143 | // Start the server. 144 | const port = 3030; 145 | 146 | app.listen(port, () => { 147 | console.log(`Feathers server listening on port ${port}`); 148 | }); 149 | ``` 150 | 151 | Run the example with `node app` and go to [localhost:3030/messages](http://localhost:3030/messages). 152 | 153 | ## License 154 | 155 | Copyright (c) 2019 156 | 157 | Licensed under the [MIT license](LICENSE). 158 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "feathers-nedb", 3 | "description": "Feathers NeDB Service", 4 | "version": "7.0.1", 5 | "homepage": "https://github.com/feathersjs-ecosystem/feathers-nedb", 6 | "main": "lib/", 7 | "repository": { 8 | "type": "git", 9 | "url": "https://github.com/feathersjs-ecosystem/feathers-nedb.git" 10 | }, 11 | "bugs": { 12 | "url": "https://github.com/feathersjs-ecosystem/feathers-nedb/issues" 13 | }, 14 | "license": "MIT", 15 | "keywords": [ 16 | "feathers", 17 | "feathers-plugin", 18 | "REST", 19 | "Socket.io", 20 | "realtime", 21 | "nedb", 22 | "service" 23 | ], 24 | "files": [ 25 | "CHANGELOG.md", 26 | "LICENSE", 27 | "README.md", 28 | "lib/**", 29 | "src/**", 30 | "*.d.ts", 31 | "*.js" 32 | ], 33 | "author": "Feathers (http://feathersjs.com)", 34 | "contributors": [ 35 | "Marshall Thompson (https://github.com/marshallswain)", 36 | "Eric Kryski (http://erickryski.com)", 37 | "David Luecke (http://neyeon.com)" 38 | ], 39 | "scripts": { 40 | "publish": "git push origin --tags && npm run changelog && git push origin", 41 | "changelog": "github_changelog_generator -u feathersjs-ecosystem -p feathers-nedb && git add CHANGELOG.md && git commit -am \"Updating changelog\"", 42 | "release:patch": "npm version patch && npm publish", 43 | "release:minor": "npm version minor && npm publish", 44 | "release:major": "npm version major && npm publish", 45 | "update-dependencies": "ncu -u", 46 | "compile": "shx rm -rf lib/ && tsc", 47 | "test": "shx rm -rf db-data/ && mocha --recursive test/**.test.ts test/**/*.test.ts" 48 | }, 49 | "semistandard": { 50 | "env": [ 51 | "mocha" 52 | ] 53 | }, 54 | "engines": { 55 | "node": ">= 16" 56 | }, 57 | "dependencies": { 58 | "@feathersjs/adapter-commons": "^5.0.11", 59 | "@feathersjs/commons": "^5.0.11", 60 | "@feathersjs/errors": "^5.0.11" 61 | }, 62 | "peerDependencies": { 63 | "@seald-io/nedb": "^4.0.2" 64 | }, 65 | "devDependencies": { 66 | "@feathersjs/adapter-tests": "^5.0.11", 67 | "@feathersjs/express": "^5.0.11", 68 | "@feathersjs/feathers": "^5.0.11", 69 | "@feathersjs/socketio": "^5.0.11", 70 | "body-parser": "^1.20.0", 71 | "@types/mocha": "^10.0.2", 72 | "mocha": "^10.2.0", 73 | "npm-check-updates": "^16.0.6", 74 | "shx": "^0.3.4", 75 | "ts-node": "^10.9.1", 76 | "typescript": "^5.2.2" 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/adapter.ts: -------------------------------------------------------------------------------- 1 | import { 2 | AdapterBase, 3 | AdapterParams, 4 | AdapterQuery, 5 | AdapterServiceOptions, 6 | PaginationOptions, 7 | getLimit, 8 | select, 9 | } from "@feathersjs/adapter-commons"; 10 | import { _ } from "@feathersjs/commons"; 11 | import { BadRequest, MethodNotAllowed, NotFound } from "@feathersjs/errors"; 12 | import { Id, NullableId, Paginated } from "@feathersjs/feathers"; 13 | import NeDB from "@seald-io/nedb"; 14 | import crypto from "crypto"; 15 | 16 | function errorHandler(error: Error): any { 17 | throw error; 18 | } 19 | 20 | export interface NeDBAdapterOptions extends AdapterServiceOptions { 21 | Model: NeDB; 22 | } 23 | 24 | export interface NeDBAdapterParams 25 | extends AdapterParams> { 26 | nedb?: { upsert: boolean }; 27 | } 28 | 29 | export class NeDbAdapter< 30 | Result extends Record, 31 | Data extends Record = Partial, 32 | ServiceParams extends NeDBAdapterParams = NeDBAdapterParams, 33 | PatchData = Partial 34 | > extends AdapterBase< 35 | Result, 36 | Data, 37 | PatchData, 38 | ServiceParams, 39 | NeDBAdapterOptions 40 | > { 41 | constructor(options: NeDBAdapterOptions) { 42 | if (!options || !options.Model) { 43 | throw new Error("NeDB datastore `Model` needs to be provided"); 44 | } 45 | super({ 46 | id: "_id", 47 | ...options, 48 | }); 49 | } 50 | 51 | getSelect(select: string[]) { 52 | if (Array.isArray(select)) { 53 | const result: any = { [this.id]: 1 }; 54 | select.forEach((name) => (result[name] = 1)); 55 | return result; 56 | } 57 | return select; 58 | } 59 | 60 | filterQuery(id: NullableId, params: ServiceParams) { 61 | const options = this.getOptions(params); 62 | const { 63 | $select, 64 | $sort, 65 | $limit: _limit, 66 | $skip = 0, 67 | ...query 68 | } = (params.query || {}) as AdapterQuery; 69 | const $limit = getLimit(_limit, options.paginate); 70 | if (id !== null) { 71 | query.$and = (query.$and || []).concat({ 72 | [this.id]: id, 73 | }); 74 | } 75 | 76 | return { 77 | filters: { $select, $sort, $limit, $skip }, 78 | query, 79 | }; 80 | } 81 | 82 | async _findOrGet(id: NullableId, params: ServiceParams) { 83 | return id === null ? await this._find(params) : await this._get(id, params); 84 | } 85 | 86 | normalizeId(id: NullableId, data: D): D { 87 | if (id !== null) { 88 | // If not using the default Mongo _id field set the ID to its 89 | // previous value. This prevents orphaned documents. 90 | return { 91 | ...data, 92 | [this.id]: id, 93 | }; 94 | } 95 | return data; 96 | } 97 | 98 | async _find( 99 | params?: ServiceParams & { paginate?: PaginationOptions } 100 | ): Promise>; 101 | async _find(params?: ServiceParams & { paginate: false }): Promise; 102 | async _find(params?: ServiceParams): Promise | Result[]>; 103 | async _find( 104 | params: ServiceParams = {} as ServiceParams 105 | ): Promise | Result[]> { 106 | const { Model, paginate } = this.getOptions(params); 107 | const { 108 | filters: { $select, $sort, $limit, $skip }, 109 | query, 110 | } = this.filterQuery(null, params); 111 | 112 | const countDocuments = async () => { 113 | if (paginate && paginate.default) { 114 | return await Model.countAsync(query); 115 | } 116 | return Promise.resolve(0); 117 | }; 118 | 119 | const q = $select 120 | ? Model.findAsync(query, this.getSelect($select)) 121 | : Model.findAsync(query); 122 | 123 | // Handle $sort 124 | if ($sort) { 125 | q.sort($sort); 126 | } 127 | // Handle $limit 128 | if ($limit) { 129 | q.limit($limit); 130 | } 131 | if ($skip) { 132 | q.skip($skip); 133 | } 134 | 135 | const [request, total] = await Promise.all([q, countDocuments()]); 136 | 137 | const page = { 138 | total, 139 | limit: $limit, 140 | skip: $skip || 0, 141 | data: $limit === 0 ? [] : ((await request) as any as Result[]), 142 | }; 143 | 144 | return paginate && paginate.default ? page : page.data; 145 | } 146 | 147 | _get( 148 | id: NullableId, 149 | params: ServiceParams = {} as ServiceParams 150 | ): Promise { 151 | const { Model } = this.getOptions(params); 152 | const { 153 | query, 154 | filters: { $select }, 155 | } = this.filterQuery(id, params); 156 | 157 | return $select 158 | ? Model.findOneAsync(query, this.getSelect($select)) 159 | : Model.findOneAsync(query) 160 | .then((data) => { 161 | if (data == null) { 162 | throw new NotFound(`No record found for id '${id}'`); 163 | } 164 | return data; 165 | }) 166 | .catch(errorHandler); 167 | } 168 | 169 | async _create(data: Data, params?: ServiceParams): Promise; 170 | async _create(data: Data[], params?: ServiceParams): Promise; 171 | async _create( 172 | data: Data | Data[], 173 | _params?: ServiceParams 174 | ): Promise; 175 | async _create( 176 | _data: Data | Data[], 177 | params: ServiceParams = {} as ServiceParams 178 | ): Promise { 179 | if (Array.isArray(_data) && !this.allowsMulti("create", params)) { 180 | throw new MethodNotAllowed("Can not create multiple entries"); 181 | } 182 | 183 | const { Model } = this.getOptions(params); 184 | 185 | const addId = (item: Data) => { 186 | if (this.id !== "_id" && item[this.id] === undefined) { 187 | return Object.assign( 188 | { 189 | [this.id]: crypto.randomBytes(8).toString("hex"), 190 | }, 191 | item 192 | ); 193 | } 194 | return item; 195 | }; 196 | 197 | const data = Array.isArray(_data) ? _data.map(addId) : addId(_data); 198 | 199 | //@ts-ignore 200 | return Model.insertAsync(data) 201 | .then(select(params, this.id)) 202 | .catch(errorHandler); 203 | } 204 | 205 | async _update( 206 | id: Id, 207 | data: Data, 208 | params: ServiceParams = {} as ServiceParams 209 | ): Promise { 210 | if (id === null || Array.isArray(data)) { 211 | throw new BadRequest( 212 | "You can not replace multiple instances. Did you mean 'patch'?" 213 | ); 214 | } 215 | 216 | const { Model } = this.getOptions(params); 217 | const { query } = this.filterQuery(id, params); 218 | 219 | const entry = _.omit(data, "_id"); 220 | 221 | if (this.id !== "_id" || (params.nedb && params.nedb.upsert)) { 222 | entry[this.id] = id; 223 | } 224 | 225 | const response = await Model.updateAsync(query, entry, { 226 | returnUpdatedDocs: true, 227 | multi: false, 228 | ...params.nedb, 229 | }); 230 | 231 | if (response.affectedDocuments == null) { 232 | throw new NotFound(`No record found for id '${id}'`); 233 | } 234 | 235 | if (Array.isArray(response.affectedDocuments)) { 236 | return response.affectedDocuments[0]; 237 | } 238 | 239 | return select(params, this.id)(response.affectedDocuments); 240 | } 241 | 242 | async _patch( 243 | id: null, 244 | data: PatchData | Partial, 245 | params?: ServiceParams 246 | ): Promise; 247 | async _patch( 248 | id: Id, 249 | data: PatchData | Partial, 250 | params?: ServiceParams 251 | ): Promise; 252 | async _patch( 253 | id: NullableId, 254 | data: PatchData | Partial, 255 | _params?: ServiceParams 256 | ): Promise; 257 | async _patch( 258 | id: NullableId, 259 | data: PatchData | Partial, 260 | params: ServiceParams = {} as ServiceParams 261 | ): Promise { 262 | if (id === null && !this.allowsMulti("patch", params)) { 263 | throw new MethodNotAllowed("Can not patch multiple entries"); 264 | } 265 | const { Model } = this.getOptions(params); 266 | 267 | const { 268 | query, 269 | filters: { $select, $sort, $limit, $skip }, 270 | } = this.filterQuery(id, params); 271 | 272 | const updateOptions = { 273 | returnUpdatedDocs: true, 274 | multi: id == null ? true : false, 275 | }; 276 | 277 | //@ts-ignore 278 | const updateData = Object.keys(data).reduce( 279 | (result: any, key: any) => { 280 | if (key.indexOf("$") === 0) { 281 | //@ts-ignore 282 | result[key] = data[key]; 283 | } else if (key !== "_id" && key !== this.id) { 284 | //@ts-ignore 285 | result.$set[key] = data[key]; 286 | } 287 | return result; 288 | }, 289 | { $set: {} } 290 | ); 291 | 292 | const response = await Model.updateAsync( 293 | query, 294 | updateData, 295 | updateOptions 296 | ); 297 | 298 | if (response.affectedDocuments == null) { 299 | throw new NotFound(`No record found for id '${id}'`); 300 | } 301 | 302 | return select(params, this.id)(response.affectedDocuments); 303 | } 304 | 305 | async _remove(id: null, params?: ServiceParams): Promise; 306 | async _remove(id: Id, params?: ServiceParams): Promise; 307 | async _remove( 308 | id: NullableId, 309 | _params?: ServiceParams 310 | ): Promise; 311 | async _remove( 312 | id: NullableId, 313 | params: ServiceParams = {} as ServiceParams 314 | ): Promise { 315 | if (id === null && !this.allowsMulti("remove", params)) { 316 | throw new MethodNotAllowed("Can not remove multiple entries"); 317 | } 318 | 319 | const { Model } = this.getOptions(params); 320 | const { 321 | query, 322 | filters: { $select }, 323 | } = this.filterQuery(id, params); 324 | 325 | const deleteOptions = { 326 | multi: id == null ? true : false, 327 | }; 328 | 329 | const findParams = { 330 | ...params, 331 | paginate: false, 332 | query: { 333 | ...query, 334 | $select, 335 | }, 336 | }; 337 | 338 | return this._findOrGet(id, findParams) 339 | .then(async (items) => { 340 | await Model.removeAsync(query, deleteOptions); 341 | return items; 342 | }) 343 | .catch(errorHandler); 344 | } 345 | } 346 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Id, 3 | NullableId, 4 | Paginated, 5 | PaginationOptions, 6 | Params, 7 | } from "@feathersjs/feathers"; 8 | import { NeDBAdapterParams, NeDbAdapter } from "./adapter"; 9 | 10 | export class NeDBService< 11 | Result extends Record = any, 12 | Data extends Record = Partial, 13 | ServiceParams extends Params = NeDBAdapterParams, 14 | PatchData = Partial 15 | > extends NeDbAdapter { 16 | async find( 17 | params?: ServiceParams & { paginate?: PaginationOptions } 18 | ): Promise>; 19 | async find(params?: ServiceParams & { paginate: false }): Promise; 20 | async find(params?: ServiceParams): Promise | Result[]>; 21 | async find(params?: ServiceParams): Promise | Result[]> { 22 | if (params) { 23 | params.query = await this.sanitizeQuery(params); 24 | } 25 | 26 | return this._find(params); 27 | } 28 | 29 | async get(id: Id, params?: ServiceParams): Promise { 30 | if (params) { 31 | params.query = await this.sanitizeQuery(params); 32 | } 33 | return this._get(id, params); 34 | } 35 | 36 | async create(data: Data, params?: ServiceParams): Promise; 37 | async create(data: Data[], params?: ServiceParams): Promise; 38 | async create( 39 | data: Data | Data[], 40 | params?: ServiceParams 41 | ): Promise; 42 | async create( 43 | data: Data | Data[], 44 | params?: ServiceParams 45 | ): Promise { 46 | return this._create(data, params); 47 | } 48 | 49 | async update(id: Id, data: Data, params?: ServiceParams): Promise { 50 | if (params) { 51 | params.query = await this.sanitizeQuery(params); 52 | } 53 | return this._update(id, data, params); 54 | } 55 | 56 | async patch( 57 | id: null, 58 | data: PatchData, 59 | params?: ServiceParams 60 | ): Promise; 61 | async patch(id: Id, data: PatchData, params?: ServiceParams): Promise; 62 | async patch( 63 | id: NullableId, 64 | data: PatchData, 65 | params?: ServiceParams 66 | ): Promise; 67 | async patch( 68 | id: NullableId, 69 | data: PatchData, 70 | params?: ServiceParams 71 | ): Promise { 72 | if (params) { 73 | const { $limit, ...query } = await this.sanitizeQuery(params); 74 | params.query = query; 75 | } 76 | 77 | return this._patch(id, data, params); 78 | } 79 | 80 | async remove(id: Id, params?: ServiceParams): Promise; 81 | async remove(id: null, params?: ServiceParams): Promise; 82 | async remove( 83 | id: NullableId, 84 | params?: ServiceParams 85 | ): Promise; 86 | async remove( 87 | id: NullableId, 88 | params?: ServiceParams 89 | ): Promise { 90 | if (params) { 91 | const { $limit, ...query } = await this.sanitizeQuery(params); 92 | params.query = query; 93 | } 94 | 95 | return this._remove(id, params); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /test/index.test.ts: -------------------------------------------------------------------------------- 1 | import adapterTests from "@feathersjs/adapter-tests"; 2 | import errors from "@feathersjs/errors"; 3 | import { feathers } from "@feathersjs/feathers"; 4 | import NeDB from "@seald-io/nedb"; 5 | import assert from "assert"; 6 | import path from "path"; 7 | import { NeDBService } from "../src"; 8 | 9 | const testSuite = adapterTests([ 10 | ".options", 11 | ".events", 12 | "._get", 13 | "._find", 14 | "._create", 15 | "._update", 16 | "._patch", 17 | "._remove", 18 | ".get", 19 | ".get + $select", 20 | ".get + id + query", 21 | ".get + id + query id", 22 | ".update + id + query id", 23 | ".get + NotFound", 24 | ".find", 25 | ".remove", 26 | ".remove + $select", 27 | ".remove + id + query", 28 | ".remove + id + query id", 29 | ".remove + multi", 30 | ".remove + multi no pagination", 31 | ".update", 32 | ".update + $select", 33 | ".update + id + query", 34 | ".update + NotFound", 35 | ".update + query + NotFound", 36 | ".patch", 37 | ".patch + $select", 38 | ".patch + id + query", 39 | ".patch + id + query id", 40 | ".patch multiple", 41 | ".patch multiple no pagination", 42 | ".patch multi query same", 43 | ".patch multi query changed", 44 | ".patch + NotFound", 45 | ".patch + query + NotFound", 46 | ".create", 47 | ".create + $select", 48 | ".create multi", 49 | ".create ignores query", 50 | "internal .find", 51 | "internal .get", 52 | "internal .create", 53 | "internal .update", 54 | "internal .patch", 55 | "internal .remove", 56 | ".find + equal", 57 | ".find + equal multiple", 58 | ".find + $sort", 59 | ".find + $sort + string", 60 | ".find + $limit", 61 | ".find + $limit 0", 62 | ".find + $skip", 63 | ".find + $select", 64 | ".find + $and", 65 | ".find + $or", 66 | ".find + $and + $or", 67 | ".find + $in", 68 | ".find + $nin", 69 | ".find + $lt", 70 | ".find + $lte", 71 | ".find + $gt", 72 | ".find + $gte", 73 | ".find + $ne", 74 | ".find + $gt + $lt + $sort", 75 | ".find + $or nested + $sort", 76 | ".find + paginate", 77 | ".find + paginate + query", 78 | ".find + paginate + $limit + $skip", 79 | ".find + paginate + $limit 0", 80 | ".find + paginate + params", 81 | "params.adapter + paginate", 82 | "params.adapter + multi", 83 | ]); 84 | 85 | const createService = (name: string, options: any) => { 86 | const filename = path.join("db-data", name); 87 | const db = new NeDB({ 88 | filename, 89 | autoload: true, 90 | }); 91 | 92 | return new NeDBService({ 93 | Model: db, 94 | events: ["testing"], 95 | ...options, 96 | }); 97 | }; 98 | 99 | describe("NeDB Service", () => { 100 | const app = feathers() 101 | .use( 102 | "/people", 103 | createService("people", { 104 | whitelist: ["$regex"], 105 | }) 106 | ) 107 | .use( 108 | "/people-customid", 109 | createService("people-customid", { 110 | id: "customid", 111 | }) 112 | ); 113 | const service = app.service("people"); 114 | 115 | describe("nedb params", () => { 116 | /* 117 | 118 | it("$select excludes id field if not explicitly selected (#66)", async () => { 119 | const mod = await service.create({ 120 | name: "Modifier", 121 | age: 222, 122 | }); 123 | const data = await service.find({ 124 | query: { 125 | age: 222, 126 | $select: ["name"], 127 | }, 128 | }); 129 | await service.remove(mod._id); 130 | 131 | assert.ok(!data[0]._id); 132 | }); 133 | 134 | it("can $select with only id (#100)", async () => { 135 | const mod = await service.create({ 136 | name: "Modifier", 137 | age: 343, 138 | }); 139 | const data = await service.find({ 140 | query: { 141 | age: 343, 142 | $select: ["_id"], 143 | }, 144 | }); 145 | 146 | await service.remove(mod._id); 147 | assert.ok(data[0]._id); 148 | assert.ok(!data[0].name); 149 | 150 | }); 151 | 152 | it("allows whitelisted parameters in query", async () => { 153 | const person = await service.create({ 154 | name: "Param test", 155 | }); 156 | 157 | const data = await service.find({ 158 | query: { 159 | name: { $regex: /haha/ }, 160 | }, 161 | }); 162 | await service.remove(person._id); 163 | 164 | assert.strictEqual(data.length, 0); 165 | }); 166 | 167 | */ 168 | 169 | it("throws error when model is missing", () => { 170 | try { 171 | //@ts-ignore 172 | const s = new NeDBService(); 173 | throw new Error("Should never get here"); 174 | } catch (error: any) { 175 | assert.strictEqual( 176 | error?.message, 177 | "NeDB datastore `Model` needs to be provided" 178 | ); 179 | } 180 | }); 181 | 182 | it("allows to set params.nedb to upsert", async () => { 183 | //@ts-ignore 184 | const person = await service.update( 185 | "testing", 186 | { 187 | name: "Upsert tester", 188 | }, 189 | { 190 | nedb: { 191 | upsert: true, 192 | }, 193 | } 194 | ); 195 | await service.remove(person._id); 196 | 197 | assert.deepStrictEqual(person, { 198 | _id: "testing", 199 | name: "Upsert tester", 200 | }); 201 | }); 202 | 203 | it("allows NeDB modifiers (#59)", async () => { 204 | const person = await service.create({ 205 | name: "Modifier", 206 | data: ["first"], 207 | }); 208 | const updated = await service.update(person._id, { 209 | $push: { data: "second" }, 210 | }); 211 | await service.remove(person._id); 212 | 213 | //@ts-ignore 214 | assert.deepStrictEqual(updated.data, ["first", "second"]); 215 | }); 216 | 217 | it("allows NeDB modifiers in patch (#65)", async () => { 218 | const service = app.service("people"); 219 | 220 | const person = await service.create({ 221 | name: "Modifier", 222 | data: ["first"], 223 | }); 224 | const updated = await service.patch(person._id, { 225 | $push: { data: "second" }, 226 | }); 227 | await service.remove(person._id); 228 | 229 | //@ts-ignore 230 | assert.deepStrictEqual(updated.data, ["first", "second"]); 231 | }); 232 | 233 | it("_patch sets default params", async () => { 234 | const person = await service.create({ 235 | name: "Param test", 236 | }); 237 | //@ts-ignore 238 | const patchedPerson = await service._patch(person._id, { 239 | name: "Updated", 240 | }); 241 | await service.remove(person._id); 242 | 243 | assert.strictEqual(patchedPerson.name, "Updated"); 244 | }); 245 | }); 246 | 247 | testSuite(app, errors, "people", "_id"); 248 | testSuite(app, errors, "people-customid", "customid"); 249 | }); 250 | -------------------------------------------------------------------------------- /tsconfig-base.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | // TODO: We should remove this but lib types break all the time 4 | "skipLibCheck": true, 5 | /* Basic Options */ 6 | "target": "es2018", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */ 7 | "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ 8 | // "lib": [], /* Specify library files to be included in the compilation. */ 9 | // "allowJs": true, /* Allow javascript files to be compiled. */ 10 | // "checkJs": true, /* Report errors in .js files. */ 11 | // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ 12 | "declaration": true, /* Generates corresponding '.d.ts' file. */ 13 | // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ 14 | "sourceMap": true, /* Generates corresponding '.map' file. */ 15 | // "outFile": "./", /* Concatenate and emit output to single file. */ 16 | // "rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ 17 | // "composite": true, /* Enable project compilation */ 18 | // "removeComments": true, /* Do not emit comments to output. */ 19 | // "noEmit": true, /* Do not emit outputs. */ 20 | // "importHelpers": true, /* Import emit helpers from 'tslib'. */ 21 | // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ 22 | // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ 23 | 24 | /* Strict Type-Checking Options */ 25 | "strict": true, /* Enable all strict type-checking options. */ 26 | //"noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ 27 | "strictNullChecks": false, /* Enable strict null checks. */ 28 | // "strictFunctionTypes": true, /* Enable strict checking of function types. */ 29 | // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ 30 | // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ 31 | // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ 32 | 33 | /* Additional Checks */ 34 | "noUnusedLocals": false, /* Report errors on unused locals. */ 35 | "noUnusedParameters": true, /* Report errors on unused parameters. */ 36 | "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ 37 | // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ 38 | 39 | /* Module Resolution Options */ 40 | // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ 41 | // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ 42 | // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ 43 | // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ 44 | // "typeRoots": [], /* List of folders to include type definitions from. */ 45 | // "types": [], /* Type declaration files to be included in compilation. */ 46 | // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ 47 | "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ 48 | // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ 49 | 50 | /* Source Map Options */ 51 | // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ 52 | // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ 53 | // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ 54 | // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ 55 | 56 | /* Experimental Options */ 57 | // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ 58 | // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ 59 | } 60 | } -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig-base", 3 | "include": [ 4 | "src/**/*.ts" 5 | ], 6 | "compilerOptions": { 7 | "outDir": "lib" 8 | } 9 | } 10 | --------------------------------------------------------------------------------