MCPcopy Create free account
hub / github.com/TanStack/db / withIndexTracking

Function withIndexTracking

packages/db/tests/utils.ts:193–209  ·  view source on GitHub ↗
(
  collection: any,
  testFn: (tracker: { stats: IndexUsageStats }) => void | Promise<void>,
)

Source from the content-addressed store, hash-verified

191
192// Helper to run a test with index usage tracking (automatically handles setup/cleanup)
193export function withIndexTracking(
194 collection: any,
195 testFn: (tracker: { stats: IndexUsageStats }) => void | Promise<void>,
196): void | Promise<void> {
197 const tracker = createIndexUsageTracker(collection)
198
199 try {
200 const result = testFn(tracker)
201 if (result instanceof Promise) {
202 return result.finally(() => tracker.restore())
203 }
204 tracker.restore()
205 } catch (error) {
206 tracker.restore()
207 throw error
208 }
209}
210
211type MockSyncCollectionConfig<T extends object = Record<string, unknown>> = {
212 id: string

Calls 2

testFnFunction · 0.85
createIndexUsageTrackerFunction · 0.70

Tested by

no test coverage detected