feat: add streaming core domain model

This commit is contained in:
a.tolmachev
2026-04-06 09:57:28 +03:00
parent d841cd0dda
commit 6a0381b8e5
12 changed files with 654 additions and 11 deletions
+40
View File
@@ -1,5 +1,7 @@
use serde::{Deserialize, Serialize};
use crate::streaming::{ExecutionMode, TransportBehavior};
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum Protocol {
@@ -40,3 +42,41 @@ pub enum ExportMode {
Portable,
Bundle,
}
impl Protocol {
pub fn supports_execution_mode(self, mode: ExecutionMode) -> bool {
match self {
Self::Rest => true,
Self::Graphql => matches!(mode, ExecutionMode::Unary),
Self::Grpc => true,
}
}
pub fn supports_transport_behavior(self, behavior: TransportBehavior) -> bool {
match self {
Self::Rest => true,
Self::Graphql => matches!(behavior, TransportBehavior::RequestResponse),
Self::Grpc => !matches!(behavior, TransportBehavior::DeferredResult),
}
}
}
#[cfg(test)]
mod tests {
use super::Protocol;
use crate::streaming::{ExecutionMode, TransportBehavior};
#[test]
fn graphql_support_matrix_is_restricted() {
assert!(Protocol::Graphql.supports_execution_mode(ExecutionMode::Unary));
assert!(!Protocol::Graphql.supports_execution_mode(ExecutionMode::Window));
assert!(!Protocol::Graphql.supports_execution_mode(ExecutionMode::Session));
assert!(!Protocol::Graphql.supports_transport_behavior(TransportBehavior::ServerStream));
}
#[test]
fn grpc_supports_session_but_not_deferred_result() {
assert!(Protocol::Grpc.supports_execution_mode(ExecutionMode::Session));
assert!(!Protocol::Grpc.supports_transport_behavior(TransportBehavior::DeferredResult));
}
}