import { AsyncThunk } from '@reduxjs/toolkit';
import { AsyncThunkConfig } from '@reduxjs/toolkit';
import { Draft } from '@reduxjs/toolkit';
import { PayloadAction } from '@reduxjs/toolkit';
import { Slice } from '@reduxjs/toolkit';
import { SliceSelectors } from '@reduxjs/toolkit';
declare type Append
= [...P, K];
declare type ArrayElement = T extends readonly (infer U)[] ? U : T extends (infer U)[] ? U : never;
export declare function batchingUpdate>(state: T, valueList: CdeebeeValueList): void;
export declare interface CdeebeeActiveRequest {
api: string;
requestId: string;
}
export declare interface CdeebeeHistoryState {
requestId: string;
api: string;
request: unknown;
}
export declare type CdeebeeListStrategy = Record;
export declare type CdeebeeModule = 'history' | 'listener' | 'storage' | 'cancelation' | 'queryQueue';
export declare interface CdeebeeRequestOptions extends Partial, 'fileKey' | 'bodyKey' | 'normalize'>> {
api: string;
files?: File[];
method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
body?: unknown;
headers?: Record;
onResult?: (response: T) => void;
ignore?: boolean;
responseType?: 'json' | 'text' | 'blob';
listStrategy?: Partial>;
historyClear?: boolean;
}
declare interface CdeebeeRequestState {
active: CdeebeeActiveRequest[];
errors: Record;
done: Record;
lastResultIdList: Record>;
}
declare interface CdeebeeSettings {
modules: CdeebeeModule[];
fileKey: string;
bodyKey: string;
mergeWithData: Record | (() => Record);
mergeWithHeaders: Record | (() => Record);
listStrategy?: CdeebeeListStrategy;
normalize?: (storage: CdeebeeState, result: unknown, strategyList: CdeebeeListStrategy) => Record;
maxHistorySize?: number;
}
export declare interface CdeebeeState {
settings: CdeebeeSettings;
storage: T;
request: CdeebeeRequestState;
}
declare type CdeebeeStrategy = 'merge' | 'replace' | 'skip';
declare type CdeebeeValueItem = NonEmptyPaths extends infer P ? P extends readonly (string | number)[] ? {
key: P;
value: ValueAtPath;
} : never : never;
export declare type CdeebeeValueList = ReadonlyArray>;
/**
* Generic hook factory that creates a selector hook for cdeebee state.
* This allows the hooks to work with any Redux root state structure.
*
* @template RootState - The shape of the Redux root state
* @template Storage - The shape of the cdeebee storage
* @param selectCdeebee - Function to select the cdeebee slice from root state
* @returns An object containing all cdeebee hooks
*/
export declare function createCdeebeeHooks(selectCdeebee: (state: RootState) => CdeebeeState): {
useLoading: (apiList: string[]) => boolean;
useRequestHistory: (api: string) => CdeebeeHistoryState[];
useRequestErrors: (api: string) => CdeebeeHistoryState[];
useStorageList: (listName: K) => Storage[K];
useStorage: () => Storage;
useIsLoading: () => boolean;
useLastResultIdList: (api: string, listName: K) => string[];
};
export declare function defaultNormalize(cdeebee: CdeebeeState, response: IResponse, strategyList: CdeebeeListStrategy): Record;
export declare const factory: (settings: CdeebeeSettings, storage?: T) => Slice, {
set(state: {
settings: {
modules: CdeebeeModule[];
fileKey: string;
bodyKey: string;
mergeWithData: (() => Record) | {
[x: string]: unknown;
};
mergeWithHeaders: (() => Record) | {
[x: string]: string;
};
listStrategy?: (CdeebeeListStrategy | undefined extends infer V ? V extends object ? Draft : V : never) | undefined;
normalize?: ((storage: CdeebeeState, result: unknown, strategyList: CdeebeeListStrategy) => Record) | undefined;
maxHistorySize?: number | undefined;
};
storage: T extends infer V ? V extends object ? Draft : V : never;
request: {
active: {
api: string;
requestId: string;
}[];
errors: {
[x: string]: {
requestId: string;
api: string;
request: unknown;
}[];
};
done: {
[x: string]: {
requestId: string;
api: string;
request: unknown;
}[];
};
lastResultIdList: {
[x: string]: {
[x: string]: string[];
};
};
};
}, action: {
payload: CdeebeeValueList;
}): void;
historyClear(state: {
settings: {
modules: CdeebeeModule[];
fileKey: string;
bodyKey: string;
mergeWithData: (() => Record) | {
[x: string]: unknown;
};
mergeWithHeaders: (() => Record) | {
[x: string]: string;
};
listStrategy?: (CdeebeeListStrategy | undefined extends infer V ? V extends object ? Draft : V : never) | undefined;
normalize?: ((storage: CdeebeeState, result: unknown, strategyList: CdeebeeListStrategy) => Record) | undefined;
maxHistorySize?: number | undefined;
};
storage: T extends infer V ? V extends object ? Draft : V : never;
request: {
active: {
api: string;
requestId: string;
}[];
errors: {
[x: string]: {
requestId: string;
api: string;
request: unknown;
}[];
};
done: {
[x: string]: {
requestId: string;
api: string;
request: unknown;
}[];
};
lastResultIdList: {
[x: string]: {
[x: string]: string[];
};
};
};
}, action: PayloadAction): void;
}, "cdeebee", "cdeebee", SliceSelectors>>;
declare type IResponse = Record;
declare type IsArray = T extends readonly unknown[] ? true : T extends unknown[] ? true : false;
declare type KeyOf = Extract;
declare type NonEmptyPaths = Exclude, []>;
declare type Paths = IsArray extends true ? P | Paths, Append> : T extends object ? {
[K in KeyOf]: Paths>;
}[KeyOf] : P;
export declare const request: AsyncThunk< {
result: unknown;
startedAt: string;
endedAt: string;
}, CdeebeeRequestOptions, AsyncThunkConfig>;
declare type ResponseValue = Record;
/**
* Standalone hook that can be used without createCdeebeeHooks.
* Assumes the cdeebee slice is at state.cdeebee.
*
* @returns true if any request is active
*/
export declare function useIsLoading(): boolean;
/**
* Standalone hook that can be used without createCdeebeeHooks.
* Assumes the cdeebee slice is at state.cdeebee.
*
* Get the list of IDs returned by the last successful request to an API for a specific list.
* Useful for filtering storage data to show only results from a specific request.
*
* @param api - The API endpoint
* @param listName - The name of the list in storage (typed from Storage)
* @returns Array of primary key IDs from the last response for that list
*
* @example
* const productList = useStorageList('productList');
* const lastIDList = useLastResultIdList('/api/search', 'productList');
* const displayResults = lastIDList.map(id => productList[id]).filter(Boolean);
*/
export declare function useLastResultIdList(api: string, listName: K): string[];
/**
* Standalone hook that can be used without createCdeebeeHooks.
* Assumes the cdeebee slice is at state.cdeebee.
*
* @param apiList - Array of API endpoints to check
* @returns true if any of the APIs are currently active/loading
*
* @example
* const isLoading = useLoading(['/api/forums', '/api/threads']);
*/
export declare function useLoading(apiList: string[]): boolean;
/**
* Standalone hook that can be used without createCdeebeeHooks.
* Assumes the cdeebee slice is at state.cdeebee.
*
* @param api - The API endpoint
* @returns Array of error history entries
*/
export declare function useRequestErrors(api: string): CdeebeeHistoryState[];
/**
* Standalone hook that can be used without createCdeebeeHooks.
* Assumes the cdeebee slice is at state.cdeebee.
*
* @param api - The API endpoint
* @returns Array of successful request history entries
*/
export declare function useRequestHistory(api: string): CdeebeeHistoryState[];
/**
* Standalone hook that can be used without createCdeebeeHooks.
* Assumes the cdeebee slice is at state.cdeebee.
*
* @returns The complete storage object
*/
export declare function useStorage(): Storage;
/**
* Standalone hook that can be used without createCdeebeeHooks.
* Assumes the cdeebee slice is at state.cdeebee.
*
* @param listName - The name of the list in storage
* @returns The list data
*/
export declare function useStorageList(listName: K): Storage[K];
declare type ValueAtPath = P extends [] ? T : P extends readonly [infer K, ...infer R] ? K extends keyof T ? ValueAtPath> : T extends readonly (infer U)[] | (infer U)[] ? K extends number | `${number}` ? ValueAtPath> : never : never : never;
export { }