pluresdb 1.0.1 → 1.3.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.
Files changed (79) hide show
  1. package/README.md +100 -5
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/better-sqlite3-shared.d.ts +12 -0
  4. package/dist/better-sqlite3-shared.d.ts.map +1 -0
  5. package/dist/better-sqlite3-shared.js +143 -0
  6. package/dist/better-sqlite3-shared.js.map +1 -0
  7. package/dist/better-sqlite3.d.ts +4 -0
  8. package/dist/better-sqlite3.d.ts.map +1 -0
  9. package/dist/better-sqlite3.js +8 -0
  10. package/dist/better-sqlite3.js.map +1 -0
  11. package/dist/cli.d.ts.map +1 -1
  12. package/dist/cli.js +21 -16
  13. package/dist/cli.js.map +1 -1
  14. package/dist/node-index.d.ts +98 -2
  15. package/dist/node-index.d.ts.map +1 -1
  16. package/dist/node-index.js +312 -6
  17. package/dist/node-index.js.map +1 -1
  18. package/dist/node-wrapper.d.ts.map +1 -1
  19. package/dist/node-wrapper.js +5 -3
  20. package/dist/node-wrapper.js.map +1 -1
  21. package/dist/types/index.d.ts.map +1 -1
  22. package/dist/types/index.js.map +1 -1
  23. package/dist/types/node-types.d.ts +12 -0
  24. package/dist/types/node-types.d.ts.map +1 -1
  25. package/dist/types/node-types.js.map +1 -1
  26. package/dist/vscode/extension.d.ts.map +1 -1
  27. package/dist/vscode/extension.js +4 -4
  28. package/dist/vscode/extension.js.map +1 -1
  29. package/examples/basic-usage.d.ts +1 -1
  30. package/examples/vscode-extension-example/src/extension.ts +15 -6
  31. package/examples/vscode-extension-integration.d.ts +24 -17
  32. package/examples/vscode-extension-integration.js +140 -106
  33. package/examples/vscode-extension-integration.ts +1 -1
  34. package/{src → legacy}/benchmarks/memory-benchmarks.ts +85 -51
  35. package/{src → legacy}/benchmarks/run-benchmarks.ts +32 -10
  36. package/legacy/better-sqlite3-shared.ts +157 -0
  37. package/legacy/better-sqlite3.ts +4 -0
  38. package/{src → legacy}/cli.ts +14 -4
  39. package/{src → legacy}/config.ts +2 -1
  40. package/{src → legacy}/core/crdt.ts +4 -1
  41. package/{src → legacy}/core/database.ts +57 -22
  42. package/{src → legacy}/healthcheck.ts +11 -5
  43. package/{src → legacy}/http/api-server.ts +125 -21
  44. package/{src → legacy}/index.ts +2 -2
  45. package/{src → legacy}/logic/rules.ts +3 -1
  46. package/{src → legacy}/main.ts +11 -4
  47. package/legacy/node-index.ts +823 -0
  48. package/{src → legacy}/node-wrapper.ts +18 -9
  49. package/{src → legacy}/sqlite-compat.ts +63 -16
  50. package/{src → legacy}/sqlite3-compat.ts +2 -2
  51. package/{src → legacy}/storage/kv-storage.ts +3 -1
  52. package/{src → legacy}/tests/core.test.ts +37 -13
  53. package/{src → legacy}/tests/fixtures/test-data.json +6 -1
  54. package/{src → legacy}/tests/integration/api-server.test.ts +110 -8
  55. package/{src → legacy}/tests/integration/mesh-network.test.ts +8 -2
  56. package/{src → legacy}/tests/logic.test.ts +6 -2
  57. package/{src → legacy}/tests/performance/load.test.ts +4 -2
  58. package/{src → legacy}/tests/security/input-validation.test.ts +5 -1
  59. package/{src → legacy}/tests/unit/core.test.ts +13 -3
  60. package/{src → legacy}/tests/unit/subscriptions.test.ts +1 -1
  61. package/{src → legacy}/tests/vscode_extension_test.ts +39 -11
  62. package/{src → legacy}/types/node-types.ts +14 -0
  63. package/{src → legacy}/vscode/extension.ts +37 -14
  64. package/package.json +19 -9
  65. package/scripts/compiled-crud-verify.ts +3 -1
  66. package/scripts/dogfood.ts +55 -16
  67. package/scripts/postinstall.js +4 -3
  68. package/scripts/release-check.js +190 -0
  69. package/scripts/run-tests.ts +5 -2
  70. package/scripts/update-changelog.js +214 -0
  71. package/web/svelte/package.json +5 -5
  72. package/src/node-index.ts +0 -385
  73. /package/{src → legacy}/main.rs +0 -0
  74. /package/{src → legacy}/network/websocket-server.ts +0 -0
  75. /package/{src → legacy}/tests/fixtures/performance-data.json +0 -0
  76. /package/{src → legacy}/tests/unit/vector-search.test.ts +0 -0
  77. /package/{src → legacy}/types/index.ts +0 -0
  78. /package/{src → legacy}/util/debug.ts +0 -0
  79. /package/{src → legacy}/vector/index.ts +0 -0
@@ -3,44 +3,45 @@
3
3
  * VSCode Extension Integration Example
4
4
  * This shows how to integrate PluresDB into a VSCode extension
5
5
  */
6
- var __createBinding =
7
- (this && this.__createBinding) ||
6
+ var __createBinding = (this && this.__createBinding) ||
8
7
  (Object.create
9
8
  ? function (o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- var desc = Object.getOwnPropertyDescriptor(m, k);
12
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
13
- desc = {
14
- enumerable: true,
15
- get: function () {
16
- return m[k];
17
- },
18
- };
19
- }
20
- Object.defineProperty(o, k2, desc);
9
+ if (k2 === undefined) k2 = k;
10
+ var desc = Object.getOwnPropertyDescriptor(m, k);
11
+ if (
12
+ !desc ||
13
+ ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)
14
+ ) {
15
+ desc = {
16
+ enumerable: true,
17
+ get: function () {
18
+ return m[k];
19
+ },
20
+ };
21
21
  }
22
+ Object.defineProperty(o, k2, desc);
23
+ }
22
24
  : function (o, m, k, k2) {
23
- if (k2 === undefined) k2 = k;
24
- o[k2] = m[k];
25
- });
26
- var __setModuleDefault =
27
- (this && this.__setModuleDefault) ||
25
+ if (k2 === undefined) k2 = k;
26
+ o[k2] = m[k];
27
+ });
28
+ var __setModuleDefault = (this && this.__setModuleDefault) ||
28
29
  (Object.create
29
30
  ? function (o, v) {
30
- Object.defineProperty(o, "default", { enumerable: true, value: v });
31
- }
31
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
32
+ }
32
33
  : function (o, v) {
33
- o["default"] = v;
34
- });
35
- var __importStar =
36
- (this && this.__importStar) ||
34
+ o["default"] = v;
35
+ });
36
+ var __importStar = (this && this.__importStar) ||
37
37
  (function () {
38
38
  var ownKeys = function (o) {
39
- ownKeys =
40
- Object.getOwnPropertyNames ||
39
+ ownKeys = Object.getOwnPropertyNames ||
41
40
  function (o) {
42
41
  var ar = [];
43
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
42
+ for (var k in o) {
43
+ if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
44
+ }
44
45
  return ar;
45
46
  };
46
47
  return ownKeys(o);
@@ -48,9 +49,11 @@ var __importStar =
48
49
  return function (mod) {
49
50
  if (mod && mod.__esModule) return mod;
50
51
  var result = {};
51
- if (mod != null)
52
- for (var k = ownKeys(mod), i = 0; i < k.length; i++)
52
+ if (mod != null) {
53
+ for (var k = ownKeys(mod), i = 0; i < k.length; i++) {
53
54
  if (k[i] !== "default") __createBinding(result, mod, k[i]);
55
+ }
56
+ }
54
57
  __setModuleDefault(result, mod);
55
58
  return result;
56
59
  };
@@ -114,7 +117,9 @@ class PluresExtension {
114
117
  await this.setupDatabase();
115
118
  vscode.window.showInformationMessage("PluresDB extension activated");
116
119
  } catch (error) {
117
- vscode.window.showErrorMessage(`Failed to activate PluresDB: ${error.message}`);
120
+ vscode.window.showErrorMessage(
121
+ `Failed to activate PluresDB: ${error.message}`,
122
+ );
118
123
  }
119
124
  }
120
125
  async deactivate() {
@@ -127,95 +132,124 @@ class PluresExtension {
127
132
  }
128
133
  registerCommands() {
129
134
  // Command to open PluresDB web UI
130
- const openWebUI = vscode.commands.registerCommand("pluresdb.openWebUI", () => {
131
- const webUrl = this.plures.getWebUrl();
132
- vscode.env.openExternal(vscode.Uri.parse(webUrl));
133
- });
135
+ const openWebUI = vscode.commands.registerCommand(
136
+ "pluresdb.openWebUI",
137
+ () => {
138
+ const webUrl = this.plures.getWebUrl();
139
+ vscode.env.openExternal(vscode.Uri.parse(webUrl));
140
+ },
141
+ );
134
142
  // Command to execute SQL query
135
- const executeQuery = vscode.commands.registerCommand("pluresdb.executeQuery", async () => {
136
- const sql = await vscode.window.showInputBox({
137
- prompt: "Enter SQL query",
138
- placeHolder: "SELECT * FROM users",
139
- });
140
- if (sql) {
141
- try {
142
- const result = await this.sqliteAPI.all(sql);
143
- const doc = await vscode.workspace.openTextDocument({
144
- content: JSON.stringify(result, null, 2),
145
- language: "json",
146
- });
147
- await vscode.window.showTextDocument(doc);
148
- } catch (error) {
149
- vscode.window.showErrorMessage(`Query failed: ${error.message}`);
150
- }
151
- }
152
- });
153
- // Command to perform vector search
154
- const vectorSearch = vscode.commands.registerCommand("pluresdb.vectorSearch", async () => {
155
- const query = await vscode.window.showInputBox({
156
- prompt: "Enter search query",
157
- placeHolder: "machine learning",
158
- });
159
- if (query) {
160
- try {
161
- const results = await this.sqliteAPI.vectorSearch(query, 10);
162
- const doc = await vscode.workspace.openTextDocument({
163
- content: JSON.stringify(results, null, 2),
164
- language: "json",
165
- });
166
- await vscode.window.showTextDocument(doc);
167
- } catch (error) {
168
- vscode.window.showErrorMessage(`Vector search failed: ${error.message}`);
169
- }
170
- }
171
- });
172
- // Command to store data
173
- const storeData = vscode.commands.registerCommand("pluresdb.storeData", async () => {
174
- const key = await vscode.window.showInputBox({
175
- prompt: "Enter key",
176
- placeHolder: "user:123",
177
- });
178
- if (key) {
179
- const value = await vscode.window.showInputBox({
180
- prompt: "Enter value (JSON)",
181
- placeHolder: '{"name": "John", "email": "john@example.com"}',
143
+ const executeQuery = vscode.commands.registerCommand(
144
+ "pluresdb.executeQuery",
145
+ async () => {
146
+ const sql = await vscode.window.showInputBox({
147
+ prompt: "Enter SQL query",
148
+ placeHolder: "SELECT * FROM users",
182
149
  });
183
- if (value) {
150
+ if (sql) {
184
151
  try {
185
- const parsedValue = JSON.parse(value);
186
- await this.sqliteAPI.put(key, parsedValue);
187
- vscode.window.showInformationMessage(`Stored data for key: ${key}`);
152
+ const result = await this.sqliteAPI.all(sql);
153
+ const doc = await vscode.workspace.openTextDocument({
154
+ content: JSON.stringify(result, null, 2),
155
+ language: "json",
156
+ });
157
+ await vscode.window.showTextDocument(doc);
188
158
  } catch (error) {
189
- vscode.window.showErrorMessage(`Failed to store data: ${error.message}`);
159
+ vscode.window.showErrorMessage(`Query failed: ${error.message}`);
190
160
  }
191
161
  }
192
- }
193
- });
194
- // Command to retrieve data
195
- const retrieveData = vscode.commands.registerCommand("pluresdb.retrieveData", async () => {
196
- const key = await vscode.window.showInputBox({
197
- prompt: "Enter key to retrieve",
198
- placeHolder: "user:123",
199
- });
200
- if (key) {
201
- try {
202
- const value = await this.sqliteAPI.getValue(key);
203
- if (value) {
162
+ },
163
+ );
164
+ // Command to perform vector search
165
+ const vectorSearch = vscode.commands.registerCommand(
166
+ "pluresdb.vectorSearch",
167
+ async () => {
168
+ const query = await vscode.window.showInputBox({
169
+ prompt: "Enter search query",
170
+ placeHolder: "machine learning",
171
+ });
172
+ if (query) {
173
+ try {
174
+ const results = await this.sqliteAPI.vectorSearch(query, 10);
204
175
  const doc = await vscode.workspace.openTextDocument({
205
- content: JSON.stringify(value, null, 2),
176
+ content: JSON.stringify(results, null, 2),
206
177
  language: "json",
207
178
  });
208
179
  await vscode.window.showTextDocument(doc);
209
- } else {
210
- vscode.window.showInformationMessage("Key not found");
180
+ } catch (error) {
181
+ vscode.window.showErrorMessage(
182
+ `Vector search failed: ${error.message}`,
183
+ );
211
184
  }
212
- } catch (error) {
213
- vscode.window.showErrorMessage(`Failed to retrieve data: ${error.message}`);
214
185
  }
215
- }
216
- });
186
+ },
187
+ );
188
+ // Command to store data
189
+ const storeData = vscode.commands.registerCommand(
190
+ "pluresdb.storeData",
191
+ async () => {
192
+ const key = await vscode.window.showInputBox({
193
+ prompt: "Enter key",
194
+ placeHolder: "user:123",
195
+ });
196
+ if (key) {
197
+ const value = await vscode.window.showInputBox({
198
+ prompt: "Enter value (JSON)",
199
+ placeHolder: '{"name": "John", "email": "john@example.com"}',
200
+ });
201
+ if (value) {
202
+ try {
203
+ const parsedValue = JSON.parse(value);
204
+ await this.sqliteAPI.put(key, parsedValue);
205
+ vscode.window.showInformationMessage(
206
+ `Stored data for key: ${key}`,
207
+ );
208
+ } catch (error) {
209
+ vscode.window.showErrorMessage(
210
+ `Failed to store data: ${error.message}`,
211
+ );
212
+ }
213
+ }
214
+ }
215
+ },
216
+ );
217
+ // Command to retrieve data
218
+ const retrieveData = vscode.commands.registerCommand(
219
+ "pluresdb.retrieveData",
220
+ async () => {
221
+ const key = await vscode.window.showInputBox({
222
+ prompt: "Enter key to retrieve",
223
+ placeHolder: "user:123",
224
+ });
225
+ if (key) {
226
+ try {
227
+ const value = await this.sqliteAPI.getValue(key);
228
+ if (value) {
229
+ const doc = await vscode.workspace.openTextDocument({
230
+ content: JSON.stringify(value, null, 2),
231
+ language: "json",
232
+ });
233
+ await vscode.window.showTextDocument(doc);
234
+ } else {
235
+ vscode.window.showInformationMessage("Key not found");
236
+ }
237
+ } catch (error) {
238
+ vscode.window.showErrorMessage(
239
+ `Failed to retrieve data: ${error.message}`,
240
+ );
241
+ }
242
+ }
243
+ },
244
+ );
217
245
  // Register all commands
218
- this.context.subscriptions.push(openWebUI, executeQuery, vectorSearch, storeData, retrieveData);
246
+ this.context.subscriptions.push(
247
+ openWebUI,
248
+ executeQuery,
249
+ vectorSearch,
250
+ storeData,
251
+ retrieveData,
252
+ );
219
253
  }
220
254
  async setupDatabase() {
221
255
  // Create tables for common VSCode extension use cases
@@ -6,8 +6,8 @@
6
6
  import * as vscode from "vscode";
7
7
  import {
8
8
  createPluresExtension,
9
- PluresVSCodeExtension,
10
9
  ExtensionContextLike,
10
+ PluresVSCodeExtension,
11
11
  VSCodeAPI,
12
12
  } from "../src/vscode/extension.ts";
13
13
 
@@ -54,9 +54,13 @@ class MemoryBenchmark {
54
54
 
55
55
  this.results.push(metrics);
56
56
 
57
- console.log(` Initial Memory: ${(initialMemory / 1024 / 1024).toFixed(2)}MB`);
57
+ console.log(
58
+ ` Initial Memory: ${(initialMemory / 1024 / 1024).toFixed(2)}MB`,
59
+ );
58
60
  console.log(` Final Memory: ${(finalMemory / 1024 / 1024).toFixed(2)}MB`);
59
- console.log(` Memory Increase: ${(memoryIncrease / 1024 / 1024).toFixed(2)}MB`);
61
+ console.log(
62
+ ` Memory Increase: ${(memoryIncrease / 1024 / 1024).toFixed(2)}MB`,
63
+ );
60
64
  console.log(` Memory per Record: ${memoryPerRecord.toFixed(2)} bytes`);
61
65
  console.log();
62
66
 
@@ -71,8 +75,14 @@ class MemoryBenchmark {
71
75
  this.results.forEach((result) => {
72
76
  console.log(`${result.operation}:`);
73
77
  console.log(` Records: ${result.recordCount.toLocaleString()}`);
74
- console.log(` Memory Increase: ${(result.memoryIncrease / 1024 / 1024).toFixed(2)}MB`);
75
- console.log(` Memory per Record: ${result.memoryPerRecord.toFixed(2)} bytes`);
78
+ console.log(
79
+ ` Memory Increase: ${
80
+ (result.memoryIncrease / 1024 / 1024).toFixed(2)
81
+ }MB`,
82
+ );
83
+ console.log(
84
+ ` Memory per Record: ${result.memoryPerRecord.toFixed(2)} bytes`,
85
+ );
76
86
  console.log();
77
87
  });
78
88
  }
@@ -92,53 +102,69 @@ async function runMemoryBenchmarks() {
92
102
  console.log("Starting Memory Benchmarks...\n");
93
103
 
94
104
  // Benchmark 1: Small Records
95
- await benchmark.measureMemoryUsage("Small Records (100 bytes)", 1000, async () => {
96
- for (let i = 0; i < 1000; i++) {
97
- await db.put(`small:${i}`, {
98
- id: i,
99
- data: "x".repeat(100),
100
- timestamp: Date.now(),
101
- });
102
- }
103
- });
105
+ await benchmark.measureMemoryUsage(
106
+ "Small Records (100 bytes)",
107
+ 1000,
108
+ async () => {
109
+ for (let i = 0; i < 1000; i++) {
110
+ await db.put(`small:${i}`, {
111
+ id: i,
112
+ data: "x".repeat(100),
113
+ timestamp: Date.now(),
114
+ });
115
+ }
116
+ },
117
+ );
104
118
 
105
119
  // Benchmark 2: Medium Records
106
- await benchmark.measureMemoryUsage("Medium Records (1KB)", 1000, async () => {
107
- for (let i = 0; i < 1000; i++) {
108
- await db.put(`medium:${i}`, {
109
- id: i,
110
- data: "x".repeat(1024),
111
- timestamp: Date.now(),
112
- metadata: { size: "medium", type: "test" },
113
- });
114
- }
115
- });
120
+ await benchmark.measureMemoryUsage(
121
+ "Medium Records (1KB)",
122
+ 1000,
123
+ async () => {
124
+ for (let i = 0; i < 1000; i++) {
125
+ await db.put(`medium:${i}`, {
126
+ id: i,
127
+ data: "x".repeat(1024),
128
+ timestamp: Date.now(),
129
+ metadata: { size: "medium", type: "test" },
130
+ });
131
+ }
132
+ },
133
+ );
116
134
 
117
135
  // Benchmark 3: Large Records
118
- await benchmark.measureMemoryUsage("Large Records (10KB)", 100, async () => {
119
- for (let i = 0; i < 100; i++) {
120
- await db.put(`large:${i}`, {
121
- id: i,
122
- data: "x".repeat(10 * 1024),
123
- timestamp: Date.now(),
124
- metadata: { size: "large", type: "test" },
125
- additional: "y".repeat(1024),
126
- });
127
- }
128
- });
136
+ await benchmark.measureMemoryUsage(
137
+ "Large Records (10KB)",
138
+ 100,
139
+ async () => {
140
+ for (let i = 0; i < 100; i++) {
141
+ await db.put(`large:${i}`, {
142
+ id: i,
143
+ data: "x".repeat(10 * 1024),
144
+ timestamp: Date.now(),
145
+ metadata: { size: "large", type: "test" },
146
+ additional: "y".repeat(1024),
147
+ });
148
+ }
149
+ },
150
+ );
129
151
 
130
152
  // Benchmark 4: Vector Data
131
- await benchmark.measureMemoryUsage("Vector Data (100 dimensions)", 500, async () => {
132
- for (let i = 0; i < 500; i++) {
133
- const vector = Array.from({ length: 100 }, () => Math.random());
134
- await db.put(`vector:${i}`, {
135
- id: i,
136
- text: `Document ${i} with vector data`,
137
- vector: vector,
138
- timestamp: Date.now(),
139
- });
140
- }
141
- });
153
+ await benchmark.measureMemoryUsage(
154
+ "Vector Data (100 dimensions)",
155
+ 500,
156
+ async () => {
157
+ for (let i = 0; i < 500; i++) {
158
+ const vector = Array.from({ length: 100 }, () => Math.random());
159
+ await db.put(`vector:${i}`, {
160
+ id: i,
161
+ text: `Document ${i} with vector data`,
162
+ vector: vector,
163
+ timestamp: Date.now(),
164
+ });
165
+ }
166
+ },
167
+ );
142
168
 
143
169
  // Benchmark 5: Nested Objects
144
170
  await benchmark.measureMemoryUsage("Nested Objects", 500, async () => {
@@ -181,9 +207,9 @@ async function runMemoryBenchmarks() {
181
207
 
182
208
  // Clean up subscriptions
183
209
  if ((globalThis as any).subscriptions) {
184
- ((globalThis as any).subscriptions as Array<() => void>).forEach((unsubscribe) =>
185
- unsubscribe(),
186
- );
210
+ ((globalThis as any).subscriptions as Array<() => void>).forEach((
211
+ unsubscribe,
212
+ ) => unsubscribe());
187
213
  delete (globalThis as any).subscriptions;
188
214
  }
189
215
 
@@ -251,7 +277,9 @@ async function runMemoryLeakTests() {
251
277
  const memoryIncrease = finalMemory - initialMemory;
252
278
 
253
279
  console.log(
254
- `Memory increase after subscription cycles: ${(memoryIncrease / 1024).toFixed(2)}KB`,
280
+ `Memory increase after subscription cycles: ${
281
+ (memoryIncrease / 1024).toFixed(2)
282
+ }KB`,
255
283
  );
256
284
 
257
285
  if (memoryIncrease > 1024 * 1024) {
@@ -269,7 +297,9 @@ async function runMemoryLeakTests() {
269
297
  // Perform many CRUD operations
270
298
  for (let cycle = 0; cycle < 100; cycle++) {
271
299
  for (let i = 0; i < 100; i++) {
272
- await db.put(`leak:${cycle}:${i}`, { data: `Cycle ${cycle} Item ${i}` });
300
+ await db.put(`leak:${cycle}:${i}`, {
301
+ data: `Cycle ${cycle} Item ${i}`,
302
+ });
273
303
  await db.get(`leak:${cycle}:${i}`);
274
304
  await db.delete(`leak:${cycle}:${i}`);
275
305
  }
@@ -283,7 +313,11 @@ async function runMemoryLeakTests() {
283
313
  const crudFinalMemory = (performance as any).memory?.usedJSHeapSize || 0;
284
314
  const crudMemoryIncrease = crudFinalMemory - crudInitialMemory;
285
315
 
286
- console.log(`Memory increase after CRUD cycles: ${(crudMemoryIncrease / 1024).toFixed(2)}KB`);
316
+ console.log(
317
+ `Memory increase after CRUD cycles: ${
318
+ (crudMemoryIncrease / 1024).toFixed(2)
319
+ }KB`,
320
+ );
287
321
 
288
322
  if (crudMemoryIncrease > 1024 * 1024) {
289
323
  // More than 1MB
@@ -46,7 +46,11 @@ class BenchmarkRunner {
46
46
  };
47
47
 
48
48
  this.results.push(result);
49
- console.log(` ✓ ${operationsPerSecond.toFixed(2)} ops/sec (${averageTime.toFixed(2)}ms avg)`);
49
+ console.log(
50
+ ` ✓ ${operationsPerSecond.toFixed(2)} ops/sec (${
51
+ averageTime.toFixed(2)
52
+ }ms avg)`,
53
+ );
50
54
 
51
55
  return result;
52
56
  }
@@ -63,7 +67,9 @@ class BenchmarkRunner {
63
67
  console.log(` Average Time: ${result.averageTime.toFixed(2)}ms`);
64
68
  console.log(` Operations/sec: ${result.operationsPerSecond.toFixed(2)}`);
65
69
  if (result.memoryUsage) {
66
- console.log(` Memory Usage: ${(result.memoryUsage / 1024 / 1024).toFixed(2)}MB`);
70
+ console.log(
71
+ ` Memory Usage: ${(result.memoryUsage / 1024 / 1024).toFixed(2)}MB`,
72
+ );
67
73
  }
68
74
  console.log();
69
75
  });
@@ -117,8 +123,10 @@ async function runCoreBenchmarks() {
117
123
  // First populate with documents
118
124
  for (let i = 0; i < 100; i++) {
119
125
  await db.put(`doc:${i}`, {
120
- text: `Document ${i} about machine learning and artificial intelligence`,
121
- content: `This is document number ${i} containing information about AI and ML algorithms`,
126
+ text:
127
+ `Document ${i} about machine learning and artificial intelligence`,
128
+ content:
129
+ `This is document number ${i} containing information about AI and ML algorithms`,
122
130
  });
123
131
  }
124
132
 
@@ -244,8 +252,14 @@ async function runMemoryBenchmarks() {
244
252
  const finalMemory = (performance as any).memory?.usedJSHeapSize || 0;
245
253
  const memoryIncrease = finalMemory - initialMemory;
246
254
 
247
- console.log(`Memory Usage: ${(memoryIncrease / 1024 / 1024).toFixed(2)}MB for 1000 records`);
248
- console.log(`Memory per record: ${(memoryIncrease / 1000).toFixed(2)} bytes`);
255
+ console.log(
256
+ `Memory Usage: ${
257
+ (memoryIncrease / 1024 / 1024).toFixed(2)
258
+ }MB for 1000 records`,
259
+ );
260
+ console.log(
261
+ `Memory per record: ${(memoryIncrease / 1000).toFixed(2)} bytes`,
262
+ );
249
263
 
250
264
  // Benchmark 2: Subscription Memory Usage
251
265
  const subscriptionMemory = (performance as any).memory?.usedJSHeapSize || 0;
@@ -257,13 +271,21 @@ async function runMemoryBenchmarks() {
257
271
  subscriptions.push(unsubscribe);
258
272
  });
259
273
 
260
- const afterSubscriptionMemory = (performance as any).memory?.usedJSHeapSize || 0;
261
- const subscriptionMemoryIncrease = afterSubscriptionMemory - subscriptionMemory;
274
+ const afterSubscriptionMemory =
275
+ (performance as any).memory?.usedJSHeapSize || 0;
276
+ const subscriptionMemoryIncrease = afterSubscriptionMemory -
277
+ subscriptionMemory;
262
278
 
263
279
  console.log(
264
- `Subscription Memory: ${(subscriptionMemoryIncrease / 1024).toFixed(2)}KB for 1000 subscriptions`,
280
+ `Subscription Memory: ${
281
+ (subscriptionMemoryIncrease / 1024).toFixed(2)
282
+ }KB for 1000 subscriptions`,
283
+ );
284
+ console.log(
285
+ `Memory per subscription: ${
286
+ (subscriptionMemoryIncrease / 1000).toFixed(2)
287
+ } bytes`,
265
288
  );
266
- console.log(`Memory per subscription: ${(subscriptionMemoryIncrease / 1000).toFixed(2)} bytes`);
267
289
 
268
290
  // Clean up subscriptions
269
291
  subscriptions.forEach((unsubscribe) => unsubscribe());