react-query-firebase 1.0.2 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. package/README.md +27 -3
  2. package/dist/src/analytics/index.d.ts +1 -0
  3. package/dist/src/analytics/index.js +1 -0
  4. package/dist/src/analytics/useAnalytics.d.ts +5 -0
  5. package/dist/src/analytics/useAnalytics.js +10 -0
  6. package/dist/src/analytics/useLogEvent.d.ts +7 -0
  7. package/dist/src/analytics/useLogEvent.js +8 -1
  8. package/dist/src/auth/index.d.ts +2 -0
  9. package/dist/src/auth/index.js +2 -0
  10. package/dist/src/auth/useAuth.d.ts +5 -0
  11. package/dist/src/auth/useAuth.js +10 -0
  12. package/dist/src/auth/useAuthStateReady.d.ts +5 -0
  13. package/dist/src/auth/useAuthStateReady.js +6 -1
  14. package/dist/src/auth/useCreateUserWitEmailAndPasswordMutation.d.ts +7 -0
  15. package/dist/src/auth/useCreateUserWitEmailAndPasswordMutation.js +8 -1
  16. package/dist/src/auth/useCurrentUser.d.ts +5 -0
  17. package/dist/src/auth/useCurrentUser.js +6 -1
  18. package/dist/src/auth/useIdToken.d.ts +12 -0
  19. package/dist/src/auth/useIdToken.js +36 -0
  20. package/dist/src/auth/useReauthenticateWitCredentialMutation.d.ts +8 -0
  21. package/dist/src/auth/useReauthenticateWitCredentialMutation.js +8 -0
  22. package/dist/src/auth/useReauthenticateWitRedirectMutation.d.ts +8 -0
  23. package/dist/src/auth/useReauthenticateWitRedirectMutation.js +8 -0
  24. package/dist/src/auth/useSendEmailVerificationMutation.d.ts +6 -0
  25. package/dist/src/auth/useSendEmailVerificationMutation.js +6 -0
  26. package/dist/src/auth/useSignInWitEmailAndPasswordMutation.d.ts +7 -0
  27. package/dist/src/auth/useSignInWitEmailAndPasswordMutation.js +8 -1
  28. package/dist/src/auth/useSignInWitRedirectMutation.d.ts +6 -0
  29. package/dist/src/auth/useSignInWitRedirectMutation.js +7 -1
  30. package/dist/src/auth/useSignOutMutation.d.ts +7 -0
  31. package/dist/src/auth/useSignOutMutation.js +8 -1
  32. package/dist/src/auth/useUpdateProfileMutation.d.ts +7 -0
  33. package/dist/src/auth/useUpdateProfileMutation.js +7 -0
  34. package/dist/src/{FirebaseContext.d.ts → context/FirebaseContext.d.ts} +8 -2
  35. package/dist/src/context/FirebaseContext.js +8 -0
  36. package/dist/src/context/FirebaseContextProvider.d.ts +105 -0
  37. package/dist/src/{FirebaseContextProvider.js → context/FirebaseContextProvider.js} +24 -1
  38. package/dist/src/context/index.d.ts +1 -0
  39. package/dist/src/context/index.js +1 -0
  40. package/dist/src/firestore/index.d.ts +1 -0
  41. package/dist/src/firestore/index.js +1 -0
  42. package/dist/src/firestore/useAddDocMutation.d.ts +11 -0
  43. package/dist/src/firestore/useAddDocMutation.js +11 -0
  44. package/dist/src/firestore/useBatchWrite.d.ts +7 -0
  45. package/dist/src/firestore/useBatchWrite.js +8 -1
  46. package/dist/src/firestore/useCollectionReference.d.ts +11 -0
  47. package/dist/src/firestore/useCollectionReference.js +12 -1
  48. package/dist/src/firestore/useCompositeFilter.d.ts +10 -0
  49. package/dist/src/firestore/useCompositeFilter.js +17 -0
  50. package/dist/src/firestore/useCountQuery.d.ts +13 -0
  51. package/dist/src/firestore/useCountQuery.js +13 -0
  52. package/dist/src/firestore/useDeleteDocMutation.d.ts +7 -0
  53. package/dist/src/firestore/useDeleteDocMutation.js +7 -0
  54. package/dist/src/firestore/useDocReference.d.ts +12 -0
  55. package/dist/src/firestore/useDocReference.js +25 -1
  56. package/dist/src/firestore/useDocReferences.d.ts +16 -0
  57. package/dist/src/firestore/useDocReferences.js +17 -1
  58. package/dist/src/firestore/useFirestore.d.ts +7 -0
  59. package/dist/src/firestore/useFirestore.js +12 -0
  60. package/dist/src/firestore/useGetDocData.d.ts +8 -0
  61. package/dist/src/firestore/useGetDocData.js +9 -1
  62. package/dist/src/firestore/useInfiniteQuery.d.ts +7 -0
  63. package/dist/src/firestore/useInfiniteQuery.js +7 -0
  64. package/dist/src/firestore/useQuery.d.ts +14 -0
  65. package/dist/src/firestore/useQuery.js +14 -0
  66. package/dist/src/firestore/useRunTransaction.d.ts +7 -0
  67. package/dist/src/firestore/useRunTransaction.js +8 -1
  68. package/dist/src/firestore/useSetDocMutation.d.ts +9 -0
  69. package/dist/src/firestore/useSetDocMutation.js +9 -0
  70. package/dist/src/firestore/useUpdateDocMutation.d.ts +19 -0
  71. package/dist/src/firestore/useUpdateDocMutation.js +19 -0
  72. package/dist/src/firestore/utils/getDocData.d.ts +14 -0
  73. package/dist/src/firestore/utils/getDocData.js +14 -0
  74. package/dist/src/firestore/utils/getDocRef.d.ts +11 -0
  75. package/dist/src/firestore/utils/getDocRef.js +11 -0
  76. package/dist/src/firestore/utils/getDocSnap.d.ts +16 -0
  77. package/dist/src/firestore/utils/getDocSnap.js +16 -0
  78. package/dist/src/index.d.ts +1 -6
  79. package/dist/src/index.js +1 -6
  80. package/dist/src/remoteConfig/index.d.ts +1 -0
  81. package/dist/src/remoteConfig/index.js +1 -0
  82. package/dist/src/remoteConfig/useFetchAndActivate.d.ts +7 -0
  83. package/dist/src/remoteConfig/useFetchAndActivate.js +13 -4
  84. package/dist/src/remoteConfig/useGetValue.d.ts +6 -0
  85. package/dist/src/remoteConfig/useGetValue.js +7 -1
  86. package/dist/src/remoteConfig/useRemoteConfig.d.ts +5 -0
  87. package/dist/src/remoteConfig/useRemoteConfig.js +10 -0
  88. package/package.json +13 -5
  89. package/src/analytics/index.ts +1 -0
  90. package/src/analytics/useAnalytics.ts +12 -0
  91. package/src/analytics/useLogEvent.ts +8 -1
  92. package/src/auth/index.ts +2 -0
  93. package/src/auth/useAuth.ts +12 -0
  94. package/src/auth/useAuthStateReady.ts +6 -1
  95. package/src/auth/useCreateUserWitEmailAndPasswordMutation.ts +8 -1
  96. package/src/auth/useCurrentUser.ts +6 -1
  97. package/src/auth/useIdToken.ts +8 -0
  98. package/src/auth/useReauthenticateWitCredentialMutation.ts +8 -0
  99. package/src/auth/useReauthenticateWitRedirectMutation.ts +8 -0
  100. package/src/auth/useSendEmailVerificationMutation.ts +6 -0
  101. package/src/auth/useSignInWitEmailAndPasswordMutation.ts +8 -1
  102. package/src/auth/useSignInWitRedirectMutation.ts +7 -1
  103. package/src/auth/useSignOutMutation.ts +8 -1
  104. package/src/auth/useUpdateProfileMutation.ts +7 -0
  105. package/src/{FirebaseContext.ts → context/FirebaseContext.ts} +9 -2
  106. package/src/context/FirebaseContextProvider.tsx +173 -0
  107. package/src/context/index.ts +1 -0
  108. package/src/firestore/index.ts +1 -0
  109. package/src/firestore/useAddDocMutation.ts +11 -0
  110. package/src/firestore/useBatchWrite.ts +8 -1
  111. package/src/firestore/useCollectionReference.ts +12 -1
  112. package/src/firestore/useCompositeFilter.ts +18 -0
  113. package/src/firestore/useCountQuery.ts +14 -0
  114. package/src/firestore/useDeleteDocMutation.ts +7 -0
  115. package/src/firestore/useDocReference.ts +25 -1
  116. package/src/firestore/useDocReferences.ts +17 -1
  117. package/src/firestore/useFirestore.ts +13 -0
  118. package/src/firestore/useGetDocData.ts +9 -1
  119. package/src/firestore/useInfiniteQuery.ts +7 -0
  120. package/src/firestore/useQuery.ts +14 -0
  121. package/src/firestore/useRunTransaction.ts +8 -1
  122. package/src/firestore/useSetDocMutation.ts +9 -0
  123. package/src/firestore/useUpdateDocMutation.ts +19 -0
  124. package/src/firestore/utils/getDocData.ts +14 -0
  125. package/src/firestore/utils/getDocRef.ts +11 -0
  126. package/src/firestore/utils/getDocSnap.ts +16 -0
  127. package/src/index.ts +1 -6
  128. package/src/remoteConfig/index.ts +1 -0
  129. package/src/remoteConfig/useFetchAndActivate.ts +13 -4
  130. package/src/remoteConfig/useGetValue.ts +7 -1
  131. package/src/remoteConfig/useRemoteConfig.ts +11 -0
  132. package/dist/src/FirebaseContext.js +0 -3
  133. package/dist/src/FirebaseContextProvider.d.ts +0 -28
  134. package/dist/src/useAnalytics.d.ts +0 -1
  135. package/dist/src/useAnalytics.js +0 -6
  136. package/dist/src/useAuth.d.ts +0 -1
  137. package/dist/src/useAuth.js +0 -6
  138. package/dist/src/useFirebase.d.ts +0 -1
  139. package/dist/src/useFirebase.js +0 -6
  140. package/dist/src/useFirestore.d.ts +0 -1
  141. package/dist/src/useFirestore.js +0 -6
  142. package/dist/src/useRemoteConfig.d.ts +0 -1
  143. package/dist/src/useRemoteConfig.js +0 -6
  144. package/src/FirebaseContextProvider.tsx +0 -91
  145. package/src/firestore/useUpdateDocMutation copy.ts +0 -51
  146. package/src/useAnalytics.ts +0 -8
  147. package/src/useAuth.ts +0 -8
  148. package/src/useFirebase.ts +0 -8
  149. package/src/useFirestore.ts +0 -7
  150. package/src/useRemoteConfig.ts +0 -7
@@ -1,7 +1,13 @@
1
1
  import { getValue } from "firebase/remote-config";
2
- import { useRemoteConfig } from "../useRemoteConfig";
2
+ import { useRemoteConfig } from "./useRemoteConfig";
3
3
  import { useMemo } from "react";
4
4
 
5
+ /**
6
+ * Custom hook to retrieve a value associated with a specified key from remote configuration.
7
+ * Utilizes memoization to optimize performance by recalculating the result only if dependencies change.
8
+ * @param {string} key - The key for which the corresponding value is to be fetched from the remote configuration.
9
+ * @returns {any | null} The value associated with the specified key if available, otherwise null.
10
+ */
5
11
  export const useGetValue = (key: string) => {
6
12
  const remoteConfig = useRemoteConfig();
7
13
  return useMemo(() => {
@@ -0,0 +1,11 @@
1
+ import { useContext } from "react";
2
+ import { FirebaseContext } from "../context/FirebaseContext";
3
+
4
+ /**
5
+ * Hook to access the Firebase Remote Config instance from the context.
6
+ * @returns {RemoteConfig} The remoteConfig object from the Firebase context.
7
+ */
8
+ export const useRemoteConfig = () => {
9
+ const { remoteConfig } = useContext(FirebaseContext);
10
+ return remoteConfig;
11
+ };
@@ -1,3 +0,0 @@
1
- "use client";
2
- import { createContext } from "react";
3
- export const FirebaseContext = createContext({});
@@ -1,28 +0,0 @@
1
- import React, { PropsWithChildren } from "react";
2
- import { RemoteConfigSettings } from "firebase/remote-config";
3
- import { FirebaseOptions } from "firebase/app";
4
- type FirestorEmulatorConfig = {
5
- host: string;
6
- port: number;
7
- };
8
- type AuthEmulatorConfig = {
9
- host: string;
10
- };
11
- type Emulators = {
12
- firestore?: FirestorEmulatorConfig;
13
- auth?: AuthEmulatorConfig;
14
- };
15
- type FirebaseContextProvider = PropsWithChildren & {
16
- emulators?: Emulators;
17
- options: FirebaseOptions;
18
- authEnabled?: boolean;
19
- analyticsEnabled?: boolean;
20
- firestoreEnabled?: boolean;
21
- remoteConfigSettings?: RemoteConfigSettings;
22
- remoteConfigDefaults?: {
23
- [key: string]: string | number | boolean;
24
- };
25
- remoteConfigEnabled?: boolean;
26
- };
27
- export declare const FirebaseContextProvider: React.FC<FirebaseContextProvider>;
28
- export {};
@@ -1 +0,0 @@
1
- export declare const useAnalytics: () => import("@firebase/analytics").Analytics;
@@ -1,6 +0,0 @@
1
- import { useContext } from "react";
2
- import { FirebaseContext } from "./FirebaseContext";
3
- export const useAnalytics = () => {
4
- const { analytics } = useContext(FirebaseContext);
5
- return analytics;
6
- };
@@ -1 +0,0 @@
1
- export declare const useAuth: () => import("firebase/auth").Auth;
@@ -1,6 +0,0 @@
1
- import { useContext } from "react";
2
- import { FirebaseContext } from "./FirebaseContext";
3
- export const useAuth = () => {
4
- const { auth } = useContext(FirebaseContext);
5
- return auth;
6
- };
@@ -1 +0,0 @@
1
- export declare const useFirebase: () => import("@firebase/app").FirebaseApp;
@@ -1,6 +0,0 @@
1
- import { useContext } from "react";
2
- import { FirebaseContext } from "./FirebaseContext";
3
- export const useFirebase = () => {
4
- const { firebase } = useContext(FirebaseContext);
5
- return firebase;
6
- };
@@ -1 +0,0 @@
1
- export declare const useFirestore: () => import("@firebase/firestore").Firestore;
@@ -1,6 +0,0 @@
1
- import { useContext } from "react";
2
- import { FirebaseContext } from "./FirebaseContext";
3
- export const useFirestore = () => {
4
- const { firestore } = useContext(FirebaseContext);
5
- return firestore;
6
- };
@@ -1 +0,0 @@
1
- export declare const useRemoteConfig: () => import("@firebase/remote-config").RemoteConfig;
@@ -1,6 +0,0 @@
1
- import { useContext } from "react";
2
- import { FirebaseContext } from "./FirebaseContext";
3
- export const useRemoteConfig = () => {
4
- const { remoteConfig } = useContext(FirebaseContext);
5
- return remoteConfig;
6
- };
@@ -1,91 +0,0 @@
1
- import React, { PropsWithChildren, useMemo } from "react";
2
- import { FirebaseContext, FirebaseContextValue } from "./FirebaseContext";
3
- import { connectAuthEmulator, getAuth } from "firebase/auth";
4
- import { getAnalytics } from "firebase/analytics";
5
- import { getRemoteConfig, RemoteConfigSettings } from "firebase/remote-config";
6
- import { connectFirestoreEmulator, getFirestore } from "firebase/firestore";
7
- import { FirebaseOptions, initializeApp } from "firebase/app";
8
-
9
- type FirestorEmulatorConfig = {
10
- host: string;
11
- port: number;
12
- };
13
-
14
- type AuthEmulatorConfig = {
15
- host: string;
16
- };
17
-
18
- type Emulators = {
19
- firestore?: FirestorEmulatorConfig;
20
- auth?: AuthEmulatorConfig;
21
- };
22
-
23
- type FirebaseContextProvider = PropsWithChildren & {
24
- emulators?: Emulators;
25
- options: FirebaseOptions;
26
- authEnabled?: boolean;
27
- analyticsEnabled?: boolean;
28
- firestoreEnabled?: boolean;
29
- remoteConfigSettings?: RemoteConfigSettings;
30
- remoteConfigDefaults?: { [key: string]: string | number | boolean };
31
- remoteConfigEnabled?: boolean;
32
- };
33
-
34
- export const FirebaseContextProvider: React.FC<FirebaseContextProvider> = ({
35
- emulators,
36
- options,
37
- children,
38
- authEnabled = true,
39
- firestoreEnabled = true,
40
- analyticsEnabled = true,
41
- remoteConfigEnabled = true,
42
- remoteConfigSettings,
43
- remoteConfigDefaults = {}
44
- }) => {
45
- const firebase = useMemo(() => {
46
- return initializeApp(options);
47
- }, [options]);
48
-
49
- const contextValue = useMemo(() => {
50
- const value: Partial<FirebaseContextValue> = {};
51
-
52
- if (firestoreEnabled) {
53
- const firestore = getFirestore(firebase);
54
-
55
- if (emulators?.firestore?.host && emulators?.firestore?.port) {
56
- connectFirestoreEmulator(firestore, emulators.firestore.host, emulators.firestore.port);
57
- }
58
-
59
- value.firestore = firestore;
60
- }
61
-
62
- if (authEnabled) {
63
- const auth = getAuth(firebase);
64
- if (emulators?.auth?.host) {
65
- connectAuthEmulator(auth, emulators?.auth?.host, {
66
- disableWarnings: true
67
- });
68
- }
69
- value.auth = auth;
70
- }
71
-
72
- if (analyticsEnabled && options.measurementId && typeof window !== "undefined") {
73
- const analytics = getAnalytics(firebase);
74
- value.analytics = analytics;
75
- }
76
-
77
- if (remoteConfigEnabled && typeof window !== "undefined") {
78
- const remoteConfig = getRemoteConfig(firebase);
79
- if (remoteConfigSettings) {
80
- remoteConfig.settings.fetchTimeoutMillis = remoteConfigSettings.fetchTimeoutMillis;
81
- remoteConfig.settings.minimumFetchIntervalMillis = remoteConfigSettings.minimumFetchIntervalMillis;
82
- remoteConfig.defaultConfig = remoteConfigDefaults;
83
- }
84
- value.remoteConfig = remoteConfig;
85
- }
86
-
87
- return { firebase, ...value };
88
- }, [firebase]);
89
-
90
- return <FirebaseContext.Provider value={contextValue}>{children}</FirebaseContext.Provider>;
91
- };
@@ -1,51 +0,0 @@
1
- import { useMutation, UseMutationOptions } from "@tanstack/react-query";
2
- import {
3
- DocumentData,
4
- updateDoc,
5
- getDoc,
6
- FirestoreDataConverter,
7
- DocumentReference,
8
- UpdateData
9
- } from "firebase/firestore";
10
-
11
- import { FirebaseError } from "firebase/app";
12
- import { useMemo } from "react";
13
-
14
- export type UseUpdateDocMutationValues<DbModelType> = {
15
- data: UpdateData<DbModelType>;
16
- };
17
-
18
- export type UseUpdateDocMutationOptions<
19
- AppModelType extends DocumentData = DocumentData,
20
- DbModelType extends DocumentData = DocumentData,
21
- TContext = unknown
22
- > = {
23
- reference: DocumentReference<AppModelType, DbModelType>;
24
- converter?: FirestoreDataConverter<AppModelType, DbModelType>;
25
- options?: Omit<
26
- UseMutationOptions<AppModelType, FirebaseError, UseUpdateDocMutationValues<DbModelType>, TContext>,
27
- "mutationFn" | "mutationKey"
28
- >;
29
- };
30
-
31
- export const useUpdateDocMutation = <
32
- AppModelType extends DocumentData = DocumentData,
33
- DbModelType extends DocumentData = DocumentData,
34
- TContext = unknown
35
- >({
36
- reference,
37
- converter,
38
- options = {}
39
- }: UseUpdateDocMutationOptions<AppModelType, DbModelType, TContext>) => {
40
- const mutationKey = useMemo(() => [reference.path], [reference.path]);
41
-
42
- return useMutation({
43
- ...options,
44
- mutationFn: async ({ data }) => {
45
- await updateDoc<AppModelType, DbModelType>(reference, data);
46
- const docSnap = await getDoc(converter ? reference.withConverter(converter) : reference);
47
- return docSnap.data() as AppModelType;
48
- },
49
- mutationKey
50
- });
51
- };
@@ -1,8 +0,0 @@
1
- import { Context, useContext } from "react";
2
-
3
- import { FirebaseContext, FirebaseContextValue } from "./FirebaseContext";
4
-
5
- export const useAnalytics = () => {
6
- const { analytics } = useContext<FirebaseContextValue>(FirebaseContext as Context<FirebaseContextValue>);
7
- return analytics;
8
- };
package/src/useAuth.ts DELETED
@@ -1,8 +0,0 @@
1
- import { useContext, Context } from "react";
2
-
3
- import { FirebaseContext, FirebaseContextValue } from "./FirebaseContext";
4
-
5
- export const useAuth = () => {
6
- const { auth } = useContext<FirebaseContextValue>(FirebaseContext as Context<FirebaseContextValue>);
7
- return auth;
8
- };
@@ -1,8 +0,0 @@
1
- import { Context, useContext } from "react";
2
-
3
- import { FirebaseContext, FirebaseContextValue } from "./FirebaseContext";
4
-
5
- export const useFirebase = () => {
6
- const { firebase } = useContext<FirebaseContextValue>(FirebaseContext as Context<FirebaseContextValue>);
7
- return firebase;
8
- };
@@ -1,7 +0,0 @@
1
- import { Context, useContext } from "react";
2
- import { FirebaseContext, FirebaseContextValue } from "./FirebaseContext";
3
-
4
- export const useFirestore = () => {
5
- const { firestore } = useContext<FirebaseContextValue>(FirebaseContext as Context<FirebaseContextValue>);
6
- return firestore;
7
- };
@@ -1,7 +0,0 @@
1
- import { Context, useContext } from "react";
2
- import { FirebaseContext, FirebaseContextValue } from "./FirebaseContext";
3
-
4
- export const useRemoteConfig = () => {
5
- const { remoteConfig } = useContext<FirebaseContextValue>(FirebaseContext as Context<FirebaseContextValue>);
6
- return remoteConfig;
7
- };