@zenofolio/hyper-decor 0.0.3 → 1.0.7
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/README.md +64 -1
- package/debug.txt +1 -0
- package/dist/__internals/constants.d.ts +5 -1
- package/dist/__internals/constants.js +5 -1
- package/dist/__internals/creators/request.creator.d.ts +2 -3
- package/dist/__internals/creators/request.creator.js +5 -3
- package/dist/__internals/creators/routes.creator.d.ts +2 -3
- package/dist/__internals/creators/routes.creator.js +5 -3
- package/dist/__internals/decorator-base.js +47 -11
- package/dist/__internals/helpers/imports.helper.d.ts +8 -0
- package/dist/__internals/helpers/imports.helper.js +92 -0
- 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.d.ts +11 -0
- package/dist/__internals/helpers/prepare.helper.js +348 -0
- package/dist/__internals/helpers/tree.helper.d.ts +36 -0
- package/dist/__internals/helpers/tree.helper.js +81 -0
- package/dist/__internals/stores/service.store.d.ts +1 -0
- package/dist/__internals/{transform/pass.transfrom.js → stores/service.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.js +8 -5
- package/dist/__internals/transform/scope.transfrom.d.ts +5 -7
- package/dist/__internals/transform/scope.transfrom.js +52 -38
- package/dist/__internals/transform/transform.registry.d.ts +33 -0
- package/dist/__internals/transform/transform.registry.js +59 -0
- package/dist/__internals/utils/function.util.d.ts +1 -4
- package/dist/__internals/utils/function.util.js +22 -10
- package/dist/common/bootstrap.js +4 -0
- 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/transport.d.ts +9 -0
- package/dist/common/transport.js +46 -0
- package/dist/decorators/File.d.ts +1 -1
- package/dist/decorators/Http.d.ts +20 -13
- package/dist/decorators/Http.js +77 -31
- package/dist/decorators/HyperApp.d.ts +0 -4
- package/dist/decorators/HyperApp.js +16 -182
- package/dist/decorators/HyperController.js +2 -1
- package/dist/decorators/HyperService.d.ts +15 -0
- package/dist/decorators/HyperService.js +29 -0
- package/dist/decorators/Messaging.d.ts +10 -0
- package/dist/decorators/Messaging.js +22 -0
- package/dist/decorators/Middleware.d.ts +5 -4
- package/dist/decorators/Middleware.js +33 -19
- package/dist/decorators/Output.d.ts +9 -0
- package/dist/decorators/Output.js +18 -0
- package/dist/decorators/Pass.d.ts +6 -3
- package/dist/decorators/Pass.js +6 -3
- package/dist/decorators/Role.js +5 -5
- package/dist/decorators/Routes.d.ts +14 -13
- package/dist/decorators/Scope.js +3 -3
- package/dist/decorators/Transform.d.ts +14 -0
- package/dist/decorators/Transform.js +18 -0
- package/dist/decorators/index.d.ts +3 -0
- package/dist/decorators/index.js +3 -0
- package/dist/decorators/types.d.ts +45 -10
- package/dist/decorators/types.js +4 -0
- package/dist/extension.js +11 -2
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/lib/openapi/collectors/class.collector.d.ts +9 -0
- package/dist/lib/openapi/collectors/class.collector.js +67 -0
- package/dist/lib/openapi/collectors/index.d.ts +4 -0
- package/dist/lib/openapi/collectors/index.js +20 -0
- package/dist/lib/openapi/collectors/method.collector.d.ts +2 -0
- package/dist/lib/openapi/collectors/method.collector.js +68 -0
- package/dist/lib/openapi/collectors/param.collector.d.ts +2 -0
- package/dist/lib/openapi/collectors/param.collector.js +64 -0
- package/dist/lib/openapi/collectors/schema.collector.d.ts +11 -0
- package/dist/lib/openapi/collectors/schema.collector.js +37 -0
- package/dist/lib/openapi/constants.d.ts +46 -0
- package/dist/lib/openapi/constants.js +61 -0
- package/dist/lib/openapi/decorators/api-bearer-auth.decorator.d.ts +2 -0
- package/dist/lib/openapi/decorators/api-bearer-auth.decorator.js +10 -0
- package/dist/lib/openapi/decorators/api-method.decorator.d.ts +3 -0
- package/dist/lib/openapi/decorators/api-method.decorator.js +11 -0
- package/dist/lib/openapi/decorators/api-parameter.decorator.d.ts +3 -0
- package/dist/lib/openapi/decorators/api-parameter.decorator.js +10 -0
- package/dist/lib/openapi/decorators/api-request-body.decorator.d.ts +3 -0
- package/dist/lib/openapi/decorators/api-request-body.decorator.js +10 -0
- package/dist/lib/openapi/decorators/api-response.decorator.d.ts +3 -0
- package/dist/lib/openapi/decorators/api-response.decorator.js +10 -0
- package/dist/lib/openapi/decorators/api-security.decorator.d.ts +3 -0
- package/dist/lib/openapi/decorators/api-security.decorator.js +10 -0
- package/dist/lib/openapi/decorators/api-tag.decorator.d.ts +3 -0
- package/dist/lib/openapi/decorators/api-tag.decorator.js +13 -0
- package/dist/lib/openapi/decorators/index.d.ts +7 -0
- package/dist/lib/openapi/decorators/index.js +23 -0
- package/dist/lib/openapi/helpers/index.d.ts +7 -0
- package/dist/lib/openapi/helpers/index.js +23 -0
- package/dist/lib/openapi/helpers/method.helper.d.ts +3 -0
- package/dist/lib/openapi/helpers/method.helper.js +20 -0
- package/dist/lib/openapi/helpers/openapi.helper.d.ts +7 -0
- package/dist/lib/openapi/helpers/openapi.helper.js +51 -0
- package/dist/lib/openapi/helpers/parameter.helper.d.ts +3 -0
- package/dist/lib/openapi/helpers/parameter.helper.js +16 -0
- package/dist/lib/openapi/helpers/request-body.helper.d.ts +3 -0
- package/dist/lib/openapi/helpers/request-body.helper.js +9 -0
- package/dist/lib/openapi/helpers/response.helper.d.ts +3 -0
- package/dist/lib/openapi/helpers/response.helper.js +18 -0
- package/dist/lib/openapi/helpers/security.helper.d.ts +3 -0
- package/dist/lib/openapi/helpers/security.helper.js +17 -0
- package/dist/lib/openapi/helpers/tag.helper.d.ts +3 -0
- package/dist/lib/openapi/helpers/tag.helper.js +10 -0
- package/dist/lib/openapi/index.d.ts +6 -0
- package/dist/lib/openapi/index.js +22 -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/stores/index.d.ts +1 -0
- package/dist/{common/openapi → stores}/index.js +1 -2
- package/dist/stores/scope.store.d.ts +14 -0
- package/dist/stores/scope.store.js +29 -0
- package/dist/type.d.ts +13 -2
- package/hyper-express-decorators.d.ts +1 -0
- package/package.json +73 -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/vitest.json +0 -0
- package/.mocharc.js +0 -5
- 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/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/__internals/stores/{index.d.ts → metadata.store.d.ts} +0 -0
- /package/dist/__internals/stores/{index.js → metadata.store.js} +0 -0
- /package/dist/{__internals/stores/store.interface.js → lib/openapi/types.js} +0 -0
package/package.json
CHANGED
|
@@ -1,61 +1,74 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@zenofolio/hyper-decor",
|
|
3
|
-
"version": "
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@zenofolio/hyper-decor",
|
|
3
|
+
"version": "1.0.7",
|
|
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
|
+
"undici": "^7.24.0",
|
|
25
|
+
"unplugin-swc": "^1.5.9",
|
|
26
|
+
"vitest": "^4.0.18"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"core-decorators": "^0.20.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
|
+
"./openapi": {
|
|
63
|
+
"node": "./dist/lib/openapi/index.js",
|
|
64
|
+
"default": "./src/lib/openapi/index.ts"
|
|
65
|
+
},
|
|
66
|
+
"./openapi/*": {
|
|
67
|
+
"node": "./dist/lib/openapi/*.js",
|
|
68
|
+
"default": "./src/lib/openapi/*.ts"
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
"bin": {
|
|
72
|
+
"hyper-clean-uws": "./scripts/clean.js"
|
|
73
|
+
}
|
|
61
74
|
}
|
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,bench}.ts', 'tests/*.{test,spec,bench}.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/vitest.json
ADDED
|
Binary file
|
package/.mocharc.js
DELETED
|
@@ -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
|
-
});
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Request, Response } from "hyper-express";
|
|
2
|
-
export type ByPassKeys = "req" | "res";
|
|
3
|
-
export type IParamsResolver = (req: Request, res: Response) => any | Promise<any>;
|
|
4
|
-
export type IStoreParams = {
|
|
5
|
-
name: string;
|
|
6
|
-
type: any;
|
|
7
|
-
index: number;
|
|
8
|
-
key: string;
|
|
9
|
-
propertyKey: string;
|
|
10
|
-
resolver: IParamsResolver;
|
|
11
|
-
};
|
|
12
|
-
export type IStoreParamsMap = Map<string, IStoreParams>;
|
|
13
|
-
export declare const paramsStore: Readonly<{
|
|
14
|
-
has(target: any, propety: any, key: string): boolean;
|
|
15
|
-
get(target: any, propety?: any): IStoreParamsMap | undefined;
|
|
16
|
-
set(target: any, propety: any, value: IStoreParams): void;
|
|
17
|
-
delete(target: any, propety: any): void;
|
|
18
|
-
support(target: any, propety: any): boolean;
|
|
19
|
-
prepareArgs(target: any, propety: any, req: Request, res: Response): Promise<any[]>;
|
|
20
|
-
intercept(target: any, propety: any, req: Request, res: Response): Promise<void>;
|
|
21
|
-
}>;
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.paramsStore = void 0;
|
|
13
|
-
const no_conflict_1 = require("reflect-metadata/no-conflict");
|
|
14
|
-
const constants_1 = require("../constants");
|
|
15
|
-
exports.paramsStore = Object.freeze({
|
|
16
|
-
has(target, propety, key) {
|
|
17
|
-
const data = this.get(target, propety);
|
|
18
|
-
return data ? data.has(key) : false;
|
|
19
|
-
},
|
|
20
|
-
get(target, propety) {
|
|
21
|
-
if (!propety) {
|
|
22
|
-
return (0, no_conflict_1.getMetadata)(constants_1.KEY_PARAMS_PARAM, target);
|
|
23
|
-
}
|
|
24
|
-
return (0, no_conflict_1.getMetadata)(constants_1.KEY_PARAMS_PARAM, target, propety);
|
|
25
|
-
},
|
|
26
|
-
set(target, propety, value) {
|
|
27
|
-
const data = this.get(target, propety) || new Map();
|
|
28
|
-
data.set(value.key, value);
|
|
29
|
-
(0, no_conflict_1.defineMetadata)(constants_1.KEY_PARAMS_PARAM, data, target, propety);
|
|
30
|
-
},
|
|
31
|
-
delete(target, propety) {
|
|
32
|
-
(0, no_conflict_1.deleteMetadata)(constants_1.KEY_PARAMS_PARAM, target, propety);
|
|
33
|
-
},
|
|
34
|
-
support(target, propety) {
|
|
35
|
-
const params = (0, no_conflict_1.getMetadata)(constants_1.DESIGN_PARAMTYPES, target, propety) || [];
|
|
36
|
-
return params.length > 0;
|
|
37
|
-
},
|
|
38
|
-
prepareArgs(target, propety, req, res) {
|
|
39
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
-
const data = this.get(target, propety);
|
|
41
|
-
if (!data)
|
|
42
|
-
return [];
|
|
43
|
-
const args = [];
|
|
44
|
-
yield Promise.all(Array.from(data.values()).map((value) => __awaiter(this, void 0, void 0, function* () {
|
|
45
|
-
const { key, resolver } = value;
|
|
46
|
-
switch (key) {
|
|
47
|
-
case "req":
|
|
48
|
-
args[value.index] = req;
|
|
49
|
-
break;
|
|
50
|
-
case "res":
|
|
51
|
-
args[value.index] = res;
|
|
52
|
-
break;
|
|
53
|
-
default: {
|
|
54
|
-
const result = yield resolver(req, res);
|
|
55
|
-
args[value.index] = result;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
})));
|
|
59
|
-
return args;
|
|
60
|
-
});
|
|
61
|
-
},
|
|
62
|
-
intercept(target, propety, req, res) {
|
|
63
|
-
return __awaiter(this, void 0, void 0, function* () { });
|
|
64
|
-
},
|
|
65
|
-
});
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { IStore } from "./store.interface";
|
|
2
|
-
interface IRoute {
|
|
3
|
-
className: string;
|
|
4
|
-
method: string;
|
|
5
|
-
path: string;
|
|
6
|
-
handler: (...args: any[]) => any;
|
|
7
|
-
}
|
|
8
|
-
export declare class RouteStore implements IStore<any> {
|
|
9
|
-
has(target: any, property?: any): boolean;
|
|
10
|
-
get(target: any, property?: any): Set<IRoute> | undefined;
|
|
11
|
-
set(target: any, property: any, value: IRoute): void;
|
|
12
|
-
create(target: any, property?: any, key?: any): Set<IRoute> | null;
|
|
13
|
-
delete(target: any, value?: IRoute): void;
|
|
14
|
-
support(target: any, property: any): boolean;
|
|
15
|
-
}
|
|
16
|
-
declare const routeStore: RouteStore;
|
|
17
|
-
export { routeStore };
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.routeStore = exports.RouteStore = void 0;
|
|
4
|
-
const no_conflict_1 = require("reflect-metadata/no-conflict");
|
|
5
|
-
const constants_1 = require("../constants");
|
|
6
|
-
class RouteStore {
|
|
7
|
-
has(target, property) {
|
|
8
|
-
return (0, no_conflict_1.hasMetadata)(constants_1.METADATA_KEYS.ROUTES, target);
|
|
9
|
-
}
|
|
10
|
-
get(target, property) {
|
|
11
|
-
return (0, no_conflict_1.getMetadata)(constants_1.METADATA_KEYS.ROUTES, target);
|
|
12
|
-
}
|
|
13
|
-
set(target, property, value) {
|
|
14
|
-
const routes = this.get(target) || new Set();
|
|
15
|
-
routes.add(value);
|
|
16
|
-
(0, no_conflict_1.defineMetadata)(constants_1.METADATA_KEYS.ROUTES, routes, target);
|
|
17
|
-
}
|
|
18
|
-
create(target, property, key) {
|
|
19
|
-
const data = this.has(target, property)
|
|
20
|
-
? this.get(target, property)
|
|
21
|
-
: new Set();
|
|
22
|
-
(0, no_conflict_1.defineMetadata)(constants_1.METADATA_KEYS.ROUTES, data, target);
|
|
23
|
-
return data;
|
|
24
|
-
}
|
|
25
|
-
delete(target, value) {
|
|
26
|
-
const routes = this.create(target, value === null || value === void 0 ? void 0 : value.className);
|
|
27
|
-
if (!routes)
|
|
28
|
-
return;
|
|
29
|
-
if (value) {
|
|
30
|
-
routes.delete(value);
|
|
31
|
-
(0, no_conflict_1.defineMetadata)(constants_1.METADATA_KEYS.ROUTES, routes, target);
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
(0, no_conflict_1.deleteMetadata)(constants_1.METADATA_KEYS.ROUTES, target);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
support(target, property) {
|
|
38
|
-
return this.has(target, property);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
exports.RouteStore = RouteStore;
|
|
42
|
-
const routeStore = new RouteStore();
|
|
43
|
-
exports.routeStore = routeStore;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export interface IStore<T> {
|
|
2
|
-
has(target: any, property: any): boolean;
|
|
3
|
-
get(target: any, property: any): T | undefined;
|
|
4
|
-
set(target: any, property: any, value: T): void;
|
|
5
|
-
create(target: any, property: any, extra?: Partial<T>): T | null;
|
|
6
|
-
delete(target: any, property?: any): void;
|
|
7
|
-
support(target: any, property: any): boolean;
|
|
8
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = methodTransformer;
|
|
4
|
-
require("reflect-metadata");
|
|
5
|
-
function methodTransformer(target, key, transfrom) {
|
|
6
|
-
const prototype = target.constructor.prototype;
|
|
7
|
-
if (!prototype || prototype.__transformed)
|
|
8
|
-
return;
|
|
9
|
-
prototype.__transformed = true;
|
|
10
|
-
const original = Reflect.getOwnMetadata(key, target);
|
|
11
|
-
if (!(original === null || original === void 0 ? void 0 : original.value))
|
|
12
|
-
return;
|
|
13
|
-
console.log(original, "original");
|
|
14
|
-
original.value = function (...args) {
|
|
15
|
-
console.log("Before method call", args);
|
|
16
|
-
};
|
|
17
|
-
// const descriptor = Object.getOwnPropertyDescriptor(prototype, key);
|
|
18
|
-
// if(!descriptor) return;
|
|
19
|
-
// console.log(descriptor, "descriptor");
|
|
20
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import "reflect-metadata";
|
|
2
|
-
type Constructor<T = any> = new (...args: any[]) => T;
|
|
3
|
-
export declare class MixinBuilder<TClass extends Constructor<any>, Type = InstanceType<TClass>> {
|
|
4
|
-
private __class;
|
|
5
|
-
constructor(__class: TClass);
|
|
6
|
-
mix<NClass extends Constructor<any>>(clazz: NClass): MixinBuilder<NClass & TClass>;
|
|
7
|
-
build(): TClass;
|
|
8
|
-
construct(...args: any[]): Type;
|
|
9
|
-
static mix<NClass extends Constructor<any>>(clazz: NClass): MixinBuilder<NClass, InstanceType<NClass>>;
|
|
10
|
-
}
|
|
11
|
-
export {};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MixinBuilder = void 0;
|
|
4
|
-
require("reflect-metadata");
|
|
5
|
-
class MixinBuilder {
|
|
6
|
-
constructor(__class) {
|
|
7
|
-
this.__class = __class;
|
|
8
|
-
}
|
|
9
|
-
mix(clazz) {
|
|
10
|
-
return new MixinBuilder(Mix(this.__class, clazz));
|
|
11
|
-
}
|
|
12
|
-
build() {
|
|
13
|
-
return this.__class;
|
|
14
|
-
}
|
|
15
|
-
construct(...args) {
|
|
16
|
-
return new this.__class(...args);
|
|
17
|
-
}
|
|
18
|
-
////////////////////////////
|
|
19
|
-
/// Static methods
|
|
20
|
-
////////////////////////////
|
|
21
|
-
static mix(clazz) {
|
|
22
|
-
return new MixinBuilder(clazz);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
exports.MixinBuilder = MixinBuilder;
|
|
26
|
-
const Mix = (a, b) => {
|
|
27
|
-
return class extends a {
|
|
28
|
-
constructor(...args) {
|
|
29
|
-
super(...args);
|
|
30
|
-
Object.assign(this, new b(...args));
|
|
31
|
-
console.log(a);
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
};
|