import { SerializedRealTimeQuery } from '@forest-fire/serialized-query'; import type { IRtdbDataSnapshot, SnapshotFrom, ISdk } from '@forest-fire/types'; import { EventFrom, IRtdbSdk } from '@forest-fire/types'; /** * Captures a CRUD event */ export interface IMockWatcherGroupEvent { /** the unique identifier of the listener */ listenerId: string; /** the path that the listener is listening at */ listenerPath: string; /** the event which is being listened to */ listenerEvent: EventFrom; /** the dispatch function for this listener */ callback: IFirebaseEventHandler; /** the path where the event took place */ eventPaths: string[]; /** the "key" of the event; this applied to value AND child events */ key: string; /** changes between value and priorValue */ changes: unknown; /** the new value which has been set */ value: unknown; /** the prior value that this property held previous to the event */ priorValue: unknown; } /** * A change event which is fired from Firebase; the specific signature * of the event depends on the event type being fired. * * events: [API Spec](https://firebase.google.com/docs/reference/node/firebase.database.Reference#on) * * @param snap the DBRtdbDataSnapshot which provides access to the root of the `on` event; * in the case of a _removal_ you will get snapshot of the prior value * @param prevChildKey provided on `child_changed`, `child_moved`, and `child_added`; gives the * name of the key which directly _preceeds_ the event key in Firebase's stored order */ export interface IFirebaseEventHandler { (snap: SnapshotFrom, prevChildKey?: string): void; } export declare type EventHandler = HandleValueEvent | HandleNewEvent | HandleRemoveEvent; export declare type GenericEventHandler = (snap: IRtdbDataSnapshot, key?: string) => void; export declare type HandleValueEvent = (dataSnapShot: IRtdbDataSnapshot) => void; export declare type HandleNewEvent = (childSnapshot: IRtdbDataSnapshot, prevChildKey: string) => void; export declare type HandleRemoveEvent = (oldChildSnapshot: IRtdbDataSnapshot) => void; export declare type HandleMoveEvent = (childSnapshot: IRtdbDataSnapshot, prevChildKey: string) => void; export declare type HandleChangeEvent = (childSnapshot: IRtdbDataSnapshot, prevChildKey: string) => void; export interface IListener { /** random string */ id: string; /** the _query_ the listener is based off of */ query: SerializedRealTimeQuery; eventType: EventFrom; callback: (a: SnapshotFrom | null, b?: string) => any; cancelCallbackOrContext?: Record | null; context?: Record | null; }