azurajs 3.0.6 → 3.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/decorators/index.d.mts +14 -1
- package/dist/decorators/index.d.ts +14 -1
- package/dist/decorators/index.js +18 -1
- package/dist/decorators/index.js.map +1 -1
- package/dist/decorators/index.mjs +18 -2
- package/dist/decorators/index.mjs.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +18 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +18 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/decorators/Route.ts +49 -1
- package/src/decorators/index.ts +1 -0
|
@@ -3,6 +3,11 @@ export { A as ApiOperation, a as ApiTags } from '../decorators-D5nY109r.mjs';
|
|
|
3
3
|
import 'node:http';
|
|
4
4
|
import '../routes.type-DZO5VBW2.mjs';
|
|
5
5
|
|
|
6
|
+
/** App com `register` (evita conflitos de overload com tipos duplicados entre subpaths). */
|
|
7
|
+
type AppRegisterable = {
|
|
8
|
+
register(...controllers: (new (...args: any[]) => any)[]): unknown;
|
|
9
|
+
listen(...args: any[]): unknown;
|
|
10
|
+
};
|
|
6
11
|
declare function Controller(prefix?: string): ClassDecorator;
|
|
7
12
|
declare const Get: (path?: string) => MethodDecorator;
|
|
8
13
|
declare const Post: (path?: string) => MethodDecorator;
|
|
@@ -22,7 +27,15 @@ declare const NextFunc: (name?: string) => ParameterDecorator;
|
|
|
22
27
|
declare const Ip: (name?: string) => ParameterDecorator;
|
|
23
28
|
declare const Session: (name?: string) => ParameterDecorator;
|
|
24
29
|
declare function UseMiddleware(...middlewares: MiddlewareHandler[]): MethodDecorator & ClassDecorator;
|
|
30
|
+
/** Compõe vários decorators (estilo NestJS). */
|
|
31
|
+
declare function composeDecorators(...decorators: (MethodDecorator | ClassDecorator)[]): MethodDecorator & ClassDecorator;
|
|
32
|
+
/**
|
|
33
|
+
* Regista controllers na app (paridade com AzuraJS v2).
|
|
34
|
+
* Aceita `applyDecorators(app, [A, B])` ou `applyDecorators(app, A, B)`.
|
|
35
|
+
*/
|
|
36
|
+
declare function applyDecorators(app: AppRegisterable, controllers: Array<new (...args: any[]) => any>): void;
|
|
37
|
+
declare function applyDecorators(app: AppRegisterable, ...controllers: (new (...args: any[]) => any)[]): void;
|
|
25
38
|
declare function applyDecorators(...decorators: (MethodDecorator | ClassDecorator)[]): MethodDecorator & ClassDecorator;
|
|
26
39
|
declare function Meta(key: string, value: any): MethodDecorator;
|
|
27
40
|
|
|
28
|
-
export { Body, Controller, Cookies, Delete, Get, Head, Headers, Ip, Meta, NextFunc, Options, Param, Patch, Post, Put, Query, Req, Res, Session, UseMiddleware, applyDecorators };
|
|
41
|
+
export { Body, Controller, Cookies, Delete, Get, Head, Headers, Ip, Meta, NextFunc, Options, Param, Patch, Post, Put, Query, Req, Res, Session, UseMiddleware, applyDecorators, composeDecorators };
|
|
@@ -3,6 +3,11 @@ export { A as ApiOperation, a as ApiTags } from '../decorators-B6l3CbxC.js';
|
|
|
3
3
|
import 'node:http';
|
|
4
4
|
import '../routes.type-DzHNkCag.js';
|
|
5
5
|
|
|
6
|
+
/** App com `register` (evita conflitos de overload com tipos duplicados entre subpaths). */
|
|
7
|
+
type AppRegisterable = {
|
|
8
|
+
register(...controllers: (new (...args: any[]) => any)[]): unknown;
|
|
9
|
+
listen(...args: any[]): unknown;
|
|
10
|
+
};
|
|
6
11
|
declare function Controller(prefix?: string): ClassDecorator;
|
|
7
12
|
declare const Get: (path?: string) => MethodDecorator;
|
|
8
13
|
declare const Post: (path?: string) => MethodDecorator;
|
|
@@ -22,7 +27,15 @@ declare const NextFunc: (name?: string) => ParameterDecorator;
|
|
|
22
27
|
declare const Ip: (name?: string) => ParameterDecorator;
|
|
23
28
|
declare const Session: (name?: string) => ParameterDecorator;
|
|
24
29
|
declare function UseMiddleware(...middlewares: MiddlewareHandler[]): MethodDecorator & ClassDecorator;
|
|
30
|
+
/** Compõe vários decorators (estilo NestJS). */
|
|
31
|
+
declare function composeDecorators(...decorators: (MethodDecorator | ClassDecorator)[]): MethodDecorator & ClassDecorator;
|
|
32
|
+
/**
|
|
33
|
+
* Regista controllers na app (paridade com AzuraJS v2).
|
|
34
|
+
* Aceita `applyDecorators(app, [A, B])` ou `applyDecorators(app, A, B)`.
|
|
35
|
+
*/
|
|
36
|
+
declare function applyDecorators(app: AppRegisterable, controllers: Array<new (...args: any[]) => any>): void;
|
|
37
|
+
declare function applyDecorators(app: AppRegisterable, ...controllers: (new (...args: any[]) => any)[]): void;
|
|
25
38
|
declare function applyDecorators(...decorators: (MethodDecorator | ClassDecorator)[]): MethodDecorator & ClassDecorator;
|
|
26
39
|
declare function Meta(key: string, value: any): MethodDecorator;
|
|
27
40
|
|
|
28
|
-
export { Body, Controller, Cookies, Delete, Get, Head, Headers, Ip, Meta, NextFunc, Options, Param, Patch, Post, Put, Query, Req, Res, Session, UseMiddleware, applyDecorators };
|
|
41
|
+
export { Body, Controller, Cookies, Delete, Get, Head, Headers, Ip, Meta, NextFunc, Options, Param, Patch, Post, Put, Query, Req, Res, Session, UseMiddleware, applyDecorators, composeDecorators };
|
package/dist/decorators/index.js
CHANGED
|
@@ -75,7 +75,10 @@ function UseMiddleware(...middlewares) {
|
|
|
75
75
|
}
|
|
76
76
|
};
|
|
77
77
|
}
|
|
78
|
-
function
|
|
78
|
+
function isAzuraServerLike(x) {
|
|
79
|
+
return typeof x === "object" && x !== null && typeof x.register === "function" && typeof x.listen === "function";
|
|
80
|
+
}
|
|
81
|
+
function composeDecorators(...decorators) {
|
|
79
82
|
return (target, propertyKey, descriptor) => {
|
|
80
83
|
for (const decorator of decorators) {
|
|
81
84
|
if (propertyKey !== void 0) {
|
|
@@ -86,6 +89,19 @@ function applyDecorators(...decorators) {
|
|
|
86
89
|
}
|
|
87
90
|
};
|
|
88
91
|
}
|
|
92
|
+
function applyDecorators(first, ...rest) {
|
|
93
|
+
if (isAzuraServerLike(first) && rest.length >= 1) {
|
|
94
|
+
const second = rest[0];
|
|
95
|
+
if (Array.isArray(second)) {
|
|
96
|
+
first.register(...second);
|
|
97
|
+
} else {
|
|
98
|
+
first.register(...rest);
|
|
99
|
+
}
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const decorators = [first, ...rest];
|
|
103
|
+
return composeDecorators(...decorators);
|
|
104
|
+
}
|
|
89
105
|
function Meta(key, value) {
|
|
90
106
|
return (target, propertyKey, _descriptor) => {
|
|
91
107
|
const routeMeta = Reflect.getMetadata(ROUTES_META_KEY, target, String(propertyKey));
|
|
@@ -143,5 +159,6 @@ exports.Res = Res;
|
|
|
143
159
|
exports.Session = Session;
|
|
144
160
|
exports.UseMiddleware = UseMiddleware;
|
|
145
161
|
exports.applyDecorators = applyDecorators;
|
|
162
|
+
exports.composeDecorators = composeDecorators;
|
|
146
163
|
//# sourceMappingURL=index.js.map
|
|
147
164
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/decorators/Route.ts","../../src/swagger/constants.ts","../../src/swagger/decorators.ts"],"names":[],"mappings":";;;AAGA,IAAM,mBAAA,GAAsB,kBAAA;AAC5B,IAAM,eAAA,GAAkB,cAAA;AACxB,IAAM,eAAA,GAAkB,cAAA;AACxB,IAAM,oBAAA,GAAuB,mBAAA;AAE7B,SAAS,aAAA,GAAsB;AAC7B,EAAA,IAAI,OAAO,OAAA,KAAY,WAAA,IAAe,CAAC,QAAQ,WAAA,EAAa;AAC1D,IAAA,MAAM,KAAA,uBAAY,GAAA,EAA2B;AAC7C,IAAC,QAAgB,cAAA,GAAiB,CAAC,GAAA,EAAa,KAAA,EAAY,QAAa,IAAA,KAAkB;AACzF,MAAA,MAAM,IAAI,IAAA,GAAO,CAAA,EAAG,GAAG,CAAA,EAAA,EAAK,IAAI,CAAA,CAAA,GAAK,GAAA;AACrC,MAAA,IAAI,CAAC,KAAA,CAAM,GAAA,CAAI,CAAC,CA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AACF;;;AC5GO,IAAM,YAAA,GAAe,gBAAA;AAGrB,IAAM,eAAA,GAAkB,2BAAA;AAGxB,IAAM,iBAAA,GAAoB,yBAAA;;;ACA1B,SAAS,WAAW,IAAA,EAAkD;AAC3E,EAAA,OAAO,SACL,MAAA,EACA,WAAA,EACA,WAAA,EACM;AACN,IAAA,IAAI,gBAAgB,MAAA,EAAW;AAC7B,MAAA,OAAA,CAAQ,cAAA,CAAe,YAAA,EAAc,IAAA,EAAM,MAAM,CAAA;AAAA,IACnD,CAAA,MAAO;AACL,MAAA,OAAA,CAAQ,eAAe,eAAA,EAAiB,IAAA,EAAM,MAAA,EAAQ,MAAA,CAAO,WAAW,CAAC,CAAA;AAAA,IAC3E;AAAA,EACF,CAAA;AACF;AAKO,SAAS,aAAa,IAAA,EAA2C;AACtE,EAAA,OAAO,SACL,MAAA,EACA,WAAA,EACA,WAAA,EACM;AACN,IAAA,MAAM,GAAA,GAAM,OAAO,WAAW,CAAA;AAC9B,IAAA,MAAM,MAAO,OAAA,CAAQ,WAAA,GAAc,mBAAmB,MAAA,EAAQ,GAAG,KAAK,EAAC;AACvE,IAAA,OAAA,CAAQ,cAAA,CAAe,mBAAmB,EAAE,GAAG,KAAK,GAAG,IAAA,EAAK,EAAG,MAAA,EAAQ,GAAG,CAAA;AAAA,EAC5E,CAAA;AACF","file":"index.js","sourcesContent":["import type { HttpMethod, MiddlewareHandler } from \"../types/common.type.js\";\r\nimport type { ParamMetadata, RouteMeta } from \"../types/routes.type.js\";\r\n\r\nconst CONTROLLER_META_KEY = \"azura:controller\";\r\nconst ROUTES_META_KEY = \"azura:routes\";\r\nconst PARAMS_META_KEY = \"azura:params\";\r\nconst MIDDLEWARES_META_KEY = \"azura:middlewares\";\r\n\r\nfunction ensureReflect(): void {\r\n if (typeof Reflect === \"undefined\" || !Reflect.getMetadata) {\r\n const store = new Map<string, Map<any, any>>();\r\n (Reflect as any).defineMetadata = (key: string, value: any, target: any, prop?: string) => {\r\n const k = prop ? `${key}::${prop}` : key;\r\n if (!store.has(k)) store.set(k, new Map());\r\n store.get(k)!.set(target, value);\r\n };\r\n (Reflect as any).getMetadata = (key: string, target: any, prop?: string) => {\r\n const k = prop ? `${key}::${prop}` : key;\r\n return store.get(k)?.get(target);\r\n };\r\n }\r\n}\r\n\r\nensureReflect();\r\n\r\nexport function Controller(prefix: string = \"\"): ClassDecorator {\r\n return (target) => {\r\n Reflect.defineMetadata(CONTROLLER_META_KEY, prefix, target);\r\n };\r\n}\r\n\r\nfunction createMethodDecorator(method: HttpMethod) {\r\n return (path: string = \"\"): MethodDecorator => {\r\n return (target, propertyKey, _descriptor) => {\r\n Reflect.defineMetadata(\r\n ROUTES_META_KEY,\r\n { method, path, propertyKey: String(propertyKey), middlewares: [], params: [], meta: undefined },\r\n target,\r\n String(propertyKey),\r\n );\r\n };\r\n };\r\n}\r\n\r\nexport const Get = createMethodDecorator(\"GET\");\r\nexport const Post = createMethodDecorator(\"POST\");\r\nexport const Put = createMethodDecorator(\"PUT\");\r\nexport const Delete = createMethodDecorator(\"DELETE\");\r\nexport const Patch = createMethodDecorator(\"PATCH\");\r\nexport const Head = createMethodDecorator(\"HEAD\");\r\nexport const Options = createMethodDecorator(\"OPTIONS\");\r\n\r\nfunction createParamDecorator(type: ParamMetadata[\"type\"]) {\r\n return (name?: string): ParameterDecorator => {\r\n return (target, propertyKey, parameterIndex) => {\r\n const key = String(propertyKey);\r\n const existing: ParamMetadata[] = Reflect.getMetadata(PARAMS_META_KEY, target, key) ?? [];\r\n existing.push({ index: parameterIndex, type, name });\r\n Reflect.defineMetadata(PARAMS_META_KEY, existing, target, key);\r\n };\r\n };\r\n}\r\n\r\nexport const Body = createParamDecorator(\"body\");\r\nexport const Query = createParamDecorator(\"query\");\r\nexport const Param = createParamDecorator(\"param\");\r\nexport const Headers = createParamDecorator(\"header\");\r\nexport const Cookies = createParamDecorator(\"cookie\");\r\nexport const Req = createParamDecorator(\"req\");\r\nexport const Res = createParamDecorator(\"res\");\r\nexport const NextFunc = createParamDecorator(\"next\");\r\nexport const Ip = createParamDecorator(\"ip\");\r\nexport const Session = createParamDecorator(\"session\");\r\n\r\nexport function UseMiddleware(...middlewares: MiddlewareHandler[]): MethodDecorator & ClassDecorator {\r\n return (target: any, propertyKey?: string | symbol, _descriptor?: PropertyDescriptor) => {\r\n if (propertyKey) {\r\n const existing: MiddlewareHandler[] =\r\n Reflect.getMetadata(MIDDLEWARES_META_KEY, target, String(propertyKey)) ?? [];\r\n Reflect.defineMetadata(MIDDLEWARES_META_KEY, [...existing, ...middlewares], target, String(propertyKey));\r\n } else {\r\n const existing: MiddlewareHandler[] =\r\n Reflect.getMetadata(MIDDLEWARES_META_KEY, target) ?? [];\r\n Reflect.defineMetadata(MIDDLEWARES_META_KEY, [...existing, ...middlewares], target);\r\n }\r\n };\r\n}\r\n\r\nexport function applyDecorators(...decorators: (MethodDecorator | ClassDecorator)[]): MethodDecorator & ClassDecorator {\r\n return (target: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor) => {\r\n for (const decorator of decorators) {\r\n if (propertyKey !== undefined) {\r\n (decorator as MethodDecorator)(target, propertyKey, descriptor!);\r\n } else {\r\n (decorator as ClassDecorator)(target);\r\n }\r\n }\r\n };\r\n}\r\n\r\nexport function Meta(key: string, value: any): MethodDecorator {\r\n return (target, propertyKey, _descriptor) => {\r\n const routeMeta = Reflect.getMetadata(ROUTES_META_KEY, target, String(propertyKey));\r\n if (routeMeta) {\r\n if (!routeMeta.meta) routeMeta.meta = {};\r\n routeMeta.meta[key] = value;\r\n Reflect.defineMetadata(ROUTES_META_KEY, routeMeta, target, String(propertyKey));\r\n }\r\n };\r\n}\r\n","/** Tags OpenAPI a nível de controller (todas as rotas do class) */\r\nexport const API_TAGS_KEY = \"azura:api-tags\";\r\n\r\n/** Tags por método (independente da ordem em relação a @Get/@Post) */\r\nexport const METHOD_TAGS_KEY = \"azura:swagger-method-tags\";\r\n\r\n/** Metadados OpenAPI por método (summary, responses, etc.) */\r\nexport const API_OPERATION_KEY = \"azura:swagger-operation\";\r\n","import type { RouteMeta } from \"../types/routes.type.js\";\r\nimport { API_OPERATION_KEY, API_TAGS_KEY, METHOD_TAGS_KEY } from \"./constants.js\";\r\n\r\n/**\r\n * Tags OpenAPI no controller (todas as rotas) ou num método específico.\r\n * Compatível com `experimentalDecorators` (assinatura legacy de 3 argumentos em métodos).\r\n */\r\nexport function ApiTags(...tags: string[]): ClassDecorator & MethodDecorator {\r\n return function (\r\n target: object,\r\n propertyKey?: string | symbol,\r\n _descriptor?: PropertyDescriptor,\r\n ): void {\r\n if (propertyKey === undefined) {\r\n Reflect.defineMetadata(API_TAGS_KEY, tags, target);\r\n } else {\r\n Reflect.defineMetadata(METHOD_TAGS_KEY, tags, target, String(propertyKey));\r\n }\r\n } as ClassDecorator & MethodDecorator;\r\n}\r\n\r\n/**\r\n * Metadados OpenAPI (summary, description, responses, parameters, etc.).\r\n */\r\nexport function ApiOperation(meta: Partial<RouteMeta>): MethodDecorator {\r\n return function (\r\n target: object,\r\n propertyKey: string | symbol,\r\n _descriptor: PropertyDescriptor,\r\n ): void {\r\n const key = String(propertyKey);\r\n const cur = (Reflect.getMetadata?.(API_OPERATION_KEY, target, key) ?? {}) as Partial<RouteMeta>;\r\n Reflect.defineMetadata(API_OPERATION_KEY, { ...cur, ...meta }, target, key);\r\n };\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/decorators/Route.ts","../../src/swagger/constants.ts","../../src/swagger/decorators.ts"],"names":[],"mappings":";;;AASA,IAAM,mBAAA,GAAsB,kBAAA;AAC5B,IAAM,eAAA,GAAkB,cAAA;AACxB,IAAM,eAAA,GAAkB,cAAA;AACxB,IAAM,oBAAA,GAAuB,mBAAA;AAE7B,SAAS,aAAA,GAAsB;AAC7B,EAAA,IAAI,OAAO,OAAA,KAAY,WAAA,IAAe,CAAC,QAAQ,WAAA,EAAa;AAC1D,IAAA,MAAM,KAAA,uBAAY,GAAA,EAA2B;AAC7C,IAAC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Ac,IAAA,EAAM,MAAM,CAAA;AAAA,IACnD,CAAA,MAAO;AACL,MAAA,OAAA,CAAQ,eAAe,eAAA,EAAiB,IAAA,EAAM,MAAA,EAAQ,MAAA,CAAO,WAAW,CAAC,CAAA;AAAA,IAC3E;AAAA,EACF,CAAA;AACF;AAKO,SAAS,aAAa,IAAA,EAA2C;AACtE,EAAA,OAAO,SACL,MAAA,EACA,WAAA,EACA,WAAA,EACM;AACN,IAAA,MAAM,GAAA,GAAM,OAAO,WAAW,CAAA;AAC9B,IAAA,MAAM,MAAO,OAAA,CAAQ,WAAA,GAAc,mBAAmB,MAAA,EAAQ,GAAG,KAAK,EAAC;AACvE,IAAA,OAAA,CAAQ,cAAA,CAAe,mBAAmB,EAAE,GAAG,KAAK,GAAG,IAAA,EAAK,EAAG,MAAA,EAAQ,GAAG,CAAA;AAAA,EAC5E,CAAA;AACF","file":"index.js","sourcesContent":["import type { HttpMethod, MiddlewareHandler } from \"../types/common.type.js\";\r\nimport type { ParamMetadata, RouteMeta } from \"../types/routes.type.js\";\r\n\r\n/** App com `register` (evita conflitos de overload com tipos duplicados entre subpaths). */\r\ntype AppRegisterable = {\r\n register(...controllers: (new (...args: any[]) => any)[]): unknown;\r\n listen(...args: any[]): unknown;\r\n};\r\n\r\nconst CONTROLLER_META_KEY = \"azura:controller\";\r\nconst ROUTES_META_KEY = \"azura:routes\";\r\nconst PARAMS_META_KEY = \"azura:params\";\r\nconst MIDDLEWARES_META_KEY = \"azura:middlewares\";\r\n\r\nfunction ensureReflect(): void {\r\n if (typeof Reflect === \"undefined\" || !Reflect.getMetadata) {\r\n const store = new Map<string, Map<any, any>>();\r\n (Reflect as any).defineMetadata = (key: string, value: any, target: any, prop?: string) => {\r\n const k = prop ? `${key}::${prop}` : key;\r\n if (!store.has(k)) store.set(k, new Map());\r\n store.get(k)!.set(target, value);\r\n };\r\n (Reflect as any).getMetadata = (key: string, target: any, prop?: string) => {\r\n const k = prop ? `${key}::${prop}` : key;\r\n return store.get(k)?.get(target);\r\n };\r\n }\r\n}\r\n\r\nensureReflect();\r\n\r\nexport function Controller(prefix: string = \"\"): ClassDecorator {\r\n return (target) => {\r\n Reflect.defineMetadata(CONTROLLER_META_KEY, prefix, target);\r\n };\r\n}\r\n\r\nfunction createMethodDecorator(method: HttpMethod) {\r\n return (path: string = \"\"): MethodDecorator => {\r\n return (target, propertyKey, _descriptor) => {\r\n Reflect.defineMetadata(\r\n ROUTES_META_KEY,\r\n { method, path, propertyKey: String(propertyKey), middlewares: [], params: [], meta: undefined },\r\n target,\r\n String(propertyKey),\r\n );\r\n };\r\n };\r\n}\r\n\r\nexport const Get = createMethodDecorator(\"GET\");\r\nexport const Post = createMethodDecorator(\"POST\");\r\nexport const Put = createMethodDecorator(\"PUT\");\r\nexport const Delete = createMethodDecorator(\"DELETE\");\r\nexport const Patch = createMethodDecorator(\"PATCH\");\r\nexport const Head = createMethodDecorator(\"HEAD\");\r\nexport const Options = createMethodDecorator(\"OPTIONS\");\r\n\r\nfunction createParamDecorator(type: ParamMetadata[\"type\"]) {\r\n return (name?: string): ParameterDecorator => {\r\n return (target, propertyKey, parameterIndex) => {\r\n const key = String(propertyKey);\r\n const existing: ParamMetadata[] = Reflect.getMetadata(PARAMS_META_KEY, target, key) ?? [];\r\n existing.push({ index: parameterIndex, type, name });\r\n Reflect.defineMetadata(PARAMS_META_KEY, existing, target, key);\r\n };\r\n };\r\n}\r\n\r\nexport const Body = createParamDecorator(\"body\");\r\nexport const Query = createParamDecorator(\"query\");\r\nexport const Param = createParamDecorator(\"param\");\r\nexport const Headers = createParamDecorator(\"header\");\r\nexport const Cookies = createParamDecorator(\"cookie\");\r\nexport const Req = createParamDecorator(\"req\");\r\nexport const Res = createParamDecorator(\"res\");\r\nexport const NextFunc = createParamDecorator(\"next\");\r\nexport const Ip = createParamDecorator(\"ip\");\r\nexport const Session = createParamDecorator(\"session\");\r\n\r\nexport function UseMiddleware(...middlewares: MiddlewareHandler[]): MethodDecorator & ClassDecorator {\r\n return (target: any, propertyKey?: string | symbol, _descriptor?: PropertyDescriptor) => {\r\n if (propertyKey) {\r\n const existing: MiddlewareHandler[] =\r\n Reflect.getMetadata(MIDDLEWARES_META_KEY, target, String(propertyKey)) ?? [];\r\n Reflect.defineMetadata(MIDDLEWARES_META_KEY, [...existing, ...middlewares], target, String(propertyKey));\r\n } else {\r\n const existing: MiddlewareHandler[] =\r\n Reflect.getMetadata(MIDDLEWARES_META_KEY, target) ?? [];\r\n Reflect.defineMetadata(MIDDLEWARES_META_KEY, [...existing, ...middlewares], target);\r\n }\r\n };\r\n}\r\n\r\nfunction isAzuraServerLike(x: unknown): x is AppRegisterable {\r\n return (\r\n typeof x === \"object\" &&\r\n x !== null &&\r\n typeof (x as AppRegisterable).register === \"function\" &&\r\n typeof (x as AppRegisterable).listen === \"function\"\r\n );\r\n}\r\n\r\n/** Compõe vários decorators (estilo NestJS). */\r\nexport function composeDecorators(...decorators: (MethodDecorator | ClassDecorator)[]): MethodDecorator & ClassDecorator {\r\n return (target: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor) => {\r\n for (const decorator of decorators) {\r\n if (propertyKey !== undefined) {\r\n (decorator as MethodDecorator)(target, propertyKey, descriptor!);\r\n } else {\r\n (decorator as ClassDecorator)(target);\r\n }\r\n }\r\n };\r\n}\r\n\r\n/**\r\n * Regista controllers na app (paridade com AzuraJS v2).\r\n * Aceita `applyDecorators(app, [A, B])` ou `applyDecorators(app, A, B)`.\r\n */\r\nexport function applyDecorators(\r\n app: AppRegisterable,\r\n controllers: Array<new (...args: any[]) => any>,\r\n): void;\r\nexport function applyDecorators(\r\n app: AppRegisterable,\r\n ...controllers: (new (...args: any[]) => any)[]\r\n): void;\r\nexport function applyDecorators(\r\n ...decorators: (MethodDecorator | ClassDecorator)[]\r\n): MethodDecorator & ClassDecorator;\r\nexport function applyDecorators(\r\n first: AppRegisterable | MethodDecorator | ClassDecorator,\r\n ...rest: unknown[]\r\n): void | (MethodDecorator & ClassDecorator) {\r\n if (isAzuraServerLike(first) && rest.length >= 1) {\r\n const second = rest[0];\r\n if (Array.isArray(second)) {\r\n first.register(...(second as (new (...args: any[]) => any)[]));\r\n } else {\r\n first.register(...(rest as (new (...args: any[]) => any)[]));\r\n }\r\n return;\r\n }\r\n const decorators = [first, ...rest] as (MethodDecorator | ClassDecorator)[];\r\n return composeDecorators(...decorators);\r\n}\r\n\r\nexport function Meta(key: string, value: any): MethodDecorator {\r\n return (target, propertyKey, _descriptor) => {\r\n const routeMeta = Reflect.getMetadata(ROUTES_META_KEY, target, String(propertyKey));\r\n if (routeMeta) {\r\n if (!routeMeta.meta) routeMeta.meta = {};\r\n routeMeta.meta[key] = value;\r\n Reflect.defineMetadata(ROUTES_META_KEY, routeMeta, target, String(propertyKey));\r\n }\r\n };\r\n}\r\n","/** Tags OpenAPI a nível de controller (todas as rotas do class) */\r\nexport const API_TAGS_KEY = \"azura:api-tags\";\r\n\r\n/** Tags por método (independente da ordem em relação a @Get/@Post) */\r\nexport const METHOD_TAGS_KEY = \"azura:swagger-method-tags\";\r\n\r\n/** Metadados OpenAPI por método (summary, responses, etc.) */\r\nexport const API_OPERATION_KEY = \"azura:swagger-operation\";\r\n","import type { RouteMeta } from \"../types/routes.type.js\";\r\nimport { API_OPERATION_KEY, API_TAGS_KEY, METHOD_TAGS_KEY } from \"./constants.js\";\r\n\r\n/**\r\n * Tags OpenAPI no controller (todas as rotas) ou num método específico.\r\n * Compatível com `experimentalDecorators` (assinatura legacy de 3 argumentos em métodos).\r\n */\r\nexport function ApiTags(...tags: string[]): ClassDecorator & MethodDecorator {\r\n return function (\r\n target: object,\r\n propertyKey?: string | symbol,\r\n _descriptor?: PropertyDescriptor,\r\n ): void {\r\n if (propertyKey === undefined) {\r\n Reflect.defineMetadata(API_TAGS_KEY, tags, target);\r\n } else {\r\n Reflect.defineMetadata(METHOD_TAGS_KEY, tags, target, String(propertyKey));\r\n }\r\n } as ClassDecorator & MethodDecorator;\r\n}\r\n\r\n/**\r\n * Metadados OpenAPI (summary, description, responses, parameters, etc.).\r\n */\r\nexport function ApiOperation(meta: Partial<RouteMeta>): MethodDecorator {\r\n return function (\r\n target: object,\r\n propertyKey: string | symbol,\r\n _descriptor: PropertyDescriptor,\r\n ): void {\r\n const key = String(propertyKey);\r\n const cur = (Reflect.getMetadata?.(API_OPERATION_KEY, target, key) ?? {}) as Partial<RouteMeta>;\r\n Reflect.defineMetadata(API_OPERATION_KEY, { ...cur, ...meta }, target, key);\r\n };\r\n}\r\n"]}
|
|
@@ -73,7 +73,10 @@ function UseMiddleware(...middlewares) {
|
|
|
73
73
|
}
|
|
74
74
|
};
|
|
75
75
|
}
|
|
76
|
-
function
|
|
76
|
+
function isAzuraServerLike(x) {
|
|
77
|
+
return typeof x === "object" && x !== null && typeof x.register === "function" && typeof x.listen === "function";
|
|
78
|
+
}
|
|
79
|
+
function composeDecorators(...decorators) {
|
|
77
80
|
return (target, propertyKey, descriptor) => {
|
|
78
81
|
for (const decorator of decorators) {
|
|
79
82
|
if (propertyKey !== void 0) {
|
|
@@ -84,6 +87,19 @@ function applyDecorators(...decorators) {
|
|
|
84
87
|
}
|
|
85
88
|
};
|
|
86
89
|
}
|
|
90
|
+
function applyDecorators(first, ...rest) {
|
|
91
|
+
if (isAzuraServerLike(first) && rest.length >= 1) {
|
|
92
|
+
const second = rest[0];
|
|
93
|
+
if (Array.isArray(second)) {
|
|
94
|
+
first.register(...second);
|
|
95
|
+
} else {
|
|
96
|
+
first.register(...rest);
|
|
97
|
+
}
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
const decorators = [first, ...rest];
|
|
101
|
+
return composeDecorators(...decorators);
|
|
102
|
+
}
|
|
87
103
|
function Meta(key, value) {
|
|
88
104
|
return (target, propertyKey, _descriptor) => {
|
|
89
105
|
const routeMeta = Reflect.getMetadata(ROUTES_META_KEY, target, String(propertyKey));
|
|
@@ -118,6 +134,6 @@ function ApiOperation(meta) {
|
|
|
118
134
|
};
|
|
119
135
|
}
|
|
120
136
|
|
|
121
|
-
export { ApiOperation, ApiTags, Body, Controller, Cookies, Delete, Get, Head, Headers, Ip, Meta, NextFunc, Options, Param, Patch, Post, Put, Query, Req, Res, Session, UseMiddleware, applyDecorators };
|
|
137
|
+
export { ApiOperation, ApiTags, Body, Controller, Cookies, Delete, Get, Head, Headers, Ip, Meta, NextFunc, Options, Param, Patch, Post, Put, Query, Req, Res, Session, UseMiddleware, applyDecorators, composeDecorators };
|
|
122
138
|
//# sourceMappingURL=index.mjs.map
|
|
123
139
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/decorators/Route.ts","../../src/swagger/constants.ts","../../src/swagger/decorators.ts"],"names":[],"mappings":";AAGA,IAAM,mBAAA,GAAsB,kBAAA;AAC5B,IAAM,eAAA,GAAkB,cAAA;AACxB,IAAM,eAAA,GAAkB,cAAA;AACxB,IAAM,oBAAA,GAAuB,mBAAA;AAE7B,SAAS,aAAA,GAAsB;AAC7B,EAAA,IAAI,OAAO,OAAA,KAAY,WAAA,IAAe,CAAC,QAAQ,WAAA,EAAa;AAC1D,IAAA,MAAM,KAAA,uBAAY,GAAA,EAA2B;AAC7C,IAAC,QAAgB,cAAA,GAAiB,CAAC,GAAA,EAAa,KAAA,EAAY,QAAa,IAAA,KAAkB;AACzF,MAAA,MAAM,IAAI,IAAA,GAAO,CAAA,EAAG,GAAG,CAAA,EAAA,EAAK,IAAI,CAAA,CAAA,GAAK,GAAA;AACrC,MAAA,IAAI,CAAC,KAAA,CAAM,GAAA,CAAI,CAAC,CAAA,QAAS,GAAA,CAAI,CAAA,kBAAG,IAAI,GAAA,EAAK,CAAA;AACzC,MAAA,KAAA,CAAM,GAAA,CAAI,CAAC,CAAA,CAAG,GAAA,CAAI,QAAQ,KAAK,CAAA;AAAA,IACjC,CAAA;AACA,IAAC,OAAA,CAAgB,WAAA,GAAc,CAAC,GAAA,EAAa,QAAa,IAAA,KAAkB;AAC1E,MAAA,M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OAAA,CAAQ,cAAA,CAAe,YAAA,EAAc,IAAA,EAAM,MAAM,CAAA;AAAA,IACnD,CAAA,MAAO;AACL,MAAA,OAAA,CAAQ,eAAe,eAAA,EAAiB,IAAA,EAAM,MAAA,EAAQ,MAAA,CAAO,WAAW,CAAC,CAAA;AAAA,IAC3E;AAAA,EACF,CAAA;AACF;AAKO,SAAS,aAAa,IAAA,EAA2C;AACtE,EAAA,OAAO,SACL,MAAA,EACA,WAAA,EACA,WAAA,EACM;AACN,IAAA,MAAM,GAAA,GAAM,OAAO,WAAW,CAAA;AAC9B,IAAA,MAAM,MAAO,OAAA,CAAQ,WAAA,GAAc,mBAAmB,MAAA,EAAQ,GAAG,KAAK,EAAC;AACvE,IAAA,OAAA,CAAQ,cAAA,CAAe,mBAAmB,EAAE,GAAG,KAAK,GAAG,IAAA,EAAK,EAAG,MAAA,EAAQ,GAAG,CAAA;AAAA,EAC5E,CAAA;AACF","file":"index.mjs","sourcesContent":["import type { HttpMethod, MiddlewareHandler } from \"../types/common.type.js\";\r\nimport type { ParamMetadata, RouteMeta } from \"../types/routes.type.js\";\r\n\r\nconst CONTROLLER_META_KEY = \"azura:controller\";\r\nconst ROUTES_META_KEY = \"azura:routes\";\r\nconst PARAMS_META_KEY = \"azura:params\";\r\nconst MIDDLEWARES_META_KEY = \"azura:middlewares\";\r\n\r\nfunction ensureReflect(): void {\r\n if (typeof Reflect === \"undefined\" || !Reflect.getMetadata) {\r\n const store = new Map<string, Map<any, any>>();\r\n (Reflect as any).defineMetadata = (key: string, value: any, target: any, prop?: string) => {\r\n const k = prop ? `${key}::${prop}` : key;\r\n if (!store.has(k)) store.set(k, new Map());\r\n store.get(k)!.set(target, value);\r\n };\r\n (Reflect as any).getMetadata = (key: string, target: any, prop?: string) => {\r\n const k = prop ? `${key}::${prop}` : key;\r\n return store.get(k)?.get(target);\r\n };\r\n }\r\n}\r\n\r\nensureReflect();\r\n\r\nexport function Controller(prefix: string = \"\"): ClassDecorator {\r\n return (target) => {\r\n Reflect.defineMetadata(CONTROLLER_META_KEY, prefix, target);\r\n };\r\n}\r\n\r\nfunction createMethodDecorator(method: HttpMethod) {\r\n return (path: string = \"\"): MethodDecorator => {\r\n return (target, propertyKey, _descriptor) => {\r\n Reflect.defineMetadata(\r\n ROUTES_META_KEY,\r\n { method, path, propertyKey: String(propertyKey), middlewares: [], params: [], meta: undefined },\r\n target,\r\n String(propertyKey),\r\n );\r\n };\r\n };\r\n}\r\n\r\nexport const Get = createMethodDecorator(\"GET\");\r\nexport const Post = createMethodDecorator(\"POST\");\r\nexport const Put = createMethodDecorator(\"PUT\");\r\nexport const Delete = createMethodDecorator(\"DELETE\");\r\nexport const Patch = createMethodDecorator(\"PATCH\");\r\nexport const Head = createMethodDecorator(\"HEAD\");\r\nexport const Options = createMethodDecorator(\"OPTIONS\");\r\n\r\nfunction createParamDecorator(type: ParamMetadata[\"type\"]) {\r\n return (name?: string): ParameterDecorator => {\r\n return (target, propertyKey, parameterIndex) => {\r\n const key = String(propertyKey);\r\n const existing: ParamMetadata[] = Reflect.getMetadata(PARAMS_META_KEY, target, key) ?? [];\r\n existing.push({ index: parameterIndex, type, name });\r\n Reflect.defineMetadata(PARAMS_META_KEY, existing, target, key);\r\n };\r\n };\r\n}\r\n\r\nexport const Body = createParamDecorator(\"body\");\r\nexport const Query = createParamDecorator(\"query\");\r\nexport const Param = createParamDecorator(\"param\");\r\nexport const Headers = createParamDecorator(\"header\");\r\nexport const Cookies = createParamDecorator(\"cookie\");\r\nexport const Req = createParamDecorator(\"req\");\r\nexport const Res = createParamDecorator(\"res\");\r\nexport const NextFunc = createParamDecorator(\"next\");\r\nexport const Ip = createParamDecorator(\"ip\");\r\nexport const Session = createParamDecorator(\"session\");\r\n\r\nexport function UseMiddleware(...middlewares: MiddlewareHandler[]): MethodDecorator & ClassDecorator {\r\n return (target: any, propertyKey?: string | symbol, _descriptor?: PropertyDescriptor) => {\r\n if (propertyKey) {\r\n const existing: MiddlewareHandler[] =\r\n Reflect.getMetadata(MIDDLEWARES_META_KEY, target, String(propertyKey)) ?? [];\r\n Reflect.defineMetadata(MIDDLEWARES_META_KEY, [...existing, ...middlewares], target, String(propertyKey));\r\n } else {\r\n const existing: MiddlewareHandler[] =\r\n Reflect.getMetadata(MIDDLEWARES_META_KEY, target) ?? [];\r\n Reflect.defineMetadata(MIDDLEWARES_META_KEY, [...existing, ...middlewares], target);\r\n }\r\n };\r\n}\r\n\r\nexport function applyDecorators(...decorators: (MethodDecorator | ClassDecorator)[]): MethodDecorator & ClassDecorator {\r\n return (target: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor) => {\r\n for (const decorator of decorators) {\r\n if (propertyKey !== undefined) {\r\n (decorator as MethodDecorator)(target, propertyKey, descriptor!);\r\n } else {\r\n (decorator as ClassDecorator)(target);\r\n }\r\n }\r\n };\r\n}\r\n\r\nexport function Meta(key: string, value: any): MethodDecorator {\r\n return (target, propertyKey, _descriptor) => {\r\n const routeMeta = Reflect.getMetadata(ROUTES_META_KEY, target, String(propertyKey));\r\n if (routeMeta) {\r\n if (!routeMeta.meta) routeMeta.meta = {};\r\n routeMeta.meta[key] = value;\r\n Reflect.defineMetadata(ROUTES_META_KEY, routeMeta, target, String(propertyKey));\r\n }\r\n };\r\n}\r\n","/** Tags OpenAPI a nível de controller (todas as rotas do class) */\r\nexport const API_TAGS_KEY = \"azura:api-tags\";\r\n\r\n/** Tags por método (independente da ordem em relação a @Get/@Post) */\r\nexport const METHOD_TAGS_KEY = \"azura:swagger-method-tags\";\r\n\r\n/** Metadados OpenAPI por método (summary, responses, etc.) */\r\nexport const API_OPERATION_KEY = \"azura:swagger-operation\";\r\n","import type { RouteMeta } from \"../types/routes.type.js\";\r\nimport { API_OPERATION_KEY, API_TAGS_KEY, METHOD_TAGS_KEY } from \"./constants.js\";\r\n\r\n/**\r\n * Tags OpenAPI no controller (todas as rotas) ou num método específico.\r\n * Compatível com `experimentalDecorators` (assinatura legacy de 3 argumentos em métodos).\r\n */\r\nexport function ApiTags(...tags: string[]): ClassDecorator & MethodDecorator {\r\n return function (\r\n target: object,\r\n propertyKey?: string | symbol,\r\n _descriptor?: PropertyDescriptor,\r\n ): void {\r\n if (propertyKey === undefined) {\r\n Reflect.defineMetadata(API_TAGS_KEY, tags, target);\r\n } else {\r\n Reflect.defineMetadata(METHOD_TAGS_KEY, tags, target, String(propertyKey));\r\n }\r\n } as ClassDecorator & MethodDecorator;\r\n}\r\n\r\n/**\r\n * Metadados OpenAPI (summary, description, responses, parameters, etc.).\r\n */\r\nexport function ApiOperation(meta: Partial<RouteMeta>): MethodDecorator {\r\n return function (\r\n target: object,\r\n propertyKey: string | symbol,\r\n _descriptor: PropertyDescriptor,\r\n ): void {\r\n const key = String(propertyKey);\r\n const cur = (Reflect.getMetadata?.(API_OPERATION_KEY, target, key) ?? {}) as Partial<RouteMeta>;\r\n Reflect.defineMetadata(API_OPERATION_KEY, { ...cur, ...meta }, target, key);\r\n };\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/decorators/Route.ts","../../src/swagger/constants.ts","../../src/swagger/decorators.ts"],"names":[],"mappings":";AASA,IAAM,mBAAA,GAAsB,kBAAA;AAC5B,IAAM,eAAA,GAAkB,cAAA;AACxB,IAAM,eAAA,GAAkB,cAAA;AACxB,IAAM,oBAAA,GAAuB,mBAAA;AAE7B,SAAS,aAAA,GAAsB;AAC7B,EAAA,IAAI,OAAO,OAAA,KAAY,WAAA,IAAe,CAAC,QAAQ,WAAA,EAAa;AAC1D,IAAA,MAAM,KAAA,uBAAY,GAAA,EAA2B;AAC7C,IAAC,QAAgB,cAAA,GAAiB,CAAC,GAAA,EAAa,KAAA,EAAY,QAAa,IAAA,KAAkB;AACzF,MAAA,MAAM,IAAI,IAAA,GAAO,CAAA,EAAG,GAAG,CAAA,EAAA,EAAK,IAAI,CAAA,CAAA,GAAK,GAAA;AACrC,MAAA,IAAI,CAAC,KAAA,CAAM,GAAA,CAAI,CAAC,CAAA,QAAS,GAAA,CAAI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WAAA,EACA,WAAA,EACM;AACN,IAAA,MAAM,GAAA,GAAM,OAAO,WAAW,CAAA;AAC9B,IAAA,MAAM,MAAO,OAAA,CAAQ,WAAA,GAAc,mBAAmB,MAAA,EAAQ,GAAG,KAAK,EAAC;AACvE,IAAA,OAAA,CAAQ,cAAA,CAAe,mBAAmB,EAAE,GAAG,KAAK,GAAG,IAAA,EAAK,EAAG,MAAA,EAAQ,GAAG,CAAA;AAAA,EAC5E,CAAA;AACF","file":"index.mjs","sourcesContent":["import type { HttpMethod, MiddlewareHandler } from \"../types/common.type.js\";\r\nimport type { ParamMetadata, RouteMeta } from \"../types/routes.type.js\";\r\n\r\n/** App com `register` (evita conflitos de overload com tipos duplicados entre subpaths). */\r\ntype AppRegisterable = {\r\n register(...controllers: (new (...args: any[]) => any)[]): unknown;\r\n listen(...args: any[]): unknown;\r\n};\r\n\r\nconst CONTROLLER_META_KEY = \"azura:controller\";\r\nconst ROUTES_META_KEY = \"azura:routes\";\r\nconst PARAMS_META_KEY = \"azura:params\";\r\nconst MIDDLEWARES_META_KEY = \"azura:middlewares\";\r\n\r\nfunction ensureReflect(): void {\r\n if (typeof Reflect === \"undefined\" || !Reflect.getMetadata) {\r\n const store = new Map<string, Map<any, any>>();\r\n (Reflect as any).defineMetadata = (key: string, value: any, target: any, prop?: string) => {\r\n const k = prop ? `${key}::${prop}` : key;\r\n if (!store.has(k)) store.set(k, new Map());\r\n store.get(k)!.set(target, value);\r\n };\r\n (Reflect as any).getMetadata = (key: string, target: any, prop?: string) => {\r\n const k = prop ? `${key}::${prop}` : key;\r\n return store.get(k)?.get(target);\r\n };\r\n }\r\n}\r\n\r\nensureReflect();\r\n\r\nexport function Controller(prefix: string = \"\"): ClassDecorator {\r\n return (target) => {\r\n Reflect.defineMetadata(CONTROLLER_META_KEY, prefix, target);\r\n };\r\n}\r\n\r\nfunction createMethodDecorator(method: HttpMethod) {\r\n return (path: string = \"\"): MethodDecorator => {\r\n return (target, propertyKey, _descriptor) => {\r\n Reflect.defineMetadata(\r\n ROUTES_META_KEY,\r\n { method, path, propertyKey: String(propertyKey), middlewares: [], params: [], meta: undefined },\r\n target,\r\n String(propertyKey),\r\n );\r\n };\r\n };\r\n}\r\n\r\nexport const Get = createMethodDecorator(\"GET\");\r\nexport const Post = createMethodDecorator(\"POST\");\r\nexport const Put = createMethodDecorator(\"PUT\");\r\nexport const Delete = createMethodDecorator(\"DELETE\");\r\nexport const Patch = createMethodDecorator(\"PATCH\");\r\nexport const Head = createMethodDecorator(\"HEAD\");\r\nexport const Options = createMethodDecorator(\"OPTIONS\");\r\n\r\nfunction createParamDecorator(type: ParamMetadata[\"type\"]) {\r\n return (name?: string): ParameterDecorator => {\r\n return (target, propertyKey, parameterIndex) => {\r\n const key = String(propertyKey);\r\n const existing: ParamMetadata[] = Reflect.getMetadata(PARAMS_META_KEY, target, key) ?? [];\r\n existing.push({ index: parameterIndex, type, name });\r\n Reflect.defineMetadata(PARAMS_META_KEY, existing, target, key);\r\n };\r\n };\r\n}\r\n\r\nexport const Body = createParamDecorator(\"body\");\r\nexport const Query = createParamDecorator(\"query\");\r\nexport const Param = createParamDecorator(\"param\");\r\nexport const Headers = createParamDecorator(\"header\");\r\nexport const Cookies = createParamDecorator(\"cookie\");\r\nexport const Req = createParamDecorator(\"req\");\r\nexport const Res = createParamDecorator(\"res\");\r\nexport const NextFunc = createParamDecorator(\"next\");\r\nexport const Ip = createParamDecorator(\"ip\");\r\nexport const Session = createParamDecorator(\"session\");\r\n\r\nexport function UseMiddleware(...middlewares: MiddlewareHandler[]): MethodDecorator & ClassDecorator {\r\n return (target: any, propertyKey?: string | symbol, _descriptor?: PropertyDescriptor) => {\r\n if (propertyKey) {\r\n const existing: MiddlewareHandler[] =\r\n Reflect.getMetadata(MIDDLEWARES_META_KEY, target, String(propertyKey)) ?? [];\r\n Reflect.defineMetadata(MIDDLEWARES_META_KEY, [...existing, ...middlewares], target, String(propertyKey));\r\n } else {\r\n const existing: MiddlewareHandler[] =\r\n Reflect.getMetadata(MIDDLEWARES_META_KEY, target) ?? [];\r\n Reflect.defineMetadata(MIDDLEWARES_META_KEY, [...existing, ...middlewares], target);\r\n }\r\n };\r\n}\r\n\r\nfunction isAzuraServerLike(x: unknown): x is AppRegisterable {\r\n return (\r\n typeof x === \"object\" &&\r\n x !== null &&\r\n typeof (x as AppRegisterable).register === \"function\" &&\r\n typeof (x as AppRegisterable).listen === \"function\"\r\n );\r\n}\r\n\r\n/** Compõe vários decorators (estilo NestJS). */\r\nexport function composeDecorators(...decorators: (MethodDecorator | ClassDecorator)[]): MethodDecorator & ClassDecorator {\r\n return (target: any, propertyKey?: string | symbol, descriptor?: PropertyDescriptor) => {\r\n for (const decorator of decorators) {\r\n if (propertyKey !== undefined) {\r\n (decorator as MethodDecorator)(target, propertyKey, descriptor!);\r\n } else {\r\n (decorator as ClassDecorator)(target);\r\n }\r\n }\r\n };\r\n}\r\n\r\n/**\r\n * Regista controllers na app (paridade com AzuraJS v2).\r\n * Aceita `applyDecorators(app, [A, B])` ou `applyDecorators(app, A, B)`.\r\n */\r\nexport function applyDecorators(\r\n app: AppRegisterable,\r\n controllers: Array<new (...args: any[]) => any>,\r\n): void;\r\nexport function applyDecorators(\r\n app: AppRegisterable,\r\n ...controllers: (new (...args: any[]) => any)[]\r\n): void;\r\nexport function applyDecorators(\r\n ...decorators: (MethodDecorator | ClassDecorator)[]\r\n): MethodDecorator & ClassDecorator;\r\nexport function applyDecorators(\r\n first: AppRegisterable | MethodDecorator | ClassDecorator,\r\n ...rest: unknown[]\r\n): void | (MethodDecorator & ClassDecorator) {\r\n if (isAzuraServerLike(first) && rest.length >= 1) {\r\n const second = rest[0];\r\n if (Array.isArray(second)) {\r\n first.register(...(second as (new (...args: any[]) => any)[]));\r\n } else {\r\n first.register(...(rest as (new (...args: any[]) => any)[]));\r\n }\r\n return;\r\n }\r\n const decorators = [first, ...rest] as (MethodDecorator | ClassDecorator)[];\r\n return composeDecorators(...decorators);\r\n}\r\n\r\nexport function Meta(key: string, value: any): MethodDecorator {\r\n return (target, propertyKey, _descriptor) => {\r\n const routeMeta = Reflect.getMetadata(ROUTES_META_KEY, target, String(propertyKey));\r\n if (routeMeta) {\r\n if (!routeMeta.meta) routeMeta.meta = {};\r\n routeMeta.meta[key] = value;\r\n Reflect.defineMetadata(ROUTES_META_KEY, routeMeta, target, String(propertyKey));\r\n }\r\n };\r\n}\r\n","/** Tags OpenAPI a nível de controller (todas as rotas do class) */\r\nexport const API_TAGS_KEY = \"azura:api-tags\";\r\n\r\n/** Tags por método (independente da ordem em relação a @Get/@Post) */\r\nexport const METHOD_TAGS_KEY = \"azura:swagger-method-tags\";\r\n\r\n/** Metadados OpenAPI por método (summary, responses, etc.) */\r\nexport const API_OPERATION_KEY = \"azura:swagger-operation\";\r\n","import type { RouteMeta } from \"../types/routes.type.js\";\r\nimport { API_OPERATION_KEY, API_TAGS_KEY, METHOD_TAGS_KEY } from \"./constants.js\";\r\n\r\n/**\r\n * Tags OpenAPI no controller (todas as rotas) ou num método específico.\r\n * Compatível com `experimentalDecorators` (assinatura legacy de 3 argumentos em métodos).\r\n */\r\nexport function ApiTags(...tags: string[]): ClassDecorator & MethodDecorator {\r\n return function (\r\n target: object,\r\n propertyKey?: string | symbol,\r\n _descriptor?: PropertyDescriptor,\r\n ): void {\r\n if (propertyKey === undefined) {\r\n Reflect.defineMetadata(API_TAGS_KEY, tags, target);\r\n } else {\r\n Reflect.defineMetadata(METHOD_TAGS_KEY, tags, target, String(propertyKey));\r\n }\r\n } as ClassDecorator & MethodDecorator;\r\n}\r\n\r\n/**\r\n * Metadados OpenAPI (summary, description, responses, parameters, etc.).\r\n */\r\nexport function ApiOperation(meta: Partial<RouteMeta>): MethodDecorator {\r\n return function (\r\n target: object,\r\n propertyKey: string | symbol,\r\n _descriptor: PropertyDescriptor,\r\n ): void {\r\n const key = String(propertyKey);\r\n const cur = (Reflect.getMetadata?.(API_OPERATION_KEY, target, key) ?? {}) as Partial<RouteMeta>;\r\n Reflect.defineMetadata(API_OPERATION_KEY, { ...cur, ...meta }, target, key);\r\n };\r\n}\r\n"]}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { AzuraServer } from './core/index.mjs';
|
|
2
2
|
export { R as Router } from './index-j6QGMhZU.mjs';
|
|
3
|
-
export { Body, Controller, Cookies, Delete, Get, Head, Headers, Ip, Meta, NextFunc, Options, Param, Patch, Post, Put, Query, Req, Res, Session, UseMiddleware, applyDecorators } from './decorators/index.mjs';
|
|
3
|
+
export { Body, Controller, Cookies, Delete, Get, Head, Headers, Ip, Meta, NextFunc, Options, Param, Patch, Post, Put, Query, Req, Res, Session, UseMiddleware, applyDecorators, composeDecorators } from './decorators/index.mjs';
|
|
4
4
|
export { A as ApiOperation, a as ApiTags } from './decorators-D5nY109r.mjs';
|
|
5
5
|
export { CORSPlugin } from './cors/index.mjs';
|
|
6
6
|
export { RateLimitPlugin } from './rate-limit/index.mjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { AzuraServer } from './core/index.js';
|
|
2
2
|
export { R as Router } from './index-tpPZS_UK.js';
|
|
3
|
-
export { Body, Controller, Cookies, Delete, Get, Head, Headers, Ip, Meta, NextFunc, Options, Param, Patch, Post, Put, Query, Req, Res, Session, UseMiddleware, applyDecorators } from './decorators/index.js';
|
|
3
|
+
export { Body, Controller, Cookies, Delete, Get, Head, Headers, Ip, Meta, NextFunc, Options, Param, Patch, Post, Put, Query, Req, Res, Session, UseMiddleware, applyDecorators, composeDecorators } from './decorators/index.js';
|
|
4
4
|
export { A as ApiOperation, a as ApiTags } from './decorators-B6l3CbxC.js';
|
|
5
5
|
export { CORSPlugin } from './cors/index.js';
|
|
6
6
|
export { RateLimitPlugin } from './rate-limit/index.js';
|
package/dist/index.js
CHANGED
|
@@ -1402,7 +1402,10 @@ function UseMiddleware(...middlewares) {
|
|
|
1402
1402
|
}
|
|
1403
1403
|
};
|
|
1404
1404
|
}
|
|
1405
|
-
function
|
|
1405
|
+
function isAzuraServerLike(x) {
|
|
1406
|
+
return typeof x === "object" && x !== null && typeof x.register === "function" && typeof x.listen === "function";
|
|
1407
|
+
}
|
|
1408
|
+
function composeDecorators(...decorators) {
|
|
1406
1409
|
return (target, propertyKey, descriptor) => {
|
|
1407
1410
|
for (const decorator of decorators) {
|
|
1408
1411
|
if (propertyKey !== void 0) {
|
|
@@ -1413,6 +1416,19 @@ function applyDecorators(...decorators) {
|
|
|
1413
1416
|
}
|
|
1414
1417
|
};
|
|
1415
1418
|
}
|
|
1419
|
+
function applyDecorators(first, ...rest) {
|
|
1420
|
+
if (isAzuraServerLike(first) && rest.length >= 1) {
|
|
1421
|
+
const second = rest[0];
|
|
1422
|
+
if (Array.isArray(second)) {
|
|
1423
|
+
first.register(...second);
|
|
1424
|
+
} else {
|
|
1425
|
+
first.register(...rest);
|
|
1426
|
+
}
|
|
1427
|
+
return;
|
|
1428
|
+
}
|
|
1429
|
+
const decorators = [first, ...rest];
|
|
1430
|
+
return composeDecorators(...decorators);
|
|
1431
|
+
}
|
|
1416
1432
|
function Meta(key, value) {
|
|
1417
1433
|
return (target, propertyKey, _descriptor) => {
|
|
1418
1434
|
const routeMeta = Reflect.getMetadata(ROUTES_META_KEY2, target, String(propertyKey));
|
|
@@ -4578,6 +4594,7 @@ exports.UseMiddleware = UseMiddleware;
|
|
|
4578
4594
|
exports.ValidationError = ValidationError;
|
|
4579
4595
|
exports.applyDecorators = applyDecorators;
|
|
4580
4596
|
exports.clearCookieHeader = clearCookieHeader;
|
|
4597
|
+
exports.composeDecorators = composeDecorators;
|
|
4581
4598
|
exports.parseBody = parseBody;
|
|
4582
4599
|
exports.parseCookies = parseCookies;
|
|
4583
4600
|
exports.parseQueryString = parseQueryString;
|