hypercore-storage 1.11.0 → 1.12.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.
package/index.js CHANGED
@@ -384,6 +384,25 @@ class CorestoreStorage {
384
384
  return this.db.ready()
385
385
  }
386
386
 
387
+ async audit () {
388
+ for await (const { core } of this.createCoreStream()) {
389
+ const coreRx = new CoreRX(core, this.db, EMPTY)
390
+ const authPromise = coreRx.getAuth()
391
+
392
+ coreRx.tryFlush()
393
+
394
+ const auth = await authPromise
395
+
396
+ if (!auth.manifest || auth.manifest.version > 0) continue
397
+ if (auth.manifest.linked === null) continue
398
+
399
+ auth.manifest.linked = null
400
+ const coreTx = new CoreTX(core, this.db, null, [])
401
+ coreTx.setAuth(auth)
402
+ await coreTx.flush()
403
+ }
404
+ }
405
+
387
406
  async deleteCore (ptr) {
388
407
  const rx = new CoreRX(ptr, this.db, EMPTY)
389
408
 
package/lib/tx.js CHANGED
@@ -35,6 +35,10 @@ class CoreTX {
35
35
  this.changes.push([core.head(this.core.dataPointer), encode(CORE_HEAD, head), null])
36
36
  }
37
37
 
38
+ deleteHead () {
39
+ this.changes.push([core.head(this.core.dataPointer), null, null])
40
+ }
41
+
38
42
  setDependency (dep) {
39
43
  this.changes.push([core.dependency(this.core.dataPointer), encode(CORE_DEPENDENCY, dep), null])
40
44
  }
@@ -373,7 +373,27 @@ async function core (core, { version, dryRun = true, gc = true }) {
373
373
  }
374
374
 
375
375
  const oplog = await readOplog(files.oplog)
376
- if (!oplog) throw new Error('No oplog available for ' + files.oplog + ', length = ' + (head ? head.length : 0) + ', writable = ' + (!!auth.keyPair))
376
+ if (!oplog) {
377
+ const writable = !!auth.keyPair
378
+
379
+ if (writable) {
380
+ throw new Error('No oplog available writable core for ' + files.oplog + ', length = ' + (head ? head.length : 0))
381
+ }
382
+
383
+ // if not writable, just nuke it to recover, some bad state happened here, prop corruption from earlier versions
384
+ const w = core.write()
385
+
386
+ w.deleteBlockRange(0, -1)
387
+ w.deleteTreeNodeRange(0, -1)
388
+ w.deleteBitfieldPageRange(0, -1)
389
+ w.deleteHead()
390
+
391
+ await w.flush()
392
+
393
+ await commitCoreMigration(auth, core, version)
394
+ if (gc) await runGC()
395
+ return // no data
396
+ }
377
397
 
378
398
  const treeData = new TreeSlicer()
379
399
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore-storage",
3
- "version": "1.11.0",
3
+ "version": "1.12.1",
4
4
  "main": "index.js",
5
5
  "files": [
6
6
  "index.js",