Repository navigation
Description
Problem
PR #604 created HierarchyRelationship to abstract database edge terminology, but the abstraction is incomplete. The type still exposes SurrealDB-specific field names (in, out) throughout the frontend code.
Current Implementation (Incomplete Abstraction)
// packages/desktop-app/src/lib/types/event-types.ts
export interface HierarchyRelationship {
id: string; // Edge ID from database
in: string; // ❌ SurrealDB terminology exposed
out: string; // ❌ SurrealDB terminology exposed
order: number;
}
// Band-aid helper functions added in PR #604:
export function getParentId(rel: HierarchyRelationship): string {
return rel.in; // Still accessing database field
}
Problem: Frontend code still directly accesses database fields:
packages/desktop-app/src/lib/stores/reactive-structure-tree.svelte.ts- Lines 69-73, 170-171, 231-232packages/desktop-app/src/lib/services/tauri-sync-listener.ts- Lines 52, 56
// Frontend code exposes database implementation:
const parentId = edge.in; // ❌ Database field accessed directly
const childId = edge.out; // ❌ Database field accessed directly
Root Cause
The abstraction was only partially implemented. Helper functions were added, but the underlying type still uses database field names instead of domain-appropriate names.
Proposed Solution
Complete the abstraction by replacing database fields with domain-focused fields at the serialization boundary.
1. Update Frontend Type (Complete Abstraction)
// packages/desktop-app/src/lib/types/event-types.ts
/**
* Hierarchy relationship in the node tree
*
* Backend converts SurrealDB edge format to this type at the
* serialization boundary, isolating database implementation details.
*/
export interface HierarchyRelationship {
parentId: string; // ✅ Domain language (was: in)
childId: string; // ✅ Domain language (was: out)
order: number; // ✅ Sort order (domain concept)
}
// Note: 'id' field removed - frontend doesn't need edge IDs
// Note: Helper functions removed - no longer needed with proper field names
2. Update Frontend Usages
packages/desktop-app/src/lib/stores/reactive-structure-tree.svelte.ts:
// BEFORE (Lines 68-75):
for (const edge of edges) {
if (!tree.has(edge.in)) {
tree.set(edge.in, []);
}
tree.get(edge.in)!.push({
nodeId: edge.out,
order: edge.order
});
}
// AFTER:
for (const rel of relationships) {
if (!tree.has(rel.parentId)) {
tree.set(rel.parentId, []);
}
tree.get(rel.parentId)!.push({
nodeId: rel.childId,
order: rel.order
});
}
Similar updates needed in:
addChild()method (lines 169-225)removeChild()method (lines 228-240)updateChildOrder()method (lines 245-248)addInMemoryRelationship()helper (lines 316-322)__testOnly_addChild()test helper
packages/desktop-app/src/lib/services/tauri-sync-listener.ts:
// BEFORE (Lines 52, 56):
console.debug(`Hierarchy relationship created: ${event.payload.in} -> ${event.payload.out}`);
// AFTER:
console.debug(`Hierarchy relationship created: ${event.payload.parentId} -> ${event.payload.childId}`);
3. Update Rust Backend Serialization
Convert SurrealDB edge format to domain format at the serialization boundary.
packages/desktop-app/src-tauri/src/services/live_query_service.rs (or wherever edge events are emitted):
use serde::Serialize;
// Domain-focused type for frontend
#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
struct HierarchyRelationship {
parent_id: String, // Converted from SurrealDB edge.in
child_id: String, // Converted from SurrealDB edge.out
order: f64,
}
// Convert at serialization boundary:
fn emit_edge_event(event_type: &str, edge: &SurrealEdge) {
let relationship = HierarchyRelationship {
parent_id: edge.in.clone(),
child_id: edge.out.clone(),
order: edge.order,
};
emit(event_type, relationship);
}
packages/desktop-app/src-tauri/src/commands/db.rs (get_all_edges command):
Update return type to convert edges to domain format before returning to frontend.
Benefits
- Clean Domain Model - Frontend works with
parentId/childId, not database implementation details - Single Responsibility - Database format isolated to backend serialization layer
- Easier Maintenance - Database changes don't ripple through frontend code
- Better Readability - Self-documenting code with clear parent/child semantics
- Completes PR Post-migration fixes: terminology cleanup, edge abstraction, placeholder promotion bug #604 - Finishes the abstraction that was started but left incomplete
Acceptance Criteria
-
HierarchyRelationshiptype usesparentId/childIdinstead ofin/out -
idfield removed from type (frontend doesn't need edge IDs) - Helper functions
getParentId()/getChildId()removed (no longer needed) - All frontend usages updated to use new field names
- Rust backend converts at serialization boundary
- All 1427+ tests passing
- No TypeScript errors or linting issues
Related
- PR Post-migration fixes: terminology cleanup, edge abstraction, placeholder promotion bug #604 - Started this abstraction but left it incomplete
- Issue Backend should return relationship data from createNode API #603 - Different concern (backend returning relationship data from createNode)
- Issue Performance: Use SurrealDB recursive FETCH to return nested tree on initial load #602 - Performance optimization with recursive FETCH
Activity
malibio commentedon Nov 22, 2025
Test Baseline: All 1427 tests passing ✅
Complete HierarchyRelationship abstraction: replace in/out with paren…
Complete HierarchyRelationship abstraction: replace in/out with paren…
Complete HierarchyRelationship abstraction: replace in/out with paren…
Complete HierarchyRelationship abstraction: replace in/out with paren…
Complete HierarchyRelationship abstraction: replace in/out with paren…