2025-10-09 16:33:08 -07:00
|
|
|
/**
|
|
|
|
|
* Test to verify correct API parameter usage
|
|
|
|
|
* Reproduces Brain Cloud issue where 'filter' was used instead of 'where'
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import { describe, it, expect, beforeAll, afterAll } from 'vitest'
|
|
|
|
|
import { Brainy } from '../../src/index.js'
|
|
|
|
|
import { NounType } from '../../src/types/graphTypes.js'
|
|
|
|
|
|
|
|
|
|
describe('API Parameter Validation', () => {
|
|
|
|
|
let brain: Brainy
|
|
|
|
|
|
|
|
|
|
beforeAll(async () => {
|
|
|
|
|
brain = new Brainy({
|
|
|
|
|
storage: { type: 'memory' }
|
|
|
|
|
})
|
|
|
|
|
await brain.init()
|
|
|
|
|
|
|
|
|
|
// Add test data
|
|
|
|
|
await brain.add({
|
|
|
|
|
data: 'Alice',
|
feat: Stage 3 CANONICAL taxonomy with 169 types (v5.5.0)
Expand type system from 71 to 169 types achieving 96-97% coverage of all human knowledge.
NEW FEATURES:
- 42 noun types (was 31): Added organism, substance + 11 others
- 127 verb types (was 40): Added affects, learns, destroys + 84 others
- Stage 3 CANONICAL taxonomy covering all major knowledge domains
NEW TYPES:
Nouns: organism (biological entities), substance (physical matter)
Verbs: destroys (lifecycle), affects (patient role), learns (cognition)
Plus 95 additional types across 24 semantic categories
REMOVED TYPES (migration recommended):
- user → person, topic → concept, content → informationContent
- createdBy, belongsTo, supervises, succeeds → use inverse relationships
PERFORMANCE:
- Memory: 676 bytes for 169 types (99.2% reduction vs Maps)
- Type embeddings: 338KB embedded, zero runtime computation
- Coverage: Natural Sciences (96%), Formal Sciences (98%), Social Sciences (97%), Humanities (96%)
DOCUMENTATION:
- Added docs/STAGE3-CANONICAL-TAXONOMY.md
- Updated README.md with new type counts
- Complete CHANGELOG entry for v5.5.0
BREAKING CHANGES (minor impact):
Removed 6 types (user, topic, content, createdBy, belongsTo, supervises, succeeds).
Migration path provided via type mapping.
Timeless design: Stable for 20+ years without changes.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-06 09:02:23 -08:00
|
|
|
type: NounType.Person,
|
2025-10-09 16:33:08 -07:00
|
|
|
metadata: { category: 'test-category', status: 'active' }
|
|
|
|
|
})
|
|
|
|
|
await brain.add({
|
|
|
|
|
data: 'Bob',
|
feat: Stage 3 CANONICAL taxonomy with 169 types (v5.5.0)
Expand type system from 71 to 169 types achieving 96-97% coverage of all human knowledge.
NEW FEATURES:
- 42 noun types (was 31): Added organism, substance + 11 others
- 127 verb types (was 40): Added affects, learns, destroys + 84 others
- Stage 3 CANONICAL taxonomy covering all major knowledge domains
NEW TYPES:
Nouns: organism (biological entities), substance (physical matter)
Verbs: destroys (lifecycle), affects (patient role), learns (cognition)
Plus 95 additional types across 24 semantic categories
REMOVED TYPES (migration recommended):
- user → person, topic → concept, content → informationContent
- createdBy, belongsTo, supervises, succeeds → use inverse relationships
PERFORMANCE:
- Memory: 676 bytes for 169 types (99.2% reduction vs Maps)
- Type embeddings: 338KB embedded, zero runtime computation
- Coverage: Natural Sciences (96%), Formal Sciences (98%), Social Sciences (97%), Humanities (96%)
DOCUMENTATION:
- Added docs/STAGE3-CANONICAL-TAXONOMY.md
- Updated README.md with new type counts
- Complete CHANGELOG entry for v5.5.0
BREAKING CHANGES (minor impact):
Removed 6 types (user, topic, content, createdBy, belongsTo, supervises, succeeds).
Migration path provided via type mapping.
Timeless design: Stable for 20+ years without changes.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-06 09:02:23 -08:00
|
|
|
type: NounType.Person,
|
2025-10-09 16:33:08 -07:00
|
|
|
metadata: { category: 'other-category', status: 'active' }
|
|
|
|
|
})
|
|
|
|
|
await brain.add({
|
|
|
|
|
data: 'Charlie',
|
feat: Stage 3 CANONICAL taxonomy with 169 types (v5.5.0)
Expand type system from 71 to 169 types achieving 96-97% coverage of all human knowledge.
NEW FEATURES:
- 42 noun types (was 31): Added organism, substance + 11 others
- 127 verb types (was 40): Added affects, learns, destroys + 84 others
- Stage 3 CANONICAL taxonomy covering all major knowledge domains
NEW TYPES:
Nouns: organism (biological entities), substance (physical matter)
Verbs: destroys (lifecycle), affects (patient role), learns (cognition)
Plus 95 additional types across 24 semantic categories
REMOVED TYPES (migration recommended):
- user → person, topic → concept, content → informationContent
- createdBy, belongsTo, supervises, succeeds → use inverse relationships
PERFORMANCE:
- Memory: 676 bytes for 169 types (99.2% reduction vs Maps)
- Type embeddings: 338KB embedded, zero runtime computation
- Coverage: Natural Sciences (96%), Formal Sciences (98%), Social Sciences (97%), Humanities (96%)
DOCUMENTATION:
- Added docs/STAGE3-CANONICAL-TAXONOMY.md
- Updated README.md with new type counts
- Complete CHANGELOG entry for v5.5.0
BREAKING CHANGES (minor impact):
Removed 6 types (user, topic, content, createdBy, belongsTo, supervises, succeeds).
Migration path provided via type mapping.
Timeless design: Stable for 20+ years without changes.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-06 09:02:23 -08:00
|
|
|
type: NounType.Person,
|
2025-10-09 16:33:08 -07:00
|
|
|
metadata: { category: 'test-category', status: 'inactive' }
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('should use "where" parameter for metadata filtering', async () => {
|
|
|
|
|
const results = await brain.find({
|
|
|
|
|
where: { category: 'test-category' },
|
|
|
|
|
limit: 10
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
expect(results).toHaveLength(2)
|
|
|
|
|
expect(results.map(r => r.entity.data).sort()).toEqual(['Alice', 'Charlie'])
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('should IGNORE unknown "filter" parameter (reproduces Brain Cloud bug)', async () => {
|
|
|
|
|
// This is what Brain Cloud was doing - using 'filter' instead of 'where'
|
|
|
|
|
const results = await brain.find({
|
|
|
|
|
filter: { category: 'test-category' } as any, // Wrong parameter!
|
|
|
|
|
limit: 10
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// Should return ALL results because filter is ignored
|
|
|
|
|
expect(results.length).toBeGreaterThanOrEqual(2)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('should demonstrate the difference between correct and incorrect API usage', async () => {
|
|
|
|
|
// CORRECT: Using 'where'
|
|
|
|
|
const correctResults = await brain.find({
|
|
|
|
|
where: { category: 'test-category' },
|
|
|
|
|
limit: 10
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// INCORRECT: Using 'filter' (what Brain Cloud did)
|
|
|
|
|
const incorrectResults = await brain.find({
|
|
|
|
|
filter: { category: 'test-category' } as any,
|
|
|
|
|
limit: 10
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// Correct usage filters results
|
|
|
|
|
expect(correctResults).toHaveLength(2)
|
|
|
|
|
|
|
|
|
|
// Incorrect usage returns more results (filter ignored)
|
|
|
|
|
expect(incorrectResults.length).toBeGreaterThan(correctResults.length)
|
|
|
|
|
})
|
|
|
|
|
})
|