corestore 6.10.1 → 6.11.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 (3) hide show
  1. package/README.md +1 -0
  2. package/index.js +6 -0
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -81,6 +81,7 @@ Useful when an application wants to accept an optional Corestore, but needs to m
81
81
  {
82
82
  primaryKey, // Overrides the primaryKey for this session
83
83
  namespace, // If set to null it will reset to the DEFAULT_NAMESPACE
84
+ detach: true // By disabling this, closing the session will also close the store that created the session
84
85
  }
85
86
  ```
86
87
 
package/index.js CHANGED
@@ -36,6 +36,7 @@ module.exports = class Corestore extends ReadyResource {
36
36
  this._replicationStreams = root ? root._replicationStreams : []
37
37
  this._overwrite = opts.overwrite === true
38
38
  this._readonly = opts.writable === false
39
+ this._attached = opts._attached || null
39
40
 
40
41
  this._sessions = new Set() // sessions for THIS namespace
41
42
  this._rootStoreSessions = new Set()
@@ -395,6 +396,7 @@ module.exports = class Corestore extends ReadyResource {
395
396
  namespace: this._namespace,
396
397
  cache: this.cache,
397
398
  writable: !this._readonly,
399
+ _attached: opts && opts.detach === false ? this : null,
398
400
  _root: this._root,
399
401
  ...opts
400
402
  })
@@ -431,9 +433,13 @@ module.exports = class Corestore extends ReadyResource {
431
433
 
432
434
  async _close () {
433
435
  this._root._rootStoreSessions.delete(this)
436
+
434
437
  await this._closeNamespace()
438
+
435
439
  if (this._root === this) {
436
440
  await this._closePrimaryNamespace()
441
+ } else if (this._attached) {
442
+ await this._attached.close()
437
443
  }
438
444
  }
439
445
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "corestore",
3
- "version": "6.10.1",
3
+ "version": "6.11.0",
4
4
  "description": "A Hypercore factory that simplifies managing collections of cores.",
5
5
  "main": "index.js",
6
6
  "scripts": {