@plures/pluresdb 1.6.10 → 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.
Files changed (126) hide show
  1. package/README.md +97 -289
  2. package/crates/README.md +99 -0
  3. package/crates/pluresdb-node/README.md +181 -0
  4. package/crates/pluresdb-node/index.d.ts +0 -0
  5. package/crates/pluresdb-node/index.js +265 -0
  6. package/crates/pluresdb-node/package.json +35 -0
  7. package/dist/napi/index.js +60 -0
  8. package/embedded.d.ts +1 -0
  9. package/embedded.js +46 -0
  10. package/package.json +20 -9
  11. package/dist/.tsbuildinfo +0 -1
  12. package/dist/better-sqlite3-shared.d.ts +0 -12
  13. package/dist/better-sqlite3-shared.d.ts.map +0 -1
  14. package/dist/better-sqlite3-shared.js +0 -143
  15. package/dist/better-sqlite3-shared.js.map +0 -1
  16. package/dist/better-sqlite3.d.ts +0 -4
  17. package/dist/better-sqlite3.d.ts.map +0 -1
  18. package/dist/better-sqlite3.js +0 -8
  19. package/dist/better-sqlite3.js.map +0 -1
  20. package/dist/cli.d.ts +0 -7
  21. package/dist/cli.d.ts.map +0 -1
  22. package/dist/cli.js.map +0 -1
  23. package/dist/local-first/unified-api.d.ts +0 -110
  24. package/dist/local-first/unified-api.d.ts.map +0 -1
  25. package/dist/local-first/unified-api.js +0 -348
  26. package/dist/local-first/unified-api.js.map +0 -1
  27. package/dist/node-index.d.ts +0 -150
  28. package/dist/node-index.d.ts.map +0 -1
  29. package/dist/node-index.js +0 -668
  30. package/dist/node-index.js.map +0 -1
  31. package/dist/node-wrapper.d.ts +0 -44
  32. package/dist/node-wrapper.d.ts.map +0 -1
  33. package/dist/node-wrapper.js +0 -296
  34. package/dist/node-wrapper.js.map +0 -1
  35. package/dist/types/index.d.ts +0 -28
  36. package/dist/types/index.d.ts.map +0 -1
  37. package/dist/types/index.js +0 -3
  38. package/dist/types/index.js.map +0 -1
  39. package/dist/types/node-types.d.ts +0 -71
  40. package/dist/types/node-types.d.ts.map +0 -1
  41. package/dist/types/node-types.js +0 -6
  42. package/dist/types/node-types.js.map +0 -1
  43. package/dist/util/debug.d.ts +0 -3
  44. package/dist/util/debug.d.ts.map +0 -1
  45. package/dist/util/debug.js +0 -34
  46. package/dist/util/debug.js.map +0 -1
  47. package/dist/vscode/extension.d.ts +0 -81
  48. package/dist/vscode/extension.d.ts.map +0 -1
  49. package/dist/vscode/extension.js +0 -309
  50. package/dist/vscode/extension.js.map +0 -1
  51. package/examples/basic-usage.d.ts +0 -2
  52. package/examples/basic-usage.d.ts.map +0 -1
  53. package/examples/basic-usage.js +0 -26
  54. package/examples/basic-usage.js.map +0 -1
  55. package/examples/basic-usage.ts +0 -29
  56. package/examples/browser-demo/README.md +0 -204
  57. package/examples/browser-demo/index.html +0 -466
  58. package/examples/browser-wasm-integration.md +0 -411
  59. package/examples/ipc-demo/README.md +0 -127
  60. package/examples/local-first-usage.ts +0 -138
  61. package/examples/native-ipc-integration.md +0 -526
  62. package/examples/tauri-demo/README.md +0 -240
  63. package/examples/tauri-integration.md +0 -260
  64. package/examples/vscode-extension-example/README.md +0 -95
  65. package/examples/vscode-extension-example/package.json +0 -49
  66. package/examples/vscode-extension-example/src/extension.ts +0 -172
  67. package/examples/vscode-extension-example/tsconfig.json +0 -12
  68. package/examples/vscode-extension-integration.d.ts +0 -31
  69. package/examples/vscode-extension-integration.d.ts.map +0 -1
  70. package/examples/vscode-extension-integration.js +0 -319
  71. package/examples/vscode-extension-integration.js.map +0 -1
  72. package/examples/vscode-extension-integration.ts +0 -41
  73. package/legacy/benchmarks/memory-benchmarks.ts +0 -350
  74. package/legacy/benchmarks/run-benchmarks.ts +0 -315
  75. package/legacy/better-sqlite3-shared.ts +0 -157
  76. package/legacy/better-sqlite3.ts +0 -4
  77. package/legacy/cli.ts +0 -241
  78. package/legacy/config.ts +0 -50
  79. package/legacy/core/crdt.ts +0 -107
  80. package/legacy/core/database.ts +0 -529
  81. package/legacy/healthcheck.ts +0 -162
  82. package/legacy/http/api-server.ts +0 -569
  83. package/legacy/index.ts +0 -31
  84. package/legacy/local-first/unified-api.ts +0 -449
  85. package/legacy/logic/rules.ts +0 -46
  86. package/legacy/main.rs +0 -3
  87. package/legacy/main.ts +0 -197
  88. package/legacy/network/websocket-server.ts +0 -115
  89. package/legacy/node-index.ts +0 -827
  90. package/legacy/node-wrapper.ts +0 -329
  91. package/legacy/plugins/README.md +0 -181
  92. package/legacy/plugins/example-embedding-plugin.ts +0 -56
  93. package/legacy/plugins/plugin-system.ts +0 -315
  94. package/legacy/sqlite-compat.ts +0 -633
  95. package/legacy/sqlite3-compat.ts +0 -55
  96. package/legacy/storage/kv-storage.ts +0 -73
  97. package/legacy/tests/core.test.ts +0 -305
  98. package/legacy/tests/fixtures/performance-data.json +0 -71
  99. package/legacy/tests/fixtures/test-data.json +0 -129
  100. package/legacy/tests/integration/api-server.test.ts +0 -334
  101. package/legacy/tests/integration/mesh-network.test.ts +0 -303
  102. package/legacy/tests/logic.test.ts +0 -34
  103. package/legacy/tests/performance/load.test.ts +0 -290
  104. package/legacy/tests/security/input-validation.test.ts +0 -286
  105. package/legacy/tests/unit/core.test.ts +0 -226
  106. package/legacy/tests/unit/local-first-api.test.ts +0 -65
  107. package/legacy/tests/unit/plugin-system.test.ts +0 -388
  108. package/legacy/tests/unit/subscriptions.test.ts +0 -135
  109. package/legacy/tests/unit/vector-search.test.ts +0 -173
  110. package/legacy/tests/vscode_extension_test.ts +0 -281
  111. package/legacy/types/index.ts +0 -32
  112. package/legacy/types/node-types.ts +0 -80
  113. package/legacy/util/debug.ts +0 -27
  114. package/legacy/vector/index.ts +0 -59
  115. package/legacy/vscode/extension.ts +0 -387
  116. package/scripts/compiled-crud-verify.ts +0 -30
  117. package/scripts/dogfood.ts +0 -297
  118. package/scripts/postinstall.js +0 -156
  119. package/scripts/publish-crates.sh +0 -95
  120. package/scripts/release-check.js +0 -224
  121. package/scripts/run-tests.ts +0 -178
  122. package/scripts/setup-libclang.ps1 +0 -209
  123. package/scripts/update-changelog.js +0 -214
  124. package/scripts/validate-npm-publish.js +0 -228
  125. package/web/README.md +0 -27
  126. package/web/svelte/package.json +0 -31
