feat: introduce CLI for Brainy and enhance type validation
Added a comprehensive command-line interface (CLI) for interacting with the Brainy vector database. The CLI supports various operations, including database initialization, adding/searching nouns, managing relationships, and querying database status. Enhanced type validation logic for nouns and verbs to ensure consistency and enforce default types for invalid inputs. Updated test scripts to verify type validation and edge cases.
This commit is contained in:
parent
a0ce5b0ca9
commit
cdbd2a9db4
14 changed files with 1196 additions and 373 deletions
63
test/validateTypes.js
Normal file
63
test/validateTypes.js
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
// Test script to verify type validation in BrainyData
|
||||
import { BrainyData } from '../src/brainyData.js';
|
||||
import { NounType, VerbType } from '../src/types/graphTypes.js';
|
||||
|
||||
async function testTypeValidation() {
|
||||
console.log('Testing type validation in BrainyData...');
|
||||
|
||||
// Create a new BrainyData instance
|
||||
const brainy = new BrainyData();
|
||||
await brainy.init();
|
||||
|
||||
console.log('Testing node with valid noun type...');
|
||||
const validNodeId = await brainy.add([0.1, 0.2, 0.3], {
|
||||
noun: NounType.Person,
|
||||
label: 'Test Person'
|
||||
});
|
||||
console.log(`Added node with valid noun type: ${validNodeId}`);
|
||||
|
||||
console.log('Testing node with invalid noun type...');
|
||||
const invalidNodeId = await brainy.add([0.4, 0.5, 0.6], {
|
||||
noun: 'invalid_type',
|
||||
label: 'Test Invalid'
|
||||
});
|
||||
console.log(`Added node with invalid noun type (should be converted to default): ${invalidNodeId}`);
|
||||
|
||||
// Get the metadata to verify it was corrected
|
||||
const invalidNodeMetadata = await brainy.get(invalidNodeId);
|
||||
console.log('Metadata for node with invalid type:', invalidNodeMetadata);
|
||||
|
||||
console.log('Testing edge with valid verb type...');
|
||||
const validEdgeId = await brainy.addEdge(validNodeId, invalidNodeId, undefined, {
|
||||
type: VerbType.RelatedTo,
|
||||
metadata: { label: 'Test Relation' }
|
||||
});
|
||||
console.log(`Added edge with valid verb type: ${validEdgeId}`);
|
||||
|
||||
console.log('Testing edge with invalid verb type...');
|
||||
const invalidEdgeId = await brainy.addEdge(validNodeId, invalidNodeId, undefined, {
|
||||
type: 'invalid_relation',
|
||||
metadata: { label: 'Test Invalid Relation' }
|
||||
});
|
||||
console.log(`Added edge with invalid verb type (should be converted to default): ${invalidEdgeId}`);
|
||||
|
||||
// Get the edge to verify it was corrected
|
||||
const invalidEdge = await brainy.getEdge(invalidEdgeId);
|
||||
console.log('Edge with invalid type:', invalidEdge);
|
||||
|
||||
console.log('Testing updateMetadata with invalid noun type...');
|
||||
await brainy.updateMetadata(validNodeId, {
|
||||
noun: 'another_invalid_type',
|
||||
label: 'Updated Test'
|
||||
});
|
||||
|
||||
// Get the metadata to verify it was corrected
|
||||
const updatedMetadata = await brainy.get(validNodeId);
|
||||
console.log('Updated metadata (should have corrected noun type):', updatedMetadata);
|
||||
|
||||
console.log('All tests completed.');
|
||||
}
|
||||
|
||||
testTypeValidation().catch(error => {
|
||||
console.error('Test failed:', error);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue