adorn-api 1.0.0

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.
Files changed (50) hide show
  1. package/README.md +249 -0
  2. package/dist/cli/generate-routes.js +101 -0
  3. package/dist/cli/generate-swagger.js +197 -0
  4. package/dist/controllers/advanced.controller.js +131 -0
  5. package/dist/controllers/user.controller.js +121 -0
  6. package/dist/entities/user.entity.js +1 -0
  7. package/dist/index.js +2 -0
  8. package/dist/lib/common.js +62 -0
  9. package/dist/lib/decorators.js +116 -0
  10. package/dist/middleware/auth.middleware.js +13 -0
  11. package/dist/routes.js +80 -0
  12. package/dist/server.js +18 -0
  13. package/dist/src/cli/generate-routes.js +105 -0
  14. package/dist/src/cli/generate-swagger.js +197 -0
  15. package/dist/src/index.js +4 -0
  16. package/dist/src/lib/common.js +62 -0
  17. package/dist/src/lib/decorators.js +116 -0
  18. package/dist/src/routes.js +80 -0
  19. package/dist/src/server.js +18 -0
  20. package/dist/tests/example-app/controllers/advanced.controller.js +130 -0
  21. package/dist/tests/example-app/controllers/controllers/advanced.controller.js +131 -0
  22. package/dist/tests/example-app/controllers/controllers/user.controller.js +121 -0
  23. package/dist/tests/example-app/controllers/user.controller.js +121 -0
  24. package/dist/tests/example-app/entities/entities/user.entity.js +1 -0
  25. package/dist/tests/example-app/entities/user.entity.js +1 -0
  26. package/dist/tests/example-app/middleware/auth.middleware.js +13 -0
  27. package/dist/tests/example-app/middleware/middleware/auth.middleware.js +13 -0
  28. package/dist/tests/example-app/routes.js +80 -0
  29. package/dist/tests/example-app/server.js +23 -0
  30. package/package.json +34 -0
  31. package/scripts/run-example.js +32 -0
  32. package/src/cli/generate-routes.ts +123 -0
  33. package/src/cli/generate-swagger.ts +216 -0
  34. package/src/index.js +20 -0
  35. package/src/index.ts +4 -0
  36. package/src/lib/common.js +68 -0
  37. package/src/lib/common.ts +35 -0
  38. package/src/lib/decorators.js +128 -0
  39. package/src/lib/decorators.ts +136 -0
  40. package/swagger.json +238 -0
  41. package/tests/e2e.test.ts +72 -0
  42. package/tests/example-app/controllers/advanced.controller.ts +52 -0
  43. package/tests/example-app/controllers/user.controller.ts +35 -0
  44. package/tests/example-app/entities/user.entity.ts +8 -0
  45. package/tests/example-app/middleware/auth.middleware.ts +16 -0
  46. package/tests/example-app/routes.ts +102 -0
  47. package/tests/example-app/server.ts +30 -0
  48. package/tests/generators.test.ts +48 -0
  49. package/tests/utils.ts +46 -0
  50. package/tsconfig.json +20 -0
