react-query-firebase 2.13.2 → 2.13.4
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/index.d.ts +2 -0
- package/dist/index.js +4 -0
- package/dist/react-native/analytics/index.d.ts +3 -0
- package/dist/react-native/analytics/index.js +3 -0
- package/{react-native/analytics/useAnalytics.ts → dist/react-native/analytics/useAnalytics.js} +1 -3
- package/{react-native → dist/react-native}/analytics/useLogEvent.js +1 -1
- package/{react-native → dist/react-native}/analytics/useSetAnalyticsCollectionEnabled.js +1 -1
- package/dist/react-native/auth/index.d.ts +19 -0
- package/dist/react-native/auth/index.js +19 -0
- package/{react-native/auth/useAuth.ts → dist/react-native/auth/useAuth.js} +1 -3
- package/{react-native → dist/react-native}/auth/useAuthStateReady.js +1 -1
- package/{react-native → dist/react-native}/auth/useCreateUserWitEmailAndPasswordMutation.js +2 -2
- package/{react-native → dist/react-native}/auth/useCurrentUser.js +1 -1
- package/{react-native → dist/react-native}/auth/useIdToken.js +3 -3
- package/{react-native → dist/react-native}/auth/useLinkWithCredentialMutation.js +1 -1
- package/{react-native → dist/react-native}/auth/useReauthenticateWitCredentialMutation.js +1 -1
- package/{react-native → dist/react-native}/auth/useReauthenticateWitRedirectMutation.js +1 -1
- package/{react-native → dist/react-native}/auth/useSendEmailVerificationMutation.js +1 -1
- package/{react-native → dist/react-native}/auth/useSignInAnonymouslyMutation.js +2 -2
- package/{react-native → dist/react-native}/auth/useSignInWitEmailAndPasswordMutation.js +2 -2
- package/{react-native → dist/react-native}/auth/useSignInWitRedirectMutation.js +2 -2
- package/{react-native → dist/react-native}/auth/useSignInWithCredentialMutation.js +2 -2
- package/{react-native → dist/react-native}/auth/useSignOutMutation.js +2 -2
- package/{react-native → dist/react-native}/auth/useUpdateProfileMutation.js +1 -1
- package/{react-native → dist/react-native}/context/FirebaseContextProvider.js +2 -2
- package/dist/react-native/context/index.d.ts +1 -0
- package/dist/react-native/context/index.js +1 -0
- package/dist/react-native/firestore/index.d.ts +23 -0
- package/dist/react-native/firestore/index.js +23 -0
- package/{react-native → dist/react-native}/firestore/useAddDocMutation.d.ts +1 -1
- package/{react-native → dist/react-native}/firestore/useBatchWrite.js +1 -1
- package/{react-native → dist/react-native}/firestore/useCollectionReference.d.ts +1 -1
- package/{react-native → dist/react-native}/firestore/useCollectionReference.js +1 -1
- package/{react-native → dist/react-native}/firestore/useCompositeFilter.d.ts +2 -2
- package/{react-native → dist/react-native}/firestore/useCompositeFilter.js +1 -1
- package/{react-native → dist/react-native}/firestore/useCountQuery.d.ts +2 -2
- package/{react-native → dist/react-native}/firestore/useDeleteDocMutation.d.ts +1 -1
- package/{react-native → dist/react-native}/firestore/useDocReference.d.ts +3 -4
- package/{react-native → dist/react-native}/firestore/useDocReference.js +6 -8
- package/{react-native → dist/react-native}/firestore/useDocReferences.d.ts +2 -2
- package/{react-native → dist/react-native}/firestore/useDocReferences.js +2 -2
- package/{web → dist/react-native}/firestore/useEnsureDoc.d.ts +2 -2
- package/{react-native → dist/react-native}/firestore/useEnsureDoc.js +3 -3
- package/{react-native/firestore/useFirestore.ts → dist/react-native/firestore/useFirestore.js} +1 -2
- package/{react-native → dist/react-native}/firestore/useGetDocData.d.ts +2 -2
- package/{web → dist/react-native}/firestore/useGetDocData.js +2 -2
- package/{react-native → dist/react-native}/firestore/useGetRealtimeDocData.d.ts +1 -1
- package/{react-native → dist/react-native}/firestore/useGetRealtimeDocData.js +1 -1
- package/{react-native → dist/react-native}/firestore/useInfiniteQuery.d.ts +2 -2
- package/{react-native → dist/react-native}/firestore/useQuery.d.ts +2 -2
- package/{react-native → dist/react-native}/firestore/useQueryConstraints.d.ts +2 -2
- package/{react-native → dist/react-native}/firestore/useQueryConstraints.js +1 -1
- package/{react-native → dist/react-native}/firestore/useRunTransaction.js +1 -1
- package/{react-native → dist/react-native}/firestore/useSetDocMutation.d.ts +1 -1
- package/{react-native → dist/react-native}/firestore/useUpdateDocMutation.d.ts +1 -1
- package/{react-native → dist/react-native}/firestore/utils/buildCompositeFilter.d.ts +1 -1
- package/{react-native → dist/react-native}/firestore/utils/buildQueryConstraint.d.ts +1 -1
- package/{react-native → dist/react-native}/firestore/utils/getDocData.d.ts +2 -2
- package/{react-native → dist/react-native}/firestore/utils/getDocData.js +1 -1
- package/{react-native → dist/react-native}/firestore/utils/getDocRef.d.ts +1 -1
- package/{react-native → dist/react-native}/firestore/utils/getDocSnap.d.ts +2 -2
- package/{react-native → dist/react-native}/firestore/utils/getDocSnap.js +1 -1
- package/dist/react-native/index.d.ts +1 -0
- package/dist/react-native/index.js +1 -0
- package/dist/react-native/remoteConfig/index.d.ts +3 -0
- package/dist/react-native/remoteConfig/index.js +3 -0
- package/{react-native → dist/react-native}/remoteConfig/useFetchAndActivate.js +1 -1
- package/{react-native → dist/react-native}/remoteConfig/useGetValue.js +1 -1
- package/{react-native/remoteConfig/useRemoteConfig.ts → dist/react-native/remoteConfig/useRemoteConfig.js} +1 -2
- package/{types → dist/types}/QueryConstraints.d.ts +1 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.js +2 -0
- package/dist/web/analytics/index.d.ts +3 -0
- package/dist/web/analytics/index.js +3 -0
- package/{web/analytics/useAnalytics.ts → dist/web/analytics/useAnalytics.js} +1 -3
- package/{web → dist/web}/analytics/useLogEvent.js +1 -1
- package/{web → dist/web}/analytics/useSetAnalyticsCollectionEnabled.js +1 -1
- package/dist/web/auth/index.d.ts +20 -0
- package/dist/web/auth/index.js +20 -0
- package/{web/auth/useAuth.ts → dist/web/auth/useAuth.js} +1 -3
- package/{web → dist/web}/auth/useAuthStateReady.js +4 -8
- package/{web → dist/web}/auth/useCreateUserWitEmailAndPasswordMutation.js +2 -2
- package/{web → dist/web}/auth/useCurrentUser.js +1 -1
- package/{web → dist/web}/auth/useGetRedirectResultMutation.js +2 -2
- package/{web → dist/web}/auth/useIdToken.js +3 -3
- package/{web → dist/web}/auth/useLinkWithCredentialMutation.js +1 -1
- package/{web → dist/web}/auth/useReauthenticateWitCredentialMutation.js +1 -1
- package/{web → dist/web}/auth/useReauthenticateWitRedirectMutation.js +1 -1
- package/{web → dist/web}/auth/useSendEmailVerificationMutation.js +1 -1
- package/{web → dist/web}/auth/useSignInAnonymouslyMutation.js +2 -2
- package/{web → dist/web}/auth/useSignInWitEmailAndPasswordMutation.js +2 -2
- package/{web → dist/web}/auth/useSignInWitRedirectMutation.js +2 -2
- package/{web → dist/web}/auth/useSignInWithCredentialMutation.js +2 -2
- package/{web → dist/web}/auth/useSignOutMutation.js +2 -2
- package/{web → dist/web}/auth/useUpdateProfileMutation.js +1 -1
- package/{web → dist/web}/context/FirebaseContextProvider.js +2 -2
- package/dist/web/context/index.d.ts +1 -0
- package/dist/web/context/index.js +1 -0
- package/dist/web/firestore/index.d.ts +23 -0
- package/dist/web/firestore/index.js +23 -0
- package/{web → dist/web}/firestore/useAddDocMutation.d.ts +1 -1
- package/{web → dist/web}/firestore/useBatchWrite.js +1 -1
- package/{web → dist/web}/firestore/useCollectionReference.d.ts +1 -1
- package/{web → dist/web}/firestore/useCollectionReference.js +1 -1
- package/{web → dist/web}/firestore/useCompositeFilter.d.ts +2 -2
- package/{web → dist/web}/firestore/useCompositeFilter.js +1 -1
- package/{web → dist/web}/firestore/useCountQuery.d.ts +2 -2
- package/{web → dist/web}/firestore/useDeleteDocMutation.d.ts +1 -1
- package/{web → dist/web}/firestore/useDocReference.d.ts +3 -4
- package/{web → dist/web}/firestore/useDocReference.js +6 -8
- package/{web → dist/web}/firestore/useDocReferences.d.ts +2 -2
- package/{web → dist/web}/firestore/useDocReferences.js +2 -2
- package/{react-native → dist/web}/firestore/useEnsureDoc.d.ts +2 -2
- package/{web → dist/web}/firestore/useEnsureDoc.js +3 -3
- package/{web/firestore/useFirestore.ts → dist/web/firestore/useFirestore.js} +1 -2
- package/{web → dist/web}/firestore/useGetDocData.d.ts +2 -2
- package/{react-native → dist/web}/firestore/useGetDocData.js +2 -2
- package/{web → dist/web}/firestore/useGetRealtimeDocData.d.ts +1 -1
- package/{web → dist/web}/firestore/useGetRealtimeDocData.js +1 -1
- package/{web → dist/web}/firestore/useInfiniteQuery.d.ts +2 -2
- package/{web → dist/web}/firestore/useQuery.d.ts +2 -2
- package/{web → dist/web}/firestore/useQueryConstraints.d.ts +2 -2
- package/{web → dist/web}/firestore/useQueryConstraints.js +1 -1
- package/{web → dist/web}/firestore/useRunTransaction.js +1 -1
- package/{web → dist/web}/firestore/useSetDocMutation.d.ts +1 -1
- package/{web → dist/web}/firestore/useUpdateDocMutation.d.ts +1 -1
- package/{web → dist/web}/firestore/utils/buildCompositeFilter.d.ts +1 -1
- package/{web → dist/web}/firestore/utils/buildQueryConstraint.d.ts +1 -1
- package/{web → dist/web}/firestore/utils/getDocData.d.ts +2 -2
- package/{web → dist/web}/firestore/utils/getDocData.js +1 -1
- package/{web → dist/web}/firestore/utils/getDocRef.d.ts +1 -1
- package/{web → dist/web}/firestore/utils/getDocSnap.d.ts +2 -2
- package/{web → dist/web}/firestore/utils/getDocSnap.js +1 -1
- package/dist/web/index.d.ts +1 -0
- package/dist/web/index.js +1 -0
- package/dist/web/remoteConfig/index.d.ts +3 -0
- package/dist/web/remoteConfig/index.js +3 -0
- package/{web → dist/web}/remoteConfig/useFetchAndActivate.js +1 -1
- package/{web → dist/web}/remoteConfig/useGetValue.js +1 -1
- package/{web/remoteConfig/useRemoteConfig.ts → dist/web/remoteConfig/useRemoteConfig.js} +1 -2
- package/package.json +45 -16
- package/react-native/analytics/index.d.ts +0 -3
- package/react-native/analytics/index.js +0 -3
- package/react-native/analytics/index.ts +0 -3
- package/react-native/analytics/useAnalytics.js +0 -10
- package/react-native/analytics/useLogEvent.ts +0 -34
- package/react-native/analytics/useSetAnalyticsCollectionEnabled.ts +0 -22
- package/react-native/auth/index.d.ts +0 -19
- package/react-native/auth/index.js +0 -19
- package/react-native/auth/index.ts +0 -19
- package/react-native/auth/mutation-keys.ts +0 -22
- package/react-native/auth/useAppleAuthProviderCredential.ts +0 -31
- package/react-native/auth/useAuth.js +0 -10
- package/react-native/auth/useAuthStateReady.ts +0 -39
- package/react-native/auth/useCreateUserWitEmailAndPasswordMutation.ts +0 -38
- package/react-native/auth/useCurrentUser.ts +0 -26
- package/react-native/auth/useEmailAuthProviderCredential.ts +0 -38
- package/react-native/auth/useFacebookAuthProviderCredential.ts +0 -31
- package/react-native/auth/useIdToken.ts +0 -83
- package/react-native/auth/useLinkWithCredentialMutation.ts +0 -35
- package/react-native/auth/useReauthenticateWitCredentialMutation.ts +0 -36
- package/react-native/auth/useReauthenticateWitRedirectMutation.ts +0 -42
- package/react-native/auth/useSendEmailVerificationMutation.ts +0 -33
- package/react-native/auth/useSignInAnonymouslyMutation.ts +0 -52
- package/react-native/auth/useSignInWitEmailAndPasswordMutation.ts +0 -39
- package/react-native/auth/useSignInWitRedirectMutation.ts +0 -38
- package/react-native/auth/useSignInWithCredentialMutation.ts +0 -36
- package/react-native/auth/useSignOutMutation.ts +0 -28
- package/react-native/auth/useUpdateProfileMutation.ts +0 -30
- package/react-native/context/FirebaseContext.ts +0 -25
- package/react-native/context/FirebaseContextProvider.tsx +0 -264
- package/react-native/context/index.d.ts +0 -1
- package/react-native/context/index.js +0 -1
- package/react-native/context/index.ts +0 -1
- package/react-native/firestore/index.d.ts +0 -23
- package/react-native/firestore/index.js +0 -23
- package/react-native/firestore/index.ts +0 -23
- package/react-native/firestore/useAddDocMutation.ts +0 -80
- package/react-native/firestore/useBatchWrite.ts +0 -58
- package/react-native/firestore/useCollectionReference.ts +0 -58
- package/react-native/firestore/useCompositeFilter.ts +0 -60
- package/react-native/firestore/useCountQuery.ts +0 -85
- package/react-native/firestore/useDeleteDocMutation.ts +0 -71
- package/react-native/firestore/useDocReference.ts +0 -50
- package/react-native/firestore/useDocReferences.ts +0 -40
- package/react-native/firestore/useEnsureDoc.ts +0 -79
- package/react-native/firestore/useFirestore.js +0 -13
- package/react-native/firestore/useGetDocData.ts +0 -52
- package/react-native/firestore/useGetRealtimeDocData.ts +0 -106
- package/react-native/firestore/useInfiniteQuery.ts +0 -115
- package/react-native/firestore/useQuery.ts +0 -89
- package/react-native/firestore/useQueryConstraints.ts +0 -44
- package/react-native/firestore/useRunTransaction.ts +0 -55
- package/react-native/firestore/useSetDocMutation.ts +0 -76
- package/react-native/firestore/useUpdateDocMutation.ts +0 -77
- package/react-native/firestore/utils/buildCompositeFilter.ts +0 -75
- package/react-native/firestore/utils/buildQueryConstraint.ts +0 -54
- package/react-native/firestore/utils/getDocData.ts +0 -33
- package/react-native/firestore/utils/getDocRef.ts +0 -41
- package/react-native/firestore/utils/getDocSnap.ts +0 -34
- package/react-native/index.d.ts +0 -1
- package/react-native/index.js +0 -1
- package/react-native/index.ts +0 -1
- package/react-native/remoteConfig/index.d.ts +0 -3
- package/react-native/remoteConfig/index.js +0 -3
- package/react-native/remoteConfig/index.ts +0 -3
- package/react-native/remoteConfig/useFetchAndActivate.ts +0 -36
- package/react-native/remoteConfig/useGetValue.ts +0 -16
- package/react-native/remoteConfig/useRemoteConfig.js +0 -10
- package/types/AppModel.ts +0 -10
- package/types/QueryConstraints.ts +0 -57
- package/types/index.d.ts +0 -2
- package/types/index.js +0 -2
- package/types/index.ts +0 -2
- package/web/analytics/index.d.ts +0 -3
- package/web/analytics/index.js +0 -3
- package/web/analytics/index.ts +0 -3
- package/web/analytics/useAnalytics.js +0 -10
- package/web/analytics/useLogEvent.ts +0 -34
- package/web/analytics/useSetAnalyticsCollectionEnabled.ts +0 -22
- package/web/auth/index.d.ts +0 -20
- package/web/auth/index.js +0 -20
- package/web/auth/index.ts +0 -20
- package/web/auth/mutation-keys.ts +0 -23
- package/web/auth/useAppleAuthProviderCredential.ts +0 -32
- package/web/auth/useAuth.js +0 -10
- package/web/auth/useAuthStateReady.ts +0 -35
- package/web/auth/useCreateUserWitEmailAndPasswordMutation.ts +0 -33
- package/web/auth/useCurrentUser.ts +0 -25
- package/web/auth/useEmailAuthProviderCredential.ts +0 -38
- package/web/auth/useFacebookAuthProviderCredential.ts +0 -31
- package/web/auth/useGetRedirectResultMutation.ts +0 -27
- package/web/auth/useIdToken.ts +0 -83
- package/web/auth/useLinkWithCredentialMutation.ts +0 -30
- package/web/auth/useReauthenticateWitCredentialMutation.ts +0 -31
- package/web/auth/useReauthenticateWitRedirectMutation.ts +0 -37
- package/web/auth/useSendEmailVerificationMutation.ts +0 -28
- package/web/auth/useSignInAnonymouslyMutation.ts +0 -49
- package/web/auth/useSignInWitEmailAndPasswordMutation.ts +0 -34
- package/web/auth/useSignInWitRedirectMutation.ts +0 -33
- package/web/auth/useSignInWithCredentialMutation.ts +0 -31
- package/web/auth/useSignOutMutation.ts +0 -25
- package/web/auth/useUpdateProfileMutation.ts +0 -30
- package/web/context/FirebaseContext.ts +0 -25
- package/web/context/FirebaseContextProvider.tsx +0 -263
- package/web/context/index.d.ts +0 -1
- package/web/context/index.js +0 -1
- package/web/context/index.ts +0 -1
- package/web/firestore/index.d.ts +0 -23
- package/web/firestore/index.js +0 -23
- package/web/firestore/index.ts +0 -23
- package/web/firestore/useAddDocMutation.ts +0 -74
- package/web/firestore/useBatchWrite.ts +0 -58
- package/web/firestore/useCollectionReference.ts +0 -58
- package/web/firestore/useCompositeFilter.ts +0 -55
- package/web/firestore/useCountQuery.ts +0 -90
- package/web/firestore/useDeleteDocMutation.ts +0 -69
- package/web/firestore/useDocReference.ts +0 -50
- package/web/firestore/useDocReferences.ts +0 -40
- package/web/firestore/useEnsureDoc.ts +0 -92
- package/web/firestore/useFirestore.js +0 -13
- package/web/firestore/useGetDocData.ts +0 -52
- package/web/firestore/useGetRealtimeDocData.ts +0 -105
- package/web/firestore/useInfiniteQuery.ts +0 -117
- package/web/firestore/useQuery.ts +0 -94
- package/web/firestore/useQueryConstraints.ts +0 -44
- package/web/firestore/useRunTransaction.ts +0 -56
- package/web/firestore/useSetDocMutation.ts +0 -77
- package/web/firestore/useUpdateDocMutation.ts +0 -78
- package/web/firestore/utils/buildCompositeFilter.ts +0 -73
- package/web/firestore/utils/buildQueryConstraint.ts +0 -55
- package/web/firestore/utils/getDocData.ts +0 -33
- package/web/firestore/utils/getDocRef.ts +0 -43
- package/web/firestore/utils/getDocSnap.ts +0 -34
- package/web/index.d.ts +0 -1
- package/web/index.js +0 -1
- package/web/index.ts +0 -1
- package/web/remoteConfig/index.d.ts +0 -3
- package/web/remoteConfig/index.js +0 -3
- package/web/remoteConfig/index.ts +0 -3
- package/web/remoteConfig/useFetchAndActivate.ts +0 -36
- package/web/remoteConfig/useGetValue.ts +0 -16
- package/web/remoteConfig/useRemoteConfig.js +0 -10
- /package/{react-native → dist/react-native}/analytics/useAnalytics.d.ts +0 -0
- /package/{react-native → dist/react-native}/analytics/useLogEvent.d.ts +0 -0
- /package/{react-native → dist/react-native}/analytics/useSetAnalyticsCollectionEnabled.d.ts +0 -0
- /package/{react-native → dist/react-native}/auth/mutation-keys.d.ts +0 -0
- /package/{react-native → dist/react-native}/auth/mutation-keys.js +0 -0
- /package/{react-native → dist/react-native}/auth/useAppleAuthProviderCredential.d.ts +0 -0
- /package/{react-native → dist/react-native}/auth/useAppleAuthProviderCredential.js +0 -0
- /package/{react-native → dist/react-native}/auth/useAuth.d.ts +0 -0
- /package/{react-native → dist/react-native}/auth/useAuthStateReady.d.ts +0 -0
- /package/{react-native → dist/react-native}/auth/useCreateUserWitEmailAndPasswordMutation.d.ts +0 -0
- /package/{react-native → dist/react-native}/auth/useCurrentUser.d.ts +0 -0
- /package/{react-native → dist/react-native}/auth/useEmailAuthProviderCredential.d.ts +0 -0
- /package/{react-native → dist/react-native}/auth/useEmailAuthProviderCredential.js +0 -0
- /package/{react-native → dist/react-native}/auth/useFacebookAuthProviderCredential.d.ts +0 -0
- /package/{react-native → dist/react-native}/auth/useFacebookAuthProviderCredential.js +0 -0
- /package/{react-native → dist/react-native}/auth/useIdToken.d.ts +0 -0
- /package/{react-native → dist/react-native}/auth/useLinkWithCredentialMutation.d.ts +0 -0
- /package/{react-native → dist/react-native}/auth/useReauthenticateWitCredentialMutation.d.ts +0 -0
- /package/{react-native → dist/react-native}/auth/useReauthenticateWitRedirectMutation.d.ts +0 -0
- /package/{react-native → dist/react-native}/auth/useSendEmailVerificationMutation.d.ts +0 -0
- /package/{react-native → dist/react-native}/auth/useSignInAnonymouslyMutation.d.ts +0 -0
- /package/{react-native → dist/react-native}/auth/useSignInWitEmailAndPasswordMutation.d.ts +0 -0
- /package/{react-native → dist/react-native}/auth/useSignInWitRedirectMutation.d.ts +0 -0
- /package/{react-native → dist/react-native}/auth/useSignInWithCredentialMutation.d.ts +0 -0
- /package/{react-native → dist/react-native}/auth/useSignOutMutation.d.ts +0 -0
- /package/{react-native → dist/react-native}/auth/useUpdateProfileMutation.d.ts +0 -0
- /package/{react-native → dist/react-native}/context/FirebaseContext.d.ts +0 -0
- /package/{react-native → dist/react-native}/context/FirebaseContext.js +0 -0
- /package/{react-native → dist/react-native}/context/FirebaseContextProvider.d.ts +0 -0
- /package/{react-native → dist/react-native}/firestore/useAddDocMutation.js +0 -0
- /package/{react-native → dist/react-native}/firestore/useBatchWrite.d.ts +0 -0
- /package/{react-native → dist/react-native}/firestore/useCountQuery.js +0 -0
- /package/{react-native → dist/react-native}/firestore/useDeleteDocMutation.js +0 -0
- /package/{react-native → dist/react-native}/firestore/useFirestore.d.ts +0 -0
- /package/{react-native → dist/react-native}/firestore/useInfiniteQuery.js +0 -0
- /package/{react-native → dist/react-native}/firestore/useQuery.js +0 -0
- /package/{react-native → dist/react-native}/firestore/useRunTransaction.d.ts +0 -0
- /package/{react-native → dist/react-native}/firestore/useSetDocMutation.js +0 -0
- /package/{react-native → dist/react-native}/firestore/useUpdateDocMutation.js +0 -0
- /package/{react-native → dist/react-native}/firestore/utils/buildCompositeFilter.js +0 -0
- /package/{react-native → dist/react-native}/firestore/utils/buildQueryConstraint.js +0 -0
- /package/{react-native → dist/react-native}/firestore/utils/getDocRef.js +0 -0
- /package/{react-native → dist/react-native}/remoteConfig/useFetchAndActivate.d.ts +0 -0
- /package/{react-native → dist/react-native}/remoteConfig/useGetValue.d.ts +0 -0
- /package/{react-native → dist/react-native}/remoteConfig/useRemoteConfig.d.ts +0 -0
- /package/{types → dist/types}/AppModel.d.ts +0 -0
- /package/{types → dist/types}/AppModel.js +0 -0
- /package/{types → dist/types}/QueryConstraints.js +0 -0
- /package/{web → dist/web}/analytics/useAnalytics.d.ts +0 -0
- /package/{web → dist/web}/analytics/useLogEvent.d.ts +0 -0
- /package/{web → dist/web}/analytics/useSetAnalyticsCollectionEnabled.d.ts +0 -0
- /package/{web → dist/web}/auth/mutation-keys.d.ts +0 -0
- /package/{web → dist/web}/auth/mutation-keys.js +0 -0
- /package/{web → dist/web}/auth/useAppleAuthProviderCredential.d.ts +0 -0
- /package/{web → dist/web}/auth/useAppleAuthProviderCredential.js +0 -0
- /package/{web → dist/web}/auth/useAuth.d.ts +0 -0
- /package/{web → dist/web}/auth/useAuthStateReady.d.ts +0 -0
- /package/{web → dist/web}/auth/useCreateUserWitEmailAndPasswordMutation.d.ts +0 -0
- /package/{web → dist/web}/auth/useCurrentUser.d.ts +0 -0
- /package/{web → dist/web}/auth/useEmailAuthProviderCredential.d.ts +0 -0
- /package/{web → dist/web}/auth/useEmailAuthProviderCredential.js +0 -0
- /package/{web → dist/web}/auth/useFacebookAuthProviderCredential.d.ts +0 -0
- /package/{web → dist/web}/auth/useFacebookAuthProviderCredential.js +0 -0
- /package/{web → dist/web}/auth/useGetRedirectResultMutation.d.ts +0 -0
- /package/{web → dist/web}/auth/useIdToken.d.ts +0 -0
- /package/{web → dist/web}/auth/useLinkWithCredentialMutation.d.ts +0 -0
- /package/{web → dist/web}/auth/useReauthenticateWitCredentialMutation.d.ts +0 -0
- /package/{web → dist/web}/auth/useReauthenticateWitRedirectMutation.d.ts +0 -0
- /package/{web → dist/web}/auth/useSendEmailVerificationMutation.d.ts +0 -0
- /package/{web → dist/web}/auth/useSignInAnonymouslyMutation.d.ts +0 -0
- /package/{web → dist/web}/auth/useSignInWitEmailAndPasswordMutation.d.ts +0 -0
- /package/{web → dist/web}/auth/useSignInWitRedirectMutation.d.ts +0 -0
- /package/{web → dist/web}/auth/useSignInWithCredentialMutation.d.ts +0 -0
- /package/{web → dist/web}/auth/useSignOutMutation.d.ts +0 -0
- /package/{web → dist/web}/auth/useUpdateProfileMutation.d.ts +0 -0
- /package/{web → dist/web}/context/FirebaseContext.d.ts +0 -0
- /package/{web → dist/web}/context/FirebaseContext.js +0 -0
- /package/{web → dist/web}/context/FirebaseContextProvider.d.ts +0 -0
- /package/{web → dist/web}/firestore/useAddDocMutation.js +0 -0
- /package/{web → dist/web}/firestore/useBatchWrite.d.ts +0 -0
- /package/{web → dist/web}/firestore/useCountQuery.js +0 -0
- /package/{web → dist/web}/firestore/useDeleteDocMutation.js +0 -0
- /package/{web → dist/web}/firestore/useFirestore.d.ts +0 -0
- /package/{web → dist/web}/firestore/useInfiniteQuery.js +0 -0
- /package/{web → dist/web}/firestore/useQuery.js +0 -0
- /package/{web → dist/web}/firestore/useRunTransaction.d.ts +0 -0
- /package/{web → dist/web}/firestore/useSetDocMutation.js +0 -0
- /package/{web → dist/web}/firestore/useUpdateDocMutation.js +0 -0
- /package/{web → dist/web}/firestore/utils/buildCompositeFilter.js +0 -0
- /package/{web → dist/web}/firestore/utils/buildQueryConstraint.js +0 -0
- /package/{web → dist/web}/firestore/utils/getDocRef.js +0 -0
- /package/{web → dist/web}/remoteConfig/useFetchAndActivate.d.ts +0 -0
- /package/{web → dist/web}/remoteConfig/useGetValue.d.ts +0 -0
- /package/{web → dist/web}/remoteConfig/useRemoteConfig.d.ts +0 -0
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { collection, CollectionReference, DocumentReference } from "firebase/firestore";
|
|
2
|
-
|
|
3
|
-
import { useMemo } from "react";
|
|
4
|
-
import { useFirestore } from "./useFirestore";
|
|
5
|
-
import { AppModel } from "../../types";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @inline
|
|
9
|
-
*/
|
|
10
|
-
export type UseCollectionReferenceOptions<AppModelType extends AppModel = AppModel> = {
|
|
11
|
-
/**
|
|
12
|
-
* CollectionReference or DocumentReference that is used as a root to lookup a sub-collection
|
|
13
|
-
*/
|
|
14
|
-
reference?: CollectionReference<AppModelType, AppModelType> | DocumentReference<AppModelType, AppModelType>;
|
|
15
|
-
/**
|
|
16
|
-
* A slash-separated path to a collection.
|
|
17
|
-
*/
|
|
18
|
-
path: string;
|
|
19
|
-
/**
|
|
20
|
-
* Additional path segments that will be applied relative
|
|
21
|
-
*/
|
|
22
|
-
pathSegments?: string[];
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Gets a `CollectionReference` instance that refers to a subcollection of
|
|
27
|
-
* `reference` at the specified relative path.
|
|
28
|
-
*
|
|
29
|
-
* @group Hook
|
|
30
|
-
*
|
|
31
|
-
* @param {UseCollectionReferenceOptions<AppModelType>} options - Options
|
|
32
|
-
*
|
|
33
|
-
* @returns {CollectionReference<AppModelType, AppModelType>} A reference to a Firestore collection
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* ```jsx
|
|
37
|
-
* export const MyComponent = () => {
|
|
38
|
-
* const ref = useCollectionReference({
|
|
39
|
-
* path: 'todos'
|
|
40
|
-
* });
|
|
41
|
-
* };
|
|
42
|
-
* ```
|
|
43
|
-
*/
|
|
44
|
-
export const useCollectionReference = <AppModelType extends AppModel = AppModel>({
|
|
45
|
-
path,
|
|
46
|
-
reference,
|
|
47
|
-
pathSegments
|
|
48
|
-
}: UseCollectionReferenceOptions<AppModelType>) => {
|
|
49
|
-
const db = useFirestore();
|
|
50
|
-
|
|
51
|
-
return useMemo(() => {
|
|
52
|
-
return !reference
|
|
53
|
-
? collection(db, path || "", ...(pathSegments || []))
|
|
54
|
-
: reference.type === "collection"
|
|
55
|
-
? collection(reference, path, ...(pathSegments || []))
|
|
56
|
-
: collection(reference, path, ...(pathSegments || []));
|
|
57
|
-
}, [path, reference, pathSegments, db]) as CollectionReference<AppModelType, AppModelType>;
|
|
58
|
-
};
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { and, or } from "firebase/firestore";
|
|
2
|
-
import { useMemo } from "react";
|
|
3
|
-
import { AppModel } from "../../types";
|
|
4
|
-
import { CompositeFilter, buildCompositeFilter, QueryFilterConstraint } from "./utils/buildCompositeFilter";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @inline
|
|
8
|
-
*/
|
|
9
|
-
export type UseCompositeFilter<AppModelType extends AppModel = AppModel> = {
|
|
10
|
-
query?: CompositeFilter<AppModelType>;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* A custom hook that constructs a composite or where query filter based on the provided query structure.
|
|
15
|
-
* It recursively builds query constraints using logical "or" or "and" operators.
|
|
16
|
-
*
|
|
17
|
-
* @group Hook
|
|
18
|
-
*
|
|
19
|
-
* @param {QueryElement<AppModelType>} query
|
|
20
|
-
*
|
|
21
|
-
* @returns {QueryFilterConstraint | null}
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```jsx
|
|
25
|
-
* export const MyComponent = () => {
|
|
26
|
-
* const filter = useCompositeFilter({
|
|
27
|
-
* operator: "AND",
|
|
28
|
-
* children: [
|
|
29
|
-
* {
|
|
30
|
-
* field: "field",
|
|
31
|
-
* value: "value",
|
|
32
|
-
* op: "=="
|
|
33
|
-
* },
|
|
34
|
-
* ...(query ? [query] : [])
|
|
35
|
-
* ]
|
|
36
|
-
* });
|
|
37
|
-
* console.log(filter);
|
|
38
|
-
* };
|
|
39
|
-
* ```
|
|
40
|
-
*/
|
|
41
|
-
export const useCompositeFilter = <AppModelType extends AppModel = AppModel>({
|
|
42
|
-
query
|
|
43
|
-
}: UseCompositeFilter<AppModelType>) => {
|
|
44
|
-
return useMemo(() => {
|
|
45
|
-
const queryConstraints =
|
|
46
|
-
query?.children?.map?.((subQuery) => buildCompositeFilter(subQuery))?.filter<QueryFilterConstraint>?.(
|
|
47
|
-
(constraint) => !!constraint
|
|
48
|
-
) ?? [];
|
|
49
|
-
|
|
50
|
-
if (queryConstraints.length <= 0) {
|
|
51
|
-
return undefined;
|
|
52
|
-
}
|
|
53
|
-
return query?.operator === "OR" ? or(...queryConstraints) : and(...queryConstraints);
|
|
54
|
-
}, [query]);
|
|
55
|
-
};
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getCountFromServer,
|
|
3
|
-
CollectionReference,
|
|
4
|
-
query,
|
|
5
|
-
QueryCompositeFilterConstraint,
|
|
6
|
-
QueryConstraint,
|
|
7
|
-
QueryNonFilterConstraint
|
|
8
|
-
} from "firebase/firestore";
|
|
9
|
-
|
|
10
|
-
import {
|
|
11
|
-
UseQueryResult,
|
|
12
|
-
useQuery as useReactQuery,
|
|
13
|
-
UseQueryOptions as UseReactQueryOptions
|
|
14
|
-
} from "@tanstack/react-query";
|
|
15
|
-
import { QueryFilterConstraint } from "./utils/buildCompositeFilter";
|
|
16
|
-
import { AppModel } from "../../types";
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* @inline
|
|
20
|
-
*/
|
|
21
|
-
type UseCountQueryOptions<AppModelType extends AppModel = AppModel> = {
|
|
22
|
-
/**
|
|
23
|
-
* Reqct-query options that must include queryKey and shall not define queryFn
|
|
24
|
-
*/
|
|
25
|
-
options: Omit<UseReactQueryOptions<number, Error, number>, "queryFn"> &
|
|
26
|
-
Required<Pick<UseReactQueryOptions<number, Error, number>, "queryKey">>;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Reference to a Firestore collection
|
|
30
|
-
*/
|
|
31
|
-
collectionReference: CollectionReference<AppModelType, AppModelType>;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Non composite filter constraints such as limit, order, where
|
|
35
|
-
*/
|
|
36
|
-
queryConstraints?: QueryConstraint[] | QueryNonFilterConstraint[];
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Composite filter
|
|
40
|
-
*/
|
|
41
|
-
compositeFilter?: QueryFilterConstraint;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Executes a query with specified constraints and returns the count of matched documents.
|
|
46
|
-
*
|
|
47
|
-
* @group Hook
|
|
48
|
-
*
|
|
49
|
-
* @param {UseCountQueryOptions<AppModelType>} options - Configuration options for the query.
|
|
50
|
-
*
|
|
51
|
-
* @returns {UseQueryResult<number>} An object containing the number of documents that match the query.
|
|
52
|
-
*
|
|
53
|
-
* @example
|
|
54
|
-
* ```jsx
|
|
55
|
-
* export const MyComponent = () => {
|
|
56
|
-
* const count = useCountQuery({
|
|
57
|
-
* options: {
|
|
58
|
-
* queryKey: ['key']
|
|
59
|
-
* },
|
|
60
|
-
* collectionReference: collection(),
|
|
61
|
-
* });
|
|
62
|
-
* console.log(count);
|
|
63
|
-
* };
|
|
64
|
-
* ```
|
|
65
|
-
*/
|
|
66
|
-
export const useCountQuery = <AppModelType extends AppModel = AppModel>({
|
|
67
|
-
options,
|
|
68
|
-
collectionReference,
|
|
69
|
-
queryConstraints = [],
|
|
70
|
-
compositeFilter
|
|
71
|
-
}: UseCountQueryOptions<AppModelType>): UseQueryResult<number> => {
|
|
72
|
-
return useReactQuery({
|
|
73
|
-
...options,
|
|
74
|
-
queryFn: async () => {
|
|
75
|
-
const queryToExecute = compositeFilter
|
|
76
|
-
? query(
|
|
77
|
-
collectionReference,
|
|
78
|
-
compositeFilter as QueryCompositeFilterConstraint,
|
|
79
|
-
...(queryConstraints as QueryNonFilterConstraint[])
|
|
80
|
-
)
|
|
81
|
-
: query(collectionReference, ...queryConstraints);
|
|
82
|
-
|
|
83
|
-
const querySnapshot = await getCountFromServer(queryToExecute);
|
|
84
|
-
if (querySnapshot) {
|
|
85
|
-
return querySnapshot.data().count;
|
|
86
|
-
}
|
|
87
|
-
return 0;
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
};
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { useMutation, UseMutationOptions } from "@tanstack/react-query";
|
|
2
|
-
import { deleteDoc, WithFieldValue, DocumentReference } from "firebase/firestore";
|
|
3
|
-
|
|
4
|
-
import { FirebaseError } from "firebase/app";
|
|
5
|
-
import { useMemo } from "react";
|
|
6
|
-
import { AppModel } from "../../types";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @inline
|
|
10
|
-
*/
|
|
11
|
-
export type UseDeleteDocMutationValues<AppModelType extends AppModel = AppModel> = {
|
|
12
|
-
data: WithFieldValue<AppModelType>;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* @inline
|
|
17
|
-
*/
|
|
18
|
-
export type UseDeleteDocMutationOptions<AppModelType extends AppModel = AppModel, TContext = unknown> = {
|
|
19
|
-
/**
|
|
20
|
-
* A reference to a firestore document
|
|
21
|
-
*/
|
|
22
|
-
reference: DocumentReference<AppModelType, AppModelType> | null;
|
|
23
|
-
/**
|
|
24
|
-
* Options for useMutation hook excluding mutationFn. MutationKey will be equal to reference.path by default.
|
|
25
|
-
*/
|
|
26
|
-
options?: Omit<UseMutationOptions<void, FirebaseError, void, TContext>, "mutationFn">;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Executes a query with specified constraints and returns the count of matched documents.
|
|
31
|
-
*
|
|
32
|
-
* @group Hook
|
|
33
|
-
*
|
|
34
|
-
* @param {UseDeleteDocMutationOptions<AppModelType>} options - Configuration options for the query.
|
|
35
|
-
*
|
|
36
|
-
* @returns {UseMutationResult<void, Error, UseDeleteDocMutationValues<AppModelType>, TContext>} A mutation result
|
|
37
|
-
*
|
|
38
|
-
* @example
|
|
39
|
-
* ```jsx
|
|
40
|
-
* export const MyComponent = () => {
|
|
41
|
-
* const {mutate} = useDeleteDocMutation({
|
|
42
|
-
* options: {
|
|
43
|
-
* },
|
|
44
|
-
* reference: document(),
|
|
45
|
-
* });
|
|
46
|
-
*
|
|
47
|
-
* // ....
|
|
48
|
-
* mutate();
|
|
49
|
-
* // ....
|
|
50
|
-
* };
|
|
51
|
-
* ```
|
|
52
|
-
*/
|
|
53
|
-
export const useDeleteDocMutation = <AppModelType extends AppModel = AppModel, TContext = unknown>({
|
|
54
|
-
reference,
|
|
55
|
-
options = {}
|
|
56
|
-
}: UseDeleteDocMutationOptions<AppModelType, TContext>) => {
|
|
57
|
-
const mutationKey = useMemo(() => [reference?.path], [reference?.path]);
|
|
58
|
-
|
|
59
|
-
return useMutation({
|
|
60
|
-
mutationKey,
|
|
61
|
-
...options,
|
|
62
|
-
mutationFn: async () => {
|
|
63
|
-
if (!reference) {
|
|
64
|
-
throw new Error("Reference is undefined");
|
|
65
|
-
}
|
|
66
|
-
await deleteDoc<AppModelType, AppModelType>(reference);
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
};
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { DocumentReference } from "firebase/firestore";
|
|
2
|
-
|
|
3
|
-
import { useEffect, useRef } from "react";
|
|
4
|
-
import { useFirestore } from "./useFirestore";
|
|
5
|
-
import { AppModel } from "../../types";
|
|
6
|
-
import { getDocRef, GetDocRefOptions } from "./utils/getDocRef";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @inline
|
|
10
|
-
*/
|
|
11
|
-
export type UseDocReferenceOptions<AppModelType extends AppModel = AppModel> = Omit<
|
|
12
|
-
GetDocRefOptions<AppModelType>,
|
|
13
|
-
"db"
|
|
14
|
-
>;
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Gets a `CollectionReference` instance
|
|
18
|
-
*
|
|
19
|
-
* @group Hook
|
|
20
|
-
*
|
|
21
|
-
* @param {UseDocReferenceOptions<AppModelType>} options - Options
|
|
22
|
-
*
|
|
23
|
-
* @returns {DocumentReference<AppModelType, AppModelType> | null} A reference to a Firestore document
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* ```jsx
|
|
27
|
-
* export const MyComponent = () => {
|
|
28
|
-
* const ref = useDocReference({
|
|
29
|
-
* reference: collection('todos')
|
|
30
|
-
* path: 'first'
|
|
31
|
-
* });
|
|
32
|
-
* };
|
|
33
|
-
* ```
|
|
34
|
-
*/
|
|
35
|
-
export const useDocReference = <AppModelType extends AppModel = AppModel>({
|
|
36
|
-
path,
|
|
37
|
-
reference,
|
|
38
|
-
pathSegments
|
|
39
|
-
}: UseDocReferenceOptions<AppModelType>) => {
|
|
40
|
-
const db = useFirestore();
|
|
41
|
-
const ref = useRef<DocumentReference<AppModelType, AppModelType> | null>(
|
|
42
|
-
getDocRef({ db, path, pathSegments, reference })
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
useEffect(() => {
|
|
46
|
-
ref.current = getDocRef({ db, path, pathSegments, reference });
|
|
47
|
-
}, [path, reference, pathSegments, db]);
|
|
48
|
-
|
|
49
|
-
return ref.current;
|
|
50
|
-
};
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { useMemo } from "react";
|
|
2
|
-
import { useFirestore } from "./useFirestore";
|
|
3
|
-
import { AppModel } from "../../types";
|
|
4
|
-
import { getDocRef, GetDocRefOptions } from "./utils/getDocRef";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @inline
|
|
8
|
-
*/
|
|
9
|
-
export type UseDocReferencesOptions<AppModelType extends AppModel = AppModel> = {
|
|
10
|
-
references: Omit<GetDocRefOptions<AppModelType>, "db">[];
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Gets `CollectionReference` instances
|
|
15
|
-
*
|
|
16
|
-
* @group Hook
|
|
17
|
-
*
|
|
18
|
-
* @param {UseDocReferencesOptions<AppModelType>} options - Options
|
|
19
|
-
*
|
|
20
|
-
* @returns {Array<DocumentReference<AppModelType, AppModelType> | null>} A reference to a Firestore document
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* ```jsx
|
|
24
|
-
* export const MyComponent = () => {
|
|
25
|
-
* const ref = useDocReference({
|
|
26
|
-
* reference: collection('todos')
|
|
27
|
-
* path: 'first'
|
|
28
|
-
* });
|
|
29
|
-
* };
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
|
-
export const useDocReferences = <AppModelType extends AppModel = AppModel>({
|
|
33
|
-
references
|
|
34
|
-
}: UseDocReferencesOptions<AppModelType>) => {
|
|
35
|
-
const db = useFirestore();
|
|
36
|
-
|
|
37
|
-
return useMemo(() => {
|
|
38
|
-
return references.map(({ path, reference, pathSegments }) => getDocRef({ db, reference, path, pathSegments }));
|
|
39
|
-
}, [references, db]);
|
|
40
|
-
};
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { useQuery, UseQueryOptions } from "@tanstack/react-query";
|
|
2
|
-
import { FirestoreError, getDoc, setDoc } from "firebase/firestore";
|
|
3
|
-
|
|
4
|
-
import { AppModel } from "../../types";
|
|
5
|
-
import { GetDocDataOptions } from "./utils/getDocData";
|
|
6
|
-
import { getDocRef } from "./utils/getDocRef";
|
|
7
|
-
import { getDocSnap } from "./utils/getDocSnap";
|
|
8
|
-
import { useFirestore } from "./useFirestore";
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @inline
|
|
12
|
-
*/
|
|
13
|
-
export type UseEnsureDocOptions<AppModelType extends AppModel = AppModel> = {
|
|
14
|
-
/**
|
|
15
|
-
* Reference to a document that must be written
|
|
16
|
-
*/
|
|
17
|
-
defaults: AppModelType;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Options for useMutation hook excluding mutationFn.
|
|
21
|
-
*/
|
|
22
|
-
options: Omit<UseQueryOptions<AppModelType, Error, AppModelType>, "queryFn"> &
|
|
23
|
-
Required<Pick<UseQueryOptions<AppModelType, Error, AppModelType>, "queryKey">>;
|
|
24
|
-
} & Omit<GetDocDataOptions<AppModelType>, "db">;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* This hook checks if a doc with a requested reference exists.
|
|
28
|
-
* It creates a document with requested data if it does not exist.
|
|
29
|
-
*
|
|
30
|
-
* @group Hook
|
|
31
|
-
*
|
|
32
|
-
* @param {UseEnsureDocOptions<AppModelType>} options - Configuration options for mutation.
|
|
33
|
-
*
|
|
34
|
-
* @returns {UseQueryResult<AppModelType, Error>} A mutation result
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* ```jsx
|
|
38
|
-
* export const MyComponent = () => {
|
|
39
|
-
* const {data} = useEnsureDocQuery({
|
|
40
|
-
* options: {
|
|
41
|
-
* },
|
|
42
|
-
* reference: collection().doc(),
|
|
43
|
-
* defaults: {prop1: 'value1'}
|
|
44
|
-
* });
|
|
45
|
-
*
|
|
46
|
-
* };
|
|
47
|
-
* ```
|
|
48
|
-
*/
|
|
49
|
-
export const useEnsureDoc = <AppModelType extends AppModel = AppModel>({
|
|
50
|
-
reference,
|
|
51
|
-
path,
|
|
52
|
-
pathSegments,
|
|
53
|
-
defaults,
|
|
54
|
-
options
|
|
55
|
-
}: UseEnsureDocOptions<AppModelType>) => {
|
|
56
|
-
const db = useFirestore();
|
|
57
|
-
|
|
58
|
-
return useQuery({
|
|
59
|
-
...options,
|
|
60
|
-
queryFn: async () => {
|
|
61
|
-
const createDoc = async () => {
|
|
62
|
-
const docRef = getDocRef({ db, reference, path, pathSegments });
|
|
63
|
-
if (!docRef) {
|
|
64
|
-
throw new Error(
|
|
65
|
-
`Cannot fetch document reference using data: ${reference?.path}, ${path}, ${pathSegments?.join("/")}`
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
await setDoc<AppModelType, AppModelType>(docRef, defaults);
|
|
70
|
-
const docSnap = await getDoc(docRef);
|
|
71
|
-
return { ...(docSnap.data() as AppModelType), uid: docSnap.id };
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
try {
|
|
75
|
-
const existingDocSnap = await getDocSnap({ db, path, pathSegments, reference });
|
|
76
|
-
|
|
77
|
-
if (existingDocSnap?.exists()) {
|
|
78
|
-
return { ...(existingDocSnap.data() as AppModelType), uid: existingDocSnap.id };
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return createDoc();
|
|
82
|
-
} catch (e) {
|
|
83
|
-
// permission denied error may arise because of a security rule
|
|
84
|
-
if ((e as FirestoreError).code === "permission-denied") {
|
|
85
|
-
return createDoc();
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
throw e;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { useContext } from "react";
|
|
2
|
-
import { FirebaseContext } from "../context/FirebaseContext";
|
|
3
|
-
/**
|
|
4
|
-
* Returns an instance of firestore bound to the closest context.
|
|
5
|
-
*
|
|
6
|
-
* @group Hook
|
|
7
|
-
*
|
|
8
|
-
* @returns {Firestore}
|
|
9
|
-
*/
|
|
10
|
-
export const useFirestore = () => {
|
|
11
|
-
const { firestore } = useContext(FirebaseContext);
|
|
12
|
-
return firestore;
|
|
13
|
-
};
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { useFirestore } from "./useFirestore";
|
|
2
|
-
import { getDocData, GetDocDataOptions } from "./utils/getDocData";
|
|
3
|
-
import { useQuery, UseQueryOptions } from "@tanstack/react-query";
|
|
4
|
-
import { AppModel } from "../../types";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @inline
|
|
8
|
-
*/
|
|
9
|
-
type UseGetDocOptions<AppModelType extends AppModel = AppModel> = {
|
|
10
|
-
/**
|
|
11
|
-
* Reqct-query options that must include queryKey and shall not define queryFn
|
|
12
|
-
*/
|
|
13
|
-
options: Omit<UseQueryOptions<AppModelType | null, Error, AppModelType>, "queryFn"> &
|
|
14
|
-
Required<Pick<UseQueryOptions<AppModelType, Error, AppModelType>, "queryKey">>;
|
|
15
|
-
} & Omit<GetDocDataOptions<AppModelType>, "db">;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Executes a query on a Firestore data source and returns the resulting document.
|
|
19
|
-
*
|
|
20
|
-
* @group Hook
|
|
21
|
-
*
|
|
22
|
-
* @param {UseGetDocOptions<AppModelType>} options - Configuration options for the query.
|
|
23
|
-
*
|
|
24
|
-
* @returns {UseQueryResult<AppModelType, Error>} An object containing document's data
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```jsx
|
|
28
|
-
* export const MyComponent = () => {
|
|
29
|
-
* const doc = useGetDocData({
|
|
30
|
-
* options: {
|
|
31
|
-
* queryKey: ['key']
|
|
32
|
-
* },
|
|
33
|
-
* reference: collection(),
|
|
34
|
-
* path: 'id'
|
|
35
|
-
* });
|
|
36
|
-
* console.log(doc);
|
|
37
|
-
* };
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
export const useGetDocData = <AppModelType extends AppModel = AppModel>({
|
|
41
|
-
options,
|
|
42
|
-
reference,
|
|
43
|
-
path,
|
|
44
|
-
pathSegments
|
|
45
|
-
}: UseGetDocOptions<AppModelType>) => {
|
|
46
|
-
const db = useFirestore();
|
|
47
|
-
|
|
48
|
-
return useQuery({
|
|
49
|
-
...options,
|
|
50
|
-
queryFn: () => getDocData<AppModelType>({ db, reference, path, pathSegments })
|
|
51
|
-
});
|
|
52
|
-
};
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { DocumentReference, onSnapshot } from "firebase/firestore";
|
|
2
|
-
|
|
3
|
-
import { useEffect, useMemo, useState } from "react";
|
|
4
|
-
import { FirebaseError } from "firebase/app";
|
|
5
|
-
import { useDocReference } from "./useDocReference";
|
|
6
|
-
import { AppModel } from "../../types";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @inline
|
|
10
|
-
*/
|
|
11
|
-
export type UseGetRealtimeDocDataOptions<AppModelType extends AppModel = AppModel> = {
|
|
12
|
-
/**
|
|
13
|
-
* A slash-separated path to a document. Has to be omitted to use
|
|
14
|
-
*/
|
|
15
|
-
path?: string;
|
|
16
|
-
/**
|
|
17
|
-
* A reference to a collection.
|
|
18
|
-
*/
|
|
19
|
-
reference?: DocumentReference<AppModelType, AppModelType>;
|
|
20
|
-
/**
|
|
21
|
-
* Additional path segments that will be applied relative
|
|
22
|
-
* to the first argument.
|
|
23
|
-
*/
|
|
24
|
-
pathSegments?: string[];
|
|
25
|
-
/**
|
|
26
|
-
* A callback to be called if the listen fails or is
|
|
27
|
-
* cancelled. No further callbacks will occur.
|
|
28
|
-
*/
|
|
29
|
-
onError?: (error: FirebaseError) => unknown;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* @inline
|
|
34
|
-
*/
|
|
35
|
-
export type UseGetRealtimeDocDataResult<AppModelType> = {
|
|
36
|
-
data: AppModelType | null;
|
|
37
|
-
isError: boolean;
|
|
38
|
-
error: FirebaseError | null;
|
|
39
|
-
isFetching: boolean;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* A hook to get realtime updates to a firestore document.
|
|
44
|
-
*
|
|
45
|
-
* @group Hook
|
|
46
|
-
*
|
|
47
|
-
* @param {UseGetRealtimeDocDataOptions<AppModelType>} options
|
|
48
|
-
*
|
|
49
|
-
* @returns {UseGetRealtimeDocDataResult<AppModelType>}
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* ```jsx
|
|
53
|
-
* const firebaseConfig = {};
|
|
54
|
-
* export const MyComponent = () => {
|
|
55
|
-
* const result = useGetRealtimeDocData('collection/documentId');
|
|
56
|
-
* return (
|
|
57
|
-
* <div>
|
|
58
|
-
* {JSON.stringify(result)}
|
|
59
|
-
* </div>
|
|
60
|
-
* );
|
|
61
|
-
* };
|
|
62
|
-
* ```
|
|
63
|
-
*/
|
|
64
|
-
export const useGetRealtimeDocData = <AppModelType extends AppModel = AppModel>({
|
|
65
|
-
path,
|
|
66
|
-
pathSegments,
|
|
67
|
-
reference,
|
|
68
|
-
onError
|
|
69
|
-
}: UseGetRealtimeDocDataOptions<AppModelType>): UseGetRealtimeDocDataResult<AppModelType> => {
|
|
70
|
-
const ref = useDocReference({ path, reference, pathSegments });
|
|
71
|
-
const [doc, setDoc] = useState<AppModelType | null>(null);
|
|
72
|
-
const [isError, setIsError] = useState(false);
|
|
73
|
-
const [isFetching, setIsFetching] = useState(true);
|
|
74
|
-
const [error, setError] = useState<FirebaseError | null>(null);
|
|
75
|
-
|
|
76
|
-
useEffect(() => {
|
|
77
|
-
const unsubscribe = ref
|
|
78
|
-
? onSnapshot(ref, {
|
|
79
|
-
next: async (snapshot) => {
|
|
80
|
-
setIsFetching(false);
|
|
81
|
-
setDoc(snapshot.data() || null);
|
|
82
|
-
setError(null);
|
|
83
|
-
setIsError(false);
|
|
84
|
-
},
|
|
85
|
-
error: (e) => {
|
|
86
|
-
setIsError(true);
|
|
87
|
-
setError(e);
|
|
88
|
-
onError?.(e);
|
|
89
|
-
}
|
|
90
|
-
})
|
|
91
|
-
: () => {};
|
|
92
|
-
|
|
93
|
-
return () => unsubscribe();
|
|
94
|
-
}, [ref, doc, isError, onError, isFetching, error]);
|
|
95
|
-
|
|
96
|
-
return useMemo(
|
|
97
|
-
() => ({
|
|
98
|
-
data: { ...(doc || {}), uid: ref?.id ?? "" } as AppModelType,
|
|
99
|
-
isError,
|
|
100
|
-
isFetching,
|
|
101
|
-
error
|
|
102
|
-
}),
|
|
103
|
-
[doc, isError, error, ref, isFetching]
|
|
104
|
-
);
|
|
105
|
-
};
|