( collection: CollectionLike<any, TKey>, fieldPath: Array<string>, compareOptions?: CompareOptions, )
| 43 | * Finds an index that matches a given field path |
| 44 | */ |
| 45 | export 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) |
no test coverage detected