From 699028baa393ac6bcb3d53002361cb60a9d10fb3 Mon Sep 17 00:00:00 2001 From: Brian Botha Date: Tue, 9 Aug 2022 12:32:20 +1000 Subject: [PATCH 01/14] build: bringing in `fast-check`, `jest-extended` and updating `@matrixai/db` --- package-lock.json | 440 ++++++++++++++-------------------------------- package.json | 6 +- 2 files changed, 139 insertions(+), 307 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8a6203956..e22deffaa 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.1", "@matrixai/errors": "^1.1.3", "@matrixai/id": "^3.3.3", "@matrixai/logger": "^3.0.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.1", + "resolved": "https://registry.npmjs.org/@matrixai/db/-/db-5.0.1.tgz", + "integrity": "sha512-5M+2+QPRzQd1LUgdCq0j6I3z9mvXQFxJ+FoW40q7NwQMm5gTJjlmJ6pEsWIYcS32xaVWpKJdfLcGoSMndiZ9DA==", + "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", @@ -4906,6 +4732,26 @@ "util-callbackify": "^1.0.0" } }, + "node_modules/encryptedfs/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==", + "dependencies": { + "@matrixai/async-init": "^1.7.3", + "@matrixai/errors": "^1.1.1", + "@matrixai/logger": "^2.1.1", + "@matrixai/resources": "^1.1.3", + "@matrixai/workers": "^1.3.3", + "@types/abstract-leveldown": "^7.2.0", + "level": "7.0.1", + "threads": "^1.6.5" + } + }, + "node_modules/encryptedfs/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/encryptedfs/node_modules/node-forge": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/node-forge/-/node-forge-1.3.1.tgz", @@ -5739,6 +5585,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 +5811,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", @@ -7487,6 +7335,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", @@ -10206,6 +10070,16 @@ "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", @@ -13799,25 +13673,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.1", + "resolved": "https://registry.npmjs.org/@matrixai/db/-/db-5.0.1.tgz", + "integrity": "sha512-5M+2+QPRzQd1LUgdCq0j6I3z9mvXQFxJ+FoW40q7NwQMm5gTJjlmJ6pEsWIYcS32xaVWpKJdfLcGoSMndiZ9DA==", "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 +13850,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 +13864,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", @@ -15497,6 +15287,28 @@ "util-callbackify": "^1.0.0" }, "dependencies": { + "@matrixai/db": { + "version": "4.0.5", + "resolved": "https://registry.npmjs.org/@matrixai/db/-/db-4.0.5.tgz", + "integrity": "sha512-X3gBcyPxC+bTEfi1J1Y49n1bglvg7HjM8MKNH5s+OUEswqKSZgeg1uWfXqvUqq72yjBtgRi4Ghmy4MdrIB1oMw==", + "requires": { + "@matrixai/async-init": "^1.7.3", + "@matrixai/errors": "^1.1.1", + "@matrixai/logger": "^2.1.1", + "@matrixai/resources": "^1.1.3", + "@matrixai/workers": "^1.3.3", + "@types/abstract-leveldown": "^7.2.0", + "level": "7.0.1", + "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==" + } + } + }, "node-forge": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/node-forge/-/node-forge-1.3.1.tgz", @@ -16122,6 +15934,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 +16135,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", @@ -17396,6 +17210,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", @@ -19432,6 +19256,12 @@ "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", diff --git a/package.json b/package.json index 69858be06..dced350dc 100644 --- a/package.json +++ b/package.json @@ -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.1", "@matrixai/errors": "^1.1.3", "@matrixai/id": "^3.3.3", "@matrixai/logger": "^3.0.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", From efa15d8c558903a19b7f4c13b5f72d9016077616 Mon Sep 17 00:00:00 2001 From: Brian Botha Date: Tue, 9 Aug 2022 12:33:22 +1000 Subject: [PATCH 02/14] build: adding `benches` to linting targets --- benches/gitgc.ts | 14 +++++++------- package.json | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/benches/gitgc.ts b/benches/gitgc.ts index 983065cf1..a7b752014 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 = []; @@ -21,7 +21,7 @@ async function main () { for (const i of map) { // NOOP } - } + }; }), b.add('obj', async () => { obj = {}; @@ -38,20 +38,20 @@ async function main () { }; }), 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 diff --git a/package.json b/package.json index dced350dc..f41812727 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", From 731c7610a2aaf2064a516dd7ac77d7c6f1e0b0e5 Mon Sep 17 00:00:00 2001 From: Brian Botha Date: Tue, 9 Aug 2022 12:36:36 +1000 Subject: [PATCH 03/14] fix: moving `PromiseDeconstructed` to types --- src/nodes/NodeManager.ts | 2 +- src/nodes/Queue.ts | 2 +- src/types.ts | 10 ++++++++++ src/utils/utils.ts | 14 ++++++-------- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/nodes/NodeManager.ts b/src/nodes/NodeManager.ts index 7245ab5c4..0609d45a7 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'; 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/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, From 98f3013101e2c760c680f15124568de829f54ed1 Mon Sep 17 00:00:00 2001 From: Brian Botha Date: Tue, 9 Aug 2022 12:37:31 +1000 Subject: [PATCH 04/14] fix: updating `setupFilesAfterEnv` Not sure what these changes do. I don't know what to name it. --- .eslintrc | 3 ++- jest.config.js | 5 ++++- tests/global.d.ts | 3 +++ 3 files changed, 9 insertions(+), 2 deletions(-) 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/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/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 From 2103713715359d920d7c1c977ae6b12f0af05d55 Mon Sep 17 00:00:00 2001 From: Brian Botha Date: Tue, 9 Aug 2022 12:37:59 +1000 Subject: [PATCH 05/14] ci: disabling some check tests --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7333f6b57..3c870f582 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -77,7 +77,7 @@ check:nix-dry: - if: $CI_COMMIT_BRANCH && $CI_COMMIT_BRANCH != 'master' && $CI_COMMIT_TITLE !~ /^[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/ when: manual -check:test-generate: +.check:test-generate: stage: check needs: [] script: @@ -96,7 +96,7 @@ check:test-generate: - if: $CI_COMMIT_BRANCH && $CI_COMMIT_BRANCH !~ /^(?:master|staging)$/ && $CI_COMMIT_TITLE !~ /^[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/ when: manual -check:test: +.check:test: stage: check needs: - check:test-generate From 16c0279640aef1bdc3347bba9eb7f9db0b58dd01 Mon Sep 17 00:00:00 2001 From: Brian Botha Date: Tue, 9 Aug 2022 12:07:49 +1000 Subject: [PATCH 06/14] fix: vaults locking and transactional locking --- benches/gitgc.ts | 6 +- src/acl/ACL.ts | 44 ++--- src/agent/service/nodesChainDataGet.ts | 2 +- .../service/nodesClosestLocalNodesGet.ts | 5 +- src/agent/service/notificationsSend.ts | 6 +- src/client/service/agentLockAll.ts | 4 +- .../service/gestaltsActionsGetByIdentity.ts | 2 +- .../service/gestaltsActionsGetByNode.ts | 2 +- .../service/gestaltsActionsSetByIdentity.ts | 2 +- .../service/gestaltsActionsSetByNode.ts | 2 +- .../service/gestaltsActionsUnsetByIdentity.ts | 2 +- .../service/gestaltsActionsUnsetByNode.ts | 2 +- .../service/gestaltsGestaltGetByIdentity.ts | 2 +- .../service/gestaltsGestaltGetByNode.ts | 2 +- src/client/service/gestaltsGestaltList.ts | 2 +- src/client/service/identitiesClaim.ts | 2 +- src/client/service/identitiesTokenDelete.ts | 2 +- src/client/service/identitiesTokenGet.ts | 2 +- src/client/service/identitiesTokenPut.ts | 2 +- src/client/service/nodesAdd.ts | 2 +- src/client/service/notificationsClear.ts | 2 +- src/client/service/notificationsRead.ts | 2 +- src/client/service/vaultsCreate.ts | 2 +- src/client/service/vaultsList.ts | 2 +- src/discovery/Discovery.ts | 77 ++++----- src/gestalts/GestaltGraph.ts | 48 ++---- src/identities/IdentitiesManager.ts | 16 +- src/nodes/NodeGraph.ts | 74 ++++----- src/nodes/NodeManager.ts | 4 +- src/notifications/NotificationsManager.ts | 104 +++++------- src/sessions/SessionManager.ts | 17 +- src/sigchain/Sigchain.ts | 77 ++++----- src/vaults/VaultInternal.ts | 47 +++--- src/vaults/VaultManager.ts | 157 +++++++++--------- tests/acl/ACL.test.ts | 2 +- tests/nodes/utils.test.ts | 4 +- tests/sigchain/Sigchain.test.ts | 14 +- tests/vaults/VaultManager.test.ts | 45 ++--- 38 files changed, 332 insertions(+), 457 deletions(-) diff --git a/benches/gitgc.ts b/benches/gitgc.ts index a7b752014..5026436fb 100644 --- a/benches/gitgc.ts +++ b/benches/gitgc.ts @@ -18,7 +18,7 @@ async function main() { for (let i = 0; i < 1000; i++) { map.delete(i); } - for (const i of map) { + for (const _i of map) { // NOOP } }; @@ -32,7 +32,7 @@ async function main() { for (let i = 0; i < 1000; i++) { delete obj[i]; } - for (const i in obj) { + for (const _i in obj) { // NOOP } }; @@ -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/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/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..738aaeacb 100644 --- a/src/nodes/NodeGraph.ts +++ b/src/nodes/NodeGraph.ts @@ -157,9 +157,7 @@ class NodeGraph { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.db.withTransactionF(async (tran) => - this.getNode(nodeId, tran), - ); + return this.db.withTransactionF((tran) => this.getNode(nodeId, tran)); } const [bucketIndex] = this.bucketIndex(nodeId); @@ -192,11 +190,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 +215,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 +264,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 +284,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 +320,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 +334,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 +352,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 +371,7 @@ class NodeGraph { bucket.push([nodeId, nodeData]); } } finally { - await bucketDbIterator.end(); + await bucketDbIterator.destroy(); // FIXME: should this be `.destroy` now? } } return bucket; @@ -410,11 +406,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 +448,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 +484,7 @@ class NodeGraph { yield [bucketIndex, bucket]; } } finally { - await bucketsDbIterator.end(); + await bucketsDbIterator.destroy(); // FIXME: destroy? } } } @@ -499,7 +495,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 +520,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 +547,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 +594,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 +625,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 +672,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 +709,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 +725,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 0609d45a7..aa0740ee5 100644 --- a/src/nodes/NodeManager.ts +++ b/src/nodes/NodeManager.ts @@ -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/notifications/NotificationsManager.ts b/src/notifications/NotificationsManager.ts index ac91a0cf1..8e6e0f541 100644 --- a/src/notifications/NotificationsManager.ts +++ b/src/notifications/NotificationsManager.ts @@ -1,4 +1,4 @@ -import type { DB, DBTransaction, KeyPath, LevelPath } from '@matrixai/db'; +import type { DB, DBTransaction, LevelPath } from '@matrixai/db'; import type { NotificationId, Notification, @@ -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) @@ -123,35 +120,30 @@ 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) => { + await tran.lock( + [...this.notificationsDbPath, MESSAGE_COUNT_KEY].toString(), + ); + 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 +153,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}`); } /** @@ -217,10 +195,12 @@ class NotificationsManager { ): 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(messageCountPath.toString()); const nodePerms = await this.acl.getNodePerm( nodesUtils.decodeNodeId(notification.senderId)!, ); @@ -230,7 +210,7 @@ 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.getForUpdate(messageCountPath); if (numMessages === undefined) { numMessages = 0; await tran.put(messageCountPath, 0); @@ -268,7 +248,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 +288,7 @@ class NotificationsManager { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.withTransactionF(async (tran) => + return this.db.withTransactionF((tran) => this.findGestaltInvite(fromNode, tran), ); } @@ -330,12 +310,12 @@ class NotificationsManager { 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(messageCountPath.toString()); const notificationIds = await this.getNotificationIds('all', tran); - const numMessages = await tran.get(messageCountPath); + const numMessages = await tran.getForUpdate(messageCountPath); if (numMessages !== undefined) { for (const id of notificationIds) { await this.removeNotification(id, tran); @@ -368,8 +348,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 +371,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,7 +399,11 @@ class NotificationsManager { messageId: NotificationId, tran: DBTransaction, ): Promise { - const numMessages = await tran.get([ + await tran.lock([ + ...this.notificationsDbPath, + MESSAGE_COUNT_KEY, + ].toString()); + const numMessages = await tran.getForUpdate([ ...this.notificationsDbPath, MESSAGE_COUNT_KEY, ]); diff --git a/src/sessions/SessionManager.ts b/src/sessions/SessionManager.ts index 4a9f1607b..160080f34 100644 --- a/src/sessions/SessionManager.ts +++ b/src/sessions/SessionManager.ts @@ -98,17 +98,10 @@ 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)); + return this.db.withTransactionF((tran) => this.resetKey(tran)); } const key = await this.generateKey(this.keyBits); await tran.put([...this.sessionsDbPath, 'key'], key, true); @@ -125,9 +118,7 @@ class SessionManager { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.withTransactionF(async (tran) => - this.createToken(expiry, tran), - ); + return this.db.withTransactionF((tran) => this.createToken(expiry, tran)); } const payload = { iss: nodesUtils.encodeNodeId(this.keyManager.getNodeId()), @@ -144,9 +135,7 @@ class SessionManager { tran?: DBTransaction, ): Promise { if (tran == null) { - return this.withTransactionF(async (tran) => - this.verifyToken(token, tran), - ); + return this.db.withTransactionF((tran) => this.verifyToken(token, tran)); } const key = await tran.get([...this.sessionsDbPath, 'key'], true); const result = await sessionsUtils.verifySessionToken(token, key!); diff --git a/src/sigchain/Sigchain.ts b/src/sigchain/Sigchain.ts index 06631cdd5..1cba40446 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,12 +170,10 @@ 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(claimIdPath.toString(), sequenceNumberPath.toString()); const prevSequenceNumber = await this.getSequenceNumber(tran); const newSequenceNumber = prevSequenceNumber + 1; const claim = await this.createClaim({ @@ -225,12 +207,12 @@ 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(claimIdPath.toString(), sequenceNumberPath.toString()); const decodedClaim = claimsUtils.decodeClaim(claim); const prevSequenceNumber = await this.getSequenceNumber(tran); const expectedSequenceNumber = prevSequenceNumber + 1; @@ -259,10 +241,12 @@ class Sigchain { this.sequenceNumberKey, ]; if (tran == null) { - return this.withTransactionF(sequenceNumberPath, async (tran) => + return this.db.withTransactionF((tran) => this.createIntermediaryClaim(claimData, tran), ); } + + await tran.lock(sequenceNumberPath.toString()); const claim = await this.createClaim({ hPrev: await this.getHashPrevious(tran), seq: (await this.getSequenceNumber(tran)) + 1, @@ -283,12 +267,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 +296,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 +364,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 +381,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 +400,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/vaults/VaultInternal.ts b/src/vaults/VaultInternal.ts index 0061d9185..0b5d95e7f 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].toString(), + ); + + // 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].toString(), + ); 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..e26b593b2 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(); @@ -268,48 +267,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].toString()); + 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 +320,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 +360,20 @@ 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 () => { + const vaultMeta = await this.getVaultMeta(vaultId, tran); + if (vaultMeta == null) return; + const vaultName = vaultMeta.vaultName; + await tran.lock([...this.vaultsNamesDbPath, vaultName].toString()); + 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 +381,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 +395,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) { @@ -419,13 +416,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,12 +441,13 @@ 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].toString()); this.logger.info(`Renaming Vault ${vaultsUtils.encodeVaultId(vaultId)}`); // Checking if new name exists if (await this.getVaultId(newVaultName, tran)) { @@ -462,6 +459,7 @@ class VaultManager { throw new vaultsErrors.ErrorVaultsVaultUndefined(); } const oldVaultName = vaultMetadata.vaultName; + await tran.lock([...this.vaultsNamesDbPath, oldVaultName].toString()); // Updating metadata with new name; const vaultDbPath = [ ...this.vaultsDbPath, @@ -469,14 +467,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 +485,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].toString()); + const vaultIdBuffer = await tran.get( + [...this.vaultsNamesDbPath, vaultName], + true, + ); + if (vaultIdBuffer == null) return; + return IdInternal.fromBuffer(vaultIdBuffer); } /** @@ -513,7 +508,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 +525,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 +550,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 +584,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 +607,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,7 +693,7 @@ 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 }), ); } @@ -768,7 +763,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 +909,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 +949,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..f5f994b9e 100644 --- a/tests/acl/ACL.test.ts +++ b/tests/acl/ACL.test.ts @@ -407,7 +407,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/nodes/utils.test.ts b/tests/nodes/utils.test.ts index 64d7c7afe..c2c1dfee8 100644 --- a/tests/nodes/utils.test.ts +++ b/tests/nodes/utils.test.ts @@ -122,7 +122,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 +162,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/sigchain/Sigchain.test.ts b/tests/sigchain/Sigchain.test.ts index 45da1b665..01bb35d62 100644 --- a/tests/sigchain/Sigchain.test.ts +++ b/tests/sigchain/Sigchain.test.ts @@ -96,7 +96,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 +237,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 +259,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 +283,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/VaultManager.test.ts b/tests/vaults/VaultManager.test.ts index 82d8ad532..b5864a44b 100644 --- a/tests/vaults/VaultManager.test.ts +++ b/tests/vaults/VaultManager.test.ts @@ -317,7 +317,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 +329,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(); @@ -1760,33 +1762,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, From 48a6ea405cf43b856054f290a986a3fa476ee50d Mon Sep 17 00:00:00 2001 From: Brian Botha Date: Thu, 11 Aug 2022 15:53:21 +1000 Subject: [PATCH 07/14] fix: cleaning up unnecessary locks This includes using `getForUpdate` for any counter updates. --- src/notifications/NotificationsManager.ts | 44 +++++++++++------------ src/sigchain/Sigchain.ts | 26 ++++++++------ 2 files changed, 36 insertions(+), 34 deletions(-) diff --git a/src/notifications/NotificationsManager.ts b/src/notifications/NotificationsManager.ts index 8e6e0f541..d45f2b1f9 100644 --- a/src/notifications/NotificationsManager.ts +++ b/src/notifications/NotificationsManager.ts @@ -1,4 +1,4 @@ -import type { DB, DBTransaction, LevelPath } from '@matrixai/db'; +import type { DB, DBTransaction, KeyPath, LevelPath } from '@matrixai/db'; import type { NotificationId, Notification, @@ -88,6 +88,10 @@ class NotificationsManager { this.constructor.name, 'messages', ]; + protected notificationsMessageCounterDbPath: KeyPath = [ + ...this.notificationsDbPath, + MESSAGE_COUNT_KEY, + ]; protected notificationIdGenerator: NotificationIdGenerator; @@ -121,9 +125,6 @@ class NotificationsManager { fresh = false, }: { fresh?: boolean } = {}): Promise { await this.db.withTransactionF(async (tran) => { - await tran.lock( - [...this.notificationsDbPath, MESSAGE_COUNT_KEY].toString(), - ); this.logger.info(`Starting ${this.constructor.name}`); if (fresh) { await tran.clear(this.notificationsDbPath); @@ -193,14 +194,13 @@ class NotificationsManager { notification: Notification, tran?: DBTransaction, ): Promise { - const messageCountPath = [...this.notificationsDbPath, MESSAGE_COUNT_KEY]; if (tran == null) { return this.db.withTransactionF(async (tran) => this.receiveNotification(notification, tran), ); } - await tran.lock(messageCountPath.toString()); + await tran.lock(this.notificationsMessageCounterDbPath.toString()); const nodePerms = await this.acl.getNodePerm( nodesUtils.decodeNodeId(notification.senderId)!, ); @@ -210,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.getForUpdate(messageCountPath); + let numMessages = await tran.getForUpdate( + 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 @@ -228,7 +230,7 @@ class NotificationsManager { ); // Number of messages += 1 const newNumMessages = numMessages + 1; - await tran.put(messageCountPath, newNumMessages); + await tran.put(this.notificationsMessageCounterDbPath, newNumMessages); } } @@ -308,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.db.withTransactionF((tran) => this.clearNotifications(tran)); } - await tran.lock(messageCountPath.toString()); + await tran.lock(this.notificationsMessageCounterDbPath.toString()); const notificationIds = await this.getNotificationIds('all', tran); - const numMessages = await tran.getForUpdate(messageCountPath); + const numMessages = await tran.getForUpdate( + this.notificationsMessageCounterDbPath, + ); if (numMessages !== undefined) { for (const id of notificationIds) { await this.removeNotification(id, tran); @@ -399,14 +402,10 @@ class NotificationsManager { messageId: NotificationId, tran: DBTransaction, ): Promise { - await tran.lock([ - ...this.notificationsDbPath, - MESSAGE_COUNT_KEY, - ].toString()); - const numMessages = await tran.getForUpdate([ - ...this.notificationsDbPath, - MESSAGE_COUNT_KEY, - ]); + await tran.lock(this.notificationsMessageCounterDbPath.toString()); + const numMessages = await tran.getForUpdate( + this.notificationsMessageCounterDbPath, + ); if (numMessages === undefined) { throw new notificationsErrors.ErrorNotificationsDb(); } @@ -415,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/sigchain/Sigchain.ts b/src/sigchain/Sigchain.ts index 1cba40446..b59aa4a8e 100644 --- a/src/sigchain/Sigchain.ts +++ b/src/sigchain/Sigchain.ts @@ -173,8 +173,14 @@ class Sigchain { return this.db.withTransactionF((tran) => this.addClaim(claimData, tran)); } - await tran.lock(claimIdPath.toString(), sequenceNumberPath.toString()); - const prevSequenceNumber = await this.getSequenceNumber(tran); + await tran.lock(sequenceNumberPath.toString()); + const prevSequenceNumber = await tran.getForUpdate([ + ...this.sigchainMetadataDbPath, + this.sequenceNumberKey, + ]); + if (prevSequenceNumber === undefined) { + throw new sigchainErrors.ErrorSigchainSequenceNumUndefined(); + } const newSequenceNumber = prevSequenceNumber + 1; const claim = await this.createClaim({ hPrev: await this.getHashPrevious(tran), @@ -212,9 +218,15 @@ class Sigchain { ); } - await tran.lock(claimIdPath.toString(), sequenceNumberPath.toString()); + await tran.lock(sequenceNumberPath.toString()); 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) { @@ -236,17 +248,11 @@ class Sigchain { claimData: ClaimData, tran?: DBTransaction, ): Promise { - const sequenceNumberPath = [ - ...this.sigchainMetadataDbPath, - this.sequenceNumberKey, - ]; if (tran == null) { return this.db.withTransactionF((tran) => this.createIntermediaryClaim(claimData, tran), ); } - - await tran.lock(sequenceNumberPath.toString()); const claim = await this.createClaim({ hPrev: await this.getHashPrevious(tran), seq: (await this.getSequenceNumber(tran)) + 1, From 8ea2e159ea6ea55272f0fff80c92c0d8155f0022 Mon Sep 17 00:00:00 2001 From: Brian Botha Date: Thu, 11 Aug 2022 16:52:03 +1000 Subject: [PATCH 08/14] fix: some get/set operations just use DB if transaction not given. --- src/nodes/NodeGraph.ts | 8 +++----- src/sessions/SessionManager.ts | 21 +++++++-------------- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/src/nodes/NodeGraph.ts b/src/nodes/NodeGraph.ts index 738aaeacb..fda9caba1 100644 --- a/src/nodes/NodeGraph.ts +++ b/src/nodes/NodeGraph.ts @@ -156,9 +156,7 @@ class NodeGraph { nodeId: NodeId, tran?: DBTransaction, ): Promise { - if (tran == null) { - return this.db.withTransactionF((tran) => this.getNode(nodeId, tran)); - } + const tranOrDb = tran ?? this.db; const [bucketIndex] = this.bucketIndex(nodeId); const bucketDomain = [ @@ -166,7 +164,7 @@ class NodeGraph { nodesUtils.bucketKey(bucketIndex), nodesUtils.bucketDbKey(nodeId), ]; - return await tran.get(bucketDomain); + return await tranOrDb.get(bucketDomain); } /** @@ -371,7 +369,7 @@ class NodeGraph { bucket.push([nodeId, nodeData]); } } finally { - await bucketDbIterator.destroy(); // FIXME: should this be `.destroy` now? + await bucketDbIterator.destroy(); } } return bucket; diff --git a/src/sessions/SessionManager.ts b/src/sessions/SessionManager.ts index 160080f34..7a5cc7b73 100644 --- a/src/sessions/SessionManager.ts +++ b/src/sessions/SessionManager.ts @@ -100,11 +100,9 @@ class SessionManager { @ready(new sessionsErrors.ErrorSessionManagerNotRunning()) public async resetKey(tran?: DBTransaction): Promise { - if (tran == null) { - return this.db.withTransactionF((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); } /** @@ -117,16 +115,13 @@ class SessionManager { expiry: number | undefined = this.expiry, tran?: DBTransaction, ): Promise { - if (tran == null) { - return this.db.withTransactionF((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()) @@ -134,10 +129,8 @@ class SessionManager { token: SessionToken, tran?: DBTransaction, ): Promise { - if (tran == null) { - return this.db.withTransactionF((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; } From 0f4d5c26189e458583729c125e945c3c630b502b Mon Sep 17 00:00:00 2001 From: Brian Botha Date: Mon, 15 Aug 2022 15:14:00 +1000 Subject: [PATCH 09/14] ci: reenabling check tests --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3c870f582..7333f6b57 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -77,7 +77,7 @@ check:nix-dry: - if: $CI_COMMIT_BRANCH && $CI_COMMIT_BRANCH != 'master' && $CI_COMMIT_TITLE !~ /^[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/ when: manual -.check:test-generate: +check:test-generate: stage: check needs: [] script: @@ -96,7 +96,7 @@ check:nix-dry: - if: $CI_COMMIT_BRANCH && $CI_COMMIT_BRANCH !~ /^(?:master|staging)$/ && $CI_COMMIT_TITLE !~ /^[0-9]+\.[0-9]+\.[0-9]+(?:-.*[0-9]+)?$/ when: manual -.check:test: +check:test: stage: check needs: - check:test-generate From 39ceada1a56241f23b4334f36727e7b5195476a8 Mon Sep 17 00:00:00 2001 From: Brian Botha Date: Mon, 22 Aug 2022 16:46:30 +1000 Subject: [PATCH 10/14] build: updating `@matrixai/db` to `^5.0.3` and `encryptedfs` to `^3.5.6` --- package-lock.json | 493 +++------------------------------------------- package.json | 4 +- 2 files changed, 27 insertions(+), 470 deletions(-) diff --git a/package-lock.json b/package-lock.json index e22deffaa..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": "^5.0.1", + "@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", @@ -2643,9 +2643,9 @@ } }, "node_modules/@matrixai/db": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/@matrixai/db/-/db-5.0.1.tgz", - "integrity": "sha512-5M+2+QPRzQd1LUgdCq0j6I3z9mvXQFxJ+FoW40q7NwQMm5gTJjlmJ6pEsWIYcS32xaVWpKJdfLcGoSMndiZ9DA==", + "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.8.1", @@ -2901,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", @@ -3317,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", @@ -3818,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", @@ -4022,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", @@ -4101,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", @@ -4522,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", @@ -4697,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", @@ -4732,26 +4655,6 @@ "util-callbackify": "^1.0.0" } }, - "node_modules/encryptedfs/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==", - "dependencies": { - "@matrixai/async-init": "^1.7.3", - "@matrixai/errors": "^1.1.1", - "@matrixai/logger": "^2.1.1", - "@matrixai/resources": "^1.1.3", - "@matrixai/workers": "^1.3.3", - "@types/abstract-leveldown": "^7.2.0", - "level": "7.0.1", - "threads": "^1.6.5" - } - }, - "node_modules/encryptedfs/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/encryptedfs/node_modules/node-forge": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/node-forge/-/node-forge-1.3.1.tgz", @@ -6210,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", @@ -6382,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", @@ -8532,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", @@ -8838,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", @@ -10084,6 +9840,7 @@ "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", @@ -10418,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", @@ -13673,9 +13408,9 @@ } }, "@matrixai/db": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/@matrixai/db/-/db-5.0.1.tgz", - "integrity": "sha512-5M+2+QPRzQd1LUgdCq0j6I3z9mvXQFxJ+FoW40q7NwQMm5gTJjlmJ6pEsWIYcS32xaVWpKJdfLcGoSMndiZ9DA==", + "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.8.1", "@matrixai/async-locks": "^3.1.1", @@ -13888,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", @@ -14207,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", @@ -14602,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", @@ -14751,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", @@ -14797,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", @@ -15134,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", @@ -15255,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", @@ -15287,28 +14971,6 @@ "util-callbackify": "^1.0.0" }, "dependencies": { - "@matrixai/db": { - "version": "4.0.5", - "resolved": "https://registry.npmjs.org/@matrixai/db/-/db-4.0.5.tgz", - "integrity": "sha512-X3gBcyPxC+bTEfi1J1Y49n1bglvg7HjM8MKNH5s+OUEswqKSZgeg1uWfXqvUqq72yjBtgRi4Ghmy4MdrIB1oMw==", - "requires": { - "@matrixai/async-init": "^1.7.3", - "@matrixai/errors": "^1.1.1", - "@matrixai/logger": "^2.1.1", - "@matrixai/resources": "^1.1.3", - "@matrixai/workers": "^1.3.3", - "@types/abstract-leveldown": "^7.2.0", - "level": "7.0.1", - "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==" - } - } - }, "node-forge": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/node-forge/-/node-forge-1.3.1.tgz", @@ -16429,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", @@ -16545,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", @@ -18104,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", @@ -18344,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", @@ -19265,7 +18829,8 @@ "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", @@ -19503,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 f41812727..29403fed3 100644 --- a/package.json +++ b/package.json @@ -79,7 +79,7 @@ "@grpc/grpc-js": "1.6.7", "@matrixai/async-init": "^1.8.2", "@matrixai/async-locks": "^3.1.2", - "@matrixai/db": "^5.0.1", + "@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", From 4fe94922010ffaf57f1c67977cba4a4c7e7090a7 Mon Sep 17 00:00:00 2001 From: Brian Botha Date: Mon, 22 Aug 2022 16:48:42 +1000 Subject: [PATCH 11/14] fix: removed `ts-ignore`s for logger version mismatch --- src/PolykeyAgent.ts | 1 - src/bootstrap/utils.ts | 1 - src/vaults/VaultManager.ts | 1 - tests/acl/ACL.test.ts | 1 - tests/agent/GRPCClientAgent.test.ts | 1 - tests/agent/service/notificationsSend.test.ts | 1 - tests/client/service/agentLockAll.test.ts | 1 - .../gestaltsActionsSetUnsetGetByIdentity.test.ts | 1 - .../service/gestaltsActionsSetUnsetGetByNode.test.ts | 1 - .../service/gestaltsDiscoveryByIdentity.test.ts | 1 - tests/client/service/gestaltsDiscoveryByNode.test.ts | 1 - .../service/gestaltsGestaltGetByIdentity.test.ts | 1 - tests/client/service/gestaltsGestaltGetByNode.test.ts | 1 - tests/client/service/gestaltsGestaltList.test.ts | 1 - .../service/gestaltsGestaltTrustByIdentity.test.ts | 1 - .../client/service/gestaltsGestaltTrustByNode.test.ts | 1 - tests/client/service/identitiesAuthenticate.test.ts | 1 - .../client/service/identitiesAuthenticatedGet.test.ts | 1 - tests/client/service/identitiesClaim.test.ts | 1 - .../client/service/identitiesInfoConnectedGet.test.ts | 1 - tests/client/service/identitiesInfoGet.test.ts | 1 - tests/client/service/identitiesProvidersList.test.ts | 1 - .../service/identitiesTokenPutDeleteGet.test.ts | 1 - tests/client/service/nodesAdd.test.ts | 1 - tests/client/service/nodesClaim.test.ts | 1 - tests/client/service/nodesFind.test.ts | 1 - tests/client/service/nodesPing.test.ts | 1 - tests/client/service/notificationsClear.test.ts | 1 - tests/client/service/notificationsRead.test.ts | 1 - tests/client/service/notificationsSend.test.ts | 1 - tests/client/service/vaultsClone.test.ts | 1 - tests/client/service/vaultsCreateDeleteList.test.ts | 1 - tests/client/service/vaultsLog.test.ts | 1 - .../service/vaultsPermissionSetUnsetGet.test.ts | 1 - tests/client/service/vaultsPull.test.ts | 1 - tests/client/service/vaultsRename.test.ts | 1 - tests/client/service/vaultsSecretsEdit.test.ts | 1 - tests/client/service/vaultsSecretsMkdir.test.ts | 1 - .../client/service/vaultsSecretsNewDeleteGet.test.ts | 1 - tests/client/service/vaultsSecretsNewDirList.test.ts | 1 - tests/client/service/vaultsSecretsRename.test.ts | 1 - tests/client/service/vaultsSecretsStat.test.ts | 1 - tests/client/service/vaultsVersion.test.ts | 1 - tests/discovery/Discovery.test.ts | 1 - tests/gestalts/GestaltGraph.test.ts | 1 - tests/git/utils.test.ts | 1 - tests/grpc/GRPCClient.test.ts | 1 - tests/grpc/GRPCServer.test.ts | 1 - tests/identities/IdentitiesManager.test.ts | 1 - tests/keys/KeyManager.test.ts | 2 -- tests/nodes/NodeConnection.test.ts | 1 - tests/nodes/NodeConnectionManager.general.test.ts | 1 - tests/nodes/NodeConnectionManager.lifecycle.test.ts | 1 - tests/nodes/NodeConnectionManager.seednodes.test.ts | 1 - tests/nodes/NodeConnectionManager.termination.test.ts | 1 - tests/nodes/NodeConnectionManager.timeout.test.ts | 1 - tests/nodes/NodeGraph.test.ts | 1 - tests/nodes/NodeManager.test.ts | 1 - tests/nodes/utils.test.ts | 1 - tests/notifications/NotificationsManager.test.ts | 1 - tests/sessions/SessionManager.test.ts | 1 - tests/sigchain/Sigchain.test.ts | 1 - tests/vaults/VaultInternal.test.ts | 2 -- tests/vaults/VaultManager.test.ts | 11 +++++------ tests/vaults/VaultOps.test.ts | 2 -- tests/vaults/utils.test.ts | 1 - 66 files changed, 5 insertions(+), 74 deletions(-) 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/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/vaults/VaultManager.ts b/src/vaults/VaultManager.ts index e26b593b2..06e404a27 100644 --- a/src/vaults/VaultManager.ts +++ b/src/vaults/VaultManager.ts @@ -180,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) { diff --git a/tests/acl/ACL.test.ts b/tests/acl/ACL.test.ts index f5f994b9e..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, 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/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 c2c1dfee8..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, 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 01bb35d62..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, 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 b5864a44b..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('Concurrently creating vault with same name only creates 1 vault', async () => { + test('concurrently creating vault with same name only creates 1 vault', async () => { const vaultManager = await VaultManager.createVaultManager({ vaultsPath, keyManager: dummyKeyManager, @@ -429,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, @@ -472,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; @@ -1466,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', @@ -1741,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, 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'), { From 1b109d95e48c7e075bfa115d38753cd205f1d729 Mon Sep 17 00:00:00 2001 From: Brian Botha Date: Mon, 22 Aug 2022 18:46:43 +1000 Subject: [PATCH 12/14] fix: using `tran.getForUpdate` for vaults renaming and sigchain claim creation --- src/notifications/NotificationsManager.ts | 6 +++--- src/vaults/VaultManager.ts | 12 ++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/notifications/NotificationsManager.ts b/src/notifications/NotificationsManager.ts index d45f2b1f9..9560ecf0d 100644 --- a/src/notifications/NotificationsManager.ts +++ b/src/notifications/NotificationsManager.ts @@ -210,7 +210,7 @@ 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.getForUpdate( + let numMessages = await tran.get( this.notificationsMessageCounterDbPath, ); if (numMessages === undefined) { @@ -316,7 +316,7 @@ class NotificationsManager { await tran.lock(this.notificationsMessageCounterDbPath.toString()); const notificationIds = await this.getNotificationIds('all', tran); - const numMessages = await tran.getForUpdate( + const numMessages = await tran.get( this.notificationsMessageCounterDbPath, ); if (numMessages !== undefined) { @@ -403,7 +403,7 @@ class NotificationsManager { tran: DBTransaction, ): Promise { await tran.lock(this.notificationsMessageCounterDbPath.toString()); - const numMessages = await tran.getForUpdate( + const numMessages = await tran.get( this.notificationsMessageCounterDbPath, ); if (numMessages === undefined) { diff --git a/src/vaults/VaultManager.ts b/src/vaults/VaultManager.ts index 06e404a27..062bedf81 100644 --- a/src/vaults/VaultManager.ts +++ b/src/vaults/VaultManager.ts @@ -365,6 +365,12 @@ class VaultManager { } await this.vaultLocks.withF([vaultId, RWLockWriter, 'write'], async () => { + // 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; @@ -452,6 +458,12 @@ class VaultManager { 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) { From 1bc948bf17eb112a3ceea67ee0724a08a756ce5f Mon Sep 17 00:00:00 2001 From: Brian Botha Date: Mon, 22 Aug 2022 20:12:40 +1000 Subject: [PATCH 13/14] fix: added transaction lock on vaultId for vault renaming --- src/vaults/VaultManager.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/vaults/VaultManager.ts b/src/vaults/VaultManager.ts index 062bedf81..c16325973 100644 --- a/src/vaults/VaultManager.ts +++ b/src/vaults/VaultManager.ts @@ -365,6 +365,7 @@ class VaultManager { } await this.vaultLocks.withF([vaultId, RWLockWriter, 'write'], async () => { + await tran.lock(vaultId); // Ensure protection from write skew await tran.getForUpdate([ ...this.vaultsDbPath, @@ -374,7 +375,6 @@ class VaultManager { const vaultMeta = await this.getVaultMeta(vaultId, tran); if (vaultMeta == null) return; const vaultName = vaultMeta.vaultName; - await tran.lock([...this.vaultsNamesDbPath, vaultName].toString()); this.logger.info( `Destroying Vault ${vaultsUtils.encodeVaultId(vaultId)}`, ); @@ -408,6 +408,7 @@ class VaultManager { } const vaultIdString = vaultId.toString() as VaultIdString; await this.vaultLocks.withF([vaultId, RWLockWriter, 'write'], async () => { + await tran.lock(vaultId); const vault = await this.getVault(vaultId, tran); await vault.stop(); this.vaultMap.delete(vaultIdString); @@ -452,7 +453,10 @@ class VaultManager { } await this.vaultLocks.withF([vaultId, RWLockWriter, 'write'], async () => { - await tran.lock([...this.vaultsNamesDbPath, newVaultName].toString()); + await tran.lock( + [...this.vaultsNamesDbPath, newVaultName].toString(), + vaultId, + ); this.logger.info(`Renaming Vault ${vaultsUtils.encodeVaultId(vaultId)}`); // Checking if new name exists if (await this.getVaultId(newVaultName, tran)) { @@ -470,7 +474,6 @@ class VaultManager { throw new vaultsErrors.ErrorVaultsVaultUndefined(); } const oldVaultName = vaultMetadata.vaultName; - await tran.lock([...this.vaultsNamesDbPath, oldVaultName].toString()); // Updating metadata with new name; const vaultDbPath = [ ...this.vaultsDbPath, @@ -711,6 +714,7 @@ class VaultManager { if ((await this.getVaultName(vaultId, tran)) == null) return; await this.vaultLocks.withF([vaultId, RWLockWriter, 'write'], async () => { + await tran.lock(vaultId); const vault = await this.getVault(vaultId, tran); await vault.pullVault({ nodeConnectionManager: this.nodeConnectionManager, From c75a40285c549ae96ab5dc9b9db96a94cf472117 Mon Sep 17 00:00:00 2001 From: Brian Botha Date: Tue, 23 Aug 2022 11:50:47 +1000 Subject: [PATCH 14/14] fix: `VaultManager` `vaultId` locking path and using `join('')` on paths --- src/notifications/NotificationsManager.ts | 6 +++--- src/sigchain/Sigchain.ts | 4 ++-- src/vaults/VaultInternal.ts | 4 ++-- src/vaults/VaultManager.ts | 14 +++++++------- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/notifications/NotificationsManager.ts b/src/notifications/NotificationsManager.ts index 9560ecf0d..19d4d8ab9 100644 --- a/src/notifications/NotificationsManager.ts +++ b/src/notifications/NotificationsManager.ts @@ -200,7 +200,7 @@ class NotificationsManager { ); } - await tran.lock(this.notificationsMessageCounterDbPath.toString()); + await tran.lock(this.notificationsMessageCounterDbPath.join('')); const nodePerms = await this.acl.getNodePerm( nodesUtils.decodeNodeId(notification.senderId)!, ); @@ -314,7 +314,7 @@ class NotificationsManager { return this.db.withTransactionF((tran) => this.clearNotifications(tran)); } - await tran.lock(this.notificationsMessageCounterDbPath.toString()); + await tran.lock(this.notificationsMessageCounterDbPath.join('')); const notificationIds = await this.getNotificationIds('all', tran); const numMessages = await tran.get( this.notificationsMessageCounterDbPath, @@ -402,7 +402,7 @@ class NotificationsManager { messageId: NotificationId, tran: DBTransaction, ): Promise { - await tran.lock(this.notificationsMessageCounterDbPath.toString()); + await tran.lock(this.notificationsMessageCounterDbPath.join('')); const numMessages = await tran.get( this.notificationsMessageCounterDbPath, ); diff --git a/src/sigchain/Sigchain.ts b/src/sigchain/Sigchain.ts index b59aa4a8e..5276f7163 100644 --- a/src/sigchain/Sigchain.ts +++ b/src/sigchain/Sigchain.ts @@ -173,7 +173,7 @@ class Sigchain { return this.db.withTransactionF((tran) => this.addClaim(claimData, tran)); } - await tran.lock(sequenceNumberPath.toString()); + await tran.lock(sequenceNumberPath.join('')); const prevSequenceNumber = await tran.getForUpdate([ ...this.sigchainMetadataDbPath, this.sequenceNumberKey, @@ -218,7 +218,7 @@ class Sigchain { ); } - await tran.lock(sequenceNumberPath.toString()); + await tran.lock(sequenceNumberPath.join('')); const decodedClaim = claimsUtils.decodeClaim(claim); const prevSequenceNumber = await tran.getForUpdate([ ...this.sigchainMetadataDbPath, diff --git a/src/vaults/VaultInternal.ts b/src/vaults/VaultInternal.ts index 0b5d95e7f..69e40043f 100644 --- a/src/vaults/VaultInternal.ts +++ b/src/vaults/VaultInternal.ts @@ -447,7 +447,7 @@ class VaultInternal { return withF([this.lock.write()], async () => { await tran.lock( - [...this.vaultMetadataDbPath, VaultInternal.dirtyKey].toString(), + [...this.vaultMetadataDbPath, VaultInternal.dirtyKey].join(''), ); // This should really be an internal property @@ -505,7 +505,7 @@ class VaultInternal { throw new vaultsErrors.ErrorVaultRemoteDefined(); } await tran.lock( - [...vaultMetadataDbPath, VaultInternal.dirtyKey].toString(), + [...vaultMetadataDbPath, VaultInternal.dirtyKey].join(''), ); await tran.put([...vaultMetadataDbPath, VaultInternal.dirtyKey], true); diff --git a/src/vaults/VaultManager.ts b/src/vaults/VaultManager.ts index c16325973..2c1f8f582 100644 --- a/src/vaults/VaultManager.ts +++ b/src/vaults/VaultManager.ts @@ -272,7 +272,7 @@ class VaultManager { } // Adding vault to name map const vaultId = await this.generateVaultId(); - await tran.lock([...this.vaultsNamesDbPath, vaultName].toString()); + await tran.lock([...this.vaultsNamesDbPath, vaultName].join('')); const vaultIdBuffer = await tran.get( [...this.vaultsNamesDbPath, vaultName], true, @@ -365,7 +365,7 @@ class VaultManager { } await this.vaultLocks.withF([vaultId, RWLockWriter, 'write'], async () => { - await tran.lock(vaultId); + await tran.lock([...this.vaultsDbPath, vaultId].join('')); // Ensure protection from write skew await tran.getForUpdate([ ...this.vaultsDbPath, @@ -408,7 +408,7 @@ class VaultManager { } const vaultIdString = vaultId.toString() as VaultIdString; await this.vaultLocks.withF([vaultId, RWLockWriter, 'write'], async () => { - await tran.lock(vaultId); + await tran.lock([...this.vaultsDbPath, vaultId].join('')); const vault = await this.getVault(vaultId, tran); await vault.stop(); this.vaultMap.delete(vaultIdString); @@ -454,8 +454,8 @@ class VaultManager { await this.vaultLocks.withF([vaultId, RWLockWriter, 'write'], async () => { await tran.lock( - [...this.vaultsNamesDbPath, newVaultName].toString(), - vaultId, + [...this.vaultsNamesDbPath, newVaultName].join(''), + [...this.vaultsDbPath, vaultId].join(''), ); this.logger.info(`Renaming Vault ${vaultsUtils.encodeVaultId(vaultId)}`); // Checking if new name exists @@ -504,7 +504,7 @@ class VaultManager { ); } - await tran.lock([...this.vaultsNamesDbPath, vaultName].toString()); + await tran.lock([...this.vaultsNamesDbPath, vaultName].join('')); const vaultIdBuffer = await tran.get( [...this.vaultsNamesDbPath, vaultName], true, @@ -714,7 +714,7 @@ class VaultManager { if ((await this.getVaultName(vaultId, tran)) == null) return; await this.vaultLocks.withF([vaultId, RWLockWriter, 'write'], async () => { - await tran.lock(vaultId); + await tran.lock([...this.vaultsDbPath, vaultId].join('')); const vault = await this.getVault(vaultId, tran); await vault.pullVault({ nodeConnectionManager: this.nodeConnectionManager,