@zenofolio/hyper-decor 0.0.3 → 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
|
@@ -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,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,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,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,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,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,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,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,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,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,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,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,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,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("./
|
|
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
|
}
|