@danielsimonjr/memory-mcp 12.2.3 → 12.5.2
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 +88 -102
- package/dist/index.js +6 -0
- package/dist/server/toolDefinitions.d.ts.map +1 -1
- package/dist/server/toolDefinitions.js +745 -3
- package/dist/server/toolHandlers.d.ts +1 -9
- package/dist/server/toolHandlers.d.ts.map +1 -1
- package/dist/server/toolHandlers.js +859 -11
- package/package.json +9 -6
- package/dist/core/EntityManager.d.ts +0 -263
- package/dist/core/EntityManager.d.ts.map +0 -1
- package/dist/core/EntityManager.js +0 -478
- package/dist/core/GraphStorage.d.ts +0 -344
- package/dist/core/GraphStorage.d.ts.map +0 -1
- package/dist/core/GraphStorage.js +0 -708
- package/dist/core/GraphTraversal.d.ts +0 -136
- package/dist/core/GraphTraversal.d.ts.map +0 -1
- package/dist/core/GraphTraversal.js +0 -556
- package/dist/core/HierarchyManager.d.ts +0 -111
- package/dist/core/HierarchyManager.d.ts.map +0 -1
- package/dist/core/HierarchyManager.js +0 -224
- package/dist/core/ManagerContext.d.ts +0 -72
- package/dist/core/ManagerContext.d.ts.map +0 -1
- package/dist/core/ManagerContext.js +0 -118
- package/dist/core/ObservationManager.d.ts +0 -85
- package/dist/core/ObservationManager.d.ts.map +0 -1
- package/dist/core/ObservationManager.js +0 -123
- package/dist/core/RelationManager.d.ts +0 -131
- package/dist/core/RelationManager.d.ts.map +0 -1
- package/dist/core/RelationManager.js +0 -210
- package/dist/core/SQLiteStorage.d.ts +0 -354
- package/dist/core/SQLiteStorage.d.ts.map +0 -1
- package/dist/core/SQLiteStorage.js +0 -917
- package/dist/core/StorageFactory.d.ts +0 -45
- package/dist/core/StorageFactory.d.ts.map +0 -1
- package/dist/core/StorageFactory.js +0 -64
- package/dist/core/TransactionManager.d.ts +0 -259
- package/dist/core/TransactionManager.d.ts.map +0 -1
- package/dist/core/TransactionManager.js +0 -392
- package/dist/core/index.d.ts +0 -16
- package/dist/core/index.d.ts.map +0 -1
- package/dist/core/index.js +0 -17
- package/dist/features/AnalyticsManager.d.ts +0 -44
- package/dist/features/AnalyticsManager.d.ts.map +0 -1
- package/dist/features/AnalyticsManager.js +0 -223
- package/dist/features/ArchiveManager.d.ts +0 -121
- package/dist/features/ArchiveManager.d.ts.map +0 -1
- package/dist/features/ArchiveManager.js +0 -240
- package/dist/features/CompressionManager.d.ts +0 -109
- package/dist/features/CompressionManager.d.ts.map +0 -1
- package/dist/features/CompressionManager.js +0 -404
- package/dist/features/IOManager.d.ts +0 -221
- package/dist/features/IOManager.d.ts.map +0 -1
- package/dist/features/IOManager.js +0 -997
- package/dist/features/StreamingExporter.d.ts +0 -105
- package/dist/features/StreamingExporter.d.ts.map +0 -1
- package/dist/features/StreamingExporter.js +0 -150
- package/dist/features/TagManager.d.ts +0 -147
- package/dist/features/TagManager.d.ts.map +0 -1
- package/dist/features/TagManager.js +0 -210
- package/dist/features/index.d.ts +0 -12
- package/dist/features/index.d.ts.map +0 -1
- package/dist/features/index.js +0 -11
- package/dist/search/BasicSearch.d.ts +0 -51
- package/dist/search/BasicSearch.d.ts.map +0 -1
- package/dist/search/BasicSearch.js +0 -137
- package/dist/search/BooleanSearch.d.ts +0 -98
- package/dist/search/BooleanSearch.d.ts.map +0 -1
- package/dist/search/BooleanSearch.js +0 -430
- package/dist/search/EmbeddingService.d.ts +0 -178
- package/dist/search/EmbeddingService.d.ts.map +0 -1
- package/dist/search/EmbeddingService.js +0 -358
- package/dist/search/FuzzySearch.d.ts +0 -118
- package/dist/search/FuzzySearch.d.ts.map +0 -1
- package/dist/search/FuzzySearch.js +0 -312
- package/dist/search/RankedSearch.d.ts +0 -71
- package/dist/search/RankedSearch.d.ts.map +0 -1
- package/dist/search/RankedSearch.js +0 -238
- package/dist/search/SavedSearchManager.d.ts +0 -79
- package/dist/search/SavedSearchManager.d.ts.map +0 -1
- package/dist/search/SavedSearchManager.js +0 -145
- package/dist/search/SearchFilterChain.d.ts +0 -120
- package/dist/search/SearchFilterChain.d.ts.map +0 -1
- package/dist/search/SearchFilterChain.js +0 -185
- package/dist/search/SearchManager.d.ts +0 -285
- package/dist/search/SearchManager.d.ts.map +0 -1
- package/dist/search/SearchManager.js +0 -338
- package/dist/search/SearchSuggestions.d.ts +0 -27
- package/dist/search/SearchSuggestions.d.ts.map +0 -1
- package/dist/search/SearchSuggestions.js +0 -57
- package/dist/search/SemanticSearch.d.ts +0 -146
- package/dist/search/SemanticSearch.d.ts.map +0 -1
- package/dist/search/SemanticSearch.js +0 -313
- package/dist/search/TFIDFIndexManager.d.ts +0 -63
- package/dist/search/TFIDFIndexManager.d.ts.map +0 -1
- package/dist/search/TFIDFIndexManager.js +0 -215
- package/dist/search/VectorStore.d.ts +0 -235
- package/dist/search/VectorStore.d.ts.map +0 -1
- package/dist/search/VectorStore.js +0 -311
- package/dist/search/index.d.ts +0 -18
- package/dist/search/index.d.ts.map +0 -1
- package/dist/search/index.js +0 -21
- package/dist/types/index.d.ts +0 -13
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -12
- package/dist/types/types.d.ts +0 -1234
- package/dist/types/types.d.ts.map +0 -1
- package/dist/types/types.js +0 -9
- package/dist/utils/compressedCache.d.ts +0 -192
- package/dist/utils/compressedCache.d.ts.map +0 -1
- package/dist/utils/compressedCache.js +0 -309
- package/dist/utils/compressionUtil.d.ts +0 -214
- package/dist/utils/compressionUtil.d.ts.map +0 -1
- package/dist/utils/compressionUtil.js +0 -247
- package/dist/utils/constants.d.ts +0 -245
- package/dist/utils/constants.d.ts.map +0 -1
- package/dist/utils/constants.js +0 -252
- package/dist/utils/entityUtils.d.ts +0 -321
- package/dist/utils/entityUtils.d.ts.map +0 -1
- package/dist/utils/entityUtils.js +0 -538
- package/dist/utils/errors.d.ts +0 -77
- package/dist/utils/errors.d.ts.map +0 -1
- package/dist/utils/errors.js +0 -121
- package/dist/utils/formatters.d.ts +0 -145
- package/dist/utils/formatters.d.ts.map +0 -1
- package/dist/utils/formatters.js +0 -132
- package/dist/utils/index.d.ts +0 -22
- package/dist/utils/index.d.ts.map +0 -1
- package/dist/utils/index.js +0 -75
- package/dist/utils/indexes.d.ts +0 -270
- package/dist/utils/indexes.d.ts.map +0 -1
- package/dist/utils/indexes.js +0 -526
- package/dist/utils/logger.d.ts +0 -24
- package/dist/utils/logger.d.ts.map +0 -1
- package/dist/utils/logger.js +0 -33
- package/dist/utils/parallelUtils.d.ts +0 -72
- package/dist/utils/parallelUtils.d.ts.map +0 -1
- package/dist/utils/parallelUtils.js +0 -169
- package/dist/utils/schemas.d.ts +0 -374
- package/dist/utils/schemas.d.ts.map +0 -1
- package/dist/utils/schemas.js +0 -484
- package/dist/utils/searchAlgorithms.d.ts +0 -99
- package/dist/utils/searchAlgorithms.d.ts.map +0 -1
- package/dist/utils/searchAlgorithms.js +0 -167
- package/dist/utils/searchCache.d.ts +0 -108
- package/dist/utils/searchCache.d.ts.map +0 -1
- package/dist/utils/searchCache.js +0 -209
- package/dist/utils/taskScheduler.d.ts +0 -290
- package/dist/utils/taskScheduler.d.ts.map +0 -1
- package/dist/utils/taskScheduler.js +0 -466
- package/dist/workers/WorkerPool.d.ts +0 -81
- package/dist/workers/WorkerPool.d.ts.map +0 -1
- package/dist/workers/WorkerPool.js +0 -121
- package/dist/workers/index.d.ts +0 -12
- package/dist/workers/index.d.ts.map +0 -1
- package/dist/workers/index.js +0 -9
- package/dist/workers/levenshteinWorker.d.ts +0 -60
- package/dist/workers/levenshteinWorker.d.ts.map +0 -1
- package/dist/workers/levenshteinWorker.js +0 -98
|
@@ -1,392 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Transaction Manager
|
|
3
|
-
*
|
|
4
|
-
* Provides atomic transaction support for knowledge graph operations.
|
|
5
|
-
* Ensures data consistency by allowing multiple operations to be
|
|
6
|
-
* grouped together and committed atomically, with automatic rollback on failure.
|
|
7
|
-
*
|
|
8
|
-
* @module core/TransactionManager
|
|
9
|
-
*/
|
|
10
|
-
import { IOManager } from '../features/IOManager.js';
|
|
11
|
-
import { KnowledgeGraphError } from '../utils/errors.js';
|
|
12
|
-
/**
|
|
13
|
-
* Types of operations that can be performed in a transaction.
|
|
14
|
-
*/
|
|
15
|
-
export var OperationType;
|
|
16
|
-
(function (OperationType) {
|
|
17
|
-
OperationType["CREATE_ENTITY"] = "CREATE_ENTITY";
|
|
18
|
-
OperationType["UPDATE_ENTITY"] = "UPDATE_ENTITY";
|
|
19
|
-
OperationType["DELETE_ENTITY"] = "DELETE_ENTITY";
|
|
20
|
-
OperationType["CREATE_RELATION"] = "CREATE_RELATION";
|
|
21
|
-
OperationType["DELETE_RELATION"] = "DELETE_RELATION";
|
|
22
|
-
})(OperationType || (OperationType = {}));
|
|
23
|
-
/**
|
|
24
|
-
* Manages atomic transactions for knowledge graph operations.
|
|
25
|
-
*
|
|
26
|
-
* Provides ACID-like guarantees:
|
|
27
|
-
* - Atomicity: All operations succeed or all fail
|
|
28
|
-
* - Consistency: Graph is always in a valid state
|
|
29
|
-
* - Isolation: Each transaction operates on a snapshot
|
|
30
|
-
* - Durability: Changes are persisted to disk
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* ```typescript
|
|
34
|
-
* const storage = new GraphStorage('/data/memory.jsonl');
|
|
35
|
-
* const txManager = new TransactionManager(storage);
|
|
36
|
-
*
|
|
37
|
-
* // Begin transaction
|
|
38
|
-
* txManager.begin();
|
|
39
|
-
*
|
|
40
|
-
* // Stage operations
|
|
41
|
-
* txManager.createEntity({ name: 'Alice', entityType: 'person', observations: [] });
|
|
42
|
-
* txManager.createRelation({ from: 'Alice', to: 'Bob', relationType: 'knows' });
|
|
43
|
-
*
|
|
44
|
-
* // Commit atomically (or rollback on error)
|
|
45
|
-
* const result = await txManager.commit();
|
|
46
|
-
* if (result.success) {
|
|
47
|
-
* console.log(`Transaction completed: ${result.operationsExecuted} operations`);
|
|
48
|
-
* }
|
|
49
|
-
* ```
|
|
50
|
-
*/
|
|
51
|
-
export class TransactionManager {
|
|
52
|
-
storage;
|
|
53
|
-
operations = [];
|
|
54
|
-
inTransaction = false;
|
|
55
|
-
ioManager;
|
|
56
|
-
transactionBackup;
|
|
57
|
-
constructor(storage) {
|
|
58
|
-
this.storage = storage;
|
|
59
|
-
this.ioManager = new IOManager(storage);
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Begin a new transaction.
|
|
63
|
-
*
|
|
64
|
-
* Creates a backup of the current state for rollback purposes.
|
|
65
|
-
* Only one transaction can be active at a time.
|
|
66
|
-
*
|
|
67
|
-
* @throws {KnowledgeGraphError} If a transaction is already in progress
|
|
68
|
-
*
|
|
69
|
-
* @example
|
|
70
|
-
* ```typescript
|
|
71
|
-
* txManager.begin();
|
|
72
|
-
* // ... stage operations ...
|
|
73
|
-
* await txManager.commit();
|
|
74
|
-
* ```
|
|
75
|
-
*/
|
|
76
|
-
begin() {
|
|
77
|
-
if (this.inTransaction) {
|
|
78
|
-
throw new KnowledgeGraphError('Transaction already in progress', 'TRANSACTION_ACTIVE');
|
|
79
|
-
}
|
|
80
|
-
this.operations = [];
|
|
81
|
-
this.inTransaction = true;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Stage a create entity operation.
|
|
85
|
-
*
|
|
86
|
-
* @param entity - Entity to create (without timestamps)
|
|
87
|
-
*
|
|
88
|
-
* @example
|
|
89
|
-
* ```typescript
|
|
90
|
-
* txManager.begin();
|
|
91
|
-
* txManager.createEntity({
|
|
92
|
-
* name: 'Alice',
|
|
93
|
-
* entityType: 'person',
|
|
94
|
-
* observations: ['Software engineer'],
|
|
95
|
-
* importance: 8
|
|
96
|
-
* });
|
|
97
|
-
* ```
|
|
98
|
-
*/
|
|
99
|
-
createEntity(entity) {
|
|
100
|
-
this.ensureInTransaction();
|
|
101
|
-
this.operations.push({
|
|
102
|
-
type: OperationType.CREATE_ENTITY,
|
|
103
|
-
data: entity,
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Stage an update entity operation.
|
|
108
|
-
*
|
|
109
|
-
* @param name - Name of entity to update
|
|
110
|
-
* @param updates - Partial entity updates
|
|
111
|
-
*
|
|
112
|
-
* @example
|
|
113
|
-
* ```typescript
|
|
114
|
-
* txManager.begin();
|
|
115
|
-
* txManager.updateEntity('Alice', {
|
|
116
|
-
* importance: 9,
|
|
117
|
-
* observations: ['Lead software engineer']
|
|
118
|
-
* });
|
|
119
|
-
* ```
|
|
120
|
-
*/
|
|
121
|
-
updateEntity(name, updates) {
|
|
122
|
-
this.ensureInTransaction();
|
|
123
|
-
this.operations.push({
|
|
124
|
-
type: OperationType.UPDATE_ENTITY,
|
|
125
|
-
data: { name, updates },
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Stage a delete entity operation.
|
|
130
|
-
*
|
|
131
|
-
* @param name - Name of entity to delete
|
|
132
|
-
*
|
|
133
|
-
* @example
|
|
134
|
-
* ```typescript
|
|
135
|
-
* txManager.begin();
|
|
136
|
-
* txManager.deleteEntity('OldEntity');
|
|
137
|
-
* ```
|
|
138
|
-
*/
|
|
139
|
-
deleteEntity(name) {
|
|
140
|
-
this.ensureInTransaction();
|
|
141
|
-
this.operations.push({
|
|
142
|
-
type: OperationType.DELETE_ENTITY,
|
|
143
|
-
data: { name },
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Stage a create relation operation.
|
|
148
|
-
*
|
|
149
|
-
* @param relation - Relation to create (without timestamps)
|
|
150
|
-
*
|
|
151
|
-
* @example
|
|
152
|
-
* ```typescript
|
|
153
|
-
* txManager.begin();
|
|
154
|
-
* txManager.createRelation({
|
|
155
|
-
* from: 'Alice',
|
|
156
|
-
* to: 'Bob',
|
|
157
|
-
* relationType: 'mentors'
|
|
158
|
-
* });
|
|
159
|
-
* ```
|
|
160
|
-
*/
|
|
161
|
-
createRelation(relation) {
|
|
162
|
-
this.ensureInTransaction();
|
|
163
|
-
this.operations.push({
|
|
164
|
-
type: OperationType.CREATE_RELATION,
|
|
165
|
-
data: relation,
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Stage a delete relation operation.
|
|
170
|
-
*
|
|
171
|
-
* @param from - Source entity name
|
|
172
|
-
* @param to - Target entity name
|
|
173
|
-
* @param relationType - Type of relation
|
|
174
|
-
*
|
|
175
|
-
* @example
|
|
176
|
-
* ```typescript
|
|
177
|
-
* txManager.begin();
|
|
178
|
-
* txManager.deleteRelation('Alice', 'Bob', 'mentors');
|
|
179
|
-
* ```
|
|
180
|
-
*/
|
|
181
|
-
deleteRelation(from, to, relationType) {
|
|
182
|
-
this.ensureInTransaction();
|
|
183
|
-
this.operations.push({
|
|
184
|
-
type: OperationType.DELETE_RELATION,
|
|
185
|
-
data: { from, to, relationType },
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* Commit the transaction, applying all staged operations atomically.
|
|
190
|
-
*
|
|
191
|
-
* Creates a backup before applying changes. If any operation fails,
|
|
192
|
-
* automatically rolls back to the pre-transaction state.
|
|
193
|
-
*
|
|
194
|
-
* @returns Promise resolving to transaction result
|
|
195
|
-
*
|
|
196
|
-
* @example
|
|
197
|
-
* ```typescript
|
|
198
|
-
* txManager.begin();
|
|
199
|
-
* txManager.createEntity({ name: 'Alice', entityType: 'person', observations: [] });
|
|
200
|
-
* txManager.createRelation({ from: 'Alice', to: 'Bob', relationType: 'knows' });
|
|
201
|
-
*
|
|
202
|
-
* const result = await txManager.commit();
|
|
203
|
-
* if (result.success) {
|
|
204
|
-
* console.log(`Committed ${result.operationsExecuted} operations`);
|
|
205
|
-
* } else {
|
|
206
|
-
* console.error(`Transaction failed: ${result.error}`);
|
|
207
|
-
* }
|
|
208
|
-
* ```
|
|
209
|
-
*/
|
|
210
|
-
async commit() {
|
|
211
|
-
this.ensureInTransaction();
|
|
212
|
-
try {
|
|
213
|
-
// Create backup for rollback
|
|
214
|
-
const backupResult = await this.ioManager.createBackup({
|
|
215
|
-
description: 'Transaction backup (auto-created)',
|
|
216
|
-
});
|
|
217
|
-
this.transactionBackup = backupResult.path;
|
|
218
|
-
// Load mutable copy of graph for transaction
|
|
219
|
-
const graph = await this.storage.getGraphForMutation();
|
|
220
|
-
const timestamp = new Date().toISOString();
|
|
221
|
-
// Apply all operations
|
|
222
|
-
let operationsExecuted = 0;
|
|
223
|
-
for (const operation of this.operations) {
|
|
224
|
-
this.applyOperation(graph, operation, timestamp);
|
|
225
|
-
operationsExecuted++;
|
|
226
|
-
}
|
|
227
|
-
// Save the modified graph
|
|
228
|
-
await this.storage.saveGraph(graph);
|
|
229
|
-
// Clean up transaction state
|
|
230
|
-
this.inTransaction = false;
|
|
231
|
-
this.operations = [];
|
|
232
|
-
// Delete the transaction backup (no longer needed)
|
|
233
|
-
if (this.transactionBackup) {
|
|
234
|
-
await this.ioManager.deleteBackup(this.transactionBackup);
|
|
235
|
-
this.transactionBackup = undefined;
|
|
236
|
-
}
|
|
237
|
-
return {
|
|
238
|
-
success: true,
|
|
239
|
-
operationsExecuted,
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
catch (error) {
|
|
243
|
-
// Rollback on error
|
|
244
|
-
const rollbackResult = await this.rollback();
|
|
245
|
-
return {
|
|
246
|
-
success: false,
|
|
247
|
-
operationsExecuted: 0,
|
|
248
|
-
error: error instanceof Error ? error.message : String(error),
|
|
249
|
-
rollbackBackup: rollbackResult.backupUsed,
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
/**
|
|
254
|
-
* Rollback the current transaction.
|
|
255
|
-
*
|
|
256
|
-
* Restores the graph to the pre-transaction state using the backup.
|
|
257
|
-
* Automatically called by commit() on failure.
|
|
258
|
-
*
|
|
259
|
-
* @returns Promise resolving to rollback result
|
|
260
|
-
*
|
|
261
|
-
* @example
|
|
262
|
-
* ```typescript
|
|
263
|
-
* txManager.begin();
|
|
264
|
-
* txManager.createEntity({ name: 'Test', entityType: 'temp', observations: [] });
|
|
265
|
-
*
|
|
266
|
-
* // Explicit rollback (e.g., user cancellation)
|
|
267
|
-
* const result = await txManager.rollback();
|
|
268
|
-
* console.log(`Rolled back, restored from: ${result.backupUsed}`);
|
|
269
|
-
* ```
|
|
270
|
-
*/
|
|
271
|
-
async rollback() {
|
|
272
|
-
if (!this.transactionBackup) {
|
|
273
|
-
this.inTransaction = false;
|
|
274
|
-
this.operations = [];
|
|
275
|
-
return { success: false };
|
|
276
|
-
}
|
|
277
|
-
try {
|
|
278
|
-
// Restore from backup
|
|
279
|
-
await this.ioManager.restoreFromBackup(this.transactionBackup);
|
|
280
|
-
// Clean up
|
|
281
|
-
const backupUsed = this.transactionBackup;
|
|
282
|
-
await this.ioManager.deleteBackup(this.transactionBackup);
|
|
283
|
-
this.inTransaction = false;
|
|
284
|
-
this.operations = [];
|
|
285
|
-
this.transactionBackup = undefined;
|
|
286
|
-
return { success: true, backupUsed };
|
|
287
|
-
}
|
|
288
|
-
catch (error) {
|
|
289
|
-
// Rollback failed - keep backup for manual recovery
|
|
290
|
-
this.inTransaction = false;
|
|
291
|
-
this.operations = [];
|
|
292
|
-
return { success: false, backupUsed: this.transactionBackup };
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
/**
|
|
296
|
-
* Check if a transaction is currently in progress.
|
|
297
|
-
*
|
|
298
|
-
* @returns True if transaction is active
|
|
299
|
-
*/
|
|
300
|
-
isInTransaction() {
|
|
301
|
-
return this.inTransaction;
|
|
302
|
-
}
|
|
303
|
-
/**
|
|
304
|
-
* Get the number of staged operations in the current transaction.
|
|
305
|
-
*
|
|
306
|
-
* @returns Number of operations staged
|
|
307
|
-
*/
|
|
308
|
-
getOperationCount() {
|
|
309
|
-
return this.operations.length;
|
|
310
|
-
}
|
|
311
|
-
/**
|
|
312
|
-
* Ensure a transaction is in progress, or throw an error.
|
|
313
|
-
*
|
|
314
|
-
* @private
|
|
315
|
-
*/
|
|
316
|
-
ensureInTransaction() {
|
|
317
|
-
if (!this.inTransaction) {
|
|
318
|
-
throw new KnowledgeGraphError('No transaction in progress. Call begin() first.', 'NO_TRANSACTION');
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
/**
|
|
322
|
-
* Apply a single operation to the graph.
|
|
323
|
-
*
|
|
324
|
-
* @private
|
|
325
|
-
*/
|
|
326
|
-
applyOperation(graph, operation, timestamp) {
|
|
327
|
-
switch (operation.type) {
|
|
328
|
-
case OperationType.CREATE_ENTITY: {
|
|
329
|
-
const entity = {
|
|
330
|
-
...operation.data,
|
|
331
|
-
createdAt: timestamp,
|
|
332
|
-
lastModified: timestamp,
|
|
333
|
-
};
|
|
334
|
-
// Check for duplicates
|
|
335
|
-
if (graph.entities.some(e => e.name === entity.name)) {
|
|
336
|
-
throw new KnowledgeGraphError(`Entity "${entity.name}" already exists`, 'DUPLICATE_ENTITY');
|
|
337
|
-
}
|
|
338
|
-
graph.entities.push(entity);
|
|
339
|
-
break;
|
|
340
|
-
}
|
|
341
|
-
case OperationType.UPDATE_ENTITY: {
|
|
342
|
-
const { name, updates } = operation.data;
|
|
343
|
-
const entity = graph.entities.find(e => e.name === name);
|
|
344
|
-
if (!entity) {
|
|
345
|
-
throw new KnowledgeGraphError(`Entity "${name}" not found`, 'ENTITY_NOT_FOUND');
|
|
346
|
-
}
|
|
347
|
-
Object.assign(entity, updates);
|
|
348
|
-
entity.lastModified = timestamp;
|
|
349
|
-
break;
|
|
350
|
-
}
|
|
351
|
-
case OperationType.DELETE_ENTITY: {
|
|
352
|
-
const { name } = operation.data;
|
|
353
|
-
const index = graph.entities.findIndex(e => e.name === name);
|
|
354
|
-
if (index === -1) {
|
|
355
|
-
throw new KnowledgeGraphError(`Entity "${name}" not found`, 'ENTITY_NOT_FOUND');
|
|
356
|
-
}
|
|
357
|
-
graph.entities.splice(index, 1);
|
|
358
|
-
// Delete related relations
|
|
359
|
-
graph.relations = graph.relations.filter(r => r.from !== name && r.to !== name);
|
|
360
|
-
break;
|
|
361
|
-
}
|
|
362
|
-
case OperationType.CREATE_RELATION: {
|
|
363
|
-
const relation = {
|
|
364
|
-
...operation.data,
|
|
365
|
-
createdAt: timestamp,
|
|
366
|
-
lastModified: timestamp,
|
|
367
|
-
};
|
|
368
|
-
// Check for duplicates
|
|
369
|
-
const exists = graph.relations.some(r => r.from === relation.from && r.to === relation.to && r.relationType === relation.relationType);
|
|
370
|
-
if (exists) {
|
|
371
|
-
throw new KnowledgeGraphError(`Relation "${relation.from}" -> "${relation.to}" (${relation.relationType}) already exists`, 'DUPLICATE_RELATION');
|
|
372
|
-
}
|
|
373
|
-
graph.relations.push(relation);
|
|
374
|
-
break;
|
|
375
|
-
}
|
|
376
|
-
case OperationType.DELETE_RELATION: {
|
|
377
|
-
const { from, to, relationType } = operation.data;
|
|
378
|
-
const index = graph.relations.findIndex(r => r.from === from && r.to === to && r.relationType === relationType);
|
|
379
|
-
if (index === -1) {
|
|
380
|
-
throw new KnowledgeGraphError(`Relation "${from}" -> "${to}" (${relationType}) not found`, 'RELATION_NOT_FOUND');
|
|
381
|
-
}
|
|
382
|
-
graph.relations.splice(index, 1);
|
|
383
|
-
break;
|
|
384
|
-
}
|
|
385
|
-
default: {
|
|
386
|
-
// Exhaustiveness check - TypeScript will error if we miss a case
|
|
387
|
-
const _exhaustiveCheck = operation;
|
|
388
|
-
throw new KnowledgeGraphError(`Unknown operation type: ${_exhaustiveCheck.type}`, 'UNKNOWN_OPERATION');
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
}
|
package/dist/core/index.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Core Module Barrel Export
|
|
3
|
-
* Phase 4: Added ObservationManager, HierarchyManager, and GraphTraversal exports
|
|
4
|
-
*/
|
|
5
|
-
export { GraphStorage } from './GraphStorage.js';
|
|
6
|
-
export { SQLiteStorage } from './SQLiteStorage.js';
|
|
7
|
-
export { EntityManager } from './EntityManager.js';
|
|
8
|
-
export { RelationManager } from './RelationManager.js';
|
|
9
|
-
export { ObservationManager } from './ObservationManager.js';
|
|
10
|
-
export { HierarchyManager } from './HierarchyManager.js';
|
|
11
|
-
export { ManagerContext } from './ManagerContext.js';
|
|
12
|
-
export { GraphTraversal } from './GraphTraversal.js';
|
|
13
|
-
export { ManagerContext as KnowledgeGraphManager } from './ManagerContext.js';
|
|
14
|
-
export { TransactionManager, OperationType, type TransactionOperation, type TransactionResult, } from './TransactionManager.js';
|
|
15
|
-
export { createStorage, createStorageFromPath } from './StorageFactory.js';
|
|
16
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/core/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,OAAO,EAAE,cAAc,IAAI,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC9E,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,KAAK,oBAAoB,EACzB,KAAK,iBAAiB,GACvB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC"}
|
package/dist/core/index.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Core Module Barrel Export
|
|
3
|
-
* Phase 4: Added ObservationManager, HierarchyManager, and GraphTraversal exports
|
|
4
|
-
*/
|
|
5
|
-
export { GraphStorage } from './GraphStorage.js';
|
|
6
|
-
export { SQLiteStorage } from './SQLiteStorage.js';
|
|
7
|
-
export { EntityManager } from './EntityManager.js';
|
|
8
|
-
export { RelationManager } from './RelationManager.js';
|
|
9
|
-
export { ObservationManager } from './ObservationManager.js';
|
|
10
|
-
export { HierarchyManager } from './HierarchyManager.js';
|
|
11
|
-
export { ManagerContext } from './ManagerContext.js';
|
|
12
|
-
// Phase 4 Sprint 6-8: Graph traversal algorithms
|
|
13
|
-
export { GraphTraversal } from './GraphTraversal.js';
|
|
14
|
-
// Backward compatibility alias
|
|
15
|
-
export { ManagerContext as KnowledgeGraphManager } from './ManagerContext.js';
|
|
16
|
-
export { TransactionManager, OperationType, } from './TransactionManager.js';
|
|
17
|
-
export { createStorage, createStorageFromPath } from './StorageFactory.js';
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Analytics Manager
|
|
3
|
-
*
|
|
4
|
-
* Handles graph statistics and validation operations.
|
|
5
|
-
* Extracted from SearchManager (Phase 4: Consolidate God Objects).
|
|
6
|
-
*
|
|
7
|
-
* @module features/AnalyticsManager
|
|
8
|
-
*/
|
|
9
|
-
import type { GraphStorage } from '../core/GraphStorage.js';
|
|
10
|
-
import type { GraphStats, ValidationReport } from '../types/index.js';
|
|
11
|
-
/**
|
|
12
|
-
* Manages analytics operations for the knowledge graph.
|
|
13
|
-
*/
|
|
14
|
-
export declare class AnalyticsManager {
|
|
15
|
-
private storage;
|
|
16
|
-
constructor(storage: GraphStorage);
|
|
17
|
-
/**
|
|
18
|
-
* Validate the knowledge graph structure and data integrity.
|
|
19
|
-
*
|
|
20
|
-
* Checks for:
|
|
21
|
-
* - Orphaned relations (pointing to non-existent entities)
|
|
22
|
-
* - Duplicate entity names
|
|
23
|
-
* - Invalid entity data (missing name/type, invalid observations)
|
|
24
|
-
* - Isolated entities (no relations)
|
|
25
|
-
* - Empty observations
|
|
26
|
-
* - Missing metadata (createdAt, lastModified)
|
|
27
|
-
*
|
|
28
|
-
* @returns Validation report with errors, warnings, and summary
|
|
29
|
-
*/
|
|
30
|
-
validateGraph(): Promise<ValidationReport>;
|
|
31
|
-
/**
|
|
32
|
-
* Get comprehensive statistics about the knowledge graph.
|
|
33
|
-
*
|
|
34
|
-
* Provides metrics including:
|
|
35
|
-
* - Total counts of entities and relations
|
|
36
|
-
* - Entity and relation type distributions
|
|
37
|
-
* - Oldest and newest entities/relations
|
|
38
|
-
* - Date ranges for entities and relations
|
|
39
|
-
*
|
|
40
|
-
* @returns Graph statistics object
|
|
41
|
-
*/
|
|
42
|
-
getGraphStats(): Promise<GraphStats>;
|
|
43
|
-
}
|
|
44
|
-
//# sourceMappingURL=AnalyticsManager.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AnalyticsManager.d.ts","sourceRoot":"","sources":["../../src/features/AnalyticsManager.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAsC,MAAM,mBAAmB,CAAC;AAE1G;;GAEG;AACH,qBAAa,gBAAgB;IACf,OAAO,CAAC,OAAO;gBAAP,OAAO,EAAE,YAAY;IAEzC;;;;;;;;;;;;OAYG;IACG,aAAa,IAAI,OAAO,CAAC,gBAAgB,CAAC;IAmIhD;;;;;;;;;;OAUG;IACG,aAAa,IAAI,OAAO,CAAC,UAAU,CAAC;CAsE3C"}
|