@opra/nestjs 0.0.8 → 0.0.11

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.
@@ -1,21 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Query = exports.Service = exports.Response = exports.Request = exports.Context = void 0;
3
+ exports.Query = exports.Service = exports.Response = exports.Context = void 0;
4
4
  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 `ExecutionContext`.
8
+ * parameter with the value of `QueryContext`.
9
9
  */
10
10
  exports.Context = (0, param_utils_js_1.createOpraParamDecorator)(handler_paramtype_enum_js_1.HandlerParamType.CONTEXT);
11
11
  /**
12
12
  * Handler method parameter decorator. Populates the decorated
13
- * parameter with the value of `ExecutionRequest`.
14
- */
15
- exports.Request = (0, param_utils_js_1.createOpraParamDecorator)(handler_paramtype_enum_js_1.HandlerParamType.REQUEST);
16
- /**
17
- * Handler method parameter decorator. Populates the decorated
18
- * parameter with the value of `ExecutionResponse`.
13
+ * parameter with the value of `QueryResponse`.
19
14
  */
20
15
  exports.Response = (0, param_utils_js_1.createOpraParamDecorator)(handler_paramtype_enum_js_1.HandlerParamType.RESPONSE);
21
16
  /**
@@ -5,8 +5,7 @@ var HandlerParamType;
5
5
  (function (HandlerParamType) {
6
6
  HandlerParamType[HandlerParamType["CONTEXT"] = 0] = "CONTEXT";
7
7
  HandlerParamType[HandlerParamType["SERVICE"] = 1] = "SERVICE";
8
- HandlerParamType[HandlerParamType["REQUEST"] = 2] = "REQUEST";
9
- HandlerParamType[HandlerParamType["QUERY"] = 3] = "QUERY";
10
- HandlerParamType[HandlerParamType["RESPONSE"] = 4] = "RESPONSE";
11
- HandlerParamType[HandlerParamType["USER_CONTEXT"] = 5] = "USER_CONTEXT";
8
+ HandlerParamType[HandlerParamType["QUERY"] = 2] = "QUERY";
9
+ HandlerParamType[HandlerParamType["RESPONSE"] = 3] = "RESPONSE";
10
+ HandlerParamType[HandlerParamType["USER_CONTEXT"] = 4] = "USER_CONTEXT";
12
11
  })(HandlerParamType = exports.HandlerParamType || (exports.HandlerParamType = {}));
@@ -13,10 +13,8 @@ class OpraParamsFactory {
13
13
  return args[3];
14
14
  case handler_paramtype_enum_js_1.HandlerParamType.SERVICE:
15
15
  return args[3].service;
16
- case handler_paramtype_enum_js_1.HandlerParamType.REQUEST:
17
- return args[3].request;
18
16
  case handler_paramtype_enum_js_1.HandlerParamType.QUERY:
19
- return args[3].request.query;
17
+ return args[3].query;
20
18
  case handler_paramtype_enum_js_1.HandlerParamType.RESPONSE:
21
19
  return args[3].response;
22
20
  case handler_paramtype_enum_js_1.HandlerParamType.USER_CONTEXT:
@@ -63,8 +63,8 @@ let ServiceFactory = class ServiceFactory {
63
63
  switch (ctx.type) {
64
64
  case 'http':
65
65
  const http = ctx.switchToHttp();
66
- const req = http.getRequest().getInstance();
67
- const res = http.getResponse().getInstance();
66
+ const req = http.getRequestWrapper().getInstance();
67
+ const res = http.getResponseWrapper().getInstance();
68
68
  return preCallback(req, res, noOpFunction, ctx);
69
69
  default:
70
70
  throw new Error(`"${ctx.type}" context type is not implemented yet`);
@@ -77,10 +77,13 @@ let ServiceFactory = class ServiceFactory {
77
77
  value: 'pre_' + methodName
78
78
  });
79
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);
80
+ const hasParamsArgs = Reflect.hasMetadata(constants_js_1.PARAM_ARGS_METADATA, instance.constructor, methodName);
81
+ const patchedFn = prototype[methodName] = function (...args) {
82
+ if (hasParamsArgs)
83
+ return fn.apply(this, args);
84
+ return fn.call(this, args[3]);
83
85
  };
86
+ Reflect.defineMetadata(METHOD_PATCHED, true, patchedFn);
84
87
  Reflect.getMetadataKeys(fn).forEach(k => {
85
88
  const metadata = Reflect.getMetadata(k, fn);
86
89
  Reflect.defineMetadata(k, metadata, patchedFn);
@@ -91,8 +94,8 @@ let ServiceFactory = class ServiceFactory {
91
94
  switch (ctx.type) {
92
95
  case 'http':
93
96
  const http = ctx.switchToHttp();
94
- const req = http.getRequest().getInstance();
95
- const res = http.getResponse().getInstance();
97
+ const req = http.getRequestWrapper().getInstance();
98
+ const res = http.getResponseWrapper().getInstance();
96
99
  return callback(req, res, noOpFunction, ctx);
97
100
  default:
98
101
  throw new Error(`"${ctx.type}" context type is not implemented yet`);
package/cjs/index.js CHANGED
@@ -4,6 +4,5 @@ const tslib_1 = require("tslib");
4
4
  require("reflect-metadata");
5
5
  tslib_1.__exportStar(require("./opra.module.js"), exports);
6
6
  tslib_1.__exportStar(require("./decorators/context.decorator.js"), exports);
7
- tslib_1.__exportStar(require("./interfaces/opra-execution-context.js"), exports);
8
7
  tslib_1.__exportStar(require("./interfaces/opra-module-options.interface.js"), exports);
9
8
  // export * as Api from './decorators/api.ns.js';
@@ -1,16 +1,11 @@
1
1
  /**
2
2
  * Handler method parameter decorator. Populates the decorated
3
- * parameter with the value of `ExecutionContext`.
3
+ * parameter with the value of `QueryContext`.
4
4
  */
5
5
  export declare const Context: ParameterDecorator;
6
6
  /**
7
7
  * Handler method parameter decorator. Populates the decorated
8
- * parameter with the value of `ExecutionRequest`.
9
- */
10
- export declare const Request: ParameterDecorator;
11
- /**
12
- * Handler method parameter decorator. Populates the decorated
13
- * parameter with the value of `ExecutionResponse`.
8
+ * parameter with the value of `QueryResponse`.
14
9
  */
15
10
  export declare const Response: ParameterDecorator;
16
11
  /**
@@ -2,17 +2,12 @@ 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 `ExecutionContext`.
5
+ * parameter with the value of `QueryContext`.
6
6
  */
7
7
  export const Context = createOpraParamDecorator(HandlerParamType.CONTEXT);
8
8
  /**
9
9
  * Handler method parameter decorator. Populates the decorated
10
- * parameter with the value of `ExecutionRequest`.
11
- */
12
- export const Request = createOpraParamDecorator(HandlerParamType.REQUEST);
13
- /**
14
- * Handler method parameter decorator. Populates the decorated
15
- * parameter with the value of `ExecutionResponse`.
10
+ * parameter with the value of `QueryResponse`.
16
11
  */
17
12
  export const Response = createOpraParamDecorator(HandlerParamType.RESPONSE);
