react-query-firebase 2.3.2 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. package/package.json +1 -1
  2. package/react-native/firestore/index.d.ts +5 -0
  3. package/react-native/firestore/index.js +5 -0
  4. package/react-native/firestore/index.ts +5 -0
  5. package/react-native/firestore/useAddDocMutation.d.ts +38 -9
  6. package/react-native/firestore/useAddDocMutation.js +25 -11
  7. package/react-native/firestore/useAddDocMutation.ts +43 -13
  8. package/react-native/firestore/useBatchWrite.d.ts +31 -7
  9. package/react-native/firestore/useBatchWrite.js +22 -4
  10. package/react-native/firestore/useBatchWrite.ts +31 -7
  11. package/react-native/firestore/useCollectionReference.d.ts +30 -9
  12. package/react-native/firestore/useCollectionReference.js +15 -7
  13. package/react-native/firestore/useCollectionReference.ts +34 -25
  14. package/react-native/firestore/useCompositeFilter.d.ts +1 -46
  15. package/react-native/firestore/useCompositeFilter.js +2 -45
  16. package/react-native/firestore/useCompositeFilter.ts +2 -74
  17. package/react-native/firestore/useCountQuery.d.ts +1 -1
  18. package/react-native/firestore/useCountQuery.ts +1 -1
  19. package/react-native/firestore/useDeleteDocMutation.d.ts +39 -10
  20. package/react-native/firestore/useDeleteDocMutation.js +22 -5
  21. package/react-native/firestore/useDeleteDocMutation.ts +38 -15
  22. package/react-native/firestore/useDocReference.d.ts +22 -14
  23. package/react-native/firestore/useDocReference.js +20 -26
  24. package/react-native/firestore/useDocReference.ts +34 -47
  25. package/react-native/firestore/useDocReferences.d.ts +23 -18
  26. package/react-native/firestore/useDocReferences.js +18 -19
  27. package/react-native/firestore/useDocReferences.ts +26 -34
  28. package/react-native/firestore/useFirestore.d.ts +4 -3
  29. package/react-native/firestore/useFirestore.js +4 -3
  30. package/react-native/firestore/useFirestore.ts +4 -3
  31. package/react-native/firestore/useGetDocData.d.ts +33 -14
  32. package/react-native/firestore/useGetDocData.js +21 -6
  33. package/react-native/firestore/useGetDocData.ts +34 -22
  34. package/react-native/firestore/useInfiniteQuery.d.ts +2 -2
  35. package/react-native/firestore/useInfiniteQuery.ts +3 -3
  36. package/react-native/firestore/useQuery.d.ts +1 -1
  37. package/react-native/firestore/useQuery.ts +1 -1
  38. package/react-native/firestore/useQueryConstraints.d.ts +2 -22
  39. package/react-native/firestore/useQueryConstraints.js +1 -39
  40. package/react-native/firestore/useQueryConstraints.ts +3 -43
  41. package/react-native/firestore/useRunTransaction.d.ts +33 -9
  42. package/react-native/firestore/useRunTransaction.js +20 -4
  43. package/react-native/firestore/useRunTransaction.ts +35 -16
  44. package/react-native/firestore/useSetDocMutation.d.ts +43 -11
  45. package/react-native/firestore/useSetDocMutation.js +28 -11
  46. package/react-native/firestore/useSetDocMutation.ts +49 -28
  47. package/react-native/firestore/useUpdateDocMutation.d.ts +40 -18
  48. package/react-native/firestore/useUpdateDocMutation.js +18 -13
  49. package/react-native/firestore/useUpdateDocMutation.ts +40 -31
  50. package/react-native/firestore/utils/buildCompositeFilter.d.ts +47 -0
  51. package/react-native/firestore/utils/buildCompositeFilter.js +45 -0
  52. package/react-native/firestore/utils/buildCompositeFilter.ts +75 -0
  53. package/react-native/firestore/utils/buildQueryConstraint.d.ts +23 -0
  54. package/react-native/firestore/utils/buildQueryConstraint.js +41 -0
  55. package/react-native/firestore/utils/buildQueryConstraint.ts +54 -0
  56. package/react-native/firestore/utils/getDocData.d.ts +11 -11
  57. package/react-native/firestore/utils/getDocData.js +5 -8
  58. package/react-native/firestore/utils/getDocData.ts +12 -16
  59. package/react-native/firestore/utils/getDocRef.d.ts +12 -9
  60. package/react-native/firestore/utils/getDocRef.js +7 -8
  61. package/react-native/firestore/utils/getDocRef.ts +12 -13
  62. package/react-native/firestore/utils/getDocSnap.d.ts +11 -13
  63. package/react-native/firestore/utils/getDocSnap.js +5 -10
  64. package/react-native/firestore/utils/getDocSnap.ts +12 -17
  65. package/types/AppModel.d.ts +4 -1
  66. package/types/AppModel.ts +4 -1
  67. package/web/firestore/index.d.ts +5 -0
  68. package/web/firestore/index.js +5 -0
  69. package/web/firestore/index.ts +5 -0
  70. package/web/firestore/useAddDocMutation.d.ts +41 -13
  71. package/web/firestore/useAddDocMutation.js +27 -14
  72. package/web/firestore/useAddDocMutation.ts +49 -37
  73. package/web/firestore/useBatchWrite.d.ts +34 -7
  74. package/web/firestore/useBatchWrite.js +22 -4
  75. package/web/firestore/useBatchWrite.ts +34 -7
  76. package/web/firestore/useCollectionReference.d.ts +32 -11
  77. package/web/firestore/useCollectionReference.js +15 -7
  78. package/web/firestore/useCollectionReference.ts +34 -13
  79. package/web/firestore/useCompositeFilter.d.ts +2 -47
  80. package/web/firestore/useCompositeFilter.js +2 -42
  81. package/web/firestore/useCompositeFilter.ts +2 -72
  82. package/web/firestore/useCountQuery.d.ts +4 -4
  83. package/web/firestore/useCountQuery.ts +5 -5
  84. package/web/firestore/useDeleteDocMutation.d.ts +41 -11
  85. package/web/firestore/useDeleteDocMutation.js +24 -7
  86. package/web/firestore/useDeleteDocMutation.ts +45 -23
  87. package/web/firestore/useDocReference.d.ts +23 -15
  88. package/web/firestore/useDocReference.js +16 -31
  89. package/web/firestore/useDocReference.ts +28 -46
  90. package/web/firestore/useDocReferences.d.ts +23 -18
  91. package/web/firestore/useDocReferences.js +18 -21
  92. package/web/firestore/useDocReferences.ts +26 -30
  93. package/web/firestore/useFirestore.d.ts +4 -3
  94. package/web/firestore/useFirestore.js +4 -3
  95. package/web/firestore/useFirestore.ts +4 -3
  96. package/web/firestore/useGetDocData.d.ts +32 -13
  97. package/web/firestore/useGetDocData.js +21 -6
  98. package/web/firestore/useGetDocData.ts +34 -23
  99. package/web/firestore/useGetRealtimeDocData.js +2 -2
  100. package/web/firestore/useGetRealtimeDocData.ts +2 -2
  101. package/web/firestore/useInfiniteQuery.d.ts +2 -2
  102. package/web/firestore/useInfiniteQuery.js +1 -1
  103. package/web/firestore/useInfiniteQuery.ts +4 -4
  104. package/web/firestore/useQuery.d.ts +1 -1
  105. package/web/firestore/useQuery.js +1 -1
  106. package/web/firestore/useQuery.ts +2 -2
  107. package/web/firestore/useQueryConstraints.d.ts +0 -21
  108. package/web/firestore/useQueryConstraints.js +1 -39
  109. package/web/firestore/useQueryConstraints.ts +2 -51
  110. package/web/firestore/useRunTransaction.d.ts +33 -8
  111. package/web/firestore/useRunTransaction.js +20 -4
  112. package/web/firestore/useRunTransaction.ts +35 -10
  113. package/web/firestore/useSetDocMutation.d.ts +45 -12
  114. package/web/firestore/useSetDocMutation.js +28 -11
  115. package/web/firestore/useSetDocMutation.ts +51 -26
  116. package/web/firestore/useUpdateDocMutation.d.ts +42 -20
  117. package/web/firestore/useUpdateDocMutation.js +20 -15
  118. package/web/firestore/useUpdateDocMutation.ts +45 -41
  119. package/web/firestore/utils/buildCompositeFilter.d.ts +47 -0
  120. package/web/firestore/utils/buildCompositeFilter.js +42 -0
  121. package/web/firestore/utils/buildCompositeFilter.ts +73 -0
  122. package/web/firestore/utils/buildQueryConstraint.d.ts +23 -0
  123. package/web/firestore/utils/buildQueryConstraint.js +41 -0
  124. package/web/firestore/utils/buildQueryConstraint.ts +55 -0
  125. package/web/firestore/utils/getDocData.d.ts +13 -11
  126. package/web/firestore/utils/getDocData.js +6 -9
  127. package/web/firestore/utils/getDocData.ts +14 -20
  128. package/web/firestore/utils/getDocRef.d.ts +14 -11
  129. package/web/firestore/utils/getDocRef.js +7 -8
  130. package/web/firestore/utils/getDocRef.ts +16 -19
  131. package/web/firestore/utils/getDocSnap.d.ts +11 -13
  132. package/web/firestore/utils/getDocSnap.js +5 -10
  133. package/web/firestore/utils/getDocSnap.ts +14 -21
