hypercore-storage 1.9.6 → 1.11.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 +11 -4
- package/lib/streams.js +19 -0
- package/package.json +1 -1
- package/spec/hyperschema/index.js +6 -2
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,
|
|
@@ -406,10 +407,12 @@ class CorestoreStorage {
|
|
|
406
407
|
const end = core.core(ptr.corePointer + 1)
|
|
407
408
|
tx.tryDeleteRange(start, end)
|
|
408
409
|
|
|
409
|
-
|
|
410
|
-
const
|
|
411
|
-
|
|
412
|
-
|
|
410
|
+
if (sessions) {
|
|
411
|
+
for (const { dataPointer } of sessions) {
|
|
412
|
+
const start = core.data(dataPointer)
|
|
413
|
+
const end = core.data(dataPointer + 1)
|
|
414
|
+
tx.tryDeleteRange(start, end)
|
|
415
|
+
}
|
|
413
416
|
}
|
|
414
417
|
|
|
415
418
|
return tx.flush()
|
|
@@ -612,6 +615,10 @@ class CorestoreStorage {
|
|
|
612
615
|
return createAliasStream(this.db, EMPTY, namespace)
|
|
613
616
|
}
|
|
614
617
|
|
|
618
|
+
createDiscoveryKeyStream (namespace) {
|
|
619
|
+
return createDiscoveryKeyStream(this.db, EMPTY, namespace)
|
|
620
|
+
}
|
|
621
|
+
|
|
615
622
|
async getAlias (alias) {
|
|
616
623
|
if (this.version === 0) await this._migrateStore()
|
|
617
624
|
|
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 }
|
package/package.json
CHANGED
|
@@ -245,6 +245,8 @@ const encoding8 = {
|
|
|
245
245
|
|
|
246
246
|
// @core/manifest.signers
|
|
247
247
|
const encoding9_4 = c.array(encoding7)
|
|
248
|
+
// @core/manifest.linked
|
|
249
|
+
const encoding9_6 = c.array(c.fixed32)
|
|
248
250
|
|
|
249
251
|
// @core/manifest
|
|
250
252
|
const encoding9 = {
|
|
@@ -256,12 +258,13 @@ const encoding9 = {
|
|
|
256
258
|
encoding9_4.preencode(state, m.signers)
|
|
257
259
|
|
|
258
260
|
if (m.prologue) encoding8.preencode(state, m.prologue)
|
|
261
|
+
if (m.linked) encoding9_6.preencode(state, m.linked)
|
|
259
262
|
},
|
|
260
263
|
encode (state, m) {
|
|
261
264
|
const flags =
|
|
262
265
|
(m.allowPatch ? 1 : 0) |
|
|
263
266
|
(m.prologue ? 2 : 0) |
|
|
264
|
-
(m.
|
|
267
|
+
(m.linked ? 4 : 0)
|
|
265
268
|
|
|
266
269
|
c.uint.encode(state, m.version)
|
|
267
270
|
c.uint.encode(state, flags)
|
|
@@ -270,6 +273,7 @@ const encoding9 = {
|
|
|
270
273
|
encoding9_4.encode(state, m.signers)
|
|
271
274
|
|
|
272
275
|
if (m.prologue) encoding8.encode(state, m.prologue)
|
|
276
|
+
if (m.linked) encoding9_6.encode(state, m.linked)
|
|
273
277
|
},
|
|
274
278
|
decode (state) {
|
|
275
279
|
const r0 = c.uint.decode(state)
|
|
@@ -282,7 +286,7 @@ const encoding9 = {
|
|
|
282
286
|
allowPatch: (flags & 1) !== 0,
|
|
283
287
|
signers: encoding9_4.decode(state),
|
|
284
288
|
prologue: (flags & 2) !== 0 ? encoding8.decode(state) : null,
|
|
285
|
-
|
|
289
|
+
linked: (flags & 4) !== 0 ? encoding9_6.decode(state) : null
|
|
286
290
|
}
|
|
287
291
|
}
|
|
288
292
|
}
|