Skip to main content

eoka_protocol/
network.rs

1use std::collections::BTreeMap;
2
3use schemars::JsonSchema;
4use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
7pub struct NetworkMeta {
8    pub namespace: String,
9    pub active: bool,
10    pub entry_count: usize,
11    pub in_flight: usize,
12    pub last_id: u64,
13    pub next_since: u64,
14    pub body_pending: usize,
15    pub body_failed: usize,
16    pub warnings: Vec<String>,
17    pub suggested_commands: Vec<String>,
18}
19
20#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
21pub struct NetworkStatus {
22    pub active: bool,
23    pub session_id: Option<String>,
24    pub target_id: Option<String>,
25    pub patterns: Vec<String>,
26    pub entry_count: usize,
27    pub in_flight: usize,
28    pub captured_body_bytes: usize,
29    pub body_pending: usize,
30    pub body_failed: usize,
31    pub body_limit_bytes: usize,
32    pub per_body_limit_bytes: usize,
33    pub lagged_events: u64,
34    pub dropped_events: u64,
35    pub started_at: Option<u64>,
36    pub last_id: u64,
37    pub next_since: u64,
38}
39
40#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
41pub struct NetworkRecording {
42    pub meta: NetworkMeta,
43    pub status: NetworkStatus,
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
47pub struct NetworkCleared {
48    pub cleared: bool,
49    pub meta: NetworkMeta,
50}
51
52#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
53pub struct NetworkLog {
54    pub meta: NetworkMeta,
55    pub count: usize,
56    pub entries: Vec<NetworkLogRow>,
57    pub filters: NetworkLogFilters,
58}
59
60#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
61pub struct NetworkLogFilters {
62    pub limit: usize,
63    pub pattern: Option<String>,
64    pub method: Option<String>,
65    pub status: Option<u16>,
66    pub since: Option<u64>,
67    pub compact: bool,
68}
69
70#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
71#[serde(untagged)]
72pub enum NetworkLogRow {
73    Full(NetworkLogEntry),
74    Compact(NetworkCompactEntry),
75}
76
77#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
78pub struct NetworkLogEntry {
79    pub id: u64,
80    pub url: String,
81    pub method: String,
82    pub status: Option<u16>,
83    pub resource_type: Option<String>,
84    pub duration_ms: f64,
85    pub request_body: Option<NetworkBodySummary>,
86    pub response_body: Option<NetworkBodySummary>,
87    pub complete: bool,
88    pub failed: Option<String>,
89}
90
91#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
92pub struct NetworkCompactEntry {
93    pub id: u64,
94    pub url: String,
95    pub method: String,
96    pub status: Option<u16>,
97    pub complete: bool,
98}
99
100#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
101#[serde(deny_unknown_fields)]
102pub struct NetworkBodySummary {
103    pub bytes: usize,
104    pub base64: bool,
105    pub omitted: Option<String>,
106}
107
108#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
109pub struct NetworkBody {
110    pub bytes: usize,
111    pub base64: bool,
112    pub text: Option<String>,
113    pub omitted: Option<String>,
114    pub mime_type: Option<String>,
115    #[serde(default, skip_serializing_if = "Option::is_none")]
116    pub truncated: Option<bool>,
117}
118
119#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
120pub struct NetworkEntryDetail<B> {
121    pub id: u64,
122    pub session_id: String,
123    pub target_id: String,
124    pub request_id: String,
125    pub hop: u32,
126    pub url: String,
127    pub method: String,
128    pub resource_type: Option<String>,
129    pub started_at: Option<f64>,
130    pub duration_ms: f64,
131    pub request: NetworkRequestDetail<B>,
132    pub response: NetworkResponseDetail<B>,
133    pub failure: Option<String>,
134    pub canceled: bool,
135    pub complete: bool,
136}
137
138#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
139pub struct NetworkRequestDetail<B> {
140    pub headers: BTreeMap<String, String>,
141    pub headers_text: Option<String>,
142    pub post_data: Option<B>,
143}
144
145#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
146pub struct NetworkResponseDetail<B> {
147    pub status: Option<u16>,
148    pub status_text: Option<String>,
149    pub protocol: Option<String>,
150    pub mime_type: Option<String>,
151    pub headers: BTreeMap<String, String>,
152    pub headers_text: Option<String>,
153    pub remote_ip: Option<String>,
154    pub remote_port: Option<u64>,
155    pub encoded_data_length: Option<f64>,
156    pub timing: Option<BTreeMap<String, serde_json::Number>>,
157    pub redirect_url: Option<String>,
158    pub body: Option<B>,
159}
160
161#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
162pub struct NetworkShow {
163    pub meta: NetworkMeta,
164    pub entry: NetworkShowEntry,
165}
166
167#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
168#[serde(untagged)]
169pub enum NetworkShowEntry {
170    Metadata(NetworkEntryDetail<NetworkBodySummary>),
171    WithBody(NetworkEntryDetail<NetworkBody>),
172}
173
174#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
175pub struct NetworkMatch {
176    pub meta: NetworkMeta,
177    pub entry: NetworkLogEntry,
178    pub matched: bool,
179}
180
181#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
182pub struct NetworkExport {
183    pub meta: NetworkMeta,
184    pub path: String,
185    pub format: String,
186    pub entries: usize,
187    pub exported: usize,
188    pub skipped_in_flight: usize,
189    pub body_pending: usize,
190    pub body_omitted: usize,
191    pub warnings: Vec<String>,
192}