mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-06-26 07:52:30 +00:00
refactor: Return hash and value.
This commit is contained in:
parent
f252e3b332
commit
8db138ac9d
@ -16,10 +16,10 @@ const Events = async ({ OpLog, Database, ipfs, identity, databaseId, accessContr
|
|||||||
return entry.payload.value
|
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 })
|
const it = log.iterator({ gt, gte, lt, lte, amount })
|
||||||
for await (const event of it) {
|
for await (const event of it) {
|
||||||
yield options.fullOp ? event : event.payload.value
|
yield { hash: event.hash, value: event.payload.value }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ Object.keys(testAPIs).forEach((IPFS) => {
|
|||||||
|
|
||||||
const all = await db.all()
|
const all = await db.all()
|
||||||
|
|
||||||
deepStrictEqual(all, events)
|
deepStrictEqual(all.map(e => e.value), events)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns all events with full operation', async () => {
|
it('returns all events with full operation', async () => {
|
||||||
@ -125,7 +125,7 @@ Object.keys(testAPIs).forEach((IPFS) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const hashes = []
|
const hashes = []
|
||||||
for await (const entry of db.iterator({}, { fullOp: true })) {
|
for await (const entry of db.iterator()) {
|
||||||
hashes.unshift(entry.hash)
|
hashes.unshift(entry.hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,7 +148,7 @@ Object.keys(testAPIs).forEach((IPFS) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
strictEqual(all.length, 4)
|
strictEqual(all.length, 4)
|
||||||
deepStrictEqual(all, ['hello0', 'hello1', 'hello2', 'hello3'])
|
deepStrictEqual(all.map(e => e.value), ['hello0', 'hello1', 'hello2', 'hello3'])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user