@opra/nestjs 0.4.0 → 0.6.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.
@@ -5,7 +5,7 @@ const handler_paramtype_enum_js_1 = require("../enums/handler-paramtype.enum.js"
5
5
  const param_utils_js_1 = require("../utils/param.utils.js");
6
6
  /**
7
7
  * Handler method parameter decorator. Populates the decorated
8
- * parameter with the value of `QueryContext`.
8
+ * parameter with the value of `RequestContext`.
9
9
  */
10
10
  exports.Context = (0, param_utils_js_1.createOpraParamDecorator)(handler_paramtype_enum_js_1.HandlerParamType.CONTEXT);
11
11
  /**
@@ -2,14 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OpraApiFactory = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const lodash_1 = tslib_1.__importDefault(require("lodash"));
5
+ const lodash_1 = require("lodash");
6
6
  const common_1 = require("@nestjs/common");
7
7
  const core_1 = require("@nestjs/core");
8
8
  const external_context_creator_1 = require("@nestjs/core/helpers/external-context-creator");
9
9
  const injector_1 = require("@nestjs/core/injector/injector");
10
10
  const internal_core_module_1 = require("@nestjs/core/injector/internal-core-module");
11
11
  const request_constants_1 = require("@nestjs/core/router/request/request-constants");
12
- const schema_1 = require("@opra/schema");
12
+ const common_2 = require("@opra/common");
13
13
  const constants_js_1 = require("../constants.js");
14
14
  const handler_paramtype_enum_js_1 = require("../enums/handler-paramtype.enum.js");
15
15
  const nest_explorer_js_1 = require("../services/nest-explorer.js");
@@ -36,7 +36,7 @@ let OpraApiFactory = class OpraApiFactory {
36
36
  const wrappers = this.explorerService.exploreResourceWrappers(rootModule);
37
37
  for (const wrapper of wrappers) {
38
38
  const instance = wrapper.instance;
39
- const resourceDef = Reflect.getMetadata(schema_1.RESOURCE_METADATA, instance.constructor);
39
+ const resourceDef = Reflect.getMetadata(common_2.RESOURCE_METADATA, instance.constructor);
40
40
  /* istanbul ignore next */
41
41
  if (!resourceDef)
42
42
  continue;
@@ -44,7 +44,7 @@ let OpraApiFactory = class OpraApiFactory {
44
44
  /* Wrap resolver functions */
45
45
  const prototype = Object.getPrototypeOf(instance);
46
46
  const isRequestScoped = !wrapper.isDependencyTreeStatic();
47
- const methodsToWrap = schema_1.OpraSchema.isCollectionResource(resourceDef) ? schema_1.collectionMethods : [];
47
+ const methodsToWrap = common_2.OpraSchema.isCollectionResource(resourceDef) ? common_2.collectionMethods : [];
48
48
  for (const methodName of methodsToWrap) {
49
49
  const fn = prototype[methodName];
50
50
  if (typeof fn !== 'function')
@@ -62,8 +62,8 @@ let OpraApiFactory = class OpraApiFactory {
62
62
  switch (ctx.type) {
63
63
  case 'http':
64
64
  const http = ctx.switchToHttp();
65
- const req = http.getRequestWrapper().getInstance();
66
- const res = http.getResponseWrapper().getInstance();
65
+ const req = http.getRequest().getInstance();
66
+ const res = http.getResponse().getInstance();
67
67
  return preCallback(req, res, noOpFunction, ctx);
68
68
  default:
69
69
  throw new Error(`"${ctx.type}" context type is not implemented yet`);
@@ -93,8 +93,8 @@ let OpraApiFactory = class OpraApiFactory {
93
93
  switch (ctx.type) {
94
94
  case 'http':
95
95
  const http = ctx.switchToHttp();
96
- const req = http.getRequestWrapper().getInstance();
97
- const res = http.getResponseWrapper().getInstance();
96
+ const req = http.getRequest().getInstance();
97
+ const res = http.getResponse().getInstance();
98
98
  return callback(req, res, noOpFunction, ctx);
99
99
  default:
100
100
  throw new Error(`"${ctx.type}" context type is not implemented yet`);
@@ -108,9 +108,9 @@ let OpraApiFactory = class OpraApiFactory {
108
108
  });
109
109
  }
110
110
  }
111
- return await schema_1.OpraDocument.create(serviceArgs);
111
+ return await common_2.OpraDocument.create(serviceArgs);
112
112
  }
113
- _createContextCallback(instance, prototype, wrapper, moduleRef, methodName, isRequestScoped, transform = lodash_1.default.identity, contextType, forPre) {
113
+ _createContextCallback(instance, prototype, wrapper, moduleRef, methodName, isRequestScoped, transform = lodash_1.identity, contextType, forPre) {
114
114
  const paramsFactory = this.paramsFactory;
115
115
  const options = !forPre ?
116
116
  { guards: false, interceptors: false, filters: false } : undefined;
@@ -174,7 +174,7 @@ let OpraApiFactory = class OpraApiFactory {
174
174
  ([key, { metatype }]) => metatype && metatype.name === internal_core_module_1.InternalCoreModule.name)
175
175
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
176
176
  .map(([key, value]) => value);
177
- const coreModuleRef = lodash_1.default.head(coreModuleArray);
177
+ const coreModuleRef = (0, lodash_1.head)(coreModuleArray);
178
178
  if (!coreModuleRef) {
179
179
  return;
180
180
  }
@@ -18,7 +18,7 @@ class OpraParamsFactory {
18
18
  case handler_paramtype_enum_js_1.HandlerParamType.RESPONSE:
19
19
  return args[3].response;
20
20
  case handler_paramtype_enum_js_1.HandlerParamType.USER_CONTEXT:
21
- return args[3].userContext;
21
+ return args[3].executionContext.userContext;
22
22
  default:
23
23
  return null;
24
24
  }
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NestExplorer = void 0;
4
- const schema_1 = require("@opra/schema");
4
+ const common_1 = require("@opra/common");
5
5
  class NestExplorer {
6
6
  exploreProviders(rootModule, predicate) {
7
7
  const modules = new Set();
@@ -28,7 +28,7 @@ class NestExplorer {
28
28
  return !!(wrapper.instance
29
29
  && typeof wrapper.instance === 'object'
30
30
  && wrapper.instance.constructor
31
- && Reflect.hasMetadata(schema_1.RESOURCE_METADATA, wrapper.instance.constructor));
31
+ && Reflect.hasMetadata(common_1.RESOURCE_METADATA, wrapper.instance.constructor));
32
32
  });
33
33
  }
34
34
  }
@@ -4,8 +4,8 @@ exports.OpraApiLoader = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const common_1 = require("@nestjs/common");
6
6
  const core_1 = require("@nestjs/core");
7
+ const common_2 = require("@opra/common");
7
8
  const core_2 = require("@opra/core");
8
- const url_1 = require("@opra/url");
9
9
  const constants_js_1 = require("../constants.js");
10
10
  const opra_api_factory_js_1 = require("../factories/opra-api.factory.js");
11
11
  class OpraApiLoader {
@@ -20,7 +20,7 @@ class OpraApiLoader {
20
20
  const globalPrefix = this.applicationConfig.getGlobalPrefix();
21
21
  const platformName = httpAdapter.getType();
22
22
  const moduleOptions = this.opraModuleOptions;
23
- const prefix = '/' + (0, url_1.normalizePath)((0, url_1.joinPath)((moduleOptions.useGlobalPrefix !== false ? globalPrefix : ''), moduleOptions.prefix || ''), true);
23
+ const prefix = '/' + (0, common_2.normalizePath)((0, common_2.joinPath)((moduleOptions.useGlobalPrefix !== false ? globalPrefix : ''), moduleOptions.prefix || ''), true);
24
24
  const name = moduleOptions.info?.title || 'untitled service';
25
25
  const options = {
26
26
  ...moduleOptions,
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Handler method parameter decorator. Populates the decorated
3
- * parameter with the value of `QueryContext`.
3
+ * parameter with the value of `RequestContext`.
4
4
  */
5
5
  export declare const Context: ParameterDecorator;
6
6
  /**
@@ -2,7 +2,7 @@ import { HandlerParamType } from '../enums/handler-paramtype.enum.js';
2
2
  import { createOpraParamDecorator } from '../utils/param.utils.js';
3
3
  /**
4
4
  * Handler method parameter decorator. Populates the decorated
5
- * parameter with the value of `QueryContext`.
5
+ * parameter with the value of `RequestContext`.
6
6
  */
7
7
  export const Context = createOpraParamDecorator(HandlerParamType.CONTEXT);
8
8
  /**
@@ -1,6 +1,6 @@
1
1
  import { ContextType } from '@nestjs/common';
2
2
  import { Module } from '@nestjs/core/injector/module.js';
3
- import { OpraDocument } from '@opra/schema';
3
+ import { OpraDocument } from '@opra/common';
4
4
  import { OpraModuleOptions } from '../interfaces/opra-module-options.interface.js';
5
5
  export declare class OpraApiFactory {
6
6
  private readonly paramsFactory;
@@ -1,12 +1,12 @@
1
1
  import { __decorate, __metadata } from "tslib";
2
- import _ from 'lodash';
2
+ import { head, identity } from 'lodash';
3
3
  import { Inject, Injectable } from '@nestjs/common';
4
4
  import { ContextIdFactory, createContextId, ModulesContainer, REQUEST } from '@nestjs/core';
5
5
  import { ExternalContextCreator } from '@nestjs/core/helpers/external-context-creator';
6
6
  import { Injector } from '@nestjs/core/injector/injector';
7
7
  import { InternalCoreModule } from '@nestjs/core/injector/internal-core-module';
8
8
  import { REQUEST_CONTEXT_ID } from '@nestjs/core/router/request/request-constants';
9
- import { collectionMethods, OpraDocument, OpraSchema, RESOURCE_METADATA } from '@opra/schema';
9
+ import { collectionMethods, OpraDocument, OpraSchema, RESOURCE_METADATA } from '@opra/common';
10
10
  import { PARAM_ARGS_METADATA } from '../constants.js';
11
11
  import { HandlerParamType } from '../enums/handler-paramtype.enum.js';
12
12
  import { NestExplorer } from '../services/nest-explorer.js';
@@ -59,8 +59,8 @@ let OpraApiFactory = class OpraApiFactory {
59
59
  switch (ctx.type) {
60
60
  case 'http':
61
61
  const http = ctx.switchToHttp();
62
- const req = http.getRequestWrapper().getInstance();
63
- const res = http.getResponseWrapper().getInstance();
62
+ const req = http.getRequest().getInstance();
63
+ const res = http.getResponse().getInstance();
64
64
  return preCallback(req, res, noOpFunction, ctx);
65
65
  default:
66
66
  throw new Error(`"${ctx.type}" context type is not implemented yet`);
@@ -90,8 +90,8 @@ let OpraApiFactory = class OpraApiFactory {
90
90
  switch (ctx.type) {
91
91
  case 'http':
92
92
  const http = ctx.switchToHttp();
93
- const req = http.getRequestWrapper().getInstance();
94
- const res = http.getResponseWrapper().getInstance();
93
+ const req = http.getRequest().getInstance();
94
+ const res = http.getResponse().getInstance();
95
95
  return callback(req, res, noOpFunction, ctx);
96
96
  default:
97
97
  throw new Error(`"${ctx.type}" context type is not implemented yet`);
@@ -107,7 +107,7 @@ let OpraApiFactory = class OpraApiFactory {
107
107
  }
108
108
  return await OpraDocument.create(serviceArgs);
109
109
  }
110
- _createContextCallback(instance, prototype, wrapper, moduleRef, methodName, isRequestScoped, transform = _.identity, contextType, forPre) {
110
+ _createContextCallback(instance, prototype, wrapper, moduleRef, methodName, isRequestScoped, transform = identity, contextType, forPre) {
111
111
  const paramsFactory = this.paramsFactory;
112
112
  const options = !forPre ?
113
113
  { guards: false, interceptors: false, filters: false } : undefined;
@@ -171,7 +171,7 @@ let OpraApiFactory = class OpraApiFactory {
171
171
  ([key, { metatype }]) => metatype && metatype.name === InternalCoreModule.name)
172
172
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
173
173
  .map(([key, value]) => value);
174
- const coreModuleRef = _.head(coreModuleArray);
174
+ const coreModuleRef = head(coreModuleArray);
175
175
  if (!coreModuleRef) {
176
176
  return;
177
177
  }
@@ -15,7 +15,7 @@ export class OpraParamsFactory {
15
15
  case HandlerParamType.RESPONSE:
16
16
  return args[3].response;
17
17
  case HandlerParamType.USER_CONTEXT:
18
- return args[3].userContext;
18
+ return args[3].executionContext.userContext;
19
19
  default:
20
20
  return null;
21
21
  }
@@ -1,6 +1,6 @@
1
1
  import { ModuleMetadata, Type } from '@nestjs/common';
2
+ import { OpraSchema } from '@opra/common';
2
3
  import { OpraHttpAdapter } from '@opra/core';
3
- import { OpraSchema } from '@opra/schema';
4
4
  export declare type OpraModuleOptions = OpraHttpAdapter.Options & {
5
5
  info?: OpraSchema.DocumentInfo;
6
6
  /**
@@ -1,4 +1,4 @@
1
- import { RESOURCE_METADATA } from '@opra/schema';
1
+ import { RESOURCE_METADATA } from '@opra/common';
2
2
  export class NestExplorer {
3
3
  exploreProviders(rootModule, predicate) {
4
4
  const modules = new Set();
@@ -1,7 +1,7 @@
1
1
  import { ApplicationConfig, HttpAdapterHost } from '@nestjs/core';
2
2
  import { Module } from '@nestjs/core/injector/module.js';
3
+ import { OpraDocument } from '@opra/common';
3
4
  import { OpraExpressAdapter } from '@opra/core';
4
- import { OpraDocument } from '@opra/schema';
5
5
  import { OpraApiFactory } from '../factories/opra-api.factory.js';
6
6
  import { OpraModuleOptions } from '../interfaces/opra-module-options.interface.js';
7
7
  export declare class OpraApiLoader {
@@ -1,8 +1,8 @@
1
1
  import { __decorate, __metadata } from "tslib";
2
2
  import { Inject, Logger } from '@nestjs/common';
3
3
  import { ApplicationConfig, HttpAdapterHost } from '@nestjs/core';
4
+ import { joinPath, normalizePath } from '@opra/common';
4
5
  import { OpraExpressAdapter } from '@opra/core';
5
- import { joinPath, normalizePath } from '@opra/url';
6
6
  import { OPRA_MODULE_OPTIONS } from '../constants.js';
7
7
  import { OpraApiFactory } from '../factories/opra-api.factory.js';
8
8
  export class OpraApiLoader {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opra/nestjs",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "description": "Opra NestJS module",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
@@ -25,23 +25,21 @@
25
25
  "clean:cover": "rimraf ../../coverage/nestjs"
26
26
  },
27
27
  "dependencies": {
28
- "@opra/core": "^0.4.0",
29
- "@opra/i18n": "^0.4.0",
30
- "@opra/schema": "^0.4.0",
31
- "@opra/url": "^0.4.0",
28
+ "@opra/common": "^0.6.0",
29
+ "@opra/core": "^0.6.0",
32
30
  "fast-tokenizer": "^1.2.0",
33
31
  "lodash": "^4.17.21",
34
32
  "reflect-metadata": "^0.1.13"
35
33
  },
36
34
  "peerDependencies": {
37
- "@nestjs/common": "^9.1.4"
35
+ "@nestjs/common": "^9.2.1"
38
36
  },
39
37
  "devDependencies": {
40
- "@nestjs/platform-express": "^9.1.4",
41
- "@nestjs/testing": "^9.1.4",
42
- "@types/lodash": "^4.14.186",
38
+ "@nestjs/platform-express": "^9.2.1",
39
+ "@nestjs/testing": "^9.2.1",
40
+ "@types/lodash": "^4.14.191",
43
41
  "filedirname": "^2.7.0",
44
- "supertest": "^6.3.0"
42
+ "supertest": "^6.3.2"
45
43
  },
46
44
  "type": "module",
47
45
  "types": "esm/index.d.ts",