@zenofolio/hyper-decor 1.0.7 → 1.0.8

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 (192) hide show
  1. package/.agent/rules/philosophy.md +103 -0
  2. package/.agent/rules/writing.md +32 -0
  3. package/README.md +103 -201
  4. package/dist/__internals/constants.d.ts +1 -62
  5. package/dist/__internals/constants.js +3 -69
  6. package/dist/__internals/helpers/merge-metadata.d.ts +2 -3
  7. package/dist/__internals/helpers/merge-metadata.js +31 -7
  8. package/dist/__internals/helpers/prepare.helper.d.ts +4 -10
  9. package/dist/__internals/helpers/prepare.helper.js +325 -281
  10. package/dist/__internals/stores/hyper.store.d.ts +5 -0
  11. package/dist/__internals/stores/hyper.store.js +5 -0
  12. package/dist/__internals/stores/index.d.ts +4 -0
  13. package/dist/{lib/openapi/helpers → __internals/stores}/index.js +4 -7
  14. package/dist/__internals/stores/meta.store.d.ts +34 -0
  15. package/dist/__internals/stores/meta.store.js +107 -0
  16. package/dist/{stores → __internals/stores}/scope.store.d.ts +1 -1
  17. package/dist/__internals/transform/middleware.transform.d.ts +1 -1
  18. package/dist/__internals/transform/middleware.transform.js +1 -1
  19. package/dist/__internals/transform/role.transform.d.ts +1 -1
  20. package/dist/__internals/transform/role.transform.js +4 -4
  21. package/dist/__internals/transform/scope.transfrom.d.ts +1 -1
  22. package/dist/__internals/transform/scope.transfrom.js +2 -2
  23. package/dist/__internals/types.d.ts +53 -4
  24. package/dist/common/bootstrap.d.ts +6 -2
  25. package/dist/common/bootstrap.js +49 -10
  26. package/dist/common/testing.d.ts +56 -0
  27. package/dist/common/testing.js +193 -0
  28. package/dist/common/transport.d.ts +1 -0
  29. package/dist/common/transport.js +27 -14
  30. package/dist/constants.d.ts +1 -0
  31. package/dist/constants.js +2 -1
  32. package/dist/decorators.d.ts +1 -0
  33. package/dist/{stores/index.js → decorators.js} +1 -1
  34. package/dist/index.d.ts +7 -5
  35. package/dist/index.js +7 -5
  36. package/dist/lib/event/meta.store.d.ts +4 -0
  37. package/dist/lib/event/meta.store.js +5 -0
  38. package/dist/lib/openapi/collectors/class.collector.d.ts +5 -9
  39. package/dist/lib/openapi/collectors/class.collector.js +6 -63
  40. package/dist/lib/openapi/collectors/index.d.ts +3 -4
  41. package/dist/lib/openapi/collectors/index.js +0 -1
  42. package/dist/lib/openapi/collectors/method.collector.d.ts +6 -1
  43. package/dist/lib/openapi/collectors/method.collector.js +92 -59
  44. package/dist/lib/openapi/collectors/schema.collector.d.ts +3 -8
  45. package/dist/lib/openapi/collectors/schema.collector.js +17 -25
  46. package/dist/lib/openapi/constants.d.ts +1 -0
  47. package/dist/lib/openapi/constants.js +2 -2
  48. package/dist/lib/openapi/decorators.d.ts +16 -0
  49. package/dist/lib/openapi/decorators.js +93 -0
  50. package/dist/lib/openapi/index.d.ts +29 -5
  51. package/dist/lib/openapi/index.js +119 -5
  52. package/dist/lib/openapi/metadata.d.ts +7 -0
  53. package/dist/lib/openapi/metadata.js +8 -0
  54. package/dist/lib/openapi/metadata.registry.d.ts +1 -1
  55. package/dist/lib/server/decorators/File.d.ts +37 -0
  56. package/dist/{decorators → lib/server/decorators}/File.js +62 -75
  57. package/dist/lib/server/decorators/Http.d.ts +12 -0
  58. package/dist/lib/server/decorators/Http.js +56 -0
  59. package/dist/lib/server/decorators/HyperApp.d.ts +7 -0
  60. package/dist/lib/server/decorators/HyperApp.js +14 -0
  61. package/dist/lib/server/decorators/HyperController.d.ts +6 -0
  62. package/dist/lib/server/decorators/HyperController.js +15 -0
  63. package/dist/lib/server/decorators/HyperModule.d.ts +6 -0
  64. package/dist/lib/server/decorators/HyperModule.js +13 -0
  65. package/dist/lib/server/decorators/HyperService.d.ts +12 -0
  66. package/dist/lib/server/decorators/HyperService.js +30 -0
  67. package/dist/lib/server/decorators/Messaging.d.ts +8 -0
  68. package/dist/lib/server/decorators/Messaging.js +19 -0
  69. package/dist/{decorators → lib/server/decorators}/Middleware.d.ts +5 -12
  70. package/dist/lib/server/decorators/Middleware.js +52 -0
  71. package/dist/lib/server/decorators/Output.d.ts +6 -0
  72. package/dist/lib/server/decorators/Output.js +14 -0
  73. package/dist/lib/server/decorators/Pass.d.ts +10 -0
  74. package/dist/lib/server/decorators/Pass.js +13 -0
  75. package/dist/lib/server/decorators/Role.d.ts +7 -0
  76. package/dist/lib/server/decorators/Role.js +14 -0
  77. package/dist/lib/server/decorators/Routes.d.ts +14 -0
  78. package/dist/lib/server/decorators/Routes.js +39 -0
  79. package/dist/lib/server/decorators/Scope.d.ts +7 -0
  80. package/dist/lib/server/decorators/Scope.js +14 -0
  81. package/dist/{decorators → lib/server/decorators}/index.d.ts +6 -4
  82. package/dist/{decorators → lib/server/decorators}/index.js +6 -4
  83. package/dist/lib/server/decorators/metadata.d.ts +1 -0
  84. package/dist/lib/server/decorators/metadata.js +5 -0
  85. package/dist/{decorators → lib/server/decorators}/types.d.ts +16 -15
  86. package/dist/{exeptions → lib/server/exeptions}/HyperException.d.ts +2 -1
  87. package/dist/{exeptions → lib/server/exeptions}/HyperException.js +2 -1
  88. package/dist/{exeptions → lib/server/exeptions}/HyperFileException.js +1 -1
  89. package/dist/{exeptions → lib/server/exeptions}/NotRoleException.js +1 -1
  90. package/dist/{exeptions → lib/server/exeptions}/NotScopeException.js +1 -1
  91. package/dist/{__internals/helpers/tree.helper.d.ts → lib/tree/tree.d.ts} +12 -12
  92. package/dist/lib/tree/tree.js +106 -0
  93. package/package.json +10 -2
  94. package/scripts/clean.js +54 -54
  95. package/scripts/test-server.ts +85 -85
  96. package/vitest.config.mjs +1 -1
  97. package/debug.txt +0 -1
  98. package/dist/__internals/creators/request.creator.d.ts +0 -11
  99. package/dist/__internals/creators/request.creator.js +0 -55
  100. package/dist/__internals/creators/routes.creator.d.ts +0 -9
  101. package/dist/__internals/creators/routes.creator.js +0 -39
  102. package/dist/__internals/decorator-base.d.ts +0 -30
  103. package/dist/__internals/decorator-base.js +0 -122
  104. package/dist/__internals/helpers/imports.helper.d.ts +0 -8
  105. package/dist/__internals/helpers/imports.helper.js +0 -92
  106. package/dist/__internals/helpers/tree.helper.js +0 -81
  107. package/dist/__internals/stores/metadata.store.d.ts +0 -15
  108. package/dist/__internals/stores/metadata.store.js +0 -37
  109. package/dist/decorators/File.d.ts +0 -65
  110. package/dist/decorators/Http.d.ts +0 -62
  111. package/dist/decorators/Http.js +0 -139
  112. package/dist/decorators/HyperApp.d.ts +0 -3
  113. package/dist/decorators/HyperApp.js +0 -96
  114. package/dist/decorators/HyperController.d.ts +0 -2
  115. package/dist/decorators/HyperController.js +0 -20
  116. package/dist/decorators/HyperModule.d.ts +0 -5
  117. package/dist/decorators/HyperModule.js +0 -14
  118. package/dist/decorators/HyperService.d.ts +0 -15
  119. package/dist/decorators/HyperService.js +0 -29
  120. package/dist/decorators/Messaging.d.ts +0 -10
  121. package/dist/decorators/Messaging.js +0 -22
  122. package/dist/decorators/Middleware.js +0 -65
  123. package/dist/decorators/Output.d.ts +0 -9
  124. package/dist/decorators/Output.js +0 -18
  125. package/dist/decorators/Pass.d.ts +0 -15
  126. package/dist/decorators/Pass.js +0 -32
  127. package/dist/decorators/Role.d.ts +0 -6
  128. package/dist/decorators/Role.js +0 -34
  129. package/dist/decorators/Routes.d.ts +0 -15
  130. package/dist/decorators/Routes.js +0 -21
  131. package/dist/decorators/Scope.d.ts +0 -6
  132. package/dist/decorators/Scope.js +0 -25
  133. package/dist/decorators/Transform.d.ts +0 -14
  134. package/dist/decorators/Transform.js +0 -18
  135. package/dist/lib/openapi/collectors/param.collector.d.ts +0 -2
  136. package/dist/lib/openapi/collectors/param.collector.js +0 -64
  137. package/dist/lib/openapi/decorators/api-bearer-auth.decorator.d.ts +0 -2
  138. package/dist/lib/openapi/decorators/api-bearer-auth.decorator.js +0 -10
  139. package/dist/lib/openapi/decorators/api-method.decorator.d.ts +0 -3
  140. package/dist/lib/openapi/decorators/api-method.decorator.js +0 -11
  141. package/dist/lib/openapi/decorators/api-parameter.decorator.d.ts +0 -3
  142. package/dist/lib/openapi/decorators/api-parameter.decorator.js +0 -10
  143. package/dist/lib/openapi/decorators/api-request-body.decorator.d.ts +0 -3
  144. package/dist/lib/openapi/decorators/api-request-body.decorator.js +0 -10
  145. package/dist/lib/openapi/decorators/api-response.decorator.d.ts +0 -3
  146. package/dist/lib/openapi/decorators/api-response.decorator.js +0 -10
  147. package/dist/lib/openapi/decorators/api-security.decorator.d.ts +0 -3
  148. package/dist/lib/openapi/decorators/api-security.decorator.js +0 -10
  149. package/dist/lib/openapi/decorators/api-tag.decorator.d.ts +0 -3
  150. package/dist/lib/openapi/decorators/api-tag.decorator.js +0 -13
  151. package/dist/lib/openapi/decorators/index.d.ts +0 -7
  152. package/dist/lib/openapi/decorators/index.js +0 -23
  153. package/dist/lib/openapi/helpers/index.d.ts +0 -7
  154. package/dist/lib/openapi/helpers/method.helper.d.ts +0 -3
  155. package/dist/lib/openapi/helpers/method.helper.js +0 -20
  156. package/dist/lib/openapi/helpers/openapi.helper.d.ts +0 -7
  157. package/dist/lib/openapi/helpers/openapi.helper.js +0 -51
  158. package/dist/lib/openapi/helpers/parameter.helper.d.ts +0 -3
  159. package/dist/lib/openapi/helpers/parameter.helper.js +0 -16
  160. package/dist/lib/openapi/helpers/request-body.helper.d.ts +0 -3
  161. package/dist/lib/openapi/helpers/request-body.helper.js +0 -9
  162. package/dist/lib/openapi/helpers/response.helper.d.ts +0 -3
  163. package/dist/lib/openapi/helpers/response.helper.js +0 -18
  164. package/dist/lib/openapi/helpers/security.helper.d.ts +0 -3
  165. package/dist/lib/openapi/helpers/security.helper.js +0 -17
  166. package/dist/lib/openapi/helpers/tag.helper.d.ts +0 -3
  167. package/dist/lib/openapi/helpers/tag.helper.js +0 -10
  168. package/dist/stores/index.d.ts +0 -1
  169. package/vitest.json +0 -0
  170. /package/dist/{stores → __internals/stores}/scope.store.js +0 -0
  171. /package/dist/__internals/stores/{service.store.d.ts → serivces.store.d.ts} +0 -0
  172. /package/dist/__internals/stores/{service.store.js → serivces.store.js} +0 -0
  173. /package/dist/{decorators → lib/server/decorators}/types.js +0 -0
  174. /package/dist/{exeptions → lib/server/exeptions}/DuplicateControllerPathException.d.ts +0 -0
  175. /package/dist/{exeptions → lib/server/exeptions}/DuplicateControllerPathException.js +0 -0
  176. /package/dist/{exeptions → lib/server/exeptions}/DuplicatedException.d.ts +0 -0
  177. /package/dist/{exeptions → lib/server/exeptions}/DuplicatedException.js +0 -0
  178. /package/dist/{exeptions → lib/server/exeptions}/DuplicatedHandlerException.d.ts +0 -0
  179. /package/dist/{exeptions → lib/server/exeptions}/DuplicatedHandlerException.js +0 -0
  180. /package/dist/{exeptions → lib/server/exeptions}/HyperFileException.d.ts +0 -0
  181. /package/dist/{exeptions → lib/server/exeptions}/MethodNotFountException.d.ts +0 -0
  182. /package/dist/{exeptions → lib/server/exeptions}/MethodNotFountException.js +0 -0
  183. /package/dist/{exeptions → lib/server/exeptions}/NotPropertyException.d.ts +0 -0
  184. /package/dist/{exeptions → lib/server/exeptions}/NotPropertyException.js +0 -0
  185. /package/dist/{exeptions → lib/server/exeptions}/NotRoleException.d.ts +0 -0
  186. /package/dist/{exeptions → lib/server/exeptions}/NotScopeException.d.ts +0 -0
  187. /package/dist/{exeptions → lib/server/exeptions}/WrongPlaceException.d.ts +0 -0
  188. /package/dist/{exeptions → lib/server/exeptions}/WrongPlaceException.js +0 -0
  189. /package/dist/{exeptions → lib/server/exeptions}/index.d.ts +0 -0
  190. /package/dist/{exeptions → lib/server/exeptions}/index.js +0 -0
  191. /package/dist/{exeptions → lib/server/exeptions}/types.d.ts +0 -0
  192. /package/dist/{exeptions → lib/server/exeptions}/types.js +0 -0
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAppTree = getAppTree;
4
+ const meta_store_1 = require("../../__internals/stores/meta.store");
5
+ const metadata_1 = require("../openapi/metadata");
6
+ const path_util_1 = require("../../__internals/utils/path.util");
7
+ const metadata_registry_1 = require("../openapi/metadata.registry");
8
+ /**
9
+ * Extracts the complete application metadata tree.
10
+ */
11
+ function getAppTree(Target) {
12
+ var _a;
13
+ const root = meta_store_1.Metadata.get(Target);
14
+ const common = (_a = root.server) === null || _a === void 0 ? void 0 : _a.common;
15
+ const prefix = (common === null || common === void 0 ? void 0 : common.prefix) || "/";
16
+ const tree = {
17
+ app: Object.assign(Object.assign({}, (common || {})), { target: Target, fullPath: prefix }),
18
+ modules: {},
19
+ paths: {}
20
+ };
21
+ const modules = (common === null || common === void 0 ? void 0 : common.modules) || [];
22
+ modules.forEach(m => {
23
+ const node = getModuleNode(m, prefix, tree.paths);
24
+ tree.modules[m.name] = node;
25
+ });
26
+ // Apply tree processors
27
+ metadata_registry_1.openApiRegistry.getProcessors().forEach(processor => processor(tree));
28
+ return tree;
29
+ }
30
+ function getModuleNode(Target, parentPath = "", globalPaths = {}) {
31
+ var _a;
32
+ const root = meta_store_1.Metadata.get(Target);
33
+ const common = (_a = root.server) === null || _a === void 0 ? void 0 : _a.common;
34
+ const currentPath = (0, path_util_1.join)(parentPath, (common === null || common === void 0 ? void 0 : common.path) || "");
35
+ const openapi = metadata_1.SwaggerMeta.get(Target); // Fixed: Metadata utility now returns root.common
36
+ // Execute custom collectors
37
+ metadata_registry_1.openApiRegistry.getCollectors("class").forEach(collector => {
38
+ const extra = collector(Target);
39
+ if (extra)
40
+ Object.assign(openapi, extra);
41
+ });
42
+ const node = {
43
+ metadata: common,
44
+ target: Target,
45
+ fullPath: currentPath,
46
+ modules: {},
47
+ controllers: {},
48
+ services: ((common === null || common === void 0 ? void 0 : common.imports) || []),
49
+ openapi: openapi
50
+ };
51
+ ((common === null || common === void 0 ? void 0 : common.modules) || []).forEach(m => {
52
+ node.modules[m.name] = getModuleNode(m, currentPath, globalPaths);
53
+ });
54
+ ((common === null || common === void 0 ? void 0 : common.controllers) || []).forEach(c => {
55
+ node.controllers[c.name] = getControllerNode(c, currentPath, globalPaths);
56
+ });
57
+ return node;
58
+ }
59
+ function getControllerNode(Target, parentPath = "", globalPaths = {}) {
60
+ var _a;
61
+ const root = meta_store_1.Metadata.get(Target);
62
+ const common = (_a = root.server) === null || _a === void 0 ? void 0 : _a.common;
63
+ const currentPath = (0, path_util_1.join)(parentPath, (common === null || common === void 0 ? void 0 : common.path) || "");
64
+ const openapi = metadata_1.SwaggerMeta.get(Target);
65
+ const server = root.server || { common: {}, methods: {} };
66
+ const methods = server.methods;
67
+ const routes = Object.keys(methods).map((propertyKey) => {
68
+ var _a;
69
+ const methodMeta = methods[propertyKey];
70
+ const route = methodMeta.route;
71
+ if (!route)
72
+ return null;
73
+ const params = ((_a = methodMeta.params) === null || _a === void 0 ? void 0 : _a.params) || [];
74
+ const fullPath = (0, path_util_1.join)(currentPath, route.path);
75
+ // Get OpenAPI metadata for the method
76
+ const methodOpenApi = (metadata_1.SwaggerMeta.get(Target, propertyKey) || {});
77
+ // Execute custom collectors
78
+ metadata_registry_1.openApiRegistry.getCollectors("method").forEach((collector) => {
79
+ const extra = collector(Target.prototype, propertyKey);
80
+ if (extra)
81
+ Object.assign(methodOpenApi, extra);
82
+ });
83
+ const routeNode = Object.assign(Object.assign({}, route), { fullPath,
84
+ params, openapi: methodOpenApi });
85
+ // Add to global paths map
86
+ if (!globalPaths[fullPath]) {
87
+ globalPaths[fullPath] = [];
88
+ }
89
+ globalPaths[fullPath].push(routeNode);
90
+ return routeNode;
91
+ }).filter(Boolean);
92
+ // Execute custom collectors
93
+ metadata_registry_1.openApiRegistry.getCollectors("class").forEach(collector => {
94
+ const extra = collector(Target);
95
+ if (extra)
96
+ Object.assign(openapi, extra);
97
+ });
98
+ return {
99
+ metadata: common,
100
+ target: Target,
101
+ fullPath: currentPath,
102
+ routes,
103
+ services: (common === null || common === void 0 ? void 0 : common.imports) || [],
104
+ openapi: openapi
105
+ };
106
+ }
package/package.json CHANGED
@@ -1,15 +1,22 @@
1
1
  {
2
2
  "name": "@zenofolio/hyper-decor",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "Project core with utilities and features",
5
5
  "main": "dist/index.js",
6
6
  "author": "zenozaga",
7
7
  "license": "MIT",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/zenofolio/hyper-decor.git"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/zenofolio/hyper-decor/issues"
14
+ },
15
+ "homepage": "https://github.com/zenofolio/hyper-decor#readme",
8
16
  "scripts": {
9
17
  "test": "vitest run",
10
18
  "test:watch": "vitest",
11
19
  "test:ui": "vitest --ui",
12
- "test:server": "vitest tests/server.bench.ts",
13
20
  "build": "tsc",
14
21
  "publish": "npm run build && npm publish --access public"
15
22
  },
@@ -26,6 +33,7 @@
26
33
  "vitest": "^4.0.18"
27
34
  },
28
35
  "dependencies": {
36
+ "@zenofolio/hyper-decor": "file:",
29
37
  "core-decorators": "^0.20.0",
30
38
  "eventemitter3": "^5.0.4",
31
39
  "file-type": "^19.5.0",
package/scripts/clean.js CHANGED
@@ -1,56 +1,56 @@
1
1
  #!/usr/bin/env node
2
- const fs = require('fs');
3
- const path = require('path');
4
-
5
- try {
6
- // Resolve where uWebSockets.js is actually installed
7
- const mainModuleFile = require.resolve('uWebSockets.js');
8
- // Usually this points to the root directory where the files are
9
- const uwsDir = path.dirname(mainModuleFile);
10
-
11
- // Construct the expected binary name for THIS machine
12
- const expectedBinary = 'uws_' + process.platform + '_' + process.arch + '_' + process.versions.modules + '.node';
13
-
14
- console.log(`[HyperDecor] Analyzing uWebSockets.js native binaries...`);
15
- console.log(`[HyperDecor] Target environment: ${process.platform} ${process.arch} (Node ABI ${process.versions.modules})`);
16
- console.log(`[HyperDecor] Expected binary: ${expectedBinary}`);
17
-
18
- const files = fs.readdirSync(uwsDir);
19
- let deletedCount = 0;
20
- let savedSpace = 0;
21
-
22
- files.forEach((file) => {
23
- // We only care about .node files
24
- if (!file.endsWith('.node')) return;
25
-
26
- // If it's NOT the exact binary we need, delete it
27
- if (file !== expectedBinary) {
28
- const filePath = path.join(uwsDir, file);
29
- const stat = fs.statSync(filePath);
30
- savedSpace += stat.size;
31
- fs.unlinkSync(filePath);
32
- deletedCount++;
33
- }
34
- });
35
-
36
- if (deletedCount > 0) {
37
- const mbSaved = (savedSpace / 1024 / 1024).toFixed(2);
38
- console.log(`[HyperDecor] ✅ Cleaned up ${deletedCount} unused native binaries.`);
39
- console.log(`[HyperDecor] 💾 Freed up ${mbSaved} MB of disk space in node_modules!`);
40
- } else {
41
- // Make sure the expected one actually exists
42
- if (!fs.existsSync(path.join(uwsDir, expectedBinary))) {
43
- console.warn(`[HyperDecor] ⚠️ The expected native binary (${expectedBinary}) was NOT found! uWebSockets.js might not work.`);
44
- } else {
45
- console.log(`[HyperDecor] ✨ No unnecessary binaries found. Everything is already optimized.`);
46
- }
47
- }
48
-
49
- } catch (err) {
50
- if (err.code === 'MODULE_NOT_FOUND') {
51
- console.error(`[HyperDecor] ❌ uWebSockets.js is not installed locally. Skipping cleanup.`);
52
- } else {
53
- console.error(`[HyperDecor] ❌ Error cleaning uWebSockets binaries:`, err.message);
54
- }
55
- process.exit(1);
2
+ const fs = require('fs');
3
+ const path = require('path');
4
+
5
+ try {
6
+ // Resolve where uWebSockets.js is actually installed
7
+ const mainModuleFile = require.resolve('uWebSockets.js');
8
+ // Usually this points to the root directory where the files are
9
+ const uwsDir = path.dirname(mainModuleFile);
10
+
11
+ // Construct the expected binary name for THIS machine
12
+ const expectedBinary = 'uws_' + process.platform + '_' + process.arch + '_' + process.versions.modules + '.node';
13
+
14
+ console.log(`[HyperDecor] Analyzing uWebSockets.js native binaries...`);
15
+ console.log(`[HyperDecor] Target environment: ${process.platform} ${process.arch} (Node ABI ${process.versions.modules})`);
16
+ console.log(`[HyperDecor] Expected binary: ${expectedBinary}`);
17
+
18
+ const files = fs.readdirSync(uwsDir);
19
+ let deletedCount = 0;
20
+ let savedSpace = 0;
21
+
22
+ files.forEach((file) => {
23
+ // We only care about .node files
24
+ if (!file.endsWith('.node')) return;
25
+
26
+ // If it's NOT the exact binary we need, delete it
27
+ if (file !== expectedBinary) {
28
+ const filePath = path.join(uwsDir, file);
29
+ const stat = fs.statSync(filePath);
30
+ savedSpace += stat.size;
31
+ fs.unlinkSync(filePath);
32
+ deletedCount++;
33
+ }
34
+ });
35
+
36
+ if (deletedCount > 0) {
37
+ const mbSaved = (savedSpace / 1024 / 1024).toFixed(2);
38
+ console.log(`[HyperDecor] ✅ Cleaned up ${deletedCount} unused native binaries.`);
39
+ console.log(`[HyperDecor] 💾 Freed up ${mbSaved} MB of disk space in node_modules!`);
40
+ } else {
41
+ // Make sure the expected one actually exists
42
+ if (!fs.existsSync(path.join(uwsDir, expectedBinary))) {
43
+ console.warn(`[HyperDecor] ⚠️ The expected native binary (${expectedBinary}) was NOT found! uWebSockets.js might not work.`);
44
+ } else {
45
+ console.log(`[HyperDecor] ✨ No unnecessary binaries found. Everything is already optimized.`);
46
+ }
47
+ }
48
+
49
+ } catch (err) {
50
+ if (err.code === 'MODULE_NOT_FOUND') {
51
+ console.error(`[HyperDecor] ❌ uWebSockets.js is not installed locally. Skipping cleanup.`);
52
+ } else {
53
+ console.error(`[HyperDecor] ❌ Error cleaning uWebSockets binaries:`, err.message);
54
+ }
55
+ process.exit(1);
56
56
  }
@@ -1,85 +1,85 @@
1
- import "reflect-metadata";
2
- import {
3
- HyperApp,
4
- HyperModule,
5
- HyperService,
6
- HyperController,
7
- Get,
8
- Post,
9
- Res,
10
- Body,
11
- Response,
12
- OnInit,
13
- createApplication,
14
- Transform,
15
- } from "../src";
16
- import { injectable } from "tsyringe";
17
-
18
- // 1. Setup a Mock Transformer (Zod-like)
19
- const ZodTransformer = {
20
- transform: ({ data, schema }: any) => {
21
- if (schema._type === "zod") {
22
- return { ...data, parsed: true, timestamp: Date.now() };
23
- }
24
- return data;
25
- },
26
- };
27
-
28
- const mockSchema = { _type: "zod" };
29
-
30
- @injectable()
31
- @HyperService()
32
- class AnalyticsService implements OnInit {
33
- async onInit() {
34
- console.log("Service initialized");
35
- }
36
- }
37
-
38
- @HyperController("/api")
39
- class MainController {
40
- @Get("/status")
41
- status(@Res() res: Response) {
42
- res.json({ status: "alive" });
43
- }
44
-
45
- @Post("/user")
46
- @Transform(mockSchema)
47
- createUser(@Body() data: any) {
48
- return data;
49
- }
50
- }
51
-
52
- @HyperModule({
53
- imports: [AnalyticsService],
54
- controllers: [MainController]
55
- })
56
- class MainModule { }
57
-
58
- @HyperApp({
59
- name: "Standalone Test App",
60
- version: "1.0.0",
61
- modules: [MainModule]
62
- })
63
- class FullApp { }
64
-
65
- async function run() {
66
- console.log("Starting App...");
67
- const app = await createApplication(FullApp);
68
- app.useTransform(ZodTransformer);
69
-
70
- const port = 3010;
71
- await app.listen(port);
72
- console.log(`Server listening on http://localhost:${port}`);
73
-
74
- // Close after 5 seconds
75
- setTimeout(async () => {
76
- console.log("Closing server...");
77
- await app.close();
78
- process.exit(0);
79
- }, 5000);
80
- }
81
-
82
- run().catch(err => {
83
- console.error(err);
84
- process.exit(1);
85
- });
1
+ import "reflect-metadata";
2
+ import {
3
+ HyperApp,
4
+ HyperModule,
5
+ HyperService,
6
+ HyperController,
7
+ Get,
8
+ Post,
9
+ Res,
10
+ Body,
11
+ Response,
12
+ OnInit,
13
+ createApplication,
14
+ Transform,
15
+ } from "../src";
16
+ import { injectable } from "tsyringe";
17
+
18
+ // 1. Setup a Mock Transformer (Zod-like)
19
+ const ZodTransformer = {
20
+ transform: ({ data, schema }: any) => {
21
+ if (schema._type === "zod") {
22
+ return { ...data, parsed: true, timestamp: Date.now() };
23
+ }
24
+ return data;
25
+ },
26
+ };
27
+
28
+ const mockSchema = { _type: "zod" };
29
+
30
+ @injectable()
31
+ @HyperService()
32
+ class AnalyticsService implements OnInit {
33
+ async onInit() {
34
+ console.log("Service initialized");
35
+ }
36
+ }
37
+
38
+ @HyperController("/api")
39
+ class MainController {
40
+ @Get("/status")
41
+ status(@Res() res: Response) {
42
+ res.json({ status: "alive" });
43
+ }
44
+
45
+ @Post("/user")
46
+ @Transform(mockSchema)
47
+ createUser(@Body() data: any) {
48
+ return data;
49
+ }
50
+ }
51
+
52
+ @HyperModule({
53
+ imports: [AnalyticsService],
54
+ controllers: [MainController]
55
+ })
56
+ class MainModule { }
57
+
58
+ @HyperApp({
59
+ name: "Standalone Test App",
60
+ version: "1.0.0",
61
+ modules: [MainModule]
62
+ })
63
+ class FullApp { }
64
+
65
+ async function run() {
66
+ console.log("Starting App...");
67
+ const app = await createApplication(FullApp);
68
+ app.useTransform(ZodTransformer);
69
+
70
+ const port = 3010;
71
+ await app.listen(port);
72
+ console.log(`Server listening on http://localhost:${port}`);
73
+
74
+ // Close after 5 seconds
75
+ setTimeout(async () => {
76
+ console.log("Closing server...");
77
+ await app.close();
78
+ process.exit(0);
79
+ }, 5000);
80
+ }
81
+
82
+ run().catch(err => {
83
+ console.error(err);
84
+ process.exit(1);
85
+ });
package/vitest.config.mjs CHANGED
@@ -5,7 +5,7 @@ export default defineConfig({
5
5
  test: {
6
6
  globals: true,
7
7
  environment: 'node',
8
- include: ['tests/**/*.{test,spec,bench}.ts', 'tests/*.{test,spec,bench}.ts'],
8
+ include: ['tests/**/*.{test,spec}.ts'],
9
9
  poolOptions: {
10
10
  threads: {
11
11
  singleThread: true,
package/debug.txt DELETED
@@ -1 +0,0 @@
1
- State: class-before-dep-ok
@@ -1,11 +0,0 @@
1
- import "reflect-metadata";
2
- import { Request } from "hyper-express/types";
3
- import { ParameterResolver } from "../../decorators";
4
- /**
5
- * Creates a parameter decorator for handling request data.
6
- *
7
- * @param {keyof Request | ByPassKeys} key - The key to extract from the request.
8
- * @param {IParamsResolver} resolver - Resolver function to handle the parameter.
9
- * @returns {ParameterDecorator} - The parameter decorator function.
10
- */
11
- export default function createParamDecorator(key: keyof Request | "req" | "res", decoratorName: string, resolver: ParameterResolver, schema?: any, isWholeSource?: boolean): ParameterDecorator;
@@ -1,55 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.default = createParamDecorator;
7
- require("reflect-metadata");
8
- const constants_1 = require("../constants");
9
- const decorator_base_1 = require("../decorator-base");
10
- const who_helper_1 = __importDefault(require("../helpers/who.helper"));
11
- const WrongPlaceException_1 = __importDefault(require("../../exeptions/WrongPlaceException"));
12
- const function_util_1 = require("../utils/function.util");
13
- /**
14
- * Creates a parameter decorator for handling request data.
15
- *
16
- * @param {keyof Request | ByPassKeys} key - The key to extract from the request.
17
- * @param {IParamsResolver} resolver - Resolver function to handle the parameter.
18
- * @returns {ParameterDecorator} - The parameter decorator function.
19
- */
20
- function createParamDecorator(key, decoratorName, resolver, schema, isWholeSource) {
21
- const _key = key;
22
- return (0, decorator_base_1.DecoratorHelper)({
23
- type: constants_1.KEY_TYPE_CONTROLLER,
24
- key: constants_1.KEY_PARAMS_PARAM,
25
- options: (options, Target, propertyKey, parameterIndex) => {
26
- const { isProperty } = (0, who_helper_1.default)(Target, propertyKey, parameterIndex);
27
- if (!isProperty)
28
- throw new WrongPlaceException_1.default(decoratorName, "parameter", `${Target.constructor.name}.${propertyKey}`, Target);
29
- const saved = options !== null && options !== void 0 ? options : { params: {} };
30
- const names = (0, function_util_1.extractArgsNames)(Target[propertyKey]);
31
- const types = Reflect.getMetadata(constants_1.DESIGN_PARAMTYPES, Target, propertyKey);
32
- const name = names === null || names === void 0 ? void 0 : names[parameterIndex];
33
- const type = types === null || types === void 0 ? void 0 : types[parameterIndex];
34
- if (name && saved) {
35
- if (!saved.params[propertyKey]) {
36
- saved.params[propertyKey] = [];
37
- }
38
- saved.params[propertyKey].push({
39
- name,
40
- type,
41
- index: parameterIndex,
42
- key: _key,
43
- method: propertyKey.toString(),
44
- resolver,
45
- schema,
46
- isWholeSource,
47
- });
48
- // sort by index
49
- saved.params[propertyKey].sort((a, b) => a.index - b.index);
50
- Reflect.defineMetadata(constants_1.KEY_PARAMS_PARAM, saved, Target[propertyKey]);
51
- }
52
- return saved;
53
- },
54
- });
55
- }
@@ -1,9 +0,0 @@
1
- import "reflect-metadata";
2
- /**
3
- * Helper function to create route decorators for HTTP methods.
4
- *
5
- * @param {string} method - The HTTP method (e.g., GET, POST).
6
- * @returns {(path?: string) => MethodDecorator} - A method decorator for defining routes.
7
- *
8
- */
9
- export default function createRouteDecorator<T extends any = undefined>(method: string): (path?: string, options?: T) => MethodDecorator & ClassDecorator;
@@ -1,39 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = createRouteDecorator;
4
- require("reflect-metadata");
5
- const constants_1 = require("../constants");
6
- const decorator_base_1 = require("../decorator-base");
7
- /**
8
- * Helper function to create route decorators for HTTP methods.
9
- *
10
- * @param {string} method - The HTTP method (e.g., GET, POST).
11
- * @returns {(path?: string) => MethodDecorator} - A method decorator for defining routes.
12
- *
13
- */
14
- function createRouteDecorator(method) {
15
- return (path = "/", options) => (0, decorator_base_1.DecoratorHelper)({
16
- type: constants_1.KEY_TYPE_CONTROLLER,
17
- key: constants_1.KEY_PARAMS_ROUTE,
18
- targetResolver: (target) => { var _a; return (_a = target.constructor) !== null && _a !== void 0 ? _a : target; },
19
- options: (data, Target, propertyKey, descriptor) => {
20
- // add openAPI data here
21
- var _a;
22
- const handler = descriptor.value;
23
- if (typeof handler !== "function")
24
- return data;
25
- const saved = (_a = Reflect.getMetadata(constants_1.KEY_PARAMS_ROUTE, Target)) !== null && _a !== void 0 ? _a : {
26
- routes: new Set(),
27
- };
28
- saved.routes.add({
29
- className: Target.name,
30
- method,
31
- path,
32
- propertyKey,
33
- handler: handler,
34
- options,
35
- });
36
- return saved;
37
- },
38
- });
39
- }
@@ -1,30 +0,0 @@
1
- import "reflect-metadata";
2
- export type DecoratorBaseTypes = "APP" | "MODULE" | "CONTROLLER" | "ROUTE" | "MIDDLEWARE";
3
- type DefineResolve<T> = (old: T, target?: any, property?: any, descriptor?: any) => T;
4
- interface onDefineResolve<T> {
5
- (data: {
6
- key: string;
7
- options: T;
8
- target: any;
9
- property?: any;
10
- descriptor?: any;
11
- }, defineData: (options: T) => void): void;
12
- }
13
- interface BeseDecoratorOptions<T extends any = any> {
14
- type?: DecoratorBaseTypes | string;
15
- key: string;
16
- options: T | DefineResolve<T>;
17
- targetResolver?: (target: any, propertyKey?: any, descriptorOrIndex?: any) => any;
18
- onDefineData?: onDefineResolve<T>;
19
- }
20
- interface BeseDecorator<T> {
21
- (target: T): any;
22
- (target: T, propertyKey?: any, descriptor?: any): any;
23
- }
24
- type TransformFunction<TOptions, T> = (options: TOptions, target: T, propertyKey?: any, descriptor?: any) => any;
25
- export declare function DecoratorHelper<T, Target extends any = any>({ key, type, options, targetResolver, onDefineData }: BeseDecoratorOptions<T>, ...transformers: TransformFunction<T, Target>[]): BeseDecorator<Target>;
26
- export declare const defineDecorData: <T>(key: string, options: T | DefineResolve<T>, target: any, property?: any, descriptor?: any) => void;
27
- export declare const getDecorData: <T>(key: string, target: any, property?: any) => T;
28
- export declare const hasDecorData: (key: string, target: any, property?: any) => boolean;
29
- export declare const extractDecorData: <T>(target: any) => T | undefined;
30
- export {};