(db)
| 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), |
no test coverage detected