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

@ -133,13 +133,11 @@ describe('Brainy Public API - Complete Coverage', () => {
expect(final?.metadata?.version).toBeGreaterThan(1)
})
it('should handle update of non-existent entity gracefully', async () => {
it('should reject update of a non-existent entity', async () => {
const fakeId = randomUUID()
try {
await brain.update({ id: fakeId, metadata: { test: true } })
} catch {
// Brainy may throw for non-existent entity — acceptable
}
await expect(
brain.update({ id: fakeId, metadata: { test: true } })
).rejects.toThrow(/not found/)
})
it('should preserve unmodified fields', async () => {
@ -191,30 +189,27 @@ describe('Brainy Public API - Complete Coverage', () => {
})
})
describe('brain.delete()', () => {
describe('brain.remove()', () => {
it('should handle cascade deletion of relationships', async () => {
const id1 = await brain.add({ data: 'Entity 1', type: NounType.Person })
const id2 = await brain.add({ data: 'Entity 2', type: NounType.Organization })
await brain.relate({ from: id1, to: id2, type: VerbType.WorksWith })
await brain.delete(id1)
await brain.remove(id1)
const relations = await brain.getRelations(id2)
const relations = await brain.related(id2)
expect(relations.filter(r => r.from === id1 || r.to === id1)).toHaveLength(0)
})
it('should handle deletion of non-existent entity gracefully', async () => {
it('should treat deletion of a non-existent entity as a no-op', async () => {
const fakeId = randomUUID()
try {
await brain.delete(fakeId)
} catch {
// Brainy may throw for non-existent entity — acceptable
}
// delete() is idempotent: unknown IDs resolve without throwing
await expect(brain.remove(fakeId)).resolves.toBeUndefined()
})
})
describe('brain.deleteMany()', () => {
describe('brain.removeMany()', () => {
it('should efficiently delete batches', async () => {
const result = await brain.addMany({
items: Array.from({ length: 5 }, (_, i) => ({
@ -224,7 +219,7 @@ describe('Brainy Public API - Complete Coverage', () => {
})
const ids = result.successful
await brain.deleteMany({ ids })
await brain.removeMany({ ids })
for (const id of ids) {
const entity = await brain.get(id)
@ -280,8 +275,8 @@ describe('Brainy Public API - Complete Coverage', () => {
bidirectional: true
})
const relations1 = await brain.getRelations(person1)
const relations2 = await brain.getRelations(person2)
const relations1 = await brain.related(person1)
const relations2 = await brain.related(person2)
expect(relations1.some(r => r.to === person2)).toBe(true)
expect(relations2.some(r => r.to === person1)).toBe(true)
@ -294,7 +289,7 @@ describe('Brainy Public API - Complete Coverage', () => {
await brain.relate({ from: id1, to: id2, type: VerbType.References })
await brain.relate({ from: id1, to: id2, type: VerbType.References })
const relations = await brain.getRelations(id1)
const relations = await brain.related(id1)
const referenceRelations = relations.filter(
r => r.type === VerbType.References && r.to === id2
)
@ -317,7 +312,7 @@ describe('Brainy Public API - Complete Coverage', () => {
}
})
const relations = await brain.getRelations(id1)
const relations = await brain.related(id1)
const relation = relations.find(r => r.id === relationId)
expect(relation).toBeDefined()
@ -350,7 +345,7 @@ describe('Brainy Public API - Complete Coverage', () => {
})
})
describe('brain.getRelations()', () => {
describe('brain.related()', () => {
it('should retrieve outgoing relationships', async () => {
const center = await brain.add({ data: 'Center', type: NounType.Person })
const related1 = await brain.add({ data: 'Related1', type: NounType.Organization })
@ -359,7 +354,7 @@ describe('Brainy Public API - Complete Coverage', () => {
await brain.relate({ from: center, to: related1, type: VerbType.WorksWith })
await brain.relate({ from: center, to: related2, type: VerbType.Creates })
const outgoing = await brain.getRelations({ from: center })
const outgoing = await brain.related({ from: center })
expect(outgoing).toHaveLength(2)
expect(outgoing.some(r => r.type === VerbType.WorksWith)).toBe(true)
@ -372,7 +367,7 @@ describe('Brainy Public API - Complete Coverage', () => {
await brain.relate({ from: source, to: center, type: VerbType.DependsOn })
const incoming = await brain.getRelations({ to: center })
const incoming = await brain.related({ to: center })
expect(incoming).toHaveLength(1)
expect(incoming[0].type).toBe(VerbType.DependsOn)
@ -386,8 +381,8 @@ describe('Brainy Public API - Complete Coverage', () => {
await brain.relate({ from: source, to: center, type: VerbType.Creates })
await brain.relate({ from: center, to: target, type: VerbType.Requires })
const outgoing = await brain.getRelations({ from: center })
const incoming = await brain.getRelations({ to: center })
const outgoing = await brain.related({ from: center })
const incoming = await brain.related({ to: center })
expect(outgoing).toHaveLength(1)
expect(outgoing[0].to).toBe(target)
@ -406,7 +401,7 @@ describe('Brainy Public API - Complete Coverage', () => {
await brain.relate({ from: doc, to: ref2, type: VerbType.References })
await brain.relate({ from: author, to: doc, type: VerbType.Creates })
const references = await brain.getRelations({
const references = await brain.related({
from: doc,
type: VerbType.References
})
@ -683,7 +678,7 @@ describe('Brainy Public API - Complete Coverage', () => {
const updated = await fsBrain.get(id)
expect(updated?.metadata?.updated).toBe(true)
await fsBrain.delete(id)
await fsBrain.remove(id)
const deleted = await fsBrain.get(id)
expect(deleted).toBeNull()