react-query-firebase 2.0.3 → 2.1.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 +3 -2
- package/react-native/firestore/index.ts +1 -0
- package/react-native/firestore/useCompositeFilter.ts +3 -3
- package/react-native/firestore/useQueryConstraints.ts +84 -0
- package/react-native/index.d.ts +0 -4
- package/react-native/index.js +0 -4
- package/react-native/index.ts +0 -4
- package/types/AppModel.ts +7 -0
- package/types/QueryConstraints.ts +58 -0
- package/types/index.ts +2 -0
- package/web/firestore/index.ts +1 -0
- package/web/firestore/useCompositeFilter.ts +3 -3
- package/web/firestore/useQueryConstraints.ts +93 -0
- package/web/index.d.ts +0 -4
- package/web/index.js +0 -4
- package/web/index.ts +0 -4
- package/react-native/analytics/index.d.ts +0 -3
- package/react-native/analytics/index.js +0 -3
- package/react-native/analytics/useAnalytics.d.ts +0 -5
- package/react-native/analytics/useAnalytics.js +0 -10
- package/react-native/analytics/useLogEvent.d.ts +0 -17
- package/react-native/analytics/useLogEvent.js +0 -21
- package/react-native/analytics/useSetAnalyticsCollectionEnabled.d.ts +0 -10
- package/react-native/analytics/useSetAnalyticsCollectionEnabled.js +0 -16
- package/react-native/auth/index.d.ts +0 -12
- package/react-native/auth/index.js +0 -12
- package/react-native/auth/mutation-keys.d.ts +0 -7
- package/react-native/auth/mutation-keys.js +0 -19
- package/react-native/auth/useAuth.d.ts +0 -5
- package/react-native/auth/useAuth.js +0 -10
- package/react-native/auth/useCreateUserWitEmailAndPasswordMutation.d.ts +0 -15
- package/react-native/auth/useCreateUserWitEmailAndPasswordMutation.js +0 -19
- package/react-native/auth/useCurrentUser.d.ts +0 -6
- package/react-native/auth/useCurrentUser.js +0 -20
- package/react-native/auth/useIdToken.d.ts +0 -30
- package/react-native/auth/useIdToken.js +0 -66
- package/react-native/auth/useReauthenticateWitCredentialMutation.d.ts +0 -16
- package/react-native/auth/useReauthenticateWitCredentialMutation.js +0 -18
- package/react-native/auth/useReauthenticateWitRedirectMutation.d.ts +0 -17
- package/react-native/auth/useReauthenticateWitRedirectMutation.js +0 -18
- package/react-native/auth/useSendEmailVerificationMutation.d.ts +0 -13
- package/react-native/auth/useSendEmailVerificationMutation.js +0 -16
- package/react-native/auth/useSignInWitEmailAndPasswordMutation.d.ts +0 -15
- package/react-native/auth/useSignInWitEmailAndPasswordMutation.js +0 -19
- package/react-native/auth/useSignInWitRedirectMutation.d.ts +0 -14
- package/react-native/auth/useSignInWitRedirectMutation.js +0 -18
- package/react-native/auth/useSignOutMutation.d.ts +0 -10
- package/react-native/auth/useSignOutMutation.js +0 -19
- package/react-native/auth/useUpdateProfileMutation.d.ts +0 -15
- package/react-native/auth/useUpdateProfileMutation.js +0 -17
- package/react-native/firestore/index.d.ts +0 -16
- package/react-native/firestore/index.js +0 -16
- package/react-native/firestore/useAddDocMutation.d.ts +0 -21
- package/react-native/firestore/useAddDocMutation.js +0 -25
- package/react-native/firestore/useBatchWrite.d.ts +0 -15
- package/react-native/firestore/useBatchWrite.js +0 -21
- package/react-native/firestore/useCollectionReference.d.ts +0 -18
- package/react-native/firestore/useCollectionReference.js +0 -22
- package/react-native/firestore/useCompositeFilter.d.ts +0 -32
- package/react-native/firestore/useCompositeFilter.js +0 -42
- package/react-native/firestore/useCountQuery.d.ts +0 -23
- package/react-native/firestore/useCountQuery.js +0 -30
- package/react-native/firestore/useDeleteDocMutation.d.ts +0 -18
- package/react-native/firestore/useDeleteDocMutation.js +0 -23
- package/react-native/firestore/useDocReference.d.ts +0 -19
- package/react-native/firestore/useDocReference.js +0 -36
- package/react-native/firestore/useDocReferences.d.ts +0 -23
- package/react-native/firestore/useDocReferences.js +0 -29
- package/react-native/firestore/useFirestore.d.ts +0 -7
- package/react-native/firestore/useFirestore.js +0 -12
- package/react-native/firestore/useGetDocData.d.ts +0 -18
- package/react-native/firestore/useGetDocData.js +0 -18
- package/react-native/firestore/useGetRealtimeDocData.d.ts +0 -57
- package/react-native/firestore/useGetRealtimeDocData.js +0 -56
- package/react-native/firestore/useInfiniteQuery.d.ts +0 -17
- package/react-native/firestore/useInfiniteQuery.js +0 -28
- package/react-native/firestore/useQuery.d.ts +0 -24
- package/react-native/firestore/useQuery.js +0 -34
- package/react-native/firestore/useRunTransaction.d.ts +0 -15
- package/react-native/firestore/useRunTransaction.js +0 -19
- package/react-native/firestore/useSetDocMutation.d.ts +0 -20
- package/react-native/firestore/useSetDocMutation.js +0 -25
- package/react-native/firestore/useUpdateDocMutation.d.ts +0 -30
- package/react-native/firestore/useUpdateDocMutation.js +0 -37
- package/react-native/firestore/utils/getDocData.d.ts +0 -18
- package/react-native/firestore/utils/getDocData.js +0 -22
- package/react-native/firestore/utils/getDocRef.d.ts +0 -19
- package/react-native/firestore/utils/getDocRef.js +0 -21
- package/react-native/firestore/utils/getDocSnap.d.ts +0 -20
- package/react-native/firestore/utils/getDocSnap.js +0 -25
- package/react-native/remoteConfig/index.d.ts +0 -3
- package/react-native/remoteConfig/index.js +0 -3
- package/react-native/remoteConfig/useFetchAndActivate.d.ts +0 -11
- package/react-native/remoteConfig/useFetchAndActivate.js +0 -31
- package/react-native/remoteConfig/useGetValue.d.ts +0 -7
- package/react-native/remoteConfig/useGetValue.js +0 -15
- package/react-native/remoteConfig/useRemoteConfig.d.ts +0 -5
- package/react-native/remoteConfig/useRemoteConfig.js +0 -10
- package/web/analytics/index.d.ts +0 -3
- package/web/analytics/index.js +0 -3
- package/web/analytics/useAnalytics.d.ts +0 -5
- package/web/analytics/useAnalytics.js +0 -10
- package/web/analytics/useLogEvent.d.ts +0 -17
- package/web/analytics/useLogEvent.js +0 -21
- package/web/analytics/useSetAnalyticsCollectionEnabled.d.ts +0 -10
- package/web/analytics/useSetAnalyticsCollectionEnabled.js +0 -16
- package/web/auth/index.d.ts +0 -13
- package/web/auth/index.js +0 -13
- package/web/auth/mutation-keys.d.ts +0 -7
- package/web/auth/mutation-keys.js +0 -19
- package/web/auth/useAuth.d.ts +0 -5
- package/web/auth/useAuth.js +0 -10
- package/web/auth/useAuthStateReady.d.ts +0 -6
- package/web/auth/useAuthStateReady.js +0 -19
- package/web/auth/useCreateUserWitEmailAndPasswordMutation.d.ts +0 -15
- package/web/auth/useCreateUserWitEmailAndPasswordMutation.js +0 -19
- package/web/auth/useCurrentUser.d.ts +0 -6
- package/web/auth/useCurrentUser.js +0 -20
- package/web/auth/useIdToken.d.ts +0 -30
- package/web/auth/useIdToken.js +0 -66
- package/web/auth/useReauthenticateWitCredentialMutation.d.ts +0 -16
- package/web/auth/useReauthenticateWitCredentialMutation.js +0 -18
- package/web/auth/useReauthenticateWitRedirectMutation.d.ts +0 -17
- package/web/auth/useReauthenticateWitRedirectMutation.js +0 -18
- package/web/auth/useSendEmailVerificationMutation.d.ts +0 -13
- package/web/auth/useSendEmailVerificationMutation.js +0 -16
- package/web/auth/useSignInWitEmailAndPasswordMutation.d.ts +0 -15
- package/web/auth/useSignInWitEmailAndPasswordMutation.js +0 -19
- package/web/auth/useSignInWitRedirectMutation.d.ts +0 -14
- package/web/auth/useSignInWitRedirectMutation.js +0 -18
- package/web/auth/useSignOutMutation.d.ts +0 -10
- package/web/auth/useSignOutMutation.js +0 -19
- package/web/auth/useUpdateProfileMutation.d.ts +0 -15
- package/web/auth/useUpdateProfileMutation.js +0 -17
- package/web/firestore/index.d.ts +0 -16
- package/web/firestore/index.js +0 -16
- package/web/firestore/useAddDocMutation.d.ts +0 -23
- package/web/firestore/useAddDocMutation.js +0 -26
- package/web/firestore/useBatchWrite.d.ts +0 -15
- package/web/firestore/useBatchWrite.js +0 -21
- package/web/firestore/useCollectionReference.d.ts +0 -18
- package/web/firestore/useCollectionReference.js +0 -24
- package/web/firestore/useCompositeFilter.d.ts +0 -32
- package/web/firestore/useCompositeFilter.js +0 -41
- package/web/firestore/useCountQuery.d.ts +0 -23
- package/web/firestore/useCountQuery.js +0 -30
- package/web/firestore/useDeleteDocMutation.d.ts +0 -18
- package/web/firestore/useDeleteDocMutation.js +0 -23
- package/web/firestore/useDocReference.d.ts +0 -19
- package/web/firestore/useDocReference.js +0 -45
- package/web/firestore/useDocReferences.d.ts +0 -23
- package/web/firestore/useDocReferences.js +0 -31
- package/web/firestore/useFirestore.d.ts +0 -7
- package/web/firestore/useFirestore.js +0 -12
- package/web/firestore/useGetDocData.d.ts +0 -18
- package/web/firestore/useGetDocData.js +0 -18
- package/web/firestore/useGetRealtimeDocData.d.ts +0 -57
- package/web/firestore/useGetRealtimeDocData.js +0 -56
- package/web/firestore/useInfiniteQuery.d.ts +0 -18
- package/web/firestore/useInfiniteQuery.js +0 -28
- package/web/firestore/useQuery.d.ts +0 -25
- package/web/firestore/useQuery.js +0 -34
- package/web/firestore/useRunTransaction.d.ts +0 -15
- package/web/firestore/useRunTransaction.js +0 -19
- package/web/firestore/useSetDocMutation.d.ts +0 -20
- package/web/firestore/useSetDocMutation.js +0 -25
- package/web/firestore/useUpdateDocMutation.d.ts +0 -31
- package/web/firestore/useUpdateDocMutation.js +0 -37
- package/web/firestore/utils/getDocData.d.ts +0 -18
- package/web/firestore/utils/getDocData.js +0 -22
- package/web/firestore/utils/getDocRef.d.ts +0 -19
- package/web/firestore/utils/getDocRef.js +0 -25
- package/web/firestore/utils/getDocSnap.d.ts +0 -20
- package/web/firestore/utils/getDocSnap.js +0 -25
- package/web/remoteConfig/index.d.ts +0 -3
- package/web/remoteConfig/index.js +0 -3
- package/web/remoteConfig/useFetchAndActivate.d.ts +0 -11
- package/web/remoteConfig/useFetchAndActivate.js +0 -31
- package/web/remoteConfig/useGetValue.d.ts +0 -7
- package/web/remoteConfig/useGetValue.js +0 -15
- package/web/remoteConfig/useRemoteConfig.d.ts +0 -5
- package/web/remoteConfig/useRemoteConfig.js +0 -10
package/package.json
CHANGED
|
@@ -57,6 +57,7 @@
|
|
|
57
57
|
"files": [
|
|
58
58
|
"./web/",
|
|
59
59
|
"./react-native/",
|
|
60
|
+
"./types",
|
|
60
61
|
"package.json",
|
|
61
62
|
"package-lock.json",
|
|
62
63
|
"README.md",
|
|
@@ -68,10 +69,10 @@
|
|
|
68
69
|
"lint:fix": "eslint --fix",
|
|
69
70
|
"lint:staged": "lint-staged",
|
|
70
71
|
"prepare": "husky",
|
|
71
|
-
"docs:generate": "
|
|
72
|
+
"docs:generate": "./.github/scripts/build.sh",
|
|
72
73
|
"docs:dev": "vitepress dev docs",
|
|
73
74
|
"docs:build": "vitepress build docs",
|
|
74
75
|
"docs:preview": "vitepress preview docs"
|
|
75
76
|
},
|
|
76
|
-
"version": "2.
|
|
77
|
+
"version": "2.1.1"
|
|
77
78
|
}
|
|
@@ -28,11 +28,11 @@ export type UseCompositeFilter<DbModelType extends CompositeFilterDocumentData =
|
|
|
28
28
|
* @returns {QueryFieldFilterConstraint | null} A constructed query filter constraint based on the input query, or null if no valid constraints can be derived.
|
|
29
29
|
*/
|
|
30
30
|
|
|
31
|
-
const
|
|
31
|
+
export const buildCompositeFilter = <DbModelType extends CompositeFilterDocumentData = CompositeFilterDocumentData>(
|
|
32
32
|
query: QueryElement<DbModelType>
|
|
33
33
|
): FirebaseFirestoreTypes.QueryFilterConstraint | null => {
|
|
34
34
|
if (query.children) {
|
|
35
|
-
const queryConstraints = query.children.map(
|
|
35
|
+
const queryConstraints = query.children.map(buildCompositeFilter).filter((constraint) => !!constraint);
|
|
36
36
|
|
|
37
37
|
if (queryConstraints.length <= 0) {
|
|
38
38
|
return null;
|
|
@@ -67,7 +67,7 @@ export const useCompositeFilter = <DbModelType extends CompositeFilterDocumentDa
|
|
|
67
67
|
}: UseCompositeFilter<DbModelType>) => {
|
|
68
68
|
return useMemo(() => {
|
|
69
69
|
const queryConstraints =
|
|
70
|
-
query?.children?.map?.((subQuery) =>
|
|
70
|
+
query?.children?.map?.((subQuery) => buildCompositeFilter(subQuery))
|
|
71
71
|
?.filter<FirebaseFirestoreTypes.QueryFilterConstraint>?.((constraint) => !!constraint) ?? [];
|
|
72
72
|
|
|
73
73
|
if (queryConstraints.length <= 0) {
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { startAt, orderBy, limit, limitToLast, startAfter, endAt, endBefore } from "@react-native-firebase/firestore";
|
|
2
|
+
import { useMemo } from "react";
|
|
3
|
+
import { AppModel } from "../../types/AppModel";
|
|
4
|
+
import { type NonFilterQueryConstraint } from "../../types/QueryConstraints";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @inline
|
|
8
|
+
*/
|
|
9
|
+
export type UseQueryConstraints<AppModelType extends AppModel = AppModel> = {
|
|
10
|
+
/**
|
|
11
|
+
* A list of constraints such as limit, order, offset.
|
|
12
|
+
*/
|
|
13
|
+
constraints: NonFilterQueryConstraint<AppModelType>[];
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* A generic mothod to build query constraints for firebase
|
|
18
|
+
*
|
|
19
|
+
* @group Utility
|
|
20
|
+
*
|
|
21
|
+
* @param {NonFilterQueryConstraint<AppModelType>} constraint
|
|
22
|
+
*
|
|
23
|
+
* @returns {FirebaseFirestoreTypes.QueryNonFilterConstraint}
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```jsx
|
|
27
|
+
* const firebaseConfig = {};
|
|
28
|
+
* export const constraint = useMemo(() => {
|
|
29
|
+
* return buildQueryConstraint({
|
|
30
|
+
* type: 'limit',
|
|
31
|
+
* limit: 1
|
|
32
|
+
* });
|
|
33
|
+
* };
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export const buildQueryConstraint = <AppModelType extends AppModel = AppModel>(
|
|
37
|
+
constraint: NonFilterQueryConstraint<AppModelType>
|
|
38
|
+
) => {
|
|
39
|
+
switch (constraint.type) {
|
|
40
|
+
case "orderBy":
|
|
41
|
+
return orderBy(constraint.fieldPath as string, constraint.directionStr);
|
|
42
|
+
case "startAt":
|
|
43
|
+
return startAt(...constraint.arguments);
|
|
44
|
+
case "startAfter":
|
|
45
|
+
return startAfter(...constraint.arguments);
|
|
46
|
+
case "endAt":
|
|
47
|
+
return endAt(constraint.value, constraint.key);
|
|
48
|
+
case "endBefore":
|
|
49
|
+
return endBefore(constraint.value, constraint.key);
|
|
50
|
+
case "limit":
|
|
51
|
+
return limit(constraint.limit);
|
|
52
|
+
case "limitToLast":
|
|
53
|
+
return limitToLast(constraint.limit);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* A hook to build a list of non-filter query constraints for firebase queries.
|
|
59
|
+
* It uses buildQueryConstraint method and useMemo hook.
|
|
60
|
+
*
|
|
61
|
+
* @group Hook
|
|
62
|
+
*
|
|
63
|
+
* @param {UseQueryConstraints<AppModelType>} options
|
|
64
|
+
*
|
|
65
|
+
* @returns {FirebaseFirestoreTypes.QueryNonFilterConstraint}
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```jsx
|
|
69
|
+
* const firebaseConfig = {};
|
|
70
|
+
* export const constraint = useQueryConstraints([
|
|
71
|
+
* {
|
|
72
|
+
* type: 'limit',
|
|
73
|
+
* limit: 1
|
|
74
|
+
* }
|
|
75
|
+
* ]};
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export const useQueryConstraints = <AppModelType extends AppModel = AppModel>({
|
|
79
|
+
constraints
|
|
80
|
+
}: UseQueryConstraints<AppModelType>) => {
|
|
81
|
+
return useMemo(() => {
|
|
82
|
+
return constraints.map(buildQueryConstraint);
|
|
83
|
+
}, [constraints]);
|
|
84
|
+
};
|
package/react-native/index.d.ts
CHANGED
package/react-native/index.js
CHANGED
package/react-native/index.ts
CHANGED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { AppModel } from "./AppModel";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Order by constraint
|
|
5
|
+
* @group Query Constraints
|
|
6
|
+
*/
|
|
7
|
+
export type OrderByConstraint<AppModelType extends AppModel = AppModel> = {
|
|
8
|
+
/**
|
|
9
|
+
* Type of a constraint
|
|
10
|
+
*/
|
|
11
|
+
type: "orderBy";
|
|
12
|
+
/**
|
|
13
|
+
* Field path to use for ordering
|
|
14
|
+
*/
|
|
15
|
+
fieldPath: keyof AppModelType;
|
|
16
|
+
/**
|
|
17
|
+
* Direction of ordering: asc or desc
|
|
18
|
+
*/
|
|
19
|
+
directionStr: "asc" | "desc";
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Start from value constraint
|
|
24
|
+
* @group Query Constraints
|
|
25
|
+
*/
|
|
26
|
+
export type StartConstraint = {
|
|
27
|
+
type: "startAt" | "startAfter";
|
|
28
|
+
arguments: unknown[];
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* End by value constraint
|
|
33
|
+
* @group Query Constraints
|
|
34
|
+
*/
|
|
35
|
+
export type EndConstraint = {
|
|
36
|
+
type: "endAt" | "endBefore";
|
|
37
|
+
value: number | string | boolean | null;
|
|
38
|
+
key?: string;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Limit constraint
|
|
43
|
+
* @group Query Constraints
|
|
44
|
+
*/
|
|
45
|
+
export type LimitConstraint = {
|
|
46
|
+
type: "limitToLast" | "limit";
|
|
47
|
+
limit: number;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Non filtering query constaints
|
|
52
|
+
* @group Query Constraints
|
|
53
|
+
*/
|
|
54
|
+
export type NonFilterQueryConstraint<AppModelType extends AppModel = AppModel> =
|
|
55
|
+
| OrderByConstraint<AppModelType>
|
|
56
|
+
| StartConstraint
|
|
57
|
+
| EndConstraint
|
|
58
|
+
| LimitConstraint;
|
package/types/index.ts
ADDED
package/web/firestore/index.ts
CHANGED
|
@@ -28,11 +28,11 @@ export type UseCompositeFilter<DbModelType extends CompositeFilterDocumentData =
|
|
|
28
28
|
* @returns {QueryFieldFilterConstraint | null} A constructed query filter constraint based on the input query, or null if no valid constraints can be derived.
|
|
29
29
|
*/
|
|
30
30
|
|
|
31
|
-
const
|
|
31
|
+
export const buildCompositeFilter = <DbModelType extends CompositeFilterDocumentData = CompositeFilterDocumentData>(
|
|
32
32
|
query: QueryElement<DbModelType>
|
|
33
33
|
): QueryFilterConstraint | null => {
|
|
34
34
|
if (query.children) {
|
|
35
|
-
const queryConstraints = query.children.map(
|
|
35
|
+
const queryConstraints = query.children.map(buildCompositeFilter).filter((constraint) => !!constraint);
|
|
36
36
|
|
|
37
37
|
if (queryConstraints.length <= 0) {
|
|
38
38
|
return null;
|
|
@@ -63,7 +63,7 @@ export const useCompositeFilter = <DbModelType extends CompositeFilterDocumentDa
|
|
|
63
63
|
}: UseCompositeFilter<DbModelType>) => {
|
|
64
64
|
return useMemo(() => {
|
|
65
65
|
const queryConstraints =
|
|
66
|
-
query?.children?.map?.((subQuery) =>
|
|
66
|
+
query?.children?.map?.((subQuery) => buildCompositeFilter(subQuery))?.filter<QueryFilterConstraint>?.(
|
|
67
67
|
(constraint) => !!constraint
|
|
68
68
|
) ?? [];
|
|
69
69
|
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import {
|
|
2
|
+
QueryNonFilterConstraint,
|
|
3
|
+
startAt,
|
|
4
|
+
orderBy,
|
|
5
|
+
limit,
|
|
6
|
+
limitToLast,
|
|
7
|
+
startAfter,
|
|
8
|
+
endAt,
|
|
9
|
+
endBefore
|
|
10
|
+
} from "firebase/firestore";
|
|
11
|
+
import { AppModel } from "../../types/AppModel";
|
|
12
|
+
import { NonFilterQueryConstraint } from "../../types/QueryConstraints";
|
|
13
|
+
import { useMemo } from "react";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @inline
|
|
17
|
+
*/
|
|
18
|
+
export type UseQueryConstraints<AppModelType extends AppModel = AppModel> = {
|
|
19
|
+
/**
|
|
20
|
+
* A list of constraints such as limit, order, offset.
|
|
21
|
+
*/
|
|
22
|
+
constraints: NonFilterQueryConstraint<AppModelType>[];
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* A generic mothod to build query constraints for firebase
|
|
27
|
+
*
|
|
28
|
+
* @group Utility
|
|
29
|
+
*
|
|
30
|
+
* @param {NonFilterQueryConstraint<AppModelType>} constraint
|
|
31
|
+
*
|
|
32
|
+
* @returns {QueryNonFilterConstraint}
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```jsx
|
|
36
|
+
* const firebaseConfig = {};
|
|
37
|
+
* export const constraint = useMemo(() => {
|
|
38
|
+
* return buildQueryConstraint({
|
|
39
|
+
* type: 'limit',
|
|
40
|
+
* limit: 1
|
|
41
|
+
* });
|
|
42
|
+
* };
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export const buildQueryConstraint = <AppModelType extends AppModel = AppModel>(
|
|
46
|
+
constraint: NonFilterQueryConstraint<AppModelType>
|
|
47
|
+
): QueryNonFilterConstraint => {
|
|
48
|
+
switch (constraint.type) {
|
|
49
|
+
case "orderBy":
|
|
50
|
+
return orderBy(constraint.fieldPath as string, constraint.directionStr);
|
|
51
|
+
case "startAt":
|
|
52
|
+
return startAt(...constraint.arguments);
|
|
53
|
+
case "startAfter":
|
|
54
|
+
return startAfter(...constraint.arguments);
|
|
55
|
+
case "endAt":
|
|
56
|
+
return endAt(constraint.value, constraint.key);
|
|
57
|
+
case "endBefore":
|
|
58
|
+
return endBefore(constraint.value, constraint.key);
|
|
59
|
+
case "limit":
|
|
60
|
+
return limit(constraint.limit);
|
|
61
|
+
case "limitToLast":
|
|
62
|
+
return limitToLast(constraint.limit);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* A hook to build a list of non-filter query constraints for firebase queries.
|
|
68
|
+
* It uses buildQueryConstraint method and useMemo hook.
|
|
69
|
+
*
|
|
70
|
+
* @group Hook
|
|
71
|
+
*
|
|
72
|
+
* @param {UseQueryConstraints<AppModelType>} constraints
|
|
73
|
+
*
|
|
74
|
+
* @returns {QueryNonFilterConstraint[]}
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```jsx
|
|
78
|
+
* const firebaseConfig = {};
|
|
79
|
+
* export const constraint = useQueryConstraints([
|
|
80
|
+
* {
|
|
81
|
+
* type: 'limit',
|
|
82
|
+
* limit: 1
|
|
83
|
+
* }
|
|
84
|
+
* ]};
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
export const useQueryConstraints = <AppModelType extends AppModel = AppModel>({
|
|
88
|
+
constraints
|
|
89
|
+
}: UseQueryConstraints<AppModelType>): QueryNonFilterConstraint[] => {
|
|
90
|
+
return useMemo(() => {
|
|
91
|
+
return constraints.map(buildQueryConstraint);
|
|
92
|
+
}, [constraints]);
|
|
93
|
+
};
|
package/web/index.d.ts
CHANGED
package/web/index.js
CHANGED
package/web/index.ts
CHANGED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { useContext } from "react";
|
|
2
|
-
import { FirebaseContext } from "../context/FirebaseContext";
|
|
3
|
-
/**
|
|
4
|
-
* Hook to access Firebase analytics from the Firebase context.
|
|
5
|
-
* @returns {any} The analytics object from the Firebase context.
|
|
6
|
-
*/
|
|
7
|
-
export const useAnalytics = () => {
|
|
8
|
-
const { analytics } = useContext(FirebaseContext);
|
|
9
|
-
return analytics;
|
|
10
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
type UseLogEventOptions = {
|
|
2
|
-
eventName: string;
|
|
3
|
-
eventParams?: {
|
|
4
|
-
[key: string]: unknown;
|
|
5
|
-
};
|
|
6
|
-
};
|
|
7
|
-
/**
|
|
8
|
-
* Custom hook to create a log event function that logs an analytics event with specified parameters.
|
|
9
|
-
* @param {Object} options - The options for the log event.
|
|
10
|
-
* @param {string} options.eventName - The name of the event to be logged.
|
|
11
|
-
* @param {Object} options.eventParams - The parameters to be sent along with the event.
|
|
12
|
-
* @returns {Object} An object containing a `logEvent` function that, when called, logs the event.
|
|
13
|
-
*/
|
|
14
|
-
export declare const useLogEvent: ({ eventName, eventParams }: UseLogEventOptions) => {
|
|
15
|
-
logEvent: () => void;
|
|
16
|
-
};
|
|
17
|
-
export {};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { logEvent } from "@react-native-firebase/analytics";
|
|
2
|
-
import { useAnalytics } from "./useAnalytics";
|
|
3
|
-
import { useCallback, useMemo } from "react";
|
|
4
|
-
/**
|
|
5
|
-
* Custom hook to create a log event function that logs an analytics event with specified parameters.
|
|
6
|
-
* @param {Object} options - The options for the log event.
|
|
7
|
-
* @param {string} options.eventName - The name of the event to be logged.
|
|
8
|
-
* @param {Object} options.eventParams - The parameters to be sent along with the event.
|
|
9
|
-
* @returns {Object} An object containing a `logEvent` function that, when called, logs the event.
|
|
10
|
-
*/
|
|
11
|
-
export const useLogEvent = ({ eventName, eventParams }) => {
|
|
12
|
-
const analytics = useAnalytics();
|
|
13
|
-
const logEventCallback = useCallback(() => {
|
|
14
|
-
if (analytics) {
|
|
15
|
-
logEvent(analytics, eventName, eventParams);
|
|
16
|
-
}
|
|
17
|
-
}, [eventName, eventParams, analytics]);
|
|
18
|
-
return useMemo(() => ({
|
|
19
|
-
logEvent: logEventCallback
|
|
20
|
-
}), [logEventCallback]);
|
|
21
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
type UseSetAnalyticsCollectionEnabledOptions = {
|
|
2
|
-
enabled?: boolean;
|
|
3
|
-
};
|
|
4
|
-
/**
|
|
5
|
-
* Custom hook to enable or disable analytics collection
|
|
6
|
-
* @param {Object} options - The options for hook.
|
|
7
|
-
* @param {string} options.enabled - Flag that identifies if analytics collection is enabled.
|
|
8
|
-
*/
|
|
9
|
-
export declare const useSetAnalyticsCollectionEnabled: ({ enabled }: UseSetAnalyticsCollectionEnabledOptions) => void;
|
|
10
|
-
export {};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { setAnalyticsCollectionEnabled } from "@react-native-firebase/analytics";
|
|
2
|
-
import { useAnalytics } from "./useAnalytics";
|
|
3
|
-
import { useEffect } from "react";
|
|
4
|
-
/**
|
|
5
|
-
* Custom hook to enable or disable analytics collection
|
|
6
|
-
* @param {Object} options - The options for hook.
|
|
7
|
-
* @param {string} options.enabled - Flag that identifies if analytics collection is enabled.
|
|
8
|
-
*/
|
|
9
|
-
export const useSetAnalyticsCollectionEnabled = ({ enabled = false }) => {
|
|
10
|
-
const analytics = useAnalytics();
|
|
11
|
-
useEffect(() => {
|
|
12
|
-
if (analytics) {
|
|
13
|
-
setAnalyticsCollectionEnabled(analytics, enabled);
|
|
14
|
-
}
|
|
15
|
-
}, [analytics, enabled]);
|
|
16
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export * from "./mutation-keys";
|
|
2
|
-
export * from "./useAuth";
|
|
3
|
-
export * from "./useCreateUserWitEmailAndPasswordMutation";
|
|
4
|
-
export * from "./useSendEmailVerificationMutation";
|
|
5
|
-
export * from "./useSignInWitEmailAndPasswordMutation";
|
|
6
|
-
export * from "./useCurrentUser";
|
|
7
|
-
export * from "./useSignInWitRedirectMutation";
|
|
8
|
-
export * from "./useUpdateProfileMutation";
|
|
9
|
-
export * from "./useSignOutMutation";
|
|
10
|
-
export * from "./useIdToken";
|
|
11
|
-
export * from "./useReauthenticateWitCredentialMutation";
|
|
12
|
-
export * from "./useReauthenticateWitRedirectMutation";
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export * from "./mutation-keys";
|
|
2
|
-
export * from "./useAuth";
|
|
3
|
-
export * from "./useCreateUserWitEmailAndPasswordMutation";
|
|
4
|
-
export * from "./useSendEmailVerificationMutation";
|
|
5
|
-
export * from "./useSignInWitEmailAndPasswordMutation";
|
|
6
|
-
export * from "./useCurrentUser";
|
|
7
|
-
export * from "./useSignInWitRedirectMutation";
|
|
8
|
-
export * from "./useUpdateProfileMutation";
|
|
9
|
-
export * from "./useSignOutMutation";
|
|
10
|
-
export * from "./useIdToken";
|
|
11
|
-
export * from "./useReauthenticateWitCredentialMutation";
|
|
12
|
-
export * from "./useReauthenticateWitRedirectMutation";
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export declare const CREATE_USER_WITH_EMAIL_AND_PASSWORD_MUTATION_KEY: readonly ["FIREBASE", "AUTH", "CREATE_USER_WITH_EMAIL_AND_PASSWORD_MUTATION"];
|
|
2
|
-
export declare const SEND_EMAIL_VERIFICATION_MUTATION_KEY: readonly ["FIREBASE", "AUTH", "SEND_EMAIL_VERIFICATION_MUTATION"];
|
|
3
|
-
export declare const SIGN_IN_WITH_EMAIL_AND_PASSWORD_MUTATION_KEY: readonly ["FIREBASE", "AUTH", "SIGN_IN_WITH_EMAIL_AND_PASSWORD_MUTATION"];
|
|
4
|
-
export declare const SIGN_IN_WITH_REDIRECT_MUTATION_KEY: readonly ["FIREBASE", "AUTH", "SIGN_IN_WITH_REDIRECT_MUTATION"];
|
|
5
|
-
export declare const SIGN_OUT_MUTATION_KEY: readonly ["FIREBASE", "AUTH", "SIGN_OUT"];
|
|
6
|
-
export declare const REAUTHENTICATE_WITH_REDIRECT_MUTATION_KEY: readonly ["FIREBASE", "AUTH", "REAUTHENTICATE_WITH_REDIRECT"];
|
|
7
|
-
export declare const REAUTHENTICATE_WITH_CREDENTIAL_MUTATION_KEY: readonly ["FIREBASE", "AUTH", "REAUTHENTICATE_WITH_CREDENTIAL"];
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export const CREATE_USER_WITH_EMAIL_AND_PASSWORD_MUTATION_KEY = [
|
|
2
|
-
"FIREBASE",
|
|
3
|
-
"AUTH",
|
|
4
|
-
"CREATE_USER_WITH_EMAIL_AND_PASSWORD_MUTATION"
|
|
5
|
-
];
|
|
6
|
-
export const SEND_EMAIL_VERIFICATION_MUTATION_KEY = ["FIREBASE", "AUTH", "SEND_EMAIL_VERIFICATION_MUTATION"];
|
|
7
|
-
export const SIGN_IN_WITH_EMAIL_AND_PASSWORD_MUTATION_KEY = [
|
|
8
|
-
"FIREBASE",
|
|
9
|
-
"AUTH",
|
|
10
|
-
"SIGN_IN_WITH_EMAIL_AND_PASSWORD_MUTATION"
|
|
11
|
-
];
|
|
12
|
-
export const SIGN_IN_WITH_REDIRECT_MUTATION_KEY = ["FIREBASE", "AUTH", "SIGN_IN_WITH_REDIRECT_MUTATION"];
|
|
13
|
-
export const SIGN_OUT_MUTATION_KEY = ["FIREBASE", "AUTH", "SIGN_OUT"];
|
|
14
|
-
export const REAUTHENTICATE_WITH_REDIRECT_MUTATION_KEY = ["FIREBASE", "AUTH", "REAUTHENTICATE_WITH_REDIRECT"];
|
|
15
|
-
export const REAUTHENTICATE_WITH_CREDENTIAL_MUTATION_KEY = [
|
|
16
|
-
"FIREBASE",
|
|
17
|
-
"AUTH",
|
|
18
|
-
"REAUTHENTICATE_WITH_CREDENTIAL"
|
|
19
|
-
];
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { useContext } from "react";
|
|
2
|
-
import { FirebaseContext } from "../context/FirebaseContext";
|
|
3
|
-
/**
|
|
4
|
-
* Custom hook to retrieve the authentication object from the Firebase context.
|
|
5
|
-
* @returns {Auth} The authentication object from the Firebase context.
|
|
6
|
-
*/
|
|
7
|
-
export const useAuth = () => {
|
|
8
|
-
const { auth } = useContext(FirebaseContext);
|
|
9
|
-
return auth;
|
|
10
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { UseMutationOptions } from "@tanstack/react-query";
|
|
2
|
-
import { FirebaseAuthTypes } from "@react-native-firebase/auth";
|
|
3
|
-
import { ReactNativeFirebase } from "@react-native-firebase/app";
|
|
4
|
-
export type UseCreateUserWitEmailAndPasswordMutationVariables = {
|
|
5
|
-
email: string;
|
|
6
|
-
password: string;
|
|
7
|
-
};
|
|
8
|
-
/**
|
|
9
|
-
* Custom hook to initiate a user creation process using email and password with Firebase authentication.
|
|
10
|
-
* This hook utilizes the `useMutation` functionality to support creating new user credentials asynchronously.
|
|
11
|
-
*
|
|
12
|
-
* @param {Omit<UseMutationOptions<FirebaseAuthTypes.UserCredential, ReactNativeFirebase.NativeFirebaseError, UseCreateUserWitEmailAndPasswordMutationVariables, TContext>, "mutationKey" | "mutationFn">} options - Optional settings to customize the mutation behavior, excluding `mutationKey` and `mutationFn`.
|
|
13
|
-
* @returns {UseMutationResult<FirebaseAuthTypes.UserCredential, ReactNativeFirebase.NativeFirebaseError, UseCreateUserWitEmailAndPasswordMutationVariables, TContext>} The result of the mutation which includes status, user credentials, and error information if any.
|
|
14
|
-
*/
|
|
15
|
-
export declare const useCreateUserWitEmailAndPasswordMutation: <TContext = unknown>(options?: Omit<UseMutationOptions<FirebaseAuthTypes.UserCredential, ReactNativeFirebase.NativeFirebaseError, UseCreateUserWitEmailAndPasswordMutationVariables, TContext>, "mutationKey" | "mutationFn">) => import("@tanstack/react-query").UseMutationResult<FirebaseAuthTypes.UserCredential, ReactNativeFirebase.NativeFirebaseError, UseCreateUserWitEmailAndPasswordMutationVariables, TContext>;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { useMutation } from "@tanstack/react-query";
|
|
2
|
-
import { createUserWithEmailAndPassword } from "@react-native-firebase/auth";
|
|
3
|
-
import { useAuth } from "./useAuth";
|
|
4
|
-
import { CREATE_USER_WITH_EMAIL_AND_PASSWORD_MUTATION_KEY } from "./mutation-keys";
|
|
5
|
-
/**
|
|
6
|
-
* Custom hook to initiate a user creation process using email and password with Firebase authentication.
|
|
7
|
-
* This hook utilizes the `useMutation` functionality to support creating new user credentials asynchronously.
|
|
8
|
-
*
|
|
9
|
-
* @param {Omit<UseMutationOptions<FirebaseAuthTypes.UserCredential, ReactNativeFirebase.NativeFirebaseError, UseCreateUserWitEmailAndPasswordMutationVariables, TContext>, "mutationKey" | "mutationFn">} options - Optional settings to customize the mutation behavior, excluding `mutationKey` and `mutationFn`.
|
|
10
|
-
* @returns {UseMutationResult<FirebaseAuthTypes.UserCredential, ReactNativeFirebase.NativeFirebaseError, UseCreateUserWitEmailAndPasswordMutationVariables, TContext>} The result of the mutation which includes status, user credentials, and error information if any.
|
|
11
|
-
*/
|
|
12
|
-
export const useCreateUserWitEmailAndPasswordMutation = (options = {}) => {
|
|
13
|
-
const firebaseAuth = useAuth();
|
|
14
|
-
return useMutation({
|
|
15
|
-
...options,
|
|
16
|
-
mutationFn: async ({ email, password }) => await createUserWithEmailAndPassword(firebaseAuth, email, password),
|
|
17
|
-
mutationKey: CREATE_USER_WITH_EMAIL_AND_PASSWORD_MUTATION_KEY
|
|
18
|
-
});
|
|
19
|
-
};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Hook that provides the current authenticated user from Firebase Auth.
|
|
3
|
-
* It listens for changes in the authentication state and updates the user accordingly.
|
|
4
|
-
* @returns {Object|null} The current authenticated user object or null if no user is authenticated.
|
|
5
|
-
*/
|
|
6
|
-
export declare const useCurrentUser: () => import("@react-native-firebase/auth").FirebaseAuthTypes.User | null;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { useAuth } from "./useAuth";
|
|
2
|
-
import { useEffect, useState } from "react";
|
|
3
|
-
/**
|
|
4
|
-
* Hook that provides the current authenticated user from Firebase Auth.
|
|
5
|
-
* It listens for changes in the authentication state and updates the user accordingly.
|
|
6
|
-
* @returns {Object|null} The current authenticated user object or null if no user is authenticated.
|
|
7
|
-
*/
|
|
8
|
-
export const useCurrentUser = () => {
|
|
9
|
-
const { onAuthStateChanged, currentUser: fbCurrentUser } = useAuth();
|
|
10
|
-
const [currentUser, setCurrentUser] = useState(fbCurrentUser);
|
|
11
|
-
useEffect(() => {
|
|
12
|
-
const unsubscribe = onAuthStateChanged((user) => {
|
|
13
|
-
setCurrentUser(user);
|
|
14
|
-
});
|
|
15
|
-
return () => {
|
|
16
|
-
unsubscribe();
|
|
17
|
-
};
|
|
18
|
-
}, [currentUser?.uid, onAuthStateChanged]);
|
|
19
|
-
return currentUser;
|
|
20
|
-
};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @inline
|
|
3
|
-
*/
|
|
4
|
-
export type UseIdTokenResult = {
|
|
5
|
-
idToken: string;
|
|
6
|
-
refresh: () => Promise<string | undefined>;
|
|
7
|
-
};
|
|
8
|
-
/**
|
|
9
|
-
* A hook to manage the ID token.
|
|
10
|
-
* It monitors changes to the ID token and provides the token itself along with a refresh method to update the token when needed.
|
|
11
|
-
*
|
|
12
|
-
* @group Hook
|
|
13
|
-
*
|
|
14
|
-
* @returns {UseIdTokenResult}
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```jsx
|
|
18
|
-
* export const MyComponent = () => {
|
|
19
|
-
* const result = useIdToken();
|
|
20
|
-
* useEffect(() => {
|
|
21
|
-
* const timeout = setTimeout(() => {
|
|
22
|
-
* result.refresh();
|
|
23
|
-
* }, 5000);
|
|
24
|
-
* return () => clearTimeout();
|
|
25
|
-
* }, [])
|
|
26
|
-
* console.log(resilt.idToken);
|
|
27
|
-
* };
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
export declare const useIdToken: () => UseIdTokenResult;
|