From d0e1a718277aa9c77ca6214c982c702720a270f0 Mon Sep 17 00:00:00 2001 From: adueck Date: Wed, 14 Aug 2024 14:51:15 -0400 Subject: [PATCH] fix CI --- src/lib/src/dictionary/dictionary-core.ts | 13 +++++++++---- src/lib/src/dictionary/dictionary.ts | 3 +++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/lib/src/dictionary/dictionary-core.ts b/src/lib/src/dictionary/dictionary-core.ts index 0990522..9047725 100644 --- a/src/lib/src/dictionary/dictionary-core.ts +++ b/src/lib/src/dictionary/dictionary-core.ts @@ -17,7 +17,7 @@ export class DictionaryDb { private ready = false; // eslint-disable-next-line - public collection: Collection; + public collection: Collection | undefined; constructor(options: { url: string; @@ -82,6 +82,9 @@ export class DictionaryDb { private async addDictionaryToLoki(dictionary: T.Dictionary): Promise<"done"> { return await new Promise((resolve: (value: "done") => void, reject) => { + if (!this.collection) { + reject("dictionary not initialized"); + } // Add it to Lokijs this.collection = this.lokidb.addCollection( this.dictionaryCollectionName, @@ -201,8 +204,10 @@ export class DictionaryDb { notifyUpdateComing(); this.ready = false; localStorage.removeItem(this.dictionaryInfoLocalStorageKey); - this.collection.clear(); - this.lokidb.removeCollection(this.dictionaryCollectionName); + if (this.collection) { + this.collection.clear(); + this.lokidb.removeCollection(this.dictionaryCollectionName); + } await (async () => { return new Promise((resolve: (value: "done") => void) => { this.lokidb.saveDatabase(() => { @@ -225,7 +230,7 @@ export class DictionaryDb { */ // TODO: not working in app usage now now with new 'this' issues public findOneByTs(ts: number): T.DictionaryEntry | undefined { - if (!this.ready) { + if (!this.ready || !this.collection) { return undefined; } const res = this.collection.by("ts", ts); diff --git a/src/lib/src/dictionary/dictionary.ts b/src/lib/src/dictionary/dictionary.ts index 5b199fd..07286d8 100644 --- a/src/lib/src/dictionary/dictionary.ts +++ b/src/lib/src/dictionary/dictionary.ts @@ -14,6 +14,9 @@ const dictDb = new DictionaryDb({ }); function queryP(p: string): T.DictionaryEntry[] { + if (!dictDb.collection) { + return []; + } return dictDb.collection.find({ p }); } const memoizedQueryP = queryP;