@tanstack/db
Version:
A reactive client store for building super fast apps on sync
47 lines (46 loc) • 2.24 kB
TypeScript
import { CompareOptions } from '../query/builder/types.js';
/**
* Universal comparison function for all data types
* Handles null/undefined, strings, arrays, dates, objects, and primitives
* Always sorts null/undefined values first
*/
export declare const ascComparator: (a: any, b: any, opts: CompareOptions) => number;
/**
* Descending comparator function for ordering values
* Handles null/undefined as largest values (opposite of ascending)
*/
export declare const descComparator: (a: unknown, b: unknown, opts: CompareOptions) => number;
export declare function makeComparator(opts: CompareOptions): (a: any, b: any) => number;
/** Default comparator orders values in ascending order with nulls first and locale string comparison. */
export declare const defaultComparator: (a: any, b: any) => number;
/**
* Sentinel value representing undefined in normalized form.
* This allows distinguishing between "start from beginning" (undefined parameter)
* and "start from the key undefined" (actual undefined value in the tree).
*/
export declare const UNDEFINED_SENTINEL = "__TS_DB_BTREE_UNDEFINED_VALUE__";
/**
* Normalize a value for comparison and Map key usage
* Converts values that can't be directly compared or used as Map keys
* into comparable primitive representations
*
* Note: This does NOT convert undefined to a sentinel. Use normalizeForBTree
* for BTree index operations that need to distinguish undefined values.
*/
export declare function normalizeValue(value: any): any;
/**
* Normalize a value for BTree index usage.
* Extends normalizeValue to also convert undefined to a sentinel value.
* This is needed because the BTree does not properly support `undefined` as a key
* (it interprets undefined as "start from beginning" in nextHigherPair/nextLowerPair).
*/
export declare function normalizeForBTree(value: any): any;
/**
* Converts the `UNDEFINED_SENTINEL` back to `undefined`.
* Needed such that the sentinel is converted back to `undefined` before comparison.
*/
export declare function denormalizeUndefined(value: any): any;
/**
* Compare two values for equality, with special handling for Uint8Arrays and Buffers
*/
export declare function areValuesEqual(a: any, b: any): boolean;