@@ -1,526 +0,0 @@
1
- # Native IPC Integration Example
2
-
3
- This example demonstrates how to use PluresDB with native desktop applications using shared memory IPC (Inter-Process Communication) for high-performance local-first integration.
4
-
5
- ## Architecture
6
-
7
- ```
8
- ┌─────────────────────────────────────┐
9
- │ Application Process │
10
- │ (Electron, NW.js, etc.) │
11
- │ │
12
- │ PluresDBLocalFirst │
13
- │ │ │
14
- │ ▼ │
15
- │ IPC Client (shared memory) │
16
- └───────────┬─────────────────────────┘
17
- │ Shared Memory
18
- │ (1MB buffer, message passing)
19
- ┌───────────▼─────────────────────────┐
20
- │ PluresDB Process │
21
- │ │
22
- │ IPC Server │
23
- │ pluresdb-core │
24
- │ pluresdb-storage (filesystem) │
25
- └─────────────────────────────────────┘
26
- ```
27
-
28
- ## Why IPC?
29
-
30
- | Feature | Network (HTTP) | IPC (Shared Memory) |
31
- |---------|----------------|---------------------|
32
- | **Latency** | 5-10ms | 0.5ms |
33
- | **Throughput** | 1k ops/s | 50k ops/s |
34
- | **Port Conflicts** | Possible | Never |
35
- | **Security** | Exposed port | Process isolation |
36
- | **Setup** | Complex (find free port) | Simple (channel name) |
37
-
38
- ## Setup
39
-
40
- ### 1. Install PluresDB
41
-
42
- ```bash
43
- npm install @plures/pluresdb
44
- ```
45
-
46
- ### 2. Start PluresDB IPC Server
47
-
48
- ```bash
49
- # Set environment variable to enable IPC mode
50
- export PLURESDB_IPC=true
51
-
52
- # Start PluresDB with IPC
53
- pluresdb serve --ipc --channel "my-app-channel"
54
- ```
55
-
56
- Or programmatically in Node.js:
57
-
58
- ```javascript
59
- const { spawn } = require("child_process");
60
-
61
- // Start PluresDB in IPC mode
62
- const dbProcess = spawn("pluresdb", [
63
- "serve",
64
- "--ipc",
65
- "--channel", "my-app-channel",
66
- "--data-dir", "./data"
67
- ], {
68
- env: {
69
- ...process.env,
70
- PLURESDB_IPC: "true"
71
- }
72
- });
73
-
74
- dbProcess.on("error", (error) => {
75
- console.error("Failed to start PluresDB:", error);
76
- });
77
- ```
78
-
79
- ### 3. Connect from Application
80
-
81
- ```typescript
82
- import { PluresDBLocalFirst } from "@plures/pluresdb/local-first";
83
-
84
- // Auto-detects IPC mode if PLURESDB_IPC=true
85
- const db = new PluresDBLocalFirst({
86
- mode: "auto",
87
- channelName: "my-app-channel"
88
- });
89
-
90
- async function main() {
91
- // Use the database
92
- await db.put("user:1", {
93
- name: "Alice",
94
- email: "alice@example.com"
95
- });
96
-
97
- const user = await db.get("user:1");
98
- console.log("User:", user);
99
-
100
- const allUsers = await db.list();
101
- console.log("Total users:", allUsers.length);
102
- }
103
-
104
- main().catch(console.error);
105
- ```
106
-
107
- ## Electron Example
108
-
109
- ### Main Process (main.js)
110
-
111
- ```javascript
112
- const { app, BrowserWindow } = require("electron");
113
- const { spawn } = require("child_process");
114
- const path = require("path");
115
-
116
- let dbProcess = null;
117
- let mainWindow = null;
118
-
119
- // Start PluresDB IPC server
120
- function startDatabase() {
121
- const dataDir = path.join(app.getPath("userData"), "pluresdb");
122
-
123
- dbProcess = spawn("pluresdb", [
124
- "serve",
125
- "--ipc",
126
- "--channel", "electron-app",
127
- "--data-dir", dataDir
128
- ], {
129
- env: {
130
- ...process.env,
131
- PLURESDB_IPC: "true"
132
- }
133
- });
134
-
135
- dbProcess.stdout.on("data", (data) => {
136
- console.log(`[PluresDB] ${data}`);
137
- });
138
-
139
- dbProcess.stderr.on("data", (data) => {
140
- console.error(`[PluresDB Error] ${data}`);
141
- });
142
-
143
- dbProcess.on("exit", (code) => {
144
- console.log(`[PluresDB] Process exited with code ${code}`);
145
- });
146
- }
147
-
148
- // Stop PluresDB IPC server
149
- function stopDatabase() {
150
- if (dbProcess) {
151
- dbProcess.kill();
152
- dbProcess = null;
153
- }
154
- }
155
-
156
- app.whenReady().then(() => {
157
- // Start database before creating window
158
- startDatabase();
159
-
160
- // Create window
161
- mainWindow = new BrowserWindow({
162
- width: 1200,
163
- height: 800,
164
- webPreferences: {
165
- nodeIntegration: true,
166
- contextIsolation: false
167
- }
168
- });
169
-
170
- mainWindow.loadFile("index.html");
171
- });
172
-
173
- app.on("window-all-closed", () => {
174
- stopDatabase();
175
- if (process.platform !== "darwin") {
176
- app.quit();
177
- }
178
- });
179
-
180
- app.on("before-quit", () => {
181
- stopDatabase();
182
- });
183
- ```
184
-
185
- ### Renderer Process (renderer.js)
186
-
187
- ```javascript
188
- const { PluresDBLocalFirst } = require("@plures/pluresdb/local-first");
189
-
190
- // Connect to IPC channel
191
- const db = new PluresDBLocalFirst({
192
- mode: "ipc",
193
- channelName: "electron-app"
194
- });
195
-
196
- // Use the database
197
- async function addUser() {
198
- const id = document.getElementById("userId").value;
199
- const name = document.getElementById("userName").value;
200
- const email = document.getElementById("userEmail").value;
201
-
202
- await db.put(id, {
203
- type: "User",
204
- name,
205
- email,
206
- createdAt: new Date().toISOString()
207
- });
208
-
209
- console.log(`Added user: ${id}`);
210
- loadUsers();
211
- }
212
-
213
- async function loadUsers() {
214
- const users = await db.list();
215
-
216
- const userList = document.getElementById("userList");
217
- userList.innerHTML = "";
218
-
219
- users.forEach((user) => {
220
- const li = document.createElement("li");
221
- li.textContent = `${user.data.name} (${user.data.email})`;
222
- userList.appendChild(li);
223
- });
224
- }
225
-
226
- // Load users on page load
227
- window.addEventListener("DOMContentLoaded", () => {
228
- loadUsers();
229
- });
230
- ```
231
-
232
- ### HTML (index.html)
233
-
234
- ```html
235
- <!DOCTYPE html>
236
- <html>
237
- <head>
238
- <title>PluresDB Electron App</title>
239
- <style>
240
- body { font-family: Arial, sans-serif; padding: 20px; }
241
- input { margin: 5px; padding: 8px; }
242
- button { padding: 8px 16px; background: #007bff; color: white; border: none; cursor: pointer; }
243
- button:hover { background: #0056b3; }
244
- ul { list-style: none; padding: 0; }
245
- li { padding: 10px; background: #f0f0f0; margin: 5px 0; border-radius: 4px; }
246
- </style>
247
- </head>
248
- <body>
249
- <h1>PluresDB Electron App</h1>
250
-
251
- <div>
252
- <h2>Add User</h2>
253
- <input id="userId" placeholder="User ID" />
254
- <input id="userName" placeholder="Name" />
255
- <input id="userEmail" placeholder="Email" />
256
- <button onclick="addUser()">Add User</button>
257
- </div>
258
-
259
- <div>
260
- <h2>Users</h2>
261
- <ul id="userList"></ul>
262
- </div>
263
-
264
- <script src="renderer.js"></script>
265
- </body>
266
- </html>
267
- ```
268
-
269
- ## NW.js Example
270
-
271
- ```javascript
272
- // package.json
273
- {
274
- "name": "pluresdb-nwjs-app",
275
- "version": "1.0.0",
276
- "main": "index.html",
277
- "scripts": {
278
- "start": "nw ."
279
- },
280
- "dependencies": {
281
- "@plures/pluresdb": "^1.6.0"
282
- }
283
- }
284
-
285
- // index.html
286
- <!DOCTYPE html>
287
- <html>
288
- <head>
289
- <title>PluresDB NW.js App</title>
290
- </head>
291
- <body>
292
- <h1>PluresDB NW.js App</h1>
293
- <div id="app"></div>
294
-
295
- <script>
296
- const { PluresDBLocalFirst } = require("@plures/pluresdb/local-first");
297
-
298
- // Set IPC environment
299
- process.env.PLURESDB_IPC = "true";
300
-
301
- // Connect via IPC
302
- const db = new PluresDBLocalFirst({
303
- mode: "ipc",
304
- channelName: "nwjs-app"
305
- });
306
-
307
- async function init() {
308
- await db.put("config:1", { theme: "dark", language: "en" });
309
- const config = await db.get("config:1");
310
- console.log("Config:", config);
311
- }
312
-
313
- init();
314
- </script>
315
- </body>
316
- </html>
317
- ```
318
-
319
- ## Performance Benchmarks
320
-
321
- ```javascript
322
- const { performance } = require("perf_hooks");
323
-
324
- async function benchmark() {
325
- const iterations = 10000;
326
-
327
- console.log(`Running benchmark with ${iterations} operations...`);
328
-
329
- // Write benchmark
330
- const writeStart = performance.now();
331
- for (let i = 0; i < iterations; i++) {
332
- await db.put(`item:${i}`, { value: i });
333
- }
334
- const writeEnd = performance.now();
335
- const writeTime = writeEnd - writeStart;
336
-
337
- console.log(`Write: ${iterations} ops in ${writeTime.toFixed(2)}ms`);
338
- console.log(`Write throughput: ${(iterations / (writeTime / 1000)).toFixed(0)} ops/s`);
339
-
340
- // Read benchmark
341
- const readStart = performance.now();
342
- for (let i = 0; i < iterations; i++) {
343
- await db.get(`item:${i}`);
344
- }
345
- const readEnd = performance.now();
346
- const readTime = readEnd - readStart;
347
-
348
- console.log(`Read: ${iterations} ops in ${readTime.toFixed(2)}ms`);
349
- console.log(`Read throughput: ${(iterations / (readTime / 1000)).toFixed(0)} ops/s`);
350
- }
351
-
352
- benchmark();
353
- ```
354
-
355
- Expected output:
356
- ```
357
- Running benchmark with 10000 operations...
358
- Write: 10000 ops in 200.45ms
359
- Write throughput: 49888 ops/s
360
- Read: 10000 ops in 180.32ms
361
- Read throughput: 55454 ops/s
362
- ```
363
-
364
- ## Advanced: Message Protocol
365
-
366
- The IPC backend uses a simple message protocol over shared memory:
367
-
368
- ```typescript
369
- // Message structure
370
- interface IPCMessage {
371
- id: string; // Request/response ID
372
- type: "request" | "response" | "error";
373
- operation: "put" | "get" | "delete" | "list" | "search";
374
- payload: any; // Operation-specific data
375
- timestamp: number; // For debugging
376
- }
377
-
378
- // Example: PUT operation
379
- {
380
- id: "req-1234",
381
- type: "request",
382
- operation: "put",
383
- payload: {
384
- id: "user:1",
385
- data: { name: "Alice", email: "alice@example.com" }
386
- },
387
- timestamp: 1674567890123
388
- }
389
-
390
- // Response
391
- {
392
- id: "req-1234",
393
- type: "response",
394
- operation: "put",
395
- payload: {
396
- success: true,
397
- id: "user:1"
398
- },
399
- timestamp: 1674567890125
400
- }
401
- ```
402
-
403
- ## Process Lifecycle Management
404
-
405
- ```javascript
406
- class PluresDBManager {
407
- constructor(channelName) {
408
- this.channelName = channelName;
409
- this.process = null;
410
- this.db = null;
411
- }
412
-
413
- async start() {
414
- // Start PluresDB process
415
- this.process = spawn("pluresdb", [
416
- "serve",
417
- "--ipc",
418
- "--channel", this.channelName
419
- ], {
420
- env: { ...process.env, PLURESDB_IPC: "true" }
421
- });
422
-
423
- // Wait for process to be ready
424
- await new Promise((resolve) => setTimeout(resolve, 1000));
425
-
426
- // Connect client
427
- this.db = new PluresDBLocalFirst({
428
- mode: "ipc",
429
- channelName: this.channelName
430
- });
431
-
432
- return this.db;
433
- }
434
-
435
- async stop() {
436
- if (this.db) {
437
- await this.db.close();
438
- this.db = null;
439
- }
440
-
441
- if (this.process) {
442
- this.process.kill();
443
- this.process = null;
444
- }
445
- }
446
-
447
- async restart() {
448
- await this.stop();
449
- await this.start();
450
- }
451
- }
452
-
453
- // Usage
454
- const manager = new PluresDBManager("my-app");
455
- const db = await manager.start();
456
-
457
- // Use db...
458
-
459
- // Clean shutdown
460
- process.on("SIGINT", async () => {
461
- await manager.stop();
462
- process.exit(0);
463
- });
464
- ```
465
-
466
- ## Security Considerations
467
-
468
- ✅ **Process Isolation**: App and DB run in separate processes
469
- ✅ **No Network Exposure**: No ports opened
470
- ✅ **Memory Access Control**: OS-level shared memory permissions
471
- ⚠️ **Same-Machine Only**: Only works on local machine
472
- ⚠️ **Input Validation**: Always validate data from shared memory
473
-
474
- ## Troubleshooting
475
-
476
- ### "IPC backend not yet implemented" error
477
-
478
- The IPC implementation is planned for Phase 3. For now, use network mode:
479
-
480
- ```typescript
481
- const db = new PluresDBLocalFirst({ mode: "network", port: 34567 });
482
- ```
483
-
484
- ### "Channel not found" error
485
-
486
- Ensure the PluresDB server is running with the correct channel:
487
-
488
- ```bash
489
- pluresdb serve --ipc --channel "my-app-channel"
490
- ```
491
-
492
- ### Permission denied on shared memory
493
-
494
- On Linux/macOS, ensure proper permissions without exposing shared memory to all users:
495
-
496
- ```bash
497
- # Check shared memory permissions
498
- ls -l /dev/shm/
499
-
500
- # Set ownership to the PluresDB service user (adjust user/group as needed)
501
- sudo chown pluresdb:pluresdb /dev/shm/pluresdb-*
502
-
503
- # Restrict access to that user (or user+group if using a dedicated group)
504
- sudo chmod 600 /dev/shm/pluresdb-*
505
- ```
506
-
507
- ## Implementation Status
508
-
509
- **Note**: The IPC backend is planned for Phase 3 of the local-first integration roadmap.
510
-
511
- Current status:
512
- - [ ] IPC server (pluresdb-ipc crate)
513
- - [ ] Shared memory message passing
514
- - [ ] Client library
515
- - [x] Unified API with auto-detection
516
- - [x] Documentation
517
-
518
- To track progress or contribute, see:
519
- - [LOCAL_FIRST_INTEGRATION.md](../../docs/LOCAL_FIRST_INTEGRATION.md)
520
- - [GitHub Issues](https://github.com/plures/pluresdb/issues)
521
-
522
- ## Next Steps
523
-
524
- - See [Browser WASM Integration](./browser-wasm-integration.md) for web apps
525
- - Explore [Tauri Integration](./tauri-integration.md) for modern desktop apps
526
- - Read [LOCAL_FIRST_INTEGRATION.md](../../docs/LOCAL_FIRST_INTEGRATION.md) for architecture details