react-query-firebase 1.3.2 → 2.0.0-rc1
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/dist/src/analytics/useAnalytics.d.ts +1 -1
- package/dist/src/analytics/useLogEvent.js +1 -1
- package/dist/src/analytics/useSetAnalyticsCollectionEnabled.js +1 -1
- package/dist/src/auth/index.d.ts +0 -1
- package/dist/src/auth/index.js +0 -1
- package/dist/src/auth/useAuth.d.ts +1 -1
- package/dist/src/auth/useCreateUserWitEmailAndPasswordMutation.d.ts +5 -5
- package/dist/src/auth/useCreateUserWitEmailAndPasswordMutation.js +3 -3
- package/dist/src/auth/useCurrentUser.d.ts +1 -1
- package/dist/src/auth/useCurrentUser.js +4 -4
- package/dist/src/auth/useIdToken.d.ts +26 -8
- package/dist/src/auth/useIdToken.js +21 -7
- package/dist/src/auth/useReauthenticateWitCredentialMutation.d.ts +7 -7
- package/dist/src/auth/useReauthenticateWitCredentialMutation.js +3 -3
- package/dist/src/auth/useReauthenticateWitRedirectMutation.d.ts +7 -7
- package/dist/src/auth/useReauthenticateWitRedirectMutation.js +3 -3
- package/dist/src/auth/useSendEmailVerificationMutation.d.ts +6 -6
- package/dist/src/auth/useSendEmailVerificationMutation.js +3 -3
- package/dist/src/auth/useSignInWitEmailAndPasswordMutation.d.ts +4 -4
- package/dist/src/auth/useSignInWitEmailAndPasswordMutation.js +2 -2
- package/dist/src/auth/useSignInWitRedirectMutation.d.ts +6 -6
- package/dist/src/auth/useSignInWitRedirectMutation.js +3 -3
- package/dist/src/auth/useSignOutMutation.d.ts +4 -4
- package/dist/src/auth/useSignOutMutation.js +3 -3
- package/dist/src/auth/useUpdateProfileMutation.d.ts +6 -6
- package/dist/src/auth/useUpdateProfileMutation.js +3 -3
- package/dist/src/context/FirebaseContext.d.ts +6 -10
- package/dist/src/context/FirebaseContextProvider.d.ts +25 -7
- package/dist/src/context/FirebaseContextProvider.js +41 -41
- package/dist/src/firestore/useAddDocMutation.d.ts +7 -9
- package/dist/src/firestore/useAddDocMutation.js +4 -5
- package/dist/src/firestore/useBatchWrite.d.ts +5 -5
- package/dist/src/firestore/useBatchWrite.js +1 -1
- package/dist/src/firestore/useCollectionReference.d.ts +5 -5
- package/dist/src/firestore/useCollectionReference.js +3 -5
- package/dist/src/firestore/useCompositeFilter.d.ts +6 -6
- package/dist/src/firestore/useCompositeFilter.js +12 -9
- package/dist/src/firestore/useCountQuery.d.ts +7 -7
- package/dist/src/firestore/useCountQuery.js +3 -3
- package/dist/src/firestore/useDeleteDocMutation.d.ts +6 -6
- package/dist/src/firestore/useDeleteDocMutation.js +1 -1
- package/dist/src/firestore/useDocReference.d.ts +6 -6
- package/dist/src/firestore/useDocReference.js +6 -10
- package/dist/src/firestore/useDocReferences.d.ts +6 -6
- package/dist/src/firestore/useDocReferences.js +4 -6
- package/dist/src/firestore/useFirestore.d.ts +1 -1
- package/dist/src/firestore/useGetDocData.d.ts +5 -5
- package/dist/src/firestore/useGetRealtimeDocData.d.ts +7 -7
- package/dist/src/firestore/useGetRealtimeDocData.js +1 -1
- package/dist/src/firestore/useInfiniteQuery.d.ts +5 -6
- package/dist/src/firestore/useInfiniteQuery.js +3 -3
- package/dist/src/firestore/useQuery.d.ts +7 -8
- package/dist/src/firestore/useQuery.js +5 -5
- package/dist/src/firestore/useRunTransaction.d.ts +5 -5
- package/dist/src/firestore/useRunTransaction.js +1 -1
- package/dist/src/firestore/useSetDocMutation.d.ts +7 -7
- package/dist/src/firestore/useSetDocMutation.js +2 -2
- package/dist/src/firestore/useUpdateDocMutation.d.ts +7 -8
- package/dist/src/firestore/useUpdateDocMutation.js +4 -4
- package/dist/src/firestore/utils/getDocData.d.ts +3 -3
- package/dist/src/firestore/utils/getDocData.js +1 -1
- package/dist/src/firestore/utils/getDocRef.d.ts +8 -8
- package/dist/src/firestore/utils/getDocRef.js +5 -9
- package/dist/src/firestore/utils/getDocSnap.d.ts +4 -4
- package/dist/src/firestore/utils/getDocSnap.js +2 -2
- package/dist/src/remoteConfig/useFetchAndActivate.js +1 -1
- package/dist/src/remoteConfig/useGetValue.d.ts +1 -1
- package/dist/src/remoteConfig/useGetValue.js +1 -1
- package/dist/src/remoteConfig/useRemoteConfig.d.ts +1 -1
- package/package.json +15 -5
- package/src/analytics/useLogEvent.ts +1 -1
- package/src/analytics/useSetAnalyticsCollectionEnabled.ts +1 -1
- package/src/auth/index.ts +0 -1
- package/src/auth/useCreateUserWitEmailAndPasswordMutation.ts +10 -5
- package/src/auth/useCurrentUser.ts +4 -4
- package/src/auth/useIdToken.ts +31 -9
- package/src/auth/useReauthenticateWitCredentialMutation.ts +12 -7
- package/src/auth/useReauthenticateWitRedirectMutation.ts +12 -7
- package/src/auth/useSendEmailVerificationMutation.ts +11 -6
- package/src/auth/useSignInWitEmailAndPasswordMutation.ts +9 -4
- package/src/auth/useSignInWitRedirectMutation.ts +11 -6
- package/src/auth/useSignOutMutation.ts +5 -5
- package/src/auth/useUpdateProfileMutation.ts +6 -6
- package/src/context/FirebaseContext.ts +6 -10
- package/src/context/FirebaseContextProvider.tsx +71 -44
- package/src/firestore/useAddDocMutation.ts +15 -22
- package/src/firestore/useBatchWrite.ts +7 -4
- package/src/firestore/useCollectionReference.ts +13 -9
- package/src/firestore/useCompositeFilter.ts +22 -27
- package/src/firestore/useCountQuery.ts +9 -13
- package/src/firestore/useDeleteDocMutation.ts +11 -10
- package/src/firestore/useDocReference.ts +23 -19
- package/src/firestore/useDocReferences.ts +15 -11
- package/src/firestore/useGetDocData.ts +14 -15
- package/src/firestore/useGetRealtimeDocData.ts +16 -10
- package/src/firestore/useInfiniteQuery.ts +9 -16
- package/src/firestore/useQuery.ts +11 -20
- package/src/firestore/useRunTransaction.ts +9 -4
- package/src/firestore/useSetDocMutation.ts +14 -11
- package/src/firestore/useUpdateDocMutation.ts +15 -21
- package/src/firestore/utils/getDocData.ts +7 -9
- package/src/firestore/utils/getDocRef.ts +13 -17
- package/src/firestore/utils/getDocSnap.ts +7 -9
- package/src/remoteConfig/useFetchAndActivate.ts +1 -1
- package/src/remoteConfig/useGetValue.ts +1 -1
- package/dist/src/auth/useAuthStateReady.d.ts +0 -6
- package/dist/src/auth/useAuthStateReady.js +0 -19
- package/src/auth/useAuthStateReady.ts +0 -24
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import React, { useEffect, useMemo } from "react";
|
|
2
2
|
import { FirebaseContext } from "./FirebaseContext";
|
|
3
|
-
import { connectAuthEmulator
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { initializeApp } from "firebase/app";
|
|
3
|
+
import { connectAuthEmulator } from "@react-native-firebase/auth";
|
|
4
|
+
import { setAnalyticsCollectionEnabled, setConsent } from "@react-native-firebase/analytics";
|
|
5
|
+
import { connectFirestoreEmulator } from "@react-native-firebase/firestore";
|
|
6
|
+
import firebase, { initializeApp } from "@react-native-firebase/app";
|
|
8
7
|
/**
|
|
9
8
|
* FirebaseContextProvider component configures and provides Firebase services to its children.
|
|
10
9
|
* Initializes Firebase app and enables optional Firebase services such as Firestore, Auth, Analytics,
|
|
@@ -28,35 +27,34 @@ import { initializeApp } from "firebase/app";
|
|
|
28
27
|
* };
|
|
29
28
|
* ```
|
|
30
29
|
*/
|
|
31
|
-
export const FirebaseContextProvider = ({ emulators, options, children, authEnabled = true, firestoreEnabled = true, analyticsEnabled = true, consentSettings = {}, remoteConfigEnabled = true, remoteConfigSettings, remoteConfigDefaults = {}, firestoreSettings }) => {
|
|
32
|
-
const
|
|
33
|
-
return initializeApp(options);
|
|
30
|
+
export const FirebaseContextProvider = ({ platform, emulators, options, children, authEnabled = true, firestoreEnabled = true, analyticsEnabled = true, consentSettings = {}, remoteConfigEnabled = true, remoteConfigSettings, remoteConfigDefaults = {}, firestoreSettings }) => {
|
|
31
|
+
const internalFirebase = useMemo(() => {
|
|
32
|
+
return platform === "Web" ? initializeApp(options) : firebase;
|
|
34
33
|
}, [options]);
|
|
35
34
|
useEffect(() => {
|
|
36
|
-
setConsent({
|
|
37
|
-
ad_personalization:
|
|
38
|
-
ad_storage:
|
|
39
|
-
ad_user_data:
|
|
40
|
-
analytics_storage:
|
|
41
|
-
functionality_storage:
|
|
42
|
-
personalization_storage:
|
|
43
|
-
security_storage:
|
|
35
|
+
setConsent(firebase.analytics(), {
|
|
36
|
+
ad_personalization: false,
|
|
37
|
+
ad_storage: false,
|
|
38
|
+
ad_user_data: false,
|
|
39
|
+
analytics_storage: false,
|
|
40
|
+
functionality_storage: false,
|
|
41
|
+
personalization_storage: false,
|
|
42
|
+
security_storage: false,
|
|
44
43
|
...consentSettings
|
|
45
44
|
});
|
|
46
|
-
}, [consentSettings]);
|
|
47
|
-
const
|
|
45
|
+
}, [consentSettings, firebase]);
|
|
46
|
+
const internalFirestore = useMemo(() => {
|
|
48
47
|
if (firestoreEnabled) {
|
|
49
|
-
const localFirestore = initializeFirestore(firebase, firestoreSettings || {});
|
|
50
48
|
if (emulators?.firestore?.host && emulators?.firestore?.port) {
|
|
51
|
-
connectFirestoreEmulator(
|
|
49
|
+
connectFirestoreEmulator(internalFirebase.firestore(), emulators.firestore.host, emulators.firestore.port);
|
|
52
50
|
}
|
|
53
|
-
return
|
|
51
|
+
return internalFirebase.firestore();
|
|
54
52
|
}
|
|
55
53
|
return null;
|
|
56
|
-
}, [firestoreSettings, emulators?.firestore, firestoreEnabled]);
|
|
57
|
-
const
|
|
54
|
+
}, [firestoreSettings, emulators?.firestore, firestoreEnabled, internalFirebase]);
|
|
55
|
+
const internalAuth = useMemo(() => {
|
|
58
56
|
if (authEnabled) {
|
|
59
|
-
const localAuth =
|
|
57
|
+
const localAuth = internalFirebase.auth();
|
|
60
58
|
if (emulators?.auth?.host) {
|
|
61
59
|
connectAuthEmulator(localAuth, emulators?.auth?.host, {
|
|
62
60
|
disableWarnings: true
|
|
@@ -65,35 +63,37 @@ export const FirebaseContextProvider = ({ emulators, options, children, authEnab
|
|
|
65
63
|
return localAuth;
|
|
66
64
|
}
|
|
67
65
|
return null;
|
|
68
|
-
}, [emulators?.auth, authEnabled]);
|
|
69
|
-
const
|
|
70
|
-
if (analyticsEnabled &&
|
|
71
|
-
|
|
66
|
+
}, [emulators?.auth, authEnabled, internalFirebase]);
|
|
67
|
+
const internalAnalytics = useMemo(() => {
|
|
68
|
+
if (analyticsEnabled &&
|
|
69
|
+
options.measurementId &&
|
|
70
|
+
(typeof window !== "undefined" || platform === "ReactNative")) {
|
|
71
|
+
return internalFirebase.analytics();
|
|
72
72
|
}
|
|
73
73
|
return null;
|
|
74
|
-
}, [analyticsEnabled, options.measurementId]);
|
|
75
|
-
const
|
|
76
|
-
if (remoteConfigEnabled && typeof window !== "undefined") {
|
|
77
|
-
const localRemoteConfig =
|
|
74
|
+
}, [analyticsEnabled, options.measurementId, internalFirebase]);
|
|
75
|
+
const internalRemoteConfig = useMemo(() => {
|
|
76
|
+
if (remoteConfigEnabled && (typeof window !== "undefined" || platform === "ReactNative")) {
|
|
77
|
+
const localRemoteConfig = internalFirebase.remoteConfig();
|
|
78
78
|
if (remoteConfigSettings) {
|
|
79
|
-
localRemoteConfig.settings.
|
|
79
|
+
localRemoteConfig.settings.fetchTimeMillis = remoteConfigSettings.fetchTimeMillis;
|
|
80
80
|
localRemoteConfig.settings.minimumFetchIntervalMillis = remoteConfigSettings.minimumFetchIntervalMillis;
|
|
81
81
|
localRemoteConfig.defaultConfig = remoteConfigDefaults;
|
|
82
82
|
}
|
|
83
83
|
return localRemoteConfig;
|
|
84
84
|
}
|
|
85
85
|
return null;
|
|
86
|
-
}, [remoteConfigEnabled]);
|
|
86
|
+
}, [remoteConfigEnabled, remoteConfigSettings, internalFirebase]);
|
|
87
87
|
const contextValue = useMemo(() => ({
|
|
88
|
-
firebase,
|
|
89
|
-
auth,
|
|
90
|
-
analytics,
|
|
91
|
-
firestore,
|
|
92
|
-
remoteConfig
|
|
93
|
-
}), [
|
|
88
|
+
firebase: internalFirebase,
|
|
89
|
+
auth: internalAuth,
|
|
90
|
+
analytics: internalAnalytics,
|
|
91
|
+
firestore: internalFirestore,
|
|
92
|
+
remoteConfig: internalRemoteConfig
|
|
93
|
+
}), [internalFirebase, internalAuth, internalAnalytics, internalFirestore, internalRemoteConfig]);
|
|
94
94
|
useEffect(() => {
|
|
95
95
|
if (contextValue.analytics) {
|
|
96
|
-
setAnalyticsCollectionEnabled(contextValue.analytics, consentSettings?.analytics_storage
|
|
96
|
+
setAnalyticsCollectionEnabled(contextValue.analytics, !!consentSettings?.analytics_storage);
|
|
97
97
|
}
|
|
98
98
|
}, [consentSettings]);
|
|
99
99
|
return (React.createElement(FirebaseContext.Provider, { value: contextValue }, children));
|
|
@@ -1,23 +1,21 @@
|
|
|
1
1
|
import { UseMutationOptions } from "@tanstack/react-query";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { FirebaseFirestoreTypes, WithFieldValue } from "@react-native-firebase/firestore";
|
|
3
|
+
import { ReactNativeFirebase } from "@react-native-firebase/app";
|
|
4
4
|
export type UseAddDocMutationValues<AppModelType> = {
|
|
5
5
|
data: WithFieldValue<AppModelType>;
|
|
6
6
|
};
|
|
7
|
-
export type UseAddDocMutationOptions<AppModelType extends DocumentData = DocumentData,
|
|
8
|
-
reference: CollectionReference<AppModelType
|
|
9
|
-
|
|
10
|
-
options?: Omit<UseMutationOptions<AppModelType, FirebaseError, UseAddDocMutationValues<AppModelType>, TContext>, "mutationFn" | "mutationKey">;
|
|
7
|
+
export type UseAddDocMutationOptions<AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData, TContext = unknown> = {
|
|
8
|
+
reference: FirebaseFirestoreTypes.CollectionReference<AppModelType>;
|
|
9
|
+
options?: Omit<UseMutationOptions<AppModelType, ReactNativeFirebase.NativeFirebaseError, UseAddDocMutationValues<AppModelType>, TContext>, "mutationFn" | "mutationKey">;
|
|
11
10
|
};
|
|
12
11
|
/**
|
|
13
12
|
* Provides a mutation hook to add a document to a Firestore collection utilizing React Query's `useMutation`.
|
|
14
13
|
* It handles addition and optional conversion of the document data in Firestore.
|
|
15
14
|
*
|
|
16
15
|
* @param {Object} options - Options for the mutation hook
|
|
17
|
-
* @param {FirebaseFirestore.CollectionReference<AppModelType>} options.reference - Firestore collection reference where the document should be added.
|
|
18
|
-
* @param {FirebaseFirestore.FirestoreDataConverter<DbModelType>} [options.converter] - Optional data converter for reading and writing Firestore documents.
|
|
16
|
+
* @param {FirebaseFirestore.FirebaseFirestoreTypes.CollectionReference<AppModelType>} options.reference - Firestore collection reference where the document should be added.
|
|
19
17
|
* @param {UseMutationOptions<AppModelType, Error, { data: DbModelType }, TContext>} [options.options={}] - Optional configuration for the mutation.
|
|
20
18
|
*
|
|
21
19
|
* @returns {UseMutationResult<AppModelType, Error, { data: DbModelType }, TContext>} The mutation hook result containing status, error, and data of the mutation process.
|
|
22
20
|
*/
|
|
23
|
-
export declare const useAddDocMutation: <AppModelType extends DocumentData = DocumentData,
|
|
21
|
+
export declare const useAddDocMutation: <AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData, TContext = unknown>({ reference, options }: UseAddDocMutationOptions<AppModelType, TContext>) => import("@tanstack/react-query").UseMutationResult<AppModelType, ReactNativeFirebase.NativeFirebaseError, UseAddDocMutationValues<AppModelType>, TContext>;
|
|
@@ -1,24 +1,23 @@
|
|
|
1
1
|
import { useMutation } from "@tanstack/react-query";
|
|
2
|
-
import { addDoc, getDoc } from "firebase/firestore";
|
|
2
|
+
import { addDoc, getDoc } from "@react-native-firebase/firestore";
|
|
3
3
|
import { useMemo } from "react";
|
|
4
4
|
/**
|
|
5
5
|
* Provides a mutation hook to add a document to a Firestore collection utilizing React Query's `useMutation`.
|
|
6
6
|
* It handles addition and optional conversion of the document data in Firestore.
|
|
7
7
|
*
|
|
8
8
|
* @param {Object} options - Options for the mutation hook
|
|
9
|
-
* @param {FirebaseFirestore.CollectionReference<AppModelType>} options.reference - Firestore collection reference where the document should be added.
|
|
10
|
-
* @param {FirebaseFirestore.FirestoreDataConverter<DbModelType>} [options.converter] - Optional data converter for reading and writing Firestore documents.
|
|
9
|
+
* @param {FirebaseFirestore.FirebaseFirestoreTypes.CollectionReference<AppModelType>} options.reference - Firestore collection reference where the document should be added.
|
|
11
10
|
* @param {UseMutationOptions<AppModelType, Error, { data: DbModelType }, TContext>} [options.options={}] - Optional configuration for the mutation.
|
|
12
11
|
*
|
|
13
12
|
* @returns {UseMutationResult<AppModelType, Error, { data: DbModelType }, TContext>} The mutation hook result containing status, error, and data of the mutation process.
|
|
14
13
|
*/
|
|
15
|
-
export const useAddDocMutation = ({ reference,
|
|
14
|
+
export const useAddDocMutation = ({ reference, options = {} }) => {
|
|
16
15
|
const mutationKey = useMemo(() => [reference.path], [reference.path]);
|
|
17
16
|
return useMutation({
|
|
18
17
|
...options,
|
|
19
18
|
mutationFn: async ({ data }) => {
|
|
20
19
|
const docRef = await addDoc(reference, data);
|
|
21
|
-
const docSnap = await getDoc(
|
|
20
|
+
const docSnap = await getDoc(docRef);
|
|
22
21
|
return docSnap.data();
|
|
23
22
|
},
|
|
24
23
|
mutationKey
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { UseMutationOptions } from "@tanstack/react-query";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
export type UseBatchWriteVariables = (batch: WriteBatch) => Promise<void> | void;
|
|
2
|
+
import { FirebaseFirestoreTypes } from "@react-native-firebase/firestore";
|
|
3
|
+
import { ReactNativeFirebase } from "@react-native-firebase/app";
|
|
4
|
+
export type UseBatchWriteVariables = (batch: FirebaseFirestoreTypes.WriteBatch) => Promise<void> | void;
|
|
5
5
|
export type UseBatchWriteOptions<TContext = unknown> = {
|
|
6
|
-
options?: Omit<UseMutationOptions<void,
|
|
6
|
+
options?: Omit<UseMutationOptions<void, ReactNativeFirebase.NativeFirebaseError, UseBatchWriteVariables, TContext>, "mutationFn">;
|
|
7
7
|
};
|
|
8
8
|
/**
|
|
9
9
|
* Custom hook to perform batch write operations using Firestore.
|
|
@@ -12,4 +12,4 @@ export type UseBatchWriteOptions<TContext = unknown> = {
|
|
|
12
12
|
* @param {Object} options - The configuration options for the mutation operation.
|
|
13
13
|
* @returns {Object} Returns an object composed of elements returned by useMutation, including properties such as status, and functions to trigger and control the mutation process.
|
|
14
14
|
*/
|
|
15
|
-
export declare const useBatchWrite: <TContext = unknown>({ options }?: UseBatchWriteOptions<TContext>) => import("@tanstack/react-query").UseMutationResult<void,
|
|
15
|
+
export declare const useBatchWrite: <TContext = unknown>({ options }?: UseBatchWriteOptions<TContext>) => import("@tanstack/react-query").UseMutationResult<void, ReactNativeFirebase.NativeFirebaseError, UseBatchWriteVariables, TContext>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useMutation } from "@tanstack/react-query";
|
|
2
|
-
import { writeBatch } from "firebase/firestore";
|
|
2
|
+
import { writeBatch } from "@react-native-firebase/firestore";
|
|
3
3
|
import { useFirestore } from "./useFirestore";
|
|
4
4
|
/**
|
|
5
5
|
* Custom hook to perform batch write operations using Firestore.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export type UseCollectionReferenceOptions<AppModelType
|
|
3
|
-
reference?: CollectionReference<AppModelType
|
|
1
|
+
import { FirebaseFirestoreTypes } from "@react-native-firebase/firestore";
|
|
2
|
+
export type UseCollectionReferenceOptions<AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData> = {
|
|
3
|
+
reference?: FirebaseFirestoreTypes.CollectionReference<AppModelType> | FirebaseFirestoreTypes.DocumentReference<AppModelType>;
|
|
4
4
|
path: string;
|
|
5
5
|
pathSegments?: string[];
|
|
6
6
|
};
|
|
@@ -9,10 +9,10 @@ export type UseCollectionReferenceOptions<AppModelType, DbModelType extends Docu
|
|
|
9
9
|
*
|
|
10
10
|
* This hook utilizes useMemo for optimization, ensuring the collection reference is recalculated only when its dependencies change.
|
|
11
11
|
*
|
|
12
|
-
* @param {UseCollectionReferenceOptions<AppModelType
|
|
12
|
+
* @param {UseCollectionReferenceOptions<AppModelType>} options - The options including path, reference, and pathSegments to construct the Firestore collection reference.
|
|
13
13
|
* @param {string} options.path - The base path for the collection.
|
|
14
14
|
* @param {FirestoreReference} options.reference - An optional Firestore reference object that should be of type "collection".
|
|
15
15
|
* @param {string[]} options.pathSegments - Additional path segments to append to the base path.
|
|
16
16
|
* @returns {CollectionReference} A Firestore collection reference constructed using the specified path, reference, and path segments.
|
|
17
17
|
*/
|
|
18
|
-
export declare const useCollectionReference: <AppModelType
|
|
18
|
+
export declare const useCollectionReference: <AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData>({ path, reference, pathSegments }: UseCollectionReferenceOptions<AppModelType>) => FirebaseFirestoreTypes.CollectionReference<FirebaseFirestoreTypes.DocumentData>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { collection } from "firebase/firestore";
|
|
1
|
+
import { collection } from "@react-native-firebase/firestore";
|
|
2
2
|
import { useMemo } from "react";
|
|
3
3
|
import { useFirestore } from "./useFirestore";
|
|
4
4
|
/**
|
|
@@ -6,7 +6,7 @@ import { useFirestore } from "./useFirestore";
|
|
|
6
6
|
*
|
|
7
7
|
* This hook utilizes useMemo for optimization, ensuring the collection reference is recalculated only when its dependencies change.
|
|
8
8
|
*
|
|
9
|
-
* @param {UseCollectionReferenceOptions<AppModelType
|
|
9
|
+
* @param {UseCollectionReferenceOptions<AppModelType>} options - The options including path, reference, and pathSegments to construct the Firestore collection reference.
|
|
10
10
|
* @param {string} options.path - The base path for the collection.
|
|
11
11
|
* @param {FirestoreReference} options.reference - An optional Firestore reference object that should be of type "collection".
|
|
12
12
|
* @param {string[]} options.pathSegments - Additional path segments to append to the base path.
|
|
@@ -17,8 +17,6 @@ export const useCollectionReference = ({ path, reference, pathSegments }) => {
|
|
|
17
17
|
return useMemo(() => {
|
|
18
18
|
return !reference
|
|
19
19
|
? collection(db, path || "", ...(pathSegments || []))
|
|
20
|
-
: reference
|
|
21
|
-
? collection(reference, path, ...(pathSegments || []))
|
|
22
|
-
: collection(reference, path, ...(pathSegments || []));
|
|
20
|
+
: collection(reference, path, ...(pathSegments || []));
|
|
23
21
|
}, [path, reference?.path, pathSegments]);
|
|
24
22
|
};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type CompositeFilterDocumentData = DocumentData;
|
|
3
|
-
export type QueryElement<DbModelType extends CompositeFilterDocumentData = CompositeFilterDocumentData> = Partial<QueryCompositeFilterConstraint> & {
|
|
1
|
+
import { FirebaseFirestoreTypes } from "@react-native-firebase/firestore";
|
|
2
|
+
type CompositeFilterDocumentData = FirebaseFirestoreTypes.DocumentData;
|
|
3
|
+
export type QueryElement<DbModelType extends CompositeFilterDocumentData = CompositeFilterDocumentData> = Partial<FirebaseFirestoreTypes.QueryCompositeFilterConstraint> & {
|
|
4
4
|
children?: QueryElement[];
|
|
5
5
|
field?: keyof (DbModelType & {
|
|
6
6
|
documentId?: string[];
|
|
7
7
|
});
|
|
8
8
|
value?: DbModelType[keyof DbModelType];
|
|
9
|
-
op?: WhereFilterOp;
|
|
9
|
+
op?: FirebaseFirestoreTypes.WhereFilterOp;
|
|
10
10
|
};
|
|
11
|
-
export type CompositeFilter<DbModelType extends CompositeFilterDocumentData = CompositeFilterDocumentData> = QueryCompositeFilterConstraint & {
|
|
11
|
+
export type CompositeFilter<DbModelType extends CompositeFilterDocumentData = CompositeFilterDocumentData> = FirebaseFirestoreTypes.QueryCompositeFilterConstraint & {
|
|
12
12
|
children: QueryElement<DbModelType & {
|
|
13
13
|
documentId?: string[];
|
|
14
14
|
}>[];
|
|
@@ -26,5 +26,5 @@ export type UseCompositeFilter<DbModelType extends CompositeFilterDocumentData =
|
|
|
26
26
|
*
|
|
27
27
|
* @returns {(Function|undefined)} A composite query filter constraint function formed by combining subqueries or undefined if there are no valid constraints.
|
|
28
28
|
*/
|
|
29
|
-
export declare const useCompositeFilter: <DbModelType extends CompositeFilterDocumentData =
|
|
29
|
+
export declare const useCompositeFilter: <DbModelType extends CompositeFilterDocumentData = CompositeFilterDocumentData>({ query }: UseCompositeFilter<DbModelType>) => FirebaseFirestoreTypes.QueryCompositeFilterConstraint | undefined;
|
|
30
30
|
export {};
|
|
@@ -1,24 +1,26 @@
|
|
|
1
|
-
import { and,
|
|
1
|
+
import firebase, { and, or, where } from "@react-native-firebase/firestore";
|
|
2
2
|
import { useMemo } from "react";
|
|
3
3
|
/**
|
|
4
4
|
* Constructs a composite query filter based on the provided query structure.
|
|
5
5
|
* It recursively builds query constraints using logical "or" or "and" operators.
|
|
6
6
|
*
|
|
7
7
|
* @param {QueryElement<DbModelType>} query - The query element or structure to be evaluated and transformed into filter constraints.
|
|
8
|
-
* @returns {
|
|
8
|
+
* @returns {QueryFieldFilterConstraint | null} A constructed query filter constraint based on the input query, or null if no valid constraints can be derived.
|
|
9
9
|
*/
|
|
10
10
|
const buildCompositeQuery = (query) => {
|
|
11
11
|
if (query.children) {
|
|
12
12
|
const queryConstraints = query.children
|
|
13
|
-
.map((subQuery) =>
|
|
13
|
+
.map((subQuery) => {
|
|
14
|
+
if (subQuery.field && subQuery.op) {
|
|
15
|
+
return where(query.field === "documentId" ? firebase.FieldPath.documentId() : query.field, subQuery.op, query.value);
|
|
16
|
+
}
|
|
17
|
+
return buildCompositeQuery(subQuery);
|
|
18
|
+
})
|
|
14
19
|
.filter((constraint) => !!constraint);
|
|
15
20
|
if (queryConstraints.length <= 0) {
|
|
16
21
|
return null;
|
|
17
22
|
}
|
|
18
|
-
return query.
|
|
19
|
-
}
|
|
20
|
-
if (query.field && query.op) {
|
|
21
|
-
return where(query.field === "documentId" ? documentId() : query.field, query.op, query.value);
|
|
23
|
+
return query.operator === "OR" ? or(...queryConstraints) : and(...queryConstraints);
|
|
22
24
|
}
|
|
23
25
|
return null;
|
|
24
26
|
};
|
|
@@ -34,10 +36,11 @@ const buildCompositeQuery = (query) => {
|
|
|
34
36
|
*/
|
|
35
37
|
export const useCompositeFilter = ({ query }) => {
|
|
36
38
|
return useMemo(() => {
|
|
37
|
-
const queryConstraints = (query?.children?.map?.((subQuery) => buildCompositeQuery(subQuery))
|
|
39
|
+
const queryConstraints = (query?.children?.map?.((subQuery) => buildCompositeQuery(subQuery))
|
|
40
|
+
?.filter)?.((constraint) => !!constraint) ?? [];
|
|
38
41
|
if (queryConstraints.length <= 0) {
|
|
39
42
|
return undefined;
|
|
40
43
|
}
|
|
41
|
-
return query?.
|
|
44
|
+
return query?.operator === "OR" ? or(...queryConstraints) : and(...queryConstraints);
|
|
42
45
|
}, [query]);
|
|
43
46
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FirebaseFirestoreTypes, QueryConstraint, QueryNonFilterConstraint } from "@react-native-firebase/firestore";
|
|
2
2
|
import { UseQueryResult, UseQueryOptions as UseReactQueryOptions } from "@tanstack/react-query";
|
|
3
|
-
type UseCountQueryOptions<AppModelType extends DocumentData = DocumentData
|
|
3
|
+
type UseCountQueryOptions<AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData> = {
|
|
4
4
|
options: Omit<UseReactQueryOptions<number, Error, number>, "queryFn"> & Required<Pick<UseReactQueryOptions<number, Error, number>, "queryKey">>;
|
|
5
|
-
query: Query<AppModelType
|
|
5
|
+
query: FirebaseFirestoreTypes.Query<AppModelType>;
|
|
6
6
|
queryConstraints?: QueryConstraint[] | QueryNonFilterConstraint[];
|
|
7
|
-
compositeFilter?: QueryCompositeFilterConstraint;
|
|
7
|
+
compositeFilter?: FirebaseFirestoreTypes.QueryCompositeFilterConstraint;
|
|
8
8
|
};
|
|
9
9
|
/**
|
|
10
10
|
* Executes a query with specified constraints and returns the count of matched documents.
|
|
@@ -12,12 +12,12 @@ type UseCountQueryOptions<AppModelType extends DocumentData = DocumentData, DbMo
|
|
|
12
12
|
* This function utilizes React Query to asynchronously fetch the count of documents from a server database
|
|
13
13
|
* that match the provided query constraints and an optional composite filter.
|
|
14
14
|
*
|
|
15
|
-
* @param {UseCountQueryOptions<AppModelType
|
|
16
|
-
* @param {AppModelType extends DocumentData = DocumentData} [options.options] - Additional options for the React Query.
|
|
15
|
+
* @param {UseCountQueryOptions<AppModelType>} options - Configuration options for the query.
|
|
16
|
+
* @param {AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData} [options.options] - Additional options for the React Query.
|
|
17
17
|
* @param {unknown} [options.query] - Reference to the query object to be executed.
|
|
18
18
|
* @param {unknown[]} [options.queryConstraints=[]] - An array of constraints to apply to the query.
|
|
19
19
|
* @param {unknown} [options.compositeFilter] - An optional composite filter to apply to the query.
|
|
20
20
|
* @returns {UseQueryResult<number>} An object containing the number of documents that match the query.
|
|
21
21
|
*/
|
|
22
|
-
export declare const useCountQuery: <AppModelType extends DocumentData = DocumentData
|
|
22
|
+
export declare const useCountQuery: <AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData>({ options, query: queryReference, queryConstraints, compositeFilter }: UseCountQueryOptions<AppModelType>) => UseQueryResult<number>;
|
|
23
23
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getCountFromServer, query } from "firebase/firestore";
|
|
1
|
+
import { getCountFromServer, query } from "@react-native-firebase/firestore";
|
|
2
2
|
import { useQuery as useReactQuery } from "@tanstack/react-query";
|
|
3
3
|
/**
|
|
4
4
|
* Executes a query with specified constraints and returns the count of matched documents.
|
|
@@ -6,8 +6,8 @@ import { useQuery as useReactQuery } from "@tanstack/react-query";
|
|
|
6
6
|
* This function utilizes React Query to asynchronously fetch the count of documents from a server database
|
|
7
7
|
* that match the provided query constraints and an optional composite filter.
|
|
8
8
|
*
|
|
9
|
-
* @param {UseCountQueryOptions<AppModelType
|
|
10
|
-
* @param {AppModelType extends DocumentData = DocumentData} [options.options] - Additional options for the React Query.
|
|
9
|
+
* @param {UseCountQueryOptions<AppModelType>} options - Configuration options for the query.
|
|
10
|
+
* @param {AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData} [options.options] - Additional options for the React Query.
|
|
11
11
|
* @param {unknown} [options.query] - Reference to the query object to be executed.
|
|
12
12
|
* @param {unknown[]} [options.queryConstraints=[]] - An array of constraints to apply to the query.
|
|
13
13
|
* @param {unknown} [options.compositeFilter] - An optional composite filter to apply to the query.
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { UseMutationOptions } from "@tanstack/react-query";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { FirebaseFirestoreTypes, WithFieldValue } from "@react-native-firebase/firestore";
|
|
3
|
+
import { ReactNativeFirebase } from "@react-native-firebase/app";
|
|
4
4
|
export type UseDeleteDocMutationValues<AppModelType> = {
|
|
5
5
|
data: WithFieldValue<AppModelType>;
|
|
6
6
|
};
|
|
7
|
-
export type UseDeleteDocMutationOptions<AppModelType extends DocumentData = DocumentData,
|
|
8
|
-
reference: DocumentReference<AppModelType
|
|
9
|
-
options?: Omit<UseMutationOptions<void,
|
|
7
|
+
export type UseDeleteDocMutationOptions<AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData, TContext = unknown> = {
|
|
8
|
+
reference: FirebaseFirestoreTypes.DocumentReference<AppModelType> | null;
|
|
9
|
+
options?: Omit<UseMutationOptions<void, ReactNativeFirebase.NativeFirebaseError, void, TContext>, "mutationFn" | "mutationKey">;
|
|
10
10
|
};
|
|
11
11
|
/**
|
|
12
12
|
* A custom hook that provides a mutation function to delete a document from the database.
|
|
@@ -15,4 +15,4 @@ export type UseDeleteDocMutationOptions<AppModelType extends DocumentData = Docu
|
|
|
15
15
|
* @param {object} options.options - Additional options for the mutation, if any (default is an empty object).
|
|
16
16
|
* @returns {UseMutationResult} An object returned by the `useMutation` hook which includes properties and methods to control the mutation's execution and track its state.
|
|
17
17
|
*/
|
|
18
|
-
export declare const useDeleteDocMutation: <AppModelType extends DocumentData = DocumentData,
|
|
18
|
+
export declare const useDeleteDocMutation: <AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData, TContext = unknown>({ reference, options }: UseDeleteDocMutationOptions<AppModelType, TContext>) => import("@tanstack/react-query").UseMutationResult<void, ReactNativeFirebase.NativeFirebaseError, void, TContext>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useMutation } from "@tanstack/react-query";
|
|
2
|
-
import { deleteDoc } from "firebase/firestore";
|
|
2
|
+
import { deleteDoc } from "@react-native-firebase/firestore";
|
|
3
3
|
import { useMemo } from "react";
|
|
4
4
|
/**
|
|
5
5
|
* A custom hook that provides a mutation function to delete a document from the database.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export type UseDocReferenceOptions<AppModelType
|
|
3
|
-
reference?: CollectionReference<AppModelType
|
|
1
|
+
import { FirebaseFirestoreTypes } from "@react-native-firebase/firestore";
|
|
2
|
+
export type UseDocReferenceOptions<AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData> = {
|
|
3
|
+
reference?: FirebaseFirestoreTypes.CollectionReference<AppModelType> | FirebaseFirestoreTypes.DocumentReference<AppModelType>;
|
|
4
4
|
path?: string;
|
|
5
5
|
pathSegments?: string[];
|
|
6
6
|
};
|
|
@@ -9,11 +9,11 @@ export type UseDocReferenceOptions<AppModelType, DbModelType extends DocumentDat
|
|
|
9
9
|
* This hook facilitates the retrieval of a Firestore document reference based on given options such as path and reference data.
|
|
10
10
|
* The reference is updated whenever the associated path, reference, or path segments change.
|
|
11
11
|
*
|
|
12
|
-
* @param {UseDocReferenceOptions<AppModelType
|
|
12
|
+
* @param {UseDocReferenceOptions<AppModelType>} options - Configuration options for setting up the document reference.
|
|
13
13
|
* @param {string} options.path - The path to the Firestore document.
|
|
14
14
|
* @param {DbModelType} options.reference - Reference data for the document, providing additional context or specifics.
|
|
15
15
|
* @param {string[]} options.pathSegments - Parts of the path to construct the full document path dynamically.
|
|
16
16
|
*
|
|
17
|
-
* @returns {DocumentReference<AppModelType
|
|
17
|
+
* @returns {DocumentReference<AppModelType> | null} The Firestore document reference corresponding to the provided path and options, or null if not initialized.
|
|
18
18
|
*/
|
|
19
|
-
export declare const useDocReference: <AppModelType
|
|
19
|
+
export declare const useDocReference: <AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData>({ path, reference, pathSegments }: UseDocReferenceOptions<AppModelType>) => FirebaseFirestoreTypes.DocumentReference<AppModelType> | null;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { doc } from "firebase/firestore";
|
|
1
|
+
import { doc } from "@react-native-firebase/firestore";
|
|
2
2
|
import { useEffect, useRef } from "react";
|
|
3
3
|
import { useFirestore } from "./useFirestore";
|
|
4
4
|
/**
|
|
@@ -6,34 +6,30 @@ import { useFirestore } from "./useFirestore";
|
|
|
6
6
|
* If a reference is not provided, it constructs a document reference using the Firestore instance, path, and path segments.
|
|
7
7
|
*
|
|
8
8
|
* @param {Firestore} db - The Firestore database instance used to create the document reference.
|
|
9
|
-
* @param {UseDocReferenceOptions<AppModelType
|
|
9
|
+
* @param {UseDocReferenceOptions<AppModelType>} options - An object containing the path, path segments, and optional reference.
|
|
10
10
|
* @param {string} options.path - The path to the document in the Firestore database.
|
|
11
11
|
* @param {string[]} [options.pathSegments] - Optional additional segments to join with the path.
|
|
12
12
|
* @param {DocumentReference | CollectionReference} [options.reference] - Optional Firestore reference object that influences how the document reference is constructed.
|
|
13
13
|
*
|
|
14
|
-
* @returns {DocumentReference<AppModelType
|
|
14
|
+
* @returns {DocumentReference<AppModelType> | null} A Firestore document reference if the path is specified; otherwise, returns null if path is not provided.
|
|
15
15
|
*/
|
|
16
16
|
const getDocReference = (db, { path, pathSegments, reference }) => {
|
|
17
17
|
if (!path) {
|
|
18
18
|
return null;
|
|
19
19
|
}
|
|
20
|
-
return (!reference
|
|
21
|
-
? doc(db, path || "", ...(pathSegments || []))
|
|
22
|
-
: reference.type === "collection"
|
|
23
|
-
? doc(reference, path, ...(pathSegments || []))
|
|
24
|
-
: doc(reference, path, ...(pathSegments || [])));
|
|
20
|
+
return (!reference ? doc(db, path || "", ...(pathSegments || [])) : doc(reference, path, ...(pathSegments || [])));
|
|
25
21
|
};
|
|
26
22
|
/**
|
|
27
23
|
* Custom hook to generate and manage a Firestore document reference.
|
|
28
24
|
* This hook facilitates the retrieval of a Firestore document reference based on given options such as path and reference data.
|
|
29
25
|
* The reference is updated whenever the associated path, reference, or path segments change.
|
|
30
26
|
*
|
|
31
|
-
* @param {UseDocReferenceOptions<AppModelType
|
|
27
|
+
* @param {UseDocReferenceOptions<AppModelType>} options - Configuration options for setting up the document reference.
|
|
32
28
|
* @param {string} options.path - The path to the Firestore document.
|
|
33
29
|
* @param {DbModelType} options.reference - Reference data for the document, providing additional context or specifics.
|
|
34
30
|
* @param {string[]} options.pathSegments - Parts of the path to construct the full document path dynamically.
|
|
35
31
|
*
|
|
36
|
-
* @returns {DocumentReference<AppModelType
|
|
32
|
+
* @returns {DocumentReference<AppModelType> | null} The Firestore document reference corresponding to the provided path and options, or null if not initialized.
|
|
37
33
|
*/
|
|
38
34
|
export const useDocReference = ({ path, reference, pathSegments }) => {
|
|
39
35
|
const db = useFirestore();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export type UseDocReferencesOptions<AppModelType
|
|
3
|
-
reference?: CollectionReference<AppModelType
|
|
1
|
+
import { FirebaseFirestoreTypes } from "@react-native-firebase/firestore";
|
|
2
|
+
export type UseDocReferencesOptions<AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData> = {
|
|
3
|
+
reference?: FirebaseFirestoreTypes.CollectionReference<AppModelType> | FirebaseFirestoreTypes.DocumentReference<AppModelType>;
|
|
4
4
|
path: string;
|
|
5
5
|
pathSegments?: string[];
|
|
6
6
|
};
|
|
@@ -14,10 +14,10 @@ export type UseDocReferencesOptions<AppModelType, DbModelType extends DocumentDa
|
|
|
14
14
|
* to interact with the Firestore database documents. It uses memoization to optimize
|
|
15
15
|
* reference generation.
|
|
16
16
|
*
|
|
17
|
-
* @param {UseDocReferencesOptions<AppModelType
|
|
17
|
+
* @param {UseDocReferencesOptions<AppModelType>[]} references - An array of options
|
|
18
18
|
* specifying how to generate document references. Each option may include a `path`
|
|
19
19
|
* as a string, a `reference` as a Firestore reference, and `pathSegments` as an array of strings.
|
|
20
|
-
* @returns {DocumentReference<AppModelType
|
|
20
|
+
* @returns {DocumentReference<AppModelType>[]} An array of Firestore document references
|
|
21
21
|
* generated from the options provided.
|
|
22
22
|
*/
|
|
23
|
-
export declare const useDocReferences: <AppModelType
|
|
23
|
+
export declare const useDocReferences: <AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData>(references: UseDocReferencesOptions<AppModelType>[]) => FirebaseFirestoreTypes.DocumentReference<AppModelType>[];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { doc } from "firebase/firestore";
|
|
1
|
+
import { doc } from "@react-native-firebase/firestore";
|
|
2
2
|
import { useMemo } from "react";
|
|
3
3
|
import { useFirestore } from "./useFirestore";
|
|
4
4
|
/**
|
|
@@ -11,10 +11,10 @@ import { useFirestore } from "./useFirestore";
|
|
|
11
11
|
* to interact with the Firestore database documents. It uses memoization to optimize
|
|
12
12
|
* reference generation.
|
|
13
13
|
*
|
|
14
|
-
* @param {UseDocReferencesOptions<AppModelType
|
|
14
|
+
* @param {UseDocReferencesOptions<AppModelType>[]} references - An array of options
|
|
15
15
|
* specifying how to generate document references. Each option may include a `path`
|
|
16
16
|
* as a string, a `reference` as a Firestore reference, and `pathSegments` as an array of strings.
|
|
17
|
-
* @returns {DocumentReference<AppModelType
|
|
17
|
+
* @returns {DocumentReference<AppModelType>[]} An array of Firestore document references
|
|
18
18
|
* generated from the options provided.
|
|
19
19
|
*/
|
|
20
20
|
export const useDocReferences = (references) => {
|
|
@@ -23,9 +23,7 @@ export const useDocReferences = (references) => {
|
|
|
23
23
|
return references.map(({ path, reference, pathSegments }) => {
|
|
24
24
|
return (!reference
|
|
25
25
|
? doc(db, path || "", ...(pathSegments || []))
|
|
26
|
-
: reference
|
|
27
|
-
? doc(reference, path, ...(pathSegments || []))
|
|
28
|
-
: doc(reference, path, ...(pathSegments || [])));
|
|
26
|
+
: doc(reference, path, ...(pathSegments || [])));
|
|
29
27
|
});
|
|
30
28
|
}, [references]);
|
|
31
29
|
};
|
|
@@ -4,4 +4,4 @@
|
|
|
4
4
|
*
|
|
5
5
|
* @returns {firestore.Firestore} The Firestore instance from the Firebase context.
|
|
6
6
|
*/
|
|
7
|
-
export declare const useFirestore: () => import("@firebase/firestore").
|
|
7
|
+
export declare const useFirestore: () => import("@react-native-firebase/firestore").FirebaseFirestoreTypes.Module;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FirebaseFirestoreTypes } from "@react-native-firebase/firestore";
|
|
2
2
|
import { UseQueryOptions } from "@tanstack/react-query";
|
|
3
|
-
type UseGetDocOptions<AppModelType extends DocumentData = DocumentData
|
|
4
|
-
options: Omit<UseQueryOptions<AppModelType | null, Error, AppModelType>, "queryFn"> & Required<Pick<UseQueryOptions<AppModelType, Error, AppModelType>, "queryKey">>;
|
|
3
|
+
type UseGetDocOptions<AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData> = {
|
|
4
|
+
options: Omit<UseQueryOptions<AppModelType | null | undefined, Error, AppModelType>, "queryFn"> & Required<Pick<UseQueryOptions<AppModelType, Error, AppModelType>, "queryKey">>;
|
|
5
5
|
path?: string;
|
|
6
6
|
pathSegments?: string[];
|
|
7
|
-
reference: CollectionReference<AppModelType
|
|
7
|
+
reference: FirebaseFirestoreTypes.CollectionReference<AppModelType> | FirebaseFirestoreTypes.DocumentReference<AppModelType>;
|
|
8
8
|
};
|
|
9
9
|
/**
|
|
10
10
|
* Custom React Hook to retrieve document data from Firestore using specified parameters.
|
|
@@ -14,5 +14,5 @@ type UseGetDocOptions<AppModelType extends DocumentData = DocumentData, DbModelT
|
|
|
14
14
|
* @param {Array<string>} pathSegments - Segments of the path to document in Firestore.
|
|
15
15
|
* @returns {Object} Result of the query containing document data and query status.
|
|
16
16
|
*/
|
|
17
|
-
export declare const useGetDocData: <AppModelType extends DocumentData = DocumentData
|
|
17
|
+
export declare const useGetDocData: <AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData>({ options, reference, path, pathSegments }: UseGetDocOptions<AppModelType>) => import("@tanstack/react-query").UseQueryResult<AppModelType, Error>;
|
|
18
18
|
export {};
|