feat: allow synchronous method & string name in Returns
This commit is contained in:
parent
91796820fe
commit
14a19c9871
@ -126,7 +126,7 @@ function overrideBuild<F extends Array<any>, R>(
|
||||
baseLogger: Logger,
|
||||
metadatas: FunctionMetadata,
|
||||
key: string,
|
||||
returnsData: ReturnsReflectData[] | true,
|
||||
returnsData: ReturnsReflectData[] | string | true,
|
||||
route?: {
|
||||
fullRoute: string;
|
||||
}
|
||||
@ -196,11 +196,13 @@ function overrideBuild<F extends Array<any>, R>(
|
||||
.filter((v) => v.length > 0)
|
||||
.join(", ")
|
||||
: ""
|
||||
: returnsData
|
||||
? typeof r === "object"
|
||||
? "WITH " + JSON.stringify(r)
|
||||
: "WITH " + r
|
||||
: "";
|
||||
: typeof returnsData === 'string'
|
||||
? "WITH " + returnsData + "=" + typeof r === "object" ? JSON.stringify(r) : r
|
||||
: returnsData
|
||||
? typeof r === "object"
|
||||
? "WITH " + JSON.stringify(r)
|
||||
: "WITH " + r
|
||||
: "";
|
||||
|
||||
injectedLogger.log(
|
||||
route
|
||||
|
@ -230,19 +230,21 @@ export function LoggedHeaders(property?: string): LoggedParamReturns {
|
||||
|
||||
export function Returns<F extends Array<any>, R>(namePaths?: {
|
||||
[name: string]: string;
|
||||
}) {
|
||||
} | string) {
|
||||
return (
|
||||
_target: any,
|
||||
_key: string | symbol,
|
||||
descriptor: TypedPropertyDescriptor<(...args: F) => Promise<R>>
|
||||
descriptor: TypedPropertyDescriptor<(...args: F) => Promise<R> | R>
|
||||
) => {
|
||||
Reflect.defineMetadata(
|
||||
returns,
|
||||
namePaths
|
||||
? Object.entries(namePaths).reduce<ReturnsReflectData[]>(
|
||||
(prev, curr) => [...prev, { name: curr[0], path: curr[1] }],
|
||||
[]
|
||||
)
|
||||
? typeof namePaths === 'string'
|
||||
? namePaths
|
||||
: Object.entries(namePaths).reduce<ReturnsReflectData[]>(
|
||||
(prev, curr) => [...prev, { name: curr[0], path: curr[1] }],
|
||||
[]
|
||||
)
|
||||
: true,
|
||||
descriptor.value
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user