mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
fix: Prefer Turtle as default content type.
Fixes https://github.com/solid/community-server/issues/463
This commit is contained in:
parent
ba5c62059a
commit
e70e060225
@ -8,7 +8,33 @@
|
||||
|
||||
{
|
||||
"@id": "urn:solid-server:default:QuadToRdfConverter",
|
||||
"@type": "QuadToRdfConverter"
|
||||
"@type": "QuadToRdfConverter",
|
||||
"QuadToRdfConverter:_options_outputPreferences": [
|
||||
{
|
||||
"QuadToRdfConverter:_options_outputPreferences_key": "text/turtle",
|
||||
"QuadToRdfConverter:_options_outputPreferences_value": 1
|
||||
},
|
||||
{
|
||||
"QuadToRdfConverter:_options_outputPreferences_key": "application/n-triples",
|
||||
"QuadToRdfConverter:_options_outputPreferences_value": 0.95
|
||||
},
|
||||
{
|
||||
"QuadToRdfConverter:_options_outputPreferences_key": "application/trig",
|
||||
"QuadToRdfConverter:_options_outputPreferences_value": 0.95
|
||||
},
|
||||
{
|
||||
"QuadToRdfConverter:_options_outputPreferences_key": "application/n-quads",
|
||||
"QuadToRdfConverter:_options_outputPreferences_value": 0.95
|
||||
},
|
||||
{
|
||||
"QuadToRdfConverter:_options_outputPreferences_key": "text/n3",
|
||||
"QuadToRdfConverter:_options_outputPreferences_value": 0.95
|
||||
},
|
||||
{
|
||||
"QuadToRdfConverter:_options_outputPreferences_key": "application/ld+json",
|
||||
"QuadToRdfConverter:_options_outputPreferences_value": 0.8
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
|
@ -17,12 +17,21 @@ import { TypedRepresentationConverter } from './TypedRepresentationConverter';
|
||||
* Converts `internal/quads` to most major RDF serializations.
|
||||
*/
|
||||
export class QuadToRdfConverter extends TypedRepresentationConverter {
|
||||
private readonly outputPreferences?: ValuePreferences;
|
||||
|
||||
public constructor(options: { outputPreferences?: Record<string, number> } = {}) {
|
||||
super();
|
||||
if (Object.keys(options.outputPreferences ?? {}).length > 0) {
|
||||
this.outputPreferences = { ...options.outputPreferences };
|
||||
}
|
||||
}
|
||||
|
||||
public async getInputTypes(): Promise<ValuePreferences> {
|
||||
return { [INTERNAL_QUADS]: 1 };
|
||||
}
|
||||
|
||||
public async getOutputTypes(): Promise<ValuePreferences> {
|
||||
return rdfSerializer.getContentTypesPrioritized();
|
||||
return this.outputPreferences ?? rdfSerializer.getContentTypesPrioritized();
|
||||
}
|
||||
|
||||
public async handle(input: RepresentationConverterArgs): Promise<Representation> {
|
||||
|
@ -16,11 +16,25 @@ describe('A QuadToRdfConverter', (): void => {
|
||||
const metadata = new RepresentationMetadata({ [CONTENT_TYPE]: INTERNAL_QUADS });
|
||||
|
||||
it('supports parsing quads.', async(): Promise<void> => {
|
||||
await expect(converter.getInputTypes()).resolves.toEqual({ [INTERNAL_QUADS]: 1 });
|
||||
await expect(new QuadToRdfConverter().getInputTypes())
|
||||
.resolves.toEqual({ [INTERNAL_QUADS]: 1 });
|
||||
});
|
||||
|
||||
it('supports serializing as the same types as rdfSerializer.', async(): Promise<void> => {
|
||||
await expect(converter.getOutputTypes()).resolves.toEqual(await rdfSerializer.getContentTypesPrioritized());
|
||||
it('defaults to rdfSerializer preferences when given no preferences.', async(): Promise<void> => {
|
||||
await expect(new QuadToRdfConverter().getOutputTypes())
|
||||
.resolves.toEqual(await rdfSerializer.getContentTypesPrioritized());
|
||||
});
|
||||
|
||||
it('defaults to rdfSerializer preferences when given empty preferences.', async(): Promise<void> => {
|
||||
const outputPreferences = {};
|
||||
await expect(new QuadToRdfConverter({ outputPreferences }).getOutputTypes())
|
||||
.resolves.toEqual(await rdfSerializer.getContentTypesPrioritized());
|
||||
});
|
||||
|
||||
it('returns custom preferences when given non-empty preferences.', async(): Promise<void> => {
|
||||
const outputPreferences = { 'text/turtle': 1 };
|
||||
await expect(new QuadToRdfConverter({ outputPreferences }).getOutputTypes())
|
||||
.resolves.toEqual(outputPreferences);
|
||||
});
|
||||
|
||||
it('can handle quad to turtle conversions.', async(): Promise<void> => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user