refactor: Streamline RepresentationMetadata interface

This commit is contained in:
Joachim Van Herwegen
2020-09-08 09:43:30 +02:00
parent 76319ba360
commit 8d3979372b
36 changed files with 416 additions and 230 deletions

View File

@@ -1,7 +1,6 @@
import { RepresentationPreference } from '../../ldp/representation/RepresentationPreference';
import { RepresentationPreferences } from '../../ldp/representation/RepresentationPreferences';
import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError';
import { CONTENT_TYPE } from '../../util/MetadataTypes';
import { matchingMediaType } from '../../util/Util';
import { RepresentationConverterArgs } from './RepresentationConverter';
@@ -35,11 +34,11 @@ RepresentationPreference[] => {
*/
export const checkRequest = (request: RepresentationConverterArgs, supportedIn: string[], supportedOut: string[]):
void => {
const inType = request.representation.metadata.get(CONTENT_TYPE);
const inType = request.representation.metadata.contentType;
if (!inType) {
throw new UnsupportedHttpError('Input type required for conversion.');
}
if (!supportedIn.some((type): boolean => matchingMediaType(inType.value, type))) {
if (!supportedIn.some((type): boolean => matchingMediaType(inType, type))) {
throw new UnsupportedHttpError(`Can only convert from ${supportedIn} to ${supportedOut}.`);
}
if (matchingTypes(request.preferences, supportedOut).length <= 0) {