Skip to content

Commit

Permalink
feat: add support for mongoose 5
Browse files Browse the repository at this point in the history
  • Loading branch information
nodkz committed Jan 21, 2018
1 parent 5047394 commit c445afb
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 66 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
---

This is a fork of [mongoose-auto-increment](https://github.com/chevex-archived/mongoose-auto-increment) which has not been maintained in a while. This fork addresses the following issues:
- fix error `'required' is not valid for an index specification` for Mongoose 4 and above
- fix error `'required' is not valid for an index specification` for Mongoose 4 and Mongoose 5
- does not require established connection for initialization (deprecate `initialize()` method)
- include Flowtype and Typescript declarations

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"homepage": "https://github.com/nodkz/mongoose-plugin-autoinc",
"peerDependencies": {
"mongoose": ">=4.0.0"
"mongoose": ">=4.0.0 || >=5.0.0"
},
"devDependencies": {
"async": "^2.6.0",
Expand All @@ -44,7 +44,7 @@
"flow-bin": "^0.63.1",
"jest": "^22.1.3",
"mongodb-memory-server": "^1.6.4",
"mongoose": "^4.13.3",
"mongoose": "^5.0.1",
"prettier": "^1.10.2",
"rimraf": "^2.6.2",
"semantic-release": "^12.2.2",
Expand Down
10 changes: 8 additions & 2 deletions src/__tests__/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@ beforeAll(async () => {
mongoServer = new MongodbMemoryServer();
const mongoUrl = await mongoServer.getConnectionString();

connection = mongoose.createConnection(mongoUrl);
connection.on('error', (...args) => console.error(...args));
connection = await mongoose
.createConnection(mongoUrl, {
autoReconnect: true,
reconnectInterval: 100,
reconnectTries: Number.MAX_VALUE,
})
.catch(() => {});
// connection.on('error', (...args) => console.error(...args));
});

afterAll(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ export function autoIncrement(
});

// Every time documents in this schema are saved, run this logic.
schema.pre('validate', async function(next: Function) {
schema.pre('validate', function(next: Function) {
// Get reference to the document being saved.
const doc: MongooseDocument = this;
// $FlowFixMe
Expand Down
88 changes: 28 additions & 60 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1037,10 +1037,6 @@ buffer-fill@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/buffer-fill/-/buffer-fill-0.1.0.tgz#ca9470e8d4d1b977fd7543f4e2ab6a7dc95101a8"

buffer-shims@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/buffer-shims/-/buffer-shims-1.0.0.tgz#9978ce317388c649ad8793028c3477ef044a8b51"

buffer@^3.0.1:
version "3.6.0"
resolved "https://registry.yarnpkg.com/buffer/-/buffer-3.6.0.tgz#a72c936f77b96bf52f5f7e7b467180628551defb"
Expand Down Expand Up @@ -1608,10 +1604,6 @@ es-to-primitive@^1.1.1:
is-date-object "^1.0.1"
is-symbol "^1.0.1"

[email protected]:
version "3.2.1"
resolved "https://registry.yarnpkg.com/es6-promise/-/es6-promise-3.2.1.tgz#ec56233868032909207170c39448e24449dd1fc4"

es6-promise@^4.0.3:
version "4.1.1"
resolved "https://registry.yarnpkg.com/es6-promise/-/es6-promise-4.1.1.tgz#8811e90915d9a0dba36274f0b242dbda78f9c92a"
Expand Down Expand Up @@ -2299,10 +2291,6 @@ home-or-tmp@^2.0.0:
os-homedir "^1.0.0"
os-tmpdir "^1.0.1"

[email protected]:
version "2.0.2"
resolved "https://registry.yarnpkg.com/hooks-fixed/-/hooks-fixed-2.0.2.tgz#20076daa07e77d8a6106883ce3f1722e051140b0"

hosted-git-info@^2.1.4, hosted-git-info@^2.4.2:
version "2.5.0"
resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.5.0.tgz#6d60e34b3abbc8313062c3b798ef8d901a07af3c"
Expand Down Expand Up @@ -2378,7 +2366,7 @@ inflight@^1.0.4:
once "^1.3.0"
wrappy "1"

inherits@2, inherits@^2.0.1, inherits@^2.0.3, inherits@~2.0.0, inherits@~2.0.1, inherits@~2.0.3:
inherits@2, inherits@^2.0.1, inherits@^2.0.3, inherits@~2.0.0, inherits@~2.0.3:
version "2.0.3"
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de"

Expand Down Expand Up @@ -3044,9 +3032,9 @@ jsprim@^1.2.2:
json-schema "0.2.3"
verror "1.10.0"

kareem@1.5.0:
version "1.5.0"
resolved "https://registry.yarnpkg.com/kareem/-/kareem-1.5.0.tgz#e3e4101d9dcfde299769daf4b4db64d895d17448"
kareem@2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/kareem/-/kareem-2.0.1.tgz#f17f77e9032f64aa402b334f91fb4407fe4c042c"

kind-of@^3.0.2:
version "3.2.2"
Expand Down Expand Up @@ -3307,12 +3295,12 @@ modify-values@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/modify-values/-/modify-values-1.0.0.tgz#e2b6cdeb9ce19f99317a53722f3dbf5df5eaaab2"

mongodb-core@2.1.18:
version "2.1.18"
resolved "https://registry.yarnpkg.com/mongodb-core/-/mongodb-core-2.1.18.tgz#4c46139bdf3a1f032ded91db49f38eec01659050"
mongodb-core@3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/mongodb-core/-/mongodb-core-3.0.1.tgz#ff6dc36ee96ff596953d80a6840d6731bc92efed"
dependencies:
bson "~1.0.4"
require_optional "~1.0.0"
require_optional "^1.0.1"

mongodb-memory-server@^1.6.4:
version "1.6.4"
Expand All @@ -3332,43 +3320,39 @@ mongodb-memory-server@^1.6.4:
tmp "^0.0.33"
uuid "^3.0.1"

mongodb@2.2.34:
version "2.2.34"
resolved "https://registry.yarnpkg.com/mongodb/-/mongodb-2.2.34.tgz#a34f59bbeb61754aec432de72c3fe21526a44c1a"
mongodb@3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/mongodb/-/mongodb-3.0.1.tgz#278ee8006257ec22798594a6259546825d6de1b2"
dependencies:
es6-promise "3.2.1"
mongodb-core "2.1.18"
readable-stream "2.2.7"
mongodb-core "3.0.1"

[email protected]:
version "1.0.1"
resolved "https://registry.yarnpkg.com/mongoose-legacy-pluralize/-/mongoose-legacy-pluralize-1.0.1.tgz#31ae25db45c30f1448c0f93f52769e903367c701"

mongoose@^4.13.3:
version "4.13.9"
resolved "https://registry.yarnpkg.com/mongoose/-/mongoose-4.13.9.tgz#ca4d99aed6e36e87854c2295387e7ea17966cfe3"
mongoose@^5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/mongoose/-/mongoose-5.0.1.tgz#ded04311b9f13c8004e2b0097f3a61653a394361"
dependencies:
async "2.1.4"
bson "~1.0.4"
hooks-fixed "2.0.2"
kareem "1.5.0"
kareem "2.0.1"
lodash.get "4.4.2"
mongodb "2.2.34"
mongodb "3.0.1"
mongoose-legacy-pluralize "1.0.1"
mpath "0.3.0"
mpromise "0.5.5"
mquery "2.3.3"
mquery "3.0.0-rc0"
ms "2.0.0"
muri "1.3.0"
regexp-clone "0.0.1"
sliced "1.0.1"

[email protected]:
version "0.3.0"
resolved "https://registry.yarnpkg.com/mpath/-/mpath-0.3.0.tgz#7a58f789e9b5fd3c94520634157960f26bd5ef44"

[email protected]:
version "0.5.5"
resolved "https://registry.yarnpkg.com/mpromise/-/mpromise-0.5.5.tgz#f5b24259d763acc2257b0a0c8c6d866fd51732e6"

[email protected]:
version "2.3.3"
resolved "https://registry.yarnpkg.com/mquery/-/mquery-2.3.3.tgz#221412e5d4e7290ca5582dd16ea8f190a506b518"
[email protected]:
version "3.0.0-rc0"
resolved "https://registry.yarnpkg.com/mquery/-/mquery-3.0.0-rc0.tgz#05ec656e92f079828bedf4202e60fb8eaacb9f47"
dependencies:
bluebird "3.5.0"
debug "2.6.9"
Expand All @@ -3379,10 +3363,6 @@ [email protected]:
version "2.0.0"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"

[email protected]:
version "1.3.0"
resolved "https://registry.yarnpkg.com/muri/-/muri-1.3.0.tgz#aeccf3db64c56aa7c5b34e00f95b7878527a4721"

[email protected]:
version "0.0.7"
resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.7.tgz#3075ce93bc21b8fab43e1bc4da7e8115ed1e7bab"
Expand Down Expand Up @@ -3913,18 +3893,6 @@ read-pkg@^3.0.0:
normalize-package-data "^2.3.2"
path-type "^3.0.0"

[email protected]:
version "2.2.7"
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.2.7.tgz#07057acbe2467b22042d36f98c5ad507054e95b1"
dependencies:
buffer-shims "~1.0.0"
core-util-is "~1.0.0"
inherits "~2.0.1"
isarray "~1.0.0"
process-nextick-args "~1.0.6"
string_decoder "~1.0.0"
util-deprecate "~1.0.1"

readable-stream@^2.0.0, readable-stream@^2.0.1, readable-stream@^2.0.2, readable-stream@^2.0.5, readable-stream@^2.0.6, readable-stream@^2.1.4, readable-stream@^2.1.5, readable-stream@^2.2.2:
version "2.3.3"
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.3.3.tgz#368f2512d79f9d46fdfc71349ae7878bbc1eb95c"
Expand Down Expand Up @@ -4134,7 +4102,7 @@ require-uncached@^1.0.3:
caller-path "^0.1.0"
resolve-from "^1.0.0"

require_optional@~1.0.0:
require_optional@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/require_optional/-/require_optional-1.0.1.tgz#4cf35a4247f64ca3df8c2ef208cc494b1ca8fc2e"
dependencies:
Expand Down Expand Up @@ -4466,7 +4434,7 @@ string-width@^2.0.0, string-width@^2.1.0, string-width@^2.1.1:
is-fullwidth-code-point "^2.0.0"
strip-ansi "^4.0.0"

string_decoder@~1.0.0, string_decoder@~1.0.3:
string_decoder@~1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.0.3.tgz#0fc67d7c141825de94282dd536bec6b9bce860ab"
dependencies:
Expand Down

0 comments on commit c445afb

Please sign in to comment.