hypercore 10.28.0 → 10.28.2

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/index.js CHANGED
@@ -56,7 +56,7 @@ module.exports = class Hypercore extends EventEmitter {
56
56
  this.replicator = null
57
57
  this.encryption = null
58
58
  this.extensions = new Map()
59
- this.cache = opts.cache === true ? new Xache({ maxSize: 65536, maxAge: 0 }) : (opts.cache || null)
59
+ this.cache = createCache(opts.cache)
60
60
 
61
61
  this.valueEncoding = null
62
62
  this.encodeBatch = null
@@ -296,6 +296,7 @@ module.exports = class Hypercore extends EventEmitter {
296
296
 
297
297
  if (!isFirst) await opts._opening
298
298
  if (opts.preload) opts = { ...opts, ...(await this._retryPreload(opts.preload)) }
299
+ if (this.cache === null && opts.cache) this.cache = createCache(opts.cache)
299
300
 
300
301
  if (isFirst) {
301
302
  await this._openCapabilities(key, storage, opts)
@@ -1116,3 +1117,7 @@ function ensureEncryption (core, opts) {
1116
1117
  if (core.encryption && b4a.equals(core.encryption.key, opts.encryptionKey)) return
1117
1118
  core.encryption = new BlockEncryption(opts.encryptionKey, core.key, { compat: core.core.compat, isBlockKey: opts.isBlockKey })
1118
1119
  }
1120
+
1121
+ function createCache (cache) {
1122
+ return cache === true ? new Xache({ maxSize: 65536, maxAge: 0 }) : (cache || null)
1123
+ }
package/lib/batch.js CHANGED
@@ -88,6 +88,12 @@ module.exports = class HypercoreBatch extends EventEmitter {
88
88
  this.emit('ready')
89
89
  }
90
90
 
91
+ async has (index) {
92
+ if (this.opened === false) await this.ready()
93
+ if (index >= this._sessionLength) return index < this.length
94
+ return this._session.has(index)
95
+ }
96
+
91
97
  async update (opts) {
92
98
  if (this.opened === false) await this.ready()
93
99
  await this.session.update(opts)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore",
3
- "version": "10.28.0",
3
+ "version": "10.28.2",
4
4
  "description": "Hypercore is a secure, distributed append-only log",
5
5
  "main": "index.js",
6
6
  "scripts": {