hypercore-storage 1.0.7 → 1.0.9
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 +19 -24
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -90,9 +90,21 @@ class HypercoreStorage {
|
|
|
90
90
|
const deps = this.core.dependencies
|
|
91
91
|
|
|
92
92
|
for (let i = deps.length - 1; i >= 0; i--) {
|
|
93
|
-
if (deps[i].length
|
|
94
|
-
|
|
95
|
-
this.core
|
|
93
|
+
if (deps[i].length > length) continue
|
|
94
|
+
|
|
95
|
+
this.core = {
|
|
96
|
+
corePointer: this.core.corePointer,
|
|
97
|
+
dataPointer: this.core.dataPointer,
|
|
98
|
+
dependencies: deps.slice(0, i + 1)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (this.core.dependencies[i].length !== length) {
|
|
102
|
+
this.core.dependencies[i] = {
|
|
103
|
+
dataPointer: deps[i].dataPointer,
|
|
104
|
+
length
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
96
108
|
return
|
|
97
109
|
}
|
|
98
110
|
|
|
@@ -104,7 +116,7 @@ class HypercoreStorage {
|
|
|
104
116
|
}
|
|
105
117
|
|
|
106
118
|
snapshot () {
|
|
107
|
-
return new HypercoreStorage(this.store, this.db.snapshot(),
|
|
119
|
+
return new HypercoreStorage(this.store, this.db.snapshot(), this.core, this.view.snapshot(), this.atom)
|
|
108
120
|
}
|
|
109
121
|
|
|
110
122
|
atomize (atom) {
|
|
@@ -145,7 +157,6 @@ class HypercoreStorage {
|
|
|
145
157
|
if (session === null) return null
|
|
146
158
|
|
|
147
159
|
const core = {
|
|
148
|
-
version: this.core.version,
|
|
149
160
|
corePointer: this.core.corePointer,
|
|
150
161
|
dataPointer: session.dataPointer,
|
|
151
162
|
dependencies: []
|
|
@@ -190,7 +201,6 @@ class HypercoreStorage {
|
|
|
190
201
|
|
|
191
202
|
const length = head === null ? 0 : head.length
|
|
192
203
|
const core = {
|
|
193
|
-
version: this.core.version,
|
|
194
204
|
corePointer: this.core.corePointer,
|
|
195
205
|
dataPointer: session.dataPointer,
|
|
196
206
|
dependencies: this._addDependency({ dataPointer: this.core.dataPointer, length })
|
|
@@ -209,7 +219,6 @@ class HypercoreStorage {
|
|
|
209
219
|
async createAtomicSession (atom, head) {
|
|
210
220
|
const length = head === null ? 0 : head.length
|
|
211
221
|
const core = {
|
|
212
|
-
version: this.core.version,
|
|
213
222
|
corePointer: this.core.corePointer,
|
|
214
223
|
dataPointer: this.core.dataPointer,
|
|
215
224
|
dependencies: this._addDependency(null)
|
|
@@ -582,10 +591,10 @@ class CorestoreStorage {
|
|
|
582
591
|
}
|
|
583
592
|
|
|
584
593
|
async _resumeFromPointers (view, discoveryKey, create, { version, corePointer, dataPointer }) {
|
|
585
|
-
const core = {
|
|
594
|
+
const core = { corePointer, dataPointer, dependencies: [] }
|
|
586
595
|
|
|
587
596
|
while (true) {
|
|
588
|
-
const rx = new CoreRX({
|
|
597
|
+
const rx = new CoreRX({ dataPointer, corePointer: 0, dependencies: [] }, this.db, view)
|
|
589
598
|
const dependencyPromise = rx.getDependency()
|
|
590
599
|
rx.tryFlush()
|
|
591
600
|
const dependency = await dependencyPromise
|
|
@@ -596,7 +605,7 @@ class CorestoreStorage {
|
|
|
596
605
|
|
|
597
606
|
const result = new HypercoreStorage(this, this.db.session(), core, EMPTY, null)
|
|
598
607
|
|
|
599
|
-
if (
|
|
608
|
+
if (version < VERSION) await this._migrateCore(result, discoveryKey, create)
|
|
600
609
|
return result
|
|
601
610
|
}
|
|
602
611
|
|
|
@@ -704,17 +713,3 @@ function createColumnFamily (db) {
|
|
|
704
713
|
|
|
705
714
|
return db.columnFamily(col)
|
|
706
715
|
}
|
|
707
|
-
|
|
708
|
-
function cloneCore (c) {
|
|
709
|
-
const copy = {
|
|
710
|
-
dataPointer: c.dataPointer,
|
|
711
|
-
corePointer: c.corePointer,
|
|
712
|
-
dependencies: []
|
|
713
|
-
}
|
|
714
|
-
|
|
715
|
-
for (const { dataPointer, length } of c.dependencies) {
|
|
716
|
-
copy.dependencies.push({ dataPointer, length })
|
|
717
|
-
}
|
|
718
|
-
|
|
719
|
-
return copy
|
|
720
|
-
}
|