fur_cli/
schema.rs

1use serde_json::{json, Value};
2use chrono::Utc;
3use uuid::Uuid;
4
5/// === FUR Schema Constructors ===
6///
7/// Centralized builders for index, thread, and message JSON.
8/// These are used by `new.rs`, `jot.rs`, and any future modules.
9/// Keeps structure consistent and allows easy schema evolution.
10
11/// Global schema version (increment as the JSON schema evolves)
12pub const SCHEMA_VERSION: &str = "0.2";
13
14/// Build index.json metadata
15pub fn make_index_metadata() -> Value {
16    json!({
17        "threads": [],
18        "active_thread": null,
19        "current_message": null,
20        "created_at": Utc::now().to_rfc3339(),
21        "schema_version": SCHEMA_VERSION
22    })
23}
24
25/// Build thread metadata (.fur/threads/<id>.json)
26pub fn make_thread_metadata(title: &str, id: &str) -> Value {
27    json!({
28        "id": id,
29        "created_at": Utc::now().to_rfc3339(),
30        "messages": [],
31        "tags": [],
32        "title": title,
33        "schema_version": SCHEMA_VERSION
34    })
35}
36
37/// Build message metadata (.fur/messages/<id>.json)
38pub fn make_message_metadata(
39    avatar: &str,
40    text: Option<String>,
41    markdown: Option<String>,
42    img: Option<String>,
43    parent: Option<String>,
44) -> Value {
45    let id = Uuid::new_v4().to_string();
46    let timestamp = Utc::now().to_rfc3339();
47
48    json!({
49        "id": id,
50        "avatar": avatar,
51        "timestamp": timestamp,
52        "text": text,
53        "markdown": markdown,
54        "attachment": img,
55        "parent": parent,
56        "children": [],
57        "branches": [],
58        "schema_version": SCHEMA_VERSION
59    })
60}