@dbcube/core 4.0.2 → 4.0.4
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 +61 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +61 -21
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -608,7 +608,12 @@ var Engine = class {
|
|
|
608
608
|
const configFilePath = path3.resolve(process.cwd(), "dbcube.config.js");
|
|
609
609
|
const requireUrl = typeof __filename !== "undefined" ? __filename : process.cwd();
|
|
610
610
|
const require2 = createRequire(requireUrl);
|
|
611
|
-
|
|
611
|
+
if (require2.cache && require2.resolve) {
|
|
612
|
+
try {
|
|
613
|
+
delete require2.cache[require2.resolve(configFilePath)];
|
|
614
|
+
} catch (e) {
|
|
615
|
+
}
|
|
616
|
+
}
|
|
612
617
|
const configModule = require2(configFilePath);
|
|
613
618
|
const configFn = configModule.default || configModule;
|
|
614
619
|
if (typeof configFn === "function") {
|
|
@@ -812,7 +817,12 @@ var QueryEngine = class {
|
|
|
812
817
|
const configFilePath = path4.resolve(process.cwd(), "dbcube.config.js");
|
|
813
818
|
const requireUrl = typeof __filename !== "undefined" ? __filename : process.cwd();
|
|
814
819
|
const require2 = createRequire2(requireUrl);
|
|
815
|
-
|
|
820
|
+
if (require2.cache && require2.resolve) {
|
|
821
|
+
try {
|
|
822
|
+
delete require2.cache[require2.resolve(configFilePath)];
|
|
823
|
+
} catch (e) {
|
|
824
|
+
}
|
|
825
|
+
}
|
|
816
826
|
const configModule = require2(configFilePath);
|
|
817
827
|
const configFn = configModule.default || configModule;
|
|
818
828
|
if (typeof configFn === "function") {
|
|
@@ -1069,68 +1079,98 @@ var QueryEngine = class {
|
|
|
1069
1079
|
}
|
|
1070
1080
|
async createPersistentConnection(args) {
|
|
1071
1081
|
return new Promise((resolve5, reject) => {
|
|
1072
|
-
|
|
1082
|
+
let client = globalTcpConnections.get(this.connectionId);
|
|
1083
|
+
let isNewConnection = false;
|
|
1084
|
+
if (!client || client.destroyed) {
|
|
1085
|
+
client = new net.Socket();
|
|
1086
|
+
isNewConnection = true;
|
|
1087
|
+
client.setNoDelay(true);
|
|
1088
|
+
client.setKeepAlive(true, 6e4);
|
|
1089
|
+
client.setMaxListeners(20);
|
|
1090
|
+
}
|
|
1073
1091
|
let responseBuffer = "";
|
|
1074
1092
|
let isResolved = false;
|
|
1075
|
-
client.setNoDelay(true);
|
|
1076
|
-
client.setKeepAlive(true, 6e4);
|
|
1077
1093
|
const timeout = setTimeout(() => {
|
|
1078
1094
|
if (!isResolved) {
|
|
1079
1095
|
isResolved = true;
|
|
1080
|
-
client.destroy();
|
|
1081
1096
|
reject(new Error("TCP connection timeout"));
|
|
1082
1097
|
}
|
|
1083
1098
|
}, 5e3);
|
|
1084
|
-
|
|
1085
|
-
clearTimeout(timeout);
|
|
1099
|
+
const executeQuery = () => {
|
|
1086
1100
|
const dmlIndex = args.findIndex((arg) => arg === "--dml");
|
|
1087
1101
|
const dmlJson = dmlIndex !== -1 ? args[dmlIndex + 1] : null;
|
|
1088
1102
|
if (!dmlJson) {
|
|
1103
|
+
clearTimeout(timeout);
|
|
1089
1104
|
if (!isResolved) {
|
|
1090
1105
|
isResolved = true;
|
|
1091
|
-
client.destroy();
|
|
1092
1106
|
reject(new Error("No DML found in arguments"));
|
|
1093
1107
|
}
|
|
1094
1108
|
return;
|
|
1095
1109
|
}
|
|
1096
|
-
globalTcpConnections.set(this.connectionId, client);
|
|
1097
1110
|
const command = {
|
|
1098
1111
|
action: "execute",
|
|
1099
1112
|
dml: dmlJson
|
|
1100
1113
|
};
|
|
1101
|
-
|
|
1102
|
-
client.write(
|
|
1103
|
-
|
|
1104
|
-
|
|
1114
|
+
const commandStr = JSON.stringify(command);
|
|
1115
|
+
const canWrite = client.write(commandStr);
|
|
1116
|
+
if (!canWrite) {
|
|
1117
|
+
client.once("drain", () => {
|
|
1118
|
+
});
|
|
1119
|
+
}
|
|
1120
|
+
};
|
|
1121
|
+
const dataHandler = (data) => {
|
|
1105
1122
|
responseBuffer += data.toString();
|
|
1106
1123
|
const match = responseBuffer.match(/PROCESS_RESPONSE:(\{.*\})/);
|
|
1107
1124
|
if (match && !isResolved) {
|
|
1108
1125
|
isResolved = true;
|
|
1126
|
+
clearTimeout(timeout);
|
|
1109
1127
|
try {
|
|
1110
1128
|
const response = JSON.parse(match[1]);
|
|
1129
|
+
responseBuffer = "";
|
|
1130
|
+
client.removeListener("data", dataHandler);
|
|
1111
1131
|
resolve5({
|
|
1112
1132
|
status: response.status,
|
|
1113
1133
|
message: response.message,
|
|
1114
1134
|
data: response.data
|
|
1115
1135
|
});
|
|
1116
1136
|
} catch (error) {
|
|
1137
|
+
client.removeListener("data", dataHandler);
|
|
1117
1138
|
reject(new Error("Failed to parse TCP response"));
|
|
1118
1139
|
}
|
|
1119
1140
|
}
|
|
1120
|
-
}
|
|
1121
|
-
|
|
1141
|
+
};
|
|
1142
|
+
const errorHandler = (error) => {
|
|
1122
1143
|
if (!isResolved) {
|
|
1123
1144
|
isResolved = true;
|
|
1145
|
+
clearTimeout(timeout);
|
|
1124
1146
|
globalTcpConnections.delete(this.connectionId);
|
|
1147
|
+
client.removeListener("data", dataHandler);
|
|
1125
1148
|
reject(error);
|
|
1126
1149
|
}
|
|
1127
|
-
}
|
|
1128
|
-
|
|
1150
|
+
};
|
|
1151
|
+
const closeHandler = () => {
|
|
1129
1152
|
globalTcpConnections.delete(this.connectionId);
|
|
1130
|
-
if (!isResolved
|
|
1131
|
-
|
|
1153
|
+
if (!isResolved) {
|
|
1154
|
+
isResolved = true;
|
|
1155
|
+
clearTimeout(timeout);
|
|
1156
|
+
client.removeListener("data", dataHandler);
|
|
1157
|
+
reject(new Error("Connection closed unexpectedly"));
|
|
1132
1158
|
}
|
|
1133
|
-
}
|
|
1159
|
+
};
|
|
1160
|
+
if (isNewConnection) {
|
|
1161
|
+
client.connect(this.tcpPort, "127.0.0.1", () => {
|
|
1162
|
+
clearTimeout(timeout);
|
|
1163
|
+
globalTcpConnections.set(this.connectionId, client);
|
|
1164
|
+
client.on("error", errorHandler);
|
|
1165
|
+
client.on("close", closeHandler);
|
|
1166
|
+
client.on("data", dataHandler);
|
|
1167
|
+
executeQuery();
|
|
1168
|
+
});
|
|
1169
|
+
} else {
|
|
1170
|
+
clearTimeout(timeout);
|
|
1171
|
+
client.on("data", dataHandler);
|
|
1172
|
+
executeQuery();
|
|
1173
|
+
}
|
|
1134
1174
|
});
|
|
1135
1175
|
}
|
|
1136
1176
|
async createProcess(binary, args) {
|