aboutsummaryrefslogtreecommitdiff
path: root/src/background/repositories
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2019-05-01 11:04:24 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2019-05-02 22:07:53 +0900
commit678020a3a27713e77ec8d74483122b4258fbc829 (patch)
tree6c84d0965f05918e6fd58a0a155c15035474d563 /src/background/repositories
parent0cffb09e249832291be73be039dc1b9bb38115f9 (diff)
Types on src/background
Diffstat (limited to 'src/background/repositories')
-rw-r--r--src/background/repositories/BookmarkRepository.ts4
-rw-r--r--src/background/repositories/BrowserSettingRepository.ts2
-rw-r--r--src/background/repositories/CompletionsRepository.ts14
-rw-r--r--src/background/repositories/FindRepository.ts6
-rw-r--r--src/background/repositories/MarkRepository.ts8
-rw-r--r--src/background/repositories/PersistentSettingRepository.ts2
-rw-r--r--src/background/repositories/SettingRepository.ts8
-rw-r--r--src/background/repositories/VersionRepository.ts10
8 files changed, 29 insertions, 25 deletions
diff --git a/src/background/repositories/BookmarkRepository.ts b/src/background/repositories/BookmarkRepository.ts
index 99f7ec4..b4da509 100644
--- a/src/background/repositories/BookmarkRepository.ts
+++ b/src/background/repositories/BookmarkRepository.ts
@@ -1,5 +1,7 @@
export default class BookmarkRepository {
- async create(title, url) {
+ async create(
+ title: string, url: string
+ ): Promise<browser.bookmarks.BookmarkTreeNode> {
let item = await browser.bookmarks.create({
type: 'bookmark',
title,
diff --git a/src/background/repositories/BrowserSettingRepository.ts b/src/background/repositories/BrowserSettingRepository.ts
index a9d2c06..48c72a5 100644
--- a/src/background/repositories/BrowserSettingRepository.ts
+++ b/src/background/repositories/BrowserSettingRepository.ts
@@ -1,7 +1,7 @@
import * as urls from '../../shared/urls';
export default class BrowserSettingRepository {
- async getHomepageUrls() {
+ async getHomepageUrls(): Promise<string[]> {
let { value } = await browser.browserSettings.homepageOverride.get({});
return value.split('|').map(urls.normalizeUrl);
}
diff --git a/src/background/repositories/CompletionsRepository.ts b/src/background/repositories/CompletionsRepository.ts
index 1318d36..18af587 100644
--- a/src/background/repositories/CompletionsRepository.ts
+++ b/src/background/repositories/CompletionsRepository.ts
@@ -1,7 +1,13 @@
+type Tab = browser.tabs.Tab;
+type BookmarkTreeNode = browser.bookmarks.BookmarkTreeNode;
+
export default class CompletionsRepository {
- async queryBookmarks(keywords) {
+ async queryBookmarks(keywords: string): Promise<BookmarkTreeNode[]> {
let items = await browser.bookmarks.search({ query: keywords });
return items.filter((item) => {
+ if (!item.url) {
+ return false;
+ }
let url = undefined;
try {
url = new URL(item.url);
@@ -12,17 +18,17 @@ export default class CompletionsRepository {
});
}
- queryHistories(keywords) {
+ queryHistories(keywords: string): Promise<browser.history.HistoryItem[]> {
return browser.history.search({
text: keywords,
startTime: 0,
});
}
- async queryTabs(keywords, excludePinned) {
+ async queryTabs(keywords: string, excludePinned: boolean): Promise<Tab[]> {
let tabs = await browser.tabs.query({ currentWindow: true });
return tabs.filter((t) => {
- return t.url.toLowerCase().includes(keywords.toLowerCase()) ||
+ return t.url && t.url.toLowerCase().includes(keywords.toLowerCase()) ||
t.title && t.title.toLowerCase().includes(keywords.toLowerCase());
}).filter((t) => {
return !(excludePinned && t.pinned);
diff --git a/src/background/repositories/FindRepository.ts b/src/background/repositories/FindRepository.ts
index 74ec914..bf286e6 100644
--- a/src/background/repositories/FindRepository.ts
+++ b/src/background/repositories/FindRepository.ts
@@ -3,15 +3,17 @@ import MemoryStorage from '../infrastructures/MemoryStorage';
const FIND_KEYWORD_KEY = 'find-keyword';
export default class FindRepository {
+ private cache: MemoryStorage;
+
constructor() {
this.cache = new MemoryStorage();
}
- getKeyword() {
+ getKeyword(): Promise<string> {
return Promise.resolve(this.cache.get(FIND_KEYWORD_KEY));
}
- setKeyword(keyword) {
+ setKeyword(keyword: string): Promise<any> {
this.cache.set(FIND_KEYWORD_KEY, keyword);
return Promise.resolve();
}
diff --git a/src/background/repositories/MarkRepository.ts b/src/background/repositories/MarkRepository.ts
index 282c712..69c85f6 100644
--- a/src/background/repositories/MarkRepository.ts
+++ b/src/background/repositories/MarkRepository.ts
@@ -4,21 +4,23 @@ import GlobalMark from '../domains/GlobalMark';
const MARK_KEY = 'mark';
export default class MarkRepository {
+ private cache: MemoryStorage;
+
constructor() {
this.cache = new MemoryStorage();
}
- getMark(key) {
+ getMark(key: string): Promise<GlobalMark | undefined> {
let marks = this.getOrEmptyMarks();
let data = marks[key];
if (!data) {
return Promise.resolve(undefined);
}
- let mark = new GlobalMark(data.tabId, data.url, data.x, data.y);
+ let mark = { tabId: data.tabId, url: data.url, x: data.x, y: data.y };
return Promise.resolve(mark);
}
- setMark(key, mark) {
+ setMark(key: string, mark: GlobalMark): Promise<any> {
let marks = this.getOrEmptyMarks();
marks[key] = { tabId: mark.tabId, url: mark.url, x: mark.x, y: mark.y };
this.cache.set(MARK_KEY, marks);
diff --git a/src/background/repositories/PersistentSettingRepository.ts b/src/background/repositories/PersistentSettingRepository.ts
index 4cab107..3f2f4a1 100644
--- a/src/background/repositories/PersistentSettingRepository.ts
+++ b/src/background/repositories/PersistentSettingRepository.ts
@@ -1,7 +1,7 @@
import Setting from '../domains/Setting';
export default class SettingRepository {
- async load() {
+ async load(): Promise<any> {
let { settings } = await browser.storage.local.get('settings');
if (!settings) {
return null;
diff --git a/src/background/repositories/SettingRepository.ts b/src/background/repositories/SettingRepository.ts
index c4667a9..15355ba 100644
--- a/src/background/repositories/SettingRepository.ts
+++ b/src/background/repositories/SettingRepository.ts
@@ -3,19 +3,21 @@ import MemoryStorage from '../infrastructures/MemoryStorage';
const CACHED_SETTING_KEY = 'setting';
export default class SettingRepository {
+ private cache: MemoryStorage;
+
constructor() {
this.cache = new MemoryStorage();
}
- get() {
+ get(): Promise<any> {
return Promise.resolve(this.cache.get(CACHED_SETTING_KEY));
}
- update(value) {
+ update(value: any): any {
return this.cache.set(CACHED_SETTING_KEY, value);
}
- async setProperty(name, value) {
+ async setProperty(name: string, value: string): Promise<any> {
let current = await this.get();
current.properties[name] = value;
return this.update(current);
diff --git a/src/background/repositories/VersionRepository.ts b/src/background/repositories/VersionRepository.ts
deleted file mode 100644
index 4c71d05..0000000
--- a/src/background/repositories/VersionRepository.ts
+++ /dev/null
@@ -1,10 +0,0 @@
-export default class VersionRepository {
- async get() {
- let { version } = await browser.storage.local.get('version');
- return version;
- }
-
- update(version) {
- return browser.storage.local.set({ version });
- }
-}