aboutsummaryrefslogtreecommitdiff
path: root/src/background/completion/CompletionUseCase.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/background/completion/CompletionUseCase.ts')
-rw-r--r--src/background/completion/CompletionUseCase.ts39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/background/completion/CompletionUseCase.ts b/src/background/completion/CompletionUseCase.ts
new file mode 100644
index 0000000..898efd4
--- /dev/null
+++ b/src/background/completion/CompletionUseCase.ts
@@ -0,0 +1,39 @@
+import { inject, injectable } from "tsyringe";
+import HistoryRepository from "./HistoryRepository";
+import BookmarkRepository from "./BookmarkRepository";
+import CachedSettingRepository from "../repositories/CachedSettingRepository";
+
+export type BookmarkItem = {
+ title: string
+ url: string
+}
+
+export type HistoryItem = {
+ title: string
+ url: string
+}
+
+@injectable()
+export default class CompletionUseCase {
+ constructor(
+ private bookmarkRepository: BookmarkRepository,
+ private historyRepository: HistoryRepository,
+ @inject("CachedSettingRepository")
+ private cachedSettingRepository: CachedSettingRepository,
+ ) {
+ }
+
+ async requestSearchEngines(query: string): Promise<string[]> {
+ const settings = await this.cachedSettingRepository.get();
+ return Object.keys(settings.search.engines)
+ .filter(key => key.startsWith(query))
+ }
+
+ requestBookmarks(query: any): Promise<BookmarkItem[]> {
+ return this.bookmarkRepository.queryBookmarks(query);
+ }
+
+ async requestHistory(query: string): Promise<HistoryItem[]> {
+ return this.historyRepository.queryHistories(query);
+ }
+} \ No newline at end of file