@convex-dev/aggregate
Version:
[](https://badge.fury.io/js/@convex-dev%2Faggregate)
29 lines • 1.1 kB
JavaScript
/**
* The Aggregate API uses keys and IDs, where the keys are for sorting and
* IDs are for tie-breaking uniqueness. The component's BTree API uses
* positions, which are unique keys.
*/
// IDs are strings so in the Convex ordering, null < IDs < arrays.
const BEFORE_ALL_IDS = null;
const AFTER_ALL_IDS = [];
export function keyToPosition(key, id) {
return ["", key, id, ""];
}
export function positionToKey(position) {
return { key: position[1], id: position[2] };
}
export function boundToPosition(direction, bound) {
if (direction === 'lower') {
if (bound === undefined) {
return [BEFORE_ALL_IDS, BEFORE_ALL_IDS, BEFORE_ALL_IDS, BEFORE_ALL_IDS];
}
return ["", bound.key, bound.id ?? BEFORE_ALL_IDS, bound.inclusive ? BEFORE_ALL_IDS : AFTER_ALL_IDS];
}
else {
if (bound === undefined) {
return [AFTER_ALL_IDS, AFTER_ALL_IDS, AFTER_ALL_IDS, AFTER_ALL_IDS];
}
return ["", bound.key, bound.id ?? AFTER_ALL_IDS, bound.inclusive ? AFTER_ALL_IDS : BEFORE_ALL_IDS];
}
}
//# sourceMappingURL=positions.js.map