systemprompt_sync/models/
local_sync.rs1use chrono::{DateTime, Utc};
9use serde::Serialize;
10use std::fmt;
11use systemprompt_identifiers::SourceId;
12
13#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize)]
14pub enum LocalSyncDirection {
15 #[default]
16 ToDisk,
17 ToDatabase,
18}
19
20impl fmt::Display for LocalSyncDirection {
21 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22 match self {
23 Self::ToDisk => write!(f, "to_disk"),
24 Self::ToDatabase => write!(f, "to_database"),
25 }
26 }
27}
28
29#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize)]
30pub enum DiffStatus {
31 Added,
32 Removed,
33 Modified,
34}
35
36#[derive(Clone, Debug, Serialize)]
37pub struct ContentDiffItem {
38 pub slug: String,
39 pub source_id: SourceId,
40 pub status: DiffStatus,
41 pub disk_hash: Option<String>,
42 pub db_hash: Option<String>,
43 pub disk_updated_at: Option<DateTime<Utc>>,
44 pub db_updated_at: Option<DateTime<Utc>>,
45 pub title: Option<String>,
46}
47
48#[derive(Clone, Debug, Serialize)]
49pub struct ContentDiffResult {
50 pub source_id: SourceId,
51 pub added: Vec<ContentDiffItem>,
52 pub removed: Vec<ContentDiffItem>,
53 pub modified: Vec<ContentDiffItem>,
54 pub unchanged: usize,
55}
56
57impl Default for ContentDiffResult {
58 fn default() -> Self {
59 Self {
60 source_id: SourceId::new(""),
61 added: Vec::new(),
62 removed: Vec::new(),
63 modified: Vec::new(),
64 unchanged: 0,
65 }
66 }
67}
68
69impl ContentDiffResult {
70 pub const fn has_changes(&self) -> bool {
71 !self.added.is_empty() || !self.removed.is_empty() || !self.modified.is_empty()
72 }
73}
74
75#[derive(Clone, Debug, Default, Serialize)]
76pub struct LocalSyncResult {
77 pub items_synced: usize,
78 pub items_skipped: usize,
79 pub items_skipped_modified: usize,
80 pub items_deleted: usize,
81 pub errors: Vec<String>,
82 pub direction: LocalSyncDirection,
83}
84
85#[derive(Debug)]
86pub struct DiskContent {
87 pub slug: String,
88 pub title: String,
89 pub body: String,
90}