@cinnabun/core 0.0.1 → 0.0.2
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/__tests__/autowired.test.d.ts +1 -0
- package/dist/__tests__/autowired.test.js +109 -0
- package/dist/__tests__/autowired.test.js.map +1 -0
- package/dist/__tests__/cinnabun-application.test.d.ts +1 -0
- package/dist/__tests__/cinnabun-application.test.js +96 -0
- package/dist/__tests__/cinnabun-application.test.js.map +1 -0
- package/dist/__tests__/cinnabun-factory.test.d.ts +1 -0
- package/dist/__tests__/cinnabun-factory.test.js +269 -0
- package/dist/__tests__/cinnabun-factory.test.js.map +1 -0
- package/dist/__tests__/circular-dependency.test.d.ts +1 -0
- package/dist/__tests__/circular-dependency.test.js +318 -0
- package/dist/__tests__/circular-dependency.test.js.map +1 -0
- package/dist/__tests__/compression.test.d.ts +1 -0
- package/dist/__tests__/compression.test.js +459 -0
- package/dist/__tests__/compression.test.js.map +1 -0
- package/dist/__tests__/config.test.d.ts +1 -0
- package/dist/__tests__/config.test.js +86 -0
- package/dist/__tests__/config.test.js.map +1 -0
- package/dist/__tests__/cors.test.d.ts +1 -0
- package/dist/__tests__/cors.test.js +575 -0
- package/dist/__tests__/cors.test.js.map +1 -0
- package/dist/__tests__/env-config.test.d.ts +1 -0
- package/dist/__tests__/env-config.test.js +367 -0
- package/dist/__tests__/env-config.test.js.map +1 -0
- package/dist/__tests__/exception.test.d.ts +1 -0
- package/dist/__tests__/exception.test.js +207 -0
- package/dist/__tests__/exception.test.js.map +1 -0
- package/dist/__tests__/guards-interceptors.test.d.ts +1 -0
- package/dist/__tests__/guards-interceptors.test.js +660 -0
- package/dist/__tests__/guards-interceptors.test.js.map +1 -0
- package/dist/__tests__/health-check.test.d.ts +1 -0
- package/dist/__tests__/health-check.test.js +240 -0
- package/dist/__tests__/health-check.test.js.map +1 -0
- package/dist/__tests__/http.test.d.ts +1 -0
- package/dist/__tests__/http.test.js +629 -0
- package/dist/__tests__/http.test.js.map +1 -0
- package/dist/__tests__/integration/e2e.test.d.ts +1 -0
- package/dist/__tests__/integration/e2e.test.js +192 -0
- package/dist/__tests__/integration/e2e.test.js.map +1 -0
- package/dist/__tests__/integration/performance.bench.d.ts +1 -0
- package/dist/__tests__/integration/performance.bench.js +129 -0
- package/dist/__tests__/integration/performance.bench.js.map +1 -0
- package/dist/__tests__/integration/validation.test.d.ts +1 -0
- package/dist/__tests__/integration/validation.test.js +133 -0
- package/dist/__tests__/integration/validation.test.js.map +1 -0
- package/dist/__tests__/lifecycle-management.test.d.ts +1 -0
- package/dist/__tests__/lifecycle-management.test.js +688 -0
- package/dist/__tests__/lifecycle-management.test.js.map +1 -0
- package/dist/__tests__/lifecycle.test.d.ts +1 -0
- package/dist/__tests__/lifecycle.test.js +196 -0
- package/dist/__tests__/lifecycle.test.js.map +1 -0
- package/dist/__tests__/logger.test.d.ts +1 -0
- package/dist/__tests__/logger.test.js +109 -0
- package/dist/__tests__/logger.test.js.map +1 -0
- package/dist/__tests__/middleware.test.d.ts +1 -0
- package/dist/__tests__/middleware.test.js +329 -0
- package/dist/__tests__/middleware.test.js.map +1 -0
- package/dist/__tests__/module.test.d.ts +1 -0
- package/dist/__tests__/module.test.js +280 -0
- package/dist/__tests__/module.test.js.map +1 -0
- package/dist/__tests__/plugin.test.d.ts +1 -0
- package/dist/__tests__/plugin.test.js +283 -0
- package/dist/__tests__/plugin.test.js.map +1 -0
- package/dist/__tests__/request-logger.test.d.ts +1 -0
- package/dist/__tests__/request-logger.test.js +342 -0
- package/dist/__tests__/request-logger.test.js.map +1 -0
- package/dist/__tests__/request-mapping.test.d.ts +1 -0
- package/dist/__tests__/request-mapping.test.js +201 -0
- package/dist/__tests__/request-mapping.test.js.map +1 -0
- package/dist/__tests__/routes.test.d.ts +1 -0
- package/dist/__tests__/routes.test.js +119 -0
- package/dist/__tests__/routes.test.js.map +1 -0
- package/dist/__tests__/scan-fixtures/controllers/hello.controller.d.ts +4 -0
- package/dist/__tests__/scan-fixtures/controllers/hello.controller.js +28 -0
- package/dist/__tests__/scan-fixtures/controllers/hello.controller.js.map +1 -0
- package/dist/__tests__/scan-fixtures/modules/feature.module.d.ts +6 -0
- package/dist/__tests__/scan-fixtures/modules/feature.module.js +28 -0
- package/dist/__tests__/scan-fixtures/modules/feature.module.js.map +1 -0
- package/dist/__tests__/scan-fixtures/services/greeting.service.d.ts +4 -0
- package/dist/__tests__/scan-fixtures/services/greeting.service.js +18 -0
- package/dist/__tests__/scan-fixtures/services/greeting.service.js.map +1 -0
- package/dist/__tests__/scanner.test.d.ts +1 -0
- package/dist/__tests__/scanner.test.js +49 -0
- package/dist/__tests__/scanner.test.js.map +1 -0
- package/dist/__tests__/validation.test.d.ts +1 -0
- package/dist/__tests__/validation.test.js +561 -0
- package/dist/__tests__/validation.test.js.map +1 -0
- package/dist/__tests__/websocket-auth.test.d.ts +1 -0
- package/dist/__tests__/websocket-auth.test.js +431 -0
- package/dist/__tests__/websocket-auth.test.js.map +1 -0
- package/dist/__tests__/websocket-decorators.test.d.ts +1 -0
- package/dist/__tests__/websocket-decorators.test.js +173 -0
- package/dist/__tests__/websocket-decorators.test.js.map +1 -0
- package/dist/__tests__/websocket-validation.test.d.ts +1 -0
- package/dist/__tests__/websocket-validation.test.js +827 -0
- package/dist/__tests__/websocket-validation.test.js.map +1 -0
- package/dist/__tests__/websocket.test.d.ts +1 -0
- package/dist/__tests__/websocket.test.js +415 -0
- package/dist/__tests__/websocket.test.js.map +1 -0
- package/dist/config/config.module.d.ts +2 -0
- package/dist/config/config.module.js +18 -0
- package/dist/config/config.module.js.map +1 -0
- package/dist/config/config.service.d.ts +15 -0
- package/dist/config/config.service.js +58 -0
- package/dist/config/config.service.js.map +1 -0
- package/dist/config/schemas.d.ts +107 -0
- package/dist/config/schemas.js +87 -0
- package/dist/config/schemas.js.map +1 -0
- package/dist/core/app.d.ts +44 -0
- package/dist/core/app.js +178 -0
- package/dist/core/app.js.map +1 -0
- package/dist/core/cinnabun-factory.d.ts +5 -0
- package/dist/core/cinnabun-factory.js +130 -0
- package/dist/core/cinnabun-factory.js.map +1 -0
- package/dist/core/config-loader.d.ts +2 -0
- package/dist/core/config-loader.js +76 -0
- package/dist/core/config-loader.js.map +1 -0
- package/dist/core/config.d.ts +12 -0
- package/dist/core/config.js +27 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/container.d.ts +10 -0
- package/dist/core/container.js +82 -0
- package/dist/core/container.js.map +1 -0
- package/dist/core/dependency-validator.d.ts +12 -0
- package/dist/core/dependency-validator.js +76 -0
- package/dist/core/dependency-validator.js.map +1 -0
- package/dist/core/guard.d.ts +3 -0
- package/dist/core/guard.js +2 -0
- package/dist/core/guard.js.map +1 -0
- package/dist/core/interceptor.d.ts +4 -0
- package/dist/core/interceptor.js +2 -0
- package/dist/core/interceptor.js.map +1 -0
- package/dist/core/logger.d.ts +15 -0
- package/dist/core/logger.js +71 -0
- package/dist/core/logger.js.map +1 -0
- package/dist/core/module-resolver.d.ts +6 -0
- package/dist/core/module-resolver.js +67 -0
- package/dist/core/module-resolver.js.map +1 -0
- package/dist/core/plugin.d.ts +12 -0
- package/dist/core/plugin.js +2 -0
- package/dist/core/plugin.js.map +1 -0
- package/dist/core/router.d.ts +38 -0
- package/dist/core/router.js +406 -0
- package/dist/core/router.js.map +1 -0
- package/dist/core/scanner.d.ts +7 -0
- package/dist/core/scanner.js +83 -0
- package/dist/core/scanner.js.map +1 -0
- package/dist/core/shutdown-manager.d.ts +15 -0
- package/dist/core/shutdown-manager.js +68 -0
- package/dist/core/shutdown-manager.js.map +1 -0
- package/dist/core/websocket-handler.d.ts +41 -0
- package/dist/core/websocket-handler.js +242 -0
- package/dist/core/websocket-handler.js.map +1 -0
- package/dist/decorators/autowired.d.ts +3 -0
- package/dist/decorators/autowired.js +11 -0
- package/dist/decorators/autowired.js.map +1 -0
- package/dist/decorators/cinnabun-application.d.ts +14 -0
- package/dist/decorators/cinnabun-application.js +17 -0
- package/dist/decorators/cinnabun-application.js.map +1 -0
- package/dist/decorators/lifecycle.d.ts +2 -0
- package/dist/decorators/lifecycle.js +12 -0
- package/dist/decorators/lifecycle.js.map +1 -0
- package/dist/decorators/middleware.d.ts +2 -0
- package/dist/decorators/middleware.js +12 -0
- package/dist/decorators/middleware.js.map +1 -0
- package/dist/decorators/module.d.ts +10 -0
- package/dist/decorators/module.js +13 -0
- package/dist/decorators/module.js.map +1 -0
- package/dist/decorators/on-shutdown.d.ts +1 -0
- package/dist/decorators/on-shutdown.js +10 -0
- package/dist/decorators/on-shutdown.js.map +1 -0
- package/dist/decorators/params.d.ts +6 -0
- package/dist/decorators/params.js +31 -0
- package/dist/decorators/params.js.map +1 -0
- package/dist/decorators/request-mapping.d.ts +7 -0
- package/dist/decorators/request-mapping.js +34 -0
- package/dist/decorators/request-mapping.js.map +1 -0
- package/dist/decorators/response.d.ts +2 -0
- package/dist/decorators/response.js +17 -0
- package/dist/decorators/response.js.map +1 -0
- package/dist/decorators/rest-controller.d.ts +1 -0
- package/dist/decorators/rest-controller.js +19 -0
- package/dist/decorators/rest-controller.js.map +1 -0
- package/dist/decorators/routes.d.ts +5 -0
- package/dist/decorators/routes.js +19 -0
- package/dist/decorators/routes.js.map +1 -0
- package/dist/decorators/service.d.ts +1 -0
- package/dist/decorators/service.js +7 -0
- package/dist/decorators/service.js.map +1 -0
- package/dist/decorators/use-guard.d.ts +2 -0
- package/dist/decorators/use-guard.js +12 -0
- package/dist/decorators/use-guard.js.map +1 -0
- package/dist/decorators/use-interceptor.d.ts +2 -0
- package/dist/decorators/use-interceptor.js +12 -0
- package/dist/decorators/use-interceptor.js.map +1 -0
- package/dist/decorators/validate.d.ts +12 -0
- package/dist/decorators/validate.js +7 -0
- package/dist/decorators/validate.js.map +1 -0
- package/dist/decorators/websocket.d.ts +9 -0
- package/dist/decorators/websocket.js +38 -0
- package/dist/decorators/websocket.js.map +1 -0
- package/dist/decorators/ws-event.d.ts +28 -0
- package/dist/decorators/ws-event.js +37 -0
- package/dist/decorators/ws-event.js.map +1 -0
- package/dist/decorators/ws-gateway.d.ts +18 -0
- package/dist/decorators/ws-gateway.js +24 -0
- package/dist/decorators/ws-gateway.js.map +1 -0
- package/dist/dev/index.d.ts +6 -0
- package/dist/dev/index.js +28 -0
- package/dist/dev/index.js.map +1 -0
- package/dist/exceptions/circular-dependency-error.d.ts +5 -0
- package/dist/exceptions/circular-dependency-error.js +16 -0
- package/dist/exceptions/circular-dependency-error.js.map +1 -0
- package/dist/exceptions/http-exception.d.ts +41 -0
- package/dist/exceptions/http-exception.js +96 -0
- package/dist/exceptions/http-exception.js.map +1 -0
- package/dist/guards/jwt-websocket.guard.d.ts +11 -0
- package/dist/guards/jwt-websocket.guard.js +37 -0
- package/dist/guards/jwt-websocket.guard.js.map +1 -0
- package/dist/guards/websocket-auth.guard.d.ts +16 -0
- package/dist/guards/websocket-auth.guard.js +43 -0
- package/dist/guards/websocket-auth.guard.js.map +1 -0
- package/dist/health/health-check.service.d.ts +45 -0
- package/dist/health/health-check.service.js +95 -0
- package/dist/health/health-check.service.js.map +1 -0
- package/dist/health/health.controller.d.ts +15 -0
- package/dist/health/health.controller.js +63 -0
- package/dist/health/health.controller.js.map +1 -0
- package/dist/health/health.module.d.ts +2 -0
- package/dist/health/health.module.js +20 -0
- package/dist/health/health.module.js.map +1 -0
- package/dist/index.d.ts +74 -11
- package/dist/index.js +54 -0
- package/dist/index.js.map +1 -0
- package/dist/metadata/storage.d.ts +171 -0
- package/dist/metadata/storage.js +257 -0
- package/dist/metadata/storage.js.map +1 -0
- package/dist/middleware/compression.middleware.d.ts +32 -0
- package/dist/middleware/compression.middleware.js +113 -0
- package/dist/middleware/compression.middleware.js.map +1 -0
- package/dist/middleware/cors.middleware.d.ts +18 -0
- package/dist/middleware/cors.middleware.js +79 -0
- package/dist/middleware/cors.middleware.js.map +1 -0
- package/dist/middleware/performance-tracker.middleware.d.ts +35 -0
- package/dist/middleware/performance-tracker.middleware.js +79 -0
- package/dist/middleware/performance-tracker.middleware.js.map +1 -0
- package/dist/middleware/request-logger.middleware.d.ts +32 -0
- package/dist/middleware/request-logger.middleware.js +125 -0
- package/dist/middleware/request-logger.middleware.js.map +1 -0
- package/dist/types/index.d.ts +14 -0
- package/dist/types/index.js +5 -0
- package/dist/types/index.js.map +1 -0
- package/dist/validation/helpers.d.ts +36 -0
- package/dist/validation/helpers.js +27 -0
- package/dist/validation/helpers.js.map +1 -0
- package/dist/websocket/error.d.ts +27 -0
- package/dist/websocket/error.js +38 -0
- package/dist/websocket/error.js.map +1 -0
- package/package.json +38 -5
- package/LICENSE +0 -9
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
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;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
+
};
|
|
13
|
+
import "reflect-metadata";
|
|
14
|
+
import { describe, it, expect, afterEach } from "bun:test";
|
|
15
|
+
import { CinnabunApplication } from "../core/app.js";
|
|
16
|
+
import { RestController } from "../decorators/rest-controller.js";
|
|
17
|
+
import { GetMapping } from "../decorators/routes.js";
|
|
18
|
+
import { RequestMapping } from "../decorators/request-mapping.js";
|
|
19
|
+
import { Param, Body } from "../decorators/params.js";
|
|
20
|
+
let app = null;
|
|
21
|
+
afterEach(async () => {
|
|
22
|
+
if (app) {
|
|
23
|
+
await app.close();
|
|
24
|
+
app = null;
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
function url(path) {
|
|
28
|
+
return `http://localhost:${app.getPort()}${path}`;
|
|
29
|
+
}
|
|
30
|
+
describe("@RequestMapping", () => {
|
|
31
|
+
it("sets class-level base path", async () => {
|
|
32
|
+
let ApiController = class ApiController {
|
|
33
|
+
health() {
|
|
34
|
+
return "ok";
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
__decorate([
|
|
38
|
+
GetMapping("/health"),
|
|
39
|
+
__metadata("design:type", Function),
|
|
40
|
+
__metadata("design:paramtypes", []),
|
|
41
|
+
__metadata("design:returntype", void 0)
|
|
42
|
+
], ApiController.prototype, "health", null);
|
|
43
|
+
ApiController = __decorate([
|
|
44
|
+
RestController(),
|
|
45
|
+
RequestMapping("/api/v1")
|
|
46
|
+
], ApiController);
|
|
47
|
+
app = await CinnabunApplication.create({ controllers: [ApiController] });
|
|
48
|
+
await app.listen(0);
|
|
49
|
+
const res = await fetch(url("/api/v1/health"));
|
|
50
|
+
expect(res.status).toBe(200);
|
|
51
|
+
expect(await res.text()).toBe("ok");
|
|
52
|
+
});
|
|
53
|
+
it("stacks with @RestController base path", async () => {
|
|
54
|
+
let VersionedController = class VersionedController {
|
|
55
|
+
status() {
|
|
56
|
+
return "ok";
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
__decorate([
|
|
60
|
+
GetMapping("/status"),
|
|
61
|
+
__metadata("design:type", Function),
|
|
62
|
+
__metadata("design:paramtypes", []),
|
|
63
|
+
__metadata("design:returntype", void 0)
|
|
64
|
+
], VersionedController.prototype, "status", null);
|
|
65
|
+
VersionedController = __decorate([
|
|
66
|
+
RestController("/api"),
|
|
67
|
+
RequestMapping("/v2")
|
|
68
|
+
], VersionedController);
|
|
69
|
+
app = await CinnabunApplication.create({
|
|
70
|
+
controllers: [VersionedController],
|
|
71
|
+
});
|
|
72
|
+
await app.listen(0);
|
|
73
|
+
const res = await fetch(url("/api/v2/status"));
|
|
74
|
+
expect(res.status).toBe(200);
|
|
75
|
+
expect(await res.text()).toBe("ok");
|
|
76
|
+
});
|
|
77
|
+
it("registers method-level route with explicit method", async () => {
|
|
78
|
+
let ProductController = class ProductController {
|
|
79
|
+
create(body) {
|
|
80
|
+
return body;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
__decorate([
|
|
84
|
+
RequestMapping({ path: "/", method: "POST" }),
|
|
85
|
+
__param(0, Body()),
|
|
86
|
+
__metadata("design:type", Function),
|
|
87
|
+
__metadata("design:paramtypes", [Object]),
|
|
88
|
+
__metadata("design:returntype", void 0)
|
|
89
|
+
], ProductController.prototype, "create", null);
|
|
90
|
+
ProductController = __decorate([
|
|
91
|
+
RestController("/products")
|
|
92
|
+
], ProductController);
|
|
93
|
+
app = await CinnabunApplication.create({
|
|
94
|
+
controllers: [ProductController],
|
|
95
|
+
});
|
|
96
|
+
await app.listen(0);
|
|
97
|
+
const res = await fetch(url("/products/"), {
|
|
98
|
+
method: "POST",
|
|
99
|
+
headers: { "Content-Type": "application/json" },
|
|
100
|
+
body: JSON.stringify({ name: "test" }),
|
|
101
|
+
});
|
|
102
|
+
expect(res.status).toBe(200);
|
|
103
|
+
const result = await res.json();
|
|
104
|
+
expect(result).toEqual({ name: "test" });
|
|
105
|
+
});
|
|
106
|
+
it("defaults to GET when method is omitted", async () => {
|
|
107
|
+
let ItemController = class ItemController {
|
|
108
|
+
findAll() {
|
|
109
|
+
return [];
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
__decorate([
|
|
113
|
+
RequestMapping({ path: "/" }),
|
|
114
|
+
__metadata("design:type", Function),
|
|
115
|
+
__metadata("design:paramtypes", []),
|
|
116
|
+
__metadata("design:returntype", void 0)
|
|
117
|
+
], ItemController.prototype, "findAll", null);
|
|
118
|
+
ItemController = __decorate([
|
|
119
|
+
RestController("/items")
|
|
120
|
+
], ItemController);
|
|
121
|
+
app = await CinnabunApplication.create({ controllers: [ItemController] });
|
|
122
|
+
await app.listen(0);
|
|
123
|
+
const res = await fetch(url("/items/"));
|
|
124
|
+
expect(res.status).toBe(200);
|
|
125
|
+
expect(await res.json()).toEqual([]);
|
|
126
|
+
});
|
|
127
|
+
it("defaults path to / when omitted", async () => {
|
|
128
|
+
let HealthController = class HealthController {
|
|
129
|
+
check() {
|
|
130
|
+
return { status: "up" };
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
__decorate([
|
|
134
|
+
RequestMapping({ method: "GET" }),
|
|
135
|
+
__metadata("design:type", Function),
|
|
136
|
+
__metadata("design:paramtypes", []),
|
|
137
|
+
__metadata("design:returntype", void 0)
|
|
138
|
+
], HealthController.prototype, "check", null);
|
|
139
|
+
HealthController = __decorate([
|
|
140
|
+
RestController("/health")
|
|
141
|
+
], HealthController);
|
|
142
|
+
app = await CinnabunApplication.create({ controllers: [HealthController] });
|
|
143
|
+
await app.listen(0);
|
|
144
|
+
const res = await fetch(url("/health/"));
|
|
145
|
+
expect(res.status).toBe(200);
|
|
146
|
+
expect(await res.json()).toEqual({ status: "up" });
|
|
147
|
+
});
|
|
148
|
+
it("works alongside shorthand decorators", async () => {
|
|
149
|
+
let MixedController = class MixedController {
|
|
150
|
+
getA() {
|
|
151
|
+
return "a";
|
|
152
|
+
}
|
|
153
|
+
getB() {
|
|
154
|
+
return "b";
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
__decorate([
|
|
158
|
+
GetMapping("/a"),
|
|
159
|
+
__metadata("design:type", Function),
|
|
160
|
+
__metadata("design:paramtypes", []),
|
|
161
|
+
__metadata("design:returntype", void 0)
|
|
162
|
+
], MixedController.prototype, "getA", null);
|
|
163
|
+
__decorate([
|
|
164
|
+
RequestMapping({ path: "/b", method: "GET" }),
|
|
165
|
+
__metadata("design:type", Function),
|
|
166
|
+
__metadata("design:paramtypes", []),
|
|
167
|
+
__metadata("design:returntype", void 0)
|
|
168
|
+
], MixedController.prototype, "getB", null);
|
|
169
|
+
MixedController = __decorate([
|
|
170
|
+
RestController("/mixed")
|
|
171
|
+
], MixedController);
|
|
172
|
+
app = await CinnabunApplication.create({ controllers: [MixedController] });
|
|
173
|
+
await app.listen(0);
|
|
174
|
+
const resA = await fetch(url("/mixed/a"));
|
|
175
|
+
expect(await resA.text()).toBe("a");
|
|
176
|
+
const resB = await fetch(url("/mixed/b"));
|
|
177
|
+
expect(await resB.text()).toBe("b");
|
|
178
|
+
});
|
|
179
|
+
it("supports path parameters with method-level @RequestMapping", async () => {
|
|
180
|
+
let UserController = class UserController {
|
|
181
|
+
find(id) {
|
|
182
|
+
return { id };
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
__decorate([
|
|
186
|
+
RequestMapping({ path: "/:id", method: "GET" }),
|
|
187
|
+
__param(0, Param("id")),
|
|
188
|
+
__metadata("design:type", Function),
|
|
189
|
+
__metadata("design:paramtypes", [String]),
|
|
190
|
+
__metadata("design:returntype", void 0)
|
|
191
|
+
], UserController.prototype, "find", null);
|
|
192
|
+
UserController = __decorate([
|
|
193
|
+
RestController("/users")
|
|
194
|
+
], UserController);
|
|
195
|
+
app = await CinnabunApplication.create({ controllers: [UserController] });
|
|
196
|
+
await app.listen(0);
|
|
197
|
+
const res = await fetch(url("/users/42"));
|
|
198
|
+
expect(await res.json()).toEqual({ id: "42" });
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
//# sourceMappingURL=request-mapping.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-mapping.test.js","sourceRoot":"","sources":["../../src/__tests__/request-mapping.test.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE3D,OAAO,EAAE,mBAAm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EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;IACjD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
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;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import "reflect-metadata";
|
|
11
|
+
import { describe, it, expect } from "bun:test";
|
|
12
|
+
import { RestController } from "../decorators/rest-controller.js";
|
|
13
|
+
import { GetMapping, PostMapping, PutMapping, DeleteMapping, PatchMapping, } from "../decorators/routes.js";
|
|
14
|
+
import { metadataStorage } from "../metadata/storage.js";
|
|
15
|
+
describe("route decorators", () => {
|
|
16
|
+
it("registers GET route metadata", () => {
|
|
17
|
+
let ItemController = class ItemController {
|
|
18
|
+
findAll() { }
|
|
19
|
+
findById() { }
|
|
20
|
+
};
|
|
21
|
+
__decorate([
|
|
22
|
+
GetMapping("/"),
|
|
23
|
+
__metadata("design:type", Function),
|
|
24
|
+
__metadata("design:paramtypes", []),
|
|
25
|
+
__metadata("design:returntype", void 0)
|
|
26
|
+
], ItemController.prototype, "findAll", null);
|
|
27
|
+
__decorate([
|
|
28
|
+
GetMapping("/:id"),
|
|
29
|
+
__metadata("design:type", Function),
|
|
30
|
+
__metadata("design:paramtypes", []),
|
|
31
|
+
__metadata("design:returntype", void 0)
|
|
32
|
+
], ItemController.prototype, "findById", null);
|
|
33
|
+
ItemController = __decorate([
|
|
34
|
+
RestController("/items")
|
|
35
|
+
], ItemController);
|
|
36
|
+
const routes = metadataStorage.getRoutesFor(ItemController);
|
|
37
|
+
expect(routes).toHaveLength(2);
|
|
38
|
+
expect(routes[0]).toMatchObject({ httpMethod: "GET", path: "/" });
|
|
39
|
+
expect(routes[1]).toMatchObject({ httpMethod: "GET", path: "/:id" });
|
|
40
|
+
});
|
|
41
|
+
it("stores controller base path", () => {
|
|
42
|
+
let ApiController = class ApiController {
|
|
43
|
+
};
|
|
44
|
+
ApiController = __decorate([
|
|
45
|
+
RestController("/api/v1")
|
|
46
|
+
], ApiController);
|
|
47
|
+
expect(metadataStorage.getControllerPath(ApiController)).toBe("/api/v1");
|
|
48
|
+
});
|
|
49
|
+
it("defaults base path to empty string", () => {
|
|
50
|
+
let RootController = class RootController {
|
|
51
|
+
};
|
|
52
|
+
RootController = __decorate([
|
|
53
|
+
RestController()
|
|
54
|
+
], RootController);
|
|
55
|
+
expect(metadataStorage.getControllerPath(RootController)).toBe("");
|
|
56
|
+
});
|
|
57
|
+
it("normalizes base path - adds leading slash", () => {
|
|
58
|
+
let UsersController = class UsersController {
|
|
59
|
+
};
|
|
60
|
+
UsersController = __decorate([
|
|
61
|
+
RestController("users")
|
|
62
|
+
], UsersController);
|
|
63
|
+
expect(metadataStorage.getControllerPath(UsersController)).toBe("/users");
|
|
64
|
+
});
|
|
65
|
+
it("normalizes base path - removes trailing slash", () => {
|
|
66
|
+
let UsersController2 = class UsersController2 {
|
|
67
|
+
};
|
|
68
|
+
UsersController2 = __decorate([
|
|
69
|
+
RestController("/users/")
|
|
70
|
+
], UsersController2);
|
|
71
|
+
expect(metadataStorage.getControllerPath(UsersController2)).toBe("/users");
|
|
72
|
+
});
|
|
73
|
+
it("registers all HTTP methods", () => {
|
|
74
|
+
let ResourceController = class ResourceController {
|
|
75
|
+
get() { }
|
|
76
|
+
post() { }
|
|
77
|
+
put() { }
|
|
78
|
+
del() { }
|
|
79
|
+
patch() { }
|
|
80
|
+
};
|
|
81
|
+
__decorate([
|
|
82
|
+
GetMapping("/"),
|
|
83
|
+
__metadata("design:type", Function),
|
|
84
|
+
__metadata("design:paramtypes", []),
|
|
85
|
+
__metadata("design:returntype", void 0)
|
|
86
|
+
], ResourceController.prototype, "get", null);
|
|
87
|
+
__decorate([
|
|
88
|
+
PostMapping("/"),
|
|
89
|
+
__metadata("design:type", Function),
|
|
90
|
+
__metadata("design:paramtypes", []),
|
|
91
|
+
__metadata("design:returntype", void 0)
|
|
92
|
+
], ResourceController.prototype, "post", null);
|
|
93
|
+
__decorate([
|
|
94
|
+
PutMapping("/:id"),
|
|
95
|
+
__metadata("design:type", Function),
|
|
96
|
+
__metadata("design:paramtypes", []),
|
|
97
|
+
__metadata("design:returntype", void 0)
|
|
98
|
+
], ResourceController.prototype, "put", null);
|
|
99
|
+
__decorate([
|
|
100
|
+
DeleteMapping("/:id"),
|
|
101
|
+
__metadata("design:type", Function),
|
|
102
|
+
__metadata("design:paramtypes", []),
|
|
103
|
+
__metadata("design:returntype", void 0)
|
|
104
|
+
], ResourceController.prototype, "del", null);
|
|
105
|
+
__decorate([
|
|
106
|
+
PatchMapping("/:id"),
|
|
107
|
+
__metadata("design:type", Function),
|
|
108
|
+
__metadata("design:paramtypes", []),
|
|
109
|
+
__metadata("design:returntype", void 0)
|
|
110
|
+
], ResourceController.prototype, "patch", null);
|
|
111
|
+
ResourceController = __decorate([
|
|
112
|
+
RestController("/res")
|
|
113
|
+
], ResourceController);
|
|
114
|
+
const routes = metadataStorage.getRoutesFor(ResourceController);
|
|
115
|
+
const methods = routes.map((r) => r.httpMethod);
|
|
116
|
+
expect(methods).toEqual(["GET", "POST", "PUT", "DELETE", "PATCH"]);
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
//# s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,KAAI,CAAC;YAER,GAAG,KAAI,CAAC;YAER,KAAK,KAAI,CAAC;SACX,CAAA;QATC;YADC,UAAU,CAAC,GAAG,CAAC;;;;qDACR;QAER;YADC,WAAW,CAAC,GAAG,CAAC;;;;sDACR;QAET;YADC,UAAU,CAAC,MAAM,CAAC;;;;qDACX;QAER;YADC,aAAa,CAAC,MAAM,CAAC;;;;qDACd;QAER;YADC,YAAY,CAAC,MAAM,CAAC;;;;uDACX;QAVN,kBAAkB;YADvB,cAAc,CAAC,MAAM,CAAC;WACjB,kBAAkB,CAWvB;QAED,MAAM,MAAM,GAAG,eAAe,CAAC,YAAY,CAAC,kBAAkB,CAAC,CAAC;QAChE,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;QAChD,MAAM,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC;IACrE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
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;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import "reflect-metadata";
|
|
11
|
+
import { RestController } from "../../../decorators/rest-controller.js";
|
|
12
|
+
import { GetMapping } from "../../../decorators/routes.js";
|
|
13
|
+
let HelloScanController = class HelloScanController {
|
|
14
|
+
hello() {
|
|
15
|
+
return "world";
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
__decorate([
|
|
19
|
+
GetMapping("/"),
|
|
20
|
+
__metadata("design:type", Function),
|
|
21
|
+
__metadata("design:paramtypes", []),
|
|
22
|
+
__metadata("design:returntype", void 0)
|
|
23
|
+
], HelloScanController.prototype, "hello", null);
|
|
24
|
+
HelloScanController = __decorate([
|
|
25
|
+
RestController("/hello")
|
|
26
|
+
], HelloScanController);
|
|
27
|
+
export { HelloScanController };
|
|
28
|
+
//# sourceMappingURL=hello.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hello.controller.js","sourceRoot":"","sources":["../../../../src/__tests__/scan-fixtures/controllers/hello.controller.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAC;AACxE,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAGpD,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAE9B,KAAK;QACH,OAAO,OAAO,CAAC;IACjB,CAAC;CACF,CAAA;AAHC;IADC,UAAU,CAAC,GAAG,CAAC;;;;gDAGf;AAJU,mBAAmB;IAD/B,cAAc,CAAC,QAAQ,CAAC;GACZ,mBAAmB,CAK/B"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
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;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import "reflect-metadata";
|
|
8
|
+
import { Module } from "../../../decorators/module.js";
|
|
9
|
+
import { Service } from "../../../decorators/service.js";
|
|
10
|
+
let FeatureScanService = class FeatureScanService {
|
|
11
|
+
getData() {
|
|
12
|
+
return "feature-data";
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
FeatureScanService = __decorate([
|
|
16
|
+
Service()
|
|
17
|
+
], FeatureScanService);
|
|
18
|
+
export { FeatureScanService };
|
|
19
|
+
let FeatureScanModule = class FeatureScanModule {
|
|
20
|
+
};
|
|
21
|
+
FeatureScanModule = __decorate([
|
|
22
|
+
Module({
|
|
23
|
+
providers: [FeatureScanService],
|
|
24
|
+
exports: [FeatureScanService],
|
|
25
|
+
})
|
|
26
|
+
], FeatureScanModule);
|
|
27
|
+
export { FeatureScanModule };
|
|
28
|
+
//# sourceMappingURL=feature.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feature.module.js","sourceRoot":"","sources":["../../../../src/__tests__/scan-fixtures/modules/feature.module.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAC;AAGlD,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAC7B,OAAO;QACL,OAAO,cAAc,CAAC;IACxB,CAAC;CACF,CAAA;AAJY,kBAAkB;IAD9B,OAAO,EAAE;GACG,kBAAkB,CAI9B;;AAMM,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;CAAG,CAAA;AAApB,iBAAiB;IAJ7B,MAAM,CAAC;QACN,SAAS,EAAE,CAAC,kBAAkB,CAAC;QAC/B,OAAO,EAAE,CAAC,kBAAkB,CAAC;KAC9B,CAAC;GACW,iBAAiB,CAAG"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
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;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import "reflect-metadata";
|
|
8
|
+
import { Service } from "../../../decorators/service.js";
|
|
9
|
+
let GreetingScanService = class GreetingScanService {
|
|
10
|
+
greet() {
|
|
11
|
+
return "hello";
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
GreetingScanService = __decorate([
|
|
15
|
+
Service()
|
|
16
|
+
], GreetingScanService);
|
|
17
|
+
export { GreetingScanService };
|
|
18
|
+
//# sourceMappingURL=greeting.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"greeting.service.js","sourceRoot":"","sources":["../../../../src/__tests__/scan-fixtures/services/greeting.service.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAC;AAGlD,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAC9B,KAAK;QACH,OAAO,OAAO,CAAC;IACjB,CAAC;CACF,CAAA;AAJY,mBAAmB;IAD/B,OAAO,EAAE;GACG,mBAAmB,CAI/B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
import { describe, it, expect } from "bun:test";
|
|
3
|
+
import { resolve } from "path";
|
|
4
|
+
import { scanComponents } from "../core/scanner.js";
|
|
5
|
+
import { metadataStorage } from "../metadata/storage.js";
|
|
6
|
+
const fixturesDir = resolve(import.meta.dir, "scan-fixtures");
|
|
7
|
+
describe("scanComponents", () => {
|
|
8
|
+
it("discovers @Service classes from filesystem", async () => {
|
|
9
|
+
await scanComponents([resolve(fixturesDir, "services")]);
|
|
10
|
+
// Check if the class is registered in metadata storage
|
|
11
|
+
// (might be in result if newly discovered, or already registered from earlier tests)
|
|
12
|
+
const providerNames = Array.from(metadataStorage.providers).map((p) => p.name);
|
|
13
|
+
expect(providerNames).toContain("GreetingScanService");
|
|
14
|
+
});
|
|
15
|
+
it("discovers @RestController classes", async () => {
|
|
16
|
+
await scanComponents([resolve(fixturesDir, "controllers")]);
|
|
17
|
+
// Check if the class is registered in metadata storage
|
|
18
|
+
const controllerNames = Array.from(metadataStorage.controllerPaths.keys()).map((c) => c.name);
|
|
19
|
+
expect(controllerNames).toContain("HelloScanController");
|
|
20
|
+
});
|
|
21
|
+
it("discovers @Module classes", async () => {
|
|
22
|
+
await scanComponents([resolve(fixturesDir, "modules")]);
|
|
23
|
+
// Check if the class is registered in metadata storage
|
|
24
|
+
const moduleNames = Array.from(metadataStorage.modules.keys()).map((m) => m.name);
|
|
25
|
+
expect(moduleNames).toContain("FeatureScanModule");
|
|
26
|
+
});
|
|
27
|
+
it("separates controllers from providers", async () => {
|
|
28
|
+
const result = await scanComponents([fixturesDir]);
|
|
29
|
+
const controllerNames = result.controllers.map((c) => c.name);
|
|
30
|
+
const providerNames = result.providers.map((p) => p.name);
|
|
31
|
+
// Controllers should NOT also appear in providers
|
|
32
|
+
for (const name of controllerNames) {
|
|
33
|
+
expect(providerNames).not.toContain(name);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
it("handles multiple scan paths without error", async () => {
|
|
37
|
+
// Classes discovered in earlier tests are already registered,
|
|
38
|
+
// so the scanner correctly returns them as "already known".
|
|
39
|
+
// This test verifies multi-path scanning completes without error.
|
|
40
|
+
const result = await scanComponents([
|
|
41
|
+
resolve(fixturesDir, "services"),
|
|
42
|
+
resolve(fixturesDir, "controllers"),
|
|
43
|
+
]);
|
|
44
|
+
expect(result).toHaveProperty("controllers");
|
|
45
|
+
expect(result).toHaveProperty("providers");
|
|
46
|
+
expect(result).toHaveProperty("modules");
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
//# sourceMappingURL=scanner.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scanner.test.js","sourceRoot":"","sources":["../../src/__tests__/scanner.test.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAE/B,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,MAAM,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,eAAe,CAAC,CAAC;AAE9D,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC9B,EAAE,CAAC,4CAA4C,EAAE,KAAK,IAAI,EAAE;QAC1D,MAAM,cAAc,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC;QAEzD,uDAAuD;QACvD,qFAAqF;QACrF,MAAM,aAAa,GAAG,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QAC/E,MAAM,CAAC,aAAa,CAAC,CAAC,SAAS,CAAC,qBAAqB,CAAC,CAAC;IACzD,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