18
13
  /**
@@ -1,8 +1,7 @@
1
1
  export declare enum HandlerParamType {
2
2
  CONTEXT = 0,
3
3
  SERVICE = 1,
4
- REQUEST = 2,
5
- QUERY = 3,
6
- RESPONSE = 4,
7
- USER_CONTEXT = 5
4
+ QUERY = 2,
5
+ RESPONSE = 3,
6
+ USER_CONTEXT = 4
8
7
  }
@@ -2,8 +2,7 @@ export var HandlerParamType;
2
2
  (function (HandlerParamType) {
3
3
  HandlerParamType[HandlerParamType["CONTEXT"] = 0] = "CONTEXT";
4
4
  HandlerParamType[HandlerParamType["SERVICE"] = 1] = "SERVICE";
5
- HandlerParamType[HandlerParamType["REQUEST"] = 2] = "REQUEST";
6
- HandlerParamType[HandlerParamType["QUERY"] = 3] = "QUERY";
7
- HandlerParamType[HandlerParamType["RESPONSE"] = 4] = "RESPONSE";
8
- HandlerParamType[HandlerParamType["USER_CONTEXT"] = 5] = "USER_CONTEXT";
5
+ HandlerParamType[HandlerParamType["QUERY"] = 2] = "QUERY";
6
+ HandlerParamType[HandlerParamType["RESPONSE"] = 3] = "RESPONSE";
7
+ HandlerParamType[HandlerParamType["USER_CONTEXT"] = 4] = "USER_CONTEXT";
9
8
  })(HandlerParamType || (HandlerParamType = {}));
@@ -10,10 +10,8 @@ export class OpraParamsFactory {
10
10
  return args[3];
11
11
  case HandlerParamType.SERVICE:
12
12
  return args[3].service;
13
- case HandlerParamType.REQUEST:
14
- return args[3].request;
15
13
  case HandlerParamType.QUERY:
16
- return args[3].request.query;
14
+ return args[3].query;
17
15
  case HandlerParamType.RESPONSE:
18
16
  return args[3].response;
19
17
  case HandlerParamType.USER_CONTEXT:
@@ -60,8 +60,8 @@ let ServiceFactory = class ServiceFactory {
60
60
  switch (ctx.type) {
61
61
  case 'http':
62
62
  const http = ctx.switchToHttp();
63
- const req = http.getRequest().getInstance();
64
- const res = http.getResponse().getInstance();
63
+ const req = http.getRequestWrapper().getInstance();
64
+ const res = http.getResponseWrapper().getInstance();
65
65
  return preCallback(req, res, noOpFunction, ctx);
66
66
  default:
67
67
  throw new Error(`"${ctx.type}" context type is not implemented yet`);
@@ -74,10 +74,13 @@ let ServiceFactory = class ServiceFactory {
74
74
  value: 'pre_' + methodName
75
75
  });
76
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);
77
+ const hasParamsArgs = Reflect.hasMetadata(PARAM_ARGS_METADATA, instance.constructor, methodName);
78
+ const patchedFn = prototype[methodName] = function (...args) {
79
+ if (hasParamsArgs)
80
+ return fn.apply(this, args);
81
+ return fn.call(this, args[3]);
80
82
  };
83
+ Reflect.defineMetadata(METHOD_PATCHED, true, patchedFn);
81
84
  Reflect.getMetadataKeys(fn).forEach(k => {
82
85
  const metadata = Reflect.getMetadata(k, fn);
83
86
  Reflect.defineMetadata(k, metadata, patchedFn);
@@ -88,8 +91,8 @@ let ServiceFactory = class ServiceFactory {
88
91
  switch (ctx.type) {
89
92
  case 'http':
90
93
  const http = ctx.switchToHttp();
91
- const req = http.getRequest().getInstance();
92
- const res = http.getResponse().getInstance();
94
+ const req = http.getRequestWrapper().getInstance();
95
+ const res = http.getResponseWrapper().getInstance();
93
96
  return callback(req, res, noOpFunction, ctx);
94
97
  default:
95
98
  throw new Error(`"${ctx.type}" context type is not implemented yet`);
package/esm/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import 'reflect-metadata';
2
2
  export * from './opra.module.js';
3
3
  export * from './decorators/context.decorator.js';
4
- export * from './interfaces/opra-execution-context.js';
5
4
  export * from './interfaces/opra-module-options.interface.js';
package/esm/index.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import 'reflect-metadata';
2
2
  export * from './opra.module.js';
3
3
  export * from './decorators/context.decorator.js';
4
- export * from './interfaces/opra-execution-context.js';
5
4
  export * from './interfaces/opra-module-options.interface.js';
6
5
  // export * as Api from './decorators/api.ns.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opra/nestjs",
3
- "version": "0.0.8",
3
+ "version": "0.0.11",
4
4
  "description": "Opra NestJS module",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
@@ -25,10 +25,10 @@
25
25
  "clean:cover": "rimraf ../../coverage/nestjs"
26
26
  },
27
27
  "dependencies": {
28
- "@opra/core": "^0.0.8",
29
- "@opra/i18n": "^0.0.8",
30
- "@opra/schema": "^0.0.8",
31
- "@opra/url": "^0.0.8",
28
+ "@opra/core": "^0.0.11",
29
+ "@opra/i18n": "^0.0.11",
30
+ "@opra/schema": "^0.0.11",
31
+ "@opra/url": "^0.0.11",
32
32
  "fast-tokenizer": "^1.1.0",
33
33
  "lodash": "^4.17.21",
34
34
  "reflect-metadata": "^0.1.13"
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OpraExecutionContext = void 0;
4
- var OpraExecutionContext;
5
- (function (OpraExecutionContext) {
6
- function from(source) {
7
- return source.getArgByIndex(4);
8
- }
9
- OpraExecutionContext.from = from;
10
- })(OpraExecutionContext = exports.OpraExecutionContext || (exports.OpraExecutionContext = {}));
@@ -1,6 +0,0 @@
1
- import { ExecutionContext } from '@nestjs/common';
2
- import * as Opra from '@opra/core';
3
- export declare type OpraExecutionContext = Opra.ExecutionContext;
4
- export declare namespace OpraExecutionContext {
5
- function from(source: ExecutionContext): OpraExecutionContext;
6
- }
@@ -1,7 +0,0 @@
1
- export var OpraExecutionContext;
2
- (function (OpraExecutionContext) {
3
- function from(source) {
4
- return source.getArgByIndex(4);
5
- }
6
- OpraExecutionContext.from = from;
7
- })(OpraExecutionContext || (OpraExecutionContext = {}));