@dbcube/core 3.0.4 → 3.0.6
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 +402 -149
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +25 -12
- package/dist/index.d.ts +25 -12
- package/dist/index.js +399 -147
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -37,6 +37,7 @@ __export(index_exports, {
|
|
|
37
37
|
DbConfig: () => DbConfig,
|
|
38
38
|
Engine: () => Engine,
|
|
39
39
|
FileLogger: () => FileLogger,
|
|
40
|
+
QueryEngine: () => QueryEngine,
|
|
40
41
|
TableProcessor: () => TableProcessor,
|
|
41
42
|
TriggerProcessor: () => TriggerProcessor
|
|
42
43
|
});
|
|
@@ -600,10 +601,6 @@ var Engine = class {
|
|
|
600
601
|
arguments;
|
|
601
602
|
binary = null;
|
|
602
603
|
timeout;
|
|
603
|
-
childProcess = null;
|
|
604
|
-
pendingRequests = /* @__PURE__ */ new Map();
|
|
605
|
-
requestCounter = 0;
|
|
606
|
-
isProcessStarting = false;
|
|
607
604
|
constructor(name, timeout = 3e4) {
|
|
608
605
|
this.name = name;
|
|
609
606
|
this.config = this.setConfig(name);
|
|
@@ -626,9 +623,7 @@ var Engine = class {
|
|
|
626
623
|
"--database",
|
|
627
624
|
this.config.config.DATABASE + ".db",
|
|
628
625
|
"--motor",
|
|
629
|
-
this.config.type
|
|
630
|
-
"--persistent"
|
|
631
|
-
// Agregar flag para modo persistente si el binario lo soporta
|
|
626
|
+
this.config.type
|
|
632
627
|
];
|
|
633
628
|
} else {
|
|
634
629
|
args = [
|
|
@@ -647,9 +642,7 @@ var Engine = class {
|
|
|
647
642
|
"--password",
|
|
648
643
|
this.config.config.PASSWORD,
|
|
649
644
|
"--motor",
|
|
650
|
-
this.config.type
|
|
651
|
-
"--persistent"
|
|
652
|
-
// Agregar flag para modo persistente si el binario lo soporta
|
|
645
|
+
this.config.type
|
|
653
646
|
];
|
|
654
647
|
}
|
|
655
648
|
return args;
|
|
@@ -679,161 +672,420 @@ var Engine = class {
|
|
|
679
672
|
getConfig() {
|
|
680
673
|
return this.config;
|
|
681
674
|
}
|
|
682
|
-
async
|
|
683
|
-
|
|
684
|
-
|
|
675
|
+
async run(binary, args) {
|
|
676
|
+
await this.initializeBinary();
|
|
677
|
+
if (!this.binary) {
|
|
678
|
+
throw new Error("Binary not initialized");
|
|
685
679
|
}
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
680
|
+
return new Promise((resolve5, reject) => {
|
|
681
|
+
const child = (0, import_child_process.spawn)(this.binary[binary], [...this.arguments, ...args]);
|
|
682
|
+
let stdoutBuffer = "";
|
|
683
|
+
let stderrBuffer = "";
|
|
684
|
+
let isResolved = false;
|
|
685
|
+
const timeoutId = setTimeout(() => {
|
|
686
|
+
if (!isResolved) {
|
|
687
|
+
isResolved = true;
|
|
688
|
+
child.kill();
|
|
689
|
+
reject(new Error("Process timeout"));
|
|
690
|
+
}
|
|
691
|
+
}, this.timeout);
|
|
692
|
+
const resolveOnce = (response) => {
|
|
693
|
+
if (!isResolved) {
|
|
694
|
+
isResolved = true;
|
|
695
|
+
clearTimeout(timeoutId);
|
|
696
|
+
resolve5(response);
|
|
697
|
+
}
|
|
698
|
+
};
|
|
699
|
+
child.stdout.on("data", (data) => {
|
|
700
|
+
stdoutBuffer += data.toString();
|
|
701
|
+
const match = stdoutBuffer.match(/PROCESS_RESPONSE:(\{.*\})/);
|
|
702
|
+
if (match) {
|
|
703
|
+
try {
|
|
704
|
+
const response = JSON.parse(match[1]);
|
|
705
|
+
resolveOnce({
|
|
706
|
+
status: response.status,
|
|
707
|
+
message: response.message,
|
|
708
|
+
data: response.data
|
|
709
|
+
});
|
|
710
|
+
} catch (error) {
|
|
711
|
+
resolveOnce({
|
|
712
|
+
status: 500,
|
|
713
|
+
message: "Failed to parse response JSON",
|
|
714
|
+
data: null
|
|
715
|
+
});
|
|
693
716
|
}
|
|
694
|
-
}
|
|
695
|
-
checkProcess();
|
|
717
|
+
}
|
|
696
718
|
});
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
719
|
+
child.stderr.on("data", (data) => {
|
|
720
|
+
stderrBuffer += data.toString();
|
|
721
|
+
const match = stderrBuffer.match(/PROCESS_RESPONSE:(\{.*\})/);
|
|
722
|
+
if (match) {
|
|
723
|
+
try {
|
|
724
|
+
const response = JSON.parse(match[1]);
|
|
725
|
+
resolveOnce({
|
|
726
|
+
status: response.status,
|
|
727
|
+
message: response.message,
|
|
728
|
+
data: response.data
|
|
729
|
+
});
|
|
730
|
+
} catch (error) {
|
|
731
|
+
resolveOnce({
|
|
732
|
+
status: 500,
|
|
733
|
+
message: "Failed to parse response JSON",
|
|
734
|
+
data: null
|
|
735
|
+
});
|
|
736
|
+
}
|
|
737
|
+
}
|
|
706
738
|
});
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
let stdoutBuffer = "";
|
|
715
|
-
let stderrBuffer = "";
|
|
716
|
-
this.childProcess.stdout?.on("data", (data) => {
|
|
717
|
-
stdoutBuffer += data.toString();
|
|
718
|
-
this.processBuffer(stdoutBuffer, "stdout");
|
|
719
|
-
});
|
|
720
|
-
this.childProcess.stderr?.on("data", (data) => {
|
|
721
|
-
stderrBuffer += data.toString();
|
|
722
|
-
this.processBuffer(stderrBuffer, "stderr");
|
|
723
|
-
});
|
|
724
|
-
this.childProcess.on("close", (code) => {
|
|
725
|
-
this.handleProcessClose(code);
|
|
726
|
-
});
|
|
727
|
-
this.childProcess.on("error", (error) => {
|
|
728
|
-
this.handleProcessError(error);
|
|
729
|
-
});
|
|
730
|
-
this.childProcess.unref();
|
|
731
|
-
}
|
|
732
|
-
processBuffer(buffer, source) {
|
|
733
|
-
const responsePattern = /PROCESS_RESPONSE:(\{[^}]*\})/g;
|
|
734
|
-
let match;
|
|
735
|
-
while ((match = responsePattern.exec(buffer)) !== null) {
|
|
736
|
-
try {
|
|
737
|
-
const response = JSON.parse(match[1]);
|
|
738
|
-
const requestId = response.requestId || "unknown";
|
|
739
|
-
const pendingRequest = this.pendingRequests.get(requestId);
|
|
740
|
-
if (pendingRequest) {
|
|
741
|
-
clearTimeout(pendingRequest.timeoutId);
|
|
742
|
-
this.pendingRequests.delete(requestId);
|
|
743
|
-
pendingRequest.resolve({
|
|
744
|
-
status: response.status,
|
|
745
|
-
message: response.message,
|
|
746
|
-
data: response.data
|
|
739
|
+
child.on("close", (code) => {
|
|
740
|
+
clearTimeout(timeoutId);
|
|
741
|
+
if (!isResolved) {
|
|
742
|
+
resolveOnce({
|
|
743
|
+
status: code === 0 ? 200 : 500,
|
|
744
|
+
message: code === 0 ? "Process completed" : `Process exited with code ${code}`,
|
|
745
|
+
data: null
|
|
747
746
|
});
|
|
748
747
|
}
|
|
749
|
-
}
|
|
750
|
-
|
|
751
|
-
|
|
748
|
+
});
|
|
749
|
+
child.on("error", (error) => {
|
|
750
|
+
clearTimeout(timeoutId);
|
|
751
|
+
if (!isResolved) {
|
|
752
|
+
resolveOnce({
|
|
753
|
+
status: 500,
|
|
754
|
+
message: `Process error: ${error.message}`,
|
|
755
|
+
data: null
|
|
756
|
+
});
|
|
757
|
+
}
|
|
758
|
+
});
|
|
759
|
+
child.unref();
|
|
760
|
+
});
|
|
761
|
+
}
|
|
762
|
+
};
|
|
763
|
+
|
|
764
|
+
// src/lib/QueryEngine.ts
|
|
765
|
+
var import_path2 = __toESM(require("path"));
|
|
766
|
+
var import_module2 = require("module");
|
|
767
|
+
var net = __toESM(require("net"));
|
|
768
|
+
var import_child_process2 = require("child_process");
|
|
769
|
+
var globalTcpServers = /* @__PURE__ */ new Map();
|
|
770
|
+
var QueryEngine = class {
|
|
771
|
+
name;
|
|
772
|
+
config;
|
|
773
|
+
arguments;
|
|
774
|
+
binary = null;
|
|
775
|
+
timeout;
|
|
776
|
+
connectionId;
|
|
777
|
+
tcpPort;
|
|
778
|
+
constructor(name, timeout = 3e4) {
|
|
779
|
+
this.name = name;
|
|
780
|
+
this.config = this.setConfig(name);
|
|
781
|
+
this.arguments = this.setArguments();
|
|
782
|
+
this.timeout = timeout;
|
|
783
|
+
this.connectionId = `${name}_${this.config.type}_${this.config.config.DATABASE}_${this.config.config.HOST || "localhost"}`;
|
|
784
|
+
this.tcpPort = this.generatePort();
|
|
785
|
+
}
|
|
786
|
+
generatePort() {
|
|
787
|
+
let hash = 0;
|
|
788
|
+
for (let i = 0; i < this.connectionId.length; i++) {
|
|
789
|
+
const char = this.connectionId.charCodeAt(i);
|
|
790
|
+
hash = (hash << 5) - hash + char;
|
|
791
|
+
hash = hash & hash;
|
|
752
792
|
}
|
|
793
|
+
return 8100 + Math.abs(hash % 900);
|
|
753
794
|
}
|
|
754
|
-
|
|
755
|
-
this.
|
|
756
|
-
|
|
757
|
-
clearTimeout(request.timeoutId);
|
|
758
|
-
request.reject(new Error(`Process closed with code ${code}`));
|
|
795
|
+
async initializeBinary() {
|
|
796
|
+
if (!this.binary) {
|
|
797
|
+
this.binary = await Binary.get();
|
|
759
798
|
}
|
|
760
|
-
this.pendingRequests.clear();
|
|
761
799
|
}
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
800
|
+
setArguments() {
|
|
801
|
+
let args = [];
|
|
802
|
+
if (this.config.type == "sqlite") {
|
|
803
|
+
args = [
|
|
804
|
+
"--id",
|
|
805
|
+
"dbcube-" + this.name,
|
|
806
|
+
"--database-ref",
|
|
807
|
+
this.name,
|
|
808
|
+
"--database",
|
|
809
|
+
this.config.config.DATABASE + ".db",
|
|
810
|
+
"--motor",
|
|
811
|
+
this.config.type
|
|
812
|
+
];
|
|
813
|
+
} else {
|
|
814
|
+
args = [
|
|
815
|
+
"--id",
|
|
816
|
+
"dbcube-" + this.name,
|
|
817
|
+
"--database-ref",
|
|
818
|
+
this.name,
|
|
819
|
+
"--database",
|
|
820
|
+
this.config.config.DATABASE,
|
|
821
|
+
"--host",
|
|
822
|
+
this.config.config.HOST,
|
|
823
|
+
"--port",
|
|
824
|
+
this.config.config.PORT,
|
|
825
|
+
"--user",
|
|
826
|
+
this.config.config.USER,
|
|
827
|
+
"--password",
|
|
828
|
+
this.config.config.PASSWORD,
|
|
829
|
+
"--motor",
|
|
830
|
+
this.config.type
|
|
831
|
+
];
|
|
767
832
|
}
|
|
768
|
-
|
|
833
|
+
return args;
|
|
834
|
+
}
|
|
835
|
+
setConfig(name) {
|
|
836
|
+
const configInstance = new Config();
|
|
837
|
+
try {
|
|
838
|
+
const configFilePath = import_path2.default.resolve(process.cwd(), "dbcube.config.js");
|
|
839
|
+
const requireUrl = typeof __filename !== "undefined" ? __filename : process.cwd();
|
|
840
|
+
const require2 = (0, import_module2.createRequire)(requireUrl);
|
|
841
|
+
delete require2.cache[require2.resolve(configFilePath)];
|
|
842
|
+
const configModule = require2(configFilePath);
|
|
843
|
+
const configFn = configModule.default || configModule;
|
|
844
|
+
if (typeof configFn === "function") {
|
|
845
|
+
configFn(configInstance);
|
|
846
|
+
} else {
|
|
847
|
+
console.error("\u274C El archivo dbcube.config.js no exporta una funci\xF3n.");
|
|
848
|
+
}
|
|
849
|
+
} catch (error) {
|
|
850
|
+
console.error("\u274C Error loading config file:", error.message);
|
|
851
|
+
if (error.code === "MODULE_NOT_FOUND") {
|
|
852
|
+
console.error("\u274C Config file not found, please create a dbcube.config.js file");
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
return configInstance.getDatabase(name);
|
|
856
|
+
}
|
|
857
|
+
getConfig() {
|
|
858
|
+
return this.config;
|
|
769
859
|
}
|
|
770
860
|
async run(binary, args) {
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
861
|
+
const actionIndex = args.findIndex((arg) => arg === "--action");
|
|
862
|
+
const isExecuteAction = actionIndex !== -1 && args[actionIndex + 1] === "execute";
|
|
863
|
+
if (isExecuteAction) {
|
|
864
|
+
return this.executeWithTcpServer(args);
|
|
865
|
+
} else {
|
|
866
|
+
return this.createProcess(binary, args);
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
async executeWithTcpServer(args) {
|
|
870
|
+
const serverInfo = globalTcpServers.get(this.connectionId);
|
|
871
|
+
if (!serverInfo || !serverInfo.process || serverInfo.process.killed) {
|
|
872
|
+
console.log("\u{1F680} Starting TCP server for ultra-fast queries...");
|
|
873
|
+
await this.startTcpServer();
|
|
874
|
+
}
|
|
875
|
+
console.log("\u26A1 Using TCP server (ultra-fast)");
|
|
876
|
+
return this.sendTcpRequest(args);
|
|
877
|
+
}
|
|
878
|
+
async startTcpServer() {
|
|
879
|
+
await this.initializeBinary();
|
|
880
|
+
if (!this.binary) {
|
|
881
|
+
throw new Error("Binary not initialized");
|
|
774
882
|
}
|
|
775
883
|
return new Promise((resolve5, reject) => {
|
|
776
|
-
const
|
|
777
|
-
const
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
884
|
+
const serverArgs = [...this.arguments, "--action", "server", "--port", this.tcpPort.toString()];
|
|
885
|
+
const serverProcess = (0, import_child_process2.spawn)(this.binary["query_engine"], serverArgs);
|
|
886
|
+
let started = false;
|
|
887
|
+
const timeout = setTimeout(() => {
|
|
888
|
+
if (!started) {
|
|
889
|
+
serverProcess.kill();
|
|
890
|
+
reject(new Error("TCP server startup timeout"));
|
|
782
891
|
}
|
|
892
|
+
}, 1e4);
|
|
893
|
+
serverProcess.stdout.on("data", (data) => {
|
|
894
|
+
const output = data.toString();
|
|
895
|
+
console.log(`[TCP Server] ${output.trim()}`);
|
|
896
|
+
if (output.includes("TCP Server listening on")) {
|
|
897
|
+
if (!started) {
|
|
898
|
+
started = true;
|
|
899
|
+
clearTimeout(timeout);
|
|
900
|
+
globalTcpServers.set(this.connectionId, {
|
|
901
|
+
port: this.tcpPort,
|
|
902
|
+
process: serverProcess
|
|
903
|
+
});
|
|
904
|
+
resolve5();
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
});
|
|
908
|
+
serverProcess.stderr.on("data", (data) => {
|
|
909
|
+
console.error(`[TCP Server Error] ${data.toString().trim()}`);
|
|
910
|
+
});
|
|
911
|
+
serverProcess.on("close", (code) => {
|
|
912
|
+
console.log(`[TCP Server] Process exited with code ${code}`);
|
|
913
|
+
globalTcpServers.delete(this.connectionId);
|
|
914
|
+
});
|
|
915
|
+
serverProcess.on("error", (error) => {
|
|
916
|
+
if (!started) {
|
|
917
|
+
clearTimeout(timeout);
|
|
918
|
+
reject(error);
|
|
919
|
+
}
|
|
920
|
+
});
|
|
921
|
+
});
|
|
922
|
+
}
|
|
923
|
+
async sendTcpRequest(args) {
|
|
924
|
+
return new Promise((resolve5, reject) => {
|
|
925
|
+
const client = new net.Socket();
|
|
926
|
+
let responseBuffer = "";
|
|
927
|
+
const timeout = setTimeout(() => {
|
|
928
|
+
client.destroy();
|
|
929
|
+
reject(new Error("TCP request timeout"));
|
|
783
930
|
}, this.timeout);
|
|
784
|
-
this.
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
931
|
+
client.connect(this.tcpPort, "127.0.0.1", () => {
|
|
932
|
+
const dmlIndex = args.findIndex((arg) => arg === "--dml");
|
|
933
|
+
const dmlJson = dmlIndex !== -1 ? args[dmlIndex + 1] : null;
|
|
934
|
+
if (!dmlJson) {
|
|
935
|
+
client.destroy();
|
|
936
|
+
reject(new Error("No DML found in arguments"));
|
|
937
|
+
return;
|
|
938
|
+
}
|
|
939
|
+
const command = {
|
|
940
|
+
action: "execute",
|
|
941
|
+
dml: dmlJson
|
|
942
|
+
};
|
|
943
|
+
client.write(JSON.stringify(command));
|
|
789
944
|
});
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
945
|
+
client.on("data", (data) => {
|
|
946
|
+
responseBuffer += data.toString();
|
|
947
|
+
const match = responseBuffer.match(/PROCESS_RESPONSE:(\{.*\})/);
|
|
948
|
+
if (match) {
|
|
949
|
+
clearTimeout(timeout);
|
|
950
|
+
client.destroy();
|
|
951
|
+
try {
|
|
952
|
+
const response = JSON.parse(match[1]);
|
|
953
|
+
resolve5({
|
|
954
|
+
status: response.status,
|
|
955
|
+
message: response.message,
|
|
956
|
+
data: response.data
|
|
957
|
+
});
|
|
958
|
+
} catch (error) {
|
|
959
|
+
reject(new Error("Failed to parse TCP response"));
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
});
|
|
963
|
+
client.on("error", (error) => {
|
|
964
|
+
clearTimeout(timeout);
|
|
799
965
|
reject(error);
|
|
800
|
-
}
|
|
966
|
+
});
|
|
967
|
+
client.on("close", () => {
|
|
968
|
+
clearTimeout(timeout);
|
|
969
|
+
if (responseBuffer && !responseBuffer.includes("\n")) {
|
|
970
|
+
reject(new Error("Incomplete TCP response"));
|
|
971
|
+
}
|
|
972
|
+
});
|
|
801
973
|
});
|
|
802
974
|
}
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
if (
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
975
|
+
async createProcess(binary, args) {
|
|
976
|
+
await this.initializeBinary();
|
|
977
|
+
if (!this.binary) {
|
|
978
|
+
throw new Error("Binary not initialized");
|
|
979
|
+
}
|
|
980
|
+
return new Promise((resolve5, reject) => {
|
|
981
|
+
const child = (0, import_child_process2.spawn)(this.binary[binary], [...this.arguments, ...args]);
|
|
982
|
+
let stdoutBuffer = "";
|
|
983
|
+
let stderrBuffer = "";
|
|
984
|
+
let isResolved = false;
|
|
985
|
+
const timeoutId = setTimeout(() => {
|
|
986
|
+
if (!isResolved) {
|
|
987
|
+
isResolved = true;
|
|
988
|
+
child.kill();
|
|
989
|
+
reject(new Error("Process timeout"));
|
|
990
|
+
}
|
|
991
|
+
}, this.timeout);
|
|
992
|
+
const resolveOnce = (response) => {
|
|
993
|
+
if (!isResolved) {
|
|
994
|
+
isResolved = true;
|
|
995
|
+
clearTimeout(timeoutId);
|
|
996
|
+
resolve5(response);
|
|
997
|
+
}
|
|
998
|
+
};
|
|
999
|
+
child.stdout.on("data", (data) => {
|
|
1000
|
+
stdoutBuffer += data.toString();
|
|
1001
|
+
const match = stdoutBuffer.match(/PROCESS_RESPONSE:(\{.*\})/);
|
|
1002
|
+
if (match) {
|
|
1003
|
+
try {
|
|
1004
|
+
const response = JSON.parse(match[1]);
|
|
1005
|
+
resolveOnce({
|
|
1006
|
+
status: response.status,
|
|
1007
|
+
message: response.message,
|
|
1008
|
+
data: response.data
|
|
1009
|
+
});
|
|
1010
|
+
} catch (error) {
|
|
1011
|
+
resolveOnce({
|
|
1012
|
+
status: 500,
|
|
1013
|
+
message: "Failed to parse response JSON",
|
|
1014
|
+
data: null
|
|
1015
|
+
});
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
});
|
|
1019
|
+
child.stderr.on("data", (data) => {
|
|
1020
|
+
stderrBuffer += data.toString();
|
|
1021
|
+
const match = stderrBuffer.match(/PROCESS_RESPONSE:(\{.*\})/);
|
|
1022
|
+
if (match) {
|
|
1023
|
+
try {
|
|
1024
|
+
const response = JSON.parse(match[1]);
|
|
1025
|
+
resolveOnce({
|
|
1026
|
+
status: response.status,
|
|
1027
|
+
message: response.message,
|
|
1028
|
+
data: response.data
|
|
1029
|
+
});
|
|
1030
|
+
} catch (error) {
|
|
1031
|
+
resolveOnce({
|
|
1032
|
+
status: 500,
|
|
1033
|
+
message: "Failed to parse response JSON",
|
|
1034
|
+
data: null
|
|
1035
|
+
});
|
|
819
1036
|
}
|
|
820
|
-
}
|
|
1037
|
+
}
|
|
821
1038
|
});
|
|
822
|
-
|
|
1039
|
+
child.on("close", (code) => {
|
|
1040
|
+
clearTimeout(timeoutId);
|
|
1041
|
+
if (!isResolved) {
|
|
1042
|
+
resolveOnce({
|
|
1043
|
+
status: code === 0 ? 200 : 500,
|
|
1044
|
+
message: code === 0 ? "Process completed" : `Process exited with code ${code}`,
|
|
1045
|
+
data: null
|
|
1046
|
+
});
|
|
1047
|
+
}
|
|
1048
|
+
});
|
|
1049
|
+
child.on("error", (error) => {
|
|
1050
|
+
clearTimeout(timeoutId);
|
|
1051
|
+
if (!isResolved) {
|
|
1052
|
+
resolveOnce({
|
|
1053
|
+
status: 500,
|
|
1054
|
+
message: `Process error: ${error.message}`,
|
|
1055
|
+
data: null
|
|
1056
|
+
});
|
|
1057
|
+
}
|
|
1058
|
+
});
|
|
1059
|
+
child.unref();
|
|
1060
|
+
});
|
|
823
1061
|
}
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
1062
|
+
async disconnect() {
|
|
1063
|
+
const serverInfo = globalTcpServers.get(this.connectionId);
|
|
1064
|
+
if (serverInfo && serverInfo.process && !serverInfo.process.killed) {
|
|
1065
|
+
console.log("\u{1F50C} Stopping TCP server...");
|
|
1066
|
+
serverInfo.process.kill();
|
|
1067
|
+
globalTcpServers.delete(this.connectionId);
|
|
1068
|
+
return {
|
|
1069
|
+
status: 200,
|
|
1070
|
+
message: "TCP server stopped",
|
|
1071
|
+
data: null
|
|
1072
|
+
};
|
|
1073
|
+
}
|
|
1074
|
+
return {
|
|
1075
|
+
status: 200,
|
|
1076
|
+
message: "No TCP server to stop",
|
|
1077
|
+
data: null
|
|
1078
|
+
};
|
|
827
1079
|
}
|
|
828
1080
|
};
|
|
829
1081
|
|
|
830
1082
|
// src/lib/SqliteExecutor.ts
|
|
831
|
-
var
|
|
832
|
-
var
|
|
1083
|
+
var import_child_process3 = require("child_process");
|
|
1084
|
+
var path5 = __toESM(require("path"));
|
|
833
1085
|
var fs3 = __toESM(require("fs"));
|
|
834
1086
|
var import_util = require("util");
|
|
835
|
-
var
|
|
836
|
-
var execAsync = (0, import_util.promisify)(
|
|
1087
|
+
var import_module3 = require("module");
|
|
1088
|
+
var execAsync = (0, import_util.promisify)(import_child_process3.exec);
|
|
837
1089
|
var SqliteExecutor = class {
|
|
838
1090
|
binaryPath;
|
|
839
1091
|
dbPath;
|
|
@@ -843,27 +1095,27 @@ var SqliteExecutor = class {
|
|
|
843
1095
|
}
|
|
844
1096
|
getBinaryPath() {
|
|
845
1097
|
const possibleDirs = [
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
1098
|
+
path5.resolve(process.cwd(), ".dbcube", "bin"),
|
|
1099
|
+
path5.resolve(process.cwd(), "node_modules", ".dbcube", "bin"),
|
|
1100
|
+
path5.resolve(__dirname, "..", "bin")
|
|
849
1101
|
];
|
|
850
1102
|
const platform2 = process.platform;
|
|
851
1103
|
const extension = platform2 === "win32" ? ".exe" : "";
|
|
852
1104
|
const binaryName = `sqlite-engine-${platform2 === "win32" ? "windows" : platform2 === "darwin" ? "macos" : "linux"}-x64${extension}`;
|
|
853
1105
|
for (const dir of possibleDirs) {
|
|
854
|
-
const fullPath =
|
|
1106
|
+
const fullPath = path5.join(dir, binaryName);
|
|
855
1107
|
if (fs3.existsSync(fullPath)) {
|
|
856
1108
|
return fullPath;
|
|
857
1109
|
}
|
|
858
1110
|
}
|
|
859
1111
|
const fallbackName = `sqlite-engine${extension}`;
|
|
860
1112
|
for (const dir of possibleDirs) {
|
|
861
|
-
const fullPath =
|
|
1113
|
+
const fullPath = path5.join(dir, fallbackName);
|
|
862
1114
|
if (fs3.existsSync(fullPath)) {
|
|
863
1115
|
return fullPath;
|
|
864
1116
|
}
|
|
865
1117
|
}
|
|
866
|
-
return
|
|
1118
|
+
return path5.join(possibleDirs[0], binaryName);
|
|
867
1119
|
}
|
|
868
1120
|
async executeBinary(args) {
|
|
869
1121
|
const escapedArgs = args.map((arg) => {
|
|
@@ -965,7 +1217,7 @@ var SqliteExecutor = class {
|
|
|
965
1217
|
// Para compatibilidad con better-sqlite3 API sincrona usando deasync si es necesario
|
|
966
1218
|
prepareSync(sql) {
|
|
967
1219
|
const requireUrl = typeof __filename !== "undefined" ? __filename : process.cwd();
|
|
968
|
-
const require2 = (0,
|
|
1220
|
+
const require2 = (0, import_module3.createRequire)(requireUrl);
|
|
969
1221
|
const deasync = require2("deasync");
|
|
970
1222
|
return {
|
|
971
1223
|
all: (...params) => {
|
|
@@ -1013,9 +1265,9 @@ var SqliteExecutor = class {
|
|
|
1013
1265
|
};
|
|
1014
1266
|
|
|
1015
1267
|
// src/lib/DbConfig.ts
|
|
1016
|
-
var
|
|
1268
|
+
var path6 = __toESM(require("path"));
|
|
1017
1269
|
var import_fs = __toESM(require("fs"));
|
|
1018
|
-
var rootPath =
|
|
1270
|
+
var rootPath = path6.resolve(process.cwd(), ".dbcube");
|
|
1019
1271
|
var SQLite = class {
|
|
1020
1272
|
executor = null;
|
|
1021
1273
|
database;
|
|
@@ -1025,7 +1277,7 @@ var SQLite = class {
|
|
|
1025
1277
|
async ifExist() {
|
|
1026
1278
|
if (this.database) {
|
|
1027
1279
|
const dbPath = this.database || ":memory:";
|
|
1028
|
-
const configPath =
|
|
1280
|
+
const configPath = path6.join(rootPath, dbPath + ".db");
|
|
1029
1281
|
if (!import_fs.default.existsSync(rootPath)) {
|
|
1030
1282
|
import_fs.default.mkdirSync(rootPath, { recursive: true });
|
|
1031
1283
|
}
|
|
@@ -1044,7 +1296,7 @@ var SQLite = class {
|
|
|
1044
1296
|
try {
|
|
1045
1297
|
if (!this.executor) {
|
|
1046
1298
|
const dbPath = this.database || ":memory:";
|
|
1047
|
-
const configPath =
|
|
1299
|
+
const configPath = path6.join(rootPath, dbPath + ".db");
|
|
1048
1300
|
if (!import_fs.default.existsSync(rootPath)) {
|
|
1049
1301
|
import_fs.default.mkdirSync(rootPath, { recursive: true });
|
|
1050
1302
|
}
|
|
@@ -1229,7 +1481,7 @@ var DbConfig_default = DbConfig;
|
|
|
1229
1481
|
|
|
1230
1482
|
// src/lib/FileLogger.ts
|
|
1231
1483
|
var fs5 = __toESM(require("fs"));
|
|
1232
|
-
var
|
|
1484
|
+
var path7 = __toESM(require("path"));
|
|
1233
1485
|
var import_events = require("events");
|
|
1234
1486
|
var FileLogger = class _FileLogger extends import_events.EventEmitter {
|
|
1235
1487
|
static watchers = /* @__PURE__ */ new Map();
|
|
@@ -1244,7 +1496,7 @@ var FileLogger = class _FileLogger extends import_events.EventEmitter {
|
|
|
1244
1496
|
*/
|
|
1245
1497
|
static async write(filePath, message, level = "INFO", append = true) {
|
|
1246
1498
|
try {
|
|
1247
|
-
const dir =
|
|
1499
|
+
const dir = path7.dirname(filePath);
|
|
1248
1500
|
if (!fs5.existsSync(dir)) {
|
|
1249
1501
|
fs5.mkdirSync(dir, { recursive: true });
|
|
1250
1502
|
}
|
|
@@ -1283,7 +1535,7 @@ var FileLogger = class _FileLogger extends import_events.EventEmitter {
|
|
|
1283
1535
|
const buffer = _FileLogger.buffers.get(filePath);
|
|
1284
1536
|
if (buffer && buffer.length > 0) {
|
|
1285
1537
|
try {
|
|
1286
|
-
const dir =
|
|
1538
|
+
const dir = path7.dirname(filePath);
|
|
1287
1539
|
if (!fs5.existsSync(dir)) {
|
|
1288
1540
|
fs5.mkdirSync(dir, { recursive: true });
|
|
1289
1541
|
}
|
|
@@ -2007,6 +2259,7 @@ function convertToType(value, type2) {
|
|
|
2007
2259
|
DbConfig,
|
|
2008
2260
|
Engine,
|
|
2009
2261
|
FileLogger,
|
|
2262
|
+
QueryEngine,
|
|
2010
2263
|
TableProcessor,
|
|
2011
2264
|
TriggerProcessor
|
|
2012
2265
|
});
|