@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,5 @@
1
+ import { HyperCommonMetadata, HyperMethodMetadata } from "../types";
2
+ export declare const HyperMeta: {
3
+ set: (target: object, propertyKey: any, data: Partial<HyperCommonMetadata> | Partial<HyperMethodMetadata>) => void;
4
+ get: (target: object, propertyKey?: any) => Partial<HyperCommonMetadata> | Partial<HyperMethodMetadata>;
5
+ };
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HyperMeta = void 0;
4
+ const meta_store_1 = require("./meta.store");
5
+ exports.HyperMeta = meta_store_1.Metadata.prefix('server');
@@ -0,0 +1,4 @@
1
+ export * from "./meta.store";
2
+ export * from "./hyper.store";
3
+ export * from "./scope.store";
4
+ export * from "./serivces.store";
@@ -14,10 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./method.helper"), exports);
18
- __exportStar(require("./parameter.helper"), exports);
19
- __exportStar(require("./request-body.helper"), exports);
20
- __exportStar(require("./response.helper"), exports);
21
- __exportStar(require("./security.helper"), exports);
22
- __exportStar(require("./tag.helper"), exports);
23
- __exportStar(require("./openapi.helper"), exports);
17
+ __exportStar(require("./meta.store"), exports);
18
+ __exportStar(require("./hyper.store"), exports);
19
+ __exportStar(require("./scope.store"), exports);
20
+ __exportStar(require("./serivces.store"), exports);
@@ -0,0 +1,34 @@
1
+ import 'reflect-metadata';
2
+ type MetadataRecord = Record<string, unknown>;
3
+ export declare class Metadata {
4
+ /**
5
+ * Resolve the real metadata target.
6
+ * If an instance is passed, use its constructor.
7
+ */
8
+ private static resolveTarget;
9
+ /**
10
+ * Track class constructors for discovery.
11
+ */
12
+ private static track;
13
+ /**
14
+ * Get metadata for a target.
15
+ * Auto-initializes the metadata object if missing.
16
+ */
17
+ static get<T = MetadataRecord>(target: object): T;
18
+ /**
19
+ * Replace the full metadata object for a target.
20
+ */
21
+ static rawSet<T extends MetadataRecord>(target: object, value: T): void;
22
+ /**
23
+ * Create a scoped metadata accessor.
24
+ */
25
+ static prefix<TCommon extends object, TMember extends object>(name: string): {
26
+ set: (target: object, propertyKey: any, data: Partial<TCommon> | Partial<TMember>) => void;
27
+ get: (target: object, propertyKey?: any) => Partial<TCommon> | Partial<TMember>;
28
+ };
29
+ /**
30
+ * Get all tracked classes.
31
+ */
32
+ static getTrackedClasses(): object[];
33
+ }
34
+ export {};
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ var _a, _b;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.Metadata = void 0;
5
+ require("reflect-metadata");
6
+ /**
7
+ * Global Symbols for cross-package consistency
8
+ */
9
+ const METADATA_STORE = Symbol.for('hyper:store');
10
+ const DISCOVERY_INDEX = Symbol.for('hyper:index');
11
+ const globalRegistry = globalThis;
12
+ /**
13
+ * Global stores ensure that even different copies of the package
14
+ * share the same metadata and discovery registry.
15
+ */
16
+ const globalStore = (_a = globalRegistry[METADATA_STORE]) !== null && _a !== void 0 ? _a : (globalRegistry[METADATA_STORE] = new WeakMap());
17
+ const globalIndex = (_b = globalRegistry[DISCOVERY_INDEX]) !== null && _b !== void 0 ? _b : (globalRegistry[DISCOVERY_INDEX] = new Set());
18
+ class Metadata {
19
+ /**
20
+ * Resolve the real metadata target.
21
+ * If an instance is passed, use its constructor.
22
+ */
23
+ static resolveTarget(target) {
24
+ return typeof target === 'function' ? target : target.constructor;
25
+ }
26
+ /**
27
+ * Track class constructors for discovery.
28
+ */
29
+ static track(target) {
30
+ if (typeof target === 'function') {
31
+ globalIndex.add(target);
32
+ }
33
+ }
34
+ /**
35
+ * Get metadata for a target.
36
+ * Auto-initializes the metadata object if missing.
37
+ */
38
+ static get(target) {
39
+ const resolved = this.resolveTarget(target);
40
+ let meta = globalStore.get(resolved);
41
+ if (!meta) {
42
+ meta = {};
43
+ globalStore.set(resolved, meta);
44
+ this.track(resolved);
45
+ }
46
+ return meta;
47
+ }
48
+ /**
49
+ * Replace the full metadata object for a target.
50
+ */
51
+ static rawSet(target, value) {
52
+ const resolved = this.resolveTarget(target);
53
+ globalStore.set(resolved, value);
54
+ this.track(resolved);
55
+ }
56
+ /**
57
+ * Create a scoped metadata accessor.
58
+ */
59
+ static prefix(name) {
60
+ const resolveKey = (key) => {
61
+ if (typeof key === 'string' || typeof key === 'symbol' || key === undefined) {
62
+ return key;
63
+ }
64
+ if (typeof key === 'object' && key !== null) {
65
+ if (key.kind === 'class')
66
+ return undefined;
67
+ if (key.name)
68
+ return key.name;
69
+ }
70
+ return undefined;
71
+ };
72
+ return {
73
+ set: (target, propertyKey, data) => {
74
+ var _a, _b, _c, _d;
75
+ const root = Metadata.get(target);
76
+ const scoped = ((_a = root[name]) !== null && _a !== void 0 ? _a : (root[name] = {}));
77
+ const key = resolveKey(propertyKey);
78
+ if (key === undefined) {
79
+ Object.assign(((_b = scoped.common) !== null && _b !== void 0 ? _b : (scoped.common = {})), data);
80
+ return;
81
+ }
82
+ const methods = ((_c = scoped.methods) !== null && _c !== void 0 ? _c : (scoped.methods = {}));
83
+ Object.assign(((_d = methods[key]) !== null && _d !== void 0 ? _d : (methods[key] = {})), data);
84
+ },
85
+ get: (target, propertyKey) => {
86
+ var _a, _b, _c;
87
+ const root = Metadata.get(target);
88
+ const scoped = root[name];
89
+ if (!scoped) {
90
+ return {};
91
+ }
92
+ const key = resolveKey(propertyKey);
93
+ if (key === undefined) {
94
+ return ((_a = scoped.common) !== null && _a !== void 0 ? _a : (scoped.common = {}));
95
+ }
96
+ return (_c = (_b = scoped.methods) === null || _b === void 0 ? void 0 : _b[key]) !== null && _c !== void 0 ? _c : {};
97
+ },
98
+ };
99
+ }
100
+ /**
101
+ * Get all tracked classes.
102
+ */
103
+ static getTrackedClasses() {
104
+ return [...globalIndex];
105
+ }
106
+ }
107
+ exports.Metadata = Metadata;
@@ -1,4 +1,4 @@
1
- import { ScopeMap } from "../decorators";
1
+ import { ScopeMap } from "../../lib/server/decorators";
2
2
  /**
3
3
  * This class is a store for the scopes that are defined in the application.
4
4
  *
@@ -1,3 +1,3 @@
1
1
  import { MiddlewareHandler } from "hyper-express";
2
- import { MiddlewareType } from "../../decorators";
2
+ import { MiddlewareType } from "../../lib/server/decorators";
3
3
  export default function middlewareTransformer(list: MiddlewareType[]): MiddlewareHandler[];
@@ -4,7 +4,7 @@ exports.default = middlewareTransformer;
4
4
  const tsyringe_1 = require("tsyringe");
5
5
  function middlewareTransformer(list) {
6
6
  return list
7
- .map((middleware) => {
7
+ .map((middleware, idx) => {
8
8
  if (isClass(middleware)) {
9
9
  const instance = tsyringe_1.container.resolve(middleware);
10
10
  return instance.handle.bind(instance);
@@ -1,5 +1,5 @@
1
1
  import { MiddlewareHandler } from "hyper-express";
2
- import { RoleType } from "../../decorators";
2
+ import { RoleType } from "../../lib/server/decorators";
3
3
  export default function roleTransform(list: RoleType[], callback?: (middleware: MiddlewareHandler, roles: {
4
4
  role: string;
5
5
  description: string;
@@ -1,16 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = roleTransform;
4
- const exeptions_1 = require("../../exeptions");
5
- const helpers_1 = require("../../common/helpers");
6
- const constants_1 = require("../constants");
4
+ const exeptions_1 = require("../../lib/server/exeptions");
5
+ const role_1 = require("../../common/helpers/role");
6
+ const constants_1 = require("../../constants");
7
7
  function roleTransform(list, callback) {
8
8
  const { roles, names, isEmtpy } = resolveRoles(list);
9
9
  const middleware = (req, res, next) => {
10
10
  var _a;
11
11
  if (isEmtpy)
12
12
  return next();
13
- const requestRoles = (_a = (0, helpers_1.getRoles)(req)) !== null && _a !== void 0 ? _a : [];
13
+ const requestRoles = (_a = (0, role_1.getRoles)(req)) !== null && _a !== void 0 ? _a : [];
14
14
  if (requestRoles.length === 0 && isEmtpy)
15
15
  return next();
16
16
  if (requestRoles.includes(constants_1.FULL_ACCESS))
@@ -1,5 +1,5 @@
1
1
  import { MiddlewareHandler } from "hyper-express/types";
2
- import { ScopeMap, ScopeType } from "../../decorators";
2
+ import { ScopeMap, ScopeType } from "../../lib/server/decorators";
3
3
  type Callback = (middleware: MiddlewareHandler, scopes: ScopeMap[], names: Set<string>) => void;
4
4
  export default function scopeTransfrom(listScopes: ScopeType[], ...callback: Callback[]): MiddlewareHandler;
5
5
  export {};
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = scopeTransfrom;
4
- const exeptions_1 = require("../../exeptions");
4
+ const exeptions_1 = require("../../lib/server/exeptions");
5
5
  const helpers_1 = require("../../common/helpers");
6
- const constants_1 = require("../constants");
6
+ const constants_1 = require("../../constants");
7
7
  function scopeTransfrom(listScopes, ...callback) {
8
8
  const { scopes, scopeNames, isEmpty } = resolveScopes(listScopes);
9
9
  const middleware = (req, res, next) => {
@@ -1,7 +1,56 @@
1
- import { RouteMetadata } from "../decorators";
2
- export interface RouterList {
3
- type: string;
4
- routes: Set<RouteMetadata>;
1
+ import { HyperAppMetadata, HyperModuleMetadata, HyperControllerMetadata, HyperParameterMetadata, RouteMetadata, Constructor, MiddlewareType, ScopeType, RoleType } from "../lib/server/decorators/types";
2
+ /**
3
+ * 🛠️ Shared Class-Level Metadata Keys
4
+ */
5
+ export interface HyperBaseCommon {
6
+ middlewares?: MiddlewareType[];
7
+ scopes?: ScopeType[];
8
+ roles?: RoleType[];
9
+ pass?: unknown;
10
+ }
11
+ /**
12
+ * 📦 Hierarchical Metadata Structure for Components
13
+ */
14
+ export type HyperCommonMetadata = (HyperAppMetadata & HyperBaseCommon & {
15
+ type: 'app';
16
+ }) | (HyperModuleMetadata & HyperBaseCommon & {
17
+ type: 'module';
18
+ }) | (HyperControllerMetadata & HyperBaseCommon & {
19
+ type: 'controller';
20
+ }) | (HyperBaseCommon & {
21
+ type: 'service';
22
+ });
23
+ /**
24
+ * 📡 Hierarchical Metadata Structure for Methods
25
+ */
26
+ export interface HyperMethodMetadata {
27
+ route?: RouteMetadata;
28
+ params?: HyperParameterMetadata;
29
+ middlewares?: MiddlewareType[];
30
+ scopes?: ScopeType[];
31
+ roles?: RoleType[];
32
+ onMessage?: {
33
+ topic: string;
34
+ };
35
+ output?: unknown;
36
+ reflection?: {
37
+ params?: (Constructor | Function)[];
38
+ output?: Constructor | Function;
39
+ };
40
+ }
41
+ /**
42
+ * 🌳 Root storage for a prefix segment (e.g. 'hyper')
43
+ */
44
+ export interface HyperPrefixRoot {
45
+ common: HyperCommonMetadata;
46
+ methods: Record<string, HyperMethodMetadata>;
47
+ }
48
+ /**
49
+ * 🏦 The global metadata store structure per class constructor
50
+ */
51
+ export interface HyperMetadataStore {
52
+ server?: HyperPrefixRoot;
53
+ openapi?: unknown;
5
54
  }
