diff --git a/CHANGELOG.md b/CHANGELOG.md index 5930f88..7cfd63a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## v0.3.0 (2017-10-24) + +* Add ability to create custom methods for service and query service. +* Add tests. + ## v0.2.0 (2017-10-12) * Add support of the [joi](https://github.com/hapijs/joi) for validating data schema. diff --git a/README.md b/README.md index c52d351..08a8ace 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,8 @@ There are few reasons, why we think this layer could be helpful to many projects 1. Every update method emits `*.updated`, `*.created`, `*.removed` events, which allow to listen for the database changes and perform business logic based on this updates. That could help keep your entities weakly coupled with each other. 2. Implements more high level api, such as paging. -3. Implements database schema validation based on [jsonschema](https://github.com/tdegrunt/jsonschema). See examples below for more details. +3. Implements database schema validation based on [joi](https://github.com/hapijs/joi). See examples below for more details. +4. Allows you to add custom methods for services that are needed on a particular project. See examples below for more details. ## Usage example @@ -196,3 +197,20 @@ module.exports = (obj) => validator.validate(obj, companySchema); const schema = require('./user.schema') const usersService = db.createService('users', schema); ``` + +In order to add your own methods to the services, you can use the functions `setServiceMethod` and `setQueryServiceMethod` of the object `db`. This function takes the function name as the first parameter and the custom function for the service as the second parameter. The custom function takes the service itself as the first parameter, and the remaining parameters are the parameters that are passed when this custom function is called. + +```javascript +const connectionString = `mongodb://localhost:27017/home-db`; +const db = require('./').connect(connectionString); + +db.setQueryServiceMethod('findById', (service, id) => { + return service.findOne({ _id: id }); +}); + +// Create entity service +const usersQueryService = db.createQueryService('users'); + +// find user by id +const user = await usersQueryService.findById('123') +``` diff --git a/bin/run.sh b/bin/run.sh index fa8d134..a4fd16e 100755 --- a/bin/run.sh +++ b/bin/run.sh @@ -1,3 +1,3 @@ #!/bin/sh -npm i --quiet -NODE_ENV=test npm run test:eslint +npm install --quiet +Node_ENV=test npm run test:eslint diff --git a/package-lock.json b/package-lock.json index 71e1b37..b47c11f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,16 +1,16 @@ { "name": "@paralect/node-mongo", - "version": "0.2.0", + "version": "0.3.0", "lockfileVersion": 1, "requires": true, "dependencies": { "@paralect/eslint-config": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/@paralect/eslint-config/-/eslint-config-0.1.2.tgz", - "integrity": "sha512-w83zQnmSn2Kmug2IVNbwzCImWFR1YsxS8/KnJ9iNntg4kNdGWUlQtk8jULJbiqpxrGAaPrGvlhBxX8VMJ31Ggw==", + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/@paralect/eslint-config/-/eslint-config-0.1.4.tgz", + "integrity": "sha1-0YFvjzwjDXvtpcIBL/Itvjk09xs=", "dev": true, "requires": { - "eslint-config-airbnb": "16.0.0" + "eslint-config-airbnb": "16.1.0" } }, "abbrev": { @@ -43,9 +43,9 @@ } }, "ajv": { - "version": "5.2.3", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-5.2.3.tgz", - "integrity": "sha1-wG9Zh3jETGsWGrr+NGa4GtGBTtI=", + "version": "5.2.4", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-5.2.4.tgz", + "integrity": "sha1-Pa+ai2ciEpn9ro2C0RftjmyAJEs=", "dev": true, "requires": { "co": "4.6.0", @@ -243,163 +243,11 @@ "integrity": "sha512-/xr1ADm5bnTjjN+xwoXb7lF4v2rnxMzNZzFU7h8SxB+qB6+IqSTOOqVcpaPTUC2Non/MbQxS3OIZnJpQ2X21aQ==", "dev": true, "requires": { - "chalk": "2.1.0", + "chalk": "2.2.0", "esutils": "2.0.2", "js-tokens": "3.0.2" } }, - "babel-core": { - "version": "6.26.0", - "resolved": "https://registry.npmjs.org/babel-core/-/babel-core-6.26.0.tgz", - "integrity": "sha1-rzL3izGm/O8RnIew/Y2XU/A6C7g=", - "dev": true, - "requires": { - "babel-code-frame": "6.26.0", - "babel-generator": "6.26.0", - "babel-helpers": "6.24.1", - "babel-messages": "6.23.0", - "babel-register": "6.26.0", - "babel-runtime": "6.26.0", - "babel-template": "6.26.0", - "babel-traverse": "6.26.0", - "babel-types": "6.26.0", - "babylon": "6.18.0", - "convert-source-map": "1.5.0", - "debug": "2.6.9", - "json5": "0.5.1", - "lodash": "4.17.4", - "minimatch": "3.0.4", - "path-is-absolute": "1.0.1", - "private": "0.1.8", - "slash": "1.0.0", - "source-map": "0.5.7" - }, - "dependencies": { - "ansi-styles": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz", - "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=", - "dev": true - }, - "babel-code-frame": { - "version": "6.26.0", - "resolved": "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-6.26.0.tgz", - "integrity": "sha1-Y/1D99weO7fONZR9uP42mj9Yx0s=", - "dev": true, - "requires": { - "chalk": "1.1.3", - "esutils": "2.0.2", - "js-tokens": "3.0.2" - } - }, - "babel-messages": { - "version": "6.23.0", - "resolved": "https://registry.npmjs.org/babel-messages/-/babel-messages-6.23.0.tgz", - "integrity": "sha1-8830cDhYA1sqKVHG7F7fbGLyYw4=", - "dev": true, - "requires": { - "babel-runtime": "6.26.0" - } - }, - "babel-template": { - "version": "6.26.0", - "resolved": "https://registry.npmjs.org/babel-template/-/babel-template-6.26.0.tgz", - "integrity": "sha1-3gPi0WOWsGn0bdn/+FIfsaDjXgI=", - "dev": true, - "requires": { - "babel-runtime": "6.26.0", - "babel-traverse": "6.26.0", - "babel-types": "6.26.0", - "babylon": "6.18.0", - "lodash": "4.17.4" - } - }, - "babel-traverse": { - "version": "6.26.0", - "resolved": "https://registry.npmjs.org/babel-traverse/-/babel-traverse-6.26.0.tgz", - "integrity": "sha1-RqnL1+3MYsjlwGTi0tjQ9ANXZu4=", - "dev": true, - "requires": { - "babel-code-frame": "6.26.0", - "babel-messages": "6.23.0", - "babel-runtime": "6.26.0", - "babel-types": "6.26.0", - "babylon": "6.18.0", - "debug": "2.6.9", - "globals": "9.18.0", - "invariant": "2.2.2", - "lodash": "4.17.4" - } - }, - "babel-types": { - "version": "6.26.0", - "resolved": "https://registry.npmjs.org/babel-types/-/babel-types-6.26.0.tgz", - "integrity": "sha1-o7Bz+Uq0nrb6Vc1lInozQ4BjJJc=", - "dev": true, - "requires": { - "babel-runtime": "6.26.0", - "esutils": "2.0.2", - "lodash": "4.17.4", - "to-fast-properties": "1.0.3" - } - }, - "babylon": { - "version": "6.18.0", - "resolved": "https://registry.npmjs.org/babylon/-/babylon-6.18.0.tgz", - "integrity": "sha512-q/UEjfGJ2Cm3oKV71DJz9d25TPnq5rhBVL2Q4fA5wcC3jcrdn7+SssEybFIxwAvvP+YCsCYNKughoF33GxgycQ==", - "dev": true - }, - "chalk": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", - "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=", - "dev": true, - "requires": { - "ansi-styles": "2.2.1", - "escape-string-regexp": "1.0.5", - "has-ansi": "2.0.0", - "strip-ansi": "3.0.1", - "supports-color": "2.0.0" - } - }, - "debug": { - "version": "2.6.9", - "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", - "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", - "dev": true, - "requires": { - "ms": "2.0.0" - } - }, - "globals": { - "version": "9.18.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-9.18.0.tgz", - "integrity": "sha512-S0nG3CLEQiY/ILxqtztTWH/3iRRdyBLw6KMDxnKMchrtbj2OFmehVh0WUCfW3DUrIgx/qFrJPICrq4Z4sTR9UQ==", - "dev": true - }, - "strip-ansi": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", - "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", - "dev": true, - "requires": { - "ansi-regex": "2.1.1" - } - }, - "supports-color": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz", - "integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=", - "dev": true - }, - "to-fast-properties": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-1.0.3.tgz", - "integrity": "sha1-uDVx+k2MJbguIxsG46MFXeTKGkc=", - "dev": true - } - } - }, "babel-eslint": { "version": "8.0.1", "resolved": "https://registry.npmjs.org/babel-eslint/-/babel-eslint-8.0.1.tgz", @@ -449,12 +297,6 @@ "to-fast-properties": "1.0.3" } }, - "source-map": { - "version": "0.5.7", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", - "integrity": "sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=", - "dev": true - }, "to-fast-properties": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-1.0.3.tgz", @@ -484,170 +326,12 @@ "babel-types": "7.0.0-beta.0" } }, - "babel-helpers": { - "version": "6.24.1", - "resolved": "https://registry.npmjs.org/babel-helpers/-/babel-helpers-6.24.1.tgz", - "integrity": "sha1-NHHenK7DiOXIUOWX5Yom3fN2ArI=", - "dev": true, - "requires": { - "babel-runtime": "6.26.0", - "babel-template": "6.26.0" - }, - "dependencies": { - "ansi-styles": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz", - "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=", - "dev": true - }, - "babel-code-frame": { - "version": "6.26.0", - "resolved": "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-6.26.0.tgz", - "integrity": "sha1-Y/1D99weO7fONZR9uP42mj9Yx0s=", - "dev": true, - "requires": { - "chalk": "1.1.3", - "esutils": "2.0.2", - "js-tokens": "3.0.2" - } - }, - "babel-messages": { - "version": "6.23.0", - "resolved": "https://registry.npmjs.org/babel-messages/-/babel-messages-6.23.0.tgz", - "integrity": "sha1-8830cDhYA1sqKVHG7F7fbGLyYw4=", - "dev": true, - "requires": { - "babel-runtime": "6.26.0" - } - }, - "babel-template": { - "version": "6.26.0", - "resolved": "https://registry.npmjs.org/babel-template/-/babel-template-6.26.0.tgz", - "integrity": "sha1-3gPi0WOWsGn0bdn/+FIfsaDjXgI=", - "dev": true, - "requires": { - "babel-runtime": "6.26.0", - "babel-traverse": "6.26.0", - "babel-types": "6.26.0", - "babylon": "6.18.0", - "lodash": "4.17.4" - } - }, - "babel-traverse": { - "version": "6.26.0", - "resolved": "https://registry.npmjs.org/babel-traverse/-/babel-traverse-6.26.0.tgz", - "integrity": "sha1-RqnL1+3MYsjlwGTi0tjQ9ANXZu4=", - "dev": true, - "requires": { - "babel-code-frame": "6.26.0", - "babel-messages": "6.23.0", - "babel-runtime": "6.26.0", - "babel-types": "6.26.0", - "babylon": "6.18.0", - "debug": "2.6.9", - "globals": "9.18.0", - "invariant": "2.2.2", - "lodash": "4.17.4" - } - }, - "babel-types": { - "version": "6.26.0", - "resolved": "https://registry.npmjs.org/babel-types/-/babel-types-6.26.0.tgz", - "integrity": "sha1-o7Bz+Uq0nrb6Vc1lInozQ4BjJJc=", - "dev": true, - "requires": { - "babel-runtime": "6.26.0", - "esutils": "2.0.2", - "lodash": "4.17.4", - "to-fast-properties": "1.0.3" - } - }, - "babylon": { - "version": "6.18.0", - "resolved": "https://registry.npmjs.org/babylon/-/babylon-6.18.0.tgz", - "integrity": "sha512-q/UEjfGJ2Cm3oKV71DJz9d25TPnq5rhBVL2Q4fA5wcC3jcrdn7+SssEybFIxwAvvP+YCsCYNKughoF33GxgycQ==", - "dev": true - }, - "chalk": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", - "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=", - "dev": true, - "requires": { - "ansi-styles": "2.2.1", - "escape-string-regexp": "1.0.5", - "has-ansi": "2.0.0", - "strip-ansi": "3.0.1", - "supports-color": "2.0.0" - } - }, - "debug": { - "version": "2.6.9", - "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", - "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", - "dev": true, - "requires": { - "ms": "2.0.0" - } - }, - "globals": { - "version": "9.18.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-9.18.0.tgz", - "integrity": "sha512-S0nG3CLEQiY/ILxqtztTWH/3iRRdyBLw6KMDxnKMchrtbj2OFmehVh0WUCfW3DUrIgx/qFrJPICrq4Z4sTR9UQ==", - "dev": true - }, - "strip-ansi": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", - "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", - "dev": true, - "requires": { - "ansi-regex": "2.1.1" - } - }, - "supports-color": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz", - "integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=", - "dev": true - }, - "to-fast-properties": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-1.0.3.tgz", - "integrity": "sha1-uDVx+k2MJbguIxsG46MFXeTKGkc=", - "dev": true - } - } - }, "babel-messages": { "version": "7.0.0-beta.0", "resolved": "https://registry.npmjs.org/babel-messages/-/babel-messages-7.0.0-beta.0.tgz", "integrity": "sha512-eXdShsm9ZTh9AQhlIaAn6HR3xWpxCnK9ZwIDA9QyjnwTgMctGxHHflw4b4RJ3/ZjTL0Vrmvm0tQXPkp49mTAUw==", "dev": true }, - "babel-register": { - "version": "6.26.0", - "resolved": "https://registry.npmjs.org/babel-register/-/babel-register-6.26.0.tgz", - "integrity": "sha1-btAhFz4vy0htestFxgCahW9kcHE=", - "dev": true, - "requires": { - "babel-core": "6.26.0", - "babel-runtime": "6.26.0", - "core-js": "2.5.1", - "home-or-tmp": "2.0.0", - "lodash": "4.17.4", - "mkdirp": "0.5.1", - "source-map-support": "0.4.18" - }, - "dependencies": { - "core-js": { - "version": "2.5.1", - "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.5.1.tgz", - "integrity": "sha1-rmh03GaTd4m4B1T/VCjfZoGcpQs=", - "dev": true - } - } - }, "babel-runtime": { "version": "6.26.0", "resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.26.0.tgz", @@ -823,14 +507,14 @@ } }, "chalk": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.1.0.tgz", - "integrity": "sha512-LUHGS/dge4ujbXMJrnihYMcL4AoOweGnw9Tp3kQuqy1Kx5c1qKjqvMJZ6nVJPMWJtKCTN72ZogH3oeSO9g9rXQ==", + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.2.0.tgz", + "integrity": "sha512-0BMM/2hG3ZaoPfR6F+h/oWpZtsh3b/s62TjSM6MGCJWEbJDN1acqCXvyhhZsDSVFklpebUoQ5O1kKC7lOzrn9g==", "dev": true, "requires": { "ansi-styles": "3.2.0", "escape-string-regexp": "1.0.5", - "supports-color": "4.4.0" + "supports-color": "4.5.0" } }, "check-error": { @@ -940,12 +624,6 @@ "integrity": "sha1-/ozxhP9mcLa67wGp1IYaXL7EEgo=", "dev": true }, - "convert-source-map": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.5.0.tgz", - "integrity": "sha1-ms1whRxtXf3ZPZKC5e35SgP/RrU=", - "dev": true - }, "core-js": { "version": "1.2.7", "resolved": "https://registry.npmjs.org/core-js/-/core-js-1.2.7.tgz", @@ -968,14 +646,6 @@ "log-driver": "1.2.5", "minimist": "1.2.0", "request": "2.83.0" - }, - "dependencies": { - "minimist": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", - "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", - "dev": true - } } }, "cross-spawn": { @@ -1206,14 +876,14 @@ "dev": true }, "eslint": { - "version": "4.8.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-4.8.0.tgz", - "integrity": "sha1-Ip7w41Tg5h2DfHqA/fuoJeGZgV4=", + "version": "4.9.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-4.9.0.tgz", + "integrity": "sha1-doedJ0BoJhsZH+Dy9Wx0wvQgjos=", "dev": true, "requires": { - "ajv": "5.2.3", + "ajv": "5.2.4", "babel-code-frame": "6.26.0", - "chalk": "2.1.0", + "chalk": "2.2.0", "concat-stream": "1.6.0", "cross-spawn": "5.1.0", "debug": "3.1.0", @@ -1227,7 +897,7 @@ "functional-red-black-tree": "1.0.1", "glob": "7.1.2", "globals": "9.18.0", - "ignore": "3.3.5", + "ignore": "3.3.6", "imurmurhash": "0.1.4", "inquirer": "3.3.0", "is-resolvable": "1.0.0", @@ -1306,18 +976,18 @@ } }, "eslint-config-airbnb": { - "version": "16.0.0", - "resolved": "https://registry.npmjs.org/eslint-config-airbnb/-/eslint-config-airbnb-16.0.0.tgz", - "integrity": "sha512-QWl/uGjvG71Bap0RTKZ1DPnZzhY5UFGQh4PUYS7q5dksfhgwyQ9WLL6f7OV4o1P8HdR0VuLs0FQI5dHkLIUOjQ==", + "version": "16.1.0", + "resolved": "https://registry.npmjs.org/eslint-config-airbnb/-/eslint-config-airbnb-16.1.0.tgz", + "integrity": "sha512-zLyOhVWhzB/jwbz7IPSbkUuj7X2ox4PHXTcZkEmDqTvd0baJmJyuxlFPDlZOE/Y5bC+HQRaEkT3FoHo9wIdRiw==", "dev": true, "requires": { - "eslint-config-airbnb-base": "12.0.2" + "eslint-config-airbnb-base": "12.1.0" } }, "eslint-config-airbnb-base": { - "version": "12.0.2", - "resolved": "https://registry.npmjs.org/eslint-config-airbnb-base/-/eslint-config-airbnb-base-12.0.2.tgz", - "integrity": "sha512-rQqOvAzrMC3BBCH6Dd/1RenDi+RW4vdgnh8xcPf6sgd324ad6aX7hSZ52L1SfDGe2VsZR2yB5uPvDfXYvxHZmA==", + "version": "12.1.0", + "resolved": "https://registry.npmjs.org/eslint-config-airbnb-base/-/eslint-config-airbnb-base-12.1.0.tgz", + "integrity": "sha512-/vjm0Px5ZCpmJqnjIzcFb9TKZrKWz0gnuG/7Gfkt0Db1ELJR51xkZth+t14rYdqWgX836XbuxtArbIHlVhbLBA==", "dev": true, "requires": { "eslint-restricted-globals": "0.1.1" @@ -1567,7 +1237,7 @@ "object-assign": "4.1.1", "promise": "7.3.1", "setimmediate": "1.0.5", - "ua-parser-js": "0.7.14" + "ua-parser-js": "0.7.17" } }, "figures": { @@ -1730,9 +1400,9 @@ "dev": true }, "handlebars": { - "version": "4.0.10", - "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.0.10.tgz", - "integrity": "sha1-PTDHGLCaPZbyPqTMH0A8TTup/08=", + "version": "4.0.11", + "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.0.11.tgz", + "integrity": "sha1-Ywo13+ApS8KB7a5v/F0yn8eYLcw=", "dev": true, "requires": { "async": "1.5.2", @@ -1764,7 +1434,7 @@ "integrity": "sha1-ukAsJmGU8VlW7xXg/PJCmT9qff0=", "dev": true, "requires": { - "ajv": "5.2.3", + "ajv": "5.2.4", "har-schema": "2.0.0" } }, @@ -1816,16 +1486,6 @@ "integrity": "sha512-v0XCLxICi9nPfYrS9RL8HbYnXi9obYAeLbSP00BmnZwCK9+Ih9WOjoZ8YoHCoav2csqn4FOz4Orldsy2dmDwmQ==", "dev": true }, - "home-or-tmp": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/home-or-tmp/-/home-or-tmp-2.0.0.tgz", - "integrity": "sha1-42w/LSyufXRqhX440Y1fMqeILbg=", - "dev": true, - "requires": { - "os-homedir": "1.0.2", - "os-tmpdir": "1.0.2" - } - }, "hosted-git-info": { "version": "2.5.0", "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.5.0.tgz", @@ -1850,9 +1510,9 @@ "dev": true }, "ignore": { - "version": "3.3.5", - "resolved": "https://registry.npmjs.org/ignore/-/ignore-3.3.5.tgz", - "integrity": "sha512-JLH93mL8amZQhh/p6mfQgVBH3M6epNq3DfsXsTSuSrInVjwyYlFE1nv2AgfRCC8PoOhM0jwQ5v8s9LgbK7yGDw==", + "version": "3.3.6", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-3.3.6.tgz", + "integrity": "sha512-HrxmNxKTGZ9a3uAl/FNG66Sdt0G9L4TtMbbUQjP1WhGmSj0FOyHvSgx7623aGJvXfPOur8MwmarlHT+37jmzlw==", "dev": true }, "imurmurhash": { @@ -1883,7 +1543,7 @@ "dev": true, "requires": { "ansi-escapes": "3.0.0", - "chalk": "2.1.0", + "chalk": "2.2.0", "cli-cursor": "2.1.0", "cli-width": "2.2.0", "external-editor": "2.0.5", @@ -2039,6 +1699,14 @@ "dev": true, "requires": { "punycode": "2.1.0" + }, + "dependencies": { + "punycode": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.0.tgz", + "integrity": "sha1-X4Y+3Im5bbCQdLrXlHvwkFbKTn0=", + "dev": true + } } }, "isexe": { @@ -2071,7 +1739,7 @@ "requires": { "abbrev": "1.0.9", "async": "1.5.2", - "istanbul-api": "1.1.14", + "istanbul-api": "1.2.1", "js-yaml": "3.10.0", "mkdirp": "0.5.1", "nopt": "3.0.6", @@ -2080,19 +1748,19 @@ } }, "istanbul-api": { - "version": "1.1.14", - "resolved": "https://registry.npmjs.org/istanbul-api/-/istanbul-api-1.1.14.tgz", - "integrity": "sha1-JbxXAffGgMD//5E95G42GaOm5oA=", + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/istanbul-api/-/istanbul-api-1.2.1.tgz", + "integrity": "sha512-oFCwXvd65amgaPCzqrR+a2XjanS1MvpXN6l/MlMUTv6uiA1NOgGX+I0uyq8Lg3GDxsxPsaP1049krz3hIJ5+KA==", "dev": true, "requires": { "async": "2.5.0", "fileset": "2.0.3", "istanbul-lib-coverage": "1.1.1", - "istanbul-lib-hook": "1.0.7", - "istanbul-lib-instrument": "1.8.0", - "istanbul-lib-report": "1.1.1", - "istanbul-lib-source-maps": "1.2.1", - "istanbul-reports": "1.1.2", + "istanbul-lib-hook": "1.1.0", + "istanbul-lib-instrument": "1.9.1", + "istanbul-lib-report": "1.1.2", + "istanbul-lib-source-maps": "1.2.2", + "istanbul-reports": "1.1.3", "js-yaml": "3.10.0", "mkdirp": "0.5.1", "once": "1.4.0" @@ -2116,18 +1784,18 @@ "dev": true }, "istanbul-lib-hook": { - "version": "1.0.7", - "resolved": "https://registry.npmjs.org/istanbul-lib-hook/-/istanbul-lib-hook-1.0.7.tgz", - "integrity": "sha512-3U2HB9y1ZV9UmFlE12Fx+nPtFqIymzrqCksrXujm3NVbAZIJg/RfYgO1XiIa0mbmxTjWpVEVlkIZJ25xVIAfkQ==", + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/istanbul-lib-hook/-/istanbul-lib-hook-1.1.0.tgz", + "integrity": "sha512-U3qEgwVDUerZ0bt8cfl3dSP3S6opBoOtk3ROO5f2EfBr/SRiD9FQqzwaZBqFORu8W7O0EXpai+k7kxHK13beRg==", "dev": true, "requires": { "append-transform": "0.4.0" } }, "istanbul-lib-instrument": { - "version": "1.8.0", - "resolved": "https://registry.npmjs.org/istanbul-lib-instrument/-/istanbul-lib-instrument-1.8.0.tgz", - "integrity": "sha1-ZvbJQhzJ7EcE928tsIS6kHiitTI=", + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/istanbul-lib-instrument/-/istanbul-lib-instrument-1.9.1.tgz", + "integrity": "sha512-RQmXeQ7sphar7k7O1wTNzVczF9igKpaeGQAG9qR2L+BS4DCJNTI9nytRmIVYevwO0bbq+2CXvJmYDuz0gMrywA==", "dev": true, "requires": { "babel-generator": "6.26.0", @@ -2265,9 +1933,9 @@ } }, "istanbul-lib-report": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/istanbul-lib-report/-/istanbul-lib-report-1.1.1.tgz", - "integrity": "sha512-tvF+YmCmH4thnez6JFX06ujIA19WPa9YUiwjc1uALF2cv5dmE3It8b5I8Ob7FHJ70H9Y5yF+TDkVa/mcADuw1Q==", + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/istanbul-lib-report/-/istanbul-lib-report-1.1.2.tgz", + "integrity": "sha512-UTv4VGx+HZivJQwAo1wnRwe1KTvFpfi/NYwN7DcsrdzMXwpRT/Yb6r4SBPoHWj4VuQPakR32g4PUUeyKkdDkBA==", "dev": true, "requires": { "istanbul-lib-coverage": "1.1.1", @@ -2294,53 +1962,44 @@ } }, "istanbul-lib-source-maps": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/istanbul-lib-source-maps/-/istanbul-lib-source-maps-1.2.1.tgz", - "integrity": "sha512-mukVvSXCn9JQvdJl8wP/iPhqig0MRtuWuD4ZNKo6vB2Ik//AmhAKe3QnPN02dmkRe3lTudFk3rzoHhwU4hb94w==", + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/istanbul-lib-source-maps/-/istanbul-lib-source-maps-1.2.2.tgz", + "integrity": "sha512-8BfdqSfEdtip7/wo1RnrvLpHVEd8zMZEDmOFEnpC6dg0vXflHt9nvoAyQUzig2uMSXfF2OBEYBV3CVjIL9JvaQ==", "dev": true, "requires": { - "debug": "2.6.9", + "debug": "3.1.0", "istanbul-lib-coverage": "1.1.1", "mkdirp": "0.5.1", "rimraf": "2.6.2", "source-map": "0.5.7" - }, - "dependencies": { - "debug": { - "version": "2.6.9", - "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", - "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", - "dev": true, - "requires": { - "ms": "2.0.0" - } - }, - "source-map": { - "version": "0.5.7", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", - "integrity": "sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=", - "dev": true - } } }, "istanbul-reports": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/istanbul-reports/-/istanbul-reports-1.1.2.tgz", - "integrity": "sha1-D7Lj9qqZIr085F0F2KtNXo4HvU8=", + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/istanbul-reports/-/istanbul-reports-1.1.3.tgz", + "integrity": "sha512-ZEelkHh8hrZNI5xDaKwPMFwDsUf5wIEI2bXAFGp1e6deR2mnEKBPhLJEgr4ZBt8Gi6Mj38E/C8kcy9XLggVO2Q==", "dev": true, "requires": { - "handlebars": "4.0.10" + "handlebars": "4.0.11" } }, "joi": { - "version": "11.3.4", - "resolved": "https://registry.npmjs.org/joi/-/joi-11.3.4.tgz", - "integrity": "sha512-2eytkbHJ0qhXaNgElrKFrruv1sZ8MtuFg7fJe1Linb028x/3+flYsrtZIc+7wYVY7oCtXv6Ou7dCzAZaV/Qubg==", + "version": "13.0.1", + "resolved": "https://registry.npmjs.org/joi/-/joi-13.0.1.tgz", + "integrity": "sha512-ChTMfmbIg5yrN9pUdeaLL8vzylMQhUteXiXa1MWINsMUs3jTQ8I87lUZwR5GdfCLJlpK04U7UgrxgmU8Zp7PhQ==", "dev": true, "requires": { - "hoek": "4.2.0", + "hoek": "5.0.0", "isemail": "3.0.0", - "topo": "2.0.2" + "topo": "3.0.0" + }, + "dependencies": { + "hoek": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/hoek/-/hoek-5.0.0.tgz", + "integrity": "sha512-/eDT+s5IgB/MR88VEIF8bYqqRiQ2yPownGng7NrmQzRv0kntBnDF68JBcpxVsnuOqDjmkemEoKlF+ln4z4NY0g==", + "dev": true + } } }, "js-tokens": { @@ -2405,12 +2064,6 @@ "integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=", "dev": true }, - "json5": { - "version": "0.5.1", - "resolved": "https://registry.npmjs.org/json5/-/json5-0.5.1.tgz", - "integrity": "sha1-Hq3nrMASA0rYTiOWdn6tn6VJWCE=", - "dev": true - }, "jsonify": { "version": "0.0.0", "resolved": "https://registry.npmjs.org/jsonify/-/jsonify-0.0.0.tgz", @@ -2617,9 +2270,9 @@ } }, "minimist": { - "version": "0.0.8", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", - "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", + "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", "dev": true }, "mkdirp": { @@ -2629,6 +2282,14 @@ "dev": true, "requires": { "minimist": "0.0.8" + }, + "dependencies": { + "minimist": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", + "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", + "dev": true + } } }, "mocha": { @@ -2647,6 +2308,17 @@ "he": "1.1.1", "mkdirp": "0.5.1", "supports-color": "4.4.0" + }, + "dependencies": { + "supports-color": { + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-4.4.0.tgz", + "integrity": "sha512-rKC3+DyXWgK0ZLKwmRsrkyHVZAjNkfzeehuFWdGGcqGDTZFH73+RH6S/RDAAxl9GusSjZSUWYLmT9N5pzXFOXQ==", + "dev": true, + "requires": { + "has-flag": "2.0.0" + } + } } }, "mocha-lcov-reporter": { @@ -2656,19 +2328,19 @@ "dev": true }, "mongodb": { - "version": "2.2.31", - "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-2.2.31.tgz", - "integrity": "sha1-GUBEXGYeGSF7s7+CRdmFSq71SNs=", + "version": "2.2.33", + "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-2.2.33.tgz", + "integrity": "sha1-tTfEcdNKZlG0jzb9vyl1A0Dgi1A=", "requires": { "es6-promise": "3.2.1", - "mongodb-core": "2.1.15", + "mongodb-core": "2.1.17", "readable-stream": "2.2.7" } }, "mongodb-core": { - "version": "2.1.15", - "resolved": "https://registry.npmjs.org/mongodb-core/-/mongodb-core-2.1.15.tgz", - "integrity": "sha1-hB9TuH//9MdFgYnDXIroJ+EWl2Q=", + "version": "2.1.17", + "resolved": "https://registry.npmjs.org/mongodb-core/-/mongodb-core-2.1.17.tgz", + "integrity": "sha1-pBizN6FKFJkPtRC5I97mqBMXPfg=", "requires": { "bson": "1.0.4", "require_optional": "1.0.1" @@ -2680,7 +2352,7 @@ "integrity": "sha512-NEygZ2fhRkPE9zxyOT/GhEYKIGClMCQ+StsTruZSlAWf1aRsgvdu8suVvOj3KWfdiOtsIMs9gg8eyyVHPNWRwg==", "requires": { "debug": "3.1.0", - "mongodb": "2.2.31", + "mongodb": "2.2.33", "monk-middleware-cast-ids": "0.2.1", "monk-middleware-fields": "0.2.0", "monk-middleware-handle-callback": "0.2.2", @@ -2775,7 +2447,7 @@ "dev": true, "requires": { "ansi-styles": "3.2.0", - "chalk": "2.1.0", + "chalk": "2.2.0", "cross-spawn": "5.1.0", "memory-streams": "0.1.2", "minimatch": "3.0.4", @@ -2832,10 +2504,16 @@ "integrity": "sha1-2j6nRob6IaGaERwybpDrFaAZZoY=", "dev": true, "requires": { - "minimist": "0.0.8", + "minimist": "0.0.10", "wordwrap": "0.0.3" }, "dependencies": { + "minimist": { + "version": "0.0.10", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.10.tgz", + "integrity": "sha1-3j+YVD2/lggr5IrRoMfNqDYwHc8=", + "dev": true + }, "wordwrap": { "version": "0.0.3", "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.3.tgz", @@ -2858,12 +2536,6 @@ "wordwrap": "1.0.0" } }, - "os-homedir": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/os-homedir/-/os-homedir-1.0.2.tgz", - "integrity": "sha1-/7xJiDNuDoM94MFox+8VISGqf7M=", - "dev": true - }, "os-tmpdir": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", @@ -2993,12 +2665,6 @@ "integrity": "sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=", "dev": true }, - "private": { - "version": "0.1.8", - "resolved": "https://registry.npmjs.org/private/-/private-0.1.8.tgz", - "integrity": "sha512-VvivMrbvd2nKkiG38qjULzlc+4Vx4wm/whI9pQD35YrARNnhxeiRktSOhSukRLFNlzg6Br/cJPet5J/u19r/mg==", - "dev": true - }, "process-nextick-args": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-1.0.7.tgz", @@ -3046,9 +2712,9 @@ "dev": true }, "punycode": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.0.tgz", - "integrity": "sha1-X4Y+3Im5bbCQdLrXlHvwkFbKTn0=", + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz", + "integrity": "sha1-wNWmOycYgArY4esPpSachN1BhF4=", "dev": true }, "qs": { @@ -3154,15 +2820,6 @@ "uuid": "3.1.0" } }, - "require_optional": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/require_optional/-/require_optional-1.0.1.tgz", - "integrity": "sha512-qhM/y57enGWHAe3v/NcwML6a3/vfESLe/sGM2dII+gEO0BpKRUkWZow/tyloNqJyN6kXSl3RyyM8Ll5D/sJP8g==", - "requires": { - "resolve-from": "2.0.0", - "semver": "5.4.1" - } - }, "require-uncached": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/require-uncached/-/require-uncached-1.0.3.tgz", @@ -3181,6 +2838,15 @@ } } }, + "require_optional": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/require_optional/-/require_optional-1.0.1.tgz", + "integrity": "sha512-qhM/y57enGWHAe3v/NcwML6a3/vfESLe/sGM2dII+gEO0BpKRUkWZow/tyloNqJyN6kXSl3RyyM8Ll5D/sJP8g==", + "requires": { + "resolve-from": "2.0.0", + "semver": "5.4.1" + } + }, "resolve": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.4.0.tgz", @@ -3297,12 +2963,6 @@ "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=", "dev": true }, - "slash": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/slash/-/slash-1.0.0.tgz", - "integrity": "sha1-xB8vbDn8FtHNF61LXYlhFK5HDVU=", - "dev": true - }, "slice-ansi": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-1.0.0.tgz", @@ -3327,15 +2987,6 @@ "integrity": "sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=", "dev": true }, - "source-map-support": { - "version": "0.4.18", - "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.4.18.tgz", - "integrity": "sha512-try0/JqxPLF9nOjvSta7tVondkP5dwgyLDjVoyMDlmjugT2lRZ1OfsrYTkCd2hkDnJTKRbO/Rl3orm8vlsUzbA==", - "dev": true, - "requires": { - "source-map": "0.5.7" - } - }, "spdx-correct": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/spdx-correct/-/spdx-correct-1.0.2.tgz", @@ -3397,14 +3048,6 @@ "duplexer": "0.1.1" } }, - "string_decoder": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz", - "integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==", - "requires": { - "safe-buffer": "5.1.1" - } - }, "string-width": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", @@ -3426,6 +3069,14 @@ "function-bind": "1.1.1" } }, + "string_decoder": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz", + "integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==", + "requires": { + "safe-buffer": "5.1.1" + } + }, "stringstream": { "version": "0.0.5", "resolved": "https://registry.npmjs.org/stringstream/-/stringstream-0.0.5.tgz", @@ -3462,9 +3113,9 @@ "dev": true }, "supports-color": { - "version": "4.4.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-4.4.0.tgz", - "integrity": "sha512-rKC3+DyXWgK0ZLKwmRsrkyHVZAjNkfzeehuFWdGGcqGDTZFH73+RH6S/RDAAxl9GusSjZSUWYLmT9N5pzXFOXQ==", + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-4.5.0.tgz", + "integrity": "sha1-vnoN5ITexcXN34s9WRJQRJEvY1s=", "dev": true, "requires": { "has-flag": "2.0.0" @@ -3476,9 +3127,9 @@ "integrity": "sha512-UUkEAPdSGxtRpiV9ozJ5cMTtYiqz7Ni1OGqLXRCynrvzdtR1p+cfOWe2RJLwvUG8hNanaSRjecIqwOjqeatDsA==", "dev": true, "requires": { - "ajv": "5.2.3", + "ajv": "5.2.4", "ajv-keywords": "2.1.0", - "chalk": "2.1.0", + "chalk": "2.2.0", "lodash": "4.17.4", "slice-ansi": "1.0.0", "string-width": "2.1.1" @@ -3512,12 +3163,20 @@ "dev": true }, "topo": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/topo/-/topo-2.0.2.tgz", - "integrity": "sha1-zVYVdSU5BXwNwEkaYhw7xvvh0YI=", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/topo/-/topo-3.0.0.tgz", + "integrity": "sha512-Tlu1fGlR90iCdIPURqPiufqAlCZYzLjHYVVbcFWDMcX7+tK8hdZWAfsMrD/pBul9jqHHwFjNdf1WaxA9vTRRhw==", "dev": true, "requires": { - "hoek": "4.2.0" + "hoek": "5.0.0" + }, + "dependencies": { + "hoek": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/hoek/-/hoek-5.0.0.tgz", + "integrity": "sha512-/eDT+s5IgB/MR88VEIF8bYqqRiQ2yPownGng7NrmQzRv0kntBnDF68JBcpxVsnuOqDjmkemEoKlF+ln4z4NY0g==", + "dev": true + } } }, "tough-cookie": { @@ -3527,14 +3186,6 @@ "dev": true, "requires": { "punycode": "1.4.1" - }, - "dependencies": { - "punycode": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz", - "integrity": "sha1-wNWmOycYgArY4esPpSachN1BhF4=", - "dev": true - } } }, "trim-right": { @@ -3587,9 +3238,9 @@ "dev": true }, "ua-parser-js": { - "version": "0.7.14", - "resolved": "https://registry.npmjs.org/ua-parser-js/-/ua-parser-js-0.7.14.tgz", - "integrity": "sha1-EQ1T+kw/MmwSEpK76skE0uAzh8o=", + "version": "0.7.17", + "resolved": "https://registry.npmjs.org/ua-parser-js/-/ua-parser-js-0.7.17.tgz", + "integrity": "sha512-uRdSdu1oA1rncCQL7sCj8vSyZkgtL7faaw9Tc9rZ3mGgraQ7+Pdx7w5mnOSF3gw9ZNG6oc+KXfkon3bKuROm0g==", "dev": true }, "uglify-js": { @@ -3602,15 +3253,6 @@ "source-map": "0.5.7", "uglify-to-browserify": "1.0.2", "yargs": "3.10.0" - }, - "dependencies": { - "source-map": { - "version": "0.5.7", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", - "integrity": "sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=", - "dev": true, - "optional": true - } } }, "uglify-to-browserify": { diff --git a/package.json b/package.json index c10da62..8c64959 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@paralect/node-mongo", - "version": "0.2.0", + "version": "0.3.0", "author": "Paralect", "description": "MongoDB wrapper for Node.JS 8", "private": false, @@ -9,7 +9,7 @@ "test": "run-s test:*", "test:eslint": "eslint ./", "test:mocha": "NODE_ENV=test mocha --exit --recursive -c -R spec src/index.test.js", - "coveralls": "istanbul cover _mocha --report lcovonly -- --exit --recursive -R spec src/index.test.js && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage" + "coveralls": "istanbul cover _mocha --report lcovonly -- --exit --recursive -c -R spec src/index.test.js && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage" }, "keywords": [ "mongo", @@ -22,20 +22,19 @@ "monk": "6.0.5" }, "devDependencies": { - "@paralect/eslint-config": "0.1.2", + "@paralect/eslint-config": "0.1.4", "babel-eslint": "8.0.1", - "babel-register": "^6.26.0", "chai": "4.1.2", - "coveralls": "^3.0.0", - "eslint": "4.8.0", + "coveralls": "3.0.0", + "eslint": "4.9.0", "eslint-plugin-import": "2.7.0", "eslint-plugin-jsx-a11y": "6.0.2", "eslint-plugin-react": "7.4.0", - "istanbul": "^1.1.0-alpha.1", - "joi": "^11.3.4", - "jsonschema": "^1.2.0", + "istanbul": "1.1.0-alpha.1", + "joi": "13.0.1", + "jsonschema": "1.2.0", "mocha": "4.0.1", - "mocha-lcov-reporter": "^1.3.0", + "mocha-lcov-reporter": "1.3.0", "npm-run-all": "4.1.1" }, "engines": { diff --git a/src/MongoQueryService.test.js b/src/MongoQueryService.test.js new file mode 100644 index 0000000..286669e --- /dev/null +++ b/src/MongoQueryService.test.js @@ -0,0 +1,118 @@ +const chai = require('chai'); + +const config = require('./config'); + +chai.should(); + +const db = require('./').connect(config.mongo.connection); + +db.setQueryServiceMethod('findById', (service, id) => { + return service.findOne({ _id: id }); +}); + +module.exports = () => { + describe('MongoQueryService', () => { + const collectionName = `users-${Date.now()}`; + const collectionName2 = `users2-${Date.now()}`; + + const userService = db.createService(collectionName); + const userService2 = db.createService(collectionName2); + + const userQueryService = db.createQueryService(collectionName); + const userQueryService2 = db.createQueryService(collectionName2); + + after(async () => { + await userService._collection.drop(); + }); + + it('should return paged result if page > 0', async () => { + // create separate service to stricly check count + // and do not mix with other tests + await userService.create([{ name: 'Bob' }, { name: 'Alice' }, { name: 'Nick' }]); + + const options = { page: 1, perPage: 2, sort: { name: 1 } }; + const res = await userQueryService.find({}, options); + res.results.length.should.be.equal(2); + res.pagesCount.should.be.equal(2); + res.count.should.be.equal(3); + }); + + it('should return one user', async () => { + await userService.create([{ name: 'Evgeny' }]); + + const res = await userQueryService.findOne({ name: 'Evgeny' }); + res.name.should.be.equal('Evgeny'); + }); + + it('should return an error that there exist more than one document in the collection', async () => { + await userService.create([{ name: 'Amy' }, { name: 'Amy' }]); + + try { + await userQueryService.findOne({ name: 'Amy' }); + } catch (err) { + err.message.should.be.equal('findOne: More than one document return for query {"name":"Amy"}'); + } + }); + + it('should return number of documents in the collection', async () => { + await userService.create([{ name: 'Jake' }, { name: 'Jake' }]); + + const res = await userQueryService.count({ name: 'Jake' }); + res.should.be.equal(2); + }); + + it('should return distinct valuest', async () => { + await userService2.create([{ name: 'User1' }, { name: 'User2' }]); + + const res = await userQueryService2.distinct('name'); + res[0].should.be.equal('User1'); + res[1].should.be.equal('User2'); + }); + + it("should return that user Professor X doesn't exist in the list of user", async () => { + const res = await userQueryService.exists({ name: 'Professor X' }); + res.should.be.equal(false); + }); + + it('should successfully return result of aggregation', async () => { + await userService.create([ + { + name: 'Magneto', + allies: [ + { name: 'Mystique' }, + { name: 'Juggernaut' }, + ], + }, + { + name: 'Professor X', + allies: [ + { name: 'Cyclops' }, + { name: 'Storm' }, + ], + }, + ]); + + const res = await userQueryService.aggregate([ + { $unwind: '$allies' }, + { + $match: { + 'allies.name': 'Juggernaut', + }, + }, + ]); + res[0].name.should.be.equal('Magneto'); + }); + + it('should generate id for document', () => { + const id = userQueryService.generateId(); + id.length.should.be.equal(24); + }); + + it('should return user by id using custom method findById', async () => { + const user = await userService.create({ name: 'Jean Grey' }); + + const res = await userQueryService.findById(user._id); + res.name.should.be.equal('Jean Grey'); + }); + }); +}; diff --git a/src/MongoService.test.js b/src/MongoService.test.js index 9bf02f9..7b03275 100644 --- a/src/MongoService.test.js +++ b/src/MongoService.test.js @@ -11,6 +11,11 @@ chai.should(); const db = require('./').connect(config.mongo.connection); +db.setServiceMethod('createByName', async (service, name) => { + const res = await service.create({ name }); + return res; +}); + const joiSchema = { _id: Joi.string(), firstName: Joi.string().allow(''), @@ -121,18 +126,6 @@ module.exports = () => { }); }); - it('it should return paged result if page > 0', async () => { - // create separate service to stricly check count - // and do not mix with other tests - await findUserService.create([{ name: 'Bob' }, { name: 'Alice' }, { name: 'Nick' }]); - - const options = { page: 1, perPage: 2, sort: { name: 1 } }; - const res = await findUserService.find({}, options); - res.results.length.should.be.equal(2); - res.pagesCount.should.be.equal(2); - res.count.should.be.equal(3); - }); - it('should create a document', async () => { const user = { name: 'Bob' }; const doc = await userService.createOrUpdate({ _id: '1' }, (dbUser) => { @@ -252,5 +245,26 @@ module.exports = () => { }); user.firstName.should.be.equal('Evgeny'); }); + + it('should return an error that update function must be specified', async () => { + try { + await userService.update({ name: 'Magneto' }, { name: 'Professor X' }); + } catch (err) { + err.message.should.be.equal('updateFn must be a function'); + } + }); + + it('should return an error that document not found', async () => { + try { + await userService.update({ name: 'Magneto' }, () => {}); + } catch (err) { + err.message.should.be.equal('Document not found while updating. Query: {"name":"Magneto"}'); + } + }); + + it('should create user using custom method createByName', async () => { + const user = await userService.createByName('Quicksilver'); + user.name.should.be.equal('Quicksilver'); + }); }); }; diff --git a/src/MongoServiceError.js b/src/MongoServiceError.js index d2733de..f767d4c 100644 --- a/src/MongoServiceError.js +++ b/src/MongoServiceError.js @@ -1,14 +1,14 @@ -class MongoServiceError extends Error { - constructor(code, message, error) { - super(message); - this.name = 'MongoServiceError'; - this.code = code; - this.error = error; - } -} - -MongoServiceError.NOT_FOUND = 'NOT_FOUND'; -MongoServiceError.INVALID_SCHEMA = 'INVALID_SCHEMA'; -MongoServiceError.MORE_THAN_ONE = 'MORE_THAN_ONE'; - -module.exports = MongoServiceError; +class MongoServiceError extends Error { + constructor(code, message, error) { + super(message); + this.name = 'MongoServiceError'; + this.code = code; + this.error = error; + } +} + +MongoServiceError.NOT_FOUND = 'NOT_FOUND'; +MongoServiceError.INVALID_SCHEMA = 'INVALID_SCHEMA'; +MongoServiceError.MORE_THAN_ONE = 'MORE_THAN_ONE'; + +module.exports = MongoServiceError; diff --git a/src/index.js b/src/index.js index 6c95226..d71061a 100644 --- a/src/index.js +++ b/src/index.js @@ -1,66 +1,90 @@ -const MongoService = require('./MongoService'); -const MongoQueryService = require('./MongoQueryService'); -const monk = require('monk'); -const idGenerator = require('./idGenerator'); - -const logger = global.logger || console; - -/** -* Inits connection with mongodb, manage reconnects, create factory methods -* -* @return {Object} with a factory method {createService}, that creates a -* mongodb service -*/ -const connect = (connectionString) => { - // options docs: http://mongodb.github.io/node-mongodb-native/2.1/reference/connecting/connection-settings/ - const db = monk(connectionString, { - connectTimeoutMS: 20000, - }); - - db.on('error-opening', (err) => { - logger.error(err, 'Failed to connect to the mongodb on start'); - throw err; - }); - - db.on('open', () => { - logger.info(`Connected to mongodb: ${connectionString}`); - }); - - db.on('close', (err) => { - if (err) { - logger.error(err, `Lost connection with mongodb: ${connectionString}`); - } else { - logger.warn(`Closed connection with mongodb: ${connectionString}`); - } - }); - - db.on('connected', (err) => { - if (err) { - logger.error(err); - } else { - logger.info(`Connected to mongodb: ${connectionString}`); - } - }); - - // Add factory methods to the database object - db.createService = (collectionName, validateSchema, options = {}) => { - const opt = options; - if (validateSchema) { - opt.validateSchema = validateSchema; - } - - const collection = db.get(collectionName, { castIds: false }); - return new MongoService(collection, opt); - }; - - db.createQueryService = (collectionName) => { - const collection = db.get(collectionName, { castIds: false }); - return new MongoQueryService(collection); - }; - - return db; -}; - - -module.exports.connect = connect; -module.exports.idGenerator = idGenerator; +const MongoService = require('./MongoService'); +const MongoQueryService = require('./MongoQueryService'); + +const monk = require('monk'); +const idGenerator = require('./idGenerator'); + +const logger = global.logger || console; + +/** +* Inits connection with mongodb, manage reconnects, create factory methods +* +* @return {Object} with a factory method {createService}, that creates a +* mongodb service +*/ +const connect = (connectionString) => { + // options docs: http://mongodb.github.io/node-mongodb-native/2.1/reference/connecting/connection-settings/ + const db = monk(connectionString, { + connectTimeoutMS: 20000, + }); + + db.on('error-opening', (err) => { + logger.error(err, 'Failed to connect to the mongodb on start'); + throw err; + }); + + db.on('open', () => { + logger.info(`Connected to mongodb: ${connectionString}`); + }); + + db.on('close', (err) => { + if (err) { + logger.error(err, `Lost connection with mongodb: ${connectionString}`); + } else { + logger.warn(`Closed connection with mongodb: ${connectionString}`); + } + }); + + db.on('connected', (err) => { + if (err) { + logger.error(err); + } else { + logger.info(`Connected to mongodb: ${connectionString}`); + } + }); + + // Add factory methods to the database object + db.createService = (collectionName, validateSchema, options = {}) => { + const opt = options; + if (validateSchema) { + opt.validateSchema = validateSchema; + } + + const collection = db.get(collectionName, { castIds: false }); + return new MongoService(collection, opt); + }; + + /** + * @desc Add additional methods for mongo service + * @param {string} name + * @param {Function} method + */ + db.setServiceMethod = (name, method) => { + MongoService.prototype[name] = function customMethod(...args) { + return method.apply(this, [this, ...args]); + }; + }; + + db.createQueryService = (collectionName) => { + const collection = db.get(collectionName, { castIds: false }); + + return new MongoQueryService(collection); + }; + + /** + * @desc Add additional methods for mongo query service + * @param {string} name + * @param {Function} method + */ + db.setQueryServiceMethod = (name, method) => { + MongoQueryService.prototype[name] = function customMethod(...args) { + return method.apply(this, [this, ...args]); + }; + }; + + return db; +}; + + +module.exports.connect = connect; +module.exports.idGenerator = idGenerator; diff --git a/src/index.test.js b/src/index.test.js index 2fd8945..7d8da7e 100644 --- a/src/index.test.js +++ b/src/index.test.js @@ -1,2 +1,3 @@ global.logger = console; require('./MongoService.test')(); +require('./MongoQueryService.test')();