azurajs 2.5.0 → 2.5.2-1
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 +8 -11
- package/dist/{Swagger-BvqoEq-j.d.cts → Swagger-BWCRS_VR.d.cts} +63 -1
- package/dist/{Swagger-VHIdi4fs.d.ts → Swagger-BuMxfyha.d.ts} +63 -1
- package/dist/decorators.cjs.map +1 -1
- package/dist/decorators.d.cts +1 -1
- package/dist/decorators.d.ts +1 -1
- package/dist/decorators.js.map +1 -1
- package/dist/index.cjs +68 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +68 -21
- package/dist/index.js.map +1 -1
- package/dist/infra.cjs +68 -21
- package/dist/infra.cjs.map +1 -1
- package/dist/infra.js +68 -21
- package/dist/infra.js.map +1 -1
- package/dist/router.cjs +52 -10
- package/dist/router.cjs.map +1 -1
- package/dist/router.js +52 -10
- package/dist/router.js.map +1 -1
- package/dist/shared/swagger/swagger-ui-modern.html +1200 -0
- package/dist/swagger.cjs +335 -12
- package/dist/swagger.cjs.map +1 -1
- package/dist/swagger.d.cts +143 -13
- package/dist/swagger.d.ts +143 -13
- package/dist/swagger.js +335 -15
- package/dist/swagger.js.map +1 -1
- package/package.json +4 -4
- package/src/decorators/Swagger.ts +134 -0
- package/src/infra/Router.ts +61 -11
- package/src/infra/Server.ts +10 -10
- package/src/infra/utils/IpResolver.ts +7 -1
- package/src/shared/swagger/SwaggerGenerator.ts +297 -0
- package/src/shared/swagger/index.ts +47 -21
- package/src/swagger.ts +12 -1
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
⚡ Modern, fast, and TypeScript-first web framework for Node.js and Bun with decorator-based routing.
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/azurajs)
|
|
6
|
-
[](https://github.com/
|
|
6
|
+
[](https://github.com/azurajs/azura/blob/main/LICENSE)
|
|
7
7
|
[](https://www.typescriptlang.org/)
|
|
8
8
|
|
|
9
9
|
## Features
|
|
@@ -41,8 +41,7 @@ AzuraJS supports modular imports for tree-shaking and better organization:
|
|
|
41
41
|
import { AzuraClient } from "azurajs";
|
|
42
42
|
|
|
43
43
|
// Decorators
|
|
44
|
-
import { Controller, Get, Post, Body, Param } from "azurajs/decorators";
|
|
45
|
-
import { applyDecorators } from "azurajs/decorators";
|
|
44
|
+
import { applyDecorators, Controller, Get, Post, Body, Param } from "azurajs/decorators";
|
|
46
45
|
|
|
47
46
|
// Middleware
|
|
48
47
|
import { createLoggingMiddleware } from "azurajs/middleware";
|
|
@@ -103,8 +102,7 @@ export default config;
|
|
|
103
102
|
|
|
104
103
|
```typescript
|
|
105
104
|
import { AzuraClient } from "azurajs";
|
|
106
|
-
import { applyDecorators } from "azurajs/decorators";
|
|
107
|
-
import { Controller, Get, Post, Body, Param, Query, Res } from "azurajs/decorators";
|
|
105
|
+
import { applyDecorators, Controller, Get, Post, Body, Param, Query, Res } from "azurajs/decorators";
|
|
108
106
|
import { createLoggingMiddleware } from "azurajs/middleware";
|
|
109
107
|
import type { ResponseServer } from "azurajs/types";
|
|
110
108
|
|
|
@@ -647,8 +645,7 @@ type ConfigTypes = {
|
|
|
647
645
|
|
|
648
646
|
```typescript
|
|
649
647
|
import { AzuraClient } from "azurajs";
|
|
650
|
-
import { applyDecorators } from "azurajs/decorators";
|
|
651
|
-
import { Controller, Get, Post, Put, Delete, Body, Param, Res } from "azurajs/decorators";
|
|
648
|
+
import { applyDecorators, Controller, Get, Post, Put, Delete, Body, Param, Res } from "azurajs/decorators";
|
|
652
649
|
import type { ResponseServer } from "azurajs/types";
|
|
653
650
|
|
|
654
651
|
interface User {
|
|
@@ -820,13 +817,13 @@ MIT License - see LICENSE file for details
|
|
|
820
817
|
|
|
821
818
|
## Links
|
|
822
819
|
|
|
823
|
-
- [GitHub Repository](https://github.com/
|
|
820
|
+
- [GitHub Repository](https://github.com/azurajs/azura)
|
|
824
821
|
- [NPM Package](https://www.npmjs.com/package/azurajs)
|
|
825
822
|
- [Documentation](https://azura.js.org/docs/en)
|
|
826
|
-
- [Examples](https://github.com/
|
|
823
|
+
- [Examples](https://github.com/azurajs/azura/tree/main/examples)
|
|
827
824
|
|
|
828
825
|
## Support
|
|
829
826
|
|
|
830
|
-
- 🐛 [Issue Tracker](https://github.com/
|
|
831
|
-
- 💬 [Discussions](https://github.com/
|
|
827
|
+
- 🐛 [Issue Tracker](https://github.com/azurajs/azura/issues)
|
|
828
|
+
- 💬 [Discussions](https://github.com/azurajs/azura/discussions)
|
|
832
829
|
- 📧 Email: 0xviny.dev@gmail.com
|
|
@@ -52,5 +52,67 @@ declare function getSwaggerMetadata(target: Function): {
|
|
|
52
52
|
body: Map<string, ApiBodyMetadata> | undefined;
|
|
53
53
|
tags: string[] | undefined;
|
|
54
54
|
};
|
|
55
|
+
/**
|
|
56
|
+
* Unified Swagger decorator - Simple and easy to use!
|
|
57
|
+
* Document everything in one place with a clean object structure.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```typescript
|
|
61
|
+
* @Swagger({
|
|
62
|
+
* summary: "Get user by ID",
|
|
63
|
+
* description: "Retrieve a single user",
|
|
64
|
+
* tags: ["Users"],
|
|
65
|
+
* parameters: [
|
|
66
|
+
* {
|
|
67
|
+
* name: "id",
|
|
68
|
+
* in: "path",
|
|
69
|
+
* description: "User ID",
|
|
70
|
+
* required: true,
|
|
71
|
+
* schema: { type: "string" },
|
|
72
|
+
* example: "123"
|
|
73
|
+
* }
|
|
74
|
+
* ],
|
|
75
|
+
* responses: {
|
|
76
|
+
* 200: {
|
|
77
|
+
* description: "User found",
|
|
78
|
+
* example: { id: "123", name: "John" }
|
|
79
|
+
* },
|
|
80
|
+
* 404: {
|
|
81
|
+
* description: "User not found",
|
|
82
|
+
* example: { error: "Not found" }
|
|
83
|
+
* }
|
|
84
|
+
* }
|
|
85
|
+
* })
|
|
86
|
+
* getUser(req, res) { }
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
declare function Swagger(config: {
|
|
90
|
+
summary?: string;
|
|
91
|
+
description?: string;
|
|
92
|
+
tags?: string[];
|
|
93
|
+
operationId?: string;
|
|
94
|
+
deprecated?: boolean;
|
|
95
|
+
security?: SecurityRequirement[];
|
|
96
|
+
parameters?: Array<{
|
|
97
|
+
name: string;
|
|
98
|
+
in: "query" | "header" | "path" | "cookie";
|
|
99
|
+
description?: string;
|
|
100
|
+
required?: boolean;
|
|
101
|
+
schema?: Schema;
|
|
102
|
+
example?: any;
|
|
103
|
+
}>;
|
|
104
|
+
requestBody?: {
|
|
105
|
+
description?: string;
|
|
106
|
+
required?: boolean;
|
|
107
|
+
content?: any;
|
|
108
|
+
example?: any;
|
|
109
|
+
};
|
|
110
|
+
responses?: Record<number, {
|
|
111
|
+
description: string;
|
|
112
|
+
example?: any;
|
|
113
|
+
schema?: Schema;
|
|
114
|
+
headers?: Record<string, Header>;
|
|
115
|
+
}>;
|
|
116
|
+
}): MethodDecorator;
|
|
55
117
|
|
|
56
|
-
export { ApiDoc as A, ApiResponse as a, ApiParameter as b, ApiBody as c, ApiTags as d, ApiDeprecated as e, ApiSecurity as f, getSwaggerMetadata as g };
|
|
118
|
+
export { ApiDoc as A, Swagger as S, ApiResponse as a, ApiParameter as b, ApiBody as c, ApiTags as d, ApiDeprecated as e, ApiSecurity as f, getSwaggerMetadata as g };
|
|
@@ -52,5 +52,67 @@ declare function getSwaggerMetadata(target: Function): {
|
|
|
52
52
|
body: Map<string, ApiBodyMetadata> | undefined;
|
|
53
53
|
tags: string[] | undefined;
|
|
54
54
|
};
|
|
55
|
+
/**
|
|
56
|
+
* Unified Swagger decorator - Simple and easy to use!
|
|
57
|
+
* Document everything in one place with a clean object structure.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```typescript
|
|
61
|
+
* @Swagger({
|
|
62
|
+
* summary: "Get user by ID",
|
|
63
|
+
* description: "Retrieve a single user",
|
|
64
|
+
* tags: ["Users"],
|
|
65
|
+
* parameters: [
|
|
66
|
+
* {
|
|
67
|
+
* name: "id",
|
|
68
|
+
* in: "path",
|
|
69
|
+
* description: "User ID",
|
|
70
|
+
* required: true,
|
|
71
|
+
* schema: { type: "string" },
|
|
72
|
+
* example: "123"
|
|
73
|
+
* }
|
|
74
|
+
* ],
|
|
75
|
+
* responses: {
|
|
76
|
+
* 200: {
|
|
77
|
+
* description: "User found",
|
|
78
|
+
* example: { id: "123", name: "John" }
|
|
79
|
+
* },
|
|
80
|
+
* 404: {
|
|
81
|
+
* description: "User not found",
|
|
82
|
+
* example: { error: "Not found" }
|
|
83
|
+
* }
|
|
84
|
+
* }
|
|
85
|
+
* })
|
|
86
|
+
* getUser(req, res) { }
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
declare function Swagger(config: {
|
|
90
|
+
summary?: string;
|
|
91
|
+
description?: string;
|
|
92
|
+
tags?: string[];
|
|
93
|
+
operationId?: string;
|
|
94
|
+
deprecated?: boolean;
|
|
95
|
+
security?: SecurityRequirement[];
|
|
96
|
+
parameters?: Array<{
|
|
97
|
+
name: string;
|
|
98
|
+
in: "query" | "header" | "path" | "cookie";
|
|
99
|
+
description?: string;
|
|
100
|
+
required?: boolean;
|
|
101
|
+
schema?: Schema;
|
|
102
|
+
example?: any;
|
|
103
|
+
}>;
|
|
104
|
+
requestBody?: {
|
|
105
|
+
description?: string;
|
|
106
|
+
required?: boolean;
|
|
107
|
+
content?: any;
|
|
108
|
+
example?: any;
|
|
109
|
+
};
|
|
110
|
+
responses?: Record<number, {
|
|
111
|
+
description: string;
|
|
112
|
+
example?: any;
|
|
113
|
+
schema?: Schema;
|
|
114
|
+
headers?: Record<string, Header>;
|
|
115
|
+
}>;
|
|
116
|
+
}): MethodDecorator;
|
|
55
117
|
|
|
56
|
-
export { ApiDoc as A, ApiResponse as a, ApiParameter as b, ApiBody as c, ApiTags as d, ApiDeprecated as e, ApiSecurity as f, getSwaggerMetadata as g };
|
|
118
|
+
export { ApiDoc as A, Swagger as S, ApiResponse as a, ApiParameter as b, ApiBody as c, ApiTags as d, ApiDeprecated as e, ApiSecurity as f, getSwaggerMetadata as g };
|
package/dist/decorators.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/decorators/Route.ts","../src/decorators/Swagger.ts"],"names":[],"mappings":";;;AAKA,IAAM,MAAA,uBAAa,OAAA,EAA0B;AAC7C,IAAM,MAAA,uBAAa,OAAA,EAAqC;AACxD,IAAM,MAAA,uBAAa,OAAA,EAAkD;AACrE,IAAM,YAAA,uBAAmB,OAAA,EAAuC;AAEzD,SAAS,UAAA,CAAW,SAAS,EAAA,EAAoB;AACtD,EAAA,OAAO,CAAC,MAAA,KAAW;AACjB,IAAA,MAAA,CAAO,GAAA,CAAI,QAAoB,MAAM,CAAA;AAAA,EACvC,CAAA;AACF;AAeA,SAAS,sBAAsB,MAAA,EAAgB;AAC7C,EAAA,OAAO,SAAU,OAAO,EAAA,EAAqB;AAC3C,IAAA,OAAO,CAAC,QAAQ,WAAA,KAAgB;AAC9B,MAAA,MAAM,IAAA,GACJ,OAAO,MAAA,KAAW,UAAA,GAAc,SAAuB,MAAA,CAAe,WAAA;AACxE,MAAA,MAAM,GAAA,GAAM,OAAO,WAAW,CAAA;AAC9B,MAAA,MAAM,MAAA,GAAS,MAAA,CAAO,GAAA,CAAI,IAAI,KAAK,EAAC;AACpC,MAAA,MAAM,MAAA,GAAS,OAAO,GAAA,CAAI,IAAI,GAAG,GAAA,CAAI,GAAG,KAAK,EAAC;AAC9C,MAAA,MAAM,cAAc,YAAA,CAAa,GAAA,CAAI,IAAI,CAAA,EAAG,IAAI,GAAG,CAAA;AAEnD,MAAA,MAAM,SAAS,MAAA,CAAO,IAAA;AAAA,QACpB,CAAC,MAAM,CAAA,CAAE,MAAA,KAAW,UAAU,CAAA,CAAE,IAAA,KAAS,IAAA,IAAQ,CAAA,CAAE,WAAA,KAAgB;AAAA,OACrE;AACA,MAAA,IAAI,CAAC,MAAA,EA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,SAAA,EAAW,aAAA,CAAc,GAAA,CAAI,MAAM,CAAA;AAAA,IACnC,UAAA,EAAY,cAAA,CAAe,GAAA,CAAI,MAAM,CAAA;AAAA,IACrC,IAAA,EAAM,QAAA,CAAS,GAAA,CAAI,MAAM,CAAA;AAAA,IACzB,IAAA,EAAM,QAAA,CAAS,GAAA,CAAI,MAAM;AAAA,GAC3B;AACF","file":"decorators.cjs","sourcesContent":["import type { AzuraClient } from \"../infra/Server\";\nimport type { RequestServer } from \"../types/http/request.type\";\nimport type { ResponseServer } from \"../types/http/response.type\";\nimport type { ParamDefinition, ParamSource, RouteDefinition } from \"../types/routes.type\";\n\nconst PREFIX = new WeakMap<Function, string>();\nconst ROUTES = new WeakMap<Function, RouteDefinition[]>();\nconst PARAMS = new WeakMap<Function, Map<string, ParamDefinition[]>>();\nconst DESCRIPTIONS = new WeakMap<Function, Map<string, string>>();\n\nexport function Controller(prefix = \"\"): ClassDecorator {\n return (target) => {\n PREFIX.set(target as Function, prefix);\n };\n}\n\nexport function Description(description: string): MethodDecorator {\n return (target, propertyKey) => {\n const ctor =\n typeof target === \"function\" ? (target as Function) : (target as any).constructor;\n let map = DESCRIPTIONS.get(ctor);\n if (!map) {\n map = new Map<string, string>();\n DESCRIPTIONS.set(ctor, map);\n }\n map.set(String(propertyKey), description);\n };\n}\n\nfunction createMethodDecorator(method: string) {\n return function (path = \"\"): MethodDecorator {\n return (target, propertyKey) => {\n const ctor =\n typeof target === \"function\" ? (target as Function) : (target as any).constructor;\n const key = String(propertyKey);\n const routes = ROUTES.get(ctor) ?? [];\n const params = PARAMS.get(ctor)?.get(key) ?? [];\n const description = DESCRIPTIONS.get(ctor)?.get(key);\n\n const exists = routes.some(\n (r) => r.method === method && r.path === path && r.propertyKey === key\n );\n if (!exists) {\n routes.push({\n method,\n path,\n propertyKey: key,\n params,\n description,\n });\n ROUTES.set(ctor, routes);\n }\n };\n };\n}\n\nfunction createParamDecorator(type: ParamSource) {\n return function (name?: string): ParameterDecorator {\n return (target, propertyKey, parameterIndex) => {\n const ctor =\n typeof target === \"function\" ? (target as Function) : (target as any).constructor;\n let map = PARAMS.get(ctor);\n if (!map) {\n map = new Map<string, ParamDefinition[]>();\n PARAMS.set(ctor, map);\n }\n\n const key = String(propertyKey);\n const list = map.get(key) ?? [];\n const exists = list.some(\n (p) => p.index === parameterIndex && p.type === type && p.name === name\n );\n if (!exists) {\n list.push({\n index: parameterIndex,\n type,\n name,\n });\n map.set(key, list);\n }\n };\n };\n}\n\nexport const Get = createMethodDecorator(\"GET\");\nexport const Post = createMethodDecorator(\"POST\");\nexport const Put = createMethodDecorator(\"PUT\");\nexport const Delete = createMethodDecorator(\"DELETE\");\nexport const Patch = createMethodDecorator(\"PATCH\");\nexport const Head = createMethodDecorator(\"HEAD\");\nexport const Options = createMethodDecorator(\"OPTIONS\");\n\nexport const Req = createParamDecorator(\"req\");\nexport const Res = createParamDecorator(\"res\");\nexport const Next = createParamDecorator(\"next\");\nexport const Param = createParamDecorator(\"param\");\nexport const Query = createParamDecorator(\"query\");\nexport const Body = createParamDecorator(\"body\");\nexport const Headers = createParamDecorator(\"headers\");\nexport const Ip = createParamDecorator(\"ip\");\nexport const UserAgent = createParamDecorator(\"useragent\");\n\nexport function applyDecorators(app: AzuraClient, controllers: Array<new () => any>) {\n controllers.forEach((ControllerClass) => {\n const prefix = PREFIX.get(ControllerClass) ?? \"\";\n const instance = new ControllerClass();\n const routes = ROUTES.get(ControllerClass) ?? [];\n\n routes.forEach((r) => {\n const handler = async (\n req: RequestServer,\n res: ResponseServer,\n next?: (err?: unknown) => void\n ) => {\n try {\n const params = (r.params ?? []).slice().sort((a, b) => a.index - b.index);\n const args = params.map((p) => {\n switch (p.type) {\n case \"req\":\n return req;\n case \"res\":\n return res;\n case \"next\":\n return next;\n case \"param\":\n return p.name ? req.params[p.name] : req.params;\n case \"query\":\n return p.name ? req.query[p.name] : req.query;\n case \"body\": {\n const body = req.body as Record<string, unknown> | undefined;\n return p.name ? body?.[p.name] : body;\n }\n case \"headers\":\n return p.name ? req.headers[p.name.toLowerCase()] : req.headers;\n case \"ip\":\n return req.ip;\n case \"useragent\":\n return req.headers[\"user-agent\"];\n default:\n return undefined;\n }\n });\n\n const fn = (instance as Record<string, unknown>)[r.propertyKey] as (\n ...args: unknown[]\n ) => unknown;\n const result = fn(...args);\n if (result instanceof Promise) await result;\n } catch (err) {\n if (next) next(err);\n }\n };\n\n app.addRoute(r.method, prefix + r.path, handler);\n });\n });\n}\n\n/**\n * Get routes metadata from a controller class\n * @internal Used by Swagger integration\n */\nexport function getControllerMetadata(ControllerClass: Function) {\n return {\n prefix: PREFIX.get(ControllerClass) || \"\",\n routes: ROUTES.get(ControllerClass) || [],\n params: PARAMS.get(ControllerClass),\n descriptions: DESCRIPTIONS.get(ControllerClass),\n };\n}\n","import type {\n ApiDocMetadata,\n ApiResponseMetadata,\n ApiParameterMetadata,\n ApiBodyMetadata,\n Schema,\n SecurityRequirement,\n Header,\n} from \"../types/swagger.type\";\n\nconst API_METADATA = new WeakMap<Function, Map<string, ApiDocMetadata>>();\nconst API_RESPONSES = new WeakMap<Function, Map<string, ApiResponseMetadata[]>>();\nconst API_PARAMETERS = new WeakMap<Function, Map<string, ApiParameterMetadata[]>>();\nconst API_BODY = new WeakMap<Function, Map<string, ApiBodyMetadata>>();\nconst API_TAGS = new WeakMap<Function, string[]>();\n\n/**\n * Decorator to document an endpoint\n */\nexport function ApiDoc(metadata: Omit<ApiDocMetadata, \"method\" | \"path\">): MethodDecorator {\n return (target, propertyKey) => {\n const ctor =\n typeof target === \"function\" ? (target as Function) : (target as any).constructor;\n let map = API_METADATA.get(ctor);\n if (!map) {\n map = new Map<string, ApiDocMetadata>();\n API_METADATA.set(ctor, map);\n }\n map.set(String(propertyKey), metadata);\n };\n}\n\n/**\n * Decorator to document a response\n */\nexport function ApiResponse(\n statusCode: number,\n description: string,\n options?: {\n type?: any;\n examples?: Record<string, any>;\n headers?: Record<string, Header>;\n }\n): MethodDecorator {\n return (target, propertyKey) => {\n const ctor =\n typeof target === \"function\" ? (target as Function) : (target as any).constructor;\n let map = API_RESPONSES.get(ctor);\n if (!map) {\n map = new Map<string, ApiResponseMetadata[]>();\n API_RESPONSES.set(ctor, map);\n }\n\n const key = String(propertyKey);\n const responses = map.get(key) ?? [];\n responses.push({\n statusCode,\n description,\n type: options?.type,\n examples: options?.examples,\n headers: options?.headers,\n });\n map.set(key, responses);\n };\n}\n\n/**\n * Decorator to document a parameter\n */\nexport function ApiParameter(\n name: string,\n paramIn: \"query\" | \"header\" | \"path\" | \"cookie\",\n options?: {\n description?: string;\n required?: boolean;\n type?: any;\n example?: any;\n schema?: Schema;\n }\n): MethodDecorator {\n return (target, propertyKey) => {\n const ctor =\n typeof target === \"function\" ? (target as Function) : (target as any).constructor;\n let map = API_PARAMETERS.get(ctor);\n if (!map) {\n map = new Map<string, ApiParameterMetadata[]>();\n API_PARAMETERS.set(ctor, map);\n }\n\n const key = String(propertyKey);\n const params = map.get(key) ?? [];\n params.push({\n name,\n in: paramIn,\n description: options?.description,\n required: options?.required,\n type: options?.type,\n example: options?.example,\n schema: options?.schema,\n });\n map.set(key, params);\n };\n}\n\n/**\n * Decorator to document a request body\n */\nexport function ApiBody(\n description: string,\n options?: {\n type?: any;\n required?: boolean;\n examples?: Record<string, any>;\n }\n): MethodDecorator {\n return (target, propertyKey) => {\n const ctor =\n typeof target === \"function\" ? (target as Function) : (target as any).constructor;\n let map = API_BODY.get(ctor);\n if (!map) {\n map = new Map<string, ApiBodyMetadata>();\n API_BODY.set(ctor, map);\n }\n\n map.set(String(propertyKey), {\n description,\n type: options?.type,\n required: options?.required,\n examples: options?.examples,\n });\n };\n}\n\n/**\n * Decorator to add tags to a controller\n */\nexport function ApiTags(...tags: string[]): ClassDecorator {\n return (target) => {\n API_TAGS.set(target as Function, tags);\n };\n}\n\n/**\n * Decorator to mark an endpoint as deprecated\n */\nexport function ApiDeprecated(): MethodDecorator {\n return (target, propertyKey) => {\n const ctor =\n typeof target === \"function\" ? (target as Function) : (target as any).constructor;\n let map = API_METADATA.get(ctor);\n if (!map) {\n map = new Map<string, ApiDocMetadata>();\n API_METADATA.set(ctor, map);\n }\n\n const key = String(propertyKey);\n const existing = map.get(key) ?? {};\n map.set(key, { ...existing, deprecated: true });\n };\n}\n\n/**\n * Decorator to add security requirements\n */\nexport function ApiSecurity(...requirements: SecurityRequirement[]): MethodDecorator {\n return (target, propertyKey) => {\n const ctor =\n typeof target === \"function\" ? (target as Function) : (target as any).constructor;\n let map = API_METADATA.get(ctor);\n if (!map) {\n map = new Map<string, ApiDocMetadata>();\n API_METADATA.set(ctor, map);\n }\n\n const key = String(propertyKey);\n const existing = map.get(key) ?? {};\n map.set(key, { ...existing, security: requirements });\n };\n}\n\n/**\n * Helper to get all swagger metadata\n */\nexport function getSwaggerMetadata(target: Function) {\n return {\n metadata: API_METADATA.get(target),\n responses: API_RESPONSES.get(target),\n parameters: API_PARAMETERS.get(target),\n body: API_BODY.get(target),\n tags: API_TAGS.get(target),\n };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/decorators/Route.ts","../src/decorators/Swagger.ts"],"names":[],"mappings":";;;AAKA,IAAM,MAAA,uBAAa,OAAA,EAA0B;AAC7C,IAAM,MAAA,uBAAa,OAAA,EAAqC;AACxD,IAAM,MAAA,uBAAa,OAAA,EAAkD;AACrE,IAAM,YAAA,uBAAmB,OAAA,EAAuC;AAEzD,SAAS,UAAA,CAAW,SAAS,EAAA,EAAoB;AACtD,EAAA,OAAO,CAAC,MAAA,KAAW;AACjB,IAAA,MAAA,CAAO,GAAA,CAAI,QAAoB,MAAM,CAAA;AAAA,EACvC,CAAA;AACF;AAeA,SAAS,sBAAsB,MAAA,EAAgB;AAC7C,EAAA,OAAO,SAAU,OAAO,EAAA,EAAqB;AAC3C,IAAA,OAAO,CAAC,QAAQ,WAAA,KAAgB;AAC9B,MAAA,MAAM,IAAA,GACJ,OAAO,MAAA,KAAW,UAAA,GAAc,SAAuB,MAAA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AI,IAAI,CAAA;AAC/B,IAAA,IAAI,CAAC,GAAA,EAAK;AACR,MAAA,GAAA,uBAAU,GAAA,EAA4B;AACtC,MAAA,YAAA,CAAa,GAAA,CAAI,MAAM,GAAG,CAAA;AAAA,IAC5B;AAEA,IAAA,MAAM,GAAA,GAAM,OAAO,WAAW,CAAA;AAC9B,IAAA,MAAM,QAAA,GAAW,GAAA,CAAI,GAAA,CAAI,GAAG,KAAK,EAAC;AAClC,IAAA,GAAA,CAAI,IAAI,GAAA,EAAK,EAAE,GAAG,QAAA,EAAU,QAAA,EAAU,cAAc,CAAA;AAAA,EACtD,CAAA;AACF;AAKO,SAAS,mBAAmB,MAAA,EAAkB;AACnD,EAAA,OAAO;AAAA,IACL,QAAA,EAAU,YAAA,CAAa,GAAA,CAAI,MAAM,CAAA;AAAA,IACjC,SAAA,EAAW,aAAA,CAAc,GAAA,CAAI,MAAM,CAAA;AAAA,IACnC,UAAA,EAAY,cAAA,CAAe,GAAA,CAAI,MAAM,CAAA;AAAA,IACrC,IAAA,EAAM,QAAA,CAAS,GAAA,CAAI,MAAM,CAAA;AAAA,IACzB,IAAA,EAAM,QAAA,CAAS,GAAA,CAAI,MAAM;AAAA,GAC3B;AACF","file":"decorators.cjs","sourcesContent":["import type { AzuraClient } from \"../infra/Server\";\nimport type { RequestServer } from \"../types/http/request.type\";\nimport type { ResponseServer } from \"../types/http/response.type\";\nimport type { ParamDefinition, ParamSource, RouteDefinition } from \"../types/routes.type\";\n\nconst PREFIX = new WeakMap<Function, string>();\nconst ROUTES = new WeakMap<Function, RouteDefinition[]>();\nconst PARAMS = new WeakMap<Function, Map<string, ParamDefinition[]>>();\nconst DESCRIPTIONS = new WeakMap<Function, Map<string, string>>();\n\nexport function Controller(prefix = \"\"): ClassDecorator {\n return (target) => {\n PREFIX.set(target as Function, prefix);\n };\n}\n\nexport function Description(description: string): MethodDecorator {\n return (target, propertyKey) => {\n const ctor =\n typeof target === \"function\" ? (target as Function) : (target as any).constructor;\n let map = DESCRIPTIONS.get(ctor);\n if (!map) {\n map = new Map<string, string>();\n DESCRIPTIONS.set(ctor, map);\n }\n map.set(String(propertyKey), description);\n };\n}\n\nfunction createMethodDecorator(method: string) {\n return function (path = \"\"): MethodDecorator {\n return (target, propertyKey) => {\n const ctor =\n typeof target === \"function\" ? (target as Function) : (target as any).constructor;\n const key = String(propertyKey);\n const routes = ROUTES.get(ctor) ?? [];\n const params = PARAMS.get(ctor)?.get(key) ?? [];\n const description = DESCRIPTIONS.get(ctor)?.get(key);\n\n const exists = routes.some(\n (r) => r.method === method && r.path === path && r.propertyKey === key\n );\n if (!exists) {\n routes.push({\n method,\n path,\n propertyKey: key,\n params,\n description,\n });\n ROUTES.set(ctor, routes);\n }\n };\n };\n}\n\nfunction createParamDecorator(type: ParamSource) {\n return function (name?: string): ParameterDecorator {\n return (target, propertyKey, parameterIndex) => {\n const ctor =\n typeof target === \"function\" ? (target as Function) : (target as any).constructor;\n let map = PARAMS.get(ctor);\n if (!map) {\n map = new Map<string, ParamDefinition[]>();\n PARAMS.set(ctor, map);\n }\n\n const key = String(propertyKey);\n const list = map.get(key) ?? [];\n const exists = list.some(\n (p) => p.index === parameterIndex && p.type === type && p.name === name\n );\n if (!exists) {\n list.push({\n index: parameterIndex,\n type,\n name,\n });\n map.set(key, list);\n }\n };\n };\n}\n\nexport const Get = createMethodDecorator(\"GET\");\nexport const Post = createMethodDecorator(\"POST\");\nexport const Put = createMethodDecorator(\"PUT\");\nexport const Delete = createMethodDecorator(\"DELETE\");\nexport const Patch = createMethodDecorator(\"PATCH\");\nexport const Head = createMethodDecorator(\"HEAD\");\nexport const Options = createMethodDecorator(\"OPTIONS\");\n\nexport const Req = createParamDecorator(\"req\");\nexport const Res = createParamDecorator(\"res\");\nexport const Next = createParamDecorator(\"next\");\nexport const Param = createParamDecorator(\"param\");\nexport const Query = createParamDecorator(\"query\");\nexport const Body = createParamDecorator(\"body\");\nexport const Headers = createParamDecorator(\"headers\");\nexport const Ip = createParamDecorator(\"ip\");\nexport const UserAgent = createParamDecorator(\"useragent\");\n\nexport function applyDecorators(app: AzuraClient, controllers: Array<new () => any>) {\n controllers.forEach((ControllerClass) => {\n const prefix = PREFIX.get(ControllerClass) ?? \"\";\n const instance = new ControllerClass();\n const routes = ROUTES.get(ControllerClass) ?? [];\n\n routes.forEach((r) => {\n const handler = async (\n req: RequestServer,\n res: ResponseServer,\n next?: (err?: unknown) => void\n ) => {\n try {\n const params = (r.params ?? []).slice().sort((a, b) => a.index - b.index);\n const args = params.map((p) => {\n switch (p.type) {\n case \"req\":\n return req;\n case \"res\":\n return res;\n case \"next\":\n return next;\n case \"param\":\n return p.name ? req.params[p.name] : req.params;\n case \"query\":\n return p.name ? req.query[p.name] : req.query;\n case \"body\": {\n const body = req.body as Record<string, unknown> | undefined;\n return p.name ? body?.[p.name] : body;\n }\n case \"headers\":\n return p.name ? req.headers[p.name.toLowerCase()] : req.headers;\n case \"ip\":\n return req.ip;\n case \"useragent\":\n return req.headers[\"user-agent\"];\n default:\n return undefined;\n }\n });\n\n const fn = (instance as Record<string, unknown>)[r.propertyKey] as (\n ...args: unknown[]\n ) => unknown;\n const result = fn(...args);\n if (result instanceof Promise) await result;\n } catch (err) {\n if (next) next(err);\n }\n };\n\n app.addRoute(r.method, prefix + r.path, handler);\n });\n });\n}\n\n/**\n * Get routes metadata from a controller class\n * @internal Used by Swagger integration\n */\nexport function getControllerMetadata(ControllerClass: Function) {\n return {\n prefix: PREFIX.get(ControllerClass) || \"\",\n routes: ROUTES.get(ControllerClass) || [],\n params: PARAMS.get(ControllerClass),\n descriptions: DESCRIPTIONS.get(ControllerClass),\n };\n}\n","import type {\n ApiDocMetadata,\n ApiResponseMetadata,\n ApiParameterMetadata,\n ApiBodyMetadata,\n Schema,\n SecurityRequirement,\n Header,\n} from \"../types/swagger.type\";\n\nconst API_METADATA = new WeakMap<Function, Map<string, ApiDocMetadata>>();\nconst API_RESPONSES = new WeakMap<Function, Map<string, ApiResponseMetadata[]>>();\nconst API_PARAMETERS = new WeakMap<Function, Map<string, ApiParameterMetadata[]>>();\nconst API_BODY = new WeakMap<Function, Map<string, ApiBodyMetadata>>();\nconst API_TAGS = new WeakMap<Function, string[]>();\n\n/**\n * Decorator to document an endpoint\n */\nexport function ApiDoc(metadata: Omit<ApiDocMetadata, \"method\" | \"path\">): MethodDecorator {\n return (target, propertyKey) => {\n const ctor =\n typeof target === \"function\" ? (target as Function) : (target as any).constructor;\n let map = API_METADATA.get(ctor);\n if (!map) {\n map = new Map<string, ApiDocMetadata>();\n API_METADATA.set(ctor, map);\n }\n map.set(String(propertyKey), metadata);\n };\n}\n\n/**\n * Decorator to document a response\n */\nexport function ApiResponse(\n statusCode: number,\n description: string,\n options?: {\n type?: any;\n examples?: Record<string, any>;\n headers?: Record<string, Header>;\n }\n): MethodDecorator {\n return (target, propertyKey) => {\n const ctor =\n typeof target === \"function\" ? (target as Function) : (target as any).constructor;\n let map = API_RESPONSES.get(ctor);\n if (!map) {\n map = new Map<string, ApiResponseMetadata[]>();\n API_RESPONSES.set(ctor, map);\n }\n\n const key = String(propertyKey);\n const responses = map.get(key) ?? [];\n responses.push({\n statusCode,\n description,\n type: options?.type,\n examples: options?.examples,\n headers: options?.headers,\n });\n map.set(key, responses);\n };\n}\n\n/**\n * Decorator to document a parameter\n */\nexport function ApiParameter(\n name: string,\n paramIn: \"query\" | \"header\" | \"path\" | \"cookie\",\n options?: {\n description?: string;\n required?: boolean;\n type?: any;\n example?: any;\n schema?: Schema;\n }\n): MethodDecorator {\n return (target, propertyKey) => {\n const ctor =\n typeof target === \"function\" ? (target as Function) : (target as any).constructor;\n let map = API_PARAMETERS.get(ctor);\n if (!map) {\n map = new Map<string, ApiParameterMetadata[]>();\n API_PARAMETERS.set(ctor, map);\n }\n\n const key = String(propertyKey);\n const params = map.get(key) ?? [];\n params.push({\n name,\n in: paramIn,\n description: options?.description,\n required: options?.required,\n type: options?.type,\n example: options?.example,\n schema: options?.schema,\n });\n map.set(key, params);\n };\n}\n\n/**\n * Decorator to document a request body\n */\nexport function ApiBody(\n description: string,\n options?: {\n type?: any;\n required?: boolean;\n examples?: Record<string, any>;\n }\n): MethodDecorator {\n return (target, propertyKey) => {\n const ctor =\n typeof target === \"function\" ? (target as Function) : (target as any).constructor;\n let map = API_BODY.get(ctor);\n if (!map) {\n map = new Map<string, ApiBodyMetadata>();\n API_BODY.set(ctor, map);\n }\n\n map.set(String(propertyKey), {\n description,\n type: options?.type,\n required: options?.required,\n examples: options?.examples,\n });\n };\n}\n\n/**\n * Decorator to add tags to a controller\n */\nexport function ApiTags(...tags: string[]): ClassDecorator {\n return (target) => {\n API_TAGS.set(target as Function, tags);\n };\n}\n\n/**\n * Decorator to mark an endpoint as deprecated\n */\nexport function ApiDeprecated(): MethodDecorator {\n return (target, propertyKey) => {\n const ctor =\n typeof target === \"function\" ? (target as Function) : (target as any).constructor;\n let map = API_METADATA.get(ctor);\n if (!map) {\n map = new Map<string, ApiDocMetadata>();\n API_METADATA.set(ctor, map);\n }\n\n const key = String(propertyKey);\n const existing = map.get(key) ?? {};\n map.set(key, { ...existing, deprecated: true });\n };\n}\n\n/**\n * Decorator to add security requirements\n */\nexport function ApiSecurity(...requirements: SecurityRequirement[]): MethodDecorator {\n return (target, propertyKey) => {\n const ctor =\n typeof target === \"function\" ? (target as Function) : (target as any).constructor;\n let map = API_METADATA.get(ctor);\n if (!map) {\n map = new Map<string, ApiDocMetadata>();\n API_METADATA.set(ctor, map);\n }\n\n const key = String(propertyKey);\n const existing = map.get(key) ?? {};\n map.set(key, { ...existing, security: requirements });\n };\n}\n\n/**\n * Helper to get all swagger metadata\n */\nexport function getSwaggerMetadata(target: Function) {\n return {\n metadata: API_METADATA.get(target),\n responses: API_RESPONSES.get(target),\n parameters: API_PARAMETERS.get(target),\n body: API_BODY.get(target),\n tags: API_TAGS.get(target),\n };\n}\n\n/**\n * Unified Swagger decorator - Simple and easy to use!\n * Document everything in one place with a clean object structure.\n * \n * @example\n * ```typescript\n * @Swagger({\n * summary: \"Get user by ID\",\n * description: \"Retrieve a single user\",\n * tags: [\"Users\"],\n * parameters: [\n * {\n * name: \"id\",\n * in: \"path\",\n * description: \"User ID\",\n * required: true,\n * schema: { type: \"string\" },\n * example: \"123\"\n * }\n * ],\n * responses: {\n * 200: {\n * description: \"User found\",\n * example: { id: \"123\", name: \"John\" }\n * },\n * 404: {\n * description: \"User not found\",\n * example: { error: \"Not found\" }\n * }\n * }\n * })\n * getUser(req, res) { }\n * ```\n */\nexport function Swagger(config: {\n summary?: string;\n description?: string;\n tags?: string[];\n operationId?: string;\n deprecated?: boolean;\n security?: SecurityRequirement[];\n parameters?: Array<{\n name: string;\n in: \"query\" | \"header\" | \"path\" | \"cookie\";\n description?: string;\n required?: boolean;\n schema?: Schema;\n example?: any;\n }>;\n requestBody?: {\n description?: string;\n required?: boolean;\n content?: any;\n example?: any;\n };\n responses?: Record<number, {\n description: string;\n example?: any;\n schema?: Schema;\n headers?: Record<string, Header>;\n }>;\n}): MethodDecorator {\n return (target, propertyKey) => {\n const ctor = typeof target === \"function\" ? (target as Function) : (target as any).constructor;\n const key = String(propertyKey);\n\n // Set basic metadata\n if (config.summary || config.description || config.operationId || config.deprecated !== undefined || config.security) {\n let metaMap = API_METADATA.get(ctor);\n if (!metaMap) {\n metaMap = new Map<string, ApiDocMetadata>();\n API_METADATA.set(ctor, metaMap);\n }\n metaMap.set(key, {\n summary: config.summary,\n description: config.description,\n operationId: config.operationId,\n deprecated: config.deprecated,\n security: config.security,\n tags: config.tags,\n });\n }\n\n // Set parameters\n if (config.parameters && config.parameters.length > 0) {\n let paramMap = API_PARAMETERS.get(ctor);\n if (!paramMap) {\n paramMap = new Map<string, ApiParameterMetadata[]>();\n API_PARAMETERS.set(ctor, paramMap);\n }\n paramMap.set(key, config.parameters.map(p => ({\n name: p.name,\n in: p.in,\n description: p.description,\n required: p.required,\n schema: p.schema,\n example: p.example,\n })));\n }\n\n // Set request body\n if (config.requestBody) {\n let bodyMap = API_BODY.get(ctor);\n if (!bodyMap) {\n bodyMap = new Map<string, ApiBodyMetadata>();\n API_BODY.set(ctor, bodyMap);\n }\n bodyMap.set(key, {\n description: config.requestBody.description,\n required: config.requestBody.required,\n type: config.requestBody.content,\n examples: config.requestBody.example ? { default: config.requestBody.example } : undefined,\n });\n }\n\n // Set responses\n if (config.responses) {\n let respMap = API_RESPONSES.get(ctor);\n if (!respMap) {\n respMap = new Map<string, ApiResponseMetadata[]>();\n API_RESPONSES.set(ctor, respMap);\n }\n const responses = Object.entries(config.responses).map(([code, resp]) => ({\n statusCode: Number(code),\n description: resp.description,\n type: resp.schema,\n examples: resp.example ? { default: resp.example } : undefined,\n headers: resp.headers,\n }));\n respMap.set(key, responses);\n }\n };\n}\n"]}
|
package/dist/decorators.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { A as AzuraClient } from './Server-CVyJAYne.cjs';
|
|
2
2
|
import { R as RouteDefinition, P as ParamDefinition } from './swagger.type-BWq5nhCX.cjs';
|
|
3
3
|
export { a as ParamSource } from './swagger.type-BWq5nhCX.cjs';
|
|
4
|
-
export { c as ApiBody, e as ApiDeprecated, A as ApiDoc, b as ApiParameter, a as ApiResponse, f as ApiSecurity, d as ApiTags, g as getSwaggerMetadata } from './Swagger-
|
|
4
|
+
export { c as ApiBody, e as ApiDeprecated, A as ApiDoc, b as ApiParameter, a as ApiResponse, f as ApiSecurity, d as ApiTags, g as getSwaggerMetadata } from './Swagger-BWCRS_VR.cjs';
|
|
5
5
|
import './config.cjs';
|
|
6
6
|
import 'node:http';
|
|
7
7
|
import './router.cjs';
|
package/dist/decorators.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { A as AzuraClient } from './Server-CbcNkm0I.js';
|
|
2
2
|
import { R as RouteDefinition, P as ParamDefinition } from './swagger.type-BWq5nhCX.js';
|
|
3
3
|
export { a as ParamSource } from './swagger.type-BWq5nhCX.js';
|
|
4
|
-
export { c as ApiBody, e as ApiDeprecated, A as ApiDoc, b as ApiParameter, a as ApiResponse, f as ApiSecurity, d as ApiTags, g as getSwaggerMetadata } from './Swagger-
|
|
4
|
+
export { c as ApiBody, e as ApiDeprecated, A as ApiDoc, b as ApiParameter, a as ApiResponse, f as ApiSecurity, d as ApiTags, g as getSwaggerMetadata } from './Swagger-BuMxfyha.js';
|
|
5
5
|
import './config.js';
|
|
6
6
|
import 'node:http';
|
|
7
7
|
import './router.js';
|
package/dist/decorators.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/decorators/Route.ts","../src/decorators/Swagger.ts"],"names":[],"mappings":";AAKA,IAAM,MAAA,uBAAa,OAAA,EAA0B;AAC7C,IAAM,MAAA,uBAAa,OAAA,EAAqC;AACxD,IAAM,MAAA,uBAAa,OAAA,EAAkD;AACrE,IAAM,YAAA,uBAAmB,OAAA,EAAuC;AAEzD,SAAS,UAAA,CAAW,SAAS,EAAA,EAAoB;AACtD,EAAA,OAAO,CAAC,MAAA,KAAW;AACjB,IAAA,MAAA,CAAO,GAAA,CAAI,QAAoB,MAAM,CAAA;AAAA,EACvC,CAAA;AACF;AAeA,SAAS,sBAAsB,MAAA,EAAgB;AAC7C,EAAA,OAAO,SAAU,OAAO,EAAA,EAAqB;AAC3C,IAAA,OAAO,CAAC,QAAQ,WAAA,KAAgB;AAC9B,MAAA,MAAM,IAAA,GACJ,OAAO,MAAA,KAAW,UAAA,GAAc,SAAuB,MAAA,CAAe,WAAA;AACxE,MAAA,MAAM,GAAA,GAAM,OAAO,WAAW,CAAA;AAC9B,MAAA,MAAM,MAAA,GAAS,MAAA,CAAO,GAAA,CAAI,IAAI,KAAK,EAAC;AACpC,MAAA,MAAM,MAAA,GAAS,OAAO,GAAA,CAAI,IAAI,GAAG,GAAA,CAAI,GAAG,KAAK,EAAC;AAC9C,MAAA,MAAM,cAAc,YAAA,CAAa,GAAA,CAAI,IAAI,CAAA,EAAG,IAAI,GAAG,CAAA;AAEnD,MAAA,M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E,GAAG,QAAA,EAAU,QAAA,EAAU,cAAc,CAAA;AAAA,EACtD,CAAA;AACF;AAKO,SAAS,mBAAmB,MAAA,EAAkB;AACnD,EAAA,OAAO;AAAA,IACL,QAAA,EAAU,YAAA,CAAa,GAAA,CAAI,MAAM,CAAA;AAAA,IACjC,SAAA,EAAW,aAAA,CAAc,GAAA,CAAI,MAAM,CAAA;AAAA,IACnC,UAAA,EAAY,cAAA,CAAe,GAAA,CAAI,MAAM,CAAA;AAAA,IACrC,IAAA,EAAM,QAAA,CAAS,GAAA,CAAI,MAAM,CAAA;AAAA,IACzB,IAAA,EAAM,QAAA,CAAS,GAAA,CAAI,MAAM;AAAA,GAC3B;AACF","file":"decorators.js","sourcesContent":["import type { AzuraClient } from \"../infra/Server\";\nimport type { RequestServer } from \"../types/http/request.type\";\nimport type { ResponseServer } from \"../types/http/response.type\";\nimport type { ParamDefinition, ParamSource, RouteDefinition } from \"../types/routes.type\";\n\nconst PREFIX = new WeakMap<Function, string>();\nconst ROUTES = new WeakMap<Function, RouteDefinition[]>();\nconst PARAMS = new WeakMap<Function, Map<string, ParamDefinition[]>>();\nconst DESCRIPTIONS = new WeakMap<Function, Map<string, string>>();\n\nexport function Controller(prefix = \"\"): ClassDecorator {\n return (target) => {\n PREFIX.set(target as Function, prefix);\n };\n}\n\nexport function Description(description: string): MethodDecorator {\n return (target, propertyKey) => {\n const ctor =\n typeof target === \"function\" ? (target as Function) : (target as any).constructor;\n let map = DESCRIPTIONS.get(ctor);\n if (!map) {\n map = new Map<string, string>();\n DESCRIPTIONS.set(ctor, map);\n }\n map.set(String(propertyKey), description);\n };\n}\n\nfunction createMethodDecorator(method: string) {\n return function (path = \"\"): MethodDecorator {\n return (target, propertyKey) => {\n const ctor =\n typeof target === \"function\" ? (target as Function) : (target as any).constructor;\n const key = String(propertyKey);\n const routes = ROUTES.get(ctor) ?? [];\n const params = PARAMS.get(ctor)?.get(key) ?? [];\n const description = DESCRIPTIONS.get(ctor)?.get(key);\n\n const exists = routes.some(\n (r) => r.method === method && r.path === path && r.propertyKey === key\n );\n if (!exists) {\n routes.push({\n method,\n path,\n propertyKey: key,\n params,\n description,\n });\n ROUTES.set(ctor, routes);\n }\n };\n };\n}\n\nfunction createParamDecorator(type: ParamSource) {\n return function (name?: string): ParameterDecorator {\n return (target, propertyKey, parameterIndex) => {\n const ctor =\n typeof target === \"function\" ? (target as Function) : (target as any).constructor;\n let map = PARAMS.get(ctor);\n if (!map) {\n map = new Map<string, ParamDefinition[]>();\n PARAMS.set(ctor, map);\n }\n\n const key = String(propertyKey);\n const list = map.get(key) ?? [];\n const exists = list.some(\n (p) => p.index === parameterIndex && p.type === type && p.name === name\n );\n if (!exists) {\n list.push({\n index: parameterIndex,\n type,\n name,\n });\n map.set(key, list);\n }\n };\n };\n}\n\nexport const Get = createMethodDecorator(\"GET\");\nexport const Post = createMethodDecorator(\"POST\");\nexport const Put = createMethodDecorator(\"PUT\");\nexport const Delete = createMethodDecorator(\"DELETE\");\nexport const Patch = createMethodDecorator(\"PATCH\");\nexport const Head = createMethodDecorator(\"HEAD\");\nexport const Options = createMethodDecorator(\"OPTIONS\");\n\nexport const Req = createParamDecorator(\"req\");\nexport const Res = createParamDecorator(\"res\");\nexport const Next = createParamDecorator(\"next\");\nexport const Param = createParamDecorator(\"param\");\nexport const Query = createParamDecorator(\"query\");\nexport const Body = createParamDecorator(\"body\");\nexport const Headers = createParamDecorator(\"headers\");\nexport const Ip = createParamDecorator(\"ip\");\nexport const UserAgent = createParamDecorator(\"useragent\");\n\nexport function applyDecorators(app: AzuraClient, controllers: Array<new () => any>) {\n controllers.forEach((ControllerClass) => {\n const prefix = PREFIX.get(ControllerClass) ?? \"\";\n const instance = new ControllerClass();\n const routes = ROUTES.get(ControllerClass) ?? [];\n\n routes.forEach((r) => {\n const handler = async (\n req: RequestServer,\n res: ResponseServer,\n next?: (err?: unknown) => void\n ) => {\n try {\n const params = (r.params ?? []).slice().sort((a, b) => a.index - b.index);\n const args = params.map((p) => {\n switch (p.type) {\n case \"req\":\n return req;\n case \"res\":\n return res;\n case \"next\":\n return next;\n case \"param\":\n return p.name ? req.params[p.name] : req.params;\n case \"query\":\n return p.name ? req.query[p.name] : req.query;\n case \"body\": {\n const body = req.body as Record<string, unknown> | undefined;\n return p.name ? body?.[p.name] : body;\n }\n case \"headers\":\n return p.name ? req.headers[p.name.toLowerCase()] : req.headers;\n case \"ip\":\n return req.ip;\n case \"useragent\":\n return req.headers[\"user-agent\"];\n default:\n return undefined;\n }\n });\n\n const fn = (instance as Record<string, unknown>)[r.propertyKey] as (\n ...args: unknown[]\n ) => unknown;\n const result = fn(...args);\n if (result instanceof Promise) await result;\n } catch (err) {\n if (next) next(err);\n }\n };\n\n app.addRoute(r.method, prefix + r.path, handler);\n });\n });\n}\n\n/**\n * Get routes metadata from a controller class\n * @internal Used by Swagger integration\n */\nexport function getControllerMetadata(ControllerClass: Function) {\n return {\n prefix: PREFIX.get(ControllerClass) || \"\",\n routes: ROUTES.get(ControllerClass) || [],\n params: PARAMS.get(ControllerClass),\n descriptions: DESCRIPTIONS.get(ControllerClass),\n };\n}\n","import type {\n ApiDocMetadata,\n ApiResponseMetadata,\n ApiParameterMetadata,\n ApiBodyMetadata,\n Schema,\n SecurityRequirement,\n Header,\n} from \"../types/swagger.type\";\n\nconst API_METADATA = new WeakMap<Function, Map<string, ApiDocMetadata>>();\nconst API_RESPONSES = new WeakMap<Function, Map<string, ApiResponseMetadata[]>>();\nconst API_PARAMETERS = new WeakMap<Function, Map<string, ApiParameterMetadata[]>>();\nconst API_BODY = new WeakMap<Function, Map<string, ApiBodyMetadata>>();\nconst API_TAGS = new WeakMap<Function, string[]>();\n\n/**\n * Decorator to document an endpoint\n */\nexport function ApiDoc(metadata: Omit<ApiDocMetadata, \"method\" | \"path\">): MethodDecorator {\n return (target, propertyKey) => {\n const ctor =\n typeof target === \"function\" ? (target as Function) : (target as any).constructor;\n let map = API_METADATA.get(ctor);\n if (!map) {\n map = new Map<string, ApiDocMetadata>();\n API_METADATA.set(ctor, map);\n }\n map.set(String(propertyKey), metadata);\n };\n}\n\n/**\n * Decorator to document a response\n */\nexport function ApiResponse(\n statusCode: number,\n description: string,\n options?: {\n type?: any;\n examples?: Record<string, any>;\n headers?: Record<string, Header>;\n }\n): MethodDecorator {\n return (target, propertyKey) => {\n const ctor =\n typeof target === \"function\" ? (target as Function) : (target as any).constructor;\n let map = API_RESPONSES.get(ctor);\n if (!map) {\n map = new Map<string, ApiResponseMetadata[]>();\n API_RESPONSES.set(ctor, map);\n }\n\n const key = String(propertyKey);\n const responses = map.get(key) ?? [];\n responses.push({\n statusCode,\n description,\n type: options?.type,\n examples: options?.examples,\n headers: options?.headers,\n });\n map.set(key, responses);\n };\n}\n\n/**\n * Decorator to document a parameter\n */\nexport function ApiParameter(\n name: string,\n paramIn: \"query\" | \"header\" | \"path\" | \"cookie\",\n options?: {\n description?: string;\n required?: boolean;\n type?: any;\n example?: any;\n schema?: Schema;\n }\n): MethodDecorator {\n return (target, propertyKey) => {\n const ctor =\n typeof target === \"function\" ? (target as Function) : (target as any).constructor;\n let map = API_PARAMETERS.get(ctor);\n if (!map) {\n map = new Map<string, ApiParameterMetadata[]>();\n API_PARAMETERS.set(ctor, map);\n }\n\n const key = String(propertyKey);\n const params = map.get(key) ?? [];\n params.push({\n name,\n in: paramIn,\n description: options?.description,\n required: options?.required,\n type: options?.type,\n example: options?.example,\n schema: options?.schema,\n });\n map.set(key, params);\n };\n}\n\n/**\n * Decorator to document a request body\n */\nexport function ApiBody(\n description: string,\n options?: {\n type?: any;\n required?: boolean;\n examples?: Record<string, any>;\n }\n): MethodDecorator {\n return (target, propertyKey) => {\n const ctor =\n typeof target === \"function\" ? (target as Function) : (target as any).constructor;\n let map = API_BODY.get(ctor);\n if (!map) {\n map = new Map<string, ApiBodyMetadata>();\n API_BODY.set(ctor, map);\n }\n\n map.set(String(propertyKey), {\n description,\n type: options?.type,\n required: options?.required,\n examples: options?.examples,\n });\n };\n}\n\n/**\n * Decorator to add tags to a controller\n */\nexport function ApiTags(...tags: string[]): ClassDecorator {\n return (target) => {\n API_TAGS.set(target as Function, tags);\n };\n}\n\n/**\n * Decorator to mark an endpoint as deprecated\n */\nexport function ApiDeprecated(): MethodDecorator {\n return (target, propertyKey) => {\n const ctor =\n typeof target === \"function\" ? (target as Function) : (target as any).constructor;\n let map = API_METADATA.get(ctor);\n if (!map) {\n map = new Map<string, ApiDocMetadata>();\n API_METADATA.set(ctor, map);\n }\n\n const key = String(propertyKey);\n const existing = map.get(key) ?? {};\n map.set(key, { ...existing, deprecated: true });\n };\n}\n\n/**\n * Decorator to add security requirements\n */\nexport function ApiSecurity(...requirements: SecurityRequirement[]): MethodDecorator {\n return (target, propertyKey) => {\n const ctor =\n typeof target === \"function\" ? (target as Function) : (target as any).constructor;\n let map = API_METADATA.get(ctor);\n if (!map) {\n map = new Map<string, ApiDocMetadata>();\n API_METADATA.set(ctor, map);\n }\n\n const key = String(propertyKey);\n const existing = map.get(key) ?? {};\n map.set(key, { ...existing, security: requirements });\n };\n}\n\n/**\n * Helper to get all swagger metadata\n */\nexport function getSwaggerMetadata(target: Function) {\n return {\n metadata: API_METADATA.get(target),\n responses: API_RESPONSES.get(target),\n parameters: API_PARAMETERS.get(target),\n body: API_BODY.get(target),\n tags: API_TAGS.get(target),\n };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/decorators/Route.ts","../src/decorators/Swagger.ts"],"names":[],"mappings":";AAKA,IAAM,MAAA,uBAAa,OAAA,EAA0B;AAC7C,IAAM,MAAA,uBAAa,OAAA,EAAqC;AACxD,IAAM,MAAA,uBAAa,OAAA,EAAkD;AACrE,IAAM,YAAA,uBAAmB,OAAA,EAAuC;AAEzD,SAAS,UAAA,CAAW,SAAS,EAAA,EAAoB;AACtD,EAAA,OAAO,CAAC,MAAA,KAAW;AACjB,IAAA,MAAA,CAAO,GAAA,CAAI,QAAoB,MAAM,CAAA;AAAA,EACvC,CAAA;AACF;AAeA,SAAS,s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D;AACnF,EAAA,OAAO,CAAC,QAAQ,WAAA,KAAgB;AAC9B,IAAA,MAAM,IAAA,GACJ,OAAO,MAAA,KAAW,UAAA,GAAc,SAAuB,MAAA,CAAe,WAAA;AACxE,IAAA,IAAI,GAAA,GAAM,YAAA,CAAa,GAAA,CAAI,IAAI,CAAA;AAC/B,IAAA,IAAI,CAAC,GAAA,EAAK;AACR,MAAA,GAAA,uBAAU,GAAA,EAA4B;AACtC,MAAA,YAAA,CAAa,GAAA,CAAI,MAAM,GAAG,CAAA;AAAA,IAC5B;AAEA,IAAA,MAAM,GAAA,GAAM,OAAO,WAAW,CAAA;AAC9B,IAAA,MAAM,QAAA,GAAW,GAAA,CAAI,GAAA,CAAI,GAAG,KAAK,EAAC;AAClC,IAAA,GAAA,CAAI,IAAI,GAAA,EAAK,EAAE,GAAG,QAAA,EAAU,QAAA,EAAU,cAAc,CAAA;AAAA,EACtD,CAAA;AACF;AAKO,SAAS,mBAAmB,MAAA,EAAkB;AACnD,EAAA,OAAO;AAAA,IACL,QAAA,EAAU,YAAA,CAAa,GAAA,CAAI,MAAM,CAAA;AAAA,IACjC,SAAA,EAAW,aAAA,CAAc,GAAA,CAAI,MAAM,CAAA;AAAA,IACnC,UAAA,EAAY,cAAA,CAAe,GAAA,CAAI,MAAM,CAAA;AAAA,IACrC,IAAA,EAAM,QAAA,CAAS,GAAA,CAAI,MAAM,CAAA;AAAA,IACzB,IAAA,EAAM,QAAA,CAAS,GAAA,CAAI,MAAM;AAAA,GAC3B;AACF","file":"decorators.js","sourcesContent":["import type { AzuraClient } from \"../infra/Server\";\nimport type { RequestServer } from \"../types/http/request.type\";\nimport type { ResponseServer } from \"../types/http/response.type\";\nimport type { ParamDefinition, ParamSource, RouteDefinition } from \"../types/routes.type\";\n\nconst PREFIX = new WeakMap<Function, string>();\nconst ROUTES = new WeakMap<Function, RouteDefinition[]>();\nconst PARAMS = new WeakMap<Function, Map<string, ParamDefinition[]>>();\nconst DESCRIPTIONS = new WeakMap<Function, Map<string, string>>();\n\nexport function Controller(prefix = \"\"): ClassDecorator {\n return (target) => {\n PREFIX.set(target as Function, prefix);\n };\n}\n\nexport function Description(description: string): MethodDecorator {\n return (target, propertyKey) => {\n const ctor =\n typeof target === \"function\" ? (target as Function) : (target as any).constructor;\n let map = DESCRIPTIONS.get(ctor);\n if (!map) {\n map = new Map<string, string>();\n DESCRIPTIONS.set(ctor, map);\n }\n map.set(String(propertyKey), description);\n };\n}\n\nfunction createMethodDecorator(method: string) {\n return function (path = \"\"): MethodDecorator {\n return (target, propertyKey) => {\n const ctor =\n typeof target === \"function\" ? (target as Function) : (target as any).constructor;\n const key = String(propertyKey);\n const routes = ROUTES.get(ctor) ?? [];\n const params = PARAMS.get(ctor)?.get(key) ?? [];\n const description = DESCRIPTIONS.get(ctor)?.get(key);\n\n const exists = routes.some(\n (r) => r.method === method && r.path === path && r.propertyKey === key\n );\n if (!exists) {\n routes.push({\n method,\n path,\n propertyKey: key,\n params,\n description,\n });\n ROUTES.set(ctor, routes);\n }\n };\n };\n}\n\nfunction createParamDecorator(type: ParamSource) {\n return function (name?: string): ParameterDecorator {\n return (target, propertyKey, parameterIndex) => {\n const ctor =\n typeof target === \"function\" ? (target as Function) : (target as any).constructor;\n let map = PARAMS.get(ctor);\n if (!map) {\n map = new Map<string, ParamDefinition[]>();\n PARAMS.set(ctor, map);\n }\n\n const key = String(propertyKey);\n const list = map.get(key) ?? [];\n const exists = list.some(\n (p) => p.index === parameterIndex && p.type === type && p.name === name\n );\n if (!exists) {\n list.push({\n index: parameterIndex,\n type,\n name,\n });\n map.set(key, list);\n }\n };\n };\n}\n\nexport const Get = createMethodDecorator(\"GET\");\nexport const Post = createMethodDecorator(\"POST\");\nexport const Put = createMethodDecorator(\"PUT\");\nexport const Delete = createMethodDecorator(\"DELETE\");\nexport const Patch = createMethodDecorator(\"PATCH\");\nexport const Head = createMethodDecorator(\"HEAD\");\nexport const Options = createMethodDecorator(\"OPTIONS\");\n\nexport const Req = createParamDecorator(\"req\");\nexport const Res = createParamDecorator(\"res\");\nexport const Next = createParamDecorator(\"next\");\nexport const Param = createParamDecorator(\"param\");\nexport const Query = createParamDecorator(\"query\");\nexport const Body = createParamDecorator(\"body\");\nexport const Headers = createParamDecorator(\"headers\");\nexport const Ip = createParamDecorator(\"ip\");\nexport const UserAgent = createParamDecorator(\"useragent\");\n\nexport function applyDecorators(app: AzuraClient, controllers: Array<new () => any>) {\n controllers.forEach((ControllerClass) => {\n const prefix = PREFIX.get(ControllerClass) ?? \"\";\n const instance = new ControllerClass();\n const routes = ROUTES.get(ControllerClass) ?? [];\n\n routes.forEach((r) => {\n const handler = async (\n req: RequestServer,\n res: ResponseServer,\n next?: (err?: unknown) => void\n ) => {\n try {\n const params = (r.params ?? []).slice().sort((a, b) => a.index - b.index);\n const args = params.map((p) => {\n switch (p.type) {\n case \"req\":\n return req;\n case \"res\":\n return res;\n case \"next\":\n return next;\n case \"param\":\n return p.name ? req.params[p.name] : req.params;\n case \"query\":\n return p.name ? req.query[p.name] : req.query;\n case \"body\": {\n const body = req.body as Record<string, unknown> | undefined;\n return p.name ? body?.[p.name] : body;\n }\n case \"headers\":\n return p.name ? req.headers[p.name.toLowerCase()] : req.headers;\n case \"ip\":\n return req.ip;\n case \"useragent\":\n return req.headers[\"user-agent\"];\n default:\n return undefined;\n }\n });\n\n const fn = (instance as Record<string, unknown>)[r.propertyKey] as (\n ...args: unknown[]\n ) => unknown;\n const result = fn(...args);\n if (result instanceof Promise) await result;\n } catch (err) {\n if (next) next(err);\n }\n };\n\n app.addRoute(r.method, prefix + r.path, handler);\n });\n });\n}\n\n/**\n * Get routes metadata from a controller class\n * @internal Used by Swagger integration\n */\nexport function getControllerMetadata(ControllerClass: Function) {\n return {\n prefix: PREFIX.get(ControllerClass) || \"\",\n routes: ROUTES.get(ControllerClass) || [],\n params: PARAMS.get(ControllerClass),\n descriptions: DESCRIPTIONS.get(ControllerClass),\n };\n}\n","import type {\n ApiDocMetadata,\n ApiResponseMetadata,\n ApiParameterMetadata,\n ApiBodyMetadata,\n Schema,\n SecurityRequirement,\n Header,\n} from \"../types/swagger.type\";\n\nconst API_METADATA = new WeakMap<Function, Map<string, ApiDocMetadata>>();\nconst API_RESPONSES = new WeakMap<Function, Map<string, ApiResponseMetadata[]>>();\nconst API_PARAMETERS = new WeakMap<Function, Map<string, ApiParameterMetadata[]>>();\nconst API_BODY = new WeakMap<Function, Map<string, ApiBodyMetadata>>();\nconst API_TAGS = new WeakMap<Function, string[]>();\n\n/**\n * Decorator to document an endpoint\n */\nexport function ApiDoc(metadata: Omit<ApiDocMetadata, \"method\" | \"path\">): MethodDecorator {\n return (target, propertyKey) => {\n const ctor =\n typeof target === \"function\" ? (target as Function) : (target as any).constructor;\n let map = API_METADATA.get(ctor);\n if (!map) {\n map = new Map<string, ApiDocMetadata>();\n API_METADATA.set(ctor, map);\n }\n map.set(String(propertyKey), metadata);\n };\n}\n\n/**\n * Decorator to document a response\n */\nexport function ApiResponse(\n statusCode: number,\n description: string,\n options?: {\n type?: any;\n examples?: Record<string, any>;\n headers?: Record<string, Header>;\n }\n): MethodDecorator {\n return (target, propertyKey) => {\n const ctor =\n typeof target === \"function\" ? (target as Function) : (target as any).constructor;\n let map = API_RESPONSES.get(ctor);\n if (!map) {\n map = new Map<string, ApiResponseMetadata[]>();\n API_RESPONSES.set(ctor, map);\n }\n\n const key = String(propertyKey);\n const responses = map.get(key) ?? [];\n responses.push({\n statusCode,\n description,\n type: options?.type,\n examples: options?.examples,\n headers: options?.headers,\n });\n map.set(key, responses);\n };\n}\n\n/**\n * Decorator to document a parameter\n */\nexport function ApiParameter(\n name: string,\n paramIn: \"query\" | \"header\" | \"path\" | \"cookie\",\n options?: {\n description?: string;\n required?: boolean;\n type?: any;\n example?: any;\n schema?: Schema;\n }\n): MethodDecorator {\n return (target, propertyKey) => {\n const ctor =\n typeof target === \"function\" ? (target as Function) : (target as any).constructor;\n let map = API_PARAMETERS.get(ctor);\n if (!map) {\n map = new Map<string, ApiParameterMetadata[]>();\n API_PARAMETERS.set(ctor, map);\n }\n\n const key = String(propertyKey);\n const params = map.get(key) ?? [];\n params.push({\n name,\n in: paramIn,\n description: options?.description,\n required: options?.required,\n type: options?.type,\n example: options?.example,\n schema: options?.schema,\n });\n map.set(key, params);\n };\n}\n\n/**\n * Decorator to document a request body\n */\nexport function ApiBody(\n description: string,\n options?: {\n type?: any;\n required?: boolean;\n examples?: Record<string, any>;\n }\n): MethodDecorator {\n return (target, propertyKey) => {\n const ctor =\n typeof target === \"function\" ? (target as Function) : (target as any).constructor;\n let map = API_BODY.get(ctor);\n if (!map) {\n map = new Map<string, ApiBodyMetadata>();\n API_BODY.set(ctor, map);\n }\n\n map.set(String(propertyKey), {\n description,\n type: options?.type,\n required: options?.required,\n examples: options?.examples,\n });\n };\n}\n\n/**\n * Decorator to add tags to a controller\n */\nexport function ApiTags(...tags: string[]): ClassDecorator {\n return (target) => {\n API_TAGS.set(target as Function, tags);\n };\n}\n\n/**\n * Decorator to mark an endpoint as deprecated\n */\nexport function ApiDeprecated(): MethodDecorator {\n return (target, propertyKey) => {\n const ctor =\n typeof target === \"function\" ? (target as Function) : (target as any).constructor;\n let map = API_METADATA.get(ctor);\n if (!map) {\n map = new Map<string, ApiDocMetadata>();\n API_METADATA.set(ctor, map);\n }\n\n const key = String(propertyKey);\n const existing = map.get(key) ?? {};\n map.set(key, { ...existing, deprecated: true });\n };\n}\n\n/**\n * Decorator to add security requirements\n */\nexport function ApiSecurity(...requirements: SecurityRequirement[]): MethodDecorator {\n return (target, propertyKey) => {\n const ctor =\n typeof target === \"function\" ? (target as Function) : (target as any).constructor;\n let map = API_METADATA.get(ctor);\n if (!map) {\n map = new Map<string, ApiDocMetadata>();\n API_METADATA.set(ctor, map);\n }\n\n const key = String(propertyKey);\n const existing = map.get(key) ?? {};\n map.set(key, { ...existing, security: requirements });\n };\n}\n\n/**\n * Helper to get all swagger metadata\n */\nexport function getSwaggerMetadata(target: Function) {\n return {\n metadata: API_METADATA.get(target),\n responses: API_RESPONSES.get(target),\n parameters: API_PARAMETERS.get(target),\n body: API_BODY.get(target),\n tags: API_TAGS.get(target),\n };\n}\n\n/**\n * Unified Swagger decorator - Simple and easy to use!\n * Document everything in one place with a clean object structure.\n * \n * @example\n * ```typescript\n * @Swagger({\n * summary: \"Get user by ID\",\n * description: \"Retrieve a single user\",\n * tags: [\"Users\"],\n * parameters: [\n * {\n * name: \"id\",\n * in: \"path\",\n * description: \"User ID\",\n * required: true,\n * schema: { type: \"string\" },\n * example: \"123\"\n * }\n * ],\n * responses: {\n * 200: {\n * description: \"User found\",\n * example: { id: \"123\", name: \"John\" }\n * },\n * 404: {\n * description: \"User not found\",\n * example: { error: \"Not found\" }\n * }\n * }\n * })\n * getUser(req, res) { }\n * ```\n */\nexport function Swagger(config: {\n summary?: string;\n description?: string;\n tags?: string[];\n operationId?: string;\n deprecated?: boolean;\n security?: SecurityRequirement[];\n parameters?: Array<{\n name: string;\n in: \"query\" | \"header\" | \"path\" | \"cookie\";\n description?: string;\n required?: boolean;\n schema?: Schema;\n example?: any;\n }>;\n requestBody?: {\n description?: string;\n required?: boolean;\n content?: any;\n example?: any;\n };\n responses?: Record<number, {\n description: string;\n example?: any;\n schema?: Schema;\n headers?: Record<string, Header>;\n }>;\n}): MethodDecorator {\n return (target, propertyKey) => {\n const ctor = typeof target === \"function\" ? (target as Function) : (target as any).constructor;\n const key = String(propertyKey);\n\n // Set basic metadata\n if (config.summary || config.description || config.operationId || config.deprecated !== undefined || config.security) {\n let metaMap = API_METADATA.get(ctor);\n if (!metaMap) {\n metaMap = new Map<string, ApiDocMetadata>();\n API_METADATA.set(ctor, metaMap);\n }\n metaMap.set(key, {\n summary: config.summary,\n description: config.description,\n operationId: config.operationId,\n deprecated: config.deprecated,\n security: config.security,\n tags: config.tags,\n });\n }\n\n // Set parameters\n if (config.parameters && config.parameters.length > 0) {\n let paramMap = API_PARAMETERS.get(ctor);\n if (!paramMap) {\n paramMap = new Map<string, ApiParameterMetadata[]>();\n API_PARAMETERS.set(ctor, paramMap);\n }\n paramMap.set(key, config.parameters.map(p => ({\n name: p.name,\n in: p.in,\n description: p.description,\n required: p.required,\n schema: p.schema,\n example: p.example,\n })));\n }\n\n // Set request body\n if (config.requestBody) {\n let bodyMap = API_BODY.get(ctor);\n if (!bodyMap) {\n bodyMap = new Map<string, ApiBodyMetadata>();\n API_BODY.set(ctor, bodyMap);\n }\n bodyMap.set(key, {\n description: config.requestBody.description,\n required: config.requestBody.required,\n type: config.requestBody.content,\n examples: config.requestBody.example ? { default: config.requestBody.example } : undefined,\n });\n }\n\n // Set responses\n if (config.responses) {\n let respMap = API_RESPONSES.get(ctor);\n if (!respMap) {\n respMap = new Map<string, ApiResponseMetadata[]>();\n API_RESPONSES.set(ctor, respMap);\n }\n const responses = Object.entries(config.responses).map(([code, resp]) => ({\n statusCode: Number(code),\n description: resp.description,\n type: resp.schema,\n examples: resp.example ? { default: resp.example } : undefined,\n headers: resp.headers,\n }));\n respMap.set(key, responses);\n }\n };\n}\n"]}
|
package/dist/index.cjs
CHANGED
|
@@ -341,28 +341,58 @@ var Router = class _Router {
|
|
|
341
341
|
add(method, path2, ...handlers) {
|
|
342
342
|
const segments = path2.split("/").filter(Boolean);
|
|
343
343
|
let node = this.root;
|
|
344
|
+
if (this.debug) {
|
|
345
|
+
console.log(`[Router:DEBUG] Adding ${method} ${path2}`);
|
|
346
|
+
console.log(`[Router:DEBUG] Segments:`, segments);
|
|
347
|
+
}
|
|
344
348
|
for (const seg of segments) {
|
|
345
349
|
let child;
|
|
346
350
|
if (seg.startsWith(":")) {
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
351
|
+
const paramKey = ":";
|
|
352
|
+
const existingChild = node.children.get(paramKey);
|
|
353
|
+
if (!existingChild) {
|
|
354
|
+
child = new Node();
|
|
355
|
+
child.isParam = true;
|
|
356
|
+
child.paramName = seg.slice(1);
|
|
357
|
+
node.children.set(paramKey, child);
|
|
358
|
+
if (this.debug) {
|
|
359
|
+
console.log(`[Router:DEBUG] Created param node: :${seg.slice(1)}`);
|
|
360
|
+
}
|
|
361
|
+
} else {
|
|
362
|
+
child = existingChild;
|
|
363
|
+
if (child.paramName !== seg.slice(1)) {
|
|
364
|
+
if (this.debug) {
|
|
365
|
+
console.warn(`[Router:DEBUG] Warning: Param name mismatch at "${seg}". Previous: ":${child.paramName}", New: ":${seg.slice(1)}"`);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
350
369
|
} else {
|
|
351
|
-
|
|
370
|
+
const existingLiteralChild = node.children.get(seg);
|
|
371
|
+
if (!existingLiteralChild) {
|
|
372
|
+
child = new Node();
|
|
373
|
+
node.children.set(seg, child);
|
|
374
|
+
if (this.debug) {
|
|
375
|
+
console.log(`[Router:DEBUG] Created literal node: "${seg}"`);
|
|
376
|
+
}
|
|
377
|
+
} else {
|
|
378
|
+
child = existingLiteralChild;
|
|
379
|
+
}
|
|
352
380
|
}
|
|
353
|
-
node.children.set(seg.startsWith(":") ? ":" : seg, child);
|
|
354
381
|
node = child;
|
|
355
382
|
}
|
|
383
|
+
if (this.debug) {
|
|
384
|
+
console.log(`[Router:DEBUG] Setting handler for ${method} at final node`);
|
|
385
|
+
}
|
|
356
386
|
node.handlers.set(method.toUpperCase(), handlers);
|
|
357
387
|
}
|
|
358
388
|
find(method, path2) {
|
|
359
|
-
const cleanPath = path2.split("?")[0];
|
|
360
|
-
const segments = cleanPath
|
|
389
|
+
const cleanPath = path2.split("?")[0] || "/";
|
|
390
|
+
const segments = cleanPath === "/" ? [] : cleanPath.split("/").filter(Boolean);
|
|
361
391
|
let node = this.root;
|
|
362
392
|
const params = {};
|
|
363
|
-
if (this.debug
|
|
364
|
-
console.
|
|
365
|
-
console.
|
|
393
|
+
if (this.debug) {
|
|
394
|
+
console.log(`[Router:DEBUG] Finding ${method} ${cleanPath}`);
|
|
395
|
+
console.log(`[Router:DEBUG] Segments:`, segments);
|
|
366
396
|
}
|
|
367
397
|
for (let i = 0; i < segments.length; i++) {
|
|
368
398
|
const seg = segments[i];
|
|
@@ -370,12 +400,20 @@ var Router = class _Router {
|
|
|
370
400
|
let child = node.children.get(seg);
|
|
371
401
|
if (child) {
|
|
372
402
|
node = child;
|
|
403
|
+
if (this.debug) {
|
|
404
|
+
console.log(`[Router:DEBUG] Matched literal segment: "${seg}"`);
|
|
405
|
+
}
|
|
373
406
|
} else {
|
|
374
407
|
child = node.children.get(":");
|
|
375
408
|
if (child) {
|
|
376
409
|
node = child;
|
|
377
410
|
if (node.paramName) {
|
|
378
411
|
params[node.paramName] = seg;
|
|
412
|
+
if (this.debug) {
|
|
413
|
+
console.log(`[Router:DEBUG] Matched param segment: ":${node.paramName}" = "${seg}"`);
|
|
414
|
+
}
|
|
415
|
+
} else if (this.debug) {
|
|
416
|
+
console.warn(`[Router:DEBUG] Warning: Param node found but paramName is undefined!`);
|
|
379
417
|
}
|
|
380
418
|
} else {
|
|
381
419
|
if (this.debug) {
|
|
@@ -401,6 +439,10 @@ var Router = class _Router {
|
|
|
401
439
|
}
|
|
402
440
|
throw new HttpError(404, "Route not found");
|
|
403
441
|
}
|
|
442
|
+
if (this.debug) {
|
|
443
|
+
console.log(`[Router:DEBUG] Found handlers for ${method} ${cleanPath}`);
|
|
444
|
+
console.log(`[Router:DEBUG] Extracted params:`, params);
|
|
445
|
+
}
|
|
404
446
|
return { handlers, params };
|
|
405
447
|
}
|
|
406
448
|
listRoutes() {
|
|
@@ -487,7 +529,12 @@ function shouldTrustProxy(ip, trustProxy) {
|
|
|
487
529
|
}
|
|
488
530
|
function resolveIp(req, config = {}) {
|
|
489
531
|
const { trustProxy = false, ipHeader = "x-forwarded-for" } = config;
|
|
490
|
-
|
|
532
|
+
let socketIp = req.socket?.remoteAddress || "";
|
|
533
|
+
if (socketIp === "::1" || socketIp === "::ffff:127.0.0.1") {
|
|
534
|
+
socketIp = "127.0.0.1";
|
|
535
|
+
} else if (socketIp.startsWith("::ffff:")) {
|
|
536
|
+
socketIp = socketIp.substring(7);
|
|
537
|
+
}
|
|
491
538
|
if (trustProxy === false) {
|
|
492
539
|
return {
|
|
493
540
|
ip: socketIp,
|
|
@@ -1029,17 +1076,17 @@ var AzuraClient = class {
|
|
|
1029
1076
|
body,
|
|
1030
1077
|
headers: headersObj,
|
|
1031
1078
|
get: (name) => request.headers.get(name.toLowerCase()) || void 0,
|
|
1032
|
-
header: (name) => request.headers.get(name.toLowerCase()) || void 0
|
|
1079
|
+
header: (name) => request.headers.get(name.toLowerCase()) || void 0,
|
|
1080
|
+
socket: {
|
|
1081
|
+
remoteAddress: request.headers.get("x-real-ip") || request.headers.get("x-forwarded-for")?.split(",")[0]?.trim() || "127.0.0.1"
|
|
1082
|
+
}
|
|
1033
1083
|
};
|
|
1034
|
-
const
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
rawReq.ip = "";
|
|
1041
|
-
rawReq.ips = [];
|
|
1042
|
-
}
|
|
1084
|
+
const { ip, ips } = resolveIp(rawReq, {
|
|
1085
|
+
trustProxy: this.opts.server?.trustProxy,
|
|
1086
|
+
ipHeader: this.opts.server?.ipHeader
|
|
1087
|
+
});
|
|
1088
|
+
rawReq.ip = ip;
|
|
1089
|
+
rawReq.ips = ips;
|
|
1043
1090
|
let statusCode = 200;
|
|
1044
1091
|
const responseHeaders = new Headers();
|
|
1045
1092
|
let responseBody = null;
|