@soulcraft/brainy 5.7.13 → 5.9.0
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/CHANGELOG.md +18 -7
- package/README.md +6 -2
- package/dist/augmentations/intelligentImport/handlers/imageHandler.d.ts +12 -16
- package/dist/augmentations/intelligentImport/handlers/imageHandler.js +40 -22
- package/dist/brainy.d.ts +1 -0
- package/dist/brainy.js +137 -126
- package/dist/graph/graphAdjacencyIndex.d.ts +76 -7
- package/dist/graph/graphAdjacencyIndex.js +94 -9
- package/dist/hnsw/typeAwareHNSWIndex.d.ts +3 -3
- package/dist/hnsw/typeAwareHNSWIndex.js +3 -3
- package/dist/query/typeAwareQueryPlanner.d.ts +4 -4
- package/dist/query/typeAwareQueryPlanner.js +4 -4
- package/dist/transaction/Transaction.d.ts +55 -0
- package/dist/transaction/Transaction.js +175 -0
- package/dist/transaction/TransactionManager.d.ts +67 -0
- package/dist/transaction/TransactionManager.js +145 -0
- package/dist/transaction/errors.d.ts +41 -0
- package/dist/transaction/errors.js +66 -0
- package/dist/transaction/index.d.ts +14 -0
- package/dist/transaction/index.js +14 -0
- package/dist/transaction/operations/IndexOperations.d.ts +172 -0
- package/dist/transaction/operations/IndexOperations.js +301 -0
- package/dist/transaction/operations/StorageOperations.d.ts +128 -0
- package/dist/transaction/operations/StorageOperations.js +253 -0
- package/dist/transaction/operations/index.d.ts +10 -0
- package/dist/transaction/operations/index.js +13 -0
- package/dist/transaction/types.d.ts +84 -0
- package/dist/transaction/types.js +8 -0
- package/dist/vfs/VirtualFileSystem.d.ts +16 -0
- package/dist/vfs/VirtualFileSystem.js +138 -48
- package/package.json +3 -3
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Index Operations with Rollback Support
|
|
3
|
+
*
|
|
4
|
+
* Provides transactional operations for all indexes:
|
|
5
|
+
* - TypeAwareHNSWIndex (per-type vector indexes)
|
|
6
|
+
* - HNSWIndex (legacy/fallback vector index)
|
|
7
|
+
* - MetadataIndexManager (roaring bitmap filtering)
|
|
8
|
+
* - GraphAdjacencyIndex (LSM-tree graph storage)
|
|
9
|
+
*
|
|
10
|
+
* Each operation can be executed and rolled back atomically.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Add to HNSW index with rollback support
|
|
14
|
+
*
|
|
15
|
+
* Rollback strategy:
|
|
16
|
+
* - Remove item from index
|
|
17
|
+
*
|
|
18
|
+
* Note: Works with both HNSWIndex and TypeAwareHNSWIndex
|
|
19
|
+
*/
|
|
20
|
+
export class AddToHNSWOperation {
|
|
21
|
+
constructor(index, id, vector) {
|
|
22
|
+
this.index = index;
|
|
23
|
+
this.id = id;
|
|
24
|
+
this.vector = vector;
|
|
25
|
+
this.name = 'AddToHNSW';
|
|
26
|
+
}
|
|
27
|
+
async execute() {
|
|
28
|
+
// Check if item already exists (for rollback decision)
|
|
29
|
+
const existed = await this.itemExists(this.id);
|
|
30
|
+
// Add to index
|
|
31
|
+
await this.index.addItem({ id: this.id, vector: this.vector });
|
|
32
|
+
// Return rollback action
|
|
33
|
+
return async () => {
|
|
34
|
+
if (!existed) {
|
|
35
|
+
// Remove newly added item
|
|
36
|
+
await this.index.removeItem(this.id);
|
|
37
|
+
}
|
|
38
|
+
// If item existed before, we don't rollback (update is OK)
|
|
39
|
+
// This prevents index corruption from removing pre-existing items
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Check if item exists in index
|
|
44
|
+
*/
|
|
45
|
+
async itemExists(id) {
|
|
46
|
+
try {
|
|
47
|
+
// Try to get item - if exists, no error
|
|
48
|
+
await this.index.getItem?.(id);
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Add to TypeAwareHNSW index with rollback support
|
|
58
|
+
*
|
|
59
|
+
* Rollback strategy:
|
|
60
|
+
* - Remove item from type-specific index
|
|
61
|
+
*/
|
|
62
|
+
export class AddToTypeAwareHNSWOperation {
|
|
63
|
+
constructor(index, id, vector, nounType) {
|
|
64
|
+
this.index = index;
|
|
65
|
+
this.id = id;
|
|
66
|
+
this.vector = vector;
|
|
67
|
+
this.nounType = nounType;
|
|
68
|
+
this.name = 'AddToTypeAwareHNSW';
|
|
69
|
+
}
|
|
70
|
+
async execute() {
|
|
71
|
+
// Check if item already exists
|
|
72
|
+
const existed = await this.itemExists(this.id, this.nounType);
|
|
73
|
+
// Add to type-specific index
|
|
74
|
+
await this.index.addItem({ id: this.id, vector: this.vector }, this.nounType);
|
|
75
|
+
// Return rollback action
|
|
76
|
+
return async () => {
|
|
77
|
+
if (!existed) {
|
|
78
|
+
// Remove newly added item from type-specific index
|
|
79
|
+
await this.index.removeItem(this.id, this.nounType);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Check if item exists in type-specific index
|
|
85
|
+
*/
|
|
86
|
+
async itemExists(id, type) {
|
|
87
|
+
try {
|
|
88
|
+
const index = this.index.getIndexForType?.(type);
|
|
89
|
+
if (index) {
|
|
90
|
+
await index.getItem?.(id);
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Remove from HNSW index with rollback support
|
|
102
|
+
*
|
|
103
|
+
* Rollback strategy:
|
|
104
|
+
* - Re-add item to index with original vector
|
|
105
|
+
*
|
|
106
|
+
* Note: Requires storing the vector for rollback
|
|
107
|
+
*/
|
|
108
|
+
export class RemoveFromHNSWOperation {
|
|
109
|
+
constructor(index, id, vector // Required for rollback
|
|
110
|
+
) {
|
|
111
|
+
this.index = index;
|
|
112
|
+
this.id = id;
|
|
113
|
+
this.vector = vector;
|
|
114
|
+
this.name = 'RemoveFromHNSW';
|
|
115
|
+
}
|
|
116
|
+
async execute() {
|
|
117
|
+
// Remove from index
|
|
118
|
+
await this.index.removeItem(this.id);
|
|
119
|
+
// Return rollback action
|
|
120
|
+
return async () => {
|
|
121
|
+
// Re-add item with original vector
|
|
122
|
+
await this.index.addItem({ id: this.id, vector: this.vector });
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Remove from TypeAwareHNSW index with rollback support
|
|
128
|
+
*
|
|
129
|
+
* Rollback strategy:
|
|
130
|
+
* - Re-add item to type-specific index with original vector
|
|
131
|
+
*/
|
|
132
|
+
export class RemoveFromTypeAwareHNSWOperation {
|
|
133
|
+
constructor(index, id, vector, // Required for rollback
|
|
134
|
+
nounType) {
|
|
135
|
+
this.index = index;
|
|
136
|
+
this.id = id;
|
|
137
|
+
this.vector = vector;
|
|
138
|
+
this.nounType = nounType;
|
|
139
|
+
this.name = 'RemoveFromTypeAwareHNSW';
|
|
140
|
+
}
|
|
141
|
+
async execute() {
|
|
142
|
+
// Remove from type-specific index
|
|
143
|
+
await this.index.removeItem(this.id, this.nounType);
|
|
144
|
+
// Return rollback action
|
|
145
|
+
return async () => {
|
|
146
|
+
// Re-add item with original vector to type-specific index
|
|
147
|
+
await this.index.addItem({ id: this.id, vector: this.vector }, this.nounType);
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Add to metadata index with rollback support
|
|
153
|
+
*
|
|
154
|
+
* Rollback strategy:
|
|
155
|
+
* - Remove item from index
|
|
156
|
+
*/
|
|
157
|
+
export class AddToMetadataIndexOperation {
|
|
158
|
+
constructor(index, id, entity // Entity or metadata structure
|
|
159
|
+
) {
|
|
160
|
+
this.index = index;
|
|
161
|
+
this.id = id;
|
|
162
|
+
this.entity = entity;
|
|
163
|
+
this.name = 'AddToMetadataIndex';
|
|
164
|
+
}
|
|
165
|
+
async execute() {
|
|
166
|
+
// Add to metadata index (skipFlush=true for transaction atomicity)
|
|
167
|
+
await this.index.addToIndex(this.id, this.entity, true);
|
|
168
|
+
// Return rollback action
|
|
169
|
+
return async () => {
|
|
170
|
+
// Remove from metadata index
|
|
171
|
+
await this.index.removeFromIndex(this.id, this.entity);
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Remove from metadata index with rollback support
|
|
177
|
+
*
|
|
178
|
+
* Rollback strategy:
|
|
179
|
+
* - Re-add item to index with original metadata
|
|
180
|
+
*/
|
|
181
|
+
export class RemoveFromMetadataIndexOperation {
|
|
182
|
+
constructor(index, id, entity // Required for rollback
|
|
183
|
+
) {
|
|
184
|
+
this.index = index;
|
|
185
|
+
this.id = id;
|
|
186
|
+
this.entity = entity;
|
|
187
|
+
this.name = 'RemoveFromMetadataIndex';
|
|
188
|
+
}
|
|
189
|
+
async execute() {
|
|
190
|
+
// Remove from metadata index
|
|
191
|
+
await this.index.removeFromIndex(this.id, this.entity);
|
|
192
|
+
// Return rollback action
|
|
193
|
+
return async () => {
|
|
194
|
+
// Re-add with original metadata (skipFlush=true)
|
|
195
|
+
await this.index.addToIndex(this.id, this.entity, true);
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Add verb to graph index with rollback support
|
|
201
|
+
*
|
|
202
|
+
* Rollback strategy:
|
|
203
|
+
* - Remove verb from graph index
|
|
204
|
+
*/
|
|
205
|
+
export class AddToGraphIndexOperation {
|
|
206
|
+
constructor(index, verb) {
|
|
207
|
+
this.index = index;
|
|
208
|
+
this.verb = verb;
|
|
209
|
+
this.name = 'AddToGraphIndex';
|
|
210
|
+
}
|
|
211
|
+
async execute() {
|
|
212
|
+
// Add verb to graph index
|
|
213
|
+
await this.index.addVerb(this.verb);
|
|
214
|
+
// Return rollback action
|
|
215
|
+
return async () => {
|
|
216
|
+
// Remove verb from graph index
|
|
217
|
+
await this.index.removeVerb(this.verb.id);
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Remove verb from graph index with rollback support
|
|
223
|
+
*
|
|
224
|
+
* Rollback strategy:
|
|
225
|
+
* - Re-add verb to graph index
|
|
226
|
+
*/
|
|
227
|
+
export class RemoveFromGraphIndexOperation {
|
|
228
|
+
constructor(index, verb // Required for rollback
|
|
229
|
+
) {
|
|
230
|
+
this.index = index;
|
|
231
|
+
this.verb = verb;
|
|
232
|
+
this.name = 'RemoveFromGraphIndex';
|
|
233
|
+
}
|
|
234
|
+
async execute() {
|
|
235
|
+
// Remove verb from graph index
|
|
236
|
+
await this.index.removeVerb(this.verb.id);
|
|
237
|
+
// Return rollback action
|
|
238
|
+
return async () => {
|
|
239
|
+
// Re-add verb with original data
|
|
240
|
+
await this.index.addVerb(this.verb);
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Batch operation: Add multiple items to HNSW index
|
|
246
|
+
*
|
|
247
|
+
* Useful for bulk imports with transaction support.
|
|
248
|
+
* Rolls back all items if any fail.
|
|
249
|
+
*/
|
|
250
|
+
export class BatchAddToHNSWOperation {
|
|
251
|
+
constructor(index, items) {
|
|
252
|
+
this.name = 'BatchAddToHNSW';
|
|
253
|
+
this.operations = items.map(item => new AddToHNSWOperation(index, item.id, item.vector));
|
|
254
|
+
}
|
|
255
|
+
async execute() {
|
|
256
|
+
const rollbackActions = [];
|
|
257
|
+
// Execute all operations
|
|
258
|
+
for (const op of this.operations) {
|
|
259
|
+
const rollback = await op.execute();
|
|
260
|
+
if (rollback) {
|
|
261
|
+
rollbackActions.push(rollback);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
// Return combined rollback action
|
|
265
|
+
return async () => {
|
|
266
|
+
// Execute all rollbacks in reverse order
|
|
267
|
+
for (let i = rollbackActions.length - 1; i >= 0; i--) {
|
|
268
|
+
await rollbackActions[i]();
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Batch operation: Add multiple entities to metadata index
|
|
275
|
+
*
|
|
276
|
+
* Useful for bulk imports with transaction support.
|
|
277
|
+
*/
|
|
278
|
+
export class BatchAddToMetadataIndexOperation {
|
|
279
|
+
constructor(index, items) {
|
|
280
|
+
this.name = 'BatchAddToMetadataIndex';
|
|
281
|
+
this.operations = items.map(item => new AddToMetadataIndexOperation(index, item.id, item.entity));
|
|
282
|
+
}
|
|
283
|
+
async execute() {
|
|
284
|
+
const rollbackActions = [];
|
|
285
|
+
// Execute all operations
|
|
286
|
+
for (const op of this.operations) {
|
|
287
|
+
const rollback = await op.execute();
|
|
288
|
+
if (rollback) {
|
|
289
|
+
rollbackActions.push(rollback);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
// Return combined rollback action
|
|
293
|
+
return async () => {
|
|
294
|
+
// Execute all rollbacks in reverse order
|
|
295
|
+
for (let i = rollbackActions.length - 1; i >= 0; i--) {
|
|
296
|
+
await rollbackActions[i]();
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
//# sourceMappingURL=IndexOperations.js.map
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Storage Operations with Rollback Support
|
|
3
|
+
*
|
|
4
|
+
* Provides transactional operations for all storage adapters.
|
|
5
|
+
* Each operation can be executed and rolled back atomically.
|
|
6
|
+
*
|
|
7
|
+
* Supports:
|
|
8
|
+
* - All 8 storage adapters (FileSystem, S3, Memory, OPFS, GCS, Azure, R2, TypeAware)
|
|
9
|
+
* - Nouns (entities) and Verbs (relationships)
|
|
10
|
+
* - Metadata and vector data
|
|
11
|
+
* - COW (Copy-on-Write) storage
|
|
12
|
+
*/
|
|
13
|
+
import type { StorageAdapter, HNSWNoun, HNSWVerb, NounMetadata, VerbMetadata } from '../../coreTypes.js';
|
|
14
|
+
import type { Operation, RollbackAction } from '../types.js';
|
|
15
|
+
/**
|
|
16
|
+
* Save noun metadata with rollback support
|
|
17
|
+
*
|
|
18
|
+
* Rollback strategy:
|
|
19
|
+
* - If metadata existed: Restore previous metadata
|
|
20
|
+
* - If metadata was new: Delete metadata
|
|
21
|
+
*/
|
|
22
|
+
export declare class SaveNounMetadataOperation implements Operation {
|
|
23
|
+
private readonly storage;
|
|
24
|
+
private readonly id;
|
|
25
|
+
private readonly metadata;
|
|
26
|
+
readonly name = "SaveNounMetadata";
|
|
27
|
+
constructor(storage: StorageAdapter, id: string, metadata: NounMetadata);
|
|
28
|
+
execute(): Promise<RollbackAction>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Save noun (vector data) with rollback support
|
|
32
|
+
*
|
|
33
|
+
* Rollback strategy:
|
|
34
|
+
* - If noun existed: Restore previous noun
|
|
35
|
+
* - If noun was new: Delete noun (if deleteNoun exists on adapter)
|
|
36
|
+
*
|
|
37
|
+
* Note: Not all adapters implement deleteNoun - this is acceptable
|
|
38
|
+
* because orphaned vector data without metadata is invisible to queries
|
|
39
|
+
*/
|
|
40
|
+
export declare class SaveNounOperation implements Operation {
|
|
41
|
+
private readonly storage;
|
|
42
|
+
private readonly noun;
|
|
43
|
+
readonly name = "SaveNoun";
|
|
44
|
+
constructor(storage: StorageAdapter, noun: HNSWNoun);
|
|
45
|
+
execute(): Promise<RollbackAction>;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Delete noun metadata with rollback support
|
|
49
|
+
*
|
|
50
|
+
* Rollback strategy:
|
|
51
|
+
* - Restore deleted metadata
|
|
52
|
+
*/
|
|
53
|
+
export declare class DeleteNounMetadataOperation implements Operation {
|
|
54
|
+
private readonly storage;
|
|
55
|
+
private readonly id;
|
|
56
|
+
readonly name = "DeleteNounMetadata";
|
|
57
|
+
constructor(storage: StorageAdapter, id: string);
|
|
58
|
+
execute(): Promise<RollbackAction>;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Save verb metadata with rollback support
|
|
62
|
+
*
|
|
63
|
+
* Rollback strategy:
|
|
64
|
+
* - If metadata existed: Restore previous metadata
|
|
65
|
+
* - If metadata was new: Delete metadata
|
|
66
|
+
*/
|
|
67
|
+
export declare class SaveVerbMetadataOperation implements Operation {
|
|
68
|
+
private readonly storage;
|
|
69
|
+
private readonly id;
|
|
70
|
+
private readonly metadata;
|
|
71
|
+
readonly name = "SaveVerbMetadata";
|
|
72
|
+
constructor(storage: StorageAdapter, id: string, metadata: VerbMetadata);
|
|
73
|
+
execute(): Promise<RollbackAction>;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Save verb (vector data) with rollback support
|
|
77
|
+
*
|
|
78
|
+
* Rollback strategy:
|
|
79
|
+
* - If verb existed: Restore previous verb
|
|
80
|
+
* - If verb was new: Delete verb (if deleteVerb exists on adapter)
|
|
81
|
+
*/
|
|
82
|
+
export declare class SaveVerbOperation implements Operation {
|
|
83
|
+
private readonly storage;
|
|
84
|
+
private readonly verb;
|
|
85
|
+
readonly name = "SaveVerb";
|
|
86
|
+
constructor(storage: StorageAdapter, verb: HNSWVerb);
|
|
87
|
+
execute(): Promise<RollbackAction>;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Delete verb metadata with rollback support
|
|
91
|
+
*
|
|
92
|
+
* Rollback strategy:
|
|
93
|
+
* - Restore deleted metadata
|
|
94
|
+
*/
|
|
95
|
+
export declare class DeleteVerbMetadataOperation implements Operation {
|
|
96
|
+
private readonly storage;
|
|
97
|
+
private readonly id;
|
|
98
|
+
readonly name = "DeleteVerbMetadata";
|
|
99
|
+
constructor(storage: StorageAdapter, id: string);
|
|
100
|
+
execute(): Promise<RollbackAction>;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Update noun metadata with rollback support
|
|
104
|
+
*
|
|
105
|
+
* Rollback strategy:
|
|
106
|
+
* - Restore previous metadata
|
|
107
|
+
*
|
|
108
|
+
* Note: This is a convenience operation that wraps SaveNounMetadataOperation
|
|
109
|
+
* with explicit "update" semantics
|
|
110
|
+
*/
|
|
111
|
+
export declare class UpdateNounMetadataOperation implements Operation {
|
|
112
|
+
readonly name = "UpdateNounMetadata";
|
|
113
|
+
private saveOperation;
|
|
114
|
+
constructor(storage: StorageAdapter, id: string, metadata: NounMetadata);
|
|
115
|
+
execute(): Promise<RollbackAction>;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Update verb metadata with rollback support
|
|
119
|
+
*
|
|
120
|
+
* Rollback strategy:
|
|
121
|
+
* - Restore previous metadata
|
|
122
|
+
*/
|
|
123
|
+
export declare class UpdateVerbMetadataOperation implements Operation {
|
|
124
|
+
readonly name = "UpdateVerbMetadata";
|
|
125
|
+
private saveOperation;
|
|
126
|
+
constructor(storage: StorageAdapter, id: string, metadata: VerbMetadata);
|
|
127
|
+
execute(): Promise<RollbackAction>;
|
|
128
|
+
}
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Storage Operations with Rollback Support
|
|
3
|
+
*
|
|
4
|
+
* Provides transactional operations for all storage adapters.
|
|
5
|
+
* Each operation can be executed and rolled back atomically.
|
|
6
|
+
*
|
|
7
|
+
* Supports:
|
|
8
|
+
* - All 8 storage adapters (FileSystem, S3, Memory, OPFS, GCS, Azure, R2, TypeAware)
|
|
9
|
+
* - Nouns (entities) and Verbs (relationships)
|
|
10
|
+
* - Metadata and vector data
|
|
11
|
+
* - COW (Copy-on-Write) storage
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Save noun metadata with rollback support
|
|
15
|
+
*
|
|
16
|
+
* Rollback strategy:
|
|
17
|
+
* - If metadata existed: Restore previous metadata
|
|
18
|
+
* - If metadata was new: Delete metadata
|
|
19
|
+
*/
|
|
20
|
+
export class SaveNounMetadataOperation {
|
|
21
|
+
constructor(storage, id, metadata) {
|
|
22
|
+
this.storage = storage;
|
|
23
|
+
this.id = id;
|
|
24
|
+
this.metadata = metadata;
|
|
25
|
+
this.name = 'SaveNounMetadata';
|
|
26
|
+
}
|
|
27
|
+
async execute() {
|
|
28
|
+
// Get existing metadata (for rollback)
|
|
29
|
+
const previousMetadata = await this.storage.getNounMetadata(this.id);
|
|
30
|
+
// Save new metadata
|
|
31
|
+
await this.storage.saveNounMetadata(this.id, this.metadata);
|
|
32
|
+
// Return rollback action
|
|
33
|
+
return async () => {
|
|
34
|
+
if (previousMetadata) {
|
|
35
|
+
// Restore previous metadata
|
|
36
|
+
await this.storage.saveNounMetadata(this.id, previousMetadata);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
// Delete newly created metadata
|
|
40
|
+
await this.storage.deleteNounMetadata(this.id);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Save noun (vector data) with rollback support
|
|
47
|
+
*
|
|
48
|
+
* Rollback strategy:
|
|
49
|
+
* - If noun existed: Restore previous noun
|
|
50
|
+
* - If noun was new: Delete noun (if deleteNoun exists on adapter)
|
|
51
|
+
*
|
|
52
|
+
* Note: Not all adapters implement deleteNoun - this is acceptable
|
|
53
|
+
* because orphaned vector data without metadata is invisible to queries
|
|
54
|
+
*/
|
|
55
|
+
export class SaveNounOperation {
|
|
56
|
+
constructor(storage, noun) {
|
|
57
|
+
this.storage = storage;
|
|
58
|
+
this.noun = noun;
|
|
59
|
+
this.name = 'SaveNoun';
|
|
60
|
+
}
|
|
61
|
+
async execute() {
|
|
62
|
+
// Get existing noun (for rollback)
|
|
63
|
+
const previousNoun = await this.storage.getNoun(this.noun.id);
|
|
64
|
+
// Save new noun
|
|
65
|
+
await this.storage.saveNoun(this.noun);
|
|
66
|
+
// Return rollback action
|
|
67
|
+
return async () => {
|
|
68
|
+
if (previousNoun) {
|
|
69
|
+
// Restore previous noun (extract just vector data)
|
|
70
|
+
const nounData = {
|
|
71
|
+
id: previousNoun.id,
|
|
72
|
+
vector: previousNoun.vector,
|
|
73
|
+
connections: previousNoun.connections || new Map(),
|
|
74
|
+
level: previousNoun.level || 0
|
|
75
|
+
};
|
|
76
|
+
await this.storage.saveNoun(nounData);
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
// Delete newly created noun (if adapter supports it)
|
|
80
|
+
// Note: Not all adapters implement deleteNoun
|
|
81
|
+
// This is acceptable - metadata deletion makes entity invisible
|
|
82
|
+
if ('deleteNoun' in this.storage && typeof this.storage.deleteNoun === 'function') {
|
|
83
|
+
await this.storage.deleteNoun(this.noun.id);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Delete noun metadata with rollback support
|
|
91
|
+
*
|
|
92
|
+
* Rollback strategy:
|
|
93
|
+
* - Restore deleted metadata
|
|
94
|
+
*/
|
|
95
|
+
export class DeleteNounMetadataOperation {
|
|
96
|
+
constructor(storage, id) {
|
|
97
|
+
this.storage = storage;
|
|
98
|
+
this.id = id;
|
|
99
|
+
this.name = 'DeleteNounMetadata';
|
|
100
|
+
}
|
|
101
|
+
async execute() {
|
|
102
|
+
// Get metadata before deletion (for rollback)
|
|
103
|
+
const previousMetadata = await this.storage.getNounMetadata(this.id);
|
|
104
|
+
if (!previousMetadata) {
|
|
105
|
+
// Nothing to delete - no rollback needed
|
|
106
|
+
return async () => { };
|
|
107
|
+
}
|
|
108
|
+
// Delete metadata
|
|
109
|
+
await this.storage.deleteNounMetadata(this.id);
|
|
110
|
+
// Return rollback action
|
|
111
|
+
return async () => {
|
|
112
|
+
// Restore deleted metadata
|
|
113
|
+
await this.storage.saveNounMetadata(this.id, previousMetadata);
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Save verb metadata with rollback support
|
|
119
|
+
*
|
|
120
|
+
* Rollback strategy:
|
|
121
|
+
* - If metadata existed: Restore previous metadata
|
|
122
|
+
* - If metadata was new: Delete metadata
|
|
123
|
+
*/
|
|
124
|
+
export class SaveVerbMetadataOperation {
|
|
125
|
+
constructor(storage, id, metadata) {
|
|
126
|
+
this.storage = storage;
|
|
127
|
+
this.id = id;
|
|
128
|
+
this.metadata = metadata;
|
|
129
|
+
this.name = 'SaveVerbMetadata';
|
|
130
|
+
}
|
|
131
|
+
async execute() {
|
|
132
|
+
// Get existing metadata (for rollback)
|
|
133
|
+
const previousMetadata = await this.storage.getVerbMetadata(this.id);
|
|
134
|
+
// Save new metadata
|
|
135
|
+
await this.storage.saveVerbMetadata(this.id, this.metadata);
|
|
136
|
+
// Return rollback action
|
|
137
|
+
return async () => {
|
|
138
|
+
if (previousMetadata) {
|
|
139
|
+
// Restore previous metadata
|
|
140
|
+
await this.storage.saveVerbMetadata(this.id, previousMetadata);
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
// Delete newly created verb (metadata + vector)
|
|
144
|
+
// Note: StorageAdapter has deleteVerb but not deleteVerbMetadata
|
|
145
|
+
await this.storage.deleteVerb(this.id);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Save verb (vector data) with rollback support
|
|
152
|
+
*
|
|
153
|
+
* Rollback strategy:
|
|
154
|
+
* - If verb existed: Restore previous verb
|
|
155
|
+
* - If verb was new: Delete verb (if deleteVerb exists on adapter)
|
|
156
|
+
*/
|
|
157
|
+
export class SaveVerbOperation {
|
|
158
|
+
constructor(storage, verb) {
|
|
159
|
+
this.storage = storage;
|
|
160
|
+
this.verb = verb;
|
|
161
|
+
this.name = 'SaveVerb';
|
|
162
|
+
}
|
|
163
|
+
async execute() {
|
|
164
|
+
// Get existing verb (for rollback)
|
|
165
|
+
const previousVerb = await this.storage.getVerb(this.verb.id);
|
|
166
|
+
// Save new verb
|
|
167
|
+
await this.storage.saveVerb(this.verb);
|
|
168
|
+
// Return rollback action
|
|
169
|
+
return async () => {
|
|
170
|
+
if (previousVerb) {
|
|
171
|
+
// Restore previous verb (extract just vector data)
|
|
172
|
+
const verbData = {
|
|
173
|
+
id: previousVerb.id,
|
|
174
|
+
sourceId: previousVerb.sourceId,
|
|
175
|
+
targetId: previousVerb.targetId,
|
|
176
|
+
verb: previousVerb.verb,
|
|
177
|
+
vector: previousVerb.vector,
|
|
178
|
+
connections: previousVerb.connections || new Map()
|
|
179
|
+
};
|
|
180
|
+
await this.storage.saveVerb(verbData);
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
// Delete newly created verb (if adapter supports it)
|
|
184
|
+
if ('deleteVerb' in this.storage && typeof this.storage.deleteVerb === 'function') {
|
|
185
|
+
await this.storage.deleteVerb(this.verb.id);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Delete verb metadata with rollback support
|
|
193
|
+
*
|
|
194
|
+
* Rollback strategy:
|
|
195
|
+
* - Restore deleted metadata
|
|
196
|
+
*/
|
|
197
|
+
export class DeleteVerbMetadataOperation {
|
|
198
|
+
constructor(storage, id) {
|
|
199
|
+
this.storage = storage;
|
|
200
|
+
this.id = id;
|
|
201
|
+
this.name = 'DeleteVerbMetadata';
|
|
202
|
+
}
|
|
203
|
+
async execute() {
|
|
204
|
+
// Get metadata before deletion (for rollback)
|
|
205
|
+
const previousMetadata = await this.storage.getVerbMetadata(this.id);
|
|
206
|
+
if (!previousMetadata) {
|
|
207
|
+
// Nothing to delete - no rollback needed
|
|
208
|
+
return async () => { };
|
|
209
|
+
}
|
|
210
|
+
// Delete verb (metadata + vector)
|
|
211
|
+
// Note: StorageAdapter has deleteVerb but not deleteVerbMetadata
|
|
212
|
+
await this.storage.deleteVerb(this.id);
|
|
213
|
+
// Return rollback action
|
|
214
|
+
return async () => {
|
|
215
|
+
// Restore deleted metadata
|
|
216
|
+
await this.storage.saveVerbMetadata(this.id, previousMetadata);
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Update noun metadata with rollback support
|
|
222
|
+
*
|
|
223
|
+
* Rollback strategy:
|
|
224
|
+
* - Restore previous metadata
|
|
225
|
+
*
|
|
226
|
+
* Note: This is a convenience operation that wraps SaveNounMetadataOperation
|
|
227
|
+
* with explicit "update" semantics
|
|
228
|
+
*/
|
|
229
|
+
export class UpdateNounMetadataOperation {
|
|
230
|
+
constructor(storage, id, metadata) {
|
|
231
|
+
this.name = 'UpdateNounMetadata';
|
|
232
|
+
this.saveOperation = new SaveNounMetadataOperation(storage, id, metadata);
|
|
233
|
+
}
|
|
234
|
+
async execute() {
|
|
235
|
+
return await this.saveOperation.execute();
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Update verb metadata with rollback support
|
|
240
|
+
*
|
|
241
|
+
* Rollback strategy:
|
|
242
|
+
* - Restore previous metadata
|
|
243
|
+
*/
|
|
244
|
+
export class UpdateVerbMetadataOperation {
|
|
245
|
+
constructor(storage, id, metadata) {
|
|
246
|
+
this.name = 'UpdateVerbMetadata';
|
|
247
|
+
this.saveOperation = new SaveVerbMetadataOperation(storage, id, metadata);
|
|
248
|
+
}
|
|
249
|
+
async execute() {
|
|
250
|
+
return await this.saveOperation.execute();
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
//# sourceMappingURL=StorageOperations.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transaction Operations
|
|
3
|
+
*
|
|
4
|
+
* Re-exports all transactional operations for storage and indexes.
|
|
5
|
+
* These operations provide atomicity with rollback support.
|
|
6
|
+
*
|
|
7
|
+
* @module transaction/operations
|
|
8
|
+
*/
|
|
9
|
+
export { SaveNounMetadataOperation, SaveNounOperation, DeleteNounMetadataOperation, SaveVerbMetadataOperation, SaveVerbOperation, DeleteVerbMetadataOperation, UpdateNounMetadataOperation, UpdateVerbMetadataOperation } from './StorageOperations.js';
|
|
10
|
+
export { AddToHNSWOperation, AddToTypeAwareHNSWOperation, RemoveFromHNSWOperation, RemoveFromTypeAwareHNSWOperation, AddToMetadataIndexOperation, RemoveFromMetadataIndexOperation, AddToGraphIndexOperation, RemoveFromGraphIndexOperation, BatchAddToHNSWOperation, BatchAddToMetadataIndexOperation } from './IndexOperations.js';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transaction Operations
|
|
3
|
+
*
|
|
4
|
+
* Re-exports all transactional operations for storage and indexes.
|
|
5
|
+
* These operations provide atomicity with rollback support.
|
|
6
|
+
*
|
|
7
|
+
* @module transaction/operations
|
|
8
|
+
*/
|
|
9
|
+
// Storage Operations
|
|
10
|
+
export { SaveNounMetadataOperation, SaveNounOperation, DeleteNounMetadataOperation, SaveVerbMetadataOperation, SaveVerbOperation, DeleteVerbMetadataOperation, UpdateNounMetadataOperation, UpdateVerbMetadataOperation } from './StorageOperations.js';
|
|
11
|
+
// Index Operations
|
|
12
|
+
export { AddToHNSWOperation, AddToTypeAwareHNSWOperation, RemoveFromHNSWOperation, RemoveFromTypeAwareHNSWOperation, AddToMetadataIndexOperation, RemoveFromMetadataIndexOperation, AddToGraphIndexOperation, RemoveFromGraphIndexOperation, BatchAddToHNSWOperation, BatchAddToMetadataIndexOperation } from './IndexOperations.js';
|
|
13
|
+
//# sourceMappingURL=index.js.map
|