pinafore/routes/_database/keys.js

59 lines
1.2 KiB
JavaScript
Raw Normal View History

import { toReversePaddedBigInt, zeroPad } from '../_utils/sorting'
//
// timelines
//
export function createTimelineId (timeline, id) {
// reverse chronological order, prefixed by timeline
return timeline + '\u0000' + toReversePaddedBigInt(id)
}
export function createTimelineKeyRange (timeline, maxId) {
let negBigInt = maxId && toReversePaddedBigInt(maxId)
let start = negBigInt ? (timeline + '\u0000' + negBigInt) : (timeline + '\u0000')
let end = timeline + '\u0000\uffff'
return IDBKeyRange.bound(start, end, true, true)
}
//
// threads
//
export function createThreadId (statusId, i) {
return statusId + '\u0000' + zeroPad(i, 5)
}
export function createThreadKeyRange (statusId) {
return IDBKeyRange.bound(
statusId + '\u0000',
statusId + '\u0000\uffff'
)
}
//
// pinned statues
//
export function createPinnedStatusId (accountId, i) {
return accountId + '\u0000' + zeroPad(i, 3)
}
export function createPinnedStatusKeyRange (accountId) {
return IDBKeyRange.bound(
accountId + '\u0000',
accountId + '\u0000\uffff'
)
}
2018-03-25 02:04:54 +01:00
//
// accounts
//
export function createAccountUsernamePrefixKeyRange (accountUsernamePrefix) {
return IDBKeyRange.bound(
accountUsernamePrefix,
accountUsernamePrefix + '\uffff'
)
}