@nest-forge/core 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ export declare abstract class ForgeBaseComponent {
2
+ protected onModuleInit(): any;
3
+ protected onApplicationBootstrap(): any;
4
+ protected onModuleDestroy(signal: string): any;
5
+ protected beforeApplicationShutdown(signal: string): any;
6
+ protected onApplicationShutdown(signal: string): any;
7
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var _a;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.ForgeBaseComponent = void 0;
5
+ const tslib_1 = require("tslib");
6
+ const common_1 = require("@nestjs/common");
7
+ const constants_1 = require("../constants");
8
+ const core_1 = require("@nestjs/core");
9
+ class ForgeBaseComponent {
10
+ /**
11
+ * @internal
12
+ */
13
+ [_a = constants_1.FORGE_FIELD_MODULE_REF];
14
+ onModuleInit() { }
15
+ onApplicationBootstrap() { }
16
+ onModuleDestroy(signal) { }
17
+ beforeApplicationShutdown(signal) { }
18
+ onApplicationShutdown(signal) { }
19
+ }
20
+ exports.ForgeBaseComponent = ForgeBaseComponent;
21
+ tslib_1.__decorate([
22
+ (0, common_1.Inject)(core_1.ModuleRef),
23
+ tslib_1.__metadata("design:type", core_1.ModuleRef)
24
+ ], ForgeBaseComponent.prototype, _a, void 0);
@@ -0,0 +1,3 @@
1
+ import { ForgeBaseComponent } from './component';
2
+ export declare abstract class ForgeController extends ForgeBaseComponent {
3
+ }
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ForgeController = void 0;
4
+ const component_1 = require("./component");
5
+ class ForgeController extends component_1.ForgeBaseComponent {
6
+ }
7
+ exports.ForgeController = ForgeController;
@@ -0,0 +1,4 @@
1
+ export * from './component';
2
+ export * from './module';
3
+ export * from './controller';
4
+ export * from './service';
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./component"), exports);
5
+ tslib_1.__exportStar(require("./module"), exports);
6
+ tslib_1.__exportStar(require("./controller"), exports);
7
+ tslib_1.__exportStar(require("./service"), exports);
@@ -0,0 +1,5 @@
1
+ import { MiddlewareConsumer } from '@nestjs/common';
2
+ import { ForgeBaseComponent } from './component';
3
+ export declare abstract class ForgeModule extends ForgeBaseComponent {
4
+ configure(consumer: MiddlewareConsumer): any;
5
+ }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ForgeModule = void 0;
4
+ const component_1 = require("./component");
5
+ class ForgeModule extends component_1.ForgeBaseComponent {
6
+ configure(consumer) { }
7
+ }
8
+ exports.ForgeModule = ForgeModule;
@@ -0,0 +1,3 @@
1
+ import { ForgeBaseComponent } from './component';
2
+ export declare abstract class ForgeService extends ForgeBaseComponent {
3
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ForgeService = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const common_1 = require("@nestjs/common");
6
+ const component_1 = require("./component");
7
+ let ForgeService = class ForgeService extends component_1.ForgeBaseComponent {
8
+ };
9
+ exports.ForgeService = ForgeService;
10
+ exports.ForgeService = ForgeService = tslib_1.__decorate([
11
+ (0, common_1.Injectable)()
12
+ ], ForgeService);
@@ -0,0 +1,6 @@
1
+ export declare const FORGE_ROOT_MODULE: unique symbol;
2
+ export declare const FORGE_FIELD_MODULE_REF: unique symbol;
3
+ export declare const FORGE_TOKEN_ROOT_MODULE: unique symbol;
4
+ export declare const FORGE_PATCHED: unique symbol;
5
+ export declare const FORGE_PATCH_BOOT_CALLBACK: unique symbol;
6
+ export declare const FORGE_PATCH_ENABLE_INIT: unique symbol;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FORGE_PATCH_ENABLE_INIT = exports.FORGE_PATCH_BOOT_CALLBACK = exports.FORGE_PATCHED = exports.FORGE_TOKEN_ROOT_MODULE = exports.FORGE_FIELD_MODULE_REF = exports.FORGE_ROOT_MODULE = void 0;
4
+ exports.FORGE_ROOT_MODULE = Symbol('FORGE_ROOT_MODULE');
5
+ exports.FORGE_FIELD_MODULE_REF = Symbol('FORGE_FIELD_MODULE_REF');
6
+ exports.FORGE_TOKEN_ROOT_MODULE = Symbol('FORGE_TOKEN_ROOT_MODULE');
7
+ exports.FORGE_PATCHED = Symbol('FORGE_PATCHED');
8
+ exports.FORGE_PATCH_BOOT_CALLBACK = Symbol('FORGE_PATCH_BOOT_CALLBACK');
9
+ exports.FORGE_PATCH_ENABLE_INIT = Symbol('FORGE_PATCH_ENABLE_INIT');
@@ -1,4 +1,8 @@
1
- import { INestApplication, INestApplicationContext, MiddlewareConsumer, ModuleMetadata } from '@nestjs/common';
1
+ import { INestApplication, INestApplicationContext, INestMicroservice, MiddlewareConsumer, ModuleMetadata, NestApplicationOptions } from '@nestjs/common';
2
+ import { ForgeBaseComponent, ForgeController, ForgeModule, ForgeService } from '../architecture';
3
+ import { NestApplicationContextOptions } from '@nestjs/common/interfaces/nest-application-context-options.interface';
4
+ import { NestMicroserviceOptions } from '@nestjs/common/interfaces/microservices/nest-microservice-options.interface';
5
+ import { AbstractHttpAdapter } from '@nestjs/core';
2
6
  export declare abstract class ForgeExtension {
3
7
  /**
4
8
  * The metdata for this extension.
@@ -8,23 +12,65 @@ export declare abstract class ForgeExtension {
8
12
  * Constructs a new forge extension instance.
9
13
  */
10
14
  constructor(options?: ForgeExtensionMetadata);
15
+ /**
16
+ * Configures the HTTP adapter to use for the Nest application instance.
17
+ *
18
+ * @param current The current adapter instance, or `undefined` if not set (default will be used).
19
+ */
20
+ configureHttpAdapter(current?: AbstractHttpAdapter): ForgeHttpAdapterLike;
11
21
  /**
12
22
  * Configures a Nest application instance.
13
23
  */
14
24
  configureHttpApplication(application: INestApplication): any;
15
25
  /**
16
- * Configures a Nest application context. This is
26
+ * Configures the options object for a Nest application instance.
27
+ */
28
+ configureHttpApplicationOptions(options: NestApplicationOptions): NestApplicationOptions | Promise<NestApplicationOptions>;
29
+ /**
30
+ * Configures a Nest application context. This is for a standalone application that has no web server.
17
31
  */
18
32
  configureStandaloneApplication(context: INestApplicationContext): any;
33
+ /**
34
+ * Configures the options object for a standalone Nest application instance.
35
+ */
36
+ configureStandaloneApplicationOptions(options: NestApplicationContextOptions): NestApplicationContextOptions | Promise<NestApplicationContextOptions>;
37
+ /**
38
+ * Configures a Nest microservice context.
39
+ */
40
+ configureMicroserviceApplication(context: INestMicroservice): any;
41
+ /**
42
+ * Configures the options object for a Nest microservice instance.
43
+ */
44
+ configureMicroserviceApplicationOptions(options: NestMicroserviceOptions): NestMicroserviceOptions | Promise<NestMicroserviceOptions>;
19
45
  /**
20
46
  * Configures the root module of the application.
21
47
  */
22
48
  configureRootModule(consumer: MiddlewareConsumer): any;
49
+ /**
50
+ * Runs after all services in the application have booted.
51
+ */
52
+ afterBoot(app: INestApplicationContext): any;
23
53
  /**
24
54
  * Instruments the application context. If a value is returned, the instance is replaced with that value, and no further extensions are
25
55
  * queried.
26
56
  */
27
57
  instrument(instance: unknown): any;
58
+ /**
59
+ * Augments a `ForgeBaseComponent` instance.
60
+ */
61
+ augmentComponent(instance: ForgeBaseComponent, moduleRef: any): any;
62
+ /**
63
+ * Augments a `ForgeModule` instance.
64
+ */
65
+ augmentModule(instance: ForgeModule, moduleRef: any): any;
66
+ /**
67
+ * Augments a `ForgeController` instance.
68
+ */
69
+ augmentController(instance: ForgeController, moduleRef: any): any;
70
+ /**
71
+ * Augments a `ForgeService` instance.
72
+ */
73
+ augmentService(instance: ForgeService, moduleRef: any): any;
28
74
  /**
29
75
  * Returns the metadata for this extension.
30
76
  */
@@ -37,3 +83,4 @@ export interface ForgeExtensionMetadata extends ModuleMetadata {
37
83
  extensions?: ForgeExtensionResolvable[];
38
84
  }
39
85
  export type ForgeExtensionResolvable = ForgeExtension | (new () => ForgeExtension) | null | undefined | false;
86
+ export type ForgeHttpAdapterLike = AbstractHttpAdapter | null | undefined | Promise<AbstractHttpAdapter | null | undefined>;
@@ -12,23 +12,73 @@ class ForgeExtension {
12
12
  constructor(options) {
13
13
  this._metadata = options || {};
14
14
  }
15
+ /**
16
+ * Configures the HTTP adapter to use for the Nest application instance.
17
+ *
18
+ * @param current The current adapter instance, or `undefined` if not set (default will be used).
19
+ */
20
+ configureHttpAdapter(current) {
21
+ return;
22
+ }
15
23
  /**
16
24
  * Configures a Nest application instance.
17
25
  */
18
26
  configureHttpApplication(application) { }
19
27
  /**
20
- * Configures a Nest application context. This is
28
+ * Configures the options object for a Nest application instance.
29
+ */
30
+ configureHttpApplicationOptions(options) {
31
+ return options;
32
+ }
33
+ /**
34
+ * Configures a Nest application context. This is for a standalone application that has no web server.
21
35
  */
22
36
  configureStandaloneApplication(context) { }
37
+ /**
38
+ * Configures the options object for a standalone Nest application instance.
39
+ */
40
+ configureStandaloneApplicationOptions(options) {
41
+ return options;
42
+ }
43
+ /**
44
+ * Configures a Nest microservice context.
45
+ */
46
+ configureMicroserviceApplication(context) { }
47
+ /**
48
+ * Configures the options object for a Nest microservice instance.
49
+ */
50
+ configureMicroserviceApplicationOptions(options) {
51
+ return options;
52
+ }
23
53
  /**
24
54
  * Configures the root module of the application.
25
55
  */
26
56
  configureRootModule(consumer) { }
57
+ /**
58
+ * Runs after all services in the application have booted.
59
+ */
60
+ afterBoot(app) { }
27
61
  /**
28
62
  * Instruments the application context. If a value is returned, the instance is replaced with that value, and no further extensions are
29
63
  * queried.
30
64
  */
31
65
  instrument(instance) { }
66
+ /**
67
+ * Augments a `ForgeBaseComponent` instance.
68
+ */
69
+ augmentComponent(instance, moduleRef) { }
70
+ /**
71
+ * Augments a `ForgeModule` instance.
72
+ */
73
+ augmentModule(instance, moduleRef) { }
74
+ /**
75
+ * Augments a `ForgeController` instance.
76
+ */
77
+ augmentController(instance, moduleRef) { }
78
+ /**
79
+ * Augments a `ForgeService` instance.
80
+ */
81
+ augmentService(instance, moduleRef) { }
32
82
  /**
33
83
  * Returns the metadata for this extension.
34
84
  */
@@ -1,9 +1,13 @@
1
1
  import { NestApplicationOptions } from '@nestjs/common';
2
2
  import { ForgeExtensionResolvable } from './extensions';
3
3
  import { NestApplicationContextOptions } from '@nestjs/common/interfaces/nest-application-context-options.interface';
4
+ import { NestMicroserviceOptions } from '@nestjs/common/interfaces/microservices/nest-microservice-options.interface';
4
5
  export interface ForgeApplicationOptions extends NestApplicationOptions {
5
6
  extensions?: ForgeExtensionResolvable | ForgeExtensionResolvable[];
6
7
  }
7
8
  export interface ForgeApplicationContextOptions extends NestApplicationContextOptions {
8
9
  extensions?: ForgeExtensionResolvable | ForgeExtensionResolvable[];
9
10
  }
11
+ export interface ForgeMicroserviceOptions extends NestMicroserviceOptions {
12
+ extensions?: ForgeExtensionResolvable | ForgeExtensionResolvable[];
13
+ }
@@ -1,21 +1,42 @@
1
- import { DynamicModule, ForwardReference, MiddlewareConsumer, Type } from '@nestjs/common';
2
- import { ForgeApplicationContextOptions, ForgeApplicationOptions } from './forge-options.interface';
1
+ import { DynamicModule, ForwardReference, INestApplication, INestApplicationContext, MiddlewareConsumer, Type } from '@nestjs/common';
2
+ import { ForgeApplicationContextOptions, ForgeApplicationOptions, ForgeMicroserviceOptions } from './forge-options.interface';
3
3
  import { ForgeExtension, ForgeExtensionResolvable } from './extensions';
4
+ import { AbstractHttpAdapter, ModuleRef } from '@nestjs/core';
5
+ import { FORGE_ROOT_MODULE } from './constants';
6
+ import { ForgeBaseComponent, ForgeController, ForgeModule, ForgeService } from './architecture';
4
7
  declare class Forge {
5
- create(appModule: IEntryNestModule, options?: ForgeApplicationOptions): Promise<import("@nestjs/common").INestApplication<any>>;
6
- createApplicationContext(appModule: IEntryNestModule, options: ForgeApplicationContextOptions): Promise<import("@nestjs/common").INestApplicationContext>;
8
+ private _augmented;
9
+ create<T extends INestApplication = INestApplication>(appModule: IEntryNestModule, options?: ForgeApplicationOptions): Promise<T>;
10
+ create<T extends INestApplication = INestApplication>(appModule: IEntryNestModule, httpAdapter: AbstractHttpAdapter, options?: ForgeApplicationOptions): Promise<T>;
11
+ createApplicationContext(appModule: IEntryNestModule, options: ForgeApplicationContextOptions): Promise<INestApplicationContext>;
12
+ createMicroservice<T extends object>(appModule: IEntryNestModule, options: ForgeMicroserviceOptions & T): Promise<import("@nestjs/common").INestMicroservice>;
7
13
  protected discoverExtensions(resolvables: ForgeExtensionResolvable | ForgeExtensionResolvable[]): ForgeExtension[];
8
- protected resolveExtension(resolvable: ForgeExtensionResolvable): ForgeExtension;
14
+ protected resolveExtension(resolvable: ForgeExtensionResolvable): ForgeExtension | null;
9
15
  protected createRootModule(appModule: IEntryNestModule, extensions: ForgeExtension[]): {
10
- new (): {
11
- configure(consumer: MiddlewareConsumer): void;
16
+ new (moduleRef: ModuleRef): {
17
+ readonly moduleRef: ModuleRef;
18
+ configure(consumer: MiddlewareConsumer): Promise<void>;
19
+ readonly [FORGE_ROOT_MODULE]: true;
12
20
  };
13
21
  };
14
- protected createInstrument(extensions: ForgeExtension[], originalInstrument?: Instrument): Instrument;
22
+ protected createInstrument(extensions: ForgeExtension[], originalInstrument?: Instrument): InstrumentResponse;
23
+ protected augmentComponents(instances: ForgeBaseComponent[], extensions: ForgeExtension[]): Promise<void>;
24
+ protected augmentComponent(instance: ForgeBaseComponent, extensions: ForgeExtension[]): Promise<void>;
25
+ protected augmentModule(instance: ForgeModule, extensions: ForgeExtension[]): Promise<void>;
26
+ protected augmentController(instance: ForgeController, extensions: ForgeExtension[]): Promise<void>;
27
+ protected augmentService(instance: ForgeService, extensions: ForgeExtension[]): Promise<void>;
28
+ protected _isRootModule(instance: unknown): instance is IForgeRootModule;
29
+ protected _isHttpAdapter(instance: unknown): instance is AbstractHttpAdapter;
30
+ protected _augmentBootHooks(createOptions: object, extensions: ForgeExtension[]): void;
31
+ protected _augmentNestApplication(): void;
15
32
  }
16
33
  type IEntryNestModule = Type<any> | DynamicModule | ForwardReference | Promise<IEntryNestModule>;
17
34
  type Instrument = {
18
35
  instanceDecorator: (instance: unknown) => unknown;
19
36
  };
37
+ interface InstrumentResponse {
38
+ instances: ForgeBaseComponent[];
39
+ instanceDecorator: (instance: unknown) => any;
40
+ }
20
41
  declare const forge: Forge;
21
42
  export { forge as Forge };
@@ -4,28 +4,96 @@ exports.Forge = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const common_1 = require("@nestjs/common");
6
6
  const core_1 = require("@nestjs/core");
7
+ const constants_1 = require("./constants");
8
+ const architecture_1 = require("./architecture");
7
9
  class Forge {
8
- async create(appModule, options) {
10
+ _augmented = new Set();
11
+ async create(appModule, optionsOrHttpAdapter, optionsFallback) {
12
+ let adapter = this._isHttpAdapter(optionsOrHttpAdapter) ? optionsOrHttpAdapter : undefined;
13
+ const options = (typeof optionsFallback === 'object' ? optionsFallback : adapter ? {} : optionsOrHttpAdapter) ??
14
+ {};
9
15
  const extensions = this.discoverExtensions(options?.extensions ?? []);
10
16
  const root = this.createRootModule(appModule, extensions);
11
- const app = await core_1.NestFactory.create(root, {
17
+ const instrument = this.createInstrument(extensions, options.instrument);
18
+ let createOptions = {
12
19
  ...options,
13
- instrument: this.createInstrument(extensions, options.instrument),
14
- });
20
+ instrument: {
21
+ instanceDecorator: instrument.instanceDecorator,
22
+ },
23
+ };
24
+ for (const extension of extensions) {
25
+ const newOptions = await extension.configureHttpApplicationOptions(createOptions);
26
+ const newAdapter = await extension.configureHttpAdapter(adapter);
27
+ if (typeof newOptions === 'object' && newOptions !== null) {
28
+ createOptions = newOptions;
29
+ }
30
+ if (typeof newAdapter === 'object' && newAdapter !== null) {
31
+ adapter = newAdapter;
32
+ }
33
+ }
34
+ const createArgs = [root, createOptions];
35
+ if (adapter) {
36
+ createArgs.splice(1, 0, adapter);
37
+ }
38
+ this._augmentBootHooks(createOptions, extensions);
39
+ this._augmentNestApplication();
40
+ const app = await core_1.NestFactory.create.apply(core_1.NestFactory, createArgs);
41
+ await this.augmentComponents(instrument.instances, extensions);
15
42
  for (const extension of extensions) {
16
- extension.configureHttpApplication(app);
43
+ await extension.configureHttpApplication(app);
17
44
  }
18
45
  return app;
19
46
  }
20
47
  async createApplicationContext(appModule, options) {
21
48
  const extensions = this.discoverExtensions(options?.extensions ?? []);
22
49
  const root = this.createRootModule(appModule, extensions);
23
- const app = await core_1.NestFactory.createApplicationContext(root, {
50
+ const instrument = this.createInstrument(extensions, options.instrument);
51
+ let createOptions = {
24
52
  ...options,
25
- instrument: this.createInstrument(extensions, options.instrument),
26
- });
53
+ instrument: {
54
+ instanceDecorator: instrument.instanceDecorator,
55
+ },
56
+ };
57
+ for (const extension of extensions) {
58
+ const newOptions = await extension.configureStandaloneApplicationOptions(createOptions);
59
+ if (typeof newOptions === 'object' && newOptions !== null) {
60
+ createOptions = newOptions;
61
+ }
62
+ }
63
+ createOptions[constants_1.FORGE_PATCH_ENABLE_INIT] = false;
64
+ this._augmentBootHooks(createOptions, extensions);
65
+ this._augmentNestApplication();
66
+ const app = await core_1.NestFactory.createApplicationContext(root, createOptions);
67
+ await this.augmentComponents(instrument.instances, extensions);
27
68
  for (const extension of extensions) {
28
- extension.configureStandaloneApplication(app);
69
+ await extension.configureStandaloneApplication(app);
70
+ }
71
+ createOptions[constants_1.FORGE_PATCH_ENABLE_INIT] = true;
72
+ await app.init();
73
+ return app;
74
+ }
75
+ async createMicroservice(appModule, options) {
76
+ const extensions = this.discoverExtensions(options?.extensions ?? []);
77
+ const root = this.createRootModule(appModule, extensions);
78
+ const instrument = this.createInstrument(extensions, options.instrument);
79
+ let createOptions = {
80
+ ...options,
81
+ instrument: {
82
+ instanceDecorator: instrument.instanceDecorator,
83
+ },
84
+ };
85
+ for (const extension of extensions) {
86
+ const newOptions = await extension.configureMicroserviceApplicationOptions(createOptions);
87
+ if (typeof newOptions === 'object' && newOptions !== null) {
88
+ createOptions = newOptions;
89
+ }
90
+ }
91
+ this._augmentBootHooks(createOptions, extensions);
92
+ this._augmentNestApplication();
93
+ const app = await core_1.NestFactory.createMicroservice(root, createOptions);
94
+ await this.augmentComponents(instrument.instances, extensions);
95
+ for (const extension of extensions) {
96
+ await extension.configureMicroserviceApplication(app);
29
97
  }
30
98
  return app;
31
99
  }
@@ -62,7 +130,7 @@ class Forge {
62
130
  }
63
131
  createRootModule(appModule, extensions) {
64
132
  const meta = {
65
- imports: [appModule],
133
+ imports: [],
66
134
  controllers: [],
67
135
  providers: [],
68
136
  exports: [],
@@ -74,22 +142,53 @@ class Forge {
74
142
  meta.providers.push(...(extensionMeta.providers ?? []));
75
143
  meta.exports.push(...(extensionMeta.exports ?? []));
76
144
  }
145
+ meta.imports.push(appModule);
77
146
  let ForgeRootModule = class ForgeRootModule {
78
- configure(consumer) {
147
+ moduleRef;
148
+ [constants_1.FORGE_ROOT_MODULE] = true;
149
+ constructor(moduleRef) {
150
+ this.moduleRef = moduleRef;
151
+ }
152
+ async configure(consumer) {
79
153
  for (const extension of extensions) {
80
- extension.configureRootModule(consumer);
154
+ await extension.configureRootModule(consumer);
81
155
  }
82
156
  }
83
157
  };
84
158
  ForgeRootModule = tslib_1.__decorate([
85
- (0, common_1.Module)(meta)
159
+ (0, common_1.Module)(meta),
160
+ (0, common_1.Global)(),
161
+ tslib_1.__metadata("design:paramtypes", [core_1.ModuleRef])
86
162
  ], ForgeRootModule);
163
+ let ForgeRootProviderModule = class ForgeRootProviderModule {
164
+ };
165
+ ForgeRootProviderModule = tslib_1.__decorate([
166
+ (0, common_1.Global)(),
167
+ (0, common_1.Module)({
168
+ providers: [
169
+ {
170
+ provide: constants_1.FORGE_TOKEN_ROOT_MODULE,
171
+ useClass: ForgeRootModule,
172
+ },
173
+ ],
174
+ exports: [constants_1.FORGE_TOKEN_ROOT_MODULE],
175
+ })
176
+ ], ForgeRootProviderModule);
177
+ meta.imports.unshift(ForgeRootProviderModule);
87
178
  return ForgeRootModule;
88
179
  }
89
180
  createInstrument(extensions, originalInstrument) {
90
181
  const hasOriginalInstrument = originalInstrument && originalInstrument.instanceDecorator;
182
+ const instances = new Array();
91
183
  return {
92
- instanceDecorator(instance) {
184
+ instances,
185
+ instanceDecorator: (instance) => {
186
+ if (this._isRootModule(instance)) {
187
+ // TODO
188
+ }
189
+ if (instance instanceof architecture_1.ForgeBaseComponent) {
190
+ instances.push(instance);
191
+ }
93
192
  for (const extension of extensions) {
94
193
  const response = extension.instrument(instance);
95
194
  if (response !== undefined) {
@@ -103,6 +202,80 @@ class Forge {
103
202
  },
104
203
  };
105
204
  }
205
+ async augmentComponents(instances, extensions) {
206
+ for (const instance of instances) {
207
+ if (!this._augmented.has(instance)) {
208
+ await this.augmentComponent(instance, extensions);
209
+ if (instance instanceof architecture_1.ForgeModule) {
210
+ await this.augmentModule(instance, extensions);
211
+ }
212
+ else if (instance instanceof architecture_1.ForgeController) {
213
+ await this.augmentController(instance, extensions);
214
+ }
215
+ else if (instance instanceof architecture_1.ForgeService) {
216
+ await this.augmentService(instance, extensions);
217
+ }
218
+ this._augmented.add(instance);
219
+ }
220
+ }
221
+ }
222
+ async augmentComponent(instance, extensions) {
223
+ for (const extension of extensions) {
224
+ await extension.augmentComponent(instance, instance[constants_1.FORGE_FIELD_MODULE_REF]);
225
+ }
226
+ }
227
+ async augmentModule(instance, extensions) {
228
+ for (const extension of extensions) {
229
+ await extension.augmentModule(instance, instance[constants_1.FORGE_FIELD_MODULE_REF]);
230
+ }
231
+ }
232
+ async augmentController(instance, extensions) {
233
+ for (const extension of extensions) {
234
+ await extension.augmentController(instance, instance[constants_1.FORGE_FIELD_MODULE_REF]);
235
+ }
236
+ }
237
+ async augmentService(instance, extensions) {
238
+ for (const extension of extensions) {
239
+ await extension.augmentService(instance, instance[constants_1.FORGE_FIELD_MODULE_REF]);
240
+ }
241
+ }
242
+ _isRootModule(instance) {
243
+ return typeof instance === 'object' && instance !== null && instance[constants_1.FORGE_ROOT_MODULE] === true;
244
+ }
245
+ _isHttpAdapter(instance) {
246
+ return typeof instance === 'object' && instance !== null && typeof instance['use'] === 'function';
247
+ }
248
+ _augmentBootHooks(createOptions, extensions) {
249
+ createOptions[constants_1.FORGE_PATCH_BOOT_CALLBACK] = async (app) => {
250
+ try {
251
+ await Promise.all(extensions.map((e) => e.afterBoot(app)));
252
+ }
253
+ catch (error) {
254
+ console.error(error);
255
+ }
256
+ };
257
+ }
258
+ _augmentNestApplication() {
259
+ const application = core_1.NestApplicationContext;
260
+ const originalBootstrapHook = application.prototype.callBootstrapHook;
261
+ const originalInit = application.prototype.init;
262
+ if (application.prototype[constants_1.FORGE_PATCHED]) {
263
+ return;
264
+ }
265
+ application.prototype[constants_1.FORGE_PATCHED] = true;
266
+ application.prototype.callBootstrapHook = async function () {
267
+ await originalBootstrapHook.call(this);
268
+ if (this.appOptions[constants_1.FORGE_PATCH_BOOT_CALLBACK]) {
269
+ await this.appOptions[constants_1.FORGE_PATCH_BOOT_CALLBACK](this);
270
+ }
271
+ };
272
+ application.prototype.init = async function () {
273
+ if (this.appOptions[constants_1.FORGE_PATCH_ENABLE_INIT] === false) {
274
+ return this;
275
+ }
276
+ return originalInit.call(this);
277
+ };
278
+ }
106
279
  }
107
280
  const forge = new Forge();
108
281
  exports.Forge = forge;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './forge.factory';
2
2
  export * from './forge-options.interface';
3
3
  export * from './extensions';
4
+ export * from './architecture';
package/dist/index.js CHANGED
@@ -4,3 +4,4 @@ const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./forge.factory"), exports);
5
5
  tslib_1.__exportStar(require("./forge-options.interface"), exports);
6
6
  tslib_1.__exportStar(require("./extensions"), exports);
7
+ tslib_1.__exportStar(require("./architecture"), exports);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nest-forge/core",
3
3
  "description": "",
4
- "version": "0.0.1",
4
+ "version": "0.0.3",
5
5
  "scripts": {
6
6
  "build": "rimraf dist && tsc -p tsconfig.json",
7
7
  "watch": "rimraf dist && tsc -w -p tsconfig.json",
@@ -31,14 +31,12 @@
31
31
  "devDependencies": {
32
32
  "@eslint/eslintrc": "^3.3.3",
33
33
  "@eslint/js": "^9.39.2",
34
- "@types/node": "~25.0.0",
34
+ "@types/node": "~24.0.0",
35
35
  "eslint": "^9.18.0",
36
36
  "eslint-config-prettier": "^10.1.8",
37
- "eslint-plugin-import": "^2.32.0",
38
37
  "eslint-plugin-prettier": "^5.5.4",
39
38
  "globals": "^16.0.0",
40
39
  "prettier": "3.7.4",
41
- "reflect-metadata": "^0.2.2",
42
40
  "rimraf": "^6.1.2",
43
41
  "typescript": "^5.9.0",
44
42
  "typescript-eslint": "^8.51.0"
package/tsconfig.json CHANGED
@@ -15,10 +15,10 @@
15
15
  "sourceMap": false,
16
16
  "allowJs": false,
17
17
  "outDir": "./dist",
18
- "baseUrl": ".",
19
18
  "forceConsistentCasingInFileNames": true,
20
19
  "strictPropertyInitialization": false,
21
- "stripInternal": true
20
+ "stripInternal": true,
21
+ "strict": true
22
22
  },
23
23
  "include": [
24
24
  "src/**/*"
package/.prettierignore DELETED
@@ -1,3 +0,0 @@
1
- pnpm-lock.yaml
2
- package-lock.json
3
- yarn.lock
package/.prettierrc DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "parser": "typescript",
3
- "useTabs": true,
4
- "singleQuote": true,
5
- "trailingComma": "es5",
6
- "printWidth": 140
7
- }
package/eslint.config.mjs DELETED
@@ -1,31 +0,0 @@
1
- import eslint from '@eslint/js';
2
- import { defineConfig } from 'eslint/config';
3
- import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
4
- import tseslint from 'typescript-eslint';
5
- import globals from 'globals';
6
-
7
- export default defineConfig(
8
- {
9
- ignores: ['node_modules', '**/node_modules/**', '**/*.js', '**/*.d.ts']
10
- },
11
- eslint.configs.recommended,
12
- ...tseslint.configs.recommendedTypeChecked,
13
- eslintPluginPrettierRecommended,
14
- {
15
- languageOptions: {
16
- globals: {
17
- ...globals.node,
18
- ...globals.jest
19
- },
20
- ecmaVersion: 2024,
21
- sourceType: 'module',
22
- parserOptions: {
23
- projectService: true,
24
- tsconfigRootDir: import.meta.dirname
25
- }
26
- }
27
- },
28
- {
29
- rules: {}
30
- }
31
- );