hypercore-storage 1.0.7 → 1.0.8
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 +16 -23
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -91,8 +91,18 @@ class HypercoreStorage {
|
|
|
91
91
|
|
|
92
92
|
for (let i = deps.length - 1; i >= 0; i--) {
|
|
93
93
|
if (deps[i].length >= length) continue
|
|
94
|
-
|
|
95
|
-
this.core
|
|
94
|
+
|
|
95
|
+
this.core = {
|
|
96
|
+
corePointer: this.core.corePointer,
|
|
97
|
+
dataPointer: this.core.dataPointer,
|
|
98
|
+
dependencies: deps.slice(0, i + 1)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
this.core.dependencies[i] = {
|
|
102
|
+
dataPointer: deps[i].dataPointer,
|
|
103
|
+
length
|
|
104
|
+
}
|
|
105
|
+
|
|
96
106
|
return
|
|
97
107
|
}
|
|
98
108
|
|
|
@@ -104,7 +114,7 @@ class HypercoreStorage {
|
|
|
104
114
|
}
|
|
105
115
|
|
|
106
116
|
snapshot () {
|
|
107
|
-
return new HypercoreStorage(this.store, this.db.snapshot(),
|
|
117
|
+
return new HypercoreStorage(this.store, this.db.snapshot(), this.core, this.view.snapshot(), this.atom)
|
|
108
118
|
}
|
|
109
119
|
|
|
110
120
|
atomize (atom) {
|
|
@@ -145,7 +155,6 @@ class HypercoreStorage {
|
|
|
145
155
|
if (session === null) return null
|
|
146
156
|
|
|
147
157
|
const core = {
|
|
148
|
-
version: this.core.version,
|
|
149
158
|
corePointer: this.core.corePointer,
|
|
150
159
|
dataPointer: session.dataPointer,
|
|
151
160
|
dependencies: []
|
|
@@ -190,7 +199,6 @@ class HypercoreStorage {
|
|
|
190
199
|
|
|
191
200
|
const length = head === null ? 0 : head.length
|
|
192
201
|
const core = {
|
|
193
|
-
version: this.core.version,
|
|
194
202
|
corePointer: this.core.corePointer,
|
|
195
203
|
dataPointer: session.dataPointer,
|
|
196
204
|
dependencies: this._addDependency({ dataPointer: this.core.dataPointer, length })
|
|
@@ -209,7 +217,6 @@ class HypercoreStorage {
|
|
|
209
217
|
async createAtomicSession (atom, head) {
|
|
210
218
|
const length = head === null ? 0 : head.length
|
|
211
219
|
const core = {
|
|
212
|
-
version: this.core.version,
|
|
213
220
|
corePointer: this.core.corePointer,
|
|
214
221
|
dataPointer: this.core.dataPointer,
|
|
215
222
|
dependencies: this._addDependency(null)
|
|
@@ -582,10 +589,10 @@ class CorestoreStorage {
|
|
|
582
589
|
}
|
|
583
590
|
|
|
584
591
|
async _resumeFromPointers (view, discoveryKey, create, { version, corePointer, dataPointer }) {
|
|
585
|
-
const core = {
|
|
592
|
+
const core = { corePointer, dataPointer, dependencies: [] }
|
|
586
593
|
|
|
587
594
|
while (true) {
|
|
588
|
-
const rx = new CoreRX({
|
|
595
|
+
const rx = new CoreRX({ dataPointer, corePointer: 0, dependencies: [] }, this.db, view)
|
|
589
596
|
const dependencyPromise = rx.getDependency()
|
|
590
597
|
rx.tryFlush()
|
|
591
598
|
const dependency = await dependencyPromise
|
|
@@ -596,7 +603,7 @@ class CorestoreStorage {
|
|
|
596
603
|
|
|
597
604
|
const result = new HypercoreStorage(this, this.db.session(), core, EMPTY, null)
|
|
598
605
|
|
|
599
|
-
if (
|
|
606
|
+
if (version < VERSION) await this._migrateCore(result, discoveryKey, create)
|
|
600
607
|
return result
|
|
601
608
|
}
|
|
602
609
|
|
|
@@ -704,17 +711,3 @@ function createColumnFamily (db) {
|
|
|
704
711
|
|
|
705
712
|
return db.columnFamily(col)
|
|
706
713
|
}
|
|
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
|
-
}
|