corestore 7.0.16 → 7.0.17
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 +12 -6
- package/package.json +2 -1
package/index.js
CHANGED
|
@@ -4,6 +4,7 @@ const ReadyResource = require('ready-resource')
|
|
|
4
4
|
const sodium = require('sodium-universal')
|
|
5
5
|
const crypto = require('hypercore-crypto')
|
|
6
6
|
const ID = require('hypercore-id-encoding')
|
|
7
|
+
const { STORAGE_EMPTY } = require('hypercore-errors')
|
|
7
8
|
|
|
8
9
|
const auditStore = require('./lib/audit.js')
|
|
9
10
|
|
|
@@ -161,12 +162,6 @@ class CoreTracker {
|
|
|
161
162
|
}
|
|
162
163
|
|
|
163
164
|
gc (core) {
|
|
164
|
-
// if not opened, gc immediately
|
|
165
|
-
if (!core.opened) {
|
|
166
|
-
this._gc(core)
|
|
167
|
-
return
|
|
168
|
-
}
|
|
169
|
-
|
|
170
165
|
core.gc = 1 // first strike
|
|
171
166
|
this._gcing.add(core)
|
|
172
167
|
if (this._gcing.size === 1) this._startGC()
|
|
@@ -448,6 +443,11 @@ class Corestore extends ReadyResource {
|
|
|
448
443
|
return this._makeSession(conf)
|
|
449
444
|
}
|
|
450
445
|
|
|
446
|
+
if (opts.discoveryKey && !opts.key && !opts.manifest) {
|
|
447
|
+
conf.preload = this._preloadCheckIfExists(opts)
|
|
448
|
+
return this._makeSession(conf)
|
|
449
|
+
}
|
|
450
|
+
|
|
451
451
|
// if not not we can sync create it, which just is easier for the
|
|
452
452
|
// upstream user in terms of guarantees (key is there etc etc)
|
|
453
453
|
const core = this._openCore(null, opts)
|
|
@@ -470,6 +470,12 @@ class Corestore extends ReadyResource {
|
|
|
470
470
|
return createKeyPair(this.primaryKey, ns, name)
|
|
471
471
|
}
|
|
472
472
|
|
|
473
|
+
async _preloadCheckIfExists (opts) {
|
|
474
|
+
const has = await this.storage.has(opts.discoveryKey)
|
|
475
|
+
if (!has) throw STORAGE_EMPTY('No Hypercore is stored here')
|
|
476
|
+
return this._preload(opts)
|
|
477
|
+
}
|
|
478
|
+
|
|
473
479
|
async _preload (opts) {
|
|
474
480
|
if (opts.preload) opts = { ...opts, ...(await opts.preload) }
|
|
475
481
|
if (this.opened === false) await this.ready()
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "corestore",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.17",
|
|
4
4
|
"description": "A Hypercore factory that simplifies managing collections of cores.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"files": [
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"b4a": "^1.6.7",
|
|
12
12
|
"hypercore": "^11.0.0",
|
|
13
13
|
"hypercore-crypto": "^3.4.2",
|
|
14
|
+
"hypercore-errors": "^1.4.0",
|
|
14
15
|
"hypercore-id-encoding": "^1.3.0",
|
|
15
16
|
"ready-resource": "^1.1.1",
|
|
16
17
|
"sodium-universal": "^4.0.1"
|