UNPKG

@tanstack/db

Version:

A reactive client store for building super fast apps on sync

49 lines (48 loc) 2.39 kB
import { BasicExpression, QueryIR } from './ir.js'; import { InitialQueryBuilder, QueryBuilder } from './builder/index.js'; import { LoadSubsetOptions } from '../types.js'; type StableIdentityValue = null | boolean | number | string | Array<StableIdentityValue> | { [key: string]: StableIdentityValue; }; declare const queryIdentityBrand: unique symbol; declare const demandKeyBrand: unique symbol; /** Semantic identity for a query plan, independent of its runtime owners. */ export type QueryIdentity = string & { readonly [queryIdentityBrand]: true; }; /** Exact identity for one loadSubset demand, including its requested window. */ export type DemandKey = string & { readonly [demandKeyBrand]: true; }; export declare class UnhashableQueryIRError extends Error { readonly path: string; readonly reason: string; constructor(path: string, reason: string); } export declare function getStableQueryIRHash(query: QueryIR): string; export declare function getStableQueryBuilderHash(query: InitialQueryBuilder | QueryBuilder<any>): string; export declare function getStableValueHash(value: unknown, path?: string): string; /** * Returns the semantic identity of a structured query. * * Logical conjunctions and disjunctions are associative, commutative, and * idempotent. Equality operands are commutative, while reversed inequalities * are normalized by inverting their operator. Order-sensitive clauses and * function arguments retain their original order. */ export declare function getQueryIdentity(query: QueryIR): QueryIdentity; /** Returns the semantic identity of one structured expression. */ export declare function getStableExpressionHash(expression: BasicExpression): string; /** * Returns the exact semantic identity of a loadSubset request. * * Abort signals and subscriptions are owners of a request, not part of the * requested data, and therefore do not affect the key. A demand generation * scopes one asynchronous attempt rather than the data it requests. Code that * rejects stale work compares this key alongside its generation; query-db uses * the key alone so equivalent data demands can reuse one cache entry across * generations. */ export declare function getLoadSubsetDemandKey(options: LoadSubsetOptions): DemandKey | undefined; export declare function canonicalizeQueryIR(query: QueryIR): StableIdentityValue; export {};