@opra/nestjs 0.0.5 → 0.0.8

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.
@@ -16,8 +16,9 @@ const handler_paramtype_enum_js_1 = require("../enums/handler-paramtype.enum.js"
16
16
  const nest_explorer_js_1 = require("../services/nest-explorer.js");
17
17
  const function_utils_js_1 = require("../utils/function.utils.js");
18
18
  const params_factory_js_1 = require("./params.factory.js");
19
- const entityHandlers = ['search', 'create', 'read', 'update', 'updateMany', 'delete', 'deleteMany'];
20
19
  const noOpFunction = () => void 0;
20
+ const entityMethods = ['search', 'count', 'create', 'get', 'update', 'updateMany', 'delete', 'deleteMany'];
21
+ const METHOD_PATCHED = 'ServiceFactory.method-patched';
21
22
  let ServiceFactory = class ServiceFactory {
22
23
  paramsFactory = new params_factory_js_1.OpraParamsFactory();
23
24
  injector = new injector_1.Injector();
@@ -44,49 +45,85 @@ let ServiceFactory = class ServiceFactory {
44
45
  /* Wrap resolver functions */
45
46
  const prototype = Object.getPrototypeOf(instance);
46
47
  const isRequestScoped = !wrapper.isDependencyTreeStatic();
47
- if (schema_1.OpraSchema.isEntityResource(resourceDef)) {
48
- for (const x of entityHandlers) {
49
- const fn = instance[x];
50
- if (typeof fn === 'function') {
51
- const methodName = fn.name || x;
52
- const callback = this._createContextCallback(instance, prototype, wrapper, rootModule, methodName, isRequestScoped, undefined, contextType);
53
- const newFn = instance[x] = (ctx) => {
54
- switch (ctx.type) {
55
- case 'http':
56
- const http = ctx.switchToHttp();
57
- return callback(http.getRequest().getInstance(), http.getResponse().getInstance(), noOpFunction, ctx);
58
- default:
59
- throw new Error(`"${ctx.type}" context type is not implemented yet`);
60
- }
61
- };
62
- if (methodName && newFn.name !== methodName)
63
- Object.defineProperty(newFn, 'name', {
64
- configurable: false,
65
- writable: false,
66
- enumerable: true,
67
- value: methodName
68
- });
48
+ const methodsToWrap = schema_1.OpraSchema.isEntityResource(resourceDef) ? entityMethods : [];
49
+ for (const methodName of methodsToWrap) {
50
+ const fn = prototype[methodName];
51
+ if (typeof fn !== 'function')
52
+ continue;
53
+ // We add special non-operational "prepare" method to prototype.
54
+ // This allows us to call Guards, Interceptors etc, before calling handler method
55
+ const oldPreFn = prototype['pre_' + methodName] = noOpFunction;
56
+ // Copy all metadata info
57
+ Reflect.getMetadataKeys(fn).forEach(k => {
58
+ const metadata = Reflect.getMetadata(k, fn);
59
+ Reflect.defineMetadata(k, metadata, oldPreFn);
60
+ });
61
+ const preCallback = this._createContextCallback(instance, prototype, wrapper, rootModule, methodName, isRequestScoped, undefined, contextType, true);
62
+ const newPreFn = instance['pre_' + methodName] = function (ctx) {
63
+ switch (ctx.type) {
64
+ case 'http':
65
+ const http = ctx.switchToHttp();
66
+ const req = http.getRequest().getInstance();
67
+ const res = http.getResponse().getInstance();
68
+ return preCallback(req, res, noOpFunction, ctx);
69
+ default:
70
+ throw new Error(`"${ctx.type}" context type is not implemented yet`);
69
71
  }
72
+ };
73
+ Object.defineProperty(newPreFn, 'name', {
74
+ configurable: false,
75
+ writable: false,
76
+ enumerable: true,
77
+ value: 'pre_' + methodName
78
+ });
79
+ if (!Reflect.hasMetadata(METHOD_PATCHED, fn)) {
80
+ Reflect.defineMetadata(METHOD_PATCHED, true, fn);
81
+ const patchedFn = prototype[methodName] = function (req, res, next, ctx) {
82
+ return fn.call(this, ctx);
83
+ };
84
+ Reflect.getMetadataKeys(fn).forEach(k => {
85
+ const metadata = Reflect.getMetadata(k, fn);
86
+ Reflect.defineMetadata(k, metadata, patchedFn);
87
+ });
70
88
  }
89
+ const callback = this._createContextCallback(instance, prototype, wrapper, rootModule, methodName, isRequestScoped, undefined, contextType, false);
90
+ const newFn = instance[methodName] = function (ctx) {
91
+ switch (ctx.type) {
92
+ case 'http':
93
+ const http = ctx.switchToHttp();
94
+ const req = http.getRequest().getInstance();
95
+ const res = http.getResponse().getInstance();
96
+ return callback(req, res, noOpFunction, ctx);
97
+ default:
98
+ throw new Error(`"${ctx.type}" context type is not implemented yet`);
99
+ }
100
+ };
101
+ Object.defineProperty(newFn, 'name', {
102
+ configurable: false,
103
+ writable: false,
104
+ enumerable: true,
105
+ value: methodName
106
+ });
71
107
  }
72
108
  }
73
109
  return await core_2.OpraService.create(serviceArgs);
74
110
  }
75
- _createContextCallback(instance, prototype, wrapper, moduleRef, methodName, isRequestScoped, transform = lodash_1.default.identity, contextType) {
111
+ _createContextCallback(instance, prototype, wrapper, moduleRef, methodName, isRequestScoped, transform = lodash_1.default.identity, contextType, forPre) {
76
112
  const paramsFactory = this.paramsFactory;
113
+ const options = !forPre ?
114
+ { guards: false, interceptors: false, filters: false } : undefined;
115
+ const fnName = forPre ? 'pre_' + methodName : methodName;
77
116
  if (isRequestScoped) {
78
117
  return async (...args) => {
79
118
  const opraContext = paramsFactory.exchangeKeyForValue(handler_paramtype_enum_js_1.HandlerParamType.CONTEXT, undefined, args);
80
119
  const contextId = this.getContextId(opraContext);
81
120
  this.registerContextProvider(opraContext, contextId);
82
121
  const contextInstance = await this.injector.loadPerContext(instance, moduleRef, moduleRef.providers, contextId);
83
- const callback = this.externalContextCreator.create(contextInstance, transform(contextInstance[methodName]), methodName, constants_js_1.PARAM_ARGS_METADATA, paramsFactory, contextId, wrapper.id, undefined, // contextOptions
84
- opraContext.type);
122
+ const callback = this.externalContextCreator.create(contextInstance, transform(contextInstance[fnName]), methodName, constants_js_1.PARAM_ARGS_METADATA, paramsFactory, contextId, wrapper.id, options, opraContext.type);
85
123
  return callback(...args);
86
124
  };
87
125
  }
88
- return this.externalContextCreator.create(instance, prototype[methodName], methodName, constants_js_1.PARAM_ARGS_METADATA, paramsFactory, undefined, undefined, undefined, // contextOptions
89
- contextType);
126
+ return this.externalContextCreator.create(instance, prototype[fnName], methodName, constants_js_1.PARAM_ARGS_METADATA, paramsFactory, undefined, undefined, options, contextType);
90
127
  }
91
128
  // noinspection JSMethodCanBeStatic
92
129
  getContextId(gqlContext) {
@@ -7,7 +7,6 @@ const crypto = tslib_1.__importStar(require("crypto"));
7
7
  const common_1 = require("@nestjs/common");
8
8
  const core_1 = require("@nestjs/core");
9
9
  const metadata_scanner_1 = require("@nestjs/core/metadata-scanner");
10
- const i18n_1 = require("@opra/i18n");
11
10
  const constants_js_1 = require("./constants.js");
12
11
  const service_factory_js_1 = require("./factories/service.factory.js");
13
12
  const nest_explorer_js_1 = require("./services/nest-explorer.js");
@@ -36,8 +35,7 @@ let OpraCoreModule = OpraCoreModule_1 = class OpraCoreModule {
36
35
  {
37
36
  provide: constants_js_1.OPRA_INITIALIZER,
38
37
  useClass: service_loader_js_1.OpraServiceLoader
39
- },
40
- this.createI18nProvider()
38
+ }
41
39
  ],
42
40
  exports: [...(options.exports || [])]
43
41
  };
@@ -56,30 +54,10 @@ let OpraCoreModule = OpraCoreModule_1 = class OpraCoreModule {
56
54
  provide: constants_js_1.OPRA_INITIALIZER,
57
55
  useClass: service_loader_js_1.OpraServiceLoader
58
56
  },
59
- ...this.createAsyncProviders(asyncOptions),
60
- this.createI18nProvider(),
57
+ ...this.createAsyncProviders(asyncOptions)
61
58
  ]
62
59
  };
63
60
  }
64
- static createI18nProvider() {
65
- return {
66
- provide: i18n_1.I18n,
67
- inject: [constants_js_1.OPRA_MODULE_OPTIONS],
68
- useFactory: async (options) => {
69
- const opts = options.i18n;
70
- const initOptions = {
71
- lng: opts?.lng,
72
- fallbackLng: opts?.fallbackLng,
73
- defaultNS: opts?.defaultNS,
74
- resources: opts?.resources,
75
- resourceDirs: opts?.resourceDirs
76
- };
77
- const instance = i18n_1.I18n.createInstance();
78
- await instance.init(initOptions);
79
- return instance;
80
- }
81
- };
82
- }
83
61
  static createAsyncProviders(asyncOptions) {
84
62
  if (asyncOptions.useExisting || asyncOptions.useFactory)
85
63
  return [this.createAsyncOptionsProvider(asyncOptions)];
@@ -1,12 +1,10 @@
1
1
  "use strict";
2
- var _a;
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  exports.OpraServiceLoader = void 0;
5
4
  const tslib_1 = require("tslib");
6
5
  const common_1 = require("@nestjs/common");
7
6
  const core_1 = require("@nestjs/core");
8
7
  const core_2 = require("@opra/core");
9
- const i18n_1 = require("@opra/i18n");
10
8
  const url_1 = require("@opra/url");
11
9
  const constants_js_1 = require("../constants.js");
12
10
  const service_factory_js_1 = require("../factories/service.factory.js");
@@ -17,7 +15,6 @@ class OpraServiceLoader {
17
15
  applicationConfig;
18
16
  opraFactory;
19
17
  opraModuleOptions;
20
- i18n;
21
18
  async initialize(rootModule) {
22
19
  const httpAdapter = this.httpAdapterHost?.httpAdapter;
23
20
  const globalPrefix = this.applicationConfig.getGlobalPrefix();
@@ -35,7 +32,6 @@ class OpraServiceLoader {
35
32
  this.logger.warn(`No resources found (${name})`);
36
33
  return;
37
34
  }
38
- // serviceConfiguration.i18n = this.i18n;
39
35
  if (platformName === 'express') {
40
36
  this.adapter = await this.registerExpress(serviceHost, options);
41
37
  // else if (platformName === 'fastify')
@@ -59,10 +55,7 @@ class OpraServiceLoader {
59
55
  if (!httpAdapter)
60
56
  return;
61
57
  const app = httpAdapter.getInstance();
62
- return core_2.OpraExpressAdapter.init(app, service, {
63
- i18n: this.i18n,
64
- prefix: moduleOptions.prefix
65
- });
58
+ return core_2.OpraExpressAdapter.init(app, service, moduleOptions);
66
59
  }
67
60
  }
68
61
  tslib_1.__decorate([
@@ -81,8 +74,4 @@ tslib_1.__decorate([
81
74
  (0, common_1.Inject)(constants_js_1.OPRA_MODULE_OPTIONS),
82
75
  tslib_1.__metadata("design:type", Object)
83
76
  ], OpraServiceLoader.prototype, "opraModuleOptions", void 0);
84
- tslib_1.__decorate([
85
- (0, common_1.Inject)(),
86
- tslib_1.__metadata("design:type", typeof (_a = typeof i18n_1.I18n !== "undefined" && i18n_1.I18n) === "function" ? _a : Object)
87
- ], OpraServiceLoader.prototype, "i18n", void 0);
88
77
  exports.OpraServiceLoader = OpraServiceLoader;
@@ -13,8 +13,9 @@ import { HandlerParamType } from '../enums/handler-paramtype.enum.js';
13
13
  import { NestExplorer } from '../services/nest-explorer.js';
14
14
  import { getNumberOfArguments } from '../utils/function.utils.js';
15
15
  import { OpraParamsFactory } from './params.factory.js';
16
- const entityHandlers = ['search', 'create', 'read', 'update', 'updateMany', 'delete', 'deleteMany'];
17
16
  const noOpFunction = () => void 0;
17
+ const entityMethods = ['search', 'count', 'create', 'get', 'update', 'updateMany', 'delete', 'deleteMany'];
18
+ const METHOD_PATCHED = 'ServiceFactory.method-patched';
18
19
  let ServiceFactory = class ServiceFactory {
19
20
  paramsFactory = new OpraParamsFactory();
20
21
  injector = new Injector();
@@ -41,49 +42,85 @@ let ServiceFactory = class ServiceFactory {
41
42
  /* Wrap resolver functions */
42
43
  const prototype = Object.getPrototypeOf(instance);
43
44
  const isRequestScoped = !wrapper.isDependencyTreeStatic();
44
- if (OpraSchema.isEntityResource(resourceDef)) {
45
- for (const x of entityHandlers) {
46
- const fn = instance[x];
47
- if (typeof fn === 'function') {
48
- const methodName = fn.name || x;
49
- const callback = this._createContextCallback(instance, prototype, wrapper, rootModule, methodName, isRequestScoped, undefined, contextType);
50
- const newFn = instance[x] = (ctx) => {
51
- switch (ctx.type) {
52
- case 'http':
53
- const http = ctx.switchToHttp();
54
- return callback(http.getRequest().getInstance(), http.getResponse().getInstance(), noOpFunction, ctx);
55
- default:
56
- throw new Error(`"${ctx.type}" context type is not implemented yet`);
57
- }
58
- };
59
- if (methodName && newFn.name !== methodName)
60
- Object.defineProperty(newFn, 'name', {
61
- configurable: false,
62
- writable: false,
63
- enumerable: true,
64
- value: methodName
65
- });
45
+ const methodsToWrap = OpraSchema.isEntityResource(resourceDef) ? entityMethods : [];
46
+ for (const methodName of methodsToWrap) {
47
+ const fn = prototype[methodName];
48
+ if (typeof fn !== 'function')
49
+ continue;
50
+ // We add special non-operational "prepare" method to prototype.
51
+ // This allows us to call Guards, Interceptors etc, before calling handler method
52
+ const oldPreFn = prototype['pre_' + methodName] = noOpFunction;
53
+ // Copy all metadata info
54
+ Reflect.getMetadataKeys(fn).forEach(k => {
55
+ const metadata = Reflect.getMetadata(k, fn);
56
+ Reflect.defineMetadata(k, metadata, oldPreFn);
57
+ });
58
+ const preCallback = this._createContextCallback(instance, prototype, wrapper, rootModule, methodName, isRequestScoped, undefined, contextType, true);
59
+ const newPreFn = instance['pre_' + methodName] = function (ctx) {
60
+ switch (ctx.type) {
61
+ case 'http':
62
+ const http = ctx.switchToHttp();
63
+ const req = http.getRequest().getInstance();
64
+ const res = http.getResponse().getInstance();
65
+ return preCallback(req, res, noOpFunction, ctx);
66
+ default:
67
+ throw new Error(`"${ctx.type}" context type is not implemented yet`);
66
68
  }
69
+ };
70
+ Object.defineProperty(newPreFn, 'name', {
71
+ configurable: false,
72
+ writable: false,
73
+ enumerable: true,
74
+ value: 'pre_' + methodName
75
+ });
76
+ if (!Reflect.hasMetadata(METHOD_PATCHED, fn)) {
77
+ Reflect.defineMetadata(METHOD_PATCHED, true, fn);
78
+ const patchedFn = prototype[methodName] = function (req, res, next, ctx) {
79
+ return fn.call(this, ctx);
80
+ };
81
+ Reflect.getMetadataKeys(fn).forEach(k => {
82
+ const metadata = Reflect.getMetadata(k, fn);
83
+ Reflect.defineMetadata(k, metadata, patchedFn);
84
+ });
67
85
  }
86
+ const callback = this._createContextCallback(instance, prototype, wrapper, rootModule, methodName, isRequestScoped, undefined, contextType, false);
87
+ const newFn = instance[methodName] = function (ctx) {
88
+ switch (ctx.type) {
89
+ case 'http':
90
+ const http = ctx.switchToHttp();
91
+ const req = http.getRequest().getInstance();
92
+ const res = http.getResponse().getInstance();
93
+ return callback(req, res, noOpFunction, ctx);
94
+ default:
95
+ throw new Error(`"${ctx.type}" context type is not implemented yet`);
96
+ }
97
+ };
98
+ Object.defineProperty(newFn, 'name', {
99
+ configurable: false,
100
+ writable: false,
101
+ enumerable: true,
102
+ value: methodName
103
+ });
68
104
  }
69
105
  }
70
106
  return await OpraService.create(serviceArgs);
71
107
  }
72
- _createContextCallback(instance, prototype, wrapper, moduleRef, methodName, isRequestScoped, transform = _.identity, contextType) {
108
+ _createContextCallback(instance, prototype, wrapper, moduleRef, methodName, isRequestScoped, transform = _.identity, contextType, forPre) {
73
109
  const paramsFactory = this.paramsFactory;
110
+ const options = !forPre ?
111
+ { guards: false, interceptors: false, filters: false } : undefined;
112
+ const fnName = forPre ? 'pre_' + methodName : methodName;
74
113
  if (isRequestScoped) {
75
114
  return async (...args) => {
76
115
  const opraContext = paramsFactory.exchangeKeyForValue(HandlerParamType.CONTEXT, undefined, args);
77
116
  const contextId = this.getContextId(opraContext);
78
117
  this.registerContextProvider(opraContext, contextId);
79
118
  const contextInstance = await this.injector.loadPerContext(instance, moduleRef, moduleRef.providers, contextId);
80
- const callback = this.externalContextCreator.create(contextInstance, transform(contextInstance[methodName]), methodName, PARAM_ARGS_METADATA, paramsFactory, contextId, wrapper.id, undefined, // contextOptions
81
- opraContext.type);
119
+ const callback = this.externalContextCreator.create(contextInstance, transform(contextInstance[fnName]), methodName, PARAM_ARGS_METADATA, paramsFactory, contextId, wrapper.id, options, opraContext.type);
82
120
  return callback(...args);
83
121
  };
84
122
  }
85
- return this.externalContextCreator.create(instance, prototype[methodName], methodName, PARAM_ARGS_METADATA, paramsFactory, undefined, undefined, undefined, // contextOptions
86
- contextType);
123
+ return this.externalContextCreator.create(instance, prototype[fnName], methodName, PARAM_ARGS_METADATA, paramsFactory, undefined, undefined, options, contextType);
87
124
  }
88
125
  // noinspection JSMethodCanBeStatic
89
126
  getContextId(gqlContext) {
@@ -1,43 +1,13 @@
1
1
  import { ModuleMetadata, Type } from '@nestjs/common';
2
- import { FallbackLng, LanguageResource } from '@opra/i18n';
2
+ import { OpraHttpAdapter } from '@opra/core';
3
3
  import { OpraSchema } from '@opra/schema';
4
- export declare type OpraModuleOptions = {
4
+ export declare type OpraModuleOptions = OpraHttpAdapter.Options & {
5
5
  /**
6
6
  * @default true
7
7
  */
8
8
  useGlobalPrefix?: boolean;
9
- prefix?: string;
10
9
  info?: OpraSchema.DocumentInfo;
11
- i18n?: I18nInitOptions;
12
- context?: object | ((request: any, platformName: string) => object | Promise<object>);
13
10
  };
14
- export interface I18nInitOptions {
15
- /**
16
- * Language to use
17
- * @default undefined
18
- */
19
- lng?: string;
20
- /**
21
- * Language to use if translations in user language are not available.
22
- * @default 'dev'
23
- */
24
- fallbackLng?: false | FallbackLng;
25
- /**
26
- * Default namespace used if not passed to translation function
27
- * @default 'translation'
28
- */
29
- defaultNS?: string;
30
- /**
31
- * Resources to initialize with
32
- * @default undefined
33
- */
34
- resources?: LanguageResource;
35
- /**
36
- * Resource directories to initialize with (if not using loading or not appending using addResourceBundle)
37
- * @default undefined
38
- */
39
- resourceDirs?: string[];
40
- }
41
11
  export interface OpraModuleOptionsFactory {
42
12
  createOptions(): Promise<OpraModuleOptions> | OpraModuleOptions;
43
13
  }
@@ -10,7 +10,6 @@ export declare class OpraCoreModule implements OnModuleInit, OnModuleDestroy {
10
10
  constructor(httpAdapterHost: HttpAdapterHost, modulesContainer: ModulesContainer, options: OpraModuleOptions, opraServiceLoader: OpraServiceLoader);
11
11
  static forRoot(options: OpraModuleOptions & Pick<DynamicModule, 'imports' | 'providers' | 'exports'>): DynamicModule;
12
12
  static forRootAsync(asyncOptions: OpraModuleAsyncOptions): DynamicModule;
13
- private static createI18nProvider;
14
13
  private static createAsyncProviders;
15
14
  private static createAsyncOptionsProvider;
16
15
  onModuleInit(): Promise<void>;
@@ -4,7 +4,6 @@ import * as crypto from 'crypto';
4
4
  import { Inject, Module } from '@nestjs/common';
5
5
  import { HttpAdapterHost, ModulesContainer } from '@nestjs/core';
6
6
  import { MetadataScanner } from '@nestjs/core/metadata-scanner';
7
- import { I18n } from '@opra/i18n';
8
7
  import { OPRA_INITIALIZER, OPRA_MODULE_ID, OPRA_MODULE_OPTIONS } from './constants.js';
9
8
  import { ServiceFactory } from './factories/service.factory.js';
10
9
  import { NestExplorer } from './services/nest-explorer.js';
@@ -33,8 +32,7 @@ let OpraCoreModule = OpraCoreModule_1 = class OpraCoreModule {
33
32
  {
34
33
  provide: OPRA_INITIALIZER,
35
34
  useClass: OpraServiceLoader
36
- },
37
- this.createI18nProvider()
35
+ }
38
36
  ],
39
37
  exports: [...(options.exports || [])]
40
38
  };
@@ -53,30 +51,10 @@ let OpraCoreModule = OpraCoreModule_1 = class OpraCoreModule {
53
51
  provide: OPRA_INITIALIZER,
54
52
  useClass: OpraServiceLoader
55
53
  },
56
- ...this.createAsyncProviders(asyncOptions),
57
- this.createI18nProvider(),
54
+ ...this.createAsyncProviders(asyncOptions)
58
55
  ]
59
56
  };
60
57
  }
61
- static createI18nProvider() {
62
- return {
63
- provide: I18n,
64
- inject: [OPRA_MODULE_OPTIONS],
65
- useFactory: async (options) => {
66
- const opts = options.i18n;
67
- const initOptions = {
68
- lng: opts?.lng,
69
- fallbackLng: opts?.fallbackLng,
70
- defaultNS: opts?.defaultNS,
71
- resources: opts?.resources,
72
- resourceDirs: opts?.resourceDirs
73
- };
74
- const instance = I18n.createInstance();
75
- await instance.init(initOptions);
76
- return instance;
77
- }
78
- };
79
- }
80
58
  static createAsyncProviders(asyncOptions) {
81
59
  if (asyncOptions.useExisting || asyncOptions.useFactory)
82
60
  return [this.createAsyncOptionsProvider(asyncOptions)];
@@ -1,7 +1,6 @@
1
1
  import { ApplicationConfig, HttpAdapterHost } from '@nestjs/core';
2
2
  import { Module } from '@nestjs/core/injector/module.js';
3
3
  import { OpraExpressAdapter, OpraService } from '@opra/core';
4
- import { I18n } from '@opra/i18n';
5
4
  import { ServiceFactory } from '../factories/service.factory.js';
6
5
  import { OpraModuleOptions } from '../interfaces/opra-module-options.interface.js';
7
6
  export declare class OpraServiceLoader {
@@ -11,7 +10,6 @@ export declare class OpraServiceLoader {
11
10
  protected readonly applicationConfig: ApplicationConfig;
12
11
  protected readonly opraFactory: ServiceFactory;
13
12
  protected readonly opraModuleOptions: OpraModuleOptions;
14
- protected readonly i18n: I18n;
15
13
  initialize(rootModule: Module): Promise<void>;
16
14
  stop(): Promise<void>;
17
15
  protected registerExpress(service: OpraService, moduleOptions: OpraModuleOptions): Promise<OpraExpressAdapter | undefined>;
@@ -1,9 +1,7 @@
1
- var _a;
2
1
  import { __decorate, __metadata } from "tslib";
3
2
  import { Inject, Logger } from '@nestjs/common';
4
3
  import { ApplicationConfig, HttpAdapterHost } from '@nestjs/core';
5
4
  import { OpraExpressAdapter } from '@opra/core';
6
- import { I18n } from '@opra/i18n';
7
5
  import { joinPath, normalizePath } from '@opra/url';
8
6
  import { OPRA_MODULE_OPTIONS } from '../constants.js';
9
7
  import { ServiceFactory } from '../factories/service.factory.js';
@@ -14,7 +12,6 @@ export class OpraServiceLoader {
14
12
  applicationConfig;
15
13
  opraFactory;
16
14
  opraModuleOptions;
17
- i18n;
18
15
  async initialize(rootModule) {
19
16
  const httpAdapter = this.httpAdapterHost?.httpAdapter;
20
17
  const globalPrefix = this.applicationConfig.getGlobalPrefix();
@@ -32,7 +29,6 @@ export class OpraServiceLoader {
32
29
  this.logger.warn(`No resources found (${name})`);
33
30
  return;
34
31
  }
35
- // serviceConfiguration.i18n = this.i18n;
36
32
  if (platformName === 'express') {
37
33
  this.adapter = await this.registerExpress(serviceHost, options);
38
34
  // else if (platformName === 'fastify')
@@ -56,10 +52,7 @@ export class OpraServiceLoader {
56
52
  if (!httpAdapter)
57
53
  return;
58
54
  const app = httpAdapter.getInstance();
59
- return OpraExpressAdapter.init(app, service, {
60
- i18n: this.i18n,
61
- prefix: moduleOptions.prefix
62
- });
55
+ return OpraExpressAdapter.init(app, service, moduleOptions);
63
56
  }
64
57
  }
65
58
  __decorate([
@@ -78,7 +71,3 @@ __decorate([
78
71
  Inject(OPRA_MODULE_OPTIONS),
79
72
  __metadata("design:type", Object)
80
73
  ], OpraServiceLoader.prototype, "opraModuleOptions", void 0);
81
- __decorate([
82
- Inject(),
83
- __metadata("design:type", typeof (_a = typeof I18n !== "undefined" && I18n) === "function" ? _a : Object)
84
- ], OpraServiceLoader.prototype, "i18n", void 0);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opra/nestjs",
3
- "version": "0.0.5",
3
+ "version": "0.0.8",
4
4
  "description": "Opra NestJS module",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
@@ -25,20 +25,20 @@
25
25
  "clean:cover": "rimraf ../../coverage/nestjs"
26
26
  },
27
27
  "dependencies": {
28
- "@opra/url": "^0.x.x",
29
- "@opra/i18n": "^0.x.x",
30
- "@opra/core": "^0.x.x",
31
- "@opra/schema": "^0.x.x",
28
+ "@opra/core": "^0.0.8",
29
+ "@opra/i18n": "^0.0.8",
30
+ "@opra/schema": "^0.0.8",
31
+ "@opra/url": "^0.0.8",
32
32
  "fast-tokenizer": "^1.1.0",
33
33
  "lodash": "^4.17.21",
34
34
  "reflect-metadata": "^0.1.13"
35
35
  },
36
36
  "peerDependencies": {
37
- "@nestjs/common": "^8.x.x || ^9.x.x"
37
+ "@nestjs/common": "^9.0.11"
38
38
  },
39
39
  "devDependencies": {
40
- "@nestjs/testing": "^9.0.11",
41
40
  "@nestjs/platform-express": "^9.0.11",
41
+ "@nestjs/testing": "^9.0.11",
42
42
  "@types/lodash": "^4.14.185",
43
43
  "filedirname": "^2.7.0",
44
44
  "supertest": "^6.2.4"