import * as t from 'io-ts'; import type { Observable } from 'rxjs'; import type { Hash } from './types'; /** * The type of a generic action */ export declare type Action = { readonly type: TType; }; export declare type Reducer = (state: S | undefined, action: A) => S; interface ActionConstraint { readonly type: string; readonly payload?: unknown; readonly meta?: unknown; readonly error?: true; } declare type ActionFactory = A extends { readonly meta?: unknown; } ? A extends { readonly payload?: unknown; } ? (payload: A['payload'], meta: A['meta']) => A : (_: undefined, meta: A['meta']) => A : A extends { readonly payload?: unknown; } ? (payload: A['payload']) => A : () => A; declare type ActionCreatorMembers = { type: A['type']; codec: t.Mixed; is: (a: unknown) => a is A; error: A extends { readonly error: true; } ? true : undefined; }; export declare type ActionCreator = ActionFactory & ActionCreatorMembers; declare type ActionCreatorFromTuple

= ActionCreator

; readonly meta: t.TypeOf; readonly error: true; } : { readonly type: P[0]; readonly meta: t.TypeOf; readonly error: true; } : P extends { readonly 1: t.Mixed; } ? { readonly type: P[0]; readonly payload: t.TypeOf; readonly error: true; } : { readonly type: P[0]; readonly error: true; } : P extends { readonly 2: t.Mixed; } ? P extends { readonly 1: t.Mixed; } ? { readonly type: P[0]; readonly payload: t.TypeOf; readonly meta: t.TypeOf; } : { readonly type: P[0]; readonly meta: t.TypeOf; } : P extends { readonly 1: t.Mixed; } ? { readonly type: P[0]; readonly payload: t.TypeOf; } : { readonly type: P[0]; }>; /** * @param args - Args params * @returns action creator */ export declare function createAction

(...args: P): ActionCreatorFromTuple

; export declare type AnyAC = ActionCreator; /** * A version of ReturnType which returns `never` insted of `any` if it can't match function type */ export declare type OnlyReturnType = F extends (...args: any) => infer R ? R : never; /** union of all value types in type T */ export declare type ValueOf = T[keyof T]; /** Types extending this constraint can be unfolded/flattened into a union of ActionCreators */ export declare type ActionsUnionConstraint = readonly AnyAC[] | { readonly [K: string]: AnyAC | { readonly [K2: string]: AnyAC; }; } | AnyAC; /** Convert tuples, arrays, modules and mappings containing ACs & AACs to the plain union of ACs */ export declare type ActionsUnion = AC extends readonly AnyAC[] ? AC[number] : AC extends AnyAC ? AC : ValueOf<{ [K in keyof AC]: AC[K] extends AnyAC ? AC[K] : AC[K] extends { readonly [K2: string]: AnyAC; } ? ValueOf : never; }>; /** * Type helper to extract the type of an action or a mapping of actions * Usage: const action: ActionType; */ export declare type ActionType = OnlyReturnType>; export declare type ActionTypeOf = ActionType['type']; export declare function isActionOf(ac: AC, action: unknown): action is ActionType; export declare function isActionOf(ac: AC): (action: unknown) => action is ActionType; /*** Async Actions ***/ /** * Maps parameters for createAsyncAction to respective async ActionCreators (request, success and * failure) */ declare type AsyncActionCreator

