@zenofolio/hyper-decor 1.0.71 → 1.0.73
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 +78 -207
- package/dist/__internals/constants.d.ts +1 -62
- package/dist/__internals/constants.js +3 -69
- package/dist/__internals/creators/request.creator.d.ts +1 -10
- package/dist/__internals/creators/request.creator.js +141 -23
- 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 +316 -283
- 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/__internals/stores/index.js +20 -0
- 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/serivces.store.js +4 -0
- 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 +44 -10
- 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/Http.d.ts +3 -43
- package/dist/decorators/Http.js +9 -103
- package/dist/decorators.d.ts +1 -0
- package/dist/decorators.js +17 -0
- package/dist/index.d.ts +6 -5
- package/dist/index.js +6 -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/lib/server/decorators/File.js +167 -0
- 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 +27 -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 +11 -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/lib/server/decorators/index.d.ts +16 -0
- package/dist/lib/server/decorators/index.js +32 -0
- 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/lib/server/exeptions/DuplicateControllerPathException.d.ts +14 -0
- package/dist/lib/server/exeptions/DuplicateControllerPathException.js +12 -0
- package/dist/lib/server/exeptions/DuplicatedException.d.ts +8 -0
- package/dist/lib/server/exeptions/DuplicatedException.js +12 -0
- package/dist/lib/server/exeptions/DuplicatedHandlerException.d.ts +4 -0
- package/dist/lib/server/exeptions/DuplicatedHandlerException.js +12 -0
- package/dist/lib/server/exeptions/HyperException.d.ts +8 -0
- package/dist/lib/server/exeptions/HyperException.js +14 -0
- package/dist/lib/server/exeptions/HyperFileException.d.ts +4 -0
- package/dist/lib/server/exeptions/HyperFileException.js +12 -0
- package/dist/lib/server/exeptions/MethodNotFountException.d.ts +4 -0
- package/dist/lib/server/exeptions/MethodNotFountException.js +12 -0
- package/dist/lib/server/exeptions/NotPropertyException.d.ts +6 -0
- package/dist/lib/server/exeptions/NotPropertyException.js +16 -0
- package/dist/lib/server/exeptions/NotRoleException.d.ts +6 -0
- package/dist/lib/server/exeptions/NotRoleException.js +17 -0
- package/dist/lib/server/exeptions/NotScopeException.d.ts +7 -0
- package/dist/lib/server/exeptions/NotScopeException.js +18 -0
- package/dist/lib/server/exeptions/WrongPlaceException.d.ts +8 -0
- package/dist/lib/server/exeptions/WrongPlaceException.js +21 -0
- package/dist/lib/server/exeptions/index.d.ts +8 -0
- package/dist/lib/server/exeptions/index.js +18 -0
- package/dist/lib/server/exeptions/types.d.ts +1 -0
- package/dist/lib/server/exeptions/types.js +2 -0
- package/dist/lib/tree/tree.d.ts +36 -0
- package/dist/lib/tree/tree.js +106 -0
- package/package.json +1 -1
- package/scripts/clean.js +55 -55
- package/scripts/test-server.ts +85 -85
- package/vitest.config.mjs +33 -30
- package/vitest.json +0 -0
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
const HyperException_1 = __importDefault(require("./HyperException"));
|
|
7
|
+
class NotRoleException extends HyperException_1.default {
|
|
8
|
+
constructor(message = `Has not Permission to access this resource`, roles = [], requiredRoles = []) {
|
|
9
|
+
super(message, "NotRoleException", {
|
|
10
|
+
roles,
|
|
11
|
+
requiredRoles,
|
|
12
|
+
}, 403);
|
|
13
|
+
this.roles = roles;
|
|
14
|
+
this.requiredRoles = requiredRoles;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.default = NotRoleException;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import HyperException from "./HyperException";
|
|
2
|
+
export default class NotScopeException extends HyperException {
|
|
3
|
+
message: string;
|
|
4
|
+
requestScopes: string[];
|
|
5
|
+
requiredScopes: string[];
|
|
6
|
+
constructor(message: string, requestScopes?: string[], requiredScopes?: string[]);
|
|
7
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
const HyperException_1 = __importDefault(require("./HyperException"));
|
|
7
|
+
class NotScopeException extends HyperException_1.default {
|
|
8
|
+
constructor(message, requestScopes = [], requiredScopes = []) {
|
|
9
|
+
super(message || `You don't have the required scopes to access this resource`, "NotScopeException", {
|
|
10
|
+
requestScopes,
|
|
11
|
+
requiredScopes,
|
|
12
|
+
}, 403);
|
|
13
|
+
this.message = message;
|
|
14
|
+
this.requestScopes = requestScopes;
|
|
15
|
+
this.requiredScopes = requiredScopes;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.default = NotScopeException;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import HyperException from "./HyperException";
|
|
2
|
+
export default class WrongPlaceException extends HyperException {
|
|
3
|
+
decorator: string;
|
|
4
|
+
as: string;
|
|
5
|
+
namespace: string;
|
|
6
|
+
target: any;
|
|
7
|
+
constructor(decorator: string, as: string, namespace: string, target: any);
|
|
8
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
const HyperException_1 = __importDefault(require("./HyperException"));
|
|
7
|
+
class WrongPlaceException extends HyperException_1.default {
|
|
8
|
+
constructor(decorator, as, namespace, target) {
|
|
9
|
+
super(`The decorator @${decorator} only can be used as a ${as} decorator. Error => ${namespace}`, "WrongPlaceException", {
|
|
10
|
+
decorator,
|
|
11
|
+
target,
|
|
12
|
+
namespace,
|
|
13
|
+
as,
|
|
14
|
+
});
|
|
15
|
+
this.decorator = decorator;
|
|
16
|
+
this.as = as;
|
|
17
|
+
this.namespace = namespace;
|
|
18
|
+
this.target = target;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.default = WrongPlaceException;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import DuplicatedHandlerException from "./DuplicatedHandlerException";
|
|
2
|
+
import DuplicateControllerPathException from "./DuplicateControllerPathException";
|
|
3
|
+
import HyperException from "./HyperException";
|
|
4
|
+
import MethodNotFountException from "./MethodNotFountException";
|
|
5
|
+
import NotRoleException from "./NotRoleException";
|
|
6
|
+
import NotScopeException from "./NotScopeException";
|
|
7
|
+
export type * from "./types";
|
|
8
|
+
export { DuplicatedHandlerException, DuplicateControllerPathException as DuplicatedRouterException, HyperException, NotRoleException, NotScopeException, MethodNotFountException as MethodNotExists, };
|
|
@@ -0,0 +1,18 @@
|
|
|
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.MethodNotExists = exports.NotScopeException = exports.NotRoleException = exports.HyperException = exports.DuplicatedRouterException = exports.DuplicatedHandlerException = void 0;
|
|
7
|
+
const DuplicatedHandlerException_1 = __importDefault(require("./DuplicatedHandlerException"));
|
|
8
|
+
exports.DuplicatedHandlerException = DuplicatedHandlerException_1.default;
|
|
9
|
+
const DuplicateControllerPathException_1 = __importDefault(require("./DuplicateControllerPathException"));
|
|
10
|
+
exports.DuplicatedRouterException = DuplicateControllerPathException_1.default;
|
|
11
|
+
const HyperException_1 = __importDefault(require("./HyperException"));
|
|
12
|
+
exports.HyperException = HyperException_1.default;
|
|
13
|
+
const MethodNotFountException_1 = __importDefault(require("./MethodNotFountException"));
|
|
14
|
+
exports.MethodNotExists = MethodNotFountException_1.default;
|
|
15
|
+
const NotRoleException_1 = __importDefault(require("./NotRoleException"));
|
|
16
|
+
exports.NotRoleException = NotRoleException_1.default;
|
|
17
|
+
const NotScopeException_1 = __importDefault(require("./NotScopeException"));
|
|
18
|
+
exports.NotScopeException = NotScopeException_1.default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type ExceptionType = "DuplicateControllerException" | "DuplicateHandlerException" | "DuplicateRouterException" | "HyperException" | "NotRoleException" | "NotScopeException" | "MethodNotFountException" | "DuplicateControllerPathException" | "DuplicateHandlerException" | "DuplicatedException" | "NotPropertyException" | "WrongPlaceException" | "HyperFileException" | "DpublicateModuleException";
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { HyperAppMetadata, HyperModuleMetadata, HyperControllerMetadata, HyperParameterMetadata, RouteMetadata, ImportType, Constructor } from "../server/decorators/types";
|
|
2
|
+
export interface AppTree {
|
|
3
|
+
app: HyperAppMetadata & {
|
|
4
|
+
target: object;
|
|
5
|
+
fullPath: string;
|
|
6
|
+
};
|
|
7
|
+
modules: Record<string, ModuleNode>;
|
|
8
|
+
paths: Record<string, RouteNode[]>;
|
|
9
|
+
openapi?: Record<string, unknown>;
|
|
10
|
+
}
|
|
11
|
+
export interface ModuleNode {
|
|
12
|
+
metadata: HyperModuleMetadata;
|
|
13
|
+
target: object;
|
|
14
|
+
fullPath: string;
|
|
15
|
+
modules: Record<string, ModuleNode>;
|
|
16
|
+
controllers: Record<string, ControllerNode>;
|
|
17
|
+
services: ImportType[];
|
|
18
|
+
openapi?: Record<string, unknown>;
|
|
19
|
+
}
|
|
20
|
+
export interface ControllerNode {
|
|
21
|
+
metadata: HyperControllerMetadata;
|
|
22
|
+
target: object;
|
|
23
|
+
fullPath: string;
|
|
24
|
+
routes: RouteNode[];
|
|
25
|
+
services: ImportType[];
|
|
26
|
+
openapi?: Record<string, unknown>;
|
|
27
|
+
}
|
|
28
|
+
export interface RouteNode extends RouteMetadata {
|
|
29
|
+
fullPath: string;
|
|
30
|
+
params: HyperParameterMetadata['params'];
|
|
31
|
+
openapi?: Record<string, unknown>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Extracts the complete application metadata tree.
|
|
35
|
+
*/
|
|
36
|
+
export declare function getAppTree(Target: Constructor): AppTree;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAppTree = getAppTree;
|
|
4
|
+
const meta_store_1 = require("../../__internals/stores/meta.store");
|
|
5
|
+
const metadata_1 = require("../openapi/metadata");
|
|
6
|
+
const path_util_1 = require("../../__internals/utils/path.util");
|
|
7
|
+
const metadata_registry_1 = require("../openapi/metadata.registry");
|
|
8
|
+
/**
|
|
9
|
+
* Extracts the complete application metadata tree.
|
|
10
|
+
*/
|
|
11
|
+
function getAppTree(Target) {
|
|
12
|
+
var _a;
|
|
13
|
+
const root = meta_store_1.Metadata.get(Target);
|
|
14
|
+
const common = (_a = root.server) === null || _a === void 0 ? void 0 : _a.common;
|
|
15
|
+
const prefix = (common === null || common === void 0 ? void 0 : common.prefix) || "/";
|
|
16
|
+
const tree = {
|
|
17
|
+
app: Object.assign(Object.assign({}, (common || {})), { target: Target, fullPath: prefix }),
|
|
18
|
+
modules: {},
|
|
19
|
+
paths: {}
|
|
20
|
+
};
|
|
21
|
+
const modules = (common === null || common === void 0 ? void 0 : common.modules) || [];
|
|
22
|
+
modules.forEach(m => {
|
|
23
|
+
const node = getModuleNode(m, prefix, tree.paths);
|
|
24
|
+
tree.modules[m.name] = node;
|
|
25
|
+
});
|
|
26
|
+
// Apply tree processors
|
|
27
|
+
metadata_registry_1.openApiRegistry.getProcessors().forEach(processor => processor(tree));
|
|
28
|
+
return tree;
|
|
29
|
+
}
|
|
30
|
+
function getModuleNode(Target, parentPath = "", globalPaths = {}) {
|
|
31
|
+
var _a;
|
|
32
|
+
const root = meta_store_1.Metadata.get(Target);
|
|
33
|
+
const common = (_a = root.server) === null || _a === void 0 ? void 0 : _a.common;
|
|
34
|
+
const currentPath = (0, path_util_1.join)(parentPath, (common === null || common === void 0 ? void 0 : common.path) || "");
|
|
35
|
+
const openapi = metadata_1.SwaggerMeta.get(Target); // Fixed: Metadata utility now returns root.common
|
|
36
|
+
// Execute custom collectors
|
|
37
|
+
metadata_registry_1.openApiRegistry.getCollectors("class").forEach(collector => {
|
|
38
|
+
const extra = collector(Target);
|
|
39
|
+
if (extra)
|
|
40
|
+
Object.assign(openapi, extra);
|
|
41
|
+
});
|
|
42
|
+
const node = {
|
|
43
|
+
metadata: common,
|
|
44
|
+
target: Target,
|
|
45
|
+
fullPath: currentPath,
|
|
46
|
+
modules: {},
|
|
47
|
+
controllers: {},
|
|
48
|
+
services: ((common === null || common === void 0 ? void 0 : common.imports) || []),
|
|
49
|
+
openapi: openapi
|
|
50
|
+
};
|
|
51
|
+
((common === null || common === void 0 ? void 0 : common.modules) || []).forEach(m => {
|
|
52
|
+
node.modules[m.name] = getModuleNode(m, currentPath, globalPaths);
|
|
53
|
+
});
|
|
54
|
+
((common === null || common === void 0 ? void 0 : common.controllers) || []).forEach(c => {
|
|
55
|
+
node.controllers[c.name] = getControllerNode(c, currentPath, globalPaths);
|
|
56
|
+
});
|
|
57
|
+
return node;
|
|
58
|
+
}
|
|
59
|
+
function getControllerNode(Target, parentPath = "", globalPaths = {}) {
|
|
60
|
+
var _a;
|
|
61
|
+
const root = meta_store_1.Metadata.get(Target);
|
|
62
|
+
const common = (_a = root.server) === null || _a === void 0 ? void 0 : _a.common;
|
|
63
|
+
const currentPath = (0, path_util_1.join)(parentPath, (common === null || common === void 0 ? void 0 : common.path) || "");
|
|
64
|
+
const openapi = metadata_1.SwaggerMeta.get(Target);
|
|
65
|
+
const server = root.server || { common: {}, methods: {} };
|
|
66
|
+
const methods = server.methods;
|
|
67
|
+
const routes = Object.keys(methods).map((propertyKey) => {
|
|
68
|
+
var _a;
|
|
69
|
+
const methodMeta = methods[propertyKey];
|
|
70
|
+
const route = methodMeta.route;
|
|
71
|
+
if (!route)
|
|
72
|
+
return null;
|
|
73
|
+
const params = ((_a = methodMeta.params) === null || _a === void 0 ? void 0 : _a.params) || [];
|
|
74
|
+
const fullPath = (0, path_util_1.join)(currentPath, route.path);
|
|
75
|
+
// Get OpenAPI metadata for the method
|
|
76
|
+
const methodOpenApi = (metadata_1.SwaggerMeta.get(Target, propertyKey) || {});
|
|
77
|
+
// Execute custom collectors
|
|
78
|
+
metadata_registry_1.openApiRegistry.getCollectors("method").forEach((collector) => {
|
|
79
|
+
const extra = collector(Target.prototype, propertyKey);
|
|
80
|
+
if (extra)
|
|
81
|
+
Object.assign(methodOpenApi, extra);
|
|
82
|
+
});
|
|
83
|
+
const routeNode = Object.assign(Object.assign({}, route), { fullPath,
|
|
84
|
+
params, openapi: methodOpenApi });
|
|
85
|
+
// Add to global paths map
|
|
86
|
+
if (!globalPaths[fullPath]) {
|
|
87
|
+
globalPaths[fullPath] = [];
|
|
88
|
+
}
|
|
89
|
+
globalPaths[fullPath].push(routeNode);
|
|
90
|
+
return routeNode;
|
|
91
|
+
}).filter(Boolean);
|
|
92
|
+
// Execute custom collectors
|
|
93
|
+
metadata_registry_1.openApiRegistry.getCollectors("class").forEach(collector => {
|
|
94
|
+
const extra = collector(Target);
|
|
95
|
+
if (extra)
|
|
96
|
+
Object.assign(openapi, extra);
|
|
97
|
+
});
|
|
98
|
+
return {
|
|
99
|
+
metadata: common,
|
|
100
|
+
target: Target,
|
|
101
|
+
fullPath: currentPath,
|
|
102
|
+
routes,
|
|
103
|
+
services: (common === null || common === void 0 ? void 0 : common.imports) || [],
|
|
104
|
+
openapi: openapi
|
|
105
|
+
};
|
|
106
|
+
}
|
package/package.json
CHANGED
package/scripts/clean.js
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
const fs = require('fs');
|
|
3
|
-
const path = require('path');
|
|
4
|
-
|
|
5
|
-
try {
|
|
6
|
-
// Resolve where uWebSockets.js is actually installed
|
|
7
|
-
const mainModuleFile = require.resolve('uWebSockets.js');
|
|
8
|
-
// Usually this points to the root directory where the files are
|
|
9
|
-
const uwsDir = path.dirname(mainModuleFile);
|
|
10
|
-
|
|
11
|
-
// Construct the expected binary name for THIS machine
|
|
12
|
-
const expectedBinary = 'uws_' + process.platform + '_' + process.arch + '_' + process.versions.modules + '.node';
|
|
13
|
-
|
|
14
|
-
console.log(`[HyperDecor] Analyzing uWebSockets.js native binaries...`);
|
|
15
|
-
console.log(`[HyperDecor] Target environment: ${process.platform} ${process.arch} (Node ABI ${process.versions.modules})`);
|
|
16
|
-
console.log(`[HyperDecor] Expected binary: ${expectedBinary}`);
|
|
17
|
-
|
|
18
|
-
const files = fs.readdirSync(uwsDir);
|
|
19
|
-
let deletedCount = 0;
|
|
20
|
-
let savedSpace = 0;
|
|
21
|
-
|
|
22
|
-
files.forEach((file) => {
|
|
23
|
-
// We only care about .node files
|
|
24
|
-
if (!file.endsWith('.node')) return;
|
|
25
|
-
|
|
26
|
-
// If it's NOT the exact binary we need, delete it
|
|
27
|
-
if (file !== expectedBinary) {
|
|
28
|
-
const filePath = path.join(uwsDir, file);
|
|
29
|
-
const stat = fs.statSync(filePath);
|
|
30
|
-
savedSpace += stat.size;
|
|
31
|
-
fs.unlinkSync(filePath);
|
|
32
|
-
deletedCount++;
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
if (deletedCount > 0) {
|
|
37
|
-
const mbSaved = (savedSpace / 1024 / 1024).toFixed(2);
|
|
38
|
-
console.log(`[HyperDecor] ✅ Cleaned up ${deletedCount} unused native binaries.`);
|
|
39
|
-
console.log(`[HyperDecor] 💾 Freed up ${mbSaved} MB of disk space in node_modules!`);
|
|
40
|
-
} else {
|
|
41
|
-
// Make sure the expected one actually exists
|
|
42
|
-
if (!fs.existsSync(path.join(uwsDir, expectedBinary))) {
|
|
43
|
-
console.warn(`[HyperDecor] ⚠️ The expected native binary (${expectedBinary}) was NOT found! uWebSockets.js might not work.`);
|
|
44
|
-
} else {
|
|
45
|
-
console.log(`[HyperDecor] ✨ No unnecessary binaries found. Everything is already optimized.`);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
} catch (err) {
|
|
50
|
-
if (err.code === 'MODULE_NOT_FOUND') {
|
|
51
|
-
console.error(`[HyperDecor] ❌ uWebSockets.js is not installed locally. Skipping cleanup.`);
|
|
52
|
-
} else {
|
|
53
|
-
console.error(`[HyperDecor] ❌ Error cleaning uWebSockets binaries:`, err.message);
|
|
54
|
-
}
|
|
55
|
-
process.exit(1);
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
|
|
5
|
+
try {
|
|
6
|
+
// Resolve where uWebSockets.js is actually installed
|
|
7
|
+
const mainModuleFile = require.resolve('uWebSockets.js');
|
|
8
|
+
// Usually this points to the root directory where the files are
|
|
9
|
+
const uwsDir = path.dirname(mainModuleFile);
|
|
10
|
+
|
|
11
|
+
// Construct the expected binary name for THIS machine
|
|
12
|
+
const expectedBinary = 'uws_' + process.platform + '_' + process.arch + '_' + process.versions.modules + '.node';
|
|
13
|
+
|
|
14
|
+
console.log(`[HyperDecor] Analyzing uWebSockets.js native binaries...`);
|
|
15
|
+
console.log(`[HyperDecor] Target environment: ${process.platform} ${process.arch} (Node ABI ${process.versions.modules})`);
|
|
16
|
+
console.log(`[HyperDecor] Expected binary: ${expectedBinary}`);
|
|
17
|
+
|
|
18
|
+
const files = fs.readdirSync(uwsDir);
|
|
19
|
+
let deletedCount = 0;
|
|
20
|
+
let savedSpace = 0;
|
|
21
|
+
|
|
22
|
+
files.forEach((file) => {
|
|
23
|
+
// We only care about .node files
|
|
24
|
+
if (!file.endsWith('.node')) return;
|
|
25
|
+
|
|
26
|
+
// If it's NOT the exact binary we need, delete it
|
|
27
|
+
if (file !== expectedBinary) {
|
|
28
|
+
const filePath = path.join(uwsDir, file);
|
|
29
|
+
const stat = fs.statSync(filePath);
|
|
30
|
+
savedSpace += stat.size;
|
|
31
|
+
fs.unlinkSync(filePath);
|
|
32
|
+
deletedCount++;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
if (deletedCount > 0) {
|
|
37
|
+
const mbSaved = (savedSpace / 1024 / 1024).toFixed(2);
|
|
38
|
+
console.log(`[HyperDecor] ✅ Cleaned up ${deletedCount} unused native binaries.`);
|
|
39
|
+
console.log(`[HyperDecor] 💾 Freed up ${mbSaved} MB of disk space in node_modules!`);
|
|
40
|
+
} else {
|
|
41
|
+
// Make sure the expected one actually exists
|
|
42
|
+
if (!fs.existsSync(path.join(uwsDir, expectedBinary))) {
|
|
43
|
+
console.warn(`[HyperDecor] ⚠️ The expected native binary (${expectedBinary}) was NOT found! uWebSockets.js might not work.`);
|
|
44
|
+
} else {
|
|
45
|
+
console.log(`[HyperDecor] ✨ No unnecessary binaries found. Everything is already optimized.`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
} catch (err) {
|
|
50
|
+
if (err.code === 'MODULE_NOT_FOUND') {
|
|
51
|
+
console.error(`[HyperDecor] ❌ uWebSockets.js is not installed locally. Skipping cleanup.`);
|
|
52
|
+
} else {
|
|
53
|
+
console.error(`[HyperDecor] ❌ Error cleaning uWebSockets binaries:`, err.message);
|
|
54
|
+
}
|
|
55
|
+
process.exit(1);
|
|
56
56
|
}
|
package/scripts/test-server.ts
CHANGED
|
@@ -1,85 +1,85 @@
|
|
|
1
|
-
import "reflect-metadata";
|
|
2
|
-
import {
|
|
3
|
-
HyperApp,
|
|
4
|
-
HyperModule,
|
|
5
|
-
HyperService,
|
|
6
|
-
HyperController,
|
|
7
|
-
Get,
|
|
8
|
-
Post,
|
|
9
|
-
Res,
|
|
10
|
-
Body,
|
|
11
|
-
Response,
|
|
12
|
-
OnInit,
|
|
13
|
-
createApplication,
|
|
14
|
-
Transform,
|
|
15
|
-
} from "../src";
|
|
16
|
-
import { injectable } from "tsyringe";
|
|
17
|
-
|
|
18
|
-
// 1. Setup a Mock Transformer (Zod-like)
|
|
19
|
-
const ZodTransformer = {
|
|
20
|
-
transform: ({ data, schema }: any) => {
|
|
21
|
-
if (schema._type === "zod") {
|
|
22
|
-
return { ...data, parsed: true, timestamp: Date.now() };
|
|
23
|
-
}
|
|
24
|
-
return data;
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const mockSchema = { _type: "zod" };
|
|
29
|
-
|
|
30
|
-
@injectable()
|
|
31
|
-
@HyperService()
|
|
32
|
-
class AnalyticsService implements OnInit {
|
|
33
|
-
async onInit() {
|
|
34
|
-
console.log("Service initialized");
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
@HyperController("/api")
|
|
39
|
-
class MainController {
|
|
40
|
-
@Get("/status")
|
|
41
|
-
status(@Res() res: Response) {
|
|
42
|
-
res.json({ status: "alive" });
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
@Post("/user")
|
|
46
|
-
@Transform(mockSchema)
|
|
47
|
-
createUser(@Body() data: any) {
|
|
48
|
-
return data;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
@HyperModule({
|
|
53
|
-
imports: [AnalyticsService],
|
|
54
|
-
controllers: [MainController]
|
|
55
|
-
})
|
|
56
|
-
class MainModule { }
|
|
57
|
-
|
|
58
|
-
@HyperApp({
|
|
59
|
-
name: "Standalone Test App",
|
|
60
|
-
version: "1.0.0",
|
|
61
|
-
modules: [MainModule]
|
|
62
|
-
})
|
|
63
|
-
class FullApp { }
|
|
64
|
-
|
|
65
|
-
async function run() {
|
|
66
|
-
console.log("Starting App...");
|
|
67
|
-
const app = await createApplication(FullApp);
|
|
68
|
-
app.useTransform(ZodTransformer);
|
|
69
|
-
|
|
70
|
-
const port = 3010;
|
|
71
|
-
await app.listen(port);
|
|
72
|
-
console.log(`Server listening on http://localhost:${port}`);
|
|
73
|
-
|
|
74
|
-
// Close after 5 seconds
|
|
75
|
-
setTimeout(async () => {
|
|
76
|
-
console.log("Closing server...");
|
|
77
|
-
await app.close();
|
|
78
|
-
process.exit(0);
|
|
79
|
-
}, 5000);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
run().catch(err => {
|
|
83
|
-
console.error(err);
|
|
84
|
-
process.exit(1);
|
|
85
|
-
});
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
import {
|
|
3
|
+
HyperApp,
|
|
4
|
+
HyperModule,
|
|
5
|
+
HyperService,
|
|
6
|
+
HyperController,
|
|
7
|
+
Get,
|
|
8
|
+
Post,
|
|
9
|
+
Res,
|
|
10
|
+
Body,
|
|
11
|
+
Response,
|
|
12
|
+
OnInit,
|
|
13
|
+
createApplication,
|
|
14
|
+
Transform,
|
|
15
|
+
} from "../src";
|
|
16
|
+
import { injectable } from "tsyringe";
|
|
17
|
+
|
|
18
|
+
// 1. Setup a Mock Transformer (Zod-like)
|
|
19
|
+
const ZodTransformer = {
|
|
20
|
+
transform: ({ data, schema }: any) => {
|
|
21
|
+
if (schema._type === "zod") {
|
|
22
|
+
return { ...data, parsed: true, timestamp: Date.now() };
|
|
23
|
+
}
|
|
24
|
+
return data;
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const mockSchema = { _type: "zod" };
|
|
29
|
+
|
|
30
|
+
@injectable()
|
|
31
|
+
@HyperService()
|
|
32
|
+
class AnalyticsService implements OnInit {
|
|
33
|
+
async onInit() {
|
|
34
|
+
console.log("Service initialized");
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@HyperController("/api")
|
|
39
|
+
class MainController {
|
|
40
|
+
@Get("/status")
|
|
41
|
+
status(@Res() res: Response) {
|
|
42
|
+
res.json({ status: "alive" });
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@Post("/user")
|
|
46
|
+
@Transform(mockSchema)
|
|
47
|
+
createUser(@Body() data: any) {
|
|
48
|
+
return data;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@HyperModule({
|
|
53
|
+
imports: [AnalyticsService],
|
|
54
|
+
controllers: [MainController]
|
|
55
|
+
})
|
|
56
|
+
class MainModule { }
|
|
57
|
+
|
|
58
|
+
@HyperApp({
|
|
59
|
+
name: "Standalone Test App",
|
|
60
|
+
version: "1.0.0",
|
|
61
|
+
modules: [MainModule]
|
|
62
|
+
})
|
|
63
|
+
class FullApp { }
|
|
64
|
+
|
|
65
|
+
async function run() {
|
|
66
|
+
console.log("Starting App...");
|
|
67
|
+
const app = await createApplication(FullApp);
|
|
68
|
+
app.useTransform(ZodTransformer);
|
|
69
|
+
|
|
70
|
+
const port = 3010;
|
|
71
|
+
await app.listen(port);
|
|
72
|
+
console.log(`Server listening on http://localhost:${port}`);
|
|
73
|
+
|
|
74
|
+
// Close after 5 seconds
|
|
75
|
+
setTimeout(async () => {
|
|
76
|
+
console.log("Closing server...");
|
|
77
|
+
await app.close();
|
|
78
|
+
process.exit(0);
|
|
79
|
+
}, 5000);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
run().catch(err => {
|
|
83
|
+
console.error(err);
|
|
84
|
+
process.exit(1);
|
|
85
|
+
});
|
package/vitest.config.mjs
CHANGED
|
@@ -1,30 +1,33 @@
|
|
|
1
|
-
import { defineConfig } from 'vitest/config';
|
|
2
|
-
import swc from 'unplugin-swc';
|
|
3
|
-
|
|
4
|
-
export default defineConfig({
|
|
5
|
-
test: {
|
|
6
|
-
globals: true,
|
|
7
|
-
environment: 'node',
|
|
8
|
-
include: ['tests/**/*.{test,spec
|
|
9
|
-
poolOptions: {
|
|
10
|
-
threads: {
|
|
11
|
-
singleThread: true,
|
|
12
|
-
},
|
|
13
|
-
},
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
1
|
+
import { defineConfig } from 'vitest/config';
|
|
2
|
+
import swc from 'unplugin-swc';
|
|
3
|
+
|
|
4
|
+
export default defineConfig({
|
|
5
|
+
test: {
|
|
6
|
+
globals: true,
|
|
7
|
+
environment: 'node',
|
|
8
|
+
include: ['tests/**/*.{test,spec}.ts'],
|
|
9
|
+
poolOptions: {
|
|
10
|
+
threads: {
|
|
11
|
+
singleThread: true,
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
benchmark: {
|
|
15
|
+
include: ['tests/bench/**/*.{bench}.ts'],
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
plugins: [
|
|
19
|
+
swc.vite({
|
|
20
|
+
jsc: {
|
|
21
|
+
parser: {
|
|
22
|
+
syntax: 'typescript',
|
|
23
|
+
decorators: true,
|
|
24
|
+
dynamicImport: true,
|
|
25
|
+
},
|
|
26
|
+
transform: {
|
|
27
|
+
legacyDecorator: true,
|
|
28
|
+
decoratorMetadata: true,
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
}),
|
|
32
|
+
],
|
|
33
|
+
});
|
package/vitest.json
DELETED
|
Binary file
|