1
0
mirror of https://github.com/nolanlawson/pinafore synced 2024-12-13 02:37:20 +01:00
Pinafore-Web-Client-Frontend/routes/_database/keys.js
2018-03-24 18:04:54 -07:00

59 lines
1.2 KiB
JavaScript

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'
)
}
//
// accounts
//
export function createAccountUsernamePrefixKeyRange (accountUsernamePrefix) {
return IDBKeyRange.bound(
accountUsernamePrefix,
accountUsernamePrefix + '\uffff'
)
}