@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
@@ -1,122 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.extractDecorData = exports.hasDecorData = exports.getDecorData = exports.defineDecorData = void 0;
4
- exports.DecoratorHelper = DecoratorHelper;
5
- require("reflect-metadata");
6
- const tsyringe_1 = require("tsyringe");
7
- const object_util_1 = require("./utils/object.util");
8
- function DecoratorHelper({ key, type, options, targetResolver, onDefineData }, ...transformers) {
9
- return (target, propertyKey, descriptor) => {
10
- const isProperty = !!propertyKey;
11
- const isMethod = !!descriptor;
12
- let _options = options;
13
- const Target = targetResolver
14
- ? targetResolver(target, propertyKey, descriptor)
15
- : target;
16
- if (options instanceof Function) {
17
- const data = (0, exports.getDecorData)(key, Target);
18
- const optionsResolver = options;
19
- const value = optionsResolver(data, Target, propertyKey, descriptor);
20
- if (value)
21
- _options = Object.assign(Object.assign({}, _options), value);
22
- }
23
- if (onDefineData) {
24
- onDefineData({
25
- key,
26
- options: Object.assign({ type }, _options),
27
- target: Target,
28
- property: propertyKey,
29
- descriptor,
30
- }, (data) => {
31
- (0, exports.defineDecorData)(key, Object.assign({ type }, data), Target);
32
- });
33
- }
34
- else {
35
- (0, exports.defineDecorData)(key, Object.assign({ type }, _options), Target);
36
- }
37
- let value = Target;
38
- if (transformers.length) {
39
- const transforms = transformers.map((fn) => fn.bind(Target, _options));
40
- if (isProperty) {
41
- (0, exports.defineDecorData)(key, Object.assign({ type }, options), Target, propertyKey);
42
- value = Reflect.decorate(transforms, Target, propertyKey);
43
- }
44
- else if (isMethod) {
45
- (0, exports.defineDecorData)(key, Object.assign({ type }, options), Target);
46
- value = Reflect.decorate(transforms, Target, propertyKey, descriptor);
47
- }
48
- else {
49
- (0, exports.defineDecorData)(key, Object.assign({ type }, options), Target);
50
- value = Reflect.decorate(transforms, Target);
51
- // If the class was wrapped/replaced, apply metadata to the new class too
52
- if (value && value !== Target) {
53
- (0, exports.defineDecorData)(key, Object.assign({ type }, options), value);
54
- }
55
- }
56
- }
57
- (0, tsyringe_1.injectable)()((0, object_util_1.$constructor)(target));
58
- return value;
59
- };
60
- }
61
- const METADATA_CACHE = new WeakMap();
62
- const defineDecorData = (key, options, target, property, descriptor) => {
63
- let value = options;
64
- if (typeof options === "function" && !(options.prototype && options.prototype.constructor === options)) {
65
- const old = (0, exports.getDecorData)(key, target, property);
66
- value = Object.assign(Object.assign({}, old), options(old, target, property, descriptor));
67
- }
68
- if (property) {
69
- Reflect.defineMetadata(key, value, target, property);
70
- }
71
- else {
72
- Reflect.defineMetadata(key, value, target);
73
- }
74
- // Update Cache
75
- let targetCache = METADATA_CACHE.get(target);
76
- if (!targetCache) {
77
- targetCache = new Map();
78
- METADATA_CACHE.set(target, targetCache);
79
- }
80
- targetCache.set(property ? `${key}:${property}` : key, value);
81
- };
82
- exports.defineDecorData = defineDecorData;
83
- const getDecorData = (key, target, property) => {
84
- const cacheKey = property ? `${key}:${property}` : key;
85
- const targetCache = METADATA_CACHE.get(target);
86
- if (targetCache && targetCache.has(cacheKey)) {
87
- return targetCache.get(cacheKey);
88
- }
89
- const value = property
90
- ? Reflect.getMetadata(key, target, property)
91
- : Reflect.getMetadata(key, target);
92
- if (value !== undefined) {
93
- let tc = METADATA_CACHE.get(target);
94
- if (!tc) {
95
- tc = new Map();
96
- METADATA_CACHE.set(target, tc);
97
- }
98
- tc.set(cacheKey, value);
99
- }
100
- return value;
101
- };
102
- exports.getDecorData = getDecorData;
103
- const hasDecorData = (key, target, property) => {
104
- const cacheKey = property ? `${key}:${property}` : key;
105
- const targetCache = METADATA_CACHE.get(target);
106
- if (targetCache && targetCache.has(cacheKey))
107
- return true;
108
- return property
109
- ? Reflect.hasMetadata(key, target, property)
110
- : Reflect.hasMetadata(key, target);
111
- };
112
- exports.hasDecorData = hasDecorData;
113
- const extractDecorData = (target) => {
114
- const keys = Reflect.getMetadataKeys(target);
115
- const result = {};
116
- for (let i = 0; i < keys.length; i++) {
117
- const key = keys[i];
118
- result[key] = (0, exports.getDecorData)(key, target);
119
- }
120
- return result;
121
- };
122
- exports.extractDecorData = extractDecorData;
@@ -1,8 +0,0 @@
1
- import { IHyperHooks, ImportType } from "../../decorators/types";
2
- /**
3
- * Prepare imports for the target class.
4
- *
5
- * @param target
6
- * @param imports
7
- */
8
- export declare function prepareImports(_target: any, imports: ImportType[], hooks?: IHyperHooks, context?: any): Promise<void>;
@@ -1,92 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.prepareImports = prepareImports;
13
- const tsyringe_1 = require("tsyringe");
14
- const lifecycle_helper_1 = require("./lifecycle.helper");
15
- const decorator_base_1 = require("../decorator-base");
16
- const constants_1 = require("../constants");
17
- const message_bus_1 = require("../../common/message-bus");
18
- /**
19
- * Prepare imports for the target class.
20
- *
21
- * @param target
22
- * @param imports
23
- */
24
- function prepareImports(_target, imports, hooks, context) {
25
- return __awaiter(this, void 0, void 0, function* () {
26
- const bus = tsyringe_1.container.resolve(message_bus_1.MessageBus);
27
- yield Promise.all(imports.map((item) => __awaiter(this, void 0, void 0, function* () {
28
- let token;
29
- if (typeof item === "function" || typeof item === "string" || typeof item === "symbol") {
30
- token = item;
31
- }
32
- else if (item && typeof item === "object" && "token" in item) {
33
- token = item.token;
34
- if (item.useClass) {
35
- tsyringe_1.container.register(token, { useClass: item.useClass }, item.options);
36
- }
37
- else if ("useValue" in item) {
38
- tsyringe_1.container.registerInstance(token, item.useValue);
39
- return;
40
- }
41
- else if (item.useFactory) {
42
- tsyringe_1.container.register(token, { useFactory: item.useFactory }, item.options);
43
- return;
44
- }
45
- else if (item.useToken) {
46
- tsyringe_1.container.register(token, { useToken: item.useToken }, item.options);
47
- return;
48
- }
49
- }
50
- if (!token)
51
- return;
52
- try {
53
- const instance = tsyringe_1.container.resolve(token);
54
- if (!instance)
55
- return;
56
- // Skip if already initialized to avoid double work/double subscription
57
- const alreadyDone = (0, lifecycle_helper_1.isInitialized)(instance);
58
- if (!alreadyDone) {
59
- if (hooks === null || hooks === void 0 ? void 0 : hooks.onBeforeInit) {
60
- yield hooks.onBeforeInit(instance, token, context);
61
- }
62
- }
63
- yield (0, lifecycle_helper_1.initializeInstance)(instance);
64
- if (!alreadyDone) {
65
- if (hooks === null || hooks === void 0 ? void 0 : hooks.onAfterInit) {
66
- yield hooks.onAfterInit(instance, token, context);
67
- }
68
- // Handle singleton registration if it's a constructor and not registered
69
- if (typeof token === "function" && !tsyringe_1.container.isRegistered(token)) {
70
- const isSingleton = typeof instance.isSingleton === "function" ? instance.isSingleton() : true;
71
- if (isSingleton) {
72
- tsyringe_1.container.registerInstance(token, instance);
73
- }
74
- }
75
- // Discovery: Messaging (only on first init)
76
- const messaging = (0, decorator_base_1.getDecorData)(constants_1.METADATA_KEYS.ON_MESSAGE, typeof token === "function" ? token : instance.constructor);
77
- if (messaging === null || messaging === void 0 ? void 0 : messaging.length) {
78
- messaging.forEach((msg) => {
79
- bus.listen(msg.topic, instance[msg.propertyKey].bind(instance));
80
- });
81
- }
82
- }
83
- }
84
- catch (e) {
85
- // Skip dependencies that cannot be resolved automatically
86
- // Log a warning to prevent silent failures in production
87
- const name = typeof token === "function" ? token.name : String(token);
88
- console.warn(`[HyperDecor] Warn: Could not resolve dependency for token "${name}". It might be missing injectable() or not exported correctly.`);
89
- }
90
- })));
91
- });
92
- }
@@ -1,81 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAppTree = getAppTree;
4
- const decorator_base_1 = require("../decorator-base");
5
- const constants_1 = require("../constants");
6
- const path_util_1 = require("../utils/path.util");
7
- const class_collector_1 = require("../../lib/openapi/collectors/class.collector");
8
- const metadata_registry_1 = require("../../lib/openapi/metadata.registry");
9
- /**
10
- * Extracts the complete application metadata tree.
11
- */
12
- function getAppTree(Target) {
13
- const appMetadata = (0, decorator_base_1.getDecorData)(constants_1.KEY_PARAMS_APP, Target);
14
- const prefix = (appMetadata === null || appMetadata === void 0 ? void 0 : appMetadata.prefix) || "/";
15
- const tree = {
16
- app: Object.assign(Object.assign({}, appMetadata), { target: Target, fullPath: prefix }),
17
- modules: {},
18
- paths: {}
19
- };
20
- ((appMetadata === null || appMetadata === void 0 ? void 0 : appMetadata.modules) || []).forEach(m => {
21
- const node = getModuleNode(m, prefix, tree.paths);
22
- tree.modules[m.name] = node;
23
- });
24
- // Apply tree processors
25
- metadata_registry_1.openApiRegistry.getProcessors().forEach(processor => processor(tree));
26
- return tree;
27
- }
28
- function getModuleNode(Target, parentPath = "", globalPaths = {}) {
29
- const metadata = (0, decorator_base_1.getDecorData)(constants_1.KEY_PARAMS_MODULE, Target);
30
- const currentPath = (0, path_util_1.join)(parentPath, (metadata === null || metadata === void 0 ? void 0 : metadata.path) || "");
31
- const openapi = (0, class_collector_1.collectClassMetadata)(Target);
32
- const node = {
33
- metadata,
34
- target: Target,
35
- fullPath: currentPath,
36
- modules: {},
37
- controllers: {},
38
- services: ((metadata === null || metadata === void 0 ? void 0 : metadata.imports) || []),
39
- openapi
40
- };
41
- ((metadata === null || metadata === void 0 ? void 0 : metadata.modules) || []).forEach(m => {
42
- node.modules[m.name] = getModuleNode(m, currentPath, globalPaths);
43
- });
44
- ((metadata === null || metadata === void 0 ? void 0 : metadata.controllers) || []).forEach(c => {
45
- node.controllers[c.name] = getControllerNode(c, currentPath, globalPaths);
46
- });
47
- return node;
48
- }
49
- function getControllerNode(Target, parentPath = "", globalPaths = {}) {
50
- var _a;
51
- const metadata = (0, decorator_base_1.getDecorData)(constants_1.KEY_TYPE_CONTROLLER, Target);
52
- const routeList = (0, decorator_base_1.getDecorData)(constants_1.KEY_PARAMS_ROUTE, Target);
53
- // Param metadata can be on the constructor or the prototype
54
- const paramMetadata = (_a = (0, decorator_base_1.getDecorData)(constants_1.KEY_PARAMS_PARAM, Target)) !== null && _a !== void 0 ? _a : (0, decorator_base_1.getDecorData)(constants_1.KEY_PARAMS_PARAM, Target.prototype);
55
- const currentPath = (0, path_util_1.join)(parentPath, (metadata === null || metadata === void 0 ? void 0 : metadata.path) || "");
56
- const openapi = (0, class_collector_1.collectClassMetadata)(Target);
57
- const routes = Array.from((routeList === null || routeList === void 0 ? void 0 : routeList.routes) || []).map((route) => {
58
- var _a, _b, _c, _d, _e, _f;
59
- // Also try to get params from the handler itself if not in aggregated metadata
60
- const params = (_e = (_b = (_a = paramMetadata === null || paramMetadata === void 0 ? void 0 : paramMetadata.params) === null || _a === void 0 ? void 0 : _a[route.propertyKey]) !== null && _b !== void 0 ? _b : (_d = (_c = (0, decorator_base_1.getDecorData)(constants_1.KEY_PARAMS_PARAM, route.handler)) === null || _c === void 0 ? void 0 : _c.params) === null || _d === void 0 ? void 0 : _d[route.propertyKey]) !== null && _e !== void 0 ? _e : [];
61
- const fullPath = (0, path_util_1.join)(currentPath, route.path);
62
- // Get OpenAPI metadata for the method
63
- const methodOpenApi = ((_f = openapi.methods) === null || _f === void 0 ? void 0 : _f[route.propertyKey]) || {};
64
- const routeNode = Object.assign(Object.assign({}, route), { fullPath,
65
- params, openapi: methodOpenApi });
66
- // Add to global paths map
67
- if (!globalPaths[fullPath]) {
68
- globalPaths[fullPath] = [];
69
- }
70
- globalPaths[fullPath].push(routeNode);
71
- return routeNode;
72
- });
73
- return {
74
- metadata,
75
- target: Target,
76
- fullPath: currentPath,
77
- routes,
78
- services: (metadata === null || metadata === void 0 ? void 0 : metadata.imports) || [],
79
- openapi
80
- };
81
- }
@@ -1,15 +0,0 @@
1
- interface MetadataStoreOptions {
2
- target: any;
3
- propertyKey?: string | symbol;
4
- descriptorOrIndex?: any;
5
- }
6
- declare class MetadatStore {
7
- static define(key: string | symbol, value: any, { target, propertyKey }: MetadataStoreOptions): void;
8
- static get<T>(key: string | symbol, { target, propertyKey }: MetadataStoreOptions, def: T): T;
9
- static list<T extends any = any>(key: string | symbol, { target, propertyKey }: MetadataStoreOptions): {
10
- has: () => boolean;
11
- get: () => never[];
12
- set: (...value: T[]) => void;
13
- };
14
- }
15
- export default MetadatStore;
@@ -1,37 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const object_util_1 = require("../utils/object.util");
4
- class MetadatStore {
5
- static define(key, value, { target, propertyKey }) {
6
- if (target && typeof propertyKey === "string") {
7
- Reflect.defineMetadata(key, value, Reflect.get(target, propertyKey));
8
- }
9
- else {
10
- Reflect.defineMetadata(key, value, (0, object_util_1.$constructor)(target));
11
- }
12
- }
13
- static get(key, { target, propertyKey }, def) {
14
- if (target && typeof propertyKey === "string") {
15
- return Reflect.getMetadata(key, Reflect.get(target, propertyKey)) || def;
16
- }
17
- else {
18
- return Reflect.getMetadata(key, (0, object_util_1.$constructor)(target)) || def;
19
- }
20
- }
21
- static list(key, { target, propertyKey }) {
22
- return {
23
- has: () => {
24
- return this.get(key, { target, propertyKey }, []).length > 0;
25
- },
26
- get: () => {
27
- return this.get(key, { target, propertyKey }, []);
28
- },
29
- set: (...value) => {
30
- const list = this.get(key, { target, propertyKey }, []);
31
- list.push(...value);
32
- this.define(key, list, { target, propertyKey });
33
- },
34
- };
35
- }
36
- }
37
- exports.default = MetadatStore;
@@ -1,65 +0,0 @@
1
- import { Request } from "hyper-express/types";
2
- /**
3
- * File upload restrictions
4
- *
5
- * @param allowedMimeTypes Allowed MIME types
6
- * @param maxFileSize Maximum file size in bytes
7
- *
8
- */
9
- export interface FileUplopadRestrictions {
10
- allowedMimeTypes: string[];
11
- maxFileSize: number;
12
- }
13
- /**
14
- * File restrictions resolver
15
- *
16
- * @param request Request object
17
- * @returns File restrictions
18
- *
19
- */
20
- export type FileRestrictions = FileUplopadRestrictions | ((request: Request) => FileUplopadRestrictions | Promise<FileUplopadRestrictions>);
21
- /**
22
- * File decorator options
23
- *
24
- * @param fieldName Field name to extract from the request
25
- * @param restrictions File restrictions
26
- * @param required If the file is required
27
- *
28
- *
29
- */
30
- export interface FileOptions {
31
- fieldName: string | string[];
32
- restrictions?: FileRestrictions;
33
- required?: boolean;
34
- }
35
- export interface UploadedFile {
36
- name: string;
37
- filename: string;
38
- mimeType: string;
39
- size: number;
40
- ext: string;
41
- buffer: Buffer;
42
- }
43
- /**
44
- * Decorator to extract file from the request
45
- *
46
- * @param param0
47
- */
48
- export declare const File: {
49
- (options: FileOptions | string): ParameterDecorator;
50
- /**
51
- *
52
- * Helper function to create a file decorator with options
53
- *
54
- * @param options
55
- * @returns
56
- */
57
- options(options: FileOptions, required?: boolean): (fieldName: string | string[]) => ParameterDecorator;
58
- /**
59
- * Helper function to create a file decorator with restrictions
60
- *
61
- * @param restrictions
62
- * @returns
63
- */
64
- restrictions(restrictions: FileRestrictions): (fieldName: string | string[], required?: boolean) => ParameterDecorator;
65
- };
@@ -1,62 +0,0 @@
1
- import { ParameterResolver } from "./types";
2
- /**
3
- * Get the value of a key from the request object
4
- *
5
- * @param key
6
- * @returns
7
- */
8
- /**
9
- * Get the value of a key from the request object or transform the entire query.
10
- *
11
- * @example
12
- * \@Query('id')
13
- * \@Query('id', IntSchema)
14
- * \@Query(UserQueryDto)
15
- */
16
- export declare function Query(keyOrSchema?: string | any, schemaOrTransform?: any): any;
17
- /**
18
- * Get the body of the request or transform it via a schema.
19
- *
20
- * @example
21
- * \@Body()
22
- * \@Body(CreateUserDto)
23
- */
24
- export declare function Body(schemaOrResolver?: any): any;
25
- /**
26
- * Get the params from the request or transform via schema.
27
- *
28
- * @example
29
- * \@Param('id')
30
- * \@Param('id', IntSchema)
31
- */
32
- export declare function Param(keyOrSchema: string | any, schemaOrValidator?: any): any;
33
- /**
34
- * Get the headers from the request.
35
- */
36
- export declare function Headers(keyOrSchema?: string | any, schema?: any): any;
37
- export declare const Req: () => ParameterDecorator;
38
- export declare const Res: () => ParameterDecorator;
39
- /**
40
- * Create a custom request decorator
41
- * that can be used to extract data from the request object
42
- *
43
- *
44
- * @example
45
- * ```typescript
46
- *
47
- * interface LoginData {
48
- * username: string;
49
- * password: string;
50
- * }
51
- *
52
- * const LoginData = createCustomRequestDecorator<LoginData>({
53
- * resolver: async (request) => {
54
- * const data = await request.json();
55
- * return [data];
56
- * }
57
- * }
58
- *
59
- *
60
- *
61
- */
62
- export declare const createCustomRequestDecorator: (decoratorName: string, resolver: ParameterResolver) => ParameterDecorator;
@@ -1,139 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.createCustomRequestDecorator = exports.Res = exports.Req = void 0;
16
- exports.Query = Query;
17
- exports.Body = Body;
18
- exports.Param = Param;
19
- exports.Headers = Headers;
20
- const request_creator_1 = __importDefault(require("../__internals/creators/request.creator"));
21
- const object_util_1 = require("../__internals/utils/object.util");
22
- /**
23
- * Get the value of a key from the request object
24
- *
25
- * @param key
26
- * @returns
27
- */
28
- /**
29
- * Get the value of a key from the request object or transform the entire query.
30
- *
31
- * @example
32
- * \@Query('id')
33
- * \@Query('id', IntSchema)
34
- * \@Query(UserQueryDto)
35
- */
36
- function Query(keyOrSchema, schemaOrTransform) {
37
- // Case: @Query(UserQueryDto)
38
- if (typeof keyOrSchema === 'function' && !schemaOrTransform) {
39
- return (0, request_creator_1.default)("query", "Query", (request) => request.query, keyOrSchema, true);
40
- }
41
- // Case: @Query('id', IntSchema) or @Query('id', data => ...)
42
- const key = keyOrSchema;
43
- const resolver = (request) => (0, object_util_1.$get)(request.query, key, request.query);
44
- if (typeof schemaOrTransform === 'function' && schemaOrTransform.prototype === undefined) {
45
- // It's a legacy transform function: data => ...
46
- return (0, request_creator_1.default)("query", "Query", (request) => {
47
- const value = resolver(request);
48
- return schemaOrTransform(value);
49
- });
50
- }
51
- // It's either a schema/DTO class or just a key
52
- return (0, request_creator_1.default)("query", "Query", resolver, schemaOrTransform, false);
53
- }
54
- /**
55
- * Get the body of the request or transform it via a schema.
56
- *
57
- * @example
58
- * \@Body()
59
- * \@Body(CreateUserDto)
60
- */
61
- function Body(schemaOrResolver) {
62
- const resolver = (request) => __awaiter(this, void 0, void 0, function* () {
63
- return request.body !== undefined ? request.body : yield request.json();
64
- });
65
- if (typeof schemaOrResolver === 'function' && schemaOrResolver.prototype !== undefined) {
66
- // Case: @Body(CreateUserDto)
67
- return (0, request_creator_1.default)("req", "BODY", resolver, schemaOrResolver, true);
68
- }
69
- // Case: @Body(data => ...) (Legacy) or @Body()
70
- return (0, request_creator_1.default)("req", "BODY", (request) => __awaiter(this, void 0, void 0, function* () {
71
- const value = yield resolver(request);
72
- return typeof schemaOrResolver === 'function' ? schemaOrResolver(value) : value;
73
- }));
74
- }
75
- /**
76
- * Get the params from the request or transform via schema.
77
- *
78
- * @example
79
- * \@Param('id')
80
- * \@Param('id', IntSchema)
81
- */
82
- function Param(keyOrSchema, schemaOrValidator) {
83
- // Case: @Param(ParamsDto)
84
- if (typeof keyOrSchema === 'function' && !schemaOrValidator) {
85
- return (0, request_creator_1.default)("params", "Param", (req) => req.params, keyOrSchema, true);
86
- }
87
- const key = keyOrSchema;
88
- const resolver = (req) => (0, object_util_1.$get)(req.params, key, req.params);
89
- if (typeof schemaOrValidator === 'function' && schemaOrValidator.prototype === undefined) {
90
- // Legacy validator function
91
- return (0, request_creator_1.default)("params", "Param", (req) => {
92
- const value = resolver(req);
93
- return schemaOrValidator(value);
94
- });
95
- }
96
- return (0, request_creator_1.default)("params", "Param", resolver, schemaOrValidator, false);
97
- }
98
- /**
99
- * Get the headers from the request.
100
- */
101
- function Headers(keyOrSchema, schema) {
102
- if (typeof keyOrSchema === 'function' && !schema) {
103
- return (0, request_creator_1.default)("headers", "Headers", (req) => req.headers, keyOrSchema, true);
104
- }
105
- const key = keyOrSchema;
106
- const resolver = (req) => (0, object_util_1.$get)(req.headers, key, req.headers);
107
- return (0, request_creator_1.default)("headers", "Headers", resolver, schema, false);
108
- }
109
- const Req = () => (0, request_creator_1.default)("req", "Req", (req) => req);
110
- exports.Req = Req;
111
- const Res = () => (0, request_creator_1.default)("res", "Res", (req, res) => res);
112
- exports.Res = Res;
113
- /**
114
- * Create a custom request decorator
115
- * that can be used to extract data from the request object
116
- *
117
- *
118
- * @example
119
- * ```typescript
120
- *
121
- * interface LoginData {
122
- * username: string;
123
- * password: string;
124
- * }
125
- *
126
- * const LoginData = createCustomRequestDecorator<LoginData>({
127
- * resolver: async (request) => {
128
- * const data = await request.json();
129
- * return [data];
130
- * }
131
- * }
132
- *
133
- *
134
- *
135
- */
136
- const createCustomRequestDecorator = (decoratorName, resolver) => {
137
- return (0, request_creator_1.default)("req", decoratorName, resolver);
138
- };
139
- exports.createCustomRequestDecorator = createCustomRequestDecorator;
@@ -1,3 +0,0 @@
1
- import "reflect-metadata";
2
- import { HyperAppDecorator } from "./types";
3
- export declare const HyperApp: HyperAppDecorator;