diff --git a/lib/index.js b/lib/index.js index e65e69c..8fb6682 100644 --- a/lib/index.js +++ b/lib/index.js @@ -400,7 +400,10 @@ function initDB(peer, config) { const data = msg.data if (data.action === 'add') { // Does this msg.pubkey have the "add" power? - const keypair = { curve: 'ed25519', public: msg.pubkey } + const keypair = { + curve: /** @type {const} */ ('ed25519'), + public: msg.pubkey, + } const powers = getAccountPowers(accountTangle, keypair) if (!powers.has('add')) { // prettier-ignore @@ -939,6 +942,13 @@ function initDB(peer, config) { } } + /** + * @param {CB<{ totalBytes: number; deletedBytes: number }>} cb + */ + function logStats(cb) { + log.stats(cb) + } + return { // public installEncryptionFormat, @@ -964,6 +974,7 @@ function initDB(peer, config) { getTangle, msgs, records, + logStats, // internal findEncryptionFormatFor, diff --git a/test/add.test.js b/test/add.test.js index 52849fc..c8720e0 100644 --- a/test/add.test.js +++ b/test/add.test.js @@ -21,7 +21,7 @@ test('add()', async (t) => { await peer.db.loaded() - const accountMsg0 = MsgV3.createAccount(keypair, 'person') + const accountMsg0 = MsgV3.createAccount(keypair, 'person', 'aliceNonce') const id = MsgV3.getMsgID(accountMsg0) await p(peer.db.add)(accountMsg0, id) @@ -48,5 +48,9 @@ test('add()', async (t) => { const rec = await p(peer.db.add)(inputMsg, rootID) assert.equal(rec.msg.data.text, 'This is the first post!') + await p(peer.db._getLog().onDrain)() + const stats = await p(peer.db.logStats)() + assert.deepEqual(stats, { totalBytes: 974, deletedBytes: 0 }) + await p(peer.close)(true) })