@bian-womp/spark-graph 0.3.54 → 0.3.56
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/lib/cjs/index.cjs +62 -9
- package/lib/cjs/index.cjs.map +1 -1
- package/lib/cjs/src/misc/utils/LevelLogger.d.ts +8 -0
- package/lib/cjs/src/misc/utils/LevelLogger.d.ts.map +1 -1
- package/lib/cjs/src/misc/utils/LevelLogger.test.d.ts +2 -0
- package/lib/cjs/src/misc/utils/LevelLogger.test.d.ts.map +1 -0
- package/lib/cjs/src/misc/utils/test-logger-output.d.ts +7 -0
- package/lib/cjs/src/misc/utils/test-logger-output.d.ts.map +1 -0
- package/lib/esm/index.js +62 -9
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/src/misc/utils/LevelLogger.d.ts +8 -0
- package/lib/esm/src/misc/utils/LevelLogger.d.ts.map +1 -1
- package/lib/esm/src/misc/utils/LevelLogger.test.d.ts +2 -0
- package/lib/esm/src/misc/utils/LevelLogger.test.d.ts.map +1 -0
- package/lib/esm/src/misc/utils/test-logger-output.d.ts +7 -0
- package/lib/esm/src/misc/utils/test-logger-output.d.ts.map +1 -0
- package/package.json +6 -3
package/lib/cjs/index.cjs
CHANGED
|
@@ -1546,6 +1546,40 @@ class LevelLogger {
|
|
|
1546
1546
|
error(message, context, overrideLevel) {
|
|
1547
1547
|
this.log("error", message, context, overrideLevel);
|
|
1548
1548
|
}
|
|
1549
|
+
/**
|
|
1550
|
+
* Tries to parse a string as JSON and format it nicely if it's fully JSON
|
|
1551
|
+
*/
|
|
1552
|
+
parseJsonStringIfFull(str) {
|
|
1553
|
+
const trimmed = str.trim();
|
|
1554
|
+
// Check if the string starts with { or [ and ends with } or ]
|
|
1555
|
+
if ((trimmed.startsWith("{") && trimmed.endsWith("}")) ||
|
|
1556
|
+
(trimmed.startsWith("[") && trimmed.endsWith("]"))) {
|
|
1557
|
+
try {
|
|
1558
|
+
const parsed = JSON.parse(trimmed);
|
|
1559
|
+
return JSON.stringify(parsed, null, 2);
|
|
1560
|
+
}
|
|
1561
|
+
catch {
|
|
1562
|
+
// If parsing fails, return original string
|
|
1563
|
+
return str;
|
|
1564
|
+
}
|
|
1565
|
+
}
|
|
1566
|
+
return str;
|
|
1567
|
+
}
|
|
1568
|
+
/**
|
|
1569
|
+
* Parses JSON strings in context values if they are fully JSON
|
|
1570
|
+
*/
|
|
1571
|
+
parseJsonStringsInContext(context) {
|
|
1572
|
+
const parsed = {};
|
|
1573
|
+
for (const [key, value] of Object.entries(context)) {
|
|
1574
|
+
if (typeof value === "string") {
|
|
1575
|
+
parsed[key] = this.parseJsonStringIfFull(value);
|
|
1576
|
+
}
|
|
1577
|
+
else {
|
|
1578
|
+
parsed[key] = value;
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
return parsed;
|
|
1582
|
+
}
|
|
1549
1583
|
/**
|
|
1550
1584
|
* Core logging method that respects the log level and applies prefix
|
|
1551
1585
|
*/
|
|
@@ -1559,12 +1593,31 @@ class LevelLogger {
|
|
|
1559
1593
|
const effectiveValue = LevelLogger.levelValues[effectiveLevel] ?? 1;
|
|
1560
1594
|
// Only log if the requested level is >= effective level
|
|
1561
1595
|
if (requestedValue >= effectiveValue) {
|
|
1562
|
-
const {
|
|
1563
|
-
const
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1596
|
+
const { logFormat = "plain", ...rest } = context ?? {};
|
|
1597
|
+
const formatJson = logFormat === "json" || logFormat === "json-deep";
|
|
1598
|
+
const parseJsonString = logFormat === "json-deep";
|
|
1599
|
+
// Parse JSON strings in context values if requested
|
|
1600
|
+
let processedContext = rest;
|
|
1601
|
+
if (parseJsonString && rest && Object.keys(rest).length > 0) {
|
|
1602
|
+
processedContext = this.parseJsonStringsInContext(rest);
|
|
1603
|
+
}
|
|
1604
|
+
const contextStr = processedContext && Object.keys(processedContext).length > 0
|
|
1605
|
+
? `${formatJson ? "\n" : " "}${Object.entries(processedContext)
|
|
1606
|
+
.map(([k, v]) => {
|
|
1607
|
+
// If parseJsonString is enabled and value is a formatted JSON string
|
|
1608
|
+
// (starts with { or [ and contains newlines indicating it was formatted),
|
|
1609
|
+
// output it directly without stringifySceneAndOps to preserve formatting
|
|
1610
|
+
if (parseJsonString &&
|
|
1611
|
+
typeof v === "string" &&
|
|
1612
|
+
v.trim().match(/^[{\[]/) &&
|
|
1613
|
+
v.includes("\n")) {
|
|
1614
|
+
return `${k}=${v}`;
|
|
1615
|
+
}
|
|
1616
|
+
if (formatJson) {
|
|
1617
|
+
return `${k}=${stringifySceneAndOps(v)}`;
|
|
1618
|
+
}
|
|
1619
|
+
return `${k}=${JSON.stringify(v)}`;
|
|
1620
|
+
})
|
|
1568
1621
|
.join(formatJson ? "\n" : " ")}`
|
|
1569
1622
|
: "";
|
|
1570
1623
|
const prefixedMessage = this.prefix
|
|
@@ -3751,11 +3804,11 @@ class GraphRuntime {
|
|
|
3751
3804
|
if (!node)
|
|
3752
3805
|
return undefined;
|
|
3753
3806
|
return {
|
|
3754
|
-
inputs:
|
|
3755
|
-
outputs:
|
|
3807
|
+
inputs: node.inputs,
|
|
3808
|
+
outputs: node.outputs,
|
|
3756
3809
|
state: node.state,
|
|
3757
3810
|
params: node.params,
|
|
3758
|
-
stats:
|
|
3811
|
+
stats: node.stats,
|
|
3759
3812
|
};
|
|
3760
3813
|
}
|
|
3761
3814
|
getEnvironment() {
|