feat: Update ChainedConverter to create dynamic paths

This commit is contained in:
Joachim Van Herwegen
2021-04-13 09:59:33 +02:00
parent 87a54011b4
commit 44d82eac04
4 changed files with 491 additions and 119 deletions

View File

@@ -4,7 +4,10 @@ import {
readableToString,
ChainedConverter,
guardedStreamFrom,
RdfToQuadConverter, BasicRepresentation, getLoggerFor,
RdfToQuadConverter,
BasicRepresentation,
getLoggerFor,
INTERNAL_QUADS,
} from '../../src';
import type { Representation,
RepresentationConverterArgs,
@@ -22,16 +25,16 @@ class DummyConverter extends TypedRepresentationConverter {
}
public async getInputTypes(): Promise<Record<string, number>> {
return { '*/*': 1 };
return { [INTERNAL_QUADS]: 1 };
}
public async getOutputTypes(): Promise<Record<string, number>> {
return { 'custom/type': 1 };
return { 'x/x': 1 };
}
public async handle({ representation }: RepresentationConverterArgs): Promise<Representation> {
const data = guardedStreamFrom([ 'dummy' ]);
const metadata = new RepresentationMetadata(representation.metadata, 'custom/type');
const metadata = new RepresentationMetadata(representation.metadata, 'x/x');
return { binary: true, data, metadata };
}
@@ -47,7 +50,7 @@ describe('A chained converter where data gets ignored', (): void => {
it('does not throw on async crash.', async(): Promise<void> => {
jest.useFakeTimers();
const result = await converter.handleSafe({ identifier, representation: rep, preferences: {}});
const result = await converter.handleSafe({ identifier, representation: rep, preferences: { type: { 'x/x': 1 }}});
expect(await readableToString(result.data)).toBe('dummy');