@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.
- package/README.md +97 -289
- 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 +20 -9
- 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/local-first/unified-api.d.ts +0 -110
- package/dist/local-first/unified-api.d.ts.map +0 -1
- package/dist/local-first/unified-api.js +0 -348
- package/dist/local-first/unified-api.js.map +0 -1
- package/dist/node-index.d.ts +0 -150
- package/dist/node-index.d.ts.map +0 -1
- package/dist/node-index.js +0 -668
- 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/util/debug.d.ts +0 -3
- package/dist/util/debug.d.ts.map +0 -1
- package/dist/util/debug.js +0 -34
- package/dist/util/debug.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/browser-demo/README.md +0 -204
- package/examples/browser-demo/index.html +0 -466
- package/examples/browser-wasm-integration.md +0 -411
- package/examples/ipc-demo/README.md +0 -127
- package/examples/local-first-usage.ts +0 -138
- package/examples/native-ipc-integration.md +0 -526
- package/examples/tauri-demo/README.md +0 -240
- package/examples/tauri-integration.md +0 -260
- 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 -569
- package/legacy/index.ts +0 -31
- package/legacy/local-first/unified-api.ts +0 -449
- 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 -827
- package/legacy/node-wrapper.ts +0 -329
- package/legacy/plugins/README.md +0 -181
- package/legacy/plugins/example-embedding-plugin.ts +0 -56
- package/legacy/plugins/plugin-system.ts +0 -315
- 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/local-first-api.test.ts +0 -65
- package/legacy/tests/unit/plugin-system.test.ts +0 -388
- 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 -27
- 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/scripts/validate-npm-publish.js +0 -228
- package/web/README.md +0 -27
- package/web/svelte/package.json +0 -31
package/legacy/util/debug.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export const DEBUG_ENABLED: boolean = (() => {
|
|
2
|
-
try {
|
|
3
|
-
let v = "";
|
|
4
|
-
// Check for Deno environment
|
|
5
|
-
if (typeof (globalThis as any).Deno !== "undefined") {
|
|
6
|
-
const Deno = (globalThis as any).Deno;
|
|
7
|
-
if (Deno.env && Deno.env.get) {
|
|
8
|
-
v = Deno.env.get("PLURESDB_DEBUG") ?? "";
|
|
9
|
-
}
|
|
10
|
-
} else {
|
|
11
|
-
// Check for Node.js environment
|
|
12
|
-
const globalProcess = (globalThis as any).process;
|
|
13
|
-
if (typeof globalProcess !== "undefined" && globalProcess?.env) {
|
|
14
|
-
v = globalProcess.env.PLURESDB_DEBUG ?? "";
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
return v === "1" || v.toLowerCase() === "true";
|
|
18
|
-
} catch {
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
})();
|
|
22
|
-
|
|
23
|
-
export function debugLog(...args: unknown[]): void {
|
|
24
|
-
if (!DEBUG_ENABLED) return;
|
|
25
|
-
// deno-lint-ignore no-console
|
|
26
|
-
console.log("[pluresdb]", ...args);
|
|
27
|
-
}
|
package/legacy/vector/index.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
export interface VectorIndexResult {
|
|
2
|
-
id: string;
|
|
3
|
-
score: number;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export interface VectorIndex {
|
|
7
|
-
upsert(id: string, vector: number[]): void;
|
|
8
|
-
remove(id: string): void;
|
|
9
|
-
search(vector: number[], k: number): VectorIndexResult[];
|
|
10
|
-
clear(): void;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export class BruteForceVectorIndex implements VectorIndex {
|
|
14
|
-
private readonly idToVector = new Map<string, Float32Array>();
|
|
15
|
-
|
|
16
|
-
upsert(id: string, vector: number[]): void {
|
|
17
|
-
const normed = normalizeVector(vector);
|
|
18
|
-
this.idToVector.set(id, normed);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
remove(id: string): void {
|
|
22
|
-
this.idToVector.delete(id);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
clear(): void {
|
|
26
|
-
this.idToVector.clear();
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
search(vector: number[], k: number): VectorIndexResult[] {
|
|
30
|
-
const q = normalizeVector(vector);
|
|
31
|
-
const results: VectorIndexResult[] = [];
|
|
32
|
-
for (const [id, v] of this.idToVector) {
|
|
33
|
-
const score = cosine(q, v);
|
|
34
|
-
if (Number.isFinite(score)) results.push({ id, score });
|
|
35
|
-
}
|
|
36
|
-
results.sort((a, b) => b.score - a.score);
|
|
37
|
-
return results.slice(0, k);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function normalizeVector(vector: number[]): Float32Array {
|
|
42
|
-
const arr = new Float32Array(vector.length);
|
|
43
|
-
let n = 0;
|
|
44
|
-
for (let i = 0; i < vector.length; i++) {
|
|
45
|
-
const v = vector[i] ?? 0;
|
|
46
|
-
arr[i] = v;
|
|
47
|
-
n += v * v;
|
|
48
|
-
}
|
|
49
|
-
const norm = Math.sqrt(n) || 1;
|
|
50
|
-
for (let i = 0; i < arr.length; i++) arr[i] /= norm;
|
|
51
|
-
return arr;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function cosine(a: Float32Array, b: Float32Array): number {
|
|
55
|
-
const len = Math.min(a.length, b.length);
|
|
56
|
-
let dot = 0;
|
|
57
|
-
for (let i = 0; i < len; i++) dot += a[i] * b[i];
|
|
58
|
-
return dot;
|
|
59
|
-
}
|
|
@@ -1,387 +0,0 @@
|
|
|
1
|
-
import * as path from "node:path";
|
|
2
|
-
import { PluresNode, SQLiteCompatibleAPI } from "../node-index";
|
|
3
|
-
import type { PluresDBConfig } from "../types/node-types";
|
|
4
|
-
|
|
5
|
-
type DisposableLike = { dispose(): void };
|
|
6
|
-
|
|
7
|
-
type InputBoxOptions = {
|
|
8
|
-
prompt: string;
|
|
9
|
-
placeHolder?: string;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
type TextDocumentInit = {
|
|
13
|
-
content: string;
|
|
14
|
-
language: string;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
type UriLike = { toString(): string } | string;
|
|
18
|
-
|
|
19
|
-
export type VSCodeWindow = {
|
|
20
|
-
showInformationMessage(message: string): void | Promise<unknown>;
|
|
21
|
-
showErrorMessage(message: string): void | Promise<unknown>;
|
|
22
|
-
showInputBox(options: InputBoxOptions): Promise<string | undefined>;
|
|
23
|
-
showTextDocument(document: unknown): Promise<unknown>;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export type VSCodeCommands = {
|
|
27
|
-
registerCommand(
|
|
28
|
-
command: string,
|
|
29
|
-
callback: (...args: unknown[]) => unknown,
|
|
30
|
-
): DisposableLike;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export type VSCodeWorkspace = {
|
|
34
|
-
openTextDocument(init: TextDocumentInit): Promise<unknown>;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export type VSCodeEnv = {
|
|
38
|
-
openExternal(target: UriLike): Promise<unknown> | unknown;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export type VSCodeUri = {
|
|
42
|
-
parse(target: string): UriLike;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export type VSCodeAPI = {
|
|
46
|
-
window: VSCodeWindow;
|
|
47
|
-
commands: VSCodeCommands;
|
|
48
|
-
workspace: VSCodeWorkspace;
|
|
49
|
-
env: VSCodeEnv;
|
|
50
|
-
Uri: VSCodeUri;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
export type ExtensionContextLike = {
|
|
54
|
-
subscriptions: DisposableLike[];
|
|
55
|
-
globalStorageUri: { fsPath: string };
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
export type ExtensionOptions = {
|
|
59
|
-
config?: PluresDBConfig;
|
|
60
|
-
commandPrefix?: string;
|
|
61
|
-
pluresInstance?: PluresNode;
|
|
62
|
-
sqliteInstance?: SQLiteCompatibleAPI;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
type CommandFactory = () => Promise<void> | void;
|
|
66
|
-
|
|
67
|
-
const DEFAULT_CONFIG: PluresDBConfig = {
|
|
68
|
-
port: 34567,
|
|
69
|
-
host: "localhost",
|
|
70
|
-
webPort: 34568,
|
|
71
|
-
logLevel: "info",
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
export class PluresVSCodeExtension {
|
|
75
|
-
private readonly vscode: VSCodeAPI;
|
|
76
|
-
private readonly context: ExtensionContextLike;
|
|
77
|
-
private readonly plures: PluresNode;
|
|
78
|
-
private readonly sqlite: SQLiteCompatibleAPI;
|
|
79
|
-
private readonly commandPrefix: string;
|
|
80
|
-
private readonly disposables: DisposableLike[] = [];
|
|
81
|
-
private activated = false;
|
|
82
|
-
|
|
83
|
-
constructor(
|
|
84
|
-
vscodeApi: VSCodeAPI,
|
|
85
|
-
context: ExtensionContextLike,
|
|
86
|
-
options: ExtensionOptions = {},
|
|
87
|
-
) {
|
|
88
|
-
this.vscode = vscodeApi;
|
|
89
|
-
this.context = context;
|
|
90
|
-
this.commandPrefix = options.commandPrefix ?? "pluresdb";
|
|
91
|
-
|
|
92
|
-
const mergedConfig: PluresDBConfig = {
|
|
93
|
-
...DEFAULT_CONFIG,
|
|
94
|
-
dataDir: path.join(context.globalStorageUri.fsPath, "pluresdb"),
|
|
95
|
-
...options.config,
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
this.plures = options.pluresInstance ??
|
|
99
|
-
new PluresNode({ config: mergedConfig, autoStart: false });
|
|
100
|
-
this.sqlite = options.sqliteInstance ??
|
|
101
|
-
new SQLiteCompatibleAPI({ config: mergedConfig, autoStart: false });
|
|
102
|
-
|
|
103
|
-
this.setupEventHandlers();
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
async activate(): Promise<void> {
|
|
107
|
-
if (this.activated) {
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
try {
|
|
112
|
-
await this.plures.start();
|
|
113
|
-
await this.sqlite.start();
|
|
114
|
-
this.registerCommands();
|
|
115
|
-
await this.setupDatabase();
|
|
116
|
-
this.activated = true;
|
|
117
|
-
await this.safeInfo("PluresDB extension activated");
|
|
118
|
-
} catch (error) {
|
|
119
|
-
await this.safeError(
|
|
120
|
-
`Failed to activate PluresDB: ${this.errorMessage(error)}`,
|
|
121
|
-
);
|
|
122
|
-
throw error;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
async deactivate(): Promise<void> {
|
|
127
|
-
if (!this.activated) {
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
try {
|
|
132
|
-
await this.sqlite.stop();
|
|
133
|
-
await this.plures.stop();
|
|
134
|
-
} finally {
|
|
135
|
-
this.disposeAll();
|
|
136
|
-
this.activated = false;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
getWebUrl(): string {
|
|
141
|
-
return this.plures.getWebUrl();
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
async storeSetting(key: string, value: unknown) {
|
|
145
|
-
return this.sqlite.put(`settings:${key}`, value);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
async getSetting(key: string) {
|
|
149
|
-
return this.sqlite.getValue(`settings:${key}`);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
async storeDocument(
|
|
153
|
-
id: string,
|
|
154
|
-
content: string,
|
|
155
|
-
language: string,
|
|
156
|
-
filePath: string,
|
|
157
|
-
) {
|
|
158
|
-
return this.sqlite.put(`documents:${id}`, {
|
|
159
|
-
content,
|
|
160
|
-
language,
|
|
161
|
-
filePath,
|
|
162
|
-
updatedAt: new Date().toISOString(),
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
async searchDocuments(query: string, limit = 20) {
|
|
167
|
-
return this.sqlite.vectorSearch(query, limit);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
async executeSQL(sql: string, params: unknown[] = []) {
|
|
171
|
-
return this.sqlite.all(sql, params);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
private setupEventHandlers() {
|
|
175
|
-
this.plures.on("started", () => {
|
|
176
|
-
this.safeInfo("PluresDB database started");
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
this.plures.on("stopped", () => {
|
|
180
|
-
this.safeInfo("PluresDB database stopped");
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
this.plures.on("error", (error: unknown) => {
|
|
184
|
-
this.safeError(`PluresDB error: ${this.errorMessage(error)}`);
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
this.plures.on("stderr", (output: string) => {
|
|
188
|
-
const trimmed = output.trim();
|
|
189
|
-
if (trimmed.length > 0) {
|
|
190
|
-
this.safeError(trimmed);
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
this.plures.on("stdout", (output: string) => {
|
|
195
|
-
const trimmed = output.trim();
|
|
196
|
-
if (trimmed.length > 0) {
|
|
197
|
-
this.safeInfo(trimmed);
|
|
198
|
-
}
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
private registerCommands() {
|
|
203
|
-
const register = (name: string, factory: CommandFactory) => {
|
|
204
|
-
const disposable = this.vscode.commands.registerCommand(
|
|
205
|
-
`${this.commandPrefix}.${name}`,
|
|
206
|
-
() => factory(),
|
|
207
|
-
);
|
|
208
|
-
this.context.subscriptions.push(disposable);
|
|
209
|
-
this.disposables.push(disposable);
|
|
210
|
-
};
|
|
211
|
-
|
|
212
|
-
register("openWebUI", async () => {
|
|
213
|
-
const webUrl = this.getWebUrl();
|
|
214
|
-
await this.vscode.env.openExternal(this.vscode.Uri.parse(webUrl));
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
register("executeQuery", async () => {
|
|
218
|
-
const sql = await this.vscode.window.showInputBox({
|
|
219
|
-
prompt: "Enter SQL query",
|
|
220
|
-
placeHolder: "SELECT * FROM users",
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
if (!sql) return;
|
|
224
|
-
|
|
225
|
-
try {
|
|
226
|
-
const result = await this.sqlite.all(sql);
|
|
227
|
-
const doc = await this.vscode.workspace.openTextDocument({
|
|
228
|
-
content: JSON.stringify(result, null, 2),
|
|
229
|
-
language: "json",
|
|
230
|
-
});
|
|
231
|
-
await this.vscode.window.showTextDocument(doc);
|
|
232
|
-
} catch (error) {
|
|
233
|
-
await this.safeError(`Query failed: ${this.errorMessage(error)}`);
|
|
234
|
-
}
|
|
235
|
-
});
|
|
236
|
-
|
|
237
|
-
register("vectorSearch", async () => {
|
|
238
|
-
const query = await this.vscode.window.showInputBox({
|
|
239
|
-
prompt: "Enter search query",
|
|
240
|
-
placeHolder: "machine learning",
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
if (!query) return;
|
|
244
|
-
|
|
245
|
-
try {
|
|
246
|
-
const results = await this.sqlite.vectorSearch(query, 10);
|
|
247
|
-
const doc = await this.vscode.workspace.openTextDocument({
|
|
248
|
-
content: JSON.stringify(results, null, 2),
|
|
249
|
-
language: "json",
|
|
250
|
-
});
|
|
251
|
-
await this.vscode.window.showTextDocument(doc);
|
|
252
|
-
} catch (error) {
|
|
253
|
-
await this.safeError(
|
|
254
|
-
`Vector search failed: ${this.errorMessage(error)}`,
|
|
255
|
-
);
|
|
256
|
-
}
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
register("storeData", async () => {
|
|
260
|
-
const key = await this.vscode.window.showInputBox({
|
|
261
|
-
prompt: "Enter key",
|
|
262
|
-
placeHolder: "user:123",
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
if (!key) return;
|
|
266
|
-
|
|
267
|
-
const json = await this.vscode.window.showInputBox({
|
|
268
|
-
prompt: "Enter value (JSON)",
|
|
269
|
-
placeHolder: '{"name": "Ada", "email": "ada@example.com"}',
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
if (!json) return;
|
|
273
|
-
|
|
274
|
-
try {
|
|
275
|
-
const value = JSON.parse(json);
|
|
276
|
-
await this.sqlite.put(key, value);
|
|
277
|
-
await this.safeInfo(`Stored data for key: ${key}`);
|
|
278
|
-
} catch (error) {
|
|
279
|
-
await this.safeError(
|
|
280
|
-
`Failed to store data: ${this.errorMessage(error)}`,
|
|
281
|
-
);
|
|
282
|
-
}
|
|
283
|
-
});
|
|
284
|
-
|
|
285
|
-
register("retrieveData", async () => {
|
|
286
|
-
const key = await this.vscode.window.showInputBox({
|
|
287
|
-
prompt: "Enter key to retrieve",
|
|
288
|
-
placeHolder: "user:123",
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
if (!key) return;
|
|
292
|
-
|
|
293
|
-
try {
|
|
294
|
-
const value = await this.sqlite.getValue(key);
|
|
295
|
-
if (value) {
|
|
296
|
-
const doc = await this.vscode.workspace.openTextDocument({
|
|
297
|
-
content: JSON.stringify(value, null, 2),
|
|
298
|
-
language: "json",
|
|
299
|
-
});
|
|
300
|
-
await this.vscode.window.showTextDocument(doc);
|
|
301
|
-
} else {
|
|
302
|
-
await this.safeInfo("Key not found");
|
|
303
|
-
}
|
|
304
|
-
} catch (error) {
|
|
305
|
-
await this.safeError(
|
|
306
|
-
`Failed to retrieve data: ${this.errorMessage(error)}`,
|
|
307
|
-
);
|
|
308
|
-
}
|
|
309
|
-
});
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
private async setupDatabase() {
|
|
313
|
-
const statements = [
|
|
314
|
-
`CREATE TABLE IF NOT EXISTS settings (
|
|
315
|
-
key TEXT PRIMARY KEY,
|
|
316
|
-
value TEXT,
|
|
317
|
-
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
318
|
-
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
319
|
-
)`,
|
|
320
|
-
`CREATE TABLE IF NOT EXISTS documents (
|
|
321
|
-
id TEXT PRIMARY KEY,
|
|
322
|
-
content TEXT,
|
|
323
|
-
language TEXT,
|
|
324
|
-
file_path TEXT,
|
|
325
|
-
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
326
|
-
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
327
|
-
)`,
|
|
328
|
-
`CREATE TABLE IF NOT EXISTS search_history (
|
|
329
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
330
|
-
query TEXT,
|
|
331
|
-
results_count INTEGER,
|
|
332
|
-
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
333
|
-
)`,
|
|
334
|
-
];
|
|
335
|
-
|
|
336
|
-
for (const sql of statements) {
|
|
337
|
-
try {
|
|
338
|
-
await this.sqlite.exec(sql);
|
|
339
|
-
} catch (error) {
|
|
340
|
-
await this.safeError(
|
|
341
|
-
`Failed to initialize database: ${this.errorMessage(error)}`,
|
|
342
|
-
);
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
private disposeAll() {
|
|
348
|
-
for (const disposable of this.disposables.splice(0)) {
|
|
349
|
-
try {
|
|
350
|
-
disposable.dispose();
|
|
351
|
-
} catch (_error) {
|
|
352
|
-
// ignore
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
private async safeInfo(message: string) {
|
|
358
|
-
try {
|
|
359
|
-
await this.vscode.window.showInformationMessage(message);
|
|
360
|
-
} catch (_error) {
|
|
361
|
-
// ignore message failures in headless tests
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
private async safeError(message: string) {
|
|
366
|
-
try {
|
|
367
|
-
await this.vscode.window.showErrorMessage(message);
|
|
368
|
-
} catch (_error) {
|
|
369
|
-
// ignore message failures in headless tests
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
private errorMessage(error: unknown): string {
|
|
374
|
-
if (error instanceof Error) {
|
|
375
|
-
return error.message;
|
|
376
|
-
}
|
|
377
|
-
return String(error);
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
export function createPluresExtension(
|
|
382
|
-
vscodeApi: VSCodeAPI,
|
|
383
|
-
context: ExtensionContextLike,
|
|
384
|
-
options: ExtensionOptions = {},
|
|
385
|
-
) {
|
|
386
|
-
return new PluresVSCodeExtension(vscodeApi, context, options);
|
|
387
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { GunDB } from "../src/core/database.ts";
|
|
2
|
-
|
|
3
|
-
const serverUrl = Deno.env.get("SERVER_URL") ?? "ws://localhost:34567";
|
|
4
|
-
|
|
5
|
-
const clientA = new GunDB();
|
|
6
|
-
const clientB = new GunDB();
|
|
7
|
-
|
|
8
|
-
const kvA = await Deno.makeTempFile({ prefix: "kv_", suffix: ".sqlite" });
|
|
9
|
-
const kvB = await Deno.makeTempFile({ prefix: "kv_", suffix: ".sqlite" });
|
|
10
|
-
|
|
11
|
-
await clientA.ready(kvA);
|
|
12
|
-
await clientB.ready(kvB);
|
|
13
|
-
|
|
14
|
-
clientA.connect(serverUrl);
|
|
15
|
-
clientB.connect(serverUrl);
|
|
16
|
-
|
|
17
|
-
const id = `bin:crud:${crypto.randomUUID()}`;
|
|
18
|
-
|
|
19
|
-
const receivedOnB = new Promise<void>((resolve) =>
|
|
20
|
-
clientB.on(id, (n) => n && resolve())
|
|
21
|
-
);
|
|
22
|
-
|
|
23
|
-
await clientA.put(id, { text: "compiled works" } as Record<string, unknown>);
|
|
24
|
-
|
|
25
|
-
await receivedOnB;
|
|
26
|
-
|
|
27
|
-
await clientA.close();
|
|
28
|
-
await clientB.close();
|
|
29
|
-
|
|
30
|
-
console.log("COMPILED-CRUD-OK", id);
|