oxirs-stream 0.3.1

Real-time streaming support with Kafka/NATS/MQTT/OPC-UA I/O, RDF Patch, and SPARQL Update delta
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
//! # Visual Designer — Types
//!
//! All data types used by the visual pipeline designer: canvas structures,
//! node/edge definitions, pipeline metadata, validation results, and
//! debugger state types.

use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use std::collections::{HashMap, VecDeque};
use std::sync::Arc;
use tokio::sync::RwLock;

use crate::event::StreamEvent;

/// Visual pipeline designer configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct VisualDesignerConfig {
    pub enable_auto_layout: bool,
    pub enable_validation: bool,
    pub enable_optimization: bool,
    pub max_nodes: usize,
    pub max_edges: usize,
    pub enable_real_time_debug: bool,
    pub debug_buffer_size: usize,
    pub enable_profiling: bool,
    pub export_formats: Vec<ExportFormat>,
}

impl Default for VisualDesignerConfig {
    fn default() -> Self {
        Self {
            enable_auto_layout: true,
            enable_validation: true,
            enable_optimization: true,
            max_nodes: 1000,
            max_edges: 5000,
            enable_real_time_debug: true,
            debug_buffer_size: 10000,
            enable_profiling: true,
            export_formats: vec![
                ExportFormat::Json,
                ExportFormat::Yaml,
                ExportFormat::Dot,
                ExportFormat::Mermaid,
            ],
        }
    }
}

/// Supported export formats
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum ExportFormat {
    Json,
    Yaml,
    Dot,     // GraphViz DOT format
    Mermaid, // Mermaid diagram format
    Svg,     // SVG image
    Png,     // PNG image
}

/// Pipeline node representing a stream operation
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PipelineNode {
    pub id: String,
    pub name: String,
    pub node_type: NodeType,
    pub position: Position,
    pub config: NodeConfig,
    pub metadata: NodeMetadata,
    pub status: NodeStatus,
}

/// Node types for different stream operations
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum NodeType {
    // Source nodes
    Source(SourceType),
    // Processing nodes
    Map,
    Filter,
    FlatMap,
    Reduce,
    Aggregate,
    Join,
    Window,
    // Transformation nodes
    Transform(TransformType),
    // ML nodes
    MLModel(MLModelType),
    // Output nodes
    Sink(SinkType),
    // Control nodes
    Router,
    Splitter,
    Merger,
    // Debug nodes
    Breakpoint,
    Logger,
    Profiler,
}

/// Source types
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum SourceType {
    Kafka,
    Nats,
    Redis,
    Memory,
    File,
    WebSocket,
    Http,
    Custom(String),
}

/// Transform types
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum TransformType {
    RdfTransform,
    SparqlQuery,
    GraphPattern,
    Custom(String),
}

/// ML model types
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum MLModelType {
    OnlineLearning,
    AnomalyDetection,
    Prediction,
    Classification,
    Clustering,
    Custom(String),
}

/// Sink types
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum SinkType {
    Kafka,
    Nats,
    Redis,
    Memory,
    Database,
    File,
    WebSocket,
    Http,
    Custom(String),
}

/// Node position in visual canvas
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Position {
    pub x: f64,
    pub y: f64,
    pub z: Option<f64>, // For 3D visualization
}

/// Node configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NodeConfig {
    pub parameters: HashMap<String, ConfigValue>,
    pub input_ports: Vec<Port>,
    pub output_ports: Vec<Port>,
    pub resource_limits: ResourceLimits,
}

/// Configuration value types
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ConfigValue {
    String(String),
    Number(f64),
    Boolean(bool),
    Array(Vec<ConfigValue>),
    Object(HashMap<String, ConfigValue>),
}

/// Port for node connections
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Port {
    pub id: String,
    pub name: String,
    pub port_type: PortType,
    pub data_type: DataType,
    pub required: bool,
}

/// Port types
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum PortType {
    Input,
    Output,
}

