From 094895ec72afe048dccdf4938b0a1bee3bfacac2 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Fri, 16 Feb 2024 20:25:28 +0200 Subject: [PATCH 01/49] server-ts: Enable ts-node instead of nodemon --- package-lock.json | 1003 ++++++++++++++++++--------------------------- package.json | 10 +- 2 files changed, 400 insertions(+), 613 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0e4925fc9..47be0133d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -88,6 +88,7 @@ "trilium": "src/www.js" }, "devDependencies": { + "@types/node": "^20.11.19", "cross-env": "7.0.3", "electron": "25.9.8", "electron-builder": "24.6.4", @@ -109,6 +110,9 @@ "nodemon": "3.0.1", "prettier": "3.1.0", "rcedit": "4.0.1", + "ts-node": "^3.3.0", + "tslib": "^2.6.2", + "typescript": "^5.3.3", "webpack": "5.89.0", "webpack-cli": "5.1.4" }, @@ -1224,19 +1228,11 @@ "node": ">=14" } }, - "node_modules/@pkgr/utils": { - "version": "2.4.2", - "resolved": "https://registry.npmjs.org/@pkgr/utils/-/utils-2.4.2.tgz", - "integrity": "sha512-POgTXhjrTfbTV63DiFXav4lBHiICLKKwDeaKn9Nphwj7WH6m0hMMCaJkMyRWjgtPFyRKRVoMXXjczsTQRDEhYw==", + "node_modules/@pkgr/core": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/@pkgr/core/-/core-0.1.1.tgz", + "integrity": "sha512-cq8o4cWH0ibXh9VGi5P20Tu9XF/0fFXl9EUinr9QfTM7a7p0oTA4iJRCQWppXR1Pg8dSM0UCItCkPwsk9qWWYA==", "dev": true, - "dependencies": { - "cross-spawn": "^7.0.3", - "fast-glob": "^3.3.0", - "is-glob": "^4.0.3", - "open": "^9.1.0", - "picocolors": "^1.0.0", - "tslib": "^2.6.0" - }, "engines": { "node": "^12.20.0 || ^14.18.0 || >=16.0.0" }, @@ -1244,36 +1240,6 @@ "url": "https://opencollective.com/unts" } }, - "node_modules/@pkgr/utils/node_modules/define-lazy-prop": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/define-lazy-prop/-/define-lazy-prop-3.0.0.tgz", - "integrity": "sha512-N+MeXYoqr3pOgn8xfyRPREN7gHakLYjhsHhWGT3fWAiL4IkAt0iDw14QiiEm2bE30c5XX5q0FtAA3CK5f9/BUg==", - "dev": true, - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/@pkgr/utils/node_modules/open": { - "version": "9.1.0", - "resolved": "https://registry.npmjs.org/open/-/open-9.1.0.tgz", - "integrity": "sha512-OS+QTnw1/4vrf+9hh1jc1jnYjzSG4ttTBB8UxOwAnInG3Uo4ssetzC1ihqaIHjLJnA5GGlRl6QlZXOTQhRBUvg==", - "dev": true, - "dependencies": { - "default-browser": "^4.0.0", - "define-lazy-prop": "^3.0.0", - "is-inside-container": "^1.0.0", - "is-wsl": "^2.2.0" - }, - "engines": { - "node": ">=14.16" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/@sindresorhus/is": { "version": "4.6.0", "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-4.6.0.tgz", @@ -1463,9 +1429,12 @@ "integrity": "sha512-xPSg0jm4mqgEkNhowKgZFBNtwoEwF6gJ4Dhww+GFpm3IgtNseHQZ5IqdNwnquZEoANxyDAKDRAdVo4Z72VvD/g==" }, "node_modules/@types/node": { - "version": "18.16.18", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.16.18.tgz", - "integrity": "sha512-/aNaQZD0+iSBAGnvvN2Cx92HqE5sZCPZtx2TsK+4nvV23fFe09jVDvpArXr2j9DnYlzuU9WuoykDDc6wqvpNcw==" + "version": "20.11.19", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.11.19.tgz", + "integrity": "sha512-7xMnVEcZFu0DikYjWOlRq7NTPETrm7teqUT2WkQjrTIkEgUyyGdWsj/Zg8bEJt5TNklzbPD1X3fqfsHw3SpapQ==", + "dependencies": { + "undici-types": "~5.26.4" + } }, "node_modules/@types/plist": { "version": "3.0.5", @@ -2316,6 +2285,15 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/arrify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/arrify/-/arrify-1.0.1.tgz", + "integrity": "sha512-3CYzex9M9FGQjCGMGyi6/31c8GJbgb0qGyrx5HWxPd0aCwh4cB2YjMb2Xf9UuoogrMrlO9cTqnB5rI5GHZTcUA==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/asar": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/asar/-/asar-3.1.0.tgz", @@ -2563,15 +2541,6 @@ "url": "https://github.com/Pomax/bezierjs/blob/master/FUNDING.md" } }, - "node_modules/big-integer": { - "version": "1.6.51", - "resolved": "https://registry.npmjs.org/big-integer/-/big-integer-1.6.51.tgz", - "integrity": "sha512-GPEid2Y9QU1Exl1rpO9B2IPJGHPSupF5GnVIP0blYvNOMer2bTvSWs1jGOUg04hTmu67nmLsQ9TBo1puaotBHg==", - "dev": true, - "engines": { - "node": ">=0.6" - } - }, "node_modules/binary-extensions": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz", @@ -2746,18 +2715,6 @@ "object-assign": "^4.1.1" } }, - "node_modules/bplist-parser": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/bplist-parser/-/bplist-parser-0.2.0.tgz", - "integrity": "sha512-z0M+byMThzQmD9NILRniCUXYsYpjwnlO8N5uCFaCqIOpqRsJCrQL9NK3JsD67CN5a08nF5oIL2bD6loTdHOuKw==", - "dev": true, - "dependencies": { - "big-integer": "^1.6.44" - }, - "engines": { - "node": ">= 5.10.0" - } - }, "node_modules/brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", @@ -2949,21 +2906,6 @@ "node": ">= 10.0.0" } }, - "node_modules/bundle-name": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/bundle-name/-/bundle-name-3.0.0.tgz", - "integrity": "sha512-PKA4BeSvBpQKQ8iPOGCSiell+N8P+Tf1DlwqmYhpe2gAhKPHn8EYOxVT+ShuGmhg8lN8XiSlS80yiExKXrURlw==", - "dev": true, - "dependencies": { - "run-applescript": "^5.0.0" - }, - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/busboy": { "version": "1.6.0", "resolved": "https://registry.npmjs.org/busboy/-/busboy-1.6.0.tgz", @@ -4598,40 +4540,6 @@ "node": ">=0.10.0" } }, - "node_modules/default-browser": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/default-browser/-/default-browser-4.0.0.tgz", - "integrity": "sha512-wX5pXO1+BrhMkSbROFsyxUm0i/cJEScyNhA4PPxc41ICuv05ZZB/MX28s8aZx6xjmatvebIapF6hLEKEcpneUA==", - "dev": true, - "dependencies": { - "bundle-name": "^3.0.0", - "default-browser-id": "^3.0.0", - "execa": "^7.1.1", - "titleize": "^3.0.0" - }, - "engines": { - "node": ">=14.16" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/default-browser-id": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/default-browser-id/-/default-browser-id-3.0.0.tgz", - "integrity": "sha512-OZ1y3y0SqSICtE8DE4S8YOE9UZOJ8wO16fKWVP5J1Qz42kV9jcnMVFrEE/noXb/ss3Q4pZIH79kxofzyNNtUNA==", - "dev": true, - "dependencies": { - "bplist-parser": "^0.2.0", - "untildify": "^4.0.0" - }, - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/defaults": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/defaults/-/defaults-1.0.3.tgz", @@ -5539,6 +5447,14 @@ "node": ">=8.0.0" } }, + "node_modules/electron/node_modules/@types/node": { + "version": "18.19.17", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.19.17.tgz", + "integrity": "sha512-SzyGKgwPzuWp2SHhlpXKzCX0pIOfcI4V2eF37nNBJOhwlegQ83omtVQ1XxZpDE06V/d6AQvfQdPfnw0tRC//Ng==", + "dependencies": { + "undici-types": "~5.26.4" + } + }, "node_modules/elkjs": { "version": "0.8.2", "resolved": "https://registry.npmjs.org/elkjs/-/elkjs-0.8.2.tgz", @@ -6291,68 +6207,6 @@ "node": ">=0.8.x" } }, - "node_modules/execa": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/execa/-/execa-7.2.0.tgz", - "integrity": "sha512-UduyVP7TLB5IcAQl+OzLyLcS/l32W/GLg+AhHJ+ow40FOk2U3SAllPwR44v4vmdFwIWqpdwxxpQbF1n5ta9seA==", - "dev": true, - "dependencies": { - "cross-spawn": "^7.0.3", - "get-stream": "^6.0.1", - "human-signals": "^4.3.0", - "is-stream": "^3.0.0", - "merge-stream": "^2.0.0", - "npm-run-path": "^5.1.0", - "onetime": "^6.0.0", - "signal-exit": "^3.0.7", - "strip-final-newline": "^3.0.0" - }, - "engines": { - "node": "^14.18.0 || ^16.14.0 || >=18.0.0" - }, - "funding": { - "url": "https://github.com/sindresorhus/execa?sponsor=1" - } - }, - "node_modules/execa/node_modules/get-stream": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-6.0.1.tgz", - "integrity": "sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==", - "dev": true, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/execa/node_modules/mimic-fn": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-4.0.0.tgz", - "integrity": "sha512-vqiC06CuhBTUdZH+RYl8sFrL096vA45Ok5ISO6sE/Mr1jRbGH4Csnhi8f3wKVl7x8mO4Au7Ir9D3Oyv1VYMFJw==", - "dev": true, - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/execa/node_modules/onetime": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/onetime/-/onetime-6.0.0.tgz", - "integrity": "sha512-1FlR+gjXK7X+AsAHso35MnyN5KqGwJRi/31ft6x0M194ht7S+rWAvd7PHss9xSKMzE0asv1pyIHaJYq+BbacAQ==", - "dev": true, - "dependencies": { - "mimic-fn": "^4.0.0" - }, - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/exif-parser": { "version": "0.1.12", "resolved": "https://registry.npmjs.org/exif-parser/-/exif-parser-0.1.12.tgz", @@ -6625,22 +6479,6 @@ "resolved": "https://registry.npmjs.org/fast-fifo/-/fast-fifo-1.3.2.tgz", "integrity": "sha512-/d9sfos4yxzpwkDkuN7k2SqFKtYNmCTzgfEpz82x34IM9/zc8KGxQoXg1liNC/izpRM/MBdt44Nmx41ZWqk+FQ==" }, - "node_modules/fast-glob": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.0.tgz", - "integrity": "sha512-ChDuvbOypPuNjO8yIDf36x7BlZX1smcUMTTcyoIjycexOxd6DFsKsg21qVBzEmr3G7fUKIRy2/psii+CIUt7FA==", - "dev": true, - "dependencies": { - "@nodelib/fs.stat": "^2.0.2", - "@nodelib/fs.walk": "^1.2.3", - "glob-parent": "^5.1.2", - "merge2": "^1.3.0", - "micromatch": "^4.0.4" - }, - "engines": { - "node": ">=8.6.0" - } - }, "node_modules/fast-json-stable-stringify": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz", @@ -7623,6 +7461,18 @@ "resolved": "https://registry.npmjs.org/hoist-non-react-statics/-/hoist-non-react-statics-2.5.5.tgz", "integrity": "sha512-rqcy4pJo55FTTLWt+bU8ukscqHeE/e9KWvsOW2b/a3afxQZhwkQdT1rPPCJ0rYXdj4vNcasY8zHTH+jF/qStxw==" }, + "node_modules/homedir-polyfill": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/homedir-polyfill/-/homedir-polyfill-1.0.3.tgz", + "integrity": "sha512-eSmmWE5bZTK2Nou4g0AI3zZ9rswp7GRKoKXS1BLUkvPviOqs4YTN1djQIqrXy9k5gEtdLPy86JjRwsNM9tnDcA==", + "dev": true, + "dependencies": { + "parse-passwd": "^1.0.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/hosted-git-info": { "version": "2.8.9", "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.9.tgz", @@ -7800,15 +7650,6 @@ "node": ">= 14" } }, - "node_modules/human-signals": { - "version": "4.3.1", - "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-4.3.1.tgz", - "integrity": "sha512-nZXjEF2nbo7lIw3mgYjItAfgQXog3OjJogSbKa2CQIIvSGWcKgeJnQlNXip6NglNzYH45nSRiEVimMvYL8DDqQ==", - "dev": true, - "engines": { - "node": ">=14.18.0" - } - }, "node_modules/humanize-ms": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/humanize-ms/-/humanize-ms-1.2.1.tgz", @@ -8243,39 +8084,6 @@ "node": ">=0.10.0" } }, - "node_modules/is-inside-container": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/is-inside-container/-/is-inside-container-1.0.0.tgz", - "integrity": "sha512-KIYLCCJghfHZxqjYBE7rEy0OBuTd5xCHS7tHVgvCLkx7StIoaxwNW3hCALgEUjFfeRk+MG/Qxmp/vtETEF3tRA==", - "dev": true, - "dependencies": { - "is-docker": "^3.0.0" - }, - "bin": { - "is-inside-container": "cli.js" - }, - "engines": { - "node": ">=14.16" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/is-inside-container/node_modules/is-docker": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/is-docker/-/is-docker-3.0.0.tgz", - "integrity": "sha512-eljcgEDlEns/7AXFosB5K/2nCM4P7FQPkGc/DWLy5rmFEWvZayGrik1d9/QIY5nJ4f9YsVvBkA6kJpHn9rISdQ==", - "dev": true, - "bin": { - "is-docker": "cli.js" - }, - "engines": { - "node": "^12.20.0 || ^14.13.1 || >=16.0.0" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/is-interactive": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-interactive/-/is-interactive-1.0.0.tgz", @@ -9719,6 +9527,12 @@ "node": ">= 6" } }, + "node_modules/make-error": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", + "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==", + "dev": true + }, "node_modules/make-fetch-happen": { "version": "10.2.0", "resolved": "https://registry.npmjs.org/make-fetch-happen/-/make-fetch-happen-10.2.0.tgz", @@ -9912,15 +9726,6 @@ "integrity": "sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==", "dev": true }, - "node_modules/merge2": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz", - "integrity": "sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==", - "dev": true, - "engines": { - "node": ">= 8" - } - }, "node_modules/mermaid": { "version": "10.6.1", "resolved": "https://registry.npmjs.org/mermaid/-/mermaid-10.6.1.tgz", @@ -11431,6 +11236,15 @@ "node": ">=0.10.0" } }, + "node_modules/parse-passwd": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/parse-passwd/-/parse-passwd-1.0.0.tgz", + "integrity": "sha512-1Y1A//QUXEZK7YKz+rD9WydcE1+EuPr6ZBgKecAB8tmoW6UFv0NREVJe1p+jRxtThkcbbKkfwIbWJe/IeE6m2Q==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/parse-srcset": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/parse-srcset/-/parse-srcset-1.0.2.tgz", @@ -12531,98 +12345,6 @@ "resolved": "https://registry.npmjs.org/rrweb-cssom/-/rrweb-cssom-0.6.0.tgz", "integrity": "sha512-APM0Gt1KoXBz0iIkkdB/kfvGOwC4UuJFeG/c+yV7wSc7q96cG/kJ0HiYCnzivD9SB53cLV1MlHFNfOuPaadYSw==" }, - "node_modules/run-applescript": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/run-applescript/-/run-applescript-5.0.0.tgz", - "integrity": "sha512-XcT5rBksx1QdIhlFOCtgZkB99ZEouFZ1E2Kc2LHqNW13U3/74YGdkQRmThTwxy4QIyookibDKYZOPqX//6BlAg==", - "dev": true, - "dependencies": { - "execa": "^5.0.0" - }, - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/run-applescript/node_modules/execa": { - "version": "5.1.1", - "resolved": "https://registry.npmjs.org/execa/-/execa-5.1.1.tgz", - "integrity": "sha512-8uSpZZocAZRBAPIEINJj3Lo9HyGitllczc27Eh5YYojjMFMn8yHMDMaUHE2Jqfq05D/wucwI4JGURyXt1vchyg==", - "dev": true, - "dependencies": { - "cross-spawn": "^7.0.3", - "get-stream": "^6.0.0", - "human-signals": "^2.1.0", - "is-stream": "^2.0.0", - "merge-stream": "^2.0.0", - "npm-run-path": "^4.0.1", - "onetime": "^5.1.2", - "signal-exit": "^3.0.3", - "strip-final-newline": "^2.0.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sindresorhus/execa?sponsor=1" - } - }, - "node_modules/run-applescript/node_modules/get-stream": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-6.0.1.tgz", - "integrity": "sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==", - "dev": true, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/run-applescript/node_modules/human-signals": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-2.1.0.tgz", - "integrity": "sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==", - "dev": true, - "engines": { - "node": ">=10.17.0" - } - }, - "node_modules/run-applescript/node_modules/is-stream": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.1.tgz", - "integrity": "sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==", - "dev": true, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/run-applescript/node_modules/npm-run-path": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-4.0.1.tgz", - "integrity": "sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==", - "dev": true, - "dependencies": { - "path-key": "^3.0.0" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/run-applescript/node_modules/strip-final-newline": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/strip-final-newline/-/strip-final-newline-2.0.0.tgz", - "integrity": "sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==", - "dev": true, - "engines": { - "node": ">=6" - } - }, "node_modules/run-parallel": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", @@ -13642,13 +13364,13 @@ "integrity": "sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw==" }, "node_modules/synckit": { - "version": "0.8.5", - "resolved": "https://registry.npmjs.org/synckit/-/synckit-0.8.5.tgz", - "integrity": "sha512-L1dapNV6vu2s/4Sputv8xGsCdAVlb5nRDMFU/E27D44l5U6cw1g0dGd45uLc+OXjNMmF4ntiMdCimzcjFKQI8Q==", + "version": "0.8.8", + "resolved": "https://registry.npmjs.org/synckit/-/synckit-0.8.8.tgz", + "integrity": "sha512-HwOKAP7Wc5aRGYdKH+dw0PRRpbO841v2DENBtjnR5HFWoiNByAl7vrx3p0G/rCyYXQsrxqtX48TImFtPcIHSpQ==", "dev": true, "dependencies": { - "@pkgr/utils": "^2.3.1", - "tslib": "^2.5.0" + "@pkgr/core": "^0.1.0", + "tslib": "^2.6.2" }, "engines": { "node": "^14.18.0 || >=16.0.0" @@ -13887,18 +13609,6 @@ "resolved": "https://registry.npmjs.org/tinycolor2/-/tinycolor2-1.6.0.tgz", "integrity": "sha512-XPaBkWQJdsf3pLKJV9p4qN/S+fm2Oj8AIPo1BTUhg5oxkvm9+SVEGFdhyOz7tTdUTfvxMiAs4sp6/eZO2Ew+pw==" }, - "node_modules/titleize": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/titleize/-/titleize-3.0.0.tgz", - "integrity": "sha512-KxVu8EYHDPBdUYdKZdKtU2aj2XfEx9AfjXxE/Aj0vT06w2icA09Vus1rh6eSu1y01akYg6BjIK/hxyLJINoMLQ==", - "dev": true, - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/tmp": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.1.tgz", @@ -14064,6 +13774,130 @@ "node": ">=6.10" } }, + "node_modules/ts-node": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-3.3.0.tgz", + "integrity": "sha512-S87fS5QGinpnvi6I1aW8PnEEwJbkQsr2o+9C3qdAkmaYQn33PKVkXowI2/wggr8FzAwKhvCaomB0EX60LW3/Fw==", + "dev": true, + "dependencies": { + "arrify": "^1.0.0", + "chalk": "^2.0.0", + "diff": "^3.1.0", + "make-error": "^1.1.1", + "minimist": "^1.2.0", + "mkdirp": "^0.5.1", + "source-map-support": "^0.4.0", + "tsconfig": "^6.0.0", + "v8flags": "^3.0.0", + "yn": "^2.0.0" + }, + "bin": { + "_ts-node": "dist/_bin.js", + "ts-node": "dist/bin.js" + }, + "engines": { + "node": ">=4.2.0" + } + }, + "node_modules/ts-node/node_modules/ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "dev": true, + "dependencies": { + "color-convert": "^1.9.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/ts-node/node_modules/chalk": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", + "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", + "dev": true, + "dependencies": { + "ansi-styles": "^3.2.1", + "escape-string-regexp": "^1.0.5", + "supports-color": "^5.3.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/ts-node/node_modules/color-convert": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", + "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", + "dev": true, + "dependencies": { + "color-name": "1.1.3" + } + }, + "node_modules/ts-node/node_modules/color-name": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", + "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==", + "dev": true + }, + "node_modules/ts-node/node_modules/diff": { + "version": "3.5.0", + "resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz", + "integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==", + "dev": true, + "engines": { + "node": ">=0.3.1" + } + }, + "node_modules/ts-node/node_modules/has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==", + "dev": true, + "engines": { + "node": ">=4" + } + }, + "node_modules/ts-node/node_modules/source-map": { + "version": "0.5.7", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", + "integrity": "sha512-LbrmJOMUSdEVxIKvdcJzQC+nQhe8FUZQTXQy6+I75skNgn3OoQ0DZA8YnFa7gp8tqtL3KPf1kmo0R5DoApeSGQ==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/ts-node/node_modules/source-map-support": { + "version": "0.4.18", + "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.4.18.tgz", + "integrity": "sha512-try0/JqxPLF9nOjvSta7tVondkP5dwgyLDjVoyMDlmjugT2lRZ1OfsrYTkCd2hkDnJTKRbO/Rl3orm8vlsUzbA==", + "dev": true, + "dependencies": { + "source-map": "^0.5.6" + } + }, + "node_modules/ts-node/node_modules/supports-color": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", + "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", + "dev": true, + "dependencies": { + "has-flag": "^3.0.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/tsconfig": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/tsconfig/-/tsconfig-6.0.0.tgz", + "integrity": "sha512-n3i8c4BOozElBHYMVkEyF9AudHRvvq6NTc6sVRVmLBQM2A02JKjLoICxRtKkoGu3gROOnRZ85KxiTAcmhWgR0w==", + "dev": true, + "dependencies": { + "strip-bom": "^3.0.0", + "strip-json-comments": "^2.0.0" + } + }, "node_modules/tsconfig-paths": { "version": "3.15.0", "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-3.15.0.tgz", @@ -14089,9 +13923,9 @@ } }, "node_modules/tslib": { - "version": "2.6.0", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.0.tgz", - "integrity": "sha512-7At1WUettjcSRHXCyYtTselblcHl9PJFFVKiCAy/bY97+BPZXSQ2wbq0P9s8tK2G7dFQfNnlJnPAiArVBVBsfA==" + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz", + "integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==" }, "node_modules/tsscmp": { "version": "1.0.6", @@ -14296,6 +14130,11 @@ "integrity": "sha512-ekY1NhRzq0B08g4bGuX4wd2jZx5GnKz6mKSqFL4nqBlfyMGiG10gDFhDTMEfYmDL6Jy0FUIZp7wiRB+0BP7J2g==", "dev": true }, + "node_modules/undici-types": { + "version": "5.26.5", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==" + }, "node_modules/unescape": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/unescape/-/unescape-1.0.1.tgz", @@ -14353,15 +14192,6 @@ "node": ">= 0.8" } }, - "node_modules/untildify": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/untildify/-/untildify-4.0.0.tgz", - "integrity": "sha512-KK8xQ1mkzZeg9inewmFVDNkg3l5LUhoq9kN6iWYB/CC9YMG8HA+c1Q8HwDe6dEX7kErrEVNVBO3fWsVq5iDgtw==", - "dev": true, - "engines": { - "node": ">=8" - } - }, "node_modules/unused-filename": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/unused-filename/-/unused-filename-2.1.0.tgz", @@ -14451,6 +14281,18 @@ "node": ">=8" } }, + "node_modules/v8flags": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/v8flags/-/v8flags-3.2.0.tgz", + "integrity": "sha512-mH8etigqMfiGWdeXpaaqGfs6BndypxusHHcv2qSHyZkGEznCd/qAXCWWRzeowtL54147cktFOC4P5y+kl8d8Jg==", + "dev": true, + "dependencies": { + "homedir-polyfill": "^1.0.1" + }, + "engines": { + "node": ">= 0.10" + } + }, "node_modules/validate-npm-package-license": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz", @@ -15057,6 +14899,15 @@ "fd-slicer": "~1.1.0" } }, + "node_modules/yn": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/yn/-/yn-2.0.0.tgz", + "integrity": "sha512-uTv8J/wiWTgUTg+9vLTi//leUl5vDQS6uii/emeTb2ssY7vl6QWf2fFbIIGjnhjvbdKlU0ed7QPgY1htTC86jQ==", + "dev": true, + "engines": { + "node": ">=4" + } + }, "node_modules/yocto-queue": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", @@ -15920,39 +15771,11 @@ "integrity": "sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==", "optional": true }, - "@pkgr/utils": { - "version": "2.4.2", - "resolved": "https://registry.npmjs.org/@pkgr/utils/-/utils-2.4.2.tgz", - "integrity": "sha512-POgTXhjrTfbTV63DiFXav4lBHiICLKKwDeaKn9Nphwj7WH6m0hMMCaJkMyRWjgtPFyRKRVoMXXjczsTQRDEhYw==", - "dev": true, - "requires": { - "cross-spawn": "^7.0.3", - "fast-glob": "^3.3.0", - "is-glob": "^4.0.3", - "open": "^9.1.0", - "picocolors": "^1.0.0", - "tslib": "^2.6.0" - }, - "dependencies": { - "define-lazy-prop": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/define-lazy-prop/-/define-lazy-prop-3.0.0.tgz", - "integrity": "sha512-N+MeXYoqr3pOgn8xfyRPREN7gHakLYjhsHhWGT3fWAiL4IkAt0iDw14QiiEm2bE30c5XX5q0FtAA3CK5f9/BUg==", - "dev": true - }, - "open": { - "version": "9.1.0", - "resolved": "https://registry.npmjs.org/open/-/open-9.1.0.tgz", - "integrity": "sha512-OS+QTnw1/4vrf+9hh1jc1jnYjzSG4ttTBB8UxOwAnInG3Uo4ssetzC1ihqaIHjLJnA5GGlRl6QlZXOTQhRBUvg==", - "dev": true, - "requires": { - "default-browser": "^4.0.0", - "define-lazy-prop": "^3.0.0", - "is-inside-container": "^1.0.0", - "is-wsl": "^2.2.0" - } - } - } + "@pkgr/core": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/@pkgr/core/-/core-0.1.1.tgz", + "integrity": "sha512-cq8o4cWH0ibXh9VGi5P20Tu9XF/0fFXl9EUinr9QfTM7a7p0oTA4iJRCQWppXR1Pg8dSM0UCItCkPwsk9qWWYA==", + "dev": true }, "@sindresorhus/is": { "version": "4.6.0", @@ -16131,9 +15954,12 @@ "integrity": "sha512-xPSg0jm4mqgEkNhowKgZFBNtwoEwF6gJ4Dhww+GFpm3IgtNseHQZ5IqdNwnquZEoANxyDAKDRAdVo4Z72VvD/g==" }, "@types/node": { - "version": "18.16.18", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.16.18.tgz", - "integrity": "sha512-/aNaQZD0+iSBAGnvvN2Cx92HqE5sZCPZtx2TsK+4nvV23fFe09jVDvpArXr2j9DnYlzuU9WuoykDDc6wqvpNcw==" + "version": "20.11.19", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.11.19.tgz", + "integrity": "sha512-7xMnVEcZFu0DikYjWOlRq7NTPETrm7teqUT2WkQjrTIkEgUyyGdWsj/Zg8bEJt5TNklzbPD1X3fqfsHw3SpapQ==", + "requires": { + "undici-types": "~5.26.4" + } }, "@types/plist": { "version": "3.0.5", @@ -16835,6 +16661,12 @@ "is-shared-array-buffer": "^1.0.2" } }, + "arrify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/arrify/-/arrify-1.0.1.tgz", + "integrity": "sha512-3CYzex9M9FGQjCGMGyi6/31c8GJbgb0qGyrx5HWxPd0aCwh4cB2YjMb2Xf9UuoogrMrlO9cTqnB5rI5GHZTcUA==", + "dev": true + }, "asar": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/asar/-/asar-3.1.0.tgz", @@ -17024,12 +16856,6 @@ "resolved": "https://registry.npmjs.org/bezier-js/-/bezier-js-6.1.4.tgz", "integrity": "sha512-PA0FW9ZpcHbojUCMu28z9Vg/fNkwTj5YhusSAjHHDfHDGLxJ6YUKrAN2vk1fP2MMOxVw4Oko16FMlRGVBGqLKg==" }, - "big-integer": { - "version": "1.6.51", - "resolved": "https://registry.npmjs.org/big-integer/-/big-integer-1.6.51.tgz", - "integrity": "sha512-GPEid2Y9QU1Exl1rpO9B2IPJGHPSupF5GnVIP0blYvNOMer2bTvSWs1jGOUg04hTmu67nmLsQ9TBo1puaotBHg==", - "dev": true - }, "binary-extensions": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz", @@ -17188,15 +17014,6 @@ } } }, - "bplist-parser": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/bplist-parser/-/bplist-parser-0.2.0.tgz", - "integrity": "sha512-z0M+byMThzQmD9NILRniCUXYsYpjwnlO8N5uCFaCqIOpqRsJCrQL9NK3JsD67CN5a08nF5oIL2bD6loTdHOuKw==", - "dev": true, - "requires": { - "big-integer": "^1.6.44" - } - }, "brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", @@ -17354,15 +17171,6 @@ "sax": "^1.2.4" } }, - "bundle-name": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/bundle-name/-/bundle-name-3.0.0.tgz", - "integrity": "sha512-PKA4BeSvBpQKQ8iPOGCSiell+N8P+Tf1DlwqmYhpe2gAhKPHn8EYOxVT+ShuGmhg8lN8XiSlS80yiExKXrURlw==", - "dev": true, - "requires": { - "run-applescript": "^5.0.0" - } - }, "busboy": { "version": "1.6.0", "resolved": "https://registry.npmjs.org/busboy/-/busboy-1.6.0.tgz", @@ -18584,28 +18392,6 @@ "resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-4.2.2.tgz", "integrity": "sha512-FJ3UgI4gIl+PHZm53knsuSFpE+nESMr7M4v9QcgB7S63Kj/6WqMiFQJpBBYz1Pt+66bZpP3Q7Lye0Oo9MPKEdg==" }, - "default-browser": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/default-browser/-/default-browser-4.0.0.tgz", - "integrity": "sha512-wX5pXO1+BrhMkSbROFsyxUm0i/cJEScyNhA4PPxc41ICuv05ZZB/MX28s8aZx6xjmatvebIapF6hLEKEcpneUA==", - "dev": true, - "requires": { - "bundle-name": "^3.0.0", - "default-browser-id": "^3.0.0", - "execa": "^7.1.1", - "titleize": "^3.0.0" - } - }, - "default-browser-id": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/default-browser-id/-/default-browser-id-3.0.0.tgz", - "integrity": "sha512-OZ1y3y0SqSICtE8DE4S8YOE9UZOJ8wO16fKWVP5J1Qz42kV9jcnMVFrEE/noXb/ss3Q4pZIH79kxofzyNNtUNA==", - "dev": true, - "requires": { - "bplist-parser": "^0.2.0", - "untildify": "^4.0.0" - } - }, "defaults": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/defaults/-/defaults-1.0.3.tgz", @@ -18917,6 +18703,16 @@ "@electron/get": "^2.0.0", "@types/node": "^18.11.18", "extract-zip": "^2.0.1" + }, + "dependencies": { + "@types/node": { + "version": "18.19.17", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.19.17.tgz", + "integrity": "sha512-SzyGKgwPzuWp2SHhlpXKzCX0pIOfcI4V2eF37nNBJOhwlegQ83omtVQ1XxZpDE06V/d6AQvfQdPfnw0tRC//Ng==", + "requires": { + "undici-types": "~5.26.4" + } + } } }, "electron-builder": { @@ -19860,46 +19656,6 @@ "integrity": "sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==", "dev": true }, - "execa": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/execa/-/execa-7.2.0.tgz", - "integrity": "sha512-UduyVP7TLB5IcAQl+OzLyLcS/l32W/GLg+AhHJ+ow40FOk2U3SAllPwR44v4vmdFwIWqpdwxxpQbF1n5ta9seA==", - "dev": true, - "requires": { - "cross-spawn": "^7.0.3", - "get-stream": "^6.0.1", - "human-signals": "^4.3.0", - "is-stream": "^3.0.0", - "merge-stream": "^2.0.0", - "npm-run-path": "^5.1.0", - "onetime": "^6.0.0", - "signal-exit": "^3.0.7", - "strip-final-newline": "^3.0.0" - }, - "dependencies": { - "get-stream": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-6.0.1.tgz", - "integrity": "sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==", - "dev": true - }, - "mimic-fn": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-4.0.0.tgz", - "integrity": "sha512-vqiC06CuhBTUdZH+RYl8sFrL096vA45Ok5ISO6sE/Mr1jRbGH4Csnhi8f3wKVl7x8mO4Au7Ir9D3Oyv1VYMFJw==", - "dev": true - }, - "onetime": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/onetime/-/onetime-6.0.0.tgz", - "integrity": "sha512-1FlR+gjXK7X+AsAHso35MnyN5KqGwJRi/31ft6x0M194ht7S+rWAvd7PHss9xSKMzE0asv1pyIHaJYq+BbacAQ==", - "dev": true, - "requires": { - "mimic-fn": "^4.0.0" - } - } - } - }, "exif-parser": { "version": "0.1.12", "resolved": "https://registry.npmjs.org/exif-parser/-/exif-parser-0.1.12.tgz", @@ -20097,19 +19853,6 @@ "resolved": "https://registry.npmjs.org/fast-fifo/-/fast-fifo-1.3.2.tgz", "integrity": "sha512-/d9sfos4yxzpwkDkuN7k2SqFKtYNmCTzgfEpz82x34IM9/zc8KGxQoXg1liNC/izpRM/MBdt44Nmx41ZWqk+FQ==" }, - "fast-glob": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.0.tgz", - "integrity": "sha512-ChDuvbOypPuNjO8yIDf36x7BlZX1smcUMTTcyoIjycexOxd6DFsKsg21qVBzEmr3G7fUKIRy2/psii+CIUt7FA==", - "dev": true, - "requires": { - "@nodelib/fs.stat": "^2.0.2", - "@nodelib/fs.walk": "^1.2.3", - "glob-parent": "^5.1.2", - "merge2": "^1.3.0", - "micromatch": "^4.0.4" - } - }, "fast-json-stable-stringify": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz", @@ -20859,6 +20602,15 @@ "resolved": "https://registry.npmjs.org/hoist-non-react-statics/-/hoist-non-react-statics-2.5.5.tgz", "integrity": "sha512-rqcy4pJo55FTTLWt+bU8ukscqHeE/e9KWvsOW2b/a3afxQZhwkQdT1rPPCJ0rYXdj4vNcasY8zHTH+jF/qStxw==" }, + "homedir-polyfill": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/homedir-polyfill/-/homedir-polyfill-1.0.3.tgz", + "integrity": "sha512-eSmmWE5bZTK2Nou4g0AI3zZ9rswp7GRKoKXS1BLUkvPviOqs4YTN1djQIqrXy9k5gEtdLPy86JjRwsNM9tnDcA==", + "dev": true, + "requires": { + "parse-passwd": "^1.0.0" + } + }, "hosted-git-info": { "version": "2.8.9", "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.9.tgz", @@ -20998,12 +20750,6 @@ } } }, - "human-signals": { - "version": "4.3.1", - "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-4.3.1.tgz", - "integrity": "sha512-nZXjEF2nbo7lIw3mgYjItAfgQXog3OjJogSbKa2CQIIvSGWcKgeJnQlNXip6NglNzYH45nSRiEVimMvYL8DDqQ==", - "dev": true - }, "humanize-ms": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/humanize-ms/-/humanize-ms-1.2.1.tgz", @@ -21310,23 +21056,6 @@ "is-extglob": "^2.1.1" } }, - "is-inside-container": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/is-inside-container/-/is-inside-container-1.0.0.tgz", - "integrity": "sha512-KIYLCCJghfHZxqjYBE7rEy0OBuTd5xCHS7tHVgvCLkx7StIoaxwNW3hCALgEUjFfeRk+MG/Qxmp/vtETEF3tRA==", - "dev": true, - "requires": { - "is-docker": "^3.0.0" - }, - "dependencies": { - "is-docker": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/is-docker/-/is-docker-3.0.0.tgz", - "integrity": "sha512-eljcgEDlEns/7AXFosB5K/2nCM4P7FQPkGc/DWLy5rmFEWvZayGrik1d9/QIY5nJ4f9YsVvBkA6kJpHn9rISdQ==", - "dev": true - } - } - }, "is-interactive": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-interactive/-/is-interactive-1.0.0.tgz", @@ -22363,6 +22092,12 @@ } } }, + "make-error": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", + "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==", + "dev": true + }, "make-fetch-happen": { "version": "10.2.0", "resolved": "https://registry.npmjs.org/make-fetch-happen/-/make-fetch-happen-10.2.0.tgz", @@ -22515,12 +22250,6 @@ "integrity": "sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==", "dev": true }, - "merge2": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz", - "integrity": "sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==", - "dev": true - }, "mermaid": { "version": "10.6.1", "resolved": "https://registry.npmjs.org/mermaid/-/mermaid-10.6.1.tgz", @@ -23564,6 +23293,12 @@ "error-ex": "^1.2.0" } }, + "parse-passwd": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/parse-passwd/-/parse-passwd-1.0.0.tgz", + "integrity": "sha512-1Y1A//QUXEZK7YKz+rD9WydcE1+EuPr6ZBgKecAB8tmoW6UFv0NREVJe1p+jRxtThkcbbKkfwIbWJe/IeE6m2Q==", + "dev": true + }, "parse-srcset": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/parse-srcset/-/parse-srcset-1.0.2.tgz", @@ -24405,67 +24140,6 @@ "resolved": "https://registry.npmjs.org/rrweb-cssom/-/rrweb-cssom-0.6.0.tgz", "integrity": "sha512-APM0Gt1KoXBz0iIkkdB/kfvGOwC4UuJFeG/c+yV7wSc7q96cG/kJ0HiYCnzivD9SB53cLV1MlHFNfOuPaadYSw==" }, - "run-applescript": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/run-applescript/-/run-applescript-5.0.0.tgz", - "integrity": "sha512-XcT5rBksx1QdIhlFOCtgZkB99ZEouFZ1E2Kc2LHqNW13U3/74YGdkQRmThTwxy4QIyookibDKYZOPqX//6BlAg==", - "dev": true, - "requires": { - "execa": "^5.0.0" - }, - "dependencies": { - "execa": { - "version": "5.1.1", - "resolved": "https://registry.npmjs.org/execa/-/execa-5.1.1.tgz", - "integrity": "sha512-8uSpZZocAZRBAPIEINJj3Lo9HyGitllczc27Eh5YYojjMFMn8yHMDMaUHE2Jqfq05D/wucwI4JGURyXt1vchyg==", - "dev": true, - "requires": { - "cross-spawn": "^7.0.3", - "get-stream": "^6.0.0", - "human-signals": "^2.1.0", - "is-stream": "^2.0.0", - "merge-stream": "^2.0.0", - "npm-run-path": "^4.0.1", - "onetime": "^5.1.2", - "signal-exit": "^3.0.3", - "strip-final-newline": "^2.0.0" - } - }, - "get-stream": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-6.0.1.tgz", - "integrity": "sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==", - "dev": true - }, - "human-signals": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-2.1.0.tgz", - "integrity": "sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==", - "dev": true - }, - "is-stream": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.1.tgz", - "integrity": "sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==", - "dev": true - }, - "npm-run-path": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-4.0.1.tgz", - "integrity": "sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==", - "dev": true, - "requires": { - "path-key": "^3.0.0" - } - }, - "strip-final-newline": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/strip-final-newline/-/strip-final-newline-2.0.0.tgz", - "integrity": "sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==", - "dev": true - } - } - }, "run-parallel": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", @@ -25235,13 +24909,13 @@ "integrity": "sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw==" }, "synckit": { - "version": "0.8.5", - "resolved": "https://registry.npmjs.org/synckit/-/synckit-0.8.5.tgz", - "integrity": "sha512-L1dapNV6vu2s/4Sputv8xGsCdAVlb5nRDMFU/E27D44l5U6cw1g0dGd45uLc+OXjNMmF4ntiMdCimzcjFKQI8Q==", + "version": "0.8.8", + "resolved": "https://registry.npmjs.org/synckit/-/synckit-0.8.8.tgz", + "integrity": "sha512-HwOKAP7Wc5aRGYdKH+dw0PRRpbO841v2DENBtjnR5HFWoiNByAl7vrx3p0G/rCyYXQsrxqtX48TImFtPcIHSpQ==", "dev": true, "requires": { - "@pkgr/utils": "^2.3.1", - "tslib": "^2.5.0" + "@pkgr/core": "^0.1.0", + "tslib": "^2.6.2" } }, "tapable": { @@ -25423,12 +25097,6 @@ "resolved": "https://registry.npmjs.org/tinycolor2/-/tinycolor2-1.6.0.tgz", "integrity": "sha512-XPaBkWQJdsf3pLKJV9p4qN/S+fm2Oj8AIPo1BTUhg5oxkvm9+SVEGFdhyOz7tTdUTfvxMiAs4sp6/eZO2Ew+pw==" }, - "titleize": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/titleize/-/titleize-3.0.0.tgz", - "integrity": "sha512-KxVu8EYHDPBdUYdKZdKtU2aj2XfEx9AfjXxE/Aj0vT06w2icA09Vus1rh6eSu1y01akYg6BjIK/hxyLJINoMLQ==", - "dev": true - }, "tmp": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.1.tgz", @@ -25551,6 +25219,107 @@ "resolved": "https://registry.npmjs.org/ts-dedent/-/ts-dedent-2.2.0.tgz", "integrity": "sha512-q5W7tVM71e2xjHZTlgfTDoPF/SmqKG5hddq9SzR49CH2hayqRKJtQ4mtRlSxKaJlR/+9rEM+mnBHf7I2/BQcpQ==" }, + "ts-node": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-3.3.0.tgz", + "integrity": "sha512-S87fS5QGinpnvi6I1aW8PnEEwJbkQsr2o+9C3qdAkmaYQn33PKVkXowI2/wggr8FzAwKhvCaomB0EX60LW3/Fw==", + "dev": true, + "requires": { + "arrify": "^1.0.0", + "chalk": "^2.0.0", + "diff": "^3.1.0", + "make-error": "^1.1.1", + "minimist": "^1.2.0", + "mkdirp": "^0.5.1", + "source-map-support": "^0.4.0", + "tsconfig": "^6.0.0", + "v8flags": "^3.0.0", + "yn": "^2.0.0" + }, + "dependencies": { + "ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "dev": true, + "requires": { + "color-convert": "^1.9.0" + } + }, + "chalk": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", + "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", + "dev": true, + "requires": { + "ansi-styles": "^3.2.1", + "escape-string-regexp": "^1.0.5", + "supports-color": "^5.3.0" + } + }, + "color-convert": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", + "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", + "dev": true, + "requires": { + "color-name": "1.1.3" + } + }, + "color-name": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", + "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==", + "dev": true + }, + "diff": { + "version": "3.5.0", + "resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz", + "integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==", + "dev": true + }, + "has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==", + "dev": true + }, + "source-map": { + "version": "0.5.7", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", + "integrity": "sha512-LbrmJOMUSdEVxIKvdcJzQC+nQhe8FUZQTXQy6+I75skNgn3OoQ0DZA8YnFa7gp8tqtL3KPf1kmo0R5DoApeSGQ==", + "dev": true + }, + "source-map-support": { + "version": "0.4.18", + "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.4.18.tgz", + "integrity": "sha512-try0/JqxPLF9nOjvSta7tVondkP5dwgyLDjVoyMDlmjugT2lRZ1OfsrYTkCd2hkDnJTKRbO/Rl3orm8vlsUzbA==", + "dev": true, + "requires": { + "source-map": "^0.5.6" + } + }, + "supports-color": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", + "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", + "dev": true, + "requires": { + "has-flag": "^3.0.0" + } + } + } + }, + "tsconfig": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/tsconfig/-/tsconfig-6.0.0.tgz", + "integrity": "sha512-n3i8c4BOozElBHYMVkEyF9AudHRvvq6NTc6sVRVmLBQM2A02JKjLoICxRtKkoGu3gROOnRZ85KxiTAcmhWgR0w==", + "dev": true, + "requires": { + "strip-bom": "^3.0.0", + "strip-json-comments": "^2.0.0" + } + }, "tsconfig-paths": { "version": "3.15.0", "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-3.15.0.tgz", @@ -25575,9 +25344,9 @@ } }, "tslib": { - "version": "2.6.0", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.0.tgz", - "integrity": "sha512-7At1WUettjcSRHXCyYtTselblcHl9PJFFVKiCAy/bY97+BPZXSQ2wbq0P9s8tK2G7dFQfNnlJnPAiArVBVBsfA==" + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz", + "integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==" }, "tsscmp": { "version": "1.0.6", @@ -25733,6 +25502,11 @@ "integrity": "sha512-ekY1NhRzq0B08g4bGuX4wd2jZx5GnKz6mKSqFL4nqBlfyMGiG10gDFhDTMEfYmDL6Jy0FUIZp7wiRB+0BP7J2g==", "dev": true }, + "undici-types": { + "version": "5.26.5", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==" + }, "unescape": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/unescape/-/unescape-1.0.1.tgz", @@ -25777,12 +25551,6 @@ "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", "integrity": "sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw=" }, - "untildify": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/untildify/-/untildify-4.0.0.tgz", - "integrity": "sha512-KK8xQ1mkzZeg9inewmFVDNkg3l5LUhoq9kN6iWYB/CC9YMG8HA+c1Q8HwDe6dEX7kErrEVNVBO3fWsVq5iDgtw==", - "dev": true - }, "unused-filename": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/unused-filename/-/unused-filename-2.1.0.tgz", @@ -25855,6 +25623,15 @@ "sade": "^1.7.3" } }, + "v8flags": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/v8flags/-/v8flags-3.2.0.tgz", + "integrity": "sha512-mH8etigqMfiGWdeXpaaqGfs6BndypxusHHcv2qSHyZkGEznCd/qAXCWWRzeowtL54147cktFOC4P5y+kl8d8Jg==", + "dev": true, + "requires": { + "homedir-polyfill": "^1.0.1" + } + }, "validate-npm-package-license": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz", @@ -26293,6 +26070,12 @@ "fd-slicer": "~1.1.0" } }, + "yn": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/yn/-/yn-2.0.0.tgz", + "integrity": "sha512-uTv8J/wiWTgUTg+9vLTi//leUl5vDQS6uii/emeTb2ssY7vl6QWf2fFbIIGjnhjvbdKlU0ed7QPgY1htTC86jQ==", + "dev": true + }, "yocto-queue": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", diff --git a/package.json b/package.json index 9d06fe839..58480422e 100644 --- a/package.json +++ b/package.json @@ -13,9 +13,9 @@ "url": "https://github.com/zadam/trilium.git" }, "scripts": { - "start-server": "cross-env TRILIUM_SAFE_MODE=1 TRILIUM_DATA_DIR=./data TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 nodemon src/www.js", - "start-server-no-dir": "cross-env TRILIUM_SAFE_MODE=1 TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 nodemon src/www.js", - "qstart-server": "npm run qswitch-server && TRILIUM_SAFE_MODE=1 TRILIUM_DATA_DIR=./data TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 nodemon src/www.js", + "start-server": "cross-env TRILIUM_SAFE_MODE=1 TRILIUM_DATA_DIR=./data TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 ts-node src/www.js", + "start-server-no-dir": "cross-env TRILIUM_SAFE_MODE=1 TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 ts-node src/www.js", + "qstart-server": "npm run qswitch-server && TRILIUM_SAFE_MODE=1 TRILIUM_DATA_DIR=./data TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 ts-node src/www.js", "start-electron": "cross-env TRILIUM_SAFE_MODE=1 TRILIUM_DATA_DIR=./data TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev electron --inspect=5858 .", "start-electron-no-dir": "cross-env TRILIUM_SAFE_MODE=1 TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 electron --inspect=5858 .", "qstart-electron": "npm run qswitch-electron && TRILIUM_SAFE_MODE=1 TRILIUM_DATA_DIR=./data TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev electron --inspect=5858 .", @@ -111,6 +111,7 @@ "yauzl": "2.10.0" }, "devDependencies": { + "@types/node": "^20.11.19", "cross-env": "7.0.3", "electron": "25.9.8", "electron-builder": "24.6.4", @@ -132,6 +133,9 @@ "nodemon": "3.0.1", "prettier": "3.1.0", "rcedit": "4.0.1", + "ts-node": "^3.3.0", + "tslib": "^2.6.2", + "typescript": "^5.3.3", "webpack": "5.89.0", "webpack-cli": "5.1.4" }, From 39627a4fc4788a36a743a70e8f83db64efc53a38 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Fri, 16 Feb 2024 20:27:00 +0200 Subject: [PATCH 02/49] server-ts: log.js -> log.ts --- db/migrations/0220__migrate_images_to_attachments.js | 2 +- src/becca/becca_loader.js | 2 +- src/becca/becca_service.js | 2 +- src/becca/entities/abstract_becca_entity.js | 2 +- src/becca/entities/battachment.js | 2 +- src/becca/entities/bbranch.js | 2 +- src/becca/entities/bnote.js | 2 +- src/becca/similarity.js | 2 +- src/etapi/etapi_utils.js | 2 +- src/routes/api/attributes.js | 2 +- src/routes/api/autocomplete.js | 2 +- src/routes/api/branches.js | 2 +- src/routes/api/clipper.js | 2 +- src/routes/api/database.js | 2 +- src/routes/api/export.js | 2 +- src/routes/api/files.js | 2 +- src/routes/api/import.js | 2 +- src/routes/api/notes.js | 2 +- src/routes/api/options.js | 2 +- src/routes/api/setup.js | 2 +- src/routes/api/sync.js | 2 +- src/routes/api/tree.js | 2 +- src/routes/custom.js | 2 +- src/routes/error_handlers.js | 2 +- src/routes/index.js | 2 +- src/routes/login.js | 2 +- src/routes/routes.js | 2 +- src/services/app_icon.js | 2 +- src/services/auth.js | 2 +- src/services/backend_script_api.js | 2 +- src/services/backup.js | 2 +- src/services/bulk_actions.js | 2 +- src/services/cloning.js | 2 +- src/services/consistency_checks.js | 2 +- src/services/content_hash.js | 2 +- src/services/encryption/data_encryption.js | 2 +- src/services/entity_changes.js | 2 +- src/services/erase.js | 2 +- src/services/events.js | 2 +- src/services/export/zip.js | 2 +- src/services/hidden_subtree.js | 2 +- src/services/image.js | 2 +- src/services/import/enex.js | 2 +- src/services/import/zip.js | 2 +- src/services/keyboard_actions.js | 2 +- src/services/{log.js => log.ts} | 0 src/services/migration.js | 2 +- src/services/notes.js | 2 +- src/services/options_init.js | 2 +- src/services/protected_session.js | 2 +- src/services/request.js | 2 +- src/services/resource_dir.js | 2 +- src/services/revisions.js | 2 +- src/services/scheduler.js | 2 +- src/services/script.js | 2 +- src/services/search/expressions/ancestor.js | 2 +- src/services/search/expressions/note_content_fulltext.js | 2 +- src/services/search/services/search.js | 2 +- src/services/session_secret.js | 2 +- src/services/setup.js | 2 +- src/services/special_notes.js | 2 +- src/services/sql.js | 2 +- src/services/sql_init.js | 2 +- src/services/sync.js | 2 +- src/services/sync_update.js | 2 +- src/services/tree.js | 2 +- src/services/window.js | 2 +- src/services/ws.js | 2 +- src/share/routes.js | 2 +- src/share/shaca/shaca_loader.js | 2 +- 70 files changed, 69 insertions(+), 69 deletions(-) rename src/services/{log.js => log.ts} (100%) diff --git a/db/migrations/0220__migrate_images_to_attachments.js b/db/migrations/0220__migrate_images_to_attachments.js index 74e743613..400003514 100644 --- a/db/migrations/0220__migrate_images_to_attachments.js +++ b/db/migrations/0220__migrate_images_to_attachments.js @@ -2,7 +2,7 @@ module.exports = () => { const beccaLoader = require('../../src/becca/becca_loader.js'); const becca = require('../../src/becca/becca.js'); const cls = require('../../src/services/cls.js'); - const log = require('../../src/services/log.js'); + const log = require('../../src/services/log.ts'); const sql = require('../../src/services/sql.js'); cls.init(() => { diff --git a/src/becca/becca_loader.js b/src/becca/becca_loader.js index 5d6ce6f06..75d7ec0c7 100644 --- a/src/becca/becca_loader.js +++ b/src/becca/becca_loader.js @@ -4,7 +4,7 @@ const sql = require('../services/sql.js'); const eventService = require('../services/events.js'); const becca = require('./becca.js'); const sqlInit = require('../services/sql_init.js'); -const log = require('../services/log.js'); +const log = require('../services/log.ts'); const BNote = require('./entities/bnote.js'); const BBranch = require('./entities/bbranch.js'); const BAttribute = require('./entities/battribute.js'); diff --git a/src/becca/becca_service.js b/src/becca/becca_service.js index 0ac5c2591..cc0c02632 100644 --- a/src/becca/becca_service.js +++ b/src/becca/becca_service.js @@ -2,7 +2,7 @@ const becca = require('./becca.js'); const cls = require('../services/cls.js'); -const log = require('../services/log.js'); +const log = require('../services/log.ts'); function isNotePathArchived(notePath) { const noteId = notePath[notePath.length - 1]; diff --git a/src/becca/entities/abstract_becca_entity.js b/src/becca/entities/abstract_becca_entity.js index 3b2e6331b..6f05dcf52 100644 --- a/src/becca/entities/abstract_becca_entity.js +++ b/src/becca/entities/abstract_becca_entity.js @@ -6,7 +6,7 @@ const entityChangesService = require('../../services/entity_changes.js'); const eventService = require('../../services/events.js'); const dateUtils = require('../../services/date_utils.js'); const cls = require('../../services/cls.js'); -const log = require('../../services/log.js'); +const log = require('../../services/log.ts'); const protectedSessionService = require('../../services/protected_session.js'); const blobService = require('../../services/blob.js'); diff --git a/src/becca/entities/battachment.js b/src/becca/entities/battachment.js index e3e77974d..c8271e391 100644 --- a/src/becca/entities/battachment.js +++ b/src/becca/entities/battachment.js @@ -5,7 +5,7 @@ const dateUtils = require('../../services/date_utils.js'); const AbstractBeccaEntity = require('./abstract_becca_entity.js'); const sql = require('../../services/sql.js'); const protectedSessionService = require('../../services/protected_session.js'); -const log = require('../../services/log.js'); +const log = require('../../services/log.ts'); const attachmentRoleToNoteTypeMapping = { 'image': 'image' diff --git a/src/becca/entities/bbranch.js b/src/becca/entities/bbranch.js index 94cc1b802..a8208632a 100644 --- a/src/becca/entities/bbranch.js +++ b/src/becca/entities/bbranch.js @@ -6,7 +6,7 @@ const dateUtils = require('../../services/date_utils.js'); const utils = require('../../services/utils.js'); const TaskContext = require('../../services/task_context.js'); const cls = require('../../services/cls.js'); -const log = require('../../services/log.js'); +const log = require('../../services/log.ts'); /** * Branch represents a relationship between a child note and its parent note. Trilium allows a note to have multiple diff --git a/src/becca/entities/bnote.js b/src/becca/entities/bnote.js index 36f8ed3d4..118ff9976 100644 --- a/src/becca/entities/bnote.js +++ b/src/becca/entities/bnote.js @@ -1,7 +1,7 @@ "use strict"; const protectedSessionService = require('../../services/protected_session.js'); -const log = require('../../services/log.js'); +const log = require('../../services/log.ts'); const sql = require('../../services/sql.js'); const utils = require('../../services/utils.js'); const dateUtils = require('../../services/date_utils.js'); diff --git a/src/becca/similarity.js b/src/becca/similarity.js index 5be56804d..9e225ddcf 100644 --- a/src/becca/similarity.js +++ b/src/becca/similarity.js @@ -1,5 +1,5 @@ const becca = require('./becca.js'); -const log = require('../services/log.js'); +const log = require('../services/log.ts'); const beccaService = require('./becca_service.js'); const dateUtils = require('../services/date_utils.js'); const {JSDOM} = require("jsdom"); diff --git a/src/etapi/etapi_utils.js b/src/etapi/etapi_utils.js index d3699b664..662e36cbb 100644 --- a/src/etapi/etapi_utils.js +++ b/src/etapi/etapi_utils.js @@ -1,6 +1,6 @@ const cls = require('../services/cls.js'); const sql = require('../services/sql.js'); -const log = require('../services/log.js'); +const log = require('../services/log.ts'); const becca = require('../becca/becca.js'); const etapiTokenService = require('../services/etapi_tokens.js'); const config = require('../services/config.js'); diff --git a/src/routes/api/attributes.js b/src/routes/api/attributes.js index 0d9b541f1..f96330beb 100644 --- a/src/routes/api/attributes.js +++ b/src/routes/api/attributes.js @@ -1,7 +1,7 @@ "use strict"; const sql = require('../../services/sql.js'); -const log = require('../../services/log.js'); +const log = require('../../services/log.ts'); const attributeService = require('../../services/attributes.js'); const BAttribute = require('../../becca/entities/battribute.js'); const becca = require('../../becca/becca.js'); diff --git a/src/routes/api/autocomplete.js b/src/routes/api/autocomplete.js index 4fe35a564..2ea2ca6c9 100644 --- a/src/routes/api/autocomplete.js +++ b/src/routes/api/autocomplete.js @@ -2,7 +2,7 @@ const beccaService = require('../../becca/becca_service.js'); const searchService = require('../../services/search/services/search.js'); -const log = require('../../services/log.js'); +const log = require('../../services/log.ts'); const utils = require('../../services/utils.js'); const cls = require('../../services/cls.js'); const becca = require('../../becca/becca.js'); diff --git a/src/routes/api/branches.js b/src/routes/api/branches.js index 17f11cd01..337fdc0eb 100644 --- a/src/routes/api/branches.js +++ b/src/routes/api/branches.js @@ -8,7 +8,7 @@ const eraseService = require('../../services/erase.js'); const becca = require('../../becca/becca.js'); const TaskContext = require('../../services/task_context.js'); const branchService = require('../../services/branches.js'); -const log = require('../../services/log.js'); +const log = require('../../services/log.ts'); const ValidationError = require('../../errors/validation_error.js'); const eventService = require("../../services/events.js"); diff --git a/src/routes/api/clipper.js b/src/routes/api/clipper.js index 1a7ac2e81..8c38ff72e 100644 --- a/src/routes/api/clipper.js +++ b/src/routes/api/clipper.js @@ -8,7 +8,7 @@ const dateUtils = require('../../services/date_utils.js'); const imageService = require('../../services/image.js'); const appInfo = require('../../services/app_info.js'); const ws = require('../../services/ws.js'); -const log = require('../../services/log.js'); +const log = require('../../services/log.ts'); const utils = require('../../services/utils.js'); const path = require('path'); const htmlSanitizer = require('../../services/html_sanitizer.js'); diff --git a/src/routes/api/database.js b/src/routes/api/database.js index 5b6b4739d..a09750a45 100644 --- a/src/routes/api/database.js +++ b/src/routes/api/database.js @@ -1,7 +1,7 @@ "use strict"; const sql = require('../../services/sql.js'); -const log = require('../../services/log.js'); +const log = require('../../services/log.ts'); const backupService = require('../../services/backup.js'); const anonymizationService = require('../../services/anonymization.js'); const consistencyChecksService = require('../../services/consistency_checks.js'); diff --git a/src/routes/api/export.js b/src/routes/api/export.js index 514fdf861..9a7323adb 100644 --- a/src/routes/api/export.js +++ b/src/routes/api/export.js @@ -5,7 +5,7 @@ const singleExportService = require('../../services/export/single.js'); const opmlExportService = require('../../services/export/opml.js'); const becca = require('../../becca/becca.js'); const TaskContext = require('../../services/task_context.js'); -const log = require('../../services/log.js'); +const log = require('../../services/log.ts'); const NotFoundError = require('../../errors/not_found_error.js'); function exportBranch(req, res) { diff --git a/src/routes/api/files.js b/src/routes/api/files.js index 72bd0ee11..43e64760d 100644 --- a/src/routes/api/files.js +++ b/src/routes/api/files.js @@ -2,7 +2,7 @@ const protectedSessionService = require('../../services/protected_session.js'); const utils = require('../../services/utils.js'); -const log = require('../../services/log.js'); +const log = require('../../services/log.ts'); const noteService = require('../../services/notes.js'); const tmp = require('tmp'); const fs = require('fs'); diff --git a/src/routes/api/import.js b/src/routes/api/import.js index 0e27ed515..2a9d8a594 100644 --- a/src/routes/api/import.js +++ b/src/routes/api/import.js @@ -8,7 +8,7 @@ const cls = require('../../services/cls.js'); const path = require('path'); const becca = require('../../becca/becca.js'); const beccaLoader = require('../../becca/becca_loader.js'); -const log = require('../../services/log.js'); +const log = require('../../services/log.ts'); const TaskContext = require('../../services/task_context.js'); const ValidationError = require('../../errors/validation_error.js'); diff --git a/src/routes/api/notes.js b/src/routes/api/notes.js index 54cd83330..d5693c137 100644 --- a/src/routes/api/notes.js +++ b/src/routes/api/notes.js @@ -5,7 +5,7 @@ const eraseService = require('../../services/erase.js'); const treeService = require('../../services/tree.js'); const sql = require('../../services/sql.js'); const utils = require('../../services/utils.js'); -const log = require('../../services/log.js'); +const log = require('../../services/log.ts'); const TaskContext = require('../../services/task_context.js'); const becca = require('../../becca/becca.js'); const ValidationError = require('../../errors/validation_error.js'); diff --git a/src/routes/api/options.js b/src/routes/api/options.js index efd70a07e..741634940 100644 --- a/src/routes/api/options.js +++ b/src/routes/api/options.js @@ -1,7 +1,7 @@ "use strict"; const optionService = require('../../services/options.js'); -const log = require('../../services/log.js'); +const log = require('../../services/log.ts'); const searchService = require('../../services/search/services/search.js'); const ValidationError = require('../../errors/validation_error.js'); diff --git a/src/routes/api/setup.js b/src/routes/api/setup.js index 4ed672f9d..a094b639c 100644 --- a/src/routes/api/setup.js +++ b/src/routes/api/setup.js @@ -2,7 +2,7 @@ const sqlInit = require('../../services/sql_init.js'); const setupService = require('../../services/setup.js'); -const log = require('../../services/log.js'); +const log = require('../../services/log.ts'); const appInfo = require('../../services/app_info.js'); function getStatus() { diff --git a/src/routes/api/sync.js b/src/routes/api/sync.js index 44da3e52c..cfe1afd88 100644 --- a/src/routes/api/sync.js +++ b/src/routes/api/sync.js @@ -7,7 +7,7 @@ const sql = require('../../services/sql.js'); const sqlInit = require('../../services/sql_init.js'); const optionService = require('../../services/options.js'); const contentHashService = require('../../services/content_hash.js'); -const log = require('../../services/log.js'); +const log = require('../../services/log.ts'); const syncOptions = require('../../services/sync_options.js'); const utils = require('../../services/utils.js'); const ws = require('../../services/ws.js'); diff --git a/src/routes/api/tree.js b/src/routes/api/tree.js index a5b4ad639..7162e13ba 100644 --- a/src/routes/api/tree.js +++ b/src/routes/api/tree.js @@ -1,7 +1,7 @@ "use strict"; const becca = require('../../becca/becca.js'); -const log = require('../../services/log.js'); +const log = require('../../services/log.ts'); const NotFoundError = require('../../errors/not_found_error.js'); function getNotesAndBranchesAndAttributes(noteIds) { diff --git a/src/routes/custom.js b/src/routes/custom.js index c76240976..1506244d3 100644 --- a/src/routes/custom.js +++ b/src/routes/custom.js @@ -1,4 +1,4 @@ -const log = require('../services/log.js'); +const log = require('../services/log.ts'); const fileService = require('./api/files.js'); const scriptService = require('../services/script.js'); const cls = require('../services/cls.js'); diff --git a/src/routes/error_handlers.js b/src/routes/error_handlers.js index 1e9715ed8..441da4b67 100644 --- a/src/routes/error_handlers.js +++ b/src/routes/error_handlers.js @@ -1,4 +1,4 @@ -const log = require('../services/log.js'); +const log = require('../services/log.ts'); function register(app) { app.use((err, req, res, next) => { diff --git a/src/routes/index.js b/src/routes/index.js index d57563bad..7544a8bc6 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -4,7 +4,7 @@ const sql = require('../services/sql.js'); const attributeService = require('../services/attributes.js'); const config = require('../services/config.js'); const optionService = require('../services/options.js'); -const log = require('../services/log.js'); +const log = require('../services/log.ts'); const env = require('../services/env.js'); const utils = require('../services/utils.js'); const protectedSessionService = require('../services/protected_session.js'); diff --git a/src/routes/login.js b/src/routes/login.js index 6c4af5cdb..181eedc0d 100644 --- a/src/routes/login.js +++ b/src/routes/login.js @@ -3,7 +3,7 @@ const utils = require('../services/utils.js'); const optionService = require('../services/options.js'); const myScryptService = require('../services/encryption/my_scrypt.js'); -const log = require('../services/log.js'); +const log = require('../services/log.ts'); const passwordService = require('../services/encryption/password.js'); const assetPath = require('../services/asset_path.js'); const appPath = require('../services/app_path.js'); diff --git a/src/routes/routes.js b/src/routes/routes.js index fd3cf167a..3c46763c3 100644 --- a/src/routes/routes.js +++ b/src/routes/routes.js @@ -2,7 +2,7 @@ const utils = require('../services/utils.js'); const multer = require('multer'); -const log = require('../services/log.js'); +const log = require('../services/log.ts'); const express = require('express'); const router = express.Router(); const auth = require('../services/auth.js'); diff --git a/src/services/app_icon.js b/src/services/app_icon.js index 51e319113..04f9d034d 100644 --- a/src/services/app_icon.js +++ b/src/services/app_icon.js @@ -2,7 +2,7 @@ const path = require('path'); const {ELECTRON_APP_ROOT_DIR} = require('./resource_dir.js'); -const log = require('./log.js'); +const log = require('./log.ts'); const os = require('os'); const fs = require('fs'); const config = require('./config.js'); diff --git a/src/services/auth.js b/src/services/auth.js index adb565134..cb31a9889 100644 --- a/src/services/auth.js +++ b/src/services/auth.js @@ -1,7 +1,7 @@ "use strict"; const etapiTokenService = require('./etapi_tokens.js'); -const log = require('./log.js'); +const log = require('./log.ts'); const sqlInit = require('./sql_init.js'); const utils = require('./utils.js'); const passwordEncryptionService = require('./encryption/password_encryption.js'); diff --git a/src/services/backend_script_api.js b/src/services/backend_script_api.js index 5abf704ed..36d1fb915 100644 --- a/src/services/backend_script_api.js +++ b/src/services/backend_script_api.js @@ -1,4 +1,4 @@ -const log = require('./log.js'); +const log = require('./log.ts'); const noteService = require('./notes.js'); const sql = require('./sql.js'); const utils = require('./utils.js'); diff --git a/src/services/backup.js b/src/services/backup.js index ef36d91cf..4796da0cf 100644 --- a/src/services/backup.js +++ b/src/services/backup.js @@ -4,7 +4,7 @@ const dateUtils = require('./date_utils.js'); const optionService = require('./options.js'); const fs = require('fs-extra'); const dataDir = require('./data_dir.js'); -const log = require('./log.js'); +const log = require('./log.ts'); const syncMutexService = require('./sync_mutex.js'); const cls = require('./cls.js'); const sql = require('./sql.js'); diff --git a/src/services/bulk_actions.js b/src/services/bulk_actions.js index 351370578..14ff03ccd 100644 --- a/src/services/bulk_actions.js +++ b/src/services/bulk_actions.js @@ -1,4 +1,4 @@ -const log = require('./log.js'); +const log = require('./log.ts'); const revisionService = require('./revisions.js'); const becca = require('../becca/becca.js'); const cloningService = require('./cloning.js'); diff --git a/src/services/cloning.js b/src/services/cloning.js index 4baae5de7..1181983ac 100644 --- a/src/services/cloning.js +++ b/src/services/cloning.js @@ -5,7 +5,7 @@ const eventChangesService = require('./entity_changes.js'); const treeService = require('./tree.js'); const BBranch = require('../becca/entities/bbranch.js'); const becca = require('../becca/becca.js'); -const log = require('./log.js'); +const log = require('./log.ts'); function cloneNoteToParentNote(noteId, parentNoteId, prefix = null) { if (!(noteId in becca.notes) || !(parentNoteId in becca.notes)) { diff --git a/src/services/consistency_checks.js b/src/services/consistency_checks.js index 63f934d4f..901a54dbd 100644 --- a/src/services/consistency_checks.js +++ b/src/services/consistency_checks.js @@ -2,7 +2,7 @@ const sql = require('./sql.js'); const sqlInit = require('./sql_init.js'); -const log = require('./log.js'); +const log = require('./log.ts'); const ws = require('./ws.js'); const syncMutexService = require('./sync_mutex.js'); const cls = require('./cls.js'); diff --git a/src/services/content_hash.js b/src/services/content_hash.js index c9ca7fef6..2858b3cac 100644 --- a/src/services/content_hash.js +++ b/src/services/content_hash.js @@ -2,7 +2,7 @@ const sql = require('./sql.js'); const utils = require('./utils.js'); -const log = require('./log.js'); +const log = require('./log.ts'); const eraseService = require('./erase.js'); function getEntityHashes() { diff --git a/src/services/encryption/data_encryption.js b/src/services/encryption/data_encryption.js index 6b81686ed..fcd5c2f36 100644 --- a/src/services/encryption/data_encryption.js +++ b/src/services/encryption/data_encryption.js @@ -1,7 +1,7 @@ "use strict"; const crypto = require('crypto'); -const log = require('../log.js'); +const log = require('../log.ts'); function arraysIdentical(a, b) { let i = a.length; diff --git a/src/services/entity_changes.js b/src/services/entity_changes.js index 0e0a8ddb3..19c154a50 100644 --- a/src/services/entity_changes.js +++ b/src/services/entity_changes.js @@ -1,6 +1,6 @@ const sql = require('./sql.js'); const dateUtils = require('./date_utils.js'); -const log = require('./log.js'); +const log = require('./log.ts'); const cls = require('./cls.js'); const utils = require('./utils.js'); const instanceId = require('./instance_id.js'); diff --git a/src/services/erase.js b/src/services/erase.js index da65c3ebb..0a4e5ee3a 100644 --- a/src/services/erase.js +++ b/src/services/erase.js @@ -1,6 +1,6 @@ const sql = require("./sql.js"); const revisionService = require("./revisions.js"); -const log = require("./log.js"); +const log = require("./log.ts"); const entityChangesService = require("./entity_changes.js"); const optionService = require("./options.js"); const dateUtils = require("./date_utils.js"); diff --git a/src/services/events.js b/src/services/events.js index acb409107..849af3c52 100644 --- a/src/services/events.js +++ b/src/services/events.js @@ -1,4 +1,4 @@ -const log = require('./log.js'); +const log = require('./log.ts'); const NOTE_TITLE_CHANGED = "NOTE_TITLE_CHANGED"; const ENTER_PROTECTED_SESSION = "ENTER_PROTECTED_SESSION"; diff --git a/src/services/export/zip.js b/src/services/export/zip.js index dba7338d3..87ee4d4e4 100644 --- a/src/services/export/zip.js +++ b/src/services/export/zip.js @@ -13,7 +13,7 @@ const fs = require("fs"); const becca = require('../../becca/becca.js'); const RESOURCE_DIR = require('../../services/resource_dir.js').RESOURCE_DIR; const archiver = require('archiver'); -const log = require('../log.js'); +const log = require('../log.ts'); const TaskContext = require('../task_context.js'); const ValidationError = require('../../errors/validation_error.js'); const NoteMeta = require('../meta/note_meta.js'); diff --git a/src/services/hidden_subtree.js b/src/services/hidden_subtree.js index 9c2820943..d96c73b1f 100644 --- a/src/services/hidden_subtree.js +++ b/src/services/hidden_subtree.js @@ -1,7 +1,7 @@ const becca = require('../becca/becca.js'); const noteService = require('./notes.js'); const BAttribute = require('../becca/entities/battribute.js'); -const log = require('./log.js'); +const log = require('./log.ts'); const migrationService = require('./migration.js'); const LBTPL_ROOT = "_lbTplRoot"; diff --git a/src/services/image.js b/src/services/image.js index 5a45e85ca..ee795ebd8 100644 --- a/src/services/image.js +++ b/src/services/image.js @@ -1,7 +1,7 @@ "use strict"; const becca = require('../becca/becca.js'); -const log = require('./log.js'); +const log = require('./log.ts'); const protectedSessionService = require('./protected_session.js'); const noteService = require('./notes.js'); const optionService = require('./options.js'); diff --git a/src/services/import/enex.js b/src/services/import/enex.js index db0dc9d6c..73d0da225 100644 --- a/src/services/import/enex.js +++ b/src/services/import/enex.js @@ -1,7 +1,7 @@ const sax = require("sax"); const stream = require('stream'); const {Throttle} = require('stream-throttle'); -const log = require('../log.js'); +const log = require('../log.ts'); const utils = require('../utils.js'); const sql = require('../sql.js'); const noteService = require('../notes.js'); diff --git a/src/services/import/zip.js b/src/services/import/zip.js index 5097ba925..7b12130c8 100644 --- a/src/services/import/zip.js +++ b/src/services/import/zip.js @@ -2,7 +2,7 @@ const BAttribute = require('../../becca/entities/battribute.js'); const utils = require('../../services/utils.js'); -const log = require('../../services/log.js'); +const log = require('../../services/log.ts'); const noteService = require('../../services/notes.js'); const attributeService = require('../../services/attributes.js'); const BBranch = require('../../becca/entities/bbranch.js'); diff --git a/src/services/keyboard_actions.js b/src/services/keyboard_actions.js index 694b7a1d7..bcc8b3cd9 100644 --- a/src/services/keyboard_actions.js +++ b/src/services/keyboard_actions.js @@ -1,7 +1,7 @@ "use strict"; const optionService = require('./options.js'); -const log = require('./log.js'); +const log = require('./log.ts'); const utils = require('./utils.js'); const isMac = process.platform === "darwin"; diff --git a/src/services/log.js b/src/services/log.ts similarity index 100% rename from src/services/log.js rename to src/services/log.ts diff --git a/src/services/migration.js b/src/services/migration.js index aeb7ba217..8dce4c755 100644 --- a/src/services/migration.js +++ b/src/services/migration.js @@ -1,7 +1,7 @@ const backupService = require('./backup.js'); const sql = require('./sql.js'); const fs = require('fs-extra'); -const log = require('./log.js'); +const log = require('./log.ts'); const utils = require('./utils.js'); const resourceDir = require('./resource_dir.js'); const appInfo = require('./app_info.js'); diff --git a/src/services/notes.js b/src/services/notes.js index 80a3b8e84..d699502e8 100644 --- a/src/services/notes.js +++ b/src/services/notes.js @@ -5,7 +5,7 @@ const entityChangesService = require('./entity_changes.js'); const eventService = require('./events.js'); const cls = require('../services/cls.js'); const protectedSessionService = require('../services/protected_session.js'); -const log = require('../services/log.js'); +const log = require('../services/log.ts'); const utils = require('../services/utils.js'); const revisionService = require('./revisions.js'); const request = require('./request.js'); diff --git a/src/services/options_init.js b/src/services/options_init.js index 95514d6d6..9f3add64b 100644 --- a/src/services/options_init.js +++ b/src/services/options_init.js @@ -1,7 +1,7 @@ const optionService = require('./options.js'); const appInfo = require('./app_info.js'); const utils = require('./utils.js'); -const log = require('./log.js'); +const log = require('./log.ts'); const dateUtils = require('./date_utils.js'); const keyboardActions = require('./keyboard_actions.js'); diff --git a/src/services/protected_session.js b/src/services/protected_session.js index 2ade5e338..c1d6b0986 100644 --- a/src/services/protected_session.js +++ b/src/services/protected_session.js @@ -1,6 +1,6 @@ "use strict"; -const log = require('./log.js'); +const log = require('./log.ts'); const dataEncryptionService = require('./encryption/data_encryption.js'); let dataKey = null; diff --git a/src/services/request.js b/src/services/request.js index 610e44f51..696f41939 100644 --- a/src/services/request.js +++ b/src/services/request.js @@ -1,7 +1,7 @@ "use strict"; const utils = require('./utils.js'); -const log = require('./log.js'); +const log = require('./log.ts'); const url = require('url'); const syncOptions = require('./sync_options.js'); diff --git a/src/services/resource_dir.js b/src/services/resource_dir.js index 088a6d7d3..cbf1dea91 100644 --- a/src/services/resource_dir.js +++ b/src/services/resource_dir.js @@ -1,4 +1,4 @@ -const log = require('./log.js'); +const log = require('./log.ts'); const path = require('path'); const fs = require('fs'); diff --git a/src/services/revisions.js b/src/services/revisions.js index 743284789..8cdff23a8 100644 --- a/src/services/revisions.js +++ b/src/services/revisions.js @@ -1,6 +1,6 @@ "use strict"; -const log = require('./log.js'); +const log = require('./log.ts'); const sql = require('./sql.js'); const protectedSessionService = require('./protected_session.js'); const dateUtils = require('./date_utils.js'); diff --git a/src/services/scheduler.js b/src/services/scheduler.js index 48a19815a..6f7dc25fb 100644 --- a/src/services/scheduler.js +++ b/src/services/scheduler.js @@ -2,7 +2,7 @@ const scriptService = require('./script.js'); const cls = require('./cls.js'); const sqlInit = require('./sql_init.js'); const config = require('./config.js'); -const log = require('./log.js'); +const log = require('./log.ts'); const attributeService = require('../services/attributes.js'); const protectedSessionService = require('../services/protected_session.js'); const hiddenSubtreeService = require('./hidden_subtree.js'); diff --git a/src/services/script.js b/src/services/script.js index 6119075e3..4c26a37f7 100644 --- a/src/services/script.js +++ b/src/services/script.js @@ -1,6 +1,6 @@ const ScriptContext = require('./script_context.js'); const cls = require('./cls.js'); -const log = require('./log.js'); +const log = require('./log.ts'); const becca = require('../becca/becca.js'); function executeNote(note, apiParams) { diff --git a/src/services/search/expressions/ancestor.js b/src/services/search/expressions/ancestor.js index 57c3adb5f..d1d93eed2 100644 --- a/src/services/search/expressions/ancestor.js +++ b/src/services/search/expressions/ancestor.js @@ -2,7 +2,7 @@ const Expression = require('./expression.js'); const NoteSet = require('../note_set.js'); -const log = require('../../log.js'); +const log = require('../../log.ts'); const becca = require('../../../becca/becca.js'); class AncestorExp extends Expression { diff --git a/src/services/search/expressions/note_content_fulltext.js b/src/services/search/expressions/note_content_fulltext.js index 86b08c469..b4c90005f 100644 --- a/src/services/search/expressions/note_content_fulltext.js +++ b/src/services/search/expressions/note_content_fulltext.js @@ -2,7 +2,7 @@ const Expression = require('./expression.js'); const NoteSet = require('../note_set.js'); -const log = require('../../log.js'); +const log = require('../../log.ts'); const becca = require('../../../becca/becca.js'); const protectedSessionService = require('../../protected_session.js'); const striptags = require('striptags'); diff --git a/src/services/search/services/search.js b/src/services/search/services/search.js index e1ceed086..68ab55226 100644 --- a/src/services/search/services/search.js +++ b/src/services/search/services/search.js @@ -9,7 +9,7 @@ const SearchContext = require('../search_context.js'); const becca = require('../../../becca/becca.js'); const beccaService = require('../../../becca/becca_service.js'); const utils = require('../../utils.js'); -const log = require('../../log.js'); +const log = require('../../log.ts'); const hoistedNoteService = require('../../hoisted_note.js'); function searchFromNote(note) { diff --git a/src/services/session_secret.js b/src/services/session_secret.js index 90eaa65bc..009fae565 100644 --- a/src/services/session_secret.js +++ b/src/services/session_secret.js @@ -3,7 +3,7 @@ const fs = require('fs'); const crypto = require('crypto'); const dataDir = require('./data_dir.js'); -const log = require('./log.js'); +const log = require('./log.ts'); const sessionSecretPath = `${dataDir.TRILIUM_DATA_DIR}/session_secret.txt`; diff --git a/src/services/setup.js b/src/services/setup.js index 67eb7f3ce..6c7156ebc 100644 --- a/src/services/setup.js +++ b/src/services/setup.js @@ -1,5 +1,5 @@ const syncService = require('./sync.js'); -const log = require('./log.js'); +const log = require('./log.ts'); const sqlInit = require('./sql_init.js'); const optionService = require('./options.js'); const syncOptions = require('./sync_options.js'); diff --git a/src/services/special_notes.js b/src/services/special_notes.js index 60d202df0..09ce82a69 100644 --- a/src/services/special_notes.js +++ b/src/services/special_notes.js @@ -3,7 +3,7 @@ const dateNoteService = require('./date_notes.js'); const becca = require('../becca/becca.js'); const noteService = require('./notes.js'); const dateUtils = require('./date_utils.js'); -const log = require('./log.js'); +const log = require('./log.ts'); const hoistedNoteService = require('./hoisted_note.js'); const searchService = require('./search/services/search.js'); const SearchContext = require('./search/search_context.js'); diff --git a/src/services/sql.js b/src/services/sql.js index 38cbabe19..171030d6f 100644 --- a/src/services/sql.js +++ b/src/services/sql.js @@ -4,7 +4,7 @@ * @module sql */ -const log = require('./log.js'); +const log = require('./log.ts'); const Database = require('better-sqlite3'); const dataDir = require('./data_dir.js'); const cls = require('./cls.js'); diff --git a/src/services/sql_init.js b/src/services/sql_init.js index f1b4e9152..572334f13 100644 --- a/src/services/sql_init.js +++ b/src/services/sql_init.js @@ -1,4 +1,4 @@ -const log = require('./log.js'); +const log = require('./log.ts'); const fs = require('fs'); const resourceDir = require('./resource_dir.js'); const sql = require('./sql.js'); diff --git a/src/services/sync.js b/src/services/sync.js index fbafdfcfa..7d64cac57 100644 --- a/src/services/sync.js +++ b/src/services/sync.js @@ -1,6 +1,6 @@ "use strict"; -const log = require('./log.js'); +const log = require('./log.ts'); const sql = require('./sql.js'); const optionService = require('./options.js'); const utils = require('./utils.js'); diff --git a/src/services/sync_update.js b/src/services/sync_update.js index 94091e9ef..3a1577971 100644 --- a/src/services/sync_update.js +++ b/src/services/sync_update.js @@ -1,5 +1,5 @@ const sql = require('./sql.js'); -const log = require('./log.js'); +const log = require('./log.ts'); const entityChangesService = require('./entity_changes.js'); const eventService = require('./events.js'); const entityConstructor = require('../becca/entity_constructor.js'); diff --git a/src/services/tree.js b/src/services/tree.js index 3973b0f6e..239a9ab35 100644 --- a/src/services/tree.js +++ b/src/services/tree.js @@ -1,7 +1,7 @@ "use strict"; const sql = require('./sql.js'); -const log = require('./log.js'); +const log = require('./log.ts'); const BBranch = require('../becca/entities/bbranch.js'); const entityChangesService = require('./entity_changes.js'); const becca = require('../becca/becca.js'); diff --git a/src/services/window.js b/src/services/window.js index 68f70010a..97a60db91 100644 --- a/src/services/window.js +++ b/src/services/window.js @@ -3,7 +3,7 @@ const url = require("url"); const port = require('./port.js'); const optionService = require('./options.js'); const env = require('./env.js'); -const log = require('./log.js'); +const log = require('./log.ts'); const sqlInit = require('./sql_init.js'); const cls = require('./cls.js'); const keyboardActionsService = require('./keyboard_actions.js'); diff --git a/src/services/ws.js b/src/services/ws.js index 9dead1866..759e0823c 100644 --- a/src/services/ws.js +++ b/src/services/ws.js @@ -1,6 +1,6 @@ const WebSocket = require('ws'); const utils = require('./utils.js'); -const log = require('./log.js'); +const log = require('./log.ts'); const sql = require('./sql.js'); const cls = require('./cls.js'); const config = require('./config.js'); diff --git a/src/share/routes.js b/src/share/routes.js index 2805933a8..95d6c1a9f 100644 --- a/src/share/routes.js +++ b/src/share/routes.js @@ -11,7 +11,7 @@ const assetPath = require('../services/asset_path.js'); const appPath = require('../services/app_path.js'); const searchService = require('../services/search/services/search.js'); const SearchContext = require('../services/search/search_context.js'); -const log = require('../services/log.js'); +const log = require('../services/log.ts'); /** * @param {SNote} note diff --git a/src/share/shaca/shaca_loader.js b/src/share/shaca/shaca_loader.js index 00ba63182..83c755e36 100644 --- a/src/share/shaca/shaca_loader.js +++ b/src/share/shaca/shaca_loader.js @@ -2,7 +2,7 @@ const sql = require('../sql.js'); const shaca = require('./shaca.js'); -const log = require('../../services/log.js'); +const log = require('../../services/log.ts'); const SNote = require('./entities/snote.js'); const SBranch = require('./entities/sbranch.js'); const SAttribute = require('./entities/sattribute.js'); From bda11fad406c34bf61f5ef17af8b54d5624eb4d9 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Fri, 16 Feb 2024 20:54:54 +0200 Subject: [PATCH 03/49] server-ts: Fix errors in log.ts --- .vscode/settings.json | 1 + package-lock.json | 177 ++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + src/services/log.ts | 23 +++--- tsconfig.json | 14 ++++ 5 files changed, 205 insertions(+), 11 deletions(-) create mode 100644 tsconfig.json diff --git a/.vscode/settings.json b/.vscode/settings.json index 0e4b77b5c..d3cb3fd10 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -30,4 +30,5 @@ "jsonc" ], "files.eol": "\n", + "typescript.tsdk": "node_modules/typescript/lib", } \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 47be0133d..953690117 100644 --- a/package-lock.json +++ b/package-lock.json @@ -88,6 +88,7 @@ "trilium": "src/www.js" }, "devDependencies": { + "@types/express": "^4.17.21", "@types/node": "^20.11.19", "cross-env": "7.0.3", "electron": "25.9.8", @@ -1280,6 +1281,16 @@ "resolved": "https://registry.npmjs.org/@tweenjs/tween.js/-/tween.js-21.0.0.tgz", "integrity": "sha512-qVfOiFh0U8ZSkLgA6tf7kj2MciqRbSCWaJZRwftVO7UbtVDNsZAXpWXqvCDtIefvjC83UJB+vHTDOGm5ibXjEA==" }, + "node_modules/@types/body-parser": { + "version": "1.19.5", + "resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.19.5.tgz", + "integrity": "sha512-fB3Zu92ucau0iQ0JMCFQE7b/dv8Ot07NI3KaZIkIUNXq82k4eBAqUaneXfleGY9JWskeS9y+u0nXMyspcuQrCg==", + "dev": true, + "dependencies": { + "@types/connect": "*", + "@types/node": "*" + } + }, "node_modules/@types/cacheable-request": { "version": "6.0.2", "resolved": "https://registry.npmjs.org/@types/cacheable-request/-/cacheable-request-6.0.2.tgz", @@ -1291,6 +1302,15 @@ "@types/responselike": "*" } }, + "node_modules/@types/connect": { + "version": "3.4.38", + "resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.38.tgz", + "integrity": "sha512-K6uROf1LD88uDQqJCktA4yzL1YYAK6NgfsI0v/mTgyPKWsX1CnJ0XPSDhViejru1GcRkLWb8RlzFYJRqGUbaug==", + "dev": true, + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/d3-scale": { "version": "4.0.8", "resolved": "https://registry.npmjs.org/@types/d3-scale/-/d3-scale-4.0.8.tgz", @@ -1343,6 +1363,30 @@ "integrity": "sha512-LG4opVs2ANWZ1TJoKc937iMmNstM/d0ae1vNbnBvBhqCSezgVUOzcLCqbI5elV8Vy6WKwKjaqR+zO9VKirBBCA==", "dev": true }, + "node_modules/@types/express": { + "version": "4.17.21", + "resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.21.tgz", + "integrity": "sha512-ejlPM315qwLpaQlQDTjPdsUFSc6ZsP4AN6AlWnogPjQ7CVi7PYF3YVz+CY3jE2pwYf7E/7HlDAN0rV2GxTG0HQ==", + "dev": true, + "dependencies": { + "@types/body-parser": "*", + "@types/express-serve-static-core": "^4.17.33", + "@types/qs": "*", + "@types/serve-static": "*" + } + }, + "node_modules/@types/express-serve-static-core": { + "version": "4.17.43", + "resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.17.43.tgz", + "integrity": "sha512-oaYtiBirUOPQGSWNGPWnzyAFJ0BP3cwvN4oWZQY+zUBwpVIGsKUkpBpSztp74drYcjavs7SKFZ4DX1V2QeN8rg==", + "dev": true, + "dependencies": { + "@types/node": "*", + "@types/qs": "*", + "@types/range-parser": "*", + "@types/send": "*" + } + }, "node_modules/@types/fs-extra": { "version": "9.0.13", "resolved": "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-9.0.13.tgz", @@ -1367,6 +1411,12 @@ "resolved": "https://registry.npmjs.org/@types/http-cache-semantics/-/http-cache-semantics-4.0.1.tgz", "integrity": "sha512-SZs7ekbP8CN0txVG2xVRH6EgKmEm31BOxA07vkFaETzZz1xh+cbt8BcI0slpymvwhx5dlFnQG2rTlPVQn+iRPQ==" }, + "node_modules/@types/http-errors": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/@types/http-errors/-/http-errors-2.0.4.tgz", + "integrity": "sha512-D0CFMMtydbJAegzOyHjtiKPLlvnm3iTZyZRSZoLq2mRhDdmLfIWOCYPfQJ4cu2erKghU++QvjcUjp/5h7hESpA==", + "dev": true + }, "node_modules/@types/json-schema": { "version": "7.0.9", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.9.tgz", @@ -1417,6 +1467,12 @@ "integrity": "sha512-eC4U9MlIcu2q0KQmXszyn5Akca/0jrQmwDRgpAMJai7qBWq4amIQhZyNau4VYGtCeALvW1/NtjzJJ567aZxfKA==", "dev": true }, + "node_modules/@types/mime": { + "version": "1.3.5", + "resolved": "https://registry.npmjs.org/@types/mime/-/mime-1.3.5.tgz", + "integrity": "sha512-/pyBZWSLD2n0dcHE3hq8s8ZvcETHtEuF+3E7XVt0Ig2nvsVQXdghHVcEkIWjy9A0wKfTn97a/PSDYohKIlnP/w==", + "dev": true + }, "node_modules/@types/minimatch": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-3.0.3.tgz", @@ -1447,6 +1503,18 @@ "xmlbuilder": ">=11.0.1" } }, + "node_modules/@types/qs": { + "version": "6.9.11", + "resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.9.11.tgz", + "integrity": "sha512-oGk0gmhnEJK4Yyk+oI7EfXsLayXatCWPHary1MtcmbAifkobT9cM9yutG/hZKIseOU0MqbIwQ/u2nn/Gb+ltuQ==", + "dev": true + }, + "node_modules/@types/range-parser": { + "version": "1.2.7", + "resolved": "https://registry.npmjs.org/@types/range-parser/-/range-parser-1.2.7.tgz", + "integrity": "sha512-hKormJbkJqzQGhziax5PItDUTMAM9uE2XXQmM37dyd4hVM+5aVl7oVxMVUiVQn2oCQFN/LKCZdvSM0pFRqbSmQ==", + "dev": true + }, "node_modules/@types/responselike": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/@types/responselike/-/responselike-1.0.0.tgz", @@ -1455,6 +1523,27 @@ "@types/node": "*" } }, + "node_modules/@types/send": { + "version": "0.17.4", + "resolved": "https://registry.npmjs.org/@types/send/-/send-0.17.4.tgz", + "integrity": "sha512-x2EM6TJOybec7c52BX0ZspPodMsQUd5L6PRwOunVyVUhXiBSKf3AezDL8Dgvgt5o0UfKNfuA0eMLr2wLT4AiBA==", + "dev": true, + "dependencies": { + "@types/mime": "^1", + "@types/node": "*" + } + }, + "node_modules/@types/serve-static": { + "version": "1.15.5", + "resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-1.15.5.tgz", + "integrity": "sha512-PDRk21MnK70hja/YF8AHfC7yIsiQHn1rcXx7ijCFBX/k+XQJhQT/gw3xekXKJvx+5SXaMMS8oqQy09Mzvz2TuQ==", + "dev": true, + "dependencies": { + "@types/http-errors": "*", + "@types/mime": "*", + "@types/node": "*" + } + }, "node_modules/@types/unist": { "version": "2.0.10", "resolved": "https://registry.npmjs.org/@types/unist/-/unist-2.0.10.tgz", @@ -15805,6 +15894,16 @@ "resolved": "https://registry.npmjs.org/@tweenjs/tween.js/-/tween.js-21.0.0.tgz", "integrity": "sha512-qVfOiFh0U8ZSkLgA6tf7kj2MciqRbSCWaJZRwftVO7UbtVDNsZAXpWXqvCDtIefvjC83UJB+vHTDOGm5ibXjEA==" }, + "@types/body-parser": { + "version": "1.19.5", + "resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.19.5.tgz", + "integrity": "sha512-fB3Zu92ucau0iQ0JMCFQE7b/dv8Ot07NI3KaZIkIUNXq82k4eBAqUaneXfleGY9JWskeS9y+u0nXMyspcuQrCg==", + "dev": true, + "requires": { + "@types/connect": "*", + "@types/node": "*" + } + }, "@types/cacheable-request": { "version": "6.0.2", "resolved": "https://registry.npmjs.org/@types/cacheable-request/-/cacheable-request-6.0.2.tgz", @@ -15816,6 +15915,15 @@ "@types/responselike": "*" } }, + "@types/connect": { + "version": "3.4.38", + "resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.38.tgz", + "integrity": "sha512-K6uROf1LD88uDQqJCktA4yzL1YYAK6NgfsI0v/mTgyPKWsX1CnJ0XPSDhViejru1GcRkLWb8RlzFYJRqGUbaug==", + "dev": true, + "requires": { + "@types/node": "*" + } + }, "@types/d3-scale": { "version": "4.0.8", "resolved": "https://registry.npmjs.org/@types/d3-scale/-/d3-scale-4.0.8.tgz", @@ -15868,6 +15976,30 @@ "integrity": "sha512-LG4opVs2ANWZ1TJoKc937iMmNstM/d0ae1vNbnBvBhqCSezgVUOzcLCqbI5elV8Vy6WKwKjaqR+zO9VKirBBCA==", "dev": true }, + "@types/express": { + "version": "4.17.21", + "resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.21.tgz", + "integrity": "sha512-ejlPM315qwLpaQlQDTjPdsUFSc6ZsP4AN6AlWnogPjQ7CVi7PYF3YVz+CY3jE2pwYf7E/7HlDAN0rV2GxTG0HQ==", + "dev": true, + "requires": { + "@types/body-parser": "*", + "@types/express-serve-static-core": "^4.17.33", + "@types/qs": "*", + "@types/serve-static": "*" + } + }, + "@types/express-serve-static-core": { + "version": "4.17.43", + "resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.17.43.tgz", + "integrity": "sha512-oaYtiBirUOPQGSWNGPWnzyAFJ0BP3cwvN4oWZQY+zUBwpVIGsKUkpBpSztp74drYcjavs7SKFZ4DX1V2QeN8rg==", + "dev": true, + "requires": { + "@types/node": "*", + "@types/qs": "*", + "@types/range-parser": "*", + "@types/send": "*" + } + }, "@types/fs-extra": { "version": "9.0.13", "resolved": "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-9.0.13.tgz", @@ -15892,6 +16024,12 @@ "resolved": "https://registry.npmjs.org/@types/http-cache-semantics/-/http-cache-semantics-4.0.1.tgz", "integrity": "sha512-SZs7ekbP8CN0txVG2xVRH6EgKmEm31BOxA07vkFaETzZz1xh+cbt8BcI0slpymvwhx5dlFnQG2rTlPVQn+iRPQ==" }, + "@types/http-errors": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/@types/http-errors/-/http-errors-2.0.4.tgz", + "integrity": "sha512-D0CFMMtydbJAegzOyHjtiKPLlvnm3iTZyZRSZoLq2mRhDdmLfIWOCYPfQJ4cu2erKghU++QvjcUjp/5h7hESpA==", + "dev": true + }, "@types/json-schema": { "version": "7.0.9", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.9.tgz", @@ -15942,6 +16080,12 @@ "integrity": "sha512-eC4U9MlIcu2q0KQmXszyn5Akca/0jrQmwDRgpAMJai7qBWq4amIQhZyNau4VYGtCeALvW1/NtjzJJ567aZxfKA==", "dev": true }, + "@types/mime": { + "version": "1.3.5", + "resolved": "https://registry.npmjs.org/@types/mime/-/mime-1.3.5.tgz", + "integrity": "sha512-/pyBZWSLD2n0dcHE3hq8s8ZvcETHtEuF+3E7XVt0Ig2nvsVQXdghHVcEkIWjy9A0wKfTn97a/PSDYohKIlnP/w==", + "dev": true + }, "@types/minimatch": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-3.0.3.tgz", @@ -15972,6 +16116,18 @@ "xmlbuilder": ">=11.0.1" } }, + "@types/qs": { + "version": "6.9.11", + "resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.9.11.tgz", + "integrity": "sha512-oGk0gmhnEJK4Yyk+oI7EfXsLayXatCWPHary1MtcmbAifkobT9cM9yutG/hZKIseOU0MqbIwQ/u2nn/Gb+ltuQ==", + "dev": true + }, + "@types/range-parser": { + "version": "1.2.7", + "resolved": "https://registry.npmjs.org/@types/range-parser/-/range-parser-1.2.7.tgz", + "integrity": "sha512-hKormJbkJqzQGhziax5PItDUTMAM9uE2XXQmM37dyd4hVM+5aVl7oVxMVUiVQn2oCQFN/LKCZdvSM0pFRqbSmQ==", + "dev": true + }, "@types/responselike": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/@types/responselike/-/responselike-1.0.0.tgz", @@ -15980,6 +16136,27 @@ "@types/node": "*" } }, + "@types/send": { + "version": "0.17.4", + "resolved": "https://registry.npmjs.org/@types/send/-/send-0.17.4.tgz", + "integrity": "sha512-x2EM6TJOybec7c52BX0ZspPodMsQUd5L6PRwOunVyVUhXiBSKf3AezDL8Dgvgt5o0UfKNfuA0eMLr2wLT4AiBA==", + "dev": true, + "requires": { + "@types/mime": "^1", + "@types/node": "*" + } + }, + "@types/serve-static": { + "version": "1.15.5", + "resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-1.15.5.tgz", + "integrity": "sha512-PDRk21MnK70hja/YF8AHfC7yIsiQHn1rcXx7ijCFBX/k+XQJhQT/gw3xekXKJvx+5SXaMMS8oqQy09Mzvz2TuQ==", + "dev": true, + "requires": { + "@types/http-errors": "*", + "@types/mime": "*", + "@types/node": "*" + } + }, "@types/unist": { "version": "2.0.10", "resolved": "https://registry.npmjs.org/@types/unist/-/unist-2.0.10.tgz", diff --git a/package.json b/package.json index 58480422e..42dd3ac3b 100644 --- a/package.json +++ b/package.json @@ -111,6 +111,7 @@ "yauzl": "2.10.0" }, "devDependencies": { + "@types/express": "^4.17.21", "@types/node": "^20.11.19", "cross-env": "7.0.3", "electron": "25.9.8", diff --git a/src/services/log.ts b/src/services/log.ts index 935d695ef..fc7e95187 100644 --- a/src/services/log.ts +++ b/src/services/log.ts @@ -1,6 +1,7 @@ "use strict"; -const fs = require('fs'); +import { Request, Response } from "express"; +import * as fs from "fs"; const dataDir = require('./data_dir.js'); const cls = require('./cls.js'); @@ -8,7 +9,7 @@ if (!fs.existsSync(dataDir.LOG_DIR)) { fs.mkdirSync(dataDir.LOG_DIR, 0o700); } -let logFile = null; +let logFile!: fs.WriteStream; const SECOND = 1000; const MINUTE = 60 * SECOND; @@ -17,7 +18,7 @@ const DAY = 24 * HOUR; const NEW_LINE = process.platform === "win32" ? '\r\n' : '\n'; -let todaysMidnight = null; +let todaysMidnight!: Date; initLogFile(); @@ -39,7 +40,7 @@ function initLogFile() { logFile = fs.createWriteStream(path, {flags: 'a'}); } -function checkDate(millisSinceMidnight) { +function checkDate(millisSinceMidnight: number) { if (millisSinceMidnight >= DAY) { initLogFile(); @@ -49,7 +50,7 @@ function checkDate(millisSinceMidnight) { return millisSinceMidnight; } -function log(str) { +function log(str: string) { const bundleNoteId = cls.get("bundleNoteId"); if (bundleNoteId) { @@ -65,17 +66,17 @@ function log(str) { console.log(str); } -function info(message) { +function info(message: string) { log(message); } -function error(message) { +function error(message: string) { log(`ERROR: ${message}`); } const requestBlacklist = [ "/libraries", "/app", "/images", "/stylesheets", "/api/recent-notes" ]; -function request(req, res, timeMs, responseLength = "?") { +function request(req: Request, res: Response, timeMs: number, responseLength = "?") { for (const bl of requestBlacklist) { if (req.url.startsWith(bl)) { return; @@ -90,13 +91,13 @@ function request(req, res, timeMs, responseLength = "?") { `${res.statusCode} ${req.method} ${req.url} with ${responseLength} bytes took ${timeMs}ms`); } -function pad(num) { +function pad(num: number) { num = Math.floor(num); return num < 10 ? (`0${num}`) : num.toString(); } -function padMilli(num) { +function padMilli(num: number) { if (num < 10) { return `00${num}`; } @@ -108,7 +109,7 @@ function padMilli(num) { } } -function formatTime(millisSinceMidnight) { +function formatTime(millisSinceMidnight: number) { return `${pad(millisSinceMidnight / HOUR)}:${pad((millisSinceMidnight % HOUR) / MINUTE)}:${pad((millisSinceMidnight % MINUTE) / SECOND)}.${padMilli(millisSinceMidnight % SECOND)}`; } diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 000000000..aa6994550 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,14 @@ +{ + "compilerOptions": { + "moduleResolution": "Node", + "declaration": true, + "sourceMap": true, + "outDir": "./build", + "strict": true + }, + "include": [ + "./src/**/*.js", + "./src/**/*.ts" + ], + "exclude": ["./node_modules/**/*"] + } From 981221d599b1c29f93b7057ce21e078ec23f4866 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Fri, 16 Feb 2024 21:03:37 +0200 Subject: [PATCH 04/49] server-ts: data_dir.js -> data_dir.ts --- docker_healthcheck.js | 2 +- src/routes/api/backend_log.js | 2 +- src/routes/session_parser.js | 2 +- src/services/anonymization.js | 2 +- src/services/app_info.js | 2 +- src/services/backup.js | 2 +- src/services/config.js | 2 +- src/services/{data_dir.js => data_dir.ts} | 8 ++++---- src/services/log.ts | 6 +++--- src/services/port.js | 2 +- src/services/session_secret.js | 2 +- src/services/sql.js | 2 +- src/share/sql.js | 2 +- tsconfig.json | 4 +++- 14 files changed, 21 insertions(+), 19 deletions(-) rename src/services/{data_dir.js => data_dir.ts} (93%) diff --git a/docker_healthcheck.js b/docker_healthcheck.js index f483d7a87..8da764043 100755 --- a/docker_healthcheck.js +++ b/docker_healthcheck.js @@ -1,7 +1,7 @@ const http = require("http"); const ini = require("ini"); const fs = require("fs"); -const dataDir = require('./src/services/data_dir.js'); +const dataDir = require('./src/services/data_dir.ts'); const config = ini.parse(fs.readFileSync(dataDir.CONFIG_INI_PATH, 'utf-8')); if (config.Network.https) { diff --git a/src/routes/api/backend_log.js b/src/routes/api/backend_log.js index 51d0cc6a6..a3d4cc37b 100644 --- a/src/routes/api/backend_log.js +++ b/src/routes/api/backend_log.js @@ -2,7 +2,7 @@ const fs = require('fs'); const dateUtils = require('../../services/date_utils.js'); -const {LOG_DIR} = require('../../services/data_dir.js'); +const {LOG_DIR} = require('../../services/data_dir.ts'); function getBackendLog() { const file = `${LOG_DIR}/trilium-${dateUtils.localNowDate()}.log`; diff --git a/src/routes/session_parser.js b/src/routes/session_parser.js index 404159b62..3ae48e356 100644 --- a/src/routes/session_parser.js +++ b/src/routes/session_parser.js @@ -1,6 +1,6 @@ const session = require("express-session"); const sessionSecret = require('../services/session_secret.js'); -const dataDir = require('../services/data_dir.js'); +const dataDir = require('../services/data_dir.ts'); const FileStore = require('session-file-store')(session); const sessionParser = session({ diff --git a/src/services/anonymization.js b/src/services/anonymization.js index 3beb1c1d6..8e79cd496 100644 --- a/src/services/anonymization.js +++ b/src/services/anonymization.js @@ -1,6 +1,6 @@ const BUILTIN_ATTRIBUTES = require('./builtin_attributes.js'); const fs = require("fs-extra"); -const dataDir = require('./data_dir.js'); +const dataDir = require('./data_dir.ts'); const dateUtils = require('./date_utils.js'); const Database = require("better-sqlite3"); const sql = require('./sql.js'); diff --git a/src/services/app_info.js b/src/services/app_info.js index 1d9d7f965..52f7dea7e 100644 --- a/src/services/app_info.js +++ b/src/services/app_info.js @@ -2,7 +2,7 @@ const build = require('./build.js'); const packageJson = require('../../package.json'); -const {TRILIUM_DATA_DIR} = require('./data_dir.js'); +const {TRILIUM_DATA_DIR} = require('./data_dir.ts'); const APP_DB_VERSION = 228; const SYNC_VERSION = 32; diff --git a/src/services/backup.js b/src/services/backup.js index 4796da0cf..9580bef84 100644 --- a/src/services/backup.js +++ b/src/services/backup.js @@ -3,7 +3,7 @@ const dateUtils = require('./date_utils.js'); const optionService = require('./options.js'); const fs = require('fs-extra'); -const dataDir = require('./data_dir.js'); +const dataDir = require('./data_dir.ts'); const log = require('./log.ts'); const syncMutexService = require('./sync_mutex.js'); const cls = require('./cls.js'); diff --git a/src/services/config.js b/src/services/config.js index 2968f1248..3349be88a 100644 --- a/src/services/config.js +++ b/src/services/config.js @@ -2,7 +2,7 @@ const ini = require('ini'); const fs = require('fs'); -const dataDir = require('./data_dir.js'); +const dataDir = require('./data_dir.ts'); const path = require('path'); const resourceDir = require('./resource_dir.js'); diff --git a/src/services/data_dir.js b/src/services/data_dir.ts similarity index 93% rename from src/services/data_dir.js rename to src/services/data_dir.ts index 7971eabf4..5608b265f 100644 --- a/src/services/data_dir.js +++ b/src/services/data_dir.ts @@ -8,14 +8,14 @@ * - as a fallback if the previous step fails, we'll use home dir */ -const os = require('os'); -const fs = require('fs'); -const path = require('path'); +import os = require('os'); +import fs = require('fs'); +import path = require('path'); function getAppDataDir() { let appDataDir = os.homedir(); // fallback if OS is not recognized - if (os.platform() === 'win32') { + if (os.platform() === 'win32' && process.env.APPDATA) { appDataDir = process.env.APPDATA; } else if (os.platform() === 'linux') { diff --git a/src/services/log.ts b/src/services/log.ts index fc7e95187..a07e27124 100644 --- a/src/services/log.ts +++ b/src/services/log.ts @@ -1,9 +1,9 @@ "use strict"; import { Request, Response } from "express"; -import * as fs from "fs"; -const dataDir = require('./data_dir.js'); -const cls = require('./cls.js'); +import fs = require("fs"); +import dataDir = require('./data_dir.ts'); +import cls = require('./cls.js'); if (!fs.existsSync(dataDir.LOG_DIR)) { fs.mkdirSync(dataDir.LOG_DIR, 0o700); diff --git a/src/services/port.js b/src/services/port.js index 938eb3324..2ad054e14 100644 --- a/src/services/port.js +++ b/src/services/port.js @@ -1,7 +1,7 @@ const config = require('./config.js'); const utils = require('./utils.js'); const env = require('./env.js'); -const dataDir = require('./data_dir.js'); +const dataDir = require('./data_dir.ts'); function parseAndValidate(portStr, source) { const portNum = parseInt(portStr); diff --git a/src/services/session_secret.js b/src/services/session_secret.js index 009fae565..711255ab1 100644 --- a/src/services/session_secret.js +++ b/src/services/session_secret.js @@ -2,7 +2,7 @@ const fs = require('fs'); const crypto = require('crypto'); -const dataDir = require('./data_dir.js'); +const dataDir = require('./data_dir.ts'); const log = require('./log.ts'); const sessionSecretPath = `${dataDir.TRILIUM_DATA_DIR}/session_secret.txt`; diff --git a/src/services/sql.js b/src/services/sql.js index 171030d6f..53d7d8d45 100644 --- a/src/services/sql.js +++ b/src/services/sql.js @@ -6,7 +6,7 @@ const log = require('./log.ts'); const Database = require('better-sqlite3'); -const dataDir = require('./data_dir.js'); +const dataDir = require('./data_dir.ts'); const cls = require('./cls.js'); const fs = require("fs-extra"); diff --git a/src/share/sql.js b/src/share/sql.js index 07dd2fd85..1dab6d555 100644 --- a/src/share/sql.js +++ b/src/share/sql.js @@ -1,7 +1,7 @@ "use strict"; const Database = require('better-sqlite3'); -const dataDir = require('../services/data_dir.js'); +const dataDir = require('../services/data_dir.ts'); const dbConnection = new Database(dataDir.DOCUMENT_PATH, { readonly: true }); diff --git a/tsconfig.json b/tsconfig.json index aa6994550..07cb010e9 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,7 +4,9 @@ "declaration": true, "sourceMap": true, "outDir": "./build", - "strict": true + "strict": true, + "allowImportingTsExtensions": true, + "noImplicitAny": true }, "include": [ "./src/**/*.js", From 78f631373b1555c4ade56eb5b3c30cbce828e1eb Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Fri, 16 Feb 2024 21:16:35 +0200 Subject: [PATCH 05/49] server-ts: cls.js -> cls.ts --- src/services/{cls.js => cls.ts} | 21 ++++++++++++--------- src/services/entity_changes.ts | 12 ++++++++++++ 2 files changed, 24 insertions(+), 9 deletions(-) rename src/services/{cls.js => cls.ts} (81%) create mode 100644 src/services/entity_changes.ts diff --git a/src/services/cls.js b/src/services/cls.ts similarity index 81% rename from src/services/cls.js rename to src/services/cls.ts index 8e2c2870c..9fca15f54 100644 --- a/src/services/cls.js +++ b/src/services/cls.ts @@ -1,26 +1,29 @@ -const clsHooked = require('cls-hooked'); +import clsHooked = require('cls-hooked'); +import type entity_changes = require('./entity_changes'); const namespace = clsHooked.createNamespace("trilium"); -function init(callback) { +type Callback = (...args: any[]) => any; + +function init(callback: Callback) { return namespace.runAndReturn(callback); } -function wrap(callback) { +function wrap(callback: Callback) { return () => { try { init(callback); } - catch (e) { + catch (e: any) { console.log(`Error occurred: ${e.message}: ${e.stack}`); } } } -function get(key) { +function get(key: string) { return namespace.get(key); } -function set(key, value) { +function set(key: string, value: any) { namespace.set(key, value); } @@ -48,7 +51,7 @@ function isEntityEventsDisabled() { return !!namespace.get('disableEntityEvents'); } -function setMigrationRunning(running) { +function setMigrationRunning(running: boolean) { namespace.set('migrationRunning', !!running); } @@ -56,7 +59,7 @@ function isMigrationRunning() { return !!namespace.get('migrationRunning'); } -function disableSlowQueryLogging(disable) { +function disableSlowQueryLogging(disable: boolean) { namespace.set('disableSlowQueryLogging', disable); } @@ -72,7 +75,7 @@ function getAndClearEntityChangeIds() { return entityChangeIds; } -function putEntityChange(entityChange) { +function putEntityChange(entityChange: entity_changes.EntityChange) { if (namespace.get('ignoreEntityChangeIds')) { return; } diff --git a/src/services/entity_changes.ts b/src/services/entity_changes.ts new file mode 100644 index 000000000..73f4ff259 --- /dev/null +++ b/src/services/entity_changes.ts @@ -0,0 +1,12 @@ +export interface EntityChange { + id?: string; + entityName: string; + entityId: string; + hash: string; + utcDateChanged: string; + isSynced: boolean | 1 | 0; + isErased: boolean | 1 | 0; + componentId?: string | null; + changeId?: string | null; + instanceId?: string | null; +} From 96b6d17d77256e8f9009ed873fb610ac04f30acc Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Fri, 16 Feb 2024 21:17:33 +0200 Subject: [PATCH 06/49] server-ts: Remove need for 'allowImportingTsExtensions' --- db/migrations/0220__migrate_images_to_attachments.js | 2 +- docker_healthcheck.js | 2 +- src/becca/becca_loader.js | 2 +- src/becca/becca_service.js | 2 +- src/becca/entities/abstract_becca_entity.js | 2 +- src/becca/entities/battachment.js | 2 +- src/becca/entities/bbranch.js | 2 +- src/becca/entities/bnote.js | 2 +- src/becca/similarity.js | 2 +- src/etapi/etapi_utils.js | 2 +- src/routes/api/attributes.js | 2 +- src/routes/api/autocomplete.js | 2 +- src/routes/api/backend_log.js | 2 +- src/routes/api/branches.js | 2 +- src/routes/api/clipper.js | 2 +- src/routes/api/database.js | 2 +- src/routes/api/export.js | 2 +- src/routes/api/files.js | 2 +- src/routes/api/import.js | 2 +- src/routes/api/notes.js | 2 +- src/routes/api/options.js | 2 +- src/routes/api/setup.js | 2 +- src/routes/api/sync.js | 2 +- src/routes/api/tree.js | 2 +- src/routes/custom.js | 2 +- src/routes/error_handlers.js | 2 +- src/routes/index.js | 2 +- src/routes/login.js | 2 +- src/routes/routes.js | 2 +- src/routes/session_parser.js | 2 +- src/services/anonymization.js | 2 +- src/services/app_icon.js | 2 +- src/services/app_info.js | 2 +- src/services/auth.js | 2 +- src/services/backend_script_api.js | 2 +- src/services/backup.js | 4 ++-- src/services/bulk_actions.js | 2 +- src/services/cloning.js | 2 +- src/services/config.js | 2 +- src/services/consistency_checks.js | 2 +- src/services/content_hash.js | 2 +- src/services/encryption/data_encryption.js | 2 +- src/services/entity_changes.js | 2 +- src/services/events.js | 2 +- src/services/export/zip.js | 2 +- src/services/hidden_subtree.js | 2 +- src/services/image.js | 2 +- src/services/import/enex.js | 2 +- src/services/import/zip.js | 2 +- src/services/keyboard_actions.js | 2 +- src/services/log.ts | 2 +- src/services/migration.js | 2 +- src/services/notes.js | 2 +- src/services/options_init.js | 2 +- src/services/port.js | 2 +- src/services/protected_session.js | 2 +- src/services/request.js | 2 +- src/services/resource_dir.js | 2 +- src/services/revisions.js | 2 +- src/services/scheduler.js | 2 +- src/services/script.js | 2 +- src/services/search/expressions/ancestor.js | 2 +- src/services/search/expressions/note_content_fulltext.js | 2 +- src/services/search/services/search.js | 2 +- src/services/session_secret.js | 4 ++-- src/services/setup.js | 2 +- src/services/special_notes.js | 2 +- src/services/sql.js | 4 ++-- src/services/sql_init.js | 2 +- src/services/sync.js | 2 +- src/services/sync_update.js | 2 +- src/services/tree.js | 2 +- src/services/window.js | 2 +- src/services/ws.js | 2 +- src/share/routes.js | 2 +- src/share/shaca/shaca_loader.js | 2 +- src/share/sql.js | 2 +- tsconfig.json | 1 - 78 files changed, 80 insertions(+), 81 deletions(-) diff --git a/db/migrations/0220__migrate_images_to_attachments.js b/db/migrations/0220__migrate_images_to_attachments.js index 400003514..331395914 100644 --- a/db/migrations/0220__migrate_images_to_attachments.js +++ b/db/migrations/0220__migrate_images_to_attachments.js @@ -2,7 +2,7 @@ module.exports = () => { const beccaLoader = require('../../src/becca/becca_loader.js'); const becca = require('../../src/becca/becca.js'); const cls = require('../../src/services/cls.js'); - const log = require('../../src/services/log.ts'); + const log = require('../../src/services/log'); const sql = require('../../src/services/sql.js'); cls.init(() => { diff --git a/docker_healthcheck.js b/docker_healthcheck.js index 8da764043..4c06a2627 100755 --- a/docker_healthcheck.js +++ b/docker_healthcheck.js @@ -1,7 +1,7 @@ const http = require("http"); const ini = require("ini"); const fs = require("fs"); -const dataDir = require('./src/services/data_dir.ts'); +const dataDir = require('./src/services/data_dir'); const config = ini.parse(fs.readFileSync(dataDir.CONFIG_INI_PATH, 'utf-8')); if (config.Network.https) { diff --git a/src/becca/becca_loader.js b/src/becca/becca_loader.js index 75d7ec0c7..98c2b700e 100644 --- a/src/becca/becca_loader.js +++ b/src/becca/becca_loader.js @@ -4,7 +4,7 @@ const sql = require('../services/sql.js'); const eventService = require('../services/events.js'); const becca = require('./becca.js'); const sqlInit = require('../services/sql_init.js'); -const log = require('../services/log.ts'); +const log = require('../services/log'); const BNote = require('./entities/bnote.js'); const BBranch = require('./entities/bbranch.js'); const BAttribute = require('./entities/battribute.js'); diff --git a/src/becca/becca_service.js b/src/becca/becca_service.js index cc0c02632..936c43dcc 100644 --- a/src/becca/becca_service.js +++ b/src/becca/becca_service.js @@ -2,7 +2,7 @@ const becca = require('./becca.js'); const cls = require('../services/cls.js'); -const log = require('../services/log.ts'); +const log = require('../services/log'); function isNotePathArchived(notePath) { const noteId = notePath[notePath.length - 1]; diff --git a/src/becca/entities/abstract_becca_entity.js b/src/becca/entities/abstract_becca_entity.js index 6f05dcf52..c6f99beb4 100644 --- a/src/becca/entities/abstract_becca_entity.js +++ b/src/becca/entities/abstract_becca_entity.js @@ -6,7 +6,7 @@ const entityChangesService = require('../../services/entity_changes.js'); const eventService = require('../../services/events.js'); const dateUtils = require('../../services/date_utils.js'); const cls = require('../../services/cls.js'); -const log = require('../../services/log.ts'); +const log = require('../../services/log'); const protectedSessionService = require('../../services/protected_session.js'); const blobService = require('../../services/blob.js'); diff --git a/src/becca/entities/battachment.js b/src/becca/entities/battachment.js index c8271e391..fedf70411 100644 --- a/src/becca/entities/battachment.js +++ b/src/becca/entities/battachment.js @@ -5,7 +5,7 @@ const dateUtils = require('../../services/date_utils.js'); const AbstractBeccaEntity = require('./abstract_becca_entity.js'); const sql = require('../../services/sql.js'); const protectedSessionService = require('../../services/protected_session.js'); -const log = require('../../services/log.ts'); +const log = require('../../services/log'); const attachmentRoleToNoteTypeMapping = { 'image': 'image' diff --git a/src/becca/entities/bbranch.js b/src/becca/entities/bbranch.js index a8208632a..b5120b0f2 100644 --- a/src/becca/entities/bbranch.js +++ b/src/becca/entities/bbranch.js @@ -6,7 +6,7 @@ const dateUtils = require('../../services/date_utils.js'); const utils = require('../../services/utils.js'); const TaskContext = require('../../services/task_context.js'); const cls = require('../../services/cls.js'); -const log = require('../../services/log.ts'); +const log = require('../../services/log'); /** * Branch represents a relationship between a child note and its parent note. Trilium allows a note to have multiple diff --git a/src/becca/entities/bnote.js b/src/becca/entities/bnote.js index 118ff9976..b11a624d8 100644 --- a/src/becca/entities/bnote.js +++ b/src/becca/entities/bnote.js @@ -1,7 +1,7 @@ "use strict"; const protectedSessionService = require('../../services/protected_session.js'); -const log = require('../../services/log.ts'); +const log = require('../../services/log'); const sql = require('../../services/sql.js'); const utils = require('../../services/utils.js'); const dateUtils = require('../../services/date_utils.js'); diff --git a/src/becca/similarity.js b/src/becca/similarity.js index 9e225ddcf..1a8534e0b 100644 --- a/src/becca/similarity.js +++ b/src/becca/similarity.js @@ -1,5 +1,5 @@ const becca = require('./becca.js'); -const log = require('../services/log.ts'); +const log = require('../services/log'); const beccaService = require('./becca_service.js'); const dateUtils = require('../services/date_utils.js'); const {JSDOM} = require("jsdom"); diff --git a/src/etapi/etapi_utils.js b/src/etapi/etapi_utils.js index 662e36cbb..be8df73e5 100644 --- a/src/etapi/etapi_utils.js +++ b/src/etapi/etapi_utils.js @@ -1,6 +1,6 @@ const cls = require('../services/cls.js'); const sql = require('../services/sql.js'); -const log = require('../services/log.ts'); +const log = require('../services/log'); const becca = require('../becca/becca.js'); const etapiTokenService = require('../services/etapi_tokens.js'); const config = require('../services/config.js'); diff --git a/src/routes/api/attributes.js b/src/routes/api/attributes.js index f96330beb..480cb8b3f 100644 --- a/src/routes/api/attributes.js +++ b/src/routes/api/attributes.js @@ -1,7 +1,7 @@ "use strict"; const sql = require('../../services/sql.js'); -const log = require('../../services/log.ts'); +const log = require('../../services/log'); const attributeService = require('../../services/attributes.js'); const BAttribute = require('../../becca/entities/battribute.js'); const becca = require('../../becca/becca.js'); diff --git a/src/routes/api/autocomplete.js b/src/routes/api/autocomplete.js index 2ea2ca6c9..3d33caa5c 100644 --- a/src/routes/api/autocomplete.js +++ b/src/routes/api/autocomplete.js @@ -2,7 +2,7 @@ const beccaService = require('../../becca/becca_service.js'); const searchService = require('../../services/search/services/search.js'); -const log = require('../../services/log.ts'); +const log = require('../../services/log'); const utils = require('../../services/utils.js'); const cls = require('../../services/cls.js'); const becca = require('../../becca/becca.js'); diff --git a/src/routes/api/backend_log.js b/src/routes/api/backend_log.js index a3d4cc37b..c941bdaeb 100644 --- a/src/routes/api/backend_log.js +++ b/src/routes/api/backend_log.js @@ -2,7 +2,7 @@ const fs = require('fs'); const dateUtils = require('../../services/date_utils.js'); -const {LOG_DIR} = require('../../services/data_dir.ts'); +const {LOG_DIR} = require('../../services/data_dir'); function getBackendLog() { const file = `${LOG_DIR}/trilium-${dateUtils.localNowDate()}.log`; diff --git a/src/routes/api/branches.js b/src/routes/api/branches.js index 337fdc0eb..3447b1e33 100644 --- a/src/routes/api/branches.js +++ b/src/routes/api/branches.js @@ -8,7 +8,7 @@ const eraseService = require('../../services/erase.js'); const becca = require('../../becca/becca.js'); const TaskContext = require('../../services/task_context.js'); const branchService = require('../../services/branches.js'); -const log = require('../../services/log.ts'); +const log = require('../../services/log'); const ValidationError = require('../../errors/validation_error.js'); const eventService = require("../../services/events.js"); diff --git a/src/routes/api/clipper.js b/src/routes/api/clipper.js index 8c38ff72e..052841cf1 100644 --- a/src/routes/api/clipper.js +++ b/src/routes/api/clipper.js @@ -8,7 +8,7 @@ const dateUtils = require('../../services/date_utils.js'); const imageService = require('../../services/image.js'); const appInfo = require('../../services/app_info.js'); const ws = require('../../services/ws.js'); -const log = require('../../services/log.ts'); +const log = require('../../services/log'); const utils = require('../../services/utils.js'); const path = require('path'); const htmlSanitizer = require('../../services/html_sanitizer.js'); diff --git a/src/routes/api/database.js b/src/routes/api/database.js index a09750a45..6d6fcddf4 100644 --- a/src/routes/api/database.js +++ b/src/routes/api/database.js @@ -1,7 +1,7 @@ "use strict"; const sql = require('../../services/sql.js'); -const log = require('../../services/log.ts'); +const log = require('../../services/log'); const backupService = require('../../services/backup.js'); const anonymizationService = require('../../services/anonymization.js'); const consistencyChecksService = require('../../services/consistency_checks.js'); diff --git a/src/routes/api/export.js b/src/routes/api/export.js index 9a7323adb..673d7c7bf 100644 --- a/src/routes/api/export.js +++ b/src/routes/api/export.js @@ -5,7 +5,7 @@ const singleExportService = require('../../services/export/single.js'); const opmlExportService = require('../../services/export/opml.js'); const becca = require('../../becca/becca.js'); const TaskContext = require('../../services/task_context.js'); -const log = require('../../services/log.ts'); +const log = require('../../services/log'); const NotFoundError = require('../../errors/not_found_error.js'); function exportBranch(req, res) { diff --git a/src/routes/api/files.js b/src/routes/api/files.js index 43e64760d..60e9aba19 100644 --- a/src/routes/api/files.js +++ b/src/routes/api/files.js @@ -2,7 +2,7 @@ const protectedSessionService = require('../../services/protected_session.js'); const utils = require('../../services/utils.js'); -const log = require('../../services/log.ts'); +const log = require('../../services/log'); const noteService = require('../../services/notes.js'); const tmp = require('tmp'); const fs = require('fs'); diff --git a/src/routes/api/import.js b/src/routes/api/import.js index 2a9d8a594..025fb8301 100644 --- a/src/routes/api/import.js +++ b/src/routes/api/import.js @@ -8,7 +8,7 @@ const cls = require('../../services/cls.js'); const path = require('path'); const becca = require('../../becca/becca.js'); const beccaLoader = require('../../becca/becca_loader.js'); -const log = require('../../services/log.ts'); +const log = require('../../services/log'); const TaskContext = require('../../services/task_context.js'); const ValidationError = require('../../errors/validation_error.js'); diff --git a/src/routes/api/notes.js b/src/routes/api/notes.js index d5693c137..f2c49e325 100644 --- a/src/routes/api/notes.js +++ b/src/routes/api/notes.js @@ -5,7 +5,7 @@ const eraseService = require('../../services/erase.js'); const treeService = require('../../services/tree.js'); const sql = require('../../services/sql.js'); const utils = require('../../services/utils.js'); -const log = require('../../services/log.ts'); +const log = require('../../services/log'); const TaskContext = require('../../services/task_context.js'); const becca = require('../../becca/becca.js'); const ValidationError = require('../../errors/validation_error.js'); diff --git a/src/routes/api/options.js b/src/routes/api/options.js index 741634940..52344891a 100644 --- a/src/routes/api/options.js +++ b/src/routes/api/options.js @@ -1,7 +1,7 @@ "use strict"; const optionService = require('../../services/options.js'); -const log = require('../../services/log.ts'); +const log = require('../../services/log'); const searchService = require('../../services/search/services/search.js'); const ValidationError = require('../../errors/validation_error.js'); diff --git a/src/routes/api/setup.js b/src/routes/api/setup.js index a094b639c..bd328509f 100644 --- a/src/routes/api/setup.js +++ b/src/routes/api/setup.js @@ -2,7 +2,7 @@ const sqlInit = require('../../services/sql_init.js'); const setupService = require('../../services/setup.js'); -const log = require('../../services/log.ts'); +const log = require('../../services/log'); const appInfo = require('../../services/app_info.js'); function getStatus() { diff --git a/src/routes/api/sync.js b/src/routes/api/sync.js index cfe1afd88..859de6d53 100644 --- a/src/routes/api/sync.js +++ b/src/routes/api/sync.js @@ -7,7 +7,7 @@ const sql = require('../../services/sql.js'); const sqlInit = require('../../services/sql_init.js'); const optionService = require('../../services/options.js'); const contentHashService = require('../../services/content_hash.js'); -const log = require('../../services/log.ts'); +const log = require('../../services/log'); const syncOptions = require('../../services/sync_options.js'); const utils = require('../../services/utils.js'); const ws = require('../../services/ws.js'); diff --git a/src/routes/api/tree.js b/src/routes/api/tree.js index 7162e13ba..f830ed8f1 100644 --- a/src/routes/api/tree.js +++ b/src/routes/api/tree.js @@ -1,7 +1,7 @@ "use strict"; const becca = require('../../becca/becca.js'); -const log = require('../../services/log.ts'); +const log = require('../../services/log'); const NotFoundError = require('../../errors/not_found_error.js'); function getNotesAndBranchesAndAttributes(noteIds) { diff --git a/src/routes/custom.js b/src/routes/custom.js index 1506244d3..7352cb7f9 100644 --- a/src/routes/custom.js +++ b/src/routes/custom.js @@ -1,4 +1,4 @@ -const log = require('../services/log.ts'); +const log = require('../services/log'); const fileService = require('./api/files.js'); const scriptService = require('../services/script.js'); const cls = require('../services/cls.js'); diff --git a/src/routes/error_handlers.js b/src/routes/error_handlers.js index 441da4b67..4d17b0d5d 100644 --- a/src/routes/error_handlers.js +++ b/src/routes/error_handlers.js @@ -1,4 +1,4 @@ -const log = require('../services/log.ts'); +const log = require('../services/log'); function register(app) { app.use((err, req, res, next) => { diff --git a/src/routes/index.js b/src/routes/index.js index 7544a8bc6..92de411c4 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -4,7 +4,7 @@ const sql = require('../services/sql.js'); const attributeService = require('../services/attributes.js'); const config = require('../services/config.js'); const optionService = require('../services/options.js'); -const log = require('../services/log.ts'); +const log = require('../services/log'); const env = require('../services/env.js'); const utils = require('../services/utils.js'); const protectedSessionService = require('../services/protected_session.js'); diff --git a/src/routes/login.js b/src/routes/login.js index 181eedc0d..15a9a9684 100644 --- a/src/routes/login.js +++ b/src/routes/login.js @@ -3,7 +3,7 @@ const utils = require('../services/utils.js'); const optionService = require('../services/options.js'); const myScryptService = require('../services/encryption/my_scrypt.js'); -const log = require('../services/log.ts'); +const log = require('../services/log'); const passwordService = require('../services/encryption/password.js'); const assetPath = require('../services/asset_path.js'); const appPath = require('../services/app_path.js'); diff --git a/src/routes/routes.js b/src/routes/routes.js index 3c46763c3..081a94353 100644 --- a/src/routes/routes.js +++ b/src/routes/routes.js @@ -2,7 +2,7 @@ const utils = require('../services/utils.js'); const multer = require('multer'); -const log = require('../services/log.ts'); +const log = require('../services/log'); const express = require('express'); const router = express.Router(); const auth = require('../services/auth.js'); diff --git a/src/routes/session_parser.js b/src/routes/session_parser.js index 3ae48e356..a2e62e851 100644 --- a/src/routes/session_parser.js +++ b/src/routes/session_parser.js @@ -1,6 +1,6 @@ const session = require("express-session"); const sessionSecret = require('../services/session_secret.js'); -const dataDir = require('../services/data_dir.ts'); +const dataDir = require('../services/data_dir'); const FileStore = require('session-file-store')(session); const sessionParser = session({ diff --git a/src/services/anonymization.js b/src/services/anonymization.js index 8e79cd496..792d83c9c 100644 --- a/src/services/anonymization.js +++ b/src/services/anonymization.js @@ -1,6 +1,6 @@ const BUILTIN_ATTRIBUTES = require('./builtin_attributes.js'); const fs = require("fs-extra"); -const dataDir = require('./data_dir.ts'); +const dataDir = require('./data_dir'); const dateUtils = require('./date_utils.js'); const Database = require("better-sqlite3"); const sql = require('./sql.js'); diff --git a/src/services/app_icon.js b/src/services/app_icon.js index 04f9d034d..784850508 100644 --- a/src/services/app_icon.js +++ b/src/services/app_icon.js @@ -2,7 +2,7 @@ const path = require('path'); const {ELECTRON_APP_ROOT_DIR} = require('./resource_dir.js'); -const log = require('./log.ts'); +const log = require('./log'); const os = require('os'); const fs = require('fs'); const config = require('./config.js'); diff --git a/src/services/app_info.js b/src/services/app_info.js index 52f7dea7e..1d419a4bf 100644 --- a/src/services/app_info.js +++ b/src/services/app_info.js @@ -2,7 +2,7 @@ const build = require('./build.js'); const packageJson = require('../../package.json'); -const {TRILIUM_DATA_DIR} = require('./data_dir.ts'); +const {TRILIUM_DATA_DIR} = require('./data_dir'); const APP_DB_VERSION = 228; const SYNC_VERSION = 32; diff --git a/src/services/auth.js b/src/services/auth.js index cb31a9889..e16fa9ba5 100644 --- a/src/services/auth.js +++ b/src/services/auth.js @@ -1,7 +1,7 @@ "use strict"; const etapiTokenService = require('./etapi_tokens.js'); -const log = require('./log.ts'); +const log = require('./log'); const sqlInit = require('./sql_init.js'); const utils = require('./utils.js'); const passwordEncryptionService = require('./encryption/password_encryption.js'); diff --git a/src/services/backend_script_api.js b/src/services/backend_script_api.js index 36d1fb915..12732d6a0 100644 --- a/src/services/backend_script_api.js +++ b/src/services/backend_script_api.js @@ -1,4 +1,4 @@ -const log = require('./log.ts'); +const log = require('./log'); const noteService = require('./notes.js'); const sql = require('./sql.js'); const utils = require('./utils.js'); diff --git a/src/services/backup.js b/src/services/backup.js index 9580bef84..58c8570b2 100644 --- a/src/services/backup.js +++ b/src/services/backup.js @@ -3,8 +3,8 @@ const dateUtils = require('./date_utils.js'); const optionService = require('./options.js'); const fs = require('fs-extra'); -const dataDir = require('./data_dir.ts'); -const log = require('./log.ts'); +const dataDir = require('./data_dir'); +const log = require('./log'); const syncMutexService = require('./sync_mutex.js'); const cls = require('./cls.js'); const sql = require('./sql.js'); diff --git a/src/services/bulk_actions.js b/src/services/bulk_actions.js index 14ff03ccd..38f649723 100644 --- a/src/services/bulk_actions.js +++ b/src/services/bulk_actions.js @@ -1,4 +1,4 @@ -const log = require('./log.ts'); +const log = require('./log'); const revisionService = require('./revisions.js'); const becca = require('../becca/becca.js'); const cloningService = require('./cloning.js'); diff --git a/src/services/cloning.js b/src/services/cloning.js index 1181983ac..6c2f0c161 100644 --- a/src/services/cloning.js +++ b/src/services/cloning.js @@ -5,7 +5,7 @@ const eventChangesService = require('./entity_changes.js'); const treeService = require('./tree.js'); const BBranch = require('../becca/entities/bbranch.js'); const becca = require('../becca/becca.js'); -const log = require('./log.ts'); +const log = require('./log'); function cloneNoteToParentNote(noteId, parentNoteId, prefix = null) { if (!(noteId in becca.notes) || !(parentNoteId in becca.notes)) { diff --git a/src/services/config.js b/src/services/config.js index 3349be88a..c57942a8c 100644 --- a/src/services/config.js +++ b/src/services/config.js @@ -2,7 +2,7 @@ const ini = require('ini'); const fs = require('fs'); -const dataDir = require('./data_dir.ts'); +const dataDir = require('./data_dir'); const path = require('path'); const resourceDir = require('./resource_dir.js'); diff --git a/src/services/consistency_checks.js b/src/services/consistency_checks.js index 901a54dbd..54ca3eed3 100644 --- a/src/services/consistency_checks.js +++ b/src/services/consistency_checks.js @@ -2,7 +2,7 @@ const sql = require('./sql.js'); const sqlInit = require('./sql_init.js'); -const log = require('./log.ts'); +const log = require('./log'); const ws = require('./ws.js'); const syncMutexService = require('./sync_mutex.js'); const cls = require('./cls.js'); diff --git a/src/services/content_hash.js b/src/services/content_hash.js index 2858b3cac..0251e0cd6 100644 --- a/src/services/content_hash.js +++ b/src/services/content_hash.js @@ -2,7 +2,7 @@ const sql = require('./sql.js'); const utils = require('./utils.js'); -const log = require('./log.ts'); +const log = require('./log'); const eraseService = require('./erase.js'); function getEntityHashes() { diff --git a/src/services/encryption/data_encryption.js b/src/services/encryption/data_encryption.js index fcd5c2f36..2b18058c5 100644 --- a/src/services/encryption/data_encryption.js +++ b/src/services/encryption/data_encryption.js @@ -1,7 +1,7 @@ "use strict"; const crypto = require('crypto'); -const log = require('../log.ts'); +const log = require('../log'); function arraysIdentical(a, b) { let i = a.length; diff --git a/src/services/entity_changes.js b/src/services/entity_changes.js index 19c154a50..dcd93d2d0 100644 --- a/src/services/entity_changes.js +++ b/src/services/entity_changes.js @@ -1,6 +1,6 @@ const sql = require('./sql.js'); const dateUtils = require('./date_utils.js'); -const log = require('./log.ts'); +const log = require('./log'); const cls = require('./cls.js'); const utils = require('./utils.js'); const instanceId = require('./instance_id.js'); diff --git a/src/services/events.js b/src/services/events.js index 849af3c52..51c30be17 100644 --- a/src/services/events.js +++ b/src/services/events.js @@ -1,4 +1,4 @@ -const log = require('./log.ts'); +const log = require('./log'); const NOTE_TITLE_CHANGED = "NOTE_TITLE_CHANGED"; const ENTER_PROTECTED_SESSION = "ENTER_PROTECTED_SESSION"; diff --git a/src/services/export/zip.js b/src/services/export/zip.js index 87ee4d4e4..153b05f58 100644 --- a/src/services/export/zip.js +++ b/src/services/export/zip.js @@ -13,7 +13,7 @@ const fs = require("fs"); const becca = require('../../becca/becca.js'); const RESOURCE_DIR = require('../../services/resource_dir.js').RESOURCE_DIR; const archiver = require('archiver'); -const log = require('../log.ts'); +const log = require('../log'); const TaskContext = require('../task_context.js'); const ValidationError = require('../../errors/validation_error.js'); const NoteMeta = require('../meta/note_meta.js'); diff --git a/src/services/hidden_subtree.js b/src/services/hidden_subtree.js index d96c73b1f..2e00a2461 100644 --- a/src/services/hidden_subtree.js +++ b/src/services/hidden_subtree.js @@ -1,7 +1,7 @@ const becca = require('../becca/becca.js'); const noteService = require('./notes.js'); const BAttribute = require('../becca/entities/battribute.js'); -const log = require('./log.ts'); +const log = require('./log'); const migrationService = require('./migration.js'); const LBTPL_ROOT = "_lbTplRoot"; diff --git a/src/services/image.js b/src/services/image.js index ee795ebd8..8ef302708 100644 --- a/src/services/image.js +++ b/src/services/image.js @@ -1,7 +1,7 @@ "use strict"; const becca = require('../becca/becca.js'); -const log = require('./log.ts'); +const log = require('./log'); const protectedSessionService = require('./protected_session.js'); const noteService = require('./notes.js'); const optionService = require('./options.js'); diff --git a/src/services/import/enex.js b/src/services/import/enex.js index 73d0da225..50f0c5549 100644 --- a/src/services/import/enex.js +++ b/src/services/import/enex.js @@ -1,7 +1,7 @@ const sax = require("sax"); const stream = require('stream'); const {Throttle} = require('stream-throttle'); -const log = require('../log.ts'); +const log = require('../log'); const utils = require('../utils.js'); const sql = require('../sql.js'); const noteService = require('../notes.js'); diff --git a/src/services/import/zip.js b/src/services/import/zip.js index 7b12130c8..0df5fff4c 100644 --- a/src/services/import/zip.js +++ b/src/services/import/zip.js @@ -2,7 +2,7 @@ const BAttribute = require('../../becca/entities/battribute.js'); const utils = require('../../services/utils.js'); -const log = require('../../services/log.ts'); +const log = require('../../services/log'); const noteService = require('../../services/notes.js'); const attributeService = require('../../services/attributes.js'); const BBranch = require('../../becca/entities/bbranch.js'); diff --git a/src/services/keyboard_actions.js b/src/services/keyboard_actions.js index bcc8b3cd9..697d1f4c7 100644 --- a/src/services/keyboard_actions.js +++ b/src/services/keyboard_actions.js @@ -1,7 +1,7 @@ "use strict"; const optionService = require('./options.js'); -const log = require('./log.ts'); +const log = require('./log'); const utils = require('./utils.js'); const isMac = process.platform === "darwin"; diff --git a/src/services/log.ts b/src/services/log.ts index a07e27124..ce59b1530 100644 --- a/src/services/log.ts +++ b/src/services/log.ts @@ -2,7 +2,7 @@ import { Request, Response } from "express"; import fs = require("fs"); -import dataDir = require('./data_dir.ts'); +import dataDir = require('./data_dir'); import cls = require('./cls.js'); if (!fs.existsSync(dataDir.LOG_DIR)) { diff --git a/src/services/migration.js b/src/services/migration.js index 8dce4c755..d0b48651d 100644 --- a/src/services/migration.js +++ b/src/services/migration.js @@ -1,7 +1,7 @@ const backupService = require('./backup.js'); const sql = require('./sql.js'); const fs = require('fs-extra'); -const log = require('./log.ts'); +const log = require('./log'); const utils = require('./utils.js'); const resourceDir = require('./resource_dir.js'); const appInfo = require('./app_info.js'); diff --git a/src/services/notes.js b/src/services/notes.js index d699502e8..977a8f4f7 100644 --- a/src/services/notes.js +++ b/src/services/notes.js @@ -5,7 +5,7 @@ const entityChangesService = require('./entity_changes.js'); const eventService = require('./events.js'); const cls = require('../services/cls.js'); const protectedSessionService = require('../services/protected_session.js'); -const log = require('../services/log.ts'); +const log = require('../services/log'); const utils = require('../services/utils.js'); const revisionService = require('./revisions.js'); const request = require('./request.js'); diff --git a/src/services/options_init.js b/src/services/options_init.js index 9f3add64b..46dca53e2 100644 --- a/src/services/options_init.js +++ b/src/services/options_init.js @@ -1,7 +1,7 @@ const optionService = require('./options.js'); const appInfo = require('./app_info.js'); const utils = require('./utils.js'); -const log = require('./log.ts'); +const log = require('./log'); const dateUtils = require('./date_utils.js'); const keyboardActions = require('./keyboard_actions.js'); diff --git a/src/services/port.js b/src/services/port.js index 2ad054e14..fe31eec35 100644 --- a/src/services/port.js +++ b/src/services/port.js @@ -1,7 +1,7 @@ const config = require('./config.js'); const utils = require('./utils.js'); const env = require('./env.js'); -const dataDir = require('./data_dir.ts'); +const dataDir = require('./data_dir'); function parseAndValidate(portStr, source) { const portNum = parseInt(portStr); diff --git a/src/services/protected_session.js b/src/services/protected_session.js index c1d6b0986..fad80c035 100644 --- a/src/services/protected_session.js +++ b/src/services/protected_session.js @@ -1,6 +1,6 @@ "use strict"; -const log = require('./log.ts'); +const log = require('./log'); const dataEncryptionService = require('./encryption/data_encryption.js'); let dataKey = null; diff --git a/src/services/request.js b/src/services/request.js index 696f41939..158495779 100644 --- a/src/services/request.js +++ b/src/services/request.js @@ -1,7 +1,7 @@ "use strict"; const utils = require('./utils.js'); -const log = require('./log.ts'); +const log = require('./log'); const url = require('url'); const syncOptions = require('./sync_options.js'); diff --git a/src/services/resource_dir.js b/src/services/resource_dir.js index cbf1dea91..4f3710e18 100644 --- a/src/services/resource_dir.js +++ b/src/services/resource_dir.js @@ -1,4 +1,4 @@ -const log = require('./log.ts'); +const log = require('./log'); const path = require('path'); const fs = require('fs'); diff --git a/src/services/revisions.js b/src/services/revisions.js index 8cdff23a8..5735ceb79 100644 --- a/src/services/revisions.js +++ b/src/services/revisions.js @@ -1,6 +1,6 @@ "use strict"; -const log = require('./log.ts'); +const log = require('./log'); const sql = require('./sql.js'); const protectedSessionService = require('./protected_session.js'); const dateUtils = require('./date_utils.js'); diff --git a/src/services/scheduler.js b/src/services/scheduler.js index 6f7dc25fb..1e03a3d34 100644 --- a/src/services/scheduler.js +++ b/src/services/scheduler.js @@ -2,7 +2,7 @@ const scriptService = require('./script.js'); const cls = require('./cls.js'); const sqlInit = require('./sql_init.js'); const config = require('./config.js'); -const log = require('./log.ts'); +const log = require('./log'); const attributeService = require('../services/attributes.js'); const protectedSessionService = require('../services/protected_session.js'); const hiddenSubtreeService = require('./hidden_subtree.js'); diff --git a/src/services/script.js b/src/services/script.js index 4c26a37f7..24ff7f04a 100644 --- a/src/services/script.js +++ b/src/services/script.js @@ -1,6 +1,6 @@ const ScriptContext = require('./script_context.js'); const cls = require('./cls.js'); -const log = require('./log.ts'); +const log = require('./log'); const becca = require('../becca/becca.js'); function executeNote(note, apiParams) { diff --git a/src/services/search/expressions/ancestor.js b/src/services/search/expressions/ancestor.js index d1d93eed2..f7463a3ae 100644 --- a/src/services/search/expressions/ancestor.js +++ b/src/services/search/expressions/ancestor.js @@ -2,7 +2,7 @@ const Expression = require('./expression.js'); const NoteSet = require('../note_set.js'); -const log = require('../../log.ts'); +const log = require('../../log'); const becca = require('../../../becca/becca.js'); class AncestorExp extends Expression { diff --git a/src/services/search/expressions/note_content_fulltext.js b/src/services/search/expressions/note_content_fulltext.js index b4c90005f..f9eac3699 100644 --- a/src/services/search/expressions/note_content_fulltext.js +++ b/src/services/search/expressions/note_content_fulltext.js @@ -2,7 +2,7 @@ const Expression = require('./expression.js'); const NoteSet = require('../note_set.js'); -const log = require('../../log.ts'); +const log = require('../../log'); const becca = require('../../../becca/becca.js'); const protectedSessionService = require('../../protected_session.js'); const striptags = require('striptags'); diff --git a/src/services/search/services/search.js b/src/services/search/services/search.js index 68ab55226..ac794e7d0 100644 --- a/src/services/search/services/search.js +++ b/src/services/search/services/search.js @@ -9,7 +9,7 @@ const SearchContext = require('../search_context.js'); const becca = require('../../../becca/becca.js'); const beccaService = require('../../../becca/becca_service.js'); const utils = require('../../utils.js'); -const log = require('../../log.ts'); +const log = require('../../log'); const hoistedNoteService = require('../../hoisted_note.js'); function searchFromNote(note) { diff --git a/src/services/session_secret.js b/src/services/session_secret.js index 711255ab1..16c1ed8c3 100644 --- a/src/services/session_secret.js +++ b/src/services/session_secret.js @@ -2,8 +2,8 @@ const fs = require('fs'); const crypto = require('crypto'); -const dataDir = require('./data_dir.ts'); -const log = require('./log.ts'); +const dataDir = require('./data_dir'); +const log = require('./log'); const sessionSecretPath = `${dataDir.TRILIUM_DATA_DIR}/session_secret.txt`; diff --git a/src/services/setup.js b/src/services/setup.js index 6c7156ebc..1bebad29a 100644 --- a/src/services/setup.js +++ b/src/services/setup.js @@ -1,5 +1,5 @@ const syncService = require('./sync.js'); -const log = require('./log.ts'); +const log = require('./log'); const sqlInit = require('./sql_init.js'); const optionService = require('./options.js'); const syncOptions = require('./sync_options.js'); diff --git a/src/services/special_notes.js b/src/services/special_notes.js index 09ce82a69..8d9c2baa1 100644 --- a/src/services/special_notes.js +++ b/src/services/special_notes.js @@ -3,7 +3,7 @@ const dateNoteService = require('./date_notes.js'); const becca = require('../becca/becca.js'); const noteService = require('./notes.js'); const dateUtils = require('./date_utils.js'); -const log = require('./log.ts'); +const log = require('./log'); const hoistedNoteService = require('./hoisted_note.js'); const searchService = require('./search/services/search.js'); const SearchContext = require('./search/search_context.js'); diff --git a/src/services/sql.js b/src/services/sql.js index 53d7d8d45..3b165d4d6 100644 --- a/src/services/sql.js +++ b/src/services/sql.js @@ -4,9 +4,9 @@ * @module sql */ -const log = require('./log.ts'); +const log = require('./log'); const Database = require('better-sqlite3'); -const dataDir = require('./data_dir.ts'); +const dataDir = require('./data_dir'); const cls = require('./cls.js'); const fs = require("fs-extra"); diff --git a/src/services/sql_init.js b/src/services/sql_init.js index 572334f13..7b348dd8b 100644 --- a/src/services/sql_init.js +++ b/src/services/sql_init.js @@ -1,4 +1,4 @@ -const log = require('./log.ts'); +const log = require('./log'); const fs = require('fs'); const resourceDir = require('./resource_dir.js'); const sql = require('./sql.js'); diff --git a/src/services/sync.js b/src/services/sync.js index 7d64cac57..8326bd1d8 100644 --- a/src/services/sync.js +++ b/src/services/sync.js @@ -1,6 +1,6 @@ "use strict"; -const log = require('./log.ts'); +const log = require('./log'); const sql = require('./sql.js'); const optionService = require('./options.js'); const utils = require('./utils.js'); diff --git a/src/services/sync_update.js b/src/services/sync_update.js index 3a1577971..f9695ba0c 100644 --- a/src/services/sync_update.js +++ b/src/services/sync_update.js @@ -1,5 +1,5 @@ const sql = require('./sql.js'); -const log = require('./log.ts'); +const log = require('./log'); const entityChangesService = require('./entity_changes.js'); const eventService = require('./events.js'); const entityConstructor = require('../becca/entity_constructor.js'); diff --git a/src/services/tree.js b/src/services/tree.js index 239a9ab35..0ca25c536 100644 --- a/src/services/tree.js +++ b/src/services/tree.js @@ -1,7 +1,7 @@ "use strict"; const sql = require('./sql.js'); -const log = require('./log.ts'); +const log = require('./log'); const BBranch = require('../becca/entities/bbranch.js'); const entityChangesService = require('./entity_changes.js'); const becca = require('../becca/becca.js'); diff --git a/src/services/window.js b/src/services/window.js index 97a60db91..8468e048c 100644 --- a/src/services/window.js +++ b/src/services/window.js @@ -3,7 +3,7 @@ const url = require("url"); const port = require('./port.js'); const optionService = require('./options.js'); const env = require('./env.js'); -const log = require('./log.ts'); +const log = require('./log'); const sqlInit = require('./sql_init.js'); const cls = require('./cls.js'); const keyboardActionsService = require('./keyboard_actions.js'); diff --git a/src/services/ws.js b/src/services/ws.js index 759e0823c..85628b235 100644 --- a/src/services/ws.js +++ b/src/services/ws.js @@ -1,6 +1,6 @@ const WebSocket = require('ws'); const utils = require('./utils.js'); -const log = require('./log.ts'); +const log = require('./log'); const sql = require('./sql.js'); const cls = require('./cls.js'); const config = require('./config.js'); diff --git a/src/share/routes.js b/src/share/routes.js index 95d6c1a9f..5db054011 100644 --- a/src/share/routes.js +++ b/src/share/routes.js @@ -11,7 +11,7 @@ const assetPath = require('../services/asset_path.js'); const appPath = require('../services/app_path.js'); const searchService = require('../services/search/services/search.js'); const SearchContext = require('../services/search/search_context.js'); -const log = require('../services/log.ts'); +const log = require('../services/log'); /** * @param {SNote} note diff --git a/src/share/shaca/shaca_loader.js b/src/share/shaca/shaca_loader.js index 83c755e36..850b820a4 100644 --- a/src/share/shaca/shaca_loader.js +++ b/src/share/shaca/shaca_loader.js @@ -2,7 +2,7 @@ const sql = require('../sql.js'); const shaca = require('./shaca.js'); -const log = require('../../services/log.ts'); +const log = require('../../services/log'); const SNote = require('./entities/snote.js'); const SBranch = require('./entities/sbranch.js'); const SAttribute = require('./entities/sattribute.js'); diff --git a/src/share/sql.js b/src/share/sql.js index 1dab6d555..485c87921 100644 --- a/src/share/sql.js +++ b/src/share/sql.js @@ -1,7 +1,7 @@ "use strict"; const Database = require('better-sqlite3'); -const dataDir = require('../services/data_dir.ts'); +const dataDir = require('../services/data_dir'); const dbConnection = new Database(dataDir.DOCUMENT_PATH, { readonly: true }); diff --git a/tsconfig.json b/tsconfig.json index 07cb010e9..7f94100dc 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,7 +5,6 @@ "sourceMap": true, "outDir": "./build", "strict": true, - "allowImportingTsExtensions": true, "noImplicitAny": true }, "include": [ From ff2e05fe832b22112650fb4b9f59b1383df9e541 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Fri, 16 Feb 2024 21:18:38 +0200 Subject: [PATCH 07/49] server-ts: Fix references to cls.js --- db/migrations/0220__migrate_images_to_attachments.js | 2 +- src/becca/becca_loader.js | 2 +- src/becca/becca_service.js | 2 +- src/becca/entities/abstract_becca_entity.js | 2 +- src/becca/entities/bbranch.js | 2 +- src/etapi/etapi_utils.js | 2 +- src/routes/api/autocomplete.js | 2 +- src/routes/api/import.js | 2 +- src/routes/api/revisions.js | 2 +- src/routes/api/search.js | 2 +- src/routes/api/special_notes.js | 2 +- src/routes/custom.js | 2 +- src/routes/routes.js | 2 +- src/services/backup.js | 2 +- src/services/consistency_checks.js | 2 +- src/services/date_utils.js | 2 +- src/services/entity_changes.js | 2 +- src/services/erase.js | 2 +- src/services/hoisted_note.js | 2 +- src/services/log.ts | 2 +- src/services/migration.js | 2 +- src/services/notes.js | 2 +- src/services/scheduler.js | 2 +- src/services/script.js | 2 +- src/services/sql.js | 2 +- src/services/sql_init.js | 2 +- src/services/sync.js | 2 +- src/services/window.js | 2 +- src/services/ws.js | 2 +- src/tools/generate_document.js | 2 +- 30 files changed, 30 insertions(+), 30 deletions(-) diff --git a/db/migrations/0220__migrate_images_to_attachments.js b/db/migrations/0220__migrate_images_to_attachments.js index 331395914..81bb84a3f 100644 --- a/db/migrations/0220__migrate_images_to_attachments.js +++ b/db/migrations/0220__migrate_images_to_attachments.js @@ -1,7 +1,7 @@ module.exports = () => { const beccaLoader = require('../../src/becca/becca_loader.js'); const becca = require('../../src/becca/becca.js'); - const cls = require('../../src/services/cls.js'); + const cls = require('../../src/services/cls'); const log = require('../../src/services/log'); const sql = require('../../src/services/sql.js'); diff --git a/src/becca/becca_loader.js b/src/becca/becca_loader.js index 98c2b700e..39989090e 100644 --- a/src/becca/becca_loader.js +++ b/src/becca/becca_loader.js @@ -10,7 +10,7 @@ const BBranch = require('./entities/bbranch.js'); const BAttribute = require('./entities/battribute.js'); const BOption = require('./entities/boption.js'); const BEtapiToken = require('./entities/betapi_token.js'); -const cls = require('../services/cls.js'); +const cls = require('../services/cls'); const entityConstructor = require('../becca/entity_constructor.js'); const beccaLoaded = new Promise((res, rej) => { diff --git a/src/becca/becca_service.js b/src/becca/becca_service.js index 936c43dcc..0d7e3193f 100644 --- a/src/becca/becca_service.js +++ b/src/becca/becca_service.js @@ -1,7 +1,7 @@ "use strict"; const becca = require('./becca.js'); -const cls = require('../services/cls.js'); +const cls = require('../services/cls'); const log = require('../services/log'); function isNotePathArchived(notePath) { diff --git a/src/becca/entities/abstract_becca_entity.js b/src/becca/entities/abstract_becca_entity.js index c6f99beb4..9cd0dad76 100644 --- a/src/becca/entities/abstract_becca_entity.js +++ b/src/becca/entities/abstract_becca_entity.js @@ -5,7 +5,7 @@ const sql = require('../../services/sql.js'); const entityChangesService = require('../../services/entity_changes.js'); const eventService = require('../../services/events.js'); const dateUtils = require('../../services/date_utils.js'); -const cls = require('../../services/cls.js'); +const cls = require('../../services/cls'); const log = require('../../services/log'); const protectedSessionService = require('../../services/protected_session.js'); const blobService = require('../../services/blob.js'); diff --git a/src/becca/entities/bbranch.js b/src/becca/entities/bbranch.js index b5120b0f2..3ee42e510 100644 --- a/src/becca/entities/bbranch.js +++ b/src/becca/entities/bbranch.js @@ -5,7 +5,7 @@ const AbstractBeccaEntity = require('./abstract_becca_entity.js'); const dateUtils = require('../../services/date_utils.js'); const utils = require('../../services/utils.js'); const TaskContext = require('../../services/task_context.js'); -const cls = require('../../services/cls.js'); +const cls = require('../../services/cls'); const log = require('../../services/log'); /** diff --git a/src/etapi/etapi_utils.js b/src/etapi/etapi_utils.js index be8df73e5..24c179a23 100644 --- a/src/etapi/etapi_utils.js +++ b/src/etapi/etapi_utils.js @@ -1,4 +1,4 @@ -const cls = require('../services/cls.js'); +const cls = require('../services/cls'); const sql = require('../services/sql.js'); const log = require('../services/log'); const becca = require('../becca/becca.js'); diff --git a/src/routes/api/autocomplete.js b/src/routes/api/autocomplete.js index 3d33caa5c..983576b8c 100644 --- a/src/routes/api/autocomplete.js +++ b/src/routes/api/autocomplete.js @@ -4,7 +4,7 @@ const beccaService = require('../../becca/becca_service.js'); const searchService = require('../../services/search/services/search.js'); const log = require('../../services/log'); const utils = require('../../services/utils.js'); -const cls = require('../../services/cls.js'); +const cls = require('../../services/cls'); const becca = require('../../becca/becca.js'); function getAutocomplete(req) { diff --git a/src/routes/api/import.js b/src/routes/api/import.js index 025fb8301..9a29b7a7e 100644 --- a/src/routes/api/import.js +++ b/src/routes/api/import.js @@ -4,7 +4,7 @@ const enexImportService = require('../../services/import/enex.js'); const opmlImportService = require('../../services/import/opml.js'); const zipImportService = require('../../services/import/zip.js'); const singleImportService = require('../../services/import/single.js'); -const cls = require('../../services/cls.js'); +const cls = require('../../services/cls'); const path = require('path'); const becca = require('../../becca/becca.js'); const beccaLoader = require('../../becca/becca_loader.js'); diff --git a/src/routes/api/revisions.js b/src/routes/api/revisions.js index 72ab1ea03..9985bbbc7 100644 --- a/src/routes/api/revisions.js +++ b/src/routes/api/revisions.js @@ -4,7 +4,7 @@ const beccaService = require('../../becca/becca_service.js'); const revisionService = require('../../services/revisions.js'); const utils = require('../../services/utils.js'); const sql = require('../../services/sql.js'); -const cls = require('../../services/cls.js'); +const cls = require('../../services/cls'); const path = require('path'); const becca = require('../../becca/becca.js'); const blobService = require('../../services/blob.js'); diff --git a/src/routes/api/search.js b/src/routes/api/search.js index cf4887523..901adbb26 100644 --- a/src/routes/api/search.js +++ b/src/routes/api/search.js @@ -4,7 +4,7 @@ const becca = require('../../becca/becca.js'); const SearchContext = require('../../services/search/search_context.js'); const searchService = require('../../services/search/services/search.js'); const bulkActionService = require('../../services/bulk_actions.js'); -const cls = require('../../services/cls.js'); +const cls = require('../../services/cls'); const {formatAttrForSearch} = require('../../services/attribute_formatter.js'); const ValidationError = require('../../errors/validation_error.js'); diff --git a/src/routes/api/special_notes.js b/src/routes/api/special_notes.js index 5f4c7933b..d39406f54 100644 --- a/src/routes/api/special_notes.js +++ b/src/routes/api/special_notes.js @@ -2,7 +2,7 @@ const dateNoteService = require('../../services/date_notes.js'); const sql = require('../../services/sql.js'); -const cls = require('../../services/cls.js'); +const cls = require('../../services/cls'); const specialNotesService = require('../../services/special_notes.js'); const becca = require('../../becca/becca.js'); diff --git a/src/routes/custom.js b/src/routes/custom.js index 7352cb7f9..1d002b964 100644 --- a/src/routes/custom.js +++ b/src/routes/custom.js @@ -1,7 +1,7 @@ const log = require('../services/log'); const fileService = require('./api/files.js'); const scriptService = require('../services/script.js'); -const cls = require('../services/cls.js'); +const cls = require('../services/cls'); const sql = require('../services/sql.js'); const becca = require('../becca/becca.js'); diff --git a/src/routes/routes.js b/src/routes/routes.js index 081a94353..d027c4fea 100644 --- a/src/routes/routes.js +++ b/src/routes/routes.js @@ -6,7 +6,7 @@ const log = require('../services/log'); const express = require('express'); const router = express.Router(); const auth = require('../services/auth.js'); -const cls = require('../services/cls.js'); +const cls = require('../services/cls'); const sql = require('../services/sql.js'); const entityChangesService = require('../services/entity_changes.js'); const csurf = require('csurf'); diff --git a/src/services/backup.js b/src/services/backup.js index 58c8570b2..14106bada 100644 --- a/src/services/backup.js +++ b/src/services/backup.js @@ -6,7 +6,7 @@ const fs = require('fs-extra'); const dataDir = require('./data_dir'); const log = require('./log'); const syncMutexService = require('./sync_mutex.js'); -const cls = require('./cls.js'); +const cls = require('./cls'); const sql = require('./sql.js'); const path = require('path'); diff --git a/src/services/consistency_checks.js b/src/services/consistency_checks.js index 54ca3eed3..873212b5b 100644 --- a/src/services/consistency_checks.js +++ b/src/services/consistency_checks.js @@ -5,7 +5,7 @@ const sqlInit = require('./sql_init.js'); const log = require('./log'); const ws = require('./ws.js'); const syncMutexService = require('./sync_mutex.js'); -const cls = require('./cls.js'); +const cls = require('./cls'); const entityChangesService = require('./entity_changes.js'); const optionsService = require('./options.js'); const BBranch = require('../becca/entities/bbranch.js'); diff --git a/src/services/date_utils.js b/src/services/date_utils.js index 4eb47bdb7..cc17a9036 100644 --- a/src/services/date_utils.js +++ b/src/services/date_utils.js @@ -1,5 +1,5 @@ const dayjs = require('dayjs'); -const cls = require('./cls.js'); +const cls = require('./cls'); const LOCAL_DATETIME_FORMAT = 'YYYY-MM-DD HH:mm:ss.SSSZZ'; const UTC_DATETIME_FORMAT = 'YYYY-MM-DD HH:mm:ssZ'; diff --git a/src/services/entity_changes.js b/src/services/entity_changes.js index dcd93d2d0..f7dd5f4d2 100644 --- a/src/services/entity_changes.js +++ b/src/services/entity_changes.js @@ -1,7 +1,7 @@ const sql = require('./sql.js'); const dateUtils = require('./date_utils.js'); const log = require('./log'); -const cls = require('./cls.js'); +const cls = require('./cls'); const utils = require('./utils.js'); const instanceId = require('./instance_id.js'); const becca = require('../becca/becca.js'); diff --git a/src/services/erase.js b/src/services/erase.js index 0a4e5ee3a..9951a83c3 100644 --- a/src/services/erase.js +++ b/src/services/erase.js @@ -5,7 +5,7 @@ const entityChangesService = require("./entity_changes.js"); const optionService = require("./options.js"); const dateUtils = require("./date_utils.js"); const sqlInit = require("./sql_init.js"); -const cls = require("./cls.js"); +const cls = require("./cls"); function eraseNotes(noteIdsToErase) { if (noteIdsToErase.length === 0) { diff --git a/src/services/hoisted_note.js b/src/services/hoisted_note.js index f3f4e5675..8a3dae18f 100644 --- a/src/services/hoisted_note.js +++ b/src/services/hoisted_note.js @@ -1,4 +1,4 @@ -const cls = require('./cls.js'); +const cls = require('./cls'); const becca = require('../becca/becca.js'); function getHoistedNoteId() { diff --git a/src/services/log.ts b/src/services/log.ts index ce59b1530..51977211f 100644 --- a/src/services/log.ts +++ b/src/services/log.ts @@ -3,7 +3,7 @@ import { Request, Response } from "express"; import fs = require("fs"); import dataDir = require('./data_dir'); -import cls = require('./cls.js'); +import cls = require('./cls'); if (!fs.existsSync(dataDir.LOG_DIR)) { fs.mkdirSync(dataDir.LOG_DIR, 0o700); diff --git a/src/services/migration.js b/src/services/migration.js index d0b48651d..b91a24069 100644 --- a/src/services/migration.js +++ b/src/services/migration.js @@ -5,7 +5,7 @@ const log = require('./log'); const utils = require('./utils.js'); const resourceDir = require('./resource_dir.js'); const appInfo = require('./app_info.js'); -const cls = require('./cls.js'); +const cls = require('./cls'); async function migrate() { const currentDbVersion = getDbVersion(); diff --git a/src/services/notes.js b/src/services/notes.js index 977a8f4f7..15b54abdc 100644 --- a/src/services/notes.js +++ b/src/services/notes.js @@ -3,7 +3,7 @@ const optionService = require('./options.js'); const dateUtils = require('./date_utils.js'); const entityChangesService = require('./entity_changes.js'); const eventService = require('./events.js'); -const cls = require('../services/cls.js'); +const cls = require('../services/cls'); const protectedSessionService = require('../services/protected_session.js'); const log = require('../services/log'); const utils = require('../services/utils.js'); diff --git a/src/services/scheduler.js b/src/services/scheduler.js index 1e03a3d34..d5d9c26dd 100644 --- a/src/services/scheduler.js +++ b/src/services/scheduler.js @@ -1,5 +1,5 @@ const scriptService = require('./script.js'); -const cls = require('./cls.js'); +const cls = require('./cls'); const sqlInit = require('./sql_init.js'); const config = require('./config.js'); const log = require('./log'); diff --git a/src/services/script.js b/src/services/script.js index 24ff7f04a..93c89ccc3 100644 --- a/src/services/script.js +++ b/src/services/script.js @@ -1,5 +1,5 @@ const ScriptContext = require('./script_context.js'); -const cls = require('./cls.js'); +const cls = require('./cls'); const log = require('./log'); const becca = require('../becca/becca.js'); diff --git a/src/services/sql.js b/src/services/sql.js index 3b165d4d6..fc961b0da 100644 --- a/src/services/sql.js +++ b/src/services/sql.js @@ -7,7 +7,7 @@ const log = require('./log'); const Database = require('better-sqlite3'); const dataDir = require('./data_dir'); -const cls = require('./cls.js'); +const cls = require('./cls'); const fs = require("fs-extra"); const dbConnection = new Database(dataDir.DOCUMENT_PATH); diff --git a/src/services/sql_init.js b/src/services/sql_init.js index 7b348dd8b..2a9ffe129 100644 --- a/src/services/sql_init.js +++ b/src/services/sql_init.js @@ -8,7 +8,7 @@ const port = require('./port.js'); const BOption = require('../becca/entities/boption.js'); const TaskContext = require('./task_context.js'); const migrationService = require('./migration.js'); -const cls = require('./cls.js'); +const cls = require('./cls'); const config = require('./config.js'); const dbReady = utils.deferred(); diff --git a/src/services/sync.js b/src/services/sync.js index 8326bd1d8..e30181930 100644 --- a/src/services/sync.js +++ b/src/services/sync.js @@ -11,7 +11,7 @@ const contentHashService = require('./content_hash.js'); const appInfo = require('./app_info.js'); const syncOptions = require('./sync_options.js'); const syncMutexService = require('./sync_mutex.js'); -const cls = require('./cls.js'); +const cls = require('./cls'); const request = require('./request.js'); const ws = require('./ws.js'); const entityChangesService = require('./entity_changes.js'); diff --git a/src/services/window.js b/src/services/window.js index 8468e048c..587dda8a4 100644 --- a/src/services/window.js +++ b/src/services/window.js @@ -5,7 +5,7 @@ const optionService = require('./options.js'); const env = require('./env.js'); const log = require('./log'); const sqlInit = require('./sql_init.js'); -const cls = require('./cls.js'); +const cls = require('./cls'); const keyboardActionsService = require('./keyboard_actions.js'); const {ipcMain} = require('electron'); diff --git a/src/services/ws.js b/src/services/ws.js index 85628b235..99880112d 100644 --- a/src/services/ws.js +++ b/src/services/ws.js @@ -2,7 +2,7 @@ const WebSocket = require('ws'); const utils = require('./utils.js'); const log = require('./log'); const sql = require('./sql.js'); -const cls = require('./cls.js'); +const cls = require('./cls'); const config = require('./config.js'); const syncMutexService = require('./sync_mutex.js'); const protectedSessionService = require('./protected_session.js'); diff --git a/src/tools/generate_document.js b/src/tools/generate_document.js index 67f202a2b..844b6e0f3 100644 --- a/src/tools/generate_document.js +++ b/src/tools/generate_document.js @@ -7,7 +7,7 @@ require('../becca/entity_constructor.js'); const sqlInit = require('../services/sql_init.js'); const noteService = require('../services/notes.js'); const attributeService = require('../services/attributes.js'); -const cls = require('../services/cls.js'); +const cls = require('../services/cls'); const cloningService = require('../services/cloning.js'); const loremIpsum = require('lorem-ipsum').loremIpsum; From 28735fa16ac11b757fc750e3c7c5409ebb9a83c0 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Fri, 16 Feb 2024 21:22:13 +0200 Subject: [PATCH 08/49] server-ts: Fix build errors --- src/services/cls.ts | 2 +- src/services/data_dir.ts | 2 +- src/services/log.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/services/cls.ts b/src/services/cls.ts index 9fca15f54..5bbffaa84 100644 --- a/src/services/cls.ts +++ b/src/services/cls.ts @@ -96,7 +96,7 @@ function ignoreEntityChangeIds() { namespace.set('ignoreEntityChangeIds', true); } -module.exports = { +export = { init, wrap, get, diff --git a/src/services/data_dir.ts b/src/services/data_dir.ts index 5608b265f..1b267850a 100644 --- a/src/services/data_dir.ts +++ b/src/services/data_dir.ts @@ -68,7 +68,7 @@ const LOG_DIR = process.env.TRILIUM_LOG_DIR || `${DIR_SEP}log`; const ANONYMIZED_DB_DIR = process.env.TRILIUM_ANONYMIZED_DB_DIR || `${DIR_SEP}anonymized-db`; const CONFIG_INI_PATH = process.env.TRILIUM_CONFIG_INI_PATH || `${DIR_SEP}config.ini`; -module.exports = { +export = { TRILIUM_DATA_DIR, DOCUMENT_PATH, BACKUP_DIR, diff --git a/src/services/log.ts b/src/services/log.ts index 51977211f..742fdcdb1 100644 --- a/src/services/log.ts +++ b/src/services/log.ts @@ -117,7 +117,7 @@ function formatDate() { return `${pad(todaysMidnight.getFullYear())}-${pad(todaysMidnight.getMonth() + 1)}-${pad(todaysMidnight.getDate())}`; } -module.exports = { +export = { info, error, request From 7a9365457a047104e8299f3f7f54cb4fd37ee875 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Fri, 16 Feb 2024 21:38:09 +0200 Subject: [PATCH 09/49] server-ts: utils.js -> utils.ts --- .../0216__move_content_into_blobs.js | 2 +- package-lock.json | 43 ++++++++ package.json | 3 + spec/search/search.spec.js | 2 +- src/app.js | 2 +- src/becca/entities/abstract_becca_entity.js | 4 +- src/becca/entities/battachment.js | 4 +- src/becca/entities/battribute.js | 2 +- src/becca/entities/bbranch.js | 4 +- src/becca/entities/betapi_token.js | 2 +- src/becca/entities/bnote.js | 4 +- src/becca/entities/boption.js | 2 +- src/becca/entities/brecent_note.js | 2 +- src/becca/entities/brevision.js | 4 +- src/becca/similarity.js | 2 +- src/etapi/app_info.js | 2 +- src/etapi/attachments.js | 4 +- src/etapi/attributes.js | 2 +- src/etapi/auth.js | 2 +- src/etapi/backup.js | 2 +- src/etapi/branches.js | 2 +- src/etapi/notes.js | 4 +- src/etapi/special_notes.js | 2 +- src/etapi/validators.js | 2 +- src/routes/api/autocomplete.js | 2 +- src/routes/api/backend_log.js | 2 +- src/routes/api/branches.js | 2 +- src/routes/api/clipper.js | 4 +- src/routes/api/files.js | 2 +- src/routes/api/login.js | 4 +- src/routes/api/notes.js | 2 +- src/routes/api/recent_notes.js | 2 +- src/routes/api/revisions.js | 2 +- src/routes/api/sync.js | 2 +- src/routes/index.js | 2 +- src/routes/login.js | 2 +- src/routes/routes.js | 2 +- src/routes/setup.js | 2 +- src/services/anonymization.js | 2 +- src/services/app_icon.js | 2 +- src/services/auth.js | 2 +- src/services/backend_script_api.js | 2 +- src/services/backup.js | 2 +- src/services/blob.js | 2 +- src/services/bulk_actions.js | 2 +- src/services/consistency_checks.js | 2 +- src/services/content_hash.js | 2 +- src/services/date_notes.js | 2 +- src/services/encryption/password.js | 2 +- .../encryption/password_encryption.js | 2 +- src/services/entity_changes.js | 4 +- src/services/erase.js | 2 +- src/services/etapi_tokens.js | 2 +- src/services/export/opml.js | 2 +- src/services/export/single.js | 2 +- src/services/export/zip.js | 4 +- src/services/import/enex.js | 2 +- src/services/import/markdown.js | 2 +- src/services/import/single.js | 4 +- src/services/import/zip.js | 2 +- src/services/instance_id.js | 2 +- src/services/keyboard_actions.js | 2 +- src/services/migration.js | 2 +- src/services/notes.js | 4 +- src/services/options_init.js | 4 +- src/services/port.js | 2 +- src/services/request.js | 2 +- src/services/revisions.js | 2 +- src/services/script_context.js | 2 +- .../expressions/note_content_fulltext.js | 2 +- .../search/expressions/note_flat_text.js | 2 +- src/services/search/services/parse.js | 2 +- src/services/search/services/search.js | 2 +- src/services/setup.js | 2 +- src/services/special_notes.js | 2 +- src/services/sql_init.js | 2 +- src/services/sync.js | 4 +- src/services/{utils.js => utils.ts} | 100 +++++++++--------- src/services/ws.js | 2 +- src/share/routes.js | 4 +- src/share/shaca/entities/sattachment.js | 2 +- src/share/shaca/entities/snote.js | 2 +- src/types/unescape.d.ts | 4 + tsconfig.json | 3 +- 84 files changed, 198 insertions(+), 145 deletions(-) rename src/services/{utils.js => utils.ts} (72%) create mode 100644 src/types/unescape.d.ts diff --git a/db/migrations/0216__move_content_into_blobs.js b/db/migrations/0216__move_content_into_blobs.js index d2f7a9f2d..3f67351b7 100644 --- a/db/migrations/0216__move_content_into_blobs.js +++ b/db/migrations/0216__move_content_into_blobs.js @@ -1,6 +1,6 @@ module.exports = () => { const sql = require('../../src/services/sql.js'); - const utils = require('../../src/services/utils.js'); + const utils = require('../../src/services/utils'); const existingBlobIds = new Set(); diff --git a/package-lock.json b/package-lock.json index 953690117..399043518 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,7 @@ "@braintree/sanitize-url": "6.0.4", "@electron/remote": "2.1.0", "@excalidraw/excalidraw": "0.16.1", + "@types/cls-hooked": "^4.3.8", "archiver": "6.0.1", "async-mutex": "0.4.0", "axios": "1.6.2", @@ -88,7 +89,9 @@ "trilium": "src/www.js" }, "devDependencies": { + "@types/escape-html": "^1.0.4", "@types/express": "^4.17.21", + "@types/mime-types": "^2.1.4", "@types/node": "^20.11.19", "cross-env": "7.0.3", "electron": "25.9.8", @@ -1302,6 +1305,14 @@ "@types/responselike": "*" } }, + "node_modules/@types/cls-hooked": { + "version": "4.3.8", + "resolved": "https://registry.npmjs.org/@types/cls-hooked/-/cls-hooked-4.3.8.tgz", + "integrity": "sha512-tf/7H883gFA6MPlWI15EQtfNZ+oPL0gLKkOlx9UHFrun1fC/FkuyNBpTKq1B5E3T4fbvjId6WifHUdSGsMMuPg==", + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/connect": { "version": "3.4.38", "resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.38.tgz", @@ -1337,6 +1348,12 @@ "@types/ms": "*" } }, + "node_modules/@types/escape-html": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@types/escape-html/-/escape-html-1.0.4.tgz", + "integrity": "sha512-qZ72SFTgUAZ5a7Tj6kf2SHLetiH5S6f8G5frB2SPQ3EyF02kxdyBFf4Tz4banE3xCgGnKgWLt//a6VuYHKYJTg==", + "dev": true + }, "node_modules/@types/eslint": { "version": "8.4.1", "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-8.4.1.tgz", @@ -1473,6 +1490,12 @@ "integrity": "sha512-/pyBZWSLD2n0dcHE3hq8s8ZvcETHtEuF+3E7XVt0Ig2nvsVQXdghHVcEkIWjy9A0wKfTn97a/PSDYohKIlnP/w==", "dev": true }, + "node_modules/@types/mime-types": { + "version": "2.1.4", + "resolved": "https://registry.npmjs.org/@types/mime-types/-/mime-types-2.1.4.tgz", + "integrity": "sha512-lfU4b34HOri+kAY5UheuFMWPDOI+OPceBSHZKp69gEyTL/mmJ4cnU6Y/rlme3UL3GyOn6Y42hyIEw0/q8sWx5w==", + "dev": true + }, "node_modules/@types/minimatch": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-3.0.3.tgz", @@ -15915,6 +15938,14 @@ "@types/responselike": "*" } }, + "@types/cls-hooked": { + "version": "4.3.8", + "resolved": "https://registry.npmjs.org/@types/cls-hooked/-/cls-hooked-4.3.8.tgz", + "integrity": "sha512-tf/7H883gFA6MPlWI15EQtfNZ+oPL0gLKkOlx9UHFrun1fC/FkuyNBpTKq1B5E3T4fbvjId6WifHUdSGsMMuPg==", + "requires": { + "@types/node": "*" + } + }, "@types/connect": { "version": "3.4.38", "resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.38.tgz", @@ -15950,6 +15981,12 @@ "@types/ms": "*" } }, + "@types/escape-html": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@types/escape-html/-/escape-html-1.0.4.tgz", + "integrity": "sha512-qZ72SFTgUAZ5a7Tj6kf2SHLetiH5S6f8G5frB2SPQ3EyF02kxdyBFf4Tz4banE3xCgGnKgWLt//a6VuYHKYJTg==", + "dev": true + }, "@types/eslint": { "version": "8.4.1", "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-8.4.1.tgz", @@ -16086,6 +16123,12 @@ "integrity": "sha512-/pyBZWSLD2n0dcHE3hq8s8ZvcETHtEuF+3E7XVt0Ig2nvsVQXdghHVcEkIWjy9A0wKfTn97a/PSDYohKIlnP/w==", "dev": true }, + "@types/mime-types": { + "version": "2.1.4", + "resolved": "https://registry.npmjs.org/@types/mime-types/-/mime-types-2.1.4.tgz", + "integrity": "sha512-lfU4b34HOri+kAY5UheuFMWPDOI+OPceBSHZKp69gEyTL/mmJ4cnU6Y/rlme3UL3GyOn6Y42hyIEw0/q8sWx5w==", + "dev": true + }, "@types/minimatch": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-3.0.3.tgz", diff --git a/package.json b/package.json index 42dd3ac3b..1678ffe4d 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "@braintree/sanitize-url": "6.0.4", "@electron/remote": "2.1.0", "@excalidraw/excalidraw": "0.16.1", + "@types/cls-hooked": "^4.3.8", "archiver": "6.0.1", "async-mutex": "0.4.0", "axios": "1.6.2", @@ -111,7 +112,9 @@ "yauzl": "2.10.0" }, "devDependencies": { + "@types/escape-html": "^1.0.4", "@types/express": "^4.17.21", + "@types/mime-types": "^2.1.4", "@types/node": "^20.11.19", "cross-env": "7.0.3", "electron": "25.9.8", diff --git a/spec/search/search.spec.js b/spec/search/search.spec.js index 97b607afd..14714cb6e 100644 --- a/spec/search/search.spec.js +++ b/spec/search/search.spec.js @@ -2,7 +2,7 @@ const searchService = require('../../src/services/search/services/search.js'); const BNote = require('../../src/becca/entities/bnote.js'); const BBranch = require('../../src/becca/entities/bbranch.js'); const SearchContext = require('../../src/services/search/search_context.js'); -const dateUtils = require('../../src/services/date_utils.js'); +const dateUtils = require('../../src/services/date_utils'); const becca = require('../../src/becca/becca.js'); const {NoteBuilder, findNoteByTitle, note} = require('./becca_mocking.js'); diff --git a/src/app.js b/src/app.js index 45451f0cc..a2e7b4f31 100644 --- a/src/app.js +++ b/src/app.js @@ -5,7 +5,7 @@ const cookieParser = require('cookie-parser'); const helmet = require('helmet'); const compression = require('compression'); const sessionParser = require('./routes/session_parser.js'); -const utils = require('./services/utils.js'); +const utils = require('./services/utils'); require('./services/handlers.js'); require('./becca/becca_loader.js'); diff --git a/src/becca/entities/abstract_becca_entity.js b/src/becca/entities/abstract_becca_entity.js index 9cd0dad76..b1c7feac9 100644 --- a/src/becca/entities/abstract_becca_entity.js +++ b/src/becca/entities/abstract_becca_entity.js @@ -1,10 +1,10 @@ "use strict"; -const utils = require('../../services/utils.js'); +const utils = require('../../services/utils'); const sql = require('../../services/sql.js'); const entityChangesService = require('../../services/entity_changes.js'); const eventService = require('../../services/events.js'); -const dateUtils = require('../../services/date_utils.js'); +const dateUtils = require('../../services/date_utils'); const cls = require('../../services/cls'); const log = require('../../services/log'); const protectedSessionService = require('../../services/protected_session.js'); diff --git a/src/becca/entities/battachment.js b/src/becca/entities/battachment.js index fedf70411..49a22ef0d 100644 --- a/src/becca/entities/battachment.js +++ b/src/becca/entities/battachment.js @@ -1,7 +1,7 @@ "use strict"; -const utils = require('../../services/utils.js'); -const dateUtils = require('../../services/date_utils.js'); +const utils = require('../../services/utils'); +const dateUtils = require('../../services/date_utils'); const AbstractBeccaEntity = require('./abstract_becca_entity.js'); const sql = require('../../services/sql.js'); const protectedSessionService = require('../../services/protected_session.js'); diff --git a/src/becca/entities/battribute.js b/src/becca/entities/battribute.js index 55e7db66d..3598b0671 100644 --- a/src/becca/entities/battribute.js +++ b/src/becca/entities/battribute.js @@ -3,7 +3,7 @@ const BNote = require('./bnote.js'); const AbstractBeccaEntity = require('./abstract_becca_entity.js'); const sql = require('../../services/sql.js'); -const dateUtils = require('../../services/date_utils.js'); +const dateUtils = require('../../services/date_utils'); const promotedAttributeDefinitionParser = require('../../services/promoted_attribute_definition_parser.js'); const {sanitizeAttributeName} = require('../../services/sanitize_attribute_name.js'); diff --git a/src/becca/entities/bbranch.js b/src/becca/entities/bbranch.js index 3ee42e510..b9a04af7f 100644 --- a/src/becca/entities/bbranch.js +++ b/src/becca/entities/bbranch.js @@ -2,8 +2,8 @@ const BNote = require('./bnote.js'); const AbstractBeccaEntity = require('./abstract_becca_entity.js'); -const dateUtils = require('../../services/date_utils.js'); -const utils = require('../../services/utils.js'); +const dateUtils = require('../../services/date_utils'); +const utils = require('../../services/utils'); const TaskContext = require('../../services/task_context.js'); const cls = require('../../services/cls'); const log = require('../../services/log'); diff --git a/src/becca/entities/betapi_token.js b/src/becca/entities/betapi_token.js index 0fded9e63..aedc1615f 100644 --- a/src/becca/entities/betapi_token.js +++ b/src/becca/entities/betapi_token.js @@ -1,6 +1,6 @@ "use strict"; -const dateUtils = require('../../services/date_utils.js'); +const dateUtils = require('../../services/date_utils'); const AbstractBeccaEntity = require('./abstract_becca_entity.js'); /** diff --git a/src/becca/entities/bnote.js b/src/becca/entities/bnote.js index b11a624d8..77776750d 100644 --- a/src/becca/entities/bnote.js +++ b/src/becca/entities/bnote.js @@ -3,8 +3,8 @@ const protectedSessionService = require('../../services/protected_session.js'); const log = require('../../services/log'); const sql = require('../../services/sql.js'); -const utils = require('../../services/utils.js'); -const dateUtils = require('../../services/date_utils.js'); +const utils = require('../../services/utils'); +const dateUtils = require('../../services/date_utils'); const AbstractBeccaEntity = require('./abstract_becca_entity.js'); const BRevision = require('./brevision.js'); const BAttachment = require('./battachment.js'); diff --git a/src/becca/entities/boption.js b/src/becca/entities/boption.js index 6c2c3edab..7fa121ccc 100644 --- a/src/becca/entities/boption.js +++ b/src/becca/entities/boption.js @@ -1,6 +1,6 @@ "use strict"; -const dateUtils = require('../../services/date_utils.js'); +const dateUtils = require('../../services/date_utils'); const AbstractBeccaEntity = require('./abstract_becca_entity.js'); /** diff --git a/src/becca/entities/brecent_note.js b/src/becca/entities/brecent_note.js index 300945b9a..8a840e2d0 100644 --- a/src/becca/entities/brecent_note.js +++ b/src/becca/entities/brecent_note.js @@ -1,6 +1,6 @@ "use strict"; -const dateUtils = require('../../services/date_utils.js'); +const dateUtils = require('../../services/date_utils'); const AbstractBeccaEntity = require('./abstract_becca_entity.js'); /** diff --git a/src/becca/entities/brevision.js b/src/becca/entities/brevision.js index 841ecaaee..e70726d1b 100644 --- a/src/becca/entities/brevision.js +++ b/src/becca/entities/brevision.js @@ -1,8 +1,8 @@ "use strict"; const protectedSessionService = require('../../services/protected_session.js'); -const utils = require('../../services/utils.js'); -const dateUtils = require('../../services/date_utils.js'); +const utils = require('../../services/utils'); +const dateUtils = require('../../services/date_utils'); const becca = require('../becca.js'); const AbstractBeccaEntity = require('./abstract_becca_entity.js'); const sql = require('../../services/sql.js'); diff --git a/src/becca/similarity.js b/src/becca/similarity.js index 1a8534e0b..62c4a9cd1 100644 --- a/src/becca/similarity.js +++ b/src/becca/similarity.js @@ -1,7 +1,7 @@ const becca = require('./becca.js'); const log = require('../services/log'); const beccaService = require('./becca_service.js'); -const dateUtils = require('../services/date_utils.js'); +const dateUtils = require('../services/date_utils'); const {JSDOM} = require("jsdom"); const DEBUG = false; diff --git a/src/etapi/app_info.js b/src/etapi/app_info.js index f82287170..a58850e77 100644 --- a/src/etapi/app_info.js +++ b/src/etapi/app_info.js @@ -1,5 +1,5 @@ const appInfo = require('../services/app_info.js'); -const eu = require('./etapi_utils.js'); +const eu = require('./etapi_utils'); function register(router) { eu.route(router, 'get', '/etapi/app-info', (req, res, next) => { diff --git a/src/etapi/attachments.js b/src/etapi/attachments.js index 586da7a21..2c77210cc 100644 --- a/src/etapi/attachments.js +++ b/src/etapi/attachments.js @@ -1,8 +1,8 @@ const becca = require('../becca/becca.js'); -const eu = require('./etapi_utils.js'); +const eu = require('./etapi_utils'); const mappers = require('./mappers.js'); const v = require('./validators.js'); -const utils = require('../services/utils.js'); +const utils = require('../services/utils'); function register(router) { const ALLOWED_PROPERTIES_FOR_CREATE_ATTACHMENT = { diff --git a/src/etapi/attributes.js b/src/etapi/attributes.js index 131e85ae8..692b8c05e 100644 --- a/src/etapi/attributes.js +++ b/src/etapi/attributes.js @@ -1,5 +1,5 @@ const becca = require('../becca/becca.js'); -const eu = require('./etapi_utils.js'); +const eu = require('./etapi_utils'); const mappers = require('./mappers.js'); const attributeService = require('../services/attributes.js'); const v = require('./validators.js'); diff --git a/src/etapi/auth.js b/src/etapi/auth.js index 96e4e2fa0..d5cab7e15 100644 --- a/src/etapi/auth.js +++ b/src/etapi/auth.js @@ -1,5 +1,5 @@ const becca = require('../becca/becca.js'); -const eu = require('./etapi_utils.js'); +const eu = require('./etapi_utils'); const passwordEncryptionService = require('../services/encryption/password_encryption.js'); const etapiTokenService = require('../services/etapi_tokens.js'); diff --git a/src/etapi/backup.js b/src/etapi/backup.js index b9ca75204..2897c36b2 100644 --- a/src/etapi/backup.js +++ b/src/etapi/backup.js @@ -1,4 +1,4 @@ -const eu = require('./etapi_utils.js'); +const eu = require('./etapi_utils'); const backupService = require('../services/backup.js'); function register(router) { diff --git a/src/etapi/branches.js b/src/etapi/branches.js index 1d11144f9..19741b100 100644 --- a/src/etapi/branches.js +++ b/src/etapi/branches.js @@ -1,5 +1,5 @@ const becca = require('../becca/becca.js'); -const eu = require('./etapi_utils.js'); +const eu = require('./etapi_utils'); const mappers = require('./mappers.js'); const BBranch = require('../becca/entities/bbranch.js'); const entityChangesService = require('../services/entity_changes.js'); diff --git a/src/etapi/notes.js b/src/etapi/notes.js index 69c00e795..8acb3546e 100644 --- a/src/etapi/notes.js +++ b/src/etapi/notes.js @@ -1,6 +1,6 @@ const becca = require('../becca/becca.js'); -const utils = require('../services/utils.js'); -const eu = require('./etapi_utils.js'); +const utils = require('../services/utils'); +const eu = require('./etapi_utils'); const mappers = require('./mappers.js'); const noteService = require('../services/notes.js'); const TaskContext = require('../services/task_context.js'); diff --git a/src/etapi/special_notes.js b/src/etapi/special_notes.js index 64f97d07b..e6408b251 100644 --- a/src/etapi/special_notes.js +++ b/src/etapi/special_notes.js @@ -1,6 +1,6 @@ const specialNotesService = require('../services/special_notes.js'); const dateNotesService = require('../services/date_notes.js'); -const eu = require('./etapi_utils.js'); +const eu = require('./etapi_utils'); const mappers = require('./mappers.js'); const getDateInvalidError = date => new eu.EtapiError(400, "DATE_INVALID", `Date "${date}" is not valid.`); diff --git a/src/etapi/validators.js b/src/etapi/validators.js index 44128b812..f9ca0fa6a 100644 --- a/src/etapi/validators.js +++ b/src/etapi/validators.js @@ -1,5 +1,5 @@ const noteTypeService = require('../services/note_types.js'); -const dateUtils = require('../services/date_utils.js'); +const dateUtils = require('../services/date_utils'); function mandatory(obj) { if (obj === undefined ) { diff --git a/src/routes/api/autocomplete.js b/src/routes/api/autocomplete.js index 983576b8c..e28ccfcdb 100644 --- a/src/routes/api/autocomplete.js +++ b/src/routes/api/autocomplete.js @@ -3,7 +3,7 @@ const beccaService = require('../../becca/becca_service.js'); const searchService = require('../../services/search/services/search.js'); const log = require('../../services/log'); -const utils = require('../../services/utils.js'); +const utils = require('../../services/utils'); const cls = require('../../services/cls'); const becca = require('../../becca/becca.js'); diff --git a/src/routes/api/backend_log.js b/src/routes/api/backend_log.js index c941bdaeb..4a07a219e 100644 --- a/src/routes/api/backend_log.js +++ b/src/routes/api/backend_log.js @@ -1,7 +1,7 @@ "use strict"; const fs = require('fs'); -const dateUtils = require('../../services/date_utils.js'); +const dateUtils = require('../../services/date_utils'); const {LOG_DIR} = require('../../services/data_dir'); function getBackendLog() { diff --git a/src/routes/api/branches.js b/src/routes/api/branches.js index 3447b1e33..fc2830b76 100644 --- a/src/routes/api/branches.js +++ b/src/routes/api/branches.js @@ -1,7 +1,7 @@ "use strict"; const sql = require('../../services/sql.js'); -const utils = require('../../services/utils.js'); +const utils = require('../../services/utils'); const entityChangesService = require('../../services/entity_changes.js'); const treeService = require('../../services/tree.js'); const eraseService = require('../../services/erase.js'); diff --git a/src/routes/api/clipper.js b/src/routes/api/clipper.js index 052841cf1..3992bbeda 100644 --- a/src/routes/api/clipper.js +++ b/src/routes/api/clipper.js @@ -4,12 +4,12 @@ const attributeService = require('../../services/attributes.js'); const cloneService = require('../../services/cloning.js'); const noteService = require('../../services/notes.js'); const dateNoteService = require('../../services/date_notes.js'); -const dateUtils = require('../../services/date_utils.js'); +const dateUtils = require('../../services/date_utils'); const imageService = require('../../services/image.js'); const appInfo = require('../../services/app_info.js'); const ws = require('../../services/ws.js'); const log = require('../../services/log'); -const utils = require('../../services/utils.js'); +const utils = require('../../services/utils'); const path = require('path'); const htmlSanitizer = require('../../services/html_sanitizer.js'); const {formatAttrForSearch} = require('../../services/attribute_formatter.js'); diff --git a/src/routes/api/files.js b/src/routes/api/files.js index 60e9aba19..48ec7c5ea 100644 --- a/src/routes/api/files.js +++ b/src/routes/api/files.js @@ -1,7 +1,7 @@ "use strict"; const protectedSessionService = require('../../services/protected_session.js'); -const utils = require('../../services/utils.js'); +const utils = require('../../services/utils'); const log = require('../../services/log'); const noteService = require('../../services/notes.js'); const tmp = require('tmp'); diff --git a/src/routes/api/login.js b/src/routes/api/login.js index 9dbf058d4..7aed6955a 100644 --- a/src/routes/api/login.js +++ b/src/routes/api/login.js @@ -1,8 +1,8 @@ "use strict"; const options = require('../../services/options.js'); -const utils = require('../../services/utils.js'); -const dateUtils = require('../../services/date_utils.js'); +const utils = require('../../services/utils'); +const dateUtils = require('../../services/date_utils'); const instanceId = require('../../services/instance_id.js'); const passwordEncryptionService = require('../../services/encryption/password_encryption.js'); const protectedSessionService = require('../../services/protected_session.js'); diff --git a/src/routes/api/notes.js b/src/routes/api/notes.js index f2c49e325..0ce570892 100644 --- a/src/routes/api/notes.js +++ b/src/routes/api/notes.js @@ -4,7 +4,7 @@ const noteService = require('../../services/notes.js'); const eraseService = require('../../services/erase.js'); const treeService = require('../../services/tree.js'); const sql = require('../../services/sql.js'); -const utils = require('../../services/utils.js'); +const utils = require('../../services/utils'); const log = require('../../services/log'); const TaskContext = require('../../services/task_context.js'); const becca = require('../../becca/becca.js'); diff --git a/src/routes/api/recent_notes.js b/src/routes/api/recent_notes.js index 2ba5c5020..80ccd9fea 100644 --- a/src/routes/api/recent_notes.js +++ b/src/routes/api/recent_notes.js @@ -2,7 +2,7 @@ const BRecentNote = require('../../becca/entities/brecent_note.js'); const sql = require('../../services/sql.js'); -const dateUtils = require('../../services/date_utils.js'); +const dateUtils = require('../../services/date_utils'); function addRecentNote(req) { new BRecentNote({ diff --git a/src/routes/api/revisions.js b/src/routes/api/revisions.js index 9985bbbc7..bf378d625 100644 --- a/src/routes/api/revisions.js +++ b/src/routes/api/revisions.js @@ -2,7 +2,7 @@ const beccaService = require('../../becca/becca_service.js'); const revisionService = require('../../services/revisions.js'); -const utils = require('../../services/utils.js'); +const utils = require('../../services/utils'); const sql = require('../../services/sql.js'); const cls = require('../../services/cls'); const path = require('path'); diff --git a/src/routes/api/sync.js b/src/routes/api/sync.js index 859de6d53..ecf22c060 100644 --- a/src/routes/api/sync.js +++ b/src/routes/api/sync.js @@ -9,7 +9,7 @@ const optionService = require('../../services/options.js'); const contentHashService = require('../../services/content_hash.js'); const log = require('../../services/log'); const syncOptions = require('../../services/sync_options.js'); -const utils = require('../../services/utils.js'); +const utils = require('../../services/utils'); const ws = require('../../services/ws.js'); async function testSync() { diff --git a/src/routes/index.js b/src/routes/index.js index 92de411c4..ef8f631a2 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -6,7 +6,7 @@ const config = require('../services/config.js'); const optionService = require('../services/options.js'); const log = require('../services/log'); const env = require('../services/env.js'); -const utils = require('../services/utils.js'); +const utils = require('../services/utils'); const protectedSessionService = require('../services/protected_session.js'); const packageJson = require('../../package.json'); const assetPath = require('../services/asset_path.js'); diff --git a/src/routes/login.js b/src/routes/login.js index 15a9a9684..2ea84a93b 100644 --- a/src/routes/login.js +++ b/src/routes/login.js @@ -1,6 +1,6 @@ "use strict"; -const utils = require('../services/utils.js'); +const utils = require('../services/utils'); const optionService = require('../services/options.js'); const myScryptService = require('../services/encryption/my_scrypt.js'); const log = require('../services/log'); diff --git a/src/routes/routes.js b/src/routes/routes.js index d027c4fea..79914e3fd 100644 --- a/src/routes/routes.js +++ b/src/routes/routes.js @@ -1,6 +1,6 @@ "use strict"; -const utils = require('../services/utils.js'); +const utils = require('../services/utils'); const multer = require('multer'); const log = require('../services/log'); const express = require('express'); diff --git a/src/routes/setup.js b/src/routes/setup.js index be14c2310..fe74c68a5 100644 --- a/src/routes/setup.js +++ b/src/routes/setup.js @@ -2,7 +2,7 @@ const sqlInit = require('../services/sql_init.js'); const setupService = require('../services/setup.js'); -const utils = require('../services/utils.js'); +const utils = require('../services/utils'); const assetPath = require('../services/asset_path.js'); const appPath = require('../services/app_path.js'); diff --git a/src/services/anonymization.js b/src/services/anonymization.js index 792d83c9c..0fc774895 100644 --- a/src/services/anonymization.js +++ b/src/services/anonymization.js @@ -1,7 +1,7 @@ const BUILTIN_ATTRIBUTES = require('./builtin_attributes.js'); const fs = require("fs-extra"); const dataDir = require('./data_dir'); -const dateUtils = require('./date_utils.js'); +const dateUtils = require('./date_utils'); const Database = require("better-sqlite3"); const sql = require('./sql.js'); const path = require("path"); diff --git a/src/services/app_icon.js b/src/services/app_icon.js index 784850508..3e7b48e24 100644 --- a/src/services/app_icon.js +++ b/src/services/app_icon.js @@ -6,7 +6,7 @@ const log = require('./log'); const os = require('os'); const fs = require('fs'); const config = require('./config.js'); -const utils = require('./utils.js'); +const utils = require('./utils'); const template = `[Desktop Entry] Type=Application diff --git a/src/services/auth.js b/src/services/auth.js index e16fa9ba5..8db06bc07 100644 --- a/src/services/auth.js +++ b/src/services/auth.js @@ -3,7 +3,7 @@ const etapiTokenService = require('./etapi_tokens.js'); const log = require('./log'); const sqlInit = require('./sql_init.js'); -const utils = require('./utils.js'); +const utils = require('./utils'); const passwordEncryptionService = require('./encryption/password_encryption.js'); const config = require('./config.js'); const passwordService = require('./encryption/password.js'); diff --git a/src/services/backend_script_api.js b/src/services/backend_script_api.js index 12732d6a0..2836018ec 100644 --- a/src/services/backend_script_api.js +++ b/src/services/backend_script_api.js @@ -1,7 +1,7 @@ const log = require('./log'); const noteService = require('./notes.js'); const sql = require('./sql.js'); -const utils = require('./utils.js'); +const utils = require('./utils'); const attributeService = require('./attributes.js'); const dateNoteService = require('./date_notes.js'); const treeService = require('./tree.js'); diff --git a/src/services/backup.js b/src/services/backup.js index 14106bada..c9ae0edba 100644 --- a/src/services/backup.js +++ b/src/services/backup.js @@ -1,6 +1,6 @@ "use strict"; -const dateUtils = require('./date_utils.js'); +const dateUtils = require('./date_utils'); const optionService = require('./options.js'); const fs = require('fs-extra'); const dataDir = require('./data_dir'); diff --git a/src/services/blob.js b/src/services/blob.js index 73f972a36..9b2cfa6dd 100644 --- a/src/services/blob.js +++ b/src/services/blob.js @@ -1,7 +1,7 @@ const becca = require('../becca/becca.js'); const NotFoundError = require('../errors/not_found_error.js'); const protectedSessionService = require('./protected_session.js'); -const utils = require('./utils.js'); +const utils = require('./utils'); function getBlobPojo(entityName, entityId) { const entity = becca.getEntity(entityName, entityId); diff --git a/src/services/bulk_actions.js b/src/services/bulk_actions.js index 38f649723..3536ed9a9 100644 --- a/src/services/bulk_actions.js +++ b/src/services/bulk_actions.js @@ -3,7 +3,7 @@ const revisionService = require('./revisions.js'); const becca = require('../becca/becca.js'); const cloningService = require('./cloning.js'); const branchService = require('./branches.js'); -const utils = require('./utils.js'); +const utils = require('./utils'); const eraseService = require("./erase.js"); const ACTION_HANDLERS = { diff --git a/src/services/consistency_checks.js b/src/services/consistency_checks.js index 873212b5b..e7b11d290 100644 --- a/src/services/consistency_checks.js +++ b/src/services/consistency_checks.js @@ -11,7 +11,7 @@ const optionsService = require('./options.js'); const BBranch = require('../becca/entities/bbranch.js'); const revisionService = require('./revisions.js'); const becca = require('../becca/becca.js'); -const utils = require('../services/utils.js'); +const utils = require('../services/utils'); const eraseService = require('../services/erase.js'); const {sanitizeAttributeName} = require('./sanitize_attribute_name.js'); const noteTypes = require('../services/note_types.js').getNoteTypeNames(); diff --git a/src/services/content_hash.js b/src/services/content_hash.js index 0251e0cd6..8e01c067f 100644 --- a/src/services/content_hash.js +++ b/src/services/content_hash.js @@ -1,7 +1,7 @@ "use strict"; const sql = require('./sql.js'); -const utils = require('./utils.js'); +const utils = require('./utils'); const log = require('./log'); const eraseService = require('./erase.js'); diff --git a/src/services/date_notes.js b/src/services/date_notes.js index 69e2a06a0..122082f57 100644 --- a/src/services/date_notes.js +++ b/src/services/date_notes.js @@ -2,7 +2,7 @@ const noteService = require('./notes.js'); const attributeService = require('./attributes.js'); -const dateUtils = require('./date_utils.js'); +const dateUtils = require('./date_utils'); const sql = require('./sql.js'); const protectedSessionService = require('./protected_session.js'); const searchService = require('../services/search/services/search.js'); diff --git a/src/services/encryption/password.js b/src/services/encryption/password.js index 563e86c02..f9665b585 100644 --- a/src/services/encryption/password.js +++ b/src/services/encryption/password.js @@ -3,7 +3,7 @@ const sql = require('../sql.js'); const optionService = require('../options.js'); const myScryptService = require('./my_scrypt.js'); -const utils = require('../utils.js'); +const utils = require('../utils'); const passwordEncryptionService = require('./password_encryption.js'); function isPasswordSet() { diff --git a/src/services/encryption/password_encryption.js b/src/services/encryption/password_encryption.js index 336be8f2f..06ada7d98 100644 --- a/src/services/encryption/password_encryption.js +++ b/src/services/encryption/password_encryption.js @@ -1,6 +1,6 @@ const optionService = require('../options.js'); const myScryptService = require('./my_scrypt.js'); -const utils = require('../utils.js'); +const utils = require('../utils'); const dataEncryptionService = require('./data_encryption.js'); function verifyPassword(password) { diff --git a/src/services/entity_changes.js b/src/services/entity_changes.js index f7dd5f4d2..520c29718 100644 --- a/src/services/entity_changes.js +++ b/src/services/entity_changes.js @@ -1,8 +1,8 @@ const sql = require('./sql.js'); -const dateUtils = require('./date_utils.js'); +const dateUtils = require('./date_utils'); const log = require('./log'); const cls = require('./cls'); -const utils = require('./utils.js'); +const utils = require('./utils'); const instanceId = require('./instance_id.js'); const becca = require('../becca/becca.js'); const blobService = require('../services/blob.js'); diff --git a/src/services/erase.js b/src/services/erase.js index 9951a83c3..dc43fc088 100644 --- a/src/services/erase.js +++ b/src/services/erase.js @@ -3,7 +3,7 @@ const revisionService = require("./revisions.js"); const log = require("./log.ts"); const entityChangesService = require("./entity_changes.js"); const optionService = require("./options.js"); -const dateUtils = require("./date_utils.js"); +const dateUtils = require("./date_utils"); const sqlInit = require("./sql_init.js"); const cls = require("./cls"); diff --git a/src/services/etapi_tokens.js b/src/services/etapi_tokens.js index 4033b8016..552a31ade 100644 --- a/src/services/etapi_tokens.js +++ b/src/services/etapi_tokens.js @@ -1,5 +1,5 @@ const becca = require('../becca/becca.js'); -const utils = require('./utils.js'); +const utils = require('./utils'); const BEtapiToken = require('../becca/entities/betapi_token.js'); const crypto = require("crypto"); diff --git a/src/services/export/opml.js b/src/services/export/opml.js index 976fb5b24..b58bb63c1 100644 --- a/src/services/export/opml.js +++ b/src/services/export/opml.js @@ -1,6 +1,6 @@ "use strict"; -const utils = require('../utils.js'); +const utils = require('../utils'); const becca = require('../../becca/becca.js'); function exportToOpml(taskContext, branch, version, res) { diff --git a/src/services/export/single.js b/src/services/export/single.js index a3bc03335..5fbe4ee44 100644 --- a/src/services/export/single.js +++ b/src/services/export/single.js @@ -2,7 +2,7 @@ const mimeTypes = require('mime-types'); const html = require('html'); -const utils = require('../utils.js'); +const utils = require('../utils'); const mdService = require('./md.js'); const becca = require('../../becca/becca.js'); diff --git a/src/services/export/zip.js b/src/services/export/zip.js index 153b05f58..5e2482013 100644 --- a/src/services/export/zip.js +++ b/src/services/export/zip.js @@ -1,12 +1,12 @@ "use strict"; const html = require('html'); -const dateUtils = require('../date_utils.js'); +const dateUtils = require('../date_utils'); const path = require('path'); const mimeTypes = require('mime-types'); const mdService = require('./md.js'); const packageInfo = require('../../../package.json'); -const utils = require('../utils.js'); +const utils = require('../utils'); const protectedSessionService = require('../protected_session.js'); const sanitize = require("sanitize-filename"); const fs = require("fs"); diff --git a/src/services/import/enex.js b/src/services/import/enex.js index 50f0c5549..72f9554ae 100644 --- a/src/services/import/enex.js +++ b/src/services/import/enex.js @@ -2,7 +2,7 @@ const sax = require("sax"); const stream = require('stream'); const {Throttle} = require('stream-throttle'); const log = require('../log'); -const utils = require('../utils.js'); +const utils = require('../utils'); const sql = require('../sql.js'); const noteService = require('../notes.js'); const imageService = require('../image.js'); diff --git a/src/services/import/markdown.js b/src/services/import/markdown.js index 90b6d1f43..7cdd6b3d2 100644 --- a/src/services/import/markdown.js +++ b/src/services/import/markdown.js @@ -2,7 +2,7 @@ const marked = require("marked"); const htmlSanitizer = require('../html_sanitizer.js'); -const importUtils = require('./utils.js'); +const importUtils = require('./utils'); function renderToHtml(content, title) { const html = marked.parse(content, { diff --git a/src/services/import/single.js b/src/services/import/single.js index 7d3ea164f..59686207f 100644 --- a/src/services/import/single.js +++ b/src/services/import/single.js @@ -5,8 +5,8 @@ const imageService = require('../../services/image.js'); const protectedSessionService = require('../protected_session.js'); const markdownService = require('./markdown.js'); const mimeService = require('./mime.js'); -const utils = require('../../services/utils.js'); -const importUtils = require('./utils.js'); +const utils = require('../../services/utils'); +const importUtils = require('./utils'); const htmlSanitizer = require('../html_sanitizer.js'); function importSingleFile(taskContext, file, parentNote) { diff --git a/src/services/import/zip.js b/src/services/import/zip.js index 0df5fff4c..fabcdd58d 100644 --- a/src/services/import/zip.js +++ b/src/services/import/zip.js @@ -1,7 +1,7 @@ "use strict"; const BAttribute = require('../../becca/entities/battribute.js'); -const utils = require('../../services/utils.js'); +const utils = require('../../services/utils'); const log = require('../../services/log'); const noteService = require('../../services/notes.js'); const attributeService = require('../../services/attributes.js'); diff --git a/src/services/instance_id.js b/src/services/instance_id.js index 49f0a4209..4ee187b01 100644 --- a/src/services/instance_id.js +++ b/src/services/instance_id.js @@ -1,4 +1,4 @@ -const utils = require('./utils.js'); +const utils = require('./utils'); const instanceId = utils.randomString(12); diff --git a/src/services/keyboard_actions.js b/src/services/keyboard_actions.js index 697d1f4c7..df44994ff 100644 --- a/src/services/keyboard_actions.js +++ b/src/services/keyboard_actions.js @@ -2,7 +2,7 @@ const optionService = require('./options.js'); const log = require('./log'); -const utils = require('./utils.js'); +const utils = require('./utils'); const isMac = process.platform === "darwin"; const isElectron = utils.isElectron(); diff --git a/src/services/migration.js b/src/services/migration.js index b91a24069..17aa5e222 100644 --- a/src/services/migration.js +++ b/src/services/migration.js @@ -2,7 +2,7 @@ const backupService = require('./backup.js'); const sql = require('./sql.js'); const fs = require('fs-extra'); const log = require('./log'); -const utils = require('./utils.js'); +const utils = require('./utils'); const resourceDir = require('./resource_dir.js'); const appInfo = require('./app_info.js'); const cls = require('./cls'); diff --git a/src/services/notes.js b/src/services/notes.js index 15b54abdc..77ed66984 100644 --- a/src/services/notes.js +++ b/src/services/notes.js @@ -1,12 +1,12 @@ const sql = require('./sql.js'); const optionService = require('./options.js'); -const dateUtils = require('./date_utils.js'); +const dateUtils = require('./date_utils'); const entityChangesService = require('./entity_changes.js'); const eventService = require('./events.js'); const cls = require('../services/cls'); const protectedSessionService = require('../services/protected_session.js'); const log = require('../services/log'); -const utils = require('../services/utils.js'); +const utils = require('../services/utils'); const revisionService = require('./revisions.js'); const request = require('./request.js'); const path = require('path'); diff --git a/src/services/options_init.js b/src/services/options_init.js index 46dca53e2..8da0de4bf 100644 --- a/src/services/options_init.js +++ b/src/services/options_init.js @@ -1,8 +1,8 @@ const optionService = require('./options.js'); const appInfo = require('./app_info.js'); -const utils = require('./utils.js'); +const utils = require('./utils'); const log = require('./log'); -const dateUtils = require('./date_utils.js'); +const dateUtils = require('./date_utils'); const keyboardActions = require('./keyboard_actions.js'); function initDocumentOptions() { diff --git a/src/services/port.js b/src/services/port.js index fe31eec35..b34490648 100644 --- a/src/services/port.js +++ b/src/services/port.js @@ -1,5 +1,5 @@ const config = require('./config.js'); -const utils = require('./utils.js'); +const utils = require('./utils'); const env = require('./env.js'); const dataDir = require('./data_dir'); diff --git a/src/services/request.js b/src/services/request.js index 158495779..88771439b 100644 --- a/src/services/request.js +++ b/src/services/request.js @@ -1,6 +1,6 @@ "use strict"; -const utils = require('./utils.js'); +const utils = require('./utils'); const log = require('./log'); const url = require('url'); const syncOptions = require('./sync_options.js'); diff --git a/src/services/revisions.js b/src/services/revisions.js index 5735ceb79..084f941f9 100644 --- a/src/services/revisions.js +++ b/src/services/revisions.js @@ -3,7 +3,7 @@ const log = require('./log'); const sql = require('./sql.js'); const protectedSessionService = require('./protected_session.js'); -const dateUtils = require('./date_utils.js'); +const dateUtils = require('./date_utils'); /** * @param {BNote} note diff --git a/src/services/script_context.js b/src/services/script_context.js index 67400d630..d4b83bc37 100644 --- a/src/services/script_context.js +++ b/src/services/script_context.js @@ -1,4 +1,4 @@ -const utils = require('./utils.js'); +const utils = require('./utils'); const BackendScriptApi = require('./backend_script_api.js'); function ScriptContext(allNotes, apiParams = {}) { diff --git a/src/services/search/expressions/note_content_fulltext.js b/src/services/search/expressions/note_content_fulltext.js index f9eac3699..48ab61a82 100644 --- a/src/services/search/expressions/note_content_fulltext.js +++ b/src/services/search/expressions/note_content_fulltext.js @@ -6,7 +6,7 @@ const log = require('../../log'); const becca = require('../../../becca/becca.js'); const protectedSessionService = require('../../protected_session.js'); const striptags = require('striptags'); -const utils = require('../../utils.js'); +const utils = require('../../utils'); const ALLOWED_OPERATORS = ['=', '!=', '*=*', '*=', '=*', '%=']; diff --git a/src/services/search/expressions/note_flat_text.js b/src/services/search/expressions/note_flat_text.js index 11cc466ec..72f06cb98 100644 --- a/src/services/search/expressions/note_flat_text.js +++ b/src/services/search/expressions/note_flat_text.js @@ -3,7 +3,7 @@ const Expression = require('./expression.js'); const NoteSet = require('../note_set.js'); const becca = require('../../../becca/becca.js'); -const utils = require('../../utils.js'); +const utils = require('../../utils'); class NoteFlatTextExp extends Expression { constructor(tokens) { diff --git a/src/services/search/services/parse.js b/src/services/search/services/parse.js index b31ea265d..84c717f6e 100644 --- a/src/services/search/services/parse.js +++ b/src/services/search/services/parse.js @@ -17,7 +17,7 @@ const OrderByAndLimitExp = require('../expressions/order_by_and_limit.js'); const AncestorExp = require('../expressions/ancestor.js'); const buildComparator = require('./build_comparator.js'); const ValueExtractor = require('../value_extractor.js'); -const utils = require('../../utils.js'); +const utils = require('../../utils'); const TrueExp = require('../expressions/true.js'); const IsHiddenExp = require('../expressions/is_hidden.js'); diff --git a/src/services/search/services/search.js b/src/services/search/services/search.js index ac794e7d0..496d420e0 100644 --- a/src/services/search/services/search.js +++ b/src/services/search/services/search.js @@ -8,7 +8,7 @@ const SearchResult = require('../search_result.js'); const SearchContext = require('../search_context.js'); const becca = require('../../../becca/becca.js'); const beccaService = require('../../../becca/becca_service.js'); -const utils = require('../../utils.js'); +const utils = require('../../utils'); const log = require('../../log'); const hoistedNoteService = require('../../hoisted_note.js'); diff --git a/src/services/setup.js b/src/services/setup.js index 1bebad29a..58736f5b8 100644 --- a/src/services/setup.js +++ b/src/services/setup.js @@ -5,7 +5,7 @@ const optionService = require('./options.js'); const syncOptions = require('./sync_options.js'); const request = require('./request.js'); const appInfo = require('./app_info.js'); -const utils = require('./utils.js'); +const utils = require('./utils'); const becca = require('../becca/becca.js'); async function hasSyncServerSchemaAndSeed() { diff --git a/src/services/special_notes.js b/src/services/special_notes.js index 8d9c2baa1..e57059987 100644 --- a/src/services/special_notes.js +++ b/src/services/special_notes.js @@ -2,7 +2,7 @@ const attributeService = require('./attributes.js'); const dateNoteService = require('./date_notes.js'); const becca = require('../becca/becca.js'); const noteService = require('./notes.js'); -const dateUtils = require('./date_utils.js'); +const dateUtils = require('./date_utils'); const log = require('./log'); const hoistedNoteService = require('./hoisted_note.js'); const searchService = require('./search/services/search.js'); diff --git a/src/services/sql_init.js b/src/services/sql_init.js index 2a9ffe129..298542a7b 100644 --- a/src/services/sql_init.js +++ b/src/services/sql_init.js @@ -2,7 +2,7 @@ const log = require('./log'); const fs = require('fs'); const resourceDir = require('./resource_dir.js'); const sql = require('./sql.js'); -const utils = require('./utils.js'); +const utils = require('./utils'); const optionService = require('./options.js'); const port = require('./port.js'); const BOption = require('../becca/entities/boption.js'); diff --git a/src/services/sync.js b/src/services/sync.js index e30181930..e31eb3654 100644 --- a/src/services/sync.js +++ b/src/services/sync.js @@ -3,9 +3,9 @@ const log = require('./log'); const sql = require('./sql.js'); const optionService = require('./options.js'); -const utils = require('./utils.js'); +const utils = require('./utils'); const instanceId = require('./instance_id.js'); -const dateUtils = require('./date_utils.js'); +const dateUtils = require('./date_utils'); const syncUpdateService = require('./sync_update.js'); const contentHashService = require('./content_hash.js'); const appInfo = require('./app_info.js'); diff --git a/src/services/utils.js b/src/services/utils.ts similarity index 72% rename from src/services/utils.js rename to src/services/utils.ts index 2e99c6ef0..d31e73482 100644 --- a/src/services/utils.js +++ b/src/services/utils.ts @@ -1,18 +1,18 @@ "use strict"; -const crypto = require('crypto'); +import crypto = require('crypto'); const randtoken = require('rand-token').generator({source: 'crypto'}); -const unescape = require('unescape'); -const escape = require('escape-html'); -const sanitize = require("sanitize-filename"); -const mimeTypes = require('mime-types'); -const path = require('path'); +import unescape = require('unescape'); +import escape = require('escape-html'); +import sanitize = require("sanitize-filename"); +import mimeTypes = require('mime-types'); +import path = require('path'); function newEntityId() { return randomString(12); } -function randomString(length) { +function randomString(length: number) { return randtoken.generate(length); } @@ -20,11 +20,11 @@ function randomSecureToken(bytes = 32) { return crypto.randomBytes(bytes).toString('base64'); } -function md5(content) { +function md5(content: crypto.BinaryLike) { return crypto.createHash('md5').update(content).digest('hex'); } -function hashedBlobId(content) { +function hashedBlobId(content: string) { if (content === null || content === undefined) { content = ""; } @@ -41,19 +41,16 @@ function hashedBlobId(content) { return kindaBase62Hash.substr(0, 20); } -function toBase64(plainText) { +function toBase64(plainText: string) { return Buffer.from(plainText).toString('base64'); } -/** - * @returns {Buffer} - */ -function fromBase64(encodedText) { +function fromBase64(encodedText: string) { return Buffer.from(encodedText, 'base64'); } -function hmac(secret, value) { - const hmac = crypto.createHmac('sha256', Buffer.from(secret.toString(), 'ASCII')); +function hmac(secret: any, value: any) { + const hmac = crypto.createHmac('sha256', Buffer.from(secret.toString(), 'ascii')); hmac.update(value.toString()); return hmac.digest('base64'); } @@ -62,30 +59,30 @@ function isElectron() { return !!process.versions['electron']; } -function hash(text) { +function hash(text: string) { text = text.normalize(); return crypto.createHash('sha1').update(text).digest('base64'); } -function isEmptyOrWhitespace(str) { +function isEmptyOrWhitespace(str: string) { return str === null || str.match(/^ *$/) !== null; } -function sanitizeSqlIdentifier(str) { +function sanitizeSqlIdentifier(str: string) { return str.replace(/[^A-Za-z0-9_]/g, ""); } -function escapeHtml(str) { +function escapeHtml(str: string) { return escape(str); } -function unescapeHtml(str) { +function unescapeHtml(str: string) { return unescape(str); } -function toObject(array, fn) { - const obj = {}; +function toObject(array: T[], fn: (item: T) => [K, V]): Record { + const obj: Record = {} as Record; // FIXME: unsafe? for (const item of array) { const ret = fn(item); @@ -96,12 +93,12 @@ function toObject(array, fn) { return obj; } -function stripTags(text) { +function stripTags(text: string) { return text.replace(/<(?:.|\n)*?>/gm, ''); } -function union(a, b) { - const obj = {}; +function union(a: T[], b: T[]): T[] { + const obj: Record = {} as Record; // FIXME: unsafe? for (let i = a.length-1; i >= 0; i--) { obj[a[i]] = a[i]; @@ -111,7 +108,7 @@ function union(a, b) { obj[b[i]] = b[i]; } - const res = []; + const res: T[] = []; for (const k in obj) { if (obj.hasOwnProperty(k)) { // <-- optional @@ -122,7 +119,7 @@ function union(a, b) { return res; } -function escapeRegExp(str) { +function escapeRegExp(str: string) { return str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1"); } @@ -135,7 +132,7 @@ function crash() { } } -function sanitizeFilenameForHeader(filename) { +function sanitizeFilenameForHeader(filename: string) { let sanitizedFilename = sanitize(filename); if (sanitizedFilename.trim().length === 0) { @@ -145,7 +142,7 @@ function sanitizeFilenameForHeader(filename) { return encodeURIComponent(sanitizedFilename); } -function getContentDisposition(filename) { +function getContentDisposition(filename: string) { const sanitizedFilename = sanitizeFilenameForHeader(filename); return `file; filename="${sanitizedFilename}"; filename*=UTF-8''${sanitizedFilename}`; @@ -159,24 +156,24 @@ const STRING_MIME_TYPES = [ "image/svg+xml" ]; -function isStringNote(type, mime) { +function isStringNote(type: string, mime: string) { // render and book are string note in the sense that they are expected to contain empty string return ["text", "code", "relationMap", "search", "render", "book", "mermaid", "canvas"].includes(type) || mime.startsWith('text/') || STRING_MIME_TYPES.includes(mime); } -function quoteRegex(url) { +function quoteRegex(url: string) { return url.replace(/[.*+\-?^${}()|[\]\\]/g, '\\$&'); } -function replaceAll(string, replaceWhat, replaceWith) { +function replaceAll(string: string, replaceWhat: string, replaceWith: string) { const quotedReplaceWhat = quoteRegex(replaceWhat); return string.replace(new RegExp(quotedReplaceWhat, "g"), replaceWith); } -function formatDownloadTitle(fileName, type, mime) { +function formatDownloadTitle(fileName: string, type: string, mime: string) { if (!fileName) { fileName = "untitled"; } @@ -218,7 +215,7 @@ function formatDownloadTitle(fileName, type, mime) { } } -function removeTextFileExtension(filePath) { +function removeTextFileExtension(filePath: string) { const extension = path.extname(filePath).toLowerCase(); if (extension === '.md' || extension === '.markdown' || extension === '.html') { @@ -229,7 +226,7 @@ function removeTextFileExtension(filePath) { } } -function getNoteTitle(filePath, replaceUnderscoresWithSpaces, noteMeta) { +function getNoteTitle(filePath: string, replaceUnderscoresWithSpaces: boolean, noteMeta: { title: string }) { if (noteMeta) { return noteMeta.title; } else { @@ -241,7 +238,7 @@ function getNoteTitle(filePath, replaceUnderscoresWithSpaces, noteMeta) { } } -function timeLimit(promise, limitMs, errorMessage) { +function timeLimit(promise: Promise, limitMs: number, errorMessage: string): Promise { if (!promise || !promise.then) { // it's not actually a promise return promise; } @@ -267,23 +264,28 @@ function timeLimit(promise, limitMs, errorMessage) { }); } -function deferred() { - return (() => { - let resolve, reject; +interface DeferredPromise extends Promise { + resolve: (value: T | PromiseLike) => void, + reject: (reason?: any) => void +} - let promise = new Promise((res, rej) => { +function deferred(): DeferredPromise { + return (() => { + let resolve!: (value: T | PromiseLike) => void; + let reject!: (reason?: any) => void; + + let promise = new Promise((res, rej) => { resolve = res; reject = rej; - }); + }) as DeferredPromise; promise.resolve = resolve; promise.reject = reject; - - return promise; + return promise as DeferredPromise; })(); } -function removeDiacritic(str) { +function removeDiacritic(str: string) { if (!str) { return ""; } @@ -291,12 +293,12 @@ function removeDiacritic(str) { return str.normalize("NFD").replace(/\p{Diacritic}/gu, ""); } -function normalize(str) { +function normalize(str: string) { return removeDiacritic(str).toLowerCase(); } -function toMap(list, key) { - const map = {}; +function toMap>(list: T[], key: keyof T): Record { + const map: Record = {}; for (const el of list) { map[el[key]] = el; @@ -305,7 +307,7 @@ function toMap(list, key) { return map; } -function isString(x) { +function isString(x: any) { return Object.prototype.toString.call(x) === "[object String]"; } diff --git a/src/services/ws.js b/src/services/ws.js index 99880112d..8c6b64a3c 100644 --- a/src/services/ws.js +++ b/src/services/ws.js @@ -1,5 +1,5 @@ const WebSocket = require('ws'); -const utils = require('./utils.js'); +const utils = require('./utils'); const log = require('./log'); const sql = require('./sql.js'); const cls = require('./cls'); diff --git a/src/share/routes.js b/src/share/routes.js index 5db054011..9e1eb5d17 100644 --- a/src/share/routes.js +++ b/src/share/routes.js @@ -236,7 +236,7 @@ function register(router) { addNoIndexHeader(note, res); - const utils = require('../services/utils.js'); + const utils = require('../services/utils'); const filename = utils.formatDownloadTitle(note.title, note.type, note.mime); @@ -304,7 +304,7 @@ function register(router) { addNoIndexHeader(attachment.note, res); - const utils = require('../services/utils.js'); + const utils = require('../services/utils'); const filename = utils.formatDownloadTitle(attachment.title, null, attachment.mime); diff --git a/src/share/shaca/entities/sattachment.js b/src/share/shaca/entities/sattachment.js index 46504ba14..0c60b1332 100644 --- a/src/share/shaca/entities/sattachment.js +++ b/src/share/shaca/entities/sattachment.js @@ -1,7 +1,7 @@ "use strict"; const sql = require('../../sql.js'); -const utils = require('../../../services/utils.js'); +const utils = require('../../../services/utils'); const AbstractShacaEntity = require('./abstract_shaca_entity.js'); class SAttachment extends AbstractShacaEntity { diff --git a/src/share/shaca/entities/snote.js b/src/share/shaca/entities/snote.js index 167f238d0..99fd61efe 100644 --- a/src/share/shaca/entities/snote.js +++ b/src/share/shaca/entities/snote.js @@ -1,7 +1,7 @@ "use strict"; const sql = require('../../sql.js'); -const utils = require('../../../services/utils.js'); +const utils = require('../../../services/utils'); const AbstractShacaEntity = require('./abstract_shaca_entity.js'); const escape = require('escape-html'); diff --git a/src/types/unescape.d.ts b/src/types/unescape.d.ts new file mode 100644 index 000000000..465ebd9e9 --- /dev/null +++ b/src/types/unescape.d.ts @@ -0,0 +1,4 @@ +declare module 'unescape' { + function unescape(str: string, type?: string): string; + export = unescape; +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 7f94100dc..0d6d3364c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,7 +5,8 @@ "sourceMap": true, "outDir": "./build", "strict": true, - "noImplicitAny": true + "noImplicitAny": true, + "lib": ["ES2021"] }, "include": [ "./src/**/*.js", From e2a727ec8aeb30b64c23b5b6839d0fb1b8aa2bc5 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Fri, 16 Feb 2024 21:48:51 +0200 Subject: [PATCH 10/49] server-ts: date_utils.js -> date_utils.ts --- src/services/{date_utils.js => date_utils.ts} | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) rename src/services/{date_utils.js => date_utils.ts} (88%) diff --git a/src/services/date_utils.js b/src/services/date_utils.ts similarity index 88% rename from src/services/date_utils.js rename to src/services/date_utils.ts index cc17a9036..a4150c89e 100644 --- a/src/services/date_utils.js +++ b/src/services/date_utils.ts @@ -1,5 +1,5 @@ -const dayjs = require('dayjs'); -const cls = require('./cls'); +import dayjs = require('dayjs'); +import cls = require('./cls'); const LOCAL_DATETIME_FORMAT = 'YYYY-MM-DD HH:mm:ss.SSSZZ'; const UTC_DATETIME_FORMAT = 'YYYY-MM-DD HH:mm:ssZ'; @@ -29,15 +29,15 @@ function localNowDate() { } } -function pad(num) { +function pad(num: number) { return num <= 9 ? `0${num}` : `${num}`; } -function utcDateStr(date) { +function utcDateStr(date: Date) { return date.toISOString().split('T')[0]; } -function utcDateTimeStr(date) { +function utcDateTimeStr(date: Date) { return date.toISOString().replace('T', ' '); } @@ -45,16 +45,16 @@ function utcDateTimeStr(date) { * @param str - needs to be in the ISO 8601 format "YYYY-MM-DDTHH:MM:SS.sssZ" format as outputted by dateStr(). * also is assumed to be GMT time (as indicated by the "Z" at the end), *not* local time */ -function parseDateTime(str) { +function parseDateTime(str: string) { try { return new Date(Date.parse(str)); } - catch (e) { + catch (e: any) { throw new Error(`Can't parse date from '${str}': ${e.stack}`); } } -function parseLocalDate(str) { +function parseLocalDate(str: string) { const datePart = str.substr(0, 10); // not specifying the timezone and specifying the time means Date.parse() will use the local timezone @@ -65,7 +65,7 @@ function getDateTimeForFile() { return new Date().toISOString().substr(0, 19).replace(/:/g, ''); } -function validateLocalDateTime(str) { +function validateLocalDateTime(str: string) { if (!str) { return; } @@ -80,7 +80,7 @@ function validateLocalDateTime(str) { } } -function validateUtcDateTime(str) { +function validateUtcDateTime(str: string) { if (!str) { return; } From 82a9808dea63dddf975a6798182f3469272af38b Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Fri, 16 Feb 2024 22:44:12 +0200 Subject: [PATCH 11/49] server-ts: sql.js -> sql.ts --- .../0216__move_content_into_blobs.js | 2 +- .../0220__migrate_images_to_attachments.js | 2 +- dump-db/inc/data_key.js | 2 +- dump-db/inc/dump.js | 2 +- package-lock.json | 19 ++++ package.json | 1 + src/becca/becca.js | 2 +- src/becca/becca_loader.js | 2 +- src/becca/entities/abstract_becca_entity.js | 2 +- src/becca/entities/battachment.js | 2 +- src/becca/entities/battribute.js | 2 +- src/becca/entities/bnote.js | 2 +- src/becca/entities/brevision.js | 2 +- src/etapi/etapi_utils.js | 2 +- src/routes/api/attributes.js | 2 +- src/routes/api/branches.js | 2 +- src/routes/api/database.js | 2 +- src/routes/api/login.js | 2 +- src/routes/api/notes.js | 2 +- src/routes/api/recent_changes.js | 2 +- src/routes/api/recent_notes.js | 2 +- src/routes/api/relation-map.js | 2 +- src/routes/api/revisions.js | 2 +- src/routes/api/script.js | 2 +- src/routes/api/special_notes.js | 2 +- src/routes/api/sql.js | 2 +- src/routes/api/stats.js | 2 +- src/routes/api/sync.js | 2 +- src/routes/custom.js | 2 +- src/routes/index.js | 2 +- src/routes/routes.js | 4 +- src/services/anonymization.js | 2 +- src/services/attributes.js | 2 +- src/services/backend_script_api.js | 2 +- src/services/backup.js | 2 +- src/services/branches.js | 2 +- src/services/cloning.js | 2 +- src/services/consistency_checks.js | 2 +- src/services/content_hash.js | 2 +- src/services/date_notes.js | 2 +- src/services/encryption/password.js | 2 +- src/services/entity_changes.js | 2 +- src/services/erase.js | 2 +- src/services/image.js | 2 +- src/services/import/enex.js | 2 +- src/services/migration.js | 2 +- src/services/notes.js | 2 +- src/services/options.js | 2 +- src/services/revisions.js | 2 +- .../expressions/note_content_fulltext.js | 2 +- src/services/search/services/search.js | 2 +- src/services/{sql.js => sql.ts} | 89 ++++++++++--------- src/services/sql_init.js | 2 +- src/services/sync.js | 2 +- src/services/sync_update.js | 2 +- src/services/tree.js | 2 +- src/services/ws.js | 2 +- src/share/shaca/entities/sattachment.js | 2 +- src/share/shaca/entities/snote.js | 2 +- src/share/shaca/shaca_loader.js | 2 +- 60 files changed, 125 insertions(+), 100 deletions(-) rename src/services/{sql.js => sql.ts} (77%) diff --git a/db/migrations/0216__move_content_into_blobs.js b/db/migrations/0216__move_content_into_blobs.js index 3f67351b7..eea287b21 100644 --- a/db/migrations/0216__move_content_into_blobs.js +++ b/db/migrations/0216__move_content_into_blobs.js @@ -1,5 +1,5 @@ module.exports = () => { - const sql = require('../../src/services/sql.js'); + const sql = require('../../src/services/sql'); const utils = require('../../src/services/utils'); const existingBlobIds = new Set(); diff --git a/db/migrations/0220__migrate_images_to_attachments.js b/db/migrations/0220__migrate_images_to_attachments.js index 81bb84a3f..e949626ef 100644 --- a/db/migrations/0220__migrate_images_to_attachments.js +++ b/db/migrations/0220__migrate_images_to_attachments.js @@ -3,7 +3,7 @@ module.exports = () => { const becca = require('../../src/becca/becca.js'); const cls = require('../../src/services/cls'); const log = require('../../src/services/log'); - const sql = require('../../src/services/sql.js'); + const sql = require('../../src/services/sql'); cls.init(() => { // emergency disabling of image compression since it appears to make problems in migration to 0.61 diff --git a/dump-db/inc/data_key.js b/dump-db/inc/data_key.js index 58d3dd850..1dfc0dacf 100644 --- a/dump-db/inc/data_key.js +++ b/dump-db/inc/data_key.js @@ -1,5 +1,5 @@ const crypto = require("crypto"); -const sql = require('./sql.js'); +const sql = require('./sql'); const decryptService = require('./decrypt.js'); function getDataKey(password) { diff --git a/dump-db/inc/dump.js b/dump-db/inc/dump.js index 96fa60f94..7e3c1e1b3 100644 --- a/dump-db/inc/dump.js +++ b/dump-db/inc/dump.js @@ -1,6 +1,6 @@ const fs = require("fs"); const sanitize = require("sanitize-filename"); -const sql = require('./sql.js'); +const sql = require('./sql'); const decryptService = require('./decrypt.js'); const dataKeyService = require('./data_key.js'); const extensionService = require('./extension.js'); diff --git a/package-lock.json b/package-lock.json index 399043518..79c32b0f0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -89,6 +89,7 @@ "trilium": "src/www.js" }, "devDependencies": { + "@types/better-sqlite3": "^7.6.9", "@types/escape-html": "^1.0.4", "@types/express": "^4.17.21", "@types/mime-types": "^2.1.4", @@ -1284,6 +1285,15 @@ "resolved": "https://registry.npmjs.org/@tweenjs/tween.js/-/tween.js-21.0.0.tgz", "integrity": "sha512-qVfOiFh0U8ZSkLgA6tf7kj2MciqRbSCWaJZRwftVO7UbtVDNsZAXpWXqvCDtIefvjC83UJB+vHTDOGm5ibXjEA==" }, + "node_modules/@types/better-sqlite3": { + "version": "7.6.9", + "resolved": "https://registry.npmjs.org/@types/better-sqlite3/-/better-sqlite3-7.6.9.tgz", + "integrity": "sha512-FvktcujPDj9XKMJQWFcl2vVl7OdRIqsSRX9b0acWwTmwLK9CF2eqo/FRcmMLNpugKoX/avA6pb7TorDLmpgTnQ==", + "dev": true, + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/body-parser": { "version": "1.19.5", "resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.19.5.tgz", @@ -15917,6 +15927,15 @@ "resolved": "https://registry.npmjs.org/@tweenjs/tween.js/-/tween.js-21.0.0.tgz", "integrity": "sha512-qVfOiFh0U8ZSkLgA6tf7kj2MciqRbSCWaJZRwftVO7UbtVDNsZAXpWXqvCDtIefvjC83UJB+vHTDOGm5ibXjEA==" }, + "@types/better-sqlite3": { + "version": "7.6.9", + "resolved": "https://registry.npmjs.org/@types/better-sqlite3/-/better-sqlite3-7.6.9.tgz", + "integrity": "sha512-FvktcujPDj9XKMJQWFcl2vVl7OdRIqsSRX9b0acWwTmwLK9CF2eqo/FRcmMLNpugKoX/avA6pb7TorDLmpgTnQ==", + "dev": true, + "requires": { + "@types/node": "*" + } + }, "@types/body-parser": { "version": "1.19.5", "resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.19.5.tgz", diff --git a/package.json b/package.json index 1678ffe4d..608d4c3a4 100644 --- a/package.json +++ b/package.json @@ -112,6 +112,7 @@ "yauzl": "2.10.0" }, "devDependencies": { + "@types/better-sqlite3": "^7.6.9", "@types/escape-html": "^1.0.4", "@types/express": "^4.17.21", "@types/mime-types": "^2.1.4", diff --git a/src/becca/becca.js b/src/becca/becca.js index d1e7c333e..1d39d7282 100644 --- a/src/becca/becca.js +++ b/src/becca/becca.js @@ -1,6 +1,6 @@ "use strict"; -const sql = require('../services/sql.js'); +const sql = require('../services/sql'); const NoteSet = require('../services/search/note_set.js'); const NotFoundError = require('../errors/not_found_error.js'); diff --git a/src/becca/becca_loader.js b/src/becca/becca_loader.js index 39989090e..ad64570a0 100644 --- a/src/becca/becca_loader.js +++ b/src/becca/becca_loader.js @@ -1,6 +1,6 @@ "use strict"; -const sql = require('../services/sql.js'); +const sql = require('../services/sql'); const eventService = require('../services/events.js'); const becca = require('./becca.js'); const sqlInit = require('../services/sql_init.js'); diff --git a/src/becca/entities/abstract_becca_entity.js b/src/becca/entities/abstract_becca_entity.js index b1c7feac9..368c55423 100644 --- a/src/becca/entities/abstract_becca_entity.js +++ b/src/becca/entities/abstract_becca_entity.js @@ -1,7 +1,7 @@ "use strict"; const utils = require('../../services/utils'); -const sql = require('../../services/sql.js'); +const sql = require('../../services/sql'); const entityChangesService = require('../../services/entity_changes.js'); const eventService = require('../../services/events.js'); const dateUtils = require('../../services/date_utils'); diff --git a/src/becca/entities/battachment.js b/src/becca/entities/battachment.js index 49a22ef0d..689590bce 100644 --- a/src/becca/entities/battachment.js +++ b/src/becca/entities/battachment.js @@ -3,7 +3,7 @@ const utils = require('../../services/utils'); const dateUtils = require('../../services/date_utils'); const AbstractBeccaEntity = require('./abstract_becca_entity.js'); -const sql = require('../../services/sql.js'); +const sql = require('../../services/sql'); const protectedSessionService = require('../../services/protected_session.js'); const log = require('../../services/log'); diff --git a/src/becca/entities/battribute.js b/src/becca/entities/battribute.js index 3598b0671..54afd3587 100644 --- a/src/becca/entities/battribute.js +++ b/src/becca/entities/battribute.js @@ -2,7 +2,7 @@ const BNote = require('./bnote.js'); const AbstractBeccaEntity = require('./abstract_becca_entity.js'); -const sql = require('../../services/sql.js'); +const sql = require('../../services/sql'); const dateUtils = require('../../services/date_utils'); const promotedAttributeDefinitionParser = require('../../services/promoted_attribute_definition_parser.js'); const {sanitizeAttributeName} = require('../../services/sanitize_attribute_name.js'); diff --git a/src/becca/entities/bnote.js b/src/becca/entities/bnote.js index 77776750d..7372b4d0d 100644 --- a/src/becca/entities/bnote.js +++ b/src/becca/entities/bnote.js @@ -2,7 +2,7 @@ const protectedSessionService = require('../../services/protected_session.js'); const log = require('../../services/log'); -const sql = require('../../services/sql.js'); +const sql = require('../../services/sql'); const utils = require('../../services/utils'); const dateUtils = require('../../services/date_utils'); const AbstractBeccaEntity = require('./abstract_becca_entity.js'); diff --git a/src/becca/entities/brevision.js b/src/becca/entities/brevision.js index e70726d1b..690ed6311 100644 --- a/src/becca/entities/brevision.js +++ b/src/becca/entities/brevision.js @@ -5,7 +5,7 @@ const utils = require('../../services/utils'); const dateUtils = require('../../services/date_utils'); const becca = require('../becca.js'); const AbstractBeccaEntity = require('./abstract_becca_entity.js'); -const sql = require('../../services/sql.js'); +const sql = require('../../services/sql'); const BAttachment = require('./battachment.js'); /** diff --git a/src/etapi/etapi_utils.js b/src/etapi/etapi_utils.js index 24c179a23..41d40cf94 100644 --- a/src/etapi/etapi_utils.js +++ b/src/etapi/etapi_utils.js @@ -1,5 +1,5 @@ const cls = require('../services/cls'); -const sql = require('../services/sql.js'); +const sql = require('../services/sql'); const log = require('../services/log'); const becca = require('../becca/becca.js'); const etapiTokenService = require('../services/etapi_tokens.js'); diff --git a/src/routes/api/attributes.js b/src/routes/api/attributes.js index 480cb8b3f..b602aba6c 100644 --- a/src/routes/api/attributes.js +++ b/src/routes/api/attributes.js @@ -1,6 +1,6 @@ "use strict"; -const sql = require('../../services/sql.js'); +const sql = require('../../services/sql'); const log = require('../../services/log'); const attributeService = require('../../services/attributes.js'); const BAttribute = require('../../becca/entities/battribute.js'); diff --git a/src/routes/api/branches.js b/src/routes/api/branches.js index fc2830b76..bca2a87a0 100644 --- a/src/routes/api/branches.js +++ b/src/routes/api/branches.js @@ -1,6 +1,6 @@ "use strict"; -const sql = require('../../services/sql.js'); +const sql = require('../../services/sql'); const utils = require('../../services/utils'); const entityChangesService = require('../../services/entity_changes.js'); const treeService = require('../../services/tree.js'); diff --git a/src/routes/api/database.js b/src/routes/api/database.js index 6d6fcddf4..6c8063fe1 100644 --- a/src/routes/api/database.js +++ b/src/routes/api/database.js @@ -1,6 +1,6 @@ "use strict"; -const sql = require('../../services/sql.js'); +const sql = require('../../services/sql'); const log = require('../../services/log'); const backupService = require('../../services/backup.js'); const anonymizationService = require('../../services/anonymization.js'); diff --git a/src/routes/api/login.js b/src/routes/api/login.js index 7aed6955a..9c3536a04 100644 --- a/src/routes/api/login.js +++ b/src/routes/api/login.js @@ -9,7 +9,7 @@ const protectedSessionService = require('../../services/protected_session.js'); const appInfo = require('../../services/app_info.js'); const eventService = require('../../services/events.js'); const sqlInit = require('../../services/sql_init.js'); -const sql = require('../../services/sql.js'); +const sql = require('../../services/sql'); const ws = require('../../services/ws.js'); const etapiTokenService = require('../../services/etapi_tokens.js'); diff --git a/src/routes/api/notes.js b/src/routes/api/notes.js index 0ce570892..5a0787c27 100644 --- a/src/routes/api/notes.js +++ b/src/routes/api/notes.js @@ -3,7 +3,7 @@ const noteService = require('../../services/notes.js'); const eraseService = require('../../services/erase.js'); const treeService = require('../../services/tree.js'); -const sql = require('../../services/sql.js'); +const sql = require('../../services/sql'); const utils = require('../../services/utils'); const log = require('../../services/log'); const TaskContext = require('../../services/task_context.js'); diff --git a/src/routes/api/recent_changes.js b/src/routes/api/recent_changes.js index 567abfb3a..8023a4875 100644 --- a/src/routes/api/recent_changes.js +++ b/src/routes/api/recent_changes.js @@ -1,6 +1,6 @@ "use strict"; -const sql = require('../../services/sql.js'); +const sql = require('../../services/sql'); const protectedSessionService = require('../../services/protected_session.js'); const noteService = require('../../services/notes.js'); const becca = require('../../becca/becca.js'); diff --git a/src/routes/api/recent_notes.js b/src/routes/api/recent_notes.js index 80ccd9fea..5f71633bb 100644 --- a/src/routes/api/recent_notes.js +++ b/src/routes/api/recent_notes.js @@ -1,7 +1,7 @@ "use strict"; const BRecentNote = require('../../becca/entities/brecent_note.js'); -const sql = require('../../services/sql.js'); +const sql = require('../../services/sql'); const dateUtils = require('../../services/date_utils'); function addRecentNote(req) { diff --git a/src/routes/api/relation-map.js b/src/routes/api/relation-map.js index 0c3db4e6d..dc89ab5bb 100644 --- a/src/routes/api/relation-map.js +++ b/src/routes/api/relation-map.js @@ -1,5 +1,5 @@ const becca = require('../../becca/becca.js'); -const sql = require('../../services/sql.js'); +const sql = require('../../services/sql'); function getRelationMap(req) { const {relationMapNoteId, noteIds} = req.body; diff --git a/src/routes/api/revisions.js b/src/routes/api/revisions.js index bf378d625..6a75f98ab 100644 --- a/src/routes/api/revisions.js +++ b/src/routes/api/revisions.js @@ -3,7 +3,7 @@ const beccaService = require('../../becca/becca_service.js'); const revisionService = require('../../services/revisions.js'); const utils = require('../../services/utils'); -const sql = require('../../services/sql.js'); +const sql = require('../../services/sql'); const cls = require('../../services/cls'); const path = require('path'); const becca = require('../../becca/becca.js'); diff --git a/src/routes/api/script.js b/src/routes/api/script.js index 833a57b9b..441d67e54 100644 --- a/src/routes/api/script.js +++ b/src/routes/api/script.js @@ -4,7 +4,7 @@ const scriptService = require('../../services/script.js'); const attributeService = require('../../services/attributes.js'); const becca = require('../../becca/becca.js'); const syncService = require('../../services/sync.js'); -const sql = require('../../services/sql.js'); +const sql = require('../../services/sql'); // The async/await here is very confusing, because the body.script may, but may not be async. If it is async, then we // need to await it and make the complete response including metadata available in a Promise, so that the route detects diff --git a/src/routes/api/special_notes.js b/src/routes/api/special_notes.js index d39406f54..3c223f767 100644 --- a/src/routes/api/special_notes.js +++ b/src/routes/api/special_notes.js @@ -1,7 +1,7 @@ "use strict"; const dateNoteService = require('../../services/date_notes.js'); -const sql = require('../../services/sql.js'); +const sql = require('../../services/sql'); const cls = require('../../services/cls'); const specialNotesService = require('../../services/special_notes.js'); const becca = require('../../becca/becca.js'); diff --git a/src/routes/api/sql.js b/src/routes/api/sql.js index 6a9767317..65c381f8b 100644 --- a/src/routes/api/sql.js +++ b/src/routes/api/sql.js @@ -1,6 +1,6 @@ "use strict"; -const sql = require('../../services/sql.js'); +const sql = require('../../services/sql'); const becca = require('../../becca/becca.js'); function getSchema() { diff --git a/src/routes/api/stats.js b/src/routes/api/stats.js index d67d624d3..4e1ad74fe 100644 --- a/src/routes/api/stats.js +++ b/src/routes/api/stats.js @@ -1,4 +1,4 @@ -const sql = require('../../services/sql.js'); +const sql = require('../../services/sql'); const becca = require('../../becca/becca.js'); function getNoteSize(req) { diff --git a/src/routes/api/sync.js b/src/routes/api/sync.js index ecf22c060..5c6dbc799 100644 --- a/src/routes/api/sync.js +++ b/src/routes/api/sync.js @@ -3,7 +3,7 @@ const syncService = require('../../services/sync.js'); const syncUpdateService = require('../../services/sync_update.js'); const entityChangesService = require('../../services/entity_changes.js'); -const sql = require('../../services/sql.js'); +const sql = require('../../services/sql'); const sqlInit = require('../../services/sql_init.js'); const optionService = require('../../services/options.js'); const contentHashService = require('../../services/content_hash.js'); diff --git a/src/routes/custom.js b/src/routes/custom.js index 1d002b964..21fca8854 100644 --- a/src/routes/custom.js +++ b/src/routes/custom.js @@ -2,7 +2,7 @@ const log = require('../services/log'); const fileService = require('./api/files.js'); const scriptService = require('../services/script.js'); const cls = require('../services/cls'); -const sql = require('../services/sql.js'); +const sql = require('../services/sql'); const becca = require('../becca/becca.js'); function handleRequest(req, res) { diff --git a/src/routes/index.js b/src/routes/index.js index ef8f631a2..128742e99 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -1,6 +1,6 @@ "use strict"; -const sql = require('../services/sql.js'); +const sql = require('../services/sql'); const attributeService = require('../services/attributes.js'); const config = require('../services/config.js'); const optionService = require('../services/options.js'); diff --git a/src/routes/routes.js b/src/routes/routes.js index 79914e3fd..014d6b11d 100644 --- a/src/routes/routes.js +++ b/src/routes/routes.js @@ -7,7 +7,7 @@ const express = require('express'); const router = express.Router(); const auth = require('../services/auth.js'); const cls = require('../services/cls'); -const sql = require('../services/sql.js'); +const sql = require('../services/sql'); const entityChangesService = require('../services/entity_changes.js'); const csurf = require('csurf'); const { createPartialContentHandler } = require("express-partial-content"); @@ -39,7 +39,7 @@ const appInfoRoute = require('./api/app_info.js'); const exportRoute = require('./api/export.js'); const importRoute = require('./api/import.js'); const setupApiRoute = require('./api/setup.js'); -const sqlRoute = require('./api/sql.js'); +const sqlRoute = require('./api/sql'); const databaseRoute = require('./api/database.js'); const imageRoute = require('./api/image.js'); const attributesRoute = require('./api/attributes.js'); diff --git a/src/services/anonymization.js b/src/services/anonymization.js index 0fc774895..6a223ec4e 100644 --- a/src/services/anonymization.js +++ b/src/services/anonymization.js @@ -3,7 +3,7 @@ const fs = require("fs-extra"); const dataDir = require('./data_dir'); const dateUtils = require('./date_utils'); const Database = require("better-sqlite3"); -const sql = require('./sql.js'); +const sql = require('./sql'); const path = require("path"); function getFullAnonymizationScript() { diff --git a/src/services/attributes.js b/src/services/attributes.js index 632a6e09a..02e0d53f4 100644 --- a/src/services/attributes.js +++ b/src/services/attributes.js @@ -1,7 +1,7 @@ "use strict"; const searchService = require('./search/services/search.js'); -const sql = require('./sql.js'); +const sql = require('./sql'); const becca = require('../becca/becca.js'); const BAttribute = require('../becca/entities/battribute.js'); const {formatAttrForSearch} = require('./attribute_formatter.js'); diff --git a/src/services/backend_script_api.js b/src/services/backend_script_api.js index 2836018ec..7a6141586 100644 --- a/src/services/backend_script_api.js +++ b/src/services/backend_script_api.js @@ -1,6 +1,6 @@ const log = require('./log'); const noteService = require('./notes.js'); -const sql = require('./sql.js'); +const sql = require('./sql'); const utils = require('./utils'); const attributeService = require('./attributes.js'); const dateNoteService = require('./date_notes.js'); diff --git a/src/services/backup.js b/src/services/backup.js index c9ae0edba..772d92d55 100644 --- a/src/services/backup.js +++ b/src/services/backup.js @@ -7,7 +7,7 @@ const dataDir = require('./data_dir'); const log = require('./log'); const syncMutexService = require('./sync_mutex.js'); const cls = require('./cls'); -const sql = require('./sql.js'); +const sql = require('./sql'); const path = require('path'); function getExistingBackups() { diff --git a/src/services/branches.js b/src/services/branches.js index 644bde80e..ec0632745 100644 --- a/src/services/branches.js +++ b/src/services/branches.js @@ -1,5 +1,5 @@ const treeService = require('./tree.js'); -const sql = require('./sql.js'); +const sql = require('./sql'); function moveBranchToNote(branchToMove, targetParentNoteId) { if (branchToMove.parentNoteId === targetParentNoteId) { diff --git a/src/services/cloning.js b/src/services/cloning.js index 6c2f0c161..a715dd3a1 100644 --- a/src/services/cloning.js +++ b/src/services/cloning.js @@ -1,6 +1,6 @@ "use strict"; -const sql = require('./sql.js'); +const sql = require('./sql'); const eventChangesService = require('./entity_changes.js'); const treeService = require('./tree.js'); const BBranch = require('../becca/entities/bbranch.js'); diff --git a/src/services/consistency_checks.js b/src/services/consistency_checks.js index e7b11d290..1b0990328 100644 --- a/src/services/consistency_checks.js +++ b/src/services/consistency_checks.js @@ -1,6 +1,6 @@ "use strict"; -const sql = require('./sql.js'); +const sql = require('./sql'); const sqlInit = require('./sql_init.js'); const log = require('./log'); const ws = require('./ws.js'); diff --git a/src/services/content_hash.js b/src/services/content_hash.js index 8e01c067f..a42c16503 100644 --- a/src/services/content_hash.js +++ b/src/services/content_hash.js @@ -1,6 +1,6 @@ "use strict"; -const sql = require('./sql.js'); +const sql = require('./sql'); const utils = require('./utils'); const log = require('./log'); const eraseService = require('./erase.js'); diff --git a/src/services/date_notes.js b/src/services/date_notes.js index 122082f57..f258d2893 100644 --- a/src/services/date_notes.js +++ b/src/services/date_notes.js @@ -3,7 +3,7 @@ const noteService = require('./notes.js'); const attributeService = require('./attributes.js'); const dateUtils = require('./date_utils'); -const sql = require('./sql.js'); +const sql = require('./sql'); const protectedSessionService = require('./protected_session.js'); const searchService = require('../services/search/services/search.js'); const SearchContext = require('../services/search/search_context.js'); diff --git a/src/services/encryption/password.js b/src/services/encryption/password.js index f9665b585..95660fcf7 100644 --- a/src/services/encryption/password.js +++ b/src/services/encryption/password.js @@ -1,6 +1,6 @@ "use strict"; -const sql = require('../sql.js'); +const sql = require('../sql'); const optionService = require('../options.js'); const myScryptService = require('./my_scrypt.js'); const utils = require('../utils'); diff --git a/src/services/entity_changes.js b/src/services/entity_changes.js index 520c29718..209afc359 100644 --- a/src/services/entity_changes.js +++ b/src/services/entity_changes.js @@ -1,4 +1,4 @@ -const sql = require('./sql.js'); +const sql = require('./sql'); const dateUtils = require('./date_utils'); const log = require('./log'); const cls = require('./cls'); diff --git a/src/services/erase.js b/src/services/erase.js index dc43fc088..05719a480 100644 --- a/src/services/erase.js +++ b/src/services/erase.js @@ -1,4 +1,4 @@ -const sql = require("./sql.js"); +const sql = require("./sql"); const revisionService = require("./revisions.js"); const log = require("./log.ts"); const entityChangesService = require("./entity_changes.js"); diff --git a/src/services/image.js b/src/services/image.js index 8ef302708..7113b6aca 100644 --- a/src/services/image.js +++ b/src/services/image.js @@ -5,7 +5,7 @@ const log = require('./log'); const protectedSessionService = require('./protected_session.js'); const noteService = require('./notes.js'); const optionService = require('./options.js'); -const sql = require('./sql.js'); +const sql = require('./sql'); const jimp = require('jimp'); const imageType = require('image-type'); const sanitizeFilename = require('sanitize-filename'); diff --git a/src/services/import/enex.js b/src/services/import/enex.js index 72f9554ae..c9565cd04 100644 --- a/src/services/import/enex.js +++ b/src/services/import/enex.js @@ -3,7 +3,7 @@ const stream = require('stream'); const {Throttle} = require('stream-throttle'); const log = require('../log'); const utils = require('../utils'); -const sql = require('../sql.js'); +const sql = require('../sql'); const noteService = require('../notes.js'); const imageService = require('../image.js'); const protectedSessionService = require('../protected_session.js'); diff --git a/src/services/migration.js b/src/services/migration.js index 17aa5e222..efe122a46 100644 --- a/src/services/migration.js +++ b/src/services/migration.js @@ -1,5 +1,5 @@ const backupService = require('./backup.js'); -const sql = require('./sql.js'); +const sql = require('./sql'); const fs = require('fs-extra'); const log = require('./log'); const utils = require('./utils'); diff --git a/src/services/notes.js b/src/services/notes.js index 77ed66984..27aa15f62 100644 --- a/src/services/notes.js +++ b/src/services/notes.js @@ -1,4 +1,4 @@ -const sql = require('./sql.js'); +const sql = require('./sql'); const optionService = require('./options.js'); const dateUtils = require('./date_utils'); const entityChangesService = require('./entity_changes.js'); diff --git a/src/services/options.js b/src/services/options.js index 6c33b9478..e7e90331b 100644 --- a/src/services/options.js +++ b/src/services/options.js @@ -1,5 +1,5 @@ const becca = require('../becca/becca.js'); -const sql = require('./sql.js'); +const sql = require('./sql'); /** @returns {string|null} */ function getOptionOrNull(name) { diff --git a/src/services/revisions.js b/src/services/revisions.js index 084f941f9..e4b2dd9ed 100644 --- a/src/services/revisions.js +++ b/src/services/revisions.js @@ -1,7 +1,7 @@ "use strict"; const log = require('./log'); -const sql = require('./sql.js'); +const sql = require('./sql'); const protectedSessionService = require('./protected_session.js'); const dateUtils = require('./date_utils'); diff --git a/src/services/search/expressions/note_content_fulltext.js b/src/services/search/expressions/note_content_fulltext.js index 48ab61a82..951d0cd6b 100644 --- a/src/services/search/expressions/note_content_fulltext.js +++ b/src/services/search/expressions/note_content_fulltext.js @@ -38,7 +38,7 @@ class NoteContentFulltextExp extends Expression { } const resultNoteSet = new NoteSet(); - const sql = require('../../sql.js'); + const sql = require('../../sql'); for (const row of sql.iterateRows(` SELECT noteId, type, mime, content, isProtected diff --git a/src/services/search/services/search.js b/src/services/search/services/search.js index 496d420e0..f6b309ad3 100644 --- a/src/services/search/services/search.js +++ b/src/services/search/services/search.js @@ -90,7 +90,7 @@ function searchFromRelation(note, relationName) { } function loadNeededInfoFromDatabase() { - const sql = require('../../sql.js'); + const sql = require('../../sql'); /** * This complex structure is needed to calculate total occupied space by a note. Several object instances diff --git a/src/services/sql.js b/src/services/sql.ts similarity index 77% rename from src/services/sql.js rename to src/services/sql.ts index fc961b0da..f89330832 100644 --- a/src/services/sql.js +++ b/src/services/sql.ts @@ -4,17 +4,19 @@ * @module sql */ -const log = require('./log'); -const Database = require('better-sqlite3'); -const dataDir = require('./data_dir'); -const cls = require('./cls'); -const fs = require("fs-extra"); +import log = require('./log'); +import Database = require('better-sqlite3'); +import dataDir = require('./data_dir'); +import cls = require('./cls'); +import fs = require("fs-extra"); const dbConnection = new Database(dataDir.DOCUMENT_PATH); dbConnection.pragma('journal_mode = WAL'); const LOG_ALL_QUERIES = false; +type Params = any; + [`exit`, `SIGINT`, `SIGUSR1`, `SIGUSR2`, `SIGTERM`].forEach(eventType => { process.on(eventType, () => { if (dbConnection) { @@ -25,7 +27,7 @@ const LOG_ALL_QUERIES = false; }); }); -function insert(tableName, rec, replace = false) { +function insert(tableName: string, rec: T, replace = false) { const keys = Object.keys(rec || {}); if (keys.length === 0) { log.error(`Can't insert empty object into table ${tableName}`); @@ -48,11 +50,11 @@ function insert(tableName, rec, replace = false) { return res ? res.lastInsertRowid : null; } -function replace(tableName, rec) { +function replace(tableName: string, rec: T) { return insert(tableName, rec, true); } -function upsert(tableName, primaryKey, rec) { +function upsert(tableName: string, primaryKey: string, rec: T) { const keys = Object.keys(rec || {}); if (keys.length === 0) { log.error(`Can't upsert empty object into table ${tableName}`); @@ -70,16 +72,16 @@ function upsert(tableName, primaryKey, rec) { for (const idx in rec) { if (rec[idx] === true || rec[idx] === false) { - rec[idx] = rec[idx] ? 1 : 0; + (rec as any)[idx] = rec[idx] ? 1 : 0; } } execute(query, rec); } -const statementCache = {}; +const statementCache: Record = {}; -function stmt(sql) { +function stmt(sql: string) { if (!(sql in statementCache)) { statementCache[sql] = dbConnection.prepare(sql); } @@ -87,31 +89,34 @@ function stmt(sql) { return statementCache[sql]; } -function getRow(query, params = []) { - return wrap(query, s => s.get(params)); +function getRow(query: string, params: Params = []): T { + return wrap(query, s => s.get(params)) as T; } -function getRowOrNull(query, params = []) { +function getRowOrNull(query: string, params: Params = []): T | null { const all = getRows(query, params); + if (!all) { + return null; + } - return all.length > 0 ? all[0] : null; + return (all.length > 0 ? all[0] : null) as (T | null); } -function getValue(query, params = []) { +function getValue(query: string, params: Params = []) { return wrap(query, s => s.pluck().get(params)); } // smaller values can result in better performance due to better usage of statement cache const PARAM_LIMIT = 100; -function getManyRows(query, params) { - let results = []; +function getManyRows(query: string, params: Params) { + let results: unknown[] = []; while (params.length > 0) { const curParams = params.slice(0, Math.min(params.length, PARAM_LIMIT)); params = params.slice(curParams.length); - const curParamsObj = {}; + const curParamsObj: Record = {}; let j = 1; for (const param of curParams) { @@ -133,15 +138,15 @@ function getManyRows(query, params) { return results; } -function getRows(query, params = []) { - return wrap(query, s => s.all(params)); +function getRows(query: string, params: Params = []): unknown[] { + return wrap(query, s => s.all(params)) as unknown[]; } -function getRawRows(query, params = []) { - return wrap(query, s => s.raw().all(params)); +function getRawRows(query: string, params: Params = []): T[] | null { + return wrap(query, s => s.raw().all(params)) as T[] | null; } -function iterateRows(query, params = []) { +function iterateRows(query: string, params: Params = []) { if (LOG_ALL_QUERIES) { console.log(query); } @@ -149,26 +154,26 @@ function iterateRows(query, params = []) { return stmt(query).iterate(params); } -function getMap(query, params = []) { - const map = {}; - const results = getRawRows(query, params); +function getMap(query: string, params: Params = []) { + const map: Record = {} as Record; + const results = getRawRows(query, params); - for (const row of results) { - map[row[0]] = row[1]; + for (const row of results || []) { + map[row[0] as K] = row[1]; } return map; } -function getColumn(query, params = []) { +function getColumn(query: string, params: Params = []) { return wrap(query, s => s.pluck().all(params)); } -function execute(query, params = []) { - return wrap(query, s => s.run(params)); +function execute(query: string, params: Params = []): Database.RunResult { + return wrap(query, s => s.run(params)) as Database.RunResult; } -function executeMany(query, params) { +function executeMany(query: string, params: Params) { if (LOG_ALL_QUERIES) { console.log(query); } @@ -177,7 +182,7 @@ function executeMany(query, params) { const curParams = params.slice(0, Math.min(params.length, PARAM_LIMIT)); params = params.slice(curParams.length); - const curParamsObj = {}; + const curParamsObj: Record = {}; let j = 1; for (const param of curParams) { @@ -192,7 +197,7 @@ function executeMany(query, params) { } } -function executeScript(query) { +function executeScript(query: string) { if (LOG_ALL_QUERIES) { console.log(query); } @@ -200,7 +205,7 @@ function executeScript(query) { return dbConnection.exec(query); } -function wrap(query, func) { +function wrap(query: string, func: (statement: Database.Statement) => unknown): unknown { const startTimestamp = Date.now(); let result; @@ -211,7 +216,7 @@ function wrap(query, func) { try { result = func(stmt(query)); } - catch (e) { + catch (e: any) { if (e.message.includes("The database connection is not open")) { // this often happens on killing the app which puts these alerts in front of user // in these cases error should be simply ignored. @@ -237,9 +242,9 @@ function wrap(query, func) { return result; } -function transactional(func) { +function transactional(func: (statement: Database.Statement) => T) { try { - const ret = dbConnection.transaction(func).deferred(); + const ret = (dbConnection.transaction(func) as any).deferred(); if (!dbConnection.inTransaction) { // i.e. transaction was really committed (and not just savepoint released) require('./ws.js').sendTransactionEntityChangesToAllClients(); @@ -263,7 +268,7 @@ function transactional(func) { } } -function fillParamList(paramIds, truncate = true) { +function fillParamList(paramIds: string[], truncate = true) { if (paramIds.length === 0) { return; } @@ -286,7 +291,7 @@ function fillParamList(paramIds, truncate = true) { s.run(paramIds); } -async function copyDatabase(targetFilePath) { +async function copyDatabase(targetFilePath: string) { try { fs.unlinkSync(targetFilePath); } catch (e) { @@ -295,7 +300,7 @@ async function copyDatabase(targetFilePath) { await dbConnection.backup(targetFilePath); } -function disableSlowQueryLogging(cb) { +function disableSlowQueryLogging(cb: () => T) { const orig = cls.isSlowQueryLoggingDisabled(); try { diff --git a/src/services/sql_init.js b/src/services/sql_init.js index 298542a7b..f11763886 100644 --- a/src/services/sql_init.js +++ b/src/services/sql_init.js @@ -1,7 +1,7 @@ const log = require('./log'); const fs = require('fs'); const resourceDir = require('./resource_dir.js'); -const sql = require('./sql.js'); +const sql = require('./sql'); const utils = require('./utils'); const optionService = require('./options.js'); const port = require('./port.js'); diff --git a/src/services/sync.js b/src/services/sync.js index e31eb3654..9afd4704f 100644 --- a/src/services/sync.js +++ b/src/services/sync.js @@ -1,7 +1,7 @@ "use strict"; const log = require('./log'); -const sql = require('./sql.js'); +const sql = require('./sql'); const optionService = require('./options.js'); const utils = require('./utils'); const instanceId = require('./instance_id.js'); diff --git a/src/services/sync_update.js b/src/services/sync_update.js index f9695ba0c..5db427e1f 100644 --- a/src/services/sync_update.js +++ b/src/services/sync_update.js @@ -1,4 +1,4 @@ -const sql = require('./sql.js'); +const sql = require('./sql'); const log = require('./log'); const entityChangesService = require('./entity_changes.js'); const eventService = require('./events.js'); diff --git a/src/services/tree.js b/src/services/tree.js index 0ca25c536..7bbca25ab 100644 --- a/src/services/tree.js +++ b/src/services/tree.js @@ -1,6 +1,6 @@ "use strict"; -const sql = require('./sql.js'); +const sql = require('./sql'); const log = require('./log'); const BBranch = require('../becca/entities/bbranch.js'); const entityChangesService = require('./entity_changes.js'); diff --git a/src/services/ws.js b/src/services/ws.js index 8c6b64a3c..9e1f7f135 100644 --- a/src/services/ws.js +++ b/src/services/ws.js @@ -1,7 +1,7 @@ const WebSocket = require('ws'); const utils = require('./utils'); const log = require('./log'); -const sql = require('./sql.js'); +const sql = require('./sql'); const cls = require('./cls'); const config = require('./config.js'); const syncMutexService = require('./sync_mutex.js'); diff --git a/src/share/shaca/entities/sattachment.js b/src/share/shaca/entities/sattachment.js index 0c60b1332..4b76fea2c 100644 --- a/src/share/shaca/entities/sattachment.js +++ b/src/share/shaca/entities/sattachment.js @@ -1,6 +1,6 @@ "use strict"; -const sql = require('../../sql.js'); +const sql = require('../../sql'); const utils = require('../../../services/utils'); const AbstractShacaEntity = require('./abstract_shaca_entity.js'); diff --git a/src/share/shaca/entities/snote.js b/src/share/shaca/entities/snote.js index 99fd61efe..fd889c23f 100644 --- a/src/share/shaca/entities/snote.js +++ b/src/share/shaca/entities/snote.js @@ -1,6 +1,6 @@ "use strict"; -const sql = require('../../sql.js'); +const sql = require('../../sql'); const utils = require('../../../services/utils'); const AbstractShacaEntity = require('./abstract_shaca_entity.js'); const escape = require('escape-html'); diff --git a/src/share/shaca/shaca_loader.js b/src/share/shaca/shaca_loader.js index 850b820a4..aef4f36d5 100644 --- a/src/share/shaca/shaca_loader.js +++ b/src/share/shaca/shaca_loader.js @@ -1,6 +1,6 @@ "use strict"; -const sql = require('../sql.js'); +const sql = require('../sql'); const shaca = require('./shaca.js'); const log = require('../../services/log'); const SNote = require('./entities/snote.js'); From d3c9e7e1579f5f8afa1542c60920f1274383c00d Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Fri, 16 Feb 2024 22:50:49 +0200 Subject: [PATCH 12/49] server-ts: errors/*.js -> .ts --- src/errors/{not_found_error.js => not_found_error.ts} | 4 +++- src/errors/{validation_error.js => validation_error.ts} | 4 +++- src/routes/api/attachments.js | 2 +- src/routes/api/attributes.js | 2 +- src/routes/api/branches.js | 2 +- src/routes/api/export.js | 2 +- src/routes/api/files.js | 2 +- src/routes/api/import.js | 2 +- src/routes/api/notes.js | 2 +- src/routes/api/options.js | 2 +- src/routes/api/password.js | 2 +- src/routes/api/search.js | 2 +- src/routes/api/tree.js | 2 +- src/routes/login.js | 2 +- src/routes/routes.js | 4 ++-- src/services/export/zip.js | 2 +- src/services/notes.js | 2 +- 17 files changed, 22 insertions(+), 18 deletions(-) rename src/errors/{not_found_error.js => not_found_error.ts} (62%) rename src/errors/{validation_error.js => validation_error.ts} (63%) diff --git a/src/errors/not_found_error.js b/src/errors/not_found_error.ts similarity index 62% rename from src/errors/not_found_error.js rename to src/errors/not_found_error.ts index af746b82c..7ceb105a9 100644 --- a/src/errors/not_found_error.js +++ b/src/errors/not_found_error.ts @@ -1,5 +1,7 @@ class NotFoundError { - constructor(message) { + message: string; + + constructor(message: string) { this.message = message; } } diff --git a/src/errors/validation_error.js b/src/errors/validation_error.ts similarity index 63% rename from src/errors/validation_error.js rename to src/errors/validation_error.ts index 1c9425669..0cabecc8e 100644 --- a/src/errors/validation_error.js +++ b/src/errors/validation_error.ts @@ -1,5 +1,7 @@ class ValidationError { - constructor(message) { + message: string; + + constructor(message: string) { this.message = message; } } diff --git a/src/routes/api/attachments.js b/src/routes/api/attachments.js index 7862534a7..1beca350e 100644 --- a/src/routes/api/attachments.js +++ b/src/routes/api/attachments.js @@ -1,6 +1,6 @@ const becca = require('../../becca/becca.js'); const blobService = require('../../services/blob.js'); -const ValidationError = require('../../errors/validation_error.js'); +const ValidationError = require('../../errors/validation_error'); const imageService = require("../../services/image.js"); function getAttachmentBlob(req) { diff --git a/src/routes/api/attributes.js b/src/routes/api/attributes.js index b602aba6c..bdbab50c5 100644 --- a/src/routes/api/attributes.js +++ b/src/routes/api/attributes.js @@ -5,7 +5,7 @@ const log = require('../../services/log'); const attributeService = require('../../services/attributes.js'); const BAttribute = require('../../becca/entities/battribute.js'); const becca = require('../../becca/becca.js'); -const ValidationError = require('../../errors/validation_error.js'); +const ValidationError = require('../../errors/validation_error'); function getEffectiveNoteAttributes(req) { const note = becca.getNote(req.params.noteId); diff --git a/src/routes/api/branches.js b/src/routes/api/branches.js index bca2a87a0..4149a7315 100644 --- a/src/routes/api/branches.js +++ b/src/routes/api/branches.js @@ -9,7 +9,7 @@ const becca = require('../../becca/becca.js'); const TaskContext = require('../../services/task_context.js'); const branchService = require('../../services/branches.js'); const log = require('../../services/log'); -const ValidationError = require('../../errors/validation_error.js'); +const ValidationError = require('../../errors/validation_error'); const eventService = require("../../services/events.js"); /** diff --git a/src/routes/api/export.js b/src/routes/api/export.js index 673d7c7bf..240f2ef4c 100644 --- a/src/routes/api/export.js +++ b/src/routes/api/export.js @@ -6,7 +6,7 @@ const opmlExportService = require('../../services/export/opml.js'); const becca = require('../../becca/becca.js'); const TaskContext = require('../../services/task_context.js'); const log = require('../../services/log'); -const NotFoundError = require('../../errors/not_found_error.js'); +const NotFoundError = require('../../errors/not_found_error'); function exportBranch(req, res) { const {branchId, type, format, version, taskId} = req.params; diff --git a/src/routes/api/files.js b/src/routes/api/files.js index 48ec7c5ea..baee239a8 100644 --- a/src/routes/api/files.js +++ b/src/routes/api/files.js @@ -10,7 +10,7 @@ const { Readable } = require('stream'); const chokidar = require('chokidar'); const ws = require('../../services/ws.js'); const becca = require('../../becca/becca.js'); -const ValidationError = require('../../errors/validation_error.js'); +const ValidationError = require('../../errors/validation_error'); function updateFile(req) { const note = becca.getNoteOrThrow(req.params.noteId); diff --git a/src/routes/api/import.js b/src/routes/api/import.js index 9a29b7a7e..49dd027c4 100644 --- a/src/routes/api/import.js +++ b/src/routes/api/import.js @@ -10,7 +10,7 @@ const becca = require('../../becca/becca.js'); const beccaLoader = require('../../becca/becca_loader.js'); const log = require('../../services/log'); const TaskContext = require('../../services/task_context.js'); -const ValidationError = require('../../errors/validation_error.js'); +const ValidationError = require('../../errors/validation_error'); async function importNotesToBranch(req) { const {parentNoteId} = req.params; diff --git a/src/routes/api/notes.js b/src/routes/api/notes.js index 5a0787c27..6a3eaad25 100644 --- a/src/routes/api/notes.js +++ b/src/routes/api/notes.js @@ -8,7 +8,7 @@ const utils = require('../../services/utils'); const log = require('../../services/log'); const TaskContext = require('../../services/task_context.js'); const becca = require('../../becca/becca.js'); -const ValidationError = require('../../errors/validation_error.js'); +const ValidationError = require('../../errors/validation_error'); const blobService = require('../../services/blob.js'); function getNote(req) { diff --git a/src/routes/api/options.js b/src/routes/api/options.js index 52344891a..f3e294571 100644 --- a/src/routes/api/options.js +++ b/src/routes/api/options.js @@ -3,7 +3,7 @@ const optionService = require('../../services/options.js'); const log = require('../../services/log'); const searchService = require('../../services/search/services/search.js'); -const ValidationError = require('../../errors/validation_error.js'); +const ValidationError = require('../../errors/validation_error'); // options allowed to be updated directly in the Options dialog const ALLOWED_OPTIONS = new Set([ diff --git a/src/routes/api/password.js b/src/routes/api/password.js index a80d4151c..419a27aca 100644 --- a/src/routes/api/password.js +++ b/src/routes/api/password.js @@ -1,7 +1,7 @@ "use strict"; const passwordService = require('../../services/encryption/password.js'); -const ValidationError = require('../../errors/validation_error.js'); +const ValidationError = require('../../errors/validation_error'); function changePassword(req) { if (passwordService.isPasswordSet()) { diff --git a/src/routes/api/search.js b/src/routes/api/search.js index 901adbb26..0c2d486ed 100644 --- a/src/routes/api/search.js +++ b/src/routes/api/search.js @@ -6,7 +6,7 @@ const searchService = require('../../services/search/services/search.js'); const bulkActionService = require('../../services/bulk_actions.js'); const cls = require('../../services/cls'); const {formatAttrForSearch} = require('../../services/attribute_formatter.js'); -const ValidationError = require('../../errors/validation_error.js'); +const ValidationError = require('../../errors/validation_error'); function searchFromNote(req) { const note = becca.getNoteOrThrow(req.params.noteId); diff --git a/src/routes/api/tree.js b/src/routes/api/tree.js index f830ed8f1..50494fced 100644 --- a/src/routes/api/tree.js +++ b/src/routes/api/tree.js @@ -2,7 +2,7 @@ const becca = require('../../becca/becca.js'); const log = require('../../services/log'); -const NotFoundError = require('../../errors/not_found_error.js'); +const NotFoundError = require('../../errors/not_found_error'); function getNotesAndBranchesAndAttributes(noteIds) { noteIds = new Set(noteIds); diff --git a/src/routes/login.js b/src/routes/login.js index 2ea84a93b..69b1ea433 100644 --- a/src/routes/login.js +++ b/src/routes/login.js @@ -7,7 +7,7 @@ const log = require('../services/log'); const passwordService = require('../services/encryption/password.js'); const assetPath = require('../services/asset_path.js'); const appPath = require('../services/app_path.js'); -const ValidationError = require('../errors/validation_error.js'); +const ValidationError = require('../errors/validation_error'); function loginPage(req, res) { res.render('login', { diff --git a/src/routes/routes.js b/src/routes/routes.js index 014d6b11d..2bc50b359 100644 --- a/src/routes/routes.js +++ b/src/routes/routes.js @@ -13,8 +13,8 @@ const csurf = require('csurf'); const { createPartialContentHandler } = require("express-partial-content"); const rateLimit = require("express-rate-limit"); const AbstractBeccaEntity = require('../becca/entities/abstract_becca_entity.js'); -const NotFoundError = require('../errors/not_found_error.js'); -const ValidationError = require('../errors/validation_error.js'); +const NotFoundError = require('../errors/not_found_error'); +const ValidationError = require('../errors/validation_error'); // page routes const setupRoute = require('./setup.js'); diff --git a/src/services/export/zip.js b/src/services/export/zip.js index 5e2482013..e0ca9f3f2 100644 --- a/src/services/export/zip.js +++ b/src/services/export/zip.js @@ -15,7 +15,7 @@ const RESOURCE_DIR = require('../../services/resource_dir.js').RESOURCE_DIR; const archiver = require('archiver'); const log = require('../log'); const TaskContext = require('../task_context.js'); -const ValidationError = require('../../errors/validation_error.js'); +const ValidationError = require('../../errors/validation_error'); const NoteMeta = require('../meta/note_meta.js'); const AttachmentMeta = require('../meta/attachment_meta.js'); const AttributeMeta = require('../meta/attribute_meta.js'); diff --git a/src/services/notes.js b/src/services/notes.js index 27aa15f62..e73c2f706 100644 --- a/src/services/notes.js +++ b/src/services/notes.js @@ -18,7 +18,7 @@ const BAttribute = require('../becca/entities/battribute.js'); const BAttachment = require('../becca/entities/battachment.js'); const dayjs = require("dayjs"); const htmlSanitizer = require('./html_sanitizer.js'); -const ValidationError = require('../errors/validation_error.js'); +const ValidationError = require('../errors/validation_error'); const noteTypesService = require('./note_types.js'); const fs = require("fs"); const ws = require('./ws.js'); From dc359b2a74b82bb91c8a7f9537c054d4e1999ce9 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Fri, 16 Feb 2024 22:51:37 +0200 Subject: [PATCH 13/49] server-ts: resource_dir.js -> ts --- src/routes/api/image.js | 2 +- src/services/app_icon.js | 2 +- src/services/config.js | 2 +- src/services/export/zip.js | 2 +- src/services/migration.js | 2 +- src/services/{resource_dir.js => resource_dir.ts} | 6 +++--- src/services/sql_init.js | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) rename src/services/{resource_dir.js => resource_dir.ts} (88%) diff --git a/src/routes/api/image.js b/src/routes/api/image.js index 14b034119..a48978a0d 100644 --- a/src/routes/api/image.js +++ b/src/routes/api/image.js @@ -2,7 +2,7 @@ const imageService = require('../../services/image.js'); const becca = require('../../becca/becca.js'); -const RESOURCE_DIR = require('../../services/resource_dir.js').RESOURCE_DIR; +const RESOURCE_DIR = require('../../services/resource_dir').RESOURCE_DIR; const fs = require('fs'); function returnImageFromNote(req, res) { diff --git a/src/services/app_icon.js b/src/services/app_icon.js index 3e7b48e24..ec18dab45 100644 --- a/src/services/app_icon.js +++ b/src/services/app_icon.js @@ -1,7 +1,7 @@ "use strict"; const path = require('path'); -const {ELECTRON_APP_ROOT_DIR} = require('./resource_dir.js'); +const {ELECTRON_APP_ROOT_DIR} = require('./resource_dir'); const log = require('./log'); const os = require('os'); const fs = require('fs'); diff --git a/src/services/config.js b/src/services/config.js index c57942a8c..8bc0723a7 100644 --- a/src/services/config.js +++ b/src/services/config.js @@ -4,7 +4,7 @@ const ini = require('ini'); const fs = require('fs'); const dataDir = require('./data_dir'); const path = require('path'); -const resourceDir = require('./resource_dir.js'); +const resourceDir = require('./resource_dir'); const configSampleFilePath = path.resolve(resourceDir.RESOURCE_DIR, "config-sample.ini"); diff --git a/src/services/export/zip.js b/src/services/export/zip.js index e0ca9f3f2..79625eee1 100644 --- a/src/services/export/zip.js +++ b/src/services/export/zip.js @@ -11,7 +11,7 @@ const protectedSessionService = require('../protected_session.js'); const sanitize = require("sanitize-filename"); const fs = require("fs"); const becca = require('../../becca/becca.js'); -const RESOURCE_DIR = require('../../services/resource_dir.js').RESOURCE_DIR; +const RESOURCE_DIR = require('../../services/resource_dir').RESOURCE_DIR; const archiver = require('archiver'); const log = require('../log'); const TaskContext = require('../task_context.js'); diff --git a/src/services/migration.js b/src/services/migration.js index efe122a46..3b6caa251 100644 --- a/src/services/migration.js +++ b/src/services/migration.js @@ -3,7 +3,7 @@ const sql = require('./sql'); const fs = require('fs-extra'); const log = require('./log'); const utils = require('./utils'); -const resourceDir = require('./resource_dir.js'); +const resourceDir = require('./resource_dir'); const appInfo = require('./app_info.js'); const cls = require('./cls'); diff --git a/src/services/resource_dir.js b/src/services/resource_dir.ts similarity index 88% rename from src/services/resource_dir.js rename to src/services/resource_dir.ts index 4f3710e18..5bd21b31d 100644 --- a/src/services/resource_dir.js +++ b/src/services/resource_dir.ts @@ -1,6 +1,6 @@ -const log = require('./log'); -const path = require('path'); -const fs = require('fs'); +import log = require('./log'); +import path = require('path'); +import fs = require('fs'); const RESOURCE_DIR = path.resolve(__dirname, "../.."); diff --git a/src/services/sql_init.js b/src/services/sql_init.js index f11763886..4b89ae389 100644 --- a/src/services/sql_init.js +++ b/src/services/sql_init.js @@ -1,6 +1,6 @@ const log = require('./log'); const fs = require('fs'); -const resourceDir = require('./resource_dir.js'); +const resourceDir = require('./resource_dir'); const sql = require('./sql'); const utils = require('./utils'); const optionService = require('./options.js'); From c20d2273e672bb14190109db30e400a43f7c09b5 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Fri, 16 Feb 2024 23:03:19 +0200 Subject: [PATCH 14/49] server-ts: services/encryption/*.js -> ts --- ...{data_encryption.js => data_encryption.ts} | 25 ++++++++----------- .../encryption/{my_scrypt.js => my_scrypt.ts} | 12 ++++----- .../encryption/{password.js => password.ts} | 25 +++++++++++-------- ...d_encryption.js => password_encryption.ts} | 17 ++++++------- src/services/sql.ts | 2 +- src/services/utils.ts | 4 +-- 6 files changed, 42 insertions(+), 43 deletions(-) rename src/services/encryption/{data_encryption.js => data_encryption.ts} (85%) rename src/services/encryption/{my_scrypt.js => my_scrypt.ts} (58%) rename src/services/encryption/{password.js => password.ts} (78%) rename src/services/encryption/{password_encryption.js => password_encryption.ts} (70%) diff --git a/src/services/encryption/data_encryption.js b/src/services/encryption/data_encryption.ts similarity index 85% rename from src/services/encryption/data_encryption.js rename to src/services/encryption/data_encryption.ts index 2b18058c5..c19008a5b 100644 --- a/src/services/encryption/data_encryption.js +++ b/src/services/encryption/data_encryption.ts @@ -1,9 +1,9 @@ "use strict"; -const crypto = require('crypto'); -const log = require('../log'); +import crypto = require('crypto'); +import log = require('../log'); -function arraysIdentical(a, b) { +function arraysIdentical(a: Buffer, b: Buffer) { let i = a.length; if (i !== b.length) return false; while (i--) { @@ -12,12 +12,12 @@ function arraysIdentical(a, b) { return true; } -function shaArray(content) { +function shaArray(content: crypto.BinaryLike) { // we use this as a simple checksum and don't rely on its security, so SHA-1 is good enough return crypto.createHash('sha1').update(content).digest(); } -function pad(data) { +function pad(data: Buffer): Buffer { if (data.length > 16) { data = data.slice(0, 16); } @@ -30,7 +30,7 @@ function pad(data) { return Buffer.from(data); } -function encrypt(key, plainText) { +function encrypt(key: Buffer, plainText: Buffer | string) { if (!key) { throw new Error("No data key!"); } @@ -51,10 +51,7 @@ function encrypt(key, plainText) { return encryptedDataWithIv.toString('base64'); } -/** - * @returns {Buffer|false|null} - */ -function decrypt(key, cipherText) { +function decrypt(key: Buffer, cipherText: string | Buffer): Buffer | false | null { if (cipherText === null) { return null; } @@ -88,12 +85,12 @@ function decrypt(key, cipherText) { return payload; } - catch (e) { + catch (e: any) { // recovery from https://github.com/zadam/trilium/issues/510 if (e.message?.includes("WRONG_FINAL_BLOCK_LENGTH") || e.message?.includes("wrong final block length")) { log.info("Caught WRONG_FINAL_BLOCK_LENGTH, returning cipherText instead"); - return cipherText; + return Buffer.from(cipherText); } else { throw e; @@ -101,7 +98,7 @@ function decrypt(key, cipherText) { } } -function decryptString(dataKey, cipherText) { +function decryptString(dataKey: Buffer, cipherText: string) { const buffer = decrypt(dataKey, cipherText); if (buffer === null) { @@ -115,7 +112,7 @@ function decryptString(dataKey, cipherText) { return buffer.toString('utf-8'); } -module.exports = { +export = { encrypt, decrypt, decryptString diff --git a/src/services/encryption/my_scrypt.js b/src/services/encryption/my_scrypt.ts similarity index 58% rename from src/services/encryption/my_scrypt.js rename to src/services/encryption/my_scrypt.ts index bc01cdde7..9c7774923 100644 --- a/src/services/encryption/my_scrypt.js +++ b/src/services/encryption/my_scrypt.ts @@ -1,28 +1,28 @@ "use strict"; -const optionService = require('../options.js'); -const crypto = require('crypto'); +import optionService = require('../options.js'); +import crypto = require('crypto'); -function getVerificationHash(password) { +function getVerificationHash(password: crypto.BinaryLike) { const salt = optionService.getOption('passwordVerificationSalt'); return getScryptHash(password, salt); } -function getPasswordDerivedKey(password) { +function getPasswordDerivedKey(password: crypto.BinaryLike) { const salt = optionService.getOption('passwordDerivedKeySalt'); return getScryptHash(password, salt); } -function getScryptHash(password, salt) { +function getScryptHash(password: crypto.BinaryLike, salt: crypto.BinaryLike) { const hashed = crypto.scryptSync(password, salt, 32, {N: 16384, r:8, p:1}); return hashed; } -module.exports = { +export = { getVerificationHash, getPasswordDerivedKey }; diff --git a/src/services/encryption/password.js b/src/services/encryption/password.ts similarity index 78% rename from src/services/encryption/password.js rename to src/services/encryption/password.ts index 95660fcf7..07b4de85b 100644 --- a/src/services/encryption/password.js +++ b/src/services/encryption/password.ts @@ -1,16 +1,16 @@ "use strict"; -const sql = require('../sql'); -const optionService = require('../options.js'); -const myScryptService = require('./my_scrypt.js'); -const utils = require('../utils'); -const passwordEncryptionService = require('./password_encryption.js'); +import sql = require('../sql'); +import optionService = require('../options.js'); +import myScryptService = require('./my_scrypt.js'); +import utils = require('../utils'); +import passwordEncryptionService = require('./password_encryption.js'); function isPasswordSet() { return !!sql.getValue("SELECT value FROM options WHERE name = 'passwordVerificationHash'"); } -function changePassword(currentPassword, newPassword) { +function changePassword(currentPassword: string, newPassword: string) { if (!isPasswordSet()) { throw new Error("Password has not been set yet, so it cannot be changed. Use 'setPassword' instead."); } @@ -29,8 +29,11 @@ function changePassword(currentPassword, newPassword) { optionService.setOption('passwordDerivedKeySalt', utils.randomSecureToken(32)); const newPasswordVerificationKey = utils.toBase64(myScryptService.getVerificationHash(newPassword)); - - passwordEncryptionService.setDataKey(newPassword, decryptedDataKey); + + if (decryptedDataKey) { + // FIXME: what should happen if the decrypted data key is null? + passwordEncryptionService.setDataKey(newPassword, decryptedDataKey); + } optionService.setOption('passwordVerificationHash', newPasswordVerificationKey); }); @@ -40,7 +43,7 @@ function changePassword(currentPassword, newPassword) { }; } -function setPassword(password) { +function setPassword(password: string) { if (isPasswordSet()) { throw new Error("Password is set already. Either change it or perform 'reset password' first."); } @@ -48,13 +51,13 @@ function setPassword(password) { optionService.createOption('passwordVerificationSalt', utils.randomSecureToken(32), true); optionService.createOption('passwordDerivedKeySalt', utils.randomSecureToken(32), true); - const passwordVerificationKey = utils.toBase64(myScryptService.getVerificationHash(password), true); + const passwordVerificationKey = utils.toBase64(myScryptService.getVerificationHash(password)); optionService.createOption('passwordVerificationHash', passwordVerificationKey, true); // passwordEncryptionService expects these options to already exist optionService.createOption('encryptedDataKey', '', true); - passwordEncryptionService.setDataKey(password, utils.randomSecureToken(16), true); + passwordEncryptionService.setDataKey(password, utils.randomSecureToken(16)); return { success: true diff --git a/src/services/encryption/password_encryption.js b/src/services/encryption/password_encryption.ts similarity index 70% rename from src/services/encryption/password_encryption.js rename to src/services/encryption/password_encryption.ts index 06ada7d98..939de5a9d 100644 --- a/src/services/encryption/password_encryption.js +++ b/src/services/encryption/password_encryption.ts @@ -1,9 +1,9 @@ -const optionService = require('../options.js'); -const myScryptService = require('./my_scrypt.js'); -const utils = require('../utils'); -const dataEncryptionService = require('./data_encryption.js'); +import optionService = require('../options.js'); +import myScryptService = require('./my_scrypt.js'); +import utils = require('../utils'); +import dataEncryptionService = require('./data_encryption.js'); -function verifyPassword(password) { +function verifyPassword(password: string) { const givenPasswordHash = utils.toBase64(myScryptService.getVerificationHash(password)); const dbPasswordHash = optionService.getOptionOrNull('passwordVerificationHash'); @@ -15,7 +15,7 @@ function verifyPassword(password) { return givenPasswordHash === dbPasswordHash; } -function setDataKey(password, plainTextDataKey) { +function setDataKey(password: string, plainTextDataKey: string | Buffer) { const passwordDerivedKey = myScryptService.getPasswordDerivedKey(password); const newEncryptedDataKey = dataEncryptionService.encrypt(passwordDerivedKey, plainTextDataKey); @@ -23,8 +23,7 @@ function setDataKey(password, plainTextDataKey) { optionService.setOption('encryptedDataKey', newEncryptedDataKey); } -/** @return {Buffer} */ -function getDataKey(password) { +function getDataKey(password: string) { const passwordDerivedKey = myScryptService.getPasswordDerivedKey(password); const encryptedDataKey = optionService.getOption('encryptedDataKey'); @@ -34,7 +33,7 @@ function getDataKey(password) { return decryptedDataKey; } -module.exports = { +export = { verifyPassword, getDataKey, setDataKey diff --git a/src/services/sql.ts b/src/services/sql.ts index f89330832..8567cafaa 100644 --- a/src/services/sql.ts +++ b/src/services/sql.ts @@ -313,7 +313,7 @@ function disableSlowQueryLogging(cb: () => T) { } } -module.exports = { +export = { dbConnection, insert, replace, diff --git a/src/services/utils.ts b/src/services/utils.ts index d31e73482..9a3397f85 100644 --- a/src/services/utils.ts +++ b/src/services/utils.ts @@ -41,7 +41,7 @@ function hashedBlobId(content: string) { return kindaBase62Hash.substr(0, 20); } -function toBase64(plainText: string) { +function toBase64(plainText: string | Buffer) { return Buffer.from(plainText).toString('base64'); } @@ -311,7 +311,7 @@ function isString(x: any) { return Object.prototype.toString.call(x) === "[object String]"; } -module.exports = { +export = { randomSecureToken, randomString, md5, From b63e8700382e718974b3ff7b86bccb7d3c99e705 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Fri, 16 Feb 2024 23:09:59 +0200 Subject: [PATCH 15/49] server-ts: protected_session.js -> ts --- src/becca/entities/abstract_becca_entity.js | 2 +- src/becca/entities/battachment.js | 2 +- src/becca/entities/brevision.js | 2 +- src/routes/api/files.js | 2 +- src/routes/api/login.js | 2 +- src/routes/api/recent_changes.js | 2 +- src/routes/index.js | 2 +- src/services/date_notes.js | 2 +- src/services/export/zip.js | 2 +- src/services/image.js | 2 +- src/services/import/enex.js | 2 +- src/services/import/opml.js | 2 +- src/services/import/single.js | 2 +- src/services/import/zip.js | 2 +- src/services/notes.js | 2 +- ...tected_session.js => protected_session.ts} | 34 +++++++++++-------- src/services/revisions.js | 2 +- src/services/scheduler.js | 2 +- .../expressions/note_content_fulltext.js | 2 +- src/services/ws.js | 2 +- 20 files changed, 39 insertions(+), 33 deletions(-) rename src/services/{protected_session.js => protected_session.ts} (55%) diff --git a/src/becca/entities/abstract_becca_entity.js b/src/becca/entities/abstract_becca_entity.js index 368c55423..b72b13381 100644 --- a/src/becca/entities/abstract_becca_entity.js +++ b/src/becca/entities/abstract_becca_entity.js @@ -7,7 +7,7 @@ const eventService = require('../../services/events.js'); const dateUtils = require('../../services/date_utils'); const cls = require('../../services/cls'); const log = require('../../services/log'); -const protectedSessionService = require('../../services/protected_session.js'); +const protectedSessionService = require('../../services/protected_session'); const blobService = require('../../services/blob.js'); let becca = null; diff --git a/src/becca/entities/battachment.js b/src/becca/entities/battachment.js index 689590bce..5445ec3de 100644 --- a/src/becca/entities/battachment.js +++ b/src/becca/entities/battachment.js @@ -4,7 +4,7 @@ const utils = require('../../services/utils'); const dateUtils = require('../../services/date_utils'); const AbstractBeccaEntity = require('./abstract_becca_entity.js'); const sql = require('../../services/sql'); -const protectedSessionService = require('../../services/protected_session.js'); +const protectedSessionService = require('../../services/protected_session'); const log = require('../../services/log'); const attachmentRoleToNoteTypeMapping = { diff --git a/src/becca/entities/brevision.js b/src/becca/entities/brevision.js index 690ed6311..ad819ad90 100644 --- a/src/becca/entities/brevision.js +++ b/src/becca/entities/brevision.js @@ -1,6 +1,6 @@ "use strict"; -const protectedSessionService = require('../../services/protected_session.js'); +const protectedSessionService = require('../../services/protected_session'); const utils = require('../../services/utils'); const dateUtils = require('../../services/date_utils'); const becca = require('../becca.js'); diff --git a/src/routes/api/files.js b/src/routes/api/files.js index baee239a8..10a1b758e 100644 --- a/src/routes/api/files.js +++ b/src/routes/api/files.js @@ -1,6 +1,6 @@ "use strict"; -const protectedSessionService = require('../../services/protected_session.js'); +const protectedSessionService = require('../../services/protected_session'); const utils = require('../../services/utils'); const log = require('../../services/log'); const noteService = require('../../services/notes.js'); diff --git a/src/routes/api/login.js b/src/routes/api/login.js index 9c3536a04..ec5891c28 100644 --- a/src/routes/api/login.js +++ b/src/routes/api/login.js @@ -5,7 +5,7 @@ const utils = require('../../services/utils'); const dateUtils = require('../../services/date_utils'); const instanceId = require('../../services/instance_id.js'); const passwordEncryptionService = require('../../services/encryption/password_encryption.js'); -const protectedSessionService = require('../../services/protected_session.js'); +const protectedSessionService = require('../../services/protected_session'); const appInfo = require('../../services/app_info.js'); const eventService = require('../../services/events.js'); const sqlInit = require('../../services/sql_init.js'); diff --git a/src/routes/api/recent_changes.js b/src/routes/api/recent_changes.js index 8023a4875..8563c41a8 100644 --- a/src/routes/api/recent_changes.js +++ b/src/routes/api/recent_changes.js @@ -1,7 +1,7 @@ "use strict"; const sql = require('../../services/sql'); -const protectedSessionService = require('../../services/protected_session.js'); +const protectedSessionService = require('../../services/protected_session'); const noteService = require('../../services/notes.js'); const becca = require('../../becca/becca.js'); diff --git a/src/routes/index.js b/src/routes/index.js index 128742e99..2a8a07759 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -7,7 +7,7 @@ const optionService = require('../services/options.js'); const log = require('../services/log'); const env = require('../services/env.js'); const utils = require('../services/utils'); -const protectedSessionService = require('../services/protected_session.js'); +const protectedSessionService = require('../services/protected_session'); const packageJson = require('../../package.json'); const assetPath = require('../services/asset_path.js'); const appPath = require('../services/app_path.js'); diff --git a/src/services/date_notes.js b/src/services/date_notes.js index f258d2893..5d74b2f47 100644 --- a/src/services/date_notes.js +++ b/src/services/date_notes.js @@ -4,7 +4,7 @@ const noteService = require('./notes.js'); const attributeService = require('./attributes.js'); const dateUtils = require('./date_utils'); const sql = require('./sql'); -const protectedSessionService = require('./protected_session.js'); +const protectedSessionService = require('./protected_session'); const searchService = require('../services/search/services/search.js'); const SearchContext = require('../services/search/search_context.js'); const hoistedNoteService = require('./hoisted_note.js'); diff --git a/src/services/export/zip.js b/src/services/export/zip.js index 79625eee1..dccf4bf2f 100644 --- a/src/services/export/zip.js +++ b/src/services/export/zip.js @@ -7,7 +7,7 @@ const mimeTypes = require('mime-types'); const mdService = require('./md.js'); const packageInfo = require('../../../package.json'); const utils = require('../utils'); -const protectedSessionService = require('../protected_session.js'); +const protectedSessionService = require('../protected_session'); const sanitize = require("sanitize-filename"); const fs = require("fs"); const becca = require('../../becca/becca.js'); diff --git a/src/services/image.js b/src/services/image.js index 7113b6aca..ff9b5b9e9 100644 --- a/src/services/image.js +++ b/src/services/image.js @@ -2,7 +2,7 @@ const becca = require('../becca/becca.js'); const log = require('./log'); -const protectedSessionService = require('./protected_session.js'); +const protectedSessionService = require('./protected_session'); const noteService = require('./notes.js'); const optionService = require('./options.js'); const sql = require('./sql'); diff --git a/src/services/import/enex.js b/src/services/import/enex.js index c9565cd04..3ef11b2ec 100644 --- a/src/services/import/enex.js +++ b/src/services/import/enex.js @@ -6,7 +6,7 @@ const utils = require('../utils'); const sql = require('../sql'); const noteService = require('../notes.js'); const imageService = require('../image.js'); -const protectedSessionService = require('../protected_session.js'); +const protectedSessionService = require('../protected_session'); const htmlSanitizer = require('../html_sanitizer.js'); const {sanitizeAttributeName} = require('../sanitize_attribute_name.js'); diff --git a/src/services/import/opml.js b/src/services/import/opml.js index eb7b891d6..a547bf7ad 100644 --- a/src/services/import/opml.js +++ b/src/services/import/opml.js @@ -2,7 +2,7 @@ const noteService = require('../../services/notes.js'); const parseString = require('xml2js').parseString; -const protectedSessionService = require('../protected_session.js'); +const protectedSessionService = require('../protected_session'); const htmlSanitizer = require('../html_sanitizer.js'); /** diff --git a/src/services/import/single.js b/src/services/import/single.js index 59686207f..5e7c92630 100644 --- a/src/services/import/single.js +++ b/src/services/import/single.js @@ -2,7 +2,7 @@ const noteService = require('../../services/notes.js'); const imageService = require('../../services/image.js'); -const protectedSessionService = require('../protected_session.js'); +const protectedSessionService = require('../protected_session'); const markdownService = require('./markdown.js'); const mimeService = require('./mime.js'); const utils = require('../../services/utils'); diff --git a/src/services/import/zip.js b/src/services/import/zip.js index fabcdd58d..17a760fdc 100644 --- a/src/services/import/zip.js +++ b/src/services/import/zip.js @@ -7,7 +7,7 @@ const noteService = require('../../services/notes.js'); const attributeService = require('../../services/attributes.js'); const BBranch = require('../../becca/entities/bbranch.js'); const path = require('path'); -const protectedSessionService = require('../protected_session.js'); +const protectedSessionService = require('../protected_session'); const mimeService = require('./mime.js'); const treeService = require('../tree.js'); const yauzl = require("yauzl"); diff --git a/src/services/notes.js b/src/services/notes.js index e73c2f706..050729c4c 100644 --- a/src/services/notes.js +++ b/src/services/notes.js @@ -4,7 +4,7 @@ const dateUtils = require('./date_utils'); const entityChangesService = require('./entity_changes.js'); const eventService = require('./events.js'); const cls = require('../services/cls'); -const protectedSessionService = require('../services/protected_session.js'); +const protectedSessionService = require('../services/protected_session'); const log = require('../services/log'); const utils = require('../services/utils'); const revisionService = require('./revisions.js'); diff --git a/src/services/protected_session.js b/src/services/protected_session.ts similarity index 55% rename from src/services/protected_session.js rename to src/services/protected_session.ts index fad80c035..060705280 100644 --- a/src/services/protected_session.js +++ b/src/services/protected_session.ts @@ -1,12 +1,12 @@ "use strict"; -const log = require('./log'); -const dataEncryptionService = require('./encryption/data_encryption.js'); +import log = require('./log'); +import dataEncryptionService = require('./encryption/data_encryption'); -let dataKey = null; +let dataKey: Buffer | null = null; -function setDataKey(decryptedDataKey) { - dataKey = Array.from(decryptedDataKey); +function setDataKey(decryptedDataKey: Buffer) { + dataKey = Buffer.from(decryptedDataKey); } function getDataKey() { @@ -21,27 +21,33 @@ function isProtectedSessionAvailable() { return !!dataKey; } -function encrypt(plainText) { - if (plainText === null) { +function encrypt(plainText: string | Buffer) { + const dataKey = getDataKey(); + if (plainText === null || dataKey === null) { return null; } - return dataEncryptionService.encrypt(getDataKey(), plainText); + return dataEncryptionService.encrypt(dataKey, plainText); } -function decrypt(cipherText) { - if (cipherText === null) { +function decrypt(cipherText: string | Buffer) { + const dataKey = getDataKey(); + if (cipherText === null || dataKey === null) { return null; } - return dataEncryptionService.decrypt(getDataKey(), cipherText); + return dataEncryptionService.decrypt(dataKey, cipherText); } -function decryptString(cipherText) { - return dataEncryptionService.decryptString(getDataKey(), cipherText); +function decryptString(cipherText: string) { + const dataKey = getDataKey(); + if (dataKey === null) { + return null; + } + return dataEncryptionService.decryptString(dataKey, cipherText); } -let lastProtectedSessionOperationDate = null; +let lastProtectedSessionOperationDate: number | null = null; function touchProtectedSession() { if (isProtectedSessionAvailable()) { diff --git a/src/services/revisions.js b/src/services/revisions.js index e4b2dd9ed..7697a35f4 100644 --- a/src/services/revisions.js +++ b/src/services/revisions.js @@ -2,7 +2,7 @@ const log = require('./log'); const sql = require('./sql'); -const protectedSessionService = require('./protected_session.js'); +const protectedSessionService = require('./protected_session'); const dateUtils = require('./date_utils'); /** diff --git a/src/services/scheduler.js b/src/services/scheduler.js index d5d9c26dd..907fc1ec5 100644 --- a/src/services/scheduler.js +++ b/src/services/scheduler.js @@ -4,7 +4,7 @@ const sqlInit = require('./sql_init.js'); const config = require('./config.js'); const log = require('./log'); const attributeService = require('../services/attributes.js'); -const protectedSessionService = require('../services/protected_session.js'); +const protectedSessionService = require('../services/protected_session'); const hiddenSubtreeService = require('./hidden_subtree.js'); /** diff --git a/src/services/search/expressions/note_content_fulltext.js b/src/services/search/expressions/note_content_fulltext.js index 951d0cd6b..351d43717 100644 --- a/src/services/search/expressions/note_content_fulltext.js +++ b/src/services/search/expressions/note_content_fulltext.js @@ -4,7 +4,7 @@ const Expression = require('./expression.js'); const NoteSet = require('../note_set.js'); const log = require('../../log'); const becca = require('../../../becca/becca.js'); -const protectedSessionService = require('../../protected_session.js'); +const protectedSessionService = require('../../protected_session'); const striptags = require('striptags'); const utils = require('../../utils'); diff --git a/src/services/ws.js b/src/services/ws.js index 9e1f7f135..73caa8d26 100644 --- a/src/services/ws.js +++ b/src/services/ws.js @@ -5,7 +5,7 @@ const sql = require('./sql'); const cls = require('./cls'); const config = require('./config.js'); const syncMutexService = require('./sync_mutex.js'); -const protectedSessionService = require('./protected_session.js'); +const protectedSessionService = require('./protected_session'); const becca = require('../becca/becca.js'); const AbstractBeccaEntity = require('../becca/entities/abstract_becca_entity.js'); From 786d851293257e07994cf0fe3cd9005a1a6ce308 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Fri, 16 Feb 2024 23:14:42 +0200 Subject: [PATCH 16/49] server-ts: events.js -> ts --- src/becca/becca_loader.js | 2 +- src/routes/api/branches.js | 2 +- src/routes/api/login.js | 2 +- src/services/entity_changes.js | 2 +- src/services/{events.js => events.ts} | 15 +++++++++------ src/services/handlers.js | 2 +- src/services/notes.js | 2 +- src/services/sync_update.js | 2 +- src/share/shaca/shaca_loader.js | 2 +- 9 files changed, 17 insertions(+), 14 deletions(-) rename src/services/{events.js => events.ts} (84%) diff --git a/src/becca/becca_loader.js b/src/becca/becca_loader.js index ad64570a0..ecf7a7441 100644 --- a/src/becca/becca_loader.js +++ b/src/becca/becca_loader.js @@ -1,7 +1,7 @@ "use strict"; const sql = require('../services/sql'); -const eventService = require('../services/events.js'); +const eventService = require('../services/events'); const becca = require('./becca.js'); const sqlInit = require('../services/sql_init.js'); const log = require('../services/log'); diff --git a/src/routes/api/branches.js b/src/routes/api/branches.js index 4149a7315..55576665e 100644 --- a/src/routes/api/branches.js +++ b/src/routes/api/branches.js @@ -10,7 +10,7 @@ const TaskContext = require('../../services/task_context.js'); const branchService = require('../../services/branches.js'); const log = require('../../services/log'); const ValidationError = require('../../errors/validation_error'); -const eventService = require("../../services/events.js"); +const eventService = require("../../services/events"); /** * Code in this file deals with moving and cloning branches. The relationship between note and parent note is unique diff --git a/src/routes/api/login.js b/src/routes/api/login.js index ec5891c28..6d57519d4 100644 --- a/src/routes/api/login.js +++ b/src/routes/api/login.js @@ -7,7 +7,7 @@ const instanceId = require('../../services/instance_id.js'); const passwordEncryptionService = require('../../services/encryption/password_encryption.js'); const protectedSessionService = require('../../services/protected_session'); const appInfo = require('../../services/app_info.js'); -const eventService = require('../../services/events.js'); +const eventService = require('../../services/events'); const sqlInit = require('../../services/sql_init.js'); const sql = require('../../services/sql'); const ws = require('../../services/ws.js'); diff --git a/src/services/entity_changes.js b/src/services/entity_changes.js index 209afc359..a2b9c99ca 100644 --- a/src/services/entity_changes.js +++ b/src/services/entity_changes.js @@ -53,7 +53,7 @@ function putNoteReorderingEntityChange(parentNoteId, componentId) { instanceId }); - const eventService = require('./events.js'); + const eventService = require('./events'); eventService.emit(eventService.ENTITY_CHANGED, { entityName: 'note_reordering', diff --git a/src/services/events.js b/src/services/events.ts similarity index 84% rename from src/services/events.js rename to src/services/events.ts index 51c30be17..fffcc3982 100644 --- a/src/services/events.js +++ b/src/services/events.ts @@ -11,13 +11,16 @@ const ENTITY_DELETE_SYNCED = "ENTITY_DELETE_SYNCED"; const CHILD_NOTE_CREATED = "CHILD_NOTE_CREATED"; const NOTE_CONTENT_CHANGE = "NOTE_CONTENT_CHANGED"; -const eventListeners = {}; +type EventType = string | string[]; +type EventListener = (data: any) => void; + +const eventListeners: Record = {}; /** * @param {string|string[]}eventTypes - can be either single event or an array of events * @param listener */ -function subscribe(eventTypes, listener) { +function subscribe(eventTypes: EventType, listener: EventListener) { if (!Array.isArray(eventTypes)) { eventTypes = [ eventTypes ]; } @@ -28,7 +31,7 @@ function subscribe(eventTypes, listener) { } } -function subscribeBeccaLoader(eventTypes, listener) { +function subscribeBeccaLoader(eventTypes: EventType, listener: EventListener) { if (!Array.isArray(eventTypes)) { eventTypes = [ eventTypes ]; } @@ -41,7 +44,7 @@ function subscribeBeccaLoader(eventTypes, listener) { } } -function emit(eventType, data) { +function emit(eventType: string, data: any) { const listeners = eventListeners[eventType]; if (listeners) { @@ -49,7 +52,7 @@ function emit(eventType, data) { try { listener(data); } - catch (e) { + catch (e: any) { log.error(`Listener threw error: ${e.message}, stack: ${e.stack}`); // we won't stop execution because of listener } @@ -57,7 +60,7 @@ function emit(eventType, data) { } } -module.exports = { +export = { subscribe, subscribeBeccaLoader, emit, diff --git a/src/services/handlers.js b/src/services/handlers.js index 769c69485..d5a55fafe 100644 --- a/src/services/handlers.js +++ b/src/services/handlers.js @@ -1,4 +1,4 @@ -const eventService = require('./events.js'); +const eventService = require('./events'); const scriptService = require('./script.js'); const treeService = require('./tree.js'); const noteService = require('./notes.js'); diff --git a/src/services/notes.js b/src/services/notes.js index 050729c4c..214975a95 100644 --- a/src/services/notes.js +++ b/src/services/notes.js @@ -2,7 +2,7 @@ const sql = require('./sql'); const optionService = require('./options.js'); const dateUtils = require('./date_utils'); const entityChangesService = require('./entity_changes.js'); -const eventService = require('./events.js'); +const eventService = require('./events'); const cls = require('../services/cls'); const protectedSessionService = require('../services/protected_session'); const log = require('../services/log'); diff --git a/src/services/sync_update.js b/src/services/sync_update.js index 5db427e1f..6581066f4 100644 --- a/src/services/sync_update.js +++ b/src/services/sync_update.js @@ -1,7 +1,7 @@ const sql = require('./sql'); const log = require('./log'); const entityChangesService = require('./entity_changes.js'); -const eventService = require('./events.js'); +const eventService = require('./events'); const entityConstructor = require('../becca/entity_constructor.js'); const ws = require('./ws.js'); diff --git a/src/share/shaca/shaca_loader.js b/src/share/shaca/shaca_loader.js index aef4f36d5..5d1648f49 100644 --- a/src/share/shaca/shaca_loader.js +++ b/src/share/shaca/shaca_loader.js @@ -8,7 +8,7 @@ const SBranch = require('./entities/sbranch.js'); const SAttribute = require('./entities/sattribute.js'); const SAttachment = require('./entities/sattachment.js'); const shareRoot = require('../share_root.js'); -const eventService = require('../../services/events.js'); +const eventService = require('../../services/events'); function load() { const start = Date.now(); From 5309d4ad5ca64542820c30d0e203afb58ca07750 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Fri, 16 Feb 2024 23:18:53 +0200 Subject: [PATCH 17/49] server-ts: instance_id.js -> ts --- src/routes/api/login.js | 2 +- src/services/entity_changes.js | 2 +- src/services/{instance_id.js => instance_id.ts} | 2 +- src/services/sync.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) rename src/services/{instance_id.js => instance_id.ts} (67%) diff --git a/src/routes/api/login.js b/src/routes/api/login.js index 6d57519d4..a3491700f 100644 --- a/src/routes/api/login.js +++ b/src/routes/api/login.js @@ -3,7 +3,7 @@ const options = require('../../services/options.js'); const utils = require('../../services/utils'); const dateUtils = require('../../services/date_utils'); -const instanceId = require('../../services/instance_id.js'); +const instanceId = require('../../services/instance_id'); const passwordEncryptionService = require('../../services/encryption/password_encryption.js'); const protectedSessionService = require('../../services/protected_session'); const appInfo = require('../../services/app_info.js'); diff --git a/src/services/entity_changes.js b/src/services/entity_changes.js index a2b9c99ca..22b5875a0 100644 --- a/src/services/entity_changes.js +++ b/src/services/entity_changes.js @@ -3,7 +3,7 @@ const dateUtils = require('./date_utils'); const log = require('./log'); const cls = require('./cls'); const utils = require('./utils'); -const instanceId = require('./instance_id.js'); +const instanceId = require('./instance_id'); const becca = require('../becca/becca.js'); const blobService = require('../services/blob.js'); diff --git a/src/services/instance_id.js b/src/services/instance_id.ts similarity index 67% rename from src/services/instance_id.js rename to src/services/instance_id.ts index 4ee187b01..704da863c 100644 --- a/src/services/instance_id.js +++ b/src/services/instance_id.ts @@ -1,4 +1,4 @@ -const utils = require('./utils'); +import utils = require('./utils'); const instanceId = utils.randomString(12); diff --git a/src/services/sync.js b/src/services/sync.js index 9afd4704f..bce751b5b 100644 --- a/src/services/sync.js +++ b/src/services/sync.js @@ -4,7 +4,7 @@ const log = require('./log'); const sql = require('./sql'); const optionService = require('./options.js'); const utils = require('./utils'); -const instanceId = require('./instance_id.js'); +const instanceId = require('./instance_id'); const dateUtils = require('./date_utils'); const syncUpdateService = require('./sync_update.js'); const contentHashService = require('./content_hash.js'); From 3a7d0d1f138c4b03c28e3c0f807c6c330d0af23f Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Fri, 16 Feb 2024 23:43:41 +0200 Subject: [PATCH 18/49] server-ts: Add some type fixes to sql.ts --- src/services/sql.ts | 21 +++++++++++---------- tsconfig.json | 2 +- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/services/sql.ts b/src/services/sql.ts index 8567cafaa..bdf490d92 100644 --- a/src/services/sql.ts +++ b/src/services/sql.ts @@ -5,12 +5,13 @@ */ import log = require('./log'); -import Database = require('better-sqlite3'); +import type { Statement, Database as DatabaseType, RunResult } from "better-sqlite3"; import dataDir = require('./data_dir'); import cls = require('./cls'); import fs = require("fs-extra"); +import Database = require('better-sqlite3'); -const dbConnection = new Database(dataDir.DOCUMENT_PATH); +const dbConnection: DatabaseType = new Database(dataDir.DOCUMENT_PATH); dbConnection.pragma('journal_mode = WAL'); const LOG_ALL_QUERIES = false; @@ -50,8 +51,8 @@ function insert(tableName: string, rec: T, replace = false) { return res ? res.lastInsertRowid : null; } -function replace(tableName: string, rec: T) { - return insert(tableName, rec, true); +function replace(tableName: string, rec: T): number | null { + return insert(tableName, rec, true) as number | null; } function upsert(tableName: string, primaryKey: string, rec: T) { @@ -79,7 +80,7 @@ function upsert(tableName: string, primaryKey: string, rec: T) { execute(query, rec); } -const statementCache: Record = {}; +const statementCache: Record = {}; function stmt(sql: string) { if (!(sql in statementCache)) { @@ -169,8 +170,8 @@ function getColumn(query: string, params: Params = []) { return wrap(query, s => s.pluck().all(params)); } -function execute(query: string, params: Params = []): Database.RunResult { - return wrap(query, s => s.run(params)) as Database.RunResult; +function execute(query: string, params: Params = []): RunResult { + return wrap(query, s => s.run(params)) as RunResult; } function executeMany(query: string, params: Params) { @@ -197,7 +198,7 @@ function executeMany(query: string, params: Params) { } } -function executeScript(query: string) { +function executeScript(query: string): DatabaseType { if (LOG_ALL_QUERIES) { console.log(query); } @@ -205,7 +206,7 @@ function executeScript(query: string) { return dbConnection.exec(query); } -function wrap(query: string, func: (statement: Database.Statement) => unknown): unknown { +function wrap(query: string, func: (statement: Statement) => unknown): unknown { const startTimestamp = Date.now(); let result; @@ -242,7 +243,7 @@ function wrap(query: string, func: (statement: Database.Statement) => unknown): return result; } -function transactional(func: (statement: Database.Statement) => T) { +function transactional(func: (statement: Statement) => T) { try { const ret = (dbConnection.transaction(func) as any).deferred(); diff --git a/tsconfig.json b/tsconfig.json index 0d6d3364c..eded031af 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { "moduleResolution": "Node", - "declaration": true, + "declaration": false, "sourceMap": true, "outDir": "./build", "strict": true, From 85af0a24eed578e60842d2d93340765a3d1c4851 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Fri, 16 Feb 2024 23:51:56 +0200 Subject: [PATCH 19/49] server-ts: Convert becca.js --- src/becca/{becca.js => becca-interface.ts} | 12 ++++-------- src/becca/becca.ts | 7 +++++++ 2 files changed, 11 insertions(+), 8 deletions(-) rename src/becca/{becca.js => becca-interface.ts} (97%) create mode 100644 src/becca/becca.ts diff --git a/src/becca/becca.js b/src/becca/becca-interface.ts similarity index 97% rename from src/becca/becca.js rename to src/becca/becca-interface.ts index 1d39d7282..0f368961c 100644 --- a/src/becca/becca.js +++ b/src/becca/becca-interface.ts @@ -1,8 +1,6 @@ -"use strict"; - -const sql = require('../services/sql'); -const NoteSet = require('../services/search/note_set.js'); -const NotFoundError = require('../errors/not_found_error.js'); +import sql = require('../services/sql'); +import NoteSet = require('../services/search/note_set'); +import NotFoundError = require('../errors/not_found_error'); /** * Becca is a backend cache of all notes, branches, and attributes. @@ -277,6 +275,4 @@ class Becca { } } -const becca = new Becca(); - -module.exports = becca; +export = Becca; \ No newline at end of file diff --git a/src/becca/becca.ts b/src/becca/becca.ts new file mode 100644 index 000000000..8ea1a6575 --- /dev/null +++ b/src/becca/becca.ts @@ -0,0 +1,7 @@ +"use strict"; + +import Becca = require("./becca-interface"); + +const becca = new Becca(); + +export = becca; From cb14d4d8f9d7af0c683b5370833bc19bf08097bd Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Fri, 16 Feb 2024 23:52:11 +0200 Subject: [PATCH 20/49] server-ts: Convert blob.js --- src/services/{blob.js => blob.ts} | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) rename src/services/{blob.js => blob.ts} (74%) diff --git a/src/services/blob.js b/src/services/blob.ts similarity index 74% rename from src/services/blob.js rename to src/services/blob.ts index 9b2cfa6dd..85917f9bb 100644 --- a/src/services/blob.js +++ b/src/services/blob.ts @@ -1,9 +1,9 @@ -const becca = require('../becca/becca.js'); -const NotFoundError = require('../errors/not_found_error.js'); -const protectedSessionService = require('./protected_session.js'); -const utils = require('./utils'); +import becca = require('../becca/becca.js'); +import NotFoundError = require('../errors/not_found_error'); +import protectedSessionService = require('./protected_session'); +import utils = require('./utils'); -function getBlobPojo(entityName, entityId) { +function getBlobPojo(entityName: string, entityId: string) { const entity = becca.getEntity(entityName, entityId); if (!entity) { throw new NotFoundError(`Entity ${entityName} '${entityId}' was not found.`); @@ -25,7 +25,7 @@ function getBlobPojo(entityName, entityId) { return pojo; } -function processContent(content, isProtected, isStringContent) { +function processContent(content: Buffer | string | null, isProtected: boolean, isStringContent: boolean) { if (isProtected) { if (protectedSessionService.isProtectedSessionAvailable()) { content = content === null ? null : protectedSessionService.decrypt(content); @@ -48,7 +48,7 @@ function processContent(content, isProtected, isStringContent) { } } -function calculateContentHash({blobId, content}) { +function calculateContentHash({blobId, content}: { blobId: string, content: Buffer }) { return utils.hash(`${blobId}|${content.toString()}`); } From e04bd5aaf0ed88a95358452577c4b52b07abb17c Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Fri, 16 Feb 2024 23:56:32 +0200 Subject: [PATCH 21/49] server-ts: Convert more classes, including entity_changes.js --- src/errors/not_found_error.ts | 2 +- src/services/blob-interface.ts | 5 + src/services/blob.ts | 5 +- src/services/date_utils.ts | 2 +- src/services/entity_changes.js | 202 --------------------- src/services/entity_changes.ts | 216 +++++++++++++++++++++-- src/services/entity_changes_interface.ts | 12 ++ src/services/instance_id.ts | 2 +- src/services/protected_session.ts | 8 +- src/services/sql.ts | 12 +- 10 files changed, 238 insertions(+), 228 deletions(-) create mode 100644 src/services/blob-interface.ts delete mode 100644 src/services/entity_changes.js create mode 100644 src/services/entity_changes_interface.ts diff --git a/src/errors/not_found_error.ts b/src/errors/not_found_error.ts index 7ceb105a9..f765e11f9 100644 --- a/src/errors/not_found_error.ts +++ b/src/errors/not_found_error.ts @@ -6,4 +6,4 @@ class NotFoundError { } } -module.exports = NotFoundError; \ No newline at end of file +export = NotFoundError; \ No newline at end of file diff --git a/src/services/blob-interface.ts b/src/services/blob-interface.ts new file mode 100644 index 000000000..5905e9d99 --- /dev/null +++ b/src/services/blob-interface.ts @@ -0,0 +1,5 @@ +export interface Blob { + blobId: string; + content: Buffer; + utcDateModified: string; +} \ No newline at end of file diff --git a/src/services/blob.ts b/src/services/blob.ts index 85917f9bb..39b979fee 100644 --- a/src/services/blob.ts +++ b/src/services/blob.ts @@ -2,6 +2,7 @@ import becca = require('../becca/becca.js'); import NotFoundError = require('../errors/not_found_error'); import protectedSessionService = require('./protected_session'); import utils = require('./utils'); +import type { Blob } from "./blob-interface"; function getBlobPojo(entityName: string, entityId: string) { const entity = becca.getEntity(entityName, entityId); @@ -48,11 +49,11 @@ function processContent(content: Buffer | string | null, isProtected: boolean, i } } -function calculateContentHash({blobId, content}: { blobId: string, content: Buffer }) { +function calculateContentHash({blobId, content}: Blob) { return utils.hash(`${blobId}|${content.toString()}`); } -module.exports = { +export = { getBlobPojo, processContent, calculateContentHash diff --git a/src/services/date_utils.ts b/src/services/date_utils.ts index a4150c89e..31c58c2e4 100644 --- a/src/services/date_utils.ts +++ b/src/services/date_utils.ts @@ -95,7 +95,7 @@ function validateUtcDateTime(str: string) { } } -module.exports = { +export = { utcNowDateTime, localNowDateTime, localNowDate, diff --git a/src/services/entity_changes.js b/src/services/entity_changes.js deleted file mode 100644 index 22b5875a0..000000000 --- a/src/services/entity_changes.js +++ /dev/null @@ -1,202 +0,0 @@ -const sql = require('./sql'); -const dateUtils = require('./date_utils'); -const log = require('./log'); -const cls = require('./cls'); -const utils = require('./utils'); -const instanceId = require('./instance_id'); -const becca = require('../becca/becca.js'); -const blobService = require('../services/blob.js'); - -let maxEntityChangeId = 0; - -function putEntityChangeWithInstanceId(origEntityChange, instanceId) { - const ec = {...origEntityChange, instanceId}; - - putEntityChange(ec); -} - -function putEntityChangeWithForcedChange(origEntityChange) { - const ec = {...origEntityChange, changeId: null}; - - putEntityChange(ec); -} - -function putEntityChange(origEntityChange) { - const ec = {...origEntityChange}; - - delete ec.id; - - if (!ec.changeId) { - ec.changeId = utils.randomString(12); - } - - ec.componentId = ec.componentId || cls.getComponentId() || "NA"; // NA = not available - ec.instanceId = ec.instanceId || instanceId; - ec.isSynced = ec.isSynced ? 1 : 0; - ec.isErased = ec.isErased ? 1 : 0; - ec.id = sql.replace("entity_changes", ec); - - maxEntityChangeId = Math.max(maxEntityChangeId, ec.id); - - cls.putEntityChange(ec); -} - -function putNoteReorderingEntityChange(parentNoteId, componentId) { - putEntityChange({ - entityName: "note_reordering", - entityId: parentNoteId, - hash: 'N/A', - isErased: false, - utcDateChanged: dateUtils.utcNowDateTime(), - isSynced: true, - componentId, - instanceId - }); - - const eventService = require('./events'); - - eventService.emit(eventService.ENTITY_CHANGED, { - entityName: 'note_reordering', - entity: sql.getMap(`SELECT branchId, notePosition FROM branches WHERE isDeleted = 0 AND parentNoteId = ?`, [parentNoteId]) - }); -} - -function putEntityChangeForOtherInstances(ec) { - putEntityChange({ - ...ec, - changeId: null, - instanceId: null - }); -} - -function addEntityChangesForSector(entityName, sector) { - const entityChanges = sql.getRows(`SELECT * FROM entity_changes WHERE entityName = ? AND SUBSTR(entityId, 1, 1) = ?`, [entityName, sector]); - - let entitiesInserted = entityChanges.length; - - sql.transactional(() => { - if (entityName === 'blobs') { - entitiesInserted += addEntityChangesForDependingEntity(sector, 'notes', 'noteId'); - entitiesInserted += addEntityChangesForDependingEntity(sector, 'attachments', 'attachmentId'); - entitiesInserted += addEntityChangesForDependingEntity(sector, 'revisions', 'revisionId'); - } - - for (const ec of entityChanges) { - putEntityChangeWithForcedChange(ec); - } - }); - - log.info(`Added sector ${sector} of '${entityName}' (${entitiesInserted} entities) to the sync queue.`); -} - -function addEntityChangesForDependingEntity(sector, tableName, primaryKeyColumn) { - // problem in blobs might be caused by problem in entity referencing the blob - const dependingEntityChanges = sql.getRows(` - SELECT dep_change.* - FROM entity_changes orig_sector - JOIN ${tableName} ON ${tableName}.blobId = orig_sector.entityId - JOIN entity_changes dep_change ON dep_change.entityName = '${tableName}' AND dep_change.entityId = ${tableName}.${primaryKeyColumn} - WHERE orig_sector.entityName = 'blobs' AND SUBSTR(orig_sector.entityId, 1, 1) = ?`, [sector]); - - for (const ec of dependingEntityChanges) { - putEntityChangeWithForcedChange(ec); - } - - return dependingEntityChanges.length; -} - -function cleanupEntityChangesForMissingEntities(entityName, entityPrimaryKey) { - sql.execute(` - DELETE - FROM entity_changes - WHERE - isErased = 0 - AND entityName = '${entityName}' - AND entityId NOT IN (SELECT ${entityPrimaryKey} FROM ${entityName})`); -} - -function fillEntityChanges(entityName, entityPrimaryKey, condition = '') { - cleanupEntityChangesForMissingEntities(entityName, entityPrimaryKey); - - sql.transactional(() => { - const entityIds = sql.getColumn(`SELECT ${entityPrimaryKey} FROM ${entityName} ${condition}`); - - let createdCount = 0; - - for (const entityId of entityIds) { - const existingRows = sql.getValue("SELECT COUNT(1) FROM entity_changes WHERE entityName = ? AND entityId = ?", [entityName, entityId]); - - if (existingRows !== 0) { - // we don't want to replace existing entities (which would effectively cause full resync) - continue; - } - - createdCount++; - - const ec = { - entityName, - entityId, - isErased: false - }; - - if (entityName === 'blobs') { - const blob = sql.getRow("SELECT blobId, content, utcDateModified FROM blobs WHERE blobId = ?", [entityId]); - ec.hash = blobService.calculateContentHash(blob); - ec.utcDateChanged = blob.utcDateModified; - ec.isSynced = true; // blobs are always synced - } else { - const entity = becca.getEntity(entityName, entityId); - - if (entity) { - ec.hash = entity.generateHash(); - ec.utcDateChanged = entity.getUtcDateChanged() || dateUtils.utcNowDateTime(); - ec.isSynced = entityName !== 'options' || !!entity.isSynced; - } else { - // entity might be null (not present in becca) when it's deleted - // this will produce different hash value than when entity is being deleted since then - // all normal hashed attributes are being used. Sync should recover from that, though. - ec.hash = "deleted"; - ec.utcDateChanged = dateUtils.utcNowDateTime(); - ec.isSynced = true; // deletable (the ones with isDeleted) entities are synced - } - } - - putEntityChange(ec); - } - - if (createdCount > 0) { - log.info(`Created ${createdCount} missing entity changes for entity '${entityName}'.`); - } - }); -} - -function fillAllEntityChanges() { - sql.transactional(() => { - sql.execute("DELETE FROM entity_changes WHERE isErased = 0"); - - fillEntityChanges("notes", "noteId"); - fillEntityChanges("branches", "branchId"); - fillEntityChanges("revisions", "revisionId"); - fillEntityChanges("attachments", "attachmentId"); - fillEntityChanges("blobs", "blobId"); - fillEntityChanges("attributes", "attributeId"); - fillEntityChanges("etapi_tokens", "etapiTokenId"); - fillEntityChanges("options", "name", 'WHERE isSynced = 1'); - }); -} - -function recalculateMaxEntityChangeId() { - maxEntityChangeId = sql.getValue("SELECT COALESCE(MAX(id), 0) FROM entity_changes"); -} - -module.exports = { - putNoteReorderingEntityChange, - putEntityChangeForOtherInstances, - putEntityChangeWithForcedChange, - putEntityChange, - putEntityChangeWithInstanceId, - fillAllEntityChanges, - addEntityChangesForSector, - getMaxEntityChangeId: () => maxEntityChangeId, - recalculateMaxEntityChangeId -}; diff --git a/src/services/entity_changes.ts b/src/services/entity_changes.ts index 73f4ff259..ff2754851 100644 --- a/src/services/entity_changes.ts +++ b/src/services/entity_changes.ts @@ -1,12 +1,206 @@ -export interface EntityChange { - id?: string; - entityName: string; - entityId: string; - hash: string; - utcDateChanged: string; - isSynced: boolean | 1 | 0; - isErased: boolean | 1 | 0; - componentId?: string | null; - changeId?: string | null; - instanceId?: string | null; +import sql = require('./sql'); +import dateUtils = require('./date_utils'); +import log = require('./log'); +import cls = require('./cls'); +import utils = require('./utils'); +import instanceId = require('./instance_id'); +import becca = require('../becca/becca.js'); +import blobService = require('../services/blob.js'); +import { EntityChange } from './entity_changes_interface'; +import type { Blob } from "./blob-interface"; + +let maxEntityChangeId = 0; + +function putEntityChangeWithInstanceId(origEntityChange: EntityChange, instanceId: string) { + const ec = {...origEntityChange, instanceId}; + + putEntityChange(ec); } + +function putEntityChangeWithForcedChange(origEntityChange: EntityChange) { + const ec = {...origEntityChange, changeId: null}; + + putEntityChange(ec); +} + +function putEntityChange(origEntityChange: EntityChange) { + const ec = {...origEntityChange}; + + delete ec.id; + + if (!ec.changeId) { + ec.changeId = utils.randomString(12); + } + + ec.componentId = ec.componentId || cls.getComponentId() || "NA"; // NA = not available + ec.instanceId = ec.instanceId || instanceId; + ec.isSynced = ec.isSynced ? 1 : 0; + ec.isErased = ec.isErased ? 1 : 0; + ec.id = sql.replace("entity_changes", ec); + + if (ec.id) { + maxEntityChangeId = Math.max(maxEntityChangeId, ec.id); + } + + cls.putEntityChange(ec); +} + +function putNoteReorderingEntityChange(parentNoteId: string, componentId: string) { + putEntityChange({ + entityName: "note_reordering", + entityId: parentNoteId, + hash: 'N/A', + isErased: false, + utcDateChanged: dateUtils.utcNowDateTime(), + isSynced: true, + componentId, + instanceId + }); + + const eventService = require('./events'); + + eventService.emit(eventService.ENTITY_CHANGED, { + entityName: 'note_reordering', + entity: sql.getMap(`SELECT branchId, notePosition FROM branches WHERE isDeleted = 0 AND parentNoteId = ?`, [parentNoteId]) + }); +} + +function putEntityChangeForOtherInstances(ec: EntityChange) { + putEntityChange({ + ...ec, + changeId: null, + instanceId: null + }); +} + +function addEntityChangesForSector(entityName: string, sector: string) { + const entityChanges = sql.getRows(`SELECT * FROM entity_changes WHERE entityName = ? AND SUBSTR(entityId, 1, 1) = ?`, [entityName, sector]); + + let entitiesInserted = entityChanges.length; + + sql.transactional(() => { + if (entityName === 'blobs') { + entitiesInserted += addEntityChangesForDependingEntity(sector, 'notes', 'noteId'); + entitiesInserted += addEntityChangesForDependingEntity(sector, 'attachments', 'attachmentId'); + entitiesInserted += addEntityChangesForDependingEntity(sector, 'revisions', 'revisionId'); + } + + for (const ec of entityChanges) { + putEntityChangeWithForcedChange(ec); + } + }); + + log.info(`Added sector ${sector} of '${entityName}' (${entitiesInserted} entities) to the sync queue.`); +} + +function addEntityChangesForDependingEntity(sector: string, tableName: string, primaryKeyColumn: string) { + // problem in blobs might be caused by problem in entity referencing the blob + const dependingEntityChanges = sql.getRows(` + SELECT dep_change.* + FROM entity_changes orig_sector + JOIN ${tableName} ON ${tableName}.blobId = orig_sector.entityId + JOIN entity_changes dep_change ON dep_change.entityName = '${tableName}' AND dep_change.entityId = ${tableName}.${primaryKeyColumn} + WHERE orig_sector.entityName = 'blobs' AND SUBSTR(orig_sector.entityId, 1, 1) = ?`, [sector]); + + for (const ec of dependingEntityChanges) { + putEntityChangeWithForcedChange(ec); + } + + return dependingEntityChanges.length; +} + +function cleanupEntityChangesForMissingEntities(entityName: string, entityPrimaryKey: string) { + sql.execute(` + DELETE + FROM entity_changes + WHERE + isErased = 0 + AND entityName = '${entityName}' + AND entityId NOT IN (SELECT ${entityPrimaryKey} FROM ${entityName})`); +} + +function fillEntityChanges(entityName: string, entityPrimaryKey: string, condition = '') { + cleanupEntityChangesForMissingEntities(entityName, entityPrimaryKey); + + sql.transactional(() => { + const entityIds = sql.getColumn(`SELECT ${entityPrimaryKey} FROM ${entityName} ${condition}`); + + let createdCount = 0; + + for (const entityId of entityIds) { + const existingRows = sql.getValue("SELECT COUNT(1) FROM entity_changes WHERE entityName = ? AND entityId = ?", [entityName, entityId]); + + if (existingRows !== 0) { + // we don't want to replace existing entities (which would effectively cause full resync) + continue; + } + + createdCount++; + + const ec: Partial = { + entityName, + entityId, + isErased: false + }; + + if (entityName === 'blobs') { + const blob = sql.getRow("SELECT blobId, content, utcDateModified FROM blobs WHERE blobId = ?", [entityId]); + ec.hash = blobService.calculateContentHash(blob); + ec.utcDateChanged = blob.utcDateModified; + ec.isSynced = true; // blobs are always synced + } else { + const entity = becca.getEntity(entityName, entityId); + + if (entity) { + ec.hash = entity.generateHash(); + ec.utcDateChanged = entity.getUtcDateChanged() || dateUtils.utcNowDateTime(); + ec.isSynced = entityName !== 'options' || !!entity.isSynced; + } else { + // entity might be null (not present in becca) when it's deleted + // this will produce different hash value than when entity is being deleted since then + // all normal hashed attributes are being used. Sync should recover from that, though. + ec.hash = "deleted"; + ec.utcDateChanged = dateUtils.utcNowDateTime(); + ec.isSynced = true; // deletable (the ones with isDeleted) entities are synced + } + } + + putEntityChange(ec as EntityChange); + } + + if (createdCount > 0) { + log.info(`Created ${createdCount} missing entity changes for entity '${entityName}'.`); + } + }); +} + +function fillAllEntityChanges() { + sql.transactional(() => { + sql.execute("DELETE FROM entity_changes WHERE isErased = 0"); + + fillEntityChanges("notes", "noteId"); + fillEntityChanges("branches", "branchId"); + fillEntityChanges("revisions", "revisionId"); + fillEntityChanges("attachments", "attachmentId"); + fillEntityChanges("blobs", "blobId"); + fillEntityChanges("attributes", "attributeId"); + fillEntityChanges("etapi_tokens", "etapiTokenId"); + fillEntityChanges("options", "name", 'WHERE isSynced = 1'); + }); +} + +function recalculateMaxEntityChangeId() { + maxEntityChangeId = sql.getValue("SELECT COALESCE(MAX(id), 0) FROM entity_changes"); +} + +export = { + putNoteReorderingEntityChange, + putEntityChangeForOtherInstances, + putEntityChangeWithForcedChange, + putEntityChange, + putEntityChangeWithInstanceId, + fillAllEntityChanges, + addEntityChangesForSector, + getMaxEntityChangeId: () => maxEntityChangeId, + recalculateMaxEntityChangeId +}; diff --git a/src/services/entity_changes_interface.ts b/src/services/entity_changes_interface.ts new file mode 100644 index 000000000..0a6409a80 --- /dev/null +++ b/src/services/entity_changes_interface.ts @@ -0,0 +1,12 @@ +export interface EntityChange { + id?: number | null; + entityName: string; + entityId: string; + hash: string; + utcDateChanged: string; + isSynced: boolean | 1 | 0; + isErased: boolean | 1 | 0; + componentId?: string | null; + changeId?: string | null; + instanceId?: string | null; +} \ No newline at end of file diff --git a/src/services/instance_id.ts b/src/services/instance_id.ts index 704da863c..6e0eb503c 100644 --- a/src/services/instance_id.ts +++ b/src/services/instance_id.ts @@ -2,4 +2,4 @@ import utils = require('./utils'); const instanceId = utils.randomString(12); -module.exports = instanceId; +export = instanceId; diff --git a/src/services/protected_session.ts b/src/services/protected_session.ts index 060705280..19d15d542 100644 --- a/src/services/protected_session.ts +++ b/src/services/protected_session.ts @@ -30,16 +30,16 @@ function encrypt(plainText: string | Buffer) { return dataEncryptionService.encrypt(dataKey, plainText); } -function decrypt(cipherText: string | Buffer) { +function decrypt(cipherText: string | Buffer): Buffer | null { const dataKey = getDataKey(); if (cipherText === null || dataKey === null) { return null; } - return dataEncryptionService.decrypt(dataKey, cipherText); + return dataEncryptionService.decrypt(dataKey, cipherText) || null; } -function decryptString(cipherText: string) { +function decryptString(cipherText: string): string | null { const dataKey = getDataKey(); if (dataKey === null) { return null; @@ -70,7 +70,7 @@ function checkProtectedSessionExpiration() { } } -module.exports = { +export = { setDataKey, resetDataKey, isProtectedSessionAvailable, diff --git a/src/services/sql.ts b/src/services/sql.ts index bdf490d92..f31d51728 100644 --- a/src/services/sql.ts +++ b/src/services/sql.ts @@ -103,8 +103,8 @@ function getRowOrNull(query: string, params: Params = []): T | null { return (all.length > 0 ? all[0] : null) as (T | null); } -function getValue(query: string, params: Params = []) { - return wrap(query, s => s.pluck().get(params)); +function getValue(query: string, params: Params = []): T { + return wrap(query, s => s.pluck().get(params)) as T; } // smaller values can result in better performance due to better usage of statement cache @@ -139,8 +139,8 @@ function getManyRows(query: string, params: Params) { return results; } -function getRows(query: string, params: Params = []): unknown[] { - return wrap(query, s => s.all(params)) as unknown[]; +function getRows(query: string, params: Params = []): T[] { + return wrap(query, s => s.all(params)) as T[]; } function getRawRows(query: string, params: Params = []): T[] | null { @@ -166,8 +166,8 @@ function getMap(query: string, params: Pa return map; } -function getColumn(query: string, params: Params = []) { - return wrap(query, s => s.pluck().all(params)); +function getColumn(query: string, params: Params = []): T[] { + return wrap(query, s => s.pluck().all(params)) as T[]; } function execute(query: string, params: Params = []): RunResult { From 6dd2cd39aab0ce7f58f57a266dc859cf3b48f87e Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 17 Feb 2024 00:44:44 +0200 Subject: [PATCH 22/49] server-ts: Convert a few classes in becca --- src/becca/becca-interface.ts | 2 + ...cca_entity.js => abstract_becca_entity.ts} | 79 ++++++--------- .../{battachment.js => battachment.ts} | 98 +++++++++---------- src/becca/entities/{bnote.js => bnote.ts} | 24 ++--- .../{brecent_note.js => brecent_note.ts} | 15 +-- .../entities/{brevision.js => brevision.ts} | 97 +++++++++--------- src/becca/entities/rows.ts | 36 +++++++ .../search/{note_set.js => note_set.ts} | 2 +- 8 files changed, 182 insertions(+), 171 deletions(-) rename src/becca/entities/{abstract_becca_entity.js => abstract_becca_entity.ts} (86%) rename src/becca/entities/{battachment.js => battachment.ts} (77%) rename src/becca/entities/{bnote.js => bnote.ts} (98%) rename src/becca/entities/{brecent_note.js => brecent_note.ts} (69%) rename src/becca/entities/{brevision.js => brevision.ts} (73%) create mode 100644 src/becca/entities/rows.ts rename src/services/search/{note_set.js => note_set.ts} (97%) diff --git a/src/becca/becca-interface.ts b/src/becca/becca-interface.ts index 0f368961c..294442cbb 100644 --- a/src/becca/becca-interface.ts +++ b/src/becca/becca-interface.ts @@ -7,6 +7,8 @@ import NotFoundError = require('../errors/not_found_error'); * There's a similar frontend cache Froca, and share cache Shaca. */ class Becca { + notes!: Record; + constructor() { this.reset(); } diff --git a/src/becca/entities/abstract_becca_entity.js b/src/becca/entities/abstract_becca_entity.ts similarity index 86% rename from src/becca/entities/abstract_becca_entity.js rename to src/becca/entities/abstract_becca_entity.ts index b72b13381..35d0d2979 100644 --- a/src/becca/entities/abstract_becca_entity.js +++ b/src/becca/entities/abstract_becca_entity.ts @@ -1,47 +1,44 @@ "use strict"; -const utils = require('../../services/utils'); -const sql = require('../../services/sql'); -const entityChangesService = require('../../services/entity_changes.js'); -const eventService = require('../../services/events.js'); -const dateUtils = require('../../services/date_utils'); -const cls = require('../../services/cls'); -const log = require('../../services/log'); -const protectedSessionService = require('../../services/protected_session'); -const blobService = require('../../services/blob.js'); +import utils = require('../../services/utils'); +import sql = require('../../services/sql'); +import entityChangesService = require('../../services/entity_changes.js'); +import eventService = require('../../services/events'); +import dateUtils = require('../../services/date_utils'); +import cls = require('../../services/cls'); +import log = require('../../services/log'); +import protectedSessionService = require('../../services/protected_session'); +import blobService = require('../../services/blob.js'); +import Becca = require('../becca-interface'); -let becca = null; +let becca: Becca | null = null; /** * Base class for all backend entities. */ -class AbstractBeccaEntity { - /** @protected */ - beforeSaving() { +abstract class AbstractBeccaEntity { + + protected utcDateModified?: string; + + protected beforeSaving() { if (!this[this.constructor.primaryKeyName]) { this[this.constructor.primaryKeyName] = utils.newEntityId(); } } - /** @protected */ - getUtcDateChanged() { + protected getUtcDateChanged() { return this.utcDateModified || this.utcDateCreated; } - /** - * @protected - * @returns {Becca} - */ - get becca() { + protected get becca(): Becca { if (!becca) { - becca = require('../becca.js'); + becca = require('../becca'); } - return becca; + return becca as Becca; } - /** @protected */ - putEntityChange(isDeleted) { + protected putEntityChange(isDeleted: boolean) { entityChangesService.putEntityChange({ entityName: this.constructor.entityName, entityId: this[this.constructor.primaryKeyName], @@ -52,11 +49,7 @@ class AbstractBeccaEntity { }); } - /** - * @protected - * @returns {string} - */ - generateHash(isDeleted) { + protected generateHash(isDeleted: boolean): string { let contentToHash = ""; for (const propertyName of this.constructor.hashedProperties) { @@ -70,25 +63,16 @@ class AbstractBeccaEntity { return utils.hash(contentToHash).substr(0, 10); } - /** @protected */ - getPojoToSave() { + protected getPojoToSave() { return this.getPojo(); } - /** - * @protected - * @abstract - */ - getPojo() { - throw new Error(`Unimplemented getPojo() for entity '${this.constructor.name}'`) - } + protected abstract getPojo(): {}; /** * Saves entity - executes SQL, but doesn't commit the transaction on its own - * - * @returns {this} */ - save(opts = {}) { + save(opts = {}): this { const entityName = this.constructor.entityName; const primaryKeyName = this.constructor.primaryKeyName; @@ -124,8 +108,7 @@ class AbstractBeccaEntity { return this; } - /** @protected */ - _setContent(content, opts = {}) { + protected _setContent(content, opts = {}) { // client code asks to save entity even if blobId didn't change (something else was changed) opts.forceSave = !!opts.forceSave; opts.forceFrontendReload = !!opts.forceFrontendReload; @@ -243,11 +226,7 @@ class AbstractBeccaEntity { return newBlobId; } - /** - * @protected - * @returns {string|Buffer} - */ - _getContent() { + protected _getContent(): string | Buffer { const row = sql.getRow(`SELECT content FROM blobs WHERE blobId = ?`, [this.blobId]); if (!row) { @@ -261,8 +240,6 @@ class AbstractBeccaEntity { * Mark the entity as (soft) deleted. It will be completely erased later. * * This is a low-level method, for notes and branches use `note.deleteNote()` and 'branch.deleteBranch()` instead. - * - * @param [deleteId=null] */ markAsDeleted(deleteId = null) { const entityId = this[this.constructor.primaryKeyName]; @@ -306,4 +283,4 @@ class AbstractBeccaEntity { } } -module.exports = AbstractBeccaEntity; +export = AbstractBeccaEntity; diff --git a/src/becca/entities/battachment.js b/src/becca/entities/battachment.ts similarity index 77% rename from src/becca/entities/battachment.js rename to src/becca/entities/battachment.ts index 5445ec3de..7b6c3f657 100644 --- a/src/becca/entities/battachment.js +++ b/src/becca/entities/battachment.ts @@ -1,16 +1,24 @@ "use strict"; -const utils = require('../../services/utils'); -const dateUtils = require('../../services/date_utils'); -const AbstractBeccaEntity = require('./abstract_becca_entity.js'); -const sql = require('../../services/sql'); -const protectedSessionService = require('../../services/protected_session'); -const log = require('../../services/log'); +import utils = require('../../services/utils'); +import dateUtils = require('../../services/date_utils'); +import AbstractBeccaEntity = require('./abstract_becca_entity.js'); +import sql = require('../../services/sql'); +import protectedSessionService = require('../../services/protected_session'); +import log = require('../../services/log'); +import { AttachmentRow } from './rows'; const attachmentRoleToNoteTypeMapping = { 'image': 'image' }; +interface ContentOpts { + /** will also save this BAttachment entity */ + forceFullSave: boolean; + /** override frontend heuristics on when to reload, instruct to reload */ + forceFrontendReload: boolean; +} + /** * Attachment represent data related/attached to the note. Conceptually similar to attributes, but intended for * larger amounts of data and generally not accessible to the user. @@ -22,7 +30,24 @@ class BAttachment extends AbstractBeccaEntity { static get primaryKeyName() { return "attachmentId"; } static get hashedProperties() { return ["attachmentId", "ownerId", "role", "mime", "title", "blobId", "utcDateScheduledForErasureSince"]; } - constructor(row) { + noteId?: number; + attachmentId?: string; + /** either noteId or revisionId to which this attachment belongs */ + ownerId: string; + role: string; + mime: string; + title: string; + type?: keyof typeof attachmentRoleToNoteTypeMapping; + position?: number; + blobId: string; + isProtected?: boolean; + dateModified?: string; + utcDateScheduledForErasureSince?: string; + /** optionally added to the entity */ + contentLength?: number; + isDecrypted?: boolean; + + constructor(row: AttachmentRow) { super(); if (!row.ownerId?.trim()) { @@ -35,43 +60,23 @@ class BAttachment extends AbstractBeccaEntity { throw new Error("'title' must be given to initialize a Attachment entity"); } - /** @type {string} */ this.attachmentId = row.attachmentId; - /** - * either noteId or revisionId to which this attachment belongs - * @type {string} - */ this.ownerId = row.ownerId; - /** @type {string} */ this.role = row.role; - /** @type {string} */ this.mime = row.mime; - /** @type {string} */ this.title = row.title; - /** @type {int} */ this.position = row.position; - /** @type {string} */ this.blobId = row.blobId; - /** @type {boolean} */ this.isProtected = !!row.isProtected; - /** @type {string} */ this.dateModified = row.dateModified; - /** @type {string} */ this.utcDateModified = row.utcDateModified; - /** @type {string} */ this.utcDateScheduledForErasureSince = row.utcDateScheduledForErasureSince; - - /** - * optionally added to the entity - * @type {int} - */ this.contentLength = row.contentLength; this.decrypt(); } - /** @returns {BAttachment} */ - copy() { + copy(): BAttachment { return new BAttachment({ ownerId: this.ownerId, role: this.role, @@ -82,13 +87,12 @@ class BAttachment extends AbstractBeccaEntity { }); } - /** @returns {BNote} */ - getNote() { + getNote(): BNote { return this.becca.notes[this.ownerId]; } - /** @returns {boolean} true if the note has string content (not binary) */ - hasStringContent() { + /** @returns true if the note has string content (not binary) */ + hasStringContent(): boolean { return utils.isStringNote(this.type, this.mime); } @@ -110,32 +114,24 @@ class BAttachment extends AbstractBeccaEntity { if (!this.isDecrypted && protectedSessionService.isProtectedSessionAvailable()) { try { - this.title = protectedSessionService.decryptString(this.title); + this.title = protectedSessionService.decryptString(this.title) || ""; this.isDecrypted = true; } - catch (e) { + catch (e: any) { log.error(`Could not decrypt attachment ${this.attachmentId}: ${e.message} ${e.stack}`); } } } - /** @returns {string|Buffer} */ - getContent() { + getContent(): string | Buffer { return this._getContent(); } - /** - * @param content - * @param {object} [opts] - * @param {object} [opts.forceSave=false] - will also save this BAttachment entity - * @param {object} [opts.forceFrontendReload=false] - override frontend heuristics on when to reload, instruct to reload - */ - setContent(content, opts) { + setContent(content: any, opts: ContentOpts) { this._setContent(content, opts); } - /** @returns {{note: BNote, branch: BBranch}} */ - convertToNote() { + convertToNote(): { note: BNote, branch: BBranch } { if (this.type === 'search') { throw new Error(`Note of type search cannot have child notes`); } @@ -195,9 +191,9 @@ class BAttachment extends AbstractBeccaEntity { super.beforeSaving(); if (this.position === undefined || this.position === null) { - this.position = 10 + sql.getValue(`SELECT COALESCE(MAX(position), 0) - FROM attachments - WHERE ownerId = ?`, [this.noteId]); + this.position = 10 + sql.getValue(`SELECT COALESCE(MAX(position), 0) + FROM attachments + WHERE ownerId = ?`, [this.noteId]); } this.dateModified = dateUtils.localNowDateTime(); @@ -210,7 +206,7 @@ class BAttachment extends AbstractBeccaEntity { ownerId: this.ownerId, role: this.role, mime: this.mime, - title: this.title, + title: this.title || undefined, position: this.position, blobId: this.blobId, isProtected: !!this.isProtected, @@ -228,7 +224,7 @@ class BAttachment extends AbstractBeccaEntity { if (pojo.isProtected) { if (this.isDecrypted) { - pojo.title = protectedSessionService.encrypt(pojo.title); + pojo.title = protectedSessionService.encrypt(pojo.title || "") || undefined; } else { // updating protected note outside of protected session means we will keep original ciphertexts @@ -240,4 +236,4 @@ class BAttachment extends AbstractBeccaEntity { } } -module.exports = BAttachment; +export = BAttachment; diff --git a/src/becca/entities/bnote.js b/src/becca/entities/bnote.ts similarity index 98% rename from src/becca/entities/bnote.js rename to src/becca/entities/bnote.ts index 7372b4d0d..5cfded718 100644 --- a/src/becca/entities/bnote.js +++ b/src/becca/entities/bnote.ts @@ -1,17 +1,17 @@ "use strict"; -const protectedSessionService = require('../../services/protected_session.js'); -const log = require('../../services/log'); -const sql = require('../../services/sql'); -const utils = require('../../services/utils'); -const dateUtils = require('../../services/date_utils'); -const AbstractBeccaEntity = require('./abstract_becca_entity.js'); -const BRevision = require('./brevision.js'); -const BAttachment = require('./battachment.js'); -const TaskContext = require('../../services/task_context.js'); -const dayjs = require("dayjs"); -const utc = require('dayjs/plugin/utc'); -const eventService = require('../../services/events.js'); +import protectedSessionService = require('../../services/protected_session'); +import log = require('../../services/log'); +import sql = require('../../services/sql'); +import utils = require('../../services/utils'); +import dateUtils = require('../../services/date_utils'); +import AbstractBeccaEntity = require('./abstract_becca_entity.js'); +import BRevision = require('./brevision.js'); +import BAttachment = require('./battachment.ts'); +import TaskContext = require('../../services/task_context.js'); +import dayjs = require("dayjs"); +import utc = require('dayjs/plugin/utc'); +import eventService = require('../../services/events.ts'); dayjs.extend(utc); const LABEL = 'label'; diff --git a/src/becca/entities/brecent_note.js b/src/becca/entities/brecent_note.ts similarity index 69% rename from src/becca/entities/brecent_note.js rename to src/becca/entities/brecent_note.ts index 8a840e2d0..a6796d0ff 100644 --- a/src/becca/entities/brecent_note.js +++ b/src/becca/entities/brecent_note.ts @@ -1,7 +1,9 @@ "use strict"; -const dateUtils = require('../../services/date_utils'); -const AbstractBeccaEntity = require('./abstract_becca_entity.js'); +import { RecentNoteRow } from "./rows"; + +import dateUtils = require('../../services/date_utils'); +import AbstractBeccaEntity = require('./abstract_becca_entity.js'); /** * RecentNote represents recently visited note. @@ -12,14 +14,15 @@ class BRecentNote extends AbstractBeccaEntity { static get entityName() { return "recent_notes"; } static get primaryKeyName() { return "noteId"; } - constructor(row) { + noteId: string; + notePath: string; + utcDateCreated: string; + + constructor(row: RecentNoteRow) { super(); - /** @type {string} */ this.noteId = row.noteId; - /** @type {string} */ this.notePath = row.notePath; - /** @type {string} */ this.utcDateCreated = row.utcDateCreated || dateUtils.utcNowDateTime(); } diff --git a/src/becca/entities/brevision.js b/src/becca/entities/brevision.ts similarity index 73% rename from src/becca/entities/brevision.js rename to src/becca/entities/brevision.ts index ad819ad90..fb590ddbb 100644 --- a/src/becca/entities/brevision.js +++ b/src/becca/entities/brevision.ts @@ -1,12 +1,22 @@ "use strict"; -const protectedSessionService = require('../../services/protected_session'); -const utils = require('../../services/utils'); -const dateUtils = require('../../services/date_utils'); -const becca = require('../becca.js'); -const AbstractBeccaEntity = require('./abstract_becca_entity.js'); -const sql = require('../../services/sql'); -const BAttachment = require('./battachment.js'); +import protectedSessionService = require('../../services/protected_session'); +import utils = require('../../services/utils'); +import dateUtils = require('../../services/date_utils'); +import becca = require('../becca.js'); +import AbstractBeccaEntity = require('./abstract_becca_entity.js'); +import sql = require('../../services/sql'); +import BAttachment = require('./battachment.js'); +import { AttachmentRow, RevisionRow } from './rows'; + +interface ContentOpts { + /** will also save this BRevision entity */ + forceSave: boolean; +} + +interface GetByIdOpts { + includeContentLength?: boolean; +} /** * Revision represents a snapshot of note's title and content at some point in the past. @@ -20,40 +30,39 @@ class BRevision extends AbstractBeccaEntity { static get hashedProperties() { return ["revisionId", "noteId", "title", "isProtected", "dateLastEdited", "dateCreated", "utcDateLastEdited", "utcDateCreated", "utcDateModified", "blobId"]; } - constructor(row, titleDecrypted = false) { + revisionId: string; + noteId: string; + type: string; + mime: string; + isProtected: boolean; + title: string; + blobId: string; + dateLastEdited: string; + dateCreated: string; + utcDateLastEdited: string; + utcDateCreated: string; + contentLength?: number; + + constructor(row: RevisionRow, titleDecrypted = false) { super(); - /** @type {string} */ this.revisionId = row.revisionId; - /** @type {string} */ this.noteId = row.noteId; - /** @type {string} */ this.type = row.type; - /** @type {string} */ this.mime = row.mime; - /** @type {boolean} */ this.isProtected = !!row.isProtected; - /** @type {string} */ this.title = row.title; - /** @type {string} */ this.blobId = row.blobId; - /** @type {string} */ this.dateLastEdited = row.dateLastEdited; - /** @type {string} */ this.dateCreated = row.dateCreated; - /** @type {string} */ this.utcDateLastEdited = row.utcDateLastEdited; - /** @type {string} */ this.utcDateCreated = row.utcDateCreated; - /** @type {string} */ this.utcDateModified = row.utcDateModified; - /** @type {int} */ this.contentLength = row.contentLength; if (this.isProtected && !titleDecrypted) { - this.title = protectedSessionService.isProtectedSessionAvailable() - ? protectedSessionService.decryptString(this.title) - : "[protected]"; + const decryptedTitle = protectedSessionService.isProtectedSessionAvailable() ? protectedSessionService.decryptString(this.title) : null; + this.title = decryptedTitle || "[protected]"; } } @@ -80,16 +89,13 @@ class BRevision extends AbstractBeccaEntity { * * This is the same approach as is used for Note's content. */ - - /** @returns {string|Buffer} */ - getContent() { + getContent(): string | Buffer { return this._getContent(); } /** - * @returns {*} * @throws Error in case of invalid JSON */ - getJsonContent() { + getJsonContent(): {} | null { const content = this.getContent(); if (!content || !content.trim()) { @@ -99,8 +105,8 @@ class BRevision extends AbstractBeccaEntity { return JSON.parse(content); } - /** @returns {*|null} valid object or null if the content cannot be parsed as JSON */ - getJsonContentSafely() { + /** @returns valid object or null if the content cannot be parsed as JSON */ + getJsonContentSafely(): {} | null { try { return this.getJsonContent(); } @@ -109,18 +115,12 @@ class BRevision extends AbstractBeccaEntity { } } - /** - * @param content - * @param {object} [opts] - * @param {object} [opts.forceSave=false] - will also save this BRevision entity - */ - setContent(content, opts) { + setContent(content: any, opts: ContentOpts) { this._setContent(content, opts); } - /** @returns {BAttachment[]} */ - getAttachments() { - return sql.getRows(` + getAttachments(): BAttachment[] { + return sql.getRows(` SELECT attachments.* FROM attachments WHERE ownerId = ? @@ -128,8 +128,7 @@ class BRevision extends AbstractBeccaEntity { .map(row => new BAttachment(row)); } - /** @returns {BAttachment|null} */ - getAttachmentById(attachmentId, opts = {}) { + getAttachmentById(attachmentId: String, opts: GetByIdOpts = {}): BAttachment | null { opts.includeContentLength = !!opts.includeContentLength; const query = opts.includeContentLength @@ -139,13 +138,12 @@ class BRevision extends AbstractBeccaEntity { WHERE ownerId = ? AND attachmentId = ? AND isDeleted = 0` : `SELECT * FROM attachments WHERE ownerId = ? AND attachmentId = ? AND isDeleted = 0`; - return sql.getRows(query, [this.revisionId, attachmentId]) + return sql.getRows(query, [this.revisionId, attachmentId]) .map(row => new BAttachment(row))[0]; } - /** @returns {BAttachment[]} */ - getAttachmentsByRole(role) { - return sql.getRows(` + getAttachmentsByRole(role: string): BAttachment[] { + return sql.getRows(` SELECT attachments.* FROM attachments WHERE ownerId = ? @@ -155,8 +153,7 @@ class BRevision extends AbstractBeccaEntity { .map(row => new BAttachment(row)); } - /** @returns {BAttachment} */ - getAttachmentByTitle(title) { + getAttachmentByTitle(title: string): BAttachment { // cannot use SQL to filter by title since it can be encrypted return this.getAttachments().filter(attachment => attachment.title === title)[0]; } @@ -174,7 +171,7 @@ class BRevision extends AbstractBeccaEntity { type: this.type, mime: this.mime, isProtected: this.isProtected, - title: this.title, + title: this.title || undefined, blobId: this.blobId, dateLastEdited: this.dateLastEdited, dateCreated: this.dateCreated, @@ -193,7 +190,7 @@ class BRevision extends AbstractBeccaEntity { if (pojo.isProtected) { if (protectedSessionService.isProtectedSessionAvailable()) { - pojo.title = protectedSessionService.encrypt(this.title); + pojo.title = protectedSessionService.encrypt(this.title) || undefined; } else { // updating protected note outside of protected session means we will keep original ciphertexts diff --git a/src/becca/entities/rows.ts b/src/becca/entities/rows.ts new file mode 100644 index 000000000..5793ee7ab --- /dev/null +++ b/src/becca/entities/rows.ts @@ -0,0 +1,36 @@ +export interface AttachmentRow { + attachmentId?: string; + ownerId: string; + role: string; + mime: string; + title?: string; + position?: number; + blobId: string; + isProtected?: boolean; + dateModified?: string; + utcDateModified?: string; + utcDateScheduledForErasureSince?: string; + contentLength?: number; +} + +export interface RevisionRow { + revisionId: string; + noteId: string; + type: string; + mime: string; + isProtected: boolean; + title: string; + blobId: string; + dateLastEdited: string; + dateCreated: string; + utcDateLastEdited: string; + utcDateCreated: string; + utcDateModified: string; + contentLength?: number; +} + +export interface RecentNoteRow { + noteId: string; + notePath: string; + utcDateCreated?: string; +} diff --git a/src/services/search/note_set.js b/src/services/search/note_set.ts similarity index 97% rename from src/services/search/note_set.js rename to src/services/search/note_set.ts index 82c236cf6..3ce84b469 100644 --- a/src/services/search/note_set.js +++ b/src/services/search/note_set.ts @@ -59,4 +59,4 @@ class NoteSet { } } -module.exports = NoteSet; +export = NoteSet; From 768aaf2d7835497723e0256cf6d03b49c490840c Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 17 Feb 2024 01:00:38 +0200 Subject: [PATCH 23/49] server-ts: Port boption --- src/becca/becca-interface.ts | 4 +++- src/becca/entities/bnote.ts | 2 +- src/becca/entities/{boption.js => boption.ts} | 22 +++++++++---------- src/becca/entities/rows.ts | 9 ++++++++ 4 files changed, 24 insertions(+), 13 deletions(-) rename src/becca/entities/{boption.js => boption.ts} (72%) diff --git a/src/becca/becca-interface.ts b/src/becca/becca-interface.ts index 294442cbb..312f6be18 100644 --- a/src/becca/becca-interface.ts +++ b/src/becca/becca-interface.ts @@ -1,6 +1,8 @@ import sql = require('../services/sql'); import NoteSet = require('../services/search/note_set'); import NotFoundError = require('../errors/not_found_error'); +import BOption = require('./entities/boption'); +import BNote = require('./entities/bnote'); /** * Becca is a backend cache of all notes, branches, and attributes. @@ -8,6 +10,7 @@ import NotFoundError = require('../errors/not_found_error'); */ class Becca { notes!: Record; + options!: Record; constructor() { this.reset(); @@ -24,7 +27,6 @@ class Becca { this.attributes = {}; /** @type {Object.} Points from attribute type-name to list of attributes */ this.attributeIndex = {}; - /** @type {Object.} */ this.options = {}; /** @type {Object.} */ this.etapiTokens = {}; diff --git a/src/becca/entities/bnote.ts b/src/becca/entities/bnote.ts index 5cfded718..f72a83916 100644 --- a/src/becca/entities/bnote.ts +++ b/src/becca/entities/bnote.ts @@ -1725,4 +1725,4 @@ class BNote extends AbstractBeccaEntity { } } -module.exports = BNote; +export = BNote; diff --git a/src/becca/entities/boption.js b/src/becca/entities/boption.ts similarity index 72% rename from src/becca/entities/boption.js rename to src/becca/entities/boption.ts index 7fa121ccc..ebfd951d1 100644 --- a/src/becca/entities/boption.js +++ b/src/becca/entities/boption.ts @@ -1,33 +1,33 @@ "use strict"; -const dateUtils = require('../../services/date_utils'); -const AbstractBeccaEntity = require('./abstract_becca_entity.js'); +import dateUtils = require('../../services/date_utils'); +import AbstractBeccaEntity = require('./abstract_becca_entity.js'); +import { OptionRow } from './rows'; /** * Option represents a name-value pair, either directly configurable by the user or some system property. - * - * @extends AbstractBeccaEntity */ class BOption extends AbstractBeccaEntity { static get entityName() { return "options"; } static get primaryKeyName() { return "name"; } static get hashedProperties() { return ["name", "value"]; } - constructor(row) { + name!: string; + value!: string; + isSynced!: boolean; + utcDateModified!: string; + + constructor(row: OptionRow) { super(); this.updateFromRow(row); this.becca.options[this.name] = this; } - updateFromRow(row) { - /** @type {string} */ + updateFromRow(row: OptionRow) { this.name = row.name; - /** @type {string} */ this.value = row.value; - /** @type {boolean} */ this.isSynced = !!row.isSynced; - /** @type {string} */ this.utcDateModified = row.utcDateModified; } @@ -47,4 +47,4 @@ class BOption extends AbstractBeccaEntity { } } -module.exports = BOption; +export = BOption; diff --git a/src/becca/entities/rows.ts b/src/becca/entities/rows.ts index 5793ee7ab..2f583d092 100644 --- a/src/becca/entities/rows.ts +++ b/src/becca/entities/rows.ts @@ -1,3 +1,5 @@ +// FIXME: Booleans should probably be numbers instead (as SQLite does not have booleans.); + export interface AttachmentRow { attachmentId?: string; ownerId: string; @@ -34,3 +36,10 @@ export interface RecentNoteRow { notePath: string; utcDateCreated?: string; } + +export interface OptionRow { + name: string; + value: string; + isSynced: boolean; + utcDateModified: string; +} \ No newline at end of file From 2f15d79476febf3eb8ba4f38c235e1a446458d52 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 17 Feb 2024 01:03:38 +0200 Subject: [PATCH 24/49] server-ts: Port betapi_token --- src/becca/becca-interface.ts | 3 ++- .../{betapi_token.js => betapi_token.ts} | 21 +++++++++++-------- src/becca/entities/rows.ts | 9 ++++++++ 3 files changed, 23 insertions(+), 10 deletions(-) rename src/becca/entities/{betapi_token.js => betapi_token.ts} (86%) diff --git a/src/becca/becca-interface.ts b/src/becca/becca-interface.ts index 312f6be18..954c34966 100644 --- a/src/becca/becca-interface.ts +++ b/src/becca/becca-interface.ts @@ -3,6 +3,7 @@ import NoteSet = require('../services/search/note_set'); import NotFoundError = require('../errors/not_found_error'); import BOption = require('./entities/boption'); import BNote = require('./entities/bnote'); +import BEtapiToken = require('./entities/betapi_token'); /** * Becca is a backend cache of all notes, branches, and attributes. @@ -11,6 +12,7 @@ import BNote = require('./entities/bnote'); class Becca { notes!: Record; options!: Record; + etapiTokens!: Record; constructor() { this.reset(); @@ -28,7 +30,6 @@ class Becca { /** @type {Object.} Points from attribute type-name to list of attributes */ this.attributeIndex = {}; this.options = {}; - /** @type {Object.} */ this.etapiTokens = {}; this.dirtyNoteSetCache(); diff --git a/src/becca/entities/betapi_token.js b/src/becca/entities/betapi_token.ts similarity index 86% rename from src/becca/entities/betapi_token.js rename to src/becca/entities/betapi_token.ts index aedc1615f..4809dc265 100644 --- a/src/becca/entities/betapi_token.js +++ b/src/becca/entities/betapi_token.ts @@ -1,5 +1,7 @@ "use strict"; +import { EtapiTokenRow } from "./rows"; + const dateUtils = require('../../services/date_utils'); const AbstractBeccaEntity = require('./abstract_becca_entity.js'); @@ -19,7 +21,14 @@ class BEtapiToken extends AbstractBeccaEntity { static get primaryKeyName() { return "etapiTokenId"; } static get hashedProperties() { return ["etapiTokenId", "name", "tokenHash", "utcDateCreated", "utcDateModified", "isDeleted"]; } - constructor(row) { + etapiTokenId!: string; + name!: string; + tokenHash!: string; + utcDateCreated!: string; + utcDateModified!: string; + isDeleted!: boolean; + + constructor(row: EtapiTokenRow) { super(); if (!row) { @@ -30,18 +39,12 @@ class BEtapiToken extends AbstractBeccaEntity { this.init(); } - updateFromRow(row) { - /** @type {string} */ + updateFromRow(row: EtapiTokenRow) { this.etapiTokenId = row.etapiTokenId; - /** @type {string} */ this.name = row.name; - /** @type {string} */ this.tokenHash = row.tokenHash; - /** @type {string} */ this.utcDateCreated = row.utcDateCreated || dateUtils.utcNowDateTime(); - /** @type {string} */ this.utcDateModified = row.utcDateModified || this.utcDateCreated; - /** @type {boolean} */ this.isDeleted = !!row.isDeleted; if (this.etapiTokenId) { @@ -75,4 +78,4 @@ class BEtapiToken extends AbstractBeccaEntity { } } -module.exports = BEtapiToken; +export = BEtapiToken; diff --git a/src/becca/entities/rows.ts b/src/becca/entities/rows.ts index 2f583d092..e2f0a240c 100644 --- a/src/becca/entities/rows.ts +++ b/src/becca/entities/rows.ts @@ -42,4 +42,13 @@ export interface OptionRow { value: string; isSynced: boolean; utcDateModified: string; +} + +export interface EtapiTokenRow { + etapiTokenId: string; + name: string; + tokenHash: string; + utcDateCreated?: string; + utcDateModified?: string; + isDeleted: boolean; } \ No newline at end of file From eef8297ce1812a2f56e68d1ee8c0d3367bfc9642 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 17 Feb 2024 01:06:07 +0200 Subject: [PATCH 25/49] server-ts: Port bblob --- src/becca/entities/{bblob.js => bblob.ts} | 17 ++++++++++------- src/becca/entities/rows.ts | 8 ++++++++ 2 files changed, 18 insertions(+), 7 deletions(-) rename src/becca/entities/{bblob.js => bblob.ts} (75%) diff --git a/src/becca/entities/bblob.js b/src/becca/entities/bblob.ts similarity index 75% rename from src/becca/entities/bblob.js rename to src/becca/entities/bblob.ts index def5888ee..2ea67f044 100644 --- a/src/becca/entities/bblob.js +++ b/src/becca/entities/bblob.ts @@ -1,18 +1,21 @@ +import { BlobRow } from "./rows"; + class BBlob { static get entityName() { return "blobs"; } static get primaryKeyName() { return "blobId"; } static get hashedProperties() { return ["blobId", "content"]; } - constructor(row) { - /** @type {string} */ + blobId: string; + content: string | Buffer; + contentLength: number; + dateModified: string; + utcDateModified: string; + + constructor(row: BlobRow) { this.blobId = row.blobId; - /** @type {string|Buffer} */ this.content = row.content; - /** @type {int} */ this.contentLength = row.contentLength; - /** @type {string} */ this.dateModified = row.dateModified; - /** @type {string} */ this.utcDateModified = row.utcDateModified; } @@ -27,4 +30,4 @@ class BBlob { } } -module.exports = BBlob; +export = BBlob; diff --git a/src/becca/entities/rows.ts b/src/becca/entities/rows.ts index e2f0a240c..54c0e8b04 100644 --- a/src/becca/entities/rows.ts +++ b/src/becca/entities/rows.ts @@ -51,4 +51,12 @@ export interface EtapiTokenRow { utcDateCreated?: string; utcDateModified?: string; isDeleted: boolean; +} + +export interface BlobRow { + blobId: string; + content: string | Buffer; + contentLength: number; + dateModified: string; + utcDateModified: string; } \ No newline at end of file From 06287da9d8c2104f084005c7394ef107ffacdd62 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 17 Feb 2024 01:19:49 +0200 Subject: [PATCH 26/49] server-ts: Port battribute --- src/becca/becca-interface.ts | 8 ++-- .../entities/{battribute.js => battribute.ts} | 45 +++++++++---------- src/becca/entities/rows.ts | 13 ++++++ ...> promoted_attribute_definition_parser.ts} | 17 +++++-- ...ute_name.js => sanitize_attribute_name.ts} | 8 ++-- 5 files changed, 54 insertions(+), 37 deletions(-) rename src/becca/entities/{battribute.js => battribute.ts} (86%) rename src/services/{promoted_attribute_definition_parser.js => promoted_attribute_definition_parser.ts} (75%) rename src/services/{sanitize_attribute_name.js => sanitize_attribute_name.ts} (69%) diff --git a/src/becca/becca-interface.ts b/src/becca/becca-interface.ts index 954c34966..6b36892b3 100644 --- a/src/becca/becca-interface.ts +++ b/src/becca/becca-interface.ts @@ -4,6 +4,7 @@ import NotFoundError = require('../errors/not_found_error'); import BOption = require('./entities/boption'); import BNote = require('./entities/bnote'); import BEtapiToken = require('./entities/betapi_token'); +import BAttribute = require('./entities/battribute'); /** * Becca is a backend cache of all notes, branches, and attributes. @@ -11,6 +12,9 @@ import BEtapiToken = require('./entities/betapi_token'); */ class Becca { notes!: Record; + attributes!: Record; + /** Points from attribute type-name to list of attributes */ + attributeIndex!: Record; options!: Record; etapiTokens!: Record; @@ -25,9 +29,7 @@ class Becca { this.branches = {}; /** @type {Object.} */ this.childParentToBranch = {}; - /** @type {Object.} */ - this.attributes = {}; - /** @type {Object.} Points from attribute type-name to list of attributes */ + this.attributes = {}; this.attributeIndex = {}; this.options = {}; this.etapiTokens = {}; diff --git a/src/becca/entities/battribute.js b/src/becca/entities/battribute.ts similarity index 86% rename from src/becca/entities/battribute.js rename to src/becca/entities/battribute.ts index 54afd3587..71d575193 100644 --- a/src/becca/entities/battribute.js +++ b/src/becca/entities/battribute.ts @@ -1,17 +1,11 @@ "use strict"; -const BNote = require('./bnote.js'); -const AbstractBeccaEntity = require('./abstract_becca_entity.js'); -const sql = require('../../services/sql'); -const dateUtils = require('../../services/date_utils'); -const promotedAttributeDefinitionParser = require('../../services/promoted_attribute_definition_parser.js'); -const {sanitizeAttributeName} = require('../../services/sanitize_attribute_name.js'); - - -/** - * There are currently only two types of attributes, labels or relations. - * @typedef {"label" | "relation"} AttributeType - */ +import BNote = require('./bnote.js'); +import AbstractBeccaEntity = require('./abstract_becca_entity.js'); +import dateUtils = require('../../services/date_utils'); +import promotedAttributeDefinitionParser = require('../../services/promoted_attribute_definition_parser'); +import sanitizeAttributeName = require('../../services/sanitize_attribute_name'); +import { AttributeRow, AttributeType } from './rows.js'; /** * Attribute is an abstract concept which has two real uses - label (key - value pair) @@ -24,7 +18,16 @@ class BAttribute extends AbstractBeccaEntity { static get primaryKeyName() { return "attributeId"; } static get hashedProperties() { return ["attributeId", "noteId", "type", "name", "value", "isInheritable"]; } - constructor(row) { + attributeId!: string; + noteId!: string; + type!: AttributeType; + name!: string; + position!: number; + value!: string; + isInheritable!: boolean; + utcDateModified!: string; + + constructor(row: AttributeRow) { super(); if (!row) { @@ -35,7 +38,7 @@ class BAttribute extends AbstractBeccaEntity { this.init(); } - updateFromRow(row) { + updateFromRow(row: AttributeRow) { this.update([ row.attributeId, row.noteId, @@ -48,22 +51,14 @@ class BAttribute extends AbstractBeccaEntity { ]); } - update([attributeId, noteId, type, name, value, isInheritable, position, utcDateModified]) { - /** @type {string} */ + update([attributeId, noteId, type, name, value, isInheritable, position, utcDateModified]: any[]) { this.attributeId = attributeId; - /** @type {string} */ this.noteId = noteId; - /** @type {AttributeType} */ this.type = type; - /** @type {string} */ this.name = name; - /** @type {int} */ this.position = position; - /** @type {string} */ this.value = value || ""; - /** @type {boolean} */ this.isInheritable = !!isInheritable; - /** @type {string} */ this.utcDateModified = utcDateModified; return this; @@ -226,7 +221,7 @@ class BAttribute extends AbstractBeccaEntity { }; } - createClone(type, name, value, isInheritable) { + createClone(type: AttributeType, name: string, value: string, isInheritable: boolean) { return new BAttribute({ noteId: this.noteId, type: type, @@ -239,4 +234,4 @@ class BAttribute extends AbstractBeccaEntity { } } -module.exports = BAttribute; +export = BAttribute; diff --git a/src/becca/entities/rows.ts b/src/becca/entities/rows.ts index 54c0e8b04..98bb0ec8a 100644 --- a/src/becca/entities/rows.ts +++ b/src/becca/entities/rows.ts @@ -59,4 +59,17 @@ export interface BlobRow { contentLength: number; dateModified: string; utcDateModified: string; +} + +export type AttributeType = "label" | "relation"; + +export interface AttributeRow { + attributeId?: string; + noteId: string; + type: AttributeType; + name: string; + position: number; + value: string; + isInheritable: boolean; + utcDateModified: string; } \ No newline at end of file diff --git a/src/services/promoted_attribute_definition_parser.js b/src/services/promoted_attribute_definition_parser.ts similarity index 75% rename from src/services/promoted_attribute_definition_parser.js rename to src/services/promoted_attribute_definition_parser.ts index 937dae1de..cd3dc18db 100644 --- a/src/services/promoted_attribute_definition_parser.js +++ b/src/services/promoted_attribute_definition_parser.ts @@ -1,6 +1,15 @@ -function parse(value) { +interface DefinitionObject { + isPromoted: boolean; + labelType: string; + multiplicity: string; + numberPrecision: number; + promotedAlias: string; + inverseRelation: string; +} + +function parse(value: string): DefinitionObject { const tokens = value.split(',').map(t => t.trim()); - const defObj = {}; + const defObj: Partial = {}; for (const token of tokens) { if (token === 'promoted') { @@ -32,9 +41,9 @@ function parse(value) { } } - return defObj; + return defObj as DefinitionObject; } -module.exports = { +export = { parse }; diff --git a/src/services/sanitize_attribute_name.js b/src/services/sanitize_attribute_name.ts similarity index 69% rename from src/services/sanitize_attribute_name.js rename to src/services/sanitize_attribute_name.ts index 3a7c9ff67..ecdc35dc0 100644 --- a/src/services/sanitize_attribute_name.js +++ b/src/services/sanitize_attribute_name.ts @@ -1,5 +1,5 @@ -function sanitizeAttributeName(origName) { - let fixedName; +function sanitizeAttributeName(origName: string) { + let fixedName: string; if (origName === '') { fixedName = "unnamed"; @@ -13,6 +13,4 @@ function sanitizeAttributeName(origName) { } -module.exports = { - sanitizeAttributeName -}; +export = sanitizeAttributeName; From 4b1d2c6bade2cdc63dc8bccca48cb0017dba1af0 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 17 Feb 2024 01:24:37 +0200 Subject: [PATCH 27/49] server-ts: Port options service --- src/becca/becca-interface.ts | 2 ++ src/services/{options.js => options.ts} | 27 +++++++++++-------------- 2 files changed, 14 insertions(+), 15 deletions(-) rename src/services/{options.js => options.ts} (72%) diff --git a/src/becca/becca-interface.ts b/src/becca/becca-interface.ts index 6b36892b3..041e4b0cc 100644 --- a/src/becca/becca-interface.ts +++ b/src/becca/becca-interface.ts @@ -11,6 +11,8 @@ import BAttribute = require('./entities/battribute'); * There's a similar frontend cache Froca, and share cache Shaca. */ class Becca { + loaded!: boolean; + notes!: Record; attributes!: Record; /** Points from attribute type-name to list of attributes */ diff --git a/src/services/options.js b/src/services/options.ts similarity index 72% rename from src/services/options.js rename to src/services/options.ts index e7e90331b..41532d74f 100644 --- a/src/services/options.js +++ b/src/services/options.ts @@ -1,22 +1,21 @@ -const becca = require('../becca/becca.js'); -const sql = require('./sql'); +import becca = require('../becca/becca'); +import { OptionRow } from '../becca/entities/rows'; +import sql = require('./sql'); -/** @returns {string|null} */ -function getOptionOrNull(name) { +function getOptionOrNull(name: string): string | null { let option; if (becca.loaded) { option = becca.getOption(name); } else { // e.g. in initial sync becca is not loaded because DB is not initialized - option = sql.getRow("SELECT * FROM options WHERE name = ?", [name]); + option = sql.getRow("SELECT * FROM options WHERE name = ?", [name]); } return option ? option.value : null; } -/** @returns {string} */ -function getOption(name) { +function getOption(name: string): string { const val = getOptionOrNull(name); if (val === null) { @@ -26,8 +25,7 @@ function getOption(name) { return val; } -/** @returns {int} */ -function getOptionInt(name, defaultValue = undefined) { +function getOptionInt(name: string, defaultValue?: number): number { const val = getOption(name); const intVal = parseInt(val); @@ -43,8 +41,7 @@ function getOptionInt(name, defaultValue = undefined) { return intVal; } -/** @returns {boolean} */ -function getOptionBool(name) { +function getOptionBool(name: string): boolean { const val = getOption(name); if (!['true', 'false'].includes(val)) { @@ -54,7 +51,7 @@ function getOptionBool(name) { return val === 'true'; } -function setOption(name, value) { +function setOption(name: string, value: string | boolean) { if (value === true || value === false) { value = value.toString(); } @@ -71,9 +68,9 @@ function setOption(name, value) { } } -function createOption(name, value, isSynced) { +function createOption(name: string, value: string, isSynced: boolean) { // to avoid circular dependency, need to find a better solution - const BOption = require('../becca/entities/boption.js'); + const BOption = require('../becca/entities/boption'); new BOption({ name: name, @@ -87,7 +84,7 @@ function getOptions() { } function getOptionMap() { - const map = {}; + const map: Record = {}; for (const option of Object.values(becca.options)) { map[option.name] = option.value; From cf18e61a3329b730f6b0cdd7e87f094b8557fb6f Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 17 Feb 2024 01:51:47 +0200 Subject: [PATCH 28/49] server-ts: Port ws service & dependencies --- package-lock.json | 32 +++++++ package.json | 2 + src/becca/entities/abstract_becca_entity.ts | 2 +- src/services/{config.js => config.ts} | 12 +-- src/services/entity_changes_interface.ts | 3 + src/services/env.js | 5 -- src/services/env.ts | 7 ++ src/services/resource_dir.ts | 2 +- src/services/sql.ts | 4 +- src/services/{sync_mutex.js => sync_mutex.ts} | 4 +- src/services/{ws.js => ws.ts} | 88 +++++++++++-------- 11 files changed, 108 insertions(+), 53 deletions(-) rename src/services/{config.js => config.ts} (65%) delete mode 100644 src/services/env.js create mode 100644 src/services/env.ts rename src/services/{sync_mutex.js => sync_mutex.ts} (87%) rename src/services/{ws.js => ws.ts} (74%) diff --git a/package-lock.json b/package-lock.json index 79c32b0f0..b4862777e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -92,8 +92,10 @@ "@types/better-sqlite3": "^7.6.9", "@types/escape-html": "^1.0.4", "@types/express": "^4.17.21", + "@types/ini": "^4.1.0", "@types/mime-types": "^2.1.4", "@types/node": "^20.11.19", + "@types/ws": "^8.5.10", "cross-env": "7.0.3", "electron": "25.9.8", "electron-builder": "24.6.4", @@ -1444,6 +1446,12 @@ "integrity": "sha512-D0CFMMtydbJAegzOyHjtiKPLlvnm3iTZyZRSZoLq2mRhDdmLfIWOCYPfQJ4cu2erKghU++QvjcUjp/5h7hESpA==", "dev": true }, + "node_modules/@types/ini": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/@types/ini/-/ini-4.1.0.tgz", + "integrity": "sha512-mTehMtc+xtnWBBvqizcqYCktKDBH2WChvx1GU3Sfe4PysFDXiNe+1YwtpVX1MDtCa4NQrSPw2+3HmvXHY3gt1w==", + "dev": true + }, "node_modules/@types/json-schema": { "version": "7.0.9", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.9.tgz", @@ -1589,6 +1597,15 @@ "dev": true, "optional": true }, + "node_modules/@types/ws": { + "version": "8.5.10", + "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.10.tgz", + "integrity": "sha512-vmQSUcfalpIq0R9q7uTo2lXs6eGIpt9wtnLdMv9LVpIjCA/+ufZRozlVoVelIYixx1ugCBKDhn89vnsEGOCx9A==", + "dev": true, + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/yauzl": { "version": "2.9.2", "resolved": "https://registry.npmjs.org/@types/yauzl/-/yauzl-2.9.2.tgz", @@ -16086,6 +16103,12 @@ "integrity": "sha512-D0CFMMtydbJAegzOyHjtiKPLlvnm3iTZyZRSZoLq2mRhDdmLfIWOCYPfQJ4cu2erKghU++QvjcUjp/5h7hESpA==", "dev": true }, + "@types/ini": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/@types/ini/-/ini-4.1.0.tgz", + "integrity": "sha512-mTehMtc+xtnWBBvqizcqYCktKDBH2WChvx1GU3Sfe4PysFDXiNe+1YwtpVX1MDtCa4NQrSPw2+3HmvXHY3gt1w==", + "dev": true + }, "@types/json-schema": { "version": "7.0.9", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.9.tgz", @@ -16231,6 +16254,15 @@ "dev": true, "optional": true }, + "@types/ws": { + "version": "8.5.10", + "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.10.tgz", + "integrity": "sha512-vmQSUcfalpIq0R9q7uTo2lXs6eGIpt9wtnLdMv9LVpIjCA/+ufZRozlVoVelIYixx1ugCBKDhn89vnsEGOCx9A==", + "dev": true, + "requires": { + "@types/node": "*" + } + }, "@types/yauzl": { "version": "2.9.2", "resolved": "https://registry.npmjs.org/@types/yauzl/-/yauzl-2.9.2.tgz", diff --git a/package.json b/package.json index 608d4c3a4..1c9c869f6 100644 --- a/package.json +++ b/package.json @@ -115,8 +115,10 @@ "@types/better-sqlite3": "^7.6.9", "@types/escape-html": "^1.0.4", "@types/express": "^4.17.21", + "@types/ini": "^4.1.0", "@types/mime-types": "^2.1.4", "@types/node": "^20.11.19", + "@types/ws": "^8.5.10", "cross-env": "7.0.3", "electron": "25.9.8", "electron-builder": "24.6.4", diff --git a/src/becca/entities/abstract_becca_entity.ts b/src/becca/entities/abstract_becca_entity.ts index 35d0d2979..0f9769fb6 100644 --- a/src/becca/entities/abstract_becca_entity.ts +++ b/src/becca/entities/abstract_becca_entity.ts @@ -67,7 +67,7 @@ abstract class AbstractBeccaEntity { return this.getPojo(); } - protected abstract getPojo(): {}; + abstract getPojo(): {}; /** * Saves entity - executes SQL, but doesn't commit the transaction on its own diff --git a/src/services/config.js b/src/services/config.ts similarity index 65% rename from src/services/config.js rename to src/services/config.ts index 8bc0723a7..f0437a2d1 100644 --- a/src/services/config.js +++ b/src/services/config.ts @@ -1,10 +1,10 @@ "use strict"; -const ini = require('ini'); -const fs = require('fs'); -const dataDir = require('./data_dir'); -const path = require('path'); -const resourceDir = require('./resource_dir'); +import ini = require('ini'); +import fs = require('fs'); +import dataDir = require('./data_dir'); +import path = require('path'); +import resourceDir = require('./resource_dir'); const configSampleFilePath = path.resolve(resourceDir.RESOURCE_DIR, "config-sample.ini"); @@ -16,4 +16,4 @@ if (!fs.existsSync(dataDir.CONFIG_INI_PATH)) { const config = ini.parse(fs.readFileSync(dataDir.CONFIG_INI_PATH, 'utf-8')); -module.exports = config; +export = config; diff --git a/src/services/entity_changes_interface.ts b/src/services/entity_changes_interface.ts index 0a6409a80..2252f27fb 100644 --- a/src/services/entity_changes_interface.ts +++ b/src/services/entity_changes_interface.ts @@ -1,7 +1,10 @@ export interface EntityChange { id?: number | null; + noteId?: string; entityName: string; entityId: string; + entity?: any; + positions?: Record; hash: string; utcDateChanged: string; isSynced: boolean | 1 | 0; diff --git a/src/services/env.js b/src/services/env.js deleted file mode 100644 index e7fa6caf8..000000000 --- a/src/services/env.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = { - isDev: function () { - return !!(process.env.TRILIUM_ENV && process.env.TRILIUM_ENV === 'dev'); - } -}; \ No newline at end of file diff --git a/src/services/env.ts b/src/services/env.ts new file mode 100644 index 000000000..23c94ee0f --- /dev/null +++ b/src/services/env.ts @@ -0,0 +1,7 @@ +function isDev() { + return !!(process.env.TRILIUM_ENV && process.env.TRILIUM_ENV === 'dev'); +} + +export = { + isDev +}; \ No newline at end of file diff --git a/src/services/resource_dir.ts b/src/services/resource_dir.ts index 5bd21b31d..cba351ac8 100644 --- a/src/services/resource_dir.ts +++ b/src/services/resource_dir.ts @@ -20,7 +20,7 @@ if (!fs.existsSync(MIGRATIONS_DIR)) { process.exit(1); } -module.exports = { +export = { RESOURCE_DIR, MIGRATIONS_DIR, DB_INIT_DIR, diff --git a/src/services/sql.ts b/src/services/sql.ts index f31d51728..e1c3f5776 100644 --- a/src/services/sql.ts +++ b/src/services/sql.ts @@ -110,7 +110,7 @@ function getValue(query: string, params: Params = []): T { // smaller values can result in better performance due to better usage of statement cache const PARAM_LIMIT = 100; -function getManyRows(query: string, params: Params) { +function getManyRows(query: string, params: Params): T[] | null { let results: unknown[] = []; while (params.length > 0) { @@ -136,7 +136,7 @@ function getManyRows(query: string, params: Params) { results = results.concat(subResults); } - return results; + return results as (T[] | null); } function getRows(query: string, params: Params = []): T[] { diff --git a/src/services/sync_mutex.js b/src/services/sync_mutex.ts similarity index 87% rename from src/services/sync_mutex.js rename to src/services/sync_mutex.ts index fb95d03c4..655af4d59 100644 --- a/src/services/sync_mutex.js +++ b/src/services/sync_mutex.ts @@ -6,7 +6,7 @@ const Mutex = require('async-mutex').Mutex; const instance = new Mutex(); -async function doExclusively(func) { +async function doExclusively(func: () => void) { const releaseMutex = await instance.acquire(); try { @@ -17,6 +17,6 @@ async function doExclusively(func) { } } -module.exports = { +export = { doExclusively }; diff --git a/src/services/ws.js b/src/services/ws.ts similarity index 74% rename from src/services/ws.js rename to src/services/ws.ts index 73caa8d26..9e76868e4 100644 --- a/src/services/ws.js +++ b/src/services/ws.ts @@ -1,15 +1,17 @@ -const WebSocket = require('ws'); -const utils = require('./utils'); -const log = require('./log'); -const sql = require('./sql'); -const cls = require('./cls'); -const config = require('./config.js'); -const syncMutexService = require('./sync_mutex.js'); -const protectedSessionService = require('./protected_session'); -const becca = require('../becca/becca.js'); -const AbstractBeccaEntity = require('../becca/entities/abstract_becca_entity.js'); +import WebSocket = require('ws'); +import utils = require('./utils'); +import log = require('./log'); +import sql = require('./sql'); +import cls = require('./cls'); +import config = require('./config'); +import syncMutexService = require('./sync_mutex.js'); +import protectedSessionService = require('./protected_session'); +import becca = require('../becca/becca.js'); +import AbstractBeccaEntity = require('../becca/entities/abstract_becca_entity.js'); -const env = require('./env.js'); +import env = require('./env'); +import { IncomingMessage, Server } from 'http'; +import { EntityChange } from './entity_changes_interface'; if (env.isDev()) { const chokidar = require('chokidar'); const debounce = require('debounce'); @@ -21,15 +23,26 @@ if (env.isDev()) { .on('unlink', debouncedReloadFrontend); } -let webSocketServer; -let lastSyncedPush = null; +let webSocketServer!: WebSocket.Server; +let lastSyncedPush: number | null = null; -function init(httpServer, sessionParser) { +interface Message { + type: string; + reason?: string; + data?: { + lastSyncedPush?: number, + entityChanges?: any[] + }, + lastSyncedPush?: number +} + +type SessionParser = (req: IncomingMessage, params: {}, cb: () => void) => void; +function init(httpServer: Server, sessionParser: SessionParser) { webSocketServer = new WebSocket.Server({ verifyClient: (info, done) => { sessionParser(info.req, {}, () => { const allowed = utils.isElectron() - || info.req.session.loggedIn + || (info.req as any).session.loggedIn || (config.General && config.General.noAuthentication); if (!allowed) { @@ -43,12 +56,12 @@ function init(httpServer, sessionParser) { }); webSocketServer.on('connection', (ws, req) => { - ws.id = utils.randomString(10); + (ws as any).id = utils.randomString(10); console.log(`websocket client connected`); ws.on('message', async messageJson => { - const message = JSON.parse(messageJson); + const message = JSON.parse(messageJson as any); if (message.type === 'log-error') { log.info(`JS Error: ${message.error}\r @@ -73,7 +86,7 @@ Stack: ${message.stack}`); }); } -function sendMessage(client, message) { +function sendMessage(client: WebSocket, message: Message) { const jsonStr = JSON.stringify(message); if (client.readyState === WebSocket.OPEN) { @@ -81,7 +94,7 @@ function sendMessage(client, message) { } } -function sendMessageToAllClients(message) { +function sendMessageToAllClients(message: Message) { const jsonStr = JSON.stringify(message); if (webSocketServer) { @@ -97,7 +110,7 @@ function sendMessageToAllClients(message) { } } -function fillInAdditionalProperties(entityChange) { +function fillInAdditionalProperties(entityChange: EntityChange) { if (entityChange.isErased) { return; } @@ -123,14 +136,14 @@ function fillInAdditionalProperties(entityChange) { if (!entityChange.entity) { entityChange.entity = sql.getRow(`SELECT * FROM notes WHERE noteId = ?`, [entityChange.entityId]); - if (entityChange.entity.isProtected) { - entityChange.entity.title = protectedSessionService.decryptString(entityChange.entity.title); + if (entityChange.entity && entityChange.entity.isProtected) { + entityChange.entity.title = protectedSessionService.decryptString(entityChange.entity.title || ""); } } } else if (entityChange.entityName === 'revisions') { - entityChange.noteId = sql.getValue(`SELECT noteId - FROM revisions - WHERE revisionId = ?`, [entityChange.entityId]); + entityChange.noteId = sql.getValue(`SELECT noteId + FROM revisions + WHERE revisionId = ?`, [entityChange.entityId]); } else if (entityChange.entityName === 'note_reordering') { entityChange.positions = {}; @@ -160,7 +173,7 @@ function fillInAdditionalProperties(entityChange) { } // entities with higher number can reference the entities with lower number -const ORDERING = { +const ORDERING: Record = { "etapi_tokens": 0, "attributes": 2, "branches": 2, @@ -172,14 +185,17 @@ const ORDERING = { "options": 0 }; -function sendPing(client, entityChangeIds = []) { +function sendPing(client: WebSocket, entityChangeIds = []) { if (entityChangeIds.length === 0) { sendMessage(client, { type: 'ping' }); return; } - const entityChanges = sql.getManyRows(`SELECT * FROM entity_changes WHERE id IN (???)`, entityChangeIds); + const entityChanges = sql.getManyRows(`SELECT * FROM entity_changes WHERE id IN (???)`, entityChangeIds); + if (!entityChanges) { + return; + } // sort entity changes since froca expects "referential order", i.e. referenced entities should already exist // in froca. @@ -190,7 +206,7 @@ function sendPing(client, entityChangeIds = []) { try { fillInAdditionalProperties(entityChange); } - catch (e) { + catch (e: any) { log.error(`Could not fill additional properties for entity change ${JSON.stringify(entityChange)} because of error: ${e.message}: ${e.stack}`); } } @@ -198,7 +214,7 @@ function sendPing(client, entityChangeIds = []) { sendMessage(client, { type: 'frontend-update', data: { - lastSyncedPush, + lastSyncedPush: lastSyncedPush || undefined, entityChanges } }); @@ -213,26 +229,26 @@ function sendTransactionEntityChangesToAllClients() { } function syncPullInProgress() { - sendMessageToAllClients({ type: 'sync-pull-in-progress', lastSyncedPush }); + sendMessageToAllClients({ type: 'sync-pull-in-progress', lastSyncedPush: lastSyncedPush || undefined }); } function syncPushInProgress() { - sendMessageToAllClients({ type: 'sync-push-in-progress', lastSyncedPush }); + sendMessageToAllClients({ type: 'sync-push-in-progress', lastSyncedPush: lastSyncedPush || undefined }); } function syncFinished() { - sendMessageToAllClients({ type: 'sync-finished', lastSyncedPush }); + sendMessageToAllClients({ type: 'sync-finished', lastSyncedPush: lastSyncedPush || undefined }); } function syncFailed() { - sendMessageToAllClients({ type: 'sync-failed', lastSyncedPush }); + sendMessageToAllClients({ type: 'sync-failed', lastSyncedPush: lastSyncedPush || undefined }); } -function reloadFrontend(reason) { +function reloadFrontend(reason: string) { sendMessageToAllClients({ type: 'reload-frontend', reason }); } -function setLastSyncedPush(entityChangeId) { +function setLastSyncedPush(entityChangeId: number) { lastSyncedPush = entityChangeId; } From f51f070b2fa05f073d8f67d17f71d2a059914cd7 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 17 Feb 2024 02:02:08 +0200 Subject: [PATCH 29/49] server-ts: Port bbranch (with some build errors) --- src/becca/becca-interface.ts | 6 +-- src/becca/entities/{bbranch.js => bbranch.ts} | 47 ++++++++++--------- src/becca/entities/rows.ts | 10 ++++ .../{task_context.js => task_context.ts} | 29 +++++++----- src/services/ws.ts | 12 +++-- 5 files changed, 64 insertions(+), 40 deletions(-) rename src/becca/entities/{bbranch.js => bbranch.ts} (89%) rename src/services/{task_context.js => task_context.ts} (72%) diff --git a/src/becca/becca-interface.ts b/src/becca/becca-interface.ts index 041e4b0cc..f71a81822 100644 --- a/src/becca/becca-interface.ts +++ b/src/becca/becca-interface.ts @@ -5,6 +5,7 @@ import BOption = require('./entities/boption'); import BNote = require('./entities/bnote'); import BEtapiToken = require('./entities/betapi_token'); import BAttribute = require('./entities/battribute'); +import BBranch = require('./entities/bbranch'); /** * Becca is a backend cache of all notes, branches, and attributes. @@ -14,6 +15,8 @@ class Becca { loaded!: boolean; notes!: Record; + branches!: Record; + childParentToBranch!: Record; attributes!: Record; /** Points from attribute type-name to list of attributes */ attributeIndex!: Record; @@ -25,11 +28,8 @@ class Becca { } reset() { - /** @type {Object.} */ this.notes = {}; - /** @type {Object.} */ this.branches = {}; - /** @type {Object.} */ this.childParentToBranch = {}; this.attributes = {}; this.attributeIndex = {}; diff --git a/src/becca/entities/bbranch.js b/src/becca/entities/bbranch.ts similarity index 89% rename from src/becca/entities/bbranch.js rename to src/becca/entities/bbranch.ts index b9a04af7f..f7ed4cffc 100644 --- a/src/becca/entities/bbranch.js +++ b/src/becca/entities/bbranch.ts @@ -1,12 +1,13 @@ "use strict"; -const BNote = require('./bnote.js'); -const AbstractBeccaEntity = require('./abstract_becca_entity.js'); -const dateUtils = require('../../services/date_utils'); -const utils = require('../../services/utils'); -const TaskContext = require('../../services/task_context.js'); -const cls = require('../../services/cls'); -const log = require('../../services/log'); +import BNote = require('./bnote.js'); +import AbstractBeccaEntity = require('./abstract_becca_entity.js'); +import dateUtils = require('../../services/date_utils'); +import utils = require('../../services/utils'); +import TaskContext = require('../../services/task_context'); +import cls = require('../../services/cls'); +import log = require('../../services/log'); +import { BranchRow } from './rows.js'; /** * Branch represents a relationship between a child note and its parent note. Trilium allows a note to have multiple @@ -23,7 +24,15 @@ class BBranch extends AbstractBeccaEntity { // notePosition is not part of hash because it would produce a lot of updates in case of reordering static get hashedProperties() { return ["branchId", "noteId", "parentNoteId", "prefix"]; } - constructor(row) { + branchId?: string; + noteId!: string; + parentNoteId!: string; + prefix!: string; + notePosition!: number; + isExpanded!: boolean; + utcDateModified?: string; + + constructor(row: BranchRow) { super(); if (!row) { @@ -34,7 +43,7 @@ class BBranch extends AbstractBeccaEntity { this.init(); } - updateFromRow(row) { + updateFromRow(row: BranchRow) { this.update([ row.branchId, row.noteId, @@ -46,20 +55,13 @@ class BBranch extends AbstractBeccaEntity { ]); } - update([branchId, noteId, parentNoteId, prefix, notePosition, isExpanded, utcDateModified]) { - /** @type {string} */ + update([branchId, noteId, parentNoteId, prefix, notePosition, isExpanded, utcDateModified]: any) { this.branchId = branchId; - /** @type {string} */ this.noteId = noteId; - /** @type {string} */ this.parentNoteId = parentNoteId; - /** @type {string|null} */ this.prefix = prefix; - /** @type {int} */ this.notePosition = notePosition; - /** @type {boolean} */ this.isExpanded = !!isExpanded; - /** @type {string} */ this.utcDateModified = utcDateModified; return this; @@ -138,12 +140,11 @@ class BBranch extends AbstractBeccaEntity { /** * Delete a branch. If this is a last note's branch, delete the note as well. * - * @param {string} [deleteId] - optional delete identified - * @param {TaskContext} [taskContext] + * @param deleteId - optional delete identified * - * @returns {boolean} - true if note has been deleted, false otherwise + * @returns true if note has been deleted, false otherwise */ - deleteBranch(deleteId, taskContext) { + deleteBranch(deleteId: string, taskContext: TaskContext): boolean { if (!deleteId) { deleteId = utils.randomString(10); } @@ -261,7 +262,7 @@ class BBranch extends AbstractBeccaEntity { }; } - createClone(parentNoteId, notePosition) { + createClone(parentNoteId: string, notePosition: number) { const existingBranch = this.becca.getBranchFromChildAndParent(this.noteId, parentNoteId); if (existingBranch) { @@ -279,4 +280,4 @@ class BBranch extends AbstractBeccaEntity { } } -module.exports = BBranch; +export = BBranch; diff --git a/src/becca/entities/rows.ts b/src/becca/entities/rows.ts index 98bb0ec8a..db51542e0 100644 --- a/src/becca/entities/rows.ts +++ b/src/becca/entities/rows.ts @@ -72,4 +72,14 @@ export interface AttributeRow { value: string; isInheritable: boolean; utcDateModified: string; +} + +export interface BranchRow { + branchId?: string; + noteId: string; + parentNoteId: string; + prefix: string | null; + notePosition: number; + isExpanded: boolean; + utcDateModified?: string; } \ No newline at end of file diff --git a/src/services/task_context.js b/src/services/task_context.ts similarity index 72% rename from src/services/task_context.js rename to src/services/task_context.ts index 58530ffec..2b1272bb5 100644 --- a/src/services/task_context.js +++ b/src/services/task_context.ts @@ -1,12 +1,20 @@ "use strict"; -const ws = require('./ws.js'); +import ws = require('./ws.js'); // taskId => TaskContext -const taskContexts = {}; +const taskContexts: Record = {}; class TaskContext { - constructor(taskId, taskType = null, data = {}) { + + private taskId: string; + private taskType: string | null; + private data: {} | null; + private noteDeletionHandlerTriggered: boolean; + private progressCount: number; + private lastSentCountTs: number; + + constructor(taskId: string, taskType: string | null = null, data: {} | null = {}) { this.taskId = taskId; this.taskType = taskType; this.data = data; @@ -23,8 +31,7 @@ class TaskContext { this.increaseProgressCount(); } - /** @returns {TaskContext} */ - static getInstance(taskId, taskType, data = null) { + static getInstance(taskId: string, taskType: string, data: {} | null = null): TaskContext { if (!taskContexts[taskId]) { taskContexts[taskId] = new TaskContext(taskId, taskType, data); } @@ -42,31 +49,31 @@ class TaskContext { type: 'taskProgressCount', taskId: this.taskId, taskType: this.taskType, - data: this.data, + data: this.data || undefined, progressCount: this.progressCount }); } } - reportError(message) { + reportError(message: string) { ws.sendMessageToAllClients({ type: 'taskError', taskId: this.taskId, taskType: this.taskType, - data: this.data, + data: this.data || undefined, message: message }); } - taskSucceeded(result) { + taskSucceeded(result: string) { ws.sendMessageToAllClients({ type: 'taskSucceeded', taskId: this.taskId, taskType: this.taskType, - data: this.data, + data: this.data || undefined, result: result }); } } -module.exports = TaskContext; +export = TaskContext; diff --git a/src/services/ws.ts b/src/services/ws.ts index 9e76868e4..086bb0d4f 100644 --- a/src/services/ws.ts +++ b/src/services/ws.ts @@ -28,12 +28,18 @@ let lastSyncedPush: number | null = null; interface Message { type: string; - reason?: string; data?: { lastSyncedPush?: number, entityChanges?: any[] }, - lastSyncedPush?: number + lastSyncedPush?: number, + + progressCount?: number; + taskId?: string; + taskType?: string | null; + message?: string; + reason?: string; + result?: string; } type SessionParser = (req: IncomingMessage, params: {}, cb: () => void) => void; @@ -252,7 +258,7 @@ function setLastSyncedPush(entityChangeId: number) { lastSyncedPush = entityChangeId; } -module.exports = { +export = { init, sendMessageToAllClients, syncPushInProgress, From f9ba8ca87d7a9e6e172602b12d116b72a41c2761 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 17 Feb 2024 10:02:50 +0200 Subject: [PATCH 30/49] server-ts: Fix errors in abstract_becca_entity --- src/becca/entities/abstract_becca_entity.ts | 100 +++++++++++++------- src/becca/entities/battribute.ts | 1 - src/becca/entities/betapi_token.ts | 2 - src/becca/entities/boption.ts | 1 - src/becca/entities/brevision.ts | 2 - src/services/blob-interface.ts | 2 +- src/services/entity_changes_interface.ts | 2 +- src/services/utils.ts | 2 +- 8 files changed, 69 insertions(+), 43 deletions(-) diff --git a/src/becca/entities/abstract_becca_entity.ts b/src/becca/entities/abstract_becca_entity.ts index 0f9769fb6..88d3e753e 100644 --- a/src/becca/entities/abstract_becca_entity.ts +++ b/src/becca/entities/abstract_becca_entity.ts @@ -13,16 +13,35 @@ import Becca = require('../becca-interface'); let becca: Becca | null = null; +interface ContentOpts { + forceSave?: boolean; + forceFrontendReload?: boolean; +} + +interface ConstructorData> { + primaryKeyName: string; + entityName: string; + hashedProperties: (keyof T)[]; +} + /** * Base class for all backend entities. */ -abstract class AbstractBeccaEntity { +abstract class AbstractBeccaEntity> { + protected utcDateCreated?: string; protected utcDateModified?: string; + protected dateModified?: string; + protected isProtected?: boolean; + protected isDeleted?: boolean; + protected isSynced?: boolean; + + protected blobId?: string; protected beforeSaving() { - if (!this[this.constructor.primaryKeyName]) { - this[this.constructor.primaryKeyName] = utils.newEntityId(); + const constructorData = (this.constructor as unknown as ConstructorData); + if (!(this as any)[constructorData.primaryKeyName]) { + (this as any)[constructorData.primaryKeyName] = utils.newEntityId(); } } @@ -39,21 +58,23 @@ abstract class AbstractBeccaEntity { } protected putEntityChange(isDeleted: boolean) { + const constructorData = (this.constructor as unknown as ConstructorData); entityChangesService.putEntityChange({ - entityName: this.constructor.entityName, - entityId: this[this.constructor.primaryKeyName], + entityName: constructorData.entityName, + entityId: (this as any)[constructorData.primaryKeyName], hash: this.generateHash(isDeleted), isErased: false, utcDateChanged: this.getUtcDateChanged(), - isSynced: this.constructor.entityName !== 'options' || !!this.isSynced + isSynced: constructorData.entityName !== 'options' || !!this.isSynced }); } protected generateHash(isDeleted: boolean): string { + const constructorData = (this.constructor as unknown as ConstructorData); let contentToHash = ""; - for (const propertyName of this.constructor.hashedProperties) { - contentToHash += `|${this[propertyName]}`; + for (const propertyName of constructorData.hashedProperties) { + contentToHash += `|${(this as any)[propertyName]}`; } if (isDeleted) { @@ -67,18 +88,21 @@ abstract class AbstractBeccaEntity { return this.getPojo(); } + abstract hasStringContent(): boolean; + abstract getPojo(): {}; /** * Saves entity - executes SQL, but doesn't commit the transaction on its own */ - save(opts = {}): this { - const entityName = this.constructor.entityName; - const primaryKeyName = this.constructor.primaryKeyName; + save(): this { + const constructorData = (this.constructor as unknown as ConstructorData); + const entityName = constructorData.entityName; + const primaryKeyName = constructorData.primaryKeyName; - const isNewEntity = !this[primaryKeyName]; + const isNewEntity = !(this as any)[primaryKeyName]; - this.beforeSaving(opts); + this.beforeSaving(); const pojo = this.getPojoToSave(); @@ -108,13 +132,14 @@ abstract class AbstractBeccaEntity { return this; } - protected _setContent(content, opts = {}) { + protected _setContent(content: string | Buffer, opts: ContentOpts = {}) { // client code asks to save entity even if blobId didn't change (something else was changed) opts.forceSave = !!opts.forceSave; opts.forceFrontendReload = !!opts.forceFrontendReload; if (content === null || content === undefined) { - throw new Error(`Cannot set null content to ${this.constructor.primaryKeyName} '${this[this.constructor.primaryKeyName]}'`); + const constructorData = (this.constructor as unknown as ConstructorData); + throw new Error(`Cannot set null content to ${constructorData.primaryKeyName} '${(this as any)[constructorData.primaryKeyName]}'`); } if (this.hasStringContent()) { @@ -123,32 +148,36 @@ abstract class AbstractBeccaEntity { content = Buffer.isBuffer(content) ? content : Buffer.from(content); } - const unencryptedContentForHashCalculation = this.#getUnencryptedContentForHashCalculation(content); + const unencryptedContentForHashCalculation = this.getUnencryptedContentForHashCalculation(content); if (this.isProtected) { if (protectedSessionService.isProtectedSessionAvailable()) { - content = protectedSessionService.encrypt(content); + const encryptedContent = protectedSessionService.encrypt(content); + if (!encryptedContent) { + throw new Error(`Unable to encrypt the content of the entity.`); + } + content = encryptedContent; } else { throw new Error(`Cannot update content of blob since protected session is not available.`); } } sql.transactional(() => { - const newBlobId = this.#saveBlob(content, unencryptedContentForHashCalculation, opts); + const newBlobId = this.saveBlob(content, unencryptedContentForHashCalculation, opts); const oldBlobId = this.blobId; if (newBlobId !== oldBlobId || opts.forceSave) { this.blobId = newBlobId; this.save(); - if (newBlobId !== oldBlobId) { - this.#deleteBlobIfNotUsed(oldBlobId); + if (oldBlobId && newBlobId !== oldBlobId) { + this.deleteBlobIfNotUsed(oldBlobId); } } }); } - #deleteBlobIfNotUsed(oldBlobId) { + private deleteBlobIfNotUsed(oldBlobId: string) { if (sql.getValue("SELECT 1 FROM notes WHERE blobId = ? LIMIT 1", [oldBlobId])) { return; } @@ -167,7 +196,7 @@ abstract class AbstractBeccaEntity { sql.execute("DELETE FROM entity_changes WHERE entityName = 'blobs' AND entityId = ?", [oldBlobId]); } - #getUnencryptedContentForHashCalculation(unencryptedContent) { + private getUnencryptedContentForHashCalculation(unencryptedContent: Buffer | string) { if (this.isProtected) { // a "random" prefix makes sure that the calculated hash/blobId is different for a decrypted/encrypted content const encryptedPrefixSuffix = "t$[nvQg7q)&_ENCRYPTED_?M:Bf&j3jr_"; @@ -179,7 +208,7 @@ abstract class AbstractBeccaEntity { } } - #saveBlob(content, unencryptedContentForHashCalculation, opts = {}) { + private saveBlob(content: string | Buffer, unencryptedContentForHashCalculation: string | Buffer, opts: ContentOpts = {}) { /* * We're using the unencrypted blob for the hash calculation, because otherwise the random IV would * cause every content blob to be unique which would balloon the database size (esp. with revisioning). @@ -226,14 +255,15 @@ abstract class AbstractBeccaEntity { return newBlobId; } - protected _getContent(): string | Buffer { - const row = sql.getRow(`SELECT content FROM blobs WHERE blobId = ?`, [this.blobId]); + protected _getContent(): string | Buffer { + const row = sql.getRow<{ content: string | Buffer }>(`SELECT content FROM blobs WHERE blobId = ?`, [this.blobId]); if (!row) { - throw new Error(`Cannot find content for ${this.constructor.primaryKeyName} '${this[this.constructor.primaryKeyName]}', blobId '${this.blobId}'`); + const constructorData = (this.constructor as unknown as ConstructorData); + throw new Error(`Cannot find content for ${constructorData.primaryKeyName} '${(this as any)[constructorData.primaryKeyName]}', blobId '${this.blobId}'`); } - return blobService.processContent(row.content, this.isProtected, this.hasStringContent()); + return blobService.processContent(row.content, this.isProtected || false, this.hasStringContent()); } /** @@ -242,19 +272,20 @@ abstract class AbstractBeccaEntity { * This is a low-level method, for notes and branches use `note.deleteNote()` and 'branch.deleteBranch()` instead. */ markAsDeleted(deleteId = null) { - const entityId = this[this.constructor.primaryKeyName]; - const entityName = this.constructor.entityName; + const constructorData = (this.constructor as unknown as ConstructorData); + const entityId = (this as any)[constructorData.primaryKeyName]; + const entityName = constructorData.entityName; this.utcDateModified = dateUtils.utcNowDateTime(); sql.execute(`UPDATE ${entityName} SET isDeleted = 1, deleteId = ?, utcDateModified = ? - WHERE ${this.constructor.primaryKeyName} = ?`, + WHERE ${constructorData.primaryKeyName} = ?`, [deleteId, this.utcDateModified, entityId]); if (this.dateModified) { this.dateModified = dateUtils.localNowDateTime(); - sql.execute(`UPDATE ${entityName} SET dateModified = ? WHERE ${this.constructor.primaryKeyName} = ?`, + sql.execute(`UPDATE ${entityName} SET dateModified = ? WHERE ${constructorData.primaryKeyName} = ?`, [this.dateModified, entityId]); } @@ -266,13 +297,14 @@ abstract class AbstractBeccaEntity { } markAsDeletedSimple() { - const entityId = this[this.constructor.primaryKeyName]; - const entityName = this.constructor.entityName; + const constructorData = (this.constructor as unknown as ConstructorData); + const entityId = (this as any)[constructorData.primaryKeyName]; + const entityName = constructorData.entityName; this.utcDateModified = dateUtils.utcNowDateTime(); sql.execute(`UPDATE ${entityName} SET isDeleted = 1, utcDateModified = ? - WHERE ${this.constructor.primaryKeyName} = ?`, + WHERE ${constructorData.primaryKeyName} = ?`, [this.utcDateModified, entityId]); log.info(`Marking ${entityName} ${entityId} as deleted`); diff --git a/src/becca/entities/battribute.ts b/src/becca/entities/battribute.ts index 71d575193..ceb3edf92 100644 --- a/src/becca/entities/battribute.ts +++ b/src/becca/entities/battribute.ts @@ -25,7 +25,6 @@ class BAttribute extends AbstractBeccaEntity { position!: number; value!: string; isInheritable!: boolean; - utcDateModified!: string; constructor(row: AttributeRow) { super(); diff --git a/src/becca/entities/betapi_token.ts b/src/becca/entities/betapi_token.ts index 4809dc265..8c0227482 100644 --- a/src/becca/entities/betapi_token.ts +++ b/src/becca/entities/betapi_token.ts @@ -24,8 +24,6 @@ class BEtapiToken extends AbstractBeccaEntity { etapiTokenId!: string; name!: string; tokenHash!: string; - utcDateCreated!: string; - utcDateModified!: string; isDeleted!: boolean; constructor(row: EtapiTokenRow) { diff --git a/src/becca/entities/boption.ts b/src/becca/entities/boption.ts index ebfd951d1..871e44157 100644 --- a/src/becca/entities/boption.ts +++ b/src/becca/entities/boption.ts @@ -15,7 +15,6 @@ class BOption extends AbstractBeccaEntity { name!: string; value!: string; isSynced!: boolean; - utcDateModified!: string; constructor(row: OptionRow) { super(); diff --git a/src/becca/entities/brevision.ts b/src/becca/entities/brevision.ts index fb590ddbb..df3447aed 100644 --- a/src/becca/entities/brevision.ts +++ b/src/becca/entities/brevision.ts @@ -21,8 +21,6 @@ interface GetByIdOpts { /** * Revision represents a snapshot of note's title and content at some point in the past. * It's used for seamless note versioning. - * - * @extends AbstractBeccaEntity */ class BRevision extends AbstractBeccaEntity { static get entityName() { return "revisions"; } diff --git a/src/services/blob-interface.ts b/src/services/blob-interface.ts index 5905e9d99..8bfcf1322 100644 --- a/src/services/blob-interface.ts +++ b/src/services/blob-interface.ts @@ -1,5 +1,5 @@ export interface Blob { blobId: string; - content: Buffer; + content: string | Buffer; utcDateModified: string; } \ No newline at end of file diff --git a/src/services/entity_changes_interface.ts b/src/services/entity_changes_interface.ts index 2252f27fb..f0a583e95 100644 --- a/src/services/entity_changes_interface.ts +++ b/src/services/entity_changes_interface.ts @@ -6,7 +6,7 @@ export interface EntityChange { entity?: any; positions?: Record; hash: string; - utcDateChanged: string; + utcDateChanged?: string; isSynced: boolean | 1 | 0; isErased: boolean | 1 | 0; componentId?: string | null; diff --git a/src/services/utils.ts b/src/services/utils.ts index 9a3397f85..f16465af8 100644 --- a/src/services/utils.ts +++ b/src/services/utils.ts @@ -24,7 +24,7 @@ function md5(content: crypto.BinaryLike) { return crypto.createHash('md5').update(content).digest('hex'); } -function hashedBlobId(content: string) { +function hashedBlobId(content: string | Buffer) { if (content === null || content === undefined) { content = ""; } From 9aec3390dd0b338be4fe19f94b0fec1458c039f1 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 17 Feb 2024 10:56:27 +0200 Subject: [PATCH 31/49] server-ts: Fix most errors in bnote --- src/becca/entities/abstract_becca_entity.ts | 4 +- src/becca/entities/battachment.ts | 15 +- src/becca/entities/battribute.ts | 4 +- src/becca/entities/bbranch.ts | 6 +- src/becca/entities/betapi_token.ts | 8 +- src/becca/entities/bnote.ts | 633 ++++++++++---------- src/becca/entities/brevision.ts | 8 +- src/becca/entities/rows.ts | 37 +- src/services/task_context.ts | 4 +- src/services/utils.ts | 2 +- 10 files changed, 359 insertions(+), 362 deletions(-) diff --git a/src/becca/entities/abstract_becca_entity.ts b/src/becca/entities/abstract_becca_entity.ts index 88d3e753e..50e76a212 100644 --- a/src/becca/entities/abstract_becca_entity.ts +++ b/src/becca/entities/abstract_becca_entity.ts @@ -31,9 +31,9 @@ abstract class AbstractBeccaEntity> { protected utcDateCreated?: string; protected utcDateModified?: string; + protected dateCreated?: string; protected dateModified?: string; protected isProtected?: boolean; - protected isDeleted?: boolean; protected isSynced?: boolean; protected blobId?: string; @@ -92,6 +92,8 @@ abstract class AbstractBeccaEntity> { abstract getPojo(): {}; + abstract get isDeleted(): boolean; + /** * Saves entity - executes SQL, but doesn't commit the transaction on its own */ diff --git a/src/becca/entities/battachment.ts b/src/becca/entities/battachment.ts index 7b6c3f657..728ee5e14 100644 --- a/src/becca/entities/battachment.ts +++ b/src/becca/entities/battachment.ts @@ -7,25 +7,28 @@ import sql = require('../../services/sql'); import protectedSessionService = require('../../services/protected_session'); import log = require('../../services/log'); import { AttachmentRow } from './rows'; +import BNote = require('./bnote'); +import BBranch = require('./bbranch'); const attachmentRoleToNoteTypeMapping = { 'image': 'image' }; interface ContentOpts { + // FIXME: Found in bnote.ts, to check if it's actually used and not a typo. + forceSave?: boolean; + /** will also save this BAttachment entity */ - forceFullSave: boolean; + forceFullSave?: boolean; /** override frontend heuristics on when to reload, instruct to reload */ - forceFrontendReload: boolean; + forceFrontendReload?: boolean; } /** * Attachment represent data related/attached to the note. Conceptually similar to attributes, but intended for * larger amounts of data and generally not accessible to the user. - * - * @extends AbstractBeccaEntity */ -class BAttachment extends AbstractBeccaEntity { +class BAttachment extends AbstractBeccaEntity { static get entityName() { return "attachments"; } static get primaryKeyName() { return "attachmentId"; } static get hashedProperties() { return ["attachmentId", "ownerId", "role", "mime", "title", "blobId", "utcDateScheduledForErasureSince"]; } @@ -39,7 +42,7 @@ class BAttachment extends AbstractBeccaEntity { title: string; type?: keyof typeof attachmentRoleToNoteTypeMapping; position?: number; - blobId: string; + blobId?: string; isProtected?: boolean; dateModified?: string; utcDateScheduledForErasureSince?: string; diff --git a/src/becca/entities/battribute.ts b/src/becca/entities/battribute.ts index ceb3edf92..5afea9fdb 100644 --- a/src/becca/entities/battribute.ts +++ b/src/becca/entities/battribute.ts @@ -10,10 +10,8 @@ import { AttributeRow, AttributeType } from './rows.js'; /** * Attribute is an abstract concept which has two real uses - label (key - value pair) * and relation (representing named relationship between source and target note) - * - * @extends AbstractBeccaEntity */ -class BAttribute extends AbstractBeccaEntity { +class BAttribute extends AbstractBeccaEntity { static get entityName() { return "attributes"; } static get primaryKeyName() { return "attributeId"; } static get hashedProperties() { return ["attributeId", "noteId", "type", "name", "value", "isInheritable"]; } diff --git a/src/becca/entities/bbranch.ts b/src/becca/entities/bbranch.ts index f7ed4cffc..8892166c4 100644 --- a/src/becca/entities/bbranch.ts +++ b/src/becca/entities/bbranch.ts @@ -15,10 +15,8 @@ import { BranchRow } from './rows.js'; * * Note that you should not rely on the branch's identity, since it can change easily with a note's move. * Always check noteId instead. - * - * @extends AbstractBeccaEntity */ -class BBranch extends AbstractBeccaEntity { +class BBranch extends AbstractBeccaEntity { static get entityName() { return "branches"; } static get primaryKeyName() { return "branchId"; } // notePosition is not part of hash because it would produce a lot of updates in case of reordering @@ -27,7 +25,7 @@ class BBranch extends AbstractBeccaEntity { branchId?: string; noteId!: string; parentNoteId!: string; - prefix!: string; + prefix!: string | null; notePosition!: number; isExpanded!: boolean; utcDateModified?: string; diff --git a/src/becca/entities/betapi_token.ts b/src/becca/entities/betapi_token.ts index 8c0227482..e4711c5fa 100644 --- a/src/becca/entities/betapi_token.ts +++ b/src/becca/entities/betapi_token.ts @@ -2,8 +2,8 @@ import { EtapiTokenRow } from "./rows"; -const dateUtils = require('../../services/date_utils'); -const AbstractBeccaEntity = require('./abstract_becca_entity.js'); +import dateUtils = require('../../services/date_utils'); +import AbstractBeccaEntity = require('./abstract_becca_entity'); /** * EtapiToken is an entity representing token used to authenticate against Trilium REST API from client applications. @@ -13,10 +13,8 @@ const AbstractBeccaEntity = require('./abstract_becca_entity.js'); * * The format user is presented with is "_". This is also called "authToken" to distinguish it * from tokenHash and token. - * - * @extends AbstractBeccaEntity */ -class BEtapiToken extends AbstractBeccaEntity { +class BEtapiToken extends AbstractBeccaEntity { static get entityName() { return "etapi_tokens"; } static get primaryKeyName() { return "etapiTokenId"; } static get hashedProperties() { return ["etapiTokenId", "name", "tokenHash", "utcDateCreated", "utcDateModified", "isDeleted"]; } diff --git a/src/becca/entities/bnote.ts b/src/becca/entities/bnote.ts index f72a83916..6c7ed6895 100644 --- a/src/becca/entities/bnote.ts +++ b/src/becca/entities/bnote.ts @@ -6,43 +6,86 @@ import sql = require('../../services/sql'); import utils = require('../../services/utils'); import dateUtils = require('../../services/date_utils'); import AbstractBeccaEntity = require('./abstract_becca_entity.js'); -import BRevision = require('./brevision.js'); -import BAttachment = require('./battachment.ts'); -import TaskContext = require('../../services/task_context.js'); +import BRevision = require('./brevision'); +import BAttachment = require('./battachment'); +import TaskContext = require('../../services/task_context'); import dayjs = require("dayjs"); import utc = require('dayjs/plugin/utc'); -import eventService = require('../../services/events.ts'); +import eventService = require('../../services/events'); +import { AttachmentRow, NoteRow, NoteType, RevisionRow } from './rows'; +import BBranch = require('./bbranch'); +import BAttribute = require('./battribute'); dayjs.extend(utc); const LABEL = 'label'; const RELATION = 'relation'; -/** - * There are many different Note types, some of which are entirely opaque to the - * end user. Those types should be used only for checking against, they are - * not for direct use. - * @typedef {"file" | "image" | "search" | "noteMap" | "launcher" | "doc" | "contentWidget" | "text" | "relationMap" | "render" | "canvas" | "mermaid" | "book" | "webView" | "code"} NoteType - */ +interface NotePathRecord { + isArchived: boolean; + isInHoistedSubTree: boolean; + notePath: string[]; + isHidden: boolean; +} -/** - * @typedef {Object} NotePathRecord - * @property {boolean} isArchived - * @property {boolean} isInHoistedSubTree - * @property {Array} notePath - * @property {boolean} isHidden - */ +interface ContentOpts { + /** will also save this BNote entity */ + forceSave?: boolean; + /** override frontend heuristics on when to reload, instruct to reload */ + forceFrontendReload?: boolean; +} + +interface AttachmentOpts { + includeContentLength?: boolean; +} + +interface Relationship { + parentNoteId: string; + childNoteId: string +} + +interface ConvertOpts { + /** if true, the action is not triggered by user, but e.g. by migration, and only perfect candidates will be migrated */ + autoConversion?: boolean; +} /** * Trilium's main entity, which can represent text note, image, code note, file attachment etc. - * - * @extends AbstractBeccaEntity */ -class BNote extends AbstractBeccaEntity { +class BNote extends AbstractBeccaEntity { static get entityName() { return "notes"; } static get primaryKeyName() { return "noteId"; } static get hashedProperties() { return ["noteId", "title", "isProtected", "type", "mime", "blobId"]; } - constructor(row) { + noteId!: string; + title!: string; + type!: NoteType; + mime!: string; + /** set during the deletion operation, before it is completed (removed from becca completely). */ + isBeingDeleted!: boolean; + isDecrypted!: boolean; + + private __flatTextCache!: string | null; + + private parentBranches!: BBranch[]; + private parents!: BNote[]; + private children!: BNote[]; + private ownedAttributes!: BAttribute[]; + private __attributeCache!: BAttribute[] | null; + private __inheritableAttributeCache!: BAttribute[] | null; + private targetRelations!: BAttribute[]; + private __ancestorCache!: BNote[] | null; + + // following attributes are filled during searching in the database + /** size of the content in bytes */ + private contentSize!: number | null; + /** size of the note content, attachment contents in bytes */ + private contentAndAttachmentsSize!: number | null; + /** size of the note content, attachment contents and revision contents in bytes */ + private contentAndAttachmentsAndRevisionsSize!: number | null; + /** number of note revisions for this note */ + private revisionCount!: number | null; + + constructor(row: NoteRow) { super(); if (!row) { @@ -53,7 +96,7 @@ class BNote extends AbstractBeccaEntity { this.init(); } - updateFromRow(row) { + updateFromRow(row: NoteRow) { this.update([ row.noteId, row.title, @@ -68,104 +111,47 @@ class BNote extends AbstractBeccaEntity { ]); } - update([noteId, title, type, mime, isProtected, blobId, dateCreated, dateModified, utcDateCreated, utcDateModified]) { + update([noteId, title, type, mime, isProtected, blobId, dateCreated, dateModified, utcDateCreated, utcDateModified]: any) { // ------ Database persisted attributes ------ - /** @type {string} */ this.noteId = noteId; - /** @type {string} */ this.title = title; - /** @type {NoteType} */ this.type = type; - /** @type {string} */ this.mime = mime; - /** @type {boolean} */ this.isProtected = !!isProtected; - /** @type {string} */ this.blobId = blobId; - /** @type {string} */ this.dateCreated = dateCreated || dateUtils.localNowDateTime(); - /** @type {string} */ this.dateModified = dateModified; - /** @type {string} */ this.utcDateCreated = utcDateCreated || dateUtils.utcNowDateTime(); - /** @type {string} */ this.utcDateModified = utcDateModified; - /** - * set during the deletion operation, before it is completed (removed from becca completely) - * @type {boolean} - */ this.isBeingDeleted = false; // ------ Derived attributes ------ - /** @type {boolean} */ this.isDecrypted = !this.noteId || !this.isProtected; this.decrypt(); - /** @type {string|null} */ this.__flatTextCache = null; return this; } init() { - /** @type {BBranch[]} - * @private */ this.parentBranches = []; - /** @type {BNote[]} - * @private */ this.parents = []; - /** @type {BNote[]} - * @private */ this.children = []; - /** @type {BAttribute[]} - * @private */ this.ownedAttributes = []; - - /** @type {BAttribute[]|null} - * @private */ this.__attributeCache = null; - /** @type {BAttribute[]|null} - * @private */ this.__inheritableAttributeCache = null; - - /** @type {BAttribute[]} - * @private */ this.targetRelations = []; this.becca.addNote(this.noteId, this); - - /** @type {BNote[]|null} - * @private */ this.__ancestorCache = null; - // following attributes are filled during searching in the database - - /** - * size of the content in bytes - * @type {int|null} - * @private - */ this.contentSize = null; - /** - * size of the note content, attachment contents in bytes - * @type {int|null} - * @private - */ this.contentAndAttachmentsSize = null; - /** - * size of the note content, attachment contents and revision contents in bytes - * @type {int|null} - * @private - */ this.contentAndAttachmentsAndRevisionsSize = null; - /** - * number of note revisions for this note - * @type {int|null} - * @private - */ this.revisionCount = null; } @@ -239,7 +225,7 @@ class BNote extends AbstractBeccaEntity { * @returns {*} * @throws Error in case of invalid JSON */ getJsonContent() { - const content = this.getContent(); + const content = this.getContent() as string; if (!content || !content.trim()) { return null; @@ -258,19 +244,13 @@ class BNote extends AbstractBeccaEntity { } } - /** - * @param content - * @param {object} [opts] - * @param {object} [opts.forceSave=false] - will also save this BNote entity - * @param {object} [opts.forceFrontendReload=false] - override frontend heuristics on when to reload, instruct to reload - */ - setContent(content, opts) { + setContent(content: string, opts: ContentOpts = {}) { this._setContent(content, opts); eventService.emit(eventService.NOTE_CONTENT_CHANGE, { entity: this }); } - setJsonContent(content) { + setJsonContent(content: {}) { this.setContent(JSON.stringify(content, null, '\t')); } @@ -351,14 +331,18 @@ class BNote extends AbstractBeccaEntity { * Beware that the method must not create a copy of the array, but actually returns its internal array * (for performance reasons) * - * @param {string} [type] - (optional) attribute type to filter - * @param {string} [name] - (optional) attribute name to filter - * @returns {BAttribute[]} all note's attributes, including inherited ones + * @param type - (optional) attribute type to filter + * @param name - (optional) attribute name to filter + * @returns all note's attributes, including inherited ones */ - getAttributes(type, name) { + getAttributes(type?: string, name?: string): BAttribute[] { this.__validateTypeName(type, name); this.__ensureAttributeCacheIsAvailable(); + if (!this.__attributeCache) { + throw new Error("Attribute cache not available."); + } + if (type && name) { return this.__attributeCache.filter(attr => attr.name === name && attr.type === type); } @@ -373,15 +357,13 @@ class BNote extends AbstractBeccaEntity { } } - /** @private */ - __ensureAttributeCacheIsAvailable() { + private __ensureAttributeCacheIsAvailable() { if (!this.__attributeCache) { this.__getAttributes([]); } } - /** @private */ - __getAttributes(path) { + private __getAttributes(path: string[]) { if (path.includes(this.noteId)) { return []; } @@ -437,11 +419,7 @@ class BNote extends AbstractBeccaEntity { return this.__attributeCache; } - /** - * @private - * @returns {BAttribute[]} - */ - __getInheritableAttributes(path) { + private __getInheritableAttributes(path: string[]): BAttribute[] { if (path.includes(this.noteId)) { return []; } @@ -450,10 +428,10 @@ class BNote extends AbstractBeccaEntity { this.__getAttributes(path); // will refresh also this.__inheritableAttributeCache } - return this.__inheritableAttributeCache; + return this.__inheritableAttributeCache || []; } - __validateTypeName(type, name) { + __validateTypeName(type?: string | null, name?: string | null) { if (type && type !== 'label' && type !== 'relation') { throw new Error(`Unrecognized attribute type '${type}'. Only 'label' and 'relation' are possible values.`); } @@ -466,13 +444,7 @@ class BNote extends AbstractBeccaEntity { } } - /** - * @param type - * @param name - * @param [value] - * @returns {boolean} - */ - hasAttribute(type, name, value = null) { + hasAttribute(type: string, name: string, value: string | null = null): boolean { return !!this.getAttributes().find(attr => attr.name === name && (value === undefined || value === null || attr.value === value) @@ -480,7 +452,7 @@ class BNote extends AbstractBeccaEntity { ); } - getAttributeCaseInsensitive(type, name, value) { + getAttributeCaseInsensitive(type: string, name: string, value: string | null) { name = name.toLowerCase(); value = value ? value.toLowerCase() : null; @@ -490,24 +462,26 @@ class BNote extends AbstractBeccaEntity { && attr.type === type); } - getRelationTarget(name) { + getRelationTarget(name: string) { const relation = this.getAttributes().find(attr => attr.name === name && attr.type === 'relation'); return relation ? relation.targetNote : null; } /** - * @param {string} name - label name - * @param {string} [value] - label value - * @returns {boolean} true if label exists (including inherited) + * @param name - label name + * @param value - label value + * @returns true if label exists (including inherited) */ - hasLabel(name, value) { return this.hasAttribute(LABEL, name, value); } + hasLabel(name: string, value?: string): boolean { + return this.hasAttribute(LABEL, name, value); + } /** - * @param {string} name - label name - * @returns {boolean} true if label exists (including inherited) and does not have "false" value. + * @param name - label name + * @returns true if label exists (including inherited) and does not have "false" value. */ - isLabelTruthy(name) { + isLabelTruthy(name: string): boolean { const label = this.getLabel(name); if (!label) { @@ -518,163 +492,185 @@ class BNote extends AbstractBeccaEntity { } /** - * @param {string} name - label name - * @param {string} [value] - label value - * @returns {boolean} true if label exists (excluding inherited) + * @param name - label name + * @param value - label value + * @returns true if label exists (excluding inherited) */ - hasOwnedLabel(name, value) { return this.hasOwnedAttribute(LABEL, name, value); } + hasOwnedLabel(name: string, value?: string): boolean { + return this.hasOwnedAttribute(LABEL, name, value); + } /** - * @param {string} name - relation name - * @param {string} [value] - relation value - * @returns {boolean} true if relation exists (including inherited) + * @param name - relation name + * @param value - relation value + * @returns true if relation exists (including inherited) */ - hasRelation(name, value) { return this.hasAttribute(RELATION, name, value); } + hasRelation(name: string, value?: string): boolean { + return this.hasAttribute(RELATION, name, value); + } /** - * @param {string} name - relation name - * @param {string} [value] - relation value - * @returns {boolean} true if relation exists (excluding inherited) + * @param name - relation name + * @param value - relation value + * @returns true if relation exists (excluding inherited) */ - hasOwnedRelation(name, value) { return this.hasOwnedAttribute(RELATION, name, value); } + hasOwnedRelation(name: string, value?: string): boolean { + return this.hasOwnedAttribute(RELATION, name, value); + } /** * @param {string} name - label name * @returns {BAttribute|null} label if it exists, null otherwise */ - getLabel(name) { return this.getAttribute(LABEL, name); } + getLabel(name: string): BAttribute | null { + return this.getAttribute(LABEL, name); + } /** - * @param {string} name - label name - * @returns {BAttribute|null} label if it exists, null otherwise + * @param name - label name + * @returns label if it exists, null otherwise */ - getOwnedLabel(name) { return this.getOwnedAttribute(LABEL, name); } + getOwnedLabel(name: string): BAttribute | null { + return this.getOwnedAttribute(LABEL, name); + } /** - * @param {string} name - relation name - * @returns {BAttribute|null} relation if it exists, null otherwise + * @param name - relation name + * @returns relation if it exists, null otherwise */ - getRelation(name) { return this.getAttribute(RELATION, name); } + getRelation(name: string): BAttribute | null { + return this.getAttribute(RELATION, name); + } /** - * @param {string} name - relation name - * @returns {BAttribute|null} relation if it exists, null otherwise + * @param name - relation name + * @returns relation if it exists, null otherwise */ - getOwnedRelation(name) { return this.getOwnedAttribute(RELATION, name); } + getOwnedRelation(name: string): BAttribute | null { + return this.getOwnedAttribute(RELATION, name); + } /** - * @param {string} name - label name - * @returns {string|null} label value if label exists, null otherwise + * @param name - label name + * @returns label value if label exists, null otherwise */ - getLabelValue(name) { return this.getAttributeValue(LABEL, name); } + getLabelValue(name: string): string | null { + return this.getAttributeValue(LABEL, name); + } /** - * @param {string} name - label name - * @returns {string|null} label value if label exists, null otherwise + * @param name - label name + * @returns label value if label exists, null otherwise */ - getOwnedLabelValue(name) { return this.getOwnedAttributeValue(LABEL, name); } + getOwnedLabelValue(name: string): string | null { + return this.getOwnedAttributeValue(LABEL, name); + } /** - * @param {string} name - relation name - * @returns {string|null} relation value if relation exists, null otherwise + * @param name - relation name + * @returns relation value if relation exists, null otherwise */ - getRelationValue(name) { return this.getAttributeValue(RELATION, name); } + getRelationValue(name: string): string | null { + return this.getAttributeValue(RELATION, name); + } /** - * @param {string} name - relation name - * @returns {string|null} relation value if relation exists, null otherwise + * @param name - relation name + * @returns relation value if relation exists, null otherwise */ - getOwnedRelationValue(name) { return this.getOwnedAttributeValue(RELATION, name); } + getOwnedRelationValue(name: string): string | null { + return this.getOwnedAttributeValue(RELATION, name); + } /** - * @param {string} type - attribute type (label, relation, etc.) - * @param {string} name - attribute name - * @param {string} [value] - attribute value - * @returns {boolean} true if note has an attribute with given type and name (excluding inherited) + * @param attribute type (label, relation, etc.) + * @param name - attribute name + * @param value - attribute value + * @returns true if note has an attribute with given type and name (excluding inherited) */ - hasOwnedAttribute(type, name, value) { + hasOwnedAttribute(type: string, name: string, value?: string): boolean { return !!this.getOwnedAttribute(type, name, value); } /** - * @param {string} type - attribute type (label, relation, etc.) - * @param {string} name - attribute name - * @returns {BAttribute} attribute of the given type and name. If there are more such attributes, first is returned. - * Returns null if there's no such attribute belonging to this note. + * @param type - attribute type (label, relation, etc.) + * @param name - attribute name + * @returns attribute of the given type and name. If there are more such attributes, first is returned. + * Returns null if there's no such attribute belonging to this note. */ - getAttribute(type, name) { + getAttribute(type: string, name: string): BAttribute | null { const attributes = this.getAttributes(); - return attributes.find(attr => attr.name === name && attr.type === type); + return attributes.find(attr => attr.name === name && attr.type === type) || null; } /** - * @param {string} type - attribute type (label, relation, etc.) - * @param {string} name - attribute name - * @returns {string|null} attribute value of given type and name or null if no such attribute exists. + * @param type - attribute type (label, relation, etc.) + * @param name - attribute name + * @returns attribute value of given type and name or null if no such attribute exists. */ - getAttributeValue(type, name) { + getAttributeValue(type: string, name: string): string | null { const attr = this.getAttribute(type, name); return attr ? attr.value : null; } /** - * @param {string} type - attribute type (label, relation, etc.) - * @param {string} name - attribute name - * @returns {string|null} attribute value of given type and name or null if no such attribute exists. + * @param type - attribute type (label, relation, etc.) + * @param name - attribute name + * @returns attribute value of given type and name or null if no such attribute exists. */ - getOwnedAttributeValue(type, name) { + getOwnedAttributeValue(type: string, name: string): string | null { const attr = this.getOwnedAttribute(type, name); return attr ? attr.value : null; } /** - * @param {string} [name] - label name to filter - * @returns {BAttribute[]} all note's labels (attributes with type label), including inherited ones + * @param name - label name to filter + * @returns all note's labels (attributes with type label), including inherited ones */ - getLabels(name) { + getLabels(name?: string): BAttribute[] { return this.getAttributes(LABEL, name); } /** - * @param {string} [name] - label name to filter - * @returns {string[]} all note's label values, including inherited ones + * @param name - label name to filter + * @returns all note's label values, including inherited ones */ - getLabelValues(name) { + getLabelValues(name: string): string[] { return this.getLabels(name).map(l => l.value); } /** - * @param {string} [name] - label name to filter - * @returns {BAttribute[]} all note's labels (attributes with type label), excluding inherited ones + * @param name - label name to filter + * @returns all note's labels (attributes with type label), excluding inherited ones */ - getOwnedLabels(name) { + getOwnedLabels(name: string): BAttribute[] { return this.getOwnedAttributes(LABEL, name); } /** - * @param {string} [name] - label name to filter - * @returns {string[]} all note's label values, excluding inherited ones + * @param name - label name to filter + * @returns all note's label values, excluding inherited ones */ - getOwnedLabelValues(name) { + getOwnedLabelValues(name: string): string[] { return this.getOwnedAttributes(LABEL, name).map(l => l.value); } /** - * @param {string} [name] - relation name to filter - * @returns {BAttribute[]} all note's relations (attributes with type relation), including inherited ones + * @param name - relation name to filter + * @returns all note's relations (attributes with type relation), including inherited ones */ - getRelations(name) { + getRelations(name: string): BAttribute[] { return this.getAttributes(RELATION, name); } /** - * @param {string} [name] - relation name to filter - * @returns {BAttribute[]} all note's relations (attributes with type relation), excluding inherited ones + * @param name - relation name to filter + * @returns all note's relations (attributes with type relation), excluding inherited ones */ - getOwnedRelations(name) { + getOwnedRelations(name: string): BAttribute[] { return this.getOwnedAttributes(RELATION, name); } @@ -682,12 +678,12 @@ class BNote extends AbstractBeccaEntity { * Beware that the method must not create a copy of the array, but actually returns its internal array * (for performance reasons) * - * @param {string|null} [type] - (optional) attribute type to filter - * @param {string|null} [name] - (optional) attribute name to filter - * @param {string|null} [value] - (optional) attribute value to filter + * @param type - (optional) attribute type to filter + * @param name - (optional) attribute name to filter + * @param value - (optional) attribute value to filter * @returns {BAttribute[]} note's "owned" attributes - excluding inherited ones */ - getOwnedAttributes(type = null, name = null, value = null) { + getOwnedAttributes(type: string | null = null, name: string | null = null, value: string | null = null) { this.__validateTypeName(type, name); if (type && name && value !== undefined && value !== null) { @@ -712,7 +708,7 @@ class BNote extends AbstractBeccaEntity { * * This method can be significantly faster than the getAttribute() */ - getOwnedAttribute(type, name, value = null) { + getOwnedAttribute(type: string, name: string, value: string | null = null) { const attrs = this.getOwnedAttributes(type, name, value); return attrs.length > 0 ? attrs[0] : null; @@ -824,7 +820,7 @@ class BNote extends AbstractBeccaEntity { this.__ancestorCache = null; } - invalidateSubTree(path = []) { + invalidateSubTree(path: string[] = []) { if (path.includes(this.noteId)) { return; } @@ -864,11 +860,10 @@ class BNote extends AbstractBeccaEntity { return !!this.targetRelations.find(rel => rel.name === 'template' || rel.name === 'inherit'); } - /** @returns {BNote[]} */ - getSubtreeNotesIncludingTemplated() { - const set = new Set(); + getSubtreeNotesIncludingTemplated(): BNote[] { + const set = new Set(); - function inner(note) { + function inner(note: BNote) { // _hidden is not counted as subtree for the purpose of inheritance if (set.has(note) || note.noteId === '_hidden') { return; @@ -896,8 +891,7 @@ class BNote extends AbstractBeccaEntity { return Array.from(set); } - /** @returns {BNote[]} */ - getSearchResultNotes() { + getSearchResultNotes(): BNote[] { if (this.type !== 'search') { return []; } @@ -911,31 +905,31 @@ class BNote extends AbstractBeccaEntity { .map(resultNoteId => becca.notes[resultNoteId]) .filter(note => !!note); } - catch (e) { + catch (e: any) { log.error(`Could not resolve search note ${this.noteId}: ${e.message}`); return []; } } - /** - * @returns {{notes: BNote[], relationships: Array.<{parentNoteId: string, childNoteId: string}>}} - */ - getSubtree({includeArchived = true, includeHidden = false, resolveSearch = false} = {}) { - const noteSet = new Set(); - const relationships = []; // list of tuples parentNoteId -> childNoteId + getSubtree({includeArchived = true, includeHidden = false, resolveSearch = false} = {}): { + notes: BNote[], + relationships: Relationship[] + } { + const noteSet = new Set(); + const relationships: Relationship[] = []; // list of tuples parentNoteId -> childNoteId - function resolveSearchNote(searchNote) { + function resolveSearchNote(searchNote: BNote) { try { for (const resultNote of searchNote.getSearchResultNotes()) { addSubtreeNotesInner(resultNote, searchNote); } } - catch (e) { + catch (e: any) { log.error(`Could not resolve search note ${searchNote?.noteId}: ${e.message}`); } } - function addSubtreeNotesInner(note, parentNote = null) { + function addSubtreeNotesInner(note: BNote, parentNote: BNote | null = null) { if (note.noteId === '_hidden' && !includeHidden) { return; } @@ -1064,13 +1058,11 @@ class BNote extends AbstractBeccaEntity { return this.__ancestorCache; } - /** @returns {string[]} */ - getAncestorNoteIds() { + getAncestorNoteIds(): string[] { return this.getAncestors().map(note => note.noteId); } - /** @returns {boolean} */ - hasAncestor(ancestorNoteId) { + hasAncestor(ancestorNoteId: string): boolean { for (const ancestorNote of this.getAncestors()) { if (ancestorNote.noteId === ancestorNoteId) { return true; @@ -1089,10 +1081,10 @@ class BNote extends AbstractBeccaEntity { return this.targetRelations; } - /** @returns {BNote[]} - returns only notes which are templated, does not include their subtrees - * in effect returns notes which are influenced by note's non-inheritable attributes */ - getInheritingNotes() { - const arr = [this]; + /** @returns returns only notes which are templated, does not include their subtrees + * in effect returns notes which are influenced by note's non-inheritable attributes */ + getInheritingNotes(): BNote[] { + const arr: BNote[] = [this]; for (const targetRelation of this.targetRelations) { if (targetRelation.name === 'template' || targetRelation.name === 'inherit') { @@ -1107,7 +1099,7 @@ class BNote extends AbstractBeccaEntity { return arr; } - getDistanceToAncestor(ancestorNoteId) { + getDistanceToAncestor(ancestorNoteId: string) { if (this.noteId === ancestorNoteId) { return 0; } @@ -1121,14 +1113,13 @@ class BNote extends AbstractBeccaEntity { return minDistance; } - /** @returns {BRevision[]} */ - getRevisions() { - return sql.getRows("SELECT * FROM revisions WHERE noteId = ?", [this.noteId]) + getRevisions(): BRevision[] { + return sql.getRows("SELECT * FROM revisions WHERE noteId = ?", [this.noteId]) .map(row => new BRevision(row)); } /** @returns {BAttachment[]} */ - getAttachments(opts = {}) { + getAttachments(opts: AttachmentOpts = {}) { opts.includeContentLength = !!opts.includeContentLength; // from testing, it looks like calculating length does not make a difference in performance even on large-ish DB // given that we're always fetching attachments only for a specific note, we might just do it always @@ -1141,12 +1132,12 @@ class BNote extends AbstractBeccaEntity { ORDER BY position` : `SELECT * FROM attachments WHERE ownerId = ? AND isDeleted = 0 ORDER BY position`; - return sql.getRows(query, [this.noteId]) + return sql.getRows(query, [this.noteId]) .map(row => new BAttachment(row)); } /** @returns {BAttachment|null} */ - getAttachmentById(attachmentId, opts = {}) { + getAttachmentById(attachmentId: string, opts: AttachmentOpts = {}) { opts.includeContentLength = !!opts.includeContentLength; const query = opts.includeContentLength @@ -1156,13 +1147,12 @@ class BNote extends AbstractBeccaEntity { WHERE ownerId = ? AND attachmentId = ? AND isDeleted = 0` : `SELECT * FROM attachments WHERE ownerId = ? AND attachmentId = ? AND isDeleted = 0`; - return sql.getRows(query, [this.noteId, attachmentId]) + return sql.getRows(query, [this.noteId, attachmentId]) .map(row => new BAttachment(row))[0]; } - /** @returns {BAttachment[]} */ - getAttachmentsByRole(role) { - return sql.getRows(` + getAttachmentsByRole(role: string): BAttachment[] { + return sql.getRows(` SELECT attachments.* FROM attachments WHERE ownerId = ? @@ -1172,8 +1162,7 @@ class BNote extends AbstractBeccaEntity { .map(row => new BAttachment(row)); } - /** @returns {BAttachment} */ - getAttachmentByTitle(title) { + getAttachmentByTitle(title: string): BAttachment { // cannot use SQL to filter by title since it can be encrypted return this.getAttachments().filter(attachment => attachment.title === title)[0]; } @@ -1181,9 +1170,9 @@ class BNote extends AbstractBeccaEntity { /** * Gives all possible note paths leading to this note. Paths containing search note are ignored (could form cycles) * - * @returns {string[][]} - array of notePaths (each represented by array of noteIds constituting the particular note path) + * @returns array of notePaths (each represented by array of noteIds constituting the particular note path) */ - getAllNotePaths() { + getAllNotePaths(): string[][] { if (this.noteId === 'root') { return [['root']]; } @@ -1201,11 +1190,7 @@ class BNote extends AbstractBeccaEntity { return notePaths; } - /** - * @param {string} [hoistedNoteId='root'] - * @return {Array} - */ - getSortedNotePathRecords(hoistedNoteId = 'root') { + getSortedNotePathRecords(hoistedNoteId: string = 'root'): NotePathRecord[] { const isHoistedRoot = hoistedNoteId === 'root'; const notePaths = this.getAllNotePaths().map(path => ({ @@ -1233,20 +1218,18 @@ class BNote extends AbstractBeccaEntity { /** * Returns a note path considered to be the "best" * - * @param {string} [hoistedNoteId='root'] - * @return {string[]} array of noteIds constituting the particular note path + * @return array of noteIds constituting the particular note path */ - getBestNotePath(hoistedNoteId = 'root') { + getBestNotePath(hoistedNoteId: string = 'root'): string[] { return this.getSortedNotePathRecords(hoistedNoteId)[0]?.notePath; } /** * Returns a note path considered to be the "best" * - * @param {string} [hoistedNoteId='root'] - * @return {string} serialized note path (e.g. 'root/a1h315/js725h') + * @return serialized note path (e.g. 'root/a1h315/js725h') */ - getBestNotePathString(hoistedNoteId = 'root') { + getBestNotePathString(hoistedNoteId: string = 'root'): string { const notePath = this.getBestNotePath(hoistedNoteId); return notePath?.join("/"); @@ -1274,10 +1257,9 @@ class BNote extends AbstractBeccaEntity { } /** - * @param ancestorNoteId - * @returns {boolean} - true if ancestorNoteId occurs in at least one of the note's paths + * @returns true if ancestorNoteId occurs in at least one of the note's paths */ - isDescendantOfNote(ancestorNoteId) { + isDescendantOfNote(ancestorNoteId: string): boolean { const notePaths = this.getAllNotePaths(); return notePaths.some(path => path.includes(ancestorNoteId)); @@ -1286,11 +1268,11 @@ class BNote extends AbstractBeccaEntity { /** * Update's given attribute's value or creates it if it doesn't exist * - * @param {string} type - attribute type (label, relation, etc.) - * @param {string} name - attribute name - * @param {string} [value] - attribute value (optional) + * @param type - attribute type (label, relation, etc.) + * @param name - attribute name + * @param value - attribute value (optional) */ - setAttribute(type, name, value) { + setAttribute(type: string, name: string, value?: string) { const attributes = this.getOwnedAttributes(); const attr = attributes.find(attr => attr.type === type && attr.name === name); @@ -1317,11 +1299,11 @@ class BNote extends AbstractBeccaEntity { /** * Removes given attribute name-value pair if it exists. * - * @param {string} type - attribute type (label, relation, etc.) - * @param {string} name - attribute name - * @param {string} [value] - attribute value (optional) + * @param type - attribute type (label, relation, etc.) + * @param name - attribute name + * @param value - attribute value (optional) */ - removeAttribute(type, name, value) { + removeAttribute(type: string, name: string, value?: string) { const attributes = this.getOwnedAttributes(); for (const attribute of attributes) { @@ -1335,14 +1317,11 @@ class BNote extends AbstractBeccaEntity { * Adds a new attribute to this note. The attribute is saved and returned. * See addLabel, addRelation for more specific methods. * - * @param {string} type - attribute type (label / relation) - * @param {string} name - name of the attribute, not including the leading ~/# - * @param {string} [value] - value of the attribute - text for labels, target note ID for relations; optional. - * @param {boolean} [isInheritable=false] - * @param {int|null} [position] - * @returns {BAttribute} + * @param type - attribute type (label / relation) + * @param name - name of the attribute, not including the leading ~/# + * @param value - value of the attribute - text for labels, target note ID for relations; optional. */ - addAttribute(type, name, value = "", isInheritable = false, position = null) { + addAttribute(type: string, name: string, value: string = "", isInheritable: boolean = false, position: number | null = null): BAttribute { const BAttribute = require('./battribute.js'); return new BAttribute({ @@ -1358,12 +1337,10 @@ class BNote extends AbstractBeccaEntity { /** * Adds a new label to this note. The label attribute is saved and returned. * - * @param {string} name - name of the label, not including the leading # - * @param {string} [value] - text value of the label; optional - * @param {boolean} [isInheritable=false] - * @returns {BAttribute} + * @param name - name of the label, not including the leading # + * @param value - text value of the label; optional */ - addLabel(name, value = "", isInheritable = false) { + addLabel(name: string, value: string = "", isInheritable: boolean = false): BAttribute { return this.addAttribute(LABEL, name, value, isInheritable); } @@ -1371,24 +1348,21 @@ class BNote extends AbstractBeccaEntity { * Adds a new relation to this note. The relation attribute is saved and * returned. * - * @param {string} name - name of the relation, not including the leading ~ - * @param {string} targetNoteId - * @param {boolean} [isInheritable=false] - * @returns {BAttribute} + * @param name - name of the relation, not including the leading ~ */ - addRelation(name, targetNoteId, isInheritable = false) { + addRelation(name: string, targetNoteId: string, isInheritable: boolean = false): BAttribute { return this.addAttribute(RELATION, name, targetNoteId, isInheritable); } /** * Based on enabled, the attribute is either set or removed. * - * @param {string} type - attribute type ('relation', 'label' etc.) - * @param {boolean} enabled - toggle On or Off - * @param {string} name - attribute name - * @param {string} [value] - attribute value (optional) + * @param type - attribute type ('relation', 'label' etc.) + * @param enabled - toggle On or Off + * @param name - attribute name + * @param value - attribute value (optional) */ - toggleAttribute(type, enabled, name, value) { + toggleAttribute(type: string, enabled: boolean, name: string, value?: string) { if (enabled) { this.setAttribute(type, name, value); } @@ -1400,68 +1374,76 @@ class BNote extends AbstractBeccaEntity { /** * Based on enabled, label is either set or removed. * - * @param {boolean} enabled - toggle On or Off - * @param {string} name - label name - * @param {string} [value] - label value (optional) + * @param enabled - toggle On or Off + * @param name - label name + * @param value - label value (optional) */ - toggleLabel(enabled, name, value) { return this.toggleAttribute(LABEL, enabled, name, value); } + toggleLabel(enabled: boolean, name: string, value?: string) { + return this.toggleAttribute(LABEL, enabled, name, value); + } /** * Based on enabled, relation is either set or removed. * - * @param {boolean} enabled - toggle On or Off - * @param {string} name - relation name - * @param {string} [value] - relation value (noteId) + * @param enabled - toggle On or Off + * @param name - relation name + * @param value - relation value (noteId) */ - toggleRelation(enabled, name, value) { return this.toggleAttribute(RELATION, enabled, name, value); } + toggleRelation(enabled: boolean, name: string, value?: string) { + return this.toggleAttribute(RELATION, enabled, name, value); + } /** * Update's given label's value or creates it if it doesn't exist * - * @param {string} name - label name - * @param {string} [value] - label value + * @param name - label name + * @param value label value */ - setLabel(name, value) { return this.setAttribute(LABEL, name, value); } + setLabel(name: string, value?: string) { + return this.setAttribute(LABEL, name, value); + } /** * Update's given relation's value or creates it if it doesn't exist * - * @param {string} name - relation name - * @param {string} value - relation value (noteId) + * @param name - relation name + * @param value - relation value (noteId) */ - setRelation(name, value) { return this.setAttribute(RELATION, name, value); } + setRelation(name: string, value: string) { + return this.setAttribute(RELATION, name, value); + } /** * Remove label name-value pair, if it exists. * - * @param {string} name - label name - * @param {string} [value] - label value + * @param name - label name + * @param value - label value */ - removeLabel(name, value) { return this.removeAttribute(LABEL, name, value); } + removeLabel(name: string, value?: string) { + return this.removeAttribute(LABEL, name, value); + } /** * Remove the relation name-value pair, if it exists. * - * @param {string} name - relation name - * @param {string} [value] - relation value (noteId) + * @param name - relation name + * @param value - relation value (noteId) */ - removeRelation(name, value) { return this.removeAttribute(RELATION, name, value); } + removeRelation(name: string, value?: string) { + return this.removeAttribute(RELATION, name, value); + } - searchNotesInSubtree(searchString) { + searchNotesInSubtree(searchString: string) { const searchService = require('../../services/search/services/search.js'); return searchService.searchNotes(searchString); } - searchNoteInSubtree(searchString) { + searchNoteInSubtree(searchString: string) { return this.searchNotesInSubtree(searchString)[0]; } - /** - * @param parentNoteId - * @returns {{success: boolean, message: string, branchId: string, notePath: string}} - */ - cloneTo(parentNoteId) { + cloneTo(parentNoteId: string) { const cloningService = require('../../services/cloning.js'); const branch = this.becca.getNote(parentNoteId).getParentBranches()[0]; @@ -1469,7 +1451,7 @@ class BNote extends AbstractBeccaEntity { return cloningService.cloneNoteToBranch(this.noteId, branch.branchId); } - isEligibleForConversionToAttachment(opts = {autoConversion: false}) { + isEligibleForConversionToAttachment(opts: ConvertOpts = { autoConversion: false }) { if (this.type !== 'image' || !this.isContentAvailable() || this.hasChildren() || this.getParentBranches().length !== 1) { return false; } @@ -1507,18 +1489,14 @@ class BNote extends AbstractBeccaEntity { * * In the future, this functionality might get more generic and some of the requirements relaxed. * - * @params {Object} [opts] - * @params {bolean} [opts.autoConversion=false} if true, the action is not triggered by user, but e.g. by migration, - * and only perfect candidates will be migrated - * - * @returns {BAttachment|null} - null if note is not eligible for conversion + * @returns null if note is not eligible for conversion */ - convertToParentAttachment(opts = {autoConversion: false}) { + convertToParentAttachment(opts: ConvertOpts = { autoConversion: false }): BAttachment | null { if (!this.isEligibleForConversionToAttachment(opts)) { return null; } - const content = this.getContent(); + const content = this.getContent() as string; const parentNote = this.getParentNotes()[0]; const attachment = parentNote.saveAttachment({ @@ -1528,7 +1506,7 @@ class BNote extends AbstractBeccaEntity { content: content }); - let parentContent = parentNote.getContent(); + let parentContent = parentNote.getContent() as string; const oldNoteUrl = `api/images/${this.noteId}/`; const newAttachmentUrl = `api/attachments/${attachment.attachmentId}/image/`; @@ -1548,10 +1526,9 @@ class BNote extends AbstractBeccaEntity { /** * (Soft) delete a note and all its descendants. * - * @param {string} [deleteId=null] - optional delete identified - * @param {TaskContext} [taskContext] + * @param deleteId - optional delete identified */ - deleteNote(deleteId = null, taskContext = null) { + deleteNote(deleteId: string | null = null, taskContext: TaskContext | null = null) { if (this.isDeleted) { return; } @@ -1577,12 +1554,12 @@ class BNote extends AbstractBeccaEntity { decrypt() { if (this.isProtected && !this.isDecrypted && protectedSessionService.isProtectedSessionAvailable()) { try { - this.title = protectedSessionService.decryptString(this.title); + this.title = protectedSessionService.decryptString(this.title) || ""; this.__flatTextCache = null; this.isDecrypted = true; } - catch (e) { + catch (e: any) { log.error(`Could not decrypt note ${this.noteId}: ${e.message} ${e.stack}`); } } @@ -1607,7 +1584,7 @@ class BNote extends AbstractBeccaEntity { */ saveRevision() { return sql.transactional(() => { - let noteContent = this.getContent(); + let noteContent = this.getContent() as string; const revision = new BRevision({ noteId: this.noteId, @@ -1628,7 +1605,7 @@ class BNote extends AbstractBeccaEntity { for (const noteAttachment of this.getAttachments()) { const revisionAttachment = noteAttachment.copy(); revisionAttachment.ownerId = revision.revisionId; - revisionAttachment.setContent(noteAttachment.getContent(), {forceSave: true}); + revisionAttachment.setContent(noteAttachment.getContent(), { forceSave: true }); if (this.type === 'text') { // content is rewritten to point to the revision attachments @@ -1651,14 +1628,14 @@ class BNote extends AbstractBeccaEntity { * Supported values are either 'attachmentId' (default) or 'title' * @returns {BAttachment} */ - saveAttachment({attachmentId, role, mime, title, content, position}, matchBy = 'attachmentId') { + saveAttachment({attachmentId, role, mime, title, content, position}: AttachmentRow, matchBy = 'attachmentId') { if (!['attachmentId', 'title'].includes(matchBy)) { throw new Error(`Unsupported value '${matchBy}' for matchBy param, has to be either 'attachmentId' or 'title'.`); } let attachment; - if (matchBy === 'title') { + if (matchBy === 'title' && title) { attachment = this.getAttachmentByTitle(title); } else if (matchBy === 'attachmentId' && attachmentId) { attachment = this.becca.getAttachmentOrThrow(attachmentId); @@ -1695,7 +1672,7 @@ class BNote extends AbstractBeccaEntity { getPojo() { return { noteId: this.noteId, - title: this.title, + title: this.title || undefined, isProtected: this.isProtected, type: this.type, mime: this.mime, @@ -1712,8 +1689,8 @@ class BNote extends AbstractBeccaEntity { const pojo = this.getPojo(); if (pojo.isProtected) { - if (this.isDecrypted) { - pojo.title = protectedSessionService.encrypt(pojo.title); + if (this.isDecrypted && pojo.title) { + pojo.title = protectedSessionService.encrypt(pojo.title) || undefined; } else { // updating protected note outside of protected session means we will keep original ciphertexts diff --git a/src/becca/entities/brevision.ts b/src/becca/entities/brevision.ts index df3447aed..90250b876 100644 --- a/src/becca/entities/brevision.ts +++ b/src/becca/entities/brevision.ts @@ -11,7 +11,7 @@ import { AttachmentRow, RevisionRow } from './rows'; interface ContentOpts { /** will also save this BRevision entity */ - forceSave: boolean; + forceSave?: boolean; } interface GetByIdOpts { @@ -22,7 +22,7 @@ interface GetByIdOpts { * Revision represents a snapshot of note's title and content at some point in the past. * It's used for seamless note versioning. */ -class BRevision extends AbstractBeccaEntity { +class BRevision extends AbstractBeccaEntity { static get entityName() { return "revisions"; } static get primaryKeyName() { return "revisionId"; } static get hashedProperties() { return ["revisionId", "noteId", "title", "isProtected", "dateLastEdited", "dateCreated", @@ -113,7 +113,7 @@ class BRevision extends AbstractBeccaEntity { } } - setContent(content: any, opts: ContentOpts) { + setContent(content: any, opts: ContentOpts = {}) { this._setContent(content, opts); } @@ -200,4 +200,4 @@ class BRevision extends AbstractBeccaEntity { } } -module.exports = BRevision; +export = BRevision; diff --git a/src/becca/entities/rows.ts b/src/becca/entities/rows.ts index db51542e0..c372b30c3 100644 --- a/src/becca/entities/rows.ts +++ b/src/becca/entities/rows.ts @@ -2,30 +2,31 @@ export interface AttachmentRow { attachmentId?: string; - ownerId: string; + ownerId?: string; role: string; mime: string; title?: string; position?: number; - blobId: string; + blobId?: string; isProtected?: boolean; dateModified?: string; utcDateModified?: string; utcDateScheduledForErasureSince?: string; contentLength?: number; + content?: string; } export interface RevisionRow { - revisionId: string; + revisionId?: string; noteId: string; type: string; mime: string; - isProtected: boolean; + isProtected?: boolean; title: string; - blobId: string; - dateLastEdited: string; + blobId?: string; + dateLastEdited?: string; dateCreated: string; - utcDateLastEdited: string; + utcDateLastEdited?: string; utcDateCreated: string; utcDateModified: string; contentLength?: number; @@ -71,7 +72,7 @@ export interface AttributeRow { position: number; value: string; isInheritable: boolean; - utcDateModified: string; + utcDateModified?: string; } export interface BranchRow { @@ -82,4 +83,24 @@ export interface BranchRow { notePosition: number; isExpanded: boolean; utcDateModified?: string; +} + +/** + * There are many different Note types, some of which are entirely opaque to the + * end user. Those types should be used only for checking against, they are + * not for direct use. + */ +export type NoteType = ("file" | "image" | "search" | "noteMap" | "launcher" | "doc" | "contentWidget" | "text" | "relationMap" | "render" | "canvas" | "mermaid" | "book" | "webView" | "code"); + +export interface NoteRow { + noteId: string; + title: string; + type: NoteType; + mime: string; + isProtected: boolean; + blobId: string; + dateCreated: string; + dateModified: string; + utcDateCreated: string; + utcDateModified: string; } \ No newline at end of file diff --git a/src/services/task_context.ts b/src/services/task_context.ts index 2b1272bb5..6aa2d9754 100644 --- a/src/services/task_context.ts +++ b/src/services/task_context.ts @@ -10,10 +10,10 @@ class TaskContext { private taskId: string; private taskType: string | null; private data: {} | null; - private noteDeletionHandlerTriggered: boolean; private progressCount: number; private lastSentCountTs: number; - + noteDeletionHandlerTriggered: boolean; + constructor(taskId: string, taskType: string | null = null, data: {} | null = {}) { this.taskId = taskId; this.taskType = taskType; diff --git a/src/services/utils.ts b/src/services/utils.ts index f16465af8..4cbb96d2f 100644 --- a/src/services/utils.ts +++ b/src/services/utils.ts @@ -12,7 +12,7 @@ function newEntityId() { return randomString(12); } -function randomString(length: number) { +function randomString(length: number): string { return randtoken.generate(length); } From 3a20bef1a9db61181832256f7b9bf5c3841fed1e Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 17 Feb 2024 11:13:53 +0200 Subject: [PATCH 32/49] server-ts: Fix more errors in becca entities --- src/becca/entities/abstract_becca_entity.ts | 2 +- src/becca/entities/battachment.ts | 2 +- src/becca/entities/battribute.ts | 6 +++- src/becca/entities/bbranch.ts | 27 ++++++++--------- src/becca/entities/bnote.ts | 33 ++++++++++----------- src/becca/entities/boption.ts | 2 +- src/becca/entities/brecent_note.ts | 4 +-- src/becca/entities/brevision.ts | 18 ++++++----- src/services/options.ts | 2 +- 9 files changed, 49 insertions(+), 47 deletions(-) diff --git a/src/becca/entities/abstract_becca_entity.ts b/src/becca/entities/abstract_becca_entity.ts index 50e76a212..1505a8830 100644 --- a/src/becca/entities/abstract_becca_entity.ts +++ b/src/becca/entities/abstract_becca_entity.ts @@ -273,7 +273,7 @@ abstract class AbstractBeccaEntity> { * * This is a low-level method, for notes and branches use `note.deleteNote()` and 'branch.deleteBranch()` instead. */ - markAsDeleted(deleteId = null) { + markAsDeleted(deleteId: string | null = null) { const constructorData = (this.constructor as unknown as ConstructorData); const entityId = (this as any)[constructorData.primaryKeyName]; const entityName = constructorData.entityName; diff --git a/src/becca/entities/battachment.ts b/src/becca/entities/battachment.ts index 728ee5e14..d2d0b8498 100644 --- a/src/becca/entities/battachment.ts +++ b/src/becca/entities/battachment.ts @@ -36,7 +36,7 @@ class BAttachment extends AbstractBeccaEntity { noteId?: number; attachmentId?: string; /** either noteId or revisionId to which this attachment belongs */ - ownerId: string; + ownerId?: string; role: string; mime: string; title: string; diff --git a/src/becca/entities/battribute.ts b/src/becca/entities/battribute.ts index 5afea9fdb..15e6ea911 100644 --- a/src/becca/entities/battribute.ts +++ b/src/becca/entities/battribute.ts @@ -7,6 +7,10 @@ import promotedAttributeDefinitionParser = require('../../services/promoted_attr import sanitizeAttributeName = require('../../services/sanitize_attribute_name'); import { AttributeRow, AttributeType } from './rows.js'; +interface SavingOpts { + skipValidation?: boolean; +} + /** * Attribute is an abstract concept which has two real uses - label (key - value pair) * and relation (representing named relationship between source and target note) @@ -174,7 +178,7 @@ class BAttribute extends AbstractBeccaEntity { return !(this.attributeId in this.becca.attributes); } - beforeSaving(opts = {}) { + beforeSaving(opts: SavingOpts = {}) { if (!opts.skipValidation) { this.validate(); } diff --git a/src/becca/entities/bbranch.ts b/src/becca/entities/bbranch.ts index 8892166c4..6c767197e 100644 --- a/src/becca/entities/bbranch.ts +++ b/src/becca/entities/bbranch.ts @@ -83,18 +83,18 @@ class BBranch extends AbstractBeccaEntity { } const parentNote = this.parentNote; - - if (!childNote.parents.includes(parentNote)) { - childNote.parents.push(parentNote); - } - - if (!parentNote.children.includes(childNote)) { - parentNote.children.push(childNote); + if (parentNote) { + if (!childNote.parents.includes(parentNote)) { + childNote.parents.push(parentNote); + } + + if (!parentNote.children.includes(childNote)) { + parentNote.children.push(childNote); + } } } - /** @returns {BNote} */ - get childNote() { + get childNote(): BNote { if (!(this.noteId in this.becca.notes)) { // entities can come out of order in sync/import, create skeleton which will be filled later this.becca.addNote(this.noteId, new BNote({noteId: this.noteId})); @@ -103,13 +103,12 @@ class BBranch extends AbstractBeccaEntity { return this.becca.notes[this.noteId]; } - /** @returns {BNote} */ - getNote() { + getNote(): BNote { return this.childNote; } - /** @returns {BNote|undefined} - root branch will have undefined parent, all other branches have to have a parent note */ - get parentNote() { + /** @returns root branch will have undefined parent, all other branches have to have a parent note */ + get parentNote(): BNote | undefined { if (!(this.parentNoteId in this.becca.notes) && this.parentNoteId !== 'none') { // entities can come out of order in sync/import, create skeleton which will be filled later this.becca.addNote(this.parentNoteId, new BNote({noteId: this.parentNoteId})); @@ -119,7 +118,7 @@ class BBranch extends AbstractBeccaEntity { } get isDeleted() { - return !(this.branchId in this.becca.branches); + return (this.branchId == undefined || !(this.branchId in this.becca.branches)); } /** diff --git a/src/becca/entities/bnote.ts b/src/becca/entities/bnote.ts index 6c7ed6895..232df43f4 100644 --- a/src/becca/entities/bnote.ts +++ b/src/becca/entities/bnote.ts @@ -64,15 +64,16 @@ class BNote extends AbstractBeccaEntity { isBeingDeleted!: boolean; isDecrypted!: boolean; + ownedAttributes!: BAttribute[]; + parentBranches!: BBranch[]; + parents!: BNote[]; + children!: BNote[]; + targetRelations!: BAttribute[]; + private __flatTextCache!: string | null; - private parentBranches!: BBranch[]; - private parents!: BNote[]; - private children!: BNote[]; - private ownedAttributes!: BAttribute[]; private __attributeCache!: BAttribute[] | null; private __inheritableAttributeCache!: BAttribute[] | null; - private targetRelations!: BAttribute[]; private __ancestorCache!: BNote[] | null; // following attributes are filled during searching in the database @@ -85,7 +86,7 @@ class BNote extends AbstractBeccaEntity { /** number of note revisions for this note */ private revisionCount!: number | null; - constructor(row: NoteRow) { + constructor(row: Partial) { super(); if (!row) { @@ -96,7 +97,7 @@ class BNote extends AbstractBeccaEntity { this.init(); } - updateFromRow(row: NoteRow) { + updateFromRow(row: Partial) { this.update([ row.noteId, row.title, @@ -215,17 +216,15 @@ class BNote extends AbstractBeccaEntity { * - changes in the note metadata or title should not trigger note content sync (so we keep separate utcDateModified and entity changes records) * - but to the user note content and title changes are one and the same - single dateModified (so all changes must go through Note and content is not a separate entity) */ - - /** @returns {string|Buffer} */ - getContent() { - return this._getContent(); + // FIXME: original declaration was (string | Buffer), but everywhere it's used as a string. + getContent(): string { + return this._getContent() as string; } /** - * @returns {*} * @throws Error in case of invalid JSON */ - getJsonContent() { - const content = this.getContent() as string; + getJsonContent(): {} | null { + const content = this.getContent(); if (!content || !content.trim()) { return null; @@ -1496,7 +1495,7 @@ class BNote extends AbstractBeccaEntity { return null; } - const content = this.getContent() as string; + const content = this.getContent(); const parentNote = this.getParentNotes()[0]; const attachment = parentNote.saveAttachment({ @@ -1506,7 +1505,7 @@ class BNote extends AbstractBeccaEntity { content: content }); - let parentContent = parentNote.getContent() as string; + let parentContent = parentNote.getContent(); const oldNoteUrl = `api/images/${this.noteId}/`; const newAttachmentUrl = `api/attachments/${attachment.attachmentId}/image/`; @@ -1584,7 +1583,7 @@ class BNote extends AbstractBeccaEntity { */ saveRevision() { return sql.transactional(() => { - let noteContent = this.getContent() as string; + let noteContent = this.getContent(); const revision = new BRevision({ noteId: this.noteId, diff --git a/src/becca/entities/boption.ts b/src/becca/entities/boption.ts index 871e44157..c72a41c11 100644 --- a/src/becca/entities/boption.ts +++ b/src/becca/entities/boption.ts @@ -7,7 +7,7 @@ import { OptionRow } from './rows'; /** * Option represents a name-value pair, either directly configurable by the user or some system property. */ -class BOption extends AbstractBeccaEntity { +class BOption extends AbstractBeccaEntity { static get entityName() { return "options"; } static get primaryKeyName() { return "name"; } static get hashedProperties() { return ["name", "value"]; } diff --git a/src/becca/entities/brecent_note.ts b/src/becca/entities/brecent_note.ts index a6796d0ff..8dbaf533c 100644 --- a/src/becca/entities/brecent_note.ts +++ b/src/becca/entities/brecent_note.ts @@ -7,10 +7,8 @@ import AbstractBeccaEntity = require('./abstract_becca_entity.js'); /** * RecentNote represents recently visited note. - * - * @extends AbstractBeccaEntity */ -class BRecentNote extends AbstractBeccaEntity { +class BRecentNote extends AbstractBeccaEntity { static get entityName() { return "recent_notes"; } static get primaryKeyName() { return "noteId"; } diff --git a/src/becca/entities/brevision.ts b/src/becca/entities/brevision.ts index 90250b876..cabbf5757 100644 --- a/src/becca/entities/brevision.ts +++ b/src/becca/entities/brevision.ts @@ -28,18 +28,19 @@ class BRevision extends AbstractBeccaEntity { static get hashedProperties() { return ["revisionId", "noteId", "title", "isProtected", "dateLastEdited", "dateCreated", "utcDateLastEdited", "utcDateCreated", "utcDateModified", "blobId"]; } - revisionId: string; + revisionId?: string; noteId: string; type: string; mime: string; isProtected: boolean; title: string; - blobId: string; - dateLastEdited: string; + blobId?: string; + dateLastEdited?: string; dateCreated: string; - utcDateLastEdited: string; + utcDateLastEdited?: string; utcDateCreated: string; contentLength?: number; + content?: string; constructor(row: RevisionRow, titleDecrypted = false) { super(); @@ -68,8 +69,8 @@ class BRevision extends AbstractBeccaEntity { return becca.notes[this.noteId]; } - /** @returns {boolean} true if the note has string content (not binary) */ - hasStringContent() { + /** @returns true if the note has string content (not binary) */ + hasStringContent(): boolean { return utils.isStringNote(this.type, this.mime); } @@ -87,8 +88,9 @@ class BRevision extends AbstractBeccaEntity { * * This is the same approach as is used for Note's content. */ - getContent(): string | Buffer { - return this._getContent(); + // FIXME: initial declaration included Buffer, but everywhere it's treated as a string. + getContent(): string { + return this._getContent() as string; } /** diff --git a/src/services/options.ts b/src/services/options.ts index 41532d74f..a7b5ad475 100644 --- a/src/services/options.ts +++ b/src/services/options.ts @@ -93,7 +93,7 @@ function getOptionMap() { return map; } -module.exports = { +export = { getOption, getOptionInt, getOptionBool, From 2c0063a5cc22e016c1a89d0a96df330898ea02ec Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 17 Feb 2024 11:16:00 +0200 Subject: [PATCH 33/49] server-ts: Remove .js extensions in src/becca --- src/becca/becca-interface.ts | 12 ++++++------ src/becca/becca_loader.js | 20 ++++++++++---------- src/becca/becca_service.js | 2 +- src/becca/entities/abstract_becca_entity.ts | 4 ++-- src/becca/entities/battachment.ts | 4 ++-- src/becca/entities/battribute.ts | 6 +++--- src/becca/entities/bbranch.ts | 8 ++++---- src/becca/entities/bnote.ts | 16 ++++++++-------- src/becca/entities/boption.ts | 2 +- src/becca/entities/brecent_note.ts | 2 +- src/becca/entities/brevision.ts | 6 +++--- src/becca/entity_constructor.js | 18 +++++++++--------- src/becca/similarity.js | 6 +++--- 13 files changed, 53 insertions(+), 53 deletions(-) diff --git a/src/becca/becca-interface.ts b/src/becca/becca-interface.ts index f71a81822..f7f435d61 100644 --- a/src/becca/becca-interface.ts +++ b/src/becca/becca-interface.ts @@ -155,7 +155,7 @@ class Becca { getRevision(revisionId) { const row = sql.getRow("SELECT * FROM revisions WHERE revisionId = ?", [revisionId]); - const BRevision = require('./entities/brevision.js'); // avoiding circular dependency problems + const BRevision = require('./entities/brevision'); // avoiding circular dependency problems return row ? new BRevision(row) : null; } @@ -170,7 +170,7 @@ class Becca { WHERE attachmentId = ? AND isDeleted = 0` : `SELECT * FROM attachments WHERE attachmentId = ? AND isDeleted = 0`; - const BAttachment = require('./entities/battachment.js'); // avoiding circular dependency problems + const BAttachment = require('./entities/battachment'); // avoiding circular dependency problems return sql.getRows(query, [attachmentId]) .map(row => new BAttachment(row))[0]; @@ -187,7 +187,7 @@ class Becca { /** @returns {BAttachment[]} */ getAttachments(attachmentIds) { - const BAttachment = require('./entities/battachment.js'); // avoiding circular dependency problems + const BAttachment = require('./entities/battachment'); // avoiding circular dependency problems return sql.getManyRows("SELECT * FROM attachments WHERE attachmentId IN (???) AND isDeleted = 0", attachmentIds) .map(row => new BAttachment(row)); } @@ -196,7 +196,7 @@ class Becca { getBlob(entity) { const row = sql.getRow("SELECT *, LENGTH(content) AS contentLength FROM blobs WHERE blobId = ?", [entity.blobId]); - const BBlob = require('./entities/bblob.js'); // avoiding circular dependency problems + const BBlob = require('./entities/bblob'); // avoiding circular dependency problems return row ? new BBlob(row) : null; } @@ -245,7 +245,7 @@ class Becca { getRecentNotesFromQuery(query, params = []) { const rows = sql.getRows(query, params); - const BRecentNote = require('./entities/brecent_note.js'); // avoiding circular dependency problems + const BRecentNote = require('./entities/brecent_note'); // avoiding circular dependency problems return rows.map(row => new BRecentNote(row)); } @@ -253,7 +253,7 @@ class Becca { getRevisionsFromQuery(query, params = []) { const rows = sql.getRows(query, params); - const BRevision = require('./entities/brevision.js'); // avoiding circular dependency problems + const BRevision = require('./entities/brevision'); // avoiding circular dependency problems return rows.map(row => new BRevision(row)); } diff --git a/src/becca/becca_loader.js b/src/becca/becca_loader.js index ecf7a7441..f0f0ccccd 100644 --- a/src/becca/becca_loader.js +++ b/src/becca/becca_loader.js @@ -2,23 +2,23 @@ const sql = require('../services/sql'); const eventService = require('../services/events'); -const becca = require('./becca.js'); -const sqlInit = require('../services/sql_init.js'); +const becca = require('./becca'); +const sqlInit = require('../services/sql_init'); const log = require('../services/log'); -const BNote = require('./entities/bnote.js'); -const BBranch = require('./entities/bbranch.js'); -const BAttribute = require('./entities/battribute.js'); -const BOption = require('./entities/boption.js'); -const BEtapiToken = require('./entities/betapi_token.js'); +const BNote = require('./entities/bnote'); +const BBranch = require('./entities/bbranch'); +const BAttribute = require('./entities/battribute'); +const BOption = require('./entities/boption'); +const BEtapiToken = require('./entities/betapi_token'); const cls = require('../services/cls'); -const entityConstructor = require('../becca/entity_constructor.js'); +const entityConstructor = require('../becca/entity_constructor'); const beccaLoaded = new Promise((res, rej) => { sqlInit.dbReady.then(() => { cls.init(() => { load(); - require('../services/options_init.js').initStartupOptions(); + require('../services/options_init').initStartupOptions(); res(); }); @@ -71,7 +71,7 @@ function load() { function reload(reason) { load(); - require('../services/ws.js').reloadFrontend(reason || "becca reloaded"); + require('../services/ws').reloadFrontend(reason || "becca reloaded"); } eventService.subscribeBeccaLoader([eventService.ENTITY_CHANGE_SYNCED], ({entityName, entityRow}) => { diff --git a/src/becca/becca_service.js b/src/becca/becca_service.js index 0d7e3193f..15a1c07cc 100644 --- a/src/becca/becca_service.js +++ b/src/becca/becca_service.js @@ -1,6 +1,6 @@ "use strict"; -const becca = require('./becca.js'); +const becca = require('./becca'); const cls = require('../services/cls'); const log = require('../services/log'); diff --git a/src/becca/entities/abstract_becca_entity.ts b/src/becca/entities/abstract_becca_entity.ts index 1505a8830..506e66564 100644 --- a/src/becca/entities/abstract_becca_entity.ts +++ b/src/becca/entities/abstract_becca_entity.ts @@ -2,13 +2,13 @@ import utils = require('../../services/utils'); import sql = require('../../services/sql'); -import entityChangesService = require('../../services/entity_changes.js'); +import entityChangesService = require('../../services/entity_changes'); import eventService = require('../../services/events'); import dateUtils = require('../../services/date_utils'); import cls = require('../../services/cls'); import log = require('../../services/log'); import protectedSessionService = require('../../services/protected_session'); -import blobService = require('../../services/blob.js'); +import blobService = require('../../services/blob'); import Becca = require('../becca-interface'); let becca: Becca | null = null; diff --git a/src/becca/entities/battachment.ts b/src/becca/entities/battachment.ts index d2d0b8498..9c46d00b7 100644 --- a/src/becca/entities/battachment.ts +++ b/src/becca/entities/battachment.ts @@ -2,7 +2,7 @@ import utils = require('../../services/utils'); import dateUtils = require('../../services/date_utils'); -import AbstractBeccaEntity = require('./abstract_becca_entity.js'); +import AbstractBeccaEntity = require('./abstract_becca_entity'); import sql = require('../../services/sql'); import protectedSessionService = require('../../services/protected_session'); import log = require('../../services/log'); @@ -152,7 +152,7 @@ class BAttachment extends AbstractBeccaEntity { throw new Error(`Cannot convert protected attachment outside of protected session`); } - const noteService = require('../../services/notes.js'); + const noteService = require('../../services/notes'); const { note, branch } = noteService.createNewNote({ parentNoteId: this.ownerId, diff --git a/src/becca/entities/battribute.ts b/src/becca/entities/battribute.ts index 15e6ea911..cc757d142 100644 --- a/src/becca/entities/battribute.ts +++ b/src/becca/entities/battribute.ts @@ -1,11 +1,11 @@ "use strict"; -import BNote = require('./bnote.js'); -import AbstractBeccaEntity = require('./abstract_becca_entity.js'); +import BNote = require('./bnote'); +import AbstractBeccaEntity = require('./abstract_becca_entity'); import dateUtils = require('../../services/date_utils'); import promotedAttributeDefinitionParser = require('../../services/promoted_attribute_definition_parser'); import sanitizeAttributeName = require('../../services/sanitize_attribute_name'); -import { AttributeRow, AttributeType } from './rows.js'; +import { AttributeRow, AttributeType } from './rows'; interface SavingOpts { skipValidation?: boolean; diff --git a/src/becca/entities/bbranch.ts b/src/becca/entities/bbranch.ts index 6c767197e..2086fc8a0 100644 --- a/src/becca/entities/bbranch.ts +++ b/src/becca/entities/bbranch.ts @@ -1,13 +1,13 @@ "use strict"; -import BNote = require('./bnote.js'); -import AbstractBeccaEntity = require('./abstract_becca_entity.js'); +import BNote = require('./bnote'); +import AbstractBeccaEntity = require('./abstract_becca_entity'); import dateUtils = require('../../services/date_utils'); import utils = require('../../services/utils'); import TaskContext = require('../../services/task_context'); import cls = require('../../services/cls'); import log = require('../../services/log'); -import { BranchRow } from './rows.js'; +import { BranchRow } from './rows'; /** * Branch represents a relationship between a child note and its parent note. Trilium allows a note to have multiple @@ -159,7 +159,7 @@ class BBranch extends AbstractBeccaEntity { if (parentBranches.length === 1 && parentBranches[0] === this) { // needs to be run before branches and attributes are deleted and thus attached relations disappear - const handlers = require('../../services/handlers.js'); + const handlers = require('../../services/handlers'); handlers.runAttachedRelations(note, 'runOnNoteDeletion', note); } } diff --git a/src/becca/entities/bnote.ts b/src/becca/entities/bnote.ts index 232df43f4..12c8ec593 100644 --- a/src/becca/entities/bnote.ts +++ b/src/becca/entities/bnote.ts @@ -5,7 +5,7 @@ import log = require('../../services/log'); import sql = require('../../services/sql'); import utils = require('../../services/utils'); import dateUtils = require('../../services/date_utils'); -import AbstractBeccaEntity = require('./abstract_becca_entity.js'); +import AbstractBeccaEntity = require('./abstract_becca_entity'); import BRevision = require('./brevision'); import BAttachment = require('./battachment'); import TaskContext = require('../../services/task_context'); @@ -896,7 +896,7 @@ class BNote extends AbstractBeccaEntity { } try { - const searchService = require('../../services/search/services/search.js'); + const searchService = require('../../services/search/services/search'); const {searchResultNoteIds} = searchService.searchFromNote(this); const becca = this.becca; @@ -1284,7 +1284,7 @@ class BNote extends AbstractBeccaEntity { } } else { - const BAttribute = require('./battribute.js'); + const BAttribute = require('./battribute'); new BAttribute({ noteId: this.noteId, @@ -1321,7 +1321,7 @@ class BNote extends AbstractBeccaEntity { * @param value - value of the attribute - text for labels, target note ID for relations; optional. */ addAttribute(type: string, name: string, value: string = "", isInheritable: boolean = false, position: number | null = null): BAttribute { - const BAttribute = require('./battribute.js'); + const BAttribute = require('./battribute'); return new BAttribute({ noteId: this.noteId, @@ -1433,7 +1433,7 @@ class BNote extends AbstractBeccaEntity { } searchNotesInSubtree(searchString: string) { - const searchService = require('../../services/search/services/search.js'); + const searchService = require('../../services/search/services/search'); return searchService.searchNotes(searchString); } @@ -1443,7 +1443,7 @@ class BNote extends AbstractBeccaEntity { } cloneTo(parentNoteId: string) { - const cloningService = require('../../services/cloning.js'); + const cloningService = require('../../services/cloning'); const branch = this.becca.getNote(parentNoteId).getParentBranches()[0]; @@ -1514,7 +1514,7 @@ class BNote extends AbstractBeccaEntity { parentNote.setContent(fixedContent); - const noteService = require('../../services/notes.js'); + const noteService = require('../../services/notes'); noteService.asyncPostProcessContent(parentNote, fixedContent); // to mark an unused attachment for deletion this.deleteNote(); @@ -1541,7 +1541,7 @@ class BNote extends AbstractBeccaEntity { } // needs to be run before branches and attributes are deleted and thus attached relations disappear - const handlers = require('../../services/handlers.js'); + const handlers = require('../../services/handlers'); handlers.runAttachedRelations(this, 'runOnNoteDeletion', this); taskContext.noteDeletionHandlerTriggered = true; diff --git a/src/becca/entities/boption.ts b/src/becca/entities/boption.ts index c72a41c11..afbf5320e 100644 --- a/src/becca/entities/boption.ts +++ b/src/becca/entities/boption.ts @@ -1,7 +1,7 @@ "use strict"; import dateUtils = require('../../services/date_utils'); -import AbstractBeccaEntity = require('./abstract_becca_entity.js'); +import AbstractBeccaEntity = require('./abstract_becca_entity'); import { OptionRow } from './rows'; /** diff --git a/src/becca/entities/brecent_note.ts b/src/becca/entities/brecent_note.ts index 8dbaf533c..4263e7f47 100644 --- a/src/becca/entities/brecent_note.ts +++ b/src/becca/entities/brecent_note.ts @@ -3,7 +3,7 @@ import { RecentNoteRow } from "./rows"; import dateUtils = require('../../services/date_utils'); -import AbstractBeccaEntity = require('./abstract_becca_entity.js'); +import AbstractBeccaEntity = require('./abstract_becca_entity'); /** * RecentNote represents recently visited note. diff --git a/src/becca/entities/brevision.ts b/src/becca/entities/brevision.ts index cabbf5757..43c6631de 100644 --- a/src/becca/entities/brevision.ts +++ b/src/becca/entities/brevision.ts @@ -3,10 +3,10 @@ import protectedSessionService = require('../../services/protected_session'); import utils = require('../../services/utils'); import dateUtils = require('../../services/date_utils'); -import becca = require('../becca.js'); -import AbstractBeccaEntity = require('./abstract_becca_entity.js'); +import becca = require('../becca'); +import AbstractBeccaEntity = require('./abstract_becca_entity'); import sql = require('../../services/sql'); -import BAttachment = require('./battachment.js'); +import BAttachment = require('./battachment'); import { AttachmentRow, RevisionRow } from './rows'; interface ContentOpts { diff --git a/src/becca/entity_constructor.js b/src/becca/entity_constructor.js index 3d66ed4da..c140b8a75 100644 --- a/src/becca/entity_constructor.js +++ b/src/becca/entity_constructor.js @@ -1,12 +1,12 @@ -const BAttachment = require('./entities/battachment.js'); -const BAttribute = require('./entities/battribute.js'); -const BBlob = require('./entities/bblob.js'); -const BBranch = require('./entities/bbranch.js'); -const BEtapiToken = require('./entities/betapi_token.js'); -const BNote = require('./entities/bnote.js'); -const BOption = require('./entities/boption.js'); -const BRecentNote = require('./entities/brecent_note.js'); -const BRevision = require('./entities/brevision.js'); +const BAttachment = require('./entities/battachment'); +const BAttribute = require('./entities/battribute'); +const BBlob = require('./entities/bblob'); +const BBranch = require('./entities/bbranch'); +const BEtapiToken = require('./entities/betapi_token'); +const BNote = require('./entities/bnote'); +const BOption = require('./entities/boption'); +const BRecentNote = require('./entities/brecent_note'); +const BRevision = require('./entities/brevision'); const ENTITY_NAME_TO_ENTITY = { "attachments": BAttachment, diff --git a/src/becca/similarity.js b/src/becca/similarity.js index 62c4a9cd1..b0ed39e13 100644 --- a/src/becca/similarity.js +++ b/src/becca/similarity.js @@ -1,6 +1,6 @@ -const becca = require('./becca.js'); +const becca = require('./becca'); const log = require('../services/log'); -const beccaService = require('./becca_service.js'); +const beccaService = require('./becca_service'); const dateUtils = require('../services/date_utils'); const {JSDOM} = require("jsdom"); @@ -35,7 +35,7 @@ const IGNORED_ATTR_NAMES = [ function filterUrlValue(value) { return value .replace(/https?:\/\//ig, "") - .replace(/www.js\./ig, "") + .replace(/www\./ig, "") .replace(/(\.net|\.com|\.org|\.info|\.edu)/ig, ""); } From 26388ad3b66219a5479ce4428b4f4c08093d756b Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 17 Feb 2024 11:24:50 +0200 Subject: [PATCH 34/49] server-ts: Fix errors in becca-interface --- src/becca/becca-interface.ts | 86 ++++++++++++++---------------- src/becca/entities/brecent_note.ts | 2 +- src/services/search/note_set.ts | 25 +++++---- src/services/sql.ts | 4 +- 4 files changed, 57 insertions(+), 60 deletions(-) diff --git a/src/becca/becca-interface.ts b/src/becca/becca-interface.ts index f7f435d61..a18dc9432 100644 --- a/src/becca/becca-interface.ts +++ b/src/becca/becca-interface.ts @@ -6,6 +6,15 @@ import BNote = require('./entities/bnote'); import BEtapiToken = require('./entities/betapi_token'); import BAttribute = require('./entities/battribute'); import BBranch = require('./entities/bbranch'); +import BRevision = require('./entities/brevision'); +import BAttachment = require('./entities/battachment'); +import { AttachmentRow, RevisionRow } from './entities/rows'; +import BBlob = require('./entities/bblob'); +import BRecentNote = require('./entities/brecent_note'); + +interface AttachmentOpts { + includeContentLength?: boolean; +} /** * Becca is a backend cache of all notes, branches, and attributes. @@ -23,8 +32,11 @@ class Becca { options!: Record; etapiTokens!: Record; + allNoteSetCache: NoteSet | null; + constructor() { this.reset(); + this.allNoteSetCache = null; } reset() { @@ -45,8 +57,7 @@ class Becca { return this.getNote('root'); } - /** @returns {BAttribute[]} */ - findAttributes(type, name) { + findAttributes(type: string, name: string): BAttribute[] { name = name.trim().toLowerCase(); if (name.startsWith('#') || name.startsWith('~')) { @@ -56,8 +67,7 @@ class Becca { return this.attributeIndex[`${type}-${name}`] || []; } - /** @returns {BAttribute[]} */ - findAttributesWithPrefix(type, name) { + findAttributesWithPrefix(type: string, name: string): BAttribute[] { const resArr = []; const key = `${type}-${name}`; @@ -76,18 +86,16 @@ class Becca { } } - addNote(noteId, note) { + addNote(noteId: string, note: BNote) { this.notes[noteId] = note; this.dirtyNoteSetCache(); } - /** @returns {BNote|null} */ - getNote(noteId) { + getNote(noteId: string): BNote | null { return this.notes[noteId]; } - /** @returns {BNote|null} */ - getNoteOrThrow(noteId) { + getNoteOrThrow(noteId: string): BNote | null { const note = this.notes[noteId]; if (!note) { throw new NotFoundError(`Note '${noteId}' doesn't exist.`); @@ -96,8 +104,7 @@ class Becca { return note; } - /** @returns {BNote[]} */ - getNotes(noteIds, ignoreMissing = false) { + getNotes(noteIds: string[], ignoreMissing: boolean = false): BNote[] { const filteredNotes = []; for (const noteId of noteIds) { @@ -117,13 +124,11 @@ class Becca { return filteredNotes; } - /** @returns {BBranch|null} */ - getBranch(branchId) { + getBranch(branchId: string): BBranch | null { return this.branches[branchId]; } - /** @returns {BBranch|null} */ - getBranchOrThrow(branchId) { + getBranchOrThrow(branchId: string): BBranch | null { const branch = this.getBranch(branchId); if (!branch) { throw new NotFoundError(`Branch '${branchId}' was not found in becca.`); @@ -131,13 +136,11 @@ class Becca { return branch; } - /** @returns {BAttribute|null} */ - getAttribute(attributeId) { + getAttribute(attributeId: string): BAttribute | null { return this.attributes[attributeId]; } - /** @returns {BAttribute} */ - getAttributeOrThrow(attributeId) { + getAttributeOrThrow(attributeId: string): BAttribute { const attribute = this.getAttribute(attributeId); if (!attribute) { throw new NotFoundError(`Attribute '${attributeId}' does not exist.`); @@ -146,21 +149,18 @@ class Becca { return attribute; } - /** @returns {BBranch|null} */ - getBranchFromChildAndParent(childNoteId, parentNoteId) { + getBranchFromChildAndParent(childNoteId: string, parentNoteId: string): BBranch | null { return this.childParentToBranch[`${childNoteId}-${parentNoteId}`]; } - /** @returns {BRevision|null} */ - getRevision(revisionId) { + getRevision(revisionId: string): BRevision | null { const row = sql.getRow("SELECT * FROM revisions WHERE revisionId = ?", [revisionId]); const BRevision = require('./entities/brevision'); // avoiding circular dependency problems return row ? new BRevision(row) : null; } - /** @returns {BAttachment|null} */ - getAttachment(attachmentId, opts = {}) { + getAttachment(attachmentId: string, opts: AttachmentOpts = {}): BAttachment | null { opts.includeContentLength = !!opts.includeContentLength; const query = opts.includeContentLength @@ -176,8 +176,7 @@ class Becca { .map(row => new BAttachment(row))[0]; } - /** @returns {BAttachment} */ - getAttachmentOrThrow(attachmentId, opts = {}) { + getAttachmentOrThrow(attachmentId: string, opts: AttachmentOpts = {}): BAttachment { const attachment = this.getAttachment(attachmentId, opts); if (!attachment) { throw new NotFoundError(`Attachment '${attachmentId}' has not been found.`); @@ -185,38 +184,33 @@ class Becca { return attachment; } - /** @returns {BAttachment[]} */ - getAttachments(attachmentIds) { + getAttachments(attachmentIds: string[]): BAttachment[] { const BAttachment = require('./entities/battachment'); // avoiding circular dependency problems - return sql.getManyRows("SELECT * FROM attachments WHERE attachmentId IN (???) AND isDeleted = 0", attachmentIds) + return sql.getManyRows("SELECT * FROM attachments WHERE attachmentId IN (???) AND isDeleted = 0", attachmentIds) .map(row => new BAttachment(row)); } - /** @returns {BBlob|null} */ - getBlob(entity) { + getBlob(entity: { blobId: string }): BBlob | null { const row = sql.getRow("SELECT *, LENGTH(content) AS contentLength FROM blobs WHERE blobId = ?", [entity.blobId]); const BBlob = require('./entities/bblob'); // avoiding circular dependency problems return row ? new BBlob(row) : null; } - /** @returns {BOption|null} */ - getOption(name) { + getOption(name: string): BOption | null { return this.options[name]; } - /** @returns {BEtapiToken[]} */ - getEtapiTokens() { + getEtapiTokens(): BEtapiToken[] { return Object.values(this.etapiTokens); } - /** @returns {BEtapiToken|null} */ - getEtapiToken(etapiTokenId) { + getEtapiToken(etapiTokenId: string): BEtapiToken | null { return this.etapiTokens[etapiTokenId]; } /** @returns {AbstractBeccaEntity|null} */ - getEntity(entityName, entityId) { + getEntity(entityName: string, entityId: string) { if (!entityName || !entityId) { return null; } @@ -238,20 +232,18 @@ class Becca { throw new Error(`Unknown entity name '${camelCaseEntityName}' (original argument '${entityName}')`); } - return this[camelCaseEntityName][entityId]; + return (this as any)[camelCaseEntityName][entityId]; } - /** @returns {BRecentNote[]} */ - getRecentNotesFromQuery(query, params = []) { + getRecentNotesFromQuery(query: string, params = []): BRecentNote[] { const rows = sql.getRows(query, params); const BRecentNote = require('./entities/brecent_note'); // avoiding circular dependency problems return rows.map(row => new BRecentNote(row)); } - /** @returns {BRevision[]} */ - getRevisionsFromQuery(query, params = []) { - const rows = sql.getRows(query, params); + getRevisionsFromQuery(query: string, params = []): BRevision[] { + const rows = sql.getRows(query, params); const BRevision = require('./entities/brevision'); // avoiding circular dependency problems return rows.map(row => new BRevision(row)); @@ -267,8 +259,8 @@ class Becca { if (!this.allNoteSetCache) { const allNotes = []; - for (const noteId in becca.notes) { - const note = becca.notes[noteId]; + for (const noteId in this.notes) { + const note = this.notes[noteId]; // in the process of loading data sometimes we create "skeleton" note instances which are expected to be filled later // in case of inconsistent data this might not work and search will then crash on these diff --git a/src/becca/entities/brecent_note.ts b/src/becca/entities/brecent_note.ts index 4263e7f47..0771a5e00 100644 --- a/src/becca/entities/brecent_note.ts +++ b/src/becca/entities/brecent_note.ts @@ -33,4 +33,4 @@ class BRecentNote extends AbstractBeccaEntity { } } -module.exports = BRecentNote; +export = BRecentNote; diff --git a/src/services/search/note_set.ts b/src/services/search/note_set.ts index 3ce84b469..d53d00e4d 100644 --- a/src/services/search/note_set.ts +++ b/src/services/search/note_set.ts @@ -1,40 +1,45 @@ "use strict"; +import BNote = require("../../becca/entities/bnote"); + class NoteSet { - constructor(notes = []) { - /** @type {BNote[]} */ + + private notes: BNote[]; + private noteIdSet: Set; + private sorted: boolean; + + constructor(notes: BNote[] = []) { this.notes = notes; this.noteIdSet = new Set(notes.map(note => note.noteId)); - /** @type {boolean} */ this.sorted = false; } - add(note) { + add(note: BNote) { if (!this.hasNote(note)) { this.notes.push(note); this.noteIdSet.add(note.noteId); } } - addAll(notes) { + addAll(notes: BNote[]) { for (const note of notes) { this.add(note); } } - hasNote(note) { + hasNote(note: BNote) { return this.hasNoteId(note.noteId); } - hasNoteId(noteId) { + hasNoteId(noteId: string) { return this.noteIdSet.has(noteId); } - mergeIn(anotherNoteSet) { + mergeIn(anotherNoteSet: NoteSet) { this.addAll(anotherNoteSet.notes); } - minus(anotherNoteSet) { + minus(anotherNoteSet: NoteSet) { const newNoteSet = new NoteSet(); for (const note of this.notes) { @@ -46,7 +51,7 @@ class NoteSet { return newNoteSet; } - intersection(anotherNoteSet) { + intersection(anotherNoteSet: NoteSet) { const newNoteSet = new NoteSet(); for (const note of this.notes) { diff --git a/src/services/sql.ts b/src/services/sql.ts index e1c3f5776..2b93ce263 100644 --- a/src/services/sql.ts +++ b/src/services/sql.ts @@ -110,7 +110,7 @@ function getValue(query: string, params: Params = []): T { // smaller values can result in better performance due to better usage of statement cache const PARAM_LIMIT = 100; -function getManyRows(query: string, params: Params): T[] | null { +function getManyRows(query: string, params: Params): T[] { let results: unknown[] = []; while (params.length > 0) { @@ -136,7 +136,7 @@ function getManyRows(query: string, params: Params): T[] | null { results = results.concat(subResults); } - return results as (T[] | null); + return (results as (T[] | null) || []); } function getRows(query: string, params: Params = []): T[] { From 2f96dc2d9defc13907e483edb5cc41056ce631d9 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 17 Feb 2024 11:39:29 +0200 Subject: [PATCH 35/49] server-ts: Fix most type errors in becca --- src/becca/entities/abstract_becca_entity.ts | 10 ++++++++-- src/becca/entities/battachment.ts | 2 +- src/becca/entities/bblob.ts | 1 + src/becca/entities/bbranch.ts | 20 ++++++++++++++------ src/becca/entities/betapi_token.ts | 8 ++++++-- src/becca/entities/bnote.ts | 18 +++++++++++------- 6 files changed, 41 insertions(+), 18 deletions(-) diff --git a/src/becca/entities/abstract_becca_entity.ts b/src/becca/entities/abstract_becca_entity.ts index 506e66564..53999be68 100644 --- a/src/becca/entities/abstract_becca_entity.ts +++ b/src/becca/entities/abstract_becca_entity.ts @@ -88,11 +88,17 @@ abstract class AbstractBeccaEntity> { return this.getPojo(); } - abstract hasStringContent(): boolean; + hasStringContent(): boolean { + // FIXME: Not sure why some entities don't implement it. + return true; + } abstract getPojo(): {}; - abstract get isDeleted(): boolean; + get isDeleted(): boolean { + // FIXME: Not sure why some entities don't implement it. + return false; + } /** * Saves entity - executes SQL, but doesn't commit the transaction on its own diff --git a/src/becca/entities/battachment.ts b/src/becca/entities/battachment.ts index 9c46d00b7..0d301494e 100644 --- a/src/becca/entities/battachment.ts +++ b/src/becca/entities/battachment.ts @@ -36,7 +36,7 @@ class BAttachment extends AbstractBeccaEntity { noteId?: number; attachmentId?: string; /** either noteId or revisionId to which this attachment belongs */ - ownerId?: string; + ownerId: string; role: string; mime: string; title: string; diff --git a/src/becca/entities/bblob.ts b/src/becca/entities/bblob.ts index 2ea67f044..27d559515 100644 --- a/src/becca/entities/bblob.ts +++ b/src/becca/entities/bblob.ts @@ -1,5 +1,6 @@ import { BlobRow } from "./rows"; +// FIXME: Why this does not extend the abstract becca? class BBlob { static get entityName() { return "blobs"; } static get primaryKeyName() { return "blobId"; } diff --git a/src/becca/entities/bbranch.ts b/src/becca/entities/bbranch.ts index 2086fc8a0..bf64d2ac6 100644 --- a/src/becca/entities/bbranch.ts +++ b/src/becca/entities/bbranch.ts @@ -180,7 +180,9 @@ class BBranch extends AbstractBeccaEntity { } for (const childBranch of note.getChildBranches()) { - childBranch.deleteBranch(deleteId, taskContext); + if (childBranch) { + childBranch.deleteBranch(deleteId, taskContext); + } } // first delete children and then parent - this will show up better in recent changes @@ -220,11 +222,17 @@ class BBranch extends AbstractBeccaEntity { if (this.notePosition === undefined || this.notePosition === null) { let maxNotePos = 0; - for (const childBranch of this.parentNote.getChildBranches()) { - if (maxNotePos < childBranch.notePosition - && childBranch.noteId !== '_hidden' // hidden has a very large notePosition to always stay last - ) { - maxNotePos = childBranch.notePosition; + if (this.parentNote) { + for (const childBranch of this.parentNote.getChildBranches()) { + if (!childBranch) { + continue; + } + + if (maxNotePos < childBranch.notePosition + && childBranch.noteId !== '_hidden' // hidden has a very large notePosition to always stay last + ) { + maxNotePos = childBranch.notePosition; + } } } diff --git a/src/becca/entities/betapi_token.ts b/src/becca/entities/betapi_token.ts index e4711c5fa..d128c1beb 100644 --- a/src/becca/entities/betapi_token.ts +++ b/src/becca/entities/betapi_token.ts @@ -22,7 +22,7 @@ class BEtapiToken extends AbstractBeccaEntity { etapiTokenId!: string; name!: string; tokenHash!: string; - isDeleted!: boolean; + private _isDeleted!: boolean; constructor(row: EtapiTokenRow) { super(); @@ -35,13 +35,17 @@ class BEtapiToken extends AbstractBeccaEntity { this.init(); } + get isDeleted() { + return this._isDeleted; + } + updateFromRow(row: EtapiTokenRow) { this.etapiTokenId = row.etapiTokenId; this.name = row.name; this.tokenHash = row.tokenHash; this.utcDateCreated = row.utcDateCreated || dateUtils.utcNowDateTime(); this.utcDateModified = row.utcDateModified || this.utcDateCreated; - this.isDeleted = !!row.isDeleted; + this._isDeleted = !!row.isDeleted; if (this.etapiTokenId) { this.becca.etapiTokens[this.etapiTokenId] = this; diff --git a/src/becca/entities/bnote.ts b/src/becca/entities/bnote.ts index 12c8ec593..a6ae85284 100644 --- a/src/becca/entities/bnote.ts +++ b/src/becca/entities/bnote.ts @@ -203,8 +203,7 @@ class BNote extends AbstractBeccaEntity { return this.children && this.children.length > 0; } - /** @returns {BBranch[]} */ - getChildBranches() { + getChildBranches(): (BBranch | null)[] { return this.children.map(childNote => this.becca.getBranchFromChildAndParent(childNote.noteId, this.noteId)); } @@ -757,7 +756,7 @@ class BNote extends AbstractBeccaEntity { this.parents = this.parentBranches .map(branch => branch.parentNote) - .filter(note => !!note); + .filter(note => !!note) as BNote[]; } sortChildren() { @@ -771,7 +770,7 @@ class BNote extends AbstractBeccaEntity { const aBranch = becca.getBranchFromChildAndParent(a.noteId, this.noteId); const bBranch = becca.getBranchFromChildAndParent(b.noteId, this.noteId); - return (aBranch?.notePosition - bBranch?.notePosition) || 0; + return ((aBranch?.notePosition || 0) - (bBranch?.notePosition || 0)) || 0; }); } @@ -900,7 +899,7 @@ class BNote extends AbstractBeccaEntity { const {searchResultNoteIds} = searchService.searchFromNote(this); const becca = this.becca; - return searchResultNoteIds + return (searchResultNoteIds as string[]) // FIXME: remove cast once search is converted .map(resultNoteId => becca.notes[resultNoteId]) .filter(note => !!note); } @@ -1445,9 +1444,9 @@ class BNote extends AbstractBeccaEntity { cloneTo(parentNoteId: string) { const cloningService = require('../../services/cloning'); - const branch = this.becca.getNote(parentNoteId).getParentBranches()[0]; + const branch = this.becca.getNote(parentNoteId)?.getParentBranches()[0]; - return cloningService.cloneNoteToBranch(this.noteId, branch.branchId); + return cloningService.cloneNoteToBranch(this.noteId, branch?.branchId); } isEligibleForConversionToAttachment(opts: ConvertOpts = { autoConversion: false }) { @@ -1603,6 +1602,11 @@ class BNote extends AbstractBeccaEntity { for (const noteAttachment of this.getAttachments()) { const revisionAttachment = noteAttachment.copy(); + + if (!revision.revisionId) { + throw new Error("Revision ID is missing."); + } + revisionAttachment.ownerId = revision.revisionId; revisionAttachment.setContent(noteAttachment.getContent(), { forceSave: true }); From 8b250e4a1345f280895b9993c76da03661147590 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 17 Feb 2024 11:42:19 +0200 Subject: [PATCH 36/49] server-ts: Fix references to js files for converted files --- src/etapi/attachments.js | 2 +- src/etapi/attributes.js | 2 +- src/etapi/auth.js | 2 +- src/etapi/branches.js | 2 +- src/etapi/etapi_utils.js | 2 +- src/etapi/notes.js | 2 +- src/etapi/validators.js | 2 +- src/routes/api/attachments.js | 4 ++-- src/routes/api/attributes.js | 2 +- src/routes/api/autocomplete.js | 2 +- src/routes/api/branches.js | 2 +- src/routes/api/bulk_action.js | 2 +- src/routes/api/export.js | 2 +- src/routes/api/files.js | 2 +- src/routes/api/fonts.js | 2 +- src/routes/api/image.js | 2 +- src/routes/api/import.js | 2 +- src/routes/api/keys.js | 2 +- src/routes/api/login.js | 2 +- src/routes/api/note_map.js | 2 +- src/routes/api/notes.js | 4 ++-- src/routes/api/options.js | 2 +- src/routes/api/other.js | 2 +- src/routes/api/recent_changes.js | 2 +- src/routes/api/relation-map.js | 2 +- src/routes/api/revisions.js | 4 ++-- src/routes/api/script.js | 2 +- src/routes/api/search.js | 2 +- src/routes/api/similar_notes.js | 2 +- src/routes/api/special_notes.js | 2 +- src/routes/api/sql.js | 2 +- src/routes/api/stats.js | 2 +- src/routes/api/sync.js | 2 +- src/routes/api/tree.js | 2 +- src/routes/custom.js | 2 +- src/routes/index.js | 2 +- src/routes/login.js | 2 +- src/services/attributes.js | 2 +- src/services/backend_script_api.js | 6 +++--- src/services/backup.js | 2 +- src/services/blob.ts | 2 +- src/services/bulk_actions.js | 2 +- src/services/cloning.js | 4 ++-- src/services/cls.ts | 4 ++-- src/services/consistency_checks.js | 6 +++--- src/services/encryption/my_scrypt.ts | 2 +- src/services/encryption/password.ts | 2 +- src/services/encryption/password_encryption.ts | 2 +- src/services/entity_changes.ts | 4 ++-- src/services/erase.js | 4 ++-- src/services/etapi_tokens.js | 2 +- src/services/export/opml.js | 2 +- src/services/export/single.js | 2 +- src/services/export/zip.js | 2 +- src/services/handlers.js | 2 +- src/services/hidden_subtree.js | 2 +- src/services/hoisted_note.js | 2 +- src/services/image.js | 4 ++-- src/services/import/zip.js | 2 +- src/services/keyboard_actions.js | 2 +- src/services/notes.js | 6 +++--- src/services/options_init.js | 2 +- src/services/protected_session.ts | 2 +- src/services/script.js | 2 +- src/services/search/expressions/ancestor.js | 2 +- src/services/search/expressions/attribute_exists.js | 2 +- src/services/search/expressions/descendant_of.js | 2 +- src/services/search/expressions/label_comparison.js | 2 +- src/services/search/expressions/note_content_fulltext.js | 2 +- src/services/search/expressions/note_flat_text.js | 2 +- src/services/search/expressions/relation_where.js | 2 +- src/services/search/search_result.js | 2 +- src/services/search/services/search.js | 2 +- src/services/setup.js | 4 ++-- src/services/special_notes.js | 2 +- src/services/sql.ts | 2 +- src/services/sql_init.js | 4 ++-- src/services/sync.js | 6 +++--- src/services/sync_options.js | 2 +- src/services/sync_update.js | 2 +- src/services/tray.js | 2 +- src/services/tree.js | 4 ++-- src/services/window.js | 2 +- src/services/ws.ts | 2 +- 84 files changed, 103 insertions(+), 103 deletions(-) diff --git a/src/etapi/attachments.js b/src/etapi/attachments.js index 2c77210cc..8a3802061 100644 --- a/src/etapi/attachments.js +++ b/src/etapi/attachments.js @@ -1,4 +1,4 @@ -const becca = require('../becca/becca.js'); +const becca = require('../becca/becca'); const eu = require('./etapi_utils'); const mappers = require('./mappers.js'); const v = require('./validators.js'); diff --git a/src/etapi/attributes.js b/src/etapi/attributes.js index 692b8c05e..dca82b0ea 100644 --- a/src/etapi/attributes.js +++ b/src/etapi/attributes.js @@ -1,4 +1,4 @@ -const becca = require('../becca/becca.js'); +const becca = require('../becca/becca'); const eu = require('./etapi_utils'); const mappers = require('./mappers.js'); const attributeService = require('../services/attributes.js'); diff --git a/src/etapi/auth.js b/src/etapi/auth.js index d5cab7e15..cdb8d5f79 100644 --- a/src/etapi/auth.js +++ b/src/etapi/auth.js @@ -1,4 +1,4 @@ -const becca = require('../becca/becca.js'); +const becca = require('../becca/becca'); const eu = require('./etapi_utils'); const passwordEncryptionService = require('../services/encryption/password_encryption.js'); const etapiTokenService = require('../services/etapi_tokens.js'); diff --git a/src/etapi/branches.js b/src/etapi/branches.js index 19741b100..2206d2224 100644 --- a/src/etapi/branches.js +++ b/src/etapi/branches.js @@ -1,4 +1,4 @@ -const becca = require('../becca/becca.js'); +const becca = require('../becca/becca'); const eu = require('./etapi_utils'); const mappers = require('./mappers.js'); const BBranch = require('../becca/entities/bbranch.js'); diff --git a/src/etapi/etapi_utils.js b/src/etapi/etapi_utils.js index 41d40cf94..5fe5459fb 100644 --- a/src/etapi/etapi_utils.js +++ b/src/etapi/etapi_utils.js @@ -1,7 +1,7 @@ const cls = require('../services/cls'); const sql = require('../services/sql'); const log = require('../services/log'); -const becca = require('../becca/becca.js'); +const becca = require('../becca/becca'); const etapiTokenService = require('../services/etapi_tokens.js'); const config = require('../services/config.js'); const GENERIC_CODE = "GENERIC"; diff --git a/src/etapi/notes.js b/src/etapi/notes.js index 8acb3546e..0878f9d77 100644 --- a/src/etapi/notes.js +++ b/src/etapi/notes.js @@ -1,4 +1,4 @@ -const becca = require('../becca/becca.js'); +const becca = require('../becca/becca'); const utils = require('../services/utils'); const eu = require('./etapi_utils'); const mappers = require('./mappers.js'); diff --git a/src/etapi/validators.js b/src/etapi/validators.js index f9ca0fa6a..59ddc1675 100644 --- a/src/etapi/validators.js +++ b/src/etapi/validators.js @@ -64,7 +64,7 @@ function isNoteId(obj) { return; } - const becca = require('../becca/becca.js'); + const becca = require('../becca/becca'); if (typeof obj !== 'string') { return `'${obj}' is not a valid noteId`; diff --git a/src/routes/api/attachments.js b/src/routes/api/attachments.js index 1beca350e..09bf09376 100644 --- a/src/routes/api/attachments.js +++ b/src/routes/api/attachments.js @@ -1,5 +1,5 @@ -const becca = require('../../becca/becca.js'); -const blobService = require('../../services/blob.js'); +const becca = require('../../becca/becca'); +const blobService = require('../../services/blob'); const ValidationError = require('../../errors/validation_error'); const imageService = require("../../services/image.js"); diff --git a/src/routes/api/attributes.js b/src/routes/api/attributes.js index bdbab50c5..0471fc298 100644 --- a/src/routes/api/attributes.js +++ b/src/routes/api/attributes.js @@ -4,7 +4,7 @@ const sql = require('../../services/sql'); const log = require('../../services/log'); const attributeService = require('../../services/attributes.js'); const BAttribute = require('../../becca/entities/battribute.js'); -const becca = require('../../becca/becca.js'); +const becca = require('../../becca/becca'); const ValidationError = require('../../errors/validation_error'); function getEffectiveNoteAttributes(req) { diff --git a/src/routes/api/autocomplete.js b/src/routes/api/autocomplete.js index e28ccfcdb..a3113ba62 100644 --- a/src/routes/api/autocomplete.js +++ b/src/routes/api/autocomplete.js @@ -5,7 +5,7 @@ const searchService = require('../../services/search/services/search.js'); const log = require('../../services/log'); const utils = require('../../services/utils'); const cls = require('../../services/cls'); -const becca = require('../../becca/becca.js'); +const becca = require('../../becca/becca'); function getAutocomplete(req) { const query = req.query.query.trim(); diff --git a/src/routes/api/branches.js b/src/routes/api/branches.js index 55576665e..06c81cd38 100644 --- a/src/routes/api/branches.js +++ b/src/routes/api/branches.js @@ -5,7 +5,7 @@ const utils = require('../../services/utils'); const entityChangesService = require('../../services/entity_changes.js'); const treeService = require('../../services/tree.js'); const eraseService = require('../../services/erase.js'); -const becca = require('../../becca/becca.js'); +const becca = require('../../becca/becca'); const TaskContext = require('../../services/task_context.js'); const branchService = require('../../services/branches.js'); const log = require('../../services/log'); diff --git a/src/routes/api/bulk_action.js b/src/routes/api/bulk_action.js index 08f59df49..f04b32d61 100644 --- a/src/routes/api/bulk_action.js +++ b/src/routes/api/bulk_action.js @@ -1,4 +1,4 @@ -const becca = require('../../becca/becca.js'); +const becca = require('../../becca/becca'); const bulkActionService = require('../../services/bulk_actions.js'); function execute(req) { diff --git a/src/routes/api/export.js b/src/routes/api/export.js index 240f2ef4c..3ceaaa857 100644 --- a/src/routes/api/export.js +++ b/src/routes/api/export.js @@ -3,7 +3,7 @@ const zipExportService = require('../../services/export/zip.js'); const singleExportService = require('../../services/export/single.js'); const opmlExportService = require('../../services/export/opml.js'); -const becca = require('../../becca/becca.js'); +const becca = require('../../becca/becca'); const TaskContext = require('../../services/task_context.js'); const log = require('../../services/log'); const NotFoundError = require('../../errors/not_found_error'); diff --git a/src/routes/api/files.js b/src/routes/api/files.js index 10a1b758e..78fa9f5db 100644 --- a/src/routes/api/files.js +++ b/src/routes/api/files.js @@ -9,7 +9,7 @@ const fs = require('fs'); const { Readable } = require('stream'); const chokidar = require('chokidar'); const ws = require('../../services/ws.js'); -const becca = require('../../becca/becca.js'); +const becca = require('../../becca/becca'); const ValidationError = require('../../errors/validation_error'); function updateFile(req) { diff --git a/src/routes/api/fonts.js b/src/routes/api/fonts.js index 6e7cce87f..d21db07c8 100644 --- a/src/routes/api/fonts.js +++ b/src/routes/api/fonts.js @@ -1,4 +1,4 @@ -const optionService = require('../../services/options.js'); +const optionService = require('../../services/options'); function getFontCss(req, res) { res.setHeader('Content-Type', 'text/css'); diff --git a/src/routes/api/image.js b/src/routes/api/image.js index a48978a0d..d1c702bc7 100644 --- a/src/routes/api/image.js +++ b/src/routes/api/image.js @@ -1,7 +1,7 @@ "use strict"; const imageService = require('../../services/image.js'); -const becca = require('../../becca/becca.js'); +const becca = require('../../becca/becca'); const RESOURCE_DIR = require('../../services/resource_dir').RESOURCE_DIR; const fs = require('fs'); diff --git a/src/routes/api/import.js b/src/routes/api/import.js index 49dd027c4..f3fd9e28c 100644 --- a/src/routes/api/import.js +++ b/src/routes/api/import.js @@ -6,7 +6,7 @@ const zipImportService = require('../../services/import/zip.js'); const singleImportService = require('../../services/import/single.js'); const cls = require('../../services/cls'); const path = require('path'); -const becca = require('../../becca/becca.js'); +const becca = require('../../becca/becca'); const beccaLoader = require('../../becca/becca_loader.js'); const log = require('../../services/log'); const TaskContext = require('../../services/task_context.js'); diff --git a/src/routes/api/keys.js b/src/routes/api/keys.js index 3f75f11a3..a2f2a0b37 100644 --- a/src/routes/api/keys.js +++ b/src/routes/api/keys.js @@ -1,7 +1,7 @@ "use strict"; const keyboardActions = require('../../services/keyboard_actions.js'); -const becca = require('../../becca/becca.js'); +const becca = require('../../becca/becca'); function getKeyboardActions() { return keyboardActions.getKeyboardActions(); diff --git a/src/routes/api/login.js b/src/routes/api/login.js index a3491700f..30dc68189 100644 --- a/src/routes/api/login.js +++ b/src/routes/api/login.js @@ -1,6 +1,6 @@ "use strict"; -const options = require('../../services/options.js'); +const options = require('../../services/options'); const utils = require('../../services/utils'); const dateUtils = require('../../services/date_utils'); const instanceId = require('../../services/instance_id'); diff --git a/src/routes/api/note_map.js b/src/routes/api/note_map.js index 30ad771ca..2e13f6167 100644 --- a/src/routes/api/note_map.js +++ b/src/routes/api/note_map.js @@ -1,6 +1,6 @@ "use strict"; -const becca = require('../../becca/becca.js'); +const becca = require('../../becca/becca'); const { JSDOM } = require("jsdom"); function buildDescendantCountMap(noteIdsToCount) { diff --git a/src/routes/api/notes.js b/src/routes/api/notes.js index 6a3eaad25..810659b72 100644 --- a/src/routes/api/notes.js +++ b/src/routes/api/notes.js @@ -7,9 +7,9 @@ const sql = require('../../services/sql'); const utils = require('../../services/utils'); const log = require('../../services/log'); const TaskContext = require('../../services/task_context.js'); -const becca = require('../../becca/becca.js'); +const becca = require('../../becca/becca'); const ValidationError = require('../../errors/validation_error'); -const blobService = require('../../services/blob.js'); +const blobService = require('../../services/blob'); function getNote(req) { return becca.getNoteOrThrow(req.params.noteId); diff --git a/src/routes/api/options.js b/src/routes/api/options.js index f3e294571..fd24422dc 100644 --- a/src/routes/api/options.js +++ b/src/routes/api/options.js @@ -1,6 +1,6 @@ "use strict"; -const optionService = require('../../services/options.js'); +const optionService = require('../../services/options'); const log = require('../../services/log'); const searchService = require('../../services/search/services/search.js'); const ValidationError = require('../../errors/validation_error'); diff --git a/src/routes/api/other.js b/src/routes/api/other.js index ca92e15c6..a05600a56 100644 --- a/src/routes/api/other.js +++ b/src/routes/api/other.js @@ -1,4 +1,4 @@ -const becca = require('../../becca/becca.js'); +const becca = require('../../becca/becca'); const markdownService = require('../../services/import/markdown.js'); function getIconUsage() { diff --git a/src/routes/api/recent_changes.js b/src/routes/api/recent_changes.js index 8563c41a8..6fea4a105 100644 --- a/src/routes/api/recent_changes.js +++ b/src/routes/api/recent_changes.js @@ -3,7 +3,7 @@ const sql = require('../../services/sql'); const protectedSessionService = require('../../services/protected_session'); const noteService = require('../../services/notes.js'); -const becca = require('../../becca/becca.js'); +const becca = require('../../becca/becca'); function getRecentChanges(req) { const {ancestorNoteId} = req.params; diff --git a/src/routes/api/relation-map.js b/src/routes/api/relation-map.js index dc89ab5bb..280ed7f67 100644 --- a/src/routes/api/relation-map.js +++ b/src/routes/api/relation-map.js @@ -1,4 +1,4 @@ -const becca = require('../../becca/becca.js'); +const becca = require('../../becca/becca'); const sql = require('../../services/sql'); function getRelationMap(req) { diff --git a/src/routes/api/revisions.js b/src/routes/api/revisions.js index 6a75f98ab..e4a843016 100644 --- a/src/routes/api/revisions.js +++ b/src/routes/api/revisions.js @@ -6,8 +6,8 @@ const utils = require('../../services/utils'); const sql = require('../../services/sql'); const cls = require('../../services/cls'); const path = require('path'); -const becca = require('../../becca/becca.js'); -const blobService = require('../../services/blob.js'); +const becca = require('../../becca/becca'); +const blobService = require('../../services/blob'); const eraseService = require("../../services/erase.js"); function getRevisionBlob(req) { diff --git a/src/routes/api/script.js b/src/routes/api/script.js index 441d67e54..0dbb72f2c 100644 --- a/src/routes/api/script.js +++ b/src/routes/api/script.js @@ -2,7 +2,7 @@ const scriptService = require('../../services/script.js'); const attributeService = require('../../services/attributes.js'); -const becca = require('../../becca/becca.js'); +const becca = require('../../becca/becca'); const syncService = require('../../services/sync.js'); const sql = require('../../services/sql'); diff --git a/src/routes/api/search.js b/src/routes/api/search.js index 0c2d486ed..b98e08517 100644 --- a/src/routes/api/search.js +++ b/src/routes/api/search.js @@ -1,6 +1,6 @@ "use strict"; -const becca = require('../../becca/becca.js'); +const becca = require('../../becca/becca'); const SearchContext = require('../../services/search/search_context.js'); const searchService = require('../../services/search/services/search.js'); const bulkActionService = require('../../services/bulk_actions.js'); diff --git a/src/routes/api/similar_notes.js b/src/routes/api/similar_notes.js index 781ba0efc..3dee1d0c1 100644 --- a/src/routes/api/similar_notes.js +++ b/src/routes/api/similar_notes.js @@ -1,7 +1,7 @@ "use strict"; const similarityService = require('../../becca/similarity.js'); -const becca = require('../../becca/becca.js'); +const becca = require('../../becca/becca'); async function getSimilarNotes(req) { const noteId = req.params.noteId; diff --git a/src/routes/api/special_notes.js b/src/routes/api/special_notes.js index 3c223f767..9c80f507f 100644 --- a/src/routes/api/special_notes.js +++ b/src/routes/api/special_notes.js @@ -4,7 +4,7 @@ const dateNoteService = require('../../services/date_notes.js'); const sql = require('../../services/sql'); const cls = require('../../services/cls'); const specialNotesService = require('../../services/special_notes.js'); -const becca = require('../../becca/becca.js'); +const becca = require('../../becca/becca'); function getInboxNote(req) { return specialNotesService.getInboxNote(req.params.date); diff --git a/src/routes/api/sql.js b/src/routes/api/sql.js index 65c381f8b..4e06ed78e 100644 --- a/src/routes/api/sql.js +++ b/src/routes/api/sql.js @@ -1,7 +1,7 @@ "use strict"; const sql = require('../../services/sql'); -const becca = require('../../becca/becca.js'); +const becca = require('../../becca/becca'); function getSchema() { const tableNames = sql.getColumn(`SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%' ORDER BY name`); diff --git a/src/routes/api/stats.js b/src/routes/api/stats.js index 4e1ad74fe..05d05d25c 100644 --- a/src/routes/api/stats.js +++ b/src/routes/api/stats.js @@ -1,5 +1,5 @@ const sql = require('../../services/sql'); -const becca = require('../../becca/becca.js'); +const becca = require('../../becca/becca'); function getNoteSize(req) { const {noteId} = req.params; diff --git a/src/routes/api/sync.js b/src/routes/api/sync.js index 5c6dbc799..aa65da91b 100644 --- a/src/routes/api/sync.js +++ b/src/routes/api/sync.js @@ -5,7 +5,7 @@ const syncUpdateService = require('../../services/sync_update.js'); const entityChangesService = require('../../services/entity_changes.js'); const sql = require('../../services/sql'); const sqlInit = require('../../services/sql_init.js'); -const optionService = require('../../services/options.js'); +const optionService = require('../../services/options'); const contentHashService = require('../../services/content_hash.js'); const log = require('../../services/log'); const syncOptions = require('../../services/sync_options.js'); diff --git a/src/routes/api/tree.js b/src/routes/api/tree.js index 50494fced..c8188068b 100644 --- a/src/routes/api/tree.js +++ b/src/routes/api/tree.js @@ -1,6 +1,6 @@ "use strict"; -const becca = require('../../becca/becca.js'); +const becca = require('../../becca/becca'); const log = require('../../services/log'); const NotFoundError = require('../../errors/not_found_error'); diff --git a/src/routes/custom.js b/src/routes/custom.js index 21fca8854..f566902f6 100644 --- a/src/routes/custom.js +++ b/src/routes/custom.js @@ -3,7 +3,7 @@ const fileService = require('./api/files.js'); const scriptService = require('../services/script.js'); const cls = require('../services/cls'); const sql = require('../services/sql'); -const becca = require('../becca/becca.js'); +const becca = require('../becca/becca'); function handleRequest(req, res) { // express puts content after first slash into 0 index element diff --git a/src/routes/index.js b/src/routes/index.js index 2a8a07759..f39c37852 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -3,7 +3,7 @@ const sql = require('../services/sql'); const attributeService = require('../services/attributes.js'); const config = require('../services/config.js'); -const optionService = require('../services/options.js'); +const optionService = require('../services/options'); const log = require('../services/log'); const env = require('../services/env.js'); const utils = require('../services/utils'); diff --git a/src/routes/login.js b/src/routes/login.js index 69b1ea433..83ab5f87b 100644 --- a/src/routes/login.js +++ b/src/routes/login.js @@ -1,7 +1,7 @@ "use strict"; const utils = require('../services/utils'); -const optionService = require('../services/options.js'); +const optionService = require('../services/options'); const myScryptService = require('../services/encryption/my_scrypt.js'); const log = require('../services/log'); const passwordService = require('../services/encryption/password.js'); diff --git a/src/services/attributes.js b/src/services/attributes.js index 02e0d53f4..a45a8ded3 100644 --- a/src/services/attributes.js +++ b/src/services/attributes.js @@ -2,7 +2,7 @@ const searchService = require('./search/services/search.js'); const sql = require('./sql'); -const becca = require('../becca/becca.js'); +const becca = require('../becca/becca'); const BAttribute = require('../becca/entities/battribute.js'); const {formatAttrForSearch} = require('./attribute_formatter.js'); const BUILTIN_ATTRIBUTES = require('./builtin_attributes.js'); diff --git a/src/services/backend_script_api.js b/src/services/backend_script_api.js index 7a6141586..4a0218d27 100644 --- a/src/services/backend_script_api.js +++ b/src/services/backend_script_api.js @@ -13,7 +13,7 @@ const cloningService = require('./cloning.js'); const appInfo = require('./app_info.js'); const searchService = require('./search/services/search.js'); const SearchContext = require('./search/search_context.js'); -const becca = require('../becca/becca.js'); +const becca = require('../becca/becca'); const ws = require('./ws.js'); const SpacedUpdate = require('./spaced_update.js'); const specialNotesService = require('./special_notes.js'); @@ -21,7 +21,7 @@ const branchService = require('./branches.js'); const exportService = require('./export/zip.js'); const syncMutex = require('./sync_mutex.js'); const backupService = require('./backup.js'); -const optionsService = require('./options.js'); +const optionsService = require('./options'); /** @@ -678,7 +678,7 @@ function BackendScriptApi(currentNote, apiParams) { /** * This object contains "at your risk" and "no BC guarantees" objects for advanced use cases. * - * @property {Becca} becca - provides access to the backend in-memory object graph, see {@link https://github.com/zadam/trilium/blob/master/src/becca/becca.js} + * @property {Becca} becca - provides access to the backend in-memory object graph, see {@link https://github.com/zadam/trilium/blob/master/src/becca/becca} */ this.__private = { becca diff --git a/src/services/backup.js b/src/services/backup.js index 772d92d55..54decedcb 100644 --- a/src/services/backup.js +++ b/src/services/backup.js @@ -1,7 +1,7 @@ "use strict"; const dateUtils = require('./date_utils'); -const optionService = require('./options.js'); +const optionService = require('./options'); const fs = require('fs-extra'); const dataDir = require('./data_dir'); const log = require('./log'); diff --git a/src/services/blob.ts b/src/services/blob.ts index 39b979fee..cfdd939c6 100644 --- a/src/services/blob.ts +++ b/src/services/blob.ts @@ -1,4 +1,4 @@ -import becca = require('../becca/becca.js'); +import becca = require('../becca/becca'); import NotFoundError = require('../errors/not_found_error'); import protectedSessionService = require('./protected_session'); import utils = require('./utils'); diff --git a/src/services/bulk_actions.js b/src/services/bulk_actions.js index 3536ed9a9..3a274c688 100644 --- a/src/services/bulk_actions.js +++ b/src/services/bulk_actions.js @@ -1,6 +1,6 @@ const log = require('./log'); const revisionService = require('./revisions.js'); -const becca = require('../becca/becca.js'); +const becca = require('../becca/becca'); const cloningService = require('./cloning.js'); const branchService = require('./branches.js'); const utils = require('./utils'); diff --git a/src/services/cloning.js b/src/services/cloning.js index a715dd3a1..b942867ab 100644 --- a/src/services/cloning.js +++ b/src/services/cloning.js @@ -1,10 +1,10 @@ "use strict"; const sql = require('./sql'); -const eventChangesService = require('./entity_changes.js'); +const eventChangesService = require('./entity_changes'); const treeService = require('./tree.js'); const BBranch = require('../becca/entities/bbranch.js'); -const becca = require('../becca/becca.js'); +const becca = require('../becca/becca'); const log = require('./log'); function cloneNoteToParentNote(noteId, parentNoteId, prefix = null) { diff --git a/src/services/cls.ts b/src/services/cls.ts index 5bbffaa84..d119c8a93 100644 --- a/src/services/cls.ts +++ b/src/services/cls.ts @@ -1,5 +1,5 @@ import clsHooked = require('cls-hooked'); -import type entity_changes = require('./entity_changes'); +import { EntityChange } from './entity_changes_interface'; const namespace = clsHooked.createNamespace("trilium"); type Callback = (...args: any[]) => any; @@ -75,7 +75,7 @@ function getAndClearEntityChangeIds() { return entityChangeIds; } -function putEntityChange(entityChange: entity_changes.EntityChange) { +function putEntityChange(entityChange: EntityChange) { if (namespace.get('ignoreEntityChangeIds')) { return; } diff --git a/src/services/consistency_checks.js b/src/services/consistency_checks.js index 1b0990328..9e9585d19 100644 --- a/src/services/consistency_checks.js +++ b/src/services/consistency_checks.js @@ -6,11 +6,11 @@ const log = require('./log'); const ws = require('./ws.js'); const syncMutexService = require('./sync_mutex.js'); const cls = require('./cls'); -const entityChangesService = require('./entity_changes.js'); -const optionsService = require('./options.js'); +const entityChangesService = require('./entity_changes'); +const optionsService = require('./options'); const BBranch = require('../becca/entities/bbranch.js'); const revisionService = require('./revisions.js'); -const becca = require('../becca/becca.js'); +const becca = require('../becca/becca'); const utils = require('../services/utils'); const eraseService = require('../services/erase.js'); const {sanitizeAttributeName} = require('./sanitize_attribute_name.js'); diff --git a/src/services/encryption/my_scrypt.ts b/src/services/encryption/my_scrypt.ts index 9c7774923..c80632bc0 100644 --- a/src/services/encryption/my_scrypt.ts +++ b/src/services/encryption/my_scrypt.ts @@ -1,6 +1,6 @@ "use strict"; -import optionService = require('../options.js'); +import optionService = require('../options'); import crypto = require('crypto'); function getVerificationHash(password: crypto.BinaryLike) { diff --git a/src/services/encryption/password.ts b/src/services/encryption/password.ts index 07b4de85b..65c6c08c0 100644 --- a/src/services/encryption/password.ts +++ b/src/services/encryption/password.ts @@ -1,7 +1,7 @@ "use strict"; import sql = require('../sql'); -import optionService = require('../options.js'); +import optionService = require('../options'); import myScryptService = require('./my_scrypt.js'); import utils = require('../utils'); import passwordEncryptionService = require('./password_encryption.js'); diff --git a/src/services/encryption/password_encryption.ts b/src/services/encryption/password_encryption.ts index 939de5a9d..140ae152e 100644 --- a/src/services/encryption/password_encryption.ts +++ b/src/services/encryption/password_encryption.ts @@ -1,4 +1,4 @@ -import optionService = require('../options.js'); +import optionService = require('../options'); import myScryptService = require('./my_scrypt.js'); import utils = require('../utils'); import dataEncryptionService = require('./data_encryption.js'); diff --git a/src/services/entity_changes.ts b/src/services/entity_changes.ts index ff2754851..bc75432b0 100644 --- a/src/services/entity_changes.ts +++ b/src/services/entity_changes.ts @@ -4,8 +4,8 @@ import log = require('./log'); import cls = require('./cls'); import utils = require('./utils'); import instanceId = require('./instance_id'); -import becca = require('../becca/becca.js'); -import blobService = require('../services/blob.js'); +import becca = require('../becca/becca'); +import blobService = require('../services/blob'); import { EntityChange } from './entity_changes_interface'; import type { Blob } from "./blob-interface"; diff --git a/src/services/erase.js b/src/services/erase.js index 05719a480..4c225428b 100644 --- a/src/services/erase.js +++ b/src/services/erase.js @@ -1,8 +1,8 @@ const sql = require("./sql"); const revisionService = require("./revisions.js"); const log = require("./log.ts"); -const entityChangesService = require("./entity_changes.js"); -const optionService = require("./options.js"); +const entityChangesService = require("./entity_changes"); +const optionService = require("./options"); const dateUtils = require("./date_utils"); const sqlInit = require("./sql_init.js"); const cls = require("./cls"); diff --git a/src/services/etapi_tokens.js b/src/services/etapi_tokens.js index 552a31ade..06302ad71 100644 --- a/src/services/etapi_tokens.js +++ b/src/services/etapi_tokens.js @@ -1,4 +1,4 @@ -const becca = require('../becca/becca.js'); +const becca = require('../becca/becca'); const utils = require('./utils'); const BEtapiToken = require('../becca/entities/betapi_token.js'); const crypto = require("crypto"); diff --git a/src/services/export/opml.js b/src/services/export/opml.js index b58bb63c1..2faa6d513 100644 --- a/src/services/export/opml.js +++ b/src/services/export/opml.js @@ -1,7 +1,7 @@ "use strict"; const utils = require('../utils'); -const becca = require('../../becca/becca.js'); +const becca = require('../../becca/becca'); function exportToOpml(taskContext, branch, version, res) { if (!['1.0', '2.0'].includes(version)) { diff --git a/src/services/export/single.js b/src/services/export/single.js index 5fbe4ee44..5021ef3a3 100644 --- a/src/services/export/single.js +++ b/src/services/export/single.js @@ -4,7 +4,7 @@ const mimeTypes = require('mime-types'); const html = require('html'); const utils = require('../utils'); const mdService = require('./md.js'); -const becca = require('../../becca/becca.js'); +const becca = require('../../becca/becca'); function exportSingleNote(taskContext, branch, format, res) { const note = branch.getNote(); diff --git a/src/services/export/zip.js b/src/services/export/zip.js index dccf4bf2f..c5609e0d9 100644 --- a/src/services/export/zip.js +++ b/src/services/export/zip.js @@ -10,7 +10,7 @@ const utils = require('../utils'); const protectedSessionService = require('../protected_session'); const sanitize = require("sanitize-filename"); const fs = require("fs"); -const becca = require('../../becca/becca.js'); +const becca = require('../../becca/becca'); const RESOURCE_DIR = require('../../services/resource_dir').RESOURCE_DIR; const archiver = require('archiver'); const log = require('../log'); diff --git a/src/services/handlers.js b/src/services/handlers.js index d5a55fafe..ee04b42ae 100644 --- a/src/services/handlers.js +++ b/src/services/handlers.js @@ -2,7 +2,7 @@ const eventService = require('./events'); const scriptService = require('./script.js'); const treeService = require('./tree.js'); const noteService = require('./notes.js'); -const becca = require('../becca/becca.js'); +const becca = require('../becca/becca'); const BAttribute = require('../becca/entities/battribute.js'); const hiddenSubtreeService = require('./hidden_subtree.js'); const oneTimeTimer = require('./one_time_timer.js'); diff --git a/src/services/hidden_subtree.js b/src/services/hidden_subtree.js index 2e00a2461..0a82e61aa 100644 --- a/src/services/hidden_subtree.js +++ b/src/services/hidden_subtree.js @@ -1,4 +1,4 @@ -const becca = require('../becca/becca.js'); +const becca = require('../becca/becca'); const noteService = require('./notes.js'); const BAttribute = require('../becca/entities/battribute.js'); const log = require('./log'); diff --git a/src/services/hoisted_note.js b/src/services/hoisted_note.js index 8a3dae18f..a75d4addc 100644 --- a/src/services/hoisted_note.js +++ b/src/services/hoisted_note.js @@ -1,5 +1,5 @@ const cls = require('./cls'); -const becca = require('../becca/becca.js'); +const becca = require('../becca/becca'); function getHoistedNoteId() { return cls.getHoistedNoteId(); diff --git a/src/services/image.js b/src/services/image.js index ff9b5b9e9..04add20f8 100644 --- a/src/services/image.js +++ b/src/services/image.js @@ -1,10 +1,10 @@ "use strict"; -const becca = require('../becca/becca.js'); +const becca = require('../becca/becca'); const log = require('./log'); const protectedSessionService = require('./protected_session'); const noteService = require('./notes.js'); -const optionService = require('./options.js'); +const optionService = require('./options'); const sql = require('./sql'); const jimp = require('jimp'); const imageType = require('image-type'); diff --git a/src/services/import/zip.js b/src/services/import/zip.js index 17a760fdc..fd42ce3d6 100644 --- a/src/services/import/zip.js +++ b/src/services/import/zip.js @@ -12,7 +12,7 @@ const mimeService = require('./mime.js'); const treeService = require('../tree.js'); const yauzl = require("yauzl"); const htmlSanitizer = require('../html_sanitizer.js'); -const becca = require('../../becca/becca.js'); +const becca = require('../../becca/becca'); const BAttachment = require('../../becca/entities/battachment.js'); const markdownService = require('./markdown.js'); diff --git a/src/services/keyboard_actions.js b/src/services/keyboard_actions.js index df44994ff..6ad590f07 100644 --- a/src/services/keyboard_actions.js +++ b/src/services/keyboard_actions.js @@ -1,6 +1,6 @@ "use strict"; -const optionService = require('./options.js'); +const optionService = require('./options'); const log = require('./log'); const utils = require('./utils'); diff --git a/src/services/notes.js b/src/services/notes.js index 214975a95..251c665cf 100644 --- a/src/services/notes.js +++ b/src/services/notes.js @@ -1,7 +1,7 @@ const sql = require('./sql'); -const optionService = require('./options.js'); +const optionService = require('./options'); const dateUtils = require('./date_utils'); -const entityChangesService = require('./entity_changes.js'); +const entityChangesService = require('./entity_changes'); const eventService = require('./events'); const cls = require('../services/cls'); const protectedSessionService = require('../services/protected_session'); @@ -11,7 +11,7 @@ const revisionService = require('./revisions.js'); const request = require('./request.js'); const path = require('path'); const url = require('url'); -const becca = require('../becca/becca.js'); +const becca = require('../becca/becca'); const BBranch = require('../becca/entities/bbranch.js'); const BNote = require('../becca/entities/bnote.js'); const BAttribute = require('../becca/entities/battribute.js'); diff --git a/src/services/options_init.js b/src/services/options_init.js index 8da0de4bf..5e7ca2f10 100644 --- a/src/services/options_init.js +++ b/src/services/options_init.js @@ -1,4 +1,4 @@ -const optionService = require('./options.js'); +const optionService = require('./options'); const appInfo = require('./app_info.js'); const utils = require('./utils'); const log = require('./log'); diff --git a/src/services/protected_session.ts b/src/services/protected_session.ts index 19d15d542..1f0e382da 100644 --- a/src/services/protected_session.ts +++ b/src/services/protected_session.ts @@ -56,7 +56,7 @@ function touchProtectedSession() { } function checkProtectedSessionExpiration() { - const options = require('./options.js'); + const options = require('./options'); const protectedSessionTimeout = options.getOptionInt('protectedSessionTimeout'); if (isProtectedSessionAvailable() && lastProtectedSessionOperationDate diff --git a/src/services/script.js b/src/services/script.js index 93c89ccc3..f82f50444 100644 --- a/src/services/script.js +++ b/src/services/script.js @@ -1,7 +1,7 @@ const ScriptContext = require('./script_context.js'); const cls = require('./cls'); const log = require('./log'); -const becca = require('../becca/becca.js'); +const becca = require('../becca/becca'); function executeNote(note, apiParams) { if (!note.isJavaScript() || note.getScriptEnv() !== 'backend' || !note.isContentAvailable()) { diff --git a/src/services/search/expressions/ancestor.js b/src/services/search/expressions/ancestor.js index f7463a3ae..a3cc4bd54 100644 --- a/src/services/search/expressions/ancestor.js +++ b/src/services/search/expressions/ancestor.js @@ -3,7 +3,7 @@ const Expression = require('./expression.js'); const NoteSet = require('../note_set.js'); const log = require('../../log'); -const becca = require('../../../becca/becca.js'); +const becca = require('../../../becca/becca'); class AncestorExp extends Expression { constructor(ancestorNoteId, ancestorDepth) { diff --git a/src/services/search/expressions/attribute_exists.js b/src/services/search/expressions/attribute_exists.js index f9be65689..126f524f9 100644 --- a/src/services/search/expressions/attribute_exists.js +++ b/src/services/search/expressions/attribute_exists.js @@ -1,7 +1,7 @@ "use strict"; const NoteSet = require('../note_set.js'); -const becca = require('../../../becca/becca.js'); +const becca = require('../../../becca/becca'); const Expression = require('./expression.js'); class AttributeExistsExp extends Expression { diff --git a/src/services/search/expressions/descendant_of.js b/src/services/search/expressions/descendant_of.js index fa0e50dd3..d97dd6c62 100644 --- a/src/services/search/expressions/descendant_of.js +++ b/src/services/search/expressions/descendant_of.js @@ -2,7 +2,7 @@ const Expression = require('./expression.js'); const NoteSet = require('../note_set.js'); -const becca = require('../../../becca/becca.js'); +const becca = require('../../../becca/becca'); class DescendantOfExp extends Expression { constructor(subExpression) { diff --git a/src/services/search/expressions/label_comparison.js b/src/services/search/expressions/label_comparison.js index 0bc27ff0c..01fe1396a 100644 --- a/src/services/search/expressions/label_comparison.js +++ b/src/services/search/expressions/label_comparison.js @@ -2,7 +2,7 @@ const Expression = require('./expression.js'); const NoteSet = require('../note_set.js'); -const becca = require('../../../becca/becca.js'); +const becca = require('../../../becca/becca'); class LabelComparisonExp extends Expression { constructor(attributeType, attributeName, comparator) { diff --git a/src/services/search/expressions/note_content_fulltext.js b/src/services/search/expressions/note_content_fulltext.js index 351d43717..0d447b7ed 100644 --- a/src/services/search/expressions/note_content_fulltext.js +++ b/src/services/search/expressions/note_content_fulltext.js @@ -3,7 +3,7 @@ const Expression = require('./expression.js'); const NoteSet = require('../note_set.js'); const log = require('../../log'); -const becca = require('../../../becca/becca.js'); +const becca = require('../../../becca/becca'); const protectedSessionService = require('../../protected_session'); const striptags = require('striptags'); const utils = require('../../utils'); diff --git a/src/services/search/expressions/note_flat_text.js b/src/services/search/expressions/note_flat_text.js index 72f06cb98..f92c1808e 100644 --- a/src/services/search/expressions/note_flat_text.js +++ b/src/services/search/expressions/note_flat_text.js @@ -2,7 +2,7 @@ const Expression = require('./expression.js'); const NoteSet = require('../note_set.js'); -const becca = require('../../../becca/becca.js'); +const becca = require('../../../becca/becca'); const utils = require('../../utils'); class NoteFlatTextExp extends Expression { diff --git a/src/services/search/expressions/relation_where.js b/src/services/search/expressions/relation_where.js index dee56b1dd..fcd0bc85c 100644 --- a/src/services/search/expressions/relation_where.js +++ b/src/services/search/expressions/relation_where.js @@ -2,7 +2,7 @@ const Expression = require('./expression.js'); const NoteSet = require('../note_set.js'); -const becca = require('../../../becca/becca.js'); +const becca = require('../../../becca/becca'); class RelationWhereExp extends Expression { constructor(relationName, subExpression) { diff --git a/src/services/search/search_result.js b/src/services/search/search_result.js index 3a094bc8c..61f7d86d8 100644 --- a/src/services/search/search_result.js +++ b/src/services/search/search_result.js @@ -1,7 +1,7 @@ "use strict"; const beccaService = require('../../becca/becca_service.js'); -const becca = require('../../becca/becca.js'); +const becca = require('../../becca/becca'); class SearchResult { constructor(notePathArray) { diff --git a/src/services/search/services/search.js b/src/services/search/services/search.js index f6b309ad3..498d31310 100644 --- a/src/services/search/services/search.js +++ b/src/services/search/services/search.js @@ -6,7 +6,7 @@ const handleParens = require('./handle_parens.js'); const parse = require('./parse.js'); const SearchResult = require('../search_result.js'); const SearchContext = require('../search_context.js'); -const becca = require('../../../becca/becca.js'); +const becca = require('../../../becca/becca'); const beccaService = require('../../../becca/becca_service.js'); const utils = require('../../utils'); const log = require('../../log'); diff --git a/src/services/setup.js b/src/services/setup.js index 58736f5b8..7434659be 100644 --- a/src/services/setup.js +++ b/src/services/setup.js @@ -1,12 +1,12 @@ const syncService = require('./sync.js'); const log = require('./log'); const sqlInit = require('./sql_init.js'); -const optionService = require('./options.js'); +const optionService = require('./options'); const syncOptions = require('./sync_options.js'); const request = require('./request.js'); const appInfo = require('./app_info.js'); const utils = require('./utils'); -const becca = require('../becca/becca.js'); +const becca = require('../becca/becca'); async function hasSyncServerSchemaAndSeed() { const response = await requestToSyncServer('GET', '/api/setup/status'); diff --git a/src/services/special_notes.js b/src/services/special_notes.js index e57059987..fd229a876 100644 --- a/src/services/special_notes.js +++ b/src/services/special_notes.js @@ -1,6 +1,6 @@ const attributeService = require('./attributes.js'); const dateNoteService = require('./date_notes.js'); -const becca = require('../becca/becca.js'); +const becca = require('../becca/becca'); const noteService = require('./notes.js'); const dateUtils = require('./date_utils'); const log = require('./log'); diff --git a/src/services/sql.ts b/src/services/sql.ts index 2b93ce263..6de5003b4 100644 --- a/src/services/sql.ts +++ b/src/services/sql.ts @@ -263,7 +263,7 @@ function transactional(func: (statement: Statement) => T) { } // the maxEntityChangeId has been incremented during failed transaction, need to recalculate - require('./entity_changes.js').recalculateMaxEntityChangeId(); + require('./entity_changes').recalculateMaxEntityChangeId(); throw e; } diff --git a/src/services/sql_init.js b/src/services/sql_init.js index 4b89ae389..c200ba58a 100644 --- a/src/services/sql_init.js +++ b/src/services/sql_init.js @@ -3,7 +3,7 @@ const fs = require('fs'); const resourceDir = require('./resource_dir'); const sql = require('./sql'); const utils = require('./utils'); -const optionService = require('./options.js'); +const optionService = require('./options'); const port = require('./port.js'); const BOption = require('../becca/entities/boption.js'); const TaskContext = require('./task_context.js'); @@ -105,7 +105,7 @@ async function createInitialDatabase() { const startNoteId = sql.getValue("SELECT noteId FROM branches WHERE parentNoteId = 'root' AND isDeleted = 0 ORDER BY notePosition"); - const optionService = require('./options.js'); + const optionService = require('./options'); optionService.setOption('openNoteContexts', JSON.stringify([ { notePath: startNoteId, diff --git a/src/services/sync.js b/src/services/sync.js index bce751b5b..856101703 100644 --- a/src/services/sync.js +++ b/src/services/sync.js @@ -2,7 +2,7 @@ const log = require('./log'); const sql = require('./sql'); -const optionService = require('./options.js'); +const optionService = require('./options'); const utils = require('./utils'); const instanceId = require('./instance_id'); const dateUtils = require('./date_utils'); @@ -14,9 +14,9 @@ const syncMutexService = require('./sync_mutex.js'); const cls = require('./cls'); const request = require('./request.js'); const ws = require('./ws.js'); -const entityChangesService = require('./entity_changes.js'); +const entityChangesService = require('./entity_changes'); const entityConstructor = require('../becca/entity_constructor.js'); -const becca = require('../becca/becca.js'); +const becca = require('../becca/becca'); let proxyToggle = true; diff --git a/src/services/sync_options.js b/src/services/sync_options.js index 7cf44c06f..8f8038849 100644 --- a/src/services/sync_options.js +++ b/src/services/sync_options.js @@ -1,6 +1,6 @@ "use strict"; -const optionService = require('./options.js'); +const optionService = require('./options'); const config = require('./config.js'); /* diff --git a/src/services/sync_update.js b/src/services/sync_update.js index 6581066f4..96922c450 100644 --- a/src/services/sync_update.js +++ b/src/services/sync_update.js @@ -1,6 +1,6 @@ const sql = require('./sql'); const log = require('./log'); -const entityChangesService = require('./entity_changes.js'); +const entityChangesService = require('./entity_changes'); const eventService = require('./events'); const entityConstructor = require('../becca/entity_constructor.js'); const ws = require('./ws.js'); diff --git a/src/services/tray.js b/src/services/tray.js index bb32a78bb..7d8e34e1e 100644 --- a/src/services/tray.js +++ b/src/services/tray.js @@ -1,7 +1,7 @@ const { Menu, Tray } = require('electron'); const path = require('path'); const windowService = require('./window.js'); -const optionService = require('./options.js'); +const optionService = require('./options'); const UPDATE_TRAY_EVENTS = [ 'minimize', 'maximize', 'show', 'hide' diff --git a/src/services/tree.js b/src/services/tree.js index 7bbca25ab..bd90b784b 100644 --- a/src/services/tree.js +++ b/src/services/tree.js @@ -3,8 +3,8 @@ const sql = require('./sql'); const log = require('./log'); const BBranch = require('../becca/entities/bbranch.js'); -const entityChangesService = require('./entity_changes.js'); -const becca = require('../becca/becca.js'); +const entityChangesService = require('./entity_changes'); +const becca = require('../becca/becca'); function validateParentChild(parentNoteId, childNoteId, branchId = null) { if (['root', '_hidden', '_share', '_lbRoot', '_lbAvailableLaunchers', '_lbVisibleLaunchers'].includes(childNoteId)) { diff --git a/src/services/window.js b/src/services/window.js index 587dda8a4..ef26ede5c 100644 --- a/src/services/window.js +++ b/src/services/window.js @@ -1,7 +1,7 @@ const path = require('path'); const url = require("url"); const port = require('./port.js'); -const optionService = require('./options.js'); +const optionService = require('./options'); const env = require('./env.js'); const log = require('./log'); const sqlInit = require('./sql_init.js'); diff --git a/src/services/ws.ts b/src/services/ws.ts index 086bb0d4f..64e7707c2 100644 --- a/src/services/ws.ts +++ b/src/services/ws.ts @@ -6,7 +6,7 @@ import cls = require('./cls'); import config = require('./config'); import syncMutexService = require('./sync_mutex.js'); import protectedSessionService = require('./protected_session'); -import becca = require('../becca/becca.js'); +import becca = require('../becca/becca'); import AbstractBeccaEntity = require('../becca/entities/abstract_becca_entity.js'); import env = require('./env'); From 030aec2f3ee35ba93c0ed0647815f358ee8f1c2e Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 17 Feb 2024 11:43:30 +0200 Subject: [PATCH 37/49] server-ts: Fix more references to js files for converted files --- src/etapi/branches.js | 2 +- src/etapi/etapi_utils.js | 2 +- src/routes/index.js | 2 +- src/services/app_icon.js | 2 +- src/services/auth.js | 2 +- src/services/backend_script_api.js | 2 +- src/services/cloning.js | 2 +- src/services/consistency_checks.js | 2 +- src/services/host.js | 2 +- src/services/import/zip.js | 2 +- src/services/notes.js | 2 +- src/services/port.js | 2 +- src/services/scheduler.js | 2 +- src/services/sql_init.js | 4 ++-- src/services/sync_options.js | 2 +- src/services/tree.js | 2 +- 16 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/etapi/branches.js b/src/etapi/branches.js index 2206d2224..6d0fa772c 100644 --- a/src/etapi/branches.js +++ b/src/etapi/branches.js @@ -1,7 +1,7 @@ const becca = require('../becca/becca'); const eu = require('./etapi_utils'); const mappers = require('./mappers.js'); -const BBranch = require('../becca/entities/bbranch.js'); +const BBranch = require('../becca/entities/bbranch'); const entityChangesService = require('../services/entity_changes.js'); const v = require('./validators.js'); diff --git a/src/etapi/etapi_utils.js b/src/etapi/etapi_utils.js index 5fe5459fb..0ec013b20 100644 --- a/src/etapi/etapi_utils.js +++ b/src/etapi/etapi_utils.js @@ -3,7 +3,7 @@ const sql = require('../services/sql'); const log = require('../services/log'); const becca = require('../becca/becca'); const etapiTokenService = require('../services/etapi_tokens.js'); -const config = require('../services/config.js'); +const config = require('../services/config'); const GENERIC_CODE = "GENERIC"; const noAuthentication = config.General && config.General.noAuthentication === true; diff --git a/src/routes/index.js b/src/routes/index.js index f39c37852..a7bf71e9f 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -2,7 +2,7 @@ const sql = require('../services/sql'); const attributeService = require('../services/attributes.js'); -const config = require('../services/config.js'); +const config = require('../services/config'); const optionService = require('../services/options'); const log = require('../services/log'); const env = require('../services/env.js'); diff --git a/src/services/app_icon.js b/src/services/app_icon.js index ec18dab45..bc845ab8c 100644 --- a/src/services/app_icon.js +++ b/src/services/app_icon.js @@ -5,7 +5,7 @@ const {ELECTRON_APP_ROOT_DIR} = require('./resource_dir'); const log = require('./log'); const os = require('os'); const fs = require('fs'); -const config = require('./config.js'); +const config = require('./config'); const utils = require('./utils'); const template = `[Desktop Entry] diff --git a/src/services/auth.js b/src/services/auth.js index 8db06bc07..d1a928ac2 100644 --- a/src/services/auth.js +++ b/src/services/auth.js @@ -5,7 +5,7 @@ const log = require('./log'); const sqlInit = require('./sql_init.js'); const utils = require('./utils'); const passwordEncryptionService = require('./encryption/password_encryption.js'); -const config = require('./config.js'); +const config = require('./config'); const passwordService = require('./encryption/password.js'); const noAuthentication = config.General && config.General.noAuthentication === true; diff --git a/src/services/backend_script_api.js b/src/services/backend_script_api.js index 4a0218d27..58d6613dd 100644 --- a/src/services/backend_script_api.js +++ b/src/services/backend_script_api.js @@ -5,7 +5,7 @@ const utils = require('./utils'); const attributeService = require('./attributes.js'); const dateNoteService = require('./date_notes.js'); const treeService = require('./tree.js'); -const config = require('./config.js'); +const config = require('./config'); const axios = require('axios'); const dayjs = require('dayjs'); const xml2js = require('xml2js'); diff --git a/src/services/cloning.js b/src/services/cloning.js index b942867ab..a42df4ba8 100644 --- a/src/services/cloning.js +++ b/src/services/cloning.js @@ -3,7 +3,7 @@ const sql = require('./sql'); const eventChangesService = require('./entity_changes'); const treeService = require('./tree.js'); -const BBranch = require('../becca/entities/bbranch.js'); +const BBranch = require('../becca/entities/bbranch'); const becca = require('../becca/becca'); const log = require('./log'); diff --git a/src/services/consistency_checks.js b/src/services/consistency_checks.js index 9e9585d19..e5ceb594f 100644 --- a/src/services/consistency_checks.js +++ b/src/services/consistency_checks.js @@ -8,7 +8,7 @@ const syncMutexService = require('./sync_mutex.js'); const cls = require('./cls'); const entityChangesService = require('./entity_changes'); const optionsService = require('./options'); -const BBranch = require('../becca/entities/bbranch.js'); +const BBranch = require('../becca/entities/bbranch'); const revisionService = require('./revisions.js'); const becca = require('../becca/becca'); const utils = require('../services/utils'); diff --git a/src/services/host.js b/src/services/host.js index 2430d45c2..389203e99 100644 --- a/src/services/host.js +++ b/src/services/host.js @@ -1,3 +1,3 @@ -const config = require('./config.js'); +const config = require('./config'); module.exports = process.env.TRILIUM_HOST || config['Network']['host'] || '0.0.0.0'; diff --git a/src/services/import/zip.js b/src/services/import/zip.js index fd42ce3d6..69cbdd4bf 100644 --- a/src/services/import/zip.js +++ b/src/services/import/zip.js @@ -5,7 +5,7 @@ const utils = require('../../services/utils'); const log = require('../../services/log'); const noteService = require('../../services/notes.js'); const attributeService = require('../../services/attributes.js'); -const BBranch = require('../../becca/entities/bbranch.js'); +const BBranch = require('../../becca/entities/bbranch'); const path = require('path'); const protectedSessionService = require('../protected_session'); const mimeService = require('./mime.js'); diff --git a/src/services/notes.js b/src/services/notes.js index 251c665cf..fa513854c 100644 --- a/src/services/notes.js +++ b/src/services/notes.js @@ -12,7 +12,7 @@ const request = require('./request.js'); const path = require('path'); const url = require('url'); const becca = require('../becca/becca'); -const BBranch = require('../becca/entities/bbranch.js'); +const BBranch = require('../becca/entities/bbranch'); const BNote = require('../becca/entities/bnote.js'); const BAttribute = require('../becca/entities/battribute.js'); const BAttachment = require('../becca/entities/battachment.js'); diff --git a/src/services/port.js b/src/services/port.js index b34490648..cec3be8d6 100644 --- a/src/services/port.js +++ b/src/services/port.js @@ -1,4 +1,4 @@ -const config = require('./config.js'); +const config = require('./config'); const utils = require('./utils'); const env = require('./env.js'); const dataDir = require('./data_dir'); diff --git a/src/services/scheduler.js b/src/services/scheduler.js index 907fc1ec5..2a712a1ce 100644 --- a/src/services/scheduler.js +++ b/src/services/scheduler.js @@ -1,7 +1,7 @@ const scriptService = require('./script.js'); const cls = require('./cls'); const sqlInit = require('./sql_init.js'); -const config = require('./config.js'); +const config = require('./config'); const log = require('./log'); const attributeService = require('../services/attributes.js'); const protectedSessionService = require('../services/protected_session'); diff --git a/src/services/sql_init.js b/src/services/sql_init.js index c200ba58a..49a101cf6 100644 --- a/src/services/sql_init.js +++ b/src/services/sql_init.js @@ -9,7 +9,7 @@ const BOption = require('../becca/entities/boption.js'); const TaskContext = require('./task_context.js'); const migrationService = require('./migration.js'); const cls = require('./cls'); -const config = require('./config.js'); +const config = require('./config'); const dbReady = utils.deferred(); @@ -63,7 +63,7 @@ async function createInitialDatabase() { require('../becca/becca_loader.js').load(); const BNote = require('../becca/entities/bnote.js'); - const BBranch = require('../becca/entities/bbranch.js'); + const BBranch = require('../becca/entities/bbranch'); log.info("Creating root note ..."); diff --git a/src/services/sync_options.js b/src/services/sync_options.js index 8f8038849..a059be973 100644 --- a/src/services/sync_options.js +++ b/src/services/sync_options.js @@ -1,7 +1,7 @@ "use strict"; const optionService = require('./options'); -const config = require('./config.js'); +const config = require('./config'); /* * Primary configuration for sync is in the options (document), but we allow to override diff --git a/src/services/tree.js b/src/services/tree.js index bd90b784b..66276ab2f 100644 --- a/src/services/tree.js +++ b/src/services/tree.js @@ -2,7 +2,7 @@ const sql = require('./sql'); const log = require('./log'); -const BBranch = require('../becca/entities/bbranch.js'); +const BBranch = require('../becca/entities/bbranch'); const entityChangesService = require('./entity_changes'); const becca = require('../becca/becca'); From 4df599fec2e2d95b271d89afbc98a113438d0703 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 17 Feb 2024 11:54:41 +0200 Subject: [PATCH 38/49] server-ts: Fix some build errors --- src/becca/entities/battachment.ts | 7 ++++--- src/services/entity_changes_interface.ts | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/becca/entities/battachment.ts b/src/becca/entities/battachment.ts index 0d301494e..84f7de5c1 100644 --- a/src/becca/entities/battachment.ts +++ b/src/becca/entities/battachment.ts @@ -96,7 +96,7 @@ class BAttachment extends AbstractBeccaEntity { /** @returns true if the note has string content (not binary) */ hasStringContent(): boolean { - return utils.isStringNote(this.type, this.mime); + return this.type !== undefined && utils.isStringNote(this.type, this.mime); } isContentAvailable() { @@ -135,7 +135,8 @@ class BAttachment extends AbstractBeccaEntity { } convertToNote(): { note: BNote, branch: BBranch } { - if (this.type === 'search') { + // FIXME: can this ever be "search"? + if (this.type as string === 'search') { throw new Error(`Note of type search cannot have child notes`); } @@ -157,7 +158,7 @@ class BAttachment extends AbstractBeccaEntity { const { note, branch } = noteService.createNewNote({ parentNoteId: this.ownerId, title: this.title, - type: attachmentRoleToNoteTypeMapping[this.role], + type: (attachmentRoleToNoteTypeMapping as any)[this.role], mime: this.mime, content: this.getContent(), isProtected: this.isProtected diff --git a/src/services/entity_changes_interface.ts b/src/services/entity_changes_interface.ts index f0a583e95..745a8a8fa 100644 --- a/src/services/entity_changes_interface.ts +++ b/src/services/entity_changes_interface.ts @@ -4,7 +4,7 @@ export interface EntityChange { entityName: string; entityId: string; entity?: any; - positions?: Record; + positions?: Record; hash: string; utcDateChanged?: string; isSynced: boolean | 1 | 0; From 45a6c9558fb2e44f12faf87cf0610e7e3da5af0f Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 17 Feb 2024 11:54:55 +0200 Subject: [PATCH 39/49] server-ts: Fix references to js files for converted files --- src/becca/entities/bblob.ts | 2 +- src/becca/entities/bnote.ts | 3 ++- src/etapi/auth.js | 2 +- src/etapi/branches.js | 2 +- src/etapi/notes.js | 2 +- src/routes/api/attributes.js | 2 +- src/routes/api/branches.js | 4 ++-- src/routes/api/clipper.js | 2 +- src/routes/api/export.js | 2 +- src/routes/api/files.js | 2 +- src/routes/api/import.js | 2 +- src/routes/api/login.js | 4 ++-- src/routes/api/notes.js | 2 +- src/routes/api/password.js | 2 +- src/routes/api/recent_notes.js | 2 +- src/routes/api/sender.js | 2 +- src/routes/api/sync.js | 4 ++-- src/routes/assets.js | 2 +- src/routes/index.js | 2 +- src/routes/login.js | 4 ++-- src/routes/routes.js | 6 +++--- src/services/app_path.js | 2 +- src/services/attributes.js | 2 +- src/services/auth.js | 4 ++-- src/services/backend_script_api.js | 4 ++-- src/services/backup.js | 2 +- src/services/consistency_checks.js | 6 +++--- src/services/encryption/password.ts | 4 ++-- src/services/encryption/password_encryption.ts | 4 ++-- src/services/etapi_tokens.js | 2 +- src/services/export/zip.js | 2 +- src/services/handlers.js | 2 +- src/services/hidden_subtree.js | 2 +- src/services/import/enex.js | 2 +- src/services/import/zip.js | 4 ++-- src/services/notes.js | 8 ++++---- src/services/port.js | 2 +- src/services/protected_session.ts | 2 +- src/services/search/expressions/ancestor.js | 2 +- src/services/search/expressions/attribute_exists.js | 2 +- src/services/search/expressions/child_of.js | 2 +- src/services/search/expressions/descendant_of.js | 2 +- src/services/search/expressions/is_hidden.js | 2 +- src/services/search/expressions/label_comparison.js | 2 +- src/services/search/expressions/note_content_fulltext.js | 2 +- src/services/search/expressions/note_flat_text.js | 2 +- src/services/search/expressions/or.js | 2 +- src/services/search/expressions/order_by_and_limit.js | 2 +- src/services/search/expressions/parent_of.js | 2 +- src/services/search/expressions/property_comparison.js | 2 +- src/services/search/expressions/relation_where.js | 2 +- src/services/sql.ts | 2 +- src/services/sql_init.js | 8 ++++---- src/services/sync.js | 4 ++-- src/services/sync_update.js | 2 +- src/services/task_context.ts | 2 +- src/services/window.js | 2 +- src/services/ws.ts | 8 +++++--- 58 files changed, 83 insertions(+), 80 deletions(-) diff --git a/src/becca/entities/bblob.ts b/src/becca/entities/bblob.ts index 27d559515..c37a20581 100644 --- a/src/becca/entities/bblob.ts +++ b/src/becca/entities/bblob.ts @@ -23,7 +23,7 @@ class BBlob { getPojo() { return { blobId: this.blobId, - content: this.content, + content: this.content || null, contentLength: this.contentLength, dateModified: this.dateModified, utcDateModified: this.utcDateModified diff --git a/src/becca/entities/bnote.ts b/src/becca/entities/bnote.ts index a6ae85284..26214e608 100644 --- a/src/becca/entities/bnote.ts +++ b/src/becca/entities/bnote.ts @@ -204,7 +204,8 @@ class BNote extends AbstractBeccaEntity { } getChildBranches(): (BBranch | null)[] { - return this.children.map(childNote => this.becca.getBranchFromChildAndParent(childNote.noteId, this.noteId)); + return this.children + .map(childNote => this.becca.getBranchFromChildAndParent(childNote.noteId, this.noteId)); } /* diff --git a/src/etapi/auth.js b/src/etapi/auth.js index cdb8d5f79..835d016a1 100644 --- a/src/etapi/auth.js +++ b/src/etapi/auth.js @@ -1,6 +1,6 @@ const becca = require('../becca/becca'); const eu = require('./etapi_utils'); -const passwordEncryptionService = require('../services/encryption/password_encryption.js'); +const passwordEncryptionService = require('../services/encryption/password_encryption'); const etapiTokenService = require('../services/etapi_tokens.js'); function register(router, loginMiddleware) { diff --git a/src/etapi/branches.js b/src/etapi/branches.js index 6d0fa772c..e0337e5cb 100644 --- a/src/etapi/branches.js +++ b/src/etapi/branches.js @@ -2,7 +2,7 @@ const becca = require('../becca/becca'); const eu = require('./etapi_utils'); const mappers = require('./mappers.js'); const BBranch = require('../becca/entities/bbranch'); -const entityChangesService = require('../services/entity_changes.js'); +const entityChangesService = require('../services/entity_changes'); const v = require('./validators.js'); function register(router) { diff --git a/src/etapi/notes.js b/src/etapi/notes.js index 0878f9d77..76318a89d 100644 --- a/src/etapi/notes.js +++ b/src/etapi/notes.js @@ -3,7 +3,7 @@ const utils = require('../services/utils'); const eu = require('./etapi_utils'); const mappers = require('./mappers.js'); const noteService = require('../services/notes.js'); -const TaskContext = require('../services/task_context.js'); +const TaskContext = require('../services/task_context'); const v = require('./validators.js'); const searchService = require('../services/search/services/search.js'); const SearchContext = require('../services/search/search_context.js'); diff --git a/src/routes/api/attributes.js b/src/routes/api/attributes.js index 0471fc298..de906a225 100644 --- a/src/routes/api/attributes.js +++ b/src/routes/api/attributes.js @@ -3,7 +3,7 @@ const sql = require('../../services/sql'); const log = require('../../services/log'); const attributeService = require('../../services/attributes.js'); -const BAttribute = require('../../becca/entities/battribute.js'); +const BAttribute = require('../../becca/entities/battribute'); const becca = require('../../becca/becca'); const ValidationError = require('../../errors/validation_error'); diff --git a/src/routes/api/branches.js b/src/routes/api/branches.js index 06c81cd38..cbc951f1e 100644 --- a/src/routes/api/branches.js +++ b/src/routes/api/branches.js @@ -2,11 +2,11 @@ const sql = require('../../services/sql'); const utils = require('../../services/utils'); -const entityChangesService = require('../../services/entity_changes.js'); +const entityChangesService = require('../../services/entity_changes'); const treeService = require('../../services/tree.js'); const eraseService = require('../../services/erase.js'); const becca = require('../../becca/becca'); -const TaskContext = require('../../services/task_context.js'); +const TaskContext = require('../../services/task_context'); const branchService = require('../../services/branches.js'); const log = require('../../services/log'); const ValidationError = require('../../errors/validation_error'); diff --git a/src/routes/api/clipper.js b/src/routes/api/clipper.js index 3992bbeda..ea4fb64c3 100644 --- a/src/routes/api/clipper.js +++ b/src/routes/api/clipper.js @@ -7,7 +7,7 @@ const dateNoteService = require('../../services/date_notes.js'); const dateUtils = require('../../services/date_utils'); const imageService = require('../../services/image.js'); const appInfo = require('../../services/app_info.js'); -const ws = require('../../services/ws.js'); +const ws = require('../../services/ws'); const log = require('../../services/log'); const utils = require('../../services/utils'); const path = require('path'); diff --git a/src/routes/api/export.js b/src/routes/api/export.js index 3ceaaa857..440eecb8d 100644 --- a/src/routes/api/export.js +++ b/src/routes/api/export.js @@ -4,7 +4,7 @@ const zipExportService = require('../../services/export/zip.js'); const singleExportService = require('../../services/export/single.js'); const opmlExportService = require('../../services/export/opml.js'); const becca = require('../../becca/becca'); -const TaskContext = require('../../services/task_context.js'); +const TaskContext = require('../../services/task_context'); const log = require('../../services/log'); const NotFoundError = require('../../errors/not_found_error'); diff --git a/src/routes/api/files.js b/src/routes/api/files.js index 78fa9f5db..5e0c391d6 100644 --- a/src/routes/api/files.js +++ b/src/routes/api/files.js @@ -8,7 +8,7 @@ const tmp = require('tmp'); const fs = require('fs'); const { Readable } = require('stream'); const chokidar = require('chokidar'); -const ws = require('../../services/ws.js'); +const ws = require('../../services/ws'); const becca = require('../../becca/becca'); const ValidationError = require('../../errors/validation_error'); diff --git a/src/routes/api/import.js b/src/routes/api/import.js index f3fd9e28c..115546cae 100644 --- a/src/routes/api/import.js +++ b/src/routes/api/import.js @@ -9,7 +9,7 @@ const path = require('path'); const becca = require('../../becca/becca'); const beccaLoader = require('../../becca/becca_loader.js'); const log = require('../../services/log'); -const TaskContext = require('../../services/task_context.js'); +const TaskContext = require('../../services/task_context'); const ValidationError = require('../../errors/validation_error'); async function importNotesToBranch(req) { diff --git a/src/routes/api/login.js b/src/routes/api/login.js index 30dc68189..7a5ff5a04 100644 --- a/src/routes/api/login.js +++ b/src/routes/api/login.js @@ -4,13 +4,13 @@ const options = require('../../services/options'); const utils = require('../../services/utils'); const dateUtils = require('../../services/date_utils'); const instanceId = require('../../services/instance_id'); -const passwordEncryptionService = require('../../services/encryption/password_encryption.js'); +const passwordEncryptionService = require('../../services/encryption/password_encryption'); const protectedSessionService = require('../../services/protected_session'); const appInfo = require('../../services/app_info.js'); const eventService = require('../../services/events'); const sqlInit = require('../../services/sql_init.js'); const sql = require('../../services/sql'); -const ws = require('../../services/ws.js'); +const ws = require('../../services/ws'); const etapiTokenService = require('../../services/etapi_tokens.js'); function loginSync(req) { diff --git a/src/routes/api/notes.js b/src/routes/api/notes.js index 810659b72..467a089f7 100644 --- a/src/routes/api/notes.js +++ b/src/routes/api/notes.js @@ -6,7 +6,7 @@ const treeService = require('../../services/tree.js'); const sql = require('../../services/sql'); const utils = require('../../services/utils'); const log = require('../../services/log'); -const TaskContext = require('../../services/task_context.js'); +const TaskContext = require('../../services/task_context'); const becca = require('../../becca/becca'); const ValidationError = require('../../errors/validation_error'); const blobService = require('../../services/blob'); diff --git a/src/routes/api/password.js b/src/routes/api/password.js index 419a27aca..42bd8b0e0 100644 --- a/src/routes/api/password.js +++ b/src/routes/api/password.js @@ -1,6 +1,6 @@ "use strict"; -const passwordService = require('../../services/encryption/password.js'); +const passwordService = require('../../services/encryption/password'); const ValidationError = require('../../errors/validation_error'); function changePassword(req) { diff --git a/src/routes/api/recent_notes.js b/src/routes/api/recent_notes.js index 5f71633bb..40139477a 100644 --- a/src/routes/api/recent_notes.js +++ b/src/routes/api/recent_notes.js @@ -1,6 +1,6 @@ "use strict"; -const BRecentNote = require('../../becca/entities/brecent_note.js'); +const BRecentNote = require('../../becca/entities/brecent_note'); const sql = require('../../services/sql'); const dateUtils = require('../../services/date_utils'); diff --git a/src/routes/api/sender.js b/src/routes/api/sender.js index 1e55d7a7b..000d1eecb 100644 --- a/src/routes/api/sender.js +++ b/src/routes/api/sender.js @@ -3,7 +3,7 @@ const imageType = require('image-type'); const imageService = require('../../services/image.js'); const noteService = require('../../services/notes.js'); -const {sanitizeAttributeName} = require('../../services/sanitize_attribute_name.js'); +const {sanitizeAttributeName} = require('../../services/sanitize_attribute_name'); const specialNotesService = require('../../services/special_notes.js'); function uploadImage(req) { diff --git a/src/routes/api/sync.js b/src/routes/api/sync.js index aa65da91b..ab32eb671 100644 --- a/src/routes/api/sync.js +++ b/src/routes/api/sync.js @@ -2,7 +2,7 @@ const syncService = require('../../services/sync.js'); const syncUpdateService = require('../../services/sync_update.js'); -const entityChangesService = require('../../services/entity_changes.js'); +const entityChangesService = require('../../services/entity_changes'); const sql = require('../../services/sql'); const sqlInit = require('../../services/sql_init.js'); const optionService = require('../../services/options'); @@ -10,7 +10,7 @@ const contentHashService = require('../../services/content_hash.js'); const log = require('../../services/log'); const syncOptions = require('../../services/sync_options.js'); const utils = require('../../services/utils'); -const ws = require('../../services/ws.js'); +const ws = require('../../services/ws'); async function testSync() { try { diff --git a/src/routes/assets.js b/src/routes/assets.js index d15201557..3f5b81013 100644 --- a/src/routes/assets.js +++ b/src/routes/assets.js @@ -1,7 +1,7 @@ const assetPath = require('../services/asset_path.js'); const path = require("path"); const express = require("express"); -const env = require('../services/env.js'); +const env = require('../services/env'); const persistentCacheStatic = (root, options) => { if (!env.isDev()) { diff --git a/src/routes/index.js b/src/routes/index.js index a7bf71e9f..277d58381 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -5,7 +5,7 @@ const attributeService = require('../services/attributes.js'); const config = require('../services/config'); const optionService = require('../services/options'); const log = require('../services/log'); -const env = require('../services/env.js'); +const env = require('../services/env'); const utils = require('../services/utils'); const protectedSessionService = require('../services/protected_session'); const packageJson = require('../../package.json'); diff --git a/src/routes/login.js b/src/routes/login.js index 83ab5f87b..5aea1a6d5 100644 --- a/src/routes/login.js +++ b/src/routes/login.js @@ -2,9 +2,9 @@ const utils = require('../services/utils'); const optionService = require('../services/options'); -const myScryptService = require('../services/encryption/my_scrypt.js'); +const myScryptService = require('../services/encryption/my_scrypt'); const log = require('../services/log'); -const passwordService = require('../services/encryption/password.js'); +const passwordService = require('../services/encryption/password'); const assetPath = require('../services/asset_path.js'); const appPath = require('../services/app_path.js'); const ValidationError = require('../errors/validation_error'); diff --git a/src/routes/routes.js b/src/routes/routes.js index 2bc50b359..aa67f7dba 100644 --- a/src/routes/routes.js +++ b/src/routes/routes.js @@ -8,11 +8,11 @@ const router = express.Router(); const auth = require('../services/auth.js'); const cls = require('../services/cls'); const sql = require('../services/sql'); -const entityChangesService = require('../services/entity_changes.js'); +const entityChangesService = require('../services/entity_changes'); const csurf = require('csurf'); const { createPartialContentHandler } = require("express-partial-content"); const rateLimit = require("express-rate-limit"); -const AbstractBeccaEntity = require('../becca/entities/abstract_becca_entity.js'); +const AbstractBeccaEntity = require('../becca/entities/abstract_becca_entity'); const NotFoundError = require('../errors/not_found_error'); const ValidationError = require('../errors/validation_error'); @@ -31,7 +31,7 @@ const cloningApiRoute = require('./api/cloning.js'); const revisionsApiRoute = require('./api/revisions.js'); const recentChangesApiRoute = require('./api/recent_changes.js'); const optionsApiRoute = require('./api/options.js'); -const passwordApiRoute = require('./api/password.js'); +const passwordApiRoute = require('./api/password'); const syncApiRoute = require('./api/sync.js'); const loginApiRoute = require('./api/login.js'); const recentNotesRoute = require('./api/recent_notes.js'); diff --git a/src/services/app_path.js b/src/services/app_path.js index ab449495d..9f28c9fa2 100644 --- a/src/services/app_path.js +++ b/src/services/app_path.js @@ -1,5 +1,5 @@ const assetPath = require('./asset_path.js'); -const env = require('./env.js'); +const env = require('./env'); module.exports = env.isDev() ? assetPath + "/app" diff --git a/src/services/attributes.js b/src/services/attributes.js index a45a8ded3..685225ae7 100644 --- a/src/services/attributes.js +++ b/src/services/attributes.js @@ -3,7 +3,7 @@ const searchService = require('./search/services/search.js'); const sql = require('./sql'); const becca = require('../becca/becca'); -const BAttribute = require('../becca/entities/battribute.js'); +const BAttribute = require('../becca/entities/battribute'); const {formatAttrForSearch} = require('./attribute_formatter.js'); const BUILTIN_ATTRIBUTES = require('./builtin_attributes.js'); diff --git a/src/services/auth.js b/src/services/auth.js index d1a928ac2..d212f6676 100644 --- a/src/services/auth.js +++ b/src/services/auth.js @@ -4,9 +4,9 @@ const etapiTokenService = require('./etapi_tokens.js'); const log = require('./log'); const sqlInit = require('./sql_init.js'); const utils = require('./utils'); -const passwordEncryptionService = require('./encryption/password_encryption.js'); +const passwordEncryptionService = require('./encryption/password_encryption'); const config = require('./config'); -const passwordService = require('./encryption/password.js'); +const passwordService = require('./encryption/password'); const noAuthentication = config.General && config.General.noAuthentication === true; diff --git a/src/services/backend_script_api.js b/src/services/backend_script_api.js index 58d6613dd..40e898659 100644 --- a/src/services/backend_script_api.js +++ b/src/services/backend_script_api.js @@ -14,12 +14,12 @@ const appInfo = require('./app_info.js'); const searchService = require('./search/services/search.js'); const SearchContext = require('./search/search_context.js'); const becca = require('../becca/becca'); -const ws = require('./ws.js'); +const ws = require('./ws'); const SpacedUpdate = require('./spaced_update.js'); const specialNotesService = require('./special_notes.js'); const branchService = require('./branches.js'); const exportService = require('./export/zip.js'); -const syncMutex = require('./sync_mutex.js'); +const syncMutex = require('./sync_mutex'); const backupService = require('./backup.js'); const optionsService = require('./options'); diff --git a/src/services/backup.js b/src/services/backup.js index 54decedcb..7fa41eb5e 100644 --- a/src/services/backup.js +++ b/src/services/backup.js @@ -5,7 +5,7 @@ const optionService = require('./options'); const fs = require('fs-extra'); const dataDir = require('./data_dir'); const log = require('./log'); -const syncMutexService = require('./sync_mutex.js'); +const syncMutexService = require('./sync_mutex'); const cls = require('./cls'); const sql = require('./sql'); const path = require('path'); diff --git a/src/services/consistency_checks.js b/src/services/consistency_checks.js index e5ceb594f..5d9ef5104 100644 --- a/src/services/consistency_checks.js +++ b/src/services/consistency_checks.js @@ -3,8 +3,8 @@ const sql = require('./sql'); const sqlInit = require('./sql_init.js'); const log = require('./log'); -const ws = require('./ws.js'); -const syncMutexService = require('./sync_mutex.js'); +const ws = require('./ws'); +const syncMutexService = require('./sync_mutex'); const cls = require('./cls'); const entityChangesService = require('./entity_changes'); const optionsService = require('./options'); @@ -13,7 +13,7 @@ const revisionService = require('./revisions.js'); const becca = require('../becca/becca'); const utils = require('../services/utils'); const eraseService = require('../services/erase.js'); -const {sanitizeAttributeName} = require('./sanitize_attribute_name.js'); +const {sanitizeAttributeName} = require('./sanitize_attribute_name'); const noteTypes = require('../services/note_types.js').getNoteTypeNames(); class ConsistencyChecks { diff --git a/src/services/encryption/password.ts b/src/services/encryption/password.ts index 65c6c08c0..266034d35 100644 --- a/src/services/encryption/password.ts +++ b/src/services/encryption/password.ts @@ -2,9 +2,9 @@ import sql = require('../sql'); import optionService = require('../options'); -import myScryptService = require('./my_scrypt.js'); +import myScryptService = require('./my_scrypt'); import utils = require('../utils'); -import passwordEncryptionService = require('./password_encryption.js'); +import passwordEncryptionService = require('./password_encryption'); function isPasswordSet() { return !!sql.getValue("SELECT value FROM options WHERE name = 'passwordVerificationHash'"); diff --git a/src/services/encryption/password_encryption.ts b/src/services/encryption/password_encryption.ts index 140ae152e..36420d03d 100644 --- a/src/services/encryption/password_encryption.ts +++ b/src/services/encryption/password_encryption.ts @@ -1,7 +1,7 @@ import optionService = require('../options'); -import myScryptService = require('./my_scrypt.js'); +import myScryptService = require('./my_scrypt'); import utils = require('../utils'); -import dataEncryptionService = require('./data_encryption.js'); +import dataEncryptionService = require('./data_encryption'); function verifyPassword(password: string) { const givenPasswordHash = utils.toBase64(myScryptService.getVerificationHash(password)); diff --git a/src/services/etapi_tokens.js b/src/services/etapi_tokens.js index 06302ad71..1c4e0338e 100644 --- a/src/services/etapi_tokens.js +++ b/src/services/etapi_tokens.js @@ -1,6 +1,6 @@ const becca = require('../becca/becca'); const utils = require('./utils'); -const BEtapiToken = require('../becca/entities/betapi_token.js'); +const BEtapiToken = require('../becca/entities/betapi_token'); const crypto = require("crypto"); function getTokens() { diff --git a/src/services/export/zip.js b/src/services/export/zip.js index c5609e0d9..8fd8fd896 100644 --- a/src/services/export/zip.js +++ b/src/services/export/zip.js @@ -14,7 +14,7 @@ const becca = require('../../becca/becca'); const RESOURCE_DIR = require('../../services/resource_dir').RESOURCE_DIR; const archiver = require('archiver'); const log = require('../log'); -const TaskContext = require('../task_context.js'); +const TaskContext = require('../task_context'); const ValidationError = require('../../errors/validation_error'); const NoteMeta = require('../meta/note_meta.js'); const AttachmentMeta = require('../meta/attachment_meta.js'); diff --git a/src/services/handlers.js b/src/services/handlers.js index ee04b42ae..1a9c8e353 100644 --- a/src/services/handlers.js +++ b/src/services/handlers.js @@ -3,7 +3,7 @@ const scriptService = require('./script.js'); const treeService = require('./tree.js'); const noteService = require('./notes.js'); const becca = require('../becca/becca'); -const BAttribute = require('../becca/entities/battribute.js'); +const BAttribute = require('../becca/entities/battribute'); const hiddenSubtreeService = require('./hidden_subtree.js'); const oneTimeTimer = require('./one_time_timer.js'); diff --git a/src/services/hidden_subtree.js b/src/services/hidden_subtree.js index 0a82e61aa..6976fcab9 100644 --- a/src/services/hidden_subtree.js +++ b/src/services/hidden_subtree.js @@ -1,6 +1,6 @@ const becca = require('../becca/becca'); const noteService = require('./notes.js'); -const BAttribute = require('../becca/entities/battribute.js'); +const BAttribute = require('../becca/entities/battribute'); const log = require('./log'); const migrationService = require('./migration.js'); diff --git a/src/services/import/enex.js b/src/services/import/enex.js index 3ef11b2ec..7cc8973ce 100644 --- a/src/services/import/enex.js +++ b/src/services/import/enex.js @@ -8,7 +8,7 @@ const noteService = require('../notes.js'); const imageService = require('../image.js'); const protectedSessionService = require('../protected_session'); const htmlSanitizer = require('../html_sanitizer.js'); -const {sanitizeAttributeName} = require('../sanitize_attribute_name.js'); +const {sanitizeAttributeName} = require('../sanitize_attribute_name'); /** * date format is e.g. 20181121T193703Z or 2013-04-14T16:19:00.000Z (Mac evernote, see #3496) diff --git a/src/services/import/zip.js b/src/services/import/zip.js index 69cbdd4bf..cf6e870ac 100644 --- a/src/services/import/zip.js +++ b/src/services/import/zip.js @@ -1,6 +1,6 @@ "use strict"; -const BAttribute = require('../../becca/entities/battribute.js'); +const BAttribute = require('../../becca/entities/battribute'); const utils = require('../../services/utils'); const log = require('../../services/log'); const noteService = require('../../services/notes.js'); @@ -13,7 +13,7 @@ const treeService = require('../tree.js'); const yauzl = require("yauzl"); const htmlSanitizer = require('../html_sanitizer.js'); const becca = require('../../becca/becca'); -const BAttachment = require('../../becca/entities/battachment.js'); +const BAttachment = require('../../becca/entities/battachment'); const markdownService = require('./markdown.js'); /** diff --git a/src/services/notes.js b/src/services/notes.js index fa513854c..47fc0ab32 100644 --- a/src/services/notes.js +++ b/src/services/notes.js @@ -13,15 +13,15 @@ const path = require('path'); const url = require('url'); const becca = require('../becca/becca'); const BBranch = require('../becca/entities/bbranch'); -const BNote = require('../becca/entities/bnote.js'); -const BAttribute = require('../becca/entities/battribute.js'); -const BAttachment = require('../becca/entities/battachment.js'); +const BNote = require('../becca/entities/bnote'); +const BAttribute = require('../becca/entities/battribute'); +const BAttachment = require('../becca/entities/battachment'); const dayjs = require("dayjs"); const htmlSanitizer = require('./html_sanitizer.js'); const ValidationError = require('../errors/validation_error'); const noteTypesService = require('./note_types.js'); const fs = require("fs"); -const ws = require('./ws.js'); +const ws = require('./ws'); const html2plaintext = require('html2plaintext') /** @param {BNote} parentNote */ diff --git a/src/services/port.js b/src/services/port.js index cec3be8d6..c57f22a5d 100644 --- a/src/services/port.js +++ b/src/services/port.js @@ -1,6 +1,6 @@ const config = require('./config'); const utils = require('./utils'); -const env = require('./env.js'); +const env = require('./env'); const dataDir = require('./data_dir'); function parseAndValidate(portStr, source) { diff --git a/src/services/protected_session.ts b/src/services/protected_session.ts index 1f0e382da..6c1d6c223 100644 --- a/src/services/protected_session.ts +++ b/src/services/protected_session.ts @@ -66,7 +66,7 @@ function checkProtectedSessionExpiration() { log.info("Expiring protected session"); - require('./ws.js').reloadFrontend("leaving protected session"); + require('./ws').reloadFrontend("leaving protected session"); } } diff --git a/src/services/search/expressions/ancestor.js b/src/services/search/expressions/ancestor.js index a3cc4bd54..5275492a1 100644 --- a/src/services/search/expressions/ancestor.js +++ b/src/services/search/expressions/ancestor.js @@ -1,7 +1,7 @@ "use strict"; const Expression = require('./expression.js'); -const NoteSet = require('../note_set.js'); +const NoteSet = require('../note_set'); const log = require('../../log'); const becca = require('../../../becca/becca'); diff --git a/src/services/search/expressions/attribute_exists.js b/src/services/search/expressions/attribute_exists.js index 126f524f9..4c723a433 100644 --- a/src/services/search/expressions/attribute_exists.js +++ b/src/services/search/expressions/attribute_exists.js @@ -1,6 +1,6 @@ "use strict"; -const NoteSet = require('../note_set.js'); +const NoteSet = require('../note_set'); const becca = require('../../../becca/becca'); const Expression = require('./expression.js'); diff --git a/src/services/search/expressions/child_of.js b/src/services/search/expressions/child_of.js index d53b49c20..fde480a83 100644 --- a/src/services/search/expressions/child_of.js +++ b/src/services/search/expressions/child_of.js @@ -1,7 +1,7 @@ "use strict"; const Expression = require('./expression.js'); -const NoteSet = require('../note_set.js'); +const NoteSet = require('../note_set'); class ChildOfExp extends Expression { constructor(subExpression) { diff --git a/src/services/search/expressions/descendant_of.js b/src/services/search/expressions/descendant_of.js index d97dd6c62..11ad011e8 100644 --- a/src/services/search/expressions/descendant_of.js +++ b/src/services/search/expressions/descendant_of.js @@ -1,7 +1,7 @@ "use strict"; const Expression = require('./expression.js'); -const NoteSet = require('../note_set.js'); +const NoteSet = require('../note_set'); const becca = require('../../../becca/becca'); class DescendantOfExp extends Expression { diff --git a/src/services/search/expressions/is_hidden.js b/src/services/search/expressions/is_hidden.js index 32f33b512..e5ff48536 100644 --- a/src/services/search/expressions/is_hidden.js +++ b/src/services/search/expressions/is_hidden.js @@ -1,7 +1,7 @@ "use strict"; const Expression = require('./expression.js'); -const NoteSet = require('../note_set.js'); +const NoteSet = require('../note_set'); /** * Note is hidden when all its note paths start in hidden subtree (i.e., the note is not cloned into visible tree) diff --git a/src/services/search/expressions/label_comparison.js b/src/services/search/expressions/label_comparison.js index 01fe1396a..961bf13f5 100644 --- a/src/services/search/expressions/label_comparison.js +++ b/src/services/search/expressions/label_comparison.js @@ -1,7 +1,7 @@ "use strict"; const Expression = require('./expression.js'); -const NoteSet = require('../note_set.js'); +const NoteSet = require('../note_set'); const becca = require('../../../becca/becca'); class LabelComparisonExp extends Expression { diff --git a/src/services/search/expressions/note_content_fulltext.js b/src/services/search/expressions/note_content_fulltext.js index 0d447b7ed..6a5466a3e 100644 --- a/src/services/search/expressions/note_content_fulltext.js +++ b/src/services/search/expressions/note_content_fulltext.js @@ -1,7 +1,7 @@ "use strict"; const Expression = require('./expression.js'); -const NoteSet = require('../note_set.js'); +const NoteSet = require('../note_set'); const log = require('../../log'); const becca = require('../../../becca/becca'); const protectedSessionService = require('../../protected_session'); diff --git a/src/services/search/expressions/note_flat_text.js b/src/services/search/expressions/note_flat_text.js index f92c1808e..e9fc2fad8 100644 --- a/src/services/search/expressions/note_flat_text.js +++ b/src/services/search/expressions/note_flat_text.js @@ -1,7 +1,7 @@ "use strict"; const Expression = require('./expression.js'); -const NoteSet = require('../note_set.js'); +const NoteSet = require('../note_set'); const becca = require('../../../becca/becca'); const utils = require('../../utils'); diff --git a/src/services/search/expressions/or.js b/src/services/search/expressions/or.js index 1704b5c60..c5a9c64c4 100644 --- a/src/services/search/expressions/or.js +++ b/src/services/search/expressions/or.js @@ -1,7 +1,7 @@ "use strict"; const Expression = require('./expression.js'); -const NoteSet = require('../note_set.js'); +const NoteSet = require('../note_set'); const TrueExp = require('./true.js'); class OrExp extends Expression { diff --git a/src/services/search/expressions/order_by_and_limit.js b/src/services/search/expressions/order_by_and_limit.js index c00f361f1..9a68f9eb2 100644 --- a/src/services/search/expressions/order_by_and_limit.js +++ b/src/services/search/expressions/order_by_and_limit.js @@ -1,7 +1,7 @@ "use strict"; const Expression = require('./expression.js'); -const NoteSet = require('../note_set.js'); +const NoteSet = require('../note_set'); class OrderByAndLimitExp extends Expression { constructor(orderDefinitions, limit) { diff --git a/src/services/search/expressions/parent_of.js b/src/services/search/expressions/parent_of.js index 2243d3540..5f388696b 100644 --- a/src/services/search/expressions/parent_of.js +++ b/src/services/search/expressions/parent_of.js @@ -1,7 +1,7 @@ "use strict"; const Expression = require('./expression.js'); -const NoteSet = require('../note_set.js'); +const NoteSet = require('../note_set'); class ParentOfExp extends Expression { constructor(subExpression) { diff --git a/src/services/search/expressions/property_comparison.js b/src/services/search/expressions/property_comparison.js index 9b014a642..5f8ac14b3 100644 --- a/src/services/search/expressions/property_comparison.js +++ b/src/services/search/expressions/property_comparison.js @@ -1,7 +1,7 @@ "use strict"; const Expression = require('./expression.js'); -const NoteSet = require('../note_set.js'); +const NoteSet = require('../note_set'); const buildComparator = require('../services/build_comparator.js'); /** diff --git a/src/services/search/expressions/relation_where.js b/src/services/search/expressions/relation_where.js index fcd0bc85c..77283b45c 100644 --- a/src/services/search/expressions/relation_where.js +++ b/src/services/search/expressions/relation_where.js @@ -1,7 +1,7 @@ "use strict"; const Expression = require('./expression.js'); -const NoteSet = require('../note_set.js'); +const NoteSet = require('../note_set'); const becca = require('../../../becca/becca'); class RelationWhereExp extends Expression { diff --git a/src/services/sql.ts b/src/services/sql.ts index 6de5003b4..ffc15a99d 100644 --- a/src/services/sql.ts +++ b/src/services/sql.ts @@ -248,7 +248,7 @@ function transactional(func: (statement: Statement) => T) { const ret = (dbConnection.transaction(func) as any).deferred(); if (!dbConnection.inTransaction) { // i.e. transaction was really committed (and not just savepoint released) - require('./ws.js').sendTransactionEntityChangesToAllClients(); + require('./ws').sendTransactionEntityChangesToAllClients(); } return ret; diff --git a/src/services/sql_init.js b/src/services/sql_init.js index 49a101cf6..da28b35d8 100644 --- a/src/services/sql_init.js +++ b/src/services/sql_init.js @@ -5,8 +5,8 @@ const sql = require('./sql'); const utils = require('./utils'); const optionService = require('./options'); const port = require('./port.js'); -const BOption = require('../becca/entities/boption.js'); -const TaskContext = require('./task_context.js'); +const BOption = require('../becca/entities/boption'); +const TaskContext = require('./task_context'); const migrationService = require('./migration.js'); const cls = require('./cls'); const config = require('./config'); @@ -62,7 +62,7 @@ async function createInitialDatabase() { require('../becca/becca_loader.js').load(); - const BNote = require('../becca/entities/bnote.js'); + const BNote = require('../becca/entities/bnote'); const BBranch = require('../becca/entities/bbranch'); log.info("Creating root note ..."); @@ -88,7 +88,7 @@ async function createInitialDatabase() { optionsInitService.initDocumentOptions(); optionsInitService.initNotSyncedOptions(true, {}); optionsInitService.initStartupOptions(); - require('./encryption/password.js').resetPassword(); + require('./encryption/password').resetPassword(); }); log.info("Importing demo content ..."); diff --git a/src/services/sync.js b/src/services/sync.js index 856101703..4410e571a 100644 --- a/src/services/sync.js +++ b/src/services/sync.js @@ -10,10 +10,10 @@ const syncUpdateService = require('./sync_update.js'); const contentHashService = require('./content_hash.js'); const appInfo = require('./app_info.js'); const syncOptions = require('./sync_options.js'); -const syncMutexService = require('./sync_mutex.js'); +const syncMutexService = require('./sync_mutex'); const cls = require('./cls'); const request = require('./request.js'); -const ws = require('./ws.js'); +const ws = require('./ws'); const entityChangesService = require('./entity_changes'); const entityConstructor = require('../becca/entity_constructor.js'); const becca = require('../becca/becca'); diff --git a/src/services/sync_update.js b/src/services/sync_update.js index 96922c450..6b6bbf556 100644 --- a/src/services/sync_update.js +++ b/src/services/sync_update.js @@ -3,7 +3,7 @@ const log = require('./log'); const entityChangesService = require('./entity_changes'); const eventService = require('./events'); const entityConstructor = require('../becca/entity_constructor.js'); -const ws = require('./ws.js'); +const ws = require('./ws'); function updateEntities(entityChanges, instanceId) { if (entityChanges.length === 0) { diff --git a/src/services/task_context.ts b/src/services/task_context.ts index 6aa2d9754..78ab6b10c 100644 --- a/src/services/task_context.ts +++ b/src/services/task_context.ts @@ -1,6 +1,6 @@ "use strict"; -import ws = require('./ws.js'); +import ws = require('./ws'); // taskId => TaskContext const taskContexts: Record = {}; diff --git a/src/services/window.js b/src/services/window.js index ef26ede5c..f855175c5 100644 --- a/src/services/window.js +++ b/src/services/window.js @@ -2,7 +2,7 @@ const path = require('path'); const url = require("url"); const port = require('./port.js'); const optionService = require('./options'); -const env = require('./env.js'); +const env = require('./env'); const log = require('./log'); const sqlInit = require('./sql_init.js'); const cls = require('./cls'); diff --git a/src/services/ws.ts b/src/services/ws.ts index 64e7707c2..461b0e650 100644 --- a/src/services/ws.ts +++ b/src/services/ws.ts @@ -4,10 +4,10 @@ import log = require('./log'); import sql = require('./sql'); import cls = require('./cls'); import config = require('./config'); -import syncMutexService = require('./sync_mutex.js'); +import syncMutexService = require('./sync_mutex'); import protectedSessionService = require('./protected_session'); import becca = require('../becca/becca'); -import AbstractBeccaEntity = require('../becca/entities/abstract_becca_entity.js'); +import AbstractBeccaEntity = require('../becca/entities/abstract_becca_entity'); import env = require('./env'); import { IncomingMessage, Server } from 'http'; @@ -157,7 +157,9 @@ function fillInAdditionalProperties(entityChange: EntityChange) { if (parentNote) { for (const childBranch of parentNote.getChildBranches()) { - entityChange.positions[childBranch.branchId] = childBranch.notePosition; + if (childBranch && childBranch.branchId) { + entityChange.positions[childBranch.branchId] = childBranch.notePosition; + } } } } else if (entityChange.entityName === 'options') { From b8ccf5ba8f108ddfec2689fd6f7d3f6cd3acbacf Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 17 Feb 2024 11:57:42 +0200 Subject: [PATCH 40/49] server-ts: Fix error with sanitize_attribute_name --- src/becca/entities/battribute.ts | 2 +- src/services/sanitize_attribute_name.ts | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/becca/entities/battribute.ts b/src/becca/entities/battribute.ts index cc757d142..c3d0115fc 100644 --- a/src/becca/entities/battribute.ts +++ b/src/becca/entities/battribute.ts @@ -183,7 +183,7 @@ class BAttribute extends AbstractBeccaEntity { this.validate(); } - this.name = sanitizeAttributeName(this.name); + this.name = sanitizeAttributeName.sanitizeAttributeName(this.name); if (!this.value) { // null value isn't allowed diff --git a/src/services/sanitize_attribute_name.ts b/src/services/sanitize_attribute_name.ts index ecdc35dc0..62b2b03b3 100644 --- a/src/services/sanitize_attribute_name.ts +++ b/src/services/sanitize_attribute_name.ts @@ -13,4 +13,6 @@ function sanitizeAttributeName(origName: string) { } -export = sanitizeAttributeName; +export = { + sanitizeAttributeName +}; From 6f0659c03cfef1abcded8c29ef483c0d5cb63109 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 17 Feb 2024 12:33:20 +0200 Subject: [PATCH 41/49] server-ts: Bring back nodemon --- nodemon.json | 7 +- package-lock.json | 478 ++++++++++++++++++++-------------------------- package.json | 8 +- tsconfig.json | 8 +- 4 files changed, 216 insertions(+), 285 deletions(-) diff --git a/nodemon.json b/nodemon.json index df14c4a84..86e1c2ca4 100644 --- a/nodemon.json +++ b/nodemon.json @@ -2,12 +2,11 @@ "restartable": "rs", "ignore": [".git", "node_modules/**/node_modules", "src/public/"], "verbose": false, - "execMap": { - "js": "node --harmony" - }, + "exec": "ts-node", "watch": ["src/"], + "signal": "SIGTERM", "env": { "NODE_ENV": "development" }, - "ext": "js,json" + "ext": "ts,js,json" } diff --git a/package-lock.json b/package-lock.json index b4862777e..930bd7d62 100644 --- a/package-lock.json +++ b/package-lock.json @@ -117,7 +117,7 @@ "nodemon": "3.0.1", "prettier": "3.1.0", "rcedit": "4.0.1", - "ts-node": "^3.3.0", + "ts-node": "^10.9.2", "tslib": "^2.6.2", "typescript": "^5.3.3", "webpack": "5.89.0", @@ -169,6 +169,28 @@ "resolved": "https://registry.npmjs.org/@braintree/sanitize-url/-/sanitize-url-6.0.4.tgz", "integrity": "sha512-s3jaWicZd0pkP0jf5ysyHUI/RE7MHos6qlToFcGWXVp+ykHOy77OUMrfbgJ9it2C5bow7OIQwYYaHjk9XlBQ2A==" }, + "node_modules/@cspotcode/source-map-support": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz", + "integrity": "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==", + "dev": true, + "dependencies": { + "@jridgewell/trace-mapping": "0.3.9" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/@cspotcode/source-map-support/node_modules/@jridgewell/trace-mapping": { + "version": "0.3.9", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz", + "integrity": "sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==", + "dev": true, + "dependencies": { + "@jridgewell/resolve-uri": "^3.0.3", + "@jridgewell/sourcemap-codec": "^1.4.10" + } + }, "node_modules/@develar/schema-utils": { "version": "2.6.5", "resolved": "https://registry.npmjs.org/@develar/schema-utils/-/schema-utils-2.6.5.tgz", @@ -1282,6 +1304,30 @@ "node": ">= 10" } }, + "node_modules/@tsconfig/node10": { + "version": "1.0.9", + "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.9.tgz", + "integrity": "sha512-jNsYVVxU8v5g43Erja32laIDHXeoNvFEpX33OK4d6hljo3jDhCBDhx5dhCCTMWUojscpAagGiRkBKxpdl9fxqA==", + "dev": true + }, + "node_modules/@tsconfig/node12": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/@tsconfig/node12/-/node12-1.0.11.tgz", + "integrity": "sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==", + "dev": true + }, + "node_modules/@tsconfig/node14": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/@tsconfig/node14/-/node14-1.0.3.tgz", + "integrity": "sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==", + "dev": true + }, + "node_modules/@tsconfig/node16": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-1.0.4.tgz", + "integrity": "sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==", + "dev": true + }, "node_modules/@tweenjs/tween.js": { "version": "21.0.0", "resolved": "https://registry.npmjs.org/@tweenjs/tween.js/-/tween.js-21.0.0.tgz", @@ -1896,6 +1942,15 @@ "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" } }, + "node_modules/acorn-walk": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.3.2.tgz", + "integrity": "sha512-cjkyv4OtNCIeqhHrfS81QWXoCBPExR/J62oyEqepVw8WaQeSqpW2uhuLPh1m9eWhDuOo/jUXVTlifvesOWp/4A==", + "dev": true, + "engines": { + "node": ">=0.4.0" + } + }, "node_modules/agent-base": { "version": "6.0.2", "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz", @@ -2305,6 +2360,12 @@ "streamx": "^2.15.0" } }, + "node_modules/arg": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", + "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==", + "dev": true + }, "node_modules/argparse": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", @@ -2424,15 +2485,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/arrify": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/arrify/-/arrify-1.0.1.tgz", - "integrity": "sha512-3CYzex9M9FGQjCGMGyi6/31c8GJbgb0qGyrx5HWxPd0aCwh4cB2YjMb2Xf9UuoogrMrlO9cTqnB5rI5GHZTcUA==", - "dev": true, - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/asar": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/asar/-/asar-3.1.0.tgz", @@ -3927,6 +3979,12 @@ "node": ">= 6" } }, + "node_modules/create-require": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", + "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", + "dev": true + }, "node_modules/cross-env": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-env/-/cross-env-7.0.3.tgz", @@ -7600,18 +7658,6 @@ "resolved": "https://registry.npmjs.org/hoist-non-react-statics/-/hoist-non-react-statics-2.5.5.tgz", "integrity": "sha512-rqcy4pJo55FTTLWt+bU8ukscqHeE/e9KWvsOW2b/a3afxQZhwkQdT1rPPCJ0rYXdj4vNcasY8zHTH+jF/qStxw==" }, - "node_modules/homedir-polyfill": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/homedir-polyfill/-/homedir-polyfill-1.0.3.tgz", - "integrity": "sha512-eSmmWE5bZTK2Nou4g0AI3zZ9rswp7GRKoKXS1BLUkvPviOqs4YTN1djQIqrXy9k5gEtdLPy86JjRwsNM9tnDcA==", - "dev": true, - "dependencies": { - "parse-passwd": "^1.0.0" - }, - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/hosted-git-info": { "version": "2.8.9", "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.9.tgz", @@ -11375,15 +11421,6 @@ "node": ">=0.10.0" } }, - "node_modules/parse-passwd": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/parse-passwd/-/parse-passwd-1.0.0.tgz", - "integrity": "sha512-1Y1A//QUXEZK7YKz+rD9WydcE1+EuPr6ZBgKecAB8tmoW6UFv0NREVJe1p+jRxtThkcbbKkfwIbWJe/IeE6m2Q==", - "dev": true, - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/parse-srcset": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/parse-srcset/-/parse-srcset-1.0.2.tgz", @@ -13914,129 +13951,57 @@ } }, "node_modules/ts-node": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-3.3.0.tgz", - "integrity": "sha512-S87fS5QGinpnvi6I1aW8PnEEwJbkQsr2o+9C3qdAkmaYQn33PKVkXowI2/wggr8FzAwKhvCaomB0EX60LW3/Fw==", + "version": "10.9.2", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.2.tgz", + "integrity": "sha512-f0FFpIdcHgn8zcPSbf1dRevwt047YMnaiJM3u2w2RewrB+fob/zePZcrOyQoLMMO7aBIddLcQIEK5dYjkLnGrQ==", "dev": true, "dependencies": { - "arrify": "^1.0.0", - "chalk": "^2.0.0", - "diff": "^3.1.0", + "@cspotcode/source-map-support": "^0.8.0", + "@tsconfig/node10": "^1.0.7", + "@tsconfig/node12": "^1.0.7", + "@tsconfig/node14": "^1.0.0", + "@tsconfig/node16": "^1.0.2", + "acorn": "^8.4.1", + "acorn-walk": "^8.1.1", + "arg": "^4.1.0", + "create-require": "^1.1.0", + "diff": "^4.0.1", "make-error": "^1.1.1", - "minimist": "^1.2.0", - "mkdirp": "^0.5.1", - "source-map-support": "^0.4.0", - "tsconfig": "^6.0.0", - "v8flags": "^3.0.0", - "yn": "^2.0.0" + "v8-compile-cache-lib": "^3.0.1", + "yn": "3.1.1" }, "bin": { - "_ts-node": "dist/_bin.js", - "ts-node": "dist/bin.js" + "ts-node": "dist/bin.js", + "ts-node-cwd": "dist/bin-cwd.js", + "ts-node-esm": "dist/bin-esm.js", + "ts-node-script": "dist/bin-script.js", + "ts-node-transpile-only": "dist/bin-transpile.js", + "ts-script": "dist/bin-script-deprecated.js" }, - "engines": { - "node": ">=4.2.0" - } - }, - "node_modules/ts-node/node_modules/ansi-styles": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", - "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", - "dev": true, - "dependencies": { - "color-convert": "^1.9.0" + "peerDependencies": { + "@swc/core": ">=1.2.50", + "@swc/wasm": ">=1.2.50", + "@types/node": "*", + "typescript": ">=2.7" }, - "engines": { - "node": ">=4" + "peerDependenciesMeta": { + "@swc/core": { + "optional": true + }, + "@swc/wasm": { + "optional": true + } } }, - "node_modules/ts-node/node_modules/chalk": { - "version": "2.4.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", - "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", - "dev": true, - "dependencies": { - "ansi-styles": "^3.2.1", - "escape-string-regexp": "^1.0.5", - "supports-color": "^5.3.0" - }, - "engines": { - "node": ">=4" - } - }, - "node_modules/ts-node/node_modules/color-convert": { - "version": "1.9.3", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", - "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", - "dev": true, - "dependencies": { - "color-name": "1.1.3" - } - }, - "node_modules/ts-node/node_modules/color-name": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", - "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==", - "dev": true - }, "node_modules/ts-node/node_modules/diff": { - "version": "3.5.0", - "resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz", - "integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==", + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", + "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", "dev": true, "engines": { "node": ">=0.3.1" } }, - "node_modules/ts-node/node_modules/has-flag": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", - "integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==", - "dev": true, - "engines": { - "node": ">=4" - } - }, - "node_modules/ts-node/node_modules/source-map": { - "version": "0.5.7", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", - "integrity": "sha512-LbrmJOMUSdEVxIKvdcJzQC+nQhe8FUZQTXQy6+I75skNgn3OoQ0DZA8YnFa7gp8tqtL3KPf1kmo0R5DoApeSGQ==", - "dev": true, - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/ts-node/node_modules/source-map-support": { - "version": "0.4.18", - "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.4.18.tgz", - "integrity": "sha512-try0/JqxPLF9nOjvSta7tVondkP5dwgyLDjVoyMDlmjugT2lRZ1OfsrYTkCd2hkDnJTKRbO/Rl3orm8vlsUzbA==", - "dev": true, - "dependencies": { - "source-map": "^0.5.6" - } - }, - "node_modules/ts-node/node_modules/supports-color": { - "version": "5.5.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", - "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", - "dev": true, - "dependencies": { - "has-flag": "^3.0.0" - }, - "engines": { - "node": ">=4" - } - }, - "node_modules/tsconfig": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/tsconfig/-/tsconfig-6.0.0.tgz", - "integrity": "sha512-n3i8c4BOozElBHYMVkEyF9AudHRvvq6NTc6sVRVmLBQM2A02JKjLoICxRtKkoGu3gROOnRZ85KxiTAcmhWgR0w==", - "dev": true, - "dependencies": { - "strip-bom": "^3.0.0", - "strip-json-comments": "^2.0.0" - } - }, "node_modules/tsconfig-paths": { "version": "3.15.0", "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-3.15.0.tgz", @@ -14420,17 +14385,11 @@ "node": ">=8" } }, - "node_modules/v8flags": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/v8flags/-/v8flags-3.2.0.tgz", - "integrity": "sha512-mH8etigqMfiGWdeXpaaqGfs6BndypxusHHcv2qSHyZkGEznCd/qAXCWWRzeowtL54147cktFOC4P5y+kl8d8Jg==", - "dev": true, - "dependencies": { - "homedir-polyfill": "^1.0.1" - }, - "engines": { - "node": ">= 0.10" - } + "node_modules/v8-compile-cache-lib": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz", + "integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==", + "dev": true }, "node_modules/validate-npm-package-license": { "version": "3.0.4", @@ -15039,12 +14998,12 @@ } }, "node_modules/yn": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/yn/-/yn-2.0.0.tgz", - "integrity": "sha512-uTv8J/wiWTgUTg+9vLTi//leUl5vDQS6uii/emeTb2ssY7vl6QWf2fFbIIGjnhjvbdKlU0ed7QPgY1htTC86jQ==", + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", + "integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==", "dev": true, "engines": { - "node": ">=4" + "node": ">=6" } }, "node_modules/yocto-queue": { @@ -15119,6 +15078,27 @@ "resolved": "https://registry.npmjs.org/@braintree/sanitize-url/-/sanitize-url-6.0.4.tgz", "integrity": "sha512-s3jaWicZd0pkP0jf5ysyHUI/RE7MHos6qlToFcGWXVp+ykHOy77OUMrfbgJ9it2C5bow7OIQwYYaHjk9XlBQ2A==" }, + "@cspotcode/source-map-support": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz", + "integrity": "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==", + "dev": true, + "requires": { + "@jridgewell/trace-mapping": "0.3.9" + }, + "dependencies": { + "@jridgewell/trace-mapping": { + "version": "0.3.9", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz", + "integrity": "sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==", + "dev": true, + "requires": { + "@jridgewell/resolve-uri": "^3.0.3", + "@jridgewell/sourcemap-codec": "^1.4.10" + } + } + } + }, "@develar/schema-utils": { "version": "2.6.5", "resolved": "https://registry.npmjs.org/@develar/schema-utils/-/schema-utils-2.6.5.tgz", @@ -15939,6 +15919,30 @@ "resolved": "https://registry.npmjs.org/@tootallnate/once/-/once-2.0.0.tgz", "integrity": "sha512-XCuKFP5PS55gnMVu3dty8KPatLqUoy/ZYzDzAGCQ8JNFCkLXzmI7vNHCR+XpbZaMWQK/vQubr7PkYq8g470J/A==" }, + "@tsconfig/node10": { + "version": "1.0.9", + "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.9.tgz", + "integrity": "sha512-jNsYVVxU8v5g43Erja32laIDHXeoNvFEpX33OK4d6hljo3jDhCBDhx5dhCCTMWUojscpAagGiRkBKxpdl9fxqA==", + "dev": true + }, + "@tsconfig/node12": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/@tsconfig/node12/-/node12-1.0.11.tgz", + "integrity": "sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==", + "dev": true + }, + "@tsconfig/node14": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/@tsconfig/node14/-/node14-1.0.3.tgz", + "integrity": "sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==", + "dev": true + }, + "@tsconfig/node16": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-1.0.4.tgz", + "integrity": "sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==", + "dev": true + }, "@tweenjs/tween.js": { "version": "21.0.0", "resolved": "https://registry.npmjs.org/@tweenjs/tween.js/-/tween.js-21.0.0.tgz", @@ -16513,6 +16517,12 @@ "dev": true, "requires": {} }, + "acorn-walk": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.3.2.tgz", + "integrity": "sha512-cjkyv4OtNCIeqhHrfS81QWXoCBPExR/J62oyEqepVw8WaQeSqpW2uhuLPh1m9eWhDuOo/jUXVTlifvesOWp/4A==", + "dev": true + }, "agent-base": { "version": "6.0.2", "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz", @@ -16846,6 +16856,12 @@ } } }, + "arg": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", + "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==", + "dev": true + }, "argparse": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", @@ -16932,12 +16948,6 @@ "is-shared-array-buffer": "^1.0.2" } }, - "arrify": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/arrify/-/arrify-1.0.1.tgz", - "integrity": "sha512-3CYzex9M9FGQjCGMGyi6/31c8GJbgb0qGyrx5HWxPd0aCwh4cB2YjMb2Xf9UuoogrMrlO9cTqnB5rI5GHZTcUA==", - "dev": true - }, "asar": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/asar/-/asar-3.1.0.tgz", @@ -18103,6 +18113,12 @@ } } }, + "create-require": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", + "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", + "dev": true + }, "cross-env": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-env/-/cross-env-7.0.3.tgz", @@ -20873,15 +20889,6 @@ "resolved": "https://registry.npmjs.org/hoist-non-react-statics/-/hoist-non-react-statics-2.5.5.tgz", "integrity": "sha512-rqcy4pJo55FTTLWt+bU8ukscqHeE/e9KWvsOW2b/a3afxQZhwkQdT1rPPCJ0rYXdj4vNcasY8zHTH+jF/qStxw==" }, - "homedir-polyfill": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/homedir-polyfill/-/homedir-polyfill-1.0.3.tgz", - "integrity": "sha512-eSmmWE5bZTK2Nou4g0AI3zZ9rswp7GRKoKXS1BLUkvPviOqs4YTN1djQIqrXy9k5gEtdLPy86JjRwsNM9tnDcA==", - "dev": true, - "requires": { - "parse-passwd": "^1.0.0" - } - }, "hosted-git-info": { "version": "2.8.9", "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.9.tgz", @@ -23564,12 +23571,6 @@ "error-ex": "^1.2.0" } }, - "parse-passwd": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/parse-passwd/-/parse-passwd-1.0.0.tgz", - "integrity": "sha512-1Y1A//QUXEZK7YKz+rD9WydcE1+EuPr6ZBgKecAB8tmoW6UFv0NREVJe1p+jRxtThkcbbKkfwIbWJe/IeE6m2Q==", - "dev": true - }, "parse-srcset": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/parse-srcset/-/parse-srcset-1.0.2.tgz", @@ -25491,106 +25492,34 @@ "integrity": "sha512-q5W7tVM71e2xjHZTlgfTDoPF/SmqKG5hddq9SzR49CH2hayqRKJtQ4mtRlSxKaJlR/+9rEM+mnBHf7I2/BQcpQ==" }, "ts-node": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-3.3.0.tgz", - "integrity": "sha512-S87fS5QGinpnvi6I1aW8PnEEwJbkQsr2o+9C3qdAkmaYQn33PKVkXowI2/wggr8FzAwKhvCaomB0EX60LW3/Fw==", + "version": "10.9.2", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.2.tgz", + "integrity": "sha512-f0FFpIdcHgn8zcPSbf1dRevwt047YMnaiJM3u2w2RewrB+fob/zePZcrOyQoLMMO7aBIddLcQIEK5dYjkLnGrQ==", "dev": true, "requires": { - "arrify": "^1.0.0", - "chalk": "^2.0.0", - "diff": "^3.1.0", + "@cspotcode/source-map-support": "^0.8.0", + "@tsconfig/node10": "^1.0.7", + "@tsconfig/node12": "^1.0.7", + "@tsconfig/node14": "^1.0.0", + "@tsconfig/node16": "^1.0.2", + "acorn": "^8.4.1", + "acorn-walk": "^8.1.1", + "arg": "^4.1.0", + "create-require": "^1.1.0", + "diff": "^4.0.1", "make-error": "^1.1.1", - "minimist": "^1.2.0", - "mkdirp": "^0.5.1", - "source-map-support": "^0.4.0", - "tsconfig": "^6.0.0", - "v8flags": "^3.0.0", - "yn": "^2.0.0" + "v8-compile-cache-lib": "^3.0.1", + "yn": "3.1.1" }, "dependencies": { - "ansi-styles": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", - "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", - "dev": true, - "requires": { - "color-convert": "^1.9.0" - } - }, - "chalk": { - "version": "2.4.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", - "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", - "dev": true, - "requires": { - "ansi-styles": "^3.2.1", - "escape-string-regexp": "^1.0.5", - "supports-color": "^5.3.0" - } - }, - "color-convert": { - "version": "1.9.3", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", - "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", - "dev": true, - "requires": { - "color-name": "1.1.3" - } - }, - "color-name": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", - "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==", - "dev": true - }, "diff": { - "version": "3.5.0", - "resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz", - "integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==", + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", + "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", "dev": true - }, - "has-flag": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", - "integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==", - "dev": true - }, - "source-map": { - "version": "0.5.7", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", - "integrity": "sha512-LbrmJOMUSdEVxIKvdcJzQC+nQhe8FUZQTXQy6+I75skNgn3OoQ0DZA8YnFa7gp8tqtL3KPf1kmo0R5DoApeSGQ==", - "dev": true - }, - "source-map-support": { - "version": "0.4.18", - "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.4.18.tgz", - "integrity": "sha512-try0/JqxPLF9nOjvSta7tVondkP5dwgyLDjVoyMDlmjugT2lRZ1OfsrYTkCd2hkDnJTKRbO/Rl3orm8vlsUzbA==", - "dev": true, - "requires": { - "source-map": "^0.5.6" - } - }, - "supports-color": { - "version": "5.5.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", - "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", - "dev": true, - "requires": { - "has-flag": "^3.0.0" - } } } }, - "tsconfig": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/tsconfig/-/tsconfig-6.0.0.tgz", - "integrity": "sha512-n3i8c4BOozElBHYMVkEyF9AudHRvvq6NTc6sVRVmLBQM2A02JKjLoICxRtKkoGu3gROOnRZ85KxiTAcmhWgR0w==", - "dev": true, - "requires": { - "strip-bom": "^3.0.0", - "strip-json-comments": "^2.0.0" - } - }, "tsconfig-paths": { "version": "3.15.0", "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-3.15.0.tgz", @@ -25894,14 +25823,11 @@ "sade": "^1.7.3" } }, - "v8flags": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/v8flags/-/v8flags-3.2.0.tgz", - "integrity": "sha512-mH8etigqMfiGWdeXpaaqGfs6BndypxusHHcv2qSHyZkGEznCd/qAXCWWRzeowtL54147cktFOC4P5y+kl8d8Jg==", - "dev": true, - "requires": { - "homedir-polyfill": "^1.0.1" - } + "v8-compile-cache-lib": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz", + "integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==", + "dev": true }, "validate-npm-package-license": { "version": "3.0.4", @@ -26342,9 +26268,9 @@ } }, "yn": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/yn/-/yn-2.0.0.tgz", - "integrity": "sha512-uTv8J/wiWTgUTg+9vLTi//leUl5vDQS6uii/emeTb2ssY7vl6QWf2fFbIIGjnhjvbdKlU0ed7QPgY1htTC86jQ==", + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", + "integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==", "dev": true }, "yocto-queue": { diff --git a/package.json b/package.json index 1c9c869f6..8a453278a 100644 --- a/package.json +++ b/package.json @@ -13,9 +13,9 @@ "url": "https://github.com/zadam/trilium.git" }, "scripts": { - "start-server": "cross-env TRILIUM_SAFE_MODE=1 TRILIUM_DATA_DIR=./data TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 ts-node src/www.js", - "start-server-no-dir": "cross-env TRILIUM_SAFE_MODE=1 TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 ts-node src/www.js", - "qstart-server": "npm run qswitch-server && TRILIUM_SAFE_MODE=1 TRILIUM_DATA_DIR=./data TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 ts-node src/www.js", + "start-server": "cross-env TRILIUM_SAFE_MODE=1 TRILIUM_DATA_DIR=./data TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 nodemon src/www.js", + "start-server-no-dir": "cross-env TRILIUM_SAFE_MODE=1 TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 nodemon src/www.js", + "qstart-server": "npm run qswitch-server && TRILIUM_SAFE_MODE=1 TRILIUM_DATA_DIR=./data TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 nodemon src/www.js", "start-electron": "cross-env TRILIUM_SAFE_MODE=1 TRILIUM_DATA_DIR=./data TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev electron --inspect=5858 .", "start-electron-no-dir": "cross-env TRILIUM_SAFE_MODE=1 TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 electron --inspect=5858 .", "qstart-electron": "npm run qswitch-electron && TRILIUM_SAFE_MODE=1 TRILIUM_DATA_DIR=./data TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev electron --inspect=5858 .", @@ -140,7 +140,7 @@ "nodemon": "3.0.1", "prettier": "3.1.0", "rcedit": "4.0.1", - "ts-node": "^3.3.0", + "ts-node": "^10.9.2", "tslib": "^2.6.2", "typescript": "^5.3.3", "webpack": "5.89.0", diff --git a/tsconfig.json b/tsconfig.json index eded031af..50d8ce89c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -12,5 +12,11 @@ "./src/**/*.js", "./src/**/*.ts" ], - "exclude": ["./node_modules/**/*"] + "exclude": ["./node_modules/**/*"], + "ts-node": { + "files": true + }, + "files": [ + "src/types/unescape.d.ts" + ] } From 8af54344627927b4035d2693c00cf367a8bb2cde Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 17 Feb 2024 12:33:34 +0200 Subject: [PATCH 42/49] server-ts: Add script to check progress --- _check_ts_progress.sh | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100755 _check_ts_progress.sh diff --git a/_check_ts_progress.sh b/_check_ts_progress.sh new file mode 100755 index 000000000..85b71add8 --- /dev/null +++ b/_check_ts_progress.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +cloc HEAD \ + --git --md \ + --include-lang=javascript,typescript \ + --found=filelist.txt \ + --exclude-dir=public,libraries \ No newline at end of file From 1e91db865bfbd8da0de6789c858b17ad2b243d76 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 17 Feb 2024 18:55:41 +0200 Subject: [PATCH 43/49] server-ts: Implement review comments --- src/becca/becca-interface.ts | 4 ++-- src/services/backend_script_api.js | 2 +- src/services/encryption/data_encryption.ts | 2 +- src/services/search/note_set.ts | 5 +++-- src/services/sql.ts | 4 ++-- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/becca/becca-interface.ts b/src/becca/becca-interface.ts index a18dc9432..4c8218797 100644 --- a/src/becca/becca-interface.ts +++ b/src/becca/becca-interface.ts @@ -68,7 +68,7 @@ class Becca { } findAttributesWithPrefix(type: string, name: string): BAttribute[] { - const resArr = []; + const resArr: BAttribute[][] = []; const key = `${type}-${name}`; for (const idx in this.attributeIndex) { @@ -105,7 +105,7 @@ class Becca { } getNotes(noteIds: string[], ignoreMissing: boolean = false): BNote[] { - const filteredNotes = []; + const filteredNotes: BNote[] = []; for (const noteId of noteIds) { const note = this.notes[noteId]; diff --git a/src/services/backend_script_api.js b/src/services/backend_script_api.js index 40e898659..fc8e80aef 100644 --- a/src/services/backend_script_api.js +++ b/src/services/backend_script_api.js @@ -678,7 +678,7 @@ function BackendScriptApi(currentNote, apiParams) { /** * This object contains "at your risk" and "no BC guarantees" objects for advanced use cases. * - * @property {Becca} becca - provides access to the backend in-memory object graph, see {@link https://github.com/zadam/trilium/blob/master/src/becca/becca} + * @property {Becca} becca - provides access to the backend in-memory object graph, see {@link https://github.com/zadam/trilium/blob/master/src/becca/becca.js} */ this.__private = { becca diff --git a/src/services/encryption/data_encryption.ts b/src/services/encryption/data_encryption.ts index c19008a5b..b82a0e8c6 100644 --- a/src/services/encryption/data_encryption.ts +++ b/src/services/encryption/data_encryption.ts @@ -3,7 +3,7 @@ import crypto = require('crypto'); import log = require('../log'); -function arraysIdentical(a: Buffer, b: Buffer) { +function arraysIdentical(a: any[] | Buffer, b: any[] | Buffer) { let i = a.length; if (i !== b.length) return false; while (i--) { diff --git a/src/services/search/note_set.ts b/src/services/search/note_set.ts index d53d00e4d..47c644c38 100644 --- a/src/services/search/note_set.ts +++ b/src/services/search/note_set.ts @@ -4,9 +4,10 @@ import BNote = require("../../becca/entities/bnote"); class NoteSet { - private notes: BNote[]; private noteIdSet: Set; - private sorted: boolean; + + notes: BNote[]; + sorted: boolean; constructor(notes: BNote[] = []) { this.notes = notes; diff --git a/src/services/sql.ts b/src/services/sql.ts index ffc15a99d..f0a9d7d29 100644 --- a/src/services/sql.ts +++ b/src/services/sql.ts @@ -157,10 +157,10 @@ function iterateRows(query: string, params: Params = []) { function getMap(query: string, params: Params = []) { const map: Record = {} as Record; - const results = getRawRows(query, params); + const results = getRawRows<[K, V]>(query, params); for (const row of results || []) { - map[row[0] as K] = row[1]; + map[row[0]] = row[1]; } return map; From 3d9da26bb3d6705604ebf7e4ce19dc7730a65f48 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sun, 18 Feb 2024 18:11:56 +0200 Subject: [PATCH 44/49] server-ts: Address review comments --- src/services/erase.js | 2 +- src/services/sync_mutex.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/services/erase.js b/src/services/erase.js index 4c225428b..7ffb30ebc 100644 --- a/src/services/erase.js +++ b/src/services/erase.js @@ -1,6 +1,6 @@ const sql = require("./sql"); const revisionService = require("./revisions.js"); -const log = require("./log.ts"); +const log = require("./log"); const entityChangesService = require("./entity_changes"); const optionService = require("./options"); const dateUtils = require("./date_utils"); diff --git a/src/services/sync_mutex.ts b/src/services/sync_mutex.ts index 655af4d59..9ad0fd08c 100644 --- a/src/services/sync_mutex.ts +++ b/src/services/sync_mutex.ts @@ -6,7 +6,7 @@ const Mutex = require('async-mutex').Mutex; const instance = new Mutex(); -async function doExclusively(func: () => void) { +async function doExclusively(func: () => T) { const releaseMutex = await instance.acquire(); try { From aff1c30557faa7022199d617ba0d9b4d9d5e3471 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sun, 18 Feb 2024 20:29:23 +0200 Subject: [PATCH 45/49] server-ts: FIXME -> TODO --- src/becca/entities/abstract_becca_entity.ts | 4 ++-- src/becca/entities/battachment.ts | 4 ++-- src/becca/entities/bblob.ts | 2 +- src/becca/entities/bnote.ts | 4 ++-- src/becca/entities/brevision.ts | 2 +- src/becca/entities/rows.ts | 2 +- src/services/encryption/password.ts | 2 +- src/services/utils.ts | 4 ++-- 8 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/becca/entities/abstract_becca_entity.ts b/src/becca/entities/abstract_becca_entity.ts index 53999be68..74f1163ae 100644 --- a/src/becca/entities/abstract_becca_entity.ts +++ b/src/becca/entities/abstract_becca_entity.ts @@ -89,14 +89,14 @@ abstract class AbstractBeccaEntity> { } hasStringContent(): boolean { - // FIXME: Not sure why some entities don't implement it. + // TODO: Not sure why some entities don't implement it. return true; } abstract getPojo(): {}; get isDeleted(): boolean { - // FIXME: Not sure why some entities don't implement it. + // TODO: Not sure why some entities don't implement it. return false; } diff --git a/src/becca/entities/battachment.ts b/src/becca/entities/battachment.ts index 84f7de5c1..7d90921ab 100644 --- a/src/becca/entities/battachment.ts +++ b/src/becca/entities/battachment.ts @@ -15,7 +15,7 @@ const attachmentRoleToNoteTypeMapping = { }; interface ContentOpts { - // FIXME: Found in bnote.ts, to check if it's actually used and not a typo. + // TODO: Found in bnote.ts, to check if it's actually used and not a typo. forceSave?: boolean; /** will also save this BAttachment entity */ @@ -135,7 +135,7 @@ class BAttachment extends AbstractBeccaEntity { } convertToNote(): { note: BNote, branch: BBranch } { - // FIXME: can this ever be "search"? + // TODO: can this ever be "search"? if (this.type as string === 'search') { throw new Error(`Note of type search cannot have child notes`); } diff --git a/src/becca/entities/bblob.ts b/src/becca/entities/bblob.ts index c37a20581..149b9070a 100644 --- a/src/becca/entities/bblob.ts +++ b/src/becca/entities/bblob.ts @@ -1,6 +1,6 @@ import { BlobRow } from "./rows"; -// FIXME: Why this does not extend the abstract becca? +// TODO: Why this does not extend the abstract becca? class BBlob { static get entityName() { return "blobs"; } static get primaryKeyName() { return "blobId"; } diff --git a/src/becca/entities/bnote.ts b/src/becca/entities/bnote.ts index 26214e608..821e10443 100644 --- a/src/becca/entities/bnote.ts +++ b/src/becca/entities/bnote.ts @@ -216,7 +216,7 @@ class BNote extends AbstractBeccaEntity { * - changes in the note metadata or title should not trigger note content sync (so we keep separate utcDateModified and entity changes records) * - but to the user note content and title changes are one and the same - single dateModified (so all changes must go through Note and content is not a separate entity) */ - // FIXME: original declaration was (string | Buffer), but everywhere it's used as a string. + // TODO: original declaration was (string | Buffer), but everywhere it's used as a string. getContent(): string { return this._getContent() as string; } @@ -900,7 +900,7 @@ class BNote extends AbstractBeccaEntity { const {searchResultNoteIds} = searchService.searchFromNote(this); const becca = this.becca; - return (searchResultNoteIds as string[]) // FIXME: remove cast once search is converted + return (searchResultNoteIds as string[]) // TODO: remove cast once search is converted .map(resultNoteId => becca.notes[resultNoteId]) .filter(note => !!note); } diff --git a/src/becca/entities/brevision.ts b/src/becca/entities/brevision.ts index 43c6631de..9b5e4a410 100644 --- a/src/becca/entities/brevision.ts +++ b/src/becca/entities/brevision.ts @@ -88,7 +88,7 @@ class BRevision extends AbstractBeccaEntity { * * This is the same approach as is used for Note's content. */ - // FIXME: initial declaration included Buffer, but everywhere it's treated as a string. + // TODO: initial declaration included Buffer, but everywhere it's treated as a string. getContent(): string { return this._getContent() as string; } diff --git a/src/becca/entities/rows.ts b/src/becca/entities/rows.ts index c372b30c3..567f14f9f 100644 --- a/src/becca/entities/rows.ts +++ b/src/becca/entities/rows.ts @@ -1,4 +1,4 @@ -// FIXME: Booleans should probably be numbers instead (as SQLite does not have booleans.); +// TODO: Booleans should probably be numbers instead (as SQLite does not have booleans.); export interface AttachmentRow { attachmentId?: string; diff --git a/src/services/encryption/password.ts b/src/services/encryption/password.ts index 266034d35..c14e27700 100644 --- a/src/services/encryption/password.ts +++ b/src/services/encryption/password.ts @@ -31,7 +31,7 @@ function changePassword(currentPassword: string, newPassword: string) { const newPasswordVerificationKey = utils.toBase64(myScryptService.getVerificationHash(newPassword)); if (decryptedDataKey) { - // FIXME: what should happen if the decrypted data key is null? + // TODO: what should happen if the decrypted data key is null? passwordEncryptionService.setDataKey(newPassword, decryptedDataKey); } diff --git a/src/services/utils.ts b/src/services/utils.ts index 4cbb96d2f..dc6129770 100644 --- a/src/services/utils.ts +++ b/src/services/utils.ts @@ -82,7 +82,7 @@ function unescapeHtml(str: string) { } function toObject(array: T[], fn: (item: T) => [K, V]): Record { - const obj: Record = {} as Record; // FIXME: unsafe? + const obj: Record = {} as Record; // TODO: unsafe? for (const item of array) { const ret = fn(item); @@ -98,7 +98,7 @@ function stripTags(text: string) { } function union(a: T[], b: T[]): T[] { - const obj: Record = {} as Record; // FIXME: unsafe? + const obj: Record = {} as Record; // TODO: unsafe? for (let i = a.length-1; i >= 0; i--) { obj[a[i]] = a[i]; From 9f6a8dc75c18ad079a2a65b16f6a080aace10ad7 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sun, 17 Mar 2024 21:34:50 +0200 Subject: [PATCH 46/49] server-ts: Fix undefined in ws --- src/services/ws.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/services/ws.ts b/src/services/ws.ts index 461b0e650..575b6456b 100644 --- a/src/services/ws.ts +++ b/src/services/ws.ts @@ -29,10 +29,10 @@ let lastSyncedPush: number | null = null; interface Message { type: string; data?: { - lastSyncedPush?: number, + lastSyncedPush?: number | null, entityChanges?: any[] }, - lastSyncedPush?: number, + lastSyncedPush?: number | null, progressCount?: number; taskId?: string; @@ -222,7 +222,7 @@ function sendPing(client: WebSocket, entityChangeIds = []) { sendMessage(client, { type: 'frontend-update', data: { - lastSyncedPush: lastSyncedPush || undefined, + lastSyncedPush, entityChanges } }); @@ -237,19 +237,19 @@ function sendTransactionEntityChangesToAllClients() { } function syncPullInProgress() { - sendMessageToAllClients({ type: 'sync-pull-in-progress', lastSyncedPush: lastSyncedPush || undefined }); + sendMessageToAllClients({ type: 'sync-pull-in-progress', lastSyncedPush }); } function syncPushInProgress() { - sendMessageToAllClients({ type: 'sync-push-in-progress', lastSyncedPush: lastSyncedPush || undefined }); + sendMessageToAllClients({ type: 'sync-push-in-progress', lastSyncedPush }); } function syncFinished() { - sendMessageToAllClients({ type: 'sync-finished', lastSyncedPush: lastSyncedPush || undefined }); + sendMessageToAllClients({ type: 'sync-finished', lastSyncedPush }); } function syncFailed() { - sendMessageToAllClients({ type: 'sync-failed', lastSyncedPush: lastSyncedPush || undefined }); + sendMessageToAllClients({ type: 'sync-failed', lastSyncedPush }); } function reloadFrontend(reason: string) { From 040ed39a4e148f8a39ff2a4e4b418ae10853b74b Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sun, 17 Mar 2024 21:37:40 +0200 Subject: [PATCH 47/49] server-ts: Fix undefined in task_context --- src/services/task_context.ts | 6 +++--- src/services/ws.ts | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/services/task_context.ts b/src/services/task_context.ts index 78ab6b10c..7a16a2645 100644 --- a/src/services/task_context.ts +++ b/src/services/task_context.ts @@ -49,7 +49,7 @@ class TaskContext { type: 'taskProgressCount', taskId: this.taskId, taskType: this.taskType, - data: this.data || undefined, + data: this.data, progressCount: this.progressCount }); } @@ -60,7 +60,7 @@ class TaskContext { type: 'taskError', taskId: this.taskId, taskType: this.taskType, - data: this.data || undefined, + data: this.data, message: message }); } @@ -70,7 +70,7 @@ class TaskContext { type: 'taskSucceeded', taskId: this.taskId, taskType: this.taskType, - data: this.data || undefined, + data: this.data, result: result }); } diff --git a/src/services/ws.ts b/src/services/ws.ts index 575b6456b..87caddcba 100644 --- a/src/services/ws.ts +++ b/src/services/ws.ts @@ -31,7 +31,7 @@ interface Message { data?: { lastSyncedPush?: number | null, entityChanges?: any[] - }, + } | null, lastSyncedPush?: number | null, progressCount?: number; @@ -142,7 +142,7 @@ function fillInAdditionalProperties(entityChange: EntityChange) { if (!entityChange.entity) { entityChange.entity = sql.getRow(`SELECT * FROM notes WHERE noteId = ?`, [entityChange.entityId]); - if (entityChange.entity && entityChange.entity.isProtected) { + if (entityChange.entity?.isProtected) { entityChange.entity.title = protectedSessionService.decryptString(entityChange.entity.title || ""); } } @@ -157,7 +157,7 @@ function fillInAdditionalProperties(entityChange: EntityChange) { if (parentNote) { for (const childBranch of parentNote.getChildBranches()) { - if (childBranch && childBranch.branchId) { + if (childBranch?.branchId) { entityChange.positions[childBranch.branchId] = childBranch.notePosition; } } From cbad58201e976140d01582485e11382321e1aca2 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sun, 17 Mar 2024 21:40:14 +0200 Subject: [PATCH 48/49] server-ts: Solve requested changes --- src/becca/similarity.js | 2 +- .../promoted_attribute_definition_parser.ts | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/becca/similarity.js b/src/becca/similarity.js index b0ed39e13..07f643a7d 100644 --- a/src/becca/similarity.js +++ b/src/becca/similarity.js @@ -35,7 +35,7 @@ const IGNORED_ATTR_NAMES = [ function filterUrlValue(value) { return value .replace(/https?:\/\//ig, "") - .replace(/www\./ig, "") + .replace(/www.js\./ig, "") .replace(/(\.net|\.com|\.org|\.info|\.edu)/ig, ""); } diff --git a/src/services/promoted_attribute_definition_parser.ts b/src/services/promoted_attribute_definition_parser.ts index cd3dc18db..3efe16f4d 100644 --- a/src/services/promoted_attribute_definition_parser.ts +++ b/src/services/promoted_attribute_definition_parser.ts @@ -1,15 +1,15 @@ interface DefinitionObject { - isPromoted: boolean; - labelType: string; - multiplicity: string; - numberPrecision: number; - promotedAlias: string; - inverseRelation: string; + isPromoted?: boolean; + labelType?: string; + multiplicity?: string; + numberPrecision?: number; + promotedAlias?: string; + inverseRelation?: string; } function parse(value: string): DefinitionObject { const tokens = value.split(',').map(t => t.trim()); - const defObj: Partial = {}; + const defObj: DefinitionObject = {}; for (const token of tokens) { if (token === 'promoted') { @@ -41,7 +41,7 @@ function parse(value: string): DefinitionObject { } } - return defObj as DefinitionObject; + return defObj; } export = { From 3eb7ed5ddafbec0d8072d9baa2fe21c489f6d5aa Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 30 Mar 2024 10:49:40 +0200 Subject: [PATCH 49/49] server-ts: Address requested changes --- .../0220__migrate_images_to_attachments.js | 4 ++-- dump-db/inc/dump.js | 8 ++++---- package-lock.json | 8 +++++--- package.json | 2 +- src/becca/becca-interface.ts | 12 ++++++++---- src/becca/becca_loader.js | 8 ++++---- src/becca/entities/abstract_becca_entity.ts | 16 +++++++++++----- src/becca/entities/battachment.ts | 2 +- src/becca/entities/brevision.ts | 2 +- src/services/blob.ts | 2 +- tsconfig.json | 4 ++-- 11 files changed, 40 insertions(+), 28 deletions(-) diff --git a/db/migrations/0220__migrate_images_to_attachments.js b/db/migrations/0220__migrate_images_to_attachments.js index e949626ef..a9b2bfdbf 100644 --- a/db/migrations/0220__migrate_images_to_attachments.js +++ b/db/migrations/0220__migrate_images_to_attachments.js @@ -1,6 +1,6 @@ module.exports = () => { const beccaLoader = require('../../src/becca/becca_loader.js'); - const becca = require('../../src/becca/becca.js'); + const becca = require('../../src/becca/becca'); const cls = require('../../src/services/cls'); const log = require('../../src/services/log'); const sql = require('../../src/services/sql'); @@ -13,7 +13,7 @@ module.exports = () => { for (const note of Object.values(becca.notes)) { try { - const attachment = note.convertToParentAttachment({autoConversion: true}); + const attachment = note.convertToParentAttachment({ autoConversion: true }); if (attachment) { log.info(`Auto-converted note '${note.noteId}' into attachment '${attachment.attachmentId}'.`); diff --git a/dump-db/inc/dump.js b/dump-db/inc/dump.js index 7e3c1e1b3..35191ded6 100644 --- a/dump-db/inc/dump.js +++ b/dump-db/inc/dump.js @@ -1,6 +1,6 @@ const fs = require("fs"); const sanitize = require("sanitize-filename"); -const sql = require('./sql'); +const sql = require('./sql.js'); const decryptService = require('./decrypt.js'); const dataKeyService = require('./data_key.js'); const extensionService = require('./extension.js'); @@ -74,7 +74,7 @@ function dumpDocument(documentPath, targetPath, options) { return; } - let {content} = sql.getRow("SELECT content FROM blobs WHERE blobId = ?", [noteRow.blobId]); + let { content } = sql.getRow("SELECT content FROM blobs WHERE blobId = ?", [noteRow.blobId]); if (content !== null && noteRow.isProtected && dataKey) { content = decryptService.decrypt(dataKey, content); @@ -108,7 +108,7 @@ function dumpDocument(documentPath, targetPath, options) { } try { - fs.mkdirSync(childTargetPath, {recursive: true}); + fs.mkdirSync(childTargetPath, { recursive: true }); } catch (e) { console.error(`DUMPERROR: Creating directory ${childTargetPath} failed with error '${e.message}'`); @@ -157,7 +157,7 @@ function validatePaths(documentPath, targetPath) { } if (!fs.existsSync(targetPath)) { - const ret = fs.mkdirSync(targetPath, {recursive: true}); + const ret = fs.mkdirSync(targetPath, { recursive: true }); if (!ret) { console.error(`Target path '${targetPath}' could not be created. Run with --help to see usage.`); diff --git a/package-lock.json b/package-lock.json index d7484da34..283832065 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,19 +1,18 @@ { "name": "trilium", - "version": "0.63.3", + "version": "0.63.5", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "trilium", - "version": "0.63.3", + "version": "0.63.5", "hasInstallScript": true, "license": "AGPL-3.0-only", "dependencies": { "@braintree/sanitize-url": "6.0.4", "@electron/remote": "2.1.2", "@excalidraw/excalidraw": "0.17.3", - "@types/cls-hooked": "^4.3.8", "archiver": "7.0.0", "async-mutex": "0.4.1", "axios": "1.6.7", @@ -90,6 +89,7 @@ }, "devDependencies": { "@types/better-sqlite3": "^7.6.9", + "@types/cls-hooked": "^4.3.8", "@types/escape-html": "^1.0.4", "@types/express": "^4.17.21", "@types/ini": "^4.1.0", @@ -1201,6 +1201,7 @@ "version": "4.3.8", "resolved": "https://registry.npmjs.org/@types/cls-hooked/-/cls-hooked-4.3.8.tgz", "integrity": "sha512-tf/7H883gFA6MPlWI15EQtfNZ+oPL0gLKkOlx9UHFrun1fC/FkuyNBpTKq1B5E3T4fbvjId6WifHUdSGsMMuPg==", + "dev": true, "dependencies": { "@types/node": "*" } @@ -13991,6 +13992,7 @@ "version": "4.3.8", "resolved": "https://registry.npmjs.org/@types/cls-hooked/-/cls-hooked-4.3.8.tgz", "integrity": "sha512-tf/7H883gFA6MPlWI15EQtfNZ+oPL0gLKkOlx9UHFrun1fC/FkuyNBpTKq1B5E3T4fbvjId6WifHUdSGsMMuPg==", + "dev": true, "requires": { "@types/node": "*" } diff --git a/package.json b/package.json index 438c001ea..5466a2e90 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,6 @@ "@braintree/sanitize-url": "6.0.4", "@electron/remote": "2.1.2", "@excalidraw/excalidraw": "0.17.3", - "@types/cls-hooked": "^4.3.8", "archiver": "7.0.0", "async-mutex": "0.4.1", "axios": "1.6.7", @@ -111,6 +110,7 @@ }, "devDependencies": { "@types/better-sqlite3": "^7.6.9", + "@types/cls-hooked": "^4.3.8", "@types/escape-html": "^1.0.4", "@types/express": "^4.17.21", "@types/ini": "^4.1.0", diff --git a/src/becca/becca-interface.ts b/src/becca/becca-interface.ts index 4c8218797..10495fc7a 100644 --- a/src/becca/becca-interface.ts +++ b/src/becca/becca-interface.ts @@ -11,6 +11,7 @@ import BAttachment = require('./entities/battachment'); import { AttachmentRow, RevisionRow } from './entities/rows'; import BBlob = require('./entities/bblob'); import BRecentNote = require('./entities/brecent_note'); +import AbstractBeccaEntity = require('./entities/abstract_becca_entity'); interface AttachmentOpts { includeContentLength?: boolean; @@ -95,7 +96,7 @@ class Becca { return this.notes[noteId]; } - getNoteOrThrow(noteId: string): BNote | null { + getNoteOrThrow(noteId: string): BNote { const note = this.notes[noteId]; if (!note) { throw new NotFoundError(`Note '${noteId}' doesn't exist.`); @@ -190,7 +191,11 @@ class Becca { .map(row => new BAttachment(row)); } - getBlob(entity: { blobId: string }): BBlob | null { + getBlob(entity: { blobId?: string }): BBlob | null { + if (!entity.blobId) { + return null; + } + const row = sql.getRow("SELECT *, LENGTH(content) AS contentLength FROM blobs WHERE blobId = ?", [entity.blobId]); const BBlob = require('./entities/bblob'); // avoiding circular dependency problems @@ -209,8 +214,7 @@ class Becca { return this.etapiTokens[etapiTokenId]; } - /** @returns {AbstractBeccaEntity|null} */ - getEntity(entityName: string, entityId: string) { + getEntity>(entityName: string, entityId: string): AbstractBeccaEntity | null { if (!entityName || !entityId) { return null; } diff --git a/src/becca/becca_loader.js b/src/becca/becca_loader.js index f0f0ccccd..a3004d9b7 100644 --- a/src/becca/becca_loader.js +++ b/src/becca/becca_loader.js @@ -18,7 +18,7 @@ const beccaLoaded = new Promise((res, rej) => { cls.init(() => { load(); - require('../services/options_init').initStartupOptions(); + require('../services/options_init.js').initStartupOptions(); res(); }); @@ -74,7 +74,7 @@ function reload(reason) { require('../services/ws').reloadFrontend(reason || "becca reloaded"); } -eventService.subscribeBeccaLoader([eventService.ENTITY_CHANGE_SYNCED], ({entityName, entityRow}) => { +eventService.subscribeBeccaLoader([eventService.ENTITY_CHANGE_SYNCED], ({ entityName, entityRow }) => { if (!becca.loaded) { return; } @@ -97,7 +97,7 @@ eventService.subscribeBeccaLoader([eventService.ENTITY_CHANGE_SYNCED], ({entity postProcessEntityUpdate(entityName, entityRow); }); -eventService.subscribeBeccaLoader(eventService.ENTITY_CHANGED, ({entityName, entity}) => { +eventService.subscribeBeccaLoader(eventService.ENTITY_CHANGED, ({ entityName, entity }) => { if (!becca.loaded) { return; } @@ -124,7 +124,7 @@ function postProcessEntityUpdate(entityName, entityRow) { } } -eventService.subscribeBeccaLoader([eventService.ENTITY_DELETED, eventService.ENTITY_DELETE_SYNCED], ({entityName, entityId}) => { +eventService.subscribeBeccaLoader([eventService.ENTITY_DELETED, eventService.ENTITY_DELETE_SYNCED], ({ entityName, entityId }) => { if (!becca.loaded) { return; } diff --git a/src/becca/entities/abstract_becca_entity.ts b/src/becca/entities/abstract_becca_entity.ts index 74f1163ae..1c775b51e 100644 --- a/src/becca/entities/abstract_becca_entity.ts +++ b/src/becca/entities/abstract_becca_entity.ts @@ -18,6 +18,10 @@ interface ContentOpts { forceFrontendReload?: boolean; } +/** + * This interface contains the data that is shared across all the objects of a given derived class of {@link AbstractBeccaEntity}. + * For example, all BAttributes will share their content, but all BBranches will have another set of this data. + */ interface ConstructorData> { primaryKeyName: string; entityName: string; @@ -26,6 +30,8 @@ interface ConstructorData> { /** * Base class for all backend entities. + * + * @type T the same entity type needed for self-reference in {@link ConstructorData}. */ abstract class AbstractBeccaEntity> { @@ -33,10 +39,10 @@ abstract class AbstractBeccaEntity> { protected utcDateModified?: string; protected dateCreated?: string; protected dateModified?: string; - protected isProtected?: boolean; - protected isSynced?: boolean; - protected blobId?: string; + isProtected?: boolean; + isSynced?: boolean; + blobId?: string; protected beforeSaving() { const constructorData = (this.constructor as unknown as ConstructorData); @@ -45,7 +51,7 @@ abstract class AbstractBeccaEntity> { } } - protected getUtcDateChanged() { + getUtcDateChanged() { return this.utcDateModified || this.utcDateCreated; } @@ -69,7 +75,7 @@ abstract class AbstractBeccaEntity> { }); } - protected generateHash(isDeleted: boolean): string { + generateHash(isDeleted?: boolean): string { const constructorData = (this.constructor as unknown as ConstructorData); let contentToHash = ""; diff --git a/src/becca/entities/battachment.ts b/src/becca/entities/battachment.ts index 44935ee04..206c03286 100644 --- a/src/becca/entities/battachment.ts +++ b/src/becca/entities/battachment.ts @@ -131,7 +131,7 @@ class BAttachment extends AbstractBeccaEntity { return this._getContent(); } - setContent(content: any, opts: ContentOpts) { + setContent(content: string | Buffer, opts: ContentOpts) { this._setContent(content, opts); } diff --git a/src/becca/entities/brevision.ts b/src/becca/entities/brevision.ts index b946bd54e..ba7cc00ba 100644 --- a/src/becca/entities/brevision.ts +++ b/src/becca/entities/brevision.ts @@ -115,7 +115,7 @@ class BRevision extends AbstractBeccaEntity { } } - setContent(content: any, opts: ContentOpts = {}) { + setContent(content: string | Buffer, opts: ContentOpts = {}) { this._setContent(content, opts); } diff --git a/src/services/blob.ts b/src/services/blob.ts index cfdd939c6..fac1adfad 100644 --- a/src/services/blob.ts +++ b/src/services/blob.ts @@ -20,7 +20,7 @@ function getBlobPojo(entityName: string, entityId: string) { if (!entity.hasStringContent()) { pojo.content = null; } else { - pojo.content = processContent(pojo.content, entity.isProtected, true); + pojo.content = processContent(pojo.content, !!entity.isProtected, true); } return pojo; diff --git a/tsconfig.json b/tsconfig.json index 50d8ce89c..0ce95ff39 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,10 +3,10 @@ "moduleResolution": "Node", "declaration": false, "sourceMap": true, - "outDir": "./build", + "outDir": "./dist", "strict": true, "noImplicitAny": true, - "lib": ["ES2021"] + "lib": ["ES2022"] }, "include": [ "./src/**/*.js",