react-query-firebase 2.0.2 → 2.1.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 +2 -2
- package/react-native/firestore/index.ts +1 -0
- package/react-native/firestore/useCompositeFilter.ts +4 -4
- package/react-native/firestore/useQueryConstraints.ts +84 -0
- package/react-native/index.d.ts +0 -4
- package/react-native/index.js +0 -4
- package/react-native/index.ts +0 -4
- package/web/firestore/index.ts +1 -0
- package/web/firestore/useCompositeFilter.ts +4 -4
- package/web/firestore/useQueryConstraints.ts +93 -0
- package/web/index.d.ts +0 -4
- package/web/index.js +0 -4
- package/web/index.ts +0 -4
- package/react-native/analytics/index.d.ts +0 -3
- package/react-native/analytics/index.js +0 -3
- package/react-native/analytics/useAnalytics.d.ts +0 -5
- package/react-native/analytics/useAnalytics.js +0 -10
- package/react-native/analytics/useLogEvent.d.ts +0 -17
- package/react-native/analytics/useLogEvent.js +0 -21
- package/react-native/analytics/useSetAnalyticsCollectionEnabled.d.ts +0 -10
- package/react-native/analytics/useSetAnalyticsCollectionEnabled.js +0 -16
- package/react-native/auth/index.d.ts +0 -12
- package/react-native/auth/index.js +0 -12
- package/react-native/auth/mutation-keys.d.ts +0 -7
- package/react-native/auth/mutation-keys.js +0 -19
- package/react-native/auth/useAuth.d.ts +0 -5
- package/react-native/auth/useAuth.js +0 -10
- package/react-native/auth/useCreateUserWitEmailAndPasswordMutation.d.ts +0 -15
- package/react-native/auth/useCreateUserWitEmailAndPasswordMutation.js +0 -19
- package/react-native/auth/useCurrentUser.d.ts +0 -6
- package/react-native/auth/useCurrentUser.js +0 -20
- package/react-native/auth/useIdToken.d.ts +0 -30
- package/react-native/auth/useIdToken.js +0 -66
- package/react-native/auth/useReauthenticateWitCredentialMutation.d.ts +0 -16
- package/react-native/auth/useReauthenticateWitCredentialMutation.js +0 -18
- package/react-native/auth/useReauthenticateWitRedirectMutation.d.ts +0 -17
- package/react-native/auth/useReauthenticateWitRedirectMutation.js +0 -18
- package/react-native/auth/useSendEmailVerificationMutation.d.ts +0 -13
- package/react-native/auth/useSendEmailVerificationMutation.js +0 -16
- package/react-native/auth/useSignInWitEmailAndPasswordMutation.d.ts +0 -15
- package/react-native/auth/useSignInWitEmailAndPasswordMutation.js +0 -19
- package/react-native/auth/useSignInWitRedirectMutation.d.ts +0 -14
- package/react-native/auth/useSignInWitRedirectMutation.js +0 -18
- package/react-native/auth/useSignOutMutation.d.ts +0 -10
- package/react-native/auth/useSignOutMutation.js +0 -19
- package/react-native/auth/useUpdateProfileMutation.d.ts +0 -15
- package/react-native/auth/useUpdateProfileMutation.js +0 -17
- package/react-native/firestore/index.d.ts +0 -16
- package/react-native/firestore/index.js +0 -16
- package/react-native/firestore/useAddDocMutation.d.ts +0 -21
- package/react-native/firestore/useAddDocMutation.js +0 -25
- package/react-native/firestore/useBatchWrite.d.ts +0 -15
- package/react-native/firestore/useBatchWrite.js +0 -21
- package/react-native/firestore/useCollectionReference.d.ts +0 -18
- package/react-native/firestore/useCollectionReference.js +0 -22
- package/react-native/firestore/useCompositeFilter.d.ts +0 -32
- package/react-native/firestore/useCompositeFilter.js +0 -42
- package/react-native/firestore/useCountQuery.d.ts +0 -23
- package/react-native/firestore/useCountQuery.js +0 -30
- package/react-native/firestore/useDeleteDocMutation.d.ts +0 -18
- package/react-native/firestore/useDeleteDocMutation.js +0 -23
- package/react-native/firestore/useDocReference.d.ts +0 -19
- package/react-native/firestore/useDocReference.js +0 -36
- package/react-native/firestore/useDocReferences.d.ts +0 -23
- package/react-native/firestore/useDocReferences.js +0 -29
- package/react-native/firestore/useFirestore.d.ts +0 -7
- package/react-native/firestore/useFirestore.js +0 -12
- package/react-native/firestore/useGetDocData.d.ts +0 -18
- package/react-native/firestore/useGetDocData.js +0 -18
- package/react-native/firestore/useGetRealtimeDocData.d.ts +0 -57
- package/react-native/firestore/useGetRealtimeDocData.js +0 -56
- package/react-native/firestore/useInfiniteQuery.d.ts +0 -17
- package/react-native/firestore/useInfiniteQuery.js +0 -28
- package/react-native/firestore/useQuery.d.ts +0 -24
- package/react-native/firestore/useQuery.js +0 -34
- package/react-native/firestore/useRunTransaction.d.ts +0 -15
- package/react-native/firestore/useRunTransaction.js +0 -19
- package/react-native/firestore/useSetDocMutation.d.ts +0 -20
- package/react-native/firestore/useSetDocMutation.js +0 -25
- package/react-native/firestore/useUpdateDocMutation.d.ts +0 -30
- package/react-native/firestore/useUpdateDocMutation.js +0 -37
- package/react-native/firestore/utils/getDocData.d.ts +0 -18
- package/react-native/firestore/utils/getDocData.js +0 -22
- package/react-native/firestore/utils/getDocRef.d.ts +0 -19
- package/react-native/firestore/utils/getDocRef.js +0 -21
- package/react-native/firestore/utils/getDocSnap.d.ts +0 -20
- package/react-native/firestore/utils/getDocSnap.js +0 -25
- package/react-native/remoteConfig/index.d.ts +0 -3
- package/react-native/remoteConfig/index.js +0 -3
- package/react-native/remoteConfig/useFetchAndActivate.d.ts +0 -11
- package/react-native/remoteConfig/useFetchAndActivate.js +0 -31
- package/react-native/remoteConfig/useGetValue.d.ts +0 -7
- package/react-native/remoteConfig/useGetValue.js +0 -15
- package/react-native/remoteConfig/useRemoteConfig.d.ts +0 -5
- package/react-native/remoteConfig/useRemoteConfig.js +0 -10
- package/web/analytics/index.d.ts +0 -3
- package/web/analytics/index.js +0 -3
- package/web/analytics/useAnalytics.d.ts +0 -5
- package/web/analytics/useAnalytics.js +0 -10
- package/web/analytics/useLogEvent.d.ts +0 -17
- package/web/analytics/useLogEvent.js +0 -21
- package/web/analytics/useSetAnalyticsCollectionEnabled.d.ts +0 -10
- package/web/analytics/useSetAnalyticsCollectionEnabled.js +0 -16
- package/web/auth/index.d.ts +0 -13
- package/web/auth/index.js +0 -13
- package/web/auth/mutation-keys.d.ts +0 -7
- package/web/auth/mutation-keys.js +0 -19
- package/web/auth/useAuth.d.ts +0 -5
- package/web/auth/useAuth.js +0 -10
- package/web/auth/useAuthStateReady.d.ts +0 -6
- package/web/auth/useAuthStateReady.js +0 -19
- package/web/auth/useCreateUserWitEmailAndPasswordMutation.d.ts +0 -15
- package/web/auth/useCreateUserWitEmailAndPasswordMutation.js +0 -19
- package/web/auth/useCurrentUser.d.ts +0 -6
- package/web/auth/useCurrentUser.js +0 -20
- package/web/auth/useIdToken.d.ts +0 -30
- package/web/auth/useIdToken.js +0 -66
- package/web/auth/useReauthenticateWitCredentialMutation.d.ts +0 -16
- package/web/auth/useReauthenticateWitCredentialMutation.js +0 -18
- package/web/auth/useReauthenticateWitRedirectMutation.d.ts +0 -17
- package/web/auth/useReauthenticateWitRedirectMutation.js +0 -18
- package/web/auth/useSendEmailVerificationMutation.d.ts +0 -13
- package/web/auth/useSendEmailVerificationMutation.js +0 -16
- package/web/auth/useSignInWitEmailAndPasswordMutation.d.ts +0 -15
- package/web/auth/useSignInWitEmailAndPasswordMutation.js +0 -19
- package/web/auth/useSignInWitRedirectMutation.d.ts +0 -14
- package/web/auth/useSignInWitRedirectMutation.js +0 -18
- package/web/auth/useSignOutMutation.d.ts +0 -10
- package/web/auth/useSignOutMutation.js +0 -19
- package/web/auth/useUpdateProfileMutation.d.ts +0 -15
- package/web/auth/useUpdateProfileMutation.js +0 -17
- package/web/firestore/index.d.ts +0 -16
- package/web/firestore/index.js +0 -16
- package/web/firestore/useAddDocMutation.d.ts +0 -23
- package/web/firestore/useAddDocMutation.js +0 -26
- package/web/firestore/useBatchWrite.d.ts +0 -15
- package/web/firestore/useBatchWrite.js +0 -21
- package/web/firestore/useCollectionReference.d.ts +0 -18
- package/web/firestore/useCollectionReference.js +0 -24
- package/web/firestore/useCompositeFilter.d.ts +0 -32
- package/web/firestore/useCompositeFilter.js +0 -41
- package/web/firestore/useCountQuery.d.ts +0 -23
- package/web/firestore/useCountQuery.js +0 -30
- package/web/firestore/useDeleteDocMutation.d.ts +0 -18
- package/web/firestore/useDeleteDocMutation.js +0 -23
- package/web/firestore/useDocReference.d.ts +0 -19
- package/web/firestore/useDocReference.js +0 -45
- package/web/firestore/useDocReferences.d.ts +0 -23
- package/web/firestore/useDocReferences.js +0 -31
- package/web/firestore/useFirestore.d.ts +0 -7
- package/web/firestore/useFirestore.js +0 -12
- package/web/firestore/useGetDocData.d.ts +0 -18
- package/web/firestore/useGetDocData.js +0 -18
- package/web/firestore/useGetRealtimeDocData.d.ts +0 -57
- package/web/firestore/useGetRealtimeDocData.js +0 -56
- package/web/firestore/useInfiniteQuery.d.ts +0 -18
- package/web/firestore/useInfiniteQuery.js +0 -28
- package/web/firestore/useQuery.d.ts +0 -25
- package/web/firestore/useQuery.js +0 -34
- package/web/firestore/useRunTransaction.d.ts +0 -15
- package/web/firestore/useRunTransaction.js +0 -19
- package/web/firestore/useSetDocMutation.d.ts +0 -20
- package/web/firestore/useSetDocMutation.js +0 -25
- package/web/firestore/useUpdateDocMutation.d.ts +0 -31
- package/web/firestore/useUpdateDocMutation.js +0 -37
- package/web/firestore/utils/getDocData.d.ts +0 -18
- package/web/firestore/utils/getDocData.js +0 -22
- package/web/firestore/utils/getDocRef.d.ts +0 -19
- package/web/firestore/utils/getDocRef.js +0 -25
- package/web/firestore/utils/getDocSnap.d.ts +0 -20
- package/web/firestore/utils/getDocSnap.js +0 -25
- package/web/remoteConfig/index.d.ts +0 -3
- package/web/remoteConfig/index.js +0 -3
- package/web/remoteConfig/useFetchAndActivate.d.ts +0 -11
- package/web/remoteConfig/useFetchAndActivate.js +0 -31
- package/web/remoteConfig/useGetValue.d.ts +0 -7
- package/web/remoteConfig/useGetValue.js +0 -15
- package/web/remoteConfig/useRemoteConfig.d.ts +0 -5
- package/web/remoteConfig/useRemoteConfig.js +0 -10
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { FirebaseFirestoreTypes } from "@react-native-firebase/firestore";
|
|
2
|
-
export type UseDocReferenceOptions<AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData> = {
|
|
3
|
-
reference?: FirebaseFirestoreTypes.CollectionReference<AppModelType> | FirebaseFirestoreTypes.DocumentReference<AppModelType>;
|
|
4
|
-
path?: string;
|
|
5
|
-
pathSegments?: string[];
|
|
6
|
-
};
|
|
7
|
-
/**
|
|
8
|
-
* Custom hook to generate and manage a Firestore document reference.
|
|
9
|
-
* This hook facilitates the retrieval of a Firestore document reference based on given options such as path and reference data.
|
|
10
|
-
* The reference is updated whenever the associated path, reference, or path segments change.
|
|
11
|
-
*
|
|
12
|
-
* @param {UseDocReferenceOptions<AppModelType>} options - Configuration options for setting up the document reference.
|
|
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.
|
|
16
|
-
*
|
|
17
|
-
* @returns {FirebaseFirestoreTypes.DocumentReference<AppModelType> | null} The Firestore document reference corresponding to the provided path and options, or null if not initialized.
|
|
18
|
-
*/
|
|
19
|
-
export declare const useDocReference: <AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData>({ path, reference, pathSegments }: UseDocReferenceOptions<AppModelType>) => FirebaseFirestoreTypes.DocumentReference<AppModelType>;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { doc } from "@react-native-firebase/firestore";
|
|
2
|
-
import { useMemo } from "react";
|
|
3
|
-
import { useFirestore } from "./useFirestore";
|
|
4
|
-
/**
|
|
5
|
-
* Generates a document reference for a specified path or reference in Firestore.
|
|
6
|
-
* If a reference is not provided, it constructs a document reference using the Firestore instance, path, and path segments.
|
|
7
|
-
*
|
|
8
|
-
* @param {Firestore} db - The Firestore database instance used to create the document reference.
|
|
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.
|
|
13
|
-
*
|
|
14
|
-
* @returns {DocumentReference<AppModelType> | null} A Firestore document reference if the path is specified; otherwise, returns null if path is not provided.
|
|
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.
|
|
23
|
-
*
|
|
24
|
-
* @param {UseDocReferenceOptions<AppModelType>} options - Configuration options for setting up the document reference.
|
|
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.
|
|
28
|
-
*
|
|
29
|
-
* @returns {FirebaseFirestoreTypes.DocumentReference<AppModelType> | null} The Firestore document reference corresponding to the provided path and options, or null if not initialized.
|
|
30
|
-
*/
|
|
31
|
-
export const useDocReference = ({ path, reference, pathSegments }) => {
|
|
32
|
-
const db = useFirestore();
|
|
33
|
-
return useMemo(() => {
|
|
34
|
-
return getDocReference(db, { path, pathSegments, reference });
|
|
35
|
-
}, [db, reference, path, pathSegments]);
|
|
36
|
-
};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { FirebaseFirestoreTypes } from "@react-native-firebase/firestore";
|
|
2
|
-
export type UseDocReferencesOptions<AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData> = {
|
|
3
|
-
reference?: FirebaseFirestoreTypes.CollectionReference<AppModelType> | FirebaseFirestoreTypes.DocumentReference<AppModelType>;
|
|
4
|
-
path: string;
|
|
5
|
-
pathSegments?: string[];
|
|
6
|
-
};
|
|
7
|
-
/**
|
|
8
|
-
* A custom hook to generate document references for Firebase Firestore documents using given
|
|
9
|
-
* reference options.
|
|
10
|
-
*
|
|
11
|
-
* The hook accepts an array of options, where each option may contain a path,
|
|
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
|
-
*
|
|
17
|
-
* @param {UseDocReferencesOptions<AppModelType>[]} references - An array of options
|
|
18
|
-
* specifying how to generate document references. Each option may include a `path`
|
|
19
|
-
* as a string, a `reference` as a Firestore reference, and `pathSegments` as an array of strings.
|
|
20
|
-
* @returns {DocumentReference<AppModelType>[]} An array of Firestore document references
|
|
21
|
-
* generated from the options provided.
|
|
22
|
-
*/
|
|
23
|
-
export declare const useDocReferences: <AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData>(references: UseDocReferencesOptions<AppModelType>[]) => FirebaseFirestoreTypes.DocumentReference<AppModelType>[];
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { doc } from "@react-native-firebase/firestore";
|
|
2
|
-
import { useMemo } from "react";
|
|
3
|
-
import { useFirestore } from "./useFirestore";
|
|
4
|
-
/**
|
|
5
|
-
* A custom hook to generate document references for Firebase Firestore documents using given
|
|
6
|
-
* reference options.
|
|
7
|
-
*
|
|
8
|
-
* The hook accepts an array of options, where each option may contain a path,
|
|
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.
|
|
13
|
-
*
|
|
14
|
-
* @param {UseDocReferencesOptions<AppModelType>[]} references - An array of options
|
|
15
|
-
* specifying how to generate document references. Each option may include a `path`
|
|
16
|
-
* as a string, a `reference` as a Firestore reference, and `pathSegments` as an array of strings.
|
|
17
|
-
* @returns {DocumentReference<AppModelType>[]} An array of Firestore document references
|
|
18
|
-
* generated from the options provided.
|
|
19
|
-
*/
|
|
20
|
-
export const useDocReferences = (references) => {
|
|
21
|
-
const db = useFirestore();
|
|
22
|
-
return useMemo(() => {
|
|
23
|
-
return references.map(({ path, reference, pathSegments }) => {
|
|
24
|
-
return (!reference
|
|
25
|
-
? doc(db, path || "", ...(pathSegments || []))
|
|
26
|
-
: doc(reference, path, ...(pathSegments || [])));
|
|
27
|
-
});
|
|
28
|
-
}, [references, db]);
|
|
29
|
-
};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Provides a hook to access the Firestore instance from the Firebase context.
|
|
3
|
-
* It extracts the Firestore object from the Firebase context, allowing components to interact with Firestore services.
|
|
4
|
-
*
|
|
5
|
-
* @returns {firestore.Firestore} The Firestore instance from the Firebase context.
|
|
6
|
-
*/
|
|
7
|
-
export declare const useFirestore: () => import("@react-native-firebase/firestore").FirebaseFirestoreTypes.Module;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { useContext } from "react";
|
|
2
|
-
import { FirebaseContext } from "../context/FirebaseContext";
|
|
3
|
-
/**
|
|
4
|
-
* Provides a hook to access the Firestore instance from the Firebase context.
|
|
5
|
-
* It extracts the Firestore object from the Firebase context, allowing components to interact with Firestore services.
|
|
6
|
-
*
|
|
7
|
-
* @returns {firestore.Firestore} The Firestore instance from the Firebase context.
|
|
8
|
-
*/
|
|
9
|
-
export const useFirestore = () => {
|
|
10
|
-
const { firestore } = useContext(FirebaseContext);
|
|
11
|
-
return firestore;
|
|
12
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { FirebaseFirestoreTypes } from "@react-native-firebase/firestore";
|
|
2
|
-
import { UseQueryOptions } from "@tanstack/react-query";
|
|
3
|
-
type UseGetDocOptions<AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData> = {
|
|
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
|
-
};
|
|
9
|
-
/**
|
|
10
|
-
* Custom React Hook to retrieve document data from Firestore using specified parameters.
|
|
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.
|
|
16
|
-
*/
|
|
17
|
-
export declare const useGetDocData: <AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData>({ options, reference, path, pathSegments }: UseGetDocOptions<AppModelType>) => import("@tanstack/react-query").UseQueryResult<AppModelType, Error>;
|
|
18
|
-
export {};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { useFirestore } from "./useFirestore";
|
|
2
|
-
import { getDocData } from "./utils/getDocData";
|
|
3
|
-
import { useQuery } from "@tanstack/react-query";
|
|
4
|
-
/**
|
|
5
|
-
* Custom React Hook to retrieve document data from Firestore using specified parameters.
|
|
6
|
-
* @param {Object} options - The options for configuring the Firestore query.
|
|
7
|
-
* @param {string} reference - The reference to the document in Firestore.
|
|
8
|
-
* @param {string} path - The path to the document in Firestore.
|
|
9
|
-
* @param {Array<string>} pathSegments - Segments of the path to document in Firestore.
|
|
10
|
-
* @returns {Object} Result of the query containing document data and query status.
|
|
11
|
-
*/
|
|
12
|
-
export const useGetDocData = ({ options, reference, path, pathSegments }) => {
|
|
13
|
-
const db = useFirestore();
|
|
14
|
-
return useQuery({
|
|
15
|
-
...options,
|
|
16
|
-
queryFn: () => getDocData({ db, reference, path, pathSegments })
|
|
17
|
-
});
|
|
18
|
-
};
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { FirebaseFirestoreTypes } from "@react-native-firebase/firestore";
|
|
2
|
-
import { ReactNativeFirebase } from "@react-native-firebase/app";
|
|
3
|
-
/**
|
|
4
|
-
* @inline
|
|
5
|
-
*/
|
|
6
|
-
export type UseGetRealtimeDocDataOptions<AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData> = {
|
|
7
|
-
/**
|
|
8
|
-
* A slash-separated path to a document. Has to be omitted to use
|
|
9
|
-
*/
|
|
10
|
-
path?: string;
|
|
11
|
-
/**
|
|
12
|
-
* A reference to a collection.
|
|
13
|
-
*/
|
|
14
|
-
reference?: FirebaseFirestoreTypes.CollectionReference<AppModelType> | FirebaseFirestoreTypes.DocumentReference<AppModelType>;
|
|
15
|
-
/**
|
|
16
|
-
* Additional path segments that will be applied relative
|
|
17
|
-
* to the first argument.
|
|
18
|
-
*/
|
|
19
|
-
pathSegments?: string[];
|
|
20
|
-
/**
|
|
21
|
-
* A callback to be called if the listen fails or is
|
|
22
|
-
* cancelled. No further callbacks will occur.
|
|
23
|
-
*/
|
|
24
|
-
onError?: (error: ReactNativeFirebase.NativeFirebaseError | Error) => unknown;
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* @inline
|
|
28
|
-
*/
|
|
29
|
-
export type UseGetRealtimeDocDataResult<AppModelType> = {
|
|
30
|
-
data: AppModelType | null;
|
|
31
|
-
isError: boolean;
|
|
32
|
-
error: ReactNativeFirebase.NativeFirebaseError | Error | null;
|
|
33
|
-
isFetching: boolean;
|
|
34
|
-
};
|
|
35
|
-
/**
|
|
36
|
-
* A hook to get realtime updates to a firestore document.
|
|
37
|
-
*
|
|
38
|
-
* @group Hook
|
|
39
|
-
*
|
|
40
|
-
* @param {UseGetRealtimeDocDataOptions<AppModelType, DbModelType>} options
|
|
41
|
-
*
|
|
42
|
-
* @returns {UseGetRealtimeDocDataResult<AppModelType>}
|
|
43
|
-
*
|
|
44
|
-
* @example
|
|
45
|
-
* ```jsx
|
|
46
|
-
* const firebaseConfig = {};
|
|
47
|
-
* export const MyComponent = () => {
|
|
48
|
-
* const result = useGetRealtimeDocData('collection/documentId');
|
|
49
|
-
* return (
|
|
50
|
-
* <div>
|
|
51
|
-
* {JSON.stringify(result)}
|
|
52
|
-
* </div>
|
|
53
|
-
* );
|
|
54
|
-
* };
|
|
55
|
-
* ```
|
|
56
|
-
*/
|
|
57
|
-
export declare const useGetRealtimeDocData: <AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData>({ path, pathSegments, reference, onError }: UseGetRealtimeDocDataOptions<AppModelType>) => UseGetRealtimeDocDataResult<AppModelType>;
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { onSnapshot } from "@react-native-firebase/firestore";
|
|
2
|
-
import { useEffect, useMemo, useState } from "react";
|
|
3
|
-
import { useDocReference } from "./useDocReference";
|
|
4
|
-
/**
|
|
5
|
-
* A hook to get realtime updates to a firestore document.
|
|
6
|
-
*
|
|
7
|
-
* @group Hook
|
|
8
|
-
*
|
|
9
|
-
* @param {UseGetRealtimeDocDataOptions<AppModelType, DbModelType>} options
|
|
10
|
-
*
|
|
11
|
-
* @returns {UseGetRealtimeDocDataResult<AppModelType>}
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```jsx
|
|
15
|
-
* const firebaseConfig = {};
|
|
16
|
-
* export const MyComponent = () => {
|
|
17
|
-
* const result = useGetRealtimeDocData('collection/documentId');
|
|
18
|
-
* return (
|
|
19
|
-
* <div>
|
|
20
|
-
* {JSON.stringify(result)}
|
|
21
|
-
* </div>
|
|
22
|
-
* );
|
|
23
|
-
* };
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
export const useGetRealtimeDocData = ({ path, pathSegments, reference, onError }) => {
|
|
27
|
-
const ref = useDocReference({ path, reference, pathSegments });
|
|
28
|
-
const [doc, setDoc] = useState(null);
|
|
29
|
-
const [isError, setIsError] = useState(false);
|
|
30
|
-
const [isFetching, setIsFetching] = useState(true);
|
|
31
|
-
const [error, setError] = useState(null);
|
|
32
|
-
useEffect(() => {
|
|
33
|
-
const unsubscribe = ref
|
|
34
|
-
? onSnapshot(ref, {
|
|
35
|
-
next: async (snapshot) => {
|
|
36
|
-
setIsFetching(false);
|
|
37
|
-
setDoc(snapshot.data() || null);
|
|
38
|
-
setError(null);
|
|
39
|
-
setIsError(false);
|
|
40
|
-
},
|
|
41
|
-
error: (e) => {
|
|
42
|
-
setIsError(true);
|
|
43
|
-
setError(e);
|
|
44
|
-
onError?.(e);
|
|
45
|
-
}
|
|
46
|
-
})
|
|
47
|
-
: () => { };
|
|
48
|
-
return () => unsubscribe();
|
|
49
|
-
}, [ref, doc, isError, onError, isFetching, error]);
|
|
50
|
-
return useMemo(() => ({
|
|
51
|
-
data: doc,
|
|
52
|
-
isError,
|
|
53
|
-
isFetching,
|
|
54
|
-
error
|
|
55
|
-
}), [doc, isError, error, isFetching]);
|
|
56
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { FirebaseFirestoreTypes, QueryConstraint, QueryNonFilterConstraint } from "@react-native-firebase/firestore";
|
|
2
|
-
import { UseInfiniteQueryOptions as UseReactInfiniteQueryOptions, QueryKey, UseInfiniteQueryResult, InfiniteData } from "@tanstack/react-query";
|
|
3
|
-
type UseInfiniteQueryOptions<AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown> = {
|
|
4
|
-
options: Omit<UseReactInfiniteQueryOptions<AppModelType[], Error, InfiniteData<AppModelType[]>, AppModelType[], TQueryKey, TPageParam>, "queryFn"> & Required<Pick<UseReactInfiniteQueryOptions<AppModelType[], Error, InfiniteData<AppModelType[]>, AppModelType[], TQueryKey, TPageParam>, "queryKey">>;
|
|
5
|
-
collectionReference: FirebaseFirestoreTypes.CollectionReference<AppModelType>;
|
|
6
|
-
queryConstraints?: QueryConstraint[] | QueryNonFilterConstraint[];
|
|
7
|
-
compositeFilter?: FirebaseFirestoreTypes.QueryCompositeFilterConstraint;
|
|
8
|
-
};
|
|
9
|
-
/**
|
|
10
|
-
* Custom hook that creates an infinite query using Firestore, allowing for query constraints, composite filters, and converters.
|
|
11
|
-
* It fetches data in pages and can load more as required.
|
|
12
|
-
*
|
|
13
|
-
* @param {UseInfiniteQueryOptions<AppModelType, DbModelType>} options - Configuration options for the infinite query, including Firestore query reference, query constraints, composite filter, and data converter.
|
|
14
|
-
* @returns {UseInfiniteQueryResult<InfiniteData<AppModelType[]>>} Result object containing the infinite data and methods for fetching more pages.
|
|
15
|
-
*/
|
|
16
|
-
export declare const useInfiniteQuery: <AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData>({ options, collectionReference, queryConstraints, compositeFilter }: UseInfiniteQueryOptions<AppModelType>) => UseInfiniteQueryResult<InfiniteData<AppModelType[]>>;
|
|
17
|
-
export {};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { getDocs, query } from "@react-native-firebase/firestore";
|
|
2
|
-
import { useInfiniteQuery as useInfiniteReactQuery } from "@tanstack/react-query";
|
|
3
|
-
/**
|
|
4
|
-
* Custom hook that creates an infinite query using Firestore, allowing for query constraints, composite filters, and converters.
|
|
5
|
-
* It fetches data in pages and can load more as required.
|
|
6
|
-
*
|
|
7
|
-
* @param {UseInfiniteQueryOptions<AppModelType, DbModelType>} options - Configuration options for the infinite query, including Firestore query reference, query constraints, composite filter, and data converter.
|
|
8
|
-
* @returns {UseInfiniteQueryResult<InfiniteData<AppModelType[]>>} Result object containing the infinite data and methods for fetching more pages.
|
|
9
|
-
*/
|
|
10
|
-
export const useInfiniteQuery = ({ options, collectionReference, queryConstraints = [], compositeFilter }) => {
|
|
11
|
-
return useInfiniteReactQuery({
|
|
12
|
-
...options,
|
|
13
|
-
queryFn: async ({ pageParam }) => {
|
|
14
|
-
const allQueryConstraints = [...queryConstraints, ...(pageParam ? [pageParam] : [])];
|
|
15
|
-
const queryToExecute = compositeFilter
|
|
16
|
-
? query(collectionReference, compositeFilter, ...allQueryConstraints)
|
|
17
|
-
: query(collectionReference, ...allQueryConstraints);
|
|
18
|
-
const querySnapshot = await getDocs(queryToExecute);
|
|
19
|
-
const docs = [];
|
|
20
|
-
if (querySnapshot) {
|
|
21
|
-
querySnapshot.forEach((doc) => {
|
|
22
|
-
docs.push(doc.data());
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
return docs;
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { FirebaseFirestoreTypes, QueryConstraint, QueryNonFilterConstraint } from "@react-native-firebase/firestore";
|
|
2
|
-
import { UseQueryResult, UseQueryOptions as UseReactQueryOptions } from "@tanstack/react-query";
|
|
3
|
-
type UseQueryOptions<AppModelType extends FirebaseFirestoreTypes.DocumentData> = {
|
|
4
|
-
options: Omit<UseReactQueryOptions<AppModelType[], Error, AppModelType[]>, "queryFn"> & Required<Pick<UseReactQueryOptions<AppModelType[], Error, AppModelType[]>, "queryKey">>;
|
|
5
|
-
collectionReference: FirebaseFirestoreTypes.CollectionReference<AppModelType>;
|
|
6
|
-
queryConstraints?: QueryConstraint[] | QueryNonFilterConstraint[];
|
|
7
|
-
compositeFilter?: FirebaseFirestoreTypes.QueryCompositeFilterConstraint;
|
|
8
|
-
};
|
|
9
|
-
/**
|
|
10
|
-
* Executes a query on a Firestore-like data source and returns the resulting documents as an array.
|
|
11
|
-
*
|
|
12
|
-
* This hook utilizes an abstraction over React Query to asynchronously fetch data based on the provided query
|
|
13
|
-
* reference and constraints. It supports optional filtering, conversion, and additional query constraints.
|
|
14
|
-
*
|
|
15
|
-
* @param {UseQueryOptions<AppModelType>} options - Configuration options for the query.
|
|
16
|
-
* @param {FirebaseFirestoreTypes.DocumentReference<AppModelType>} collectionReference - The reference to the query to be executed.
|
|
17
|
-
* @param {QueryConstraint[]} queryConstraints - Additional constraints to fine-tune the query.
|
|
18
|
-
* @param {QueryConstraint} compositeFilter - Optional composite filter to apply to the query.
|
|
19
|
-
* @param {FirestoreDataConverter<AppModelType>} converter - Optional data converter for transforming snapshots.
|
|
20
|
-
*
|
|
21
|
-
* @returns {UseQueryResult<AppModelType[]>} Result containing an array of documents that match the query criteria.
|
|
22
|
-
*/
|
|
23
|
-
export declare const useQuery: <AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData>({ options, collectionReference, queryConstraints, compositeFilter }: UseQueryOptions<AppModelType>) => UseQueryResult<AppModelType[]>;
|
|
24
|
-
export {};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { getDocs, query } from "@react-native-firebase/firestore";
|
|
2
|
-
import { useQuery as useReactQuery } from "@tanstack/react-query";
|
|
3
|
-
/**
|
|
4
|
-
* Executes a query on a Firestore-like data source and returns the resulting documents as an array.
|
|
5
|
-
*
|
|
6
|
-
* This hook utilizes an abstraction over React Query to asynchronously fetch data based on the provided query
|
|
7
|
-
* reference and constraints. It supports optional filtering, conversion, and additional query constraints.
|
|
8
|
-
*
|
|
9
|
-
* @param {UseQueryOptions<AppModelType>} options - Configuration options for the query.
|
|
10
|
-
* @param {FirebaseFirestoreTypes.DocumentReference<AppModelType>} collectionReference - The reference to the query to be executed.
|
|
11
|
-
* @param {QueryConstraint[]} queryConstraints - Additional constraints to fine-tune the query.
|
|
12
|
-
* @param {QueryConstraint} compositeFilter - Optional composite filter to apply to the query.
|
|
13
|
-
* @param {FirestoreDataConverter<AppModelType>} converter - Optional data converter for transforming snapshots.
|
|
14
|
-
*
|
|
15
|
-
* @returns {UseQueryResult<AppModelType[]>} Result containing an array of documents that match the query criteria.
|
|
16
|
-
*/
|
|
17
|
-
export const useQuery = ({ options, collectionReference, queryConstraints = [], compositeFilter }) => {
|
|
18
|
-
return useReactQuery({
|
|
19
|
-
...options,
|
|
20
|
-
queryFn: async () => {
|
|
21
|
-
const queryToExecute = compositeFilter
|
|
22
|
-
? query(collectionReference, compositeFilter, ...queryConstraints)
|
|
23
|
-
: query(collectionReference, ...queryConstraints);
|
|
24
|
-
const querySnapshot = await getDocs(queryToExecute);
|
|
25
|
-
const docs = [];
|
|
26
|
-
if (querySnapshot) {
|
|
27
|
-
querySnapshot.forEach((doc) => {
|
|
28
|
-
docs.push(doc.data());
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
return docs;
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { UseMutationOptions } from "@tanstack/react-query";
|
|
2
|
-
import { FirebaseFirestoreTypes } from "@react-native-firebase/firestore";
|
|
3
|
-
import { ReactNativeFirebase } from "@react-native-firebase/app";
|
|
4
|
-
export type UseRunTransactionValues = <AppModelType = unknown>(transaction: FirebaseFirestoreTypes.Transaction) => AppModelType;
|
|
5
|
-
export type UseRunTransactionOptions<AppModelType = unknown, TContext = unknown> = {
|
|
6
|
-
options?: Omit<UseMutationOptions<AppModelType, ReactNativeFirebase.NativeFirebaseError, UseRunTransactionValues, TContext>, "mutationFn">;
|
|
7
|
-
};
|
|
8
|
-
/**
|
|
9
|
-
* Custom hook to execute a Firestore transaction using the useMutation hook.
|
|
10
|
-
*
|
|
11
|
-
* @param {UseRunTransactionOptions<AppModelType, TContext>} options - Configuration options for running the transaction.
|
|
12
|
-
* @param {Object} options.options - Options to customize the behavior of useMutation and runTransaction.
|
|
13
|
-
* @returns {UseMutationResult} The result object from the useMutation hook, allowing to track the transaction state and outcome.
|
|
14
|
-
*/
|
|
15
|
-
export declare const useRunTransaction: <AppModelType = unknown, TContext = unknown>({ options }: UseRunTransactionOptions<AppModelType, TContext>) => import("@tanstack/react-query").UseMutationResult<AppModelType, ReactNativeFirebase.NativeFirebaseError, UseRunTransactionValues, TContext>;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { useMutation } from "@tanstack/react-query";
|
|
2
|
-
import { runTransaction } from "@react-native-firebase/firestore";
|
|
3
|
-
import { useFirestore } from "./useFirestore";
|
|
4
|
-
/**
|
|
5
|
-
* Custom hook to execute a Firestore transaction using the useMutation hook.
|
|
6
|
-
*
|
|
7
|
-
* @param {UseRunTransactionOptions<AppModelType, TContext>} options - Configuration options for running the transaction.
|
|
8
|
-
* @param {Object} options.options - Options to customize the behavior of useMutation and runTransaction.
|
|
9
|
-
* @returns {UseMutationResult} The result object from the useMutation hook, allowing to track the transaction state and outcome.
|
|
10
|
-
*/
|
|
11
|
-
export const useRunTransaction = ({ options = {} }) => {
|
|
12
|
-
const db = useFirestore();
|
|
13
|
-
return useMutation({
|
|
14
|
-
...options,
|
|
15
|
-
mutationFn: async (transactionFn) => {
|
|
16
|
-
return runTransaction(db, transactionFn);
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { UseMutationOptions } from "@tanstack/react-query";
|
|
2
|
-
import { FirebaseFirestoreTypes, WithFieldValue } from "@react-native-firebase/firestore";
|
|
3
|
-
import { ReactNativeFirebase } from "@react-native-firebase/app";
|
|
4
|
-
export type UseSetDocMutationValues<AppModelType> = {
|
|
5
|
-
data: WithFieldValue<AppModelType>;
|
|
6
|
-
};
|
|
7
|
-
export type UseSetDocMutationOptions<AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData, TContext = unknown> = {
|
|
8
|
-
reference: FirebaseFirestoreTypes.DocumentReference<AppModelType> | null;
|
|
9
|
-
options?: Omit<UseMutationOptions<void, ReactNativeFirebase.NativeFirebaseError, UseSetDocMutationValues<AppModelType>, TContext>, "mutationFn" | "mutationKey">;
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* Custom hook to create a mutation for setting a document in a Firestore-like database.
|
|
13
|
-
* The mutation can be configured with options and reference to specific document path.
|
|
14
|
-
*
|
|
15
|
-
* @param {UseSetDocMutationOptions<AppModelType, TContext>} param0 - The options for configuring the mutation, including the document reference and additional mutation options.
|
|
16
|
-
* @param {Object} param0.reference - The reference object that contains the path to the document.
|
|
17
|
-
* @param {Object} param0.options - Additional options for the mutation, can configure aspects like onSuccess or onError callbacks.
|
|
18
|
-
* @returns {MutationResult} The result of the mutation operation, which includes states like isLoading, isSuccess, isError, and methods to control the mutation process.
|
|
19
|
-
*/
|
|
20
|
-
export declare const useSetDocMutation: <AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData, TContext = unknown>({ reference, options }: UseSetDocMutationOptions<AppModelType, TContext>) => import("@tanstack/react-query").UseMutationResult<void, ReactNativeFirebase.NativeFirebaseError, UseSetDocMutationValues<AppModelType>, TContext>;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { useMutation } from "@tanstack/react-query";
|
|
2
|
-
import { setDoc } from "@react-native-firebase/firestore";
|
|
3
|
-
import { useMemo } from "react";
|
|
4
|
-
/**
|
|
5
|
-
* Custom hook to create a mutation for setting a document in a Firestore-like database.
|
|
6
|
-
* The mutation can be configured with options and reference to specific document path.
|
|
7
|
-
*
|
|
8
|
-
* @param {UseSetDocMutationOptions<AppModelType, TContext>} param0 - The options for configuring the mutation, including the document reference and additional mutation options.
|
|
9
|
-
* @param {Object} param0.reference - The reference object that contains the path to the document.
|
|
10
|
-
* @param {Object} param0.options - Additional options for the mutation, can configure aspects like onSuccess or onError callbacks.
|
|
11
|
-
* @returns {MutationResult} The result of the mutation operation, which includes states like isLoading, isSuccess, isError, and methods to control the mutation process.
|
|
12
|
-
*/
|
|
13
|
-
export const useSetDocMutation = ({ reference, options }) => {
|
|
14
|
-
const mutationKey = useMemo(() => [reference?.path], [reference?.path]);
|
|
15
|
-
return useMutation({
|
|
16
|
-
...options,
|
|
17
|
-
mutationFn: ({ data }) => {
|
|
18
|
-
if (!reference) {
|
|
19
|
-
throw new Error("Reference is undefined");
|
|
20
|
-
}
|
|
21
|
-
return setDoc(reference, data);
|
|
22
|
-
},
|
|
23
|
-
mutationKey
|
|
24
|
-
});
|
|
25
|
-
};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { UseMutationOptions } from "@tanstack/react-query";
|
|
2
|
-
import { FirebaseFirestoreTypes, UpdateData } from "@react-native-firebase/firestore";
|
|
3
|
-
import { ReactNativeFirebase } from "@react-native-firebase/app";
|
|
4
|
-
export type UseUpdateDocMutationValues<DbModelType> = {
|
|
5
|
-
data: UpdateData<DbModelType>;
|
|
6
|
-
};
|
|
7
|
-
export type UseUpdateDocMutationOptions<AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData, TContext = unknown> = {
|
|
8
|
-
reference: FirebaseFirestoreTypes.DocumentReference<AppModelType> | null;
|
|
9
|
-
options?: Omit<UseMutationOptions<AppModelType, ReactNativeFirebase.NativeFirebaseError, UseUpdateDocMutationValues<AppModelType>, TContext>, "mutationFn" | "mutationKey">;
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* Custom hook that sets up a mutation for updating a document in a Firestore database.
|
|
13
|
-
*
|
|
14
|
-
* This hook utilizes `useMutation` for performing asynchronous operations to update the document
|
|
15
|
-
* and retrieve the latest data snapshot. The update functionality can be configured with a custom
|
|
16
|
-
* converter if needed.
|
|
17
|
-
*
|
|
18
|
-
* @param {UseUpdateDocMutationOptions<AppModelType, TContext>} options - Configuration options for the mutation,
|
|
19
|
-
* including Firestore reference, an optional Firestore data converter, and additional mutation options.
|
|
20
|
-
*
|
|
21
|
-
* `reference` - The Firestore document reference that identifies the document to be updated.
|
|
22
|
-
*
|
|
23
|
-
* `converter` - An optional Firestore converter for transforming the database response into a custom type.
|
|
24
|
-
*
|
|
25
|
-
* `options` - Additional options that customize the mutation's behavior.
|
|
26
|
-
*
|
|
27
|
-
* @returns {UseMutationResult<AppModelType, Error, {data: AppModelType}, TContext>} An object returned by `useMutation`
|
|
28
|
-
* which includes functions to start the mutation and properties that represent the different states of the mutation.
|
|
29
|
-
*/
|
|
30
|
-
export declare const useUpdateDocMutation: <AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData, TContext = unknown>({ reference, options }: UseUpdateDocMutationOptions<AppModelType, TContext>) => import("@tanstack/react-query").UseMutationResult<AppModelType, ReactNativeFirebase.NativeFirebaseError, UseUpdateDocMutationValues<AppModelType>, TContext>;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { useMutation } from "@tanstack/react-query";
|
|
2
|
-
import { updateDoc, getDoc } from "@react-native-firebase/firestore";
|
|
3
|
-
import { useMemo } from "react";
|
|
4
|
-
/**
|
|
5
|
-
* Custom hook that sets up a mutation for updating a document in a Firestore database.
|
|
6
|
-
*
|
|
7
|
-
* This hook utilizes `useMutation` for performing asynchronous operations to update the document
|
|
8
|
-
* and retrieve the latest data snapshot. The update functionality can be configured with a custom
|
|
9
|
-
* converter if needed.
|
|
10
|
-
*
|
|
11
|
-
* @param {UseUpdateDocMutationOptions<AppModelType, TContext>} options - Configuration options for the mutation,
|
|
12
|
-
* including Firestore reference, an optional Firestore data converter, and additional mutation options.
|
|
13
|
-
*
|
|
14
|
-
* `reference` - The Firestore document reference that identifies the document to be updated.
|
|
15
|
-
*
|
|
16
|
-
* `converter` - An optional Firestore converter for transforming the database response into a custom type.
|
|
17
|
-
*
|
|
18
|
-
* `options` - Additional options that customize the mutation's behavior.
|
|
19
|
-
*
|
|
20
|
-
* @returns {UseMutationResult<AppModelType, Error, {data: AppModelType}, TContext>} An object returned by `useMutation`
|
|
21
|
-
* which includes functions to start the mutation and properties that represent the different states of the mutation.
|
|
22
|
-
*/
|
|
23
|
-
export const useUpdateDocMutation = ({ reference, options = {} }) => {
|
|
24
|
-
const mutationKey = useMemo(() => [reference?.path], [reference?.path]);
|
|
25
|
-
return useMutation({
|
|
26
|
-
...options,
|
|
27
|
-
mutationFn: async ({ data }) => {
|
|
28
|
-
if (!reference) {
|
|
29
|
-
throw new Error("Reference is undefined");
|
|
30
|
-
}
|
|
31
|
-
await updateDoc(reference, data);
|
|
32
|
-
const docSnap = await getDoc(reference);
|
|
33
|
-
return docSnap.data();
|
|
34
|
-
},
|
|
35
|
-
mutationKey
|
|
36
|
-
});
|
|
37
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { FirebaseFirestoreTypes } from "@react-native-firebase/firestore";
|
|
2
|
-
import { GetDocSnapOptions } from "./getDocSnap";
|
|
3
|
-
export type GetDocDataOptions<AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData> = GetDocSnapOptions<AppModelType>;
|
|
4
|
-
/**
|
|
5
|
-
* Asynchronously retrieves document data from a specified database and reference.
|
|
6
|
-
* Utilizes the helper function `getDocSnap` to fetch the document snapshot and
|
|
7
|
-
* checks if the document exists before returning its data.
|
|
8
|
-
*
|
|
9
|
-
* @param {Object} options - The options for fetching document data.
|
|
10
|
-
* @param {FirebaseFirestore} options.db - The Firestore database instance.
|
|
11
|
-
* @param {DocumentReference=} options.reference - The document reference. This is an optional parameter.
|
|
12
|
-
* @param {string=} options.path - The path to the document in the database. This is an optional parameter.
|
|
13
|
-
* @param {Array<string>=} options.pathSegments - The path segments for the document's path. This is an optional parameter.
|
|
14
|
-
*
|
|
15
|
-
* @returns {Promise<AppModelType | null>} Returns a promise that resolves to the document data if it exists,
|
|
16
|
-
* or null if the document does not exist.
|
|
17
|
-
*/
|
|
18
|
-
export declare const getDocData: <AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData>({ db, reference, path, pathSegments }: GetDocDataOptions<AppModelType>) => Promise<AppModelType | null | undefined>;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { getDocSnap } from "./getDocSnap";
|
|
2
|
-
/**
|
|
3
|
-
* Asynchronously retrieves document data from a specified database and reference.
|
|
4
|
-
* Utilizes the helper function `getDocSnap` to fetch the document snapshot and
|
|
5
|
-
* checks if the document exists before returning its data.
|
|
6
|
-
*
|
|
7
|
-
* @param {Object} options - The options for fetching document data.
|
|
8
|
-
* @param {FirebaseFirestore} options.db - The Firestore database instance.
|
|
9
|
-
* @param {DocumentReference=} options.reference - The document reference. This is an optional parameter.
|
|
10
|
-
* @param {string=} options.path - The path to the document in the database. This is an optional parameter.
|
|
11
|
-
* @param {Array<string>=} options.pathSegments - The path segments for the document's path. This is an optional parameter.
|
|
12
|
-
*
|
|
13
|
-
* @returns {Promise<AppModelType | null>} Returns a promise that resolves to the document data if it exists,
|
|
14
|
-
* or null if the document does not exist.
|
|
15
|
-
*/
|
|
16
|
-
export const getDocData = async ({ db, reference, path, pathSegments }) => {
|
|
17
|
-
const docSnap = await getDocSnap({ db, reference, path, pathSegments });
|
|
18
|
-
if (docSnap && docSnap?.exists) {
|
|
19
|
-
return docSnap.data();
|
|
20
|
-
}
|
|
21
|
-
return null;
|
|
22
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { FirebaseFirestoreTypes } from "@react-native-firebase/firestore";
|
|
2
|
-
export type GetDocRefOptions<AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData> = {
|
|
3
|
-
db: FirebaseFirestoreTypes.Module;
|
|
4
|
-
reference?: FirebaseFirestoreTypes.CollectionReference<AppModelType> | FirebaseFirestoreTypes.DocumentReference<AppModelType>;
|
|
5
|
-
path?: string;
|
|
6
|
-
pathSegments?: string[];
|
|
7
|
-
};
|
|
8
|
-
/**
|
|
9
|
-
* Retrieves a document reference based on provided database options.
|
|
10
|
-
* Either `reference` or `path` must be provided, not both.
|
|
11
|
-
*
|
|
12
|
-
* @param {Object} options - The options for getting a document reference.
|
|
13
|
-
* @param {FirebaseFirestoreTypes.Module} options.db - The Firestore database instance.
|
|
14
|
-
* @param {FirebaseFirestoreTypes.DocumentReference | FirebaseFirestoreTypes.CollectionReference | null} [options.reference] - Reference to a document or collection.
|
|
15
|
-
* @param {string | null} [options.path] - Path to the document.
|
|
16
|
-
* @param {string[] | null} [options.pathSegments] - Additional path segments if any.
|
|
17
|
-
* @returns {FirebaseFirestoreTypes.DocumentReference<AppModelType>} The document reference.
|
|
18
|
-
*/
|
|
19
|
-
export declare const getDocRef: <AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData>({ db, reference, path, pathSegments }: GetDocRefOptions<AppModelType>) => Promise<FirebaseFirestoreTypes.DocumentReference<AppModelType>>;
|