refactor: Return hash and value.

This commit is contained in:
Hayden Young 2023-02-21 17:22:27 +00:00
parent f252e3b332
commit 8db138ac9d
2 changed files with 5 additions and 5 deletions

View File

@ -16,10 +16,10 @@ const Events = async ({ OpLog, Database, ipfs, identity, databaseId, accessContr
return entry.payload.value
}
const iterator = async function * ({ gt, gte, lt, lte, amount } = {}, options = { fullOp: false }) {
const iterator = async function * ({ gt, gte, lt, lte, amount } = {}) {
const it = log.iterator({ gt, gte, lt, lte, amount })
for await (const event of it) {
yield options.fullOp ? event : event.payload.value
yield { hash: event.hash, value: event.payload.value }
}
}

View File

@ -105,7 +105,7 @@ Object.keys(testAPIs).forEach((IPFS) => {
const all = await db.all()
deepStrictEqual(all, events)
deepStrictEqual(all.map(e => e.value), events)
})
it('returns all events with full operation', async () => {
@ -125,7 +125,7 @@ Object.keys(testAPIs).forEach((IPFS) => {
}
const hashes = []
for await (const entry of db.iterator({}, { fullOp: true })) {
for await (const entry of db.iterator()) {
hashes.unshift(entry.hash)
}
@ -148,7 +148,7 @@ Object.keys(testAPIs).forEach((IPFS) => {
}
strictEqual(all.length, 4)
deepStrictEqual(all, ['hello0', 'hello1', 'hello2', 'hello3'])
deepStrictEqual(all.map(e => e.value), ['hello0', 'hello1', 'hello2', 'hello3'])
})
})
})