Minor refactoring of @hediet/debug-visualizer-data-extraction's API. Improved documentation.
This commit is contained in:
@@ -1,22 +1,45 @@
|
||||
import { ExtractedData } from "../DataExtractionResult";
|
||||
|
||||
export interface DataExtractor<T extends ExtractedData> {
|
||||
/**
|
||||
* Must be unique among all data extractors.
|
||||
*/
|
||||
id: string;
|
||||
getExtractions(
|
||||
data: unknown,
|
||||
extractionCollector: ExtractionCollector<T>,
|
||||
evalFn: <TEval>(expression: string) => TEval
|
||||
context: DataExtractorContext
|
||||
): void;
|
||||
}
|
||||
|
||||
export interface ExtractionCollector<T extends ExtractedData> {
|
||||
/**
|
||||
* Suggests a possible extraction.
|
||||
*/
|
||||
addExtraction(extraction: DataExtraction<T>): void;
|
||||
}
|
||||
|
||||
export interface DataExtractorContext {
|
||||
/**
|
||||
* Evaluates an expression in the context of the active stack frame.
|
||||
*/
|
||||
evalFn: <TEval>(expression: string) => TEval;
|
||||
}
|
||||
|
||||
export interface DataExtraction<TData extends ExtractedData> {
|
||||
// the higher the better
|
||||
/**
|
||||
* Higher priorities are preferred.
|
||||
*/
|
||||
priority: number;
|
||||
|
||||
/**
|
||||
* A unique id identifying this extraction among all extractions.
|
||||
* Required to express extraction preferences.
|
||||
*/
|
||||
id: string;
|
||||
/**
|
||||
* A user friendly name of this extraction.
|
||||
*/
|
||||
name: string;
|
||||
extractData(): TData;
|
||||
}
|
||||
@@ -24,7 +47,7 @@ export interface DataExtraction<TData extends ExtractedData> {
|
||||
export function getExtractions<T extends ExtractedData>(
|
||||
extractor: DataExtractor<T>,
|
||||
data: unknown,
|
||||
evalFn: <T>(expression: string) => T
|
||||
context: DataExtractorContext
|
||||
): DataExtraction<T>[] {
|
||||
const extractions = new Array<DataExtraction<T>>();
|
||||
const collector: ExtractionCollector<T> = {
|
||||
@@ -32,6 +55,6 @@ export function getExtractions<T extends ExtractedData>(
|
||||
extractions.push(extraction);
|
||||
},
|
||||
};
|
||||
extractor.getExtractions(data, collector, evalFn);
|
||||
extractor.getExtractions(data, collector, context);
|
||||
return extractions;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user