@zenofolio/hyper-decor 1.0.4 → 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 +107 -142
- package/dist/__internals/constants.d.ts +1 -58
- package/dist/__internals/constants.js +3 -65
- 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.d.ts +2 -3
- package/dist/__internals/helpers/merge-metadata.js +43 -23
- package/dist/__internals/helpers/prepare.helper.d.ts +5 -0
- package/dist/__internals/helpers/prepare.helper.js +392 -0
- 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 -15
- package/dist/__internals/stores/index.js +18 -35
- package/dist/__internals/stores/meta.store.d.ts +34 -0
- package/dist/__internals/stores/meta.store.js +107 -0
- package/dist/__internals/stores/scope.store.d.ts +14 -0
- package/dist/__internals/stores/scope.store.js +29 -0
- package/dist/__internals/stores/serivces.store.d.ts +1 -0
- package/dist/__internals/stores/{store.interface.js → serivces.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.d.ts +1 -1
- package/dist/__internals/transform/role.transform.js +10 -7
- package/dist/__internals/transform/scope.transfrom.d.ts +5 -7
- package/dist/__internals/transform/scope.transfrom.js +53 -39
- package/dist/__internals/transform/transform.registry.d.ts +33 -0
- package/dist/__internals/transform/transform.registry.js +59 -0
- package/dist/__internals/types.d.ts +53 -4
- package/dist/__internals/utils/function.util.d.ts +1 -4
- package/dist/__internals/utils/function.util.js +22 -10
- package/dist/common/bootstrap.d.ts +6 -2
- package/dist/common/bootstrap.js +51 -8
- 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/testing.d.ts +56 -0
- package/dist/common/testing.js +193 -0
- package/dist/common/transport.d.ts +10 -0
- package/dist/common/transport.js +59 -0
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +2 -1
- package/dist/decorators.d.ts +1 -0
- package/dist/{common/openapi/index.js → decorators.js} +1 -2
- package/dist/extension.js +11 -2
- package/dist/index.d.ts +11 -3
- package/dist/index.js +11 -3
- 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 -0
- package/dist/lib/openapi/collectors/class.collector.js +10 -0
- package/dist/lib/openapi/collectors/index.d.ts +3 -0
- package/dist/lib/openapi/collectors/index.js +19 -0
- package/dist/lib/openapi/collectors/method.collector.d.ts +7 -0
- package/dist/lib/openapi/collectors/method.collector.js +101 -0
- package/dist/lib/openapi/collectors/schema.collector.d.ts +6 -0
- package/dist/lib/openapi/collectors/schema.collector.js +29 -0
- package/dist/lib/openapi/constants.d.ts +47 -0
- package/dist/lib/openapi/constants.js +61 -0
- package/dist/lib/openapi/decorators.d.ts +16 -0
- package/dist/lib/openapi/decorators.js +93 -0
- package/dist/lib/openapi/index.d.ts +30 -0
- package/dist/lib/openapi/index.js +136 -0
- 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 +29 -0
- package/dist/lib/openapi/metadata.registry.js +41 -0
- package/dist/lib/openapi/types.d.ts +131 -0
- 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/lib/server/decorators/Middleware.d.ts +18 -0
- 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 +9 -4
- package/dist/{decorators → lib/server/decorators}/index.js +9 -4
- package/dist/lib/server/decorators/metadata.d.ts +1 -0
- package/dist/lib/server/decorators/metadata.js +5 -0
- package/dist/lib/server/decorators/types.d.ts +125 -0
- package/dist/lib/server/decorators/types.js +6 -0
- 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/lib/tree/tree.d.ts +36 -0
- package/dist/lib/tree/tree.js +106 -0
- package/dist/type.d.ts +13 -2
- package/hyper-express-decorators.d.ts +1 -0
- package/package.json +81 -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/.mocharc.js +0 -5
- package/dist/__internals/creators/request.creator.d.ts +0 -12
- package/dist/__internals/creators/request.creator.js +0 -53
- package/dist/__internals/creators/routes.creator.d.ts +0 -10
- package/dist/__internals/creators/routes.creator.js +0 -37
- package/dist/__internals/decorator-base.d.ts +0 -30
- package/dist/__internals/decorator-base.js +0 -86
- 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/transform/pass.transfrom.js +0 -2
- 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/decorators/File.d.ts +0 -65
- package/dist/decorators/Http.d.ts +0 -55
- package/dist/decorators/Http.js +0 -93
- package/dist/decorators/HyperApp.d.ts +0 -7
- package/dist/decorators/HyperApp.js +0 -262
- package/dist/decorators/HyperController.d.ts +0 -2
- package/dist/decorators/HyperController.js +0 -19
- package/dist/decorators/HyperModule.d.ts +0 -5
- package/dist/decorators/HyperModule.js +0 -14
- package/dist/decorators/Middleware.d.ts +0 -24
- package/dist/decorators/Middleware.js +0 -51
- package/dist/decorators/Pass.d.ts +0 -12
- package/dist/decorators/Pass.js +0 -29
- package/dist/decorators/Role.d.ts +0 -6
- package/dist/decorators/Role.js +0 -34
- package/dist/decorators/Routes.d.ts +0 -14
- 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/types.d.ts +0 -89
- /package/dist/{decorators → lib/openapi}/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
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Request, Response } from "hyper-express";
|
|
2
|
-
export type ByPassKeys = "req" | "res";
|
|
3
|
-
export type IParamsResolver = (req: Request, res: Response) => any | Promise<any>;
|
|
4
|
-
export type IStoreParams = {
|
|
5
|
-
name: string;
|
|
6
|
-
type: any;
|
|
7
|
-
index: number;
|
|
8
|
-
key: string;
|
|
9
|
-
propertyKey: string;
|
|
10
|
-
resolver: IParamsResolver;
|
|
11
|
-
};
|
|
12
|
-
export type IStoreParamsMap = Map<string, IStoreParams>;
|
|
13
|
-
export declare const paramsStore: Readonly<{
|
|
14
|
-
has(target: any, propety: any, key: string): boolean;
|
|
15
|
-
get(target: any, propety?: any): IStoreParamsMap | undefined;
|
|
16
|
-
set(target: any, propety: any, value: IStoreParams): void;
|
|
17
|
-
delete(target: any, propety: any): void;
|
|
18
|
-
support(target: any, propety: any): boolean;
|
|
19
|
-
prepareArgs(target: any, propety: any, req: Request, res: Response): Promise<any[]>;
|
|
20
|
-
intercept(target: any, propety: any, req: Request, res: Response): Promise<void>;
|
|
21
|
-
}>;
|
|
@@ -1,65 +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.paramsStore = void 0;
|
|
13
|
-
const no_conflict_1 = require("reflect-metadata/no-conflict");
|
|
14
|
-
const constants_1 = require("../constants");
|
|
15
|
-
exports.paramsStore = Object.freeze({
|
|
16
|
-
has(target, propety, key) {
|
|
17
|
-
const data = this.get(target, propety);
|
|
18
|
-
return data ? data.has(key) : false;
|
|
19
|
-
},
|
|
20
|
-
get(target, propety) {
|
|
21
|
-
if (!propety) {
|
|
22
|
-
return (0, no_conflict_1.getMetadata)(constants_1.KEY_PARAMS_PARAM, target);
|
|
23
|
-
}
|
|
24
|
-
return (0, no_conflict_1.getMetadata)(constants_1.KEY_PARAMS_PARAM, target, propety);
|
|
25
|
-
},
|
|
26
|
-
set(target, propety, value) {
|
|
27
|
-
const data = this.get(target, propety) || new Map();
|
|
28
|
-
data.set(value.key, value);
|
|
29
|
-
(0, no_conflict_1.defineMetadata)(constants_1.KEY_PARAMS_PARAM, data, target, propety);
|
|
30
|
-
},
|
|
31
|
-
delete(target, propety) {
|
|
32
|
-
(0, no_conflict_1.deleteMetadata)(constants_1.KEY_PARAMS_PARAM, target, propety);
|
|
33
|
-
},
|
|
34
|
-
support(target, propety) {
|
|
35
|
-
const params = (0, no_conflict_1.getMetadata)(constants_1.DESIGN_PARAMTYPES, target, propety) || [];
|
|
36
|
-
return params.length > 0;
|
|
37
|
-
},
|
|
38
|
-
prepareArgs(target, propety, req, res) {
|
|
39
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
-
const data = this.get(target, propety);
|
|
41
|
-
if (!data)
|
|
42
|
-
return [];
|
|
43
|
-
const args = [];
|
|
44
|
-
yield Promise.all(Array.from(data.values()).map((value) => __awaiter(this, void 0, void 0, function* () {
|
|
45
|
-
const { key, resolver } = value;
|
|
46
|
-
switch (key) {
|
|
47
|
-
case "req":
|
|
48
|
-
args[value.index] = req;
|
|
49
|
-
break;
|
|
50
|
-
case "res":
|
|
51
|
-
args[value.index] = res;
|
|
52
|
-
break;
|
|
53
|
-
default: {
|
|
54
|
-
const result = yield resolver(req, res);
|
|
55
|
-
args[value.index] = result;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
})));
|
|
59
|
-
return args;
|
|
60
|
-
});
|
|
61
|
-
},
|
|
62
|
-
intercept(target, propety, req, res) {
|
|
63
|
-
return __awaiter(this, void 0, void 0, function* () { });
|
|
64
|
-
},
|
|
65
|
-
});
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { IStore } from "./store.interface";
|
|
2
|
-
interface IRoute {
|
|
3
|
-
className: string;
|
|
4
|
-
method: string;
|
|
5
|
-
path: string;
|
|
6
|
-
handler: (...args: any[]) => any;
|
|
7
|
-
}
|
|
8
|
-
export declare class RouteStore implements IStore<any> {
|
|
9
|
-
has(target: any, property?: any): boolean;
|
|
10
|
-
get(target: any, property?: any): Set<IRoute> | undefined;
|
|
11
|
-
set(target: any, property: any, value: IRoute): void;
|
|
12
|
-
create(target: any, property?: any, key?: any): Set<IRoute> | null;
|
|
13
|
-
delete(target: any, value?: IRoute): void;
|
|
14
|
-
support(target: any, property: any): boolean;
|
|
15
|
-
}
|
|
16
|
-
declare const routeStore: RouteStore;
|
|
17
|
-
export { routeStore };
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.routeStore = exports.RouteStore = void 0;
|
|
4
|
-
const no_conflict_1 = require("reflect-metadata/no-conflict");
|
|
5
|
-
const constants_1 = require("../constants");
|
|
6
|
-
class RouteStore {
|
|
7
|
-
has(target, property) {
|
|
8
|
-
return (0, no_conflict_1.hasMetadata)(constants_1.METADATA_KEYS.ROUTES, target);
|
|
9
|
-
}
|
|
10
|
-
get(target, property) {
|
|
11
|
-
return (0, no_conflict_1.getMetadata)(constants_1.METADATA_KEYS.ROUTES, target);
|
|
12
|
-
}
|
|
13
|
-
set(target, property, value) {
|
|
14
|
-
const routes = this.get(target) || new Set();
|
|
15
|
-
routes.add(value);
|
|
16
|
-
(0, no_conflict_1.defineMetadata)(constants_1.METADATA_KEYS.ROUTES, routes, target);
|
|
17
|
-
}
|
|
18
|
-
create(target, property, key) {
|
|
19
|
-
const data = this.has(target, property)
|
|
20
|
-
? this.get(target, property)
|
|
21
|
-
: new Set();
|
|
22
|
-
(0, no_conflict_1.defineMetadata)(constants_1.METADATA_KEYS.ROUTES, data, target);
|
|
23
|
-
return data;
|
|
24
|
-
}
|
|
25
|
-
delete(target, value) {
|
|
26
|
-
const routes = this.create(target, value === null || value === void 0 ? void 0 : value.className);
|
|
27
|
-
if (!routes)
|
|
28
|
-
return;
|
|
29
|
-
if (value) {
|
|
30
|
-
routes.delete(value);
|
|
31
|
-
(0, no_conflict_1.defineMetadata)(constants_1.METADATA_KEYS.ROUTES, routes, target);
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
(0, no_conflict_1.deleteMetadata)(constants_1.METADATA_KEYS.ROUTES, target);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
support(target, property) {
|
|
38
|
-
return this.has(target, property);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
exports.RouteStore = RouteStore;
|
|
42
|
-
const routeStore = new RouteStore();
|
|
43
|
-
exports.routeStore = routeStore;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export interface IStore<T> {
|
|
2
|
-
has(target: any, property: any): boolean;
|
|
3
|
-
get(target: any, property: any): T | undefined;
|
|
4
|
-
set(target: any, property: any, value: T): void;
|
|
5
|
-
create(target: any, property: any, extra?: Partial<T>): T | null;
|
|
6
|
-
delete(target: any, property?: any): void;
|
|
7
|
-
support(target: any, property: any): boolean;
|
|
8
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = methodTransformer;
|
|
4
|
-
require("reflect-metadata");
|
|
5
|
-
function methodTransformer(target, key, transfrom) {
|
|
6
|
-
const prototype = target.constructor.prototype;
|
|
7
|
-
if (!prototype || prototype.__transformed)
|
|
8
|
-
return;
|
|
9
|
-
prototype.__transformed = true;
|
|
10
|
-
const original = Reflect.getOwnMetadata(key, target);
|
|
11
|
-
if (!(original === null || original === void 0 ? void 0 : original.value))
|
|
12
|
-
return;
|
|
13
|
-
console.log(original, "original");
|
|
14
|
-
original.value = function (...args) {
|
|
15
|
-
console.log("Before method call", args);
|
|
16
|
-
};
|
|
17
|
-
// const descriptor = Object.getOwnPropertyDescriptor(prototype, key);
|
|
18
|
-
// if(!descriptor) return;
|
|
19
|
-
// console.log(descriptor, "descriptor");
|
|
20
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import "reflect-metadata";
|
|
2
|
-
type Constructor<T = any> = new (...args: any[]) => T;
|
|
3
|
-
export declare class MixinBuilder<TClass extends Constructor<any>, Type = InstanceType<TClass>> {
|
|
4
|
-
private __class;
|
|
5
|
-
constructor(__class: TClass);
|
|
6
|
-
mix<NClass extends Constructor<any>>(clazz: NClass): MixinBuilder<NClass & TClass>;
|
|
7
|
-
build(): TClass;
|
|
8
|
-
construct(...args: any[]): Type;
|
|
9
|
-
static mix<NClass extends Constructor<any>>(clazz: NClass): MixinBuilder<NClass, InstanceType<NClass>>;
|
|
10
|
-
}
|
|
11
|
-
export {};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MixinBuilder = void 0;
|
|
4
|
-
require("reflect-metadata");
|
|
5
|
-
class MixinBuilder {
|
|
6
|
-
constructor(__class) {
|
|
7
|
-
this.__class = __class;
|
|
8
|
-
}
|
|
9
|
-
mix(clazz) {
|
|
10
|
-
return new MixinBuilder(Mix(this.__class, clazz));
|
|
11
|
-
}
|
|
12
|
-
build() {
|
|
13
|
-
return this.__class;
|
|
14
|
-
}
|
|
15
|
-
construct(...args) {
|
|
16
|
-
return new this.__class(...args);
|
|
17
|
-
}
|
|
18
|
-
////////////////////////////
|
|
19
|
-
/// Static methods
|
|
20
|
-
////////////////////////////
|
|
21
|
-
static mix(clazz) {
|
|
22
|
-
return new MixinBuilder(clazz);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
exports.MixinBuilder = MixinBuilder;
|
|
26
|
-
const Mix = (a, b) => {
|
|
27
|
-
return class extends a {
|
|
28
|
-
constructor(...args) {
|
|
29
|
-
super(...args);
|
|
30
|
-
Object.assign(this, new b(...args));
|
|
31
|
-
console.log(a);
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import "reflect-metadata";
|
|
2
|
-
/**
|
|
3
|
-
* Options to customize class metadata extraction.
|
|
4
|
-
*/
|
|
5
|
-
interface ClassDataOptions {
|
|
6
|
-
includePrivateMethods?: boolean;
|
|
7
|
-
methodOptions?: Record<string, any>;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Extracts metadata from a class, including methods and OpenAPI data.
|
|
11
|
-
*
|
|
12
|
-
* @param Target - The class constructor.
|
|
13
|
-
* @param options - Options for metadata extraction.
|
|
14
|
-
* @returns Object containing class metadata and method details.
|
|
15
|
-
*/
|
|
16
|
-
export declare function collectClassData(Target: new (...args: any[]) => any, options?: ClassDataOptions): {
|
|
17
|
-
className: string;
|
|
18
|
-
methods: Record<string, any>;
|
|
19
|
-
staticMethods: Record<string, any>;
|
|
20
|
-
};
|
|
21
|
-
export {};
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.collectClassData = collectClassData;
|
|
4
|
-
require("reflect-metadata");
|
|
5
|
-
const collect_function_data_1 = require("./collect-function-data");
|
|
6
|
-
/**
|
|
7
|
-
* Extracts metadata from a class, including methods and OpenAPI data.
|
|
8
|
-
*
|
|
9
|
-
* @param Target - The class constructor.
|
|
10
|
-
* @param options - Options for metadata extraction.
|
|
11
|
-
* @returns Object containing class metadata and method details.
|
|
12
|
-
*/
|
|
13
|
-
function collectClassData(Target, options = {}) {
|
|
14
|
-
if (typeof Target !== "function") {
|
|
15
|
-
throw new Error("Target must be a class constructor.");
|
|
16
|
-
}
|
|
17
|
-
const prototype = Target.prototype;
|
|
18
|
-
const className = Target.name;
|
|
19
|
-
// Get method names
|
|
20
|
-
const allMethods = Object.getOwnPropertyNames(prototype).filter((name) => typeof prototype[name] === "function" && name !== "constructor");
|
|
21
|
-
// Get static methods
|
|
22
|
-
const staticMethods = Object.getOwnPropertyNames(Target).filter((name) => typeof Target[name] === "function");
|
|
23
|
-
// Filter private methods (if not included)
|
|
24
|
-
const isPrivate = (name) => name.startsWith("_");
|
|
25
|
-
const methods = options.includePrivateMethods
|
|
26
|
-
? allMethods
|
|
27
|
-
: allMethods.filter((m) => !isPrivate(m));
|
|
28
|
-
// Extract metadata for each method
|
|
29
|
-
const methodsData = methods.reduce((acc, methodName) => {
|
|
30
|
-
var _a;
|
|
31
|
-
acc[methodName] = (0, collect_function_data_1.collectFunctionData)(prototype[methodName], ((_a = options.methodOptions) === null || _a === void 0 ? void 0 : _a[methodName]) || {});
|
|
32
|
-
return acc;
|
|
33
|
-
}, {});
|
|
34
|
-
// Extract metadata for static methods
|
|
35
|
-
const staticMethodsData = staticMethods.reduce((acc, methodName) => {
|
|
36
|
-
var _a;
|
|
37
|
-
acc[methodName] = (0, collect_function_data_1.collectFunctionData)(Target[methodName], ((_a = options.methodOptions) === null || _a === void 0 ? void 0 : _a[methodName]) || {});
|
|
38
|
-
return acc;
|
|
39
|
-
}, {});
|
|
40
|
-
return {
|
|
41
|
-
className,
|
|
42
|
-
methods: methodsData,
|
|
43
|
-
staticMethods: staticMethodsData,
|
|
44
|
-
};
|
|
45
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
type OpenAPIParamLocation = "query" | "path" | "body";
|
|
2
|
-
type OpenAPIType = "string" | "number" | "boolean" | "object" | "array" | "any";
|
|
3
|
-
/**
|
|
4
|
-
* Options to customize OpenAPI metadata extraction.
|
|
5
|
-
*/
|
|
6
|
-
interface FunctionDataOptions {
|
|
7
|
-
paramLocation?: OpenAPIParamLocation;
|
|
8
|
-
paramDescriptions?: Record<string, string>;
|
|
9
|
-
responseDescriptions?: Record<number, string>;
|
|
10
|
-
responseSchemas?: Record<number, any>;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Extracts function metadata and adapts it for OpenAPI documentation.
|
|
14
|
-
*
|
|
15
|
-
* @param Target - The function to analyze.
|
|
16
|
-
* @param options - Customization options for OpenAPI extraction.
|
|
17
|
-
* @returns An object formatted for OpenAPI documentation.
|
|
18
|
-
*/
|
|
19
|
-
export declare function collectFunctionData(Target: (...args: any[]) => any, options?: FunctionDataOptions): {
|
|
20
|
-
operationId: string;
|
|
21
|
-
parameters: {
|
|
22
|
-
name: string;
|
|
23
|
-
in: OpenAPIParamLocation;
|
|
24
|
-
required: boolean;
|
|
25
|
-
description: string;
|
|
26
|
-
schema: {
|
|
27
|
-
type: OpenAPIType;
|
|
28
|
-
};
|
|
29
|
-
}[];
|
|
30
|
-
responses: Record<number, any>;
|
|
31
|
-
};
|
|
32
|
-
export {};
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.collectFunctionData = collectFunctionData;
|
|
4
|
-
const constants_1 = require("../../__internals/constants");
|
|
5
|
-
const function_util_1 = require("../../__internals/utils/function.util");
|
|
6
|
-
/**
|
|
7
|
-
* Maps TypeScript types to OpenAPI-compatible types.
|
|
8
|
-
*/
|
|
9
|
-
const mapTypeToOpenAPI = (type) => {
|
|
10
|
-
if (!type)
|
|
11
|
-
return "any";
|
|
12
|
-
const typeMap = {
|
|
13
|
-
String: "string",
|
|
14
|
-
Number: "number",
|
|
15
|
-
Boolean: "boolean",
|
|
16
|
-
Object: "object",
|
|
17
|
-
Array: "array",
|
|
18
|
-
};
|
|
19
|
-
return type.name === "Array" ? "array" : typeMap[type.name] || "any";
|
|
20
|
-
};
|
|
21
|
-
/**
|
|
22
|
-
* Formats the response schema for OpenAPI.
|
|
23
|
-
*/
|
|
24
|
-
const formatResponseSchema = (type, description = "Successful response") => ({
|
|
25
|
-
description,
|
|
26
|
-
content: {
|
|
27
|
-
"application/json": {
|
|
28
|
-
schema: { type: mapTypeToOpenAPI(type) },
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
});
|
|
32
|
-
/**
|
|
33
|
-
* Extracts function metadata and adapts it for OpenAPI documentation.
|
|
34
|
-
*
|
|
35
|
-
* @param Target - The function to analyze.
|
|
36
|
-
* @param options - Customization options for OpenAPI extraction.
|
|
37
|
-
* @returns An object formatted for OpenAPI documentation.
|
|
38
|
-
*/
|
|
39
|
-
function collectFunctionData(Target, options = {}) {
|
|
40
|
-
var _a;
|
|
41
|
-
if (typeof Target !== "function") {
|
|
42
|
-
throw new Error("Target must be a function.");
|
|
43
|
-
}
|
|
44
|
-
// Extract metadata
|
|
45
|
-
const paramTypes = Reflect.getMetadata(constants_1.DESIGN_PARAMTYPES, Target) || [];
|
|
46
|
-
const paramNames = (_a = (0, function_util_1.extreactArgsNames)(Target)) !== null && _a !== void 0 ? _a : [];
|
|
47
|
-
const returnType = Reflect.getMetadata(constants_1.DESIGN_RETURNTYPE, Target);
|
|
48
|
-
// Default locations and descriptions
|
|
49
|
-
const { paramLocation = "query", paramDescriptions = {}, responseDescriptions = { 200: "Successful response" }, responseSchemas = {}, } = options;
|
|
50
|
-
// Build OpenAPI parameters
|
|
51
|
-
const parameters = paramNames.map((name, index) => ({
|
|
52
|
-
name,
|
|
53
|
-
in: paramLocation,
|
|
54
|
-
required: true,
|
|
55
|
-
description: paramDescriptions[name] || `Parameter ${name}`,
|
|
56
|
-
schema: { type: mapTypeToOpenAPI(paramTypes[index]) },
|
|
57
|
-
}));
|
|
58
|
-
// Build OpenAPI responses
|
|
59
|
-
const responses = {};
|
|
60
|
-
Object.entries(responseDescriptions).forEach(([statusCode, description]) => {
|
|
61
|
-
const code = Number(statusCode);
|
|
62
|
-
responses[code] =
|
|
63
|
-
responseSchemas[code] || formatResponseSchema(returnType, description);
|
|
64
|
-
});
|
|
65
|
-
return {
|
|
66
|
-
operationId: Target.name || "anonymous",
|
|
67
|
-
parameters,
|
|
68
|
-
responses,
|
|
69
|
-
};
|
|
70
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { Request } from "hyper-express";
|
|
2
|
-
/**
|
|
3
|
-
* File upload restrictions
|
|
4
|
-
*
|
|
5
|
-
* @param allowedMimeTypes Allowed MIME types
|
|
6
|
-
* @param maxFileSize Maximum file size in bytes
|
|
7
|
-
*
|
|
8
|
-
*/
|
|
9
|
-
export interface FileUplopadRestrictions {
|
|
10
|
-
allowedMimeTypes: string[];
|
|
11
|
-
maxFileSize: number;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* File restrictions resolver
|
|
15
|
-
*
|
|
16
|
-
* @param request Request object
|
|
17
|
-
* @returns File restrictions
|
|
18
|
-
*
|
|
19
|
-
*/
|
|
20
|
-
export type FileRestrictions = FileUplopadRestrictions | ((request: Request) => FileUplopadRestrictions | Promise<FileUplopadRestrictions>);
|
|
21
|
-
/**
|
|
22
|
-
* File decorator options
|
|
23
|
-
*
|
|
24
|
-
* @param fieldName Field name to extract from the request
|
|
25
|
-
* @param restrictions File restrictions
|
|
26
|
-
* @param required If the file is required
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*/
|
|
30
|
-
export interface FileOptions {
|
|
31
|
-
fieldName: string | string[];
|
|
32
|
-
restrictions?: FileRestrictions;
|
|
33
|
-
required?: boolean;
|
|
34
|
-
}
|
|
35
|
-
export interface UploadedFile {
|
|
36
|
-
name: string;
|
|
37
|
-
filename: string;
|
|
38
|
-
mimeType: string;
|
|
39
|
-
size: number;
|
|
40
|
-
ext: string;
|
|
41
|
-
buffer: Buffer;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Decorator to extract file from the request
|
|
45
|
-
*
|
|
46
|
-
* @param param0
|
|
47
|
-
*/
|
|
48
|
-
export declare const File: {
|
|
49
|
-
(options: FileOptions | string): ParameterDecorator;
|
|
50
|
-
/**
|
|
51
|
-
*
|
|
52
|
-
* Helper function to create a file decorator with options
|
|
53
|
-
*
|
|
54
|
-
* @param options
|
|
55
|
-
* @returns
|
|
56
|
-
*/
|
|
57
|
-
options(options: FileOptions, required?: boolean): (fieldName: string | string[]) => ParameterDecorator;
|
|
58
|
-
/**
|
|
59
|
-
* Helper function to create a file decorator with restrictions
|
|
60
|
-
*
|
|
61
|
-
* @param restrictions
|
|
62
|
-
* @returns
|
|
63
|
-
*/
|
|
64
|
-
restrictions(restrictions: FileRestrictions): (fieldName: string | string[], required?: boolean) => ParameterDecorator;
|
|
65
|
-
};
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { ParameterResolver } from "./types";
|
|
2
|
-
/**
|
|
3
|
-
* Get the value of a key from the request object
|
|
4
|
-
*
|
|
5
|
-
* @param key
|
|
6
|
-
* @returns
|
|
7
|
-
*/
|
|
8
|
-
export declare const Query: (key?: string, transfrom?: (data: any) => any) => ParameterDecorator;
|
|
9
|
-
/**
|
|
10
|
-
* Get the body of the request
|
|
11
|
-
*
|
|
12
|
-
* @param resolver
|
|
13
|
-
* @returns
|
|
14
|
-
*/
|
|
15
|
-
export declare const Body: <T, R>(resolver?: (data: T) => R) => ParameterDecorator;
|
|
16
|
-
/**
|
|
17
|
-
* Get the params from the request
|
|
18
|
-
*
|
|
19
|
-
* @param k
|
|
20
|
-
* @returns
|
|
21
|
-
*/
|
|
22
|
-
export declare const Param: (k?: string, validator?: (data: any) => any) => ParameterDecorator;
|
|
23
|
-
/**
|
|
24
|
-
* get the headers from the request
|
|
25
|
-
*
|
|
26
|
-
* @param key
|
|
27
|
-
* @returns
|
|
28
|
-
*/
|
|
29
|
-
export declare const Headers: <T extends string>(key?: T) => ParameterDecorator;
|
|
30
|
-
export declare const Req: () => ParameterDecorator;
|
|
31
|
-
export declare const Res: () => ParameterDecorator;
|
|
32
|
-
/**
|
|
33
|
-
* Create a custom request decorator
|
|
34
|
-
* that can be used to extract data from the request object
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
* ```typescript
|
|
39
|
-
*
|
|
40
|
-
* interface LoginData {
|
|
41
|
-
* username: string;
|
|
42
|
-
* password: string;
|
|
43
|
-
* }
|
|
44
|
-
*
|
|
45
|
-
* const LoginData = createCustomRequestDecorator<LoginData>({
|
|
46
|
-
* resolver: async (request) => {
|
|
47
|
-
* const data = await request.json();
|
|
48
|
-
* return [data];
|
|
49
|
-
* }
|
|
50
|
-
* }
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*/
|
|
55
|
-
export declare const createCustomRequestDecorator: (decoratorName: string, resolver: ParameterResolver) => ParameterDecorator;
|
package/dist/decorators/Http.js
DELETED
|
@@ -1,93 +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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.createCustomRequestDecorator = exports.Res = exports.Req = exports.Headers = exports.Param = exports.Body = exports.Query = void 0;
|
|
16
|
-
const request_creator_1 = __importDefault(require("../__internals/creators/request.creator"));
|
|
17
|
-
const object_util_1 = require("../__internals/utils/object.util");
|
|
18
|
-
/**
|
|
19
|
-
* Get the value of a key from the request object
|
|
20
|
-
*
|
|
21
|
-
* @param key
|
|
22
|
-
* @returns
|
|
23
|
-
*/
|
|
24
|
-
const Query = (key, transfrom) => (0, request_creator_1.default)("query", "Query", (request) => {
|
|
25
|
-
const value = (0, object_util_1.$get)(request.query, key, request.query);
|
|
26
|
-
if (!transfrom)
|
|
27
|
-
return value;
|
|
28
|
-
return value;
|
|
29
|
-
});
|
|
30
|
-
exports.Query = Query;
|
|
31
|
-
/**
|
|
32
|
-
* Get the body of the request
|
|
33
|
-
*
|
|
34
|
-
* @param resolver
|
|
35
|
-
* @returns
|
|
36
|
-
*/
|
|
37
|
-
const Body = (resolver) => (0, request_creator_1.default)("req", "BODY", (request) => __awaiter(void 0, void 0, void 0, function* () {
|
|
38
|
-
const value = yield request.json();
|
|
39
|
-
return resolver ? resolver(value) : value;
|
|
40
|
-
}));
|
|
41
|
-
exports.Body = Body;
|
|
42
|
-
/**
|
|
43
|
-
* Get the params from the request
|
|
44
|
-
*
|
|
45
|
-
* @param k
|
|
46
|
-
* @returns
|
|
47
|
-
*/
|
|
48
|
-
const Param = (k, validator) => (0, request_creator_1.default)("params", "Param", (req) => {
|
|
49
|
-
const value = (0, object_util_1.$get)(req.params, k, req.params);
|
|
50
|
-
if (typeof validator === "function")
|
|
51
|
-
return validator(value);
|
|
52
|
-
return value;
|
|
53
|
-
});
|
|
54
|
-
exports.Param = Param;
|
|
55
|
-
/**
|
|
56
|
-
* get the headers from the request
|
|
57
|
-
*
|
|
58
|
-
* @param key
|
|
59
|
-
* @returns
|
|
60
|
-
*/
|
|
61
|
-
const Headers = (key) => (0, request_creator_1.default)("headers", "Headers", (req) => (0, object_util_1.$get)(req.headers, key, req.headers));
|
|
62
|
-
exports.Headers = Headers;
|
|
63
|
-
const Req = () => (0, request_creator_1.default)("req", "Req", (req) => req);
|
|
64
|
-
exports.Req = Req;
|
|
65
|
-
const Res = () => (0, request_creator_1.default)("res", "Res", (req, res) => res);
|
|
66
|
-
exports.Res = Res;
|
|
67
|
-
/**
|
|
68
|
-
* Create a custom request decorator
|
|
69
|
-
* that can be used to extract data from the request object
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
* @example
|
|
73
|
-
* ```typescript
|
|
74
|
-
*
|
|
75
|
-
* interface LoginData {
|
|
76
|
-
* username: string;
|
|
77
|
-
* password: string;
|
|
78
|
-
* }
|
|
79
|
-
*
|
|
80
|
-
* const LoginData = createCustomRequestDecorator<LoginData>({
|
|
81
|
-
* resolver: async (request) => {
|
|
82
|
-
* const data = await request.json();
|
|
83
|
-
* return [data];
|
|
84
|
-
* }
|
|
85
|
-
* }
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*/
|
|
90
|
-
const createCustomRequestDecorator = (decoratorName, resolver) => {
|
|
91
|
-
return (0, request_creator_1.default)("req", decoratorName, resolver);
|
|
92
|
-
};
|
|
93
|
-
exports.createCustomRequestDecorator = createCustomRequestDecorator;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import "reflect-metadata";
|
|
2
|
-
import { HyperAppDecorator } from "./types";
|
|
3
|
-
/**
|
|
4
|
-
* Decorator to define the main application class with assigned modules.
|
|
5
|
-
* @param modules - List of modules to be used in the application.
|
|
6
|
-
*/
|
|
7
|
-
export declare const HyperApp: HyperAppDecorator;
|