@opra/nestjs 0.24.1 → 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 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__';
@@ -5,12 +5,14 @@ const tslib_1 = require("tslib");
5
5
  const lodash_head_1 = tslib_1.__importDefault(require("lodash.head"));
6
6
  const common_1 = require("@nestjs/common");
7
7
  const core_1 = require("@nestjs/core");
8
+ const external_context_creator_1 = require("@nestjs/core/helpers/external-context-creator");
8
9
  const injector_1 = require("@nestjs/core/injector/injector");
9
10
  const internal_core_module_1 = require("@nestjs/core/injector/internal-core-module");
10
11
  const request_constants_1 = require("@nestjs/core/router/request/request-constants");
11
12
  const common_2 = require("@opra/common");
12
13
  const constants_js_1 = require("../constants.js");
13
14
  const handler_paramtype_enum_js_1 = require("../enums/handler-paramtype.enum.js");
15
+ const nest_explorer_js_1 = require("../services/nest-explorer.js");
14
16
  const function_utils_js_1 = require("../utils/function.utils.js");
15
17
  const params_factory_js_1 = require("./params.factory.js");
16
18
  const noOpFunction = () => void 0;
@@ -172,13 +174,16 @@ let OpraApiFactory = exports.OpraApiFactory = class OpraApiFactory {
172
174
  }
173
175
  };
174
176
  tslib_1.__decorate([
175
- (0, common_1.Inject)()
177
+ (0, common_1.Inject)(),
178
+ tslib_1.__metadata("design:type", core_1.ModulesContainer)
176
179
  ], OpraApiFactory.prototype, "modulesContainer", void 0);
177
180
  tslib_1.__decorate([
178
- (0, common_1.Inject)()
181
+ (0, common_1.Inject)(),
182
+ tslib_1.__metadata("design:type", external_context_creator_1.ExternalContextCreator)
179
183
  ], OpraApiFactory.prototype, "externalContextCreator", void 0);
180
184
  tslib_1.__decorate([
181
- (0, common_1.Inject)()
185
+ (0, common_1.Inject)(),
186
+ tslib_1.__metadata("design:type", nest_explorer_js_1.NestExplorer)
182
187
  ], OpraApiFactory.prototype, "explorerService", void 0);
183
188
  exports.OpraApiFactory = OpraApiFactory = tslib_1.__decorate([
184
189
  (0, common_1.Injectable)()
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);
@@ -5,34 +5,44 @@ exports.OpraCoreModule = void 0;
5
5
  const tslib_1 = require("tslib");
6
6
  const crypto = tslib_1.__importStar(require("crypto"));
7
7
  const common_1 = require("@nestjs/common");
8
+ const core_1 = require("@nestjs/core");
8
9
  const metadata_scanner_1 = require("@nestjs/core/metadata-scanner");
9
10
  const constants_js_1 = require("./constants.js");
10
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");
11
13
  const nest_explorer_js_1 = require("./services/nest-explorer.js");
12
14
  const opra_api_loader_js_1 = require("./services/opra-api-loader.js");
13
15
  let OpraCoreModule = exports.OpraCoreModule = OpraCoreModule_1 = class OpraCoreModule {
14
- constructor(httpAdapterHost, modulesContainer, options, opraServiceLoader) {
16
+ constructor(httpAdapterHost, modulesContainer, options, apiLoader) {
15
17
  this.httpAdapterHost = httpAdapterHost;
16
18
  this.modulesContainer = modulesContainer;
17
19
  this.options = options;
18
- this.opraServiceLoader = opraServiceLoader;
20
+ this.apiLoader = apiLoader;
19
21
  }
20
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
+ ];
21
41
  return {
22
42
  module: OpraCoreModule_1,
23
43
  imports: [...(options.imports || [])],
24
- providers: [
25
- ...(options.providers || []),
26
- {
27
- provide: constants_js_1.OPRA_MODULE_OPTIONS,
28
- useValue: options,
29
- },
30
- {
31
- provide: constants_js_1.OPRA_INITIALIZER,
32
- useClass: opra_api_loader_js_1.OpraApiLoader
33
- }
34
- ],
35
- exports: [...(options.exports || [])]
44
+ exports: [...(options.exports || [])],
45
+ providers
36
46
  };
37
47
  }
38
48
  static forRootAsync(asyncOptions) {
@@ -49,6 +59,13 @@ let OpraCoreModule = exports.OpraCoreModule = OpraCoreModule_1 = class OpraCoreM
49
59
  provide: constants_js_1.OPRA_INITIALIZER,
50
60
  useClass: opra_api_loader_js_1.OpraApiLoader
51
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
+ },
52
69
  ...this.createAsyncProviders(asyncOptions)
53
70
  ]
