UNPKG

@tanstack/db

Version:

A reactive client store for building super fast apps on sync

47 lines (46 loc) 1.44 kB
import { compileSingleRowExpression } from "../query/compiler/evaluators.js"; import { comparisonFunctions } from "../query/builder/functions.js"; const IndexOperation = comparisonFunctions; class BaseIndex { constructor(id, expression, name, options) { this.lookupCount = 0; this.totalLookupTime = 0; this.lastUpdated = /* @__PURE__ */ new Date(); this.id = id; this.expression = expression; this.name = name; this.initialize(options); } // Common methods supports(operation) { return this.supportedOperations.has(operation); } matchesField(fieldPath) { return this.expression.type === `ref` && this.expression.path.length === fieldPath.length && this.expression.path.every((part, i) => part === fieldPath[i]); } getStats() { return { entryCount: this.keyCount, lookupCount: this.lookupCount, averageLookupTime: this.lookupCount > 0 ? this.totalLookupTime / this.lookupCount : 0, lastUpdated: this.lastUpdated }; } evaluateIndexExpression(item) { const evaluator = compileSingleRowExpression(this.expression); return evaluator(item); } trackLookup(startTime) { const duration = performance.now() - startTime; this.lookupCount++; this.totalLookupTime += duration; } updateTimestamp() { this.lastUpdated = /* @__PURE__ */ new Date(); } } export { BaseIndex, IndexOperation }; //# sourceMappingURL=base-index.js.map