react-query-firebase 1.0.2 → 1.0.4
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/README.md +27 -3
- package/dist/src/analytics/index.d.ts +1 -0
- package/dist/src/analytics/index.js +1 -0
- package/dist/src/analytics/useAnalytics.d.ts +5 -0
- package/dist/src/analytics/useAnalytics.js +10 -0
- package/dist/src/analytics/useLogEvent.d.ts +7 -0
- package/dist/src/analytics/useLogEvent.js +8 -1
- package/dist/src/auth/index.d.ts +2 -0
- package/dist/src/auth/index.js +2 -0
- package/dist/src/auth/useAuth.d.ts +5 -0
- package/dist/src/auth/useAuth.js +10 -0
- package/dist/src/auth/useAuthStateReady.d.ts +5 -0
- package/dist/src/auth/useAuthStateReady.js +6 -1
- package/dist/src/auth/useCreateUserWitEmailAndPasswordMutation.d.ts +7 -0
- package/dist/src/auth/useCreateUserWitEmailAndPasswordMutation.js +8 -1
- package/dist/src/auth/useCurrentUser.d.ts +5 -0
- package/dist/src/auth/useCurrentUser.js +6 -1
- package/dist/src/auth/useIdToken.d.ts +12 -0
- package/dist/src/auth/useIdToken.js +36 -0
- package/dist/src/auth/useReauthenticateWitCredentialMutation.d.ts +8 -0
- package/dist/src/auth/useReauthenticateWitCredentialMutation.js +8 -0
- package/dist/src/auth/useReauthenticateWitRedirectMutation.d.ts +8 -0
- package/dist/src/auth/useReauthenticateWitRedirectMutation.js +8 -0
- package/dist/src/auth/useSendEmailVerificationMutation.d.ts +6 -0
- package/dist/src/auth/useSendEmailVerificationMutation.js +6 -0
- package/dist/src/auth/useSignInWitEmailAndPasswordMutation.d.ts +7 -0
- package/dist/src/auth/useSignInWitEmailAndPasswordMutation.js +8 -1
- package/dist/src/auth/useSignInWitRedirectMutation.d.ts +6 -0
- package/dist/src/auth/useSignInWitRedirectMutation.js +7 -1
- package/dist/src/auth/useSignOutMutation.d.ts +7 -0
- package/dist/src/auth/useSignOutMutation.js +8 -1
- package/dist/src/auth/useUpdateProfileMutation.d.ts +7 -0
- package/dist/src/auth/useUpdateProfileMutation.js +7 -0
- package/dist/src/{FirebaseContext.d.ts → context/FirebaseContext.d.ts} +8 -2
- package/dist/src/context/FirebaseContext.js +8 -0
- package/dist/src/context/FirebaseContextProvider.d.ts +105 -0
- package/dist/src/{FirebaseContextProvider.js → context/FirebaseContextProvider.js} +24 -1
- package/dist/src/context/index.d.ts +1 -0
- package/dist/src/context/index.js +1 -0
- package/dist/src/firestore/index.d.ts +1 -0
- package/dist/src/firestore/index.js +1 -0
- package/dist/src/firestore/useAddDocMutation.d.ts +11 -0
- package/dist/src/firestore/useAddDocMutation.js +11 -0
- package/dist/src/firestore/useBatchWrite.d.ts +7 -0
- package/dist/src/firestore/useBatchWrite.js +8 -1
- package/dist/src/firestore/useCollectionReference.d.ts +11 -0
- package/dist/src/firestore/useCollectionReference.js +12 -1
- package/dist/src/firestore/useCompositeFilter.d.ts +10 -0
- package/dist/src/firestore/useCompositeFilter.js +17 -0
- package/dist/src/firestore/useCountQuery.d.ts +13 -0
- package/dist/src/firestore/useCountQuery.js +13 -0
- package/dist/src/firestore/useDeleteDocMutation.d.ts +7 -0
- package/dist/src/firestore/useDeleteDocMutation.js +7 -0
- package/dist/src/firestore/useDocReference.d.ts +12 -0
- package/dist/src/firestore/useDocReference.js +25 -1
- package/dist/src/firestore/useDocReferences.d.ts +16 -0
- package/dist/src/firestore/useDocReferences.js +17 -1
- package/dist/src/firestore/useFirestore.d.ts +7 -0
- package/dist/src/firestore/useFirestore.js +12 -0
- package/dist/src/firestore/useGetDocData.d.ts +8 -0
- package/dist/src/firestore/useGetDocData.js +9 -1
- package/dist/src/firestore/useInfiniteQuery.d.ts +7 -0
- package/dist/src/firestore/useInfiniteQuery.js +7 -0
- package/dist/src/firestore/useQuery.d.ts +14 -0
- package/dist/src/firestore/useQuery.js +14 -0
- package/dist/src/firestore/useRunTransaction.d.ts +7 -0
- package/dist/src/firestore/useRunTransaction.js +8 -1
- package/dist/src/firestore/useSetDocMutation.d.ts +9 -0
- package/dist/src/firestore/useSetDocMutation.js +9 -0
- package/dist/src/firestore/useUpdateDocMutation.d.ts +19 -0
- package/dist/src/firestore/useUpdateDocMutation.js +19 -0
- package/dist/src/firestore/utils/getDocData.d.ts +14 -0
- package/dist/src/firestore/utils/getDocData.js +14 -0
- package/dist/src/firestore/utils/getDocRef.d.ts +11 -0
- package/dist/src/firestore/utils/getDocRef.js +11 -0
- package/dist/src/firestore/utils/getDocSnap.d.ts +16 -0
- package/dist/src/firestore/utils/getDocSnap.js +16 -0
- package/dist/src/index.d.ts +1 -6
- package/dist/src/index.js +1 -6
- package/dist/src/remoteConfig/index.d.ts +1 -0
- package/dist/src/remoteConfig/index.js +1 -0
- package/dist/src/remoteConfig/useFetchAndActivate.d.ts +7 -0
- package/dist/src/remoteConfig/useFetchAndActivate.js +13 -4
- package/dist/src/remoteConfig/useGetValue.d.ts +6 -0
- package/dist/src/remoteConfig/useGetValue.js +7 -1
- package/dist/src/remoteConfig/useRemoteConfig.d.ts +5 -0
- package/dist/src/remoteConfig/useRemoteConfig.js +10 -0
- package/package.json +13 -5
- package/src/analytics/index.ts +1 -0
- package/src/analytics/useAnalytics.ts +12 -0
- package/src/analytics/useLogEvent.ts +8 -1
- package/src/auth/index.ts +2 -0
- package/src/auth/useAuth.ts +12 -0
- package/src/auth/useAuthStateReady.ts +6 -1
- package/src/auth/useCreateUserWitEmailAndPasswordMutation.ts +8 -1
- package/src/auth/useCurrentUser.ts +6 -1
- package/src/auth/useIdToken.ts +8 -0
- package/src/auth/useReauthenticateWitCredentialMutation.ts +8 -0
- package/src/auth/useReauthenticateWitRedirectMutation.ts +8 -0
- package/src/auth/useSendEmailVerificationMutation.ts +6 -0
- package/src/auth/useSignInWitEmailAndPasswordMutation.ts +8 -1
- package/src/auth/useSignInWitRedirectMutation.ts +7 -1
- package/src/auth/useSignOutMutation.ts +8 -1
- package/src/auth/useUpdateProfileMutation.ts +7 -0
- package/src/{FirebaseContext.ts → context/FirebaseContext.ts} +9 -2
- package/src/context/FirebaseContextProvider.tsx +173 -0
- package/src/context/index.ts +1 -0
- package/src/firestore/index.ts +1 -0
- package/src/firestore/useAddDocMutation.ts +11 -0
- package/src/firestore/useBatchWrite.ts +8 -1
- package/src/firestore/useCollectionReference.ts +12 -1
- package/src/firestore/useCompositeFilter.ts +18 -0
- package/src/firestore/useCountQuery.ts +14 -0
- package/src/firestore/useDeleteDocMutation.ts +7 -0
- package/src/firestore/useDocReference.ts +25 -1
- package/src/firestore/useDocReferences.ts +17 -1
- package/src/firestore/useFirestore.ts +13 -0
- package/src/firestore/useGetDocData.ts +9 -1
- package/src/firestore/useInfiniteQuery.ts +7 -0
- package/src/firestore/useQuery.ts +14 -0
- package/src/firestore/useRunTransaction.ts +8 -1
- package/src/firestore/useSetDocMutation.ts +9 -0
- package/src/firestore/useUpdateDocMutation.ts +19 -0
- package/src/firestore/utils/getDocData.ts +14 -0
- package/src/firestore/utils/getDocRef.ts +11 -0
- package/src/firestore/utils/getDocSnap.ts +16 -0
- package/src/index.ts +1 -6
- package/src/remoteConfig/index.ts +1 -0
- package/src/remoteConfig/useFetchAndActivate.ts +13 -4
- package/src/remoteConfig/useGetValue.ts +7 -1
- package/src/remoteConfig/useRemoteConfig.ts +11 -0
- package/dist/src/FirebaseContext.js +0 -3
- package/dist/src/FirebaseContextProvider.d.ts +0 -28
- package/dist/src/useAnalytics.d.ts +0 -1
- package/dist/src/useAnalytics.js +0 -6
- package/dist/src/useAuth.d.ts +0 -1
- package/dist/src/useAuth.js +0 -6
- package/dist/src/useFirebase.d.ts +0 -1
- package/dist/src/useFirebase.js +0 -6
- package/dist/src/useFirestore.d.ts +0 -1
- package/dist/src/useFirestore.js +0 -6
- package/dist/src/useRemoteConfig.d.ts +0 -1
- package/dist/src/useRemoteConfig.js +0 -6
- package/src/FirebaseContextProvider.tsx +0 -91
- package/src/firestore/useUpdateDocMutation copy.ts +0 -51
- package/src/useAnalytics.ts +0 -8
- package/src/useAuth.ts +0 -8
- package/src/useFirebase.ts +0 -8
- package/src/useFirestore.ts +0 -7
- package/src/useRemoteConfig.ts +0 -7
|
@@ -5,6 +5,29 @@ import { getAnalytics } from "firebase/analytics";
|
|
|
5
5
|
import { getRemoteConfig } from "firebase/remote-config";
|
|
6
6
|
import { connectFirestoreEmulator, getFirestore } from "firebase/firestore";
|
|
7
7
|
import { initializeApp } from "firebase/app";
|
|
8
|
+
/**
|
|
9
|
+
* FirebaseContextProvider component configures and provides Firebase services to its children.
|
|
10
|
+
* Initializes Firebase app and enables optional Firebase services such as Firestore, Auth, Analytics,
|
|
11
|
+
* and Remote Config based on the provided configuration and parameters.
|
|
12
|
+
*
|
|
13
|
+
* @group Component
|
|
14
|
+
*
|
|
15
|
+
* @param {FirebaseContextProviderProps} props
|
|
16
|
+
*
|
|
17
|
+
* @returns {FirebaseContextProvider<FirebaseContextProviderProps>}
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```jsx
|
|
21
|
+
* const firebaseConfig = {};
|
|
22
|
+
* export const App = () => {
|
|
23
|
+
* return (
|
|
24
|
+
* <FirebaseContextProvider options={firebaseConfig}>
|
|
25
|
+
* <ChildComponent />
|
|
26
|
+
* </FirebaseContextProvider>
|
|
27
|
+
* );
|
|
28
|
+
* };
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
8
31
|
export const FirebaseContextProvider = ({ emulators, options, children, authEnabled = true, firestoreEnabled = true, analyticsEnabled = true, remoteConfigEnabled = true, remoteConfigSettings, remoteConfigDefaults = {} }) => {
|
|
9
32
|
const firebase = useMemo(() => {
|
|
10
33
|
return initializeApp(options);
|
|
@@ -42,5 +65,5 @@ export const FirebaseContextProvider = ({ emulators, options, children, authEnab
|
|
|
42
65
|
}
|
|
43
66
|
return { firebase, ...value };
|
|
44
67
|
}, [firebase]);
|
|
45
|
-
return React.createElement(FirebaseContext.Provider, { value: contextValue }, children);
|
|
68
|
+
return (React.createElement(FirebaseContext.Provider, { value: contextValue }, children));
|
|
46
69
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./FirebaseContextProvider";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./FirebaseContextProvider";
|
|
@@ -9,4 +9,15 @@ export type UseAddDocMutationOptions<AppModelType extends DocumentData = Documen
|
|
|
9
9
|
converter?: FirestoreDataConverter<AppModelType, DbModelType>;
|
|
10
10
|
options?: Omit<UseMutationOptions<AppModelType, FirebaseError, UseAddDocMutationValues<AppModelType>, TContext>, "mutationFn" | "mutationKey">;
|
|
11
11
|
};
|
|
12
|
+
/**
|
|
13
|
+
* Provides a mutation hook to add a document to a Firestore collection utilizing React Query's `useMutation`.
|
|
14
|
+
* It handles addition and optional conversion of the document data in Firestore.
|
|
15
|
+
*
|
|
16
|
+
* @param {Object} options - Options for the mutation hook
|
|
17
|
+
* @param {FirebaseFirestore.CollectionReference<AppModelType>} options.reference - Firestore collection reference where the document should be added.
|
|
18
|
+
* @param {FirebaseFirestore.FirestoreDataConverter<DbModelType>} [options.converter] - Optional data converter for reading and writing Firestore documents.
|
|
19
|
+
* @param {UseMutationOptions<AppModelType, Error, { data: DbModelType }, TContext>} [options.options={}] - Optional configuration for the mutation.
|
|
20
|
+
*
|
|
21
|
+
* @returns {UseMutationResult<AppModelType, Error, { data: DbModelType }, TContext>} The mutation hook result containing status, error, and data of the mutation process.
|
|
22
|
+
*/
|
|
12
23
|
export declare const useAddDocMutation: <AppModelType extends DocumentData = DocumentData, DbModelType extends DocumentData = DocumentData, TContext = unknown>({ reference, converter, options }: UseAddDocMutationOptions<AppModelType, DbModelType, TContext>) => import("@tanstack/react-query").UseMutationResult<AppModelType, FirebaseError, UseAddDocMutationValues<AppModelType>, TContext>;
|
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import { useMutation } from "@tanstack/react-query";
|
|
2
2
|
import { addDoc, getDoc } from "firebase/firestore";
|
|
3
3
|
import { useMemo } from "react";
|
|
4
|
+
/**
|
|
5
|
+
* Provides a mutation hook to add a document to a Firestore collection utilizing React Query's `useMutation`.
|
|
6
|
+
* It handles addition and optional conversion of the document data in Firestore.
|
|
7
|
+
*
|
|
8
|
+
* @param {Object} options - Options for the mutation hook
|
|
9
|
+
* @param {FirebaseFirestore.CollectionReference<AppModelType>} options.reference - Firestore collection reference where the document should be added.
|
|
10
|
+
* @param {FirebaseFirestore.FirestoreDataConverter<DbModelType>} [options.converter] - Optional data converter for reading and writing Firestore documents.
|
|
11
|
+
* @param {UseMutationOptions<AppModelType, Error, { data: DbModelType }, TContext>} [options.options={}] - Optional configuration for the mutation.
|
|
12
|
+
*
|
|
13
|
+
* @returns {UseMutationResult<AppModelType, Error, { data: DbModelType }, TContext>} The mutation hook result containing status, error, and data of the mutation process.
|
|
14
|
+
*/
|
|
4
15
|
export const useAddDocMutation = ({ reference, converter, options = {} }) => {
|
|
5
16
|
const mutationKey = useMemo(() => [reference.path], [reference.path]);
|
|
6
17
|
return useMutation({
|
|
@@ -5,4 +5,11 @@ export type UseBatchWriteVariables = (batch: WriteBatch) => Promise<void> | void
|
|
|
5
5
|
export type UseBatchWriteOptions<TContext = unknown> = {
|
|
6
6
|
options?: Omit<UseMutationOptions<void, FirebaseError, UseBatchWriteVariables, TContext>, "mutationFn">;
|
|
7
7
|
};
|
|
8
|
+
/**
|
|
9
|
+
* Custom hook to perform batch write operations using Firestore.
|
|
10
|
+
* Utilizes a mutation to carry out the batch write transaction.
|
|
11
|
+
* @template TContext - The type of context that can be passed into the hook, defaults to unknown.
|
|
12
|
+
* @param {Object} options - The configuration options for the mutation operation.
|
|
13
|
+
* @returns {Object} Returns an object composed of elements returned by useMutation, including properties such as status, and functions to trigger and control the mutation process.
|
|
14
|
+
*/
|
|
8
15
|
export declare const useBatchWrite: <TContext = unknown>({ options }?: UseBatchWriteOptions<TContext>) => import("@tanstack/react-query").UseMutationResult<void, FirebaseError, UseBatchWriteVariables, TContext>;
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { useMutation } from "@tanstack/react-query";
|
|
2
2
|
import { writeBatch } from "firebase/firestore";
|
|
3
|
-
import { useFirestore } from "
|
|
3
|
+
import { useFirestore } from "./useFirestore";
|
|
4
|
+
/**
|
|
5
|
+
* Custom hook to perform batch write operations using Firestore.
|
|
6
|
+
* Utilizes a mutation to carry out the batch write transaction.
|
|
7
|
+
* @template TContext - The type of context that can be passed into the hook, defaults to unknown.
|
|
8
|
+
* @param {Object} options - The configuration options for the mutation operation.
|
|
9
|
+
* @returns {Object} Returns an object composed of elements returned by useMutation, including properties such as status, and functions to trigger and control the mutation process.
|
|
10
|
+
*/
|
|
4
11
|
export const useBatchWrite = ({ options = {} } = {}) => {
|
|
5
12
|
const db = useFirestore();
|
|
6
13
|
return useMutation({
|
|
@@ -4,4 +4,15 @@ export type UseCollectionReferenceOptions<AppModelType, DbModelType extends Docu
|
|
|
4
4
|
path: string;
|
|
5
5
|
pathSegments?: string[];
|
|
6
6
|
};
|
|
7
|
+
/**
|
|
8
|
+
* Creates a reference to a Firestore collection based on the provided path, reference, and path segments.
|
|
9
|
+
*
|
|
10
|
+
* This hook utilizes useMemo for optimization, ensuring the collection reference is recalculated only when its dependencies change.
|
|
11
|
+
*
|
|
12
|
+
* @param {UseCollectionReferenceOptions<AppModelType, DbModelType>} options - The options including path, reference, and pathSegments to construct the Firestore collection reference.
|
|
13
|
+
* @param {string} options.path - The base path for the collection.
|
|
14
|
+
* @param {FirestoreReference} options.reference - An optional Firestore reference object that should be of type "collection".
|
|
15
|
+
* @param {string[]} options.pathSegments - Additional path segments to append to the base path.
|
|
16
|
+
* @returns {CollectionReference} A Firestore collection reference constructed using the specified path, reference, and path segments.
|
|
17
|
+
*/
|
|
7
18
|
export declare const useCollectionReference: <AppModelType, DbModelType extends DocumentData = DocumentData>({ path, reference, pathSegments }: UseCollectionReferenceOptions<AppModelType, DbModelType>) => CollectionReference<DocumentData, DocumentData>;
|
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import { collection } from "firebase/firestore";
|
|
2
2
|
import { useMemo } from "react";
|
|
3
|
-
import { useFirestore } from "
|
|
3
|
+
import { useFirestore } from "./useFirestore";
|
|
4
|
+
/**
|
|
5
|
+
* Creates a reference to a Firestore collection based on the provided path, reference, and path segments.
|
|
6
|
+
*
|
|
7
|
+
* This hook utilizes useMemo for optimization, ensuring the collection reference is recalculated only when its dependencies change.
|
|
8
|
+
*
|
|
9
|
+
* @param {UseCollectionReferenceOptions<AppModelType, DbModelType>} options - The options including path, reference, and pathSegments to construct the Firestore collection reference.
|
|
10
|
+
* @param {string} options.path - The base path for the collection.
|
|
11
|
+
* @param {FirestoreReference} options.reference - An optional Firestore reference object that should be of type "collection".
|
|
12
|
+
* @param {string[]} options.pathSegments - Additional path segments to append to the base path.
|
|
13
|
+
* @returns {CollectionReference} A Firestore collection reference constructed using the specified path, reference, and path segments.
|
|
14
|
+
*/
|
|
4
15
|
export const useCollectionReference = ({ path, reference, pathSegments }) => {
|
|
5
16
|
const db = useFirestore();
|
|
6
17
|
return useMemo(() => {
|
|
@@ -16,5 +16,15 @@ export type CompositeFilter<DbModelType extends CompositeFilterDocumentData = Co
|
|
|
16
16
|
export type UseCompositeFilter<DbModelType extends CompositeFilterDocumentData = CompositeFilterDocumentData> = {
|
|
17
17
|
query?: CompositeFilter<DbModelType>;
|
|
18
18
|
};
|
|
19
|
+
/**
|
|
20
|
+
* A custom hook that generates a composite filter for database queries, using the provided query configuration.
|
|
21
|
+
* It applies either an 'OR' or 'AND' logical operation based on the type specified in the query.
|
|
22
|
+
*
|
|
23
|
+
* @param {Object} query - The query configuration object that contains subqueries and a type for logical combination.
|
|
24
|
+
* @param {string} query.type - The type of composite operation ('or'/'and').
|
|
25
|
+
* @param {Array} query.children - An array of subqueries that will be processed to form the composite filter.
|
|
26
|
+
*
|
|
27
|
+
* @returns {(Function|undefined)} A composite query filter constraint function formed by combining subqueries or undefined if there are no valid constraints.
|
|
28
|
+
*/
|
|
19
29
|
export declare const useCompositeFilter: <DbModelType extends CompositeFilterDocumentData = DocumentData>({ query }: UseCompositeFilter<DbModelType>) => QueryCompositeFilterConstraint | undefined;
|
|
20
30
|
export {};
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { and, documentId, or, where } from "firebase/firestore";
|
|
2
2
|
import { useMemo } from "react";
|
|
3
|
+
/**
|
|
4
|
+
* Constructs a composite query filter based on the provided query structure.
|
|
5
|
+
* It recursively builds query constraints using logical "or" or "and" operators.
|
|
6
|
+
*
|
|
7
|
+
* @param {QueryElement<DbModelType>} query - The query element or structure to be evaluated and transformed into filter constraints.
|
|
8
|
+
* @returns {QueryFilterConstraint | null} A constructed query filter constraint based on the input query, or null if no valid constraints can be derived.
|
|
9
|
+
*/
|
|
3
10
|
const buildCompositeQuery = (query) => {
|
|
4
11
|
if (query.children) {
|
|
5
12
|
const queryConstraints = query.children
|
|
@@ -15,6 +22,16 @@ const buildCompositeQuery = (query) => {
|
|
|
15
22
|
}
|
|
16
23
|
return null;
|
|
17
24
|
};
|
|
25
|
+
/**
|
|
26
|
+
* A custom hook that generates a composite filter for database queries, using the provided query configuration.
|
|
27
|
+
* It applies either an 'OR' or 'AND' logical operation based on the type specified in the query.
|
|
28
|
+
*
|
|
29
|
+
* @param {Object} query - The query configuration object that contains subqueries and a type for logical combination.
|
|
30
|
+
* @param {string} query.type - The type of composite operation ('or'/'and').
|
|
31
|
+
* @param {Array} query.children - An array of subqueries that will be processed to form the composite filter.
|
|
32
|
+
*
|
|
33
|
+
* @returns {(Function|undefined)} A composite query filter constraint function formed by combining subqueries or undefined if there are no valid constraints.
|
|
34
|
+
*/
|
|
18
35
|
export const useCompositeFilter = ({ query }) => {
|
|
19
36
|
return useMemo(() => {
|
|
20
37
|
const queryConstraints = (query?.children?.map?.((subQuery) => buildCompositeQuery(subQuery))?.filter)?.((constraint) => !!constraint) ?? [];
|
|
@@ -6,5 +6,18 @@ type UseCountQueryOptions<AppModelType extends DocumentData = DocumentData, DbMo
|
|
|
6
6
|
queryConstraints?: QueryConstraint[] | QueryNonFilterConstraint[];
|
|
7
7
|
compositeFilter?: QueryCompositeFilterConstraint;
|
|
8
8
|
};
|
|
9
|
+
/**
|
|
10
|
+
* Executes a query with specified constraints and returns the count of matched documents.
|
|
11
|
+
*
|
|
12
|
+
* This function utilizes React Query to asynchronously fetch the count of documents from a server database
|
|
13
|
+
* that match the provided query constraints and an optional composite filter.
|
|
14
|
+
*
|
|
15
|
+
* @param {UseCountQueryOptions<AppModelType, DbModelType>} options - Configuration options for the query.
|
|
16
|
+
* @param {AppModelType extends DocumentData = DocumentData} [options.options] - Additional options for the React Query.
|
|
17
|
+
* @param {unknown} [options.query] - Reference to the query object to be executed.
|
|
18
|
+
* @param {unknown[]} [options.queryConstraints=[]] - An array of constraints to apply to the query.
|
|
19
|
+
* @param {unknown} [options.compositeFilter] - An optional composite filter to apply to the query.
|
|
20
|
+
* @returns {UseQueryResult<number>} An object containing the number of documents that match the query.
|
|
21
|
+
*/
|
|
9
22
|
export declare const useCountQuery: <AppModelType extends DocumentData = DocumentData, DbModelType extends DocumentData = DocumentData>({ options, query: queryReference, queryConstraints, compositeFilter }: UseCountQueryOptions<AppModelType, DbModelType>) => UseQueryResult<number>;
|
|
10
23
|
export {};
|
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
import { getCountFromServer, query } from "firebase/firestore";
|
|
2
2
|
import { useQuery as useReactQuery } from "@tanstack/react-query";
|
|
3
|
+
/**
|
|
4
|
+
* Executes a query with specified constraints and returns the count of matched documents.
|
|
5
|
+
*
|
|
6
|
+
* This function utilizes React Query to asynchronously fetch the count of documents from a server database
|
|
7
|
+
* that match the provided query constraints and an optional composite filter.
|
|
8
|
+
*
|
|
9
|
+
* @param {UseCountQueryOptions<AppModelType, DbModelType>} options - Configuration options for the query.
|
|
10
|
+
* @param {AppModelType extends DocumentData = DocumentData} [options.options] - Additional options for the React Query.
|
|
11
|
+
* @param {unknown} [options.query] - Reference to the query object to be executed.
|
|
12
|
+
* @param {unknown[]} [options.queryConstraints=[]] - An array of constraints to apply to the query.
|
|
13
|
+
* @param {unknown} [options.compositeFilter] - An optional composite filter to apply to the query.
|
|
14
|
+
* @returns {UseQueryResult<number>} An object containing the number of documents that match the query.
|
|
15
|
+
*/
|
|
3
16
|
export const useCountQuery = ({ options, query: queryReference, queryConstraints = [], compositeFilter }) => {
|
|
4
17
|
return useReactQuery({
|
|
5
18
|
...options,
|
|
@@ -8,4 +8,11 @@ export type UseDeleteDocMutationOptions<AppModelType extends DocumentData = Docu
|
|
|
8
8
|
reference: DocumentReference<AppModelType, DbModelType> | null;
|
|
9
9
|
options?: Omit<UseMutationOptions<void, FirebaseError, void, TContext>, "mutationFn" | "mutationKey">;
|
|
10
10
|
};
|
|
11
|
+
/**
|
|
12
|
+
* A custom hook that provides a mutation function to delete a document from the database.
|
|
13
|
+
* @param {UseDeleteDocMutationOptions<AppModelType, DbModelType, TContext>} options - An object containing the reference to the document and additional options for the mutation.
|
|
14
|
+
* @param {FirestoreReference<AppModelType, DbModelType>} options.reference - The reference to the document that needs to be deleted.
|
|
15
|
+
* @param {object} options.options - Additional options for the mutation, if any (default is an empty object).
|
|
16
|
+
* @returns {UseMutationResult} An object returned by the `useMutation` hook which includes properties and methods to control the mutation's execution and track its state.
|
|
17
|
+
*/
|
|
11
18
|
export declare const useDeleteDocMutation: <AppModelType extends DocumentData = DocumentData, DbModelType extends DocumentData = DocumentData, TContext = unknown>({ reference, options }: UseDeleteDocMutationOptions<AppModelType, DbModelType, TContext>) => import("@tanstack/react-query").UseMutationResult<void, FirebaseError, void, TContext>;
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { useMutation } from "@tanstack/react-query";
|
|
2
2
|
import { deleteDoc } from "firebase/firestore";
|
|
3
3
|
import { useMemo } from "react";
|
|
4
|
+
/**
|
|
5
|
+
* A custom hook that provides a mutation function to delete a document from the database.
|
|
6
|
+
* @param {UseDeleteDocMutationOptions<AppModelType, DbModelType, TContext>} options - An object containing the reference to the document and additional options for the mutation.
|
|
7
|
+
* @param {FirestoreReference<AppModelType, DbModelType>} options.reference - The reference to the document that needs to be deleted.
|
|
8
|
+
* @param {object} options.options - Additional options for the mutation, if any (default is an empty object).
|
|
9
|
+
* @returns {UseMutationResult} An object returned by the `useMutation` hook which includes properties and methods to control the mutation's execution and track its state.
|
|
10
|
+
*/
|
|
4
11
|
export const useDeleteDocMutation = ({ reference, options = {} }) => {
|
|
5
12
|
const mutationKey = useMemo(() => [reference?.path], [reference?.path]);
|
|
6
13
|
return useMutation({
|
|
@@ -4,4 +4,16 @@ export type UseDocReferenceOptions<AppModelType, DbModelType extends DocumentDat
|
|
|
4
4
|
path?: string;
|
|
5
5
|
pathSegments?: string[];
|
|
6
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, DbModelType>} 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 {DocumentReference<AppModelType, DbModelType> | null} The Firestore document reference corresponding to the provided path and options, or null if not initialized.
|
|
18
|
+
*/
|
|
7
19
|
export declare const useDocReference: <AppModelType, DbModelType extends DocumentData = DocumentData>({ path, reference, pathSegments }: UseDocReferenceOptions<AppModelType, DbModelType>) => DocumentReference<AppModelType, DbModelType> | null;
|
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
import { doc } from "firebase/firestore";
|
|
2
2
|
import { useEffect, useRef } from "react";
|
|
3
|
-
import { useFirestore } from "
|
|
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, DbModelType>} 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, DbModelType> | null} A Firestore document reference if the path is specified; otherwise, returns null if path is not provided.
|
|
15
|
+
*/
|
|
4
16
|
const getDocReference = (db, { path, pathSegments, reference }) => {
|
|
5
17
|
if (!path) {
|
|
6
18
|
return null;
|
|
@@ -11,6 +23,18 @@ const getDocReference = (db, { path, pathSegments, reference }) => {
|
|
|
11
23
|
? doc(reference, path, ...(pathSegments || []))
|
|
12
24
|
: doc(reference, path, ...(pathSegments || [])));
|
|
13
25
|
};
|
|
26
|
+
/**
|
|
27
|
+
* Custom hook to generate and manage a Firestore document reference.
|
|
28
|
+
* This hook facilitates the retrieval of a Firestore document reference based on given options such as path and reference data.
|
|
29
|
+
* The reference is updated whenever the associated path, reference, or path segments change.
|
|
30
|
+
*
|
|
31
|
+
* @param {UseDocReferenceOptions<AppModelType, DbModelType>} options - Configuration options for setting up the document reference.
|
|
32
|
+
* @param {string} options.path - The path to the Firestore document.
|
|
33
|
+
* @param {DbModelType} options.reference - Reference data for the document, providing additional context or specifics.
|
|
34
|
+
* @param {string[]} options.pathSegments - Parts of the path to construct the full document path dynamically.
|
|
35
|
+
*
|
|
36
|
+
* @returns {DocumentReference<AppModelType, DbModelType> | null} The Firestore document reference corresponding to the provided path and options, or null if not initialized.
|
|
37
|
+
*/
|
|
14
38
|
export const useDocReference = ({ path, reference, pathSegments }) => {
|
|
15
39
|
const db = useFirestore();
|
|
16
40
|
const ref = useRef(getDocReference(db, { path, pathSegments, reference }));
|
|
@@ -4,4 +4,20 @@ export type UseDocReferencesOptions<AppModelType, DbModelType extends DocumentDa
|
|
|
4
4
|
path: string;
|
|
5
5
|
pathSegments?: string[];
|
|
6
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, DbModelType>[]} 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, DbModelType>[]} An array of Firestore document references
|
|
21
|
+
* generated from the options provided.
|
|
22
|
+
*/
|
|
7
23
|
export declare const useDocReferences: <AppModelType, DbModelType extends DocumentData = DocumentData>(references: UseDocReferencesOptions<AppModelType, DbModelType>[]) => DocumentReference<AppModelType, DbModelType>[];
|
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
import { doc } from "firebase/firestore";
|
|
2
2
|
import { useMemo } from "react";
|
|
3
|
-
import { useFirestore } from "
|
|
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, DbModelType>[]} 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, DbModelType>[]} An array of Firestore document references
|
|
18
|
+
* generated from the options provided.
|
|
19
|
+
*/
|
|
4
20
|
export const useDocReferences = (references) => {
|
|
5
21
|
const db = useFirestore();
|
|
6
22
|
return useMemo(() => {
|
|
@@ -0,0 +1,7 @@
|
|
|
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("@firebase/firestore").Firestore;
|
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
};
|
|
@@ -6,5 +6,13 @@ type UseGetDocOptions<AppModelType extends DocumentData = DocumentData, DbModelT
|
|
|
6
6
|
pathSegments?: string[];
|
|
7
7
|
reference: CollectionReference<AppModelType, DbModelType> | DocumentReference<AppModelType, DbModelType>;
|
|
8
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
|
+
*/
|
|
9
17
|
export declare const useGetDocData: <AppModelType extends DocumentData = DocumentData, DbModelType extends DocumentData = DocumentData>({ options, reference, path, pathSegments }: UseGetDocOptions<AppModelType, DbModelType>) => import("@tanstack/react-query").UseQueryResult<AppModelType, Error>;
|
|
10
18
|
export {};
|
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
import { useFirestore } from "
|
|
1
|
+
import { useFirestore } from "./useFirestore";
|
|
2
2
|
import { getDocData } from "./utils/getDocData";
|
|
3
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
|
+
*/
|
|
4
12
|
export const useGetDocData = ({ options, reference, path, pathSegments }) => {
|
|
5
13
|
const db = useFirestore();
|
|
6
14
|
return useQuery({
|
|
@@ -7,5 +7,12 @@ type UseInfiniteQueryOptions<AppModelType extends DocumentData = DocumentData, D
|
|
|
7
7
|
compositeFilter?: QueryCompositeFilterConstraint;
|
|
8
8
|
converter?: FirestoreDataConverter<AppModelType, DbModelType>;
|
|
9
9
|
};
|
|
10
|
+
/**
|
|
11
|
+
* Custom hook that creates an infinite query using Firestore, allowing for query constraints, composite filters, and converters.
|
|
12
|
+
* It fetches data in pages and can load more as required.
|
|
13
|
+
*
|
|
14
|
+
* @param {UseInfiniteQueryOptions<AppModelType, DbModelType>} options - Configuration options for the infinite query, including Firestore query reference, query constraints, composite filter, and data converter.
|
|
15
|
+
* @returns {UseInfiniteQueryResult<InfiniteData<AppModelType[]>>} Result object containing the infinite data and methods for fetching more pages.
|
|
16
|
+
*/
|
|
10
17
|
export declare const useInfiniteQuery: <AppModelType extends DocumentData = DocumentData, DbModelType extends DocumentData = DocumentData>({ options, query: queryReference, queryConstraints, compositeFilter, converter }: UseInfiniteQueryOptions<AppModelType, DbModelType>) => UseInfiniteQueryResult<InfiniteData<AppModelType[]>>;
|
|
11
18
|
export {};
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { getDocs, query } from "firebase/firestore";
|
|
2
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
|
+
*/
|
|
3
10
|
export const useInfiniteQuery = ({ options, query: queryReference, queryConstraints = [], compositeFilter, converter }) => {
|
|
4
11
|
return useInfiniteReactQuery({
|
|
5
12
|
...options,
|
|
@@ -7,5 +7,19 @@ type UseQueryOptions<AppModelType extends DocumentData = DocumentData, DbModelTy
|
|
|
7
7
|
compositeFilter?: QueryCompositeFilterConstraint;
|
|
8
8
|
converter?: FirestoreDataConverter<AppModelType, DbModelType>;
|
|
9
9
|
};
|
|
10
|
+
/**
|
|
11
|
+
* Executes a query on a Firestore-like data source and returns the resulting documents as an array.
|
|
12
|
+
*
|
|
13
|
+
* This hook utilizes an abstraction over React Query to asynchronously fetch data based on the provided query
|
|
14
|
+
* reference and constraints. It supports optional filtering, conversion, and additional query constraints.
|
|
15
|
+
*
|
|
16
|
+
* @param {UseQueryOptions<AppModelType, DbModelType>} options - Configuration options for the query.
|
|
17
|
+
* @param {DocumentReference<AppModelType>} queryReference - The reference to the query to be executed.
|
|
18
|
+
* @param {QueryConstraint[]} queryConstraints - Additional constraints to fine-tune the query.
|
|
19
|
+
* @param {QueryConstraint} compositeFilter - Optional composite filter to apply to the query.
|
|
20
|
+
* @param {FirestoreDataConverter<AppModelType>} converter - Optional data converter for transforming snapshots.
|
|
21
|
+
*
|
|
22
|
+
* @returns {UseQueryResult<AppModelType[]>} Result containing an array of documents that match the query criteria.
|
|
23
|
+
*/
|
|
10
24
|
export declare const useQuery: <AppModelType extends DocumentData = DocumentData, DbModelType extends DocumentData = DocumentData>({ options, query: queryReference, queryConstraints, compositeFilter, converter }: UseQueryOptions<AppModelType, DbModelType>) => UseQueryResult<AppModelType[]>;
|
|
11
25
|
export {};
|
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
import { getDocs, query } from "firebase/firestore";
|
|
2
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, DbModelType>} options - Configuration options for the query.
|
|
10
|
+
* @param {DocumentReference<AppModelType>} queryReference - 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
|
+
*/
|
|
3
17
|
export const useQuery = ({ options, query: queryReference, queryConstraints = [], compositeFilter, converter }) => {
|
|
4
18
|
return useReactQuery({
|
|
5
19
|
...options,
|
|
@@ -5,4 +5,11 @@ export type UseRunTransactionValues = <AppModelType = unknown>(transaction: Tran
|
|
|
5
5
|
export type UseRunTransactionOptions<AppModelType = unknown, TContext = unknown> = {
|
|
6
6
|
options?: Omit<UseMutationOptions<AppModelType, FirebaseError, UseRunTransactionValues, TContext>, "mutationFn">;
|
|
7
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
|
+
*/
|
|
8
15
|
export declare const useRunTransaction: <AppModelType = unknown, TContext = unknown>({ options }: UseRunTransactionOptions<AppModelType, TContext>) => import("@tanstack/react-query").UseMutationResult<AppModelType, FirebaseError, UseRunTransactionValues, TContext>;
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { useMutation } from "@tanstack/react-query";
|
|
2
2
|
import { runTransaction } from "firebase/firestore";
|
|
3
|
-
import { useFirestore } from "
|
|
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
|
+
*/
|
|
4
11
|
export const useRunTransaction = ({ options = {} }) => {
|
|
5
12
|
const db = useFirestore();
|
|
6
13
|
return useMutation({
|
|
@@ -8,4 +8,13 @@ export type UseSetDocMutationOptions<AppModelType = unknown, DbModelType extends
|
|
|
8
8
|
reference: DocumentReference<AppModelType, DbModelType> | null;
|
|
9
9
|
options?: Omit<UseMutationOptions<void, FirebaseError, UseSetDocMutationValues<AppModelType>, TContext>, "mutationFn" | "mutationKey">;
|
|
10
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, DbModelType, 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
|
+
*/
|
|
11
20
|
export declare const useSetDocMutation: <AppModelType = unknown, DbModelType extends DocumentData = DocumentData, TContext = unknown>({ reference, options }: UseSetDocMutationOptions<AppModelType, DbModelType, TContext>) => import("@tanstack/react-query").UseMutationResult<void, FirebaseError, UseSetDocMutationValues<AppModelType>, TContext>;
|
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import { useMutation } from "@tanstack/react-query";
|
|
2
2
|
import { setDoc } from "firebase/firestore";
|
|
3
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, DbModelType, 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
|
+
*/
|
|
4
13
|
export const useSetDocMutation = ({ reference, options }) => {
|
|
5
14
|
const mutationKey = useMemo(() => [reference?.path], [reference?.path]);
|
|
6
15
|
return useMutation({
|
|
@@ -9,4 +9,23 @@ export type UseUpdateDocMutationOptions<AppModelType extends DocumentData = Docu
|
|
|
9
9
|
converter?: FirestoreDataConverter<AppModelType, DbModelType>;
|
|
10
10
|
options?: Omit<UseMutationOptions<AppModelType, FirebaseError, UseUpdateDocMutationValues<DbModelType>, TContext>, "mutationFn" | "mutationKey">;
|
|
11
11
|
};
|
|
12
|
+
/**
|
|
13
|
+
* Custom hook that sets up a mutation for updating a document in a Firestore database.
|
|
14
|
+
*
|
|
15
|
+
* This hook utilizes `useMutation` for performing asynchronous operations to update the document
|
|
16
|
+
* and retrieve the latest data snapshot. The update functionality can be configured with a custom
|
|
17
|
+
* converter if needed.
|
|
18
|
+
*
|
|
19
|
+
* @param {UseUpdateDocMutationOptions<AppModelType, DbModelType, TContext>} options - Configuration options for the mutation,
|
|
20
|
+
* including Firestore reference, an optional Firestore data converter, and additional mutation options.
|
|
21
|
+
*
|
|
22
|
+
* `reference` - The Firestore document reference that identifies the document to be updated.
|
|
23
|
+
*
|
|
24
|
+
* `converter` - An optional Firestore converter for transforming the database response into a custom type.
|
|
25
|
+
*
|
|
26
|
+
* `options` - Additional options that customize the mutation's behavior.
|
|
27
|
+
*
|
|
28
|
+
* @returns {UseMutationResult<AppModelType, Error, {data: AppModelType}, TContext>} An object returned by `useMutation`
|
|
29
|
+
* which includes functions to start the mutation and properties that represent the different states of the mutation.
|
|
30
|
+
*/
|
|
12
31
|
export declare const useUpdateDocMutation: <AppModelType extends DocumentData = DocumentData, DbModelType extends DocumentData = DocumentData, TContext = unknown>({ reference, converter, options }: UseUpdateDocMutationOptions<AppModelType, DbModelType, TContext>) => import("@tanstack/react-query").UseMutationResult<AppModelType, FirebaseError, UseUpdateDocMutationValues<DbModelType>, TContext>;
|
|
@@ -1,6 +1,25 @@
|
|
|
1
1
|
import { useMutation } from "@tanstack/react-query";
|
|
2
2
|
import { updateDoc, getDoc } from "firebase/firestore";
|
|
3
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, DbModelType, 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
|
+
*/
|
|
4
23
|
export const useUpdateDocMutation = ({ reference, converter, options = {} }) => {
|
|
5
24
|
const mutationKey = useMemo(() => [reference?.path], [reference?.path]);
|
|
6
25
|
return useMutation({
|