corestore 6.11.0 → 6.12.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.
Files changed (2) hide show
  1. package/index.js +15 -5
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -27,6 +27,7 @@ module.exports = class Corestore extends ReadyResource {
27
27
  this.cores = root ? root.cores : new Map()
28
28
  this.cache = !!opts.cache
29
29
  this.primaryKey = opts.primaryKey || null
30
+ this.passive = !!opts.passive
30
31
 
31
32
  this._keyStorage = null
32
33
  this._bootstrap = opts._bootstrap || null
@@ -363,15 +364,24 @@ module.exports = class Corestore extends ReadyResource {
363
364
  const isExternal = isStream(isInitiator) || !!(opts && opts.stream)
364
365
  const stream = Hypercore.createProtocolStream(isInitiator, {
365
366
  ...opts,
366
- ondiscoverykey: discoveryKey => {
367
+ ondiscoverykey: async discoveryKey => {
367
368
  const core = this.get({ _discoveryKey: discoveryKey })
368
- return core.ready().catch(safetyCatch)
369
+
370
+ try {
371
+ await core.ready()
372
+ } catch {
373
+ return
374
+ }
375
+
376
+ if (this.passive && !core.closing) core.replicate(stream, { session: true })
369
377
  }
370
378
  })
371
379
 
372
- for (const core of this.cores.values()) {
373
- if (!core.opened || core.closing) continue // If the core is not opened, it will be replicated in preload.
374
- core.replicate(stream, { session: true })
380
+ if (!this.passive) {
381
+ for (const core of this.cores.values()) {
382
+ if (!core.opened || core.closing) continue // If the core is not opened, it will be replicated in preload.
383
+ core.replicate(stream, { session: true })
384
+ }
375
385
  }
376
386
 
377
387
  const streamRecord = { stream, isExternal }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "corestore",
3
- "version": "6.11.0",
3
+ "version": "6.12.0",
4
4
  "description": "A Hypercore factory that simplifies managing collections of cores.",
5
5
  "main": "index.js",
6
6
  "scripts": {