Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 69 additions & 26 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react'
import { FirebaseNamespace } from "@firebase/app-types";
import * as FirestoreTypes from '@firebase/firestore-types'
import * as DatabaseTypes from '@firebase/database-types'
import * as StorageTypes from '@firebase/storage-types'
Expand Down Expand Up @@ -139,12 +140,32 @@ interface RemoveOptions {
dispatchAction: boolean
}

/**
* https://firebase.google.com/docs/reference/js/firebase.database
*/

interface FirebaseDatabaseService {
database: {
(app?: string): DatabaseTypes.FirebaseDatabase
Reference: DatabaseTypes.Reference
Query: DatabaseTypes.Query
DataSnapshot: DatabaseTypes.DataSnapshot
enableLogging: typeof DatabaseTypes.enableLogging
ServerValue: DatabaseTypes.ServerValue
Database: typeof DatabaseTypes.FirebaseDatabase
}
}

/**
* Firestore instance extended with methods which dispatch
* redux actions.
* @see https://react-redux-firebase.com/docs/api/firebaseInstance.html
*/
interface ExtendedFirebaseInstance extends DatabaseTypes.FirebaseDatabase {
interface BaseExtendedFirebaseInstance
extends DatabaseTypes.FirebaseDatabase,
FirebaseDatabaseService,
ExtendedAuthInstance,
ExtendedStorageInstance {
initializeAuth: VoidFunction

firestore: () => ExtendedFirestoreInstance
Expand Down Expand Up @@ -318,6 +339,15 @@ interface ExtendedFirebaseInstance extends DatabaseTypes.FirebaseDatabase {
) => Promise<any>
}

/**
* OptionalOverride is left here in the event that any of the optional properties below need to be extended in the future.
* Example: OptionalOverride<FirebaseNamespace, 'messaging', { messaging: ExtendedMessagingInstance }>
*/
type OptionalOverride<T, b extends string, P> = b extends keyof T ? P : {};
type OptionalPick<T, b extends string> = Pick<T, b & keyof T>

type ExtendedFirebaseInstance = BaseExtendedFirebaseInstance & OptionalPick<FirebaseNamespace, 'messaging' | 'performance' | 'functions' | 'analytics' | 'remoteConfig'>

/**
* Create an extended firebase instance that has methods attached
* which dispatch redux actions.
Expand All @@ -330,7 +360,8 @@ export function createFirebaseInstance(
firebase: any,
configs: Partial<ReduxFirestoreConfig>,
dispatch: Dispatch
): ExtendedFirebaseInstance & ExtendedAuthInstance & ExtendedStorageInstance
): ExtendedFirebaseInstance;


export type QueryParamOption =
| 'orderByKey'
Expand Down Expand Up @@ -447,7 +478,9 @@ export type ReduxFirestoreQueriesFunction = (
* Firestore instance extended with methods which dispatch redux actions.
* @see https://github.com/prescottprue/redux-firestore#api
*/
interface ExtendedFirestoreInstance extends FirestoreTypes.FirebaseFirestore {
interface ExtendedFirestoreInstance
extends FirestoreTypes.FirebaseFirestore,
FirestoreStatics {
/**
* Get data from firestore.
* @see https://github.com/prescottprue/redux-firestore#get
Expand Down Expand Up @@ -532,7 +565,7 @@ interface ExtendedFirestoreInstance extends FirestoreTypes.FirebaseFirestore {
* @see https://github.com/prescottprue/redux-firestore#other-firebase-statics
*/
interface FirestoreStatics {
FieldValue: FirestoreTypes.FieldValue
FieldValue: typeof FirestoreTypes.FieldValue
FieldPath: FirestoreTypes.FieldPath
setLogLevel: (logLevel: FirestoreTypes.LogLevel) => void
Blob: FirestoreTypes.Blob
Expand All @@ -543,18 +576,14 @@ interface FirestoreStatics {
Query: FirestoreTypes.Query
QueryDocumentSnapshot: FirestoreTypes.QueryDocumentSnapshot
QuerySnapshot: FirestoreTypes.QuerySnapshot
Timestamp: FirestoreTypes.FieldValue
Timestamp: typeof FirestoreTypes.FieldValue
Transaction: FirestoreTypes.Transaction
WriteBatch: FirestoreTypes.WriteBatch
}

export interface WithFirestoreProps {
firestore: FirestoreTypes.FirebaseFirestore &
ExtendedFirestoreInstance &
FirestoreStatics
firebase: ExtendedFirebaseInstance &
ExtendedAuthInstance &
ExtendedStorageInstance
firestore: ExtendedFirestoreInstance
firebase: ExtendedFirebaseInstance
dispatch: Dispatch
}

Expand Down Expand Up @@ -803,9 +832,7 @@ export interface UploadFileOptions<T extends File | Blob> {
}

export interface WithFirebaseProps<ProfileType> {
firebase: ExtendedAuthInstance &
ExtendedStorageInstance &
ExtendedFirebaseInstance
firebase: ExtendedFirebaseInstance
}

/**
Expand Down Expand Up @@ -862,10 +889,11 @@ export function firestoreConnect<TInner = {}>(
* @param action.data - Data associated with action
* @see https://react-redux-firebase.com/docs/api/reducer.html
*/
export function firestoreReducer(
export function firestoreReducer<Schema extends Record<string, any> = {}
>(
state: any,
action: any
): FirestoreReducer.Reducer
): Reducer<FirestoreReducer.State<Schema>>

/**
* Fix path by adding "/" to path if needed
Expand All @@ -878,9 +906,7 @@ export function fixPath(path: string): string
* integrations into external libraries such as redux-thunk and redux-observable.
* @see https://react-redux-firebase.com/docs/api/getFirebase.html
*/
export function getFirebase(): ExtendedFirebaseInstance &
ExtendedAuthInstance &
ExtendedStorageInstance
export function getFirebase(): ExtendedFirebaseInstance

/**
* Get a value from firebase using slash notation. This enables an easy
Expand Down Expand Up @@ -919,9 +945,7 @@ export function isLoaded(...args: any[]): boolean
* instance is gathered from `ReactReduxFirebaseContext`.
* @see https://react-redux-firebase.com/docs/api/useFirebase.html
*/
export function useFirebase(): ExtendedFirebaseInstance &
ExtendedAuthInstance &
ExtendedStorageInstance
export function useFirebase(): ExtendedFirebaseInstance

/**
* React hook that automatically listens/unListens
Expand Down Expand Up @@ -1223,16 +1247,35 @@ export namespace FirebaseReducer {
}
}


export namespace FirestoreReducer {
export interface Reducer {
composite?: Data<any | Dictionary<any>>
data: Data<any | Dictionary<any>>
declare const entitySymbol: unique symbol

export type Entity<T> = T & {
[entitySymbol]: never
}
export type EntityWithId<T> = T & { id: string }
export type FirestoreData<Schema extends Record<string, any>> = {
[T in keyof Schema]: Record<
string,
Schema[T] extends Entity<infer V> ? V : FirestoreData<Schema[T]>
>
}

export type OrderedData<Schema extends Record<string, any>> = {
[T in keyof Schema]: Schema[T] extends Entity<infer V>
? EntityWithId<V>[]
: OrderedData<EntityWithId<Schema[T]>>[]
}

export interface Reducer<Schema extends Record<string, any> = {}> {
errors: {
allIds: string[]
byQuery: any[]
}
listeners: Listeners
ordered: Ordered<any>
data: FirestoreData<Schema>
ordered: OrderedData<Schema>
queries: Data<ReduxFirestoreQuerySetting & (Dictionary<any> | any)>
status: {
requested: Dictionary<boolean>
Expand Down