MCPcopy Index your code
hub / github.com/violentmonkey/violentmonkey / transform

Function transform

src/background/utils/patch-db.js:24–65  ·  view source on GitHub ↗
(db)

Source from the content-addressed store, hash-verified

22 };
23 }
24 function transform(db) {
25 const tx = db.transaction([SCRIPTS, S_REQUIRE, S_CACHE, VALUES]);
26 const updates = {};
27 let processing = 3;
28 const done = () => {
29 processing -= 1;
30 if (!processing) resolve(storage.api.set(updates));
31 };
32 const getAll = (storeName, callback) => {
33 const req = tx.objectStore(storeName).getAll();
34 req.onsuccess = () => callback(req.result);
35 req.onerror = reject;
36 };
37 getAll(SCRIPTS, (allScripts) => {
38 const uriMap = {};
39 allScripts.forEach((script) => {
40 const { code, id, uri } = script;
41 updates[storage[S_SCRIPT].toKey(id)] = transformScript(script);
42 updates[storage[S_CODE].toKey(id)] = code;
43 uriMap[uri] = id;
44 });
45 getAll(VALUES, (allValues) => {
46 allValues.forEach(({ uri, [VALUES]: values }) => {
47 const id = uriMap[uri];
48 if (id) updates[storage[S_VALUE].toKey(id)] = values;
49 });
50 done();
51 });
52 });
53 getAll(S_CACHE, (allCache) => {
54 allCache.forEach(({ uri, data }) => {
55 updates[storage[S_CACHE].toKey(uri)] = data;
56 });
57 done();
58 });
59 getAll(S_REQUIRE, (allRequire) => {
60 allRequire.forEach(({ uri, code }) => {
61 updates[storage[S_REQUIRE].toKey(uri)] = code;
62 });
63 done();
64 });
65 }
66 function transformScript(script) {
67 return {
68 meta: parseMeta(script.code),

Callers 3

doFetchFunction · 0.85
initFunction · 0.85
objectPickFunction · 0.85

Calls 4

getAllFunction · 0.85
transformScriptFunction · 0.85
doneFunction · 0.85
toKeyMethod · 0.80

Tested by

no test coverage detected