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

Function createDerivedCollection

packages/db/tests/query/includes.test.ts:6337–6352  ·  view source on GitHub ↗
(
      id: string,
      source: ReturnType<typeof createSyncCollection<any>>[`collection`],
      extraFields?: (d: any) => Record<string, unknown>,
    )

Source from the content-addressed store, hash-verified

6335 type RawItem = { key: string; _seq: number; [k: string]: unknown }
6336
6337 function createDerivedCollection(
6338 id: string,
6339 source: ReturnType<typeof createSyncCollection<any>>[`collection`],
6340 extraFields?: (d: any) => Record<string, unknown>,
6341 ) {
6342 return createLiveQueryCollection({
6343 id: `${id}:derived`,
6344 query: (q: any) =>
6345 q.from({ d: source }).select(({ d }: any) => ({
6346 timelineKey: TIMELINE_KEY,
6347 key: d.key,
6348 order: coalesce(d._seq, -1),
6349 ...(extraFields ? extraFields(d) : {}),
6350 })),
6351 })
6352 }
6353
6354 it(`second insert propagates with 5 sibling chained toArray includes`, async () => {
6355 const runs = createSyncCollection<RawItem>(`raw-runs`, (r) => r.key)

Callers 1

includes.test.tsFile · 0.85

Calls 4

coalesceFunction · 0.85
selectMethod · 0.80
fromMethod · 0.80

Tested by

no test coverage detected