fix: clean up structure using more AsyncHandlers and more folders

This commit is contained in:
Joachim Van Herwegen 2020-05-28 10:53:35 +02:00
parent 14cfe75865
commit cc8f965495
16 changed files with 33 additions and 37 deletions

View File

@ -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<Credentials>;
}
export type CredentialsExtractor = AsyncHandler<HttpRequest, Credentials>;

View File

@ -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.
*/
export interface Authorizer {
/**
* 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.
*/
ensurePermissions: (
credentials: Credentials,
identifier: ResourceIdentifier,
permissions: PermissionSet,
) => Promise<void>;
export type Authorizer = AsyncHandler<AuthorizerArgs>;
export interface AuthorizerArgs {
/**
* Credentials of the entity that wants to use the resource.
*/
credentials: Credentials;
/**
* Identifier of the resource that will be read/modified.
*/
identifier: ResourceIdentifier;
/**
* Permissions that are requested on the resource.
*/
permissions: PermissionSet;
}

View File

@ -1,4 +1,4 @@
import { Representation } from './Representation';
import { Representation } from '../representation/Representation';
/**
* Represents the changes needed for a PATCH request.

View File

@ -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.

View File

@ -1,4 +1,4 @@
import { RepresentationMetadata } from '../ldp/http/RepresentationMetadata';
import { RepresentationMetadata } from '../ldp/representation/RepresentationMetadata';
/**
* The conditions of an HTTP conditional request.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.