@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
package/package.json
CHANGED
|
@@ -1,61 +1,82 @@
|
|
|
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
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"
|
|
25
|
-
},
|
|
26
|
-
"
|
|
27
|
-
"@
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
"
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"default": "./
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@zenofolio/hyper-decor",
|
|
3
|
+
"version": "1.0.8",
|
|
4
|
+
"description": "Project core with utilities and features",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"author": "zenozaga",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/zenofolio/hyper-decor.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/zenofolio/hyper-decor/issues"
|
|
14
|
+
},
|
|
15
|
+
"homepage": "https://github.com/zenofolio/hyper-decor#readme",
|
|
16
|
+
"scripts": {
|
|
17
|
+
"test": "vitest run",
|
|
18
|
+
"test:watch": "vitest",
|
|
19
|
+
"test:ui": "vitest --ui",
|
|
20
|
+
"build": "tsc",
|
|
21
|
+
"publish": "npm run build && npm publish --access public"
|
|
22
|
+
},
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"hyper-express": "^6.17.3"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/file-type": "10.6.0",
|
|
28
|
+
"@vitest/ui": "^4.0.18",
|
|
29
|
+
"nodemon": "3.1.7",
|
|
30
|
+
"typescript": "5.6.2",
|
|
31
|
+
"undici": "^7.24.0",
|
|
32
|
+
"unplugin-swc": "^1.5.9",
|
|
33
|
+
"vitest": "^4.0.18"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@zenofolio/hyper-decor": "file:",
|
|
37
|
+
"core-decorators": "^0.20.0",
|
|
38
|
+
"eventemitter3": "^5.0.4",
|
|
39
|
+
"file-type": "^19.5.0",
|
|
40
|
+
"reflect-metadata": "^0.2.2",
|
|
41
|
+
"ts-type": "^3.0.8",
|
|
42
|
+
"tsyringe": "^4.8.0"
|
|
43
|
+
},
|
|
44
|
+
"exports": {
|
|
45
|
+
".": {
|
|
46
|
+
"default": "./dist/index.js",
|
|
47
|
+
"node": "./dist/index.js",
|
|
48
|
+
"import": "./src/index.ts"
|
|
49
|
+
},
|
|
50
|
+
"./decorators/*": {
|
|
51
|
+
"node": "./dist/decorators/*.js",
|
|
52
|
+
"default": "./src/decorators/*.ts"
|
|
53
|
+
},
|
|
54
|
+
"./helpers/*": {
|
|
55
|
+
"node": "./dist/common/helpers/*.js",
|
|
56
|
+
"default": "./src/common/helpers/*.ts"
|
|
57
|
+
},
|
|
58
|
+
"./collectors/*": {
|
|
59
|
+
"node": "./dist/common/collectors/*.js",
|
|
60
|
+
"default": "./src/common/collectors/*.ts"
|
|
61
|
+
},
|
|
62
|
+
"./exceptions/*": {
|
|
63
|
+
"node": "./dist/common/exceptions/*.js",
|
|
64
|
+
"default": "./src/common/exceptions/*.ts"
|
|
65
|
+
},
|
|
66
|
+
"./extension": {
|
|
67
|
+
"node": "./dist/extension.js",
|
|
68
|
+
"default": "./src/extension.ts"
|
|
69
|
+
},
|
|
70
|
+
"./openapi": {
|
|
71
|
+
"node": "./dist/lib/openapi/index.js",
|
|
72
|
+
"default": "./src/lib/openapi/index.ts"
|
|
73
|
+
},
|
|
74
|
+
"./openapi/*": {
|
|
75
|
+
"node": "./dist/lib/openapi/*.js",
|
|
76
|
+
"default": "./src/lib/openapi/*.ts"
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
"bin": {
|
|
80
|
+
"hyper-clean-uws": "./scripts/clean.js"
|
|
81
|
+
}
|
|
61
82
|
}
|
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
|
+
}
|
|
@@ -0,0 +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/tsconfig.json
CHANGED
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
"emitDecoratorMetadata": true,
|
|
3
|
+
"module": "Node16",
|
|
4
|
+
"moduleResolution": "Node16",
|
|
5
|
+
"strict": true, /* Enable all strict type-checking options. */
|
|
6
|
+
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
|
7
|
+
"declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
|
|
8
|
+
"outDir": "./dist", /* Specify an output folder for all emitted files. */
|
|
9
|
+
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
|
|
10
|
+
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
|
|
11
|
+
"skipLibCheck": true, /* Skip type checking all .d.ts files. */
|
|
12
|
+
"experimentalDecorators": true,
|
|
13
|
+
"emitDecoratorMetadata": true,
|
|
15
14
|
},
|
|
16
|
-
"exclude": [
|
|
15
|
+
"exclude": [
|
|
16
|
+
"node_modules",
|
|
17
|
+
"dist",
|
|
18
|
+
"tests",
|
|
19
|
+
"examples",
|
|
20
|
+
"scripts"
|
|
21
|
+
],
|
|
17
22
|
}
|
|
@@ -0,0 +1,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
|
+
},
|
|
15
|
+
plugins: [
|
|
16
|
+
swc.vite({
|
|
17
|
+
jsc: {
|
|
18
|
+
parser: {
|
|
19
|
+
syntax: 'typescript',
|
|
20
|
+
decorators: true,
|
|
21
|
+
dynamicImport: true,
|
|
22
|
+
},
|
|
23
|
+
transform: {
|
|
24
|
+
legacyDecorator: true,
|
|
25
|
+
decoratorMetadata: true,
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
}),
|
|
29
|
+
],
|
|
30
|
+
});
|
package/.mocharc.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import "reflect-metadata";
|
|
2
|
-
import { Request } from "hyper-express";
|
|
3
|
-
import { ByPassKeys } from "../stores/params.store";
|
|
4
|
-
import { ParameterResolver } from "../../decorators";
|
|
5
|
-
/**
|
|
6
|
-
* Creates a parameter decorator for handling request data.
|
|
7
|
-
*
|
|
8
|
-
* @param {keyof Request | ByPassKeys} key - The key to extract from the request.
|
|
9
|
-
* @param {IParamsResolver} resolver - Resolver function to handle the parameter.
|
|
10
|
-
* @returns {ParameterDecorator} - The parameter decorator function.
|
|
11
|
-
*/
|
|
12
|
-
export default function createParamDecorator(key: keyof Request | ByPassKeys, decoratorName: string, resolver: ParameterResolver): ParameterDecorator;
|
|
@@ -1,53 +0,0 @@
|
|
|
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.default = createParamDecorator;
|
|
7
|
-
require("reflect-metadata");
|
|
8
|
-
const function_util_1 = require("../utils/function.util");
|
|
9
|
-
const constants_1 = require("../constants");
|
|
10
|
-
const decorator_base_1 = require("../decorator-base");
|
|
11
|
-
const who_helper_1 = __importDefault(require("../helpers/who.helper"));
|
|
12
|
-
const WrongPlaceException_1 = __importDefault(require("../../exeptions/WrongPlaceException"));
|
|
13
|
-
/**
|
|
14
|
-
* Creates a parameter decorator for handling request data.
|
|
15
|
-
*
|
|
16
|
-
* @param {keyof Request | ByPassKeys} key - The key to extract from the request.
|
|
17
|
-
* @param {IParamsResolver} resolver - Resolver function to handle the parameter.
|
|
18
|
-
* @returns {ParameterDecorator} - The parameter decorator function.
|
|
19
|
-
*/
|
|
20
|
-
function createParamDecorator(key, decoratorName, resolver) {
|
|
21
|
-
const _key = key;
|
|
22
|
-
return (0, decorator_base_1.DecoratorHelper)({
|
|
23
|
-
type: constants_1.KEY_TYPE_CONTROLLER,
|
|
24
|
-
key: constants_1.KEY_PARAMS_PARAM,
|
|
25
|
-
options: (options, Target, propertyKey, parameterIndex) => {
|
|
26
|
-
const { isProperty } = (0, who_helper_1.default)(Target, propertyKey, parameterIndex);
|
|
27
|
-
if (!isProperty)
|
|
28
|
-
throw new WrongPlaceException_1.default(decoratorName, "parameter", `${Target.constructor.name}.${propertyKey}`, Target);
|
|
29
|
-
const saved = options !== null && options !== void 0 ? options : { params: {} };
|
|
30
|
-
const names = (0, function_util_1.extreactArgsNames)(Target[propertyKey]);
|
|
31
|
-
const types = Reflect.getMetadata(constants_1.DESIGN_PARAMTYPES, Target, propertyKey);
|
|
32
|
-
const name = names === null || names === void 0 ? void 0 : names[parameterIndex];
|
|
33
|
-
const type = types === null || types === void 0 ? void 0 : types[parameterIndex];
|
|
34
|
-
if (name && saved) {
|
|
35
|
-
if (!saved.params[propertyKey]) {
|
|
36
|
-
saved.params[propertyKey] = [];
|
|
37
|
-
}
|
|
38
|
-
saved.params[propertyKey].push({
|
|
39
|
-
name,
|
|
40
|
-
type,
|
|
41
|
-
index: parameterIndex,
|
|
42
|
-
key: _key,
|
|
43
|
-
method: propertyKey.toString(),
|
|
44
|
-
resolver,
|
|
45
|
-
});
|
|
46
|
-
// sort by index
|
|
47
|
-
saved.params[propertyKey].sort((a, b) => a.index - b.index);
|
|
48
|
-
Reflect.defineMetadata(constants_1.KEY_PARAMS_PARAM, saved, Target[propertyKey]);
|
|
49
|
-
}
|
|
50
|
-
return saved;
|
|
51
|
-
},
|
|
52
|
-
});
|
|
53
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Request, Response } from "hyper-express";
|
|
2
|
-
/**
|
|
3
|
-
* Helper function to create route decorators for HTTP methods.
|
|
4
|
-
*
|
|
5
|
-
* @param {string} method - The HTTP method (e.g., GET, POST).
|
|
6
|
-
* @param {(req: Request, res: Response) => any} [resolver] - Optional resolver for the route.
|
|
7
|
-
* @returns {(path?: string) => MethodDecorator} - A method decorator for defining routes.
|
|
8
|
-
*
|
|
9
|
-
*/
|
|
10
|
-
export default function createRouteDecorator(method: string, resolver?: (req: Request, res: Response) => any): (path?: string) => MethodDecorator & ClassDecorator;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = createRouteDecorator;
|
|
4
|
-
const constants_1 = require("../constants");
|
|
5
|
-
const decorator_base_1 = require("../decorator-base");
|
|
6
|
-
/**
|
|
7
|
-
* Helper function to create route decorators for HTTP methods.
|
|
8
|
-
*
|
|
9
|
-
* @param {string} method - The HTTP method (e.g., GET, POST).
|
|
10
|
-
* @param {(req: Request, res: Response) => any} [resolver] - Optional resolver for the route.
|
|
11
|
-
* @returns {(path?: string) => MethodDecorator} - A method decorator for defining routes.
|
|
12
|
-
*
|
|
13
|
-
*/
|
|
14
|
-
function createRouteDecorator(method, resolver) {
|
|
15
|
-
return (path = "/") => (0, decorator_base_1.DecoratorHelper)({
|
|
16
|
-
type: constants_1.KEY_TYPE_CONTROLLER,
|
|
17
|
-
key: constants_1.KEY_PARAMS_ROUTE,
|
|
18
|
-
targetResolver: (target) => { var _a; return (_a = target.constructor) !== null && _a !== void 0 ? _a : target; },
|
|
19
|
-
options: (data, Target, propertyKey, descriptor) => {
|
|
20
|
-
var _a;
|
|
21
|
-
const handler = descriptor.value;
|
|
22
|
-
if (typeof handler !== "function")
|
|
23
|
-
return data;
|
|
24
|
-
const saved = (_a = Reflect.getMetadata(constants_1.KEY_PARAMS_ROUTE, Target)) !== null && _a !== void 0 ? _a : {
|
|
25
|
-
routes: new Set(),
|
|
26
|
-
};
|
|
27
|
-
saved.routes.add({
|
|
28
|
-
className: Target.name,
|
|
29
|
-
method,
|
|
30
|
-
path,
|
|
31
|
-
propertyKey,
|
|
32
|
-
handler: handler,
|
|
33
|
-
});
|
|
34
|
-
return saved;
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import "reflect-metadata";
|
|
2
|
-
export type DecoratorBaseTypes = "APP" | "MODULE" | "CONTROLLER" | "ROUTE" | "MIDDLEWARE";
|
|
3
|
-
type DefineResolve<T> = (old: T, target?: any, property?: any, descriptor?: any) => T;
|
|
4
|
-
interface onDefineResolve<T> {
|
|
5
|
-
(data: {
|
|
6
|
-
key: string;
|
|
7
|
-
options: T;
|
|
8
|
-
target: any;
|
|
9
|
-
property?: any;
|
|
10
|
-
descriptor?: any;
|
|
11
|
-
}, defineData: (options: T) => void): void;
|
|
12
|
-
}
|
|
13
|
-
interface BeseDecoratorOptions<T extends any = any> {
|
|
14
|
-
type?: DecoratorBaseTypes | string;
|
|
15
|
-
key: string;
|
|
16
|
-
options: T | DefineResolve<T>;
|
|
17
|
-
targetResolver?: (target: any, propertyKey?: any, descriptorOrIndex?: any) => any;
|
|
18
|
-
onDefineData?: onDefineResolve<T>;
|
|
19
|
-
}
|
|
20
|
-
interface BeseDecorator<T> {
|
|
21
|
-
(target: T): any;
|
|
22
|
-
(target: T, propertyKey?: any, descriptor?: any): any;
|
|
23
|
-
}
|
|
24
|
-
type TransformFunction<TOptions, T> = (options: TOptions, target: T, propertyKey?: any, descriptor?: any) => any;
|
|
25
|
-
export declare function DecoratorHelper<T, Target extends any = any>({ key, type, options, targetResolver, onDefineData }: BeseDecoratorOptions<T>, ...transformers: TransformFunction<T, Target>[]): BeseDecorator<Target>;
|
|
26
|
-
export declare const defineDecorData: <T>(key: string, options: T | DefineResolve<T>, target: any, property?: any, descriptor?: any) => void;
|
|
27
|
-
export declare const getDecorData: <T>(key: string, target: any, property?: any) => T;
|
|
28
|
-
export declare const hasDecorData: (key: string, target: any, property?: any) => boolean;
|
|
29
|
-
export declare const extractDecorData: <T>(target: any) => T | undefined;
|
|
30
|
-
export {};
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extractDecorData = exports.hasDecorData = exports.getDecorData = exports.defineDecorData = void 0;
|
|
4
|
-
exports.DecoratorHelper = DecoratorHelper;
|
|
5
|
-
require("reflect-metadata");
|
|
6
|
-
const tsyringe_1 = require("tsyringe");
|
|
7
|
-
const object_util_1 = require("./utils/object.util");
|
|
8
|
-
function DecoratorHelper({ key, type, options, targetResolver, onDefineData }, ...transformers) {
|
|
9
|
-
return (target, propertyKey, descriptor) => {
|
|
10
|
-
const isProperty = !!propertyKey;
|
|
11
|
-
const isMethod = !!descriptor;
|
|
12
|
-
let _options = options;
|
|
13
|
-
const Target = targetResolver
|
|
14
|
-
? targetResolver(target, propertyKey, descriptor)
|
|
15
|
-
: target;
|
|
16
|
-
if (options instanceof Function) {
|
|
17
|
-
const data = (0, exports.getDecorData)(key, Target);
|
|
18
|
-
const optionsResolver = options;
|
|
19
|
-
const value = optionsResolver(data, Target, propertyKey, descriptor);
|
|
20
|
-
if (value)
|
|
21
|
-
_options = Object.assign(Object.assign({}, _options), value);
|
|
22
|
-
}
|
|
23
|
-
if (onDefineData) {
|
|
24
|
-
onDefineData({
|
|
25
|
-
key,
|
|
26
|
-
options: Object.assign({ type }, _options),
|
|
27
|
-
target: Target,
|
|
28
|
-
property: propertyKey,
|
|
29
|
-
descriptor,
|
|
30
|
-
}, (data) => {
|
|
31
|
-
(0, exports.defineDecorData)(key, Object.assign({ type }, data), Target);
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
(0, exports.defineDecorData)(key, Object.assign({ type }, _options), Target);
|
|
36
|
-
}
|
|
37
|
-
let value = Target;
|
|
38
|
-
if (transformers.length) {
|
|
39
|
-
const transforms = transformers.map((fn) => fn.bind(Target, _options));
|
|
40
|
-
if (isProperty) {
|
|
41
|
-
(0, exports.defineDecorData)(key, Object.assign({ type }, options), Target, propertyKey);
|
|
42
|
-
value = Reflect.decorate(transforms, Target, propertyKey);
|
|
43
|
-
}
|
|
44
|
-
else if (isMethod) {
|
|
45
|
-
(0, exports.defineDecorData)(key, Object.assign({ type }, options), Target);
|
|
46
|
-
value = Reflect.decorate(transforms, Target, propertyKey, descriptor);
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
(0, exports.defineDecorData)(key, Object.assign({ type }, options), Target);
|
|
50
|
-
value = Reflect.decorate(transforms, Target);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
(0, tsyringe_1.injectable)()((0, object_util_1.$constructor)(target));
|
|
54
|
-
return value;
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
const defineDecorData = (key, options, target, property, descriptor) => {
|
|
58
|
-
let value = options;
|
|
59
|
-
if (typeof options === "function") {
|
|
60
|
-
const old = (0, exports.getDecorData)(key, target, property);
|
|
61
|
-
value = Object.assign(Object.assign({}, old), options(old, target, property, descriptor));
|
|
62
|
-
}
|
|
63
|
-
if (property) {
|
|
64
|
-
Reflect.defineMetadata(key, value, target, property);
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
Reflect.defineMetadata(key, value, target);
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
exports.defineDecorData = defineDecorData;
|
|
71
|
-
const getDecorData = (key, target, property) => property
|
|
72
|
-
? Reflect.getMetadata(key, target, property)
|
|
73
|
-
: Reflect.getMetadata(key, target);
|
|
74
|
-
exports.getDecorData = getDecorData;
|
|
75
|
-
const hasDecorData = (key, target, property) => property
|
|
76
|
-
? Reflect.hasMetadata(key, target, property)
|
|
77
|
-
: Reflect.hasMetadata(key, target);
|
|
78
|
-
exports.hasDecorData = hasDecorData;
|
|
79
|
-
const extractDecorData = (target) => {
|
|
80
|
-
const keys = Reflect.getMetadataKeys(target);
|
|
81
|
-
return keys.reduce((acc, key) => {
|
|
82
|
-
acc[key] = Reflect.getMetadata(key, target);
|
|
83
|
-
return acc;
|
|
84
|
-
}, {});
|
|
85
|
-
};
|
|
86
|
-
exports.extractDecorData = extractDecorData;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
class HyperAppStore {
|
|
4
|
-
constructor() {
|
|
5
|
-
this.roles = new Set();
|
|
6
|
-
this.scopes = new Set();
|
|
7
|
-
this.modules = new Map();
|
|
8
|
-
this.controllers = new Map();
|
|
9
|
-
this.routes = new Map();
|
|
10
|
-
this.middlewares = new Map();
|
|
11
|
-
}
|
|
12
|
-
addRole(role) {
|
|
13
|
-
this.roles.add(role);
|
|
14
|
-
}
|
|
15
|
-
addModuleRole(module, role) { }
|
|
16
|
-
}
|
|
17
|
-
exports.default = HyperAppStore;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.middlewareStore = void 0;
|
|
4
|
-
require("reflect-metadata");
|
|
5
|
-
const constants_1 = require("../constants");
|
|
6
|
-
const { MIDDLEWARES } = constants_1.METADATA_KEYS;
|
|
7
|
-
exports.middlewareStore = Object.freeze({
|
|
8
|
-
get(target) {
|
|
9
|
-
return Reflect.getMetadata(MIDDLEWARES, target);
|
|
10
|
-
},
|
|
11
|
-
has(target) {
|
|
12
|
-
return !!this.get(target);
|
|
13
|
-
},
|
|
14
|
-
set(target, ...middlewares) {
|
|
15
|
-
const list = this.get(target) || [];
|
|
16
|
-
list.push(...middlewares);
|
|
17
|
-
Reflect.defineMetadata(MIDDLEWARES, list, target);
|
|
18
|
-
},
|
|
19
|
-
});
|