react-query-firebase 2.3.2 → 2.4.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 (133) hide show
  1. package/package.json +1 -1
  2. package/react-native/firestore/index.d.ts +5 -0
  3. package/react-native/firestore/index.js +5 -0
  4. package/react-native/firestore/index.ts +5 -0
  5. package/react-native/firestore/useAddDocMutation.d.ts +38 -9
  6. package/react-native/firestore/useAddDocMutation.js +25 -11
  7. package/react-native/firestore/useAddDocMutation.ts +43 -13
  8. package/react-native/firestore/useBatchWrite.d.ts +31 -7
  9. package/react-native/firestore/useBatchWrite.js +22 -4
  10. package/react-native/firestore/useBatchWrite.ts +31 -7
  11. package/react-native/firestore/useCollectionReference.d.ts +30 -9
  12. package/react-native/firestore/useCollectionReference.js +15 -7
  13. package/react-native/firestore/useCollectionReference.ts +34 -25
  14. package/react-native/firestore/useCompositeFilter.d.ts +1 -46
  15. package/react-native/firestore/useCompositeFilter.js +2 -45
  16. package/react-native/firestore/useCompositeFilter.ts +2 -74
  17. package/react-native/firestore/useCountQuery.d.ts +1 -1
  18. package/react-native/firestore/useCountQuery.ts +1 -1
  19. package/react-native/firestore/useDeleteDocMutation.d.ts +39 -10
  20. package/react-native/firestore/useDeleteDocMutation.js +22 -5
  21. package/react-native/firestore/useDeleteDocMutation.ts +38 -15
  22. package/react-native/firestore/useDocReference.d.ts +22 -14
  23. package/react-native/firestore/useDocReference.js +20 -26
  24. package/react-native/firestore/useDocReference.ts +34 -47
  25. package/react-native/firestore/useDocReferences.d.ts +23 -18
  26. package/react-native/firestore/useDocReferences.js +18 -19
  27. package/react-native/firestore/useDocReferences.ts +26 -34
  28. package/react-native/firestore/useFirestore.d.ts +4 -3
  29. package/react-native/firestore/useFirestore.js +4 -3
  30. package/react-native/firestore/useFirestore.ts +4 -3
  31. package/react-native/firestore/useGetDocData.d.ts +33 -14
  32. package/react-native/firestore/useGetDocData.js +21 -6
  33. package/react-native/firestore/useGetDocData.ts +34 -22
  34. package/react-native/firestore/useInfiniteQuery.d.ts +2 -2
  35. package/react-native/firestore/useInfiniteQuery.ts +3 -3
  36. package/react-native/firestore/useQuery.d.ts +1 -1
  37. package/react-native/firestore/useQuery.ts +1 -1
  38. package/react-native/firestore/useQueryConstraints.d.ts +2 -22
  39. package/react-native/firestore/useQueryConstraints.js +1 -39
  40. package/react-native/firestore/useQueryConstraints.ts +3 -43
  41. package/react-native/firestore/useRunTransaction.d.ts +33 -9
  42. package/react-native/firestore/useRunTransaction.js +20 -4
  43. package/react-native/firestore/useRunTransaction.ts +35 -16
  44. package/react-native/firestore/useSetDocMutation.d.ts +43 -11
  45. package/react-native/firestore/useSetDocMutation.js +28 -11
  46. package/react-native/firestore/useSetDocMutation.ts +49 -28
  47. package/react-native/firestore/useUpdateDocMutation.d.ts +40 -18
  48. package/react-native/firestore/useUpdateDocMutation.js +18 -13
  49. package/react-native/firestore/useUpdateDocMutation.ts +40 -31
  50. package/react-native/firestore/utils/buildCompositeFilter.d.ts +47 -0
  51. package/react-native/firestore/utils/buildCompositeFilter.js +45 -0
  52. package/react-native/firestore/utils/buildCompositeFilter.ts +75 -0
  53. package/react-native/firestore/utils/buildQueryConstraint.d.ts +23 -0
  54. package/react-native/firestore/utils/buildQueryConstraint.js +41 -0
  55. package/react-native/firestore/utils/buildQueryConstraint.ts +54 -0
  56. package/react-native/firestore/utils/getDocData.d.ts +11 -11
  57. package/react-native/firestore/utils/getDocData.js +5 -8
  58. package/react-native/firestore/utils/getDocData.ts +12 -16
  59. package/react-native/firestore/utils/getDocRef.d.ts +12 -9
  60. package/react-native/firestore/utils/getDocRef.js +7 -8
  61. package/react-native/firestore/utils/getDocRef.ts +12 -13
  62. package/react-native/firestore/utils/getDocSnap.d.ts +11 -13
  63. package/react-native/firestore/utils/getDocSnap.js +5 -10
  64. package/react-native/firestore/utils/getDocSnap.ts +12 -17
  65. package/types/AppModel.d.ts +4 -1
  66. package/types/AppModel.ts +4 -1
  67. package/web/firestore/index.d.ts +5 -0
  68. package/web/firestore/index.js +5 -0
  69. package/web/firestore/index.ts +5 -0
  70. package/web/firestore/useAddDocMutation.d.ts +41 -13
  71. package/web/firestore/useAddDocMutation.js +27 -14
  72. package/web/firestore/useAddDocMutation.ts +49 -37
  73. package/web/firestore/useBatchWrite.d.ts +34 -7
  74. package/web/firestore/useBatchWrite.js +22 -4
  75. package/web/firestore/useBatchWrite.ts +34 -7
  76. package/web/firestore/useCollectionReference.d.ts +32 -11
  77. package/web/firestore/useCollectionReference.js +15 -7
  78. package/web/firestore/useCollectionReference.ts +34 -13
  79. package/web/firestore/useCompositeFilter.d.ts +2 -47
  80. package/web/firestore/useCompositeFilter.js +2 -42
  81. package/web/firestore/useCompositeFilter.ts +2 -72
  82. package/web/firestore/useCountQuery.d.ts +4 -4
  83. package/web/firestore/useCountQuery.ts +5 -5
  84. package/web/firestore/useDeleteDocMutation.d.ts +41 -11
  85. package/web/firestore/useDeleteDocMutation.js +24 -7
  86. package/web/firestore/useDeleteDocMutation.ts +45 -23
  87. package/web/firestore/useDocReference.d.ts +23 -15
  88. package/web/firestore/useDocReference.js +16 -31
  89. package/web/firestore/useDocReference.ts +28 -46
  90. package/web/firestore/useDocReferences.d.ts +23 -18
  91. package/web/firestore/useDocReferences.js +18 -21
  92. package/web/firestore/useDocReferences.ts +26 -30
  93. package/web/firestore/useFirestore.d.ts +4 -3
  94. package/web/firestore/useFirestore.js +4 -3
  95. package/web/firestore/useFirestore.ts +4 -3
  96. package/web/firestore/useGetDocData.d.ts +32 -13
  97. package/web/firestore/useGetDocData.js +21 -6
  98. package/web/firestore/useGetDocData.ts +34 -23
  99. package/web/firestore/useGetRealtimeDocData.js +2 -2
  100. package/web/firestore/useGetRealtimeDocData.ts +2 -2
  101. package/web/firestore/useInfiniteQuery.d.ts +2 -2
  102. package/web/firestore/useInfiniteQuery.js +1 -1
  103. package/web/firestore/useInfiniteQuery.ts +4 -4
  104. package/web/firestore/useQuery.d.ts +1 -1
  105. package/web/firestore/useQuery.js +1 -1
  106. package/web/firestore/useQuery.ts +2 -2
  107. package/web/firestore/useQueryConstraints.d.ts +0 -21
  108. package/web/firestore/useQueryConstraints.js +1 -39
  109. package/web/firestore/useQueryConstraints.ts +2 -51
  110. package/web/firestore/useRunTransaction.d.ts +33 -8
  111. package/web/firestore/useRunTransaction.js +20 -4
  112. package/web/firestore/useRunTransaction.ts +35 -10
  113. package/web/firestore/useSetDocMutation.d.ts +45 -12
  114. package/web/firestore/useSetDocMutation.js +28 -11
  115. package/web/firestore/useSetDocMutation.ts +51 -26
  116. package/web/firestore/useUpdateDocMutation.d.ts +42 -20
  117. package/web/firestore/useUpdateDocMutation.js +20 -15
  118. package/web/firestore/useUpdateDocMutation.ts +45 -41
  119. package/web/firestore/utils/buildCompositeFilter.d.ts +47 -0
  120. package/web/firestore/utils/buildCompositeFilter.js +42 -0
  121. package/web/firestore/utils/buildCompositeFilter.ts +73 -0
  122. package/web/firestore/utils/buildQueryConstraint.d.ts +23 -0
  123. package/web/firestore/utils/buildQueryConstraint.js +41 -0
  124. package/web/firestore/utils/buildQueryConstraint.ts +55 -0
  125. package/web/firestore/utils/getDocData.d.ts +13 -11
  126. package/web/firestore/utils/getDocData.js +6 -9
  127. package/web/firestore/utils/getDocData.ts +14 -20
  128. package/web/firestore/utils/getDocRef.d.ts +14 -11
  129. package/web/firestore/utils/getDocRef.js +7 -8
  130. package/web/firestore/utils/getDocRef.ts +16 -19
  131. package/web/firestore/utils/getDocSnap.d.ts +11 -13
  132. package/web/firestore/utils/getDocSnap.js +5 -10
  133. package/web/firestore/utils/getDocSnap.ts +14 -21
