wxt-svelte-storage 0.0.1 → 0.0.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/dist/index.cjs +13 -12
- package/dist/index.d.cts +24 -8
- package/dist/index.d.mts +24 -8
- package/dist/index.mjs +13 -12
- package/package.json +16 -3
package/dist/index.cjs
CHANGED
|
@@ -14,36 +14,37 @@ function stateStorage(key, initialValue, { manualUpdate = false, async = false }
|
|
|
14
14
|
init: () => initialValue,
|
|
15
15
|
fallback: initialValue
|
|
16
16
|
});
|
|
17
|
+
const getStorage = storageDefinition.getValue().then(updateFromStorage);
|
|
17
18
|
const subscribe = (0, svelte_reactivity.createSubscriber)((update) => {
|
|
18
19
|
subscriberUpdate = update;
|
|
19
20
|
return storageDefinition.watch(updateFromStorage);
|
|
20
21
|
});
|
|
21
22
|
const proxy = new Proxy(currentState, {
|
|
22
|
-
get(
|
|
23
|
+
get(obj, prop, receiver) {
|
|
23
24
|
subscribe();
|
|
24
|
-
return Reflect.get(
|
|
25
|
+
return Reflect.get(obj, prop, receiver);
|
|
25
26
|
},
|
|
26
|
-
set(
|
|
27
|
-
const oldValue = Reflect.get(
|
|
28
|
-
const result = Reflect.set(
|
|
29
|
-
if (result && !Object.is(oldValue,
|
|
30
|
-
if (!manualUpdate) storageDefinition.setValue(
|
|
27
|
+
set(obj, prop, value, receiver) {
|
|
28
|
+
const oldValue = Reflect.get(obj, prop, receiver);
|
|
29
|
+
const result = Reflect.set(obj, prop, value, receiver);
|
|
30
|
+
if (result && !Object.is(oldValue, obj)) {
|
|
31
|
+
if (!manualUpdate) storageDefinition.setValue(obj);
|
|
31
32
|
subscriberUpdate?.();
|
|
32
33
|
}
|
|
33
34
|
return result;
|
|
34
35
|
},
|
|
35
|
-
deleteProperty(
|
|
36
|
-
const hadKey = Reflect.has(
|
|
37
|
-
const result = Reflect.deleteProperty(
|
|
36
|
+
deleteProperty(obj, prop) {
|
|
37
|
+
const hadKey = Reflect.has(obj, prop);
|
|
38
|
+
const result = Reflect.deleteProperty(obj, prop);
|
|
38
39
|
if (result && hadKey) {
|
|
39
|
-
if (!manualUpdate) storageDefinition.setValue(
|
|
40
|
+
if (!manualUpdate) storageDefinition.setValue(obj);
|
|
40
41
|
subscriberUpdate?.();
|
|
41
42
|
}
|
|
42
43
|
return result;
|
|
43
44
|
}
|
|
44
45
|
});
|
|
45
46
|
const returnValue = manualUpdate ? [proxy, () => storageDefinition.setValue(currentState)] : proxy;
|
|
46
|
-
return async ?
|
|
47
|
+
return async ? getStorage.then(() => Promise.resolve(returnValue)) : returnValue;
|
|
47
48
|
}
|
|
48
49
|
var SvelteMapStorage = class extends svelte_reactivity.SvelteMap {
|
|
49
50
|
storageDefinition;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,11 +1,28 @@
|
|
|
1
1
|
import { SvelteMap, SvelteSet } from "svelte/reactivity";
|
|
2
2
|
import { StorageItemKey } from "@wxt-dev/storage";
|
|
3
|
-
|
|
4
|
-
manualUpdate?:
|
|
5
|
-
async
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
export declare function stateStorage<T extends object>(key: StorageItemKey, initialValue: T, settings: {
|
|
4
|
+
manualUpdate?: false;
|
|
5
|
+
async: true;
|
|
6
|
+
}): Promise<T>;
|
|
7
|
+
export declare function stateStorage<T extends object>(key: StorageItemKey, initialValue: T, settings: {
|
|
8
|
+
manualUpdate: true;
|
|
9
|
+
async: true;
|
|
10
|
+
}): [Promise<T>, () => Promise<void>];
|
|
11
|
+
export declare function stateStorage<T extends object>(key: StorageItemKey, initialValue: T, settings: {
|
|
12
|
+
manualUpdate: true;
|
|
13
|
+
async?: false;
|
|
14
|
+
}): [T, () => Promise<void>];
|
|
15
|
+
export declare function stateStorage<T extends object>(key: StorageItemKey, initialValue: T, settings: {
|
|
16
|
+
manualUpdate?: false;
|
|
17
|
+
async?: false;
|
|
18
|
+
}): T;
|
|
19
|
+
export declare function stateStorage<T extends object>(key: StorageItemKey, initialValue: T, settings: {
|
|
20
|
+
async?: false;
|
|
21
|
+
}): T;
|
|
22
|
+
export declare function stateStorage<T extends object>(key: StorageItemKey, initialValue: T, settings: {
|
|
23
|
+
manualUpdate?: false;
|
|
24
|
+
}): T;
|
|
25
|
+
export declare function stateStorage<T extends object>(key: StorageItemKey, initialValue: T): T;
|
|
9
26
|
export declare class SvelteMapStorage<T extends Record<string, unknown>, K extends keyof T & string = keyof T & string> extends SvelteMap<K, T[K]> {
|
|
10
27
|
private storageDefinition;
|
|
11
28
|
private manualUpdate;
|
|
@@ -24,5 +41,4 @@ export declare class SvelteSetStorage<T> extends SvelteSet<T> {
|
|
|
24
41
|
update(): Promise<void>;
|
|
25
42
|
add(value: T): this;
|
|
26
43
|
delete(value: T): boolean;
|
|
27
|
-
}
|
|
28
|
-
export {};
|
|
44
|
+
}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,11 +1,28 @@
|
|
|
1
1
|
import { SvelteMap, SvelteSet } from "svelte/reactivity";
|
|
2
2
|
import { StorageItemKey } from "@wxt-dev/storage";
|
|
3
|
-
|
|
4
|
-
manualUpdate?:
|
|
5
|
-
async
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
export declare function stateStorage<T extends object>(key: StorageItemKey, initialValue: T, settings: {
|
|
4
|
+
manualUpdate?: false;
|
|
5
|
+
async: true;
|
|
6
|
+
}): Promise<T>;
|
|
7
|
+
export declare function stateStorage<T extends object>(key: StorageItemKey, initialValue: T, settings: {
|
|
8
|
+
manualUpdate: true;
|
|
9
|
+
async: true;
|
|
10
|
+
}): [Promise<T>, () => Promise<void>];
|
|
11
|
+
export declare function stateStorage<T extends object>(key: StorageItemKey, initialValue: T, settings: {
|
|
12
|
+
manualUpdate: true;
|
|
13
|
+
async?: false;
|
|
14
|
+
}): [T, () => Promise<void>];
|
|
15
|
+
export declare function stateStorage<T extends object>(key: StorageItemKey, initialValue: T, settings: {
|
|
16
|
+
manualUpdate?: false;
|
|
17
|
+
async?: false;
|
|
18
|
+
}): T;
|
|
19
|
+
export declare function stateStorage<T extends object>(key: StorageItemKey, initialValue: T, settings: {
|
|
20
|
+
async?: false;
|
|
21
|
+
}): T;
|
|
22
|
+
export declare function stateStorage<T extends object>(key: StorageItemKey, initialValue: T, settings: {
|
|
23
|
+
manualUpdate?: false;
|
|
24
|
+
}): T;
|
|
25
|
+
export declare function stateStorage<T extends object>(key: StorageItemKey, initialValue: T): T;
|
|
9
26
|
export declare class SvelteMapStorage<T extends Record<string, unknown>, K extends keyof T & string = keyof T & string> extends SvelteMap<K, T[K]> {
|
|
10
27
|
private storageDefinition;
|
|
11
28
|
private manualUpdate;
|
|
@@ -24,5 +41,4 @@ export declare class SvelteSetStorage<T> extends SvelteSet<T> {
|
|
|
24
41
|
update(): Promise<void>;
|
|
25
42
|
add(value: T): this;
|
|
26
43
|
delete(value: T): boolean;
|
|
27
|
-
}
|
|
28
|
-
export {};
|
|
44
|
+
}
|
package/dist/index.mjs
CHANGED
|
@@ -13,36 +13,37 @@ function stateStorage(key, initialValue, { manualUpdate = false, async = false }
|
|
|
13
13
|
init: () => initialValue,
|
|
14
14
|
fallback: initialValue
|
|
15
15
|
});
|
|
16
|
+
const getStorage = storageDefinition.getValue().then(updateFromStorage);
|
|
16
17
|
const subscribe = createSubscriber((update) => {
|
|
17
18
|
subscriberUpdate = update;
|
|
18
19
|
return storageDefinition.watch(updateFromStorage);
|
|
19
20
|
});
|
|
20
21
|
const proxy = new Proxy(currentState, {
|
|
21
|
-
get(
|
|
22
|
+
get(obj, prop, receiver) {
|
|
22
23
|
subscribe();
|
|
23
|
-
return Reflect.get(
|
|
24
|
+
return Reflect.get(obj, prop, receiver);
|
|
24
25
|
},
|
|
25
|
-
set(
|
|
26
|
-
const oldValue = Reflect.get(
|
|
27
|
-
const result = Reflect.set(
|
|
28
|
-
if (result && !Object.is(oldValue,
|
|
29
|
-
if (!manualUpdate) storageDefinition.setValue(
|
|
26
|
+
set(obj, prop, value, receiver) {
|
|
27
|
+
const oldValue = Reflect.get(obj, prop, receiver);
|
|
28
|
+
const result = Reflect.set(obj, prop, value, receiver);
|
|
29
|
+
if (result && !Object.is(oldValue, obj)) {
|
|
30
|
+
if (!manualUpdate) storageDefinition.setValue(obj);
|
|
30
31
|
subscriberUpdate?.();
|
|
31
32
|
}
|
|
32
33
|
return result;
|
|
33
34
|
},
|
|
34
|
-
deleteProperty(
|
|
35
|
-
const hadKey = Reflect.has(
|
|
36
|
-
const result = Reflect.deleteProperty(
|
|
35
|
+
deleteProperty(obj, prop) {
|
|
36
|
+
const hadKey = Reflect.has(obj, prop);
|
|
37
|
+
const result = Reflect.deleteProperty(obj, prop);
|
|
37
38
|
if (result && hadKey) {
|
|
38
|
-
if (!manualUpdate) storageDefinition.setValue(
|
|
39
|
+
if (!manualUpdate) storageDefinition.setValue(obj);
|
|
39
40
|
subscriberUpdate?.();
|
|
40
41
|
}
|
|
41
42
|
return result;
|
|
42
43
|
}
|
|
43
44
|
});
|
|
44
45
|
const returnValue = manualUpdate ? [proxy, () => storageDefinition.setValue(currentState)] : proxy;
|
|
45
|
-
return async ?
|
|
46
|
+
return async ? getStorage.then(() => Promise.resolve(returnValue)) : returnValue;
|
|
46
47
|
}
|
|
47
48
|
var SvelteMapStorage = class extends SvelteMap {
|
|
48
49
|
storageDefinition;
|
package/package.json
CHANGED
|
@@ -1,8 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wxt-svelte-storage",
|
|
3
|
-
|
|
3
|
+
"license": "MIT",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "git+https://github.com/dragonostic/wxt-svelte-storage.git"
|
|
7
|
+
},
|
|
8
|
+
"version": "0.0.3",
|
|
4
9
|
"keywords": [
|
|
5
|
-
"svelte"
|
|
10
|
+
"svelte",
|
|
11
|
+
"wxt",
|
|
12
|
+
"webext",
|
|
13
|
+
"browser-extension",
|
|
14
|
+
"web-extension",
|
|
15
|
+
"state-management",
|
|
16
|
+
"typescript",
|
|
17
|
+
"chrome",
|
|
18
|
+
"firefox"
|
|
6
19
|
],
|
|
7
20
|
"type": "module",
|
|
8
21
|
"main": "./dist/index.cjs",
|
|
@@ -14,7 +27,7 @@
|
|
|
14
27
|
"scripts": {
|
|
15
28
|
"build": "tsdown",
|
|
16
29
|
"check": "bun run build && check",
|
|
17
|
-
|
|
30
|
+
"prepublishOnly": "bun run build"
|
|
18
31
|
},
|
|
19
32
|
"devDependencies": {
|
|
20
33
|
"@arethetypeswrong/core": "^0.18.5",
|