@zenofolio/hyper-decor 1.0.7 → 1.0.8
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/.agent/rules/philosophy.md +103 -0
- package/.agent/rules/writing.md +32 -0
- package/README.md +103 -201
- package/dist/__internals/constants.d.ts +1 -62
- package/dist/__internals/constants.js +3 -69
- package/dist/__internals/helpers/merge-metadata.d.ts +2 -3
- package/dist/__internals/helpers/merge-metadata.js +31 -7
- package/dist/__internals/helpers/prepare.helper.d.ts +4 -10
- package/dist/__internals/helpers/prepare.helper.js +325 -281
- package/dist/__internals/stores/hyper.store.d.ts +5 -0
- package/dist/__internals/stores/hyper.store.js +5 -0
- package/dist/__internals/stores/index.d.ts +4 -0
- package/dist/{lib/openapi/helpers → __internals/stores}/index.js +4 -7
- package/dist/__internals/stores/meta.store.d.ts +34 -0
- package/dist/__internals/stores/meta.store.js +107 -0
- package/dist/{stores → __internals/stores}/scope.store.d.ts +1 -1
- package/dist/__internals/transform/middleware.transform.d.ts +1 -1
- package/dist/__internals/transform/middleware.transform.js +1 -1
- package/dist/__internals/transform/role.transform.d.ts +1 -1
- package/dist/__internals/transform/role.transform.js +4 -4
- package/dist/__internals/transform/scope.transfrom.d.ts +1 -1
- package/dist/__internals/transform/scope.transfrom.js +2 -2
- package/dist/__internals/types.d.ts +53 -4
- package/dist/common/bootstrap.d.ts +6 -2
- package/dist/common/bootstrap.js +49 -10
- package/dist/common/testing.d.ts +56 -0
- package/dist/common/testing.js +193 -0
- package/dist/common/transport.d.ts +1 -0
- package/dist/common/transport.js +27 -14
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +2 -1
- package/dist/decorators.d.ts +1 -0
- package/dist/{stores/index.js → decorators.js} +1 -1
- package/dist/index.d.ts +7 -5
- package/dist/index.js +7 -5
- package/dist/lib/event/meta.store.d.ts +4 -0
- package/dist/lib/event/meta.store.js +5 -0
- package/dist/lib/openapi/collectors/class.collector.d.ts +5 -9
- package/dist/lib/openapi/collectors/class.collector.js +6 -63
- package/dist/lib/openapi/collectors/index.d.ts +3 -4
- package/dist/lib/openapi/collectors/index.js +0 -1
- package/dist/lib/openapi/collectors/method.collector.d.ts +6 -1
- package/dist/lib/openapi/collectors/method.collector.js +92 -59
- package/dist/lib/openapi/collectors/schema.collector.d.ts +3 -8
- package/dist/lib/openapi/collectors/schema.collector.js +17 -25
- package/dist/lib/openapi/constants.d.ts +1 -0
- package/dist/lib/openapi/constants.js +2 -2
- package/dist/lib/openapi/decorators.d.ts +16 -0
- package/dist/lib/openapi/decorators.js +93 -0
- package/dist/lib/openapi/index.d.ts +29 -5
- package/dist/lib/openapi/index.js +119 -5
- package/dist/lib/openapi/metadata.d.ts +7 -0
- package/dist/lib/openapi/metadata.js +8 -0
- package/dist/lib/openapi/metadata.registry.d.ts +1 -1
- package/dist/lib/server/decorators/File.d.ts +37 -0
- package/dist/{decorators → lib/server/decorators}/File.js +62 -75
- package/dist/lib/server/decorators/Http.d.ts +12 -0
- package/dist/lib/server/decorators/Http.js +56 -0
- package/dist/lib/server/decorators/HyperApp.d.ts +7 -0
- package/dist/lib/server/decorators/HyperApp.js +14 -0
- package/dist/lib/server/decorators/HyperController.d.ts +6 -0
- package/dist/lib/server/decorators/HyperController.js +15 -0
- package/dist/lib/server/decorators/HyperModule.d.ts +6 -0
- package/dist/lib/server/decorators/HyperModule.js +13 -0
- package/dist/lib/server/decorators/HyperService.d.ts +12 -0
- package/dist/lib/server/decorators/HyperService.js +30 -0
- package/dist/lib/server/decorators/Messaging.d.ts +8 -0
- package/dist/lib/server/decorators/Messaging.js +19 -0
- package/dist/{decorators → lib/server/decorators}/Middleware.d.ts +5 -12
- package/dist/lib/server/decorators/Middleware.js +52 -0
- package/dist/lib/server/decorators/Output.d.ts +6 -0
- package/dist/lib/server/decorators/Output.js +14 -0
- package/dist/lib/server/decorators/Pass.d.ts +10 -0
- package/dist/lib/server/decorators/Pass.js +13 -0
- package/dist/lib/server/decorators/Role.d.ts +7 -0
- package/dist/lib/server/decorators/Role.js +14 -0
- package/dist/lib/server/decorators/Routes.d.ts +14 -0
- package/dist/lib/server/decorators/Routes.js +39 -0
- package/dist/lib/server/decorators/Scope.d.ts +7 -0
- package/dist/lib/server/decorators/Scope.js +14 -0
- package/dist/{decorators → lib/server/decorators}/index.d.ts +6 -4
- package/dist/{decorators → lib/server/decorators}/index.js +6 -4
- package/dist/lib/server/decorators/metadata.d.ts +1 -0
- package/dist/lib/server/decorators/metadata.js +5 -0
- package/dist/{decorators → lib/server/decorators}/types.d.ts +16 -15
- package/dist/{exeptions → lib/server/exeptions}/HyperException.d.ts +2 -1
- package/dist/{exeptions → lib/server/exeptions}/HyperException.js +2 -1
- package/dist/{exeptions → lib/server/exeptions}/HyperFileException.js +1 -1
- package/dist/{exeptions → lib/server/exeptions}/NotRoleException.js +1 -1
- package/dist/{exeptions → lib/server/exeptions}/NotScopeException.js +1 -1
- package/dist/{__internals/helpers/tree.helper.d.ts → lib/tree/tree.d.ts} +12 -12
- package/dist/lib/tree/tree.js +106 -0
- package/package.json +10 -2
- package/scripts/clean.js +54 -54
- package/scripts/test-server.ts +85 -85
- package/vitest.config.mjs +1 -1
- package/debug.txt +0 -1
- package/dist/__internals/creators/request.creator.d.ts +0 -11
- package/dist/__internals/creators/request.creator.js +0 -55
- 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.js +0 -81
- package/dist/__internals/stores/metadata.store.d.ts +0 -15
- package/dist/__internals/stores/metadata.store.js +0 -37
- package/dist/decorators/File.d.ts +0 -65
- package/dist/decorators/Http.d.ts +0 -62
- package/dist/decorators/Http.js +0 -139
- 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.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/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/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/vitest.json +0 -0
- /package/dist/{stores → __internals/stores}/scope.store.js +0 -0
- /package/dist/__internals/stores/{service.store.d.ts → serivces.store.d.ts} +0 -0
- /package/dist/__internals/stores/{service.store.js → serivces.store.js} +0 -0
- /package/dist/{decorators → lib/server/decorators}/types.js +0 -0
- /package/dist/{exeptions → lib/server/exeptions}/DuplicateControllerPathException.d.ts +0 -0
- /package/dist/{exeptions → lib/server/exeptions}/DuplicateControllerPathException.js +0 -0
- /package/dist/{exeptions → lib/server/exeptions}/DuplicatedException.d.ts +0 -0
- /package/dist/{exeptions → lib/server/exeptions}/DuplicatedException.js +0 -0
- /package/dist/{exeptions → lib/server/exeptions}/DuplicatedHandlerException.d.ts +0 -0
- /package/dist/{exeptions → lib/server/exeptions}/DuplicatedHandlerException.js +0 -0
- /package/dist/{exeptions → lib/server/exeptions}/HyperFileException.d.ts +0 -0
- /package/dist/{exeptions → lib/server/exeptions}/MethodNotFountException.d.ts +0 -0
- /package/dist/{exeptions → lib/server/exeptions}/MethodNotFountException.js +0 -0
- /package/dist/{exeptions → lib/server/exeptions}/NotPropertyException.d.ts +0 -0
- /package/dist/{exeptions → lib/server/exeptions}/NotPropertyException.js +0 -0
- /package/dist/{exeptions → lib/server/exeptions}/NotRoleException.d.ts +0 -0
- /package/dist/{exeptions → lib/server/exeptions}/NotScopeException.d.ts +0 -0
- /package/dist/{exeptions → lib/server/exeptions}/WrongPlaceException.d.ts +0 -0
- /package/dist/{exeptions → lib/server/exeptions}/WrongPlaceException.js +0 -0
- /package/dist/{exeptions → lib/server/exeptions}/index.d.ts +0 -0
- /package/dist/{exeptions → lib/server/exeptions}/index.js +0 -0
- /package/dist/{exeptions → lib/server/exeptions}/types.d.ts +0 -0
- /package/dist/{exeptions → lib/server/exeptions}/types.js +0 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HyperModule = HyperModule;
|
|
4
|
+
const metadata_1 = require("./metadata");
|
|
5
|
+
/**
|
|
6
|
+
* 🚀 HyperModule Decorator
|
|
7
|
+
* Purely injects metadata into the target class.
|
|
8
|
+
*/
|
|
9
|
+
function HyperModule(options) {
|
|
10
|
+
return (Target) => {
|
|
11
|
+
metadata_1.HyperMeta.set(Target, undefined, Object.assign({ type: "module" }, options));
|
|
12
|
+
};
|
|
13
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
import { Constructor } from "./types";
|
|
3
|
+
interface ServiceDecoratorOptions {
|
|
4
|
+
singleton?: boolean;
|
|
5
|
+
token?: string | symbol | Constructor | (abstract new (...args: any[]) => any);
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* 🚀 HyperService Decorator
|
|
9
|
+
* Purely injects metadata and registers the class in the DI container.
|
|
10
|
+
*/
|
|
11
|
+
export declare function HyperService({ token, singleton, }?: ServiceDecoratorOptions): (Target: any) => any;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HyperService = HyperService;
|
|
4
|
+
require("reflect-metadata");
|
|
5
|
+
const tsyringe_1 = require("tsyringe");
|
|
6
|
+
const metadata_1 = require("./metadata");
|
|
7
|
+
/**
|
|
8
|
+
* 🚀 HyperService Decorator
|
|
9
|
+
* Purely injects metadata and registers the class in the DI container.
|
|
10
|
+
*/
|
|
11
|
+
function HyperService({ token, singleton = true, } = {}) {
|
|
12
|
+
return (Target) => {
|
|
13
|
+
const useToken = token !== null && token !== void 0 ? token : Target;
|
|
14
|
+
// 1. DI Registration
|
|
15
|
+
(0, tsyringe_1.injectable)()(Target);
|
|
16
|
+
if (!tsyringe_1.container.isRegistered(useToken)) {
|
|
17
|
+
if (singleton) {
|
|
18
|
+
tsyringe_1.container.registerSingleton(useToken, Target);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
tsyringe_1.container.register(useToken, { useClass: Target });
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
// 2. Hierarchical Metadata Injection
|
|
25
|
+
metadata_1.HyperMeta.set(Target, undefined, {
|
|
26
|
+
type: 'service',
|
|
27
|
+
});
|
|
28
|
+
return Target;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
/**
|
|
3
|
+
* 🚀 OnMessage Decorator
|
|
4
|
+
* Purely injects message subscription metadata into the method.
|
|
5
|
+
*
|
|
6
|
+
* @param topic The topic or pattern to listen to (e.g. "user.created", "user.*")
|
|
7
|
+
*/
|
|
8
|
+
export declare const OnMessage: (topic: string) => (target: any, propertyKey: any) => void;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OnMessage = void 0;
|
|
4
|
+
require("reflect-metadata");
|
|
5
|
+
const metadata_1 = require("./metadata");
|
|
6
|
+
/**
|
|
7
|
+
* 🚀 OnMessage Decorator
|
|
8
|
+
* Purely injects message subscription metadata into the method.
|
|
9
|
+
*
|
|
10
|
+
* @param topic The topic or pattern to listen to (e.g. "user.created", "user.*")
|
|
11
|
+
*/
|
|
12
|
+
const OnMessage = (topic) => {
|
|
13
|
+
return (target, propertyKey) => {
|
|
14
|
+
metadata_1.HyperMeta.set(target, propertyKey, {
|
|
15
|
+
onMessage: { topic }
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
exports.OnMessage = OnMessage;
|
|
@@ -2,24 +2,17 @@ import "reflect-metadata";
|
|
|
2
2
|
import { MiddlewareHandler } from "hyper-express";
|
|
3
3
|
import { MiddlewareType } from "./types";
|
|
4
4
|
/**
|
|
5
|
-
* Middleware
|
|
5
|
+
* 🚀 Middleware Decorator
|
|
6
|
+
* Purely injects middleware metadata into the target class or method.
|
|
6
7
|
*/
|
|
7
8
|
export declare const Middleware: {
|
|
8
|
-
(...middleware: MiddlewareType[]):
|
|
9
|
+
(...middleware: MiddlewareType[]): any;
|
|
9
10
|
/**
|
|
10
11
|
* Exclude middleware from matching paths.
|
|
11
|
-
*
|
|
12
|
-
* @param expressions
|
|
13
|
-
* @param middleware
|
|
14
|
-
* @returns
|
|
15
12
|
*/
|
|
16
|
-
exclude(expressions: RegExp | RegExp[], middleware: MiddlewareHandler):
|
|
13
|
+
exclude(expressions: RegExp | RegExp[], middleware: MiddlewareHandler): any;
|
|
17
14
|
/**
|
|
18
15
|
* Only run middleware on matching paths.
|
|
19
|
-
*
|
|
20
|
-
* @param expresiosn
|
|
21
|
-
* @param middleware
|
|
22
|
-
* @returns
|
|
23
16
|
*/
|
|
24
|
-
only(expressions: RegExp | RegExp[], middleware: MiddlewareHandler):
|
|
17
|
+
only(expressions: RegExp | RegExp[], middleware: MiddlewareHandler): any;
|
|
25
18
|
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Middleware = void 0;
|
|
4
|
+
require("reflect-metadata");
|
|
5
|
+
const metadata_1 = require("./metadata");
|
|
6
|
+
/**
|
|
7
|
+
* 🚀 Middleware Decorator
|
|
8
|
+
* Purely injects middleware metadata into the target class or method.
|
|
9
|
+
*/
|
|
10
|
+
const Middleware = (...middleware) => (target, propertyKey) => {
|
|
11
|
+
const current = metadata_1.HyperMeta.get(target, propertyKey);
|
|
12
|
+
const existing = current.middlewares || [];
|
|
13
|
+
metadata_1.HyperMeta.set(target, propertyKey, {
|
|
14
|
+
middlewares: [...existing, ...middleware]
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
exports.Middleware = Middleware;
|
|
18
|
+
/**
|
|
19
|
+
* Exclude middleware from matching paths.
|
|
20
|
+
*/
|
|
21
|
+
exports.Middleware.exclude = (expressions, middleware) => (target, propertyKey) => {
|
|
22
|
+
const handler = buildHandler("exclude", expressions, middleware);
|
|
23
|
+
const current = metadata_1.HyperMeta.get(target, propertyKey);
|
|
24
|
+
const existing = current.middlewares || [];
|
|
25
|
+
metadata_1.HyperMeta.set(target, propertyKey, {
|
|
26
|
+
middlewares: [...existing, handler]
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Only run middleware on matching paths.
|
|
31
|
+
*/
|
|
32
|
+
exports.Middleware.only = (expressions, middleware) => (target, propertyKey) => {
|
|
33
|
+
const handler = buildHandler("only", expressions, middleware);
|
|
34
|
+
const current = metadata_1.HyperMeta.get(target, propertyKey);
|
|
35
|
+
const existing = current.middlewares || [];
|
|
36
|
+
metadata_1.HyperMeta.set(target, propertyKey, {
|
|
37
|
+
middlewares: [...existing, handler]
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Helper function to build middleware handlers for "only" and "exclude" modes.
|
|
42
|
+
*/
|
|
43
|
+
const buildHandler = (mode, expressions, middleware) => {
|
|
44
|
+
const matchers = Array.isArray(expressions) ? expressions : [expressions];
|
|
45
|
+
return (req, res, next) => {
|
|
46
|
+
const matches = matchers.some((rx) => rx.test(req.path));
|
|
47
|
+
if ((mode === "only" && !matches) || (mode === "exclude" && matches)) {
|
|
48
|
+
return next();
|
|
49
|
+
}
|
|
50
|
+
return middleware(req, res, next);
|
|
51
|
+
};
|
|
52
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Output = Output;
|
|
4
|
+
require("reflect-metadata");
|
|
5
|
+
const metadata_1 = require("./metadata");
|
|
6
|
+
/**
|
|
7
|
+
* 🚀 Output Decorator
|
|
8
|
+
* Purely injects output schema metadata into the method.
|
|
9
|
+
*/
|
|
10
|
+
function Output(schema) {
|
|
11
|
+
return (target, propertyKey) => {
|
|
12
|
+
metadata_1.HyperMeta.set(target, propertyKey, { output: schema });
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
import { Request, Response } from "hyper-express";
|
|
3
|
+
export interface PassOptions {
|
|
4
|
+
(req: Request, res: Response): boolean | Promise<boolean>;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* 🚀 Pass Decorator
|
|
8
|
+
* Purely injects pass metadata into the target class or method.
|
|
9
|
+
*/
|
|
10
|
+
export declare const Pass: (options?: PassOptions | boolean) => any;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Pass = void 0;
|
|
4
|
+
require("reflect-metadata");
|
|
5
|
+
const metadata_1 = require("./metadata");
|
|
6
|
+
/**
|
|
7
|
+
* 🚀 Pass Decorator
|
|
8
|
+
* Purely injects pass metadata into the target class or method.
|
|
9
|
+
*/
|
|
10
|
+
const Pass = (options = true) => (target, propertyKey) => {
|
|
11
|
+
metadata_1.HyperMeta.set(target, propertyKey, { pass: options });
|
|
12
|
+
};
|
|
13
|
+
exports.Pass = Pass;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
import { RoleType } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* 🚀 Role Decorator
|
|
5
|
+
* Purely injects role metadata into the target class or method.
|
|
6
|
+
*/
|
|
7
|
+
export declare const Role: <T extends string = string>(roles: RoleType<T>) => (target: any, propertyKey?: any) => void;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Role = void 0;
|
|
4
|
+
require("reflect-metadata");
|
|
5
|
+
const metadata_1 = require("./metadata");
|
|
6
|
+
/**
|
|
7
|
+
* 🚀 Role Decorator
|
|
8
|
+
* Purely injects role metadata into the target class or method.
|
|
9
|
+
*/
|
|
10
|
+
const Role = (roles) => (target, propertyKey) => {
|
|
11
|
+
const _roles = Array.isArray(roles) ? roles : [roles];
|
|
12
|
+
metadata_1.HyperMeta.set(target, propertyKey, { roles: _roles });
|
|
13
|
+
};
|
|
14
|
+
exports.Role = Role;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
export declare const Get: (path?: string, options?: Record<string, unknown> | undefined) => (target: object, propertyKey?: any) => void;
|
|
3
|
+
export declare const Post: (path?: string, options?: Record<string, unknown> | undefined) => (target: object, propertyKey?: any) => void;
|
|
4
|
+
export declare const Put: (path?: string, options?: Record<string, unknown> | undefined) => (target: object, propertyKey?: any) => void;
|
|
5
|
+
export declare const Delete: (path?: string, options?: Record<string, unknown> | undefined) => (target: object, propertyKey?: any) => void;
|
|
6
|
+
export declare const Patch: (path?: string, options?: Record<string, unknown> | undefined) => (target: object, propertyKey?: any) => void;
|
|
7
|
+
export declare const Options: (path?: string, options?: Record<string, unknown> | undefined) => (target: object, propertyKey?: any) => void;
|
|
8
|
+
export declare const Head: (path?: string, options?: Record<string, unknown> | undefined) => (target: object, propertyKey?: any) => void;
|
|
9
|
+
export declare const Trace: (path?: string, options?: Record<string, unknown> | undefined) => (target: object, propertyKey?: any) => void;
|
|
10
|
+
export declare const Any: (path?: string, options?: Record<string, unknown> | undefined) => (target: object, propertyKey?: any) => void;
|
|
11
|
+
export declare const All: (path?: string, options?: Record<string, unknown> | undefined) => (target: object, propertyKey?: any) => void;
|
|
12
|
+
export declare const Connect: (path?: string, options?: Record<string, unknown> | undefined) => (target: object, propertyKey?: any) => void;
|
|
13
|
+
export declare const WS: (path?: string, options?: Record<string, unknown> | undefined) => (target: object, propertyKey?: any) => void;
|
|
14
|
+
export declare const Upgrade: (path?: string, options?: Record<string, unknown> | undefined) => (target: object, propertyKey?: any) => void;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
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;
|
|
4
|
+
require("reflect-metadata");
|
|
5
|
+
const metadata_1 = require("./metadata");
|
|
6
|
+
/**
|
|
7
|
+
* 🛠️ Helper to create route decorators
|
|
8
|
+
*/
|
|
9
|
+
function createRouteDecorator(method) {
|
|
10
|
+
return (path = "/", options) => {
|
|
11
|
+
return (target, propertyKey) => {
|
|
12
|
+
const returnType = Reflect.getMetadata("design:returntype", target, propertyKey);
|
|
13
|
+
metadata_1.HyperMeta.set(target, propertyKey, {
|
|
14
|
+
route: {
|
|
15
|
+
method,
|
|
16
|
+
path,
|
|
17
|
+
propertyKey: propertyKey,
|
|
18
|
+
options: options,
|
|
19
|
+
},
|
|
20
|
+
reflection: {
|
|
21
|
+
output: returnType
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
exports.Get = createRouteDecorator("get");
|
|
28
|
+
exports.Post = createRouteDecorator("post");
|
|
29
|
+
exports.Put = createRouteDecorator("put");
|
|
30
|
+
exports.Delete = createRouteDecorator("delete");
|
|
31
|
+
exports.Patch = createRouteDecorator("patch");
|
|
32
|
+
exports.Options = createRouteDecorator("options");
|
|
33
|
+
exports.Head = createRouteDecorator("head");
|
|
34
|
+
exports.Trace = createRouteDecorator("trace");
|
|
35
|
+
exports.Any = createRouteDecorator("any");
|
|
36
|
+
exports.All = createRouteDecorator("all");
|
|
37
|
+
exports.Connect = createRouteDecorator("connect");
|
|
38
|
+
exports.WS = createRouteDecorator("ws");
|
|
39
|
+
exports.Upgrade = createRouteDecorator("upgrade");
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
import { ScopeType } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* 🚀 Scope Decorator
|
|
5
|
+
* Purely injects scope metadata into the target class or method.
|
|
6
|
+
*/
|
|
7
|
+
export declare const Scope: <T extends string = string>(scopes: ScopeType<T>) => (target: any, propertyKey?: any) => void;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Scope = void 0;
|
|
4
|
+
require("reflect-metadata");
|
|
5
|
+
const metadata_1 = require("./metadata");
|
|
6
|
+
/**
|
|
7
|
+
* 🚀 Scope Decorator
|
|
8
|
+
* Purely injects scope metadata into the target class or method.
|
|
9
|
+
*/
|
|
10
|
+
const Scope = (scopes) => (target, propertyKey) => {
|
|
11
|
+
const _scopes = Array.isArray(scopes) ? scopes : [scopes];
|
|
12
|
+
metadata_1.HyperMeta.set(target, propertyKey, { scopes: _scopes });
|
|
13
|
+
};
|
|
14
|
+
exports.Scope = Scope;
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
+
export * from "./metadata";
|
|
2
|
+
export * from "./types";
|
|
1
3
|
export * from "./HyperApp";
|
|
2
4
|
export * from "./HyperModule";
|
|
3
5
|
export * from "./HyperController";
|
|
4
6
|
export * from "./HyperService";
|
|
5
|
-
export * from "./Middleware";
|
|
6
|
-
export * from "./Scope";
|
|
7
|
-
export * from "./Role";
|
|
8
7
|
export * from "./Routes";
|
|
9
|
-
export * from "./types";
|
|
10
8
|
export * from "./Http";
|
|
9
|
+
export * from "./Role";
|
|
10
|
+
export * from "./Scope";
|
|
11
|
+
export * from "./Output";
|
|
12
|
+
export * from "./Middleware";
|
|
11
13
|
export * from "./Pass";
|
|
12
14
|
export * from "./File";
|
|
13
15
|
export * from "./Messaging";
|
|
@@ -14,16 +14,18 @@ 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("./metadata"), exports);
|
|
18
|
+
__exportStar(require("./types"), exports);
|
|
17
19
|
__exportStar(require("./HyperApp"), exports);
|
|
18
20
|
__exportStar(require("./HyperModule"), exports);
|
|
19
21
|
__exportStar(require("./HyperController"), exports);
|
|
20
22
|
__exportStar(require("./HyperService"), exports);
|
|
21
|
-
__exportStar(require("./Middleware"), exports);
|
|
22
|
-
__exportStar(require("./Scope"), exports);
|
|
23
|
-
__exportStar(require("./Role"), exports);
|
|
24
23
|
__exportStar(require("./Routes"), exports);
|
|
25
|
-
__exportStar(require("./types"), exports);
|
|
26
24
|
__exportStar(require("./Http"), exports);
|
|
25
|
+
__exportStar(require("./Role"), exports);
|
|
26
|
+
__exportStar(require("./Scope"), exports);
|
|
27
|
+
__exportStar(require("./Output"), exports);
|
|
28
|
+
__exportStar(require("./Middleware"), exports);
|
|
27
29
|
__exportStar(require("./Pass"), exports);
|
|
28
30
|
__exportStar(require("./File"), exports);
|
|
29
31
|
__exportStar(require("./Messaging"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { HyperMeta } from "../../../__internals/stores/hyper.store";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HyperMeta = void 0;
|
|
4
|
+
var hyper_store_1 = require("../../../__internals/stores/hyper.store");
|
|
5
|
+
Object.defineProperty(exports, "HyperMeta", { enumerable: true, get: function () { return hyper_store_1.HyperMeta; } });
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import type { MiddlewareHandler, MiddlewareNext, Request, Response, ServerConstructorOptions } from "hyper-express";
|
|
2
2
|
import { InjectionToken, RegistrationOptions } from "tsyringe";
|
|
3
|
-
import { IMessageTransport } from "
|
|
3
|
+
import { IMessageTransport } from "../../../common/transport";
|
|
4
4
|
export interface OnInit {
|
|
5
5
|
onInit(): Promise<any>;
|
|
6
6
|
}
|
|
7
7
|
export interface IsSingleton {
|
|
8
8
|
isSingleton(): boolean;
|
|
9
9
|
}
|
|
10
|
-
export type Constructor<R
|
|
10
|
+
export type Constructor<R = object> = new (...args: any[]) => R;
|
|
11
11
|
export type ImportObject = {
|
|
12
|
-
token: InjectionToken;
|
|
12
|
+
token: (abstract new (...args: any[]) => any) | InjectionToken;
|
|
13
13
|
useClass?: Constructor;
|
|
14
14
|
useValue?: any;
|
|
15
15
|
useFactory?: (...args: any[]) => any;
|
|
@@ -25,6 +25,7 @@ export interface LogSpaces {
|
|
|
25
25
|
controllers: boolean;
|
|
26
26
|
middleware: boolean;
|
|
27
27
|
routes: boolean;
|
|
28
|
+
messaging: boolean;
|
|
28
29
|
}
|
|
29
30
|
export interface IHyperHooks {
|
|
30
31
|
onBeforeInit?(instance: any, token: any, context: any): void | Promise<void>;
|
|
@@ -42,6 +43,7 @@ export interface HyperAppMetadata {
|
|
|
42
43
|
modules: Constructor[];
|
|
43
44
|
imports?: ImportType[];
|
|
44
45
|
options?: ServerConstructorOptions;
|
|
46
|
+
uwsOptions?: any;
|
|
45
47
|
transports?: IMessageTransport[];
|
|
46
48
|
hooks?: IHyperHooks | Constructor<IHyperHooks>;
|
|
47
49
|
}
|
|
@@ -67,16 +69,17 @@ export type HyperControllerMetadata = {
|
|
|
67
69
|
export type HyperControllerDecorator = HyperClassDecorator<HyperControllerMetadata | string>;
|
|
68
70
|
export type ParameterResolver = (req: Request, res: Response) => any | Promise<any>;
|
|
69
71
|
export type HyperParameterMetadata = {
|
|
70
|
-
params:
|
|
72
|
+
params: {
|
|
71
73
|
index: number;
|
|
72
|
-
type:
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
resolver: ParameterResolver;
|
|
77
|
-
schema?: any;
|
|
74
|
+
type: Constructor | Function;
|
|
75
|
+
source?: "body" | "query" | "params" | "headers" | "req" | "res";
|
|
76
|
+
picker?: string;
|
|
77
|
+
schema?: object | Function;
|
|
78
78
|
isWholeSource?: boolean;
|
|
79
|
-
|
|
79
|
+
name?: string;
|
|
80
|
+
decorator: string;
|
|
81
|
+
resolver?: ParameterResolver;
|
|
82
|
+
}[];
|
|
80
83
|
};
|
|
81
84
|
export type HyperParamDecorator = (key: string) => (target: any, key: string, index: number) => void;
|
|
82
85
|
export type RoleMap<T> = {
|
|
@@ -101,15 +104,13 @@ export type ScopeMap<T extends string = string> = {
|
|
|
101
104
|
export type ScopeType<T extends string = string> = T | T[] | ScopeMap<T> | ScopeMap<T>[];
|
|
102
105
|
/**
|
|
103
106
|
* Type definition for Route metadata.
|
|
104
|
-
* Contains method, path, and
|
|
107
|
+
* Contains method, path, and other configuration for a specific method.
|
|
105
108
|
*/
|
|
106
109
|
export interface RouteMetadata {
|
|
107
|
-
className: string;
|
|
108
110
|
method: string;
|
|
109
111
|
path: string;
|
|
110
112
|
propertyKey: string;
|
|
111
|
-
options?:
|
|
112
|
-
handler: (...args: any[]) => any;
|
|
113
|
+
options?: Record<string, unknown>;
|
|
113
114
|
}
|
|
114
115
|
export declare abstract class MiddlewareClass {
|
|
115
116
|
abstract handle(req: Request, res: Response, next: MiddlewareNext): 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;
|
|
@@ -9,7 +9,7 @@ class NotScopeException extends HyperException_1.default {
|
|
|
9
9
|
super(message || `You don't have the required scopes to access this resource`, "NotScopeException", {
|
|
10
10
|
requestScopes,
|
|
11
11
|
requiredScopes,
|
|
12
|
-
});
|
|
12
|
+
}, 403);
|
|
13
13
|
this.message = message;
|
|
14
14
|
this.requestScopes = requestScopes;
|
|
15
15
|
this.requiredScopes = requiredScopes;
|
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
import { HyperAppMetadata, HyperModuleMetadata, HyperControllerMetadata, RouteMetadata } from "
|
|
1
|
+
import { HyperAppMetadata, HyperModuleMetadata, HyperControllerMetadata, HyperParameterMetadata, RouteMetadata, ImportType, Constructor } from "../server/decorators/types";
|
|
2
2
|
export interface AppTree {
|
|
3
3
|
app: HyperAppMetadata & {
|
|
4
|
-
target:
|
|
4
|
+
target: object;
|
|
5
5
|
fullPath: string;
|
|
6
6
|
};
|
|
7
7
|
modules: Record<string, ModuleNode>;
|
|
8
8
|
paths: Record<string, RouteNode[]>;
|
|
9
|
-
openapi?:
|
|
9
|
+
openapi?: Record<string, unknown>;
|
|
10
10
|
}
|
|
11
11
|
export interface ModuleNode {
|
|
12
12
|
metadata: HyperModuleMetadata;
|
|
13
|
-
target:
|
|
13
|
+
target: object;
|
|
14
14
|
fullPath: string;
|
|
15
15
|
modules: Record<string, ModuleNode>;
|
|
16
16
|
controllers: Record<string, ControllerNode>;
|
|
17
|
-
services:
|
|
18
|
-
openapi?:
|
|
17
|
+
services: ImportType[];
|
|
18
|
+
openapi?: Record<string, unknown>;
|
|
19
19
|
}
|
|
20
20
|
export interface ControllerNode {
|
|
21
21
|
metadata: HyperControllerMetadata;
|
|
22
|
-
target:
|
|
22
|
+
target: object;
|
|
23
23
|
fullPath: string;
|
|
24
24
|
routes: RouteNode[];
|
|
25
|
-
services:
|
|
26
|
-
openapi?:
|
|
25
|
+
services: ImportType[];
|
|
26
|
+
openapi?: Record<string, unknown>;
|
|
27
27
|
}
|
|
28
28
|
export interface RouteNode extends RouteMetadata {
|
|
29
29
|
fullPath: string;
|
|
30
|
-
params:
|
|
31
|
-
openapi?:
|
|
30
|
+
params: HyperParameterMetadata['params'];
|
|
31
|
+
openapi?: Record<string, unknown>;
|
|
32
32
|
}
|
|
33
33
|
/**
|
|
34
34
|
* Extracts the complete application metadata tree.
|
|
35
35
|
*/
|
|
36
|
-
export declare function getAppTree(Target:
|
|
36
|
+
export declare function getAppTree(Target: Constructor): AppTree;
|