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
package/package.json CHANGED
@@ -57,6 +57,7 @@
57
57
  "files": [
58
58
  "./web/",
59
59
  "./react-native/",
60
+ "./types",
60
61
  "package.json",
61
62
  "package-lock.json",
62
63
  "README.md",
@@ -68,10 +69,10 @@
68
69
  "lint:fix": "eslint --fix",
69
70
  "lint:staged": "lint-staged",
70
71
  "prepare": "husky",
71
- "docs:generate": "mv docs/.vitepress .vitepress && rm -rf docs && typedoc --plugin typedoc-plugin-markdown --plugin typedoc-vitepress-theme && mv .vitepress docs/.vitepress",
72
+ "docs:generate": "./.github/scripts/build.sh",
72
73
  "docs:dev": "vitepress dev docs",
73
74
  "docs:build": "vitepress build docs",
74
75
  "docs:preview": "vitepress preview docs"
75
76
  },
76
- "version": "2.0.3"
77
+ "version": "2.1.1"
77
78
  }
@@ -14,3 +14,4 @@ export * from "./useRunTransaction";
14
14
  export * from "./useSetDocMutation";
15
15
  export * from "./useUpdateDocMutation";
16
16
  export * from "./useGetRealtimeDocData";
17
+ export * from "./useQueryConstraints";
@@ -28,11 +28,11 @@ export type UseCompositeFilter<DbModelType extends CompositeFilterDocumentData =
28
28
  * @returns {QueryFieldFilterConstraint | null} A constructed query filter constraint based on the input query, or null if no valid constraints can be derived.
29
29
  */
30
30
 
31
- const buildCompositeQuery = <DbModelType extends CompositeFilterDocumentData = CompositeFilterDocumentData>(
31
+ export const buildCompositeFilter = <DbModelType extends CompositeFilterDocumentData = CompositeFilterDocumentData>(
32
32
  query: QueryElement<DbModelType>
33
33
  ): FirebaseFirestoreTypes.QueryFilterConstraint | null => {
34
34
  if (query.children) {
35
- const queryConstraints = query.children.map(buildCompositeQuery).filter((constraint) => !!constraint);
35
+ const queryConstraints = query.children.map(buildCompositeFilter).filter((constraint) => !!constraint);
36
36
 
37
37
  if (queryConstraints.length <= 0) {
38
38
  return null;
@@ -67,7 +67,7 @@ export const useCompositeFilter = <DbModelType extends CompositeFilterDocumentDa
67
67
  }: UseCompositeFilter<DbModelType>) => {
68
68
  return useMemo(() => {
69
69
  const queryConstraints =
70
- query?.children?.map?.((subQuery) => buildCompositeQuery(subQuery))
70
+ query?.children?.map?.((subQuery) => buildCompositeFilter(subQuery))
71
71
  ?.filter<FirebaseFirestoreTypes.QueryFilterConstraint>?.((constraint) => !!constraint) ?? [];
72
72
 
73
73
  if (queryConstraints.length <= 0) {
@@ -0,0 +1,84 @@
1
+ import { startAt, orderBy, limit, limitToLast, startAfter, endAt, endBefore } from "@react-native-firebase/firestore";
2
+ import { useMemo } from "react";
3
+ import { AppModel } from "../../types/AppModel";
4
+ import { type NonFilterQueryConstraint } from "../../types/QueryConstraints";
5
+
6
+ /**
7
+ * @inline
8
+ */
9
+ export type UseQueryConstraints<AppModelType extends AppModel = AppModel> = {
10
+ /**
11
+ * A list of constraints such as limit, order, offset.
12
+ */
13
+ constraints: NonFilterQueryConstraint<AppModelType>[];
14
+ };
15
+
16
+ /**
17
+ * A generic mothod to build query constraints for firebase
18
+ *
19
+ * @group Utility
20
+ *
21
+ * @param {NonFilterQueryConstraint<AppModelType>} constraint
22
+ *
23
+ * @returns {FirebaseFirestoreTypes.QueryNonFilterConstraint}
24
+ *
25
+ * @example
26
+ * ```jsx
27
+ * const firebaseConfig = {};
28
+ * export const constraint = useMemo(() => {
29
+ * return buildQueryConstraint({
30
+ * type: 'limit',
31
+ * limit: 1
32
+ * });
33
+ * };
34
+ * ```
35
+ */
36
+ export const buildQueryConstraint = <AppModelType extends AppModel = AppModel>(
37
+ constraint: NonFilterQueryConstraint<AppModelType>
38
+ ) => {
39
+ switch (constraint.type) {
40
+ case "orderBy":
41
+ return orderBy(constraint.fieldPath as string, constraint.directionStr);
42
+ case "startAt":
43
+ return startAt(...constraint.arguments);
44
+ case "startAfter":
45
+ return startAfter(...constraint.arguments);
46
+ case "endAt":
47
+ return endAt(constraint.value, constraint.key);
48
+ case "endBefore":
49
+ return endBefore(constraint.value, constraint.key);
50
+ case "limit":
51
+ return limit(constraint.limit);
52
+ case "limitToLast":
53
+ return limitToLast(constraint.limit);
54
+ }
55
+ };
56
+
57
+ /**
58
+ * A hook to build a list of non-filter query constraints for firebase queries.
59
+ * It uses buildQueryConstraint method and useMemo hook.
60
+ *
61
+ * @group Hook
62
+ *
63
+ * @param {UseQueryConstraints<AppModelType>} options
64
+ *
65
+ * @returns {FirebaseFirestoreTypes.QueryNonFilterConstraint}
66
+ *
67
+ * @example
68
+ * ```jsx
69
+ * const firebaseConfig = {};
70
+ * export const constraint = useQueryConstraints([
71
+ * {
72
+ * type: 'limit',
73
+ * limit: 1
74
+ * }
75
+ * ]};
76
+ * ```
77
+ */
78
+ export const useQueryConstraints = <AppModelType extends AppModel = AppModel>({
79
+ constraints
80
+ }: UseQueryConstraints<AppModelType>) => {
81
+ return useMemo(() => {
82
+ return constraints.map(buildQueryConstraint);
83
+ }, [constraints]);
84
+ };
@@ -1,5 +1 @@
1
- export * from "./analytics";
2
- export * from "./auth";
3
1
  export * from "./context";
4
- export * from "./firestore";
5
- export * from "./remoteConfig";
@@ -1,5 +1 @@
1
- export * from "./analytics";
2
- export * from "./auth";
3
1
  export * from "./context";
4
- export * from "./firestore";
5
- export * from "./remoteConfig";
@@ -1,5 +1 @@
1
- export * from "./analytics";
2
- export * from "./auth";
3
1
  export * from "./context";
4
- export * from "./firestore";
5
- export * from "./remoteConfig";
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Generic definition for a data model
3
+ * @group Models
4
+ */
5
+ export type AppModel = {
6
+ [key: string]: unknown;
7
+ };
@@ -0,0 +1,58 @@
1
+ import { AppModel } from "./AppModel";
2
+
3
+ /**
4
+ * Order by constraint
5
+ * @group Query Constraints
6
+ */
7
+ export type OrderByConstraint<AppModelType extends AppModel = AppModel> = {
8
+ /**
9
+ * Type of a constraint
10
+ */
11
+ type: "orderBy";
12
+ /**
13
+ * Field path to use for ordering
14
+ */
15
+ fieldPath: keyof AppModelType;
16
+ /**
17
+ * Direction of ordering: asc or desc
18
+ */
19
+ directionStr: "asc" | "desc";
20
+ };
21
+
22
+ /**
23
+ * Start from value constraint
24
+ * @group Query Constraints
25
+ */
26
+ export type StartConstraint = {
27
+ type: "startAt" | "startAfter";
28
+ arguments: unknown[];
29
+ };
30
+
31
+ /**
32
+ * End by value constraint
33
+ * @group Query Constraints
34
+ */
35
+ export type EndConstraint = {
36
+ type: "endAt" | "endBefore";
37
+ value: number | string | boolean | null;
38
+ key?: string;
39
+ };
40
+
41
+ /**
42
+ * Limit constraint
43
+ * @group Query Constraints
44
+ */
45
+ export type LimitConstraint = {
46
+ type: "limitToLast" | "limit";
47
+ limit: number;
48
+ };
49
+
50
+ /**
51
+ * Non filtering query constaints
52
+ * @group Query Constraints
53
+ */
54
+ export type NonFilterQueryConstraint<AppModelType extends AppModel = AppModel> =
55
+ | OrderByConstraint<AppModelType>
56
+ | StartConstraint
57
+ | EndConstraint
58
+ | LimitConstraint;
package/types/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./AppModel";
2
+ export * from "./QueryConstraints";
@@ -14,3 +14,4 @@ export * from "./useRunTransaction";
14
14
  export * from "./useSetDocMutation";
15
15
  export * from "./useUpdateDocMutation";
16
16
  export * from "./useGetRealtimeDocData";
17
+ export * from "./useQueryConstraints";
@@ -28,11 +28,11 @@ export type UseCompositeFilter<DbModelType extends CompositeFilterDocumentData =
28
28
  * @returns {QueryFieldFilterConstraint | null} A constructed query filter constraint based on the input query, or null if no valid constraints can be derived.
29
29
  */
30
30
 
31
- const buildCompositeQuery = <DbModelType extends CompositeFilterDocumentData = CompositeFilterDocumentData>(
31
+ export const buildCompositeFilter = <DbModelType extends CompositeFilterDocumentData = CompositeFilterDocumentData>(
32
32
  query: QueryElement<DbModelType>
33
33
  ): QueryFilterConstraint | null => {
34
34
  if (query.children) {
35
- const queryConstraints = query.children.map(buildCompositeQuery).filter((constraint) => !!constraint);
35
+ const queryConstraints = query.children.map(buildCompositeFilter).filter((constraint) => !!constraint);
36
36
 
37
37
  if (queryConstraints.length <= 0) {
38
38
  return null;
@@ -63,7 +63,7 @@ export const useCompositeFilter = <DbModelType extends CompositeFilterDocumentDa
63
63
  }: UseCompositeFilter<DbModelType>) => {
64
64
  return useMemo(() => {
65
65
  const queryConstraints =
66
- query?.children?.map?.((subQuery) => buildCompositeQuery(subQuery))?.filter<QueryFilterConstraint>?.(
66
+ query?.children?.map?.((subQuery) => buildCompositeFilter(subQuery))?.filter<QueryFilterConstraint>?.(
67
67
  (constraint) => !!constraint
68
68
  ) ?? [];
69
69
 
@@ -0,0 +1,93 @@
1
+ import {
2
+ QueryNonFilterConstraint,
3
+ startAt,
4
+ orderBy,
5
+ limit,
6
+ limitToLast,
7
+ startAfter,
8
+ endAt,
9
+ endBefore
10
+ } from "firebase/firestore";
11
+ import { AppModel } from "../../types/AppModel";
12
+ import { NonFilterQueryConstraint } from "../../types/QueryConstraints";
13
+ import { useMemo } from "react";
14
+
15
+ /**
16
+ * @inline
17
+ */
18
+ export type UseQueryConstraints<AppModelType extends AppModel = AppModel> = {
19
+ /**
20
+ * A list of constraints such as limit, order, offset.
21
+ */
22
+ constraints: NonFilterQueryConstraint<AppModelType>[];
23
+ };
24
+
25
+ /**
26
+ * A generic mothod to build query constraints for firebase
27
+ *
28
+ * @group Utility
29
+ *
30
+ * @param {NonFilterQueryConstraint<AppModelType>} constraint
31
+ *
32
+ * @returns {QueryNonFilterConstraint}
33
+ *
34
+ * @example
35
+ * ```jsx
36
+ * const firebaseConfig = {};
37
+ * export const constraint = useMemo(() => {
38
+ * return buildQueryConstraint({
39
+ * type: 'limit',
40
+ * limit: 1
41
+ * });
42
+ * };
43
+ * ```
44
+ */
45
+ export const buildQueryConstraint = <AppModelType extends AppModel = AppModel>(
46
+ constraint: NonFilterQueryConstraint<AppModelType>
47
+ ): QueryNonFilterConstraint => {
48
+ switch (constraint.type) {
49
+ case "orderBy":
50
+ return orderBy(constraint.fieldPath as string, constraint.directionStr);
51
+ case "startAt":
52
+ return startAt(...constraint.arguments);
53
+ case "startAfter":
54
+ return startAfter(...constraint.arguments);
55
+ case "endAt":
56
+ return endAt(constraint.value, constraint.key);
57
+ case "endBefore":
58
+ return endBefore(constraint.value, constraint.key);
59
+ case "limit":
60
+ return limit(constraint.limit);
61
+ case "limitToLast":
62
+ return limitToLast(constraint.limit);
63
+ }
64
+ };
65
+
66
+ /**
67
+ * A hook to build a list of non-filter query constraints for firebase queries.
68
+ * It uses buildQueryConstraint method and useMemo hook.
69
+ *
70
+ * @group Hook
71
+ *
72
+ * @param {UseQueryConstraints<AppModelType>} constraints
73
+ *
74
+ * @returns {QueryNonFilterConstraint[]}
75
+ *
76
+ * @example
77
+ * ```jsx
78
+ * const firebaseConfig = {};
79
+ * export const constraint = useQueryConstraints([
80
+ * {
81
+ * type: 'limit',
82
+ * limit: 1
83
+ * }
84
+ * ]};
85
+ * ```
86
+ */
87
+ export const useQueryConstraints = <AppModelType extends AppModel = AppModel>({
88
+ constraints
89
+ }: UseQueryConstraints<AppModelType>): QueryNonFilterConstraint[] => {
90
+ return useMemo(() => {
91
+ return constraints.map(buildQueryConstraint);
92
+ }, [constraints]);
93
+ };
package/web/index.d.ts CHANGED
@@ -1,5 +1 @@
1
- export * from "./analytics";
2
- export * from "./auth";
3
1
  export * from "./context";
4
- export * from "./firestore";
5
- export * from "./remoteConfig";
package/web/index.js CHANGED
@@ -1,5 +1 @@
1
- export * from "./analytics";
2
- export * from "./auth";
3
1
  export * from "./context";
4
- export * from "./firestore";
5
- export * from "./remoteConfig";
package/web/index.ts CHANGED
@@ -1,5 +1 @@
1
- export * from "./analytics";
2
- export * from "./auth";
3
1
  export * from "./context";
4
- export * from "./firestore";
5
- export * from "./remoteConfig";
@@ -1,3 +0,0 @@
1
- export * from "./useLogEvent";
2
- export * from "./useAnalytics";
3
- export * from "./useSetAnalyticsCollectionEnabled";
@@ -1,3 +0,0 @@
1
- export * from "./useLogEvent";
2
- export * from "./useAnalytics";
3
- export * from "./useSetAnalyticsCollectionEnabled";
@@ -1,5 +0,0 @@
1
- /**
2
- * Hook to access Firebase analytics from the Firebase context.
3
- * @returns {any} The analytics object from the Firebase context.
4
- */
5
- export declare const useAnalytics: () => import("@react-native-firebase/analytics").FirebaseAnalyticsTypes.Module;
@@ -1,10 +0,0 @@
1
- import { useContext } from "react";
2
- import { FirebaseContext } from "../context/FirebaseContext";
3
- /**
4
- * Hook to access Firebase analytics from the Firebase context.
5
- * @returns {any} The analytics object from the Firebase context.
6
- */
7
- export const useAnalytics = () => {
8
- const { analytics } = useContext(FirebaseContext);
9
- return analytics;
10
- };
@@ -1,17 +0,0 @@
1
- type UseLogEventOptions = {
2
- eventName: string;
3
- eventParams?: {
4
- [key: string]: unknown;
5
- };
6
- };
7
- /**
8
- * Custom hook to create a log event function that logs an analytics event with specified parameters.
9
- * @param {Object} options - The options for the log event.
10
- * @param {string} options.eventName - The name of the event to be logged.
11
- * @param {Object} options.eventParams - The parameters to be sent along with the event.
12
- * @returns {Object} An object containing a `logEvent` function that, when called, logs the event.
13
- */
14
- export declare const useLogEvent: ({ eventName, eventParams }: UseLogEventOptions) => {
15
- logEvent: () => void;
16
- };
17
- export {};
@@ -1,21 +0,0 @@
1
- import { logEvent } from "@react-native-firebase/analytics";
2
- import { useAnalytics } from "./useAnalytics";
3
- import { useCallback, useMemo } from "react";
4
- /**
5
- * Custom hook to create a log event function that logs an analytics event with specified parameters.
6
- * @param {Object} options - The options for the log event.
7
- * @param {string} options.eventName - The name of the event to be logged.
8
- * @param {Object} options.eventParams - The parameters to be sent along with the event.
9
- * @returns {Object} An object containing a `logEvent` function that, when called, logs the event.
10
- */
11
- export const useLogEvent = ({ eventName, eventParams }) => {
12
- const analytics = useAnalytics();
13
- const logEventCallback = useCallback(() => {
14
- if (analytics) {
15
- logEvent(analytics, eventName, eventParams);
16
- }
17
- }, [eventName, eventParams, analytics]);
18
- return useMemo(() => ({
19
- logEvent: logEventCallback
20
- }), [logEventCallback]);
21
- };
@@ -1,10 +0,0 @@
1
- type UseSetAnalyticsCollectionEnabledOptions = {
2
- enabled?: boolean;
3
- };
4
- /**
5
- * Custom hook to enable or disable analytics collection
6
- * @param {Object} options - The options for hook.
7
- * @param {string} options.enabled - Flag that identifies if analytics collection is enabled.
8
- */
9
- export declare const useSetAnalyticsCollectionEnabled: ({ enabled }: UseSetAnalyticsCollectionEnabledOptions) => void;
10
- export {};
@@ -1,16 +0,0 @@
1
- import { setAnalyticsCollectionEnabled } from "@react-native-firebase/analytics";
2
- import { useAnalytics } from "./useAnalytics";
3
- import { useEffect } from "react";
4
- /**
5
- * Custom hook to enable or disable analytics collection
6
- * @param {Object} options - The options for hook.
7
- * @param {string} options.enabled - Flag that identifies if analytics collection is enabled.
8
- */
9
- export const useSetAnalyticsCollectionEnabled = ({ enabled = false }) => {
10
- const analytics = useAnalytics();
11
- useEffect(() => {
12
- if (analytics) {
13
- setAnalyticsCollectionEnabled(analytics, enabled);
14
- }
15
- }, [analytics, enabled]);
16
- };
@@ -1,12 +0,0 @@
1
- export * from "./mutation-keys";
2
- export * from "./useAuth";
3
- export * from "./useCreateUserWitEmailAndPasswordMutation";
4
- export * from "./useSendEmailVerificationMutation";
5
- export * from "./useSignInWitEmailAndPasswordMutation";
6
- export * from "./useCurrentUser";
7
- export * from "./useSignInWitRedirectMutation";
8
- export * from "./useUpdateProfileMutation";
9
- export * from "./useSignOutMutation";
10
- export * from "./useIdToken";
11
- export * from "./useReauthenticateWitCredentialMutation";
12
- export * from "./useReauthenticateWitRedirectMutation";
@@ -1,12 +0,0 @@
1
- export * from "./mutation-keys";
2
- export * from "./useAuth";
3
- export * from "./useCreateUserWitEmailAndPasswordMutation";
4
- export * from "./useSendEmailVerificationMutation";
5
- export * from "./useSignInWitEmailAndPasswordMutation";
6
- export * from "./useCurrentUser";
7
- export * from "./useSignInWitRedirectMutation";
8
- export * from "./useUpdateProfileMutation";
9
- export * from "./useSignOutMutation";
10
- export * from "./useIdToken";
11
- export * from "./useReauthenticateWitCredentialMutation";
12
- export * from "./useReauthenticateWitRedirectMutation";
@@ -1,7 +0,0 @@
1
- export declare const CREATE_USER_WITH_EMAIL_AND_PASSWORD_MUTATION_KEY: readonly ["FIREBASE", "AUTH", "CREATE_USER_WITH_EMAIL_AND_PASSWORD_MUTATION"];
2
- export declare const SEND_EMAIL_VERIFICATION_MUTATION_KEY: readonly ["FIREBASE", "AUTH", "SEND_EMAIL_VERIFICATION_MUTATION"];
3
- export declare const SIGN_IN_WITH_EMAIL_AND_PASSWORD_MUTATION_KEY: readonly ["FIREBASE", "AUTH", "SIGN_IN_WITH_EMAIL_AND_PASSWORD_MUTATION"];
4
- export declare const SIGN_IN_WITH_REDIRECT_MUTATION_KEY: readonly ["FIREBASE", "AUTH", "SIGN_IN_WITH_REDIRECT_MUTATION"];
5
- export declare const SIGN_OUT_MUTATION_KEY: readonly ["FIREBASE", "AUTH", "SIGN_OUT"];
6
- export declare const REAUTHENTICATE_WITH_REDIRECT_MUTATION_KEY: readonly ["FIREBASE", "AUTH", "REAUTHENTICATE_WITH_REDIRECT"];
7
- export declare const REAUTHENTICATE_WITH_CREDENTIAL_MUTATION_KEY: readonly ["FIREBASE", "AUTH", "REAUTHENTICATE_WITH_CREDENTIAL"];
@@ -1,19 +0,0 @@
1
- export const CREATE_USER_WITH_EMAIL_AND_PASSWORD_MUTATION_KEY = [
2
- "FIREBASE",
3
- "AUTH",
4
- "CREATE_USER_WITH_EMAIL_AND_PASSWORD_MUTATION"
5
- ];
6
- export const SEND_EMAIL_VERIFICATION_MUTATION_KEY = ["FIREBASE", "AUTH", "SEND_EMAIL_VERIFICATION_MUTATION"];
7
- export const SIGN_IN_WITH_EMAIL_AND_PASSWORD_MUTATION_KEY = [
8
- "FIREBASE",
9
- "AUTH",
10
- "SIGN_IN_WITH_EMAIL_AND_PASSWORD_MUTATION"
11
- ];
12
- export const SIGN_IN_WITH_REDIRECT_MUTATION_KEY = ["FIREBASE", "AUTH", "SIGN_IN_WITH_REDIRECT_MUTATION"];
13
- export const SIGN_OUT_MUTATION_KEY = ["FIREBASE", "AUTH", "SIGN_OUT"];
14
- export const REAUTHENTICATE_WITH_REDIRECT_MUTATION_KEY = ["FIREBASE", "AUTH", "REAUTHENTICATE_WITH_REDIRECT"];
15
- export const REAUTHENTICATE_WITH_CREDENTIAL_MUTATION_KEY = [
16
- "FIREBASE",
17
- "AUTH",
18
- "REAUTHENTICATE_WITH_CREDENTIAL"
19
- ];
@@ -1,5 +0,0 @@
1
- /**
2
- * Custom hook to retrieve the authentication object from the Firebase context.
3
- * @returns {Auth} The authentication object from the Firebase context.
4
- */
5
- export declare const useAuth: () => import("@react-native-firebase/auth").FirebaseAuthTypes.Module;
@@ -1,10 +0,0 @@
1
- import { useContext } from "react";
2
- import { FirebaseContext } from "../context/FirebaseContext";
3
- /**
4
- * Custom hook to retrieve the authentication object from the Firebase context.
5
- * @returns {Auth} The authentication object from the Firebase context.
6
- */
7
- export const useAuth = () => {
8
- const { auth } = useContext(FirebaseContext);
9
- return auth;
10
- };
@@ -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 UseCreateUserWitEmailAndPasswordMutationVariables = {
5
- email: string;
6
- password: string;
7
- };
8
- /**
9
- * Custom hook to initiate a user creation process using email and password with Firebase authentication.
10
- * This hook utilizes the `useMutation` functionality to support creating new user credentials asynchronously.
11
- *
12
- * @param {Omit<UseMutationOptions<FirebaseAuthTypes.UserCredential, ReactNativeFirebase.NativeFirebaseError, UseCreateUserWitEmailAndPasswordMutationVariables, TContext>, "mutationKey" | "mutationFn">} options - Optional settings to customize the mutation behavior, excluding `mutationKey` and `mutationFn`.
13
- * @returns {UseMutationResult<FirebaseAuthTypes.UserCredential, ReactNativeFirebase.NativeFirebaseError, UseCreateUserWitEmailAndPasswordMutationVariables, TContext>} The result of the mutation which includes status, user credentials, and error information if any.
14
- */
15
- export declare const useCreateUserWitEmailAndPasswordMutation: <TContext = unknown>(options?: Omit<UseMutationOptions<FirebaseAuthTypes.UserCredential, ReactNativeFirebase.NativeFirebaseError, UseCreateUserWitEmailAndPasswordMutationVariables, TContext>, "mutationKey" | "mutationFn">) => import("@tanstack/react-query").UseMutationResult<FirebaseAuthTypes.UserCredential, ReactNativeFirebase.NativeFirebaseError, UseCreateUserWitEmailAndPasswordMutationVariables, TContext>;
@@ -1,19 +0,0 @@
1
- import { useMutation } from "@tanstack/react-query";
2
- import { createUserWithEmailAndPassword } from "@react-native-firebase/auth";
3
- import { useAuth } from "./useAuth";
4
- import { CREATE_USER_WITH_EMAIL_AND_PASSWORD_MUTATION_KEY } from "./mutation-keys";
5
- /**
6
- * Custom hook to initiate a user creation process using email and password with Firebase authentication.
7
- * This hook utilizes the `useMutation` functionality to support creating new user credentials asynchronously.
8
- *
9
- * @param {Omit<UseMutationOptions<FirebaseAuthTypes.UserCredential, ReactNativeFirebase.NativeFirebaseError, UseCreateUserWitEmailAndPasswordMutationVariables, TContext>, "mutationKey" | "mutationFn">} options - Optional settings to customize the mutation behavior, excluding `mutationKey` and `mutationFn`.
10
- * @returns {UseMutationResult<FirebaseAuthTypes.UserCredential, ReactNativeFirebase.NativeFirebaseError, UseCreateUserWitEmailAndPasswordMutationVariables, TContext>} The result of the mutation which includes status, user credentials, and error information if any.
11
- */
12
- export const useCreateUserWitEmailAndPasswordMutation = (options = {}) => {
13
- const firebaseAuth = useAuth();
14
- return useMutation({
15
- ...options,
16
- mutationFn: async ({ email, password }) => await createUserWithEmailAndPassword(firebaseAuth, email, password),
17
- mutationKey: CREATE_USER_WITH_EMAIL_AND_PASSWORD_MUTATION_KEY
18
- });
19
- };
@@ -1,6 +0,0 @@
1
- /**
2
- * Hook that provides the current authenticated user from Firebase Auth.
3
- * It listens for changes in the authentication state and updates the user accordingly.
4
- * @returns {Object|null} The current authenticated user object or null if no user is authenticated.
5
- */
6
- export declare const useCurrentUser: () => import("@react-native-firebase/auth").FirebaseAuthTypes.User | null;
@@ -1,20 +0,0 @@
1
- import { useAuth } from "./useAuth";
2
- import { useEffect, useState } from "react";
3
- /**
4
- * Hook that provides the current authenticated user from Firebase Auth.
5
- * It listens for changes in the authentication state and updates the user accordingly.
6
- * @returns {Object|null} The current authenticated user object or null if no user is authenticated.
7
- */
8
- export const useCurrentUser = () => {
9
- const { onAuthStateChanged, currentUser: fbCurrentUser } = useAuth();
10
- const [currentUser, setCurrentUser] = useState(fbCurrentUser);
11
- useEffect(() => {
12
- const unsubscribe = onAuthStateChanged((user) => {
13
- setCurrentUser(user);
14
- });
15
- return () => {
16
- unsubscribe();
17
- };
18
- }, [currentUser?.uid, onAuthStateChanged]);
19
- return currentUser;
20
- };
@@ -1,30 +0,0 @@
1
- /**
2
- * @inline
3
- */
4
- export type UseIdTokenResult = {
5
- idToken: string;
6
- refresh: () => Promise<string | undefined>;
7
- };
8
- /**
9
- * A hook to manage the ID token.
10
- * It monitors changes to the ID token and provides the token itself along with a refresh method to update the token when needed.
11
- *
12
- * @group Hook
13
- *
14
- * @returns {UseIdTokenResult}
15
- *
16
- * @example
17
- * ```jsx
18
- * export const MyComponent = () => {
19
- * const result = useIdToken();
20
- * useEffect(() => {
21
- * const timeout = setTimeout(() => {
22
- * result.refresh();
23
- * }, 5000);
24
- * return () => clearTimeout();
25
- * }, [])
26
- * console.log(resilt.idToken);
27
- * };
28
- * ```
29
- */
30
- export declare const useIdToken: () => UseIdTokenResult;