hypercore 11.0.10 → 11.0.11
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/index.js +9 -6
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -318,7 +318,10 @@ class Hypercore extends EventEmitter {
|
|
|
318
318
|
if (e) this.core.encryption = new BlockEncryption(e.key, this.key, { compat: this.core.compat, ...e })
|
|
319
319
|
}
|
|
320
320
|
|
|
321
|
+
const parent = opts.parent || null
|
|
322
|
+
|
|
321
323
|
if (this.core.encryption) this.encryption = this.core.encryption
|
|
324
|
+
else if (parent && parent.encryption) this.encryption = this.core.encryption = parent.encryption
|
|
322
325
|
|
|
323
326
|
this.writable = this._isWritable()
|
|
324
327
|
|
|
@@ -329,9 +332,9 @@ class Hypercore extends EventEmitter {
|
|
|
329
332
|
this.encodeBatch = opts.encodeBatch
|
|
330
333
|
}
|
|
331
334
|
|
|
332
|
-
if (
|
|
333
|
-
if (
|
|
334
|
-
this._setupSession(
|
|
335
|
+
if (parent) {
|
|
336
|
+
if (parent._stateIndex === -1) await parent.ready()
|
|
337
|
+
this._setupSession(parent)
|
|
335
338
|
}
|
|
336
339
|
|
|
337
340
|
if (opts.exclusive) {
|
|
@@ -339,17 +342,17 @@ class Hypercore extends EventEmitter {
|
|
|
339
342
|
await this.core.lockExclusive()
|
|
340
343
|
}
|
|
341
344
|
|
|
342
|
-
const
|
|
345
|
+
const parentState = parent ? parent.state : this.core.state
|
|
343
346
|
const checkout = opts.checkout === undefined ? -1 : opts.checkout
|
|
344
347
|
const state = this.state
|
|
345
348
|
|
|
346
349
|
if (opts.atom) {
|
|
347
|
-
this.state = await
|
|
350
|
+
this.state = await parentState.createSession(null, false, opts.atom)
|
|
348
351
|
if (state) state.unref()
|
|
349
352
|
} else if (opts.name) {
|
|
350
353
|
// todo: need to make named sessions safe before ready
|
|
351
354
|
// atm we always copy the state in passCapabilities
|
|
352
|
-
this.state = await
|
|
355
|
+
this.state = await parentState.createSession(opts.name, !!opts.overwrite, null)
|
|
353
356
|
if (state) state.unref() // ref'ed above in setup session
|
|
354
357
|
}
|
|
355
358
|
|