corestore 6.1.1 → 6.2.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 +13 -0
  2. package/index.js +8 -3
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -66,6 +66,19 @@ const core1 = ns1.get({ name: 'main' }) // These will load different Hypercores
66
66
  const core2 = ns2.get({ name: 'main' })
67
67
  ```
68
68
 
69
+ #### `const storeB = storeA.session(opts)`
70
+ Create a new Corestore that shares resources with the original, like cache, cores, replication streams, and storage, while optionally resetting the namespace, overriding `primaryKey`.
71
+ Useful when an application wants to accept an optional Corestore, but needs to maintain a predictable key derivation.
72
+
73
+ `opts` are the same as the constructor options:
74
+
75
+ ```js
76
+ {
77
+ primaryKey, // Overrides the primaryKey for this session
78
+ namespace, // If set to null it will reset to the DEFAULT_NAMESPACE
79
+ }
80
+ ```
81
+
69
82
  ### License
70
83
  MIT
71
84
 
package/index.js CHANGED
@@ -79,7 +79,7 @@ module.exports = class Corestore extends EventEmitter {
79
79
  async _open () {
80
80
  if (this._root !== this) {
81
81
  await this._root._opening
82
- this.primaryKey = this._root.primaryKey
82
+ if (!this.primaryKey) this.primaryKey = this._root.primaryKey
83
83
  return
84
84
  }
85
85
 
@@ -288,10 +288,15 @@ module.exports = class Corestore extends EventEmitter {
288
288
  }
289
289
 
290
290
  namespace (name) {
291
+ return this.session({ namespace: generateNamespace(this._namespace, name) })
292
+ }
293
+
294
+ session (opts) {
291
295
  return new Corestore(this.storage, {
292
- namespace: generateNamespace(this._namespace, name),
296
+ namespace: this._namespace,
293
297
  cache: this.cache,
294
- _root: this._root
298
+ _root: this._root,
299
+ ...opts
295
300
  })
296
301
  }
297
302
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "corestore",
3
- "version": "6.1.1",
3
+ "version": "6.2.0",
4
4
  "description": "A Hypercore factory that simplifies managing collections of cores.",
5
5
  "main": "index.js",
6
6
  "scripts": {