package/package.json CHANGED
@@ -74,5 +74,5 @@
74
74
  "docs:build": "vitepress build docs",
75
75
  "docs:preview": "vitepress preview docs"
76
76
  },
77
- "version": "2.3.2"
77
+ "version": "2.4.0"
78
78
  }
@@ -15,3 +15,8 @@ export * from "./useSetDocMutation";
15
15
  export * from "./useUpdateDocMutation";
16
16
  export * from "./useGetRealtimeDocData";
17
17
  export * from "./useQueryConstraints";
18
+ export * from "./utils/getDocData";
19
+ export * from "./utils/getDocSnap";
20
+ export * from "./utils/getDocRef";
21
+ export * from "./utils/buildQueryConstraint";
22
+ export * from "./utils/buildCompositeFilter";
@@ -15,3 +15,8 @@ export * from "./useSetDocMutation";
15
15
  export * from "./useUpdateDocMutation";
16
16
  export * from "./useGetRealtimeDocData";
17
17
  export * from "./useQueryConstraints";
18
+ export * from "./utils/getDocData";
19
+ export * from "./utils/getDocSnap";
20
+ export * from "./utils/getDocRef";
21
+ export * from "./utils/buildQueryConstraint";
22
+ export * from "./utils/buildCompositeFilter";
@@ -15,3 +15,8 @@ export * from "./useSetDocMutation";
15
15
  export * from "./useUpdateDocMutation";
16
16
  export * from "./useGetRealtimeDocData";
17
17
  export * from "./useQueryConstraints";
18
+ export * from "./utils/getDocData";
19
+ export * from "./utils/getDocSnap";
20
+ export * from "./utils/getDocRef";
21
+ export * from "./utils/buildQueryConstraint";
22
+ export * from "./utils/buildCompositeFilter";
@@ -1,21 +1,50 @@
1
1
  import { UseMutationOptions } from "@tanstack/react-query";
2
2
  import { FirebaseFirestoreTypes, WithFieldValue } from "@react-native-firebase/firestore";
3
3
  import { ReactNativeFirebase } from "@react-native-firebase/app";
4
+ /**
5
+ * @inline
6
+ */
4
7
  export type UseAddDocMutationValues<AppModelType> = {
8
+ /**
9
+ * Data to write
10
+ */
5
11
  data: WithFieldValue<AppModelType>;
6
12
  };
13
+ /**
14
+ * @inline
15
+ */
7
16
  export type UseAddDocMutationOptions<AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData, TContext = unknown> = {
8
- reference: FirebaseFirestoreTypes.CollectionReference<AppModelType>;
9
- options?: Omit<UseMutationOptions<AppModelType, ReactNativeFirebase.NativeFirebaseError, UseAddDocMutationValues<AppModelType>, TContext>, "mutationFn" | "mutationKey">;
17
+ /**
18
+ * Reference to a collection where document must be added
19
+ */
20
+ collectionReference: FirebaseFirestoreTypes.CollectionReference<AppModelType>;
21
+ /**
22
+ * Options for useMutation hook excluding mutationFn. MutationKey will be equal to reference.path by default.
23
+ */
24
+ options?: Omit<UseMutationOptions<AppModelType, ReactNativeFirebase.NativeFirebaseError, UseAddDocMutationValues<AppModelType>, TContext>, "mutationFn">;
10
25
  };
11
26
  /**
12
- * Provides a mutation hook to add a document to a Firestore collection utilizing React Query's `useMutation`.
13
- * It handles addition and optional conversion of the document data in Firestore.
27
+ * Executes a mutation and returns added document
28
+ *
29
+ * @group Hook
30
+ *
31
+ * @param {UseAddDocMutationOptions<AppModelType>} options - Configuration options for the mutation.
32
+ *
33
+ * @returns {UseMutationResult<AppModelType, Error, UseAddDocMutationValues<AppModelType>, TContext>} A mutation result
14
34
  *
15
- * @param {Object} options - Options for the mutation hook
16
- * @param {FirebaseFirestore.FirebaseFirestoreTypes.CollectionReference<AppModelType>} options.reference - Firestore collection reference where the document should be added.
17
- * @param {UseMutationOptions<AppModelType, Error, { data: DbModelType }, TContext>} [options.options={}] - Optional configuration for the mutation.
35
+ * @example
36
+ * ```jsx
37
+ * export const MyComponent = () => {
38
+ * const {mutate} = useAddDocMutation({
39
+ * options: {
40
+ * },
41
+ * reference: collection(),
42
+ * });
18
43
  *
19
- * @returns {UseMutationResult<AppModelType, Error, { data: DbModelType }, TContext>} The mutation hook result containing status, error, and data of the mutation process.
44
+ * // ....
45
+ * mutate({data: {test: 'value'}});
46
+ * // ....
47
+ * };
48
+ * ```
20
49
  */
21
- export declare const useAddDocMutation: <AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData, TContext = unknown>({ reference, options }: UseAddDocMutationOptions<AppModelType, TContext>) => import("@tanstack/react-query").UseMutationResult<AppModelType, ReactNativeFirebase.NativeFirebaseError, UseAddDocMutationValues<AppModelType>, TContext>;
50
+ export declare const useAddDocMutation: <AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData, TContext = unknown>({ collectionReference, options }: UseAddDocMutationOptions<AppModelType, TContext>) => import("@tanstack/react-query").UseMutationResult<AppModelType, ReactNativeFirebase.NativeFirebaseError, UseAddDocMutationValues<AppModelType>, TContext>;
@@ -2,24 +2,38 @@ import { useMutation } from "@tanstack/react-query";
2
2
  import { addDoc, getDoc } from "@react-native-firebase/firestore";
3
3
  import { useMemo } from "react";
4
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.
5
+ * Executes a mutation and returns added document
7
6
  *
8
- * @param {Object} options - Options for the mutation hook
9
- * @param {FirebaseFirestore.FirebaseFirestoreTypes.CollectionReference<AppModelType>} options.reference - Firestore collection reference where the document should be added.
10
- * @param {UseMutationOptions<AppModelType, Error, { data: DbModelType }, TContext>} [options.options={}] - Optional configuration for the mutation.
7
+ * @group Hook
11
8
  *
12
- * @returns {UseMutationResult<AppModelType, Error, { data: DbModelType }, TContext>} The mutation hook result containing status, error, and data of the mutation process.
9
+ * @param {UseAddDocMutationOptions<AppModelType>} options - Configuration options for the mutation.
10
+ *
11
+ * @returns {UseMutationResult<AppModelType, Error, UseAddDocMutationValues<AppModelType>, TContext>} A mutation result
12
+ *
13
+ * @example
14
+ * ```jsx
15
+ * export const MyComponent = () => {
16
+ * const {mutate} = useAddDocMutation({
17
+ * options: {
18
+ * },
19
+ * reference: collection(),
20
+ * });
21
+ *
22
+ * // ....
23
+ * mutate({data: {test: 'value'}});
24
+ * // ....
25
+ * };
26
+ * ```
13
27
  */
14
- export const useAddDocMutation = ({ reference, options = {} }) => {
15
- const mutationKey = useMemo(() => [reference.path], [reference.path]);
28
+ export const useAddDocMutation = ({ collectionReference, options = {} }) => {
29
+ const mutationKey = useMemo(() => [collectionReference.path], [collectionReference.path]);
16
30
  return useMutation({
31
+ mutationKey,
17
32
  ...options,
18
33
  mutationFn: async ({ data }) => {
19
- const docRef = await addDoc(reference, data);
34
+ const docRef = await addDoc(collectionReference, data);
20
35
  const docSnap = await getDoc(docRef);
21
36
  return docSnap.data();
22
- },
23
- mutationKey
37
+ }
24
38
  });
25
39
  };
@@ -4,15 +4,31 @@ import { FirebaseFirestoreTypes, addDoc, WithFieldValue, getDoc } from "@react-n
4
4
  import { ReactNativeFirebase } from "@react-native-firebase/app";
5
5
  import { useMemo } from "react";
6
6
 
7
+ /**
8
+ * @inline
9
+ */
7
10
  export type UseAddDocMutationValues<AppModelType> = {
11
+ /**
12
+ * Data to write
13
+ */
8
14
  data: WithFieldValue<AppModelType>;
9
15
  };
10
16
 
17
+ /**
18
+ * @inline
19
+ */
11
20
  export type UseAddDocMutationOptions<
12
21
  AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData,
13
22
  TContext = unknown
14
23
  > = {
15
- reference: FirebaseFirestoreTypes.CollectionReference<AppModelType>;
24
+ /**
25
+ * Reference to a collection where document must be added
26
+ */
27
+ collectionReference: FirebaseFirestoreTypes.CollectionReference<AppModelType>;
28
+
29
+ /**
30
+ * Options for useMutation hook excluding mutationFn. MutationKey will be equal to reference.path by default.
31
+ */
16
32
  options?: Omit<
17
33
  UseMutationOptions<
18
34
  AppModelType,
@@ -20,36 +36,50 @@ export type UseAddDocMutationOptions<
20
36
  UseAddDocMutationValues<AppModelType>,
21
37
  TContext
22
38
  >,
23
- "mutationFn" | "mutationKey"
39
+ "mutationFn"
24
40
  >;
25
41
  };
