varstor 0.6.62 → 0.6.64

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/src/types.d.ts CHANGED
@@ -7,9 +7,10 @@ type IValue = {
7
7
  fullKey?: string;
8
8
  value?: any;
9
9
  computeFn?: boolean | IComputeFunction;
10
- dependencies: string[];
11
- dependants: string[];
12
- storageType: string;
10
+ isAction?: boolean;
11
+ dependencies?: string[];
12
+ dependants?: string[];
13
+ storageType?: string;
13
14
  listeners?: any[];
14
15
  defaultValue?: any;
15
16
  namespace: INamespace;
@@ -28,12 +29,23 @@ type IStorageFunctions = {
28
29
  IS_AVAILABE: (type: string) => boolean;
29
30
  UPDATE_STATE: (state: IStateDefault, type: string) => IStateDefault;
30
31
  SET_VALUES: (type: string, changes: Record<string, any>) => Promise<boolean>;
32
+ REMOVE_KEY: (type: string, key: string) => void;
31
33
  };
32
34
 
33
35
  type IStateListener = (
34
36
  changes: string[],
35
37
  values: Record<string, any>,
36
38
  data: IStateChanges,
37
- ) => {};
39
+ ) => any;
38
40
 
39
41
  type IStateListeners = Record<string, IStateListener[]>;
42
+
43
+ type IStateAction = (mutator: IStateMutator, args: any[]) => void;
44
+
45
+ type IStateActions = Record<string, IStateAction>;
46
+
47
+ type IStateUpdatePieces = Record<string, {
48
+ storageTypes: Record<string, boolean>;
49
+ readyStorageTypes: Record<string, boolean>;
50
+ changes: IStateChanges;
51
+ }>;
@@ -5,6 +5,7 @@ export default {
5
5
  IS_AVAILABE: isStorageAvailable,
6
6
  UPDATE_STATE: updateStateFromStorage,
7
7
  SET_VALUES: setStorageValue,
8
+ REMOVE_KEY: removeStorageKey,
8
9
  };
9
10
 
10
11
  function getStorageType(isPersistent: boolean) {
@@ -27,6 +28,12 @@ async function setStorageValue(type: string, changes: Record<string, any>) {
27
28
  return true;
28
29
  }
29
30
 
31
+ async function removeStorageKey(type: string, key: string) {
32
+ if (type) {
33
+ await browser.storage[type].remove(key);
34
+ }
35
+ }
36
+
30
37
  export function isSessionStorageSupport() {
31
38
  return !!browser.storage.session;
32
39
  }
@@ -6,12 +6,12 @@ import webextensionStorageUtils, {
6
6
  isSessionStorageSupport,
7
7
  } from "./webextension-storage";
8
8
 
9
- const { onStateChange, setStorageUtils } = main;
9
+ const { joinStateChanges, setStorageUtils } = main;
10
10
 
11
11
  if (isBackgroundScript()) {
12
- browser.storage.local.onChanged.addListener(onStateChange);
12
+ browser.storage.local.onChanged.addListener(joinStateChanges);
13
13
  isSessionStorageSupport() &&
14
- browser.storage.session.onChanged.addListener(onStateChange);
14
+ browser.storage.session.onChanged.addListener(joinStateChanges);
15
15
  }
16
16
 
17
17
  setStorageUtils(webextensionStorageUtils);
package/src/validation.ts DELETED
@@ -1,31 +0,0 @@
1
- import { STATE } from ".";
2
- import { NAMESPACE_DELIMITER } from "./constants";
3
-
4
- function splitFullKey(fullKey: string) {
5
- const segments = fullKey.split(NAMESPACE_DELIMITER);
6
- return [segments.slice(-1)[0], segments.join(NAMESPACE_DELIMITER)];
7
- }
8
-
9
- export const isValid = {
10
- Setting: (fullKey: string) => {
11
- if (!STATE[fullKey]) {
12
- const [key, namespace] = splitFullKey(fullKey);
13
- throw new Error(
14
- `Setting "${key}" key in "${namespace}" namespace. DOES NOT EXIST`,
15
- );
16
- }
17
-
18
- return true;
19
- },
20
-
21
- Defining: (fullKey: string) => {
22
- if (STATE[fullKey]) {
23
- const [key, namespace] = splitFullKey(fullKey);
24
- throw new Error(
25
- `Redefining "${key}" key in "${namespace}" namespace. ALREADY DEFINED`,
26
- );
27
- }
28
-
29
- return true;
30
- },
31
- };