@zenofolio/hyper-decor 1.0.75 → 1.0.81
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 +42 -0
- package/dist/__internals/helpers/prepare.helper.js +15 -6
- package/dist/common/testing.d.ts +56 -0
- package/dist/common/testing.js +193 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/lib/server/decorators/HyperService.d.ts +2 -1
- package/dist/lib/server/decorators/types.d.ts +1 -1
- package/package.json +5 -1
- package/dist/__internals/creators/request.creator.d.ts +0 -2
- package/dist/__internals/creators/request.creator.js +0 -173
- package/dist/__internals/creators/routes.creator.d.ts +0 -9
- package/dist/__internals/creators/routes.creator.js +0 -39
- package/dist/__internals/decorator-base.d.ts +0 -30
- package/dist/__internals/decorator-base.js +0 -122
- package/dist/__internals/helpers/imports.helper.d.ts +0 -8
- package/dist/__internals/helpers/imports.helper.js +0 -92
- package/dist/__internals/helpers/tree.helper.d.ts +0 -36
- package/dist/__internals/helpers/tree.helper.js +0 -81
- package/dist/__internals/stores/metadata.store.d.ts +0 -15
- package/dist/__internals/stores/metadata.store.js +0 -37
- package/dist/__internals/stores/service.store.d.ts +0 -1
- package/dist/__internals/stores/service.store.js +0 -4
- package/dist/decorators/File.d.ts +0 -37
- package/dist/decorators/File.js +0 -167
- package/dist/decorators/Http.d.ts +0 -22
- package/dist/decorators/Http.js +0 -45
- package/dist/decorators/HyperApp.d.ts +0 -3
- package/dist/decorators/HyperApp.js +0 -96
- package/dist/decorators/HyperController.d.ts +0 -2
- package/dist/decorators/HyperController.js +0 -20
- package/dist/decorators/HyperModule.d.ts +0 -5
- package/dist/decorators/HyperModule.js +0 -14
- package/dist/decorators/HyperService.d.ts +0 -15
- package/dist/decorators/HyperService.js +0 -29
- package/dist/decorators/Messaging.d.ts +0 -10
- package/dist/decorators/Messaging.js +0 -22
- package/dist/decorators/Middleware.d.ts +0 -25
- package/dist/decorators/Middleware.js +0 -65
- package/dist/decorators/Output.d.ts +0 -9
- package/dist/decorators/Output.js +0 -18
- package/dist/decorators/Pass.d.ts +0 -15
- package/dist/decorators/Pass.js +0 -32
- package/dist/decorators/Role.d.ts +0 -6
- package/dist/decorators/Role.js +0 -34
- package/dist/decorators/Routes.d.ts +0 -15
- package/dist/decorators/Routes.js +0 -21
- package/dist/decorators/Scope.d.ts +0 -6
- package/dist/decorators/Scope.js +0 -25
- package/dist/decorators/Transform.d.ts +0 -14
- package/dist/decorators/Transform.js +0 -18
- package/dist/decorators/index.d.ts +0 -14
- package/dist/decorators/index.js +0 -30
- package/dist/decorators/types.d.ts +0 -124
- package/dist/decorators/types.js +0 -6
- package/dist/exeptions/DuplicateControllerPathException.d.ts +0 -14
- package/dist/exeptions/DuplicateControllerPathException.js +0 -12
- package/dist/exeptions/DuplicatedException.d.ts +0 -8
- package/dist/exeptions/DuplicatedException.js +0 -12
- package/dist/exeptions/DuplicatedHandlerException.d.ts +0 -4
- package/dist/exeptions/DuplicatedHandlerException.js +0 -12
- package/dist/exeptions/HyperException.d.ts +0 -8
- package/dist/exeptions/HyperException.js +0 -14
- package/dist/exeptions/HyperFileException.d.ts +0 -4
- package/dist/exeptions/HyperFileException.js +0 -12
- package/dist/exeptions/MethodNotFountException.d.ts +0 -4
- package/dist/exeptions/MethodNotFountException.js +0 -12
- package/dist/exeptions/NotPropertyException.d.ts +0 -6
- package/dist/exeptions/NotPropertyException.js +0 -16
- package/dist/exeptions/NotRoleException.d.ts +0 -6
- package/dist/exeptions/NotRoleException.js +0 -17
- package/dist/exeptions/NotScopeException.d.ts +0 -7
- package/dist/exeptions/NotScopeException.js +0 -18
- package/dist/exeptions/WrongPlaceException.d.ts +0 -8
- package/dist/exeptions/WrongPlaceException.js +0 -21
- package/dist/exeptions/index.d.ts +0 -8
- package/dist/exeptions/index.js +0 -18
- package/dist/exeptions/types.d.ts +0 -1
- package/dist/exeptions/types.js +0 -2
- package/dist/lib/openapi/collectors/param.collector.d.ts +0 -2
- package/dist/lib/openapi/collectors/param.collector.js +0 -64
- package/dist/lib/openapi/decorators/api-bearer-auth.decorator.d.ts +0 -2
- package/dist/lib/openapi/decorators/api-bearer-auth.decorator.js +0 -10
- package/dist/lib/openapi/decorators/api-method.decorator.d.ts +0 -3
- package/dist/lib/openapi/decorators/api-method.decorator.js +0 -11
- package/dist/lib/openapi/decorators/api-parameter.decorator.d.ts +0 -3
- package/dist/lib/openapi/decorators/api-parameter.decorator.js +0 -10
- package/dist/lib/openapi/decorators/api-request-body.decorator.d.ts +0 -3
- package/dist/lib/openapi/decorators/api-request-body.decorator.js +0 -10
- package/dist/lib/openapi/decorators/api-response.decorator.d.ts +0 -3
- package/dist/lib/openapi/decorators/api-response.decorator.js +0 -10
- package/dist/lib/openapi/decorators/api-security.decorator.d.ts +0 -3
- package/dist/lib/openapi/decorators/api-security.decorator.js +0 -10
- package/dist/lib/openapi/decorators/api-tag.decorator.d.ts +0 -3
- package/dist/lib/openapi/decorators/api-tag.decorator.js +0 -13
- package/dist/lib/openapi/decorators/index.d.ts +0 -7
- package/dist/lib/openapi/decorators/index.js +0 -23
- package/dist/lib/openapi/helpers/index.d.ts +0 -7
- package/dist/lib/openapi/helpers/index.js +0 -23
- package/dist/lib/openapi/helpers/method.helper.d.ts +0 -3
- package/dist/lib/openapi/helpers/method.helper.js +0 -20
- package/dist/lib/openapi/helpers/openapi.helper.d.ts +0 -7
- package/dist/lib/openapi/helpers/openapi.helper.js +0 -51
- package/dist/lib/openapi/helpers/parameter.helper.d.ts +0 -3
- package/dist/lib/openapi/helpers/parameter.helper.js +0 -16
- package/dist/lib/openapi/helpers/request-body.helper.d.ts +0 -3
- package/dist/lib/openapi/helpers/request-body.helper.js +0 -9
- package/dist/lib/openapi/helpers/response.helper.d.ts +0 -3
- package/dist/lib/openapi/helpers/response.helper.js +0 -18
- package/dist/lib/openapi/helpers/security.helper.d.ts +0 -3
- package/dist/lib/openapi/helpers/security.helper.js +0 -17
- package/dist/lib/openapi/helpers/tag.helper.d.ts +0 -3
- package/dist/lib/openapi/helpers/tag.helper.js +0 -10
- package/dist/stores/index.d.ts +0 -1
- package/dist/stores/index.js +0 -17
- package/dist/stores/scope.store.d.ts +0 -14
- package/dist/stores/scope.store.js +0 -29
package/dist/decorators/Http.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createCustomRequestDecorator = exports.Res = exports.Req = void 0;
|
|
7
|
-
exports.Query = Query;
|
|
8
|
-
exports.Body = Body;
|
|
9
|
-
exports.Param = Param;
|
|
10
|
-
exports.Headers = Headers;
|
|
11
|
-
const request_creator_1 = __importDefault(require("../__internals/creators/request.creator"));
|
|
12
|
-
/**
|
|
13
|
-
* Get the value of a key from the request object
|
|
14
|
-
*
|
|
15
|
-
* @param key
|
|
16
|
-
* @returns
|
|
17
|
-
*/
|
|
18
|
-
/**
|
|
19
|
-
* Get the value of a key from the request object or transform the entire query.
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* \@Query('id')
|
|
23
|
-
* \@Query('id', IntSchema)
|
|
24
|
-
* \@Query(UserQueryDto)
|
|
25
|
-
*/
|
|
26
|
-
function Query(keyOrSchema, schemaOrTransform) {
|
|
27
|
-
return (0, request_creator_1.default)("query", "Query", keyOrSchema, schemaOrTransform);
|
|
28
|
-
}
|
|
29
|
-
function Body(keyOrSchema, schemaOrTransform) {
|
|
30
|
-
return (0, request_creator_1.default)("body", "Body", keyOrSchema, schemaOrTransform, true);
|
|
31
|
-
}
|
|
32
|
-
function Param(keyOrSchema, schemaOrTransform) {
|
|
33
|
-
return (0, request_creator_1.default)("params", "Param", keyOrSchema, schemaOrTransform);
|
|
34
|
-
}
|
|
35
|
-
function Headers(keyOrSchema, schemaOrTransform) {
|
|
36
|
-
return (0, request_creator_1.default)("headers", "Headers", keyOrSchema, schemaOrTransform);
|
|
37
|
-
}
|
|
38
|
-
const Req = () => (0, request_creator_1.default)("req", "Req");
|
|
39
|
-
exports.Req = Req;
|
|
40
|
-
const Res = () => (0, request_creator_1.default)("res", "Res");
|
|
41
|
-
exports.Res = Res;
|
|
42
|
-
const createCustomRequestDecorator = (decoratorName, resolver) => {
|
|
43
|
-
return (0, request_creator_1.default)("req", decoratorName, resolver);
|
|
44
|
-
};
|
|
45
|
-
exports.createCustomRequestDecorator = createCustomRequestDecorator;
|
|
@@ -1,96 +0,0 @@
|
|
|
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.HyperApp = void 0;
|
|
13
|
-
require("reflect-metadata");
|
|
14
|
-
const hyper_express_1 = require("hyper-express");
|
|
15
|
-
const tsyringe_1 = require("tsyringe");
|
|
16
|
-
const constants_1 = require("../__internals/constants");
|
|
17
|
-
const decorator_base_1 = require("../__internals/decorator-base");
|
|
18
|
-
const merge_metadata_1 = require("../__internals/helpers/merge-metadata");
|
|
19
|
-
const transform_registry_1 = require("../__internals/transform/transform.registry");
|
|
20
|
-
const prepare_helper_1 = require("../__internals/helpers/prepare.helper");
|
|
21
|
-
const HyperApp = (options) => (0, decorator_base_1.DecoratorHelper)({
|
|
22
|
-
type: constants_1.KEY_TYPE_APP,
|
|
23
|
-
key: constants_1.KEY_PARAMS_APP,
|
|
24
|
-
options: Object.assign({ modules: [], logger: console.log }, options),
|
|
25
|
-
}, (options, Target) => {
|
|
26
|
-
return class extends hyper_express_1.Server {
|
|
27
|
-
constructor(...args) {
|
|
28
|
-
super(options.options);
|
|
29
|
-
this.listArguments = [];
|
|
30
|
-
this.storeLogs = {};
|
|
31
|
-
this.listArguments = args;
|
|
32
|
-
}
|
|
33
|
-
/** Registers an agnostic transformer (Zod, Joi, etc.) */
|
|
34
|
-
useTransform(transformer) {
|
|
35
|
-
transform_registry_1.transformRegistry.register(transformer);
|
|
36
|
-
return this;
|
|
37
|
-
}
|
|
38
|
-
prepare() {
|
|
39
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
-
tsyringe_1.container.registerInstance(hyper_express_1.Server, this);
|
|
41
|
-
this.mergeMetadata(Target);
|
|
42
|
-
yield this.applyOptions(Target);
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
/** Fusiona los metadatos relevantes al Target */
|
|
46
|
-
mergeMetadata(targetPrototype) {
|
|
47
|
-
(0, merge_metadata_1.mergeMetadata)(targetPrototype, this.constructor, [
|
|
48
|
-
constants_1.KEY_PARAMS_MIDDLEWARES,
|
|
49
|
-
constants_1.KEY_PARAMS_SCOPE,
|
|
50
|
-
constants_1.KEY_PARAMS_ROLE,
|
|
51
|
-
constants_1.KEY_PARAMS_PASS,
|
|
52
|
-
]);
|
|
53
|
-
}
|
|
54
|
-
/** Aplica las opciones y prepara la instancia del Target */
|
|
55
|
-
applyOptions(Target) {
|
|
56
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
-
yield (0, prepare_helper_1.prepareApplication)(options, Target, this, this.log.bind(this));
|
|
58
|
-
const target = Reflect.construct(Target, this.listArguments);
|
|
59
|
-
if (target && typeof target === 'object' && 'onPrepare' in target) {
|
|
60
|
-
target.onPrepare();
|
|
61
|
-
}
|
|
62
|
-
this.showLogs();
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
/** Maneja los logs respetando las opciones configuradas */
|
|
66
|
-
log(space, message) {
|
|
67
|
-
var _a;
|
|
68
|
-
var _b;
|
|
69
|
-
if (((_a = options.logs) === null || _a === void 0 ? void 0 : _a[space]) === false)
|
|
70
|
-
return;
|
|
71
|
-
((_b = this.storeLogs)[space] || (_b[space] = [])).push(`- ${message}`);
|
|
72
|
-
}
|
|
73
|
-
showLogs() {
|
|
74
|
-
var _a, _b, _c;
|
|
75
|
-
const content = ["\n\n"];
|
|
76
|
-
content.push("/////////////////////////////");
|
|
77
|
-
content.push(`- HyperExpress Application`);
|
|
78
|
-
content.push(`- ${(_a = options.name) !== null && _a !== void 0 ? _a : "Hyper App"} - ${(_b = options.version) !== null && _b !== void 0 ? _b : "1.0.0"}`);
|
|
79
|
-
content.push("/////////////////////////////\n");
|
|
80
|
-
content.push("\nLogs:");
|
|
81
|
-
Object.entries(this.storeLogs).forEach(([space, logs]) => {
|
|
82
|
-
if (!logs.length)
|
|
83
|
-
return;
|
|
84
|
-
content.push(`- [${space.toUpperCase()}]`);
|
|
85
|
-
logs.forEach((log) => content.push(` ${log}`));
|
|
86
|
-
content.push("");
|
|
87
|
-
});
|
|
88
|
-
(_c = options.logger) === null || _c === void 0 ? void 0 : _c.call(this, content.join("\n"));
|
|
89
|
-
this.storeLogs = {};
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
});
|
|
93
|
-
exports.HyperApp = HyperApp;
|
|
94
|
-
//////////////////////////////////
|
|
95
|
-
/// Private methods
|
|
96
|
-
//////////////////////////////////
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HyperController = void 0;
|
|
4
|
-
const decorator_base_1 = require("../__internals/decorator-base");
|
|
5
|
-
const constants_1 = require("../__internals/constants");
|
|
6
|
-
const HyperController = (options) => {
|
|
7
|
-
var _a, _b, _c, _d;
|
|
8
|
-
const isString = typeof options === "string";
|
|
9
|
-
return (0, decorator_base_1.DecoratorHelper)({
|
|
10
|
-
type: constants_1.KEY_TYPE_CONTROLLER,
|
|
11
|
-
key: constants_1.KEY_PARAMS_CONTROLLER,
|
|
12
|
-
options: {
|
|
13
|
-
path: isString ? options : (_a = options === null || options === void 0 ? void 0 : options.path) !== null && _a !== void 0 ? _a : "/",
|
|
14
|
-
roles: isString ? [] : (_b = options === null || options === void 0 ? void 0 : options.roles) !== null && _b !== void 0 ? _b : [],
|
|
15
|
-
scopes: isString ? [] : (_c = options === null || options === void 0 ? void 0 : options.scopes) !== null && _c !== void 0 ? _c : [],
|
|
16
|
-
imports: isString ? [] : (_d = options === null || options === void 0 ? void 0 : options.imports) !== null && _d !== void 0 ? _d : [],
|
|
17
|
-
},
|
|
18
|
-
});
|
|
19
|
-
};
|
|
20
|
-
exports.HyperController = HyperController;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HyperModule = void 0;
|
|
4
|
-
const constants_1 = require("../__internals/constants");
|
|
5
|
-
const decorator_base_1 = require("../__internals/decorator-base");
|
|
6
|
-
/**
|
|
7
|
-
* Decorator to define a module with controllers and services.
|
|
8
|
-
*/
|
|
9
|
-
const HyperModule = (options) => (0, decorator_base_1.DecoratorHelper)({
|
|
10
|
-
type: constants_1.KEY_PARAMS_MODULE,
|
|
11
|
-
key: constants_1.KEY_PARAMS_MODULE,
|
|
12
|
-
options,
|
|
13
|
-
});
|
|
14
|
-
exports.HyperModule = HyperModule;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Constructor } from "./types";
|
|
2
|
-
interface ServiceDecoratorOptions {
|
|
3
|
-
singleton?: boolean;
|
|
4
|
-
token?: string | symbol;
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* HyperService decorator is used to register a class as a service in the tsyringe container.
|
|
8
|
-
*
|
|
9
|
-
* No matter where this decorator is applied, the class will be registered in the tsyringe container
|
|
10
|
-
* and included in the service store to be launched when the application starts.
|
|
11
|
-
*
|
|
12
|
-
* @param options.singleton - Whether to register as a singleton (default: true)
|
|
13
|
-
*/
|
|
14
|
-
export declare const HyperService: ({ token, singleton, }?: ServiceDecoratorOptions) => (target: Constructor) => void;
|
|
15
|
-
export {};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HyperService = void 0;
|
|
4
|
-
const tsyringe_1 = require("tsyringe");
|
|
5
|
-
const service_store_1 = require("../__internals/stores/service.store");
|
|
6
|
-
/**
|
|
7
|
-
* HyperService decorator is used to register a class as a service in the tsyringe container.
|
|
8
|
-
*
|
|
9
|
-
* No matter where this decorator is applied, the class will be registered in the tsyringe container
|
|
10
|
-
* and included in the service store to be launched when the application starts.
|
|
11
|
-
*
|
|
12
|
-
* @param options.singleton - Whether to register as a singleton (default: true)
|
|
13
|
-
*/
|
|
14
|
-
const HyperService = ({ token, singleton = true, } = {}) => {
|
|
15
|
-
return (target) => {
|
|
16
|
-
const useToken = token !== null && token !== void 0 ? token : target;
|
|
17
|
-
(0, tsyringe_1.injectable)()(target);
|
|
18
|
-
if (!tsyringe_1.container.isRegistered(useToken)) {
|
|
19
|
-
if (singleton) {
|
|
20
|
-
tsyringe_1.container.registerSingleton(useToken, target);
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
tsyringe_1.container.register(useToken, { useClass: target });
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
service_store_1.serviceStore.add(target);
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
exports.HyperService = HyperService;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export interface OnMessageMetadata {
|
|
2
|
-
topic: string;
|
|
3
|
-
propertyKey: string;
|
|
4
|
-
}
|
|
5
|
-
/**
|
|
6
|
-
* OnMessage decorator for subscribing to topics.
|
|
7
|
-
*
|
|
8
|
-
* @param topic The topic or pattern to listen to (e.g. "user.created", "user.*")
|
|
9
|
-
*/
|
|
10
|
-
export declare const OnMessage: (topic: string) => (target: any, propertyKey: string | symbol | any, descriptor?: any) => void;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OnMessage = void 0;
|
|
4
|
-
const constants_1 = require("../__internals/constants");
|
|
5
|
-
const decorator_base_1 = require("../__internals/decorator-base");
|
|
6
|
-
/**
|
|
7
|
-
* OnMessage decorator for subscribing to topics.
|
|
8
|
-
*
|
|
9
|
-
* @param topic The topic or pattern to listen to (e.g. "user.created", "user.*")
|
|
10
|
-
*/
|
|
11
|
-
const OnMessage = (topic) => {
|
|
12
|
-
return (target, propertyKey, descriptor) => {
|
|
13
|
-
var _a;
|
|
14
|
-
const existing = (_a = Reflect.getMetadata(constants_1.METADATA_KEYS.ON_MESSAGE, target.constructor)) !== null && _a !== void 0 ? _a : [];
|
|
15
|
-
existing.push({
|
|
16
|
-
topic,
|
|
17
|
-
propertyKey: propertyKey.toString(),
|
|
18
|
-
});
|
|
19
|
-
(0, decorator_base_1.defineDecorData)(constants_1.METADATA_KEYS.ON_MESSAGE, existing, target.constructor);
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
exports.OnMessage = OnMessage;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import "reflect-metadata";
|
|
2
|
-
import { MiddlewareHandler } from "hyper-express";
|
|
3
|
-
import { MiddlewareType } from "./types";
|
|
4
|
-
/**
|
|
5
|
-
* Middleware decorator to attach middleware to controllers, modules, and routes.
|
|
6
|
-
*/
|
|
7
|
-
export declare const Middleware: {
|
|
8
|
-
(...middleware: MiddlewareType[]): ClassDecorator & MethodDecorator;
|
|
9
|
-
/**
|
|
10
|
-
* Exclude middleware from matching paths.
|
|
11
|
-
*
|
|
12
|
-
* @param expressions
|
|
13
|
-
* @param middleware
|
|
14
|
-
* @returns
|
|
15
|
-
*/
|
|
16
|
-
exclude(expressions: RegExp | RegExp[], middleware: MiddlewareHandler): ClassDecorator & MethodDecorator;
|
|
17
|
-
/**
|
|
18
|
-
* Only run middleware on matching paths.
|
|
19
|
-
*
|
|
20
|
-
* @param expresiosn
|
|
21
|
-
* @param middleware
|
|
22
|
-
* @returns
|
|
23
|
-
*/
|
|
24
|
-
only(expressions: RegExp | RegExp[], middleware: MiddlewareHandler): (Target: any, propertyKey?: any) => void;
|
|
25
|
-
};
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Middleware = void 0;
|
|
7
|
-
require("reflect-metadata");
|
|
8
|
-
const constants_1 = require("../__internals/constants");
|
|
9
|
-
const metadata_store_1 = __importDefault(require("../__internals/stores/metadata.store"));
|
|
10
|
-
/**
|
|
11
|
-
* Middleware decorator to attach middleware to controllers, modules, and routes.
|
|
12
|
-
*/
|
|
13
|
-
const Middleware = (...middleware) => (Target, propertyKey) => {
|
|
14
|
-
metadata_store_1.default.define(constants_1.KEY_PARAMS_MIDDLEWARES, middleware, {
|
|
15
|
-
target: Target,
|
|
16
|
-
propertyKey,
|
|
17
|
-
});
|
|
18
|
-
};
|
|
19
|
-
exports.Middleware = Middleware;
|
|
20
|
-
/**
|
|
21
|
-
* Exclude middleware from matching paths.
|
|
22
|
-
*
|
|
23
|
-
* @param expressions
|
|
24
|
-
* @param middleware
|
|
25
|
-
* @returns
|
|
26
|
-
*/
|
|
27
|
-
exports.Middleware.exclude =
|
|
28
|
-
(expressions, middleware) => (Target, propertyKey) => {
|
|
29
|
-
metadata_store_1.default.define(constants_1.KEY_PARAMS_MIDDLEWARES, buildHandler("exclude", expressions, middleware), {
|
|
30
|
-
target: Target,
|
|
31
|
-
propertyKey,
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
/**
|
|
35
|
-
* Only run middleware on matching paths.
|
|
36
|
-
*
|
|
37
|
-
* @param expresiosn
|
|
38
|
-
* @param middleware
|
|
39
|
-
* @returns
|
|
40
|
-
*/
|
|
41
|
-
exports.Middleware.only =
|
|
42
|
-
(expressions, middleware) => (Target, propertyKey) => {
|
|
43
|
-
metadata_store_1.default.define(constants_1.KEY_PARAMS_MIDDLEWARES, buildHandler("only", expressions, middleware), {
|
|
44
|
-
target: Target,
|
|
45
|
-
propertyKey,
|
|
46
|
-
});
|
|
47
|
-
};
|
|
48
|
-
/**
|
|
49
|
-
*
|
|
50
|
-
* Helper function to build middleware handlers for "only" and "exclude" modes.
|
|
51
|
-
*
|
|
52
|
-
* @param mode
|
|
53
|
-
* @param expresions
|
|
54
|
-
* @returns
|
|
55
|
-
*/
|
|
56
|
-
const buildHandler = (mode, expressions, middleware) => {
|
|
57
|
-
const matchers = Array.isArray(expressions) ? expressions : [expressions];
|
|
58
|
-
return (req, res, next) => {
|
|
59
|
-
const matches = matchers.some((rx) => rx.test(req.path));
|
|
60
|
-
if ((mode === "only" && !matches) || (mode === "exclude" && matches)) {
|
|
61
|
-
return next();
|
|
62
|
-
}
|
|
63
|
-
return middleware(req, res, next);
|
|
64
|
-
};
|
|
65
|
-
};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import "reflect-metadata";
|
|
2
|
-
/**
|
|
3
|
-
* Decorator to explicitly mark a method for response transformation and OpenAPI documentation.
|
|
4
|
-
*
|
|
5
|
-
* @param schema The schema or DTO class for the successful response (200).
|
|
6
|
-
* @example
|
|
7
|
-
* \@Output(UserDto)
|
|
8
|
-
*/
|
|
9
|
-
export declare function Output(schema?: any): (target: any, propertyKey?: any, descriptor?: PropertyDescriptor) => void;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Output = Output;
|
|
4
|
-
require("reflect-metadata");
|
|
5
|
-
const decorator_base_1 = require("../__internals/decorator-base");
|
|
6
|
-
const constants_1 = require("../__internals/constants");
|
|
7
|
-
/**
|
|
8
|
-
* Decorator to explicitly mark a method for response transformation and OpenAPI documentation.
|
|
9
|
-
*
|
|
10
|
-
* @param schema The schema or DTO class for the successful response (200).
|
|
11
|
-
* @example
|
|
12
|
-
* \@Output(UserDto)
|
|
13
|
-
*/
|
|
14
|
-
function Output(schema) {
|
|
15
|
-
return (target, propertyKey, descriptor) => {
|
|
16
|
-
(0, decorator_base_1.defineDecorData)(constants_1.KEY_OUTPUT_SCHEMA, schema, target, propertyKey);
|
|
17
|
-
};
|
|
18
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Request, Response } from "hyper-express";
|
|
2
|
-
interface PassOptions {
|
|
3
|
-
(req: Request, res: Response): boolean | Promise<boolean>;
|
|
4
|
-
}
|
|
5
|
-
/**
|
|
6
|
-
* Pass decorator
|
|
7
|
-
*
|
|
8
|
-
* This decorator allows bypassing checks when the provided function returns `true`.
|
|
9
|
-
* It can be applied to classes or methods, but not to properties.
|
|
10
|
-
*
|
|
11
|
-
* @param options - A function that returns true to allow bypassing
|
|
12
|
-
* @returns A class or method decorator
|
|
13
|
-
*/
|
|
14
|
-
export declare const Pass: (options: PassOptions) => ClassDecorator & MethodDecorator;
|
|
15
|
-
export {};
|
package/dist/decorators/Pass.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Pass = void 0;
|
|
7
|
-
const who_helper_1 = __importDefault(require("../__internals/helpers/who.helper"));
|
|
8
|
-
const NotPropertyException_1 = __importDefault(require("../exeptions/NotPropertyException"));
|
|
9
|
-
const constants_1 = require("../__internals/constants");
|
|
10
|
-
/**
|
|
11
|
-
* Pass decorator
|
|
12
|
-
*
|
|
13
|
-
* This decorator allows bypassing checks when the provided function returns `true`.
|
|
14
|
-
* It can be applied to classes or methods, but not to properties.
|
|
15
|
-
*
|
|
16
|
-
* @param options - A function that returns true to allow bypassing
|
|
17
|
-
* @returns A class or method decorator
|
|
18
|
-
*/
|
|
19
|
-
const Pass = (options) => (target, propertyKey, descriptorOrIndex) => {
|
|
20
|
-
const { isProperty, isMethod } = (0, who_helper_1.default)(target, propertyKey, descriptorOrIndex);
|
|
21
|
-
if (isProperty) {
|
|
22
|
-
throw new NotPropertyException_1.default(`${target.constructor.name}.${propertyKey === null || propertyKey === void 0 ? void 0 : propertyKey.toString()}`, target);
|
|
23
|
-
}
|
|
24
|
-
if (isMethod) {
|
|
25
|
-
Reflect.defineMetadata(constants_1.KEY_PARAMS_PASS, options, target, propertyKey);
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
Reflect.defineMetadata(constants_1.KEY_PARAMS_PASS, options, target);
|
|
29
|
-
}
|
|
30
|
-
return target;
|
|
31
|
-
};
|
|
32
|
-
exports.Pass = Pass;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import "reflect-metadata";
|
|
2
|
-
import { RoleType } from "./types";
|
|
3
|
-
/**
|
|
4
|
-
* Role decorator for setting role-based access control.
|
|
5
|
-
*/
|
|
6
|
-
export declare const Role: <T extends string = string>(roles: RoleType<T>) => (target: any, propertyKey?: any, descriptorOrIndex?: any) => void;
|
package/dist/decorators/Role.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Role = void 0;
|
|
7
|
-
require("reflect-metadata");
|
|
8
|
-
const exeptions_1 = require("../exeptions");
|
|
9
|
-
const who_helper_1 = __importDefault(require("../__internals/helpers/who.helper"));
|
|
10
|
-
const constants_1 = require("../__internals/constants");
|
|
11
|
-
const metadata_store_1 = __importDefault(require("../__internals/stores/metadata.store"));
|
|
12
|
-
/**
|
|
13
|
-
* Role decorator for setting role-based access control.
|
|
14
|
-
*/
|
|
15
|
-
const Role = (roles) => (target, propertyKey, descriptorOrIndex) => {
|
|
16
|
-
const _roles = Array.isArray(roles) ? roles : [roles];
|
|
17
|
-
if (!_roles.length) {
|
|
18
|
-
exeptions_1.HyperException.throw(`Role decorator must have at least one role.`, "HyperException", {
|
|
19
|
-
target,
|
|
20
|
-
propertyKey,
|
|
21
|
-
descriptorOrIndex,
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
const { isProperty } = (0, who_helper_1.default)(target, propertyKey, descriptorOrIndex);
|
|
25
|
-
if (isProperty) {
|
|
26
|
-
throw new Error(`Scope decorator cannot be used as parameter decorator in ${target.constructor.name}.${propertyKey}`);
|
|
27
|
-
}
|
|
28
|
-
const list = metadata_store_1.default.list(constants_1.KEY_PARAMS_ROLE, {
|
|
29
|
-
target,
|
|
30
|
-
propertyKey,
|
|
31
|
-
});
|
|
32
|
-
list.set(..._roles);
|
|
33
|
-
};
|
|
34
|
-
exports.Role = Role;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import "reflect-metadata";
|
|
2
|
-
import { WSRouteOptions } from "hyper-express/types";
|
|
3
|
-
export declare const Get: (path?: string, options?: undefined) => MethodDecorator & ClassDecorator;
|
|
4
|
-
export declare const Post: (path?: string, options?: undefined) => MethodDecorator & ClassDecorator;
|
|
5
|
-
export declare const Put: (path?: string, options?: undefined) => MethodDecorator & ClassDecorator;
|
|
6
|
-
export declare const Delete: (path?: string, options?: undefined) => MethodDecorator & ClassDecorator;
|
|
7
|
-
export declare const Patch: (path?: string, options?: undefined) => MethodDecorator & ClassDecorator;
|
|
8
|
-
export declare const Options: (path?: string, options?: undefined) => MethodDecorator & ClassDecorator;
|
|
9
|
-
export declare const Head: (path?: string, options?: undefined) => MethodDecorator & ClassDecorator;
|
|
10
|
-
export declare const Trace: (path?: string, options?: undefined) => MethodDecorator & ClassDecorator;
|
|
11
|
-
export declare const Any: (path?: string, options?: undefined) => MethodDecorator & ClassDecorator;
|
|
12
|
-
export declare const All: (path?: string, options?: undefined) => MethodDecorator & ClassDecorator;
|
|
13
|
-
export declare const Connect: (path?: string, options?: undefined) => MethodDecorator & ClassDecorator;
|
|
14
|
-
export declare const WS: (path?: string, options?: WSRouteOptions | undefined) => MethodDecorator & ClassDecorator;
|
|
15
|
-
export declare const Upgrade: (path?: string, options?: undefined) => MethodDecorator & ClassDecorator;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Upgrade = exports.WS = exports.Connect = exports.All = exports.Any = exports.Trace = exports.Head = exports.Options = exports.Patch = exports.Delete = exports.Put = exports.Post = exports.Get = void 0;
|
|
7
|
-
require("reflect-metadata");
|
|
8
|
-
const routes_creator_1 = __importDefault(require("../__internals/creators/routes.creator"));
|
|
9
|
-
exports.Get = (0, routes_creator_1.default)("get");
|
|
10
|
-
exports.Post = (0, routes_creator_1.default)("post");
|
|
11
|
-
exports.Put = (0, routes_creator_1.default)("put");
|
|
12
|
-
exports.Delete = (0, routes_creator_1.default)("delete");
|
|
13
|
-
exports.Patch = (0, routes_creator_1.default)("patch");
|
|
14
|
-
exports.Options = (0, routes_creator_1.default)("options");
|
|
15
|
-
exports.Head = (0, routes_creator_1.default)("head");
|
|
16
|
-
exports.Trace = (0, routes_creator_1.default)("trace");
|
|
17
|
-
exports.Any = (0, routes_creator_1.default)("any");
|
|
18
|
-
exports.All = (0, routes_creator_1.default)("all");
|
|
19
|
-
exports.Connect = (0, routes_creator_1.default)("connect");
|
|
20
|
-
exports.WS = (0, routes_creator_1.default)("ws");
|
|
21
|
-
exports.Upgrade = (0, routes_creator_1.default)("upgrade");
|
package/dist/decorators/Scope.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Scope = void 0;
|
|
7
|
-
require("reflect-metadata");
|
|
8
|
-
const constants_1 = require("../__internals/constants");
|
|
9
|
-
const who_helper_1 = __importDefault(require("../__internals/helpers/who.helper"));
|
|
10
|
-
const metadata_store_1 = __importDefault(require("../__internals/stores/metadata.store"));
|
|
11
|
-
/**
|
|
12
|
-
* Scope decorator for defining access scopes.
|
|
13
|
-
*/
|
|
14
|
-
const Scope = (scopes) => (target, propertyKey, descriptorOrIndex) => {
|
|
15
|
-
const { isProperty } = (0, who_helper_1.default)(target, propertyKey, descriptorOrIndex);
|
|
16
|
-
if (isProperty) {
|
|
17
|
-
throw new Error(`Scope decorator cannot be used as parameter decorator in ${target.constructor.name}.${propertyKey}`);
|
|
18
|
-
}
|
|
19
|
-
const list = metadata_store_1.default.list(constants_1.KEY_PARAMS_SCOPE, {
|
|
20
|
-
target,
|
|
21
|
-
propertyKey,
|
|
22
|
-
});
|
|
23
|
-
list.set(...(Array.isArray(scopes) ? scopes : [scopes]));
|
|
24
|
-
};
|
|
25
|
-
exports.Scope = Scope;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import "reflect-metadata";
|
|
2
|
-
export interface TransformOptions {
|
|
3
|
-
/**
|
|
4
|
-
* Where to extract the data from. Defaults to 'body'.
|
|
5
|
-
*/
|
|
6
|
-
from?: 'body' | 'query' | 'params' | 'headers';
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Agnostic decorator to transform/validate request data using a registered transformer.
|
|
10
|
-
*
|
|
11
|
-
* @param schema The schema or object to be used by the registered transformer.
|
|
12
|
-
* @param options Transformation options.
|
|
13
|
-
*/
|
|
14
|
-
export declare function Transform(schema: any, options?: TransformOptions): (target: any, propertyKey: any) => void;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Transform = Transform;
|
|
4
|
-
require("reflect-metadata");
|
|
5
|
-
const constants_1 = require("../__internals/constants");
|
|
6
|
-
const decorator_base_1 = require("../__internals/decorator-base");
|
|
7
|
-
/**
|
|
8
|
-
* Agnostic decorator to transform/validate request data using a registered transformer.
|
|
9
|
-
*
|
|
10
|
-
* @param schema The schema or object to be used by the registered transformer.
|
|
11
|
-
* @param options Transformation options.
|
|
12
|
-
*/
|
|
13
|
-
function Transform(schema, options = {}) {
|
|
14
|
-
return (target, propertyKey) => {
|
|
15
|
-
const data = { schema, options };
|
|
16
|
-
(0, decorator_base_1.defineDecorData)(constants_1.KEY_PARAMS_TRANSFORM, data, target, propertyKey);
|
|
17
|
-
};
|
|
18
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export * from "./HyperApp";
|
|
2
|
-
export * from "./HyperModule";
|
|
3
|
-
export * from "./HyperController";
|
|
4
|
-
export * from "./HyperService";
|
|
5
|
-
export * from "./Middleware";
|
|
6
|
-
export * from "./Scope";
|
|
7
|
-
export * from "./Role";
|
|
8
|
-
export * from "./Routes";
|
|
9
|
-
export * from "./types";
|
|
10
|
-
export * from "./Http";
|
|
11
|
-
export * from "./Pass";
|
|
12
|
-
export * from "./File";
|
|
13
|
-
export * from "./Messaging";
|
|
14
|
-
export * from "./Output";
|
package/dist/decorators/index.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
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("./HyperApp"), exports);
|
|
18
|
-
__exportStar(require("./HyperModule"), exports);
|
|
19
|
-
__exportStar(require("./HyperController"), exports);
|
|
20
|
-
__exportStar(require("./HyperService"), exports);
|
|
21
|
-
__exportStar(require("./Middleware"), exports);
|
|
22
|
-
__exportStar(require("./Scope"), exports);
|
|
23
|
-
__exportStar(require("./Role"), exports);
|
|
24
|
-
__exportStar(require("./Routes"), exports);
|
|
25
|
-
__exportStar(require("./types"), exports);
|
|
26
|
-
__exportStar(require("./Http"), exports);
|
|
27
|
-
__exportStar(require("./Pass"), exports);
|
|
28
|
-
__exportStar(require("./File"), exports);
|
|
29
|
-
__exportStar(require("./Messaging"), exports);
|
|
30
|
-
__exportStar(require("./Output"), exports);
|