1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.ModuleCompiler = void 0;
|
4 | const module_token_factory_1 = require("./module-token-factory");
|
5 | class ModuleCompiler {
|
6 | constructor(moduleTokenFactory = new module_token_factory_1.ModuleTokenFactory()) {
|
7 | this.moduleTokenFactory = moduleTokenFactory;
|
8 | }
|
9 | async compile(metatype) {
|
10 | const { type, dynamicMetadata } = this.extractMetadata(await metatype);
|
11 | const token = this.moduleTokenFactory.create(type, dynamicMetadata);
|
12 | return { type, dynamicMetadata, token };
|
13 | }
|
14 | extractMetadata(metatype) {
|
15 | if (!this.isDynamicModule(metatype)) {
|
16 | return {
|
17 | type: metatype?.forwardRef
|
18 | ? metatype.forwardRef()
|
19 | : metatype,
|
20 | };
|
21 | }
|
22 | const { module: type, ...dynamicMetadata } = metatype;
|
23 | return { type, dynamicMetadata };
|
24 | }
|
25 | isDynamicModule(module) {
|
26 | return !!module.module;
|
27 | }
|
28 | }
|
29 | exports.ModuleCompiler = ModuleCompiler;
|