mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
refactor: Use declarations style for functions.
This commit is contained in:
@@ -18,8 +18,8 @@ import { NotImplementedHttpError } from '../../util/errors/NotImplementedHttpErr
|
||||
*
|
||||
* @returns The weighted and filtered list of matching types.
|
||||
*/
|
||||
export const matchingMediaTypes = (preferredTypes: ValuePreferences = {}, availableTypes: ValuePreferences = {}):
|
||||
string[] => {
|
||||
export function matchingMediaTypes(preferredTypes: ValuePreferences = {}, availableTypes: ValuePreferences = {}):
|
||||
string[] {
|
||||
// No preference means anything is acceptable
|
||||
const preferred = { ...preferredTypes };
|
||||
if (Object.keys(preferredTypes).length === 0) {
|
||||
@@ -53,7 +53,7 @@ string[] => {
|
||||
.filter(([ , weight ]): boolean => weight !== 0)
|
||||
.sort(([ , weightA ], [ , weightB ]): number => weightB - weightA)
|
||||
.map(([ type ]): string => type);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given two media types/ranges match each other.
|
||||
@@ -63,7 +63,7 @@ string[] => {
|
||||
*
|
||||
* @returns True if the media type patterns can match each other.
|
||||
*/
|
||||
export const matchesMediaType = (mediaA: string, mediaB: string): boolean => {
|
||||
export function matchesMediaType(mediaA: string, mediaB: string): boolean {
|
||||
if (mediaA === mediaB) {
|
||||
return true;
|
||||
}
|
||||
@@ -80,7 +80,7 @@ export const matchesMediaType = (mediaA: string, mediaB: string): boolean => {
|
||||
return true;
|
||||
}
|
||||
return subTypeA === subTypeB;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the given conversion request is supported,
|
||||
@@ -94,10 +94,10 @@ export const matchesMediaType = (mediaA: string, mediaB: string): boolean => {
|
||||
* @param convertorIn - Media types that can be parsed by the converter.
|
||||
* @param convertorOut - Media types that can be produced by the converter.
|
||||
*/
|
||||
export const supportsMediaTypeConversion = (
|
||||
export function supportsMediaTypeConversion(
|
||||
inputType = 'unknown', outputTypes: ValuePreferences = {},
|
||||
convertorIn: ValuePreferences = {}, convertorOut: ValuePreferences = {},
|
||||
): void => {
|
||||
): void {
|
||||
if (!Object.keys(convertorIn).some((type): boolean => matchesMediaType(inputType, type)) ||
|
||||
matchingMediaTypes(outputTypes, convertorOut).length === 0) {
|
||||
throw new NotImplementedHttpError(
|
||||
@@ -105,4 +105,4 @@ export const supportsMediaTypeConversion = (
|
||||
}, only from ${Object.keys(convertorIn)} to ${Object.keys(convertorOut)}.`,
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -14,8 +14,9 @@ const logger = getLoggerFor('MapperUtil');
|
||||
*
|
||||
* @returns Absolute path of the file.
|
||||
*/
|
||||
export const getAbsolutePath = (rootFilepath: string, path: string, identifier = ''): string =>
|
||||
joinFilePath(rootFilepath, path, identifier);
|
||||
export function getAbsolutePath(rootFilepath: string, path: string, identifier = ''): string {
|
||||
return joinFilePath(rootFilepath, path, identifier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Strips the baseRequestURI from the identifier and checks if the stripped base URI matches the store's one.
|
||||
@@ -27,13 +28,13 @@ export const getAbsolutePath = (rootFilepath: string, path: string, identifier =
|
||||
*
|
||||
* @returns A string representing the relative path.
|
||||
*/
|
||||
export const getRelativePath = (baseRequestURI: string, identifier: ResourceIdentifier): string => {
|
||||
export function getRelativePath(baseRequestURI: string, identifier: ResourceIdentifier): string {
|
||||
if (!identifier.path.startsWith(baseRequestURI)) {
|
||||
logger.warn(`The URL ${identifier.path} is outside of the scope ${baseRequestURI}`);
|
||||
throw new NotFoundHttpError();
|
||||
}
|
||||
return decodeUriPathComponents(identifier.path.slice(baseRequestURI.length));
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given relative path is valid.
|
||||
@@ -44,7 +45,7 @@ export const getRelativePath = (baseRequestURI: string, identifier: ResourceIden
|
||||
* @param path - A relative path, as generated by {@link getRelativePath}.
|
||||
* @param identifier - A resource identifier.
|
||||
*/
|
||||
export const validateRelativePath = (path: string, identifier: ResourceIdentifier): void => {
|
||||
export function validateRelativePath(path: string, identifier: ResourceIdentifier): void {
|
||||
if (!path.startsWith('/')) {
|
||||
logger.warn(`URL ${identifier.path} needs a / after the base`);
|
||||
throw new BadRequestHttpError('URL needs a / after the base');
|
||||
@@ -54,4 +55,4 @@ export const validateRelativePath = (path: string, identifier: ResourceIdentifie
|
||||
logger.warn(`Disallowed /.. segment in URL ${identifier.path}.`);
|
||||
throw new BadRequestHttpError('Disallowed /.. segment in URL');
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user