/// Data types flowing through ports
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum DataType {
    StreamEvent,
    RdfTriple,
    SparqlResult,
    Json,
    Binary,
    Custom(String),
}

/// Resource limits for nodes
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ResourceLimits {
    pub max_memory_mb: Option<u64>,
    pub max_cpu_percent: Option<f64>,
    pub max_execution_time_ms: Option<u64>,
    pub max_events_per_second: Option<u64>,
}

/// Node metadata
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NodeMetadata {
    pub created_at: DateTime<Utc>,
    pub updated_at: DateTime<Utc>,
    pub version: String,
    pub author: Option<String>,
    pub description: Option<String>,
    pub tags: Vec<String>,
}

/// Node status for monitoring
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum NodeStatus {
    Idle,
    Running,
    Paused,
    Error(String),
    Completed,
}

/// Pipeline edge connecting nodes
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PipelineEdge {
    pub id: String,
    pub source_node_id: String,
    pub source_port_id: String,
    pub target_node_id: String,
    pub target_port_id: String,
    pub edge_type: EdgeType,
    pub config: EdgeConfig,
    pub metadata: EdgeMetadata,
}

/// Edge types
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum EdgeType {
    DataFlow,
    ControlFlow,
    Conditional(Condition),
}

/// Condition for conditional edges
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct Condition {
    pub expression: String,
    pub predicate_type: PredicateType,
}

/// Predicate types
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum PredicateType {
    Equals,
    NotEquals,
    GreaterThan,
    LessThan,
    Contains,
    Matches,
    Custom(String),
}

/// Edge configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EdgeConfig {
    pub buffer_size: usize,
    pub backpressure_strategy: BackpressureStrategy,
    pub error_handling: ErrorHandling,
}

/// Backpressure strategies
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum BackpressureStrategy {
    Drop,
    Buffer,
    Block,
    Exponential,
    Adaptive,
}

/// Error handling strategies
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ErrorHandling {
    Propagate,
    Ignore,
    Retry { max_attempts: u32 },
    DeadLetter,
    Custom(String),
}

/// Edge metadata
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EdgeMetadata {
    pub created_at: DateTime<Utc>,
    pub label: Option<String>,
    pub style: EdgeStyle,
}

/// Edge visual style
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EdgeStyle {
    pub color: String,
    pub thickness: f64,
    pub line_type: LineType,
}

/// Line types for edges
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum LineType {
    Solid,
    Dashed,
    Dotted,
    Curved,
}

/// Visual pipeline definition
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct VisualPipeline {
    pub id: String,
    pub name: String,
    pub description: Option<String>,
    pub version: String,
    pub nodes: HashMap<String, PipelineNode>,
    pub edges: HashMap<String, PipelineEdge>,
    pub metadata: PipelineMetadata,
    pub validation_result: Option<ValidationResult>,
}

/// Pipeline metadata
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PipelineMetadata {
    pub created_at: DateTime<Utc>,
    pub updated_at: DateTime<Utc>,
    pub author: Option<String>,
    pub tags: Vec<String>,
    pub properties: HashMap<String, String>,
}

/// Validation result
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ValidationResult {
    pub is_valid: bool,
    pub errors: Vec<ValidationError>,
    pub warnings: Vec<ValidationWarning>,
    pub validated_at: DateTime<Utc>,
}

/// Validation error
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ValidationError {
    pub error_type: ValidationErrorType,
    pub message: String,
    pub node_id: Option<String>,
    pub edge_id: Option<String>,
}

/// Validation error types
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum ValidationErrorType {
    MissingRequiredPort,
    IncompatibleDataTypes,
    CyclicDependency,
    DisconnectedNode,
    InvalidConfiguration,
    ResourceLimitExceeded,
    DuplicateNodeId,
}

/// Validation warning
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ValidationWarning {
    pub warning_type: ValidationWarningType,
    pub message: String,
    pub node_id: Option<String>,
    pub suggestion: Option<String>,
}

/// Validation warning types
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum ValidationWarningType {
    UnusedPort,
    SuboptimalConfiguration,
    PerformanceBottleneck,
    MemoryPressure,
    DeprecatedNode,
}

/// Pipeline debugger for real-time debugging
#[derive(Debug)]
pub struct PipelineDebugger {
    pub pipeline: VisualPipeline,
    pub config: DebuggerConfig,
    pub state: Arc<RwLock<DebuggerState>>,
    pub breakpoints: Arc<RwLock<HashMap<String, Breakpoint>>>,
    pub event_history: Arc<RwLock<VecDeque<DebugEvent>>>,
}

/// Debugger configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DebuggerConfig {
    pub enable_breakpoints: bool,
    pub enable_event_capture: bool,
    pub max_event_history: usize,
    pub enable_time_travel: bool,
    pub enable_profiling: bool,
    pub capture_intermediate_results: bool,
}

impl Default for DebuggerConfig {
    fn default() -> Self {
        Self {
            enable_breakpoints: true,
            enable_event_capture: true,
            max_event_history: 10000,
            enable_time_travel: true,
            enable_profiling: true,
            capture_intermediate_results: true,
        }
    }
}

/// Debugger state
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DebuggerState {
    pub is_running: bool,
    pub is_paused: bool,
    pub current_node_id: Option<String>,
    pub execution_stack: Vec<String>,
    pub variables: HashMap<String, DebugVariable>,
    pub metrics: DebugMetrics,
}

/// Debug variable
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DebugVariable {
    pub name: String,
    pub value: String,
    pub var_type: String,
    pub scope: String,
}

/// Debug metrics
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct DebugMetrics {
    pub events_processed: u64,
    pub events_dropped: u64,
    pub average_latency_ms: f64,
    pub throughput_per_second: f64,
    pub memory_usage_mb: f64,
    pub cpu_usage_percent: f64,
}

/// Breakpoint for debugging
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Breakpoint {
    pub id: String,
    pub node_id: String,
    pub condition: Option<String>,
    pub enabled: bool,
    pub hit_count: u64,
    pub max_hits: Option<u64>,
}

/// Debug event captured during execution
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DebugEvent {
    pub timestamp: DateTime<Utc>,
    pub node_id: String,
    pub event_type: DebugEventType,
    pub data: StreamEvent,
    pub metadata: HashMap<String, String>,
}

/// Debug event types
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum DebugEventType {
    NodeEnter,
    NodeExit,
    BreakpointHit,
    Error,
    Warning,
}

/// Pipeline information summary
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PipelineInfo {
    pub id: String,
    pub name: String,
    pub version: String,
    pub node_count: usize,
    pub edge_count: usize,
    pub created_at: DateTime<Utc>,
    pub updated_at: DateTime<Utc>,
}

/// Optimization result
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OptimizationResult {
    pub original_metrics: PipelineMetrics,
    pub suggestions: Vec<OptimizationSuggestion>,
    pub optimized_at: DateTime<Utc>,
}

/// Pipeline metrics
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PipelineMetrics {
    pub node_count: usize,
    pub edge_count: usize,
    pub avg_chain_length: f64,
    pub max_chain_length: usize,
    pub parallel_opportunities: usize,
    pub bottleneck_nodes: Vec<String>,
}

/// Optimization suggestion
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OptimizationSuggestion {
    pub suggestion_type: OptimizationType,
    pub impact: ImpactLevel,
    pub description: String,
    pub estimated_improvement: f64,
}

/// Optimization types
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum OptimizationType {
    ReduceChainLength,
    IncreaseParallelism,
    OptimizeBufferSize,
    ReduceMemoryUsage,
    ImproveLocality,
}

/// Impact levels
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum ImpactLevel {
    Low,
    Medium,
    High,
    Critical,
}

/// Pipeline validator
pub struct PipelineValidator {
    pub(crate) config: VisualDesignerConfig,
}

/// Pipeline optimizer
pub struct PipelineOptimizer {
    pub(crate) config: VisualDesignerConfig,
}