= { readonly request: ActionCreatorFromTuple<[`${P[1]}/request`, P[2], P[0]]>; readonly success: ActionCreatorFromTuple<[`${P[1]}/success`, P[3], P[0]]>; readonly failure: ActionCreatorFromTuple<[ `${P[1]}/failure`, P[4] extends t.Mixed ? P[4] : t.UnknownC, P[0], true ]>; }; /** * A type which constrains any async ActionCreator tuple */ export declare type AnyAAC = { readonly request: ActionCreator<{ readonly type: `${string}/request`; readonly payload?: any; readonly meta: any; }>; readonly success: ActionCreator<{ readonly type: `${string}/success`; readonly payload?: any; readonly meta: any; }>; readonly failure: ActionCreator<{ readonly type: `${string}/failure`; readonly payload: unknown; readonly meta: any; readonly error: true; }>; }; /** * Create a set of async actions * * Here, meta is first class citizen, as it's required and what links a request with its responses * (success or failure). * * @param args - Arguments tuple; [meta, type] are required, while [request, success an failure] * are codecs to be used as payloads for the respective ActionCreators * @returns Async actions */ export declare function createAsyncAction

(...args: P): AsyncActionCreator

; export declare function isResponseOf(asyncAction: AAC, meta: ActionType['meta']): (action: unknown) => action is ActionType; export declare function isResponseOf(asyncAction: AAC, meta: ActionType['meta'], action: unknown): action is ActionType; export declare function isConfirmationResponseOf(asyncAction: AAC, meta: ActionType['meta'], action: unknown): action is (ActionType & { payload: { confirmed: boolean; }; }) | ActionType; export declare function isConfirmationResponseOf(asyncAction: AAC, meta: ActionType['meta']): (action: unknown) => action is (ActionType & { payload: { confirmed: boolean; }; }) | ActionType; export declare function asyncActionToPromise(asyncAction: AAC, meta: ActionType['meta'], action$: Observable): Promise['payload']>; export declare function asyncActionToPromise(asyncAction: AAC, meta: ActionType['meta'], action$: Observable, confirmed: false): Promise['payload'] & { txBlock: number; txHash: Hash; confirmed: undefined | boolean; }>; export declare function asyncActionToPromise(asyncAction: AAC, meta: ActionType['meta'], action$: Observable, confirmed: true): Promise['payload'] & { txBlock: number; txHash: Hash; confirmed: true; }>; /** * Create a reducer which can be extended with additional actions handlers * * Usage: * const reducer = createReducer(State) * .handle(action, (s, a): State => ...) * .handle(...) * .handle(...); * * @param initialState - state for initialization (if no state is passed on reducer call) * @returns A reducer function, extended with a handle method to extend it */ export declare function createReducer(initialState: S): Reducer & { handle: >) => S, AD extends AnyAC = AC>(ac: AC | readonly AC[], handler: H) => Reducer & { handle: >) => S, AD_1 extends AnyAC = AC_1>(ac: AC_1 | readonly AC_1[], handler: H_1) => Reducer & { handle: >) => S, AD_2 extends AnyAC = AC_2>(ac: AC_2 | readonly AC_2[], handler: H_2) => Reducer & { handle: >) => S, AD_3 extends AnyAC = AC_3>(ac: AC_3 | readonly AC_3[], handler: H_3) => Reducer & { handle: >) => S, AD_4 extends AnyAC = AC_4>(ac: AC_4 | readonly AC_4[], handler: H_4) => Reducer & { handle: >) => S, AD_5 extends AnyAC = AC_5>(ac: AC_5 | readonly AC_5[], handler: H_5) => Reducer & { handle: >) => S, AD_6 extends AnyAC = AC_6>(ac: AC_6 | readonly AC_6[], handler: H_6) => Reducer & { handle: >) => S, AD_7 extends AnyAC = AC_7>(ac: AC_7 | readonly AC_7[], handler: H_7) => Reducer & { handle: >) => S, AD_8 extends AnyAC = AC_8>(ac: AC_8 | readonly AC_8[], handler: H_8) => Reducer & { handle: >) => S, AD_9 extends AnyAC = AC_9>(ac: AC_9 | readonly AC_9[], handler: H_9) => Reducer & { handle: >) => S, AD_10 extends AnyAC = AC_10>(ac: AC_10 | readonly AC_10[], handler: H_10) => Reducer & any; }; }; }; }; }; }; }; }; }; }; }; export {};