corestore 6.1.0 → 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.
- package/README.md +13 -0
- package/index.js +10 -4
- 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:
|
|
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
|
|
|
@@ -381,6 +386,7 @@ function isStream (s) {
|
|
|
381
386
|
return typeof s === 'object' && s && typeof s.pipe === 'function'
|
|
382
387
|
}
|
|
383
388
|
|
|
384
|
-
function forceClose (core) {
|
|
389
|
+
async function forceClose (core) {
|
|
390
|
+
await core.ready()
|
|
385
391
|
return Promise.all(core.sessions.map(s => s.close()))
|
|
386
392
|
}
|