mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-14 15:00:01 -04:00
re-implement idbmap for storage proxy
This commit is contained in:
parent
453f15f796
commit
efa30f6d84
3 changed files with 17 additions and 21 deletions
|
@ -43,7 +43,7 @@
|
|||
"type": "module",
|
||||
"dependencies": {
|
||||
"@mercuryworkshop/bare-mux": "^2.0.1",
|
||||
"@webreflection/idb-map": "^0.1.3",
|
||||
"@webreflection/idb-map": "^0.3.1",
|
||||
"astravel": "^0.6.1",
|
||||
"astring": "^1.8.6",
|
||||
"meriyah": "^4.4.2"
|
||||
|
|
10
pnpm-lock.yaml
generated
10
pnpm-lock.yaml
generated
|
@ -12,8 +12,8 @@ importers:
|
|||
specifier: ^2.0.1
|
||||
version: 2.0.1
|
||||
'@webreflection/idb-map':
|
||||
specifier: ^0.1.3
|
||||
version: 0.1.3
|
||||
specifier: ^0.3.1
|
||||
version: 0.3.1
|
||||
astravel:
|
||||
specifier: ^0.6.1
|
||||
version: 0.6.1
|
||||
|
@ -477,8 +477,8 @@ packages:
|
|||
'@ungap/structured-clone@1.2.0':
|
||||
resolution: {integrity: sha512-zuVdFrMJiuCDQUMCzQaD6KL28MjnqqN8XnAqiEq9PNm/hCPTSGfrXCOfwj1ow4LFb/tNymJPwsNbVePc1xFqrQ==}
|
||||
|
||||
'@webreflection/idb-map@0.1.3':
|
||||
resolution: {integrity: sha512-7lTEpXDgpy9xueW4NSNkBHgqedz/dlGgtwTZa4fRMKWJKcnC9cORVlXwV7qNyYYKarT8gpB1+wv5UNBYhjgc8w==}
|
||||
'@webreflection/idb-map@0.3.1':
|
||||
resolution: {integrity: sha512-lRCanqwR7tHHFohJHAMSMEZnoNPvgjcKr0f5e4y+lTJA+fctT61EZ+f5pT5/+8+wlSsMAvXjzfKRLT6o9aqxbA==}
|
||||
|
||||
abort-controller@3.0.0:
|
||||
resolution: {integrity: sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==}
|
||||
|
@ -1764,7 +1764,7 @@ snapshots:
|
|||
|
||||
'@ungap/structured-clone@1.2.0': {}
|
||||
|
||||
'@webreflection/idb-map@0.1.3': {}
|
||||
'@webreflection/idb-map@0.3.1': {}
|
||||
|
||||
abort-controller@3.0.0:
|
||||
dependencies:
|
||||
|
|
|
@ -1,44 +1,40 @@
|
|||
// import IDBMap from "@webreflection/idb-map";
|
||||
|
||||
// this will be converted to use IDB later but i can't figure out how to make it work synchronously
|
||||
|
||||
function filterStorage(scope: Storage) {
|
||||
return Object.keys(scope).filter((key) => key.startsWith(window.__location.host));
|
||||
}
|
||||
import IDBMapSync from "@webreflection/idb-map/sync";
|
||||
|
||||
function storageProxy(scope: Storage): Storage {
|
||||
// const store = new IDBMap(window.__location.host);
|
||||
const store = new IDBMapSync(window.__location.host);
|
||||
|
||||
return new Proxy(scope, {
|
||||
get(target, prop) {
|
||||
async get(target, prop) {
|
||||
await store.sync();
|
||||
|
||||
switch (prop) {
|
||||
case "getItem":
|
||||
return (key: string) => {
|
||||
return target.getItem(window.__location.host + "@" + key);
|
||||
return store.get(key);
|
||||
}
|
||||
|
||||
case "setItem":
|
||||
return (key: string, value: string) => {
|
||||
target.setItem(window.__location.host + "@" + key, value);
|
||||
store.set(key, value);
|
||||
}
|
||||
|
||||
case "removeItem":
|
||||
return (key: string) => {
|
||||
target.removeItem(window.__location.host + "@" + key);
|
||||
store.delete(key);
|
||||
}
|
||||
|
||||
case "clear":
|
||||
return () => {
|
||||
filterStorage(target).forEach((key) => target.removeItem(key));
|
||||
store.clear();
|
||||
}
|
||||
|
||||
case "key":
|
||||
return (index: number) => {
|
||||
return target[filterStorage(target)[index]];
|
||||
store.keys()[index];
|
||||
}
|
||||
|
||||
case "length":
|
||||
return filterStorage(target).length;
|
||||
return store.size;
|
||||
}
|
||||
},
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue