react-query-firebase 2.2.0 → 2.3.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.
@@ -3,15 +3,24 @@ import { useQuery as useReactQuery } from "@tanstack/react-query";
3
3
  /**
4
4
  * Executes a query with specified constraints and returns the count of matched documents.
5
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.
6
+ * @group Hook
7
+ *
8
+ * @param {UseCountQueryOptions<AppModelType>} options - Configuration options for the query.
8
9
  *
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
10
  * @returns {UseQueryResult<number>} An object containing the number of documents that match the query.
11
+ *
12
+ * @example
13
+ * ```jsx
14
+ * export const MyComponent = () => {
15
+ * const count = useCountQuery({
16
+ * options: {
17
+ * queryKey: ['key']
18
+ * },
19
+ * collectionReference: collection(),
20
+ * });
21
+ * console.log(count);
22
+ * };
23
+ * ```
15
24
  */
16
25
  export const useCountQuery = ({ options, collectionReference, queryConstraints = [], compositeFilter }) => {
17
26
  return useReactQuery({
@@ -1,5 +1,4 @@
1
1
  import {
2
- DocumentData,
3
2
  getCountFromServer,
4
3
  CollectionReference,
5
4
  query,
@@ -13,36 +12,58 @@ import {
13
12
  useQuery as useReactQuery,
14
13
  UseQueryOptions as UseReactQueryOptions
15
14
  } from "@tanstack/react-query";
15
+ import { QueryFilterConstraint } from "./useCompositeFilter";
16
+ import { AppModel } from "../../types";
16
17
 
17
- type UseCountQueryOptions<
18
- AppModelType extends DocumentData = DocumentData,
19
- DbModelType extends DocumentData = DocumentData
20
- > = {
18
+ /**
19
+ * @inline
20
+ */
21
+ type UseCountQueryOptions<AppModelType extends AppModel = AppModel, DbModelType extends AppModel = AppModel> = {
22
+ /**
23
+ * Reqct-query options that must include queryKey and shall not define queryFn
24
+ */
21
25
  options: Omit<UseReactQueryOptions<number, Error, number>, "queryFn"> &
22
26
  Required<Pick<UseReactQueryOptions<number, Error, number>, "queryKey">>;
27
+
28
+ /**
29
+ * Reference to a Firestore collection
30
+ */
23
31
  collectionReference: CollectionReference<AppModelType, DbModelType>;
32
+
33
+ /**
34
+ * Non composite filter constraints such as limit, order, where
35
+ */
24
36
  queryConstraints?: QueryConstraint[] | QueryNonFilterConstraint[];
25
- compositeFilter?: QueryCompositeFilterConstraint;
37
+
38
+ /**
39
+ * Composite filter
40
+ */
41
+ compositeFilter?: QueryFilterConstraint;
26
42
  };
27
43
 
28
44
  /**
29
45
  * Executes a query with specified constraints and returns the count of matched documents.
30
46
  *
31
- * This function utilizes React Query to asynchronously fetch the count of documents from a server database
32
- * that match the provided query constraints and an optional composite filter.
47
+ * @group Hook
48
+ *
49
+ * @param {UseCountQueryOptions<AppModelType>} options - Configuration options for the query.
33
50
  *
34
- * @param {UseCountQueryOptions<AppModelType, DbModelType>} options - Configuration options for the query.
35
- * @param {AppModelType extends DocumentData = DocumentData} [options.options] - Additional options for the React Query.
36
- * @param {unknown} [options.query] - Reference to the query object to be executed.
37
- * @param {unknown[]} [options.queryConstraints=[]] - An array of constraints to apply to the query.
38
- * @param {unknown} [options.compositeFilter] - An optional composite filter to apply to the query.
39
51
  * @returns {UseQueryResult<number>} An object containing the number of documents that match the query.
52
+ *
53
+ * @example
54
+ * ```jsx
55
+ * export const MyComponent = () => {
56
+ * const count = useCountQuery({
57
+ * options: {
58
+ * queryKey: ['key']
59
+ * },
60
+ * collectionReference: collection(),
61
+ * });
62
+ * console.log(count);
63
+ * };
64
+ * ```
40
65
  */
41
-
42
- export const useCountQuery = <
43
- AppModelType extends DocumentData = DocumentData,
44
- DbModelType extends DocumentData = DocumentData
45
- >({
66
+ export const useCountQuery = <AppModelType extends AppModel = AppModel, DbModelType extends AppModel = AppModel>({
46
67
  options,
47
68
  collectionReference,
48
69
  queryConstraints = [],
@@ -52,7 +73,11 @@ export const useCountQuery = <
52
73
  ...options,
53
74
  queryFn: async () => {
54
75
  const queryToExecute = compositeFilter
55
- ? query(collectionReference, compositeFilter, ...(queryConstraints as QueryNonFilterConstraint[]))
76
+ ? query(
77
+ collectionReference,
78
+ compositeFilter as QueryCompositeFilterConstraint,
79
+ ...(queryConstraints as QueryNonFilterConstraint[])
80
+ )
56
81
  : query(collectionReference, ...queryConstraints);
57
82
 
58
83
  const querySnapshot = await getCountFromServer(queryToExecute);
@@ -1,18 +1,49 @@
1
- import { CollectionReference, DocumentData, FirestoreDataConverter, QueryCompositeFilterConstraint, QueryConstraint, QueryNonFilterConstraint } from "firebase/firestore";
1
+ import { CollectionReference, QueryConstraint, QueryNonFilterConstraint } from "firebase/firestore";
2
2
  import { UseInfiniteQueryOptions as UseReactInfiniteQueryOptions, QueryKey, UseInfiniteQueryResult, InfiniteData } from "@tanstack/react-query";
3
- type UseInfiniteQueryOptions<AppModelType extends DocumentData = DocumentData, DbModelType extends DocumentData = DocumentData, TQueryKey extends QueryKey = QueryKey> = {
3
+ import { QueryFilterConstraint } from "./useCompositeFilter";
4
+ import { AppModel } from "../../types";
5
+ /**
6
+ * @inline
7
+ */
8
+ type UseInfiniteQueryOptions<AppModelType extends AppModel = AppModel, TQueryKey extends QueryKey = QueryKey> = {
9
+ /**
10
+ * Reqct-query options that must include queryKey and shall not define queryFn
11
+ */
4
12
  options: Omit<UseReactInfiniteQueryOptions<AppModelType[], Error, InfiniteData<AppModelType[]>, AppModelType[], TQueryKey, QueryConstraint>, "queryFn"> & Required<Pick<UseReactInfiniteQueryOptions<AppModelType[], Error, InfiniteData<AppModelType[]>, AppModelType[], TQueryKey, QueryConstraint>, "queryKey">>;
5
- collectionReference: CollectionReference<AppModelType, DbModelType>;
13
+ /**
14
+ * Reference to a Firestore collection
15
+ */
16
+ collectionReference: CollectionReference<AppModelType, AppModelType>;
17
+ /**
18
+ * Non composite filter constraints such as limit, order, where
19
+ */
6
20
  queryConstraints?: QueryConstraint[] | QueryNonFilterConstraint[];
7
- compositeFilter?: QueryCompositeFilterConstraint;
8
- converter?: FirestoreDataConverter<AppModelType, DbModelType>;
21
+ /**
22
+ * Composite filter
23
+ */
24
+ compositeFilter?: QueryFilterConstraint;
9
25
  };
10
26
  /**
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.
27
+ * Executes an infinite query on a Firestore data source and returns the resulting documents as an array.
28
+ *
29
+ * @group Hook
30
+ *
31
+ * @param {UseInfiniteQueryOptions<AppModelType, TQueryKey>} options - Configuration options for the query.
32
+ *
33
+ * @returns {UseInfiniteQueryResult<InfiniteData<AppModelType[]>>} An object containing documents that match the query.
13
34
  *
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.
35
+ * @example
36
+ * ```jsx
37
+ * export const MyComponent = () => {
38
+ * const docs = useInfiniteQuery({
39
+ * options: {
40
+ * queryKey: ['key']
41
+ * },
42
+ * collectionReference: collection(),
43
+ * });
44
+ * console.log(docs);
45
+ * };
46
+ * ```
16
47
  */
17
- export declare const useInfiniteQuery: <AppModelType extends DocumentData = DocumentData, DbModelType extends DocumentData = DocumentData>({ options, collectionReference, queryConstraints, compositeFilter, converter }: UseInfiniteQueryOptions<AppModelType, DbModelType>) => UseInfiniteQueryResult<InfiniteData<AppModelType[]>>;
48
+ export declare const useInfiniteQuery: <AppModelType extends AppModel = AppModel, TQueryKey extends QueryKey = QueryKey>({ options, collectionReference, queryConstraints, compositeFilter }: UseInfiniteQueryOptions<AppModelType, TQueryKey>) => UseInfiniteQueryResult<InfiniteData<AppModelType[]>>;
18
49
  export {};
@@ -1,13 +1,28 @@
1
1
  import { getDocs, query } from "firebase/firestore";
2
2
  import { useInfiniteQuery as useInfiniteReactQuery } from "@tanstack/react-query";
3
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.
4
+ * Executes an infinite query on a Firestore data source and returns the resulting documents as an array.
6
5
  *
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.
6
+ * @group Hook
7
+ *
8
+ * @param {UseInfiniteQueryOptions<AppModelType, TQueryKey>} options - Configuration options for the query.
9
+ *
10
+ * @returns {UseInfiniteQueryResult<InfiniteData<AppModelType[]>>} An object containing documents that match the query.
11
+ *
12
+ * @example
13
+ * ```jsx
14
+ * export const MyComponent = () => {
15
+ * const docs = useInfiniteQuery({
16
+ * options: {
17
+ * queryKey: ['key']
18
+ * },
19
+ * collectionReference: collection(),
20
+ * });
21
+ * console.log(docs);
22
+ * };
23
+ * ```
9
24
  */
10
- export const useInfiniteQuery = ({ options, collectionReference, queryConstraints = [], compositeFilter, converter }) => {
25
+ export const useInfiniteQuery = ({ options, collectionReference, queryConstraints = [], compositeFilter }) => {
11
26
  return useInfiniteReactQuery({
12
27
  ...options,
13
28
  queryFn: async ({ pageParam }) => {
@@ -15,7 +30,7 @@ export const useInfiniteQuery = ({ options, collectionReference, queryConstraint
15
30
  const queryToExecute = compositeFilter
16
31
  ? query(collectionReference, compositeFilter, ...allQueryConstraints)
17
32
  : query(collectionReference, ...allQueryConstraints);
18
- const querySnapshot = await getDocs(converter ? queryToExecute.withConverter(converter) : queryToExecute);
33
+ const querySnapshot = await getDocs(queryToExecute);
19
34
  const docs = [];
20
35
  if (querySnapshot) {
21
36
  querySnapshot.forEach((doc) => {
@@ -1,7 +1,5 @@
1
1
  import {
2
2
  CollectionReference,
3
- DocumentData,
4
- FirestoreDataConverter,
5
3
  getDocs,
6
4
  query,
7
5
  QueryCompositeFilterConstraint,
@@ -16,12 +14,16 @@ import {
16
14
  UseInfiniteQueryResult,
17
15
  InfiniteData
18
16
  } from "@tanstack/react-query";
17
+ import { QueryFilterConstraint } from "./useCompositeFilter";
18
+ import { AppModel } from "../../types";
19
19
 
20
- type UseInfiniteQueryOptions<
21
- AppModelType extends DocumentData = DocumentData,
22
- DbModelType extends DocumentData = DocumentData,
23
- TQueryKey extends QueryKey = QueryKey
24
- > = {
20
+ /**
21
+ * @inline
22
+ */
23
+ type UseInfiniteQueryOptions<AppModelType extends AppModel = AppModel, TQueryKey extends QueryKey = QueryKey> = {
24
+ /**
25
+ * Reqct-query options that must include queryKey and shall not define queryFn
26
+ */
25
27
  options: Omit<
26
28
  UseReactInfiniteQueryOptions<
27
29
  AppModelType[],
@@ -46,38 +48,64 @@ type UseInfiniteQueryOptions<
46
48
  "queryKey"
47
49
  >
48
50
  >;
49
- collectionReference: CollectionReference<AppModelType, DbModelType>;
51
+
52
+ /**
53
+ * Reference to a Firestore collection
54
+ */
55
+ collectionReference: CollectionReference<AppModelType, AppModelType>;
56
+
57
+ /**
58
+ * Non composite filter constraints such as limit, order, where
59
+ */
50
60
  queryConstraints?: QueryConstraint[] | QueryNonFilterConstraint[];
51
- compositeFilter?: QueryCompositeFilterConstraint;
52
- converter?: FirestoreDataConverter<AppModelType, DbModelType>;
61
+
62
+ /**
63
+ * Composite filter
64
+ */
65
+ compositeFilter?: QueryFilterConstraint;
53
66
  };
54
67
 
55
68
  /**
56
- * Custom hook that creates an infinite query using Firestore, allowing for query constraints, composite filters, and converters.
57
- * It fetches data in pages and can load more as required.
69
+ * Executes an infinite query on a Firestore data source and returns the resulting documents as an array.
70
+ *
71
+ * @group Hook
72
+ *
73
+ * @param {UseInfiniteQueryOptions<AppModelType, TQueryKey>} options - Configuration options for the query.
74
+ *
75
+ * @returns {UseInfiniteQueryResult<InfiniteData<AppModelType[]>>} An object containing documents that match the query.
58
76
  *
59
- * @param {UseInfiniteQueryOptions<AppModelType, DbModelType>} options - Configuration options for the infinite query, including Firestore query reference, query constraints, composite filter, and data converter.
60
- * @returns {UseInfiniteQueryResult<InfiniteData<AppModelType[]>>} Result object containing the infinite data and methods for fetching more pages.
77
+ * @example
78
+ * ```jsx
79
+ * export const MyComponent = () => {
80
+ * const docs = useInfiniteQuery({
81
+ * options: {
82
+ * queryKey: ['key']
83
+ * },
84
+ * collectionReference: collection(),
85
+ * });
86
+ * console.log(docs);
87
+ * };
88
+ * ```
61
89
  */
62
- export const useInfiniteQuery = <
63
- AppModelType extends DocumentData = DocumentData,
64
- DbModelType extends DocumentData = DocumentData
65
- >({
90
+ export const useInfiniteQuery = <AppModelType extends AppModel = AppModel, TQueryKey extends QueryKey = QueryKey>({
66
91
  options,
67
92
  collectionReference,
68
93
  queryConstraints = [],
69
- compositeFilter,
70
- converter
71
- }: UseInfiniteQueryOptions<AppModelType, DbModelType>): UseInfiniteQueryResult<InfiniteData<AppModelType[]>> => {
94
+ compositeFilter
95
+ }: UseInfiniteQueryOptions<AppModelType, TQueryKey>): UseInfiniteQueryResult<InfiniteData<AppModelType[]>> => {
72
96
  return useInfiniteReactQuery({
73
97
  ...options,
74
98
  queryFn: async ({ pageParam }) => {
75
99
  const allQueryConstraints = [...queryConstraints, ...(pageParam ? [pageParam] : [])];
76
100
  const queryToExecute = compositeFilter
77
- ? query(collectionReference, compositeFilter, ...(allQueryConstraints as QueryNonFilterConstraint[]))
101
+ ? query(
102
+ collectionReference,
103
+ compositeFilter as QueryCompositeFilterConstraint,
104
+ ...(allQueryConstraints as QueryNonFilterConstraint[])
105
+ )
78
106
  : query(collectionReference, ...allQueryConstraints);
79
107
 
80
- const querySnapshot = await getDocs(converter ? queryToExecute.withConverter(converter) : queryToExecute);
108
+ const querySnapshot = await getDocs(queryToExecute);
81
109
  const docs: AppModelType[] = [];
82
110
 
83
111
  if (querySnapshot) {
@@ -1,25 +1,49 @@
1
- import { DocumentData, FirestoreDataConverter, CollectionReference, QueryCompositeFilterConstraint, QueryConstraint, QueryNonFilterConstraint } from "firebase/firestore";
1
+ import { CollectionReference, QueryConstraint, QueryNonFilterConstraint } from "firebase/firestore";
2
2
  import { UseQueryResult, UseQueryOptions as UseReactQueryOptions } from "@tanstack/react-query";
3
- type UseQueryOptions<AppModelType extends DocumentData = DocumentData, DbModelType extends DocumentData = DocumentData> = {
3
+ import { QueryFilterConstraint } from "./useCompositeFilter";
4
+ import { AppModel } from "../../types";
5
+ /**
6
+ * @inline
7
+ */
8
+ type UseQueryOptions<AppModelType extends AppModel = AppModel> = {
9
+ /**
10
+ * Reqct-query options that must include queryKey and shall not define queryFn
11
+ */
4
12
  options: Omit<UseReactQueryOptions<AppModelType[], Error, AppModelType[]>, "queryFn"> & Required<Pick<UseReactQueryOptions<AppModelType[], Error, AppModelType[]>, "queryKey">>;
5
- collectionReference: CollectionReference<AppModelType, DbModelType>;
13
+ /**
14
+ * Reference to a Firestore collection
15
+ */
16
+ collectionReference: CollectionReference<AppModelType, AppModelType>;
17
+ /**
18
+ * Non composite filter constraints such as limit, order, where
19
+ */
6
20
  queryConstraints?: QueryConstraint[] | QueryNonFilterConstraint[];
7
- compositeFilter?: QueryCompositeFilterConstraint;
8
- converter?: FirestoreDataConverter<AppModelType, DbModelType>;
21
+ /**
22
+ * Composite filter
23
+ */
24
+ compositeFilter?: QueryFilterConstraint;
9
25
  };
10
26
  /**
11
- * Executes a query on a Firestore-like data source and returns the resulting documents as an array.
27
+ * Executes a query on a Firestore data source and returns the resulting documents as an array.
28
+ *
29
+ * @group Hook
12
30
  *
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.
31
+ * @param {UseQueryOptions<AppModelType>} options - Configuration options for the query.
15
32
  *
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.
33
+ * @returns {UseQueryResult<AppModelType[]>} An object containing documents that match the query.
21
34
  *
22
- * @returns {UseQueryResult<AppModelType[]>} Result containing an array of documents that match the query criteria.
35
+ * @example
36
+ * ```jsx
37
+ * export const MyComponent = () => {
38
+ * const docs = useQuery({
39
+ * options: {
40
+ * queryKey: ['key']
41
+ * },
42
+ * collectionReference: collection(),
43
+ * });
44
+ * console.log(docs);
45
+ * };
46
+ * ```
23
47
  */
24
- export declare const useQuery: <AppModelType extends DocumentData = DocumentData, DbModelType extends DocumentData = DocumentData>({ options, collectionReference, queryConstraints, compositeFilter, converter }: UseQueryOptions<AppModelType, DbModelType>) => UseQueryResult<AppModelType[]>;
48
+ export declare const useQuery: <AppModelType extends AppModel = AppModel>({ options, collectionReference, queryConstraints, compositeFilter }: UseQueryOptions<AppModelType>) => UseQueryResult<AppModelType[]>;
25
49
  export {};
@@ -1,27 +1,35 @@
1
1
  import { getDocs, query } from "firebase/firestore";
2
2
  import { useQuery as useReactQuery } from "@tanstack/react-query";
3
3
  /**
4
- * Executes a query on a Firestore-like data source and returns the resulting documents as an array.
4
+ * Executes a query on a Firestore data source and returns the resulting documents as an array.
5
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.
6
+ * @group Hook
8
7
  *
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.
8
+ * @param {UseQueryOptions<AppModelType>} options - Configuration options for the query.
14
9
  *
15
- * @returns {UseQueryResult<AppModelType[]>} Result containing an array of documents that match the query criteria.
10
+ * @returns {UseQueryResult<AppModelType[]>} An object containing documents that match the query.
11
+ *
12
+ * @example
13
+ * ```jsx
14
+ * export const MyComponent = () => {
15
+ * const docs = useQuery({
16
+ * options: {
17
+ * queryKey: ['key']
18
+ * },
19
+ * collectionReference: collection(),
20
+ * });
21
+ * console.log(docs);
22
+ * };
23
+ * ```
16
24
  */
17
- export const useQuery = ({ options, collectionReference, queryConstraints = [], compositeFilter, converter }) => {
25
+ export const useQuery = ({ options, collectionReference, queryConstraints = [], compositeFilter }) => {
18
26
  return useReactQuery({
19
27
  ...options,
20
28
  queryFn: async () => {
21
29
  const queryToExecute = compositeFilter
22
30
  ? query(collectionReference, compositeFilter, ...queryConstraints)
23
31
  : query(collectionReference, ...queryConstraints);
24
- const querySnapshot = await getDocs(converter ? queryToExecute.withConverter(converter) : queryToExecute);
32
+ const querySnapshot = await getDocs(queryToExecute);
25
33
  const docs = [];
26
34
  if (querySnapshot) {
27
35
  querySnapshot.forEach((doc) => {
@@ -1,6 +1,4 @@
1
1
  import {
2
- DocumentData,
3
- FirestoreDataConverter,
4
2
  getDocs,
5
3
  CollectionReference,
6
4
  query,
@@ -14,51 +12,75 @@ import {
14
12
  useQuery as useReactQuery,
15
13
  UseQueryOptions as UseReactQueryOptions
16
14
  } from "@tanstack/react-query";
15
+ import { QueryFilterConstraint } from "./useCompositeFilter";
16
+ import { AppModel } from "../../types";
17
17
 
18
- type UseQueryOptions<
19
- AppModelType extends DocumentData = DocumentData,
20
- DbModelType extends DocumentData = DocumentData
21
- > = {
18
+ /**
19
+ * @inline
20
+ */
21
+ type UseQueryOptions<AppModelType extends AppModel = AppModel> = {
22
+ /**
23
+ * Reqct-query options that must include queryKey and shall not define queryFn
24
+ */
22
25
  options: Omit<UseReactQueryOptions<AppModelType[], Error, AppModelType[]>, "queryFn"> &
23
26
  Required<Pick<UseReactQueryOptions<AppModelType[], Error, AppModelType[]>, "queryKey">>;
24
- collectionReference: CollectionReference<AppModelType, DbModelType>;
27
+
28
+ /**
29
+ * Reference to a Firestore collection
30
+ */
31
+ collectionReference: CollectionReference<AppModelType, AppModelType>;
32
+
33
+ /**
34
+ * Non composite filter constraints such as limit, order, where
35
+ */
25
36
  queryConstraints?: QueryConstraint[] | QueryNonFilterConstraint[];
26
- compositeFilter?: QueryCompositeFilterConstraint;
27
- converter?: FirestoreDataConverter<AppModelType, DbModelType>;
37
+
38
+ /**
39
+ * Composite filter
40
+ */
41
+ compositeFilter?: QueryFilterConstraint;
28
42
  };
29
43
 
30
44
  /**
31
- * Executes a query on a Firestore-like data source and returns the resulting documents as an array.
45
+ * Executes a query on a Firestore data source and returns the resulting documents as an array.
46
+ *
47
+ * @group Hook
32
48
  *
33
- * This hook utilizes an abstraction over React Query to asynchronously fetch data based on the provided query
34
- * reference and constraints. It supports optional filtering, conversion, and additional query constraints.
49
+ * @param {UseQueryOptions<AppModelType>} options - Configuration options for the query.
35
50
  *
36
- * @param {UseQueryOptions<AppModelType, DbModelType>} options - Configuration options for the query.
37
- * @param {DocumentReference<AppModelType>} queryReference - The reference to the query to be executed.
38
- * @param {QueryConstraint[]} queryConstraints - Additional constraints to fine-tune the query.
39
- * @param {QueryConstraint} compositeFilter - Optional composite filter to apply to the query.
40
- * @param {FirestoreDataConverter<AppModelType>} converter - Optional data converter for transforming snapshots.
51
+ * @returns {UseQueryResult<AppModelType[]>} An object containing documents that match the query.
41
52
  *
42
- * @returns {UseQueryResult<AppModelType[]>} Result containing an array of documents that match the query criteria.
53
+ * @example
54
+ * ```jsx
55
+ * export const MyComponent = () => {
56
+ * const docs = useQuery({
57
+ * options: {
58
+ * queryKey: ['key']
59
+ * },
60
+ * collectionReference: collection(),
61
+ * });
62
+ * console.log(docs);
63
+ * };
64
+ * ```
43
65
  */
44
- export const useQuery = <
45
- AppModelType extends DocumentData = DocumentData,
46
- DbModelType extends DocumentData = DocumentData
47
- >({
66
+ export const useQuery = <AppModelType extends AppModel = AppModel>({
48
67
  options,
49
68
  collectionReference,
50
69
  queryConstraints = [],
51
- compositeFilter,
52
- converter
53
- }: UseQueryOptions<AppModelType, DbModelType>): UseQueryResult<AppModelType[]> => {
70
+ compositeFilter
71
+ }: UseQueryOptions<AppModelType>): UseQueryResult<AppModelType[]> => {
54
72
  return useReactQuery({
55
73
  ...options,
56
74
  queryFn: async () => {
57
75
  const queryToExecute = compositeFilter
58
- ? query(collectionReference, compositeFilter, ...(queryConstraints as QueryNonFilterConstraint[]))
76
+ ? query(
77
+ collectionReference,
78
+ compositeFilter as QueryCompositeFilterConstraint,
79
+ ...(queryConstraints as QueryNonFilterConstraint[])
80
+ )
59
81
  : query(collectionReference, ...queryConstraints);
60
82
 
61
- const querySnapshot = await getDocs(converter ? queryToExecute.withConverter(converter) : queryToExecute);
83
+ const querySnapshot = await getDocs(queryToExecute);
62
84
  const docs: AppModelType[] = [];
63
85
 
64
86
  if (querySnapshot) {