@@ -0,0 +1,41 @@
1
+ import { orderBy, startAt, startAfter, endAt, endBefore, limit, limitToLast } from "firebase/firestore";
2
+ /**
3
+ * A generic mothod to build query constraints for firebase
4
+ *
5
+ * @group Utility
6
+ *
7
+ * @param {NonFilterQueryConstraint<AppModelType>} constraint
8
+ *
9
+ * @returns {QueryNonFilterConstraint}
10
+ *
11
+ * @example
12
+ * ```jsx
13
+ * const firebaseConfig = {};
14
+ * export const constraint = useMemo(() => {
15
+ * return buildQueryConstraint({
16
+ * type: 'limit',
17
+ * limit: 1
18
+ * });
19
+ * };
20
+ * ```
21
+ */
22
+ export const buildQueryConstraint = (constraint) => {
23
+ switch (constraint.type) {
24
+ case "orderBy":
25
+ return orderBy(constraint.fieldPath, constraint.directionStr);
26
+ case "startAt":
27
+ return startAt(...constraint.arguments);
28
+ case "startAfter":
29
+ return startAfter(...constraint.arguments);
30
+ case "endAt":
31
+ return endAt(constraint.value, constraint.key);
32
+ case "endBefore":
33
+ return endBefore(constraint.value, constraint.key);
34
+ case "limit":
35
+ return limit(constraint.limit);
36
+ case "limitToLast":
37
+ return limitToLast(constraint.limit);
38
+ default:
39
+ throw new Error(`Unsupported constaint ${JSON.stringify(constraint)}`);
40
+ }
41
+ };
@@ -0,0 +1,55 @@
1
+ import {
2
+ QueryNonFilterConstraint,
3
+ orderBy,
4
+ startAt,
5
+ startAfter,
6
+ endAt,
7
+ endBefore,
8
+ limit,
9
+ limitToLast
10
+ } from "firebase/firestore";
11
+ import { AppModel, NonFilterQueryConstraint } from "../../../types";
12
+
13
+ /**
14
+ * A generic mothod to build query constraints for firebase
15
+ *
16
+ * @group Utility
17
+ *
18
+ * @param {NonFilterQueryConstraint<AppModelType>} constraint
19
+ *
20
+ * @returns {QueryNonFilterConstraint}
21
+ *
22
+ * @example
23
+ * ```jsx
24
+ * const firebaseConfig = {};
25
+ * export const constraint = useMemo(() => {
26
+ * return buildQueryConstraint({
27
+ * type: 'limit',
28
+ * limit: 1
29
+ * });
30
+ * };
31
+ * ```
32
+ */
33
+
34
+ export const buildQueryConstraint = <AppModelType extends AppModel = AppModel>(
35
+ constraint: NonFilterQueryConstraint<AppModelType>
36
+ ): QueryNonFilterConstraint => {
37
+ switch (constraint.type) {
38
+ case "orderBy":
39
+ return orderBy(constraint.fieldPath as string, constraint.directionStr);
40
+ case "startAt":
41
+ return startAt(...constraint.arguments);
42
+ case "startAfter":
43
+ return startAfter(...constraint.arguments);
44
+ case "endAt":
45
+ return endAt(constraint.value, constraint.key);
46
+ case "endBefore":
47
+ return endBefore(constraint.value, constraint.key);
48
+ case "limit":
49
+ return limit(constraint.limit);
50
+ case "limitToLast":
51
+ return limitToLast(constraint.limit);
52
+ default:
53
+ throw new Error(`Unsupported constaint ${JSON.stringify(constraint)}`);
54
+ }
55
+ };
@@ -1,18 +1,20 @@
1
- import { DocumentData } from "firebase/firestore";
2
1
  import { GetDocSnapOptions } from "./getDocSnap";
