<commit_before>// Type definitions for redux-first-router 1.9
// Project: https://github.com/faceyspacey/redux-first-router#readme
// Definitions by: Valbrand <https://github.com/Valbrand>
//                 viggyfresh <https://github.com/viggyfresh>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.4

import {
    Dispatch,
    Store,
    Reducer,
    Middleware,
    GenericStoreEnhancer
} from 'redux';
import { History } from 'history';

export type Nullable<T> = T | null | undefined;

export type StateGetter = () => object;

export type RouteString = string;

export type RouteThunk = <S>(dispatch: Dispatch<S>, getState: StateGetter) => any | Promise<any>;

export interface RouteObject {
    path: string;
    capitalizedWords?: boolean;
    toPath?(param: string, key?: string): string;
    fromPath?(path: string, key?: string): string;
    thunk?: RouteThunk;
    navKey?: string;
}

export type Route = RouteString | RouteObject;

export interface RoutesMap {
    [key: string]: Route;
}

export interface ReceivedAction {
    type: string;
    payload: Payload;
    meta?: object;
    query?: object;
    search?: string;
    navKey?: Nullable<string>;
}

export interface ReceivedActionMeta {
    type: string;
    payload: Payload;
    query?: object;
    navKey?: Nullable<string>;
    meta: {
        notFoundPath?: string;
        query?: object;
        search?: string;
    };
}

export interface HistoryData {
    entries: Array<{ pathname: string }>;
    index: number;
    length: number;
}

export interface Location {
    pathname: string;
    type: string;
    payload: Payload;
    query?: object;
    search?: string;
}

export interface LocationState {
    pathname: string;
    type: string;
    payload: Payload;
    query?: object;
    search?: string;
    prev: Location;
    kind: Nullable<string>;
    history: Nullable<HistoryData>;
    routesMap: RoutesMap;
    hasSSR?: boolean;
}

export interface ActionMetaLocation {
    current: Location;
    prev: Location;
    kind: Nullable<string>;
    history: Nullable<HistoryData>;
}

export interface NavigationAction {
    type: string;
    key?: Nullable<string>;
    navKey?: Nullable<string>;
    routeName?: string;
    actions?: NavigationAction[];
    action?: NavigationAction;
    params?: Params;
    meta?: object;
}

export interface Meta {
    location: ActionMetaLocation;
    notFoundPath?: string;
    navigation?: NavigationAction;
    query?: object;
    search?: string;
}

export interface Action {
    type: string;
    payload: Payload;
    meta?: Meta;
    query?: object;
    navKey?: Nullable<string>;
}

export interface HistoryLocation {
    pathname: string;
    search?: string;
}

export type HistoryAction = string;

export type Listener = (location: HistoryLocation, action: HistoryAction) => void;

export type ScrollBehavior = object;

export interface Router {
    getStateForActionOriginal(action: object, state: Nullable<object>): Nullable<object>;
    getStateForAction(action: object, state: Nullable<object>): Nullable<object>;
    getPathAndParamsForState(state: object): { path: Nullable<string>, params: Nullable<Params> };
    getActionForPathAndParams(path: string): Nullable<object>;
}

export interface Navigator {
    router: Router;
}

export interface Navigators {
    [key: string]: Navigator;
}

export type SelectLocationState = (state: object) => LocationState;
export type SelectTitleState = (state: object) => string;

export interface QuerySerializer {
    stringify(params: Params): string;
    parse(queryString: string): object;
}

export interface NavigatorsConfig {
    navigators: Navigators;
    patchNavigators(navigators: Navigators): void;

    actionToNavigation(
        navigators: Navigators,
        action: object, // TODO check this
        navigationAction: Nullable<NavigationAction>,
        route: Nullable<Route>
    ): object;
    navigationToAction<S>(
        navigators: Navigators,
        store: Store<S>,
        routesMap: RoutesMap,
        action: object
    ): {
        action: object,
        navigationAction: Nullable<NavigationAction>
    };
}

export interface Options {
    title?: string | SelectTitleState;
    location?: string | SelectLocationState;
    notFoundPath?: string;
    scrollTop?: boolean;
    onBeforeChange?<S>(dispatch: Dispatch<S>, getState: StateGetter): void;
    onAfterChange?<S>(dispatch: Dispatch<S>, getState: StateGetter): void;
    onBackNext?<S>(dispatch: Dispatch<S>, getState: StateGetter): void;
    restoreScroll?(history: History): ScrollBehavior;
    initialDispatch?: boolean;
    querySerializer?: QuerySerializer;
    navigators?: NavigatorsConfig;
}

export type Params = object;
export type Payload = object;

export type ScrollUpdater = (performedByUser: boolean) => void;

export const NOT_FOUND: string;

export function actionToPath(action: ReceivedAction, routesMap: RoutesMap): string;

export function back(): void;

export function canGo(n: number): boolean;

export function canGoBack(): boolean;

export function canGoForward(): boolean;

export function connectRoutes(history: History, routesMap: RoutesMap, options?: Options): {
    reducer: Reducer<LocationState>,
    middleware: Middleware,
    thunk<S>(store: Store<S>): Promise<Nullable<RouteThunk>>,
    enhancer: GenericStoreEnhancer,
    initialDispatch?(): void
};

export function go(n: number): void;

export function history(): History;

export function isLocationAction(action: any): boolean;

export function next(): void;

export function nextPath(): string | void;

export function pathToAction(pathname: string, routesMap: RoutesMap): ReceivedAction;

export function prevPath(): string | void;

export function push(pathname: string): void;

export function redirect(action: Action): Action;

export function replace(pathname: string): void;

export function scrollBehavior(): ScrollBehavior | void;

export function setKind(action: Action, kind: string): Action;

export function updateScroll(): void;
<commit_msg>Payload key in Action interface is optional<commit_after>// Type definitions for redux-first-router 1.9
// Project: https://github.com/faceyspacey/redux-first-router#readme
// Definitions by: Valbrand <https://github.com/Valbrand>
//                 viggyfresh <https://github.com/viggyfresh>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.4

import {
    Dispatch,
    Store,
    Reducer,
    Middleware,
    GenericStoreEnhancer
} from 'redux';
import { History } from 'history';

export type Nullable<T> = T | null | undefined;

export type StateGetter = () => object;

export type RouteString = string;

export type RouteThunk = <S>(dispatch: Dispatch<S>, getState: StateGetter) => any | Promise<any>;

export interface RouteObject {
    path: string;
    capitalizedWords?: boolean;
    toPath?(param: string, key?: string): string;
    fromPath?(path: string, key?: string): string;
    thunk?: RouteThunk;
    navKey?: string;
}

export type Route = RouteString | RouteObject;

export interface RoutesMap {
    [key: string]: Route;
}

export interface ReceivedAction {
    type: string;
    payload: Payload;
    meta?: object;
    query?: object;
    search?: string;
    navKey?: Nullable<string>;
}

export interface ReceivedActionMeta {
    type: string;
    payload: Payload;
    query?: object;
    navKey?: Nullable<string>;
    meta: {
        notFoundPath?: string;
        query?: object;
        search?: string;
    };
}

export interface HistoryData {
    entries: Array<{ pathname: string }>;
    index: number;
    length: number;
}

export interface Location {
    pathname: string;
    type: string;
    payload: Payload;
    query?: object;
    search?: string;
}

export interface LocationState {
    pathname: string;
    type: string;
    payload: Payload;
    query?: object;
    search?: string;
    prev: Location;
    kind: Nullable<string>;
    history: Nullable<HistoryData>;
    routesMap: RoutesMap;
    hasSSR?: boolean;
}

export interface ActionMetaLocation {
    current: Location;
    prev: Location;
    kind: Nullable<string>;
    history: Nullable<HistoryData>;
}

export interface NavigationAction {
    type: string;
    key?: Nullable<string>;
    navKey?: Nullable<string>;
    routeName?: string;
    actions?: NavigationAction[];
    action?: NavigationAction;
    params?: Params;
    meta?: object;
}

export interface Meta {
    location: ActionMetaLocation;
    notFoundPath?: string;
    navigation?: NavigationAction;
    query?: object;
    search?: string;
}

export interface Action {
    type: string;
    payload?: Payload;
    meta?: Meta;
    query?: object;
    navKey?: Nullable<string>;
}

export interface HistoryLocation {
    pathname: string;
    search?: string;
}

export type HistoryAction = string;

export type Listener = (location: HistoryLocation, action: HistoryAction) => void;

export type ScrollBehavior = object;

export interface Router {
    getStateForActionOriginal(action: object, state: Nullable<object>): Nullable<object>;
    getStateForAction(action: object, state: Nullable<object>): Nullable<object>;
    getPathAndParamsForState(state: object): { path: Nullable<string>, params: Nullable<Params> };
    getActionForPathAndParams(path: string): Nullable<object>;
}

export interface Navigator {
    router: Router;
}

export interface Navigators {
    [key: string]: Navigator;
}

export type SelectLocationState = (state: object) => LocationState;
export type SelectTitleState = (state: object) => string;

export interface QuerySerializer {
    stringify(params: Params): string;
    parse(queryString: string): object;
}

export interface NavigatorsConfig {
    navigators: Navigators;
    patchNavigators(navigators: Navigators): void;

    actionToNavigation(
        navigators: Navigators,
        action: object, // TODO check this
        navigationAction: Nullable<NavigationAction>,
        route: Nullable<Route>
    ): object;
    navigationToAction<S>(
        navigators: Navigators,
        store: Store<S>,
        routesMap: RoutesMap,
        action: object
    ): {
        action: object,
        navigationAction: Nullable<NavigationAction>
    };
}

export interface Options {
    title?: string | SelectTitleState;
    location?: string | SelectLocationState;
    notFoundPath?: string;
    scrollTop?: boolean;
    onBeforeChange?<S>(dispatch: Dispatch<S>, getState: StateGetter): void;
    onAfterChange?<S>(dispatch: Dispatch<S>, getState: StateGetter): void;
    onBackNext?<S>(dispatch: Dispatch<S>, getState: StateGetter): void;
    restoreScroll?(history: History): ScrollBehavior;
    initialDispatch?: boolean;
    querySerializer?: QuerySerializer;
    navigators?: NavigatorsConfig;
}

export type Params = object;
export type Payload = object;

export type ScrollUpdater = (performedByUser: boolean) => void;

export const NOT_FOUND: string;

export function actionToPath(action: ReceivedAction, routesMap: RoutesMap): string;

export function back(): void;

export function canGo(n: number): boolean;

export function canGoBack(): boolean;

export function canGoForward(): boolean;

export function connectRoutes(history: History, routesMap: RoutesMap, options?: Options): {
    reducer: Reducer<LocationState>,
    middleware: Middleware,
    thunk<S>(store: Store<S>): Promise<Nullable<RouteThunk>>,
    enhancer: GenericStoreEnhancer,
    initialDispatch?(): void
};

export function go(n: number): void;

export function history(): History;

export function isLocationAction(action: any): boolean;

export function next(): void;

export function nextPath(): string | void;

export function pathToAction(pathname: string, routesMap: RoutesMap): ReceivedAction;

export function prevPath(): string | void;

export function push(pathname: string): void;

export function redirect(action: Action): Action;

export function replace(pathname: string): void;

export function scrollBehavior(): ScrollBehavior | void;

export function setKind(action: Action, kind: string): Action;

export function updateScroll(): void;

{'fraction_non_alphanumeric': 0.11114767585355821, 'fraction_numerical': 0.0006581653640477169, 'mean_word_length': 4.135614702154626, 'pattern_counts': {'":': 0, '<': 81, '<?xml version=': 0, '>': 93, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6628558', 'n_tokens_mistral': 3483, 'n_tokens_neox': 3486, 'n_words': 1000}