hypercore-storage 1.16.0 → 1.17.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.
@@ -2,7 +2,7 @@ const { Readable, getStreamError } = require('streamx')
2
2
  const { core } = require('./keys')
3
3
 
4
4
  module.exports = class BlockStream extends Readable {
5
- constructor (core, db, updates, start, end, reverse) {
5
+ constructor(core, db, updates, start, end, reverse) {
6
6
  super()
7
7
 
8
8
  this.core = core
@@ -21,24 +21,24 @@ module.exports = class BlockStream extends Readable {
21
21
  this._update()
22
22
  }
23
23
 
24
- _update () {
24
+ _update() {
25
25
  if (this._consumed > this.core.dependencies.length) return
26
26
 
27
27
  const deps = this.core.dependencies
28
28
  const index = this._findDependencyIndex(deps)
29
29
 
30
30
  const curr = index < deps.length ? deps[index] : null
31
- const prev = (index > 0 && index - 1 < deps.length) ? deps[index - 1] : null
31
+ const prev = index > 0 && index - 1 < deps.length ? deps[index - 1] : null
32
32
 
33
- const start = (prev && prev.length > this.start) ? prev.length : this.start
34
- const end = (curr && (this.end === -1 || curr.length < this.end)) ? curr.length : this.end
33
+ const start = prev && prev.length > this.start ? prev.length : this.start
34
+ const end = curr && (this.end === -1 || curr.length < this.end) ? curr.length : this.end
35
35
 
36
36
  const ptr = curr ? curr.dataPointer : this.core.dataPointer
37
37
 
38
38
  this._makeStream(core.block(ptr, start), core.block(ptr, end))
39
39
  }
40
40
 
41
- _findDependencyIndex (deps) {
41
+ _findDependencyIndex(deps) {
42
42
  if (!this.reverse) return this._consumed++
43
43
 
44
44
  let i = deps.length - this._consumed++
@@ -51,21 +51,21 @@ module.exports = class BlockStream extends Readable {
51
51
  return 0
52
52
  }
53
53
 
54
- _predestroy () {
54
+ _predestroy() {
55
55
  if (this._stream !== null) this._stream.destroy()
56
56
  }
57
57
 
58
- _read (cb) {
58
+ _read(cb) {
59
59
  this._drained = this._onreadable()
60
60
  cb(null)
61
61
  }
62
62
 
63
- _maybeDrain () {
63
+ _maybeDrain() {
64
64
  if (this._drained === true) return
65
65
  this._drained = this._onreadable()
66
66
  }
67
67
 
68
- _onreadable () {
68
+ _onreadable() {
69
69
  if (this._stream === null) {
70
70
  this.push(null)
71
71
  return true
@@ -83,7 +83,7 @@ module.exports = class BlockStream extends Readable {
83
83
  return true
84
84
  }
85
85
 
86
- _onclose () {
86
+ _onclose() {
87
87
  if (this.destroying) return
88
88
 
89
89
  const err = getStreamError(this._stream)
@@ -102,7 +102,7 @@ module.exports = class BlockStream extends Readable {
102
102
  this._maybeDrain()
103
103
  }
104
104
 
105
- _makeStream (start, end) {
105
+ _makeStream(start, end) {
106
106
  this._stream = this.updates.iterator(this.db, start, end, this.reverse)
107
107
  this._stream.on('readable', this._maybeDrainBound)
108
108
  this._stream.on('error', noop)
@@ -110,4 +110,4 @@ module.exports = class BlockStream extends Readable {
110
110
  }
111
111
  }
112
112
 
113
- function noop () {}
113
+ function noop() {}
@@ -3,12 +3,12 @@ const { Readable } = require('streamx')
3
3
  // used for returned a stream that just errors (during read during teardown)
4
4
 
5
5
  module.exports = class CloseErrorStream extends Readable {
6
- constructor (err) {
6
+ constructor(err) {
7
7
  super()
8
8
  this.error = err
9
9
  }
10
10
 
11
- _open (cb) {
11
+ _open(cb) {
12
12
  cb(this.error)
13
13
  }
14
14
  }
package/lib/keys.js CHANGED
@@ -283,7 +283,7 @@ core.localKey = function (buffer) {
283
283
 
284
284
  module.exports = { store, core }
285
285
 
286
- function alloc () {
286
+ function alloc() {
287
287
  if (slab.buffer.byteLength - slab.start < 4096) {
288
288
  slab.buffer = b4a.allocUnsafe(slab.buffer.byteLength)
289
289
  slab.start = 0
package/lib/streams.js CHANGED
@@ -18,7 +18,7 @@ module.exports = {
18
18
  createLocalStream
19
19
  }
20
20
 
21
- function createCoreStream (db, view) {
21
+ function createCoreStream(db, view) {
22
22
  const start = store.coreStart()
23
23
  const end = store.coreEnd()
24
24
 
@@ -28,7 +28,7 @@ function createCoreStream (db, view) {
28
28
  return ite
29
29
  }
30
30
 
31
- function createDiscoveryKeyStream (db, view, namespace) {
31
+ function createDiscoveryKeyStream(db, view, namespace) {
32
32
  const start = namespace ? store.coreByAliasStart(namespace) : store.coreStart()
33
33
  const end = namespace ? store.coreByAliasEnd(namespace) : store.coreEnd()
34
34
 
@@ -38,7 +38,7 @@ function createDiscoveryKeyStream (db, view, namespace) {
38
38
  return ite
39
39
  }
40
40
 
41
- function createAliasStream (db, view, namespace) {
41
+ function createAliasStream(db, view, namespace) {
42
42
  const start = store.coreByAliasStart(namespace)
43
43
  const end = store.coreByAliasEnd(namespace)
44
44
 
@@ -48,7 +48,7 @@ function createAliasStream (db, view, namespace) {
48
48
  return ite
49
49
  }
50
50
 
51
- function createBlockIterator (ptr, db, view, start, end, reverse) {
51
+ function createBlockIterator(ptr, db, view, start, end, reverse) {
52
52
  if (ptr.dependencies.length > 0) {
53
53
  return new BlockDependencyStream(ptr, db, view, start, end, reverse)
54
54
  }
@@ -58,14 +58,24 @@ function createBlockIterator (ptr, db, view, start, end, reverse) {
58
58
  return view.iterator(db, s, e, reverse)
59
59
  }
60
60
 
61
- function createBlockStream (ptr, db, view, { gt = -1, gte = gt + 1, lte = -1, lt = lte === -1 ? -1 : lte + 1, reverse = false } = {}) {
61
+ function createBlockStream(
62
+ ptr,
63
+ db,
64
+ view,
65
+ { gt = -1, gte = gt + 1, lte = -1, lt = lte === -1 ? -1 : lte + 1, reverse = false } = {}
66
+ ) {
62
67
  const ite = createBlockIterator(ptr, db, view, gte, lt, reverse)
63
68
 
64
69
  ite._readableState.map = mapBlock
65
70
  return ite
66
71
  }
67
72
 
68
- function createBitfieldStream (ptr, db, view, { gt = -1, gte = gt + 1, lte = -1, lt = lte === -1 ? -1 : lte + 1, reverse = false } = {}) {
73
+ function createBitfieldStream(
74
+ ptr,
75
+ db,
76
+ view,
77
+ { gt = -1, gte = gt + 1, lte = -1, lt = lte === -1 ? -1 : lte + 1, reverse = false } = {}
78
+ ) {
69
79
  const s = core.bitfield(ptr.dataPointer, gte, 0)
70
80
  const e = core.bitfield(ptr.dataPointer, lt === -1 ? Infinity : lt, 0)
71
81
  const ite = view.iterator(db, s, e, false)
@@ -75,7 +85,12 @@ function createBitfieldStream (ptr, db, view, { gt = -1, gte = gt + 1, lte = -1,
75
85
  }
76
86
 
77
87
  // NOTE: this does not do dependency lookups atm
78
- function createTreeNodeStream (ptr, db, view, { gt = -1, gte = gt + 1, lte = -1, lt = lte === -1 ? -1 : lte + 1, reverse = false } = {}) {
88
+ function createTreeNodeStream(
89
+ ptr,
90
+ db,
91
+ view,
92
+ { gt = -1, gte = gt + 1, lte = -1, lt = lte === -1 ? -1 : lte + 1, reverse = false } = {}
93
+ ) {
79
94
  const s = core.tree(ptr.dataPointer, gte, 0)
80
95
  const e = core.tree(ptr.dataPointer, lt === -1 ? Infinity : lt, 0)
81
96
  const ite = view.iterator(db, s, e, false)
@@ -84,8 +99,14 @@ function createTreeNodeStream (ptr, db, view, { gt = -1, gte = gt + 1, lte = -1,
84
99
  return ite
85
100
  }
86
101
 
87
- function createUserDataStream (ptr, db, view, { gt = null, gte = '', lte = null, lt = null, reverse = false } = {}) {
88
- if (gt !== null || lte !== null) throw new Error('gt and lte not yet supported for user data streams')
102
+ function createUserDataStream(
103
+ ptr,
104
+ db,
105
+ view,
106
+ { gt = null, gte = '', lte = null, lt = null, reverse = false } = {}
107
+ ) {
108
+ if (gt !== null || lte !== null)
109
+ throw new Error('gt and lte not yet supported for user data streams')
89
110
 
90
111
  const s = core.userData(ptr.dataPointer, gte)
91
112
  const e = lt === null ? core.userDataEnd(ptr.dataPointer) : core.userData(ptr.dataPointer, lt)
@@ -95,7 +116,12 @@ function createUserDataStream (ptr, db, view, { gt = null, gte = '', lte = null,
95
116
  return ite
96
117
  }
97
118
 
98
- function createLocalStream (ptr, db, view, { gt = null, gte = EMPTY, lte = null, lt = null, reverse = false } = {}) {
119
+ function createLocalStream(
120
+ ptr,
121
+ db,
122
+ view,
123
+ { gt = null, gte = EMPTY, lte = null, lt = null, reverse = false } = {}
124
+ ) {
99
125
  if (gt !== null || lte !== null) throw new Error('gt and lte not yet supported for local streams')
100
126
 
101
127
  const s = core.local(ptr.dataPointer, gte)
@@ -106,45 +132,53 @@ function createLocalStream (ptr, db, view, { gt = null, gte = EMPTY, lte = null,
106
132
  return ite
107
133
  }
108
134
 
109
- function mapBitfield (data) {
135
+ function mapBitfield(data) {
110
136
  const [index, type] = core.bitfieldIndexAndType(data.key)
111
137
  if (type !== 0) return null // ignore for now
112
138
  return { index, page: data.value }
113
139
  }
114
140
 
115
- function mapLocal (data) {
141
+ function mapLocal(data) {
116
142
  const key = core.localKey(data.key)
117
143
  return { key, value: data.value }
118
144
  }
119
145
 
120
- function mapUserData (data) {
146
+ function mapUserData(data) {
121
147
  const key = core.userDataKey(data.key)
122
148
  return { key, value: data.value }
123
149
  }
124
150
 
125
- function mapCore (data) {
151
+ function mapCore(data) {
126
152
  const discoveryKey = store.discoveryKey(data.key)
127
- const core = CORESTORE_CORE.decode({ start: 0, end: data.value.byteLength, buffer: data.value })
153
+ const core = CORESTORE_CORE.decode({
154
+ start: 0,
155
+ end: data.value.byteLength,
156
+ buffer: data.value
157
+ })
128
158
  return { discoveryKey, core }
129
159
  }
130
160
 
131
- function mapAllDiscoveryKeys (data) {
161
+ function mapAllDiscoveryKeys(data) {
132
162
  return store.discoveryKey(data.key)
133
163
  }
134
164
 
135
- function mapNamespaceDiscoveryKeys (data) {
165
+ function mapNamespaceDiscoveryKeys(data) {
136
166
  return data.value
137
167
  }
138
168
 
139
- function mapAlias (data) {
169
+ function mapAlias(data) {
140
170
  const alias = store.alias(data.key)
141
171
  return { alias, discoveryKey: data.value }
142
172
  }
143
173
 
144
- function mapBlock (data) {
174
+ function mapBlock(data) {
145
175
  return { index: core.blockIndex(data.key), value: data.value }
146
176
  }
147
177
 
148
- function mapTreeNode (data) {
149
- return CORE_TREE_NODE.decode({ start: 0, end: data.value.byteLength, buffer: data.value })
178
+ function mapTreeNode(data) {
179
+ return CORE_TREE_NODE.decode({
180
+ start: 0,
181
+ end: data.value.byteLength,
182
+ buffer: data.value
183
+ })
150
184
  }
package/lib/tx.js CHANGED
@@ -15,7 +15,7 @@ const CORE_DEPENDENCY = schema.getEncoding('@core/dependency')
15
15
  const CORE_HINTS = schema.getEncoding('@core/hints')
16
16
 
17
17
  class CoreTX {
18
- constructor (core, db, view, changes) {
18
+ constructor(core, db, view, changes) {
19
19
  if (db.snapshotted) throw new Error('Cannot open core tx on snapshot')
20
20
  this.core = core
21
21
  this.db = db
@@ -23,39 +23,39 @@ class CoreTX {
23
23
  this.changes = changes
24
24
  }
25
25
 
26
- setAuth (auth) {
26
+ setAuth(auth) {
27
27
  this.changes.push([core.auth(this.core.corePointer), encode(CORE_AUTH, auth), null])
28
28
  }
29
29
 
30
- setSessions (sessions) {
30
+ setSessions(sessions) {
31
31
  this.changes.push([core.sessions(this.core.corePointer), encode(CORE_SESSIONS, sessions), null])
32
32
  }
33
33
 
34
- setHead (head) {
34
+ setHead(head) {
35
35
  this.changes.push([core.head(this.core.dataPointer), encode(CORE_HEAD, head), null])
36
36
  }
37
37
 
38
- deleteHead () {
38
+ deleteHead() {
39
39
  this.changes.push([core.head(this.core.dataPointer), null, null])
40
40
  }
41
41
 
42
- setDependency (dep) {
42
+ setDependency(dep) {
43
43
  this.changes.push([core.dependency(this.core.dataPointer), encode(CORE_DEPENDENCY, dep), null])
44
44
  }
45
45
 
46
- setHints (hints) {
46
+ setHints(hints) {
47
47
  this.changes.push([core.hints(this.core.dataPointer), encode(CORE_HINTS, hints), null])
48
48
  }
49
49
 
50
- putBlock (index, data) {
50
+ putBlock(index, data) {
51
51
  this.changes.push([core.block(this.core.dataPointer, index), data, null])
52
52
  }
53
53
 
54
- deleteBlock (index) {
54
+ deleteBlock(index) {
55
55
  this.changes.push([core.block(this.core.dataPointer, index), null, null])
56
56
  }
57
57
 
58
- deleteBlockRange (start, end) {
58
+ deleteBlockRange(start, end) {
59
59
  this.changes.push([
60
60
  core.block(this.core.dataPointer, start),
61
61
  null,
@@ -63,15 +63,15 @@ class CoreTX {
63
63
  ])
64
64
  }
65
65
 
66
- putBitfieldPage (index, data) {
66
+ putBitfieldPage(index, data) {
67
67
  this.changes.push([core.bitfield(this.core.dataPointer, index, 0), data, null])
68
68
  }
69
69
 
70
- deleteBitfieldPage (index) {
70
+ deleteBitfieldPage(index) {
71
71
  this.changes.push([core.bitfield(this.core.dataPointer, index, 0), null, null])
72
72
  }
73
73
 
74
- deleteBitfieldPageRange (start, end) {
74
+ deleteBitfieldPageRange(start, end) {
75
75
  this.changes.push([
76
76
  core.bitfield(this.core.dataPointer, start, 0),
77
77
  null,
@@ -79,15 +79,19 @@ class CoreTX {
79
79
  ])
80
80
  }
81
81
 
82
- putTreeNode (node) {
83
- this.changes.push([core.tree(this.core.dataPointer, node.index), encode(CORE_TREE_NODE, node), null])
82
+ putTreeNode(node) {
83
+ this.changes.push([
84
+ core.tree(this.core.dataPointer, node.index),
85
+ encode(CORE_TREE_NODE, node),
86
+ null
87
+ ])
84
88
  }
85
89
 
86
- deleteTreeNode (index) {
90
+ deleteTreeNode(index) {
87
91
  this.changes.push([core.tree(this.core.dataPointer, index), null, null])
88
92
  }
89
93
 
90
- deleteTreeNodeRange (start, end) {
94
+ deleteTreeNodeRange(start, end) {
91
95
  this.changes.push([
92
96
  core.tree(this.core.dataPointer, start),
93
97
  null,
@@ -95,24 +99,24 @@ class CoreTX {
95
99
  ])
96
100
  }
97
101
 
98
- putUserData (key, value) {
102
+ putUserData(key, value) {
99
103
  const buffer = typeof value === 'string' ? b4a.from(value) : value
100
104
  this.changes.push([core.userData(this.core.dataPointer, key), buffer, null])
101
105
  }
102
106
 
103
- deleteUserData (key) {
107
+ deleteUserData(key) {
104
108
  this.changes.push([core.userData(this.core.dataPointer, key), null, null])
105
109
  }
106
110
 
107
- putLocal (key, value) {
111
+ putLocal(key, value) {
108
112
  this.changes.push([core.local(this.core.dataPointer, key), value, null])
109
113
  }
110
114
 
111
- deleteLocal (key) {
115
+ deleteLocal(key) {
112
116
  this.changes.push([core.local(this.core.dataPointer, key), null, null])
113
117
  }
114
118
 
115
- deleteLocalRange (start, end) {
119
+ deleteLocalRange(start, end) {
116
120
  this.changes.push([
117
121
  core.local(this.core.dataPointer, start),
118
122
  null,
@@ -120,7 +124,7 @@ class CoreTX {
120
124
  ])
121
125
  }
122
126
 
123
- flush () {
127
+ flush() {
124
128
  const changes = this.changes
125
129
  if (changes === null) return Promise.resolve(!this.view)
126
130
 
@@ -136,7 +140,7 @@ class CoreTX {
136
140
  }
137
141
 
138
142
  class CoreRX {
139
- constructor (core, db, view) {
143
+ constructor(core, db, view) {
140
144
  this.core = core
141
145
  this.read = db.read({ autoDestroy: true })
142
146
  this.view = view
@@ -144,65 +148,86 @@ class CoreRX {
144
148
  view.readStart()
145
149
  }
146
150
 
147
- async getAuth () {
151
+ static async getAuth(db, c) {
152
+ return await decode(CORE_AUTH, await db.get(core.auth(c.corePointer)))
153
+ }
154
+
155
+ async getAuth() {
148
156
  return await decode(CORE_AUTH, await this.view.get(this.read, core.auth(this.core.corePointer)))
149
157
  }
150
158
 
151
- async getSessions () {
152
- return await decode(CORE_SESSIONS, await this.view.get(this.read, core.sessions(this.core.corePointer)))
159
+ async getSessions() {
160
+ return await decode(
161
+ CORE_SESSIONS,
162
+ await this.view.get(this.read, core.sessions(this.core.corePointer))
163
+ )
153
164
  }
154
165
 
155
- async getHead () {
166
+ static async getHead(db, c) {
167
+ return await decode(CORE_HEAD, await db.get(core.head(c.dataPointer)))
168
+ }
169
+
170
+ async getHead() {
156
171
  return await decode(CORE_HEAD, await this.view.get(this.read, core.head(this.core.dataPointer)))
157
172
  }
158
173
 
159
- async getDependency () {
160
- return await decode(CORE_DEPENDENCY, await this.view.get(this.read, core.dependency(this.core.dataPointer)))
174
+ async getDependency() {
175
+ return await decode(
176
+ CORE_DEPENDENCY,
177
+ await this.view.get(this.read, core.dependency(this.core.dataPointer))
178
+ )
179
+ }
180
+
181
+ static async getHints(db, c) {
182
+ return await decode(CORE_HINTS, await db.get(core.head(c.dataPointer)))
161
183
  }
162
184
 
163
- async getHints () {
164
- return await decode(CORE_HINTS, await this.view.get(this.read, core.hints(this.core.dataPointer)))
185
+ async getHints() {
186
+ return await decode(
187
+ CORE_HINTS,
188
+ await this.view.get(this.read, core.hints(this.core.dataPointer))
189
+ )
165
190
  }
166
191
 
167
- getBlock (index) {
192
+ getBlock(index) {
168
193
  const dep = findBlockDependency(this.core.dependencies, index)
169
194
  const data = dep === null ? this.core.dataPointer : dep.dataPointer
170
195
  return this.view.get(this.read, core.block(data, index))
171
196
  }
172
197
 
173
- getBitfieldPage (index) {
198
+ getBitfieldPage(index) {
174
199
  return this.view.get(this.read, core.bitfield(this.core.dataPointer, index, 0))
175
200
  }
176
201
 
177
- async getTreeNode (index) {
202
+ async getTreeNode(index) {
178
203
  const dep = findTreeDependency(this.core.dependencies, index)
179
204
  const data = dep === null ? this.core.dataPointer : dep.dataPointer
180
205
  return decode(CORE_TREE_NODE, await this.view.get(this.read, core.tree(data, index)))
181
206
  }
182
207
 
183
- async hasTreeNode (index) {
208
+ async hasTreeNode(index) {
184
209
  return (await this.getTreeNode(index)) !== null
185
210
  }
186
211
 
187
- getUserData (key) {
212
+ getUserData(key) {
188
213
  return this.view.get(this.read, core.userData(this.core.dataPointer, key))
189
214
  }
190
215
 
191
- getLocal (key) {
216
+ getLocal(key) {
192
217
  return this.view.get(this.read, core.local(this.core.dataPointer, key))
193
218
  }
194
219
 
195
- tryFlush () {
220
+ tryFlush() {
196
221
  this.read.tryFlush()
197
222
  this._free()
198
223
  }
199
224
 
200
- destroy () {
225
+ destroy() {
201
226
  this.read.destroy()
202
227
  this._free()
203
228
  }
204
229
 
205
- _free () {
230
+ _free() {
206
231
  if (this.view === null) return
207
232
  this.view.readStop()
208
233
  this.view = null
@@ -210,29 +235,29 @@ class CoreRX {
210
235
  }
211
236
 
212
237
  class CorestoreTX {
213
- constructor (view) {
238
+ constructor(view) {
214
239
  this.view = view
215
240
  this.changes = []
216
241
  }
217
242
 
218
- setHead (head) {
243
+ setHead(head) {
219
244
  this.changes.push([store.head(), encode(CORESTORE_HEAD, head), null])
220
245
  }
221
246
 
222
- putCore (discoveryKey, ptr) {
247
+ putCore(discoveryKey, ptr) {
223
248
  this.changes.push([store.core(discoveryKey), encode(CORESTORE_CORE, ptr), null])
224
249
  }
225
250
 
226
- putCoreByAlias (alias, discoveryKey) {
251
+ putCoreByAlias(alias, discoveryKey) {
227
252
  this.changes.push([store.coreByAlias(alias), discoveryKey, null])
228
253
  }
229
254
 
230
- clear () {
255
+ clear() {
231
256
  const [start, end] = store.clear()
232
257
  this.changes.push([start, null, end])
233
258
  }
234
259
 
235
- apply () {
260
+ apply() {
236
261
  if (this.changes === null) return
237
262
  this.view.apply(this.changes)
238
263
  this.changes = null
@@ -240,36 +265,36 @@ class CorestoreTX {
240
265
  }
241
266
 
242
267
  class CorestoreRX {
243
- constructor (db, view) {
268
+ constructor(db, view) {
244
269
  this.read = db.read({ autoDestroy: true })
245
270
  this.view = view
246
271
 
247
272
  view.readStart()
248
273
  }
249
274
 
250
- async getHead () {
275
+ async getHead() {
251
276
  return decode(CORESTORE_HEAD, await this.view.get(this.read, store.head()))
252
277
  }
253
278
 
254
- async getCore (discoveryKey) {
279
+ async getCore(discoveryKey) {
255
280
  return decode(CORESTORE_CORE, await this.view.get(this.read, store.core(discoveryKey)))
256
281
  }
257
282
 
258
- getCoreByAlias (alias) {
283
+ getCoreByAlias(alias) {
259
284
  return this.view.get(this.read, store.coreByAlias(alias))
260
285
  }
261
286
 
262
- tryFlush () {
287
+ tryFlush() {
263
288
  this.read.tryFlush()
264
289
  this._free()
265
290
  }
266
291
 
267
- destroy () {
292
+ destroy() {
268
293
  this.read.destroy()
269
294
  this._free()
270
295
  }
271
296
 
272
- _free () {
297
+ _free() {
273
298
  if (this.view === null) return
274
299
  this.view.readStop()
275
300
  this.view = null
@@ -278,7 +303,7 @@ class CorestoreRX {
278
303
 
279
304
  module.exports = { CorestoreTX, CorestoreRX, CoreTX, CoreRX }
280
305
 
281
- function findBlockDependency (dependencies, index) {
306
+ function findBlockDependency(dependencies, index) {
282
307
  for (let i = 0; i < dependencies.length; i++) {
283
308
  const dep = dependencies[i]
284
309
  if (index < dep.length) return dep
@@ -287,7 +312,7 @@ function findBlockDependency (dependencies, index) {
287
312
  return null
288
313
  }
289
314
 
290
- function findTreeDependency (dependencies, index) {
315
+ function findTreeDependency(dependencies, index) {
291
316
  for (let i = 0; i < dependencies.length; i++) {
292
317
  const dep = dependencies[i]
293
318
  if (flat.rightSpan(index) <= (dep.length - 1) * 2) return dep
@@ -296,12 +321,12 @@ function findTreeDependency (dependencies, index) {
296
321
  return null
297
322
  }
298
323
 
299
- function decode (enc, buffer) {
324
+ function decode(enc, buffer) {
300
325
  if (buffer === null) return null
301
326
  return enc.decode({ start: 0, end: buffer.byteLength, buffer })
302
327
  }
303
328
 
304
- function encode (enc, m) {
329
+ function encode(enc, m) {
305
330
  // TODO: use fancy slab for small messages
306
331
  const state = { start: 0, end: 0, buffer: null }
307
332
  enc.preencode(state, m)