@karmaniverous/jsonmap 2.0.5 → 2.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +6 -632
- package/dist/index.mjs +6 -632
- package/package.json +1 -2
package/dist/index.cjs
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var node_crypto = require('node:crypto');
|
|
4
|
-
var os = require('os');
|
|
5
|
-
var path = require('path');
|
|
6
|
-
var util = require('util');
|
|
7
4
|
|
|
8
5
|
/******************************************************************************
|
|
9
6
|
Copyright (c) Microsoft Corporation.
|
|
@@ -17269,629 +17266,6 @@ function nanoid(size = 21) {
|
|
|
17269
17266
|
return id
|
|
17270
17267
|
}
|
|
17271
17268
|
|
|
17272
|
-
const prettyLogStyles = {
|
|
17273
|
-
reset: [0, 0],
|
|
17274
|
-
bold: [1, 22],
|
|
17275
|
-
dim: [2, 22],
|
|
17276
|
-
italic: [3, 23],
|
|
17277
|
-
underline: [4, 24],
|
|
17278
|
-
overline: [53, 55],
|
|
17279
|
-
inverse: [7, 27],
|
|
17280
|
-
hidden: [8, 28],
|
|
17281
|
-
strikethrough: [9, 29],
|
|
17282
|
-
black: [30, 39],
|
|
17283
|
-
red: [31, 39],
|
|
17284
|
-
green: [32, 39],
|
|
17285
|
-
yellow: [33, 39],
|
|
17286
|
-
blue: [34, 39],
|
|
17287
|
-
magenta: [35, 39],
|
|
17288
|
-
cyan: [36, 39],
|
|
17289
|
-
white: [37, 39],
|
|
17290
|
-
blackBright: [90, 39],
|
|
17291
|
-
redBright: [91, 39],
|
|
17292
|
-
greenBright: [92, 39],
|
|
17293
|
-
yellowBright: [93, 39],
|
|
17294
|
-
blueBright: [94, 39],
|
|
17295
|
-
magentaBright: [95, 39],
|
|
17296
|
-
cyanBright: [96, 39],
|
|
17297
|
-
whiteBright: [97, 39],
|
|
17298
|
-
bgBlack: [40, 49],
|
|
17299
|
-
bgRed: [41, 49],
|
|
17300
|
-
bgGreen: [42, 49],
|
|
17301
|
-
bgYellow: [43, 49],
|
|
17302
|
-
bgBlue: [44, 49],
|
|
17303
|
-
bgMagenta: [45, 49],
|
|
17304
|
-
bgCyan: [46, 49],
|
|
17305
|
-
bgWhite: [47, 49],
|
|
17306
|
-
bgBlackBright: [100, 49],
|
|
17307
|
-
bgRedBright: [101, 49],
|
|
17308
|
-
bgGreenBright: [102, 49],
|
|
17309
|
-
bgYellowBright: [103, 49],
|
|
17310
|
-
bgBlueBright: [104, 49],
|
|
17311
|
-
bgMagentaBright: [105, 49],
|
|
17312
|
-
bgCyanBright: [106, 49],
|
|
17313
|
-
bgWhiteBright: [107, 49],
|
|
17314
|
-
};
|
|
17315
|
-
|
|
17316
|
-
function formatTemplate(settings, template, values, hideUnsetPlaceholder = false) {
|
|
17317
|
-
const templateString = String(template);
|
|
17318
|
-
const ansiColorWrap = (placeholderValue, code) => `\u001b[${code[0]}m${placeholderValue}\u001b[${code[1]}m`;
|
|
17319
|
-
const styleWrap = (value, style) => {
|
|
17320
|
-
if (style != null && typeof style === "string") {
|
|
17321
|
-
return ansiColorWrap(value, prettyLogStyles[style]);
|
|
17322
|
-
}
|
|
17323
|
-
else if (style != null && Array.isArray(style)) {
|
|
17324
|
-
return style.reduce((prevValue, thisStyle) => styleWrap(prevValue, thisStyle), value);
|
|
17325
|
-
}
|
|
17326
|
-
else {
|
|
17327
|
-
if (style != null && style[value.trim()] != null) {
|
|
17328
|
-
return styleWrap(value, style[value.trim()]);
|
|
17329
|
-
}
|
|
17330
|
-
else if (style != null && style["*"] != null) {
|
|
17331
|
-
return styleWrap(value, style["*"]);
|
|
17332
|
-
}
|
|
17333
|
-
else {
|
|
17334
|
-
return value;
|
|
17335
|
-
}
|
|
17336
|
-
}
|
|
17337
|
-
};
|
|
17338
|
-
const defaultStyle = null;
|
|
17339
|
-
return templateString.replace(/{{(.+?)}}/g, (_, placeholder) => {
|
|
17340
|
-
const value = values[placeholder] != null ? String(values[placeholder]) : hideUnsetPlaceholder ? "" : _;
|
|
17341
|
-
return settings.stylePrettyLogs
|
|
17342
|
-
? styleWrap(value, settings?.prettyLogStyles?.[placeholder] ?? defaultStyle) + ansiColorWrap("", prettyLogStyles.reset)
|
|
17343
|
-
: value;
|
|
17344
|
-
});
|
|
17345
|
-
}
|
|
17346
|
-
|
|
17347
|
-
function formatNumberAddZeros(value, digits = 2, addNumber = 0) {
|
|
17348
|
-
if (value != null && isNaN(value)) {
|
|
17349
|
-
return "";
|
|
17350
|
-
}
|
|
17351
|
-
value = value != null ? value + addNumber : value;
|
|
17352
|
-
return digits === 2
|
|
17353
|
-
? value == null
|
|
17354
|
-
? "--"
|
|
17355
|
-
: value < 10
|
|
17356
|
-
? "0" + value
|
|
17357
|
-
: value.toString()
|
|
17358
|
-
: value == null
|
|
17359
|
-
? "---"
|
|
17360
|
-
: value < 10
|
|
17361
|
-
? "00" + value
|
|
17362
|
-
: value < 100
|
|
17363
|
-
? "0" + value
|
|
17364
|
-
: value.toString();
|
|
17365
|
-
}
|
|
17366
|
-
|
|
17367
|
-
function urlToObject(url) {
|
|
17368
|
-
return {
|
|
17369
|
-
href: url.href,
|
|
17370
|
-
protocol: url.protocol,
|
|
17371
|
-
username: url.username,
|
|
17372
|
-
password: url.password,
|
|
17373
|
-
host: url.host,
|
|
17374
|
-
hostname: url.hostname,
|
|
17375
|
-
port: url.port,
|
|
17376
|
-
pathname: url.pathname,
|
|
17377
|
-
search: url.search,
|
|
17378
|
-
searchParams: [...url.searchParams].map(([key, value]) => ({ key, value })),
|
|
17379
|
-
hash: url.hash,
|
|
17380
|
-
origin: url.origin,
|
|
17381
|
-
};
|
|
17382
|
-
}
|
|
17383
|
-
|
|
17384
|
-
var Runtime = {
|
|
17385
|
-
getCallerStackFrame,
|
|
17386
|
-
getErrorTrace,
|
|
17387
|
-
getMeta,
|
|
17388
|
-
transportJSON,
|
|
17389
|
-
transportFormatted,
|
|
17390
|
-
isBuffer,
|
|
17391
|
-
isError,
|
|
17392
|
-
prettyFormatLogObj,
|
|
17393
|
-
prettyFormatErrorObj,
|
|
17394
|
-
};
|
|
17395
|
-
const meta = {
|
|
17396
|
-
runtime: "Nodejs",
|
|
17397
|
-
runtimeVersion: process?.version,
|
|
17398
|
-
hostname: os.hostname ? os.hostname() : undefined,
|
|
17399
|
-
};
|
|
17400
|
-
function getMeta(logLevelId, logLevelName, stackDepthLevel, hideLogPositionForPerformance, name, parentNames) {
|
|
17401
|
-
return Object.assign({}, meta, {
|
|
17402
|
-
name,
|
|
17403
|
-
parentNames,
|
|
17404
|
-
date: new Date(),
|
|
17405
|
-
logLevelId,
|
|
17406
|
-
logLevelName,
|
|
17407
|
-
path: !hideLogPositionForPerformance ? getCallerStackFrame(stackDepthLevel) : undefined,
|
|
17408
|
-
});
|
|
17409
|
-
}
|
|
17410
|
-
function getCallerStackFrame(stackDepthLevel, error = Error()) {
|
|
17411
|
-
return stackLineToStackFrame(error?.stack?.split("\n")?.filter((thisLine) => thisLine.includes(" at "))?.[stackDepthLevel]);
|
|
17412
|
-
}
|
|
17413
|
-
function getErrorTrace(error) {
|
|
17414
|
-
return error?.stack?.split("\n")?.reduce((result, line) => {
|
|
17415
|
-
if (line.includes(" at ")) {
|
|
17416
|
-
result.push(stackLineToStackFrame(line));
|
|
17417
|
-
}
|
|
17418
|
-
return result;
|
|
17419
|
-
}, []);
|
|
17420
|
-
}
|
|
17421
|
-
function stackLineToStackFrame(line) {
|
|
17422
|
-
const pathResult = {
|
|
17423
|
-
fullFilePath: undefined,
|
|
17424
|
-
fileName: undefined,
|
|
17425
|
-
fileNameWithLine: undefined,
|
|
17426
|
-
fileColumn: undefined,
|
|
17427
|
-
fileLine: undefined,
|
|
17428
|
-
filePath: undefined,
|
|
17429
|
-
filePathWithLine: undefined,
|
|
17430
|
-
method: undefined,
|
|
17431
|
-
};
|
|
17432
|
-
if (line != null && line.includes(" at ")) {
|
|
17433
|
-
line = line.replace(/^\s+at\s+/gm, "");
|
|
17434
|
-
const errorStackLine = line.split(" (");
|
|
17435
|
-
const fullFilePath = line?.slice(-1) === ")" ? line?.match(/\(([^)]+)\)/)?.[1] : line;
|
|
17436
|
-
const pathArray = fullFilePath?.includes(":") ? fullFilePath?.replace("file://", "")?.replace(process.cwd(), "")?.split(":") : undefined;
|
|
17437
|
-
const fileColumn = pathArray?.pop();
|
|
17438
|
-
const fileLine = pathArray?.pop();
|
|
17439
|
-
const filePath = pathArray?.pop();
|
|
17440
|
-
const filePathWithLine = path.normalize(`${filePath}:${fileLine}`);
|
|
17441
|
-
const fileName = filePath?.split("/")?.pop();
|
|
17442
|
-
const fileNameWithLine = `${fileName}:${fileLine}`;
|
|
17443
|
-
if (filePath != null && filePath.length > 0) {
|
|
17444
|
-
pathResult.fullFilePath = fullFilePath;
|
|
17445
|
-
pathResult.fileName = fileName;
|
|
17446
|
-
pathResult.fileNameWithLine = fileNameWithLine;
|
|
17447
|
-
pathResult.fileColumn = fileColumn;
|
|
17448
|
-
pathResult.fileLine = fileLine;
|
|
17449
|
-
pathResult.filePath = filePath;
|
|
17450
|
-
pathResult.filePathWithLine = filePathWithLine;
|
|
17451
|
-
pathResult.method = errorStackLine?.[1] != null ? errorStackLine?.[0] : undefined;
|
|
17452
|
-
}
|
|
17453
|
-
}
|
|
17454
|
-
return pathResult;
|
|
17455
|
-
}
|
|
17456
|
-
function isError(e) {
|
|
17457
|
-
return util.types?.isNativeError != null ? util.types.isNativeError(e) : e instanceof Error;
|
|
17458
|
-
}
|
|
17459
|
-
function prettyFormatLogObj(maskedArgs, settings) {
|
|
17460
|
-
return maskedArgs.reduce((result, arg) => {
|
|
17461
|
-
isError(arg) ? result.errors.push(prettyFormatErrorObj(arg, settings)) : result.args.push(arg);
|
|
17462
|
-
return result;
|
|
17463
|
-
}, { args: [], errors: [] });
|
|
17464
|
-
}
|
|
17465
|
-
function prettyFormatErrorObj(error, settings) {
|
|
17466
|
-
const errorStackStr = getErrorTrace(error).map((stackFrame) => {
|
|
17467
|
-
return formatTemplate(settings, settings.prettyErrorStackTemplate, { ...stackFrame }, true);
|
|
17468
|
-
});
|
|
17469
|
-
const placeholderValuesError = {
|
|
17470
|
-
errorName: ` ${error.name} `,
|
|
17471
|
-
errorMessage: Object.getOwnPropertyNames(error)
|
|
17472
|
-
.reduce((result, key) => {
|
|
17473
|
-
if (key !== "stack") {
|
|
17474
|
-
result.push(error[key]);
|
|
17475
|
-
}
|
|
17476
|
-
return result;
|
|
17477
|
-
}, [])
|
|
17478
|
-
.join(", "),
|
|
17479
|
-
errorStack: errorStackStr.join("\n"),
|
|
17480
|
-
};
|
|
17481
|
-
return formatTemplate(settings, settings.prettyErrorTemplate, placeholderValuesError);
|
|
17482
|
-
}
|
|
17483
|
-
function transportFormatted(logMetaMarkup, logArgs, logErrors, settings) {
|
|
17484
|
-
const logErrorsStr = (logErrors.length > 0 && logArgs.length > 0 ? "\n" : "") + logErrors.join("\n");
|
|
17485
|
-
settings.prettyInspectOptions.colors = settings.stylePrettyLogs;
|
|
17486
|
-
console.log(logMetaMarkup + util.formatWithOptions(settings.prettyInspectOptions, ...logArgs) + logErrorsStr);
|
|
17487
|
-
}
|
|
17488
|
-
function transportJSON(json) {
|
|
17489
|
-
console.log(jsonStringifyRecursive(json));
|
|
17490
|
-
function jsonStringifyRecursive(obj) {
|
|
17491
|
-
const cache = new Set();
|
|
17492
|
-
return JSON.stringify(obj, (key, value) => {
|
|
17493
|
-
if (typeof value === "object" && value !== null) {
|
|
17494
|
-
if (cache.has(value)) {
|
|
17495
|
-
return "[Circular]";
|
|
17496
|
-
}
|
|
17497
|
-
cache.add(value);
|
|
17498
|
-
}
|
|
17499
|
-
if (typeof value === "bigint") {
|
|
17500
|
-
return `${value}`;
|
|
17501
|
-
}
|
|
17502
|
-
if (typeof value === "undefined") {
|
|
17503
|
-
return "[undefined]";
|
|
17504
|
-
}
|
|
17505
|
-
return value;
|
|
17506
|
-
});
|
|
17507
|
-
}
|
|
17508
|
-
}
|
|
17509
|
-
function isBuffer(arg) {
|
|
17510
|
-
return Buffer.isBuffer(arg);
|
|
17511
|
-
}
|
|
17512
|
-
|
|
17513
|
-
class BaseLogger {
|
|
17514
|
-
constructor(settings, logObj, stackDepthLevel = 4) {
|
|
17515
|
-
this.logObj = logObj;
|
|
17516
|
-
this.stackDepthLevel = stackDepthLevel;
|
|
17517
|
-
this.runtime = Runtime;
|
|
17518
|
-
this.settings = {
|
|
17519
|
-
type: settings?.type ?? "pretty",
|
|
17520
|
-
name: settings?.name,
|
|
17521
|
-
parentNames: settings?.parentNames,
|
|
17522
|
-
minLevel: settings?.minLevel ?? 0,
|
|
17523
|
-
argumentsArrayName: settings?.argumentsArrayName,
|
|
17524
|
-
hideLogPositionForProduction: settings?.hideLogPositionForProduction ?? false,
|
|
17525
|
-
prettyLogTemplate: settings?.prettyLogTemplate ??
|
|
17526
|
-
"{{yyyy}}.{{mm}}.{{dd}} {{hh}}:{{MM}}:{{ss}}:{{ms}}\t{{logLevelName}}\t{{filePathWithLine}}{{nameWithDelimiterPrefix}}\t",
|
|
17527
|
-
prettyErrorTemplate: settings?.prettyErrorTemplate ?? "\n{{errorName}} {{errorMessage}}\nerror stack:\n{{errorStack}}",
|
|
17528
|
-
prettyErrorStackTemplate: settings?.prettyErrorStackTemplate ?? " • {{fileName}}\t{{method}}\n\t{{filePathWithLine}}",
|
|
17529
|
-
prettyErrorParentNamesSeparator: settings?.prettyErrorParentNamesSeparator ?? ":",
|
|
17530
|
-
prettyErrorLoggerNameDelimiter: settings?.prettyErrorLoggerNameDelimiter ?? "\t",
|
|
17531
|
-
stylePrettyLogs: settings?.stylePrettyLogs ?? true,
|
|
17532
|
-
prettyLogTimeZone: settings?.prettyLogTimeZone ?? "UTC",
|
|
17533
|
-
prettyLogStyles: settings?.prettyLogStyles ?? {
|
|
17534
|
-
logLevelName: {
|
|
17535
|
-
"*": ["bold", "black", "bgWhiteBright", "dim"],
|
|
17536
|
-
SILLY: ["bold", "white"],
|
|
17537
|
-
TRACE: ["bold", "whiteBright"],
|
|
17538
|
-
DEBUG: ["bold", "green"],
|
|
17539
|
-
INFO: ["bold", "blue"],
|
|
17540
|
-
WARN: ["bold", "yellow"],
|
|
17541
|
-
ERROR: ["bold", "red"],
|
|
17542
|
-
FATAL: ["bold", "redBright"],
|
|
17543
|
-
},
|
|
17544
|
-
dateIsoStr: "white",
|
|
17545
|
-
filePathWithLine: "white",
|
|
17546
|
-
name: ["white", "bold"],
|
|
17547
|
-
nameWithDelimiterPrefix: ["white", "bold"],
|
|
17548
|
-
nameWithDelimiterSuffix: ["white", "bold"],
|
|
17549
|
-
errorName: ["bold", "bgRedBright", "whiteBright"],
|
|
17550
|
-
fileName: ["yellow"],
|
|
17551
|
-
fileNameWithLine: "white",
|
|
17552
|
-
},
|
|
17553
|
-
prettyInspectOptions: settings?.prettyInspectOptions ?? {
|
|
17554
|
-
colors: true,
|
|
17555
|
-
compact: false,
|
|
17556
|
-
depth: Infinity,
|
|
17557
|
-
},
|
|
17558
|
-
metaProperty: settings?.metaProperty ?? "_meta",
|
|
17559
|
-
maskPlaceholder: settings?.maskPlaceholder ?? "[***]",
|
|
17560
|
-
maskValuesOfKeys: settings?.maskValuesOfKeys ?? ["password"],
|
|
17561
|
-
maskValuesOfKeysCaseInsensitive: settings?.maskValuesOfKeysCaseInsensitive ?? false,
|
|
17562
|
-
maskValuesRegEx: settings?.maskValuesRegEx,
|
|
17563
|
-
prefix: [...(settings?.prefix ?? [])],
|
|
17564
|
-
attachedTransports: [...(settings?.attachedTransports ?? [])],
|
|
17565
|
-
overwrite: {
|
|
17566
|
-
mask: settings?.overwrite?.mask,
|
|
17567
|
-
toLogObj: settings?.overwrite?.toLogObj,
|
|
17568
|
-
addMeta: settings?.overwrite?.addMeta,
|
|
17569
|
-
addPlaceholders: settings?.overwrite?.addPlaceholders,
|
|
17570
|
-
formatMeta: settings?.overwrite?.formatMeta,
|
|
17571
|
-
formatLogObj: settings?.overwrite?.formatLogObj,
|
|
17572
|
-
transportFormatted: settings?.overwrite?.transportFormatted,
|
|
17573
|
-
transportJSON: settings?.overwrite?.transportJSON,
|
|
17574
|
-
},
|
|
17575
|
-
};
|
|
17576
|
-
}
|
|
17577
|
-
log(logLevelId, logLevelName, ...args) {
|
|
17578
|
-
if (logLevelId < this.settings.minLevel) {
|
|
17579
|
-
return;
|
|
17580
|
-
}
|
|
17581
|
-
const logArgs = [...this.settings.prefix, ...args];
|
|
17582
|
-
const maskedArgs = this.settings.overwrite?.mask != null
|
|
17583
|
-
? this.settings.overwrite?.mask(logArgs)
|
|
17584
|
-
: this.settings.maskValuesOfKeys != null && this.settings.maskValuesOfKeys.length > 0
|
|
17585
|
-
? this._mask(logArgs)
|
|
17586
|
-
: logArgs;
|
|
17587
|
-
const thisLogObj = this.logObj != null ? this._recursiveCloneAndExecuteFunctions(this.logObj) : undefined;
|
|
17588
|
-
const logObj = this.settings.overwrite?.toLogObj != null ? this.settings.overwrite?.toLogObj(maskedArgs, thisLogObj) : this._toLogObj(maskedArgs, thisLogObj);
|
|
17589
|
-
const logObjWithMeta = this.settings.overwrite?.addMeta != null
|
|
17590
|
-
? this.settings.overwrite?.addMeta(logObj, logLevelId, logLevelName)
|
|
17591
|
-
: this._addMetaToLogObj(logObj, logLevelId, logLevelName);
|
|
17592
|
-
let logMetaMarkup;
|
|
17593
|
-
let logArgsAndErrorsMarkup = undefined;
|
|
17594
|
-
if (this.settings.overwrite?.formatMeta != null) {
|
|
17595
|
-
logMetaMarkup = this.settings.overwrite?.formatMeta(logObjWithMeta?.[this.settings.metaProperty]);
|
|
17596
|
-
}
|
|
17597
|
-
if (this.settings.overwrite?.formatLogObj != null) {
|
|
17598
|
-
logArgsAndErrorsMarkup = this.settings.overwrite?.formatLogObj(maskedArgs, this.settings);
|
|
17599
|
-
}
|
|
17600
|
-
if (this.settings.type === "pretty") {
|
|
17601
|
-
logMetaMarkup = logMetaMarkup ?? this._prettyFormatLogObjMeta(logObjWithMeta?.[this.settings.metaProperty]);
|
|
17602
|
-
logArgsAndErrorsMarkup = logArgsAndErrorsMarkup ?? this.runtime.prettyFormatLogObj(maskedArgs, this.settings);
|
|
17603
|
-
}
|
|
17604
|
-
if (logMetaMarkup != null && logArgsAndErrorsMarkup != null) {
|
|
17605
|
-
this.settings.overwrite?.transportFormatted != null
|
|
17606
|
-
? this.settings.overwrite?.transportFormatted(logMetaMarkup, logArgsAndErrorsMarkup.args, logArgsAndErrorsMarkup.errors, this.settings)
|
|
17607
|
-
: this.runtime.transportFormatted(logMetaMarkup, logArgsAndErrorsMarkup.args, logArgsAndErrorsMarkup.errors, this.settings);
|
|
17608
|
-
}
|
|
17609
|
-
else {
|
|
17610
|
-
this.settings.overwrite?.transportJSON != null
|
|
17611
|
-
? this.settings.overwrite?.transportJSON(logObjWithMeta)
|
|
17612
|
-
: this.settings.type !== "hidden"
|
|
17613
|
-
? this.runtime.transportJSON(logObjWithMeta)
|
|
17614
|
-
: undefined;
|
|
17615
|
-
}
|
|
17616
|
-
if (this.settings.attachedTransports != null && this.settings.attachedTransports.length > 0) {
|
|
17617
|
-
this.settings.attachedTransports.forEach((transportLogger) => {
|
|
17618
|
-
transportLogger(logObjWithMeta);
|
|
17619
|
-
});
|
|
17620
|
-
}
|
|
17621
|
-
return logObjWithMeta;
|
|
17622
|
-
}
|
|
17623
|
-
attachTransport(transportLogger) {
|
|
17624
|
-
this.settings.attachedTransports.push(transportLogger);
|
|
17625
|
-
}
|
|
17626
|
-
getSubLogger(settings, logObj) {
|
|
17627
|
-
const subLoggerSettings = {
|
|
17628
|
-
...this.settings,
|
|
17629
|
-
...settings,
|
|
17630
|
-
parentNames: this.settings?.parentNames != null && this.settings?.name != null
|
|
17631
|
-
? [...this.settings.parentNames, this.settings.name]
|
|
17632
|
-
: this.settings?.name != null
|
|
17633
|
-
? [this.settings.name]
|
|
17634
|
-
: undefined,
|
|
17635
|
-
prefix: [...this.settings.prefix, ...(settings?.prefix ?? [])],
|
|
17636
|
-
};
|
|
17637
|
-
const subLogger = new this.constructor(subLoggerSettings, logObj ?? this.logObj, this.stackDepthLevel);
|
|
17638
|
-
return subLogger;
|
|
17639
|
-
}
|
|
17640
|
-
_mask(args) {
|
|
17641
|
-
const maskValuesOfKeys = this.settings.maskValuesOfKeysCaseInsensitive !== true ? this.settings.maskValuesOfKeys : this.settings.maskValuesOfKeys.map((key) => key.toLowerCase());
|
|
17642
|
-
return args?.map((arg) => {
|
|
17643
|
-
return this._recursiveCloneAndMaskValuesOfKeys(arg, maskValuesOfKeys);
|
|
17644
|
-
});
|
|
17645
|
-
}
|
|
17646
|
-
_recursiveCloneAndMaskValuesOfKeys(source, keys, seen = []) {
|
|
17647
|
-
if (seen.includes(source)) {
|
|
17648
|
-
return { ...source };
|
|
17649
|
-
}
|
|
17650
|
-
if (typeof source === "object" && source !== null) {
|
|
17651
|
-
seen.push(source);
|
|
17652
|
-
}
|
|
17653
|
-
if (this.runtime.isError(source) || this.runtime.isBuffer(source)) {
|
|
17654
|
-
return source;
|
|
17655
|
-
}
|
|
17656
|
-
else if (source instanceof Map) {
|
|
17657
|
-
return new Map(source);
|
|
17658
|
-
}
|
|
17659
|
-
else if (source instanceof Set) {
|
|
17660
|
-
return new Set(source);
|
|
17661
|
-
}
|
|
17662
|
-
else if (Array.isArray(source)) {
|
|
17663
|
-
return source.map((item) => this._recursiveCloneAndMaskValuesOfKeys(item, keys, seen));
|
|
17664
|
-
}
|
|
17665
|
-
else if (source instanceof Date) {
|
|
17666
|
-
return new Date(source.getTime());
|
|
17667
|
-
}
|
|
17668
|
-
else if (source instanceof URL) {
|
|
17669
|
-
return urlToObject(source);
|
|
17670
|
-
}
|
|
17671
|
-
else if (source !== null && typeof source === "object") {
|
|
17672
|
-
const baseObject = this.runtime.isError(source) ? this._cloneError(source) : Object.create(Object.getPrototypeOf(source));
|
|
17673
|
-
return Object.getOwnPropertyNames(source).reduce((o, prop) => {
|
|
17674
|
-
o[prop] = keys.includes(this.settings?.maskValuesOfKeysCaseInsensitive !== true ? prop : prop.toLowerCase())
|
|
17675
|
-
? this.settings.maskPlaceholder
|
|
17676
|
-
: (() => {
|
|
17677
|
-
try {
|
|
17678
|
-
return this._recursiveCloneAndMaskValuesOfKeys(source[prop], keys, seen);
|
|
17679
|
-
}
|
|
17680
|
-
catch (e) {
|
|
17681
|
-
return null;
|
|
17682
|
-
}
|
|
17683
|
-
})();
|
|
17684
|
-
return o;
|
|
17685
|
-
}, baseObject);
|
|
17686
|
-
}
|
|
17687
|
-
else {
|
|
17688
|
-
if (typeof source === "string") {
|
|
17689
|
-
let modifiedSource = source;
|
|
17690
|
-
for (const regEx of this.settings?.maskValuesRegEx || []) {
|
|
17691
|
-
modifiedSource = modifiedSource.replace(regEx, this.settings?.maskPlaceholder || "");
|
|
17692
|
-
}
|
|
17693
|
-
return modifiedSource;
|
|
17694
|
-
}
|
|
17695
|
-
return source;
|
|
17696
|
-
}
|
|
17697
|
-
}
|
|
17698
|
-
_recursiveCloneAndExecuteFunctions(source, seen = []) {
|
|
17699
|
-
if (this.isObjectOrArray(source) && seen.includes(source)) {
|
|
17700
|
-
return this.shallowCopy(source);
|
|
17701
|
-
}
|
|
17702
|
-
if (this.isObjectOrArray(source)) {
|
|
17703
|
-
seen.push(source);
|
|
17704
|
-
}
|
|
17705
|
-
if (Array.isArray(source)) {
|
|
17706
|
-
return source.map((item) => this._recursiveCloneAndExecuteFunctions(item, seen));
|
|
17707
|
-
}
|
|
17708
|
-
else if (source instanceof Date) {
|
|
17709
|
-
return new Date(source.getTime());
|
|
17710
|
-
}
|
|
17711
|
-
else if (this.isObject(source)) {
|
|
17712
|
-
return Object.getOwnPropertyNames(source).reduce((o, prop) => {
|
|
17713
|
-
const descriptor = Object.getOwnPropertyDescriptor(source, prop);
|
|
17714
|
-
if (descriptor) {
|
|
17715
|
-
Object.defineProperty(o, prop, descriptor);
|
|
17716
|
-
const value = source[prop];
|
|
17717
|
-
o[prop] = typeof value === "function" ? value() : this._recursiveCloneAndExecuteFunctions(value, seen);
|
|
17718
|
-
}
|
|
17719
|
-
return o;
|
|
17720
|
-
}, Object.create(Object.getPrototypeOf(source)));
|
|
17721
|
-
}
|
|
17722
|
-
else {
|
|
17723
|
-
return source;
|
|
17724
|
-
}
|
|
17725
|
-
}
|
|
17726
|
-
isObjectOrArray(value) {
|
|
17727
|
-
return typeof value === "object" && value !== null;
|
|
17728
|
-
}
|
|
17729
|
-
isObject(value) {
|
|
17730
|
-
return typeof value === "object" && !Array.isArray(value) && value !== null;
|
|
17731
|
-
}
|
|
17732
|
-
shallowCopy(source) {
|
|
17733
|
-
if (Array.isArray(source)) {
|
|
17734
|
-
return [...source];
|
|
17735
|
-
}
|
|
17736
|
-
else {
|
|
17737
|
-
return { ...source };
|
|
17738
|
-
}
|
|
17739
|
-
}
|
|
17740
|
-
_toLogObj(args, clonedLogObj = {}) {
|
|
17741
|
-
args = args?.map((arg) => (this.runtime.isError(arg) ? this._toErrorObject(arg) : arg));
|
|
17742
|
-
if (this.settings.argumentsArrayName == null) {
|
|
17743
|
-
if (args.length === 1 && !Array.isArray(args[0]) && this.runtime.isBuffer(args[0]) !== true && !(args[0] instanceof Date)) {
|
|
17744
|
-
clonedLogObj = typeof args[0] === "object" && args[0] != null ? { ...args[0], ...clonedLogObj } : { 0: args[0], ...clonedLogObj };
|
|
17745
|
-
}
|
|
17746
|
-
else {
|
|
17747
|
-
clonedLogObj = { ...clonedLogObj, ...args };
|
|
17748
|
-
}
|
|
17749
|
-
}
|
|
17750
|
-
else {
|
|
17751
|
-
clonedLogObj = {
|
|
17752
|
-
...clonedLogObj,
|
|
17753
|
-
[this.settings.argumentsArrayName]: args,
|
|
17754
|
-
};
|
|
17755
|
-
}
|
|
17756
|
-
return clonedLogObj;
|
|
17757
|
-
}
|
|
17758
|
-
_cloneError(error) {
|
|
17759
|
-
const cloned = new error.constructor();
|
|
17760
|
-
Object.getOwnPropertyNames(error).forEach((key) => {
|
|
17761
|
-
cloned[key] = error[key];
|
|
17762
|
-
});
|
|
17763
|
-
return cloned;
|
|
17764
|
-
}
|
|
17765
|
-
_toErrorObject(error) {
|
|
17766
|
-
return {
|
|
17767
|
-
nativeError: error,
|
|
17768
|
-
name: error.name ?? "Error",
|
|
17769
|
-
message: error.message,
|
|
17770
|
-
stack: this.runtime.getErrorTrace(error),
|
|
17771
|
-
};
|
|
17772
|
-
}
|
|
17773
|
-
_addMetaToLogObj(logObj, logLevelId, logLevelName) {
|
|
17774
|
-
return {
|
|
17775
|
-
...logObj,
|
|
17776
|
-
[this.settings.metaProperty]: this.runtime.getMeta(logLevelId, logLevelName, this.stackDepthLevel, this.settings.hideLogPositionForProduction, this.settings.name, this.settings.parentNames),
|
|
17777
|
-
};
|
|
17778
|
-
}
|
|
17779
|
-
_prettyFormatLogObjMeta(logObjMeta) {
|
|
17780
|
-
if (logObjMeta == null) {
|
|
17781
|
-
return "";
|
|
17782
|
-
}
|
|
17783
|
-
let template = this.settings.prettyLogTemplate;
|
|
17784
|
-
const placeholderValues = {};
|
|
17785
|
-
if (template.includes("{{yyyy}}.{{mm}}.{{dd}} {{hh}}:{{MM}}:{{ss}}:{{ms}}")) {
|
|
17786
|
-
template = template.replace("{{yyyy}}.{{mm}}.{{dd}} {{hh}}:{{MM}}:{{ss}}:{{ms}}", "{{dateIsoStr}}");
|
|
17787
|
-
}
|
|
17788
|
-
else {
|
|
17789
|
-
if (this.settings.prettyLogTimeZone === "UTC") {
|
|
17790
|
-
placeholderValues["yyyy"] = logObjMeta?.date?.getUTCFullYear() ?? "----";
|
|
17791
|
-
placeholderValues["mm"] = formatNumberAddZeros(logObjMeta?.date?.getUTCMonth(), 2, 1);
|
|
17792
|
-
placeholderValues["dd"] = formatNumberAddZeros(logObjMeta?.date?.getUTCDate(), 2);
|
|
17793
|
-
placeholderValues["hh"] = formatNumberAddZeros(logObjMeta?.date?.getUTCHours(), 2);
|
|
17794
|
-
placeholderValues["MM"] = formatNumberAddZeros(logObjMeta?.date?.getUTCMinutes(), 2);
|
|
17795
|
-
placeholderValues["ss"] = formatNumberAddZeros(logObjMeta?.date?.getUTCSeconds(), 2);
|
|
17796
|
-
placeholderValues["ms"] = formatNumberAddZeros(logObjMeta?.date?.getUTCMilliseconds(), 3);
|
|
17797
|
-
}
|
|
17798
|
-
else {
|
|
17799
|
-
placeholderValues["yyyy"] = logObjMeta?.date?.getFullYear() ?? "----";
|
|
17800
|
-
placeholderValues["mm"] = formatNumberAddZeros(logObjMeta?.date?.getMonth(), 2, 1);
|
|
17801
|
-
placeholderValues["dd"] = formatNumberAddZeros(logObjMeta?.date?.getDate(), 2);
|
|
17802
|
-
placeholderValues["hh"] = formatNumberAddZeros(logObjMeta?.date?.getHours(), 2);
|
|
17803
|
-
placeholderValues["MM"] = formatNumberAddZeros(logObjMeta?.date?.getMinutes(), 2);
|
|
17804
|
-
placeholderValues["ss"] = formatNumberAddZeros(logObjMeta?.date?.getSeconds(), 2);
|
|
17805
|
-
placeholderValues["ms"] = formatNumberAddZeros(logObjMeta?.date?.getMilliseconds(), 3);
|
|
17806
|
-
}
|
|
17807
|
-
}
|
|
17808
|
-
const dateInSettingsTimeZone = this.settings.prettyLogTimeZone === "UTC" ? logObjMeta?.date : new Date(logObjMeta?.date?.getTime() - logObjMeta?.date?.getTimezoneOffset() * 60000);
|
|
17809
|
-
placeholderValues["rawIsoStr"] = dateInSettingsTimeZone?.toISOString();
|
|
17810
|
-
placeholderValues["dateIsoStr"] = dateInSettingsTimeZone?.toISOString().replace("T", " ").replace("Z", "");
|
|
17811
|
-
placeholderValues["logLevelName"] = logObjMeta?.logLevelName;
|
|
17812
|
-
placeholderValues["fileNameWithLine"] = logObjMeta?.path?.fileNameWithLine ?? "";
|
|
17813
|
-
placeholderValues["filePathWithLine"] = logObjMeta?.path?.filePathWithLine ?? "";
|
|
17814
|
-
placeholderValues["fullFilePath"] = logObjMeta?.path?.fullFilePath ?? "";
|
|
17815
|
-
let parentNamesString = this.settings.parentNames?.join(this.settings.prettyErrorParentNamesSeparator);
|
|
17816
|
-
parentNamesString = parentNamesString != null && logObjMeta?.name != null ? parentNamesString + this.settings.prettyErrorParentNamesSeparator : undefined;
|
|
17817
|
-
placeholderValues["name"] = logObjMeta?.name != null || parentNamesString != null ? (parentNamesString ?? "") + logObjMeta?.name ?? "" : "";
|
|
17818
|
-
placeholderValues["nameWithDelimiterPrefix"] =
|
|
17819
|
-
placeholderValues["name"].length > 0 ? this.settings.prettyErrorLoggerNameDelimiter + placeholderValues["name"] : "";
|
|
17820
|
-
placeholderValues["nameWithDelimiterSuffix"] =
|
|
17821
|
-
placeholderValues["name"].length > 0 ? placeholderValues["name"] + this.settings.prettyErrorLoggerNameDelimiter : "";
|
|
17822
|
-
if (this.settings.overwrite?.addPlaceholders != null) {
|
|
17823
|
-
this.settings.overwrite?.addPlaceholders(logObjMeta, placeholderValues);
|
|
17824
|
-
}
|
|
17825
|
-
return formatTemplate(this.settings, template, placeholderValues);
|
|
17826
|
-
}
|
|
17827
|
-
}
|
|
17828
|
-
|
|
17829
|
-
class Logger extends BaseLogger {
|
|
17830
|
-
constructor(settings, logObj) {
|
|
17831
|
-
const isBrowser = typeof window !== "undefined" && typeof document !== "undefined";
|
|
17832
|
-
const isBrowserBlinkEngine = isBrowser ? window.chrome !== undefined && window.CSS !== undefined && window.CSS.supports("color", "green") : false;
|
|
17833
|
-
const isSafari = isBrowser ? /^((?!chrome|android).)*safari/i.test(navigator.userAgent) : false;
|
|
17834
|
-
settings = settings || {};
|
|
17835
|
-
settings.stylePrettyLogs = settings.stylePrettyLogs && isBrowser && !isBrowserBlinkEngine ? false : settings.stylePrettyLogs;
|
|
17836
|
-
super(settings, logObj, isSafari ? 4 : 5);
|
|
17837
|
-
}
|
|
17838
|
-
log(logLevelId, logLevelName, ...args) {
|
|
17839
|
-
return super.log(logLevelId, logLevelName, ...args);
|
|
17840
|
-
}
|
|
17841
|
-
silly(...args) {
|
|
17842
|
-
return super.log(0, "SILLY", ...args);
|
|
17843
|
-
}
|
|
17844
|
-
trace(...args) {
|
|
17845
|
-
return super.log(1, "TRACE", ...args);
|
|
17846
|
-
}
|
|
17847
|
-
debug(...args) {
|
|
17848
|
-
return super.log(2, "DEBUG", ...args);
|
|
17849
|
-
}
|
|
17850
|
-
info(...args) {
|
|
17851
|
-
return super.log(3, "INFO", ...args);
|
|
17852
|
-
}
|
|
17853
|
-
warn(...args) {
|
|
17854
|
-
return super.log(4, "WARN", ...args);
|
|
17855
|
-
}
|
|
17856
|
-
error(...args) {
|
|
17857
|
-
return super.log(5, "ERROR", ...args);
|
|
17858
|
-
}
|
|
17859
|
-
fatal(...args) {
|
|
17860
|
-
return super.log(6, "FATAL", ...args);
|
|
17861
|
-
}
|
|
17862
|
-
getSubLogger(settings, logObj) {
|
|
17863
|
-
return super.getSubLogger(settings, logObj);
|
|
17864
|
-
}
|
|
17865
|
-
}
|
|
17866
|
-
|
|
17867
|
-
// Get package scope & name from package.json.
|
|
17868
|
-
const npmPackageRegex = /^(?:(?<packageScope>@[a-z0-9-~][a-z0-9-._~]*)\/)?(?<packageName>[a-z0-9-~][a-z0-9-._~]*)$/;
|
|
17869
|
-
const { packageScope, packageName } = (process.env.npm_package_name?.match(npmPackageRegex)?.groups ?? {});
|
|
17870
|
-
|
|
17871
|
-
// These are the presefined tslog log levels. You can specify
|
|
17872
|
-
// LOG_LEVEL by any of the keys or values defined below.
|
|
17873
|
-
const logLevels = {
|
|
17874
|
-
silly: 0,
|
|
17875
|
-
trace: 1,
|
|
17876
|
-
debug: 2,
|
|
17877
|
-
info: 3,
|
|
17878
|
-
warn: 4,
|
|
17879
|
-
error: 5,
|
|
17880
|
-
fatal: 6,
|
|
17881
|
-
};
|
|
17882
|
-
const integerLogLevel = parseInt(process.env.LOG_LEVEL ?? '');
|
|
17883
|
-
const resolvedLogLevel = Number.isNaN(integerLogLevel)
|
|
17884
|
-
? logLevels[(process.env.LOG_LEVEL ?? '').toLowerCase()]
|
|
17885
|
-
: integerLogLevel;
|
|
17886
|
-
// Set your tslog instance options here! By default, logs are suppressed if LOG_LEVEL is invalid or undefined.
|
|
17887
|
-
// See https://tslog.js.org for more info.
|
|
17888
|
-
const logger = new Logger({
|
|
17889
|
-
hideLogPositionForProduction: true,
|
|
17890
|
-
minLevel: resolvedLogLevel,
|
|
17891
|
-
name: packageName,
|
|
17892
|
-
type: resolvedLogLevel === undefined ? 'hidden' : 'pretty',
|
|
17893
|
-
});
|
|
17894
|
-
|
|
17895
17269
|
var _JsonMap_instances, _JsonMap_transform, _JsonMap_resolvePath;
|
|
17896
17270
|
// The transformation process leverages JSON.stringify and JSON.parse to eliminate circular references.
|
|
17897
17271
|
const getJsonFns = () => {
|
|
@@ -17946,17 +17320,17 @@ _JsonMap_instances = new WeakSet(), _JsonMap_transform =
|
|
|
17946
17320
|
* Recursive function to handle transformations.
|
|
17947
17321
|
*/
|
|
17948
17322
|
async function _JsonMap_transform(node, input, output, path = '') {
|
|
17949
|
-
|
|
17323
|
+
console.debug('#transform params:\n', { node, input, output, path });
|
|
17950
17324
|
// Checks if the current node is an object and has only a '$' key
|
|
17951
17325
|
if (node instanceof Object && _.size(node) === 1 && '$' in node) {
|
|
17952
17326
|
// Retrieves the transformations to be applied (can be an array or a single object)
|
|
17953
17327
|
const transformations = _.castArray(node.$);
|
|
17954
|
-
|
|
17328
|
+
console.debug('transformations:\n', transformations);
|
|
17955
17329
|
// Array to store the results of the transformations
|
|
17956
17330
|
const results = [];
|
|
17957
17331
|
// Iterates over each transformation
|
|
17958
17332
|
for (const transformation of transformations) {
|
|
17959
|
-
|
|
17333
|
+
console.debug('processing transformation:\n', transformation);
|
|
17960
17334
|
// Resolves the object path for the transformation
|
|
17961
17335
|
const { obj: methodObj, path: methodPath } = __classPrivateFieldGet(this, _JsonMap_instances, "m", _JsonMap_resolvePath).call(this, transformation.method, results);
|
|
17962
17336
|
// Resolves the parameter paths for the transformation
|
|
@@ -17968,16 +17342,16 @@ async function _JsonMap_transform(node, input, output, path = '') {
|
|
|
17968
17342
|
: paramObj
|
|
17969
17343
|
: paramPath;
|
|
17970
17344
|
});
|
|
17971
|
-
|
|
17345
|
+
console.debug('resolved transformation params:\n', params);
|
|
17972
17346
|
// Calls the specified method on the resolved object with the resolved parameters
|
|
17973
17347
|
const result = (await _.invoke(methodObj, methodPath, ...params));
|
|
17974
|
-
|
|
17348
|
+
console.debug('transformation result:\n', result);
|
|
17975
17349
|
// Stores the result of the transformation
|
|
17976
17350
|
results.unshift(result);
|
|
17977
17351
|
}
|
|
17978
17352
|
// Sets the output at the specified path to the last result of the transformations & returns.
|
|
17979
17353
|
_.set(output, path, results[0]);
|
|
17980
|
-
|
|
17354
|
+
console.debug('updated output:\n', output);
|
|
17981
17355
|
return results[0];
|
|
17982
17356
|
}
|
|
17983
17357
|
// Checks if the current node is an object
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
import { webcrypto } from 'node:crypto';
|
|
2
|
-
import { hostname } from 'os';
|
|
3
|
-
import { normalize } from 'path';
|
|
4
|
-
import { types, formatWithOptions } from 'util';
|
|
5
2
|
|
|
6
3
|
/******************************************************************************
|
|
7
4
|
Copyright (c) Microsoft Corporation.
|
|
@@ -17267,629 +17264,6 @@ function nanoid(size = 21) {
|
|
|
17267
17264
|
return id
|
|
17268
17265
|
}
|
|
17269
17266
|
|
|
17270
|
-
const prettyLogStyles = {
|
|
17271
|
-
reset: [0, 0],
|
|
17272
|
-
bold: [1, 22],
|
|
17273
|
-
dim: [2, 22],
|
|
17274
|
-
italic: [3, 23],
|
|
17275
|
-
underline: [4, 24],
|
|
17276
|
-
overline: [53, 55],
|
|
17277
|
-
inverse: [7, 27],
|
|
17278
|
-
hidden: [8, 28],
|
|
17279
|
-
strikethrough: [9, 29],
|
|
17280
|
-
black: [30, 39],
|
|
17281
|
-
red: [31, 39],
|
|
17282
|
-
green: [32, 39],
|
|
17283
|
-
yellow: [33, 39],
|
|
17284
|
-
blue: [34, 39],
|
|
17285
|
-
magenta: [35, 39],
|
|
17286
|
-
cyan: [36, 39],
|
|
17287
|
-
white: [37, 39],
|
|
17288
|
-
blackBright: [90, 39],
|
|
17289
|
-
redBright: [91, 39],
|
|
17290
|
-
greenBright: [92, 39],
|
|
17291
|
-
yellowBright: [93, 39],
|
|
17292
|
-
blueBright: [94, 39],
|
|
17293
|
-
magentaBright: [95, 39],
|
|
17294
|
-
cyanBright: [96, 39],
|
|
17295
|
-
whiteBright: [97, 39],
|
|
17296
|
-
bgBlack: [40, 49],
|
|
17297
|
-
bgRed: [41, 49],
|
|
17298
|
-
bgGreen: [42, 49],
|
|
17299
|
-
bgYellow: [43, 49],
|
|
17300
|
-
bgBlue: [44, 49],
|
|
17301
|
-
bgMagenta: [45, 49],
|
|
17302
|
-
bgCyan: [46, 49],
|
|
17303
|
-
bgWhite: [47, 49],
|
|
17304
|
-
bgBlackBright: [100, 49],
|
|
17305
|
-
bgRedBright: [101, 49],
|
|
17306
|
-
bgGreenBright: [102, 49],
|
|
17307
|
-
bgYellowBright: [103, 49],
|
|
17308
|
-
bgBlueBright: [104, 49],
|
|
17309
|
-
bgMagentaBright: [105, 49],
|
|
17310
|
-
bgCyanBright: [106, 49],
|
|
17311
|
-
bgWhiteBright: [107, 49],
|
|
17312
|
-
};
|
|
17313
|
-
|
|
17314
|
-
function formatTemplate(settings, template, values, hideUnsetPlaceholder = false) {
|
|
17315
|
-
const templateString = String(template);
|
|
17316
|
-
const ansiColorWrap = (placeholderValue, code) => `\u001b[${code[0]}m${placeholderValue}\u001b[${code[1]}m`;
|
|
17317
|
-
const styleWrap = (value, style) => {
|
|
17318
|
-
if (style != null && typeof style === "string") {
|
|
17319
|
-
return ansiColorWrap(value, prettyLogStyles[style]);
|
|
17320
|
-
}
|
|
17321
|
-
else if (style != null && Array.isArray(style)) {
|
|
17322
|
-
return style.reduce((prevValue, thisStyle) => styleWrap(prevValue, thisStyle), value);
|
|
17323
|
-
}
|
|
17324
|
-
else {
|
|
17325
|
-
if (style != null && style[value.trim()] != null) {
|
|
17326
|
-
return styleWrap(value, style[value.trim()]);
|
|
17327
|
-
}
|
|
17328
|
-
else if (style != null && style["*"] != null) {
|
|
17329
|
-
return styleWrap(value, style["*"]);
|
|
17330
|
-
}
|
|
17331
|
-
else {
|
|
17332
|
-
return value;
|
|
17333
|
-
}
|
|
17334
|
-
}
|
|
17335
|
-
};
|
|
17336
|
-
const defaultStyle = null;
|
|
17337
|
-
return templateString.replace(/{{(.+?)}}/g, (_, placeholder) => {
|
|
17338
|
-
const value = values[placeholder] != null ? String(values[placeholder]) : hideUnsetPlaceholder ? "" : _;
|
|
17339
|
-
return settings.stylePrettyLogs
|
|
17340
|
-
? styleWrap(value, settings?.prettyLogStyles?.[placeholder] ?? defaultStyle) + ansiColorWrap("", prettyLogStyles.reset)
|
|
17341
|
-
: value;
|
|
17342
|
-
});
|
|
17343
|
-
}
|
|
17344
|
-
|
|
17345
|
-
function formatNumberAddZeros(value, digits = 2, addNumber = 0) {
|
|
17346
|
-
if (value != null && isNaN(value)) {
|
|
17347
|
-
return "";
|
|
17348
|
-
}
|
|
17349
|
-
value = value != null ? value + addNumber : value;
|
|
17350
|
-
return digits === 2
|
|
17351
|
-
? value == null
|
|
17352
|
-
? "--"
|
|
17353
|
-
: value < 10
|
|
17354
|
-
? "0" + value
|
|
17355
|
-
: value.toString()
|
|
17356
|
-
: value == null
|
|
17357
|
-
? "---"
|
|
17358
|
-
: value < 10
|
|
17359
|
-
? "00" + value
|
|
17360
|
-
: value < 100
|
|
17361
|
-
? "0" + value
|
|
17362
|
-
: value.toString();
|
|
17363
|
-
}
|
|
17364
|
-
|
|
17365
|
-
function urlToObject(url) {
|
|
17366
|
-
return {
|
|
17367
|
-
href: url.href,
|
|
17368
|
-
protocol: url.protocol,
|
|
17369
|
-
username: url.username,
|
|
17370
|
-
password: url.password,
|
|
17371
|
-
host: url.host,
|
|
17372
|
-
hostname: url.hostname,
|
|
17373
|
-
port: url.port,
|
|
17374
|
-
pathname: url.pathname,
|
|
17375
|
-
search: url.search,
|
|
17376
|
-
searchParams: [...url.searchParams].map(([key, value]) => ({ key, value })),
|
|
17377
|
-
hash: url.hash,
|
|
17378
|
-
origin: url.origin,
|
|
17379
|
-
};
|
|
17380
|
-
}
|
|
17381
|
-
|
|
17382
|
-
var Runtime = {
|
|
17383
|
-
getCallerStackFrame,
|
|
17384
|
-
getErrorTrace,
|
|
17385
|
-
getMeta,
|
|
17386
|
-
transportJSON,
|
|
17387
|
-
transportFormatted,
|
|
17388
|
-
isBuffer,
|
|
17389
|
-
isError,
|
|
17390
|
-
prettyFormatLogObj,
|
|
17391
|
-
prettyFormatErrorObj,
|
|
17392
|
-
};
|
|
17393
|
-
const meta = {
|
|
17394
|
-
runtime: "Nodejs",
|
|
17395
|
-
runtimeVersion: process?.version,
|
|
17396
|
-
hostname: hostname ? hostname() : undefined,
|
|
17397
|
-
};
|
|
17398
|
-
function getMeta(logLevelId, logLevelName, stackDepthLevel, hideLogPositionForPerformance, name, parentNames) {
|
|
17399
|
-
return Object.assign({}, meta, {
|
|
17400
|
-
name,
|
|
17401
|
-
parentNames,
|
|
17402
|
-
date: new Date(),
|
|
17403
|
-
logLevelId,
|
|
17404
|
-
logLevelName,
|
|
17405
|
-
path: !hideLogPositionForPerformance ? getCallerStackFrame(stackDepthLevel) : undefined,
|
|
17406
|
-
});
|
|
17407
|
-
}
|
|
17408
|
-
function getCallerStackFrame(stackDepthLevel, error = Error()) {
|
|
17409
|
-
return stackLineToStackFrame(error?.stack?.split("\n")?.filter((thisLine) => thisLine.includes(" at "))?.[stackDepthLevel]);
|
|
17410
|
-
}
|
|
17411
|
-
function getErrorTrace(error) {
|
|
17412
|
-
return error?.stack?.split("\n")?.reduce((result, line) => {
|
|
17413
|
-
if (line.includes(" at ")) {
|
|
17414
|
-
result.push(stackLineToStackFrame(line));
|
|
17415
|
-
}
|
|
17416
|
-
return result;
|
|
17417
|
-
}, []);
|
|
17418
|
-
}
|
|
17419
|
-
function stackLineToStackFrame(line) {
|
|
17420
|
-
const pathResult = {
|
|
17421
|
-
fullFilePath: undefined,
|
|
17422
|
-
fileName: undefined,
|
|
17423
|
-
fileNameWithLine: undefined,
|
|
17424
|
-
fileColumn: undefined,
|
|
17425
|
-
fileLine: undefined,
|
|
17426
|
-
filePath: undefined,
|
|
17427
|
-
filePathWithLine: undefined,
|
|
17428
|
-
method: undefined,
|
|
17429
|
-
};
|
|
17430
|
-
if (line != null && line.includes(" at ")) {
|
|
17431
|
-
line = line.replace(/^\s+at\s+/gm, "");
|
|
17432
|
-
const errorStackLine = line.split(" (");
|
|
17433
|
-
const fullFilePath = line?.slice(-1) === ")" ? line?.match(/\(([^)]+)\)/)?.[1] : line;
|
|
17434
|
-
const pathArray = fullFilePath?.includes(":") ? fullFilePath?.replace("file://", "")?.replace(process.cwd(), "")?.split(":") : undefined;
|
|
17435
|
-
const fileColumn = pathArray?.pop();
|
|
17436
|
-
const fileLine = pathArray?.pop();
|
|
17437
|
-
const filePath = pathArray?.pop();
|
|
17438
|
-
const filePathWithLine = normalize(`${filePath}:${fileLine}`);
|
|
17439
|
-
const fileName = filePath?.split("/")?.pop();
|
|
17440
|
-
const fileNameWithLine = `${fileName}:${fileLine}`;
|
|
17441
|
-
if (filePath != null && filePath.length > 0) {
|
|
17442
|
-
pathResult.fullFilePath = fullFilePath;
|
|
17443
|
-
pathResult.fileName = fileName;
|
|
17444
|
-
pathResult.fileNameWithLine = fileNameWithLine;
|
|
17445
|
-
pathResult.fileColumn = fileColumn;
|
|
17446
|
-
pathResult.fileLine = fileLine;
|
|
17447
|
-
pathResult.filePath = filePath;
|
|
17448
|
-
pathResult.filePathWithLine = filePathWithLine;
|
|
17449
|
-
pathResult.method = errorStackLine?.[1] != null ? errorStackLine?.[0] : undefined;
|
|
17450
|
-
}
|
|
17451
|
-
}
|
|
17452
|
-
return pathResult;
|
|
17453
|
-
}
|
|
17454
|
-
function isError(e) {
|
|
17455
|
-
return types?.isNativeError != null ? types.isNativeError(e) : e instanceof Error;
|
|
17456
|
-
}
|
|
17457
|
-
function prettyFormatLogObj(maskedArgs, settings) {
|
|
17458
|
-
return maskedArgs.reduce((result, arg) => {
|
|
17459
|
-
isError(arg) ? result.errors.push(prettyFormatErrorObj(arg, settings)) : result.args.push(arg);
|
|
17460
|
-
return result;
|
|
17461
|
-
}, { args: [], errors: [] });
|
|
17462
|
-
}
|
|
17463
|
-
function prettyFormatErrorObj(error, settings) {
|
|
17464
|
-
const errorStackStr = getErrorTrace(error).map((stackFrame) => {
|
|
17465
|
-
return formatTemplate(settings, settings.prettyErrorStackTemplate, { ...stackFrame }, true);
|
|
17466
|
-
});
|
|
17467
|
-
const placeholderValuesError = {
|
|
17468
|
-
errorName: ` ${error.name} `,
|
|
17469
|
-
errorMessage: Object.getOwnPropertyNames(error)
|
|
17470
|
-
.reduce((result, key) => {
|
|
17471
|
-
if (key !== "stack") {
|
|
17472
|
-
result.push(error[key]);
|
|
17473
|
-
}
|
|
17474
|
-
return result;
|
|
17475
|
-
}, [])
|
|
17476
|
-
.join(", "),
|
|
17477
|
-
errorStack: errorStackStr.join("\n"),
|
|
17478
|
-
};
|
|
17479
|
-
return formatTemplate(settings, settings.prettyErrorTemplate, placeholderValuesError);
|
|
17480
|
-
}
|
|
17481
|
-
function transportFormatted(logMetaMarkup, logArgs, logErrors, settings) {
|
|
17482
|
-
const logErrorsStr = (logErrors.length > 0 && logArgs.length > 0 ? "\n" : "") + logErrors.join("\n");
|
|
17483
|
-
settings.prettyInspectOptions.colors = settings.stylePrettyLogs;
|
|
17484
|
-
console.log(logMetaMarkup + formatWithOptions(settings.prettyInspectOptions, ...logArgs) + logErrorsStr);
|
|
17485
|
-
}
|
|
17486
|
-
function transportJSON(json) {
|
|
17487
|
-
console.log(jsonStringifyRecursive(json));
|
|
17488
|
-
function jsonStringifyRecursive(obj) {
|
|
17489
|
-
const cache = new Set();
|
|
17490
|
-
return JSON.stringify(obj, (key, value) => {
|
|
17491
|
-
if (typeof value === "object" && value !== null) {
|
|
17492
|
-
if (cache.has(value)) {
|
|
17493
|
-
return "[Circular]";
|
|
17494
|
-
}
|
|
17495
|
-
cache.add(value);
|
|
17496
|
-
}
|
|
17497
|
-
if (typeof value === "bigint") {
|
|
17498
|
-
return `${value}`;
|
|
17499
|
-
}
|
|
17500
|
-
if (typeof value === "undefined") {
|
|
17501
|
-
return "[undefined]";
|
|
17502
|
-
}
|
|
17503
|
-
return value;
|
|
17504
|
-
});
|
|
17505
|
-
}
|
|
17506
|
-
}
|
|
17507
|
-
function isBuffer(arg) {
|
|
17508
|
-
return Buffer.isBuffer(arg);
|
|
17509
|
-
}
|
|
17510
|
-
|
|
17511
|
-
class BaseLogger {
|
|
17512
|
-
constructor(settings, logObj, stackDepthLevel = 4) {
|
|
17513
|
-
this.logObj = logObj;
|
|
17514
|
-
this.stackDepthLevel = stackDepthLevel;
|
|
17515
|
-
this.runtime = Runtime;
|
|
17516
|
-
this.settings = {
|
|
17517
|
-
type: settings?.type ?? "pretty",
|
|
17518
|
-
name: settings?.name,
|
|
17519
|
-
parentNames: settings?.parentNames,
|
|
17520
|
-
minLevel: settings?.minLevel ?? 0,
|
|
17521
|
-
argumentsArrayName: settings?.argumentsArrayName,
|
|
17522
|
-
hideLogPositionForProduction: settings?.hideLogPositionForProduction ?? false,
|
|
17523
|
-
prettyLogTemplate: settings?.prettyLogTemplate ??
|
|
17524
|
-
"{{yyyy}}.{{mm}}.{{dd}} {{hh}}:{{MM}}:{{ss}}:{{ms}}\t{{logLevelName}}\t{{filePathWithLine}}{{nameWithDelimiterPrefix}}\t",
|
|
17525
|
-
prettyErrorTemplate: settings?.prettyErrorTemplate ?? "\n{{errorName}} {{errorMessage}}\nerror stack:\n{{errorStack}}",
|
|
17526
|
-
prettyErrorStackTemplate: settings?.prettyErrorStackTemplate ?? " • {{fileName}}\t{{method}}\n\t{{filePathWithLine}}",
|
|
17527
|
-
prettyErrorParentNamesSeparator: settings?.prettyErrorParentNamesSeparator ?? ":",
|
|
17528
|
-
prettyErrorLoggerNameDelimiter: settings?.prettyErrorLoggerNameDelimiter ?? "\t",
|
|
17529
|
-
stylePrettyLogs: settings?.stylePrettyLogs ?? true,
|
|
17530
|
-
prettyLogTimeZone: settings?.prettyLogTimeZone ?? "UTC",
|
|
17531
|
-
prettyLogStyles: settings?.prettyLogStyles ?? {
|
|
17532
|
-
logLevelName: {
|
|
17533
|
-
"*": ["bold", "black", "bgWhiteBright", "dim"],
|
|
17534
|
-
SILLY: ["bold", "white"],
|
|
17535
|
-
TRACE: ["bold", "whiteBright"],
|
|
17536
|
-
DEBUG: ["bold", "green"],
|
|
17537
|
-
INFO: ["bold", "blue"],
|
|
17538
|
-
WARN: ["bold", "yellow"],
|
|
17539
|
-
ERROR: ["bold", "red"],
|
|
17540
|
-
FATAL: ["bold", "redBright"],
|
|
17541
|
-
},
|
|
17542
|
-
dateIsoStr: "white",
|
|
17543
|
-
filePathWithLine: "white",
|
|
17544
|
-
name: ["white", "bold"],
|
|
17545
|
-
nameWithDelimiterPrefix: ["white", "bold"],
|
|
17546
|
-
nameWithDelimiterSuffix: ["white", "bold"],
|
|
17547
|
-
errorName: ["bold", "bgRedBright", "whiteBright"],
|
|
17548
|
-
fileName: ["yellow"],
|
|
17549
|
-
fileNameWithLine: "white",
|
|
17550
|
-
},
|
|
17551
|
-
prettyInspectOptions: settings?.prettyInspectOptions ?? {
|
|
17552
|
-
colors: true,
|
|
17553
|
-
compact: false,
|
|
17554
|
-
depth: Infinity,
|
|
17555
|
-
},
|
|
17556
|
-
metaProperty: settings?.metaProperty ?? "_meta",
|
|
17557
|
-
maskPlaceholder: settings?.maskPlaceholder ?? "[***]",
|
|
17558
|
-
maskValuesOfKeys: settings?.maskValuesOfKeys ?? ["password"],
|
|
17559
|
-
maskValuesOfKeysCaseInsensitive: settings?.maskValuesOfKeysCaseInsensitive ?? false,
|
|
17560
|
-
maskValuesRegEx: settings?.maskValuesRegEx,
|
|
17561
|
-
prefix: [...(settings?.prefix ?? [])],
|
|
17562
|
-
attachedTransports: [...(settings?.attachedTransports ?? [])],
|
|
17563
|
-
overwrite: {
|
|
17564
|
-
mask: settings?.overwrite?.mask,
|
|
17565
|
-
toLogObj: settings?.overwrite?.toLogObj,
|
|
17566
|
-
addMeta: settings?.overwrite?.addMeta,
|
|
17567
|
-
addPlaceholders: settings?.overwrite?.addPlaceholders,
|
|
17568
|
-
formatMeta: settings?.overwrite?.formatMeta,
|
|
17569
|
-
formatLogObj: settings?.overwrite?.formatLogObj,
|
|
17570
|
-
transportFormatted: settings?.overwrite?.transportFormatted,
|
|
17571
|
-
transportJSON: settings?.overwrite?.transportJSON,
|
|
17572
|
-
},
|
|
17573
|
-
};
|
|
17574
|
-
}
|
|
17575
|
-
log(logLevelId, logLevelName, ...args) {
|
|
17576
|
-
if (logLevelId < this.settings.minLevel) {
|
|
17577
|
-
return;
|
|
17578
|
-
}
|
|
17579
|
-
const logArgs = [...this.settings.prefix, ...args];
|
|
17580
|
-
const maskedArgs = this.settings.overwrite?.mask != null
|
|
17581
|
-
? this.settings.overwrite?.mask(logArgs)
|
|
17582
|
-
: this.settings.maskValuesOfKeys != null && this.settings.maskValuesOfKeys.length > 0
|
|
17583
|
-
? this._mask(logArgs)
|
|
17584
|
-
: logArgs;
|
|
17585
|
-
const thisLogObj = this.logObj != null ? this._recursiveCloneAndExecuteFunctions(this.logObj) : undefined;
|
|
17586
|
-
const logObj = this.settings.overwrite?.toLogObj != null ? this.settings.overwrite?.toLogObj(maskedArgs, thisLogObj) : this._toLogObj(maskedArgs, thisLogObj);
|
|
17587
|
-
const logObjWithMeta = this.settings.overwrite?.addMeta != null
|
|
17588
|
-
? this.settings.overwrite?.addMeta(logObj, logLevelId, logLevelName)
|
|
17589
|
-
: this._addMetaToLogObj(logObj, logLevelId, logLevelName);
|
|
17590
|
-
let logMetaMarkup;
|
|
17591
|
-
let logArgsAndErrorsMarkup = undefined;
|
|
17592
|
-
if (this.settings.overwrite?.formatMeta != null) {
|
|
17593
|
-
logMetaMarkup = this.settings.overwrite?.formatMeta(logObjWithMeta?.[this.settings.metaProperty]);
|
|
17594
|
-
}
|
|
17595
|
-
if (this.settings.overwrite?.formatLogObj != null) {
|
|
17596
|
-
logArgsAndErrorsMarkup = this.settings.overwrite?.formatLogObj(maskedArgs, this.settings);
|
|
17597
|
-
}
|
|
17598
|
-
if (this.settings.type === "pretty") {
|
|
17599
|
-
logMetaMarkup = logMetaMarkup ?? this._prettyFormatLogObjMeta(logObjWithMeta?.[this.settings.metaProperty]);
|
|
17600
|
-
logArgsAndErrorsMarkup = logArgsAndErrorsMarkup ?? this.runtime.prettyFormatLogObj(maskedArgs, this.settings);
|
|
17601
|
-
}
|
|
17602
|
-
if (logMetaMarkup != null && logArgsAndErrorsMarkup != null) {
|
|
17603
|
-
this.settings.overwrite?.transportFormatted != null
|
|
17604
|
-
? this.settings.overwrite?.transportFormatted(logMetaMarkup, logArgsAndErrorsMarkup.args, logArgsAndErrorsMarkup.errors, this.settings)
|
|
17605
|
-
: this.runtime.transportFormatted(logMetaMarkup, logArgsAndErrorsMarkup.args, logArgsAndErrorsMarkup.errors, this.settings);
|
|
17606
|
-
}
|
|
17607
|
-
else {
|
|
17608
|
-
this.settings.overwrite?.transportJSON != null
|
|
17609
|
-
? this.settings.overwrite?.transportJSON(logObjWithMeta)
|
|
17610
|
-
: this.settings.type !== "hidden"
|
|
17611
|
-
? this.runtime.transportJSON(logObjWithMeta)
|
|
17612
|
-
: undefined;
|
|
17613
|
-
}
|
|
17614
|
-
if (this.settings.attachedTransports != null && this.settings.attachedTransports.length > 0) {
|
|
17615
|
-
this.settings.attachedTransports.forEach((transportLogger) => {
|
|
17616
|
-
transportLogger(logObjWithMeta);
|
|
17617
|
-
});
|
|
17618
|
-
}
|
|
17619
|
-
return logObjWithMeta;
|
|
17620
|
-
}
|
|
17621
|
-
attachTransport(transportLogger) {
|
|
17622
|
-
this.settings.attachedTransports.push(transportLogger);
|
|
17623
|
-
}
|
|
17624
|
-
getSubLogger(settings, logObj) {
|
|
17625
|
-
const subLoggerSettings = {
|
|
17626
|
-
...this.settings,
|
|
17627
|
-
...settings,
|
|
17628
|
-
parentNames: this.settings?.parentNames != null && this.settings?.name != null
|
|
17629
|
-
? [...this.settings.parentNames, this.settings.name]
|
|
17630
|
-
: this.settings?.name != null
|
|
17631
|
-
? [this.settings.name]
|
|
17632
|
-
: undefined,
|
|
17633
|
-
prefix: [...this.settings.prefix, ...(settings?.prefix ?? [])],
|
|
17634
|
-
};
|
|
17635
|
-
const subLogger = new this.constructor(subLoggerSettings, logObj ?? this.logObj, this.stackDepthLevel);
|
|
17636
|
-
return subLogger;
|
|
17637
|
-
}
|
|
17638
|
-
_mask(args) {
|
|
17639
|
-
const maskValuesOfKeys = this.settings.maskValuesOfKeysCaseInsensitive !== true ? this.settings.maskValuesOfKeys : this.settings.maskValuesOfKeys.map((key) => key.toLowerCase());
|
|
17640
|
-
return args?.map((arg) => {
|
|
17641
|
-
return this._recursiveCloneAndMaskValuesOfKeys(arg, maskValuesOfKeys);
|
|
17642
|
-
});
|
|
17643
|
-
}
|
|
17644
|
-
_recursiveCloneAndMaskValuesOfKeys(source, keys, seen = []) {
|
|
17645
|
-
if (seen.includes(source)) {
|
|
17646
|
-
return { ...source };
|
|
17647
|
-
}
|
|
17648
|
-
if (typeof source === "object" && source !== null) {
|
|
17649
|
-
seen.push(source);
|
|
17650
|
-
}
|
|
17651
|
-
if (this.runtime.isError(source) || this.runtime.isBuffer(source)) {
|
|
17652
|
-
return source;
|
|
17653
|
-
}
|
|
17654
|
-
else if (source instanceof Map) {
|
|
17655
|
-
return new Map(source);
|
|
17656
|
-
}
|
|
17657
|
-
else if (source instanceof Set) {
|
|
17658
|
-
return new Set(source);
|
|
17659
|
-
}
|
|
17660
|
-
else if (Array.isArray(source)) {
|
|
17661
|
-
return source.map((item) => this._recursiveCloneAndMaskValuesOfKeys(item, keys, seen));
|
|
17662
|
-
}
|
|
17663
|
-
else if (source instanceof Date) {
|
|
17664
|
-
return new Date(source.getTime());
|
|
17665
|
-
}
|
|
17666
|
-
else if (source instanceof URL) {
|
|
17667
|
-
return urlToObject(source);
|
|
17668
|
-
}
|
|
17669
|
-
else if (source !== null && typeof source === "object") {
|
|
17670
|
-
const baseObject = this.runtime.isError(source) ? this._cloneError(source) : Object.create(Object.getPrototypeOf(source));
|
|
17671
|
-
return Object.getOwnPropertyNames(source).reduce((o, prop) => {
|
|
17672
|
-
o[prop] = keys.includes(this.settings?.maskValuesOfKeysCaseInsensitive !== true ? prop : prop.toLowerCase())
|
|
17673
|
-
? this.settings.maskPlaceholder
|
|
17674
|
-
: (() => {
|
|
17675
|
-
try {
|
|
17676
|
-
return this._recursiveCloneAndMaskValuesOfKeys(source[prop], keys, seen);
|
|
17677
|
-
}
|
|
17678
|
-
catch (e) {
|
|
17679
|
-
return null;
|
|
17680
|
-
}
|
|
17681
|
-
})();
|
|
17682
|
-
return o;
|
|
17683
|
-
}, baseObject);
|
|
17684
|
-
}
|
|
17685
|
-
else {
|
|
17686
|
-
if (typeof source === "string") {
|
|
17687
|
-
let modifiedSource = source;
|
|
17688
|
-
for (const regEx of this.settings?.maskValuesRegEx || []) {
|
|
17689
|
-
modifiedSource = modifiedSource.replace(regEx, this.settings?.maskPlaceholder || "");
|
|
17690
|
-
}
|
|
17691
|
-
return modifiedSource;
|
|
17692
|
-
}
|
|
17693
|
-
return source;
|
|
17694
|
-
}
|
|
17695
|
-
}
|
|
17696
|
-
_recursiveCloneAndExecuteFunctions(source, seen = []) {
|
|
17697
|
-
if (this.isObjectOrArray(source) && seen.includes(source)) {
|
|
17698
|
-
return this.shallowCopy(source);
|
|
17699
|
-
}
|
|
17700
|
-
if (this.isObjectOrArray(source)) {
|
|
17701
|
-
seen.push(source);
|
|
17702
|
-
}
|
|
17703
|
-
if (Array.isArray(source)) {
|
|
17704
|
-
return source.map((item) => this._recursiveCloneAndExecuteFunctions(item, seen));
|
|
17705
|
-
}
|
|
17706
|
-
else if (source instanceof Date) {
|
|
17707
|
-
return new Date(source.getTime());
|
|
17708
|
-
}
|
|
17709
|
-
else if (this.isObject(source)) {
|
|
17710
|
-
return Object.getOwnPropertyNames(source).reduce((o, prop) => {
|
|
17711
|
-
const descriptor = Object.getOwnPropertyDescriptor(source, prop);
|
|
17712
|
-
if (descriptor) {
|
|
17713
|
-
Object.defineProperty(o, prop, descriptor);
|
|
17714
|
-
const value = source[prop];
|
|
17715
|
-
o[prop] = typeof value === "function" ? value() : this._recursiveCloneAndExecuteFunctions(value, seen);
|
|
17716
|
-
}
|
|
17717
|
-
return o;
|
|
17718
|
-
}, Object.create(Object.getPrototypeOf(source)));
|
|
17719
|
-
}
|
|
17720
|
-
else {
|
|
17721
|
-
return source;
|
|
17722
|
-
}
|
|
17723
|
-
}
|
|
17724
|
-
isObjectOrArray(value) {
|
|
17725
|
-
return typeof value === "object" && value !== null;
|
|
17726
|
-
}
|
|
17727
|
-
isObject(value) {
|
|
17728
|
-
return typeof value === "object" && !Array.isArray(value) && value !== null;
|
|
17729
|
-
}
|
|
17730
|
-
shallowCopy(source) {
|
|
17731
|
-
if (Array.isArray(source)) {
|
|
17732
|
-
return [...source];
|
|
17733
|
-
}
|
|
17734
|
-
else {
|
|
17735
|
-
return { ...source };
|
|
17736
|
-
}
|
|
17737
|
-
}
|
|
17738
|
-
_toLogObj(args, clonedLogObj = {}) {
|
|
17739
|
-
args = args?.map((arg) => (this.runtime.isError(arg) ? this._toErrorObject(arg) : arg));
|
|
17740
|
-
if (this.settings.argumentsArrayName == null) {
|
|
17741
|
-
if (args.length === 1 && !Array.isArray(args[0]) && this.runtime.isBuffer(args[0]) !== true && !(args[0] instanceof Date)) {
|
|
17742
|
-
clonedLogObj = typeof args[0] === "object" && args[0] != null ? { ...args[0], ...clonedLogObj } : { 0: args[0], ...clonedLogObj };
|
|
17743
|
-
}
|
|
17744
|
-
else {
|
|
17745
|
-
clonedLogObj = { ...clonedLogObj, ...args };
|
|
17746
|
-
}
|
|
17747
|
-
}
|
|
17748
|
-
else {
|
|
17749
|
-
clonedLogObj = {
|
|
17750
|
-
...clonedLogObj,
|
|
17751
|
-
[this.settings.argumentsArrayName]: args,
|
|
17752
|
-
};
|
|
17753
|
-
}
|
|
17754
|
-
return clonedLogObj;
|
|
17755
|
-
}
|
|
17756
|
-
_cloneError(error) {
|
|
17757
|
-
const cloned = new error.constructor();
|
|
17758
|
-
Object.getOwnPropertyNames(error).forEach((key) => {
|
|
17759
|
-
cloned[key] = error[key];
|
|
17760
|
-
});
|
|
17761
|
-
return cloned;
|
|
17762
|
-
}
|
|
17763
|
-
_toErrorObject(error) {
|
|
17764
|
-
return {
|
|
17765
|
-
nativeError: error,
|
|
17766
|
-
name: error.name ?? "Error",
|
|
17767
|
-
message: error.message,
|
|
17768
|
-
stack: this.runtime.getErrorTrace(error),
|
|
17769
|
-
};
|
|
17770
|
-
}
|
|
17771
|
-
_addMetaToLogObj(logObj, logLevelId, logLevelName) {
|
|
17772
|
-
return {
|
|
17773
|
-
...logObj,
|
|
17774
|
-
[this.settings.metaProperty]: this.runtime.getMeta(logLevelId, logLevelName, this.stackDepthLevel, this.settings.hideLogPositionForProduction, this.settings.name, this.settings.parentNames),
|
|
17775
|
-
};
|
|
17776
|
-
}
|
|
17777
|
-
_prettyFormatLogObjMeta(logObjMeta) {
|
|
17778
|
-
if (logObjMeta == null) {
|
|
17779
|
-
return "";
|
|
17780
|
-
}
|
|
17781
|
-
let template = this.settings.prettyLogTemplate;
|
|
17782
|
-
const placeholderValues = {};
|
|
17783
|
-
if (template.includes("{{yyyy}}.{{mm}}.{{dd}} {{hh}}:{{MM}}:{{ss}}:{{ms}}")) {
|
|
17784
|
-
template = template.replace("{{yyyy}}.{{mm}}.{{dd}} {{hh}}:{{MM}}:{{ss}}:{{ms}}", "{{dateIsoStr}}");
|
|
17785
|
-
}
|
|
17786
|
-
else {
|
|
17787
|
-
if (this.settings.prettyLogTimeZone === "UTC") {
|
|
17788
|
-
placeholderValues["yyyy"] = logObjMeta?.date?.getUTCFullYear() ?? "----";
|
|
17789
|
-
placeholderValues["mm"] = formatNumberAddZeros(logObjMeta?.date?.getUTCMonth(), 2, 1);
|
|
17790
|
-
placeholderValues["dd"] = formatNumberAddZeros(logObjMeta?.date?.getUTCDate(), 2);
|
|
17791
|
-
placeholderValues["hh"] = formatNumberAddZeros(logObjMeta?.date?.getUTCHours(), 2);
|
|
17792
|
-
placeholderValues["MM"] = formatNumberAddZeros(logObjMeta?.date?.getUTCMinutes(), 2);
|
|
17793
|
-
placeholderValues["ss"] = formatNumberAddZeros(logObjMeta?.date?.getUTCSeconds(), 2);
|
|
17794
|
-
placeholderValues["ms"] = formatNumberAddZeros(logObjMeta?.date?.getUTCMilliseconds(), 3);
|
|
17795
|
-
}
|
|
17796
|
-
else {
|
|
17797
|
-
placeholderValues["yyyy"] = logObjMeta?.date?.getFullYear() ?? "----";
|
|
17798
|
-
placeholderValues["mm"] = formatNumberAddZeros(logObjMeta?.date?.getMonth(), 2, 1);
|
|
17799
|
-
placeholderValues["dd"] = formatNumberAddZeros(logObjMeta?.date?.getDate(), 2);
|
|
17800
|
-
placeholderValues["hh"] = formatNumberAddZeros(logObjMeta?.date?.getHours(), 2);
|
|
17801
|
-
placeholderValues["MM"] = formatNumberAddZeros(logObjMeta?.date?.getMinutes(), 2);
|
|
17802
|
-
placeholderValues["ss"] = formatNumberAddZeros(logObjMeta?.date?.getSeconds(), 2);
|
|
17803
|
-
placeholderValues["ms"] = formatNumberAddZeros(logObjMeta?.date?.getMilliseconds(), 3);
|
|
17804
|
-
}
|
|
17805
|
-
}
|
|
17806
|
-
const dateInSettingsTimeZone = this.settings.prettyLogTimeZone === "UTC" ? logObjMeta?.date : new Date(logObjMeta?.date?.getTime() - logObjMeta?.date?.getTimezoneOffset() * 60000);
|
|
17807
|
-
placeholderValues["rawIsoStr"] = dateInSettingsTimeZone?.toISOString();
|
|
17808
|
-
placeholderValues["dateIsoStr"] = dateInSettingsTimeZone?.toISOString().replace("T", " ").replace("Z", "");
|
|
17809
|
-
placeholderValues["logLevelName"] = logObjMeta?.logLevelName;
|
|
17810
|
-
placeholderValues["fileNameWithLine"] = logObjMeta?.path?.fileNameWithLine ?? "";
|
|
17811
|
-
placeholderValues["filePathWithLine"] = logObjMeta?.path?.filePathWithLine ?? "";
|
|
17812
|
-
placeholderValues["fullFilePath"] = logObjMeta?.path?.fullFilePath ?? "";
|
|
17813
|
-
let parentNamesString = this.settings.parentNames?.join(this.settings.prettyErrorParentNamesSeparator);
|
|
17814
|
-
parentNamesString = parentNamesString != null && logObjMeta?.name != null ? parentNamesString + this.settings.prettyErrorParentNamesSeparator : undefined;
|
|
17815
|
-
placeholderValues["name"] = logObjMeta?.name != null || parentNamesString != null ? (parentNamesString ?? "") + logObjMeta?.name ?? "" : "";
|
|
17816
|
-
placeholderValues["nameWithDelimiterPrefix"] =
|
|
17817
|
-
placeholderValues["name"].length > 0 ? this.settings.prettyErrorLoggerNameDelimiter + placeholderValues["name"] : "";
|
|
17818
|
-
placeholderValues["nameWithDelimiterSuffix"] =
|
|
17819
|
-
placeholderValues["name"].length > 0 ? placeholderValues["name"] + this.settings.prettyErrorLoggerNameDelimiter : "";
|
|
17820
|
-
if (this.settings.overwrite?.addPlaceholders != null) {
|
|
17821
|
-
this.settings.overwrite?.addPlaceholders(logObjMeta, placeholderValues);
|
|
17822
|
-
}
|
|
17823
|
-
return formatTemplate(this.settings, template, placeholderValues);
|
|
17824
|
-
}
|
|
17825
|
-
}
|
|
17826
|
-
|
|
17827
|
-
class Logger extends BaseLogger {
|
|
17828
|
-
constructor(settings, logObj) {
|
|
17829
|
-
const isBrowser = typeof window !== "undefined" && typeof document !== "undefined";
|
|
17830
|
-
const isBrowserBlinkEngine = isBrowser ? window.chrome !== undefined && window.CSS !== undefined && window.CSS.supports("color", "green") : false;
|
|
17831
|
-
const isSafari = isBrowser ? /^((?!chrome|android).)*safari/i.test(navigator.userAgent) : false;
|
|
17832
|
-
settings = settings || {};
|
|
17833
|
-
settings.stylePrettyLogs = settings.stylePrettyLogs && isBrowser && !isBrowserBlinkEngine ? false : settings.stylePrettyLogs;
|
|
17834
|
-
super(settings, logObj, isSafari ? 4 : 5);
|
|
17835
|
-
}
|
|
17836
|
-
log(logLevelId, logLevelName, ...args) {
|
|
17837
|
-
return super.log(logLevelId, logLevelName, ...args);
|
|
17838
|
-
}
|
|
17839
|
-
silly(...args) {
|
|
17840
|
-
return super.log(0, "SILLY", ...args);
|
|
17841
|
-
}
|
|
17842
|
-
trace(...args) {
|
|
17843
|
-
return super.log(1, "TRACE", ...args);
|
|
17844
|
-
}
|
|
17845
|
-
debug(...args) {
|
|
17846
|
-
return super.log(2, "DEBUG", ...args);
|
|
17847
|
-
}
|
|
17848
|
-
info(...args) {
|
|
17849
|
-
return super.log(3, "INFO", ...args);
|
|
17850
|
-
}
|
|
17851
|
-
warn(...args) {
|
|
17852
|
-
return super.log(4, "WARN", ...args);
|
|
17853
|
-
}
|
|
17854
|
-
error(...args) {
|
|
17855
|
-
return super.log(5, "ERROR", ...args);
|
|
17856
|
-
}
|
|
17857
|
-
fatal(...args) {
|
|
17858
|
-
return super.log(6, "FATAL", ...args);
|
|
17859
|
-
}
|
|
17860
|
-
getSubLogger(settings, logObj) {
|
|
17861
|
-
return super.getSubLogger(settings, logObj);
|
|
17862
|
-
}
|
|
17863
|
-
}
|
|
17864
|
-
|
|
17865
|
-
// Get package scope & name from package.json.
|
|
17866
|
-
const npmPackageRegex = /^(?:(?<packageScope>@[a-z0-9-~][a-z0-9-._~]*)\/)?(?<packageName>[a-z0-9-~][a-z0-9-._~]*)$/;
|
|
17867
|
-
const { packageScope, packageName } = (process.env.npm_package_name?.match(npmPackageRegex)?.groups ?? {});
|
|
17868
|
-
|
|
17869
|
-
// These are the presefined tslog log levels. You can specify
|
|
17870
|
-
// LOG_LEVEL by any of the keys or values defined below.
|
|
17871
|
-
const logLevels = {
|
|
17872
|
-
silly: 0,
|
|
17873
|
-
trace: 1,
|
|
17874
|
-
debug: 2,
|
|
17875
|
-
info: 3,
|
|
17876
|
-
warn: 4,
|
|
17877
|
-
error: 5,
|
|
17878
|
-
fatal: 6,
|
|
17879
|
-
};
|
|
17880
|
-
const integerLogLevel = parseInt(process.env.LOG_LEVEL ?? '');
|
|
17881
|
-
const resolvedLogLevel = Number.isNaN(integerLogLevel)
|
|
17882
|
-
? logLevels[(process.env.LOG_LEVEL ?? '').toLowerCase()]
|
|
17883
|
-
: integerLogLevel;
|
|
17884
|
-
// Set your tslog instance options here! By default, logs are suppressed if LOG_LEVEL is invalid or undefined.
|
|
17885
|
-
// See https://tslog.js.org for more info.
|
|
17886
|
-
const logger = new Logger({
|
|
17887
|
-
hideLogPositionForProduction: true,
|
|
17888
|
-
minLevel: resolvedLogLevel,
|
|
17889
|
-
name: packageName,
|
|
17890
|
-
type: resolvedLogLevel === undefined ? 'hidden' : 'pretty',
|
|
17891
|
-
});
|
|
17892
|
-
|
|
17893
17267
|
var _JsonMap_instances, _JsonMap_transform, _JsonMap_resolvePath;
|
|
17894
17268
|
// The transformation process leverages JSON.stringify and JSON.parse to eliminate circular references.
|
|
17895
17269
|
const getJsonFns = () => {
|
|
@@ -17944,17 +17318,17 @@ _JsonMap_instances = new WeakSet(), _JsonMap_transform =
|
|
|
17944
17318
|
* Recursive function to handle transformations.
|
|
17945
17319
|
*/
|
|
17946
17320
|
async function _JsonMap_transform(node, input, output, path = '') {
|
|
17947
|
-
|
|
17321
|
+
console.debug('#transform params:\n', { node, input, output, path });
|
|
17948
17322
|
// Checks if the current node is an object and has only a '$' key
|
|
17949
17323
|
if (node instanceof Object && _.size(node) === 1 && '$' in node) {
|
|
17950
17324
|
// Retrieves the transformations to be applied (can be an array or a single object)
|
|
17951
17325
|
const transformations = _.castArray(node.$);
|
|
17952
|
-
|
|
17326
|
+
console.debug('transformations:\n', transformations);
|
|
17953
17327
|
// Array to store the results of the transformations
|
|
17954
17328
|
const results = [];
|
|
17955
17329
|
// Iterates over each transformation
|
|
17956
17330
|
for (const transformation of transformations) {
|
|
17957
|
-
|
|
17331
|
+
console.debug('processing transformation:\n', transformation);
|
|
17958
17332
|
// Resolves the object path for the transformation
|
|
17959
17333
|
const { obj: methodObj, path: methodPath } = __classPrivateFieldGet(this, _JsonMap_instances, "m", _JsonMap_resolvePath).call(this, transformation.method, results);
|
|
17960
17334
|
// Resolves the parameter paths for the transformation
|
|
@@ -17966,16 +17340,16 @@ async function _JsonMap_transform(node, input, output, path = '') {
|
|
|
17966
17340
|
: paramObj
|
|
17967
17341
|
: paramPath;
|
|
17968
17342
|
});
|
|
17969
|
-
|
|
17343
|
+
console.debug('resolved transformation params:\n', params);
|
|
17970
17344
|
// Calls the specified method on the resolved object with the resolved parameters
|
|
17971
17345
|
const result = (await _.invoke(methodObj, methodPath, ...params));
|
|
17972
|
-
|
|
17346
|
+
console.debug('transformation result:\n', result);
|
|
17973
17347
|
// Stores the result of the transformation
|
|
17974
17348
|
results.unshift(result);
|
|
17975
17349
|
}
|
|
17976
17350
|
// Sets the output at the specified path to the last result of the transformations & returns.
|
|
17977
17351
|
_.set(output, path, results[0]);
|
|
17978
|
-
|
|
17352
|
+
console.debug('updated output:\n', output);
|
|
17979
17353
|
return results[0];
|
|
17980
17354
|
}
|
|
17981
17355
|
// Checks if the current node is an object
|
package/package.json
CHANGED
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"lodash": "^4.17.21",
|
|
8
8
|
"nanoid": "^5.0.7",
|
|
9
|
-
"tslog": "^4.9.3",
|
|
10
9
|
"zod": "^3.23.8"
|
|
11
10
|
},
|
|
12
11
|
"description": "A hyper-generic JSON mapping library.",
|
|
@@ -119,5 +118,5 @@
|
|
|
119
118
|
},
|
|
120
119
|
"type": "module",
|
|
121
120
|
"types": "dist/index.d.ts",
|
|
122
|
-
"version": "2.0.
|
|
121
|
+
"version": "2.0.6"
|
|
123
122
|
}
|