import { type DocumentReference, type DocumentSnapshot, type SnapshotListenOptions, type Unsubscribe } from 'firebase/firestore'; import { type ReactiveController, type ReactiveControllerHost } from 'lit'; export type DocRefTarget = DocumentReference | (() => DocumentReference | null | undefined) | null | undefined; export interface FirestoreDocControllerOptions { /** * The DocumentReference or a getter function returning one (or null/undefined). */ ref?: DocRefTarget; /** * Optional Firestore snapshot listen options (e.g., { includeMetadataChanges: true }). */ listenOptions?: SnapshotListenOptions; /** * Callback invoked whenever a new document snapshot arrives. */ onData?: (data: T | undefined, snapshot: DocumentSnapshot) => void; /** * Callback invoked when a Firestore 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 document subscriptions. * * Automatically subscribes on `hostConnected` and cleans up on `hostDisconnected`. * Supports dynamic reference getters that re-subscribe when properties change during `hostUpdate`. * * @example * ```typescript * class UserProfileElement extends LitElement { * @property() userId!: string; * * private user = new FirestoreDocController(this, { * ref: () => (this.userId ? doc(db, 'users', this.userId).withConverter(userConverter) : null), * }); * * render() { * if (this.user.loading) return html`

Loading...

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

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

`; * if (!this.user.exists) return html`

User not found

`; * return html`

${this.user.data?.name}

`; * } * } * ``` */ export declare class FirestoreDocController implements ReactiveController { protected host: ReactiveControllerHost; protected options: FirestoreDocControllerOptions; protected refTarget: DocRefTarget; protected activeRef: DocumentReference | null; protected unsubscribeFn?: Unsubscribe; protected isHostConnected: boolean; /** * Deserialized document data from the latest snapshot. */ data: T | undefined; /** * Raw QueryDocumentSnapshot or DocumentSnapshot from Firestore. */ snapshot?: DocumentSnapshot; /** * Whether the controller is actively waiting for the initial snapshot. */ loading: boolean; /** * Any error that occurred while listening to document changes. */ error?: Error; constructor(host: ReactiveControllerHost, options?: FirestoreDocControllerOptions); /** * Whether the document exists in Firestore. */ get exists(): boolean; /** * Whether the latest snapshot was served from the local cache. */ get isFromCache(): boolean; /** * Whether the document 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 reference getters to detect changes. */ hostUpdate(): void; /** * Updates the target reference and re-subscribes if connected. */ setRef(ref: DocRefTarget): void; /** * Begins listening to the current document target. */ subscribe(): void; /** * Unsubscribes from active listener and clears subscription handle. */ unsubscribe(): void; /** * Clears existing state and re-subscribes. */ refresh(): void; protected resolveRef(): DocumentReference | null; protected subscribeToRef(ref: DocumentReference | null): void; } //# sourceMappingURL=doc.controller.d.ts.map