@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.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,412 @@ 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"));
|
|
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);
|
|
782
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 command = {
|
|
933
|
+
action: "execute",
|
|
934
|
+
args
|
|
935
|
+
};
|
|
936
|
+
client.write(JSON.stringify(command) + "\n");
|
|
789
937
|
});
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
938
|
+
client.on("data", (data) => {
|
|
939
|
+
responseBuffer += data.toString();
|
|
940
|
+
if (responseBuffer.includes("\n")) {
|
|
941
|
+
clearTimeout(timeout);
|
|
942
|
+
client.destroy();
|
|
943
|
+
try {
|
|
944
|
+
const response = JSON.parse(responseBuffer.trim());
|
|
945
|
+
resolve5({
|
|
946
|
+
status: response.status || 200,
|
|
947
|
+
message: response.message || "Success",
|
|
948
|
+
data: response.data
|
|
949
|
+
});
|
|
950
|
+
} catch (error) {
|
|
951
|
+
reject(new Error("Failed to parse TCP response"));
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
});
|
|
955
|
+
client.on("error", (error) => {
|
|
956
|
+
clearTimeout(timeout);
|
|
799
957
|
reject(error);
|
|
800
|
-
}
|
|
958
|
+
});
|
|
959
|
+
client.on("close", () => {
|
|
960
|
+
clearTimeout(timeout);
|
|
961
|
+
if (responseBuffer && !responseBuffer.includes("\n")) {
|
|
962
|
+
reject(new Error("Incomplete TCP response"));
|
|
963
|
+
}
|
|
964
|
+
});
|
|
801
965
|
});
|
|
802
966
|
}
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
if (
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
967
|
+
async createProcess(binary, args) {
|
|
968
|
+
await this.initializeBinary();
|
|
969
|
+
if (!this.binary) {
|
|
970
|
+
throw new Error("Binary not initialized");
|
|
971
|
+
}
|
|
972
|
+
return new Promise((resolve5, reject) => {
|
|
973
|
+
const child = (0, import_child_process2.spawn)(this.binary[binary], [...this.arguments, ...args]);
|
|
974
|
+
let stdoutBuffer = "";
|
|
975
|
+
let stderrBuffer = "";
|
|
976
|
+
let isResolved = false;
|
|
977
|
+
const timeoutId = setTimeout(() => {
|
|
978
|
+
if (!isResolved) {
|
|
979
|
+
isResolved = true;
|
|
980
|
+
child.kill();
|
|
981
|
+
reject(new Error("Process timeout"));
|
|
982
|
+
}
|
|
983
|
+
}, this.timeout);
|
|
984
|
+
const resolveOnce = (response) => {
|
|
985
|
+
if (!isResolved) {
|
|
986
|
+
isResolved = true;
|
|
987
|
+
clearTimeout(timeoutId);
|
|
988
|
+
resolve5(response);
|
|
989
|
+
}
|
|
990
|
+
};
|
|
991
|
+
child.stdout.on("data", (data) => {
|
|
992
|
+
stdoutBuffer += data.toString();
|
|
993
|
+
const match = stdoutBuffer.match(/PROCESS_RESPONSE:(\{.*\})/);
|
|
994
|
+
if (match) {
|
|
995
|
+
try {
|
|
996
|
+
const response = JSON.parse(match[1]);
|
|
997
|
+
resolveOnce({
|
|
998
|
+
status: response.status,
|
|
999
|
+
message: response.message,
|
|
1000
|
+
data: response.data
|
|
1001
|
+
});
|
|
1002
|
+
} catch (error) {
|
|
1003
|
+
resolveOnce({
|
|
1004
|
+
status: 500,
|
|
1005
|
+
message: "Failed to parse response JSON",
|
|
1006
|
+
data: null
|
|
1007
|
+
});
|
|
819
1008
|
}
|
|
820
|
-
}
|
|
1009
|
+
}
|
|
821
1010
|
});
|
|
822
|
-
|
|
1011
|
+
child.stderr.on("data", (data) => {
|
|
1012
|
+
stderrBuffer += data.toString();
|
|
1013
|
+
const match = stderrBuffer.match(/PROCESS_RESPONSE:(\{.*\})/);
|
|
1014
|
+
if (match) {
|
|
1015
|
+
try {
|
|
1016
|
+
const response = JSON.parse(match[1]);
|
|
1017
|
+
resolveOnce({
|
|
1018
|
+
status: response.status,
|
|
1019
|
+
message: response.message,
|
|
1020
|
+
data: response.data
|
|
1021
|
+
});
|
|
1022
|
+
} catch (error) {
|
|
1023
|
+
resolveOnce({
|
|
1024
|
+
status: 500,
|
|
1025
|
+
message: "Failed to parse response JSON",
|
|
1026
|
+
data: null
|
|
1027
|
+
});
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
});
|
|
1031
|
+
child.on("close", (code) => {
|
|
1032
|
+
clearTimeout(timeoutId);
|
|
1033
|
+
if (!isResolved) {
|
|
1034
|
+
resolveOnce({
|
|
1035
|
+
status: code === 0 ? 200 : 500,
|
|
1036
|
+
message: code === 0 ? "Process completed" : `Process exited with code ${code}`,
|
|
1037
|
+
data: null
|
|
1038
|
+
});
|
|
1039
|
+
}
|
|
1040
|
+
});
|
|
1041
|
+
child.on("error", (error) => {
|
|
1042
|
+
clearTimeout(timeoutId);
|
|
1043
|
+
if (!isResolved) {
|
|
1044
|
+
resolveOnce({
|
|
1045
|
+
status: 500,
|
|
1046
|
+
message: `Process error: ${error.message}`,
|
|
1047
|
+
data: null
|
|
1048
|
+
});
|
|
1049
|
+
}
|
|
1050
|
+
});
|
|
1051
|
+
child.unref();
|
|
1052
|
+
});
|
|
823
1053
|
}
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
1054
|
+
async disconnect() {
|
|
1055
|
+
const serverInfo = globalTcpServers.get(this.connectionId);
|
|
1056
|
+
if (serverInfo && serverInfo.process && !serverInfo.process.killed) {
|
|
1057
|
+
console.log("\u{1F50C} Stopping TCP server...");
|
|
1058
|
+
serverInfo.process.kill();
|
|
1059
|
+
globalTcpServers.delete(this.connectionId);
|
|
1060
|
+
return {
|
|
1061
|
+
status: 200,
|
|
1062
|
+
message: "TCP server stopped",
|
|
1063
|
+
data: null
|
|
1064
|
+
};
|
|
1065
|
+
}
|
|
1066
|
+
return {
|
|
1067
|
+
status: 200,
|
|
1068
|
+
message: "No TCP server to stop",
|
|
1069
|
+
data: null
|
|
1070
|
+
};
|
|
827
1071
|
}
|
|
828
1072
|
};
|
|
829
1073
|
|
|
830
1074
|
// src/lib/SqliteExecutor.ts
|
|
831
|
-
var
|
|
832
|
-
var
|
|
1075
|
+
var import_child_process3 = require("child_process");
|
|
1076
|
+
var path5 = __toESM(require("path"));
|
|
833
1077
|
var fs3 = __toESM(require("fs"));
|
|
834
1078
|
var import_util = require("util");
|
|
835
|
-
var
|
|
836
|
-
var execAsync = (0, import_util.promisify)(
|
|
1079
|
+
var import_module3 = require("module");
|
|
1080
|
+
var execAsync = (0, import_util.promisify)(import_child_process3.exec);
|
|
837
1081
|
var SqliteExecutor = class {
|
|
838
1082
|
binaryPath;
|
|
839
1083
|
dbPath;
|
|
@@ -843,27 +1087,27 @@ var SqliteExecutor = class {
|
|
|
843
1087
|
}
|
|
844
1088
|
getBinaryPath() {
|
|
845
1089
|
const possibleDirs = [
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
1090
|
+
path5.resolve(process.cwd(), ".dbcube", "bin"),
|
|
1091
|
+
path5.resolve(process.cwd(), "node_modules", ".dbcube", "bin"),
|
|
1092
|
+
path5.resolve(__dirname, "..", "bin")
|
|
849
1093
|
];
|
|
850
1094
|
const platform2 = process.platform;
|
|
851
1095
|
const extension = platform2 === "win32" ? ".exe" : "";
|
|
852
1096
|
const binaryName = `sqlite-engine-${platform2 === "win32" ? "windows" : platform2 === "darwin" ? "macos" : "linux"}-x64${extension}`;
|
|
853
1097
|
for (const dir of possibleDirs) {
|
|
854
|
-
const fullPath =
|
|
1098
|
+
const fullPath = path5.join(dir, binaryName);
|
|
855
1099
|
if (fs3.existsSync(fullPath)) {
|
|
856
1100
|
return fullPath;
|
|
857
1101
|
}
|
|
858
1102
|
}
|
|
859
1103
|
const fallbackName = `sqlite-engine${extension}`;
|
|
860
1104
|
for (const dir of possibleDirs) {
|
|
861
|
-
const fullPath =
|
|
1105
|
+
const fullPath = path5.join(dir, fallbackName);
|
|
862
1106
|
if (fs3.existsSync(fullPath)) {
|
|
863
1107
|
return fullPath;
|
|
864
1108
|
}
|
|
865
1109
|
}
|
|
866
|
-
return
|
|
1110
|
+
return path5.join(possibleDirs[0], binaryName);
|
|
867
1111
|
}
|
|
868
1112
|
async executeBinary(args) {
|
|
869
1113
|
const escapedArgs = args.map((arg) => {
|
|
@@ -965,7 +1209,7 @@ var SqliteExecutor = class {
|
|
|
965
1209
|
// Para compatibilidad con better-sqlite3 API sincrona usando deasync si es necesario
|
|
966
1210
|
prepareSync(sql) {
|
|
967
1211
|
const requireUrl = typeof __filename !== "undefined" ? __filename : process.cwd();
|
|
968
|
-
const require2 = (0,
|
|
1212
|
+
const require2 = (0, import_module3.createRequire)(requireUrl);
|
|
969
1213
|
const deasync = require2("deasync");
|
|
970
1214
|
return {
|
|
971
1215
|
all: (...params) => {
|
|
@@ -1013,9 +1257,9 @@ var SqliteExecutor = class {
|
|
|
1013
1257
|
};
|
|
1014
1258
|
|
|
1015
1259
|
// src/lib/DbConfig.ts
|
|
1016
|
-
var
|
|
1260
|
+
var path6 = __toESM(require("path"));
|
|
1017
1261
|
var import_fs = __toESM(require("fs"));
|
|
1018
|
-
var rootPath =
|
|
1262
|
+
var rootPath = path6.resolve(process.cwd(), ".dbcube");
|
|
1019
1263
|
var SQLite = class {
|
|
1020
1264
|
executor = null;
|
|
1021
1265
|
database;
|
|
@@ -1025,7 +1269,7 @@ var SQLite = class {
|
|
|
1025
1269
|
async ifExist() {
|
|
1026
1270
|
if (this.database) {
|
|
1027
1271
|
const dbPath = this.database || ":memory:";
|
|
1028
|
-
const configPath =
|
|
1272
|
+
const configPath = path6.join(rootPath, dbPath + ".db");
|
|
1029
1273
|
if (!import_fs.default.existsSync(rootPath)) {
|
|
1030
1274
|
import_fs.default.mkdirSync(rootPath, { recursive: true });
|
|
1031
1275
|
}
|
|
@@ -1044,7 +1288,7 @@ var SQLite = class {
|
|
|
1044
1288
|
try {
|
|
1045
1289
|
if (!this.executor) {
|
|
1046
1290
|
const dbPath = this.database || ":memory:";
|
|
1047
|
-
const configPath =
|
|
1291
|
+
const configPath = path6.join(rootPath, dbPath + ".db");
|
|
1048
1292
|
if (!import_fs.default.existsSync(rootPath)) {
|
|
1049
1293
|
import_fs.default.mkdirSync(rootPath, { recursive: true });
|
|
1050
1294
|
}
|
|
@@ -1229,7 +1473,7 @@ var DbConfig_default = DbConfig;
|
|
|
1229
1473
|
|
|
1230
1474
|
// src/lib/FileLogger.ts
|
|
1231
1475
|
var fs5 = __toESM(require("fs"));
|
|
1232
|
-
var
|
|
1476
|
+
var path7 = __toESM(require("path"));
|
|
1233
1477
|
var import_events = require("events");
|
|
1234
1478
|
var FileLogger = class _FileLogger extends import_events.EventEmitter {
|
|
1235
1479
|
static watchers = /* @__PURE__ */ new Map();
|
|
@@ -1244,7 +1488,7 @@ var FileLogger = class _FileLogger extends import_events.EventEmitter {
|
|
|
1244
1488
|
*/
|
|
1245
1489
|
static async write(filePath, message, level = "INFO", append = true) {
|
|
1246
1490
|
try {
|
|
1247
|
-
const dir =
|
|
1491
|
+
const dir = path7.dirname(filePath);
|
|
1248
1492
|
if (!fs5.existsSync(dir)) {
|
|
1249
1493
|
fs5.mkdirSync(dir, { recursive: true });
|
|
1250
1494
|
}
|
|
@@ -1283,7 +1527,7 @@ var FileLogger = class _FileLogger extends import_events.EventEmitter {
|
|
|
1283
1527
|
const buffer = _FileLogger.buffers.get(filePath);
|
|
1284
1528
|
if (buffer && buffer.length > 0) {
|
|
1285
1529
|
try {
|
|
1286
|
-
const dir =
|
|
1530
|
+
const dir = path7.dirname(filePath);
|
|
1287
1531
|
if (!fs5.existsSync(dir)) {
|
|
1288
1532
|
fs5.mkdirSync(dir, { recursive: true });
|
|
1289
1533
|
}
|
|
@@ -2007,6 +2251,7 @@ function convertToType(value, type2) {
|
|
|
2007
2251
|
DbConfig,
|
|
2008
2252
|
Engine,
|
|
2009
2253
|
FileLogger,
|
|
2254
|
+
QueryEngine,
|
|
2010
2255
|
TableProcessor,
|
|
2011
2256
|
TriggerProcessor
|
|
2012
2257
|
});
|