feat: allow synchronous method & string name in Returns

This commit is contained in:
p-sw 2024-01-10 01:20:27 +09:00
parent 91796820fe
commit 14a19c9871
2 changed files with 16 additions and 12 deletions

View File

@ -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)

View File

@ -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] }],
[] []
) )