diff --git a/package-lock.json b/package-lock.json index 55383e85..1ee54d70 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,7 @@ "license": "Apache-2.0", "dependencies": { "@matrixai/async-init": "^1.8.4", - "@matrixai/async-locks": "^3.1.1", + "@matrixai/async-locks": "^4.0.0", "@matrixai/errors": "^1.1.7", "@matrixai/logger": "^3.1.0", "@matrixai/resources": "^1.1.5", @@ -1192,7 +1192,7 @@ "@matrixai/errors": "^1.1.7" } }, - "node_modules/@matrixai/async-init/node_modules/@matrixai/async-locks": { + "node_modules/@matrixai/async-locks": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/@matrixai/async-locks/-/async-locks-4.0.0.tgz", "integrity": "sha512-u/3fOdtjOKcDYF8dDoPR1/+7nmOkhxo42eBpXTEgfI0hLPGI37PoW7tjLvwy+O51Quy1HGOwhsR/Dgr4x+euug==", @@ -1203,16 +1203,6 @@ "@matrixai/timer": "^1.1.1" } }, - "node_modules/@matrixai/async-locks": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/@matrixai/async-locks/-/async-locks-3.2.0.tgz", - "integrity": "sha512-Gl919y3GK2lBCI7M3MabE2u0+XOhKqqgwFEGVaPSI2BrdSI+RY7K3+dzjTSUTujVZwiYskT611CBvlDm9fhsNg==", - "dependencies": { - "@matrixai/errors": "^1.1.3", - "@matrixai/resources": "^1.1.4", - "async-mutex": "^0.3.2" - } - }, "node_modules/@matrixai/errors": { "version": "1.1.7", "resolved": "https://registry.npmjs.org/@matrixai/errors/-/errors-1.1.7.tgz", @@ -2135,19 +2125,6 @@ "node": ">=8" } }, - "node_modules/async-mutex": { - "version": "0.3.2", - "resolved": "https://registry.npmjs.org/async-mutex/-/async-mutex-0.3.2.tgz", - "integrity": "sha512-HuTK7E7MT7jZEh1P9GtRW9+aTWiDWWi9InbZ5hjxrnRa39KS4BW04+xLBhYNS2aXhHUIKZSw3gj4Pn1pj+qGAA==", - "dependencies": { - "tslib": "^2.3.1" - } - }, - "node_modules/async-mutex/node_modules/tslib": { - "version": "2.5.3", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.5.3.tgz", - "integrity": "sha512-mSxlJJwl3BMEQCUNnxXBU9jP4JBktcEGhURcPR6VQVlnP0FdDEsIaz0C35dXNGLyRfrATNofF0F5p2KPxQgB+w==" - }, "node_modules/babel-jest": { "version": "28.1.3", "resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-28.1.3.tgz", @@ -8026,29 +8003,17 @@ "requires": { "@matrixai/async-locks": "^4.0.0", "@matrixai/errors": "^1.1.7" - }, - "dependencies": { - "@matrixai/async-locks": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/@matrixai/async-locks/-/async-locks-4.0.0.tgz", - "integrity": "sha512-u/3fOdtjOKcDYF8dDoPR1/+7nmOkhxo42eBpXTEgfI0hLPGI37PoW7tjLvwy+O51Quy1HGOwhsR/Dgr4x+euug==", - "requires": { - "@matrixai/async-cancellable": "^1.1.1", - "@matrixai/errors": "^1.1.7", - "@matrixai/resources": "^1.1.5", - "@matrixai/timer": "^1.1.1" - } - } } }, "@matrixai/async-locks": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/@matrixai/async-locks/-/async-locks-3.2.0.tgz", - "integrity": "sha512-Gl919y3GK2lBCI7M3MabE2u0+XOhKqqgwFEGVaPSI2BrdSI+RY7K3+dzjTSUTujVZwiYskT611CBvlDm9fhsNg==", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/@matrixai/async-locks/-/async-locks-4.0.0.tgz", + "integrity": "sha512-u/3fOdtjOKcDYF8dDoPR1/+7nmOkhxo42eBpXTEgfI0hLPGI37PoW7tjLvwy+O51Quy1HGOwhsR/Dgr4x+euug==", "requires": { - "@matrixai/errors": "^1.1.3", - "@matrixai/resources": "^1.1.4", - "async-mutex": "^0.3.2" + "@matrixai/async-cancellable": "^1.1.1", + "@matrixai/errors": "^1.1.7", + "@matrixai/resources": "^1.1.5", + "@matrixai/timer": "^1.1.1" } }, "@matrixai/errors": { @@ -8683,21 +8648,6 @@ "version": "2.0.0", "dev": true }, - "async-mutex": { - "version": "0.3.2", - "resolved": "https://registry.npmjs.org/async-mutex/-/async-mutex-0.3.2.tgz", - "integrity": "sha512-HuTK7E7MT7jZEh1P9GtRW9+aTWiDWWi9InbZ5hjxrnRa39KS4BW04+xLBhYNS2aXhHUIKZSw3gj4Pn1pj+qGAA==", - "requires": { - "tslib": "^2.3.1" - }, - "dependencies": { - "tslib": { - "version": "2.5.3", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.5.3.tgz", - "integrity": "sha512-mSxlJJwl3BMEQCUNnxXBU9jP4JBktcEGhURcPR6VQVlnP0FdDEsIaz0C35dXNGLyRfrATNofF0F5p2KPxQgB+w==" - } - } - }, "babel-jest": { "version": "28.1.3", "resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-28.1.3.tgz", diff --git a/package.json b/package.json index bf603618..7206b085 100644 --- a/package.json +++ b/package.json @@ -58,8 +58,8 @@ "node-forge": "^1.3.1", "node-gyp": "9.0.0", "prettier": "^2.6.2", - "shx": "^0.3.4", "semver": "^7.3.7", + "shx": "^0.3.4", "systeminformation": "^5.12.1", "ts-jest": "^28.0.5", "ts-node": "^10.9.1", diff --git a/tests/DBTransaction.test.ts b/tests/DBTransaction.test.ts index 4236a613..fb702d77 100644 --- a/tests/DBTransaction.test.ts +++ b/tests/DBTransaction.test.ts @@ -1035,9 +1035,9 @@ describe(DBTransaction.name, () => { ); await db.withTransactionF(async (tran2) => { await tran2.lock(['foo', 'read']); - await expect(tran2.lock(['bar', 'write', 0])).rejects.toThrow( - locksErrors.ErrorAsyncLocksTimeout, - ); + await expect( + tran2.lock(['bar', 'write', { timer: 0 }]), + ).rejects.toThrow(locksErrors.ErrorAsyncLocksTimeout); expect(tran1.locks.size).toBe(2); expect(tran1.locks.has('foo')).toBe(true); expect(tran1.locks.get('foo')!.type).toBe('read'); @@ -1097,9 +1097,9 @@ describe(DBTransaction.name, () => { // This is a noop, because `tran1` owns `key1` and `key2` await tran2.unlock('key1', 'key2'); // This fails because `key1` is still locked by `tran1` - await expect(tran2.lock(['key1', 'write', 0])).rejects.toThrow( - locksErrors.ErrorAsyncLocksTimeout, - ); + await expect( + tran2.lock(['key1', 'write', { timer: 0 }]), + ).rejects.toThrow(locksErrors.ErrorAsyncLocksTimeout); await tran1.unlock('key1'); expect(tran1.locks.size).toBe(1); // This succeeds because `key1` is now unlocked @@ -1109,9 +1109,9 @@ describe(DBTransaction.name, () => { await tran1.unlock('key1'); expect(tran2.locks.has('key1')).toBe(true); expect(tran1.locks.has('key1')).toBe(false); - await expect(tran1.lock(['key1', 'write', 0])).rejects.toThrow( - locksErrors.ErrorAsyncLocksTimeout, - ); + await expect( + tran1.lock(['key1', 'write', { timer: 0 }]), + ).rejects.toThrow(locksErrors.ErrorAsyncLocksTimeout); }); await tran1.lock('key1'); expect(tran1.locks.has('key1')).toBe(true); @@ -1126,8 +1126,8 @@ describe(DBTransaction.name, () => { // Currently a deadlock can happen, and the only way to avoid is to use timeouts // In the future, we want to have `DBTransaction` detect deadlocks // and automatically give us `ErrorDBTransactionDeadlock` exception - const p1 = tran1.lock(['bar', 'write', 50]); - const p2 = tran2.lock(['foo', 'write', 50]); + const p1 = tran1.lock(['bar', 'write', { timer: 50 }]); + const p2 = tran2.lock(['foo', 'write', { timer: 50 }]); const results = await Promise.allSettled([p1, p2]); expect( results.every(