@dbcube/core 1.0.52 → 1.0.55
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 +76 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +76 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -12,6 +12,8 @@ declare class Engine {
|
|
|
12
12
|
private arguments;
|
|
13
13
|
private binary;
|
|
14
14
|
private timeout;
|
|
15
|
+
private isDaemonConnected;
|
|
16
|
+
private isConnecting;
|
|
15
17
|
constructor(name: string, timeout?: number);
|
|
16
18
|
initializeBinary(): Promise<void>;
|
|
17
19
|
setArguments(): any[];
|
|
@@ -19,7 +21,10 @@ declare class Engine {
|
|
|
19
21
|
[x: string]: any;
|
|
20
22
|
} | null;
|
|
21
23
|
getConfig(): any;
|
|
22
|
-
run(binary: string, args: []): Promise<ResponseEngine>;
|
|
24
|
+
run(binary: string, args: string[]): Promise<ResponseEngine>;
|
|
25
|
+
ensureDaemonConnected(): Promise<void>;
|
|
26
|
+
disconnect(): Promise<void>;
|
|
27
|
+
private setupProcessExitHandlers;
|
|
23
28
|
}
|
|
24
29
|
|
|
25
30
|
interface SystemInfo {
|
package/dist/index.d.ts
CHANGED
|
@@ -12,6 +12,8 @@ declare class Engine {
|
|
|
12
12
|
private arguments;
|
|
13
13
|
private binary;
|
|
14
14
|
private timeout;
|
|
15
|
+
private isDaemonConnected;
|
|
16
|
+
private isConnecting;
|
|
15
17
|
constructor(name: string, timeout?: number);
|
|
16
18
|
initializeBinary(): Promise<void>;
|
|
17
19
|
setArguments(): any[];
|
|
@@ -19,7 +21,10 @@ declare class Engine {
|
|
|
19
21
|
[x: string]: any;
|
|
20
22
|
} | null;
|
|
21
23
|
getConfig(): any;
|
|
22
|
-
run(binary: string, args: []): Promise<ResponseEngine>;
|
|
24
|
+
run(binary: string, args: string[]): Promise<ResponseEngine>;
|
|
25
|
+
ensureDaemonConnected(): Promise<void>;
|
|
26
|
+
disconnect(): Promise<void>;
|
|
27
|
+
private setupProcessExitHandlers;
|
|
23
28
|
}
|
|
24
29
|
|
|
25
30
|
interface SystemInfo {
|
package/dist/index.js
CHANGED
|
@@ -555,11 +555,14 @@ var Engine = class {
|
|
|
555
555
|
arguments;
|
|
556
556
|
binary = null;
|
|
557
557
|
timeout;
|
|
558
|
+
isDaemonConnected = false;
|
|
559
|
+
isConnecting = false;
|
|
558
560
|
constructor(name, timeout = 3e4) {
|
|
559
561
|
this.name = name;
|
|
560
562
|
this.config = this.setConfig(name);
|
|
561
563
|
this.arguments = this.setArguments();
|
|
562
564
|
this.timeout = timeout;
|
|
565
|
+
this.setupProcessExitHandlers();
|
|
563
566
|
}
|
|
564
567
|
async initializeBinary() {
|
|
565
568
|
if (!this.binary) {
|
|
@@ -631,6 +634,12 @@ var Engine = class {
|
|
|
631
634
|
if (!this.binary) {
|
|
632
635
|
throw new Error("Binary not initialized");
|
|
633
636
|
}
|
|
637
|
+
const isConnectAction = args.includes("connect");
|
|
638
|
+
const isDisconnectAction = args.includes("disconnect");
|
|
639
|
+
const isExecuteAction = args.includes("execute");
|
|
640
|
+
if (isExecuteAction) {
|
|
641
|
+
await this.ensureDaemonConnected();
|
|
642
|
+
}
|
|
634
643
|
return new Promise((resolve5, reject) => {
|
|
635
644
|
const child = spawn(this.binary[binary], [...this.arguments, ...args]);
|
|
636
645
|
let stdoutBuffer = "";
|
|
@@ -648,6 +657,12 @@ var Engine = class {
|
|
|
648
657
|
isResolved = true;
|
|
649
658
|
clearTimeout(timeoutId);
|
|
650
659
|
resolve5(response);
|
|
660
|
+
if (isConnectAction && response.status === 200) {
|
|
661
|
+
this.isDaemonConnected = true;
|
|
662
|
+
this.isConnecting = false;
|
|
663
|
+
} else if (isDisconnectAction) {
|
|
664
|
+
this.isDaemonConnected = false;
|
|
665
|
+
}
|
|
651
666
|
}
|
|
652
667
|
};
|
|
653
668
|
child.stdout.on("data", (data) => {
|
|
@@ -715,6 +730,67 @@ var Engine = class {
|
|
|
715
730
|
child.unref();
|
|
716
731
|
});
|
|
717
732
|
}
|
|
733
|
+
async ensureDaemonConnected() {
|
|
734
|
+
if (this.isDaemonConnected) {
|
|
735
|
+
return;
|
|
736
|
+
}
|
|
737
|
+
if (this.isConnecting) {
|
|
738
|
+
while (this.isConnecting) {
|
|
739
|
+
await new Promise((resolve5) => setTimeout(resolve5, 50));
|
|
740
|
+
}
|
|
741
|
+
return;
|
|
742
|
+
}
|
|
743
|
+
this.isConnecting = true;
|
|
744
|
+
try {
|
|
745
|
+
const response = await this.run("query_engine", ["--action", "connect"]);
|
|
746
|
+
if (response.status !== 200) {
|
|
747
|
+
throw new Error(`Failed to connect daemon: ${response.message}`);
|
|
748
|
+
}
|
|
749
|
+
} catch (error) {
|
|
750
|
+
this.isConnecting = false;
|
|
751
|
+
throw error;
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
async disconnect() {
|
|
755
|
+
if (this.isDaemonConnected) {
|
|
756
|
+
await this.run("query_engine", ["--action", "disconnect"]);
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
setupProcessExitHandlers() {
|
|
760
|
+
const gracefulShutdown = async () => {
|
|
761
|
+
if (this.isDaemonConnected) {
|
|
762
|
+
console.log("\u{1F504} Disconnecting daemon before exit...");
|
|
763
|
+
try {
|
|
764
|
+
await this.disconnect();
|
|
765
|
+
console.log("\u2705 Daemon disconnected successfully");
|
|
766
|
+
} catch (error) {
|
|
767
|
+
console.error("\u274C Error disconnecting daemon:", error);
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
};
|
|
771
|
+
process.on("exit", () => {
|
|
772
|
+
});
|
|
773
|
+
process.on("SIGINT", async () => {
|
|
774
|
+
console.log("\n\u{1F6D1} Received SIGINT (Ctrl+C)");
|
|
775
|
+
await gracefulShutdown();
|
|
776
|
+
process.exit(0);
|
|
777
|
+
});
|
|
778
|
+
process.on("SIGTERM", async () => {
|
|
779
|
+
console.log("\u{1F6D1} Received SIGTERM");
|
|
780
|
+
await gracefulShutdown();
|
|
781
|
+
process.exit(0);
|
|
782
|
+
});
|
|
783
|
+
process.on("uncaughtException", async (error) => {
|
|
784
|
+
console.error("\u{1F4A5} Uncaught Exception:", error);
|
|
785
|
+
await gracefulShutdown();
|
|
786
|
+
process.exit(1);
|
|
787
|
+
});
|
|
788
|
+
process.on("unhandledRejection", async (reason, promise) => {
|
|
789
|
+
console.error("\u{1F4A5} Unhandled Rejection at:", promise, "reason:", reason);
|
|
790
|
+
await gracefulShutdown();
|
|
791
|
+
process.exit(1);
|
|
792
|
+
});
|
|
793
|
+
}
|
|
718
794
|
};
|
|
719
795
|
|
|
720
796
|
// src/lib/SqliteExecutor.ts
|