@plures/pluresdb 1.5.3 → 2.9.6
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 +106 -414
- package/crates/README.md +99 -0
- package/crates/pluresdb-node/README.md +181 -0
- package/crates/pluresdb-node/index.d.ts +0 -0
- package/crates/pluresdb-node/index.js +265 -0
- package/crates/pluresdb-node/package.json +35 -0
- package/dist/napi/index.js +60 -0
- package/embedded.d.ts +1 -0
- package/embedded.js +46 -0
- package/package.json +27 -10
- package/dist/.tsbuildinfo +0 -1
- package/dist/better-sqlite3-shared.d.ts +0 -12
- package/dist/better-sqlite3-shared.d.ts.map +0 -1
- package/dist/better-sqlite3-shared.js +0 -143
- package/dist/better-sqlite3-shared.js.map +0 -1
- package/dist/better-sqlite3.d.ts +0 -4
- package/dist/better-sqlite3.d.ts.map +0 -1
- package/dist/better-sqlite3.js +0 -8
- package/dist/better-sqlite3.js.map +0 -1
- package/dist/cli.d.ts +0 -7
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/node-index.d.ts +0 -148
- package/dist/node-index.d.ts.map +0 -1
- package/dist/node-index.js +0 -665
- package/dist/node-index.js.map +0 -1
- package/dist/node-wrapper.d.ts +0 -44
- package/dist/node-wrapper.d.ts.map +0 -1
- package/dist/node-wrapper.js +0 -296
- package/dist/node-wrapper.js.map +0 -1
- package/dist/types/index.d.ts +0 -28
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -3
- package/dist/types/index.js.map +0 -1
- package/dist/types/node-types.d.ts +0 -71
- package/dist/types/node-types.d.ts.map +0 -1
- package/dist/types/node-types.js +0 -6
- package/dist/types/node-types.js.map +0 -1
- package/dist/vscode/extension.d.ts +0 -81
- package/dist/vscode/extension.d.ts.map +0 -1
- package/dist/vscode/extension.js +0 -309
- package/dist/vscode/extension.js.map +0 -1
- package/examples/basic-usage.d.ts +0 -2
- package/examples/basic-usage.d.ts.map +0 -1
- package/examples/basic-usage.js +0 -26
- package/examples/basic-usage.js.map +0 -1
- package/examples/basic-usage.ts +0 -29
- package/examples/vscode-extension-example/README.md +0 -95
- package/examples/vscode-extension-example/package.json +0 -49
- package/examples/vscode-extension-example/src/extension.ts +0 -172
- package/examples/vscode-extension-example/tsconfig.json +0 -12
- package/examples/vscode-extension-integration.d.ts +0 -31
- package/examples/vscode-extension-integration.d.ts.map +0 -1
- package/examples/vscode-extension-integration.js +0 -319
- package/examples/vscode-extension-integration.js.map +0 -1
- package/examples/vscode-extension-integration.ts +0 -41
- package/legacy/benchmarks/memory-benchmarks.ts +0 -350
- package/legacy/benchmarks/run-benchmarks.ts +0 -315
- package/legacy/better-sqlite3-shared.ts +0 -157
- package/legacy/better-sqlite3.ts +0 -4
- package/legacy/cli.ts +0 -241
- package/legacy/config.ts +0 -50
- package/legacy/core/crdt.ts +0 -107
- package/legacy/core/database.ts +0 -529
- package/legacy/healthcheck.ts +0 -162
- package/legacy/http/api-server.ts +0 -438
- package/legacy/index.ts +0 -28
- package/legacy/logic/rules.ts +0 -46
- package/legacy/main.rs +0 -3
- package/legacy/main.ts +0 -197
- package/legacy/network/websocket-server.ts +0 -115
- package/legacy/node-index.ts +0 -823
- package/legacy/node-wrapper.ts +0 -329
- package/legacy/sqlite-compat.ts +0 -633
- package/legacy/sqlite3-compat.ts +0 -55
- package/legacy/storage/kv-storage.ts +0 -73
- package/legacy/tests/core.test.ts +0 -305
- package/legacy/tests/fixtures/performance-data.json +0 -71
- package/legacy/tests/fixtures/test-data.json +0 -129
- package/legacy/tests/integration/api-server.test.ts +0 -334
- package/legacy/tests/integration/mesh-network.test.ts +0 -303
- package/legacy/tests/logic.test.ts +0 -34
- package/legacy/tests/performance/load.test.ts +0 -290
- package/legacy/tests/security/input-validation.test.ts +0 -286
- package/legacy/tests/unit/core.test.ts +0 -226
- package/legacy/tests/unit/subscriptions.test.ts +0 -135
- package/legacy/tests/unit/vector-search.test.ts +0 -173
- package/legacy/tests/vscode_extension_test.ts +0 -281
- package/legacy/types/index.ts +0 -32
- package/legacy/types/node-types.ts +0 -80
- package/legacy/util/debug.ts +0 -14
- package/legacy/vector/index.ts +0 -59
- package/legacy/vscode/extension.ts +0 -387
- package/scripts/compiled-crud-verify.ts +0 -30
- package/scripts/dogfood.ts +0 -297
- package/scripts/postinstall.js +0 -156
- package/scripts/publish-crates.sh +0 -95
- package/scripts/release-check.js +0 -224
- package/scripts/run-tests.ts +0 -178
- package/scripts/setup-libclang.ps1 +0 -209
- package/scripts/update-changelog.js +0 -214
- package/web/README.md +0 -27
- package/web/svelte/package.json +0 -31
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
# @plures/pluresdb-native
|
|
2
|
+
|
|
3
|
+
Native Node.js bindings for PluresDB - a P2P Graph Database with SQLite compatibility.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@plures/pluresdb-native)
|
|
6
|
+
[](../../LICENSE)
|
|
7
|
+
|
|
8
|
+
This package provides high-performance N-API bindings to the PluresDB Rust core, enabling native database operations directly from Node.js.
|
|
9
|
+
|
|
10
|
+
## ✅ Features
|
|
11
|
+
|
|
12
|
+
- **CRUD Operations** - Create, read, update, and delete nodes with CRDT synchronization
|
|
13
|
+
- **SQL Support** - Execute SQL queries with parameterized statements (95% SQLite compatible)
|
|
14
|
+
- **BLOB Support** - Store binary data including embedding vectors
|
|
15
|
+
- **Search** - Text-based and vector similarity search
|
|
16
|
+
- **Type Filtering** - Filter nodes by type
|
|
17
|
+
- **Subscriptions** - Subscribe to database changes
|
|
18
|
+
- **Native Performance** - Rust-powered N-API bindings for maximum speed
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install @plures/pluresdb-native
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Pre-built binaries are available for:
|
|
27
|
+
- **Linux**: x86_64, aarch64 (GNU libc)
|
|
28
|
+
- **macOS**: x86_64 (Intel), aarch64 (Apple Silicon)
|
|
29
|
+
- **Windows**: x86_64, aarch64 (MSVC)
|
|
30
|
+
|
|
31
|
+
## Quick Start
|
|
32
|
+
|
|
33
|
+
```javascript
|
|
34
|
+
const { PluresDatabase } = require('@plures/pluresdb-native');
|
|
35
|
+
|
|
36
|
+
// Create a new database instance
|
|
37
|
+
const db = new PluresDatabase('my-actor');
|
|
38
|
+
|
|
39
|
+
// Insert a node
|
|
40
|
+
const id = db.put('user-1', {
|
|
41
|
+
name: 'Alice',
|
|
42
|
+
email: 'alice@example.com',
|
|
43
|
+
type: 'User'
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// Retrieve a node
|
|
47
|
+
const user = db.get('user-1');
|
|
48
|
+
console.log(user); // { name: 'Alice', email: 'alice@example.com', type: 'User' }
|
|
49
|
+
|
|
50
|
+
// List all nodes
|
|
51
|
+
const all = db.list();
|
|
52
|
+
|
|
53
|
+
// Delete a node
|
|
54
|
+
db.delete('user-1');
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## SQL Support
|
|
58
|
+
|
|
59
|
+
```javascript
|
|
60
|
+
// Create database with SQL support (provide db_path)
|
|
61
|
+
const db = new PluresDatabase('my-actor', './data.db');
|
|
62
|
+
|
|
63
|
+
// Create table
|
|
64
|
+
db.exec(`
|
|
65
|
+
CREATE TABLE IF NOT EXISTS users (
|
|
66
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
67
|
+
name TEXT NOT NULL,
|
|
68
|
+
email TEXT UNIQUE,
|
|
69
|
+
embedding BLOB
|
|
70
|
+
)
|
|
71
|
+
`);
|
|
72
|
+
|
|
73
|
+
// Insert data
|
|
74
|
+
db.exec(`INSERT INTO users (name, email) VALUES ('Alice', 'alice@example.com')`);
|
|
75
|
+
|
|
76
|
+
// Query with parameters (supports ? placeholders)
|
|
77
|
+
const result = db.query('SELECT * FROM users WHERE name = ?', ['Alice']);
|
|
78
|
+
console.log(result.rows); // [{ id: 1, name: 'Alice', email: 'alice@example.com', embedding: null }]
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## API Reference
|
|
82
|
+
|
|
83
|
+
### Constructor
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
new PluresDatabase(actorId?: string, dbPath?: string)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
- `actorId` (optional): Unique identifier for this database instance. Default: `"node-actor"`
|
|
90
|
+
- `dbPath` (optional): Path to SQLite database file for SQL support
|
|
91
|
+
|
|
92
|
+
### Methods
|
|
93
|
+
|
|
94
|
+
#### CRUD Operations
|
|
95
|
+
|
|
96
|
+
- `put(id: string, data: any): string` - Insert or update a node
|
|
97
|
+
- `get(id: string): any | null` - Retrieve a node by ID
|
|
98
|
+
- `getWithMetadata(id: string): NodeWithMetadata | null` - Get node with vector clock and timestamp
|
|
99
|
+
- `delete(id: string): void` - Delete a node
|
|
100
|
+
- `list(): Array<{id, data, timestamp}>` - List all nodes
|
|
101
|
+
- `listByType(nodeType: string): Array<{id, data, timestamp}>` - Filter nodes by type
|
|
102
|
+
|
|
103
|
+
#### SQL Operations
|
|
104
|
+
|
|
105
|
+
- `query(sql: string, params?: any[]): QueryResult` - Execute SQL SELECT with parameters
|
|
106
|
+
- `exec(sql: string): ExecutionResult` - Execute SQL statement (INSERT, UPDATE, DELETE, CREATE)
|
|
107
|
+
|
|
108
|
+
**Example:**
|
|
109
|
+
```javascript
|
|
110
|
+
const result = db.query('SELECT * FROM users WHERE age > ?', [25]);
|
|
111
|
+
console.log(result.rows); // Array of matching rows
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
#### Search
|
|
115
|
+
|
|
116
|
+
- `search(query: string, limit?: number): SearchResult[]` - Text search across node data
|
|
117
|
+
- `vectorSearch(query: string, limit?: number, threshold?: number): SearchResult[]` - Vector similarity search
|
|
118
|
+
|
|
119
|
+
#### Utilities
|
|
120
|
+
|
|
121
|
+
- `subscribe(): string` - Subscribe to database changes
|
|
122
|
+
- `getActorId(): string` - Get the actor ID
|
|
123
|
+
- `stats(): DatabaseStats` - Get database statistics (`{totalNodes, typeCounts}`)
|
|
124
|
+
|
|
125
|
+
## TypeScript Support
|
|
126
|
+
|
|
127
|
+
TypeScript definitions are included in the package.
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
import { PluresDatabase, QueryResult, ExecutionResult } from '@plures/pluresdb-native';
|
|
131
|
+
|
|
132
|
+
const db = new PluresDatabase('my-actor', './data.db');
|
|
133
|
+
const result: QueryResult = db.query('SELECT * FROM users WHERE id = ?', [1]);
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## SLM (superlocalmemory) Compatibility
|
|
137
|
+
|
|
138
|
+
This package is designed as a drop-in replacement for better-sqlite3 in the superlocalmemory project:
|
|
139
|
+
|
|
140
|
+
- ✅ Parameterized SQL with `?` placeholders
|
|
141
|
+
- ✅ BLOB column support for embedding vectors
|
|
142
|
+
- ✅ Synchronous API (no async/await required)
|
|
143
|
+
- ✅ 95% SQLite compatibility
|
|
144
|
+
|
|
145
|
+
See the [SLM Migration Guide](https://github.com/plures/development-guide/blob/main/goals/SLM-PLURESDB-MIGRATION.md) for details.
|
|
146
|
+
|
|
147
|
+
## Building from Source
|
|
148
|
+
|
|
149
|
+
If a pre-built binary is not available for your platform:
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
# Clone the repository
|
|
153
|
+
git clone https://github.com/plures/pluresdb.git
|
|
154
|
+
cd pluresdb/crates/pluresdb-node
|
|
155
|
+
|
|
156
|
+
# Install dependencies
|
|
157
|
+
npm install
|
|
158
|
+
|
|
159
|
+
# Build
|
|
160
|
+
npm run build
|
|
161
|
+
|
|
162
|
+
# Test
|
|
163
|
+
npm test
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### Requirements
|
|
167
|
+
|
|
168
|
+
- Rust 1.70 or later
|
|
169
|
+
- Node.js 20 or later
|
|
170
|
+
- C compiler (for rusqlite native dependencies)
|
|
171
|
+
|
|
172
|
+
## License
|
|
173
|
+
|
|
174
|
+
AGPL-3.0 - see [LICENSE](../../LICENSE) for details.
|
|
175
|
+
|
|
176
|
+
## Links
|
|
177
|
+
|
|
178
|
+
- [GitHub Repository](https://github.com/plures/pluresdb)
|
|
179
|
+
- [PluresDB Documentation](https://github.com/plures/pluresdb#readme)
|
|
180
|
+
- [Issue Tracker](https://github.com/plures/pluresdb/issues)
|
|
181
|
+
- [NPM Package](https://www.npmjs.com/package/@plures/pluresdb-native)
|
|
File without changes
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
const { existsSync, readFileSync } = require("fs");
|
|
2
|
+
const { join } = require("path");
|
|
3
|
+
|
|
4
|
+
const { platform, arch } = process;
|
|
5
|
+
|
|
6
|
+
let nativeBinding = null;
|
|
7
|
+
let localFileExisted = false;
|
|
8
|
+
let loadError = null;
|
|
9
|
+
|
|
10
|
+
function isMusl() {
|
|
11
|
+
// For non-glibc Linux systems we must check if musl is used instead
|
|
12
|
+
if (!process.report || typeof process.report.getReport !== "function") {
|
|
13
|
+
try {
|
|
14
|
+
const lddPath = require("child_process")
|
|
15
|
+
.execSync("which ldd")
|
|
16
|
+
.toString()
|
|
17
|
+
.trim();
|
|
18
|
+
return readFileSync(lddPath, "utf8").includes("musl");
|
|
19
|
+
} catch (e) {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
} else {
|
|
23
|
+
const { glibcVersionRuntime } = process.report.getReport().header;
|
|
24
|
+
return !glibcVersionRuntime;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
switch (platform) {
|
|
29
|
+
case "android":
|
|
30
|
+
switch (arch) {
|
|
31
|
+
case "arm64":
|
|
32
|
+
localFileExisted = existsSync(
|
|
33
|
+
join(__dirname, "pluresdb-node.android-arm64.node")
|
|
34
|
+
);
|
|
35
|
+
try {
|
|
36
|
+
if (localFileExisted) {
|
|
37
|
+
nativeBinding = require("./pluresdb-node.android-arm64.node");
|
|
38
|
+
} else {
|
|
39
|
+
nativeBinding = require("@plures/pluresdb-native-android-arm64");
|
|
40
|
+
}
|
|
41
|
+
} catch (e) {
|
|
42
|
+
loadError = e;
|
|
43
|
+
}
|
|
44
|
+
break;
|
|
45
|
+
case "arm":
|
|
46
|
+
localFileExisted = existsSync(
|
|
47
|
+
join(__dirname, "pluresdb-node.android-arm-eabi.node")
|
|
48
|
+
);
|
|
49
|
+
try {
|
|
50
|
+
if (localFileExisted) {
|
|
51
|
+
nativeBinding = require("./pluresdb-node.android-arm-eabi.node");
|
|
52
|
+
} else {
|
|
53
|
+
nativeBinding = require("@plures/pluresdb-native-android-arm-eabi");
|
|
54
|
+
}
|
|
55
|
+
} catch (e) {
|
|
56
|
+
loadError = e;
|
|
57
|
+
}
|
|
58
|
+
break;
|
|
59
|
+
default:
|
|
60
|
+
throw new Error(`Unsupported architecture on Android ${arch}`);
|
|
61
|
+
}
|
|
62
|
+
break;
|
|
63
|
+
case "win32":
|
|
64
|
+
switch (arch) {
|
|
65
|
+
case "x64":
|
|
66
|
+
localFileExisted = existsSync(
|
|
67
|
+
join(__dirname, "pluresdb-node.win32-x64-msvc.node")
|
|
68
|
+
);
|
|
69
|
+
try {
|
|
70
|
+
if (localFileExisted) {
|
|
71
|
+
nativeBinding = require("./pluresdb-node.win32-x64-msvc.node");
|
|
72
|
+
} else {
|
|
73
|
+
nativeBinding = require("@plures/pluresdb-native-win32-x64-msvc");
|
|
74
|
+
}
|
|
75
|
+
} catch (e) {
|
|
76
|
+
loadError = e;
|
|
77
|
+
}
|
|
78
|
+
break;
|
|
79
|
+
case "ia32":
|
|
80
|
+
localFileExisted = existsSync(
|
|
81
|
+
join(__dirname, "pluresdb-node.win32-ia32-msvc.node")
|
|
82
|
+
);
|
|
83
|
+
try {
|
|
84
|
+
if (localFileExisted) {
|
|
85
|
+
nativeBinding = require("./pluresdb-node.win32-ia32-msvc.node");
|
|
86
|
+
} else {
|
|
87
|
+
nativeBinding = require("@plures/pluresdb-native-win32-ia32-msvc");
|
|
88
|
+
}
|
|
89
|
+
} catch (e) {
|
|
90
|
+
loadError = e;
|
|
91
|
+
}
|
|
92
|
+
break;
|
|
93
|
+
case "arm64":
|
|
94
|
+
localFileExisted = existsSync(
|
|
95
|
+
join(__dirname, "pluresdb-node.win32-arm64-msvc.node")
|
|
96
|
+
);
|
|
97
|
+
try {
|
|
98
|
+
if (localFileExisted) {
|
|
99
|
+
nativeBinding = require("./pluresdb-node.win32-arm64-msvc.node");
|
|
100
|
+
} else {
|
|
101
|
+
nativeBinding = require("@plures/pluresdb-native-win32-arm64-msvc");
|
|
102
|
+
}
|
|
103
|
+
} catch (e) {
|
|
104
|
+
loadError = e;
|
|
105
|
+
}
|
|
106
|
+
break;
|
|
107
|
+
default:
|
|
108
|
+
throw new Error(`Unsupported architecture on Windows: ${arch}`);
|
|
109
|
+
}
|
|
110
|
+
break;
|
|
111
|
+
case "darwin":
|
|
112
|
+
localFileExisted = existsSync(
|
|
113
|
+
join(__dirname, "pluresdb-node.darwin-universal.node")
|
|
114
|
+
);
|
|
115
|
+
try {
|
|
116
|
+
if (localFileExisted) {
|
|
117
|
+
nativeBinding = require("./pluresdb-node.darwin-universal.node");
|
|
118
|
+
} else {
|
|
119
|
+
nativeBinding = require("@plures/pluresdb-native-darwin-universal");
|
|
120
|
+
}
|
|
121
|
+
break;
|
|
122
|
+
} catch {}
|
|
123
|
+
switch (arch) {
|
|
124
|
+
case "x64":
|
|
125
|
+
localFileExisted = existsSync(
|
|
126
|
+
join(__dirname, "pluresdb-node.darwin-x64.node")
|
|
127
|
+
);
|
|
128
|
+
try {
|
|
129
|
+
if (localFileExisted) {
|
|
130
|
+
nativeBinding = require("./pluresdb-node.darwin-x64.node");
|
|
131
|
+
} else {
|
|
132
|
+
nativeBinding = require("@plures/pluresdb-native-darwin-x64");
|
|
133
|
+
}
|
|
134
|
+
} catch (e) {
|
|
135
|
+
loadError = e;
|
|
136
|
+
}
|
|
137
|
+
break;
|
|
138
|
+
case "arm64":
|
|
139
|
+
localFileExisted = existsSync(
|
|
140
|
+
join(__dirname, "pluresdb-node.darwin-arm64.node")
|
|
141
|
+
);
|
|
142
|
+
try {
|
|
143
|
+
if (localFileExisted) {
|
|
144
|
+
nativeBinding = require("./pluresdb-node.darwin-arm64.node");
|
|
145
|
+
} else {
|
|
146
|
+
nativeBinding = require("@plures/pluresdb-native-darwin-arm64");
|
|
147
|
+
}
|
|
148
|
+
} catch (e) {
|
|
149
|
+
loadError = e;
|
|
150
|
+
}
|
|
151
|
+
break;
|
|
152
|
+
default:
|
|
153
|
+
throw new Error(`Unsupported architecture on macOS: ${arch}`);
|
|
154
|
+
}
|
|
155
|
+
break;
|
|
156
|
+
case "freebsd":
|
|
157
|
+
if (arch !== "x64") {
|
|
158
|
+
throw new Error(`Unsupported architecture on FreeBSD: ${arch}`);
|
|
159
|
+
}
|
|
160
|
+
localFileExisted = existsSync(
|
|
161
|
+
join(__dirname, "pluresdb-node.freebsd-x64.node")
|
|
162
|
+
);
|
|
163
|
+
try {
|
|
164
|
+
if (localFileExisted) {
|
|
165
|
+
nativeBinding = require("./pluresdb-node.freebsd-x64.node");
|
|
166
|
+
} else {
|
|
167
|
+
nativeBinding = require("@plures/pluresdb-native-freebsd-x64");
|
|
168
|
+
}
|
|
169
|
+
} catch (e) {
|
|
170
|
+
loadError = e;
|
|
171
|
+
}
|
|
172
|
+
break;
|
|
173
|
+
case "linux":
|
|
174
|
+
switch (arch) {
|
|
175
|
+
case "x64":
|
|
176
|
+
if (isMusl()) {
|
|
177
|
+
localFileExisted = existsSync(
|
|
178
|
+
join(__dirname, "pluresdb-node.linux-x64-musl.node")
|
|
179
|
+
);
|
|
180
|
+
try {
|
|
181
|
+
if (localFileExisted) {
|
|
182
|
+
nativeBinding = require("./pluresdb-node.linux-x64-musl.node");
|
|
183
|
+
} else {
|
|
184
|
+
nativeBinding = require("@plures/pluresdb-native-linux-x64-musl");
|
|
185
|
+
}
|
|
186
|
+
} catch (e) {
|
|
187
|
+
loadError = e;
|
|
188
|
+
}
|
|
189
|
+
} else {
|
|
190
|
+
localFileExisted = existsSync(
|
|
191
|
+
join(__dirname, "pluresdb-node.linux-x64-gnu.node")
|
|
192
|
+
);
|
|
193
|
+
try {
|
|
194
|
+
if (localFileExisted) {
|
|
195
|
+
nativeBinding = require("./pluresdb-node.linux-x64-gnu.node");
|
|
196
|
+
} else {
|
|
197
|
+
nativeBinding = require("@plures/pluresdb-native-linux-x64-gnu");
|
|
198
|
+
}
|
|
199
|
+
} catch (e) {
|
|
200
|
+
loadError = e;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
break;
|
|
204
|
+
case "arm64":
|
|
205
|
+
if (isMusl()) {
|
|
206
|
+
localFileExisted = existsSync(
|
|
207
|
+
join(__dirname, "pluresdb-node.linux-arm64-musl.node")
|
|
208
|
+
);
|
|
209
|
+
try {
|
|
210
|
+
if (localFileExisted) {
|
|
211
|
+
nativeBinding = require("./pluresdb-node.linux-arm64-musl.node");
|
|
212
|
+
} else {
|
|
213
|
+
nativeBinding = require("@plures/pluresdb-native-linux-arm64-musl");
|
|
214
|
+
}
|
|
215
|
+
} catch (e) {
|
|
216
|
+
loadError = e;
|
|
217
|
+
}
|
|
218
|
+
} else {
|
|
219
|
+
localFileExisted = existsSync(
|
|
220
|
+
join(__dirname, "pluresdb-node.linux-arm64-gnu.node")
|
|
221
|
+
);
|
|
222
|
+
try {
|
|
223
|
+
if (localFileExisted) {
|
|
224
|
+
nativeBinding = require("./pluresdb-node.linux-arm64-gnu.node");
|
|
225
|
+
} else {
|
|
226
|
+
nativeBinding = require("@plures/pluresdb-native-linux-arm64-gnu");
|
|
227
|
+
}
|
|
228
|
+
} catch (e) {
|
|
229
|
+
loadError = e;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
break;
|
|
233
|
+
case "arm":
|
|
234
|
+
localFileExisted = existsSync(
|
|
235
|
+
join(__dirname, "pluresdb-node.linux-arm-gnueabihf.node")
|
|
236
|
+
);
|
|
237
|
+
try {
|
|
238
|
+
if (localFileExisted) {
|
|
239
|
+
nativeBinding = require("./pluresdb-node.linux-arm-gnueabihf.node");
|
|
240
|
+
} else {
|
|
241
|
+
nativeBinding = require("@plures/pluresdb-native-linux-arm-gnueabihf");
|
|
242
|
+
}
|
|
243
|
+
} catch (e) {
|
|
244
|
+
loadError = e;
|
|
245
|
+
}
|
|
246
|
+
break;
|
|
247
|
+
default:
|
|
248
|
+
throw new Error(`Unsupported architecture on Linux: ${arch}`);
|
|
249
|
+
}
|
|
250
|
+
break;
|
|
251
|
+
default:
|
|
252
|
+
throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if (!nativeBinding) {
|
|
256
|
+
if (loadError) {
|
|
257
|
+
throw loadError;
|
|
258
|
+
}
|
|
259
|
+
throw new Error(`Failed to load native binding`);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
const { PluresDatabase, init } = nativeBinding;
|
|
263
|
+
|
|
264
|
+
module.exports.PluresDatabase = PluresDatabase;
|
|
265
|
+
module.exports.init = init;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@plures/pluresdb-native",
|
|
3
|
+
"version": "2.0.0-alpha.1",
|
|
4
|
+
"description": "Native Node.js bindings for PluresDB",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"napi": {
|
|
8
|
+
"binaryName": "pluresdb-node",
|
|
9
|
+
"targets": [
|
|
10
|
+
"x86_64-unknown-linux-gnu",
|
|
11
|
+
"aarch64-unknown-linux-gnu",
|
|
12
|
+
"x86_64-apple-darwin",
|
|
13
|
+
"aarch64-apple-darwin",
|
|
14
|
+
"x86_64-pc-windows-msvc",
|
|
15
|
+
"aarch64-pc-windows-msvc"
|
|
16
|
+
]
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "napi build --platform --release",
|
|
20
|
+
"build:debug": "napi build --platform",
|
|
21
|
+
"test": "node test-node.js",
|
|
22
|
+
"prepublishOnly": "npm run build"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"database",
|
|
26
|
+
"pluresdb",
|
|
27
|
+
"native",
|
|
28
|
+
"napi"
|
|
29
|
+
],
|
|
30
|
+
"author": "Plures Organization",
|
|
31
|
+
"license": "AGPL-3.0",
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@napi-rs/cli": "^3.5.1"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* NAPI-based entry point for PluresDB Node.js bindings.
|
|
4
|
+
*
|
|
5
|
+
* This is the primary interface for Node.js consumers.
|
|
6
|
+
* The native Rust bindings provide direct in-process access to the database,
|
|
7
|
+
* eliminating the need to spawn a separate Deno server process.
|
|
8
|
+
*
|
|
9
|
+
* For the legacy HTTP-based interface, use '@plures/pluresdb/legacy'.
|
|
10
|
+
*/
|
|
11
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
14
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
15
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
16
|
+
}
|
|
17
|
+
Object.defineProperty(o, k2, desc);
|
|
18
|
+
}) : (function(o, m, k, k2) {
|
|
19
|
+
if (k2 === undefined) k2 = k;
|
|
20
|
+
o[k2] = m[k];
|
|
21
|
+
}));
|
|
22
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
23
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
24
|
+
}) : function(o, v) {
|
|
25
|
+
o["default"] = v;
|
|
26
|
+
});
|
|
27
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
28
|
+
var ownKeys = function(o) {
|
|
29
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
30
|
+
var ar = [];
|
|
31
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
32
|
+
return ar;
|
|
33
|
+
};
|
|
34
|
+
return ownKeys(o);
|
|
35
|
+
};
|
|
36
|
+
return function (mod) {
|
|
37
|
+
if (mod && mod.__esModule) return mod;
|
|
38
|
+
var result = {};
|
|
39
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
40
|
+
__setModuleDefault(result, mod);
|
|
41
|
+
return result;
|
|
42
|
+
};
|
|
43
|
+
})();
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.PluresDatabase = void 0;
|
|
46
|
+
const path = __importStar(require("node:path"));
|
|
47
|
+
// The crates/pluresdb-node/index.js loader selects the correct platform-specific
|
|
48
|
+
// .node binary and falls back to scoped npm packages (e.g.
|
|
49
|
+
// @plures/pluresdb-native-linux-x64-gnu) when no local binary is present.
|
|
50
|
+
//
|
|
51
|
+
// Path calculation: this file compiles to dist/napi/index.js, so __dirname at
|
|
52
|
+
// runtime is <pkg-root>/dist/napi/ and ../../ resolves to <pkg-root>/, which is
|
|
53
|
+
// exactly where crates/pluresdb-node/index.js lives (included in the npm package
|
|
54
|
+
// via the "files" field in package.json).
|
|
55
|
+
const nativeLoaderPath = path.resolve(__dirname, "../../crates/pluresdb-node/index.js");
|
|
56
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
57
|
+
const native = require(nativeLoaderPath);
|
|
58
|
+
exports.PluresDatabase = native.PluresDatabase;
|
|
59
|
+
exports.default = exports.PluresDatabase;
|
|
60
|
+
//# sourceMappingURL=index.js.map
|
package/embedded.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { PluresDatabase, QueryResult, ExecutionResult, NodeWithMetadata, SearchResult, DatabaseStats, init } from './crates/pluresdb-node/index';
|
package/embedded.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PluresDB Embedded - Pure embedded database (no server process required)
|
|
3
|
+
*
|
|
4
|
+
* Re-exports the native N-API bindings from @plures/pluresdb-native.
|
|
5
|
+
* Requires the native `.node` binary to be built first:
|
|
6
|
+
* cd crates/pluresdb-node && npm run build
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* const { PluresDatabase } = require('@plures/pluresdb/embedded');
|
|
10
|
+
* const db = new PluresDatabase('my-actor', '/tmp/my.db');
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const path = require('path');
|
|
14
|
+
|
|
15
|
+
let nativeModule;
|
|
16
|
+
try {
|
|
17
|
+
// Try loading the platform-specific binary via napi-rs conventions
|
|
18
|
+
const platformTriple = `${process.arch === 'x64' ? 'x86_64' : process.arch === 'arm64' ? 'aarch64' : process.arch}-${
|
|
19
|
+
process.platform === 'linux' ? 'unknown-linux-gnu' :
|
|
20
|
+
process.platform === 'darwin' ? 'apple-darwin' :
|
|
21
|
+
process.platform === 'win32' ? 'pc-windows-msvc' : process.platform
|
|
22
|
+
}`;
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
// Try platform-specific package first (npm optional deps pattern)
|
|
26
|
+
nativeModule = require(`@plures/pluresdb-native-${platformTriple}`);
|
|
27
|
+
} catch {
|
|
28
|
+
// Fall back to local build output in crates/pluresdb-node/
|
|
29
|
+
nativeModule = require(path.join(__dirname, 'crates', 'pluresdb-node', `pluresdb-node.${process.platform}-${process.arch === 'x64' ? 'x86_64' : process.arch}-${process.platform === 'linux' ? 'gnu' : ''}.node`));
|
|
30
|
+
}
|
|
31
|
+
} catch (err) {
|
|
32
|
+
// Final fallback: try loading index.js from the native crate directory
|
|
33
|
+
try {
|
|
34
|
+
nativeModule = require(path.join(__dirname, 'crates', 'pluresdb-node', 'index.js'));
|
|
35
|
+
} catch {
|
|
36
|
+
throw new Error(
|
|
37
|
+
`Failed to load PluresDB native bindings. ` +
|
|
38
|
+
`The native .node binary must be built first:\n` +
|
|
39
|
+
` cd crates/pluresdb-node && npm run build\n` +
|
|
40
|
+
`Or install the pre-built binary: npm install @plures/pluresdb-native\n` +
|
|
41
|
+
`Original error: ${err.message}`
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
module.exports = nativeModule;
|
package/package.json
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plures/pluresdb",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.9.6",
|
|
4
4
|
"description": "P2P Graph Database with SQLite Compatibility - Local-first, offline-first database for modern applications",
|
|
5
|
-
"main": "dist/
|
|
6
|
-
"types": "dist/
|
|
5
|
+
"main": "dist/napi/index.js",
|
|
6
|
+
"types": "dist/napi/index.d.ts",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": {
|
|
9
|
+
"types": "./dist/napi/index.d.ts",
|
|
10
|
+
"require": "./dist/napi/index.js",
|
|
11
|
+
"default": "./dist/napi/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./legacy": {
|
|
9
14
|
"types": "./dist/node-index.d.ts",
|
|
10
15
|
"require": "./dist/node-index.js",
|
|
11
16
|
"default": "./dist/node-index.js"
|
|
@@ -20,6 +25,11 @@
|
|
|
20
25
|
"require": "./dist/better-sqlite3.js",
|
|
21
26
|
"default": "./dist/better-sqlite3.js"
|
|
22
27
|
},
|
|
28
|
+
"./embedded": {
|
|
29
|
+
"types": "./embedded.d.ts",
|
|
30
|
+
"require": "./embedded.js",
|
|
31
|
+
"default": "./embedded.js"
|
|
32
|
+
},
|
|
23
33
|
"./vscode": {
|
|
24
34
|
"types": "./dist/vscode/extension.d.ts",
|
|
25
35
|
"require": "./dist/vscode/extension.js",
|
|
@@ -35,6 +45,11 @@
|
|
|
35
45
|
"require": "./dist/types/node-types.js",
|
|
36
46
|
"default": "./dist/types/node-types.js"
|
|
37
47
|
},
|
|
48
|
+
"./local-first": {
|
|
49
|
+
"types": "./dist/local-first/unified-api.d.ts",
|
|
50
|
+
"require": "./dist/local-first/unified-api.js",
|
|
51
|
+
"default": "./dist/local-first/unified-api.js"
|
|
52
|
+
},
|
|
38
53
|
"./package.json": "./package.json"
|
|
39
54
|
},
|
|
40
55
|
"bin": {
|
|
@@ -46,7 +61,7 @@
|
|
|
46
61
|
"build:web": "cd web/svelte && npm install && npm run build",
|
|
47
62
|
"dev": "deno run -A --unstable-kv --watch src/main.ts serve --port 34567",
|
|
48
63
|
"start": "node dist/cli.js serve",
|
|
49
|
-
"test": "deno test -A --unstable-kv",
|
|
64
|
+
"test": "deno test -A --unstable-kv --sloppy-imports",
|
|
50
65
|
"test:azure:relay": "deno test --allow-net --allow-env azure/tests/relay-tests.ts",
|
|
51
66
|
"test:azure:full": "npm run test:azure:relay",
|
|
52
67
|
"lint": "eslint . --ext .js,.ts,.tsx",
|
|
@@ -55,6 +70,7 @@
|
|
|
55
70
|
"verify": "npm run build:lib && npm test",
|
|
56
71
|
"prepare": "npm run build:lib",
|
|
57
72
|
"prepublishOnly": "npm run verify && npm run build:web",
|
|
73
|
+
"validate-publish": "node scripts/validate-npm-publish.js",
|
|
58
74
|
"postinstall": "node scripts/postinstall.js",
|
|
59
75
|
"release-check": "node scripts/release-check.js",
|
|
60
76
|
"update-changelog": "node scripts/update-changelog.js"
|
|
@@ -91,11 +107,11 @@
|
|
|
91
107
|
"npm": ">=8.0.0"
|
|
92
108
|
},
|
|
93
109
|
"files": [
|
|
94
|
-
"
|
|
95
|
-
"
|
|
96
|
-
"
|
|
97
|
-
"
|
|
98
|
-
"
|
|
110
|
+
"embedded.js",
|
|
111
|
+
"embedded.d.ts",
|
|
112
|
+
"crates/pluresdb-node/index.d.ts",
|
|
113
|
+
"crates/pluresdb-node/index.js",
|
|
114
|
+
"crates/pluresdb-node/*.node",
|
|
99
115
|
"README.md",
|
|
100
116
|
"LICENSE",
|
|
101
117
|
"package.json"
|
|
@@ -103,12 +119,13 @@
|
|
|
103
119
|
"dependencies": {
|
|
104
120
|
"cors": "^2.8.5",
|
|
105
121
|
"express": "^5.1.0",
|
|
122
|
+
"hyperswarm": "^4.8.4",
|
|
106
123
|
"ws": "^8.18.3"
|
|
107
124
|
},
|
|
108
125
|
"devDependencies": {
|
|
109
126
|
"@types/cors": "^2.8.19",
|
|
110
127
|
"@types/express": "^5.0.0",
|
|
111
|
-
"@types/node": "^22.
|
|
128
|
+
"@types/node": "^22.19.11",
|
|
112
129
|
"@types/vscode": "^1.104.0",
|
|
113
130
|
"@types/ws": "^8.18.1",
|
|
114
131
|
"@typescript-eslint/eslint-plugin": "^8.46.4",
|