(
configOrQuery:
| (LiveQueryCollectionConfig<TContext, TResult> & { utils?: TUtils })
| ((
q: InitialQueryBuilder,
) => QueryBuilder<TContext> & RootObjectResultConstraint<TContext>),
)
| 153 | |
| 154 | // Implementation |
| 155 | export function createLiveQueryCollection< |
| 156 | TContext extends Context, |
| 157 | TResult extends object = RootQueryResult<TContext>, |
| 158 | TUtils extends UtilsRecord = {}, |
| 159 | >( |
| 160 | configOrQuery: |
| 161 | | (LiveQueryCollectionConfig<TContext, TResult> & { utils?: TUtils }) |
| 162 | | (( |
| 163 | q: InitialQueryBuilder, |
| 164 | ) => QueryBuilder<TContext> & RootObjectResultConstraint<TContext>), |
| 165 | ): CollectionForContext<TContext, TResult> & { |
| 166 | utils: LiveQueryCollectionUtils & TUtils |
| 167 | } { |
| 168 | // Determine if the argument is a function (query) or a config object |
| 169 | if (typeof configOrQuery === `function`) { |
| 170 | // Simple query function case |
| 171 | const config: LiveQueryCollectionConfig<TContext, TResult> = { |
| 172 | query: configOrQuery as ( |
| 173 | q: InitialQueryBuilder, |
| 174 | ) => QueryBuilder<TContext> & RootObjectResultConstraint<TContext>, |
| 175 | } |
| 176 | // The implementation accepts both overload shapes, but TypeScript cannot |
| 177 | // preserve the overload-specific query-builder inference through this branch. |
| 178 | const options = liveQueryCollectionOptions(config as any) |
| 179 | return bridgeToCreateCollection(options) as CollectionForContext< |
| 180 | TContext, |
| 181 | TResult |
| 182 | > & { utils: LiveQueryCollectionUtils & TUtils } |
| 183 | } else { |
| 184 | // Config object case |
| 185 | const config = configOrQuery as LiveQueryCollectionConfig< |
| 186 | TContext, |
| 187 | TResult |
| 188 | > & { utils?: TUtils } |
| 189 | // Same overload implementation limitation as above: the config has already |
| 190 | // been validated by the public signatures, but the branch loses that precision. |
| 191 | const options = liveQueryCollectionOptions(config as any) |
| 192 | |
| 193 | // Merge custom utils if provided, preserving the getBuilder() method for dependency tracking |
| 194 | if (config.utils) { |
| 195 | options.utils = { ...options.utils, ...config.utils } |
| 196 | } |
| 197 | |
| 198 | return bridgeToCreateCollection(options) as CollectionForContext< |
| 199 | TContext, |
| 200 | TResult |
| 201 | > & { utils: LiveQueryCollectionUtils & TUtils } |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | /** |
| 206 | * Bridge function that handles the type compatibility between query2's TResult |
searching dependent graphs…