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

Function assertAllItemsMatch

packages/db-collection-e2e/src/utils/assertions.ts:89–103  ·  view source on GitHub ↗
(
  collection: Collection<T>,
  predicate: (item: T) => boolean,
  message?: string,
)

Source from the content-addressed store, hash-verified

87 * Assert that all items in a collection match a predicate
88 */
89export function assertAllItemsMatch<T extends object>(
90 collection: Collection<T>,
91 predicate: (item: T) => boolean,
92 message?: string,
93) {
94 const items = Array.from(collection.state.values())
95 const failingItems = items.filter((item) => !predicate(item))
96
97 if (failingItems.length > 0) {
98 throw new Error(
99 message ??
100 `${failingItems.length} item(s) did not match predicate: ${JSON.stringify(failingItems[0])}`,
101 )
102 }
103}
104
105/**
106 * Assert that items are sorted correctly

Callers 2

Calls 3

fromMethod · 0.80
filterMethod · 0.80
valuesMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…