26
42
 
27
43
  /**
28
- * Provides a mutation hook to add a document to a Firestore collection utilizing React Query's `useMutation`.
29
- * It handles addition and optional conversion of the document data in Firestore.
44
+ * Executes a mutation and returns added document
45
+ *
46
+ * @group Hook
47
+ *
48
+ * @param {UseAddDocMutationOptions<AppModelType>} options - Configuration options for the mutation.
49
+ *
50
+ * @returns {UseMutationResult<AppModelType, Error, UseAddDocMutationValues<AppModelType>, TContext>} A mutation result
30
51
  *
31
- * @param {Object} options - Options for the mutation hook
32
- * @param {FirebaseFirestore.FirebaseFirestoreTypes.CollectionReference<AppModelType>} options.reference - Firestore collection reference where the document should be added.
33
- * @param {UseMutationOptions<AppModelType, Error, { data: DbModelType }, TContext>} [options.options={}] - Optional configuration for the mutation.
52
+ * @example
53
+ * ```jsx
54
+ * export const MyComponent = () => {
55
+ * const {mutate} = useAddDocMutation({
56
+ * options: {
57
+ * },
58
+ * reference: collection(),
59
+ * });
34
60
  *
35
- * @returns {UseMutationResult<AppModelType, Error, { data: DbModelType }, TContext>} The mutation hook result containing status, error, and data of the mutation process.
61
+ * // ....
62
+ * mutate({data: {test: 'value'}});
63
+ * // ....
64
+ * };
65
+ * ```
36
66
  */
37
67
  export const useAddDocMutation = <
38
68
  AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData,
39
69
  TContext = unknown
40
70
  >({
41
- reference,
71
+ collectionReference,
42
72
  options = {}
43
73
  }: UseAddDocMutationOptions<AppModelType, TContext>) => {
44
- const mutationKey = useMemo(() => [reference.path], [reference.path]);
74
+ const mutationKey = useMemo(() => [collectionReference.path], [collectionReference.path]);
45
75
 
46
76
  return useMutation({
77
+ mutationKey,
47
78
  ...options,
48
79
  mutationFn: async ({ data }) => {
49
- const docRef = await addDoc<AppModelType>(reference, data);
80
+ const docRef = await addDoc<AppModelType>(collectionReference, data);
50
81
  const docSnap = await getDoc(docRef);
51
82
  return docSnap.data() as AppModelType;
52
- },
53
- mutationKey
83
+ }
54
84
  });
55
85
  };
@@ -1,15 +1,39 @@
1
1
  import { UseMutationOptions } from "@tanstack/react-query";
2
2
  import { FirebaseFirestoreTypes } from "@react-native-firebase/firestore";
3
3
  import { ReactNativeFirebase } from "@react-native-firebase/app";
4
+ /**
5
+ * @inline
6
+ */
4
7
  export type UseBatchWriteVariables = (batch: FirebaseFirestoreTypes.WriteBatch) => Promise<void> | void;
5
- export type UseBatchWriteOptions<TContext = unknown> = {
6
- options?: Omit<UseMutationOptions<void, ReactNativeFirebase.NativeFirebaseError, UseBatchWriteVariables, TContext>, "mutationFn">;
8
+ /**
9
+ * @inline
10
+ */
11
+ export type UseBatchWriteOptions = {
12
+ options?: Omit<UseMutationOptions<void, ReactNativeFirebase.NativeFirebaseError, UseBatchWriteVariables>, "mutationFn">;
7
13
  };
8
14
  /**
9
15
  * 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.
16
+ *
17
+ * @group Hook
18
+ *
19
+ * @param {UseBatchWriteOptions} options - Configuration options for the query.
20
+ *
21
+ * @returns {UseMutationResult<void, Error, UseAddDocMutationValues<AppModelType>>} A mutation result
22
+ *
23
+ * @example
24
+ * ```jsx
25
+ * export const MyComponent = () => {
26
+ * const {mutate} = useBatchWrite({
27
+ * options: {
28
+ * },
29
+ * });
30
+ *
31
+ * // ....
32
+ * mutate(() => {
33
+ * ref.update({...})
34
+ * });
35
+ * // ....
36
+ * };
37
+ * ```
14
38
  */
15
- export declare const useBatchWrite: <TContext = unknown>({ options }?: UseBatchWriteOptions<TContext>) => import("@tanstack/react-query").UseMutationResult<void, ReactNativeFirebase.NativeFirebaseError, UseBatchWriteVariables, TContext>;
39
+ export declare const useBatchWrite: ({ options }?: UseBatchWriteOptions) => import("@tanstack/react-query").UseMutationResult<void, ReactNativeFirebase.NativeFirebaseError, UseBatchWriteVariables, unknown>;
@@ -3,10 +3,28 @@ import { writeBatch } from "@react-native-firebase/firestore";
3
3
  import { useFirestore } from "./useFirestore";
4
4
  /**
5
5
  * Custom hook to perform batch write operations using Firestore.
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.
6
+ *
7
+ * @group Hook
8
+ *
9
+ * @param {UseBatchWriteOptions} options - Configuration options for the query.
10
+ *
11
+ * @returns {UseMutationResult<void, Error, UseAddDocMutationValues<AppModelType>>} A mutation result
12
+ *
13
+ * @example
14
+ * ```jsx
15
+ * export const MyComponent = () => {
16
+ * const {mutate} = useBatchWrite({
17
+ * options: {
18
+ * },
19
+ * });
20
+ *
21
+ * // ....
22
+ * mutate(() => {
23
+ * ref.update({...})
24
+ * });
25
+ * // ....
26
+ * };
27
+ * ```
10
28
  */
11
29
  export const useBatchWrite = ({ options = {} } = {}) => {
12
30
  const db = useFirestore();
@@ -4,23 +4,47 @@ import { writeBatch, FirebaseFirestoreTypes } from "@react-native-firebase/fires
4
4
  import { ReactNativeFirebase } from "@react-native-firebase/app";
5
5
  import { useFirestore } from "./useFirestore";
6
6
 
7
+ /**
8
+ * @inline
9
+ */
7
10
  export type UseBatchWriteVariables = (batch: FirebaseFirestoreTypes.WriteBatch) => Promise<void> | void;
8
11
 
9
- export type UseBatchWriteOptions<TContext = unknown> = {
12
+ /**
13
+ * @inline
14
+ */
15
+ export type UseBatchWriteOptions = {
10
16
  options?: Omit<
11
- UseMutationOptions<void, ReactNativeFirebase.NativeFirebaseError, UseBatchWriteVariables, TContext>,
17
+ UseMutationOptions<void, ReactNativeFirebase.NativeFirebaseError, UseBatchWriteVariables>,
12
18
  "mutationFn"
13
19
  >;
14
20
  };
15
21
 
16
22
  /**
17
23
  * Custom hook to perform batch write operations using Firestore.
18
- * Utilizes a mutation to carry out the batch write transaction.
19
- * @template TContext - The type of context that can be passed into the hook, defaults to unknown.
20
- * @param {Object} options - The configuration options for the mutation operation.
21
- * @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.
24
+ *
25
+ * @group Hook
26
+ *
27
+ * @param {UseBatchWriteOptions} options - Configuration options for the query.
28
+ *
29
+ * @returns {UseMutationResult<void, Error, UseAddDocMutationValues<AppModelType>>} A mutation result
30
+ *
31
+ * @example
32
+ * ```jsx
33
+ * export const MyComponent = () => {
34
+ * const {mutate} = useBatchWrite({
35
+ * options: {
36
+ * },
37
+ * });
38
+ *
39
+ * // ....
40
+ * mutate(() => {
41
+ * ref.update({...})
42
+ * });
43
+ * // ....
44
+ * };
45
+ * ```
22
46
  */
23
- export const useBatchWrite = <TContext = unknown>({ options = {} }: UseBatchWriteOptions<TContext> = {}) => {
47
+ export const useBatchWrite = ({ options = {} }: UseBatchWriteOptions = {}) => {
24
48
  const db = useFirestore();
25
49
 
26
50
  return useMutation({
@@ -1,18 +1,39 @@
1
1
  import { FirebaseFirestoreTypes } from "@react-native-firebase/firestore";
2
- export type UseCollectionReferenceOptions<AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData> = {
2
+ import { AppModel } from "../../types";
3
+ /**
4
+ * @inline
5
+ */
6
+ export type UseCollectionReferenceOptions<AppModelType extends AppModel = AppModel> = {
7
+ /**
8
+ * CollectionReference or DocumentReference that is used as a root to lookup a sub-collection
9
+ */
3
10
  reference?: FirebaseFirestoreTypes.CollectionReference<AppModelType> | FirebaseFirestoreTypes.DocumentReference<AppModelType>;
11
+ /**
12
+ * A slash-separated path to a collection.
13
+ */
4
14
  path: string;
15
+ /**
16
+ * Additional path segments that will be applied relative
17
+ */
5
18
  pathSegments?: string[];
6
19
  };
7
20
  /**
8
- * Creates a reference to a Firestore collection based on the provided path, reference, and path segments.
21
+ * Gets a `CollectionReference` instance that refers to a subcollection of
22
+ * `reference` at the specified relative path.
23
+ *
24
+ * @group Hook
25
+ *
26
+ * @param {UseCollectionReferenceOptions<AppModelType>} options - Options
9
27
  *
10
- * This hook utilizes useMemo for optimization, ensuring the collection reference is recalculated only when its dependencies change.
28
+ * @returns {FirebaseFirestoreTypes.CollectionReference<AppModelType, AppModelType>} A reference to a Firestore collection
11
29
  *
12
- * @param {UseCollectionReferenceOptions<AppModelType>} options - The options including path, reference, and pathSegments to construct the Firestore collection reference.
13
- * @param {string} options.path - The base path for the collection.
14
- * @param {FirestoreReference} options.reference - An optional Firestore reference object that should be of type "collection".
15
- * @param {string[]} options.pathSegments - Additional path segments to append to the base path.
16
- * @returns {CollectionReference} A Firestore collection reference constructed using the specified path, reference, and path segments.
30
+ * @example
31
+ * ```jsx
32
+ * export const MyComponent = () => {
33
+ * const ref = useCollectionReference({
34
+ * path: 'todos'
35
+ * });
36
+ * };
37
+ * ```
17
38
  */
18
- export declare const useCollectionReference: <AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData>({ path, reference, pathSegments }: UseCollectionReferenceOptions<AppModelType>) => FirebaseFirestoreTypes.CollectionReference<AppModelType>;
39
+ export declare const useCollectionReference: <AppModelType extends AppModel = AppModel>({ path, reference, pathSegments }: UseCollectionReferenceOptions<AppModelType>) => FirebaseFirestoreTypes.CollectionReference<AppModelType>;
@@ -2,15 +2,23 @@ import { collection } from "@react-native-firebase/firestore";
2
2
  import { useMemo } from "react";
3
3
  import { useFirestore } from "./useFirestore";
4
4
  /**
5
- * Creates a reference to a Firestore collection based on the provided path, reference, and path segments.
5
+ * Gets a `CollectionReference` instance that refers to a subcollection of
6
+ * `reference` at the specified relative path.
6
7
  *
7
- * This hook utilizes useMemo for optimization, ensuring the collection reference is recalculated only when its dependencies change.
8
+ * @group Hook
8
9
  *
9
- * @param {UseCollectionReferenceOptions<AppModelType>} options - The options including path, reference, and pathSegments to construct the Firestore collection reference.
10
- * @param {string} options.path - The base path for the collection.
11
- * @param {FirestoreReference} options.reference - An optional Firestore reference object that should be of type "collection".
12
- * @param {string[]} options.pathSegments - Additional path segments to append to the base path.
13
- * @returns {CollectionReference} A Firestore collection reference constructed using the specified path, reference, and path segments.
10
+ * @param {UseCollectionReferenceOptions<AppModelType>} options - Options
11
+ *
12
+ * @returns {FirebaseFirestoreTypes.CollectionReference<AppModelType, AppModelType>} A reference to a Firestore collection
13
+ *
14
+ * @example
15
+ * ```jsx
16
+ * export const MyComponent = () => {
17
+ * const ref = useCollectionReference({
18
+ * path: 'todos'
19
+ * });
20
+ * };
21
+ * ```
14
22
  */
15
23
  export const useCollectionReference = ({ path, reference, pathSegments }) => {
16
24
  const db = useFirestore();
@@ -2,48 +2,57 @@ import { collection, FirebaseFirestoreTypes } from "@react-native-firebase/fires
2
2
 
3
3
  import { useMemo } from "react";
4
4
  import { useFirestore } from "./useFirestore";
5
+ import { AppModel } from "../../types";
5
6
 
6
- export type UseCollectionReferenceOptions<
7
- AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData
8
- > = {
7
+ /**
8
+ * @inline
9
+ */
10
+ export type UseCollectionReferenceOptions<AppModelType extends AppModel = AppModel> = {
11
+ /**
12
+ * CollectionReference or DocumentReference that is used as a root to lookup a sub-collection
13
+ */
9
14
  reference?:
10
15
  | FirebaseFirestoreTypes.CollectionReference<AppModelType>
11
16
  | FirebaseFirestoreTypes.DocumentReference<AppModelType>;
17
+ /**
18
+ * A slash-separated path to a collection.
19
+ */
12
20
  path: string;
21
+ /**
22
+ * Additional path segments that will be applied relative
23
+ */
13
24
  pathSegments?: string[];
14
25
  };
15
26
 
16
27
  /**
17
- * Creates a reference to a Firestore collection based on the provided path, reference, and path segments.
28
+ * Gets a `CollectionReference` instance that refers to a subcollection of
29
+ * `reference` at the specified relative path.
30
+ *
31
+ * @group Hook
32
+ *
33
+ * @param {UseCollectionReferenceOptions<AppModelType>} options - Options
18
34
  *
19
- * This hook utilizes useMemo for optimization, ensuring the collection reference is recalculated only when its dependencies change.
35
+ * @returns {FirebaseFirestoreTypes.CollectionReference<AppModelType, AppModelType>} A reference to a Firestore collection
20
36
  *
21
- * @param {UseCollectionReferenceOptions<AppModelType>} options - The options including path, reference, and pathSegments to construct the Firestore collection reference.
22
- * @param {string} options.path - The base path for the collection.
23
- * @param {FirestoreReference} options.reference - An optional Firestore reference object that should be of type "collection".
24
- * @param {string[]} options.pathSegments - Additional path segments to append to the base path.
25
- * @returns {CollectionReference} A Firestore collection reference constructed using the specified path, reference, and path segments.
37
+ * @example
38
+ * ```jsx
39
+ * export const MyComponent = () => {
40
+ * const ref = useCollectionReference({
41
+ * path: 'todos'
42
+ * });
43
+ * };
44
+ * ```
26
45
  */
27
- export const useCollectionReference = <
28
- AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData
29
- >({
46
+ export const useCollectionReference = <AppModelType extends AppModel = AppModel>({
30
47
  path,
31
48
  reference,
32
49
  pathSegments
33
- }: UseCollectionReferenceOptions<AppModelType>): FirebaseFirestoreTypes.CollectionReference<AppModelType> => {
50
+ }: UseCollectionReferenceOptions<AppModelType>) => {
34
51
  const db = useFirestore();
35
52
 
36
53
  return useMemo(() => {
37
54
  return !reference
38
- ? (collection(
39
- db,
40
- path || "",
41
- ...(pathSegments || [])
42
- ) as FirebaseFirestoreTypes.CollectionReference<AppModelType>)
43
- : (collection(
44
- reference,
45
- path,
46
- ...(pathSegments || [])
47
- ) as FirebaseFirestoreTypes.CollectionReference<AppModelType>);
48
- }, [db, reference, path, pathSegments]);
55
+ ? collection(db, path || "", ...(pathSegments || []))
56
+ : collection(reference, path, ...(pathSegments || []));
57
+ }, [db, reference, path, pathSegments]) as FirebaseFirestoreTypes.CollectionReference<AppModelType>;
49
58
  };
@@ -1,56 +1,11 @@
1
- import { FirebaseFirestoreTypes } from "@react-native-firebase/firestore";
2
1
  import { AppModel } from "../../types";
3
- export type QueryFilterConstraint = FirebaseFirestoreTypes.QueryCompositeFilterConstraint | FirebaseFirestoreTypes.QueryFilterConstraint;
4
- export type QueryElement<AppModelType extends AppModel = AppModel> = {
5
- operator?: "OR" | "AND";
6
- children?: QueryElement[];
7
- field?: keyof (AppModelType & {
8
- documentId?: string[];
9
- });
10
- value?: AppModelType[keyof AppModelType];
11
- op?: FirebaseFirestoreTypes.WhereFilterOp;
12
- };
13
- export type CompositeFilter<AppModelType extends AppModel = AppModel> = {
14
- operator: "OR" | "AND";
15
- children: QueryElement<AppModelType & {
16
- documentId?: string[];
17
- }>[];
18
- };
2
+ import { CompositeFilter, QueryFilterConstraint } from "./utils/buildCompositeFilter";
19
3
  /**
20
4
  * @inline
21
5
  */
22
6
  export type UseCompositeFilter<AppModelType extends AppModel = AppModel> = {
23
7
  query?: CompositeFilter<AppModelType>;
24
8
  };
25
- /**
26
- * Constructs a composite or where query filter based on the provided query structure.
27
- * It recursively builds query constraints using logical "or" or "and" operators.
28
- *
29
- * @group Utility
30
- *
31
- * @param {QueryElement<AppModelType>} query
32
- *
33
- * @returns {QueryFilterConstraint | null}
34
- *
35
- * @example
36
- * ```jsx
37
- * export const MyComponent = () => {
38
- * const filter = buildCompositeFilter({
39
- * operator: "AND",
40
- * children: [
41
- * {
42
- * field: "field",
43
- * value: "value",
44
- * op: "=="
45
- * },
46
- * ...(query ? [query] : [])
47
- * ]
48
- * });
49
- * console.log(filter);
50
- * };
51
- * ```
52
- */
53
- export declare const buildCompositeFilter: <AppModelType extends AppModel = AppModel>(query: QueryElement<AppModelType>) => QueryFilterConstraint | null;
54
9
  /**
55
10
  * A custom hook that constructs a composite or where query filter based on the provided query structure.
56
11
  * It recursively builds query constraints using logical "or" or "and" operators.