@wxt-dev/storage 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.mjs +12 -5
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { dequal } from 'dequal/lite';
|
|
2
2
|
import { Mutex } from 'async-mutex';
|
|
3
3
|
|
|
4
|
+
const browser = (
|
|
5
|
+
// @ts-expect-error
|
|
6
|
+
globalThis.browser?.runtime?.id == null ? globalThis.chrome : (
|
|
7
|
+
// @ts-expect-error
|
|
8
|
+
globalThis.browser
|
|
9
|
+
)
|
|
10
|
+
);
|
|
4
11
|
const storage = createStorage();
|
|
5
12
|
function createStorage() {
|
|
6
13
|
const drivers = {
|
|
@@ -152,7 +159,7 @@ function createStorage() {
|
|
|
152
159
|
const resultsMap = {};
|
|
153
160
|
await Promise.all(
|
|
154
161
|
Object.entries(areaToDriverMetaKeysMap).map(async ([area, keys2]) => {
|
|
155
|
-
const areaRes = await
|
|
162
|
+
const areaRes = await browser.storage[area].get(
|
|
156
163
|
keys2.map((key) => key.driverMetaKey)
|
|
157
164
|
);
|
|
158
165
|
keys2.forEach((key) => {
|
|
@@ -400,7 +407,7 @@ function createStorage() {
|
|
|
400
407
|
}
|
|
401
408
|
function createDriver(storageArea) {
|
|
402
409
|
const getStorageArea = () => {
|
|
403
|
-
if (
|
|
410
|
+
if (browser.runtime == null) {
|
|
404
411
|
throw Error(
|
|
405
412
|
[
|
|
406
413
|
"'wxt/storage' must be loaded in a web extension environment",
|
|
@@ -409,14 +416,14 @@ function createDriver(storageArea) {
|
|
|
409
416
|
].join("\n")
|
|
410
417
|
);
|
|
411
418
|
}
|
|
412
|
-
if (
|
|
419
|
+
if (browser.storage == null) {
|
|
413
420
|
throw Error(
|
|
414
421
|
"You must add the 'storage' permission to your manifest to use 'wxt/storage'"
|
|
415
422
|
);
|
|
416
423
|
}
|
|
417
|
-
const area =
|
|
424
|
+
const area = browser.storage[storageArea];
|
|
418
425
|
if (area == null)
|
|
419
|
-
throw Error(`"
|
|
426
|
+
throw Error(`"browser.storage.${storageArea}" is undefined`);
|
|
420
427
|
return area;
|
|
421
428
|
};
|
|
422
429
|
const watchListeners = /* @__PURE__ */ new Set();
|