@zenofolio/hyper-decor 1.0.4 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (154) hide show
  1. package/README.md +64 -1
  2. package/debug.txt +1 -0
  3. package/dist/__internals/constants.d.ts +5 -1
  4. package/dist/__internals/constants.js +5 -1
  5. package/dist/__internals/creators/request.creator.d.ts +2 -3
  6. package/dist/__internals/creators/request.creator.js +5 -3
  7. package/dist/__internals/creators/routes.creator.d.ts +2 -3
  8. package/dist/__internals/creators/routes.creator.js +5 -3
  9. package/dist/__internals/decorator-base.js +47 -11
  10. package/dist/__internals/helpers/imports.helper.d.ts +8 -0
  11. package/dist/__internals/helpers/imports.helper.js +92 -0
  12. package/dist/__internals/helpers/lifecycle.helper.d.ts +3 -0
  13. package/dist/__internals/helpers/lifecycle.helper.js +25 -0
  14. package/dist/__internals/helpers/merge-metadata.js +16 -20
  15. package/dist/__internals/helpers/prepare.helper.d.ts +11 -0
  16. package/dist/__internals/helpers/prepare.helper.js +348 -0
  17. package/dist/__internals/helpers/tree.helper.d.ts +36 -0
  18. package/dist/__internals/helpers/tree.helper.js +81 -0
  19. package/dist/__internals/stores/service.store.d.ts +1 -0
  20. package/dist/__internals/{transform/pass.transfrom.js → stores/service.store.js} +2 -0
  21. package/dist/__internals/transform/middleware.transform.d.ts +3 -0
  22. package/dist/__internals/transform/middleware.transform.js +19 -0
  23. package/dist/__internals/transform/role.transform.js +8 -5
  24. package/dist/__internals/transform/scope.transfrom.d.ts +5 -7
  25. package/dist/__internals/transform/scope.transfrom.js +52 -38
  26. package/dist/__internals/transform/transform.registry.d.ts +33 -0
  27. package/dist/__internals/transform/transform.registry.js +59 -0
  28. package/dist/__internals/utils/function.util.d.ts +1 -4
  29. package/dist/__internals/utils/function.util.js +22 -10
  30. package/dist/common/bootstrap.js +4 -0
  31. package/dist/common/helpers/index.d.ts +1 -0
  32. package/dist/common/helpers/index.js +1 -0
  33. package/dist/common/helpers/scopes.d.ts +3 -3
  34. package/dist/common/helpers/scopes.js +7 -8
  35. package/dist/common/helpers/state.d.ts +17 -0
  36. package/dist/common/helpers/state.js +44 -0
  37. package/dist/common/message-bus.d.ts +11 -0
  38. package/dist/common/message-bus.js +51 -0
  39. package/dist/common/transport.d.ts +9 -0
  40. package/dist/common/transport.js +46 -0
  41. package/dist/decorators/File.d.ts +1 -1
  42. package/dist/decorators/Http.d.ts +20 -13
  43. package/dist/decorators/Http.js +77 -31
  44. package/dist/decorators/HyperApp.d.ts +0 -4
  45. package/dist/decorators/HyperApp.js +16 -182
  46. package/dist/decorators/HyperController.js +2 -1
  47. package/dist/decorators/HyperService.d.ts +15 -0
  48. package/dist/decorators/HyperService.js +29 -0
  49. package/dist/decorators/Messaging.d.ts +10 -0
  50. package/dist/decorators/Messaging.js +22 -0
  51. package/dist/decorators/Middleware.d.ts +5 -4
  52. package/dist/decorators/Middleware.js +33 -19
  53. package/dist/decorators/Output.d.ts +9 -0
  54. package/dist/decorators/Output.js +18 -0
  55. package/dist/decorators/Pass.d.ts +6 -3
  56. package/dist/decorators/Pass.js +6 -3
  57. package/dist/decorators/Role.js +5 -5
  58. package/dist/decorators/Routes.d.ts +14 -13
  59. package/dist/decorators/Scope.js +3 -3
  60. package/dist/decorators/Transform.d.ts +14 -0
  61. package/dist/decorators/Transform.js +18 -0
  62. package/dist/decorators/index.d.ts +3 -0
  63. package/dist/decorators/index.js +3 -0
  64. package/dist/decorators/types.d.ts +45 -10
  65. package/dist/decorators/types.js +4 -0
  66. package/dist/extension.js +11 -2
  67. package/dist/index.d.ts +6 -0
  68. package/dist/index.js +6 -0
  69. package/dist/lib/openapi/collectors/class.collector.d.ts +9 -0
  70. package/dist/lib/openapi/collectors/class.collector.js +67 -0
  71. package/dist/lib/openapi/collectors/index.d.ts +4 -0
  72. package/dist/lib/openapi/collectors/index.js +20 -0
  73. package/dist/lib/openapi/collectors/method.collector.d.ts +2 -0
  74. package/dist/lib/openapi/collectors/method.collector.js +68 -0
  75. package/dist/lib/openapi/collectors/param.collector.d.ts +2 -0
  76. package/dist/lib/openapi/collectors/param.collector.js +64 -0
  77. package/dist/lib/openapi/collectors/schema.collector.d.ts +11 -0
  78. package/dist/lib/openapi/collectors/schema.collector.js +37 -0
  79. package/dist/lib/openapi/constants.d.ts +46 -0
  80. package/dist/lib/openapi/constants.js +61 -0
  81. package/dist/lib/openapi/decorators/api-bearer-auth.decorator.d.ts +2 -0
  82. package/dist/lib/openapi/decorators/api-bearer-auth.decorator.js +10 -0
  83. package/dist/lib/openapi/decorators/api-method.decorator.d.ts +3 -0
  84. package/dist/lib/openapi/decorators/api-method.decorator.js +11 -0
  85. package/dist/lib/openapi/decorators/api-parameter.decorator.d.ts +3 -0
  86. package/dist/lib/openapi/decorators/api-parameter.decorator.js +10 -0
  87. package/dist/lib/openapi/decorators/api-request-body.decorator.d.ts +3 -0
  88. package/dist/lib/openapi/decorators/api-request-body.decorator.js +10 -0
  89. package/dist/lib/openapi/decorators/api-response.decorator.d.ts +3 -0
  90. package/dist/lib/openapi/decorators/api-response.decorator.js +10 -0
  91. package/dist/lib/openapi/decorators/api-security.decorator.d.ts +3 -0
  92. package/dist/lib/openapi/decorators/api-security.decorator.js +10 -0
  93. package/dist/lib/openapi/decorators/api-tag.decorator.d.ts +3 -0
  94. package/dist/lib/openapi/decorators/api-tag.decorator.js +13 -0
  95. package/dist/lib/openapi/decorators/index.d.ts +7 -0
  96. package/dist/lib/openapi/decorators/index.js +23 -0
  97. package/dist/lib/openapi/helpers/index.d.ts +7 -0
  98. package/dist/lib/openapi/helpers/index.js +23 -0
  99. package/dist/lib/openapi/helpers/method.helper.d.ts +3 -0
  100. package/dist/lib/openapi/helpers/method.helper.js +20 -0
  101. package/dist/lib/openapi/helpers/openapi.helper.d.ts +7 -0
  102. package/dist/lib/openapi/helpers/openapi.helper.js +51 -0
  103. package/dist/lib/openapi/helpers/parameter.helper.d.ts +3 -0
  104. package/dist/lib/openapi/helpers/parameter.helper.js +16 -0
  105. package/dist/lib/openapi/helpers/request-body.helper.d.ts +3 -0
  106. package/dist/lib/openapi/helpers/request-body.helper.js +9 -0
  107. package/dist/lib/openapi/helpers/response.helper.d.ts +3 -0
  108. package/dist/lib/openapi/helpers/response.helper.js +18 -0
  109. package/dist/lib/openapi/helpers/security.helper.d.ts +3 -0
  110. package/dist/lib/openapi/helpers/security.helper.js +17 -0
  111. package/dist/lib/openapi/helpers/tag.helper.d.ts +3 -0
  112. package/dist/lib/openapi/helpers/tag.helper.js +10 -0
  113. package/dist/lib/openapi/index.d.ts +6 -0
  114. package/dist/lib/openapi/index.js +22 -0
  115. package/dist/lib/openapi/metadata.registry.d.ts +29 -0
  116. package/dist/lib/openapi/metadata.registry.js +41 -0
  117. package/dist/lib/openapi/types.d.ts +131 -0
  118. package/dist/stores/index.d.ts +1 -0
  119. package/dist/{common/openapi → stores}/index.js +1 -2
  120. package/dist/stores/scope.store.d.ts +14 -0
  121. package/dist/stores/scope.store.js +29 -0
  122. package/dist/type.d.ts +13 -2
  123. package/hyper-express-decorators.d.ts +1 -0
  124. package/package.json +73 -60
  125. package/scripts/clean.js +56 -0
  126. package/scripts/test-server.ts +85 -0
  127. package/tsconfig.json +18 -13
  128. package/vitest.config.mjs +30 -0
  129. package/vitest.json +0 -0
  130. package/.mocharc.js +0 -5
  131. package/dist/__internals/store.d.ts +0 -10
  132. package/dist/__internals/store.js +0 -17
  133. package/dist/__internals/stores/middleware.store.d.ts +0 -7
  134. package/dist/__internals/stores/middleware.store.js +0 -19
  135. package/dist/__internals/stores/params.store.d.ts +0 -21
  136. package/dist/__internals/stores/params.store.js +0 -65
  137. package/dist/__internals/stores/routes.store.d.ts +0 -17
  138. package/dist/__internals/stores/routes.store.js +0 -43
  139. package/dist/__internals/stores/store.interface.d.ts +0 -8
  140. package/dist/__internals/transform/method.transform.d.ts +0 -2
  141. package/dist/__internals/transform/method.transform.js +0 -20
  142. package/dist/__internals/transform/pass.transfrom.d.ts +0 -1
  143. package/dist/__internals/utils/mixin.utils.d.ts +0 -11
  144. package/dist/__internals/utils/mixin.utils.js +0 -34
  145. package/dist/__internals/utils/router.d.ts +0 -1
  146. package/dist/__internals/utils/router.js +0 -2
  147. package/dist/common/openapi/collect-class-data.d.ts +0 -21
  148. package/dist/common/openapi/collect-class-data.js +0 -45
  149. package/dist/common/openapi/collect-function-data.d.ts +0 -32
  150. package/dist/common/openapi/collect-function-data.js +0 -70
  151. package/dist/common/openapi/index.d.ts +0 -2
  152. /package/dist/__internals/stores/{index.d.ts → metadata.store.d.ts} +0 -0
  153. /package/dist/__internals/stores/{index.js → metadata.store.js} +0 -0
  154. /package/dist/{__internals/stores/store.interface.js → lib/openapi/types.js} +0 -0
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ApiParameter = ApiParameter;
4
+ require("reflect-metadata");
5
+ const parameter_helper_1 = require("../helpers/parameter.helper");
6
+ function ApiParameter(options) {
7
+ return (target, propertyKey) => {
8
+ (0, parameter_helper_1.apiParameter)(target, propertyKey, options);
9
+ };
10
+ }
@@ -0,0 +1,3 @@
1
+ import 'reflect-metadata';
2
+ import { RequestBody } from '../types';
3
+ export declare function ApiRequestBody(options: RequestBody): (target: any, propertyKey: any) => void;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ApiRequestBody = ApiRequestBody;
4
+ require("reflect-metadata");
5
+ const request_body_helper_1 = require("../helpers/request-body.helper");
6
+ function ApiRequestBody(options) {
7
+ return (target, propertyKey) => {
8
+ (0, request_body_helper_1.apiRequestBody)(target, propertyKey, options);
9
+ };
10
+ }
@@ -0,0 +1,3 @@
1
+ import "reflect-metadata";
2
+ import { OpenApiResponses } from "../types";
3
+ export declare function ApiResponse(options: OpenApiResponses): (target: any, propertyKey?: any, descriptor?: any) => any;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ApiResponse = ApiResponse;
4
+ require("reflect-metadata");
5
+ const response_helper_1 = require("../helpers/response.helper");
6
+ function ApiResponse(options) {
7
+ return (target, propertyKey, descriptor) => {
8
+ (0, response_helper_1.apiResponse)(target, propertyKey, options);
9
+ };
10
+ }
@@ -0,0 +1,3 @@
1
+ import 'reflect-metadata';
2
+ import { SecurityRequirement } from '../types';
3
+ export declare function ApiSecurity(options: SecurityRequirement): (target: any, propertyKey?: any, descriptor?: any) => void;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ApiSecurity = ApiSecurity;
4
+ require("reflect-metadata");
5
+ const security_helper_1 = require("../helpers/security.helper");
6
+ function ApiSecurity(options) {
7
+ return (target, propertyKey, descriptor) => {
8
+ (0, security_helper_1.apiSecurity)(target, options, propertyKey);
9
+ };
10
+ }
@@ -0,0 +1,3 @@
1
+ import 'reflect-metadata';
2
+ import { Tag } from '../types';
3
+ export declare function ApiTag(options: Tag | string): (target: any) => void;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ApiTag = ApiTag;
4
+ require("reflect-metadata");
5
+ const tag_helper_1 = require("../helpers/tag.helper");
6
+ function ApiTag(options) {
7
+ return (target) => {
8
+ if (typeof options === 'string') {
9
+ options = { name: options };
10
+ }
11
+ (0, tag_helper_1.apiTag)(target, options);
12
+ };
13
+ }
@@ -0,0 +1,7 @@
1
+ export * from "./api-method.decorator";
2
+ export * from "./api-parameter.decorator";
3
+ export * from "./api-request-body.decorator";
4
+ export * from "./api-response.decorator";
5
+ export * from "./api-security.decorator";
6
+ export * from "./api-bearer-auth.decorator";
7
+ export * from "./api-tag.decorator";
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./api-method.decorator"), exports);
18
+ __exportStar(require("./api-parameter.decorator"), exports);
19
+ __exportStar(require("./api-request-body.decorator"), exports);
20
+ __exportStar(require("./api-response.decorator"), exports);
21
+ __exportStar(require("./api-security.decorator"), exports);
22
+ __exportStar(require("./api-bearer-auth.decorator"), exports);
23
+ __exportStar(require("./api-tag.decorator"), exports);
@@ -0,0 +1,7 @@
1
+ export * from "./method.helper";
2
+ export * from "./parameter.helper";
3
+ export * from "./request-body.helper";
4
+ export * from "./response.helper";
5
+ export * from "./security.helper";
6
+ export * from "./tag.helper";
7
+ export * from "./openapi.helper";
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
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);
@@ -0,0 +1,3 @@
1
+ import "reflect-metadata";
2
+ import { Operation } from "../types";
3
+ export declare function apimethod(target: any, propertyKey: string | symbol, options: Partial<Operation>): void;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.apimethod = apimethod;
4
+ require("reflect-metadata");
5
+ const constants_1 = require("../constants");
6
+ const response_helper_1 = require("./response.helper");
7
+ function apimethod(target, propertyKey, options) {
8
+ if (options.summary) {
9
+ Reflect.defineMetadata(constants_1.METHOD_SUMMARY, options.summary, target, propertyKey);
10
+ }
11
+ if (options.operationId) {
12
+ Reflect.defineMetadata(constants_1.METHOD_OPERATION_ID, options.operationId, target, propertyKey);
13
+ }
14
+ if (options.tags) {
15
+ Reflect.defineMetadata(constants_1.METHOD_TAGS, options.tags, target, propertyKey);
16
+ }
17
+ if (options.responses) {
18
+ (0, response_helper_1.apiResponse)(target, propertyKey, options.responses);
19
+ }
20
+ }
@@ -0,0 +1,7 @@
1
+ import { OpenAPIDocument } from "../types";
2
+ /**
3
+ * Generates a complete OpenAPI 3.0.0 document from a HyperApp class.
4
+ *
5
+ * @param App The HyperApp class (usually decorated with @HyperApp)
6
+ */
7
+ export declare function getOpenAPI(App: any): OpenAPIDocument;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getOpenAPI = getOpenAPI;
4
+ const tree_helper_1 = require("../../../__internals/helpers/tree.helper");
5
+ /**
6
+ * Generates a complete OpenAPI 3.0.0 document from a HyperApp class.
7
+ *
8
+ * @param App The HyperApp class (usually decorated with @HyperApp)
9
+ */
10
+ function getOpenAPI(App) {
11
+ var _a;
12
+ const tree = (0, tree_helper_1.getAppTree)(App);
13
+ const appMeta = tree.app;
14
+ const doc = {
15
+ openapi: "3.0.0",
16
+ info: {
17
+ title: appMeta.name || "API Documentation",
18
+ version: appMeta.version || "1.0.0",
19
+ description: appMeta.description || "",
20
+ },
21
+ paths: {},
22
+ components: Object.assign({ schemas: {}, securitySchemes: {} }, (_a = tree.openapi) === null || _a === void 0 ? void 0 : _a.components)
23
+ };
24
+ // Populate paths from the flattened tree paths
25
+ Object.entries(tree.paths).forEach(([path, routes]) => {
26
+ // Convert /v1/user/ to /v1/user (remove trailing slash except for root)
27
+ const normalizedPath = path.length > 1 && path.endsWith("/") ? path.slice(0, -1) : path;
28
+ if (!doc.paths[normalizedPath]) {
29
+ doc.paths[normalizedPath] = {};
30
+ }
31
+ const pathItem = doc.paths[normalizedPath];
32
+ routes.forEach(route => {
33
+ var _a;
34
+ const method = route.method.toLowerCase();
35
+ // Merge route-level OpenAPI metadata
36
+ const operation = Object.assign(Object.assign({}, route.openapi), { responses: ((_a = route.openapi) === null || _a === void 0 ? void 0 : _a.responses) || {
37
+ "200": { description: "Successful operation" }
38
+ } });
39
+ // Ensure operationId if missing for better client generation
40
+ if (!operation.operationId) {
41
+ operation.operationId = `${route.propertyKey}`;
42
+ }
43
+ pathItem[method] = operation;
44
+ });
45
+ });
46
+ // Apply any global tree processors that might have added data to tree.openapi
47
+ if (tree.openapi) {
48
+ Object.assign(doc, tree.openapi);
49
+ }
50
+ return doc;
51
+ }
@@ -0,0 +1,3 @@
1
+ import 'reflect-metadata';
2
+ import { OpenApiParameter } from '../types';
3
+ export declare function apiParameter(target: any, propertyKey: string, options: OpenApiParameter): void;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.apiParameter = apiParameter;
4
+ require("reflect-metadata");
5
+ const constants_1 = require("../constants");
6
+ function apiParameter(target, propertyKey, options) {
7
+ const existingParameters = Reflect.getMetadata(constants_1.PARAMETERS, target, propertyKey) || [];
8
+ existingParameters.push({
9
+ name: options.name,
10
+ in: options.in,
11
+ required: options.required || false,
12
+ description: options.description,
13
+ schema: options.schema,
14
+ });
15
+ Reflect.defineMetadata(constants_1.PARAMETERS, existingParameters, target, propertyKey);
16
+ }
@@ -0,0 +1,3 @@
1
+ import 'reflect-metadata';
2
+ import { RequestBody } from '../types';
3
+ export declare function apiRequestBody(target: any, propertyKey: string, options: RequestBody): void;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.apiRequestBody = apiRequestBody;
4
+ require("reflect-metadata");
5
+ const constants_1 = require("../constants");
6
+ function apiRequestBody(target, propertyKey, options) {
7
+ Reflect.defineMetadata(constants_1.REQUEST_BODY_DESCRIPTION, options.description, target, propertyKey);
8
+ Reflect.defineMetadata(constants_1.REQUEST_BODY_CONTENT, options.content, target, propertyKey);
9
+ }
@@ -0,0 +1,3 @@
1
+ import "reflect-metadata";
2
+ import { OpenApiResponses } from "../types";
3
+ export declare function apiResponse(target: any, propertyKey: string | symbol, options: OpenApiResponses): void;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.apiResponse = apiResponse;
4
+ require("reflect-metadata");
5
+ const constants_1 = require("../constants");
6
+ function apiResponse(target, propertyKey, options) {
7
+ const existingResponses = Reflect.getMetadata(constants_1.RESPONSES, target, propertyKey) || {};
8
+ for (const key in options) {
9
+ if (options.hasOwnProperty(key)) {
10
+ const response = options[key];
11
+ existingResponses[key] = {
12
+ description: response.description,
13
+ content: response.content,
14
+ };
15
+ }
16
+ }
17
+ Reflect.defineMetadata(constants_1.RESPONSES, existingResponses, target, propertyKey);
18
+ }
@@ -0,0 +1,3 @@
1
+ import 'reflect-metadata';
2
+ import { SecurityRequirement } from '../types';
3
+ export declare function apiSecurity(target: any, options: SecurityRequirement, propertyKey?: string): void;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.apiSecurity = apiSecurity;
4
+ require("reflect-metadata");
5
+ const constants_1 = require("../constants");
6
+ function apiSecurity(target, options, propertyKey) {
7
+ const existingSecurity = propertyKey
8
+ ? Reflect.getMetadata(constants_1.SECURITY, target, propertyKey) || []
9
+ : Reflect.getMetadata(constants_1.SECURITY, target) || [];
10
+ existingSecurity.push(options);
11
+ if (propertyKey) {
12
+ Reflect.defineMetadata(constants_1.SECURITY, existingSecurity, target, propertyKey);
13
+ }
14
+ else {
15
+ Reflect.defineMetadata(constants_1.SECURITY, existingSecurity, target);
16
+ }
17
+ }
@@ -0,0 +1,3 @@
1
+ import 'reflect-metadata';
2
+ import { Tag } from '../types';
3
+ export declare function apiTag(target: any, options: Tag): void;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.apiTag = apiTag;
4
+ require("reflect-metadata");
5
+ const constants_1 = require("../constants");
6
+ function apiTag(target, options) {
7
+ const existingTags = Reflect.getMetadata(constants_1.TAGS, target) || [];
8
+ existingTags.push({ name: options.name, description: options.description });
9
+ Reflect.defineMetadata(constants_1.TAGS, existingTags, target);
10
+ }
@@ -0,0 +1,6 @@
1
+ export * from "./metadata.registry";
2
+ export * from "./constants";
3
+ export * from "./collectors";
4
+ export * from "./decorators";
5
+ export * from "./helpers";
6
+ export * from "./types";
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./metadata.registry"), exports);
18
+ __exportStar(require("./constants"), exports);
19
+ __exportStar(require("./collectors"), exports);
20
+ __exportStar(require("./decorators"), exports);
21
+ __exportStar(require("./helpers"), exports);
22
+ __exportStar(require("./types"), exports);
@@ -0,0 +1,29 @@
1
+ import { AppTree } from "../../__internals/helpers/tree.helper";
2
+ export type CollectorType = "class" | "method" | "param";
3
+ export type CollectorFn = (target: any, propertyKey?: string) => any;
4
+ export type TreeProcessorFn = (tree: AppTree) => void;
5
+ declare class OpenAPIMetadataRegistry {
6
+ private collectors;
7
+ private processors;
8
+ /**
9
+ * Register a custom metadata collector.
10
+ * @param type The level where the collector operates.
11
+ * @param collector The function that extracts metadata.
12
+ */
13
+ registerCollector(type: CollectorType, collector: CollectorFn): void;
14
+ /**
15
+ * Register a processor to transform the final AppTree.
16
+ * @param processor The function that enriches the tree.
17
+ */
18
+ registerProcessor(processor: TreeProcessorFn): void;
19
+ /**
20
+ * Returns all registered collectors for a specific type.
21
+ */
22
+ getCollectors(type: CollectorType): CollectorFn[];
23
+ /**
24
+ * Returns all registered tree processors.
25
+ */
26
+ getProcessors(): TreeProcessorFn[];
27
+ }
28
+ export declare const openApiRegistry: OpenAPIMetadataRegistry;
29
+ export {};
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.openApiRegistry = void 0;
4
+ class OpenAPIMetadataRegistry {
5
+ constructor() {
6
+ this.collectors = {
7
+ class: new Set(),
8
+ method: new Set(),
9
+ param: new Set(),
10
+ };
11
+ this.processors = new Set();
12
+ }
13
+ /**
14
+ * Register a custom metadata collector.
15
+ * @param type The level where the collector operates.
16
+ * @param collector The function that extracts metadata.
17
+ */
18
+ registerCollector(type, collector) {
19
+ this.collectors[type].add(collector);
20
+ }
21
+ /**
22
+ * Register a processor to transform the final AppTree.
23
+ * @param processor The function that enriches the tree.
24
+ */
25
+ registerProcessor(processor) {
26
+ this.processors.add(processor);
27
+ }
28
+ /**
29
+ * Returns all registered collectors for a specific type.
30
+ */
31
+ getCollectors(type) {
32
+ return Array.from(this.collectors[type]);
33
+ }
34
+ /**
35
+ * Returns all registered tree processors.
36
+ */
37
+ getProcessors() {
38
+ return Array.from(this.processors);
39
+ }
40
+ }
41
+ exports.openApiRegistry = new OpenAPIMetadataRegistry();
@@ -0,0 +1,131 @@
1
+ export interface OpenAPIDocument {
2
+ openapi: string;
3
+ info: Info;
4
+ paths: Paths;
5
+ components?: Components;
6
+ security?: SecurityRequirement[];
7
+ tags?: Tag[];
8
+ }
9
+ export interface Info {
10
+ title: string;
11
+ description?: string;
12
+ termsOfService?: string;
13
+ contact?: Contact;
14
+ license?: License;
15
+ version: string;
16
+ }
17
+ export interface Contact {
18
+ name?: string;
19
+ url?: string;
20
+ email?: string;
21
+ }
22
+ export interface License {
23
+ name: string;
24
+ url?: string;
25
+ }
26
+ export interface Paths {
27
+ [path: string]: PathItem;
28
+ }
29
+ export interface PathItem {
30
+ get?: Operation;
31
+ post?: Operation;
32
+ put?: Operation;
33
+ delete?: Operation;
34
+ patch?: Operation;
35
+ head?: Operation;
36
+ options?: Operation;
37
+ trace?: Operation;
38
+ }
39
+ export interface Operation {
40
+ summary?: string;
41
+ description?: string;
42
+ operationId?: string;
43
+ tags?: Tag[];
44
+ parameters?: OpenApiParameter[];
45
+ requestBody?: RequestBody;
46
+ responses: OpenApiResponses;
47
+ security?: SecurityRequirement[];
48
+ }
49
+ export interface OpenApiParameter {
50
+ name: string;
51
+ in: "query" | "header" | "path" | "cookie";
52
+ description?: string;
53
+ required?: boolean;
54
+ deprecated?: boolean;
55
+ allowEmptyValue?: boolean;
56
+ schema: Schema;
57
+ }
58
+ export interface RequestBody {
59
+ description?: string;
60
+ content: {
61
+ [mediaType: string]: MediaType;
62
+ };
63
+ }
64
+ export interface MediaType {
65
+ schema: Schema;
66
+ }
67
+ export interface OpenApiResponses {
68
+ [statusCode: string]: OpenApiResponse;
69
+ }
70
+ export interface OpenApiResponse {
71
+ description: string;
72
+ content?: {
73
+ [mediaType: string]: MediaType;
74
+ };
75
+ headers?: {
76
+ [name: string]: Header;
77
+ };
78
+ }
79
+ export interface Header {
80
+ description?: string;
81
+ required?: boolean;
82
+ schema: Schema;
83
+ }
84
+ export interface Schema {
85
+ type: string;
86
+ format?: string;
87
+ items?: Schema;
88
+ properties?: {
89
+ [key: string]: Schema;
90
+ };
91
+ additionalProperties?: boolean;
92
+ example?: any;
93
+ }
94
+ export interface SecurityRequirement {
95
+ [securityScheme: string]: string[];
96
+ }
97
+ export interface Tag {
98
+ name: string;
99
+ description?: string;
100
+ }
101
+ export interface Components {
102
+ schemas?: {
103
+ [schemaName: string]: Schema;
104
+ };
105
+ responses?: {
106
+ [responseName: string]: OpenApiResponse;
107
+ };
108
+ parameters?: {
109
+ [parameterName: string]: OpenApiParameter;
110
+ };
111
+ securitySchemes?: {
112
+ [schemeName: string]: SecurityScheme;
113
+ };
114
+ }
115
+ export interface SecurityScheme {
116
+ type: "apiKey" | "http" | "oauth2" | "openIdConnect";
117
+ in?: "header" | "query" | "cookie";
118
+ name?: string;
119
+ scheme?: string;
120
+ bearerFormat?: string;
121
+ openIdConnectUrl?: string;
122
+ oauth2?: OAuth2Scheme;
123
+ }
124
+ export interface OAuth2Scheme {
125
+ authorizationUrl: string;
126
+ tokenUrl: string;
127
+ refreshUrl?: string;
128
+ scopes: {
129
+ [scope: string]: string;
130
+ };
131
+ }
@@ -0,0 +1 @@
1
+ export * from "./scope.store";
@@ -14,5 +14,4 @@ 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("./collect-class-data"), exports);
18
- __exportStar(require("./collect-function-data"), exports);
17
+ __exportStar(require("./scope.store"), exports);
@@ -0,0 +1,14 @@
1
+ import { ScopeMap } from "../decorators";
2
+ /**
3
+ * This class is a store for the scopes that are defined in the application.
4
+ *
5
+ */
6
+ export declare class ScopeStore {
7
+ private static scopes;
8
+ static add(scope: ScopeMap): void;
9
+ static addAll(scopes: ScopeMap[]): void;
10
+ static getScopes(): ScopeMap[];
11
+ static getScopeNames(): string[];
12
+ static isEmpty(): boolean;
13
+ static clear(): void;
14
+ }
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ScopeStore = void 0;
4
+ /**
5
+ * This class is a store for the scopes that are defined in the application.
6
+ *
7
+ */
8
+ class ScopeStore {
9
+ static add(scope) {
10
+ this.scopes.set(scope.scope, scope); // Evita duplicados basados en el nombre del scope
11
+ }
12
+ static addAll(scopes) {
13
+ scopes.forEach((scope) => this.add(scope));
14
+ }
15
+ static getScopes() {
16
+ return Array.from(this.scopes.values());
17
+ }
18
+ static getScopeNames() {
19
+ return Array.from(this.scopes.keys());
20
+ }
21
+ static isEmpty() {
22
+ return this.scopes.size === 0;
23
+ }
24
+ static clear() {
25
+ this.scopes.clear();
26
+ }
27
+ }
28
+ exports.ScopeStore = ScopeStore;
29
+ ScopeStore.scopes = new Map();
package/dist/type.d.ts CHANGED
@@ -1,10 +1,21 @@
1
1
  import type { Server } from "hyper-express";
2
+ declare module "hyper-express" {
3
+ interface Request {
4
+ setValue(key: string, value: any): void;
5
+ getValue<T>(key: string, defaultValue?: T): T;
6
+ }
7
+ }
8
+ import { TransformerInput } from "./__internals/transform/transform.registry";
2
9
  export type HyperRoleOptions = string | string[];
3
10
  export type HyperScopeOptions = string | string[];
4
11
  export interface IHyperApplication extends Partial<Server> {
5
- onPrepare(): void;
12
+ onPrepare?(): void;
13
+ emit?(topic: string, data: any): Promise<void>;
6
14
  }
7
- export type IHyperApp<T> = T & Server;
15
+ export type IHyperApp<T> = T & Server & {
16
+ emit(topic: string, data: any): Promise<void>;
17
+ useTransform(transformer: TransformerInput): IHyperApp<T>;
18
+ };
8
19
  export interface IHyperAppTarget {
9
20
  new (...args: any[]): IHyperApplication;
10
21
  }