@opra/nestjs 0.24.2 → 0.25.0
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/cjs/constants.js +3 -1
- package/cjs/index.js +1 -0
- package/cjs/opra-core.module.js +33 -16
- package/cjs/opra-module-ref.js +16 -0
- package/cjs/services/opra-api-loader.js +13 -9
- package/esm/constants.js +2 -0
- package/esm/index.js +1 -0
- package/esm/opra-core.module.js +34 -17
- package/esm/opra-module-ref.js +12 -0
- package/esm/services/opra-api-loader.js +14 -10
- package/package.json +6 -12
- package/types/constants.d.ts +2 -0
- package/types/index.d.ts +1 -0
- package/types/interfaces/opra-module-options.interface.d.ts +6 -2
- package/types/opra-core.module.d.ts +2 -2
- package/types/opra-module-ref.d.ts +11 -0
- package/types/services/opra-api-loader.d.ts +5 -4
package/cjs/constants.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PARAM_ARGS_METADATA = exports.OPRA_INITIALIZER = exports.OPRA_MODULE_ID = exports.OPRA_MODULE_OPTIONS = void 0;
|
|
3
|
+
exports.PARAM_ARGS_METADATA = exports.kAdapter = exports.kOptions = exports.OPRA_INITIALIZER = exports.OPRA_MODULE_ID = exports.OPRA_MODULE_OPTIONS = void 0;
|
|
4
4
|
exports.OPRA_MODULE_OPTIONS = 'opra:module_options';
|
|
5
5
|
exports.OPRA_MODULE_ID = 'opra:module_id';
|
|
6
6
|
exports.OPRA_INITIALIZER = 'opra_initializer';
|
|
7
|
+
exports.kOptions = Symbol('kOptions');
|
|
8
|
+
exports.kAdapter = Symbol('kAdapter');
|
|
7
9
|
exports.PARAM_ARGS_METADATA = '__routeArguments__';
|
package/cjs/index.js
CHANGED
|
@@ -6,3 +6,4 @@ require("./augmentation/common-decorator.augmentation.js");
|
|
|
6
6
|
tslib_1.__exportStar(require("./opra.module.js"), exports);
|
|
7
7
|
tslib_1.__exportStar(require("./decorators/context.decorator.js"), exports);
|
|
8
8
|
tslib_1.__exportStar(require("./interfaces/opra-module-options.interface.js"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./opra-module-ref.js"), exports);
|
package/cjs/opra-core.module.js
CHANGED
|
@@ -9,31 +9,40 @@ const core_1 = require("@nestjs/core");
|
|
|
9
9
|
const metadata_scanner_1 = require("@nestjs/core/metadata-scanner");
|
|
10
10
|
const constants_js_1 = require("./constants.js");
|
|
11
11
|
const opra_api_factory_js_1 = require("./factories/opra-api.factory.js");
|
|
12
|
+
const opra_module_ref_js_1 = require("./opra-module-ref.js");
|
|
12
13
|
const nest_explorer_js_1 = require("./services/nest-explorer.js");
|
|
13
14
|
const opra_api_loader_js_1 = require("./services/opra-api-loader.js");
|
|
14
15
|
let OpraCoreModule = exports.OpraCoreModule = OpraCoreModule_1 = class OpraCoreModule {
|
|
15
|
-
constructor(httpAdapterHost, modulesContainer, options,
|
|
16
|
+
constructor(httpAdapterHost, modulesContainer, options, apiLoader) {
|
|
16
17
|
this.httpAdapterHost = httpAdapterHost;
|
|
17
18
|
this.modulesContainer = modulesContainer;
|
|
18
19
|
this.options = options;
|
|
19
|
-
this.
|
|
20
|
+
this.apiLoader = apiLoader;
|
|
20
21
|
}
|
|
21
22
|
static forRoot(options) {
|
|
23
|
+
const providers = [
|
|
24
|
+
...(options.providers || []),
|
|
25
|
+
{
|
|
26
|
+
provide: constants_js_1.OPRA_MODULE_OPTIONS,
|
|
27
|
+
useValue: options,
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
provide: constants_js_1.OPRA_INITIALIZER,
|
|
31
|
+
useClass: opra_api_loader_js_1.OpraApiLoader
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
provide: options.id || opra_module_ref_js_1.OpraModuleRef,
|
|
35
|
+
inject: [constants_js_1.OPRA_INITIALIZER],
|
|
36
|
+
useFactory: (apiLoader) => {
|
|
37
|
+
return apiLoader.opraModuleRef;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
];
|
|
22
41
|
return {
|
|
23
42
|
module: OpraCoreModule_1,
|
|
24
43
|
imports: [...(options.imports || [])],
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
{
|
|
28
|
-
provide: constants_js_1.OPRA_MODULE_OPTIONS,
|
|
29
|
-
useValue: options,
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
provide: constants_js_1.OPRA_INITIALIZER,
|
|
33
|
-
useClass: opra_api_loader_js_1.OpraApiLoader
|
|
34
|
-
}
|
|
35
|
-
],
|
|
36
|
-
exports: [...(options.exports || [])]
|
|
44
|
+
exports: [...(options.exports || [])],
|
|
45
|
+
providers
|
|
37
46
|
};
|
|
38
47
|
}
|
|
39
48
|
static forRootAsync(asyncOptions) {
|
|
@@ -50,6 +59,13 @@ let OpraCoreModule = exports.OpraCoreModule = OpraCoreModule_1 = class OpraCoreM
|
|
|
50
59
|
provide: constants_js_1.OPRA_INITIALIZER,
|
|
51
60
|
useClass: opra_api_loader_js_1.OpraApiLoader
|
|
52
61
|
},
|
|
62
|
+
{
|
|
63
|
+
provide: asyncOptions.id || opra_module_ref_js_1.OpraModuleRef,
|
|
64
|
+
inject: [constants_js_1.OPRA_INITIALIZER],
|
|
65
|
+
useFactory: (apiLoader) => {
|
|
66
|
+
return apiLoader.opraModuleRef;
|
|
67
|
+
}
|
|
68
|
+
},
|
|
53
69
|
...this.createAsyncProviders(asyncOptions)
|
|
54
70
|
]
|
|
55
71
|
};
|
|
@@ -100,11 +116,11 @@ let OpraCoreModule = exports.OpraCoreModule = OpraCoreModule_1 = class OpraCoreM
|
|
|
100
116
|
}
|
|
101
117
|
})();
|
|
102
118
|
if (opraModule) {
|
|
103
|
-
await this.
|
|
119
|
+
await this.apiLoader.initialize(opraModule);
|
|
104
120
|
}
|
|
105
121
|
}
|
|
106
122
|
async onModuleDestroy() {
|
|
107
|
-
await this.
|
|
123
|
+
await this.apiLoader.stop();
|
|
108
124
|
}
|
|
109
125
|
};
|
|
110
126
|
exports.OpraCoreModule = OpraCoreModule = OpraCoreModule_1 = tslib_1.__decorate([
|
|
@@ -115,6 +131,7 @@ exports.OpraCoreModule = OpraCoreModule = OpraCoreModule_1 = tslib_1.__decorate(
|
|
|
115
131
|
nest_explorer_js_1.NestExplorer
|
|
116
132
|
]
|
|
117
133
|
}),
|
|
134
|
+
(0, common_1.Global)(),
|
|
118
135
|
tslib_1.__param(2, (0, common_1.Inject)(constants_js_1.OPRA_MODULE_OPTIONS)),
|
|
119
136
|
tslib_1.__param(3, (0, common_1.Inject)(constants_js_1.OPRA_INITIALIZER)),
|
|
120
137
|
tslib_1.__metadata("design:paramtypes", [core_1.HttpAdapterHost,
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OpraModuleRef = void 0;
|
|
4
|
+
const constants_js_1 = require("./constants.js");
|
|
5
|
+
class OpraModuleRef {
|
|
6
|
+
get adapter() {
|
|
7
|
+
return this[constants_js_1.kAdapter];
|
|
8
|
+
}
|
|
9
|
+
get api() {
|
|
10
|
+
return this[constants_js_1.kAdapter].api;
|
|
11
|
+
}
|
|
12
|
+
get options() {
|
|
13
|
+
return this[constants_js_1.kOptions];
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.OpraModuleRef = OpraModuleRef;
|
|
@@ -8,15 +8,18 @@ const common_2 = require("@opra/common");
|
|
|
8
8
|
const core_2 = require("@opra/core");
|
|
9
9
|
const constants_js_1 = require("../constants.js");
|
|
10
10
|
const opra_api_factory_js_1 = require("../factories/opra-api.factory.js");
|
|
11
|
+
const opra_module_ref_js_1 = require("../opra-module-ref.js");
|
|
11
12
|
class OpraApiLoader {
|
|
12
13
|
constructor() {
|
|
13
14
|
this.logger = new common_1.Logger(OpraApiLoader.name, { timestamp: true });
|
|
15
|
+
this.opraModuleRef = new opra_module_ref_js_1.OpraModuleRef();
|
|
14
16
|
}
|
|
15
17
|
async initialize(rootModule) {
|
|
16
18
|
const httpAdapter = this.httpAdapterHost?.httpAdapter;
|
|
17
19
|
const globalPrefix = this.applicationConfig.getGlobalPrefix();
|
|
18
20
|
const platformName = httpAdapter.getType();
|
|
19
|
-
const moduleOptions = this.
|
|
21
|
+
const moduleOptions = this.options;
|
|
22
|
+
this.opraModuleRef[constants_js_1.kOptions] = this.options;
|
|
20
23
|
let prefixPath = new common_2.OpraURLPath((moduleOptions.useGlobalPrefix !== false ? globalPrefix : ''));
|
|
21
24
|
if (moduleOptions.basePath)
|
|
22
25
|
prefixPath = prefixPath.join(moduleOptions.basePath);
|
|
@@ -26,13 +29,13 @@ class OpraApiLoader {
|
|
|
26
29
|
basePath: prefixPath.toString()
|
|
27
30
|
};
|
|
28
31
|
try {
|
|
29
|
-
const
|
|
30
|
-
if (!
|
|
32
|
+
const apiDocument = await this.opraFactory.generateService(rootModule, options, 'http');
|
|
33
|
+
if (!apiDocument.resources.size) {
|
|
31
34
|
this.logger.warn(`No Sources found (${name})`);
|
|
32
35
|
return;
|
|
33
36
|
}
|
|
34
37
|
if (platformName === 'express') {
|
|
35
|
-
this.
|
|
38
|
+
this.opraModuleRef[constants_js_1.kAdapter] = await this.registerExpress(apiDocument, options);
|
|
36
39
|
// else if (platformName === 'fastify')
|
|
37
40
|
// await this.registerFastify();
|
|
38
41
|
}
|
|
@@ -49,13 +52,14 @@ class OpraApiLoader {
|
|
|
49
52
|
async stop() {
|
|
50
53
|
//
|
|
51
54
|
}
|
|
52
|
-
async registerExpress(
|
|
55
|
+
async registerExpress(apiDocument, moduleOptions) {
|
|
53
56
|
const httpAdapter = this.httpAdapterHost.httpAdapter;
|
|
57
|
+
/* istanbul ignore next */
|
|
54
58
|
if (!httpAdapter)
|
|
55
|
-
|
|
59
|
+
throw new Error('HttpAdapterHost is not initialized');
|
|
56
60
|
const app = httpAdapter.getInstance();
|
|
57
|
-
const logger = moduleOptions.logger || new common_1.Logger(
|
|
58
|
-
return await core_2.ExpressAdapter.create(app,
|
|
61
|
+
const logger = moduleOptions.logger || new common_1.Logger(apiDocument.info.title);
|
|
62
|
+
return await core_2.ExpressAdapter.create(app, apiDocument, {
|
|
59
63
|
...moduleOptions,
|
|
60
64
|
logger,
|
|
61
65
|
});
|
|
@@ -77,4 +81,4 @@ tslib_1.__decorate([
|
|
|
77
81
|
tslib_1.__decorate([
|
|
78
82
|
(0, common_1.Inject)(constants_js_1.OPRA_MODULE_OPTIONS),
|
|
79
83
|
tslib_1.__metadata("design:type", Object)
|
|
80
|
-
], OpraApiLoader.prototype, "
|
|
84
|
+
], OpraApiLoader.prototype, "options", void 0);
|
package/esm/constants.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export const OPRA_MODULE_OPTIONS = 'opra:module_options';
|
|
2
2
|
export const OPRA_MODULE_ID = 'opra:module_id';
|
|
3
3
|
export const OPRA_INITIALIZER = 'opra_initializer';
|
|
4
|
+
export const kOptions = Symbol('kOptions');
|
|
5
|
+
export const kAdapter = Symbol('kAdapter');
|
|
4
6
|
export const PARAM_ARGS_METADATA = '__routeArguments__';
|
package/esm/index.js
CHANGED
package/esm/opra-core.module.js
CHANGED
|
@@ -1,36 +1,45 @@
|
|
|
1
1
|
var OpraCoreModule_1;
|
|
2
2
|
import { __decorate, __metadata, __param } from "tslib";
|
|
3
3
|
import * as crypto from 'crypto';
|
|
4
|
-
import { Inject, Module } from '@nestjs/common';
|
|
4
|
+
import { Global, Inject, Module } from '@nestjs/common';
|
|
5
5
|
import { HttpAdapterHost, ModulesContainer } from '@nestjs/core';
|
|
6
6
|
import { MetadataScanner } from '@nestjs/core/metadata-scanner';
|
|
7
7
|
import { OPRA_INITIALIZER, OPRA_MODULE_ID, OPRA_MODULE_OPTIONS } from './constants.js';
|
|
8
8
|
import { OpraApiFactory } from './factories/opra-api.factory.js';
|
|
9
|
+
import { OpraModuleRef } from './opra-module-ref.js';
|
|
9
10
|
import { NestExplorer } from './services/nest-explorer.js';
|
|
10
11
|
import { OpraApiLoader } from './services/opra-api-loader.js';
|
|
11
12
|
export let OpraCoreModule = OpraCoreModule_1 = class OpraCoreModule {
|
|
12
|
-
constructor(httpAdapterHost, modulesContainer, options,
|
|
13
|
+
constructor(httpAdapterHost, modulesContainer, options, apiLoader) {
|
|
13
14
|
this.httpAdapterHost = httpAdapterHost;
|
|
14
15
|
this.modulesContainer = modulesContainer;
|
|
15
16
|
this.options = options;
|
|
16
|
-
this.
|
|
17
|
+
this.apiLoader = apiLoader;
|
|
17
18
|
}
|
|
18
19
|
static forRoot(options) {
|
|
20
|
+
const providers = [
|
|
21
|
+
...(options.providers || []),
|
|
22
|
+
{
|
|
23
|
+
provide: OPRA_MODULE_OPTIONS,
|
|
24
|
+
useValue: options,
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
provide: OPRA_INITIALIZER,
|
|
28
|
+
useClass: OpraApiLoader
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
provide: options.id || OpraModuleRef,
|
|
32
|
+
inject: [OPRA_INITIALIZER],
|
|
33
|
+
useFactory: (apiLoader) => {
|
|
34
|
+
return apiLoader.opraModuleRef;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
];
|
|
19
38
|
return {
|
|
20
39
|
module: OpraCoreModule_1,
|
|
21
40
|
imports: [...(options.imports || [])],
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
{
|
|
25
|
-
provide: OPRA_MODULE_OPTIONS,
|
|
26
|
-
useValue: options,
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
provide: OPRA_INITIALIZER,
|
|
30
|
-
useClass: OpraApiLoader
|
|
31
|
-
}
|
|
32
|
-
],
|
|
33
|
-
exports: [...(options.exports || [])]
|
|
41
|
+
exports: [...(options.exports || [])],
|
|
42
|
+
providers
|
|
34
43
|
};
|
|
35
44
|
}
|
|
36
45
|
static forRootAsync(asyncOptions) {
|
|
@@ -47,6 +56,13 @@ export let OpraCoreModule = OpraCoreModule_1 = class OpraCoreModule {
|
|
|
47
56
|
provide: OPRA_INITIALIZER,
|
|
48
57
|
useClass: OpraApiLoader
|
|
49
58
|
},
|
|
59
|
+
{
|
|
60
|
+
provide: asyncOptions.id || OpraModuleRef,
|
|
61
|
+
inject: [OPRA_INITIALIZER],
|
|
62
|
+
useFactory: (apiLoader) => {
|
|
63
|
+
return apiLoader.opraModuleRef;
|
|
64
|
+
}
|
|
65
|
+
},
|
|
50
66
|
...this.createAsyncProviders(asyncOptions)
|
|
51
67
|
]
|
|
52
68
|
};
|
|
@@ -97,11 +113,11 @@ export let OpraCoreModule = OpraCoreModule_1 = class OpraCoreModule {
|
|
|
97
113
|
}
|
|
98
114
|
})();
|
|
99
115
|
if (opraModule) {
|
|
100
|
-
await this.
|
|
116
|
+
await this.apiLoader.initialize(opraModule);
|
|
101
117
|
}
|
|
102
118
|
}
|
|
103
119
|
async onModuleDestroy() {
|
|
104
|
-
await this.
|
|
120
|
+
await this.apiLoader.stop();
|
|
105
121
|
}
|
|
106
122
|
};
|
|
107
123
|
OpraCoreModule = OpraCoreModule_1 = __decorate([
|
|
@@ -112,6 +128,7 @@ OpraCoreModule = OpraCoreModule_1 = __decorate([
|
|
|
112
128
|
NestExplorer
|
|
113
129
|
]
|
|
114
130
|
}),
|
|
131
|
+
Global(),
|
|
115
132
|
__param(2, Inject(OPRA_MODULE_OPTIONS)),
|
|
116
133
|
__param(3, Inject(OPRA_INITIALIZER)),
|
|
117
134
|
__metadata("design:paramtypes", [HttpAdapterHost,
|
|
@@ -3,17 +3,20 @@ import { Inject, Logger } from '@nestjs/common';
|
|
|
3
3
|
import { ApplicationConfig, HttpAdapterHost } from '@nestjs/core';
|
|
4
4
|
import { OpraURLPath } from '@opra/common';
|
|
5
5
|
import { ExpressAdapter } from '@opra/core';
|
|
6
|
-
import { OPRA_MODULE_OPTIONS } from '../constants.js';
|
|
6
|
+
import { kAdapter, kOptions, OPRA_MODULE_OPTIONS } from '../constants.js';
|
|
7
7
|
import { OpraApiFactory } from '../factories/opra-api.factory.js';
|
|
8
|
+
import { OpraModuleRef } from '../opra-module-ref.js';
|
|
8
9
|
export class OpraApiLoader {
|
|
9
10
|
constructor() {
|
|
10
11
|
this.logger = new Logger(OpraApiLoader.name, { timestamp: true });
|
|
12
|
+
this.opraModuleRef = new OpraModuleRef();
|
|
11
13
|
}
|
|
12
14
|
async initialize(rootModule) {
|
|
13
15
|
const httpAdapter = this.httpAdapterHost?.httpAdapter;
|
|
14
16
|
const globalPrefix = this.applicationConfig.getGlobalPrefix();
|
|
15
17
|
const platformName = httpAdapter.getType();
|
|
16
|
-
const moduleOptions = this.
|
|
18
|
+
const moduleOptions = this.options;
|
|
19
|
+
this.opraModuleRef[kOptions] = this.options;
|
|
17
20
|
let prefixPath = new OpraURLPath((moduleOptions.useGlobalPrefix !== false ? globalPrefix : ''));
|
|
18
21
|
if (moduleOptions.basePath)
|
|
19
22
|
prefixPath = prefixPath.join(moduleOptions.basePath);
|
|
@@ -23,13 +26,13 @@ export class OpraApiLoader {
|
|
|
23
26
|
basePath: prefixPath.toString()
|
|
24
27
|
};
|
|
25
28
|
try {
|
|
26
|
-
const
|
|
27
|
-
if (!
|
|
29
|
+
const apiDocument = await this.opraFactory.generateService(rootModule, options, 'http');
|
|
30
|
+
if (!apiDocument.resources.size) {
|
|
28
31
|
this.logger.warn(`No Sources found (${name})`);
|
|
29
32
|
return;
|
|
30
33
|
}
|
|
31
34
|
if (platformName === 'express') {
|
|
32
|
-
this.
|
|
35
|
+
this.opraModuleRef[kAdapter] = await this.registerExpress(apiDocument, options);
|
|
33
36
|
// else if (platformName === 'fastify')
|
|
34
37
|
// await this.registerFastify();
|
|
35
38
|
}
|
|
@@ -46,13 +49,14 @@ export class OpraApiLoader {
|
|
|
46
49
|
async stop() {
|
|
47
50
|
//
|
|
48
51
|
}
|
|
49
|
-
async registerExpress(
|
|
52
|
+
async registerExpress(apiDocument, moduleOptions) {
|
|
50
53
|
const httpAdapter = this.httpAdapterHost.httpAdapter;
|
|
54
|
+
/* istanbul ignore next */
|
|
51
55
|
if (!httpAdapter)
|
|
52
|
-
|
|
56
|
+
throw new Error('HttpAdapterHost is not initialized');
|
|
53
57
|
const app = httpAdapter.getInstance();
|
|
54
|
-
const logger = moduleOptions.logger || new Logger(
|
|
55
|
-
return await ExpressAdapter.create(app,
|
|
58
|
+
const logger = moduleOptions.logger || new Logger(apiDocument.info.title);
|
|
59
|
+
return await ExpressAdapter.create(app, apiDocument, {
|
|
56
60
|
...moduleOptions,
|
|
57
61
|
logger,
|
|
58
62
|
});
|
|
@@ -73,4 +77,4 @@ __decorate([
|
|
|
73
77
|
__decorate([
|
|
74
78
|
Inject(OPRA_MODULE_OPTIONS),
|
|
75
79
|
__metadata("design:type", Object)
|
|
76
|
-
], OpraApiLoader.prototype, "
|
|
80
|
+
], OpraApiLoader.prototype, "options", void 0);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/nestjs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.25.0",
|
|
4
4
|
"description": "Opra NestJS module",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"clean:cover": "rimraf ../../coverage/nestjs"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@opra/common": "^0.
|
|
29
|
-
"@opra/core": "^0.
|
|
28
|
+
"@opra/common": "^0.25.0",
|
|
29
|
+
"@opra/core": "^0.25.0",
|
|
30
30
|
"fast-tokenizer": "^1.2.2",
|
|
31
31
|
"lodash.head": "^4.0.1",
|
|
32
32
|
"lodash.identity": "^3.0.0",
|
|
@@ -43,15 +43,9 @@
|
|
|
43
43
|
"ts-gems": "^2.4.1"
|
|
44
44
|
},
|
|
45
45
|
"type": "module",
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
|
|
49
|
-
"require": "./cjs/index.js",
|
|
50
|
-
"default": "./esm/index.js"
|
|
51
|
-
},
|
|
52
|
-
"./cjs": "./cjs/index.js",
|
|
53
|
-
"./esm": "./esm/index.js"
|
|
54
|
-
},
|
|
46
|
+
"module": "./esm/index.js",
|
|
47
|
+
"main": "./cjs/index.js",
|
|
48
|
+
"types": "./types/index.d.ts",
|
|
55
49
|
"engines": {
|
|
56
50
|
"node": ">=16.0",
|
|
57
51
|
"npm": ">=7.0.0"
|
package/types/constants.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export declare const OPRA_MODULE_OPTIONS = "opra:module_options";
|
|
2
2
|
export declare const OPRA_MODULE_ID = "opra:module_id";
|
|
3
3
|
export declare const OPRA_INITIALIZER = "opra_initializer";
|
|
4
|
+
export declare const kOptions: unique symbol;
|
|
5
|
+
export declare const kAdapter: unique symbol;
|
|
4
6
|
export declare const PARAM_ARGS_METADATA = "__routeArguments__";
|
package/types/index.d.ts
CHANGED
|
@@ -2,18 +2,22 @@ import { ModuleMetadata, Type } from '@nestjs/common';
|
|
|
2
2
|
import { OpraSchema } from '@opra/common';
|
|
3
3
|
import { HttpAdapter } from '@opra/core';
|
|
4
4
|
export type OpraModuleOptions = HttpAdapter.Options & {
|
|
5
|
+
id?: any;
|
|
5
6
|
info?: OpraSchema.DocumentInfo;
|
|
6
7
|
/**
|
|
7
8
|
* @default true
|
|
8
9
|
*/
|
|
9
10
|
useGlobalPrefix?: boolean;
|
|
10
11
|
};
|
|
12
|
+
type OpraModuleOptionsWithoutId = Omit<OpraModuleOptions, 'id'>;
|
|
11
13
|
export interface OpraModuleOptionsFactory {
|
|
12
|
-
createOptions(): Promise<
|
|
14
|
+
createOptions(): Promise<OpraModuleOptionsWithoutId> | OpraModuleOptionsWithoutId;
|
|
13
15
|
}
|
|
14
16
|
export interface OpraModuleAsyncOptions extends Pick<ModuleMetadata, 'imports' | 'providers'> {
|
|
17
|
+
id?: any;
|
|
15
18
|
useExisting?: Type<OpraModuleOptionsFactory>;
|
|
16
19
|
useClass?: Type<OpraModuleOptionsFactory>;
|
|
17
|
-
useFactory?: (...args: any[]) => Promise<
|
|
20
|
+
useFactory?: (...args: any[]) => Promise<OpraModuleOptionsWithoutId> | OpraModuleOptionsWithoutId;
|
|
18
21
|
inject?: any[];
|
|
19
22
|
}
|
|
23
|
+
export {};
|
|
@@ -6,8 +6,8 @@ export declare class OpraCoreModule implements OnModuleInit, OnModuleDestroy {
|
|
|
6
6
|
private readonly httpAdapterHost;
|
|
7
7
|
protected readonly modulesContainer: ModulesContainer;
|
|
8
8
|
private readonly options;
|
|
9
|
-
private readonly
|
|
10
|
-
constructor(httpAdapterHost: HttpAdapterHost, modulesContainer: ModulesContainer, options: OpraModuleOptions,
|
|
9
|
+
private readonly apiLoader;
|
|
10
|
+
constructor(httpAdapterHost: HttpAdapterHost, modulesContainer: ModulesContainer, options: OpraModuleOptions, apiLoader: OpraApiLoader);
|
|
11
11
|
static forRoot(options: OpraModuleOptions & Pick<DynamicModule, 'imports' | 'providers' | 'exports'>): DynamicModule;
|
|
12
12
|
static forRootAsync(asyncOptions: OpraModuleAsyncOptions): DynamicModule;
|
|
13
13
|
private static createAsyncProviders;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ApiDocument } from '@opra/common';
|
|
2
|
+
import { PlatformAdapter } from '@opra/core';
|
|
3
|
+
import { kAdapter, kOptions } from './constants.js';
|
|
4
|
+
import { OpraModuleOptions } from './interfaces/opra-module-options.interface.js';
|
|
5
|
+
export declare class OpraModuleRef {
|
|
6
|
+
protected [kOptions]: OpraModuleOptions;
|
|
7
|
+
protected [kAdapter]: PlatformAdapter;
|
|
8
|
+
get adapter(): PlatformAdapter;
|
|
9
|
+
get api(): ApiDocument;
|
|
10
|
+
get options(): OpraModuleOptions;
|
|
11
|
+
}
|
|
@@ -2,17 +2,18 @@ import { Logger } from '@nestjs/common';
|
|
|
2
2
|
import { ApplicationConfig, HttpAdapterHost } from '@nestjs/core';
|
|
3
3
|
import { Module } from '@nestjs/core/injector/module.js';
|
|
4
4
|
import { ApiDocument } from '@opra/common';
|
|
5
|
-
import { ExpressAdapter
|
|
5
|
+
import { ExpressAdapter } from '@opra/core';
|
|
6
6
|
import { OpraApiFactory } from '../factories/opra-api.factory.js';
|
|
7
7
|
import { OpraModuleOptions } from '../interfaces/opra-module-options.interface.js';
|
|
8
|
+
import { OpraModuleRef } from '../opra-module-ref.js';
|
|
8
9
|
export declare class OpraApiLoader {
|
|
9
10
|
protected readonly logger: Logger;
|
|
10
|
-
|
|
11
|
+
readonly opraModuleRef: OpraModuleRef;
|
|
11
12
|
protected readonly httpAdapterHost: HttpAdapterHost;
|
|
12
13
|
protected readonly applicationConfig: ApplicationConfig;
|
|
13
14
|
protected readonly opraFactory: OpraApiFactory;
|
|
14
|
-
protected readonly
|
|
15
|
+
protected readonly options: OpraModuleOptions;
|
|
15
16
|
initialize(rootModule: Module): Promise<void>;
|
|
16
17
|
stop(): Promise<void>;
|
|
17
|
-
protected registerExpress(
|
|
18
|
+
protected registerExpress(apiDocument: ApiDocument, moduleOptions: OpraModuleOptions): Promise<ExpressAdapter>;
|
|
18
19
|
}
|