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

Function assertLoadedExactly

packages/db-collection-e2e/src/utils/assertions.ts:8–34  ·  view source on GitHub ↗
(
  collection: Collection<T>,
  expectedIds: Array<string>,
  message?: string,
)

Source from the content-addressed store, hash-verified

6 * Assert that a collection has loaded exactly the expected items (no more, no less)
7 */
8export function assertLoadedExactly<T extends { id: string }>(
9 collection: Collection<T>,
10 expectedIds: Array<string>,
11 message?: string,
12) {
13 const loadedIds = getLoadedIds(collection)
14 const loadedSet = new Set(loadedIds)
15 const expectedSet = new Set(expectedIds)
16
17 // Check for extra items
18 const extraIds = loadedIds.filter((id) => !expectedSet.has(id))
19 if (extraIds.length > 0) {
20 throw new Error(
21 message ??
22 `Collection has extra items: ${extraIds.join(`, `)} (expected only: ${expectedIds.join(`, `)})`,
23 )
24 }
25
26 // Check for missing items
27 const missingIds = expectedIds.filter((id) => !loadedSet.has(id))
28 if (missingIds.length > 0) {
29 throw new Error(
30 message ??
31 `Collection is missing items: ${missingIds.join(`, `)} (loaded: ${loadedIds.join(`, `)})`,
32 )
33 }
34}
35
36/**
37 * Assert that a collection has loaded at least the expected items (may have more)

Callers

nothing calls this directly

Calls 4

getLoadedIdsFunction · 0.90
filterMethod · 0.80
hasMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…