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

@ -8,6 +8,45 @@
*/
import type { BaseStorage } from '../storage/baseStorage.js'
import type { HNSWNounWithMetadata, HNSWVerbWithMetadata } from '../coreTypes.js'
/**
* Result page shape returned by the adapter offset-paginated readers.
*/
interface PaginatedScanResult<TItem> {
items: TItem[]
totalCount?: number
hasMore: boolean
nextCursor?: string
}
/**
* Structural view of the count bookkeeping this utility repairs.
*
* The count fields are `protected` on `BaseStorageAdapter`; this recovery
* utility deliberately reaches past that visibility to overwrite
* desynchronized counters, so the cast below is a visibility boundary rather
* than a shape mismatch. The paginated readers are optional adapter
* capabilities (probed at runtime) whose implementations accept an `offset`
* option not modeled on the cursor-based `BaseStorageAdapter` declaration.
*/
interface CountRebuildTarget {
getNounsWithPagination?: (options: {
limit?: number
offset?: number
}) => Promise<PaginatedScanResult<HNSWNounWithMetadata>>
getVerbsWithPagination?: (options: {
limit?: number
offset?: number
}) => Promise<PaginatedScanResult<HNSWVerbWithMetadata>>
totalNounCount: number
totalVerbCount: number
entityCounts: Map<string, number>
verbCounts: Map<string, number>
pendingCountPersist: boolean
pendingCountOperations: number
flushCounts(): Promise<void>
}
export interface RebuildCountsResult {
/** Total number of entities (nouns) found */
@ -57,8 +96,10 @@ export async function rebuildCounts(storage: BaseStorage): Promise<RebuildCounts
// Scan all nouns using pagination
console.log('📊 Scanning entities...')
// Check if pagination method exists
const storageWithPagination = storage as any
// Check if pagination method exists.
// Typed boundary: see CountRebuildTarget — protected count bookkeeping plus
// optional offset-paginated readers, neither visible on the public type.
const storageWithPagination = storage as unknown as CountRebuildTarget
if (typeof storageWithPagination.getNounsWithPagination !== 'function') {
throw new Error('Storage adapter does not support getNounsWithPagination')
}
@ -67,7 +108,7 @@ export async function rebuildCounts(storage: BaseStorage): Promise<RebuildCounts
let offset = 0 // Use offset-based pagination instead of cursor (bug fix for infinite loop)
while (hasMore) {
const result: any = await storageWithPagination.getNounsWithPagination({
const result = await storageWithPagination.getNounsWithPagination({
limit: 100,
offset // Pass offset for proper pagination (previously passed cursor which was ignored)
})
@ -98,7 +139,7 @@ export async function rebuildCounts(storage: BaseStorage): Promise<RebuildCounts
offset = 0 // Reset offset for verbs pagination
while (hasMore) {
const result: any = await storageWithPagination.getVerbsWithPagination({
const result = await storageWithPagination.getVerbsWithPagination({
limit: 100,
offset // Pass offset for proper pagination (previously passed cursor which was ignored)
})