mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: Integrate ChainedConverter into the server
This commit is contained in:
parent
af4a82f4c1
commit
3931d5f664
@ -24,6 +24,29 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"@id": "urn:solid-server:default:ResourceStore_Converting_RdfToQuad",
|
||||||
|
"@type": "RdfToQuadConverter"
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"@id": "urn:solid-server:default:ResourceStore_Converting_QuadToRdf",
|
||||||
|
"@type": "QuadToRdfConverter"
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"@id": "urn:solid-server:default:ResourceStore_Converting_Chained",
|
||||||
|
"@type": "ChainedConverter",
|
||||||
|
"ChainedConverter:_converters": [
|
||||||
|
{
|
||||||
|
"@id": "urn:solid-server:default:ResourceStore_Converting_RdfToQuad"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"@id": "urn:solid-server:default:ResourceStore_Converting_QuadToRdf"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"@id": "urn:solid-server:default:ResourceStore_Converting",
|
"@id": "urn:solid-server:default:ResourceStore_Converting",
|
||||||
"@type": "RepresentationConvertingStore",
|
"@type": "RepresentationConvertingStore",
|
||||||
@ -34,10 +57,13 @@
|
|||||||
"@type": "CompositeAsyncHandler",
|
"@type": "CompositeAsyncHandler",
|
||||||
"CompositeAsyncHandler:_handlers": [
|
"CompositeAsyncHandler:_handlers": [
|
||||||
{
|
{
|
||||||
"@type": "RdfToQuadConverter"
|
"@id": "urn:solid-server:default:ResourceStore_Converting_RdfToQuad"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"@type": "QuadToRdfConverter"
|
"@id": "urn:solid-server:default:ResourceStore_Converting_QuadToRdf"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"@id": "urn:solid-server:default:ResourceStore_Converting_Chained"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
4
index.ts
4
index.ts
@ -65,11 +65,13 @@ export * from './src/server/HttpRequest';
|
|||||||
export * from './src/server/HttpResponse';
|
export * from './src/server/HttpResponse';
|
||||||
|
|
||||||
// Storage/Conversion
|
// Storage/Conversion
|
||||||
|
export * from './src/storage/conversion/ChainedConverter';
|
||||||
export * from './src/storage/conversion/QuadToRdfConverter';
|
export * from './src/storage/conversion/QuadToRdfConverter';
|
||||||
export * from './src/storage/conversion/RdfToQuadConverter';
|
|
||||||
export * from './src/storage/conversion/QuadToTurtleConverter';
|
export * from './src/storage/conversion/QuadToTurtleConverter';
|
||||||
|
export * from './src/storage/conversion/RdfToQuadConverter';
|
||||||
export * from './src/storage/conversion/RepresentationConverter';
|
export * from './src/storage/conversion/RepresentationConverter';
|
||||||
export * from './src/storage/conversion/TurtleToQuadConverter';
|
export * from './src/storage/conversion/TurtleToQuadConverter';
|
||||||
|
export * from './src/storage/conversion/TypedRepresentationConverter';
|
||||||
|
|
||||||
// Storage/Patch
|
// Storage/Patch
|
||||||
export * from './src/storage/patch/PatchHandler';
|
export * from './src/storage/patch/PatchHandler';
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
},
|
},
|
||||||
"husky": {
|
"husky": {
|
||||||
"hooks": {
|
"hooks": {
|
||||||
"pre-commit": "npm run build && npm run lint && npm run validate && npm run test"
|
"pre-commit": "npm run build && npm run lint && npm run test"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
|
51
test/integration/RepresentationConverter.test.ts
Normal file
51
test/integration/RepresentationConverter.test.ts
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
import streamifyArray from 'streamify-array';
|
||||||
|
import { Representation } from '../../src/ldp/representation/Representation';
|
||||||
|
import { ChainedConverter } from '../../src/storage/conversion/ChainedConverter';
|
||||||
|
import { QuadToRdfConverter } from '../../src/storage/conversion/QuadToRdfConverter';
|
||||||
|
import { RdfToQuadConverter } from '../../src/storage/conversion/RdfToQuadConverter';
|
||||||
|
import { DATA_TYPE_BINARY } from '../../src/util/ContentTypes';
|
||||||
|
import { readableToString } from '../../src/util/Util';
|
||||||
|
|
||||||
|
describe('A ChainedConverter', (): void => {
|
||||||
|
const converters = [
|
||||||
|
new RdfToQuadConverter(),
|
||||||
|
new QuadToRdfConverter(),
|
||||||
|
];
|
||||||
|
const converter = new ChainedConverter(converters);
|
||||||
|
|
||||||
|
it('can convert from JSON-LD to turtle.', async(): Promise<void> => {
|
||||||
|
const representation: Representation = {
|
||||||
|
dataType: DATA_TYPE_BINARY,
|
||||||
|
data: streamifyArray([ '{"@id": "http://test.com/s", "http://test.com/p": { "@id": "http://test.com/o" }}' ]),
|
||||||
|
metadata: { raw: [], contentType: 'application/ld+json' },
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = await converter.handleSafe({
|
||||||
|
representation,
|
||||||
|
preferences: { type: [{ value: 'text/turtle', weight: 1 }]},
|
||||||
|
identifier: { path: 'path' },
|
||||||
|
});
|
||||||
|
|
||||||
|
await expect(readableToString(result.data)).resolves.toEqual('<http://test.com/s> <http://test.com/p> <http://test.com/o>.\n');
|
||||||
|
expect(result.metadata.contentType).toEqual('text/turtle');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('can convert from turtle to JSON-LD.', async(): Promise<void> => {
|
||||||
|
const representation: Representation = {
|
||||||
|
dataType: DATA_TYPE_BINARY,
|
||||||
|
data: streamifyArray([ '<http://test.com/s> <http://test.com/p> <http://test.com/o>.' ]),
|
||||||
|
metadata: { raw: [], contentType: 'text/turtle' },
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = await converter.handleSafe({
|
||||||
|
representation,
|
||||||
|
preferences: { type: [{ value: 'application/ld+json', weight: 1 }]},
|
||||||
|
identifier: { path: 'path' },
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(JSON.parse(await readableToString(result.data))).toEqual(
|
||||||
|
[{ '@id': 'http://test.com/s', 'http://test.com/p': [{ '@id': 'http://test.com/o' }]}],
|
||||||
|
);
|
||||||
|
expect(result.metadata.contentType).toEqual('application/ld+json');
|
||||||
|
});
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user