hypercore-storage 1.0.9 → 1.1.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 (2) hide show
  1. package/index.js +21 -7
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -346,11 +346,8 @@ class CorestoreStorage {
346
346
  }
347
347
 
348
348
  // runs pre the core is returned to the user
349
- async _migrateCore (core, discoveryKey, locked) {
349
+ async _migrateCore (core, discoveryKey, version, locked) {
350
350
  const view = locked ? this.view : await this._enter()
351
-
352
- const version = core.core.version
353
-
354
351
  try {
355
352
  if (version === VERSION) return
356
353
 
@@ -366,8 +363,6 @@ class CorestoreStorage {
366
363
  }
367
364
  }
368
365
 
369
- core.core.version = VERSION
370
-
371
366
  if (locked === false) return
372
367
 
373
368
  // if its locked, then move the core state into the memview
@@ -572,6 +567,25 @@ class CorestoreStorage {
572
567
  return (await promise) !== null
573
568
  }
574
569
 
570
+ async getAuth (discoveryKey) {
571
+ if (this.version === 0) await this._migrateStore()
572
+
573
+ const rx = new CorestoreRX(this.db, EMPTY)
574
+ const corePromise = rx.getCore(discoveryKey)
575
+
576
+ rx.tryFlush()
577
+
578
+ const core = await corePromise
579
+ if (core === null) return null
580
+
581
+ const coreRx = new CoreRX(core, this.db, EMPTY)
582
+ const authPromise = coreRx.getAuth()
583
+
584
+ coreRx.tryFlush()
585
+
586
+ return authPromise
587
+ }
588
+
575
589
  async resume (discoveryKey) {
576
590
  if (this.version === 0) await this._migrateStore()
577
591
 
@@ -605,7 +619,7 @@ class CorestoreStorage {
605
619
 
606
620
  const result = new HypercoreStorage(this, this.db.session(), core, EMPTY, null)
607
621
 
608
- if (version < VERSION) await this._migrateCore(result, discoveryKey, create)
622
+ if (version < VERSION) await this._migrateCore(result, discoveryKey, version, create)
609
623
  return result
610
624
  }
611
625
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore-storage",
3
- "version": "1.0.9",
3
+ "version": "1.1.0",
4
4
  "main": "index.js",
5
5
  "files": [
6
6
  "index.js",