@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.cjs
CHANGED
|
@@ -653,7 +653,12 @@ var Engine = class {
|
|
|
653
653
|
const configFilePath = import_path.default.resolve(process.cwd(), "dbcube.config.js");
|
|
654
654
|
const requireUrl = typeof __filename !== "undefined" ? __filename : process.cwd();
|
|
655
655
|
const require2 = (0, import_module.createRequire)(requireUrl);
|
|
656
|
-
|
|
656
|
+
if (require2.cache && require2.resolve) {
|
|
657
|
+
try {
|
|
658
|
+
delete require2.cache[require2.resolve(configFilePath)];
|
|
659
|
+
} catch (e) {
|
|
660
|
+
}
|
|
661
|
+
}
|
|
657
662
|
const configModule = require2(configFilePath);
|
|
658
663
|
const configFn = configModule.default || configModule;
|
|
659
664
|
if (typeof configFn === "function") {
|
|
@@ -857,7 +862,12 @@ var QueryEngine = class {
|
|
|
857
862
|
const configFilePath = import_path2.default.resolve(process.cwd(), "dbcube.config.js");
|
|
858
863
|
const requireUrl = typeof __filename !== "undefined" ? __filename : process.cwd();
|
|
859
864
|
const require2 = (0, import_module2.createRequire)(requireUrl);
|
|
860
|
-
|
|
865
|
+
if (require2.cache && require2.resolve) {
|
|
866
|
+
try {
|
|
867
|
+
delete require2.cache[require2.resolve(configFilePath)];
|
|
868
|
+
} catch (e) {
|
|
869
|
+
}
|
|
870
|
+
}
|
|
861
871
|
const configModule = require2(configFilePath);
|
|
862
872
|
const configFn = configModule.default || configModule;
|
|
863
873
|
if (typeof configFn === "function") {
|
|
@@ -1114,68 +1124,98 @@ var QueryEngine = class {
|
|
|
1114
1124
|
}
|
|
1115
1125
|
async createPersistentConnection(args) {
|
|
1116
1126
|
return new Promise((resolve5, reject) => {
|
|
1117
|
-
|
|
1127
|
+
let client = globalTcpConnections.get(this.connectionId);
|
|
1128
|
+
let isNewConnection = false;
|
|
1129
|
+
if (!client || client.destroyed) {
|
|
1130
|
+
client = new net.Socket();
|
|
1131
|
+
isNewConnection = true;
|
|
1132
|
+
client.setNoDelay(true);
|
|
1133
|
+
client.setKeepAlive(true, 6e4);
|
|
1134
|
+
client.setMaxListeners(20);
|
|
1135
|
+
}
|
|
1118
1136
|
let responseBuffer = "";
|
|
1119
1137
|
let isResolved = false;
|
|
1120
|
-
client.setNoDelay(true);
|
|
1121
|
-
client.setKeepAlive(true, 6e4);
|
|
1122
1138
|
const timeout = setTimeout(() => {
|
|
1123
1139
|
if (!isResolved) {
|
|
1124
1140
|
isResolved = true;
|
|
1125
|
-
client.destroy();
|
|
1126
1141
|
reject(new Error("TCP connection timeout"));
|
|
1127
1142
|
}
|
|
1128
1143
|
}, 5e3);
|
|
1129
|
-
|
|
1130
|
-
clearTimeout(timeout);
|
|
1144
|
+
const executeQuery = () => {
|
|
1131
1145
|
const dmlIndex = args.findIndex((arg) => arg === "--dml");
|
|
1132
1146
|
const dmlJson = dmlIndex !== -1 ? args[dmlIndex + 1] : null;
|
|
1133
1147
|
if (!dmlJson) {
|
|
1148
|
+
clearTimeout(timeout);
|
|
1134
1149
|
if (!isResolved) {
|
|
1135
1150
|
isResolved = true;
|
|
1136
|
-
client.destroy();
|
|
1137
1151
|
reject(new Error("No DML found in arguments"));
|
|
1138
1152
|
}
|
|
1139
1153
|
return;
|
|
1140
1154
|
}
|
|
1141
|
-
globalTcpConnections.set(this.connectionId, client);
|
|
1142
1155
|
const command = {
|
|
1143
1156
|
action: "execute",
|
|
1144
1157
|
dml: dmlJson
|
|
1145
1158
|
};
|
|
1146
|
-
|
|
1147
|
-
client.write(
|
|
1148
|
-
|
|
1149
|
-
|
|
1159
|
+
const commandStr = JSON.stringify(command);
|
|
1160
|
+
const canWrite = client.write(commandStr);
|
|
1161
|
+
if (!canWrite) {
|
|
1162
|
+
client.once("drain", () => {
|
|
1163
|
+
});
|
|
1164
|
+
}
|
|
1165
|
+
};
|
|
1166
|
+
const dataHandler = (data) => {
|
|
1150
1167
|
responseBuffer += data.toString();
|
|
1151
1168
|
const match = responseBuffer.match(/PROCESS_RESPONSE:(\{.*\})/);
|
|
1152
1169
|
if (match && !isResolved) {
|
|
1153
1170
|
isResolved = true;
|
|
1171
|
+
clearTimeout(timeout);
|
|
1154
1172
|
try {
|
|
1155
1173
|
const response = JSON.parse(match[1]);
|
|
1174
|
+
responseBuffer = "";
|
|
1175
|
+
client.removeListener("data", dataHandler);
|
|
1156
1176
|
resolve5({
|
|
1157
1177
|
status: response.status,
|
|
1158
1178
|
message: response.message,
|
|
1159
1179
|
data: response.data
|
|
1160
1180
|
});
|
|
1161
1181
|
} catch (error) {
|
|
1182
|
+
client.removeListener("data", dataHandler);
|
|
1162
1183
|
reject(new Error("Failed to parse TCP response"));
|
|
1163
1184
|
}
|
|
1164
1185
|
}
|
|
1165
|
-
}
|
|
1166
|
-
|
|
1186
|
+
};
|
|
1187
|
+
const errorHandler = (error) => {
|
|
1167
1188
|
if (!isResolved) {
|
|
1168
1189
|
isResolved = true;
|
|
1190
|
+
clearTimeout(timeout);
|
|
1169
1191
|
globalTcpConnections.delete(this.connectionId);
|
|
1192
|
+
client.removeListener("data", dataHandler);
|
|
1170
1193
|
reject(error);
|
|
1171
1194
|
}
|
|
1172
|
-
}
|
|
1173
|
-
|
|
1195
|
+
};
|
|
1196
|
+
const closeHandler = () => {
|
|
1174
1197
|
globalTcpConnections.delete(this.connectionId);
|
|
1175
|
-
if (!isResolved
|
|
1176
|
-
|
|
1198
|
+
if (!isResolved) {
|
|
1199
|
+
isResolved = true;
|
|
1200
|
+
clearTimeout(timeout);
|
|
1201
|
+
client.removeListener("data", dataHandler);
|
|
1202
|
+
reject(new Error("Connection closed unexpectedly"));
|
|
1177
1203
|
}
|
|
1178
|
-
}
|
|
1204
|
+
};
|
|
1205
|
+
if (isNewConnection) {
|
|
1206
|
+
client.connect(this.tcpPort, "127.0.0.1", () => {
|
|
1207
|
+
clearTimeout(timeout);
|
|
1208
|
+
globalTcpConnections.set(this.connectionId, client);
|
|
1209
|
+
client.on("error", errorHandler);
|
|
1210
|
+
client.on("close", closeHandler);
|
|
1211
|
+
client.on("data", dataHandler);
|
|
1212
|
+
executeQuery();
|
|
1213
|
+
});
|
|
1214
|
+
} else {
|
|
1215
|
+
clearTimeout(timeout);
|
|
1216
|
+
client.on("data", dataHandler);
|
|
1217
|
+
executeQuery();
|
|
1218
|
+
}
|
|
1179
1219
|
});
|
|
1180
1220
|
}
|
|
1181
1221
|
async createProcess(binary, args) {
|