chore(8.0): final pre-RC1 sweep — API consistency, named errors, orphans, zero-cast codebase

This commit is contained in:
David Snelling 2026-06-11 14:51:00 -07:00
parent 970e08c466
commit 1f7e365a4e
237 changed files with 1951 additions and 49413 deletions

View file

@ -20,7 +20,7 @@
* - EntityIdMapper handles UUID integer conversion
*/
import { StorageAdapter } from '../coreTypes.js'
import { StorageAdapter, NounMetadata } from '../coreTypes.js'
import { prodLog } from './logger.js'
import { RoaringBitmap32 } from './roaring/index.js'
import type { EntityIdMapper } from './entityIdMapper.js'
@ -109,6 +109,29 @@ export interface ChunkData {
lastUpdated: number
}
/**
* Storage representation of a roaring bitmap inside a serialized chunk.
* Produced by `ChunkManager.saveChunk()` portable-format bytes as a plain
* number array so the payload survives JSON round-trips.
*/
type SerializedRoaringBitmap = {
buffer: number[]
size: number
}
/**
* Storage representation of a chunk as persisted by `ChunkManager.saveChunk()`
* and re-hydrated by `ChunkManager.loadChunk()`. A type alias (not an
* interface) so it carries an implicit index signature and converts cleanly
* to/from the `NounMetadata` shape used by the storage metadata channel.
*/
type SerializedChunkData = {
chunkId: number
field: string
entries: Record<string, SerializedRoaringBitmap | undefined>
lastUpdated: number
}
// ============================================================================
// BloomFilter - Production-Ready Implementation
// ============================================================================
@ -609,25 +632,26 @@ export class ChunkManager {
const data = await this.storage.getMetadata(chunkPath)
if (data) {
// Cast NounMetadata to chunk data structure
const chunkData = data as unknown as any
// Chunks round-trip through the storage metadata channel; re-type the
// JSON payload to the serialized chunk shape written by saveChunk()
const chunkData = data as SerializedChunkData
// Deserialize: convert serialized roaring bitmaps back to RoaringBitmap32 objects
const chunk: ChunkData = {
chunkId: chunkData.chunkId as number,
field: chunkData.field as string,
chunkId: chunkData.chunkId,
field: chunkData.field,
entries: new Map(
Object.entries(chunkData.entries).map(([value, serializedBitmap]) => {
// Deserialize roaring bitmap from portable format
const bitmap = new RoaringBitmap32()
if (serializedBitmap && typeof serializedBitmap === 'object' && (serializedBitmap as any).buffer) {
if (serializedBitmap && typeof serializedBitmap === 'object' && serializedBitmap.buffer) {
// Deserialize from Buffer
bitmap.deserialize(Buffer.from((serializedBitmap as any).buffer), 'portable')
bitmap.deserialize(Buffer.from(serializedBitmap.buffer), 'portable')
}
return [value, bitmap]
return [value, bitmap] as const
})
),
lastUpdated: chunkData.lastUpdated as number
lastUpdated: chunkData.lastUpdated
}
this.chunkCache.set(cacheKey, chunk)
@ -668,7 +692,7 @@ export class ChunkManager {
}
const chunkPath = this.getChunkPath(chunk.field, chunk.chunkId)
await this.storage.saveMetadata(chunkPath, serializable as any)
await this.storage.saveMetadata(chunkPath, serializable)
}
/**
@ -842,8 +866,10 @@ export class ChunkManager {
this.chunkCache.delete(cacheKey)
const chunkPath = this.getChunkPath(field, chunkId)
// null signals deletion to storage adapter
await this.storage.saveMetadata(chunkPath, null as any)
// Typed boundary: the storage metadata channel doubles as the delete path —
// writing a JSON `null` tombstone clears the chunk. The adapter signature
// only models real payloads, so the null must be re-typed here.
await this.storage.saveMetadata(chunkPath, null as unknown as NounMetadata)
}
/**