diff --git a/package-lock.json b/package-lock.json index a2a3a6d2..f3ef0f8b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -32,6 +32,7 @@ "@lingui/loader": "^3.13.3", "@lingui/react": "^3.13.3", "@pmmmwh/react-refresh-webpack-plugin": "^0.5.5", + "@seald-io/nedb": "^3.0.0", "@types/bencode": "^2.0.1", "@types/body-parser": "^1.19.2", "@types/compression": "^1.7.2", @@ -114,7 +115,6 @@ "mobx": "^6.5.0", "mobx-react": "^7.3.0", "morgan": "^1.10.0", - "nedb-promises": "^5.0.3", "overlayscrollbars": "^1.13.1", "overlayscrollbars-react": "^0.2.3", "parse-torrent": "^9.1.5", @@ -3160,22 +3160,16 @@ "dev": true }, "node_modules/@seald-io/nedb": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/@seald-io/nedb/-/nedb-2.2.0.tgz", - "integrity": "sha512-whkcx3hpcowNhoSEbIsrfe8TXxDwyj8SJJut2EqF7DSX2GGqQlL7Ix/vzwwOo4FJolzDhZD2DaUTVKmTQS3Rog==", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/@seald-io/nedb/-/nedb-3.0.0.tgz", + "integrity": "sha512-nJLQPbosz84BlJdE9qLRbIfQDYpB7PPMi6yGfQbN7YoWsnGef/sIFLDGWcV/rqsOfzJD5wtQYEcA42MIDerFvg==", "dev": true, "dependencies": { "@seald-io/binary-search-tree": "^1.0.2", - "async": "0.2.10", - "localforage": "^1.9.0" + "localforage": "^1.9.0", + "util": "^0.12.4" } }, - "node_modules/@seald-io/nedb/node_modules/async": { - "version": "0.2.10", - "resolved": "https://registry.npmjs.org/async/-/async-0.2.10.tgz", - "integrity": "sha1-trvgsGdLnXGXCMo43owjfLUmw9E=", - "dev": true - }, "node_modules/@sinonjs/commons": { "version": "1.8.3", "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.8.3.tgz", @@ -5189,6 +5183,18 @@ "postcss": "^8.1.0" } }, + "node_modules/available-typed-arrays": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.5.tgz", + "integrity": "sha512-DMD0KiN46eipeziST1LPP/STfDU0sufISXmjSgvVsoU2tqxctQeASejWcfNtxYKqETM1UxQ8sp2OrSBWpHY6sw==", + "dev": true, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/axe-core": { "version": "4.3.5", "resolved": "https://registry.npmjs.org/axe-core/-/axe-core-4.3.5.tgz", @@ -9116,6 +9122,12 @@ } } }, + "node_modules/foreach": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/foreach/-/foreach-2.0.5.tgz", + "integrity": "sha1-C+4AUBiusmDQo6865ljdATbsG5k=", + "dev": true + }, "node_modules/fork-ts-checker-webpack-plugin": { "version": "6.5.0", "resolved": "https://registry.npmjs.org/fork-ts-checker-webpack-plugin/-/fork-ts-checker-webpack-plugin-6.5.0.tgz", @@ -10228,6 +10240,22 @@ "url": "https://github.com/sponsors/wooorm" } }, + "node_modules/is-arguments": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/is-arguments/-/is-arguments-1.1.1.tgz", + "integrity": "sha512-8Q7EARjzEnKpt/PCD7e1cgUS0a6X8u5tdSiMqXhojOdoV9TsMsiO+9VLC5vAmO8N7/GmXn7yjR8qnA6bVAEzfA==", + "dev": true, + "dependencies": { + "call-bind": "^1.0.2", + "has-tostringtag": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/is-arrayish": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.2.1.tgz", @@ -10406,6 +10434,21 @@ "node": ">=6" } }, + "node_modules/is-generator-function": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/is-generator-function/-/is-generator-function-1.0.10.tgz", + "integrity": "sha512-jsEjy9l3yiXEQ+PsXdmBwEPcOxaXWLspKdplFUVI9vq1iZgIekeC0L167qeu86czQaxed3q/Uzuw0swL0irL8A==", + "dev": true, + "dependencies": { + "has-tostringtag": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/is-glob": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", @@ -10563,6 +10606,25 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/is-typed-array": { + "version": "1.1.8", + "resolved": "https://registry.npmjs.org/is-typed-array/-/is-typed-array-1.1.8.tgz", + "integrity": "sha512-HqH41TNZq2fgtGT8WHVFVJhBVGuY3AnP3Q36K8JKXUxSxRgk/d+7NjmwG2vo2mYmXK8UYZKu0qH8bVP5gEisjA==", + "dev": true, + "dependencies": { + "available-typed-arrays": "^1.0.5", + "call-bind": "^1.0.2", + "es-abstract": "^1.18.5", + "foreach": "^2.0.5", + "has-tostringtag": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/is-typedarray": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz", @@ -12601,15 +12663,6 @@ "integrity": "sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=", "dev": true }, - "node_modules/nedb-promises": { - "version": "5.0.3", - "resolved": "https://registry.npmjs.org/nedb-promises/-/nedb-promises-5.0.3.tgz", - "integrity": "sha512-hqQZi/T3dMJXQraFohVdatNX1uPDTGuVrqMiEnwA0dJxlC90xctOFG+jeUzPy9hYQGqCV+CpkSBkvUvTJdUApQ==", - "dev": true, - "dependencies": { - "@seald-io/nedb": "^2.2.0" - } - }, "node_modules/negotiator": { "version": "0.6.3", "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", @@ -16741,6 +16794,20 @@ "integrity": "sha1-9F8VDExm7uloGGUFq5P8u4rWv2E=", "dev": true }, + "node_modules/util": { + "version": "0.12.4", + "resolved": "https://registry.npmjs.org/util/-/util-0.12.4.tgz", + "integrity": "sha512-bxZ9qtSlGUWSOy9Qa9Xgk11kSslpuZwaxCg4sNIDj6FLucDab2JxnHwyNTCpHMtK1MjoQiWQ6DiUMZYbSrO+Sw==", + "dev": true, + "dependencies": { + "inherits": "^2.0.3", + "is-arguments": "^1.0.4", + "is-generator-function": "^1.0.7", + "is-typed-array": "^1.1.3", + "safe-buffer": "^5.1.2", + "which-typed-array": "^1.1.2" + } + }, "node_modules/util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", @@ -17341,6 +17408,26 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/which-typed-array": { + "version": "1.1.7", + "resolved": "https://registry.npmjs.org/which-typed-array/-/which-typed-array-1.1.7.tgz", + "integrity": "sha512-vjxaB4nfDqwKI0ws7wZpxIlde1XrLX5uB0ZjpfshgmapJMD7jJWhZI+yToJTqaFByF0eNBcYxbjmCzoRP7CfEw==", + "dev": true, + "dependencies": { + "available-typed-arrays": "^1.0.5", + "call-bind": "^1.0.2", + "es-abstract": "^1.18.5", + "foreach": "^2.0.5", + "has-tostringtag": "^1.0.0", + "is-typed-array": "^1.1.7" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/word-wrap": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz", @@ -19710,22 +19797,14 @@ "dev": true }, "@seald-io/nedb": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/@seald-io/nedb/-/nedb-2.2.0.tgz", - "integrity": "sha512-whkcx3hpcowNhoSEbIsrfe8TXxDwyj8SJJut2EqF7DSX2GGqQlL7Ix/vzwwOo4FJolzDhZD2DaUTVKmTQS3Rog==", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/@seald-io/nedb/-/nedb-3.0.0.tgz", + "integrity": "sha512-nJLQPbosz84BlJdE9qLRbIfQDYpB7PPMi6yGfQbN7YoWsnGef/sIFLDGWcV/rqsOfzJD5wtQYEcA42MIDerFvg==", "dev": true, "requires": { "@seald-io/binary-search-tree": "^1.0.2", - "async": "0.2.10", - "localforage": "^1.9.0" - }, - "dependencies": { - "async": { - "version": "0.2.10", - "resolved": "https://registry.npmjs.org/async/-/async-0.2.10.tgz", - "integrity": "sha1-trvgsGdLnXGXCMo43owjfLUmw9E=", - "dev": true - } + "localforage": "^1.9.0", + "util": "^0.12.4" } }, "@sinonjs/commons": { @@ -21412,6 +21491,12 @@ "postcss-value-parser": "^4.2.0" } }, + "available-typed-arrays": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.5.tgz", + "integrity": "sha512-DMD0KiN46eipeziST1LPP/STfDU0sufISXmjSgvVsoU2tqxctQeASejWcfNtxYKqETM1UxQ8sp2OrSBWpHY6sw==", + "dev": true + }, "axe-core": { "version": "4.3.5", "resolved": "https://registry.npmjs.org/axe-core/-/axe-core-4.3.5.tgz", @@ -24394,6 +24479,12 @@ "integrity": "sha512-MQDfihBQYMcyy5dhRDJUHcw7lb2Pv/TuE6xP1vyraLukNDHKbDxDNaOE3NbCAdKQApno+GPRyo1YAp89yCjK4w==", "dev": true }, + "foreach": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/foreach/-/foreach-2.0.5.tgz", + "integrity": "sha1-C+4AUBiusmDQo6865ljdATbsG5k=", + "dev": true + }, "fork-ts-checker-webpack-plugin": { "version": "6.5.0", "resolved": "https://registry.npmjs.org/fork-ts-checker-webpack-plugin/-/fork-ts-checker-webpack-plugin-6.5.0.tgz", @@ -25212,6 +25303,16 @@ "is-decimal": "^1.0.0" } }, + "is-arguments": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/is-arguments/-/is-arguments-1.1.1.tgz", + "integrity": "sha512-8Q7EARjzEnKpt/PCD7e1cgUS0a6X8u5tdSiMqXhojOdoV9TsMsiO+9VLC5vAmO8N7/GmXn7yjR8qnA6bVAEzfA==", + "dev": true, + "requires": { + "call-bind": "^1.0.2", + "has-tostringtag": "^1.0.0" + } + }, "is-arrayish": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.2.1.tgz", @@ -25318,6 +25419,15 @@ "integrity": "sha512-cTIB4yPYL/Grw0EaSzASzg6bBy9gqCofvWN8okThAYIxKJZC+udlRAmGbM0XLeniEJSs8uEgHPGuHSe1XsOLSQ==", "dev": true }, + "is-generator-function": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/is-generator-function/-/is-generator-function-1.0.10.tgz", + "integrity": "sha512-jsEjy9l3yiXEQ+PsXdmBwEPcOxaXWLspKdplFUVI9vq1iZgIekeC0L167qeu86czQaxed3q/Uzuw0swL0irL8A==", + "dev": true, + "requires": { + "has-tostringtag": "^1.0.0" + } + }, "is-glob": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", @@ -25418,6 +25528,19 @@ "has-symbols": "^1.0.2" } }, + "is-typed-array": { + "version": "1.1.8", + "resolved": "https://registry.npmjs.org/is-typed-array/-/is-typed-array-1.1.8.tgz", + "integrity": "sha512-HqH41TNZq2fgtGT8WHVFVJhBVGuY3AnP3Q36K8JKXUxSxRgk/d+7NjmwG2vo2mYmXK8UYZKu0qH8bVP5gEisjA==", + "dev": true, + "requires": { + "available-typed-arrays": "^1.0.5", + "call-bind": "^1.0.2", + "es-abstract": "^1.18.5", + "foreach": "^2.0.5", + "has-tostringtag": "^1.0.0" + } + }, "is-typedarray": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz", @@ -27012,15 +27135,6 @@ "integrity": "sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=", "dev": true }, - "nedb-promises": { - "version": "5.0.3", - "resolved": "https://registry.npmjs.org/nedb-promises/-/nedb-promises-5.0.3.tgz", - "integrity": "sha512-hqQZi/T3dMJXQraFohVdatNX1uPDTGuVrqMiEnwA0dJxlC90xctOFG+jeUzPy9hYQGqCV+CpkSBkvUvTJdUApQ==", - "dev": true, - "requires": { - "@seald-io/nedb": "^2.2.0" - } - }, "negotiator": { "version": "0.6.3", "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", @@ -30050,6 +30164,20 @@ "integrity": "sha1-9F8VDExm7uloGGUFq5P8u4rWv2E=", "dev": true }, + "util": { + "version": "0.12.4", + "resolved": "https://registry.npmjs.org/util/-/util-0.12.4.tgz", + "integrity": "sha512-bxZ9qtSlGUWSOy9Qa9Xgk11kSslpuZwaxCg4sNIDj6FLucDab2JxnHwyNTCpHMtK1MjoQiWQ6DiUMZYbSrO+Sw==", + "dev": true, + "requires": { + "inherits": "^2.0.3", + "is-arguments": "^1.0.4", + "is-generator-function": "^1.0.7", + "is-typed-array": "^1.1.3", + "safe-buffer": "^5.1.2", + "which-typed-array": "^1.1.2" + } + }, "util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", @@ -30495,6 +30623,20 @@ "is-symbol": "^1.0.3" } }, + "which-typed-array": { + "version": "1.1.7", + "resolved": "https://registry.npmjs.org/which-typed-array/-/which-typed-array-1.1.7.tgz", + "integrity": "sha512-vjxaB4nfDqwKI0ws7wZpxIlde1XrLX5uB0ZjpfshgmapJMD7jJWhZI+yToJTqaFByF0eNBcYxbjmCzoRP7CfEw==", + "dev": true, + "requires": { + "available-typed-arrays": "^1.0.5", + "call-bind": "^1.0.2", + "es-abstract": "^1.18.5", + "foreach": "^2.0.5", + "has-tostringtag": "^1.0.0", + "is-typed-array": "^1.1.7" + } + }, "word-wrap": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz", diff --git a/package.json b/package.json index 20b9f1ad..9ca7cbb5 100644 --- a/package.json +++ b/package.json @@ -81,6 +81,7 @@ "@lingui/loader": "^3.13.3", "@lingui/react": "^3.13.3", "@pmmmwh/react-refresh-webpack-plugin": "^0.5.5", + "@seald-io/nedb": "^3.0.0", "@types/bencode": "^2.0.1", "@types/body-parser": "^1.19.2", "@types/compression": "^1.7.2", @@ -163,7 +164,6 @@ "mobx": "^6.5.0", "mobx-react": "^7.3.0", "morgan": "^1.10.0", - "nedb-promises": "^5.0.3", "overlayscrollbars": "^1.13.1", "overlayscrollbars-react": "^0.2.3", "parse-torrent": "^9.1.5", diff --git a/server/models/HistoryEra.ts b/server/models/HistoryEra.ts index 4043b38b..4fa2ec80 100644 --- a/server/models/HistoryEra.ts +++ b/server/models/HistoryEra.ts @@ -1,6 +1,6 @@ import type {TransferData, TransferSnapshot} from '@shared/types/TransferData'; -import Datastore from 'nedb-promises'; +import Datastore from '@seald-io/nedb'; import {setInterval} from 'timers'; import config from '../../config'; @@ -20,7 +20,7 @@ class HistoryEra { constructor(opts: HistoryEraOpts) { this.opts = opts; - this.db = Datastore.create(); + this.db = new Datastore(); let cleanupInterval = this.opts.maxTime; @@ -33,7 +33,7 @@ class HistoryEra { private removeOutdatedData = (): Promise => { const minTimestamp = Date.now() - this.opts.maxTime; - return this.db.remove({timestamp: {$lt: minTimestamp}}, {multi: true}).then( + return this.db.removeAsync({timestamp: {$lt: minTimestamp}}, {multi: true}).then( () => undefined, () => undefined, ); @@ -45,13 +45,13 @@ class HistoryEra { if (currentTime - this.lastUpdate >= this.opts.interval - CUMULATIVE_DATA_BUFFER_DIFF) { this.lastUpdate = currentTime; await this.db - .insert({ + .insertAsync({ timestamp: currentTime, ...data, }) .catch(() => undefined); } else { - await this.db.find({timestamp: this.lastUpdate}).then( + await this.db.findAsync({timestamp: this.lastUpdate}).then( async (snapshots) => { if (snapshots.length !== 0) { const snapshot = snapshots[0]; @@ -65,7 +65,7 @@ class HistoryEra { numUpdates: numUpdates + 1, }; - await this.db.update({timestamp: this.lastUpdate}, updatedSnapshot).catch(() => undefined); + await this.db.updateAsync({timestamp: this.lastUpdate}, updatedSnapshot).catch(() => undefined); } }, () => undefined, @@ -77,7 +77,7 @@ class HistoryEra { const minTimestamp = Date.now() - this.opts.maxTime; return this.db - .find({timestamp: {$gte: minTimestamp}}) + .findAsync({timestamp: {$gte: minTimestamp}}) .sort({timestamp: 1}) .then((snapshots) => snapshots.slice(snapshots.length - config.maxHistoryStates)); } diff --git a/server/models/Users.ts b/server/models/Users.ts index 7ad63709..81500f20 100644 --- a/server/models/Users.ts +++ b/server/models/Users.ts @@ -1,6 +1,6 @@ import {argon2id, argon2Verify} from 'hash-wasm'; import crypto from 'crypto'; -import Datastore from 'nedb-promises'; +import Datastore from '@seald-io/nedb'; import fs from 'fs'; import path from 'path'; @@ -25,7 +25,7 @@ const hashPassword = async (password: string): Promise => { class Users { private db = (() => { - const db = Datastore.create({ + const db = new Datastore({ autoload: true, filename: path.join(config.dbPath, 'users.db'), }); @@ -61,7 +61,7 @@ class Users { * @return {Promise} - Returns access level of the user if matched or rejects with error. */ async comparePassword(credentials: Pick): Promise { - return this.db.findOne({username: credentials.username}).then((user) => { + return this.db.findOneAsync({username: credentials.username}).then((user) => { // Wrong data provided if (credentials?.password == null) { throw new Error(); @@ -101,7 +101,7 @@ class Users { } return this.db - .insert({ + .insertAsync>({ ...credentials, password: hashed, timestamp: Math.ceil(Date.now() / 1000), @@ -112,7 +112,7 @@ class Users { } throw new Error(); - }); + }) as Promise; } /** @@ -122,7 +122,7 @@ class Users { * @return {Promise} - Returns ID of removed user or rejects with error. */ async removeUser(username: string): Promise { - return this.db.findOne({username}).then(async ({_id}) => { + return this.db.findOneAsync({username}).then(async ({_id}) => { destroyUserServices(_id); await this.db.remove({username}, {}); @@ -150,7 +150,7 @@ class Users { patch.timestamp = Math.ceil(Date.now() / 1000); } - return this.db.update({username}, {$set: patch}, {}).then((numUsersUpdated) => { + return this.db.updateAsync({username}, {$set: patch}, {}).then(({numAffected: numUsersUpdated}) => { if (numUsersUpdated === 0) { throw new Error(); } @@ -170,7 +170,7 @@ class Users { return this.getConfigUser(); } - return this.db.findOne({username}); + return this.db.findOneAsync({username}); } /** @@ -183,14 +183,14 @@ class Users { return [this.getConfigUser()]; } - return this.db.find({}); + return this.db.findAsync({}); } /** * Gets the number of users and route to appropriate handler. */ async initialUserGate(handlers: {handleInitialUser: () => void; handleSubsequentUser: () => void}): Promise { - const userCount = await this.db.count({}); + const userCount = await this.db.countAsync({}); if (userCount && userCount > 0) { return handlers.handleSubsequentUser(); diff --git a/server/services/feedService.ts b/server/services/feedService.ts index ce65fe6a..6ba97aa3 100644 --- a/server/services/feedService.ts +++ b/server/services/feedService.ts @@ -1,5 +1,5 @@ import path from 'path'; -import Datastore from 'nedb-promises'; +import Datastore from '@seald-io/nedb'; import type {FeedItem} from 'feedsub'; @@ -15,7 +15,7 @@ import type {FeedReaderOptions} from '../models/FeedReader'; class FeedService extends BaseService { rules: Record> = {}; feedReaders: Array = []; - db = Datastore.create({ + db = new Datastore({ autoload: true, filename: path.join(config.dbPath, this.user._id, 'settings', 'feeds.db'), }); @@ -28,7 +28,7 @@ class FeedService extends BaseService { this.onServicesUpdated = () => undefined; // Loads state from database. - const docs = await this.db.find({}).catch(() => undefined); + const docs = await this.db.findAsync({}).catch(() => undefined); if (docs == null) { return; @@ -128,7 +128,7 @@ class FeedService extends BaseService { throw new Error(); } - const newFeed = await this.db.insert>({type: 'feed', url, label, interval}); + const newFeed = (await this.db.insertAsync>({type: 'feed', url, label, interval})) as Feed; this.startNewFeed(newFeed); @@ -167,12 +167,12 @@ class FeedService extends BaseService { modifiedFeedReader.modify(JSON.parse(JSON.stringify({feedLabel: label, url, interval}))); return this.db - .update({_id: id}, {$set: JSON.parse(JSON.stringify({label, url, interval}))}, {}) + .updateAsync({_id: id}, {$set: JSON.parse(JSON.stringify({label, url, interval}))}, {}) .then(() => undefined); } async addRule(options: AddRuleOptions): Promise { - const newRule = await this.db.insert>({type: 'rule', ...options}); + const newRule = (await this.db.insertAsync>({type: 'rule', ...options})) as Rule; if (this.rules[newRule.feedIDs[0]] == null) { this.rules[newRule.feedIDs[0]] = []; @@ -192,7 +192,7 @@ class FeedService extends BaseService { } async getAll(): Promise<{feeds: Array; rules: Array}> { - return this.db.find({}).then((docs) => + return this.db.findAsync({}).then((docs) => docs.reduce( (memo: {feeds: Array; rules: Array}, item) => { if (item.type === 'feed') { @@ -211,7 +211,7 @@ class FeedService extends BaseService { } async getFeeds(id?: string): Promise> { - return this.db.find(id ? {_id: id} : {type: 'feed'}); + return this.db.findAsync(id ? {_id: id} : {type: 'feed'}); } async getItems(id: string, search: string): Promise> { @@ -242,12 +242,12 @@ class FeedService extends BaseService { async getPreviouslyMatchedUrls(): Promise> { return this.db - .find({type: 'matchedTorrents'}) + .findAsync({type: 'matchedTorrents'}) .then((docs) => docs.reduce((matchedUrls: Array, doc) => matchedUrls.concat(doc.urls), [])); } async getRules(): Promise> { - return this.db.find({type: 'rule'}); + return this.db.findAsync({type: 'rule'}); } handleNewItems = (feedReaderOptions: FeedReaderOptions, feedItems: Array): void => { @@ -334,7 +334,7 @@ class FeedService extends BaseService { this.rules[key] = rule.filter((rule) => rule._id !== id); } - return this.db.remove({_id: id}, {}).then(() => undefined); + return this.db.removeAsync({_id: id}, {}).then(() => undefined); } } diff --git a/server/services/notificationService.ts b/server/services/notificationService.ts index 3ac8a76d..87bf54bc 100644 --- a/server/services/notificationService.ts +++ b/server/services/notificationService.ts @@ -1,4 +1,4 @@ -import Datastore from 'nedb-promises'; +import Datastore from '@seald-io/nedb'; import path from 'path'; import type { @@ -19,7 +19,7 @@ const DEFAULT_QUERY_LIMIT = 20; class NotificationService extends BaseService { count: NotificationCount = {read: 0, total: 0, unread: 0}; - db = Datastore.create({ + db = new Datastore({ autoload: true, filename: path.join(config.dbPath, this.user._id, 'notifications.db'), }); @@ -28,7 +28,7 @@ class NotificationService extends BaseService { super(...args); (async () => { - const notifications = await this.db.find({}).catch(() => undefined); + const notifications = await this.db.findAsync({}).catch(() => undefined); if (notifications != null) { notifications.forEach((notification) => { @@ -68,7 +68,7 @@ class NotificationService extends BaseService { this.count.unread += notifications.length; await this.db - .insert( + .insertAsync( notifications.map((notification) => ({ ts, data: notification.data, @@ -87,7 +87,7 @@ class NotificationService extends BaseService { * @return {Promise} - Rejects with error. */ async clearNotifications(): Promise { - await this.db.remove({}, {multi: true}); + await this.db.removeAsync({}, {multi: true}); this.count = {read: 0, total: 0, unread: 0}; this.emitUpdate(); @@ -100,11 +100,11 @@ class NotificationService extends BaseService { * @return {NotificationState} - Resolves with notifications and counts or rejects with error. */ async getNotifications({allNotifications, start, limit}: NotificationFetchOptions): Promise { - const sortedNotifications = this.db.find({}).sort({ts: -1}); + const sortedNotifications = this.db.findAsync({}).sort({ts: -1}); if (allNotifications) { return { - notifications: await sortedNotifications.exec(), + notifications: await sortedNotifications.execAsync(), count: this.count, }; } else if (start != null) { @@ -112,12 +112,12 @@ class NotificationService extends BaseService { notifications: await sortedNotifications .skip(Number(start)) .limit(Number(limit) || DEFAULT_QUERY_LIMIT) - .exec(), + .execAsync(), count: this.count, }; } else { return { - notifications: await sortedNotifications.limit(Number(limit) || DEFAULT_QUERY_LIMIT).exec(), + notifications: await sortedNotifications.limit(Number(limit) || DEFAULT_QUERY_LIMIT).execAsync(), count: this.count, }; } diff --git a/server/services/settingService.ts b/server/services/settingService.ts index 47fc8027..81c7aea5 100644 --- a/server/services/settingService.ts +++ b/server/services/settingService.ts @@ -1,4 +1,4 @@ -import Datastore from 'nedb-promises'; +import Datastore from '@seald-io/nedb'; import path from 'path'; import type {FloodSettings} from '@shared/types/FloodSettings'; @@ -16,21 +16,21 @@ interface SettingServiceEvents { } class SettingService extends BaseService { - db = Datastore.create({ + db = new Datastore({ autoload: true, filename: path.join(config.dbPath, this.user._id, 'settings', 'settings.db'), }); async get(property: keyof FloodSettings | null): Promise> { const docs = await this.db - .find( + .findAsync( property ? { id: property, } : {}, ) - .exec(); + .execAsync(); return Object.assign( {}, @@ -51,7 +51,7 @@ class SettingService extends BaseService { const property = key as keyof FloodSettings; const value = changedSettings[property]; - await this.db.update({id: property}, {$set: {data: value}}, {upsert: true}); + await this.db.updateAsync({id: property}, {$set: {data: value}}, {upsert: true}); Object.assign(savedSettings, { [property]: value,