@webext-core/storage 1.1.2 → 1.2.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/README.md +1 -1
- package/lib/index.cjs +6 -1
- package/lib/index.d.ts +36 -4
- package/lib/index.global.js +5 -1
- package/lib/index.js +5 -1
- package/package.json +3 -3
package/README.md
CHANGED
package/lib/index.cjs
CHANGED
|
@@ -49,6 +49,7 @@ __export(src_exports, {
|
|
|
49
49
|
defineExtensionStorage: () => defineExtensionStorage,
|
|
50
50
|
localExtStorage: () => localExtStorage,
|
|
51
51
|
managedExtStorage: () => managedExtStorage,
|
|
52
|
+
sessionExtStorage: () => sessionExtStorage,
|
|
52
53
|
syncExtStorage: () => syncExtStorage
|
|
53
54
|
});
|
|
54
55
|
module.exports = __toCommonJS(src_exports);
|
|
@@ -83,7 +84,9 @@ function defineExtensionStorage(storage) {
|
|
|
83
84
|
}
|
|
84
85
|
}
|
|
85
86
|
return {
|
|
86
|
-
clear
|
|
87
|
+
clear() {
|
|
88
|
+
return storage.clear();
|
|
89
|
+
},
|
|
87
90
|
getItem(key) {
|
|
88
91
|
return storage.get(key).then((res) => {
|
|
89
92
|
var _a;
|
|
@@ -110,6 +113,7 @@ function defineExtensionStorage(storage) {
|
|
|
110
113
|
// src/index.ts
|
|
111
114
|
var import_webextension_polyfill2 = __toESM(require("webextension-polyfill"), 1);
|
|
112
115
|
var localExtStorage = defineExtensionStorage(import_webextension_polyfill2.default.storage.local);
|
|
116
|
+
var sessionExtStorage = defineExtensionStorage(import_webextension_polyfill2.default.storage.session);
|
|
113
117
|
var syncExtStorage = defineExtensionStorage(import_webextension_polyfill2.default.storage.sync);
|
|
114
118
|
var managedExtStorage = defineExtensionStorage(import_webextension_polyfill2.default.storage.managed);
|
|
115
119
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -117,5 +121,6 @@ var managedExtStorage = defineExtensionStorage(import_webextension_polyfill2.def
|
|
|
117
121
|
defineExtensionStorage,
|
|
118
122
|
localExtStorage,
|
|
119
123
|
managedExtStorage,
|
|
124
|
+
sessionExtStorage,
|
|
120
125
|
syncExtStorage
|
|
121
126
|
});
|
package/lib/index.d.ts
CHANGED
|
@@ -6,6 +6,12 @@ declare type AnySchema = Record<string, any>;
|
|
|
6
6
|
*/
|
|
7
7
|
declare type RemoveListenerCallback = () => void;
|
|
8
8
|
declare type OnChangeCallback<TSchema extends AnySchema, TKey extends keyof TSchema = keyof TSchema> = (newValue: TSchema[TKey], oldValue: TSchema[TKey] | null) => void;
|
|
9
|
+
/**
|
|
10
|
+
* This is the interface for the storage objects exported from the package. It is similar to `localStorage`, except for a few differences:
|
|
11
|
+
*
|
|
12
|
+
* - ***It's async*** since the web extension storage APIs are async.
|
|
13
|
+
* - It can store any data type, ***not just strings***.
|
|
14
|
+
*/
|
|
9
15
|
interface ExtensionStorage<TSchema extends AnySchema> {
|
|
10
16
|
/**
|
|
11
17
|
* Clear all values from storage.
|
|
@@ -34,15 +40,41 @@ interface ExtensionStorage<TSchema extends AnySchema> {
|
|
|
34
40
|
}
|
|
35
41
|
|
|
36
42
|
/**
|
|
37
|
-
* Create a storage instance with an optional type
|
|
43
|
+
* Create a storage instance with an optional schema, `TSchema`, for type safety.
|
|
44
|
+
*
|
|
45
|
+
* @param storage The storage to to use. Either `Browser.storage.local`, `Browser.storage.sync`, or `Browser.storage.managed`.
|
|
38
46
|
*
|
|
39
|
-
* @
|
|
40
|
-
*
|
|
47
|
+
* @example
|
|
48
|
+
* import browser from 'webextension-polyfill';
|
|
49
|
+
*
|
|
50
|
+
* interface Schema {
|
|
51
|
+
* installDate: number;
|
|
52
|
+
* }
|
|
53
|
+
* const extensionStorage = defineExtensionStorage<Schema>(browser.storage.local);
|
|
54
|
+
*
|
|
55
|
+
* const date = await extensionStorage.getItem("installDate");
|
|
41
56
|
*/
|
|
42
57
|
declare function defineExtensionStorage<TSchema extends AnySchema = AnySchema>(storage: Storage.StorageArea): ExtensionStorage<TSchema>;
|
|
43
58
|
|
|
59
|
+
/**
|
|
60
|
+
* An implementation of `ExtensionStorage` based on the `browser.storage.local` storage area.
|
|
61
|
+
*/
|
|
44
62
|
declare const localExtStorage: ExtensionStorage<AnySchema>;
|
|
63
|
+
/**
|
|
64
|
+
* An implementation of `ExtensionStorage` based on the `browser.storage.local` storage area.
|
|
65
|
+
*
|
|
66
|
+
* - Added to Chrome 102 as of May 24th, 2022.
|
|
67
|
+
* - Added to Safari 16.4 as of March 27th, 2023.
|
|
68
|
+
* - Added to Firefox 115 as of July 4th, 2023.
|
|
69
|
+
*/
|
|
70
|
+
declare const sessionExtStorage: ExtensionStorage<AnySchema>;
|
|
71
|
+
/**
|
|
72
|
+
* An implementation of `ExtensionStorage` based on the `browser.storage.sync` storage area.
|
|
73
|
+
*/
|
|
45
74
|
declare const syncExtStorage: ExtensionStorage<AnySchema>;
|
|
75
|
+
/**
|
|
76
|
+
* An implementation of `ExtensionStorage` based on the `browser.storage.managed` storage area.
|
|
77
|
+
*/
|
|
46
78
|
declare const managedExtStorage: ExtensionStorage<AnySchema>;
|
|
47
79
|
|
|
48
|
-
export { ExtensionStorage, defineExtensionStorage, localExtStorage, managedExtStorage, syncExtStorage };
|
|
80
|
+
export { ExtensionStorage, defineExtensionStorage, localExtStorage, managedExtStorage, sessionExtStorage, syncExtStorage };
|
package/lib/index.global.js
CHANGED
|
@@ -1048,6 +1048,7 @@ var webExtCoreStorage = (() => {
|
|
|
1048
1048
|
defineExtensionStorage: () => defineExtensionStorage,
|
|
1049
1049
|
localExtStorage: () => localExtStorage,
|
|
1050
1050
|
managedExtStorage: () => managedExtStorage,
|
|
1051
|
+
sessionExtStorage: () => sessionExtStorage,
|
|
1051
1052
|
syncExtStorage: () => syncExtStorage
|
|
1052
1053
|
});
|
|
1053
1054
|
|
|
@@ -1081,7 +1082,9 @@ var webExtCoreStorage = (() => {
|
|
|
1081
1082
|
}
|
|
1082
1083
|
}
|
|
1083
1084
|
return {
|
|
1084
|
-
clear
|
|
1085
|
+
clear() {
|
|
1086
|
+
return storage.clear();
|
|
1087
|
+
},
|
|
1085
1088
|
getItem(key) {
|
|
1086
1089
|
return storage.get(key).then((res) => {
|
|
1087
1090
|
var _a;
|
|
@@ -1108,6 +1111,7 @@ var webExtCoreStorage = (() => {
|
|
|
1108
1111
|
// src/index.ts
|
|
1109
1112
|
var import_webextension_polyfill2 = __toESM(require_browser_polyfill(), 1);
|
|
1110
1113
|
var localExtStorage = defineExtensionStorage(import_webextension_polyfill2.default.storage.local);
|
|
1114
|
+
var sessionExtStorage = defineExtensionStorage(import_webextension_polyfill2.default.storage.session);
|
|
1111
1115
|
var syncExtStorage = defineExtensionStorage(import_webextension_polyfill2.default.storage.sync);
|
|
1112
1116
|
var managedExtStorage = defineExtensionStorage(import_webextension_polyfill2.default.storage.managed);
|
|
1113
1117
|
return __toCommonJS(src_exports);
|
package/lib/index.js
CHANGED
|
@@ -49,7 +49,9 @@ function defineExtensionStorage(storage) {
|
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
return {
|
|
52
|
-
clear
|
|
52
|
+
clear() {
|
|
53
|
+
return storage.clear();
|
|
54
|
+
},
|
|
53
55
|
getItem(key) {
|
|
54
56
|
return storage.get(key).then((res) => {
|
|
55
57
|
var _a;
|
|
@@ -76,11 +78,13 @@ function defineExtensionStorage(storage) {
|
|
|
76
78
|
// src/index.ts
|
|
77
79
|
import Browser from "webextension-polyfill";
|
|
78
80
|
var localExtStorage = defineExtensionStorage(Browser.storage.local);
|
|
81
|
+
var sessionExtStorage = defineExtensionStorage(Browser.storage.session);
|
|
79
82
|
var syncExtStorage = defineExtensionStorage(Browser.storage.sync);
|
|
80
83
|
var managedExtStorage = defineExtensionStorage(Browser.storage.managed);
|
|
81
84
|
export {
|
|
82
85
|
defineExtensionStorage,
|
|
83
86
|
localExtStorage,
|
|
84
87
|
managedExtStorage,
|
|
88
|
+
sessionExtStorage,
|
|
85
89
|
syncExtStorage
|
|
86
90
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webext-core/storage",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "A type-safe, localStorage-esk wrapper around the web extension storage APIs. Supports all browsers (Chrome, Firefox, Safari, etc)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
@@ -42,12 +42,12 @@
|
|
|
42
42
|
"webextension-polyfill": "^0.10.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@types/webextension-polyfill": "^0.
|
|
45
|
+
"@types/webextension-polyfill": "^0.10.5",
|
|
46
46
|
"@vitest/coverage-c8": "^0.24.5",
|
|
47
47
|
"tsup": "^6.4.0",
|
|
48
48
|
"typescript": "^4.8.4",
|
|
49
49
|
"vitest": "^0.24.5",
|
|
50
|
-
"@webext-core/fake-browser": "1.
|
|
50
|
+
"@webext-core/fake-browser": "1.3.0",
|
|
51
51
|
"tsconfig": "0.0.0"
|
|
52
52
|
},
|
|
53
53
|
"scripts": {
|