@nest-forge/core 0.0.3 → 0.0.5
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/dist/constants-public.d.ts +2 -0
- package/dist/constants-public.js +5 -0
- package/dist/constants.d.ts +0 -1
- package/dist/constants.js +1 -2
- package/dist/extensions/extension.d.ts +23 -17
- package/dist/extensions/extension.js +27 -13
- package/dist/forge.factory.d.ts +14 -7
- package/dist/forge.factory.js +35 -20
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +11 -16
- package/README.md +0 -0
package/dist/constants.d.ts
CHANGED
package/dist/constants.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
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 =
|
|
4
|
-
exports.FORGE_ROOT_MODULE = Symbol('FORGE_ROOT_MODULE');
|
|
3
|
+
exports.FORGE_PATCH_ENABLE_INIT = exports.FORGE_PATCH_BOOT_CALLBACK = exports.FORGE_PATCHED = exports.FORGE_TOKEN_ROOT_MODULE = exports.FORGE_FIELD_MODULE_REF = void 0;
|
|
5
4
|
exports.FORGE_FIELD_MODULE_REF = Symbol('FORGE_FIELD_MODULE_REF');
|
|
6
5
|
exports.FORGE_TOKEN_ROOT_MODULE = Symbol('FORGE_TOKEN_ROOT_MODULE');
|
|
7
6
|
exports.FORGE_PATCHED = Symbol('FORGE_PATCHED');
|
|
@@ -1,17 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { INestApplicationContext, INestMicroservice, MiddlewareConsumer, ModuleMetadata, NestApplicationOptions } from '@nestjs/common';
|
|
2
2
|
import { ForgeBaseComponent, ForgeController, ForgeModule, ForgeService } from '../architecture';
|
|
3
3
|
import { NestApplicationContextOptions } from '@nestjs/common/interfaces/nest-application-context-options.interface';
|
|
4
4
|
import { NestMicroserviceOptions } from '@nestjs/common/interfaces/microservices/nest-microservice-options.interface';
|
|
5
|
-
import { AbstractHttpAdapter } from '@nestjs/core';
|
|
5
|
+
import { AbstractHttpAdapter, NestApplication } from '@nestjs/core';
|
|
6
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
7
|
/**
|
|
16
8
|
* Configures the HTTP adapter to use for the Nest application instance.
|
|
17
9
|
*
|
|
@@ -21,7 +13,7 @@ export declare abstract class ForgeExtension {
|
|
|
21
13
|
/**
|
|
22
14
|
* Configures a Nest application instance.
|
|
23
15
|
*/
|
|
24
|
-
configureHttpApplication(application:
|
|
16
|
+
configureHttpApplication(application: NestApplication): any;
|
|
25
17
|
/**
|
|
26
18
|
* Configures the options object for a Nest application instance.
|
|
27
19
|
*/
|
|
@@ -72,15 +64,29 @@ export declare abstract class ForgeExtension {
|
|
|
72
64
|
*/
|
|
73
65
|
augmentService(instance: ForgeService, moduleRef: any): any;
|
|
74
66
|
/**
|
|
75
|
-
* Returns
|
|
67
|
+
* Returns an array of imports to add onto the root module.
|
|
76
68
|
*/
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
69
|
+
getRootImports(): ModuleImport[];
|
|
70
|
+
/**
|
|
71
|
+
* Returns an array of providers to add onto the root module.
|
|
72
|
+
*/
|
|
73
|
+
getRootProviders(): ModuleProvider[];
|
|
74
|
+
/**
|
|
75
|
+
* Returns an array of controllers to add onto the root module.
|
|
76
|
+
*/
|
|
77
|
+
getRootControllers(): ModuleController[];
|
|
78
|
+
/**
|
|
79
|
+
* Returns an array of exports to add onto the root module.
|
|
80
|
+
*/
|
|
81
|
+
getRootExports(): ModuleExport[];
|
|
80
82
|
/**
|
|
81
|
-
*
|
|
83
|
+
* Returns an array of nested extensions that will be imported along with this one.
|
|
82
84
|
*/
|
|
83
|
-
|
|
85
|
+
getNestedExtensions(): ForgeExtensionResolvable[];
|
|
84
86
|
}
|
|
87
|
+
export type ModuleImport = NonNullable<ModuleMetadata['imports']>[number];
|
|
88
|
+
export type ModuleProvider = NonNullable<ModuleMetadata['providers']>[number];
|
|
89
|
+
export type ModuleController = NonNullable<ModuleMetadata['controllers']>[number];
|
|
90
|
+
export type ModuleExport = NonNullable<ModuleMetadata['exports']>[number];
|
|
85
91
|
export type ForgeExtensionResolvable = ForgeExtension | (new () => ForgeExtension) | null | undefined | false;
|
|
86
92
|
export type ForgeHttpAdapterLike = AbstractHttpAdapter | null | undefined | Promise<AbstractHttpAdapter | null | undefined>;
|
|
@@ -2,16 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ForgeExtension = void 0;
|
|
4
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
5
|
/**
|
|
16
6
|
* Configures the HTTP adapter to use for the Nest application instance.
|
|
17
7
|
*
|
|
@@ -80,10 +70,34 @@ class ForgeExtension {
|
|
|
80
70
|
*/
|
|
81
71
|
augmentService(instance, moduleRef) { }
|
|
82
72
|
/**
|
|
83
|
-
* Returns
|
|
73
|
+
* Returns an array of imports to add onto the root module.
|
|
74
|
+
*/
|
|
75
|
+
getRootImports() {
|
|
76
|
+
return [];
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Returns an array of providers to add onto the root module.
|
|
80
|
+
*/
|
|
81
|
+
getRootProviders() {
|
|
82
|
+
return [];
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Returns an array of controllers to add onto the root module.
|
|
86
|
+
*/
|
|
87
|
+
getRootControllers() {
|
|
88
|
+
return [];
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Returns an array of exports to add onto the root module.
|
|
92
|
+
*/
|
|
93
|
+
getRootExports() {
|
|
94
|
+
return [];
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Returns an array of nested extensions that will be imported along with this one.
|
|
84
98
|
*/
|
|
85
|
-
|
|
86
|
-
return
|
|
99
|
+
getNestedExtensions() {
|
|
100
|
+
return [];
|
|
87
101
|
}
|
|
88
102
|
}
|
|
89
103
|
exports.ForgeExtension = ForgeExtension;
|
package/dist/forge.factory.d.ts
CHANGED
|
@@ -1,24 +1,25 @@
|
|
|
1
|
-
import { DynamicModule, ForwardReference, INestApplication, INestApplicationContext, MiddlewareConsumer, Type } from '@nestjs/common';
|
|
1
|
+
import { DynamicModule, ForwardReference, INestApplication, INestApplicationContext, MiddlewareConsumer, ModuleMetadata, Type } from '@nestjs/common';
|
|
2
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';
|
|
4
|
+
import { AbstractHttpAdapter, ModuleRef, NestApplication } from '@nestjs/core';
|
|
6
5
|
import { ForgeBaseComponent, ForgeController, ForgeModule, ForgeService } from './architecture';
|
|
6
|
+
import { FORGE_ROOT_MODULE } from './constants-public';
|
|
7
7
|
declare class Forge {
|
|
8
8
|
private _augmented;
|
|
9
|
-
create<T extends INestApplication =
|
|
10
|
-
create<T extends INestApplication =
|
|
9
|
+
create<T extends INestApplication = NestApplication>(appModule: IEntryNestModule, options?: ForgeApplicationOptions): Promise<T>;
|
|
10
|
+
create<T extends INestApplication = NestApplication>(appModule: IEntryNestModule, httpAdapter: AbstractHttpAdapter, options?: ForgeApplicationOptions): Promise<T>;
|
|
11
11
|
createApplicationContext(appModule: IEntryNestModule, options: ForgeApplicationContextOptions): Promise<INestApplicationContext>;
|
|
12
12
|
createMicroservice<T extends object>(appModule: IEntryNestModule, options: ForgeMicroserviceOptions & T): Promise<import("@nestjs/common").INestMicroservice>;
|
|
13
13
|
protected discoverExtensions(resolvables: ForgeExtensionResolvable | ForgeExtensionResolvable[]): ForgeExtension[];
|
|
14
14
|
protected resolveExtension(resolvable: ForgeExtensionResolvable): ForgeExtension | null;
|
|
15
|
-
protected createRootModule(appModule: IEntryNestModule, extensions: ForgeExtension[]): {
|
|
15
|
+
protected createRootModule(appModule: IEntryNestModule, extensions: ForgeExtension[], options: any): Promise<{
|
|
16
16
|
new (moduleRef: ModuleRef): {
|
|
17
17
|
readonly moduleRef: ModuleRef;
|
|
18
18
|
configure(consumer: MiddlewareConsumer): Promise<void>;
|
|
19
19
|
readonly [FORGE_ROOT_MODULE]: true;
|
|
20
20
|
};
|
|
21
|
-
}
|
|
21
|
+
}>;
|
|
22
|
+
protected _getExtensionMetadata(extension: ForgeExtension): Promise<ExtensionMetadata>;
|
|
22
23
|
protected createInstrument(extensions: ForgeExtension[], originalInstrument?: Instrument): InstrumentResponse;
|
|
23
24
|
protected augmentComponents(instances: ForgeBaseComponent[], extensions: ForgeExtension[]): Promise<void>;
|
|
24
25
|
protected augmentComponent(instance: ForgeBaseComponent, extensions: ForgeExtension[]): Promise<void>;
|
|
@@ -34,9 +35,15 @@ type IEntryNestModule = Type<any> | DynamicModule | ForwardReference | Promise<I
|
|
|
34
35
|
type Instrument = {
|
|
35
36
|
instanceDecorator: (instance: unknown) => unknown;
|
|
36
37
|
};
|
|
38
|
+
type NonNullableFields<T> = {
|
|
39
|
+
[P in keyof T]-?: NonNullable<T[P]>;
|
|
40
|
+
};
|
|
37
41
|
interface InstrumentResponse {
|
|
38
42
|
instances: ForgeBaseComponent[];
|
|
39
43
|
instanceDecorator: (instance: unknown) => any;
|
|
40
44
|
}
|
|
45
|
+
interface ExtensionMetadata extends NonNullableFields<ModuleMetadata> {
|
|
46
|
+
extensions: ForgeExtensionResolvable[];
|
|
47
|
+
}
|
|
41
48
|
declare const forge: Forge;
|
|
42
49
|
export { forge as Forge };
|
package/dist/forge.factory.js
CHANGED
|
@@ -6,6 +6,7 @@ const common_1 = require("@nestjs/common");
|
|
|
6
6
|
const core_1 = require("@nestjs/core");
|
|
7
7
|
const constants_1 = require("./constants");
|
|
8
8
|
const architecture_1 = require("./architecture");
|
|
9
|
+
const constants_public_1 = require("./constants-public");
|
|
9
10
|
class Forge {
|
|
10
11
|
_augmented = new Set();
|
|
11
12
|
async create(appModule, optionsOrHttpAdapter, optionsFallback) {
|
|
@@ -13,7 +14,7 @@ class Forge {
|
|
|
13
14
|
const options = (typeof optionsFallback === 'object' ? optionsFallback : adapter ? {} : optionsOrHttpAdapter) ??
|
|
14
15
|
{};
|
|
15
16
|
const extensions = this.discoverExtensions(options?.extensions ?? []);
|
|
16
|
-
const root = this.createRootModule(appModule, extensions);
|
|
17
|
+
const root = await this.createRootModule(appModule, extensions, options);
|
|
17
18
|
const instrument = this.createInstrument(extensions, options.instrument);
|
|
18
19
|
let createOptions = {
|
|
19
20
|
...options,
|
|
@@ -46,7 +47,7 @@ class Forge {
|
|
|
46
47
|
}
|
|
47
48
|
async createApplicationContext(appModule, options) {
|
|
48
49
|
const extensions = this.discoverExtensions(options?.extensions ?? []);
|
|
49
|
-
const root = this.createRootModule(appModule, extensions);
|
|
50
|
+
const root = this.createRootModule(appModule, extensions, options);
|
|
50
51
|
const instrument = this.createInstrument(extensions, options.instrument);
|
|
51
52
|
let createOptions = {
|
|
52
53
|
...options,
|
|
@@ -74,7 +75,7 @@ class Forge {
|
|
|
74
75
|
}
|
|
75
76
|
async createMicroservice(appModule, options) {
|
|
76
77
|
const extensions = this.discoverExtensions(options?.extensions ?? []);
|
|
77
|
-
const root = this.createRootModule(appModule, extensions);
|
|
78
|
+
const root = this.createRootModule(appModule, extensions, options);
|
|
78
79
|
const instrument = this.createInstrument(extensions, options.instrument);
|
|
79
80
|
let createOptions = {
|
|
80
81
|
...options,
|
|
@@ -105,8 +106,7 @@ class Forge {
|
|
|
105
106
|
for (const resolvable of resolvables) {
|
|
106
107
|
const extension = this.resolveExtension(resolvable);
|
|
107
108
|
if (extension !== null) {
|
|
108
|
-
const
|
|
109
|
-
for (const nestedExtension of this.discoverExtensions(metadata.extensions)) {
|
|
109
|
+
for (const nestedExtension of this.discoverExtensions(extension.getNestedExtensions())) {
|
|
110
110
|
extensions.delete(nestedExtension.constructor);
|
|
111
111
|
extensions.set(nestedExtension.constructor, nestedExtension);
|
|
112
112
|
}
|
|
@@ -128,7 +128,7 @@ class Forge {
|
|
|
128
128
|
}
|
|
129
129
|
throw new Error(`Unsupported extension resolvable "${String(resolvable)}"`);
|
|
130
130
|
}
|
|
131
|
-
createRootModule(appModule, extensions) {
|
|
131
|
+
async createRootModule(appModule, extensions, options) {
|
|
132
132
|
const meta = {
|
|
133
133
|
imports: [],
|
|
134
134
|
controllers: [],
|
|
@@ -136,16 +136,16 @@ class Forge {
|
|
|
136
136
|
exports: [],
|
|
137
137
|
};
|
|
138
138
|
for (const extension of extensions) {
|
|
139
|
-
const extensionMeta =
|
|
140
|
-
meta.imports.push(...
|
|
141
|
-
meta.controllers.push(...
|
|
142
|
-
meta.providers.push(...
|
|
143
|
-
meta.exports.push(...
|
|
139
|
+
const extensionMeta = await this._getExtensionMetadata(extension);
|
|
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
144
|
}
|
|
145
145
|
meta.imports.push(appModule);
|
|
146
146
|
let ForgeRootModule = class ForgeRootModule {
|
|
147
147
|
moduleRef;
|
|
148
|
-
[
|
|
148
|
+
[constants_public_1.FORGE_ROOT_MODULE] = true;
|
|
149
149
|
constructor(moduleRef) {
|
|
150
150
|
this.moduleRef = moduleRef;
|
|
151
151
|
}
|
|
@@ -170,13 +170,33 @@ class Forge {
|
|
|
170
170
|
provide: constants_1.FORGE_TOKEN_ROOT_MODULE,
|
|
171
171
|
useClass: ForgeRootModule,
|
|
172
172
|
},
|
|
173
|
+
{
|
|
174
|
+
provide: constants_public_1.FORGE_APP_OPTIONS,
|
|
175
|
+
useValue: options,
|
|
176
|
+
},
|
|
173
177
|
],
|
|
174
|
-
exports: [constants_1.FORGE_TOKEN_ROOT_MODULE],
|
|
178
|
+
exports: [constants_1.FORGE_TOKEN_ROOT_MODULE, constants_public_1.FORGE_APP_OPTIONS],
|
|
175
179
|
})
|
|
176
180
|
], ForgeRootProviderModule);
|
|
177
181
|
meta.imports.unshift(ForgeRootProviderModule);
|
|
178
182
|
return ForgeRootModule;
|
|
179
183
|
}
|
|
184
|
+
async _getExtensionMetadata(extension) {
|
|
185
|
+
const results = await Promise.all([
|
|
186
|
+
extension.getRootImports(),
|
|
187
|
+
extension.getRootProviders(),
|
|
188
|
+
extension.getRootExports(),
|
|
189
|
+
extension.getRootControllers(),
|
|
190
|
+
extension.getNestedExtensions(),
|
|
191
|
+
]);
|
|
192
|
+
return {
|
|
193
|
+
imports: results[0],
|
|
194
|
+
providers: results[1],
|
|
195
|
+
exports: results[2],
|
|
196
|
+
controllers: results[3],
|
|
197
|
+
extensions: results[4],
|
|
198
|
+
};
|
|
199
|
+
}
|
|
180
200
|
createInstrument(extensions, originalInstrument) {
|
|
181
201
|
const hasOriginalInstrument = originalInstrument && originalInstrument.instanceDecorator;
|
|
182
202
|
const instances = new Array();
|
|
@@ -240,19 +260,14 @@ class Forge {
|
|
|
240
260
|
}
|
|
241
261
|
}
|
|
242
262
|
_isRootModule(instance) {
|
|
243
|
-
return typeof instance === 'object' && instance !== null && instance[
|
|
263
|
+
return typeof instance === 'object' && instance !== null && instance[constants_public_1.FORGE_ROOT_MODULE] === true;
|
|
244
264
|
}
|
|
245
265
|
_isHttpAdapter(instance) {
|
|
246
266
|
return typeof instance === 'object' && instance !== null && typeof instance['use'] === 'function';
|
|
247
267
|
}
|
|
248
268
|
_augmentBootHooks(createOptions, extensions) {
|
|
249
269
|
createOptions[constants_1.FORGE_PATCH_BOOT_CALLBACK] = async (app) => {
|
|
250
|
-
|
|
251
|
-
await Promise.all(extensions.map((e) => e.afterBoot(app)));
|
|
252
|
-
}
|
|
253
|
-
catch (error) {
|
|
254
|
-
console.error(error);
|
|
255
|
-
}
|
|
270
|
+
await Promise.all(extensions.map((e) => e.afterBoot(app)));
|
|
256
271
|
};
|
|
257
272
|
}
|
|
258
273
|
_augmentNestApplication() {
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -5,3 +5,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
7
|
tslib_1.__exportStar(require("./architecture"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./constants-public"), exports);
|
package/package.json
CHANGED
|
@@ -1,27 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nest-forge/core",
|
|
3
3
|
"description": "",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.5",
|
|
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
|
},
|
|
10
|
+
"main": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
11
12
|
"directories": {
|
|
12
13
|
"lib": "src"
|
|
13
14
|
},
|
|
14
|
-
"
|
|
15
|
-
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"tsconfig.json"
|
|
18
|
+
],
|
|
16
19
|
"keywords": [],
|
|
17
20
|
"license": "UNLICENSED",
|
|
18
|
-
"homepage": "https://github.com/nest-forge",
|
|
19
21
|
"repository": {
|
|
20
22
|
"type": "git",
|
|
21
|
-
"url": "https://github.com/nest-forge
|
|
23
|
+
"url": "git+https://github.com/baileyherbert/nest-forge.git"
|
|
22
24
|
},
|
|
23
25
|
"bugs": {
|
|
24
|
-
"url": "https://github.com/nest-forge/
|
|
26
|
+
"url": "https://github.com/baileyherbert/nest-forge/issues"
|
|
25
27
|
},
|
|
26
28
|
"author": "Bailey Herbert <hello@bailey.sh>",
|
|
27
29
|
"contributors": [],
|
|
@@ -29,17 +31,10 @@
|
|
|
29
31
|
"tslib": "^2.8.1"
|
|
30
32
|
},
|
|
31
33
|
"devDependencies": {
|
|
32
|
-
"@eslint/eslintrc": "^3.3.3",
|
|
33
|
-
"@eslint/js": "^9.39.2",
|
|
34
34
|
"@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
35
|
"prettier": "3.7.4",
|
|
40
36
|
"rimraf": "^6.1.2",
|
|
41
|
-
"typescript": "^5.9.0"
|
|
42
|
-
"typescript-eslint": "^8.51.0"
|
|
37
|
+
"typescript": "^5.9.0"
|
|
43
38
|
},
|
|
44
39
|
"peerDependencies": {
|
|
45
40
|
"@nestjs/common": "^10.2.0 || ^11.0.0",
|
package/README.md
DELETED
|
File without changes
|