MCPcopy Create free account
hub / github.com/clientdb/clientdb / getRemainingItemsAfterApplyingQueryFields

Function getRemainingItemsAfterApplyingQueryFields

core/find.ts:25–47  ·  view source on GitHub ↗
(
  currentItems: Entity<Data, View>[],
  store: EntityStore<Data, View>,
  queryObject: FindObjectPartInput<Data & View>
)

Source from the content-addressed store, hash-verified

23type MaybeObservableArray<T> = IObservableArray<T> | T[];
24
25function getRemainingItemsAfterApplyingQueryFields<Data, View>(
26 currentItems: Entity<Data, View>[],
27 store: EntityStore<Data, View>,
28 queryObject: FindObjectPartInput<Data & View>
29) {
30 let passingItems = currentItems;
31
32 const itemsMatchingEachValue: Entity<Data, View>[][] = [];
33
34 for (const queryKey of typedKeys(queryObject)) {
35 const queryValue = queryObject[queryKey] as AnyKeyIndexInput<Data & View>;
36 const index = store.getPropIndex(queryKey);
37
38 const itemsMatchingValue = index.find(queryValue);
39
40 // If no items are matching some value - there is no point in continuing.
41 if (itemsMatchingValue.length === 0) return [];
42
43 itemsMatchingEachValue.push(itemsMatchingValue);
44 }
45
46 return getArraysCommonPart(passingItems, ...itemsMatchingEachValue);
47}
48
49export function findInSourceByObjectInput<Data, View>(
50 source: MaybeObservableArray<Entity<Data, View>>,

Callers 1

Calls 4

typedKeysFunction · 0.90
getArraysCommonPartFunction · 0.90
getPropIndexMethod · 0.80
findMethod · 0.65

Tested by

no test coverage detected