fix(deps): Update to Comunica v2

This commit is contained in:
Joachim Van Herwegen
2022-04-20 13:49:20 +02:00
parent b84788e05f
commit 1de1f7c12a
7 changed files with 3501 additions and 5747 deletions

View File

@@ -1,9 +1,8 @@
import type { Readable } from 'stream';
import { newEngine } from '@comunica/actor-init-sparql';
import type { ActorInitSparql } from '@comunica/actor-init-sparql';
import type { IQueryResultBindings } from '@comunica/actor-init-sparql/lib/ActorInitSparql-browser';
import { QueryEngine } from '@comunica/query-sparql';
import arrayifyStream from 'arrayify-stream';
import { Store } from 'n3';
import type { Quad, Term } from 'rdf-js';
import type { Bindings, Quad, Term } from 'rdf-js';
import { mapTerms } from 'rdf-terms';
import { Generator, Wildcard } from 'sparqljs';
import type { SparqlGenerator } from 'sparqljs';
@@ -30,12 +29,12 @@ import { RepresentationPatcher } from './RepresentationPatcher';
export class N3Patcher extends RepresentationPatcher {
protected readonly logger = getLoggerFor(this);
private readonly engine: ActorInitSparql;
private readonly engine: QueryEngine;
private readonly generator: SparqlGenerator;
public constructor() {
super();
this.engine = newEngine();
this.engine = new QueryEngine();
this.generator = new Generator();
}
@@ -125,9 +124,8 @@ export class N3Patcher extends RepresentationPatcher {
}],
});
this.logger.debug(`Finding bindings using SPARQL query ${sparql}`);
const query = await this.engine.query(sparql,
{ sources: [ source ], baseIRI: identifier.path }) as IQueryResultBindings;
const bindings = await query.bindings();
const bindingsStream = await this.engine.queryBindings(sparql, { sources: [ source ], baseIRI: identifier.path });
const bindings: Bindings[] = await arrayifyStream(bindingsStream);
// Solid, §5.3.1: "If no such mapping exists, or if multiple mappings exist,
// the server MUST respond with a 409 status code."
@@ -143,11 +141,10 @@ export class N3Patcher extends RepresentationPatcher {
}
// Apply bindings to deletes/inserts
// Note that Comunica binding keys start with a `?` while Variable terms omit that in their value
deletes = deletes.map((quad): Quad => mapTerms<Quad>(quad, (term): Term =>
term.termType === 'Variable' ? bindings[0].get(`?${term.value}`) : term));
term.termType === 'Variable' ? bindings[0].get(term)! : term));
inserts = inserts.map((quad): Quad => mapTerms<Quad>(quad, (term): Term =>
term.termType === 'Variable' ? bindings[0].get(`?${term.value}`) : term));
term.termType === 'Variable' ? bindings[0].get(term)! : term));
}
return {

View File

@@ -1,7 +1,5 @@
import type { Readable } from 'stream';
import type { ActorInitSparql } from '@comunica/actor-init-sparql';
import { newEngine } from '@comunica/actor-init-sparql';
import type { IQueryResultUpdate } from '@comunica/actor-init-sparql/lib/ActorInitSparql-browser';
import { QueryEngine } from '@comunica/query-sparql';
import { DataFactory, Store } from 'n3';
import { Algebra } from 'sparqlalgebrajs';
import { BasicRepresentation } from '../../http/representation/BasicRepresentation';
@@ -25,11 +23,11 @@ import type { RepresentationPatcherInput } from './RepresentationPatcher';
export class SparqlUpdatePatcher extends RepresentationPatcher {
protected readonly logger = getLoggerFor(this);
private readonly engine: ActorInitSparql;
private readonly engine: QueryEngine;
public constructor() {
super();
this.engine = newEngine();
this.engine = new QueryEngine();
}
public async canHandle({ patch }: RepresentationPatcherInput): Promise<void> {
@@ -123,9 +121,7 @@ export class SparqlUpdatePatcher extends RepresentationPatcher {
// Run the query through Comunica
const sparql = await readableToString(patch.data);
const query = await this.engine.query(sparql,
{ sources: [ result ], baseIRI: identifier.path }) as IQueryResultUpdate;
await query.updateResult;
await this.engine.queryVoid(sparql, { sources: [ result ], baseIRI: identifier.path });
this.logger.debug(`${result.size} quads will be stored to ${identifier.path}.`);

View File

@@ -1,4 +1,3 @@
import type { Readable } from 'stream';
import type { Quad } from '@rdfjs/types';
import arrayifyStream from 'arrayify-stream';
import type { Response } from 'cross-fetch';
@@ -21,7 +20,7 @@ export async function fetchDataset(url: string): Promise<Representation> {
// Try content negotiation to parse quads from the URL
return (async(): Promise<Representation> => {
try {
const quadStream = (await rdfDereferencer.dereference(url)).quads as Readable;
const quadStream = (await rdfDereferencer.dereference(url)).data;
const quadArray = await arrayifyStream<Quad>(quadStream);
return new BasicRepresentation(quadArray, { path: url }, INTERNAL_QUADS, false);
} catch {