Skip to content

Commit

Permalink
Upgrade amalgamate to 0.1.6.
Browse files Browse the repository at this point in the history
Closes #239.
  • Loading branch information
flatheadmill committed Sep 9, 2020
1 parent a027e66 commit 77587b7
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 29 deletions.
13 changes: 13 additions & 0 deletions locket.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,19 @@ Locket.prototype._open = callbackify(async function (options) {
return header
}
},
parts: {
serialize: function (parts) { return parts },
deserialize: function (parts) { return parts }
},
key: {
compare: Buffer.compare,
serialize: function (key) {
return [ key ]
},
deserialize: function (parts) {
return parts[0]
}
},
transformer: function (operation) {
return {
method: operation.type == 'put' ? 'insert' : 'remove',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"dependencies":
{
"abstract-leveldown": "6.3.0",
"amalgamate": "0.1.4",
"amalgamate": "0.1.6",
"b-tree": "2.0.0-alpha.31",
"constrain": "2.0.0-alpha.0",
"destructible": "7.0.0-alpha.8",
Expand Down
58 changes: 30 additions & 28 deletions test/locket.t.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,38 +69,40 @@ require('proof')(6, async okay => {

await callback(callback => locket.close(callback))

await callback(callback => locket.open({ createIfMissing: true }, callback))

{
const [ value ] = await callback(callback => locket.get('a', callback))
okay({
isBuffer: Buffer.isBuffer(value),
value: value.toString()
}, {
isBuffer: true,
value: 'z'
}, 'reopen')
}
await Destructible.rescue(async function () {
await callback(callback => locket.open({ createIfMissing: true }, callback))

{
const [ value ] = await callback(callback => locket.get('a', callback))
okay({
isBuffer: Buffer.isBuffer(value),
value: value.toString()
}, {
isBuffer: true,
value: 'z'
}, 'reopen')
}

{
const iterator = locket._iterator({
keys: true, values: true, keyAsBuffer: false, valueAsBuffer: false
})
const [ key, value ] = await callback(callback => iterator.next(callback))
okay({ key, value }, { key: 'a', value: 'z' }, 'next')
const ended = await callback(callback => iterator.next(callback))
okay(ended, [], 'ended')
await callback(callback => iterator.end(callback))
}
{
const iterator = locket._iterator({
keys: true, values: true, keyAsBuffer: false, valueAsBuffer: false
})
const [ key, value ] = await callback(callback => iterator.next(callback))
okay({ key, value }, { key: 'a', value: 'z' }, 'next')
const ended = await callback(callback => iterator.next(callback))
okay(ended, [], 'ended')
await callback(callback => iterator.end(callback))
}

const alphabet = 'abcdefghijklmnopqrstuvwxyz'.split('')
const alphabet = 'abcdefghijklmnopqrstuvwxyz'.split('')

const put = alphabet.map(letter => { return { type: 'put', key: letter, value: letter } })
const del = alphabet.map(letter => { return { type: 'del', key: letter } })
const put = alphabet.map(letter => { return { type: 'put', key: letter, value: letter } })
const del = alphabet.map(letter => { return { type: 'del', key: letter } })

for (let i = 0; i < 128; i++) {
await callback(callback => locket.batch(put.concat(del), callback))
}
for (let i = 0; i < 128; i++) {
await callback(callback => locket.batch(put.concat(del), callback))
}
})

await callback(callback => locket.close(callback))

Expand Down

0 comments on commit 77587b7

Please sign in to comment.