MCPcopy Index your code
hub / github.com/TanStack/db / findIndexForField

Function findIndexForField

packages/db/src/utils/index-optimization.ts:45–70  ·  view source on GitHub ↗
(
  collection: CollectionLike<any, TKey>,
  fieldPath: Array<string>,
  compareOptions?: CompareOptions,
)

Source from the content-addressed store, hash-verified

43 * Finds an index that matches a given field path
44 */
45export function findIndexForField<TKey extends string | number>(
46 collection: CollectionLike<any, TKey>,
47 fieldPath: Array<string>,
48 compareOptions?: CompareOptions,
49): IndexInterface<TKey> | undefined {
50 if (hasVirtualPropPath(fieldPath)) {
51 return undefined
52 }
53 const compareOpts = compareOptions ?? {
54 ...DEFAULT_COMPARE_OPTIONS,
55 ...collection.compareOptions,
56 }
57
58 for (const index of collection.indexes.values()) {
59 if (
60 index.matchesField(fieldPath) &&
61 index.matchesCompareOptions(compareOpts)
62 ) {
63 if (!index.matchesDirection(compareOpts.direction)) {
64 return new ReverseIndex(index)
65 }
66 return index
67 }
68 }
69 return undefined
70}
71
72/**
73 * Intersects multiple sets (AND logic)

Callers 7

getOrderedKeysFunction · 0.85
optimizeSimpleComparisonFunction · 0.85
processOrderByFunction · 0.85

Calls 5

hasVirtualPropPathFunction · 0.85
matchesFieldMethod · 0.80
matchesCompareOptionsMethod · 0.80
matchesDirectionMethod · 0.80
valuesMethod · 0.45

Tested by

no test coverage detected