import type { SagaIterator } from 'redux-saga'; import type { LoadingMapPayload, LoadingState, LoadingItemState, } from 'robodux'; export type { LoadingState, LoadingItemState }; type IfAny = 0 extends 1 & T ? Y : N; export interface Payload

{ payload: P; } export interface PipeCtx

extends Payload

{ name: string; key: string; action: ActionWithPayload>; actionFn: IfAny< P, CreateAction, CreateActionWithPayload, P> >; } export interface LoaderCtx

extends PipeCtx

{ loader: LoadingMapPayload> | null; } export interface ApiFetchSuccess { ok: true; data: ApiSuccess; } export interface ApiFetchError { ok: false; data: ApiError; } export type ApiFetchResponse = | ApiFetchSuccess | ApiFetchError; export type ApiRequest = Partial<{ url: string } & RequestInit>; export type RequiredApiRequest = { url: string; headers: HeadersInit; } & Partial; export interface FetchCtx

extends PipeCtx

{ request: ApiRequest | null; req: (r?: ApiRequest) => RequiredApiRequest; response: Response | null; bodyType: 'arrayBuffer' | 'blob' | 'formData' | 'json' | 'text'; } export interface FetchJson { json: ApiFetchResponse; } export interface FetchJsonCtx

extends FetchCtx

, FetchJson {} export interface ApiCtx extends FetchJsonCtx { actions: Action[]; loader: Omit>, 'id'> | null; cache: boolean; cacheData: any; } export type Middleware = ( ctx: Ctx, next: Next, ) => any; export type MiddlewareCo = | Middleware | Middleware[]; export type MiddlewareApi = ( ctx: Ctx, next: Next, ) => any; export type MiddlewareApiCo = | Middleware | Middleware[]; export type Next = () => any; export interface Action { type: string; } export interface ActionWithPayload

extends Action { payload: P; } export interface CreateActionPayload

{ name: string; key: string; options: P; } export interface InvalidateCachePayload { invalidate?: boolean; } export type CreateActionFn = () => ActionWithPayload>; export interface CreateAction extends CreateActionFn { run: (p: ActionWithPayload>) => SagaIterator; } export type CreateActionFnWithPayload

= ( p: P, ) => ActionWithPayload>; export interface CreateActionWithPayload extends CreateActionFnWithPayload

{ run: (a: ActionWithPayload>) => SagaIterator; }