hypercore 10.28.8 → 10.28.9

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.
Files changed (3) hide show
  1. package/index.js +2 -12
  2. package/lib/batch.js +3 -5
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -20,8 +20,6 @@ const { manifestHash, defaultSignerManifest, createVerifier, createManifest, isC
20
20
  const { ReadStream, WriteStream, ByteStream } = require('./lib/streams')
21
21
  const {
22
22
  BAD_ARGUMENT,
23
- BATCH_ALREADY_EXISTS,
24
- BATCH_UNFLUSHED,
25
23
  SESSION_CLOSED,
26
24
  SESSION_NOT_WRITABLE,
27
25
  SNAPSHOT_NOT_AVAILABLE
@@ -83,7 +81,6 @@ module.exports = class Hypercore extends EventEmitter {
83
81
  this._readonly = opts.writable === false
84
82
  this._preappend = preappend.bind(this)
85
83
  this._snapshot = null
86
- this._batch = opts._batch || null
87
84
  this._findingPeers = 0
88
85
  this._active = opts.active !== false
89
86
 
@@ -231,8 +228,7 @@ module.exports = class Hypercore extends EventEmitter {
231
228
  timeout,
232
229
  writable,
233
230
  _opening: this.opening,
234
- _sessions: this.sessions,
235
- _batch: this._batch
231
+ _sessions: this.sessions
236
232
  })
237
233
 
238
234
  s._passCapabilities(this)
@@ -805,10 +801,7 @@ module.exports = class Hypercore extends EventEmitter {
805
801
  }
806
802
 
807
803
  batch ({ checkout = -1, autoClose = true, session = true } = {}) {
808
- if (this._batch !== null) throw BATCH_ALREADY_EXISTS()
809
- const batch = new Batch(session ? this.session() : this, checkout, autoClose)
810
- for (const session of this.sessions) session._batch = batch
811
- return batch
804
+ return new Batch(session ? this.session() : this, checkout, autoClose)
812
805
  }
813
806
 
814
807
  async seek (bytes, opts) {
@@ -978,7 +971,6 @@ module.exports = class Hypercore extends EventEmitter {
978
971
 
979
972
  const {
980
973
  fork = this.core.tree.fork + 1,
981
- force = false,
982
974
  keyPair = this.keyPair,
983
975
  signature = null
984
976
  } = typeof opts === 'number' ? { fork: opts } : opts
@@ -986,7 +978,6 @@ module.exports = class Hypercore extends EventEmitter {
986
978
  const writable = !this._readonly && !!(signature || (keyPair && keyPair.secretKey))
987
979
 
988
980
  if (writable === false) throw SESSION_NOT_WRITABLE()
989
- if (this._batch && !force) throw BATCH_UNFLUSHED()
990
981
 
991
982
  await this.core.truncate(newLength, fork, { keyPair, signature })
992
983
 
@@ -996,7 +987,6 @@ module.exports = class Hypercore extends EventEmitter {
996
987
 
997
988
  async append (blocks, opts = {}) {
998
989
  if (this.opened === false) await this.opening
999
- if (this._batch) throw BATCH_UNFLUSHED()
1000
990
 
1001
991
  const { keyPair = this.keyPair, signature = null } = opts
1002
992
  const writable = !this._readonly && !!(signature || (keyPair && keyPair.secretKey))
package/lib/batch.js CHANGED
@@ -312,6 +312,8 @@ module.exports = class HypercoreBatch extends EventEmitter {
312
312
  }
313
313
 
314
314
  async _flush (length, keyPair, signature) { // TODO: make this safe to interact with a parallel truncate...
315
+ if (this._sessionBatch.fork !== this.session.fork) return false // no truncs supported atm
316
+
315
317
  const flushingLength = Math.min(length - this._sessionLength, this._appends.length)
316
318
  if (flushingLength <= 0) return true
317
319
 
@@ -344,7 +346,6 @@ module.exports = class HypercoreBatch extends EventEmitter {
344
346
  }
345
347
 
346
348
  async _close () {
347
- this._clearBatch()
348
349
  this._clearAppends()
349
350
 
350
351
  await this.session.close()
@@ -355,13 +356,10 @@ module.exports = class HypercoreBatch extends EventEmitter {
355
356
 
356
357
  _clearAppends () {
357
358
  this._appends = []
359
+ this._appendsActual = []
358
360
  this._byteLength = 0
359
361
  this.fork = 0
360
362
  }
361
-
362
- _clearBatch () {
363
- for (const session of this.session.sessions) session._batch = null
364
- }
365
363
  }
366
364
 
367
365
  function noop () {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore",
3
- "version": "10.28.8",
3
+ "version": "10.28.9",
4
4
  "description": "Hypercore is a secure, distributed append-only log",
5
5
  "main": "index.js",
6
6
  "scripts": {