@zenofolio/hyper-decor 1.0.53 → 1.0.54

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.
@@ -8,4 +8,4 @@ import { Request, Response } from "hyper-express";
8
8
  * @returns {(path?: string) => MethodDecorator} - A method decorator for defining routes.
9
9
  *
10
10
  */
11
- export default function createRouteDecorator(method: string, resolver?: (req: Request, res: Response) => any): (path?: string) => MethodDecorator & ClassDecorator;
11
+ export default function createRouteDecorator<T extends any = undefined>(method: string, resolver?: (req: Request, res: Response) => any): (path?: string, options?: T) => MethodDecorator & ClassDecorator;
@@ -13,7 +13,7 @@ const decorator_base_1 = require("../decorator-base");
13
13
  *
14
14
  */
15
15
  function createRouteDecorator(method, resolver) {
16
- return (path = "/") => (0, decorator_base_1.DecoratorHelper)({
16
+ return (path = "/", options) => (0, decorator_base_1.DecoratorHelper)({
17
17
  type: constants_1.KEY_TYPE_CONTROLLER,
18
18
  key: constants_1.KEY_PARAMS_ROUTE,
19
19
  targetResolver: (target) => { var _a; return (_a = target.constructor) !== null && _a !== void 0 ? _a : target; },
@@ -32,6 +32,7 @@ function createRouteDecorator(method, resolver) {
32
32
  path,
33
33
  propertyKey,
34
34
  handler: handler,
35
+ options,
35
36
  });
36
37
  return saved;
37
38
  },
@@ -209,7 +209,7 @@ function prepareTarget(_a) {
209
209
  function prepareRoutes(_a) {
210
210
  return __awaiter(this, arguments, void 0, function* ({ target, router, route, instance, namespace, log, }) {
211
211
  var _b, _c, _d;
212
- const { method, path, handler, propertyKey } = route;
212
+ const { method, path, handler, propertyKey, options } = route;
213
213
  const metadata = getData(handler);
214
214
  const params = (_d = (_c = (_b = metadata.params) === null || _b === void 0 ? void 0 : _b.params) === null || _c === void 0 ? void 0 : _c[propertyKey]) !== null && _d !== void 0 ? _d : [];
215
215
  const $fn = Reflect.get(router, method);
@@ -224,6 +224,10 @@ function prepareRoutes(_a) {
224
224
  });
225
225
  log("routes", `${namespace}/${propertyKey} ${method.toUpperCase()} { ${path} }`);
226
226
  if (!hasParams) {
227
+ if (method === "ws" && options) {
228
+ router.ws(path, options, handler.bind(instance));
229
+ return;
230
+ }
227
231
  $fn.call(router, path, ...middlewares, handler.bind(instance));
228
232
  }
229
233
  else {
@@ -1,14 +1,15 @@
1
1
  import "reflect-metadata";
2
- export declare const Get: (path?: string) => MethodDecorator & ClassDecorator;
3
- export declare const Post: (path?: string) => MethodDecorator & ClassDecorator;
4
- export declare const Put: (path?: string) => MethodDecorator & ClassDecorator;
5
- export declare const Delete: (path?: string) => MethodDecorator & ClassDecorator;
6
- export declare const Patch: (path?: string) => MethodDecorator & ClassDecorator;
7
- export declare const Options: (path?: string) => MethodDecorator & ClassDecorator;
8
- export declare const Head: (path?: string) => MethodDecorator & ClassDecorator;
9
- export declare const Trace: (path?: string) => MethodDecorator & ClassDecorator;
10
- export declare const Any: (path?: string) => MethodDecorator & ClassDecorator;
11
- export declare const All: (path?: string) => MethodDecorator & ClassDecorator;
12
- export declare const Connect: (path?: string) => MethodDecorator & ClassDecorator;
13
- export declare const WS: (path?: string) => MethodDecorator & ClassDecorator;
14
- export declare const Upgrade: (path?: string) => MethodDecorator & ClassDecorator;
2
+ import { WSRouteOptions } from "hyper-express/types";
3
+ export declare const Get: (path?: string, options?: undefined) => MethodDecorator & ClassDecorator;
4
+ export declare const Post: (path?: string, options?: undefined) => MethodDecorator & ClassDecorator;
5
+ export declare const Put: (path?: string, options?: undefined) => MethodDecorator & ClassDecorator;
6
+ export declare const Delete: (path?: string, options?: undefined) => MethodDecorator & ClassDecorator;
7
+ export declare const Patch: (path?: string, options?: undefined) => MethodDecorator & ClassDecorator;
8
+ export declare const Options: (path?: string, options?: undefined) => MethodDecorator & ClassDecorator;
9
+ export declare const Head: (path?: string, options?: undefined) => MethodDecorator & ClassDecorator;
10
+ export declare const Trace: (path?: string, options?: undefined) => MethodDecorator & ClassDecorator;
11
+ export declare const Any: (path?: string, options?: undefined) => MethodDecorator & ClassDecorator;
12
+ export declare const All: (path?: string, options?: undefined) => MethodDecorator & ClassDecorator;
13
+ export declare const Connect: (path?: string, options?: undefined) => MethodDecorator & ClassDecorator;
14
+ export declare const WS: (path?: string, options?: WSRouteOptions | undefined) => MethodDecorator & ClassDecorator;
15
+ export declare const Upgrade: (path?: string, options?: undefined) => MethodDecorator & ClassDecorator;
@@ -89,6 +89,7 @@ export interface RouteMetadata {
89
89
  method: string;
90
90
  path: string;
91
91
  propertyKey: string;
92
+ options?: any;
92
93
  handler: (...args: any[]) => any;
93
94
  }
94
95
  export declare abstract class MiddlewareClass {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zenofolio/hyper-decor",
3
- "version": "1.0.53",
3
+ "version": "1.0.54",
4
4
  "description": "Project core with utilities and features",
5
5
  "main": "dist/index.js",
6
6
  "author": "zenozaga",