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

Function processJoinSource

packages/db/src/query/compiler/joins.ts:455–571  ·  view source on GitHub ↗

* Processes the join source (collection or sub-query)

(
  from: CollectionRef | QueryRef,
  allInputs: Record<string, KeyedStream>,
  collections: Record<string, Collection>,
  subscriptions: Record<string, CollectionSubscription>,
  callbacks: Record<string, LazyCollectionCallbacks>,
  lazySources: Set<string>,
  optimizableOrderByCollections: Record<string, OrderByOptimizationInfo>,
  setWindowFn: (windowFn: (options: WindowOptions) => void) => void,
  cache: QueryCache,
  queryMapping: QueryMapping,
  onCompileSubquery: CompileQueryFn,
  aliasToCollectionId: Record<string, string>,
  aliasRemapping: Record<string, string>,
  sourceWhereClauses: Map<string, BasicExpression<boolean>>,
)

Source from the content-addressed store, hash-verified

453 * Processes the join source (collection or sub-query)
454 */
455function processJoinSource(
456 from: CollectionRef | QueryRef,
457 allInputs: Record<string, KeyedStream>,
458 collections: Record<string, Collection>,
459 subscriptions: Record<string, CollectionSubscription>,
460 callbacks: Record<string, LazyCollectionCallbacks>,
461 lazySources: Set<string>,
462 optimizableOrderByCollections: Record<string, OrderByOptimizationInfo>,
463 setWindowFn: (windowFn: (options: WindowOptions) => void) => void,
464 cache: QueryCache,
465 queryMapping: QueryMapping,
466 onCompileSubquery: CompileQueryFn,
467 aliasToCollectionId: Record<string, string>,
468 aliasRemapping: Record<string, string>,
469 sourceWhereClauses: Map<string, BasicExpression<boolean>>,
470): { alias: string; input: KeyedStream; collectionId: string } {
471 switch (from.type) {
472 case `collectionRef`: {
473 const input = allInputs[from.alias]
474 if (!input) {
475 throw new CollectionInputNotFoundError(
476 from.alias,
477 from.collection.id,
478 Object.keys(allInputs),
479 )
480 }
481 aliasToCollectionId[from.alias] = from.collection.id
482 return { alias: from.alias, input, collectionId: from.collection.id }
483 }
484 case `queryRef`: {
485 // Find the original query for caching purposes
486 const originalQuery = queryMapping.get(from.query) || from.query
487
488 // Recursively compile the sub-query with cache
489 const subQueryResult = onCompileSubquery(
490 originalQuery,
491 allInputs,
492 collections,
493 subscriptions,
494 callbacks,
495 lazySources,
496 optimizableOrderByCollections,
497 setWindowFn,
498 cache,
499 queryMapping,
500 )
501
502 // Pull up alias mappings from subquery to parent scope.
503 // This includes both the innermost alias-to-collection mappings AND
504 // any existing remappings from nested subquery levels.
505 Object.assign(aliasToCollectionId, subQueryResult.aliasToCollectionId)
506 Object.assign(aliasRemapping, subQueryResult.aliasRemapping)
507
508 // Pull up source WHERE clauses from subquery to parent scope.
509 // This enables loadSubset to receive the correct where clauses for subquery collections.
510 //
511 // IMPORTANT: Skip pull-up for optimizer-created subqueries. These are detected when:
512 // 1. The outer alias (from.alias) matches the inner alias (from.query.from.alias)

Callers 1

processJoinFunction · 0.85

Calls 7

mapFunction · 0.90
pipeMethod · 0.80
getFirstFromAliasFunction · 0.70
keysMethod · 0.45
getMethod · 0.45
hasMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…