MCPcopy Index your code
hub / github.com/pyscript/pyscript / storage

Function storage

core/src/storage.js:34–72  ·  view source on GitHub ↗
(name)

Source from the content-addressed store, hash-verified

32
33// this export simulate pyscript.storage exposed in the Python world
34export const storage = async (name) => {
35 if (!name) throw new SyntaxError("The storage name must be defined");
36
37 const store = new IDBMapSync(`@pyscript/${name}`);
38 const map = new Map();
39 await store.sync();
40 for (const [k, v] of store.entries()) map.set(k, from_idb(v));
41
42 const clear = () => {
43 map.clear();
44 store.clear();
45 };
46
47 const sync = async () => {
48 await store.sync();
49 };
50
51 return new Proxy(map, {
52 ownKeys: (map) => [...map.keys()],
53 has: (map, name) => map.has(name),
54 get: (map, name) => {
55 if (name === "clear") return clear;
56 if (name === "sync") return sync;
57 return map.get(name);
58 },
59 set: (map, name, value) => {
60 map.set(name, value);
61 store.set(name, to_idb(value));
62 return true;
63 },
64 deleteProperty: (map, name) => {
65 if (map.has(name)) {
66 map.delete(name);
67 store.delete(name);
68 }
69 return true;
70 },
71 });
72};

Callers

nothing calls this directly

Calls 7

from_idbFunction · 0.85
to_idbFunction · 0.85
syncMethod · 0.80
hasMethod · 0.80
setMethod · 0.45
getMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected