UNPKG

5.01 kBTypeScriptView Raw
1import * as Firebase from 'firebase';
2import { Dispatch } from 'redux';
3
4/**
5 * Action types used within actions dispatched internally. These action types
6 * can be manually dispatched to update state.
7 */
8export const actionTypes: {
9 START: string;
10 ERROR: string;
11 CLEAR_DATA: string;
12 CLEAR_ERROR: string;
13 CLEAR_ERRORS: string;
14 SET_LISTENER: string;
15 UNSET_LISTENER: string;
16 GET_REQUEST: string;
17 GET_SUCCESS: string;
18 GET_FAILURE: string;
19 SET_REQUEST: string;
20 SET_SUCCESS: string;
21 SET_FAILURE: string;
22 ADD_REQUEST: string;
23 ADD_SUCCESS: string;
24 ADD_FAILURE: string;
25 UPDATE_REQUEST: string;
26 UPDATE_SUCCESS: string;
27 UPDATE_FAILURE: string;
28 DELETE_REQUEST: string;
29 DELETE_SUCCESS: string;
30 DELETE_FAILURE: string;
31 ATTACH_LISTENER: string;
32 LISTENER_RESPONSE: string;
33 LISTENER_ERROR: string;
34 ON_SNAPSHOT_REQUEST: string;
35 ON_SNAPSHOT_SUCCESS: string;
36 ON_SNAPSHOT_FAILURE: string;
37 DOCUMENT_ADDED: string;
38 DOCUMENT_MODIFIED: string;
39 DOCUMENT_REMOVED: string;
40 TRANSACTION_START: string;
41 TRANSACTION_SUCCESS: string;
42 TRANSACTION_FAILURE: string;
43};
44
45/**
46 * Constants used within redux-firetore. Includes actionTypes, actionsPrefix,
47 * and default config.
48 */
49export const constants: {
50 actionTypes: typeof actionTypes;
51 actionsPrefix: string;
52 defaultConfig: Config;
53};
54
55export interface Config {
56 enableLogging: boolean;
57
58 helpersNamespace: string | null;
59
60 // https://github.com/prescottprue/redux-firestore#loglistenererror
61 logListenerError: boolean;
62
63 // https://github.com/prescottprue/redux-firestore#enhancernamespace
64 enhancerNamespace: string;
65
66 // https://github.com/prescottprue/redux-firestore#allowmultiplelisteners
67 allowMultipleListeners:
68 | ((listenerToAttach: any, currentListeners: any) => boolean)
69 | boolean;
70
71 // https://github.com/prescottprue/redux-firestore#preserveondelete
72 preserveOnDelete: null | object;
73
74 // https://github.com/prescottprue/redux-firestore#preserveonlistenererror
75 preserveOnListenerError: null | object;
76
77 // https://github.com/prescottprue/redux-firestore#onattemptcollectiondelete
78 onAttemptCollectionDelete:
79 | null
80 | ((queryOption: string, dispatch: Dispatch, firebase: Object) => void);
81
82 // https://github.com/prescottprue/redux-firestore#mergeordered
83 mergeOrdered: boolean;
84
85 // https://github.com/prescottprue/redux-firestore#mergeordereddocupdate
86 mergeOrderedDocUpdate: boolean;
87
88 // https://github.com/prescottprue/redux-firestore#mergeorderedcollectionupdates
89 mergeOrderedCollectionUpdates: boolean;
90}
91
92/**
93 * A redux store enhancer that adds store.firebase (passed to React component
94 * context through react-redux's <Provider>).
95 */
96export function reduxFirestore(
97 firebaseInstance: typeof Firebase,
98 otherConfig?: Partial<Config>,
99): any;
100
101/**
102 * Get extended firestore instance (attached to store.firestore)
103 */
104export function getFirestore(
105 firebaseInstance: typeof Firebase,
106 otherConfig?: Partial<Config>,
107): any;
108
109/**
110 * Reducer for Firestore state
111 * @param state - Current Firebase Redux State (state.firestore)
112 * @param action - Action which will modify state
113 * @param action.type - Type of Action being called
114 * @param action.path - Path of action that was dispatched
115 * @param action.data - Data associated with action
116 * @see https://react-redux-firebase.com/docs/api/reducer.html
117 */
118export function firestoreReducer<Schema extends Record<string, any> = {}
119>(
120 state: any,
121 action: any
122): Reducer<FirestoreReducer.State<Schema>>
123
124/**
125 * Create a firestore instance that has helpers attached for dispatching actions
126 */
127export function createFirestoreInstance(
128 firebaseInstance: typeof Firebase,
129 configs: Partial<Config>,
130 dispatch: Dispatch,
131): object;
132
133/**
134 * A redux store reducer for Firestore state
135 */
136export namespace firestoreReducer {
137 const prototype: {};
138}
139
140/**
141 * A redux store reducer for Firestore state
142 */
143export namespace reduxFirestore {
144 const prototype: {};
145}
146
147export namespace FirestoreReducer {
148 declare const entitySymbol: unique symbol
149
150 export type Entity<T> = T & {
151 [entitySymbol]: never
152 }
153 export type EntityWithId<T> = T & { id: string }
154 export type FirestoreData<Schema extends Record<string, any>> = {
155 [T in keyof Schema]: Record<
156 string,
157 Schema[T] extends Entity<infer V> ? V : FirestoreData<Schema[T]>
158 >
159 }
160
161 export type OrderedData<Schema extends Record<string, any>> = {
162 [T in keyof Schema]: Schema[T] extends Entity<infer V>
163 ? EntityWithId<V>[]
164 : OrderedData<EntityWithId<Schema[T]>>[]
165 }
166
167 export interface Reducer<Schema extends Record<string, any> = {}> {
168 errors: {
169 allIds: string[]
170 byQuery: any[]
171 }
172 listeners: Listeners
173 data: FirestoreData<Schema>
174 ordered: OrderedData<Schema>
175 queries: Data<ReduxFirestoreQuerySetting & (Dictionary<any> | any)>
176 status: {
177 requested: Dictionary<boolean>
178 requesting: Dictionary<boolean>
179 timestamps: Dictionary<number>
180 }
181 }
182
183 const prototype: {}
184}
185
\No newline at end of file