hypercore-storage 1.0.6 → 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 +18 -12
- 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
|
|
|
@@ -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,16 +217,14 @@ 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
|
-
dependencies: this._addDependency(
|
|
222
|
+
dependencies: this._addDependency(null)
|
|
216
223
|
}
|
|
217
224
|
|
|
218
225
|
const coreTx = new CoreTX(core, this.db, atom.view, [])
|
|
219
226
|
|
|
220
227
|
if (length > 0) coreTx.setHead(head)
|
|
221
|
-
coreTx.setDependency(core.dependencies[core.dependencies.length - 1])
|
|
222
228
|
|
|
223
229
|
await coreTx.flush()
|
|
224
230
|
|
|
@@ -231,7 +237,7 @@ class HypercoreStorage {
|
|
|
231
237
|
for (let i = 0; i < this.core.dependencies.length; i++) {
|
|
232
238
|
const d = this.core.dependencies[i]
|
|
233
239
|
|
|
234
|
-
if (d.length > dep.length) {
|
|
240
|
+
if (dep !== null && d.length > dep.length) {
|
|
235
241
|
deps.push({ dataPointer: d.dataPointer, length: dep.length })
|
|
236
242
|
return deps
|
|
237
243
|
}
|
|
@@ -239,7 +245,7 @@ class HypercoreStorage {
|
|
|
239
245
|
deps.push(d)
|
|
240
246
|
}
|
|
241
247
|
|
|
242
|
-
deps.push(dep)
|
|
248
|
+
if (dep !== null) deps.push(dep)
|
|
243
249
|
return deps
|
|
244
250
|
}
|
|
245
251
|
|
|
@@ -583,10 +589,10 @@ class CorestoreStorage {
|
|
|
583
589
|
}
|
|
584
590
|
|
|
585
591
|
async _resumeFromPointers (view, discoveryKey, create, { version, corePointer, dataPointer }) {
|
|
586
|
-
const core = {
|
|
592
|
+
const core = { corePointer, dataPointer, dependencies: [] }
|
|
587
593
|
|
|
588
594
|
while (true) {
|
|
589
|
-
const rx = new CoreRX({
|
|
595
|
+
const rx = new CoreRX({ dataPointer, corePointer: 0, dependencies: [] }, this.db, view)
|
|
590
596
|
const dependencyPromise = rx.getDependency()
|
|
591
597
|
rx.tryFlush()
|
|
592
598
|
const dependency = await dependencyPromise
|
|
@@ -597,7 +603,7 @@ class CorestoreStorage {
|
|
|
597
603
|
|
|
598
604
|
const result = new HypercoreStorage(this, this.db.session(), core, EMPTY, null)
|
|
599
605
|
|
|
600
|
-
if (
|
|
606
|
+
if (version < VERSION) await this._migrateCore(result, discoveryKey, create)
|
|
601
607
|
return result
|
|
602
608
|
}
|
|
603
609
|
|