From cc8f965495456f6ab369923a34004a18dcddf0d4 Mon Sep 17 00:00:00 2001 From: Joachim Van Herwegen Date: Thu, 28 May 2020 10:53:35 +0200 Subject: [PATCH] fix: clean up structure using more AsyncHandlers and more folders --- src/authentication/CredentialsExtractor.ts | 14 +++----- src/authorization/Authorizer.ts | 32 ++++++++++--------- src/ldp/http/Patch.ts | 2 +- src/ldp/operations/Operation.ts | 6 ++-- .../BinaryRepresentation.ts | 0 .../NamedRepresentation.ts | 0 .../QuadRepresentation.ts | 0 .../Representation.ts | 0 .../RepresentationMetadata.ts | 0 .../RepresentationPreferences.ts | 0 .../ResourceIdentifier.ts | 0 src/storage/Conditions.ts | 2 +- src/storage/RepresentationConverter.ts | 4 +-- src/storage/ResourceLocker.ts | 2 +- src/storage/ResourceMapper.ts | 2 +- src/storage/ResourceStore.ts | 6 ++-- 16 files changed, 33 insertions(+), 37 deletions(-) rename src/ldp/{http => representation}/BinaryRepresentation.ts (100%) rename src/ldp/{http => representation}/NamedRepresentation.ts (100%) rename src/ldp/{http => representation}/QuadRepresentation.ts (100%) rename src/ldp/{http => representation}/Representation.ts (100%) rename src/ldp/{http => representation}/RepresentationMetadata.ts (100%) rename src/ldp/{http => representation}/RepresentationPreferences.ts (100%) rename src/ldp/{http => representation}/ResourceIdentifier.ts (100%) diff --git a/src/authentication/CredentialsExtractor.ts b/src/authentication/CredentialsExtractor.ts index c966f2ce0..aca9a40f8 100644 --- a/src/authentication/CredentialsExtractor.ts +++ b/src/authentication/CredentialsExtractor.ts @@ -1,15 +1,9 @@ +import { AsyncHandler } from '../util/AsyncHandler'; import { Credentials } from './Credentials'; import { HttpRequest } from '../server/HttpRequest'; /** - * Responsible for extracting credentials. + * Responsible for extracting credentials from an incoming request. + * Will return `null` if no credentials were found. */ -export interface CredentialsExtractor { - /** - * Extracts the credentials found in an HttpRequest. - * - * @param request - The incoming request. - * @returns A promise resolving to the credentials. - */ - extractCredentials: (request: HttpRequest) => Promise; -} +export type CredentialsExtractor = AsyncHandler; diff --git a/src/authorization/Authorizer.ts b/src/authorization/Authorizer.ts index 1f185c916..ae2932d5d 100644 --- a/src/authorization/Authorizer.ts +++ b/src/authorization/Authorizer.ts @@ -1,23 +1,25 @@ +import { AsyncHandler } from '../util/AsyncHandler'; import { Credentials } from '../authentication/Credentials'; import { PermissionSet } from '../ldp/permissions/PermissionSet'; -import { ResourceIdentifier } from '../ldp/http/ResourceIdentifier'; +import { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; /** - * Responsible for the permission verification. + * Verifies if the given credentials have access to the given permissions on the given resource. + * An {@link Error} with the necessary explanation will be thrown when permissions are not granted. */ -export interface Authorizer { +export type Authorizer = AsyncHandler; + +export interface AuthorizerArgs { /** - * Verifies if the given credentials have access to the given permissions on the given resource. - * @param credentials - Credentials of the entity that wants to use the resource. - * @param identifier - Identifier of the resource that will be read/modified. - * @param permissions - Permissions that are requested on the resource. - * - * @returns A promise resolving when the Authorizer is finished. - * An {@link Error} with the necessary explanation will be thrown when permissions are not granted. + * Credentials of the entity that wants to use the resource. */ - ensurePermissions: ( - credentials: Credentials, - identifier: ResourceIdentifier, - permissions: PermissionSet, - ) => Promise; + credentials: Credentials; + /** + * Identifier of the resource that will be read/modified. + */ + identifier: ResourceIdentifier; + /** + * Permissions that are requested on the resource. + */ + permissions: PermissionSet; } diff --git a/src/ldp/http/Patch.ts b/src/ldp/http/Patch.ts index 62aa32c97..b5a13a73e 100644 --- a/src/ldp/http/Patch.ts +++ b/src/ldp/http/Patch.ts @@ -1,4 +1,4 @@ -import { Representation } from './Representation'; +import { Representation } from '../representation/Representation'; /** * Represents the changes needed for a PATCH request. diff --git a/src/ldp/operations/Operation.ts b/src/ldp/operations/Operation.ts index 135586c17..29f3875f8 100644 --- a/src/ldp/operations/Operation.ts +++ b/src/ldp/operations/Operation.ts @@ -1,6 +1,6 @@ -import { Representation } from '../http/Representation'; -import { RepresentationPreferences } from '../http/RepresentationPreferences'; -import { ResourceIdentifier } from '../http/ResourceIdentifier'; +import { Representation } from '../representation/Representation'; +import { RepresentationPreferences } from '../representation/RepresentationPreferences'; +import { ResourceIdentifier } from '../representation/ResourceIdentifier'; /** * A single REST operation. diff --git a/src/ldp/http/BinaryRepresentation.ts b/src/ldp/representation/BinaryRepresentation.ts similarity index 100% rename from src/ldp/http/BinaryRepresentation.ts rename to src/ldp/representation/BinaryRepresentation.ts diff --git a/src/ldp/http/NamedRepresentation.ts b/src/ldp/representation/NamedRepresentation.ts similarity index 100% rename from src/ldp/http/NamedRepresentation.ts rename to src/ldp/representation/NamedRepresentation.ts diff --git a/src/ldp/http/QuadRepresentation.ts b/src/ldp/representation/QuadRepresentation.ts similarity index 100% rename from src/ldp/http/QuadRepresentation.ts rename to src/ldp/representation/QuadRepresentation.ts diff --git a/src/ldp/http/Representation.ts b/src/ldp/representation/Representation.ts similarity index 100% rename from src/ldp/http/Representation.ts rename to src/ldp/representation/Representation.ts diff --git a/src/ldp/http/RepresentationMetadata.ts b/src/ldp/representation/RepresentationMetadata.ts similarity index 100% rename from src/ldp/http/RepresentationMetadata.ts rename to src/ldp/representation/RepresentationMetadata.ts diff --git a/src/ldp/http/RepresentationPreferences.ts b/src/ldp/representation/RepresentationPreferences.ts similarity index 100% rename from src/ldp/http/RepresentationPreferences.ts rename to src/ldp/representation/RepresentationPreferences.ts diff --git a/src/ldp/http/ResourceIdentifier.ts b/src/ldp/representation/ResourceIdentifier.ts similarity index 100% rename from src/ldp/http/ResourceIdentifier.ts rename to src/ldp/representation/ResourceIdentifier.ts diff --git a/src/storage/Conditions.ts b/src/storage/Conditions.ts index 76513e763..73d840db4 100644 --- a/src/storage/Conditions.ts +++ b/src/storage/Conditions.ts @@ -1,4 +1,4 @@ -import { RepresentationMetadata } from '../ldp/http/RepresentationMetadata'; +import { RepresentationMetadata } from '../ldp/representation/RepresentationMetadata'; /** * The conditions of an HTTP conditional request. diff --git a/src/storage/RepresentationConverter.ts b/src/storage/RepresentationConverter.ts index 67519968b..333a01d7b 100644 --- a/src/storage/RepresentationConverter.ts +++ b/src/storage/RepresentationConverter.ts @@ -1,5 +1,5 @@ -import { Representation } from '../ldp/http/Representation'; -import { RepresentationPreferences } from '../ldp/http/RepresentationPreferences'; +import { Representation } from '../ldp/representation/Representation'; +import { RepresentationPreferences } from '../ldp/representation/RepresentationPreferences'; /** * Allows converting from one resource representation to another. diff --git a/src/storage/ResourceLocker.ts b/src/storage/ResourceLocker.ts index 5265f1e12..8964fd050 100644 --- a/src/storage/ResourceLocker.ts +++ b/src/storage/ResourceLocker.ts @@ -1,5 +1,5 @@ import { Lock } from './Lock'; -import { ResourceIdentifier } from '../ldp/http/ResourceIdentifier'; +import { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; /** * Allows the locking of resources which is needed for non-atomic {@link ResourceStore}s. diff --git a/src/storage/ResourceMapper.ts b/src/storage/ResourceMapper.ts index 6467d1e26..195de965b 100644 --- a/src/storage/ResourceMapper.ts +++ b/src/storage/ResourceMapper.ts @@ -1,4 +1,4 @@ -import { RepresentationMetadata } from '../ldp/http/RepresentationMetadata'; +import { RepresentationMetadata } from '../ldp/representation/RepresentationMetadata'; /** * Supports mapping a file to an URL and back. diff --git a/src/storage/ResourceStore.ts b/src/storage/ResourceStore.ts index 853a29b98..dcdff55cc 100644 --- a/src/storage/ResourceStore.ts +++ b/src/storage/ResourceStore.ts @@ -1,8 +1,8 @@ import { Conditions } from './Conditions'; import { Patch } from '../ldp/http/Patch'; -import { Representation } from '../ldp/http/Representation'; -import { RepresentationPreferences } from '../ldp/http/RepresentationPreferences'; -import { ResourceIdentifier } from '../ldp/http/ResourceIdentifier'; +import { Representation } from '../ldp/representation/Representation'; +import { RepresentationPreferences } from '../ldp/representation/RepresentationPreferences'; +import { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; /** * A ResourceStore represents a collection of resources.