@webext-core/storage 1.1.2 → 1.1.3

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 CHANGED
@@ -14,4 +14,4 @@ const value = await localExtStorage.getItem('some-key');
14
14
 
15
15
  ## Get Started
16
16
 
17
- See [documentation](https://webext-core.aklinker1.io/storage) to get started!
17
+ See [documentation](https://webext-core.aklinker1.io/guide/storage/) to get started!
package/lib/index.cjs CHANGED
@@ -83,7 +83,9 @@ function defineExtensionStorage(storage) {
83
83
  }
84
84
  }
85
85
  return {
86
- clear: storage.clear,
86
+ clear() {
87
+ return storage.clear();
88
+ },
87
89
  getItem(key) {
88
90
  return storage.get(key).then((res) => {
89
91
  var _a;
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,33 @@ interface ExtensionStorage<TSchema extends AnySchema> {
34
40
  }
35
41
 
36
42
  /**
37
- * Create a storage instance with an optional type schema.
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`.
46
+ *
47
+ * @example
48
+ * import browser from 'webextension-polyfill';
49
+ *
50
+ * interface Schema {
51
+ * installDate: number;
52
+ * }
53
+ * const extensionStorage = defineExtensionStorage<Schema>(browser.storage.local);
38
54
  *
39
- * @arg storage Either `Browser.storage.local`, `Browser.storage.sync`, or
40
- * `Browser.storage.managed`. This is the storage that will back the implementation.
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.sync` storage area.
65
+ */
45
66
  declare const syncExtStorage: ExtensionStorage<AnySchema>;
67
+ /**
68
+ * An implementation of `ExtensionStorage` based on the `browser.storage.managed` storage area.
69
+ */
46
70
  declare const managedExtStorage: ExtensionStorage<AnySchema>;
47
71
 
48
72
  export { ExtensionStorage, defineExtensionStorage, localExtStorage, managedExtStorage, syncExtStorage };
@@ -1081,7 +1081,9 @@ var webExtCoreStorage = (() => {
1081
1081
  }
1082
1082
  }
1083
1083
  return {
1084
- clear: storage.clear,
1084
+ clear() {
1085
+ return storage.clear();
1086
+ },
1085
1087
  getItem(key) {
1086
1088
  return storage.get(key).then((res) => {
1087
1089
  var _a;
package/lib/index.js CHANGED
@@ -49,7 +49,9 @@ function defineExtensionStorage(storage) {
49
49
  }
50
50
  }
51
51
  return {
52
- clear: storage.clear,
52
+ clear() {
53
+ return storage.clear();
54
+ },
53
55
  getItem(key) {
54
56
  return storage.get(key).then((res) => {
55
57
  var _a;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webext-core/storage",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
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": [
@@ -47,7 +47,7 @@
47
47
  "tsup": "^6.4.0",
48
48
  "typescript": "^4.8.4",
49
49
  "vitest": "^0.24.5",
50
- "@webext-core/fake-browser": "1.2.1",
50
+ "@webext-core/fake-browser": "1.2.2",
51
51
  "tsconfig": "0.0.0"
52
52
  },
53
53
  "scripts": {