(opts: any)
| 134 | liveQueryCollection: Collection<TResult, TKey, TUtils> & SingleResult, |
| 135 | ): InjectLiveQueryResultWithSingleResultCollection<TResult, TKey, TUtils> |
| 136 | export function injectLiveQuery(opts: any) { |
| 137 | assertInInjectionContext(injectLiveQuery) |
| 138 | const destroyRef = inject(DestroyRef) |
| 139 | |
| 140 | const collection = computed(() => { |
| 141 | // Check if it's an existing collection |
| 142 | const isExistingCollection = |
| 143 | opts && |
| 144 | typeof opts === `object` && |
| 145 | typeof opts.subscribeChanges === `function` && |
| 146 | typeof opts.startSyncImmediate === `function` && |
| 147 | typeof opts.id === `string` |
| 148 | |
| 149 | if (isExistingCollection) { |
| 150 | return opts |
| 151 | } |
| 152 | |
| 153 | if (typeof opts === `function`) { |
| 154 | // Check if query function returns null/undefined (disabled query) |
| 155 | const queryBuilder = new BaseQueryBuilder() as InitialQueryBuilder |
| 156 | const result = opts(queryBuilder) |
| 157 | |
| 158 | if (result === undefined || result === null) { |
| 159 | // Disabled query - return null |
| 160 | return null |
| 161 | } |
| 162 | |
| 163 | return createLiveQueryCollection({ |
| 164 | query: opts, |
| 165 | startSync: true, |
| 166 | gcTime: 0, |
| 167 | }) |
| 168 | } |
| 169 | |
| 170 | // Check if it's reactive query options |
| 171 | const isReactiveQueryOptions = |
| 172 | opts && |
| 173 | typeof opts === `object` && |
| 174 | typeof opts.query === `function` && |
| 175 | typeof opts.params === `function` |
| 176 | |
| 177 | if (isReactiveQueryOptions) { |
| 178 | const { params, query } = opts |
| 179 | const currentParams = params() |
| 180 | |
| 181 | // Check if query function returns null/undefined (disabled query) |
| 182 | const queryBuilder = new BaseQueryBuilder() as InitialQueryBuilder |
| 183 | const result = query({ params: currentParams, q: queryBuilder }) |
| 184 | |
| 185 | if (result === undefined || result === null) { |
| 186 | // Disabled query - return null |
| 187 | return null |
| 188 | } |
| 189 | |
| 190 | return createLiveQueryCollection({ |
| 191 | query: () => result, |
| 192 | startSync: true, |
| 193 | gcTime: 0, |
no test coverage detected
searching dependent graphs…