Skip to main content

pushkin_core/
envelope.rs

1//! The uniform result JSON of spec §8.3 — the wire contract every adapter
2//! translates from (charter N7). camelCase on the wire, `deny_unknown_fields`
3//! on ingest (charter N2).
4
5use serde::{Deserialize, Serialize};
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
8#[serde(rename_all = "lowercase")]
9pub enum Decision {
10    Allow,
11    Block,
12}
13
14impl Decision {
15    #[must_use]
16    pub fn as_str(self) -> &'static str {
17        match self {
18            Decision::Allow => "allow",
19            Decision::Block => "block",
20        }
21    }
22}
23
24#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
25#[serde(rename_all = "lowercase")]
26pub enum Severity {
27    Error,
28    Warning,
29    Info,
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
33#[serde(deny_unknown_fields, rename_all = "camelCase")]
34pub struct Violation {
35    pub file: String,
36    pub line: u32,
37    pub rule: String,
38    pub contract: Option<String>,
39    pub fix_hint: String,
40    pub suggestions: Vec<String>,
41    pub severity: Severity,
42}
43
44#[derive(Debug, Clone, Serialize, Deserialize)]
45#[serde(deny_unknown_fields, rename_all = "camelCase")]
46pub struct CheckResult {
47    pub decision: Decision,
48    pub violations: Vec<Violation>,
49    pub duration_ms: f64,
50}