Skip to content

Commit

Permalink
feat(datacube): fetch is configurable at datacube instantiation
Browse files Browse the repository at this point in the history
  • Loading branch information
vhf committed Sep 10, 2019
1 parent 00ab2a6 commit c93abff
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/datacube.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { NamedNode } from "rdf-js";
import { Generator as SparqlGenerator } from "sparqljs";
import DataSet, { IDataSetOptions, Label } from "./dataset";
import { generateLangCoalesce, generateLangOptionals, prefixes } from "./query/utils";
import SparqlFetcher from "./sparqlfetcher";
import SparqlFetcher, { ISparqlFetcherOptions } from "./sparqlfetcher";
import { SelectQuery } from "./sparqljs";

export interface ICubeOptions {
languages?: string[];
fetcher?: ISparqlFetcherOptions;
}

type SerializedDataCube = {
Expand Down Expand Up @@ -53,7 +54,7 @@ export class DataCube {
constructor(endpoint: string, options: ICubeOptions = {}) {
this.endpoint = endpoint;
this.languages = options.languages || ["de", "it"];
this.fetcher = new SparqlFetcher(endpoint);
this.fetcher = new SparqlFetcher(endpoint, options.fetcher || {});
this.cachedDatasets = new Map();
this.cachedGraphs = [];
}
Expand Down
6 changes: 5 additions & 1 deletion src/sparqlfetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@ type RDFTerm =
| { type: "bnode"; value: string };

export type Result = Record<string, Term>;
export interface ISparqlFetcherOptions {
fetch?: typeof fetch;
fetchOptions?: RequestInit;
}

export default class SparqlFetcher {
private fetch: typeof fetch;
private fetchOptions: RequestInit;
private endpoint: string;

constructor(endpoint: string, options: { fetch?: typeof fetch, fetchOptions?: RequestInit } = {}) {
constructor(endpoint: string, options: ISparqlFetcherOptions = {}) {
this.endpoint = endpoint;
this.fetch = options.fetch || fetch;
this.fetchOptions = options.fetchOptions || {
Expand Down

0 comments on commit c93abff

Please sign in to comment.