2021-06-03 03:36:25 +00:00
|
|
|
import {Canonical, CanonicalDefinition} from './Canonical'
|
|
|
|
import {isStaticClass, StaticClass} from '../di'
|
|
|
|
import {InvalidCanonicalExportError} from './CanonicalInstantiable'
|
2021-03-03 00:57:41 +00:00
|
|
|
|
2021-03-25 13:50:13 +00:00
|
|
|
/**
|
|
|
|
* Variant of the Canonical unit whose files export static classes, and these static classes
|
|
|
|
* are the exports of the class.
|
|
|
|
*
|
|
|
|
* @example
|
|
|
|
* The Controllers class is CanonicalStatic. The various `.controller.ts` files export static
|
|
|
|
* Controller classes, so the canonical items managed by the Controllers service are `Instantiable<Controller>`.
|
|
|
|
*/
|
2021-03-03 00:57:41 +00:00
|
|
|
export class CanonicalStatic<T, T2> extends Canonical<StaticClass<T, T2>> {
|
|
|
|
public async initCanonicalItem(definition: CanonicalDefinition): Promise<StaticClass<T, T2>> {
|
|
|
|
if ( isStaticClass(definition.imported.default) ) {
|
|
|
|
return definition.imported.default
|
|
|
|
}
|
|
|
|
|
2021-03-08 17:08:56 +00:00
|
|
|
if ( isStaticClass(definition.imported[definition.canonicalName.split(':').reverse()[0]]) ) {
|
|
|
|
return definition.imported[definition.canonicalName.split(':').reverse()[0]]
|
2021-03-06 17:44:32 +00:00
|
|
|
}
|
|
|
|
|
2021-03-03 00:57:41 +00:00
|
|
|
throw new InvalidCanonicalExportError(definition.originalName)
|
|
|
|
}
|
|
|
|
}
|