import {Canonical, CanonicalDefinition} from './Canonical.ts' import Instantiable, {isInstantiable} from '../../../di/src/type/Instantiable.ts' /** * Error thrown when the item returned from a canonical definition file is not the expected item. * @extends Error */ export class InvalidCanonicalExportError extends Error { constructor(name: string) { super(`Unable to import canonical item from "${name}". The default export of this file is invalid.`) } } /** * Base class for Canonical units which return instantiated versions of the classes * defined in those files. The files should export default clases which are Instantiable. * @extends Canonical */ export class InstantiableCanonical extends Canonical> { public async init_canonical_item(def: CanonicalDefinition): Promise> { if ( isInstantiable(def.imported.default) ) { return this.make(def.imported.default) } throw new InvalidCanonicalExportError(def.original_name) } }