diff --git a/.eslintrc b/.eslintrc index 7538a6443..ed7535105 100644 --- a/.eslintrc +++ b/.eslintrc @@ -50,7 +50,8 @@ }, "block": { "exceptions": ["*"] - } + }, + "markers": ["/"] } ], "capitalized-comments": [ diff --git a/benches/gitgc.ts b/benches/gitgc.ts index 983065cf1..5026436fb 100644 --- a/benches/gitgc.ts +++ b/benches/gitgc.ts @@ -2,7 +2,7 @@ import path from 'path'; import b from 'benny'; import { suiteCommon } from './utils'; -async function main () { +async function main() { let map = new Map(); let obj = {}; let arr: any = []; @@ -18,10 +18,10 @@ async function main () { for (let i = 0; i < 1000; i++) { map.delete(i); } - for (const i of map) { + for (const _i of map) { // NOOP } - } + }; }), b.add('obj', async () => { obj = {}; @@ -32,26 +32,26 @@ async function main () { for (let i = 0; i < 1000; i++) { delete obj[i]; } - for (const i in obj) { + for (const _i in obj) { // NOOP } }; }), b.add('arr', async () => { - // you first have to count the number of objects + // You first have to count the number of objects arr = []; return async () => { - // you have to iterate for each object + // You have to iterate for each object // then for each value in length for (let i = 0; i < 1000; i++) { if (i === arr.length) { - // double the vector + // Double the vector arr.length = arr.length * 2 || 2; } arr[i] = { id: i, mark: false }; - // arr.push({ id: i, mark: false}); + // Arr.push({ id: i, mark: false}); } - // this has to iterate the length of the array + // This has to iterate the length of the array // but stop as soon as it reaches the end // it gets complicate, but for 5x improvement // it could be interesting @@ -74,7 +74,7 @@ async function main () { for (let i = 0; i < 1000; i++) { set.delete(i); } - for (const i of set) { + for (const _i of set) { // NOOP } }; diff --git a/jest.config.js b/jest.config.js index 537d08f69..e0ae603c2 100644 --- a/jest.config.js +++ b/jest.config.js @@ -77,6 +77,9 @@ module.exports = { // Setup files after env are executed before each test file // after the jest test environment is installed // Can access globals - setupFilesAfterEnv: ['/tests/setupAfterEnv.ts'], + setupFilesAfterEnv: [ + 'jest-extended/all', + '/tests/setupAfterEnv.ts' + ], moduleNameMapper: moduleNameMapper, }; diff --git a/package-lock.json b/package-lock.json index 8a6203956..835225da2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,7 @@ "@grpc/grpc-js": "1.6.7", "@matrixai/async-init": "^1.8.2", "@matrixai/async-locks": "^3.1.2", - "@matrixai/db": "^4.0.5", + "@matrixai/db": "^5.0.3", "@matrixai/errors": "^1.1.3", "@matrixai/id": "^3.3.3", "@matrixai/logger": "^3.0.0", @@ -25,7 +25,7 @@ "commander": "^8.3.0", "cross-fetch": "^3.0.6", "cross-spawn": "^7.0.3", - "encryptedfs": "^3.5.5", + "encryptedfs": "^3.5.6", "fast-fuzzy": "^1.10.8", "fd-lock": "^1.2.0", "google-protobuf": "^3.14.0", @@ -69,8 +69,10 @@ "eslint-config-prettier": "^8.5.0", "eslint-plugin-import": "^2.26.0", "eslint-plugin-prettier": "^4.0.0", + "fast-check": "^3.0.1", "grpc_tools_node_protoc_ts": "^5.1.3", "jest": "^28.1.1", + "jest-extended": "^3.0.1", "jest-junit": "^14.0.0", "jest-mock-process": "^2.0.0", "jest-mock-props": "^1.9.1", @@ -2641,25 +2643,25 @@ } }, "node_modules/@matrixai/db": { - "version": "4.0.5", - "resolved": "https://registry.npmjs.org/@matrixai/db/-/db-4.0.5.tgz", - "integrity": "sha512-X3gBcyPxC+bTEfi1J1Y49n1bglvg7HjM8MKNH5s+OUEswqKSZgeg1uWfXqvUqq72yjBtgRi4Ghmy4MdrIB1oMw==", + "version": "5.0.3", + "resolved": "https://registry.npmjs.org/@matrixai/db/-/db-5.0.3.tgz", + "integrity": "sha512-/BNbg+vzFw8fv5e7KXZTXb5CvZvFUjwH5cI4l7kZ/kUHTWKgVSvdxz77h7njYDuhHStY6sSHnVAlWrgczFbQ8w==", + "hasInstallScript": true, "dependencies": { - "@matrixai/async-init": "^1.7.3", - "@matrixai/errors": "^1.1.1", - "@matrixai/logger": "^2.1.1", + "@matrixai/async-init": "^1.8.1", + "@matrixai/async-locks": "^3.1.1", + "@matrixai/errors": "^1.1.2", + "@matrixai/logger": "^3.0.0", "@matrixai/resources": "^1.1.3", - "@matrixai/workers": "^1.3.3", - "@types/abstract-leveldown": "^7.2.0", - "level": "7.0.1", + "@matrixai/workers": "^1.3.5", + "node-gyp-build": "4.4.0", "threads": "^1.6.5" + }, + "engines": { + "msvs": "2019", + "node": "^16.15.0" } }, - "node_modules/@matrixai/db/node_modules/@matrixai/logger": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/@matrixai/logger/-/logger-2.3.0.tgz", - "integrity": "sha512-DbsUv9eBubB2WxA8aGygnY/A2Ggm9a+ZnnnL2hIWWnE+sid92FK96gubW1a+u8OrXWx559HqUTBkcPDs83zV/A==" - }, "node_modules/@matrixai/errors": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/@matrixai/errors/-/errors-1.1.3.tgz", @@ -2843,134 +2845,6 @@ "@swc/core-win32-x64-msvc": "1.2.218" } }, - "node_modules/@swc/core-android-arm-eabi": { - "version": "1.2.218", - "resolved": "https://registry.npmjs.org/@swc/core-android-arm-eabi/-/core-android-arm-eabi-1.2.218.tgz", - "integrity": "sha512-Q/uLCh262t3xxNzhCz+ZW9t+g2nWd0gZZO4jMYFWJs7ilKVNsBfRtfnNGGACHzkVuWLNDIWtAS2PSNodl7VUHQ==", - "cpu": [ - "arm" - ], - "dev": true, - "optional": true, - "os": [ - "android" - ], - "engines": { - "node": ">=10" - } - }, - "node_modules/@swc/core-android-arm64": { - "version": "1.2.218", - "resolved": "https://registry.npmjs.org/@swc/core-android-arm64/-/core-android-arm64-1.2.218.tgz", - "integrity": "sha512-dy+8lUHUcyrkfPcl7azEQ4M44duRo1Uibz1E5/tltXCGoR6tu2ZN2VkqEKgA2a9XR3UD8/x4lv2r5evwJWy+uQ==", - "cpu": [ - "arm64" - ], - "dev": true, - "optional": true, - "os": [ - "android" - ], - "engines": { - "node": ">=10" - } - }, - "node_modules/@swc/core-darwin-arm64": { - "version": "1.2.218", - "resolved": "https://registry.npmjs.org/@swc/core-darwin-arm64/-/core-darwin-arm64-1.2.218.tgz", - "integrity": "sha512-aTpFjWio8G0oukN76VtXCBPtFzH0PXIQ+1dFjGGkzrBcU5suztCCbhPBGhKRoWp3NJBwfPDwwWzmG+ddXrVAKg==", - "cpu": [ - "arm64" - ], - "dev": true, - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">=10" - } - }, - "node_modules/@swc/core-darwin-x64": { - "version": "1.2.218", - "resolved": "https://registry.npmjs.org/@swc/core-darwin-x64/-/core-darwin-x64-1.2.218.tgz", - "integrity": "sha512-H3w/gNzROE6gVPZCAg5qvvPihzlg88Yi7HWb/mowfpNqH9/iJ8XMdwqJyovnfUeUXsuJQBFv6uXv/ri7qhGMHA==", - "cpu": [ - "x64" - ], - "dev": true, - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">=10" - } - }, - "node_modules/@swc/core-freebsd-x64": { - "version": "1.2.218", - "resolved": "https://registry.npmjs.org/@swc/core-freebsd-x64/-/core-freebsd-x64-1.2.218.tgz", - "integrity": "sha512-kkch07yCSlpUrSMp0FZPWtMHJjh3lfHiwp7JYNf6CUl5xXlgT19NeomPYq31dbTzPV2VnE7TVVlAawIjuuOH4g==", - "cpu": [ - "x64" - ], - "dev": true, - "optional": true, - "os": [ - "freebsd" - ], - "engines": { - "node": ">=10" - } - }, - "node_modules/@swc/core-linux-arm-gnueabihf": { - "version": "1.2.218", - "resolved": "https://registry.npmjs.org/@swc/core-linux-arm-gnueabihf/-/core-linux-arm-gnueabihf-1.2.218.tgz", - "integrity": "sha512-vwEgvtD9f/+0HFxYD5q4sd8SG6zd0cxm17cwRGZ6jWh/d4Ninjht3CpDGE1ffh9nJ+X3Mb/7rjU/kTgWFz5qfg==", - "cpu": [ - "arm" - ], - "dev": true, - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=10" - } - }, - "node_modules/@swc/core-linux-arm64-gnu": { - "version": "1.2.218", - "resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-gnu/-/core-linux-arm64-gnu-1.2.218.tgz", - "integrity": "sha512-g5PQI6COUHV7x7tyaZQn6jXWtOLXXNIEQK1HS5/e+6kqqsM2NsndE9bjLhoH1EQuXiN2eUjAR/ZDOFAg102aRw==", - "cpu": [ - "arm64" - ], - "dev": true, - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=10" - } - }, - "node_modules/@swc/core-linux-arm64-musl": { - "version": "1.2.218", - "resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-musl/-/core-linux-arm64-musl-1.2.218.tgz", - "integrity": "sha512-IETYHB6H01NmVmlw+Ng8nkjdFBv1exGQRR74GAnHis1bVx1Uq14hREIF6XT3I1Aj26nRwlGkIYQuEKnFO5/j3Q==", - "cpu": [ - "arm64" - ], - "dev": true, - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=10" - } - }, "node_modules/@swc/core-linux-x64-gnu": { "version": "1.2.218", "resolved": "https://registry.npmjs.org/@swc/core-linux-x64-gnu/-/core-linux-x64-gnu-1.2.218.tgz", @@ -3003,54 +2877,6 @@ "node": ">=10" } }, - "node_modules/@swc/core-win32-arm64-msvc": { - "version": "1.2.218", - "resolved": "https://registry.npmjs.org/@swc/core-win32-arm64-msvc/-/core-win32-arm64-msvc-1.2.218.tgz", - "integrity": "sha512-lVXFWkYl+w8+deq9mgGsfvSY5Gr1RRjFgqZ+0wMZgyaonfx7jNn3TILUwc7egumEwxK0anNriVZCyKfcO3ZIjA==", - "cpu": [ - "arm64" - ], - "dev": true, - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">=10" - } - }, - "node_modules/@swc/core-win32-ia32-msvc": { - "version": "1.2.218", - "resolved": "https://registry.npmjs.org/@swc/core-win32-ia32-msvc/-/core-win32-ia32-msvc-1.2.218.tgz", - "integrity": "sha512-jgP+NZsHUh9Cp8PcXznnkpJTW3hPDLUgsXI0NKfE+8+Xvc6hALHxl6K46IyPYU67FfFlegYcBSNkOgpc85gk0A==", - "cpu": [ - "ia32" - ], - "dev": true, - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">=10" - } - }, - "node_modules/@swc/core-win32-x64-msvc": { - "version": "1.2.218", - "resolved": "https://registry.npmjs.org/@swc/core-win32-x64-msvc/-/core-win32-x64-msvc-1.2.218.tgz", - "integrity": "sha512-XYLjX00KV4ft324Q3QDkw61xHkoN7EKkVvIpb0wXaf6wVshwU+BCDyPw2CSg4PQecNP8QGgMRQf9QM7xNtEM7A==", - "cpu": [ - "x64" - ], - "dev": true, - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">=10" - } - }, "node_modules/@tsconfig/node10": { "version": "1.0.9", "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.9.tgz", @@ -3075,11 +2901,6 @@ "integrity": "sha512-yOlFc+7UtL/89t2ZhjPvvB/DeAr3r+Dq58IgzsFkOAvVC6NMJXmCGjbptdXdR9qsX7pKcTL+s87FtYREi2dEEQ==", "dev": true }, - "node_modules/@types/abstract-leveldown": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/@types/abstract-leveldown/-/abstract-leveldown-7.2.0.tgz", - "integrity": "sha512-q5veSX6zjUy/DlDhR4Y4cU0k2Ar+DT2LUraP00T19WLmTO6Se1djepCCaqU6nQrwcJ5Hyo/CWqxTzrrFg8eqbQ==" - }, "node_modules/@types/babel__core": { "version": "7.1.19", "resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.1.19.tgz", @@ -3491,22 +3312,6 @@ "url": "https://opencollective.com/typescript-eslint" } }, - "node_modules/abstract-leveldown": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/abstract-leveldown/-/abstract-leveldown-7.2.0.tgz", - "integrity": "sha512-DnhQwcFEaYsvYDnACLZhMmCWd3rkOeEvglpa4q5i/5Jlm3UIsWaxVzuXvDLFCSCWRO3yy2/+V/G7FusFgejnfQ==", - "dependencies": { - "buffer": "^6.0.3", - "catering": "^2.0.0", - "is-buffer": "^2.0.5", - "level-concat-iterator": "^3.0.0", - "level-supports": "^2.0.1", - "queue-microtask": "^1.2.3" - }, - "engines": { - "node": ">=10" - } - }, "node_modules/acorn": { "version": "8.7.1", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.7.1.tgz", @@ -3992,6 +3797,7 @@ "version": "1.5.1", "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==", + "dev": true, "funding": [ { "type": "github", @@ -4196,29 +4002,6 @@ "node-int64": "^0.4.0" } }, - "node_modules/buffer": { - "version": "6.0.3", - "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", - "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ], - "dependencies": { - "base64-js": "^1.3.1", - "ieee754": "^1.2.1" - } - }, "node_modules/buffer-from": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", @@ -4275,14 +4058,6 @@ "resolved": "https://registry.npmjs.org/canonicalize/-/canonicalize-1.0.8.tgz", "integrity": "sha512-0CNTVCLZggSh7bc5VkX5WWPWO+cyZbNd07IHIsSXLia/eAq+r836hgk+8BKoEh7949Mda87VUOitx5OddVj64A==" }, - "node_modules/catering": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/catering/-/catering-2.1.1.tgz", - "integrity": "sha512-K7Qy8O9p76sL3/3m7/zLKbRkyOlSZAgzEaLhyj2mXS8PsCud2Eo4hAb8aLtZqHh0QGqLcb9dlJSu6lHRVENm1w==", - "engines": { - "node": ">=6" - } - }, "node_modules/chalk": { "version": "2.4.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", @@ -4696,18 +4471,6 @@ "node": ">=0.10.0" } }, - "node_modules/deferred-leveldown": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/deferred-leveldown/-/deferred-leveldown-7.0.0.tgz", - "integrity": "sha512-QKN8NtuS3BC6m0B8vAnBls44tX1WXAFATUsJlruyAYbZpysWV3siH6o/i3g9DCHauzodksO60bdj5NazNbjCmg==", - "dependencies": { - "abstract-leveldown": "^7.2.0", - "inherits": "^2.0.3" - }, - "engines": { - "node": ">=10" - } - }, "node_modules/define-properties": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.4.tgz", @@ -4871,28 +4634,14 @@ "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==" }, - "node_modules/encoding-down": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/encoding-down/-/encoding-down-7.1.0.tgz", - "integrity": "sha512-ky47X5jP84ryk5EQmvedQzELwVJPjCgXDQZGeb9F6r4PdChByCGHTBrVcF3h8ynKVJ1wVbkxTsDC8zBROPypgQ==", - "dependencies": { - "abstract-leveldown": "^7.2.0", - "inherits": "^2.0.3", - "level-codec": "^10.0.0", - "level-errors": "^3.0.0" - }, - "engines": { - "node": ">=10" - } - }, "node_modules/encryptedfs": { - "version": "3.5.5", - "resolved": "https://registry.npmjs.org/encryptedfs/-/encryptedfs-3.5.5.tgz", - "integrity": "sha512-aLuRH7Q2hVYXpz6o8EG0TsZEm04rjPFdFo9U04PTZd0uk0wn5xcKCyBbioSg6fHaD7sSRGFn1k6HRmvt5MSV9A==", + "version": "3.5.6", + "resolved": "https://registry.npmjs.org/encryptedfs/-/encryptedfs-3.5.6.tgz", + "integrity": "sha512-fK7MASgrNFhY2P6GVnwiThFrgQF/9Vnh/POLHUp/ROu7OgZcz4pJO0KTae1W+rX7iz13U58B6bdD2Q4pbfGipA==", "dependencies": { "@matrixai/async-init": "^1.8.2", "@matrixai/async-locks": "^3.1.2", - "@matrixai/db": "^4.0.2", + "@matrixai/db": "^5.0.3", "@matrixai/errors": "^1.1.3", "@matrixai/logger": "^3.0.0", "@matrixai/resources": "^1.1.4", @@ -5739,6 +5488,22 @@ "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" } }, + "node_modules/fast-check": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/fast-check/-/fast-check-3.0.1.tgz", + "integrity": "sha512-AriFDYpYVOBynpPZq/quxSLumFOo2hPB2H5Nz2vc1QlNfjOaA62zX8USNXcOY5nwKHEq7lZ84dG9M1W+LAND1g==", + "dev": true, + "dependencies": { + "pure-rand": "^5.0.1" + }, + "engines": { + "node": ">=8.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/fast-check" + } + }, "node_modules/fast-deep-equal": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", @@ -5949,20 +5714,6 @@ "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==", "dev": true }, - "node_modules/fsevents": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", - "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", - "dev": true, - "hasInstallScript": true, - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": "^8.16.0 || ^10.6.0 || >=11.0.0" - } - }, "node_modules/function-bind": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", @@ -6362,6 +6113,7 @@ "version": "1.2.1", "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==", + "dev": true, "funding": [ { "type": "github", @@ -6534,28 +6286,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/is-buffer": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.5.tgz", - "integrity": "sha512-i2R6zNFDwgEHJyQUtJEk0XFi1i0dPFn/oqjK3/vPCcDeJvW5NQ83V8QbicfF1SupOaB0h8ntgBC2YiE7dfyctQ==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ], - "engines": { - "node": ">=4" - } - }, "node_modules/is-callable": { "version": "1.2.4", "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.2.4.tgz", @@ -7487,6 +7217,22 @@ "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" } }, + "node_modules/jest-extended": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/jest-extended/-/jest-extended-3.0.1.tgz", + "integrity": "sha512-OSGbKUhbjy7QikfQyK3ishFrAqLeRodBzeJk7SuuWGACAT7HHcGuJ4aUQ3ueLANx4KSv1Pa7r1LJWGtJ3eI0xA==", + "dev": true, + "dependencies": { + "jest-diff": "^28.0.0", + "jest-get-type": "^28.0.0" + }, + "engines": { + "node": "^14.15.0 || ^16.13.0 || >=18.0.0" + }, + "peerDependencies": { + "jest": ">=27.2.5" + } + }, "node_modules/jest-get-type": { "version": "28.0.2", "resolved": "https://registry.npmjs.org/jest-get-type/-/jest-get-type-28.0.2.tgz", @@ -8668,127 +8414,6 @@ "node": "> 0.8" } }, - "node_modules/level": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/level/-/level-7.0.1.tgz", - "integrity": "sha512-w3E64+ALx2eZf8RV5JL4kIcE0BFAvQscRYd1yU4YVqZN9RGTQxXSvH202xvK15yZwFFxRXe60f13LJjcJ//I4Q==", - "dependencies": { - "level-js": "^6.1.0", - "level-packager": "^6.0.1", - "leveldown": "^6.1.0" - }, - "engines": { - "node": ">=10.12.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/level" - } - }, - "node_modules/level-codec": { - "version": "10.0.0", - "resolved": "https://registry.npmjs.org/level-codec/-/level-codec-10.0.0.tgz", - "integrity": "sha512-QW3VteVNAp6c/LuV6nDjg7XDXx9XHK4abmQarxZmlRSDyXYk20UdaJTSX6yzVvQ4i0JyWSB7jert0DsyD/kk6g==", - "dependencies": { - "buffer": "^6.0.3" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/level-concat-iterator": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/level-concat-iterator/-/level-concat-iterator-3.1.0.tgz", - "integrity": "sha512-BWRCMHBxbIqPxJ8vHOvKUsaO0v1sLYZtjN3K2iZJsRBYtp+ONsY6Jfi6hy9K3+zolgQRryhIn2NRZjZnWJ9NmQ==", - "dependencies": { - "catering": "^2.1.0" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/level-errors": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/level-errors/-/level-errors-3.0.1.tgz", - "integrity": "sha512-tqTL2DxzPDzpwl0iV5+rBCv65HWbHp6eutluHNcVIftKZlQN//b6GEnZDM2CvGZvzGYMwyPtYppYnydBQd2SMQ==", - "engines": { - "node": ">=10" - } - }, - "node_modules/level-iterator-stream": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/level-iterator-stream/-/level-iterator-stream-5.0.0.tgz", - "integrity": "sha512-wnb1+o+CVFUDdiSMR/ZymE2prPs3cjVLlXuDeSq9Zb8o032XrabGEXcTCsBxprAtseO3qvFeGzh6406z9sOTRA==", - "dependencies": { - "inherits": "^2.0.4", - "readable-stream": "^3.4.0" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/level-js": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/level-js/-/level-js-6.1.0.tgz", - "integrity": "sha512-i7mPtkZm68aewfv0FnIUWvFUFfoyzIvVKnUmuQGrelEkP72vSPTaA1SGneWWoCV5KZJG4wlzbJLp1WxVNGuc6A==", - "dependencies": { - "abstract-leveldown": "^7.2.0", - "buffer": "^6.0.3", - "inherits": "^2.0.3", - "ltgt": "^2.1.2", - "run-parallel-limit": "^1.1.0" - } - }, - "node_modules/level-packager": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/level-packager/-/level-packager-6.0.1.tgz", - "integrity": "sha512-8Ezr0XM6hmAwqX9uu8IGzGNkWz/9doyPA8Oo9/D7qcMI6meJC+XhIbNYHukJhIn8OGdlzQs/JPcL9B8lA2F6EQ==", - "dependencies": { - "encoding-down": "^7.1.0", - "levelup": "^5.1.1" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/level-supports": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/level-supports/-/level-supports-2.1.0.tgz", - "integrity": "sha512-E486g1NCjW5cF78KGPrMDRBYzPuueMZ6VBXHT6gC7A8UYWGiM14fGgp+s/L1oFfDWSPV/+SFkYCmZ0SiESkRKA==", - "engines": { - "node": ">=10" - } - }, - "node_modules/leveldown": { - "version": "6.1.1", - "resolved": "https://registry.npmjs.org/leveldown/-/leveldown-6.1.1.tgz", - "integrity": "sha512-88c+E+Eizn4CkQOBHwqlCJaTNEjGpaEIikn1S+cINc5E9HEvJ77bqY4JY/HxT5u0caWqsc3P3DcFIKBI1vHt+A==", - "hasInstallScript": true, - "dependencies": { - "abstract-leveldown": "^7.2.0", - "napi-macros": "~2.0.0", - "node-gyp-build": "^4.3.0" - }, - "engines": { - "node": ">=10.12.0" - } - }, - "node_modules/levelup": { - "version": "5.1.1", - "resolved": "https://registry.npmjs.org/levelup/-/levelup-5.1.1.tgz", - "integrity": "sha512-0mFCcHcEebOwsQuk00WJwjLI6oCjbBuEYdh/RaRqhjnyVlzqf41T1NnDtCedumZ56qyIh8euLFDqV1KfzTAVhg==", - "dependencies": { - "catering": "^2.0.0", - "deferred-leveldown": "^7.0.0", - "level-errors": "^3.0.1", - "level-iterator-stream": "^5.0.0", - "level-supports": "^2.0.1", - "queue-microtask": "^1.2.3" - }, - "engines": { - "node": ">=10" - } - }, "node_modules/leven": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/leven/-/leven-3.1.0.tgz", @@ -8974,11 +8599,6 @@ "node": ">=10" } }, - "node_modules/ltgt": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/ltgt/-/ltgt-2.2.1.tgz", - "integrity": "sha512-AI2r85+4MquTw9ZYqabu4nMwy9Oftlfa/e/52t9IjtfG+mGBbTNdAoZ3RQKLHR6r0wQnwZnPIEh/Ya6XTWAKNA==" - }, "node_modules/lunr": { "version": "2.3.9", "resolved": "https://registry.npmjs.org/lunr/-/lunr-2.3.9.tgz", @@ -10206,10 +9826,21 @@ "node": ">=6" } }, + "node_modules/pure-rand": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/pure-rand/-/pure-rand-5.0.1.tgz", + "integrity": "sha512-ksWccjmXOHU2gJBnH0cK1lSYdvSZ0zLoCMSz/nTGh6hDvCSgcRxDyIcOBD6KNxFz3xhMPm/T267Tbe2JRymKEQ==", + "dev": true, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/fast-check" + } + }, "node_modules/queue-microtask": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz", "integrity": "sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==", + "dev": true, "funding": [ { "type": "github", @@ -10544,28 +10175,6 @@ "queue-microtask": "^1.2.2" } }, - "node_modules/run-parallel-limit": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/run-parallel-limit/-/run-parallel-limit-1.1.0.tgz", - "integrity": "sha512-jJA7irRNM91jaKc3Hcl1npHsFLOXOoTkPCUL1JEa1R82O2miplXXRaGdjW/KM/98YQWDhJLiSs793CnXfblJUw==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ], - "dependencies": { - "queue-microtask": "^1.2.2" - } - }, "node_modules/safe-buffer": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", @@ -13799,25 +13408,18 @@ } }, "@matrixai/db": { - "version": "4.0.5", - "resolved": "https://registry.npmjs.org/@matrixai/db/-/db-4.0.5.tgz", - "integrity": "sha512-X3gBcyPxC+bTEfi1J1Y49n1bglvg7HjM8MKNH5s+OUEswqKSZgeg1uWfXqvUqq72yjBtgRi4Ghmy4MdrIB1oMw==", + "version": "5.0.3", + "resolved": "https://registry.npmjs.org/@matrixai/db/-/db-5.0.3.tgz", + "integrity": "sha512-/BNbg+vzFw8fv5e7KXZTXb5CvZvFUjwH5cI4l7kZ/kUHTWKgVSvdxz77h7njYDuhHStY6sSHnVAlWrgczFbQ8w==", "requires": { - "@matrixai/async-init": "^1.7.3", - "@matrixai/errors": "^1.1.1", - "@matrixai/logger": "^2.1.1", + "@matrixai/async-init": "^1.8.1", + "@matrixai/async-locks": "^3.1.1", + "@matrixai/errors": "^1.1.2", + "@matrixai/logger": "^3.0.0", "@matrixai/resources": "^1.1.3", - "@matrixai/workers": "^1.3.3", - "@types/abstract-leveldown": "^7.2.0", - "level": "7.0.1", + "@matrixai/workers": "^1.3.5", + "node-gyp-build": "4.4.0", "threads": "^1.6.5" - }, - "dependencies": { - "@matrixai/logger": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/@matrixai/logger/-/logger-2.3.0.tgz", - "integrity": "sha512-DbsUv9eBubB2WxA8aGygnY/A2Ggm9a+ZnnnL2hIWWnE+sid92FK96gubW1a+u8OrXWx559HqUTBkcPDs83zV/A==" - } } }, "@matrixai/errors": { @@ -13983,62 +13585,6 @@ "@swc/core-win32-x64-msvc": "1.2.218" } }, - "@swc/core-android-arm-eabi": { - "version": "1.2.218", - "resolved": "https://registry.npmjs.org/@swc/core-android-arm-eabi/-/core-android-arm-eabi-1.2.218.tgz", - "integrity": "sha512-Q/uLCh262t3xxNzhCz+ZW9t+g2nWd0gZZO4jMYFWJs7ilKVNsBfRtfnNGGACHzkVuWLNDIWtAS2PSNodl7VUHQ==", - "dev": true, - "optional": true - }, - "@swc/core-android-arm64": { - "version": "1.2.218", - "resolved": "https://registry.npmjs.org/@swc/core-android-arm64/-/core-android-arm64-1.2.218.tgz", - "integrity": "sha512-dy+8lUHUcyrkfPcl7azEQ4M44duRo1Uibz1E5/tltXCGoR6tu2ZN2VkqEKgA2a9XR3UD8/x4lv2r5evwJWy+uQ==", - "dev": true, - "optional": true - }, - "@swc/core-darwin-arm64": { - "version": "1.2.218", - "resolved": "https://registry.npmjs.org/@swc/core-darwin-arm64/-/core-darwin-arm64-1.2.218.tgz", - "integrity": "sha512-aTpFjWio8G0oukN76VtXCBPtFzH0PXIQ+1dFjGGkzrBcU5suztCCbhPBGhKRoWp3NJBwfPDwwWzmG+ddXrVAKg==", - "dev": true, - "optional": true - }, - "@swc/core-darwin-x64": { - "version": "1.2.218", - "resolved": "https://registry.npmjs.org/@swc/core-darwin-x64/-/core-darwin-x64-1.2.218.tgz", - "integrity": "sha512-H3w/gNzROE6gVPZCAg5qvvPihzlg88Yi7HWb/mowfpNqH9/iJ8XMdwqJyovnfUeUXsuJQBFv6uXv/ri7qhGMHA==", - "dev": true, - "optional": true - }, - "@swc/core-freebsd-x64": { - "version": "1.2.218", - "resolved": "https://registry.npmjs.org/@swc/core-freebsd-x64/-/core-freebsd-x64-1.2.218.tgz", - "integrity": "sha512-kkch07yCSlpUrSMp0FZPWtMHJjh3lfHiwp7JYNf6CUl5xXlgT19NeomPYq31dbTzPV2VnE7TVVlAawIjuuOH4g==", - "dev": true, - "optional": true - }, - "@swc/core-linux-arm-gnueabihf": { - "version": "1.2.218", - "resolved": "https://registry.npmjs.org/@swc/core-linux-arm-gnueabihf/-/core-linux-arm-gnueabihf-1.2.218.tgz", - "integrity": "sha512-vwEgvtD9f/+0HFxYD5q4sd8SG6zd0cxm17cwRGZ6jWh/d4Ninjht3CpDGE1ffh9nJ+X3Mb/7rjU/kTgWFz5qfg==", - "dev": true, - "optional": true - }, - "@swc/core-linux-arm64-gnu": { - "version": "1.2.218", - "resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-gnu/-/core-linux-arm64-gnu-1.2.218.tgz", - "integrity": "sha512-g5PQI6COUHV7x7tyaZQn6jXWtOLXXNIEQK1HS5/e+6kqqsM2NsndE9bjLhoH1EQuXiN2eUjAR/ZDOFAg102aRw==", - "dev": true, - "optional": true - }, - "@swc/core-linux-arm64-musl": { - "version": "1.2.218", - "resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-musl/-/core-linux-arm64-musl-1.2.218.tgz", - "integrity": "sha512-IETYHB6H01NmVmlw+Ng8nkjdFBv1exGQRR74GAnHis1bVx1Uq14hREIF6XT3I1Aj26nRwlGkIYQuEKnFO5/j3Q==", - "dev": true, - "optional": true - }, "@swc/core-linux-x64-gnu": { "version": "1.2.218", "resolved": "https://registry.npmjs.org/@swc/core-linux-x64-gnu/-/core-linux-x64-gnu-1.2.218.tgz", @@ -14053,27 +13599,6 @@ "dev": true, "optional": true }, - "@swc/core-win32-arm64-msvc": { - "version": "1.2.218", - "resolved": "https://registry.npmjs.org/@swc/core-win32-arm64-msvc/-/core-win32-arm64-msvc-1.2.218.tgz", - "integrity": "sha512-lVXFWkYl+w8+deq9mgGsfvSY5Gr1RRjFgqZ+0wMZgyaonfx7jNn3TILUwc7egumEwxK0anNriVZCyKfcO3ZIjA==", - "dev": true, - "optional": true - }, - "@swc/core-win32-ia32-msvc": { - "version": "1.2.218", - "resolved": "https://registry.npmjs.org/@swc/core-win32-ia32-msvc/-/core-win32-ia32-msvc-1.2.218.tgz", - "integrity": "sha512-jgP+NZsHUh9Cp8PcXznnkpJTW3hPDLUgsXI0NKfE+8+Xvc6hALHxl6K46IyPYU67FfFlegYcBSNkOgpc85gk0A==", - "dev": true, - "optional": true - }, - "@swc/core-win32-x64-msvc": { - "version": "1.2.218", - "resolved": "https://registry.npmjs.org/@swc/core-win32-x64-msvc/-/core-win32-x64-msvc-1.2.218.tgz", - "integrity": "sha512-XYLjX00KV4ft324Q3QDkw61xHkoN7EKkVvIpb0wXaf6wVshwU+BCDyPw2CSg4PQecNP8QGgMRQf9QM7xNtEM7A==", - "dev": true, - "optional": true - }, "@tsconfig/node10": { "version": "1.0.9", "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.9.tgz", @@ -14098,11 +13623,6 @@ "integrity": "sha512-yOlFc+7UtL/89t2ZhjPvvB/DeAr3r+Dq58IgzsFkOAvVC6NMJXmCGjbptdXdR9qsX7pKcTL+s87FtYREi2dEEQ==", "dev": true }, - "@types/abstract-leveldown": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/@types/abstract-leveldown/-/abstract-leveldown-7.2.0.tgz", - "integrity": "sha512-q5veSX6zjUy/DlDhR4Y4cU0k2Ar+DT2LUraP00T19WLmTO6Se1djepCCaqU6nQrwcJ5Hyo/CWqxTzrrFg8eqbQ==" - }, "@types/babel__core": { "version": "7.1.19", "resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.1.19.tgz", @@ -14417,19 +13937,6 @@ "eslint-visitor-keys": "^3.3.0" } }, - "abstract-leveldown": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/abstract-leveldown/-/abstract-leveldown-7.2.0.tgz", - "integrity": "sha512-DnhQwcFEaYsvYDnACLZhMmCWd3rkOeEvglpa4q5i/5Jlm3UIsWaxVzuXvDLFCSCWRO3yy2/+V/G7FusFgejnfQ==", - "requires": { - "buffer": "^6.0.3", - "catering": "^2.0.0", - "is-buffer": "^2.0.5", - "level-concat-iterator": "^3.0.0", - "level-supports": "^2.0.1", - "queue-microtask": "^1.2.3" - } - }, "acorn": { "version": "8.7.1", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.7.1.tgz", @@ -14812,7 +14319,8 @@ "base64-js": { "version": "1.5.1", "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", - "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==" + "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==", + "dev": true }, "benchmark": { "version": "2.1.4", @@ -14961,15 +14469,6 @@ "node-int64": "^0.4.0" } }, - "buffer": { - "version": "6.0.3", - "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", - "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", - "requires": { - "base64-js": "^1.3.1", - "ieee754": "^1.2.1" - } - }, "buffer-from": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", @@ -15007,11 +14506,6 @@ "resolved": "https://registry.npmjs.org/canonicalize/-/canonicalize-1.0.8.tgz", "integrity": "sha512-0CNTVCLZggSh7bc5VkX5WWPWO+cyZbNd07IHIsSXLia/eAq+r836hgk+8BKoEh7949Mda87VUOitx5OddVj64A==" }, - "catering": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/catering/-/catering-2.1.1.tgz", - "integrity": "sha512-K7Qy8O9p76sL3/3m7/zLKbRkyOlSZAgzEaLhyj2mXS8PsCud2Eo4hAb8aLtZqHh0QGqLcb9dlJSu6lHRVENm1w==" - }, "chalk": { "version": "2.4.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", @@ -15344,15 +14838,6 @@ "integrity": "sha512-FJ3UgI4gIl+PHZm53knsuSFpE+nESMr7M4v9QcgB7S63Kj/6WqMiFQJpBBYz1Pt+66bZpP3Q7Lye0Oo9MPKEdg==", "dev": true }, - "deferred-leveldown": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/deferred-leveldown/-/deferred-leveldown-7.0.0.tgz", - "integrity": "sha512-QKN8NtuS3BC6m0B8vAnBls44tX1WXAFATUsJlruyAYbZpysWV3siH6o/i3g9DCHauzodksO60bdj5NazNbjCmg==", - "requires": { - "abstract-leveldown": "^7.2.0", - "inherits": "^2.0.3" - } - }, "define-properties": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.4.tgz", @@ -15465,25 +14950,14 @@ "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==" }, - "encoding-down": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/encoding-down/-/encoding-down-7.1.0.tgz", - "integrity": "sha512-ky47X5jP84ryk5EQmvedQzELwVJPjCgXDQZGeb9F6r4PdChByCGHTBrVcF3h8ynKVJ1wVbkxTsDC8zBROPypgQ==", - "requires": { - "abstract-leveldown": "^7.2.0", - "inherits": "^2.0.3", - "level-codec": "^10.0.0", - "level-errors": "^3.0.0" - } - }, "encryptedfs": { - "version": "3.5.5", - "resolved": "https://registry.npmjs.org/encryptedfs/-/encryptedfs-3.5.5.tgz", - "integrity": "sha512-aLuRH7Q2hVYXpz6o8EG0TsZEm04rjPFdFo9U04PTZd0uk0wn5xcKCyBbioSg6fHaD7sSRGFn1k6HRmvt5MSV9A==", + "version": "3.5.6", + "resolved": "https://registry.npmjs.org/encryptedfs/-/encryptedfs-3.5.6.tgz", + "integrity": "sha512-fK7MASgrNFhY2P6GVnwiThFrgQF/9Vnh/POLHUp/ROu7OgZcz4pJO0KTae1W+rX7iz13U58B6bdD2Q4pbfGipA==", "requires": { "@matrixai/async-init": "^1.8.2", "@matrixai/async-locks": "^3.1.2", - "@matrixai/db": "^4.0.2", + "@matrixai/db": "^5.0.3", "@matrixai/errors": "^1.1.3", "@matrixai/logger": "^3.0.0", "@matrixai/resources": "^1.1.4", @@ -16122,6 +15596,15 @@ "jest-util": "^28.1.1" } }, + "fast-check": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/fast-check/-/fast-check-3.0.1.tgz", + "integrity": "sha512-AriFDYpYVOBynpPZq/quxSLumFOo2hPB2H5Nz2vc1QlNfjOaA62zX8USNXcOY5nwKHEq7lZ84dG9M1W+LAND1g==", + "dev": true, + "requires": { + "pure-rand": "^5.0.1" + } + }, "fast-deep-equal": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", @@ -16314,13 +15797,6 @@ "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==", "dev": true }, - "fsevents": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", - "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", - "dev": true, - "optional": true - }, "function-bind": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", @@ -16615,7 +16091,8 @@ "ieee754": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", - "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==" + "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==", + "dev": true }, "ignore": { "version": "5.2.0", @@ -16731,11 +16208,6 @@ "has-tostringtag": "^1.0.0" } }, - "is-buffer": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.5.tgz", - "integrity": "sha512-i2R6zNFDwgEHJyQUtJEk0XFi1i0dPFn/oqjK3/vPCcDeJvW5NQ83V8QbicfF1SupOaB0h8ntgBC2YiE7dfyctQ==" - }, "is-callable": { "version": "1.2.4", "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.2.4.tgz", @@ -17396,6 +16868,16 @@ "jest-util": "^28.1.1" } }, + "jest-extended": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/jest-extended/-/jest-extended-3.0.1.tgz", + "integrity": "sha512-OSGbKUhbjy7QikfQyK3ishFrAqLeRodBzeJk7SuuWGACAT7HHcGuJ4aUQ3ueLANx4KSv1Pa7r1LJWGtJ3eI0xA==", + "dev": true, + "requires": { + "jest-diff": "^28.0.0", + "jest-get-type": "^28.0.0" + } + }, "jest-get-type": { "version": "28.0.2", "resolved": "https://registry.npmjs.org/jest-get-type/-/jest-get-type-28.0.2.tgz", @@ -18280,95 +17762,6 @@ "integrity": "sha512-cc8oEVoctTvsFZ/Oje/kGnHbpWHYBe8IAJe4C0QNc3t8uM/0Y8+erSz/7Y1ALuXTEZTMvxXwO6YbX1ey3ujiZw==", "dev": true }, - "level": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/level/-/level-7.0.1.tgz", - "integrity": "sha512-w3E64+ALx2eZf8RV5JL4kIcE0BFAvQscRYd1yU4YVqZN9RGTQxXSvH202xvK15yZwFFxRXe60f13LJjcJ//I4Q==", - "requires": { - "level-js": "^6.1.0", - "level-packager": "^6.0.1", - "leveldown": "^6.1.0" - } - }, - "level-codec": { - "version": "10.0.0", - "resolved": "https://registry.npmjs.org/level-codec/-/level-codec-10.0.0.tgz", - "integrity": "sha512-QW3VteVNAp6c/LuV6nDjg7XDXx9XHK4abmQarxZmlRSDyXYk20UdaJTSX6yzVvQ4i0JyWSB7jert0DsyD/kk6g==", - "requires": { - "buffer": "^6.0.3" - } - }, - "level-concat-iterator": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/level-concat-iterator/-/level-concat-iterator-3.1.0.tgz", - "integrity": "sha512-BWRCMHBxbIqPxJ8vHOvKUsaO0v1sLYZtjN3K2iZJsRBYtp+ONsY6Jfi6hy9K3+zolgQRryhIn2NRZjZnWJ9NmQ==", - "requires": { - "catering": "^2.1.0" - } - }, - "level-errors": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/level-errors/-/level-errors-3.0.1.tgz", - "integrity": "sha512-tqTL2DxzPDzpwl0iV5+rBCv65HWbHp6eutluHNcVIftKZlQN//b6GEnZDM2CvGZvzGYMwyPtYppYnydBQd2SMQ==" - }, - "level-iterator-stream": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/level-iterator-stream/-/level-iterator-stream-5.0.0.tgz", - "integrity": "sha512-wnb1+o+CVFUDdiSMR/ZymE2prPs3cjVLlXuDeSq9Zb8o032XrabGEXcTCsBxprAtseO3qvFeGzh6406z9sOTRA==", - "requires": { - "inherits": "^2.0.4", - "readable-stream": "^3.4.0" - } - }, - "level-js": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/level-js/-/level-js-6.1.0.tgz", - "integrity": "sha512-i7mPtkZm68aewfv0FnIUWvFUFfoyzIvVKnUmuQGrelEkP72vSPTaA1SGneWWoCV5KZJG4wlzbJLp1WxVNGuc6A==", - "requires": { - "abstract-leveldown": "^7.2.0", - "buffer": "^6.0.3", - "inherits": "^2.0.3", - "ltgt": "^2.1.2", - "run-parallel-limit": "^1.1.0" - } - }, - "level-packager": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/level-packager/-/level-packager-6.0.1.tgz", - "integrity": "sha512-8Ezr0XM6hmAwqX9uu8IGzGNkWz/9doyPA8Oo9/D7qcMI6meJC+XhIbNYHukJhIn8OGdlzQs/JPcL9B8lA2F6EQ==", - "requires": { - "encoding-down": "^7.1.0", - "levelup": "^5.1.1" - } - }, - "level-supports": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/level-supports/-/level-supports-2.1.0.tgz", - "integrity": "sha512-E486g1NCjW5cF78KGPrMDRBYzPuueMZ6VBXHT6gC7A8UYWGiM14fGgp+s/L1oFfDWSPV/+SFkYCmZ0SiESkRKA==" - }, - "leveldown": { - "version": "6.1.1", - "resolved": "https://registry.npmjs.org/leveldown/-/leveldown-6.1.1.tgz", - "integrity": "sha512-88c+E+Eizn4CkQOBHwqlCJaTNEjGpaEIikn1S+cINc5E9HEvJ77bqY4JY/HxT5u0caWqsc3P3DcFIKBI1vHt+A==", - "requires": { - "abstract-leveldown": "^7.2.0", - "napi-macros": "~2.0.0", - "node-gyp-build": "^4.3.0" - } - }, - "levelup": { - "version": "5.1.1", - "resolved": "https://registry.npmjs.org/levelup/-/levelup-5.1.1.tgz", - "integrity": "sha512-0mFCcHcEebOwsQuk00WJwjLI6oCjbBuEYdh/RaRqhjnyVlzqf41T1NnDtCedumZ56qyIh8euLFDqV1KfzTAVhg==", - "requires": { - "catering": "^2.0.0", - "deferred-leveldown": "^7.0.0", - "level-errors": "^3.0.1", - "level-iterator-stream": "^5.0.0", - "level-supports": "^2.0.1", - "queue-microtask": "^1.2.3" - } - }, "leven": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/leven/-/leven-3.1.0.tgz", @@ -18520,11 +17913,6 @@ "yallist": "^4.0.0" } }, - "ltgt": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/ltgt/-/ltgt-2.2.1.tgz", - "integrity": "sha512-AI2r85+4MquTw9ZYqabu4nMwy9Oftlfa/e/52t9IjtfG+mGBbTNdAoZ3RQKLHR6r0wQnwZnPIEh/Ya6XTWAKNA==" - }, "lunr": { "version": "2.3.9", "resolved": "https://registry.npmjs.org/lunr/-/lunr-2.3.9.tgz", @@ -19432,10 +18820,17 @@ "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==" }, + "pure-rand": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/pure-rand/-/pure-rand-5.0.1.tgz", + "integrity": "sha512-ksWccjmXOHU2gJBnH0cK1lSYdvSZ0zLoCMSz/nTGh6hDvCSgcRxDyIcOBD6KNxFz3xhMPm/T267Tbe2JRymKEQ==", + "dev": true + }, "queue-microtask": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz", - "integrity": "sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==" + "integrity": "sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==", + "dev": true }, "ramda": { "version": "0.27.1", @@ -19673,14 +19068,6 @@ "queue-microtask": "^1.2.2" } }, - "run-parallel-limit": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/run-parallel-limit/-/run-parallel-limit-1.1.0.tgz", - "integrity": "sha512-jJA7irRNM91jaKc3Hcl1npHsFLOXOoTkPCUL1JEa1R82O2miplXXRaGdjW/KM/98YQWDhJLiSs793CnXfblJUw==", - "requires": { - "queue-microtask": "^1.2.2" - } - }, "safe-buffer": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", diff --git a/package.json b/package.json index 69858be06..29403fed3 100644 --- a/package.json +++ b/package.json @@ -66,8 +66,8 @@ "postversion": "npm install --package-lock-only --ignore-scripts --silent", "ts-node": "ts-node", "test": "jest", - "lint": "eslint '{src,tests,scripts}/**/*.{js,ts}'", - "lintfix": "eslint '{src,tests,scripts}/**/*.{js,ts}' --fix", + "lint": "eslint '{src,tests,scripts,benches}/**/*.{js,ts}'", + "lintfix": "eslint '{src,tests,scripts,benches}/**/*.{js,ts}' --fix", "lint-shell": "find ./src ./tests ./scripts -type f -regextype posix-extended -regex '.*\\.(sh)' -exec shellcheck {} +", "docs": "shx rm -rf ./docs && typedoc --gitRevision master --tsconfig ./tsconfig.build.json --out ./docs src", "bench": "shx rm -rf ./benches/results && ts-node ./benches", @@ -79,7 +79,7 @@ "@grpc/grpc-js": "1.6.7", "@matrixai/async-init": "^1.8.2", "@matrixai/async-locks": "^3.1.2", - "@matrixai/db": "^4.0.5", + "@matrixai/db": "^5.0.3", "@matrixai/errors": "^1.1.3", "@matrixai/id": "^3.3.3", "@matrixai/logger": "^3.0.0", @@ -92,7 +92,7 @@ "commander": "^8.3.0", "cross-fetch": "^3.0.6", "cross-spawn": "^7.0.3", - "encryptedfs": "^3.5.5", + "encryptedfs": "^3.5.6", "fast-fuzzy": "^1.10.8", "fd-lock": "^1.2.0", "google-protobuf": "^3.14.0", @@ -111,8 +111,8 @@ "uuid": "^8.3.0" }, "devDependencies": { - "@swc/core": "^1.2.215", "@babel/preset-env": "^7.13.10", + "@swc/core": "^1.2.215", "@types/cross-spawn": "^6.0.2", "@types/google-protobuf": "^3.7.4", "@types/jest": "^28.1.3", @@ -132,8 +132,10 @@ "eslint-config-prettier": "^8.5.0", "eslint-plugin-import": "^2.26.0", "eslint-plugin-prettier": "^4.0.0", + "fast-check": "^3.0.1", "grpc_tools_node_protoc_ts": "^5.1.3", "jest": "^28.1.1", + "jest-extended": "^3.0.1", "jest-junit": "^14.0.0", "jest-mock-process": "^2.0.0", "jest-mock-props": "^1.9.1", diff --git a/src/PolykeyAgent.ts b/src/PolykeyAgent.ts index 15d369d45..528a092b5 100644 --- a/src/PolykeyAgent.ts +++ b/src/PolykeyAgent.ts @@ -230,7 +230,6 @@ class PolykeyAgent { }, }, fs, - // @ts-ignore - version of js-logger is incompatible (remove when DB updates to 5.*) logger: logger.getChild(DB.name), fresh, })); diff --git a/src/acl/ACL.ts b/src/acl/ACL.ts index 62d5bfa70..c66dee09c 100644 --- a/src/acl/ACL.ts +++ b/src/acl/ACL.ts @@ -15,7 +15,6 @@ import { CreateDestroyStartStop, ready, } from '@matrixai/async-init/dist/CreateDestroyStartStop'; -import { withF } from '@matrixai/resources'; import * as aclUtils from './utils'; import * as aclErrors from './errors'; @@ -91,13 +90,6 @@ class ACL { this.logger.info(`Destroyed ${this.constructor.name}`); } - @ready(new aclErrors.ErrorACLNotRunning()) - public async withTransactionF( - f: (tran: DBTransaction) => Promise, - ): Promise { - return withF([this.db.transaction()], ([tran]) => f(tran)); - } - @ready(new aclErrors.ErrorACLNotRunning()) public async sameNodePerm( nodeId1: NodeId, @@ -105,7 +97,7 @@ class ACL { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.sameNodePerm(nodeId1, nodeId2, tran), ); } @@ -130,10 +122,10 @@ class ACL { tran?: DBTransaction, ): Promise>> { if (tran == null) { - return this.withTransactionF(async (tran) => this.getNodePerms(tran)); + return this.db.withTransactionF((tran) => this.getNodePerms(tran)); } const permIds: Record> = {}; - for await (const [keyPath, value] of tran.iterator(undefined, [ + for await (const [keyPath, value] of tran.iterator([ ...this.aclNodesDbPath, ])) { const key = keyPath[0] as Buffer; @@ -171,12 +163,12 @@ class ACL { tran?: DBTransaction, ): Promise>> { if (tran == null) { - return this.withTransactionF(async (tran) => this.getVaultPerms(tran)); + return this.db.withTransactionF((tran) => this.getVaultPerms(tran)); } const vaultPerms: Record> = {}; for await (const [keyPath, nodeIds] of tran.iterator>( - { valueAsBuffer: false }, [...this.aclVaultsDbPath], + { valueAsBuffer: false }, )) { const key = keyPath[0] as Buffer; const vaultId = IdInternal.fromBuffer(key); @@ -226,9 +218,7 @@ class ACL { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.withTransactionF(async (tran) => - this.getNodePerm(nodeId, tran), - ); + return this.db.withTransactionF((tran) => this.getNodePerm(nodeId, tran)); } const permId = await tran.get( [...this.aclNodesDbPath, nodeId.toBuffer()], @@ -255,7 +245,7 @@ class ACL { tran?: DBTransaction, ): Promise> { if (tran == null) { - return this.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.getVaultPerm(vaultId, tran), ); } @@ -311,7 +301,7 @@ class ACL { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.setNodeAction(nodeId, action, tran), ); } @@ -357,7 +347,7 @@ class ACL { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.unsetNodeAction(nodeId, action, tran), ); } @@ -384,7 +374,7 @@ class ACL { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.setVaultAction(vaultId, nodeId, action, tran), ); } @@ -428,7 +418,7 @@ class ACL { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.unsetVaultAction(vaultId, nodeId, action, tran), ); } @@ -470,7 +460,7 @@ class ACL { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.setNodesPerm(nodeIds, perm, tran), ); } @@ -525,7 +515,7 @@ class ACL { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.setNodePerm(nodeId, perm, tran), ); } @@ -566,7 +556,7 @@ class ACL { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.unsetNodePerm(nodeId, tran), ); } @@ -598,7 +588,7 @@ class ACL { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.unsetVaultPerms(vaultId, tran), ); } @@ -638,7 +628,7 @@ class ACL { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.joinNodePerm(nodeId, nodeIdsJoin, perm, tran), ); } @@ -694,7 +684,7 @@ class ACL { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.joinVaultPerms(vaultId, vaultIdsJoin, tran), ); } diff --git a/src/agent/service/nodesChainDataGet.ts b/src/agent/service/nodesChainDataGet.ts index 10175c706..97a5375fb 100644 --- a/src/agent/service/nodesChainDataGet.ts +++ b/src/agent/service/nodesChainDataGet.ts @@ -26,7 +26,7 @@ function nodesChainDataGet({ ): Promise => { try { const response = new nodesPB.ChainData(); - const chainData = await db.withTransactionF(async (tran) => + const chainData = await db.withTransactionF((tran) => sigchain.getChainData(tran), ); // Iterate through each claim in the chain, and serialize for transport diff --git a/src/agent/service/nodesClosestLocalNodesGet.ts b/src/agent/service/nodesClosestLocalNodesGet.ts index 4c987667d..12cb6e066 100644 --- a/src/agent/service/nodesClosestLocalNodesGet.ts +++ b/src/agent/service/nodesClosestLocalNodesGet.ts @@ -46,9 +46,8 @@ function nodesClosestLocalNodesGet({ }, ); // Get all local nodes that are closest to the target node from the request - const closestNodes = await db.withTransactionF( - async (tran) => - await nodeGraph.getClosestNodes(nodeId, undefined, tran), + const closestNodes = await db.withTransactionF((tran) => + nodeGraph.getClosestNodes(nodeId, undefined, tran), ); for (const [nodeId, nodeData] of closestNodes) { const addressMessage = new nodesPB.Address(); diff --git a/src/agent/service/notificationsSend.ts b/src/agent/service/notificationsSend.ts index cd1b43c76..d192f1905 100644 --- a/src/agent/service/notificationsSend.ts +++ b/src/agent/service/notificationsSend.ts @@ -28,9 +28,9 @@ function notificationsSend({ try { const jwt = call.request.getContent(); const notification = await notificationsUtils.verifyAndDecodeNotif(jwt); - await db.withTransactionF(async (tran) => { - await notificationsManager.receiveNotification(notification, tran); - }); + await db.withTransactionF((tran) => + notificationsManager.receiveNotification(notification, tran), + ); const response = new utilsPB.EmptyMessage(); callback(null, response); return; diff --git a/src/bootstrap/utils.ts b/src/bootstrap/utils.ts index 72aa2d0d3..9eece1244 100644 --- a/src/bootstrap/utils.ts +++ b/src/bootstrap/utils.ts @@ -100,7 +100,6 @@ async function bootstrapState({ const db = await DB.createDB({ dbPath, fs, - // @ts-ignore - version of js-logger is incompatible (remove when DB updates to 5.*) logger: logger.getChild(DB.name), crypto: { key: keyManager.dbKey, diff --git a/src/client/service/agentLockAll.ts b/src/client/service/agentLockAll.ts index 2c2c7505e..da90e23a5 100644 --- a/src/client/service/agentLockAll.ts +++ b/src/client/service/agentLockAll.ts @@ -26,9 +26,7 @@ function agentLockAll({ const response = new utilsPB.EmptyMessage(); const metadata = await authenticate(call.metadata); call.sendMetadata(metadata); - await db.withTransactionF( - async (tran) => await sessionManager.resetKey(tran), - ); + await db.withTransactionF((tran) => sessionManager.resetKey(tran)); callback(null, response); return; } catch (e) { diff --git a/src/client/service/gestaltsActionsGetByIdentity.ts b/src/client/service/gestaltsActionsGetByIdentity.ts index 3375ed15d..0b7d7c039 100644 --- a/src/client/service/gestaltsActionsGetByIdentity.ts +++ b/src/client/service/gestaltsActionsGetByIdentity.ts @@ -48,7 +48,7 @@ function gestaltsActionsGetByIdentity({ }, ); - const result = await db.withTransactionF(async (tran) => + const result = await db.withTransactionF((tran) => gestaltGraph.getGestaltActionsByIdentity(providerId, identityId, tran), ); if (result == null) { diff --git a/src/client/service/gestaltsActionsGetByNode.ts b/src/client/service/gestaltsActionsGetByNode.ts index ea0e4298d..b221186ec 100644 --- a/src/client/service/gestaltsActionsGetByNode.ts +++ b/src/client/service/gestaltsActionsGetByNode.ts @@ -42,7 +42,7 @@ function gestaltsActionsGetByNode({ nodeId: call.request.getNodeId(), }, ); - const result = await db.withTransactionF(async (tran) => + const result = await db.withTransactionF((tran) => gestaltGraph.getGestaltActionsByNode(nodeId, tran), ); if (result == null) { diff --git a/src/client/service/gestaltsActionsSetByIdentity.ts b/src/client/service/gestaltsActionsSetByIdentity.ts index b60d3aa84..1944e1b67 100644 --- a/src/client/service/gestaltsActionsSetByIdentity.ts +++ b/src/client/service/gestaltsActionsSetByIdentity.ts @@ -56,7 +56,7 @@ function gestaltsActionsSetByIdentity({ identityId: call.request.getIdentity()?.getIdentityId(), }, ); - await db.withTransactionF(async (tran) => + await db.withTransactionF((tran) => gestaltGraph.setGestaltActionByIdentity( providerId, identityId, diff --git a/src/client/service/gestaltsActionsSetByNode.ts b/src/client/service/gestaltsActionsSetByNode.ts index 187c634a7..b2009e98c 100644 --- a/src/client/service/gestaltsActionsSetByNode.ts +++ b/src/client/service/gestaltsActionsSetByNode.ts @@ -47,7 +47,7 @@ function gestaltsActionsSetByNode({ action: call.request.getAction(), }, ); - await db.withTransactionF(async (tran) => + await db.withTransactionF((tran) => gestaltGraph.setGestaltActionByNode(nodeId, action, tran), ); callback(null, response); diff --git a/src/client/service/gestaltsActionsUnsetByIdentity.ts b/src/client/service/gestaltsActionsUnsetByIdentity.ts index b2467bee5..d224c5053 100644 --- a/src/client/service/gestaltsActionsUnsetByIdentity.ts +++ b/src/client/service/gestaltsActionsUnsetByIdentity.ts @@ -56,7 +56,7 @@ function gestaltsActionsUnsetByIdentity({ identityId: call.request.getIdentity()?.getIdentityId(), }, ); - await db.withTransactionF(async (tran) => + await db.withTransactionF((tran) => gestaltGraph.unsetGestaltActionByIdentity( providerId, identityId, diff --git a/src/client/service/gestaltsActionsUnsetByNode.ts b/src/client/service/gestaltsActionsUnsetByNode.ts index bc39dc569..fc2fa5670 100644 --- a/src/client/service/gestaltsActionsUnsetByNode.ts +++ b/src/client/service/gestaltsActionsUnsetByNode.ts @@ -47,7 +47,7 @@ function gestaltsActionsUnsetByNode({ action: call.request.getAction(), }, ); - await db.withTransactionF(async (tran) => + await db.withTransactionF((tran) => gestaltGraph.unsetGestaltActionByNode(nodeId, action, tran), ); callback(null, response); diff --git a/src/client/service/gestaltsGestaltGetByIdentity.ts b/src/client/service/gestaltsGestaltGetByIdentity.ts index 8768ad136..5c96467a0 100644 --- a/src/client/service/gestaltsGestaltGetByIdentity.ts +++ b/src/client/service/gestaltsGestaltGetByIdentity.ts @@ -50,7 +50,7 @@ function gestaltsGestaltGetByIdentity({ identityId: call.request.getIdentityId(), }, ); - const gestalt = await db.withTransactionF(async (tran) => + const gestalt = await db.withTransactionF((tran) => gestaltGraph.getGestaltByIdentity(providerId, identityId, tran), ); if (gestalt != null) { diff --git a/src/client/service/gestaltsGestaltGetByNode.ts b/src/client/service/gestaltsGestaltGetByNode.ts index 207859fb5..f5677758d 100644 --- a/src/client/service/gestaltsGestaltGetByNode.ts +++ b/src/client/service/gestaltsGestaltGetByNode.ts @@ -46,7 +46,7 @@ function gestaltsGestaltGetByNode({ nodeId: call.request.getNodeId(), }, ); - const gestalt = await db.withTransactionF(async (tran) => + const gestalt = await db.withTransactionF((tran) => gestaltGraph.getGestaltByNode(nodeId, tran), ); if (gestalt != null) { diff --git a/src/client/service/gestaltsGestaltList.ts b/src/client/service/gestaltsGestaltList.ts index d07fb9f32..62c25c570 100644 --- a/src/client/service/gestaltsGestaltList.ts +++ b/src/client/service/gestaltsGestaltList.ts @@ -28,7 +28,7 @@ function gestaltsGestaltList({ try { const metadata = await authenticate(call.metadata); call.sendMetadata(metadata); - const certs: Array = await db.withTransactionF(async (tran) => + const certs: Array = await db.withTransactionF((tran) => gestaltGraph.getGestalts(tran), ); for (const cert of certs) { diff --git a/src/client/service/identitiesClaim.ts b/src/client/service/identitiesClaim.ts index 6677c77d4..952cd77ae 100644 --- a/src/client/service/identitiesClaim.ts +++ b/src/client/service/identitiesClaim.ts @@ -71,7 +71,7 @@ function identitiesClaim({ throw new identitiesErrors.ErrorProviderUnauthenticated(); } // Create identity claim on our node - const [, claim] = await db.withTransactionF(async (tran) => + const [, claim] = await db.withTransactionF((tran) => sigchain.addClaim( { type: 'identity', diff --git a/src/client/service/identitiesTokenDelete.ts b/src/client/service/identitiesTokenDelete.ts index 2b4a78b9b..da0bbaa20 100644 --- a/src/client/service/identitiesTokenDelete.ts +++ b/src/client/service/identitiesTokenDelete.ts @@ -50,7 +50,7 @@ function identitiesTokenDelete({ identityId: call.request.getIdentityId(), }, ); - await db.withTransactionF(async (tran) => + await db.withTransactionF((tran) => identitiesManager.delToken(providerId, identityId, tran), ); callback(null, response); diff --git a/src/client/service/identitiesTokenGet.ts b/src/client/service/identitiesTokenGet.ts index c829da281..3a25c1b06 100644 --- a/src/client/service/identitiesTokenGet.ts +++ b/src/client/service/identitiesTokenGet.ts @@ -49,7 +49,7 @@ function identitiesTokenGet({ identityId: call.request.getIdentityId(), }, ); - const tokens = await db.withTransactionF(async (tran) => + const tokens = await db.withTransactionF((tran) => identitiesManager.getToken(providerId, identityId, tran), ); response.setToken(JSON.stringify(tokens)); diff --git a/src/client/service/identitiesTokenPut.ts b/src/client/service/identitiesTokenPut.ts index b7ae0139f..4ce158838 100644 --- a/src/client/service/identitiesTokenPut.ts +++ b/src/client/service/identitiesTokenPut.ts @@ -53,7 +53,7 @@ function identitiesTokenPut({ identityId: call.request.getProvider()?.getIdentityId(), }, ); - await db.withTransactionF(async (tran) => + await db.withTransactionF((tran) => identitiesManager.putToken( providerId, identityId, diff --git a/src/client/service/nodesAdd.ts b/src/client/service/nodesAdd.ts index 92de5581d..87b356b7f 100644 --- a/src/client/service/nodesAdd.ts +++ b/src/client/service/nodesAdd.ts @@ -72,7 +72,7 @@ function nodesAdd({ ); } - await db.withTransactionF(async (tran) => + await db.withTransactionF((tran) => nodeManager.setNode( nodeId, { diff --git a/src/client/service/notificationsClear.ts b/src/client/service/notificationsClear.ts index ebcea2af0..e26b24cb4 100644 --- a/src/client/service/notificationsClear.ts +++ b/src/client/service/notificationsClear.ts @@ -26,7 +26,7 @@ function notificationsClear({ const response = new utilsPB.EmptyMessage(); const metadata = await authenticate(call.metadata); call.sendMetadata(metadata); - await db.withTransactionF(async (tran) => + await db.withTransactionF((tran) => notificationsManager.clearNotifications(tran), ); callback(null, response); diff --git a/src/client/service/notificationsRead.ts b/src/client/service/notificationsRead.ts index f706b5bd2..4e790f7fa 100644 --- a/src/client/service/notificationsRead.ts +++ b/src/client/service/notificationsRead.ts @@ -35,7 +35,7 @@ function notificationsRead({ } else { number = parseInt(numberField); } - const notifications = await db.withTransactionF(async (tran) => + const notifications = await db.withTransactionF((tran) => notificationsManager.readNotifications({ unread, number, diff --git a/src/client/service/vaultsCreate.ts b/src/client/service/vaultsCreate.ts index df7c6cfac..26617a665 100644 --- a/src/client/service/vaultsCreate.ts +++ b/src/client/service/vaultsCreate.ts @@ -31,7 +31,7 @@ function vaultsCreate({ try { const metadata = await authenticate(call.metadata); call.sendMetadata(metadata); - vaultId = await db.withTransactionF(async (tran) => + vaultId = await db.withTransactionF((tran) => vaultManager.createVault(call.request.getNameOrId() as VaultName, tran), ); response.setNameOrId(vaultsUtils.encodeVaultId(vaultId)); diff --git a/src/client/service/vaultsList.ts b/src/client/service/vaultsList.ts index c7d3da737..3fbbdadd5 100644 --- a/src/client/service/vaultsList.ts +++ b/src/client/service/vaultsList.ts @@ -27,7 +27,7 @@ function vaultsList({ try { const metadata = await authenticate(call.metadata); call.sendMetadata(metadata); - const vaults = await db.withTransactionF(async (tran) => + const vaults = await db.withTransactionF((tran) => vaultManager.listVaults(tran), ); for await (const [vaultName, vaultId] of vaults) { diff --git a/src/discovery/Discovery.ts b/src/discovery/Discovery.ts index 5d33b5cbf..37bc416f6 100644 --- a/src/discovery/Discovery.ts +++ b/src/discovery/Discovery.ts @@ -24,9 +24,7 @@ import { status, } from '@matrixai/async-init/dist/CreateDestroyStartStop'; import { IdInternal } from '@matrixai/id'; -import { Lock } from '@matrixai/async-locks'; import * as idUtils from '@matrixai/id/dist/utils'; -import * as resources from '@matrixai/resources'; import * as discoveryUtils from './utils'; import * as discoveryErrors from './errors'; import * as nodesErrors from '../nodes/errors'; @@ -91,7 +89,6 @@ class Discovery { protected discoveryProcess: Promise; protected queuePlug = promise(); protected queueDrained = promise(); - protected lock: Lock = new Lock(); public constructor({ keyManager, @@ -130,10 +127,11 @@ class Discovery { } // Getting latest ID and creating ID generator let latestId: DiscoveryQueueId | undefined; - const keyIterator = this.db.iterator( - { limit: 1, reverse: true, values: false }, - this.discoveryQueueDbPath, - ); + const keyIterator = this.db.iterator(this.discoveryQueueDbPath, { + limit: 1, + reverse: true, + values: false, + }); for await (const [keyPath] of keyIterator) { const key = keyPath[0] as Buffer; latestId = IdInternal.fromBuffer(key); @@ -204,8 +202,8 @@ class Discovery { // Processing queue this.logger.debug('DiscoveryQueue is processing'); for await (const [keyPath, vertex] of this.db.iterator( - { valueAsBuffer: false }, this.discoveryQueueDbPath, + { valueAsBuffer: false }, )) { const key = keyPath[0] as Buffer; const vertexId = IdInternal.fromBuffer(key); @@ -419,22 +417,19 @@ class Discovery { } /** - * Simple check for whether the Discovery Queue is empty. Uses a - * transaction lock to ensure consistency. + * Simple check for whether the Discovery Queue is empty. */ protected async queueIsEmpty(): Promise { - return await this.lock.withF(async () => { - let nextDiscoveryQueueId: DiscoveryQueueId | undefined; - const keyIterator = this.db.iterator( - { limit: 1, values: false }, - this.discoveryQueueDbPath, - ); - for await (const [keyPath] of keyIterator) { - const key = keyPath[0] as Buffer; - nextDiscoveryQueueId = IdInternal.fromBuffer(key); - } - return nextDiscoveryQueueId == null; + let nextDiscoveryQueueId: DiscoveryQueueId | undefined; + const keyIterator = this.db.iterator(this.discoveryQueueDbPath, { + limit: 1, + values: false, }); + for await (const [keyPath] of keyIterator) { + const key = keyPath[0] as Buffer; + nextDiscoveryQueueId = IdInternal.fromBuffer(key); + } + return nextDiscoveryQueueId == null; } /** @@ -445,25 +440,22 @@ class Discovery { protected async pushKeyToDiscoveryQueue( gestaltKey: GestaltKey, ): Promise { - await resources.withF( - [this.db.transaction(), this.lock.lock()], - async ([tran]) => { - const valueIterator = tran.iterator( - { valueAsBuffer: false }, - this.discoveryQueueDbPath, - ); - for await (const [, value] of valueIterator) { - if (value === gestaltKey) { - return; - } + await this.db.withTransactionF(async (tran) => { + const valueIterator = tran.iterator( + this.discoveryQueueDbPath, + { valueAsBuffer: false }, + ); + for await (const [, value] of valueIterator) { + if (value === gestaltKey) { + return; } - const discoveryQueueId = this.discoveryQueueIdGenerator(); - await tran.put( - [...this.discoveryQueueDbPath, idUtils.toBuffer(discoveryQueueId)], - gestaltKey, - ); - }, - ); + } + const discoveryQueueId = this.discoveryQueueIdGenerator(); + await tran.put( + [...this.discoveryQueueDbPath, idUtils.toBuffer(discoveryQueueId)], + gestaltKey, + ); + }); this.queuePlug.resolveP(); } @@ -475,12 +467,7 @@ class Discovery { protected async removeKeyFromDiscoveryQueue( keyId: DiscoveryQueueId, ): Promise { - await this.lock.withF(async () => { - await this.db.del([ - ...this.discoveryQueueDbPath, - idUtils.toBuffer(keyId), - ]); - }); + await this.db.del([...this.discoveryQueueDbPath, idUtils.toBuffer(keyId)]); } /** diff --git a/src/gestalts/GestaltGraph.ts b/src/gestalts/GestaltGraph.ts index 0bb6c7cd1..e9f688ca2 100644 --- a/src/gestalts/GestaltGraph.ts +++ b/src/gestalts/GestaltGraph.ts @@ -17,7 +17,6 @@ import { CreateDestroyStartStop, ready, } from '@matrixai/async-init/dist/CreateDestroyStartStop'; -import { withF } from '@matrixai/resources'; import * as gestaltsUtils from './utils'; import * as gestaltsErrors from './errors'; import * as aclUtils from '../acl/utils'; @@ -90,22 +89,15 @@ class GestaltGraph { this.logger.info(`Destroyed ${this.constructor.name}`); } - @ready(new gestaltsErrors.ErrorGestaltsGraphNotRunning()) - public async withTransactionF( - f: (tran: DBTransaction) => Promise, - ): Promise { - return withF([this.db.transaction()], ([tran]) => f(tran)); - } - @ready(new gestaltsErrors.ErrorGestaltsGraphNotRunning()) public async getGestalts(tran?: DBTransaction): Promise> { if (tran == null) { - return this.withTransactionF(async (tran) => this.getGestalts(tran)); + return this.db.withTransactionF((tran) => this.getGestalts(tran)); } const unvisited: Map = new Map(); for await (const [k, gKs] of tran.iterator( - { valueAsBuffer: false }, [...this.gestaltGraphMatrixDbPath], + { valueAsBuffer: false }, )) { const gK = k.toString() as GestaltKey; unvisited.set(gK, gKs); @@ -164,7 +156,7 @@ class GestaltGraph { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.getGestaltByNode(nodeId, tran), ); } @@ -179,7 +171,7 @@ class GestaltGraph { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.getGestaltByIdentity(providerId, identityId, tran), ); } @@ -193,7 +185,7 @@ class GestaltGraph { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.setIdentity(identityInfo, tran), ); } @@ -222,7 +214,7 @@ class GestaltGraph { tran?: DBTransaction, ) { if (tran == null) { - return this.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.unsetIdentity(providerId, identityId, tran), ); } @@ -267,9 +259,7 @@ class GestaltGraph { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.withTransactionF(async (tran) => - this.setNode(nodeInfo, tran), - ); + return this.db.withTransactionF((tran) => this.setNode(nodeInfo, tran)); } const nodeKey = gestaltsUtils.keyFromNode( nodesUtils.decodeNodeId(nodeInfo.id)!, @@ -307,9 +297,7 @@ class GestaltGraph { @ready(new gestaltsErrors.ErrorGestaltsGraphNotRunning()) public async unsetNode(nodeId: NodeId, tran?: DBTransaction): Promise { if (tran == null) { - return this.withTransactionF(async (tran) => - this.unsetNode(nodeId, tran), - ); + return this.db.withTransactionF((tran) => this.unsetNode(nodeId, tran)); } const nodeKey = gestaltsUtils.keyFromNode(nodeId); const nodeKeyPath = [ @@ -356,7 +344,7 @@ class GestaltGraph { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.linkNodeAndIdentity(nodeInfo, identityInfo, tran), ); } @@ -502,7 +490,7 @@ class GestaltGraph { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.linkNodeAndNode(nodeInfo1, nodeInfo2, tran), ); } @@ -621,7 +609,7 @@ class GestaltGraph { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.unlinkNodeAndIdentity(nodeId, providerId, identityId, tran), ); } @@ -676,7 +664,7 @@ class GestaltGraph { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.unlinkNodeAndNode(nodeId1, nodeId2, tran), ); } @@ -729,7 +717,7 @@ class GestaltGraph { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.getGestaltActionsByNode(nodeId, tran), ); } @@ -755,7 +743,7 @@ class GestaltGraph { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.getGestaltActionsByIdentity(providerId, identityId, tran), ); } @@ -796,7 +784,7 @@ class GestaltGraph { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.setGestaltActionByNode(nodeId, action, tran), ); } @@ -819,7 +807,7 @@ class GestaltGraph { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.setGestaltActionByIdentity(providerId, identityId, action, tran), ); } @@ -855,7 +843,7 @@ class GestaltGraph { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.unsetGestaltActionByNode(nodeId, action, tran), ); } @@ -878,7 +866,7 @@ class GestaltGraph { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.unsetGestaltActionByIdentity(providerId, identityId, action, tran), ); } diff --git a/src/identities/IdentitiesManager.ts b/src/identities/IdentitiesManager.ts index f4e42dc38..2f1e98adf 100644 --- a/src/identities/IdentitiesManager.ts +++ b/src/identities/IdentitiesManager.ts @@ -11,7 +11,6 @@ import { CreateDestroyStartStop, ready, } from '@matrixai/async-init/dist/CreateDestroyStartStop'; -import { withF } from '@matrixai/resources'; import * as identitiesErrors from './errors'; interface IdentitiesManager extends CreateDestroyStartStop {} @@ -74,13 +73,6 @@ class IdentitiesManager { this.logger.info(`Destroyed ${this.constructor.name}`); } - @ready(new identitiesErrors.ErrorIdentitiesManagerNotRunning()) - public async withTransactionF( - f: (tran: DBTransaction) => Promise, - ): Promise { - return withF([this.db.transaction()], ([tran]) => f(tran)); - } - @ready(new identitiesErrors.ErrorIdentitiesManagerNotRunning()) public getProviders(): Record { return Object.fromEntries(this.providers); @@ -116,7 +108,7 @@ class IdentitiesManager { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.getTokens(providerId, tran), ); } @@ -138,7 +130,7 @@ class IdentitiesManager { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.getToken(providerId, identityId, tran), ); } @@ -161,7 +153,7 @@ class IdentitiesManager { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.putToken(providerId, identityId, tokenData, tran), ); } @@ -181,7 +173,7 @@ class IdentitiesManager { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.delToken(providerId, identityId, tran), ); } diff --git a/src/nodes/NodeGraph.ts b/src/nodes/NodeGraph.ts index a05610d33..fda9caba1 100644 --- a/src/nodes/NodeGraph.ts +++ b/src/nodes/NodeGraph.ts @@ -156,11 +156,7 @@ class NodeGraph { nodeId: NodeId, tran?: DBTransaction, ): Promise { - if (tran == null) { - return this.db.withTransactionF(async (tran) => - this.getNode(nodeId, tran), - ); - } + const tranOrDb = tran ?? this.db; const [bucketIndex] = this.bucketIndex(nodeId); const bucketDomain = [ @@ -168,7 +164,7 @@ class NodeGraph { nodesUtils.bucketKey(bucketIndex), nodesUtils.bucketDbKey(nodeId), ]; - return await tran.get(bucketDomain); + return await tranOrDb.get(bucketDomain); } /** @@ -192,11 +188,11 @@ class NodeGraph { } for await (const [keyPath, nodeData] of tran.iterator( + this.nodeGraphBucketsDbPath, { reverse: order !== 'asc', valueAsBuffer: false, }, - this.nodeGraphBucketsDbPath, )) { const { nodeId } = nodesUtils.parseBucketsDbKey(keyPath); yield [nodeId, nodeData]; @@ -217,7 +213,7 @@ class NodeGraph { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.db.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.setNode(nodeId, nodeAddress, tran), ); } @@ -266,17 +262,17 @@ class NodeGraph { tran?: DBTransaction, ): Promise> { if (tran == null) { - return this.db.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.getOldestNode(bucketIndex, limit, tran), ); } const bucketKey = nodesUtils.bucketKey(bucketIndex); // Remove the oldest entry in the bucket const oldestNodeIds: Array = []; - for await (const [keyPath] of tran.iterator({ limit }, [ - ...this.nodeGraphLastUpdatedDbPath, - bucketKey, - ])) { + for await (const [keyPath] of tran.iterator( + [...this.nodeGraphLastUpdatedDbPath, bucketKey], + { limit }, + )) { const { nodeId } = nodesUtils.parseLastUpdatedBucketDbKey(keyPath); oldestNodeIds.push(nodeId); } @@ -286,9 +282,7 @@ class NodeGraph { @ready(new nodesErrors.ErrorNodeGraphNotRunning()) public async unsetNode(nodeId: NodeId, tran?: DBTransaction): Promise { if (tran == null) { - return this.db.withTransactionF(async (tran) => - this.unsetNode(nodeId, tran), - ); + return this.db.withTransactionF((tran) => this.unsetNode(nodeId, tran)); } const [bucketIndex, bucketKey] = this.bucketIndex(nodeId); @@ -324,7 +318,7 @@ class NodeGraph { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.db.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.getBucket(bucketIndex, sort, order, tran), ); } @@ -338,11 +332,11 @@ class NodeGraph { const bucket: NodeBucket = []; if (sort === 'nodeId' || sort === 'distance') { for await (const [key, nodeData] of tran.iterator( + [...this.nodeGraphBucketsDbPath, bucketKey], { reverse: order !== 'asc', valueAsBuffer: false, }, - [...this.nodeGraphBucketsDbPath, bucketKey], )) { const nodeId = nodesUtils.parseBucketDbKey(key[0] as Buffer); bucket.push([nodeId, nodeData]); @@ -356,15 +350,15 @@ class NodeGraph { } } else if (sort === 'lastUpdated') { const bucketDbIterator = tran.iterator( - { valueAsBuffer: false }, [...this.nodeGraphBucketsDbPath, bucketKey], + { valueAsBuffer: false }, ); try { for await (const [, nodeIdBuffer] of tran.iterator( + [...this.nodeGraphLastUpdatedDbPath, bucketKey], { reverse: order !== 'asc', }, - [...this.nodeGraphLastUpdatedDbPath, bucketKey], )) { const nodeId = IdInternal.fromBuffer(nodeIdBuffer); bucketDbIterator.seek(nodeIdBuffer); @@ -375,7 +369,7 @@ class NodeGraph { bucket.push([nodeId, nodeData]); } } finally { - await bucketDbIterator.end(); + await bucketDbIterator.destroy(); } } return bucket; @@ -410,11 +404,11 @@ class NodeGraph { let bucket: NodeBucket = []; if (sort === 'nodeId' || sort === 'distance') { for await (const [key, nodeData] of tran.iterator( + this.nodeGraphBucketsDbPath, { reverse: order !== 'asc', valueAsBuffer: false, }, - this.nodeGraphBucketsDbPath, )) { const { bucketIndex: bucketIndex_, nodeId } = nodesUtils.parseBucketsDbKey(key); @@ -452,15 +446,15 @@ class NodeGraph { } } else if (sort === 'lastUpdated') { const bucketsDbIterator = tran.iterator( - { valueAsBuffer: false }, this.nodeGraphBucketsDbPath, + { valueAsBuffer: false }, ); try { for await (const [key] of tran.iterator( + this.nodeGraphLastUpdatedDbPath, { reverse: order !== 'asc', }, - this.nodeGraphLastUpdatedDbPath, )) { const { bucketIndex: bucketIndex_, nodeId } = nodesUtils.parseLastUpdatedBucketsDbKey(key); @@ -488,7 +482,7 @@ class NodeGraph { yield [bucketIndex, bucket]; } } finally { - await bucketsDbIterator.end(); + await bucketsDbIterator.destroy(); // FIXME: destroy? } } } @@ -499,7 +493,7 @@ class NodeGraph { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.db.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.resetBuckets(nodeIdOwn, tran), ); } @@ -524,8 +518,8 @@ class NodeGraph { // Iterating over all entries across all buckets for await (const [key, nodeData] of tran.iterator( - { valueAsBuffer: false }, this.nodeGraphBucketsDbPath, + { valueAsBuffer: false }, )) { // The key is a combined bucket key and node ID const { bucketIndex: bucketIndexOld, nodeId } = @@ -551,12 +545,9 @@ class NodeGraph { } else { let oldestIndexKey: KeyPath | undefined = undefined; let oldestNodeId: NodeId | undefined = undefined; - for await (const [key] of tran.iterator( - { - limit: 1, - }, - indexPathNew, - )) { + for await (const [key] of tran.iterator(indexPathNew, { + limit: 1, + })) { oldestIndexKey = key; ({ nodeId: oldestNodeId } = nodesUtils.parseLastUpdatedBucketDbKey(key)); @@ -601,7 +592,7 @@ class NodeGraph { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.db.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.getBucketMeta(bucketIndex, tran), ); } @@ -632,7 +623,7 @@ class NodeGraph { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.db.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.getBucketMetaProp(bucketIndex, key, tran), ); } @@ -679,7 +670,7 @@ class NodeGraph { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.db.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.getClosestNodes(nodeId, limit, tran), ); } @@ -716,12 +707,12 @@ class NodeGraph { const remainingLimit = limit - nodeIds.length; // Iterate over lower buckets for await (const [key, nodeData] of tran.iterator( + this.nodeGraphBucketsDbPath, { lt: [bucketIdKey, ''], limit: remainingLimit, valueAsBuffer: false, }, - this.nodeGraphBucketsDbPath, )) { const info = nodesUtils.parseBucketsDbKey(key); nodeIds.push([info.nodeId, nodeData]); @@ -732,20 +723,17 @@ class NodeGraph { const bucketId = Buffer.from(nodesUtils.bucketKey(startingBucket + 1)); const remainingLimit = limit - nodeIds.length; // Iterate over ids further away - tran.iterator( - { - gt: [bucketId, ''], - limit: remainingLimit, - }, - this.nodeGraphBucketsDbPath, - ); + tran.iterator(this.nodeGraphBucketsDbPath, { + gt: [bucketId, ''], + limit: remainingLimit, + }); for await (const [key, nodeData] of tran.iterator( + this.nodeGraphBucketsDbPath, { gt: [bucketId, ''], limit: remainingLimit, valueAsBuffer: false, }, - this.nodeGraphBucketsDbPath, )) { const info = nodesUtils.parseBucketsDbKey(key); nodeIds.push([info.nodeId, nodeData]); diff --git a/src/nodes/NodeManager.ts b/src/nodes/NodeManager.ts index 7245ab5c4..aa0740ee5 100644 --- a/src/nodes/NodeManager.ts +++ b/src/nodes/NodeManager.ts @@ -14,7 +14,7 @@ import type { } from '../nodes/types'; import type { ClaimEncoded } from '../claims/types'; import type { Timer } from '../types'; -import type { PromiseDeconstructed } from '../utils/utils'; +import type { PromiseDeconstructed } from '../types'; import Logger from '@matrixai/logger'; import { StartStop, ready } from '@matrixai/async-init/dist/StartStop'; import * as nodesErrors from './errors'; @@ -233,7 +233,7 @@ class NodeManager { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.db.withTransactionF(async (tran) => { + return this.db.withTransactionF((tran) => { return this.claimNode(targetNodeId, tran); }); } @@ -418,7 +418,7 @@ class NodeManager { } if (tran == null) { - return this.db.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.setNode(nodeId, nodeAddress, block, force, timeout, tran), ); } diff --git a/src/nodes/Queue.ts b/src/nodes/Queue.ts index 602efd5ae..ed2eaa06e 100644 --- a/src/nodes/Queue.ts +++ b/src/nodes/Queue.ts @@ -1,4 +1,4 @@ -import type { PromiseDeconstructed } from '../utils'; +import type { PromiseDeconstructed } from '../types'; import Logger from '@matrixai/logger'; import { StartStop, ready } from '@matrixai/async-init/dist/StartStop'; import * as nodesErrors from './errors'; diff --git a/src/notifications/NotificationsManager.ts b/src/notifications/NotificationsManager.ts index ac91a0cf1..19d4d8ab9 100644 --- a/src/notifications/NotificationsManager.ts +++ b/src/notifications/NotificationsManager.ts @@ -12,13 +12,11 @@ import type NodeConnectionManager from '../nodes/NodeConnectionManager'; import type { NodeId } from '../nodes/types'; import Logger from '@matrixai/logger'; import { IdInternal } from '@matrixai/id'; -import { Lock, LockBox } from '@matrixai/async-locks'; import { CreateDestroyStartStop, ready, } from '@matrixai/async-init/dist/CreateDestroyStartStop'; import { utils as idUtils } from '@matrixai/id'; -import { withF } from '@matrixai/resources'; import * as notificationsUtils from './utils'; import * as notificationsErrors from './errors'; import * as notificationsPB from '../proto/js/polykey/v1/notifications/notifications_pb'; @@ -78,7 +76,6 @@ class NotificationsManager { protected nodeManager: NodeManager; protected nodeConnectionManager: NodeConnectionManager; protected messageCap: number; - protected locks: LockBox = new LockBox(); /** * Top level stores MESSAGE_COUNT_KEY -> number (of messages) @@ -91,6 +88,10 @@ class NotificationsManager { this.constructor.name, 'messages', ]; + protected notificationsMessageCounterDbPath: KeyPath = [ + ...this.notificationsDbPath, + MESSAGE_COUNT_KEY, + ]; protected notificationIdGenerator: NotificationIdGenerator; @@ -123,35 +124,27 @@ class NotificationsManager { public async start({ fresh = false, }: { fresh?: boolean } = {}): Promise { - await withF( - [ - this.db.transaction(), - this.locks.lock([ - [...this.notificationsDbPath, MESSAGE_COUNT_KEY], - Lock, - ]), - ], - async ([tran]) => { - this.logger.info(`Starting ${this.constructor.name}`); - if (fresh) { - await tran.clear(this.notificationsDbPath); - } + await this.db.withTransactionF(async (tran) => { + this.logger.info(`Starting ${this.constructor.name}`); + if (fresh) { + await tran.clear(this.notificationsDbPath); + } - // Getting latest ID and creating ID generator - let latestId: NotificationId | undefined; - const keyIterator = tran.iterator( - { limit: 1, reverse: true, values: false }, - this.notificationsMessagesDbPath, - ); - for await (const [keyPath] of keyIterator) { - const key = keyPath[0] as Buffer; - latestId = IdInternal.fromBuffer(key); - } - this.notificationIdGenerator = - notificationsUtils.createNotificationIdGenerator(latestId); - this.logger.info(`Started ${this.constructor.name}`); - }, - ); + // Getting latest ID and creating ID generator + let latestId: NotificationId | undefined; + const keyIterator = tran.iterator(this.notificationsMessagesDbPath, { + limit: 1, + reverse: true, + values: false, + }); + for await (const [keyPath] of keyIterator) { + const key = keyPath[0] as Buffer; + latestId = IdInternal.fromBuffer(key); + } + this.notificationIdGenerator = + notificationsUtils.createNotificationIdGenerator(latestId); + this.logger.info(`Started ${this.constructor.name}`); + }); } public async stop() { @@ -161,24 +154,10 @@ class NotificationsManager { public async destroy() { this.logger.info(`Destroying ${this.constructor.name}`); - await this.db.withTransactionF(async (tran) => { - await tran.clear(this.notificationsDbPath); - }); - this.logger.info(`Destroyed ${this.constructor.name}`); - } - - @ready(new notificationsErrors.ErrorNotificationsNotRunning()) - public async withTransactionF( - ...params: [...keys: Array, f: (tran: DBTransaction) => Promise] - ): Promise { - const f = params.pop() as (tran: DBTransaction) => Promise; - const lockRequests = (params as Array).map<[KeyPath, typeof Lock]>( - (key) => [key, Lock], - ); - return withF( - [this.db.transaction(), this.locks.lock(...lockRequests)], - ([tran]) => f(tran), + await this.db.withTransactionF((tran) => + tran.clear(this.notificationsDbPath), ); + this.logger.info(`Destroyed ${this.constructor.name}`); } /** @@ -215,12 +194,13 @@ class NotificationsManager { notification: Notification, tran?: DBTransaction, ): Promise { - const messageCountPath = [...this.notificationsDbPath, MESSAGE_COUNT_KEY]; if (tran == null) { - return this.withTransactionF(messageCountPath, async (tran) => + return this.db.withTransactionF(async (tran) => this.receiveNotification(notification, tran), ); } + + await tran.lock(this.notificationsMessageCounterDbPath.join('')); const nodePerms = await this.acl.getNodePerm( nodesUtils.decodeNodeId(notification.senderId)!, ); @@ -230,10 +210,12 @@ class NotificationsManager { // Only keep the message if the sending node has the correct permissions if (Object.keys(nodePerms.gestalt).includes('notify')) { // If the number stored in notificationsDb >= 10000 - let numMessages = await tran.get(messageCountPath); + let numMessages = await tran.get( + this.notificationsMessageCounterDbPath, + ); if (numMessages === undefined) { numMessages = 0; - await tran.put(messageCountPath, 0); + await tran.put(this.notificationsMessageCounterDbPath, 0); } if (numMessages >= this.messageCap) { // Remove the oldest notification from notificationsMessagesDb @@ -248,7 +230,7 @@ class NotificationsManager { ); // Number of messages += 1 const newNumMessages = numMessages + 1; - await tran.put(messageCountPath, newNumMessages); + await tran.put(this.notificationsMessageCounterDbPath, newNumMessages); } } @@ -268,7 +250,7 @@ class NotificationsManager { tran?: DBTransaction; } = {}): Promise> { if (tran == null) { - return this.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.readNotifications({ unread, number, order, tran }), ); } @@ -308,7 +290,7 @@ class NotificationsManager { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.findGestaltInvite(fromNode, tran), ); } @@ -328,14 +310,15 @@ class NotificationsManager { */ @ready(new notificationsErrors.ErrorNotificationsNotRunning()) public async clearNotifications(tran?: DBTransaction): Promise { - const messageCountPath = [...this.notificationsDbPath, MESSAGE_COUNT_KEY]; if (tran == null) { - return this.withTransactionF(messageCountPath, async (tran) => - this.clearNotifications(tran), - ); + return this.db.withTransactionF((tran) => this.clearNotifications(tran)); } + + await tran.lock(this.notificationsMessageCounterDbPath.join('')); const notificationIds = await this.getNotificationIds('all', tran); - const numMessages = await tran.get(messageCountPath); + const numMessages = await tran.get( + this.notificationsMessageCounterDbPath, + ); if (numMessages !== undefined) { for (const id of notificationIds) { await this.removeNotification(id, tran); @@ -368,8 +351,8 @@ class NotificationsManager { ): Promise> { const notificationIds: Array = []; const messageIterator = tran.iterator( - { valueAsBuffer: false }, this.notificationsMessagesDbPath, + { valueAsBuffer: false }, ); for await (const [keyPath, notification] of messageIterator) { const key = keyPath[0] as Buffer; @@ -391,8 +374,8 @@ class NotificationsManager { ): Promise> { const notifications: Array = []; for await (const [, notification] of tran.iterator( - { valueAsBuffer: false }, this.notificationsMessagesDbPath, + { valueAsBuffer: false }, )) { if (type === 'all') { notifications.push(notification); @@ -419,10 +402,10 @@ class NotificationsManager { messageId: NotificationId, tran: DBTransaction, ): Promise { - const numMessages = await tran.get([ - ...this.notificationsDbPath, - MESSAGE_COUNT_KEY, - ]); + await tran.lock(this.notificationsMessageCounterDbPath.join('')); + const numMessages = await tran.get( + this.notificationsMessageCounterDbPath, + ); if (numMessages === undefined) { throw new notificationsErrors.ErrorNotificationsDb(); } @@ -431,10 +414,7 @@ class NotificationsManager { ...this.notificationsMessagesDbPath, idUtils.toBuffer(messageId), ]); - await tran.put( - [...this.notificationsDbPath, MESSAGE_COUNT_KEY], - numMessages - 1, - ); + await tran.put(this.notificationsMessageCounterDbPath, numMessages - 1); } } diff --git a/src/sessions/SessionManager.ts b/src/sessions/SessionManager.ts index 4a9f1607b..7a5cc7b73 100644 --- a/src/sessions/SessionManager.ts +++ b/src/sessions/SessionManager.ts @@ -98,20 +98,11 @@ class SessionManager { this.logger.info(`Destroyed ${this.constructor.name}`); } - @ready(new sessionsErrors.ErrorSessionManagerNotRunning()) - public async withTransactionF( - f: (tran: DBTransaction) => Promise, - ): Promise { - return withF([this.db.transaction()], ([tran]) => f(tran)); - } - @ready(new sessionsErrors.ErrorSessionManagerNotRunning()) public async resetKey(tran?: DBTransaction): Promise { - if (tran == null) { - return this.withTransactionF(async (tran) => this.resetKey(tran)); - } + const tranOrDb = tran ?? this.db; const key = await this.generateKey(this.keyBits); - await tran.put([...this.sessionsDbPath, 'key'], key, true); + await tranOrDb.put([...this.sessionsDbPath, 'key'], key, true); } /** @@ -124,18 +115,13 @@ class SessionManager { expiry: number | undefined = this.expiry, tran?: DBTransaction, ): Promise { - if (tran == null) { - return this.withTransactionF(async (tran) => - this.createToken(expiry, tran), - ); - } + const tranOrDb = tran ?? this.db; const payload = { iss: nodesUtils.encodeNodeId(this.keyManager.getNodeId()), sub: nodesUtils.encodeNodeId(this.keyManager.getNodeId()), }; - const key = await tran.get([...this.sessionsDbPath, 'key'], true); - const token = await sessionsUtils.createSessionToken(payload, key!, expiry); - return token; + const key = await tranOrDb.get([...this.sessionsDbPath, 'key'], true); + return await sessionsUtils.createSessionToken(payload, key!, expiry); } @ready(new sessionsErrors.ErrorSessionManagerNotRunning()) @@ -143,12 +129,8 @@ class SessionManager { token: SessionToken, tran?: DBTransaction, ): Promise { - if (tran == null) { - return this.withTransactionF(async (tran) => - this.verifyToken(token, tran), - ); - } - const key = await tran.get([...this.sessionsDbPath, 'key'], true); + const tranOrDb = tran ?? this.db; + const key = await tranOrDb.get([...this.sessionsDbPath, 'key'], true); const result = await sessionsUtils.verifySessionToken(token, key!); return result !== undefined; } diff --git a/src/sigchain/Sigchain.ts b/src/sigchain/Sigchain.ts index 06631cdd5..5276f7163 100644 --- a/src/sigchain/Sigchain.ts +++ b/src/sigchain/Sigchain.ts @@ -1,4 +1,4 @@ -import type { DB, DBTransaction, KeyPath, LevelPath } from '@matrixai/db'; +import type { DB, DBTransaction, LevelPath } from '@matrixai/db'; import type { ChainDataEncoded } from './types'; import type { ClaimData, @@ -16,7 +16,6 @@ import { CreateDestroyStartStop, ready, } from '@matrixai/async-init/dist/CreateDestroyStartStop'; -import { Lock, LockBox } from '@matrixai/async-locks'; import { withF } from '@matrixai/resources'; import * as sigchainErrors from './errors'; import * as claimsUtils from '../claims/utils'; @@ -32,7 +31,6 @@ class Sigchain { protected logger: Logger; protected keyManager: KeyManager; protected db: DB; - protected locks: LockBox = new LockBox(); // Top-level database for the sigchain domain protected sigchainDbPath: LevelPath = [this.constructor.name]; // ClaimId (the lexicographic integer of the sequence number) @@ -124,20 +122,6 @@ class Sigchain { this.logger.info(`Destroyed ${this.constructor.name}`); } - @ready(new sigchainErrors.ErrorSigchainNotRunning()) - public async withTransactionF( - ...params: [...keys: Array, f: (tran: DBTransaction) => Promise] - ): Promise { - const f = params.pop() as (tran: DBTransaction) => Promise; - const lockRequests = (params as Array).map<[KeyPath, typeof Lock]>( - (key) => [key, Lock], - ); - return withF( - [this.db.transaction(), this.locks.lock(...lockRequests)], - ([tran]) => f(tran), - ); - } - /** * Helper function to create claims internally in the Sigchain class. * Wraps claims::createClaim() with the static information common to all @@ -186,13 +170,17 @@ class Sigchain { this.sequenceNumberKey, ]; if (tran == null) { - return this.withTransactionF( - claimIdPath, - sequenceNumberPath, - async (tran) => this.addClaim(claimData, tran), - ); + return this.db.withTransactionF((tran) => this.addClaim(claimData, tran)); + } + + await tran.lock(sequenceNumberPath.join('')); + const prevSequenceNumber = await tran.getForUpdate([ + ...this.sigchainMetadataDbPath, + this.sequenceNumberKey, + ]); + if (prevSequenceNumber === undefined) { + throw new sigchainErrors.ErrorSigchainSequenceNumUndefined(); } - const prevSequenceNumber = await this.getSequenceNumber(tran); const newSequenceNumber = prevSequenceNumber + 1; const claim = await this.createClaim({ hPrev: await this.getHashPrevious(tran), @@ -225,14 +213,20 @@ class Sigchain { this.sequenceNumberKey, ]; if (tran == null) { - return this.withTransactionF( - claimIdPath, - sequenceNumberPath, - async (tran) => this.addExistingClaim(claim, tran), + return this.db.withTransactionF((tran) => + this.addExistingClaim(claim, tran), ); } + + await tran.lock(sequenceNumberPath.join('')); const decodedClaim = claimsUtils.decodeClaim(claim); - const prevSequenceNumber = await this.getSequenceNumber(tran); + const prevSequenceNumber = await tran.getForUpdate([ + ...this.sigchainMetadataDbPath, + this.sequenceNumberKey, + ]); + if (prevSequenceNumber === undefined) { + throw new sigchainErrors.ErrorSigchainSequenceNumUndefined(); + } const expectedSequenceNumber = prevSequenceNumber + 1; // Ensure the sequence number and hash are correct before appending if (decodedClaim.payload.seq !== expectedSequenceNumber) { @@ -254,12 +248,8 @@ class Sigchain { claimData: ClaimData, tran?: DBTransaction, ): Promise { - const sequenceNumberPath = [ - ...this.sigchainMetadataDbPath, - this.sequenceNumberKey, - ]; if (tran == null) { - return this.withTransactionF(sequenceNumberPath, async (tran) => + return this.db.withTransactionF((tran) => this.createIntermediaryClaim(claimData, tran), ); } @@ -283,12 +273,13 @@ class Sigchain { @ready(new sigchainErrors.ErrorSigchainNotRunning()) public async getChainData(tran?: DBTransaction): Promise { if (tran == null) { - return this.withTransactionF(async (tran) => this.getChainData(tran)); + return this.db.withTransactionF((tran) => this.getChainData(tran)); } const chainData: ChainDataEncoded = {}; - const readIterator = tran.iterator({ valueAsBuffer: false }, [ - ...this.sigchainClaimsDbPath, - ]); + const readIterator = tran.iterator( + this.sigchainClaimsDbPath, + { valueAsBuffer: false }, + ); for await (const [keyPath, claimEncoded] of readIterator) { const key = keyPath[0] as Buffer; const claimId = IdInternal.fromBuffer(key); @@ -311,14 +302,15 @@ class Sigchain { tran?: DBTransaction, ): Promise> { if (tran == null) { - return this.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.getClaims(claimType, tran), ); } const relevantClaims: Array = []; - const readIterator = tran.iterator({ valueAsBuffer: false }, [ - ...this.sigchainClaimsDbPath, - ]); + const readIterator = tran.iterator( + this.sigchainClaimsDbPath, + { valueAsBuffer: false }, + ); for await (const [, claim] of readIterator) { const decodedClaim = claimsUtils.decodeClaim(claim); if (decodedClaim.payload.data.type === claimType) { @@ -378,9 +370,7 @@ class Sigchain { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.withTransactionF(async (tran) => - this.getClaim(claimId, tran), - ); + return this.db.withTransactionF((tran) => this.getClaim(claimId, tran)); } const claim = await tran.get([ ...this.sigchainClaimsDbPath, @@ -397,12 +387,12 @@ class Sigchain { tran?: DBTransaction, ): Promise> { if (tran == null) { - return this.withTransactionF(async (tran) => this.getSeqMap(tran)); + return this.db.withTransactionF((tran) => this.getSeqMap(tran)); } const map: Record = {}; - const claimStream = tran.iterator({ values: false }, [ - ...this.sigchainClaimsDbPath, - ]); + const claimStream = tran.iterator(this.sigchainClaimsDbPath, { + values: false, + }); let seq = 1; for await (const [keyPath] of claimStream) { const key = keyPath[0] as Buffer; @@ -416,10 +406,11 @@ class Sigchain { tran: DBTransaction, ): Promise { let latestId: ClaimId | undefined; - const keyStream = tran.iterator( - { limit: 1, reverse: true, values: false }, - [...this.sigchainClaimsDbPath], - ); + const keyStream = tran.iterator(this.sigchainClaimsDbPath, { + limit: 1, + reverse: true, + values: false, + }); for await (const [keyPath] of keyStream) { latestId = IdInternal.fromBuffer(keyPath[0] as Buffer); } diff --git a/src/types.ts b/src/types.ts index fae58ae01..d0d73eef5 100644 --- a/src/types.ts +++ b/src/types.ts @@ -63,6 +63,15 @@ type Timer = { timerP: Promise; }; +/** + * Deconstructed promise + */ +type PromiseDeconstructed = { + p: Promise; + resolveP: (value: T | PromiseLike) => void; + rejectP: (reason?: any) => void; +}; + /** * Minimal filesystem type * Based on the required operations from fs/promises @@ -115,6 +124,7 @@ export type { ToString, Ref, Timer, + PromiseDeconstructed, FileSystem, FileHandle, FunctionProperties, diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 46e7a131c..f7c904194 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -1,4 +1,9 @@ -import type { FileSystem, Timer, Callback } from '../types'; +import type { + FileSystem, + Timer, + PromiseDeconstructed, + Callback, +} from '../types'; import os from 'os'; import process from 'process'; import path from 'path'; @@ -170,12 +175,6 @@ function promisify< }; } -type PromiseDeconstructed = { - p: Promise; - resolveP: (value: T | PromiseLike) => void; - rejectP: (reason?: any) => void; -}; - /** * Deconstructed promise */ @@ -310,7 +309,6 @@ function debounce

( }; } -export type { PromiseDeconstructed }; export { getDefaultNodePath, never, diff --git a/src/vaults/VaultInternal.ts b/src/vaults/VaultInternal.ts index 0061d9185..69e40043f 100644 --- a/src/vaults/VaultInternal.ts +++ b/src/vaults/VaultInternal.ts @@ -68,7 +68,7 @@ class VaultInternal { tran?: DBTransaction; }): Promise { if (tran == null) { - return await db.withTransactionF(async (tran) => + return await db.withTransactionF((tran) => this.createVaultInternal({ vaultId, vaultName, @@ -122,7 +122,7 @@ class VaultInternal { tran?: DBTransaction; }): Promise { if (tran == null) { - return await db.withTransactionF(async (tran) => + return await db.withTransactionF((tran) => this.cloneVaultInternal({ targetNodeId, targetVaultNameOrId, @@ -266,7 +266,7 @@ class VaultInternal { tran?: DBTransaction; } = {}): Promise { if (tran == null) { - return await this.db.withTransactionF(async (tran) => + return await this.db.withTransactionF((tran) => this.start_(fresh, tran, vaultName), ); } @@ -328,9 +328,7 @@ class VaultInternal { public async destroy(tran?: DBTransaction): Promise { if (tran == null) { - return await this.db.withTransactionF(async (tran) => - this.destroy_(tran), - ); + return await this.db.withTransactionF((tran) => this.destroy_(tran)); } return await this.destroy_(tran); } @@ -444,23 +442,27 @@ class VaultInternal { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.db.withTransactionF(async (tran) => this.writeF(f, tran)); + return this.db.withTransactionF((tran) => this.writeF(f, tran)); } - // This should really be an internal property - // get whether this is remote, and the remote address - // if it is, we consider this repo an "attached repo" - // this vault is a "mirrored" vault - if ( - (await tran.get([ - ...this.vaultMetadataDbPath, - VaultInternal.remoteKey, - ])) != null - ) { - // Mirrored vaults are immutable - throw new vaultsErrors.ErrorVaultRemoteDefined(); - } return withF([this.lock.write()], async () => { + await tran.lock( + [...this.vaultMetadataDbPath, VaultInternal.dirtyKey].join(''), + ); + + // This should really be an internal property + // get whether this is remote, and the remote address + // if it is, we consider this repo an "attached repo" + // this vault is a "mirrored" vault + if ( + (await tran.get([ + ...this.vaultMetadataDbPath, + VaultInternal.remoteKey, + ])) != null + ) { + // Mirrored vaults are immutable + throw new vaultsErrors.ErrorVaultRemoteDefined(); + } await tran.put( [...this.vaultMetadataDbPath, VaultInternal.dirtyKey], true, @@ -502,6 +504,9 @@ class VaultInternal { // Mirrored vaults are immutable throw new vaultsErrors.ErrorVaultRemoteDefined(); } + await tran.lock( + [...vaultMetadataDbPath, VaultInternal.dirtyKey].join(''), + ); await tran.put([...vaultMetadataDbPath, VaultInternal.dirtyKey], true); let result; @@ -537,7 +542,7 @@ class VaultInternal { tran?: DBTransaction; }): Promise { if (tran == null) { - return this.db.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.pullVault({ nodeConnectionManager, pullNodeId, diff --git a/src/vaults/VaultManager.ts b/src/vaults/VaultManager.ts index e6fa716f6..2c1f8f582 100644 --- a/src/vaults/VaultManager.ts +++ b/src/vaults/VaultManager.ts @@ -116,7 +116,6 @@ class VaultManager { protected notificationsManager: NotificationsManager; protected vaultsDbPath: LevelPath = [this.constructor.name]; protected vaultsNamesDbPath: LevelPath = [this.constructor.name, 'names']; - protected vaultsNamesLock: RWLockWriter = new RWLockWriter(); // VaultId -> VaultMetadata protected vaultMap: VaultMap = new Map(); protected vaultLocks: LockBox = new LockBox(); @@ -181,7 +180,6 @@ class VaultManager { efs = await EncryptedFS.createEncryptedFS({ dbPath: this.efsPath, dbKey: vaultKey, - // @ts-ignore - version of js-logger is incompatible (remove when EFS logger updates to 3.*) logger: this.logger.getChild('EncryptedFileSystem'), }); } catch (e) { @@ -268,48 +266,47 @@ class VaultManager { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.db.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.createVault(vaultName, tran), ); } // Adding vault to name map const vaultId = await this.generateVaultId(); - return await this.vaultsNamesLock.withWriteF(async () => { - const vaultIdBuffer = await tran.get( - [...this.vaultsNamesDbPath, vaultName], - true, - ); - // Check if the vault name already exists; - if (vaultIdBuffer != null) { - throw new vaultsErrors.ErrorVaultsVaultDefined(); - } - await tran.put( - [...this.vaultsNamesDbPath, vaultName], - vaultId.toBuffer(), - true, - ); - const vaultIdString = vaultId.toString() as VaultIdString; - return await this.vaultLocks.withF( - [vaultId, RWLockWriter, 'write'], - async () => { - // Creating vault - const vault = await VaultInternal.createVaultInternal({ - vaultId, - vaultName, - keyManager: this.keyManager, - efs: this.efs, - logger: this.logger.getChild(VaultInternal.name), - db: this.db, - vaultsDbPath: this.vaultsDbPath, - fresh: true, - tran, - }); - // Adding vault to object map - this.vaultMap.set(vaultIdString, vault); - return vault.vaultId; - }, - ); - }); + await tran.lock([...this.vaultsNamesDbPath, vaultName].join('')); + const vaultIdBuffer = await tran.get( + [...this.vaultsNamesDbPath, vaultName], + true, + ); + // Check if the vault name already exists; + if (vaultIdBuffer != null) { + throw new vaultsErrors.ErrorVaultsVaultDefined(); + } + await tran.put( + [...this.vaultsNamesDbPath, vaultName], + vaultId.toBuffer(), + true, + ); + const vaultIdString = vaultId.toString() as VaultIdString; + return await this.vaultLocks.withF( + [vaultId, RWLockWriter, 'write'], + async () => { + // Creating vault + const vault = await VaultInternal.createVaultInternal({ + vaultId, + vaultName, + keyManager: this.keyManager, + efs: this.efs, + logger: this.logger.getChild(VaultInternal.name), + db: this.db, + vaultsDbPath: this.vaultsDbPath, + fresh: true, + tran, + }); + // Adding vault to object map + this.vaultMap.set(vaultIdString, vault); + return vault.vaultId; + }, + ); } /** @@ -322,7 +319,7 @@ class VaultManager { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.db.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.getVaultMeta(vaultId, tran), ); } @@ -362,17 +359,26 @@ class VaultManager { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.db.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.destroyVault(vaultId, tran), ); } - const vaultMeta = await this.getVaultMeta(vaultId, tran); - if (vaultMeta == null) return; - const vaultName = vaultMeta.vaultName; - this.logger.info(`Destroying Vault ${vaultsUtils.encodeVaultId(vaultId)}`); - const vaultIdString = vaultId.toString() as VaultIdString; await this.vaultLocks.withF([vaultId, RWLockWriter, 'write'], async () => { + await tran.lock([...this.vaultsDbPath, vaultId].join('')); + // Ensure protection from write skew + await tran.getForUpdate([ + ...this.vaultsDbPath, + vaultsUtils.encodeVaultId(vaultId), + VaultInternal.nameKey, + ]); + const vaultMeta = await this.getVaultMeta(vaultId, tran); + if (vaultMeta == null) return; + const vaultName = vaultMeta.vaultName; + this.logger.info( + `Destroying Vault ${vaultsUtils.encodeVaultId(vaultId)}`, + ); + const vaultIdString = vaultId.toString() as VaultIdString; const vault = await this.getVault(vaultId, tran); // Destroying vault state and metadata await vault.stop(); @@ -380,9 +386,7 @@ class VaultManager { // Removing from map this.vaultMap.delete(vaultIdString); // Removing name->id mapping - await this.vaultsNamesLock.withWriteF(async () => { - await tran.del([...this.vaultsNamesDbPath, vaultName]); - }); + await tran.del([...this.vaultsNamesDbPath, vaultName]); }); this.logger.info(`Destroyed Vault ${vaultsUtils.encodeVaultId(vaultId)}`); } @@ -396,9 +400,7 @@ class VaultManager { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.db.withTransactionF(async (tran) => - this.closeVault(vaultId, tran), - ); + return this.db.withTransactionF((tran) => this.closeVault(vaultId, tran)); } if ((await this.getVaultName(vaultId, tran)) == null) { @@ -406,6 +408,7 @@ class VaultManager { } const vaultIdString = vaultId.toString() as VaultIdString; await this.vaultLocks.withF([vaultId, RWLockWriter, 'write'], async () => { + await tran.lock([...this.vaultsDbPath, vaultId].join('')); const vault = await this.getVault(vaultId, tran); await vault.stop(); this.vaultMap.delete(vaultIdString); @@ -419,13 +422,12 @@ class VaultManager { @ready(new vaultsErrors.ErrorVaultManagerNotRunning()) public async listVaults(tran?: DBTransaction): Promise { if (tran == null) { - return this.db.withTransactionF(async (tran) => this.listVaults(tran)); + return this.db.withTransactionF((tran) => this.listVaults(tran)); } const vaults: VaultList = new Map(); // Stream of vaultName VaultId key value pairs for await (const [vaultNameBuffer, vaultIdBuffer] of tran.iterator( - undefined, this.vaultsNamesDbPath, )) { const vaultName = vaultNameBuffer.toString() as VaultName; @@ -445,17 +447,27 @@ class VaultManager { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.db.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.renameVault(vaultId, newVaultName, tran), ); } await this.vaultLocks.withF([vaultId, RWLockWriter, 'write'], async () => { + await tran.lock( + [...this.vaultsNamesDbPath, newVaultName].join(''), + [...this.vaultsDbPath, vaultId].join(''), + ); this.logger.info(`Renaming Vault ${vaultsUtils.encodeVaultId(vaultId)}`); // Checking if new name exists if (await this.getVaultId(newVaultName, tran)) { throw new vaultsErrors.ErrorVaultsVaultDefined(); } + // Ensure protection from write skew + await tran.getForUpdate([ + ...this.vaultsDbPath, + vaultsUtils.encodeVaultId(vaultId), + VaultInternal.nameKey, + ]); // Checking if vault exists const vaultMetadata = await this.getVaultMeta(vaultId, tran); if (vaultMetadata == null) { @@ -469,14 +481,12 @@ class VaultManager { ]; await tran.put([...vaultDbPath, VaultInternal.nameKey], newVaultName); // Updating name->id map - await this.vaultsNamesLock.withWriteF(async () => { - await tran.del([...this.vaultsNamesDbPath, oldVaultName]); - await tran.put( - [...this.vaultsNamesDbPath, newVaultName], - vaultId.toBuffer(), - true, - ); - }); + await tran.del([...this.vaultsNamesDbPath, oldVaultName]); + await tran.put( + [...this.vaultsNamesDbPath, newVaultName], + vaultId.toBuffer(), + true, + ); }); } @@ -489,19 +499,18 @@ class VaultManager { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.db.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.getVaultId(vaultName, tran), ); } - return await this.vaultsNamesLock.withWriteF(async () => { - const vaultIdBuffer = await tran.get( - [...this.vaultsNamesDbPath, vaultName], - true, - ); - if (vaultIdBuffer == null) return; - return IdInternal.fromBuffer(vaultIdBuffer); - }); + await tran.lock([...this.vaultsNamesDbPath, vaultName].join('')); + const vaultIdBuffer = await tran.get( + [...this.vaultsNamesDbPath, vaultName], + true, + ); + if (vaultIdBuffer == null) return; + return IdInternal.fromBuffer(vaultIdBuffer); } /** @@ -513,7 +522,7 @@ class VaultManager { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.db.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.getVaultName(vaultId, tran), ); } @@ -530,7 +539,7 @@ class VaultManager { tran?: DBTransaction, ): Promise> { if (tran == null) { - return this.db.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.getVaultPermission(vaultId, tran), ); } @@ -555,7 +564,7 @@ class VaultManager { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.db.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.shareVault(vaultId, nodeId, tran), ); } @@ -589,7 +598,7 @@ class VaultManager { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.db.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.unshareVault(vaultId, nodeId, tran), ); } @@ -612,7 +621,7 @@ class VaultManager { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.db.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.cloneVault(nodeId, vaultNameOrId, tran), ); } @@ -698,13 +707,14 @@ class VaultManager { tran?: DBTransaction; }): Promise { if (tran == null) { - return this.db.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.pullVault({ vaultId, pullNodeId, pullVaultNameOrId, tran }), ); } if ((await this.getVaultName(vaultId, tran)) == null) return; await this.vaultLocks.withF([vaultId, RWLockWriter, 'write'], async () => { + await tran.lock([...this.vaultsDbPath, vaultId].join('')); const vault = await this.getVault(vaultId, tran); await vault.pullVault({ nodeConnectionManager: this.nodeConnectionManager, @@ -768,7 +778,7 @@ class VaultManager { tran?: DBTransaction, ): Promise<[PassThrough, PassThrough]> { if (tran == null) { - return this.db.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.handlePackRequest(vaultId, body, tran), ); } @@ -914,9 +924,7 @@ class VaultManager { tran: DBTransaction, ): Promise { if (tran == null) { - return this.db.withTransactionF(async (tran) => - this.getVault(vaultId, tran), - ); + return this.db.withTransactionF((tran) => this.getVault(vaultId, tran)); } const vaultIdString = vaultId.toString() as VaultIdString; @@ -956,7 +964,7 @@ class VaultManager { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.db.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.withVaults(vaultIds, f, tran), ); } diff --git a/tests/acl/ACL.test.ts b/tests/acl/ACL.test.ts index 45e1b8baf..3236e1a3a 100644 --- a/tests/acl/ACL.test.ts +++ b/tests/acl/ACL.test.ts @@ -42,7 +42,6 @@ describe(ACL.name, () => { const dbPath = `${dataDir}/db`; db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when EFS logger updates to 3.*) logger, crypto: { key: dbKey, @@ -407,7 +406,7 @@ describe(ACL.name, () => { test('transactional operations', async () => { const acl = await ACL.createACL({ db, logger }); const p1 = acl.getNodePerms(); - const p2 = acl.withTransactionF(async (tran) => { + const p2 = db.withTransactionF(async (tran) => { await acl.setNodesPerm( [nodeIdG1First, nodeIdG1Second] as Array, { diff --git a/tests/agent/GRPCClientAgent.test.ts b/tests/agent/GRPCClientAgent.test.ts index 952ffdc8d..c7f710295 100644 --- a/tests/agent/GRPCClientAgent.test.ts +++ b/tests/agent/GRPCClientAgent.test.ts @@ -76,7 +76,6 @@ describe(GRPCClientAgent.name, () => { db = await DB.createDB({ dbPath: dbPath, fs: fs, - // @ts-ignore - version of js-logger is incompatible (remove when EFS logger updates to 3.*) logger: logger, crypto: { key: keyManager.dbKey, diff --git a/tests/agent/service/notificationsSend.test.ts b/tests/agent/service/notificationsSend.test.ts index e087b6ffb..506941396 100644 --- a/tests/agent/service/notificationsSend.test.ts +++ b/tests/agent/service/notificationsSend.test.ts @@ -74,7 +74,6 @@ describe('notificationsSend', () => { const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when EFS logger updates to 3.*) logger, }); acl = await ACL.createACL({ diff --git a/tests/client/service/agentLockAll.test.ts b/tests/client/service/agentLockAll.test.ts index 659433f8b..49bfa9306 100644 --- a/tests/client/service/agentLockAll.test.ts +++ b/tests/client/service/agentLockAll.test.ts @@ -44,7 +44,6 @@ describe('agentLockall', () => { const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when EFS logger updates to 3.*) logger, crypto: { key: keyManager.dbKey, diff --git a/tests/client/service/gestaltsActionsSetUnsetGetByIdentity.test.ts b/tests/client/service/gestaltsActionsSetUnsetGetByIdentity.test.ts index daf72bb55..381ec9b60 100644 --- a/tests/client/service/gestaltsActionsSetUnsetGetByIdentity.test.ts +++ b/tests/client/service/gestaltsActionsSetUnsetGetByIdentity.test.ts @@ -55,7 +55,6 @@ describe('gestaltsActionsByIdentity', () => { const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when EFS logger updates to 3.*) logger, }); acl = await ACL.createACL({ diff --git a/tests/client/service/gestaltsActionsSetUnsetGetByNode.test.ts b/tests/client/service/gestaltsActionsSetUnsetGetByNode.test.ts index 25bdafd0f..439f9b754 100644 --- a/tests/client/service/gestaltsActionsSetUnsetGetByNode.test.ts +++ b/tests/client/service/gestaltsActionsSetUnsetGetByNode.test.ts @@ -49,7 +49,6 @@ describe('gestaltsActionsByNode', () => { const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when EFS logger updates to 3.*) logger, }); acl = await ACL.createACL({ diff --git a/tests/client/service/gestaltsDiscoveryByIdentity.test.ts b/tests/client/service/gestaltsDiscoveryByIdentity.test.ts index a7696a7c2..0b9dd8c44 100644 --- a/tests/client/service/gestaltsDiscoveryByIdentity.test.ts +++ b/tests/client/service/gestaltsDiscoveryByIdentity.test.ts @@ -69,7 +69,6 @@ describe('gestaltsDiscoveryByIdentity', () => { const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when EFS logger updates to 3.*) logger, crypto: { key: keyManager.dbKey, diff --git a/tests/client/service/gestaltsDiscoveryByNode.test.ts b/tests/client/service/gestaltsDiscoveryByNode.test.ts index 175511661..d0d77b431 100644 --- a/tests/client/service/gestaltsDiscoveryByNode.test.ts +++ b/tests/client/service/gestaltsDiscoveryByNode.test.ts @@ -70,7 +70,6 @@ describe('gestaltsDiscoveryByNode', () => { const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when EFS logger updates to 3.*) logger, crypto: { key: keyManager.dbKey, diff --git a/tests/client/service/gestaltsGestaltGetByIdentity.test.ts b/tests/client/service/gestaltsGestaltGetByIdentity.test.ts index 926b363f7..b6ecc2d71 100644 --- a/tests/client/service/gestaltsGestaltGetByIdentity.test.ts +++ b/tests/client/service/gestaltsGestaltGetByIdentity.test.ts @@ -73,7 +73,6 @@ describe('gestaltsGestaltGetByIdentity', () => { const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when EFS logger updates to 3.*) logger, }); acl = await ACL.createACL({ diff --git a/tests/client/service/gestaltsGestaltGetByNode.test.ts b/tests/client/service/gestaltsGestaltGetByNode.test.ts index 3a5c23ebf..1d7a3ceb6 100644 --- a/tests/client/service/gestaltsGestaltGetByNode.test.ts +++ b/tests/client/service/gestaltsGestaltGetByNode.test.ts @@ -70,7 +70,6 @@ describe('gestaltsGestaltGetByNode', () => { const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when EFS logger updates to 3.*) logger, }); acl = await ACL.createACL({ diff --git a/tests/client/service/gestaltsGestaltList.test.ts b/tests/client/service/gestaltsGestaltList.test.ts index f118fdf51..1075a34f8 100644 --- a/tests/client/service/gestaltsGestaltList.test.ts +++ b/tests/client/service/gestaltsGestaltList.test.ts @@ -75,7 +75,6 @@ describe('gestaltsGestaltList', () => { const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when EFS logger updates to 3.*) logger, }); acl = await ACL.createACL({ diff --git a/tests/client/service/gestaltsGestaltTrustByIdentity.test.ts b/tests/client/service/gestaltsGestaltTrustByIdentity.test.ts index 4e10d8c45..052295ed7 100644 --- a/tests/client/service/gestaltsGestaltTrustByIdentity.test.ts +++ b/tests/client/service/gestaltsGestaltTrustByIdentity.test.ts @@ -121,7 +121,6 @@ describe('gestaltsGestaltTrustByIdentity', () => { const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when EFS logger updates to 3.*) logger, crypto: { key: keyManager.dbKey, diff --git a/tests/client/service/gestaltsGestaltTrustByNode.test.ts b/tests/client/service/gestaltsGestaltTrustByNode.test.ts index 4b716d59d..b32462ff5 100644 --- a/tests/client/service/gestaltsGestaltTrustByNode.test.ts +++ b/tests/client/service/gestaltsGestaltTrustByNode.test.ts @@ -129,7 +129,6 @@ describe('gestaltsGestaltTrustByNode', () => { const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when EFS logger updates to 3.*) logger, crypto: { key: keyManager.dbKey, diff --git a/tests/client/service/identitiesAuthenticate.test.ts b/tests/client/service/identitiesAuthenticate.test.ts index 29fa35d7f..bdb6a53b8 100644 --- a/tests/client/service/identitiesAuthenticate.test.ts +++ b/tests/client/service/identitiesAuthenticate.test.ts @@ -45,7 +45,6 @@ describe('identitiesAuthenticate', () => { const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when EFS logger updates to 3.*) logger, }); identitiesManager = await IdentitiesManager.createIdentitiesManager({ diff --git a/tests/client/service/identitiesAuthenticatedGet.test.ts b/tests/client/service/identitiesAuthenticatedGet.test.ts index 84bfa0744..1dacdddbc 100644 --- a/tests/client/service/identitiesAuthenticatedGet.test.ts +++ b/tests/client/service/identitiesAuthenticatedGet.test.ts @@ -38,7 +38,6 @@ describe('identitiesAuthenticatedGet', () => { const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when EFS logger updates to 3.*) logger, }); identitiesManager = await IdentitiesManager.createIdentitiesManager({ diff --git a/tests/client/service/identitiesClaim.test.ts b/tests/client/service/identitiesClaim.test.ts index 521ee0769..1dcba0893 100644 --- a/tests/client/service/identitiesClaim.test.ts +++ b/tests/client/service/identitiesClaim.test.ts @@ -98,7 +98,6 @@ describe('identitiesClaim', () => { const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when EFS logger updates to 3.*) logger, }); identitiesManager = await IdentitiesManager.createIdentitiesManager({ diff --git a/tests/client/service/identitiesInfoConnectedGet.test.ts b/tests/client/service/identitiesInfoConnectedGet.test.ts index f51277578..4043abef5 100644 --- a/tests/client/service/identitiesInfoConnectedGet.test.ts +++ b/tests/client/service/identitiesInfoConnectedGet.test.ts @@ -43,7 +43,6 @@ describe('identitiesInfoConnectedGet', () => { const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when EFS logger updates to 3.*) logger, }); identitiesManager = await IdentitiesManager.createIdentitiesManager({ diff --git a/tests/client/service/identitiesInfoGet.test.ts b/tests/client/service/identitiesInfoGet.test.ts index f87336beb..68b9df655 100644 --- a/tests/client/service/identitiesInfoGet.test.ts +++ b/tests/client/service/identitiesInfoGet.test.ts @@ -41,7 +41,6 @@ describe('identitiesInfoGet', () => { const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when EFS logger updates to 3.*) logger, }); identitiesManager = await IdentitiesManager.createIdentitiesManager({ diff --git a/tests/client/service/identitiesProvidersList.test.ts b/tests/client/service/identitiesProvidersList.test.ts index d48d4c610..e75ffd477 100644 --- a/tests/client/service/identitiesProvidersList.test.ts +++ b/tests/client/service/identitiesProvidersList.test.ts @@ -50,7 +50,6 @@ describe('identitiesProvidersList', () => { const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when EFS logger updates to 3.*) logger, }); identitiesManager = await IdentitiesManager.createIdentitiesManager({ diff --git a/tests/client/service/identitiesTokenPutDeleteGet.test.ts b/tests/client/service/identitiesTokenPutDeleteGet.test.ts index 3bfba7e90..1752e2f94 100644 --- a/tests/client/service/identitiesTokenPutDeleteGet.test.ts +++ b/tests/client/service/identitiesTokenPutDeleteGet.test.ts @@ -45,7 +45,6 @@ describe('identitiesTokenPutDeleteGet', () => { const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when EFS logger updates to 3.*) logger, }); identitiesManager = await IdentitiesManager.createIdentitiesManager({ diff --git a/tests/client/service/nodesAdd.test.ts b/tests/client/service/nodesAdd.test.ts index 4cc770b0d..fe28906de 100644 --- a/tests/client/service/nodesAdd.test.ts +++ b/tests/client/service/nodesAdd.test.ts @@ -58,7 +58,6 @@ describe('nodesAdd', () => { const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when DB updates to 5.*) logger, }); proxy = new Proxy({ diff --git a/tests/client/service/nodesClaim.test.ts b/tests/client/service/nodesClaim.test.ts index fc1b4e81e..55fe371d7 100644 --- a/tests/client/service/nodesClaim.test.ts +++ b/tests/client/service/nodesClaim.test.ts @@ -90,7 +90,6 @@ describe('nodesClaim', () => { const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when EFS logger updates to 3.*) logger, }); acl = await ACL.createACL({ diff --git a/tests/client/service/nodesFind.test.ts b/tests/client/service/nodesFind.test.ts index 771215b74..f8dd24b27 100644 --- a/tests/client/service/nodesFind.test.ts +++ b/tests/client/service/nodesFind.test.ts @@ -67,7 +67,6 @@ describe('nodesFind', () => { const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when EFS logger updates to 3.*) logger, }); proxy = new Proxy({ diff --git a/tests/client/service/nodesPing.test.ts b/tests/client/service/nodesPing.test.ts index 6349c5b23..5874207df 100644 --- a/tests/client/service/nodesPing.test.ts +++ b/tests/client/service/nodesPing.test.ts @@ -67,7 +67,6 @@ describe('nodesPing', () => { const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when EFS logger updates to 3.*) logger, }); proxy = new Proxy({ diff --git a/tests/client/service/notificationsClear.test.ts b/tests/client/service/notificationsClear.test.ts index efaabf480..64aa78eb8 100644 --- a/tests/client/service/notificationsClear.test.ts +++ b/tests/client/service/notificationsClear.test.ts @@ -67,7 +67,6 @@ describe('notificationsClear', () => { const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when EFS logger updates to 3.*) logger, }); acl = await ACL.createACL({ diff --git a/tests/client/service/notificationsRead.test.ts b/tests/client/service/notificationsRead.test.ts index dd0c313e6..a39860841 100644 --- a/tests/client/service/notificationsRead.test.ts +++ b/tests/client/service/notificationsRead.test.ts @@ -142,7 +142,6 @@ describe('notificationsRead', () => { const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when EFS logger updates to 3.*) logger, }); acl = await ACL.createACL({ diff --git a/tests/client/service/notificationsSend.test.ts b/tests/client/service/notificationsSend.test.ts index 2757f6bb0..3c5aecbce 100644 --- a/tests/client/service/notificationsSend.test.ts +++ b/tests/client/service/notificationsSend.test.ts @@ -77,7 +77,6 @@ describe('notificationsSend', () => { const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when EFS logger updates to 3.*) logger, }); acl = await ACL.createACL({ diff --git a/tests/client/service/vaultsClone.test.ts b/tests/client/service/vaultsClone.test.ts index e9f906b87..536cbd8ba 100644 --- a/tests/client/service/vaultsClone.test.ts +++ b/tests/client/service/vaultsClone.test.ts @@ -35,7 +35,6 @@ describe('vaultsClone', () => { const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when EFS logger updates to 3.*) logger, }); const vaultsPath = path.join(dataDir, 'vaults'); diff --git a/tests/client/service/vaultsCreateDeleteList.test.ts b/tests/client/service/vaultsCreateDeleteList.test.ts index f7159d630..ced8acaa5 100644 --- a/tests/client/service/vaultsCreateDeleteList.test.ts +++ b/tests/client/service/vaultsCreateDeleteList.test.ts @@ -50,7 +50,6 @@ describe('vaultsCreateDeleteList', () => { const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when EFS logger updates to 3.*) logger, }); const vaultsPath = path.join(dataDir, 'vaults'); diff --git a/tests/client/service/vaultsLog.test.ts b/tests/client/service/vaultsLog.test.ts index 96c1c1ae9..97e1448b7 100644 --- a/tests/client/service/vaultsLog.test.ts +++ b/tests/client/service/vaultsLog.test.ts @@ -55,7 +55,6 @@ describe('vaultsLog', () => { const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when EFS logger updates to 3.*) logger, }); const vaultsPath = path.join(dataDir, 'vaults'); diff --git a/tests/client/service/vaultsPermissionSetUnsetGet.test.ts b/tests/client/service/vaultsPermissionSetUnsetGet.test.ts index e025591f2..7563c3109 100644 --- a/tests/client/service/vaultsPermissionSetUnsetGet.test.ts +++ b/tests/client/service/vaultsPermissionSetUnsetGet.test.ts @@ -66,7 +66,6 @@ describe('vaultsPermissionSetUnsetGet', () => { const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when EFS logger updates to 3.*) logger, }); acl = await ACL.createACL({ diff --git a/tests/client/service/vaultsPull.test.ts b/tests/client/service/vaultsPull.test.ts index f438fa71f..8d3951cb8 100644 --- a/tests/client/service/vaultsPull.test.ts +++ b/tests/client/service/vaultsPull.test.ts @@ -35,7 +35,6 @@ describe('vaultsPull', () => { const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when EFS logger updates to 3.*) logger, }); const vaultsPath = path.join(dataDir, 'vaults'); diff --git a/tests/client/service/vaultsRename.test.ts b/tests/client/service/vaultsRename.test.ts index d14463091..637c6f288 100644 --- a/tests/client/service/vaultsRename.test.ts +++ b/tests/client/service/vaultsRename.test.ts @@ -48,7 +48,6 @@ describe('vaultsRename', () => { const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when EFS logger updates to 3.*) logger, }); const vaultsPath = path.join(dataDir, 'vaults'); diff --git a/tests/client/service/vaultsSecretsEdit.test.ts b/tests/client/service/vaultsSecretsEdit.test.ts index 817cda396..e805b9eb7 100644 --- a/tests/client/service/vaultsSecretsEdit.test.ts +++ b/tests/client/service/vaultsSecretsEdit.test.ts @@ -50,7 +50,6 @@ describe('vaultsSecretsEdit', () => { const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when EFS logger updates to 3.*) logger, }); const vaultsPath = path.join(dataDir, 'vaults'); diff --git a/tests/client/service/vaultsSecretsMkdir.test.ts b/tests/client/service/vaultsSecretsMkdir.test.ts index 7b78c6e54..ee50aaff7 100644 --- a/tests/client/service/vaultsSecretsMkdir.test.ts +++ b/tests/client/service/vaultsSecretsMkdir.test.ts @@ -49,7 +49,6 @@ describe('vaultsSecretsMkdir', () => { const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when EFS logger updates to 3.*) logger, }); const vaultsPath = path.join(dataDir, 'vaults'); diff --git a/tests/client/service/vaultsSecretsNewDeleteGet.test.ts b/tests/client/service/vaultsSecretsNewDeleteGet.test.ts index 32ed9030f..b23fbc8e2 100644 --- a/tests/client/service/vaultsSecretsNewDeleteGet.test.ts +++ b/tests/client/service/vaultsSecretsNewDeleteGet.test.ts @@ -53,7 +53,6 @@ describe('vaultsSecretsNewDeleteGet', () => { const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when EFS logger updates to 3.*) logger, }); const vaultsPath = path.join(dataDir, 'vaults'); diff --git a/tests/client/service/vaultsSecretsNewDirList.test.ts b/tests/client/service/vaultsSecretsNewDirList.test.ts index e0ed0fda7..01a8bf462 100644 --- a/tests/client/service/vaultsSecretsNewDirList.test.ts +++ b/tests/client/service/vaultsSecretsNewDirList.test.ts @@ -51,7 +51,6 @@ describe('vaultsSecretsNewDirList', () => { const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when EFS logger updates to 3.*) logger, }); const vaultsPath = path.join(dataDir, 'vaults'); diff --git a/tests/client/service/vaultsSecretsRename.test.ts b/tests/client/service/vaultsSecretsRename.test.ts index 51c458523..b54acd01e 100644 --- a/tests/client/service/vaultsSecretsRename.test.ts +++ b/tests/client/service/vaultsSecretsRename.test.ts @@ -50,7 +50,6 @@ describe('vaultsSecretsRename', () => { const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when EFS logger updates to 3.*) logger, }); const vaultsPath = path.join(dataDir, 'vaults'); diff --git a/tests/client/service/vaultsSecretsStat.test.ts b/tests/client/service/vaultsSecretsStat.test.ts index 80ec8eaed..33b6b3cec 100644 --- a/tests/client/service/vaultsSecretsStat.test.ts +++ b/tests/client/service/vaultsSecretsStat.test.ts @@ -50,7 +50,6 @@ describe('vaultsSecretsStat', () => { const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when EFS logger updates to 3.*) logger, }); const vaultsPath = path.join(dataDir, 'vaults'); diff --git a/tests/client/service/vaultsVersion.test.ts b/tests/client/service/vaultsVersion.test.ts index 7e0e3f13a..c397eafe7 100644 --- a/tests/client/service/vaultsVersion.test.ts +++ b/tests/client/service/vaultsVersion.test.ts @@ -60,7 +60,6 @@ describe('vaultsVersion', () => { const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when EFS logger updates to 3.*) logger, }); const vaultsPath = path.join(dataDir, 'vaults'); diff --git a/tests/discovery/Discovery.test.ts b/tests/discovery/Discovery.test.ts index f4fbddd4e..2e59779b1 100644 --- a/tests/discovery/Discovery.test.ts +++ b/tests/discovery/Discovery.test.ts @@ -72,7 +72,6 @@ describe('Discovery', () => { const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when EFS logger updates to 3.*) logger: logger.getChild('db'), crypto: { key: keyManager.dbKey, diff --git a/tests/gestalts/GestaltGraph.test.ts b/tests/gestalts/GestaltGraph.test.ts index 2ef000424..e24a08e00 100644 --- a/tests/gestalts/GestaltGraph.test.ts +++ b/tests/gestalts/GestaltGraph.test.ts @@ -55,7 +55,6 @@ describe('GestaltGraph', () => { const dbPath = `${dataDir}/db`; db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when EFS logger updates to 3.*) logger, crypto: { key: await keysUtils.generateKey(), diff --git a/tests/git/utils.test.ts b/tests/git/utils.test.ts index 33c40a80a..46d4e2542 100644 --- a/tests/git/utils.test.ts +++ b/tests/git/utils.test.ts @@ -30,7 +30,6 @@ describe('Git utils', () => { efs = await EncryptedFS.createEncryptedFS({ dbKey, dbPath: dataDir, - // @ts-ignore - version of js-logger is incompatible (remove when EFS logger updates to 3.*) logger, }); await efs.start(); diff --git a/tests/global.d.ts b/tests/global.d.ts index d286db7d5..ecd25dd85 100644 --- a/tests/global.d.ts +++ b/tests/global.d.ts @@ -1,4 +1,7 @@ /* eslint-disable no-var */ + +/// + /** * Follows the globals in jest.config.ts * @module diff --git a/tests/grpc/GRPCClient.test.ts b/tests/grpc/GRPCClient.test.ts index 5d7f6b8d5..f013c8822 100644 --- a/tests/grpc/GRPCClient.test.ts +++ b/tests/grpc/GRPCClient.test.ts @@ -53,7 +53,6 @@ describe('GRPCClient', () => { const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when EFS logger updates to 3.*) logger, crypto: { key: await keysUtils.generateKey(), diff --git a/tests/grpc/GRPCServer.test.ts b/tests/grpc/GRPCServer.test.ts index 5c8a7777f..285018cb1 100644 --- a/tests/grpc/GRPCServer.test.ts +++ b/tests/grpc/GRPCServer.test.ts @@ -40,7 +40,6 @@ describe('GRPCServer', () => { const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when EFS logger updates to 3.*) logger, crypto: { key: keyManager.dbKey, diff --git a/tests/identities/IdentitiesManager.test.ts b/tests/identities/IdentitiesManager.test.ts index 1e2a39a7b..23000440b 100644 --- a/tests/identities/IdentitiesManager.test.ts +++ b/tests/identities/IdentitiesManager.test.ts @@ -32,7 +32,6 @@ describe('IdentitiesManager', () => { const dbPath = `${dataDir}/db`; db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when EFS logger updates to 3.*) logger, crypto: { key: await keysUtils.generateKey(), diff --git a/tests/keys/KeyManager.test.ts b/tests/keys/KeyManager.test.ts index 776949df4..f2d707eae 100644 --- a/tests/keys/KeyManager.test.ts +++ b/tests/keys/KeyManager.test.ts @@ -326,7 +326,6 @@ describe('KeyManager', () => { const dbPath = `${dataDir}/db`; const db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when DB updates to 5.*) logger, crypto: { key: keyManager.dbKey, @@ -376,7 +375,6 @@ describe('KeyManager', () => { const dbPath = `${dataDir}/db`; const db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when DB updates to 5.*) logger, crypto: { key: keyManager.dbKey, diff --git a/tests/nodes/NodeConnection.test.ts b/tests/nodes/NodeConnection.test.ts index 0d71d371d..3afb53aa1 100644 --- a/tests/nodes/NodeConnection.test.ts +++ b/tests/nodes/NodeConnection.test.ts @@ -206,7 +206,6 @@ describe(`${NodeConnection.name} test`, () => { serverDb = await DB.createDB({ dbPath: serverDbPath, fs: fs, - // @ts-ignore - version of js-logger is incompatible (remove when DB updates to 5.*) logger: logger, crypto: { key: serverKeyManager.dbKey, diff --git a/tests/nodes/NodeConnectionManager.general.test.ts b/tests/nodes/NodeConnectionManager.general.test.ts index 48fbd9689..28423dde9 100644 --- a/tests/nodes/NodeConnectionManager.general.test.ts +++ b/tests/nodes/NodeConnectionManager.general.test.ts @@ -183,7 +183,6 @@ describe(`${NodeConnectionManager.name} general test`, () => { const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when DB updates to 5.*) logger: nodeConnectionManagerLogger, crypto: { key: keyManager.dbKey, diff --git a/tests/nodes/NodeConnectionManager.lifecycle.test.ts b/tests/nodes/NodeConnectionManager.lifecycle.test.ts index 9de7e6e5f..c9ff18cff 100644 --- a/tests/nodes/NodeConnectionManager.lifecycle.test.ts +++ b/tests/nodes/NodeConnectionManager.lifecycle.test.ts @@ -141,7 +141,6 @@ describe(`${NodeConnectionManager.name} lifecycle test`, () => { const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when DB updates to 5.*) logger: nodeConnectionManagerLogger, crypto: { key: keyManager.dbKey, diff --git a/tests/nodes/NodeConnectionManager.seednodes.test.ts b/tests/nodes/NodeConnectionManager.seednodes.test.ts index 46518a996..4c8d62440 100644 --- a/tests/nodes/NodeConnectionManager.seednodes.test.ts +++ b/tests/nodes/NodeConnectionManager.seednodes.test.ts @@ -141,7 +141,6 @@ describe(`${NodeConnectionManager.name} seed nodes test`, () => { const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when DB updates to 5.*) logger: logger, crypto: { key: keyManager.dbKey, diff --git a/tests/nodes/NodeConnectionManager.termination.test.ts b/tests/nodes/NodeConnectionManager.termination.test.ts index bdf7c4a6b..5436a9fbb 100644 --- a/tests/nodes/NodeConnectionManager.termination.test.ts +++ b/tests/nodes/NodeConnectionManager.termination.test.ts @@ -100,7 +100,6 @@ describe(`${NodeConnectionManager.name} termination test`, () => { const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when DB updates to 5.*) logger: logger, crypto: { key: keyManager.dbKey, diff --git a/tests/nodes/NodeConnectionManager.timeout.test.ts b/tests/nodes/NodeConnectionManager.timeout.test.ts index 35884d0b0..d356f1f55 100644 --- a/tests/nodes/NodeConnectionManager.timeout.test.ts +++ b/tests/nodes/NodeConnectionManager.timeout.test.ts @@ -131,7 +131,6 @@ describe(`${NodeConnectionManager.name} timeout test`, () => { const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when DB updates to 5.*) logger: nodeConnectionManagerLogger, crypto: { key: keyManager.dbKey, diff --git a/tests/nodes/NodeGraph.test.ts b/tests/nodes/NodeGraph.test.ts index 81a4fb153..7e9631514 100644 --- a/tests/nodes/NodeGraph.test.ts +++ b/tests/nodes/NodeGraph.test.ts @@ -54,7 +54,6 @@ describe(`${NodeGraph.name} test`, () => { beforeEach(async () => { db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when DB updates to 5.*) logger, crypto: { key: dbKey, diff --git a/tests/nodes/NodeManager.test.ts b/tests/nodes/NodeManager.test.ts index b7a2d8059..f2ed4dfb5 100644 --- a/tests/nodes/NodeManager.test.ts +++ b/tests/nodes/NodeManager.test.ts @@ -92,7 +92,6 @@ describe(`${NodeManager.name} test`, () => { const dbPath = `${dataDir}/db`; db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when DB updates to 5.*) logger, crypto: { key: keyManager.dbKey, diff --git a/tests/nodes/utils.test.ts b/tests/nodes/utils.test.ts index 64d7c7afe..daf2d40dd 100644 --- a/tests/nodes/utils.test.ts +++ b/tests/nodes/utils.test.ts @@ -25,7 +25,6 @@ describe('nodes/utils', () => { const dbPath = `${dataDir}/db`; db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when DB updates to 5.*) logger, crypto: { key: dbKey, @@ -122,7 +121,7 @@ describe('nodes/utils', () => { data.sort((a, b) => Buffer.compare(a.key, b.key)); let i = 0; - for await (const [key] of db.iterator({}, bucketsDbPath)) { + for await (const [key] of db.iterator(bucketsDbPath)) { const { bucketIndex, bucketKey, nodeId } = nodesUtils.parseBucketsDbKey( key as Array, ); @@ -162,7 +161,7 @@ describe('nodes/utils', () => { // the bucket key and last updated and node ID data.sort((a, b) => Buffer.compare(a.key, b.key)); let i = 0; - for await (const [key] of db.iterator({}, lastUpdatedDbPath)) { + for await (const [key] of db.iterator(lastUpdatedDbPath)) { const { bucketIndex, bucketKey, lastUpdated, nodeId } = nodesUtils.parseLastUpdatedBucketsDbKey(key as Array); expect(bucketIndex).toBe(data[i].bucketIndex); diff --git a/tests/notifications/NotificationsManager.test.ts b/tests/notifications/NotificationsManager.test.ts index d9bd3accc..0a4d23f3e 100644 --- a/tests/notifications/NotificationsManager.test.ts +++ b/tests/notifications/NotificationsManager.test.ts @@ -71,7 +71,6 @@ describe('NotificationsManager', () => { const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when DB updates to 5.*) logger, crypto: { key: keyManager.dbKey, diff --git a/tests/sessions/SessionManager.test.ts b/tests/sessions/SessionManager.test.ts index eecd1cf8c..4bdad8cb2 100644 --- a/tests/sessions/SessionManager.test.ts +++ b/tests/sessions/SessionManager.test.ts @@ -35,7 +35,6 @@ describe('SessionManager', () => { const dbPath = path.join(dataDir, 'db'); db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when DB updates to 5.*) logger, crypto: { key: keyManager.dbKey, diff --git a/tests/sigchain/Sigchain.test.ts b/tests/sigchain/Sigchain.test.ts index 45da1b665..b51ee110f 100644 --- a/tests/sigchain/Sigchain.test.ts +++ b/tests/sigchain/Sigchain.test.ts @@ -59,7 +59,6 @@ describe('Sigchain', () => { const dbPath = `${dataDir}/db`; db = await DB.createDB({ dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when DB updates to 5.*) logger, crypto: { key: keyManager.dbKey, @@ -96,7 +95,7 @@ describe('Sigchain', () => { }); test('async start initialises the sequence number', async () => { const sigchain = await Sigchain.createSigchain({ keyManager, db, logger }); - const sequenceNumber = await sigchain.withTransactionF(async (tran) => + const sequenceNumber = await db.withTransactionF(async (tran) => // @ts-ignore - get protected method sigchain.getSequenceNumber(tran), ); @@ -237,11 +236,11 @@ describe('Sigchain', () => { // Create a claim // Firstly, check that we can add an existing claim if it's the first claim // in the sigchain - const hPrev1 = await sigchain.withTransactionF(async (tran) => + const hPrev1 = await db.withTransactionF(async (tran) => // @ts-ignore - get protected method sigchain.getHashPrevious(tran), ); - const seq1 = await sigchain.withTransactionF(async (tran) => + const seq1 = await db.withTransactionF(async (tran) => // @ts-ignore - get protected method sigchain.getSequenceNumber(tran), ); @@ -259,11 +258,11 @@ describe('Sigchain', () => { kid: nodeIdAEncoded, }); await sigchain.addExistingClaim(claim1); - const hPrev2 = await sigchain.withTransactionF(async (tran) => + const hPrev2 = await db.withTransactionF(async (tran) => // @ts-ignore - get protected method sigchain.getHashPrevious(tran), ); - const seq2 = await sigchain.withTransactionF(async (tran) => + const seq2 = await db.withTransactionF(async (tran) => // @ts-ignore - get protected method sigchain.getSequenceNumber(tran), ); @@ -283,11 +282,11 @@ describe('Sigchain', () => { kid: nodeIdAEncoded, }); await sigchain.addExistingClaim(claim2); - const hPrev3 = await sigchain.withTransactionF(async (tran) => + const hPrev3 = await db.withTransactionF(async (tran) => // @ts-ignore - get protected method sigchain.getHashPrevious(tran), ); - const seq3 = await sigchain.withTransactionF(async (tran) => + const seq3 = await db.withTransactionF(async (tran) => // @ts-ignore - get protected method sigchain.getSequenceNumber(tran), ); diff --git a/tests/vaults/VaultInternal.test.ts b/tests/vaults/VaultInternal.test.ts index 59757a7b3..5c41d18bf 100644 --- a/tests/vaults/VaultInternal.test.ts +++ b/tests/vaults/VaultInternal.test.ts @@ -56,7 +56,6 @@ describe('VaultInternal', () => { efs = await EncryptedFS.createEncryptedFS({ dbPath: efsDbPath, dbKey, - // @ts-ignore - version of js-logger is incompatible (remove when EFS logger updates to 3.*) logger, }); await efs.start(); @@ -71,7 +70,6 @@ describe('VaultInternal', () => { }, dbPath: path.join(dataDir, 'db'), fs: fs, - // @ts-ignore - version of js-logger is incompatible (remove when EFS logger updates to 3.*) logger: logger, }); vaultsDbPath = ['vaults']; diff --git a/tests/vaults/VaultManager.test.ts b/tests/vaults/VaultManager.test.ts index 82d8ad532..762010273 100644 --- a/tests/vaults/VaultManager.test.ts +++ b/tests/vaults/VaultManager.test.ts @@ -73,7 +73,6 @@ describe('VaultManager', () => { vaultsPath = path.join(dataDir, 'VAULTS'); db = await DB.createDB({ dbPath: path.join(dataDir, 'DB'), - // @ts-ignore - version of js-logger is incompatible (remove when DB updates to 5.*) logger: logger.getChild(DB.name), }); }); @@ -317,7 +316,7 @@ describe('VaultManager', () => { }, globalThis.defaultTimeout * 2, ); - test('cannot concurrently create vaults with the same name', async () => { + test('concurrently creating vault with same name only creates 1 vault', async () => { const vaultManager = await VaultManager.createVaultManager({ vaultsPath, keyManager: dummyKeyManager, @@ -329,13 +328,15 @@ describe('VaultManager', () => { logger: logger.getChild(VaultManager.name), }); try { - const vaults = Promise.all([ - vaultManager.createVault(vaultName), - vaultManager.createVault(vaultName), - ]); - await expect(() => vaults).rejects.toThrow( - vaultsErrors.ErrorVaultsVaultDefined, - ); + await expect( + Promise.all([ + vaultManager.createVault(vaultName), + vaultManager.createVault(vaultName), + ]), + ).rejects.toThrow(vaultsErrors.ErrorVaultsVaultDefined); + // @ts-ignore: kidnapping the map + const vaultMap = vaultManager.vaultMap; + expect(vaultMap.size).toBe(1); } finally { await vaultManager?.stop(); await vaultManager?.destroy(); @@ -427,7 +428,7 @@ describe('VaultManager', () => { await vaultManager?.destroy(); } }); - test('Do actions on a vault using `withVault`', async () => { + test('do actions on a vault using `withVault`', async () => { const vaultManager = await VaultManager.createVaultManager({ vaultsPath, keyManager: dummyKeyManager, @@ -470,7 +471,7 @@ describe('VaultManager', () => { await vaultManager?.destroy(); } }); - describe('With remote agents', () => { + describe('with remote agents', () => { let allDataDir: string; let keyManager: KeyManager; let proxy: Proxy; @@ -1464,7 +1465,7 @@ describe('VaultManager', () => { await acl.destroy(); } }); - test('ScanVaults should get all vaults with permissions from remote node', async () => { + test('scanVaults should get all vaults with permissions from remote node', async () => { // 1. we need to set up state const remoteAgent = await PolykeyAgent.createPolykeyAgent({ password: 'password', @@ -1739,7 +1740,7 @@ describe('VaultManager', () => { await vaultManager?.destroy(); } }); - test('Creation adds a vault', async () => { + test('creation adds a vault', async () => { const vaultManager = await VaultManager.createVaultManager({ vaultsPath, keyManager: dummyKeyManager, @@ -1760,33 +1761,6 @@ describe('VaultManager', () => { await vaultManager?.destroy(); } }); - test('Concurrently creating vault with same name only creates 1 vault', async () => { - const vaultManager = await VaultManager.createVaultManager({ - vaultsPath, - keyManager: dummyKeyManager, - gestaltGraph: {} as GestaltGraph, - nodeConnectionManager: {} as NodeConnectionManager, - acl: {} as ACL, - notificationsManager: {} as NotificationsManager, - db, - logger: logger.getChild(VaultManager.name), - }); - - try { - await expect( - Promise.all([ - vaultManager.createVault(vaultName), - vaultManager.createVault(vaultName), - ]), - ).rejects.toThrow(vaultsErrors.ErrorVaultsVaultDefined); - // @ts-ignore: kidnapping the map - const vaultMap = vaultManager.vaultMap; - expect(vaultMap.size).toBe(1); - } finally { - await vaultManager?.stop(); - await vaultManager?.destroy(); - } - }); test('vaults persist', async () => { const vaultManager = await VaultManager.createVaultManager({ vaultsPath, diff --git a/tests/vaults/VaultOps.test.ts b/tests/vaults/VaultOps.test.ts index 1ff696243..beec79b60 100644 --- a/tests/vaults/VaultOps.test.ts +++ b/tests/vaults/VaultOps.test.ts @@ -40,7 +40,6 @@ describe('VaultOps', () => { baseEfs = await EncryptedFS.createEncryptedFS({ dbKey, dbPath, - // @ts-ignore - version of js-logger is incompatible (remove when DB updates to 5.*) logger, }); await baseEfs.start(); @@ -54,7 +53,6 @@ describe('VaultOps', () => { ); db = await DB.createDB({ dbPath: path.join(dataDir, 'db'), - // @ts-ignore - version of js-logger is incompatible (remove when DB updates to 5.*) logger, }); vaultsDbPath = ['vaults']; diff --git a/tests/vaults/utils.test.ts b/tests/vaults/utils.test.ts index 6db27f261..78c06d40d 100644 --- a/tests/vaults/utils.test.ts +++ b/tests/vaults/utils.test.ts @@ -32,7 +32,6 @@ describe('Vaults utils', () => { const efs = await EncryptedFS.createEncryptedFS({ dbKey: key, dbPath: dataDir, - // @ts-ignore - version of js-logger is incompatible (remove when DB updates to 5.*) logger, }); await efs.promises.mkdir(path.join('dir', 'dir2', 'dir3'), {