fix: add documentation for many classes where it was missing

This commit is contained in:
Joachim Van Herwegen 2020-06-24 16:27:38 +02:00
parent 39853b0bd0
commit fe11f4b1ce
18 changed files with 62 additions and 2 deletions

View File

@ -2,6 +2,9 @@ import { Credentials } from './Credentials';
import { CredentialsExtractor } from './CredentialsExtractor'; import { CredentialsExtractor } from './CredentialsExtractor';
import { HttpRequest } from '../server/HttpRequest'; import { HttpRequest } from '../server/HttpRequest';
/**
* Credentials extractor which simply interprets the contents of the Authorization header as a webID.
*/
export class SimpleCredentialsExtractor extends CredentialsExtractor { export class SimpleCredentialsExtractor extends CredentialsExtractor {
public async canHandle(): Promise<void> { public async canHandle(): Promise<void> {
return undefined; return undefined;

View File

@ -1,6 +1,9 @@
import { UnsupportedHttpError } from '../util/errors/UnsupportedHttpError'; import { UnsupportedHttpError } from '../util/errors/UnsupportedHttpError';
import { Authorizer, AuthorizerArgs } from './Authorizer'; import { Authorizer, AuthorizerArgs } from './Authorizer';
/**
* Authorizer which allows all access independent of the identifier and requested permissions.
*/
export class SimpleAuthorizer extends Authorizer { export class SimpleAuthorizer extends Authorizer {
public async canHandle(input: AuthorizerArgs): Promise<void> { public async canHandle(input: AuthorizerArgs): Promise<void> {
if (!input.identifier || !input.permissions) { if (!input.identifier || !input.permissions) {

View File

@ -2,4 +2,7 @@ import { AsyncHandler } from '../../util/AsyncHandler';
import { HttpRequest } from '../../server/HttpRequest'; import { HttpRequest } from '../../server/HttpRequest';
import { Representation } from '../representation/Representation'; import { Representation } from '../representation/Representation';
/**
* Parses the body of an incoming {@link HttpRequest} and converts it to a {@link Representation}.
*/
export abstract class BodyParser extends AsyncHandler<HttpRequest, Representation> {} export abstract class BodyParser extends AsyncHandler<HttpRequest, Representation> {}

View File

@ -2,4 +2,7 @@ import { AsyncHandler } from '../../util/AsyncHandler';
import { HttpRequest } from '../../server/HttpRequest'; import { HttpRequest } from '../../server/HttpRequest';
import { RepresentationPreferences } from '../representation/RepresentationPreferences'; import { RepresentationPreferences } from '../representation/RepresentationPreferences';
/**
* Creates {@link RepresentationPreferences} based on the incoming HTTP headers in a {@link HttpRequest}.
*/
export abstract class PreferenceParser extends AsyncHandler<HttpRequest, RepresentationPreferences> {} export abstract class PreferenceParser extends AsyncHandler<HttpRequest, RepresentationPreferences> {}

View File

@ -5,6 +5,10 @@ import { RepresentationMetadata } from '../representation/RepresentationMetadata
import { StreamParser } from 'n3'; import { StreamParser } from 'n3';
import { UnsupportedMediaTypeHttpError } from '../../util/errors/UnsupportedMediaTypeHttpError'; import { UnsupportedMediaTypeHttpError } from '../../util/errors/UnsupportedMediaTypeHttpError';
/**
* Parses the incoming {@link HttpRequest} if there is no body or if it contains turtle (or similar) RDF data.
* Naively parses the content-type header to determine the body type.
*/
export class SimpleBodyParser extends BodyParser { export class SimpleBodyParser extends BodyParser {
private static readonly contentTypes = [ private static readonly contentTypes = [
'application/n-quads', 'application/n-quads',

View File

@ -3,6 +3,10 @@ import { PreferenceParser } from './PreferenceParser';
import { RepresentationPreference } from '../representation/RepresentationPreference'; import { RepresentationPreference } from '../representation/RepresentationPreference';
import { RepresentationPreferences } from '../representation/RepresentationPreferences'; import { RepresentationPreferences } from '../representation/RepresentationPreferences';
/**
* Extracts preferences from the accept-* headers from an incoming {@link HttpRequest}.
* Parsing of header strings is done naively.
*/
export class SimplePreferenceParser extends PreferenceParser { export class SimplePreferenceParser extends PreferenceParser {
public constructor() { public constructor() {
super(); super();

View File

@ -14,6 +14,10 @@ export interface SimpleRequestParserArgs {
bodyParser: BodyParser; bodyParser: BodyParser;
} }
/**
* Creates an {@link Operation} from an incoming {@link HttpRequest} by aggregating the results
* of a {@link TargetExtractor}, {@link PreferenceParser}, and {@link BodyParser}.
*/
export class SimpleRequestParser extends RequestParser { export class SimpleRequestParser extends RequestParser {
private readonly targetExtractor: TargetExtractor; private readonly targetExtractor: TargetExtractor;
private readonly preferenceParser: PreferenceParser; private readonly preferenceParser: PreferenceParser;

View File

@ -4,6 +4,9 @@ import { ResponseDescription } from '../operations/ResponseDescription';
import { ResponseWriter } from './ResponseWriter'; import { ResponseWriter } from './ResponseWriter';
import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError'; import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError';
/**
* Writes to an {@link HttpResponse} based on the incoming {@link ResponseDescription} or error.
*/
export class SimpleResponseWriter extends ResponseWriter { export class SimpleResponseWriter extends ResponseWriter {
public async canHandle(input: { response: HttpResponse; description?: ResponseDescription; error?: Error }): Promise<void> { public async canHandle(input: { response: HttpResponse; description?: ResponseDescription; error?: Error }): Promise<void> {
if (!input.description && !input.error) { if (!input.description && !input.error) {

View File

@ -2,6 +2,10 @@ import { HttpRequest } from '../../server/HttpRequest';
import { ResourceIdentifier } from '../representation/ResourceIdentifier'; import { ResourceIdentifier } from '../representation/ResourceIdentifier';
import { TargetExtractor } from './TargetExtractor'; import { TargetExtractor } from './TargetExtractor';
/**
* Extracts an identifier from an incoming {@link HttpRequest}.
* Simply takes the input URl without any parsing/cleaning.
*/
export class SimpleTargetExtractor extends TargetExtractor { export class SimpleTargetExtractor extends TargetExtractor {
public async canHandle(input: HttpRequest): Promise<void> { public async canHandle(input: HttpRequest): Promise<void> {
if (!input.url) { if (!input.url) {

View File

@ -2,4 +2,7 @@ import { AsyncHandler } from '../../util/AsyncHandler';
import { HttpRequest } from '../../server/HttpRequest'; import { HttpRequest } from '../../server/HttpRequest';
import { ResourceIdentifier } from '../representation/ResourceIdentifier'; import { ResourceIdentifier } from '../representation/ResourceIdentifier';
/**
* Extracts a {@link ResourceIdentifier} from an incoming {@link HttpRequest}.
*/
export abstract class TargetExtractor extends AsyncHandler<HttpRequest, ResourceIdentifier> {} export abstract class TargetExtractor extends AsyncHandler<HttpRequest, ResourceIdentifier> {}

View File

@ -4,6 +4,10 @@ import { ResourceStore } from '../../storage/ResourceStore';
import { ResponseDescription } from './ResponseDescription'; import { ResponseDescription } from './ResponseDescription';
import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError'; import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError';
/**
* Handles DELETE {@link Operation}s.
* Calls the deleteResource function from a {@link ResourceStore}.
*/
export class SimpleDeleteOperationHandler extends OperationHandler { export class SimpleDeleteOperationHandler extends OperationHandler {
private readonly store: ResourceStore; private readonly store: ResourceStore;

View File

@ -4,6 +4,10 @@ import { ResourceStore } from '../../storage/ResourceStore';
import { ResponseDescription } from './ResponseDescription'; import { ResponseDescription } from './ResponseDescription';
import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError'; import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError';
/**
* Handles GET {@link Operation}s.
* Calls the getRepresentation function from a {@link ResourceStore}.
*/
export class SimpleGetOperationHandler extends OperationHandler { export class SimpleGetOperationHandler extends OperationHandler {
private readonly store: ResourceStore; private readonly store: ResourceStore;

View File

@ -4,6 +4,10 @@ import { ResourceStore } from '../../storage/ResourceStore';
import { ResponseDescription } from './ResponseDescription'; import { ResponseDescription } from './ResponseDescription';
import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError'; import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError';
/**
* Handles POST {@link Operation}s.
* Calls the addResource function from a {@link ResourceStore}.
*/
export class SimplePostOperationHandler extends OperationHandler { export class SimplePostOperationHandler extends OperationHandler {
private readonly store: ResourceStore; private readonly store: ResourceStore;

View File

@ -2,6 +2,9 @@ import { Operation } from '../operations/Operation';
import { PermissionSet } from './PermissionSet'; import { PermissionSet } from './PermissionSet';
import { PermissionsExtractor } from './PermissionsExtractor'; import { PermissionsExtractor } from './PermissionsExtractor';
/**
* Makes some simplified assumption based on the {@link Operation} method to generate a {@link PermissionSet}.
*/
export class SimplePermissionsExtractor extends PermissionsExtractor { export class SimplePermissionsExtractor extends PermissionsExtractor {
public async canHandle(): Promise<void> { public async canHandle(): Promise<void> {
return undefined; return undefined;

View File

@ -1,6 +1,9 @@
import { Representation } from './Representation'; import { Representation } from './Representation';
import { ResourceIdentifier } from './ResourceIdentifier'; import { ResourceIdentifier } from './ResourceIdentifier';
/**
* A {@link Representation} with an identifier.
*/
export interface NamedRepresentation extends Representation { export interface NamedRepresentation extends Representation {
/** /**
* The identifier of this representation. * The identifier of this representation.

View File

@ -3,6 +3,9 @@
*/ */
import { Quad } from 'rdf-js'; import { Quad } from 'rdf-js';
/**
* Metadata corresponding to a {@link Representation}.
*/
export interface RepresentationMetadata { export interface RepresentationMetadata {
/** /**
* All metadata triples of the resource. * All metadata triples of the resource.

View File

@ -1,5 +1,7 @@
import { HttpError } from './HttpError'; import { HttpError } from './HttpError';
/**
* An error thrown when no data was found for the requested identifier.
*/
export class NotFoundHttpError extends HttpError { export class NotFoundHttpError extends HttpError {
public constructor(message?: string) { public constructor(message?: string) {
super(404, 'NotFoundHttpError', message); super(404, 'NotFoundHttpError', message);

View File

@ -1,7 +1,10 @@
import { HttpError } from './HttpError'; import { HttpError } from './HttpError';
/**
* An error thrown when the media type of incoming data is not supported by a parser.
*/
export class UnsupportedMediaTypeHttpError extends HttpError { export class UnsupportedMediaTypeHttpError extends HttpError {
public constructor(message?: string) { public constructor(message?: string) {
super(415, 'UnsupportedHttpError', message); super(415, 'UnsupportedMediaTypeHttpError', message);
} }
} }