6
55
  export type HyperApplicationPrivate<T> = T & {
7
56
  prepare(): Promise<void>;
@@ -1,3 +1,7 @@
1
1
  import { IHyperApp, IHyperApplication } from "../type";
2
- export default function createApplication<T extends IHyperApplication>(app: new (...args: any[]) => T): Promise<IHyperApp<T>>;
3
- export { createApplication };
2
+ /**
3
+ * Creates a new HyperApplication.
4
+ *
5
+ * @param app
6
+ */
7
+ export declare function createApplication<T extends IHyperApplication>(application: new (...args: any[]) => T): Promise<IHyperApp<T>>;
@@ -9,21 +9,60 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.default = createApplication;
13
12
  exports.createApplication = createApplication;
14
13
  const tsyringe_1 = require("tsyringe");
15
14
  const message_bus_1 = require("./message-bus");
16
- function createApplication(app) {
15
+ const stores_1 = require("../__internals/stores");
16
+ const prepare_helper_1 = require("../__internals/helpers/prepare.helper");
17
+ const transform_registry_1 = require("../__internals/transform/transform.registry");
18
+ /**
19
+ * Creates a new HyperApplication.
20
+ *
21
+ * @param app
22
+ */
23
+ function createApplication(application) {
17
24
  return __awaiter(this, void 0, void 0, function* () {
18
- var _a;
19
- const instance = tsyringe_1.container.resolve(app);
20
- if (instance.prepare) {
21
- yield instance.prepare();
25
+ const metadata = stores_1.HyperMeta.get(application);
26
+ if (metadata.type !== "app") {
27
+ throw new Error("Application must be decorated with @HyperApp");
22
28
  }
23
- (_a = instance === null || instance === void 0 ? void 0 : instance.onPrepare) === null || _a === void 0 ? void 0 : _a.call(instance);
24
- instance.emit = (topic, data) => __awaiter(this, void 0, void 0, function* () {
25
- yield message_bus_1.MessageBus.emit(topic, data);
29
+ const logger = metadata.logger || console.log;
30
+ const logWrapper = (space, msg) => {
31
+ var _a;
32
+ if ((_a = metadata.logs) === null || _a === void 0 ? void 0 : _a[space]) {
33
+ logger(`[${space.toUpperCase()}] ${msg}`);
34
+ }
35
+ };
36
+ const appServer = yield (0, prepare_helper_1.prepareApplication)(metadata, application, logWrapper);
37
+ const appInstance = tsyringe_1.container.resolve(application);
38
+ const appProxy = new Proxy(appInstance, {
39
+ get(target, prop) {
40
+ if (prop === "useTransform") {
41
+ return (transformer) => {
42
+ transform_registry_1.transformRegistry.register(transformer);
43
+ return appProxy;
44
+ };
45
+ }
46
+ if (prop === "emit") {
47
+ return (topic, data) => __awaiter(this, void 0, void 0, function* () {
48
+ const bus = tsyringe_1.container.resolve(message_bus_1.MessageBus);
49
+ yield bus.emit(topic, data);
50
+ });
51
+ }
52
+ // Prioritize application instance methods/props
53
+ if (prop in target) {
54
+ const value = target[prop];
55
+ return typeof value === "function" ? value.bind(target) : value;
56
+ }
57
+ // Fallback to hyper-express server
58
+ const serverValue = appServer[prop];
59
+ return typeof serverValue === "function" ? serverValue.bind(appServer) : serverValue;
60
+ },
26
61
  });
27
- return instance;
62
+ if ("onPrepare" in appInstance && typeof appInstance.onPrepare === "function") {
63
+ const onPrepare = appInstance.onPrepare.bind(appInstance);
64
+ yield onPrepare();
65
+ }
66
+ return appProxy;
28
67
  });
29
68
  }
@@ -0,0 +1,56 @@
1
+ import "reflect-metadata";
2
+ import { InjectionToken } from "tsyringe";
3
+ import { Constructor, HyperAppMetadata, ImportType } from "../lib/server/decorators/types";
4
+ export type Token<T = any> = InjectionToken<T> | Constructor<T> | string | (abstract new (...args: any[]) => T);
5
+ /**
6
+ * 🧪 TestingModule
7
+ * Holds the context of a compiled test environment.
8
+ */
9
+ export declare class TestingModule {
10
+ private target?;
11
+ constructor(target?: Constructor | undefined);
12
+ /**
13
+ * Resolves a dependency from the container and ensures it's initialized.
14
+ */
15
+ resolve<T>(token: Token<T>): Promise<T>;
16
+ /**
17
+ * Shortcut for resolve (consistent with NestJS)
18
+ */
19
+ get<T>(token: Token<T>): Promise<T>;
20
+ /**
21
+ * Creates the full HyperExpress application proxy.
22
+ */
23
+ createHyperApplication(): Promise<any>;
24
+ }
25
+ /**
26
+ * 🛠️ TestingModuleBuilder
27
+ * Fluent API for configuring the testing module.
28
+ */
29
+ export declare class TestingModuleBuilder {
30
+ private metadata;
31
+ constructor(metadata: Partial<HyperAppMetadata>);
32
+ overrideProvider(token: Token): any;
33
+ compile(): Promise<TestingModule>;
34
+ }
35
+ /**
36
+ * 🚀 HyperTest
37
+ * Entry point for creating testing environments.
38
+ */
39
+ export declare class HyperTest {
40
+ /**
41
+ * Ultra-simple one-liner to boot a module or app.
42
+ * const module = await HyperTest.create(AppModule);
43
+ */
44
+ static create(Target: Constructor, options?: {
45
+ providers?: ImportType[];
46
+ }): Promise<TestingModule>;
47
+ /**
48
+ * Full builder API for complex configurations.
49
+ */
50
+ static createTestingModule(metadata: Partial<HyperAppMetadata>): TestingModuleBuilder;
51
+ /**
52
+ * Resets the global container instances (but keeps registrations).
53
+ * Useful between tests when isolation is not possible.
54
+ */
55
+ static reset(): void;
56
+ }
@@ -0,0 +1,193 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
9
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
10
+ return new (P || (P = Promise))(function (resolve, reject) {
11
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
12
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
13
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
14
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
15
+ });
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.HyperTest = exports.TestingModuleBuilder = exports.TestingModule = void 0;
19
+ require("reflect-metadata");
20
+ const tsyringe_1 = require("tsyringe");
21
+ const stores_1 = require("../__internals/stores");
22
+ const lifecycle_helper_1 = require("../__internals/helpers/lifecycle.helper");
23
+ const bootstrap_1 = require("./bootstrap");
24
+ const HyperApp_1 = require("../lib/server/decorators/HyperApp");
25
+ /**
26
+ * 🧪 TestingModule
27
+ * Holds the context of a compiled test environment.
28
+ */
29
+ class TestingModule {
30
+ constructor(target) {
31
+ this.target = target;
32
+ }
33
+ /**
34
+ * Resolves a dependency from the container and ensures it's initialized.
35
+ */
36
+ resolve(token) {
37
+ return __awaiter(this, void 0, void 0, function* () {
38
+ return yield deepResolve(token);
39
+ });
40
+ }
41
+ /**
42
+ * Shortcut for resolve (consistent with NestJS)
43
+ */
44
+ get(token) {
45
+ return __awaiter(this, void 0, void 0, function* () {
46
+ return yield this.resolve(token);
47
+ });
48
+ }
49
+ /**
50
+ * Creates the full HyperExpress application proxy.
51
+ */
52
+ createHyperApplication() {
53
+ return __awaiter(this, void 0, void 0, function* () {
54
+ if (!this.target) {
55
+ throw new Error("Cannot create application without a target module/app.");
56
+ }
57
+ return yield (0, bootstrap_1.createApplication)(this.target);
58
+ });
59
+ }
60
+ }
61
+ exports.TestingModule = TestingModule;
62
+ /**
63
+ * 🛠️ TestingModuleBuilder
64
+ * Fluent API for configuring the testing module.
65
+ */
66
+ class TestingModuleBuilder {
67
+ constructor(metadata) {
68
+ this.metadata = metadata;
69
+ }
70
+ overrideProvider(token) {
71
+ return {
72
+ useValue: (value) => {
73
+ tsyringe_1.container.register(token, { useValue: value });
74
+ return this;
75
+ },
76
+ useClass: (target) => {
77
+ tsyringe_1.container.register(token, { useClass: target });
78
+ return this;
79
+ },
80
+ useFactory: (factory) => {
81
+ tsyringe_1.container.register(token, { useFactory: factory });
82
+ return this;
83
+ }
84
+ };
85
+ }
86
+ compile() {
87
+ return __awaiter(this, void 0, void 0, function* () {
88
+ // 1. Create a synthetic app if needed
89
+ let SyntheticApp = class SyntheticApp {
90
+ };
91
+ SyntheticApp = __decorate([
92
+ (0, HyperApp_1.HyperApp)(this.metadata)
93
+ ], SyntheticApp);
94
+ // 2. Deep initialize all defined imports/providers
95
+ if (this.metadata.imports) {
96
+ for (const item of this.metadata.imports) {
97
+ const token = typeof item === "object" && "token" in item ? item.token : item;
98
+ yield deepResolve(token);
99
+ }
100
+ }
101
+ return new TestingModule(SyntheticApp);
102
+ });
103
+ }
104
+ }
105
+ exports.TestingModuleBuilder = TestingModuleBuilder;
106
+ /**
107
+ * 🚀 HyperTest
108
+ * Entry point for creating testing environments.
109
+ */
110
+ class HyperTest {
111
+ /**
112
+ * Ultra-simple one-liner to boot a module or app.
113
+ * const module = await HyperTest.create(AppModule);
114
+ */
115
+ static create(Target, options) {
116
+ return __awaiter(this, void 0, void 0, function* () {
117
+ const builder = this.createTestingModule({
118
+ imports: [Target, ...((options === null || options === void 0 ? void 0 : options.providers) || [])]
119
+ });
120
+ const module = yield builder.compile();
121
+ // Ensure the target itself is deep-resolved
122
+ yield deepResolve(Target);
123
+ return module;
124
+ });
125
+ }
126
+ /**
127
+ * Full builder API for complex configurations.
128
+ */
129
+ static createTestingModule(metadata) {
130
+ return new TestingModuleBuilder(metadata);
131
+ }
132
+ /**
133
+ * Resets the global container instances (but keeps registrations).
134
+ * Useful between tests when isolation is not possible.
135
+ */
136
+ static reset() {
137
+ tsyringe_1.container.clearInstances();
138
+ }
139
+ }
140
+ exports.HyperTest = HyperTest;
141
+ /**
142
+ * 🔄 deepResolve
143
+ * Recursively resolves a token and ensures its onInit chain is executed.
144
+ */
145
+ function deepResolve(token) {
146
+ return __awaiter(this, void 0, void 0, function* () {
147
+ const instance = tsyringe_1.container.resolve(token);
148
+ // 1. Get the actual implementation constructor to inspect dependencies.
149
+ // We prefer instance.constructor because if token is an abstract class,
150
+ // dependencies are defined on the implementation.
151
+ const target = (instance === null || instance === void 0 ? void 0 : instance.constructor) || (typeof token === "function" ? token : null);
152
+ // 2. Recursive resolution of dependencies (Bottom-up initialization)
153
+ if (target && typeof target === "function") {
154
+ const paramTypes = Reflect.getMetadata("design:paramtypes", target) || [];
155
+ const injectionTokens = Reflect.getOwnMetadata("injectionTokens", target) || {};
156
+ for (let i = 0; i < paramTypes.length; i++) {
157
+ // Use @inject token if present, otherwise use design:paramtype
158
+ const dep = injectionTokens[i] || paramTypes[i];
159
+ // Avoid cycles or primitives
160
+ if (dep && typeof dep === "function" && dep !== Object && dep !== Array && dep !== String && dep !== Number && dep !== Boolean) {
161
+ yield deepResolve(dep);
162
+ }
163
+ }
164
+ }
165
+ // 3. Metadata Discovery (traversing @HyperApp, @HyperModule, etc.)
166
+ const metadata = stores_1.HyperMeta.get(target);
167
+ if (metadata) {
168
+ // Resolve imports
169
+ if (metadata.imports && Array.isArray(metadata.imports)) {
170
+ for (const item of metadata.imports) {
171
+ const depToken = typeof item === "object" && item !== null && "token" in item ? item.token : item;
172
+ if (depToken)
173
+ yield deepResolve(depToken);
174
+ }
175
+ }
176
+ // Resolve modules recursively
177
+ if (metadata.modules && Array.isArray(metadata.modules)) {
178
+ for (const m of metadata.modules) {
179
+ yield deepResolve(m);
180
+ }
181
+ }
182
+ // Resolve controllers
183
+ if (metadata.controllers && Array.isArray(metadata.controllers)) {
184
+ for (const c of metadata.controllers) {
185
+ yield deepResolve(c);
186
+ }
187
+ }
188
+ }
189
+ // 4. Initialize the instance itself
190
+ yield (0, lifecycle_helper_1.initializeInstance)(instance);
191
+ return instance;
192
+ });
193
+ }
@@ -4,6 +4,7 @@ export interface IMessageTransport {
4
4
  }
5
5
  export declare class InternalTransport implements IMessageTransport {
6
6
  private emitter;
7
+ private wildcardHandlers;
7
8
  listen(topic: string, handler: (data: any) => Promise<void> | void): Promise<void>;
8
9
  emit(topic: string, data: any): Promise<void>;
9
10
  }