react-query-firebase 3.2.0 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/react-native/context/FirebaseContext.d.ts +4 -4
- package/dist/react-native/context/FirebaseContextProvider.d.ts +1 -18
- package/dist/react-native/context/FirebaseContextProvider.js +2 -5
- package/dist/react-native/firestore/useAddDocMutation.d.ts +2 -2
- package/dist/react-native/firestore/useBatchWrite.d.ts +2 -2
- package/dist/react-native/firestore/useCollectionReference.d.ts +4 -4
- package/dist/react-native/firestore/useCollectionReference.js +1 -1
- package/dist/react-native/firestore/useCompositeFilter.d.ts +2 -2
- package/dist/react-native/firestore/useCompositeFilter.js +1 -11
- package/dist/react-native/firestore/useCountQuery.d.ts +3 -4
- package/dist/react-native/firestore/useDeleteDocMutation.d.ts +3 -3
- package/dist/react-native/firestore/useDocReference.d.ts +2 -2
- package/dist/react-native/firestore/useDocReference.js +1 -1
- package/dist/react-native/firestore/useDocReferences.d.ts +2 -2
- package/dist/react-native/firestore/useDocReferences.js +1 -1
- package/dist/react-native/firestore/useFirestore.d.ts +1 -1
- package/dist/react-native/firestore/useFirestoreQueryEngine.d.ts +2 -2
- package/dist/react-native/firestore/useFirestoreQueryEngine.js +4 -11
- package/dist/react-native/firestore/useGetRealtimeDocData.d.ts +2 -2
- package/dist/react-native/firestore/useInfiniteQuery.d.ts +3 -4
- package/dist/react-native/firestore/useInfiniteQuery.js +1 -3
- package/dist/react-native/firestore/useQuery.d.ts +4 -4
- package/dist/react-native/firestore/useQuery.js +1 -3
- package/dist/react-native/firestore/useQueryConstraints.d.ts +1 -1
- package/dist/react-native/firestore/useQueryConstraints.js +1 -1
- package/dist/react-native/firestore/useRunTransaction.d.ts +4 -4
- package/dist/react-native/firestore/useSetDocMutation.d.ts +2 -2
- package/dist/react-native/firestore/useUpdateDocMutation.d.ts +2 -2
- package/dist/react-native/firestore/utils/buildCompositeFilter.d.ts +9 -11
- package/dist/react-native/firestore/utils/buildCompositeFilter.js +11 -5
- package/dist/react-native/firestore/utils/buildQueryConstraint.d.ts +1 -1
- package/dist/react-native/firestore/utils/buildQueryConstraint.js +1 -1
- package/dist/react-native/firestore/utils/getDocRef.d.ts +4 -4
- package/dist/react-native/firestore/utils/getDocSnap.d.ts +1 -1
- package/dist/react-native/firestore/utils/getDocSnap.js +1 -1
- package/package.json +26 -26
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type FirebaseApp } from "@react-native-firebase/app";
|
|
2
2
|
import { type FirebaseAuthTypes } from "@react-native-firebase/auth";
|
|
3
3
|
import { type Analytics } from "@react-native-firebase/analytics";
|
|
4
4
|
import { type Messaging } from "@react-native-firebase/messaging";
|
|
5
5
|
import { type FirebaseRemoteConfigTypes } from "@react-native-firebase/remote-config";
|
|
6
|
-
import { type
|
|
6
|
+
import { type Firestore } from "@react-native-firebase/firestore";
|
|
7
7
|
export type FirebaseContextValue = {
|
|
8
8
|
auth: FirebaseAuthTypes.Module;
|
|
9
9
|
analytics: Analytics;
|
|
10
|
-
firebase:
|
|
10
|
+
firebase: FirebaseApp;
|
|
11
11
|
remoteConfig: FirebaseRemoteConfigTypes.Module;
|
|
12
|
-
firestore:
|
|
12
|
+
firestore: Firestore;
|
|
13
13
|
messaging: Messaging;
|
|
14
14
|
};
|
|
15
15
|
/**
|
|
@@ -1,25 +1,8 @@
|
|
|
1
1
|
import React, { PropsWithChildren } from "react";
|
|
2
2
|
import { ConsentSettings } from "@react-native-firebase/analytics";
|
|
3
3
|
import { FirebaseRemoteConfigTypes } from "@react-native-firebase/remote-config";
|
|
4
|
+
import { FirestoreSettings } from "@react-native-firebase/firestore";
|
|
4
5
|
import { ReactNativeFirebase } from "@react-native-firebase/app";
|
|
5
|
-
/**
|
|
6
|
-
* @inline
|
|
7
|
-
* @see https://firebase.google.com/docs/reference/js/firestore_.firestoresettings
|
|
8
|
-
*/
|
|
9
|
-
export type FirestoreSettings = {
|
|
10
|
-
cacheSizeBytes?: number;
|
|
11
|
-
experimentalAutoDetectLongPolling?: boolean;
|
|
12
|
-
experimentalForceLongPolling?: boolean;
|
|
13
|
-
experimentalLongPollingOptions?: {
|
|
14
|
-
timeoutSeconds: number;
|
|
15
|
-
};
|
|
16
|
-
host?: string;
|
|
17
|
-
ignoreUndefinedProperties?: boolean;
|
|
18
|
-
localCache?: {
|
|
19
|
-
kind: "memory" | "persistent";
|
|
20
|
-
};
|
|
21
|
-
ssl?: boolean;
|
|
22
|
-
};
|
|
23
6
|
/**
|
|
24
7
|
* @inline
|
|
25
8
|
*/
|
|
@@ -3,7 +3,7 @@ import { connectAuthEmulator, getAuth } from "@react-native-firebase/auth";
|
|
|
3
3
|
import { getMessaging } from "@react-native-firebase/messaging";
|
|
4
4
|
import { setAnalyticsCollectionEnabled, setConsent, getAnalytics } from "@react-native-firebase/analytics";
|
|
5
5
|
import { getRemoteConfig } from "@react-native-firebase/remote-config";
|
|
6
|
-
import { connectFirestoreEmulator, getFirestore } from "@react-native-firebase/firestore";
|
|
6
|
+
import { connectFirestoreEmulator, getFirestore, initializeFirestore } from "@react-native-firebase/firestore";
|
|
7
7
|
import { getApp } from "@react-native-firebase/app";
|
|
8
8
|
import { FirebaseContext } from "./FirebaseContext.js";
|
|
9
9
|
/**
|
|
@@ -48,10 +48,7 @@ export const FirebaseContextProvider = ({ emulators, children, authEnabled = tru
|
|
|
48
48
|
if (emulators?.firestore?.host && emulators?.firestore?.port) {
|
|
49
49
|
connectFirestoreEmulator(getFirestore(internalFirebase), emulators.firestore.host, emulators.firestore.port);
|
|
50
50
|
}
|
|
51
|
-
const localFirestore =
|
|
52
|
-
if (firestoreSettings) {
|
|
53
|
-
localFirestore.settings(firestoreSettings);
|
|
54
|
-
}
|
|
51
|
+
const localFirestore = initializeFirestore(internalFirebase, firestoreSettings || {});
|
|
55
52
|
return localFirestore;
|
|
56
53
|
}
|
|
57
54
|
return null;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UseMutationOptions } from "@tanstack/react-query";
|
|
2
|
-
import {
|
|
2
|
+
import { type CollectionReference, WithFieldValue } from "@react-native-firebase/firestore";
|
|
3
3
|
import { ReactNativeFirebase } from "@react-native-firebase/app";
|
|
4
4
|
import { AppModel } from "../../types/index.js";
|
|
5
5
|
/**
|
|
@@ -18,7 +18,7 @@ export type UseAddDocMutationOptions<AppModelType extends AppModel = AppModel, T
|
|
|
18
18
|
/**
|
|
19
19
|
* Reference to a collection where document must be added
|
|
20
20
|
*/
|
|
21
|
-
collectionReference:
|
|
21
|
+
collectionReference: CollectionReference<AppModelType, AppModelType>;
|
|
22
22
|
/**
|
|
23
23
|
* Options for useMutation hook excluding mutationFn. MutationKey will be equal to reference.path by default.
|
|
24
24
|
*/
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { UseMutationOptions } from "@tanstack/react-query";
|
|
2
|
-
import {
|
|
2
|
+
import { writeBatch } from "@react-native-firebase/firestore";
|
|
3
3
|
import { ReactNativeFirebase } from "@react-native-firebase/app";
|
|
4
4
|
/**
|
|
5
5
|
* @inline
|
|
6
6
|
*/
|
|
7
|
-
export type UseBatchWriteVariables = (batch:
|
|
7
|
+
export type UseBatchWriteVariables = (batch: ReturnType<typeof writeBatch>) => Promise<void> | void;
|
|
8
8
|
/**
|
|
9
9
|
* @inline
|
|
10
10
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CollectionReference, DocumentReference } from "@react-native-firebase/firestore";
|
|
2
2
|
import { AppModel } from "../../types/index.js";
|
|
3
3
|
/**
|
|
4
4
|
* @inline
|
|
@@ -7,7 +7,7 @@ export type UseCollectionReferenceOptions<AppModelType extends AppModel = AppMod
|
|
|
7
7
|
/**
|
|
8
8
|
* CollectionReference or DocumentReference that is used as a root to lookup a sub-collection
|
|
9
9
|
*/
|
|
10
|
-
reference?:
|
|
10
|
+
reference?: CollectionReference<AppModelType, AppModelType> | DocumentReference<AppModelType, AppModelType>;
|
|
11
11
|
/**
|
|
12
12
|
* A slash-separated path to a collection.
|
|
13
13
|
*/
|
|
@@ -25,7 +25,7 @@ export type UseCollectionReferenceOptions<AppModelType extends AppModel = AppMod
|
|
|
25
25
|
*
|
|
26
26
|
* @param {UseCollectionReferenceOptions<AppModelType>} options - Options
|
|
27
27
|
*
|
|
28
|
-
* @returns {
|
|
28
|
+
* @returns {CollectionReference<AppModelType, AppModelType>} A reference to a Firestore collection
|
|
29
29
|
*
|
|
30
30
|
* @example
|
|
31
31
|
* ```jsx
|
|
@@ -36,4 +36,4 @@ export type UseCollectionReferenceOptions<AppModelType extends AppModel = AppMod
|
|
|
36
36
|
* };
|
|
37
37
|
* ```
|
|
38
38
|
*/
|
|
39
|
-
export declare const useCollectionReference: <AppModelType extends AppModel = AppModel>({ path, reference, pathSegments }: UseCollectionReferenceOptions<AppModelType>) =>
|
|
39
|
+
export declare const useCollectionReference: <AppModelType extends AppModel = AppModel>({ path, reference, pathSegments }: UseCollectionReferenceOptions<AppModelType>) => CollectionReference<AppModelType, AppModelType>;
|
|
@@ -9,7 +9,7 @@ import { useFirestore } from "./useFirestore.js";
|
|
|
9
9
|
*
|
|
10
10
|
* @param {UseCollectionReferenceOptions<AppModelType>} options - Options
|
|
11
11
|
*
|
|
12
|
-
* @returns {
|
|
12
|
+
* @returns {CollectionReference<AppModelType, AppModelType>} A reference to a Firestore collection
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
15
15
|
* ```jsx
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AppModel } from "../../types/index.js";
|
|
2
|
-
import { CompositeFilter
|
|
2
|
+
import { CompositeFilter } from "./utils/buildCompositeFilter.js";
|
|
3
3
|
/**
|
|
4
4
|
* @inline
|
|
5
5
|
*/
|
|
@@ -34,4 +34,4 @@ export type UseCompositeFilter<AppModelType extends AppModel = AppModel> = {
|
|
|
34
34
|
* };
|
|
35
35
|
* ```
|
|
36
36
|
*/
|
|
37
|
-
export declare const useCompositeFilter: <AppModelType extends AppModel = AppModel>({ query }: UseCompositeFilter<AppModelType>) =>
|
|
37
|
+
export declare const useCompositeFilter: <AppModelType extends AppModel = AppModel>({ query }: UseCompositeFilter<AppModelType>) => import("@firebase/firestore").QueryCompositeFilterConstraint | null;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { and, or } from "@react-native-firebase/firestore";
|
|
2
1
|
import { useMemo } from "react";
|
|
3
2
|
import { buildCompositeFilter } from "./utils/buildCompositeFilter.js";
|
|
4
3
|
/**
|
|
@@ -31,15 +30,6 @@ import { buildCompositeFilter } from "./utils/buildCompositeFilter.js";
|
|
|
31
30
|
*/
|
|
32
31
|
export const useCompositeFilter = ({ query }) => {
|
|
33
32
|
return useMemo(() => {
|
|
34
|
-
|
|
35
|
-
?.map?.((subQuery) => buildCompositeFilter(subQuery))
|
|
36
|
-
?.filter?.((constraint) => !!constraint) ?? [];
|
|
37
|
-
if (queryConstraints.length <= 0) {
|
|
38
|
-
return undefined;
|
|
39
|
-
}
|
|
40
|
-
if (queryConstraints.length <= 1) {
|
|
41
|
-
return queryConstraints[0];
|
|
42
|
-
}
|
|
43
|
-
return query?.operator === "OR" ? or(...queryConstraints) : and(...queryConstraints);
|
|
33
|
+
return query ? buildCompositeFilter(query) : null;
|
|
44
34
|
}, [query]);
|
|
45
35
|
};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CollectionReference, QueryCompositeFilterConstraint, QueryConstraint, QueryNonFilterConstraint } from "@react-native-firebase/firestore";
|
|
2
2
|
import { UseQueryResult, UseQueryOptions as UseReactQueryOptions } from "@tanstack/react-query";
|
|
3
3
|
import { AppModel } from "../../types/index.js";
|
|
4
|
-
import { QueryFilterConstraint } from "./utils/buildCompositeFilter.js";
|
|
5
4
|
/**
|
|
6
5
|
* @inline
|
|
7
6
|
*/
|
|
@@ -13,7 +12,7 @@ type UseCountQueryOptions<AppModelType extends AppModel = AppModel> = {
|
|
|
13
12
|
/**
|
|
14
13
|
* Reference to a Firestore collection
|
|
15
14
|
*/
|
|
16
|
-
collectionReference:
|
|
15
|
+
collectionReference: CollectionReference<AppModelType, AppModelType>;
|
|
17
16
|
/**
|
|
18
17
|
* Non composite filter constraints such as limit, order, where
|
|
19
18
|
*/
|
|
@@ -21,7 +20,7 @@ type UseCountQueryOptions<AppModelType extends AppModel = AppModel> = {
|
|
|
21
20
|
/**
|
|
22
21
|
* Composite filter
|
|
23
22
|
*/
|
|
24
|
-
compositeFilter?:
|
|
23
|
+
compositeFilter?: QueryCompositeFilterConstraint;
|
|
25
24
|
};
|
|
26
25
|
/**
|
|
27
26
|
* Executes a query with specified constraints and returns the count of matched documents.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UseMutationOptions } from "@tanstack/react-query";
|
|
2
|
-
import {
|
|
2
|
+
import { DocumentReference, WithFieldValue, DocumentData } from "@react-native-firebase/firestore";
|
|
3
3
|
import { AppModel } from "../../types/index.js";
|
|
4
4
|
/**
|
|
5
5
|
* @inline
|
|
@@ -14,7 +14,7 @@ export type UseDeleteDocMutationOptions<AppModelType extends AppModel = AppModel
|
|
|
14
14
|
/**
|
|
15
15
|
* A reference to a firestore document
|
|
16
16
|
*/
|
|
17
|
-
reference:
|
|
17
|
+
reference: DocumentReference<AppModelType, AppModelType> | null;
|
|
18
18
|
/**
|
|
19
19
|
* Options for useMutation hook excluding mutationFn. MutationKey will be equal to reference.path by default.
|
|
20
20
|
*/
|
|
@@ -44,4 +44,4 @@ export type UseDeleteDocMutationOptions<AppModelType extends AppModel = AppModel
|
|
|
44
44
|
* };
|
|
45
45
|
* ```
|
|
46
46
|
*/
|
|
47
|
-
export declare const useDeleteDocMutation: <AppModelType extends
|
|
47
|
+
export declare const useDeleteDocMutation: <AppModelType extends DocumentData = DocumentData, TContext = unknown>({ reference, options }: UseDeleteDocMutationOptions<AppModelType, TContext>) => import("@tanstack/react-query").UseMutationResult<void, Error, void, TContext>;
|
|
@@ -11,7 +11,7 @@ export type UseDocReferenceOptions<AppModelType extends AppModel = AppModel> = O
|
|
|
11
11
|
*
|
|
12
12
|
* @param {UseDocReferenceOptions<AppModelType>} options - Options
|
|
13
13
|
*
|
|
14
|
-
* @returns {
|
|
14
|
+
* @returns {DocumentReference<AppModelType, AppModelType> | null} A reference to a Firestore document
|
|
15
15
|
*
|
|
16
16
|
* @example
|
|
17
17
|
* ```jsx
|
|
@@ -23,4 +23,4 @@ export type UseDocReferenceOptions<AppModelType extends AppModel = AppModel> = O
|
|
|
23
23
|
* };
|
|
24
24
|
* ```
|
|
25
25
|
*/
|
|
26
|
-
export declare const useDocReference: <AppModelType extends AppModel = AppModel>({ path, reference, pathSegments }: UseDocReferenceOptions<AppModelType>) => import("@react-native-firebase/firestore").
|
|
26
|
+
export declare const useDocReference: <AppModelType extends AppModel = AppModel>({ path, reference, pathSegments }: UseDocReferenceOptions<AppModelType>) => import("@react-native-firebase/firestore").DocumentReference<AppModelType, AppModelType> | null;
|
|
@@ -8,7 +8,7 @@ import { getDocRef } from "./utils/getDocRef.js";
|
|
|
8
8
|
*
|
|
9
9
|
* @param {UseDocReferenceOptions<AppModelType>} options - Options
|
|
10
10
|
*
|
|
11
|
-
* @returns {
|
|
11
|
+
* @returns {DocumentReference<AppModelType, AppModelType> | null} A reference to a Firestore document
|
|
12
12
|
*
|
|
13
13
|
* @example
|
|
14
14
|
* ```jsx
|
|
@@ -13,7 +13,7 @@ export type UseDocReferencesOptions<AppModelType extends AppModel = AppModel> =
|
|
|
13
13
|
*
|
|
14
14
|
* @param {UseDocReferencesOptions<AppModelType>} options - Options
|
|
15
15
|
*
|
|
16
|
-
* @returns {Array<
|
|
16
|
+
* @returns {Array<DocumentReference<AppModelType> | null>} A reference to a Firestore document
|
|
17
17
|
*
|
|
18
18
|
* @example
|
|
19
19
|
* ```jsx
|
|
@@ -25,4 +25,4 @@ export type UseDocReferencesOptions<AppModelType extends AppModel = AppModel> =
|
|
|
25
25
|
* };
|
|
26
26
|
* ```
|
|
27
27
|
*/
|
|
28
|
-
export declare const useDocReferences: <AppModelType extends AppModel = AppModel>({ references }: UseDocReferencesOptions<AppModelType>) => (import("@react-native-firebase/firestore").
|
|
28
|
+
export declare const useDocReferences: <AppModelType extends AppModel = AppModel>({ references }: UseDocReferencesOptions<AppModelType>) => (import("@react-native-firebase/firestore").DocumentReference<AppModelType, AppModelType> | null)[];
|
|
@@ -8,7 +8,7 @@ import { getDocRef } from "./utils/getDocRef.js";
|
|
|
8
8
|
*
|
|
9
9
|
* @param {UseDocReferencesOptions<AppModelType>} options - Options
|
|
10
10
|
*
|
|
11
|
-
* @returns {Array<
|
|
11
|
+
* @returns {Array<DocumentReference<AppModelType> | null>} A reference to a Firestore document
|
|
12
12
|
*
|
|
13
13
|
* @example
|
|
14
14
|
* ```jsx
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CollectionReference } from "@react-native-firebase/firestore";
|
|
2
2
|
import { AppModel } from "../../types/index.js";
|
|
3
3
|
import { type NonFilterQueryConstraint } from "../../types/QueryConstraints.js";
|
|
4
4
|
import { type CompositeFilter } from "./utils/buildCompositeFilter.js";
|
|
@@ -9,7 +9,7 @@ type UseFirestoreQueryEngineOptions<AppModelType extends AppModel = AppModel> =
|
|
|
9
9
|
/**
|
|
10
10
|
* Reference to a Firestore collection
|
|
11
11
|
*/
|
|
12
|
-
collectionReference:
|
|
12
|
+
collectionReference: CollectionReference<AppModelType, AppModelType>;
|
|
13
13
|
/**
|
|
14
14
|
* Non composite filter constraints such as limit, order, where
|
|
15
15
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getDocs, query
|
|
1
|
+
import { getDocs, query } from "@react-native-firebase/firestore";
|
|
2
2
|
import { useCallback } from "react";
|
|
3
3
|
import { buildCompositeFilter } from "./utils/buildCompositeFilter.js";
|
|
4
4
|
import { buildQueryConstraint } from "./utils/buildQueryConstraint.js";
|
|
@@ -25,16 +25,9 @@ import { buildQueryConstraint } from "./utils/buildQueryConstraint.js";
|
|
|
25
25
|
*/
|
|
26
26
|
export const useFirestoreQueryEngine = () => {
|
|
27
27
|
return useCallback(async ({ collectionReference, queryConstraints = [], compositeFilter: inputCompositeFilter }) => {
|
|
28
|
-
const compositeFilter =
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
? inputCompositeFilter?.operator === "OR"
|
|
32
|
-
? or(...compositeFilter)
|
|
33
|
-
: and(...compositeFilter)
|
|
34
|
-
: undefined;
|
|
35
|
-
const queryToExecute = finalCompositeFilter
|
|
36
|
-
? query(collectionReference, finalCompositeFilter, ...queryConstraints.map(buildQueryConstraint))
|
|
37
|
-
: query(collectionReference, ...queryConstraints.map(buildQueryConstraint));
|
|
28
|
+
const compositeFilter = inputCompositeFilter ? buildCompositeFilter(inputCompositeFilter) : null;
|
|
29
|
+
const builtQueryConstraints = queryConstraints.map(buildQueryConstraint);
|
|
30
|
+
const queryToExecute = query(collectionReference, ...[...(compositeFilter ? [compositeFilter] : []), ...builtQueryConstraints]);
|
|
38
31
|
const querySnapshot = await getDocs(queryToExecute);
|
|
39
32
|
const docs = [];
|
|
40
33
|
if (querySnapshot) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DocumentReference } from "@react-native-firebase/firestore";
|
|
2
2
|
import { ReactNativeFirebase } from "@react-native-firebase/app";
|
|
3
3
|
import { AppModel } from "../../types/index.js";
|
|
4
4
|
/**
|
|
@@ -12,7 +12,7 @@ export type UseGetRealtimeDocDataOptions<AppModelType extends AppModel = AppMode
|
|
|
12
12
|
/**
|
|
13
13
|
* A reference to a collection.
|
|
14
14
|
*/
|
|
15
|
-
reference?:
|
|
15
|
+
reference?: DocumentReference<AppModelType, AppModelType>;
|
|
16
16
|
/**
|
|
17
17
|
* Additional path segments that will be applied relative
|
|
18
18
|
* to the first argument.
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CollectionReference, QueryCompositeFilterConstraint, QueryConstraint, QueryNonFilterConstraint } from "@react-native-firebase/firestore";
|
|
2
2
|
import { UseInfiniteQueryOptions as UseReactInfiniteQueryOptions, QueryKey, UseInfiniteQueryResult, InfiniteData } from "@tanstack/react-query";
|
|
3
3
|
import { AppModel } from "../../types/index.js";
|
|
4
|
-
import { QueryFilterConstraint } from "./utils/buildCompositeFilter.js";
|
|
5
4
|
/**
|
|
6
5
|
* @inline
|
|
7
6
|
*/
|
|
@@ -13,7 +12,7 @@ type UseInfiniteQueryOptions<AppModelType extends AppModel = AppModel, TQueryKey
|
|
|
13
12
|
/**
|
|
14
13
|
* Reference to a Firestore collection
|
|
15
14
|
*/
|
|
16
|
-
collectionReference:
|
|
15
|
+
collectionReference: CollectionReference<AppModelType, AppModelType>;
|
|
17
16
|
/**
|
|
18
17
|
* Non composite filter constraints such as limit, order, where
|
|
19
18
|
*/
|
|
@@ -21,7 +20,7 @@ type UseInfiniteQueryOptions<AppModelType extends AppModel = AppModel, TQueryKey
|
|
|
21
20
|
/**
|
|
22
21
|
* Composite filter
|
|
23
22
|
*/
|
|
24
|
-
compositeFilter?:
|
|
23
|
+
compositeFilter?: QueryCompositeFilterConstraint;
|
|
25
24
|
};
|
|
26
25
|
/**
|
|
27
26
|
* Executes an infinite query on a Firestore data source and returns the resulting documents as an array.
|
|
@@ -27,9 +27,7 @@ export const useInfiniteQuery = ({ options, collectionReference, queryConstraint
|
|
|
27
27
|
...options,
|
|
28
28
|
queryFn: async ({ pageParam }) => {
|
|
29
29
|
const allQueryConstraints = [...queryConstraints, ...(pageParam ? [pageParam] : [])];
|
|
30
|
-
const queryToExecute = compositeFilter
|
|
31
|
-
? query(collectionReference, compositeFilter, ...allQueryConstraints)
|
|
32
|
-
: query(collectionReference, ...allQueryConstraints);
|
|
30
|
+
const queryToExecute = query(collectionReference, ...[...(compositeFilter ? [compositeFilter] : []), ...allQueryConstraints]);
|
|
33
31
|
const querySnapshot = await getDocs(queryToExecute);
|
|
34
32
|
const docs = [];
|
|
35
33
|
if (querySnapshot) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CollectionReference, QueryConstraint, QueryNonFilterConstraint } from "@react-native-firebase/firestore";
|
|
2
2
|
import { UseQueryResult, UseQueryOptions as UseReactQueryOptions } from "@tanstack/react-query";
|
|
3
|
+
import { QueryCompositeFilterConstraint } from "firebase/firestore";
|
|
3
4
|
import { AppModel } from "../../types/index.js";
|
|
4
|
-
import { QueryFilterConstraint } from "./utils/buildCompositeFilter.js";
|
|
5
5
|
/**
|
|
6
6
|
* @inline
|
|
7
7
|
*/
|
|
@@ -13,7 +13,7 @@ type UseQueryOptions<AppModelType extends AppModel = AppModel> = {
|
|
|
13
13
|
/**
|
|
14
14
|
* Reference to a Firestore collection
|
|
15
15
|
*/
|
|
16
|
-
collectionReference:
|
|
16
|
+
collectionReference: CollectionReference<AppModelType, AppModelType>;
|
|
17
17
|
/**
|
|
18
18
|
* Non composite filter constraints such as limit, order, where
|
|
19
19
|
*/
|
|
@@ -21,7 +21,7 @@ type UseQueryOptions<AppModelType extends AppModel = AppModel> = {
|
|
|
21
21
|
/**
|
|
22
22
|
* Composite filter
|
|
23
23
|
*/
|
|
24
|
-
compositeFilter?:
|
|
24
|
+
compositeFilter?: QueryCompositeFilterConstraint;
|
|
25
25
|
};
|
|
26
26
|
/**
|
|
27
27
|
* Executes a query on a Firestore data source and returns the resulting documents as an array.
|
|
@@ -26,9 +26,7 @@ export const useQuery = ({ options, collectionReference, queryConstraints = [],
|
|
|
26
26
|
return useReactQuery({
|
|
27
27
|
...options,
|
|
28
28
|
queryFn: async () => {
|
|
29
|
-
const queryToExecute = compositeFilter
|
|
30
|
-
? query(collectionReference, compositeFilter, ...queryConstraints)
|
|
31
|
-
: query(collectionReference, ...queryConstraints);
|
|
29
|
+
const queryToExecute = query(collectionReference, ...[...(compositeFilter ? [compositeFilter] : []), ...queryConstraints]);
|
|
32
30
|
const querySnapshot = await getDocs(queryToExecute);
|
|
33
31
|
const docs = [];
|
|
34
32
|
if (querySnapshot) {
|
|
@@ -18,7 +18,7 @@ export type UseQueryConstraints<AppModelType extends AppModel = AppModel> = {
|
|
|
18
18
|
*
|
|
19
19
|
* @param {UseQueryConstraints<AppModelType>} options
|
|
20
20
|
*
|
|
21
|
-
* @returns {
|
|
21
|
+
* @returns {QueryNonFilterConstraint}
|
|
22
22
|
*
|
|
23
23
|
* @example
|
|
24
24
|
* ```jsx
|
|
@@ -8,7 +8,7 @@ import { buildQueryConstraint } from "./utils/buildQueryConstraint.js";
|
|
|
8
8
|
*
|
|
9
9
|
* @param {UseQueryConstraints<AppModelType>} options
|
|
10
10
|
*
|
|
11
|
-
* @returns {
|
|
11
|
+
* @returns {QueryNonFilterConstraint}
|
|
12
12
|
*
|
|
13
13
|
* @example
|
|
14
14
|
* ```jsx
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { UseMutationOptions } from "@tanstack/react-query";
|
|
2
|
-
import {
|
|
2
|
+
import { runTransaction } from "@react-native-firebase/firestore";
|
|
3
3
|
/**
|
|
4
4
|
* @inline
|
|
5
5
|
*/
|
|
6
|
-
export type UseRunTransactionValues
|
|
6
|
+
export type UseRunTransactionValues<T = unknown> = Parameters<typeof runTransaction<T>>[1];
|
|
7
7
|
/**
|
|
8
8
|
* @inline
|
|
9
9
|
*/
|
|
@@ -11,7 +11,7 @@ export type UseRunTransactionOptions<T = unknown, TContext = unknown> = {
|
|
|
11
11
|
/**
|
|
12
12
|
* Reqct-mutation options that shall omit mutationFn
|
|
13
13
|
*/
|
|
14
|
-
options?: Omit<UseMutationOptions<T, Error, UseRunTransactionValues
|
|
14
|
+
options?: Omit<UseMutationOptions<T, Error, UseRunTransactionValues<T>, TContext>, "mutationFn">;
|
|
15
15
|
};
|
|
16
16
|
/**
|
|
17
17
|
* Executes a Firestore transaction
|
|
@@ -36,4 +36,4 @@ export type UseRunTransactionOptions<T = unknown, TContext = unknown> = {
|
|
|
36
36
|
* };
|
|
37
37
|
* ```
|
|
38
38
|
*/
|
|
39
|
-
export declare const useRunTransaction: <T = unknown, TContext = unknown>({ options }: UseRunTransactionOptions<T, TContext>) => import("@tanstack/react-query").UseMutationResult<T, Error,
|
|
39
|
+
export declare const useRunTransaction: <T = unknown, TContext = unknown>({ options }: UseRunTransactionOptions<T, TContext>) => import("@tanstack/react-query").UseMutationResult<T, Error, (transaction: import("@react-native-firebase/firestore/dist/typescript/lib/types/firestore.js").Transaction) => Promise<T>, TContext>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UseMutationOptions } from "@tanstack/react-query";
|
|
2
|
-
import {
|
|
2
|
+
import { DocumentReference, WithFieldValue } from "@react-native-firebase/firestore";
|
|
3
3
|
import { AppModel } from "../../types/index.js";
|
|
4
4
|
/**
|
|
5
5
|
* @inline
|
|
@@ -17,7 +17,7 @@ export type UseSetDocMutationOptions<AppModelType extends AppModel = AppModel, T
|
|
|
17
17
|
/**
|
|
18
18
|
* Reference to a document that must be written
|
|
19
19
|
*/
|
|
20
|
-
reference:
|
|
20
|
+
reference: DocumentReference<AppModelType, AppModelType> | null;
|
|
21
21
|
/**
|
|
22
22
|
* Options for useMutation hook excluding mutationFn.
|
|
23
23
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UseMutationOptions } from "@tanstack/react-query";
|
|
2
|
-
import {
|
|
2
|
+
import { DocumentReference, UpdateData } from "@react-native-firebase/firestore";
|
|
3
3
|
import { AppModel } from "../../types/index.js";
|
|
4
4
|
/**
|
|
5
5
|
* @inline
|
|
@@ -17,7 +17,7 @@ export type UseUpdateDocMutationOptions<AppModelType extends AppModel = AppModel
|
|
|
17
17
|
/**
|
|
18
18
|
* Reference to a document that must be updated
|
|
19
19
|
*/
|
|
20
|
-
reference:
|
|
20
|
+
reference: DocumentReference<AppModelType, AppModelType> | null;
|
|
21
21
|
/**
|
|
22
22
|
* Options for useMutation hook excluding mutationFn.
|
|
23
23
|
*/
|
|
@@ -1,20 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { WhereFilterOp } from "@react-native-firebase/firestore";
|
|
2
|
+
import { QueryCompositeFilterConstraint } from "firebase/firestore";
|
|
2
3
|
import { AppModel } from "../../../types/index.js";
|
|
3
|
-
export type QueryFilterConstraint = FirebaseFirestoreTypes.QueryCompositeFilterConstraint | FirebaseFirestoreTypes.QueryFilterConstraint;
|
|
4
4
|
export type QueryElement<AppModelType extends AppModel = AppModel> = {
|
|
5
|
-
|
|
6
|
-
children?: QueryElement[];
|
|
7
|
-
field?: keyof (AppModelType & {
|
|
5
|
+
field: keyof (AppModelType & {
|
|
8
6
|
documentId?: string[];
|
|
9
7
|
});
|
|
10
|
-
value
|
|
11
|
-
op
|
|
8
|
+
value: AppModelType[keyof AppModelType];
|
|
9
|
+
op: WhereFilterOp;
|
|
12
10
|
};
|
|
13
11
|
export type CompositeFilter<AppModelType extends AppModel = AppModel> = {
|
|
14
12
|
operator: "OR" | "AND";
|
|
15
|
-
children: QueryElement<AppModelType & {
|
|
13
|
+
children: Array<CompositeFilter<AppModelType> | QueryElement<AppModelType & {
|
|
16
14
|
documentId?: string[];
|
|
17
|
-
}
|
|
15
|
+
}>>;
|
|
18
16
|
};
|
|
19
17
|
/**
|
|
20
18
|
* Constructs a composite or where query filter based on the provided query structure.
|
|
@@ -24,7 +22,7 @@ export type CompositeFilter<AppModelType extends AppModel = AppModel> = {
|
|
|
24
22
|
*
|
|
25
23
|
* @param {QueryElement<AppModelType>} query
|
|
26
24
|
*
|
|
27
|
-
* @returns {
|
|
25
|
+
* @returns {QueryCompositeFilterConstraint | null}
|
|
28
26
|
*
|
|
29
27
|
* @example
|
|
30
28
|
* ```jsx
|
|
@@ -44,4 +42,4 @@ export type CompositeFilter<AppModelType extends AppModel = AppModel> = {
|
|
|
44
42
|
* };
|
|
45
43
|
* ```
|
|
46
44
|
*/
|
|
47
|
-
export declare const buildCompositeFilter: <AppModelType extends AppModel = AppModel>(query: QueryElement<AppModelType>) =>
|
|
45
|
+
export declare const buildCompositeFilter: <AppModelType extends AppModel = AppModel>(query: CompositeFilter<AppModelType> | QueryElement<AppModelType>) => QueryCompositeFilterConstraint | null;
|
|
@@ -7,7 +7,7 @@ import { and, or, where, FieldPath } from "@react-native-firebase/firestore";
|
|
|
7
7
|
*
|
|
8
8
|
* @param {QueryElement<AppModelType>} query
|
|
9
9
|
*
|
|
10
|
-
* @returns {
|
|
10
|
+
* @returns {QueryCompositeFilterConstraint | null}
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
13
|
* ```jsx
|
|
@@ -29,17 +29,23 @@ import { and, or, where, FieldPath } from "@react-native-firebase/firestore";
|
|
|
29
29
|
*/
|
|
30
30
|
export const buildCompositeFilter = (query) => {
|
|
31
31
|
if (query.children) {
|
|
32
|
-
const queryConstraints = query.children
|
|
32
|
+
const queryConstraints = query.children
|
|
33
|
+
.map(buildCompositeFilter)
|
|
34
|
+
.filter((constraint) => !!constraint);
|
|
33
35
|
if (queryConstraints.length <= 0) {
|
|
34
36
|
return null;
|
|
35
37
|
}
|
|
36
38
|
if (queryConstraints.length <= 1) {
|
|
37
|
-
return queryConstraints[0];
|
|
39
|
+
return and(queryConstraints[0]);
|
|
38
40
|
}
|
|
39
|
-
return query.operator === "OR"
|
|
41
|
+
return query.operator === "OR"
|
|
42
|
+
? or(...queryConstraints)
|
|
43
|
+
: and(...queryConstraints);
|
|
40
44
|
}
|
|
41
45
|
if (query.field && query.op) {
|
|
42
|
-
return where(query.field === "documentId"
|
|
46
|
+
return and(where(query.field === "documentId"
|
|
47
|
+
? new FieldPath("__name__")
|
|
48
|
+
: query.field, query.op, query.value));
|
|
43
49
|
}
|
|
44
50
|
return null;
|
|
45
51
|
};
|
|
@@ -7,7 +7,7 @@ import { AppModel, type NonFilterQueryConstraint } from "../../../types/index.js
|
|
|
7
7
|
*
|
|
8
8
|
* @param {NonFilterQueryConstraint<AppModelType>} constraint
|
|
9
9
|
*
|
|
10
|
-
* @returns {
|
|
10
|
+
* @returns {QueryNonFilterConstraint}
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
13
|
* ```jsx
|
|
@@ -6,7 +6,7 @@ import { orderBy, startAt, startAfter, endAt, endBefore, limit, limitToLast } fr
|
|
|
6
6
|
*
|
|
7
7
|
* @param {NonFilterQueryConstraint<AppModelType>} constraint
|
|
8
8
|
*
|
|
9
|
-
* @returns {
|
|
9
|
+
* @returns {QueryNonFilterConstraint}
|
|
10
10
|
*
|
|
11
11
|
* @example
|
|
12
12
|
* ```jsx
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CollectionReference, DocumentReference, Firestore } from "@react-native-firebase/firestore";
|
|
2
2
|
import { AppModel } from "../../../types/index.js";
|
|
3
3
|
/**
|
|
4
4
|
* @inline
|
|
5
5
|
*/
|
|
6
6
|
export type GetDocRefOptions<AppModelType extends AppModel = AppModel> = {
|
|
7
|
-
db:
|
|
8
|
-
reference?:
|
|
7
|
+
db: Firestore;
|
|
8
|
+
reference?: CollectionReference<AppModelType, AppModelType> | DocumentReference<AppModelType, AppModelType>;
|
|
9
9
|
path?: string;
|
|
10
10
|
pathSegments?: string[];
|
|
11
11
|
};
|
|
@@ -19,4 +19,4 @@ export type GetDocRefOptions<AppModelType extends AppModel = AppModel> = {
|
|
|
19
19
|
*
|
|
20
20
|
* @returns {DocumentReference<AppModelType, AppModelType>} Returns a document reference
|
|
21
21
|
*/
|
|
22
|
-
export declare const getDocRef: <AppModelType extends AppModel = AppModel>({ db, reference, path, pathSegments }: GetDocRefOptions<AppModelType>) =>
|
|
22
|
+
export declare const getDocRef: <AppModelType extends AppModel = AppModel>({ db, reference, path, pathSegments }: GetDocRefOptions<AppModelType>) => DocumentReference<AppModelType, AppModelType> | null;
|
|
@@ -15,4 +15,4 @@ export type GetDocSnapOptions<AppModelType extends AppModel = AppModel> = GetDoc
|
|
|
15
15
|
*
|
|
16
16
|
* @returns {Promise<DocumentSnapshot<AppModelType, AppModelType> | null>} Returns a document reference
|
|
17
17
|
*/
|
|
18
|
-
export declare const getDocSnap: <AppModelType extends AppModel = AppModel>({ db, reference, path, pathSegments }: GetDocSnapOptions<AppModelType>) => Promise<import("@react-native-firebase/firestore").
|
|
18
|
+
export declare const getDocSnap: <AppModelType extends AppModel = AppModel>({ db, reference, path, pathSegments }: GetDocSnapOptions<AppModelType>) => Promise<import("@react-native-firebase/firestore/dist/typescript/lib/types/firestore.js").DocumentSnapshot<AppModelType, AppModelType> | null>;
|
|
@@ -12,7 +12,7 @@ import { getDocRef } from "./getDocRef.js";
|
|
|
12
12
|
* @returns {Promise<DocumentSnapshot<AppModelType, AppModelType> | null>} Returns a document reference
|
|
13
13
|
*/
|
|
14
14
|
export const getDocSnap = async ({ db, reference, path, pathSegments }) => {
|
|
15
|
-
const docRef =
|
|
15
|
+
const docRef = getDocRef({ db, reference, path, pathSegments });
|
|
16
16
|
if (docRef) {
|
|
17
17
|
return await firestoreGetDoc(docRef);
|
|
18
18
|
}
|
package/package.json
CHANGED
|
@@ -5,14 +5,14 @@
|
|
|
5
5
|
"url": "https://github.com/vpishuk/react-query-firebase/issues"
|
|
6
6
|
},
|
|
7
7
|
"peerDependencies": {
|
|
8
|
-
"@react-native-firebase/analytics": "^
|
|
9
|
-
"@react-native-firebase/app": "^
|
|
10
|
-
"@react-native-firebase/auth": "^
|
|
11
|
-
"@react-native-firebase/crashlytics": "^
|
|
12
|
-
"@react-native-firebase/firestore": "^
|
|
13
|
-
"@react-native-firebase/installations": "^
|
|
14
|
-
"@react-native-firebase/messaging": "^
|
|
15
|
-
"@react-native-firebase/remote-config": "^
|
|
8
|
+
"@react-native-firebase/analytics": "^24.x.x",
|
|
9
|
+
"@react-native-firebase/app": "^24.x.x",
|
|
10
|
+
"@react-native-firebase/auth": "^24.x.x",
|
|
11
|
+
"@react-native-firebase/crashlytics": "^24.x.x",
|
|
12
|
+
"@react-native-firebase/firestore": "^24.x.x",
|
|
13
|
+
"@react-native-firebase/installations": "^24.x.x",
|
|
14
|
+
"@react-native-firebase/messaging": "^24.x.x",
|
|
15
|
+
"@react-native-firebase/remote-config": "^24.x.x",
|
|
16
16
|
"@tanstack/react-query": "^5.x.x",
|
|
17
17
|
"firebase": "^11.x.x || ^12.x.x",
|
|
18
18
|
"react": "^18.x.x || ^19.x.x"
|
|
@@ -23,34 +23,34 @@
|
|
|
23
23
|
"description": "This module offers react hooks to work with Firebase on react-native and web platforms",
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@eslint-community/eslint-plugin-eslint-comments": "^4.7.1",
|
|
26
|
-
"@react-native-firebase/analytics": "^
|
|
27
|
-
"@react-native-firebase/app": "^
|
|
28
|
-
"@react-native-firebase/auth": "^
|
|
29
|
-
"@react-native-firebase/crashlytics": "^
|
|
30
|
-
"@react-native-firebase/firestore": "^
|
|
31
|
-
"@react-native-firebase/installations": "^
|
|
32
|
-
"@react-native-firebase/messaging": "^
|
|
33
|
-
"@react-native-firebase/remote-config": "^
|
|
34
|
-
"@tanstack/react-query": "^5.
|
|
26
|
+
"@react-native-firebase/analytics": "^24.0.0",
|
|
27
|
+
"@react-native-firebase/app": "^24.0.0",
|
|
28
|
+
"@react-native-firebase/auth": "^24.0.0",
|
|
29
|
+
"@react-native-firebase/crashlytics": "^24.0.0",
|
|
30
|
+
"@react-native-firebase/firestore": "^24.0.0",
|
|
31
|
+
"@react-native-firebase/installations": "^24.0.0",
|
|
32
|
+
"@react-native-firebase/messaging": "^24.0.0",
|
|
33
|
+
"@react-native-firebase/remote-config": "^24.0.0",
|
|
34
|
+
"@tanstack/react-query": "^5.99.2",
|
|
35
35
|
"@types/react": "^19.2.14",
|
|
36
36
|
"eslint": "^9.39.4",
|
|
37
37
|
"eslint-config-prettier": "^10.1.8",
|
|
38
38
|
"eslint-plugin-import": "^2.32.0",
|
|
39
|
-
"eslint-plugin-jest": "^29.15.
|
|
39
|
+
"eslint-plugin-jest": "^29.15.2",
|
|
40
40
|
"eslint-plugin-jsonc": "^2.21.1",
|
|
41
41
|
"eslint-plugin-prettier": "^5.5.5",
|
|
42
42
|
"eslint-plugin-react": "^7.37.5",
|
|
43
|
-
"eslint-plugin-react-hooks": "^7.
|
|
44
|
-
"firebase": "^12.
|
|
43
|
+
"eslint-plugin-react-hooks": "^7.1.1",
|
|
44
|
+
"firebase": "^12.12.1",
|
|
45
45
|
"husky": "^9.1.7",
|
|
46
46
|
"lint-staged": "^16.4.0",
|
|
47
|
-
"prettier": "^3.8.
|
|
48
|
-
"react": "^19.2.
|
|
49
|
-
"typedoc": "^0.28.
|
|
50
|
-
"typedoc-plugin-markdown": "^4.
|
|
47
|
+
"prettier": "^3.8.3",
|
|
48
|
+
"react": "^19.2.5",
|
|
49
|
+
"typedoc": "^0.28.19",
|
|
50
|
+
"typedoc-plugin-markdown": "^4.11.0",
|
|
51
51
|
"typedoc-vitepress-theme": "^1.1.2",
|
|
52
52
|
"typescript": "^5.9.3",
|
|
53
|
-
"typescript-eslint": "^8.
|
|
53
|
+
"typescript-eslint": "^8.59.0",
|
|
54
54
|
"vitepress": "^1.6.4"
|
|
55
55
|
},
|
|
56
56
|
"homepage": "https://github.com/vpishuk/react-query-firebase",
|
|
@@ -93,5 +93,5 @@
|
|
|
93
93
|
"docs:build": "vitepress build docs",
|
|
94
94
|
"docs:preview": "vitepress preview docs"
|
|
95
95
|
},
|
|
96
|
-
"version": "3.
|
|
96
|
+
"version": "3.3.0"
|
|
97
97
|
}
|