diff --git a/src/storage/conversion/QuadToRdfConverter.ts b/src/storage/conversion/QuadToRdfConverter.ts index 63d73890b..c3efe5e7b 100644 --- a/src/storage/conversion/QuadToRdfConverter.ts +++ b/src/storage/conversion/QuadToRdfConverter.ts @@ -6,7 +6,7 @@ import type { RepresentationPreferences } from '../../ldp/representation/Represe import { INTERNAL_QUADS } from '../../util/ContentTypes'; import { guardStream } from '../../util/GuardedStream'; import { CONTENT_TYPE } from '../../util/UriConstants'; -import { supportsConversion, matchingMediaTypes } from './ConversionUtil'; +import { matchingMediaTypes } from './ConversionUtil'; import type { RepresentationConverterArgs } from './RepresentationConverter'; import { TypedRepresentationConverter } from './TypedRepresentationConverter'; @@ -22,10 +22,6 @@ export class QuadToRdfConverter extends TypedRepresentationConverter { return rdfSerializer.getContentTypesPrioritized(); } - public async canHandle(input: RepresentationConverterArgs): Promise { - supportsConversion(input, [ INTERNAL_QUADS ], await rdfSerializer.getContentTypes()); - } - public async handle(input: RepresentationConverterArgs): Promise { return this.quadsToRdf(input.representation, input.preferences); } diff --git a/src/storage/conversion/RdfToQuadConverter.ts b/src/storage/conversion/RdfToQuadConverter.ts index 299e1c1d1..21aeaff21 100644 --- a/src/storage/conversion/RdfToQuadConverter.ts +++ b/src/storage/conversion/RdfToQuadConverter.ts @@ -6,7 +6,6 @@ import { INTERNAL_QUADS } from '../../util/ContentTypes'; import { BadRequestHttpError } from '../../util/errors/BadRequestHttpError'; import { pipeSafely } from '../../util/StreamUtil'; import { CONTENT_TYPE } from '../../util/UriConstants'; -import { supportsConversion } from './ConversionUtil'; import type { RepresentationConverterArgs } from './RepresentationConverter'; import { TypedRepresentationConverter } from './TypedRepresentationConverter'; @@ -22,10 +21,6 @@ export class RdfToQuadConverter extends TypedRepresentationConverter { return { [INTERNAL_QUADS]: 1 }; } - public async canHandle(input: RepresentationConverterArgs): Promise { - supportsConversion(input, await rdfParser.getContentTypes(), [ INTERNAL_QUADS ]); - } - public async handle(input: RepresentationConverterArgs): Promise { return this.rdfToQuads(input.representation, input.identifier.path); } diff --git a/src/storage/conversion/TypedRepresentationConverter.ts b/src/storage/conversion/TypedRepresentationConverter.ts index 8919a4fa6..850667cdc 100644 --- a/src/storage/conversion/TypedRepresentationConverter.ts +++ b/src/storage/conversion/TypedRepresentationConverter.ts @@ -1,4 +1,6 @@ +import { supportsConversion } from './ConversionUtil'; import { RepresentationConverter } from './RepresentationConverter'; +import type { RepresentationConverterArgs } from './RepresentationConverter'; /** * A {@link RepresentationConverter} that allows requesting the supported types. @@ -17,4 +19,13 @@ export abstract class TypedRepresentationConverter extends RepresentationConvert * @returns A promise resolving to a hash mapping content type to a priority number. */ public abstract getOutputTypes(): Promise>; + + /** + * Verifies whether this converter supports the input. + */ + public async canHandle(args: RepresentationConverterArgs): Promise { + const types = [ this.getInputTypes(), this.getOutputTypes() ]; + const [ inputTypes, outputTypes ] = await Promise.all(types); + supportsConversion(args, Object.keys(inputTypes), Object.keys(outputTypes)); + } }