@dataql/firebase-adapter
Version:
Firebase adapter for DataQL with zero API changes
80 lines • 2.64 kB
TypeScript
export interface FirebaseConfig {
apiKey: string;
authDomain: string;
projectId: string;
storageBucket?: string;
messagingSenderId?: string;
appId: string;
measurementId?: string;
}
export interface DataQLFirebaseOptions {
appToken?: string;
dbName?: string;
env?: "dev" | "prod";
devPrefix?: string;
customConnection?: any;
firebase?: FirebaseConfig;
}
export interface DocumentSnapshot<T = any> {
id: string;
exists: boolean;
data(): T | undefined;
get(field: string): any;
}
export interface QuerySnapshot<T = any> {
empty: boolean;
size: number;
docs: QueryDocumentSnapshot<T>[];
forEach(callback: (doc: QueryDocumentSnapshot<T>) => void): void;
}
export interface QueryDocumentSnapshot<T = any> {
id: string;
data(): T;
get(field: string): any;
}
export interface WriteResult {
writeTime: string;
}
export interface DocumentReference<T = any> {
id: string;
path: string;
get(): Promise<DocumentSnapshot<T>>;
set(data: T, options?: SetOptions): Promise<WriteResult>;
update(data: Partial<T>): Promise<WriteResult>;
delete(): Promise<WriteResult>;
onSnapshot(onNext: (snapshot: DocumentSnapshot<T>) => void, onError?: (error: Error) => void): () => void;
}
export interface SetOptions {
merge?: boolean;
}
export type WhereFilterOp = "==" | "!=" | "<" | "<=" | ">" | ">=" | "array-contains" | "in" | "array-contains-any";
export type OrderByDirection = "asc" | "desc";
export interface Query<T = any> {
where(fieldPath: string, opStr: WhereFilterOp, value: any): Query<T>;
orderBy(fieldPath: string, directionStr?: OrderByDirection): Query<T>;
limit(limit: number): Query<T>;
get(): Promise<QuerySnapshot<T>>;
onSnapshot(onNext: (snapshot: QuerySnapshot<T>) => void, onError?: (error: Error) => void): () => void;
}
export interface CollectionReference<T = any> extends Query<T> {
id: string;
path: string;
doc(documentPath?: string): DocumentReference<T>;
add(data: T): Promise<DocumentReference<T>>;
}
export interface Firestore {
collection(collectionPath: string): CollectionReference;
doc(documentPath: string): DocumentReference;
}
export interface FirebaseApp {
name: string;
options: FirebaseConfig;
}
export declare function initializeApp(config: FirebaseConfig, options?: DataQLFirebaseOptions): FirebaseApp;
export declare function getFirestore(app?: FirebaseApp): Firestore;
declare const _default: {
initializeApp: typeof initializeApp;
getFirestore: typeof getFirestore;
};
export default _default;
//# sourceMappingURL=index.d.ts.map