Skip to content

feat: Connection store with validation #369

@ggfevans

Description

@ggfevans

Parent Epic

Part of #362 (Connection Graph Model - Port-Based Architecture)


Summary

Implement a connection store with CRUD operations and validation logic for port-based connections.

Acceptance Criteria

  • Create src/lib/stores/connection.svelte.ts
  • addConnection(a_port_id, b_port_id, props) method
  • updateConnection(id, updates) method
  • removeConnection(id) method
  • getConnection(id) method
  • getConnectionsForPort(port_id) method
  • getConnectionsForDevice(device_id) method
  • Validation: port can only have one connection (error)
  • Validation: incompatible port types (warning)
  • Validation: same connection class required
  • Undo/redo support via raw operations
  • Dirty state tracking

Validation Rules

  1. Single connection per port: Most ports allow only one connection. Error if already connected.
  2. Type compatibility: Warning if connecting mismatched types (e.g., RJ45 to SFP).
  3. Class match: Network ports only connect to network ports, power to power.
  4. Self-connection: Cannot connect a port to itself.
  5. Duplicate: Cannot create duplicate connection between same ports.

API

interface ConnectionStore {
  // Getters
  connections: Connection[];
  getConnection(id: string): Connection | undefined;
  getConnectionsForPort(portId: string): Connection[];
  getConnectionsForDevice(deviceId: string): Connection[];
  
  // CRUD
  addConnection(input: CreateConnectionInput): { connection: Connection } | { errors: string[] };
  updateConnection(id: string, updates: Partial<Connection>): { success: true } | { errors: string[] };
  removeConnection(id: string): Connection | undefined;
  removeConnectionsForDevice(deviceId: string): number;
  
  // Raw operations (for undo/redo)
  addConnectionRaw(connection: Connection): void;
  updateConnectionRaw(id: string, updates: Partial<Connection>): void;
  removeConnectionRaw(id: string): void;
  
  // Validation
  validateConnection(input: CreateConnectionInput): ValidationResult;
}

Test Requirements

  • addConnection creates valid connection
  • Double-connecting a port raises error
  • Type mismatch raises warning
  • Self-connection raises error
  • Duplicate connection raises error
  • removeConnectionsForDevice removes all connections for device
  • Undo/redo works for connection operations
  • Dirty state updates on changes

Related

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions