@j0hanz/memdb 1.0.6 → 1.0.8
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 +55 -26
- package/package.json +5 -6
- package/dist/core/database.d.ts +0 -4
- package/dist/core/database.d.ts.map +0 -1
- package/dist/core/database.js +0 -81
- package/dist/core/database.js.map +0 -1
- package/dist/core/db-helpers.d.ts +0 -10
- package/dist/core/db-helpers.d.ts.map +0 -1
- package/dist/core/db-helpers.js +0 -17
- package/dist/core/db-helpers.js.map +0 -1
- package/dist/core/db-worker-client.d.ts +0 -8
- package/dist/core/db-worker-client.d.ts.map +0 -1
- package/dist/core/db-worker-client.js +0 -67
- package/dist/core/db-worker-client.js.map +0 -1
- package/dist/core/db-worker-protocol.d.ts +0 -77
- package/dist/core/db-worker-protocol.d.ts.map +0 -1
- package/dist/core/db-worker-protocol.js +0 -2
- package/dist/core/db-worker-protocol.js.map +0 -1
- package/dist/core/db-worker.d.ts +0 -2
- package/dist/core/db-worker.d.ts.map +0 -1
- package/dist/core/db-worker.js +0 -73
- package/dist/core/db-worker.js.map +0 -1
- package/dist/core/memory-helpers.d.ts +0 -3
- package/dist/core/memory-helpers.d.ts.map +0 -1
- package/dist/core/memory-helpers.js +0 -18
- package/dist/core/memory-helpers.js.map +0 -1
- package/dist/core/memory-mappers.d.ts +0 -11
- package/dist/core/memory-mappers.d.ts.map +0 -1
- package/dist/core/memory-mappers.js +0 -52
- package/dist/core/memory-mappers.js.map +0 -1
- package/dist/core/memory-search.d.ts +0 -9
- package/dist/core/memory-search.d.ts.map +0 -1
- package/dist/core/memory-search.js +0 -46
- package/dist/core/memory-search.js.map +0 -1
- package/dist/core/memory-service-core.d.ts +0 -9
- package/dist/core/memory-service-core.d.ts.map +0 -1
- package/dist/core/memory-service-core.js +0 -229
- package/dist/core/memory-service-core.js.map +0 -1
- package/dist/core/memory-service.d.ts +0 -11
- package/dist/core/memory-service.d.ts.map +0 -1
- package/dist/core/memory-service.js +0 -83
- package/dist/core/memory-service.js.map +0 -1
- package/dist/core/memory-stats.d.ts +0 -3
- package/dist/core/memory-stats.d.ts.map +0 -1
- package/dist/core/memory-stats.js +0 -44
- package/dist/core/memory-stats.js.map +0 -1
- package/dist/core/memory-types.d.ts +0 -18
- package/dist/core/memory-types.d.ts.map +0 -1
- package/dist/core/memory-types.js +0 -2
- package/dist/core/memory-types.js.map +0 -1
- package/dist/core/memory-updates.d.ts +0 -11
- package/dist/core/memory-updates.d.ts.map +0 -1
- package/dist/core/memory-updates.js +0 -102
- package/dist/core/memory-updates.js.map +0 -1
- package/dist/core/relation-queries.d.ts +0 -8
- package/dist/core/relation-queries.d.ts.map +0 -1
- package/dist/core/relation-queries.js +0 -107
- package/dist/core/relation-queries.js.map +0 -1
- package/dist/core/row-mappers.d.ts +0 -7
- package/dist/core/row-mappers.d.ts.map +0 -1
- package/dist/core/row-mappers.js +0 -52
- package/dist/core/row-mappers.js.map +0 -1
- package/dist/core/search-errors.d.ts +0 -2
- package/dist/core/search-errors.d.ts.map +0 -1
- package/dist/core/search-errors.js +0 -21
- package/dist/core/search-errors.js.map +0 -1
- package/dist/core/search.d.ts +0 -9
- package/dist/core/search.d.ts.map +0 -1
- package/dist/core/search.js +0 -57
- package/dist/core/search.js.map +0 -1
- package/dist/core/tag-helpers.d.ts +0 -2
- package/dist/core/tag-helpers.d.ts.map +0 -1
- package/dist/core/tag-helpers.js +0 -22
- package/dist/core/tag-helpers.js.map +0 -1
- package/dist/index.d.ts +0 -3
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -131
- package/dist/index.js.map +0 -1
- package/dist/lib/errors.d.ts +0 -20
- package/dist/lib/errors.d.ts.map +0 -1
- package/dist/lib/errors.js +0 -20
- package/dist/lib/errors.js.map +0 -1
- package/dist/lib/tool_response.d.ts +0 -5
- package/dist/lib/tool_response.d.ts.map +0 -1
- package/dist/lib/tool_response.js +0 -7
- package/dist/lib/tool_response.js.map +0 -1
- package/dist/schemas/inputs.d.ts +0 -52
- package/dist/schemas/inputs.d.ts.map +0 -1
- package/dist/schemas/inputs.js +0 -134
- package/dist/schemas/inputs.js.map +0 -1
- package/dist/schemas/outputs.d.ts +0 -13
- package/dist/schemas/outputs.d.ts.map +0 -1
- package/dist/schemas/outputs.js +0 -15
- package/dist/schemas/outputs.js.map +0 -1
- package/dist/tools/delete-memory.d.ts +0 -3
- package/dist/tools/delete-memory.d.ts.map +0 -1
- package/dist/tools/delete-memory.js +0 -32
- package/dist/tools/delete-memory.js.map +0 -1
- package/dist/tools/get-memory.d.ts +0 -3
- package/dist/tools/get-memory.d.ts.map +0 -1
- package/dist/tools/get-memory.js +0 -32
- package/dist/tools/get-memory.js.map +0 -1
- package/dist/tools/get-related.d.ts +0 -3
- package/dist/tools/get-related.d.ts.map +0 -1
- package/dist/tools/get-related.js +0 -29
- package/dist/tools/get-related.js.map +0 -1
- package/dist/tools/index.d.ts +0 -3
- package/dist/tools/index.d.ts.map +0 -1
- package/dist/tools/index.js +0 -147
- package/dist/tools/index.js.map +0 -1
- package/dist/tools/link-memories.d.ts +0 -3
- package/dist/tools/link-memories.d.ts.map +0 -1
- package/dist/tools/link-memories.js +0 -29
- package/dist/tools/link-memories.js.map +0 -1
- package/dist/tools/memory-stats.d.ts +0 -3
- package/dist/tools/memory-stats.d.ts.map +0 -1
- package/dist/tools/memory-stats.js +0 -28
- package/dist/tools/memory-stats.js.map +0 -1
- package/dist/tools/search-memories.d.ts +0 -3
- package/dist/tools/search-memories.d.ts.map +0 -1
- package/dist/tools/search-memories.js +0 -29
- package/dist/tools/search-memories.js.map +0 -1
- package/dist/tools/store-memory.d.ts +0 -3
- package/dist/tools/store-memory.d.ts.map +0 -1
- package/dist/tools/store-memory.js +0 -29
- package/dist/tools/store-memory.js.map +0 -1
- package/dist/types/index.d.ts +0 -38
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -2
- package/dist/types/index.js.map +0 -1
- package/dist/utils/config.d.ts +0 -10
- package/dist/utils/config.d.ts.map +0 -1
- package/dist/utils/config.js +0 -75
- package/dist/utils/config.js.map +0 -1
- package/dist/utils/logger.d.ts +0 -10
- package/dist/utils/logger.d.ts.map +0 -1
- package/dist/utils/logger.js +0 -21
- package/dist/utils/logger.js.map +0 -1
- package/dist/utils/protocol.d.ts +0 -2
- package/dist/utils/protocol.d.ts.map +0 -1
- package/dist/utils/protocol.js +0 -7
- package/dist/utils/protocol.js.map +0 -1
package/README.md
CHANGED
|
@@ -80,9 +80,11 @@ Precedence: CLI flags > environment variables > defaults.
|
|
|
80
80
|
|
|
81
81
|
## Tool Response Format
|
|
82
82
|
|
|
83
|
-
All tools return structured JSON in
|
|
83
|
+
All tools return structured JSON in `structuredContent`. For backwards
|
|
84
|
+
compatibility, the first `content` item is a JSON string that matches
|
|
85
|
+
`structuredContent`.
|
|
84
86
|
|
|
85
|
-
Success:
|
|
87
|
+
Success (`structuredContent`):
|
|
86
88
|
|
|
87
89
|
```json
|
|
88
90
|
{
|
|
@@ -91,7 +93,7 @@ Success:
|
|
|
91
93
|
}
|
|
92
94
|
```
|
|
93
95
|
|
|
94
|
-
Error:
|
|
96
|
+
Error (`structuredContent`):
|
|
95
97
|
|
|
96
98
|
```json
|
|
97
99
|
{
|
|
@@ -103,6 +105,14 @@ Error:
|
|
|
103
105
|
}
|
|
104
106
|
```
|
|
105
107
|
|
|
108
|
+
Error responses also set `isError: true` on the top-level tool result.
|
|
109
|
+
|
|
110
|
+
Example `content[0].text`:
|
|
111
|
+
|
|
112
|
+
```text
|
|
113
|
+
{"ok":true,"result":{...}}
|
|
114
|
+
```
|
|
115
|
+
|
|
106
116
|
## Tools
|
|
107
117
|
|
|
108
118
|
### `store_memory`
|
|
@@ -168,6 +178,11 @@ Create a relationship between two memories.
|
|
|
168
178
|
|
|
169
179
|
**Returns:** `{ linked: true }`.
|
|
170
180
|
|
|
181
|
+
Notes:
|
|
182
|
+
|
|
183
|
+
- Linking the same relation again is a no-op (idempotent).
|
|
184
|
+
- Returns an error if either memory hash does not exist.
|
|
185
|
+
|
|
171
186
|
### `get_related`
|
|
172
187
|
|
|
173
188
|
Get memories related to a given memory.
|
|
@@ -268,27 +283,29 @@ Add to your `claude_desktop_config.json`:
|
|
|
268
283
|
|
|
269
284
|
## Limits & Constraints
|
|
270
285
|
|
|
271
|
-
| Constraint | Value | Description
|
|
272
|
-
| :---------------------------- | :------------ |
|
|
273
|
-
| **Max content length** | 100,000 chars | Maximum characters in memory content
|
|
274
|
-
| **Max query length** | 1,000 chars | Maximum characters in search query
|
|
275
|
-
| **Max search
|
|
276
|
-
| **
|
|
277
|
-
| **
|
|
278
|
-
| **Max
|
|
279
|
-
| **Max
|
|
280
|
-
| **Max
|
|
281
|
-
| **Max
|
|
282
|
-
| **Max
|
|
283
|
-
| **
|
|
284
|
-
| **
|
|
285
|
-
| **
|
|
286
|
-
| **
|
|
286
|
+
| Constraint | Value | Description |
|
|
287
|
+
| :---------------------------- | :------------ | :---------------------------------------------------------------------------- |
|
|
288
|
+
| **Max content length** | 100,000 chars | Maximum characters in memory content |
|
|
289
|
+
| **Max query length** | 1,000 chars | Maximum characters in search query |
|
|
290
|
+
| **Max search terms** | 50 | Maximum whitespace-separated terms per query |
|
|
291
|
+
| **Max search results** | 100 | Maximum results returned from `search_memories` |
|
|
292
|
+
| **Default search limit** | 10 | Default `limit` for `search_memories` |
|
|
293
|
+
| **Max search offset** | 1,000 | Maximum `offset` for `search_memories` |
|
|
294
|
+
| **Max tags per memory** | 100 | Maximum number of tags when storing a memory |
|
|
295
|
+
| **Max tag length** | 50 chars | Maximum characters per tag |
|
|
296
|
+
| **Max tags in search filter** | 50 | Maximum tags when filtering search results |
|
|
297
|
+
| **Max related memories** | 1,000 | Maximum results from `get_related` queries |
|
|
298
|
+
| **Max traversal depth** | 3 | Maximum depth for relationship traversal |
|
|
299
|
+
| **Importance range** | 0-10 | Allowed range for `importance` |
|
|
300
|
+
| **Min relevance range** | 0-1 | Allowed range for `minRelevance` |
|
|
301
|
+
| **Hash length** | 32 chars | MD5 hash length |
|
|
302
|
+
| **Search mode** | Tokenized OR | Whitespace-split terms are quoted and OR'ed; FTS5 operators are not supported |
|
|
287
303
|
|
|
288
304
|
### Notes
|
|
289
305
|
|
|
290
306
|
- **Content deduplication**: Memories are deduplicated using MD5 hashes.
|
|
291
307
|
- **Search errors**: If FTS5 is unavailable, `search_memories` returns an error indicating the index is missing. Invalid query syntax returns an error with details.
|
|
308
|
+
- **Search tokenization**: Queries are split on whitespace (max 50 terms); whitespace-only queries are rejected.
|
|
292
309
|
- **Tag behavior**: Tags are de-duplicated per memory; exceeding tag limits throws an error.
|
|
293
310
|
- **Bidirectional depth**: `get_related` with `direction: "both"` caps traversal depth at 2.
|
|
294
311
|
- **Local storage**: All data is stored locally in `.memdb/memory.db` unless `:memory:` is used.
|
|
@@ -314,21 +331,33 @@ Add to your `claude_desktop_config.json`:
|
|
|
314
331
|
| `npm run format:check` | Check code formatting |
|
|
315
332
|
| `npm run type-check` | TypeScript type checking |
|
|
316
333
|
| `npm run type-check:test` | Type-check tests only |
|
|
317
|
-
| `npm run maintainability` | Generate maintainability report |
|
|
318
334
|
| `npm run duplication` | Run duplication report (jscpd) |
|
|
319
|
-
| `npm run bench:memory` | Run memory-service benchmark |
|
|
320
335
|
| `npm run inspector` | Run MCP inspector |
|
|
321
336
|
|
|
322
337
|
### Project Structure
|
|
323
338
|
|
|
324
339
|
```text
|
|
325
340
|
src/
|
|
326
|
-
|-- index.ts #
|
|
327
|
-
|-- core/ #
|
|
328
|
-
|--
|
|
341
|
+
|-- index.ts # Server entry point (stdio transport)
|
|
342
|
+
|-- core/ # SQLite setup + memory CRUD/search/relations
|
|
343
|
+
| |-- database.ts # DB init + schema sync
|
|
344
|
+
| |-- memory-create.ts
|
|
345
|
+
| |-- memory-read.ts
|
|
346
|
+
| |-- memory-search.ts
|
|
347
|
+
| |-- memory-relations.ts
|
|
348
|
+
| |-- memory-updates.ts
|
|
349
|
+
| |-- memory-stats.ts
|
|
350
|
+
|-- tools/ # Tool registration + handlers
|
|
351
|
+
| |-- definitions/ # Tool metadata + handlers
|
|
329
352
|
|-- schemas/ # Zod input/output schemas
|
|
330
|
-
|--
|
|
331
|
-
|
|
353
|
+
| |-- inputs.ts
|
|
354
|
+
| |-- outputs.ts
|
|
355
|
+
|-- lib/ # Error/response helpers
|
|
356
|
+
|-- types/ # TypeScript types
|
|
357
|
+
`-- utils/ # Config + logger
|
|
358
|
+
|
|
359
|
+
tests/
|
|
360
|
+
`-- *.test.ts # Node.js test runner tests
|
|
332
361
|
```
|
|
333
362
|
|
|
334
363
|
## Contributing
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@j0hanz/memdb",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"mcpName": "io.github.j0hanz/memdb",
|
|
5
5
|
"description": "A memory-based MCP server using SQLite in-memory database.",
|
|
6
6
|
"type": "module",
|
|
@@ -19,14 +19,12 @@
|
|
|
19
19
|
],
|
|
20
20
|
"scripts": {
|
|
21
21
|
"clean": "node -e \"require('fs').rmSync('dist', {recursive: true, force: true})\"",
|
|
22
|
-
"build": "tsc",
|
|
22
|
+
"build": "npm run clean && tsc",
|
|
23
23
|
"dev": "tsx watch src/index.ts",
|
|
24
24
|
"start": "node dist/index.js",
|
|
25
25
|
"test": "node --import tsx/esm --test tests/*.test.ts",
|
|
26
26
|
"test:coverage": "node --import tsx/esm --test --experimental-test-coverage tests/*.test.ts",
|
|
27
|
-
"maintainability": "node --import tsx/esm scripts/maintainability.ts --dir src --output reports/maintainability.json --threshold 65",
|
|
28
27
|
"duplication": "npx --yes jscpd -k 50 -f typescript -r json -o .jscpd src",
|
|
29
|
-
"bench:memory": "node --expose-gc --import tsx/esm benchmark/memory-service.bench.ts",
|
|
30
28
|
"lint": "eslint .",
|
|
31
29
|
"format": "prettier --write .",
|
|
32
30
|
"format:check": "prettier --check .",
|
|
@@ -51,7 +49,7 @@
|
|
|
51
49
|
"license": "MIT",
|
|
52
50
|
"dependencies": {
|
|
53
51
|
"@modelcontextprotocol/sdk": "^1.25.1",
|
|
54
|
-
"zod": "^4.3.
|
|
52
|
+
"zod": "^4.3.5"
|
|
55
53
|
},
|
|
56
54
|
"devDependencies": {
|
|
57
55
|
"@eslint/js": "^9.39.2",
|
|
@@ -59,11 +57,12 @@
|
|
|
59
57
|
"@types/node": "^22.19.3",
|
|
60
58
|
"eslint": "^9.39.2",
|
|
61
59
|
"eslint-config-prettier": "^10.1.8",
|
|
60
|
+
"eslint-plugin-sonarjs": "^3.0.5",
|
|
62
61
|
"eslint-plugin-unused-imports": "^4.3.0",
|
|
63
62
|
"prettier": "^3.7.4",
|
|
64
63
|
"tsx": "^4.21.0",
|
|
65
64
|
"typescript": "^5.9.3",
|
|
66
|
-
"typescript-eslint": "^8.
|
|
65
|
+
"typescript-eslint": "^8.52.0"
|
|
67
66
|
},
|
|
68
67
|
"engines": {
|
|
69
68
|
"node": ">=22.0.0"
|
package/dist/core/database.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../src/core/database.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AA0E3C,eAAO,MAAM,EAAE,cAAqD,CAAC;AAUrE,eAAO,MAAM,OAAO,QAAO,IAG1B,CAAC"}
|
package/dist/core/database.js
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { mkdir } from 'node:fs/promises';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { DatabaseSync } from 'node:sqlite';
|
|
4
|
-
import { config } from '../utils/config.js';
|
|
5
|
-
const SCHEMA_SQL = `
|
|
6
|
-
PRAGMA foreign_keys = ON;
|
|
7
|
-
PRAGMA journal_mode = WAL;
|
|
8
|
-
PRAGMA synchronous = NORMAL;
|
|
9
|
-
|
|
10
|
-
CREATE TABLE IF NOT EXISTS memories (
|
|
11
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
12
|
-
content TEXT NOT NULL,
|
|
13
|
-
summary TEXT,
|
|
14
|
-
importance INTEGER DEFAULT 0,
|
|
15
|
-
memory_type TEXT DEFAULT 'general',
|
|
16
|
-
created_at TEXT DEFAULT CURRENT_TIMESTAMP,
|
|
17
|
-
accessed_at TEXT DEFAULT CURRENT_TIMESTAMP,
|
|
18
|
-
hash TEXT UNIQUE NOT NULL
|
|
19
|
-
) STRICT;
|
|
20
|
-
|
|
21
|
-
CREATE TABLE IF NOT EXISTS tags (
|
|
22
|
-
memory_id INTEGER NOT NULL,
|
|
23
|
-
tag TEXT NOT NULL,
|
|
24
|
-
PRIMARY KEY (memory_id, tag),
|
|
25
|
-
FOREIGN KEY (memory_id) REFERENCES memories(id) ON DELETE CASCADE
|
|
26
|
-
) STRICT;
|
|
27
|
-
|
|
28
|
-
CREATE INDEX IF NOT EXISTS idx_tags_tag_memory_id ON tags(tag, memory_id);
|
|
29
|
-
|
|
30
|
-
CREATE TABLE IF NOT EXISTS relationships (
|
|
31
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
32
|
-
from_memory_id INTEGER NOT NULL,
|
|
33
|
-
to_memory_id INTEGER NOT NULL,
|
|
34
|
-
relation_type TEXT NOT NULL,
|
|
35
|
-
created_at TEXT DEFAULT CURRENT_TIMESTAMP,
|
|
36
|
-
FOREIGN KEY (from_memory_id) REFERENCES memories(id) ON DELETE CASCADE,
|
|
37
|
-
FOREIGN KEY (to_memory_id) REFERENCES memories(id) ON DELETE CASCADE,
|
|
38
|
-
UNIQUE(from_memory_id, to_memory_id, relation_type)
|
|
39
|
-
) STRICT;
|
|
40
|
-
|
|
41
|
-
CREATE INDEX IF NOT EXISTS idx_relationships_to_memory_id ON relationships(to_memory_id);
|
|
42
|
-
|
|
43
|
-
CREATE VIRTUAL TABLE IF NOT EXISTS memories_fts USING fts5(
|
|
44
|
-
content,
|
|
45
|
-
summary,
|
|
46
|
-
content_rowid='id'
|
|
47
|
-
);
|
|
48
|
-
|
|
49
|
-
CREATE TRIGGER IF NOT EXISTS memories_ai AFTER INSERT ON memories BEGIN
|
|
50
|
-
INSERT INTO memories_fts(rowid, content, summary)
|
|
51
|
-
VALUES (new.id, new.content, new.summary);
|
|
52
|
-
END;
|
|
53
|
-
|
|
54
|
-
CREATE TRIGGER IF NOT EXISTS memories_au AFTER UPDATE ON memories BEGIN
|
|
55
|
-
DELETE FROM memories_fts WHERE rowid = old.id;
|
|
56
|
-
INSERT INTO memories_fts(rowid, content, summary)
|
|
57
|
-
VALUES (new.id, new.content, new.summary);
|
|
58
|
-
END;
|
|
59
|
-
|
|
60
|
-
CREATE TRIGGER IF NOT EXISTS memories_ad AFTER DELETE ON memories BEGIN
|
|
61
|
-
DELETE FROM memories_fts WHERE rowid = old.id;
|
|
62
|
-
END;
|
|
63
|
-
`;
|
|
64
|
-
const FTS_SYNC_SQL = `
|
|
65
|
-
INSERT INTO memories_fts(rowid, content, summary)
|
|
66
|
-
SELECT id, content, summary FROM memories
|
|
67
|
-
WHERE id NOT IN (SELECT rowid FROM memories_fts);
|
|
68
|
-
`;
|
|
69
|
-
if (config.dbPath !== ':memory:') {
|
|
70
|
-
await mkdir(path.dirname(config.dbPath), { recursive: true });
|
|
71
|
-
}
|
|
72
|
-
export const db = new DatabaseSync(config.dbPath, { timeout: 5000 });
|
|
73
|
-
db.enableDefensive?.(true);
|
|
74
|
-
db.exec(SCHEMA_SQL);
|
|
75
|
-
db.exec(FTS_SYNC_SQL);
|
|
76
|
-
export const closeDb = () => {
|
|
77
|
-
if (!db.isOpen)
|
|
78
|
-
return;
|
|
79
|
-
db.close();
|
|
80
|
-
};
|
|
81
|
-
//# sourceMappingURL=database.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"database.js","sourceRoot":"","sources":["../../src/core/database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,MAAM,UAAU,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0DlB,CAAC;AAEF,MAAM,YAAY,GAAG;;;;CAIpB,CAAC;AAEF,IAAI,MAAM,CAAC,MAAM,KAAK,UAAU,EAAE,CAAC;IACjC,MAAM,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;AAChE,CAAC;AAED,MAAM,CAAC,MAAM,EAAE,GAAG,IAAI,YAAY,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;AAEnE,EAGD,CAAC,eAAe,EAAE,CAAC,IAAI,CAAC,CAAC;AAE1B,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;AACpB,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;AAEtB,MAAM,CAAC,MAAM,OAAO,GAAG,GAAS,EAAE;IAChC,IAAI,CAAC,EAAE,CAAC,MAAM;QAAE,OAAO;IACvB,EAAE,CAAC,KAAK,EAAE,CAAC;AACb,CAAC,CAAC"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { StatementSync } from 'node:sqlite';
|
|
2
|
-
import type { DbRow } from './row-mappers.js';
|
|
3
|
-
export type SqlParam = string | number | bigint | null | Uint8Array;
|
|
4
|
-
export declare const executeAll: (stmt: StatementSync, ...params: SqlParam[]) => DbRow[];
|
|
5
|
-
export declare const executeGet: (stmt: StatementSync, ...params: SqlParam[]) => DbRow | undefined;
|
|
6
|
-
export declare const executeRun: (stmt: StatementSync, ...params: SqlParam[]) => {
|
|
7
|
-
changes: number | bigint;
|
|
8
|
-
};
|
|
9
|
-
export declare const withImmediateTransaction: <T>(operation: () => T) => T;
|
|
10
|
-
//# sourceMappingURL=db-helpers.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"db-helpers.d.ts","sourceRoot":"","sources":["../../src/core/db-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAGjD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAE9C,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,UAAU,CAAC;AAEpE,eAAO,MAAM,UAAU,GACrB,MAAM,aAAa,EACnB,GAAG,QAAQ,QAAQ,EAAE,KACpB,KAAK,EAAoC,CAAC;AAE7C,eAAO,MAAM,UAAU,GACrB,MAAM,aAAa,EACnB,GAAG,QAAQ,QAAQ,EAAE,KACpB,KAAK,GAAG,SAAqD,CAAC;AAEjE,eAAO,MAAM,UAAU,GACrB,MAAM,aAAa,EACnB,GAAG,QAAQ,QAAQ,EAAE,KACpB;IAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAAA;CAG1B,CAAC;AAEJ,eAAO,MAAM,wBAAwB,GAAI,CAAC,EAAE,WAAW,MAAM,CAAC,KAAG,CAUhE,CAAC"}
|
package/dist/core/db-helpers.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { db } from './database.js';
|
|
2
|
-
export const executeAll = (stmt, ...params) => stmt.all(...params);
|
|
3
|
-
export const executeGet = (stmt, ...params) => stmt.get(...params);
|
|
4
|
-
export const executeRun = (stmt, ...params) => stmt.run(...params);
|
|
5
|
-
export const withImmediateTransaction = (operation) => {
|
|
6
|
-
db.exec('BEGIN IMMEDIATE');
|
|
7
|
-
try {
|
|
8
|
-
const result = operation();
|
|
9
|
-
db.exec('COMMIT');
|
|
10
|
-
return result;
|
|
11
|
-
}
|
|
12
|
-
catch (err) {
|
|
13
|
-
db.exec('ROLLBACK');
|
|
14
|
-
throw err;
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
//# sourceMappingURL=db-helpers.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"db-helpers.js","sourceRoot":"","sources":["../../src/core/db-helpers.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,EAAE,EAAE,MAAM,eAAe,CAAC;AAKnC,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,IAAmB,EACnB,GAAG,MAAkB,EACZ,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,MAAM,CAAY,CAAC;AAE7C,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,IAAmB,EACnB,GAAG,MAAkB,EACF,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,MAAM,CAAsB,CAAC;AAEjE,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,IAAmB,EACnB,GAAG,MAAkB,EACS,EAAE,CAChC,IAAI,CAAC,GAAG,CAAC,GAAG,MAAM,CAEjB,CAAC;AAEJ,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAI,SAAkB,EAAK,EAAE;IACnE,EAAE,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;IAC3B,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;QAC3B,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAClB,OAAO,MAAM,CAAC;IAChB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACpB,MAAM,GAAG,CAAC;IACZ,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { DbWorkerCallMap } from './db-worker-protocol.js';
|
|
2
|
-
type PayloadFor<K extends keyof DbWorkerCallMap> = DbWorkerCallMap[K]['payload'];
|
|
3
|
-
type ResultFor<K extends keyof DbWorkerCallMap> = DbWorkerCallMap[K]['result'];
|
|
4
|
-
type ArgsFor<K extends keyof DbWorkerCallMap> = undefined extends PayloadFor<K> ? [payload?: PayloadFor<K>] : [payload: PayloadFor<K>];
|
|
5
|
-
export declare const callDbWorker: <K extends keyof DbWorkerCallMap>(type: K, ...args: ArgsFor<K>) => Promise<ResultFor<K>>;
|
|
6
|
-
export declare const closeDbWorker: () => Promise<void>;
|
|
7
|
-
export {};
|
|
8
|
-
//# sourceMappingURL=db-worker-client.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"db-worker-client.d.ts","sourceRoot":"","sources":["../../src/core/db-worker-client.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,eAAe,EAGhB,MAAM,yBAAyB,CAAC;AAOjC,KAAK,UAAU,CAAC,CAAC,SAAS,MAAM,eAAe,IAC7C,eAAe,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;AAChC,KAAK,SAAS,CAAC,CAAC,SAAS,MAAM,eAAe,IAAI,eAAe,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;AAC/E,KAAK,OAAO,CAAC,CAAC,SAAS,MAAM,eAAe,IAC1C,SAAS,SAAS,UAAU,CAAC,CAAC,CAAC,GAC3B,CAAC,OAAO,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,GACzB,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AAkE/B,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,MAAM,eAAe,EAC1D,MAAM,CAAC,EACP,GAAG,MAAM,OAAO,CAAC,CAAC,CAAC,KAClB,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAGtB,CAAC;AAEF,eAAO,MAAM,aAAa,QAAa,OAAO,CAAC,IAAI,CAUlD,CAAC"}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import process from 'node:process';
|
|
2
|
-
import { Worker } from 'node:worker_threads';
|
|
3
|
-
let worker;
|
|
4
|
-
let nextId = 1;
|
|
5
|
-
const pending = new Map();
|
|
6
|
-
const rejectAll = (error) => {
|
|
7
|
-
for (const entry of pending.values()) {
|
|
8
|
-
entry.reject(error);
|
|
9
|
-
}
|
|
10
|
-
pending.clear();
|
|
11
|
-
};
|
|
12
|
-
const handleMessage = (message) => {
|
|
13
|
-
const entry = pending.get(message.id);
|
|
14
|
-
if (!entry)
|
|
15
|
-
return;
|
|
16
|
-
pending.delete(message.id);
|
|
17
|
-
if (message.ok) {
|
|
18
|
-
entry.resolve(message.result);
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
entry.reject(new Error(message.error.message));
|
|
22
|
-
};
|
|
23
|
-
const createWorker = () => {
|
|
24
|
-
const workerUrl = new URL(import.meta.url.endsWith('.ts') ? './db-worker.ts' : './db-worker.js', import.meta.url);
|
|
25
|
-
const instance = new Worker(workerUrl, { execArgv: process.execArgv });
|
|
26
|
-
instance.on('message', handleMessage);
|
|
27
|
-
instance.on('error', (error) => {
|
|
28
|
-
rejectAll(error);
|
|
29
|
-
});
|
|
30
|
-
instance.on('exit', (code) => {
|
|
31
|
-
if (code !== 0) {
|
|
32
|
-
rejectAll(new Error(`DB worker exited with code ${String(code)}`));
|
|
33
|
-
}
|
|
34
|
-
if (worker === instance) {
|
|
35
|
-
worker = undefined;
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
return instance;
|
|
39
|
-
};
|
|
40
|
-
const getWorker = () => {
|
|
41
|
-
worker ??= createWorker();
|
|
42
|
-
return worker;
|
|
43
|
-
};
|
|
44
|
-
const sendRequest = (instance, type, payload) => new Promise((resolve, reject) => {
|
|
45
|
-
const id = nextId++;
|
|
46
|
-
pending.set(id, { resolve: resolve, reject });
|
|
47
|
-
const request = (payload === undefined ? { id, type } : { id, type, payload });
|
|
48
|
-
instance.postMessage(request);
|
|
49
|
-
});
|
|
50
|
-
export const callDbWorker = (type, ...args) => {
|
|
51
|
-
const payload = args[0];
|
|
52
|
-
return sendRequest(getWorker(), type, payload);
|
|
53
|
-
};
|
|
54
|
-
export const closeDbWorker = async () => {
|
|
55
|
-
if (!worker)
|
|
56
|
-
return;
|
|
57
|
-
const instance = worker;
|
|
58
|
-
try {
|
|
59
|
-
await sendRequest(instance, 'close');
|
|
60
|
-
}
|
|
61
|
-
finally {
|
|
62
|
-
worker = undefined;
|
|
63
|
-
rejectAll(new Error('DB worker closed'));
|
|
64
|
-
await instance.terminate();
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
//# sourceMappingURL=db-worker-client.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"db-worker-client.js","sourceRoot":"","sources":["../../src/core/db-worker-client.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAqB7C,IAAI,MAA0B,CAAC;AAC/B,IAAI,MAAM,GAAG,CAAC,CAAC;AACf,MAAM,OAAO,GAAG,IAAI,GAAG,EAA0B,CAAC;AAElD,MAAM,SAAS,GAAG,CAAC,KAAY,EAAQ,EAAE;IACvC,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;QACrC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACtB,CAAC;IACD,OAAO,CAAC,KAAK,EAAE,CAAC;AAClB,CAAC,CAAC;AAEF,MAAM,aAAa,GAAG,CAAC,OAAyB,EAAQ,EAAE;IACxD,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IACtC,IAAI,CAAC,KAAK;QAAE,OAAO;IACnB,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAC3B,IAAI,OAAO,CAAC,EAAE,EAAE,CAAC;QACf,KAAK,CAA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B,QAAgB,EAChB,IAAO,EACP,OAAuB,EACA,EAAE,CACzB,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;IAC9B,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC;IACpB,OAAO,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,OAAO,EAAE,OAAmC,EAAE,MAAM,EAAE,CAAC,CAAC;IAC1E,MAAM,OAAO,GAAG,CACd,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAC1C,CAAC;IACrB,QAAQ,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;AAChC,CAAC,CAAC,CAAC;AAEL,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,IAAO,EACP,GAAG,IAAgB,EACI,EAAE;IACzB,MAAM,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IACxB,OAAO,WAAW,CAAC,SAAS,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;AACjD,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,IAAmB,EAAE;IACrD,IAAI,CAAC,MAAM;QAAE,OAAO;IACpB,MAAM,QAAQ,GAAG,MAAM,CAAC;IACxB,IAAI,CAAC;QACH,MAAM,WAAW,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACvC,CAAC;YAAS,CAAC;QACT,MAAM,GAAG,SAAS,CAAC;QACnB,SAAS,CAAC,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC,CAAC;QACzC,MAAM,QAAQ,CAAC,SAAS,EAAE,CAAC;IAC7B,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import type { Memory, MemoryInsertResult, MemoryStats, RelatedMemory, SearchResult, StatementResult } from '../types/index.js';
|
|
2
|
-
export interface DbWorkerCallMap {
|
|
3
|
-
createMemory: {
|
|
4
|
-
payload: {
|
|
5
|
-
content: string;
|
|
6
|
-
tags: readonly string[];
|
|
7
|
-
importance: number;
|
|
8
|
-
memoryType: string;
|
|
9
|
-
};
|
|
10
|
-
result: MemoryInsertResult;
|
|
11
|
-
};
|
|
12
|
-
searchMemories: {
|
|
13
|
-
payload: {
|
|
14
|
-
query: string;
|
|
15
|
-
limit: number;
|
|
16
|
-
tags: readonly string[];
|
|
17
|
-
minRelevance?: number;
|
|
18
|
-
};
|
|
19
|
-
result: SearchResult[];
|
|
20
|
-
};
|
|
21
|
-
getMemory: {
|
|
22
|
-
payload: {
|
|
23
|
-
hash: string;
|
|
24
|
-
};
|
|
25
|
-
result: Memory | undefined;
|
|
26
|
-
};
|
|
27
|
-
deleteMemory: {
|
|
28
|
-
payload: {
|
|
29
|
-
hash: string;
|
|
30
|
-
};
|
|
31
|
-
result: StatementResult;
|
|
32
|
-
};
|
|
33
|
-
linkMemories: {
|
|
34
|
-
payload: {
|
|
35
|
-
fromHash: string;
|
|
36
|
-
toHash: string;
|
|
37
|
-
relationType: string;
|
|
38
|
-
};
|
|
39
|
-
result: StatementResult;
|
|
40
|
-
};
|
|
41
|
-
getRelated: {
|
|
42
|
-
payload: {
|
|
43
|
-
hash: string;
|
|
44
|
-
relationType?: string;
|
|
45
|
-
depth: number;
|
|
46
|
-
};
|
|
47
|
-
result: RelatedMemory[];
|
|
48
|
-
};
|
|
49
|
-
getStats: {
|
|
50
|
-
payload: undefined;
|
|
51
|
-
result: MemoryStats;
|
|
52
|
-
};
|
|
53
|
-
close: {
|
|
54
|
-
payload: undefined;
|
|
55
|
-
result: undefined;
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
export type DbWorkerRequest = {
|
|
59
|
-
[K in keyof DbWorkerCallMap]: {
|
|
60
|
-
id: number;
|
|
61
|
-
type: K;
|
|
62
|
-
} & (DbWorkerCallMap[K]['payload'] extends undefined ? Record<string, never> : {
|
|
63
|
-
payload: DbWorkerCallMap[K]['payload'];
|
|
64
|
-
});
|
|
65
|
-
}[keyof DbWorkerCallMap];
|
|
66
|
-
export type DbWorkerResponse = {
|
|
67
|
-
id: number;
|
|
68
|
-
ok: true;
|
|
69
|
-
result: unknown;
|
|
70
|
-
} | {
|
|
71
|
-
id: number;
|
|
72
|
-
ok: false;
|
|
73
|
-
error: {
|
|
74
|
-
message: string;
|
|
75
|
-
};
|
|
76
|
-
};
|
|
77
|
-
//# sourceMappingURL=db-worker-protocol.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"db-worker-protocol.d.ts","sourceRoot":"","sources":["../../src/core/db-worker-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,MAAM,EACN,kBAAkB,EAClB,WAAW,EACX,aAAa,EACb,YAAY,EACZ,eAAe,EAChB,MAAM,mBAAmB,CAAC;AAE3B,MAAM,WAAW,eAAe;IAC9B,YAAY,EAAE;QACZ,OAAO,EAAE;YACP,OAAO,EAAE,MAAM,CAAC;YAChB,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;YACxB,UAAU,EAAE,MAAM,CAAC;YACnB,UAAU,EAAE,MAAM,CAAC;SACpB,CAAC;QACF,MAAM,EAAE,kBAAkB,CAAC;KAC5B,CAAC;IACF,cAAc,EAAE;QACd,OAAO,EAAE;YACP,KAAK,EAAE,MAAM,CAAC;YACd,KAAK,EAAE,MAAM,CAAC;YACd,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;YACxB,YAAY,CAAC,EAAE,MAAM,CAAC;SACvB,CAAC;QACF,MAAM,EAAE,YAAY,EAAE,CAAC;KACxB,CAAC;IACF,SAAS,EAAE;QACT,OAAO,EAAE;YAAE,IAAI,EAAE,MAAM,CAAA;SAAE,CAAC;QAC1B,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;KAC5B,CAAC;IACF,YAAY,EAAE;QACZ,OAAO,EAAE;YAAE,IAAI,EAAE,MAAM,CAAA;SAAE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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"db-worker-protocol.js","sourceRoot":"","sources":["../../src/core/db-worker-protocol.ts"],"names":[],"mappings":""}
|
package/dist/core/db-worker.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"db-worker.d.ts","sourceRoot":"","sources":["../../src/core/db-worker.ts"],"names":[],"mappings":""}
|
package/dist/core/db-worker.js
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { parentPort } from 'node:worker_threads';
|
|
2
|
-
import { closeDb } from './database.js';
|
|
3
|
-
import { createMemory, deleteMemory, getMemory, getRelated, getStats, linkMemories, searchMemories, } from './memory-service-core.js';
|
|
4
|
-
const port = parentPort;
|
|
5
|
-
if (!port) {
|
|
6
|
-
throw new Error('db-worker must be started as a worker thread');
|
|
7
|
-
}
|
|
8
|
-
const respond = (response) => {
|
|
9
|
-
port.postMessage(response);
|
|
10
|
-
};
|
|
11
|
-
const handleRequest = (request) => {
|
|
12
|
-
try {
|
|
13
|
-
switch (request.type) {
|
|
14
|
-
case 'createMemory': {
|
|
15
|
-
const { content, tags, importance, memoryType } = request.payload;
|
|
16
|
-
return {
|
|
17
|
-
id: request.id,
|
|
18
|
-
ok: true,
|
|
19
|
-
result: createMemory(content, tags, importance, memoryType),
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
case 'searchMemories': {
|
|
23
|
-
const { query, limit, tags, minRelevance } = request.payload;
|
|
24
|
-
return {
|
|
25
|
-
id: request.id,
|
|
26
|
-
ok: true,
|
|
27
|
-
result: searchMemories(query, limit, tags, minRelevance),
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
case 'getMemory':
|
|
31
|
-
return {
|
|
32
|
-
id: request.id,
|
|
33
|
-
ok: true,
|
|
34
|
-
result: getMemory(request.payload.hash),
|
|
35
|
-
};
|
|
36
|
-
case 'deleteMemory':
|
|
37
|
-
return {
|
|
38
|
-
id: request.id,
|
|
39
|
-
ok: true,
|
|
40
|
-
result: deleteMemory(request.payload.hash),
|
|
41
|
-
};
|
|
42
|
-
case 'linkMemories': {
|
|
43
|
-
const { fromHash, toHash, relationType } = request.payload;
|
|
44
|
-
return {
|
|
45
|
-
id: request.id,
|
|
46
|
-
ok: true,
|
|
47
|
-
result: linkMemories(fromHash, toHash, relationType),
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
case 'getRelated': {
|
|
51
|
-
const { hash, relationType, depth } = request.payload;
|
|
52
|
-
return {
|
|
53
|
-
id: request.id,
|
|
54
|
-
ok: true,
|
|
55
|
-
result: getRelated(hash, relationType, depth),
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
case 'getStats':
|
|
59
|
-
return { id: request.id, ok: true, result: getStats() };
|
|
60
|
-
case 'close':
|
|
61
|
-
closeDb();
|
|
62
|
-
return { id: request.id, ok: true, result: undefined };
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
catch (err) {
|
|
66
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
67
|
-
return { id: request.id, ok: false, error: { message } };
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
port.on('message', (request) => {
|
|
71
|
-
respond(handleRequest(request));
|
|
72
|
-
});
|
|
73
|
-
//# sourceMappingURL=db-worker.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"db-worker.js","sourceRoot":"","sources":["../../src/core/db-worker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAKxC,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,SAAS,EACT,UAAU,EACV,QAAQ,EACR,YAAY,EACZ,cAAc,GACf,MAAM,0BAA0B,CAAC;AAElC,MAAM,IAAI,GAAG,UAAU,CAAC;AACxB,IAAI,CAAC,IAAI,EAAE,CAAC;IACV,MAAM,IAAI,KAAK,CAA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C,OAAwB,EAAE,EAAE;IAC9C,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC;AAClC,CAAC,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"memory-helpers.d.ts","sourceRoot":"","sources":["../../src/core/memory-helpers.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,kBAAkB,GAAI,MAAM,MAAM,KAAG,MAAM,GAAG,SAO1D,CAAC;AAEF,eAAO,MAAM,UAAU,GAAI,UAAU,MAAM,EAAE,MAAM,SAAS,MAAM,EAAE,KAAG,IAQtE,CAAC"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { db } from './database.js';
|
|
2
|
-
import { executeGet, executeRun } from './db-helpers.js';
|
|
3
|
-
import { toSafeInteger } from './row-mappers.js';
|
|
4
|
-
export const findMemoryIdByHash = (hash) => {
|
|
5
|
-
const row = executeGet(db.prepare('SELECT id FROM memories WHERE hash = ?'), hash);
|
|
6
|
-
if (!row)
|
|
7
|
-
return undefined;
|
|
8
|
-
return toSafeInteger(row.id, 'id');
|
|
9
|
-
};
|
|
10
|
-
export const insertTags = (memoryId, tags) => {
|
|
11
|
-
if (tags.length === 0)
|
|
12
|
-
return;
|
|
13
|
-
const placeholders = tags.map(() => '(?, ?)').join(', ');
|
|
14
|
-
const params = tags.flatMap((tag) => [memoryId, tag]);
|
|
15
|
-
const stmt = db.prepare(`INSERT OR IGNORE INTO tags (memory_id, tag) VALUES ${placeholders}`);
|
|
16
|
-
executeRun(stmt, ...params);
|
|
17
|
-
};
|
|
18
|
-
//# sourceMappingURL=memory-helpers.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"memory-helpers.js","sourceRoot":"","sources":["../../src/core/memory-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,eAAe,CAAC;AACnC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAiB,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,IAAY,EAAsB,EAAE;IACrE,MAAM,GAAG,GAAG,UAAU,CACpB,EAAE,CAAC,OAAO,CAAC,wCAAwC,CAAC,EACpD,IAAI,CACL,CAAC;IACF,IAAI,CAAC,GAAG;QAAE,OAAO,SAAS,CAAC;IAC3B,OAAO,aAAa,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;AACrC,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,QAAgB,EAAE,IAAuB,EAAQ,EAAE;IAC5E,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO;IAC9B,MAAM,YAAY,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACzD,MAAM,MAAM,GAAe,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC;IAClE,MAAM,IAAI,GAAG,EAAE,CAAC,OAAO,CACrB,sDAAsD,YAAY,EAAE,CACrE,CAAC;IACF,UAAU,CAAC,IAAI,EAAE,GAAG,MAAM,CAAC,CAAC;AAC9B,CAAC,CAAC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { Memory, SearchResult } from '../types/index.js';
|
|
2
|
-
import type { RelatedMemory } from './memory-types.js';
|
|
3
|
-
export type DbRow = Record<string, unknown>;
|
|
4
|
-
export declare const toSafeInteger: (value: unknown, field: string) => number;
|
|
5
|
-
export declare const toString: (value: unknown, field: string) => string;
|
|
6
|
-
export declare const toOptionalString: (value: unknown, field: string) => string | undefined;
|
|
7
|
-
export declare const toOptionalNumber: (value: unknown, field: string) => number | undefined;
|
|
8
|
-
export declare const mapRowToMemory: (row: DbRow) => Memory;
|
|
9
|
-
export declare const mapRowToSearchResult: (row: DbRow) => SearchResult;
|
|
10
|
-
export declare const mapRowToRelatedMemory: (row: DbRow) => RelatedMemory;
|
|
11
|
-
//# sourceMappingURL=memory-mappers.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"memory-mappers.d.ts","sourceRoot":"","sources":["../../src/core/memory-mappers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEvD,MAAM,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAW5C,eAAO,MAAM,aAAa,GAAI,OAAO,OAAO,EAAE,OAAO,MAAM,KAAG,MAM7D,CAAC;AAEF,eAAO,MAAM,QAAQ,GAAI,OAAO,OAAO,EAAE,OAAO,MAAM,KAAG,MAGxD,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAC3B,OAAO,OAAO,EACd,OAAO,MAAM,KACZ,MAAM,GAAG,SAGX,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAC3B,OAAO,OAAO,EACd,OAAO,MAAM,KACZ,MAAM,GAAG,SAGX,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,KAAK,KAAK,KAAG,MAS1C,CAAC;AAEH,eAAO,MAAM,oBAAoB,GAAI,KAAK,KAAK,KAAG,YAGhD,CAAC;AAEH,eAAO,MAAM,qBAAqB,GAAI,KAAK,KAAK,KAAG,aAIjD,CAAC"}
|