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

@ -50,13 +50,26 @@ export class AddToHNSWOperation implements Operation {
}
/**
* Check if item exists in index
* Check if item exists in index.
*
* `getItem` is an optional, feature-detected provider capability see the
* VectorIndexProvider docs; it is intentionally absent from the required
* contract (Brainy's JS HNSW index omits it). When the capability is
* missing the answer must be `false`, not `true`: treating unknowable
* pre-existence as "existed" made every rollback skip removeItem, leaving
* phantom entries in the index after a failed transaction. The safe default
* is to remove what this operation added update flows pair this op with a
* RemoveFromHNSWOperation whose own rollback restores the prior vector, so
* reverse-order rollback reconstructs the original state either way.
*/
private async itemExists(id: string): Promise<boolean> {
const index = this.index as JsHnswVectorIndex & {
getItem?: (id: string) => Promise<unknown>
}
if (typeof index.getItem !== 'function') return false
try {
// Try to get item - if exists, no error
await (this.index as any).getItem?.(id)
return true
const item = await index.getItem(id)
return item !== undefined && item !== null
} catch {
return false
}

View file

@ -95,8 +95,8 @@ export class SaveNounOperation implements Operation {
// Delete newly created noun (if adapter supports it)
// Note: Not all adapters implement deleteNoun
// This is acceptable - metadata deletion makes entity invisible
if ('deleteNoun' in this.storage && typeof (this.storage as any).deleteNoun === 'function') {
await (this.storage as any).deleteNoun(this.noun.id)
if ('deleteNoun' in this.storage && typeof this.storage.deleteNoun === 'function') {
await this.storage.deleteNoun(this.noun.id)
}
}
}
@ -211,8 +211,8 @@ export class SaveVerbOperation implements Operation {
await this.storage.saveVerb(verbData)
} else {
// Delete newly created verb (if adapter supports it)
if ('deleteVerb' in this.storage && typeof (this.storage as any).deleteVerb === 'function') {
await (this.storage as any).deleteVerb(this.verb.id)
if ('deleteVerb' in this.storage && typeof this.storage.deleteVerb === 'function') {
await this.storage.deleteVerb(this.verb.id)
}
}
}