@zenofolio/hyper-decor 1.0.63 → 1.0.64
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/run-bench.d.ts +1 -0
- package/dist/run-bench.js +190 -0
- package/dist/scripts/test-server.d.ts +1 -0
- package/dist/scripts/test-server.js +110 -0
- package/package.json +1 -1
- package/scripts/test-server.ts +85 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
@@ -0,0 +1,190 @@
|
|
|
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 __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
15
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
16
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
17
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
18
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
19
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
20
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
require("reflect-metadata");
|
|
25
|
+
const src_1 = require("./src");
|
|
26
|
+
const tsyringe_1 = require("tsyringe");
|
|
27
|
+
const request_1 = require("./tests/helpers/request");
|
|
28
|
+
// Global counter to verify execution
|
|
29
|
+
let initCounter = 0;
|
|
30
|
+
const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
|
31
|
+
let StaticServiceA = class StaticServiceA {
|
|
32
|
+
onInit() {
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
yield delay(5);
|
|
35
|
+
initCounter++;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
getValue() { return "A"; }
|
|
39
|
+
};
|
|
40
|
+
StaticServiceA = __decorate([
|
|
41
|
+
(0, tsyringe_1.injectable)(),
|
|
42
|
+
(0, src_1.HyperService)()
|
|
43
|
+
], StaticServiceA);
|
|
44
|
+
let StaticServiceB = class StaticServiceB {
|
|
45
|
+
onInit() {
|
|
46
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
yield delay(5);
|
|
48
|
+
initCounter++;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
getValue() { return "B"; }
|
|
52
|
+
};
|
|
53
|
+
StaticServiceB = __decorate([
|
|
54
|
+
(0, tsyringe_1.injectable)(),
|
|
55
|
+
(0, src_1.HyperService)()
|
|
56
|
+
], StaticServiceB);
|
|
57
|
+
let BenchController = class BenchController {
|
|
58
|
+
verify(res) {
|
|
59
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
res.json({
|
|
61
|
+
count: initCounter,
|
|
62
|
+
status: "ok"
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
__decorate([
|
|
68
|
+
(0, src_1.Get)("/"),
|
|
69
|
+
__param(0, (0, src_1.Res)()),
|
|
70
|
+
__metadata("design:type", Function),
|
|
71
|
+
__metadata("design:paramtypes", [src_1.Response]),
|
|
72
|
+
__metadata("design:returntype", Promise)
|
|
73
|
+
], BenchController.prototype, "verify", null);
|
|
74
|
+
BenchController = __decorate([
|
|
75
|
+
(0, src_1.HyperController)("/verify")
|
|
76
|
+
], BenchController);
|
|
77
|
+
let BenchModule = class BenchModule {
|
|
78
|
+
};
|
|
79
|
+
BenchModule = __decorate([
|
|
80
|
+
(0, src_1.HyperModule)({
|
|
81
|
+
imports: [StaticServiceA, StaticServiceB],
|
|
82
|
+
controllers: [BenchController]
|
|
83
|
+
})
|
|
84
|
+
], BenchModule);
|
|
85
|
+
let App = class App {
|
|
86
|
+
};
|
|
87
|
+
App = __decorate([
|
|
88
|
+
(0, src_1.HyperApp)({
|
|
89
|
+
modules: [BenchModule]
|
|
90
|
+
})
|
|
91
|
+
], App);
|
|
92
|
+
let CircularA = class CircularA {
|
|
93
|
+
constructor(b) {
|
|
94
|
+
this.b = b;
|
|
95
|
+
}
|
|
96
|
+
onInit() {
|
|
97
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
98
|
+
yield delay(10);
|
|
99
|
+
initCounter++;
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
getName() { return "A"; }
|
|
103
|
+
};
|
|
104
|
+
CircularA = __decorate([
|
|
105
|
+
(0, tsyringe_1.injectable)(),
|
|
106
|
+
(0, src_1.HyperService)(),
|
|
107
|
+
__param(0, (0, tsyringe_1.inject)((0, tsyringe_1.delay)(() => CircularB))),
|
|
108
|
+
__metadata("design:paramtypes", [Object])
|
|
109
|
+
], CircularA);
|
|
110
|
+
let CircularB = class CircularB {
|
|
111
|
+
constructor(a) {
|
|
112
|
+
this.a = a;
|
|
113
|
+
}
|
|
114
|
+
onInit() {
|
|
115
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
116
|
+
yield delay(10);
|
|
117
|
+
initCounter++;
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
getName() { return "B"; }
|
|
121
|
+
};
|
|
122
|
+
CircularB = __decorate([
|
|
123
|
+
(0, tsyringe_1.injectable)(),
|
|
124
|
+
(0, src_1.HyperService)(),
|
|
125
|
+
__param(0, (0, tsyringe_1.inject)((0, tsyringe_1.delay)(() => CircularA))),
|
|
126
|
+
__metadata("design:paramtypes", [Object])
|
|
127
|
+
], CircularB);
|
|
128
|
+
let CircularModule = class CircularModule {
|
|
129
|
+
};
|
|
130
|
+
CircularModule = __decorate([
|
|
131
|
+
(0, src_1.HyperModule)({
|
|
132
|
+
imports: [CircularA, CircularB]
|
|
133
|
+
})
|
|
134
|
+
], CircularModule);
|
|
135
|
+
let CircularApp = class CircularApp {
|
|
136
|
+
};
|
|
137
|
+
CircularApp = __decorate([
|
|
138
|
+
(0, src_1.HyperApp)({
|
|
139
|
+
modules: [CircularModule]
|
|
140
|
+
})
|
|
141
|
+
], CircularApp);
|
|
142
|
+
function runBenchmarks() {
|
|
143
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
144
|
+
console.log("Enhanced Performance & Robustness Benchmark");
|
|
145
|
+
// Test 1
|
|
146
|
+
console.log("\n-> should verify service execution and fetch liveliness");
|
|
147
|
+
initCounter = 0;
|
|
148
|
+
tsyringe_1.container.reset();
|
|
149
|
+
const start = Date.now();
|
|
150
|
+
const app = yield (0, src_1.createApplication)(App);
|
|
151
|
+
const duration = Date.now() - start;
|
|
152
|
+
yield app.listen(3005);
|
|
153
|
+
const responseText = yield (0, request_1.request)("/verify", undefined, 3005);
|
|
154
|
+
const response = JSON.parse(responseText);
|
|
155
|
+
console.log(`\n✅ LIVELINESS & EXECUTION:`);
|
|
156
|
+
console.log(`- Startup: ${duration}ms`);
|
|
157
|
+
console.log(`- Services Initialized: ${response.count}`);
|
|
158
|
+
console.log(`- Response: ${responseText}`);
|
|
159
|
+
if (response.status !== "ok")
|
|
160
|
+
throw new Error("Status not ok");
|
|
161
|
+
if (response.count !== 2)
|
|
162
|
+
throw new Error("Count not 2");
|
|
163
|
+
yield app.close();
|
|
164
|
+
// Test 2
|
|
165
|
+
console.log("\n-> should handle circular dependencies with delays");
|
|
166
|
+
tsyringe_1.container.reset();
|
|
167
|
+
initCounter = 0;
|
|
168
|
+
const app2 = yield (0, src_1.createApplication)(CircularApp);
|
|
169
|
+
const a = tsyringe_1.container.resolve(CircularA);
|
|
170
|
+
const b = tsyringe_1.container.resolve(CircularB);
|
|
171
|
+
console.log(`\n🔄 CIRCULAR DEP RESULTS:`);
|
|
172
|
+
console.log(`- CircularA sees name: ${a.b.getName()}`);
|
|
173
|
+
console.log(`- CircularB sees name: ${b.a.getName()}`);
|
|
174
|
+
console.log(`- Init Counter: ${initCounter}`);
|
|
175
|
+
if (a.b.getName() !== "B")
|
|
176
|
+
throw new Error("Mismatch B");
|
|
177
|
+
if (b.a.getName() !== "A")
|
|
178
|
+
throw new Error("Mismatch A");
|
|
179
|
+
if (initCounter !== 2)
|
|
180
|
+
throw new Error("Mismatch initCounter");
|
|
181
|
+
yield app2.close();
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
runBenchmarks().then(() => {
|
|
185
|
+
console.log("\nAll benchmarks finished successfully!");
|
|
186
|
+
process.exit(0);
|
|
187
|
+
}).catch(e => {
|
|
188
|
+
console.error(e);
|
|
189
|
+
process.exit(1);
|
|
190
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
@@ -0,0 +1,110 @@
|
|
|
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 __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
15
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
16
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
17
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
18
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
19
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
20
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
require("reflect-metadata");
|
|
25
|
+
const src_1 = require("../src");
|
|
26
|
+
const tsyringe_1 = require("tsyringe");
|
|
27
|
+
// 1. Setup a Mock Transformer (Zod-like)
|
|
28
|
+
const ZodTransformer = {
|
|
29
|
+
transform: ({ data, schema }) => {
|
|
30
|
+
if (schema._type === "zod") {
|
|
31
|
+
return Object.assign(Object.assign({}, data), { parsed: true, timestamp: Date.now() });
|
|
32
|
+
}
|
|
33
|
+
return data;
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
const mockSchema = { _type: "zod" };
|
|
37
|
+
let AnalyticsService = class AnalyticsService {
|
|
38
|
+
onInit() {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
console.log("Service initialized");
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
AnalyticsService = __decorate([
|
|
45
|
+
(0, tsyringe_1.injectable)(),
|
|
46
|
+
(0, src_1.HyperService)()
|
|
47
|
+
], AnalyticsService);
|
|
48
|
+
let MainController = class MainController {
|
|
49
|
+
status(res) {
|
|
50
|
+
res.json({ status: "alive" });
|
|
51
|
+
}
|
|
52
|
+
createUser(data) {
|
|
53
|
+
return data;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
__decorate([
|
|
57
|
+
(0, src_1.Get)("/status"),
|
|
58
|
+
__param(0, (0, src_1.Res)()),
|
|
59
|
+
__metadata("design:type", Function),
|
|
60
|
+
__metadata("design:paramtypes", [src_1.Response]),
|
|
61
|
+
__metadata("design:returntype", void 0)
|
|
62
|
+
], MainController.prototype, "status", null);
|
|
63
|
+
__decorate([
|
|
64
|
+
(0, src_1.Post)("/user"),
|
|
65
|
+
(0, src_1.Transform)(mockSchema),
|
|
66
|
+
__param(0, (0, src_1.Body)()),
|
|
67
|
+
__metadata("design:type", Function),
|
|
68
|
+
__metadata("design:paramtypes", [Object]),
|
|
69
|
+
__metadata("design:returntype", void 0)
|
|
70
|
+
], MainController.prototype, "createUser", null);
|
|
71
|
+
MainController = __decorate([
|
|
72
|
+
(0, src_1.HyperController)("/api")
|
|
73
|
+
], MainController);
|
|
74
|
+
let MainModule = class MainModule {
|
|
75
|
+
};
|
|
76
|
+
MainModule = __decorate([
|
|
77
|
+
(0, src_1.HyperModule)({
|
|
78
|
+
imports: [AnalyticsService],
|
|
79
|
+
controllers: [MainController]
|
|
80
|
+
})
|
|
81
|
+
], MainModule);
|
|
82
|
+
let FullApp = class FullApp {
|
|
83
|
+
};
|
|
84
|
+
FullApp = __decorate([
|
|
85
|
+
(0, src_1.HyperApp)({
|
|
86
|
+
name: "Standalone Test App",
|
|
87
|
+
version: "1.0.0",
|
|
88
|
+
modules: [MainModule]
|
|
89
|
+
})
|
|
90
|
+
], FullApp);
|
|
91
|
+
function run() {
|
|
92
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
+
console.log("Starting App...");
|
|
94
|
+
const app = yield (0, src_1.createApplication)(FullApp);
|
|
95
|
+
app.useTransform(ZodTransformer);
|
|
96
|
+
const port = 3010;
|
|
97
|
+
yield app.listen(port);
|
|
98
|
+
console.log(`Server listening on http://localhost:${port}`);
|
|
99
|
+
// Close after 5 seconds
|
|
100
|
+
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
101
|
+
console.log("Closing server...");
|
|
102
|
+
yield app.close();
|
|
103
|
+
process.exit(0);
|
|
104
|
+
}), 5000);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
run().catch(err => {
|
|
108
|
+
console.error(err);
|
|
109
|
+
process.exit(1);
|
|
110
|
+
});
|
package/package.json
CHANGED
|
@@ -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
|
+
});
|