@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.cjs CHANGED
@@ -1161,15 +1161,15 @@ var Engine = class {
1161
1161
  resolve5(response);
1162
1162
  }
1163
1163
  };
1164
- child.stdout.on("data", (data) => {
1165
- const text = data.toString();
1166
- stdoutBuffer += text;
1167
- const visible = text.split("\n").filter((l) => l.trim() && !l.includes("PROCESS_RESPONSE:")).join("\n");
1168
- if (visible) console.log(visible);
1169
- const match = stdoutBuffer.match(/PROCESS_RESPONSE:(\{.*\})/);
1170
- if (match) {
1164
+ const tryParseLines = (buffer) => {
1165
+ let idx;
1166
+ while ((idx = buffer.indexOf("\n")) !== -1) {
1167
+ const line = buffer.slice(0, idx);
1168
+ buffer = buffer.slice(idx + 1);
1169
+ const marker = line.indexOf("PROCESS_RESPONSE:");
1170
+ if (marker === -1) continue;
1171
1171
  try {
1172
- const response = JSON.parse(match[1]);
1172
+ const response = JSON.parse(line.slice(marker + "PROCESS_RESPONSE:".length));
1173
1173
  resolveOnce({
1174
1174
  status: response.status,
1175
1175
  message: response.message,
@@ -1183,29 +1183,19 @@ var Engine = class {
1183
1183
  });
1184
1184
  }
1185
1185
  }
1186
+ return buffer;
1187
+ };
1188
+ child.stdout.on("data", (data) => {
1189
+ const text = data.toString();
1190
+ const visible = text.split("\n").filter((l) => l.trim() && !l.includes("PROCESS_RESPONSE:")).join("\n");
1191
+ if (visible) console.log(visible);
1192
+ stdoutBuffer = tryParseLines(stdoutBuffer + text);
1186
1193
  });
1187
1194
  child.stderr.on("data", (data) => {
1188
1195
  const text = data.toString();
1189
- stderrBuffer += text;
1190
1196
  const visible = text.split("\n").filter((l) => l.trim() && !l.includes("PROCESS_RESPONSE:")).join("\n");
1191
1197
  if (visible) console.log(visible);
1192
- const match = stderrBuffer.match(/PROCESS_RESPONSE:(\{.*\})/);
1193
- if (match) {
1194
- try {
1195
- const response = JSON.parse(match[1]);
1196
- resolveOnce({
1197
- status: response.status,
1198
- message: response.message,
1199
- data: response.data
1200
- });
1201
- } catch (error) {
1202
- resolveOnce({
1203
- status: 500,
1204
- message: "Failed to parse response JSON",
1205
- data: null
1206
- });
1207
- }
1208
- }
1198
+ stderrBuffer = tryParseLines(stderrBuffer + text);
1209
1199
  });
1210
1200
  child.on("close", (code) => {
1211
1201
  clearTimeout(timeoutId);
@@ -1612,14 +1602,18 @@ var QueryEngine = class {
1612
1602
  }, this.timeout);
1613
1603
  const onData = (data) => {
1614
1604
  responseBuffer += data.toString();
1615
- const match = responseBuffer.match(/PROCESS_RESPONSE:(\{.*\})/);
1616
- if (match && !isResolved) {
1605
+ let idx;
1606
+ while ((idx = responseBuffer.indexOf("\n")) !== -1 && !isResolved) {
1607
+ const line = responseBuffer.slice(0, idx);
1608
+ responseBuffer = responseBuffer.slice(idx + 1);
1609
+ const marker = line.indexOf("PROCESS_RESPONSE:");
1610
+ if (marker === -1) continue;
1617
1611
  isResolved = true;
1618
1612
  clearTimeout(timeout);
1619
1613
  connection.removeListener("data", onData);
1620
1614
  connection.removeListener("error", onError);
1621
1615
  try {
1622
- const response = JSON.parse(match[1]);
1616
+ const response = JSON.parse(line.slice(marker + "PROCESS_RESPONSE:".length));
1623
1617
  resolve5({
1624
1618
  status: response.status,
1625
1619
  message: response.message,
@@ -1668,12 +1662,15 @@ var QueryEngine = class {
1668
1662
  resolve5(response);
1669
1663
  }
1670
1664
  };
1671
- child.stdout.on("data", (data) => {
1672
- stdoutBuffer += data.toString();
1673
- const match = stdoutBuffer.match(/PROCESS_RESPONSE:(\{.*\})/);
1674
- if (match) {
1665
+ const tryParseLines = (buffer) => {
1666
+ let idx;
1667
+ while ((idx = buffer.indexOf("\n")) !== -1) {
1668
+ const line = buffer.slice(0, idx);
1669
+ buffer = buffer.slice(idx + 1);
1670
+ const marker = line.indexOf("PROCESS_RESPONSE:");
1671
+ if (marker === -1) continue;
1675
1672
  try {
1676
- const response = JSON.parse(match[1]);
1673
+ const response = JSON.parse(line.slice(marker + "PROCESS_RESPONSE:".length));
1677
1674
  resolveOnce({
1678
1675
  status: response.status,
1679
1676
  message: response.message,
@@ -1687,26 +1684,13 @@ var QueryEngine = class {
1687
1684
  });
1688
1685
  }
1689
1686
  }
1687
+ return buffer;
1688
+ };
1689
+ child.stdout.on("data", (data) => {
1690
+ stdoutBuffer = tryParseLines(stdoutBuffer + data.toString());
1690
1691
  });
1691
1692
  child.stderr.on("data", (data) => {
1692
- stderrBuffer += data.toString();
1693
- const match = stderrBuffer.match(/PROCESS_RESPONSE:(\{.*\})/);
1694
- if (match) {
1695
- try {
1696
- const response = JSON.parse(match[1]);
1697
- resolveOnce({
1698
- status: response.status,
1699
- message: response.message,
1700
- data: response.data
1701
- });
1702
- } catch (error) {
1703
- resolveOnce({
1704
- status: 500,
1705
- message: "Failed to parse response JSON",
1706
- data: null
1707
- });
1708
- }
1709
- }
1693
+ stderrBuffer = tryParseLines(stderrBuffer + data.toString());
1710
1694
  });
1711
1695
  child.on("close", (code) => {
1712
1696
  clearTimeout(timeoutId);