diff options
author | A.J. Shulman <Shulman.aj@gmail.com> | 2024-09-05 11:40:24 -0400 |
---|---|---|
committer | A.J. Shulman <Shulman.aj@gmail.com> | 2024-09-05 11:40:24 -0400 |
commit | c1053475810a1b1b3a9963c3f1ef0b1a9509d222 (patch) | |
tree | 41da9f26592ba7f189f8d00536435182e38272da /src/server/database.ts | |
parent | 785e55141cab178a761080f5c99384bb19855969 (diff) | |
parent | 9014cc474a039f0daef6cc0ee2011329da7703ac (diff) |
merged with master
Diffstat (limited to 'src/server/database.ts')
-rw-r--r-- | src/server/database.ts | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/server/database.ts b/src/server/database.ts index ff8584cd7..10dc540c3 100644 --- a/src/server/database.ts +++ b/src/server/database.ts @@ -5,11 +5,11 @@ import { emptyFunction, Utils } from '../Utils'; import { GoogleApiServerUtils } from './apis/google/GoogleApiServerUtils'; import { DocumentsCollection, IDatabase } from './IDatabase'; import { MemoryDatabase } from './MemoryDatabase'; -import { Transferable } from './Message'; import { Upload } from './SharedMediaTypes'; +import { serializedDoctype } from '../fields/ObjectField'; export namespace Database { - export let disconnect: Function; + export let disconnect: () => void; class DocSchema implements mongodb.BSON.Document { _id!: string; @@ -31,7 +31,7 @@ export namespace Database { try { const { connection } = mongoose; disconnect = async () => - new Promise<any>(resolve => { + new Promise<void>(resolve => { connection.close().then(resolve); }); if (connection.readyState === ConnectionStates.disconnected) { @@ -84,6 +84,7 @@ export namespace Database { if (this.db) { const collection = this.db.collection<DocSchema>(collectionName); const prom = this.currentWrites[id]; + // eslint-disable-next-line prefer-const let newProm: Promise<void>; const run = (): Promise<void> => new Promise<void>(resolve => { @@ -112,6 +113,7 @@ export namespace Database { if (this.db) { const collection = this.db.collection<DocSchema>(collectionName); const prom = this.currentWrites[id]; + // eslint-disable-next-line prefer-const let newProm: Promise<void>; const run = (): Promise<void> => new Promise<void>(resolve => { @@ -145,9 +147,7 @@ export namespace Database { } public delete(query: any, collectionName?: string): Promise<mongodb.DeleteResult>; - // eslint-disable-next-line no-dupe-class-members public delete(id: string, collectionName?: string): Promise<mongodb.DeleteResult>; - // eslint-disable-next-line no-dupe-class-members public delete(idIn: any, collectionName = DocumentsCollection) { let id = idIn; if (typeof id === 'string') { @@ -196,6 +196,7 @@ export namespace Database { const id = value._id; const collection = this.db.collection<DocSchema>(collectionName); const prom = this.currentWrites[id]; + // eslint-disable-next-line prefer-const let newProm: Promise<void>; const run = (): Promise<void> => new Promise<void>(resolve => { @@ -219,7 +220,7 @@ export namespace Database { return undefined; } - public getDocument(id: string, fn: (result?: Transferable) => void, collectionName = DocumentsCollection) { + public getDocument(id: string, fn: (result?: serializedDoctype) => void, collectionName = DocumentsCollection) { if (this.db) { const collection = this.db.collection<DocSchema>(collectionName); collection.findOne({ _id: id }).then(resultIn => { @@ -237,7 +238,7 @@ export namespace Database { } } - public async getDocuments(ids: string[], fn: (result: Transferable[]) => void, collectionName = DocumentsCollection) { + public async getDocuments(ids: string[], fn: (result: serializedDoctype[]) => void, collectionName = DocumentsCollection) { if (this.db) { const found = await this.db .collection<DocSchema>(collectionName) |