@dbcube/core 1.0.55 → 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 +13 -80
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +3 -6
- package/dist/index.d.ts +3 -6
- package/dist/index.js +13 -80
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -593,20 +593,28 @@ var Config = class {
|
|
|
593
593
|
// src/lib/Engine.ts
|
|
594
594
|
var import_child_process = require("child_process");
|
|
595
595
|
var import_module = require("module");
|
|
596
|
-
var Engine = class {
|
|
596
|
+
var Engine = class _Engine {
|
|
597
597
|
name;
|
|
598
598
|
config;
|
|
599
599
|
arguments;
|
|
600
600
|
binary = null;
|
|
601
601
|
timeout;
|
|
602
|
-
|
|
603
|
-
isConnecting = false;
|
|
602
|
+
static instances = /* @__PURE__ */ new Map();
|
|
604
603
|
constructor(name, timeout = 3e4) {
|
|
604
|
+
if (_Engine.instances.has(name)) {
|
|
605
|
+
return _Engine.instances.get(name);
|
|
606
|
+
}
|
|
605
607
|
this.name = name;
|
|
608
|
+
this.timeout = timeout;
|
|
606
609
|
this.config = this.setConfig(name);
|
|
607
610
|
this.arguments = this.setArguments();
|
|
608
|
-
|
|
609
|
-
|
|
611
|
+
_Engine.instances.set(name, this);
|
|
612
|
+
}
|
|
613
|
+
static getInstance(name, timeout = 3e4) {
|
|
614
|
+
if (_Engine.instances.has(name)) {
|
|
615
|
+
return _Engine.instances.get(name);
|
|
616
|
+
}
|
|
617
|
+
return new _Engine(name, timeout);
|
|
610
618
|
}
|
|
611
619
|
async initializeBinary() {
|
|
612
620
|
if (!this.binary) {
|
|
@@ -678,12 +686,6 @@ var Engine = class {
|
|
|
678
686
|
if (!this.binary) {
|
|
679
687
|
throw new Error("Binary not initialized");
|
|
680
688
|
}
|
|
681
|
-
const isConnectAction = args.includes("connect");
|
|
682
|
-
const isDisconnectAction = args.includes("disconnect");
|
|
683
|
-
const isExecuteAction = args.includes("execute");
|
|
684
|
-
if (isExecuteAction) {
|
|
685
|
-
await this.ensureDaemonConnected();
|
|
686
|
-
}
|
|
687
689
|
return new Promise((resolve5, reject) => {
|
|
688
690
|
const child = (0, import_child_process.spawn)(this.binary[binary], [...this.arguments, ...args]);
|
|
689
691
|
let stdoutBuffer = "";
|
|
@@ -701,17 +703,10 @@ var Engine = class {
|
|
|
701
703
|
isResolved = true;
|
|
702
704
|
clearTimeout(timeoutId);
|
|
703
705
|
resolve5(response);
|
|
704
|
-
if (isConnectAction && response.status === 200) {
|
|
705
|
-
this.isDaemonConnected = true;
|
|
706
|
-
this.isConnecting = false;
|
|
707
|
-
} else if (isDisconnectAction) {
|
|
708
|
-
this.isDaemonConnected = false;
|
|
709
|
-
}
|
|
710
706
|
}
|
|
711
707
|
};
|
|
712
708
|
child.stdout.on("data", (data) => {
|
|
713
709
|
stdoutBuffer += data.toString();
|
|
714
|
-
console.log(stdoutBuffer);
|
|
715
710
|
const match = stdoutBuffer.match(/PROCESS_RESPONSE:(\{.*\})/);
|
|
716
711
|
if (match) {
|
|
717
712
|
try {
|
|
@@ -732,7 +727,6 @@ var Engine = class {
|
|
|
732
727
|
});
|
|
733
728
|
child.stderr.on("data", (data) => {
|
|
734
729
|
stderrBuffer += data.toString();
|
|
735
|
-
console.log(stderrBuffer);
|
|
736
730
|
const match = stderrBuffer.match(/PROCESS_RESPONSE:(\{.*\})/);
|
|
737
731
|
if (match) {
|
|
738
732
|
try {
|
|
@@ -774,67 +768,6 @@ var Engine = class {
|
|
|
774
768
|
child.unref();
|
|
775
769
|
});
|
|
776
770
|
}
|
|
777
|
-
async ensureDaemonConnected() {
|
|
778
|
-
if (this.isDaemonConnected) {
|
|
779
|
-
return;
|
|
780
|
-
}
|
|
781
|
-
if (this.isConnecting) {
|
|
782
|
-
while (this.isConnecting) {
|
|
783
|
-
await new Promise((resolve5) => setTimeout(resolve5, 50));
|
|
784
|
-
}
|
|
785
|
-
return;
|
|
786
|
-
}
|
|
787
|
-
this.isConnecting = true;
|
|
788
|
-
try {
|
|
789
|
-
const response = await this.run("query_engine", ["--action", "connect"]);
|
|
790
|
-
if (response.status !== 200) {
|
|
791
|
-
throw new Error(`Failed to connect daemon: ${response.message}`);
|
|
792
|
-
}
|
|
793
|
-
} catch (error) {
|
|
794
|
-
this.isConnecting = false;
|
|
795
|
-
throw error;
|
|
796
|
-
}
|
|
797
|
-
}
|
|
798
|
-
async disconnect() {
|
|
799
|
-
if (this.isDaemonConnected) {
|
|
800
|
-
await this.run("query_engine", ["--action", "disconnect"]);
|
|
801
|
-
}
|
|
802
|
-
}
|
|
803
|
-
setupProcessExitHandlers() {
|
|
804
|
-
const gracefulShutdown = async () => {
|
|
805
|
-
if (this.isDaemonConnected) {
|
|
806
|
-
console.log("\u{1F504} Disconnecting daemon before exit...");
|
|
807
|
-
try {
|
|
808
|
-
await this.disconnect();
|
|
809
|
-
console.log("\u2705 Daemon disconnected successfully");
|
|
810
|
-
} catch (error) {
|
|
811
|
-
console.error("\u274C Error disconnecting daemon:", error);
|
|
812
|
-
}
|
|
813
|
-
}
|
|
814
|
-
};
|
|
815
|
-
process.on("exit", () => {
|
|
816
|
-
});
|
|
817
|
-
process.on("SIGINT", async () => {
|
|
818
|
-
console.log("\n\u{1F6D1} Received SIGINT (Ctrl+C)");
|
|
819
|
-
await gracefulShutdown();
|
|
820
|
-
process.exit(0);
|
|
821
|
-
});
|
|
822
|
-
process.on("SIGTERM", async () => {
|
|
823
|
-
console.log("\u{1F6D1} Received SIGTERM");
|
|
824
|
-
await gracefulShutdown();
|
|
825
|
-
process.exit(0);
|
|
826
|
-
});
|
|
827
|
-
process.on("uncaughtException", async (error) => {
|
|
828
|
-
console.error("\u{1F4A5} Uncaught Exception:", error);
|
|
829
|
-
await gracefulShutdown();
|
|
830
|
-
process.exit(1);
|
|
831
|
-
});
|
|
832
|
-
process.on("unhandledRejection", async (reason, promise) => {
|
|
833
|
-
console.error("\u{1F4A5} Unhandled Rejection at:", promise, "reason:", reason);
|
|
834
|
-
await gracefulShutdown();
|
|
835
|
-
process.exit(1);
|
|
836
|
-
});
|
|
837
|
-
}
|
|
838
771
|
};
|
|
839
772
|
|
|
840
773
|
// src/lib/SqliteExecutor.ts
|