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

@ -155,7 +155,7 @@ describe('Brainy Batch Operations', () => {
})
})
describe('deleteMany - Batch Deletion', () => {
describe('removeMany - Batch Deletion', () => {
let testIds: string[]
beforeEach(async () => {
@ -171,7 +171,7 @@ describe('Brainy Batch Operations', () => {
})
it('should delete multiple entities at once', async () => {
await brain.deleteMany({ ids: testIds })
await brain.removeMany({ ids: testIds })
// All should be gone
for (const id of testIds) {
@ -185,7 +185,7 @@ describe('Brainy Batch Operations', () => {
const toDelete = [testIds[0], testIds[2], testIds[4]]
const toKeep = [testIds[1], testIds[3]]
await brain.deleteMany({ ids: toDelete })
await brain.removeMany({ ids: toDelete })
// Deleted ones should be gone
for (const id of toDelete) {
@ -212,7 +212,7 @@ describe('Brainy Batch Operations', () => {
await brain.relate({ from: person2, to: org, type: VerbType.MemberOf as any })
// Delete the organization
await brain.deleteMany({ ids: [org] })
await brain.removeMany({ ids: [org] })
// Organization should be gone
const deletedOrg = await brain.get(org)
@ -237,7 +237,7 @@ describe('Brainy Batch Operations', () => {
const manyIds = manyResult.successful
const startTime = Date.now()
await brain.deleteMany({ ids: manyIds })
await brain.removeMany({ ids: manyIds })
const duration = Date.now() - startTime
// v5.4.0: Increased to 14500ms for type-first storage + system load variance
@ -281,7 +281,7 @@ describe('Brainy Batch Operations', () => {
expect(relationIds).toHaveLength(3)
// Verify relationships exist
const person1Relations = await brain.getRelations({ from: entities[0] })
const person1Relations = await brain.related({ from: entities[0] })
expect(person1Relations.length).toBeGreaterThan(0)
})
@ -297,13 +297,13 @@ describe('Brainy Batch Operations', () => {
expect(relationIds).toHaveLength(3)
// Verify different types
const friendRelations = await brain.getRelations({
const friendRelations = await brain.related({
from: entities[0],
type: VerbType.FriendOf
})
expect(friendRelations.length).toBeGreaterThan(0)
const workRelations = await brain.getRelations({
const workRelations = await brain.related({
from: entities[0],
type: VerbType.WorksWith
})
@ -321,10 +321,10 @@ describe('Brainy Batch Operations', () => {
expect(relationIds).toHaveLength(2)
// Both should have the relationship
const person1Friends = await brain.getRelations({ from: entities[0] })
const person1Friends = await brain.related({ from: entities[0] })
expect(person1Friends.length).toBeGreaterThan(0)
const person2Friends = await brain.getRelations({ from: entities[1] })
const person2Friends = await brain.related({ from: entities[1] })
expect(person2Friends.length).toBeGreaterThan(0)
})
@ -358,7 +358,7 @@ describe('Brainy Batch Operations', () => {
expect(duration).toBeLessThan(1000) // Should be fast
// Verify company has all relationships
const companyRelations = await brain.getRelations({ to: company })
const companyRelations = await brain.related({ to: company })
expect(companyRelations.length).toBeGreaterThanOrEqual(50)
})
@ -460,7 +460,7 @@ describe('Brainy Batch Operations', () => {
await brain.relateMany({ items: relationships })
// 4. Delete some entities
await brain.deleteMany({ ids: initialIds.slice(15) })
await brain.removeMany({ ids: initialIds.slice(15) })
const totalTime = Date.now() - startTime
@ -473,7 +473,7 @@ describe('Brainy Batch Operations', () => {
const deleted = await brain.get(initialIds[19])
expect(deleted).toBeNull()
const relations = await brain.getRelations({ from: initialIds[0] })
const relations = await brain.related({ from: initialIds[0] })
expect(relations.length).toBeGreaterThan(0)
})
})
@ -487,7 +487,7 @@ describe('Brainy Batch Operations', () => {
expect(result.successful).toHaveLength(0)
await brain.updateMany({ items: [] })
await brain.deleteMany({ ids: [] })
await brain.removeMany({ ids: [] })
// Should not throw
})

View file

@ -169,9 +169,9 @@ describe('Brainy.fillSubtypes()', () => {
expect(report.filled).toBe(1)
expect(report.byType).toEqual({ relatedTo: 1 })
const relations = await brain.getRelations({ from: a })
const relations = await brain.related({ from: a })
expect(relations.find((r) => r.id === relId)!.subtype).toBe('unspecified')
const reverse = await brain.getRelations({ from: b })
const reverse = await brain.related({ from: b })
expect(reverse.find((r) => r.id === labeled)!.subtype).toBe('colleague') // untouched
})
@ -195,7 +195,7 @@ describe('Brainy.fillSubtypes()', () => {
})
expect(report.filled).toBe(1)
const relations = await brain.getRelations({ from: a })
const relations = await brain.related({ from: a })
expect(relations[0].subtype).toBe('dotted-line')
})

View file

@ -182,7 +182,7 @@ describe('Brainy.get()', () => {
data: 'To be deleted',
type: 'thing'
}))
await brain.delete(id)
await brain.remove(id)
// Act
const entity = await brain.get(id)

View file

@ -51,7 +51,7 @@ describe('Duplicate Check Optimization', () => {
expect(relationId2).toBe(relationId1)
// Verify only one relationship exists
const relations = await brain.getRelations({ from: personId })
const relations = await brain.related({ from: personId })
expect(relations).toHaveLength(1)
expect(relations[0].id).toBe(relationId1)
})
@ -85,7 +85,7 @@ describe('Duplicate Check Optimization', () => {
expect(relationId2).not.toBe(relationId1)
// Verify both relationships exist
const relations = await brain.getRelations({ from: personId })
const relations = await brain.related({ from: personId })
expect(relations).toHaveLength(2)
// Both relations should exist with different IDs
const relationIds = relations.map(r => r.id)
@ -129,7 +129,7 @@ describe('Duplicate Check Optimization', () => {
expect(elapsed).toBeLessThan(10)
// Verify duplicate was detected
const relations = await brain.getRelations({ from: sourceId })
const relations = await brain.related({ from: sourceId })
expect(relations).toHaveLength(50) // No duplicate created
})
@ -198,7 +198,7 @@ describe('Duplicate Check Optimization', () => {
})
// Verify both relationships exist
let relations = await brain.getRelations({ from: person })
let relations = await brain.related({ from: person })
expect(relations).toHaveLength(2)
const relationIds = relations.map(r => r.id)
expect(relationIds).toContain(rel1)
@ -218,7 +218,7 @@ describe('Duplicate Check Optimization', () => {
expect(duplicate).toBe(rel1)
// Verify still same number of relationships (no duplicate added)
const finalRelations = await brain.getRelations({ from: person })
const finalRelations = await brain.related({ from: person })
expect(finalRelations.length).toBe(relations.length)
})
})

View file

@ -61,7 +61,7 @@ describe('Brainy.relate()', () => {
expect(typeof relationId).toBe('string')
// Verify relationship exists
const relations = await brain.getRelations({ from: entity1Id })
const relations = await brain.related({ from: entity1Id })
expect(relations.length).toBeGreaterThan(0)
expect(relations.some(r => r.to === entity2Id)).toBe(true)
})
@ -76,7 +76,7 @@ describe('Brainy.relate()', () => {
})
// Assert
const relations = await brain.getRelations({ from: entity1Id })
const relations = await brain.related({ from: entity1Id })
const relation = relations.find(r => r.to === entity2Id)
expect(relation).toBeDefined()
expect(relation!.weight).toBe(0.8)
@ -99,7 +99,7 @@ describe('Brainy.relate()', () => {
})
// Assert
const relations = await brain.getRelations({ from: entity1Id })
const relations = await brain.related({ from: entity1Id })
const relation = relations.find(r => r.to === entity2Id)
expect(relation).toBeDefined()
expect(relation!.metadata || {}).toMatchObject(metadata)
@ -115,8 +115,8 @@ describe('Brainy.relate()', () => {
})
// Assert - Check both directions
const forwardRelations = await brain.getRelations({ from: entity1Id })
const reverseRelations = await brain.getRelations({ from: entity2Id })
const forwardRelations = await brain.related({ from: entity1Id })
const reverseRelations = await brain.related({ from: entity2Id })
expect(forwardRelations.some(r => r.to === entity2Id)).toBe(true)
expect(reverseRelations.some(r => r.to === entity1Id)).toBe(true)
@ -137,7 +137,7 @@ describe('Brainy.relate()', () => {
})
// Assert
const relations = await brain.getRelations({ from: entity1Id })
const relations = await brain.related({ from: entity1Id })
expect(relations.length).toBe(2)
expect(relations.some(r => r.to === entity2Id)).toBe(true)
expect(relations.some(r => r.to === entity3Id)).toBe(true)
@ -158,7 +158,7 @@ describe('Brainy.relate()', () => {
})
// Assert
const relations = await brain.getRelations({ from: entity1Id })
const relations = await brain.related({ from: entity1Id })
const toEntity2 = relations.filter(r => r.to === entity2Id)
expect(toEntity2.length).toBe(2)
expect(toEntity2.some(r => r.type === 'worksWith')).toBe(true)
@ -175,7 +175,7 @@ describe('Brainy.relate()', () => {
})
// Assert
const relations = await brain.getRelations({ from: entity1Id })
const relations = await brain.related({ from: entity1Id })
const selfRelation = relations.find(r => r.to === entity1Id)
expect(selfRelation).toBeDefined()
expect(selfRelation!.metadata?.type).toBe('self-reference')
@ -241,7 +241,7 @@ describe('Brainy.relate()', () => {
// Second call should return existing relationship ID instead of creating duplicate
expect(id1).toBe(id2)
const relations = await brain.getRelations({ from: entity1Id })
const relations = await brain.related({ from: entity1Id })
const matches = relations.filter(r =>
r.to === entity2Id && r.type === 'worksWith'
)
@ -267,7 +267,7 @@ describe('Brainy.relate()', () => {
})
// Assert
const relations = await brain.getRelations({ from: entity1Id })
const relations = await brain.related({ from: entity1Id })
const relation = relations.find(r => r.to === entity2Id)
expect(relation).toBeDefined()
expect(relation!.metadata?.bigArray).toHaveLength(100)
@ -291,7 +291,7 @@ describe('Brainy.relate()', () => {
})
// Assert
const relations = await brain.getRelations({ from: entity1Id })
const relations = await brain.related({ from: entity1Id })
const relation = relations.find(r => r.to === entity2Id)
expect(relation!.metadata || {}).toMatchObject(specialMetadata)
})
@ -356,8 +356,8 @@ describe('Brainy.relate()', () => {
})
// Assert - Multiple queries should return same data
const relations1 = await brain.getRelations({ from: entity1Id })
const relations2 = await brain.getRelations({ from: entity1Id })
const relations1 = await brain.related({ from: entity1Id })
const relations2 = await brain.related({ from: entity1Id })
expect(relations1.length).toBe(relations2.length)
const rel1 = relations1.find(r => r.to === entity2Id)
@ -386,7 +386,7 @@ describe('Brainy.relate()', () => {
})
// Assert - Relationship should still exist
const relations = await brain.getRelations({ from: entity1Id })
const relations = await brain.related({ from: entity1Id })
expect(relations.some(r => r.to === entity2Id)).toBe(true)
})
})
@ -407,8 +407,8 @@ describe('Brainy.relate()', () => {
})
// Act - Get relationships step by step
const step1 = await brain.getRelations({ from: entity1Id })
const entity2Relations = await brain.getRelations({ from: entity2Id })
const step1 = await brain.related({ from: entity1Id })
const entity2Relations = await brain.related({ from: entity2Id })
// Assert
expect(step1.some(r => r.to === entity2Id)).toBe(true)
@ -436,9 +436,9 @@ describe('Brainy.relate()', () => {
})
// Assert - All relationships should exist
const rel1 = await brain.getRelations({ from: entity1Id })
const rel2 = await brain.getRelations({ from: entity2Id })
const rel3 = await brain.getRelations({ from: entity3Id })
const rel1 = await brain.related({ from: entity1Id })
const rel2 = await brain.related({ from: entity2Id })
const rel3 = await brain.related({ from: entity3Id })
expect(rel1.some(r => r.to === entity2Id)).toBe(true)
expect(rel2.some(r => r.to === entity3Id)).toBe(true)

View file

@ -284,7 +284,7 @@ describe('reserved-field metadata remap (8.0 contract)', () => {
expect(result?.entity._rev).toBe(1)
})
it('getRelations() by target surfaces reserved fields top-level, custom-only metadata', async () => {
it('related() by target surfaces reserved fields top-level, custom-only metadata', async () => {
const a = await brain.add({ type: NounType.Person, subtype: 'employee', data: 'src' })
const b = await brain.add({ type: NounType.Person, subtype: 'employee', data: 'tgt' })
const relId = await brain.relate({
@ -298,7 +298,7 @@ describe('reserved-field metadata remap (8.0 contract)', () => {
metadata: { note: 'target path' }
})
const relations = await brain.getRelations({ to: b })
const relations = await brain.related({ to: b })
const rel = relations.find((r) => r.id === relId)
expect(rel).toBeDefined()
expect(rel?.metadata).toEqual({ note: 'target path' })
@ -329,7 +329,7 @@ describe('reserved-field metadata remap (8.0 contract)', () => {
service: 'orders'
})
const relations = await brain.getRelations({ from: a })
const relations = await brain.related({ from: a })
const rel = relations.find((r) => r.id === relId)
expect(rel?.confidence).toBe(0.77)
expect(rel?.service).toBe('orders')
@ -344,7 +344,7 @@ describe('reserved-field metadata remap (8.0 contract)', () => {
metadata: { confidence: 0.4, weight: 0.3, role: 'peer' } as object
})
const relations = await brain.getRelations({ from: a })
const relations = await brain.related({ from: a })
const rel = relations.find((r) => r.id === relId)
expect(rel?.confidence).toBe(0.4)
expect(rel?.weight).toBe(0.3)
@ -360,7 +360,7 @@ describe('reserved-field metadata remap (8.0 contract)', () => {
metadata: { note: 'no echo' }
})
const relations = await brain.getRelations({ from: a })
const relations = await brain.related({ from: a })
const rel = relations.find((r) => r.id === relId)
expect(rel?.type).toBe(VerbType.RelatedTo)
expect((rel?.metadata as Record<string, unknown>)?.verb).toBeUndefined()
@ -382,7 +382,7 @@ describe('reserved-field metadata remap (8.0 contract)', () => {
metadata: { confidence: 0.55, subtype: 'dotted-line', extra: 'applied' } as object
})
const relations = await brain.getRelations({ from: a })
const relations = await brain.related({ from: a })
const rel = relations.find((r) => r.id === relId)
expect(rel?.confidence).toBe(0.55)
expect(rel?.subtype).toBe('dotted-line')