@comunica/actor-rdf-parse-jsonld
Advanced tools
Comparing version 1.12.1 to 1.13.0
import { IActionHttp, IActorHttpOutput } from "@comunica/bus-http"; | ||
import { ActionContext, Actor, IActorTest, Mediator } from "@comunica/core"; | ||
import { IDocumentLoader, IJsonLdContext } from "jsonld-context-parser"; | ||
import { FetchDocumentLoader } from "jsonld-context-parser"; | ||
/** | ||
* A JSON-LD document loader that fetches over an HTTP bus using a given mediator. | ||
*/ | ||
export declare class DocumentLoaderMediated implements IDocumentLoader { | ||
export declare class DocumentLoaderMediated extends FetchDocumentLoader { | ||
private readonly mediatorHttp; | ||
private readonly context; | ||
constructor(mediatorHttp: Mediator<Actor<IActionHttp, IActorTest, IActorHttpOutput>, IActionHttp, IActorTest, IActorHttpOutput>, context: ActionContext); | ||
load(url: string): Promise<IJsonLdContext>; | ||
protected static createFetcher(mediatorHttp: Mediator<Actor<IActionHttp, IActorTest, IActorHttpOutput>, IActionHttp, IActorTest, IActorHttpOutput>, context: ActionContext): (input: RequestInfo, init: RequestInit) => Promise<Response>; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const bus_http_1 = require("@comunica/bus-http"); | ||
const jsonld_context_parser_1 = require("jsonld-context-parser"); | ||
const stringifyStream = require("stream-to-string"); | ||
@@ -8,15 +9,14 @@ /** | ||
*/ | ||
class DocumentLoaderMediated { | ||
class DocumentLoaderMediated extends jsonld_context_parser_1.FetchDocumentLoader { | ||
constructor(mediatorHttp, context) { | ||
super(DocumentLoaderMediated.createFetcher(mediatorHttp, context)); | ||
this.mediatorHttp = mediatorHttp; | ||
this.context = context; | ||
} | ||
async load(url) { | ||
const response = await this.mediatorHttp.mediate({ input: url, init: { headers: new Headers({ accept: 'application/ld+json' }) }, context: this.context }); | ||
if (response.ok) { | ||
return JSON.parse(await stringifyStream(bus_http_1.ActorHttp.toNodeReadable(response.body))); | ||
} | ||
else { | ||
throw new Error(`No valid context was found at ${url}: ${response.statusText}`); | ||
} | ||
static createFetcher(mediatorHttp, context) { | ||
return async (url, init) => { | ||
const response = await mediatorHttp.mediate({ input: url, init, context }); | ||
response.json = async () => JSON.parse(await stringifyStream(bus_http_1.ActorHttp.toNodeReadable(response.body))); | ||
return response; | ||
}; | ||
} | ||
@@ -23,0 +23,0 @@ } |
{ | ||
"name": "@comunica/actor-rdf-parse-jsonld", | ||
"version": "1.12.1", | ||
"version": "1.13.0", | ||
"description": "A JSON-LD RDF Parse actor", | ||
@@ -41,8 +41,8 @@ "lsd:module": "https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-rdf-parse-jsonld", | ||
"devDependencies": { | ||
"@comunica/bus-http": "^1.10.0", | ||
"@comunica/bus-rdf-parse": "^1.11.0", | ||
"@comunica/core": "^1.9.2" | ||
"@comunica/bus-http": "^1.13.0", | ||
"@comunica/bus-rdf-parse": "^1.13.0", | ||
"@comunica/core": "^1.13.0" | ||
}, | ||
"dependencies": { | ||
"jsonld-streaming-parser": "^2.0.0", | ||
"jsonld-streaming-parser": "^2.0.2", | ||
"stream-to-string": "^1.2.0" | ||
@@ -73,3 +73,3 @@ }, | ||
}, | ||
"gitHead": "9f4f4c013308b068d3b32ccd43ac10783580cb91" | ||
"gitHead": "cd8df73fe091e3d7413147ec5301b47be2de392a" | ||
} |
11159