@open-norantec/herbal 1.0.2-alpha.34 → 1.0.2-alpha.35

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/dist/core.d.ts CHANGED
@@ -8,12 +8,13 @@ import { Constructor } from 'type-fest';
8
8
  import { AuthAdapter } from './abstracts/auth-adapter.abstract.class';
9
9
  import { PathsObject } from 'zod-openapi/dist/openapi3-ts/dist/model/openapi31';
10
10
  export * from '@nestjs/core';
11
+ declare const HANDLE_REQUEST_SYMBOL: unique symbol;
11
12
  export type MethodHandler<IS extends z.Schema<any>, OS extends z.Schema<any>> = (request: Request, input: unknown, headers: ReturnType<typeof HeaderUtil.parse>) => Promise<{
12
13
  request: z.infer<IS>;
13
14
  response: z.infer<OS>;
14
15
  }>;
15
16
  export declare class HerbalController {
16
- private $handleRequest;
17
+ private [HANDLE_REQUEST_SYMBOL];
17
18
  }
18
19
  type ClientGroups = Array<string> | null | undefined;
19
20
  type ClienttGroupsFactory = (defaultGroupName: string) => ClientGroups;
package/dist/core.js CHANGED
@@ -33,9 +33,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
33
33
  var __metadata = (this && this.__metadata) || function (k, v) {
34
34
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
35
35
  };
36
- var __param = (this && this.__param) || function (paramIndex, decorator) {
37
- return function (target, key) { decorator(target, key, paramIndex); }
38
- };
39
36
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
40
37
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
41
38
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -111,10 +108,12 @@ var sequelize_typescript_1 = require("sequelize-typescript");
111
108
  var decorators_1 = require("./decorators");
112
109
  var zod_openapi_1 = require("zod-openapi");
113
110
  __exportStar(require("@nestjs/core"), exports);
