@opra/nestjs 0.16.2 → 0.17.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/esm/constants.js CHANGED
@@ -1,7 +1,4 @@
1
- "use strict";
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;
4
- exports.OPRA_MODULE_OPTIONS = 'opra:module_options';
5
- exports.OPRA_MODULE_ID = 'opra:module_id';
6
- exports.OPRA_INITIALIZER = 'opra_initializer';
7
- exports.PARAM_ARGS_METADATA = '__routeArguments__';
1
+ export const OPRA_MODULE_OPTIONS = 'opra:module_options';
2
+ export const OPRA_MODULE_ID = 'opra:module_id';
3
+ export const OPRA_INITIALIZER = 'opra_initializer';
4
+ export const PARAM_ARGS_METADATA = '__routeArguments__';
@@ -1,15 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ApiDoc = exports.Context = void 0;
4
- const handler_paramtype_enum_js_1 = require("../enums/handler-paramtype.enum.js");
5
- const param_utils_js_1 = require("../utils/param.utils.js");
1
+ import { HandlerParamType } from '../enums/handler-paramtype.enum.js';
2
+ import { createOpraParamDecorator } from '../utils/param.utils.js';
6
3
  /**
7
4
  * Handler method parameter decorator. Populates the decorated
8
5
  * parameter with the value of `RequestContext`.
9
6
  */
10
- exports.Context = (0, param_utils_js_1.createOpraParamDecorator)(handler_paramtype_enum_js_1.HandlerParamType.CONTEXT);
7
+ export const Context = createOpraParamDecorator(HandlerParamType.CONTEXT);
11
8
  /**
12
9
  * Handler method parameter decorator. Populates the decorated
13
10
  * parameter with the value of `OpraService`.
14
11
  */
15
- exports.ApiDoc = (0, param_utils_js_1.createOpraParamDecorator)(handler_paramtype_enum_js_1.HandlerParamType.API);
12
+ export const ApiDoc = createOpraParamDecorator(HandlerParamType.API);
@@ -1,10 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HandlerParamType = void 0;
4
- var HandlerParamType;
1
+ export var HandlerParamType;
5
2
  (function (HandlerParamType) {
6
3
  HandlerParamType[HandlerParamType["CONTEXT"] = 0] = "CONTEXT";
7
4
  HandlerParamType[HandlerParamType["API"] = 1] = "API";
8
5
  HandlerParamType[HandlerParamType["REQUEST"] = 2] = "REQUEST";
9
6
  HandlerParamType[HandlerParamType["RESPONSE"] = 3] = "RESPONSE";
10
- })(HandlerParamType = exports.HandlerParamType || (exports.HandlerParamType = {}));
7
+ })(HandlerParamType || (HandlerParamType = {}));
@@ -1,26 +1,23 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OpraApiFactory = void 0;
4
- const tslib_1 = require("tslib");
5
- const lodash_head_1 = tslib_1.__importDefault(require("lodash.head"));
6
- const lodash_identity_1 = tslib_1.__importDefault(require("lodash.identity"));
7
- const common_1 = require("@nestjs/common");
8
- const core_1 = require("@nestjs/core");
9
- const external_context_creator_1 = require("@nestjs/core/helpers/external-context-creator");
10
- const injector_1 = require("@nestjs/core/injector/injector");
11
- const internal_core_module_1 = require("@nestjs/core/injector/internal-core-module");
12
- const request_constants_1 = require("@nestjs/core/router/request/request-constants");
13
- const common_2 = require("@opra/common");
14
- const constants_js_1 = require("../constants.js");
15
- const handler_paramtype_enum_js_1 = require("../enums/handler-paramtype.enum.js");
16
- const nest_explorer_js_1 = require("../services/nest-explorer.js");
17
- const function_utils_js_1 = require("../utils/function.utils.js");
18
- const params_factory_js_1 = require("./params.factory.js");
1
+ import { __decorate, __metadata } from "tslib";
2
+ import head from 'lodash.head';
3
+ import identity from 'lodash.identity';
4
+ import { Inject, Injectable } from '@nestjs/common';
5
+ import { ContextIdFactory, createContextId, ModulesContainer, REQUEST } from '@nestjs/core';
6
+ import { ExternalContextCreator } from '@nestjs/core/helpers/external-context-creator';
7
+ import { Injector } from '@nestjs/core/injector/injector';
8
+ import { InternalCoreModule } from '@nestjs/core/injector/internal-core-module';
9
+ import { REQUEST_CONTEXT_ID } from '@nestjs/core/router/request/request-constants';
10
+ import { DocumentFactory, METADATA_KEY, OpraSchema } from '@opra/common';
11
+ import { PARAM_ARGS_METADATA } from '../constants.js';
12
+ import { HandlerParamType } from '../enums/handler-paramtype.enum.js';
13
+ import { NestExplorer } from '../services/nest-explorer.js';
14
+ import { getNumberOfArguments } from '../utils/function.utils.js';
15
+ import { OpraParamsFactory } from './params.factory.js';
19
16
  const noOpFunction = () => void 0;
