autobee 2.0.0-rc.16 → 2.0.0-rc.17

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/topo.js CHANGED
@@ -308,7 +308,9 @@ function getLocalBatch(undo, writer, length, weight, index) {
308
308
 
309
309
  if (length > writer.core.length) {
310
310
  if (!writer.pending) {
311
- throw new Error(`No local nodes: looking for ${length}, found ${writer.core.length}@${writer.core.id}`)
311
+ throw new Error(
312
+ `No local nodes: looking for ${length}, found ${writer.core.length}@${writer.core.id}`
313
+ )
312
314
  }
313
315
 
314
316
  let i = 0
@@ -318,9 +320,10 @@ function getLocalBatch(undo, writer, length, weight, index) {
318
320
  }
319
321
 
320
322
  const head = writer.pending[i]
323
+ const headBatch = head.batch || { start: 0, end: 0 }
321
324
 
322
- const start = i - head.batch.start
323
- const end = i + head.batch.end + 1 // include head
325
+ const start = i - headBatch.start
326
+ const end = i + headBatch.end + 1 // include head
324
327
 
325
328
  const batch = writer.pending.slice(start, end)
326
329
  return { undo, batch, index }
package/lib/writers.js CHANGED
@@ -652,8 +652,8 @@ class Writer {
652
652
  this.processed = 0
653
653
  }
654
654
 
655
- flush(views, queued, trusted) {
656
- if (this.pending === null || this.processed === 0) return Promise.resolve()
655
+ async flush(views, queued, trusted) {
656
+ if (this.pending === null || this.processed === 0) return
657
657
 
658
658
  const head = this.pending[this.processed - 1]
659
659
  head.views = views
@@ -681,8 +681,12 @@ class Writer {
681
681
  for (let i = 0; i < this.processed; i++) {
682
682
  buffers.push(encoding.encodeOplog(this.pending[i]))
683
683
  }
684
- this.clear()
685
- return this.core.append(buffers)
684
+
685
+ try {
686
+ await this.core.append(buffers)
687
+ } finally {
688
+ this.clear()
689
+ }
686
690
  }
687
691
  }
688
692
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autobee",
3
- "version": "2.0.0-rc.16",
3
+ "version": "2.0.0-rc.17",
4
4
  "description": "Bee based autobase",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Holepunch Inc.",