Skip to main content

wasm4pm_compat/
streaming.rs

1//! # Streaming Process Evidence
2//!
3//! Typed shapes for streaming event log evidence — online process monitoring.
4//! A streaming evidence surface carries the same type law as batch evidence
5//! but with an additional streaming-context marker.
6//!
7//! ## What this module IS
8//!
9//! - Structure-only typed markers for online vs. offline evidence collection.
10//! - Zero-cost context tags that prevent an online monitoring window from being
11//!   silently substituted for an offline analysis log at the type level.
12//! - A companion to [`crate::evidence`]: streaming context is orthogonal to the
13//!   `Raw → Admitted` lifecycle.
14//!
15//! ## What this module is NOT
16//!
17//! - **Not** a streaming runtime. No event ingestion, no window management, no
18//!   sliding-window logic. Those concerns graduate to `wasm4pm`.
19//! - **Not** a replacement for [`crate::evidence::Evidence`]. Use
20//!   `ContextualEvidence<T, Context>` to add a collection-context tag to an
21//!   evidence value; the lifecycle law is unchanged.
22//!
23//! ## Graduation
24//!
25//! When you need to actually ingest events from a stream, manage windows, or
26//! perform online conformance checking, graduate to `wasm4pm`. The context
27//! markers here travel with the evidence into the engine.
28
29use core::marker::PhantomData;
30
31/// Marker that this evidence is produced by a streaming source with a fixed
32/// window size.
33///
34/// `WINDOW_SIZE` is a compile-time constant naming the maximum number of events
35/// in a single evidence window. It is a structural constraint only — no buffer
36/// is allocated here. Graduate to `wasm4pm` when windowed ingestion must run.
37///
38/// This is structure only. See [`crate::streaming`]. Graduate to `wasm4pm`
39/// when streaming ingestion must be executed.
40pub struct StreamingSource<const WINDOW_SIZE: usize>;
41
42/// A streaming event evidence window of fixed size.
43///
44/// `SIZE` is a compile-time constant bounding the window. `T` is the element
45/// type (e.g., an event shape). This is a structure-only envelope — no
46/// elements are stored at this layer.
47///
48/// This is structure only. See [`crate::streaming`]. Graduate to `wasm4pm`
49/// when window contents must be consumed by an online monitor.
50pub struct EventWindow<T, const SIZE: usize> {
51    _items: PhantomData<T>,
52}
53
54impl<T, const SIZE: usize> EventWindow<T, SIZE> {
55    /// Construct a typed evidence window envelope.
56    ///
57    /// # Examples
58    ///
59    /// ```ignore
60    /// use wasm4pm_compat::streaming::EventWindow;
61    ///
62    /// let _window: EventWindow<u8, 128> = EventWindow::new();
63    /// ```
64    pub fn new() -> Self {
65        Self {
66            _items: PhantomData,
67        }
68    }
69}
70
71impl<T, const SIZE: usize> Default for EventWindow<T, SIZE> {
72    fn default() -> Self {
73        Self::new()
74    }
75}
76
77/// Online monitoring context — evidence produced in real-time from a live event
78/// stream.
79///
80/// Use as the `Context` type parameter of [`ContextualEvidence`] when the
81/// evidence was collected during active process execution.
82///
83/// This is structure only. See [`crate::streaming`]. Graduate to `wasm4pm`
84/// when online monitoring logic must execute.
85pub struct OnlineMonitoringContext;
86
87/// Offline analysis context — evidence collected from a complete, static event
88/// log.
89///
90/// Use as the `Context` type parameter of [`ContextualEvidence`] when the
91/// evidence was collected from a finished log rather than a live stream.
92///
93/// This is structure only. See [`crate::streaming`]. Graduate to `wasm4pm`
94/// when offline replay or conformance checking must execute.
95pub struct OfflineAnalysisContext;
96
97/// Evidence tagged with its collection context.
98///
99/// `Context` is one of [`OnlineMonitoringContext`] or [`OfflineAnalysisContext`]
100/// (or a custom context type). The tag is zero-cost — `PhantomData` only.
101///
102/// An `ContextualEvidence<T, OnlineMonitoringContext>` is a different type from
103/// `ContextualEvidence<T, OfflineAnalysisContext>`, so a function that demands
104/// offline evidence cannot accidentally receive an online window.
105///
106/// ## Type aliases
107///
108/// See [`OnlineEvidence`] and [`OfflineEvidence`] for the common case.
109///
110/// This is structure only. See [`crate::streaming`]. Graduate to `wasm4pm`
111/// when context-dependent processing must execute.
112pub struct ContextualEvidence<T, Context> {
113    /// The inner evidence value.
114    pub inner: T,
115    _ctx: PhantomData<Context>,
116}
117
118impl<T> ContextualEvidence<T, OfflineAnalysisContext> {
119    /// Wrap `inner` as offline (complete-log) evidence.
120    ///
121    /// # Examples
122    ///
123    /// ```ignore
124    /// use wasm4pm_compat::streaming::ContextualEvidence;
125    ///
126    /// let ev = ContextualEvidence::offline(42u32);
127    /// assert_eq!(ev.inner, 42);
128    /// ```
129    pub fn offline(inner: T) -> Self {
130        Self {
131            inner,
132            _ctx: PhantomData,
133        }
134    }
135}
136
137impl<T> ContextualEvidence<T, OnlineMonitoringContext> {
138    /// Wrap `inner` as online (live-stream) evidence.
139    ///
140    /// # Examples
141    ///
142    /// ```ignore
143    /// use wasm4pm_compat::streaming::ContextualEvidence;
144    ///
145    /// let ev = ContextualEvidence::online(42u32);
146    /// assert_eq!(ev.inner, 42);
147    /// ```
148    pub fn online(inner: T) -> Self {
149        Self {
150            inner,
151            _ctx: PhantomData,
152        }
153    }
154}
155
156/// Type alias for evidence collected in an online (live-stream) context.
157///
158/// Equivalent to `ContextualEvidence<T, OnlineMonitoringContext>`.
159///
160/// # Examples
161///
162/// ```ignore
163/// use wasm4pm_compat::streaming::{OnlineEvidence, ContextualEvidence};
164///
165/// let ev: OnlineEvidence<u32> = ContextualEvidence::online(7u32);
166/// assert_eq!(ev.inner, 7);
167/// ```
168pub type OnlineEvidence<T> = ContextualEvidence<T, OnlineMonitoringContext>;
169
170/// Type alias for evidence collected in an offline (complete-log) context.
171///
172/// Equivalent to `ContextualEvidence<T, OfflineAnalysisContext>`.
173///
174/// # Examples
175///
176/// ```ignore
177/// use wasm4pm_compat::streaming::{OfflineEvidence, ContextualEvidence};
178///
179/// let ev: OfflineEvidence<u32> = ContextualEvidence::offline(7u32);
180/// assert_eq!(ev.inner, 7);
181/// ```
182pub type OfflineEvidence<T> = ContextualEvidence<T, OfflineAnalysisContext>;