react-query-firebase 2.0.3 → 2.1.1

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.
Files changed (182) hide show
  1. package/package.json +3 -2
  2. package/react-native/firestore/index.ts +1 -0
  3. package/react-native/firestore/useCompositeFilter.ts +3 -3
  4. package/react-native/firestore/useQueryConstraints.ts +84 -0
  5. package/react-native/index.d.ts +0 -4
  6. package/react-native/index.js +0 -4
  7. package/react-native/index.ts +0 -4
  8. package/types/AppModel.ts +7 -0
  9. package/types/QueryConstraints.ts +58 -0
  10. package/types/index.ts +2 -0
  11. package/web/firestore/index.ts +1 -0
  12. package/web/firestore/useCompositeFilter.ts +3 -3
  13. package/web/firestore/useQueryConstraints.ts +93 -0
  14. package/web/index.d.ts +0 -4
  15. package/web/index.js +0 -4
  16. package/web/index.ts +0 -4
  17. package/react-native/analytics/index.d.ts +0 -3
  18. package/react-native/analytics/index.js +0 -3
  19. package/react-native/analytics/useAnalytics.d.ts +0 -5
  20. package/react-native/analytics/useAnalytics.js +0 -10
  21. package/react-native/analytics/useLogEvent.d.ts +0 -17
  22. package/react-native/analytics/useLogEvent.js +0 -21
  23. package/react-native/analytics/useSetAnalyticsCollectionEnabled.d.ts +0 -10
  24. package/react-native/analytics/useSetAnalyticsCollectionEnabled.js +0 -16
  25. package/react-native/auth/index.d.ts +0 -12
  26. package/react-native/auth/index.js +0 -12
  27. package/react-native/auth/mutation-keys.d.ts +0 -7
  28. package/react-native/auth/mutation-keys.js +0 -19
  29. package/react-native/auth/useAuth.d.ts +0 -5
  30. package/react-native/auth/useAuth.js +0 -10
  31. package/react-native/auth/useCreateUserWitEmailAndPasswordMutation.d.ts +0 -15
  32. package/react-native/auth/useCreateUserWitEmailAndPasswordMutation.js +0 -19
  33. package/react-native/auth/useCurrentUser.d.ts +0 -6
  34. package/react-native/auth/useCurrentUser.js +0 -20
  35. package/react-native/auth/useIdToken.d.ts +0 -30
  36. package/react-native/auth/useIdToken.js +0 -66
  37. package/react-native/auth/useReauthenticateWitCredentialMutation.d.ts +0 -16
  38. package/react-native/auth/useReauthenticateWitCredentialMutation.js +0 -18
  39. package/react-native/auth/useReauthenticateWitRedirectMutation.d.ts +0 -17
  40. package/react-native/auth/useReauthenticateWitRedirectMutation.js +0 -18
  41. package/react-native/auth/useSendEmailVerificationMutation.d.ts +0 -13
  42. package/react-native/auth/useSendEmailVerificationMutation.js +0 -16
  43. package/react-native/auth/useSignInWitEmailAndPasswordMutation.d.ts +0 -15
  44. package/react-native/auth/useSignInWitEmailAndPasswordMutation.js +0 -19
  45. package/react-native/auth/useSignInWitRedirectMutation.d.ts +0 -14
  46. package/react-native/auth/useSignInWitRedirectMutation.js +0 -18
  47. package/react-native/auth/useSignOutMutation.d.ts +0 -10
  48. package/react-native/auth/useSignOutMutation.js +0 -19
  49. package/react-native/auth/useUpdateProfileMutation.d.ts +0 -15
  50. package/react-native/auth/useUpdateProfileMutation.js +0 -17
  51. package/react-native/firestore/index.d.ts +0 -16
  52. package/react-native/firestore/index.js +0 -16
  53. package/react-native/firestore/useAddDocMutation.d.ts +0 -21
  54. package/react-native/firestore/useAddDocMutation.js +0 -25
  55. package/react-native/firestore/useBatchWrite.d.ts +0 -15
  56. package/react-native/firestore/useBatchWrite.js +0 -21
  57. package/react-native/firestore/useCollectionReference.d.ts +0 -18
  58. package/react-native/firestore/useCollectionReference.js +0 -22
  59. package/react-native/firestore/useCompositeFilter.d.ts +0 -32
  60. package/react-native/firestore/useCompositeFilter.js +0 -42
  61. package/react-native/firestore/useCountQuery.d.ts +0 -23
  62. package/react-native/firestore/useCountQuery.js +0 -30
  63. package/react-native/firestore/useDeleteDocMutation.d.ts +0 -18
  64. package/react-native/firestore/useDeleteDocMutation.js +0 -23
  65. package/react-native/firestore/useDocReference.d.ts +0 -19
  66. package/react-native/firestore/useDocReference.js +0 -36
  67. package/react-native/firestore/useDocReferences.d.ts +0 -23
  68. package/react-native/firestore/useDocReferences.js +0 -29
  69. package/react-native/firestore/useFirestore.d.ts +0 -7
  70. package/react-native/firestore/useFirestore.js +0 -12
  71. package/react-native/firestore/useGetDocData.d.ts +0 -18
  72. package/react-native/firestore/useGetDocData.js +0 -18
  73. package/react-native/firestore/useGetRealtimeDocData.d.ts +0 -57
  74. package/react-native/firestore/useGetRealtimeDocData.js +0 -56
  75. package/react-native/firestore/useInfiniteQuery.d.ts +0 -17
  76. package/react-native/firestore/useInfiniteQuery.js +0 -28
  77. package/react-native/firestore/useQuery.d.ts +0 -24
  78. package/react-native/firestore/useQuery.js +0 -34
  79. package/react-native/firestore/useRunTransaction.d.ts +0 -15
  80. package/react-native/firestore/useRunTransaction.js +0 -19
  81. package/react-native/firestore/useSetDocMutation.d.ts +0 -20
  82. package/react-native/firestore/useSetDocMutation.js +0 -25
  83. package/react-native/firestore/useUpdateDocMutation.d.ts +0 -30
  84. package/react-native/firestore/useUpdateDocMutation.js +0 -37
  85. package/react-native/firestore/utils/getDocData.d.ts +0 -18
  86. package/react-native/firestore/utils/getDocData.js +0 -22
  87. package/react-native/firestore/utils/getDocRef.d.ts +0 -19
  88. package/react-native/firestore/utils/getDocRef.js +0 -21
  89. package/react-native/firestore/utils/getDocSnap.d.ts +0 -20
  90. package/react-native/firestore/utils/getDocSnap.js +0 -25
  91. package/react-native/remoteConfig/index.d.ts +0 -3
  92. package/react-native/remoteConfig/index.js +0 -3
  93. package/react-native/remoteConfig/useFetchAndActivate.d.ts +0 -11
  94. package/react-native/remoteConfig/useFetchAndActivate.js +0 -31
  95. package/react-native/remoteConfig/useGetValue.d.ts +0 -7
  96. package/react-native/remoteConfig/useGetValue.js +0 -15
  97. package/react-native/remoteConfig/useRemoteConfig.d.ts +0 -5
  98. package/react-native/remoteConfig/useRemoteConfig.js +0 -10
  99. package/web/analytics/index.d.ts +0 -3
  100. package/web/analytics/index.js +0 -3
  101. package/web/analytics/useAnalytics.d.ts +0 -5
  102. package/web/analytics/useAnalytics.js +0 -10
  103. package/web/analytics/useLogEvent.d.ts +0 -17
  104. package/web/analytics/useLogEvent.js +0 -21
  105. package/web/analytics/useSetAnalyticsCollectionEnabled.d.ts +0 -10
  106. package/web/analytics/useSetAnalyticsCollectionEnabled.js +0 -16
  107. package/web/auth/index.d.ts +0 -13
  108. package/web/auth/index.js +0 -13
  109. package/web/auth/mutation-keys.d.ts +0 -7
  110. package/web/auth/mutation-keys.js +0 -19
  111. package/web/auth/useAuth.d.ts +0 -5
  112. package/web/auth/useAuth.js +0 -10
  113. package/web/auth/useAuthStateReady.d.ts +0 -6
  114. package/web/auth/useAuthStateReady.js +0 -19
  115. package/web/auth/useCreateUserWitEmailAndPasswordMutation.d.ts +0 -15
  116. package/web/auth/useCreateUserWitEmailAndPasswordMutation.js +0 -19
  117. package/web/auth/useCurrentUser.d.ts +0 -6
  118. package/web/auth/useCurrentUser.js +0 -20
  119. package/web/auth/useIdToken.d.ts +0 -30
  120. package/web/auth/useIdToken.js +0 -66
  121. package/web/auth/useReauthenticateWitCredentialMutation.d.ts +0 -16
  122. package/web/auth/useReauthenticateWitCredentialMutation.js +0 -18
  123. package/web/auth/useReauthenticateWitRedirectMutation.d.ts +0 -17
  124. package/web/auth/useReauthenticateWitRedirectMutation.js +0 -18
  125. package/web/auth/useSendEmailVerificationMutation.d.ts +0 -13
  126. package/web/auth/useSendEmailVerificationMutation.js +0 -16
  127. package/web/auth/useSignInWitEmailAndPasswordMutation.d.ts +0 -15
  128. package/web/auth/useSignInWitEmailAndPasswordMutation.js +0 -19
  129. package/web/auth/useSignInWitRedirectMutation.d.ts +0 -14
  130. package/web/auth/useSignInWitRedirectMutation.js +0 -18
  131. package/web/auth/useSignOutMutation.d.ts +0 -10
  132. package/web/auth/useSignOutMutation.js +0 -19
  133. package/web/auth/useUpdateProfileMutation.d.ts +0 -15
  134. package/web/auth/useUpdateProfileMutation.js +0 -17
  135. package/web/firestore/index.d.ts +0 -16
  136. package/web/firestore/index.js +0 -16
  137. package/web/firestore/useAddDocMutation.d.ts +0 -23
  138. package/web/firestore/useAddDocMutation.js +0 -26
  139. package/web/firestore/useBatchWrite.d.ts +0 -15
  140. package/web/firestore/useBatchWrite.js +0 -21
  141. package/web/firestore/useCollectionReference.d.ts +0 -18
  142. package/web/firestore/useCollectionReference.js +0 -24
  143. package/web/firestore/useCompositeFilter.d.ts +0 -32
  144. package/web/firestore/useCompositeFilter.js +0 -41
  145. package/web/firestore/useCountQuery.d.ts +0 -23
  146. package/web/firestore/useCountQuery.js +0 -30
  147. package/web/firestore/useDeleteDocMutation.d.ts +0 -18
  148. package/web/firestore/useDeleteDocMutation.js +0 -23
  149. package/web/firestore/useDocReference.d.ts +0 -19
  150. package/web/firestore/useDocReference.js +0 -45
  151. package/web/firestore/useDocReferences.d.ts +0 -23
  152. package/web/firestore/useDocReferences.js +0 -31
  153. package/web/firestore/useFirestore.d.ts +0 -7
  154. package/web/firestore/useFirestore.js +0 -12
  155. package/web/firestore/useGetDocData.d.ts +0 -18
  156. package/web/firestore/useGetDocData.js +0 -18
  157. package/web/firestore/useGetRealtimeDocData.d.ts +0 -57
  158. package/web/firestore/useGetRealtimeDocData.js +0 -56
  159. package/web/firestore/useInfiniteQuery.d.ts +0 -18
  160. package/web/firestore/useInfiniteQuery.js +0 -28
  161. package/web/firestore/useQuery.d.ts +0 -25
  162. package/web/firestore/useQuery.js +0 -34
  163. package/web/firestore/useRunTransaction.d.ts +0 -15
  164. package/web/firestore/useRunTransaction.js +0 -19
  165. package/web/firestore/useSetDocMutation.d.ts +0 -20
  166. package/web/firestore/useSetDocMutation.js +0 -25
  167. package/web/firestore/useUpdateDocMutation.d.ts +0 -31
  168. package/web/firestore/useUpdateDocMutation.js +0 -37
  169. package/web/firestore/utils/getDocData.d.ts +0 -18
  170. package/web/firestore/utils/getDocData.js +0 -22
  171. package/web/firestore/utils/getDocRef.d.ts +0 -19
  172. package/web/firestore/utils/getDocRef.js +0 -25
  173. package/web/firestore/utils/getDocSnap.d.ts +0 -20
  174. package/web/firestore/utils/getDocSnap.js +0 -25
  175. package/web/remoteConfig/index.d.ts +0 -3
  176. package/web/remoteConfig/index.js +0 -3
  177. package/web/remoteConfig/useFetchAndActivate.d.ts +0 -11
  178. package/web/remoteConfig/useFetchAndActivate.js +0 -31
  179. package/web/remoteConfig/useGetValue.d.ts +0 -7
  180. package/web/remoteConfig/useGetValue.js +0 -15
  181. package/web/remoteConfig/useRemoteConfig.d.ts +0 -5
  182. package/web/remoteConfig/useRemoteConfig.js +0 -10
@@ -1,66 +0,0 @@
1
- import { useCallback, useEffect, useState } from "react";
2
- import { useCurrentUser } from "./useCurrentUser";
3
- import { onIdTokenChanged } from "@react-native-firebase/auth";
4
- import { useAuth } from "./useAuth";
5
- /**
6
- * A hook to manage the ID token.
7
- * It monitors changes to the ID token and provides the token itself along with a refresh method to update the token when needed.
8
- *
9
- * @group Hook
10
- *
11
- * @returns {UseIdTokenResult}
12
- *
13
- * @example
14
- * ```jsx
15
- * export const MyComponent = () => {
16
- * const result = useIdToken();
17
- * useEffect(() => {
18
- * const timeout = setTimeout(() => {
19
- * result.refresh();
20
- * }, 5000);
21
- * return () => clearTimeout();
22
- * }, [])
23
- * console.log(resilt.idToken);
24
- * };
25
- * ```
26
- */
27
- export const useIdToken = () => {
28
- const auth = useAuth();
29
- const currentUser = useCurrentUser();
30
- const [idToken, setIdToken] = useState("");
31
- const callback = useCallback(async () => {
32
- if (!currentUser) {
33
- setIdToken("");
34
- return;
35
- }
36
- const idToken = await currentUser.getIdToken();
37
- setIdToken(idToken);
38
- }, [currentUser]);
39
- const refresh = useCallback(async () => {
40
- if (!currentUser) {
41
- return;
42
- }
43
- const idToken = await currentUser.getIdToken(true);
44
- return idToken;
45
- }, [currentUser]);
46
- useEffect(() => {
47
- callback();
48
- }, [callback]);
49
- useEffect(() => {
50
- const unsubscribe = onIdTokenChanged(auth, (user) => {
51
- if (user) {
52
- user.getIdToken().then((idToken) => {
53
- setIdToken(idToken);
54
- });
55
- }
56
- else {
57
- setIdToken("");
58
- }
59
- });
60
- return () => unsubscribe();
61
- }, [auth]);
62
- return {
63
- idToken,
64
- refresh
65
- };
66
- };
@@ -1,16 +0,0 @@
1
- import { UseMutationOptions } from "@tanstack/react-query";
2
- import { FirebaseAuthTypes } from "@react-native-firebase/auth";
3
- import { ReactNativeFirebase } from "@react-native-firebase/app";
4
- export type UseReauthenticateWitCredentialMutationVariables = {
5
- credential: FirebaseAuthTypes.AuthCredential;
6
- user: FirebaseAuthTypes.User;
7
- };
8
- /**
9
- * Custom hook to create a mutation for re-authenticating a user with a given credential.
10
- * This hook utilizes useMutation from React Query to manage the asynchronous re-authentication
11
- * process with Firebase credentials. It omits the default "mutationKey" and "mutationFn" options.
12
- *
13
- * @param {Omit<UseMutationOptions<FirebaseAuthTypes.UserCredential, ReactNativeFirebase.NativeFirebaseError, UseReauthenticateWitCredentialMutationVariables, TContext>, "mutationKey" | "mutationFn">} options - Optional mutation options excluding "mutationKey" and "mutationFn".
14
- * @returns {UseMutationResult<FirebaseAuthTypes.UserCredential, ReactNativeFirebase.NativeFirebaseError, UseReauthenticateWitCredentialMutationVariables, TContext>} A useMutation result object managing the loading, error, and result state of the re-authentication mutation.
15
- */
16
- export declare const useReauthenticateWitCredentialMutation: <TContext = unknown>(options?: Omit<UseMutationOptions<FirebaseAuthTypes.UserCredential, ReactNativeFirebase.NativeFirebaseError, UseReauthenticateWitCredentialMutationVariables, TContext>, "mutationKey" | "mutationFn">) => import("@tanstack/react-query").UseMutationResult<FirebaseAuthTypes.UserCredential, ReactNativeFirebase.NativeFirebaseError, UseReauthenticateWitCredentialMutationVariables, TContext>;
@@ -1,18 +0,0 @@
1
- import { useMutation } from "@tanstack/react-query";
2
- import { reauthenticateWithCredential } from "@react-native-firebase/auth";
3
- import { REAUTHENTICATE_WITH_CREDENTIAL_MUTATION_KEY } from "./mutation-keys";
4
- /**
5
- * Custom hook to create a mutation for re-authenticating a user with a given credential.
6
- * This hook utilizes useMutation from React Query to manage the asynchronous re-authentication
7
- * process with Firebase credentials. It omits the default "mutationKey" and "mutationFn" options.
8
- *
9
- * @param {Omit<UseMutationOptions<FirebaseAuthTypes.UserCredential, ReactNativeFirebase.NativeFirebaseError, UseReauthenticateWitCredentialMutationVariables, TContext>, "mutationKey" | "mutationFn">} options - Optional mutation options excluding "mutationKey" and "mutationFn".
10
- * @returns {UseMutationResult<FirebaseAuthTypes.UserCredential, ReactNativeFirebase.NativeFirebaseError, UseReauthenticateWitCredentialMutationVariables, TContext>} A useMutation result object managing the loading, error, and result state of the re-authentication mutation.
11
- */
12
- export const useReauthenticateWitCredentialMutation = (options = {}) => {
13
- return useMutation({
14
- ...options,
15
- mutationFn: async ({ credential, user }) => reauthenticateWithCredential(user, credential),
16
- mutationKey: REAUTHENTICATE_WITH_CREDENTIAL_MUTATION_KEY
17
- });
18
- };
@@ -1,17 +0,0 @@
1
- import { UseMutationOptions } from "@tanstack/react-query";
2
- import { FirebaseAuthTypes, PopupRedirectResolver } from "@react-native-firebase/auth";
3
- import { ReactNativeFirebase } from "@react-native-firebase/app";
4
- export type UseReauthenticateWitRedirectMutationVariables = {
5
- authProvider: FirebaseAuthTypes.AuthProvider;
6
- popupRedirectResolver?: PopupRedirectResolver;
7
- user: FirebaseAuthTypes.User;
8
- };
9
- /**
10
- * Custom hook that provides a mutation to reauthenticate a user with a given authentication provider using redirection.
11
- * This hook uses the `useMutation` hook from the React Query library to handle async mutation logic.
12
- *
13
- * @param {Omit<UseMutationOptions<void, ReactNativeFirebase.NativeFirebaseError, UseReauthenticateWitRedirectMutationVariables, TContext>, "mutationKey" | "mutationFn">} options - Optional configuration object for the mutation. It provides the ability to pass options to customize the behavior of the mutation.
14
- * @template TContext - The type of any additional context you wish to pass to the mutation.
15
- * @returns {UseMutationResult<void, ReactNativeFirebase.NativeFirebaseError, UseReauthenticateWitRedirectMutationVariables, TContext>} A mutation result object containing methods and state of the mutation.
16
- */
17
- export declare const useReauthenticateWitRedirectMutation: <TContext = unknown>(options?: Omit<UseMutationOptions<void, ReactNativeFirebase.NativeFirebaseError, UseReauthenticateWitRedirectMutationVariables, TContext>, "mutationKey" | "mutationFn">) => import("@tanstack/react-query").UseMutationResult<void, ReactNativeFirebase.NativeFirebaseError, UseReauthenticateWitRedirectMutationVariables, TContext>;
@@ -1,18 +0,0 @@
1
- import { useMutation } from "@tanstack/react-query";
2
- import { reauthenticateWithRedirect } from "@react-native-firebase/auth";
3
- import { REAUTHENTICATE_WITH_REDIRECT_MUTATION_KEY } from "./mutation-keys";
4
- /**
5
- * Custom hook that provides a mutation to reauthenticate a user with a given authentication provider using redirection.
6
- * This hook uses the `useMutation` hook from the React Query library to handle async mutation logic.
7
- *
8
- * @param {Omit<UseMutationOptions<void, ReactNativeFirebase.NativeFirebaseError, UseReauthenticateWitRedirectMutationVariables, TContext>, "mutationKey" | "mutationFn">} options - Optional configuration object for the mutation. It provides the ability to pass options to customize the behavior of the mutation.
9
- * @template TContext - The type of any additional context you wish to pass to the mutation.
10
- * @returns {UseMutationResult<void, ReactNativeFirebase.NativeFirebaseError, UseReauthenticateWitRedirectMutationVariables, TContext>} A mutation result object containing methods and state of the mutation.
11
- */
12
- export const useReauthenticateWitRedirectMutation = (options = {}) => {
13
- return useMutation({
14
- ...options,
15
- mutationFn: async ({ authProvider, user, popupRedirectResolver }) => reauthenticateWithRedirect(user, authProvider, popupRedirectResolver),
16
- mutationKey: REAUTHENTICATE_WITH_REDIRECT_MUTATION_KEY
17
- });
18
- };
@@ -1,13 +0,0 @@
1
- import { UseMutationOptions } from "@tanstack/react-query";
2
- import { FirebaseAuthTypes } from "@react-native-firebase/auth";
3
- import { ReactNativeFirebase } from "@react-native-firebase/app";
4
- export type UseSendEmailVerificationMutationVariables = {
5
- user: FirebaseAuthTypes.User;
6
- };
7
- /**
8
- * A custom hook to create a mutation for sending an email verification to a user using Firebase.
9
- * This uses the `useMutation` hook from a query library and wraps it with specific configuration options.
10
- * @param {Omit<UseMutationOptions<void, ReactNativeFirebase.NativeReactNativeFirebase.NativeFirebaseError, UseSendEmailVerificationMutationVariables, TContext>, "queryKey" | "queryFn">} options - Configuration options for the mutation, excluding `queryKey` and `queryFn`.
11
- * @returns {UseMutationResult<void, NativeReactNativeFirebase.NativeFirebaseError, UseSendEmailVerificationMutationVariables, TContext>} An object containing mutation state and functions for managing the mutation lifecycle.
12
- */
13
- export declare const useSendEmailVerificationMutation: <TContext = unknown>(options?: Omit<UseMutationOptions<void, ReactNativeFirebase.NativeFirebaseError, UseSendEmailVerificationMutationVariables, TContext>, "queryKey" | "queryFn">) => import("@tanstack/react-query").UseMutationResult<void, ReactNativeFirebase.NativeFirebaseError, UseSendEmailVerificationMutationVariables, TContext>;
@@ -1,16 +0,0 @@
1
- import { useMutation } from "@tanstack/react-query";
2
- import { sendEmailVerification } from "@react-native-firebase/auth";
3
- import { SEND_EMAIL_VERIFICATION_MUTATION_KEY } from "./mutation-keys";
4
- /**
5
- * A custom hook to create a mutation for sending an email verification to a user using Firebase.
6
- * This uses the `useMutation` hook from a query library and wraps it with specific configuration options.
7
- * @param {Omit<UseMutationOptions<void, ReactNativeFirebase.NativeReactNativeFirebase.NativeFirebaseError, UseSendEmailVerificationMutationVariables, TContext>, "queryKey" | "queryFn">} options - Configuration options for the mutation, excluding `queryKey` and `queryFn`.
8
- * @returns {UseMutationResult<void, NativeReactNativeFirebase.NativeFirebaseError, UseSendEmailVerificationMutationVariables, TContext>} An object containing mutation state and functions for managing the mutation lifecycle.
9
- */
10
- export const useSendEmailVerificationMutation = (options = {}) => {
11
- return useMutation({
12
- ...options,
13
- mutationFn: async ({ user }) => await sendEmailVerification(user),
14
- mutationKey: SEND_EMAIL_VERIFICATION_MUTATION_KEY
15
- });
16
- };
@@ -1,15 +0,0 @@
1
- import { UseMutationOptions } from "@tanstack/react-query";
2
- import { FirebaseAuthTypes } from "@react-native-firebase/auth";
3
- import { ReactNativeFirebase } from "@react-native-firebase/app";
4
- export type UseSignInWitEmailAndPasswordMutationVariables = {
5
- email: string;
6
- password: string;
7
- };
8
- /**
9
- * Custom hook to perform a sign-in operation using email and password with Firebase Authentication.
10
- * It utilizes the `useMutation` hook to manage the asynchronous operation and its state.
11
- *
12
- * @param {Omit<UseMutationOptions<FirebaseAuthTypes.UserCredential, ReactNativeFirebase.NativeFirebaseError, UseSignInWitEmailAndPasswordMutationVariables, TContext>, 'mutationKey' | 'mutationFn'>} options - Options to configure the mutation, excluding 'mutationKey' and 'mutationFn'.
13
- * @returns {MutationResult} A mutation object containing the result of the sign-in process and helper functions.
14
- */
15
- export declare const useSignInWitEmailAndPasswordMutation: <TContext = unknown>(options?: Omit<UseMutationOptions<FirebaseAuthTypes.UserCredential, ReactNativeFirebase.NativeFirebaseError, UseSignInWitEmailAndPasswordMutationVariables, TContext>, "mutationKey" | "mutationFn">) => import("@tanstack/react-query").UseMutationResult<FirebaseAuthTypes.UserCredential, ReactNativeFirebase.NativeFirebaseError, UseSignInWitEmailAndPasswordMutationVariables, TContext>;
@@ -1,19 +0,0 @@
1
- import { useMutation } from "@tanstack/react-query";
2
- import { signInWithEmailAndPassword } from "@react-native-firebase/auth";
3
- import { useAuth } from "./useAuth";
4
- import { SIGN_IN_WITH_EMAIL_AND_PASSWORD_MUTATION_KEY } from "./mutation-keys";
5
- /**
6
- * Custom hook to perform a sign-in operation using email and password with Firebase Authentication.
7
- * It utilizes the `useMutation` hook to manage the asynchronous operation and its state.
8
- *
9
- * @param {Omit<UseMutationOptions<FirebaseAuthTypes.UserCredential, ReactNativeFirebase.NativeFirebaseError, UseSignInWitEmailAndPasswordMutationVariables, TContext>, 'mutationKey' | 'mutationFn'>} options - Options to configure the mutation, excluding 'mutationKey' and 'mutationFn'.
10
- * @returns {MutationResult} A mutation object containing the result of the sign-in process and helper functions.
11
- */
12
- export const useSignInWitEmailAndPasswordMutation = (options = {}) => {
13
- const firebaseAuth = useAuth();
14
- return useMutation({
15
- ...options,
16
- mutationFn: async ({ email, password }) => signInWithEmailAndPassword(firebaseAuth, email, password),
17
- mutationKey: SIGN_IN_WITH_EMAIL_AND_PASSWORD_MUTATION_KEY
18
- });
19
- };
@@ -1,14 +0,0 @@
1
- import { UseMutationOptions } from "@tanstack/react-query";
2
- import { FirebaseAuthTypes, PopupRedirectResolver } from "@react-native-firebase/auth";
3
- import { ReactNativeFirebase } from "@react-native-firebase/app";
4
- export type UseSignInWitRedirectMutationVariables = {
5
- authProvider: FirebaseAuthTypes.AuthProvider;
6
- popupRedirectResolver?: PopupRedirectResolver;
7
- };
8
- /**
9
- * Custom hook for handling Firebase authentication using sign-in with redirect functionality.
10
- * This hook utilizes the `useMutation` mechanism to perform the sign-in operation.
11
- * @param {Omit<UseMutationOptions<void, ReactNativeFirebase.NativeFirebaseError, UseSignInWitRedirectMutationVariables, TContext>, "mutationKey" | "mutationFn">} options - Optional configurations for the mutation, omitting the mutationKey and mutationFn properties.
12
- * @returns {UseMutationResult<void, ReactNativeFirebase.NativeFirebaseError, UseSignInWitRedirectMutationVariables, TContext>} The result object from the useMutation hook, containing the mutation function and its current state.
13
- */
14
- export declare const useSignInWitRedirectMutation: <TContext = unknown>(options?: Omit<UseMutationOptions<void, ReactNativeFirebase.NativeFirebaseError, UseSignInWitRedirectMutationVariables, TContext>, "mutationKey" | "mutationFn">) => import("@tanstack/react-query").UseMutationResult<void, ReactNativeFirebase.NativeFirebaseError, UseSignInWitRedirectMutationVariables, TContext>;
@@ -1,18 +0,0 @@
1
- import { useMutation } from "@tanstack/react-query";
2
- import { signInWithRedirect } from "@react-native-firebase/auth";
3
- import { useAuth } from "./useAuth";
4
- import { SIGN_IN_WITH_REDIRECT_MUTATION_KEY } from "./mutation-keys";
5
- /**
6
- * Custom hook for handling Firebase authentication using sign-in with redirect functionality.
7
- * This hook utilizes the `useMutation` mechanism to perform the sign-in operation.
8
- * @param {Omit<UseMutationOptions<void, ReactNativeFirebase.NativeFirebaseError, UseSignInWitRedirectMutationVariables, TContext>, "mutationKey" | "mutationFn">} options - Optional configurations for the mutation, omitting the mutationKey and mutationFn properties.
9
- * @returns {UseMutationResult<void, ReactNativeFirebase.NativeFirebaseError, UseSignInWitRedirectMutationVariables, TContext>} The result object from the useMutation hook, containing the mutation function and its current state.
10
- */
11
- export const useSignInWitRedirectMutation = (options = {}) => {
12
- const firebaseAuth = useAuth();
13
- return useMutation({
14
- ...options,
15
- mutationFn: async ({ authProvider, popupRedirectResolver }) => signInWithRedirect(firebaseAuth, authProvider, popupRedirectResolver),
16
- mutationKey: SIGN_IN_WITH_REDIRECT_MUTATION_KEY
17
- });
18
- };
@@ -1,10 +0,0 @@
1
- import { UseMutationOptions } from "@tanstack/react-query";
2
- import { ReactNativeFirebase } from "@react-native-firebase/app";
3
- /**
4
- * Custom hook for handling the sign-out mutation using Firebase authentication.
5
- * It wraps the useMutation hook to provide a sign-out function with Firebase.
6
- *
7
- * @param {Omit<UseMutationOptions<void, ReactNativeFirebase.NativeFirebaseError, void, TContext>, "queryKey" | "queryFn">} options - Configuration options for the mutation, excluding "queryKey" and "queryFn".
8
- * @returns {UseMutationResult<void, ReactNativeFirebase.NativeFirebaseError, void, TContext>} A mutation object for handling the sign-out process, including methods for mutating and state tracking.
9
- */
10
- export declare const useSignOutMutation: <TContext = unknown>(options?: Omit<UseMutationOptions<void, ReactNativeFirebase.NativeFirebaseError, void, TContext>, "queryKey" | "queryFn">) => import("@tanstack/react-query").UseMutationResult<void, ReactNativeFirebase.NativeFirebaseError, void, TContext>;
@@ -1,19 +0,0 @@
1
- import { useMutation } from "@tanstack/react-query";
2
- import { signOut } from "@react-native-firebase/auth";
3
- import { SIGN_OUT_MUTATION_KEY } from "./mutation-keys";
4
- import { useAuth } from "./useAuth";
5
- /**
6
- * Custom hook for handling the sign-out mutation using Firebase authentication.
7
- * It wraps the useMutation hook to provide a sign-out function with Firebase.
8
- *
9
- * @param {Omit<UseMutationOptions<void, ReactNativeFirebase.NativeFirebaseError, void, TContext>, "queryKey" | "queryFn">} options - Configuration options for the mutation, excluding "queryKey" and "queryFn".
10
- * @returns {UseMutationResult<void, ReactNativeFirebase.NativeFirebaseError, void, TContext>} A mutation object for handling the sign-out process, including methods for mutating and state tracking.
11
- */
12
- export const useSignOutMutation = (options = {}) => {
13
- const firebaseAuth = useAuth();
14
- return useMutation({
15
- ...options,
16
- mutationFn: async () => await signOut(firebaseAuth),
17
- mutationKey: SIGN_OUT_MUTATION_KEY
18
- });
19
- };
@@ -1,15 +0,0 @@
1
- import { UseMutationOptions } from "@tanstack/react-query";
2
- import { FirebaseAuthTypes } from "@react-native-firebase/auth";
3
- import { ReactNativeFirebase } from "@react-native-firebase/app";
4
- export type UseUpdateProfileMutationVariables = {
5
- displayName?: string;
6
- user: FirebaseAuthTypes.User;
7
- };
8
- /**
9
- * Custom hook to manage the mutation for updating a user's profile.
10
- * Utilizes Firebase for updating the user's display name.
11
- *
12
- * @param {Omit<UseMutationOptions<void, ReactNativeFirebase.NativeFirebaseError, UseUpdateProfileMutationVariables, TContext>, "mutationKey" | "mutationFn">} options - Configuration options for the mutation, excluding mutationKey and mutationFn.
13
- * @returns {UseMutationResult<void, ReactNativeFirebase.NativeFirebaseError, UseUpdateProfileMutationVariables, TContext>} The result of the mutation operation including statuses, data, and error information.
14
- */
15
- export declare const useUpdateProfileMutation: <TContext = unknown>(options?: Omit<UseMutationOptions<void, ReactNativeFirebase.NativeFirebaseError, UseUpdateProfileMutationVariables, TContext>, "mutationKey" | "mutationFn">) => import("@tanstack/react-query").UseMutationResult<void, ReactNativeFirebase.NativeFirebaseError, UseUpdateProfileMutationVariables, TContext>;
@@ -1,17 +0,0 @@
1
- import { useMutation } from "@tanstack/react-query";
2
- import { updateProfile } from "@react-native-firebase/auth";
3
- import { CREATE_USER_WITH_EMAIL_AND_PASSWORD_MUTATION_KEY } from "./mutation-keys";
4
- /**
5
- * Custom hook to manage the mutation for updating a user's profile.
6
- * Utilizes Firebase for updating the user's display name.
7
- *
8
- * @param {Omit<UseMutationOptions<void, ReactNativeFirebase.NativeFirebaseError, UseUpdateProfileMutationVariables, TContext>, "mutationKey" | "mutationFn">} options - Configuration options for the mutation, excluding mutationKey and mutationFn.
9
- * @returns {UseMutationResult<void, ReactNativeFirebase.NativeFirebaseError, UseUpdateProfileMutationVariables, TContext>} The result of the mutation operation including statuses, data, and error information.
10
- */
11
- export const useUpdateProfileMutation = (options = {}) => {
12
- return useMutation({
13
- ...options,
14
- mutationFn: async ({ displayName, user }) => await updateProfile(user, { displayName }),
15
- mutationKey: CREATE_USER_WITH_EMAIL_AND_PASSWORD_MUTATION_KEY
16
- });
17
- };
@@ -1,16 +0,0 @@
1
- export * from "./useFirestore";
2
- export * from "./useAddDocMutation";
3
- export * from "./useBatchWrite";
4
- export * from "./useCollectionReference";
5
- export * from "./useCompositeFilter";
6
- export * from "./useCountQuery";
7
- export * from "./useDeleteDocMutation";
8
- export * from "./useDocReference";
9
- export * from "./useDocReferences";
10
- export * from "./useGetDocData";
11
- export * from "./useInfiniteQuery";
12
- export * from "./useQuery";
13
- export * from "./useRunTransaction";
14
- export * from "./useSetDocMutation";
15
- export * from "./useUpdateDocMutation";
16
- export * from "./useGetRealtimeDocData";
@@ -1,16 +0,0 @@
1
- export * from "./useFirestore";
2
- export * from "./useAddDocMutation";
3
- export * from "./useBatchWrite";
4
- export * from "./useCollectionReference";
5
- export * from "./useCompositeFilter";
6
- export * from "./useCountQuery";
7
- export * from "./useDeleteDocMutation";
8
- export * from "./useDocReference";
9
- export * from "./useDocReferences";
10
- export * from "./useGetDocData";
11
- export * from "./useInfiniteQuery";
12
- export * from "./useQuery";
13
- export * from "./useRunTransaction";
14
- export * from "./useSetDocMutation";
15
- export * from "./useUpdateDocMutation";
16
- export * from "./useGetRealtimeDocData";
@@ -1,21 +0,0 @@
1
- import { UseMutationOptions } from "@tanstack/react-query";
2
- import { FirebaseFirestoreTypes, WithFieldValue } from "@react-native-firebase/firestore";
3
- import { ReactNativeFirebase } from "@react-native-firebase/app";
4
- export type UseAddDocMutationValues<AppModelType> = {
5
- data: WithFieldValue<AppModelType>;
6
- };
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">;
10
- };
11
- /**
12
- * Provides a mutation hook to add a document to a Firestore collection utilizing React Query's `useMutation`.
13
- * It handles addition and optional conversion of the document data in Firestore.
14
- *
15
- * @param {Object} options - Options for the mutation hook
16
- * @param {FirebaseFirestore.FirebaseFirestoreTypes.CollectionReference<AppModelType>} options.reference - Firestore collection reference where the document should be added.
17
- * @param {UseMutationOptions<AppModelType, Error, { data: DbModelType }, TContext>} [options.options={}] - Optional configuration for the mutation.
18
- *
19
- * @returns {UseMutationResult<AppModelType, Error, { data: DbModelType }, TContext>} The mutation hook result containing status, error, and data of the mutation process.
20
- */
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,25 +0,0 @@
1
- import { useMutation } from "@tanstack/react-query";
2
- import { addDoc, getDoc } from "@react-native-firebase/firestore";
3
- import { useMemo } from "react";
4
- /**
5
- * Provides a mutation hook to add a document to a Firestore collection utilizing React Query's `useMutation`.
6
- * It handles addition and optional conversion of the document data in Firestore.
7
- *
8
- * @param {Object} options - Options for the mutation hook
9
- * @param {FirebaseFirestore.FirebaseFirestoreTypes.CollectionReference<AppModelType>} options.reference - Firestore collection reference where the document should be added.
10
- * @param {UseMutationOptions<AppModelType, Error, { data: DbModelType }, TContext>} [options.options={}] - Optional configuration for the mutation.
11
- *
12
- * @returns {UseMutationResult<AppModelType, Error, { data: DbModelType }, TContext>} The mutation hook result containing status, error, and data of the mutation process.
13
- */
14
- export const useAddDocMutation = ({ reference, options = {} }) => {
15
- const mutationKey = useMemo(() => [reference.path], [reference.path]);
16
- return useMutation({
17
- ...options,
18
- mutationFn: async ({ data }) => {
19
- const docRef = await addDoc(reference, data);
20
- const docSnap = await getDoc(docRef);
21
- return docSnap.data();
22
- },
23
- mutationKey
24
- });
25
- };
@@ -1,15 +0,0 @@
1
- import { UseMutationOptions } from "@tanstack/react-query";
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
- export type UseBatchWriteOptions<TContext = unknown> = {
6
- options?: Omit<UseMutationOptions<void, ReactNativeFirebase.NativeFirebaseError, UseBatchWriteVariables, TContext>, "mutationFn">;
7
- };
8
- /**
9
- * Custom hook to perform batch write operations using Firestore.
10
- * Utilizes a mutation to carry out the batch write transaction.
11
- * @template TContext - The type of context that can be passed into the hook, defaults to unknown.
12
- * @param {Object} options - The configuration options for the mutation operation.
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
- */
15
- export declare const useBatchWrite: <TContext = unknown>({ options }?: UseBatchWriteOptions<TContext>) => import("@tanstack/react-query").UseMutationResult<void, ReactNativeFirebase.NativeFirebaseError, UseBatchWriteVariables, TContext>;
@@ -1,21 +0,0 @@
1
- import { useMutation } from "@tanstack/react-query";
2
- import { writeBatch } from "@react-native-firebase/firestore";
3
- import { useFirestore } from "./useFirestore";
4
- /**
5
- * Custom hook to perform batch write operations using Firestore.
6
- * Utilizes a mutation to carry out the batch write transaction.
7
- * @template TContext - The type of context that can be passed into the hook, defaults to unknown.
8
- * @param {Object} options - The configuration options for the mutation operation.
9
- * @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.
10
- */
11
- export const useBatchWrite = ({ options = {} } = {}) => {
12
- const db = useFirestore();
13
- return useMutation({
14
- ...options,
15
- mutationFn: async (batchWriteFn) => {
16
- const batch = writeBatch(db);
17
- await batchWriteFn(batch);
18
- return batch.commit();
19
- }
20
- });
21
- };
@@ -1,18 +0,0 @@
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
- path: string;
5
- pathSegments?: string[];
6
- };
7
- /**
8
- * Creates a reference to a Firestore collection based on the provided path, reference, and path segments.
9
- *
10
- * This hook utilizes useMemo for optimization, ensuring the collection reference is recalculated only when its dependencies change.
11
- *
12
- * @param {UseCollectionReferenceOptions<AppModelType>} options - The options including path, reference, and pathSegments to construct the Firestore collection reference.
13
- * @param {string} options.path - The base path for the collection.
14
- * @param {FirestoreReference} options.reference - An optional Firestore reference object that should be of type "collection".
15
- * @param {string[]} options.pathSegments - Additional path segments to append to the base path.
16
- * @returns {CollectionReference} A Firestore collection reference constructed using the specified path, reference, and path segments.
17
- */
18
- export declare const useCollectionReference: <AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData>({ path, reference, pathSegments }: UseCollectionReferenceOptions<AppModelType>) => FirebaseFirestoreTypes.CollectionReference<AppModelType>;
@@ -1,22 +0,0 @@
1
- import { collection } from "@react-native-firebase/firestore";
2
- import { useMemo } from "react";
3
- import { useFirestore } from "./useFirestore";
4
- /**
5
- * Creates a reference to a Firestore collection based on the provided path, reference, and path segments.
6
- *
7
- * This hook utilizes useMemo for optimization, ensuring the collection reference is recalculated only when its dependencies change.
8
- *
9
- * @param {UseCollectionReferenceOptions<AppModelType>} options - The options including path, reference, and pathSegments to construct the Firestore collection reference.
10
- * @param {string} options.path - The base path for the collection.
11
- * @param {FirestoreReference} options.reference - An optional Firestore reference object that should be of type "collection".
12
- * @param {string[]} options.pathSegments - Additional path segments to append to the base path.
13
- * @returns {CollectionReference} A Firestore collection reference constructed using the specified path, reference, and path segments.
14
- */
15
- export const useCollectionReference = ({ path, reference, pathSegments }) => {
16
- const db = useFirestore();
17
- return useMemo(() => {
18
- return !reference
19
- ? collection(db, path || "", ...(pathSegments || []))
20
- : collection(reference, path, ...(pathSegments || []));
21
- }, [db, reference, path, pathSegments]);
22
- };
@@ -1,32 +0,0 @@
1
- import { FirebaseFirestoreTypes } from "@react-native-firebase/firestore";
2
- type CompositeFilterDocumentData = FirebaseFirestoreTypes.DocumentData;
3
- export type QueryElement<DbModelType extends CompositeFilterDocumentData = CompositeFilterDocumentData> = {
4
- operator?: "OR" | "AND";
5
- children?: QueryElement[];
6
- field?: keyof (DbModelType & {
7
- documentId?: string[];
8
- });
9
- value?: DbModelType[keyof DbModelType];
10
- op?: FirebaseFirestoreTypes.WhereFilterOp;
11
- };
12
- export type CompositeFilter<DbModelType extends CompositeFilterDocumentData = CompositeFilterDocumentData> = {
13
- operator: "OR" | "AND";
14
- children: QueryElement<DbModelType & {
15
- documentId?: string[];
16
- }>[];
17
- };
18
- export type UseCompositeFilter<DbModelType extends CompositeFilterDocumentData = CompositeFilterDocumentData> = {
19
- query?: CompositeFilter<DbModelType>;
20
- };
21
- /**
22
- * A custom hook that generates a composite filter for database queries, using the provided query configuration.
23
- * It applies either an 'OR' or 'AND' logical operation based on the type specified in the query.
24
- *
25
- * @param {Object} query - The query configuration object that contains subqueries and a type for logical combination.
26
- * @param {string} query.type - The type of composite operation ('or'/'and').
27
- * @param {Array} query.children - An array of subqueries that will be processed to form the composite filter.
28
- *
29
- * @returns {(Function|undefined)} A composite query filter constraint function formed by combining subqueries or undefined if there are no valid constraints.
30
- */
31
- export declare const useCompositeFilter: <DbModelType extends CompositeFilterDocumentData = CompositeFilterDocumentData>({ query }: UseCompositeFilter<DbModelType>) => FirebaseFirestoreTypes.QueryCompositeFilterConstraint | undefined;
32
- export {};
@@ -1,42 +0,0 @@
1
- import firebase, { and, or, where } from "@react-native-firebase/firestore";
2
- import { useMemo } from "react";
3
- /**
4
- * Constructs a composite query filter based on the provided query structure.
5
- * It recursively builds query constraints using logical "or" or "and" operators.
6
- *
7
- * @param {QueryElement<DbModelType>} query - The query element or structure to be evaluated and transformed into filter constraints.
8
- * @returns {QueryFieldFilterConstraint | null} A constructed query filter constraint based on the input query, or null if no valid constraints can be derived.
9
- */
10
- const buildCompositeQuery = (query) => {
11
- if (query.children) {
12
- const queryConstraints = query.children.map(buildCompositeQuery).filter((constraint) => !!constraint);
13
- if (queryConstraints.length <= 0) {
14
- return null;
15
- }
16
- return query.operator === "OR" ? or(...queryConstraints) : and(...queryConstraints);
17
- }
18
- if (query.field && query.op) {
19
- return where(query.field === "documentId" ? firebase.FieldPath.documentId() : query.field, query.op, query.value);
20
- }
21
- return null;
22
- };
23
- /**
24
- * A custom hook that generates a composite filter for database queries, using the provided query configuration.
25
- * It applies either an 'OR' or 'AND' logical operation based on the type specified in the query.
26
- *
27
- * @param {Object} query - The query configuration object that contains subqueries and a type for logical combination.
28
- * @param {string} query.type - The type of composite operation ('or'/'and').
29
- * @param {Array} query.children - An array of subqueries that will be processed to form the composite filter.
30
- *
31
- * @returns {(Function|undefined)} A composite query filter constraint function formed by combining subqueries or undefined if there are no valid constraints.
32
- */
33
- export const useCompositeFilter = ({ query }) => {
34
- return useMemo(() => {
35
- const queryConstraints = (query?.children?.map?.((subQuery) => buildCompositeQuery(subQuery))
36
- ?.filter)?.((constraint) => !!constraint) ?? [];
37
- if (queryConstraints.length <= 0) {
38
- return undefined;
39
- }
40
- return query?.operator === "OR" ? or(...queryConstraints) : and(...queryConstraints);
41
- }, [query]);
42
- };
@@ -1,23 +0,0 @@
1
- import { FirebaseFirestoreTypes, QueryConstraint, QueryNonFilterConstraint } from "@react-native-firebase/firestore";
2
- import { UseQueryResult, UseQueryOptions as UseReactQueryOptions } from "@tanstack/react-query";
3
- type UseCountQueryOptions<AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData> = {
4
- options: Omit<UseReactQueryOptions<number, Error, number>, "queryFn"> & Required<Pick<UseReactQueryOptions<number, Error, number>, "queryKey">>;
5
- collectionReference: FirebaseFirestoreTypes.CollectionReference<AppModelType>;
6
- queryConstraints?: QueryConstraint[] | QueryNonFilterConstraint[];
7
- compositeFilter?: FirebaseFirestoreTypes.QueryCompositeFilterConstraint;
8
- };
9
- /**
10
- * Executes a query with specified constraints and returns the count of matched documents.
11
- *
12
- * This function utilizes React Query to asynchronously fetch the count of documents from a server database
13
- * that match the provided query constraints and an optional composite filter.
14
- *
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
- * @param {unknown} [options.query] - Reference to the query object to be executed.
18
- * @param {unknown[]} [options.queryConstraints=[]] - An array of constraints to apply to the query.
19
- * @param {unknown} [options.compositeFilter] - An optional composite filter to apply to the query.
20
- * @returns {UseQueryResult<number>} An object containing the number of documents that match the query.
21
- */
22
- export declare const useCountQuery: <AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData>({ options, collectionReference, queryConstraints, compositeFilter }: UseCountQueryOptions<AppModelType>) => UseQueryResult<number>;
23
- export {};
@@ -1,30 +0,0 @@
1
- import { getCountFromServer, query } from "@react-native-firebase/firestore";
2
- import { useQuery as useReactQuery } from "@tanstack/react-query";
3
- /**
4
- * Executes a query with specified constraints and returns the count of matched documents.
5
- *
6
- * This function utilizes React Query to asynchronously fetch the count of documents from a server database
7
- * that match the provided query constraints and an optional composite filter.
8
- *
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
- * @param {unknown} [options.query] - Reference to the query object to be executed.
12
- * @param {unknown[]} [options.queryConstraints=[]] - An array of constraints to apply to the query.
13
- * @param {unknown} [options.compositeFilter] - An optional composite filter to apply to the query.
14
- * @returns {UseQueryResult<number>} An object containing the number of documents that match the query.
15
- */
16
- export const useCountQuery = ({ options, collectionReference, queryConstraints = [], compositeFilter }) => {
17
- return useReactQuery({
18
- ...options,
19
- queryFn: async () => {
20
- const queryToExecute = compositeFilter
21
- ? query(collectionReference, compositeFilter, ...queryConstraints)
22
- : query(collectionReference, ...queryConstraints);
23
- const querySnapshot = await getCountFromServer(queryToExecute);
24
- if (querySnapshot) {
25
- return querySnapshot.data().count;
26
- }
27
- return 0;
28
- }
29
- });
30
- };