react-query-firebase 2.1.2 → 2.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/react-native/context/FirebaseContextProvider.d.ts +1 -2
- package/react-native/context/FirebaseContextProvider.js +16 -15
- package/react-native/context/FirebaseContextProvider.tsx +20 -22
- package/react-native/firestore/useCompositeFilter.d.ts +1 -1
- package/react-native/firestore/useCompositeFilter.js +6 -0
- package/react-native/firestore/useCompositeFilter.ts +9 -0
package/package.json
CHANGED
|
@@ -59,7 +59,6 @@ export type FirebaseContextProviderEmulators = {
|
|
|
59
59
|
* @inline
|
|
60
60
|
*/
|
|
61
61
|
export type FirebaseContextProviderProps = PropsWithChildren & {
|
|
62
|
-
platform: "Web" | "ReactNative";
|
|
63
62
|
/**
|
|
64
63
|
* Defines configuration for firebase emulators
|
|
65
64
|
*/
|
|
@@ -67,7 +66,7 @@ export type FirebaseContextProviderProps = PropsWithChildren & {
|
|
|
67
66
|
/**
|
|
68
67
|
* Configuration options for Firebase initialization. {@link https://firebase.google.com/docs/web/setup#config-object | Learn about the Firebase config object}
|
|
69
68
|
*/
|
|
70
|
-
options
|
|
69
|
+
options?: ReactNativeFirebase.FirebaseAppOptions;
|
|
71
70
|
/**
|
|
72
71
|
* Flag indicating whether Firebase Auth should be enabled.
|
|
73
72
|
*/
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import React, { useEffect, useMemo } from "react";
|
|
2
2
|
import { FirebaseContext } from "./FirebaseContext";
|
|
3
|
-
import { connectAuthEmulator } from "@react-native-firebase/auth";
|
|
4
|
-
import { setAnalyticsCollectionEnabled, setConsent } from "@react-native-firebase/analytics";
|
|
5
|
-
import
|
|
3
|
+
import auth, { connectAuthEmulator } from "@react-native-firebase/auth";
|
|
4
|
+
import analytics, { setAnalyticsCollectionEnabled, setConsent } from "@react-native-firebase/analytics";
|
|
5
|
+
import remoteConfig from "@react-native-firebase/remote-config";
|
|
6
|
+
import firestore, { connectFirestoreEmulator } from "@react-native-firebase/firestore";
|
|
6
7
|
import firebase from "@react-native-firebase/app";
|
|
7
8
|
/**
|
|
8
9
|
* FirebaseContextProvider component configures and provides Firebase services to its children.
|
|
@@ -27,10 +28,10 @@ import firebase from "@react-native-firebase/app";
|
|
|
27
28
|
* };
|
|
28
29
|
* ```
|
|
29
30
|
*/
|
|
30
|
-
export const FirebaseContextProvider = ({ emulators,
|
|
31
|
+
export const FirebaseContextProvider = ({ emulators, children, authEnabled = true, firestoreEnabled = true, analyticsEnabled = true, consentSettings = {}, remoteConfigEnabled = true, remoteConfigSettings, remoteConfigDefaults = {}, firestoreSettings }) => {
|
|
31
32
|
const internalFirebase = useMemo(() => firebase, []);
|
|
32
33
|
useEffect(() => {
|
|
33
|
-
setConsent(
|
|
34
|
+
setConsent(analytics(), {
|
|
34
35
|
ad_personalization: false,
|
|
35
36
|
ad_storage: false,
|
|
36
37
|
ad_user_data: false,
|
|
@@ -44,19 +45,19 @@ export const FirebaseContextProvider = ({ emulators, options, children, authEnab
|
|
|
44
45
|
const internalFirestore = useMemo(() => {
|
|
45
46
|
if (firestoreEnabled) {
|
|
46
47
|
if (emulators?.firestore?.host && emulators?.firestore?.port) {
|
|
47
|
-
connectFirestoreEmulator(
|
|
48
|
+
connectFirestoreEmulator(firestore(), emulators.firestore.host, emulators.firestore.port);
|
|
48
49
|
}
|
|
49
|
-
const localFirestore =
|
|
50
|
+
const localFirestore = firestore();
|
|
50
51
|
if (firestoreSettings) {
|
|
51
52
|
localFirestore.settings(firestoreSettings);
|
|
52
53
|
}
|
|
53
54
|
return localFirestore;
|
|
54
55
|
}
|
|
55
56
|
return null;
|
|
56
|
-
}, [emulators?.firestore, firestoreEnabled,
|
|
57
|
+
}, [emulators?.firestore, firestoreEnabled, firestoreSettings]);
|
|
57
58
|
const internalAuth = useMemo(() => {
|
|
58
59
|
if (authEnabled) {
|
|
59
|
-
const localAuth =
|
|
60
|
+
const localAuth = auth();
|
|
60
61
|
if (emulators?.auth?.host) {
|
|
61
62
|
connectAuthEmulator(localAuth, emulators?.auth?.host, {
|
|
62
63
|
disableWarnings: true
|
|
@@ -65,16 +66,16 @@ export const FirebaseContextProvider = ({ emulators, options, children, authEnab
|
|
|
65
66
|
return localAuth;
|
|
66
67
|
}
|
|
67
68
|
return null;
|
|
68
|
-
}, [emulators?.auth, authEnabled
|
|
69
|
+
}, [emulators?.auth, authEnabled]);
|
|
69
70
|
const internalAnalytics = useMemo(() => {
|
|
70
|
-
if (analyticsEnabled
|
|
71
|
-
return
|
|
71
|
+
if (analyticsEnabled) {
|
|
72
|
+
return analytics();
|
|
72
73
|
}
|
|
73
74
|
return null;
|
|
74
|
-
}, [analyticsEnabled
|
|
75
|
+
}, [analyticsEnabled]);
|
|
75
76
|
const internalRemoteConfig = useMemo(() => {
|
|
76
77
|
if (remoteConfigEnabled) {
|
|
77
|
-
const localRemoteConfig =
|
|
78
|
+
const localRemoteConfig = remoteConfig();
|
|
78
79
|
if (remoteConfigSettings) {
|
|
79
80
|
localRemoteConfig.settings.fetchTimeMillis = remoteConfigSettings.fetchTimeMillis;
|
|
80
81
|
localRemoteConfig.settings.minimumFetchIntervalMillis = remoteConfigSettings.minimumFetchIntervalMillis;
|
|
@@ -83,7 +84,7 @@ export const FirebaseContextProvider = ({ emulators, options, children, authEnab
|
|
|
83
84
|
return localRemoteConfig;
|
|
84
85
|
}
|
|
85
86
|
return null;
|
|
86
|
-
}, [remoteConfigEnabled, remoteConfigSettings,
|
|
87
|
+
}, [remoteConfigEnabled, remoteConfigSettings, remoteConfigDefaults]);
|
|
87
88
|
const contextValue = useMemo(() => ({
|
|
88
89
|
firebase: internalFirebase,
|
|
89
90
|
auth: internalAuth,
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import React, { PropsWithChildren, useEffect, useMemo } from "react";
|
|
2
2
|
import { FirebaseContext, FirebaseContextValue } from "./FirebaseContext";
|
|
3
|
-
import { connectAuthEmulator } from "@react-native-firebase/auth";
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
import auth, { connectAuthEmulator } from "@react-native-firebase/auth";
|
|
4
|
+
import analytics, {
|
|
5
|
+
FirebaseAnalyticsTypes,
|
|
6
|
+
setAnalyticsCollectionEnabled,
|
|
7
|
+
setConsent
|
|
8
|
+
} from "@react-native-firebase/analytics";
|
|
9
|
+
import remoteConfig, { FirebaseRemoteConfigTypes } from "@react-native-firebase/remote-config";
|
|
10
|
+
import firestore, { connectFirestoreEmulator } from "@react-native-firebase/firestore";
|
|
7
11
|
import firebase, { ReactNativeFirebase } from "@react-native-firebase/app";
|
|
8
12
|
|
|
9
13
|
/**
|
|
@@ -67,7 +71,6 @@ export type FirebaseContextProviderEmulators = {
|
|
|
67
71
|
* @inline
|
|
68
72
|
*/
|
|
69
73
|
export type FirebaseContextProviderProps = PropsWithChildren & {
|
|
70
|
-
platform: "Web" | "ReactNative";
|
|
71
74
|
/**
|
|
72
75
|
* Defines configuration for firebase emulators
|
|
73
76
|
*/
|
|
@@ -75,7 +78,7 @@ export type FirebaseContextProviderProps = PropsWithChildren & {
|
|
|
75
78
|
/**
|
|
76
79
|
* Configuration options for Firebase initialization. {@link https://firebase.google.com/docs/web/setup#config-object | Learn about the Firebase config object}
|
|
77
80
|
*/
|
|
78
|
-
options
|
|
81
|
+
options?: ReactNativeFirebase.FirebaseAppOptions;
|
|
79
82
|
/**
|
|
80
83
|
* Flag indicating whether Firebase Auth should be enabled.
|
|
81
84
|
*/
|
|
@@ -151,7 +154,6 @@ export type FirebaseContextProviderProps = PropsWithChildren & {
|
|
|
151
154
|
*/
|
|
152
155
|
export const FirebaseContextProvider: React.FC<FirebaseContextProviderProps> = ({
|
|
153
156
|
emulators,
|
|
154
|
-
options,
|
|
155
157
|
children,
|
|
156
158
|
authEnabled = true,
|
|
157
159
|
firestoreEnabled = true,
|
|
@@ -165,7 +167,7 @@ export const FirebaseContextProvider: React.FC<FirebaseContextProviderProps> = (
|
|
|
165
167
|
const internalFirebase = useMemo(() => firebase, []);
|
|
166
168
|
|
|
167
169
|
useEffect(() => {
|
|
168
|
-
setConsent(
|
|
170
|
+
setConsent(analytics(), {
|
|
169
171
|
ad_personalization: false,
|
|
170
172
|
ad_storage: false,
|
|
171
173
|
ad_user_data: false,
|
|
@@ -180,14 +182,10 @@ export const FirebaseContextProvider: React.FC<FirebaseContextProviderProps> = (
|
|
|
180
182
|
const internalFirestore = useMemo(() => {
|
|
181
183
|
if (firestoreEnabled) {
|
|
182
184
|
if (emulators?.firestore?.host && emulators?.firestore?.port) {
|
|
183
|
-
connectFirestoreEmulator(
|
|
184
|
-
internalFirebase.firestore(),
|
|
185
|
-
emulators.firestore.host,
|
|
186
|
-
emulators.firestore.port
|
|
187
|
-
);
|
|
185
|
+
connectFirestoreEmulator(firestore(), emulators.firestore.host, emulators.firestore.port);
|
|
188
186
|
}
|
|
189
187
|
|
|
190
|
-
const localFirestore =
|
|
188
|
+
const localFirestore = firestore();
|
|
191
189
|
if (firestoreSettings) {
|
|
192
190
|
localFirestore.settings(firestoreSettings);
|
|
193
191
|
}
|
|
@@ -195,11 +193,11 @@ export const FirebaseContextProvider: React.FC<FirebaseContextProviderProps> = (
|
|
|
195
193
|
}
|
|
196
194
|
|
|
197
195
|
return null;
|
|
198
|
-
}, [emulators?.firestore, firestoreEnabled,
|
|
196
|
+
}, [emulators?.firestore, firestoreEnabled, firestoreSettings]);
|
|
199
197
|
|
|
200
198
|
const internalAuth = useMemo(() => {
|
|
201
199
|
if (authEnabled) {
|
|
202
|
-
const localAuth =
|
|
200
|
+
const localAuth = auth();
|
|
203
201
|
if (emulators?.auth?.host) {
|
|
204
202
|
connectAuthEmulator(localAuth, emulators?.auth?.host, {
|
|
205
203
|
disableWarnings: true
|
|
@@ -208,18 +206,18 @@ export const FirebaseContextProvider: React.FC<FirebaseContextProviderProps> = (
|
|
|
208
206
|
return localAuth;
|
|
209
207
|
}
|
|
210
208
|
return null;
|
|
211
|
-
}, [emulators?.auth, authEnabled
|
|
209
|
+
}, [emulators?.auth, authEnabled]);
|
|
212
210
|
|
|
213
211
|
const internalAnalytics = useMemo(() => {
|
|
214
|
-
if (analyticsEnabled
|
|
215
|
-
return
|
|
212
|
+
if (analyticsEnabled) {
|
|
213
|
+
return analytics();
|
|
216
214
|
}
|
|
217
215
|
return null;
|
|
218
|
-
}, [analyticsEnabled
|
|
216
|
+
}, [analyticsEnabled]);
|
|
219
217
|
|
|
220
218
|
const internalRemoteConfig = useMemo(() => {
|
|
221
219
|
if (remoteConfigEnabled) {
|
|
222
|
-
const localRemoteConfig =
|
|
220
|
+
const localRemoteConfig = remoteConfig();
|
|
223
221
|
if (remoteConfigSettings) {
|
|
224
222
|
localRemoteConfig.settings.fetchTimeMillis = remoteConfigSettings.fetchTimeMillis;
|
|
225
223
|
localRemoteConfig.settings.minimumFetchIntervalMillis = remoteConfigSettings.minimumFetchIntervalMillis;
|
|
@@ -228,7 +226,7 @@ export const FirebaseContextProvider: React.FC<FirebaseContextProviderProps> = (
|
|
|
228
226
|
return localRemoteConfig;
|
|
229
227
|
}
|
|
230
228
|
return null;
|
|
231
|
-
}, [remoteConfigEnabled, remoteConfigSettings,
|
|
229
|
+
}, [remoteConfigEnabled, remoteConfigSettings, remoteConfigDefaults]);
|
|
232
230
|
|
|
233
231
|
const contextValue = useMemo(
|
|
234
232
|
() => ({
|
|
@@ -36,5 +36,5 @@ export declare const buildCompositeFilter: <DbModelType extends CompositeFilterD
|
|
|
36
36
|
*
|
|
37
37
|
* @returns {(Function|undefined)} A composite query filter constraint function formed by combining subqueries or undefined if there are no valid constraints.
|
|
38
38
|
*/
|
|
39
|
-
export declare const useCompositeFilter: <DbModelType extends CompositeFilterDocumentData = CompositeFilterDocumentData>({ query }: UseCompositeFilter<DbModelType>) => FirebaseFirestoreTypes.
|
|
39
|
+
export declare const useCompositeFilter: <DbModelType extends CompositeFilterDocumentData = CompositeFilterDocumentData>({ query }: UseCompositeFilter<DbModelType>) => FirebaseFirestoreTypes.QueryFilterConstraint | undefined;
|
|
40
40
|
export {};
|
|
@@ -13,6 +13,9 @@ export const buildCompositeFilter = (query) => {
|
|
|
13
13
|
if (queryConstraints.length <= 0) {
|
|
14
14
|
return null;
|
|
15
15
|
}
|
|
16
|
+
if (queryConstraints.length <= 1) {
|
|
17
|
+
return queryConstraints[0];
|
|
18
|
+
}
|
|
16
19
|
return query.operator === "OR" ? or(...queryConstraints) : and(...queryConstraints);
|
|
17
20
|
}
|
|
18
21
|
if (query.field && query.op) {
|
|
@@ -37,6 +40,9 @@ export const useCompositeFilter = ({ query }) => {
|
|
|
37
40
|
if (queryConstraints.length <= 0) {
|
|
38
41
|
return undefined;
|
|
39
42
|
}
|
|
43
|
+
if (queryConstraints.length <= 1) {
|
|
44
|
+
return queryConstraints[0];
|
|
45
|
+
}
|
|
40
46
|
return query?.operator === "OR" ? or(...queryConstraints) : and(...queryConstraints);
|
|
41
47
|
}, [query]);
|
|
42
48
|
};
|
|
@@ -38,6 +38,10 @@ export const buildCompositeFilter = <DbModelType extends CompositeFilterDocument
|
|
|
38
38
|
return null;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
if (queryConstraints.length <= 1) {
|
|
42
|
+
return queryConstraints[0];
|
|
43
|
+
}
|
|
44
|
+
|
|
41
45
|
return (query as CompositeFilter).operator === "OR" ? or(...queryConstraints) : and(...queryConstraints);
|
|
42
46
|
}
|
|
43
47
|
|
|
@@ -73,6 +77,11 @@ export const useCompositeFilter = <DbModelType extends CompositeFilterDocumentDa
|
|
|
73
77
|
if (queryConstraints.length <= 0) {
|
|
74
78
|
return undefined;
|
|
75
79
|
}
|
|
80
|
+
|
|
81
|
+
if (queryConstraints.length <= 1) {
|
|
82
|
+
return queryConstraints[0];
|
|
83
|
+
}
|
|
84
|
+
|
|
76
85
|
return query?.operator === "OR" ? or(...queryConstraints) : and(...queryConstraints);
|
|
77
86
|
}, [query]);
|
|
78
87
|
};
|