@grafema/rfdb 0.2.10 → 0.2.12-beta
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/README.md +20 -18
- package/index.d.ts +2 -17
- package/index.js +3 -31
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -39,32 +39,34 @@ rfdb-server ./my-graph.rfdb
|
|
|
39
39
|
|
|
40
40
|
### Programmatic usage
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
const { startServer, waitForServer, isAvailable } = require('@grafema/rfdb');
|
|
42
|
+
Server lifecycle is managed through `@grafema/core`:
|
|
44
43
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
console.log('RFDB not available, using in-memory backend');
|
|
48
|
-
}
|
|
44
|
+
```javascript
|
|
45
|
+
const { startRfdbServer, RFDBServerBackend } = require('@grafema/core');
|
|
49
46
|
|
|
50
|
-
// Start server
|
|
51
|
-
const server =
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
silent: false,
|
|
47
|
+
// Start server (handles binary discovery, socket polling, PID file)
|
|
48
|
+
const server = await startRfdbServer({
|
|
49
|
+
dbPath: './my-graph.rfdb',
|
|
50
|
+
socketPath: '.grafema/rfdb.sock',
|
|
55
51
|
});
|
|
56
52
|
|
|
57
|
-
//
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
// Use with @grafema/core
|
|
61
|
-
const { RFDBServerBackend } = require('@grafema/core');
|
|
62
|
-
const backend = new RFDBServerBackend({ socketPath: '/tmp/rfdb.sock' });
|
|
53
|
+
// Use with Grafema
|
|
54
|
+
const backend = new RFDBServerBackend({ socketPath: '.grafema/rfdb.sock' });
|
|
63
55
|
|
|
64
56
|
// Stop server when done
|
|
65
57
|
server.kill();
|
|
66
58
|
```
|
|
67
59
|
|
|
60
|
+
This package also exports helpers for binary detection:
|
|
61
|
+
|
|
62
|
+
```javascript
|
|
63
|
+
const { isAvailable, waitForServer } = require('@grafema/rfdb');
|
|
64
|
+
|
|
65
|
+
if (!isAvailable()) {
|
|
66
|
+
console.log('RFDB not available, using in-memory backend');
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
68
70
|
## With Grafema
|
|
69
71
|
|
|
70
72
|
RFDB is the default storage backend for Grafema. The MCP server and CLI auto-start RFDB when needed.
|
|
@@ -74,7 +76,7 @@ const { Orchestrator, RFDBServerBackend } = require('@grafema/core');
|
|
|
74
76
|
|
|
75
77
|
const orchestrator = new Orchestrator({
|
|
76
78
|
rootDir: './src',
|
|
77
|
-
backend: new RFDBServerBackend({ socketPath: '/
|
|
79
|
+
backend: new RFDBServerBackend({ socketPath: '.grafema/rfdb.sock' }),
|
|
78
80
|
});
|
|
79
81
|
```
|
|
80
82
|
|
package/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ChildProcess } from 'child_process';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* Get the path to the rfdb-server binary for the current platform.
|
|
3
|
+
* Only checks prebuilt directory. For full search, use findRfdbBinary() from @grafema/core.
|
|
4
|
+
* @deprecated Use findRfdbBinary() from @grafema/core for full binary search.
|
|
5
5
|
* @returns Path to binary, or null if not available
|
|
6
6
|
*/
|
|
7
7
|
export function getBinaryPath(): string | null;
|
|
@@ -11,21 +11,6 @@ export function getBinaryPath(): string | null;
|
|
|
11
11
|
*/
|
|
12
12
|
export function isAvailable(): boolean;
|
|
13
13
|
|
|
14
|
-
export interface StartServerOptions {
|
|
15
|
-
/** Unix socket path (default: /tmp/rfdb.sock) */
|
|
16
|
-
socketPath?: string;
|
|
17
|
-
/** Data directory (default: ./rfdb-data) */
|
|
18
|
-
dataDir?: string;
|
|
19
|
-
/** Suppress output (default: false) */
|
|
20
|
-
silent?: boolean;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Start the rfdb-server.
|
|
25
|
-
* @returns The server process
|
|
26
|
-
*/
|
|
27
|
-
export function startServer(options?: StartServerOptions): ChildProcess & { socketPath: string };
|
|
28
|
-
|
|
29
14
|
/**
|
|
30
15
|
* Wait for the server to be ready.
|
|
31
16
|
* @param socketPath Unix socket path
|
package/index.js
CHANGED
|
@@ -4,13 +4,15 @@
|
|
|
4
4
|
* This package provides the rfdb-server binary and helpers for managing it.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
const { spawn } = require('child_process');
|
|
8
7
|
const path = require('path');
|
|
9
8
|
const fs = require('fs');
|
|
10
9
|
const net = require('net');
|
|
11
10
|
|
|
12
11
|
/**
|
|
13
12
|
* Get the path to the rfdb-server binary for the current platform.
|
|
13
|
+
* Only checks prebuilt directory. For full search (monorepo, PATH, env var, ~/.local/bin),
|
|
14
|
+
* use findRfdbBinary() from @grafema/core instead.
|
|
15
|
+
* @deprecated Use findRfdbBinary() from @grafema/core for full binary search.
|
|
14
16
|
* @returns {string|null} Path to binary, or null if not available
|
|
15
17
|
*/
|
|
16
18
|
function getBinaryPath() {
|
|
@@ -38,35 +40,6 @@ function isAvailable() {
|
|
|
38
40
|
return getBinaryPath() !== null;
|
|
39
41
|
}
|
|
40
42
|
|
|
41
|
-
/**
|
|
42
|
-
* Start the rfdb-server.
|
|
43
|
-
* @param {Object} options
|
|
44
|
-
* @param {string} options.socketPath - Unix socket path (default: /tmp/rfdb.sock)
|
|
45
|
-
* @param {string} options.dataDir - Data directory (default: ./rfdb-data)
|
|
46
|
-
* @param {boolean} options.silent - Suppress output (default: false)
|
|
47
|
-
* @returns {ChildProcess} The server process
|
|
48
|
-
*/
|
|
49
|
-
function startServer(options = {}) {
|
|
50
|
-
const binaryPath = getBinaryPath();
|
|
51
|
-
if (!binaryPath) {
|
|
52
|
-
throw new Error(`No rfdb-server binary available for ${process.platform}-${process.arch}`);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const socketPath = options.socketPath || '/tmp/rfdb.sock';
|
|
56
|
-
const dataDir = options.dataDir || './rfdb-data';
|
|
57
|
-
|
|
58
|
-
const args = ['--socket', socketPath, '--data-dir', dataDir];
|
|
59
|
-
|
|
60
|
-
const child = spawn(binaryPath, args, {
|
|
61
|
-
stdio: options.silent ? 'ignore' : 'inherit',
|
|
62
|
-
detached: false,
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
child.socketPath = socketPath;
|
|
66
|
-
|
|
67
|
-
return child;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
43
|
/**
|
|
71
44
|
* Wait for the server to be ready.
|
|
72
45
|
* @param {string} socketPath - Unix socket path
|
|
@@ -102,6 +75,5 @@ function waitForServer(socketPath, timeout = 5000) {
|
|
|
102
75
|
module.exports = {
|
|
103
76
|
getBinaryPath,
|
|
104
77
|
isAvailable,
|
|
105
|
-
startServer,
|
|
106
78
|
waitForServer,
|
|
107
79
|
};
|