feat: add topic hierarchy APIs
This commit is contained in:
@@ -19,6 +19,16 @@ async function seedMemoryGraph(db: IdentityDB): Promise<void> {
|
||||
{ name: 'programming language', category: 'concept', granularity: 'abstract', role: 'classification' },
|
||||
],
|
||||
});
|
||||
|
||||
await db.linkTopics({
|
||||
parentName: 'software technology',
|
||||
childName: 'programming language',
|
||||
});
|
||||
|
||||
await db.linkTopics({
|
||||
parentName: 'programming language',
|
||||
childName: 'TypeScript',
|
||||
});
|
||||
}
|
||||
|
||||
describe('IdentityDB queries', () => {
|
||||
@@ -60,6 +70,7 @@ describe('IdentityDB queries', () => {
|
||||
'2025',
|
||||
'I',
|
||||
'programming language',
|
||||
'software technology',
|
||||
'TypeScript',
|
||||
]);
|
||||
expect('facts' in topics[0]!).toBe(false);
|
||||
@@ -81,4 +92,25 @@ describe('IdentityDB queries', () => {
|
||||
expect(facts).toHaveLength(1);
|
||||
expect(facts[0]?.statement).toBe('I have worked with TypeScript since 2025.');
|
||||
});
|
||||
|
||||
it('lists direct child topics for a parent topic', async () => {
|
||||
const children = await db.getTopicChildren('programming language');
|
||||
|
||||
expect(children.map((topic) => topic.name)).toEqual(['TypeScript']);
|
||||
});
|
||||
|
||||
it('lists direct parent topics for a child topic', async () => {
|
||||
const parents = await db.getTopicParents('TypeScript');
|
||||
|
||||
expect(parents.map((topic) => topic.name)).toEqual(['programming language']);
|
||||
});
|
||||
|
||||
it('returns lineage from nearest parent outward', async () => {
|
||||
const lineage = await db.getTopicLineage('TypeScript');
|
||||
|
||||
expect(lineage.map((topic) => topic.name)).toEqual([
|
||||
'programming language',
|
||||
'software technology',
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user