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.
19 lines
647 B
19 lines
647 B
import {Canonical, CanonicalDefinition} from './Canonical.ts'
|
|
import {isInstantiable} from '../../../di/src/type/Instantiable.ts'
|
|
|
|
export class InvalidCanonicalExportError extends Error {
|
|
constructor(name: string) {
|
|
super(`Unable to import canonical item from "${name}". The default export of this file is invalid.`)
|
|
}
|
|
}
|
|
|
|
export class InstantiableCanonical extends Canonical {
|
|
public async init_canonical_item(def: CanonicalDefinition) {
|
|
if ( isInstantiable(def.imported.default) ) {
|
|
return this.make(def.imported.default)
|
|
}
|
|
|
|
throw new InvalidCanonicalExportError(def.original_name)
|
|
}
|
|
}
|