From c93abff4aebb81d78aed2f458ff7958325894371 Mon Sep 17 00:00:00 2001 From: Victor Felder Date: Tue, 10 Sep 2019 12:05:14 +0200 Subject: [PATCH] feat(datacube): fetch is configurable at datacube instantiation --- src/datacube.ts | 5 +++-- src/sparqlfetcher.ts | 6 +++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/datacube.ts b/src/datacube.ts index 1f821b9..11bbe70 100644 --- a/src/datacube.ts +++ b/src/datacube.ts @@ -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 = { @@ -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 = []; } diff --git a/src/sparqlfetcher.ts b/src/sparqlfetcher.ts index e8df993..7c2646d 100644 --- a/src/sparqlfetcher.ts +++ b/src/sparqlfetcher.ts @@ -17,13 +17,17 @@ type RDFTerm = | { type: "bnode"; value: string }; export type Result = Record; +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 || {