@wxt-dev/storage 1.2.9 → 1.4.0
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/LICENSE +21 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.mjs +7 -1
- package/package.json +25 -26
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Aaron
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.mts
CHANGED
|
@@ -128,6 +128,8 @@ interface WxtStorage {
|
|
|
128
128
|
restoreSnapshot(base: StorageArea, data: any): Promise<void>;
|
|
129
129
|
/** Watch for changes to a specific key in storage. */
|
|
130
130
|
watch<T>(key: StorageItemKey, cb: WatchCallback<T | null>): Unwatch;
|
|
131
|
+
/** Watch for changes to a specific key's metadata in storage. */
|
|
132
|
+
watchMeta<T extends Record<string, unknown>>(key: StorageItemKey, cb: WatchCallback<T>): Unwatch;
|
|
131
133
|
/** Remove all watch listeners. */
|
|
132
134
|
unwatch(): void;
|
|
133
135
|
/**
|
|
@@ -168,6 +170,8 @@ interface WxtStorageItem<TValue, TMetadata extends Record<string, unknown>> {
|
|
|
168
170
|
removeMeta(properties?: string[]): Promise<void>;
|
|
169
171
|
/** Listen for changes to the value in storage. */
|
|
170
172
|
watch(cb: WatchCallback<TValue>): Unwatch;
|
|
173
|
+
/** Listen for changes to the metadata in storage. */
|
|
174
|
+
watchMeta(cb: WatchCallback<NullablePartial<TMetadata>>): Unwatch;
|
|
171
175
|
/**
|
|
172
176
|
* If there are migrations defined on the storage item, migrate to the latest
|
|
173
177
|
* version.
|
package/dist/index.mjs
CHANGED
|
@@ -70,7 +70,7 @@ function createStorage() {
|
|
|
70
70
|
return newFields;
|
|
71
71
|
};
|
|
72
72
|
const getValueOrFallback = (value, fallback) => value ?? fallback ?? null;
|
|
73
|
-
const getMetaValue = (properties) => typeof properties === "object" && !Array.isArray(properties) ? properties : {};
|
|
73
|
+
const getMetaValue = (properties) => properties != null && typeof properties === "object" && !Array.isArray(properties) ? properties : {};
|
|
74
74
|
const getItem = async (driver, driverKey, opts) => {
|
|
75
75
|
return getValueOrFallback(await driver.getItem(driverKey), opts?.fallback ?? opts?.defaultValue);
|
|
76
76
|
};
|
|
@@ -103,6 +103,7 @@ function createStorage() {
|
|
|
103
103
|
}
|
|
104
104
|
};
|
|
105
105
|
const watch = (driver, driverKey, cb) => driver.watch(driverKey, cb);
|
|
106
|
+
const watchMeta = (driver, driverKey, cb) => watch(driver, getMetaKey(driverKey), (newValue, oldValue) => cb(getMetaValue(newValue), getMetaValue(oldValue)));
|
|
106
107
|
return {
|
|
107
108
|
getItem: async (key, opts) => {
|
|
108
109
|
const { driver, driverKey } = resolveKey(key);
|
|
@@ -271,6 +272,10 @@ function createStorage() {
|
|
|
271
272
|
const { driver, driverKey } = resolveKey(key);
|
|
272
273
|
return watch(driver, driverKey, cb);
|
|
273
274
|
},
|
|
275
|
+
watchMeta: (key, cb) => {
|
|
276
|
+
const { driver, driverKey } = resolveKey(key);
|
|
277
|
+
return watchMeta(driver, driverKey, cb);
|
|
278
|
+
},
|
|
274
279
|
unwatch() {
|
|
275
280
|
Object.values(drivers).forEach((driver) => {
|
|
276
281
|
driver.unwatch();
|
|
@@ -362,6 +367,7 @@ function createStorage() {
|
|
|
362
367
|
return await removeMeta(driver, driverKey, properties);
|
|
363
368
|
},
|
|
364
369
|
watch: (cb) => watch(driver, driverKey, (newValue, oldValue) => cb(newValue ?? getFallback(), oldValue ?? getFallback())),
|
|
370
|
+
watchMeta: (cb) => watchMeta(driver, driverKey, cb),
|
|
365
371
|
migrate
|
|
366
372
|
};
|
|
367
373
|
}
|
package/package.json
CHANGED
|
@@ -1,34 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wxt-dev/storage",
|
|
3
|
+
"version": "1.4.0",
|
|
3
4
|
"description": "Web extension storage API provided by WXT, supports all browsers.",
|
|
4
|
-
"version": "1.2.9",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"repository": {
|
|
7
|
-
"type": "git",
|
|
8
|
-
"url": "git+https://github.com/wxt-dev/wxt.git",
|
|
9
|
-
"directory": "packages/storage"
|
|
10
|
-
},
|
|
11
|
-
"homepage": "https://wxt.dev/storage.html",
|
|
12
5
|
"keywords": [
|
|
13
|
-
"wxt",
|
|
14
|
-
"storage",
|
|
15
|
-
"extension",
|
|
16
6
|
"addon",
|
|
17
7
|
"chrome",
|
|
8
|
+
"edge",
|
|
9
|
+
"extension",
|
|
18
10
|
"firefox",
|
|
19
|
-
"
|
|
11
|
+
"storage",
|
|
12
|
+
"wxt"
|
|
20
13
|
],
|
|
14
|
+
"homepage": "https://wxt.dev/storage.html",
|
|
15
|
+
"license": "MIT",
|
|
21
16
|
"author": {
|
|
22
17
|
"name": "Aaron Klinker",
|
|
23
18
|
"email": "aaronklinker1+wxt@gmail.com"
|
|
24
19
|
},
|
|
25
|
-
"
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/wxt-dev/wxt.git",
|
|
23
|
+
"directory": "packages/storage"
|
|
24
|
+
},
|
|
26
25
|
"funding": "https://github.com/sponsors/wxt-dev",
|
|
26
|
+
"files": [
|
|
27
|
+
"dist"
|
|
28
|
+
],
|
|
29
|
+
"type": "module",
|
|
30
|
+
"module": "./dist/index.mjs",
|
|
31
|
+
"types": "./dist/index.d.mts",
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"types": "./dist/index.d.mts",
|
|
35
|
+
"import": "./dist/index.mjs"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
27
38
|
"scripts": {
|
|
28
39
|
"build": "buildc -- tsdown --deps.onlyBundle dequal",
|
|
29
40
|
"check": "buildc --deps-only -- check",
|
|
30
41
|
"test": "buildc --deps-only -- vitest",
|
|
31
|
-
"test:coverage": "bun run test run --coverage",
|
|
32
42
|
"prepack": "bun run build"
|
|
33
43
|
},
|
|
34
44
|
"dependencies": {
|
|
@@ -44,16 +54,5 @@
|
|
|
44
54
|
"tsdown": "^0.21.0",
|
|
45
55
|
"typescript": "^6.0.3",
|
|
46
56
|
"vitest": "^4.1.10"
|
|
47
|
-
}
|
|
48
|
-
"module": "./dist/index.mjs",
|
|
49
|
-
"types": "./dist/index.d.mts",
|
|
50
|
-
"exports": {
|
|
51
|
-
".": {
|
|
52
|
-
"types": "./dist/index.d.mts",
|
|
53
|
-
"import": "./dist/index.mjs"
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
"files": [
|
|
57
|
-
"dist"
|
|
58
|
-
]
|
|
57
|
+
}
|
|
59
58
|
}
|