Skip to content

Commit 7998449

Browse files
Expose audit from store (#111)
* expose audit from store * fix test * move audit to lib and export in package * open cores as inactive
1 parent b2895b8 commit 7998449

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

index.js

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ const sodium = require('sodium-universal')
66
const crypto = require('hypercore-crypto')
77
const ID = require('hypercore-id-encoding')
88

9+
const auditStore = require('./lib/audit.js')
10+
911
const [NS] = crypto.namespace('corestore', 1)
1012
const DEFAULT_NAMESPACE = b4a.alloc(32) // This is meant to be 32 0-bytes
1113

@@ -211,6 +213,10 @@ class Corestore extends ReadyResource {
211213
}
212214
}
213215

216+
audit (opts = {}) {
217+
return auditStore(this, opts)
218+
}
219+
214220
suspend () {
215221
return this.storage.db.suspend()
216222
}

audit.js lib/audit.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module.exports = async function audit (store, { dryRun = false } = {}) {
66
for await (const { discoveryKey } of store.storage.createCoreStream()) {
77
stats.cores++
88

9-
const core = await store.get({ discoveryKey })
9+
const core = await store.get({ discoveryKey, active: false })
1010
await core.ready()
1111

1212
const audit = await auditCore(core.core, { dryRun })

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"description": "A Hypercore factory that simplifies managing collections of cores.",
55
"main": "index.js",
66
"files": [
7-
"index.js"
7+
"index.js",
8+
"lib/*"
89
],
910
"dependencies": {
1011
"b4a": "^1.6.7",

test/basic.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const Hypercore = require('hypercore')
66
const crypto = require('hypercore-crypto')
77

88
const Corestore = require('../')
9-
const audit = require('../audit.js')
109

1110
test('basic', async function (t) {
1211
const store = await create(t)
@@ -247,7 +246,7 @@ test('audit', async function (t) {
247246
await d.append(i.toString())
248247
}
249248

250-
const result = await audit(store)
249+
const result = await store.audit()
251250

252251
t.is(result.cores, 4)
253252
t.is(result.skipped, 0)

0 commit comments

Comments
 (0)