3
- export type GetDocDataOptions<AppModelType extends DocumentData = DocumentData, DbModelType extends DocumentData = DocumentData> = GetDocSnapOptions<AppModelType, DbModelType>;
2
+ import { AppModel } from "../../../types";
4
3
  /**
5
- * Asynchronously retrieves document data from a specified database and reference.
4
+ * @inline
5
+ */
6
+ export type GetDocDataOptions<AppModelType extends AppModel = AppModel> = GetDocSnapOptions<AppModelType>;
7
+ /**
8
+ * Asynchronously retrieves document data from a specified database reference.
6
9
  * Utilizes the helper function `getDocSnap` to fetch the document snapshot and
7
10
  * checks if the document exists before returning its data.
8
11
  *
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.
12
+ * @group Utility
13
+ *
14
+ * @param {GetDocDataOptions<AppModelType>} options - The options for fetching document data.
14
15
  *
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.
16
+ * @returns {Promise<AppModelType | null>} Returns a promise that resolves to the document data if it exists, or null if the document does not exist.
17
17
  */
18
- export declare const getDocData: <AppModelType extends DocumentData = DocumentData, DbModelType extends DocumentData = DocumentData>({ db, reference, path, pathSegments }: GetDocDataOptions<AppModelType, DbModelType>) => Promise<AppModelType | null>;
18
+ export declare const getDocData: <AppModelType extends AppModel = AppModel>({ db, reference, path, pathSegments }: GetDocDataOptions<AppModelType>) => Promise<(AppModelType & {
19
+ uid: string;
20
+ }) | null>;
@@ -1,22 +1,19 @@
1
1
  import { getDocSnap } from "./getDocSnap";
2
2
  /**
3
- * Asynchronously retrieves document data from a specified database and reference.
3
+ * Asynchronously retrieves document data from a specified database reference.
4
4
  * Utilizes the helper function `getDocSnap` to fetch the document snapshot and
5
5
  * checks if the document exists before returning its data.
6
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.
7
+ * @group Utility
12
8
  *
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.
9
+ * @param {GetDocDataOptions<AppModelType>} options - The options for fetching document data.
10
+ *
11
+ * @returns {Promise<AppModelType | null>} Returns a promise that resolves to the document data if it exists, or null if the document does not exist.
15
12
  */
16
13
  export const getDocData = async ({ db, reference, path, pathSegments }) => {
17
14
  const docSnap = await getDocSnap({ db, reference, path, pathSegments });
18
15
  if (docSnap && docSnap.exists()) {
19
- return docSnap.data();
16
+ return { ...docSnap.data(), uid: docSnap.id };
20
17
  }
21
18
  return null;
22
19
  };
@@ -1,38 +1,32 @@
1
- import { DocumentData } from "firebase/firestore";
2
1
  import { getDocSnap, GetDocSnapOptions } from "./getDocSnap";
2
+ import { AppModel } from "../../../types";
3
3
 
4
- export type GetDocDataOptions<
5
- AppModelType extends DocumentData = DocumentData,
6
- DbModelType extends DocumentData = DocumentData
7
- > = GetDocSnapOptions<AppModelType, DbModelType>;
4
+ /**
5
+ * @inline
6
+ */
7
+ export type GetDocDataOptions<AppModelType extends AppModel = AppModel> = GetDocSnapOptions<AppModelType>;
8
8
 
9
9
  /**
10
- * Asynchronously retrieves document data from a specified database and reference.
10
+ * Asynchronously retrieves document data from a specified database reference.
11
11
  * Utilizes the helper function `getDocSnap` to fetch the document snapshot and
12
12
  * checks if the document exists before returning its data.
13
13
  *
14
- * @param {Object} options - The options for fetching document data.
15
- * @param {FirebaseFirestore} options.db - The Firestore database instance.
16
- * @param {DocumentReference=} options.reference - The document reference. This is an optional parameter.
17
- * @param {string=} options.path - The path to the document in the database. This is an optional parameter.
18
- * @param {Array<string>=} options.pathSegments - The path segments for the document's path. This is an optional parameter.
14
+ * @group Utility
15
+ *
16
+ * @param {GetDocDataOptions<AppModelType>} options - The options for fetching document data.
19
17
  *
20
- * @returns {Promise<AppModelType | null>} Returns a promise that resolves to the document data if it exists,
21
- * or null if the document does not exist.
18
+ * @returns {Promise<AppModelType | null>} Returns a promise that resolves to the document data if it exists, or null if the document does not exist.
22
19
  */
23
- export const getDocData = async <
24
- AppModelType extends DocumentData = DocumentData,
25
- DbModelType extends DocumentData = DocumentData
26
- >({
20
+ export const getDocData = async <AppModelType extends AppModel = AppModel>({
27
21
  db,
28
22
  reference,
29
23
  path,
30
24
  pathSegments
31
- }: GetDocDataOptions<AppModelType, DbModelType>) => {
32
- const docSnap = await getDocSnap<AppModelType, DbModelType>({ db, reference, path, pathSegments });
25
+ }: GetDocDataOptions<AppModelType>) => {
26
+ const docSnap = await getDocSnap<AppModelType>({ db, reference, path, pathSegments });
33
27
 
34
28
  if (docSnap && docSnap.exists()) {
35
- return docSnap.data();
29
+ return { ...docSnap.data(), uid: docSnap.id };
36
30
  }
37
31
 
38
32
  return null;
@@ -1,19 +1,22 @@
1
- import { CollectionReference, DocumentData, DocumentReference, Firestore } from "firebase/firestore";
2
- export type GetDocRefOptions<AppModelType extends DocumentData = DocumentData, DbModelType extends DocumentData = DocumentData> = {
1
+ import { CollectionReference, DocumentReference, Firestore } from "firebase/firestore";
2
+ import { AppModel } from "../../../types";
3
+ /**
4
+ * @inline
5
+ */
6
+ export type GetDocRefOptions<AppModelType extends AppModel = AppModel> = {
3
7
  db: Firestore;
4
- reference?: CollectionReference<AppModelType, DbModelType> | DocumentReference<AppModelType, DbModelType>;
8
+ reference?: CollectionReference<AppModelType, AppModelType> | DocumentReference<AppModelType, AppModelType>;
5
9
  path?: string;
6
10
  pathSegments?: string[];
7
11
  };
8
12
  /**
9
13
  * Retrieves a document reference based on provided database options.
10
- * Either `reference` or `path` must be provided, not both.
14
+ * Either `reference` or `path`.
15
+ *
16
+ * @group Utility
17
+ *
18
+ * @param {GetDocRefOptions<AppModelType>} options - The options for building doc reference.
11
19
  *
12
- * @param {Object} options - The options for getting a document reference.
13
- * @param {Firestore} options.db - The Firestore database instance.
14
- * @param {DocumentReference | 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 {DocumentReference<AppModelType, DbModelType>} The document reference.
20
+ * @returns {DocumentReference<AppModelType, AppModelType>} Returns a document reference
18
21
  */
19
- export declare const getDocRef: <AppModelType extends DocumentData = DocumentData, DbModelType extends DocumentData = DocumentData>({ db, reference, path, pathSegments }: GetDocRefOptions<AppModelType, DbModelType>) => Promise<DocumentReference<AppModelType, DbModelType>>;
22
+ export declare const getDocRef: <AppModelType extends AppModel = AppModel>({ db, reference, path, pathSegments }: GetDocRefOptions<AppModelType>) => DocumentReference<AppModelType, AppModelType>;
@@ -1,16 +1,15 @@
1
1
  import { doc } from "firebase/firestore";
2
2
  /**
3
3
  * Retrieves a document reference based on provided database options.
4
- * Either `reference` or `path` must be provided, not both.
4
+ * Either `reference` or `path`.
5
5
  *
6
- * @param {Object} options - The options for getting a document reference.
7
- * @param {Firestore} options.db - The Firestore database instance.
8
- * @param {DocumentReference | CollectionReference | null} [options.reference] - Reference to a document or collection.
9
- * @param {string | null} [options.path] - Path to the document.
10
- * @param {string[] | null} [options.pathSegments] - Additional path segments if any.
11
- * @returns {DocumentReference<AppModelType, DbModelType>} The document reference.
6
+ * @group Utility
7
+ *
8
+ * @param {GetDocRefOptions<AppModelType>} options - The options for building doc reference.
9
+ *
10
+ * @returns {DocumentReference<AppModelType, AppModelType>} Returns a document reference
12
11
  */
13
- export const getDocRef = async ({ db, reference, path, pathSegments }) => {
12
+ export const getDocRef = ({ db, reference, path, pathSegments }) => {
14
13
  if (!reference && !path) {
15
14
  throw new Error("One of the options must be provided: path or reference.");
16
15
  }
@@ -1,35 +1,32 @@
1
- import { CollectionReference, doc, DocumentData, DocumentReference, Firestore } from "firebase/firestore";
1
+ import { CollectionReference, doc, DocumentReference, Firestore } from "firebase/firestore";
2
+ import { AppModel } from "../../../types";
2
3
 
3
- export type GetDocRefOptions<
4
- AppModelType extends DocumentData = DocumentData,
5
- DbModelType extends DocumentData = DocumentData
6
- > = {
4
+ /**
5
+ * @inline
6
+ */
7
+ export type GetDocRefOptions<AppModelType extends AppModel = AppModel> = {
7
8
  db: Firestore;
8
- reference?: CollectionReference<AppModelType, DbModelType> | DocumentReference<AppModelType, DbModelType>;
9
+ reference?: CollectionReference<AppModelType, AppModelType> | DocumentReference<AppModelType, AppModelType>;
9
10
  path?: string;
10
11
  pathSegments?: string[];
11
12
  };
12
13
 
13
14
  /**
14
15
  * Retrieves a document reference based on provided database options.
15
- * Either `reference` or `path` must be provided, not both.
16
+ * Either `reference` or `path`.
17
+ *
18
+ * @group Utility
19
+ *
20
+ * @param {GetDocRefOptions<AppModelType>} options - The options for building doc reference.
16
21
  *
17
- * @param {Object} options - The options for getting a document reference.
18
- * @param {Firestore} options.db - The Firestore database instance.
19
- * @param {DocumentReference | CollectionReference | null} [options.reference] - Reference to a document or collection.
20
- * @param {string | null} [options.path] - Path to the document.
21
- * @param {string[] | null} [options.pathSegments] - Additional path segments if any.
22
- * @returns {DocumentReference<AppModelType, DbModelType>} The document reference.
22
+ * @returns {DocumentReference<AppModelType, AppModelType>} Returns a document reference
23
23
  */
24
- export const getDocRef = async <
25
- AppModelType extends DocumentData = DocumentData,
26
- DbModelType extends DocumentData = DocumentData
27
- >({
24
+ export const getDocRef = <AppModelType extends AppModel = AppModel>({
28
25
  db,
29
26
  reference,
30
27
  path,
31
28
  pathSegments
32
- }: GetDocRefOptions<AppModelType, DbModelType>) => {
29
+ }: GetDocRefOptions<AppModelType>) => {
33
30
  if (!reference && !path) {
34
31
  throw new Error("One of the options must be provided: path or reference.");
35
32
  }
@@ -42,5 +39,5 @@ export const getDocRef = async <
42
39
  ? doc(reference, path as string, ...(pathSegments || []))
43
40
  : null;
44
41
 
45
- return docRef as DocumentReference<AppModelType, DbModelType>;
42
+ return docRef as DocumentReference<AppModelType, AppModelType>;
46
43
  };
@@ -1,20 +1,18 @@
1
- import { DocumentData } from "firebase/firestore";
2
1
  import { GetDocRefOptions } from "./getDocRef";
3
- export type GetDocSnapOptions<AppModelType extends DocumentData = DocumentData, DbModelType extends DocumentData = DocumentData> = GetDocRefOptions<AppModelType, DbModelType>;
2
+ import { AppModel } from "../../../types";
3
+ /**
4
+ * @inline
5
+ */
6
+ export type GetDocSnapOptions<AppModelType extends AppModel = AppModel> = GetDocRefOptions<AppModelType>;
4
7
  /**
5
8
  * Asynchronously retrieves a document snapshot from Firestore using a specified document reference
6
9
  * or path information. This function handles getting the appropriate document reference based on
7
10
  * the parameters provided, and then fetches the document data from Firestore.
8
11
  *
9
- * @param {GetDocSnapOptions<AppModelType, DbModelType>} options - An object containing options
10
- * for retrieving the document
11
- * snapshot.
12
- * @param {DocumentData} options.db - The Firestore database instance to perform the operation on.
13
- * @param {string} options.reference - A string representing a direct Firestore document reference.
14
- * @param {string} options.path - A Firestore path string leading to the document.
15
- * @param {string[]} options.pathSegments - An array of path segments to build the Firestore path.
16
- * @returns {Promise<DocumentData | null>} A promise that resolves to the document data if the
17
- * document exists, or `null` if the document does not exist
18
- * or if the reference could not be obtained.
12
+ * @group Utility
13
+ *
14
+ * @param {GetDocSnapOptions<AppModelType>} options - The options for retrieving the document snapshot
15
+ *
16
+ * @returns {Promise<DocumentSnapshot<AppModelType, AppModelType> | null>} Returns a document reference
19
17
  */
20
- export declare const getDocSnap: <AppModelType extends DocumentData = DocumentData, DbModelType extends DocumentData = DocumentData>({ db, reference, path, pathSegments }: GetDocSnapOptions<AppModelType, DbModelType>) => Promise<import("@firebase/firestore").DocumentSnapshot<AppModelType, DbModelType> | null>;
18
+ export declare const getDocSnap: <AppModelType extends AppModel = AppModel>({ db, reference, path, pathSegments }: GetDocSnapOptions<AppModelType>) => Promise<import("@firebase/firestore").DocumentSnapshot<AppModelType, AppModelType> | null>;
@@ -5,16 +5,11 @@ import { getDocRef } from "./getDocRef";
5
5
  * or path information. This function handles getting the appropriate document reference based on
6
6
  * the parameters provided, and then fetches the document data from Firestore.
7
7
  *
8
- * @param {GetDocSnapOptions<AppModelType, DbModelType>} options - An object containing options
9
- * for retrieving the document
10
- * snapshot.
11
- * @param {DocumentData} options.db - The Firestore database instance to perform the operation on.
12
- * @param {string} options.reference - A string representing a direct Firestore document reference.
13
- * @param {string} options.path - A Firestore path string leading to the document.
14
- * @param {string[]} options.pathSegments - An array of path segments to build the Firestore path.
15
- * @returns {Promise<DocumentData | null>} A promise that resolves to the document data if the
16
- * document exists, or `null` if the document does not exist
17
- * or if the reference could not be obtained.
8
+ * @group Utility
9
+ *
10
+ * @param {GetDocSnapOptions<AppModelType>} options - The options for retrieving the document snapshot
11
+ *
12
+ * @returns {Promise<DocumentSnapshot<AppModelType, AppModelType> | null>} Returns a document reference
18
13
  */
19
14
  export const getDocSnap = async ({ db, reference, path, pathSegments }) => {
20
15
  const docRef = await getDocRef({ db, reference, path, pathSegments });
@@ -1,37 +1,30 @@
1
- import { DocumentData, getDoc as firestoreGetDoc } from "firebase/firestore";
1
+ import { getDoc as firestoreGetDoc } from "firebase/firestore";
2
2
  import { getDocRef, GetDocRefOptions } from "./getDocRef";
3
+ import { AppModel } from "../../../types";
3
4
 
4
- export type GetDocSnapOptions<
5
- AppModelType extends DocumentData = DocumentData,
6
- DbModelType extends DocumentData = DocumentData
7
- > = GetDocRefOptions<AppModelType, DbModelType>;
5
+ /**
6
+ * @inline
7
+ */
8
+ export type GetDocSnapOptions<AppModelType extends AppModel = AppModel> = GetDocRefOptions<AppModelType>;
8
9
 
9
10
  /**
10
11
  * Asynchronously retrieves a document snapshot from Firestore using a specified document reference
11
12
  * or path information. This function handles getting the appropriate document reference based on
12
13
  * the parameters provided, and then fetches the document data from Firestore.
13
14
  *
14
- * @param {GetDocSnapOptions<AppModelType, DbModelType>} options - An object containing options
15
- * for retrieving the document
16
- * snapshot.
17
- * @param {DocumentData} options.db - The Firestore database instance to perform the operation on.
18
- * @param {string} options.reference - A string representing a direct Firestore document reference.
19
- * @param {string} options.path - A Firestore path string leading to the document.
20
- * @param {string[]} options.pathSegments - An array of path segments to build the Firestore path.
21
- * @returns {Promise<DocumentData | null>} A promise that resolves to the document data if the
22
- * document exists, or `null` if the document does not exist
23
- * or if the reference could not be obtained.
15
+ * @group Utility
16
+ *
17
+ * @param {GetDocSnapOptions<AppModelType>} options - The options for retrieving the document snapshot
18
+ *
19
+ * @returns {Promise<DocumentSnapshot<AppModelType, AppModelType> | null>} Returns a document reference
24
20
  */
25
- export const getDocSnap = async <
26
- AppModelType extends DocumentData = DocumentData,
27
- DbModelType extends DocumentData = DocumentData
28
- >({
21
+ export const getDocSnap = async <AppModelType extends AppModel = AppModel>({
29
22
  db,
30
23
  reference,
31
24
  path,
32
25
  pathSegments
33
- }: GetDocSnapOptions<AppModelType, DbModelType>) => {
34
- const docRef = await getDocRef<AppModelType, DbModelType>({ db, reference, path, pathSegments });
26
+ }: GetDocSnapOptions<AppModelType>) => {
27
+ const docRef = await getDocRef<AppModelType>({ db, reference, path, pathSegments });
35
28
 
36
29
  if (docRef) {
37
30
  return await firestoreGetDoc(docRef);