Skip to content

Phase 1.3: Migrate Core Logic Components from nodespace-core-logic #75

Closed

Description

@malibio

Parent Issue

Part of Epic #69: Text Editor Architecture Enhancement - Phase 1

Summary

Migrate proven hierarchy management, node operations, and performance optimizations from existing nodespace-core-logic and nodespace-core-types to establish the foundation for our enhanced contenteditable architecture.

Background

The existing nodespace-core-logic contains sophisticated systems that should be preserved and enhanced:

  • Hierarchy Management: Complete hierarchy computation with caching (hierarchy.rs)
  • Node Operations: Unified upsert with type-segmented metadata (node_operations.rs)
  • Performance Optimizations: Root hierarchy optimization, O(1) queries
  • Multi-Level Embeddings: Individual, contextual, and hierarchical embeddings
  • Content Extraction: Smart content parsing with fallbacks

Core Components to Migrate

1. Hierarchy Management System

From hierarchy.rs - Migrate to TypeScript:

interface HierarchyComputation {
  getNodeDepth(nodeId: string): Promise<number>;
  getChildren(parentId: string): Promise<Node[]>;
  getDescendants(nodeId: string): Promise<Node[]>;
  getNodePath(nodeId: string): Promise<Node[]>;
  invalidateHierarchyCache(): Promise<void>;
}

interface HierarchyCache {
  depthCache: Map<string, number>;
  childrenCache: Map<string, string[]>;
  pathCache: Map<string, string[]>;
}

2. Node Operations with Type-Segmented Metadata

From node_operations.rs - Migrate core patterns:

interface NodeOperations {
  upsertNode(node: Node): Promise<void>;
  validateUpsertNode(node: Node): Promise<void>;
  resolveParentAndRoot(parentId?: string): Promise<[string?, string?]>;
  handleSiblingPositioning(nodeId: string, beforeSiblingId?: string, parentId?: string): Promise<void>;
  ensureDateNodeExists(date: Date): Promise<string>;
}

3. Enhanced Node Structure

From nodespace-core-types - Preserve database compatibility:

interface NodeSpaceNode {
  id: string;
  type: string;
  content: string;
  parent_id?: string;
  before_sibling?: string;  // Single-pointer approach initially
  root_id?: string;         // Root hierarchy optimization
  created_at: string;
  updated_at: string;
  metadata?: any;
}

Implementation Tasks

  • Create HierarchyService with complete computation system and caching
  • Implement NodeOperationsService with unified upsert and type-segmented metadata
  • Add content extraction utilities with smart parsing and fallbacks
  • Create enhanced Node interface with database compatibility
  • Implement single-pointer sibling navigation (before_sibling only)
  • Add root hierarchy optimization for O(1) query performance
  • Create MultiLevelEmbeddings interface for future AI integration
  • Build performance monitoring and caching strategies
  • Add comprehensive unit tests for all migrated functionality
  • Create TypeScript type definitions matching Rust patterns

Acceptance Criteria

  • HierarchyService implements complete hierarchy computation with caching
  • NodeOperationsService handles unified upsert with type-segmented metadata preservation
  • Content extraction utilities work with smart parsing and fallback strategies
  • Enhanced Node structure maintains compatibility with existing database persistence
  • Single-pointer sibling navigation works correctly with upgrade path documented
  • Root hierarchy optimization provides O(1) query performance
  • Multi-level embeddings interfaces ready for Phase 3 AI integration
  • All migrated functionality has comprehensive unit tests (>95% coverage)
  • Performance benchmarks meet or exceed existing nodespace-core-logic performance

Dependencies

  • ContentProcessor service (Phase 1.1) for content coordination
  • NodeManager service (Phase 1.2) for integration

Estimated Effort

5-6 days

Definition of Done

  • All core logic components migrated and functional
  • Comprehensive test suite with >95% coverage
  • Performance benchmarks demonstrate O(1) hierarchy optimizations
  • Type-segmented metadata preservation working correctly
  • Database compatibility maintained with existing patterns
  • Documentation updated with migration decisions and patterns
  • Code review completed
  • Foundation ready for Phase 2 backlinking integration

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions