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

9769
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -75,8 +75,9 @@
"templates"
],
"dependencies": {
"@comunica/actor-init-sparql": "^1.22.3",
"@solid/access-token-verifier": "^1.1.3",
"@comunica/query-sparql": "^2.2.1",
"@rdfjs/types": "^1.1.0",
"@solid/access-token-verifier": "^1.2.2",
"@types/async-lock": "^1.1.3",
"@types/bcrypt": "^5.0.0",
"@types/cors": "^2.8.12",
@ -118,9 +119,9 @@
"oidc-provider": "^7.10.6",
"pump": "^3.0.0",
"punycode": "^2.1.1",
"rdf-dereference": "^1.9.0",
"rdf-parse": "^1.9.1",
"rdf-serialize": "^1.2.0",
"rdf-dereference": "^2.0.0",
"rdf-parse": "^2.0.0",
"rdf-serialize": "^2.0.0",
"rdf-terms": "^1.7.1",
"sparqlalgebrajs": "^4.0.2",
"sparqljs": "^3.5.1",

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 {

View File

@ -33,8 +33,7 @@ describe('A TokenOwnershipValidator', (): void => {
function mockDereference(qq?: Quad): any {
rdfDereferenceMock.dereference.mockImplementation((uri: string): any => ({
uri,
quads: Readable.from(qq ? [ qq ] : []),
exists: true,
data: Readable.from(qq ? [ qq ] : []),
}));
}

View File

@ -34,8 +34,7 @@ describe('FetchUtil', (): void => {
}
return {
uri,
quads: Readable.from(quads),
exists: true,
data: Readable.from(quads),
};
});
}