hypercore-storage 3.0.1 → 3.0.2
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/migrations/1/index.js +43 -0
- package/package.json +3 -2
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const c = require('compact-encoding')
|
|
2
|
+
const schema = require('../../encoding/spec/hyperschema')
|
|
3
|
+
const { core: coreKey } = require('../../lib/keys.js')
|
|
4
|
+
const View = require('../../lib/view.js')
|
|
5
|
+
|
|
6
|
+
const CORE_AUTH = schema.getEncoding('@core/auth')
|
|
7
|
+
|
|
8
|
+
const { CorestoreRX, CorestoreTX } = require('../../lib/tx.js')
|
|
9
|
+
|
|
10
|
+
async function core (core, { version, dryRun = false } = {}) {
|
|
11
|
+
if (dryRun) return // dryRun mode not supported atm
|
|
12
|
+
|
|
13
|
+
const rx = core.db.read({ autoDestroy: true })
|
|
14
|
+
const storedAuthPromise = rx.get(coreKey.auth(core.core.corePointer))
|
|
15
|
+
|
|
16
|
+
rx.tryFlush()
|
|
17
|
+
|
|
18
|
+
const storedAuth = await storedAuthPromise
|
|
19
|
+
if (!storedAuth) return
|
|
20
|
+
|
|
21
|
+
const auth = c.decode(CORE_AUTH, storedAuth)
|
|
22
|
+
await commitCoreMigration(auth, core, version)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
module.exports = { core }
|
|
26
|
+
|
|
27
|
+
async function commitCoreMigration (auth, core, version) {
|
|
28
|
+
const view = new View()
|
|
29
|
+
const rx = new CorestoreRX(core.db, view)
|
|
30
|
+
|
|
31
|
+
const storeCorePromise = rx.getCore(auth.discoveryKey)
|
|
32
|
+
rx.tryFlush()
|
|
33
|
+
|
|
34
|
+
const storeCore = await storeCorePromise
|
|
35
|
+
|
|
36
|
+
storeCore.version = version
|
|
37
|
+
|
|
38
|
+
const tx = new CorestoreTX(view)
|
|
39
|
+
tx.putCore(auth.discoveryKey, storeCore)
|
|
40
|
+
tx.apply()
|
|
41
|
+
|
|
42
|
+
await View.flush(view.changes, core.db)
|
|
43
|
+
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hypercore-storage",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.2",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"files": [
|
|
6
6
|
"index.js",
|
|
7
7
|
"lib/*.js",
|
|
8
8
|
"encoding/*",
|
|
9
|
-
"migrations/0/*.js"
|
|
9
|
+
"migrations/0/*.js",
|
|
10
|
+
"migrations/1/*.js"
|
|
10
11
|
],
|
|
11
12
|
"scripts": {
|
|
12
13
|
"format": "prettier --write .",
|