flams_router_backend/
lib.rs1#![recursion_limit = "256"]
2#![cfg_attr(docsrs, feature(doc_auto_cfg))]
3
4use flams_ontology::file_states::FileStateSummary;
5use flams_utils::vecmap::VecMap;
6
7#[cfg(any(
8 all(feature = "ssr", feature = "hydrate", not(feature = "docs-only")),
9 not(any(feature = "ssr", feature = "hydrate"))
10))]
11compile_error!("exactly one of the features \"ssr\" or \"hydrate\" must be enabled");
12
13pub mod components;
14pub mod index_components;
15pub mod server_fns;
16
17#[derive(Debug, Clone, PartialEq, Eq, Hash, Default, serde::Serialize, serde::Deserialize)]
18pub struct FileStates(VecMap<String, FileStateSummary>);
19
20#[cfg(feature = "ssr")]
21impl From<flams_system::backend::archives::source_files::FileStates> for FileStates {
22 fn from(value: flams_system::backend::archives::source_files::FileStates) -> Self {
23 Self(
24 value
25 .formats
26 .into_iter()
27 .map(|(k, v)| (k.to_string(), v))
28 .collect(),
29 )
30 }
31}
32
33#[cfg(feature = "ssr")]
34impl
35 From<
36 &VecMap<
37 flams_system::formats::BuildTargetId,
38 flams_system::backend::archives::source_files::FileState,
39 >,
40 > for FileStates
41{
42 fn from(
43 value: &VecMap<
44 flams_system::formats::BuildTargetId,
45 flams_system::backend::archives::source_files::FileState,
46 >,
47 ) -> Self {
48 use flams_system::backend::archives::source_files::FileState;
49 Self(
50 value
51 .iter()
52 .map(|(k, v)| {
53 (
54 k.to_string(),
55 match v {
56 FileState::New => FileStateSummary {
57 new: 1,
58 ..Default::default()
59 },
60 FileState::Stale(s) => FileStateSummary {
61 stale: 1,
62 last_built: s.last_built,
63 last_changed: s.last_changed,
64 ..Default::default()
65 },
66 FileState::UpToDate(s) => FileStateSummary {
67 up_to_date: 1,
68 last_built: s.last_built,
69 ..Default::default()
70 },
71 FileState::Deleted => FileStateSummary {
72 deleted: 1,
73 ..Default::default()
74 },
75 },
76 )
77 })
78 .collect(),
79 )
80 }
81}