Skip to content
This repository was archived by the owner on Oct 25, 2023. It is now read-only.

Commit d201905

Browse files
committed
renames, docs
1 parent fd6f178 commit d201905

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

archaeologist/src/storage_api_local.ts renamed to archaeologist/src/storage_api_browser_ext.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
/**
22
* An implementation of @see smuggler-api.StorageApi that persists the data
3-
* on user device and is based on browser extension APIs.
3+
* in a storage only available to browser extensions (most likely - locally on device).
44
*
55
* It is intended to work in all browser extension contexts (such as background,
6-
* content etc). See https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/storage
6+
* content etc).
7+
* See https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/storage
78
* for more information.
9+
*
10+
* NOTE: At the time of this writing dev tools of some browsers (including the
11+
* Chromium-based ones) do not including anything to inspect the contents
12+
* of the underlying storage. See https://stackoverflow.com/a/27432365/3375765
13+
* for workarounds.
814
*/
915

1016
import {
@@ -117,6 +123,10 @@ class YekLavStore {
117123
this.store = store
118124
}
119125

126+
// TODO[snikitin@outlook.com] Add a note that the code that uses this
127+
// method should try to combine everything it needs to do into ONE
128+
// call to set() in hopes to retain at least some data consistency
129+
// guarantees.
120130
set(items: YekLav[]): Promise<void> {
121131
for (const item of items) {
122132
if (item.yek.yek.kind !== item.lav.lav.kind) {
@@ -128,7 +138,7 @@ class YekLavStore {
128138
let records: Record<string, any> = {}
129139
for (const item of items) {
130140
const key = this.stringify(item.yek)
131-
if (records.keys().indexOf(key) !== -1) {
141+
if (Object.keys(records).indexOf(key) !== -1) {
132142
throw new Error(`Attempted to set more than 1 value for key '${key}'`)
133143
}
134144
records[key] = item.lav
@@ -605,15 +615,16 @@ async function advanceUserIngestionProgress(
605615
return { ack: true }
606616
}
607617

608-
export function makeLocalStorageApi(
618+
export function makeBrowserExtStorageApi(
609619
browserStore: browser.Storage.StorageArea
610620
): StorageApi {
611621
const store = new YekLavStore(browserStore)
612622

613623
const throwUnimplementedError = (endpoint: string) => {
614624
return (..._: any[]): never => {
615625
throw new Error(
616-
`Attempted to call an ${endpoint} endpoint of local StorageApi which hasn't been implemented yet`
626+
`Attempted to call an ${endpoint} endpoint of browser ` +
627+
"extension's local StorageApi which hasn't been implemented yet"
617628
)
618629
}
619630
}

0 commit comments

Comments
 (0)