@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.
- package/README.md +64 -1
- package/debug.txt +1 -0
- package/dist/__internals/constants.d.ts +5 -1
- package/dist/__internals/constants.js +5 -1
- package/dist/__internals/creators/request.creator.d.ts +2 -3
- package/dist/__internals/creators/request.creator.js +5 -3
- package/dist/__internals/creators/routes.creator.d.ts +2 -3
- package/dist/__internals/creators/routes.creator.js +5 -3
- package/dist/__internals/decorator-base.js +47 -11
- package/dist/__internals/helpers/imports.helper.d.ts +8 -0
- package/dist/__internals/helpers/imports.helper.js +92 -0
- package/dist/__internals/helpers/lifecycle.helper.d.ts +3 -0
- package/dist/__internals/helpers/lifecycle.helper.js +25 -0
- package/dist/__internals/helpers/merge-metadata.js +16 -20
- package/dist/__internals/helpers/prepare.helper.d.ts +11 -0
- package/dist/__internals/helpers/prepare.helper.js +348 -0
- package/dist/__internals/helpers/tree.helper.d.ts +36 -0
- package/dist/__internals/helpers/tree.helper.js +81 -0
- package/dist/__internals/stores/service.store.d.ts +1 -0
- package/dist/__internals/{transform/pass.transfrom.js → stores/service.store.js} +2 -0
- package/dist/__internals/transform/middleware.transform.d.ts +3 -0
- package/dist/__internals/transform/middleware.transform.js +19 -0
- package/dist/__internals/transform/role.transform.js +8 -5
- package/dist/__internals/transform/scope.transfrom.d.ts +5 -7
- package/dist/__internals/transform/scope.transfrom.js +52 -38
- package/dist/__internals/transform/transform.registry.d.ts +33 -0
- package/dist/__internals/transform/transform.registry.js +59 -0
- package/dist/__internals/utils/function.util.d.ts +1 -4
- package/dist/__internals/utils/function.util.js +22 -10
- package/dist/common/bootstrap.js +4 -0
- package/dist/common/helpers/index.d.ts +1 -0
- package/dist/common/helpers/index.js +1 -0
- package/dist/common/helpers/scopes.d.ts +3 -3
- package/dist/common/helpers/scopes.js +7 -8
- package/dist/common/helpers/state.d.ts +17 -0
- package/dist/common/helpers/state.js +44 -0
- package/dist/common/message-bus.d.ts +11 -0
- package/dist/common/message-bus.js +51 -0
- package/dist/common/transport.d.ts +9 -0
- package/dist/common/transport.js +46 -0
- package/dist/decorators/File.d.ts +1 -1
- package/dist/decorators/Http.d.ts +20 -13
- package/dist/decorators/Http.js +77 -31
- package/dist/decorators/HyperApp.d.ts +0 -4
- package/dist/decorators/HyperApp.js +16 -182
- package/dist/decorators/HyperController.js +2 -1
- package/dist/decorators/HyperService.d.ts +15 -0
- package/dist/decorators/HyperService.js +29 -0
- package/dist/decorators/Messaging.d.ts +10 -0
- package/dist/decorators/Messaging.js +22 -0
- package/dist/decorators/Middleware.d.ts +5 -4
- package/dist/decorators/Middleware.js +33 -19
- package/dist/decorators/Output.d.ts +9 -0
- package/dist/decorators/Output.js +18 -0
- package/dist/decorators/Pass.d.ts +6 -3
- package/dist/decorators/Pass.js +6 -3
- package/dist/decorators/Role.js +5 -5
- package/dist/decorators/Routes.d.ts +14 -13
- package/dist/decorators/Scope.js +3 -3
- package/dist/decorators/Transform.d.ts +14 -0
- package/dist/decorators/Transform.js +18 -0
- package/dist/decorators/index.d.ts +3 -0
- package/dist/decorators/index.js +3 -0
- package/dist/decorators/types.d.ts +45 -10
- package/dist/decorators/types.js +4 -0
- package/dist/extension.js +11 -2
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/lib/openapi/collectors/class.collector.d.ts +9 -0
- package/dist/lib/openapi/collectors/class.collector.js +67 -0
- package/dist/lib/openapi/collectors/index.d.ts +4 -0
- package/dist/lib/openapi/collectors/index.js +20 -0
- package/dist/lib/openapi/collectors/method.collector.d.ts +2 -0
- package/dist/lib/openapi/collectors/method.collector.js +68 -0
- package/dist/lib/openapi/collectors/param.collector.d.ts +2 -0
- package/dist/lib/openapi/collectors/param.collector.js +64 -0
- package/dist/lib/openapi/collectors/schema.collector.d.ts +11 -0
- package/dist/lib/openapi/collectors/schema.collector.js +37 -0
- package/dist/lib/openapi/constants.d.ts +46 -0
- package/dist/lib/openapi/constants.js +61 -0
- package/dist/lib/openapi/decorators/api-bearer-auth.decorator.d.ts +2 -0
- package/dist/lib/openapi/decorators/api-bearer-auth.decorator.js +10 -0
- package/dist/lib/openapi/decorators/api-method.decorator.d.ts +3 -0
- package/dist/lib/openapi/decorators/api-method.decorator.js +11 -0
- package/dist/lib/openapi/decorators/api-parameter.decorator.d.ts +3 -0
- package/dist/lib/openapi/decorators/api-parameter.decorator.js +10 -0
- package/dist/lib/openapi/decorators/api-request-body.decorator.d.ts +3 -0
- package/dist/lib/openapi/decorators/api-request-body.decorator.js +10 -0
- package/dist/lib/openapi/decorators/api-response.decorator.d.ts +3 -0
- package/dist/lib/openapi/decorators/api-response.decorator.js +10 -0
- package/dist/lib/openapi/decorators/api-security.decorator.d.ts +3 -0
- package/dist/lib/openapi/decorators/api-security.decorator.js +10 -0
- package/dist/lib/openapi/decorators/api-tag.decorator.d.ts +3 -0
- package/dist/lib/openapi/decorators/api-tag.decorator.js +13 -0
- package/dist/lib/openapi/decorators/index.d.ts +7 -0
- package/dist/lib/openapi/decorators/index.js +23 -0
- package/dist/lib/openapi/helpers/index.d.ts +7 -0
- package/dist/lib/openapi/helpers/index.js +23 -0
- package/dist/lib/openapi/helpers/method.helper.d.ts +3 -0
- package/dist/lib/openapi/helpers/method.helper.js +20 -0
- package/dist/lib/openapi/helpers/openapi.helper.d.ts +7 -0
- package/dist/lib/openapi/helpers/openapi.helper.js +51 -0
- package/dist/lib/openapi/helpers/parameter.helper.d.ts +3 -0
- package/dist/lib/openapi/helpers/parameter.helper.js +16 -0
- package/dist/lib/openapi/helpers/request-body.helper.d.ts +3 -0
- package/dist/lib/openapi/helpers/request-body.helper.js +9 -0
- package/dist/lib/openapi/helpers/response.helper.d.ts +3 -0
- package/dist/lib/openapi/helpers/response.helper.js +18 -0
- package/dist/lib/openapi/helpers/security.helper.d.ts +3 -0
- package/dist/lib/openapi/helpers/security.helper.js +17 -0
- package/dist/lib/openapi/helpers/tag.helper.d.ts +3 -0
- package/dist/lib/openapi/helpers/tag.helper.js +10 -0
- package/dist/lib/openapi/index.d.ts +6 -0
- package/dist/lib/openapi/index.js +22 -0
- package/dist/lib/openapi/metadata.registry.d.ts +29 -0
- package/dist/lib/openapi/metadata.registry.js +41 -0
- package/dist/lib/openapi/types.d.ts +131 -0
- package/dist/stores/index.d.ts +1 -0
- package/dist/{common/openapi → stores}/index.js +1 -2
- package/dist/stores/scope.store.d.ts +14 -0
- package/dist/stores/scope.store.js +29 -0
- package/dist/type.d.ts +13 -2
- package/hyper-express-decorators.d.ts +1 -0
- package/package.json +73 -60
- package/scripts/clean.js +56 -0
- package/scripts/test-server.ts +85 -0
- package/tsconfig.json +18 -13
- package/vitest.config.mjs +30 -0
- package/vitest.json +0 -0
- package/.mocharc.js +0 -5
- package/dist/__internals/store.d.ts +0 -10
- package/dist/__internals/store.js +0 -17
- package/dist/__internals/stores/middleware.store.d.ts +0 -7
- package/dist/__internals/stores/middleware.store.js +0 -19
- package/dist/__internals/stores/params.store.d.ts +0 -21
- package/dist/__internals/stores/params.store.js +0 -65
- package/dist/__internals/stores/routes.store.d.ts +0 -17
- package/dist/__internals/stores/routes.store.js +0 -43
- package/dist/__internals/stores/store.interface.d.ts +0 -8
- package/dist/__internals/transform/method.transform.d.ts +0 -2
- package/dist/__internals/transform/method.transform.js +0 -20
- package/dist/__internals/transform/pass.transfrom.d.ts +0 -1
- package/dist/__internals/utils/mixin.utils.d.ts +0 -11
- package/dist/__internals/utils/mixin.utils.js +0 -34
- package/dist/__internals/utils/router.d.ts +0 -1
- package/dist/__internals/utils/router.js +0 -2
- package/dist/common/openapi/collect-class-data.d.ts +0 -21
- package/dist/common/openapi/collect-class-data.js +0 -45
- package/dist/common/openapi/collect-function-data.d.ts +0 -32
- package/dist/common/openapi/collect-function-data.js +0 -70
- package/dist/common/openapi/index.d.ts +0 -2
- /package/dist/__internals/stores/{index.d.ts → metadata.store.d.ts} +0 -0
- /package/dist/__internals/stores/{index.js → metadata.store.js} +0 -0
- /package/dist/{__internals/stores/store.interface.js → lib/openapi/types.js} +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,21 +0,0 @@
|
|
|
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 {};
|
|
@@ -1,45 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
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 {};
|
|
@@ -1,70 +0,0 @@
|
|
|
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
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|