fur_cli/
schema.rs

1use serde_json::{json, Value};
2use chrono::Utc;
3use uuid::Uuid;
4
5/* 
6=== FUR Schema Constructors ===
7
8Centralized builders for index, conversation, and message JSON.
9These are used by `new.rs`, `jot.rs`, and any future modules.
10Keeps structure consistent and allows easy schema evolution.
11
12Global schema version (increment as the JSON schema evolves)
13 */
14
15pub const SCHEMA_VERSION: &str = "0.2";
16
17pub fn make_index_metadata() -> Value {
18    json!({
19        "threads": [],
20        "active_thread": null,
21        "current_message": null,
22        "created_at": Utc::now().to_rfc3339(),
23        "schema_version": SCHEMA_VERSION
24    })
25}
26
27pub fn make_conversation_metadata(title: &str, id: &str) -> Value {
28    json!({
29        "id": id,
30        "created_at": Utc::now().to_rfc3339(),
31        "messages": [],
32        "tags": [],
33        "title": title,
34        "schema_version": SCHEMA_VERSION
35    })
36}
37
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}