export type GetApiStoreNameSparqlArgs = {storeName: string, query: string, 'default-graph-uri'?: string | undefined, 'named-graph-uri'?: string | undefined}; export type GetApiStoreNameSparqlOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Execute a SPARQL query and return the results * * GET /{storeName}/sparql */ export const getApiStoreNameSparql = async (args: GetApiStoreNameSparqlArgs, options: GetApiStoreNameSparqlOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.query != null) query.append("query", String(args.query)) if (args['default-graph-uri'] != null) query.append("default-graph-uri", String(args['default-graph-uri'])) if (args['named-graph-uri'] != null) query.append("named-graph-uri", String(args['named-graph-uri'])) const url = `${baseUrl.replace(/\/+$/, '')}/${encodeURIComponent(String(args.storeName))}/sparql${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };