|
|
|
@ -2,7 +2,7 @@ import {Request} from '../lifecycle/Request'
|
|
|
|
|
import {ResponseObject} from './Route'
|
|
|
|
|
import {Container} from '../../di'
|
|
|
|
|
import {CanonicalItemClass} from '../../support/CanonicalReceiver'
|
|
|
|
|
import {Awaitable, Either, Left, left, Right, right} from '../../util'
|
|
|
|
|
import {Awaitable, Either, ErrorWithContext, Left, left, Right, right} from '../../util'
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Base class representing a middleware handler that can be applied to routes.
|
|
|
|
@ -37,12 +37,12 @@ export abstract class Middleware extends CanonicalItemClass {
|
|
|
|
|
* A type of Middleware that produces a parameter that is passed to later handlers.
|
|
|
|
|
* Can be used to do common look-ups, &c before routes.
|
|
|
|
|
*/
|
|
|
|
|
export abstract class ParameterMiddleware<T> extends Middleware {
|
|
|
|
|
export abstract class ParameterMiddleware<T, THandlerArgs extends any[] = []> extends Middleware {
|
|
|
|
|
/** Look up the value. */
|
|
|
|
|
public abstract handle(): Awaitable<Either<ResponseObject, T>>
|
|
|
|
|
public abstract handle(...options: THandlerArgs): Awaitable<Either<ResponseObject, T>>
|
|
|
|
|
|
|
|
|
|
apply(): ResponseObject {
|
|
|
|
|
return this.handle()
|
|
|
|
|
throw new ErrorWithContext('Attempted to apply parameter-providing middleware directly. Try using `parameterMiddleware()` instead.')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Alias for an error response return. */
|
|
|
|
|