UNPKG

35.6 kBSource Map (JSON)View Raw
1{"version":3,"file":"typesafe-actions.umd.production.js","sources":["../src/utils/validation.ts","../src/action.ts","../src/create-custom-action.ts","../src/create-action.ts","../src/get-type.ts","../src/deprecated/create-custom-action.ts","../src/deprecated/index.ts","../src/deprecated/create-action.ts","../src/deprecated/create-standard-action.ts","../src/create-async-action.ts","../src/create-reducer.ts","../src/is-action-of.ts","../src/is-of-type.ts"],"sourcesContent":["import {\n ActionCreator,\n ActionCreatorTypeMetadata,\n TypeConstant,\n} from '../type-helpers';\n\nexport function checkIsEmpty(arg: unknown) {\n return arg == null;\n}\n\nexport function throwIsEmpty(argPosition: number): never {\n throw new Error(`Argument ${argPosition} is empty.`);\n}\n\nexport function checkValidActionCreator(\n arg: unknown\n): arg is ActionCreator<TypeConstant> {\n return typeof arg === 'function' && 'getType' in arg;\n}\n\nexport function checkInvalidActionCreator(arg: unknown) {\n return !checkValidActionCreator(arg);\n}\n\nexport function throwInvalidActionCreator(argPosition: number): never {\n throw new Error(\n `Argument ${argPosition} is invalid, it should be an action-creator instance from \"typesafe-actions\"`\n );\n}\n\nexport function checkInvalidActionCreatorInArray(\n arg: ActionCreator<TypeConstant> & ActionCreatorTypeMetadata<TypeConstant>,\n idx: number\n): void | never {\n if (arg == null) {\n throw new Error(\n `Argument contains array with empty element at index ${idx}`\n );\n } else if (arg.getType == null) {\n throw new Error(\n // tslint:disable-next-line:max-line-length\n `Argument contains array with invalid element at index ${idx}, it should be an action-creator instance from \"typesafe-actions\"`\n );\n }\n}\n\nexport function checkValidActionType(arg: unknown): arg is string | symbol {\n return typeof arg === 'string' || typeof arg === 'symbol';\n}\n\nexport function checkInvalidActionType(arg: unknown) {\n return !checkValidActionType(arg);\n}\n\nexport function throwInvalidActionType(argPosition: number): never {\n throw new Error(\n `Argument ${argPosition} is invalid, it should be an action type of type: string | symbol`\n );\n}\n\nexport function checkInvalidActionTypeInArray(\n arg: TypeConstant,\n idx: number\n): void | never {\n if (arg == null) {\n throw new Error(\n `Argument contains array with empty element at index ${idx}`\n );\n } else if (typeof arg !== 'string' && typeof arg !== 'symbol') {\n throw new Error(\n `Argument contains array with invalid element at index ${idx}, it should be of type: string | symbol`\n );\n }\n}\n\nexport function throwInvalidActionTypeOrActionCreator(\n argPosition: number\n): never {\n throw new Error(\n `Argument ${argPosition} is invalid, it should be an action-creator instance from \"typesafe-actions\" or action type of type: string | symbol`\n );\n}\n","import { TypeConstant } from './type-helpers';\nimport {\n checkIsEmpty,\n throwIsEmpty,\n checkInvalidActionType,\n throwInvalidActionCreator,\n} from './utils/validation';\n\nexport function action<T extends TypeConstant, E>(\n type: T,\n payload: undefined,\n meta: undefined,\n error: E\n): { type: T; error: E };\n\nexport function action<T extends TypeConstant, M, E>(\n type: T,\n payload: undefined,\n meta: M,\n error: E\n): { type: T; meta: M; error: E };\n\nexport function action<T extends TypeConstant, P, E>(\n type: T,\n payload: P,\n meta: undefined,\n error: E\n): { type: T; payload: P; error: E };\n\nexport function action<T extends TypeConstant, P, M, E>(\n type: T,\n payload: P,\n meta: M,\n error: E\n): { type: T; payload: P; meta: M; error: E };\n\nexport function action<T extends TypeConstant, M>(\n type: T,\n payload: undefined,\n meta: M\n): { type: T; meta: M };\n\nexport function action<T extends TypeConstant, P, M>(\n type: T,\n payload: P,\n meta: M\n): { type: T; payload: P; meta: M };\n\nexport function action<T extends TypeConstant, P>(\n type: T,\n payload: P\n): { type: T; payload: P };\n\nexport function action<T extends TypeConstant>(type: T): { type: T };\n\n/**\n * @description flux standard action factory\n * @example\n * ```\n * const add = (amount: number, meta?: Meta, error?: boolean) => action('INCREMENT', amount, meta, error);\n * ```\n */\nexport function action<\n T extends TypeConstant,\n P = undefined,\n M = undefined,\n E = undefined\n>(type: T, payload?: P, meta?: M, error?: E) {\n if (checkIsEmpty(type)) {\n throwIsEmpty(1);\n }\n\n if (checkInvalidActionType(type)) {\n throwInvalidActionCreator(1);\n }\n\n return { type, payload, meta, error } as any;\n}\n","import {\n TypeConstant,\n ResolveType,\n ActionCreatorTypeMetadata,\n} from './type-helpers';\nimport {\n checkIsEmpty,\n throwIsEmpty,\n checkInvalidActionType,\n throwInvalidActionType,\n} from './utils/validation';\n\n/**\n * @description create custom action-creator using constructor function with injected type argument\n */\nexport function createCustomAction<\n TType extends TypeConstant,\n TArgs extends any[] = [],\n TReturn extends any = {}\n>(\n type: TType,\n createHandler?: (...args: TArgs) => TReturn\n): ((...args: TArgs) => ResolveType<{ type: TType } & TReturn>) &\n ActionCreatorTypeMetadata<TType> {\n if (checkIsEmpty(type)) {\n throwIsEmpty(1);\n }\n\n if (checkInvalidActionType(type)) {\n throwInvalidActionType(1);\n }\n\n const actionCreator = (...args: TArgs) => {\n const customProps =\n createHandler != null ? createHandler(...args) : undefined;\n return { type, ...customProps } as ResolveType<{ type: TType } & TReturn>;\n };\n\n const typeMeta = {\n getType: () => type,\n // redux-actions compatibility\n toString: () => type,\n } as ActionCreatorTypeMetadata<TType>;\n\n return Object.assign(actionCreator, typeMeta);\n}\n","import {\n TypeConstant,\n ActionCreatorBuilder,\n ActionCreatorTypeMetadata,\n ActionBuilder,\n} from './type-helpers';\nimport { createCustomAction } from './create-custom-action';\nimport {\n checkIsEmpty,\n throwIsEmpty,\n checkInvalidActionType,\n throwInvalidActionType,\n} from './utils/validation';\n\nexport function createAction<TType extends TypeConstant>(\n type: TType\n): <TPayload = undefined, TMeta = undefined>() => ActionCreatorBuilder<\n TType,\n TPayload,\n TMeta\n>;\n\nexport function createAction<\n TType extends TypeConstant,\n TCreatorPayload extends any = undefined,\n TCreatorMeta extends any = undefined,\n TArgs extends any[] = any[]\n>(\n type: TType,\n payloadCreator: undefined | ((...args: TArgs) => TCreatorPayload),\n metaCreator?: (...args: TArgs) => TCreatorMeta\n): <\n TPayload extends TCreatorPayload = TCreatorPayload,\n TMeta extends TCreatorMeta = TCreatorMeta\n>() => (...args: TArgs) => ActionBuilder<TType, TPayload, TMeta>;\n\n/**\n * @description create an action-creator\n */\nexport function createAction<\n TType extends TypeConstant,\n TCreatorPayload extends any = undefined,\n TCreatorMeta extends any = undefined,\n TArgs extends any[] = any[]\n>(\n type: TType,\n payloadCreator?: undefined | ((...args: TArgs) => TCreatorPayload),\n metaCreator?: (...args: TArgs) => TCreatorMeta\n):\n | (<\n TPayload extends TCreatorPayload = TCreatorPayload,\n TMeta extends TCreatorMeta = TCreatorMeta\n >() => (...args: TArgs) => ActionBuilder<TType, TPayload, TMeta>)\n | (<TPayload = undefined, TMeta = undefined>() => ActionCreatorBuilder<\n TType,\n TPayload,\n TMeta\n >) {\n if (checkIsEmpty(type)) {\n throwIsEmpty(1);\n }\n\n if (checkInvalidActionType(type)) {\n throwInvalidActionType(1);\n }\n\n return <TPayload, TMeta = undefined>() => {\n return createCustomAction(type, (...args: TArgs) => {\n let payload = args[0];\n let meta = args[1];\n\n if (payloadCreator != null || metaCreator != null) {\n payload = payloadCreator != null ? payloadCreator(...args) : undefined;\n meta = metaCreator != null ? metaCreator(...args) : undefined;\n }\n\n return {\n ...(payload !== undefined && { payload }),\n ...(meta !== undefined && { meta }),\n };\n }) as ActionCreatorBuilder<TType, TPayload, TMeta>;\n };\n}\n","import {\n TypeConstant,\n ActionCreator,\n ActionCreatorTypeMetadata,\n} from './type-helpers';\nimport {\n checkIsEmpty,\n throwIsEmpty,\n checkInvalidActionCreator,\n throwInvalidActionCreator,\n} from './utils/validation';\n\n/**\n * @description get the \"type literal\" of a given action-creator\n */\nexport function getType<TType extends TypeConstant>(\n actionCreator: ActionCreator<TType> & ActionCreatorTypeMetadata<TType>\n): TType {\n if (checkIsEmpty(actionCreator)) {\n throwIsEmpty(1);\n }\n\n if (checkInvalidActionCreator(actionCreator)) {\n throwInvalidActionCreator(1);\n }\n\n return actionCreator.getType!();\n}\n","import { ActionCreator, TypeConstant } from '../type-helpers';\nimport {\n checkIsEmpty,\n throwIsEmpty,\n checkInvalidActionType,\n throwInvalidActionType,\n} from '../utils/validation';\n\n/**\n * @description create custom action-creator using constructor function with injected type argument\n */\nexport function createCustomAction<\n T extends TypeConstant,\n AC extends ActionCreator<T> = () => { type: T }\n>(type: T, createHandler?: (type: T) => AC): AC {\n if (checkIsEmpty(type)) {\n throwIsEmpty(1);\n }\n\n if (checkInvalidActionType(type)) {\n throwInvalidActionType(1);\n }\n\n const actionCreator: AC =\n createHandler != null ? createHandler(type) : ((() => ({ type })) as AC);\n\n return Object.assign(actionCreator, {\n getType: () => type,\n // redux-actions compatibility\n toString: () => type,\n });\n}\n","import { createAction } from './create-action';\nimport { createCustomAction } from './create-custom-action';\nimport { createStandardAction } from './create-standard-action';\n\nexport default { createAction, createCustomAction, createStandardAction };\n","import { TypeConstant, ActionCreator } from '../type-helpers';\nimport { action } from '../action';\n\nexport type PayloadMetaAction<\n T extends TypeConstant,\n P,\n M\n> = P extends undefined\n ? M extends undefined\n ? { type: T }\n : { type: T; meta: M }\n : M extends undefined\n ? { type: T; payload: P }\n : { type: T; payload: P; meta: M };\n\n/**\n * @description typesafe action-creator factory\n */\nexport function createAction<\n T extends TypeConstant,\n AC extends ActionCreator<T> = () => { type: T }\n>(\n type: T,\n createHandler?: (\n actionCallback: <P = undefined, M = undefined>(\n payload?: P,\n meta?: M\n ) => PayloadMetaAction<T, P, M>\n ) => AC\n): AC {\n // validation is already done in action function\n\n const actionCreator: AC =\n createHandler == null\n ? ((() => action(type)) as AC)\n : createHandler(action.bind(null, type) as Parameters<\n typeof createHandler\n >[0]);\n\n return Object.assign(actionCreator, {\n getType: () => type,\n // redux-actions compatibility\n toString: () => type,\n });\n}\n","import { TypeConstant, ActionCreatorBuilder } from '../type-helpers';\nimport {\n checkIsEmpty,\n throwIsEmpty,\n checkInvalidActionType,\n throwInvalidActionType,\n} from '../utils/validation';\nimport { createCustomAction } from './create-custom-action';\n\n/** @private */\nexport type ActionBuilderMap<\n TType extends TypeConstant,\n TActionProps extends any,\n TPayloadArg extends any = undefined,\n TMetaArg extends any = undefined\n> = [TMetaArg] extends [undefined]\n ? [TPayloadArg] extends [undefined]\n ? () => { type: TType } & TActionProps\n : (payload: TPayloadArg) => { type: TType } & TActionProps\n : (payload: TPayloadArg, meta: TMetaArg) => { type: TType } & TActionProps;\n\nexport interface ActionBuilder<T extends TypeConstant> {\n <P = undefined, M = undefined>(): ActionCreatorBuilder<T, P, M>;\n map<R, P = undefined, M = undefined>(\n fn: (payload: P, meta: M) => R\n ): ActionBuilderMap<T, R, P, M>;\n}\n\n/**\n * @description create an action-creator of a given function that contains hidden \"type\" metadata\n */\nexport function createStandardAction<T extends TypeConstant>(\n type: T\n): ActionBuilder<T> {\n if (checkIsEmpty(type)) {\n throwIsEmpty(1);\n }\n\n if (checkInvalidActionType(type)) {\n throwInvalidActionType(1);\n }\n\n function constructor<P, M = undefined>(): ActionCreatorBuilder<T, P, M> {\n return createCustomAction(type, _type => (payload: P, meta: M) => ({\n type: _type,\n payload,\n meta,\n })) as ActionCreatorBuilder<T, P, M>;\n }\n\n function map<R, P, M>(\n fn: (payload: P, meta: M) => R\n ): ActionBuilderMap<T, R, P, M> {\n return createCustomAction(type, _type => (payload: P, meta: M) =>\n Object.assign(fn(payload, meta), { type: _type })\n ) as ActionBuilderMap<T, R, P, M>;\n }\n\n return Object.assign(constructor, { map });\n}\n","import {\n TypeConstant,\n ActionCreatorBuilder,\n ActionBuilder,\n} from './type-helpers';\nimport { createAction } from './create-action';\n\nexport function throwInvalidAsyncActionArgument(argPosition: number): never {\n throw new Error(\n `Argument ${argPosition} is invalid, it should be an action type of \"string | symbol\" or a tuple of \"[string | symbol, Function, Function?]\"`\n );\n}\n\ntype AsyncActionHandler<\n TType extends TypeConstant,\n TArgs extends any[],\n TPayloadMeta\n> = [TArgs] extends [never]\n ? ActionCreatorBuilder<\n TType,\n unknown extends TPayloadMeta\n ? any\n : [TPayloadMeta] extends [[infer T, any]]\n ? T\n : TPayloadMeta,\n unknown extends TPayloadMeta\n ? undefined\n : [TPayloadMeta] extends [[any, infer T]]\n ? T\n : undefined\n >\n : (\n ...args: TArgs\n ) => ActionBuilder<\n TType,\n [TPayloadMeta] extends [[infer T, any]] ? T : TPayloadMeta,\n [TPayloadMeta] extends [[any, infer T]] ? T : undefined\n >;\n\ninterface AsyncAction<\n TType1 extends TypeConstant,\n TPayload1 extends any,\n TMeta1 extends any,\n TArgs1 extends any[],\n TType2 extends TypeConstant,\n TPayload2 extends any,\n TMeta2 extends any,\n TArgs2 extends any[],\n TType3 extends TypeConstant,\n TPayload3 extends any,\n TMeta3 extends any,\n TArgs3 extends any[],\n TType4 extends TypeConstant,\n TPayload4 extends any,\n TMeta4 extends any,\n TArgs4 extends any[]\n> {\n // tslint:disable-next-line: callable-types\n <\n TPayloadMeta1 extends\n | TPayload1\n | [TPayload1, TMeta1] = TMeta1 extends undefined\n ? TPayload1\n : [TPayload1, TMeta1],\n TPayloadMeta2 extends\n | TPayload2\n | [TPayload2, TMeta2] = TMeta2 extends undefined\n ? TPayload2\n : [TPayload2, TMeta2],\n TPayloadMeta3 extends\n | TPayload3\n | [TPayload3, TMeta3] = TMeta3 extends undefined\n ? TPayload3\n : [TPayload3, TMeta3],\n TPayloadMeta4 extends\n | TPayload4\n | [TPayload4, TMeta4] = TMeta3 extends undefined\n ? TPayload4\n : [TPayload4, TMeta4]\n >(): [TType4] extends [never]\n ? {\n request: AsyncActionHandler<TType1, TArgs1, TPayloadMeta1>;\n success: AsyncActionHandler<TType2, TArgs2, TPayloadMeta2>;\n failure: AsyncActionHandler<TType3, TArgs3, TPayloadMeta3>;\n }\n : {\n request: AsyncActionHandler<TType1, TArgs1, TPayloadMeta1>;\n success: AsyncActionHandler<TType2, TArgs2, TPayloadMeta2>;\n failure: AsyncActionHandler<TType3, TArgs3, TPayloadMeta3>;\n cancel: AsyncActionHandler<TType4, TArgs4, TPayloadMeta4>;\n };\n}\n\nexport function createAsyncAction<\n TType1 extends TypeConstant,\n TType2 extends TypeConstant,\n TType3 extends TypeConstant,\n TType4 extends TypeConstant = never\n>(\n requestArg: TType1,\n successArg: TType2,\n failureArg: TType3,\n cancelArg?: TType4\n): AsyncAction<\n TType1,\n unknown,\n unknown,\n never,\n TType2,\n unknown,\n unknown,\n never,\n TType3,\n unknown,\n unknown,\n never,\n TType4,\n unknown,\n unknown,\n never\n>;\n\nexport function createAsyncAction<\n TType1 extends TypeConstant,\n TType2 extends TypeConstant,\n TType3 extends TypeConstant,\n TType4 extends TypeConstant = never,\n TPayloadCreator1 extends\n | ((...args: TArgs1) => TPayload1)\n | undefined = undefined,\n TPayloadCreator2 extends\n | ((...args: TArgs2) => TPayload2)\n | undefined = undefined,\n TPayloadCreator3 extends\n | ((...args: TArgs3) => TPayload3)\n | undefined = undefined,\n TPayloadCreator4 extends\n | ((...args: TArgs4) => TPayload4)\n | undefined = undefined,\n TMetaCreator1 extends ((...args: TArgs1) => TMeta1) | undefined = undefined,\n TMetaCreator2 extends ((...args: TArgs2) => TMeta2) | undefined = undefined,\n TMetaCreator3 extends ((...args: TArgs3) => TMeta3) | undefined = undefined,\n TMetaCreator4 extends ((...args: TArgs4) => TMeta4) | undefined = undefined,\n TPayload1 extends any = TPayloadCreator1 extends ((...args: any[]) => infer T)\n ? T\n : undefined,\n TMeta1 extends any = TMetaCreator1 extends ((...args: any[]) => infer T)\n ? T\n : undefined,\n TPayload2 extends any = TPayloadCreator2 extends ((...args: any[]) => infer T)\n ? T\n : undefined,\n TMeta2 extends any = TMetaCreator2 extends ((...args: any[]) => infer T)\n ? T\n : undefined,\n TPayload3 extends any = TPayloadCreator3 extends ((...args: any[]) => infer T)\n ? T\n : undefined,\n TMeta3 extends any = TMetaCreator3 extends ((...args: any[]) => infer T)\n ? T\n : undefined,\n TPayload4 extends any = TPayloadCreator4 extends ((...args: any[]) => infer T)\n ? T\n : undefined,\n TMeta4 extends any = TMetaCreator4 extends ((...args: any[]) => infer T)\n ? T\n : undefined,\n TArgs1 extends any[] = TPayloadCreator1 extends ((...args: infer T) => any)\n ? T\n : TMetaCreator1 extends ((...args: infer T) => any)\n ? T\n : never,\n TArgs2 extends any[] = TPayloadCreator2 extends ((...args: infer T) => any)\n ? T\n : TMetaCreator2 extends ((...args: infer T) => any)\n ? T\n : never,\n TArgs3 extends any[] = TPayloadCreator3 extends ((...args: infer T) => any)\n ? T\n : TMetaCreator3 extends ((...args: infer T) => any)\n ? T\n : never,\n TArgs4 extends any[] = TPayloadCreator4 extends ((...args: infer T) => any)\n ? T\n : TMetaCreator4 extends ((...args: infer T) => any)\n ? T\n : never\n>(\n requestArg:\n | TType1\n | [TType1, TPayloadCreator1]\n | [TType1, TPayloadCreator1, TMetaCreator1],\n successArg:\n | TType2\n | [TType2, TPayloadCreator2]\n | [TType2, TPayloadCreator2, TMetaCreator2],\n failureArg:\n | TType3\n | [TType3, TPayloadCreator3]\n | [TType3, TPayloadCreator3, TMetaCreator3],\n cancelArg?:\n | TType4\n | [TType4, TPayloadCreator4]\n | [TType4, TPayloadCreator4, TMetaCreator4]\n): AsyncAction<\n TType1,\n TPayload1,\n TMeta1,\n TArgs1,\n TType2,\n TPayload2,\n TMeta2,\n TArgs2,\n TType3,\n TPayload3,\n TMeta3,\n TArgs3,\n TType4,\n TPayload4,\n TMeta4,\n TArgs4\n>;\n\n/**\n * @description create an async action-creator object that contains `request`, `success` and `failure` actions as props\n */\nexport function createAsyncAction<\n TType1 extends TypeConstant,\n TType2 extends TypeConstant,\n TType3 extends TypeConstant,\n TType4 extends TypeConstant = never,\n TPayloadCreator1 extends\n | ((...args: TArgs1) => TPayload1)\n | undefined = undefined,\n TPayloadCreator2 extends\n | ((...args: TArgs2) => TPayload2)\n | undefined = undefined,\n TPayloadCreator3 extends\n | ((...args: TArgs3) => TPayload3)\n | undefined = undefined,\n TPayloadCreator4 extends\n | ((...args: TArgs4) => TPayload4)\n | undefined = undefined,\n TMetaCreator1 extends ((...args: TArgs1) => TMeta1) | undefined = undefined,\n TMetaCreator2 extends ((...args: TArgs2) => TMeta2) | undefined = undefined,\n TMetaCreator3 extends ((...args: TArgs3) => TMeta3) | undefined = undefined,\n TMetaCreator4 extends ((...args: TArgs4) => TMeta4) | undefined = undefined,\n TPayload1 extends any = TPayloadCreator1 extends ((...args: any[]) => infer T)\n ? T\n : undefined,\n TMeta1 extends any = TMetaCreator1 extends ((...args: any[]) => infer T)\n ? T\n : undefined,\n TPayload2 extends any = TPayloadCreator2 extends ((...args: any[]) => infer T)\n ? T\n : undefined,\n TMeta2 extends any = TMetaCreator2 extends ((...args: any[]) => infer T)\n ? T\n : undefined,\n TPayload3 extends any = TPayloadCreator3 extends ((...args: any[]) => infer T)\n ? T\n : undefined,\n TMeta3 extends any = TMetaCreator3 extends ((...args: any[]) => infer T)\n ? T\n : undefined,\n TPayload4 extends any = TPayloadCreator4 extends ((...args: any[]) => infer T)\n ? T\n : undefined,\n TMeta4 extends any = TMetaCreator4 extends ((...args: any[]) => infer T)\n ? T\n : undefined,\n TArgs1 extends any[] = TPayloadCreator1 extends ((...args: infer T) => any)\n ? T\n : TMetaCreator1 extends ((...args: infer T) => any)\n ? T\n : never,\n TArgs2 extends any[] = TPayloadCreator2 extends ((...args: infer T) => any)\n ? T\n : TMetaCreator2 extends ((...args: infer T) => any)\n ? T\n : never,\n TArgs3 extends any[] = TPayloadCreator3 extends ((...args: infer T) => any)\n ? T\n : TMetaCreator3 extends ((...args: infer T) => any)\n ? T\n : never,\n TArgs4 extends any[] = TPayloadCreator4 extends ((...args: infer T) => any)\n ? T\n : TMetaCreator4 extends ((...args: infer T) => any)\n ? T\n : never\n>(\n requestArg:\n | TType1\n | [TType1, TPayloadCreator1]\n | [TType1, TPayloadCreator1, TMetaCreator1],\n successArg:\n | TType2\n | [TType2, TPayloadCreator2]\n | [TType2, TPayloadCreator2, TMetaCreator2],\n failureArg:\n | TType3\n | [TType3, TPayloadCreator3]\n | [TType3, TPayloadCreator3, TMetaCreator3],\n cancelArg?:\n | TType4\n | [TType4, TPayloadCreator4]\n | [TType4, TPayloadCreator4, TMetaCreator4]\n): AsyncAction<\n TType1,\n TPayload1,\n TMeta1,\n TArgs1,\n TType2,\n TPayload2,\n TMeta2,\n TArgs2,\n TType3,\n TPayload3,\n TMeta3,\n TArgs3,\n TType4,\n TPayload4,\n TMeta4,\n TArgs4\n> {\n const constructor = (<\n TP1 = undefined,\n TM1 = undefined,\n TP2 = undefined,\n TM2 = undefined,\n TP3 = undefined,\n TM3 = undefined,\n TP4 = undefined,\n TM4 = undefined\n >() => {\n const results = [requestArg, successArg, failureArg, cancelArg].map(\n (arg, index) => {\n if (Array.isArray(arg)) {\n return createAction(arg[0], arg[1] as any, arg[2] as any)();\n } else if (typeof arg === 'string' || typeof arg === 'symbol') {\n return createAction(arg as string)();\n } else if (index < 3) {\n throwInvalidAsyncActionArgument(index);\n }\n }\n );\n\n const [request, success, failure, cancel] = results;\n\n return {\n request,\n success,\n failure,\n cancel,\n };\n }) as AsyncAction<\n TType1,\n TPayload1,\n TMeta1,\n TArgs1,\n TType2,\n TPayload2,\n TMeta2,\n TArgs2,\n TType3,\n TPayload3,\n TMeta3,\n TArgs3,\n TType4,\n TPayload4,\n TMeta4,\n TArgs4\n >;\n\n return constructor;\n}\n","import { getType } from './get-type';\nimport {\n checkValidActionCreator,\n checkValidActionType,\n throwInvalidActionTypeOrActionCreator,\n} from './utils/validation';\nimport { Reducer, Action, Types } from './type-helpers';\n\ntype HandleActionChainApi<\n TState,\n TInputAction extends Action,\n TRootAction extends Action\n> = <\n TActionCreator extends (...args: any[]) => TInputAction,\n THandledAction extends ReturnType<TActionCreator>,\n TOutputAction extends Exclude<TInputAction, THandledAction>\n>(\n singleOrMultipleCreatorsAndTypes: TActionCreator | TActionCreator[],\n reducer: (state: TState, action: THandledAction) => TState\n) => [TOutputAction] extends [Action]\n ? Reducer<TState, TRootAction> & {\n handlers: Record<\n Exclude<TRootAction, TOutputAction>['type'],\n (state: TState, action: TRootAction) => TState\n >;\n handleAction: HandleActionChainApi<TState, TOutputAction, TRootAction>;\n }\n : Reducer<TState, TRootAction> & {\n handlers: Record<\n TRootAction['type'],\n (state: TState, action: TRootAction) => TState\n >;\n };\n\ntype HandleTypeChainApi<\n TState,\n TInputAction extends Action,\n TRootAction extends Action\n> = <\n TType extends TInputAction['type'],\n THandledAction extends Extract<TInputAction, Action<TType>>,\n TOutputAction extends Exclude<TInputAction, THandledAction>\n>(\n singleOrMultipleCreatorsAndTypes: TType | TType[],\n reducer: (state: TState, action: THandledAction) => TState\n) => [TOutputAction] extends [Action]\n ? Reducer<TState, TRootAction> & {\n handlers: Record<\n Exclude<TRootAction, TOutputAction>['type'],\n (state: TState, action: TRootAction) => TState\n >;\n handleType: HandleTypeChainApi<TState, TOutputAction, TRootAction>;\n }\n : Reducer<TState, TRootAction> & {\n handlers: Record<\n TRootAction['type'],\n (state: TState, action: TRootAction) => TState\n >;\n };\n\ntype GetAction<\n TAction extends Action,\n TType extends TAction['type']\n> = TAction extends Action<TType> ? TAction : never;\n\ntype InitialHandler<TState, TRootAction extends Action> = {\n [P in TRootAction['type']]?: (\n state: TState,\n action: GetAction<TRootAction, P>\n ) => TState;\n};\n\ntype RootAction = Types extends { RootAction: infer T } ? T : any;\n\nexport function createReducer<TState, TRootAction extends Action = RootAction>(\n initialState: TState,\n initialHandlers: InitialHandler<TState, TRootAction> = {}\n) {\n const handlers: any = {\n ...initialHandlers,\n };\n\n const rootReducer: Reducer<TState, TRootAction> = (\n state = initialState,\n action: TRootAction\n ) => {\n if (handlers.hasOwnProperty(action.type)) {\n const reducer = handlers[action.type];\n if (typeof reducer !== 'function') {\n throw Error(\n `Reducer under \"${action.type}\" key is not a valid reducer`\n );\n }\n return reducer(state, action);\n } else {\n return state;\n }\n };\n\n const reducerHandler = ((\n singleOrMultipleCreatorsAndTypes: any,\n reducer: any\n ) => {\n const creatorsAndTypes = Array.isArray(singleOrMultipleCreatorsAndTypes)\n ? singleOrMultipleCreatorsAndTypes\n : [singleOrMultipleCreatorsAndTypes];\n\n const newHandlers: typeof handlers = {};\n\n creatorsAndTypes\n .map(\n (\n acOrType: TRootAction['type'] | ((...args: any[]) => TRootAction),\n index\n ) =>\n checkValidActionCreator(acOrType)\n ? getType(acOrType)\n : checkValidActionType(acOrType)\n ? acOrType\n : throwInvalidActionTypeOrActionCreator(index + 1)\n )\n .forEach(type => (newHandlers[type] = reducer));\n\n return createReducer<TState, TRootAction>(initialState, {\n ...handlers,\n ...newHandlers,\n });\n }) as\n | HandleActionChainApi<TState, TRootAction, TRootAction>\n | HandleTypeChainApi<TState, TRootAction, TRootAction>;\n\n const chainApi = Object.assign(rootReducer, {\n handlers: { ...handlers },\n handleAction: reducerHandler,\n handleType: reducerHandler,\n }) as Reducer<TState, TRootAction> &\n Readonly<{\n handlers: InitialHandler<TState, RootAction>;\n handleAction: [unknown] extends [TRootAction]\n ? any\n : HandleActionChainApi<TState, TRootAction, TRootAction>;\n handleType: [unknown] extends [TRootAction]\n ? any\n : HandleTypeChainApi<TState, TRootAction, TRootAction>;\n }>;\n\n return chainApi;\n}\n","import { ActionCreatorTypeMetadata } from './type-helpers';\nimport {\n checkInvalidActionCreatorInArray,\n checkIsEmpty,\n throwIsEmpty,\n} from './utils/validation';\n\nexport type ActionCreator<T extends { type: string }> = ((\n ...args: any[]\n) => T) &\n ActionCreatorTypeMetadata<T['type']>;\n\n/**\n * @description (curried assert function) check if an action is the instance of given action-creator(s)\n * @description it works with discriminated union types\n */\nexport function isActionOf<AC extends ActionCreator<{ type: string }>>(\n actionCreator: AC | AC[],\n action: { type: string }\n): action is ReturnType<AC>;\n\n/**\n * @description (curried assert function) check if an action is the instance of given action-creator(s)\n * @description it works with discriminated union types\n */\nexport function isActionOf<AC extends ActionCreator<{ type: string }>>(\n actionCreator: AC | AC[]\n): (action: { type: string }) => action is ReturnType<AC>;\n\n/**\n * implementation\n */\nexport function isActionOf<AC extends ActionCreator<{ type: string }>>(\n actionCreatorOrCreators: AC | AC[],\n action?: { type: string }\n) {\n if (checkIsEmpty(actionCreatorOrCreators)) {\n throwIsEmpty(1);\n }\n\n const actionCreators = Array.isArray(actionCreatorOrCreators)\n ? actionCreatorOrCreators\n : [actionCreatorOrCreators];\n\n actionCreators.forEach(checkInvalidActionCreatorInArray);\n\n const assertFn = (_action: { type: string }) =>\n actionCreators.some(\n actionCreator => _action.type === actionCreator.getType!()\n );\n\n // 1 arg case => return curried version\n if (action === undefined) {\n return assertFn;\n }\n // 2 args case => invoke assertFn and return the result\n return assertFn(action);\n}\n","import {\n checkInvalidActionTypeInArray,\n checkIsEmpty,\n throwIsEmpty,\n} from './utils/validation';\n/**\n * @description (curried assert function) check if action type is equal given type-constant\n * @description it works with discriminated union types\n */\nexport function isOfType<T extends string, A extends { type: string }>(\n type: T | T[],\n action: A\n): action is A extends { type: T } ? A : never;\n\n/**\n * @description (curried assert function) check if action type is equal given type-constant\n * @description it works with discriminated union types\n */\nexport function isOfType<T extends string>(\n type: T | T[]\n): <A extends { type: string }>(\n action: A\n) => action is A extends { type: T } ? A : never;\n\n/**\n * implementation\n */\nexport function isOfType<T extends string, A extends { type: T }>(\n actionTypeOrTypes: T | T[],\n action?: A\n) {\n if (checkIsEmpty(actionTypeOrTypes)) {\n throwIsEmpty(1);\n }\n\n const actionTypes = Array.isArray(actionTypeOrTypes)\n ? actionTypeOrTypes\n : [actionTypeOrTypes];\n\n actionTypes.forEach(checkInvalidActionTypeInArray);\n\n const assertFn = (_action: A) => actionTypes.includes(_action.type);\n\n // 1 arg case => return curried version\n if (action === undefined) {\n return assertFn;\n }\n // 2 args case => invoke assertFn and return the result\n return assertFn(action);\n}\n"],"names":["checkIsEmpty","arg","throwIsEmpty","argPosition","Error","checkValidActionCreator","throwInvalidActionCreator","checkInvalidActionCreatorInArray","idx","getType","checkValidActionType","checkInvalidActionType","throwInvalidActionType","checkInvalidActionTypeInArray","action","type","payload","meta","error","createCustomAction","createHandler","Object","assign","customProps","undefined","toString","createAction","payloadCreator","metaCreator","actionCreator","bind","createStandardAction","_type","map","fn","requestArg","successArg","failureArg","cancelArg","results","index","Array","isArray","throwInvalidAsyncActionArgument","request","success","failure","cancel","createReducer","initialState","initialHandlers","handlers","reducerHandler","singleOrMultipleCreatorsAndTypes","reducer","creatorsAndTypes","newHandlers","acOrType","throwInvalidActionTypeOrActionCreator","forEach","state","hasOwnProperty","handleAction","handleType","actionCreatorOrCreators","actionCreators","assertFn","_action","some","actionTypeOrTypes","actionTypes","includes"],"mappings":"sNAMgBA,EAAaC,UACb,MAAPA,WAGOC,EAAaC,SACrB,IAAIC,kBAAkBD,yBAGdE,EACdJ,SAEsB,mBAARA,GAAsB,YAAaA,WAOnCK,EAA0BH,SAClC,IAAIC,kBACID,2FAIAI,EACdN,EACAO,MAEW,MAAPP,QACI,IAAIG,6DAC+CI,GAEpD,GAAmB,MAAfP,EAAIQ,cACP,IAAIL,+DAEiDI,gFAK/CE,EAAqBT,SACb,iBAARA,GAAmC,iBAARA,WAG3BU,EAAuBV,UAC7BS,EAAqBT,YAGfW,EAAuBT,SAC/B,IAAIC,kBACID,gFAIAU,EACdZ,EACAO,MAEW,MAAPP,QACI,IAAIG,6DAC+CI,GAEpD,GAAmB,iBAARP,GAAmC,iBAARA,QACrC,IAAIG,+DACiDI,sDCR/CM,EAKdC,EAASC,EAAaC,EAAUC,UAC5BlB,EAAae,IACfb,EAAa,GAGXS,EAAuBI,IACzBT,EAA0B,GAGrB,CAAES,KAAAA,EAAMC,QAAAA,EAASC,KAAAA,EAAMC,MAAAA,YC7DhBC,EAKdJ,EACAK,GAGIpB,EAAae,IACfb,EAAa,GAGXS,EAAuBI,IACzBH,EAAuB,UAelBS,OAAOC,QAZQ,eACdC,EACa,MAAjBH,EAAwBA,+BAAyBI,wBAC1CT,KAAAA,GAASQ,KAGH,CACfd,QAAS,kBAAMM,GAEfU,SAAU,kBAAMV,cCFJW,EAMdX,EACAY,EACAC,UAWI5B,EAAae,IACfb,EAAa,GAGXS,EAAuBI,IACzBH,EAAuB,GAGlB,kBACEO,EAAmBJ,GAAM,eAC1BC,0CACAC,iDAEkB,MAAlBU,GAAyC,MAAfC,IAC5BZ,EAA4B,MAAlBW,EAAyBA,+BAA0BH,EAC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