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
|
@@ -1,48 +1,40 @@
|
|
|
1
|
-
import { doc, FirebaseFirestoreTypes } from "@react-native-firebase/firestore";
|
|
2
|
-
|
|
3
1
|
import { useMemo } from "react";
|
|
4
2
|
import { useFirestore } from "./useFirestore";
|
|
3
|
+
import { AppModel } from "../../types";
|
|
4
|
+
import { getDocRef, GetDocRefOptions } from "./utils/getDocRef";
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
| FirebaseFirestoreTypes.DocumentReference<AppModelType>;
|
|
12
|
-
path: string;
|
|
13
|
-
pathSegments?: string[];
|
|
6
|
+
/**
|
|
7
|
+
* @inline
|
|
8
|
+
*/
|
|
9
|
+
export type UseDocReferencesOptions<AppModelType extends AppModel = AppModel> = {
|
|
10
|
+
references: Omit<GetDocRefOptions<AppModelType>, "db">[];
|
|
14
11
|
};
|
|
15
12
|
|
|
16
13
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
14
|
+
* Gets `CollectionReference` instances
|
|
15
|
+
*
|
|
16
|
+
* @group Hook
|
|
17
|
+
*
|
|
18
|
+
* @param {UseDocReferencesOptions<AppModelType>} options - Options
|
|
19
19
|
*
|
|
20
|
-
*
|
|
21
|
-
* an existing reference, or path segments, and returns an array of generated
|
|
22
|
-
* Firestore document references based on those options. The references can be used
|
|
23
|
-
* to interact with the Firestore database documents. It uses memoization to optimize
|
|
24
|
-
* reference generation.
|
|
20
|
+
* @returns {Array<FirebaseFirestoreTypes.DocumentReference<AppModelType> | null>} A reference to a Firestore document
|
|
25
21
|
*
|
|
26
|
-
* @
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```jsx
|
|
24
|
+
* export const MyComponent = () => {
|
|
25
|
+
* const ref = useDocReference({
|
|
26
|
+
* reference: collection('todos')
|
|
27
|
+
* path: 'first'
|
|
28
|
+
* });
|
|
29
|
+
* };
|
|
30
|
+
* ```
|
|
31
31
|
*/
|
|
32
|
-
export const useDocReferences = <
|
|
33
|
-
|
|
34
|
-
>
|
|
35
|
-
references: UseDocReferencesOptions<AppModelType>[]
|
|
36
|
-
) => {
|
|
32
|
+
export const useDocReferences = <AppModelType extends AppModel = AppModel>({
|
|
33
|
+
references
|
|
34
|
+
}: UseDocReferencesOptions<AppModelType>) => {
|
|
37
35
|
const db = useFirestore();
|
|
38
36
|
|
|
39
37
|
return useMemo(() => {
|
|
40
|
-
return references.map(({ path, reference, pathSegments }) => {
|
|
41
|
-
return (
|
|
42
|
-
!reference
|
|
43
|
-
? doc(db, path || "", ...(pathSegments || []))
|
|
44
|
-
: doc(reference, path, ...(pathSegments || []))
|
|
45
|
-
) as FirebaseFirestoreTypes.DocumentReference<AppModelType>;
|
|
46
|
-
});
|
|
38
|
+
return references.map(({ path, reference, pathSegments }) => getDocRef({ db, reference, path, pathSegments }));
|
|
47
39
|
}, [references, db]);
|
|
48
40
|
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* It extracts the Firestore object from the Firebase context, allowing components to interact with Firestore services.
|
|
2
|
+
* Returns an instance of firestore bound to the closest context.
|
|
4
3
|
*
|
|
5
|
-
* @
|
|
4
|
+
* @group Hook
|
|
5
|
+
*
|
|
6
|
+
* @returns {Firestore}
|
|
6
7
|
*/
|
|
7
8
|
export declare const useFirestore: () => import("@react-native-firebase/firestore").FirebaseFirestoreTypes.Module;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { useContext } from "react";
|
|
2
2
|
import { FirebaseContext } from "../context/FirebaseContext";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
* It extracts the Firestore object from the Firebase context, allowing components to interact with Firestore services.
|
|
4
|
+
* Returns an instance of firestore bound to the closest context.
|
|
6
5
|
*
|
|
7
|
-
* @
|
|
6
|
+
* @group Hook
|
|
7
|
+
*
|
|
8
|
+
* @returns {Firestore}
|
|
8
9
|
*/
|
|
9
10
|
export const useFirestore = () => {
|
|
10
11
|
const { firestore } = useContext(FirebaseContext);
|
|
@@ -2,10 +2,11 @@ import { useContext } from "react";
|
|
|
2
2
|
import { FirebaseContext } from "../context/FirebaseContext";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
* It extracts the Firestore object from the Firebase context, allowing components to interact with Firestore services.
|
|
5
|
+
* Returns an instance of firestore bound to the closest context.
|
|
7
6
|
*
|
|
8
|
-
* @
|
|
7
|
+
* @group Hook
|
|
8
|
+
*
|
|
9
|
+
* @returns {Firestore}
|
|
9
10
|
*/
|
|
10
11
|
export const useFirestore = () => {
|
|
11
12
|
const { firestore } = useContext(FirebaseContext);
|
|
@@ -1,18 +1,37 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GetDocDataOptions } from "./utils/getDocData";
|
|
2
2
|
import { UseQueryOptions } from "@tanstack/react-query";
|
|
3
|
-
|
|
4
|
-
options: Omit<UseQueryOptions<AppModelType | null | undefined, Error, AppModelType>, "queryFn"> & Required<Pick<UseQueryOptions<AppModelType, Error, AppModelType>, "queryKey">>;
|
|
5
|
-
path?: string;
|
|
6
|
-
pathSegments?: string[];
|
|
7
|
-
reference: FirebaseFirestoreTypes.CollectionReference<AppModelType> | FirebaseFirestoreTypes.DocumentReference<AppModelType>;
|
|
8
|
-
};
|
|
3
|
+
import { AppModel } from "../../types";
|
|
9
4
|
/**
|
|
10
|
-
*
|
|
11
|
-
* @param {Object} options - The options for configuring the Firestore query.
|
|
12
|
-
* @param {string} reference - The reference to the document in Firestore.
|
|
13
|
-
* @param {string} path - The path to the document in Firestore.
|
|
14
|
-
* @param {Array<string>} pathSegments - Segments of the path to document in Firestore.
|
|
15
|
-
* @returns {Object} Result of the query containing document data and query status.
|
|
5
|
+
* @inline
|
|
16
6
|
*/
|
|
17
|
-
|
|
7
|
+
type UseGetDocOptions<AppModelType extends AppModel = AppModel> = {
|
|
8
|
+
/**
|
|
9
|
+
* Reqct-query options that must include queryKey and shall not define queryFn
|
|
10
|
+
*/
|
|
11
|
+
options: Omit<UseQueryOptions<AppModelType | null, Error, AppModelType>, "queryFn"> & Required<Pick<UseQueryOptions<AppModelType, Error, AppModelType>, "queryKey">>;
|
|
12
|
+
} & Omit<GetDocDataOptions<AppModelType>, "db">;
|
|
13
|
+
/**
|
|
14
|
+
* Executes a query on a Firestore data source and returns the resulting document.
|
|
15
|
+
*
|
|
16
|
+
* @group Hook
|
|
17
|
+
*
|
|
18
|
+
* @param {UseGetDocOptions<AppModelType>} options - Configuration options for the query.
|
|
19
|
+
*
|
|
20
|
+
* @returns {UseQueryResult<AppModelType, Error>} An object containing document's data
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```jsx
|
|
24
|
+
* export const MyComponent = () => {
|
|
25
|
+
* const doc = useGetDocData({
|
|
26
|
+
* options: {
|
|
27
|
+
* queryKey: ['key']
|
|
28
|
+
* },
|
|
29
|
+
* reference: collection(),
|
|
30
|
+
* path: 'id'
|
|
31
|
+
* });
|
|
32
|
+
* console.log(doc);
|
|
33
|
+
* };
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare const useGetDocData: <AppModelType extends AppModel = AppModel>({ options, reference, path, pathSegments }: UseGetDocOptions<AppModelType>) => import("@tanstack/react-query").UseQueryResult<AppModelType, Error>;
|
|
18
37
|
export {};
|
|
@@ -2,12 +2,27 @@ import { useFirestore } from "./useFirestore";
|
|
|
2
2
|
import { getDocData } from "./utils/getDocData";
|
|
3
3
|
import { useQuery } from "@tanstack/react-query";
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* @
|
|
8
|
-
*
|
|
9
|
-
* @param {
|
|
10
|
-
*
|
|
5
|
+
* Executes a query on a Firestore data source and returns the resulting document.
|
|
6
|
+
*
|
|
7
|
+
* @group Hook
|
|
8
|
+
*
|
|
9
|
+
* @param {UseGetDocOptions<AppModelType>} options - Configuration options for the query.
|
|
10
|
+
*
|
|
11
|
+
* @returns {UseQueryResult<AppModelType, Error>} An object containing document's data
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```jsx
|
|
15
|
+
* export const MyComponent = () => {
|
|
16
|
+
* const doc = useGetDocData({
|
|
17
|
+
* options: {
|
|
18
|
+
* queryKey: ['key']
|
|
19
|
+
* },
|
|
20
|
+
* reference: collection(),
|
|
21
|
+
* path: 'id'
|
|
22
|
+
* });
|
|
23
|
+
* console.log(doc);
|
|
24
|
+
* };
|
|
25
|
+
* ```
|
|
11
26
|
*/
|
|
12
27
|
export const useGetDocData = ({ options, reference, path, pathSegments }) => {
|
|
13
28
|
const db = useFirestore();
|
|
@@ -1,31 +1,43 @@
|
|
|
1
|
-
import { FirebaseFirestoreTypes } from "@react-native-firebase/firestore";
|
|
2
|
-
|
|
3
1
|
import { useFirestore } from "./useFirestore";
|
|
4
|
-
import { getDocData } from "./utils/getDocData";
|
|
2
|
+
import { getDocData, GetDocDataOptions } from "./utils/getDocData";
|
|
5
3
|
import { useQuery, UseQueryOptions } from "@tanstack/react-query";
|
|
4
|
+
import { AppModel } from "../../types";
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
6
|
+
/**
|
|
7
|
+
* @inline
|
|
8
|
+
*/
|
|
9
|
+
type UseGetDocOptions<AppModelType extends AppModel = AppModel> = {
|
|
10
|
+
/**
|
|
11
|
+
* Reqct-query options that must include queryKey and shall not define queryFn
|
|
12
|
+
*/
|
|
13
|
+
options: Omit<UseQueryOptions<AppModelType | null, Error, AppModelType>, "queryFn"> &
|
|
14
|
+
Required<Pick<UseQueryOptions<AppModelType, Error, AppModelType>, "queryKey">>;
|
|
15
|
+
} & Omit<GetDocDataOptions<AppModelType>, "db">;
|
|
17
16
|
|
|
18
17
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* @
|
|
22
|
-
*
|
|
23
|
-
* @param {
|
|
24
|
-
*
|
|
18
|
+
* Executes a query on a Firestore data source and returns the resulting document.
|
|
19
|
+
*
|
|
20
|
+
* @group Hook
|
|
21
|
+
*
|
|
22
|
+
* @param {UseGetDocOptions<AppModelType>} options - Configuration options for the query.
|
|
23
|
+
*
|
|
24
|
+
* @returns {UseQueryResult<AppModelType, Error>} An object containing document's data
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```jsx
|
|
28
|
+
* export const MyComponent = () => {
|
|
29
|
+
* const doc = useGetDocData({
|
|
30
|
+
* options: {
|
|
31
|
+
* queryKey: ['key']
|
|
32
|
+
* },
|
|
33
|
+
* reference: collection(),
|
|
34
|
+
* path: 'id'
|
|
35
|
+
* });
|
|
36
|
+
* console.log(doc);
|
|
37
|
+
* };
|
|
38
|
+
* ```
|
|
25
39
|
*/
|
|
26
|
-
export const useGetDocData = <
|
|
27
|
-
AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData
|
|
28
|
-
>({
|
|
40
|
+
export const useGetDocData = <AppModelType extends AppModel = AppModel>({
|
|
29
41
|
options,
|
|
30
42
|
reference,
|
|
31
43
|
path,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FirebaseFirestoreTypes, QueryConstraint, QueryNonFilterConstraint } from "@react-native-firebase/firestore";
|
|
2
2
|
import { UseInfiniteQueryOptions as UseReactInfiniteQueryOptions, QueryKey, UseInfiniteQueryResult, InfiniteData } 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
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
UseInfiniteQueryResult,
|
|
14
14
|
InfiniteData
|
|
15
15
|
} from "@tanstack/react-query";
|
|
16
|
-
import { QueryFilterConstraint } from "./
|
|
16
|
+
import { QueryFilterConstraint } from "./utils/buildCompositeFilter";
|
|
17
17
|
import { AppModel } from "../../types";
|
|
18
18
|
|
|
19
19
|
/**
|
|
@@ -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
|
/**
|
|
@@ -10,27 +10,6 @@ export type UseQueryConstraints<AppModelType extends AppModel = AppModel> = {
|
|
|
10
10
|
*/
|
|
11
11
|
constraints: NonFilterQueryConstraint<AppModelType>[];
|
|
12
12
|
};
|
|
13
|
-
/**
|
|
14
|
-
* A generic mothod to build query constraints for firebase
|
|
15
|
-
*
|
|
16
|
-
* @group Utility
|
|
17
|
-
*
|
|
18
|
-
* @param {NonFilterQueryConstraint<AppModelType>} constraint
|
|
19
|
-
*
|
|
20
|
-
* @returns {FirebaseFirestoreTypes.QueryNonFilterConstraint}
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* ```jsx
|
|
24
|
-
* const firebaseConfig = {};
|
|
25
|
-
* export const constraint = useMemo(() => {
|
|
26
|
-
* return buildQueryConstraint({
|
|
27
|
-
* type: 'limit',
|
|
28
|
-
* limit: 1
|
|
29
|
-
* });
|
|
30
|
-
* };
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
export declare const buildQueryConstraint: <AppModelType extends AppModel = AppModel>(constraint: NonFilterQueryConstraint<AppModelType>) => QueryNonFilterConstraint;
|
|
34
13
|
/**
|
|
35
14
|
* A hook to build a list of non-filter query constraints for firebase queries.
|
|
36
15
|
* It uses buildQueryConstraint method and useMemo hook.
|
|
@@ -1,43 +1,5 @@
|
|
|
1
|
-
import { startAt, orderBy, limit, limitToLast, startAfter, endAt, endBefore } from "@react-native-firebase/firestore";
|
|
2
1
|
import { useMemo } from "react";
|
|
3
|
-
|
|
4
|
-
* A generic mothod to build query constraints for firebase
|
|
5
|
-
*
|
|
6
|
-
* @group Utility
|
|
7
|
-
*
|
|
8
|
-
* @param {NonFilterQueryConstraint<AppModelType>} constraint
|
|
9
|
-
*
|
|
10
|
-
* @returns {FirebaseFirestoreTypes.QueryNonFilterConstraint}
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```jsx
|
|
14
|
-
* const firebaseConfig = {};
|
|
15
|
-
* export const constraint = useMemo(() => {
|
|
16
|
-
* return buildQueryConstraint({
|
|
17
|
-
* type: 'limit',
|
|
18
|
-
* limit: 1
|
|
19
|
-
* });
|
|
20
|
-
* };
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
export const buildQueryConstraint = (constraint) => {
|
|
24
|
-
switch (constraint.type) {
|
|
25
|
-
case "orderBy":
|
|
26
|
-
return orderBy(constraint.fieldPath, constraint.directionStr);
|
|
27
|
-
case "startAt":
|
|
28
|
-
return startAt(...constraint.arguments);
|
|
29
|
-
case "startAfter":
|
|
30
|
-
return startAfter(...constraint.arguments);
|
|
31
|
-
case "endAt":
|
|
32
|
-
return endAt(constraint.value, constraint.key);
|
|
33
|
-
case "endBefore":
|
|
34
|
-
return endBefore(constraint.value, constraint.key);
|
|
35
|
-
case "limit":
|
|
36
|
-
return limit(constraint.limit);
|
|
37
|
-
case "limitToLast":
|
|
38
|
-
return limitToLast(constraint.limit);
|
|
39
|
-
}
|
|
40
|
-
};
|
|
2
|
+
import { buildQueryConstraint } from "./utils/buildQueryConstraint";
|
|
41
3
|
/**
|
|
42
4
|
* A hook to build a list of non-filter query constraints for firebase queries.
|
|
43
5
|
* It uses buildQueryConstraint method and useMemo hook.
|
|
@@ -1,16 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
startAt,
|
|
3
|
-
orderBy,
|
|
4
|
-
limit,
|
|
5
|
-
limitToLast,
|
|
6
|
-
startAfter,
|
|
7
|
-
endAt,
|
|
8
|
-
endBefore,
|
|
9
|
-
type QueryNonFilterConstraint
|
|
10
|
-
} from "@react-native-firebase/firestore";
|
|
1
|
+
import { type QueryNonFilterConstraint } from "@react-native-firebase/firestore";
|
|
11
2
|
import { useMemo } from "react";
|
|
12
3
|
import { AppModel } from "../../types/AppModel";
|
|
13
4
|
import { type NonFilterQueryConstraint } from "../../types/QueryConstraints";
|
|
5
|
+
import { buildQueryConstraint } from "./utils/buildQueryConstraint";
|
|
14
6
|
|
|
15
7
|
/**
|
|
16
8
|
* @inline
|
|
@@ -22,47 +14,6 @@ export type UseQueryConstraints<AppModelType extends AppModel = AppModel> = {
|
|
|
22
14
|
constraints: NonFilterQueryConstraint<AppModelType>[];
|
|
23
15
|
};
|
|
24
16
|
|
|
25
|
-
/**
|
|
26
|
-
* A generic mothod to build query constraints for firebase
|
|
27
|
-
*
|
|
28
|
-
* @group Utility
|
|
29
|
-
*
|
|
30
|
-
* @param {NonFilterQueryConstraint<AppModelType>} constraint
|
|
31
|
-
*
|
|
32
|
-
* @returns {FirebaseFirestoreTypes.QueryNonFilterConstraint}
|
|
33
|
-
*
|
|
34
|
-
* @example
|
|
35
|
-
* ```jsx
|
|
36
|
-
* const firebaseConfig = {};
|
|
37
|
-
* export const constraint = useMemo(() => {
|
|
38
|
-
* return buildQueryConstraint({
|
|
39
|
-
* type: 'limit',
|
|
40
|
-
* limit: 1
|
|
41
|
-
* });
|
|
42
|
-
* };
|
|
43
|
-
* ```
|
|
44
|
-
*/
|
|
45
|
-
export const buildQueryConstraint = <AppModelType extends AppModel = AppModel>(
|
|
46
|
-
constraint: NonFilterQueryConstraint<AppModelType>
|
|
47
|
-
): QueryNonFilterConstraint => {
|
|
48
|
-
switch (constraint.type) {
|
|
49
|
-
case "orderBy":
|
|
50
|
-
return orderBy(constraint.fieldPath as string, constraint.directionStr);
|
|
51
|
-
case "startAt":
|
|
52
|
-
return startAt(...constraint.arguments);
|
|
53
|
-
case "startAfter":
|
|
54
|
-
return startAfter(...constraint.arguments);
|
|
55
|
-
case "endAt":
|
|
56
|
-
return endAt(constraint.value, constraint.key);
|
|
57
|
-
case "endBefore":
|
|
58
|
-
return endBefore(constraint.value, constraint.key);
|
|
59
|
-
case "limit":
|
|
60
|
-
return limit(constraint.limit);
|
|
61
|
-
case "limitToLast":
|
|
62
|
-
return limitToLast(constraint.limit);
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
|
|
66
17
|
/**
|
|
67
18
|
* A hook to build a list of non-filter query constraints for firebase queries.
|
|
68
19
|
* It uses buildQueryConstraint method and useMemo hook.
|
|
@@ -1,15 +1,39 @@
|
|
|
1
1
|
import { UseMutationOptions } from "@tanstack/react-query";
|
|
2
2
|
import { FirebaseFirestoreTypes } from "@react-native-firebase/firestore";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
/**
|
|
4
|
+
* @inline
|
|
5
|
+
*/
|
|
6
|
+
export type UseRunTransactionValues = <T = unknown>(transaction: FirebaseFirestoreTypes.Transaction) => T;
|
|
7
|
+
/**
|
|
8
|
+
* @inline
|
|
9
|
+
*/
|
|
10
|
+
export type UseRunTransactionOptions<T = unknown, TContext = unknown> = {
|
|
11
|
+
/**
|
|
12
|
+
* Reqct-mutation options that shall omit mutationFn
|
|
13
|
+
*/
|
|
14
|
+
options?: Omit<UseMutationOptions<T, Error, UseRunTransactionValues, TContext>, "mutationFn">;
|
|
7
15
|
};
|
|
8
16
|
/**
|
|
9
|
-
*
|
|
17
|
+
* Executes a Firestore transaction
|
|
18
|
+
*
|
|
19
|
+
* @group Hook
|
|
20
|
+
*
|
|
21
|
+
* @param {UseRunTransactionOptions<T>} options - Configuration options for the mutation.
|
|
22
|
+
*
|
|
23
|
+
* @returns {UseMutationResult<T, Error>} An object representing mutation
|
|
10
24
|
*
|
|
11
|
-
* @
|
|
12
|
-
*
|
|
13
|
-
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```jsx
|
|
27
|
+
* export const MyComponent = () => {
|
|
28
|
+
* const doc = useGetDocData({
|
|
29
|
+
* options: {
|
|
30
|
+
* queryKey: ['key']
|
|
31
|
+
* },
|
|
32
|
+
* reference: collection(),
|
|
33
|
+
* path: 'id'
|
|
34
|
+
* });
|
|
35
|
+
* console.log(doc);
|
|
36
|
+
* };
|
|
37
|
+
* ```
|
|
14
38
|
*/
|
|
15
|
-
export declare const useRunTransaction: <
|
|
39
|
+
export declare const useRunTransaction: <T = unknown, TContext = unknown>({ options }: UseRunTransactionOptions<T, TContext>) => import("@tanstack/react-query").UseMutationResult<T, Error, UseRunTransactionValues, TContext>;
|
|
@@ -2,11 +2,27 @@ import { useMutation } from "@tanstack/react-query";
|
|
|
2
2
|
import { runTransaction } from "@react-native-firebase/firestore";
|
|
3
3
|
import { useFirestore } from "./useFirestore";
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Executes a Firestore transaction
|
|
6
6
|
*
|
|
7
|
-
* @
|
|
8
|
-
*
|
|
9
|
-
* @
|
|
7
|
+
* @group Hook
|
|
8
|
+
*
|
|
9
|
+
* @param {UseRunTransactionOptions<T>} options - Configuration options for the mutation.
|
|
10
|
+
*
|
|
11
|
+
* @returns {UseMutationResult<T, Error>} An object representing mutation
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```jsx
|
|
15
|
+
* export const MyComponent = () => {
|
|
16
|
+
* const doc = useGetDocData({
|
|
17
|
+
* options: {
|
|
18
|
+
* queryKey: ['key']
|
|
19
|
+
* },
|
|
20
|
+
* reference: collection(),
|
|
21
|
+
* path: 'id'
|
|
22
|
+
* });
|
|
23
|
+
* console.log(doc);
|
|
24
|
+
* };
|
|
25
|
+
* ```
|
|
10
26
|
*/
|
|
11
27
|
export const useRunTransaction = ({ options = {} }) => {
|
|
12
28
|
const db = useFirestore();
|
|
@@ -1,36 +1,55 @@
|
|
|
1
1
|
import { useMutation, UseMutationOptions } from "@tanstack/react-query";
|
|
2
2
|
import { runTransaction, FirebaseFirestoreTypes } from "@react-native-firebase/firestore";
|
|
3
3
|
|
|
4
|
-
import { ReactNativeFirebase } from "@react-native-firebase/app";
|
|
5
4
|
import { useFirestore } from "./useFirestore";
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
/**
|
|
7
|
+
* @inline
|
|
8
|
+
*/
|
|
9
|
+
export type UseRunTransactionValues = <T = unknown>(transaction: FirebaseFirestoreTypes.Transaction) => T;
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
/**
|
|
12
|
+
* @inline
|
|
13
|
+
*/
|
|
14
|
+
export type UseRunTransactionOptions<T = unknown, TContext = unknown> = {
|
|
15
|
+
/**
|
|
16
|
+
* Reqct-mutation options that shall omit mutationFn
|
|
17
|
+
*/
|
|
18
|
+
options?: Omit<UseMutationOptions<T, Error, UseRunTransactionValues, TContext>, "mutationFn">;
|
|
16
19
|
};
|
|
17
20
|
|
|
18
21
|
/**
|
|
19
|
-
*
|
|
22
|
+
* Executes a Firestore transaction
|
|
23
|
+
*
|
|
24
|
+
* @group Hook
|
|
25
|
+
*
|
|
26
|
+
* @param {UseRunTransactionOptions<T>} options - Configuration options for the mutation.
|
|
27
|
+
*
|
|
28
|
+
* @returns {UseMutationResult<T, Error>} An object representing mutation
|
|
20
29
|
*
|
|
21
|
-
* @
|
|
22
|
-
*
|
|
23
|
-
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```jsx
|
|
32
|
+
* export const MyComponent = () => {
|
|
33
|
+
* const doc = useGetDocData({
|
|
34
|
+
* options: {
|
|
35
|
+
* queryKey: ['key']
|
|
36
|
+
* },
|
|
37
|
+
* reference: collection(),
|
|
38
|
+
* path: 'id'
|
|
39
|
+
* });
|
|
40
|
+
* console.log(doc);
|
|
41
|
+
* };
|
|
42
|
+
* ```
|
|
24
43
|
*/
|
|
25
|
-
export const useRunTransaction = <
|
|
44
|
+
export const useRunTransaction = <T = unknown, TContext = unknown>({
|
|
26
45
|
options = {}
|
|
27
|
-
}: UseRunTransactionOptions<
|
|
46
|
+
}: UseRunTransactionOptions<T, TContext>) => {
|
|
28
47
|
const db = useFirestore();
|
|
29
48
|
|
|
30
49
|
return useMutation({
|
|
31
50
|
...options,
|
|
32
51
|
mutationFn: async (transactionFn) => {
|
|
33
|
-
return runTransaction<
|
|
52
|
+
return runTransaction<T>(db, transactionFn);
|
|
34
53
|
}
|
|
35
54
|
});
|
|
36
55
|
};
|