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,
|
baseLogger: Logger,
|
||||||
metadatas: FunctionMetadata,
|
metadatas: FunctionMetadata,
|
||||||
key: string,
|
key: string,
|
||||||
returnsData: ReturnsReflectData[] | true,
|
returnsData: ReturnsReflectData[] | string | true,
|
||||||
route?: {
|
route?: {
|
||||||
fullRoute: string;
|
fullRoute: string;
|
||||||
}
|
}
|
||||||
@ -196,6 +196,8 @@ function overrideBuild<F extends Array<any>, R>(
|
|||||||
.filter((v) => v.length > 0)
|
.filter((v) => v.length > 0)
|
||||||
.join(", ")
|
.join(", ")
|
||||||
: ""
|
: ""
|
||||||
|
: typeof returnsData === 'string'
|
||||||
|
? "WITH " + returnsData + "=" + typeof r === "object" ? JSON.stringify(r) : r
|
||||||
: returnsData
|
: returnsData
|
||||||
? typeof r === "object"
|
? typeof r === "object"
|
||||||
? "WITH " + JSON.stringify(r)
|
? "WITH " + JSON.stringify(r)
|
||||||
|
@ -230,16 +230,18 @@ export function LoggedHeaders(property?: string): LoggedParamReturns {
|
|||||||
|
|
||||||
export function Returns<F extends Array<any>, R>(namePaths?: {
|
export function Returns<F extends Array<any>, R>(namePaths?: {
|
||||||
[name: string]: string;
|
[name: string]: string;
|
||||||
}) {
|
} | string) {
|
||||||
return (
|
return (
|
||||||
_target: any,
|
_target: any,
|
||||||
_key: string | symbol,
|
_key: string | symbol,
|
||||||
descriptor: TypedPropertyDescriptor<(...args: F) => Promise<R>>
|
descriptor: TypedPropertyDescriptor<(...args: F) => Promise<R> | R>
|
||||||
) => {
|
) => {
|
||||||
Reflect.defineMetadata(
|
Reflect.defineMetadata(
|
||||||
returns,
|
returns,
|
||||||
namePaths
|
namePaths
|
||||||
? Object.entries(namePaths).reduce<ReturnsReflectData[]>(
|
? typeof namePaths === 'string'
|
||||||
|
? namePaths
|
||||||
|
: Object.entries(namePaths).reduce<ReturnsReflectData[]>(
|
||||||
(prev, curr) => [...prev, { name: curr[0], path: curr[1] }],
|
(prev, curr) => [...prev, { name: curr[0], path: curr[1] }],
|
||||||
[]
|
[]
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user