This commit is contained in:
p-sw 2024-01-10 01:21:13 +09:00
parent f518b537cd
commit 94c564d063
5 changed files with 14 additions and 9 deletions

2
dist/lib/index.d.ts vendored
View File

@ -1,3 +1,3 @@
export { LoggedRoute, LoggedFunction, LoggedController, LoggedInjectable, } from "./logged";
export { ScopedLogger } from "./logger";
export { InjectLogger, LoggedParam, LoggedHeaders, LoggedBody, LoggedQuery, Returns } from "./reflected";
export { InjectLogger, LoggedParam, LoggedHeaders, LoggedBody, LoggedQuery, Logged, Returns } from "./reflected";

3
dist/lib/index.js vendored
View File

@ -1,6 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Returns = exports.LoggedQuery = exports.LoggedBody = exports.LoggedHeaders = exports.LoggedParam = exports.InjectLogger = exports.ScopedLogger = exports.LoggedInjectable = exports.LoggedController = exports.LoggedFunction = exports.LoggedRoute = void 0;
exports.Returns = exports.Logged = exports.LoggedQuery = exports.LoggedBody = exports.LoggedHeaders = exports.LoggedParam = exports.InjectLogger = exports.ScopedLogger = exports.LoggedInjectable = exports.LoggedController = exports.LoggedFunction = exports.LoggedRoute = void 0;
var logged_1 = require("./logged");
Object.defineProperty(exports, "LoggedRoute", { enumerable: true, get: function () { return logged_1.LoggedRoute; } });
Object.defineProperty(exports, "LoggedFunction", { enumerable: true, get: function () { return logged_1.LoggedFunction; } });
@ -14,4 +14,5 @@ Object.defineProperty(exports, "LoggedParam", { enumerable: true, get: function
Object.defineProperty(exports, "LoggedHeaders", { enumerable: true, get: function () { return reflected_1.LoggedHeaders; } });
Object.defineProperty(exports, "LoggedBody", { enumerable: true, get: function () { return reflected_1.LoggedBody; } });
Object.defineProperty(exports, "LoggedQuery", { enumerable: true, get: function () { return reflected_1.LoggedQuery; } });
Object.defineProperty(exports, "Logged", { enumerable: true, get: function () { return reflected_1.Logged; } });
Object.defineProperty(exports, "Returns", { enumerable: true, get: function () { return reflected_1.Returns; } });

12
dist/lib/logged.js vendored
View File

@ -107,11 +107,13 @@ function overrideBuild(originalFunction, baseLogger, metadatas, key, returnsData
.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
? `RETURNED HTTP ${route.fullRoute} (${key}) ${resultLogged}`
: `RETURNED ${key} ${resultLogged}`);

View File

@ -42,5 +42,5 @@ export declare function LoggedBody(property: string, ...pipes: Pipe[]): LoggedPa
export declare function LoggedHeaders(property?: string): LoggedParamReturns;
export declare function Returns<F extends Array<any>, R>(namePaths?: {
[name: string]: string;
}): (_target: any, _key: string | symbol, descriptor: TypedPropertyDescriptor<(...args: F) => Promise<R>>) => void;
} | string): (_target: any, _key: string | symbol, descriptor: TypedPropertyDescriptor<(...args: F) => Promise<R> | R>) => void;
export {};

View File

@ -84,7 +84,9 @@ exports.LoggedHeaders = LoggedHeaders;
function Returns(namePaths) {
return (_target, _key, descriptor) => {
Reflect.defineMetadata(exports.returns, namePaths
? Object.entries(namePaths).reduce((prev, curr) => [...prev, { name: curr[0], path: curr[1] }], [])
? typeof namePaths === 'string'
? namePaths
: Object.entries(namePaths).reduce((prev, curr) => [...prev, { name: curr[0], path: curr[1] }], [])
: true, descriptor.value);
};
}