@knowmax/genericlist-core
Version:
Knowmax Generic list with basic CRUD support without any user interface implementation.
46 lines (45 loc) • 2.65 kB
TypeScript
import type { FetchOptions } from "../types";
export type TranslationValues = Record<string, string | number>;
export type OnGetHeadersType = (token?: string, language?: string, headers?: any, listId?: string) => any;
export type OnFetchType = <T>(url: string, options?: FetchOptions, listId?: string) => Promise<T>;
export type OnErrorMessageType = (error: Error) => Promise<string>;
export type OnSerializeType = (params: URLSearchParams, settings: GenericListSettings, listId?: string) => void;
export type OnTranslateType = (key: string, values?: TranslationValues, listId?: string) => string;
/** Responsible for all system settings in use for all generic lists. Allows system specific implementation of generic list components. */
export declare class GenericListSettings {
/** Never use directly. Always use getter. */
private _onFetch;
private _onFetchSet;
/** Never use directly. Always use getter. */
private _onTranslate;
private _onTranslateSet;
constructor();
/** Set after required configuration of onFetch and onTranslate were made. */
ready: boolean;
/** Internally called after configuration of required settings was done. No need to call it externally. */
setReady(value: boolean): void;
/** Set to required bearer token for use in authentication of fetch requests. */
token?: string;
setToken(value?: string): void;
/** Set to required language of user for use in fetch requests to get localized data from server. */
language?: string;
setLanguage(value?: string): void;
/** Contains current set of values components user for state. */
params: URLSearchParams;
/** Set to current set of values for components to use for state. */
setParams(value: URLSearchParams): void;
/** Internally used to serialize params. By default set to internally maintained params. Override for custom onSerialize for custom serialization. */
serialize(params: URLSearchParams): void;
/** Used for fetching data from server. */
get onFetch(): OnFetchType;
set onFetch(value: OnFetchType);
/** Used for translation of all language sensitive contents. */
get onTranslate(): OnTranslateType;
set onTranslate(value: OnTranslateType);
/** Override to handle custom serialization of user settings like sorting, filtering and paging. */
onSerialize: OnSerializeType;
/** Override for custom implementation of header generation for fetch requests. */
onGetHeaders: OnGetHeadersType;
/** Override for custom implementation of error message extraction after for example fetch requests. */
onErrorMessage: OnErrorMessageType;
}