Commit e7f0912e authored by Fabien Amarger's avatar Fabien Amarger
Browse files

feat: [datafetcher] Add datafetcher to the simplerender signature

This datafetcher implement the fetchDataFromURI method which fetch
the data for the URI and format the return, depending on the respFormat
parameter.

By the way, add the nodeId parameter, which is the node id in which
the view must render the result.
parent 476859f89633
Pipeline #13916 passed with stages
in 2 minutes and 10 seconds
......@@ -53,10 +53,35 @@ export interface ViewRendering {
suggestedResources?: Resource[];
}
export type FetchDataFromURIFunction = (
uri: string,
respFormat?: {[key: string]: string}
) => Promise<{[key: string]: string}>;
export type DataFetcher = {
/**
* The fetchDataFromURI is the method to fetch data for a dedicated URI
*/
fetchDataFromURI: (
/**
* The uri for which we want fetch data for
*/
uri: string,
/**
* The respFormat object is a way to configure how to format data when fetched.
* This allow to define how to result will be formated to avoid manipulate triples.
* The keys in the respFormat will be used for the object returned. The values are
* the predicate to use to discover a specific relation. The result object will
* have the string representation for the specified predicate.
* For exemple :
* respFormat(
* "http://fr.dbpedia.org/resource/Victor_Hugo", {
* label: "http://www.w3.org/2000/01/rdf-schema#label",
* sameAs: "http://www.w3.org/2002/07/owl#sameAs",
* });
* returns a promise for the result :
* {label: "Victor Hugo", sameAs: "http://rdf.freebase.com/ns/m.01vh096"}
* Note that the results contains only one result.
* TODO change to fetch several values for a predicate
*/
respFormat?: {[key: string]: string}
) => Promise<{[key: string]: string}>;
};
/**
* The implementation of a view
......@@ -88,9 +113,22 @@ export interface ViewImplementation {
): ViewRendering;
simpleRender?: (
/**
* The node id in which the view must be rendered
*/
nodeId: string,
/**
* The triples in which the target is subject or object
*/
context: $rdf.Formula,
/**
* The target URI. The target is the element we want to show with the view
*/
target: string,
fetchDataFromURI?: FetchDataFromURIFunction
/**
* The (optional) data fetcher is an utility to ease fetching data for a specific URI
*/
dataFetcher?: DataFetcher
) => Element;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment