forked from CSFrequency/react-firebase-hooks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.ts
44 lines (41 loc) · 1.4 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import firebase from 'firebase/app';
import { LoadingHook } from '../util';
export type IDOptions<T> = {
idField?: string;
refField?: string;
snapshotOptions?: firebase.firestore.SnapshotOptions;
transform?: (val: any) => T;
};
export type Options = {
snapshotListenOptions?: firebase.firestore.SnapshotListenOptions;
};
export type DataOptions<T> = Options & IDOptions<T>;
export type OnceOptions = {
getOptions?: firebase.firestore.GetOptions;
};
export type OnceDataOptions<T> = OnceOptions & IDOptions<T>;
export type Data<
T = firebase.firestore.DocumentData,
IDField extends string = '',
RefField extends string = ''
> = T &
Record<IDField, string> &
Record<RefField, firebase.firestore.DocumentReference<T>>;
export type CollectionHook<T = firebase.firestore.DocumentData> = LoadingHook<
firebase.firestore.QuerySnapshot<T>,
firebase.FirebaseError
>;
export type CollectionDataHook<
T = firebase.firestore.DocumentData,
IDField extends string = '',
RefField extends string = ''
> = LoadingHook<Data<T, IDField, RefField>[], firebase.FirebaseError>;
export type DocumentHook<T = firebase.firestore.DocumentData> = LoadingHook<
firebase.firestore.DocumentSnapshot<T>,
firebase.FirebaseError
>;
export type DocumentDataHook<
T = firebase.firestore.DocumentData,
IDField extends string = '',
RefField extends string = ''
> = LoadingHook<Data<T, IDField, RefField>, firebase.FirebaseError>;