hypercore-storage 2.7.0 → 2.7.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.
Files changed (2) hide show
  1. package/index.js +22 -1
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -32,9 +32,14 @@ class Atom {
32
32
  this.view = new View()
33
33
  this.flushedPromise = null
34
34
  this.flushing = false
35
+ this.preflushes = []
35
36
  this.flushes = []
36
37
  }
37
38
 
39
+ preflush(fn) {
40
+ this.preflushes.push(fn)
41
+ }
42
+
38
43
  onflush(fn) {
39
44
  this.flushes.push(fn)
40
45
  }
@@ -57,8 +62,10 @@ class Atom {
57
62
  this.flushing = true
58
63
 
59
64
  try {
65
+ const plen = this.preflushes.length
66
+ for (let i = 0; i < plen; i++) this.preflushes[i]()
67
+
60
68
  await View.flush(this.view.changes, this.db)
61
- this.view.reset()
62
69
 
63
70
  const promises = []
64
71
  const len = this.flushes.length // in case of reentry
@@ -66,6 +73,7 @@ class Atom {
66
73
 
67
74
  await Promise.all(promises)
68
75
  } finally {
76
+ this.view.reset()
69
77
  this.flushing = false
70
78
  if (this.flushedPromise !== null) this._resolve()
71
79
  }
@@ -450,6 +458,11 @@ class HypercoreStorage {
450
458
 
451
459
  return core
452
460
  }
461
+
462
+ static isParentStorage(storage, parent) {
463
+ const last = getLastDependency(storage)
464
+ return !!last && last.dataPointer === parent.core.dataPointer
465
+ }
453
466
  }
454
467
 
455
468
  class CorestoreStorage {
@@ -1103,6 +1116,10 @@ class CorestoreStorage {
1103
1116
  await this._exit()
1104
1117
  }
1105
1118
  }
1119
+
1120
+ static isParentStorage(storage, parent) {
1121
+ return HypercoreStorage.isParentStorage(storage, parent)
1122
+ }
1106
1123
  }
1107
1124
 
1108
1125
  module.exports = CorestoreStorage
@@ -1157,6 +1174,10 @@ function createColumnFamily(db, opts = {}) {
1157
1174
  return db.columnFamily(col)
1158
1175
  }
1159
1176
 
1177
+ function getLastDependency(storage) {
1178
+ return storage.dependencies.length ? storage.dependencies[storage.dependencies.length - 1] : null
1179
+ }
1180
+
1160
1181
  // TODO: remove in like 3-6 mo
1161
1182
  function tmpFixStorage(p) {
1162
1183
  // if CORESTORE file is written, new format
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore-storage",
3
- "version": "2.7.0",
3
+ "version": "2.7.1",
4
4
  "main": "index.js",
5
5
  "files": [
6
6
  "index.js",