@dbcube/core 3.0.12 → 3.0.14

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
@@ -964,7 +964,6 @@ var QueryEngine = class {
964
964
  if (output.includes("TCP Server listening on")) {
965
965
  if (!started) {
966
966
  started = true;
967
- clearTimeout(timeout);
968
967
  globalTcpServers.set(this.connectionId, {
969
968
  port: this.tcpPort,
970
969
  process: serverProcess
@@ -981,7 +980,6 @@ var QueryEngine = class {
981
980
  });
982
981
  serverProcess.on("error", (error) => {
983
982
  if (!started) {
984
- clearTimeout(timeout);
985
983
  reject(error);
986
984
  }
987
985
  });
@@ -1005,7 +1003,6 @@ var QueryEngine = class {
1005
1003
  if (!dmlJson) {
1006
1004
  if (!isResolved) {
1007
1005
  isResolved = true;
1008
- clearTimeout(timeout);
1009
1006
  client.destroy();
1010
1007
  reject(new Error("No DML found in arguments"));
1011
1008
  }
@@ -1022,7 +1019,6 @@ var QueryEngine = class {
1022
1019
  const match = responseBuffer.match(/PROCESS_RESPONSE:(\{.*\})/);
1023
1020
  if (match && !isResolved) {
1024
1021
  isResolved = true;
1025
- clearTimeout(timeout);
1026
1022
  client.destroy();
1027
1023
  try {
1028
1024
  const response = JSON.parse(match[1]);
@@ -1039,13 +1035,11 @@ var QueryEngine = class {
1039
1035
  client.on("error", (error) => {
1040
1036
  if (!isResolved) {
1041
1037
  isResolved = true;
1042
- clearTimeout(timeout);
1043
1038
  reject(error);
1044
1039
  }
1045
1040
  });
1046
1041
  client.on("close", () => {
1047
1042
  if (!isResolved) {
1048
- clearTimeout(timeout);
1049
1043
  if (!responseBuffer.includes("PROCESS_RESPONSE:")) {
1050
1044
  reject(new Error("Connection closed without valid response"));
1051
1045
  }
@@ -1081,22 +1075,14 @@ var QueryEngine = class {
1081
1075
  }
1082
1076
  let responseBuffer = "";
1083
1077
  let isResolved = false;
1084
- const timeout = setTimeout(() => {
1085
- if (!isResolved) {
1086
- isResolved = true;
1087
- connection.off("data", onData);
1088
- connection.off("error", onError);
1089
- reject(new Error("Ultra-fast timeout"));
1090
- }
1091
- }, 50);
1092
1078
  const onData = (data) => {
1093
1079
  responseBuffer += data.toString();
1094
1080
  const match = responseBuffer.match(/PROCESS_RESPONSE:(\{.*\})/);
1095
1081
  if (match && !isResolved) {
1096
1082
  isResolved = true;
1097
- clearTimeout(timeout);
1098
1083
  connection.off("data", onData);
1099
1084
  connection.off("error", onError);
1085
+ connection.off("close", onClose);
1100
1086
  try {
1101
1087
  const response = JSON.parse(match[1]);
1102
1088
  resolve5({
@@ -1112,14 +1098,25 @@ var QueryEngine = class {
1112
1098
  const onError = (error) => {
1113
1099
  if (!isResolved) {
1114
1100
  isResolved = true;
1115
- clearTimeout(timeout);
1116
1101
  connection.off("data", onData);
1117
1102
  connection.off("error", onError);
1103
+ connection.off("close", onClose);
1118
1104
  reject(error);
1119
1105
  }
1120
1106
  };
1107
+ const onClose = () => {
1108
+ if (!isResolved) {
1109
+ isResolved = true;
1110
+ connection.off("data", onData);
1111
+ connection.off("error", onError);
1112
+ connection.off("close", onClose);
1113
+ connection.off("close", onClose);
1114
+ reject(new Error("Connection closed unexpectedly"));
1115
+ }
1116
+ };
1121
1117
  connection.on("data", onData);
1122
1118
  connection.on("error", onError);
1119
+ connection.on("close", onClose);
1123
1120
  const command = `{"action":"execute","dml":${dmlJson}}`;
1124
1121
  connection.write(command);
1125
1122
  });
@@ -1160,20 +1157,14 @@ var QueryEngine = class {
1160
1157
  const dmlParsed = this.getCachedDML(dmlJson);
1161
1158
  let responseBuffer = "";
1162
1159
  let isResolved = false;
1163
- const timeout = setTimeout(() => {
1164
- if (!isResolved) {
1165
- isResolved = true;
1166
- reject(new Error("TCP request timeout"));
1167
- }
1168
- }, 100);
1169
1160
  const onData = (data) => {
1170
1161
  responseBuffer += data.toString();
1171
1162
  const match = responseBuffer.match(/PROCESS_RESPONSE:(\{.*\})/);
1172
1163
  if (match && !isResolved) {
1173
1164
  isResolved = true;
1174
- clearTimeout(timeout);
1175
1165
  connection.off("data", onData);
1176
1166
  connection.off("error", onError);
1167
+ connection.off("close", onClose);
1177
1168
  try {
1178
1169
  const response = JSON.parse(match[1]);
1179
1170
  resolve5({
@@ -1189,14 +1180,24 @@ var QueryEngine = class {
1189
1180
  const onError = (error) => {
1190
1181
  if (!isResolved) {
1191
1182
  isResolved = true;
1192
- clearTimeout(timeout);
1193
1183
  connection.off("data", onData);
1194
1184
  connection.off("error", onError);
1185
+ connection.off("close", onClose);
1195
1186
  reject(error);
1196
1187
  }
1197
1188
  };
1189
+ const onClose = () => {
1190
+ if (!isResolved) {
1191
+ isResolved = true;
1192
+ connection.off("data", onData);
1193
+ connection.off("error", onError);
1194
+ connection.off("close", onClose);
1195
+ reject(new Error("Connection closed unexpectedly"));
1196
+ }
1197
+ };
1198
1198
  connection.on("data", onData);
1199
1199
  connection.on("error", onError);
1200
+ connection.on("close", onClose);
1200
1201
  const command = {
1201
1202
  action: "execute",
1202
1203
  dml: dmlJson