@soulcraft/cor 3.0.0-rc.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.
- package/LICENSE +16 -0
- package/README.md +328 -0
- package/dist/aggregation/NativeAggregationEngine.d.ts +118 -0
- package/dist/aggregation/NativeAggregationEngine.js +186 -0
- package/dist/cli.d.ts +12 -0
- package/dist/cli.js +236 -0
- package/dist/graph/GraphAccelerationAdapter.d.ts +153 -0
- package/dist/graph/GraphAccelerationAdapter.js +326 -0
- package/dist/graph/NativeGraphAdjacencyIndex.d.ts +286 -0
- package/dist/graph/NativeGraphAdjacencyIndex.js +944 -0
- package/dist/hnsw/AdaptiveDiskAnnModeSelector.d.ts +187 -0
- package/dist/hnsw/AdaptiveDiskAnnModeSelector.js +313 -0
- package/dist/hnsw/NativeDiskAnnWrapper.d.ts +489 -0
- package/dist/hnsw/NativeDiskAnnWrapper.js +1456 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +29 -0
- package/dist/legacyLayoutGuard.d.ts +93 -0
- package/dist/legacyLayoutGuard.js +237 -0
- package/dist/license/constants.d.ts +30 -0
- package/dist/license/constants.js +30 -0
- package/dist/license/onlineValidator.d.ts +43 -0
- package/dist/license/onlineValidator.js +225 -0
- package/dist/license/types.d.ts +39 -0
- package/dist/license/types.js +5 -0
- package/dist/license.d.ts +64 -0
- package/dist/license.js +165 -0
- package/dist/migration/MigrationCoordinator.d.ts +171 -0
- package/dist/migration/MigrationCoordinator.js +249 -0
- package/dist/migration/indexEpochGuard.d.ts +163 -0
- package/dist/migration/indexEpochGuard.js +202 -0
- package/dist/native/NativeEmbeddingEngine.d.ts +79 -0
- package/dist/native/NativeEmbeddingEngine.js +318 -0
- package/dist/native/NativeRoaringBitmap32.d.ts +114 -0
- package/dist/native/NativeRoaringBitmap32.js +221 -0
- package/dist/native/ffi.d.ts +20 -0
- package/dist/native/ffi.js +48 -0
- package/dist/native/idMapperTestSupport.d.ts +67 -0
- package/dist/native/idMapperTestSupport.js +112 -0
- package/dist/native/index.d.ts +49 -0
- package/dist/native/index.js +87 -0
- package/dist/native/napi.d.ts +21 -0
- package/dist/native/napi.js +88 -0
- package/dist/native/types.d.ts +1298 -0
- package/dist/native/types.js +16 -0
- package/dist/plugin.d.ts +50 -0
- package/dist/plugin.js +388 -0
- package/dist/providerContracts.d.ts +277 -0
- package/dist/providerContracts.js +38 -0
- package/dist/resource/OsMemoryProbe.d.ts +175 -0
- package/dist/resource/OsMemoryProbe.js +206 -0
- package/dist/resource/ResourceManager.d.ts +491 -0
- package/dist/resource/ResourceManager.js +960 -0
- package/dist/utils/ColumnManifest.d.ts +97 -0
- package/dist/utils/ColumnManifest.js +129 -0
- package/dist/utils/NativeColumnStore.d.ts +284 -0
- package/dist/utils/NativeColumnStore.js +685 -0
- package/dist/utils/NativeMetadataIndex.d.ts +882 -0
- package/dist/utils/NativeMetadataIndex.js +2631 -0
- package/dist/utils/NativeUnifiedCache.d.ts +87 -0
- package/dist/utils/NativeUnifiedCache.js +273 -0
- package/dist/utils/binaryIdMapperFactory.d.ts +59 -0
- package/dist/utils/binaryIdMapperFactory.js +94 -0
- package/dist/utils/collation.d.ts +30 -0
- package/dist/utils/collation.js +40 -0
- package/dist/utils/columnStoreTypes.d.ts +161 -0
- package/dist/utils/columnStoreTypes.js +29 -0
- package/dist/utils/nativeBinaryEntityIdMapper.d.ts +211 -0
- package/dist/utils/nativeBinaryEntityIdMapper.js +381 -0
- package/dist/utils/nativeEntityIdMapper.d.ts +111 -0
- package/dist/utils/nativeEntityIdMapper.js +170 -0
- package/docs/ADR-002-diskann-100-percent-rust.md +294 -0
- package/docs/ADR-003-semantic-time-travel.md +100 -0
- package/docs/aggregation.md +251 -0
- package/docs/comparison.md +162 -0
- package/docs/deployment-limits.md +87 -0
- package/docs/diskann.md +184 -0
- package/docs/migration-3.0.md +396 -0
- package/docs/performance-budget.md +274 -0
- package/docs/performance.md +117 -0
- package/docs/scaling.md +439 -0
- package/docs/snapshot-safety.md +246 -0
- package/docs/u64-id-space.md +214 -0
- package/docs/verification-report.md +670 -0
- package/native/brainy-native.node +0 -0
- package/native/index.d.ts +3916 -0
- package/package.json +92 -0
- package/scripts/migrate-cortex-2x-to-3x.mjs +970 -0
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module utils/columnStoreTypes
|
|
3
|
+
* @description Cor-local type definitions for the native column store bridge.
|
|
4
|
+
*
|
|
5
|
+
* These mirror `@soulcraft/brainy`'s internal `indexes/columnStore/types`, which
|
|
6
|
+
* is NOT a published export of brainy 7.24.0. Cor defines them locally so the
|
|
7
|
+
* native `ColumnStoreProvider` implementation compiles against published brainy
|
|
8
|
+
* while staying byte-compatible with brainy's `.cidx` segments and manifests.
|
|
9
|
+
*
|
|
10
|
+
* The `ValueType` enum values are load-bearing: they are written into segment
|
|
11
|
+
* headers and manifests and MUST match brainy's enum exactly (Number=0, Float=1,
|
|
12
|
+
* String=2, Boolean=3). Keep in lockstep if brainy ever adds a value type.
|
|
13
|
+
*/
|
|
14
|
+
import type { StorageAdapter } from '@soulcraft/brainy';
|
|
15
|
+
import type { RoaringBitmap32 } from '../native/NativeRoaringBitmap32.js';
|
|
16
|
+
/**
|
|
17
|
+
* @description Discriminator for a column's value encoding, identical to
|
|
18
|
+
* brainy's `ValueType`. Numbers are load-bearing (persisted in headers/manifests).
|
|
19
|
+
*/
|
|
20
|
+
export declare enum ValueType {
|
|
21
|
+
/** i64 little-endian — timestamps, integer counts. */
|
|
22
|
+
Number = 0,
|
|
23
|
+
/** f64 little-endian — prices, scores, ratings. */
|
|
24
|
+
Float = 1,
|
|
25
|
+
/** u32-length-prefixed UTF-8 — status, category, names. */
|
|
26
|
+
String = 2,
|
|
27
|
+
/** i64 (0 or 1) — flags, toggles. */
|
|
28
|
+
Boolean = 3
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* @description Metadata for a single persisted segment within a field manifest.
|
|
32
|
+
* Matches brainy's `SegmentMeta` shape so manifests are interchangeable.
|
|
33
|
+
*/
|
|
34
|
+
export interface SegmentMeta {
|
|
35
|
+
/** Segment id, unique within the field (monotonic counter). */
|
|
36
|
+
id: number;
|
|
37
|
+
/** LSM compaction level. 0 = freshest (direct from the tail buffer). */
|
|
38
|
+
level: number;
|
|
39
|
+
/** Number of entries in the segment (including tombstoned). */
|
|
40
|
+
count: number;
|
|
41
|
+
/** Minimum value in the sorted column (zone-map pruning). */
|
|
42
|
+
minValue: number | string;
|
|
43
|
+
/** Maximum value in the sorted column. */
|
|
44
|
+
maxValue: number | string;
|
|
45
|
+
/** Relative file name within the field directory (e.g. `L0-000001.cidx`). */
|
|
46
|
+
file: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* @description Per-field manifest payload, persisted as JSON at
|
|
50
|
+
* `_column_index/{field}/MANIFEST.json`. Matches brainy's `ManifestData`.
|
|
51
|
+
*/
|
|
52
|
+
export interface ManifestData {
|
|
53
|
+
/** Format version, bumped on every save. */
|
|
54
|
+
version: number;
|
|
55
|
+
/** Field name this manifest covers. */
|
|
56
|
+
field: string;
|
|
57
|
+
/** Value type for all segments in this field. */
|
|
58
|
+
valueType: ValueType;
|
|
59
|
+
/** Whether this is a multi-value field (one entity → many entries). */
|
|
60
|
+
multiValue: boolean;
|
|
61
|
+
/** All known segments, ordered by level then id. */
|
|
62
|
+
segments: SegmentMeta[];
|
|
63
|
+
/** Monotonically increasing segment id counter. */
|
|
64
|
+
nextSegmentId: number;
|
|
65
|
+
/** Whether the initial build from existing entities has completed. */
|
|
66
|
+
buildComplete: boolean;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* @description The slice of brainy's `EntityIdMapper` that callers of the column
|
|
70
|
+
* store actually use. Cor's metadata index builds one of these backed by the
|
|
71
|
+
* native id mapper. Only `getUuid` is exercised by brainy's `orderBy` path; the
|
|
72
|
+
* rest mirror the brainy mapper surface that other call sites touch.
|
|
73
|
+
*/
|
|
74
|
+
export interface EntityIdMapperLike {
|
|
75
|
+
/** UUID for an int id, or undefined if unknown. */
|
|
76
|
+
getUuid(intId: number): string | undefined;
|
|
77
|
+
/** Int id for a UUID without assigning, or undefined if unknown. */
|
|
78
|
+
getInt(uuid: string): number | undefined;
|
|
79
|
+
/** Int id for a UUID, assigning a new one if absent. */
|
|
80
|
+
getOrAssign(uuid: string): number;
|
|
81
|
+
/** Resolve an iterable of int ids to UUIDs (unknown ids skipped). */
|
|
82
|
+
intsIterableToUuids(ints: Iterable<number>): string[];
|
|
83
|
+
/**
|
|
84
|
+
* Optional: reconstruct the UUID↔int mapping from the restored canonical
|
|
85
|
+
* entities. Brainy 8.0 `restore()` feature-detects this (`typeof
|
|
86
|
+
* idMapper.rebuild === 'function'`) and awaits it BEFORE rebuilding the
|
|
87
|
+
* metadata/vector/graph indexes, so a native adjacency keyed on entity ints
|
|
88
|
+
* resolves verb endpoints against the snapshot's assignments rather than
|
|
89
|
+
* stale/missing ints. Absent on the JS mapper (whose ints are re-derived by
|
|
90
|
+
* the metadata rebuild itself).
|
|
91
|
+
*/
|
|
92
|
+
rebuild?(): Promise<void>;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* @description The provider contract cor implements and registers with brainy
|
|
96
|
+
* as the column store. Structurally identical to brainy's `ColumnStoreProvider`;
|
|
97
|
+
* cor's `RoaringBitmap32` is binary-compatible with brainy's, so the bitmap
|
|
98
|
+
* return/argument types interoperate at runtime.
|
|
99
|
+
*/
|
|
100
|
+
export interface ColumnStoreProvider {
|
|
101
|
+
/**
|
|
102
|
+
* Initialize: discover fields, load manifests + segments, re-apply tombstones.
|
|
103
|
+
* @param storage - Storage adapter for segment/manifest I/O.
|
|
104
|
+
* @param idMapper - Shared entity id mapper for UUID ↔ int conversion.
|
|
105
|
+
*/
|
|
106
|
+
init(storage: StorageAdapter, idMapper: EntityIdMapperLike): Promise<void>;
|
|
107
|
+
/**
|
|
108
|
+
* Index an entity's field values (synchronous; buffered until flush).
|
|
109
|
+
* @param entityIntId - The entity's u32 int id.
|
|
110
|
+
* @param fields - Map of field name → value (array = multi-value).
|
|
111
|
+
*/
|
|
112
|
+
addEntity(entityIntId: number, fields: Record<string, unknown>): void;
|
|
113
|
+
/**
|
|
114
|
+
* Tombstone an entity across all indexed fields (synchronous).
|
|
115
|
+
* @param entityIntId - The entity's u32 int id.
|
|
116
|
+
*/
|
|
117
|
+
removeEntity(entityIntId: number): void;
|
|
118
|
+
/**
|
|
119
|
+
* Point filter: entity int ids where `field` equals `value`.
|
|
120
|
+
* @param field - Field to filter.
|
|
121
|
+
* @param value - Exact value to match.
|
|
122
|
+
*/
|
|
123
|
+
filter(field: string, value: unknown): Promise<RoaringBitmap32>;
|
|
124
|
+
/**
|
|
125
|
+
* Range filter: entity int ids where `field` is within `[min, max]`.
|
|
126
|
+
* @param field - Field to filter.
|
|
127
|
+
* @param min - Lower bound (undefined = open).
|
|
128
|
+
* @param max - Upper bound (undefined = open).
|
|
129
|
+
*/
|
|
130
|
+
rangeQuery(field: string, min?: unknown, max?: unknown): Promise<RoaringBitmap32>;
|
|
131
|
+
/**
|
|
132
|
+
* Sort top-K entity int ids by `field` in `order`.
|
|
133
|
+
* @param field - Field to sort by.
|
|
134
|
+
* @param order - 'asc' or 'desc'.
|
|
135
|
+
* @param k - Maximum results.
|
|
136
|
+
*/
|
|
137
|
+
sortTopK(field: string, order: 'asc' | 'desc', k: number): Promise<number[]>;
|
|
138
|
+
/**
|
|
139
|
+
* Filtered sort top-K: `sortTopK` restricted to `filterBitmap`.
|
|
140
|
+
* @param filterBitmap - Candidate entity int ids.
|
|
141
|
+
* @param field - Field to sort by.
|
|
142
|
+
* @param order - 'asc' or 'desc'.
|
|
143
|
+
* @param k - Maximum results.
|
|
144
|
+
*/
|
|
145
|
+
filteredSortTopK(filterBitmap: RoaringBitmap32, field: string, order: 'asc' | 'desc', k: number): Promise<number[]>;
|
|
146
|
+
/**
|
|
147
|
+
* All distinct values for a field, as ascending strings.
|
|
148
|
+
* @param field - Field name.
|
|
149
|
+
*/
|
|
150
|
+
getFilterValues(field: string): Promise<string[]>;
|
|
151
|
+
/**
|
|
152
|
+
* Whether a field has any indexed data.
|
|
153
|
+
* @param field - Field name.
|
|
154
|
+
*/
|
|
155
|
+
hasField(field: string): boolean;
|
|
156
|
+
/** Flush all tail buffers to L0 segments and save manifests. */
|
|
157
|
+
flush(): Promise<void>;
|
|
158
|
+
/** Flush and release all resources. */
|
|
159
|
+
close(): Promise<void>;
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=columnStoreTypes.d.ts.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module utils/columnStoreTypes
|
|
3
|
+
* @description Cor-local type definitions for the native column store bridge.
|
|
4
|
+
*
|
|
5
|
+
* These mirror `@soulcraft/brainy`'s internal `indexes/columnStore/types`, which
|
|
6
|
+
* is NOT a published export of brainy 7.24.0. Cor defines them locally so the
|
|
7
|
+
* native `ColumnStoreProvider` implementation compiles against published brainy
|
|
8
|
+
* while staying byte-compatible with brainy's `.cidx` segments and manifests.
|
|
9
|
+
*
|
|
10
|
+
* The `ValueType` enum values are load-bearing: they are written into segment
|
|
11
|
+
* headers and manifests and MUST match brainy's enum exactly (Number=0, Float=1,
|
|
12
|
+
* String=2, Boolean=3). Keep in lockstep if brainy ever adds a value type.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* @description Discriminator for a column's value encoding, identical to
|
|
16
|
+
* brainy's `ValueType`. Numbers are load-bearing (persisted in headers/manifests).
|
|
17
|
+
*/
|
|
18
|
+
export var ValueType;
|
|
19
|
+
(function (ValueType) {
|
|
20
|
+
/** i64 little-endian — timestamps, integer counts. */
|
|
21
|
+
ValueType[ValueType["Number"] = 0] = "Number";
|
|
22
|
+
/** f64 little-endian — prices, scores, ratings. */
|
|
23
|
+
ValueType[ValueType["Float"] = 1] = "Float";
|
|
24
|
+
/** u32-length-prefixed UTF-8 — status, category, names. */
|
|
25
|
+
ValueType[ValueType["String"] = 2] = "String";
|
|
26
|
+
/** i64 (0 or 1) — flags, toggles. */
|
|
27
|
+
ValueType[ValueType["Boolean"] = 3] = "Boolean";
|
|
28
|
+
})(ValueType || (ValueType = {}));
|
|
29
|
+
//# sourceMappingURL=columnStoreTypes.js.map
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module utils/nativeBinaryEntityIdMapper
|
|
3
|
+
* @description TypeScript wrapper around cor's native binary
|
|
4
|
+
* `BinaryIdMapper`. Implements brainy's `EntityIdMapperProvider` so the
|
|
5
|
+
* mmap-backed billion-scale mapper is a drop-in for the existing
|
|
6
|
+
* JSON-persisted one.
|
|
7
|
+
*
|
|
8
|
+
* ## When this engages
|
|
9
|
+
*
|
|
10
|
+
* The cor plugin registers this wrapper as the `'entityIdMapper'`
|
|
11
|
+
* provider when the storage adapter exposes `getBinaryBlobPath()` (i.e.
|
|
12
|
+
* filesystem-backed storage with cor's 2.4.0 #2 mmap-vector layer).
|
|
13
|
+
* Cloud-storage adapters fall back to the JSON variant
|
|
14
|
+
* (`NativeEntityIdMapperWrapper`) since they have no local-path concept.
|
|
15
|
+
*
|
|
16
|
+
* ## UUID format conversion
|
|
17
|
+
*
|
|
18
|
+
* Brainy passes UUIDs as strings (typically the canonical 36-char
|
|
19
|
+
* `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`). The native side works in
|
|
20
|
+
* 16-byte Buffers. This wrapper converts at the boundary. Non-canonical
|
|
21
|
+
* UUID strings (any other 32-hex-digit form) are also accepted.
|
|
22
|
+
*
|
|
23
|
+
* ## Concurrency
|
|
24
|
+
*
|
|
25
|
+
* `getOrAssign` is atomic across concurrent callers for the same UUID
|
|
26
|
+
* (256 sharded per-UUID mutexes in the native layer). Lookups are
|
|
27
|
+
* lock-free. The wrapper holds no JS-side mutable state besides the
|
|
28
|
+
* native handle.
|
|
29
|
+
*
|
|
30
|
+
* ## IdSpace (Piece 10)
|
|
31
|
+
*
|
|
32
|
+
* The wrapper supports two entity-int wire widths:
|
|
33
|
+
*
|
|
34
|
+
* - `'u32'` (default): cortex 2.x compatible — JS `number` throughout,
|
|
35
|
+
* capped at 4.29 B entities. Persists in the legacy `int_to_uuid.bin`
|
|
36
|
+
* v1 header.
|
|
37
|
+
* - `'u64'`: opt-in via `idSpace: 'u64'`. The native layer's `number`
|
|
38
|
+
* surface throws in this mode, so the wrapper transparently routes
|
|
39
|
+
* the `EntityIdMapperProvider` methods through the BigInt napi
|
|
40
|
+
* siblings and converts BigInt → number at the boundary. Entity ints
|
|
41
|
+
* above `Number.MAX_SAFE_INTEGER` (2^53 - 1 = ~9 PB of entities)
|
|
42
|
+
* throw a clear `EntityIdSpaceExceeded` error so callers get a loud
|
|
43
|
+
* failure rather than a silent precision loss.
|
|
44
|
+
*
|
|
45
|
+
* The `getOrAssignBig` / `getIntBig` / `getUuidBig` / `sizeBig`
|
|
46
|
+
* sibling methods are available on both modes and always return
|
|
47
|
+
* `bigint` losslessly — use them in u64-aware code paths that need
|
|
48
|
+
* the full u64 range.
|
|
49
|
+
*/
|
|
50
|
+
import type { StorageAdapter } from '@soulcraft/brainy';
|
|
51
|
+
import type { EntityIdMapperProvider } from '../providerContracts.js';
|
|
52
|
+
export interface NativeBinaryEntityIdMapperOptions {
|
|
53
|
+
/** Storage adapter — required for binary blob path resolution. */
|
|
54
|
+
storage: StorageAdapter;
|
|
55
|
+
/**
|
|
56
|
+
* Override the relative path under storage for the uuid_to_int file.
|
|
57
|
+
* Default `_id_mapper/uuid_to_int.mkv`.
|
|
58
|
+
*/
|
|
59
|
+
uuidToIntKey?: string;
|
|
60
|
+
/**
|
|
61
|
+
* Override the relative path under storage for the int_to_uuid file.
|
|
62
|
+
* Default `_id_mapper/int_to_uuid.bin`.
|
|
63
|
+
*/
|
|
64
|
+
intToUuidKey?: string;
|
|
65
|
+
/** Sparse file size for int_to_uuid. Default 32 GB. */
|
|
66
|
+
intToUuidSize?: bigint;
|
|
67
|
+
/** Sparse file size for uuid_to_int. Default 32 GB. */
|
|
68
|
+
uuidToIntSize?: bigint;
|
|
69
|
+
/** Bucket capacity in the MmapKv. Default 16. */
|
|
70
|
+
bucketCapacity?: number;
|
|
71
|
+
/** Maximum extendible-hash directory depth. Default 28. */
|
|
72
|
+
maxGlobalDepth?: number;
|
|
73
|
+
/**
|
|
74
|
+
* Entity-int wire width. **`'u64'` is the default** for cor 3.0 —
|
|
75
|
+
* supports `u64::MAX - 1` entities with no measurable perf cost
|
|
76
|
+
* (audit: 4 extra bytes per int_to_uuid slot, no impact on the hot
|
|
77
|
+
* paths per `findPerfGates.test.ts`). `'u32'` is available for the
|
|
78
|
+
* brainy 7.x-compatible cap at 4.29 B entities but is no longer the
|
|
79
|
+
* default — cor 3.0's design floor of 1 B+ entities makes u32
|
|
80
|
+
* the wrong default for production.
|
|
81
|
+
*
|
|
82
|
+
* The `EntityIdMapperProvider` `number`-typed methods still work in
|
|
83
|
+
* U64 mode by routing through the BigInt napi siblings; entity ints
|
|
84
|
+
* above `Number.MAX_SAFE_INTEGER` (2^53 - 1) throw an explicit
|
|
85
|
+
* `EntityIdSpaceExceeded` error.
|
|
86
|
+
*
|
|
87
|
+
* Ignored on open when the underlying file's header disagrees: the
|
|
88
|
+
* on-disk format wins and any mismatch is surfaced as a hard error.
|
|
89
|
+
*/
|
|
90
|
+
idSpace?: 'u32' | 'u64';
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Thrown when a U64-mode mapper allocates or returns an entity int
|
|
94
|
+
* above `Number.MAX_SAFE_INTEGER` (2^53 - 1). At this point a JS
|
|
95
|
+
* `number` can no longer represent the value losslessly; callers must
|
|
96
|
+
* switch to the BigInt sibling methods (`getOrAssignBig`,
|
|
97
|
+
* `getIntBig`, `getUuidBig`).
|
|
98
|
+
*/
|
|
99
|
+
export declare class EntityIdSpaceExceeded extends Error {
|
|
100
|
+
/** The u64 entity int that exceeded the safe-integer ceiling. */
|
|
101
|
+
readonly value: bigint;
|
|
102
|
+
/** The method that was called (`'getOrAssign'`, `'getInt'`, etc.). */
|
|
103
|
+
readonly method: string;
|
|
104
|
+
constructor(method: string, value: bigint);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Drop-in `EntityIdMapperProvider` backed by the native `BinaryIdMapper`.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* const mapper = new NativeBinaryEntityIdMapperWrapper({ storage })
|
|
112
|
+
* await mapper.init()
|
|
113
|
+
* const intId = mapper.getOrAssign('12345678-1234-5678-1234-567812345678')
|
|
114
|
+
* const uuid = mapper.getUuid(intId)
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
export declare class NativeBinaryEntityIdMapperWrapper implements EntityIdMapperProvider {
|
|
118
|
+
private storage;
|
|
119
|
+
private uuidToIntKey;
|
|
120
|
+
private intToUuidKey;
|
|
121
|
+
private intToUuidSize;
|
|
122
|
+
private uuidToIntSize;
|
|
123
|
+
private bucketCapacity;
|
|
124
|
+
private maxGlobalDepth;
|
|
125
|
+
private requestedIdSpace;
|
|
126
|
+
/**
|
|
127
|
+
* The actual IdSpace of the open mapper, sourced from the native
|
|
128
|
+
* binding's `idSpace()` reflection after `init()`. The on-disk
|
|
129
|
+
* header wins over `requestedIdSpace` (which may be ignored at
|
|
130
|
+
* `openExisting` time).
|
|
131
|
+
*/
|
|
132
|
+
private resolvedIdSpace;
|
|
133
|
+
private native;
|
|
134
|
+
private initialized;
|
|
135
|
+
constructor(options: NativeBinaryEntityIdMapperOptions);
|
|
136
|
+
init(): Promise<void>;
|
|
137
|
+
/**
|
|
138
|
+
* Report the mapper's actual IdSpace mode. Returns `'u32'` before
|
|
139
|
+
* `init()` (the default the wrapper assumes); after init, returns the
|
|
140
|
+
* mode reported by the native binding (which is authoritative).
|
|
141
|
+
*/
|
|
142
|
+
getIdSpace(): 'u32' | 'u64';
|
|
143
|
+
/**
|
|
144
|
+
* Allocate or retrieve the entity int for `uuid`. Returns a JS
|
|
145
|
+
* `number`. In U64 mode, routes through the BigInt sibling and
|
|
146
|
+
* throws {@link EntityIdSpaceExceeded} if the allocated int exceeds
|
|
147
|
+
* `Number.MAX_SAFE_INTEGER` — at that point the caller MUST switch
|
|
148
|
+
* to `getOrAssignBig` for the full u64 range.
|
|
149
|
+
*/
|
|
150
|
+
getOrAssign(uuid: string): number;
|
|
151
|
+
/**
|
|
152
|
+
* Look up the UUID for `intId`. Accepts a JS `number` — in U64 mode
|
|
153
|
+
* this is a lossy conversion above 2^53; use {@link getUuidBig} for
|
|
154
|
+
* the full u64 range.
|
|
155
|
+
*/
|
|
156
|
+
getUuid(intId: number): string | undefined;
|
|
157
|
+
/**
|
|
158
|
+
* Look up the entity int for `uuid`. Returns a JS `number`. In U64
|
|
159
|
+
* mode throws {@link EntityIdSpaceExceeded} if the int exceeds
|
|
160
|
+
* `Number.MAX_SAFE_INTEGER`.
|
|
161
|
+
*/
|
|
162
|
+
getInt(uuid: string): number | undefined;
|
|
163
|
+
remove(uuid: string): boolean;
|
|
164
|
+
flush(): Promise<void>;
|
|
165
|
+
clear(): Promise<void>;
|
|
166
|
+
/**
|
|
167
|
+
* Materialise every live int id into a JS `number[]`. **U32 mode
|
|
168
|
+
* only.** U64 mode throws — the native binding refuses to allocate
|
|
169
|
+
* a giant JS array at the scale a U64 brain implies. Iterate via
|
|
170
|
+
* the BigInt sibling iterator (TBD — a follow-up surfaces it on the
|
|
171
|
+
* wrapper) for U64 brains.
|
|
172
|
+
*/
|
|
173
|
+
getAllIntIds(): number[];
|
|
174
|
+
intsIterableToUuids(ints: Iterable<number>): string[];
|
|
175
|
+
/**
|
|
176
|
+
* @description Batch-resolve entity ints to their UUIDs in one native
|
|
177
|
+
* call (ADR-006 Q5) — the provider path brainy uses to hydrate a
|
|
178
|
+
* `Subgraph`'s `nodes` column. One boundary crossing instead of N
|
|
179
|
+
* per-int `getUuidBig` calls when a viz/export renders many rows. An
|
|
180
|
+
* unmapped int yields `''` so the result stays index-aligned with the
|
|
181
|
+
* input.
|
|
182
|
+
* @param ints - The entity ints to resolve (a `BigInt64Array`, the
|
|
183
|
+
* `Subgraph.nodes` column).
|
|
184
|
+
* @returns UUID strings index-aligned with `ints` (`''` for unmapped).
|
|
185
|
+
*/
|
|
186
|
+
entityIntsToUuids(ints: BigInt64Array): string[];
|
|
187
|
+
get size(): number;
|
|
188
|
+
/**
|
|
189
|
+
* Allocate or retrieve the entity int for `uuid` as a `bigint`.
|
|
190
|
+
* Lossless across the full u64 range; safe to call in either mode.
|
|
191
|
+
*/
|
|
192
|
+
getOrAssignBig(uuid: string): bigint;
|
|
193
|
+
/** Look up the entity int for `uuid` as a `bigint`. */
|
|
194
|
+
getIntBig(uuid: string): bigint | undefined;
|
|
195
|
+
/** Look up the UUID for `int` (passed as a `bigint`). */
|
|
196
|
+
getUuidBig(int: bigint): string | undefined;
|
|
197
|
+
/** Live (non-tombstone) entry count as a `bigint`. */
|
|
198
|
+
sizeBig(): bigint;
|
|
199
|
+
/** Largest int ever assigned + 1, as a `bigint`. */
|
|
200
|
+
nextIntBig(): bigint;
|
|
201
|
+
/**
|
|
202
|
+
* Encode a UUID string into a 16-byte Buffer. Accepts canonical
|
|
203
|
+
* 36-char form (with hyphens) or any 32-hex-digit form. Throws on
|
|
204
|
+
* malformed input.
|
|
205
|
+
*/
|
|
206
|
+
private encode;
|
|
207
|
+
/** Decode a 16-byte Buffer back to canonical UUID string. */
|
|
208
|
+
private decode;
|
|
209
|
+
private ensure;
|
|
210
|
+
}
|
|
211
|
+
//# sourceMappingURL=nativeBinaryEntityIdMapper.d.ts.map
|