react-query-firebase 2.0.2 → 2.1.0

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 (179) hide show
  1. package/package.json +2 -2
  2. package/react-native/firestore/index.ts +1 -0
  3. package/react-native/firestore/useCompositeFilter.ts +4 -4
  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/web/firestore/index.ts +1 -0
  9. package/web/firestore/useCompositeFilter.ts +4 -4
  10. package/web/firestore/useQueryConstraints.ts +93 -0
  11. package/web/index.d.ts +0 -4
  12. package/web/index.js +0 -4
  13. package/web/index.ts +0 -4
  14. package/react-native/analytics/index.d.ts +0 -3
  15. package/react-native/analytics/index.js +0 -3
  16. package/react-native/analytics/useAnalytics.d.ts +0 -5
  17. package/react-native/analytics/useAnalytics.js +0 -10
  18. package/react-native/analytics/useLogEvent.d.ts +0 -17
  19. package/react-native/analytics/useLogEvent.js +0 -21
  20. package/react-native/analytics/useSetAnalyticsCollectionEnabled.d.ts +0 -10
  21. package/react-native/analytics/useSetAnalyticsCollectionEnabled.js +0 -16
  22. package/react-native/auth/index.d.ts +0 -12
  23. package/react-native/auth/index.js +0 -12
  24. package/react-native/auth/mutation-keys.d.ts +0 -7
  25. package/react-native/auth/mutation-keys.js +0 -19
  26. package/react-native/auth/useAuth.d.ts +0 -5
  27. package/react-native/auth/useAuth.js +0 -10
  28. package/react-native/auth/useCreateUserWitEmailAndPasswordMutation.d.ts +0 -15
  29. package/react-native/auth/useCreateUserWitEmailAndPasswordMutation.js +0 -19
  30. package/react-native/auth/useCurrentUser.d.ts +0 -6
  31. package/react-native/auth/useCurrentUser.js +0 -20
  32. package/react-native/auth/useIdToken.d.ts +0 -30
  33. package/react-native/auth/useIdToken.js +0 -66
  34. package/react-native/auth/useReauthenticateWitCredentialMutation.d.ts +0 -16
  35. package/react-native/auth/useReauthenticateWitCredentialMutation.js +0 -18
  36. package/react-native/auth/useReauthenticateWitRedirectMutation.d.ts +0 -17
  37. package/react-native/auth/useReauthenticateWitRedirectMutation.js +0 -18
  38. package/react-native/auth/useSendEmailVerificationMutation.d.ts +0 -13
  39. package/react-native/auth/useSendEmailVerificationMutation.js +0 -16
  40. package/react-native/auth/useSignInWitEmailAndPasswordMutation.d.ts +0 -15
  41. package/react-native/auth/useSignInWitEmailAndPasswordMutation.js +0 -19
  42. package/react-native/auth/useSignInWitRedirectMutation.d.ts +0 -14
  43. package/react-native/auth/useSignInWitRedirectMutation.js +0 -18
  44. package/react-native/auth/useSignOutMutation.d.ts +0 -10
  45. package/react-native/auth/useSignOutMutation.js +0 -19
  46. package/react-native/auth/useUpdateProfileMutation.d.ts +0 -15
  47. package/react-native/auth/useUpdateProfileMutation.js +0 -17
  48. package/react-native/firestore/index.d.ts +0 -16
  49. package/react-native/firestore/index.js +0 -16
  50. package/react-native/firestore/useAddDocMutation.d.ts +0 -21
  51. package/react-native/firestore/useAddDocMutation.js +0 -25
  52. package/react-native/firestore/useBatchWrite.d.ts +0 -15
  53. package/react-native/firestore/useBatchWrite.js +0 -21
  54. package/react-native/firestore/useCollectionReference.d.ts +0 -18
  55. package/react-native/firestore/useCollectionReference.js +0 -22
  56. package/react-native/firestore/useCompositeFilter.d.ts +0 -32
  57. package/react-native/firestore/useCompositeFilter.js +0 -42
  58. package/react-native/firestore/useCountQuery.d.ts +0 -23
  59. package/react-native/firestore/useCountQuery.js +0 -30
  60. package/react-native/firestore/useDeleteDocMutation.d.ts +0 -18
  61. package/react-native/firestore/useDeleteDocMutation.js +0 -23
  62. package/react-native/firestore/useDocReference.d.ts +0 -19
  63. package/react-native/firestore/useDocReference.js +0 -36
  64. package/react-native/firestore/useDocReferences.d.ts +0 -23
  65. package/react-native/firestore/useDocReferences.js +0 -29
  66. package/react-native/firestore/useFirestore.d.ts +0 -7
  67. package/react-native/firestore/useFirestore.js +0 -12
  68. package/react-native/firestore/useGetDocData.d.ts +0 -18
  69. package/react-native/firestore/useGetDocData.js +0 -18
  70. package/react-native/firestore/useGetRealtimeDocData.d.ts +0 -57
  71. package/react-native/firestore/useGetRealtimeDocData.js +0 -56
  72. package/react-native/firestore/useInfiniteQuery.d.ts +0 -17
  73. package/react-native/firestore/useInfiniteQuery.js +0 -28
  74. package/react-native/firestore/useQuery.d.ts +0 -24
  75. package/react-native/firestore/useQuery.js +0 -34
  76. package/react-native/firestore/useRunTransaction.d.ts +0 -15
  77. package/react-native/firestore/useRunTransaction.js +0 -19
  78. package/react-native/firestore/useSetDocMutation.d.ts +0 -20
  79. package/react-native/firestore/useSetDocMutation.js +0 -25
  80. package/react-native/firestore/useUpdateDocMutation.d.ts +0 -30
  81. package/react-native/firestore/useUpdateDocMutation.js +0 -37
  82. package/react-native/firestore/utils/getDocData.d.ts +0 -18
  83. package/react-native/firestore/utils/getDocData.js +0 -22
  84. package/react-native/firestore/utils/getDocRef.d.ts +0 -19
  85. package/react-native/firestore/utils/getDocRef.js +0 -21
  86. package/react-native/firestore/utils/getDocSnap.d.ts +0 -20
  87. package/react-native/firestore/utils/getDocSnap.js +0 -25
  88. package/react-native/remoteConfig/index.d.ts +0 -3
  89. package/react-native/remoteConfig/index.js +0 -3
  90. package/react-native/remoteConfig/useFetchAndActivate.d.ts +0 -11
  91. package/react-native/remoteConfig/useFetchAndActivate.js +0 -31
  92. package/react-native/remoteConfig/useGetValue.d.ts +0 -7
  93. package/react-native/remoteConfig/useGetValue.js +0 -15
  94. package/react-native/remoteConfig/useRemoteConfig.d.ts +0 -5
  95. package/react-native/remoteConfig/useRemoteConfig.js +0 -10
  96. package/web/analytics/index.d.ts +0 -3
  97. package/web/analytics/index.js +0 -3
  98. package/web/analytics/useAnalytics.d.ts +0 -5
  99. package/web/analytics/useAnalytics.js +0 -10
  100. package/web/analytics/useLogEvent.d.ts +0 -17
  101. package/web/analytics/useLogEvent.js +0 -21
  102. package/web/analytics/useSetAnalyticsCollectionEnabled.d.ts +0 -10
  103. package/web/analytics/useSetAnalyticsCollectionEnabled.js +0 -16
  104. package/web/auth/index.d.ts +0 -13
  105. package/web/auth/index.js +0 -13
  106. package/web/auth/mutation-keys.d.ts +0 -7
  107. package/web/auth/mutation-keys.js +0 -19
  108. package/web/auth/useAuth.d.ts +0 -5
  109. package/web/auth/useAuth.js +0 -10
  110. package/web/auth/useAuthStateReady.d.ts +0 -6
  111. package/web/auth/useAuthStateReady.js +0 -19
  112. package/web/auth/useCreateUserWitEmailAndPasswordMutation.d.ts +0 -15
  113. package/web/auth/useCreateUserWitEmailAndPasswordMutation.js +0 -19
  114. package/web/auth/useCurrentUser.d.ts +0 -6
  115. package/web/auth/useCurrentUser.js +0 -20
  116. package/web/auth/useIdToken.d.ts +0 -30
  117. package/web/auth/useIdToken.js +0 -66
  118. package/web/auth/useReauthenticateWitCredentialMutation.d.ts +0 -16
  119. package/web/auth/useReauthenticateWitCredentialMutation.js +0 -18
  120. package/web/auth/useReauthenticateWitRedirectMutation.d.ts +0 -17
  121. package/web/auth/useReauthenticateWitRedirectMutation.js +0 -18
  122. package/web/auth/useSendEmailVerificationMutation.d.ts +0 -13
  123. package/web/auth/useSendEmailVerificationMutation.js +0 -16
  124. package/web/auth/useSignInWitEmailAndPasswordMutation.d.ts +0 -15
  125. package/web/auth/useSignInWitEmailAndPasswordMutation.js +0 -19
  126. package/web/auth/useSignInWitRedirectMutation.d.ts +0 -14
  127. package/web/auth/useSignInWitRedirectMutation.js +0 -18
  128. package/web/auth/useSignOutMutation.d.ts +0 -10
  129. package/web/auth/useSignOutMutation.js +0 -19
  130. package/web/auth/useUpdateProfileMutation.d.ts +0 -15
  131. package/web/auth/useUpdateProfileMutation.js +0 -17
  132. package/web/firestore/index.d.ts +0 -16
  133. package/web/firestore/index.js +0 -16
  134. package/web/firestore/useAddDocMutation.d.ts +0 -23
  135. package/web/firestore/useAddDocMutation.js +0 -26
  136. package/web/firestore/useBatchWrite.d.ts +0 -15
  137. package/web/firestore/useBatchWrite.js +0 -21
  138. package/web/firestore/useCollectionReference.d.ts +0 -18
  139. package/web/firestore/useCollectionReference.js +0 -24
  140. package/web/firestore/useCompositeFilter.d.ts +0 -32
  141. package/web/firestore/useCompositeFilter.js +0 -41
  142. package/web/firestore/useCountQuery.d.ts +0 -23
  143. package/web/firestore/useCountQuery.js +0 -30
  144. package/web/firestore/useDeleteDocMutation.d.ts +0 -18
  145. package/web/firestore/useDeleteDocMutation.js +0 -23
  146. package/web/firestore/useDocReference.d.ts +0 -19
  147. package/web/firestore/useDocReference.js +0 -45
  148. package/web/firestore/useDocReferences.d.ts +0 -23
  149. package/web/firestore/useDocReferences.js +0 -31
  150. package/web/firestore/useFirestore.d.ts +0 -7
  151. package/web/firestore/useFirestore.js +0 -12
  152. package/web/firestore/useGetDocData.d.ts +0 -18
  153. package/web/firestore/useGetDocData.js +0 -18
  154. package/web/firestore/useGetRealtimeDocData.d.ts +0 -57
  155. package/web/firestore/useGetRealtimeDocData.js +0 -56
  156. package/web/firestore/useInfiniteQuery.d.ts +0 -18
  157. package/web/firestore/useInfiniteQuery.js +0 -28
  158. package/web/firestore/useQuery.d.ts +0 -25
  159. package/web/firestore/useQuery.js +0 -34
  160. package/web/firestore/useRunTransaction.d.ts +0 -15
  161. package/web/firestore/useRunTransaction.js +0 -19
  162. package/web/firestore/useSetDocMutation.d.ts +0 -20
  163. package/web/firestore/useSetDocMutation.js +0 -25
  164. package/web/firestore/useUpdateDocMutation.d.ts +0 -31
  165. package/web/firestore/useUpdateDocMutation.js +0 -37
  166. package/web/firestore/utils/getDocData.d.ts +0 -18
  167. package/web/firestore/utils/getDocData.js +0 -22
  168. package/web/firestore/utils/getDocRef.d.ts +0 -19
  169. package/web/firestore/utils/getDocRef.js +0 -25
  170. package/web/firestore/utils/getDocSnap.d.ts +0 -20
  171. package/web/firestore/utils/getDocSnap.js +0 -25
  172. package/web/remoteConfig/index.d.ts +0 -3
  173. package/web/remoteConfig/index.js +0 -3
  174. package/web/remoteConfig/useFetchAndActivate.d.ts +0 -11
  175. package/web/remoteConfig/useFetchAndActivate.js +0 -31
  176. package/web/remoteConfig/useGetValue.d.ts +0 -7
  177. package/web/remoteConfig/useGetValue.js +0 -15
  178. package/web/remoteConfig/useRemoteConfig.d.ts +0 -5
  179. package/web/remoteConfig/useRemoteConfig.js +0 -10
@@ -1,16 +0,0 @@
1
- import { useMutation } from "@tanstack/react-query";
2
- import { sendEmailVerification } from "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, FirebaseError, UseSendEmailVerificationMutationVariables, TContext>, "queryKey" | "queryFn">} options - Configuration options for the mutation, excluding `queryKey` and `queryFn`.
8
- * @returns {UseMutationResult<void, FirebaseError, 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 { UserCredential } from "firebase/auth";
3
- import { FirebaseError } from "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<UserCredential, FirebaseError, 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<UserCredential, FirebaseError, UseSignInWitEmailAndPasswordMutationVariables, TContext>, "mutationKey" | "mutationFn">) => import("@tanstack/react-query").UseMutationResult<UserCredential, FirebaseError, UseSignInWitEmailAndPasswordMutationVariables, TContext>;
@@ -1,19 +0,0 @@
1
- import { useMutation } from "@tanstack/react-query";
2
- import { signInWithEmailAndPassword } from "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<UserCredential, FirebaseError, 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 { AuthProvider, PopupRedirectResolver } from "firebase/auth";
3
- import { FirebaseError } from "firebase/app";
4
- export type UseSignInWitRedirectMutationVariables = {
5
- authProvider: 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, FirebaseError, UseSignInWitRedirectMutationVariables, TContext>, "mutationKey" | "mutationFn">} options - Optional configurations for the mutation, omitting the mutationKey and mutationFn properties.
12
- * @returns {UseMutationResult<void, FirebaseError, 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, FirebaseError, UseSignInWitRedirectMutationVariables, TContext>, "mutationKey" | "mutationFn">) => import("@tanstack/react-query").UseMutationResult<void, FirebaseError, UseSignInWitRedirectMutationVariables, TContext>;
@@ -1,18 +0,0 @@
1
- import { useMutation } from "@tanstack/react-query";
2
- import { signInWithRedirect } from "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, FirebaseError, UseSignInWitRedirectMutationVariables, TContext>, "mutationKey" | "mutationFn">} options - Optional configurations for the mutation, omitting the mutationKey and mutationFn properties.
9
- * @returns {UseMutationResult<void, FirebaseError, 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 { FirebaseError } from "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, FirebaseError, void, TContext>, "queryKey" | "queryFn">} options - Configuration options for the mutation, excluding "queryKey" and "queryFn".
8
- * @returns {UseMutationResult<void, FirebaseError, 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, FirebaseError, void, TContext>, "queryKey" | "queryFn">) => import("@tanstack/react-query").UseMutationResult<void, FirebaseError, void, TContext>;
@@ -1,19 +0,0 @@
1
- import { useMutation } from "@tanstack/react-query";
2
- import { signOut } from "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, FirebaseError, void, TContext>, "queryKey" | "queryFn">} options - Configuration options for the mutation, excluding "queryKey" and "queryFn".
10
- * @returns {UseMutationResult<void, FirebaseError, 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 { User } from "firebase/auth";
3
- import { FirebaseError } from "firebase/app";
4
- export type UseUpdateProfileMutationVariables = {
5
- displayName?: string;
6
- user: 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, FirebaseError, UseUpdateProfileMutationVariables, TContext>, "mutationKey" | "mutationFn">} options - Configuration options for the mutation, excluding mutationKey and mutationFn.
13
- * @returns {UseMutationResult<void, FirebaseError, 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, FirebaseError, UseUpdateProfileMutationVariables, TContext>, "mutationKey" | "mutationFn">) => import("@tanstack/react-query").UseMutationResult<void, FirebaseError, UseUpdateProfileMutationVariables, TContext>;
@@ -1,17 +0,0 @@
1
- import { useMutation } from "@tanstack/react-query";
2
- import { updateProfile } from "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, FirebaseError, UseUpdateProfileMutationVariables, TContext>, "mutationKey" | "mutationFn">} options - Configuration options for the mutation, excluding mutationKey and mutationFn.
9
- * @returns {UseMutationResult<void, FirebaseError, 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,23 +0,0 @@
1
- import { UseMutationOptions } from "@tanstack/react-query";
2
- import { DocumentData, WithFieldValue, CollectionReference, FirestoreDataConverter } from "firebase/firestore";
3
- import { FirebaseError } from "firebase/app";
4
- export type UseAddDocMutationValues<AppModelType> = {
5
- data: WithFieldValue<AppModelType>;
6
- };
7
- export type UseAddDocMutationOptions<AppModelType extends DocumentData = DocumentData, DbModelType extends DocumentData = DocumentData, TContext = unknown> = {
8
- reference: CollectionReference<AppModelType, DbModelType>;
9
- converter?: FirestoreDataConverter<AppModelType, DbModelType>;
10
- options?: Omit<UseMutationOptions<AppModelType, FirebaseError, UseAddDocMutationValues<AppModelType>, TContext>, "mutationFn" | "mutationKey">;
11
- };
12
- /**
13
- * Provides a mutation hook to add a document to a Firestore collection utilizing React Query's `useMutation`.
14
- * It handles addition and optional conversion of the document data in Firestore.
15
- *
16
- * @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.
19
- * @param {UseMutationOptions<AppModelType, Error, { data: DbModelType }, TContext>} [options.options={}] - Optional configuration for the mutation.
20
- *
21
- * @returns {UseMutationResult<AppModelType, Error, { data: DbModelType }, TContext>} The mutation hook result containing status, error, and data of the mutation process.
22
- */
23
- export declare const useAddDocMutation: <AppModelType extends DocumentData = DocumentData, DbModelType extends DocumentData = DocumentData, TContext = unknown>({ reference, converter, options }: UseAddDocMutationOptions<AppModelType, DbModelType, TContext>) => import("@tanstack/react-query").UseMutationResult<AppModelType, FirebaseError, UseAddDocMutationValues<AppModelType>, TContext>;
@@ -1,26 +0,0 @@
1
- import { useMutation } from "@tanstack/react-query";
2
- import { addDoc, getDoc } from "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.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.
11
- * @param {UseMutationOptions<AppModelType, Error, { data: DbModelType }, TContext>} [options.options={}] - Optional configuration for the mutation.
12
- *
13
- * @returns {UseMutationResult<AppModelType, Error, { data: DbModelType }, TContext>} The mutation hook result containing status, error, and data of the mutation process.
14
- */
15
- export const useAddDocMutation = ({ reference, converter, options = {} }) => {
16
- const mutationKey = useMemo(() => [reference.path], [reference.path]);
17
- return useMutation({
18
- ...options,
19
- mutationFn: async ({ data }) => {
20
- const docRef = await addDoc(reference, data);
21
- const docSnap = await getDoc(converter ? docRef.withConverter(converter) : docRef);
22
- return docSnap.data();
23
- },
24
- mutationKey
25
- });
26
- };
@@ -1,15 +0,0 @@
1
- import { UseMutationOptions } from "@tanstack/react-query";
2
- import { WriteBatch } from "firebase/firestore";
3
- import { FirebaseError } from "firebase/app";
4
- export type UseBatchWriteVariables = (batch: WriteBatch) => Promise<void> | void;
5
- export type UseBatchWriteOptions<TContext = unknown> = {
6
- options?: Omit<UseMutationOptions<void, FirebaseError, 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, FirebaseError, UseBatchWriteVariables, TContext>;
@@ -1,21 +0,0 @@
1
- import { useMutation } from "@tanstack/react-query";
2
- import { writeBatch } from "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 { CollectionReference, DocumentData, DocumentReference } from "firebase/firestore";
2
- export type UseCollectionReferenceOptions<AppModelType, DbModelType extends DocumentData = DocumentData> = {
3
- reference?: CollectionReference<AppModelType, DbModelType> | DocumentReference<AppModelType, DbModelType>;
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, DbModelType>} 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, DbModelType extends DocumentData = DocumentData>({ path, reference, pathSegments }: UseCollectionReferenceOptions<AppModelType, DbModelType>) => CollectionReference<DocumentData, DocumentData>;
@@ -1,24 +0,0 @@
1
- import { collection } from "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, DbModelType>} 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
- : reference.type === "collection"
21
- ? collection(reference, path, ...(pathSegments || []))
22
- : collection(reference, path, ...(pathSegments || []));
23
- }, [path, reference, pathSegments, db]);
24
- };
@@ -1,32 +0,0 @@
1
- import { DocumentData, WhereFilterOp } from "firebase/firestore";
2
- type CompositeFilterDocumentData = 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?: 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>) => import("@firebase/firestore").QueryCompositeFilterConstraint | undefined;
32
- export {};
@@ -1,41 +0,0 @@
1
- import { documentId, and, or, where } from "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" ? 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))?.filter)?.((constraint) => !!constraint) ?? [];
36
- if (queryConstraints.length <= 0) {
37
- return undefined;
38
- }
39
- return query?.operator === "OR" ? or(...queryConstraints) : and(...queryConstraints);
40
- }, [query]);
41
- };
@@ -1,23 +0,0 @@
1
- import { DocumentData, CollectionReference, QueryCompositeFilterConstraint, QueryConstraint, QueryNonFilterConstraint } from "firebase/firestore";
2
- import { UseQueryResult, UseQueryOptions as UseReactQueryOptions } from "@tanstack/react-query";
3
- type UseCountQueryOptions<AppModelType extends DocumentData = DocumentData, DbModelType extends DocumentData = DocumentData> = {
4
- options: Omit<UseReactQueryOptions<number, Error, number>, "queryFn"> & Required<Pick<UseReactQueryOptions<number, Error, number>, "queryKey">>;
5
- collectionReference: CollectionReference<AppModelType, DbModelType>;
6
- queryConstraints?: QueryConstraint[] | QueryNonFilterConstraint[];
7
- compositeFilter?: 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, DbModelType>} options - Configuration options for the query.
16
- * @param {AppModelType extends DocumentData = 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 DocumentData = DocumentData, DbModelType extends DocumentData = DocumentData>({ options, collectionReference, queryConstraints, compositeFilter }: UseCountQueryOptions<AppModelType, DbModelType>) => UseQueryResult<number>;
23
- export {};
@@ -1,30 +0,0 @@
1
- import { getCountFromServer, query } from "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, DbModelType>} options - Configuration options for the query.
10
- * @param {AppModelType extends DocumentData = 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
- };
@@ -1,18 +0,0 @@
1
- import { UseMutationOptions } from "@tanstack/react-query";
2
- import { DocumentData, WithFieldValue, DocumentReference } from "firebase/firestore";
3
- import { FirebaseError } from "firebase/app";
4
- export type UseDeleteDocMutationValues<AppModelType> = {
5
- data: WithFieldValue<AppModelType>;
6
- };
7
- export type UseDeleteDocMutationOptions<AppModelType extends DocumentData = DocumentData, DbModelType extends DocumentData = DocumentData, TContext = unknown> = {
8
- reference: DocumentReference<AppModelType, DbModelType> | null;
9
- options?: Omit<UseMutationOptions<void, FirebaseError, void, TContext>, "mutationFn" | "mutationKey">;
10
- };
11
- /**
12
- * A custom hook that provides a mutation function to delete a document from the database.
13
- * @param {UseDeleteDocMutationOptions<AppModelType, DbModelType, TContext>} options - An object containing the reference to the document and additional options for the mutation.
14
- * @param {FirestoreReference<AppModelType, DbModelType>} options.reference - The reference to the document that needs to be deleted.
15
- * @param {object} options.options - Additional options for the mutation, if any (default is an empty object).
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
- */
18
- export declare const useDeleteDocMutation: <AppModelType extends DocumentData = DocumentData, DbModelType extends DocumentData = DocumentData, TContext = unknown>({ reference, options }: UseDeleteDocMutationOptions<AppModelType, DbModelType, TContext>) => import("@tanstack/react-query").UseMutationResult<void, FirebaseError, void, TContext>;
@@ -1,23 +0,0 @@
1
- import { useMutation } from "@tanstack/react-query";
2
- import { deleteDoc } from "firebase/firestore";
3
- import { useMemo } from "react";
4
- /**
5
- * A custom hook that provides a mutation function to delete a document from the database.
6
- * @param {UseDeleteDocMutationOptions<AppModelType, DbModelType, TContext>} options - An object containing the reference to the document and additional options for the mutation.
7
- * @param {FirestoreReference<AppModelType, DbModelType>} options.reference - The reference to the document that needs to be deleted.
8
- * @param {object} options.options - Additional options for the mutation, if any (default is an empty object).
9
- * @returns {UseMutationResult} An object returned by the `useMutation` hook which includes properties and methods to control the mutation's execution and track its state.
10
- */
11
- export const useDeleteDocMutation = ({ reference, options = {} }) => {
12
- const mutationKey = useMemo(() => [reference?.path], [reference?.path]);
13
- return useMutation({
14
- ...options,
15
- mutationFn: async () => {
16
- if (!reference) {
17
- throw new Error("Reference is undefined");
18
- }
19
- await deleteDoc(reference);
20
- },
21
- mutationKey
22
- });
23
- };
@@ -1,19 +0,0 @@
1
- import { CollectionReference, DocumentData, DocumentReference } from "firebase/firestore";
2
- export type UseDocReferenceOptions<AppModelType, DbModelType extends DocumentData = DocumentData> = {
3
- reference?: CollectionReference<AppModelType, DbModelType> | DocumentReference<AppModelType, DbModelType>;
4
- path?: string;
5
- pathSegments?: string[];
6
- };
7
- /**
8
- * Custom hook to generate and manage a Firestore document reference.
9
- * This hook facilitates the retrieval of a Firestore document reference based on given options such as path and reference data.
10
- * The reference is updated whenever the associated path, reference, or path segments change.
11
- *
12
- * @param {UseDocReferenceOptions<AppModelType, DbModelType>} options - Configuration options for setting up the document reference.
13
- * @param {string} options.path - The path to the Firestore document.
14
- * @param {DbModelType} options.reference - Reference data for the document, providing additional context or specifics.
15
- * @param {string[]} options.pathSegments - Parts of the path to construct the full document path dynamically.
16
- *
17
- * @returns {DocumentReference<AppModelType, DbModelType> | null} The Firestore document reference corresponding to the provided path and options, or null if not initialized.
18
- */
19
- export declare const useDocReference: <AppModelType, DbModelType extends DocumentData = DocumentData>({ path, reference, pathSegments }: UseDocReferenceOptions<AppModelType, DbModelType>) => DocumentReference<AppModelType, DbModelType> | null;
@@ -1,45 +0,0 @@
1
- import { doc } from "firebase/firestore";
2
- import { useEffect, useRef } from "react";
3
- import { useFirestore } from "./useFirestore";
4
- /**
5
- * Generates a document reference for a specified path or reference in Firestore.
6
- * If a reference is not provided, it constructs a document reference using the Firestore instance, path, and path segments.
7
- *
8
- * @param {Firestore} db - The Firestore database instance used to create the document reference.
9
- * @param {UseDocReferenceOptions<AppModelType, DbModelType>} options - An object containing the path, path segments, and optional reference.
10
- * @param {string} options.path - The path to the document in the Firestore database.
11
- * @param {string[]} [options.pathSegments] - Optional additional segments to join with the path.
12
- * @param {DocumentReference | CollectionReference} [options.reference] - Optional Firestore reference object that influences how the document reference is constructed.
13
- *
14
- * @returns {DocumentReference<AppModelType, DbModelType> | null} A Firestore document reference if the path is specified; otherwise, returns null if path is not provided.
15
- */
16
- const getDocReference = (db, { path, pathSegments, reference }) => {
17
- if (!path) {
18
- return null;
19
- }
20
- return (!reference
21
- ? doc(db, path || "", ...(pathSegments || []))
22
- : reference.type === "collection"
23
- ? doc(reference, path, ...(pathSegments || []))
24
- : doc(reference, path, ...(pathSegments || [])));
25
- };
26
- /**
27
- * Custom hook to generate and manage a Firestore document reference.
28
- * This hook facilitates the retrieval of a Firestore document reference based on given options such as path and reference data.
29
- * The reference is updated whenever the associated path, reference, or path segments change.
30
- *
31
- * @param {UseDocReferenceOptions<AppModelType, DbModelType>} options - Configuration options for setting up the document reference.
32
- * @param {string} options.path - The path to the Firestore document.
33
- * @param {DbModelType} options.reference - Reference data for the document, providing additional context or specifics.
34
- * @param {string[]} options.pathSegments - Parts of the path to construct the full document path dynamically.
35
- *
36
- * @returns {DocumentReference<AppModelType, DbModelType> | null} The Firestore document reference corresponding to the provided path and options, or null if not initialized.
37
- */
38
- export const useDocReference = ({ path, reference, pathSegments }) => {
39
- const db = useFirestore();
40
- const ref = useRef(getDocReference(db, { path, pathSegments, reference }));
41
- useEffect(() => {
42
- ref.current = getDocReference(db, { path, pathSegments, reference });
43
- }, [path, reference, pathSegments, db]);
44
- return ref.current;
45
- };
@@ -1,23 +0,0 @@
1
- import { CollectionReference, DocumentData, DocumentReference } from "firebase/firestore";
2
- export type UseDocReferencesOptions<AppModelType, DbModelType extends DocumentData = DocumentData> = {
3
- reference?: CollectionReference<AppModelType, DbModelType> | DocumentReference<AppModelType, DbModelType>;
4
- path: string;
5
- pathSegments?: string[];
6
- };
7
- /**
8
- * A custom hook to generate document references for Firebase Firestore documents using given
9
- * reference options.
10
- *
11
- * The hook accepts an array of options, where each option may contain a path,
12
- * an existing reference, or path segments, and returns an array of generated
13
- * Firestore document references based on those options. The references can be used
14
- * to interact with the Firestore database documents. It uses memoization to optimize
15
- * reference generation.
16
- *
17
- * @param {UseDocReferencesOptions<AppModelType, DbModelType>[]} references - An array of options
18
- * specifying how to generate document references. Each option may include a `path`
19
- * as a string, a `reference` as a Firestore reference, and `pathSegments` as an array of strings.
20
- * @returns {DocumentReference<AppModelType, DbModelType>[]} An array of Firestore document references
21
- * generated from the options provided.
22
- */
23
- export declare const useDocReferences: <AppModelType, DbModelType extends DocumentData = DocumentData>(references: UseDocReferencesOptions<AppModelType, DbModelType>[]) => DocumentReference<AppModelType, DbModelType>[];