@dbcube/core 1.0.57 → 1.0.58
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 +4 -82
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +2 -7
- package/dist/index.d.ts +2 -7
- package/dist/index.js +4 -82
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -594,24 +594,21 @@ var Config = class {
|
|
|
594
594
|
var import_child_process = require("child_process");
|
|
595
595
|
var import_module = require("module");
|
|
596
596
|
var Engine = class _Engine {
|
|
597
|
-
|
|
598
|
-
name = "";
|
|
597
|
+
name;
|
|
599
598
|
config;
|
|
600
599
|
arguments;
|
|
601
600
|
binary = null;
|
|
602
|
-
timeout
|
|
603
|
-
|
|
604
|
-
isConnecting = false;
|
|
601
|
+
timeout;
|
|
602
|
+
static instances = /* @__PURE__ */ new Map();
|
|
605
603
|
constructor(name, timeout = 3e4) {
|
|
606
604
|
if (_Engine.instances.has(name)) {
|
|
607
605
|
return _Engine.instances.get(name);
|
|
608
606
|
}
|
|
609
607
|
this.name = name;
|
|
608
|
+
this.timeout = timeout;
|
|
610
609
|
this.config = this.setConfig(name);
|
|
611
610
|
this.arguments = this.setArguments();
|
|
612
|
-
this.timeout = timeout;
|
|
613
611
|
_Engine.instances.set(name, this);
|
|
614
|
-
this.setupProcessExitHandlers();
|
|
615
612
|
}
|
|
616
613
|
static getInstance(name, timeout = 3e4) {
|
|
617
614
|
if (_Engine.instances.has(name)) {
|
|
@@ -689,12 +686,6 @@ var Engine = class _Engine {
|
|
|
689
686
|
if (!this.binary) {
|
|
690
687
|
throw new Error("Binary not initialized");
|
|
691
688
|
}
|
|
692
|
-
const isConnectAction = args.includes("connect");
|
|
693
|
-
const isDisconnectAction = args.includes("disconnect");
|
|
694
|
-
const isExecuteAction = args.includes("execute");
|
|
695
|
-
if (isExecuteAction) {
|
|
696
|
-
await this.ensureDaemonConnected();
|
|
697
|
-
}
|
|
698
689
|
return new Promise((resolve5, reject) => {
|
|
699
690
|
const child = (0, import_child_process.spawn)(this.binary[binary], [...this.arguments, ...args]);
|
|
700
691
|
let stdoutBuffer = "";
|
|
@@ -712,17 +703,10 @@ var Engine = class _Engine {
|
|
|
712
703
|
isResolved = true;
|
|
713
704
|
clearTimeout(timeoutId);
|
|
714
705
|
resolve5(response);
|
|
715
|
-
if (isConnectAction && response.status === 200) {
|
|
716
|
-
this.isDaemonConnected = true;
|
|
717
|
-
this.isConnecting = false;
|
|
718
|
-
} else if (isDisconnectAction) {
|
|
719
|
-
this.isDaemonConnected = false;
|
|
720
|
-
}
|
|
721
706
|
}
|
|
722
707
|
};
|
|
723
708
|
child.stdout.on("data", (data) => {
|
|
724
709
|
stdoutBuffer += data.toString();
|
|
725
|
-
console.log(stdoutBuffer);
|
|
726
710
|
const match = stdoutBuffer.match(/PROCESS_RESPONSE:(\{.*\})/);
|
|
727
711
|
if (match) {
|
|
728
712
|
try {
|
|
@@ -743,7 +727,6 @@ var Engine = class _Engine {
|
|
|
743
727
|
});
|
|
744
728
|
child.stderr.on("data", (data) => {
|
|
745
729
|
stderrBuffer += data.toString();
|
|
746
|
-
console.log(stderrBuffer);
|
|
747
730
|
const match = stderrBuffer.match(/PROCESS_RESPONSE:(\{.*\})/);
|
|
748
731
|
if (match) {
|
|
749
732
|
try {
|
|
@@ -785,67 +768,6 @@ var Engine = class _Engine {
|
|
|
785
768
|
child.unref();
|
|
786
769
|
});
|
|
787
770
|
}
|
|
788
|
-
async ensureDaemonConnected() {
|
|
789
|
-
if (this.isDaemonConnected) {
|
|
790
|
-
return;
|
|
791
|
-
}
|
|
792
|
-
if (this.isConnecting) {
|
|
793
|
-
while (this.isConnecting) {
|
|
794
|
-
await new Promise((resolve5) => setTimeout(resolve5, 50));
|
|
795
|
-
}
|
|
796
|
-
return;
|
|
797
|
-
}
|
|
798
|
-
this.isConnecting = true;
|
|
799
|
-
try {
|
|
800
|
-
const response = await this.run("query_engine", ["--action", "connect"]);
|
|
801
|
-
if (response.status !== 200) {
|
|
802
|
-
throw new Error(`Failed to connect daemon: ${response.message}`);
|
|
803
|
-
}
|
|
804
|
-
} catch (error) {
|
|
805
|
-
this.isConnecting = false;
|
|
806
|
-
throw error;
|
|
807
|
-
}
|
|
808
|
-
}
|
|
809
|
-
async disconnect() {
|
|
810
|
-
if (this.isDaemonConnected) {
|
|
811
|
-
await this.run("query_engine", ["--action", "disconnect"]);
|
|
812
|
-
}
|
|
813
|
-
}
|
|
814
|
-
setupProcessExitHandlers() {
|
|
815
|
-
const gracefulShutdown = async () => {
|
|
816
|
-
if (this.isDaemonConnected) {
|
|
817
|
-
console.log("\u{1F504} Disconnecting daemon before exit...");
|
|
818
|
-
try {
|
|
819
|
-
await this.disconnect();
|
|
820
|
-
console.log("\u2705 Daemon disconnected successfully");
|
|
821
|
-
} catch (error) {
|
|
822
|
-
console.error("\u274C Error disconnecting daemon:", error);
|
|
823
|
-
}
|
|
824
|
-
}
|
|
825
|
-
};
|
|
826
|
-
process.on("exit", () => {
|
|
827
|
-
});
|
|
828
|
-
process.on("SIGINT", async () => {
|
|
829
|
-
console.log("\n\u{1F6D1} Received SIGINT (Ctrl+C)");
|
|
830
|
-
await gracefulShutdown();
|
|
831
|
-
process.exit(0);
|
|
832
|
-
});
|
|
833
|
-
process.on("SIGTERM", async () => {
|
|
834
|
-
console.log("\u{1F6D1} Received SIGTERM");
|
|
835
|
-
await gracefulShutdown();
|
|
836
|
-
process.exit(0);
|
|
837
|
-
});
|
|
838
|
-
process.on("uncaughtException", async (error) => {
|
|
839
|
-
console.error("\u{1F4A5} Uncaught Exception:", error);
|
|
840
|
-
await gracefulShutdown();
|
|
841
|
-
process.exit(1);
|
|
842
|
-
});
|
|
843
|
-
process.on("unhandledRejection", async (reason, promise) => {
|
|
844
|
-
console.error("\u{1F4A5} Unhandled Rejection at:", promise, "reason:", reason);
|
|
845
|
-
await gracefulShutdown();
|
|
846
|
-
process.exit(1);
|
|
847
|
-
});
|
|
848
|
-
}
|
|
849
771
|
};
|
|
850
772
|
|
|
851
773
|
// src/lib/SqliteExecutor.ts
|