Skip to content

Complete HierarchyRelationship abstraction - replace in/out with parentId/childId #608

Closed

Description

@malibio

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-232
  • packages/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

  1. Clean Domain Model - Frontend works with parentId/childId, not database implementation details
  2. Single Responsibility - Database format isolated to backend serialization layer
  3. Easier Maintenance - Database changes don't ripple through frontend code
  4. Better Readability - Self-documenting code with clear parent/child semantics
  5. Completes PR Post-migration fixes: terminology cleanup, edge abstraction, placeholder promotion bug #604 - Finishes the abstraction that was started but left incomplete

Acceptance Criteria

  • HierarchyRelationship type uses parentId/childId instead of in/out
  • id field 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

Activity

  1. malibio commented on Nov 22, 2025

    @malibio
    CollaboratorAuthor

    Test Baseline: All 1427 tests passing ✅

  2. self-assigned this
    on Nov 22, 2025
  3. added a commit that references this issue on Nov 22, 2025
    21fa465
  4. added a commit that references this issue on Nov 22, 2025
    263cd8e
  5. added 2 commits that reference this issue on Feb 4, 2026
    d63e015
    11ec28d
  6. added a commit that references this issue on Feb 26, 2026
    b413794
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions