corestore 7.6.0 → 7.7.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/index.js +46 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -235,7 +235,8 @@ class Corestore extends ReadyResource {
|
|
|
235
235
|
: Hypercore.defaultStorage(storage, {
|
|
236
236
|
id: opts.id,
|
|
237
237
|
allowBackup: opts.allowBackup,
|
|
238
|
-
readOnly: opts.readOnly
|
|
238
|
+
readOnly: opts.readOnly,
|
|
239
|
+
wait: opts.wait
|
|
239
240
|
})
|
|
240
241
|
this.streamTracker = this.root ? this.root.streamTracker : new StreamTracker()
|
|
241
242
|
this.cores = this.root ? this.root.cores : new CoreTracker()
|
|
@@ -456,6 +457,50 @@ class Corestore extends ReadyResource {
|
|
|
456
457
|
}
|
|
457
458
|
}
|
|
458
459
|
|
|
460
|
+
async staticify(core, opts) {
|
|
461
|
+
if (!this.opened) await this.ready()
|
|
462
|
+
if (!core.opened) await core.ready()
|
|
463
|
+
|
|
464
|
+
const rx = core.state.storage.read()
|
|
465
|
+
|
|
466
|
+
const headPromise = rx.getHead()
|
|
467
|
+
const authPromise = rx.getAuth()
|
|
468
|
+
|
|
469
|
+
rx.tryFlush()
|
|
470
|
+
|
|
471
|
+
const [head, auth] = await Promise.all([headPromise, authPromise])
|
|
472
|
+
if (!head || head.length === 0) throw new Error('Core must have data')
|
|
473
|
+
|
|
474
|
+
const prologue = {
|
|
475
|
+
length: head.length,
|
|
476
|
+
hash: head.rootHash
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
const manifest = {
|
|
480
|
+
version: 1,
|
|
481
|
+
hash: auth.manifest.hash,
|
|
482
|
+
quorum: 0,
|
|
483
|
+
signers: [],
|
|
484
|
+
prologue
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
const c = {
|
|
488
|
+
key: null,
|
|
489
|
+
discoveryKey: null,
|
|
490
|
+
manifest,
|
|
491
|
+
core: core.state.storage.core
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
c.key = Hypercore.key(c.manifest)
|
|
495
|
+
c.discoveryKey = Hypercore.discoveryKey(c.key)
|
|
496
|
+
|
|
497
|
+
await this.storage.createCore(c)
|
|
498
|
+
|
|
499
|
+
const staticCore = this.get({ ...opts, key: c.key })
|
|
500
|
+
await staticCore.ready()
|
|
501
|
+
return staticCore
|
|
502
|
+
}
|
|
503
|
+
|
|
459
504
|
get(opts) {
|
|
460
505
|
this._maybeClosed()
|
|
461
506
|
|