@@ -423,6 +423,38 @@ export function syncTreeRemoveEventRegistration(
423423 return cancelEvents ;
424424}
425425
426+ /**
427+ * This function was added to support non-listener queries,
428+ * specifically for use in repoGetValue. It sets up all the same
429+ * local cache data-structures (SyncPoint + View) that are
430+ * needed for listeners without installing an event registration.
431+ * If `query` is not `loadsAllData`, it will also provision a tag for
432+ * the query so that query results can be merged into the sync
433+ * tree using existing logic for tagged listener queries.
434+ *
435+ * @param syncTree - Synctree to add the query to.
436+ * @param query - Query to register
437+ * @returns tag as a string if query is not a default query, null if query is not.
438+ */
439+ export function syncTreeRegisterQuery ( syncTree : SyncTree , query : QueryContext ) {
440+ const { syncPoint, serverCache, writesCache, serverCacheComplete } =
441+ syncTreeRegisterSyncPoint ( query , syncTree ) ;
442+ const view = syncPointGetView (
443+ syncPoint ,
444+ query ,
445+ writesCache ,
446+ serverCache ,
447+ serverCacheComplete
448+ ) ;
449+ if ( ! syncPoint . views . has ( query . _queryIdentifier ) ) {
450+ syncPoint . views . set ( query . _queryIdentifier , view ) ;
451+ }
452+ if ( ! query . _queryParams . loadsAllData ( ) ) {
453+ return syncTreeTagForQuery_ ( syncTree , query ) ;
454+ }
455+ return null ;
456+ }
457+
426458/**
427459 * Apply new server data for the specified tagged query.
428460 *
@@ -483,15 +515,14 @@ export function syncTreeApplyTaggedQueryMerge(
483515}
484516
485517/**
486- * Add an event callback for the specified query .
487- *
488- * @returns Events to raise .
518+ * Creates a new syncpoint for a query and creates a tag if the view doesn't exist .
519+ * Extracted from addEventRegistration to allow `repoGetValue` to properly set up the SyncTree
520+ * without actually listening on a query .
489521 */
490- export function syncTreeAddEventRegistration (
491- syncTree : SyncTree ,
522+ export function syncTreeRegisterSyncPoint (
492523 query : QueryContext ,
493- eventRegistration : EventRegistration
494- ) : Event [ ] {
524+ syncTree : SyncTree
525+ ) {
495526 const path = query . _path ;
496527
497528 let serverCache : Node | null = null ;
@@ -550,6 +581,35 @@ export function syncTreeAddEventRegistration(
550581 syncTree . tagToQueryMap . set ( tag , queryKey ) ;
551582 }
552583 const writesCache = writeTreeChildWrites ( syncTree . pendingWriteTree_ , path ) ;
584+ return {
585+ syncPoint,
586+ writesCache,
587+ serverCache,
588+ serverCacheComplete,
589+ foundAncestorDefaultView,
590+ viewAlreadyExists
591+ } ;
592+ }
593+
594+ /**
595+ * Add an event callback for the specified query.
596+ *
597+ * @returns Events to raise.
598+ */
599+ export function syncTreeAddEventRegistration (
600+ syncTree : SyncTree ,
601+ query : QueryContext ,
602+ eventRegistration : EventRegistration
603+ ) : Event [ ] {
604+ const {
605+ syncPoint,
606+ serverCache,
607+ writesCache,
608+ serverCacheComplete,
609+ viewAlreadyExists,
610+ foundAncestorDefaultView
611+ } = syncTreeRegisterSyncPoint ( query , syncTree ) ;
612+
553613 let events = syncPointAddEventRegistration (
554614 syncPoint ,
555615 query ,
@@ -937,7 +997,6 @@ function syncTreeSetupListener_(
937997 const path = query . _path ;
938998 const tag = syncTreeTagForQuery_ ( syncTree , query ) ;
939999 const listener = syncTreeCreateListenerForView_ ( syncTree , view ) ;
940-
9411000 const events = syncTree . listenProvider_ . startListening (
9421001 syncTreeQueryForListening_ ( query ) ,
9431002 tag ,
0 commit comments