feat: add comprehensive zero-config validation system

- Implement self-configuring validation that adapts to system resources
- Add validation for all CRUD operations (add, update, delete, find, relate)
- Auto-configure limits based on available memory (1GB = 10K limit, 8GB = 80K)
- Monitor and auto-tune performance based on query response times
- Fix multiple type filtering with proper anyOf structure
- Enhance type safety by requiring NounType/VerbType enums
- Fix tests to validate correct behavior (no fake implementations)
- Add comprehensive VALIDATION.md documentation
- Update API_REFERENCE.md with validation rules and examples
- Clarify metadata update behavior (null keeps existing, {} clears)

BREAKING CHANGE: getFieldsForType() now requires NounType enum instead of string

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
David Snelling 2025-09-12 14:37:39 -07:00
parent e9a2c41b0a
commit 7eaf5a9252
12 changed files with 979 additions and 76 deletions

View file

@ -54,7 +54,7 @@ describe('Brainy.add()', () => {
it('should add an entity with pre-computed vector', async () => {
// Arrange
const vector = generateTestVector()
const vector = generateTestVector(384) // Use correct dimensions for all-MiniLM-L6-v2
const params = createAddParams({
vector,
type: 'thing',
@ -227,7 +227,8 @@ describe('Brainy.add()', () => {
expect(entity).not.toBeNull()
expect(entity!.createdAt).toBeGreaterThanOrEqual(beforeAdd)
expect(entity!.createdAt).toBeLessThanOrEqual(afterAdd)
expect(entity!.updatedAt).toBe(entity!.createdAt)
// updatedAt should be very close to createdAt for new entities (within 10ms)
expect(Math.abs(entity!.updatedAt! - entity!.createdAt)).toBeLessThanOrEqual(10)
})
})
@ -242,7 +243,7 @@ describe('Brainy.add()', () => {
// Act & Assert
await assertRejectsWithError(
brain.add(params),
'Either data or vector'
'must provide either data or vector'
)
})
@ -256,7 +257,7 @@ describe('Brainy.add()', () => {
// Act & Assert
await assertRejectsWithError(
brain.add(params),
'Invalid noun type'
'invalid NounType'
)
})
@ -342,7 +343,7 @@ describe('Brainy.add()', () => {
})
// Act & Assert - Empty string is not valid data
await expect(brain.add(params)).rejects.toThrow('Either data or vector')
await expect(brain.add(params)).rejects.toThrow('must provide either data or vector')
})
it('should handle very long text content', async () => {
@ -419,7 +420,7 @@ describe('Brainy.add()', () => {
it('should store vectors as provided without normalization', async () => {
// Arrange
const unnormalizedVector = new Array(1536).fill(2) // Not unit length
const unnormalizedVector = new Array(384).fill(2) // Not unit length, correct dimensions
const params = createAddParams({
vector: unnormalizedVector,
type: 'thing'