@soulcraft/cortex 1.3.1

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.
Files changed (35) hide show
  1. package/LICENSE +16 -0
  2. package/README.md +125 -0
  3. package/dist/graph/NativeGraphAdjacencyIndex.d.ts +92 -0
  4. package/dist/graph/NativeGraphAdjacencyIndex.js +671 -0
  5. package/dist/index.d.ts +22 -0
  6. package/dist/index.js +23 -0
  7. package/dist/license.d.ts +18 -0
  8. package/dist/license.js +172 -0
  9. package/dist/native/NativeEmbeddingEngine.d.ts +79 -0
  10. package/dist/native/NativeEmbeddingEngine.js +302 -0
  11. package/dist/native/NativeRoaringBitmap32.d.ts +114 -0
  12. package/dist/native/NativeRoaringBitmap32.js +221 -0
  13. package/dist/native/ffi.d.ts +20 -0
  14. package/dist/native/ffi.js +48 -0
  15. package/dist/native/index.d.ts +30 -0
  16. package/dist/native/index.js +58 -0
  17. package/dist/native/napi.d.ts +21 -0
  18. package/dist/native/napi.js +88 -0
  19. package/dist/native/types.d.ts +710 -0
  20. package/dist/native/types.js +16 -0
  21. package/dist/plugin.d.ts +22 -0
  22. package/dist/plugin.js +115 -0
  23. package/dist/storage/mmapFileSystemStorage.d.ts +24 -0
  24. package/dist/storage/mmapFileSystemStorage.js +73 -0
  25. package/dist/utils/NativeMetadataIndex.d.ts +185 -0
  26. package/dist/utils/NativeMetadataIndex.js +1274 -0
  27. package/dist/utils/nativeEntityIdMapper.d.ts +84 -0
  28. package/dist/utils/nativeEntityIdMapper.js +134 -0
  29. package/native/brainy-native.darwin-arm64.node +0 -0
  30. package/native/brainy-native.darwin-x64.node +0 -0
  31. package/native/brainy-native.linux-arm64-gnu.node +0 -0
  32. package/native/brainy-native.linux-x64-gnu.node +0 -0
  33. package/native/brainy-native.win32-x64-msvc.node +0 -0
  34. package/native/index.d.ts +1068 -0
  35. package/package.json +66 -0
