Repository navigation
Description
Overview
TypeScript node type interfaces are inconsistent with the Rust backend's serialization output. This creates type mismatches and potential runtime issues when the frontend receives data from Tauri commands, MCP handlers, or the HTTP dev-proxy.
Problem Statement
Issue 1: TaskNode Structure Mismatch
The Rust TaskNode struct (after Issue #673) serializes to a flat structure:
{
"id": "task-123",
"nodeType": "task",
"content": "Fix the bug",
"version": 1,
"createdAt": "2025-01-01T00:00:00Z",
"modifiedAt": "2025-01-01T00:00:00Z",
"status": "open",
"priority": 2,
"dueDate": null,
"assignee": null
}But the TypeScript TaskNode interface expects a nested structure:
interface TaskNode extends Node {
nodeType: 'task';
properties: {
task?: {
status?: TaskStatus;
priority?: TaskPriority;
dueDate?: string;
// ...
};
};
}Impact: getTaskStatus(node) reads from node.properties.task?.status but backend sends node.status directly.
Issue 2: Simple Node Types Have Unnecessary Property Declarations
CodeBlockNode, QuoteBlockNode, and OrderedListNode declare explicit properties types:
export interface CodeBlockNode extends Node {
nodeType: 'code-block';
properties: {
language?: string; // ❌ Actually derived from content, not stored
[key: string]: unknown;
};
}But these properties are derived from content, not stored in the database:
languageis parsed from code fence syntax (```typescript)header levelis parsed from#count- These should NOT be declared as
properties
Issue 3: Inconsistent Patterns Across Node Types
| Node Type | Current Pattern | Should Be |
|---|---|---|
| Text | Uses base Node |
✅ Correct |
| Date | Uses base Node |
Should extend with nodeType: 'date' |
| Header | Uses base Node |
Should extend with nodeType: 'header' |
| CodeBlock | Extends with properties.language |
Extend with just nodeType |
| QuoteBlock | Extends with empty properties |
Extend with just nodeType |
| OrderedList | Extends with empty properties |
Extend with just nodeType |
| Task | Extends with nested properties.task |
Flat interface matching Rust |
| Schema | Flat interface | ✅ Correct |
Technical Specifications
Reference Files
TypeScript Types (to modify):
packages/desktop-app/src/lib/types/task-node.ts- TaskNode interface and helperspackages/desktop-app/src/lib/types/code-block-node.ts- CodeBlockNode interfacepackages/desktop-app/src/lib/types/quote-block-node.ts- QuoteBlockNode interfacepackages/desktop-app/src/lib/types/ordered-list-node.ts- OrderedListNode interfacepackages/desktop-app/src/lib/types/node.ts- Base Node interface
Rust Backend (reference only - do not modify):
packages/core/src/models/task_node.rs- Flat TaskNode struct (lines 192-232)packages/core/src/models/schema_node.rs- Flat SchemaNode struct (reference pattern)packages/core/src/models/mod.rs-node_to_typed_value()function (lines 82-95)
Frontend Consumers (must update usages):
packages/desktop-app/src/lib/design/components/task-node.svelte- UsesgetTaskStatus()packages/desktop-app/src/lib/design/components/base-node-viewer.svelte- Maps task properties
Target Architecture
Pattern 1: Simple Node Types (no spoke table)
All simple node types should extend Node with only nodeType narrowing:
// Correct pattern for simple types
export interface TextNode extends Node {
nodeType: 'text';
}
export interface DateNode extends Node {
nodeType: 'date';
}
export interface HeaderNode extends Node {
nodeType: 'header';
}
export interface CodeBlockNode extends Node {
nodeType: 'code-block';
}
export interface QuoteBlockNode extends Node {
nodeType: 'quote-block';
}
export interface OrderedListNode extends Node {
nodeType: 'ordered-list';
}Pattern 2: Spoke Table Types (Task, Schema)
Types with spoke tables have flat interfaces matching Rust serialization:
// TaskNode - flat structure matching Rust output
export interface TaskNode {
// Hub fields
id: string;
nodeType: 'task';
content: string;
version: number;
createdAt: string;
modifiedAt: string;
// Spoke fields (flat, not nested in properties)
status: TaskStatus;
priority?: number;
dueDate?: string;
assignee?: string;
}
// SchemaNode already follows this pattern correctlyHelper Function Updates
Before (reads from nested properties):
export function getTaskStatus(node: TaskNode): TaskStatus {
return node.properties.task?.status ?? 'open';
}After (reads from flat fields):
export function getTaskStatus(node: TaskNode): TaskStatus {
return node.status ?? 'open';
}Content-derived helpers remain unchanged:
// These parse from content, not properties - keep as-is
export function getLanguage(node: CodeBlockNode): string {
// Parse from code fence in node.content
}
export function getHeaderLevel(node: HeaderNode): number {
// Count # characters in node.content
}Implementation Approach
Phase 1: Update Simple Node Type Interfaces
-
Modify
code-block-node.ts:- Remove
properties.languagedeclaration - Keep interface as
extends Nodewith justnodeType: 'code-block' - Keep
getLanguage()helper (parses from content) - Update tests
- Remove
-
Modify
quote-block-node.ts:- Remove explicit
propertiesdeclaration - Keep interface as
extends Nodewith justnodeType: 'quote-block' - Update tests
- Remove explicit
-
Modify
ordered-list-node.ts:- Remove explicit
propertiesdeclaration - Keep interface as
extends Nodewith justnodeType: 'ordered-list' - Update tests
- Remove explicit
-
Create missing interfaces (if not exist):
TextNode extends NodewithnodeType: 'text'DateNode extends NodewithnodeType: 'date'HeaderNode extends NodewithnodeType: 'header'
Phase 2: Update TaskNode to Flat Structure
-
Modify
task-node.ts:- Change
TaskNodeinterface to flat structure (not extendingNode) - Update all helper functions (
getTaskStatus,setTaskStatus, etc.) - Add type guard that checks for flat structure
- Change
-
Update consumers:
task-node.svelte- UpdategetTaskStatus()usagebase-node-viewer.svelte- Update task property mapping- Any other files using
properties.task
-
Update tests to use new flat structure
Phase 3: Verification
- Run full test suite:
bun run test:all - Run type checking:
bunx svelte-check - Manual testing of task node functionality
- Verify Tauri/HTTP communication works correctly
Acceptance Criteria
- All simple node types (text, date, header, code-block, quote-block, ordered-list) extend
Nodewith onlynodeTypenarrowing - No simple node types declare explicit
propertiesfields -
TaskNodeinterface is flat, matching RustTaskNodeserialization output -
TaskNodedoes NOT extend baseNode(it's a separate flat interface likeSchemaNode) - All helper functions (
getTaskStatus,setTaskStatus, etc.) work with flat structure - Type guards (
isTaskNode,isCodeBlockNode, etc.) work correctly - All existing tests pass
-
bunx svelte-checkpasses with zero errors - Task node UI functionality works correctly (status changes, priority, etc.)
Testing Strategy
Unit Tests:
- Test type guards for all node types
- Test helper functions with new flat TaskNode structure
- Test content-derived helpers (getLanguage, getHeaderLevel)
Integration Tests:
- Test TaskNode round-trip through Tauri commands
- Test task status updates via UI
- Test task node rendering in task-node.svelte
Dependencies
None - this is a standalone cleanup issue.
Related Issues
- Strongly-Typed Node Structs with Direct Spoke Table Deserialization #673 (Strongly-typed node structs - introduced flat TaskNode in Rust)
- Simplify Schema Architecture: Remove SchemaDefinition and SchemaService #690 (Schema simplification - established flat SchemaNode pattern)
Activity
malibio commentedon Dec 1, 2025
Test baseline: Frontend: 729 passed, Rust: 490 passed (3 ignored)
Align TypeScript node types with Rust backend serialization (#700)
Remove backward compatibility code and add TaskNode tests (#700)
Align TypeScript Node Type Interfaces with Rust Backend Serialization (…
Align TypeScript Node Type Interfaces with Rust Backend Serialization (…
Align TypeScript Node Type Interfaces with Rust Backend Serialization (…
Align TypeScript Node Type Interfaces with Rust Backend Serialization (…