import { type Query, type QuerySnapshot, type SnapshotListenOptions, type Unsubscribe } from 'firebase/firestore'; import { type ReactiveController, type ReactiveControllerHost } from 'lit'; export type QueryTarget = Query | (() => Query | null | undefined) | null | undefined; export interface FirestoreQueryControllerOptions { /** * The Firestore Query/CollectionReference or a getter function returning one (or null/undefined). */ query?: QueryTarget; /** * Optional Firestore snapshot listen options (e.g., { includeMetadataChanges: true }). */ listenOptions?: SnapshotListenOptions; /** * Callback invoked whenever a new query snapshot arrives. */ onData?: (data: T[], snapshot: QuerySnapshot) => void; /** * Callback invoked when a Firestore query listener error occurs. */ onError?: (error: Error) => void; /** * Whether to automatically subscribe when host connects. Defaults to true. */ autoStart?: boolean; } /** * A Lit Reactive Controller that manages real-time Firestore query subscriptions. * * Automatically subscribes on `hostConnected` and cleans up on `hostDisconnected`. * Supports dynamic query getters that re-subscribe when filter parameters change during `hostUpdate`. * * @example * ```typescript * class CampListElement extends LitElement { * @property({ type: Boolean }) isPublicOnly = true; * * private camps = new FirestoreQueryController(this, { * query: () => { * const col = collection(db, 'camps').withConverter(campConverter); * return this.isPublicOnly ? query(col, where('isPublic', '==', true)) : query(col); * }, * }); * * render() { * if (this.camps.loading) return html`

Loading camps...

`; * if (this.camps.error) return html`

Error: ${this.camps.error.message}

`; * if (this.camps.empty) return html`

No camps found.

`; * return html` *

Total: ${this.camps.count}

*
    * ${this.camps.data.map(camp => html`
  • ${camp.name}
  • `)} *
* `; * } * } * ``` */ export declare class FirestoreQueryController implements ReactiveController { protected host: ReactiveControllerHost; protected options: FirestoreQueryControllerOptions; protected queryTarget: QueryTarget; protected activeQuery: Query | null; protected unsubscribeFn?: Unsubscribe; protected isHostConnected: boolean; /** * Deserialized items from the latest query snapshot. */ data: T[]; /** * Raw QuerySnapshot from Firestore. */ snapshot?: QuerySnapshot; /** * Whether the controller is waiting for the initial query snapshot. */ loading: boolean; /** * Any error that occurred during query subscription. */ error?: Error; constructor(host: ReactiveControllerHost, options?: FirestoreQueryControllerOptions); /** * Number of items in current result set. */ get count(): number; /** * Whether the query snapshot contains no documents. */ get empty(): boolean; /** * Whether the latest snapshot was served from the local cache. */ get isFromCache(): boolean; /** * Whether the snapshot has uncommitted local mutations. */ get hasPendingWrites(): boolean; /** * Lifecycle callback: host connected to DOM. */ hostConnected(): void; /** * Lifecycle callback: host disconnected from DOM. */ hostDisconnected(): void; /** * Lifecycle callback: runs before host update. * Re-evaluates dynamic query getters to detect changes. */ hostUpdate(): void; /** * Updates the target query and re-subscribes if connected. */ setQuery(query: QueryTarget): void; /** * Begins listening to the current query target. */ subscribe(): void; /** * Unsubscribes from active listener and clears subscription handle. */ unsubscribe(): void; /** * Clears existing state and re-subscribes. */ refresh(): void; protected resolveQuery(): Query | null; protected subscribeToQuery(q: Query | null): void; } //# sourceMappingURL=query.controller.d.ts.map