@nest-forge/core 0.0.3 → 0.0.4
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.
- package/package.json +5 -14
- package/README.md +0 -0
- package/dist/architecture/component.d.ts +0 -7
- package/dist/architecture/component.js +0 -24
- package/dist/architecture/controller.d.ts +0 -3
- package/dist/architecture/controller.js +0 -7
- package/dist/architecture/index.d.ts +0 -4
- package/dist/architecture/index.js +0 -7
- package/dist/architecture/module.d.ts +0 -5
- package/dist/architecture/module.js +0 -8
- package/dist/architecture/service.d.ts +0 -3
- package/dist/architecture/service.js +0 -12
- package/dist/constants.d.ts +0 -6
- package/dist/constants.js +0 -9
- package/dist/extensions/extension.d.ts +0 -86
- package/dist/extensions/extension.js +0 -89
- package/dist/extensions/index.d.ts +0 -1
- package/dist/extensions/index.js +0 -4
- package/dist/forge-options.interface.d.ts +0 -13
- package/dist/forge-options.interface.js +0 -2
- package/dist/forge.factory.d.ts +0 -42
- package/dist/forge.factory.js +0 -281
- package/dist/index.d.ts +0 -4
- package/dist/index.js +0 -7
package/package.json
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nest-forge/core",
|
|
3
3
|
"description": "",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.4",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "rimraf dist && tsc -p tsconfig.json",
|
|
7
7
|
"watch": "rimraf dist && tsc -w -p tsconfig.json",
|
|
8
|
-
"format": "prettier --write \"{src,apps,libs,test}/**/*.ts\""
|
|
9
|
-
"lint": "eslint --ignore-pattern .gitignore \"{src,apps,libs,test}/**/*.ts\""
|
|
8
|
+
"format": "prettier --write \"{src,apps,libs,test}/**/*.ts\""
|
|
10
9
|
},
|
|
11
10
|
"directories": {
|
|
12
11
|
"lib": "src"
|
|
@@ -15,13 +14,12 @@
|
|
|
15
14
|
"types": "./dist/index.d.ts",
|
|
16
15
|
"keywords": [],
|
|
17
16
|
"license": "UNLICENSED",
|
|
18
|
-
"homepage": "https://github.com/nest-forge",
|
|
19
17
|
"repository": {
|
|
20
18
|
"type": "git",
|
|
21
|
-
"url": "https://github.com/nest-forge
|
|
19
|
+
"url": "https://github.com/baileyherbert/nest-forge"
|
|
22
20
|
},
|
|
23
21
|
"bugs": {
|
|
24
|
-
"url": "https://github.com/nest-forge/
|
|
22
|
+
"url": "https://github.com/baileyherbert/nest-forge/issues"
|
|
25
23
|
},
|
|
26
24
|
"author": "Bailey Herbert <hello@bailey.sh>",
|
|
27
25
|
"contributors": [],
|
|
@@ -29,17 +27,10 @@
|
|
|
29
27
|
"tslib": "^2.8.1"
|
|
30
28
|
},
|
|
31
29
|
"devDependencies": {
|
|
32
|
-
"@eslint/eslintrc": "^3.3.3",
|
|
33
|
-
"@eslint/js": "^9.39.2",
|
|
34
30
|
"@types/node": "~24.0.0",
|
|
35
|
-
"eslint": "^9.18.0",
|
|
36
|
-
"eslint-config-prettier": "^10.1.8",
|
|
37
|
-
"eslint-plugin-prettier": "^5.5.4",
|
|
38
|
-
"globals": "^16.0.0",
|
|
39
31
|
"prettier": "3.7.4",
|
|
40
32
|
"rimraf": "^6.1.2",
|
|
41
|
-
"typescript": "^5.9.0"
|
|
42
|
-
"typescript-eslint": "^8.51.0"
|
|
33
|
+
"typescript": "^5.9.0"
|
|
43
34
|
},
|
|
44
35
|
"peerDependencies": {
|
|
45
36
|
"@nestjs/common": "^10.2.0 || ^11.0.0",
|
package/README.md
DELETED
|
File without changes
|
|
@@ -1,7 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
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);
|
|
@@ -1,7 +0,0 @@
|
|
|
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;
|
|
@@ -1,7 +0,0 @@
|
|
|
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);
|
|
@@ -1,8 +0,0 @@
|
|
|
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;
|
|
@@ -1,12 +0,0 @@
|
|
|
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);
|
package/dist/constants.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
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;
|
package/dist/constants.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
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,86 +0,0 @@
|
|
|
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';
|
|
6
|
-
export declare abstract class ForgeExtension {
|
|
7
|
-
/**
|
|
8
|
-
* The metdata for this extension.
|
|
9
|
-
*/
|
|
10
|
-
private readonly _metadata;
|
|
11
|
-
/**
|
|
12
|
-
* Constructs a new forge extension instance.
|
|
13
|
-
*/
|
|
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;
|
|
21
|
-
/**
|
|
22
|
-
* Configures a Nest application instance.
|
|
23
|
-
*/
|
|
24
|
-
configureHttpApplication(application: INestApplication): any;
|
|
25
|
-
/**
|
|
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.
|
|
31
|
-
*/
|
|
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>;
|
|
45
|
-
/**
|
|
46
|
-
* Configures the root module of the application.
|
|
47
|
-
*/
|
|
48
|
-
configureRootModule(consumer: MiddlewareConsumer): any;
|
|
49
|
-
/**
|
|
50
|
-
* Runs after all services in the application have booted.
|
|
51
|
-
*/
|
|
52
|
-
afterBoot(app: INestApplicationContext): any;
|
|
53
|
-
/**
|
|
54
|
-
* Instruments the application context. If a value is returned, the instance is replaced with that value, and no further extensions are
|
|
55
|
-
* queried.
|
|
56
|
-
*/
|
|
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;
|
|
74
|
-
/**
|
|
75
|
-
* Returns the metadata for this extension.
|
|
76
|
-
*/
|
|
77
|
-
getMetadata(): ForgeExtensionMetadata;
|
|
78
|
-
}
|
|
79
|
-
export interface ForgeExtensionMetadata extends ModuleMetadata {
|
|
80
|
-
/**
|
|
81
|
-
* An optional array of nested extensions to import.
|
|
82
|
-
*/
|
|
83
|
-
extensions?: ForgeExtensionResolvable[];
|
|
84
|
-
}
|
|
85
|
-
export type ForgeExtensionResolvable = ForgeExtension | (new () => ForgeExtension) | null | undefined | false;
|
|
86
|
-
export type ForgeHttpAdapterLike = AbstractHttpAdapter | null | undefined | Promise<AbstractHttpAdapter | null | undefined>;
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ForgeExtension = void 0;
|
|
4
|
-
class ForgeExtension {
|
|
5
|
-
/**
|
|
6
|
-
* The metdata for this extension.
|
|
7
|
-
*/
|
|
8
|
-
_metadata;
|
|
9
|
-
/**
|
|
10
|
-
* Constructs a new forge extension instance.
|
|
11
|
-
*/
|
|
12
|
-
constructor(options) {
|
|
13
|
-
this._metadata = options || {};
|
|
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
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Configures a Nest application instance.
|
|
25
|
-
*/
|
|
26
|
-
configureHttpApplication(application) { }
|
|
27
|
-
/**
|
|
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.
|
|
35
|
-
*/
|
|
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
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Configures the root module of the application.
|
|
55
|
-
*/
|
|
56
|
-
configureRootModule(consumer) { }
|
|
57
|
-
/**
|
|
58
|
-
* Runs after all services in the application have booted.
|
|
59
|
-
*/
|
|
60
|
-
afterBoot(app) { }
|
|
61
|
-
/**
|
|
62
|
-
* Instruments the application context. If a value is returned, the instance is replaced with that value, and no further extensions are
|
|
63
|
-
* queried.
|
|
64
|
-
*/
|
|
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) { }
|
|
82
|
-
/**
|
|
83
|
-
* Returns the metadata for this extension.
|
|
84
|
-
*/
|
|
85
|
-
getMetadata() {
|
|
86
|
-
return this._metadata;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
exports.ForgeExtension = ForgeExtension;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './extension';
|
package/dist/extensions/index.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { NestApplicationOptions } from '@nestjs/common';
|
|
2
|
-
import { ForgeExtensionResolvable } from './extensions';
|
|
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
|
-
export interface ForgeApplicationOptions extends NestApplicationOptions {
|
|
6
|
-
extensions?: ForgeExtensionResolvable | ForgeExtensionResolvable[];
|
|
7
|
-
}
|
|
8
|
-
export interface ForgeApplicationContextOptions extends NestApplicationContextOptions {
|
|
9
|
-
extensions?: ForgeExtensionResolvable | ForgeExtensionResolvable[];
|
|
10
|
-
}
|
|
11
|
-
export interface ForgeMicroserviceOptions extends NestMicroserviceOptions {
|
|
12
|
-
extensions?: ForgeExtensionResolvable | ForgeExtensionResolvable[];
|
|
13
|
-
}
|
package/dist/forge.factory.d.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { DynamicModule, ForwardReference, INestApplication, INestApplicationContext, MiddlewareConsumer, Type } from '@nestjs/common';
|
|
2
|
-
import { ForgeApplicationContextOptions, ForgeApplicationOptions, ForgeMicroserviceOptions } from './forge-options.interface';
|
|
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';
|
|
7
|
-
declare class Forge {
|
|
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>;
|
|
13
|
-
protected discoverExtensions(resolvables: ForgeExtensionResolvable | ForgeExtensionResolvable[]): ForgeExtension[];
|
|
14
|
-
protected resolveExtension(resolvable: ForgeExtensionResolvable): ForgeExtension | null;
|
|
15
|
-
protected createRootModule(appModule: IEntryNestModule, extensions: ForgeExtension[]): {
|
|
16
|
-
new (moduleRef: ModuleRef): {
|
|
17
|
-
readonly moduleRef: ModuleRef;
|
|
18
|
-
configure(consumer: MiddlewareConsumer): Promise<void>;
|
|
19
|
-
readonly [FORGE_ROOT_MODULE]: true;
|
|
20
|
-
};
|
|
21
|
-
};
|
|
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;
|
|
32
|
-
}
|
|
33
|
-
type IEntryNestModule = Type<any> | DynamicModule | ForwardReference | Promise<IEntryNestModule>;
|
|
34
|
-
type Instrument = {
|
|
35
|
-
instanceDecorator: (instance: unknown) => unknown;
|
|
36
|
-
};
|
|
37
|
-
interface InstrumentResponse {
|
|
38
|
-
instances: ForgeBaseComponent[];
|
|
39
|
-
instanceDecorator: (instance: unknown) => any;
|
|
40
|
-
}
|
|
41
|
-
declare const forge: Forge;
|
|
42
|
-
export { forge as Forge };
|
package/dist/forge.factory.js
DELETED
|
@@ -1,281 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Forge = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const common_1 = require("@nestjs/common");
|
|
6
|
-
const core_1 = require("@nestjs/core");
|
|
7
|
-
const constants_1 = require("./constants");
|
|
8
|
-
const architecture_1 = require("./architecture");
|
|
9
|
-
class Forge {
|
|
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
|
-
{};
|
|
15
|
-
const extensions = this.discoverExtensions(options?.extensions ?? []);
|
|
16
|
-
const root = this.createRootModule(appModule, extensions);
|
|
17
|
-
const instrument = this.createInstrument(extensions, options.instrument);
|
|
18
|
-
let createOptions = {
|
|
19
|
-
...options,
|
|
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);
|
|
42
|
-
for (const extension of extensions) {
|
|
43
|
-
await extension.configureHttpApplication(app);
|
|
44
|
-
}
|
|
45
|
-
return app;
|
|
46
|
-
}
|
|
47
|
-
async createApplicationContext(appModule, options) {
|
|
48
|
-
const extensions = this.discoverExtensions(options?.extensions ?? []);
|
|
49
|
-
const root = this.createRootModule(appModule, extensions);
|
|
50
|
-
const instrument = this.createInstrument(extensions, options.instrument);
|
|
51
|
-
let createOptions = {
|
|
52
|
-
...options,
|
|
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);
|
|
68
|
-
for (const extension of extensions) {
|
|
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);
|
|
97
|
-
}
|
|
98
|
-
return app;
|
|
99
|
-
}
|
|
100
|
-
discoverExtensions(resolvables) {
|
|
101
|
-
const extensions = new Map();
|
|
102
|
-
if (!Array.isArray(resolvables)) {
|
|
103
|
-
resolvables = [resolvables];
|
|
104
|
-
}
|
|
105
|
-
for (const resolvable of resolvables) {
|
|
106
|
-
const extension = this.resolveExtension(resolvable);
|
|
107
|
-
if (extension !== null) {
|
|
108
|
-
const metadata = extension.getMetadata();
|
|
109
|
-
for (const nestedExtension of this.discoverExtensions(metadata.extensions)) {
|
|
110
|
-
extensions.delete(nestedExtension.constructor);
|
|
111
|
-
extensions.set(nestedExtension.constructor, nestedExtension);
|
|
112
|
-
}
|
|
113
|
-
extensions.delete(extension.constructor);
|
|
114
|
-
extensions.set(extension.constructor, extension);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
return Array.from(extensions.values());
|
|
118
|
-
}
|
|
119
|
-
resolveExtension(resolvable) {
|
|
120
|
-
if (resolvable === false || resolvable === null || resolvable === undefined) {
|
|
121
|
-
return null;
|
|
122
|
-
}
|
|
123
|
-
if (typeof resolvable === 'object') {
|
|
124
|
-
return resolvable;
|
|
125
|
-
}
|
|
126
|
-
if (typeof resolvable === 'function') {
|
|
127
|
-
return new resolvable();
|
|
128
|
-
}
|
|
129
|
-
throw new Error(`Unsupported extension resolvable "${String(resolvable)}"`);
|
|
130
|
-
}
|
|
131
|
-
createRootModule(appModule, extensions) {
|
|
132
|
-
const meta = {
|
|
133
|
-
imports: [],
|
|
134
|
-
controllers: [],
|
|
135
|
-
providers: [],
|
|
136
|
-
exports: [],
|
|
137
|
-
};
|
|
138
|
-
for (const extension of extensions) {
|
|
139
|
-
const extensionMeta = extension.getMetadata();
|
|
140
|
-
meta.imports.push(...(extensionMeta.imports ?? []));
|
|
141
|
-
meta.controllers.push(...(extensionMeta.controllers ?? []));
|
|
142
|
-
meta.providers.push(...(extensionMeta.providers ?? []));
|
|
143
|
-
meta.exports.push(...(extensionMeta.exports ?? []));
|
|
144
|
-
}
|
|
145
|
-
meta.imports.push(appModule);
|
|
146
|
-
let ForgeRootModule = class ForgeRootModule {
|
|
147
|
-
moduleRef;
|
|
148
|
-
[constants_1.FORGE_ROOT_MODULE] = true;
|
|
149
|
-
constructor(moduleRef) {
|
|
150
|
-
this.moduleRef = moduleRef;
|
|
151
|
-
}
|
|
152
|
-
async configure(consumer) {
|
|
153
|
-
for (const extension of extensions) {
|
|
154
|
-
await extension.configureRootModule(consumer);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
ForgeRootModule = tslib_1.__decorate([
|
|
159
|
-
(0, common_1.Module)(meta),
|
|
160
|
-
(0, common_1.Global)(),
|
|
161
|
-
tslib_1.__metadata("design:paramtypes", [core_1.ModuleRef])
|
|
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);
|
|
178
|
-
return ForgeRootModule;
|
|
179
|
-
}
|
|
180
|
-
createInstrument(extensions, originalInstrument) {
|
|
181
|
-
const hasOriginalInstrument = originalInstrument && originalInstrument.instanceDecorator;
|
|
182
|
-
const instances = new Array();
|
|
183
|
-
return {
|
|
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
|
-
}
|
|
192
|
-
for (const extension of extensions) {
|
|
193
|
-
const response = extension.instrument(instance);
|
|
194
|
-
if (response !== undefined) {
|
|
195
|
-
return response;
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
if (hasOriginalInstrument) {
|
|
199
|
-
return originalInstrument.instanceDecorator(instance);
|
|
200
|
-
}
|
|
201
|
-
return instance;
|
|
202
|
-
},
|
|
203
|
-
};
|
|
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
|
-
}
|
|
279
|
-
}
|
|
280
|
-
const forge = new Forge();
|
|
281
|
-
exports.Forge = forge;
|
package/dist/index.d.ts
DELETED
package/dist/index.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./forge.factory"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./forge-options.interface"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./extensions"), exports);
|
|
7
|
-
tslib_1.__exportStar(require("./architecture"), exports);
|