diff options
author | Tyler Schicke <tschicke@gmail.com> | 2020-01-07 23:35:14 -0800 |
---|---|---|
committer | Tyler Schicke <tschicke@gmail.com> | 2020-01-07 23:57:32 -0800 |
commit | 786d25a4f8db1db8795f04a17fba392636e5f891 (patch) | |
tree | 6973a067fda8e79a14e70ee8fcd4685752fb0bb0 /src/server/MemoryDatabase.ts | |
parent | 23d5f6b28a93a3c66c0bd7776d6a42073cc55afb (diff) |
Various features/fixes to allow running on Linux w/o MongoDB or Solr
- Added new launch config option for chromium
- Changed port for TypeScript server debugger to account for worker
process
- Updated packages to versions that work with current node/npm
- Update IDatabase interface
- Updated MemoryDatabase to work properly with Dash
- Added some workarounds for in memory database as they currently don't
support users, so you must be guest, which means the guest needs to be
able to do things it usually can't
- Added environment variable to disable search. This doesn't fully
disable search yet, but it is enough to not throw major errors when
Solr isn't running
- Added logic to support using an in memory DB instead of MongoDB
Diffstat (limited to 'src/server/MemoryDatabase.ts')
-rw-r--r-- | src/server/MemoryDatabase.ts | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/src/server/MemoryDatabase.ts b/src/server/MemoryDatabase.ts index 8bf6abdd8..a14a68d17 100644 --- a/src/server/MemoryDatabase.ts +++ b/src/server/MemoryDatabase.ts @@ -17,8 +17,26 @@ export class MemoryDatabase implements IDatabase { public update(id: string, value: any, callback: (err: mongodb.MongoError, res: mongodb.UpdateWriteOpResult) => void, _upsert?: boolean, collectionName = DocumentsCollection): Promise<void> { const collection = this.getCollection(collectionName); - collection[id] = { ...collection[id], ...value }; - callback(null, {} as any); + if ("$set" in value) { + let currentVal = collection[id] ?? (collection[id] = {}); + const val = value["$set"]; + for (const key in val) { + const keys = key.split("."); + for (let i = 0; i < keys.length - 1; i++) { + const k = keys[i]; + if (typeof currentVal[k] === "object") { + currentVal = currentVal[k]; + } else { + currentVal[k] = {}; + currentVal = currentVal[k]; + } + } + currentVal[keys[keys.length - 1]] = val[key]; + } + } else { + collection[id] = value; + } + callback(null as any, {} as any); return Promise.resolve(undefined); } @@ -29,7 +47,7 @@ export class MemoryDatabase implements IDatabase { public delete(query: any, collectionName?: string): Promise<mongodb.DeleteWriteOpResultObject>; public delete(id: string, collectionName?: string): Promise<mongodb.DeleteWriteOpResultObject>; public delete(id: any, collectionName = DocumentsCollection): Promise<mongodb.DeleteWriteOpResultObject> { - const i = id["_id"] ?? id; + const i = id.id ?? id; delete this.getCollection(collectionName)[i]; return Promise.resolve({} as any); @@ -41,7 +59,7 @@ export class MemoryDatabase implements IDatabase { } public insert(value: any, collectionName = DocumentsCollection): Promise<void> { - const id = value._id; + const id = value.id; this.getCollection(collectionName)[id] = value; return Promise.resolve(); } @@ -49,7 +67,7 @@ export class MemoryDatabase implements IDatabase { public getDocument(id: string, fn: (result?: Transferable) => void, collectionName = NewDocumentsCollection): void { fn(this.getCollection(collectionName)[id]); } - public getDocuments(ids: string[], fn: (result?: Transferable[]) => void, collectionName = DocumentsCollection): void { + public getDocuments(ids: string[], fn: (result: Transferable[]) => void, collectionName = DocumentsCollection): void { fn(ids.map(id => this.getCollection(collectionName)[id])); } @@ -70,4 +88,8 @@ export class MemoryDatabase implements IDatabase { } } } + + public query(): Promise<mongodb.Cursor> { + throw new Error("Can't query a MemoryDatabase"); + } } |