corestore 6.4.2 → 6.5.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 +19 -2
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -27,6 +27,7 @@ module.exports = class Corestore extends EventEmitter {
27
27
  this.primaryKey = opts.primaryKey || null
28
28
 
29
29
  this._keyStorage = null
30
+ this._bootstrap = opts.bootstrap || null
30
31
  this._namespace = opts.namespace || DEFAULT_NAMESPACE
31
32
 
32
33
  this._root = root || this
@@ -81,10 +82,18 @@ module.exports = class Corestore extends EventEmitter {
81
82
  }
82
83
  }
83
84
 
85
+ async _openNamespaceFromBootstrap () {
86
+ const ns = await this._bootstrap.getUserData(USERDATA_NAMESPACE_KEY)
87
+ if (ns) {
88
+ this._namespace = ns
89
+ }
90
+ }
91
+
84
92
  async _open () {
85
93
  if (this._root !== this) {
86
94
  await this._root._opening
87
95
  if (!this.primaryKey) this.primaryKey = this._root.primaryKey
96
+ if (this._bootstrap) await this._openNamespaceFromBootstrap()
88
97
  return
89
98
  }
90
99
 
@@ -107,6 +116,8 @@ module.exports = class Corestore extends EventEmitter {
107
116
  })
108
117
  })
109
118
  })
119
+
120
+ if (this._bootstrap) await this._openNamespaceFromBootstrap()
110
121
  }
111
122
 
112
123
  async _generateKeys (opts) {
@@ -263,12 +274,15 @@ module.exports = class Corestore extends EventEmitter {
263
274
  this._findingPeers.push(core.findingPeers())
264
275
  }
265
276
 
266
- core.once('close', () => {
277
+ const gc = () => {
267
278
  // technically better to also clear _findingPeers if we added it,
268
279
  // but the lifecycle for those are pretty short so prob not worth the complexity
269
280
  // as _decFindingPeers clear them all.
270
281
  this._sessions.delete(core)
271
- })
282
+ }
283
+
284
+ core.ready().catch(gc)
285
+ core.once('close', gc)
272
286
 
273
287
  return core
274
288
  }
@@ -299,6 +313,9 @@ module.exports = class Corestore extends EventEmitter {
299
313
  }
300
314
 
301
315
  namespace (name) {
316
+ if (name instanceof Hypercore) {
317
+ return this.session({ bootstrap: name })
318
+ }
302
319
  return this.session({ namespace: generateNamespace(this._namespace, name) })
303
320
  }
304
321
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "corestore",
3
- "version": "6.4.2",
3
+ "version": "6.5.0",
4
4
  "description": "A Hypercore factory that simplifies managing collections of cores.",
5
5
  "main": "index.js",
6
6
  "scripts": {