mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
fix: Have SimpleResourceStore return text/turtle by default
This commit is contained in:
parent
b93a77c11b
commit
4001050588
@ -122,17 +122,22 @@ export class SimpleResourceStore implements ResourceStore {
|
|||||||
* Converts an array of Quads to a Representation.
|
* Converts an array of Quads to a Representation.
|
||||||
* If preferences.type contains 'text/turtle' the result will be a stream of turtle strings,
|
* If preferences.type contains 'text/turtle' the result will be a stream of turtle strings,
|
||||||
* otherwise a stream of Quads.
|
* otherwise a stream of Quads.
|
||||||
|
*
|
||||||
|
* Note that in general this should be done by resource store specifically made for converting to turtle,
|
||||||
|
* this is just here to make this simple resource store work.
|
||||||
|
*
|
||||||
* @param data - Quads to transform.
|
* @param data - Quads to transform.
|
||||||
* @param preferences - Requested preferences.
|
* @param preferences - Requested preferences.
|
||||||
*
|
*
|
||||||
* @returns The resulting Representation.
|
* @returns The resulting Representation.
|
||||||
*/
|
*/
|
||||||
private generateRepresentation(data: Quad[], preferences: RepresentationPreferences): Representation {
|
private generateRepresentation(data: Quad[], preferences: RepresentationPreferences): Representation {
|
||||||
if (preferences.type && preferences.type.some((preference): boolean => preference.value.includes('text/turtle'))) {
|
// Always return turtle unless explicitly asked for quads
|
||||||
return this.generateBinaryRepresentation(data);
|
if (preferences.type?.some((preference): boolean => preference.value.includes('internal/quads'))) {
|
||||||
}
|
|
||||||
return this.generateQuadRepresentation(data);
|
return this.generateQuadRepresentation(data);
|
||||||
}
|
}
|
||||||
|
return this.generateBinaryRepresentation(data);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a {@link BinaryRepresentation} of the incoming Quads.
|
* Creates a {@link BinaryRepresentation} of the incoming Quads.
|
||||||
|
@ -47,7 +47,7 @@ describe('A SimpleResourceStore', (): void => {
|
|||||||
it('can write and read data.', async(): Promise<void> => {
|
it('can write and read data.', async(): Promise<void> => {
|
||||||
const identifier = await store.addResource({ path: base }, representation);
|
const identifier = await store.addResource({ path: base }, representation);
|
||||||
expect(identifier.path.startsWith(base)).toBeTruthy();
|
expect(identifier.path.startsWith(base)).toBeTruthy();
|
||||||
const result = await store.getRepresentation(identifier, {});
|
const result = await store.getRepresentation(identifier, { type: [{ value: 'internal/quads', weight: 1 }]});
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
dataType: 'quad',
|
dataType: 'quad',
|
||||||
data: expect.any(Readable),
|
data: expect.any(Readable),
|
||||||
@ -84,9 +84,27 @@ describe('A SimpleResourceStore', (): void => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('returns turtle data if no preference was set.', async(): Promise<void> => {
|
||||||
|
const identifier = await store.addResource({ path: base }, representation);
|
||||||
|
expect(identifier.path.startsWith(base)).toBeTruthy();
|
||||||
|
const result = await store.getRepresentation(identifier, { });
|
||||||
|
expect(result).toEqual({
|
||||||
|
dataType: 'binary',
|
||||||
|
data: expect.any(Readable),
|
||||||
|
metadata: {
|
||||||
|
profiles: [],
|
||||||
|
raw: [],
|
||||||
|
contentType: 'text/turtle',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
await expect(arrayifyStream(result.data)).resolves.toContain(
|
||||||
|
`<${quad.subject.value}> <${quad.predicate.value}> <${quad.object.value}>`,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it('can set data.', async(): Promise<void> => {
|
it('can set data.', async(): Promise<void> => {
|
||||||
await store.setRepresentation({ path: base }, representation);
|
await store.setRepresentation({ path: base }, representation);
|
||||||
const result = await store.getRepresentation({ path: base }, {});
|
const result = await store.getRepresentation({ path: base }, { type: [{ value: 'internal/quads', weight: 1 }]});
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
dataType: 'quad',
|
dataType: 'quad',
|
||||||
data: expect.any(Readable),
|
data: expect.any(Readable),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user