From 23bc463676ea1ff53c77a232a7ccc874fa84015d Mon Sep 17 00:00:00 2001 From: Eric D Date: Thu, 14 Jun 2018 17:04:55 +0800 Subject: [PATCH 01/11] fix bug: not support model validation fix bug: not support model validation when using this plugin --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 96aaf34..4f1f9e2 100755 --- a/src/index.js +++ b/src/index.js @@ -315,7 +315,7 @@ export function autoIncrement( }); // Every time documents in this schema are saved, run this logic. - schema.pre('validate', function(next: Function) { + schema.post('validate', function(next: Function) { // Get reference to the document being saved. const doc: MongooseDocument = this; // $FlowFixMe From a23840cadd4c2fe2fa45e66565d8cfc9d6e7f8ae Mon Sep 17 00:00:00 2001 From: bigdong Date: Thu, 14 Jun 2018 17:44:20 +0800 Subject: [PATCH 02/11] update package info --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 8a68d84..20395f1 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "mongoose-plugin-autoinc", - "version": "0.0.0-development", - "description": "This plugin allows you to auto-increment any field on any mongoose schema that you wish (forked mongoose-auto-increment in 2018).", + "version": "0.0.1", + "description": "==fix-bug==This plugin allows you to auto-increment any field on any mongoose schema that you wish (forked mongoose-auto-increment in 2018).", "files": [ "lib" ], @@ -9,7 +9,7 @@ "types": "lib/index.d.ts", "repository": { "type": "git", - "url": "https://github.com/nodkz/mongoose-plugin-autoinc.git" + "url": "https://github.com/bigdong89/mongoose-plugin-autoinc.git" }, "keywords": [ "mongoose", @@ -21,7 +21,7 @@ "bugs": { "url": "https://github.com/nodkz/mongoose-plugin-autoinc/issues" }, - "homepage": "https://github.com/nodkz/mongoose-plugin-autoinc", + "homepage": "https://github.com/bigdong89/mongoose-plugin-autoinc", "peerDependencies": { "mongoose": ">=4.0.0 || >=5.0.0" }, From 9638772a77099a36f655dd29809579834dc3ca80 Mon Sep 17 00:00:00 2001 From: bigdong Date: Thu, 14 Jun 2018 18:43:32 +0800 Subject: [PATCH 03/11] fix packaged files --- package.json | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 20395f1..2bfc311 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,12 @@ { - "name": "mongoose-plugin-autoinc", + "name": "mongoose-plugin-autoinc-fix", "version": "0.0.1", "description": "==fix-bug==This plugin allows you to auto-increment any field on any mongoose schema that you wish (forked mongoose-auto-increment in 2018).", "files": [ - "lib" + "src" ], - "main": "lib/index.js", - "types": "lib/index.d.ts", + "main": "src/index.js", + "types": "src/index.d.ts", "repository": { "type": "git", "url": "https://github.com/bigdong89/mongoose-plugin-autoinc.git" @@ -80,5 +80,6 @@ "flow": "./node_modules/.bin/flow", "test": "npm run coverage && npm run lint && npm run flow", "semantic-release": "semantic-release" - } + }, + "dependencies": {} } From 1cc6a15ac3e2f3202e57f4302c1e6637e3fa1cd3 Mon Sep 17 00:00:00 2001 From: bigdong Date: Thu, 14 Jun 2018 20:21:43 +0800 Subject: [PATCH 04/11] fix wrong changes --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 2bfc311..433a69f 100644 --- a/package.json +++ b/package.json @@ -3,10 +3,10 @@ "version": "0.0.1", "description": "==fix-bug==This plugin allows you to auto-increment any field on any mongoose schema that you wish (forked mongoose-auto-increment in 2018).", "files": [ - "src" + "lib" ], - "main": "src/index.js", - "types": "src/index.d.ts", + "main": "lib/index.js", + "types": "lib/index.d.ts", "repository": { "type": "git", "url": "https://github.com/bigdong89/mongoose-plugin-autoinc.git" From a899bd9e5c381723fa0de03f21a4250c711377e6 Mon Sep 17 00:00:00 2001 From: bigdong Date: Thu, 14 Jun 2018 20:22:11 +0800 Subject: [PATCH 05/11] v0.0.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 433a69f..91a0421 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mongoose-plugin-autoinc-fix", - "version": "0.0.1", + "version": "0.0.2", "description": "==fix-bug==This plugin allows you to auto-increment any field on any mongoose schema that you wish (forked mongoose-auto-increment in 2018).", "files": [ "lib" From 2e9b4880a616eb562bd427657bc8a8b9df9cfe91 Mon Sep 17 00:00:00 2001 From: bigdong Date: Fri, 15 Jun 2018 10:54:33 +0800 Subject: [PATCH 06/11] v0.0.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 91a0421..499c375 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mongoose-plugin-autoinc-fix", - "version": "0.0.2", + "version": "0.0.3", "description": "==fix-bug==This plugin allows you to auto-increment any field on any mongoose schema that you wish (forked mongoose-auto-increment in 2018).", "files": [ "lib" From f5fc1ce3786c8a913aba1db26e4e670039d38c23 Mon Sep 17 00:00:00 2001 From: bigdong Date: Fri, 15 Jun 2018 18:38:17 +0800 Subject: [PATCH 07/11] fix bug --- package.json | 2 +- src/index.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 499c375..4e94362 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mongoose-plugin-autoinc-fix", - "version": "0.0.3", + "version": "0.0.5", "description": "==fix-bug==This plugin allows you to auto-increment any field on any mongoose schema that you wish (forked mongoose-auto-increment in 2018).", "files": [ "lib" diff --git a/src/index.js b/src/index.js index 4f1f9e2..658399f 100755 --- a/src/index.js +++ b/src/index.js @@ -315,9 +315,9 @@ export function autoIncrement( }); // Every time documents in this schema are saved, run this logic. - schema.post('validate', function(next: Function) { + schema.post('validate', function(doc: MongooseDocument, next: Function) { // Get reference to the document being saved. - const doc: MongooseDocument = this; + //const doc: MongooseDocument = this; // $FlowFixMe const alreadyGetId = doc.__maiRanOnce === true; From 41e536541771d9866a1acdd34e50cbadbcaf7cb1 Mon Sep 17 00:00:00 2001 From: bigdong89 Date: Wed, 22 May 2019 23:05:57 +0800 Subject: [PATCH 08/11] yarn test: coverage&eslint work; but flow error-incompatible paramater --- src/__tests__/index-test.js | 33 ++++++------ src/__tests__/parallel-test.js | 15 +++--- src/index.js | 8 +-- yarn.lock | 97 ++++++++++++++-------------------- 4 files changed, 71 insertions(+), 82 deletions(-) diff --git a/src/__tests__/index-test.js b/src/__tests__/index-test.js index 76c1468..8ce3e68 100644 --- a/src/__tests__/index-test.js +++ b/src/__tests__/index-test.js @@ -16,14 +16,15 @@ beforeAll(async () => { mongoServer = new MongodbMemoryServer(); const mongoUrl = await mongoServer.getConnectionString(); - connection = await mongoose - .createConnection(mongoUrl, { + mongoose + .connect(mongoUrl, { autoReconnect: true, reconnectInterval: 100, reconnectTries: Number.MAX_VALUE, }) // $FlowFixMe .catch(() => {}); + connection = mongoose.connection; // connection.on('error', (...args) => console.error(...args)); }); @@ -56,7 +57,7 @@ describe('mongoose-auto-increment', () => { dept: String, }); UserSchema.plugin(autoIncrement, 'User'); - const User = connection.model('User', UserSchema); + const User = mongoose.model('User', UserSchema); await User.ensureIndexes(); const user1 = new User({ name: 'Charlie', dept: 'Support' }); @@ -76,7 +77,7 @@ describe('mongoose-auto-increment', () => { }); UserSchema.plugin(autoIncrement, 'User'); - const User = connection.model('User', UserSchema); + const User = mongoose.model('User', UserSchema); await User.ensureIndexes(); const user1 = new User({ name: 'Charlie', dept: 'Support' }); @@ -95,7 +96,7 @@ describe('mongoose-auto-increment', () => { }); UserSchema.plugin(autoIncrement, { model: 'User', field: 'userId' }); - const User = connection.model('User', UserSchema); + const User = mongoose.model('User', UserSchema); await User.ensureIndexes(); const user1 = new User({ name: 'Charlie', dept: 'Support' }); @@ -114,7 +115,7 @@ describe('mongoose-auto-increment', () => { dept: String, }); UserSchema.plugin(autoIncrement, { model: 'User', field: 'userId' }); - const User = connection.model('User', UserSchema); + const User = mongoose.model('User', UserSchema); await User.ensureIndexes(); const user1 = new User({ name: 'Charlie', dept: 'Support' }); @@ -138,7 +139,7 @@ describe('mongoose-auto-increment', () => { }); UserSchema.plugin(autoIncrement, { model: 'User', startAt: 3 }); - const User = connection.model('User', UserSchema); + const User = mongoose.model('User', UserSchema); await User.ensureIndexes(); const user1 = new User({ name: 'Charlie', dept: 'Support' }); @@ -157,7 +158,7 @@ describe('mongoose-auto-increment', () => { dept: String, }); UserSchema.plugin(autoIncrement, { model: 'User', incrementBy: 5 }); - const User = connection.model('User', UserSchema); + const User = mongoose.model('User', UserSchema); await User.ensureIndexes(); const user1 = new User({ name: 'Charlie', dept: 'Support' }); @@ -185,7 +186,7 @@ describe('mongoose-auto-increment', () => { field: 'userId', groupingField: 'dept', }); - const User = connection.model('User', UserSchema); + const User = mongoose.model('User', UserSchema); await User.ensureIndexes(); const user1 = new User({ name: 'Charlie', dept: 'Support' }); @@ -230,7 +231,7 @@ describe('mongoose-auto-increment', () => { dept: String, }); UserSchema.plugin(autoIncrement, 'User'); - const User = connection.model('User', UserSchema); + const User = mongoose.model('User', UserSchema); await User.ensureIndexes(); const user1 = new User({ name: 'Charlie', dept: 'Support' }); @@ -255,7 +256,7 @@ describe('mongoose-auto-increment', () => { dept: String, }); UserSchema.plugin(autoIncrement, 'User'); - const User = connection.model('User', UserSchema); + const User = mongoose.model('User', UserSchema); await User.ensureIndexes(); const user1 = new User({ name: 'Charlie', dept: 'Support' }); @@ -284,7 +285,7 @@ describe('mongoose-auto-increment', () => { field: 'userId', groupingField: 'dept', }); - const User = connection.model('User', UserSchema); + const User = mongoose.model('User', UserSchema); await User.ensureIndexes(); const user1 = new User({ name: 'Charlie', dept: 'Support' }); @@ -311,7 +312,7 @@ describe('mongoose-auto-increment', () => { dept: String, }); UserSchema.plugin(autoIncrement, 'User'); - const User = connection.model('User', UserSchema); + const User = mongoose.model('User', UserSchema); await User.ensureIndexes(); const user = new User({ name: 'Charlie', dept: 'Support' }); @@ -333,7 +334,7 @@ describe('mongoose-auto-increment', () => { dept: String, }); UserSchema.plugin(autoIncrement, 'User'); - const User = connection.model('User', UserSchema); + const User = mongoose.model('User', UserSchema); await User.ensureIndexes(); const user = new User({ name: 'Charlie', dept: 'Support' }); @@ -361,7 +362,7 @@ describe('mongoose-auto-increment', () => { field: 'orderNumber', outputFilter: value => value * 100, }); - const User = connection.model('User', UserSchema); + const User = mongoose.model('User', UserSchema); await User.ensureIndexes(); const user1 = new User({ name: 'Charlie', dept: 'Support' }); @@ -406,7 +407,7 @@ describe('mongoose-auto-increment', () => { model: 'User', field: 'orderNumber', }); - const User = connection.model('User', UserSchema); + const User = mongoose.model('User', UserSchema); await User.ensureIndexes(); const user1 = new User({ name: 'Charlie', dept: 'Support' }); diff --git a/src/__tests__/parallel-test.js b/src/__tests__/parallel-test.js index 492fa73..9c365f5 100644 --- a/src/__tests__/parallel-test.js +++ b/src/__tests__/parallel-test.js @@ -9,21 +9,24 @@ jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000; mongoose.Promise = global.Promise; let mongoServer; -let connection; +// let connection; beforeAll(async () => { mongoServer = new MongodbMemoryServer(); const mongoUrl = await mongoServer.getConnectionString(); - connection = await mongoose - .createConnection(mongoUrl, { + mongoose + .connect(mongoUrl, { autoReconnect: true, reconnectInterval: 100, reconnectTries: Number.MAX_VALUE, }) // $FlowFixMe .catch(() => {}); - connection.on('error', (...args) => console.error(...args)); + // connection = mongoose.connection; + /* connection.on('error', (...args) => { + // console.error(...args); + }); */ }); afterAll(() => { @@ -40,7 +43,7 @@ describe('parallel writing', () => { dept: String, }); UserSchema.plugin(autoIncrement, 'User'); - const User = connection.model('User', UserSchema); + const User = mongoose.model('User', UserSchema); async function createUserAsync() { return User.create({ @@ -72,7 +75,7 @@ describe('parallel writing', () => { dept: String, }); UserPidSchema.plugin(autoIncrement, { model: 'UserPid', field: 'pid' }); - const UserPid = connection.model('UserPid', UserPidSchema); + const UserPid = mongoose.model('UserPid', UserPidSchema); async function createUserPidAsync() { return UserPid.create({ diff --git a/src/index.js b/src/index.js index 658399f..045b814 100755 --- a/src/index.js +++ b/src/index.js @@ -48,10 +48,10 @@ counterSchema.index( ); export function initialize(): void { - console.log( + /* console.log( `MongooseAutoIncrement.initialize() method is deprecated. ` + `Just remove this method, it not required anymore.` - ); + ); */ } function isMongoDuplicateError(e: any): boolean { @@ -315,9 +315,9 @@ export function autoIncrement( }); // Every time documents in this schema are saved, run this logic. - schema.post('validate', function(doc: MongooseDocument, next: Function) { + schema.post('validate', (doc: MongooseDocument, next: Function) => { // Get reference to the document being saved. - //const doc: MongooseDocument = this; + // const doc: MongooseDocument = this; // $FlowFixMe const alreadyGetId = doc.__maiRanOnce === true; diff --git a/yarn.lock b/yarn.lock index 5f7c5ea..1ffed65 100644 --- a/yarn.lock +++ b/yarn.lock @@ -361,11 +361,11 @@ async@2.1.4: dependencies: lodash "^4.14.0" -async@2.4.0: - version "2.4.0" - resolved "https://registry.yarnpkg.com/async/-/async-2.4.0.tgz#4990200f18ea5b837c2cc4f8c031a6985c385611" +async@2.6.1: + version "2.6.1" + resolved "https://registry.yarnpkg.com/async/-/async-2.6.1.tgz#b245a23ca71930044ec53fa46aa00a3e87c6a610" dependencies: - lodash "^4.14.0" + lodash "^4.17.10" async@^1.4.0: version "1.5.2" @@ -987,10 +987,6 @@ bluebird@3.5.0: version "3.5.0" resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.0.tgz#791420d7f551eea2897453a8a77653f96606d67c" -bluebird@^3.5.0: - version "3.5.1" - resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.1.tgz#d9551f9de98f1fcda1e683d17ee91a0602ee2eb9" - boom@2.x.x: version "2.10.1" resolved "https://registry.yarnpkg.com/boom/-/boom-2.10.1.tgz#39c8918ceff5799f83f9492a848f625add0c766f" @@ -1051,25 +1047,10 @@ bson@~1.0.4: version "1.0.4" resolved "https://registry.yarnpkg.com/bson/-/bson-1.0.4.tgz#93c10d39eaa5b58415cbc4052f3e53e562b0b72c" -buffer-alloc-unsafe@^0.1.0: - version "0.1.1" - resolved "https://registry.yarnpkg.com/buffer-alloc-unsafe/-/buffer-alloc-unsafe-0.1.1.tgz#ffe1f67551dd055737de253337bfe853dfab1a6a" - -buffer-alloc@^1.1.0: - version "1.1.0" - resolved "https://registry.yarnpkg.com/buffer-alloc/-/buffer-alloc-1.1.0.tgz#05514d33bf1656d3540c684f65b1202e90eca303" - dependencies: - buffer-alloc-unsafe "^0.1.0" - buffer-fill "^0.1.0" - buffer-crc32@~0.2.3: version "0.2.13" resolved "https://registry.yarnpkg.com/buffer-crc32/-/buffer-crc32-0.2.13.tgz#0d333e3f00eac50aa1454abd30ef8c2a5d9a7242" -buffer-fill@^0.1.0: - version "0.1.0" - resolved "https://registry.yarnpkg.com/buffer-fill/-/buffer-fill-0.1.0.tgz#ca9470e8d4d1b977fd7543f4e2ab6a7dc95101a8" - buffer@^3.0.1: version "3.6.0" resolved "https://registry.yarnpkg.com/buffer/-/buffer-3.6.0.tgz#a72c936f77b96bf52f5f7e7b467180628551defb" @@ -2102,9 +2083,9 @@ get-caller-file@^1.0.1: version "1.0.2" resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-1.0.2.tgz#f702e63127e7e231c160a80c1554acb70d5047e5" -get-port@^3.2.0: - version "3.2.0" - resolved "https://registry.yarnpkg.com/get-port/-/get-port-3.2.0.tgz#dd7ce7de187c06c8bf353796ac71e099f0980ebc" +get-port@^4.0.0: + version "4.2.0" + resolved "https://registry.yarnpkg.com/get-port/-/get-port-4.2.0.tgz#e37368b1e863b7629c43c5a323625f95cf24b119" get-stdin@^4.0.1: version "4.0.1" @@ -2126,10 +2107,10 @@ get-stream@^3.0.0: resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-3.0.0.tgz#8e943d1358dc37555054ecbe2edb05aa174ede14" getos@^3.1.0: - version "3.1.0" - resolved "https://registry.yarnpkg.com/getos/-/getos-3.1.0.tgz#db3aa4df15a3295557ce5e81aa9e3e5cdfaa6567" + version "3.1.1" + resolved "https://registry.yarnpkg.com/getos/-/getos-3.1.1.tgz#967a813cceafee0156b0483f7cffa5b3eff029c5" dependencies: - async "2.4.0" + async "2.6.1" getpass@^0.1.1: version "0.1.7" @@ -2365,6 +2346,13 @@ https-proxy-agent@^2.1.0: agent-base "^4.1.0" debug "^2.4.1" +https-proxy-agent@^2.2.1: + version "2.2.1" + resolved "https://registry.yarnpkg.com/https-proxy-agent/-/https-proxy-agent-2.2.1.tgz#51552970fa04d723e04c56d04178c3f92592bbc0" + dependencies: + agent-base "^4.1.0" + debug "^3.1.0" + iconv-lite@0.4.19, iconv-lite@^0.4.17: version "0.4.19" resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.19.tgz#f7468f60135f5e5dad3399c0a81be9a1603a082b" @@ -3153,9 +3141,11 @@ locate-path@^2.0.0: p-locate "^2.0.0" path-exists "^3.0.0" -lockfile@^1.0.3: - version "1.0.3" - resolved "https://registry.yarnpkg.com/lockfile/-/lockfile-1.0.3.tgz#2638fc39a0331e9cac1a04b71799931c9c50df79" +lockfile@^1.0.4: + version "1.0.4" + resolved "https://registry.yarnpkg.com/lockfile/-/lockfile-1.0.4.tgz#07f819d25ae48f87e538e6578b6964a4981a5609" + dependencies: + signal-exit "^3.0.2" lodash.assign@^4.2.0: version "4.2.0" @@ -3185,6 +3175,10 @@ lodash@^4.0.0, lodash@^4.13.1, lodash@^4.14.0, lodash@^4.15.0, lodash@^4.17.4, l version "4.17.4" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae" +lodash@^4.17.10: + version "4.17.11" + resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d" + longest@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/longest/-/longest-1.0.1.tgz#30a0b2da38f73770e8294a0d22e6625ed77d0097" @@ -3239,11 +3233,9 @@ marked@^0.3.9: version "0.3.12" resolved "https://registry.yarnpkg.com/marked/-/marked-0.3.12.tgz#7cf25ff2252632f3fe2406bde258e94eee927519" -md5-file@^3.2.3: - version "3.2.3" - resolved "https://registry.yarnpkg.com/md5-file/-/md5-file-3.2.3.tgz#f9bceb941eca2214a4c0727f5e700314e770f06f" - dependencies: - buffer-alloc "^1.1.0" +md5-file@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/md5-file/-/md5-file-4.0.0.tgz#f3f7ba1e2dd1144d5bf1de698d0e5f44a4409584" mem@^1.1.0: version "1.1.0" @@ -3348,22 +3340,20 @@ mongodb-core@3.0.2: require_optional "^1.0.1" mongodb-memory-server@^1.6.5: - version "1.6.5" - resolved "https://registry.yarnpkg.com/mongodb-memory-server/-/mongodb-memory-server-1.6.5.tgz#6dd8ab3c67ed238d46f981ab565b3c07bb368644" + version "1.9.3" + resolved "https://registry.yarnpkg.com/mongodb-memory-server/-/mongodb-memory-server-1.9.3.tgz#a1dbe2ca6ec7436e4cb6e481d5f4e3a24b97d304" dependencies: babel-runtime "^6.26.0" debug "^3.1.0" decompress "^4.2.0" - fs-extra "^5.0.0" - get-port "^3.2.0" + get-port "^4.0.0" getos "^3.1.0" - lockfile "^1.0.3" - md5-file "^3.2.3" + https-proxy-agent "^2.2.1" + lockfile "^1.0.4" + md5-file "^4.0.0" mkdirp "^0.5.1" - request "^2.83.0" - request-promise "^4.2.2" tmp "^0.0.33" - uuid "^3.0.1" + uuid "^3.2.1" mongodb@3.0.2: version "3.0.2" @@ -4069,15 +4059,6 @@ request-promise-native@^1.0.3: stealthy-require "^1.1.0" tough-cookie ">=2.3.3" -request-promise@^4.2.2: - version "4.2.2" - resolved "https://registry.yarnpkg.com/request-promise/-/request-promise-4.2.2.tgz#d1ea46d654a6ee4f8ee6a4fea1018c22911904b4" - dependencies: - bluebird "^3.5.0" - request-promise-core "1.1.1" - stealthy-require "^1.1.0" - tough-cookie ">=2.3.3" - request@2.81.0: version "2.81.0" resolved "https://registry.yarnpkg.com/request/-/request-2.81.0.tgz#c6928946a0e06c5f8d6f8a9333469ffda46298a0" @@ -4784,10 +4765,14 @@ util.promisify@^1.0.0: define-properties "^1.1.2" object.getownpropertydescriptors "^2.0.3" -uuid@^3.0.0, uuid@^3.0.1, uuid@^3.1.0: +uuid@^3.0.0, uuid@^3.1.0: version "3.1.0" resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.1.0.tgz#3dd3d3e790abc24d7b0d3a034ffababe28ebbc04" +uuid@^3.2.1: + version "3.3.2" + resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.3.2.tgz#1b4af4955eb3077c501c23872fc6513811587131" + v8flags@^2.1.1: version "2.1.1" resolved "https://registry.yarnpkg.com/v8flags/-/v8flags-2.1.1.tgz#aab1a1fa30d45f88dd321148875ac02c0b55e5b4" From 2ab1aa2880d8f30dac752c3498e7163eb0615017 Mon Sep 17 00:00:00 2001 From: bigdong89 Date: Thu, 23 May 2019 01:51:11 +0800 Subject: [PATCH 09/11] change README.md & version --- README.md | 18 +++++++++++++----- package.json | 2 +- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 79a4bd5..63d8bbc 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,15 @@ --- -This is a fork of [mongoose-auto-increment](https://github.com/chevex-archived/mongoose-auto-increment) which has not been maintained in a while. Also used fixes and changes from [dashride fork](https://github.com/Dashride/mongoose-auto-increment). This fork addresses the following issues: +This is a fork of [nodkz/mongoose-auto-increment](https://github.com/nodkz/mongoose-auto-increment) which has not been maintained in a while.This fork addresses the following issues: +- fix errors during testing +- After `run test`, `run flow` output error `'The first parameter is incompatible'`. However, it was the same as nodz's version. +- fix errors in README.md `call nextCount and resetCount methods wrongly` +- tested with Mongoose 5 +- upload to yarnpkg.com as `'mongoose-plugin-autoinc-fix'` +- increment version number started from nodkz's version + +The following issues were fixed by [nodkz](https://github.com/nodkz/mongoose-plugin-autoinc).Also used fixes and changes from [dashride fork](https://github.com/Dashride/mongoose-auto-increment). - fix error `'required' is not valid for an index specification` for Mongoose 4 - does not require established connection for initialization **(deprecate `initialize()` method)** - include Flowtype and Typescript declarations @@ -80,7 +88,7 @@ Your first book document would have a `bookId` equal to `100`. Your second book ````js const Book = connection.model('Book', BookSchema); -Book.nextCount((err, count) => { +Book.nextCount().then(count => { // count === 0 -> true @@ -89,7 +97,7 @@ Book.nextCount((err, count) => { // book._id === 0 -> true - book.nextCount((err2, count) => { + book.nextCount().then(count => { // count === 1 -> true @@ -116,11 +124,11 @@ book.save(err => { // book._id === 100 -> true - book.nextCount((err1, count) => { + book.nextCount().then(count => { // count === 101 -> true - book.resetCount((err2, nextCount) => { + book.resetCount().then(nextCount => { // nextCount === 100 -> true diff --git a/package.json b/package.json index 4e94362..22acd69 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mongoose-plugin-autoinc-fix", - "version": "0.0.5", + "version": "1.2.0", "description": "==fix-bug==This plugin allows you to auto-increment any field on any mongoose schema that you wish (forked mongoose-auto-increment in 2018).", "files": [ "lib" From 7079f45bdf71f5109f4cbe95c23bb54fdedc115d Mon Sep 17 00:00:00 2001 From: bigdong89 Date: Thu, 23 May 2019 01:58:38 +0800 Subject: [PATCH 10/11] update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 63d8bbc..4e0dfc1 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,8 @@ The following issues were fixed by [nodkz](https://github.com/nodkz/mongoose-plu ## Getting Started -> npm install mongoose-plugin-autoinc +> npm install mongoose-plugin-autoinc-fix +> yarn add mongoose-plugin-autoinc-fix Once you have the plugin installed it is very simple to use. Just pass `autoIncrement` to the `plugin()` function on your schema. From 289a800eaa61eb028588584c564b85db2e8ec768 Mon Sep 17 00:00:00 2001 From: bigdong89 Date: Fri, 24 May 2019 23:46:12 +0800 Subject: [PATCH 11/11] fix errors in README.md --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4e0dfc1..e291d63 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# mongoose-plugin-autoinc +# mongoose-plugin-autoinc-fix [![](https://img.shields.io/npm/v/mongoose-plugin-autoinc.svg)](https://www.npmjs.com/package/mongoose-plugin-autoinc) [![codecov coverage](https://img.shields.io/codecov/c/github/nodkz/mongoose-plugin-autoinc.svg)](https://codecov.io/github/nodkz/mongoose-plugin-autoinc) [![Travis](https://img.shields.io/travis/nodkz/mongoose-plugin-autoinc.svg?maxAge=2592000)](https://travis-ci.org/nodkz/mongoose-plugin-autoinc) @@ -25,6 +25,7 @@ The following issues were fixed by [nodkz](https://github.com/nodkz/mongoose-plu ## Getting Started > npm install mongoose-plugin-autoinc-fix + > yarn add mongoose-plugin-autoinc-fix Once you have the plugin installed it is very simple to use. Just pass `autoIncrement` to the `plugin()` function on your schema. @@ -33,9 +34,9 @@ Once you have the plugin installed it is very simple to use. Just pass `autoIncr ````js import mongoose from 'mongoose'; -import { autoIncrement } from 'mongoose-plugin-autoinc'; +import { autoIncrement } from 'mongoose-plugin-autoinc-fix'; -const connection = mongoose.createConnection("mongodb://localhost/myDatabase"); +mongoose.connect("mongodb://localhost/myDatabase"); const BookSchema = new mongoose.Schema({ author: { type: Schema.Types.ObjectId, ref: 'Author' }, @@ -45,7 +46,7 @@ const BookSchema = new mongoose.Schema({ }); BookSchema.plugin(autoIncrement, 'Book'); -const Book = connection.model('Book', BookSchema); +const Book = mongoose.model('Book', BookSchema); ```` That's it. Now you can create book entities at will and they will have an `_id` field added of type `Number` and will automatically increment with each new document. Even declaring references is easy, just remember to change the reference property's type to `Number` instead of `ObjectId` if the referenced model is also using the plugin.