@@ -0,0 +1,84 @@
1
+ /**
2
+ * EntityIdMapper — Bidirectional UUID ↔ integer mapping for roaring bitmaps
3
+ *
4
+ * Thin TypeScript wrapper around the native Rust NativeEntityIdMapper.
5
+ * All mapping operations execute synchronously in Rust (O(1) HashMap lookups).
6
+ * This wrapper handles async storage I/O (load from storage, persist to storage).
7
+ */
8
+ import type { StorageAdapter } from '@soulcraft/brainy';
9
+ export interface NativeEntityIdMapperWrapperOptions {
10
+ storage: StorageAdapter;
11
+ storageKey?: string;
12
+ }
13
+ /**
14
+ * Bidirectional UUID ↔ integer mapping for roaring bitmap integration.
15
+ * Delegates to native Rust implementation for all mapping operations.
16
+ */
17
+ export declare class NativeEntityIdMapperWrapper {
18
+ private storage;
19
+ private storageKey;
20
+ private native;
21
+ constructor(options: NativeEntityIdMapperWrapperOptions);
22
+ /**
23
+ * Initialize the mapper by loading from storage
24
+ */
25
+ init(): Promise<void>;
26
+ /**
27
+ * Get integer ID for UUID, assigning a new ID if not exists
28
+ */
29
+ getOrAssign(uuid: string): number;
30
+ /**
31
+ * Get integer ID for UUID with immediate persistence guarantee
32
+ */
33
+ getOrAssignSync(uuid: string): Promise<number>;
34
+ /**
35
+ * Get UUID for integer ID
36
+ */
37
+ getUuid(intId: number): string | undefined;
38
+ /**
39
+ * Get integer ID for UUID (without assigning if not exists)
40
+ */
41
+ getInt(uuid: string): number | undefined;
42
+ /**
43
+ * Check if UUID has been assigned an integer ID
44
+ */
45
+ has(uuid: string): boolean;
46
+ /**
47
+ * Remove mapping for UUID
48
+ */
49
+ remove(uuid: string): boolean;
50
+ /**
51
+ * Get total number of mappings
52
+ */
53
+ get size(): number;
54
+ /**
55
+ * Convert array of UUIDs to array of integers
56
+ */
57
+ uuidsToInts(uuids: string[]): number[];
58
+ /**
59
+ * Convert array of integers to array of UUIDs
60
+ */
61
+ intsToUuids(ints: number[]): string[];
62
+ /**
63
+ * Convert iterable of integers to array of UUIDs (for roaring bitmap iteration)
64
+ */
65
+ intsIterableToUuids(ints: Iterable<number>): string[];
66
+ /**
67
+ * Flush mappings to storage
68
+ */
69
+ flush(): Promise<void>;
70
+ /**
71
+ * Clear all mappings
72
+ */
73
+ clear(): Promise<void>;
74
+ /**
75
+ * Get statistics about the mapper
76
+ */
77
+ getStats(): {
78
+ mappings: number;
79
+ nextId: number;
80
+ dirty: boolean;
81
+ memoryEstimate: number;
82
+ };
83
+ }
84
+ //# sourceMappingURL=nativeEntityIdMapper.d.ts.map
@@ -0,0 +1,134 @@
1
+ /**
2
+ * EntityIdMapper — Bidirectional UUID ↔ integer mapping for roaring bitmaps
3
+ *
4
+ * Thin TypeScript wrapper around the native Rust NativeEntityIdMapper.
5
+ * All mapping operations execute synchronously in Rust (O(1) HashMap lookups).
6
+ * This wrapper handles async storage I/O (load from storage, persist to storage).
7
+ */
8
+ import { loadNativeModule } from '../native/index.js';
9
+ /**
10
+ * Bidirectional UUID ↔ integer mapping for roaring bitmap integration.
11
+ * Delegates to native Rust implementation for all mapping operations.
12
+ */
13
+ export class NativeEntityIdMapperWrapper {
14
+ storage;
15
+ storageKey;
16
+ native;
17
+ constructor(options) {
18
+ this.storage = options.storage;
19
+ this.storageKey = options.storageKey || 'brainy:entityIdMapper';
20
+ const bindings = loadNativeModule();
21
+ this.native = new bindings.NativeEntityIdMapper();
22
+ }
23
+ /**
24
+ * Initialize the mapper by loading from storage
25
+ */
26
+ async init() {
27
+ try {
28
+ const metadata = await this.storage.getMetadata(this.storageKey);
29
+ if (metadata && metadata.nextId !== undefined) {
30
+ this.native.loadFromJson(JSON.stringify(metadata));
31
+ }
32
+ }
33
+ catch {
34
+ // First time initialization — native mapper starts empty
35
+ }
36
+ }
37
+ /**
38
+ * Get integer ID for UUID, assigning a new ID if not exists
39
+ */
40
+ getOrAssign(uuid) {
41
+ return this.native.getOrAssign(uuid);
42
+ }
43
+ /**
44
+ * Get integer ID for UUID with immediate persistence guarantee
45
+ */
46
+ async getOrAssignSync(uuid) {
47
+ const id = this.native.getOrAssign(uuid);
48
+ if (this.native.isDirty()) {
49
+ await this.flush();
50
+ }
51
+ return id;
52
+ }
53
+ /**
54
+ * Get UUID for integer ID
55
+ */
56
+ getUuid(intId) {
57
+ return this.native.getUuid(intId) ?? undefined;
58
+ }
59
+ /**
60
+ * Get integer ID for UUID (without assigning if not exists)
61
+ */
62
+ getInt(uuid) {
63
+ return this.native.getInt(uuid) ?? undefined;
64
+ }
65
+ /**
66
+ * Check if UUID has been assigned an integer ID
67
+ */
68
+ has(uuid) {
69
+ return this.native.has(uuid);
70
+ }
71
+ /**
72
+ * Remove mapping for UUID
73
+ */
74
+ remove(uuid) {
75
+ return this.native.remove(uuid);
76
+ }
77
+ /**
78
+ * Get total number of mappings
79
+ */
80
+ get size() {
81
+ return this.native.size;
82
+ }
83
+ /**
84
+ * Convert array of UUIDs to array of integers
85
+ */
86
+ uuidsToInts(uuids) {
87
+ return this.native.uuidsToInts(uuids);
88
+ }
89
+ /**
90
+ * Convert array of integers to array of UUIDs
91
+ */
92
+ intsToUuids(ints) {
93
+ return this.native.intsToUuids(ints);
94
+ }
95
+ /**
96
+ * Convert iterable of integers to array of UUIDs (for roaring bitmap iteration)
97
+ */
98
+ intsIterableToUuids(ints) {
99
+ return this.native.intsToUuids(Array.from(ints));
100
+ }
101
+ /**
102
+ * Flush mappings to storage
103
+ */
104
+ async flush() {
105
+ if (!this.native.isDirty()) {
106
+ return;
107
+ }
108
+ const json = this.native.saveToJson();
109
+ const data = JSON.parse(json);
110
+ await this.storage.saveMetadata(this.storageKey, data);
111
+ // Reload to clear dirty flag (native sets dirty=false on load)
112
+ this.native.loadFromJson(json);
113
+ }
114
+ /**
115
+ * Clear all mappings
116
+ */
117
+ async clear() {
118
+ this.native.clear();
119
+ await this.flush();
120
+ }
121
+ /**
122
+ * Get statistics about the mapper
123
+ */
124
+ getStats() {
125
+ const stats = this.native.getStats();
126
+ return {
127
+ mappings: stats.mappings,
128
+ nextId: stats.nextId,
129
+ dirty: stats.dirty,
130
+ memoryEstimate: stats.memoryEstimate,
131
+ };
132
+ }
133
+ }
134
+ //# sourceMappingURL=nativeEntityIdMapper.js.map