@zenofolio/hyper-decor 1.0.61 → 1.0.63
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/dist/__internals/constants.d.ts +1 -0
- package/dist/__internals/constants.js +1 -0
- package/dist/__internals/decorator-base.js +46 -10
- package/dist/__internals/helpers/imports.helper.d.ts +2 -2
- package/dist/__internals/helpers/imports.helper.js +68 -21
- package/dist/__internals/helpers/lifecycle.helper.d.ts +3 -0
- package/dist/__internals/helpers/lifecycle.helper.js +25 -0
- package/dist/__internals/helpers/merge-metadata.js +16 -20
- package/dist/__internals/helpers/prepare.helper.js +85 -52
- package/dist/__internals/helpers/tree.helper.d.ts +32 -0
- package/dist/__internals/helpers/tree.helper.js +48 -0
- package/dist/__internals/transform/middleware.transform.js +0 -2
- package/dist/__internals/transform/role.transform.js +5 -5
- package/dist/__internals/transform/scope.transfrom.js +2 -3
- package/dist/common/bootstrap.js +4 -0
- package/dist/common/helpers/role.js +1 -4
- package/dist/common/message-bus.d.ts +11 -0
- package/dist/common/message-bus.js +51 -0
- package/dist/common/transport.d.ts +9 -0
- package/dist/common/transport.js +46 -0
- package/dist/decorators/HyperApp.js +3 -1
- package/dist/decorators/HyperService.d.ts +2 -1
- package/dist/decorators/HyperService.js +6 -4
- package/dist/decorators/Messaging.d.ts +10 -0
- package/dist/decorators/Messaging.js +22 -0
- package/dist/decorators/Middleware.d.ts +1 -1
- package/dist/decorators/Middleware.js +14 -2
- package/dist/decorators/index.d.ts +1 -0
- package/dist/decorators/index.js +1 -0
- package/dist/decorators/types.d.ts +21 -4
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/type.d.ts +5 -2
- package/dist/vitest.config.d.ts +2 -0
- package/dist/vitest.config.js +34 -0
- package/package.json +66 -59
- package/scripts/clean.js +56 -0
- package/vitest.config.mjs +30 -0
- package/vitest.json +0 -0
- package/.mocharc.js +0 -5
- package/dist/__internals/store.d.ts +0 -29
- package/dist/__internals/store.js +0 -17
- package/dist/__internals/stores/index.d.ts +0 -15
- package/dist/__internals/stores/index.js +0 -37
- 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/stores/store.interface.js +0 -2
- 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/collectors/index.d.ts +0 -1
- package/dist/collectors/index.js +0 -17
- package/dist/collectors/scope.collector.d.ts +0 -14
- package/dist/collectors/scope.collector.js +0 -29
- 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/common/openapi/index.js +0 -18
- package/dist/decorators/Service.d.ts +0 -5
- package/dist/decorators/Service.js +0 -16
|
@@ -14,11 +14,10 @@ function scopeTransfrom(listScopes, ...callback) {
|
|
|
14
14
|
if (!userScopesRaw || userScopesRaw.length === 0) {
|
|
15
15
|
return next(new exeptions_1.NotScopeException(`FORBIDDEN`, [], Array.from(scopeNames)));
|
|
16
16
|
}
|
|
17
|
-
|
|
18
|
-
if (userScopes.has(constants_1.FULL_ACCESS))
|
|
17
|
+
if (userScopesRaw.includes(constants_1.FULL_ACCESS))
|
|
19
18
|
return next();
|
|
20
19
|
for (const scope of scopes) {
|
|
21
|
-
if (!
|
|
20
|
+
if (!userScopesRaw.includes(scope.scope)) {
|
|
22
21
|
return next(new exeptions_1.NotScopeException((_a = scope.message) !== null && _a !== void 0 ? _a : `FORBIDDEN`, userScopesRaw, Array.from(scopeNames)));
|
|
23
22
|
}
|
|
24
23
|
}
|
package/dist/common/bootstrap.js
CHANGED
|
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.default = createApplication;
|
|
13
13
|
exports.createApplication = createApplication;
|
|
14
14
|
const tsyringe_1 = require("tsyringe");
|
|
15
|
+
const message_bus_1 = require("./message-bus");
|
|
15
16
|
function createApplication(app) {
|
|
16
17
|
return __awaiter(this, void 0, void 0, function* () {
|
|
17
18
|
var _a;
|
|
@@ -20,6 +21,9 @@ function createApplication(app) {
|
|
|
20
21
|
yield instance.prepare();
|
|
21
22
|
}
|
|
22
23
|
(_a = instance === null || instance === void 0 ? void 0 : instance.onPrepare) === null || _a === void 0 ? void 0 : _a.call(instance);
|
|
24
|
+
instance.emit = (topic, data) => __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
yield message_bus_1.MessageBus.emit(topic, data);
|
|
26
|
+
});
|
|
23
27
|
return instance;
|
|
24
28
|
});
|
|
25
29
|
}
|
|
@@ -38,9 +38,6 @@ const hasRole = (request, role) => {
|
|
|
38
38
|
if (!roles) {
|
|
39
39
|
return false;
|
|
40
40
|
}
|
|
41
|
-
|
|
42
|
-
return true;
|
|
43
|
-
}
|
|
44
|
-
return (0, object_util_1.$array)(role).some((r) => roles.includes(r));
|
|
41
|
+
return (0, object_util_1.$array)(role).every((r) => roles.includes(r));
|
|
45
42
|
};
|
|
46
43
|
exports.hasRole = hasRole;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IMessageTransport } from "./transport";
|
|
2
|
+
export declare class MessageBus {
|
|
3
|
+
private transports;
|
|
4
|
+
registerTransport(transport: IMessageTransport): void;
|
|
5
|
+
emit(topic: string, data: any): Promise<void>;
|
|
6
|
+
listen(topic: string, handler: (data: any) => Promise<void> | void): Promise<void>;
|
|
7
|
+
/**
|
|
8
|
+
* Static helper to emit messages without resolving the bus manually.
|
|
9
|
+
*/
|
|
10
|
+
static emit(topic: string, data: any): Promise<void>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
9
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
10
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
11
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
12
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
13
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
14
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
var MessageBus_1;
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.MessageBus = void 0;
|
|
20
|
+
const tsyringe_1 = require("tsyringe");
|
|
21
|
+
let MessageBus = MessageBus_1 = class MessageBus {
|
|
22
|
+
constructor() {
|
|
23
|
+
this.transports = [];
|
|
24
|
+
}
|
|
25
|
+
registerTransport(transport) {
|
|
26
|
+
this.transports.push(transport);
|
|
27
|
+
}
|
|
28
|
+
emit(topic, data) {
|
|
29
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
yield Promise.all(this.transports.map((t) => t.emit(topic, data)));
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
listen(topic, handler) {
|
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
yield Promise.all(this.transports.map((t) => t.listen(topic, handler)));
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Static helper to emit messages without resolving the bus manually.
|
|
40
|
+
*/
|
|
41
|
+
static emit(topic, data) {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
const bus = tsyringe_1.container.resolve(MessageBus_1);
|
|
44
|
+
yield bus.emit(topic, data);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
exports.MessageBus = MessageBus;
|
|
49
|
+
exports.MessageBus = MessageBus = MessageBus_1 = __decorate([
|
|
50
|
+
(0, tsyringe_1.singleton)()
|
|
51
|
+
], MessageBus);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface IMessageTransport {
|
|
2
|
+
listen(topic: string, handler: (data: any) => Promise<void> | void): Promise<void>;
|
|
3
|
+
emit(topic: string, data: any): Promise<void>;
|
|
4
|
+
}
|
|
5
|
+
export declare class InternalTransport implements IMessageTransport {
|
|
6
|
+
private emitter;
|
|
7
|
+
listen(topic: string, handler: (data: any) => Promise<void> | void): Promise<void>;
|
|
8
|
+
emit(topic: string, data: any): Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
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.InternalTransport = void 0;
|
|
13
|
+
const eventemitter3_1 = require("eventemitter3");
|
|
14
|
+
class InternalTransport {
|
|
15
|
+
constructor() {
|
|
16
|
+
this.emitter = new eventemitter3_1.EventEmitter();
|
|
17
|
+
}
|
|
18
|
+
listen(topic, handler) {
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
// Basic wildcard support: user.* -> user.created, user.updated
|
|
21
|
+
// We'll use a simple regex for this internal transport
|
|
22
|
+
if (topic.includes("*")) {
|
|
23
|
+
const pattern = new RegExp("^" + topic.replace(/\*/g, ".*") + "$");
|
|
24
|
+
// We need a catch-all for wildcards in EventEmitter3?
|
|
25
|
+
// EE3 doesn't support wildcards out of the box easily without listening to all events.
|
|
26
|
+
// For this internal implementation, we'll override emit or use a proxy.
|
|
27
|
+
// But simpler: just use a pattern-matching listener.
|
|
28
|
+
this.emitter.on("message", (t, data) => {
|
|
29
|
+
if (pattern.test(t)) {
|
|
30
|
+
handler(data);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
this.emitter.on(topic, handler);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
emit(topic, data) {
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
this.emitter.emit(topic, data);
|
|
42
|
+
this.emitter.emit("message", topic, data); // For wildcard listeners
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.InternalTransport = InternalTransport;
|
|
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.HyperApp = void 0;
|
|
13
13
|
require("reflect-metadata");
|
|
14
14
|
const hyper_express_1 = require("hyper-express");
|
|
15
|
+
const tsyringe_1 = require("tsyringe");
|
|
15
16
|
const constants_1 = require("../__internals/constants");
|
|
16
17
|
const decorator_base_1 = require("../__internals/decorator-base");
|
|
17
18
|
const merge_metadata_1 = require("../__internals/helpers/merge-metadata");
|
|
@@ -23,7 +24,7 @@ const prepare_helper_1 = require("../__internals/helpers/prepare.helper");
|
|
|
23
24
|
const HyperApp = (options) => (0, decorator_base_1.DecoratorHelper)({
|
|
24
25
|
type: constants_1.KEY_TYPE_APP,
|
|
25
26
|
key: constants_1.KEY_PARAMS_APP,
|
|
26
|
-
options:
|
|
27
|
+
options: Object.assign({ modules: [], logger: console.log }, options),
|
|
27
28
|
}, (options, Target) => {
|
|
28
29
|
return class extends hyper_express_1.Server {
|
|
29
30
|
constructor(...args) {
|
|
@@ -34,6 +35,7 @@ const HyperApp = (options) => (0, decorator_base_1.DecoratorHelper)({
|
|
|
34
35
|
}
|
|
35
36
|
prepare() {
|
|
36
37
|
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
tsyringe_1.container.registerInstance(hyper_express_1.Server, this);
|
|
37
39
|
this.mergeMetadata(Target);
|
|
38
40
|
yield this.applyOptions(Target);
|
|
39
41
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Constructor } from "./types";
|
|
2
2
|
interface ServiceDecoratorOptions {
|
|
3
3
|
singleton?: boolean;
|
|
4
|
+
token?: string | symbol;
|
|
4
5
|
}
|
|
5
6
|
/**
|
|
6
7
|
* HyperService decorator is used to register a class as a service in the tsyringe container.
|
|
@@ -10,5 +11,5 @@ interface ServiceDecoratorOptions {
|
|
|
10
11
|
*
|
|
11
12
|
* @param options.singleton - Whether to register as a singleton (default: true)
|
|
12
13
|
*/
|
|
13
|
-
export declare const HyperService: ({ singleton, }?: ServiceDecoratorOptions) => (target: Constructor) => void;
|
|
14
|
+
export declare const HyperService: ({ token, singleton, }?: ServiceDecoratorOptions) => (target: Constructor) => void;
|
|
14
15
|
export {};
|
|
@@ -11,14 +11,16 @@ const service_store_1 = require("../__internals/stores/service.store");
|
|
|
11
11
|
*
|
|
12
12
|
* @param options.singleton - Whether to register as a singleton (default: true)
|
|
13
13
|
*/
|
|
14
|
-
const HyperService = ({ singleton = true, } = {}) => {
|
|
14
|
+
const HyperService = ({ token, singleton = true, } = {}) => {
|
|
15
15
|
return (target) => {
|
|
16
|
-
|
|
16
|
+
const useToken = token !== null && token !== void 0 ? token : target;
|
|
17
|
+
(0, tsyringe_1.injectable)()(target);
|
|
18
|
+
if (!tsyringe_1.container.isRegistered(useToken)) {
|
|
17
19
|
if (singleton) {
|
|
18
|
-
tsyringe_1.container.registerSingleton(target);
|
|
20
|
+
tsyringe_1.container.registerSingleton(useToken, target);
|
|
19
21
|
}
|
|
20
22
|
else {
|
|
21
|
-
tsyringe_1.container.register(
|
|
23
|
+
tsyringe_1.container.register(useToken, { useClass: target });
|
|
22
24
|
}
|
|
23
25
|
}
|
|
24
26
|
service_store_1.serviceStore.add(target);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface OnMessageMetadata {
|
|
2
|
+
topic: string;
|
|
3
|
+
propertyKey: string;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* OnMessage decorator for subscribing to topics.
|
|
7
|
+
*
|
|
8
|
+
* @param topic The topic or pattern to listen to (e.g. "user.created", "user.*")
|
|
9
|
+
*/
|
|
10
|
+
export declare const OnMessage: (topic: string) => (target: any, propertyKey: string | symbol | any, descriptor?: any) => void;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OnMessage = void 0;
|
|
4
|
+
const constants_1 = require("../__internals/constants");
|
|
5
|
+
const decorator_base_1 = require("../__internals/decorator-base");
|
|
6
|
+
/**
|
|
7
|
+
* OnMessage decorator for subscribing to topics.
|
|
8
|
+
*
|
|
9
|
+
* @param topic The topic or pattern to listen to (e.g. "user.created", "user.*")
|
|
10
|
+
*/
|
|
11
|
+
const OnMessage = (topic) => {
|
|
12
|
+
return (target, propertyKey, descriptor) => {
|
|
13
|
+
var _a;
|
|
14
|
+
const existing = (_a = Reflect.getMetadata(constants_1.METADATA_KEYS.ON_MESSAGE, target.constructor)) !== null && _a !== void 0 ? _a : [];
|
|
15
|
+
existing.push({
|
|
16
|
+
topic,
|
|
17
|
+
propertyKey: propertyKey.toString(),
|
|
18
|
+
});
|
|
19
|
+
(0, decorator_base_1.defineDecorData)(constants_1.METADATA_KEYS.ON_MESSAGE, existing, target.constructor);
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
exports.OnMessage = OnMessage;
|
|
@@ -21,5 +21,5 @@ export declare const Middleware: {
|
|
|
21
21
|
* @param middleware
|
|
22
22
|
* @returns
|
|
23
23
|
*/
|
|
24
|
-
only(expressions: RegExp | RegExp[], middleware: MiddlewareHandler):
|
|
24
|
+
only(expressions: RegExp | RegExp[], middleware: MiddlewareHandler): (Target: any, propertyKey?: any) => void;
|
|
25
25
|
};
|
|
@@ -24,7 +24,13 @@ exports.Middleware = Middleware;
|
|
|
24
24
|
* @param middleware
|
|
25
25
|
* @returns
|
|
26
26
|
*/
|
|
27
|
-
exports.Middleware.exclude =
|
|
27
|
+
exports.Middleware.exclude =
|
|
28
|
+
(expressions, middleware) => (Target, propertyKey) => {
|
|
29
|
+
metadata_store_1.default.define(constants_1.KEY_PARAMS_MIDDLEWARES, buildHandler("exclude", expressions, middleware), {
|
|
30
|
+
target: Target,
|
|
31
|
+
propertyKey,
|
|
32
|
+
});
|
|
33
|
+
};
|
|
28
34
|
/**
|
|
29
35
|
* Only run middleware on matching paths.
|
|
30
36
|
*
|
|
@@ -32,7 +38,13 @@ exports.Middleware.exclude = (expressions, middleware) => (0, exports.Middleware
|
|
|
32
38
|
* @param middleware
|
|
33
39
|
* @returns
|
|
34
40
|
*/
|
|
35
|
-
exports.Middleware.only =
|
|
41
|
+
exports.Middleware.only =
|
|
42
|
+
(expressions, middleware) => (Target, propertyKey) => {
|
|
43
|
+
metadata_store_1.default.define(constants_1.KEY_PARAMS_MIDDLEWARES, buildHandler("only", expressions, middleware), {
|
|
44
|
+
target: Target,
|
|
45
|
+
propertyKey,
|
|
46
|
+
});
|
|
47
|
+
};
|
|
36
48
|
/**
|
|
37
49
|
*
|
|
38
50
|
* Helper function to build middleware handlers for "only" and "exclude" modes.
|
package/dist/decorators/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { MiddlewareHandler, MiddlewareNext, Request, Response, ServerConstructorOptions } from "hyper-express";
|
|
2
|
+
import { InjectionToken, RegistrationOptions } from "tsyringe";
|
|
3
|
+
import { IMessageTransport } from "../common/transport";
|
|
2
4
|
export interface OnInit {
|
|
3
5
|
onInit(): Promise<any>;
|
|
4
6
|
}
|
|
@@ -6,15 +8,28 @@ export interface IsSingleton {
|
|
|
6
8
|
isSingleton(): boolean;
|
|
7
9
|
}
|
|
8
10
|
export type Constructor<R extends any = any> = new (...args: any[]) => R;
|
|
9
|
-
export type
|
|
11
|
+
export type ImportObject = {
|
|
12
|
+
token: InjectionToken;
|
|
13
|
+
useClass?: Constructor;
|
|
14
|
+
useValue?: any;
|
|
15
|
+
useFactory?: (...args: any[]) => any;
|
|
16
|
+
useToken?: InjectionToken;
|
|
17
|
+
options?: RegistrationOptions;
|
|
18
|
+
};
|
|
19
|
+
export type ImportType = Constructor<Partial<OnInit> & Partial<IsSingleton>> | InjectionToken | ImportObject;
|
|
10
20
|
export type ConstructorDecorator = (target: Constructor, kay?: any, descriptor?: PropertyDescriptor) => Constructor;
|
|
11
21
|
export type HyperClassDecorator<T> = (options?: T) => ConstructorDecorator;
|
|
12
22
|
export type HyperMethodDecorator<T> = (options?: T) => (target: any, key?: any, descriptor?: PropertyDescriptor) => void;
|
|
13
23
|
export interface LogSpaces {
|
|
24
|
+
modules: boolean;
|
|
14
25
|
controllers: boolean;
|
|
15
26
|
middleware: boolean;
|
|
16
27
|
routes: boolean;
|
|
17
28
|
}
|
|
29
|
+
export interface IHyperHooks {
|
|
30
|
+
onBeforeInit?(instance: any, token: any, context: any): void | Promise<void>;
|
|
31
|
+
onAfterInit?(instance: any, token: any, context: any): void | Promise<void>;
|
|
32
|
+
}
|
|
18
33
|
export interface HyperAppMetadata {
|
|
19
34
|
name?: string;
|
|
20
35
|
version?: string;
|
|
@@ -23,16 +38,18 @@ export interface HyperAppMetadata {
|
|
|
23
38
|
license?: string;
|
|
24
39
|
prefix?: string;
|
|
25
40
|
logger?: (...args: any[]) => void;
|
|
26
|
-
logs?: LogSpaces
|
|
41
|
+
logs?: Partial<LogSpaces>;
|
|
27
42
|
modules: Constructor[];
|
|
28
43
|
imports?: ImportType[];
|
|
29
44
|
options?: ServerConstructorOptions;
|
|
45
|
+
transports?: IMessageTransport[];
|
|
46
|
+
hooks?: IHyperHooks | Constructor<IHyperHooks>;
|
|
30
47
|
}
|
|
31
48
|
export interface HyperAppDecorator {
|
|
32
49
|
(options?: HyperAppMetadata): (target: Constructor) => Constructor;
|
|
33
50
|
}
|
|
34
51
|
export type HyperModuleMetadata = {
|
|
35
|
-
path
|
|
52
|
+
path?: string;
|
|
36
53
|
name?: string;
|
|
37
54
|
roles?: string[];
|
|
38
55
|
scopes?: string[];
|
|
@@ -49,7 +66,7 @@ export type HyperControllerMetadata = {
|
|
|
49
66
|
};
|
|
50
67
|
export type HyperControllerDecorator = HyperClassDecorator<HyperControllerMetadata | string>;
|
|
51
68
|
export type ParameterResolver = (req: Request, res: Response) => any | Promise<any>;
|
|
52
|
-
export type
|
|
69
|
+
export type HyperParameterMetadata = {
|
|
53
70
|
params: Record<string, {
|
|
54
71
|
index: number;
|
|
55
72
|
type: any;
|
package/dist/index.d.ts
CHANGED
|
@@ -3,8 +3,11 @@ export * from "./constants";
|
|
|
3
3
|
export * from "./extension";
|
|
4
4
|
export * from "./decorators";
|
|
5
5
|
export * from "./common/helpers";
|
|
6
|
+
export * from "./__internals/helpers/tree.helper";
|
|
6
7
|
export * from "./common/bootstrap";
|
|
7
8
|
export * from "hyper-express";
|
|
8
9
|
export * from "tsyringe";
|
|
9
10
|
export * from "./stores";
|
|
10
11
|
export * from "./type";
|
|
12
|
+
export * from "./common/transport";
|
|
13
|
+
export * from "./common/message-bus";
|
package/dist/index.js
CHANGED
|
@@ -19,8 +19,11 @@ __exportStar(require("./constants"), exports);
|
|
|
19
19
|
__exportStar(require("./extension"), exports);
|
|
20
20
|
__exportStar(require("./decorators"), exports);
|
|
21
21
|
__exportStar(require("./common/helpers"), exports);
|
|
22
|
+
__exportStar(require("./__internals/helpers/tree.helper"), exports);
|
|
22
23
|
__exportStar(require("./common/bootstrap"), exports);
|
|
23
24
|
__exportStar(require("hyper-express"), exports);
|
|
24
25
|
__exportStar(require("tsyringe"), exports);
|
|
25
26
|
__exportStar(require("./stores"), exports);
|
|
26
27
|
__exportStar(require("./type"), exports);
|
|
28
|
+
__exportStar(require("./common/transport"), exports);
|
|
29
|
+
__exportStar(require("./common/message-bus"), exports);
|
package/dist/type.d.ts
CHANGED
|
@@ -2,9 +2,12 @@ import type { Server } from "hyper-express";
|
|
|
2
2
|
export type HyperRoleOptions = string | string[];
|
|
3
3
|
export type HyperScopeOptions = string | string[];
|
|
4
4
|
export interface IHyperApplication extends Partial<Server> {
|
|
5
|
-
onPrepare(): void;
|
|
5
|
+
onPrepare?(): void;
|
|
6
|
+
emit?(topic: string, data: any): Promise<void>;
|
|
6
7
|
}
|
|
7
|
-
export type IHyperApp<T> = T & Server
|
|
8
|
+
export type IHyperApp<T> = T & Server & {
|
|
9
|
+
emit(topic: string, data: any): Promise<void>;
|
|
10
|
+
};
|
|
8
11
|
export interface IHyperAppTarget {
|
|
9
12
|
new (...args: any[]): IHyperApplication;
|
|
10
13
|
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
declare const _default: import("vite", { with: { "resolution-mode": "import" } }).UserConfig & Promise<import("vite", { with: { "resolution-mode": "import" } }).UserConfig> & (import("vitest/config", { with: { "resolution-mode": "import" } }).ViteUserConfigFnObject & (import("vitest/config", { with: { "resolution-mode": "import" } }).ViteUserConfigFnPromise & import("vitest/config", { with: { "resolution-mode": "import" } }).ViteUserConfigExport));
|
|
2
|
+
export default _default;
|
|
@@ -0,0 +1,34 @@
|
|
|
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 config_1 = require("vitest/config");
|
|
7
|
+
const unplugin_swc_1 = __importDefault(require("unplugin-swc"));
|
|
8
|
+
exports.default = (0, config_1.defineConfig)({
|
|
9
|
+
test: {
|
|
10
|
+
globals: true,
|
|
11
|
+
environment: 'node',
|
|
12
|
+
include: ['tests/**/*.{test,spec,bench}.ts', 'tests/*.{test,spec,bench}.ts'],
|
|
13
|
+
poolOptions: {
|
|
14
|
+
threads: {
|
|
15
|
+
singleThread: true,
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
plugins: [
|
|
20
|
+
unplugin_swc_1.default.vite({
|
|
21
|
+
jsc: {
|
|
22
|
+
parser: {
|
|
23
|
+
syntax: 'typescript',
|
|
24
|
+
decorators: true,
|
|
25
|
+
dynamicImport: true,
|
|
26
|
+
},
|
|
27
|
+
transform: {
|
|
28
|
+
legacyDecorator: true,
|
|
29
|
+
decoratorMetadata: true,
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
}),
|
|
33
|
+
],
|
|
34
|
+
});
|
package/package.json
CHANGED
|
@@ -1,59 +1,66 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@zenofolio/hyper-decor",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Project core with utilities and features",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"author": "zenozaga",
|
|
7
|
-
"license": "MIT",
|
|
8
|
-
"scripts": {
|
|
9
|
-
"test": "
|
|
10
|
-
"test:
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"nodemon": "3.1.7",
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"node": "./dist/
|
|
40
|
-
"
|
|
41
|
-
},
|
|
42
|
-
"./
|
|
43
|
-
"node": "./dist/
|
|
44
|
-
"default": "./src/
|
|
45
|
-
},
|
|
46
|
-
"./
|
|
47
|
-
"node": "./dist/common/
|
|
48
|
-
"default": "./src/common/
|
|
49
|
-
},
|
|
50
|
-
"./
|
|
51
|
-
"node": "./dist/common/
|
|
52
|
-
"default": "./src/common/
|
|
53
|
-
},
|
|
54
|
-
"./
|
|
55
|
-
"node": "./dist/
|
|
56
|
-
"default": "./src/
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@zenofolio/hyper-decor",
|
|
3
|
+
"version": "1.0.63",
|
|
4
|
+
"description": "Project core with utilities and features",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"author": "zenozaga",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"test": "vitest run",
|
|
10
|
+
"test:watch": "vitest",
|
|
11
|
+
"test:ui": "vitest --ui",
|
|
12
|
+
"test:server": "vitest tests/server.bench.ts",
|
|
13
|
+
"build": "tsc",
|
|
14
|
+
"publish": "npm run build && npm publish --access public"
|
|
15
|
+
},
|
|
16
|
+
"peerDependencies": {
|
|
17
|
+
"hyper-express": "^6.17.3"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@types/file-type": "10.6.0",
|
|
21
|
+
"@vitest/ui": "^4.0.18",
|
|
22
|
+
"nodemon": "3.1.7",
|
|
23
|
+
"typescript": "5.6.2",
|
|
24
|
+
"unplugin-swc": "^1.5.9",
|
|
25
|
+
"vitest": "^4.0.18"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"core-decorators": "^0.20.0",
|
|
29
|
+
"delay": "^7.0.0",
|
|
30
|
+
"eventemitter3": "^5.0.4",
|
|
31
|
+
"file-type": "^19.5.0",
|
|
32
|
+
"reflect-metadata": "^0.2.2",
|
|
33
|
+
"ts-type": "^3.0.8",
|
|
34
|
+
"tsyringe": "^4.8.0"
|
|
35
|
+
},
|
|
36
|
+
"exports": {
|
|
37
|
+
".": {
|
|
38
|
+
"default": "./dist/index.js",
|
|
39
|
+
"node": "./dist/index.js",
|
|
40
|
+
"import": "./src/index.ts"
|
|
41
|
+
},
|
|
42
|
+
"./decorators/*": {
|
|
43
|
+
"node": "./dist/decorators/*.js",
|
|
44
|
+
"default": "./src/decorators/*.ts"
|
|
45
|
+
},
|
|
46
|
+
"./helpers/*": {
|
|
47
|
+
"node": "./dist/common/helpers/*.js",
|
|
48
|
+
"default": "./src/common/helpers/*.ts"
|
|
49
|
+
},
|
|
50
|
+
"./collectors/*": {
|
|
51
|
+
"node": "./dist/common/collectors/*.js",
|
|
52
|
+
"default": "./src/common/collectors/*.ts"
|
|
53
|
+
},
|
|
54
|
+
"./exceptions/*": {
|
|
55
|
+
"node": "./dist/common/exceptions/*.js",
|
|
56
|
+
"default": "./src/common/exceptions/*.ts"
|
|
57
|
+
},
|
|
58
|
+
"./extension": {
|
|
59
|
+
"node": "./dist/extension.js",
|
|
60
|
+
"default": "./src/extension.ts"
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
"bin": {
|
|
64
|
+
"hyper-clean-uws": "./scripts/clean.js"
|
|
65
|
+
}
|
|
66
|
+
}
|
package/scripts/clean.js
ADDED
|
@@ -0,0 +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);
|
|
56
|
+
}
|