114
- var HerbalController = exports.HerbalController = (function () {
111
+ var HANDLE_REQUEST_SYMBOL = Symbol();
112
+ var HANDLE_REQUEST_INSTANCE_SYMBOL = '$handleRequestInstance';
113
+ var HerbalController = (function () {
115
114
  function HerbalController() {
116
115
  }
117
- HerbalController.prototype.$handleRequest = function (request) {
116
+ HerbalController.prototype[HANDLE_REQUEST_SYMBOL] = function (request) {
118
117
  var _a, _b, _c, _d, _e, _f;
119
118
  return __awaiter(this, void 0, void 0, function () {
120
119
  var callFn, result, error_1;
@@ -170,14 +169,9 @@ var HerbalController = exports.HerbalController = (function () {
170
169
  });
171
170
  });
172
171
  };
173
- __decorate([
174
- __param(0, (0, common_1.Req)()),
175
- __metadata("design:type", Function),
176
- __metadata("design:paramtypes", [Object]),
177
- __metadata("design:returntype", Promise)
178
- ], HerbalController.prototype, "$handleRequest", null);
179
172
  return HerbalController;
180
173
  }());
174
+ exports.HerbalController = HerbalController;
181
175
  var METHOD_POOL = Symbol();
182
176
  var MethodConfig = (function () {
183
177
  function MethodConfig(name, options, callback) {
@@ -440,7 +434,7 @@ function HerbalGuard(options) {
440
434
  _.attempt(function () { return _this.getLogger().log("[trace:".concat(request === null || request === void 0 ? void 0 : request.traceId, ":request:body] ").concat(request.rawBody)); });
441
435
  rawHandlerName = (_e = (_d = context === null || context === void 0 ? void 0 : context.getHandler) === null || _d === void 0 ? void 0 : _d.call(context)) === null || _e === void 0 ? void 0 : _e.name;
442
436
  handlerPropertype = (_g = (_f = context === null || context === void 0 ? void 0 : context.getClass) === null || _f === void 0 ? void 0 : _f.call(context)) === null || _g === void 0 ? void 0 : _g.prototype;
443
- handlerName = string_util_class_1.StringUtil.isFalsyString(rawHandlerName) ? request.methodName : rawHandlerName;
437
+ handlerName = string_util_class_1.StringUtil.isFalsyString(request.methodName) ? rawHandlerName : request.methodName;
444
438
  authAdapters = (_j = (_h = getMethodPool(handlerPropertype)) === null || _h === void 0 ? void 0 : _h.getAuthAdapters) === null || _j === void 0 ? void 0 : _j.call(_h, handlerName);
445
439
  if (authAdapters === null)
446
440
  authAdapters = auth_adapter_decorator_1.AuthAdapters.getAdapters(handlerPropertype, handlerName);
@@ -539,6 +533,7 @@ var ControllerUtil = (function () {
539
533
  function ControllerUtil() {
540
534
  }
541
535
  ControllerUtil.create = function (createOptions) {
536
+ var logger = new common_1.Logger('Herbal');
542
537
  function Controller(options) {
543
538
  return function (target) {
544
539
  var _a;
@@ -549,6 +544,7 @@ var ControllerUtil = (function () {
549
544
  : createOptions.prefix
550
545
  : options.prefix;
551
546
  var controllerName = _.camelCase(target.name.replace(/Controller$/g, ''));
547
+ var paths = [];
552
548
  if (!(options === null || options === void 0 ? void 0 : options.ignoreControllerNamePostfix)) {
553
549
  finalPrefix += "".concat(((_a = finalPrefix === null || finalPrefix === void 0 ? void 0 : finalPrefix.endsWith) === null || _a === void 0 ? void 0 : _a.call(finalPrefix, '/')) ? '' : '/').concat(controllerName);
554
550
  }
@@ -556,7 +552,7 @@ var ControllerUtil = (function () {
556
552
  if (string_util_class_1.StringUtil.isFalsyString(name) || typeof callback !== 'function')
557
553
  return;
558
554
  methodPool.registerMethod(name, options, callback);
559
- (0, common_2.Post)(name.startsWith('/') ? name : "/".concat(name))(target.prototype, '$handleRequest', Object.getOwnPropertyDescriptor(HerbalController.prototype, '$handleRequest'));
555
+ paths.push(name.startsWith('/') ? name : "/".concat(name));
560
556
  };
561
557
  if (!finalPrefix.startsWith('/'))
562
558
  finalPrefix = "/".concat(finalPrefix);
@@ -565,6 +561,20 @@ var ControllerUtil = (function () {
565
561
  Reflect.defineMetadata(METHOD_POOL, methodPool, target.prototype);
566
562
  if (typeof (options === null || options === void 0 ? void 0 : options.methods) === 'function')
567
563
  options.methods(register);
564
+ Object.defineProperty(target.prototype, HANDLE_REQUEST_INSTANCE_SYMBOL, {
565
+ enumerable: false,
566
+ writable: false,
567
+ value: function (request) {
568
+ return this[HANDLE_REQUEST_SYMBOL].call(this, request);
569
+ },
570
+ });
571
+ (0, common_1.Req)()(target.prototype, HANDLE_REQUEST_INSTANCE_SYMBOL, 0);
572
+ if (paths.length > 0) {
573
+ (0, common_2.Post)(paths)(target.prototype, HANDLE_REQUEST_INSTANCE_SYMBOL, Object.getOwnPropertyDescriptor(target.prototype, HANDLE_REQUEST_INSTANCE_SYMBOL));
574
+ paths.forEach(function (path) {
575
+ logger.log("Mapped method: /".concat(controllerName).concat(path));
576
+ });
577
+ }
568
578
  (0, common_2.Controller)(finalPrefix)(target);
569
579
  (0, common_2.UseInterceptors)(ControllerInterceptor)(target);
570
580
  common_2.UseGuards.apply(void 0, __spreadArray(__spreadArray(__spreadArray([HerbalGuard(_.pick(createOptions, ['getTraceId']))], (Array.isArray(options === null || options === void 0 ? void 0 : options.useHeadGuards) ? options.useHeadGuards : []), false), (Array.isArray(createOptions === null || createOptions === void 0 ? void 0 : createOptions.useGuards) ? createOptions.useGuards : []), false), (Array.isArray(options === null || options === void 0 ? void 0 : options.useTailGuards) ? options.useTailGuards : []), false))(target);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-norantec/herbal",
3
- "version": "1.0.2-alpha.34",
3
+ "version": "1.0.2-alpha.35",
4
4
  "description": "Herbal is a builder and toolchain for Nest.js applications",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {