export interface StoreMap { [key: string]: Model; } export type RoutineList = string[]; export interface FluxAction { meta?: MetaType; payload?: Model; type: string; } export type ActionCreator = (payload: Model, meta: MetaType) => FluxAction; export interface Routine { (): FluxAction; (payload: InputType, meta: MetaType): FluxAction; (payload: InputType): FluxAction; routineName: string; success: ActionCreator; SUCCESS: string; sync: boolean; trigger: ActionCreator; TRIGGER: string; } export interface AsyncRoutine extends Routine { failure: ActionCreator; FAILURE: string; fulfill: ActionCreator; FULFILL: string; getError: (state: any) => Error; isInitialized: (state: any) => boolean; isLoading: (state: any) => boolean; request: ActionCreator; REQUEST: string; } export type Ident = any; export type IdentResolver = (item: Model) => Ident; export type IdentSource = string | string[] | IdentResolver; export type RoutineDict = StoreMap>; export type EntityCollectionSelector = (state: StateType) => Model[]; export type EntitySelector = (state: StateType, ident?: Ident) => Model; export type IdentSelector = (state: StateType) => Ident; export type PropSelector = (state: StateType, ident: Ident, propName: string) => PropType; export type ViewPropMap = StoreMap; export type ViewSelector = (state: StateType) => Model; export type ViewSelectorMap = StoreMap>; export interface ViewSelectors { getEntities: ViewSelector; getProps: ViewSelector; } export interface EntityStore { createFindSelector: (identSelector: IdentSelector) => EntitySelector; getAll: EntityCollectionSelector; getCollection: EntityCollectionSelector; getFlag: PropSelector; getObject: EntitySelector; getProp: PropSelector; getSize: EntitySelector; isEmpty: EntitySelector; name: string; views: ViewSelectorMap; } export type ItemReducer = (state: Model, action: FluxAction>) => Model; export type JsonPathMap = StoreMap; export type ReducerMap = StoreMap>; export interface RelationConfig { attr: string; collection: string; } export interface ViewConfig { name: string; props?: JsonPathMap; routine: Routine; } export interface OperationState { error?: Error; initialized?: boolean; loading?: boolean; } export interface ViewState { entities: string[]; props: ViewPropMap; } export type EntitiesState = StoreMap; export type OperationsState = StoreMap; export type ViewsState = StoreMap; export type StoreReducer = (state: Model, action: FluxAction) => Model; export type EntitiesReducer = StoreReducer; export type OperationsReducer = StoreReducer; export type ViewReducer = StoreReducer; export interface GlobalReducerMap { entities: EntitiesReducer; operations: OperationsReducer; views?: ViewReducer; } export interface EntityConfig { belongsTo?: RelationConfig[]; clearedBy?: (AsyncRoutine)[]; collectionReducers?: ReducerMap; deletedBy?: (AsyncRoutine)[]; hasManyToMany?: RelationConfig[]; identSource: IdentSource; name: string; on?: ReducerMap; providedBy?: (AsyncRoutine)[]; views?: ViewConfig[]; } export type EntityMap = StoreMap; declare module 'redux-entity-store' { function createAsyncRoutine( baseName: string, entityMap?: EntityMap ): AsyncRoutine; function createSyncRoutine( baseName: string, entityMap?: EntityMap ): Routine; function createEntityRoutines( entity: string, routines: RoutineList, sync?: boolean ): RoutineDict; function createEntityStore(storeConfig: EntityConfig): EntityStore; function createEntitiesReducer(...stores: EntityStore[]): any; function connectReducers(mountPoint: string, ...stores: EntityStore[]): GlobalReducerMap; function operations(state: any, action: FluxAction): any; }