@dbcube/core 5.2.1 → 5.2.2

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.js CHANGED
@@ -1113,15 +1113,15 @@ var Engine = class {
1113
1113
  resolve5(response);
1114
1114
  }
1115
1115
  };
1116
- child.stdout.on("data", (data) => {
1117
- const text = data.toString();
1118
- stdoutBuffer += text;
1119
- const visible = text.split("\n").filter((l) => l.trim() && !l.includes("PROCESS_RESPONSE:")).join("\n");
1120
- if (visible) console.log(visible);
1121
- const match = stdoutBuffer.match(/PROCESS_RESPONSE:(\{.*\})/);
1122
- if (match) {
1116
+ const tryParseLines = (buffer) => {
1117
+ let idx;
1118
+ while ((idx = buffer.indexOf("\n")) !== -1) {
1119
+ const line = buffer.slice(0, idx);
1120
+ buffer = buffer.slice(idx + 1);
1121
+ const marker = line.indexOf("PROCESS_RESPONSE:");
1122
+ if (marker === -1) continue;
1123
1123
  try {
1124
- const response = JSON.parse(match[1]);
1124
+ const response = JSON.parse(line.slice(marker + "PROCESS_RESPONSE:".length));
1125
1125
  resolveOnce({
1126
1126
  status: response.status,
1127
1127
  message: response.message,
@@ -1135,29 +1135,19 @@ var Engine = class {
1135
1135
  });
1136
1136
  }
1137
1137
  }
1138
+ return buffer;
1139
+ };
1140
+ child.stdout.on("data", (data) => {
1141
+ const text = data.toString();
1142
+ const visible = text.split("\n").filter((l) => l.trim() && !l.includes("PROCESS_RESPONSE:")).join("\n");
1143
+ if (visible) console.log(visible);
1144
+ stdoutBuffer = tryParseLines(stdoutBuffer + text);
1138
1145
  });
1139
1146
  child.stderr.on("data", (data) => {
1140
1147
  const text = data.toString();
1141
- stderrBuffer += text;
1142
1148
  const visible = text.split("\n").filter((l) => l.trim() && !l.includes("PROCESS_RESPONSE:")).join("\n");
1143
1149
  if (visible) console.log(visible);
1144
- const match = stderrBuffer.match(/PROCESS_RESPONSE:(\{.*\})/);
1145
- if (match) {
1146
- try {
1147
- const response = JSON.parse(match[1]);
1148
- resolveOnce({
1149
- status: response.status,
1150
- message: response.message,
1151
- data: response.data
1152
- });
1153
- } catch (error) {
1154
- resolveOnce({
1155
- status: 500,
1156
- message: "Failed to parse response JSON",
1157
- data: null
1158
- });
1159
- }
1160
- }
1150
+ stderrBuffer = tryParseLines(stderrBuffer + text);
1161
1151
  });
1162
1152
  child.on("close", (code) => {
1163
1153
  clearTimeout(timeoutId);
@@ -1564,14 +1554,18 @@ var QueryEngine = class {
1564
1554
  }, this.timeout);
1565
1555
  const onData = (data) => {
1566
1556
  responseBuffer += data.toString();
1567
- const match = responseBuffer.match(/PROCESS_RESPONSE:(\{.*\})/);
1568
- if (match && !isResolved) {
1557
+ let idx;
1558
+ while ((idx = responseBuffer.indexOf("\n")) !== -1 && !isResolved) {
1559
+ const line = responseBuffer.slice(0, idx);
1560
+ responseBuffer = responseBuffer.slice(idx + 1);
1561
+ const marker = line.indexOf("PROCESS_RESPONSE:");
1562
+ if (marker === -1) continue;
1569
1563
  isResolved = true;
1570
1564
  clearTimeout(timeout);
1571
1565
  connection.removeListener("data", onData);
1572
1566
  connection.removeListener("error", onError);
1573
1567
  try {
1574
- const response = JSON.parse(match[1]);
1568
+ const response = JSON.parse(line.slice(marker + "PROCESS_RESPONSE:".length));
1575
1569
  resolve5({
1576
1570
  status: response.status,
1577
1571
  message: response.message,
@@ -1620,12 +1614,15 @@ var QueryEngine = class {
1620
1614
  resolve5(response);
1621
1615
  }
1622
1616
  };
1623
- child.stdout.on("data", (data) => {
1624
- stdoutBuffer += data.toString();
1625
- const match = stdoutBuffer.match(/PROCESS_RESPONSE:(\{.*\})/);
1626
- if (match) {
1617
+ const tryParseLines = (buffer) => {
1618
+ let idx;
1619
+ while ((idx = buffer.indexOf("\n")) !== -1) {
1620
+ const line = buffer.slice(0, idx);
1621
+ buffer = buffer.slice(idx + 1);
1622
+ const marker = line.indexOf("PROCESS_RESPONSE:");
1623
+ if (marker === -1) continue;
1627
1624
  try {
1628
- const response = JSON.parse(match[1]);
1625
+ const response = JSON.parse(line.slice(marker + "PROCESS_RESPONSE:".length));
1629
1626
  resolveOnce({
1630
1627
  status: response.status,
1631
1628
  message: response.message,
@@ -1639,26 +1636,13 @@ var QueryEngine = class {
1639
1636
  });
1640
1637
  }
1641
1638
  }
1639
+ return buffer;
1640
+ };
1641
+ child.stdout.on("data", (data) => {
1642
+ stdoutBuffer = tryParseLines(stdoutBuffer + data.toString());
1642
1643
  });
1643
1644
  child.stderr.on("data", (data) => {
1644
- stderrBuffer += data.toString();
1645
- const match = stderrBuffer.match(/PROCESS_RESPONSE:(\{.*\})/);
1646
- if (match) {
1647
- try {
1648
- const response = JSON.parse(match[1]);
1649
- resolveOnce({
1650
- status: response.status,
1651
- message: response.message,
1652
- data: response.data
1653
- });
1654
- } catch (error) {
1655
- resolveOnce({
1656
- status: 500,
1657
- message: "Failed to parse response JSON",
1658
- data: null
1659
- });
1660
- }
1661
- }
1645
+ stderrBuffer = tryParseLines(stderrBuffer + data.toString());
1662
1646
  });
1663
1647
  child.on("close", (code) => {
1664
1648
  clearTimeout(timeoutId);