@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.d.mts
CHANGED
|
@@ -12,19 +12,16 @@ declare class Engine {
|
|
|
12
12
|
private arguments;
|
|
13
13
|
private binary;
|
|
14
14
|
private timeout;
|
|
15
|
-
private
|
|
16
|
-
private isConnecting;
|
|
15
|
+
private static instances;
|
|
17
16
|
constructor(name: string, timeout?: number);
|
|
17
|
+
static getInstance(name: string, timeout?: number): Engine;
|
|
18
18
|
initializeBinary(): Promise<void>;
|
|
19
19
|
setArguments(): any[];
|
|
20
20
|
setConfig(name: string): {
|
|
21
21
|
[x: string]: any;
|
|
22
22
|
} | null;
|
|
23
23
|
getConfig(): any;
|
|
24
|
-
run(binary: string, args:
|
|
25
|
-
ensureDaemonConnected(): Promise<void>;
|
|
26
|
-
disconnect(): Promise<void>;
|
|
27
|
-
private setupProcessExitHandlers;
|
|
24
|
+
run(binary: string, args: []): Promise<ResponseEngine>;
|
|
28
25
|
}
|
|
29
26
|
|
|
30
27
|
interface SystemInfo {
|
package/dist/index.d.ts
CHANGED
|
@@ -12,19 +12,16 @@ declare class Engine {
|
|
|
12
12
|
private arguments;
|
|
13
13
|
private binary;
|
|
14
14
|
private timeout;
|
|
15
|
-
private
|
|
16
|
-
private isConnecting;
|
|
15
|
+
private static instances;
|
|
17
16
|
constructor(name: string, timeout?: number);
|
|
17
|
+
static getInstance(name: string, timeout?: number): Engine;
|
|
18
18
|
initializeBinary(): Promise<void>;
|
|
19
19
|
setArguments(): any[];
|
|
20
20
|
setConfig(name: string): {
|
|
21
21
|
[x: string]: any;
|
|
22
22
|
} | null;
|
|
23
23
|
getConfig(): any;
|
|
24
|
-
run(binary: string, args:
|
|
25
|
-
ensureDaemonConnected(): Promise<void>;
|
|
26
|
-
disconnect(): Promise<void>;
|
|
27
|
-
private setupProcessExitHandlers;
|
|
24
|
+
run(binary: string, args: []): Promise<ResponseEngine>;
|
|
28
25
|
}
|
|
29
26
|
|
|
30
27
|
interface SystemInfo {
|
package/dist/index.js
CHANGED
|
@@ -549,20 +549,28 @@ var Config = class {
|
|
|
549
549
|
// src/lib/Engine.ts
|
|
550
550
|
import { spawn } from "child_process";
|
|
551
551
|
import { createRequire } from "module";
|
|
552
|
-
var Engine = class {
|
|
552
|
+
var Engine = class _Engine {
|
|
553
553
|
name;
|
|
554
554
|
config;
|
|
555
555
|
arguments;
|
|
556
556
|
binary = null;
|
|
557
557
|
timeout;
|
|
558
|
-
|
|
559
|
-
isConnecting = false;
|
|
558
|
+
static instances = /* @__PURE__ */ new Map();
|
|
560
559
|
constructor(name, timeout = 3e4) {
|
|
560
|
+
if (_Engine.instances.has(name)) {
|
|
561
|
+
return _Engine.instances.get(name);
|
|
562
|
+
}
|
|
561
563
|
this.name = name;
|
|
564
|
+
this.timeout = timeout;
|
|
562
565
|
this.config = this.setConfig(name);
|
|
563
566
|
this.arguments = this.setArguments();
|
|
564
|
-
|
|
565
|
-
|
|
567
|
+
_Engine.instances.set(name, this);
|
|
568
|
+
}
|
|
569
|
+
static getInstance(name, timeout = 3e4) {
|
|
570
|
+
if (_Engine.instances.has(name)) {
|
|
571
|
+
return _Engine.instances.get(name);
|
|
572
|
+
}
|
|
573
|
+
return new _Engine(name, timeout);
|
|
566
574
|
}
|
|
567
575
|
async initializeBinary() {
|
|
568
576
|
if (!this.binary) {
|
|
@@ -634,12 +642,6 @@ var Engine = class {
|
|
|
634
642
|
if (!this.binary) {
|
|
635
643
|
throw new Error("Binary not initialized");
|
|
636
644
|
}
|
|
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
|
-
}
|
|
643
645
|
return new Promise((resolve5, reject) => {
|
|
644
646
|
const child = spawn(this.binary[binary], [...this.arguments, ...args]);
|
|
645
647
|
let stdoutBuffer = "";
|
|
@@ -657,17 +659,10 @@ var Engine = class {
|
|
|
657
659
|
isResolved = true;
|
|
658
660
|
clearTimeout(timeoutId);
|
|
659
661
|
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
|
-
}
|
|
666
662
|
}
|
|
667
663
|
};
|
|
668
664
|
child.stdout.on("data", (data) => {
|
|
669
665
|
stdoutBuffer += data.toString();
|
|
670
|
-
console.log(stdoutBuffer);
|
|
671
666
|
const match = stdoutBuffer.match(/PROCESS_RESPONSE:(\{.*\})/);
|
|
672
667
|
if (match) {
|
|
673
668
|
try {
|
|
@@ -688,7 +683,6 @@ var Engine = class {
|
|
|
688
683
|
});
|
|
689
684
|
child.stderr.on("data", (data) => {
|
|
690
685
|
stderrBuffer += data.toString();
|
|
691
|
-
console.log(stderrBuffer);
|
|
692
686
|
const match = stderrBuffer.match(/PROCESS_RESPONSE:(\{.*\})/);
|
|
693
687
|
if (match) {
|
|
694
688
|
try {
|
|
@@ -730,67 +724,6 @@ var Engine = class {
|
|
|
730
724
|
child.unref();
|
|
731
725
|
});
|
|
732
726
|
}
|
|
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
|
-
}
|
|
794
727
|
};
|
|
795
728
|
|
|
796
729
|
// src/lib/SqliteExecutor.ts
|