import {Model} from '../model/Model' import {Instantiable, Singleton, Inject} from '../../di' import {CommandLine} from '../../cli' import {templateModel} from '../template/model' import {CanonicalStatic} from '../../service/CanonicalStatic' import {CanonicalDefinition} from '../../service/Canonical' /** * Canonical unit responsible for loading the model classes defined by the application. */ @Singleton() export class Models extends CanonicalStatic, Instantiable>> { @Inject() protected readonly cli!: CommandLine protected appPath = ['models'] protected canonicalItem = 'model' protected suffix = '.model' public async up(): Promise { await super.up() this.cli.registerTemplate(templateModel) } public async initCanonicalItem(definition: CanonicalDefinition): Promise>> { const item = await super.initCanonicalItem(definition) if ( !(item.prototype instanceof Model) ) { throw new TypeError(`Invalid controller definition: ${definition.originalName}. Models must extend from @extollo/orm.Model.`) } return item } }