@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
|
@@ -16,8 +16,8 @@ export declare const getScopes: (request: Request) => string[] | undefined;
|
|
|
16
16
|
/**
|
|
17
17
|
* Check if request has required scopes
|
|
18
18
|
*
|
|
19
|
-
* @param request
|
|
20
|
-
* @param scopes
|
|
21
|
-
* @returns
|
|
19
|
+
* @param request - The incoming request
|
|
20
|
+
* @param scopes - Required scopes to check
|
|
21
|
+
* @returns `true` if the request has all required scopes, otherwise `false`
|
|
22
22
|
*/
|
|
23
23
|
export declare const hasScopes: (request: Request, scopes: HyperScopeOptions) => boolean;
|
|
@@ -33,15 +33,14 @@ exports.getScopes = getScopes;
|
|
|
33
33
|
/**
|
|
34
34
|
* Check if request has required scopes
|
|
35
35
|
*
|
|
36
|
-
* @param request
|
|
37
|
-
* @param scopes
|
|
38
|
-
* @returns
|
|
36
|
+
* @param request - The incoming request
|
|
37
|
+
* @param scopes - Required scopes to check
|
|
38
|
+
* @returns `true` if the request has all required scopes, otherwise `false`
|
|
39
39
|
*/
|
|
40
40
|
const hasScopes = (request, scopes) => {
|
|
41
|
-
const requestScopes = (0, exports.getScopes)(request);
|
|
42
|
-
if (
|
|
43
|
-
return
|
|
44
|
-
|
|
45
|
-
return (0, object_util_1.$array)(scopes).every((scope) => requestScopes.includes(scope));
|
|
41
|
+
const requestScopes = new Set((0, exports.getScopes)(request) || []);
|
|
42
|
+
if (requestScopes.has("*"))
|
|
43
|
+
return true;
|
|
44
|
+
return (0, object_util_1.$array)(scopes).every(scope => requestScopes.has(scope));
|
|
46
45
|
};
|
|
47
46
|
exports.hasScopes = hasScopes;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Request } from "hyper-express";
|
|
2
|
+
/**
|
|
3
|
+
* Save a custom value against the request directly via an internal Map
|
|
4
|
+
*
|
|
5
|
+
* @param {Request} request
|
|
6
|
+
* @param {string} key
|
|
7
|
+
* @param {any} value
|
|
8
|
+
*/
|
|
9
|
+
export declare const setValue: (request: Request, key: string, value: any) => void;
|
|
10
|
+
/**
|
|
11
|
+
* Get a custom value from the request object directly via an internal Map
|
|
12
|
+
*
|
|
13
|
+
* @param {Request} request
|
|
14
|
+
* @param {string} key
|
|
15
|
+
* @param {any} defaultValue
|
|
16
|
+
*/
|
|
17
|
+
export declare const getValue: <T>(request: Request, key: string, defaultValue?: T) => T | any;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getValue = exports.setValue = void 0;
|
|
4
|
+
const STATE_SYMBOL = Symbol("HYPER_DECOR_REQUEST_STATE");
|
|
5
|
+
/**
|
|
6
|
+
* Get or create the internal state map for the request
|
|
7
|
+
* @param request
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
function getStore(request) {
|
|
11
|
+
if (!request[STATE_SYMBOL]) {
|
|
12
|
+
request[STATE_SYMBOL] = new Map();
|
|
13
|
+
}
|
|
14
|
+
return request[STATE_SYMBOL];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Save a custom value against the request directly via an internal Map
|
|
18
|
+
*
|
|
19
|
+
* @param {Request} request
|
|
20
|
+
* @param {string} key
|
|
21
|
+
* @param {any} value
|
|
22
|
+
*/
|
|
23
|
+
const setValue = (request, key, value) => {
|
|
24
|
+
const store = getStore(request);
|
|
25
|
+
if (value === undefined) {
|
|
26
|
+
store.delete(key);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
store.set(key, value);
|
|
30
|
+
};
|
|
31
|
+
exports.setValue = setValue;
|
|
32
|
+
/**
|
|
33
|
+
* Get a custom value from the request object directly via an internal Map
|
|
34
|
+
*
|
|
35
|
+
* @param {Request} request
|
|
36
|
+
* @param {string} key
|
|
37
|
+
* @param {any} defaultValue
|
|
38
|
+
*/
|
|
39
|
+
const getValue = (request, key, defaultValue) => {
|
|
40
|
+
const store = getStore(request);
|
|
41
|
+
const value = store.get(key);
|
|
42
|
+
return value !== undefined ? value : defaultValue;
|
|
43
|
+
};
|
|
44
|
+
exports.getValue = getValue;
|
|
@@ -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,56 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
import { InjectionToken } from "tsyringe";
|
|
3
|
+
import { Constructor, HyperAppMetadata, ImportType } from "../lib/server/decorators/types";
|
|
4
|
+
export type Token<T = any> = InjectionToken<T> | Constructor<T> | string | (abstract new (...args: any[]) => T);
|
|
5
|
+
/**
|
|
6
|
+
* 🧪 TestingModule
|
|
7
|
+
* Holds the context of a compiled test environment.
|
|
8
|
+
*/
|
|
9
|
+
export declare class TestingModule {
|
|
10
|
+
private target?;
|
|
11
|
+
constructor(target?: Constructor | undefined);
|
|
12
|
+
/**
|
|
13
|
+
* Resolves a dependency from the container and ensures it's initialized.
|
|
14
|
+
*/
|
|
15
|
+
resolve<T>(token: Token<T>): Promise<T>;
|
|
16
|
+
/**
|
|
17
|
+
* Shortcut for resolve (consistent with NestJS)
|
|
18
|
+
*/
|
|
19
|
+
get<T>(token: Token<T>): Promise<T>;
|
|
20
|
+
/**
|
|
21
|
+
* Creates the full HyperExpress application proxy.
|
|
22
|
+
*/
|
|
23
|
+
createHyperApplication(): Promise<any>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* 🛠️ TestingModuleBuilder
|
|
27
|
+
* Fluent API for configuring the testing module.
|
|
28
|
+
*/
|
|
29
|
+
export declare class TestingModuleBuilder {
|
|
30
|
+
private metadata;
|
|
31
|
+
constructor(metadata: Partial<HyperAppMetadata>);
|
|
32
|
+
overrideProvider(token: Token): any;
|
|
33
|
+
compile(): Promise<TestingModule>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* 🚀 HyperTest
|
|
37
|
+
* Entry point for creating testing environments.
|
|
38
|
+
*/
|
|
39
|
+
export declare class HyperTest {
|
|
40
|
+
/**
|
|
41
|
+
* Ultra-simple one-liner to boot a module or app.
|
|
42
|
+
* const module = await HyperTest.create(AppModule);
|
|
43
|
+
*/
|
|
44
|
+
static create(Target: Constructor, options?: {
|
|
45
|
+
providers?: ImportType[];
|
|
46
|
+
}): Promise<TestingModule>;
|
|
47
|
+
/**
|
|
48
|
+
* Full builder API for complex configurations.
|
|
49
|
+
*/
|
|
50
|
+
static createTestingModule(metadata: Partial<HyperAppMetadata>): TestingModuleBuilder;
|
|
51
|
+
/**
|
|
52
|
+
* Resets the global container instances (but keeps registrations).
|
|
53
|
+
* Useful between tests when isolation is not possible.
|
|
54
|
+
*/
|
|
55
|
+
static reset(): void;
|
|
56
|
+
}
|
|
@@ -0,0 +1,193 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.HyperTest = exports.TestingModuleBuilder = exports.TestingModule = void 0;
|
|
19
|
+
require("reflect-metadata");
|
|
20
|
+
const tsyringe_1 = require("tsyringe");
|
|
21
|
+
const stores_1 = require("../__internals/stores");
|
|
22
|
+
const lifecycle_helper_1 = require("../__internals/helpers/lifecycle.helper");
|
|
23
|
+
const bootstrap_1 = require("./bootstrap");
|
|
24
|
+
const HyperApp_1 = require("../lib/server/decorators/HyperApp");
|
|
25
|
+
/**
|
|
26
|
+
* 🧪 TestingModule
|
|
27
|
+
* Holds the context of a compiled test environment.
|
|
28
|
+
*/
|
|
29
|
+
class TestingModule {
|
|
30
|
+
constructor(target) {
|
|
31
|
+
this.target = target;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Resolves a dependency from the container and ensures it's initialized.
|
|
35
|
+
*/
|
|
36
|
+
resolve(token) {
|
|
37
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
return yield deepResolve(token);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Shortcut for resolve (consistent with NestJS)
|
|
43
|
+
*/
|
|
44
|
+
get(token) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
return yield this.resolve(token);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Creates the full HyperExpress application proxy.
|
|
51
|
+
*/
|
|
52
|
+
createHyperApplication() {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
if (!this.target) {
|
|
55
|
+
throw new Error("Cannot create application without a target module/app.");
|
|
56
|
+
}
|
|
57
|
+
return yield (0, bootstrap_1.createApplication)(this.target);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.TestingModule = TestingModule;
|
|
62
|
+
/**
|
|
63
|
+
* 🛠️ TestingModuleBuilder
|
|
64
|
+
* Fluent API for configuring the testing module.
|
|
65
|
+
*/
|
|
66
|
+
class TestingModuleBuilder {
|
|
67
|
+
constructor(metadata) {
|
|
68
|
+
this.metadata = metadata;
|
|
69
|
+
}
|
|
70
|
+
overrideProvider(token) {
|
|
71
|
+
return {
|
|
72
|
+
useValue: (value) => {
|
|
73
|
+
tsyringe_1.container.register(token, { useValue: value });
|
|
74
|
+
return this;
|
|
75
|
+
},
|
|
76
|
+
useClass: (target) => {
|
|
77
|
+
tsyringe_1.container.register(token, { useClass: target });
|
|
78
|
+
return this;
|
|
79
|
+
},
|
|
80
|
+
useFactory: (factory) => {
|
|
81
|
+
tsyringe_1.container.register(token, { useFactory: factory });
|
|
82
|
+
return this;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
compile() {
|
|
87
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
+
// 1. Create a synthetic app if needed
|
|
89
|
+
let SyntheticApp = class SyntheticApp {
|
|
90
|
+
};
|
|
91
|
+
SyntheticApp = __decorate([
|
|
92
|
+
(0, HyperApp_1.HyperApp)(this.metadata)
|
|
93
|
+
], SyntheticApp);
|
|
94
|
+
// 2. Deep initialize all defined imports/providers
|
|
95
|
+
if (this.metadata.imports) {
|
|
96
|
+
for (const item of this.metadata.imports) {
|
|
97
|
+
const token = typeof item === "object" && "token" in item ? item.token : item;
|
|
98
|
+
yield deepResolve(token);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return new TestingModule(SyntheticApp);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
exports.TestingModuleBuilder = TestingModuleBuilder;
|
|
106
|
+
/**
|
|
107
|
+
* 🚀 HyperTest
|
|
108
|
+
* Entry point for creating testing environments.
|
|
109
|
+
*/
|
|
110
|
+
class HyperTest {
|
|
111
|
+
/**
|
|
112
|
+
* Ultra-simple one-liner to boot a module or app.
|
|
113
|
+
* const module = await HyperTest.create(AppModule);
|
|
114
|
+
*/
|
|
115
|
+
static create(Target, options) {
|
|
116
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
117
|
+
const builder = this.createTestingModule({
|
|
118
|
+
imports: [Target, ...((options === null || options === void 0 ? void 0 : options.providers) || [])]
|
|
119
|
+
});
|
|
120
|
+
const module = yield builder.compile();
|
|
121
|
+
// Ensure the target itself is deep-resolved
|
|
122
|
+
yield deepResolve(Target);
|
|
123
|
+
return module;
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Full builder API for complex configurations.
|
|
128
|
+
*/
|
|
129
|
+
static createTestingModule(metadata) {
|
|
130
|
+
return new TestingModuleBuilder(metadata);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Resets the global container instances (but keeps registrations).
|
|
134
|
+
* Useful between tests when isolation is not possible.
|
|
135
|
+
*/
|
|
136
|
+
static reset() {
|
|
137
|
+
tsyringe_1.container.clearInstances();
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
exports.HyperTest = HyperTest;
|
|
141
|
+
/**
|
|
142
|
+
* 🔄 deepResolve
|
|
143
|
+
* Recursively resolves a token and ensures its onInit chain is executed.
|
|
144
|
+
*/
|
|
145
|
+
function deepResolve(token) {
|
|
146
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
147
|
+
const instance = tsyringe_1.container.resolve(token);
|
|
148
|
+
// 1. Get the actual implementation constructor to inspect dependencies.
|
|
149
|
+
// We prefer instance.constructor because if token is an abstract class,
|
|
150
|
+
// dependencies are defined on the implementation.
|
|
151
|
+
const target = (instance === null || instance === void 0 ? void 0 : instance.constructor) || (typeof token === "function" ? token : null);
|
|
152
|
+
// 2. Recursive resolution of dependencies (Bottom-up initialization)
|
|
153
|
+
if (target && typeof target === "function") {
|
|
154
|
+
const paramTypes = Reflect.getMetadata("design:paramtypes", target) || [];
|
|
155
|
+
const injectionTokens = Reflect.getOwnMetadata("injectionTokens", target) || {};
|
|
156
|
+
for (let i = 0; i < paramTypes.length; i++) {
|
|
157
|
+
// Use @inject token if present, otherwise use design:paramtype
|
|
158
|
+
const dep = injectionTokens[i] || paramTypes[i];
|
|
159
|
+
// Avoid cycles or primitives
|
|
160
|
+
if (dep && typeof dep === "function" && dep !== Object && dep !== Array && dep !== String && dep !== Number && dep !== Boolean) {
|
|
161
|
+
yield deepResolve(dep);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
// 3. Metadata Discovery (traversing @HyperApp, @HyperModule, etc.)
|
|
166
|
+
const metadata = stores_1.HyperMeta.get(target);
|
|
167
|
+
if (metadata) {
|
|
168
|
+
// Resolve imports
|
|
169
|
+
if (metadata.imports && Array.isArray(metadata.imports)) {
|
|
170
|
+
for (const item of metadata.imports) {
|
|
171
|
+
const depToken = typeof item === "object" && item !== null && "token" in item ? item.token : item;
|
|
172
|
+
if (depToken)
|
|
173
|
+
yield deepResolve(depToken);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
// Resolve modules recursively
|
|
177
|
+
if (metadata.modules && Array.isArray(metadata.modules)) {
|
|
178
|
+
for (const m of metadata.modules) {
|
|
179
|
+
yield deepResolve(m);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
// Resolve controllers
|
|
183
|
+
if (metadata.controllers && Array.isArray(metadata.controllers)) {
|
|
184
|
+
for (const c of metadata.controllers) {
|
|
185
|
+
yield deepResolve(c);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
// 4. Initialize the instance itself
|
|
190
|
+
yield (0, lifecycle_helper_1.initializeInstance)(instance);
|
|
191
|
+
return instance;
|
|
192
|
+
});
|
|
193
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
private wildcardHandlers;
|
|
8
|
+
listen(topic: string, handler: (data: any) => Promise<void> | void): Promise<void>;
|
|
9
|
+
emit(topic: string, data: any): Promise<void>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.InternalTransport = void 0;
|
|
19
|
+
const tsyringe_1 = require("tsyringe");
|
|
20
|
+
const eventemitter3_1 = require("eventemitter3");
|
|
21
|
+
let InternalTransport = class InternalTransport {
|
|
22
|
+
constructor() {
|
|
23
|
+
this.emitter = new eventemitter3_1.EventEmitter();
|
|
24
|
+
this.wildcardHandlers = [];
|
|
25
|
+
}
|
|
26
|
+
listen(topic, handler) {
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
if (topic.includes("*")) {
|
|
29
|
+
const patternString = topic
|
|
30
|
+
.replace(/[+?^${}()|[\]\\]/g, "\\$&")
|
|
31
|
+
.replace(/\./g, "\\.")
|
|
32
|
+
.replace(/\*/g, ".*");
|
|
33
|
+
this.wildcardHandlers.push({
|
|
34
|
+
pattern: new RegExp(`^${patternString}$`),
|
|
35
|
+
handler,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
this.emitter.on(topic, handler);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
emit(topic, data) {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
// 1. Regular emit
|
|
46
|
+
this.emitter.emit(topic, data);
|
|
47
|
+
// 2. Wildcard checks
|
|
48
|
+
for (const item of this.wildcardHandlers) {
|
|
49
|
+
if (item.pattern.test(topic)) {
|
|
50
|
+
yield item.handler(data);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
exports.InternalTransport = InternalTransport;
|
|
57
|
+
exports.InternalTransport = InternalTransport = __decorate([
|
|
58
|
+
(0, tsyringe_1.singleton)()
|
|
59
|
+
], InternalTransport);
|
package/dist/constants.d.ts
CHANGED
package/dist/constants.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HYPER_PASS_KEY = exports.HYPER_ROLE_KEY = exports.HYPER_SCOPES_KEY = void 0;
|
|
3
|
+
exports.FULL_ACCESS = exports.HYPER_PASS_KEY = exports.HYPER_ROLE_KEY = exports.HYPER_SCOPES_KEY = void 0;
|
|
4
4
|
exports.HYPER_SCOPES_KEY = "__HYPER_SCOPES_KEY";
|
|
5
5
|
exports.HYPER_ROLE_KEY = "__HYPER_ROLE_KEY";
|
|
6
6
|
exports.HYPER_PASS_KEY = "__HYPER_PASS_KEY";
|
|
7
|
+
exports.FULL_ACCESS = "*";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./lib/server/decorators";
|
|
@@ -14,5 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./
|
|
18
|
-
__exportStar(require("./collect-function-data"), exports);
|
|
17
|
+
__exportStar(require("./lib/server/decorators"), exports);
|
package/dist/extension.js
CHANGED
|
@@ -18,6 +18,9 @@ const requestMethods = {
|
|
|
18
18
|
setScopes(scopes) {
|
|
19
19
|
(0, helpers_1.setScopes)(this, scopes);
|
|
20
20
|
},
|
|
21
|
+
setFullScopes() {
|
|
22
|
+
(0, helpers_1.setScopes)(this, ["*"]);
|
|
23
|
+
},
|
|
21
24
|
hasScopes(scopes) {
|
|
22
25
|
return (0, helpers_1.hasScopes)(this, scopes);
|
|
23
26
|
},
|
|
@@ -25,8 +28,14 @@ const requestMethods = {
|
|
|
25
28
|
return (0, helpers_1.getScopes)(this);
|
|
26
29
|
},
|
|
27
30
|
setRoleScopes(role, scopes) {
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
(0, helpers_1.setRole)(this, role);
|
|
32
|
+
(0, helpers_1.setScopes)(this, scopes);
|
|
33
|
+
},
|
|
34
|
+
setValue(key, value) {
|
|
35
|
+
(0, helpers_1.setValue)(this, key, value);
|
|
36
|
+
},
|
|
37
|
+
getValue(key, defaultValue) {
|
|
38
|
+
return (0, helpers_1.getValue)(this, key, defaultValue);
|
|
30
39
|
},
|
|
31
40
|
};
|
|
32
41
|
/////////////////////////////
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
import "./extension";
|
|
2
|
+
export * from "./lib/server/exeptions";
|
|
2
3
|
export * from "./constants";
|
|
3
4
|
export * from "./extension";
|
|
4
|
-
export * from "./decorators";
|
|
5
|
+
export * from "./lib/server/decorators";
|
|
5
6
|
export * from "./common/helpers";
|
|
7
|
+
export * from "./lib/tree/tree";
|
|
6
8
|
export * from "./common/bootstrap";
|
|
7
9
|
export * from "hyper-express";
|
|
8
10
|
export * from "tsyringe";
|
|
9
|
-
export * from "./
|
|
11
|
+
export * from "./__internals/stores";
|
|
12
|
+
export * from "./__internals/types";
|
|
13
|
+
export * from "./common/transport";
|
|
14
|
+
export * from "./common/message-bus";
|
|
15
|
+
export * from "./__internals/transform/transform.registry";
|
|
16
|
+
export * from "./lib/openapi";
|
|
17
|
+
export * from "./common/testing";
|
package/dist/index.js
CHANGED
|
@@ -14,12 +14,20 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
|
|
17
|
+
require("./extension");
|
|
18
|
+
__exportStar(require("./lib/server/exeptions"), exports);
|
|
18
19
|
__exportStar(require("./constants"), exports);
|
|
19
20
|
__exportStar(require("./extension"), exports);
|
|
20
|
-
__exportStar(require("./decorators"), exports);
|
|
21
|
+
__exportStar(require("./lib/server/decorators"), exports);
|
|
21
22
|
__exportStar(require("./common/helpers"), exports);
|
|
23
|
+
__exportStar(require("./lib/tree/tree"), exports);
|
|
22
24
|
__exportStar(require("./common/bootstrap"), exports);
|
|
23
25
|
__exportStar(require("hyper-express"), exports);
|
|
24
26
|
__exportStar(require("tsyringe"), exports);
|
|
25
|
-
__exportStar(require("./
|
|
27
|
+
__exportStar(require("./__internals/stores"), exports);
|
|
28
|
+
__exportStar(require("./__internals/types"), exports);
|
|
29
|
+
__exportStar(require("./common/transport"), exports);
|
|
30
|
+
__exportStar(require("./common/message-bus"), exports);
|
|
31
|
+
__exportStar(require("./__internals/transform/transform.registry"), exports);
|
|
32
|
+
__exportStar(require("./lib/openapi"), exports);
|
|
33
|
+
__exportStar(require("./common/testing"), exports);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.collectClassMetadata = collectClassMetadata;
|
|
4
|
+
const metadata_1 = require("../metadata");
|
|
5
|
+
/**
|
|
6
|
+
* 🏢 Extracts class-level OpenAPI metadata (Tags, Security, etc.)
|
|
7
|
+
*/
|
|
8
|
+
function collectClassMetadata(Target) {
|
|
9
|
+
return metadata_1.SwaggerMeta.get(Target);
|
|
10
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./class.collector"), exports);
|
|
18
|
+
__exportStar(require("./method.collector"), exports);
|
|
19
|
+
__exportStar(require("./schema.collector"), exports);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
import { Operation } from '../types';
|
|
3
|
+
import { Constructor } from '../../server/decorators/types';
|
|
4
|
+
/**
|
|
5
|
+
* 🛠️ Consolidates framework metadata and OpenAPI decorators into a single Operation object.
|
|
6
|
+
*/
|
|
7
|
+
export declare function collectMethodMetadata(target: Constructor, propertyKey?: string): Operation | undefined;
|