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.
- 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 +2 -2
- package/react-native/firestore/useInfiniteQuery.ts +3 -3
- package/react-native/firestore/useQuery.d.ts +1 -1
- package/react-native/firestore/useQuery.ts +1 -1
- package/react-native/firestore/useQueryConstraints.d.ts +2 -22
- package/react-native/firestore/useQueryConstraints.js +1 -39
- package/react-native/firestore/useQueryConstraints.ts +3 -43
- 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 +7 -8
- package/react-native/firestore/utils/getDocRef.ts +12 -13
- 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 +2 -2
- package/web/firestore/useInfiniteQuery.js +1 -1
- package/web/firestore/useInfiniteQuery.ts +4 -4
- 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 +7 -8
- package/web/firestore/utils/getDocRef.ts +16 -19
- 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
|
@@ -1,49 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { and, or } from "@react-native-firebase/firestore";
|
|
2
2
|
import { useMemo } from "react";
|
|
3
|
-
|
|
4
|
-
* Constructs a composite or where query filter based on the provided query structure.
|
|
5
|
-
* It recursively builds query constraints using logical "or" or "and" operators.
|
|
6
|
-
*
|
|
7
|
-
* @group Utility
|
|
8
|
-
*
|
|
9
|
-
* @param {QueryElement<AppModelType>} query
|
|
10
|
-
*
|
|
11
|
-
* @returns {QueryFilterConstraint | null}
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```jsx
|
|
15
|
-
* export const MyComponent = () => {
|
|
16
|
-
* const filter = buildCompositeFilter({
|
|
17
|
-
* operator: "AND",
|
|
18
|
-
* children: [
|
|
19
|
-
* {
|
|
20
|
-
* field: "field",
|
|
21
|
-
* value: "value",
|
|
22
|
-
* op: "=="
|
|
23
|
-
* },
|
|
24
|
-
* ...(query ? [query] : [])
|
|
25
|
-
* ]
|
|
26
|
-
* });
|
|
27
|
-
* console.log(filter);
|
|
28
|
-
* };
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
|
-
export const buildCompositeFilter = (query) => {
|
|
32
|
-
if (query.children) {
|
|
33
|
-
const queryConstraints = query.children.map(buildCompositeFilter).filter((constraint) => !!constraint);
|
|
34
|
-
if (queryConstraints.length <= 0) {
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
-
if (queryConstraints.length <= 1) {
|
|
38
|
-
return queryConstraints[0];
|
|
39
|
-
}
|
|
40
|
-
return query.operator === "OR" ? or(...queryConstraints) : and(...queryConstraints);
|
|
41
|
-
}
|
|
42
|
-
if (query.field && query.op) {
|
|
43
|
-
return where(query.field === "documentId" ? firebase.FieldPath.documentId() : query.field, query.op, query.value);
|
|
44
|
-
}
|
|
45
|
-
return null;
|
|
46
|
-
};
|
|
3
|
+
import { buildCompositeFilter } from "./utils/buildCompositeFilter";
|
|
47
4
|
/**
|
|
48
5
|
* A custom hook that constructs a composite or where query filter based on the provided query structure.
|
|
49
6
|
* It recursively builds query constraints using logical "or" or "and" operators.
|
|
@@ -1,23 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { and, or } from "@react-native-firebase/firestore";
|
|
2
2
|
import { useMemo } from "react";
|
|
3
3
|
import { AppModel } from "../../types";
|
|
4
|
-
|
|
5
|
-
export type QueryFilterConstraint =
|
|
6
|
-
| FirebaseFirestoreTypes.QueryCompositeFilterConstraint
|
|
7
|
-
| FirebaseFirestoreTypes.QueryFilterConstraint;
|
|
8
|
-
|
|
9
|
-
export type QueryElement<AppModelType extends AppModel = AppModel> = {
|
|
10
|
-
operator?: "OR" | "AND";
|
|
11
|
-
children?: QueryElement[];
|
|
12
|
-
field?: keyof (AppModelType & { documentId?: string[] });
|
|
13
|
-
value?: AppModelType[keyof AppModelType];
|
|
14
|
-
op?: FirebaseFirestoreTypes.WhereFilterOp;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export type CompositeFilter<AppModelType extends AppModel = AppModel> = {
|
|
18
|
-
operator: "OR" | "AND";
|
|
19
|
-
children: QueryElement<AppModelType & { documentId?: string[] }>[];
|
|
20
|
-
};
|
|
4
|
+
import { buildCompositeFilter, CompositeFilter, QueryFilterConstraint } from "./utils/buildCompositeFilter";
|
|
21
5
|
|
|
22
6
|
/**
|
|
23
7
|
* @inline
|
|
@@ -26,62 +10,6 @@ export type UseCompositeFilter<AppModelType extends AppModel = AppModel> = {
|
|
|
26
10
|
query?: CompositeFilter<AppModelType>;
|
|
27
11
|
};
|
|
28
12
|
|
|
29
|
-
/**
|
|
30
|
-
* Constructs a composite or where query filter based on the provided query structure.
|
|
31
|
-
* It recursively builds query constraints using logical "or" or "and" operators.
|
|
32
|
-
*
|
|
33
|
-
* @group Utility
|
|
34
|
-
*
|
|
35
|
-
* @param {QueryElement<AppModelType>} query
|
|
36
|
-
*
|
|
37
|
-
* @returns {QueryFilterConstraint | null}
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* ```jsx
|
|
41
|
-
* export const MyComponent = () => {
|
|
42
|
-
* const filter = buildCompositeFilter({
|
|
43
|
-
* operator: "AND",
|
|
44
|
-
* children: [
|
|
45
|
-
* {
|
|
46
|
-
* field: "field",
|
|
47
|
-
* value: "value",
|
|
48
|
-
* op: "=="
|
|
49
|
-
* },
|
|
50
|
-
* ...(query ? [query] : [])
|
|
51
|
-
* ]
|
|
52
|
-
* });
|
|
53
|
-
* console.log(filter);
|
|
54
|
-
* };
|
|
55
|
-
* ```
|
|
56
|
-
*/
|
|
57
|
-
export const buildCompositeFilter = <AppModelType extends AppModel = AppModel>(
|
|
58
|
-
query: QueryElement<AppModelType>
|
|
59
|
-
): QueryFilterConstraint | null => {
|
|
60
|
-
if (query.children) {
|
|
61
|
-
const queryConstraints = query.children.map(buildCompositeFilter).filter((constraint) => !!constraint);
|
|
62
|
-
|
|
63
|
-
if (queryConstraints.length <= 0) {
|
|
64
|
-
return null;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (queryConstraints.length <= 1) {
|
|
68
|
-
return queryConstraints[0];
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return (query as CompositeFilter).operator === "OR" ? or(...queryConstraints) : and(...queryConstraints);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (query.field && query.op) {
|
|
75
|
-
return where(
|
|
76
|
-
query.field === "documentId" ? firebase.FieldPath.documentId() : (query.field as string),
|
|
77
|
-
query.op,
|
|
78
|
-
query.value
|
|
79
|
-
) as unknown as FirebaseFirestoreTypes.QueryFilterConstraint;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return null;
|
|
83
|
-
};
|
|
84
|
-
|
|
85
13
|
/**
|
|
86
14
|
* A custom hook that constructs a composite or where query filter based on the provided query structure.
|
|
87
15
|
* It recursively builds query constraints using logical "or" or "and" operators.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FirebaseFirestoreTypes, QueryConstraint, QueryNonFilterConstraint } from "@react-native-firebase/firestore";
|
|
2
2
|
import { UseQueryResult, UseQueryOptions as UseReactQueryOptions } from "@tanstack/react-query";
|
|
3
|
-
import { QueryFilterConstraint } from "./
|
|
3
|
+
import { QueryFilterConstraint } from "./utils/buildCompositeFilter";
|
|
4
4
|
import { AppModel } from "../../types";
|
|
5
5
|
/**
|
|
6
6
|
* @inline
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
useQuery as useReactQuery,
|
|
12
12
|
UseQueryOptions as UseReactQueryOptions
|
|
13
13
|
} from "@tanstack/react-query";
|
|
14
|
-
import { QueryFilterConstraint } from "./
|
|
14
|
+
import { QueryFilterConstraint } from "./utils/buildCompositeFilter";
|
|
15
15
|
import { AppModel } from "../../types";
|
|
16
16
|
|
|
17
17
|
/**
|
|
@@ -1,18 +1,47 @@
|
|
|
1
1
|
import { UseMutationOptions } from "@tanstack/react-query";
|
|
2
2
|
import { FirebaseFirestoreTypes, WithFieldValue } from "@react-native-firebase/firestore";
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import { AppModel } from "../../types";
|
|
4
|
+
/**
|
|
5
|
+
* @inline
|
|
6
|
+
*/
|
|
7
|
+
export type UseDeleteDocMutationValues<AppModelType extends AppModel = AppModel> = {
|
|
5
8
|
data: WithFieldValue<AppModelType>;
|
|
6
9
|
};
|
|
7
|
-
|
|
10
|
+
/**
|
|
11
|
+
* @inline
|
|
12
|
+
*/
|
|
13
|
+
export type UseDeleteDocMutationOptions<AppModelType extends AppModel = AppModel, TContext = unknown> = {
|
|
14
|
+
/**
|
|
15
|
+
* A reference to a firestore document
|
|
16
|
+
*/
|
|
8
17
|
reference: FirebaseFirestoreTypes.DocumentReference<AppModelType> | null;
|
|
9
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Options for useMutation hook excluding mutationFn. MutationKey will be equal to reference.path by default.
|
|
20
|
+
*/
|
|
21
|
+
options?: Omit<UseMutationOptions<void, Error, void, TContext>, "mutationFn">;
|
|
10
22
|
};
|
|
11
23
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* @
|
|
15
|
-
*
|
|
16
|
-
* @
|
|
24
|
+
* Executes a query with specified constraints and returns the count of matched documents.
|
|
25
|
+
*
|
|
26
|
+
* @group Hook
|
|
27
|
+
*
|
|
28
|
+
* @param {UseDeleteDocMutationOptions<AppModelType>} options - Configuration options for the query.
|
|
29
|
+
*
|
|
30
|
+
* @returns {UseMutationResult<void, Error, UseDeleteDocMutationValues<AppModelType>, TContext>} A mutation result
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```jsx
|
|
34
|
+
* export const MyComponent = () => {
|
|
35
|
+
* const {mutate} = useDeleteDocMutation({
|
|
36
|
+
* options: {
|
|
37
|
+
* },
|
|
38
|
+
* reference: document(),
|
|
39
|
+
* });
|
|
40
|
+
*
|
|
41
|
+
* // ....
|
|
42
|
+
* mutate();
|
|
43
|
+
* // ....
|
|
44
|
+
* };
|
|
45
|
+
* ```
|
|
17
46
|
*/
|
|
18
|
-
export declare const useDeleteDocMutation: <AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData, TContext = unknown>({ reference, options }: UseDeleteDocMutationOptions<AppModelType, TContext>) => import("@tanstack/react-query").UseMutationResult<void,
|
|
47
|
+
export declare const useDeleteDocMutation: <AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData, TContext = unknown>({ reference, options }: UseDeleteDocMutationOptions<AppModelType, TContext>) => import("@tanstack/react-query").UseMutationResult<void, Error, void, TContext>;
|
|
@@ -2,11 +2,28 @@ import { useMutation } from "@tanstack/react-query";
|
|
|
2
2
|
import { deleteDoc } from "@react-native-firebase/firestore";
|
|
3
3
|
import { useMemo } from "react";
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* @
|
|
8
|
-
*
|
|
9
|
-
* @
|
|
5
|
+
* Executes a query with specified constraints and returns the count of matched documents.
|
|
6
|
+
*
|
|
7
|
+
* @group Hook
|
|
8
|
+
*
|
|
9
|
+
* @param {UseDeleteDocMutationOptions<AppModelType>} options - Configuration options for the query.
|
|
10
|
+
*
|
|
11
|
+
* @returns {UseMutationResult<void, Error, UseDeleteDocMutationValues<AppModelType>, TContext>} A mutation result
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```jsx
|
|
15
|
+
* export const MyComponent = () => {
|
|
16
|
+
* const {mutate} = useDeleteDocMutation({
|
|
17
|
+
* options: {
|
|
18
|
+
* },
|
|
19
|
+
* reference: document(),
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* // ....
|
|
23
|
+
* mutate();
|
|
24
|
+
* // ....
|
|
25
|
+
* };
|
|
26
|
+
* ```
|
|
10
27
|
*/
|
|
11
28
|
export const useDeleteDocMutation = ({ reference, options = {} }) => {
|
|
12
29
|
const mutationKey = useMemo(() => [reference?.path], [reference?.path]);
|
|
@@ -1,30 +1,53 @@
|
|
|
1
1
|
import { useMutation, UseMutationOptions } from "@tanstack/react-query";
|
|
2
2
|
import { FirebaseFirestoreTypes, deleteDoc, WithFieldValue } from "@react-native-firebase/firestore";
|
|
3
3
|
|
|
4
|
-
import { ReactNativeFirebase } from "@react-native-firebase/app";
|
|
5
4
|
import { useMemo } from "react";
|
|
5
|
+
import { AppModel } from "../../types";
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
/**
|
|
8
|
+
* @inline
|
|
9
|
+
*/
|
|
10
|
+
export type UseDeleteDocMutationValues<AppModelType extends AppModel = AppModel> = {
|
|
8
11
|
data: WithFieldValue<AppModelType>;
|
|
9
12
|
};
|
|
10
13
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
> = {
|
|
14
|
+
/**
|
|
15
|
+
* @inline
|
|
16
|
+
*/
|
|
17
|
+
export type UseDeleteDocMutationOptions<AppModelType extends AppModel = AppModel, TContext = unknown> = {
|
|
18
|
+
/**
|
|
19
|
+
* A reference to a firestore document
|
|
20
|
+
*/
|
|
15
21
|
reference: FirebaseFirestoreTypes.DocumentReference<AppModelType> | null;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
>;
|
|
22
|
+
/**
|
|
23
|
+
* Options for useMutation hook excluding mutationFn. MutationKey will be equal to reference.path by default.
|
|
24
|
+
*/
|
|
25
|
+
options?: Omit<UseMutationOptions<void, Error, void, TContext>, "mutationFn">;
|
|
20
26
|
};
|
|
21
27
|
|
|
22
28
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* @
|
|
26
|
-
*
|
|
27
|
-
* @
|
|
29
|
+
* Executes a query with specified constraints and returns the count of matched documents.
|
|
30
|
+
*
|
|
31
|
+
* @group Hook
|
|
32
|
+
*
|
|
33
|
+
* @param {UseDeleteDocMutationOptions<AppModelType>} options - Configuration options for the query.
|
|
34
|
+
*
|
|
35
|
+
* @returns {UseMutationResult<void, Error, UseDeleteDocMutationValues<AppModelType>, TContext>} A mutation result
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```jsx
|
|
39
|
+
* export const MyComponent = () => {
|
|
40
|
+
* const {mutate} = useDeleteDocMutation({
|
|
41
|
+
* options: {
|
|
42
|
+
* },
|
|
43
|
+
* reference: document(),
|
|
44
|
+
* });
|
|
45
|
+
*
|
|
46
|
+
* // ....
|
|
47
|
+
* mutate();
|
|
48
|
+
* // ....
|
|
49
|
+
* };
|
|
50
|
+
* ```
|
|
28
51
|
*/
|
|
29
52
|
export const useDeleteDocMutation = <
|
|
30
53
|
AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData,
|
|
@@ -1,19 +1,27 @@
|
|
|
1
1
|
import { FirebaseFirestoreTypes } from "@react-native-firebase/firestore";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
path?: string;
|
|
5
|
-
pathSegments?: string[];
|
|
6
|
-
};
|
|
2
|
+
import { AppModel } from "../../types";
|
|
3
|
+
import { GetDocRefOptions } from "./utils/getDocRef";
|
|
7
4
|
/**
|
|
8
|
-
*
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
* @inline
|
|
6
|
+
*/
|
|
7
|
+
export type UseDocReferenceOptions<AppModelType extends AppModel = AppModel> = Omit<GetDocRefOptions<AppModelType>, "db">;
|
|
8
|
+
/**
|
|
9
|
+
* Gets a `CollectionReference` instance.
|
|
10
|
+
*
|
|
11
|
+
* @group Hook
|
|
12
|
+
*
|
|
13
|
+
* @param {UseDocReferenceOptions<AppModelType>} options - Options
|
|
11
14
|
*
|
|
12
|
-
* @
|
|
13
|
-
* @param {string} options.path - The path to the Firestore document.
|
|
14
|
-
* @param {DbModelType} options.reference - Reference data for the document, providing additional context or specifics.
|
|
15
|
-
* @param {string[]} options.pathSegments - Parts of the path to construct the full document path dynamically.
|
|
15
|
+
* @returns {FirebaseFirestoreTypes.DocumentReference<AppModelType, AppModelType> | null} A reference to a Firestore document
|
|
16
16
|
*
|
|
17
|
-
* @
|
|
17
|
+
* @example
|
|
18
|
+
* ```jsx
|
|
19
|
+
* export const MyComponent = () => {
|
|
20
|
+
* const ref = useDocReference({
|
|
21
|
+
* reference: collection('todos')
|
|
22
|
+
* path: 'first'
|
|
23
|
+
* });
|
|
24
|
+
* };
|
|
25
|
+
* ```
|
|
18
26
|
*/
|
|
19
|
-
export declare const useDocReference: <AppModelType extends
|
|
27
|
+
export declare const useDocReference: <AppModelType extends AppModel = AppModel>({ path, reference, pathSegments }: UseDocReferenceOptions<AppModelType>) => FirebaseFirestoreTypes.DocumentReference<AppModelType> | null;
|
|
@@ -1,36 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { useMemo } from "react";
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
3
2
|
import { useFirestore } from "./useFirestore";
|
|
3
|
+
import { getDocRef } from "./utils/getDocRef";
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
* If a reference is not provided, it constructs a document reference using the Firestore instance, path, and path segments.
|
|
5
|
+
* Gets a `CollectionReference` instance.
|
|
7
6
|
*
|
|
8
|
-
* @
|
|
9
|
-
* @param {UseDocReferenceOptions<AppModelType>} options - An object containing the path, path segments, and optional reference.
|
|
10
|
-
* @param {string} options.path - The path to the document in the Firestore database.
|
|
11
|
-
* @param {string[]} [options.pathSegments] - Optional additional segments to join with the path.
|
|
12
|
-
* @param {DocumentReference | CollectionReference} [options.reference] - Optional Firestore reference object that influences how the document reference is constructed.
|
|
7
|
+
* @group Hook
|
|
13
8
|
*
|
|
14
|
-
* @
|
|
15
|
-
*/
|
|
16
|
-
const getDocReference = (db, { path, pathSegments, reference }) => {
|
|
17
|
-
return (!reference ? doc(db, path || "", ...(pathSegments || [])) : doc(reference, path, ...(pathSegments || [])));
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* Custom hook to generate and manage a Firestore document reference.
|
|
21
|
-
* This hook facilitates the retrieval of a Firestore document reference based on given options such as path and reference data.
|
|
22
|
-
* The reference is updated whenever the associated path, reference, or path segments change.
|
|
9
|
+
* @param {UseDocReferenceOptions<AppModelType>} options - Options
|
|
23
10
|
*
|
|
24
|
-
* @
|
|
25
|
-
* @param {string} options.path - The path to the Firestore document.
|
|
26
|
-
* @param {DbModelType} options.reference - Reference data for the document, providing additional context or specifics.
|
|
27
|
-
* @param {string[]} options.pathSegments - Parts of the path to construct the full document path dynamically.
|
|
11
|
+
* @returns {FirebaseFirestoreTypes.DocumentReference<AppModelType, AppModelType> | null} A reference to a Firestore document
|
|
28
12
|
*
|
|
29
|
-
* @
|
|
13
|
+
* @example
|
|
14
|
+
* ```jsx
|
|
15
|
+
* export const MyComponent = () => {
|
|
16
|
+
* const ref = useDocReference({
|
|
17
|
+
* reference: collection('todos')
|
|
18
|
+
* path: 'first'
|
|
19
|
+
* });
|
|
20
|
+
* };
|
|
21
|
+
* ```
|
|
30
22
|
*/
|
|
31
23
|
export const useDocReference = ({ path, reference, pathSegments }) => {
|
|
32
24
|
const db = useFirestore();
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
25
|
+
const ref = useRef(getDocRef({ db, path, pathSegments, reference }));
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
ref.current = getDocRef({ db, path, pathSegments, reference });
|
|
28
|
+
}, [path, reference, pathSegments, db]);
|
|
29
|
+
return ref.current;
|
|
36
30
|
};
|
|
@@ -1,63 +1,50 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FirebaseFirestoreTypes } from "@react-native-firebase/firestore";
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { useEffect, useRef } from "react";
|
|
4
4
|
import { useFirestore } from "./useFirestore";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData
|
|
8
|
-
> = {
|
|
9
|
-
reference?:
|
|
10
|
-
| FirebaseFirestoreTypes.CollectionReference<AppModelType>
|
|
11
|
-
| FirebaseFirestoreTypes.DocumentReference<AppModelType>;
|
|
12
|
-
path?: string;
|
|
13
|
-
pathSegments?: string[];
|
|
14
|
-
};
|
|
5
|
+
import { AppModel } from "../../types";
|
|
6
|
+
import { getDocRef, GetDocRefOptions } from "./utils/getDocRef";
|
|
15
7
|
|
|
16
8
|
/**
|
|
17
|
-
*
|
|
18
|
-
* If a reference is not provided, it constructs a document reference using the Firestore instance, path, and path segments.
|
|
19
|
-
*
|
|
20
|
-
* @param {Firestore} db - The Firestore database instance used to create the document reference.
|
|
21
|
-
* @param {UseDocReferenceOptions<AppModelType>} options - An object containing the path, path segments, and optional reference.
|
|
22
|
-
* @param {string} options.path - The path to the document in the Firestore database.
|
|
23
|
-
* @param {string[]} [options.pathSegments] - Optional additional segments to join with the path.
|
|
24
|
-
* @param {DocumentReference | CollectionReference} [options.reference] - Optional Firestore reference object that influences how the document reference is constructed.
|
|
25
|
-
*
|
|
26
|
-
* @returns {DocumentReference<AppModelType> | null} A Firestore document reference if the path is specified; otherwise, returns null if path is not provided.
|
|
9
|
+
* @inline
|
|
27
10
|
*/
|
|
28
|
-
|
|
29
|
-
AppModelType
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
{ path, pathSegments, reference }: UseDocReferenceOptions<AppModelType>
|
|
33
|
-
) => {
|
|
34
|
-
return (
|
|
35
|
-
!reference ? doc(db, path || "", ...(pathSegments || [])) : doc(reference, path, ...(pathSegments || []))
|
|
36
|
-
) as FirebaseFirestoreTypes.DocumentReference<AppModelType>;
|
|
37
|
-
};
|
|
11
|
+
export type UseDocReferenceOptions<AppModelType extends AppModel = AppModel> = Omit<
|
|
12
|
+
GetDocRefOptions<AppModelType>,
|
|
13
|
+
"db"
|
|
14
|
+
>;
|
|
38
15
|
|
|
39
16
|
/**
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
17
|
+
* Gets a `CollectionReference` instance.
|
|
18
|
+
*
|
|
19
|
+
* @group Hook
|
|
43
20
|
*
|
|
44
|
-
* @param {UseDocReferenceOptions<AppModelType>} options -
|
|
45
|
-
* @param {string} options.path - The path to the Firestore document.
|
|
46
|
-
* @param {DbModelType} options.reference - Reference data for the document, providing additional context or specifics.
|
|
47
|
-
* @param {string[]} options.pathSegments - Parts of the path to construct the full document path dynamically.
|
|
21
|
+
* @param {UseDocReferenceOptions<AppModelType>} options - Options
|
|
48
22
|
*
|
|
49
|
-
* @returns {FirebaseFirestoreTypes.DocumentReference<AppModelType> | null}
|
|
23
|
+
* @returns {FirebaseFirestoreTypes.DocumentReference<AppModelType, AppModelType> | null} A reference to a Firestore document
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```jsx
|
|
27
|
+
* export const MyComponent = () => {
|
|
28
|
+
* const ref = useDocReference({
|
|
29
|
+
* reference: collection('todos')
|
|
30
|
+
* path: 'first'
|
|
31
|
+
* });
|
|
32
|
+
* };
|
|
33
|
+
* ```
|
|
50
34
|
*/
|
|
51
|
-
export const useDocReference = <
|
|
52
|
-
AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData
|
|
53
|
-
>({
|
|
35
|
+
export const useDocReference = <AppModelType extends AppModel = AppModel>({
|
|
54
36
|
path,
|
|
55
37
|
reference,
|
|
56
38
|
pathSegments
|
|
57
|
-
}: UseDocReferenceOptions<AppModelType>)
|
|
39
|
+
}: UseDocReferenceOptions<AppModelType>) => {
|
|
58
40
|
const db = useFirestore();
|
|
41
|
+
const ref = useRef<FirebaseFirestoreTypes.DocumentReference<AppModelType> | null>(
|
|
42
|
+
getDocRef({ db, path, pathSegments, reference })
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
ref.current = getDocRef({ db, path, pathSegments, reference });
|
|
47
|
+
}, [path, reference, pathSegments, db]);
|
|
59
48
|
|
|
60
|
-
return
|
|
61
|
-
return getDocReference(db, { path, pathSegments, reference });
|
|
62
|
-
}, [db, reference, path, pathSegments]);
|
|
49
|
+
return ref.current;
|
|
63
50
|
};
|
|
@@ -1,23 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { AppModel } from "../../types";
|
|
2
|
+
import { GetDocRefOptions } from "./utils/getDocRef";
|
|
3
|
+
/**
|
|
4
|
+
* @inline
|
|
5
|
+
*/
|
|
6
|
+
export type UseDocReferencesOptions<AppModelType extends AppModel = AppModel> = {
|
|
7
|
+
references: Omit<GetDocRefOptions<AppModelType>, "db">[];
|
|
6
8
|
};
|
|
7
9
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
+
* Gets `CollectionReference` instances
|
|
11
|
+
*
|
|
12
|
+
* @group Hook
|
|
13
|
+
*
|
|
14
|
+
* @param {UseDocReferencesOptions<AppModelType>} options - Options
|
|
10
15
|
*
|
|
11
|
-
*
|
|
12
|
-
* an existing reference, or path segments, and returns an array of generated
|
|
13
|
-
* Firestore document references based on those options. The references can be used
|
|
14
|
-
* to interact with the Firestore database documents. It uses memoization to optimize
|
|
15
|
-
* reference generation.
|
|
16
|
+
* @returns {Array<FirebaseFirestoreTypes.DocumentReference<AppModelType> | null>} A reference to a Firestore document
|
|
16
17
|
*
|
|
17
|
-
* @
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```jsx
|
|
20
|
+
* export const MyComponent = () => {
|
|
21
|
+
* const ref = useDocReference({
|
|
22
|
+
* reference: collection('todos')
|
|
23
|
+
* path: 'first'
|
|
24
|
+
* });
|
|
25
|
+
* };
|
|
26
|
+
* ```
|
|
22
27
|
*/
|
|
23
|
-
export declare const useDocReferences: <AppModelType extends
|
|
28
|
+
export declare const useDocReferences: <AppModelType extends AppModel = AppModel>({ references }: UseDocReferencesOptions<AppModelType>) => import("@react-native-firebase/firestore").FirebaseFirestoreTypes.DocumentReference<AppModelType>[];
|
|
@@ -1,29 +1,28 @@
|
|
|
1
|
-
import { doc } from "@react-native-firebase/firestore";
|
|
2
1
|
import { useMemo } from "react";
|
|
3
2
|
import { useFirestore } from "./useFirestore";
|
|
3
|
+
import { getDocRef } from "./utils/getDocRef";
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
* reference options.
|
|
5
|
+
* Gets `CollectionReference` instances
|
|
7
6
|
*
|
|
8
|
-
*
|
|
9
|
-
* an existing reference, or path segments, and returns an array of generated
|
|
10
|
-
* Firestore document references based on those options. The references can be used
|
|
11
|
-
* to interact with the Firestore database documents. It uses memoization to optimize
|
|
12
|
-
* reference generation.
|
|
7
|
+
* @group Hook
|
|
13
8
|
*
|
|
14
|
-
* @param {UseDocReferencesOptions<AppModelType>
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
9
|
+
* @param {UseDocReferencesOptions<AppModelType>} options - Options
|
|
10
|
+
*
|
|
11
|
+
* @returns {Array<FirebaseFirestoreTypes.DocumentReference<AppModelType> | null>} A reference to a Firestore document
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```jsx
|
|
15
|
+
* export const MyComponent = () => {
|
|
16
|
+
* const ref = useDocReference({
|
|
17
|
+
* reference: collection('todos')
|
|
18
|
+
* path: 'first'
|
|
19
|
+
* });
|
|
20
|
+
* };
|
|
21
|
+
* ```
|
|
19
22
|
*/
|
|
20
|
-
export const useDocReferences = (references) => {
|
|
23
|
+
export const useDocReferences = ({ references }) => {
|
|
21
24
|
const db = useFirestore();
|
|
22
25
|
return useMemo(() => {
|
|
23
|
-
return references.map(({ path, reference, pathSegments }) => {
|
|
24
|
-
return (!reference
|
|
25
|
-
? doc(db, path || "", ...(pathSegments || []))
|
|
26
|
-
: doc(reference, path, ...(pathSegments || [])));
|
|
27
|
-
});
|
|
26
|
+
return references.map(({ path, reference, pathSegments }) => getDocRef({ db, reference, path, pathSegments }));
|
|
28
27
|
}, [references, db]);
|
|
29
28
|
};
|