@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.cjs CHANGED
@@ -1002,7 +1002,6 @@ var QueryEngine = class {
1002
1002
  if (output.includes("TCP Server listening on")) {
1003
1003
  if (!started) {
1004
1004
  started = true;
1005
- clearTimeout(timeout);
1006
1005
  globalTcpServers.set(this.connectionId, {
1007
1006
  port: this.tcpPort,
1008
1007
  process: serverProcess
@@ -1019,7 +1018,6 @@ var QueryEngine = class {
1019
1018
  });
1020
1019
  serverProcess.on("error", (error) => {
1021
1020
  if (!started) {
1022
- clearTimeout(timeout);
1023
1021
  reject(error);
1024
1022
  }
1025
1023
  });
@@ -1043,7 +1041,6 @@ var QueryEngine = class {
1043
1041
  if (!dmlJson) {
1044
1042
  if (!isResolved) {
1045
1043
  isResolved = true;
1046
- clearTimeout(timeout);
1047
1044
  client.destroy();
1048
1045
  reject(new Error("No DML found in arguments"));
1049
1046
  }
@@ -1060,7 +1057,6 @@ var QueryEngine = class {
1060
1057
  const match = responseBuffer.match(/PROCESS_RESPONSE:(\{.*\})/);
1061
1058
  if (match && !isResolved) {
1062
1059
  isResolved = true;
1063
- clearTimeout(timeout);
1064
1060
  client.destroy();
1065
1061
  try {
1066
1062
  const response = JSON.parse(match[1]);
@@ -1077,13 +1073,11 @@ var QueryEngine = class {
1077
1073
  client.on("error", (error) => {
1078
1074
  if (!isResolved) {
1079
1075
  isResolved = true;
1080
- clearTimeout(timeout);
1081
1076
  reject(error);
1082
1077
  }
1083
1078
  });
1084
1079
  client.on("close", () => {
1085
1080
  if (!isResolved) {
1086
- clearTimeout(timeout);
1087
1081
  if (!responseBuffer.includes("PROCESS_RESPONSE:")) {
1088
1082
  reject(new Error("Connection closed without valid response"));
1089
1083
  }
@@ -1119,22 +1113,14 @@ var QueryEngine = class {
1119
1113
  }
1120
1114
  let responseBuffer = "";
1121
1115
  let isResolved = false;
1122
- const timeout = setTimeout(() => {
1123
- if (!isResolved) {
1124
- isResolved = true;
1125
- connection.off("data", onData);
1126
- connection.off("error", onError);
1127
- reject(new Error("Ultra-fast timeout"));
1128
- }
1129
- }, 50);
1130
1116
  const onData = (data) => {
1131
1117
  responseBuffer += data.toString();
1132
1118
  const match = responseBuffer.match(/PROCESS_RESPONSE:(\{.*\})/);
1133
1119
  if (match && !isResolved) {
1134
1120
  isResolved = true;
1135
- clearTimeout(timeout);
1136
1121
  connection.off("data", onData);
1137
1122
  connection.off("error", onError);
1123
+ connection.off("close", onClose);
1138
1124
  try {
1139
1125
  const response = JSON.parse(match[1]);
1140
1126
  resolve5({
@@ -1150,14 +1136,25 @@ var QueryEngine = class {
1150
1136
  const onError = (error) => {
1151
1137
  if (!isResolved) {
1152
1138
  isResolved = true;
1153
- clearTimeout(timeout);
1154
1139
  connection.off("data", onData);
1155
1140
  connection.off("error", onError);
1141
+ connection.off("close", onClose);
1156
1142
  reject(error);
1157
1143
  }
1158
1144
  };
1145
+ const onClose = () => {
1146
+ if (!isResolved) {
1147
+ isResolved = true;
1148
+ connection.off("data", onData);
1149
+ connection.off("error", onError);
1150
+ connection.off("close", onClose);
1151
+ connection.off("close", onClose);
1152
+ reject(new Error("Connection closed unexpectedly"));
1153
+ }
1154
+ };
1159
1155
  connection.on("data", onData);
1160
1156
  connection.on("error", onError);
1157
+ connection.on("close", onClose);
1161
1158
  const command = `{"action":"execute","dml":${dmlJson}}`;
1162
1159
  connection.write(command);
1163
1160
  });
@@ -1198,20 +1195,14 @@ var QueryEngine = class {
1198
1195
  const dmlParsed = this.getCachedDML(dmlJson);
1199
1196
  let responseBuffer = "";
1200
1197
  let isResolved = false;
1201
- const timeout = setTimeout(() => {
1202
- if (!isResolved) {
1203
- isResolved = true;
1204
- reject(new Error("TCP request timeout"));
1205
- }
1206
- }, 100);
1207
1198
  const onData = (data) => {
1208
1199
  responseBuffer += data.toString();
1209
1200
  const match = responseBuffer.match(/PROCESS_RESPONSE:(\{.*\})/);
1210
1201
  if (match && !isResolved) {
1211
1202
  isResolved = true;
1212
- clearTimeout(timeout);
1213
1203
  connection.off("data", onData);
1214
1204
  connection.off("error", onError);
1205
+ connection.off("close", onClose);
1215
1206
  try {
1216
1207
  const response = JSON.parse(match[1]);
1217
1208
  resolve5({
@@ -1227,14 +1218,24 @@ var QueryEngine = class {
1227
1218
  const onError = (error) => {
1228
1219
  if (!isResolved) {
1229
1220
  isResolved = true;
1230
- clearTimeout(timeout);
1231
1221
  connection.off("data", onData);
1232
1222
  connection.off("error", onError);
1223
+ connection.off("close", onClose);
1233
1224
  reject(error);
1234
1225
  }
1235
1226
  };
1227
+ const onClose = () => {
1228
+ if (!isResolved) {
1229
+ isResolved = true;
1230
+ connection.off("data", onData);
1231
+ connection.off("error", onError);
1232
+ connection.off("close", onClose);
1233
+ reject(new Error("Connection closed unexpectedly"));
1234
+ }
1235
+ };
1236
1236
  connection.on("data", onData);
1237
1237
  connection.on("error", onError);
1238
+ connection.on("close", onClose);
1238
1239
  const command = {
1239
1240
  action: "execute",
1240
1241
  dml: dmlJson