@plures/pluresdb 1.6.10 → 2.9.7

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 (93) 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/.tsbuildinfo +1 -1
  8. package/dist/napi/index.d.ts +38 -0
  9. package/dist/napi/index.d.ts.map +1 -0
  10. package/dist/napi/index.js +60 -0
  11. package/dist/napi/index.js.map +1 -0
  12. package/dist/node-index.d.ts +32 -0
  13. package/dist/node-index.d.ts.map +1 -1
  14. package/dist/node-index.js +52 -0
  15. package/dist/node-index.js.map +1 -1
  16. package/embedded.d.ts +1 -0
  17. package/embedded.js +46 -0
  18. package/package.json +21 -8
  19. package/examples/basic-usage.d.ts +0 -2
  20. package/examples/basic-usage.d.ts.map +0 -1
  21. package/examples/basic-usage.js +0 -26
  22. package/examples/basic-usage.js.map +0 -1
  23. package/examples/basic-usage.ts +0 -29
  24. package/examples/browser-demo/README.md +0 -204
  25. package/examples/browser-demo/index.html +0 -466
  26. package/examples/browser-wasm-integration.md +0 -411
  27. package/examples/ipc-demo/README.md +0 -127
  28. package/examples/local-first-usage.ts +0 -138
  29. package/examples/native-ipc-integration.md +0 -526
  30. package/examples/tauri-demo/README.md +0 -240
  31. package/examples/tauri-integration.md +0 -260
  32. package/examples/vscode-extension-example/README.md +0 -95
  33. package/examples/vscode-extension-example/package.json +0 -49
  34. package/examples/vscode-extension-example/src/extension.ts +0 -172
  35. package/examples/vscode-extension-example/tsconfig.json +0 -12
  36. package/examples/vscode-extension-integration.d.ts +0 -31
  37. package/examples/vscode-extension-integration.d.ts.map +0 -1
  38. package/examples/vscode-extension-integration.js +0 -319
  39. package/examples/vscode-extension-integration.js.map +0 -1
  40. package/examples/vscode-extension-integration.ts +0 -41
  41. package/legacy/benchmarks/memory-benchmarks.ts +0 -350
  42. package/legacy/benchmarks/run-benchmarks.ts +0 -315
  43. package/legacy/better-sqlite3-shared.ts +0 -157
  44. package/legacy/better-sqlite3.ts +0 -4
  45. package/legacy/cli.ts +0 -241
  46. package/legacy/config.ts +0 -50
  47. package/legacy/core/crdt.ts +0 -107
  48. package/legacy/core/database.ts +0 -529
  49. package/legacy/healthcheck.ts +0 -162
  50. package/legacy/http/api-server.ts +0 -569
  51. package/legacy/index.ts +0 -31
  52. package/legacy/local-first/unified-api.ts +0 -449
  53. package/legacy/logic/rules.ts +0 -46
  54. package/legacy/main.rs +0 -3
  55. package/legacy/main.ts +0 -197
  56. package/legacy/network/websocket-server.ts +0 -115
  57. package/legacy/node-index.ts +0 -827
  58. package/legacy/node-wrapper.ts +0 -329
  59. package/legacy/plugins/README.md +0 -181
  60. package/legacy/plugins/example-embedding-plugin.ts +0 -56
  61. package/legacy/plugins/plugin-system.ts +0 -315
  62. package/legacy/sqlite-compat.ts +0 -633
  63. package/legacy/sqlite3-compat.ts +0 -55
  64. package/legacy/storage/kv-storage.ts +0 -73
  65. package/legacy/tests/core.test.ts +0 -305
  66. package/legacy/tests/fixtures/performance-data.json +0 -71
  67. package/legacy/tests/fixtures/test-data.json +0 -129
  68. package/legacy/tests/integration/api-server.test.ts +0 -334
  69. package/legacy/tests/integration/mesh-network.test.ts +0 -303
  70. package/legacy/tests/logic.test.ts +0 -34
  71. package/legacy/tests/performance/load.test.ts +0 -290
  72. package/legacy/tests/security/input-validation.test.ts +0 -286
  73. package/legacy/tests/unit/core.test.ts +0 -226
  74. package/legacy/tests/unit/local-first-api.test.ts +0 -65
  75. package/legacy/tests/unit/plugin-system.test.ts +0 -388
  76. package/legacy/tests/unit/subscriptions.test.ts +0 -135
  77. package/legacy/tests/unit/vector-search.test.ts +0 -173
  78. package/legacy/tests/vscode_extension_test.ts +0 -281
  79. package/legacy/types/index.ts +0 -32
  80. package/legacy/types/node-types.ts +0 -80
  81. package/legacy/util/debug.ts +0 -27
  82. package/legacy/vector/index.ts +0 -59
  83. package/legacy/vscode/extension.ts +0 -387
  84. package/scripts/compiled-crud-verify.ts +0 -30
  85. package/scripts/dogfood.ts +0 -297
  86. package/scripts/publish-crates.sh +0 -95
  87. package/scripts/release-check.js +0 -224
  88. package/scripts/run-tests.ts +0 -178
  89. package/scripts/setup-libclang.ps1 +0 -209
  90. package/scripts/update-changelog.js +0 -214
  91. package/scripts/validate-npm-publish.js +0 -228
  92. package/web/README.md +0 -27
  93. package/web/svelte/package.json +0 -31
