import { AbstractPowerSyncDatabase } from './AbstractPowerSyncDatabase.js'; import { Query, StandardWatchedQueryOptions } from './Query.js'; import { FalsyComparator } from './watched/processors/comparators.js'; import { DifferentialQueryProcessor, DifferentialWatchedQueryOptions } from './watched/processors/DifferentialQueryProcessor.js'; import { OnChangeQueryProcessor } from './watched/processors/OnChangeQueryProcessor.js'; import { DEFAULT_WATCH_QUERY_OPTIONS, WatchCompatibleQuery, WatchedQueryOptions } from './watched/WatchedQuery.js'; /** * @internal */ export interface CustomQueryOptions { db: AbstractPowerSyncDatabase; query: WatchCompatibleQuery; } /** * @internal */ export class CustomQuery implements Query { constructor(protected options: CustomQueryOptions) {} protected resolveOptions(options: WatchedQueryOptions): WatchedQueryOptions { return { reportFetching: options?.reportFetching ?? DEFAULT_WATCH_QUERY_OPTIONS.reportFetching, throttleMs: options?.throttleMs ?? DEFAULT_WATCH_QUERY_OPTIONS.throttleMs, triggerOnTables: options?.triggerOnTables }; } watch(watchOptions: StandardWatchedQueryOptions) { return new OnChangeQueryProcessor({ db: this.options.db, comparator: watchOptions?.comparator ?? FalsyComparator, placeholderData: watchOptions?.placeholderData ?? [], watchOptions: { ...this.resolveOptions(watchOptions), query: this.options.query } }); } differentialWatch(differentialWatchOptions: DifferentialWatchedQueryOptions) { return new DifferentialQueryProcessor({ db: this.options.db, rowComparator: differentialWatchOptions?.rowComparator, placeholderData: differentialWatchOptions?.placeholderData ?? [], watchOptions: { ...this.resolveOptions(differentialWatchOptions), query: this.options.query } }); } }