mirror of
https://github.com/Dasemu/Synapse.git
synced 2026-11-26 15:26:17 +00:00
Merge branch 'feat/tags-types-view' into feat/settings-theme-tree
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
12c3cd463b
45 files changed
+3142
-248
No files matched your search
@@ -25,4 +25,4 @@ pub use structure::{
|
||||
HubConversion, HubInfo, HubPreview, Structure, is_legacy_page, namespace_parent,
|
||||
};
|
||||
pub use tags::{MAX_TAG_CHARS, TagInfo, normalize_tag};
|
||||
pub use types::SUGGESTED_TYPES;
|
||||
pub use types::{MAX_ICON_CHARS, SUGGESTED_TYPES, normalize_icon};
|
||||
@@ -183,12 +183,43 @@ pub struct OpRecord {
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(tag = "type", rename_all = "snake_case")]
|
||||
pub enum Op {
|
||||
UpsertPage { page: Page },
|
||||
DeletePage { id: PageId },
|
||||
UpsertBlock { block: Block },
|
||||
DeleteBlock { id: BlockId },
|
||||
PutAsset { asset: Asset },
|
||||
SetAlias { alias: String, page: Option<PageId> },
|
||||
UpsertPage {
|
||||
page: Page,
|
||||
},
|
||||
DeletePage {
|
||||
id: PageId,
|
||||
},
|
||||
UpsertBlock {
|
||||
block: Block,
|
||||
},
|
||||
DeleteBlock {
|
||||
id: BlockId,
|
||||
},
|
||||
PutAsset {
|
||||
asset: Asset,
|
||||
},
|
||||
SetAlias {
|
||||
alias: String,
|
||||
page: Option<PageId>,
|
||||
},
|
||||
/// Metadata of a type name (its icon), last writer wins per [`title_key`] of the name.
|
||||
PutTypeDef {
|
||||
def: TypeDef,
|
||||
},
|
||||
}
|
||||
|
||||
/// Graph-wide metadata of a type name: types are names, not pages, so this is where their
|
||||
/// icon lives (`type_defs` table, synced by [`Op::PutTypeDef`]). A definition also keeps a
|
||||
/// type in the vocabulary while no page uses it. `removed` is a tombstone: the type was
|
||||
/// deleted (it also hides a seeded suggestion of that name).
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct TypeDef {
|
||||
pub name: String,
|
||||
/// An emoji (a short string) shown next to the names of pages of this type.
|
||||
#[serde(default)]
|
||||
pub icon: Option<String>,
|
||||
#[serde(default)]
|
||||
pub removed: bool,
|
||||
}
|
||||
|
||||
/// Fields for creating a page; defaults come from the graph clock.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use rusqlite::OptionalExtension;
|
||||
|
||||
pub const VERSION: i64 = 7;
|
||||
pub const VERSION: i64 = 8;
|
||||
|
||||
pub const SCHEMA: &str = r#"
|
||||
CREATE TABLE IF NOT EXISTS meta (key TEXT PRIMARY KEY, value TEXT NOT NULL);
|
||||
@@ -107,6 +107,15 @@ CREATE TABLE IF NOT EXISTS assets (
|
||||
created_at INTEGER NOT NULL
|
||||
);
|
||||
|
||||
-- v8: type metadata (icon), one row per type name key; `removed` rows are tombstones.
|
||||
CREATE TABLE IF NOT EXISTS type_defs (
|
||||
type_key TEXT PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
icon TEXT,
|
||||
removed INTEGER NOT NULL DEFAULT 0,
|
||||
hlc TEXT NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS tombstones (id TEXT PRIMARY KEY, hlc TEXT NOT NULL);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS ops (
|
||||
@@ -272,6 +281,7 @@ pub fn migrate(conn: &rusqlite::Connection) -> rusqlite::Result<()> {
|
||||
// v7: a page's hub title is an implicit tag, so the index changes.
|
||||
rebuild_page_tags(conn)?;
|
||||
}
|
||||
// v8: `type_defs` (type icons) is created empty by `SCHEMA`; nothing to convert.
|
||||
conn.execute(
|
||||
"INSERT OR REPLACE INTO meta(key, value) VALUES ('schema', ?1)",
|
||||
[VERSION.to_string()],
|
||||
|
||||
@@ -1161,6 +1161,19 @@ impl Graph {
|
||||
true
|
||||
}
|
||||
}
|
||||
Op::PutTypeDef { def } => {
|
||||
let local: Option<String> = self
|
||||
.row(
|
||||
"SELECT hlc FROM type_defs WHERE type_key=?1",
|
||||
[title_key(&def.name)],
|
||||
|r| r.get(0),
|
||||
)
|
||||
.optional()?;
|
||||
local.is_none_or(|l| hlc > l.as_str()) && {
|
||||
self.write_type_def_row(def, hlc)?;
|
||||
true
|
||||
}
|
||||
}
|
||||
};
|
||||
if applied {
|
||||
self.log(hlc, op)?;
|
||||
@@ -1404,6 +1417,22 @@ impl Graph {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Stores a type definition row (no op logged), keyed by the name's [`title_key`].
|
||||
pub(crate) fn write_type_def_row(&self, def: &TypeDef, hlc: &str) -> Result<()> {
|
||||
self.exec(
|
||||
"INSERT OR REPLACE INTO type_defs(type_key, name, icon, removed, hlc)
|
||||
VALUES (?1, ?2, ?3, ?4, ?5)",
|
||||
params![
|
||||
title_key(&def.name),
|
||||
def.name.trim(),
|
||||
def.icon,
|
||||
def.removed,
|
||||
hlc
|
||||
],
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Page whose own title (not alias) matches, case-insensitively.
|
||||
fn page_by_exact_title(&self, title: &str) -> Result<Option<Page>> {
|
||||
Ok(self
|
||||
|
||||
@@ -17,12 +17,20 @@ use std::collections::{HashMap, HashSet};
|
||||
pub const MAX_TAG_CHARS: usize = 48;
|
||||
|
||||
/// A tag with the number of pages filed under it (explicitly or through a type).
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
#[derive(Debug, Clone, Default, PartialEq, Eq)]
|
||||
pub struct TagInfo {
|
||||
pub name: String,
|
||||
pub count: u32,
|
||||
/// Part of the seeded suggestions (types only).
|
||||
pub suggested: bool,
|
||||
/// Emoji of the type ([`crate::TypeDef::icon`]; types only).
|
||||
pub icon: Option<String>,
|
||||
/// Pages listing it among their explicit tags (`tag_catalog` only).
|
||||
pub explicit: u32,
|
||||
/// Pages having it as their type (`tag_catalog` only).
|
||||
pub typed: u32,
|
||||
/// Pages carrying it because their hub has this title (`tag_catalog` only).
|
||||
pub from_hub: u32,
|
||||
}
|
||||
|
||||
/// Cleans a tag name: leading `#` dropped, whitespace collapsed. `None` when nothing is left.
|
||||
@@ -135,7 +143,7 @@ impl Graph {
|
||||
/// Every tag in use (listed, implied by a type or by the page's hub): spelling of its first
|
||||
/// page, with its page count. Most used first, then by name.
|
||||
pub fn tag_catalog(&self) -> Result<Vec<TagInfo>> {
|
||||
let mut used: HashMap<String, (String, u32)> = HashMap::new();
|
||||
let mut used: HashMap<String, TagInfo> = HashMap::new();
|
||||
let mut sources = schema::tag_sources(self.conn(), None)?;
|
||||
sources.sort_by(|a, b| a.id.cmp(&b.id));
|
||||
for src in sources {
|
||||
@@ -143,18 +151,19 @@ impl Graph {
|
||||
for t in src.names() {
|
||||
let key = title_key(t);
|
||||
if seen.insert(key.clone()) {
|
||||
used.entry(key).or_insert((t.clone(), 0)).1 += 1;
|
||||
let info = used.entry(key.clone()).or_insert_with(|| TagInfo {
|
||||
name: t.clone(),
|
||||
..Default::default()
|
||||
});
|
||||
info.count += 1;
|
||||
let is = |n: &String| title_key(n) == key;
|
||||
info.explicit += u32::from(src.tags.iter().any(is));
|
||||
info.typed += u32::from(src.types.iter().take(1).any(is));
|
||||
info.from_hub += u32::from(src.hub.iter().any(is));
|
||||
}
|
||||
}
|
||||
}
|
||||
let mut out: Vec<TagInfo> = used
|
||||
.into_values()
|
||||
.map(|(name, count)| TagInfo {
|
||||
name,
|
||||
count,
|
||||
suggested: false,
|
||||
})
|
||||
.collect();
|
||||
let mut out: Vec<TagInfo> = used.into_values().collect();
|
||||
out.sort_by(|a, b| {
|
||||
b.count
|
||||
.cmp(&a.count)
|
||||
@@ -165,7 +174,8 @@ impl Graph {
|
||||
|
||||
/// Renames a tag everywhere: in the `tags` and `types` of every page carrying it (one
|
||||
/// transaction; each page is rewritten and logged, so it syncs). When a page already lists
|
||||
/// `new`, the two merge. Returns the number of pages changed. A hub's implicit tag is never renamed (the hub page
|
||||
/// `new`, the two merge. A type's definition (its icon) moves to the new name, keeping the
|
||||
/// icon `new` already had. Returns the number of pages changed. A hub's implicit tag is never renamed (the hub page
|
||||
/// is not touched): only explicit tags and types change.
|
||||
pub fn rename_tag(&self, old: &str, new: &str) -> Result<usize> {
|
||||
let new = normalize_tag(new).ok_or_else(|| Error::Invalid("empty tag name".into()))?;
|
||||
@@ -191,6 +201,7 @@ impl Graph {
|
||||
changed += 1;
|
||||
}
|
||||
}
|
||||
self.rename_type_def(&key, &new)?;
|
||||
tx.commit()?;
|
||||
Ok(changed)
|
||||
}
|
||||
|
||||
@@ -3,11 +3,17 @@
|
||||
//! Types are plain names from a small vocabulary, not pages: a page carries its own
|
||||
//! ([`Page::types`], at most one name, kept as a list for compatibility; synced with the page, last writer wins). Topics are a different
|
||||
//! mechanism: see `tags`.
|
||||
//!
|
||||
//! Graph-wide metadata of a type (its emoji icon) is a [`TypeDef`] in the `type_defs` table,
|
||||
//! keyed by [`title_key`] and synced with its own op ([`Op::PutTypeDef`], last writer wins per
|
||||
//! name). A definition also keeps an unused type in the vocabulary; a removed one is a
|
||||
//! tombstone that hides the type (even a seeded suggestion).
|
||||
|
||||
use crate::error::{Error, Result};
|
||||
use crate::model::{Page, PageId, title_key};
|
||||
use crate::model::{Op, Page, PageId, TypeDef, title_key};
|
||||
use crate::store::Graph;
|
||||
use crate::tags::{MAX_TAG_CHARS, TagInfo, normalize_tag};
|
||||
use rusqlite::OptionalExtension;
|
||||
use std::collections::HashMap;
|
||||
|
||||
/// Types offered in pickers before they are used anywhere (the seed of the vocabulary).
|
||||
@@ -16,6 +22,36 @@ pub const SUGGESTED_TYPES: [&str; 10] = [
|
||||
"receta",
|
||||
];
|
||||
|
||||
/// Longest icon, in characters (emoji sequences such as families or flags take several).
|
||||
pub const MAX_ICON_CHARS: usize = 16;
|
||||
|
||||
/// Cleans a type icon: trimmed; `None` when empty. Refused when longer than
|
||||
/// [`MAX_ICON_CHARS`], when it contains whitespace or control characters, or when it is plain
|
||||
/// ASCII (an icon is an emoji or symbol, not a word).
|
||||
pub fn normalize_icon(raw: &str) -> Result<Option<String>> {
|
||||
let t = raw.trim();
|
||||
if t.is_empty() {
|
||||
return Ok(None);
|
||||
}
|
||||
if t.chars().count() > MAX_ICON_CHARS
|
||||
|| t.chars().any(|c| c.is_whitespace() || c.is_control())
|
||||
|| t.is_ascii()
|
||||
{
|
||||
return Err(Error::Invalid(format!("{t:?} is not an emoji icon")));
|
||||
}
|
||||
Ok(Some(t.to_string()))
|
||||
}
|
||||
|
||||
fn checked_type_name(name: &str) -> Result<String> {
|
||||
let n = normalize_tag(name).ok_or_else(|| Error::Invalid("empty type name".into()))?;
|
||||
if n.chars().count() > MAX_TAG_CHARS {
|
||||
return Err(Error::Invalid(format!(
|
||||
"type {n:?} is longer than {MAX_TAG_CHARS} characters"
|
||||
)));
|
||||
}
|
||||
Ok(n)
|
||||
}
|
||||
|
||||
impl Graph {
|
||||
/// Sets the single type of `page` (name cleaned), or clears it with `None`. Journals and
|
||||
/// templates cannot be typed. The type is stored as a list of zero or one name.
|
||||
@@ -51,9 +87,11 @@ impl Graph {
|
||||
Ok(p)
|
||||
}
|
||||
|
||||
/// The vocabulary: every type in use (spelling of its first page) plus the suggestions not
|
||||
/// used yet. Used types first by count then name, then unused suggestions in seed order.
|
||||
/// The vocabulary: every type in use (spelling of its first page), then types defined but
|
||||
/// unused (by name), then the suggestions not used yet in seed order (unless removed).
|
||||
/// Used types are sorted by count then name. Each carries its icon.
|
||||
pub fn type_catalog(&self) -> Result<Vec<TagInfo>> {
|
||||
let defs = self.type_defs()?;
|
||||
let mut st = self.conn().prepare_cached(
|
||||
"SELECT types FROM pages WHERE types != '[]' ORDER BY created_at, id",
|
||||
)?;
|
||||
@@ -66,12 +104,19 @@ impl Graph {
|
||||
}
|
||||
}
|
||||
let suggested = |k: &str| SUGGESTED_TYPES.iter().any(|s| title_key(s) == k);
|
||||
let live_icon = |k: &str| {
|
||||
defs.get(k)
|
||||
.filter(|d| !d.removed)
|
||||
.and_then(|d| d.icon.clone())
|
||||
};
|
||||
let mut out: Vec<TagInfo> = used
|
||||
.iter()
|
||||
.map(|(k, (name, count))| TagInfo {
|
||||
name: name.clone(),
|
||||
count: *count,
|
||||
suggested: suggested(k),
|
||||
icon: live_icon(k),
|
||||
..Default::default()
|
||||
})
|
||||
.collect();
|
||||
out.sort_by(|a, b| {
|
||||
@@ -79,15 +124,219 @@ impl Graph {
|
||||
.cmp(&a.count)
|
||||
.then_with(|| title_key(&a.name).cmp(&title_key(&b.name)))
|
||||
});
|
||||
// Defined but unused types (created explicitly, or given an icon), by name.
|
||||
let mut unused: Vec<&TypeDef> = defs
|
||||
.iter()
|
||||
.filter(|(k, d)| !d.removed && !used.contains_key(*k) && !suggested(k))
|
||||
.map(|(_, d)| d)
|
||||
.collect();
|
||||
unused.sort_by_cached_key(|d| title_key(&d.name));
|
||||
out.extend(unused.into_iter().map(|d| TagInfo {
|
||||
name: d.name.clone(),
|
||||
count: 0,
|
||||
suggested: false,
|
||||
icon: d.icon.clone(),
|
||||
..Default::default()
|
||||
}));
|
||||
for s in SUGGESTED_TYPES {
|
||||
if !used.contains_key(&title_key(s)) {
|
||||
let k = title_key(s);
|
||||
let def = defs.get(&k);
|
||||
if !used.contains_key(&k) && !def.is_some_and(|d| d.removed) {
|
||||
out.push(TagInfo {
|
||||
name: s.to_string(),
|
||||
name: def.map_or_else(|| s.to_string(), |d| d.name.clone()),
|
||||
count: 0,
|
||||
suggested: true,
|
||||
icon: def.and_then(|d| d.icon.clone()),
|
||||
..Default::default()
|
||||
});
|
||||
}
|
||||
}
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
/// The type of every typed page.
|
||||
pub fn all_page_types(&self) -> Result<HashMap<PageId, String>> {
|
||||
let mut st = self
|
||||
.conn()
|
||||
.prepare_cached("SELECT id, types FROM pages WHERE types != '[]'")?;
|
||||
let rows = st.query_map([], |r| Ok((r.get::<_, String>(0)?, r.get::<_, String>(1)?)))?;
|
||||
let mut out = HashMap::new();
|
||||
for row in rows {
|
||||
let (id, types) = row?;
|
||||
let types: Vec<String> = serde_json::from_str(&types).unwrap_or_default();
|
||||
if let Some(t) = types.into_iter().next() {
|
||||
out.insert(crate::store::parse_id(&id)?, t);
|
||||
}
|
||||
}
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
/// Every stored type definition (removed ones included), by name key.
|
||||
pub fn type_defs(&self) -> Result<HashMap<String, TypeDef>> {
|
||||
let mut st = self
|
||||
.conn()
|
||||
.prepare_cached("SELECT type_key, name, icon, removed FROM type_defs")?;
|
||||
let rows = st.query_map([], |r| {
|
||||
Ok((
|
||||
r.get::<_, String>(0)?,
|
||||
TypeDef {
|
||||
name: r.get(1)?,
|
||||
icon: r.get(2)?,
|
||||
removed: r.get(3)?,
|
||||
},
|
||||
))
|
||||
})?;
|
||||
Ok(rows.collect::<rusqlite::Result<_>>()?)
|
||||
}
|
||||
|
||||
/// The definition of one type name (case-insensitive), removed ones included.
|
||||
pub fn type_def(&self, name: &str) -> Result<Option<TypeDef>> {
|
||||
Ok(self
|
||||
.row(
|
||||
"SELECT name, icon, removed FROM type_defs WHERE type_key=?1",
|
||||
[title_key(name)],
|
||||
|r| {
|
||||
Ok(TypeDef {
|
||||
name: r.get(0)?,
|
||||
icon: r.get(1)?,
|
||||
removed: r.get(2)?,
|
||||
})
|
||||
},
|
||||
)
|
||||
.optional()?)
|
||||
}
|
||||
|
||||
/// Writes and logs a type definition (synced as [`Op::PutTypeDef`]).
|
||||
fn put_type_def(&self, def: TypeDef) -> Result<()> {
|
||||
let hlc = self.tick();
|
||||
self.write_type_def_row(&def, &hlc)?;
|
||||
self.log(&hlc, &Op::PutTypeDef { def })
|
||||
}
|
||||
|
||||
/// How a type name is spelled: its definition, else its first page, else `name`.
|
||||
fn type_spelling(&self, name: &str) -> Result<String> {
|
||||
if let Some(d) = self.type_def(name)?.filter(|d| !d.removed) {
|
||||
return Ok(d.name);
|
||||
}
|
||||
let key = title_key(name);
|
||||
Ok(self
|
||||
.type_catalog()?
|
||||
.into_iter()
|
||||
.find(|t| t.count > 0 && title_key(&t.name) == key)
|
||||
.map_or_else(|| name.to_string(), |t| t.name))
|
||||
}
|
||||
|
||||
/// Adds a type to the vocabulary even if no page uses it (no-op when it is already
|
||||
/// defined). Returns its name as spelled in the graph.
|
||||
pub fn create_type(&self, name: &str) -> Result<String> {
|
||||
let name = checked_type_name(name)?;
|
||||
let tx = self.tx()?;
|
||||
if let Some(d) = self.type_def(&name)?.filter(|d| !d.removed) {
|
||||
tx.commit()?;
|
||||
return Ok(d.name);
|
||||
}
|
||||
let name = self.type_spelling(&name)?;
|
||||
self.put_type_def(TypeDef {
|
||||
name: name.clone(),
|
||||
icon: None,
|
||||
removed: false,
|
||||
})?;
|
||||
tx.commit()?;
|
||||
Ok(name)
|
||||
}
|
||||
|
||||
/// Sets (or with `None` clears) the emoji of a type, defining the type when setting one
|
||||
/// (see [`normalize_icon`] for what an icon may be). Clearing an undefined type is a no-op.
|
||||
pub fn set_type_icon(&self, name: &str, icon: Option<&str>) -> Result<()> {
|
||||
let name = checked_type_name(name)?;
|
||||
let icon = match icon {
|
||||
Some(i) => normalize_icon(i)?,
|
||||
None => None,
|
||||
};
|
||||
let tx = self.tx()?;
|
||||
let current = self.type_def(&name)?.filter(|d| !d.removed);
|
||||
// Clearing the icon of an undefined type changes nothing (and defines nothing).
|
||||
if current.as_ref().map_or(icon.is_none(), |d| d.icon == icon) {
|
||||
tx.commit()?;
|
||||
return Ok(());
|
||||
}
|
||||
let name = self.type_spelling(&name)?;
|
||||
self.put_type_def(TypeDef {
|
||||
name,
|
||||
icon,
|
||||
removed: false,
|
||||
})?;
|
||||
tx.commit()
|
||||
}
|
||||
|
||||
/// Deletes a type: pages of that type lose it (their explicit tags stay) and its
|
||||
/// definition becomes a tombstone (icon dropped; a seeded suggestion of that name is
|
||||
/// hidden too). Returns the number of pages changed.
|
||||
pub fn remove_type(&self, name: &str) -> Result<usize> {
|
||||
let name = checked_type_name(name)?;
|
||||
let key = title_key(&name);
|
||||
let tx = self.tx()?;
|
||||
let mut changed = 0;
|
||||
for id in self.pages_with_tag(&name)? {
|
||||
let Some(mut p) = self.get_page(id)? else {
|
||||
continue;
|
||||
};
|
||||
if p.page_type().is_some_and(|t| title_key(t) == key) {
|
||||
p.types.clear();
|
||||
p.updated_at = self.now_ms();
|
||||
self.write_page(&p, &self.tick())?;
|
||||
changed += 1;
|
||||
}
|
||||
}
|
||||
let name = self.type_def(&name)?.map_or(name, |d| d.name);
|
||||
self.put_type_def(TypeDef {
|
||||
name,
|
||||
icon: None,
|
||||
removed: true,
|
||||
})?;
|
||||
tx.commit()?;
|
||||
Ok(changed)
|
||||
}
|
||||
|
||||
/// Renames a type: like [`Graph::rename_tag`] (pages' types and same-name tags, merging
|
||||
/// duplicates), and the type stays in the vocabulary under `new` with its icon even when
|
||||
/// no page uses it (e.g. an unused suggestion). Returns the number of pages changed.
|
||||
pub fn rename_type(&self, old: &str, new: &str) -> Result<usize> {
|
||||
checked_type_name(new)?;
|
||||
let tx = self.tx()?;
|
||||
self.create_type(old)?;
|
||||
let n = self.rename_tag(old, new)?;
|
||||
tx.commit()?;
|
||||
Ok(n)
|
||||
}
|
||||
|
||||
/// Moves the definition of type `old_key` to `new` (used by `rename_tag`): `new` keeps its
|
||||
/// own icon if it has one, else takes the old one; the old name becomes a tombstone (only
|
||||
/// the spelling changes when the keys match). No-op when `old_key` has no live definition.
|
||||
pub(crate) fn rename_type_def(&self, old_key: &str, new: &str) -> Result<()> {
|
||||
let Some(old) = self.type_def(old_key)?.filter(|d| !d.removed) else {
|
||||
return Ok(());
|
||||
};
|
||||
if title_key(new) == old_key {
|
||||
if old.name != new {
|
||||
self.put_type_def(TypeDef {
|
||||
name: new.to_string(),
|
||||
..old
|
||||
})?;
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
let target = self.type_def(new)?.filter(|d| !d.removed);
|
||||
let icon = target.and_then(|d| d.icon).or(old.icon);
|
||||
self.put_type_def(TypeDef {
|
||||
name: new.to_string(),
|
||||
icon,
|
||||
removed: false,
|
||||
})?;
|
||||
self.put_type_def(TypeDef {
|
||||
name: old.name,
|
||||
icon: None,
|
||||
removed: true,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -506,7 +506,7 @@ fn old_ops_and_v2_databases_load() {
|
||||
r.get(0)
|
||||
})
|
||||
.unwrap();
|
||||
assert_eq!(schema, "7");
|
||||
assert_eq!(schema, "8");
|
||||
let p = g.get_page(id).unwrap().unwrap();
|
||||
assert_eq!((p.kind, p.title.as_str()), (PageKind::Note, "Legacy"));
|
||||
let h = g.create_hub("New hub", "").unwrap();
|
||||
@@ -996,3 +996,202 @@ fn v6_databases_gain_hub_tags() {
|
||||
let g = Graph::open(dir.path()).unwrap();
|
||||
assert_eq!(g.pages_with_tag("anime").unwrap(), [a]);
|
||||
}
|
||||
|
||||
fn type_row(g: &Graph, name: &str) -> Option<(String, u32, Option<String>)> {
|
||||
g.type_catalog()
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.find(|t| synapse_core::title_key(&t.name) == synapse_core::title_key(name))
|
||||
.map(|t| (t.name, t.count, t.icon))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn types_carry_an_icon_and_can_exist_without_pages() {
|
||||
let (_d, g) = graph();
|
||||
let p = page(&g, "Ada", &["x"]);
|
||||
g.set_page_type(p, Some("persona")).unwrap();
|
||||
g.set_type_icon("Persona", Some(" 🧑 ")).unwrap();
|
||||
assert_eq!(
|
||||
type_row(&g, "persona"),
|
||||
Some(("persona".into(), 1, Some("🧑".into())))
|
||||
);
|
||||
// Unused suggestions keep listing (e.g. "sueño"), and can get an icon.
|
||||
assert_eq!(type_row(&g, "sueño"), Some(("sueño".into(), 0, None)));
|
||||
g.set_type_icon("sueño", Some("💭")).unwrap();
|
||||
assert_eq!(
|
||||
type_row(&g, "sueño"),
|
||||
Some(("sueño".into(), 0, Some("💭".into())))
|
||||
);
|
||||
// A type created explicitly lists with no pages.
|
||||
assert_eq!(g.create_type(" Libro ").unwrap(), "Libro");
|
||||
assert_eq!(type_row(&g, "libro"), Some(("Libro".into(), 0, None)));
|
||||
assert_eq!(g.create_type("LIBRO").unwrap(), "Libro");
|
||||
// Icons are short emoji, not words; clearing works.
|
||||
assert!(invalid(g.set_type_icon("Libro", Some("ab"))));
|
||||
assert!(invalid(g.set_type_icon("Libro", Some("📕 📗"))));
|
||||
assert!(invalid(g.set_type_icon("Libro", Some(&"📕".repeat(17)))));
|
||||
g.set_type_icon("Libro", Some("👨👩👧👦")).unwrap();
|
||||
g.set_type_icon("Libro", None).unwrap();
|
||||
assert_eq!(type_row(&g, "libro"), Some(("Libro".into(), 0, None)));
|
||||
assert!(invalid(g.create_type(" ")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn renaming_a_type_keeps_its_icon_and_removing_drops_it() {
|
||||
let (_d, g) = graph();
|
||||
let a = page(&g, "A", &["x"]);
|
||||
let b = page(&g, "B", &["x"]);
|
||||
g.set_page_type(a, Some("persona")).unwrap();
|
||||
g.set_page_type(b, Some("persona")).unwrap();
|
||||
g.add_page_tag(b, "persona").unwrap();
|
||||
g.set_type_icon("persona", Some("🧑")).unwrap();
|
||||
assert_eq!(g.rename_tag("persona", "Gente").unwrap(), 2);
|
||||
assert_eq!(
|
||||
type_row(&g, "gente"),
|
||||
Some(("Gente".into(), 2, Some("🧑".into())))
|
||||
);
|
||||
// The old name is gone; a seeded suggestion of that name is not offered again.
|
||||
assert_eq!(type_row(&g, "persona"), None);
|
||||
// Merging into a type with its own icon keeps that icon.
|
||||
g.set_type_icon("humano", Some("🙂")).unwrap();
|
||||
g.rename_tag("gente", "humano").unwrap();
|
||||
assert_eq!(
|
||||
type_row(&g, "humano"),
|
||||
Some(("humano".into(), 2, Some("🙂".into())))
|
||||
);
|
||||
// Renaming an unused suggestion through rename_type keeps it listed.
|
||||
g.set_type_icon("sueño", Some("💭")).unwrap();
|
||||
assert_eq!(g.rename_type("sueño", "Sueños").unwrap(), 0);
|
||||
assert_eq!(
|
||||
type_row(&g, "sueños"),
|
||||
Some(("Sueños".into(), 0, Some("💭".into())))
|
||||
);
|
||||
assert_eq!(type_row(&g, "sueño"), None);
|
||||
// Case-only renames keep the definition.
|
||||
g.rename_type("Sueños", "sueños").unwrap();
|
||||
assert_eq!(
|
||||
type_row(&g, "sueños"),
|
||||
Some(("sueños".into(), 0, Some("💭".into())))
|
||||
);
|
||||
|
||||
// Removing a type clears it from its pages (explicit tags stay) and drops the icon.
|
||||
assert_eq!(g.remove_type("Humano").unwrap(), 2);
|
||||
assert!(g.get_page(a).unwrap().unwrap().types.is_empty());
|
||||
assert_eq!(g.get_page(b).unwrap().unwrap().tags, ["humano"]);
|
||||
assert_eq!(type_row(&g, "humano"), None);
|
||||
// Defining it again starts without an icon.
|
||||
g.create_type("humano").unwrap();
|
||||
assert_eq!(type_row(&g, "humano"), Some(("humano".into(), 0, None)));
|
||||
// A removed suggestion stays hidden until used again.
|
||||
g.remove_type("lugar").unwrap();
|
||||
assert_eq!(type_row(&g, "lugar"), None);
|
||||
g.set_page_type(a, Some("lugar")).unwrap();
|
||||
assert_eq!(type_row(&g, "lugar"), Some(("lugar".into(), 1, None)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn renaming_a_tag_leaves_undefined_types_alone() {
|
||||
let (_d, g) = graph();
|
||||
let a = page(&g, "A", &["x"]);
|
||||
g.add_page_tag(a, "idea").unwrap();
|
||||
let seq = g.last_seq().unwrap();
|
||||
g.rename_tag("idea", "ocurrencia").unwrap();
|
||||
// "idea" is only a suggestion (no definition): it stays offered, nothing is defined.
|
||||
assert_eq!(type_row(&g, "idea"), Some(("idea".into(), 0, None)));
|
||||
assert!(g.type_defs().unwrap().is_empty());
|
||||
assert!(
|
||||
g.ops_since(seq, 100)
|
||||
.unwrap()
|
||||
.iter()
|
||||
.all(|r| !matches!(r.op, Op::PutTypeDef { .. }))
|
||||
);
|
||||
// Clearing the icon of an undefined type is a no-op.
|
||||
g.set_type_icon("idea", None).unwrap();
|
||||
g.set_type_icon("nueva", None).unwrap();
|
||||
assert!(g.type_defs().unwrap().is_empty());
|
||||
assert_eq!(type_row(&g, "nueva"), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tag_catalog_says_where_each_tag_comes_from() {
|
||||
let (_d, g) = graph();
|
||||
let h = hub(&g, "Anime");
|
||||
let a = page(&g, "A", &["x"]);
|
||||
let b = page(&g, "B", &["x"]);
|
||||
g.add_to_hub(a, h).unwrap();
|
||||
g.add_page_tag(a, "idea").unwrap();
|
||||
g.set_page_type(b, Some("Idea")).unwrap();
|
||||
g.add_page_tag(b, "idea").unwrap();
|
||||
let cat = g.tag_catalog().unwrap();
|
||||
let get = |n: &str| cat.iter().find(|t| t.name.eq_ignore_ascii_case(n)).unwrap();
|
||||
let idea = get("idea");
|
||||
assert_eq!(
|
||||
(idea.count, idea.explicit, idea.typed, idea.from_hub),
|
||||
(2, 2, 1, 0)
|
||||
);
|
||||
let anime = get("anime");
|
||||
assert_eq!(
|
||||
(anime.count, anime.explicit, anime.typed, anime.from_hub),
|
||||
(1, 0, 0, 1)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn type_definitions_sync_last_writer_wins() {
|
||||
let (_a, a) = graph();
|
||||
let (_b, b) = graph();
|
||||
a.set_type_icon("persona", Some("🧑")).unwrap();
|
||||
a.create_type("Libro").unwrap();
|
||||
assert_eq!(ship(&a, &a, 0), 0, "own ops are not re-applied");
|
||||
ship(&a, &b, 0);
|
||||
assert_eq!(type_row(&b, "persona").unwrap().2.as_deref(), Some("🧑"));
|
||||
assert_eq!(type_row(&b, "libro"), Some(("Libro".into(), 0, None)));
|
||||
let (seq_a, seq_b) = (a.last_seq().unwrap(), b.last_seq().unwrap());
|
||||
// Concurrent edits: both replicas end with the same icon.
|
||||
a.set_type_icon("persona", Some("👤")).unwrap();
|
||||
b.set_type_icon("persona", Some("🙋")).unwrap();
|
||||
ship(&a, &b, seq_a);
|
||||
ship(&b, &a, seq_b);
|
||||
assert_eq!(
|
||||
type_row(&a, "persona").unwrap().2,
|
||||
type_row(&b, "persona").unwrap().2
|
||||
);
|
||||
// Removal travels as a tombstone.
|
||||
let seq_a = a.last_seq().unwrap();
|
||||
a.remove_type("libro").unwrap();
|
||||
ship(&a, &b, seq_a);
|
||||
assert_eq!(type_row(&b, "libro"), None);
|
||||
// The op round-trips through JSON; missing fields default.
|
||||
for r in a.ops_since(0, 1000).unwrap() {
|
||||
let s = serde_json::to_string(&r.op).unwrap();
|
||||
assert_eq!(serde_json::from_str::<Op>(&s).unwrap(), r.op);
|
||||
}
|
||||
let op: Op =
|
||||
serde_json::from_value(json!({"type": "put_type_def", "def": {"name": "x"}})).unwrap();
|
||||
assert!(matches!(op, Op::PutTypeDef { def } if def.icon.is_none() && !def.removed));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn v7_databases_gain_type_definitions() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
{
|
||||
let g = Graph::open(dir.path()).unwrap();
|
||||
let p = page(&g, "A", &["x"]);
|
||||
g.set_page_type(p, Some("persona")).unwrap();
|
||||
g.conn().execute("DROP TABLE type_defs", []).unwrap();
|
||||
g.conn()
|
||||
.execute("UPDATE meta SET value='7' WHERE key='schema'", [])
|
||||
.unwrap();
|
||||
}
|
||||
let g = Graph::open(dir.path()).unwrap();
|
||||
let schema: String = g
|
||||
.conn()
|
||||
.query_row("SELECT value FROM meta WHERE key='schema'", [], |r| {
|
||||
r.get(0)
|
||||
})
|
||||
.unwrap();
|
||||
assert_eq!(schema, "8");
|
||||
assert_eq!(type_row(&g, "persona"), Some(("persona".into(), 1, None)));
|
||||
g.set_type_icon("persona", Some("🧑")).unwrap();
|
||||
assert_eq!(type_row(&g, "persona").unwrap().2.as_deref(), Some("🧑"));
|
||||
}
|
||||
@@ -50,6 +50,28 @@ pub struct TagDto {
|
||||
pub count: u32,
|
||||
/// One of the seeded suggestions.
|
||||
pub suggested: bool,
|
||||
/// Emoji of a type (types only).
|
||||
pub icon: Option<String>,
|
||||
/// Pages listing it as an explicit tag (tags only).
|
||||
pub explicit: u32,
|
||||
/// Pages having it as their type (tags only).
|
||||
pub typed: u32,
|
||||
/// Pages carrying it through their hub (tags only; hub tags cannot be renamed or removed).
|
||||
pub from_hub: u32,
|
||||
}
|
||||
|
||||
impl From<synapse_core::TagInfo> for TagDto {
|
||||
fn from(t: synapse_core::TagInfo) -> Self {
|
||||
Self {
|
||||
name: t.name,
|
||||
count: t.count,
|
||||
suggested: t.suggested,
|
||||
icon: t.icon,
|
||||
explicit: t.explicit,
|
||||
typed: t.typed,
|
||||
from_hub: t.from_hub,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// One row of the outline, in pre-order.
|
||||
@@ -110,6 +132,8 @@ pub struct BacklinkGroup {
|
||||
pub page_id: String,
|
||||
pub page_title: String,
|
||||
pub is_journal: bool,
|
||||
/// Type of the referencing page (for its icon).
|
||||
pub page_type: Option<String>,
|
||||
pub blocks: Vec<BlockDto>,
|
||||
}
|
||||
|
||||
@@ -119,6 +143,8 @@ pub struct PageBrief {
|
||||
pub title: String,
|
||||
pub is_journal: bool,
|
||||
pub is_hub: bool,
|
||||
/// The page's type (the UI shows its icon next to the title).
|
||||
pub page_type: Option<String>,
|
||||
}
|
||||
|
||||
impl From<&Page> for PageBrief {
|
||||
@@ -128,6 +154,7 @@ impl From<&Page> for PageBrief {
|
||||
title: p.title.clone(),
|
||||
is_journal: p.is_journal(),
|
||||
is_hub: p.is_hub(),
|
||||
page_type: p.page_type().map(String::from),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -185,6 +212,8 @@ pub struct TitleHit {
|
||||
/// The matched title or alias.
|
||||
pub title: String,
|
||||
pub is_alias: bool,
|
||||
/// Type of the page (for its icon).
|
||||
pub page_type: Option<String>,
|
||||
}
|
||||
|
||||
/// A block matching a search (`((` autocomplete, quick switcher content results).
|
||||
@@ -240,6 +269,8 @@ pub struct GraphNode {
|
||||
/// A virtual tag node (not a page, no outline): `id` is `tag:<title_key>`, `title` the
|
||||
/// display name, `degree` the number of pages carrying the tag.
|
||||
pub is_tag: bool,
|
||||
/// The page's type (tree labels show its icon; the network view does not).
|
||||
pub page_type: Option<String>,
|
||||
}
|
||||
|
||||
/// The whole page-level graph, edges as parallel arrays (cheap to move across the FFI).
|
||||
|
||||
@@ -209,15 +209,23 @@ impl SynapseGraph {
|
||||
if !seen.insert(bl.block.id) {
|
||||
continue;
|
||||
}
|
||||
let i = *index.entry(bl.block.page_id).or_insert_with(|| {
|
||||
groups.push(BacklinkGroup {
|
||||
page_id: bl.block.page_id.to_string(),
|
||||
page_title: bl.page_title.clone(),
|
||||
is_journal: parse_day(&bl.page_title).is_some(),
|
||||
blocks: Vec::new(),
|
||||
});
|
||||
groups.len() - 1
|
||||
});
|
||||
let i = match index.get(&bl.block.page_id) {
|
||||
Some(&i) => i,
|
||||
None => {
|
||||
let page_type = g
|
||||
.get_page(bl.block.page_id)?
|
||||
.and_then(|p| p.page_type().map(String::from));
|
||||
groups.push(BacklinkGroup {
|
||||
page_id: bl.block.page_id.to_string(),
|
||||
page_title: bl.page_title.clone(),
|
||||
is_journal: parse_day(&bl.page_title).is_some(),
|
||||
page_type,
|
||||
blocks: Vec::new(),
|
||||
});
|
||||
index.insert(bl.block.page_id, groups.len() - 1);
|
||||
groups.len() - 1
|
||||
}
|
||||
};
|
||||
groups[i].blocks.push(BlockDto::new(0, &bl.block, false));
|
||||
}
|
||||
Ok(groups)
|
||||
|
||||
@@ -83,6 +83,11 @@ pub(crate) fn build(g: &Graph, seq: i64) -> Result<GraphData> {
|
||||
.into_iter()
|
||||
.map(|(id, t)| (id.to_string(), t))
|
||||
.collect();
|
||||
let mut page_types: HashMap<String, String> = g
|
||||
.all_page_types()?
|
||||
.into_iter()
|
||||
.map(|(id, t)| (id.to_string(), t))
|
||||
.collect();
|
||||
{
|
||||
let mut st = conn.prepare(
|
||||
"SELECT id, title, journal_date, origin_journal, created_at FROM pages
|
||||
@@ -100,6 +105,7 @@ pub(crate) fn build(g: &Graph, seq: i64) -> Result<GraphData> {
|
||||
})?;
|
||||
for row in rows {
|
||||
let (id, title, journal_date, origin_journal, created_at) = row?;
|
||||
let page_type = page_types.remove(&id);
|
||||
let tags = page_tags.get(&id).cloned().unwrap_or_default();
|
||||
index.insert(id.clone(), nodes.len() as u32);
|
||||
nodes.push(GraphNode {
|
||||
@@ -116,6 +122,7 @@ pub(crate) fn build(g: &Graph, seq: i64) -> Result<GraphData> {
|
||||
home_hub: None,
|
||||
tags,
|
||||
is_tag: false,
|
||||
page_type,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -328,6 +335,7 @@ fn tagged(
|
||||
home_hub: None,
|
||||
tags: Vec::new(),
|
||||
is_tag: true,
|
||||
page_type: None,
|
||||
});
|
||||
nodes.len() as u32 - 1
|
||||
});
|
||||
|
||||
@@ -23,6 +23,7 @@ impl SynapseGraph {
|
||||
page_id: p.id.to_string(),
|
||||
title: p.title.clone(),
|
||||
is_alias: false,
|
||||
page_type: p.page_type().map(String::from),
|
||||
})
|
||||
.collect());
|
||||
}
|
||||
@@ -52,13 +53,15 @@ impl SynapseGraph {
|
||||
hits.truncate(limit as usize);
|
||||
let mut out = Vec::with_capacity(hits.len());
|
||||
for (_, _, title, id) in hits {
|
||||
let is_alias = g
|
||||
.get_page(id)?
|
||||
let page = g.get_page(id)?;
|
||||
let is_alias = page
|
||||
.as_ref()
|
||||
.is_some_and(|p| title_key(&p.title) != title_key(&title));
|
||||
out.push(TitleHit {
|
||||
page_id: id.to_string(),
|
||||
title,
|
||||
is_alias,
|
||||
page_type: page.and_then(|p| p.page_type().map(String::from)),
|
||||
});
|
||||
}
|
||||
Ok(out)
|
||||
|
||||
@@ -42,11 +42,7 @@ impl SynapseGraph {
|
||||
.lock()
|
||||
.tag_catalog()?
|
||||
.into_iter()
|
||||
.map(|t| TagDto {
|
||||
name: t.name,
|
||||
count: t.count,
|
||||
suggested: t.suggested,
|
||||
})
|
||||
.map(TagDto::from)
|
||||
.collect())
|
||||
}
|
||||
|
||||
@@ -72,17 +68,34 @@ impl SynapseGraph {
|
||||
)?))
|
||||
}
|
||||
|
||||
/// Types in use (most used first) followed by the seeded suggestions not used yet.
|
||||
/// Adds a type to the vocabulary even if no page uses it; returns its spelling.
|
||||
pub fn create_type(&self, name: String) -> Result<String> {
|
||||
Ok(self.lock().create_type(&name)?)
|
||||
}
|
||||
|
||||
/// Sets (or with `None` clears) the emoji of a type, defining the type if needed.
|
||||
pub fn set_type_icon(&self, name: String, icon: Option<String>) -> Result<()> {
|
||||
Ok(self.lock().set_type_icon(&name, icon.as_deref())?)
|
||||
}
|
||||
|
||||
/// Renames a type (and same-name tags), keeping its icon; returns the pages changed.
|
||||
pub fn rename_type(&self, old: String, new: String) -> Result<u32> {
|
||||
Ok(self.lock().rename_type(&old, &new)? as u32)
|
||||
}
|
||||
|
||||
/// Deletes a type: its pages lose it and its icon is dropped; returns the pages changed.
|
||||
pub fn remove_type(&self, name: String) -> Result<u32> {
|
||||
Ok(self.lock().remove_type(&name)? as u32)
|
||||
}
|
||||
|
||||
/// Types in use (most used first), then defined unused types, then the seeded suggestions
|
||||
/// not used yet; each with its icon.
|
||||
pub fn type_catalog(&self) -> Result<Vec<TagDto>> {
|
||||
Ok(self
|
||||
.lock()
|
||||
.type_catalog()?
|
||||
.into_iter()
|
||||
.map(|t| TagDto {
|
||||
name: t.name,
|
||||
count: t.count,
|
||||
suggested: t.suggested,
|
||||
})
|
||||
.map(TagDto::from)
|
||||
.collect())
|
||||
}
|
||||
}
|
||||
@@ -41,7 +41,7 @@ flutter_rust_bridge::frb_generated_boilerplate!(
|
||||
default_rust_auto_opaque = RustAutoOpaqueMoi,
|
||||
);
|
||||
pub(crate) const FLUTTER_RUST_BRIDGE_CODEGEN_VERSION: &str = "2.13.0";
|
||||
pub(crate) const FLUTTER_RUST_BRIDGE_CODEGEN_CONTENT_HASH: i32 = -1472342481;
|
||||
pub(crate) const FLUTTER_RUST_BRIDGE_CODEGEN_CONTENT_HASH: i32 = 272705018;
|
||||
|
||||
// Section: executor
|
||||
|
||||
@@ -921,6 +921,61 @@ fn wire__crate__api__graph__SynapseGraph_create_page_from_template_impl(
|
||||
},
|
||||
)
|
||||
}
|
||||
fn wire__crate__api__graph__SynapseGraph_create_type_impl(
|
||||
port_: flutter_rust_bridge::for_generated::MessagePort,
|
||||
ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr,
|
||||
rust_vec_len_: i32,
|
||||
data_len_: i32,
|
||||
) {
|
||||
FLUTTER_RUST_BRIDGE_HANDLER.wrap_normal::<flutter_rust_bridge::for_generated::SseCodec, _, _>(
|
||||
flutter_rust_bridge::for_generated::TaskInfo {
|
||||
debug_name: "SynapseGraph_create_type",
|
||||
port: Some(port_),
|
||||
mode: flutter_rust_bridge::for_generated::FfiCallMode::Normal,
|
||||
},
|
||||
move || {
|
||||
let message = unsafe {
|
||||
flutter_rust_bridge::for_generated::Dart2RustMessageSse::from_wire(
|
||||
ptr_,
|
||||
rust_vec_len_,
|
||||
data_len_,
|
||||
)
|
||||
};
|
||||
let mut deserializer =
|
||||
flutter_rust_bridge::for_generated::SseDeserializer::new(message);
|
||||
let api_that = <RustOpaqueMoi<
|
||||
flutter_rust_bridge::for_generated::RustAutoOpaqueInner<SynapseGraph>,
|
||||
>>::sse_decode(&mut deserializer);
|
||||
let api_name = <String>::sse_decode(&mut deserializer);
|
||||
deserializer.end();
|
||||
move |context| {
|
||||
transform_result_sse::<_, flutter_rust_bridge::for_generated::anyhow::Error>(
|
||||
(move || {
|
||||
let mut api_that_guard = None;
|
||||
let decode_indices_ =
|
||||
flutter_rust_bridge::for_generated::lockable_compute_decode_order(
|
||||
vec![flutter_rust_bridge::for_generated::LockableOrderInfo::new(
|
||||
&api_that, 0, false,
|
||||
)],
|
||||
);
|
||||
for i in decode_indices_ {
|
||||
match i {
|
||||
0 => api_that_guard = Some(api_that.lockable_decode_sync_ref()),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
let api_that_guard = api_that_guard.unwrap();
|
||||
let output_ok = crate::api::graph::SynapseGraph::create_type(
|
||||
&*api_that_guard,
|
||||
api_name,
|
||||
)?;
|
||||
std::result::Result::Ok(output_ok)
|
||||
})(),
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
fn wire__crate__api__graph__SynapseGraph_delete_block_impl(
|
||||
port_: flutter_rust_bridge::for_generated::MessagePort,
|
||||
ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr,
|
||||
@@ -2722,6 +2777,61 @@ fn wire__crate__api__graph__SynapseGraph_remove_tag_impl(
|
||||
},
|
||||
)
|
||||
}
|
||||
fn wire__crate__api__graph__SynapseGraph_remove_type_impl(
|
||||
port_: flutter_rust_bridge::for_generated::MessagePort,
|
||||
ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr,
|
||||
rust_vec_len_: i32,
|
||||
data_len_: i32,
|
||||
) {
|
||||
FLUTTER_RUST_BRIDGE_HANDLER.wrap_normal::<flutter_rust_bridge::for_generated::SseCodec, _, _>(
|
||||
flutter_rust_bridge::for_generated::TaskInfo {
|
||||
debug_name: "SynapseGraph_remove_type",
|
||||
port: Some(port_),
|
||||
mode: flutter_rust_bridge::for_generated::FfiCallMode::Normal,
|
||||
},
|
||||
move || {
|
||||
let message = unsafe {
|
||||
flutter_rust_bridge::for_generated::Dart2RustMessageSse::from_wire(
|
||||
ptr_,
|
||||
rust_vec_len_,
|
||||
data_len_,
|
||||
)
|
||||
};
|
||||
let mut deserializer =
|
||||
flutter_rust_bridge::for_generated::SseDeserializer::new(message);
|
||||
let api_that = <RustOpaqueMoi<
|
||||
flutter_rust_bridge::for_generated::RustAutoOpaqueInner<SynapseGraph>,
|
||||
>>::sse_decode(&mut deserializer);
|
||||
let api_name = <String>::sse_decode(&mut deserializer);
|
||||
deserializer.end();
|
||||
move |context| {
|
||||
transform_result_sse::<_, flutter_rust_bridge::for_generated::anyhow::Error>(
|
||||
(move || {
|
||||
let mut api_that_guard = None;
|
||||
let decode_indices_ =
|
||||
flutter_rust_bridge::for_generated::lockable_compute_decode_order(
|
||||
vec![flutter_rust_bridge::for_generated::LockableOrderInfo::new(
|
||||
&api_that, 0, false,
|
||||
)],
|
||||
);
|
||||
for i in decode_indices_ {
|
||||
match i {
|
||||
0 => api_that_guard = Some(api_that.lockable_decode_sync_ref()),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
let api_that_guard = api_that_guard.unwrap();
|
||||
let output_ok = crate::api::graph::SynapseGraph::remove_type(
|
||||
&*api_that_guard,
|
||||
api_name,
|
||||
)?;
|
||||
std::result::Result::Ok(output_ok)
|
||||
})(),
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
fn wire__crate__api__graph__SynapseGraph_rename_page_impl(
|
||||
port_: flutter_rust_bridge::for_generated::MessagePort,
|
||||
ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr,
|
||||
@@ -2836,6 +2946,63 @@ fn wire__crate__api__graph__SynapseGraph_rename_tag_impl(
|
||||
},
|
||||
)
|
||||
}
|
||||
fn wire__crate__api__graph__SynapseGraph_rename_type_impl(
|
||||
port_: flutter_rust_bridge::for_generated::MessagePort,
|
||||
ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr,
|
||||
rust_vec_len_: i32,
|
||||
data_len_: i32,
|
||||
) {
|
||||
FLUTTER_RUST_BRIDGE_HANDLER.wrap_normal::<flutter_rust_bridge::for_generated::SseCodec, _, _>(
|
||||
flutter_rust_bridge::for_generated::TaskInfo {
|
||||
debug_name: "SynapseGraph_rename_type",
|
||||
port: Some(port_),
|
||||
mode: flutter_rust_bridge::for_generated::FfiCallMode::Normal,
|
||||
},
|
||||
move || {
|
||||
let message = unsafe {
|
||||
flutter_rust_bridge::for_generated::Dart2RustMessageSse::from_wire(
|
||||
ptr_,
|
||||
rust_vec_len_,
|
||||
data_len_,
|
||||
)
|
||||
};
|
||||
let mut deserializer =
|
||||
flutter_rust_bridge::for_generated::SseDeserializer::new(message);
|
||||
let api_that = <RustOpaqueMoi<
|
||||
flutter_rust_bridge::for_generated::RustAutoOpaqueInner<SynapseGraph>,
|
||||
>>::sse_decode(&mut deserializer);
|
||||
let api_old = <String>::sse_decode(&mut deserializer);
|
||||
let api_new = <String>::sse_decode(&mut deserializer);
|
||||
deserializer.end();
|
||||
move |context| {
|
||||
transform_result_sse::<_, flutter_rust_bridge::for_generated::anyhow::Error>(
|
||||
(move || {
|
||||
let mut api_that_guard = None;
|
||||
let decode_indices_ =
|
||||
flutter_rust_bridge::for_generated::lockable_compute_decode_order(
|
||||
vec![flutter_rust_bridge::for_generated::LockableOrderInfo::new(
|
||||
&api_that, 0, false,
|
||||
)],
|
||||
);
|
||||
for i in decode_indices_ {
|
||||
match i {
|
||||
0 => api_that_guard = Some(api_that.lockable_decode_sync_ref()),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
let api_that_guard = api_that_guard.unwrap();
|
||||
let output_ok = crate::api::graph::SynapseGraph::rename_type(
|
||||
&*api_that_guard,
|
||||
api_old,
|
||||
api_new,
|
||||
)?;
|
||||
std::result::Result::Ok(output_ok)
|
||||
})(),
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
fn wire__crate__api__graph__SynapseGraph_search_blocks_impl(
|
||||
port_: flutter_rust_bridge::for_generated::MessagePort,
|
||||
ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr,
|
||||
@@ -3178,6 +3345,63 @@ fn wire__crate__api__graph__SynapseGraph_set_page_type_impl(
|
||||
},
|
||||
)
|
||||
}
|
||||
fn wire__crate__api__graph__SynapseGraph_set_type_icon_impl(
|
||||
port_: flutter_rust_bridge::for_generated::MessagePort,
|
||||
ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr,
|
||||
rust_vec_len_: i32,
|
||||
data_len_: i32,
|
||||
) {
|
||||
FLUTTER_RUST_BRIDGE_HANDLER.wrap_normal::<flutter_rust_bridge::for_generated::SseCodec, _, _>(
|
||||
flutter_rust_bridge::for_generated::TaskInfo {
|
||||
debug_name: "SynapseGraph_set_type_icon",
|
||||
port: Some(port_),
|
||||
mode: flutter_rust_bridge::for_generated::FfiCallMode::Normal,
|
||||
},
|
||||
move || {
|
||||
let message = unsafe {
|
||||
flutter_rust_bridge::for_generated::Dart2RustMessageSse::from_wire(
|
||||
ptr_,
|
||||
rust_vec_len_,
|
||||
data_len_,
|
||||
)
|
||||
};
|
||||
let mut deserializer =
|
||||
flutter_rust_bridge::for_generated::SseDeserializer::new(message);
|
||||
let api_that = <RustOpaqueMoi<
|
||||
flutter_rust_bridge::for_generated::RustAutoOpaqueInner<SynapseGraph>,
|
||||
>>::sse_decode(&mut deserializer);
|
||||
let api_name = <String>::sse_decode(&mut deserializer);
|
||||
let api_icon = <Option<String>>::sse_decode(&mut deserializer);
|
||||
deserializer.end();
|
||||
move |context| {
|
||||
transform_result_sse::<_, flutter_rust_bridge::for_generated::anyhow::Error>(
|
||||
(move || {
|
||||
let mut api_that_guard = None;
|
||||
let decode_indices_ =
|
||||
flutter_rust_bridge::for_generated::lockable_compute_decode_order(
|
||||
vec![flutter_rust_bridge::for_generated::LockableOrderInfo::new(
|
||||
&api_that, 0, false,
|
||||
)],
|
||||
);
|
||||
for i in decode_indices_ {
|
||||
match i {
|
||||
0 => api_that_guard = Some(api_that.lockable_decode_sync_ref()),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
let api_that_guard = api_that_guard.unwrap();
|
||||
let output_ok = crate::api::graph::SynapseGraph::set_type_icon(
|
||||
&*api_that_guard,
|
||||
api_name,
|
||||
api_icon,
|
||||
)?;
|
||||
std::result::Result::Ok(output_ok)
|
||||
})(),
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
fn wire__crate__api__graph__SynapseGraph_tag_catalog_impl(
|
||||
port_: flutter_rust_bridge::for_generated::MessagePort,
|
||||
ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr,
|
||||
@@ -3533,11 +3757,13 @@ impl SseDecode for crate::api::dto::BacklinkGroup {
|
||||
let mut var_pageId = <String>::sse_decode(deserializer);
|
||||
let mut var_pageTitle = <String>::sse_decode(deserializer);
|
||||
let mut var_isJournal = <bool>::sse_decode(deserializer);
|
||||
let mut var_pageType = <Option<String>>::sse_decode(deserializer);
|
||||
let mut var_blocks = <Vec<crate::api::dto::BlockDto>>::sse_decode(deserializer);
|
||||
return crate::api::dto::BacklinkGroup {
|
||||
page_id: var_pageId,
|
||||
page_title: var_pageTitle,
|
||||
is_journal: var_isJournal,
|
||||
page_type: var_pageType,
|
||||
blocks: var_blocks,
|
||||
};
|
||||
}
|
||||
@@ -3657,6 +3883,7 @@ impl SseDecode for crate::api::dto::GraphNode {
|
||||
let mut var_homeHub = <Option<u32>>::sse_decode(deserializer);
|
||||
let mut var_tags = <Vec<String>>::sse_decode(deserializer);
|
||||
let mut var_isTag = <bool>::sse_decode(deserializer);
|
||||
let mut var_pageType = <Option<String>>::sse_decode(deserializer);
|
||||
return crate::api::dto::GraphNode {
|
||||
id: var_id,
|
||||
title: var_title,
|
||||
@@ -3671,6 +3898,7 @@ impl SseDecode for crate::api::dto::GraphNode {
|
||||
home_hub: var_homeHub,
|
||||
tags: var_tags,
|
||||
is_tag: var_isTag,
|
||||
page_type: var_pageType,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -4073,11 +4301,13 @@ impl SseDecode for crate::api::dto::PageBrief {
|
||||
let mut var_title = <String>::sse_decode(deserializer);
|
||||
let mut var_isJournal = <bool>::sse_decode(deserializer);
|
||||
let mut var_isHub = <bool>::sse_decode(deserializer);
|
||||
let mut var_pageType = <Option<String>>::sse_decode(deserializer);
|
||||
return crate::api::dto::PageBrief {
|
||||
id: var_id,
|
||||
title: var_title,
|
||||
is_journal: var_isJournal,
|
||||
is_hub: var_isHub,
|
||||
page_type: var_pageType,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -4201,10 +4431,18 @@ impl SseDecode for crate::api::dto::TagDto {
|
||||
let mut var_name = <String>::sse_decode(deserializer);
|
||||
let mut var_count = <u32>::sse_decode(deserializer);
|
||||
let mut var_suggested = <bool>::sse_decode(deserializer);
|
||||
let mut var_icon = <Option<String>>::sse_decode(deserializer);
|
||||
let mut var_explicit = <u32>::sse_decode(deserializer);
|
||||
let mut var_typed = <u32>::sse_decode(deserializer);
|
||||
let mut var_fromHub = <u32>::sse_decode(deserializer);
|
||||
return crate::api::dto::TagDto {
|
||||
name: var_name,
|
||||
count: var_count,
|
||||
suggested: var_suggested,
|
||||
icon: var_icon,
|
||||
explicit: var_explicit,
|
||||
typed: var_typed,
|
||||
from_hub: var_fromHub,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -4243,10 +4481,12 @@ impl SseDecode for crate::api::dto::TitleHit {
|
||||
let mut var_pageId = <String>::sse_decode(deserializer);
|
||||
let mut var_title = <String>::sse_decode(deserializer);
|
||||
let mut var_isAlias = <bool>::sse_decode(deserializer);
|
||||
let mut var_pageType = <Option<String>>::sse_decode(deserializer);
|
||||
return crate::api::dto::TitleHit {
|
||||
page_id: var_pageId,
|
||||
title: var_title,
|
||||
is_alias: var_isAlias,
|
||||
page_type: var_pageType,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -4337,211 +4577,235 @@ fn pde_ffi_dispatcher_primary_impl(
|
||||
rust_vec_len,
|
||||
data_len,
|
||||
),
|
||||
17 => wire__crate__api__graph__SynapseGraph_delete_block_impl(
|
||||
17 => wire__crate__api__graph__SynapseGraph_create_type_impl(
|
||||
port,
|
||||
ptr,
|
||||
rust_vec_len,
|
||||
data_len,
|
||||
),
|
||||
18 => wire__crate__api__graph__SynapseGraph_delete_page_impl(
|
||||
18 => wire__crate__api__graph__SynapseGraph_delete_block_impl(
|
||||
port,
|
||||
ptr,
|
||||
rust_vec_len,
|
||||
data_len,
|
||||
),
|
||||
20 => {
|
||||
19 => wire__crate__api__graph__SynapseGraph_delete_page_impl(
|
||||
port,
|
||||
ptr,
|
||||
rust_vec_len,
|
||||
data_len,
|
||||
),
|
||||
21 => {
|
||||
wire__crate__api__graph__SynapseGraph_graph_data_impl(port, ptr, rust_vec_len, data_len)
|
||||
}
|
||||
21 => wire__crate__api__graph__SynapseGraph_hub_conversion_preview_impl(
|
||||
22 => wire__crate__api__graph__SynapseGraph_hub_conversion_preview_impl(
|
||||
port,
|
||||
ptr,
|
||||
rust_vec_len,
|
||||
data_len,
|
||||
),
|
||||
22 => wire__crate__api__graph__SynapseGraph_hub_template_impl(
|
||||
23 => wire__crate__api__graph__SynapseGraph_hub_template_impl(
|
||||
port,
|
||||
ptr,
|
||||
rust_vec_len,
|
||||
data_len,
|
||||
),
|
||||
23 => wire__crate__api__graph__SynapseGraph_hubs_impl(port, ptr, rust_vec_len, data_len),
|
||||
24 => wire__crate__api__graph__SynapseGraph_indent_block_impl(
|
||||
24 => wire__crate__api__graph__SynapseGraph_hubs_impl(port, ptr, rust_vec_len, data_len),
|
||||
25 => wire__crate__api__graph__SynapseGraph_indent_block_impl(
|
||||
port,
|
||||
ptr,
|
||||
rust_vec_len,
|
||||
data_len,
|
||||
),
|
||||
25 => wire__crate__api__graph__SynapseGraph_insert_block_impl(
|
||||
26 => wire__crate__api__graph__SynapseGraph_insert_block_impl(
|
||||
port,
|
||||
ptr,
|
||||
rust_vec_len,
|
||||
data_len,
|
||||
),
|
||||
26 => wire__crate__api__graph__SynapseGraph_journal_impl(port, ptr, rust_vec_len, data_len),
|
||||
27 => wire__crate__api__graph__SynapseGraph_journal_neighbors_impl(
|
||||
27 => wire__crate__api__graph__SynapseGraph_journal_impl(port, ptr, rust_vec_len, data_len),
|
||||
28 => wire__crate__api__graph__SynapseGraph_journal_neighbors_impl(
|
||||
port,
|
||||
ptr,
|
||||
rust_vec_len,
|
||||
data_len,
|
||||
),
|
||||
28 => {
|
||||
29 => {
|
||||
wire__crate__api__graph__SynapseGraph_journals_impl(port, ptr, rust_vec_len, data_len)
|
||||
}
|
||||
29 => wire__crate__api__graph__SynapseGraph_legacy_candidates_impl(
|
||||
30 => wire__crate__api__graph__SynapseGraph_legacy_candidates_impl(
|
||||
port,
|
||||
ptr,
|
||||
rust_vec_len,
|
||||
data_len,
|
||||
),
|
||||
30 => {
|
||||
31 => {
|
||||
wire__crate__api__graph__SynapseGraph_list_pages_impl(port, ptr, rust_vec_len, data_len)
|
||||
}
|
||||
31 => wire__crate__api__graph__SynapseGraph_merge_block_impl(
|
||||
32 => wire__crate__api__graph__SynapseGraph_merge_block_impl(
|
||||
port,
|
||||
ptr,
|
||||
rust_vec_len,
|
||||
data_len,
|
||||
),
|
||||
32 => {
|
||||
33 => {
|
||||
wire__crate__api__graph__SynapseGraph_move_block_impl(port, ptr, rust_vec_len, data_len)
|
||||
}
|
||||
33 => wire__crate__api__graph__SynapseGraph_open_impl(port, ptr, rust_vec_len, data_len),
|
||||
34 => {
|
||||
34 => wire__crate__api__graph__SynapseGraph_open_impl(port, ptr, rust_vec_len, data_len),
|
||||
35 => {
|
||||
wire__crate__api__graph__SynapseGraph_open_page_impl(port, ptr, rust_vec_len, data_len)
|
||||
}
|
||||
35 => wire__crate__api__graph__SynapseGraph_outdent_block_impl(
|
||||
36 => wire__crate__api__graph__SynapseGraph_outdent_block_impl(
|
||||
port,
|
||||
ptr,
|
||||
rust_vec_len,
|
||||
data_len,
|
||||
),
|
||||
36 => wire__crate__api__graph__SynapseGraph_outline_impl(port, ptr, rust_vec_len, data_len),
|
||||
37 => wire__crate__api__graph__SynapseGraph_page_impl(port, ptr, rust_vec_len, data_len),
|
||||
38 => wire__crate__api__graph__SynapseGraph_page_by_title_impl(
|
||||
37 => wire__crate__api__graph__SynapseGraph_outline_impl(port, ptr, rust_vec_len, data_len),
|
||||
38 => wire__crate__api__graph__SynapseGraph_page_impl(port, ptr, rust_vec_len, data_len),
|
||||
39 => wire__crate__api__graph__SynapseGraph_page_by_title_impl(
|
||||
port,
|
||||
ptr,
|
||||
rust_vec_len,
|
||||
data_len,
|
||||
),
|
||||
39 => wire__crate__api__graph__SynapseGraph_page_structure_impl(
|
||||
40 => wire__crate__api__graph__SynapseGraph_page_structure_impl(
|
||||
port,
|
||||
ptr,
|
||||
rust_vec_len,
|
||||
data_len,
|
||||
),
|
||||
40 => wire__crate__api__graph__SynapseGraph_pages_with_tag_impl(
|
||||
41 => wire__crate__api__graph__SynapseGraph_pages_with_tag_impl(
|
||||
port,
|
||||
ptr,
|
||||
rust_vec_len,
|
||||
data_len,
|
||||
),
|
||||
41 => wire__crate__api__graph__SynapseGraph_purge_pages_impl(
|
||||
42 => wire__crate__api__graph__SynapseGraph_purge_pages_impl(
|
||||
port,
|
||||
ptr,
|
||||
rust_vec_len,
|
||||
data_len,
|
||||
),
|
||||
42 => wire__crate__api__graph__SynapseGraph_put_asset_bytes_impl(
|
||||
43 => wire__crate__api__graph__SynapseGraph_put_asset_bytes_impl(
|
||||
port,
|
||||
ptr,
|
||||
rust_vec_len,
|
||||
data_len,
|
||||
),
|
||||
43 => wire__crate__api__graph__SynapseGraph_put_asset_file_impl(
|
||||
44 => wire__crate__api__graph__SynapseGraph_put_asset_file_impl(
|
||||
port,
|
||||
ptr,
|
||||
rust_vec_len,
|
||||
data_len,
|
||||
),
|
||||
44 => wire__crate__api__graph__SynapseGraph_record_visit_impl(
|
||||
45 => wire__crate__api__graph__SynapseGraph_record_visit_impl(
|
||||
port,
|
||||
ptr,
|
||||
rust_vec_len,
|
||||
data_len,
|
||||
),
|
||||
45 => wire__crate__api__graph__SynapseGraph_related_impl(port, ptr, rust_vec_len, data_len),
|
||||
46 => wire__crate__api__graph__SynapseGraph_remove_alias_impl(
|
||||
46 => wire__crate__api__graph__SynapseGraph_related_impl(port, ptr, rust_vec_len, data_len),
|
||||
47 => wire__crate__api__graph__SynapseGraph_remove_alias_impl(
|
||||
port,
|
||||
ptr,
|
||||
rust_vec_len,
|
||||
data_len,
|
||||
),
|
||||
47 => wire__crate__api__graph__SynapseGraph_remove_from_hub_impl(
|
||||
48 => wire__crate__api__graph__SynapseGraph_remove_from_hub_impl(
|
||||
port,
|
||||
ptr,
|
||||
rust_vec_len,
|
||||
data_len,
|
||||
),
|
||||
48 => wire__crate__api__graph__SynapseGraph_remove_page_tag_impl(
|
||||
49 => wire__crate__api__graph__SynapseGraph_remove_page_tag_impl(
|
||||
port,
|
||||
ptr,
|
||||
rust_vec_len,
|
||||
data_len,
|
||||
),
|
||||
49 => {
|
||||
50 => {
|
||||
wire__crate__api__graph__SynapseGraph_remove_tag_impl(port, ptr, rust_vec_len, data_len)
|
||||
}
|
||||
50 => wire__crate__api__graph__SynapseGraph_rename_page_impl(
|
||||
51 => wire__crate__api__graph__SynapseGraph_remove_type_impl(
|
||||
port,
|
||||
ptr,
|
||||
rust_vec_len,
|
||||
data_len,
|
||||
),
|
||||
51 => {
|
||||
52 => wire__crate__api__graph__SynapseGraph_rename_page_impl(
|
||||
port,
|
||||
ptr,
|
||||
rust_vec_len,
|
||||
data_len,
|
||||
),
|
||||
53 => {
|
||||
wire__crate__api__graph__SynapseGraph_rename_tag_impl(port, ptr, rust_vec_len, data_len)
|
||||
}
|
||||
52 => wire__crate__api__graph__SynapseGraph_search_blocks_impl(
|
||||
54 => wire__crate__api__graph__SynapseGraph_rename_type_impl(
|
||||
port,
|
||||
ptr,
|
||||
rust_vec_len,
|
||||
data_len,
|
||||
),
|
||||
53 => wire__crate__api__graph__SynapseGraph_search_titles_impl(
|
||||
55 => wire__crate__api__graph__SynapseGraph_search_blocks_impl(
|
||||
port,
|
||||
ptr,
|
||||
rust_vec_len,
|
||||
data_len,
|
||||
),
|
||||
54 => wire__crate__api__graph__SynapseGraph_set_collapsed_impl(
|
||||
56 => wire__crate__api__graph__SynapseGraph_search_titles_impl(
|
||||
port,
|
||||
ptr,
|
||||
rust_vec_len,
|
||||
data_len,
|
||||
),
|
||||
55 => wire__crate__api__graph__SynapseGraph_set_hub_description_impl(
|
||||
57 => wire__crate__api__graph__SynapseGraph_set_collapsed_impl(
|
||||
port,
|
||||
ptr,
|
||||
rust_vec_len,
|
||||
data_len,
|
||||
),
|
||||
56 => wire__crate__api__graph__SynapseGraph_set_page_tags_impl(
|
||||
58 => wire__crate__api__graph__SynapseGraph_set_hub_description_impl(
|
||||
port,
|
||||
ptr,
|
||||
rust_vec_len,
|
||||
data_len,
|
||||
),
|
||||
57 => wire__crate__api__graph__SynapseGraph_set_page_type_impl(
|
||||
59 => wire__crate__api__graph__SynapseGraph_set_page_tags_impl(
|
||||
port,
|
||||
ptr,
|
||||
rust_vec_len,
|
||||
data_len,
|
||||
),
|
||||
58 => wire__crate__api__graph__SynapseGraph_tag_catalog_impl(
|
||||
60 => wire__crate__api__graph__SynapseGraph_set_page_type_impl(
|
||||
port,
|
||||
ptr,
|
||||
rust_vec_len,
|
||||
data_len,
|
||||
),
|
||||
59 => {
|
||||
61 => wire__crate__api__graph__SynapseGraph_set_type_icon_impl(
|
||||
port,
|
||||
ptr,
|
||||
rust_vec_len,
|
||||
data_len,
|
||||
),
|
||||
62 => wire__crate__api__graph__SynapseGraph_tag_catalog_impl(
|
||||
port,
|
||||
ptr,
|
||||
rust_vec_len,
|
||||
data_len,
|
||||
),
|
||||
63 => {
|
||||
wire__crate__api__graph__SynapseGraph_timeline_impl(port, ptr, rust_vec_len, data_len)
|
||||
}
|
||||
61 => wire__crate__api__graph__SynapseGraph_type_catalog_impl(
|
||||
65 => wire__crate__api__graph__SynapseGraph_type_catalog_impl(
|
||||
port,
|
||||
ptr,
|
||||
rust_vec_len,
|
||||
data_len,
|
||||
),
|
||||
62 => wire__crate__api__graph__SynapseGraph_update_block_impl(
|
||||
66 => wire__crate__api__graph__SynapseGraph_update_block_impl(
|
||||
port,
|
||||
ptr,
|
||||
rust_vec_len,
|
||||
@@ -4561,8 +4825,8 @@ fn pde_ffi_dispatcher_sync_impl(
|
||||
match func_id {
|
||||
1 => wire__crate__api__layout__ForceLayout_new_impl(ptr, rust_vec_len, data_len),
|
||||
10 => wire__crate__api__graph__SynapseGraph_asset_path_impl(ptr, rust_vec_len, data_len),
|
||||
19 => wire__crate__api__graph__SynapseGraph_dir_impl(ptr, rust_vec_len, data_len),
|
||||
60 => wire__crate__api__graph__SynapseGraph_today_impl(ptr, rust_vec_len, data_len),
|
||||
20 => wire__crate__api__graph__SynapseGraph_dir_impl(ptr, rust_vec_len, data_len),
|
||||
64 => wire__crate__api__graph__SynapseGraph_today_impl(ptr, rust_vec_len, data_len),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
@@ -4624,6 +4888,7 @@ impl flutter_rust_bridge::IntoDart for crate::api::dto::BacklinkGroup {
|
||||
self.page_id.into_into_dart().into_dart(),
|
||||
self.page_title.into_into_dart().into_dart(),
|
||||
self.is_journal.into_into_dart().into_dart(),
|
||||
self.page_type.into_into_dart().into_dart(),
|
||||
self.blocks.into_into_dart().into_dart(),
|
||||
]
|
||||
.into_dart()
|
||||
@@ -4751,6 +5016,7 @@ impl flutter_rust_bridge::IntoDart for crate::api::dto::GraphNode {
|
||||
self.home_hub.into_into_dart().into_dart(),
|
||||
self.tags.into_into_dart().into_dart(),
|
||||
self.is_tag.into_into_dart().into_dart(),
|
||||
self.page_type.into_into_dart().into_dart(),
|
||||
]
|
||||
.into_dart()
|
||||
}
|
||||
@@ -4893,6 +5159,7 @@ impl flutter_rust_bridge::IntoDart for crate::api::dto::PageBrief {
|
||||
self.title.into_into_dart().into_dart(),
|
||||
self.is_journal.into_into_dart().into_dart(),
|
||||
self.is_hub.into_into_dart().into_dart(),
|
||||
self.page_type.into_into_dart().into_dart(),
|
||||
]
|
||||
.into_dart()
|
||||
}
|
||||
@@ -5030,6 +5297,10 @@ impl flutter_rust_bridge::IntoDart for crate::api::dto::TagDto {
|
||||
self.name.into_into_dart().into_dart(),
|
||||
self.count.into_into_dart().into_dart(),
|
||||
self.suggested.into_into_dart().into_dart(),
|
||||
self.icon.into_into_dart().into_dart(),
|
||||
self.explicit.into_into_dart().into_dart(),
|
||||
self.typed.into_into_dart().into_dart(),
|
||||
self.from_hub.into_into_dart().into_dart(),
|
||||
]
|
||||
.into_dart()
|
||||
}
|
||||
@@ -5088,6 +5359,7 @@ impl flutter_rust_bridge::IntoDart for crate::api::dto::TitleHit {
|
||||
self.page_id.into_into_dart().into_dart(),
|
||||
self.title.into_into_dart().into_dart(),
|
||||
self.is_alias.into_into_dart().into_dart(),
|
||||
self.page_type.into_into_dart().into_dart(),
|
||||
]
|
||||
.into_dart()
|
||||
}
|
||||
@@ -5165,6 +5437,7 @@ impl SseEncode for crate::api::dto::BacklinkGroup {
|
||||
<String>::sse_encode(self.page_id, serializer);
|
||||
<String>::sse_encode(self.page_title, serializer);
|
||||
<bool>::sse_encode(self.is_journal, serializer);
|
||||
<Option<String>>::sse_encode(self.page_type, serializer);
|
||||
<Vec<crate::api::dto::BlockDto>>::sse_encode(self.blocks, serializer);
|
||||
}
|
||||
}
|
||||
@@ -5251,6 +5524,7 @@ impl SseEncode for crate::api::dto::GraphNode {
|
||||
<Option<u32>>::sse_encode(self.home_hub, serializer);
|
||||
<Vec<String>>::sse_encode(self.tags, serializer);
|
||||
<bool>::sse_encode(self.is_tag, serializer);
|
||||
<Option<String>>::sse_encode(self.page_type, serializer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5574,6 +5848,7 @@ impl SseEncode for crate::api::dto::PageBrief {
|
||||
<String>::sse_encode(self.title, serializer);
|
||||
<bool>::sse_encode(self.is_journal, serializer);
|
||||
<bool>::sse_encode(self.is_hub, serializer);
|
||||
<Option<String>>::sse_encode(self.page_type, serializer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5664,6 +5939,10 @@ impl SseEncode for crate::api::dto::TagDto {
|
||||
<String>::sse_encode(self.name, serializer);
|
||||
<u32>::sse_encode(self.count, serializer);
|
||||
<bool>::sse_encode(self.suggested, serializer);
|
||||
<Option<String>>::sse_encode(self.icon, serializer);
|
||||
<u32>::sse_encode(self.explicit, serializer);
|
||||
<u32>::sse_encode(self.typed, serializer);
|
||||
<u32>::sse_encode(self.from_hub, serializer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5691,6 +5970,7 @@ impl SseEncode for crate::api::dto::TitleHit {
|
||||
<String>::sse_encode(self.page_id, serializer);
|
||||
<String>::sse_encode(self.title, serializer);
|
||||
<bool>::sse_encode(self.is_alias, serializer);
|
||||
<Option<String>>::sse_encode(self.page_type, serializer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -518,6 +518,52 @@ fn page_type_and_tag_renaming_round_trip_through_the_api() {
|
||||
assert!(g.set_page_type(a, None).unwrap().page_type.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn type_icons_and_page_types_reach_the_ui_dtos() {
|
||||
let (_d, g) = open();
|
||||
let (a, _) = page_with(&g, "Ana", &["x"]);
|
||||
let (b, _) = page_with(&g, "Notes", &["about [[Ana]]"]);
|
||||
g.set_page_type(a.clone(), Some("persona".into())).unwrap();
|
||||
g.set_page_type(b.clone(), Some("idea".into())).unwrap();
|
||||
g.set_type_icon("persona".into(), Some("🧑".into()))
|
||||
.unwrap();
|
||||
assert!(
|
||||
g.set_type_icon("persona".into(), Some("xy".into()))
|
||||
.is_err()
|
||||
);
|
||||
assert_eq!(g.create_type(" Libro ".into()).unwrap(), "Libro");
|
||||
let cat = g.type_catalog().unwrap();
|
||||
let persona = cat.iter().find(|t| t.name == "persona").unwrap();
|
||||
assert_eq!((persona.count, persona.icon.as_deref()), (1, Some("🧑")));
|
||||
assert!(cat.iter().any(|t| t.name == "Libro" && t.count == 0));
|
||||
assert!(cat.iter().any(|t| t.name == "sueño" && t.count == 0));
|
||||
|
||||
// Lists of pages carry the page type, so the UI can look up its icon.
|
||||
let hits = g.search_titles("Ana".into(), 5).unwrap();
|
||||
assert_eq!(hits[0].page_type.as_deref(), Some("persona"));
|
||||
let bl = g.backlinks(a.clone()).unwrap();
|
||||
assert_eq!(bl[0].page_type.as_deref(), Some("idea"));
|
||||
let briefs = g.pages_with_tag("persona".into()).unwrap();
|
||||
assert_eq!(briefs[0].page_type.as_deref(), Some("persona"));
|
||||
let data = g.graph_data().unwrap();
|
||||
let node = data.nodes.iter().find(|n| n.id == a).unwrap();
|
||||
assert_eq!(node.page_type.as_deref(), Some("persona"));
|
||||
|
||||
// Rename keeps the icon; remove drops the type from its pages.
|
||||
assert_eq!(g.rename_type("persona".into(), "Gente".into()).unwrap(), 1);
|
||||
let cat = g.type_catalog().unwrap();
|
||||
let gente = cat.iter().find(|t| t.name == "Gente").unwrap();
|
||||
assert_eq!(gente.icon.as_deref(), Some("🧑"));
|
||||
assert_eq!(g.remove_type("Gente".into()).unwrap(), 1);
|
||||
assert!(g.page(a).unwrap().unwrap().page.page_type.is_none());
|
||||
|
||||
// The tag catalog says where tags come from.
|
||||
g.add_page_tag(b.clone(), "idea".into()).unwrap();
|
||||
let tags = g.tag_catalog().unwrap();
|
||||
let idea = tags.iter().find(|t| t.name == "idea").unwrap();
|
||||
assert_eq!((idea.explicit, idea.typed, idea.from_hub), (1, 1, 0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_hub_tag_and_a_same_name_type_need_no_tag_node_beside_the_hub() {
|
||||
let (_d, g) = open();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! Deterministic Markdown export of pages.
|
||||
//!
|
||||
//! Layout: `pages/<encoded title>.md`, `journals/YYYY_MM_DD.md`, `assets.json`.
|
||||
//! Layout: `pages/<encoded title>.md`, `journals/YYYY_MM_DD.md`, `assets.json`, `types.json`.
|
||||
//! A page file starts with page properties (`key:: value`, aliases as `alias:: a, b`),
|
||||
//! then one `- ` bullet per block, nested with tabs. Block properties follow the content;
|
||||
//! blocks referenced by `((uuid))` carry an `id::` property. Hubs carry `synapse-kind:: hub`
|
||||
@@ -16,6 +16,8 @@ use synapse_core::{Block, BlockId, Graph, Page, Properties};
|
||||
pub const PAGES_DIR: &str = "pages";
|
||||
pub const JOURNALS_DIR: &str = "journals";
|
||||
pub const MANIFEST: &str = "assets.json";
|
||||
/// Type definitions (names with their emoji icon), see [`render_types`].
|
||||
pub const TYPES_FILE: &str = "types.json";
|
||||
/// Page property marking a hub or tag page (`synapse-kind:: hub|tag`); notes omit it.
|
||||
pub const KIND_PROP: &str = "synapse-kind";
|
||||
/// Page property holding a hub's description.
|
||||
@@ -242,6 +244,35 @@ pub fn referenced_blocks(conn: &Connection) -> Result<HashSet<BlockId>> {
|
||||
Ok(set)
|
||||
}
|
||||
|
||||
/// One entry of [`TYPES_FILE`].
|
||||
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||
pub struct TypeEntry {
|
||||
pub name: String,
|
||||
#[serde(default)]
|
||||
pub icon: Option<String>,
|
||||
}
|
||||
|
||||
/// Type definitions (`types.json`): the live ones (not removed), sorted by name key, so it is
|
||||
/// deterministic. `None` when there are none (the file is left out).
|
||||
pub fn render_types(graph: &Graph) -> Result<Option<String>> {
|
||||
let defs: std::collections::BTreeMap<String, synapse_core::TypeDef> =
|
||||
graph.type_defs()?.into_iter().collect();
|
||||
let list: Vec<TypeEntry> = defs
|
||||
.into_values()
|
||||
.filter(|d| !d.removed)
|
||||
.map(|d| TypeEntry {
|
||||
name: d.name,
|
||||
icon: d.icon,
|
||||
})
|
||||
.collect();
|
||||
if list.is_empty() {
|
||||
return Ok(None);
|
||||
}
|
||||
let mut s = serde_json::to_string_pretty(&list).map_err(Error::from)?;
|
||||
s.push('\n');
|
||||
Ok(Some(s))
|
||||
}
|
||||
|
||||
/// Asset manifest (`assets.json`): sorted by hash, so it is deterministic.
|
||||
pub fn render_manifest(conn: &Connection) -> Result<String> {
|
||||
let mut st =
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use crate::Result;
|
||||
use crate::error::Error;
|
||||
use crate::export::{self, JOURNALS_DIR, MANIFEST, PAGES_DIR};
|
||||
use crate::export::{self, JOURNALS_DIR, MANIFEST, PAGES_DIR, TYPES_FILE};
|
||||
use crate::repo::{CommitInfo, Files, Repo};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::{BTreeSet, HashMap, HashSet};
|
||||
@@ -202,7 +202,7 @@ impl History {
|
||||
Op::DeletePage { id } => touched.extend(graph.hub_members(id)?),
|
||||
// Deletions and moves do not say which page lost a block; those
|
||||
// pages are caught by the `updated_at` scan below.
|
||||
Op::DeleteBlock { .. } | Op::PutAsset { .. } => {}
|
||||
Op::DeleteBlock { .. } | Op::PutAsset { .. } | Op::PutTypeDef { .. } => {}
|
||||
// The previous owner of an alias is unknown.
|
||||
Op::SetAlias { .. } => everything = true,
|
||||
}
|
||||
@@ -270,6 +270,22 @@ impl History {
|
||||
.write_blob(export::render_manifest(graph.conn())?.as_bytes())?;
|
||||
let assets_changed = old_files.get(MANIFEST) != Some(&manifest);
|
||||
files.insert(MANIFEST.to_string(), manifest);
|
||||
let types = match export::render_types(graph)? {
|
||||
Some(text) => Some(self.repo.write_blob(text.as_bytes())?),
|
||||
None => None,
|
||||
};
|
||||
let types_changed = old_files.get(TYPES_FILE) != types.as_ref();
|
||||
match types {
|
||||
Some(oid) => files.insert(TYPES_FILE.to_string(), oid),
|
||||
None => files.remove(TYPES_FILE),
|
||||
};
|
||||
let other = if assets_changed {
|
||||
Some("assets updated")
|
||||
} else if types_changed {
|
||||
Some("types updated")
|
||||
} else {
|
||||
None
|
||||
};
|
||||
if self.opts.include_blobs {
|
||||
self.add_blobs(graph, &mut files)?;
|
||||
}
|
||||
@@ -284,7 +300,7 @@ impl History {
|
||||
self.save_state(&new_state)?;
|
||||
return Ok(None);
|
||||
}
|
||||
let message = commit_message(&created, &edited, &deleted, assets_changed, seq_now);
|
||||
let message = commit_message(&created, &edited, &deleted, other, seq_now);
|
||||
let id = self.repo.commit(&files, &message, now_ms / 1000)?;
|
||||
self.save_state(&new_state)?;
|
||||
Ok(Some(self.repo.commit_info(id)?.into()))
|
||||
@@ -430,7 +446,7 @@ fn commit_message(
|
||||
created: &BTreeSet<String>,
|
||||
edited: &BTreeSet<String>,
|
||||
deleted: &BTreeSet<String>,
|
||||
assets: bool,
|
||||
other: Option<&str>,
|
||||
seq: i64,
|
||||
) -> String {
|
||||
let plural = |n: usize| if n == 1 { "page" } else { "pages" };
|
||||
@@ -445,7 +461,7 @@ fn commit_message(
|
||||
parts.push(format!("{} deleted", deleted.len()));
|
||||
}
|
||||
if parts.is_empty() {
|
||||
parts.push(if assets { "assets updated" } else { "snapshot" }.to_string());
|
||||
parts.push(other.unwrap_or("snapshot").to_string());
|
||||
}
|
||||
let mut titles: Vec<&String> = edited.iter().chain(created).chain(deleted).collect();
|
||||
titles.sort();
|
||||
|
||||
@@ -20,6 +20,30 @@ pub struct RestoreReport {
|
||||
pub safety_snapshot: Option<SnapshotInfo>,
|
||||
}
|
||||
|
||||
/// Brings type definitions back to the snapshot's `types.json` (missing file: none). Types
|
||||
/// defined now but not in the snapshot lose their icon and stay defined (a tombstone would
|
||||
/// also hide a seeded suggestion of that name). Bad entries are skipped.
|
||||
fn restore_types(graph: &Graph, history: &History, files: &crate::repo::Files) -> Result<()> {
|
||||
let wanted: Vec<export::TypeEntry> = match files.get(export::TYPES_FILE) {
|
||||
Some(oid) => serde_json::from_str(&history.read_blob(*oid)?).unwrap_or_default(),
|
||||
None => Vec::new(),
|
||||
};
|
||||
let mut keep: HashSet<String> = HashSet::new();
|
||||
for t in &wanted {
|
||||
if skip_invalid(graph.create_type(&t.name))?.is_some()
|
||||
&& skip_invalid(graph.set_type_icon(&t.name, t.icon.as_deref()))?.is_some()
|
||||
{
|
||||
keep.insert(synapse_core::title_key(&t.name));
|
||||
}
|
||||
}
|
||||
for (key, def) in graph.type_defs()? {
|
||||
if !def.removed && def.icon.is_some() && !keep.contains(&key) {
|
||||
graph.set_type_icon(&def.name, None)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Test hook: fail after this many block writes/deletes.
|
||||
type Fault<'a> = &'a Cell<Option<usize>>;
|
||||
|
||||
@@ -436,6 +460,7 @@ impl History {
|
||||
report.removed += 1;
|
||||
}
|
||||
}
|
||||
restore_types(graph, this, &files)?;
|
||||
Ok(())
|
||||
})?;
|
||||
Ok(report)
|
||||
|
||||
@@ -371,6 +371,38 @@ fn tags_round_trip_through_snapshots() {
|
||||
assert_eq!(g.pages_with_tag("idea").unwrap(), [note.id]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn type_icons_round_trip_through_snapshots() {
|
||||
let (_d, g, mut h) = setup();
|
||||
let note = add(&g, "Ada", &["body"]);
|
||||
g.set_page_type(note.id, Some("persona")).unwrap();
|
||||
let s0 = h.snapshot(&g, T0 + 100).unwrap().unwrap();
|
||||
assert!(h.file(&s0.id, export::TYPES_FILE).unwrap().is_none());
|
||||
|
||||
at(&g, T0 + 200);
|
||||
g.set_type_icon("persona", Some("🧑")).unwrap();
|
||||
g.create_type("Libro").unwrap();
|
||||
let s1 = h.snapshot(&g, T0 + 500).unwrap().unwrap();
|
||||
assert_eq!(s1.summary, "types updated");
|
||||
let json = h.file(&s1.id, export::TYPES_FILE).unwrap().unwrap();
|
||||
assert!(json.contains("\"Libro\"") && json.contains("🧑"), "{json}");
|
||||
|
||||
at(&g, T0 + 1000);
|
||||
g.set_type_icon("persona", Some("👤")).unwrap();
|
||||
g.set_type_icon("lugar", Some("📍")).unwrap();
|
||||
h.restore_graph(&g, &s1.id, T0 + 2000).unwrap();
|
||||
let icon = |name: &str| {
|
||||
g.type_catalog()
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.find(|t| t.name == name)
|
||||
.and_then(|t| t.icon)
|
||||
};
|
||||
assert_eq!(icon("persona").as_deref(), Some("🧑"));
|
||||
assert_eq!(icon("lugar"), None);
|
||||
assert!(g.type_catalog().unwrap().iter().any(|t| t.name == "Libro"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hubs_round_trip_kind_description_and_memberships() {
|
||||
let (_d, g, mut h) = setup();
|
||||
|
||||
@@ -256,7 +256,7 @@ impl Search {
|
||||
}
|
||||
// The previous owner of an alias is not in the op, so refresh all pages.
|
||||
Op::SetAlias { .. } => all_pages = true,
|
||||
Op::PutAsset { .. } => {}
|
||||
Op::PutAsset { .. } | Op::PutTypeDef { .. } => {}
|
||||
}
|
||||
}
|
||||
stats.ops_processed += ops.len();
|
||||
|
||||
Reference in new issue
Block a user