hypercore-storage 1.1.5 → 1.2.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/lib/close-error-stream.js +14 -0
- package/lib/view.js +8 -0
- package/migrations/0/messages.js +4 -2
- package/package.json +1 -1
- package/spec/hyperschema/index.js +5 -3
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const { Readable } = require('streamx')
|
|
2
|
+
|
|
3
|
+
// used for returned a stream that just errors (during read during teardown)
|
|
4
|
+
|
|
5
|
+
module.exports = class CloseErrorStream extends Readable {
|
|
6
|
+
constructor (err) {
|
|
7
|
+
super()
|
|
8
|
+
this.error = err
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
_open (cb) {
|
|
12
|
+
cb(this.error)
|
|
13
|
+
}
|
|
14
|
+
}
|
package/lib/view.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const { Readable, getStreamError } = require('streamx')
|
|
2
|
+
const CloseErrorStream = require('./close-error-stream.js')
|
|
2
3
|
const b4a = require('b4a')
|
|
3
4
|
|
|
4
5
|
class OverlayStream extends Readable {
|
|
@@ -212,6 +213,8 @@ class View {
|
|
|
212
213
|
}
|
|
213
214
|
|
|
214
215
|
iterator (db, start, end, reverse) {
|
|
216
|
+
if (dbClosing(db)) return new CloseErrorStream(new Error('RocksDB session is closed'))
|
|
217
|
+
|
|
215
218
|
const stream = db.iterator({ gte: start, lt: end, reverse })
|
|
216
219
|
if (this.changes === null) return stream
|
|
217
220
|
|
|
@@ -344,3 +347,8 @@ function reverseArray (list) {
|
|
|
344
347
|
for (let i = 0; i < list.length; i++) r[r.length - 1 - i] = list[i]
|
|
345
348
|
return r
|
|
346
349
|
}
|
|
350
|
+
|
|
351
|
+
// TODO: expose from rocks instead
|
|
352
|
+
function dbClosing (db) {
|
|
353
|
+
return db._state.closing || db._index === -1
|
|
354
|
+
}
|
package/migrations/0/messages.js
CHANGED
|
@@ -180,7 +180,7 @@ const manifest = exports.manifest = {
|
|
|
180
180
|
c.uint.encode(state, m.version)
|
|
181
181
|
if (m.version === 0) return manifestv0.encode(state, m)
|
|
182
182
|
|
|
183
|
-
c.uint.encode(state, (m.allowPatch ? 1 : 0) | (m.prologue ? 2 : 0))
|
|
183
|
+
c.uint.encode(state, (m.allowPatch ? 1 : 0) | (m.prologue ? 2 : 0) | (m.unencrypted ? 4 : 0))
|
|
184
184
|
hashes.encode(state, m.hash)
|
|
185
185
|
|
|
186
186
|
c.uint.encode(state, m.quorum)
|
|
@@ -196,6 +196,7 @@ const manifest = exports.manifest = {
|
|
|
196
196
|
const hash = hashes.decode(state)
|
|
197
197
|
const quorum = c.uint.decode(state)
|
|
198
198
|
const signers = signerArray.decode(state)
|
|
199
|
+
const unencrypted = (flags & 4) !== 0
|
|
199
200
|
|
|
200
201
|
return {
|
|
201
202
|
version: 1,
|
|
@@ -203,7 +204,8 @@ const manifest = exports.manifest = {
|
|
|
203
204
|
allowPatch: (flags & 1) !== 0,
|
|
204
205
|
quorum,
|
|
205
206
|
signers,
|
|
206
|
-
prologue: (flags & 2) === 0 ? null : prologue.decode(state)
|
|
207
|
+
prologue: (flags & 2) === 0 ? null : prologue.decode(state),
|
|
208
|
+
unencrypted
|
|
207
209
|
}
|
|
208
210
|
}
|
|
209
211
|
}
|
package/package.json
CHANGED
|
@@ -250,7 +250,7 @@ const encoding9_4 = c.array(encoding7)
|
|
|
250
250
|
const encoding9 = {
|
|
251
251
|
preencode (state, m) {
|
|
252
252
|
c.uint.preencode(state, m.version)
|
|
253
|
-
state.end++ // max flag is
|
|
253
|
+
state.end++ // max flag is 4 so always one byte
|
|
254
254
|
encoding4.preencode(state, m.hash)
|
|
255
255
|
c.uint.preencode(state, m.quorum)
|
|
256
256
|
encoding9_4.preencode(state, m.signers)
|
|
@@ -260,7 +260,8 @@ const encoding9 = {
|
|
|
260
260
|
encode (state, m) {
|
|
261
261
|
const flags =
|
|
262
262
|
(m.allowPatch ? 1 : 0) |
|
|
263
|
-
(m.prologue ? 2 : 0)
|
|
263
|
+
(m.prologue ? 2 : 0) |
|
|
264
|
+
(m.unencrypted ? 4 : 0)
|
|
264
265
|
|
|
265
266
|
c.uint.encode(state, m.version)
|
|
266
267
|
c.uint.encode(state, flags)
|
|
@@ -280,7 +281,8 @@ const encoding9 = {
|
|
|
280
281
|
quorum: c.uint.decode(state),
|
|
281
282
|
allowPatch: (flags & 1) !== 0,
|
|
282
283
|
signers: encoding9_4.decode(state),
|
|
283
|
-
prologue: (flags & 2) !== 0 ? encoding8.decode(state) : null
|
|
284
|
+
prologue: (flags & 2) !== 0 ? encoding8.decode(state) : null,
|
|
285
|
+
unencrypted: (flags & 4) !== 0
|
|
284
286
|
}
|
|
285
287
|
}
|
|
286
288
|
}
|