@zenofolio/hyper-decor 0.0.3 → 1.0.7

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.
Files changed (154) hide show
  1. package/README.md +64 -1
  2. package/debug.txt +1 -0
  3. package/dist/__internals/constants.d.ts +5 -1
  4. package/dist/__internals/constants.js +5 -1
  5. package/dist/__internals/creators/request.creator.d.ts +2 -3
  6. package/dist/__internals/creators/request.creator.js +5 -3
  7. package/dist/__internals/creators/routes.creator.d.ts +2 -3
  8. package/dist/__internals/creators/routes.creator.js +5 -3
  9. package/dist/__internals/decorator-base.js +47 -11
  10. package/dist/__internals/helpers/imports.helper.d.ts +8 -0
  11. package/dist/__internals/helpers/imports.helper.js +92 -0
  12. package/dist/__internals/helpers/lifecycle.helper.d.ts +3 -0
  13. package/dist/__internals/helpers/lifecycle.helper.js +25 -0
  14. package/dist/__internals/helpers/merge-metadata.js +16 -20
  15. package/dist/__internals/helpers/prepare.helper.d.ts +11 -0
  16. package/dist/__internals/helpers/prepare.helper.js +348 -0
  17. package/dist/__internals/helpers/tree.helper.d.ts +36 -0
  18. package/dist/__internals/helpers/tree.helper.js +81 -0
  19. package/dist/__internals/stores/service.store.d.ts +1 -0
  20. package/dist/__internals/{transform/pass.transfrom.js → stores/service.store.js} +2 -0
  21. package/dist/__internals/transform/middleware.transform.d.ts +3 -0
  22. package/dist/__internals/transform/middleware.transform.js +19 -0
  23. package/dist/__internals/transform/role.transform.js +8 -5
  24. package/dist/__internals/transform/scope.transfrom.d.ts +5 -7
  25. package/dist/__internals/transform/scope.transfrom.js +52 -38
  26. package/dist/__internals/transform/transform.registry.d.ts +33 -0
  27. package/dist/__internals/transform/transform.registry.js +59 -0
  28. package/dist/__internals/utils/function.util.d.ts +1 -4
  29. package/dist/__internals/utils/function.util.js +22 -10
  30. package/dist/common/bootstrap.js +4 -0
  31. package/dist/common/helpers/index.d.ts +1 -0
  32. package/dist/common/helpers/index.js +1 -0
  33. package/dist/common/helpers/scopes.d.ts +3 -3
  34. package/dist/common/helpers/scopes.js +7 -8
  35. package/dist/common/helpers/state.d.ts +17 -0
  36. package/dist/common/helpers/state.js +44 -0
  37. package/dist/common/message-bus.d.ts +11 -0
  38. package/dist/common/message-bus.js +51 -0
  39. package/dist/common/transport.d.ts +9 -0
  40. package/dist/common/transport.js +46 -0
  41. package/dist/decorators/File.d.ts +1 -1
  42. package/dist/decorators/Http.d.ts +20 -13
  43. package/dist/decorators/Http.js +77 -31
  44. package/dist/decorators/HyperApp.d.ts +0 -4
  45. package/dist/decorators/HyperApp.js +16 -182
  46. package/dist/decorators/HyperController.js +2 -1
  47. package/dist/decorators/HyperService.d.ts +15 -0
  48. package/dist/decorators/HyperService.js +29 -0
  49. package/dist/decorators/Messaging.d.ts +10 -0
  50. package/dist/decorators/Messaging.js +22 -0
  51. package/dist/decorators/Middleware.d.ts +5 -4
  52. package/dist/decorators/Middleware.js +33 -19
  53. package/dist/decorators/Output.d.ts +9 -0
  54. package/dist/decorators/Output.js +18 -0
  55. package/dist/decorators/Pass.d.ts +6 -3
  56. package/dist/decorators/Pass.js +6 -3
  57. package/dist/decorators/Role.js +5 -5
  58. package/dist/decorators/Routes.d.ts +14 -13
  59. package/dist/decorators/Scope.js +3 -3
  60. package/dist/decorators/Transform.d.ts +14 -0
  61. package/dist/decorators/Transform.js +18 -0
  62. package/dist/decorators/index.d.ts +3 -0
  63. package/dist/decorators/index.js +3 -0
  64. package/dist/decorators/types.d.ts +45 -10
  65. package/dist/decorators/types.js +4 -0
  66. package/dist/extension.js +11 -2
  67. package/dist/index.d.ts +6 -0
  68. package/dist/index.js +6 -0
  69. package/dist/lib/openapi/collectors/class.collector.d.ts +9 -0
  70. package/dist/lib/openapi/collectors/class.collector.js +67 -0
  71. package/dist/lib/openapi/collectors/index.d.ts +4 -0
  72. package/dist/lib/openapi/collectors/index.js +20 -0
  73. package/dist/lib/openapi/collectors/method.collector.d.ts +2 -0
  74. package/dist/lib/openapi/collectors/method.collector.js +68 -0
  75. package/dist/lib/openapi/collectors/param.collector.d.ts +2 -0
  76. package/dist/lib/openapi/collectors/param.collector.js +64 -0
  77. package/dist/lib/openapi/collectors/schema.collector.d.ts +11 -0
  78. package/dist/lib/openapi/collectors/schema.collector.js +37 -0
  79. package/dist/lib/openapi/constants.d.ts +46 -0
  80. package/dist/lib/openapi/constants.js +61 -0
  81. package/dist/lib/openapi/decorators/api-bearer-auth.decorator.d.ts +2 -0
  82. package/dist/lib/openapi/decorators/api-bearer-auth.decorator.js +10 -0
  83. package/dist/lib/openapi/decorators/api-method.decorator.d.ts +3 -0
  84. package/dist/lib/openapi/decorators/api-method.decorator.js +11 -0
  85. package/dist/lib/openapi/decorators/api-parameter.decorator.d.ts +3 -0
  86. package/dist/lib/openapi/decorators/api-parameter.decorator.js +10 -0
  87. package/dist/lib/openapi/decorators/api-request-body.decorator.d.ts +3 -0
  88. package/dist/lib/openapi/decorators/api-request-body.decorator.js +10 -0
  89. package/dist/lib/openapi/decorators/api-response.decorator.d.ts +3 -0
  90. package/dist/lib/openapi/decorators/api-response.decorator.js +10 -0
  91. package/dist/lib/openapi/decorators/api-security.decorator.d.ts +3 -0
  92. package/dist/lib/openapi/decorators/api-security.decorator.js +10 -0
  93. package/dist/lib/openapi/decorators/api-tag.decorator.d.ts +3 -0
  94. package/dist/lib/openapi/decorators/api-tag.decorator.js +13 -0
  95. package/dist/lib/openapi/decorators/index.d.ts +7 -0
  96. package/dist/lib/openapi/decorators/index.js +23 -0
  97. package/dist/lib/openapi/helpers/index.d.ts +7 -0
  98. package/dist/lib/openapi/helpers/index.js +23 -0
  99. package/dist/lib/openapi/helpers/method.helper.d.ts +3 -0
  100. package/dist/lib/openapi/helpers/method.helper.js +20 -0
  101. package/dist/lib/openapi/helpers/openapi.helper.d.ts +7 -0
  102. package/dist/lib/openapi/helpers/openapi.helper.js +51 -0
  103. package/dist/lib/openapi/helpers/parameter.helper.d.ts +3 -0
  104. package/dist/lib/openapi/helpers/parameter.helper.js +16 -0
  105. package/dist/lib/openapi/helpers/request-body.helper.d.ts +3 -0
  106. package/dist/lib/openapi/helpers/request-body.helper.js +9 -0
  107. package/dist/lib/openapi/helpers/response.helper.d.ts +3 -0
  108. package/dist/lib/openapi/helpers/response.helper.js +18 -0
  109. package/dist/lib/openapi/helpers/security.helper.d.ts +3 -0
  110. package/dist/lib/openapi/helpers/security.helper.js +17 -0
  111. package/dist/lib/openapi/helpers/tag.helper.d.ts +3 -0
  112. package/dist/lib/openapi/helpers/tag.helper.js +10 -0
  113. package/dist/lib/openapi/index.d.ts +6 -0
  114. package/dist/lib/openapi/index.js +22 -0
  115. package/dist/lib/openapi/metadata.registry.d.ts +29 -0
  116. package/dist/lib/openapi/metadata.registry.js +41 -0
  117. package/dist/lib/openapi/types.d.ts +131 -0
  118. package/dist/stores/index.d.ts +1 -0
  119. package/dist/{common/openapi → stores}/index.js +1 -2
  120. package/dist/stores/scope.store.d.ts +14 -0
  121. package/dist/stores/scope.store.js +29 -0
  122. package/dist/type.d.ts +13 -2
  123. package/hyper-express-decorators.d.ts +1 -0
  124. package/package.json +73 -60
  125. package/scripts/clean.js +56 -0
  126. package/scripts/test-server.ts +85 -0
  127. package/tsconfig.json +18 -13
  128. package/vitest.config.mjs +30 -0
  129. package/vitest.json +0 -0
  130. package/.mocharc.js +0 -5
  131. package/dist/__internals/store.d.ts +0 -10
  132. package/dist/__internals/store.js +0 -17
  133. package/dist/__internals/stores/middleware.store.d.ts +0 -7
  134. package/dist/__internals/stores/middleware.store.js +0 -19
  135. package/dist/__internals/stores/params.store.d.ts +0 -21
  136. package/dist/__internals/stores/params.store.js +0 -65
  137. package/dist/__internals/stores/routes.store.d.ts +0 -17
  138. package/dist/__internals/stores/routes.store.js +0 -43
  139. package/dist/__internals/stores/store.interface.d.ts +0 -8
  140. package/dist/__internals/transform/method.transform.d.ts +0 -2
  141. package/dist/__internals/transform/method.transform.js +0 -20
  142. package/dist/__internals/transform/pass.transfrom.d.ts +0 -1
  143. package/dist/__internals/utils/mixin.utils.d.ts +0 -11
  144. package/dist/__internals/utils/mixin.utils.js +0 -34
  145. package/dist/__internals/utils/router.d.ts +0 -1
  146. package/dist/__internals/utils/router.js +0 -2
  147. package/dist/common/openapi/collect-class-data.d.ts +0 -21
  148. package/dist/common/openapi/collect-class-data.js +0 -45
  149. package/dist/common/openapi/collect-function-data.d.ts +0 -32
  150. package/dist/common/openapi/collect-function-data.js +0 -70
  151. package/dist/common/openapi/index.d.ts +0 -2
  152. /package/dist/__internals/stores/{index.d.ts → metadata.store.d.ts} +0 -0
  153. /package/dist/__internals/stores/{index.js → metadata.store.js} +0 -0
  154. /package/dist/{__internals/stores/store.interface.js → lib/openapi/types.js} +0 -0
