Request handlers & error response factory!

This commit is contained in:
garrettmills
2020-07-29 22:01:20 -05:00
parent 48f5da1747
commit a04f083dbb
11 changed files with 240 additions and 22 deletions

View File

@@ -3,6 +3,19 @@ import {DependencyKey} from '../../../di/src/type/DependencyKey.ts'
import {make} from '../../../di/src/global.ts'
import Application from '../lifecycle/Application.ts'
export interface Bindable {
get_bound_method(method_name: string): (...args: any[]) => any
}
export function isBindable(what: any): what is Bindable {
return (
what
&& typeof what.get_bound_method === 'function'
&& what.get_bound_method.length === 1
&& typeof what.get_bound_method('get_bound_method') === 'function'
)
}
export default class AppClass {
protected static make<T>(target: Instantiable<T>|DependencyKey, ...parameters: any[]) {
return make(target, ...parameters)
@@ -19,4 +32,16 @@ export default class AppClass {
protected get app() {
return make(Application)
}
public get_bound_method(method_name: string): (...args: any[]) => any {
// @ts-ignore
if ( typeof this[method_name] !== 'function' ) {
throw new TypeError(`Attempt to get bound method for non-function type: ${method_name}`)
}
return (...args: any[]): any => {
// @ts-ignore
return this[method_name](...args)
}
}
}