Skip to content

Commit

Permalink
fix: Add priorities to RDF types when converting
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimvh committed Mar 14, 2024
1 parent df9062c commit 33e9ae4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
9 changes: 6 additions & 3 deletions src/storage/conversion/RdfToQuadConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import rdfParser from 'rdf-parse';
import { BasicRepresentation } from '../../http/representation/BasicRepresentation';
import type { Representation } from '../../http/representation/Representation';
import { RepresentationMetadata } from '../../http/representation/RepresentationMetadata';
import { INTERNAL_QUADS } from '../../util/ContentTypes';
import { APPLICATION_JSON, INTERNAL_QUADS } from '../../util/ContentTypes';
import { BadRequestHttpError } from '../../util/errors/BadRequestHttpError';
import { pipeSafely } from '../../util/StreamUtil';
import { PREFERRED_PREFIX_TERM, SOLID_META } from '../../util/Vocabularies';
Expand All @@ -25,9 +25,12 @@ export class RdfToQuadConverter extends BaseTypedRepresentationConverter {
private readonly documentLoader: ContextDocumentLoader;

public constructor(contexts: Record<string, string> = {}) {
const inputTypes = rdfParser.getContentTypes()
const inputTypes = rdfParser.getContentTypesPrioritized()
// ContentType application/json MAY NOT be converted to Quad.
.then((types): string[] => types.filter((type): boolean => type !== 'application/json'));
.then((types): Record<string, number> => {
delete types[APPLICATION_JSON];
return types;
});
super(inputTypes, INTERNAL_QUADS);
this.documentLoader = new ContextDocumentLoader(contexts);
}
Expand Down
9 changes: 5 additions & 4 deletions test/unit/storage/conversion/RdfToQuadConverter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ describe('A RdfToQuadConverter', (): void => {
const converter = new RdfToQuadConverter();
const identifier: ResourceIdentifier = { path: 'http://example.com/resource' };
it('supports serializing as quads.', async(): Promise<void> => {
const types = rdfParser.getContentTypes()
.then((inputTypes): string[] => inputTypes.filter((type): boolean => type !== 'application/json'));
for (const type of await types) {
await expect(converter.getOutputTypes(type)).resolves.toEqual({ [INTERNAL_QUADS]: 1 });
const types = await rdfParser.getContentTypesPrioritized();
// JSON is not supported
delete types['application/json'];
for (const [ type, priority ] of Object.entries(types)) {
await expect(converter.getOutputTypes(type)).resolves.toEqual({ [INTERNAL_QUADS]: priority });
}
});

Expand Down

0 comments on commit 33e9ae4

Please sign in to comment.