react-query-firebase 2.3.3 → 2.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/react-native/firestore/index.d.ts +5 -0
- package/react-native/firestore/index.js +5 -0
- package/react-native/firestore/index.ts +5 -0
- package/react-native/firestore/useAddDocMutation.d.ts +38 -9
- package/react-native/firestore/useAddDocMutation.js +25 -11
- package/react-native/firestore/useAddDocMutation.ts +43 -13
- package/react-native/firestore/useBatchWrite.d.ts +31 -7
- package/react-native/firestore/useBatchWrite.js +22 -4
- package/react-native/firestore/useBatchWrite.ts +31 -7
- package/react-native/firestore/useCollectionReference.d.ts +30 -9
- package/react-native/firestore/useCollectionReference.js +15 -7
- package/react-native/firestore/useCollectionReference.ts +34 -25
- package/react-native/firestore/useCompositeFilter.d.ts +1 -46
- package/react-native/firestore/useCompositeFilter.js +2 -45
- package/react-native/firestore/useCompositeFilter.ts +2 -74
- package/react-native/firestore/useCountQuery.d.ts +1 -1
- package/react-native/firestore/useCountQuery.ts +1 -1
- package/react-native/firestore/useDeleteDocMutation.d.ts +39 -10
- package/react-native/firestore/useDeleteDocMutation.js +22 -5
- package/react-native/firestore/useDeleteDocMutation.ts +38 -15
- package/react-native/firestore/useDocReference.d.ts +22 -14
- package/react-native/firestore/useDocReference.js +20 -26
- package/react-native/firestore/useDocReference.ts +34 -47
- package/react-native/firestore/useDocReferences.d.ts +23 -18
- package/react-native/firestore/useDocReferences.js +18 -19
- package/react-native/firestore/useDocReferences.ts +26 -34
- package/react-native/firestore/useFirestore.d.ts +4 -3
- package/react-native/firestore/useFirestore.js +4 -3
- package/react-native/firestore/useFirestore.ts +4 -3
- package/react-native/firestore/useGetDocData.d.ts +33 -14
- package/react-native/firestore/useGetDocData.js +21 -6
- package/react-native/firestore/useGetDocData.ts +34 -22
- package/react-native/firestore/useInfiniteQuery.d.ts +1 -1
- package/react-native/firestore/useInfiniteQuery.ts +1 -1
- package/react-native/firestore/useQuery.d.ts +1 -1
- package/react-native/firestore/useQuery.ts +1 -1
- package/react-native/firestore/useQueryConstraints.d.ts +0 -21
- package/react-native/firestore/useQueryConstraints.js +1 -39
- package/react-native/firestore/useQueryConstraints.ts +2 -51
- package/react-native/firestore/useRunTransaction.d.ts +33 -9
- package/react-native/firestore/useRunTransaction.js +20 -4
- package/react-native/firestore/useRunTransaction.ts +35 -16
- package/react-native/firestore/useSetDocMutation.d.ts +43 -11
- package/react-native/firestore/useSetDocMutation.js +28 -11
- package/react-native/firestore/useSetDocMutation.ts +49 -28
- package/react-native/firestore/useUpdateDocMutation.d.ts +40 -18
- package/react-native/firestore/useUpdateDocMutation.js +18 -13
- package/react-native/firestore/useUpdateDocMutation.ts +40 -31
- package/react-native/firestore/utils/buildCompositeFilter.d.ts +47 -0
- package/react-native/firestore/utils/buildCompositeFilter.js +45 -0
- package/react-native/firestore/utils/buildCompositeFilter.ts +75 -0
- package/react-native/firestore/utils/buildQueryConstraint.d.ts +23 -0
- package/react-native/firestore/utils/buildQueryConstraint.js +41 -0
- package/react-native/firestore/utils/buildQueryConstraint.ts +54 -0
- package/react-native/firestore/utils/getDocData.d.ts +11 -11
- package/react-native/firestore/utils/getDocData.js +5 -8
- package/react-native/firestore/utils/getDocData.ts +12 -16
- package/react-native/firestore/utils/getDocRef.d.ts +12 -9
- package/react-native/firestore/utils/getDocRef.js +9 -10
- package/react-native/firestore/utils/getDocRef.ts +14 -15
- package/react-native/firestore/utils/getDocSnap.d.ts +11 -13
- package/react-native/firestore/utils/getDocSnap.js +5 -10
- package/react-native/firestore/utils/getDocSnap.ts +12 -17
- package/types/AppModel.d.ts +4 -1
- package/types/AppModel.ts +4 -1
- package/web/firestore/index.d.ts +5 -0
- package/web/firestore/index.js +5 -0
- package/web/firestore/index.ts +5 -0
- package/web/firestore/useAddDocMutation.d.ts +41 -13
- package/web/firestore/useAddDocMutation.js +27 -14
- package/web/firestore/useAddDocMutation.ts +49 -37
- package/web/firestore/useBatchWrite.d.ts +34 -7
- package/web/firestore/useBatchWrite.js +22 -4
- package/web/firestore/useBatchWrite.ts +34 -7
- package/web/firestore/useCollectionReference.d.ts +32 -11
- package/web/firestore/useCollectionReference.js +15 -7
- package/web/firestore/useCollectionReference.ts +34 -13
- package/web/firestore/useCompositeFilter.d.ts +2 -47
- package/web/firestore/useCompositeFilter.js +2 -42
- package/web/firestore/useCompositeFilter.ts +2 -72
- package/web/firestore/useCountQuery.d.ts +4 -4
- package/web/firestore/useCountQuery.ts +5 -5
- package/web/firestore/useDeleteDocMutation.d.ts +41 -11
- package/web/firestore/useDeleteDocMutation.js +24 -7
- package/web/firestore/useDeleteDocMutation.ts +45 -23
- package/web/firestore/useDocReference.d.ts +23 -15
- package/web/firestore/useDocReference.js +16 -31
- package/web/firestore/useDocReference.ts +28 -46
- package/web/firestore/useDocReferences.d.ts +23 -18
- package/web/firestore/useDocReferences.js +18 -21
- package/web/firestore/useDocReferences.ts +26 -30
- package/web/firestore/useFirestore.d.ts +4 -3
- package/web/firestore/useFirestore.js +4 -3
- package/web/firestore/useFirestore.ts +4 -3
- package/web/firestore/useGetDocData.d.ts +32 -13
- package/web/firestore/useGetDocData.js +21 -6
- package/web/firestore/useGetDocData.ts +34 -23
- package/web/firestore/useGetRealtimeDocData.js +2 -2
- package/web/firestore/useGetRealtimeDocData.ts +2 -2
- package/web/firestore/useInfiniteQuery.d.ts +1 -1
- package/web/firestore/useInfiniteQuery.js +1 -1
- package/web/firestore/useInfiniteQuery.ts +2 -2
- package/web/firestore/useQuery.d.ts +1 -1
- package/web/firestore/useQuery.js +1 -1
- package/web/firestore/useQuery.ts +2 -2
- package/web/firestore/useQueryConstraints.d.ts +0 -21
- package/web/firestore/useQueryConstraints.js +1 -39
- package/web/firestore/useQueryConstraints.ts +2 -51
- package/web/firestore/useRunTransaction.d.ts +33 -8
- package/web/firestore/useRunTransaction.js +20 -4
- package/web/firestore/useRunTransaction.ts +35 -10
- package/web/firestore/useSetDocMutation.d.ts +45 -12
- package/web/firestore/useSetDocMutation.js +28 -11
- package/web/firestore/useSetDocMutation.ts +51 -26
- package/web/firestore/useUpdateDocMutation.d.ts +42 -20
- package/web/firestore/useUpdateDocMutation.js +20 -15
- package/web/firestore/useUpdateDocMutation.ts +45 -41
- package/web/firestore/utils/buildCompositeFilter.d.ts +47 -0
- package/web/firestore/utils/buildCompositeFilter.js +42 -0
- package/web/firestore/utils/buildCompositeFilter.ts +73 -0
- package/web/firestore/utils/buildQueryConstraint.d.ts +23 -0
- package/web/firestore/utils/buildQueryConstraint.js +41 -0
- package/web/firestore/utils/buildQueryConstraint.ts +55 -0
- package/web/firestore/utils/getDocData.d.ts +13 -11
- package/web/firestore/utils/getDocData.js +6 -9
- package/web/firestore/utils/getDocData.ts +14 -20
- package/web/firestore/utils/getDocRef.d.ts +14 -11
- package/web/firestore/utils/getDocRef.js +9 -10
- package/web/firestore/utils/getDocRef.ts +21 -24
- package/web/firestore/utils/getDocSnap.d.ts +11 -13
- package/web/firestore/utils/getDocSnap.js +5 -10
- package/web/firestore/utils/getDocSnap.ts +14 -21
|
@@ -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
|
-
|
|
2
|
+
import { AppModel } from "../../../types";
|
|
4
3
|
/**
|
|
5
|
-
*
|
|
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
|
-
* @
|
|
10
|
-
*
|
|
11
|
-
* @param {
|
|
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
|
|
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
|
|
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
|
-
* @
|
|
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
|
-
* @
|
|
14
|
-
*
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
> = GetDocSnapOptions<AppModelType
|
|
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
|
|
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
|
-
* @
|
|
15
|
-
*
|
|
16
|
-
* @param {
|
|
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
|
|
32
|
-
const docSnap = await getDocSnap<AppModelType
|
|
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,
|
|
2
|
-
|
|
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,
|
|
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
|
|
14
|
+
* Either `reference` or `path`.
|
|
15
|
+
*
|
|
16
|
+
* @group Utility
|
|
17
|
+
*
|
|
18
|
+
* @param {GetDocRefOptions<AppModelType>} options - The options for building doc reference.
|
|
11
19
|
*
|
|
12
|
-
* @
|
|
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
|
|
22
|
+
export declare const getDocRef: <AppModelType extends AppModel = AppModel>({ db, reference, path, pathSegments }: GetDocRefOptions<AppModelType>) => DocumentReference<AppModelType, AppModelType> | null;
|
|
@@ -1,18 +1,17 @@
|
|
|
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
|
|
4
|
+
* Either `reference` or `path`.
|
|
5
5
|
*
|
|
6
|
-
* @
|
|
7
|
-
*
|
|
8
|
-
* @param {
|
|
9
|
-
*
|
|
10
|
-
* @
|
|
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 =
|
|
14
|
-
if (!reference && !path) {
|
|
15
|
-
|
|
12
|
+
export const getDocRef = ({ db, reference, path, pathSegments }) => {
|
|
13
|
+
if ((!reference && !path) || (reference && !path)) {
|
|
14
|
+
return null;
|
|
16
15
|
}
|
|
17
16
|
const docRef = !reference
|
|
18
17
|
? doc(db, path, ...(pathSegments || []))
|
|
@@ -1,46 +1,43 @@
|
|
|
1
|
-
import { CollectionReference, doc,
|
|
1
|
+
import { CollectionReference, doc, DocumentReference, Firestore } from "firebase/firestore";
|
|
2
|
+
import { AppModel } from "../../../types";
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
> = {
|
|
4
|
+
/**
|
|
5
|
+
* @inline
|
|
6
|
+
*/
|
|
7
|
+
export type GetDocRefOptions<AppModelType extends AppModel = AppModel> = {
|
|
7
8
|
db: Firestore;
|
|
8
|
-
reference?: CollectionReference<AppModelType,
|
|
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
|
|
16
|
+
* Either `reference` or `path`.
|
|
17
|
+
*
|
|
18
|
+
* @group Utility
|
|
19
|
+
*
|
|
20
|
+
* @param {GetDocRefOptions<AppModelType>} options - The options for building doc reference.
|
|
16
21
|
*
|
|
17
|
-
* @
|
|
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 =
|
|
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
|
|
33
|
-
if (!reference && !path) {
|
|
34
|
-
|
|
29
|
+
}: GetDocRefOptions<AppModelType>) => {
|
|
30
|
+
if ((!reference && !path) || (reference && !path)) {
|
|
31
|
+
return null;
|
|
35
32
|
}
|
|
36
33
|
|
|
37
34
|
const docRef = !reference
|
|
38
|
-
? doc(db, path as string, ...(pathSegments || []))
|
|
35
|
+
? (doc(db, path as string, ...(pathSegments || [])) as DocumentReference<AppModelType, AppModelType>)
|
|
39
36
|
: reference.type === "collection"
|
|
40
|
-
? doc(reference, path, ...(pathSegments || []))
|
|
37
|
+
? (doc(reference, path, ...(pathSegments || [])) as DocumentReference<AppModelType, AppModelType>)
|
|
41
38
|
: reference.type === "document"
|
|
42
|
-
? doc(reference, path as string, ...(pathSegments || []))
|
|
39
|
+
? (doc(reference, path as string, ...(pathSegments || [])) as DocumentReference<AppModelType, AppModelType>)
|
|
43
40
|
: null;
|
|
44
41
|
|
|
45
|
-
return docRef
|
|
42
|
+
return docRef;
|
|
46
43
|
};
|
|
@@ -1,20 +1,18 @@
|
|
|
1
|
-
import { DocumentData } from "firebase/firestore";
|
|
2
1
|
import { GetDocRefOptions } from "./getDocRef";
|
|
3
|
-
|
|
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
|
-
* @
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* @
|
|
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
|
|
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
|
-
* @
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* @
|
|
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 {
|
|
1
|
+
import { getDoc as firestoreGetDoc } from "firebase/firestore";
|
|
2
2
|
import { getDocRef, GetDocRefOptions } from "./getDocRef";
|
|
3
|
+
import { AppModel } from "../../../types";
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
> = GetDocRefOptions<AppModelType
|
|
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
|
-
* @
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* @
|
|
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
|
|
34
|
-
const docRef = await getDocRef<AppModelType
|
|
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);
|