@zenofolio/hyper-decor 1.0.69 → 1.0.72
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 +136 -254
- package/dist/__internals/constants.d.ts +2 -2
- package/dist/__internals/constants.js +2 -2
- package/dist/__internals/creators/request.creator.d.ts +1 -10
- package/dist/__internals/creators/request.creator.js +141 -21
- package/dist/__internals/decorator-base.js +1 -1
- package/dist/__internals/helpers/prepare.helper.js +71 -51
- package/dist/decorators/File.d.ts +4 -32
- package/dist/decorators/File.js +62 -75
- package/dist/decorators/Http.d.ts +9 -42
- package/dist/decorators/Http.js +24 -72
- package/dist/decorators/Output.d.ts +9 -0
- package/dist/decorators/Output.js +18 -0
- package/dist/decorators/index.d.ts +1 -1
- package/dist/decorators/index.js +1 -1
- package/dist/decorators/types.d.ts +2 -0
- package/dist/exeptions/HyperException.d.ts +2 -1
- package/dist/exeptions/HyperException.js +2 -1
- package/dist/exeptions/HyperFileException.js +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/lib/openapi/collectors/method.collector.js +25 -12
- package/dist/lib/openapi/collectors/param.collector.d.ts +2 -3
- package/dist/lib/openapi/collectors/param.collector.js +49 -12
- package/dist/lib/openapi/decorators/api-parameter.decorator.d.ts +2 -2
- package/dist/lib/openapi/decorators/api-response.decorator.d.ts +2 -2
- package/dist/lib/openapi/decorators/api-tag.decorator.d.ts +1 -1
- package/dist/lib/openapi/decorators/api-tag.decorator.js +3 -0
- package/dist/lib/openapi/helpers/parameter.helper.d.ts +2 -2
- package/dist/lib/openapi/helpers/response.helper.d.ts +2 -2
- package/dist/lib/openapi/types.d.ts +8 -8
- package/package.json +3 -2
|
@@ -74,6 +74,8 @@ export type HyperParameterMetadata = {
|
|
|
74
74
|
name: string;
|
|
75
75
|
method: string;
|
|
76
76
|
resolver: ParameterResolver;
|
|
77
|
+
schema?: any;
|
|
78
|
+
isWholeSource?: boolean;
|
|
77
79
|
}[]>;
|
|
78
80
|
};
|
|
79
81
|
export type HyperParamDecorator = (key: string) => (target: any, key: string, index: number) => void;
|
|
@@ -2,6 +2,7 @@ import { ExceptionType } from "./types";
|
|
|
2
2
|
export default class HyperException extends Error {
|
|
3
3
|
code: ExceptionType;
|
|
4
4
|
additionalInfo: any;
|
|
5
|
-
|
|
5
|
+
status: number;
|
|
6
|
+
constructor(message: string, code?: ExceptionType, additionalInfo?: any, status?: number);
|
|
6
7
|
static throw(message: string, code?: ExceptionType, additionalInfo?: {}): void;
|
|
7
8
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
class HyperException extends Error {
|
|
4
|
-
constructor(message, code = "HyperException", additionalInfo = {}) {
|
|
4
|
+
constructor(message, code = "HyperException", additionalInfo = {}, status = 500) {
|
|
5
5
|
super(message);
|
|
6
6
|
this.code = code;
|
|
7
7
|
this.additionalInfo = additionalInfo;
|
|
8
|
+
this.status = status;
|
|
8
9
|
}
|
|
9
10
|
static throw(message, code, additionalInfo = {}) {
|
|
10
11
|
throw new this(message, code, additionalInfo);
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const HyperException_1 = __importDefault(require("./HyperException"));
|
|
7
7
|
class HyperFileException extends HyperException_1.default {
|
|
8
8
|
constructor(message, additional) {
|
|
9
|
-
super(message, "HyperFileException", additional);
|
|
9
|
+
super(message, "HyperFileException", additional, 400);
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
exports.default = HyperFileException;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -27,3 +27,5 @@ __exportStar(require("./stores"), exports);
|
|
|
27
27
|
__exportStar(require("./type"), exports);
|
|
28
28
|
__exportStar(require("./common/transport"), exports);
|
|
29
29
|
__exportStar(require("./common/message-bus"), exports);
|
|
30
|
+
__exportStar(require("./__internals/transform/transform.registry"), exports);
|
|
31
|
+
__exportStar(require("./lib/openapi"), exports);
|
|
@@ -4,7 +4,6 @@ exports.collectMethodMetadata = collectMethodMetadata;
|
|
|
4
4
|
const constants_1 = require("../constants");
|
|
5
5
|
const param_collector_1 = require("./param.collector");
|
|
6
6
|
const constants_2 = require("../../../__internals/constants");
|
|
7
|
-
const decorator_base_1 = require("../../../__internals/decorator-base");
|
|
8
7
|
const transform_registry_1 = require("../../../__internals/transform/transform.registry");
|
|
9
8
|
function collectMethodMetadata(target, methodName) {
|
|
10
9
|
const methodMetadata = {};
|
|
@@ -22,20 +21,34 @@ function collectMethodMetadata(target, methodName) {
|
|
|
22
21
|
description: Reflect.getMetadata(constants_1.REQUEST_BODY_DESCRIPTION, target, methodName),
|
|
23
22
|
content: Reflect.getMetadata(constants_1.REQUEST_BODY_CONTENT, target, methodName),
|
|
24
23
|
};
|
|
25
|
-
//
|
|
26
|
-
const
|
|
27
|
-
if (
|
|
28
|
-
const
|
|
29
|
-
if (
|
|
30
|
-
const
|
|
31
|
-
if (
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
24
|
+
// Bridge @Body to OpenAPI
|
|
25
|
+
const hyperParams = Reflect.getMetadata(constants_2.KEY_PARAMS_PARAM, target[methodName]);
|
|
26
|
+
if (hyperParams && hyperParams.params[methodName]) {
|
|
27
|
+
const bodyParam = hyperParams.params[methodName].find(p => ['body', 'BODY', 'req'].includes(p.key));
|
|
28
|
+
if (bodyParam) {
|
|
29
|
+
const targetSchema = bodyParam.schema;
|
|
30
|
+
if (targetSchema) {
|
|
31
|
+
const bodySchema = transform_registry_1.transformRegistry.getOpenApiSchema(targetSchema);
|
|
32
|
+
if (bodySchema) {
|
|
33
|
+
requestBody.content = requestBody.content || {};
|
|
34
|
+
requestBody.content['application/json'] = {
|
|
35
|
+
schema: bodySchema
|
|
36
|
+
};
|
|
37
|
+
}
|
|
36
38
|
}
|
|
37
39
|
}
|
|
38
40
|
}
|
|
41
|
+
// Bridging @Output / return type to OpenAPI
|
|
42
|
+
const outputSchema = Reflect.getMetadata(constants_2.KEY_OUTPUT_SCHEMA, target, methodName)
|
|
43
|
+
|| Reflect.getMetadata(constants_2.DESIGN_RETURNTYPE, target, methodName);
|
|
44
|
+
if (outputSchema && outputSchema !== Object && outputSchema !== Promise) {
|
|
45
|
+
const schema = transform_registry_1.transformRegistry.getOpenApiSchema(outputSchema);
|
|
46
|
+
if (schema) {
|
|
47
|
+
responses['200'] = responses['200'] || { description: 'Success' };
|
|
48
|
+
responses['200'].content = responses['200'].content || {};
|
|
49
|
+
responses['200'].content['application/json'] = { schema };
|
|
50
|
+
}
|
|
51
|
+
}
|
|
39
52
|
// Asignamos las propiedades al objeto de metadata solo si existen
|
|
40
53
|
if (summary)
|
|
41
54
|
methodMetadata.summary = summary;
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import "
|
|
2
|
-
|
|
3
|
-
export declare function collectParameterMetadata(target: any, methodName: string): Parameter[];
|
|
1
|
+
import { OpenApiParameter } from "../types";
|
|
2
|
+
export declare function collectParameterMetadata(target: any, methodName: string): OpenApiParameter[];
|
|
@@ -1,26 +1,63 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.collectParameterMetadata = collectParameterMetadata;
|
|
4
|
-
require("reflect-metadata");
|
|
5
4
|
const constants_1 = require("../constants");
|
|
5
|
+
const constants_2 = require("../../../__internals/constants");
|
|
6
|
+
const transform_registry_1 = require("../../../__internals/transform/transform.registry");
|
|
6
7
|
const function_util_1 = require("../../../__internals/utils/function.util");
|
|
7
8
|
function collectParameterMetadata(target, methodName) {
|
|
8
9
|
const parameters = Reflect.getMetadata(constants_1.PARAMETERS, target, methodName) || [];
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
const hyperParams = Reflect.getMetadata(constants_2.KEY_PARAMS_PARAM, target[methodName]);
|
|
11
|
+
if (hyperParams && hyperParams.params[methodName]) {
|
|
12
|
+
hyperParams.params[methodName].forEach((p) => {
|
|
13
|
+
// Ignore body, req, res as they are not standard "parameters" in OpenAPI terms (body is separate)
|
|
14
|
+
if (['req', 'res', 'body', 'BODY'].includes(p.key))
|
|
15
|
+
return;
|
|
16
|
+
const locationMap = {
|
|
17
|
+
'query': 'query',
|
|
18
|
+
'params': 'path',
|
|
19
|
+
'headers': 'header',
|
|
20
|
+
'cookie': 'cookie'
|
|
21
|
+
};
|
|
22
|
+
const location = locationMap[p.key] || 'query';
|
|
23
|
+
if (p.isWholeSource && p.schema) {
|
|
24
|
+
const schema = transform_registry_1.transformRegistry.getOpenApiSchema(p.schema);
|
|
25
|
+
if (schema && schema.properties) {
|
|
26
|
+
Object.keys(schema.properties).forEach((propKey) => {
|
|
27
|
+
parameters.push({
|
|
28
|
+
name: propKey,
|
|
29
|
+
in: location,
|
|
30
|
+
required: (schema.required || []).includes(propKey),
|
|
31
|
+
schema: schema.properties[propKey]
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
parameters.push({
|
|
38
|
+
name: p.name,
|
|
39
|
+
in: location,
|
|
40
|
+
required: true, // TODO: detect optionality from design:paramtypes or metadata
|
|
41
|
+
schema: p.schema ? transform_registry_1.transformRegistry.getOpenApiSchema(p.schema) : { type: 'string' }
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
// Fallback to design:paramtypes if no hyper-decor metadata found
|
|
47
|
+
if (parameters.length === 0) {
|
|
48
|
+
const methodParams = Reflect.getMetadata("design:paramtypes", target, methodName) || [];
|
|
49
|
+
const paramNames = (0, function_util_1.extractArgsNames)(target[methodName]);
|
|
14
50
|
methodParams.forEach((paramType, index) => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
51
|
+
var _a;
|
|
52
|
+
const name = paramNames && paramNames[index] ? paramNames[index] : `param${index}`;
|
|
53
|
+
parameters.push({
|
|
54
|
+
name,
|
|
55
|
+
in: "query",
|
|
18
56
|
required: true,
|
|
19
57
|
schema: {
|
|
20
|
-
type: paramType.name.toLowerCase()
|
|
58
|
+
type: ((_a = paramType === null || paramType === void 0 ? void 0 : paramType.name) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === 'number' ? 'number' : 'string',
|
|
21
59
|
},
|
|
22
|
-
};
|
|
23
|
-
parameters.push(param);
|
|
60
|
+
});
|
|
24
61
|
});
|
|
25
62
|
}
|
|
26
63
|
return parameters;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
|
-
import {
|
|
3
|
-
export declare function ApiParameter(options:
|
|
2
|
+
import { OpenApiParameter } from '../types';
|
|
3
|
+
export declare function ApiParameter(options: OpenApiParameter): (target: any, propertyKey: any) => void;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
|
-
import {
|
|
3
|
-
export declare function ApiResponse(options:
|
|
2
|
+
import { OpenApiResponses } from "../types";
|
|
3
|
+
export declare function ApiResponse(options: OpenApiResponses): (target: any, propertyKey?: any, descriptor?: any) => any;
|
|
@@ -5,6 +5,9 @@ require("reflect-metadata");
|
|
|
5
5
|
const tag_helper_1 = require("../helpers/tag.helper");
|
|
6
6
|
function ApiTag(options) {
|
|
7
7
|
return (target) => {
|
|
8
|
+
if (typeof options === 'string') {
|
|
9
|
+
options = { name: options };
|
|
10
|
+
}
|
|
8
11
|
(0, tag_helper_1.apiTag)(target, options);
|
|
9
12
|
};
|
|
10
13
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
|
-
import {
|
|
3
|
-
export declare function apiParameter(target: any, propertyKey: string, options:
|
|
2
|
+
import { OpenApiParameter } from '../types';
|
|
3
|
+
export declare function apiParameter(target: any, propertyKey: string, options: OpenApiParameter): void;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
|
-
import {
|
|
3
|
-
export declare function apiResponse(target: any, propertyKey: string | symbol, options:
|
|
2
|
+
import { OpenApiResponses } from "../types";
|
|
3
|
+
export declare function apiResponse(target: any, propertyKey: string | symbol, options: OpenApiResponses): void;
|
|
@@ -41,12 +41,12 @@ export interface Operation {
|
|
|
41
41
|
description?: string;
|
|
42
42
|
operationId?: string;
|
|
43
43
|
tags?: Tag[];
|
|
44
|
-
parameters?:
|
|
44
|
+
parameters?: OpenApiParameter[];
|
|
45
45
|
requestBody?: RequestBody;
|
|
46
|
-
responses:
|
|
46
|
+
responses: OpenApiResponses;
|
|
47
47
|
security?: SecurityRequirement[];
|
|
48
48
|
}
|
|
49
|
-
export interface
|
|
49
|
+
export interface OpenApiParameter {
|
|
50
50
|
name: string;
|
|
51
51
|
in: "query" | "header" | "path" | "cookie";
|
|
52
52
|
description?: string;
|
|
@@ -64,10 +64,10 @@ export interface RequestBody {
|
|
|
64
64
|
export interface MediaType {
|
|
65
65
|
schema: Schema;
|
|
66
66
|
}
|
|
67
|
-
export interface
|
|
68
|
-
[statusCode: string]:
|
|
67
|
+
export interface OpenApiResponses {
|
|
68
|
+
[statusCode: string]: OpenApiResponse;
|
|
69
69
|
}
|
|
70
|
-
export interface
|
|
70
|
+
export interface OpenApiResponse {
|
|
71
71
|
description: string;
|
|
72
72
|
content?: {
|
|
73
73
|
[mediaType: string]: MediaType;
|
|
@@ -103,10 +103,10 @@ export interface Components {
|
|
|
103
103
|
[schemaName: string]: Schema;
|
|
104
104
|
};
|
|
105
105
|
responses?: {
|
|
106
|
-
[responseName: string]:
|
|
106
|
+
[responseName: string]: OpenApiResponse;
|
|
107
107
|
};
|
|
108
108
|
parameters?: {
|
|
109
|
-
[parameterName: string]:
|
|
109
|
+
[parameterName: string]: OpenApiParameter;
|
|
110
110
|
};
|
|
111
111
|
securitySchemes?: {
|
|
112
112
|
[schemeName: string]: SecurityScheme;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zenofolio/hyper-decor",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.72",
|
|
4
4
|
"description": "Project core with utilities and features",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"author": "zenozaga",
|
|
@@ -21,14 +21,15 @@
|
|
|
21
21
|
"@vitest/ui": "^4.0.18",
|
|
22
22
|
"nodemon": "3.1.7",
|
|
23
23
|
"typescript": "5.6.2",
|
|
24
|
+
"undici": "^7.24.0",
|
|
24
25
|
"unplugin-swc": "^1.5.9",
|
|
25
26
|
"vitest": "^4.0.18"
|
|
26
27
|
},
|
|
27
28
|
"dependencies": {
|
|
28
29
|
"core-decorators": "^0.20.0",
|
|
29
|
-
"reflect-metadata": "^0.2.2",
|
|
30
30
|
"eventemitter3": "^5.0.4",
|
|
31
31
|
"file-type": "^19.5.0",
|
|
32
|
+
"reflect-metadata": "^0.2.2",
|
|
32
33
|
"ts-type": "^3.0.8",
|
|
33
34
|
"tsyringe": "^4.8.0"
|
|
34
35
|
},
|