hypercore-storage 1.10.0 → 1.12.0
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/index.js +24 -0
- package/lib/streams.js +19 -0
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -21,6 +21,7 @@ const {
|
|
|
21
21
|
const {
|
|
22
22
|
createCoreStream,
|
|
23
23
|
createAliasStream,
|
|
24
|
+
createDiscoveryKeyStream,
|
|
24
25
|
createBlockStream,
|
|
25
26
|
createBitfieldStream,
|
|
26
27
|
createUserDataStream,
|
|
@@ -383,6 +384,25 @@ class CorestoreStorage {
|
|
|
383
384
|
return this.db.ready()
|
|
384
385
|
}
|
|
385
386
|
|
|
387
|
+
async audit () {
|
|
388
|
+
for await (const { core } of this.createCoreStream()) {
|
|
389
|
+
const coreRx = new CoreRX(core, this.db, EMPTY)
|
|
390
|
+
const authPromise = coreRx.getAuth()
|
|
391
|
+
|
|
392
|
+
coreRx.tryFlush()
|
|
393
|
+
|
|
394
|
+
const auth = await authPromise
|
|
395
|
+
|
|
396
|
+
if (!auth.manifest || auth.manifest.version > 0) continue
|
|
397
|
+
if (auth.manifest.linked === null) continue
|
|
398
|
+
|
|
399
|
+
auth.manifest.linked = null
|
|
400
|
+
const coreTx = new CoreTX(core, this.db, null, [])
|
|
401
|
+
coreTx.setAuth(auth)
|
|
402
|
+
await coreTx.flush()
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
386
406
|
async deleteCore (ptr) {
|
|
387
407
|
const rx = new CoreRX(ptr, this.db, EMPTY)
|
|
388
408
|
|
|
@@ -614,6 +634,10 @@ class CorestoreStorage {
|
|
|
614
634
|
return createAliasStream(this.db, EMPTY, namespace)
|
|
615
635
|
}
|
|
616
636
|
|
|
637
|
+
createDiscoveryKeyStream (namespace) {
|
|
638
|
+
return createDiscoveryKeyStream(this.db, EMPTY, namespace)
|
|
639
|
+
}
|
|
640
|
+
|
|
617
641
|
async getAlias (alias) {
|
|
618
642
|
if (this.version === 0) await this._migrateStore()
|
|
619
643
|
|
package/lib/streams.js
CHANGED
|
@@ -13,6 +13,7 @@ module.exports = {
|
|
|
13
13
|
createUserDataStream,
|
|
14
14
|
createCoreStream,
|
|
15
15
|
createAliasStream,
|
|
16
|
+
createDiscoveryKeyStream,
|
|
16
17
|
createTreeNodeStream,
|
|
17
18
|
createLocalStream
|
|
18
19
|
}
|
|
@@ -27,6 +28,16 @@ function createCoreStream (db, view) {
|
|
|
27
28
|
return ite
|
|
28
29
|
}
|
|
29
30
|
|
|
31
|
+
function createDiscoveryKeyStream (db, view, namespace) {
|
|
32
|
+
const start = namespace ? store.coreByAliasStart(namespace) : store.coreStart()
|
|
33
|
+
const end = namespace ? store.coreByAliasEnd(namespace) : store.coreEnd()
|
|
34
|
+
|
|
35
|
+
const ite = view.iterator(db, start, end, false)
|
|
36
|
+
|
|
37
|
+
ite._readableState.map = namespace ? mapNamespaceDiscoveryKeys : mapAllDiscoveryKeys
|
|
38
|
+
return ite
|
|
39
|
+
}
|
|
40
|
+
|
|
30
41
|
function createAliasStream (db, view, namespace) {
|
|
31
42
|
const start = store.coreByAliasStart(namespace)
|
|
32
43
|
const end = store.coreByAliasEnd(namespace)
|
|
@@ -117,6 +128,14 @@ function mapCore (data) {
|
|
|
117
128
|
return { discoveryKey, core }
|
|
118
129
|
}
|
|
119
130
|
|
|
131
|
+
function mapAllDiscoveryKeys (data) {
|
|
132
|
+
return store.discoveryKey(data.key)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function mapNamespaceDiscoveryKeys (data) {
|
|
136
|
+
return data.value
|
|
137
|
+
}
|
|
138
|
+
|
|
120
139
|
function mapAlias (data) {
|
|
121
140
|
const alias = store.alias(data.key)
|
|
122
141
|
return { alias, discoveryKey: data.value }
|