2021-06-03 03:36:25 +00:00
|
|
|
import {CanonicalStatic} from './CanonicalStatic'
|
|
|
|
import {Singleton, Instantiable, StaticClass} from '../di'
|
|
|
|
import {Controller} from '../http/Controller'
|
|
|
|
import {CanonicalDefinition} from './Canonical'
|
2021-03-03 00:57:41 +00:00
|
|
|
|
2021-03-25 13:50:13 +00:00
|
|
|
/**
|
|
|
|
* A canonical unit that loads the controller classes from `app/http/controllers`.
|
|
|
|
*/
|
2021-03-03 00:57:41 +00:00
|
|
|
@Singleton()
|
2021-03-08 17:08:56 +00:00
|
|
|
export class Controllers extends CanonicalStatic<Instantiable<Controller>, Controller> {
|
2021-03-03 00:57:41 +00:00
|
|
|
protected appPath = ['http', 'controllers']
|
2021-06-03 03:36:25 +00:00
|
|
|
|
2021-03-03 00:57:41 +00:00
|
|
|
protected canonicalItem = 'controller'
|
2021-06-03 03:36:25 +00:00
|
|
|
|
2021-03-03 00:57:41 +00:00
|
|
|
protected suffix = '.controller.js'
|
|
|
|
|
2021-06-03 03:36:25 +00:00
|
|
|
public async initCanonicalItem(definition: CanonicalDefinition): Promise<StaticClass<Instantiable<Controller>, Controller>> {
|
2021-03-03 00:57:41 +00:00
|
|
|
const item = await super.initCanonicalItem(definition)
|
2021-03-08 17:08:56 +00:00
|
|
|
if ( !(item.prototype instanceof Controller) ) {
|
2021-03-03 00:57:41 +00:00
|
|
|
throw new TypeError(`Invalid controller definition: ${definition.originalName}. Controllers must extend from @extollo/lib.http.Controller.`)
|
|
|
|
}
|
|
|
|
|
|
|
|
return item
|
|
|
|
}
|
|
|
|
}
|