Skip to main content

pjson_rs/application/commands/
mod.rs

1//! Commands - Write operations that change system state
2
3use crate::application::dto::{PriorityDto, SessionIdDto, StreamIdDto};
4use crate::domain::{
5    aggregates::stream_session::SessionConfig, entities::stream::StreamConfig,
6    value_objects::JsonData,
7};
8use serde::{Deserialize, Serialize};
9
10/// Create new streaming session
11#[derive(Debug, Clone, Serialize, Deserialize)]
12pub struct CreateSessionCommand {
13    /// Session configuration (limits, priority thresholds, transport options).
14    pub config: SessionConfig,
15    /// Optional human-readable client identifier.
16    pub client_info: Option<String>,
17    /// Optional `User-Agent` header captured from the originating request.
18    pub user_agent: Option<String>,
19    /// Optional source IP address captured from the originating request.
20    pub ip_address: Option<String>,
21}
22
23/// Create new stream within a session
24#[derive(Debug, Clone, Serialize, Deserialize)]
25pub struct CreateStreamCommand {
26    /// Identifier of the parent session.
27    pub session_id: SessionIdDto,
28    /// JSON payload that will be decomposed into priority frames.
29    pub source_data: JsonData,
30    /// Optional per-stream configuration overriding session defaults.
31    pub config: Option<StreamConfig>,
32}
33
34/// Start streaming data for a specific stream
35#[derive(Debug, Clone, Serialize, Deserialize)]
36pub struct StartStreamCommand {
37    /// Identifier of the parent session.
38    pub session_id: SessionIdDto,
39    /// Identifier of the stream to start.
40    pub stream_id: StreamIdDto,
41}
42
43/// Generate frames for a stream with priority filtering
44#[derive(Debug, Clone, Serialize, Deserialize)]
45pub struct GenerateFramesCommand {
46    /// Identifier of the parent session.
47    pub session_id: SessionIdDto,
48    /// Identifier of the stream to generate frames for.
49    pub stream_id: StreamIdDto,
50    /// Minimum priority frames must satisfy to be emitted.
51    pub priority_threshold: PriorityDto,
52    /// Maximum number of frames to emit in this batch.
53    pub max_frames: usize,
54}
55
56/// Complete a stream successfully
57#[derive(Debug, Clone, Serialize, Deserialize)]
58pub struct CompleteStreamCommand {
59    /// Identifier of the parent session.
60    pub session_id: SessionIdDto,
61    /// Identifier of the stream being completed.
62    pub stream_id: StreamIdDto,
63    /// Optional payload checksum used to verify integrity.
64    pub checksum: Option<String>,
65}
66
67/// Close session gracefully
68#[derive(Debug, Clone, Serialize, Deserialize)]
69pub struct CloseSessionCommand {
70    /// Identifier of the session to close.
71    pub session_id: SessionIdDto,
72}
73
74/// Batch generate frames across multiple streams with priority
75#[derive(Debug, Clone, Serialize, Deserialize)]
76pub struct BatchGenerateFramesCommand {
77    /// Identifier of the parent session.
78    pub session_id: SessionIdDto,
79    /// Minimum priority frames must satisfy to be emitted.
80    pub priority_threshold: PriorityDto,
81    /// Maximum total number of frames to emit across all streams.
82    pub max_frames: usize,
83}