@@ -8,29 +8,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
11
  Object.defineProperty(exports, "__esModule", { value: true });
15
12
  exports.HyperApp = void 0;
16
13
  require("reflect-metadata");
17
- const constants_1 = require("../__internals/constants");
18
14
  const hyper_express_1 = require("hyper-express");
15
+ const tsyringe_1 = require("tsyringe");
16
+ const constants_1 = require("../__internals/constants");
19
17
  const decorator_base_1 = require("../__internals/decorator-base");
20
- const path_util_1 = require("../__internals/utils/path.util");
21
- const scope_transfrom_1 = __importDefault(require("../__internals/transform/scope.transfrom"));
22
- const role_transform_1 = __importDefault(require("../__internals/transform/role.transform"));
23
- const object_util_1 = require("../__internals/utils/object.util");
24
18
  const merge_metadata_1 = require("../__internals/helpers/merge-metadata");
25
- const tsyringe_1 = require("tsyringe");
26
- /**
27
- * Decorator to define the main application class with assigned modules.
28
- * @param modules - List of modules to be used in the application.
29
- */
19
+ const transform_registry_1 = require("../__internals/transform/transform.registry");
20
+ const prepare_helper_1 = require("../__internals/helpers/prepare.helper");
30
21
  const HyperApp = (options) => (0, decorator_base_1.DecoratorHelper)({
31
22
  type: constants_1.KEY_TYPE_APP,
32
23
  key: constants_1.KEY_PARAMS_APP,
33
- options: options !== null && options !== void 0 ? options : { modules: [] },
24
+ options: Object.assign({ modules: [], logger: console.log }, options),
34
25
  }, (options, Target) => {
35
26
  return class extends hyper_express_1.Server {
36
27
  constructor(...args) {
@@ -39,8 +30,14 @@ const HyperApp = (options) => (0, decorator_base_1.DecoratorHelper)({
39
30
  this.storeLogs = {};
40
31
  this.listArguments = args;
41
32
  }
33
+ /** Registers an agnostic transformer (Zod, Joi, etc.) */
34
+ useTransform(transformer) {
35
+ transform_registry_1.transformRegistry.register(transformer);
36
+ return this;
37
+ }
42
38
  prepare() {
43
39
  return __awaiter(this, void 0, void 0, function* () {
40
+ tsyringe_1.container.registerInstance(hyper_express_1.Server, this);
44
41
  this.mergeMetadata(Target);
45
42
  yield this.applyOptions(Target);
46
43
  });
@@ -57,10 +54,11 @@ const HyperApp = (options) => (0, decorator_base_1.DecoratorHelper)({
57
54
  /** Aplica las opciones y prepara la instancia del Target */
58
55
  applyOptions(Target) {
59
56
  return __awaiter(this, void 0, void 0, function* () {
60
- var _a;
61
- yield applyAppOptions(options, Target, this, this.log.bind(this));
57
+ yield (0, prepare_helper_1.prepareApplication)(options, Target, this, this.log.bind(this));
62
58
  const target = Reflect.construct(Target, this.listArguments);
63
- (_a = target === null || target === void 0 ? void 0 : target.onPrepare) === null || _a === void 0 ? void 0 : _a.call(target);
59
+ if (target && typeof target === 'object' && 'onPrepare' in target) {
60
+ target.onPrepare();
61
+ }
64
62
  this.showLogs();
65
63
  });
66
64
  }
@@ -88,6 +86,7 @@ const HyperApp = (options) => (0, decorator_base_1.DecoratorHelper)({
88
86
  content.push("");
89
87
  });
90
88
  (_c = options.logger) === null || _c === void 0 ? void 0 : _c.call(this, content.join("\n"));
89
+ this.storeLogs = {};
91
90
  }
92
91
  };
93
92
  });
@@ -95,168 +94,3 @@ exports.HyperApp = HyperApp;
95
94
  //////////////////////////////////
96
95
  /// Private methods
97
96
  //////////////////////////////////
98
- const if_router = (current) => {
99
- if (!current || !((current === null || current === void 0 ? void 0 : current.prototype) instanceof hyper_express_1.Router))
100
- return new hyper_express_1.Router();
101
- return new current();
102
- };
103
- function getData(target) {
104
- var _a, _b, _c, _d, _e;
105
- const app = (0, decorator_base_1.getDecorData)(constants_1.KEY_PARAMS_APP, target);
106
- const module = (0, decorator_base_1.getDecorData)(constants_1.KEY_PARAMS_MODULE, target);
107
- const controller = (0, decorator_base_1.getDecorData)(constants_1.KEY_TYPE_CONTROLLER, target);
108
- const middlewares = (_a = (0, decorator_base_1.getDecorData)(constants_1.KEY_PARAMS_MIDDLEWARES, target)) !== null && _a !== void 0 ? _a : [];
109
- const scopes = (_b = (0, decorator_base_1.getDecorData)(constants_1.KEY_PARAMS_SCOPE, target)) !== null && _b !== void 0 ? _b : [];
110
- const roles = (_c = (0, decorator_base_1.getDecorData)(constants_1.KEY_PARAMS_ROLE, target)) !== null && _c !== void 0 ? _c : [];
111
- const routes = (_d = (0, decorator_base_1.getDecorData)(constants_1.KEY_PARAMS_ROUTE, target)) !== null && _d !== void 0 ? _d : {
112
- routes: [],
113
- };
114
- const params = (_e = (0, decorator_base_1.getDecorData)(constants_1.KEY_PARAMS_PARAM, target)) !== null && _e !== void 0 ? _e : {};
115
- const pass = (0, decorator_base_1.getDecorData)(constants_1.KEY_PARAMS_PASS, target);
116
- return {
117
- app,
118
- module,
119
- controller,
120
- middlewares,
121
- scopes,
122
- roles,
123
- routes,
124
- params,
125
- pass,
126
- };
127
- }
128
- function applyAppOptions(options, Target, app, log) {
129
- return __awaiter(this, void 0, void 0, function* () {
130
- var _a, _b;
131
- const data = getData(Target);
132
- const prefix = (_a = options.prefix) !== null && _a !== void 0 ? _a : "/";
133
- const services = (_b = options.imports) !== null && _b !== void 0 ? _b : [];
134
- if (data.middlewares.length) {
135
- app.use(...data.middlewares);
136
- log("middleware", `${Target.name} with middlewares: ${data.middlewares.map((e) => e.name).join(", ")}`);
137
- }
138
- (0, scope_transfrom_1.default)(data.scopes, (middleware) => {
139
- app.use(middleware);
140
- log("middleware", `${Target.name} with scopes: ${data.scopes.join(", ")}`);
141
- });
142
- (0, role_transform_1.default)(data.roles, (middleware) => {
143
- app.use(middleware);
144
- log("middleware", `${Target.name} with roles: ${data.roles.join(", ")}`);
145
- });
146
- const routers = yield Promise.all(options.modules.map((module) => __awaiter(this, void 0, void 0, function* () {
147
- var _a, _b;
148
- const path = (_b = (_a = getData(module).module) === null || _a === void 0 ? void 0 : _a.path) !== null && _b !== void 0 ? _b : "/";
149
- return prepareTarget({
150
- target: module,
151
- router: if_router(module),
152
- namespace: `${Target.name}/${module.name}`,
153
- instance: app,
154
- prefix: path,
155
- log,
156
- });
157
- })));
158
- routers.forEach(({ router, path }) => {
159
- app.use((0, path_util_1.join)(prefix, path), router);
160
- });
161
- });
162
- }
163
- function prepareTarget(_a) {
164
- return __awaiter(this, arguments, void 0, function* ({ target, router, prefix = "/", namespace = "", instance, log, }) {
165
- var _b, _c, _d, _e, _f, _g, _h, _j;
166
- const _router = router !== null && router !== void 0 ? router : if_router(target);
167
- const data = getData(target);
168
- const modules = (_c = (_b = data.module) === null || _b === void 0 ? void 0 : _b.modules) !== null && _c !== void 0 ? _c : [];
169
- const controllers = (_e = (_d = data.module) === null || _d === void 0 ? void 0 : _d.controllers) !== null && _e !== void 0 ? _e : [];
170
- const routes = (_f = data.routes) !== null && _f !== void 0 ? _f : [];
171
- const middlewares = (_g = data.middlewares) !== null && _g !== void 0 ? _g : [];
172
- const scopes = (_h = data.scopes) !== null && _h !== void 0 ? _h : [];
173
- const roles = (_j = data.roles) !== null && _j !== void 0 ? _j : [];
174
- ////////////////////////////////
175
- /// Attach Middlewares
176
- ////////////////////////////////
177
- _router.use(...middlewares);
178
- (0, scope_transfrom_1.default)(scopes, (middleware) => _router.use(middleware));
179
- (0, role_transform_1.default)(roles, (middleware) => _router.use(middleware));
180
- ////////////////////////////////
181
- /// Prepare Modules
182
- ////////////////////////////////
183
- yield (0, object_util_1.$each)(modules, (module) => __awaiter(this, void 0, void 0, function* () {
184
- const moduleData = getData(module);
185
- if (!moduleData.module)
186
- return;
187
- const router = yield prepareTarget({
188
- target: module,
189
- namespace: `${namespace}/${module.name}`,
190
- prefix: moduleData.module.path,
191
- instance: tsyringe_1.container.resolve(module),
192
- log,
193
- });
194
- _router.use(router.path, router.router);
195
- }));
196
- // ////////////////////////////////
197
- // /// Prepare Controllers
198
- // ////////////////////////////////
199
- yield (0, object_util_1.$each)(controllers, (controller) => __awaiter(this, void 0, void 0, function* () {
200
- const data = getData(controller);
201
- const controllerData = data.controller;
202
- if (!controllerData)
203
- return;
204
- const router = yield prepareTarget({
205
- target: controller,
206
- namespace: `${namespace}/${controller.name}`,
207
- prefix: controllerData.path,
208
- instance: tsyringe_1.container.resolve(controller),
209
- log,
210
- });
211
- _router.use(router.path, router.router);
212
- }));
213
- ////////////////////////////////
214
- /// Prepare Routes
215
- ////////////////////////////////
216
- yield (0, object_util_1.$each)(Array.from(routes.routes), (route) => __awaiter(this, void 0, void 0, function* () {
217
- if (typeof route !== "object")
218
- return;
219
- yield prepareRoutes({
220
- target: target,
221
- router: _router,
222
- route,
223
- namespace,
224
- instance,
225
- prefix,
226
- log,
227
- });
228
- }));
229
- return {
230
- router: _router,
231
- path: prefix,
232
- };
233
- });
234
- }
235
- function prepareRoutes(_a) {
236
- return __awaiter(this, arguments, void 0, function* ({ target, router, route, instance, namespace, prefix, scopes = [], roles = [], log, }) {
237
- var _b, _c, _d;
238
- const { method, path, handler, propertyKey } = route;
239
- const metadata = getData(handler);
240
- 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 : [];
241
- const $fn = Reflect.get(router, method);
242
- const hasParams = params.length > 0;
243
- if (!$fn)
244
- return;
245
- const middlewares = [...metadata.middlewares];
246
- (0, role_transform_1.default)(metadata.roles, (middleware) => middlewares.push(middleware));
247
- (0, scope_transfrom_1.default)(metadata.scopes, (middleware) => middlewares.push(middleware));
248
- log("routes", `${namespace}/${propertyKey} ${method.toUpperCase()} { ${path} }`);
249
- if (!hasParams) {
250
- $fn.call(router, path, ...middlewares, handler.bind(instance));
251
- }
252
- else {
253
- $fn.call(router, path, ...middlewares, (req, res) => __awaiter(this, void 0, void 0, function* () {
254
- const args = yield Promise.all(params.map((param) => __awaiter(this, void 0, void 0, function* () {
255
- const { resolver, key } = param;
256
- return yield resolver(req, res);
257
- })));
258
- return handler.bind(instance)(...args, req, res);
259
- }));
260
- }
261
- });
262
- }
@@ -4,7 +4,7 @@ exports.HyperController = void 0;
4
4
  const decorator_base_1 = require("../__internals/decorator-base");
5
5
  const constants_1 = require("../__internals/constants");
6
6
  const HyperController = (options) => {
7
- var _a, _b, _c;
7
+ var _a, _b, _c, _d;
8
8
  const isString = typeof options === "string";
9
9
  return (0, decorator_base_1.DecoratorHelper)({
10
10
  type: constants_1.KEY_TYPE_CONTROLLER,
@@ -13,6 +13,7 @@ const HyperController = (options) => {
13
13
  path: isString ? options : (_a = options === null || options === void 0 ? void 0 : options.path) !== null && _a !== void 0 ? _a : "/",
14
14
  roles: isString ? [] : (_b = options === null || options === void 0 ? void 0 : options.roles) !== null && _b !== void 0 ? _b : [],
15
15
  scopes: isString ? [] : (_c = options === null || options === void 0 ? void 0 : options.scopes) !== null && _c !== void 0 ? _c : [],
16
+ imports: isString ? [] : (_d = options === null || options === void 0 ? void 0 : options.imports) !== null && _d !== void 0 ? _d : [],
16
17
  },
17
18
  });
18
19
  };
@@ -0,0 +1,15 @@
1
+ import { Constructor } from "./types";
2
+ interface ServiceDecoratorOptions {
3
+ singleton?: boolean;
4
+ token?: string | symbol;
5
+ }
6
+ /**
7
+ * HyperService decorator is used to register a class as a service in the tsyringe container.
8
+ *
9
+ * No matter where this decorator is applied, the class will be registered in the tsyringe container
10
+ * and included in the service store to be launched when the application starts.
11
+ *
12
+ * @param options.singleton - Whether to register as a singleton (default: true)
13
+ */
14
+ export declare const HyperService: ({ token, singleton, }?: ServiceDecoratorOptions) => (target: Constructor) => void;
15
+ export {};
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HyperService = void 0;
4
+ const tsyringe_1 = require("tsyringe");
5
+ const service_store_1 = require("../__internals/stores/service.store");
6
+ /**
7
+ * HyperService decorator is used to register a class as a service in the tsyringe container.
8
+ *
9
+ * No matter where this decorator is applied, the class will be registered in the tsyringe container
10
+ * and included in the service store to be launched when the application starts.
11
+ *
12
+ * @param options.singleton - Whether to register as a singleton (default: true)
13
+ */
14
+ const HyperService = ({ token, singleton = true, } = {}) => {
15
+ return (target) => {
16
+ const useToken = token !== null && token !== void 0 ? token : target;
17
+ (0, tsyringe_1.injectable)()(target);
18
+ if (!tsyringe_1.container.isRegistered(useToken)) {
19
+ if (singleton) {
20
+ tsyringe_1.container.registerSingleton(useToken, target);
21
+ }
22
+ else {
23
+ tsyringe_1.container.register(useToken, { useClass: target });
24
+ }
25
+ }
26
+ service_store_1.serviceStore.add(target);
27
+ };
28
+ };
29
+ exports.HyperService = HyperService;
@@ -0,0 +1,10 @@
1
+ export interface OnMessageMetadata {
2
+ topic: string;
3
+ propertyKey: string;
4
+ }
5
+ /**
6
+ * OnMessage decorator for subscribing to topics.
7
+ *
8
+ * @param topic The topic or pattern to listen to (e.g. "user.created", "user.*")
9
+ */
10
+ export declare const OnMessage: (topic: string) => (target: any, propertyKey: string | symbol | any, descriptor?: any) => void;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OnMessage = void 0;
4
+ const constants_1 = require("../__internals/constants");
5
+ const decorator_base_1 = require("../__internals/decorator-base");
6
+ /**
7
+ * OnMessage decorator for subscribing to topics.
8
+ *
9
+ * @param topic The topic or pattern to listen to (e.g. "user.created", "user.*")
10
+ */
11
+ const OnMessage = (topic) => {
12
+ return (target, propertyKey, descriptor) => {
13
+ var _a;
14
+ const existing = (_a = Reflect.getMetadata(constants_1.METADATA_KEYS.ON_MESSAGE, target.constructor)) !== null && _a !== void 0 ? _a : [];
15
+ existing.push({
16
+ topic,
17
+ propertyKey: propertyKey.toString(),
18
+ });
19
+ (0, decorator_base_1.defineDecorData)(constants_1.METADATA_KEYS.ON_MESSAGE, existing, target.constructor);
20
+ };
21
+ };
22
+ exports.OnMessage = OnMessage;
@@ -1,18 +1,19 @@
1
1
  import "reflect-metadata";
2
2
  import { MiddlewareHandler } from "hyper-express";
3
+ import { MiddlewareType } from "./types";
3
4
  /**
4
5
  * Middleware decorator to attach middleware to controllers, modules, and routes.
5
6
  */
6
7
  export declare const Middleware: {
7
- (...middleware: MiddlewareHandler[]): ClassDecorator & MethodDecorator;
8
+ (...middleware: MiddlewareType[]): ClassDecorator & MethodDecorator;
8
9
  /**
9
10
  * Exclude middleware from matching paths.
10
11
  *
11
- * @param expresiosn
12
+ * @param expressions
12
13
  * @param middleware
13
14
  * @returns
14
15
  */
15
- exclude(expresiosn: RegExp | RegExp[], middleware: MiddlewareHandler): ClassDecorator & MethodDecorator;
16
+ exclude(expressions: RegExp | RegExp[], middleware: MiddlewareHandler): ClassDecorator & MethodDecorator;
16
17
  /**
17
18
  * Only run middleware on matching paths.
18
19
  *
@@ -20,5 +21,5 @@ export declare const Middleware: {
20
21
  * @param middleware
21
22
  * @returns
22
23
  */
23
- only(expresiosn: RegExp | RegExp[], middleware: MiddlewareHandler): ClassDecorator & MethodDecorator;
24
+ only(expressions: RegExp | RegExp[], middleware: MiddlewareHandler): (Target: any, propertyKey?: any) => void;
24
25
  };
@@ -6,12 +6,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Middleware = void 0;
7
7
  require("reflect-metadata");
8
8
  const constants_1 = require("../__internals/constants");
9
- const stores_1 = __importDefault(require("../__internals/stores"));
9
+ const metadata_store_1 = __importDefault(require("../__internals/stores/metadata.store"));
10
10
  /**
11
11
  * Middleware decorator to attach middleware to controllers, modules, and routes.
12
12
  */
13
- const Middleware = (...middleware) => (Target, propertyKey, descriptor) => {
14
- stores_1.default.define(constants_1.KEY_PARAMS_MIDDLEWARES, middleware, {
13
+ const Middleware = (...middleware) => (Target, propertyKey) => {
14
+ metadata_store_1.default.define(constants_1.KEY_PARAMS_MIDDLEWARES, middleware, {
15
15
  target: Target,
16
16
  propertyKey,
17
17
  });
@@ -20,19 +20,17 @@ exports.Middleware = Middleware;
20
20
  /**
21
21
  * Exclude middleware from matching paths.
22
22
  *
23
- * @param expresiosn
23
+ * @param expressions
24
24
  * @param middleware
25
25
  * @returns
26
26
  */
27
- exports.Middleware.exclude = (expresiosn, middleware) => {
28
- return (0, exports.Middleware)((req, res, next) => {
29
- expresiosn = Array.isArray(expresiosn) ? expresiosn : [expresiosn];
30
- const excluude = expresiosn.some((exp) => exp.test(req.path));
31
- if (excluude)
32
- return next();
33
- return middleware(req, res, next);
34
- });
35
- };
27
+ exports.Middleware.exclude =
28
+ (expressions, middleware) => (Target, propertyKey) => {
29
+ metadata_store_1.default.define(constants_1.KEY_PARAMS_MIDDLEWARES, buildHandler("exclude", expressions, middleware), {
30
+ target: Target,
31
+ propertyKey,
32
+ });
33
+ };
36
34
  /**
37
35
  * Only run middleware on matching paths.
38
36
  *
@@ -40,12 +38,28 @@ exports.Middleware.exclude = (expresiosn, middleware) => {
40
38
  * @param middleware
41
39
  * @returns
42
40
  */
43
- exports.Middleware.only = (expresiosn, middleware) => {
44
- return (0, exports.Middleware)((req, res, next) => {
45
- expresiosn = Array.isArray(expresiosn) ? expresiosn : [expresiosn];
46
- const only = expresiosn.some((exp) => exp.test(req.path));
47
- if (!only)
41
+ exports.Middleware.only =
42
+ (expressions, middleware) => (Target, propertyKey) => {
43
+ metadata_store_1.default.define(constants_1.KEY_PARAMS_MIDDLEWARES, buildHandler("only", expressions, middleware), {
44
+ target: Target,
45
+ propertyKey,
46
+ });
47
+ };
48
+ /**
49
+ *
50
+ * Helper function to build middleware handlers for "only" and "exclude" modes.
51
+ *
52
+ * @param mode
53
+ * @param expresions
54
+ * @returns
55
+ */
56
+ const buildHandler = (mode, expressions, middleware) => {
57
+ const matchers = Array.isArray(expressions) ? expressions : [expressions];
58
+ return (req, res, next) => {
59
+ const matches = matchers.some((rx) => rx.test(req.path));
60
+ if ((mode === "only" && !matches) || (mode === "exclude" && matches)) {
48
61
  return next();
62
+ }
49
63
  return middleware(req, res, next);
50
- });
64
+ };
51
65
  };
@@ -0,0 +1,9 @@
1
+ import "reflect-metadata";
2
+ /**
3
+ * Decorator to explicitly mark a method for response transformation and OpenAPI documentation.
4
+ *
5
+ * @param schema The schema or DTO class for the successful response (200).
6
+ * @example
7
+ * \@Output(UserDto)
8
+ */
9
+ export declare function Output(schema?: any): (target: any, propertyKey?: any, descriptor?: PropertyDescriptor) => void;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Output = Output;
4
+ require("reflect-metadata");
5
+ const decorator_base_1 = require("../__internals/decorator-base");
6
+ const constants_1 = require("../__internals/constants");
7
+ /**
8
+ * Decorator to explicitly mark a method for response transformation and OpenAPI documentation.
9
+ *
10
+ * @param schema The schema or DTO class for the successful response (200).
11
+ * @example
12
+ * \@Output(UserDto)
13
+ */
14
+ function Output(schema) {
15
+ return (target, propertyKey, descriptor) => {
16
+ (0, decorator_base_1.defineDecorData)(constants_1.KEY_OUTPUT_SCHEMA, schema, target, propertyKey);
17
+ };
18
+ }
@@ -3,10 +3,13 @@ interface PassOptions {
3
3
  (req: Request, res: Response): boolean | Promise<boolean>;
4
4
  }
5
5
  /**
6
- * This method will pass all checks if the function returns true.
6
+ * Pass decorator
7
7
  *
8
- * @param options
9
- * @returns
8
+ * This decorator allows bypassing checks when the provided function returns `true`.
9
+ * It can be applied to classes or methods, but not to properties.
10
+ *
11
+ * @param options - A function that returns true to allow bypassing
12
+ * @returns A class or method decorator
10
13
  */
11
14
  export declare const Pass: (options: PassOptions) => ClassDecorator & MethodDecorator;
12
15
  export {};
@@ -8,10 +8,13 @@ const who_helper_1 = __importDefault(require("../__internals/helpers/who.helper"
8
8
  const NotPropertyException_1 = __importDefault(require("../exeptions/NotPropertyException"));
9
9
  const constants_1 = require("../__internals/constants");
10
10
  /**
11
- * This method will pass all checks if the function returns true.
11
+ * Pass decorator
12
12
  *
13
- * @param options
14
- * @returns
13
+ * This decorator allows bypassing checks when the provided function returns `true`.
14
+ * It can be applied to classes or methods, but not to properties.
15
+ *
16
+ * @param options - A function that returns true to allow bypassing
17
+ * @returns A class or method decorator
15
18
  */
16
19
  const Pass = (options) => (target, propertyKey, descriptorOrIndex) => {
17
20
  const { isProperty, isMethod } = (0, who_helper_1.default)(target, propertyKey, descriptorOrIndex);
@@ -5,10 +5,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Role = void 0;
7
7
  require("reflect-metadata");
8
- const constants_1 = require("../__internals/constants");
9
- const who_helper_1 = __importDefault(require("../__internals/helpers/who.helper"));
10
- const stores_1 = __importDefault(require("../__internals/stores"));
11
8
  const exeptions_1 = require("../exeptions");
9
+ const who_helper_1 = __importDefault(require("../__internals/helpers/who.helper"));
10
+ const constants_1 = require("../__internals/constants");
11
+ const metadata_store_1 = __importDefault(require("../__internals/stores/metadata.store"));
12
12
  /**
13
13
  * Role decorator for setting role-based access control.
14
14
  */
@@ -21,11 +21,11 @@ const Role = (roles) => (target, propertyKey, descriptorOrIndex) => {
21
21
  descriptorOrIndex,
22
22
  });
23
23
  }
24
- const { isProperty, isMethod } = (0, who_helper_1.default)(target, propertyKey, descriptorOrIndex);
24
+ const { isProperty } = (0, who_helper_1.default)(target, propertyKey, descriptorOrIndex);
25
25
  if (isProperty) {
26
26
  throw new Error(`Scope decorator cannot be used as parameter decorator in ${target.constructor.name}.${propertyKey}`);
27
27
  }
28
- const list = stores_1.default.list(constants_1.KEY_PARAMS_ROLE, {
28
+ const list = metadata_store_1.default.list(constants_1.KEY_PARAMS_ROLE, {
29
29
  target,
30
30
  propertyKey,
31
31
  });
@@ -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;
@@ -7,16 +7,16 @@ exports.Scope = void 0;
7
7
  require("reflect-metadata");
8
8
  const constants_1 = require("../__internals/constants");
9
9
  const who_helper_1 = __importDefault(require("../__internals/helpers/who.helper"));
10
- const stores_1 = __importDefault(require("../__internals/stores"));
10
+ const metadata_store_1 = __importDefault(require("../__internals/stores/metadata.store"));
11
11
  /**
12
12
  * Scope decorator for defining access scopes.
13
13
  */
14
14
  const Scope = (scopes) => (target, propertyKey, descriptorOrIndex) => {
15
- const { isProperty, isMethod } = (0, who_helper_1.default)(target, propertyKey, descriptorOrIndex);
15
+ const { isProperty } = (0, who_helper_1.default)(target, propertyKey, descriptorOrIndex);
16
16
  if (isProperty) {
17
17
  throw new Error(`Scope decorator cannot be used as parameter decorator in ${target.constructor.name}.${propertyKey}`);
18
18
  }
19
- const list = stores_1.default.list(constants_1.KEY_PARAMS_SCOPE, {
19
+ const list = metadata_store_1.default.list(constants_1.KEY_PARAMS_SCOPE, {
20
20
  target,
21
21
  propertyKey,
22
22
  });
@@ -0,0 +1,14 @@
1
+ import "reflect-metadata";
2
+ export interface TransformOptions {
3
+ /**
4
+ * Where to extract the data from. Defaults to 'body'.
5
+ */
6
+ from?: 'body' | 'query' | 'params' | 'headers';
7
+ }
8
+ /**
9
+ * Agnostic decorator to transform/validate request data using a registered transformer.
10
+ *
11
+ * @param schema The schema or object to be used by the registered transformer.
12
+ * @param options Transformation options.
13
+ */
14
+ export declare function Transform(schema: any, options?: TransformOptions): (target: any, propertyKey: any) => void;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Transform = Transform;
4
+ require("reflect-metadata");
5
+ const constants_1 = require("../__internals/constants");
6
+ const decorator_base_1 = require("../__internals/decorator-base");
7
+ /**
8
+ * Agnostic decorator to transform/validate request data using a registered transformer.
9
+ *
10
+ * @param schema The schema or object to be used by the registered transformer.
11
+ * @param options Transformation options.
12
+ */
13
+ function Transform(schema, options = {}) {
14
+ return (target, propertyKey) => {
15
+ const data = { schema, options };
16
+ (0, decorator_base_1.defineDecorData)(constants_1.KEY_PARAMS_TRANSFORM, data, target, propertyKey);
17
+ };
18
+ }
@@ -1,6 +1,7 @@
1
1
  export * from "./HyperApp";
2
2
  export * from "./HyperModule";
3
3
  export * from "./HyperController";
4
+ export * from "./HyperService";
4
5
  export * from "./Middleware";
5
6
  export * from "./Scope";
6
7
  export * from "./Role";
@@ -9,3 +10,5 @@ export * from "./types";
9
10
  export * from "./Http";
10
11
  export * from "./Pass";
11
12
  export * from "./File";
13
+ export * from "./Messaging";
14
+ export * from "./Output";