20
17
  let OpraApiFactory = class OpraApiFactory {
21
18
  constructor() {
22
- this.paramsFactory = new params_factory_js_1.OpraParamsFactory();
23
- this.injector = new injector_1.Injector();
19
+ this.paramsFactory = new OpraParamsFactory();
20
+ this.injector = new Injector();
24
21
  }
25
22
  async generateService(rootModule, moduleOptions, contextType) {
26
23
  const info = { title: '', version: '', ...moduleOptions.info };
@@ -28,7 +25,7 @@ let OpraApiFactory = class OpraApiFactory {
28
25
  info.version = info.version || '1';
29
26
  const resources = [];
30
27
  const apiSchema = {
31
- version: common_2.OpraSchema.SpecVersion,
28
+ version: OpraSchema.SpecVersion,
32
29
  info,
33
30
  types: [],
34
31
  resources,
@@ -40,14 +37,14 @@ let OpraApiFactory = class OpraApiFactory {
40
37
  for (const wrapper of wrappers) {
41
38
  const instance = wrapper.instance;
42
39
  const ctor = instance.constructor;
43
- const metadata = Reflect.getMetadata(common_2.METADATA_KEY, ctor);
44
- if (common_2.OpraSchema.isResource(metadata))
40
+ const metadata = Reflect.getMetadata(METADATA_KEY, ctor);
41
+ if (OpraSchema.isResource(metadata))
45
42
  resources.push(instance);
46
43
  }
47
44
  for (const wrapper of wrappers) {
48
45
  const instance = wrapper.instance;
49
46
  const ctor = instance.constructor;
50
- const resourceDef = Reflect.getMetadata(common_2.METADATA_KEY, ctor);
47
+ const resourceDef = Reflect.getMetadata(METADATA_KEY, ctor);
51
48
  /* istanbul ignore next */
52
49
  if (!resourceDef)
53
50
  continue;
@@ -56,7 +53,7 @@ let OpraApiFactory = class OpraApiFactory {
56
53
  const prototype = Object.getPrototypeOf(instance);
57
54
  const isRequestScoped = !wrapper.isDependencyTreeStatic();
58
55
  // const methodsToWrap = OpraSchema.isCollectionResource(resourceDef) ? collectionMethods : [];
59
- if ((common_2.OpraSchema.isCollection(resourceDef) || common_2.OpraSchema.isSingleton(resourceDef)) && resourceDef.operations) {
56
+ if ((OpraSchema.isCollection(resourceDef) || OpraSchema.isSingleton(resourceDef)) && resourceDef.operations) {
60
57
  for (const opr of Object.values(resourceDef.operations)) {
61
58
  const { handlerName } = opr;
62
59
  const fn = prototype[handlerName];
@@ -68,7 +65,7 @@ let OpraApiFactory = class OpraApiFactory {
68
65
  // To work handlers properly we create new handlers that will work as a proxy to wrap parameters
69
66
  // Opra request (context) -> Nest (req, res, next, context: QueryRequestContext) -> Opra response (context)
70
67
  const nestHandlerName = handlerName + '::nestjs';
71
- const paramArgsMetadata = Reflect.getMetadata(constants_js_1.PARAM_ARGS_METADATA, instance.constructor, handlerName);
68
+ const paramArgsMetadata = Reflect.getMetadata(PARAM_ARGS_METADATA, instance.constructor, handlerName);
72
69
  const hasParamsArgs = !!paramArgsMetadata;
73
70
  const patchedFn = prototype[nestHandlerName] = function (...args) {
74
71
  if (hasParamsArgs)
@@ -76,7 +73,7 @@ let OpraApiFactory = class OpraApiFactory {
76
73
  return fn.call(this, args[3]);
77
74
  };
78
75
  if (paramArgsMetadata)
79
- Reflect.defineMetadata(constants_js_1.PARAM_ARGS_METADATA, paramArgsMetadata, instance.constructor, nestHandlerName);
76
+ Reflect.defineMetadata(PARAM_ARGS_METADATA, paramArgsMetadata, instance.constructor, nestHandlerName);
80
77
  // Copy all metadata from old Function to new one
81
78
  Reflect.getMetadataKeys(fn).forEach(k => {
82
79
  const m = Reflect.getMetadata(k, fn);
@@ -102,30 +99,30 @@ let OpraApiFactory = class OpraApiFactory {
102
99
  }
103
100
  }
104
101
  // Create api document
105
- return common_2.DocumentFactory.createDocument(apiSchema);
102
+ return DocumentFactory.createDocument(apiSchema);
106
103
  }
107
- _createContextCallback(instance, prototype, wrapper, moduleRef, methodName, isRequestScoped, transform = lodash_identity_1.default, contextType, options) {
104
+ _createContextCallback(instance, prototype, wrapper, moduleRef, methodName, isRequestScoped, transform = identity, contextType, options) {
108
105
  const paramsFactory = this.paramsFactory;
109
106
  if (isRequestScoped) {
110
107
  return async (...args) => {
111
- const opraContext = paramsFactory.exchangeKeyForValue(handler_paramtype_enum_js_1.HandlerParamType.CONTEXT, undefined, args);
108
+ const opraContext = paramsFactory.exchangeKeyForValue(HandlerParamType.CONTEXT, undefined, args);
112
109
  const contextId = this.getContextId(opraContext);
113
110
  this.registerContextProvider(opraContext, contextId);
114
111
  const contextInstance = await this.injector.loadPerContext(instance, moduleRef, moduleRef.providers, contextId);
115
- const callback = this.externalContextCreator.create(contextInstance, transform(contextInstance[methodName]), methodName, constants_js_1.PARAM_ARGS_METADATA, paramsFactory, contextId, wrapper.id, options, opraContext.protocol);
112
+ const callback = this.externalContextCreator.create(contextInstance, transform(contextInstance[methodName]), methodName, PARAM_ARGS_METADATA, paramsFactory, contextId, wrapper.id, options, opraContext.protocol);
116
113
  return callback(...args);
117
114
  };
118
115
  }
119
- return this.externalContextCreator.create(instance, prototype[methodName], methodName, constants_js_1.PARAM_ARGS_METADATA, paramsFactory, undefined, undefined, options, contextType);
116
+ return this.externalContextCreator.create(instance, prototype[methodName], methodName, PARAM_ARGS_METADATA, paramsFactory, undefined, undefined, options, contextType);
120
117
  }
121
118
  // noinspection JSMethodCanBeStatic
122
119
  getContextId(gqlContext) {
123
- const numberOfArguments = (0, function_utils_js_1.getNumberOfArguments)(core_1.ContextIdFactory.getByRequest);
120
+ const numberOfArguments = getNumberOfArguments(ContextIdFactory.getByRequest);
124
121
  if (numberOfArguments === 2) {
125
122
  // @ts-ignore
126
- const contextId = core_1.ContextIdFactory.getByRequest(gqlContext, ['req']);
127
- if (!gqlContext[request_constants_1.REQUEST_CONTEXT_ID]) {
128
- Object.defineProperty(gqlContext, request_constants_1.REQUEST_CONTEXT_ID, {
123
+ const contextId = ContextIdFactory.getByRequest(gqlContext, ['req']);
124
+ if (!gqlContext[REQUEST_CONTEXT_ID]) {
125
+ Object.defineProperty(gqlContext, REQUEST_CONTEXT_ID, {
129
126
  value: contextId,
130
127
  enumerable: false,
131
128
  configurable: false,
@@ -138,17 +135,17 @@ let OpraApiFactory = class OpraApiFactory {
138
135
  // TODO remove in the next version (backward-compatibility layer)
139
136
  // Left for backward compatibility purposes
140
137
  let contextId;
141
- if (gqlContext && gqlContext[request_constants_1.REQUEST_CONTEXT_ID]) {
142
- contextId = gqlContext[request_constants_1.REQUEST_CONTEXT_ID];
138
+ if (gqlContext && gqlContext[REQUEST_CONTEXT_ID]) {
139
+ contextId = gqlContext[REQUEST_CONTEXT_ID];
143
140
  }
144
141
  else if (gqlContext &&
145
142
  gqlContext.req &&
146
- gqlContext.req[request_constants_1.REQUEST_CONTEXT_ID]) {
147
- contextId = gqlContext.req[request_constants_1.REQUEST_CONTEXT_ID];
143
+ gqlContext.req[REQUEST_CONTEXT_ID]) {
144
+ contextId = gqlContext.req[REQUEST_CONTEXT_ID];
148
145
  }
149
146
  else {
150
- contextId = (0, core_1.createContextId)();
151
- Object.defineProperty(gqlContext, request_constants_1.REQUEST_CONTEXT_ID, {
147
+ contextId = createContextId();
148
+ Object.defineProperty(gqlContext, REQUEST_CONTEXT_ID, {
152
149
  value: contextId,
153
150
  enumerable: false,
154
151
  configurable: false,
@@ -162,33 +159,33 @@ let OpraApiFactory = class OpraApiFactory {
162
159
  const coreModuleArray = [...this.modulesContainer.entries()]
163
160
  .filter(
164
161
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
165
- ([key, { metatype }]) => metatype && metatype.name === internal_core_module_1.InternalCoreModule.name)
162
+ ([key, { metatype }]) => metatype && metatype.name === InternalCoreModule.name)
166
163
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
167
164
  .map(([key, value]) => value);
168
- const coreModuleRef = (0, lodash_head_1.default)(coreModuleArray);
165
+ const coreModuleRef = head(coreModuleArray);
169
166
  if (!coreModuleRef) {
170
167
  return;
171
168
  }
172
- const wrapper = coreModuleRef.getProviderByKey(core_1.REQUEST);
169
+ const wrapper = coreModuleRef.getProviderByKey(REQUEST);
173
170
  wrapper.setInstanceByContextId(contextId, {
174
171
  instance: request,
175
172
  isResolved: true,
176
173
  });
177
174
  }
178
175
  };
179
- tslib_1.__decorate([
180
- (0, common_1.Inject)(),
181
- tslib_1.__metadata("design:type", core_1.ModulesContainer)
176
+ __decorate([
177
+ Inject(),
178
+ __metadata("design:type", ModulesContainer)
182
179
  ], OpraApiFactory.prototype, "modulesContainer", void 0);
183
- tslib_1.__decorate([
184
- (0, common_1.Inject)(),
185
- tslib_1.__metadata("design:type", external_context_creator_1.ExternalContextCreator)
180
+ __decorate([
181
+ Inject(),
182
+ __metadata("design:type", ExternalContextCreator)
186
183
  ], OpraApiFactory.prototype, "externalContextCreator", void 0);
187
- tslib_1.__decorate([
188
- (0, common_1.Inject)(),
189
- tslib_1.__metadata("design:type", nest_explorer_js_1.NestExplorer)
184
+ __decorate([
185
+ Inject(),
186
+ __metadata("design:type", NestExplorer)
190
187
  ], OpraApiFactory.prototype, "explorerService", void 0);
191
- OpraApiFactory = tslib_1.__decorate([
192
- (0, common_1.Injectable)()
188
+ OpraApiFactory = __decorate([
189
+ Injectable()
193
190
  ], OpraApiFactory);
194
- exports.OpraApiFactory = OpraApiFactory;
191
+ export { OpraApiFactory };
@@ -1,25 +1,21 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OpraParamsFactory = void 0;
4
- const handler_paramtype_enum_js_1 = require("../enums/handler-paramtype.enum.js");
5
- class OpraParamsFactory {
1
+ import { HandlerParamType } from '../enums/handler-paramtype.enum.js';
2
+ export class OpraParamsFactory {
6
3
  exchangeKeyForValue(type, data, args) {
7
4
  if (!args) {
8
5
  return null;
9
6
  }
10
7
  args = Array.isArray(args) ? args : [];
11
8
  switch (type) {
12
- case handler_paramtype_enum_js_1.HandlerParamType.CONTEXT:
9
+ case HandlerParamType.CONTEXT:
13
10
  return args[3];
14
- case handler_paramtype_enum_js_1.HandlerParamType.API:
11
+ case HandlerParamType.API:
15
12
  return args[3].api;
16
- case handler_paramtype_enum_js_1.HandlerParamType.REQUEST:
13
+ case HandlerParamType.REQUEST:
17
14
  return args[3].request;
18
- case handler_paramtype_enum_js_1.HandlerParamType.RESPONSE:
15
+ case HandlerParamType.RESPONSE:
19
16
  return args[3].response;
20
17
  default:
21
18
  return null;
22
19
  }
23
20
  }
24
21
  }
25
- exports.OpraParamsFactory = OpraParamsFactory;
package/esm/index.js CHANGED
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- require("reflect-metadata");
5
- tslib_1.__exportStar(require("./opra.module.js"), exports);
6
- tslib_1.__exportStar(require("./decorators/context.decorator.js"), exports);
7
- tslib_1.__exportStar(require("./interfaces/opra-module-options.interface.js"), exports);
1
+ import 'reflect-metadata';
2
+ export * from './opra.module.js';
3
+ export * from './decorators/context.decorator.js';
4
+ export * from './interfaces/opra-module-options.interface.js';
8
5
  // export * as Api from './decorators/api.ns.js';
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,16 +1,13 @@
1
- "use strict";
2
1
  var OpraCoreModule_1;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.OpraCoreModule = void 0;
5
- const tslib_1 = require("tslib");
6
- const crypto = tslib_1.__importStar(require("crypto"));
7
- const common_1 = require("@nestjs/common");
8
- const core_1 = require("@nestjs/core");
9
- const metadata_scanner_1 = require("@nestjs/core/metadata-scanner");
10
- const constants_js_1 = require("./constants.js");
11
- const opra_api_factory_js_1 = require("./factories/opra-api.factory.js");
12
- const nest_explorer_js_1 = require("./services/nest-explorer.js");
13
- const opra_api_loader_js_1 = require("./services/opra-api-loader.js");
2
+ import { __decorate, __metadata, __param } from "tslib";
3
+ import * as crypto from 'crypto';
4
+ import { Inject, Module } from '@nestjs/common';
5
+ import { HttpAdapterHost, ModulesContainer } from '@nestjs/core';
6
+ import { MetadataScanner } from '@nestjs/core/metadata-scanner';
7
+ import { OPRA_INITIALIZER, OPRA_MODULE_ID, OPRA_MODULE_OPTIONS } from './constants.js';
8
+ import { OpraApiFactory } from './factories/opra-api.factory.js';
9
+ import { NestExplorer } from './services/nest-explorer.js';
10
+ import { OpraApiLoader } from './services/opra-api-loader.js';
14
11
  let OpraCoreModule = OpraCoreModule_1 = class OpraCoreModule {
15
12
  constructor(httpAdapterHost, modulesContainer, options, opraServiceLoader) {
16
13
  this.httpAdapterHost = httpAdapterHost;
@@ -25,12 +22,12 @@ let OpraCoreModule = OpraCoreModule_1 = class OpraCoreModule {
25
22
  providers: [
26
23
  ...(options.providers || []),
27
24
  {
28
- provide: constants_js_1.OPRA_MODULE_OPTIONS,
25
+ provide: OPRA_MODULE_OPTIONS,
29
26
  useValue: options,
30
27
  },
31
28
  {
32
- provide: constants_js_1.OPRA_INITIALIZER,
33
- useClass: opra_api_loader_js_1.OpraApiLoader
29
+ provide: OPRA_INITIALIZER,
30
+ useClass: OpraApiLoader
34
31
  }
35
32
  ],
36
33
  exports: [...(options.exports || [])]
@@ -43,12 +40,12 @@ let OpraCoreModule = OpraCoreModule_1 = class OpraCoreModule {
43
40
  providers: [
44
41
  ...(asyncOptions.providers || []),
45
42
  {
46
- provide: constants_js_1.OPRA_MODULE_ID,
43
+ provide: OPRA_MODULE_ID,
47
44
  useValue: crypto.randomUUID()
48
45
  },
49
46
  {
50
- provide: constants_js_1.OPRA_INITIALIZER,
51
- useClass: opra_api_loader_js_1.OpraApiLoader
47
+ provide: OPRA_INITIALIZER,
48
+ useClass: OpraApiLoader
52
49
  },
53
50
  ...this.createAsyncProviders(asyncOptions)
54
51
  ]
@@ -70,7 +67,7 @@ let OpraCoreModule = OpraCoreModule_1 = class OpraCoreModule {
70
67
  static createAsyncOptionsProvider(asyncOptions) {
71
68
  if (asyncOptions.useFactory) {
72
69
  return {
73
- provide: constants_js_1.OPRA_MODULE_OPTIONS,
70
+ provide: OPRA_MODULE_OPTIONS,
74
71
  useFactory: asyncOptions.useFactory,
75
72
  inject: asyncOptions.inject || []
76
73
  };
@@ -78,7 +75,7 @@ let OpraCoreModule = OpraCoreModule_1 = class OpraCoreModule {
78
75
  const useClass = asyncOptions.useClass || asyncOptions.useExisting;
79
76
  if (useClass) {
80
77
  return {
81
- provide: constants_js_1.OPRA_MODULE_OPTIONS,
78
+ provide: OPRA_MODULE_OPTIONS,
82
79
  useFactory: (optionsFactory) => optionsFactory.createOptions(),
83
80
  inject: [useClass]
84
81
  };
@@ -107,17 +104,17 @@ let OpraCoreModule = OpraCoreModule_1 = class OpraCoreModule {
107
104
  await this.opraServiceLoader.stop();
108
105
  }
109
106
  };
110
- OpraCoreModule = OpraCoreModule_1 = tslib_1.__decorate([
111
- (0, common_1.Module)({
107
+ OpraCoreModule = OpraCoreModule_1 = __decorate([
108
+ Module({
112
109
  providers: [
113
- opra_api_factory_js_1.OpraApiFactory,
114
- metadata_scanner_1.MetadataScanner,
115
- nest_explorer_js_1.NestExplorer
110
+ OpraApiFactory,
111
+ MetadataScanner,
112
+ NestExplorer
116
113
  ]
117
114
  }),
118
- tslib_1.__param(2, (0, common_1.Inject)(constants_js_1.OPRA_MODULE_OPTIONS)),
119
- tslib_1.__param(3, (0, common_1.Inject)(constants_js_1.OPRA_INITIALIZER)),
120
- tslib_1.__metadata("design:paramtypes", [core_1.HttpAdapterHost,
121
- core_1.ModulesContainer, Object, opra_api_loader_js_1.OpraApiLoader])
115
+ __param(2, Inject(OPRA_MODULE_OPTIONS)),
116
+ __param(3, Inject(OPRA_INITIALIZER)),
117
+ __metadata("design:paramtypes", [HttpAdapterHost,
118
+ ModulesContainer, Object, OpraApiLoader])
122
119
  ], OpraCoreModule);
123
- exports.OpraCoreModule = OpraCoreModule;
120
+ export { OpraCoreModule };
@@ -1,25 +1,22 @@
1
- "use strict";
2
1
  var OpraModule_1;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.OpraModule = void 0;
5
- const tslib_1 = require("tslib");
6
- const common_1 = require("@nestjs/common");
7
- const opra_core_module_js_1 = require("./opra-core.module.js");
2
+ import { __decorate } from "tslib";
3
+ import { Module } from '@nestjs/common';
4
+ import { OpraCoreModule } from './opra-core.module.js';
8
5
  let OpraModule = OpraModule_1 = class OpraModule {
9
6
  static forRoot(options) {
10
7
  return {
11
8
  module: OpraModule_1,
12
- imports: [opra_core_module_js_1.OpraCoreModule.forRoot(options)]
9
+ imports: [OpraCoreModule.forRoot(options)]
13
10
  };
14
11
  }
15
12
  static forRootAsync(asyncOptions) {
16
13
  return {
17
14
  module: OpraModule_1,
18
- imports: [opra_core_module_js_1.OpraCoreModule.forRootAsync(asyncOptions)]
15
+ imports: [OpraCoreModule.forRootAsync(asyncOptions)]
19
16
  };
20
17
  }
21
18
  };
22
- OpraModule = OpraModule_1 = tslib_1.__decorate([
23
- (0, common_1.Module)({})
19
+ OpraModule = OpraModule_1 = __decorate([
20
+ Module({})
24
21
  ], OpraModule);
25
- exports.OpraModule = OpraModule;
22
+ export { OpraModule };
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NestExplorer = void 0;
4
- const common_1 = require("@opra/common");
5
- class NestExplorer {
1
+ import { METADATA_KEY, OpraSchema } from '@opra/common';
2
+ export class NestExplorer {
6
3
  exploreProviders(rootModule, predicate) {
7
4
  const modules = new Set();
8
5
  const wrappers = new Set();
@@ -28,8 +25,7 @@ class NestExplorer {
28
25
  return !!(wrapper.instance
29
26
  && typeof wrapper.instance === 'object'
30
27
  && wrapper.instance.constructor
31
- && common_1.OpraSchema.isResource(Reflect.getMetadata(common_1.METADATA_KEY, wrapper.instance.constructor)));
28
+ && OpraSchema.isResource(Reflect.getMetadata(METADATA_KEY, wrapper.instance.constructor)));
32
29
  });
33
30
  }
34
31
  }
35
- exports.NestExplorer = NestExplorer;
@@ -1,23 +1,20 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OpraApiLoader = void 0;
4
- const tslib_1 = require("tslib");
5
- const common_1 = require("@nestjs/common");
6
- const core_1 = require("@nestjs/core");
7
- const common_2 = require("@opra/common");
8
- const core_2 = require("@opra/core");
9
- const constants_js_1 = require("../constants.js");
10
- const opra_api_factory_js_1 = require("../factories/opra-api.factory.js");
11
- class OpraApiLoader {
1
+ import { __decorate, __metadata } from "tslib";
2
+ import { Inject, Logger } from '@nestjs/common';
3
+ import { ApplicationConfig, HttpAdapterHost } from '@nestjs/core';
4
+ import { joinPath, normalizePath } from '@opra/common';
5
+ import { OpraExpressAdapter } from '@opra/core';
6
+ import { OPRA_MODULE_OPTIONS } from '../constants.js';
7
+ import { OpraApiFactory } from '../factories/opra-api.factory.js';
8
+ export class OpraApiLoader {
12
9
  constructor() {
13
- this.logger = new common_1.Logger(OpraApiLoader.name, { timestamp: true });
10
+ this.logger = new Logger(OpraApiLoader.name, { timestamp: true });
14
11
  }
15
12
  async initialize(rootModule) {
16
13
  const httpAdapter = this.httpAdapterHost?.httpAdapter;
17
14
  const globalPrefix = this.applicationConfig.getGlobalPrefix();
18
15
  const platformName = httpAdapter.getType();
19
16
  const moduleOptions = this.opraModuleOptions;
20
- const prefix = '/' + (0, common_2.normalizePath)((0, common_2.joinPath)((moduleOptions.useGlobalPrefix !== false ? globalPrefix : ''), moduleOptions.prefix || ''), true);
17
+ const prefix = '/' + normalizePath(joinPath((moduleOptions.useGlobalPrefix !== false ? globalPrefix : ''), moduleOptions.prefix || ''), true);
21
18
  const name = moduleOptions.info?.title || 'untitled service';
22
19
  const options = {
23
20
  ...moduleOptions,
@@ -54,29 +51,28 @@ class OpraApiLoader {
54
51
  const app = httpAdapter.getInstance();
55
52
  let logger = moduleOptions.logger;
56
53
  if (!logger) {
57
- logger = new common_1.Logger(service.info.title);
54
+ logger = new Logger(service.info.title);
58
55
  logger.fatal = logger.error.bind(logger);
59
56
  }
60
- return core_2.OpraExpressAdapter.create(app, service, {
57
+ return OpraExpressAdapter.create(app, service, {
61
58
  logger,
62
59
  ...moduleOptions
63
60
  });
64
61
  }
65
62
  }
66
- tslib_1.__decorate([
67
- (0, common_1.Inject)(),
68
- tslib_1.__metadata("design:type", core_1.HttpAdapterHost)
63
+ __decorate([
64
+ Inject(),
65
+ __metadata("design:type", HttpAdapterHost)
69
66
  ], OpraApiLoader.prototype, "httpAdapterHost", void 0);
70
- tslib_1.__decorate([
71
- (0, common_1.Inject)(),
72
- tslib_1.__metadata("design:type", core_1.ApplicationConfig)
67
+ __decorate([
68
+ Inject(),
69
+ __metadata("design:type", ApplicationConfig)
73
70
  ], OpraApiLoader.prototype, "applicationConfig", void 0);
74
- tslib_1.__decorate([
75
- (0, common_1.Inject)(),
76
- tslib_1.__metadata("design:type", opra_api_factory_js_1.OpraApiFactory)
71
+ __decorate([
72
+ Inject(),
73
+ __metadata("design:type", OpraApiFactory)
77
74
  ], OpraApiLoader.prototype, "opraFactory", void 0);
78
- tslib_1.__decorate([
79
- (0, common_1.Inject)(constants_js_1.OPRA_MODULE_OPTIONS),
80
- tslib_1.__metadata("design:type", Object)
75
+ __decorate([
76
+ Inject(OPRA_MODULE_OPTIONS),
77
+ __metadata("design:type", Object)
81
78
  ], OpraApiLoader.prototype, "opraModuleOptions", void 0);
82
- exports.OpraApiLoader = OpraApiLoader;
package/esm/types.js CHANGED
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,25 +1,19 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getClassName = exports.getClassOrUndefined = exports.isConstructor = void 0;
4
- const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
5
- function isConstructor(obj) {
1
+ import { isFunction, isString } from '@nestjs/common/utils/shared.utils';
2
+ export function isConstructor(obj) {
6
3
  return typeof obj === 'function' &&
7
4
  !!(obj.prototype && obj.prototype.constructor);
8
5
  }
9
- exports.isConstructor = isConstructor;
10
- function getClassOrUndefined(typeOrFunc) {
6
+ export function getClassOrUndefined(typeOrFunc) {
11
7
  return isConstructor(typeOrFunc)
12
8
  ? typeOrFunc
13
- : (0, shared_utils_1.isFunction)(typeOrFunc)
9
+ : isFunction(typeOrFunc)
14
10
  ? typeOrFunc()
15
11
  : undefined;
16
12
  }
17
- exports.getClassOrUndefined = getClassOrUndefined;
18
- function getClassName(nameOrType) {
19
- if ((0, shared_utils_1.isString)(nameOrType)) {
13
+ export function getClassName(nameOrType) {
14
+ if (isString(nameOrType)) {
20
15
  return nameOrType;
21
16
  }
22
17
  const classOrUndefined = getClassOrUndefined(nameOrType);
23
18
  return classOrUndefined && classOrUndefined.name;
24
19
  }
25
- exports.getClassName = getClassName;
@@ -1,10 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getNumberOfArguments = void 0;
4
- const fast_tokenizer_1 = require("fast-tokenizer");
5
- function getNumberOfArguments(fn) {
1
+ import { splitString, tokenize } from 'fast-tokenizer';
2
+ export function getNumberOfArguments(fn) {
6
3
  const functionAsString = fn.toString();
7
- const tokenizer = (0, fast_tokenizer_1.tokenize)(functionAsString, {
4
+ const tokenizer = tokenize(functionAsString, {
8
5
  // keepBrackets: true,
9
6
  keepDelimiters: true,
10
7
  keepQuotes: true,
@@ -24,7 +21,7 @@ function getNumberOfArguments(fn) {
24
21
  else if (k)
25
22
  s += token;
26
23
  }
27
- const x = (0, fast_tokenizer_1.splitString)(s, {
24
+ const x = splitString(s, {
28
25
  brackets: {
29
26
  '{': '}',
30
27
  '(': ')',
@@ -34,4 +31,3 @@ function getNumberOfArguments(fn) {
34
31
  });
35
32
  return x.length > 1 ? x.length : (x[0] ? 1 : 0);
36
33
  }
37
- exports.getNumberOfArguments = getNumberOfArguments;
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createOpraParamDecorator = void 0;
4
- require("reflect-metadata");
5
- const constants_js_1 = require("../constants.js");
1
+ import 'reflect-metadata';
2
+ import { PARAM_ARGS_METADATA } from '../constants.js';
6
3
  function assignMetadata(args, paramType, index, data, ...pipes) {
7
4
  return {
8
5
  ...args,
@@ -13,12 +10,11 @@ function assignMetadata(args, paramType, index, data, ...pipes) {
13
10
  },
14
11
  };
15
12
  }
16
- function createOpraParamDecorator(paramType) {
13
+ export function createOpraParamDecorator(paramType) {
17
14
  return (target, key, index) => {
18
15
  if (!key)
19
16
  return;
20
- const args = Reflect.getMetadata(constants_js_1.PARAM_ARGS_METADATA, target.constructor, key) || {};
21
- Reflect.defineMetadata(constants_js_1.PARAM_ARGS_METADATA, assignMetadata(args, paramType, index), target.constructor, key);
17
+ const args = Reflect.getMetadata(PARAM_ARGS_METADATA, target.constructor, key) || {};
18
+ Reflect.defineMetadata(PARAM_ARGS_METADATA, assignMetadata(args, paramType, index), target.constructor, key);
22
19
  };
23
20
  }
24
- exports.createOpraParamDecorator = createOpraParamDecorator;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opra/nestjs",
3
- "version": "0.16.2",
3
+ "version": "0.17.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.16.2",
29
- "@opra/core": "^0.16.2",
28
+ "@opra/common": "^0.17.0",
29
+ "@opra/core": "^0.17.0",
30
30
  "fast-tokenizer": "^1.2.2",
31
31
  "lodash.head": "^4.0.1",
32
32
  "lodash.identity": "^3.0.0",