mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
fix(deps): Update to Comunica v2
This commit is contained in:
parent
b84788e05f
commit
1de1f7c12a
9769
package-lock.json
generated
9769
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
11
package.json
11
package.json
@ -75,8 +75,9 @@
|
|||||||
"templates"
|
"templates"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@comunica/actor-init-sparql": "^1.22.3",
|
"@comunica/query-sparql": "^2.2.1",
|
||||||
"@solid/access-token-verifier": "^1.1.3",
|
"@rdfjs/types": "^1.1.0",
|
||||||
|
"@solid/access-token-verifier": "^1.2.2",
|
||||||
"@types/async-lock": "^1.1.3",
|
"@types/async-lock": "^1.1.3",
|
||||||
"@types/bcrypt": "^5.0.0",
|
"@types/bcrypt": "^5.0.0",
|
||||||
"@types/cors": "^2.8.12",
|
"@types/cors": "^2.8.12",
|
||||||
@ -118,9 +119,9 @@
|
|||||||
"oidc-provider": "^7.10.6",
|
"oidc-provider": "^7.10.6",
|
||||||
"pump": "^3.0.0",
|
"pump": "^3.0.0",
|
||||||
"punycode": "^2.1.1",
|
"punycode": "^2.1.1",
|
||||||
"rdf-dereference": "^1.9.0",
|
"rdf-dereference": "^2.0.0",
|
||||||
"rdf-parse": "^1.9.1",
|
"rdf-parse": "^2.0.0",
|
||||||
"rdf-serialize": "^1.2.0",
|
"rdf-serialize": "^2.0.0",
|
||||||
"rdf-terms": "^1.7.1",
|
"rdf-terms": "^1.7.1",
|
||||||
"sparqlalgebrajs": "^4.0.2",
|
"sparqlalgebrajs": "^4.0.2",
|
||||||
"sparqljs": "^3.5.1",
|
"sparqljs": "^3.5.1",
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
import type { Readable } from 'stream';
|
import type { Readable } from 'stream';
|
||||||
import { newEngine } from '@comunica/actor-init-sparql';
|
import { QueryEngine } from '@comunica/query-sparql';
|
||||||
import type { ActorInitSparql } from '@comunica/actor-init-sparql';
|
import arrayifyStream from 'arrayify-stream';
|
||||||
import type { IQueryResultBindings } from '@comunica/actor-init-sparql/lib/ActorInitSparql-browser';
|
|
||||||
import { Store } from 'n3';
|
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 { mapTerms } from 'rdf-terms';
|
||||||
import { Generator, Wildcard } from 'sparqljs';
|
import { Generator, Wildcard } from 'sparqljs';
|
||||||
import type { SparqlGenerator } from 'sparqljs';
|
import type { SparqlGenerator } from 'sparqljs';
|
||||||
@ -30,12 +29,12 @@ import { RepresentationPatcher } from './RepresentationPatcher';
|
|||||||
export class N3Patcher extends RepresentationPatcher {
|
export class N3Patcher extends RepresentationPatcher {
|
||||||
protected readonly logger = getLoggerFor(this);
|
protected readonly logger = getLoggerFor(this);
|
||||||
|
|
||||||
private readonly engine: ActorInitSparql;
|
private readonly engine: QueryEngine;
|
||||||
private readonly generator: SparqlGenerator;
|
private readonly generator: SparqlGenerator;
|
||||||
|
|
||||||
public constructor() {
|
public constructor() {
|
||||||
super();
|
super();
|
||||||
this.engine = newEngine();
|
this.engine = new QueryEngine();
|
||||||
this.generator = new Generator();
|
this.generator = new Generator();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,9 +124,8 @@ export class N3Patcher extends RepresentationPatcher {
|
|||||||
}],
|
}],
|
||||||
});
|
});
|
||||||
this.logger.debug(`Finding bindings using SPARQL query ${sparql}`);
|
this.logger.debug(`Finding bindings using SPARQL query ${sparql}`);
|
||||||
const query = await this.engine.query(sparql,
|
const bindingsStream = await this.engine.queryBindings(sparql, { sources: [ source ], baseIRI: identifier.path });
|
||||||
{ sources: [ source ], baseIRI: identifier.path }) as IQueryResultBindings;
|
const bindings: Bindings[] = await arrayifyStream(bindingsStream);
|
||||||
const bindings = await query.bindings();
|
|
||||||
|
|
||||||
// Solid, §5.3.1: "If no such mapping exists, or if multiple mappings exist,
|
// Solid, §5.3.1: "If no such mapping exists, or if multiple mappings exist,
|
||||||
// the server MUST respond with a 409 status code."
|
// the server MUST respond with a 409 status code."
|
||||||
@ -143,11 +141,10 @@ export class N3Patcher extends RepresentationPatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Apply bindings to deletes/inserts
|
// 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 =>
|
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 =>
|
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 {
|
return {
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
import type { Readable } from 'stream';
|
import type { Readable } from 'stream';
|
||||||
import type { ActorInitSparql } from '@comunica/actor-init-sparql';
|
import { QueryEngine } from '@comunica/query-sparql';
|
||||||
import { newEngine } from '@comunica/actor-init-sparql';
|
|
||||||
import type { IQueryResultUpdate } from '@comunica/actor-init-sparql/lib/ActorInitSparql-browser';
|
|
||||||
import { DataFactory, Store } from 'n3';
|
import { DataFactory, Store } from 'n3';
|
||||||
import { Algebra } from 'sparqlalgebrajs';
|
import { Algebra } from 'sparqlalgebrajs';
|
||||||
import { BasicRepresentation } from '../../http/representation/BasicRepresentation';
|
import { BasicRepresentation } from '../../http/representation/BasicRepresentation';
|
||||||
@ -25,11 +23,11 @@ import type { RepresentationPatcherInput } from './RepresentationPatcher';
|
|||||||
export class SparqlUpdatePatcher extends RepresentationPatcher {
|
export class SparqlUpdatePatcher extends RepresentationPatcher {
|
||||||
protected readonly logger = getLoggerFor(this);
|
protected readonly logger = getLoggerFor(this);
|
||||||
|
|
||||||
private readonly engine: ActorInitSparql;
|
private readonly engine: QueryEngine;
|
||||||
|
|
||||||
public constructor() {
|
public constructor() {
|
||||||
super();
|
super();
|
||||||
this.engine = newEngine();
|
this.engine = new QueryEngine();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async canHandle({ patch }: RepresentationPatcherInput): Promise<void> {
|
public async canHandle({ patch }: RepresentationPatcherInput): Promise<void> {
|
||||||
@ -123,9 +121,7 @@ export class SparqlUpdatePatcher extends RepresentationPatcher {
|
|||||||
|
|
||||||
// Run the query through Comunica
|
// Run the query through Comunica
|
||||||
const sparql = await readableToString(patch.data);
|
const sparql = await readableToString(patch.data);
|
||||||
const query = await this.engine.query(sparql,
|
await this.engine.queryVoid(sparql, { sources: [ result ], baseIRI: identifier.path });
|
||||||
{ sources: [ result ], baseIRI: identifier.path }) as IQueryResultUpdate;
|
|
||||||
await query.updateResult;
|
|
||||||
|
|
||||||
this.logger.debug(`${result.size} quads will be stored to ${identifier.path}.`);
|
this.logger.debug(`${result.size} quads will be stored to ${identifier.path}.`);
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import type { Readable } from 'stream';
|
|
||||||
import type { Quad } from '@rdfjs/types';
|
import type { Quad } from '@rdfjs/types';
|
||||||
import arrayifyStream from 'arrayify-stream';
|
import arrayifyStream from 'arrayify-stream';
|
||||||
import type { Response } from 'cross-fetch';
|
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
|
// Try content negotiation to parse quads from the URL
|
||||||
return (async(): Promise<Representation> => {
|
return (async(): Promise<Representation> => {
|
||||||
try {
|
try {
|
||||||
const quadStream = (await rdfDereferencer.dereference(url)).quads as Readable;
|
const quadStream = (await rdfDereferencer.dereference(url)).data;
|
||||||
const quadArray = await arrayifyStream<Quad>(quadStream);
|
const quadArray = await arrayifyStream<Quad>(quadStream);
|
||||||
return new BasicRepresentation(quadArray, { path: url }, INTERNAL_QUADS, false);
|
return new BasicRepresentation(quadArray, { path: url }, INTERNAL_QUADS, false);
|
||||||
} catch {
|
} catch {
|
||||||
|
@ -33,8 +33,7 @@ describe('A TokenOwnershipValidator', (): void => {
|
|||||||
function mockDereference(qq?: Quad): any {
|
function mockDereference(qq?: Quad): any {
|
||||||
rdfDereferenceMock.dereference.mockImplementation((uri: string): any => ({
|
rdfDereferenceMock.dereference.mockImplementation((uri: string): any => ({
|
||||||
uri,
|
uri,
|
||||||
quads: Readable.from(qq ? [ qq ] : []),
|
data: Readable.from(qq ? [ qq ] : []),
|
||||||
exists: true,
|
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,8 +34,7 @@ describe('FetchUtil', (): void => {
|
|||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
uri,
|
uri,
|
||||||
quads: Readable.from(quads),
|
data: Readable.from(quads),
|
||||||
exists: true,
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user