chore: v2.2.8 build

This commit is contained in:
p-sw 2024-03-31 20:43:35 +09:00
parent e0eac61ec7
commit b6e828a003
6 changed files with 100 additions and 19 deletions

View File

@ -1,7 +1,17 @@
export declare const notIncludedSymbol: unique symbol;
export declare function includeObjectSync(ocv: any, opt: {
paths: string[];
}): any;
export declare function excludeObjectSync(ocv: any, opt: {
paths: string[];
}): any;
export declare function includeOrExcludeObjectSync(ocv: any, paths: string[], currentPath: string[], include: boolean): any;
export declare function objectContainedLoggedSync(ocv: any, options?: {
include?: string[];
exclude: string[];
}): string;
export declare function imObjectContainedLogSync(ocv: any, options?: {
include?: string[];
exclude?: string[];
}): string;
export declare function getItemByPathSync(obj: object, path: string | string[]): any;

67
dist/lib/functions.js vendored
View File

@ -1,7 +1,55 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getItemByPathSync = exports.objectContainedLoggedSync = exports.includeOrExcludeObjectSync = exports.notIncludedSymbol = void 0;
exports.getItemByPathSync = exports.imObjectContainedLogSync = exports.objectContainedLoggedSync = exports.includeOrExcludeObjectSync = exports.excludeObjectSync = exports.includeObjectSync = exports.notIncludedSymbol = void 0;
exports.notIncludedSymbol = Symbol("notIncluded");
function includeObjectSync(ocv, opt) {
let current = Array.isArray(ocv) ? [] : typeof ocv === 'object' ? {} : ocv;
opt.paths.forEach((dotpath) => {
let query = ocv;
let objRef = current;
const path = dotpath.split('.');
for (const [index, key] of Object.entries(path)) {
query = query[key];
if (query !== undefined && objRef[key] === undefined) {
if (typeof query === 'object') {
if (Array.isArray(query)) {
objRef[key] = [];
}
else {
objRef[key] = {};
}
}
}
if (typeof query !== 'object' || index === (path.length - 1).toString()) {
objRef[key] = query;
break;
}
objRef = objRef[key];
}
});
return current;
}
exports.includeObjectSync = includeObjectSync;
function excludeObjectSync(ocv, opt) {
const copied = typeof ocv === 'object' ? Array.isArray(ocv) ? [...ocv] : { ...ocv } : ocv;
opt.paths.forEach((dotpath) => {
let objRef = copied;
const path = dotpath.split('.');
const lastIndex = (path.length - 1).toString();
for (const [index, key] of Object.entries(path)) {
if (index === lastIndex) {
delete objRef[key];
break;
}
objRef = objRef[key];
if (typeof objRef !== 'object') {
break;
}
}
});
return copied;
}
exports.excludeObjectSync = excludeObjectSync;
function includeOrExcludeObjectSync(ocv, paths, currentPath = [], include // or exclude
) {
if (Array.isArray(ocv)) {
@ -40,6 +88,23 @@ function objectContainedLoggedSync(ocv, options) {
}
}
exports.objectContainedLoggedSync = objectContainedLoggedSync;
function imObjectContainedLogSync(ocv, options) {
if (options && typeof ocv === 'object' && ocv !== null) {
if (options.include && options.include.length > 0) {
return JSON.stringify(includeObjectSync(ocv, { paths: options.include }));
}
if (options.exclude && options.exclude.length > 0) {
return JSON.stringify(excludeObjectSync(ocv, { paths: options.exclude }));
}
}
if (typeof ocv === "object" && ocv !== null) {
return JSON.stringify(ocv);
}
else {
return `${ocv}`;
}
}
exports.imObjectContainedLogSync = imObjectContainedLogSync;
function getItemByPathSync(obj, path) {
const paths = Array.isArray(path) ? path : path.split(".");
return Object.keys(obj).includes(paths[0])

10
dist/lib/logged.js vendored
View File

@ -79,10 +79,10 @@ function overrideBuild(originalFunction, baseLogger, metadatas, key, returnsData
if (typeof metadatas.scopedLoggerInjectableParam !== "undefined") {
if (args.length <= metadatas.scopedLoggerInjectableParam ||
!(args[metadatas.scopedLoggerInjectableParam] instanceof logger_1.ScopedLogger)) {
args[metadatas.scopedLoggerInjectableParam] = new logger_1.ScopedLogger(baseLogger, key, true, true);
args[metadatas.scopedLoggerInjectableParam] = logger_1.ScopedLogger.fromRoot(baseLogger, key);
}
else {
args[metadatas.scopedLoggerInjectableParam] = new logger_1.ScopedLogger(args[metadatas.scopedLoggerInjectableParam], key, false);
args[metadatas.scopedLoggerInjectableParam] = logger_1.ScopedLogger.fromSuper(baseLogger, args[metadatas.scopedLoggerInjectableParam], key);
}
injectedLogger = args[metadatas.scopedLoggerInjectableParam];
}
@ -90,7 +90,7 @@ function overrideBuild(originalFunction, baseLogger, metadatas, key, returnsData
? "WITH " +
metadatas.loggedParams.map(({ name, index, include, exclude }) => name +
"=" +
(0, functions_1.objectContainedLoggedSync)(args[index], {
(0, functions_1.imObjectContainedLogSync)(args[index], {
include,
exclude,
})).join(", ")
@ -101,7 +101,7 @@ function overrideBuild(originalFunction, baseLogger, metadatas, key, returnsData
(r && typeof r === 'object' && typeof r['then'] === 'function')) {
return r['then']((r) => {
const resultLogged = Array.isArray(returnsData)
? typeof r === "object"
? typeof r === "object" && r !== null
? "WITH " +
returnsData.map(({ name, path }) => {
const value = (0, functions_1.getItemByPathSync)(r, path);
@ -125,7 +125,7 @@ function overrideBuild(originalFunction, baseLogger, metadatas, key, returnsData
}
else {
const resultLogged = Array.isArray(returnsData)
? typeof r === "object"
? typeof r === "object" && r !== null
? "WITH " +
returnsData.map(({ name, path }) => {
const value = (0, functions_1.getItemByPathSync)(r, path);

View File

@ -2,10 +2,8 @@ import { Logger } from "@nestjs/common";
export declare class ScopedLogger extends Logger {
private logger;
private scope;
private root;
private createScopeId;
private readonly scopeId?;
constructor(logger: Logger, scope: string, root?: boolean, createScopeId?: boolean);
private scopeId;
constructor(logger: Logger, scope: string[], scopeId?: string);
private scopedLog;
debug: (message: string) => void;
log: (message: string) => void;
@ -13,4 +11,6 @@ export declare class ScopedLogger extends Logger {
verbose: (message: string) => void;
error: (message: string) => void;
fatal: (message: string) => void;
static fromSuper(baseLogger: Logger, logger: ScopedLogger, scope: string): ScopedLogger;
static fromRoot(logger: Logger, scope: string): ScopedLogger;
}

17
dist/lib/logger.js vendored
View File

@ -5,25 +5,30 @@ const common_1 = require("@nestjs/common");
const hyperid = require("hyperid");
const createId = hyperid({ fixedLength: true });
class ScopedLogger extends common_1.Logger {
constructor(logger, scope, root = false, createScopeId = false) {
constructor(logger, scope, scopeId = createId()) {
super();
this.logger = logger;
this.scope = scope;
this.root = root;
this.createScopeId = createScopeId;
this.scopeId = scopeId;
this.debug = this.scopedLog("debug");
this.log = this.scopedLog("log");
this.warn = this.scopedLog("warn");
this.verbose = this.scopedLog("verbose");
this.error = this.scopedLog("error");
this.fatal = this.scopedLog("fatal");
if (this.createScopeId)
this.scopeId = createId();
}
scopedLog(method) {
return (message) => {
this.logger[method](`${this.root ? "" : "-> "}${this.scope}${this.scopeId ? `(${this.scopeId})` : ""}: ${message}`);
this.logger[method](`${this.scopeId ? `(ID ${this.scopeId}) | ` : ""}${this.scope.join(" -> ")}: ${message}`);
};
}
static fromSuper(baseLogger, logger, scope) {
return new ScopedLogger(baseLogger, [...logger.scope, scope], logger.scopeId);
}
;
static fromRoot(logger, scope) {
return new ScopedLogger(logger, [scope]);
}
;
}
exports.ScopedLogger = ScopedLogger;

View File

@ -273,6 +273,7 @@ class LoggedMethodsClass {
@InjectLogger logger?: ScopedLogger
) {
logger.log(userId);
return {
http: {
result: "success",
@ -371,12 +372,12 @@ class LoggedMethodsClass {
const service = new TestService();
// const service = new TestService();
/**
* Choose Class to Test
*/
const tester = new LoggedClass(service);
// const tester = new LoggedClass(service);
// const tester = new LoggedMethodsClass(service);
/**
@ -398,7 +399,7 @@ const tester = new LoggedClass(service);
// void tester.testLoggerRootLogging();
// tester.testSyncLoggerRootLogging();
// tester.testSyncLogging();
void tester.testService();
// void tester.testService();
/**
* Then run `yarn test`