1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright (C) 2024-2026 Tristan Stoltz / Luminous Dynamics
// SPDX-License-Identifier: AGPL-3.0-or-later
// Commercial licensing: see COMMERCIAL_LICENSE.md at repository root
//! Browser-compatible Holochain client for Leptos frontends.
//!
//! Replaces `@holochain/client` (JavaScript) for Rust WASM frontends.
//! Uses `web-sys::WebSocket` + `rmp-serde` (MessagePack) to communicate
//! with a Holochain conductor over binary WebSocket frames.
//!
//! # Architecture
//!
//! The crate is built around the [`HolochainTransport`] trait, which abstracts
//! the underlying communication mechanism. Two implementations are provided:
//!
//! - [`BrowserWsTransport`] — Uses `web-sys::WebSocket` for browser WASM targets
//! - `TauriIpcTransport` — (future) Calls Tauri backend via `wasm-bindgen` `invoke()`
//!
//! The [`HolochainClient`] type wraps any transport and provides a typed,
//! ergonomic API for calling zome functions with automatic MessagePack
//! serialization/deserialization.
//!
//! # Example
//!
//! ```rust,ignore
//! use mycelix_leptos_client::{HolochainClient, BrowserWsTransport};
//! use serde::{Serialize, Deserialize};
//!
//! #[derive(Serialize)]
//! struct CreateProposal { title: String, body: String }
//!
//! #[derive(Deserialize)]
//! struct ProposalHash { hash: Vec<u8> }
//!
//! async fn example() {
//! let transport = BrowserWsTransport::new();
//! let client = HolochainClient::new(transport, "mycelix-unified", "governance");
//! // Connect with optional auth token (None = no authentication)
//! client.connect("ws://localhost:8888", None).await.unwrap();
//!
//! let result: ProposalHash = client.call_zome(
//! "agora",
//! "create_proposal",
//! &CreateProposal { title: "Test".into(), body: "Body".into() },
//! ).await.unwrap();
//! }
//! ```
// Re-exports for convenience
pub use HolochainClient;
pub use ClientError;
pub use MockTransport;
pub use NativeWsTransport;
pub use HolochainTransport;
pub use ;
pub use BrowserWsTransport;
pub use TauriIpcTransport;