react-query-firebase 2.3.3 → 2.4.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.
- package/package.json +1 -1
- package/react-native/firestore/index.d.ts +5 -0
- package/react-native/firestore/index.js +5 -0
- package/react-native/firestore/index.ts +5 -0
- package/react-native/firestore/useAddDocMutation.d.ts +38 -9
- package/react-native/firestore/useAddDocMutation.js +25 -11
- package/react-native/firestore/useAddDocMutation.ts +43 -13
- package/react-native/firestore/useBatchWrite.d.ts +31 -7
- package/react-native/firestore/useBatchWrite.js +22 -4
- package/react-native/firestore/useBatchWrite.ts +31 -7
- package/react-native/firestore/useCollectionReference.d.ts +30 -9
- package/react-native/firestore/useCollectionReference.js +15 -7
- package/react-native/firestore/useCollectionReference.ts +34 -25
- package/react-native/firestore/useCompositeFilter.d.ts +1 -46
- package/react-native/firestore/useCompositeFilter.js +2 -45
- package/react-native/firestore/useCompositeFilter.ts +2 -74
- package/react-native/firestore/useCountQuery.d.ts +1 -1
- package/react-native/firestore/useCountQuery.ts +1 -1
- package/react-native/firestore/useDeleteDocMutation.d.ts +39 -10
- package/react-native/firestore/useDeleteDocMutation.js +22 -5
- package/react-native/firestore/useDeleteDocMutation.ts +38 -15
- package/react-native/firestore/useDocReference.d.ts +22 -14
- package/react-native/firestore/useDocReference.js +20 -26
- package/react-native/firestore/useDocReference.ts +34 -47
- package/react-native/firestore/useDocReferences.d.ts +23 -18
- package/react-native/firestore/useDocReferences.js +18 -19
- package/react-native/firestore/useDocReferences.ts +26 -34
- package/react-native/firestore/useFirestore.d.ts +4 -3
- package/react-native/firestore/useFirestore.js +4 -3
- package/react-native/firestore/useFirestore.ts +4 -3
- package/react-native/firestore/useGetDocData.d.ts +33 -14
- package/react-native/firestore/useGetDocData.js +21 -6
- package/react-native/firestore/useGetDocData.ts +34 -22
- package/react-native/firestore/useInfiniteQuery.d.ts +1 -1
- package/react-native/firestore/useInfiniteQuery.ts +1 -1
- package/react-native/firestore/useQuery.d.ts +1 -1
- package/react-native/firestore/useQuery.ts +1 -1
- package/react-native/firestore/useQueryConstraints.d.ts +0 -21
- package/react-native/firestore/useQueryConstraints.js +1 -39
- package/react-native/firestore/useQueryConstraints.ts +2 -51
- package/react-native/firestore/useRunTransaction.d.ts +33 -9
- package/react-native/firestore/useRunTransaction.js +20 -4
- package/react-native/firestore/useRunTransaction.ts +35 -16
- package/react-native/firestore/useSetDocMutation.d.ts +43 -11
- package/react-native/firestore/useSetDocMutation.js +28 -11
- package/react-native/firestore/useSetDocMutation.ts +49 -28
- package/react-native/firestore/useUpdateDocMutation.d.ts +40 -18
- package/react-native/firestore/useUpdateDocMutation.js +18 -13
- package/react-native/firestore/useUpdateDocMutation.ts +40 -31
- package/react-native/firestore/utils/buildCompositeFilter.d.ts +47 -0
- package/react-native/firestore/utils/buildCompositeFilter.js +45 -0
- package/react-native/firestore/utils/buildCompositeFilter.ts +75 -0
- package/react-native/firestore/utils/buildQueryConstraint.d.ts +23 -0
- package/react-native/firestore/utils/buildQueryConstraint.js +41 -0
- package/react-native/firestore/utils/buildQueryConstraint.ts +54 -0
- package/react-native/firestore/utils/getDocData.d.ts +11 -11
- package/react-native/firestore/utils/getDocData.js +5 -8
- package/react-native/firestore/utils/getDocData.ts +12 -16
- package/react-native/firestore/utils/getDocRef.d.ts +12 -9
- package/react-native/firestore/utils/getDocRef.js +9 -10
- package/react-native/firestore/utils/getDocRef.ts +14 -15
- package/react-native/firestore/utils/getDocSnap.d.ts +11 -13
- package/react-native/firestore/utils/getDocSnap.js +5 -10
- package/react-native/firestore/utils/getDocSnap.ts +12 -17
- package/types/AppModel.d.ts +4 -1
- package/types/AppModel.ts +4 -1
- package/web/firestore/index.d.ts +5 -0
- package/web/firestore/index.js +5 -0
- package/web/firestore/index.ts +5 -0
- package/web/firestore/useAddDocMutation.d.ts +41 -13
- package/web/firestore/useAddDocMutation.js +27 -14
- package/web/firestore/useAddDocMutation.ts +49 -37
- package/web/firestore/useBatchWrite.d.ts +34 -7
- package/web/firestore/useBatchWrite.js +22 -4
- package/web/firestore/useBatchWrite.ts +34 -7
- package/web/firestore/useCollectionReference.d.ts +32 -11
- package/web/firestore/useCollectionReference.js +15 -7
- package/web/firestore/useCollectionReference.ts +34 -13
- package/web/firestore/useCompositeFilter.d.ts +2 -47
- package/web/firestore/useCompositeFilter.js +2 -42
- package/web/firestore/useCompositeFilter.ts +2 -72
- package/web/firestore/useCountQuery.d.ts +4 -4
- package/web/firestore/useCountQuery.ts +5 -5
- package/web/firestore/useDeleteDocMutation.d.ts +41 -11
- package/web/firestore/useDeleteDocMutation.js +24 -7
- package/web/firestore/useDeleteDocMutation.ts +45 -23
- package/web/firestore/useDocReference.d.ts +23 -15
- package/web/firestore/useDocReference.js +16 -31
- package/web/firestore/useDocReference.ts +28 -46
- package/web/firestore/useDocReferences.d.ts +23 -18
- package/web/firestore/useDocReferences.js +18 -21
- package/web/firestore/useDocReferences.ts +26 -30
- package/web/firestore/useFirestore.d.ts +4 -3
- package/web/firestore/useFirestore.js +4 -3
- package/web/firestore/useFirestore.ts +4 -3
- package/web/firestore/useGetDocData.d.ts +32 -13
- package/web/firestore/useGetDocData.js +21 -6
- package/web/firestore/useGetDocData.ts +34 -23
- package/web/firestore/useGetRealtimeDocData.js +2 -2
- package/web/firestore/useGetRealtimeDocData.ts +2 -2
- package/web/firestore/useInfiniteQuery.d.ts +1 -1
- package/web/firestore/useInfiniteQuery.js +1 -1
- package/web/firestore/useInfiniteQuery.ts +2 -2
- package/web/firestore/useQuery.d.ts +1 -1
- package/web/firestore/useQuery.js +1 -1
- package/web/firestore/useQuery.ts +2 -2
- package/web/firestore/useQueryConstraints.d.ts +0 -21
- package/web/firestore/useQueryConstraints.js +1 -39
- package/web/firestore/useQueryConstraints.ts +2 -51
- package/web/firestore/useRunTransaction.d.ts +33 -8
- package/web/firestore/useRunTransaction.js +20 -4
- package/web/firestore/useRunTransaction.ts +35 -10
- package/web/firestore/useSetDocMutation.d.ts +45 -12
- package/web/firestore/useSetDocMutation.js +28 -11
- package/web/firestore/useSetDocMutation.ts +51 -26
- package/web/firestore/useUpdateDocMutation.d.ts +42 -20
- package/web/firestore/useUpdateDocMutation.js +20 -15
- package/web/firestore/useUpdateDocMutation.ts +45 -41
- package/web/firestore/utils/buildCompositeFilter.d.ts +47 -0
- package/web/firestore/utils/buildCompositeFilter.js +42 -0
- package/web/firestore/utils/buildCompositeFilter.ts +73 -0
- package/web/firestore/utils/buildQueryConstraint.d.ts +23 -0
- package/web/firestore/utils/buildQueryConstraint.js +41 -0
- package/web/firestore/utils/buildQueryConstraint.ts +55 -0
- package/web/firestore/utils/getDocData.d.ts +13 -11
- package/web/firestore/utils/getDocData.js +6 -9
- package/web/firestore/utils/getDocData.ts +14 -20
- package/web/firestore/utils/getDocRef.d.ts +14 -11
- package/web/firestore/utils/getDocRef.js +9 -10
- package/web/firestore/utils/getDocRef.ts +21 -24
- package/web/firestore/utils/getDocSnap.d.ts +11 -13
- package/web/firestore/utils/getDocSnap.js +5 -10
- package/web/firestore/utils/getDocSnap.ts +14 -21
package/package.json
CHANGED
|
@@ -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
|
-
|
|
9
|
-
|
|
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
|
-
*
|
|
13
|
-
*
|
|
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
|
-
* @
|
|
16
|
-
*
|
|
17
|
-
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```jsx
|
|
37
|
+
* export const MyComponent = () => {
|
|
38
|
+
* const {mutate} = useAddDocMutation({
|
|
39
|
+
* options: {
|
|
40
|
+
* },
|
|
41
|
+
* reference: collection(),
|
|
42
|
+
* });
|
|
18
43
|
*
|
|
19
|
-
*
|
|
44
|
+
* // ....
|
|
45
|
+
* mutate({data: {test: 'value'}});
|
|
46
|
+
* // ....
|
|
47
|
+
* };
|
|
48
|
+
* ```
|
|
20
49
|
*/
|
|
21
|
-
export declare const useAddDocMutation: <AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData, TContext = unknown>({
|
|
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
|
-
*
|
|
6
|
-
* It handles addition and optional conversion of the document data in Firestore.
|
|
5
|
+
* Executes a mutation and returns added document
|
|
7
6
|
*
|
|
8
|
-
* @
|
|
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
|
-
* @
|
|
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 = ({
|
|
15
|
-
const mutationKey = useMemo(() => [
|
|
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(
|
|
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
|
-
|
|
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"
|
|
39
|
+
"mutationFn"
|
|
24
40
|
>;
|
|
25
41
|
};
|
|
26
42
|
|
|
27
43
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
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
|
-
* @
|
|
32
|
-
*
|
|
33
|
-
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```jsx
|
|
54
|
+
* export const MyComponent = () => {
|
|
55
|
+
* const {mutate} = useAddDocMutation({
|
|
56
|
+
* options: {
|
|
57
|
+
* },
|
|
58
|
+
* reference: collection(),
|
|
59
|
+
* });
|
|
34
60
|
*
|
|
35
|
-
*
|
|
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
|
-
|
|
71
|
+
collectionReference,
|
|
42
72
|
options = {}
|
|
43
73
|
}: UseAddDocMutationOptions<AppModelType, TContext>) => {
|
|
44
|
-
const mutationKey = useMemo(() => [
|
|
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>(
|
|
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
|
-
|
|
6
|
-
|
|
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
|
-
*
|
|
11
|
-
* @
|
|
12
|
-
*
|
|
13
|
-
* @
|
|
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:
|
|
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
|
-
*
|
|
7
|
-
* @
|
|
8
|
-
*
|
|
9
|
-
* @
|
|
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
|
-
|
|
12
|
+
/**
|
|
13
|
+
* @inline
|
|
14
|
+
*/
|
|
15
|
+
export type UseBatchWriteOptions = {
|
|
10
16
|
options?: Omit<
|
|
11
|
-
UseMutationOptions<void, ReactNativeFirebase.NativeFirebaseError, UseBatchWriteVariables
|
|
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
|
-
*
|
|
19
|
-
* @
|
|
20
|
-
*
|
|
21
|
-
* @
|
|
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 =
|
|
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
|
-
|
|
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
|
-
*
|
|
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
|
-
*
|
|
28
|
+
* @returns {FirebaseFirestoreTypes.CollectionReference<AppModelType, AppModelType>} A reference to a Firestore collection
|
|
11
29
|
*
|
|
12
|
-
* @
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
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
|
|
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
|
-
*
|
|
5
|
+
* Gets a `CollectionReference` instance that refers to a subcollection of
|
|
6
|
+
* `reference` at the specified relative path.
|
|
6
7
|
*
|
|
7
|
-
*
|
|
8
|
+
* @group Hook
|
|
8
9
|
*
|
|
9
|
-
* @param {UseCollectionReferenceOptions<AppModelType>} options -
|
|
10
|
-
*
|
|
11
|
-
* @
|
|
12
|
-
*
|
|
13
|
-
* @
|
|
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
|
-
|
|
7
|
-
|
|
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
|
-
*
|
|
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
|
-
*
|
|
35
|
+
* @returns {FirebaseFirestoreTypes.CollectionReference<AppModelType, AppModelType>} A reference to a Firestore collection
|
|
20
36
|
*
|
|
21
|
-
* @
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
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>)
|
|
50
|
+
}: UseCollectionReferenceOptions<AppModelType>) => {
|
|
34
51
|
const db = useFirestore();
|
|
35
52
|
|
|
36
53
|
return useMemo(() => {
|
|
37
54
|
return !reference
|
|
38
|
-
?
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
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.
|