@soulcraft/brainy 5.3.5 → 5.4.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.
@@ -2,18 +2,18 @@
2
2
  * OPFS (Origin Private File System) Storage Adapter
3
3
  * Provides persistent storage for the vector database using the Origin Private File System API
4
4
  */
5
- import { HNSWNoun, HNSWVerb, HNSWNounWithMetadata, HNSWVerbWithMetadata, StatisticsData } from '../../coreTypes.js';
5
+ import { StatisticsData } from '../../coreTypes.js';
6
6
  import { BaseStorage, StorageBatchConfig } from '../baseStorage.js';
7
7
  import '../../types/fileSystemTypes.js';
8
- type HNSWNode = HNSWNoun;
9
- /**
10
- * Type alias for HNSWVerb to make the code more readable
11
- */
12
- type Edge = HNSWVerb;
13
- type HNSWNoun_internal = HNSWNoun;
14
8
  /**
15
9
  * OPFS storage adapter for browser environments
16
10
  * Uses the Origin Private File System API to store data persistently
11
+ *
12
+ * v5.4.0: Type-aware storage now built into BaseStorage
13
+ * - Removed 10 *_internal method overrides (now inherit from BaseStorage's type-first implementation)
14
+ * - Removed 2 pagination method overrides (getNounsWithPagination, getVerbsWithPagination)
15
+ * - Updated HNSW methods to use BaseStorage's getNoun/saveNoun (type-first paths)
16
+ * - All operations now use type-first paths: entities/nouns/{type}/vectors/{shard}/{id}.json
17
17
  */
18
18
  export declare class OPFSStorage extends BaseStorage {
19
19
  private rootDir;
@@ -61,85 +61,6 @@ export declare class OPFSStorage extends BaseStorage {
61
61
  * @returns Promise that resolves to true if persistent storage is granted, false otherwise
62
62
  */
63
63
  isPersistent(): Promise<boolean>;
64
- /**
65
- * Save a noun to storage
66
- */
67
- protected saveNoun_internal(noun: HNSWNoun_internal): Promise<void>;
68
- /**
69
- * Get a noun from storage (internal implementation)
70
- * Combines vector data from file with metadata from getNounMetadata()
71
- */
72
- protected getNoun_internal(id: string): Promise<HNSWNoun_internal | null>;
73
- /**
74
- * Get nouns by noun type (internal implementation)
75
- * @param nounType The noun type to filter by
76
- * @returns Promise that resolves to an array of nouns of the specified noun type
77
- */
78
- protected getNounsByNounType_internal(nounType: string): Promise<HNSWNoun[]>;
79
- /**
80
- * Get nodes by noun type
81
- * @param nounType The noun type to filter by
82
- * @returns Promise that resolves to an array of nodes of the specified noun type
83
- */
84
- protected getNodesByNounType(nounType: string): Promise<HNSWNode[]>;
85
- /**
86
- * Delete a noun from storage (internal implementation)
87
- */
88
- protected deleteNoun_internal(id: string): Promise<void>;
89
- /**
90
- * Delete a node from storage
91
- */
92
- protected deleteNode(id: string): Promise<void>;
93
- /**
94
- * Save a verb to storage (internal implementation)
95
- */
96
- protected saveVerb_internal(verb: HNSWVerb): Promise<void>;
97
- /**
98
- * Save an edge to storage
99
- */
100
- protected saveEdge(edge: Edge): Promise<void>;
101
- /**
102
- * Get a verb from storage (internal implementation)
103
- * v4.0.0: Returns ONLY vector + core relational fields (no metadata field)
104
- * Base class combines with metadata via getVerb() -> HNSWVerbWithMetadata
105
- */
106
- protected getVerb_internal(id: string): Promise<HNSWVerb | null>;
107
- /**
108
- * Get an edge from storage
109
- */
110
- protected getEdge(id: string): Promise<Edge | null>;
111
- /**
112
- * Get all edges from storage
113
- */
114
- protected getAllEdges(): Promise<Edge[]>;
115
- /**
116
- * Get verbs by source (internal implementation)
117
- */
118
- protected getVerbsBySource_internal(sourceId: string): Promise<HNSWVerbWithMetadata[]>;
119
- /**
120
- * Get edges by source
121
- */
122
- protected getEdgesBySource(sourceId: string): Promise<HNSWVerbWithMetadata[]>;
123
- /**
124
- * Get verbs by target (internal implementation)
125
- */
126
- protected getVerbsByTarget_internal(targetId: string): Promise<HNSWVerbWithMetadata[]>;
127
- /**
128
- * Get edges by target
129
- */
130
- protected getEdgesByTarget(targetId: string): Promise<HNSWVerbWithMetadata[]>;
131
- /**
132
- * Get verbs by type (internal implementation)
133
- */
134
- protected getVerbsByType_internal(type: string): Promise<HNSWVerbWithMetadata[]>;
135
- /**
136
- * Get edges by type
137
- */
138
- protected getEdgesByType(type: string): Promise<HNSWVerbWithMetadata[]>;
139
- /**
140
- * Delete a verb from storage (internal implementation)
141
- */
142
- protected deleteVerb_internal(id: string): Promise<void>;
143
64
  /**
144
65
  * Delete an edge from storage
145
66
  */
@@ -268,41 +189,6 @@ export declare class OPFSStorage extends BaseStorage {
268
189
  * @param options Pagination and filter options
269
190
  * @returns Promise that resolves to a paginated result of nouns
270
191
  */
271
- getNounsWithPagination(options?: {
272
- limit?: number;
273
- cursor?: string;
274
- filter?: {
275
- nounType?: string | string[];
276
- service?: string | string[];
277
- metadata?: Record<string, any>;
278
- };
279
- }): Promise<{
280
- items: HNSWNounWithMetadata[];
281
- totalCount?: number;
282
- hasMore: boolean;
283
- nextCursor?: string;
284
- }>;
285
- /**
286
- * Get verbs with pagination support
287
- * @param options Pagination and filter options
288
- * @returns Promise that resolves to a paginated result of verbs
289
- */
290
- getVerbsWithPagination(options?: {
291
- limit?: number;
292
- cursor?: string;
293
- filter?: {
294
- verbType?: string | string[];
295
- sourceId?: string | string[];
296
- targetId?: string | string[];
297
- service?: string | string[];
298
- metadata?: Record<string, any>;
299
- };
300
- }): Promise<{
301
- items: HNSWVerbWithMetadata[];
302
- totalCount?: number;
303
- hasMore: boolean;
304
- nextCursor?: string;
305
- }>;
306
192
  /**
307
193
  * Initialize counts from OPFS storage
308
194
  */
@@ -318,15 +204,17 @@ export declare class OPFSStorage extends BaseStorage {
318
204
  /**
319
205
  * Get a noun's vector for HNSW rebuild
320
206
  */
207
+ /**
208
+ * Get vector for a noun
209
+ * v5.4.0: Uses BaseStorage's getNoun (type-first paths)
210
+ */
321
211
  getNounVector(id: string): Promise<number[] | null>;
322
212
  private hnswLocks;
323
213
  /**
324
214
  * Save HNSW graph data for a noun
325
- * Storage path: nouns/hnsw/{shard}/{id}.json
326
215
  *
327
- * CRITICAL FIX (v4.10.1): Mutex locking to prevent race conditions during concurrent HNSW updates
328
- * Browser is single-threaded but async operations can interleave - mutex prevents this
329
- * Prevents data corruption when multiple entities connect to same neighbor simultaneously
216
+ * v5.4.0: Uses BaseStorage's getNoun/saveNoun (type-first paths)
217
+ * CRITICAL: Preserves mutex locking to prevent read-modify-write races
330
218
  */
331
219
  saveHNSWData(nounId: string, hnswData: {
332
220
  level: number;
@@ -334,7 +222,7 @@ export declare class OPFSStorage extends BaseStorage {
334
222
  }): Promise<void>;
335
223
  /**
336
224
  * Get HNSW graph data for a noun
337
- * Storage path: nouns/hnsw/{shard}/{id}.json
225
+ * v5.4.0: Uses BaseStorage's getNoun (type-first paths)
338
226
  */
339
227
  getHNSWData(nounId: string): Promise<{
340
228
  level: number;
@@ -359,4 +247,3 @@ export declare class OPFSStorage extends BaseStorage {
359
247
  maxLevel: number;
360
248
  } | null>;
361
249
  }
362
- export {};