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

Function toTree

packages/db/tests/query/includes.test.ts:135–142  ·  view source on GitHub ↗

* Recursively converts a live query collection (or child Collection) into a * plain sorted array, turning any nested child Collections into nested arrays. * This lets tests compare the full hierarchical result as a single literal.

(collectionOrArray: any, sortKey = `id`)

Source from the content-addressed store, hash-verified

133 * This lets tests compare the full hierarchical result as a single literal.
134 */
135function toTree(collectionOrArray: any, sortKey = `id`): Array<any> {
136 const rows = (
137 Array.isArray(collectionOrArray)
138 ? [...collectionOrArray]
139 : [...collectionOrArray.toArray]
140 ).sort((a: any, b: any) => a[sortKey] - b[sortKey])
141 return rows.map((row: any) => stripVirtualPropsDeep(row))
142}
143
144describe(`includes subqueries`, () => {
145 let projects: ReturnType<typeof createProjectsCollection>

Callers 2

stripVirtualPropsDeepFunction · 0.85
includes.test.tsFile · 0.85

Calls 2

stripVirtualPropsDeepFunction · 0.70
mapMethod · 0.45

Tested by

no test coverage detected