Skip to main content

kindling_types/
common.rs

1use serde::{Deserialize, Serialize};
2
3#[cfg(feature = "ts-rs")]
4use ts_rs::TS;
5
6/// Unique identifier for entities. Implementation uses UUIDv4 format.
7pub type Id = String;
8
9/// Timestamp in epoch milliseconds.
10///
11/// Aliased to `i64` to keep arithmetic ergonomic in Rust. Every public field
12/// that holds a `Timestamp` MUST carry a `#[cfg_attr(feature = "ts-rs",
13/// ts(type = "number"))]` override (use `ts(optional, type = "number")` for
14/// `Option<Timestamp>`); without it the `ts-rs` projection would emit
15/// `bigint`, breaking the JSON `number` wire contract. Round-trip and
16/// bindings tests will fail if the override is missed.
17pub type Timestamp = i64;
18
19/// Scope identifiers for multi-dimensional isolation.
20///
21/// All fields are optional to support partial scoping. Mirrors `ScopeIds`
22/// in `packages/kindling-core/src/types/common.ts`.
23#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
24#[cfg_attr(feature = "ts-rs", derive(TS), ts(export, export_to = "../bindings/"))]
25#[serde(rename_all = "camelCase")]
26pub struct ScopeIds {
27    #[serde(default, skip_serializing_if = "Option::is_none")]
28    #[cfg_attr(feature = "ts-rs", ts(optional))]
29    pub session_id: Option<String>,
30    #[serde(default, skip_serializing_if = "Option::is_none")]
31    #[cfg_attr(feature = "ts-rs", ts(optional))]
32    pub repo_id: Option<String>,
33    #[serde(default, skip_serializing_if = "Option::is_none")]
34    #[cfg_attr(feature = "ts-rs", ts(optional))]
35    pub agent_id: Option<String>,
36    #[serde(default, skip_serializing_if = "Option::is_none")]
37    #[cfg_attr(feature = "ts-rs", ts(optional))]
38    pub user_id: Option<String>,
39    #[serde(default, skip_serializing_if = "Option::is_none")]
40    #[cfg_attr(feature = "ts-rs", ts(optional))]
41    pub task_id: Option<String>,
42}
43
44/// Validation error details.
45#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
46#[cfg_attr(feature = "ts-rs", derive(TS), ts(export, export_to = "../bindings/"))]
47#[serde(rename_all = "camelCase")]
48pub struct ValidationError {
49    pub field: String,
50    pub message: String,
51    #[serde(default, skip_serializing_if = "Option::is_none")]
52    #[cfg_attr(feature = "ts-rs", ts(optional))]
53    pub value: Option<serde_json::Value>,
54}