//! Plain data transferred to the UI. Ids are UUID strings and days are `YYYY-MM-DD`, which //! keeps the generated Dart side free of extra codecs. use synapse_core::{Block, Page, journal_title}; /// Page header data. #[derive(Debug, Clone, PartialEq)] pub struct PageDto { pub id: String, pub title: String, /// Set for journal pages. pub journal_date: Option, /// Journal day the page was born in. pub origin_journal: Option, pub created_at: i64, pub updated_at: i64, /// The page is a hub (no blocks; members list instead of an outline). pub is_hub: bool, /// Hub description (empty for notes). pub description: String, /// Titles of the tag pages this page is filed under, in the order they were added. pub tags: Vec, /// The page is a tag page (a topic that other pages are filed under). pub is_tag: bool, /// Type names ("persona", "lugar"...: plain names, not pages), in the order added. pub types: Vec, } impl From<&Page> for PageDto { fn from(p: &Page) -> Self { Self { id: p.id.to_string(), title: p.title.clone(), journal_date: p.journal_date.map(journal_title), origin_journal: p.origin_journal.map(journal_title), created_at: p.created_at, updated_at: p.updated_at, is_hub: p.is_hub(), description: p.description.clone(), tags: p.tags.clone(), is_tag: p.is_tag(), types: p.types.clone(), } } } /// A tag or type of the vocabulary. #[derive(Debug, Clone, PartialEq)] pub struct TagDto { pub name: String, /// Pages using it. pub count: u32, /// One of the seeded suggestions. pub suggested: bool, } /// One row of the outline, in pre-order. #[derive(Debug, Clone, PartialEq)] pub struct BlockDto { pub id: String, pub parent_id: Option, pub depth: u32, pub content: String, pub collapsed: bool, pub has_children: bool, } impl BlockDto { pub(crate) fn new(depth: usize, b: &Block, has_children: bool) -> Self { Self { id: b.id.to_string(), parent_id: b.parent_id.map(|p| p.to_string()), depth: depth as u32, content: b.content.clone(), collapsed: b.collapsed, has_children, } } } /// Everything the page view needs in one call. #[derive(Debug, Clone, PartialEq)] pub struct PageData { pub page: PageDto, pub blocks: Vec, pub aliases: Vec, /// Previous/next existing journal (journal pages only). pub prev_journal: Option, pub next_journal: Option, } /// Where a block goes, relative to `anchor`. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum PlaceKind { After, Before, /// Last child of `anchor`, or last root block when `anchor` is `None`. LastChildOf, /// First child of `anchor`, or first root block when `anchor` is `None`. FirstChildOf, } #[derive(Debug, Clone, PartialEq, Eq)] pub struct Place { pub kind: PlaceKind, pub anchor: Option, } /// Blocks of one page referencing the queried page. #[derive(Debug, Clone, PartialEq)] pub struct BacklinkGroup { pub page_id: String, pub page_title: String, pub is_journal: bool, pub blocks: Vec, } #[derive(Debug, Clone, PartialEq)] pub struct PageBrief { pub id: String, pub title: String, pub is_journal: bool, pub is_hub: bool, } impl From<&Page> for PageBrief { fn from(p: &Page) -> Self { Self { id: p.id.to_string(), title: p.title.clone(), is_journal: p.is_journal(), is_hub: p.is_hub(), } } } #[derive(Debug, Clone, PartialEq)] pub struct RelatedDto { pub page: PageBrief, pub score: f32, } /// Target of a `((block ref))`. #[derive(Debug, Clone, PartialEq)] pub struct BlockRefDto { pub id: String, pub content: String, pub page_id: String, pub page_title: String, } #[derive(Debug, Clone, PartialEq)] pub struct EditDto { pub page_id: String, pub edits: u32, } #[derive(Debug, Clone, PartialEq)] pub struct TimelineDayDto { pub date: String, pub journal_id: Option, /// Pages born on this day. pub created: Vec, /// Pages edited on this day. pub edited: Vec, } /// Timeline slice plus the titles of every page it mentions. #[derive(Debug, Clone, PartialEq)] pub struct TimelineDto { pub days: Vec, pub pages: Vec, } #[derive(Debug, Clone, PartialEq)] pub struct AssetDto { pub hash: String, pub size: u64, pub mime: Option, pub original_name: Option, } /// Quick switcher / `[[` autocomplete hit. #[derive(Debug, Clone, PartialEq)] pub struct TitleHit { pub page_id: String, /// The matched title or alias. pub title: String, pub is_alias: bool, } /// `((` autocomplete hit. #[derive(Debug, Clone, PartialEq)] pub struct BlockHit { pub id: String, pub content: String, pub page_title: String, } /// Kind codes of [`GraphData::kinds`]. pub mod edge_kind { pub const LINK: u8 = 0; pub const TAG: u8 = 1; pub const PROPERTY: u8 = 2; pub const BLOCK_REF: u8 = 3; pub const EMBED: u8 = 4; /// Unlinked reference: the target's title appears in the source's text. pub const MENTION: u8 = 5; /// Hebbian association (undirected), weight = decayed synapse strength. pub const SYNAPSE: u8 = 6; /// Hub membership, hub → member (structural, weight 1). pub const CONTAINS: u8 = 7; /// A page filed under a tag page (page → tag page, weight 1). Unlike `TAG` (an inline /// `#tag` in the text) it comes from the page's own `tags` list. pub const TAGGED: u8 = 8; } #[derive(Debug, Clone, PartialEq)] pub struct GraphNode { pub id: String, pub title: String, pub journal_date: Option, pub origin_journal: Option, pub created_at: i64, /// Distinct neighbours over structural edges (links, tags, properties, block refs, hub /// membership). pub degree: u32, /// Distinct pages referencing this one. pub backlinks: u32, /// Community (Louvain), numbered by size: 0 is the largest. pub cluster: u32, /// Node index of the tag this page uses most, if any. pub primary_tag: Option, /// The page is a hub (`PageKind::Hub`). pub is_hub: bool, /// Node index of the deepest hub containing this page (a hub: itself). pub home_hub: Option, /// Tag names of the page (see `PageDto::tags`), for grouping by tag. pub tags: Vec, } /// The whole page-level graph, edges as parallel arrays (cheap to move across the FFI). /// Edges are directed source → target, except synapses (stored once, `source < target`). #[derive(Debug, Clone, PartialEq)] pub struct GraphData { pub nodes: Vec, pub sources: Vec, pub targets: Vec, /// See [`edge_kind`]. pub kinds: Vec, /// Number of references (structural edges) or synapse strength. pub weights: Vec, /// Op-log sequence the data was built at. pub seq: i64, } /// One batch of layout iterations. #[derive(Debug, Clone, PartialEq)] pub struct LayoutFrame { /// `x0, y0, x1, y1, ...` pub positions: Vec, /// Remaining "temperature"; the layout is settled when it reaches 0. pub alpha: f32, } /// A hub (folder-like page) with its members. #[derive(Debug, Clone, PartialEq)] pub struct HubDto { pub id: String, pub title: String, pub description: String, /// 0 for root hubs, one more per level of nesting. pub depth: u32, /// Sub-hubs first, then notes, each by title. pub members: Vec, /// Ids of the members that are hubs themselves. pub sub_hubs: Vec, } #[derive(Debug, Clone, PartialEq)] pub struct HubsDto { /// Sorted by title. pub hubs: Vec, /// Ids of the hubs that are not a member of any hub, by title. pub roots: Vec, } /// A level of a namespace (`A/B` under `A`); `id` is `None` when only deeper pages exist. #[derive(Debug, Clone, PartialEq)] pub struct NamespaceEntry { pub title: String, pub id: Option, } /// Hub and namespace context of one page. #[derive(Debug, Clone, PartialEq)] pub struct PageStructure { pub is_hub: bool, /// Hub description (empty for notes). pub description: String, /// Empty unless the page is a hub; sub-hubs first, then notes. pub members: Vec, /// Hubs the page belongs to (its own membership list), by title. pub in_hubs: Vec, /// Ancestor namespaces from the root: `A`, `A/B` for `A/B/C` (they may not exist). pub ns_path: Vec, pub ns_children: Vec, } /// Defaults for the "convert to hub" dialog. #[derive(Debug, Clone, PartialEq)] pub struct HubPreviewDto { /// Last namespace segment of the title. pub suggested_title: String, /// First prose block as plain text (<= 280 chars). pub suggested_description: String, /// Candidate members: pages the outline links or tags (outline order), then pages /// referencing the note from properties or tags. pub members: Vec, /// Blocks that are prose rather than links (what "keep the outline" would save). pub prose_blocks: u32, pub blocks: u32, /// `" (notes)"`, for the note receiving the outline. pub suggested_note_title: String, } /// A page the legacy purge offers to delete. #[derive(Debug, Clone, PartialEq)] pub struct LegacyCandidate { pub id: String, pub title: String, pub reason: String, pub blocks: u32, pub preselected: bool, }