pluresdb 1.0.1
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/LICENSE +72 -0
- package/README.md +322 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/cli.d.ts +7 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +253 -0
- package/dist/cli.js.map +1 -0
- package/dist/node-index.d.ts +52 -0
- package/dist/node-index.d.ts.map +1 -0
- package/dist/node-index.js +359 -0
- package/dist/node-index.js.map +1 -0
- package/dist/node-wrapper.d.ts +44 -0
- package/dist/node-wrapper.d.ts.map +1 -0
- package/dist/node-wrapper.js +294 -0
- package/dist/node-wrapper.js.map +1 -0
- package/dist/types/index.d.ts +28 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/node-types.d.ts +59 -0
- package/dist/types/node-types.d.ts.map +1 -0
- package/dist/types/node-types.js +6 -0
- package/dist/types/node-types.js.map +1 -0
- package/dist/vscode/extension.d.ts +81 -0
- package/dist/vscode/extension.d.ts.map +1 -0
- package/dist/vscode/extension.js +309 -0
- package/dist/vscode/extension.js.map +1 -0
- package/examples/basic-usage.d.ts +2 -0
- package/examples/basic-usage.d.ts.map +1 -0
- package/examples/basic-usage.js +26 -0
- package/examples/basic-usage.js.map +1 -0
- package/examples/basic-usage.ts +29 -0
- package/examples/vscode-extension-example/README.md +95 -0
- package/examples/vscode-extension-example/package.json +49 -0
- package/examples/vscode-extension-example/src/extension.ts +163 -0
- package/examples/vscode-extension-example/tsconfig.json +12 -0
- package/examples/vscode-extension-integration.d.ts +24 -0
- package/examples/vscode-extension-integration.d.ts.map +1 -0
- package/examples/vscode-extension-integration.js +285 -0
- package/examples/vscode-extension-integration.js.map +1 -0
- package/examples/vscode-extension-integration.ts +41 -0
- package/package.json +115 -0
- package/scripts/compiled-crud-verify.ts +28 -0
- package/scripts/dogfood.ts +258 -0
- package/scripts/postinstall.js +155 -0
- package/scripts/run-tests.ts +175 -0
- package/scripts/setup-libclang.ps1 +209 -0
- package/src/benchmarks/memory-benchmarks.ts +316 -0
- package/src/benchmarks/run-benchmarks.ts +293 -0
- package/src/cli.ts +231 -0
- package/src/config.ts +49 -0
- package/src/core/crdt.ts +104 -0
- package/src/core/database.ts +494 -0
- package/src/healthcheck.ts +156 -0
- package/src/http/api-server.ts +334 -0
- package/src/index.ts +28 -0
- package/src/logic/rules.ts +44 -0
- package/src/main.rs +3 -0
- package/src/main.ts +190 -0
- package/src/network/websocket-server.ts +115 -0
- package/src/node-index.ts +385 -0
- package/src/node-wrapper.ts +320 -0
- package/src/sqlite-compat.ts +586 -0
- package/src/sqlite3-compat.ts +55 -0
- package/src/storage/kv-storage.ts +71 -0
- package/src/tests/core.test.ts +281 -0
- package/src/tests/fixtures/performance-data.json +71 -0
- package/src/tests/fixtures/test-data.json +124 -0
- package/src/tests/integration/api-server.test.ts +232 -0
- package/src/tests/integration/mesh-network.test.ts +297 -0
- package/src/tests/logic.test.ts +30 -0
- package/src/tests/performance/load.test.ts +288 -0
- package/src/tests/security/input-validation.test.ts +282 -0
- package/src/tests/unit/core.test.ts +216 -0
- package/src/tests/unit/subscriptions.test.ts +135 -0
- package/src/tests/unit/vector-search.test.ts +173 -0
- package/src/tests/vscode_extension_test.ts +253 -0
- package/src/types/index.ts +32 -0
- package/src/types/node-types.ts +66 -0
- package/src/util/debug.ts +14 -0
- package/src/vector/index.ts +59 -0
- package/src/vscode/extension.ts +364 -0
- package/web/README.md +27 -0
- package/web/svelte/package.json +31 -0
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node.js Wrapper for PluresDB
|
|
3
|
+
* This module provides a Node.js-compatible API for VSCode extensions
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { spawn, ChildProcess } 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 (error) {
|
|
70
|
+
// Continue to next path
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
throw new Error("Deno not found. Please install Deno from https://deno.land/");
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
private isCommandAvailable(command: string): boolean {
|
|
78
|
+
try {
|
|
79
|
+
require("child_process").execSync(`"${command}" --version`, { stdio: "ignore" });
|
|
80
|
+
return true;
|
|
81
|
+
} catch {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async start(): Promise<void> {
|
|
87
|
+
if (this.isRunning) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return new Promise((resolve, reject) => {
|
|
92
|
+
try {
|
|
93
|
+
// Ensure data directory exists
|
|
94
|
+
if (!fs.existsSync(this.config.dataDir!)) {
|
|
95
|
+
fs.mkdirSync(this.config.dataDir!, { recursive: true });
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Find the main.ts file
|
|
99
|
+
const mainTsPath = path.join(__dirname, "main.ts");
|
|
100
|
+
if (!fs.existsSync(mainTsPath)) {
|
|
101
|
+
throw new Error(
|
|
102
|
+
"PluresDB main.ts not found. Please ensure the package is properly installed.",
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Start the Deno process
|
|
107
|
+
const args = [
|
|
108
|
+
"run",
|
|
109
|
+
"-A",
|
|
110
|
+
mainTsPath,
|
|
111
|
+
"serve",
|
|
112
|
+
"--port",
|
|
113
|
+
this.config.port!.toString(),
|
|
114
|
+
"--host",
|
|
115
|
+
this.config.host!,
|
|
116
|
+
"--data-dir",
|
|
117
|
+
this.config.dataDir!,
|
|
118
|
+
];
|
|
119
|
+
|
|
120
|
+
this.process = spawn(this.denoPath, args, {
|
|
121
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
122
|
+
cwd: path.dirname(__dirname),
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
this.apiUrl = `http://${this.config.host}:${this.config.port}`;
|
|
126
|
+
|
|
127
|
+
// Handle process events
|
|
128
|
+
this.process.on("error", (error) => {
|
|
129
|
+
this.emit("error", error);
|
|
130
|
+
reject(error);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
this.process.on("exit", (code) => {
|
|
134
|
+
this.isRunning = false;
|
|
135
|
+
this.emit("exit", code);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
// Wait for server to start
|
|
139
|
+
this.waitForServer()
|
|
140
|
+
.then(() => {
|
|
141
|
+
this.isRunning = true;
|
|
142
|
+
this.emit("started");
|
|
143
|
+
resolve();
|
|
144
|
+
})
|
|
145
|
+
.catch(reject);
|
|
146
|
+
|
|
147
|
+
// Handle stdout/stderr
|
|
148
|
+
this.process.stdout?.on("data", (data) => {
|
|
149
|
+
const output = data.toString();
|
|
150
|
+
this.emit("stdout", output);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
this.process.stderr?.on("data", (data) => {
|
|
154
|
+
const output = data.toString();
|
|
155
|
+
this.emit("stderr", output);
|
|
156
|
+
});
|
|
157
|
+
} catch (error) {
|
|
158
|
+
reject(error);
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
private async waitForServer(timeout = 10000): Promise<void> {
|
|
164
|
+
const startTime = Date.now();
|
|
165
|
+
|
|
166
|
+
while (Date.now() - startTime < timeout) {
|
|
167
|
+
try {
|
|
168
|
+
const response = await fetch(`${this.apiUrl}/api/config`);
|
|
169
|
+
if (response.ok) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
} catch (error) {
|
|
173
|
+
// Server not ready yet
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
throw new Error("Server failed to start within timeout");
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
async stop(): Promise<void> {
|
|
183
|
+
if (!this.isRunning || !this.process) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return new Promise((resolve) => {
|
|
188
|
+
this.process!.kill("SIGTERM");
|
|
189
|
+
|
|
190
|
+
this.process!.on("exit", () => {
|
|
191
|
+
this.isRunning = false;
|
|
192
|
+
this.emit("stopped");
|
|
193
|
+
resolve();
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
// Force kill after 5 seconds
|
|
197
|
+
setTimeout(() => {
|
|
198
|
+
if (this.process && this.isRunning) {
|
|
199
|
+
this.process.kill("SIGKILL");
|
|
200
|
+
}
|
|
201
|
+
resolve();
|
|
202
|
+
}, 5000);
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
getApiUrl(): string {
|
|
207
|
+
return this.apiUrl;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
getWebUrl(): string {
|
|
211
|
+
return `http://${this.config.host}:${this.config.webPort}`;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
isServerRunning(): boolean {
|
|
215
|
+
return this.isRunning;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// SQLite-compatible API methods
|
|
219
|
+
async query(sql: string, params: any[] = []): Promise<any> {
|
|
220
|
+
const response = await fetch(`${this.apiUrl}/api/query`, {
|
|
221
|
+
method: "POST",
|
|
222
|
+
headers: { "Content-Type": "application/json" },
|
|
223
|
+
body: JSON.stringify({ sql, params }),
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
if (!response.ok) {
|
|
227
|
+
throw new Error(`Query failed: ${response.statusText}`);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return response.json();
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
async put(key: string, value: any): Promise<void> {
|
|
234
|
+
const response = await fetch(`${this.apiUrl}/api/data`, {
|
|
235
|
+
method: "PUT",
|
|
236
|
+
headers: { "Content-Type": "application/json" },
|
|
237
|
+
body: JSON.stringify({ key, value }),
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
if (!response.ok) {
|
|
241
|
+
throw new Error(`Put failed: ${response.statusText}`);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
async get(key: string): Promise<any> {
|
|
246
|
+
const response = await fetch(`${this.apiUrl}/api/data/${encodeURIComponent(key)}`);
|
|
247
|
+
|
|
248
|
+
if (!response.ok) {
|
|
249
|
+
if (response.status === 404) {
|
|
250
|
+
return null;
|
|
251
|
+
}
|
|
252
|
+
throw new Error(`Get failed: ${response.statusText}`);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
return response.json();
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
async delete(key: string): Promise<void> {
|
|
259
|
+
const response = await fetch(`${this.apiUrl}/api/data/${encodeURIComponent(key)}`, {
|
|
260
|
+
method: "DELETE",
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
if (!response.ok) {
|
|
264
|
+
throw new Error(`Delete failed: ${response.statusText}`);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
async vectorSearch(query: string, limit = 10): Promise<any[]> {
|
|
269
|
+
const response = await fetch(`${this.apiUrl}/api/vsearch`, {
|
|
270
|
+
method: "POST",
|
|
271
|
+
headers: { "Content-Type": "application/json" },
|
|
272
|
+
body: JSON.stringify({ query, limit }),
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
if (!response.ok) {
|
|
276
|
+
throw new Error(`Vector search failed: ${response.statusText}`);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
return response.json() as Promise<any[]>;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
async list(prefix?: string): Promise<string[]> {
|
|
283
|
+
const url = prefix
|
|
284
|
+
? `${this.apiUrl}/api/list?prefix=${encodeURIComponent(prefix)}`
|
|
285
|
+
: `${this.apiUrl}/api/list`;
|
|
286
|
+
const response = await fetch(url);
|
|
287
|
+
|
|
288
|
+
if (!response.ok) {
|
|
289
|
+
throw new Error(`List failed: ${response.statusText}`);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
return response.json() as Promise<string[]>;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
async getConfig(): Promise<any> {
|
|
296
|
+
const response = await fetch(`${this.apiUrl}/api/config`);
|
|
297
|
+
|
|
298
|
+
if (!response.ok) {
|
|
299
|
+
throw new Error(`Get config failed: ${response.statusText}`);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
return response.json();
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
async setConfig(config: any): Promise<void> {
|
|
306
|
+
const response = await fetch(`${this.apiUrl}/api/config`, {
|
|
307
|
+
method: "POST",
|
|
308
|
+
headers: { "Content-Type": "application/json" },
|
|
309
|
+
body: JSON.stringify(config),
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
if (!response.ok) {
|
|
313
|
+
throw new Error(`Set config failed: ${response.statusText}`);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// Export the main class and types
|
|
319
|
+
export { PluresNode as default };
|
|
320
|
+
export * from "./types/index";
|