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

Function extractIncludesFromSelect

packages/db/src/query/compiler/index.ts:1763–1792  ·  view source on GitHub ↗

* Walks a Select object to find IncludesSubquery entries. * Plain nested objects still reject includes, but ConditionalSelect branches can * contain guarded nested includes that are only materialized when the branch * condition is true.

(select: Record<string, any>)

Source from the content-addressed store, hash-verified

1761 * condition is true.
1762 */
1763function extractIncludesFromSelect(select: Record<string, any>): Array<{
1764 key: string
1765 path: Array<string>
1766 subquery: IncludesSubquery
1767 guards: Array<ConditionalSelectGuard>
1768}> {
1769 const results: Array<{
1770 key: string
1771 path: Array<string>
1772 subquery: IncludesSubquery
1773 guards: Array<ConditionalSelectGuard>
1774 }> = []
1775 for (const [key, value] of Object.entries(select)) {
1776 if (key.startsWith(`__SPREAD_SENTINEL__`)) continue
1777 if (value instanceof IncludesSubquery) {
1778 results.push({
1779 key: getIncludesRoutingKey([key], results),
1780 path: [key],
1781 subquery: value,
1782 guards: [],
1783 })
1784 } else if (value instanceof ConditionalSelect) {
1785 collectIncludesFromConditionalSelect(value, [key], [], results)
1786 } else if (isNestedSelectObject(value)) {
1787 // Check nested objects for IncludesSubquery — not supported yet
1788 assertNoNestedIncludes(value, key)
1789 }
1790 }
1791 return results
1792}
1793
1794function collectIncludesFromConditionalSelect(
1795 conditional: ConditionalSelect,

Callers 1

compileQueryFunction · 0.85

Calls 5

getIncludesRoutingKeyFunction · 0.85
assertNoNestedIncludesFunction · 0.85
isNestedSelectObjectFunction · 0.70
entriesMethod · 0.45

Tested by

no test coverage detected