54
71
  };
@@ -99,11 +116,11 @@ let OpraCoreModule = exports.OpraCoreModule = OpraCoreModule_1 = class OpraCoreM
99
116
  }
100
117
  })();
101
118
  if (opraModule) {
102
- await this.opraServiceLoader.initialize(opraModule);
119
+ await this.apiLoader.initialize(opraModule);
103
120
  }
104
121
  }
105
122
  async onModuleDestroy() {
106
- await this.opraServiceLoader.stop();
123
+ await this.apiLoader.stop();
107
124
  }
108
125
  };
109
126
  exports.OpraCoreModule = OpraCoreModule = OpraCoreModule_1 = tslib_1.__decorate([
@@ -114,6 +131,9 @@ exports.OpraCoreModule = OpraCoreModule = OpraCoreModule_1 = tslib_1.__decorate(
114
131
  nest_explorer_js_1.NestExplorer
115
132
  ]
116
133
  }),
134
+ (0, common_1.Global)(),
117
135
  tslib_1.__param(2, (0, common_1.Inject)(constants_js_1.OPRA_MODULE_OPTIONS)),
118
- tslib_1.__param(3, (0, common_1.Inject)(constants_js_1.OPRA_INITIALIZER))
136
+ tslib_1.__param(3, (0, common_1.Inject)(constants_js_1.OPRA_INITIALIZER)),
137
+ tslib_1.__metadata("design:paramtypes", [core_1.HttpAdapterHost,
138
+ core_1.ModulesContainer, Object, opra_api_loader_js_1.OpraApiLoader])
119
139
  ], OpraCoreModule);
@@ -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;
@@ -3,18 +3,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OpraApiLoader = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const common_1 = require("@nestjs/common");
6
+ const core_1 = require("@nestjs/core");
6
7
  const common_2 = require("@opra/common");
7
- const core_1 = require("@opra/core");
8
+ const core_2 = require("@opra/core");
8
9
  const constants_js_1 = require("../constants.js");
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");
9
12
  class OpraApiLoader {
10
13
  constructor() {
11
14
  this.logger = new common_1.Logger(OpraApiLoader.name, { timestamp: true });
15
+ this.opraModuleRef = new opra_module_ref_js_1.OpraModuleRef();
12
16
  }
13
17
  async initialize(rootModule) {
14
18
  const httpAdapter = this.httpAdapterHost?.httpAdapter;
15
19
  const globalPrefix = this.applicationConfig.getGlobalPrefix();
16
20
  const platformName = httpAdapter.getType();
17
- const moduleOptions = this.opraModuleOptions;
21
+ const moduleOptions = this.options;
22
+ this.opraModuleRef[constants_js_1.kOptions] = this.options;
18
23
  let prefixPath = new common_2.OpraURLPath((moduleOptions.useGlobalPrefix !== false ? globalPrefix : ''));
19
24
  if (moduleOptions.basePath)
20
25
  prefixPath = prefixPath.join(moduleOptions.basePath);
@@ -24,13 +29,13 @@ class OpraApiLoader {
24
29
  basePath: prefixPath.toString()
25
30
  };
26
31
  try {
27
- const serviceHost = await this.opraFactory.generateService(rootModule, options, 'http');
28
- if (!serviceHost.resources.size) {
32
+ const apiDocument = await this.opraFactory.generateService(rootModule, options, 'http');
33
+ if (!apiDocument.resources.size) {
29
34
  this.logger.warn(`No Sources found (${name})`);
30
35
  return;
31
36
  }
32
37
  if (platformName === 'express') {
33
- this.adapter = await this.registerExpress(serviceHost, options);
38
+ this.opraModuleRef[constants_js_1.kAdapter] = await this.registerExpress(apiDocument, options);
34
39
  // else if (platformName === 'fastify')
35
40
  // await this.registerFastify();
36
41
  }
@@ -47,13 +52,14 @@ class OpraApiLoader {
47
52
  async stop() {
48
53
  //
49
54
  }
50
- async registerExpress(service, moduleOptions) {
55
+ async registerExpress(apiDocument, moduleOptions) {
51
56
  const httpAdapter = this.httpAdapterHost.httpAdapter;
57
+ /* istanbul ignore next */
52
58
  if (!httpAdapter)
53
- return;
59
+ throw new Error('HttpAdapterHost is not initialized');
54
60
  const app = httpAdapter.getInstance();
55
- const logger = moduleOptions.logger || new common_1.Logger(service.info.title);
56
- return await core_1.ExpressAdapter.create(app, service, {
61
+ const logger = moduleOptions.logger || new common_1.Logger(apiDocument.info.title);
62
+ return await core_2.ExpressAdapter.create(app, apiDocument, {
57
63
  ...moduleOptions,
58
64
  logger,
59
65
  });
@@ -61,14 +67,18 @@ class OpraApiLoader {
61
67
  }
62
68
  exports.OpraApiLoader = OpraApiLoader;
63
69
  tslib_1.__decorate([
64
- (0, common_1.Inject)()
70
+ (0, common_1.Inject)(),
71
+ tslib_1.__metadata("design:type", core_1.HttpAdapterHost)
65
72
  ], OpraApiLoader.prototype, "httpAdapterHost", void 0);
66
73
  tslib_1.__decorate([
67
- (0, common_1.Inject)()
74
+ (0, common_1.Inject)(),
75
+ tslib_1.__metadata("design:type", core_1.ApplicationConfig)
68
76
  ], OpraApiLoader.prototype, "applicationConfig", void 0);
69
77
  tslib_1.__decorate([
70
- (0, common_1.Inject)()
78
+ (0, common_1.Inject)(),
79
+ tslib_1.__metadata("design:type", opra_api_factory_js_1.OpraApiFactory)
71
80
  ], OpraApiLoader.prototype, "opraFactory", void 0);
72
81
  tslib_1.__decorate([
73
- (0, common_1.Inject)(constants_js_1.OPRA_MODULE_OPTIONS)
74
- ], OpraApiLoader.prototype, "opraModuleOptions", void 0);
82
+ (0, common_1.Inject)(constants_js_1.OPRA_MODULE_OPTIONS),
83
+ tslib_1.__metadata("design:type", Object)
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__';
@@ -1,13 +1,15 @@
1
- import { __decorate } from "tslib";
1
+ import { __decorate, __metadata } from "tslib";
2
2
  import head from 'lodash.head';
3
3
  import { Inject, Injectable } from '@nestjs/common';
4
- import { ContextIdFactory, createContextId, REQUEST } from '@nestjs/core';
4
+ import { ContextIdFactory, createContextId, ModulesContainer, REQUEST } from '@nestjs/core';
5
+ import { ExternalContextCreator } from '@nestjs/core/helpers/external-context-creator';
5
6
  import { Injector } from '@nestjs/core/injector/injector';
6
7
  import { InternalCoreModule } from '@nestjs/core/injector/internal-core-module';
7
8
  import { REQUEST_CONTEXT_ID } from '@nestjs/core/router/request/request-constants';
8
9
  import { DocumentFactory, OpraSchema, RESOURCE_METADATA } from '@opra/common';
9
10
  import { PARAM_ARGS_METADATA } from '../constants.js';
10
11
  import { HandlerParamType } from '../enums/handler-paramtype.enum.js';
12
+ import { NestExplorer } from '../services/nest-explorer.js';
11
13
  import { getNumberOfArguments } from '../utils/function.utils.js';
12
14
  import { OpraParamsFactory } from './params.factory.js';
13
15
  const noOpFunction = () => void 0;
@@ -169,13 +171,16 @@ export let OpraApiFactory = class OpraApiFactory {
169
171
  }
170
172
  };
171
173
  __decorate([
172
- Inject()
174
+ Inject(),
175
+ __metadata("design:type", ModulesContainer)
173
176
  ], OpraApiFactory.prototype, "modulesContainer", void 0);
174
177
  __decorate([
175
- Inject()
178
+ Inject(),
179
+ __metadata("design:type", ExternalContextCreator)
176
180
  ], OpraApiFactory.prototype, "externalContextCreator", void 0);
177
181
  __decorate([
178
- Inject()
182
+ Inject(),
183
+ __metadata("design:type", NestExplorer)
179
184
  ], OpraApiFactory.prototype, "explorerService", void 0);
180
185
  OpraApiFactory = __decorate([
181
186
  Injectable()
package/esm/index.js CHANGED
@@ -3,3 +3,4 @@ import './augmentation/common-decorator.augmentation.js';
3
3
  export * from './opra.module.js';
4
4
  export * from './decorators/context.decorator.js';
5
5
  export * from './interfaces/opra-module-options.interface.js';
6
+ export * from './opra-module-ref.js';
@@ -1,35 +1,45 @@
1
1
  var OpraCoreModule_1;
2
- import { __decorate, __param } from "tslib";
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
+ import { HttpAdapterHost, ModulesContainer } from '@nestjs/core';
5
6
  import { MetadataScanner } from '@nestjs/core/metadata-scanner';
6
7
  import { OPRA_INITIALIZER, OPRA_MODULE_ID, OPRA_MODULE_OPTIONS } from './constants.js';
7
8
  import { OpraApiFactory } from './factories/opra-api.factory.js';
9
+ import { OpraModuleRef } from './opra-module-ref.js';
8
10
  import { NestExplorer } from './services/nest-explorer.js';
9
11
  import { OpraApiLoader } from './services/opra-api-loader.js';
10
12
  export let OpraCoreModule = OpraCoreModule_1 = class OpraCoreModule {
11
- constructor(httpAdapterHost, modulesContainer, options, opraServiceLoader) {
13
+ constructor(httpAdapterHost, modulesContainer, options, apiLoader) {
12
14
  this.httpAdapterHost = httpAdapterHost;
13
15
  this.modulesContainer = modulesContainer;
14
16
  this.options = options;
15
- this.opraServiceLoader = opraServiceLoader;
17
+ this.apiLoader = apiLoader;
16
18
  }
17
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
+ ];
18
38
  return {
19
39
  module: OpraCoreModule_1,
20
40
  imports: [...(options.imports || [])],
21
- providers: [
22
- ...(options.providers || []),
23
- {
24
- provide: OPRA_MODULE_OPTIONS,
25
- useValue: options,
26
- },
27
- {
28
- provide: OPRA_INITIALIZER,
29
- useClass: OpraApiLoader
30
- }
31
- ],
32
- exports: [...(options.exports || [])]
41
+ exports: [...(options.exports || [])],
42
+ providers
33
43
  };
34
44
  }
35
45
  static forRootAsync(asyncOptions) {
@@ -46,6 +56,13 @@ export let OpraCoreModule = OpraCoreModule_1 = class OpraCoreModule {
46
56
  provide: OPRA_INITIALIZER,
47
57
  useClass: OpraApiLoader
48
58
  },
59
+ {
60
+ provide: asyncOptions.id || OpraModuleRef,
61
+ inject: [OPRA_INITIALIZER],
62
+ useFactory: (apiLoader) => {
63
+ return apiLoader.opraModuleRef;
64
+ }
65
+ },
49
66
  ...this.createAsyncProviders(asyncOptions)
50
67
  ]
51
68
  };
@@ -96,11 +113,11 @@ export let OpraCoreModule = OpraCoreModule_1 = class OpraCoreModule {
96
113
  }
97
114
  })();
98
115
  if (opraModule) {
99
- await this.opraServiceLoader.initialize(opraModule);
116
+ await this.apiLoader.initialize(opraModule);
100
117
  }
101
118
  }
102
119
  async onModuleDestroy() {
103
- await this.opraServiceLoader.stop();
120
+ await this.apiLoader.stop();
104
121
  }
105
122
  };
106
123
  OpraCoreModule = OpraCoreModule_1 = __decorate([
@@ -111,6 +128,9 @@ OpraCoreModule = OpraCoreModule_1 = __decorate([
111
128
  NestExplorer
112
129
  ]
113
130
  }),
131
+ Global(),
114
132
  __param(2, Inject(OPRA_MODULE_OPTIONS)),
115
- __param(3, Inject(OPRA_INITIALIZER))
133
+ __param(3, Inject(OPRA_INITIALIZER)),
134
+ __metadata("design:paramtypes", [HttpAdapterHost,
135
+ ModulesContainer, Object, OpraApiLoader])
116
136
  ], OpraCoreModule);
@@ -0,0 +1,12 @@
1
+ import { kAdapter, kOptions } from './constants.js';
2
+ export class OpraModuleRef {
3
+ get adapter() {
4
+ return this[kAdapter];
5
+ }
6
+ get api() {
7
+ return this[kAdapter].api;
8
+ }
9
+ get options() {
10
+ return this[kOptions];
11
+ }
12
+ }
@@ -1,17 +1,22 @@
1
- import { __decorate } from "tslib";
1
+ import { __decorate, __metadata } from "tslib";
2
2
  import { Inject, Logger } from '@nestjs/common';
3
+ import { ApplicationConfig, HttpAdapterHost } from '@nestjs/core';
3
4
  import { OpraURLPath } from '@opra/common';
4
5
  import { ExpressAdapter } from '@opra/core';
5
- import { OPRA_MODULE_OPTIONS } from '../constants.js';
6
+ import { kAdapter, kOptions, OPRA_MODULE_OPTIONS } from '../constants.js';
7
+ import { OpraApiFactory } from '../factories/opra-api.factory.js';
8
+ import { OpraModuleRef } from '../opra-module-ref.js';
6
9
  export class OpraApiLoader {
7
10
  constructor() {
8
11
  this.logger = new Logger(OpraApiLoader.name, { timestamp: true });
12
+ this.opraModuleRef = new OpraModuleRef();
9
13
  }
10
14
  async initialize(rootModule) {
11
15
  const httpAdapter = this.httpAdapterHost?.httpAdapter;
12
16
  const globalPrefix = this.applicationConfig.getGlobalPrefix();
13
17
  const platformName = httpAdapter.getType();
14
- const moduleOptions = this.opraModuleOptions;
18
+ const moduleOptions = this.options;
19
+ this.opraModuleRef[kOptions] = this.options;
15
20
  let prefixPath = new OpraURLPath((moduleOptions.useGlobalPrefix !== false ? globalPrefix : ''));
16
21
  if (moduleOptions.basePath)
17
22
  prefixPath = prefixPath.join(moduleOptions.basePath);
@@ -21,13 +26,13 @@ export class OpraApiLoader {
21
26
  basePath: prefixPath.toString()
22
27
  };
23
28
  try {
24
- const serviceHost = await this.opraFactory.generateService(rootModule, options, 'http');
25
- if (!serviceHost.resources.size) {
29
+ const apiDocument = await this.opraFactory.generateService(rootModule, options, 'http');
30
+ if (!apiDocument.resources.size) {
26
31
  this.logger.warn(`No Sources found (${name})`);
27
32
  return;
28
33
  }
29
34
  if (platformName === 'express') {
30
- this.adapter = await this.registerExpress(serviceHost, options);
35
+ this.opraModuleRef[kAdapter] = await this.registerExpress(apiDocument, options);
31
36
  // else if (platformName === 'fastify')
32
37
  // await this.registerFastify();
33
38
  }
@@ -44,27 +49,32 @@ export class OpraApiLoader {
44
49
  async stop() {
45
50
  //
46
51
  }
47
- async registerExpress(service, moduleOptions) {
52
+ async registerExpress(apiDocument, moduleOptions) {
48
53
  const httpAdapter = this.httpAdapterHost.httpAdapter;
54
+ /* istanbul ignore next */
49
55
  if (!httpAdapter)
50
- return;
56
+ throw new Error('HttpAdapterHost is not initialized');
51
57
  const app = httpAdapter.getInstance();
52
- const logger = moduleOptions.logger || new Logger(service.info.title);
53
- return await ExpressAdapter.create(app, service, {
58
+ const logger = moduleOptions.logger || new Logger(apiDocument.info.title);
59
+ return await ExpressAdapter.create(app, apiDocument, {
54
60
  ...moduleOptions,
55
61
  logger,
56
62
  });
57
63
  }
58
64
  }
59
65
  __decorate([
60
- Inject()
66
+ Inject(),
67
+ __metadata("design:type", HttpAdapterHost)
61
68
  ], OpraApiLoader.prototype, "httpAdapterHost", void 0);
62
69
  __decorate([
63
- Inject()
70
+ Inject(),
71
+ __metadata("design:type", ApplicationConfig)
64
72
  ], OpraApiLoader.prototype, "applicationConfig", void 0);
65
73
  __decorate([
66
- Inject()
74
+ Inject(),
75
+ __metadata("design:type", OpraApiFactory)
67
76
  ], OpraApiLoader.prototype, "opraFactory", void 0);
68
77
  __decorate([
69
- Inject(OPRA_MODULE_OPTIONS)
70
- ], OpraApiLoader.prototype, "opraModuleOptions", void 0);
78
+ Inject(OPRA_MODULE_OPTIONS),
79
+ __metadata("design:type", Object)
80
+ ], OpraApiLoader.prototype, "options", void 0);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opra/nestjs",
3
- "version": "0.24.1",
3
+ "version": "0.25.0",
4
4
  "description": "Opra NestJS module",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
@@ -25,33 +25,27 @@
25
25
  "clean:cover": "rimraf ../../coverage/nestjs"
26
26
  },
27
27
  "dependencies": {
28
- "@opra/common": "^0.24.1",
29
- "@opra/core": "^0.24.1",
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",
33
33
  "reflect-metadata": "^0.1.13"
34
34
  },
35
35
  "peerDependencies": {
36
- "@nestjs/common": "^10.2.0"
36
+ "@nestjs/common": "^10.2.1"
37
37
  },
38
38
  "devDependencies": {
39
- "@nestjs/platform-express": "^10.2.0",
40
- "@nestjs/testing": "^10.2.0",
39
+ "@nestjs/platform-express": "^10.2.1",
40
+ "@nestjs/testing": "^10.2.1",
41
41
  "@types/lodash": "^4.14.197",
42
42
  "filedirname": "^2.7.0",
43
43
  "ts-gems": "^2.4.1"
44
44
  },
45
45
  "type": "module",
46
- "types": "types/index.d.ts",
47
- "exports": {
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"
@@ -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
@@ -3,3 +3,4 @@ import './augmentation/common-decorator.augmentation.js';
3
3
  export * from './opra.module.js';
4
4
  export * from './decorators/context.decorator.js';
5
5
  export * from './interfaces/opra-module-options.interface.js';
6
+ export * from './opra-module-ref.js';
@@ -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<OpraModuleOptions> | OpraModuleOptions;
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<OpraModuleOptions> | OpraModuleOptions;
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 opraServiceLoader;
10
- constructor(httpAdapterHost: HttpAdapterHost, modulesContainer: ModulesContainer, options: OpraModuleOptions, opraServiceLoader: OpraApiLoader);
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, PlatformAdapter } from '@opra/core';
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
- protected adapter: PlatformAdapter | undefined;
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 opraModuleOptions: OpraModuleOptions;
15
+ protected readonly options: OpraModuleOptions;
15
16
  initialize(rootModule: Module): Promise<void>;
16
17
  stop(): Promise<void>;
17
- protected registerExpress(service: ApiDocument, moduleOptions: OpraModuleOptions): Promise<ExpressAdapter | undefined>;
18
+ protected registerExpress(apiDocument: ApiDocument, moduleOptions: OpraModuleOptions): Promise<ExpressAdapter>;
18
19
  }