@liorandb/core 1.0.4 → 1.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@liorandb/core",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "LioranDB is a lightweight, local-first, peer-to-peer, file-based database with a MongoDB-style Node.js API and a simple CLI for seamless distributed development.",
5
5
  "main": "./src/index.js",
6
6
  "types": "./src/index.d.ts",
@@ -2,30 +2,43 @@ import os from "os";
2
2
  import path from "path";
3
3
  import fs from "fs";
4
4
 
5
- export function getBaseDBFolder() {
5
+ /**
6
+ * INTERNAL:
7
+ * Used by LioranManager to resolve default DB root path
8
+ * NO side effects. NO logs. NO installers.
9
+ */
10
+ export function getDefaultRootPath() {
6
11
  let dbPath = process.env.LIORANDB_PATH;
7
12
 
8
- // If LIORANDB_PATH is NOT set system-wide
9
13
  if (!dbPath) {
10
14
  const homeDir = os.homedir();
11
- dbPath = path.join(homeDir, "LioranDB");
15
+ dbPath = path.join(homeDir, "LioranDB", "db");
12
16
 
13
- // Ensure directory exists
14
17
  if (!fs.existsSync(dbPath)) {
15
18
  fs.mkdirSync(dbPath, { recursive: true });
16
19
  }
17
20
 
18
- // Set env var for current process
21
+ // process-level only
19
22
  process.env.LIORANDB_PATH = dbPath;
20
-
21
- // Create OS-specific installer scripts
22
- createSystemEnvInstaller(dbPath);
23
23
  }
24
24
 
25
25
  return dbPath;
26
26
  }
27
27
 
28
- function createSystemEnvInstaller(dbPath) {
28
+ /**
29
+ * PUBLIC:
30
+ * Backward-compatible helper
31
+ */
32
+ export function getBaseDBFolder() {
33
+ return getDefaultRootPath();
34
+ }
35
+
36
+ /**
37
+ * OPTIONAL:
38
+ * Explicit installer for system-wide env setup
39
+ * Must be called manually by user
40
+ */
41
+ export function installSystemEnv(dbPath = getDefaultRootPath()) {
29
42
  const platform = os.platform();
30
43
  const scriptsDir = path.join(os.tmpdir(), "lioran_env_setup");
31
44
 
@@ -35,6 +48,7 @@ function createSystemEnvInstaller(dbPath) {
35
48
 
36
49
  if (platform === "win32") {
37
50
  const winScript = path.join(scriptsDir, "set-lioran-env.ps1");
51
+
38
52
  fs.writeFileSync(
39
53
  winScript,
40
54
  `Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
@@ -43,35 +57,31 @@ Write-Host "LIORANDB_PATH set system-wide to: ${dbPath}"`,
43
57
  "utf8"
44
58
  );
45
59
 
46
- console.log(`
47
- ⚠️ LIORANDB_PATH is not set system-wide.
48
- Run this PowerShell script as ADMIN:
49
-
50
- ${winScript}
51
- `);
60
+ return {
61
+ platform: "windows",
62
+ script: winScript
63
+ };
52
64
  }
53
65
 
54
66
  if (platform === "linux" || platform === "darwin") {
55
67
  const bashScript = path.join(scriptsDir, "set-lioran-env.sh");
68
+
56
69
  fs.writeFileSync(
57
70
  bashScript,
58
71
  `#!/bin/bash
59
72
  echo 'export LIORANDB_PATH="${dbPath}"' >> ~/.bashrc
60
73
  echo 'export LIORANDB_PATH="${dbPath}"' >> ~/.zshrc
61
- echo "LIORANDB_PATH set system-wide to: ${dbPath}"
62
- source ~/.bashrc 2>/dev/null
63
- source ~/.zshrc 2>/dev/null
64
- `,
74
+ echo "LIORANDB_PATH set system-wide to: ${dbPath}"`,
65
75
  "utf8"
66
76
  );
67
77
 
68
78
  fs.chmodSync(bashScript, 0o755);
69
79
 
70
- console.log(`
71
- ⚠️ LIORANDB_PATH is not set system-wide.
72
- Run this script:
73
-
74
- bash ${bashScript}
75
- `);
80
+ return {
81
+ platform: platform,
82
+ script: bashScript
83
+ };
76
84
  }
85
+
86
+ return null;
77
87
  }