garrettmills
1d5056b753
All checks were successful
continuous-integration/drone/push Build is passing
26 lines
973 B
TypeScript
26 lines
973 B
TypeScript
import {CanonicalStatic} from './CanonicalStatic'
|
|
import {Singleton, Instantiable, StaticClass} from '../di'
|
|
import {Controller} from '../http/Controller'
|
|
import {CanonicalDefinition} from './Canonical'
|
|
|
|
/**
|
|
* A canonical unit that loads the controller classes from `app/http/controllers`.
|
|
*/
|
|
@Singleton()
|
|
export class Controllers extends CanonicalStatic<Instantiable<Controller>, Controller> {
|
|
protected appPath = ['http', 'controllers']
|
|
|
|
protected canonicalItem = 'controller'
|
|
|
|
protected suffix = '.controller.js'
|
|
|
|
public async initCanonicalItem(definition: CanonicalDefinition): Promise<StaticClass<Instantiable<Controller>, Controller>> {
|
|
const item = await super.initCanonicalItem(definition)
|
|
if ( !(item.prototype instanceof Controller) ) {
|
|
throw new TypeError(`Invalid controller definition: ${definition.originalName}. Controllers must extend from @extollo/lib.http.Controller.`)
|
|
}
|
|
|
|
return item
|
|
}
|
|
}
|