@dbcube/core 5.2.4 → 5.2.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.js CHANGED
@@ -6,7 +6,8 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
6
6
  });
7
7
 
8
8
  // src/lib/Engine.ts
9
- import path4 from "path";
9
+ import path5 from "path";
10
+ import * as fs5 from "fs";
10
11
 
11
12
  // src/lib/Arquitecture.ts
12
13
  import * as os from "os";
@@ -153,7 +154,7 @@ var Downloader = class {
153
154
  */
154
155
  static async fetchLatestVersion(prefix) {
155
156
  const url = this.VERSION_URLS[prefix];
156
- return new Promise((resolve5, reject) => {
157
+ return new Promise((resolve6, reject) => {
157
158
  https.get(url, (response) => {
158
159
  let data = "";
159
160
  response.on("data", (chunk) => {
@@ -163,7 +164,7 @@ var Downloader = class {
163
164
  try {
164
165
  const versions = JSON.parse(data);
165
166
  if (versions && versions.length > 0) {
166
- resolve5(versions[0].version);
167
+ resolve6(versions[0].version);
167
168
  } else {
168
169
  reject(new Error("No versions found"));
169
170
  }
@@ -372,7 +373,7 @@ var Downloader = class {
372
373
  if (attempt < maxRetries && (errorMessage.includes("ECONNRESET") || errorMessage.includes("timeout") || errorMessage.includes("ETIMEDOUT") || errorMessage.includes("ENOTFOUND"))) {
373
374
  attempt++;
374
375
  console.log(`\u{1F504} Retrying ${binary.prefix}-engine (${attempt}/${maxRetries})...`);
375
- await new Promise((resolve5) => setTimeout(resolve5, 1e3 + Math.random() * 1e3));
376
+ await new Promise((resolve6) => setTimeout(resolve6, 1e3 + Math.random() * 1e3));
376
377
  } else {
377
378
  throw new Error(`Error downloading ${binary.prefix}: ${errorMessage}`);
378
379
  }
@@ -420,12 +421,12 @@ var Downloader = class {
420
421
  return `[${filledBar}${emptyBar}] ${percentage}`;
421
422
  }
422
423
  static downloadFileWithProgress(url, outputPath, prefix) {
423
- return new Promise((resolve5, reject) => {
424
+ return new Promise((resolve6, reject) => {
424
425
  const request = https.get(url, { timeout: 0 }, (response) => {
425
426
  if (response.statusCode === 302 || response.statusCode === 301) {
426
427
  const redirectUrl = response.headers.location;
427
428
  if (redirectUrl) {
428
- return this.downloadFileWithProgress(redirectUrl, outputPath, prefix).then(resolve5).catch(reject);
429
+ return this.downloadFileWithProgress(redirectUrl, outputPath, prefix).then(resolve6).catch(reject);
429
430
  }
430
431
  }
431
432
  if (response.statusCode !== 200) {
@@ -448,7 +449,7 @@ var Downloader = class {
448
449
  }
449
450
  });
450
451
  response.on("end", () => {
451
- file.end(() => resolve5());
452
+ file.end(() => resolve6());
452
453
  });
453
454
  response.on("error", (err) => {
454
455
  file.close();
@@ -480,7 +481,7 @@ var Downloader = class {
480
481
  this.mainSpinner.text = `\u{1F4E5} ${chalk.bold(binary)} - ${progressText}`;
481
482
  }
482
483
  static extractBinary(zipPath, outputPath, prefix) {
483
- return new Promise((resolve5, reject) => {
484
+ return new Promise((resolve6, reject) => {
484
485
  const outDir = path.dirname(outputPath);
485
486
  let extracted = 0;
486
487
  const pending = [];
@@ -515,7 +516,7 @@ var Downloader = class {
515
516
  if (extracted === 0) {
516
517
  reject(new Error(`No se encontr\xF3 archivo v\xE1lido en el ZIP para ${prefix}`));
517
518
  } else {
518
- resolve5();
519
+ resolve6();
519
520
  }
520
521
  }).catch((err) => {
521
522
  this.cleanupFile(zipPath);
@@ -705,14 +706,75 @@ var Config = class {
705
706
  }
706
707
  };
707
708
 
709
+ // src/lib/EnvLoader.ts
710
+ import * as fs3 from "fs";
711
+ import * as path3 from "path";
712
+ var EnvLoader = class _EnvLoader {
713
+ /**
714
+ * Carga el archivo .env indicado (o ./.env del cwd) en process.env.
715
+ * Silencioso si el archivo no existe. Devuelve true si cargó algo.
716
+ */
717
+ static load(envPath) {
718
+ const file = envPath || path3.resolve(process.cwd(), ".env");
719
+ if (!fs3.existsSync(file)) return false;
720
+ const proc = process;
721
+ if (typeof proc.loadEnvFile === "function") {
722
+ try {
723
+ proc.loadEnvFile(file);
724
+ return true;
725
+ } catch {
726
+ }
727
+ }
728
+ try {
729
+ const parsed = _EnvLoader.parse(fs3.readFileSync(file, "utf8"));
730
+ for (const [key, value] of Object.entries(parsed)) {
731
+ if (process.env[key] === void 0) {
732
+ process.env[key] = value;
733
+ }
734
+ }
735
+ return true;
736
+ } catch {
737
+ return false;
738
+ }
739
+ }
740
+ /**
741
+ * Parser mínimo de formato .env. Soporta:
742
+ * KEY=value · KEY="value con espacios" · KEY='literal' · export KEY=value
743
+ * comentarios con # · líneas en blanco · \n \t en comillas dobles.
744
+ */
745
+ static parse(content) {
746
+ const out = {};
747
+ for (const rawLine of content.split(/\r?\n/)) {
748
+ const line = rawLine.trim();
749
+ if (!line || line.startsWith("#")) continue;
750
+ const withoutExport = line.startsWith("export ") ? line.slice(7).trim() : line;
751
+ const eq = withoutExport.indexOf("=");
752
+ if (eq === -1) continue;
753
+ const key = withoutExport.slice(0, eq).trim();
754
+ if (!key) continue;
755
+ let value = withoutExport.slice(eq + 1).trim();
756
+ if (value.length >= 2 && value[0] === '"' && value[value.length - 1] === '"') {
757
+ value = value.slice(1, -1).replace(/\\n/g, "\n").replace(/\\t/g, " ").replace(/\\"/g, '"');
758
+ } else if (value.length >= 2 && value[0] === "'" && value[value.length - 1] === "'") {
759
+ value = value.slice(1, -1);
760
+ } else {
761
+ const hash = value.indexOf(" #");
762
+ if (hash !== -1) value = value.slice(0, hash).trim();
763
+ }
764
+ out[key] = value;
765
+ }
766
+ return out;
767
+ }
768
+ };
769
+
708
770
  // src/lib/Engine.ts
709
771
  import { spawn as spawn2 } from "child_process";
710
772
  import { createRequire } from "module";
711
773
 
712
774
  // src/lib/DaemonClient.ts
713
775
  import net from "net";
714
- import fs3 from "fs";
715
- import path3 from "path";
776
+ import fs4 from "fs";
777
+ import path4 from "path";
716
778
  import { spawn } from "child_process";
717
779
  var DaemonClient = class _DaemonClient {
718
780
  static registry = /* @__PURE__ */ new Map();
@@ -744,10 +806,10 @@ var DaemonClient = class _DaemonClient {
744
806
  return true;
745
807
  }
746
808
  portfilePath() {
747
- return path3.join(process.cwd(), ".dbcube", "daemon", `${this.name}.json`);
809
+ return path4.join(process.cwd(), ".dbcube", "daemon", `${this.name}.json`);
748
810
  }
749
811
  lockfilePath() {
750
- return path3.join(process.cwd(), ".dbcube", "daemon", `${this.name}.lock`);
812
+ return path4.join(process.cwd(), ".dbcube", "daemon", `${this.name}.lock`);
751
813
  }
752
814
  /**
753
815
  * Exclusive-create lock so two processes never spawn two daemons for the
@@ -756,16 +818,16 @@ var DaemonClient = class _DaemonClient {
756
818
  acquireSpawnLock() {
757
819
  const lockPath = this.lockfilePath();
758
820
  try {
759
- fs3.mkdirSync(path3.dirname(lockPath), { recursive: true });
760
- const fd = fs3.openSync(lockPath, "wx");
761
- fs3.writeSync(fd, String(process.pid));
762
- fs3.closeSync(fd);
821
+ fs4.mkdirSync(path4.dirname(lockPath), { recursive: true });
822
+ const fd = fs4.openSync(lockPath, "wx");
823
+ fs4.writeSync(fd, String(process.pid));
824
+ fs4.closeSync(fd);
763
825
  return true;
764
826
  } catch {
765
827
  try {
766
- const age = Date.now() - fs3.statSync(lockPath).mtimeMs;
828
+ const age = Date.now() - fs4.statSync(lockPath).mtimeMs;
767
829
  if (age > 15e3) {
768
- fs3.unlinkSync(lockPath);
830
+ fs4.unlinkSync(lockPath);
769
831
  return this.acquireSpawnLock();
770
832
  }
771
833
  } catch {
@@ -775,7 +837,7 @@ var DaemonClient = class _DaemonClient {
775
837
  }
776
838
  releaseSpawnLock() {
777
839
  try {
778
- fs3.unlinkSync(this.lockfilePath());
840
+ fs4.unlinkSync(this.lockfilePath());
779
841
  } catch {
780
842
  }
781
843
  }
@@ -799,7 +861,7 @@ var DaemonClient = class _DaemonClient {
799
861
  try {
800
862
  if (gotLock) {
801
863
  try {
802
- fs3.unlinkSync(this.portfilePath());
864
+ fs4.unlinkSync(this.portfilePath());
803
865
  } catch {
804
866
  }
805
867
  this.spawnDaemon();
@@ -817,7 +879,7 @@ var DaemonClient = class _DaemonClient {
817
879
  }
818
880
  readPortfile() {
819
881
  try {
820
- const raw = fs3.readFileSync(this.portfilePath(), "utf8");
882
+ const raw = fs4.readFileSync(this.portfilePath(), "utf8");
821
883
  const info = JSON.parse(raw);
822
884
  const port = info?.port;
823
885
  return Number.isInteger(port) && port > 0 && port <= 65535 ? port : null;
@@ -834,22 +896,22 @@ var DaemonClient = class _DaemonClient {
834
896
  child.unref();
835
897
  }
836
898
  tryConnect(port) {
837
- return new Promise((resolve5) => {
899
+ return new Promise((resolve6) => {
838
900
  const socket = net.createConnection({ host: "127.0.0.1", port }, async () => {
839
901
  socket.setNoDelay(true);
840
902
  this.attach(socket);
841
903
  try {
842
904
  const pong = await this.send({ action: "ping" }, 2e3);
843
- resolve5(pong.status === 200);
905
+ resolve6(pong.status === 200);
844
906
  } catch {
845
907
  this.detach();
846
- resolve5(false);
908
+ resolve6(false);
847
909
  }
848
910
  });
849
- socket.once("error", () => resolve5(false));
911
+ socket.once("error", () => resolve6(false));
850
912
  socket.setTimeout(3e3, () => {
851
913
  socket.destroy();
852
- resolve5(false);
914
+ resolve6(false);
853
915
  });
854
916
  });
855
917
  }
@@ -897,7 +959,7 @@ var DaemonClient = class _DaemonClient {
897
959
  * single socket, so pending requests resolve in send order.
898
960
  */
899
961
  send(payload, timeoutMs) {
900
- return new Promise((resolve5, reject) => {
962
+ return new Promise((resolve6, reject) => {
901
963
  if (!this.socket || this.socket.destroyed) {
902
964
  reject(new Error("Daemon not connected"));
903
965
  return;
@@ -908,7 +970,7 @@ var DaemonClient = class _DaemonClient {
908
970
  reject(new Error("Daemon request timeout"));
909
971
  this.detach();
910
972
  }, timeoutMs ?? this.requestTimeout);
911
- this.pending.push({ resolve: resolve5, reject, timer });
973
+ this.pending.push({ resolve: resolve6, reject, timer });
912
974
  this.socket.write(JSON.stringify(payload) + "\n");
913
975
  });
914
976
  }
@@ -944,7 +1006,7 @@ var DaemonClient = class _DaemonClient {
944
1006
  }
945
1007
  this.detach();
946
1008
  try {
947
- fs3.unlinkSync(this.portfilePath());
1009
+ fs4.unlinkSync(this.portfilePath());
948
1010
  } catch {
949
1011
  }
950
1012
  }
@@ -1042,6 +1104,7 @@ var Engine = class {
1042
1104
  }
1043
1105
  setArguments() {
1044
1106
  let args = [];
1107
+ const motor = this.config.type === "postgres" ? "postgresql" : this.config.type;
1045
1108
  if (this.config.type == "sqlite") {
1046
1109
  args = [
1047
1110
  "--id",
@@ -1051,7 +1114,7 @@ var Engine = class {
1051
1114
  "--database",
1052
1115
  this.config.config.DATABASE + ".db",
1053
1116
  "--motor",
1054
- this.config.type
1117
+ motor
1055
1118
  ];
1056
1119
  } else {
1057
1120
  args = [
@@ -1066,7 +1129,7 @@ var Engine = class {
1066
1129
  "--port",
1067
1130
  String(this.config.config.PORT),
1068
1131
  "--motor",
1069
- this.config.type
1132
+ motor
1070
1133
  ];
1071
1134
  if (this.config.config.USER != null && this.config.config.USER !== "") {
1072
1135
  args.push("--user", this.config.config.USER);
@@ -1079,8 +1142,10 @@ var Engine = class {
1079
1142
  }
1080
1143
  setConfig(name) {
1081
1144
  const configInstance = new Config();
1145
+ EnvLoader.load();
1082
1146
  try {
1083
- const configFilePath = path4.resolve(process.cwd(), "dbcube.config.js");
1147
+ const cjsPath = path5.resolve(process.cwd(), "dbcube.config.cjs");
1148
+ const configFilePath = fs5.existsSync(cjsPath) ? cjsPath : path5.resolve(process.cwd(), "dbcube.config.js");
1084
1149
  const requireUrl = typeof __filename !== "undefined" ? __filename : process.cwd();
1085
1150
  const require2 = createRequire(requireUrl);
1086
1151
  if (require2.cache && require2.resolve) {
@@ -1112,7 +1177,7 @@ var Engine = class {
1112
1177
  if (!this.binary) {
1113
1178
  throw new Error("Binary not initialized");
1114
1179
  }
1115
- return new Promise((resolve5, reject) => {
1180
+ return new Promise((resolve6, reject) => {
1116
1181
  const child = spawn2(this.binary[binary], [...this.arguments, ...args]);
1117
1182
  let stdoutBuffer = "";
1118
1183
  let stderrBuffer = "";
@@ -1128,7 +1193,7 @@ var Engine = class {
1128
1193
  if (!isResolved) {
1129
1194
  isResolved = true;
1130
1195
  clearTimeout(timeoutId);
1131
- resolve5(response);
1196
+ resolve6(response);
1132
1197
  }
1133
1198
  };
1134
1199
  const tryParseLines = (buffer) => {
@@ -1193,11 +1258,12 @@ var Engine = class {
1193
1258
  };
1194
1259
 
1195
1260
  // src/lib/QueryEngine.ts
1196
- import path6 from "path";
1261
+ import path7 from "path";
1262
+ import * as fs7 from "fs";
1197
1263
 
1198
1264
  // src/lib/EmbeddedEngine.ts
1199
- import * as fs4 from "fs";
1200
- import * as path5 from "path";
1265
+ import * as fs6 from "fs";
1266
+ import * as path6 from "path";
1201
1267
  if (!process.env.UV_THREADPOOL_SIZE) {
1202
1268
  process.env.UV_THREADPOOL_SIZE = "16";
1203
1269
  }
@@ -1213,11 +1279,11 @@ function platTag() {
1213
1279
  }
1214
1280
  function findFile(name) {
1215
1281
  const candidates = [
1216
- path5.resolve(process.cwd(), ".dbcube", "bin", name),
1217
- path5.resolve(process.cwd(), "node_modules", ".dbcube", "bin", name)
1282
+ path6.resolve(process.cwd(), ".dbcube", "bin", name),
1283
+ path6.resolve(process.cwd(), "node_modules", ".dbcube", "bin", name)
1218
1284
  ];
1219
1285
  for (const c of candidates) {
1220
- if (fs4.existsSync(c)) return c;
1286
+ if (fs6.existsSync(c)) return c;
1221
1287
  }
1222
1288
  return null;
1223
1289
  }
@@ -1325,10 +1391,10 @@ function loadKoffiBackend() {
1325
1391
  return { status: 500, message: `Invalid embedded response: ${e.message}`, data: null };
1326
1392
  }
1327
1393
  };
1328
- const call = (fn, ...args) => new Promise((resolve5, reject) => {
1394
+ const call = (fn, ...args) => new Promise((resolve6, reject) => {
1329
1395
  fn.async(...args, (err, ptr) => {
1330
1396
  if (err) return reject(err);
1331
- resolve5(take(ptr));
1397
+ resolve6(take(ptr));
1332
1398
  });
1333
1399
  });
1334
1400
  return {
@@ -1482,12 +1548,12 @@ var QueryEngine = class {
1482
1548
  throw new Error("No available ports found in range 9900-9944");
1483
1549
  }
1484
1550
  isPortAvailable(port) {
1485
- return new Promise((resolve5) => {
1551
+ return new Promise((resolve6) => {
1486
1552
  const tester = net2.createServer();
1487
- tester.once("error", () => resolve5(false));
1553
+ tester.once("error", () => resolve6(false));
1488
1554
  tester.once("listening", () => {
1489
1555
  tester.close();
1490
- resolve5(true);
1556
+ resolve6(true);
1491
1557
  });
1492
1558
  tester.listen(port, "127.0.0.1");
1493
1559
  });
@@ -1499,6 +1565,7 @@ var QueryEngine = class {
1499
1565
  }
1500
1566
  setArguments() {
1501
1567
  let args = [];
1568
+ const motor = this.config.type === "postgres" ? "postgresql" : this.config.type;
1502
1569
  if (this.config.type == "sqlite") {
1503
1570
  args = [
1504
1571
  "--id",
@@ -1508,7 +1575,7 @@ var QueryEngine = class {
1508
1575
  "--database",
1509
1576
  this.config.config.DATABASE + ".db",
1510
1577
  "--motor",
1511
- this.config.type
1578
+ motor
1512
1579
  ];
1513
1580
  } else {
1514
1581
  args = [
@@ -1523,7 +1590,7 @@ var QueryEngine = class {
1523
1590
  "--port",
1524
1591
  String(this.config.config.PORT),
1525
1592
  "--motor",
1526
- this.config.type
1593
+ motor
1527
1594
  ];
1528
1595
  if (this.config.config.USER != null && this.config.config.USER !== "") {
1529
1596
  args.push("--user", this.config.config.USER);
@@ -1547,8 +1614,10 @@ var QueryEngine = class {
1547
1614
  }
1548
1615
  setConfig(name) {
1549
1616
  const configInstance = new Config();
1617
+ EnvLoader.load();
1550
1618
  try {
1551
- const configFilePath = path6.resolve(process.cwd(), "dbcube.config.js");
1619
+ const cjsPath = path7.resolve(process.cwd(), "dbcube.config.cjs");
1620
+ const configFilePath = fs7.existsSync(cjsPath) ? cjsPath : path7.resolve(process.cwd(), "dbcube.config.js");
1552
1621
  const requireUrl = typeof __filename !== "undefined" ? __filename : process.cwd();
1553
1622
  const require2 = createRequire2(requireUrl);
1554
1623
  if (require2.cache && require2.resolve) {
@@ -1720,7 +1789,7 @@ var QueryEngine = class {
1720
1789
  throw e;
1721
1790
  }
1722
1791
  }
1723
- return new Promise((resolve5) => pool.waiters.push(resolve5));
1792
+ return new Promise((resolve6) => pool.waiters.push(resolve6));
1724
1793
  }
1725
1794
  releaseSocket(socket, broken) {
1726
1795
  const pool = socketPools.get(this.connectionId);
@@ -1759,25 +1828,25 @@ var QueryEngine = class {
1759
1828
  throw new Error("TCP server failed to become ready within timeout");
1760
1829
  }
1761
1830
  async isServerResponding(port) {
1762
- return new Promise((resolve5) => {
1831
+ return new Promise((resolve6) => {
1763
1832
  const client = new net2.Socket();
1764
1833
  const timeout = setTimeout(() => {
1765
1834
  client.destroy();
1766
- resolve5(false);
1835
+ resolve6(false);
1767
1836
  }, 1e3);
1768
1837
  client.connect(port, "127.0.0.1", () => {
1769
1838
  clearTimeout(timeout);
1770
1839
  client.destroy();
1771
- resolve5(true);
1840
+ resolve6(true);
1772
1841
  });
1773
1842
  client.on("error", () => {
1774
1843
  clearTimeout(timeout);
1775
- resolve5(false);
1844
+ resolve6(false);
1776
1845
  });
1777
1846
  });
1778
1847
  }
1779
1848
  sleep(ms) {
1780
- return new Promise((resolve5) => setTimeout(resolve5, ms));
1849
+ return new Promise((resolve6) => setTimeout(resolve6, ms));
1781
1850
  }
1782
1851
  getCachedDML(dmlJson) {
1783
1852
  if (queryCache.has(dmlJson)) {
@@ -1797,7 +1866,7 @@ var QueryEngine = class {
1797
1866
  throw new Error("Binary not initialized");
1798
1867
  }
1799
1868
  this.tcpPort = await this.findAvailablePort(this.tcpPort);
1800
- return new Promise((resolve5, reject) => {
1869
+ return new Promise((resolve6, reject) => {
1801
1870
  const serverArgs = [...this.arguments, "--action", "server", "--tcp-port", this.tcpPort.toString()];
1802
1871
  const serverProcess = spawn3(this.binary["query_engine"], serverArgs);
1803
1872
  let started = false;
@@ -1817,7 +1886,7 @@ var QueryEngine = class {
1817
1886
  port: this.tcpPort,
1818
1887
  process: serverProcess
1819
1888
  });
1820
- resolve5();
1889
+ resolve6();
1821
1890
  }
1822
1891
  }
1823
1892
  });
@@ -1836,7 +1905,7 @@ var QueryEngine = class {
1836
1905
  });
1837
1906
  }
1838
1907
  async createNewConnection(port) {
1839
- return new Promise((resolve5, reject) => {
1908
+ return new Promise((resolve6, reject) => {
1840
1909
  const client = new net2.Socket();
1841
1910
  client.setNoDelay(true);
1842
1911
  client.setKeepAlive(true, 6e4);
@@ -1846,7 +1915,7 @@ var QueryEngine = class {
1846
1915
  }, 5e3);
1847
1916
  client.connect(port, "127.0.0.1", () => {
1848
1917
  clearTimeout(timeout);
1849
- resolve5(client);
1918
+ resolve6(client);
1850
1919
  });
1851
1920
  client.on("error", (error) => {
1852
1921
  clearTimeout(timeout);
@@ -1855,7 +1924,7 @@ var QueryEngine = class {
1855
1924
  });
1856
1925
  }
1857
1926
  async executeOnConnection(connection, command) {
1858
- return new Promise((resolve5, reject) => {
1927
+ return new Promise((resolve6, reject) => {
1859
1928
  let responseBuffer = "";
1860
1929
  let isResolved = false;
1861
1930
  const timeout = setTimeout(() => {
@@ -1880,7 +1949,7 @@ var QueryEngine = class {
1880
1949
  connection.removeListener("error", onError);
1881
1950
  try {
1882
1951
  const response = JSON.parse(line.slice(marker + "PROCESS_RESPONSE:".length));
1883
- resolve5({
1952
+ resolve6({
1884
1953
  status: response.status,
1885
1954
  message: response.message,
1886
1955
  data: response.data
@@ -1909,7 +1978,7 @@ var QueryEngine = class {
1909
1978
  if (!this.binary) {
1910
1979
  throw new Error("Binary not initialized");
1911
1980
  }
1912
- return new Promise((resolve5, reject) => {
1981
+ return new Promise((resolve6, reject) => {
1913
1982
  const child = spawn3(this.binary[binary], [...this.arguments, ...args]);
1914
1983
  let stdoutBuffer = "";
1915
1984
  let stderrBuffer = "";
@@ -1925,7 +1994,7 @@ var QueryEngine = class {
1925
1994
  if (!isResolved) {
1926
1995
  isResolved = true;
1927
1996
  clearTimeout(timeoutId);
1928
- resolve5(response);
1997
+ resolve6(response);
1929
1998
  }
1930
1999
  };
1931
2000
  const tryParseLines = (buffer) => {
@@ -2012,9 +2081,9 @@ var QueryEngine = class {
2012
2081
  };
2013
2082
 
2014
2083
  // src/lib/DbConfig.ts
2015
- import * as path7 from "path";
2016
- import fs5 from "fs";
2017
- var rootPath = path7.resolve(process.cwd(), ".dbcube");
2084
+ import * as path8 from "path";
2085
+ import fs8 from "fs";
2086
+ var rootPath = path8.resolve(process.cwd(), ".dbcube");
2018
2087
  var SQLite = class {
2019
2088
  database;
2020
2089
  engine = null;
@@ -2023,14 +2092,14 @@ var SQLite = class {
2023
2092
  }
2024
2093
  /** Ruta del archivo SQLite interno (.dbcube/<database>.db). */
2025
2094
  dbFilePath() {
2026
- return path7.join(rootPath, this.database + ".db");
2095
+ return path8.join(rootPath, this.database + ".db");
2027
2096
  }
2028
2097
  /** QueryEngine sqlite apuntando al archivo interno, con config explícito
2029
2098
  * (no vive en dbcube.config.js). La ruta relativa `.dbcube/<db>` deja que
2030
2099
  * QueryEngine le añada `.db` → `.dbcube/<db>.db`, relativo al CWD. */
2031
2100
  getEngine() {
2032
2101
  if (!this.engine) {
2033
- const relativeDb = path7.join(".dbcube", this.database).replace(/\\/g, "/");
2102
+ const relativeDb = path8.join(".dbcube", this.database).replace(/\\/g, "/");
2034
2103
  this.engine = new QueryEngine(`dbcube-internal-${this.database}`, 3e4, {
2035
2104
  type: "sqlite",
2036
2105
  config: { DATABASE: relativeDb }
@@ -2039,14 +2108,14 @@ var SQLite = class {
2039
2108
  return this.engine;
2040
2109
  }
2041
2110
  async ifExist() {
2042
- if (!fs5.existsSync(rootPath)) {
2043
- fs5.mkdirSync(rootPath, { recursive: true });
2111
+ if (!fs8.existsSync(rootPath)) {
2112
+ fs8.mkdirSync(rootPath, { recursive: true });
2044
2113
  }
2045
- return fs5.existsSync(this.dbFilePath());
2114
+ return fs8.existsSync(this.dbFilePath());
2046
2115
  }
2047
2116
  async connect() {
2048
- if (!fs5.existsSync(rootPath)) {
2049
- fs5.mkdirSync(rootPath, { recursive: true });
2117
+ if (!fs8.existsSync(rootPath)) {
2118
+ fs8.mkdirSync(rootPath, { recursive: true });
2050
2119
  }
2051
2120
  return this.getEngine();
2052
2121
  }
@@ -2162,8 +2231,8 @@ var DbConfig = new SQLite({ DATABASE: "config" });
2162
2231
  var DbConfig_default = DbConfig;
2163
2232
 
2164
2233
  // src/lib/FileLogger.ts
2165
- import * as fs6 from "fs";
2166
- import * as path8 from "path";
2234
+ import * as fs9 from "fs";
2235
+ import * as path9 from "path";
2167
2236
  import { EventEmitter } from "events";
2168
2237
  var FileLogger = class _FileLogger extends EventEmitter {
2169
2238
  static watchers = /* @__PURE__ */ new Map();
@@ -2178,9 +2247,9 @@ var FileLogger = class _FileLogger extends EventEmitter {
2178
2247
  */
2179
2248
  static async write(filePath, message, level = "INFO", append = true) {
2180
2249
  try {
2181
- const dir = path8.dirname(filePath);
2182
- if (!fs6.existsSync(dir)) {
2183
- fs6.mkdirSync(dir, { recursive: true });
2250
+ const dir = path9.dirname(filePath);
2251
+ if (!fs9.existsSync(dir)) {
2252
+ fs9.mkdirSync(dir, { recursive: true });
2184
2253
  }
2185
2254
  const timestamp = (/* @__PURE__ */ new Date()).toISOString();
2186
2255
  const formattedMessage = `[${timestamp}] [${level}] ${message}
@@ -2190,9 +2259,9 @@ var FileLogger = class _FileLogger extends EventEmitter {
2190
2259
  return true;
2191
2260
  }
2192
2261
  if (append) {
2193
- await fs6.promises.appendFile(filePath, formattedMessage, "utf8");
2262
+ await fs9.promises.appendFile(filePath, formattedMessage, "utf8");
2194
2263
  } else {
2195
- await fs6.promises.writeFile(filePath, formattedMessage, "utf8");
2264
+ await fs9.promises.writeFile(filePath, formattedMessage, "utf8");
2196
2265
  }
2197
2266
  return true;
2198
2267
  } catch (error) {
@@ -2217,12 +2286,12 @@ var FileLogger = class _FileLogger extends EventEmitter {
2217
2286
  const buffer = _FileLogger.buffers.get(filePath);
2218
2287
  if (buffer && buffer.length > 0) {
2219
2288
  try {
2220
- const dir = path8.dirname(filePath);
2221
- if (!fs6.existsSync(dir)) {
2222
- fs6.mkdirSync(dir, { recursive: true });
2289
+ const dir = path9.dirname(filePath);
2290
+ if (!fs9.existsSync(dir)) {
2291
+ fs9.mkdirSync(dir, { recursive: true });
2223
2292
  }
2224
2293
  const content = buffer.join("");
2225
- await fs6.promises.appendFile(filePath, content, "utf8");
2294
+ await fs9.promises.appendFile(filePath, content, "utf8");
2226
2295
  _FileLogger.buffers.delete(filePath);
2227
2296
  return true;
2228
2297
  } catch (error) {
@@ -2358,10 +2427,10 @@ var FileLogger = class _FileLogger extends EventEmitter {
2358
2427
  // Si debe retornar como array de líneas
2359
2428
  } = options;
2360
2429
  try {
2361
- if (!fs6.existsSync(filePath)) {
2430
+ if (!fs9.existsSync(filePath)) {
2362
2431
  return asArray ? [] : "";
2363
2432
  }
2364
- let content = await fs6.promises.readFile(filePath, "utf8");
2433
+ let content = await fs9.promises.readFile(filePath, "utf8");
2365
2434
  if (asArray) {
2366
2435
  let linesArray = content.split("\n").filter((line) => line.trim() !== "");
2367
2436
  if (lines !== null) {
@@ -2404,15 +2473,15 @@ var FileLogger = class _FileLogger extends EventEmitter {
2404
2473
  } = options;
2405
2474
  let lastSize = 0;
2406
2475
  let lastPosition = 0;
2407
- if (fs6.existsSync(filePath)) {
2408
- const stats = fs6.statSync(filePath);
2476
+ if (fs9.existsSync(filePath)) {
2477
+ const stats = fs9.statSync(filePath);
2409
2478
  lastSize = stats.size;
2410
2479
  lastPosition = fromEnd ? stats.size : 0;
2411
2480
  }
2412
2481
  const listener = async (curr, prev) => {
2413
2482
  try {
2414
2483
  if (curr.size > lastSize) {
2415
- const stream = fs6.createReadStream(filePath, {
2484
+ const stream = fs9.createReadStream(filePath, {
2416
2485
  start: lastPosition,
2417
2486
  end: curr.size - 1,
2418
2487
  encoding: "utf8"
@@ -2440,7 +2509,7 @@ var FileLogger = class _FileLogger extends EventEmitter {
2440
2509
  console.error("Error en watcher:", error);
2441
2510
  }
2442
2511
  };
2443
- fs6.watchFile(filePath, { persistent, interval }, listener);
2512
+ fs9.watchFile(filePath, { persistent, interval }, listener);
2444
2513
  const watcherId = `${filePath}_${Date.now()}`;
2445
2514
  _FileLogger.watchers.set(watcherId, listener);
2446
2515
  return {
@@ -2448,7 +2517,7 @@ var FileLogger = class _FileLogger extends EventEmitter {
2448
2517
  stop: () => {
2449
2518
  const storedListener = _FileLogger.watchers.get(watcherId);
2450
2519
  if (storedListener) {
2451
- fs6.unwatchFile(filePath, storedListener);
2520
+ fs9.unwatchFile(filePath, storedListener);
2452
2521
  _FileLogger.watchers.delete(watcherId);
2453
2522
  }
2454
2523
  },
@@ -2461,7 +2530,7 @@ var FileLogger = class _FileLogger extends EventEmitter {
2461
2530
  static stopAllWatchers() {
2462
2531
  for (const [watcherId] of _FileLogger.watchers) {
2463
2532
  const filePath = watcherId.split("_")[0];
2464
- fs6.unwatchFile(filePath);
2533
+ fs9.unwatchFile(filePath);
2465
2534
  }
2466
2535
  _FileLogger.watchers.clear();
2467
2536
  }
@@ -2491,7 +2560,7 @@ var FileLogger = class _FileLogger extends EventEmitter {
2491
2560
  if (lines.length > maxLines) {
2492
2561
  const keepLines = lines.slice(-maxLines);
2493
2562
  const content = keepLines.join("\n") + "\n";
2494
- await fs6.promises.writeFile(filePath, content, "utf8");
2563
+ await fs9.promises.writeFile(filePath, content, "utf8");
2495
2564
  return lines.length - maxLines;
2496
2565
  }
2497
2566
  return 0;
@@ -2506,8 +2575,8 @@ var FileLogger = class _FileLogger extends EventEmitter {
2506
2575
  */
2507
2576
  static async deleteLogFile(filePath) {
2508
2577
  try {
2509
- if (fs6.existsSync(filePath)) {
2510
- await fs6.promises.unlink(filePath);
2578
+ if (fs9.existsSync(filePath)) {
2579
+ await fs9.promises.unlink(filePath);
2511
2580
  return true;
2512
2581
  }
2513
2582
  return false;
@@ -2922,6 +2991,7 @@ export {
2922
2991
  DaemonClient,
2923
2992
  DbConfig,
2924
2993
  Engine,
2994
+ EnvLoader,
2925
2995
  FileLogger,
2926
2996
  QueryEngine,
2927
2997
  TableProcessor,