@j0hanz/memdb 1.0.1 → 1.0.3
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 +157 -66
- package/dist/core/database.d.ts +2 -7
- package/dist/core/database.d.ts.map +1 -1
- package/dist/core/database.js +72 -81
- package/dist/core/database.js.map +1 -1
- package/dist/core/db-worker-client.d.ts +8 -0
- package/dist/core/db-worker-client.d.ts.map +1 -0
- package/dist/core/db-worker-client.js +67 -0
- package/dist/core/db-worker-client.js.map +1 -0
- package/dist/core/db-worker-protocol.d.ts +77 -0
- package/dist/core/db-worker-protocol.d.ts.map +1 -0
- package/dist/core/db-worker-protocol.js +2 -0
- package/dist/core/db-worker-protocol.js.map +1 -0
- package/dist/core/db-worker.d.ts +2 -0
- package/dist/core/db-worker.d.ts.map +1 -0
- package/dist/core/db-worker.js +73 -0
- package/dist/core/db-worker.js.map +1 -0
- package/dist/core/memory-mappers.d.ts +11 -0
- package/dist/core/memory-mappers.d.ts.map +1 -0
- package/dist/core/memory-mappers.js +52 -0
- package/dist/core/memory-mappers.js.map +1 -0
- package/dist/core/memory-search.d.ts +9 -0
- package/dist/core/memory-search.d.ts.map +1 -0
- package/dist/core/memory-search.js +46 -0
- package/dist/core/memory-search.js.map +1 -0
- package/dist/core/memory-service-core.d.ts +9 -0
- package/dist/core/memory-service-core.d.ts.map +1 -0
- package/dist/core/memory-service-core.js +229 -0
- package/dist/core/memory-service-core.js.map +1 -0
- package/dist/core/memory-service.d.ts +8 -30
- package/dist/core/memory-service.d.ts.map +1 -1
- package/dist/core/memory-service.js +184 -169
- package/dist/core/memory-service.js.map +1 -1
- package/dist/core/memory-types.d.ts +18 -0
- package/dist/core/memory-types.d.ts.map +1 -0
- package/dist/core/memory-types.js +2 -0
- package/dist/core/memory-types.js.map +1 -0
- package/dist/core/row-mappers.d.ts +7 -0
- package/dist/core/row-mappers.d.ts.map +1 -0
- package/dist/core/row-mappers.js +52 -0
- package/dist/core/row-mappers.js.map +1 -0
- package/dist/core/search-errors.d.ts +2 -0
- package/dist/core/search-errors.d.ts.map +1 -0
- package/dist/core/search-errors.js +21 -0
- package/dist/core/search-errors.js.map +1 -0
- package/dist/index.js +86 -18
- package/dist/index.js.map +1 -1
- package/dist/lib/errors.d.ts +3 -2
- package/dist/lib/errors.d.ts.map +1 -1
- package/dist/lib/errors.js.map +1 -1
- package/dist/schemas/inputs.d.ts.map +1 -1
- package/dist/schemas/inputs.js +5 -5
- package/dist/schemas/inputs.js.map +1 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +130 -14
- package/dist/tools/index.js.map +1 -1
- package/dist/types/index.d.ts +25 -17
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/config.d.ts +4 -0
- package/dist/utils/config.d.ts.map +1 -1
- package/dist/utils/config.js +48 -1
- package/dist/utils/config.js.map +1 -1
- package/dist/utils/logger.d.ts +6 -2
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +25 -10
- package/dist/utils/logger.js.map +1 -1
- package/dist/utils/protocol.d.ts +2 -0
- package/dist/utils/protocol.d.ts.map +1 -0
- package/dist/utils/protocol.js +7 -0
- package/dist/utils/protocol.js.map +1 -0
- package/package.json +5 -1
|
@@ -1,179 +1,194 @@
|
|
|
1
1
|
import crypto from 'node:crypto';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
try {
|
|
19
|
-
const result = insert.run(content, importance, memoryType, hash);
|
|
20
|
-
const memoryId = result.lastInsertRowid;
|
|
21
|
-
const insertTag = this.db.prepare('INSERT INTO tags (memory_id, tag) VALUES (?, ?)');
|
|
22
|
-
for (const tag of uniqueTags) {
|
|
23
|
-
insertTag.run(memoryId, tag);
|
|
24
|
-
}
|
|
25
|
-
this.db.exec('COMMIT');
|
|
26
|
-
return { id: memoryId, hash, isNew: true };
|
|
27
|
-
}
|
|
28
|
-
catch (err) {
|
|
29
|
-
this.db.exec('ROLLBACK');
|
|
30
|
-
throw err;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
const result = insert.run(content, importance, memoryType, hash);
|
|
34
|
-
const memoryId = result.lastInsertRowid;
|
|
35
|
-
return { id: memoryId, hash, isNew: true };
|
|
2
|
+
import { db } from './database.js';
|
|
3
|
+
import { mapRowToMemory, mapRowToRelatedMemory, mapRowToSearchResult, toSafeInteger, } from './row-mappers.js';
|
|
4
|
+
import { toSearchError } from './search-errors.js';
|
|
5
|
+
const executeAll = (stmt, ...params) => stmt.all(...params);
|
|
6
|
+
const executeGet = (stmt, ...params) => stmt.get(...params);
|
|
7
|
+
const executeRun = (stmt, ...params) => stmt.run(...params);
|
|
8
|
+
const buildSearchQuery = (query, limit, tags, minRelevance) => {
|
|
9
|
+
const sanitizedQuery = `"${query.replace(/"/g, '""')}"`;
|
|
10
|
+
const relevanceExpr = '1.0 / (1.0 + abs(bm25(memories_fts)))';
|
|
11
|
+
const whereParts = ['memories_fts MATCH ?'];
|
|
12
|
+
const params = [sanitizedQuery];
|
|
13
|
+
if (tags.length > 0) {
|
|
14
|
+
whereParts.push(`m.id IN (SELECT memory_id FROM tags WHERE tag IN (${tags
|
|
15
|
+
.map(() => '?')
|
|
16
|
+
.join(', ')}))`);
|
|
17
|
+
params.push(...tags);
|
|
36
18
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const stmt = this.db.prepare(sql);
|
|
64
|
-
let rows;
|
|
65
|
-
try {
|
|
66
|
-
rows = stmt.all(...params);
|
|
67
|
-
}
|
|
68
|
-
catch (err) {
|
|
69
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
70
|
-
if (message.includes('fts5') || message.includes('syntax error')) {
|
|
71
|
-
throw new Error(`Invalid search query syntax. Check for unbalanced quotes or special characters. Details: ${message}`);
|
|
72
|
-
}
|
|
73
|
-
throw err;
|
|
19
|
+
let sql = `
|
|
20
|
+
WITH ranked AS (
|
|
21
|
+
SELECT m.*, ${relevanceExpr} as relevance
|
|
22
|
+
FROM memories m
|
|
23
|
+
JOIN memories_fts fts ON m.id = fts.rowid
|
|
24
|
+
WHERE ${whereParts.join(' AND ')}
|
|
25
|
+
)
|
|
26
|
+
SELECT * FROM ranked
|
|
27
|
+
`;
|
|
28
|
+
if (minRelevance !== undefined) {
|
|
29
|
+
sql += ' WHERE relevance >= ?';
|
|
30
|
+
params.push(minRelevance);
|
|
31
|
+
}
|
|
32
|
+
sql += ' ORDER BY relevance DESC LIMIT ?';
|
|
33
|
+
params.push(limit);
|
|
34
|
+
return { sql, params };
|
|
35
|
+
};
|
|
36
|
+
const executeSearch = (sql, params) => {
|
|
37
|
+
try {
|
|
38
|
+
const stmt = db.prepare(sql);
|
|
39
|
+
return executeAll(stmt, ...params);
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
const mappedError = toSearchError(err);
|
|
43
|
+
if (mappedError) {
|
|
44
|
+
throw mappedError;
|
|
74
45
|
}
|
|
75
|
-
|
|
76
|
-
id: row.id,
|
|
77
|
-
content: row.content,
|
|
78
|
-
summary: row.summary,
|
|
79
|
-
importance: row.importance,
|
|
80
|
-
memory_type: row.memory_type,
|
|
81
|
-
created_at: row.created_at,
|
|
82
|
-
accessed_at: row.accessed_at,
|
|
83
|
-
hash: row.hash,
|
|
84
|
-
relevance: row.relevance,
|
|
85
|
-
}));
|
|
46
|
+
throw err;
|
|
86
47
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
48
|
+
};
|
|
49
|
+
const buildHash = (content) => crypto.createHash('md5').update(content).digest('hex');
|
|
50
|
+
const assertValidTag = (tag) => {
|
|
51
|
+
if (tag.length === 0) {
|
|
52
|
+
throw new Error('Tag must be at least 1 character');
|
|
91
53
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
.prepare('DELETE FROM memories WHERE hash = ?')
|
|
95
|
-
.run(hash);
|
|
54
|
+
if (tag.length > 50) {
|
|
55
|
+
throw new Error('Tag exceeds 50 characters');
|
|
96
56
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
const insert = this.db.prepare('INSERT OR IGNORE INTO relationships (from_memory_id, to_memory_id, relation_type) VALUES (?, ?, ?)');
|
|
104
|
-
return insert.run(from.id, to.id, relationType);
|
|
57
|
+
};
|
|
58
|
+
const normalizeTags = (tags, maxTags) => {
|
|
59
|
+
if (tags.length === 0)
|
|
60
|
+
return [];
|
|
61
|
+
if (tags.length > maxTags) {
|
|
62
|
+
throw new Error('Too many tags (max ' + String(maxTags) + ')');
|
|
105
63
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
64
|
+
const seen = new Set();
|
|
65
|
+
for (const tag of tags) {
|
|
66
|
+
assertValidTag(tag);
|
|
67
|
+
seen.add(tag);
|
|
68
|
+
}
|
|
69
|
+
return [...seen];
|
|
70
|
+
};
|
|
71
|
+
const withImmediateTransaction = (operation) => {
|
|
72
|
+
db.exec('BEGIN IMMEDIATE');
|
|
73
|
+
try {
|
|
74
|
+
const result = operation();
|
|
75
|
+
db.exec('COMMIT');
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
db.exec('ROLLBACK');
|
|
80
|
+
throw err;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
const findMemoryIdByHash = (hash) => {
|
|
84
|
+
const row = executeGet(db.prepare('SELECT id FROM memories WHERE hash = ?'), hash);
|
|
85
|
+
if (!row)
|
|
86
|
+
return undefined;
|
|
87
|
+
return toSafeInteger(row.id, 'id');
|
|
88
|
+
};
|
|
89
|
+
const insertTags = (memoryId, tags) => {
|
|
90
|
+
if (tags.length === 0)
|
|
91
|
+
return;
|
|
92
|
+
const insertTag = db.prepare('INSERT OR IGNORE INTO tags (memory_id, tag) VALUES (?, ?)');
|
|
93
|
+
for (const tag of tags) {
|
|
94
|
+
executeRun(insertTag, memoryId, tag);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
export const createMemory = (content, tags = [], importance = 0, memoryType = 'general') => withImmediateTransaction(() => {
|
|
98
|
+
const hash = buildHash(content);
|
|
99
|
+
const normalizedTags = normalizeTags(tags, 100);
|
|
100
|
+
const insert = db.prepare('INSERT OR IGNORE INTO memories (content, importance, ' +
|
|
101
|
+
'memory_type, hash) VALUES (?, ?, ?, ?)');
|
|
102
|
+
const result = executeRun(insert, content, importance, memoryType, hash);
|
|
103
|
+
const id = findMemoryIdByHash(hash);
|
|
104
|
+
if (id === undefined) {
|
|
105
|
+
throw new Error('Failed to resolve memory id');
|
|
106
|
+
}
|
|
107
|
+
insertTags(id, normalizedTags);
|
|
108
|
+
return { id, hash, isNew: toSafeInteger(result.changes, 'changes') === 1 };
|
|
109
|
+
});
|
|
110
|
+
export const searchMemories = (query, limit = 10, tags = [], minRelevance) => {
|
|
111
|
+
const { sql, params } = buildSearchQuery(query, limit, normalizeTags(tags, 50), minRelevance);
|
|
112
|
+
const rows = executeSearch(sql, params);
|
|
113
|
+
return rows.map((row) => mapRowToSearchResult(row));
|
|
114
|
+
};
|
|
115
|
+
export const getMemory = (hash) => {
|
|
116
|
+
const row = executeGet(db.prepare('SELECT * FROM memories WHERE hash = ?'), hash);
|
|
117
|
+
return row ? mapRowToMemory(row) : undefined;
|
|
118
|
+
};
|
|
119
|
+
export const deleteMemory = (hash) => {
|
|
120
|
+
const result = executeRun(db.prepare('DELETE FROM memories WHERE hash = ?'), hash);
|
|
121
|
+
return { changes: toSafeInteger(result.changes, 'changes') };
|
|
122
|
+
};
|
|
123
|
+
export const linkMemories = (fromHash, toHash, relationType) => {
|
|
124
|
+
const fromId = findMemoryIdByHash(fromHash);
|
|
125
|
+
const toId = findMemoryIdByHash(toHash);
|
|
126
|
+
if (fromId === undefined || toId === undefined) {
|
|
127
|
+
throw new Error('One or both memories not found');
|
|
128
|
+
}
|
|
129
|
+
const insert = db.prepare('INSERT OR IGNORE INTO relationships (from_memory_id, to_memory_id, ' +
|
|
130
|
+
'relation_type) VALUES (?, ?, ?)');
|
|
131
|
+
const result = executeRun(insert, fromId, toId, relationType);
|
|
132
|
+
return { changes: toSafeInteger(result.changes, 'changes') };
|
|
133
|
+
};
|
|
134
|
+
export const getRelated = (hash, relationType, depth = 1) => {
|
|
135
|
+
const memoryId = findMemoryIdByHash(hash);
|
|
136
|
+
if (memoryId === undefined)
|
|
137
|
+
return [];
|
|
138
|
+
const maxDepth = Math.max(1, depth);
|
|
139
|
+
if (maxDepth === 1) {
|
|
140
|
+
return getRelatedDirect(memoryId, relationType);
|
|
171
141
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
142
|
+
return getRelatedRecursive(memoryId, relationType, maxDepth);
|
|
143
|
+
};
|
|
144
|
+
export const getStats = () => {
|
|
145
|
+
const memoryRow = executeGet(db.prepare('SELECT COUNT(*) as count FROM memories'));
|
|
146
|
+
const relationshipRow = executeGet(db.prepare('SELECT COUNT(*) as count FROM relationships'));
|
|
147
|
+
if (!memoryRow || !relationshipRow) {
|
|
148
|
+
throw new Error('Failed to load database stats');
|
|
176
149
|
}
|
|
177
|
-
|
|
178
|
-
|
|
150
|
+
return {
|
|
151
|
+
memoryCount: toSafeInteger(memoryRow.count, 'memoryCount'),
|
|
152
|
+
relationshipCount: toSafeInteger(relationshipRow.count, 'relationshipCount'),
|
|
153
|
+
};
|
|
154
|
+
};
|
|
155
|
+
const getRelatedDirect = (memoryId, relationType) => {
|
|
156
|
+
const clause = relationType ? ' AND r.relation_type = ?' : '';
|
|
157
|
+
const params = relationType ? [relationType] : [];
|
|
158
|
+
const sql = `
|
|
159
|
+
SELECT m.*, r.relation_type as relation_type, 1 as depth
|
|
160
|
+
FROM memories m
|
|
161
|
+
JOIN relationships r ON m.id = r.to_memory_id
|
|
162
|
+
WHERE r.from_memory_id = ?${clause}
|
|
163
|
+
LIMIT 1000
|
|
164
|
+
`;
|
|
165
|
+
const rows = executeAll(db.prepare(sql), memoryId, ...params);
|
|
166
|
+
return rows.map((row) => mapRowToRelatedMemory(row));
|
|
167
|
+
};
|
|
168
|
+
const getRelatedRecursive = (memoryId, relationType, maxDepth) => {
|
|
169
|
+
const clause = relationType ? ' AND r.relation_type = ?' : '';
|
|
170
|
+
const sql = `
|
|
171
|
+
WITH RECURSIVE rels(depth, from_id, to_id, relation_type) AS (
|
|
172
|
+
SELECT 1, r.from_memory_id, r.to_memory_id, r.relation_type
|
|
173
|
+
FROM relationships r
|
|
174
|
+
WHERE r.from_memory_id = ?${clause}
|
|
175
|
+
UNION ALL
|
|
176
|
+
SELECT rels.depth + 1, r.from_memory_id, r.to_memory_id, r.relation_type
|
|
177
|
+
FROM relationships r
|
|
178
|
+
JOIN rels ON r.from_memory_id = rels.to_id
|
|
179
|
+
WHERE rels.depth < ?${clause}
|
|
180
|
+
)
|
|
181
|
+
SELECT m.*, rels.relation_type as relation_type, MIN(rels.depth) as depth
|
|
182
|
+
FROM rels
|
|
183
|
+
JOIN memories m ON m.id = rels.to_id
|
|
184
|
+
GROUP BY m.id, rels.relation_type
|
|
185
|
+
ORDER BY depth, m.id
|
|
186
|
+
LIMIT 1000
|
|
187
|
+
`;
|
|
188
|
+
const queryParams = relationType
|
|
189
|
+
? [memoryId, relationType, maxDepth, relationType]
|
|
190
|
+
: [memoryId, maxDepth];
|
|
191
|
+
const rows = executeAll(db.prepare(sql), ...queryParams);
|
|
192
|
+
return rows.map((row) => mapRowToRelatedMemory(row));
|
|
193
|
+
};
|
|
179
194
|
//# sourceMappingURL=memory-service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory-service.js","sourceRoot":"","sources":["../../src/core/memory-service.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"memory-service.js","sourceRoot":"","sources":["../../src/core/memory-service.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AAWjC,OAAO,EAAE,EAAE,EAAE,MAAM,eAAe,CAAC;AACnC,OAAO,EAE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+
}
|
|
6
|
+
export interface StatementResult {
|
|
7
|
+
changes: number;
|
|
8
|
+
}
|
|
9
|
+
export interface MemoryInsertResult {
|
|
10
|
+
id: number;
|
|
11
|
+
hash: string;
|
|
12
|
+
isNew: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface MemoryStats {
|
|
15
|
+
memoryCount: number;
|
|
16
|
+
relationshipCount: number;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=memory-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-types.d.ts","sourceRoot":"","sources":["../../src/core/memory-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEhD,MAAM,WAAW,aAAc,SAAQ,MAAM;IAC3C,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,WAAW,WAAW;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,iBAAiB,EAAE,MAAM,CAAC;CAC3B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-types.js","sourceRoot":"","sources":["../../src/core/memory-types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Memory, RelatedMemory, SearchResult } from '../types/index.js';
|
|
2
|
+
export type DbRow = Record<string, unknown>;
|
|
3
|
+
export declare const toSafeInteger: (value: unknown, field: string) => number;
|
|
4
|
+
export declare const mapRowToMemory: (row: DbRow) => Memory;
|
|
5
|
+
export declare const mapRowToSearchResult: (row: DbRow) => SearchResult;
|
|
6
|
+
export declare const mapRowToRelatedMemory: (row: DbRow) => RelatedMemory;
|
|
7
|
+
//# sourceMappingURL=row-mappers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"row-mappers.d.ts","sourceRoot":"","sources":["../../src/core/row-mappers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAE7E,MAAM,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAW5C,eAAO,MAAM,aAAa,GAAI,OAAO,OAAO,EAAE,OAAO,MAAM,KAAG,MAM7D,CAAC;AAuBF,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"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
const toNumber = (value, field) => {
|
|
2
|
+
if (typeof value === 'number' && Number.isFinite(value))
|
|
3
|
+
return value;
|
|
4
|
+
if (typeof value === 'bigint') {
|
|
5
|
+
const numeric = Number(value);
|
|
6
|
+
if (Number.isFinite(numeric))
|
|
7
|
+
return numeric;
|
|
8
|
+
}
|
|
9
|
+
throw new Error(`Invalid ${field}`);
|
|
10
|
+
};
|
|
11
|
+
export const toSafeInteger = (value, field) => {
|
|
12
|
+
const numeric = toNumber(value, field);
|
|
13
|
+
if (!Number.isSafeInteger(numeric)) {
|
|
14
|
+
throw new Error(`Invalid ${field}`);
|
|
15
|
+
}
|
|
16
|
+
return numeric;
|
|
17
|
+
};
|
|
18
|
+
const toString = (value, field) => {
|
|
19
|
+
if (typeof value === 'string')
|
|
20
|
+
return value;
|
|
21
|
+
throw new Error(`Invalid ${field}`);
|
|
22
|
+
};
|
|
23
|
+
const toOptionalString = (value, field) => {
|
|
24
|
+
if (value === null || value === undefined)
|
|
25
|
+
return undefined;
|
|
26
|
+
return toString(value, field);
|
|
27
|
+
};
|
|
28
|
+
const toOptionalNumber = (value, field) => {
|
|
29
|
+
if (value === null || value === undefined)
|
|
30
|
+
return undefined;
|
|
31
|
+
return toNumber(value, field);
|
|
32
|
+
};
|
|
33
|
+
export const mapRowToMemory = (row) => ({
|
|
34
|
+
id: toSafeInteger(row.id, 'id'),
|
|
35
|
+
content: toString(row.content, 'content'),
|
|
36
|
+
summary: toOptionalString(row.summary, 'summary'),
|
|
37
|
+
importance: toSafeInteger(row.importance, 'importance'),
|
|
38
|
+
memory_type: toString(row.memory_type, 'memory_type'),
|
|
39
|
+
created_at: toString(row.created_at, 'created_at'),
|
|
40
|
+
accessed_at: toString(row.accessed_at, 'accessed_at'),
|
|
41
|
+
hash: toString(row.hash, 'hash'),
|
|
42
|
+
});
|
|
43
|
+
export const mapRowToSearchResult = (row) => ({
|
|
44
|
+
...mapRowToMemory(row),
|
|
45
|
+
relevance: toOptionalNumber(row.relevance, 'relevance'),
|
|
46
|
+
});
|
|
47
|
+
export const mapRowToRelatedMemory = (row) => ({
|
|
48
|
+
...mapRowToMemory(row),
|
|
49
|
+
relation_type: toString(row.relation_type, 'relation_type'),
|
|
50
|
+
depth: toSafeInteger(row.depth, 'depth'),
|
|
51
|
+
});
|
|
52
|
+
//# sourceMappingURL=row-mappers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"row-mappers.js","sourceRoot":"","sources":["../../src/core/row-mappers.ts"],"names":[],"mappings":"AAIA,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAE,KAAa,EAAU,EAAE;IACzD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACtE,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;QAC9B,IAAI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|
|
3
|
+
'no such table: memories_fts',
|
|
4
|
+
];
|
|
5
|
+
const QUERY_INVALID_TOKENS = ['fts5', 'syntax error'];
|
|
6
|
+
const isSearchIndexMissing = (message) => INDEX_MISSING_TOKENS.some((token) => message.includes(token));
|
|
7
|
+
const isSearchQueryInvalid = (message) => QUERY_INVALID_TOKENS.some((token) => message.includes(token));
|
|
8
|
+
export const toSearchError = (err) => {
|
|
9
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
10
|
+
if (isSearchIndexMissing(message)) {
|
|
11
|
+
return new Error('Search index unavailable. Ensure FTS5 is enabled and the index is ' +
|
|
12
|
+
'initialized.');
|
|
13
|
+
}
|
|
14
|
+
if (isSearchQueryInvalid(message)) {
|
|
15
|
+
return new Error('Invalid search query syntax. Check for unbalanced quotes or special ' +
|
|
16
|
+
'characters. ' +
|
|
17
|
+
`Details: ${message}`);
|
|
18
|
+
}
|
|
19
|
+
return undefined;
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=search-errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search-errors.js","sourceRoot":"","sources":["../../src/core/search-errors.ts"],"names":[],"mappings":"AAAA,MAAM,oBAAoB,GAAG;IAC3B,sBAAsB;IACtB,6BAA6B;CAC9B,CAAC;AACF,MAAM,oBAAoB,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;AAEtD,MAAM,oBAAoB,GAAG,CAAC,OAAe,EAAW,EAAE,CACxD,oBAAoB,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;AAEhE,MAAM,oBAAoB,GAAG,CAAC,OAAe,EAAW,EAAE,CACxD,oBAAoB,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;AAEhE,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,GAAY,EAAqB,EAAE;IAC/D,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACjE,IAAI,oBAAoB,CAAC,OAAO,CAAC,EAAE,CAAC;QAClC,OAAO,IAAI,KAAK,CACd,oEAAoE;YAClE,cAAc,CACjB,CAAC;IACJ,CAAC;IACD,IAAI,oBAAoB,CAAC,OAAO,CAAC,EAAE,CAAC;QAClC,OAAO,IAAI,KAAK,CACd,sEAAsE;YACpE,cAAc;YACd,YAAY,OAAO,EAAE,CACxB,CAAC;IACJ,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC"}
|