@jsmanifest/content-combiner
Version:
Combine content from multiple sources and transform them into one unified data structure to work with
30 lines (29 loc) • 1.22 kB
TypeScript
import Keymapper from './Keymapper';
import * as T from './types';
declare class PostsAggregator<DataObject extends {} = any> {
#private;
constructor({ dataKeys, fetchers, keymapper, }?: {
dataKeys?: string[];
fetchers?: T.Fetcher<DataObject>[];
keymapper?: Keymapper;
});
/**
* Runs each fetcher and parses each list of results using the keymappers that
* are currently registered
* @param { object } options - Options passed to each fetch function
*/
execute<T = any>(options?: T): Promise<DataObject[][]>;
createFetcher(fetch: T.Fetcher, options: {
keymappers: T.ConsumerKeymap<DataObject>;
}): {
(...args: any[]): Promise<DataObject | DataObject[]>;
id: string;
};
/** Formats/parses the keymappers and returns the keymap used on the executor */
getKeymap(): Record<keyof DataObject, T.FuncMapper<DataObject>>;
getKeymapper(key: string): string | T.ArrayMapper | T.FuncMapper<any> | undefined;
setKeymapper(key: string | Record<string, T.Mapper<DataObject>>, mapper: T.Mapper<DataObject>): this;
getDataKeys(): string[];
setDataKeys(keys: string[]): this;
}
export default PostsAggregator;