hypercore-storage 1.18.0 → 2.0.1

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 CHANGED
@@ -18,11 +18,11 @@ const Storage = require('hypercore-storage')
18
18
 
19
19
  Make a new storage engine.
20
20
 
21
- #### `core = await store.create({ key, discoveyKey, manifest?, keyPair?, encryptionKey?, userData? })`
21
+ #### `core = await store.createCore({ key, discoveyKey, manifest?, keyPair?, encryptionKey?, userData? })`
22
22
 
23
23
  Create a new core, returns a storage instance for that core.
24
24
 
25
- #### `core = await store.resume(discoveryKey)`
25
+ #### `core = await store.resumeCore(discoveryKey)`
26
26
 
27
27
  Resume a previously make core. If it doesn't exist it returns `null`.
28
28
 
@@ -33,7 +33,7 @@ When you wanna flush your changes to the underlying storage, use `await atom.flu
33
33
 
34
34
  Internally to "listen" for when that happens you can add an sync hook with `atom.onflush(fn)`
35
35
 
36
- #### `bool = await store.has(discoveryKey)`
36
+ #### `bool = await store.hasCore(discoveryKey)`
37
37
 
38
38
  Check if a core exists.
39
39
 
package/index.js CHANGED
@@ -428,7 +428,6 @@ class CorestoreStorage {
428
428
  this.allowBackup = !!opts.allowBackup
429
429
  this.deviceFile = null
430
430
  this.wait = !!opts.wait
431
- this.lock = !!opts.lock || this.wait
432
431
 
433
432
  // tmp sync fix for simplicty since not super deployed yet
434
433
  if (this.bootstrap && !this.readOnly) tmpFixStorage(this.path)
@@ -544,7 +543,6 @@ class CorestoreStorage {
544
543
 
545
544
  this.deviceFile = new DeviceFile(corestoreFile, {
546
545
  wait: this.wait,
547
- lock: this.lock,
548
546
  data: { id: this.id }
549
547
  })
550
548
 
@@ -805,7 +803,7 @@ class CorestoreStorage {
805
803
  }
806
804
  }
807
805
 
808
- async has(discoveryKey, { ifMigrated = false } = {}) {
806
+ async hasCore(discoveryKey, { ifMigrated = false } = {}) {
809
807
  if (this.version === 0) await this._migrateStore()
810
808
 
811
809
  const rx = new CorestoreRX(this.db, EMPTY)
@@ -872,7 +870,17 @@ class CorestoreStorage {
872
870
  return Promise.all(resultPromises)
873
871
  }
874
872
 
875
- async resume(discoveryKey) {
873
+ async suspend() {
874
+ await this.db.suspend()
875
+ if (this.deviceFile) await this.deviceFile.suspend()
876
+ }
877
+
878
+ async resume() {
879
+ if (this.deviceFile) await this.deviceFile.resume()
880
+ await this.db.resume()
881
+ }
882
+
883
+ async resumeCore(discoveryKey) {
876
884
  if (this.version === 0) await this._migrateStore()
877
885
 
878
886
  if (!discoveryKey) {
@@ -986,7 +994,7 @@ class CorestoreStorage {
986
994
  return new HypercoreStorage(this, this.db.session(), ptr, EMPTY, null)
987
995
  }
988
996
 
989
- async create(data) {
997
+ async createCore(data) {
990
998
  if (this.version === 0) await this._migrateStore()
991
999
 
992
1000
  const view = await this._enter()
@@ -622,6 +622,7 @@ function getCached (read, cache, index) {
622
622
  async function getByteRangeFromStorage (read, index, roots, cache) {
623
623
  const promises = [getCached(read, cache, index), getByteOffsetFromStorage(read, index, roots, cache)]
624
624
  const [node, offset] = await Promise.all(promises)
625
+ if (!node) throw new Error('Node not found during migration: ' + index)
625
626
  return [offset, node.size]
626
627
  }
627
628
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore-storage",
3
- "version": "1.18.0",
3
+ "version": "2.0.1",
4
4
  "main": "index.js",
5
5
  "files": [
6
6
  "index.js",
@@ -45,7 +45,7 @@
45
45
  },
46
46
  "devDependencies": {
47
47
  "brittle": "^3.7.0",
48
- "lunte": "^1.0.2",
48
+ "lunte": "^1.2.0",
49
49
  "prettier": "^3.6.2",
50
50
  "prettier-config-holepunch": "^2.0.0",
51
51
  "test-tmp": "^1.3.1"