@bian-womp/spark-graph 0.3.56 → 0.3.57

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.
@@ -48,8 +48,14 @@ export declare class LevelLogger {
48
48
  * Tries to parse a string as JSON and format it nicely if it's fully JSON
49
49
  */
50
50
  private parseJsonStringIfFull;
51
+ /**
52
+ * Tries to parse a string as JSON and return the parsed object/array if it's fully JSON
53
+ * Used for parsing JSON strings inside arrays so they can be formatted by stringifySceneAndOps
54
+ */
55
+ private parseJsonStringToObject;
51
56
  /**
52
57
  * Parses JSON strings in context values if they are fully JSON
58
+ * Also handles arrays containing JSON strings
53
59
  */
54
60
  private parseJsonStringsInContext;
55
61
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"LevelLogger.d.ts","sourceRoot":"","sources":["../../../../../src/misc/utils/LevelLogger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAI1D;;;GAGG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,YAAY,CAAW;IAC/B,OAAO,CAAC,MAAM,CAAS;IAEvB;;OAEG;IACH,gBAAuB,WAAW,EAAE,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,CACzC;gBAEP,YAAY,GAAE,QAAiB,EAAE,MAAM,GAAE,MAAW;IAKhE;;OAEG;IACH,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAI/B;;OAEG;IACH,SAAS,IAAI,MAAM;IAInB;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI;IAI/B;;OAEG;IACH,QAAQ,IAAI,QAAQ;IAIpB,aAAa,IAAI,MAAM;IAIvB;;OAEG;IACH,KAAK,CACH,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,aAAa,CAAC,EAAE,QAAQ,GACvB,IAAI;IAIP;;OAEG;I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,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,aAAa,CAAC,EAAE,QAAQ,GACvB,IAAI;IAIP;;OAEG;IACH,IAAI,CACF,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,aAAa,CAAC,EAAE,QAAQ,GACvB,IAAI;IAIP;;OAEG;IACH,IAAI,CACF,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,aAAa,CAAC,EAAE,QAAQ,GACvB,IAAI;IAIP;;OAEG;IACH,KAAK,CACH,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,aAAa,CAAC,EAAE,QAAQ,GACvB,IAAI;IAIP;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAkB7B;;;OAGG;IACH,OAAO,CAAC,uBAAuB;IAiB/B;;;OAGG;IACH,OAAO,CAAC,yBAAyB;IAuBjC;;OAEG;IACH,OAAO,CAAC,GAAG;CAgHZ"}
package/lib/esm/index.js CHANGED
@@ -1563,8 +1563,28 @@ class LevelLogger {
1563
1563
  }
1564
1564
  return str;
1565
1565
  }
1566
+ /**
1567
+ * Tries to parse a string as JSON and return the parsed object/array if it's fully JSON
1568
+ * Used for parsing JSON strings inside arrays so they can be formatted by stringifySceneAndOps
1569
+ */
1570
+ parseJsonStringToObject(str) {
1571
+ const trimmed = str.trim();
1572
+ // Check if the string starts with { or [ and ends with } or ]
1573
+ if ((trimmed.startsWith("{") && trimmed.endsWith("}")) ||
1574
+ (trimmed.startsWith("[") && trimmed.endsWith("]"))) {
1575
+ try {
1576
+ return JSON.parse(trimmed);
1577
+ }
1578
+ catch {
1579
+ // If parsing fails, return original string
1580
+ return str;
1581
+ }
1582
+ }
1583
+ return str;
1584
+ }
1566
1585
  /**
1567
1586
  * Parses JSON strings in context values if they are fully JSON
1587
+ * Also handles arrays containing JSON strings
1568
1588
  */
1569
1589
  parseJsonStringsInContext(context) {
1570
1590
  const parsed = {};
@@ -1572,6 +1592,16 @@ class LevelLogger {
1572
1592
  if (typeof value === "string") {
1573
1593
  parsed[key] = this.parseJsonStringIfFull(value);
1574
1594
  }
1595
+ else if (Array.isArray(value)) {
1596
+ // Process arrays: parse JSON strings within the array to objects/arrays
1597
+ // so they can be formatted correctly by stringifySceneAndOps
1598
+ parsed[key] = value.map((item) => {
1599
+ if (typeof item === "string") {
1600
+ return this.parseJsonStringToObject(item);
1601
+ }
1602
+ return item;
1603
+ });
1604
+ }
1575
1605
  else {
1576
1606
  parsed[key] = value;
1577
1607
  }
@@ -1596,7 +1626,43 @@ class LevelLogger {
1596
1626
  const parseJsonString = logFormat === "json-deep";
1597
1627
  // Parse JSON strings in context values if requested
1598
1628
  let processedContext = rest;
1629
+ const parsedKeys = new Set(); // Track keys that had JSON strings parsed
1599
1630
  if (parseJsonString && rest && Object.keys(rest).length > 0) {
1631
+ // Check which keys had JSON strings before parsing
1632
+ for (const [key, value] of Object.entries(rest)) {
1633
+ if (typeof value === "string") {
1634
+ const trimmed = value.trim();
1635
+ if ((trimmed.startsWith("{") && trimmed.endsWith("}")) ||
1636
+ (trimmed.startsWith("[") && trimmed.endsWith("]"))) {
1637
+ try {
1638
+ JSON.parse(trimmed);
1639
+ parsedKeys.add(key);
1640
+ }
1641
+ catch {
1642
+ // Not valid JSON, skip
1643
+ }
1644
+ }
1645
+ }
1646
+ else if (Array.isArray(value)) {
1647
+ // Check if array contains JSON strings
1648
+ for (const item of value) {
1649
+ if (typeof item === "string") {
1650
+ const trimmed = item.trim();
1651
+ if ((trimmed.startsWith("{") && trimmed.endsWith("}")) ||
1652
+ (trimmed.startsWith("[") && trimmed.endsWith("]"))) {
1653
+ try {
1654
+ JSON.parse(trimmed);
1655
+ parsedKeys.add(key);
1656
+ break; // Found at least one JSON string in array
1657
+ }
1658
+ catch {
1659
+ // Not valid JSON, continue
1660
+ }
1661
+ }
1662
+ }
1663
+ }
1664
+ }
1665
+ }
1600
1666
  processedContext = this.parseJsonStringsInContext(rest);
1601
1667
  }
1602
1668
  const contextStr = processedContext && Object.keys(processedContext).length > 0
@@ -1605,11 +1671,17 @@ class LevelLogger {
1605
1671
  // If parseJsonString is enabled and value is a formatted JSON string
1606
1672
  // (starts with { or [ and contains newlines indicating it was formatted),
1607
1673
  // output it directly without stringifySceneAndOps to preserve formatting
1674
+ // Wrap it with json`...` to distinguish it as formatted JSON
1608
1675
  if (parseJsonString &&
1609
1676
  typeof v === "string" &&
1610
1677
  v.trim().match(/^[{\[]/) &&
1611
1678
  v.includes("\n")) {
1612
- return `${k}=${v}`;
1679
+ return `${k}=json\`${v}\``;
1680
+ }
1681
+ // If this key had a JSON string parsed and we're formatting JSON,
1682
+ // wrap the formatted output with json`...`
1683
+ if (formatJson && parseJsonString && parsedKeys.has(k)) {
1684
+ return `${k}=json\`${stringifySceneAndOps(v)}\``;
1613
1685
  }
1614
1686
  if (formatJson) {
1615
1687
  return `${k}=${stringifySceneAndOps(v)}`;