@zenofolio/hyper-decor 0.0.3

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 (120) hide show
  1. package/.mocharc.js +5 -0
  2. package/LICENSE +21 -0
  3. package/README.md +191 -0
  4. package/dist/__internals/constants.d.ts +61 -0
  5. package/dist/__internals/constants.js +72 -0
  6. package/dist/__internals/creators/request.creator.d.ts +12 -0
  7. package/dist/__internals/creators/request.creator.js +53 -0
  8. package/dist/__internals/creators/routes.creator.d.ts +10 -0
  9. package/dist/__internals/creators/routes.creator.js +37 -0
  10. package/dist/__internals/decorator-base.d.ts +30 -0
  11. package/dist/__internals/decorator-base.js +86 -0
  12. package/dist/__internals/helpers/merge-metadata.d.ts +14 -0
  13. package/dist/__internals/helpers/merge-metadata.js +44 -0
  14. package/dist/__internals/helpers/who.helper.d.ts +9 -0
  15. package/dist/__internals/helpers/who.helper.js +19 -0
  16. package/dist/__internals/store.d.ts +10 -0
  17. package/dist/__internals/store.js +17 -0
  18. package/dist/__internals/stores/index.d.ts +15 -0
  19. package/dist/__internals/stores/index.js +37 -0
  20. package/dist/__internals/stores/middleware.store.d.ts +7 -0
  21. package/dist/__internals/stores/middleware.store.js +19 -0
  22. package/dist/__internals/stores/params.store.d.ts +21 -0
  23. package/dist/__internals/stores/params.store.js +65 -0
  24. package/dist/__internals/stores/routes.store.d.ts +17 -0
  25. package/dist/__internals/stores/routes.store.js +43 -0
  26. package/dist/__internals/stores/store.interface.d.ts +8 -0
  27. package/dist/__internals/stores/store.interface.js +2 -0
  28. package/dist/__internals/transform/method.transform.d.ts +2 -0
  29. package/dist/__internals/transform/method.transform.js +20 -0
  30. package/dist/__internals/transform/pass.transfrom.d.ts +1 -0
  31. package/dist/__internals/transform/pass.transfrom.js +2 -0
  32. package/dist/__internals/transform/role.transform.d.ts +7 -0
  33. package/dist/__internals/transform/role.transform.js +86 -0
  34. package/dist/__internals/transform/scope.transfrom.d.ts +7 -0
  35. package/dist/__internals/transform/scope.transfrom.js +72 -0
  36. package/dist/__internals/types.d.ts +8 -0
  37. package/dist/__internals/types.js +2 -0
  38. package/dist/__internals/utils/function.util.d.ts +4 -0
  39. package/dist/__internals/utils/function.util.js +20 -0
  40. package/dist/__internals/utils/mixin.utils.d.ts +11 -0
  41. package/dist/__internals/utils/mixin.utils.js +34 -0
  42. package/dist/__internals/utils/object.util.d.ts +27 -0
  43. package/dist/__internals/utils/object.util.js +72 -0
  44. package/dist/__internals/utils/path.util.d.ts +4 -0
  45. package/dist/__internals/utils/path.util.js +8 -0
  46. package/dist/__internals/utils/router.d.ts +1 -0
  47. package/dist/__internals/utils/router.js +2 -0
  48. package/dist/common/bootstrap.d.ts +3 -0
  49. package/dist/common/bootstrap.js +25 -0
  50. package/dist/common/helpers/index.d.ts +2 -0
  51. package/dist/common/helpers/index.js +18 -0
  52. package/dist/common/helpers/role.d.ts +22 -0
  53. package/dist/common/helpers/role.js +43 -0
  54. package/dist/common/helpers/scopes.d.ts +23 -0
  55. package/dist/common/helpers/scopes.js +47 -0
  56. package/dist/common/openapi/collect-class-data.d.ts +21 -0
  57. package/dist/common/openapi/collect-class-data.js +45 -0
  58. package/dist/common/openapi/collect-function-data.d.ts +32 -0
  59. package/dist/common/openapi/collect-function-data.js +70 -0
  60. package/dist/common/openapi/index.d.ts +2 -0
  61. package/dist/common/openapi/index.js +18 -0
  62. package/dist/constants.d.ts +3 -0
  63. package/dist/constants.js +6 -0
  64. package/dist/decorators/File.d.ts +65 -0
  65. package/dist/decorators/File.js +180 -0
  66. package/dist/decorators/Http.d.ts +55 -0
  67. package/dist/decorators/Http.js +93 -0
  68. package/dist/decorators/HyperApp.d.ts +7 -0
  69. package/dist/decorators/HyperApp.js +262 -0
  70. package/dist/decorators/HyperController.d.ts +2 -0
  71. package/dist/decorators/HyperController.js +19 -0
  72. package/dist/decorators/HyperModule.d.ts +5 -0
  73. package/dist/decorators/HyperModule.js +14 -0
  74. package/dist/decorators/Middleware.d.ts +24 -0
  75. package/dist/decorators/Middleware.js +51 -0
  76. package/dist/decorators/Pass.d.ts +12 -0
  77. package/dist/decorators/Pass.js +29 -0
  78. package/dist/decorators/Role.d.ts +6 -0
  79. package/dist/decorators/Role.js +34 -0
  80. package/dist/decorators/Routes.d.ts +14 -0
  81. package/dist/decorators/Routes.js +21 -0
  82. package/dist/decorators/Scope.d.ts +6 -0
  83. package/dist/decorators/Scope.js +25 -0
  84. package/dist/decorators/index.d.ts +11 -0
  85. package/dist/decorators/index.js +27 -0
  86. package/dist/decorators/types.d.ts +89 -0
  87. package/dist/decorators/types.js +2 -0
  88. package/dist/exeptions/DuplicateControllerPathException.d.ts +14 -0
  89. package/dist/exeptions/DuplicateControllerPathException.js +12 -0
  90. package/dist/exeptions/DuplicatedException.d.ts +8 -0
  91. package/dist/exeptions/DuplicatedException.js +12 -0
  92. package/dist/exeptions/DuplicatedHandlerException.d.ts +4 -0
  93. package/dist/exeptions/DuplicatedHandlerException.js +12 -0
  94. package/dist/exeptions/HyperException.d.ts +7 -0
  95. package/dist/exeptions/HyperException.js +13 -0
  96. package/dist/exeptions/HyperFileException.d.ts +4 -0
  97. package/dist/exeptions/HyperFileException.js +12 -0
  98. package/dist/exeptions/MethodNotFountException.d.ts +4 -0
  99. package/dist/exeptions/MethodNotFountException.js +12 -0
  100. package/dist/exeptions/NotPropertyException.d.ts +6 -0
  101. package/dist/exeptions/NotPropertyException.js +16 -0
  102. package/dist/exeptions/NotRoleException.d.ts +6 -0
  103. package/dist/exeptions/NotRoleException.js +17 -0
  104. package/dist/exeptions/NotScopeException.d.ts +7 -0
  105. package/dist/exeptions/NotScopeException.js +18 -0
  106. package/dist/exeptions/WrongPlaceException.d.ts +8 -0
  107. package/dist/exeptions/WrongPlaceException.js +21 -0
  108. package/dist/exeptions/index.d.ts +8 -0
  109. package/dist/exeptions/index.js +18 -0
  110. package/dist/exeptions/types.d.ts +1 -0
  111. package/dist/exeptions/types.js +2 -0
  112. package/dist/extension.d.ts +1 -0
  113. package/dist/extension.js +41 -0
  114. package/dist/index.d.ts +9 -0
  115. package/dist/index.js +25 -0
  116. package/dist/type.d.ts +10 -0
  117. package/dist/type.js +2 -0
  118. package/hyper-express-decorators.d.ts +16 -0
  119. package/package.json +61 -0
  120. package/tsconfig.json +17 -0
@@ -0,0 +1,72 @@
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.$except_slash = exports.$each = exports.$constructor = exports.$get = exports.$array = void 0;
13
+ /**
14
+ * Retrieves a value from an object using a path.
15
+ */
16
+ const $get = (data, name, def) => {
17
+ if (!data || !name)
18
+ return def;
19
+ return name.split(".").reduce((data, key) => {
20
+ if (Object.prototype.hasOwnProperty.call(data, key)) {
21
+ return data[key];
22
+ }
23
+ return def;
24
+ }, data);
25
+ };
26
+ exports.$get = $get;
27
+ ////////////////////////////////////
28
+ // Array utilities
29
+ ////////////////////////////////////
30
+ /**
31
+ * Ensures the given value is returned as an array.
32
+ *
33
+ * @param {T | T[]} value - The value to ensure as an array.
34
+ * @returns {T[]} - The value as an array.
35
+ */
36
+ const $array = (value) => {
37
+ if (!value)
38
+ return [];
39
+ return Array.isArray(value) ? value : [value];
40
+ };
41
+ exports.$array = $array;
42
+ /**
43
+ * Extract constructor from value.
44
+ *
45
+ * @param value
46
+ */
47
+ const $constructor = (value) => {
48
+ if (typeof value === "object") {
49
+ return value.constructor;
50
+ }
51
+ return value;
52
+ };
53
+ exports.$constructor = $constructor;
54
+ const $each = (data, callback) => __awaiter(void 0, void 0, void 0, function* () {
55
+ if (!data || !data.length)
56
+ return [];
57
+ return yield Promise.all(data.map(callback));
58
+ });
59
+ exports.$each = $each;
60
+ const $except_slash = (message, length = 3, middle = true) => {
61
+ const parts = message.split("/");
62
+ if (parts.length === 1)
63
+ return message;
64
+ const middleLength = Math.floor(length / 2);
65
+ length = length - middleLength;
66
+ const start = parts.slice(0, length).join("/");
67
+ const end = parts.slice(-length).join("/");
68
+ if (!middle)
69
+ return `${start}/.../${end}`;
70
+ return `${start}/.../${parts.slice(-middleLength).join("/")}`;
71
+ };
72
+ exports.$except_slash = $except_slash;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Joins all given paths, removing extra slashes.
3
+ */
4
+ export declare const join: (...paths: (string | null | undefined)[]) => string;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.join = void 0;
4
+ /**
5
+ * Joins all given paths, removing extra slashes.
6
+ */
7
+ const join = (...paths) => paths.filter(Boolean).join("/").replace(/\/+/g, "/");
8
+ exports.join = join;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
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 };
@@ -0,0 +1,25 @@
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.default = createApplication;
13
+ exports.createApplication = createApplication;
14
+ const tsyringe_1 = require("tsyringe");
15
+ function createApplication(app) {
16
+ return __awaiter(this, void 0, void 0, function* () {
17
+ var _a;
18
+ const instance = tsyringe_1.container.resolve(app);
19
+ if (instance.prepare) {
20
+ yield instance.prepare();
21
+ }
22
+ (_a = instance === null || instance === void 0 ? void 0 : instance.onPrepare) === null || _a === void 0 ? void 0 : _a.call(instance);
23
+ return instance;
24
+ });
25
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./role";
2
+ export * from "./scopes";
@@ -0,0 +1,18 @@
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("./role"), exports);
18
+ __exportStar(require("./scopes"), exports);
@@ -0,0 +1,22 @@
1
+ import type { Request } from "hyper-express";
2
+ import { HyperRoleOptions } from "../../type";
3
+ /**
4
+ * Set role to request object
5
+ *
6
+ * @param {Request} request
7
+ * @param {HyperRoleOptions} role
8
+ */
9
+ export declare const setRole: (request: Request, role: HyperRoleOptions | null) => void;
10
+ /**
11
+ * Get list of roles from request object
12
+ *
13
+ * @param {Request} request
14
+ */
15
+ export declare const getRoles: (request: Request) => string[] | undefined;
16
+ /**
17
+ * Check if user has role
18
+ *
19
+ * @param {Request} request
20
+ * @param {string | string[]} role
21
+ */
22
+ export declare const hasRole: (request: Request, role: string | string[]) => boolean;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hasRole = exports.getRoles = exports.setRole = void 0;
4
+ const no_conflict_1 = require("reflect-metadata/no-conflict");
5
+ const constants_1 = require("../../constants");
6
+ const object_util_1 = require("../../__internals/utils/object.util");
7
+ /**
8
+ * Set role to request object
9
+ *
10
+ * @param {Request} request
11
+ * @param {HyperRoleOptions} role
12
+ */
13
+ const setRole = (request, role) => {
14
+ if (!role) {
15
+ (0, no_conflict_1.deleteMetadata)(constants_1.HYPER_ROLE_KEY, request);
16
+ return;
17
+ }
18
+ (0, no_conflict_1.defineMetadata)(constants_1.HYPER_ROLE_KEY, (0, object_util_1.$array)(role), request);
19
+ };
20
+ exports.setRole = setRole;
21
+ /**
22
+ * Get list of roles from request object
23
+ *
24
+ * @param {Request} request
25
+ */
26
+ const getRoles = (request) => {
27
+ return (0, no_conflict_1.getMetadata)(constants_1.HYPER_ROLE_KEY, request);
28
+ };
29
+ exports.getRoles = getRoles;
30
+ /**
31
+ * Check if user has role
32
+ *
33
+ * @param {Request} request
34
+ * @param {string | string[]} role
35
+ */
36
+ const hasRole = (request, role) => {
37
+ const roles = (0, exports.getRoles)(request);
38
+ if (!roles) {
39
+ return false;
40
+ }
41
+ return (0, object_util_1.$array)(role).every((r) => roles.includes(r));
42
+ };
43
+ exports.hasRole = hasRole;
@@ -0,0 +1,23 @@
1
+ import type { Request } from "hyper-express";
2
+ import { HyperScopeOptions } from "../../type";
3
+ /**
4
+ * Set scopes to request object
5
+ *
6
+ * @param request
7
+ * @param scopes
8
+ */
9
+ export declare const setScopes: (request: Request, scopes: HyperScopeOptions | null) => void;
10
+ /**
11
+ * Get list of scopes from request object
12
+ *
13
+ * @param request
14
+ */
15
+ export declare const getScopes: (request: Request) => string[] | undefined;
16
+ /**
17
+ * Check if request has required scopes
18
+ *
19
+ * @param request
20
+ * @param scopes
21
+ * @returns
22
+ */
23
+ export declare const hasScopes: (request: Request, scopes: HyperScopeOptions) => boolean;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hasScopes = exports.getScopes = exports.setScopes = void 0;
4
+ const no_conflict_1 = require("reflect-metadata/no-conflict");
5
+ const constants_1 = require("../../constants");
6
+ const object_util_1 = require("../../__internals/utils/object.util");
7
+ /**
8
+ * Set scopes to request object
9
+ *
10
+ * @param request
11
+ * @param scopes
12
+ */
13
+ const setScopes = (request, scopes) => {
14
+ if (!scopes) {
15
+ (0, no_conflict_1.deleteMetadata)(constants_1.HYPER_SCOPES_KEY, request);
16
+ return;
17
+ }
18
+ (0, no_conflict_1.defineMetadata)(constants_1.HYPER_SCOPES_KEY, (0, object_util_1.$array)(scopes), request);
19
+ };
20
+ exports.setScopes = setScopes;
21
+ /**
22
+ * Get list of scopes from request object
23
+ *
24
+ * @param request
25
+ */
26
+ const getScopes = (request) => {
27
+ if (!(0, no_conflict_1.hasOwnMetadata)(constants_1.HYPER_SCOPES_KEY, request)) {
28
+ return undefined;
29
+ }
30
+ return (0, no_conflict_1.getMetadata)(constants_1.HYPER_SCOPES_KEY, request);
31
+ };
32
+ exports.getScopes = getScopes;
33
+ /**
34
+ * Check if request has required scopes
35
+ *
36
+ * @param request
37
+ * @param scopes
38
+ * @returns
39
+ */
40
+ const hasScopes = (request, scopes) => {
41
+ const requestScopes = (0, exports.getScopes)(request);
42
+ if (!requestScopes) {
43
+ return false;
44
+ }
45
+ return (0, object_util_1.$array)(scopes).every((scope) => requestScopes.includes(scope));
46
+ };
47
+ exports.hasScopes = hasScopes;
@@ -0,0 +1,21 @@
1
+ import "reflect-metadata";
2
+ /**
3
+ * Options to customize class metadata extraction.
4
+ */
5
+ interface ClassDataOptions {
6
+ includePrivateMethods?: boolean;
7
+ methodOptions?: Record<string, any>;
8
+ }
9
+ /**
10
+ * Extracts metadata from a class, including methods and OpenAPI data.
11
+ *
12
+ * @param Target - The class constructor.
13
+ * @param options - Options for metadata extraction.
14
+ * @returns Object containing class metadata and method details.
15
+ */
16
+ export declare function collectClassData(Target: new (...args: any[]) => any, options?: ClassDataOptions): {
17
+ className: string;
18
+ methods: Record<string, any>;
19
+ staticMethods: Record<string, any>;
20
+ };
21
+ export {};
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.collectClassData = collectClassData;
4
+ require("reflect-metadata");
5
+ const collect_function_data_1 = require("./collect-function-data");
6
+ /**
7
+ * Extracts metadata from a class, including methods and OpenAPI data.
8
+ *
9
+ * @param Target - The class constructor.
10
+ * @param options - Options for metadata extraction.
11
+ * @returns Object containing class metadata and method details.
12
+ */
13
+ function collectClassData(Target, options = {}) {
14
+ if (typeof Target !== "function") {
15
+ throw new Error("Target must be a class constructor.");
16
+ }
17
+ const prototype = Target.prototype;
18
+ const className = Target.name;
19
+ // Get method names
20
+ const allMethods = Object.getOwnPropertyNames(prototype).filter((name) => typeof prototype[name] === "function" && name !== "constructor");
21
+ // Get static methods
22
+ const staticMethods = Object.getOwnPropertyNames(Target).filter((name) => typeof Target[name] === "function");
23
+ // Filter private methods (if not included)
24
+ const isPrivate = (name) => name.startsWith("_");
25
+ const methods = options.includePrivateMethods
26
+ ? allMethods
27
+ : allMethods.filter((m) => !isPrivate(m));
28
+ // Extract metadata for each method
29
+ const methodsData = methods.reduce((acc, methodName) => {
30
+ var _a;
31
+ acc[methodName] = (0, collect_function_data_1.collectFunctionData)(prototype[methodName], ((_a = options.methodOptions) === null || _a === void 0 ? void 0 : _a[methodName]) || {});
32
+ return acc;
33
+ }, {});
34
+ // Extract metadata for static methods
35
+ const staticMethodsData = staticMethods.reduce((acc, methodName) => {
36
+ var _a;
37
+ acc[methodName] = (0, collect_function_data_1.collectFunctionData)(Target[methodName], ((_a = options.methodOptions) === null || _a === void 0 ? void 0 : _a[methodName]) || {});
38
+ return acc;
39
+ }, {});
40
+ return {
41
+ className,
42
+ methods: methodsData,
43
+ staticMethods: staticMethodsData,
44
+ };
45
+ }
@@ -0,0 +1,32 @@
1
+ type OpenAPIParamLocation = "query" | "path" | "body";
2
+ type OpenAPIType = "string" | "number" | "boolean" | "object" | "array" | "any";
3
+ /**
4
+ * Options to customize OpenAPI metadata extraction.
5
+ */
6
+ interface FunctionDataOptions {
7
+ paramLocation?: OpenAPIParamLocation;
8
+ paramDescriptions?: Record<string, string>;
9
+ responseDescriptions?: Record<number, string>;
10
+ responseSchemas?: Record<number, any>;
11
+ }
12
+ /**
13
+ * Extracts function metadata and adapts it for OpenAPI documentation.
14
+ *
15
+ * @param Target - The function to analyze.
16
+ * @param options - Customization options for OpenAPI extraction.
17
+ * @returns An object formatted for OpenAPI documentation.
18
+ */
19
+ export declare function collectFunctionData(Target: (...args: any[]) => any, options?: FunctionDataOptions): {
20
+ operationId: string;
21
+ parameters: {
22
+ name: string;
23
+ in: OpenAPIParamLocation;
24
+ required: boolean;
25
+ description: string;
26
+ schema: {
27
+ type: OpenAPIType;
28
+ };
29
+ }[];
30
+ responses: Record<number, any>;
31
+ };
32
+ export {};
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.collectFunctionData = collectFunctionData;
4
+ const constants_1 = require("../../__internals/constants");
5
+ const function_util_1 = require("../../__internals/utils/function.util");
6
+ /**
7
+ * Maps TypeScript types to OpenAPI-compatible types.
8
+ */
9
+ const mapTypeToOpenAPI = (type) => {
10
+ if (!type)
11
+ return "any";
12
+ const typeMap = {
13
+ String: "string",
14
+ Number: "number",
15
+ Boolean: "boolean",
16
+ Object: "object",
17
+ Array: "array",
18
+ };
19
+ return type.name === "Array" ? "array" : typeMap[type.name] || "any";
20
+ };
21
+ /**
22
+ * Formats the response schema for OpenAPI.
23
+ */
24
+ const formatResponseSchema = (type, description = "Successful response") => ({
25
+ description,
26
+ content: {
27
+ "application/json": {
28
+ schema: { type: mapTypeToOpenAPI(type) },
29
+ },
30
+ },
31
+ });
32
+ /**
33
+ * Extracts function metadata and adapts it for OpenAPI documentation.
34
+ *
35
+ * @param Target - The function to analyze.
36
+ * @param options - Customization options for OpenAPI extraction.
37
+ * @returns An object formatted for OpenAPI documentation.
38
+ */
39
+ function collectFunctionData(Target, options = {}) {
40
+ var _a;
41
+ if (typeof Target !== "function") {
42
+ throw new Error("Target must be a function.");
43
+ }
44
+ // Extract metadata
45
+ const paramTypes = Reflect.getMetadata(constants_1.DESIGN_PARAMTYPES, Target) || [];
46
+ const paramNames = (_a = (0, function_util_1.extreactArgsNames)(Target)) !== null && _a !== void 0 ? _a : [];
47
+ const returnType = Reflect.getMetadata(constants_1.DESIGN_RETURNTYPE, Target);
48
+ // Default locations and descriptions
49
+ const { paramLocation = "query", paramDescriptions = {}, responseDescriptions = { 200: "Successful response" }, responseSchemas = {}, } = options;
50
+ // Build OpenAPI parameters
51
+ const parameters = paramNames.map((name, index) => ({
52
+ name,
53
+ in: paramLocation,
54
+ required: true,
55
+ description: paramDescriptions[name] || `Parameter ${name}`,
56
+ schema: { type: mapTypeToOpenAPI(paramTypes[index]) },
57
+ }));
58
+ // Build OpenAPI responses
59
+ const responses = {};
60
+ Object.entries(responseDescriptions).forEach(([statusCode, description]) => {
61
+ const code = Number(statusCode);
62
+ responses[code] =
63
+ responseSchemas[code] || formatResponseSchema(returnType, description);
64
+ });
65
+ return {
66
+ operationId: Target.name || "anonymous",
67
+ parameters,
68
+ responses,
69
+ };
70
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./collect-class-data";
2
+ export * from "./collect-function-data";
@@ -0,0 +1,18 @@
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("./collect-class-data"), exports);
18
+ __exportStar(require("./collect-function-data"), exports);
@@ -0,0 +1,3 @@
1
+ export declare const HYPER_SCOPES_KEY = "__HYPER_SCOPES_KEY";
2
+ export declare const HYPER_ROLE_KEY = "__HYPER_ROLE_KEY";
3
+ export declare const HYPER_PASS_KEY = "__HYPER_PASS_KEY";
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HYPER_PASS_KEY = exports.HYPER_ROLE_KEY = exports.HYPER_SCOPES_KEY = void 0;
4
+ exports.HYPER_SCOPES_KEY = "__HYPER_SCOPES_KEY";
5
+ exports.HYPER_ROLE_KEY = "__HYPER_ROLE_KEY";
6
+ exports.HYPER_PASS_KEY = "__HYPER_PASS_KEY";
@@ -0,0 +1,65 @@
1
+ import { Request } from "hyper-express";
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
+ };