@@ -0,0 +1,197 @@
1
+ // src/cli/generate-swagger.ts
2
+ import { Project, SyntaxKind } from "ts-morph";
3
+ import * as fs from "fs";
4
+ const PROJECT_ROOT = "./tsconfig.json";
5
+ const OUTPUT_FILE = "./swagger.json";
6
+ const project = new Project({ tsConfigFilePath: PROJECT_ROOT });
7
+ const openApiSpec = {
8
+ openapi: "3.0.0",
9
+ info: { title: "Adorn API", version: "2.0.0" },
10
+ paths: {},
11
+ components: {
12
+ schemas: {},
13
+ securitySchemes: {
14
+ bearerAuth: {
15
+ type: "http",
16
+ scheme: "bearer",
17
+ bearerFormat: "JWT"
18
+ }
19
+ }
20
+ },
21
+ };
22
+ // --- Helper: Deep Type Resolver ---
23
+ // This converts TypeScript Types (Generics, Interfaces, Primitives) into JSON Schema
24
+ function resolveSchema(type, collectedSchemas) {
25
+ // 1. Handle Primitives
26
+ if (type.isString() || type.isStringLiteral())
27
+ return { type: "string" };
28
+ if (type.isNumber() || type.isNumberLiteral())
29
+ return { type: "integer" };
30
+ if (type.isBoolean() || type.isBooleanLiteral())
31
+ return { type: "boolean" };
32
+ if (type.isArray()) {
33
+ const arrayType = type.getArrayElementType();
34
+ return {
35
+ type: "array",
36
+ items: arrayType ? resolveSchema(arrayType, collectedSchemas) : {},
37
+ };
38
+ }
39
+ // 2. Handle Union Types (Enums)
40
+ if (type.isUnion()) {
41
+ const unionTypes = type.getUnionTypes();
42
+ // Extract literal values (e.g., "active", 100)
43
+ const literals = unionTypes
44
+ .map(t => t.isLiteral() ? t.getLiteralValue() : null)
45
+ .filter(val => val !== null);
46
+ // If we found literals, it's an Enum
47
+ if (literals.length > 0) {
48
+ const isString = typeof literals[0] === 'string';
49
+ return {
50
+ type: isString ? 'string' : 'integer',
51
+ enum: literals
52
+ };
53
+ }
54
+ // If it's a mix of objects (e.g. User | Admin), OpenApi uses 'oneOf'
55
+ // Simplified for this demo: take the first non-null type
56
+ return resolveSchema(unionTypes[0], collectedSchemas);
57
+ }
58
+ // 3. Handle Objects (Classes, Interfaces, Nested Literals)
59
+ if (type.isObject()) {
60
+ // Recursion Guard: If we've seen this type name before in components, reference it!
61
+ // (This prevents infinite loops and reduces swagger size)
62
+ const symbol = type.getSymbol();
63
+ const typeName = symbol?.getName();
64
+ // Common excluded types
65
+ if (typeName === "Promise") {
66
+ return resolveSchema(type.getTypeArguments()[0], collectedSchemas);
67
+ }
68
+ if (typeName === "Date")
69
+ return { type: "string", format: "date-time" };
70
+ // If it's a named class/interface (e.g. "Address"), and we haven't processed it,
71
+ // we could add it to components.schemas. For now, we inline it for simplicity.
72
+ const properties = type.getProperties();
73
+ const schema = { type: "object", properties: {}, required: [] };
74
+ properties.forEach((prop) => {
75
+ const propName = prop.getName();
76
+ if (propName.startsWith("_"))
77
+ return; // Skip privates
78
+ // Get the type of the property using getTypeAtLocation
79
+ const declarations = prop.getDeclarations();
80
+ if (declarations.length > 0) {
81
+ const propType = prop.getTypeAtLocation(declarations[0]);
82
+ if (propType) {
83
+ // RECURSION HERE: Pass the property type back into resolveSchema
84
+ schema.properties[propName] = resolveSchema(propType, collectedSchemas);
85
+ if (!prop.isOptional()) {
86
+ schema.required.push(propName);
87
+ }
88
+ }
89
+ }
90
+ });
91
+ return schema;
92
+ }
93
+ return { type: "string" }; // Fallback
94
+ }
95
+ function processController(classDec) {
96
+ const controllerDec = classDec.getDecorators().find((d) => d.getName() === "Controller");
97
+ if (!controllerDec)
98
+ return;
99
+ const basePath = controllerDec.getArguments()[0]?.getText().replace(/['"]/g, "") || "/";
100
+ classDec.getMethods().forEach((method) => {
101
+ const getDec = method.getDecorator("Get");
102
+ const postDec = method.getDecorator("Post");
103
+ const putDec = method.getDecorator("Put");
104
+ const deleteDec = method.getDecorator("Delete");
105
+ const decorator = getDec || postDec || putDec || deleteDec;
106
+ if (!decorator)
107
+ return;
108
+ const httpMethod = getDec ? "get" : postDec ? "post" : putDec ? "put" : "delete";
109
+ const pathArg = decorator.getArguments()[0]?.getText().replace(/['"]/g, "") || "/";
110
+ const fullPath = `/${basePath}${pathArg}`.replace("//", "/");
111
+ const parameters = [];
112
+ const requestBody = { content: {} };
113
+ // --- 1. Request Analysis (Input DTOs) ---
114
+ const params = method.getParameters();
115
+ if (params.length > 0) {
116
+ const param = params[0];
117
+ const paramType = param.getType(); // This resolves generics and inheritance!
118
+ // Iterate ALL properties of the type (inherited included)
119
+ paramType.getProperties().forEach(prop => {
120
+ const propName = prop.getName();
121
+ // We need to check Decorators.
122
+ // Note: In mapped types/generics, getting decorators is hard.
123
+ // We fallback to checking the source declaration.
124
+ const declarations = prop.getDeclarations();
125
+ let isQuery = false;
126
+ let isBody = false;
127
+ let isPath = false;
128
+ // Check decorators on the definition
129
+ declarations.forEach(decl => {
130
+ if (decl.getKind() === SyntaxKind.PropertyDeclaration) {
131
+ const pDecl = decl;
132
+ if (pDecl.getDecorator("FromQuery"))
133
+ isQuery = true;
134
+ if (pDecl.getDecorator("FromPath"))
135
+ isPath = true;
136
+ if (pDecl.getDecorator("FromBody"))
137
+ isBody = true;
138
+ }
139
+ });
140
+ // IMPLICIT RULES:
141
+ // If it's a GET, and not path, default to Query.
142
+ // If it's a POST, and not path/query, default to Body.
143
+ if (!isQuery && !isPath && !isBody) {
144
+ if (httpMethod === "get")
145
+ isQuery = true;
146
+ else
147
+ isBody = true;
148
+ }
149
+ const propType = prop.getTypeAtLocation(param.getSourceFile());
150
+ const propTypeSchema = resolveSchema(propType, openApiSpec.components.schemas);
151
+ if (isPath) {
152
+ parameters.push({ name: propName, in: "path", required: true, schema: propTypeSchema });
153
+ }
154
+ else if (isQuery) {
155
+ parameters.push({ name: propName, in: "query", required: !prop.isOptional(), schema: propTypeSchema });
156
+ }
157
+ else if (isBody) {
158
+ if (!requestBody.content["application/json"]) {
159
+ requestBody.content["application/json"] = { schema: { type: "object", properties: {}, required: [] } };
160
+ }
161
+ const bodySchema = requestBody.content["application/json"].schema;
162
+ bodySchema.properties[propName] = propTypeSchema;
163
+ if (!prop.isOptional())
164
+ bodySchema.required.push(propName);
165
+ }
166
+ });
167
+ }
168
+ // --- 2. Authentication Check ---
169
+ const authDec = method.getDecorator("Authorized");
170
+ const controllerAuthDec = classDec.getDecorator("Authorized");
171
+ const isAuth = !!authDec || !!controllerAuthDec;
172
+ // --- 3. Response Analysis (Return Type) ---
173
+ const returnType = method.getReturnType(); // e.g. Promise<EntityResponse<User>>
174
+ const responseSchema = resolveSchema(returnType, openApiSpec.components.schemas);
175
+ if (!openApiSpec.paths[fullPath])
176
+ openApiSpec.paths[fullPath] = {};
177
+ openApiSpec.paths[fullPath][httpMethod] = {
178
+ operationId: method.getName(),
179
+ parameters,
180
+ requestBody: Object.keys(requestBody.content).length ? requestBody : undefined,
181
+ security: isAuth ? [{ bearerAuth: [] }] : undefined,
182
+ responses: {
183
+ 200: {
184
+ description: "Success",
185
+ content: {
186
+ "application/json": { schema: responseSchema }
187
+ }
188
+ }
189
+ }
190
+ };
191
+ });
192
+ }
193
+ console.log("🔍 Scanning...");
194
+ const sourceFiles = project.getSourceFiles("tests/example-app/**/*.ts");
195
+ sourceFiles.forEach(file => file.getClasses().forEach(processController));
196
+ fs.writeFileSync(OUTPUT_FILE, JSON.stringify(openApiSpec, null, 2));
197
+ console.log(`✅ Generated ${OUTPUT_FILE}`);
@@ -0,0 +1,4 @@
1
+ // src/index.ts
2
+ // Main entry point for adorn-api library
3
+ export * from "./lib/decorators.js";
4
+ export * from "./lib/common.js";
@@ -0,0 +1,62 @@
1
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
2
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
3
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
4
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
5
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
6
+ var _, done = false;
7
+ for (var i = decorators.length - 1; i >= 0; i--) {
8
+ var context = {};
9
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
10
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
11
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
12
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
13
+ if (kind === "accessor") {
14
+ if (result === void 0) continue;
15
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
16
+ if (_ = accept(result.get)) descriptor.get = _;
17
+ if (_ = accept(result.set)) descriptor.set = _;
18
+ if (_ = accept(result.init)) initializers.unshift(_);
19
+ }
20
+ else if (_ = accept(result)) {
21
+ if (kind === "field") initializers.unshift(_);
22
+ else descriptor[key] = _;
23
+ }
24
+ }
25
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
26
+ done = true;
27
+ };
28
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
29
+ var useValue = arguments.length > 2;
30
+ for (var i = 0; i < initializers.length; i++) {
31
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
32
+ }
33
+ return useValue ? value : void 0;
34
+ };
35
+ // src/lib/common.ts
36
+ import { FromQuery } from "./decorators.js";
37
+ // --- 2. Pagination Logic ---
38
+ // We need a Concrete Class for Pagination because it carries Metadata (@FromQuery)
39
+ let PaginationQuery = (() => {
40
+ let _page_decorators;
41
+ let _page_initializers = [];
42
+ let _page_extraInitializers = [];
43
+ let _limit_decorators;
44
+ let _limit_initializers = [];
45
+ let _limit_extraInitializers = [];
46
+ return class PaginationQuery {
47
+ static {
48
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
49
+ _page_decorators = [FromQuery()];
50
+ _limit_decorators = [FromQuery()];
51
+ __esDecorate(null, null, _page_decorators, { kind: "field", name: "page", static: false, private: false, access: { has: obj => "page" in obj, get: obj => obj.page, set: (obj, value) => { obj.page = value; } }, metadata: _metadata }, _page_initializers, _page_extraInitializers);
52
+ __esDecorate(null, null, _limit_decorators, { kind: "field", name: "limit", static: false, private: false, access: { has: obj => "limit" in obj, get: obj => obj.limit, set: (obj, value) => { obj.limit = value; } }, metadata: _metadata }, _limit_initializers, _limit_extraInitializers);
53
+ if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
54
+ }
55
+ page = __runInitializers(this, _page_initializers, 1);
56
+ limit = (__runInitializers(this, _page_extraInitializers), __runInitializers(this, _limit_initializers, 20));
57
+ constructor() {
58
+ __runInitializers(this, _limit_extraInitializers);
59
+ }
60
+ };
61
+ })();
62
+ export { PaginationQuery };
@@ -0,0 +1,116 @@
1
+ // src/lib/decorators.ts
2
+ // Context metadata symbol for standard decorators
3
+ const META_KEY = Symbol('adorn:route');
4
+ export const SCHEMA_META = Symbol('adorn:schema');
5
+ export const AUTH_META = Symbol('adorn:auth');
6
+ // -- Method Decorator --
7
+ // Using Standard TC39 Signature
8
+ export function Get(path) {
9
+ return function (originalMethod, context) {
10
+ // In standard decorators, we can attach metadata to the class prototype via context
11
+ context.addInitializer(function () {
12
+ const routes = this[META_KEY] || [];
13
+ routes.push({
14
+ method: 'get',
15
+ path,
16
+ methodName: String(context.name),
17
+ });
18
+ this[META_KEY] = routes;
19
+ });
20
+ return originalMethod;
21
+ };
22
+ }
23
+ export function Post(path) {
24
+ return function (originalMethod, context) {
25
+ context.addInitializer(function () {
26
+ const routes = this[META_KEY] || [];
27
+ routes.push({
28
+ method: 'post',
29
+ path,
30
+ methodName: String(context.name),
31
+ });
32
+ this[META_KEY] = routes;
33
+ });
34
+ return originalMethod;
35
+ };
36
+ }
37
+ export function Put(path) {
38
+ return function (originalMethod, context) {
39
+ context.addInitializer(function () {
40
+ const routes = this[META_KEY] || [];
41
+ routes.push({
42
+ method: 'put',
43
+ path,
44
+ methodName: String(context.name),
45
+ });
46
+ this[META_KEY] = routes;
47
+ });
48
+ return originalMethod;
49
+ };
50
+ }
51
+ export function Delete(path) {
52
+ return function (originalMethod, context) {
53
+ context.addInitializer(function () {
54
+ const routes = this[META_KEY] || [];
55
+ routes.push({
56
+ method: 'delete',
57
+ path,
58
+ methodName: String(context.name),
59
+ });
60
+ this[META_KEY] = routes;
61
+ });
62
+ return originalMethod;
63
+ };
64
+ }
65
+ // -- Class Decorator --
66
+ export function Controller(basePath) {
67
+ return function (target, context) {
68
+ // We attach the base path to the class constructor
69
+ context.addInitializer(function () {
70
+ this._basePath = basePath;
71
+ });
72
+ return target;
73
+ };
74
+ }
75
+ // -- DTO Field Decorators --
76
+ // Since we can't decorate parameters, we decorate fields in a class
77
+ // e.g. class GetUserParams { @FromPath id: string }
78
+ export function FromQuery(name) {
79
+ return function (target, context) {
80
+ context.addInitializer(function () {
81
+ const meta = this[SCHEMA_META] || {};
82
+ meta[context.name] = { type: 'query' };
83
+ this[SCHEMA_META] = meta;
84
+ });
85
+ return function (initialValue) { return initialValue; };
86
+ };
87
+ }
88
+ export function FromPath(name) {
89
+ return function (target, context) {
90
+ context.addInitializer(function () {
91
+ const meta = this[SCHEMA_META] || {};
92
+ meta[context.name] = { type: 'path' };
93
+ this[SCHEMA_META] = meta;
94
+ });
95
+ return function (initialValue) { return initialValue; };
96
+ };
97
+ }
98
+ export function FromBody() {
99
+ return function (target, context) {
100
+ context.addInitializer(function () {
101
+ const meta = this[SCHEMA_META] || {};
102
+ meta[context.name] = { type: 'body' };
103
+ this[SCHEMA_META] = meta;
104
+ });
105
+ return function (initialValue) { return initialValue; };
106
+ };
107
+ }
108
+ // -- Authentication Decorator --
109
+ export function Authorized(role) {
110
+ return function (target, context) {
111
+ context.addInitializer(function () {
112
+ this[AUTH_META] = role || 'default';
113
+ });
114
+ return target;
115
+ };
116
+ }
@@ -0,0 +1,80 @@
1
+ import { AdvancedController } from 'C:/Users/celso/Documents/projetos/adorn-api/src/controllers/advanced.controller.js';
2
+ import { UserController } from 'C:/Users/celso/Documents/projetos/adorn-api/src/controllers/user.controller.js';
3
+ export function RegisterRoutes(app) {
4
+ app.get('/advanced/:tenantId/users', async (req, res) => {
5
+ const controller = new AdvancedController();
6
+ try {
7
+ const input = {};
8
+ // Map Query
9
+ Object.assign(input, req.query);
10
+ // Map Params
11
+ Object.assign(input, req.params);
12
+ // Map Body
13
+ Object.assign(input, req.body);
14
+ // In a real app, you would run 'zod' or 'class-validator' here on 'input'
15
+ const response = await controller.listUsers(input);
16
+ res.status(200).json(response);
17
+ }
18
+ catch (err) {
19
+ console.error(err);
20
+ res.status(500).send(err.message);
21
+ }
22
+ });
23
+ app.post('/advanced/', async (req, res) => {
24
+ const controller = new AdvancedController();
25
+ try {
26
+ const input = {};
27
+ // Map Query
28
+ Object.assign(input, req.query);
29
+ // Map Params
30
+ Object.assign(input, req.params);
31
+ // Map Body
32
+ Object.assign(input, req.body);
33
+ // In a real app, you would run 'zod' or 'class-validator' here on 'input'
34
+ const response = await controller.create(input);
35
+ res.status(200).json(response);
36
+ }
37
+ catch (err) {
38
+ console.error(err);
39
+ res.status(500).send(err.message);
40
+ }
41
+ });
42
+ app.get('/users/:userId', async (req, res) => {
43
+ const controller = new UserController();
44
+ try {
45
+ const input = {};
46
+ // Map Query
47
+ Object.assign(input, req.query);
48
+ // Map Params
49
+ Object.assign(input, req.params);
50
+ // Map Body
51
+ Object.assign(input, req.body);
52
+ // In a real app, you would run 'zod' or 'class-validator' here on 'input'
53
+ const response = await controller.getUser(input);
54
+ res.status(200).json(response);
55
+ }
56
+ catch (err) {
57
+ console.error(err);
58
+ res.status(500).send(err.message);
59
+ }
60
+ });
61
+ app.post('/users/', async (req, res) => {
62
+ const controller = new UserController();
63
+ try {
64
+ const input = {};
65
+ // Map Query
66
+ Object.assign(input, req.query);
67
+ // Map Params
68
+ Object.assign(input, req.params);
69
+ // Map Body
70
+ Object.assign(input, req.body);
71
+ // In a real app, you would run 'zod' or 'class-validator' here on 'input'
72
+ const response = await controller.createUser(input);
73
+ res.status(200).json(response);
74
+ }
75
+ catch (err) {
76
+ console.error(err);
77
+ res.status(500).send(err.message);
78
+ }
79
+ });
80
+ }
@@ -0,0 +1,18 @@
1
+ // src/server.ts
2
+ import express from "express";
3
+ import bodyParser from "body-parser";
4
+ // This is the file we just generated!
5
+ import { RegisterRoutes } from "./routes.js";
6
+ import swaggerUi from "swagger-ui-express";
7
+ import { readFileSync } from "fs";
8
+ const app = express();
9
+ app.use(bodyParser.json());
10
+ // 1. Register the Generated Routes
11
+ RegisterRoutes(app);
12
+ // 2. Serve Swagger UI
13
+ const swaggerDoc = JSON.parse(readFileSync("./swagger.json", "utf-8"));
14
+ app.use("/docs", swaggerUi.serve, swaggerUi.setup(swaggerDoc));
15
+ app.listen(3000, () => {
16
+ console.log("🚀 Server running on http://localhost:3000");
17
+ console.log("📄 Swagger running on http://localhost:3000/docs");
18
+ });
@@ -0,0 +1,130 @@
1
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
2
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
3
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
4
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
5
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
6
+ var _, done = false;
7
+ for (var i = decorators.length - 1; i >= 0; i--) {
8
+ var context = {};
9
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
10
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
11
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
12
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
13
+ if (kind === "accessor") {
14
+ if (result === void 0) continue;
15
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
16
+ if (_ = accept(result.get)) descriptor.get = _;
17
+ if (_ = accept(result.set)) descriptor.set = _;
18
+ if (_ = accept(result.init)) initializers.unshift(_);
19
+ }
20
+ else if (_ = accept(result)) {
21
+ if (kind === "field") initializers.unshift(_);
22
+ else descriptor[key] = _;
23
+ }
24
+ }
25
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
26
+ done = true;
27
+ };
28
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
29
+ var useValue = arguments.length > 2;
30
+ for (var i = 0; i < initializers.length; i++) {
31
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
32
+ }
33
+ return useValue ? value : void 0;
34
+ };
35
+ // src/controllers/advanced.controller.ts
36
+ import { Controller, Get, Post, FromBody, FromPath, PaginationQuery } from "../../../src/index.js";
37
+ // --- 1. Advanced Request DTOs ---
38
+ // INHERITANCE: UserListRequest automatically gets 'page' and 'limit' from PaginationQuery
39
+ // AND the generator will find them because we scan the Type properties.
40
+ let UserListRequest = (() => {
41
+ let _classSuper = PaginationQuery;
42
+ let _tenantId_decorators;
43
+ let _tenantId_initializers = [];
44
+ let _tenantId_extraInitializers = [];
45
+ return class UserListRequest extends _classSuper {
46
+ static {
47
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
48
+ _tenantId_decorators = [FromPath()];
49
+ __esDecorate(null, null, _tenantId_decorators, { kind: "field", name: "tenantId", static: false, private: false, access: { has: obj => "tenantId" in obj, get: obj => obj.tenantId, set: (obj, value) => { obj.tenantId = value; } }, metadata: _metadata }, _tenantId_initializers, _tenantId_extraInitializers);
50
+ if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
51
+ }
52
+ // Implicitly @FromQuery because it's a GET request and extends a class
53
+ search;
54
+ tenantId = __runInitializers(this, _tenantId_initializers, void 0);
55
+ constructor() {
56
+ super(...arguments);
57
+ __runInitializers(this, _tenantId_extraInitializers);
58
+ }
59
+ };
60
+ })();
61
+ export { UserListRequest };
62
+ // COMPOSITION: Using the Type Helper for safety, but class for Decorators
63
+ // We implement the Type Helper to ensure our Class matches the Entity rule
64
+ let CreateUserDto = (() => {
65
+ let _name_decorators;
66
+ let _name_initializers = [];
67
+ let _name_extraInitializers = [];
68
+ let _email_decorators;
69
+ let _email_initializers = [];
70
+ let _email_extraInitializers = [];
71
+ return class CreateUserDto {
72
+ static {
73
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
74
+ _name_decorators = [FromBody()];
75
+ _email_decorators = [FromBody()];
76
+ __esDecorate(null, null, _name_decorators, { kind: "field", name: "name", static: false, private: false, access: { has: obj => "name" in obj, get: obj => obj.name, set: (obj, value) => { obj.name = value; } }, metadata: _metadata }, _name_initializers, _name_extraInitializers);
77
+ __esDecorate(null, null, _email_decorators, { kind: "field", name: "email", static: false, private: false, access: { has: obj => "email" in obj, get: obj => obj.email, set: (obj, value) => { obj.email = value; } }, metadata: _metadata }, _email_initializers, _email_extraInitializers);
78
+ if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
79
+ }
80
+ name = __runInitializers(this, _name_initializers, void 0);
81
+ email = (__runInitializers(this, _name_extraInitializers), __runInitializers(this, _email_initializers, void 0));
82
+ constructor() {
83
+ __runInitializers(this, _email_extraInitializers);
84
+ }
85
+ };
86
+ })();
87
+ export { CreateUserDto };
88
+ // --- 2. The Controller ---
89
+ let AdvancedController = (() => {
90
+ let _classDecorators = [Controller("advanced")];
91
+ let _classDescriptor;
92
+ let _classExtraInitializers = [];
93
+ let _classThis;
94
+ let _instanceExtraInitializers = [];
95
+ let _listUsers_decorators;
96
+ let _create_decorators;
97
+ var AdvancedController = class {
98
+ static { _classThis = this; }
99
+ static {
100
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
101
+ _listUsers_decorators = [Get("/{tenantId}/users")];
102
+ _create_decorators = [Post("/")];
103
+ __esDecorate(this, null, _listUsers_decorators, { kind: "method", name: "listUsers", static: false, private: false, access: { has: obj => "listUsers" in obj, get: obj => obj.listUsers }, metadata: _metadata }, null, _instanceExtraInitializers);
104
+ __esDecorate(this, null, _create_decorators, { kind: "method", name: "create", static: false, private: false, access: { has: obj => "create" in obj, get: obj => obj.create }, metadata: _metadata }, null, _instanceExtraInitializers);
105
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
106
+ AdvancedController = _classThis = _classDescriptor.value;
107
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
108
+ __runInitializers(_classThis, _classExtraInitializers);
109
+ }
110
+ async listUsers(req) {
111
+ return [
112
+ { id: "1", name: "Alice", email: "a@a.com", isActive: true, createdAt: "now" }
113
+ ];
114
+ }
115
+ async create(req) {
116
+ return {
117
+ id: "123",
118
+ name: req.name,
119
+ email: req.email,
120
+ isActive: true,
121
+ createdAt: "now"
122
+ };
123
+ }
124
+ constructor() {
125
+ __runInitializers(this, _instanceExtraInitializers);
126
+ }
127
+ };
128
+ return AdvancedController = _classThis;
129
+ })();
130
+ export { AdvancedController };