hypercore-storage 2.9.0 → 3.0.1

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/lib/streams.js CHANGED
@@ -1,7 +1,7 @@
1
1
  const b4a = require('b4a')
2
2
  const BlockDependencyStream = require('./block-dependency-stream.js')
3
- const { core, store } = require('./keys.js')
4
- const schema = require('../spec/hyperschema')
3
+ const { core, store, group } = require('./keys.js')
4
+ const schema = require('../encoding/spec/hyperschema')
5
5
 
6
6
  const CORESTORE_CORE = schema.getEncoding('@corestore/core')
7
7
  const CORE_TREE_NODE = schema.getEncoding('@core/tree-node')
@@ -16,7 +16,8 @@ module.exports = {
16
16
  createDiscoveryKeyStream,
17
17
  createTreeNodeStream,
18
18
  createMarkStream,
19
- createLocalStream
19
+ createLocalStream,
20
+ createGroupUpdateStream
20
21
  }
21
22
 
22
23
  function createCoreStream(db, view) {
@@ -49,6 +50,16 @@ function createAliasStream(db, view, namespace) {
49
50
  return ite
50
51
  }
51
52
 
53
+ function createGroupUpdateStream(db, view, groupID, { gte = 0, reverse = true } = {}) {
54
+ const start = group.entry(groupID, gte, 0)
55
+ const end = group.entry(groupID + 1, 0, 0)
56
+
57
+ const ite = view.iterator(db, start, end, reverse)
58
+
59
+ ite._readableState.map = mapGroupUpdate
60
+ return ite
61
+ }
62
+
52
63
  function createBlockIterator(ptr, db, view, start, end, reverse) {
53
64
  if (ptr.dependencies.length > 0) {
54
65
  return new BlockDependencyStream(ptr, db, view, start, end, reverse)
@@ -164,6 +175,10 @@ function mapLocal(data) {
164
175
  return { key, value: data.value }
165
176
  }
166
177
 
178
+ function mapGroupUpdate(data) {
179
+ return data.value
180
+ }
181
+
167
182
  function mapUserData(data) {
168
183
  const key = core.userDataKey(data.key)
169
184
  return { key, value: data.value }
package/lib/tx.js CHANGED
@@ -1,13 +1,17 @@
1
- const schema = require('../spec/hyperschema')
2
- const { store, core } = require('./keys.js')
3
- const View = require('./view.js')
4
1
  const b4a = require('b4a')
2
+ const c = require('compact-encoding')
5
3
  const flat = require('flat-tree')
6
4
 
5
+ const schema = require('../encoding/spec/hyperschema')
6
+ const { store, core, group } = require('./keys.js')
7
+ const View = require('./view.js')
8
+
7
9
  const CORESTORE_HEAD = schema.getEncoding('@corestore/head')
8
10
  const CORESTORE_CORE = schema.getEncoding('@corestore/core')
11
+ const CORESTORE_GROUP = c.uint
9
12
 
10
13
  const CORE_AUTH = schema.getEncoding('@core/auth')
14
+ const CORE_GROUP = schema.getEncoding('@core/group')
11
15
  const CORE_SESSIONS = schema.getEncoding('@core/sessions')
12
16
  const CORE_HEAD = schema.getEncoding('@core/head')
13
17
  const CORE_TREE_NODE = schema.getEncoding('@core/tree-node')
@@ -43,6 +47,14 @@ class CoreTX {
43
47
  this.changes.push([core.dependency(this.core.dataPointer), encode(CORE_DEPENDENCY, dep), null])
44
48
  }
45
49
 
50
+ setGroup(group) {
51
+ this.changes.push([core.group(this.core.dataPointer), encode(CORE_GROUP, group), null])
52
+ }
53
+
54
+ deleteGroup() {
55
+ this.changes.push([core.group(this.core.dataPointer), null, null])
56
+ }
57
+
46
58
  setHints(hints) {
47
59
  this.changes.push([core.hints(this.core.dataPointer), encode(CORE_HINTS, hints), null])
48
60
  }
@@ -140,6 +152,14 @@ class CoreTX {
140
152
  ])
141
153
  }
142
154
 
155
+ putGroupUpdate(groupPtr, timestamp, key) {
156
+ this.changes.push([group.entry(groupPtr, timestamp, this.core.corePointer), key, null])
157
+ }
158
+
159
+ deleteGroupUpdate(groupPtr, timestamp) {
160
+ this.changes.push([group.entry(groupPtr, timestamp, this.core.corePointer), null, null])
161
+ }
162
+
143
163
  flush() {
144
164
  const changes = this.changes
145
165
  if (changes === null) return Promise.resolve(!this.view)
@@ -194,6 +214,13 @@ class CoreRX {
194
214
  )
195
215
  }
196
216
 
217
+ async getGroup() {
218
+ return await decode(
219
+ CORE_GROUP,
220
+ await this.view.get(this.read, core.group(this.core.corePointer))
221
+ )
222
+ }
223
+
197
224
  static async getHints(db, c) {
198
225
  return await decode(CORE_HINTS, await db.get(core.hints(c.dataPointer)))
199
226
  }
@@ -276,6 +303,14 @@ class CorestoreTX {
276
303
  this.changes.push([store.coreByAlias(alias), discoveryKey, null])
277
304
  }
278
305
 
306
+ putGroup(topic, groupPtr) {
307
+ this.changes.push([group.topic(topic), encode(CORESTORE_GROUP, groupPtr), null])
308
+ }
309
+
310
+ deleteGroup(topic) {
311
+ this.changes.push([group.topic(topic), null, null])
312
+ }
313
+
279
314
  clear() {
280
315
  const [start, end] = store.clear()
281
316
  this.changes.push([start, null, end])
@@ -296,6 +331,10 @@ class CorestoreRX {
296
331
  view.readStart()
297
332
  }
298
333
 
334
+ async getHeadRaw(db) {
335
+ return await this.view.get(this.read, store.head())
336
+ }
337
+
299
338
  async getHead() {
300
339
  return decode(CORESTORE_HEAD, await this.view.get(this.read, store.head()))
301
340
  }
@@ -308,6 +347,10 @@ class CorestoreRX {
308
347
  return this.view.get(this.read, store.coreByAlias(alias))
309
348
  }
310
349
 
350
+ async getGroup(topic) {
351
+ return decode(CORESTORE_GROUP, await this.view.get(this.read, group.topic(topic)))
352
+ }
353
+
311
354
  tryFlush() {
312
355
  this.read.tryFlush()
313
356
  this._free()
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "hypercore-storage",
3
- "version": "2.9.0",
3
+ "version": "3.0.1",
4
4
  "main": "index.js",
5
5
  "files": [
6
6
  "index.js",
7
7
  "lib/*.js",
8
- "spec/hyperschema/*.js",
8
+ "encoding/*",
9
9
  "migrations/0/*.js"
10
10
  ],
11
11
  "scripts": {
@@ -24,6 +24,14 @@
24
24
  "bare": "bare-fs",
25
25
  "default": "fs"
26
26
  },
27
+ "fs/*": {
28
+ "bare": "bare-fs/*",
29
+ "default": "fs/*"
30
+ },
31
+ "os": {
32
+ "bare": "bare-os",
33
+ "default": "os"
34
+ },
27
35
  "path": {
28
36
  "bare": "bare-path",
29
37
  "default": "path"
@@ -39,13 +47,12 @@
39
47
  "homepage": "https://github.com/holepunchto/hypercore-storage#readme",
40
48
  "dependencies": {
41
49
  "b4a": "^1.6.7",
42
- "bare-fs": "^4.0.1",
43
50
  "bare-path": "^3.0.0",
44
- "compact-encoding": "^3.0.0",
51
+ "compact-encoding": "^3.1.0",
45
52
  "device-file": "^2.1.2",
46
53
  "flat-tree": "^1.12.1",
47
54
  "hypercore-crypto": "^3.4.2",
48
- "hyperschema": "^1.7.0",
55
+ "hyperschema": "^1.21.0",
49
56
  "index-encoder": "^3.3.2",
50
57
  "resolve-reject-promise": "^1.0.0",
51
58
  "rocksdb-native": "^3.11.0",
@@ -53,7 +60,9 @@
53
60
  "streamx": "^2.21.1"
54
61
  },
55
62
  "devDependencies": {
63
+ "bare-os": "^3.9.1",
56
64
  "brittle": "^3.7.0",
65
+ "hypercore-storage-2.9.0": "npm:hypercore-storage@^2.9.0",
57
66
  "lunte": "^1.3.0",
58
67
  "prettier": "^3.6.2",
59
68
  "prettier-config-holepunch": "^2.0.0",