mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: store turtle prefixes in metadata when parsing
build: correct package-lock file
This commit is contained in:
committed by
Joachim Van Herwegen
parent
9a12152253
commit
66e82dd772
@@ -3,6 +3,7 @@ import { Readable } from 'stream';
|
||||
import arrayifyStream from 'arrayify-stream';
|
||||
import { DataFactory } from 'n3';
|
||||
import rdfParser from 'rdf-parse';
|
||||
import { PREFERRED_PREFIX_TERM, SOLID_META } from '../../../../src';
|
||||
import { BasicRepresentation } from '../../../../src/http/representation/BasicRepresentation';
|
||||
import type { Representation } from '../../../../src/http/representation/Representation';
|
||||
import { RepresentationMetadata } from '../../../../src/http/representation/RepresentationMetadata';
|
||||
@@ -11,7 +12,7 @@ import type { ResourceIdentifier } from '../../../../src/http/representation/Res
|
||||
import { RdfToQuadConverter } from '../../../../src/storage/conversion/RdfToQuadConverter';
|
||||
import { INTERNAL_QUADS } from '../../../../src/util/ContentTypes';
|
||||
import { BadRequestHttpError } from '../../../../src/util/errors/BadRequestHttpError';
|
||||
const { namedNode, triple } = DataFactory;
|
||||
const { namedNode, triple, literal, quad } = DataFactory;
|
||||
|
||||
describe('A RdfToQuadConverter', (): void => {
|
||||
const converter = new RdfToQuadConverter();
|
||||
@@ -63,6 +64,30 @@ describe('A RdfToQuadConverter', (): void => {
|
||||
) ]);
|
||||
});
|
||||
|
||||
it('emits on prefixes when converting turtle to quads.', async(): Promise<void> => {
|
||||
const id: ResourceIdentifier = { path: 'http://example.com/' };
|
||||
const metadata = new RepresentationMetadata('text/turtle');
|
||||
const representation = new BasicRepresentation(`
|
||||
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
|
||||
|
||||
<http://test.com/s> a foaf:Person.
|
||||
`
|
||||
, metadata);
|
||||
const preferences: RepresentationPreferences = { type: { [INTERNAL_QUADS]: 1 }};
|
||||
const result = await converter.handle({ identifier: id, representation, preferences });
|
||||
expect(result).toEqual({
|
||||
binary: false,
|
||||
data: expect.any(Readable),
|
||||
metadata: expect.any(RepresentationMetadata),
|
||||
});
|
||||
expect(result.metadata.contentType).toEqual(INTERNAL_QUADS);
|
||||
await arrayifyStream(result.data);
|
||||
|
||||
expect(result.metadata.quads(null, PREFERRED_PREFIX_TERM, null)).toBeRdfIsomorphic([
|
||||
quad(namedNode('http://xmlns.com/foaf/0.1/'), PREFERRED_PREFIX_TERM, literal('foaf'), SOLID_META.terms.ResponseMetadata),
|
||||
]);
|
||||
});
|
||||
|
||||
it('converts JSON-LD to quads.', async(): Promise<void> => {
|
||||
const metadata = new RepresentationMetadata('application/ld+json');
|
||||
const representation = new BasicRepresentation(
|
||||
|
||||
Reference in New Issue
Block a user