hypercore-storage 1.18.0 → 2.0.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/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
@@ -805,7 +805,7 @@ class CorestoreStorage {
805
805
  }
806
806
  }
807
807
 
808
- async has(discoveryKey, { ifMigrated = false } = {}) {
808
+ async hasCore(discoveryKey, { ifMigrated = false } = {}) {
809
809
  if (this.version === 0) await this._migrateStore()
810
810
 
811
811
  const rx = new CorestoreRX(this.db, EMPTY)
@@ -872,7 +872,17 @@ class CorestoreStorage {
872
872
  return Promise.all(resultPromises)
873
873
  }
874
874
 
875
- async resume(discoveryKey) {
875
+ async suspend() {
876
+ await this.db.suspend()
877
+ if (this.deviceFile) await this.deviceFile.suspend()
878
+ }
879
+
880
+ async resume() {
881
+ if (this.deviceFile) await this.deviceFile.resume()
882
+ await this.db.resume()
883
+ }
884
+
885
+ async resumeCore(discoveryKey) {
876
886
  if (this.version === 0) await this._migrateStore()
877
887
 
878
888
  if (!discoveryKey) {
@@ -986,7 +996,7 @@ class CorestoreStorage {
986
996
  return new HypercoreStorage(this, this.db.session(), ptr, EMPTY, null)
987
997
  }
988
998
 
989
- async create(data) {
999
+ async createCore(data) {
990
1000
  if (this.version === 0) await this._migrateStore()
991
1001
 
992
1002
  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.0",
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"