@dbcube/core 3.0.4 → 3.0.5
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 +394 -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 +391 -147
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -556,10 +556,6 @@ var Engine = class {
|
|
|
556
556
|
arguments;
|
|
557
557
|
binary = null;
|
|
558
558
|
timeout;
|
|
559
|
-
childProcess = null;
|
|
560
|
-
pendingRequests = /* @__PURE__ */ new Map();
|
|
561
|
-
requestCounter = 0;
|
|
562
|
-
isProcessStarting = false;
|
|
563
559
|
constructor(name, timeout = 3e4) {
|
|
564
560
|
this.name = name;
|
|
565
561
|
this.config = this.setConfig(name);
|
|
@@ -582,9 +578,7 @@ var Engine = class {
|
|
|
582
578
|
"--database",
|
|
583
579
|
this.config.config.DATABASE + ".db",
|
|
584
580
|
"--motor",
|
|
585
|
-
this.config.type
|
|
586
|
-
"--persistent"
|
|
587
|
-
// Agregar flag para modo persistente si el binario lo soporta
|
|
581
|
+
this.config.type
|
|
588
582
|
];
|
|
589
583
|
} else {
|
|
590
584
|
args = [
|
|
@@ -603,9 +597,7 @@ var Engine = class {
|
|
|
603
597
|
"--password",
|
|
604
598
|
this.config.config.PASSWORD,
|
|
605
599
|
"--motor",
|
|
606
|
-
this.config.type
|
|
607
|
-
"--persistent"
|
|
608
|
-
// Agregar flag para modo persistente si el binario lo soporta
|
|
600
|
+
this.config.type
|
|
609
601
|
];
|
|
610
602
|
}
|
|
611
603
|
return args;
|
|
@@ -635,160 +627,411 @@ var Engine = class {
|
|
|
635
627
|
getConfig() {
|
|
636
628
|
return this.config;
|
|
637
629
|
}
|
|
638
|
-
async
|
|
639
|
-
|
|
640
|
-
|
|
630
|
+
async run(binary, args) {
|
|
631
|
+
await this.initializeBinary();
|
|
632
|
+
if (!this.binary) {
|
|
633
|
+
throw new Error("Binary not initialized");
|
|
641
634
|
}
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
635
|
+
return new Promise((resolve5, reject) => {
|
|
636
|
+
const child = spawn(this.binary[binary], [...this.arguments, ...args]);
|
|
637
|
+
let stdoutBuffer = "";
|
|
638
|
+
let stderrBuffer = "";
|
|
639
|
+
let isResolved = false;
|
|
640
|
+
const timeoutId = setTimeout(() => {
|
|
641
|
+
if (!isResolved) {
|
|
642
|
+
isResolved = true;
|
|
643
|
+
child.kill();
|
|
644
|
+
reject(new Error("Process timeout"));
|
|
645
|
+
}
|
|
646
|
+
}, this.timeout);
|
|
647
|
+
const resolveOnce = (response) => {
|
|
648
|
+
if (!isResolved) {
|
|
649
|
+
isResolved = true;
|
|
650
|
+
clearTimeout(timeoutId);
|
|
651
|
+
resolve5(response);
|
|
652
|
+
}
|
|
653
|
+
};
|
|
654
|
+
child.stdout.on("data", (data) => {
|
|
655
|
+
stdoutBuffer += data.toString();
|
|
656
|
+
const match = stdoutBuffer.match(/PROCESS_RESPONSE:(\{.*\})/);
|
|
657
|
+
if (match) {
|
|
658
|
+
try {
|
|
659
|
+
const response = JSON.parse(match[1]);
|
|
660
|
+
resolveOnce({
|
|
661
|
+
status: response.status,
|
|
662
|
+
message: response.message,
|
|
663
|
+
data: response.data
|
|
664
|
+
});
|
|
665
|
+
} catch (error) {
|
|
666
|
+
resolveOnce({
|
|
667
|
+
status: 500,
|
|
668
|
+
message: "Failed to parse response JSON",
|
|
669
|
+
data: null
|
|
670
|
+
});
|
|
649
671
|
}
|
|
650
|
-
}
|
|
651
|
-
checkProcess();
|
|
672
|
+
}
|
|
652
673
|
});
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
674
|
+
child.stderr.on("data", (data) => {
|
|
675
|
+
stderrBuffer += data.toString();
|
|
676
|
+
const match = stderrBuffer.match(/PROCESS_RESPONSE:(\{.*\})/);
|
|
677
|
+
if (match) {
|
|
678
|
+
try {
|
|
679
|
+
const response = JSON.parse(match[1]);
|
|
680
|
+
resolveOnce({
|
|
681
|
+
status: response.status,
|
|
682
|
+
message: response.message,
|
|
683
|
+
data: response.data
|
|
684
|
+
});
|
|
685
|
+
} catch (error) {
|
|
686
|
+
resolveOnce({
|
|
687
|
+
status: 500,
|
|
688
|
+
message: "Failed to parse response JSON",
|
|
689
|
+
data: null
|
|
690
|
+
});
|
|
691
|
+
}
|
|
692
|
+
}
|
|
662
693
|
});
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
let stdoutBuffer = "";
|
|
671
|
-
let stderrBuffer = "";
|
|
672
|
-
this.childProcess.stdout?.on("data", (data) => {
|
|
673
|
-
stdoutBuffer += data.toString();
|
|
674
|
-
this.processBuffer(stdoutBuffer, "stdout");
|
|
675
|
-
});
|
|
676
|
-
this.childProcess.stderr?.on("data", (data) => {
|
|
677
|
-
stderrBuffer += data.toString();
|
|
678
|
-
this.processBuffer(stderrBuffer, "stderr");
|
|
679
|
-
});
|
|
680
|
-
this.childProcess.on("close", (code) => {
|
|
681
|
-
this.handleProcessClose(code);
|
|
682
|
-
});
|
|
683
|
-
this.childProcess.on("error", (error) => {
|
|
684
|
-
this.handleProcessError(error);
|
|
685
|
-
});
|
|
686
|
-
this.childProcess.unref();
|
|
687
|
-
}
|
|
688
|
-
processBuffer(buffer, source) {
|
|
689
|
-
const responsePattern = /PROCESS_RESPONSE:(\{[^}]*\})/g;
|
|
690
|
-
let match;
|
|
691
|
-
while ((match = responsePattern.exec(buffer)) !== null) {
|
|
692
|
-
try {
|
|
693
|
-
const response = JSON.parse(match[1]);
|
|
694
|
-
const requestId = response.requestId || "unknown";
|
|
695
|
-
const pendingRequest = this.pendingRequests.get(requestId);
|
|
696
|
-
if (pendingRequest) {
|
|
697
|
-
clearTimeout(pendingRequest.timeoutId);
|
|
698
|
-
this.pendingRequests.delete(requestId);
|
|
699
|
-
pendingRequest.resolve({
|
|
700
|
-
status: response.status,
|
|
701
|
-
message: response.message,
|
|
702
|
-
data: response.data
|
|
694
|
+
child.on("close", (code) => {
|
|
695
|
+
clearTimeout(timeoutId);
|
|
696
|
+
if (!isResolved) {
|
|
697
|
+
resolveOnce({
|
|
698
|
+
status: code === 0 ? 200 : 500,
|
|
699
|
+
message: code === 0 ? "Process completed" : `Process exited with code ${code}`,
|
|
700
|
+
data: null
|
|
703
701
|
});
|
|
704
702
|
}
|
|
705
|
-
}
|
|
706
|
-
|
|
707
|
-
|
|
703
|
+
});
|
|
704
|
+
child.on("error", (error) => {
|
|
705
|
+
clearTimeout(timeoutId);
|
|
706
|
+
if (!isResolved) {
|
|
707
|
+
resolveOnce({
|
|
708
|
+
status: 500,
|
|
709
|
+
message: `Process error: ${error.message}`,
|
|
710
|
+
data: null
|
|
711
|
+
});
|
|
712
|
+
}
|
|
713
|
+
});
|
|
714
|
+
child.unref();
|
|
715
|
+
});
|
|
716
|
+
}
|
|
717
|
+
};
|
|
718
|
+
|
|
719
|
+
// src/lib/QueryEngine.ts
|
|
720
|
+
import path4 from "path";
|
|
721
|
+
import { createRequire as createRequire2 } from "module";
|
|
722
|
+
import * as net from "net";
|
|
723
|
+
import { spawn as spawn2 } from "child_process";
|
|
724
|
+
var globalTcpServers = /* @__PURE__ */ new Map();
|
|
725
|
+
var QueryEngine = class {
|
|
726
|
+
name;
|
|
727
|
+
config;
|
|
728
|
+
arguments;
|
|
729
|
+
binary = null;
|
|
730
|
+
timeout;
|
|
731
|
+
connectionId;
|
|
732
|
+
tcpPort;
|
|
733
|
+
constructor(name, timeout = 3e4) {
|
|
734
|
+
this.name = name;
|
|
735
|
+
this.config = this.setConfig(name);
|
|
736
|
+
this.arguments = this.setArguments();
|
|
737
|
+
this.timeout = timeout;
|
|
738
|
+
this.connectionId = `${name}_${this.config.type}_${this.config.config.DATABASE}_${this.config.config.HOST || "localhost"}`;
|
|
739
|
+
this.tcpPort = this.generatePort();
|
|
740
|
+
}
|
|
741
|
+
generatePort() {
|
|
742
|
+
let hash = 0;
|
|
743
|
+
for (let i = 0; i < this.connectionId.length; i++) {
|
|
744
|
+
const char = this.connectionId.charCodeAt(i);
|
|
745
|
+
hash = (hash << 5) - hash + char;
|
|
746
|
+
hash = hash & hash;
|
|
708
747
|
}
|
|
748
|
+
return 8100 + Math.abs(hash % 900);
|
|
709
749
|
}
|
|
710
|
-
|
|
711
|
-
this.
|
|
712
|
-
|
|
713
|
-
clearTimeout(request.timeoutId);
|
|
714
|
-
request.reject(new Error(`Process closed with code ${code}`));
|
|
750
|
+
async initializeBinary() {
|
|
751
|
+
if (!this.binary) {
|
|
752
|
+
this.binary = await Binary.get();
|
|
715
753
|
}
|
|
716
|
-
this.pendingRequests.clear();
|
|
717
754
|
}
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
755
|
+
setArguments() {
|
|
756
|
+
let args = [];
|
|
757
|
+
if (this.config.type == "sqlite") {
|
|
758
|
+
args = [
|
|
759
|
+
"--id",
|
|
760
|
+
"dbcube-" + this.name,
|
|
761
|
+
"--database-ref",
|
|
762
|
+
this.name,
|
|
763
|
+
"--database",
|
|
764
|
+
this.config.config.DATABASE + ".db",
|
|
765
|
+
"--motor",
|
|
766
|
+
this.config.type
|
|
767
|
+
];
|
|
768
|
+
} else {
|
|
769
|
+
args = [
|
|
770
|
+
"--id",
|
|
771
|
+
"dbcube-" + this.name,
|
|
772
|
+
"--database-ref",
|
|
773
|
+
this.name,
|
|
774
|
+
"--database",
|
|
775
|
+
this.config.config.DATABASE,
|
|
776
|
+
"--host",
|
|
777
|
+
this.config.config.HOST,
|
|
778
|
+
"--port",
|
|
779
|
+
this.config.config.PORT,
|
|
780
|
+
"--user",
|
|
781
|
+
this.config.config.USER,
|
|
782
|
+
"--password",
|
|
783
|
+
this.config.config.PASSWORD,
|
|
784
|
+
"--motor",
|
|
785
|
+
this.config.type
|
|
786
|
+
];
|
|
723
787
|
}
|
|
724
|
-
|
|
788
|
+
return args;
|
|
789
|
+
}
|
|
790
|
+
setConfig(name) {
|
|
791
|
+
const configInstance = new Config();
|
|
792
|
+
try {
|
|
793
|
+
const configFilePath = path4.resolve(process.cwd(), "dbcube.config.js");
|
|
794
|
+
const requireUrl = typeof __filename !== "undefined" ? __filename : process.cwd();
|
|
795
|
+
const require2 = createRequire2(requireUrl);
|
|
796
|
+
delete require2.cache[require2.resolve(configFilePath)];
|
|
797
|
+
const configModule = require2(configFilePath);
|
|
798
|
+
const configFn = configModule.default || configModule;
|
|
799
|
+
if (typeof configFn === "function") {
|
|
800
|
+
configFn(configInstance);
|
|
801
|
+
} else {
|
|
802
|
+
console.error("\u274C El archivo dbcube.config.js no exporta una funci\xF3n.");
|
|
803
|
+
}
|
|
804
|
+
} catch (error) {
|
|
805
|
+
console.error("\u274C Error loading config file:", error.message);
|
|
806
|
+
if (error.code === "MODULE_NOT_FOUND") {
|
|
807
|
+
console.error("\u274C Config file not found, please create a dbcube.config.js file");
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
return configInstance.getDatabase(name);
|
|
811
|
+
}
|
|
812
|
+
getConfig() {
|
|
813
|
+
return this.config;
|
|
725
814
|
}
|
|
726
815
|
async run(binary, args) {
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
816
|
+
const actionIndex = args.findIndex((arg) => arg === "--action");
|
|
817
|
+
const isExecuteAction = actionIndex !== -1 && args[actionIndex + 1] === "execute";
|
|
818
|
+
if (isExecuteAction) {
|
|
819
|
+
return this.executeWithTcpServer(args);
|
|
820
|
+
} else {
|
|
821
|
+
return this.createProcess(binary, args);
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
async executeWithTcpServer(args) {
|
|
825
|
+
const serverInfo = globalTcpServers.get(this.connectionId);
|
|
826
|
+
if (!serverInfo || !serverInfo.process || serverInfo.process.killed) {
|
|
827
|
+
console.log("\u{1F680} Starting TCP server for ultra-fast queries...");
|
|
828
|
+
await this.startTcpServer();
|
|
829
|
+
}
|
|
830
|
+
console.log("\u26A1 Using TCP server (ultra-fast)");
|
|
831
|
+
return this.sendTcpRequest(args);
|
|
832
|
+
}
|
|
833
|
+
async startTcpServer() {
|
|
834
|
+
await this.initializeBinary();
|
|
835
|
+
if (!this.binary) {
|
|
836
|
+
throw new Error("Binary not initialized");
|
|
730
837
|
}
|
|
731
838
|
return new Promise((resolve5, reject) => {
|
|
732
|
-
const
|
|
733
|
-
const
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
839
|
+
const serverArgs = [...this.arguments, "--action", "server", "--port", this.tcpPort.toString()];
|
|
840
|
+
const serverProcess = spawn2(this.binary["query_engine"], serverArgs);
|
|
841
|
+
let started = false;
|
|
842
|
+
const timeout = setTimeout(() => {
|
|
843
|
+
if (!started) {
|
|
844
|
+
serverProcess.kill();
|
|
845
|
+
reject(new Error("TCP server startup timeout"));
|
|
846
|
+
}
|
|
847
|
+
}, 1e4);
|
|
848
|
+
serverProcess.stdout.on("data", (data) => {
|
|
849
|
+
const output = data.toString();
|
|
850
|
+
console.log(`[TCP Server] ${output.trim()}`);
|
|
851
|
+
if (output.includes("TCP Server listening on")) {
|
|
852
|
+
if (!started) {
|
|
853
|
+
started = true;
|
|
854
|
+
clearTimeout(timeout);
|
|
855
|
+
globalTcpServers.set(this.connectionId, {
|
|
856
|
+
port: this.tcpPort,
|
|
857
|
+
process: serverProcess
|
|
858
|
+
});
|
|
859
|
+
resolve5();
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
});
|
|
863
|
+
serverProcess.stderr.on("data", (data) => {
|
|
864
|
+
console.error(`[TCP Server Error] ${data.toString().trim()}`);
|
|
865
|
+
});
|
|
866
|
+
serverProcess.on("close", (code) => {
|
|
867
|
+
console.log(`[TCP Server] Process exited with code ${code}`);
|
|
868
|
+
globalTcpServers.delete(this.connectionId);
|
|
869
|
+
});
|
|
870
|
+
serverProcess.on("error", (error) => {
|
|
871
|
+
if (!started) {
|
|
872
|
+
clearTimeout(timeout);
|
|
873
|
+
reject(error);
|
|
738
874
|
}
|
|
875
|
+
});
|
|
876
|
+
});
|
|
877
|
+
}
|
|
878
|
+
async sendTcpRequest(args) {
|
|
879
|
+
return new Promise((resolve5, reject) => {
|
|
880
|
+
const client = new net.Socket();
|
|
881
|
+
let responseBuffer = "";
|
|
882
|
+
const timeout = setTimeout(() => {
|
|
883
|
+
client.destroy();
|
|
884
|
+
reject(new Error("TCP request timeout"));
|
|
739
885
|
}, this.timeout);
|
|
740
|
-
this.
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
886
|
+
client.connect(this.tcpPort, "127.0.0.1", () => {
|
|
887
|
+
const command = {
|
|
888
|
+
action: "execute",
|
|
889
|
+
args
|
|
890
|
+
};
|
|
891
|
+
client.write(JSON.stringify(command) + "\n");
|
|
745
892
|
});
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
893
|
+
client.on("data", (data) => {
|
|
894
|
+
responseBuffer += data.toString();
|
|
895
|
+
if (responseBuffer.includes("\n")) {
|
|
896
|
+
clearTimeout(timeout);
|
|
897
|
+
client.destroy();
|
|
898
|
+
try {
|
|
899
|
+
const response = JSON.parse(responseBuffer.trim());
|
|
900
|
+
resolve5({
|
|
901
|
+
status: response.status || 200,
|
|
902
|
+
message: response.message || "Success",
|
|
903
|
+
data: response.data
|
|
904
|
+
});
|
|
905
|
+
} catch (error) {
|
|
906
|
+
reject(new Error("Failed to parse TCP response"));
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
});
|
|
910
|
+
client.on("error", (error) => {
|
|
911
|
+
clearTimeout(timeout);
|
|
755
912
|
reject(error);
|
|
756
|
-
}
|
|
913
|
+
});
|
|
914
|
+
client.on("close", () => {
|
|
915
|
+
clearTimeout(timeout);
|
|
916
|
+
if (responseBuffer && !responseBuffer.includes("\n")) {
|
|
917
|
+
reject(new Error("Incomplete TCP response"));
|
|
918
|
+
}
|
|
919
|
+
});
|
|
757
920
|
});
|
|
758
921
|
}
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
if (
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
922
|
+
async createProcess(binary, args) {
|
|
923
|
+
await this.initializeBinary();
|
|
924
|
+
if (!this.binary) {
|
|
925
|
+
throw new Error("Binary not initialized");
|
|
926
|
+
}
|
|
927
|
+
return new Promise((resolve5, reject) => {
|
|
928
|
+
const child = spawn2(this.binary[binary], [...this.arguments, ...args]);
|
|
929
|
+
let stdoutBuffer = "";
|
|
930
|
+
let stderrBuffer = "";
|
|
931
|
+
let isResolved = false;
|
|
932
|
+
const timeoutId = setTimeout(() => {
|
|
933
|
+
if (!isResolved) {
|
|
934
|
+
isResolved = true;
|
|
935
|
+
child.kill();
|
|
936
|
+
reject(new Error("Process timeout"));
|
|
937
|
+
}
|
|
938
|
+
}, this.timeout);
|
|
939
|
+
const resolveOnce = (response) => {
|
|
940
|
+
if (!isResolved) {
|
|
941
|
+
isResolved = true;
|
|
942
|
+
clearTimeout(timeoutId);
|
|
943
|
+
resolve5(response);
|
|
944
|
+
}
|
|
945
|
+
};
|
|
946
|
+
child.stdout.on("data", (data) => {
|
|
947
|
+
stdoutBuffer += data.toString();
|
|
948
|
+
const match = stdoutBuffer.match(/PROCESS_RESPONSE:(\{.*\})/);
|
|
949
|
+
if (match) {
|
|
950
|
+
try {
|
|
951
|
+
const response = JSON.parse(match[1]);
|
|
952
|
+
resolveOnce({
|
|
953
|
+
status: response.status,
|
|
954
|
+
message: response.message,
|
|
955
|
+
data: response.data
|
|
956
|
+
});
|
|
957
|
+
} catch (error) {
|
|
958
|
+
resolveOnce({
|
|
959
|
+
status: 500,
|
|
960
|
+
message: "Failed to parse response JSON",
|
|
961
|
+
data: null
|
|
962
|
+
});
|
|
775
963
|
}
|
|
776
|
-
}
|
|
964
|
+
}
|
|
777
965
|
});
|
|
778
|
-
|
|
966
|
+
child.stderr.on("data", (data) => {
|
|
967
|
+
stderrBuffer += data.toString();
|
|
968
|
+
const match = stderrBuffer.match(/PROCESS_RESPONSE:(\{.*\})/);
|
|
969
|
+
if (match) {
|
|
970
|
+
try {
|
|
971
|
+
const response = JSON.parse(match[1]);
|
|
972
|
+
resolveOnce({
|
|
973
|
+
status: response.status,
|
|
974
|
+
message: response.message,
|
|
975
|
+
data: response.data
|
|
976
|
+
});
|
|
977
|
+
} catch (error) {
|
|
978
|
+
resolveOnce({
|
|
979
|
+
status: 500,
|
|
980
|
+
message: "Failed to parse response JSON",
|
|
981
|
+
data: null
|
|
982
|
+
});
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
});
|
|
986
|
+
child.on("close", (code) => {
|
|
987
|
+
clearTimeout(timeoutId);
|
|
988
|
+
if (!isResolved) {
|
|
989
|
+
resolveOnce({
|
|
990
|
+
status: code === 0 ? 200 : 500,
|
|
991
|
+
message: code === 0 ? "Process completed" : `Process exited with code ${code}`,
|
|
992
|
+
data: null
|
|
993
|
+
});
|
|
994
|
+
}
|
|
995
|
+
});
|
|
996
|
+
child.on("error", (error) => {
|
|
997
|
+
clearTimeout(timeoutId);
|
|
998
|
+
if (!isResolved) {
|
|
999
|
+
resolveOnce({
|
|
1000
|
+
status: 500,
|
|
1001
|
+
message: `Process error: ${error.message}`,
|
|
1002
|
+
data: null
|
|
1003
|
+
});
|
|
1004
|
+
}
|
|
1005
|
+
});
|
|
1006
|
+
child.unref();
|
|
1007
|
+
});
|
|
779
1008
|
}
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
1009
|
+
async disconnect() {
|
|
1010
|
+
const serverInfo = globalTcpServers.get(this.connectionId);
|
|
1011
|
+
if (serverInfo && serverInfo.process && !serverInfo.process.killed) {
|
|
1012
|
+
console.log("\u{1F50C} Stopping TCP server...");
|
|
1013
|
+
serverInfo.process.kill();
|
|
1014
|
+
globalTcpServers.delete(this.connectionId);
|
|
1015
|
+
return {
|
|
1016
|
+
status: 200,
|
|
1017
|
+
message: "TCP server stopped",
|
|
1018
|
+
data: null
|
|
1019
|
+
};
|
|
1020
|
+
}
|
|
1021
|
+
return {
|
|
1022
|
+
status: 200,
|
|
1023
|
+
message: "No TCP server to stop",
|
|
1024
|
+
data: null
|
|
1025
|
+
};
|
|
783
1026
|
}
|
|
784
1027
|
};
|
|
785
1028
|
|
|
786
1029
|
// src/lib/SqliteExecutor.ts
|
|
787
1030
|
import { exec } from "child_process";
|
|
788
|
-
import * as
|
|
1031
|
+
import * as path5 from "path";
|
|
789
1032
|
import * as fs3 from "fs";
|
|
790
1033
|
import { promisify } from "util";
|
|
791
|
-
import { createRequire as
|
|
1034
|
+
import { createRequire as createRequire3 } from "module";
|
|
792
1035
|
var execAsync = promisify(exec);
|
|
793
1036
|
var SqliteExecutor = class {
|
|
794
1037
|
binaryPath;
|
|
@@ -799,27 +1042,27 @@ var SqliteExecutor = class {
|
|
|
799
1042
|
}
|
|
800
1043
|
getBinaryPath() {
|
|
801
1044
|
const possibleDirs = [
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
1045
|
+
path5.resolve(process.cwd(), ".dbcube", "bin"),
|
|
1046
|
+
path5.resolve(process.cwd(), "node_modules", ".dbcube", "bin"),
|
|
1047
|
+
path5.resolve(__dirname, "..", "bin")
|
|
805
1048
|
];
|
|
806
1049
|
const platform2 = process.platform;
|
|
807
1050
|
const extension = platform2 === "win32" ? ".exe" : "";
|
|
808
1051
|
const binaryName = `sqlite-engine-${platform2 === "win32" ? "windows" : platform2 === "darwin" ? "macos" : "linux"}-x64${extension}`;
|
|
809
1052
|
for (const dir of possibleDirs) {
|
|
810
|
-
const fullPath =
|
|
1053
|
+
const fullPath = path5.join(dir, binaryName);
|
|
811
1054
|
if (fs3.existsSync(fullPath)) {
|
|
812
1055
|
return fullPath;
|
|
813
1056
|
}
|
|
814
1057
|
}
|
|
815
1058
|
const fallbackName = `sqlite-engine${extension}`;
|
|
816
1059
|
for (const dir of possibleDirs) {
|
|
817
|
-
const fullPath =
|
|
1060
|
+
const fullPath = path5.join(dir, fallbackName);
|
|
818
1061
|
if (fs3.existsSync(fullPath)) {
|
|
819
1062
|
return fullPath;
|
|
820
1063
|
}
|
|
821
1064
|
}
|
|
822
|
-
return
|
|
1065
|
+
return path5.join(possibleDirs[0], binaryName);
|
|
823
1066
|
}
|
|
824
1067
|
async executeBinary(args) {
|
|
825
1068
|
const escapedArgs = args.map((arg) => {
|
|
@@ -921,7 +1164,7 @@ var SqliteExecutor = class {
|
|
|
921
1164
|
// Para compatibilidad con better-sqlite3 API sincrona usando deasync si es necesario
|
|
922
1165
|
prepareSync(sql) {
|
|
923
1166
|
const requireUrl = typeof __filename !== "undefined" ? __filename : process.cwd();
|
|
924
|
-
const require2 =
|
|
1167
|
+
const require2 = createRequire3(requireUrl);
|
|
925
1168
|
const deasync = require2("deasync");
|
|
926
1169
|
return {
|
|
927
1170
|
all: (...params) => {
|
|
@@ -969,9 +1212,9 @@ var SqliteExecutor = class {
|
|
|
969
1212
|
};
|
|
970
1213
|
|
|
971
1214
|
// src/lib/DbConfig.ts
|
|
972
|
-
import * as
|
|
1215
|
+
import * as path6 from "path";
|
|
973
1216
|
import fs4 from "fs";
|
|
974
|
-
var rootPath =
|
|
1217
|
+
var rootPath = path6.resolve(process.cwd(), ".dbcube");
|
|
975
1218
|
var SQLite = class {
|
|
976
1219
|
executor = null;
|
|
977
1220
|
database;
|
|
@@ -981,7 +1224,7 @@ var SQLite = class {
|
|
|
981
1224
|
async ifExist() {
|
|
982
1225
|
if (this.database) {
|
|
983
1226
|
const dbPath = this.database || ":memory:";
|
|
984
|
-
const configPath =
|
|
1227
|
+
const configPath = path6.join(rootPath, dbPath + ".db");
|
|
985
1228
|
if (!fs4.existsSync(rootPath)) {
|
|
986
1229
|
fs4.mkdirSync(rootPath, { recursive: true });
|
|
987
1230
|
}
|
|
@@ -1000,7 +1243,7 @@ var SQLite = class {
|
|
|
1000
1243
|
try {
|
|
1001
1244
|
if (!this.executor) {
|
|
1002
1245
|
const dbPath = this.database || ":memory:";
|
|
1003
|
-
const configPath =
|
|
1246
|
+
const configPath = path6.join(rootPath, dbPath + ".db");
|
|
1004
1247
|
if (!fs4.existsSync(rootPath)) {
|
|
1005
1248
|
fs4.mkdirSync(rootPath, { recursive: true });
|
|
1006
1249
|
}
|
|
@@ -1185,7 +1428,7 @@ var DbConfig_default = DbConfig;
|
|
|
1185
1428
|
|
|
1186
1429
|
// src/lib/FileLogger.ts
|
|
1187
1430
|
import * as fs5 from "fs";
|
|
1188
|
-
import * as
|
|
1431
|
+
import * as path7 from "path";
|
|
1189
1432
|
import { EventEmitter } from "events";
|
|
1190
1433
|
var FileLogger = class _FileLogger extends EventEmitter {
|
|
1191
1434
|
static watchers = /* @__PURE__ */ new Map();
|
|
@@ -1200,7 +1443,7 @@ var FileLogger = class _FileLogger extends EventEmitter {
|
|
|
1200
1443
|
*/
|
|
1201
1444
|
static async write(filePath, message, level = "INFO", append = true) {
|
|
1202
1445
|
try {
|
|
1203
|
-
const dir =
|
|
1446
|
+
const dir = path7.dirname(filePath);
|
|
1204
1447
|
if (!fs5.existsSync(dir)) {
|
|
1205
1448
|
fs5.mkdirSync(dir, { recursive: true });
|
|
1206
1449
|
}
|
|
@@ -1239,7 +1482,7 @@ var FileLogger = class _FileLogger extends EventEmitter {
|
|
|
1239
1482
|
const buffer = _FileLogger.buffers.get(filePath);
|
|
1240
1483
|
if (buffer && buffer.length > 0) {
|
|
1241
1484
|
try {
|
|
1242
|
-
const dir =
|
|
1485
|
+
const dir = path7.dirname(filePath);
|
|
1243
1486
|
if (!fs5.existsSync(dir)) {
|
|
1244
1487
|
fs5.mkdirSync(dir, { recursive: true });
|
|
1245
1488
|
}
|
|
@@ -1962,6 +2205,7 @@ export {
|
|
|
1962
2205
|
DbConfig,
|
|
1963
2206
|
Engine,
|
|
1964
2207
|
FileLogger,
|
|
2208
|
+
QueryEngine,
|
|
1965
2209
|
TableProcessor,
|
|
1966
2210
|
TriggerProcessor
|
|
1967
2211
|
};
|