You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
import {CanonicalDefinition} from '../../lib/src/unit/Canonical.ts'
|
|
|
|
import {Model} from './model/Model.ts'
|
|
|
|
import {Unit} from '../../lib/src/lifecycle/decorators.ts'
|
|
|
|
import {StaticCanonical} from '../../lib/src/unit/StaticCanonical.ts'
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Canonical unit which loads ORM models from their directory.
|
|
|
|
* @extends StaticCanonical
|
|
|
|
*/
|
|
|
|
@Unit()
|
|
|
|
export default class ModelsUnit extends StaticCanonical<Model<any>, typeof Model> {
|
|
|
|
protected base_path = './app/models'
|
|
|
|
protected canonical_item = 'model'
|
|
|
|
protected suffix = '.model.ts'
|
|
|
|
|
|
|
|
public async init_canonical_item(def: CanonicalDefinition) {
|
|
|
|
const item = await super.init_canonical_item(def)
|
|
|
|
if ( !(item.prototype instanceof Model) ) {
|
|
|
|
throw new TypeError(`Invalid model definition: ${def.original_name}. Models must extend from Daton ORM's base Model class.`)
|
|
|
|
}
|
|
|
|
|
|
|
|
return item
|
|
|
|
}
|
|
|
|
}
|