@@ -1,329 +0,0 @@
1
- /**
2
- * Node.js Wrapper for PluresDB
3
- * This module provides a Node.js-compatible API for VSCode extensions
4
- */
5
-
6
- import { ChildProcess, spawn } from "node:child_process";
7
- import { EventEmitter } from "node:events";
8
- import * as path from "node:path";
9
- import * as fs from "node:fs";
10
- import * as os from "node:os";
11
-
12
- export interface PluresDBConfig {
13
- port?: number;
14
- host?: string;
15
- dataDir?: string;
16
- webPort?: number;
17
- logLevel?: "debug" | "info" | "warn" | "error";
18
- }
19
-
20
- export interface PluresDBOptions {
21
- config?: PluresDBConfig;
22
- autoStart?: boolean;
23
- denoPath?: string;
24
- }
25
-
26
- export class PluresNode extends EventEmitter {
27
- private process: ChildProcess | null = null;
28
- private config: PluresDBConfig;
29
- private denoPath: string;
30
- private isRunning = false;
31
- private apiUrl: string = "";
32
-
33
- constructor(options: PluresDBOptions = {}) {
34
- super();
35
-
36
- this.config = {
37
- port: 34567,
38
- host: "localhost",
39
- dataDir: path.join(os.homedir(), ".pluresdb"),
40
- webPort: 34568,
41
- logLevel: "info",
42
- ...options.config,
43
- };
44
-
45
- this.denoPath = options.denoPath || this.findDenoPath();
46
-
47
- if (options.autoStart !== false) {
48
- this.start();
49
- }
50
- }
51
-
52
- private findDenoPath(): string {
53
- // Try to find Deno in common locations
54
- const possiblePaths = [
55
- "deno", // In PATH
56
- path.join(os.homedir(), ".deno", "bin", "deno"),
57
- path.join(os.homedir(), ".local", "bin", "deno"),
58
- "/usr/local/bin/deno",
59
- "/opt/homebrew/bin/deno",
60
- "C:\\Users\\" + os.userInfo().username + "\\.deno\\bin\\deno.exe",
61
- "C:\\Program Files\\deno\\deno.exe",
62
- ];
63
-
64
- for (const denoPath of possiblePaths) {
65
- try {
66
- if (fs.existsSync(denoPath) || this.isCommandAvailable(denoPath)) {
67
- return denoPath;
68
- }
69
- } catch {
70
- // Continue to next path
71
- }
72
- }
73
-
74
- throw new Error(
75
- "Deno not found. Please install Deno from https://deno.land/",
76
- );
77
- }
78
-
79
- private isCommandAvailable(command: string): boolean {
80
- try {
81
- require("child_process").execSync(`"${command}" --version`, {
82
- stdio: "ignore",
83
- });
84
- return true;
85
- } catch {
86
- return false;
87
- }
88
- }
89
-
90
- async start(): Promise<void> {
91
- if (this.isRunning) {
92
- return;
93
- }
94
-
95
- return new Promise((resolve, reject) => {
96
- try {
97
- // Ensure data directory exists
98
- if (!fs.existsSync(this.config.dataDir!)) {
99
- fs.mkdirSync(this.config.dataDir!, { recursive: true });
100
- }
101
-
102
- // Find the main.ts file
103
- const mainTsPath = path.join(__dirname, "main.ts");
104
- if (!fs.existsSync(mainTsPath)) {
105
- throw new Error(
106
- "PluresDB main.ts not found. Please ensure the package is properly installed.",
107
- );
108
- }
109
-
110
- // Start the Deno process
111
- const args = [
112
- "run",
113
- "-A",
114
- mainTsPath,
115
- "serve",
116
- "--port",
117
- this.config.port!.toString(),
118
- "--host",
119
- this.config.host!,
120
- "--data-dir",
121
- this.config.dataDir!,
122
- ];
123
-
124
- this.process = spawn(this.denoPath, args, {
125
- stdio: ["pipe", "pipe", "pipe"],
126
- cwd: path.dirname(__dirname),
127
- });
128
-
129
- this.apiUrl = `http://${this.config.host}:${this.config.port}`;
130
-
131
- // Handle process events
132
- this.process.on("error", (error) => {
133
- this.emit("error", error);
134
- reject(error);
135
- });
136
-
137
- this.process.on("exit", (code) => {
138
- this.isRunning = false;
139
- this.emit("exit", code);
140
- });
141
-
142
- // Wait for server to start
143
- this.waitForServer()
144
- .then(() => {
145
- this.isRunning = true;
146
- this.emit("started");
147
- resolve();
148
- })
149
- .catch(reject);
150
-
151
- // Handle stdout/stderr
152
- this.process.stdout?.on("data", (data) => {
153
- const output = data.toString();
154
- this.emit("stdout", output);
155
- });
156
-
157
- this.process.stderr?.on("data", (data) => {
158
- const output = data.toString();
159
- this.emit("stderr", output);
160
- });
161
- } catch (error) {
162
- reject(error);
163
- }
164
- });
165
- }
166
-
167
- private async waitForServer(timeout = 10000): Promise<void> {
168
- const startTime = Date.now();
169
-
170
- while (Date.now() - startTime < timeout) {
171
- try {
172
- const response = await fetch(`${this.apiUrl}/api/config`);
173
- if (response.ok) {
174
- return;
175
- }
176
- } catch {
177
- // Server not ready yet
178
- }
179
-
180
- await new Promise((resolve) => setTimeout(resolve, 100));
181
- }
182
-
183
- throw new Error("Server failed to start within timeout");
184
- }
185
-
186
- async stop(): Promise<void> {
187
- if (!this.isRunning || !this.process) {
188
- return;
189
- }
190
-
191
- return new Promise((resolve) => {
192
- this.process!.kill("SIGTERM");
193
-
194
- this.process!.on("exit", () => {
195
- this.isRunning = false;
196
- this.emit("stopped");
197
- resolve();
198
- });
199
-
200
- // Force kill after 5 seconds
201
- setTimeout(() => {
202
- if (this.process && this.isRunning) {
203
- this.process.kill("SIGKILL");
204
- }
205
- resolve();
206
- }, 5000);
207
- });
208
- }
209
-
210
- getApiUrl(): string {
211
- return this.apiUrl;
212
- }
213
-
214
- getWebUrl(): string {
215
- return `http://${this.config.host}:${this.config.webPort}`;
216
- }
217
-
218
- isServerRunning(): boolean {
219
- return this.isRunning;
220
- }
221
-
222
- // SQLite-compatible API methods
223
- async query(sql: string, params: any[] = []): Promise<any> {
224
- const response = await fetch(`${this.apiUrl}/api/query`, {
225
- method: "POST",
226
- headers: { "Content-Type": "application/json" },
227
- body: JSON.stringify({ sql, params }),
228
- });
229
-
230
- if (!response.ok) {
231
- throw new Error(`Query failed: ${response.statusText}`);
232
- }
233
-
234
- return response.json();
235
- }
236
-
237
- async put(key: string, value: any): Promise<void> {
238
- const response = await fetch(`${this.apiUrl}/api/data`, {
239
- method: "PUT",
240
- headers: { "Content-Type": "application/json" },
241
- body: JSON.stringify({ key, value }),
242
- });
243
-
244
- if (!response.ok) {
245
- throw new Error(`Put failed: ${response.statusText}`);
246
- }
247
- }
248
-
249
- async get(key: string): Promise<any> {
250
- const response = await fetch(
251
- `${this.apiUrl}/api/data/${encodeURIComponent(key)}`,
252
- );
253
-
254
- if (!response.ok) {
255
- if (response.status === 404) {
256
- return null;
257
- }
258
- throw new Error(`Get failed: ${response.statusText}`);
259
- }
260
-
261
- return response.json();
262
- }
263
-
264
- async delete(key: string): Promise<void> {
265
- const response = await fetch(
266
- `${this.apiUrl}/api/data/${encodeURIComponent(key)}`,
267
- {
268
- method: "DELETE",
269
- },
270
- );
271
-
272
- if (!response.ok) {
273
- throw new Error(`Delete failed: ${response.statusText}`);
274
- }
275
- }
276
-
277
- async vectorSearch(query: string, limit = 10): Promise<any[]> {
278
- const response = await fetch(`${this.apiUrl}/api/vsearch`, {
279
- method: "POST",
280
- headers: { "Content-Type": "application/json" },
281
- body: JSON.stringify({ query, limit }),
282
- });
283
-
284
- if (!response.ok) {
285
- throw new Error(`Vector search failed: ${response.statusText}`);
286
- }
287
-
288
- return response.json() as Promise<any[]>;
289
- }
290
-
291
- async list(prefix?: string): Promise<string[]> {
292
- const url = prefix
293
- ? `${this.apiUrl}/api/list?prefix=${encodeURIComponent(prefix)}`
294
- : `${this.apiUrl}/api/list`;
295
- const response = await fetch(url);
296
-
297
- if (!response.ok) {
298
- throw new Error(`List failed: ${response.statusText}`);
299
- }
300
-
301
- return response.json() as Promise<string[]>;
302
- }
303
-
304
- async getConfig(): Promise<any> {
305
- const response = await fetch(`${this.apiUrl}/api/config`);
306
-
307
- if (!response.ok) {
308
- throw new Error(`Get config failed: ${response.statusText}`);
309
- }
310
-
311
- return response.json();
312
- }
313
-
314
- async setConfig(config: any): Promise<void> {
315
- const response = await fetch(`${this.apiUrl}/api/config`, {
316
- method: "POST",
317
- headers: { "Content-Type": "application/json" },
318
- body: JSON.stringify(config),
319
- });
320
-
321
- if (!response.ok) {
322
- throw new Error(`Set config failed: ${response.statusText}`);
323
- }
324
- }
325
- }
326
-
327
- // Export the main class and types
328
- export { PluresNode as default };
329
- export * from "./types/index";
@@ -1,181 +0,0 @@
1
- # PluresDB Plugin System
2
-
3
- The PluresDB plugin system allows you to extend the database with custom functionality.
4
-
5
- ## Plugin Types
6
-
7
- ### 1. Embedding Providers
8
-
9
- Add custom embedding providers for vector search:
10
-
11
- ```typescript
12
- // For Deno projects
13
- import { Plugin, EmbeddingProvider } from "../legacy/plugins/plugin-system.ts";
14
-
15
- // For Node.js projects (after compilation)
16
- // import { Plugin, EmbeddingProvider } from "./legacy/plugins/plugin-system";
17
-
18
- class MyEmbeddingProvider implements EmbeddingProvider {
19
- name = "my-embeddings";
20
- dimensions = 384;
21
-
22
- async embed(text: string): Promise<number[]> {
23
- // Your embedding logic here
24
- return new Array(this.dimensions).fill(0);
25
- }
26
- }
27
-
28
- const plugin: Plugin = {
29
- id: "my-plugin",
30
- name: "My Plugin",
31
- version: "1.0.0",
32
- embeddingProviders: [new MyEmbeddingProvider()],
33
- };
34
- ```
35
-
36
- ### 2. UI Panels
37
-
38
- Add custom UI panels to the web interface:
39
-
40
- ```typescript
41
- import MyPanel from "./MyPanel.svelte";
42
-
43
- const plugin: Plugin = {
44
- id: "my-ui-plugin",
45
- name: "My UI Plugin",
46
- version: "1.0.0",
47
- uiPanels: [{
48
- id: "my-panel",
49
- name: "My Panel",
50
- icon: "🎨",
51
- component: MyPanel,
52
- order: 100,
53
- }],
54
- };
55
- ```
56
-
57
- ### 3. Query Transformers
58
-
59
- Transform queries before execution:
60
-
61
- ```typescript
62
- const plugin: Plugin = {
63
- id: "query-plugin",
64
- name: "Query Plugin",
65
- version: "1.0.0",
66
- queryTransformers: [{
67
- id: "my-transformer",
68
- async transform(query: any) {
69
- // Modify query here
70
- return { ...query, enhanced: true };
71
- },
72
- }],
73
- };
74
- ```
75
-
76
- ### 4. Data Validators
77
-
78
- Validate data before storage:
79
-
80
- ```typescript
81
- const plugin: Plugin = {
82
- id: "validator-plugin",
83
- name: "Validator Plugin",
84
- version: "1.0.0",
85
- dataValidators: [{
86
- id: "email-validator",
87
- async validate(data: Record<string, unknown>) {
88
- if (data.email && typeof data.email === "string") {
89
- const isValid = /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(data.email);
90
- if (!isValid) {
91
- return {
92
- valid: false,
93
- errors: ["Invalid email format"],
94
- };
95
- }
96
- }
97
- return { valid: true };
98
- },
99
- }],
100
- };
101
- ```
102
-
103
- ## Registering Plugins
104
-
105
- ```typescript
106
- // For Deno projects
107
- import { pluginManager } from "../legacy/plugins/plugin-system.ts";
108
- import { myPlugin } from "./my-plugin.ts";
109
-
110
- // For Node.js projects (after compilation)
111
- // import { pluginManager } from "./legacy/plugins/plugin-system";
112
- // import { myPlugin } from "./my-plugin";
113
-
114
- // Register plugin
115
- await pluginManager.register(myPlugin);
116
-
117
- // Use custom embedding provider
118
- const provider = pluginManager.getEmbeddingProvider("my-embeddings");
119
- if (provider) {
120
- const embedding = await provider.embed("Hello, world!");
121
- }
122
-
123
- // Unregister plugin
124
- await pluginManager.unregister("my-plugin");
125
- ```
126
-
127
- ## Complete Example
128
-
129
- See `example-embedding-plugin.ts` for a complete example plugin.
130
-
131
- ## API Reference
132
-
133
- ### Plugin Interface
134
-
135
- ```typescript
136
- interface Plugin {
137
- id: string;
138
- name: string;
139
- version: string;
140
- description?: string;
141
- embeddingProviders?: EmbeddingProvider[];
142
- uiPanels?: UIPanel[];
143
- queryTransformers?: QueryTransformer[];
144
- dataValidators?: DataValidator[];
145
- init?(): Promise<void>;
146
- destroy?(): Promise<void>;
147
- }
148
- ```
149
-
150
- ### PluginManager Methods
151
-
152
- - `register(plugin: Plugin): Promise<void>` - Register a plugin
153
- - `unregister(pluginId: string): Promise<void>` - Unregister a plugin
154
- - `getPlugins(): Plugin[]` - Get all registered plugins
155
- - `getEmbeddingProvider(name: string): EmbeddingProvider | undefined`
156
- - `getEmbeddingProviders(): EmbeddingProvider[]`
157
- - `getUIPanel(id: string): UIPanel | undefined`
158
- - `getUIPanels(): UIPanel[]`
159
- - `getQueryTransformer(id: string): QueryTransformer | undefined`
160
- - `getQueryTransformers(): QueryTransformer[]`
161
- - `getDataValidator(id: string): DataValidator | undefined`
162
- - `getDataValidators(): DataValidator[]`
163
- - `transformQuery(query: any): Promise<any>` - Apply all transformers
164
- - `validateData(data: Record<string, unknown>): Promise<{valid: boolean; errors: string[]}>` - Validate with all validators
165
-
166
- ## Best Practices
167
-
168
- 1. **Unique IDs**: Use unique, descriptive IDs for plugins and their components
169
- 2. **Error Handling**: Handle errors gracefully in your plugin code
170
- 3. **Cleanup**: Implement `destroy()` to clean up resources
171
- 4. **Documentation**: Document your plugin's functionality and configuration
172
- 5. **Testing**: Test your plugin thoroughly before deployment
173
- 6. **Versioning**: Use semantic versioning for your plugins
174
-
175
- ## Security Considerations
176
-
177
- - Validate all input data in your plugins
178
- - Avoid storing sensitive data (API keys, etc.) in plugin code
179
- - Use environment variables for configuration
180
- - Review third-party dependencies carefully
181
- - Test plugins in a safe environment before production use
@@ -1,56 +0,0 @@
1
- import type { Plugin, EmbeddingProvider } from "./plugin-system";
2
-
3
- /**
4
- * Example Custom Embedding Provider Plugin
5
- *
6
- * This plugin demonstrates how to add a custom embedding provider to PluresDB.
7
- * It provides a simple character-based embedding for demonstration purposes.
8
- */
9
-
10
- class SimpleEmbeddingProvider implements EmbeddingProvider {
11
- name = "simple-char-embeddings";
12
- dimensions = 256;
13
-
14
- /**
15
- * Generate simple character-based embeddings
16
- * Maps characters to vector positions
17
- */
18
- async embed(text: string): Promise<number[]> {
19
- const vector = new Array(this.dimensions).fill(0);
20
-
21
- // Simple algorithm: increment vector position for each character
22
- for (let i = 0; i < text.length && i < this.dimensions; i++) {
23
- const charCode = text.charCodeAt(i);
24
- vector[charCode % this.dimensions] += 1;
25
- }
26
-
27
- // Normalize
28
- const magnitude = Math.sqrt(vector.reduce((sum, val) => sum + val * val, 0));
29
- if (magnitude > 0) {
30
- for (let i = 0; i < vector.length; i++) {
31
- vector[i] /= magnitude;
32
- }
33
- }
34
-
35
- return vector;
36
- }
37
- }
38
-
39
- export const customEmbeddingsPlugin: Plugin = {
40
- id: "custom-embeddings",
41
- name: "Custom Embeddings Provider",
42
- version: "1.0.0",
43
- description: "Provides a simple character-based embedding provider for PluresDB",
44
-
45
- embeddingProviders: [
46
- new SimpleEmbeddingProvider(),
47
- ],
48
-
49
- async init() {
50
- console.log("Custom embeddings plugin initialized");
51
- },
52
-
53
- async destroy() {
54
- console.log("Custom embeddings plugin destroyed");
55
- },
56
- };