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