Skip to content

Implement Type-Safe Node CRUD Operations End-to-End #709

Closed

Description

@malibio

Problem

We have strongly-typed node interfaces (TypeScript) and structs (Rust) for core node types like TaskNode, SchemaNode, etc., but CRUD operations still go through the generic NodeUpdate pipeline, which:

  1. Drops spoke fields - NodeUpdate only accepts content, nodeType, properties, embeddingVector
  2. Loses type safety - Frontend sends { status: 'in_progress' } but backend silently ignores it
  3. Requires workarounds - Developers must remember to use nested properties.task.status instead of flat node.status

Current State (Broken)

TaskNode.svelte reads node.status (flat) ✅
  → dispatches taskStateChanged event
  → base-node-viewer calls updateTaskStatus({ status: 'in_progress' })
  → sharedNodeStore.updateNode(nodeId, { status }, source)
  → tauriCommands.updateNode() → invoke('update_node', { update: { status } })
  → Rust NodeUpdate struct has no 'status' field
  → STATUS IS SILENTLY DROPPED ❌

Desired State (Type-Safe)

TaskNode.svelte uses TaskNode interface ✅
  → dispatches taskStateChanged event  
  → base-node-viewer calls updateTaskNode(nodeId, { status: 'in_progress' })
  → sharedNodeStore routes to registered TaskNode updater (plugin system)
  → tauriCommands.updateTaskNode() → invoke('update_task_node', { status })
  → Rust NodeService::update_task_node() updates spoke table
  → Returns updated TaskNode with new status ✅

Scope

Frontend Changes

  1. Extend UpdateNodeInput or create typed variants (UpdateTaskNodeInput, etc.)
  2. Add type-specific update methods to backend-adapter.ts:
    • updateTaskNode(id, version, update: TaskNodeUpdate)
    • Pattern: one method per core node type with spoke fields
  3. Plugin registry dispatch - sharedNodeStore routes updates based on nodeType:
    updateNode(nodeId, changes, source) {
      const node = this.getNode(nodeId);
      const updater = pluginRegistry.getUpdater(node.nodeType);
      if (updater) {
        return updater.update(nodeId, changes);  // Type-specific
      }
      return genericUpdate(nodeId, changes);  // Fallback for simple types
    }
  4. Remove workarounds in base-node-viewer.svelte that try to read from both nested and flat formats

Backend Changes

  1. Add update_task_node() to NodeService:
    pub async fn update_task_node(
        &self,
        id: &str,
        expected_version: i64,
        update: TaskNodeUpdate,
    ) -> Result<TaskNode, NodeServiceError>
  2. Add TaskNodeUpdate struct with spoke fields:
    pub struct TaskNodeUpdate {
        pub content: Option<String>,
        pub status: Option<TaskStatus>,
        pub priority: Option<i32>,
        pub due_date: Option<Option<DateTime<Utc>>>,
        pub assignee: Option<Option<String>>,
    }
  3. Add Tauri command update_task_node in commands/nodes.rs
  4. Update spoke table in same transaction as hub table

Types Requiring Typed Updates

Node Type Has Spoke Table Spoke Fields
task Yes status, priority, dueDate, assignee
schema Yes isCore, schemaVersion, description, fields
date Yes (TBD - calendar-specific fields)
text No None (hub-only)

Acceptance Criteria

  • Clicking task icon to toggle status persists to database
  • Task status survives page reload
  • TaskNode.svelte uses TaskNode interface throughout (no generic Node casting)
  • Backend update_task_node() validates spoke fields with type safety
  • Plugin registry can register type-specific updaters
  • Generic update_node() still works for hub-only types (text, etc.)
  • No silent field dropping - unknown fields should error or warn

Related Issues

Technical Notes

The hub-and-spoke architecture (Issue #560) was designed for this - spoke tables store type-specific data. We just never implemented the write path for spoke fields through the CRUD API.

Activity

  1. self-assigned this
    on Dec 1, 2025
  2. malibio commented on Dec 1, 2025

    @malibio
    CollaboratorAuthor

    Test Baseline (feature/issue-709-type-safe-crud branch):

    • Frontend: 1477 passed (74 test files)
    • Rust: 482 passed, 16 ignored

    Starting implementation of type-safe CRUD operations end-to-end.

  3. added 2 commits that reference this issue on Dec 1, 2025
    13c663a
    a609cd9
  4. malibio commented on Dec 1, 2025

    @malibio
    CollaboratorAuthor

    Refined Implementation Plan (Type-Safe CRUD with Hybrid Schema Forms)

    After further analysis, the implementation should follow a hybrid architecture pattern documented in docs/architecture/components/component-architecture-guide.md:

    Key Insight

    The current implementation (PR #711) added type-safe backend methods (updateTaskNode) but the frontend routing is incomplete:

    • SchemaPropertyForm still calls generic sharedNodeStore.updateNode()
    • base-node-viewer.updateSchemaField() has hardcoded routing (not plugin-based)

    The Complete Pattern

    Core Node Types (compile-time)     User-Defined Types (runtime)
             │                                  │
             ▼                                  ▼
       TaskSchemaForm                   SchemaPropertyForm
       (hardcoded UI)                   (dynamic/generic)
             │                                  │
             └──────────┬───────────────────────┘
                        ▼
          sharedNodeStore.updateNode()
          (smart routing via plugin registry)
                        │
             ┌─────────┴─────────┐
             ▼                   ▼
       updateTaskNode()    updateNode()
       (spoke table)       (properties JSON)
    

    Remaining Implementation Tasks

    Phase 1: Type-Specific Schema Form (TaskSchemaForm)

    • Create task-schema-form.svelte with hardcoded UI for task spoke fields
    • Use TaskNode interface directly (not generic Node)
    • Call sharedNodeStore.updateNode() which will route to updateTaskNode()

    Phase 2: Plugin-Based Routing

    • Add schemaForm property to PluginDefinition interface
    • Add updater property for type-specific update logic
    • Update sharedNodeStore.updateNode() to check for registered updater
    • Remove hardcoded routing in base-node-viewer.updateSchemaField()

    Phase 3: BaseNodeViewer Integration

    • Update BaseNodeViewer to select schema form via plugin registry
    • Use TaskSchemaForm for task nodes, SchemaPropertyForm for others
    • Remove direct SchemaPropertyForm import (dynamic via plugin)

    Why This Pattern?

    1. Type Safety for Core Types: TaskSchemaForm uses TaskNode interface - full TypeScript inference
    2. Flexibility for User Types: SchemaPropertyForm handles custom schemas at runtime
    3. Single Entry Point: All updates go through updateNode(), routing is internal
    4. Extensible: Adding new core types = create TypeSchemaForm + register plugin

    Documentation

    See updated architecture guide: docs/architecture/components/component-architecture-guide.md#type-safe-crud-architecture-issue-709

  5. added 4 commits that reference this issue on Feb 4, 2026
    7e28cc8
    85e7368
    964da00
    0008864
  6. added 2 commits that reference this issue on Feb 26, 2026
    76fc484
    3d6af32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions