lib/src/service/Controllers.ts
garrettmills 1d5056b753
All checks were successful
continuous-integration/drone/push Build is passing
Setup eslint and enforce rules
2021-06-02 22:36:25 -05:00

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
}
}