From 1ea37e2e7f80395922c30158e92081bb227b077d Mon Sep 17 00:00:00 2001 From: Timur Gordon <31495328+timurgordon@users.noreply.github.com> Date: Thu, 3 Apr 2025 19:03:38 +0200 Subject: [PATCH] rust rhai ui components wip --- devtools/reloadd/Cargo.toml | 11 + devtools/reloadd/bin/reloadd.rs | 97 ++ devtools/reloadd/src/main.rs | 240 +++ examples/calendar/backend/Cargo.lock | 251 +++ examples/calendar/backend/Cargo.toml | 11 + examples/calendar/backend/data/calendars.json | 31 + examples/calendar/backend/data/events.json | 57 + examples/calendar/backend/data/users.json | 54 + examples/calendar/backend/main.rhai | 118 ++ examples/calendar/backend/main.rs | 11 + .../backend/models/calendar_model.rhai | 54 + .../calendar/backend/models/event_model.rhai | 92 + .../calendar/backend/models/user_model.rhai | 72 + .../calendar/backend/scripts/calendars.rhai | 73 + examples/calendar/backend/scripts/events.rhai | 85 + examples/calendar/backend/scripts/users.rhai | 60 + examples/calendar/backend/scripts/utils.rhai | 84 + .../components/calendar/.cargo/config.toml | 2 + .../calendar/components/calendar/Cargo.lock | 1524 +++++++++++++++++ .../calendar/components/calendar/Cargo.toml | 15 + .../calendar/components/calendar/README.md | 51 + .../calendar/components/calendar/develop.sh | 9 + .../components/calendar/examples/server.rs | 114 ++ .../calendar/src/controller/calendar.rs | 121 ++ .../calendar/components/calendar/src/main.rs | 69 + .../src/templates/get_calendars.html.tera | 16 + 26 files changed, 3322 insertions(+) create mode 100644 devtools/reloadd/Cargo.toml create mode 100644 devtools/reloadd/bin/reloadd.rs create mode 100644 devtools/reloadd/src/main.rs create mode 100644 examples/calendar/backend/Cargo.lock create mode 100644 examples/calendar/backend/Cargo.toml create mode 100644 examples/calendar/backend/data/calendars.json create mode 100644 examples/calendar/backend/data/events.json create mode 100644 examples/calendar/backend/data/users.json create mode 100644 examples/calendar/backend/main.rhai create mode 100644 examples/calendar/backend/main.rs create mode 100644 examples/calendar/backend/models/calendar_model.rhai create mode 100644 examples/calendar/backend/models/event_model.rhai create mode 100644 examples/calendar/backend/models/user_model.rhai create mode 100644 examples/calendar/backend/scripts/calendars.rhai create mode 100644 examples/calendar/backend/scripts/events.rhai create mode 100644 examples/calendar/backend/scripts/users.rhai create mode 100644 examples/calendar/backend/scripts/utils.rhai create mode 100644 examples/calendar/components/calendar/.cargo/config.toml create mode 100644 examples/calendar/components/calendar/Cargo.lock create mode 100644 examples/calendar/components/calendar/Cargo.toml create mode 100644 examples/calendar/components/calendar/README.md create mode 100755 examples/calendar/components/calendar/develop.sh create mode 100644 examples/calendar/components/calendar/examples/server.rs create mode 100644 examples/calendar/components/calendar/src/controller/calendar.rs create mode 100644 examples/calendar/components/calendar/src/main.rs create mode 100644 examples/calendar/components/calendar/src/templates/get_calendars.html.tera diff --git a/devtools/reloadd/Cargo.toml b/devtools/reloadd/Cargo.toml new file mode 100644 index 0000000..b320e3b --- /dev/null +++ b/devtools/reloadd/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "reloadd" +version = "0.1.0" +edition = "2021" + +[dependencies] +clap = { version = "4", features = ["derive"] } +tokio = { version = "1", features = ["full"] } +tokio-tungstenite = "0.21" +notify = "6" +futures-util = "0.3" \ No newline at end of file diff --git a/devtools/reloadd/bin/reloadd.rs b/devtools/reloadd/bin/reloadd.rs new file mode 100644 index 0000000..ac8faad --- /dev/null +++ b/devtools/reloadd/bin/reloadd.rs @@ -0,0 +1,97 @@ +use clap::{Parser}; +use notify::{RecursiveMode, Watcher, EventKind, recommended_watcher}; +use std::sync::{Arc, Mutex}; +use std::process::{Command, Child, Stdio}; +use tokio::net::TcpListener; +use tokio::sync::broadcast; +use tokio_tungstenite::accept_async; +use futures_util::{SinkExt, StreamExt}; + +#[derive(Parser, Debug)] +#[command(author, version, about)] +struct Args { + /// Paths to watch (like src/, templates/, scripts/) + #[arg(short, long, value_name = "PATH", num_args = 1.., required = true)] + watch: Vec, + + /// Command to run on change (like: -- run --example server) + #[arg(last = true)] + command: Vec, +} + +#[tokio::main] +async fn main() { + let args = Args::parse(); + + let (tx, _) = broadcast::channel::<()>(10); + let tx_ws = tx.clone(); + let server_process = Arc::new(Mutex::new(None::)); + + // Start WebSocket reload server + tokio::spawn(start_websocket_server(tx_ws.clone())); + + // Start watching files and restarting command + let server_process_clone = Arc::clone(&server_process); + let watch_paths = args.watch.clone(); + let cmd_args = args.command.clone(); + + std::thread::spawn(move || { + let mut watcher = recommended_watcher(move |res| { + if let Ok(event) = res { + if matches!(event.kind, EventKind::Modify(_) | EventKind::Create(_) | EventKind::Remove(_)) { + println!("πŸ“¦ Change detected, restarting..."); + + // Kill previous process + if let Some(mut child) = server_process_clone.lock().unwrap().take() { + let _ = child.kill(); + } + + // Run new process + let mut cmd = Command::new("cargo"); + cmd.args(&cmd_args); + cmd.stdout(Stdio::inherit()) + .stderr(Stdio::inherit()); + let child = cmd.spawn().expect("Failed to spawn"); + + *server_process_clone.lock().unwrap() = Some(child); + + // Notify browser + let _ = tx.send(()); + } + } + }).expect("watcher failed"); + + // Add watches + for path in &watch_paths { + watcher.watch(path, RecursiveMode::Recursive).unwrap(); + } + + loop { + std::thread::sleep(std::time::Duration::from_secs(3600)); + } + }); + + println!("πŸ” Watching paths: {:?}", args.watch); + println!("🌐 Connect browser to ws://localhost:35729"); + loop { + tokio::time::sleep(tokio::time::Duration::from_secs(3600)).await; + } +} + +async fn start_websocket_server(tx: broadcast::Sender<()>) { + let listener = TcpListener::bind("127.0.0.1:35729").await.unwrap(); + + while let Ok((stream, _)) = listener.accept().await { + let tx = tx.clone(); + let mut rx = tx.subscribe(); + + tokio::spawn(async move { + let ws_stream = accept_async(stream).await.unwrap(); + let (mut write, _) = ws_stream.split(); + + while rx.recv().await.is_ok() { + let _ = write.send(tokio_tungstenite::tungstenite::Message::Text("reload".into())).await; + } + }); + } +} \ No newline at end of file diff --git a/devtools/reloadd/src/main.rs b/devtools/reloadd/src/main.rs new file mode 100644 index 0000000..e0acc40 --- /dev/null +++ b/devtools/reloadd/src/main.rs @@ -0,0 +1,240 @@ +use clap::{Parser}; +use notify::{RecursiveMode, Watcher, EventKind, recommended_watcher}; +use std::sync::{Arc, Mutex}; +use std::process::{Command, Child, Stdio}; +use tokio::net::TcpStream; +use tokio::sync::broadcast; +use tokio_tungstenite::accept_async; +use futures_util::{SinkExt, StreamExt}; +use tokio::time::{sleep, Duration}; +use tokio::io::AsyncWriteExt; +use std::net::TcpListener as StdTcpListener; + +#[derive(Parser, Debug)] +#[command(author, version, about)] +struct Args { + /// Paths to watch (like src/, templates/, scripts/) + #[arg(short, long, value_name = "PATH", num_args = 1.., required = true)] + watch: Vec, + + /// Command to run on change (like: -- run --example server) + #[arg(last = true)] + command: Vec, +} + +async fn wait_for_server(port: u16) -> bool { + let address = format!("localhost:{}", port); + let mut retries = 0; + + while retries < 10 { + if let Ok(mut stream) = TcpStream::connect(&address).await { + let _ = stream.write_all(b"GET / HTTP/1.1\r\n\r\n").await; // A dummy GET request + println!("βœ… Server is ready on {}!", address); + return true; + } else { + retries += 1; + println!("⏳ Waiting for server to be ready (Attempt {}/10)...", retries); + sleep(Duration::from_secs(1)).await; + } + } + + eprintln!("❌ Server not ready after 10 attempts."); + false +} + +// Check if a port is already in use +fn is_port_in_use(port: u16) -> bool { + StdTcpListener::bind(format!("127.0.0.1:{}", port)).is_err() +} +#[tokio::main] +async fn main() { + let args = Args::parse(); + println!("Command: {:?}", args.command); + + // Check if server port is already in use + let server_port = 8080; // Adjust as needed + if is_port_in_use(server_port) { + eprintln!("❌ Error: Port {} is already in use. Stop any running instances before starting a new one.", server_port); + std::process::exit(1); + } + + // Check if WebSocket port is already in use + let ws_port = 35729; + if is_port_in_use(ws_port) { + eprintln!("❌ Error: WebSocket port {} is already in use. Stop any running instances before starting a new one.", ws_port); + std::process::exit(1); + } + + let (tx, _) = broadcast::channel::<()>(10); + let tx_ws = tx.clone(); + let server_process = Arc::new(Mutex::new(None::)); + + // Validate paths before starting the watcher + let mut invalid_paths = Vec::new(); + for path in &args.watch { + if !std::path::Path::new(path).exists() { + invalid_paths.push(path.clone()); + } + } + + if !invalid_paths.is_empty() { + eprintln!("❌ Error: The following watch paths do not exist:"); + for path in invalid_paths { + eprintln!(" - {}", path); + } + eprintln!("Please provide valid paths to watch."); + std::process::exit(1); + } + + // Start WebSocket reload server + match start_websocket_server(tx_ws.clone()).await { + Ok(_) => {}, + Err(e) => { + eprintln!("❌ Failed to start WebSocket server: {}", e); + std::process::exit(1); + } + } + + // πŸš€ Run the server immediately + { + let mut cmd = Command::new("cargo"); + cmd.args(&args.command); + cmd.stdout(Stdio::inherit()) + .stderr(Stdio::inherit()); + match cmd.spawn() { + Ok(child) => { + *server_process.lock().unwrap() = Some(child); + }, + Err(e) => { + eprintln!("❌ Failed to start initial process: {}", e); + std::process::exit(1); + } + } + } + + // Wait for the server to be ready before triggering reloads + if !wait_for_server(server_port).await { + eprintln!("❌ Server failed to start properly."); + std::process::exit(1); + } + + println!("πŸ” Watching paths: {:?}", args.watch); + println!("🌐 Connect browser to ws://localhost:{}", ws_port); + + // Create a runtime handle for the watcher to use + let rt_handle = tokio::runtime::Handle::current(); + + // Clone necessary values before moving into the watcher thread + let watch_paths = args.watch.clone(); + let cmd_args = args.command.clone(); + let server_process_clone = Arc::clone(&server_process); + let tx_clone = tx.clone(); + + // Create a dedicated thread for the file watcher + let watcher_thread = std::thread::spawn(move || { + // Create a new watcher + let mut watcher = match recommended_watcher(move |res: notify::Result| { + if let Ok(event) = res { + if matches!(event.kind, EventKind::Modify(_) | EventKind::Create(_) | EventKind::Remove(_)) { + println!("πŸ“¦ Change detected, restarting..."); + + // Kill previous process + if let Some(mut child) = server_process_clone.lock().unwrap().take() { + let _ = child.kill(); + } + + // Run new process + let mut cmd = Command::new("cargo"); + cmd.args(&cmd_args); + cmd.stdout(Stdio::inherit()) + .stderr(Stdio::inherit()); + + match cmd.spawn() { + Ok(child) => { + *server_process_clone.lock().unwrap() = Some(child); + + // Use the runtime handle to spawn a task + let tx = tx_clone.clone(); + rt_handle.spawn(async move { + if wait_for_server(server_port).await { + // Notify browser to reload + let _ = tx.send(()); + } + }); + }, + Err(e) => { + eprintln!("❌ Failed to spawn process: {}", e); + } + } + } + } else if let Err(e) = res { + eprintln!("❌ Watch error: {}", e); + } + }) { + Ok(w) => w, + Err(e) => { + eprintln!("❌ Failed to create watcher: {}", e); + std::process::exit(1); + } + }; + + // Add watches + for path in &watch_paths { + match watcher.watch(path.as_ref(), RecursiveMode::Recursive) { + Ok(_) => println!("πŸ‘οΈ Watching path: {}", path), + Err(e) => { + eprintln!("❌ Failed to watch path '{}': {}", path, e); + std::process::exit(1); + } + } + } + + // Keep the thread alive + loop { + std::thread::sleep(std::time::Duration::from_secs(3600)); + } + }); + + // Wait for the watcher thread to finish (it shouldn't unless there's an error) + match watcher_thread.join() { + Ok(_) => {}, + Err(e) => { + eprintln!("❌ Watcher thread panicked: {:?}", e); + std::process::exit(1); + } + } +} + +async fn start_websocket_server(tx: broadcast::Sender<()>) -> Result<(), Box> { + let listener = tokio::net::TcpListener::bind("127.0.0.1:35729").await?; + println!("WebSocket server started on ws://localhost:35729"); + + // Spawn a task to handle WebSocket connections + tokio::spawn(async move { + while let Ok((stream, addr)) = listener.accept().await { + println!("New WebSocket connection from: {}", addr); + let tx = tx.clone(); + let mut rx = tx.subscribe(); + + tokio::spawn(async move { + match accept_async(stream).await { + Ok(ws_stream) => { + let (mut write, _) = ws_stream.split(); + + while rx.recv().await.is_ok() { + if let Err(e) = write.send(tokio_tungstenite::tungstenite::Message::Text("reload".into())).await { + eprintln!("❌ Error sending reload message to client {}: {}", addr, e); + break; + } + } + }, + Err(e) => { + eprintln!("❌ Failed to accept WebSocket connection from {}: {}", addr, e); + } + } + }); + } + }); + + Ok(()) +} \ No newline at end of file diff --git a/examples/calendar/backend/Cargo.lock b/examples/calendar/backend/Cargo.lock new file mode 100644 index 0000000..3b16fa3 --- /dev/null +++ b/examples/calendar/backend/Cargo.lock @@ -0,0 +1,251 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "const-random", + "getrandom", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "autocfg" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" + +[[package]] +name = "bitflags" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c8214115b7bf84099f1309324e63141d4c5d7cc26862f97a0a857dbefe165bd" + +[[package]] +name = "calendar_backend" +version = "0.1.0" +dependencies = [ + "rhai", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "const-random" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87e00182fe74b066627d63b85fd550ac2998d4b0bd86bfed477a0ae4c7c71359" +dependencies = [ + "const-random-macro", +] + +[[package]] +name = "const-random-macro" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9d839f2a20b0aee515dc581a6172f2321f96cab76c1a38a4c584a194955390e" +dependencies = [ + "getrandom", + "once_cell", + "tiny-keccak", +] + +[[package]] +name = "crunchy" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43da5946c66ffcc7745f48db692ffbb10a83bfe0afd96235c5c2a4fb23994929" + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "instant" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0242819d153cba4b4b05a5a8f2a7e9bbf97b6055b2a002b395c96b5ff3c0222" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "libc" +version = "0.2.171" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c19937216e9d3aa9956d9bb8dfc0b0c8beb6058fc4f7a4dc4d850edf86a237d6" + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "once_cell" +version = "1.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" +dependencies = [ + "portable-atomic", +] + +[[package]] +name = "portable-atomic" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "350e9b48cbc6b0e028b0473b114454c6316e57336ee184ceab6e53f72c178b3e" + +[[package]] +name = "proc-macro2" +version = "1.0.94" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a31971752e70b8b2686d7e46ec17fb38dad4051d94024c88df49b667caea9c84" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rhai" +version = "1.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce4d759a4729a655ddfdbb3ff6e77fb9eadd902dae12319455557796e435d2a6" +dependencies = [ + "ahash", + "bitflags", + "instant", + "num-traits", + "once_cell", + "rhai_codegen", + "smallvec", + "smartstring", + "thin-vec", +] + +[[package]] +name = "rhai_codegen" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5a11a05ee1ce44058fa3d5961d05194fdbe3ad6b40f904af764d81b86450e6b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "smallvec" +version = "1.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fcf8323ef1faaee30a44a340193b1ac6814fd9b7b4e88e9d4519a3e4abe1cfd" + +[[package]] +name = "smartstring" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fb72c633efbaa2dd666986505016c32c3044395ceaf881518399d2f4127ee29" +dependencies = [ + "autocfg", + "static_assertions", + "version_check", +] + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + +[[package]] +name = "syn" +version = "2.0.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "thin-vec" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "144f754d318415ac792f9d69fc87abbbfc043ce2ef041c60f16ad828f638717d" + +[[package]] +name = "tiny-keccak" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" +dependencies = [ + "crunchy", +] + +[[package]] +name = "unicode-ident" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] diff --git a/examples/calendar/backend/Cargo.toml b/examples/calendar/backend/Cargo.toml new file mode 100644 index 0000000..d8f61c2 --- /dev/null +++ b/examples/calendar/backend/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "calendar_backend" +version = "0.1.0" +edition = "2021" + +[[bin]] +name = "rhai_engine" +path = "main.rs" + +[dependencies] +rhai = "1.12.0" diff --git a/examples/calendar/backend/data/calendars.json b/examples/calendar/backend/data/calendars.json new file mode 100644 index 0000000..2c17ffb --- /dev/null +++ b/examples/calendar/backend/data/calendars.json @@ -0,0 +1,31 @@ +{ + "calendars": [ + { + "id": "cal1", + "name": "Work Calendar", + "owner_id": "user1", + "description": "Main work calendar for team coordination", + "color": "#4285F4", + "shared_with": ["user2", "user3", "user4"], + "visibility": "team" + }, + { + "id": "cal2", + "name": "Personal Calendar", + "owner_id": "user1", + "description": "Personal appointments and reminders", + "color": "#0F9D58", + "shared_with": ["user5"], + "visibility": "private" + }, + { + "id": "cal3", + "name": "Project Calendar", + "owner_id": "user2", + "description": "Project-specific deadlines and milestones", + "color": "#DB4437", + "shared_with": ["user1", "user3", "user4"], + "visibility": "public" + } + ] +} diff --git a/examples/calendar/backend/data/events.json b/examples/calendar/backend/data/events.json new file mode 100644 index 0000000..119bbed --- /dev/null +++ b/examples/calendar/backend/data/events.json @@ -0,0 +1,57 @@ +{ + "events": [ + { + "id": "event1", + "title": "Team Meeting", + "description": "Weekly team sync meeting", + "start_time": "2025-04-04T10:00:00", + "end_time": "2025-04-04T11:00:00", + "location": "Conference Room A", + "calendar_id": "cal1", + "organizer_id": "user1", + "attendees": ["user1", "user2", "user3"], + "recurring": false, + "status": "confirmed" + }, + { + "id": "event2", + "title": "Project Deadline", + "description": "Final submission for Q2 project", + "start_time": "2025-04-15T17:00:00", + "end_time": "2025-04-15T18:00:00", + "location": "Virtual", + "calendar_id": "cal1", + "organizer_id": "user2", + "attendees": ["user1", "user2", "user4"], + "recurring": false, + "status": "confirmed" + }, + { + "id": "event3", + "title": "Lunch with Client", + "description": "Discuss upcoming partnership", + "start_time": "2025-04-10T12:30:00", + "end_time": "2025-04-10T14:00:00", + "location": "Downtown Cafe", + "calendar_id": "cal2", + "organizer_id": "user1", + "attendees": ["user1", "user5"], + "recurring": false, + "status": "tentative" + }, + { + "id": "event4", + "title": "Weekly Status Update", + "description": "Regular status update meeting", + "start_time": "2025-04-05T09:00:00", + "end_time": "2025-04-05T09:30:00", + "location": "Conference Room B", + "calendar_id": "cal1", + "organizer_id": "user3", + "attendees": ["user1", "user2", "user3", "user4"], + "recurring": true, + "recurrence_pattern": "weekly", + "status": "confirmed" + } + ] +} diff --git a/examples/calendar/backend/data/users.json b/examples/calendar/backend/data/users.json new file mode 100644 index 0000000..261af3c --- /dev/null +++ b/examples/calendar/backend/data/users.json @@ -0,0 +1,54 @@ +{ + "users": [ + { + "id": "user1", + "name": "John Doe", + "email": "john.doe@example.com", + "timezone": "UTC+2", + "preferences": { + "notification_time": 15, + "default_calendar_id": "cal1" + } + }, + { + "id": "user2", + "name": "Jane Smith", + "email": "jane.smith@example.com", + "timezone": "UTC+1", + "preferences": { + "notification_time": 30, + "default_calendar_id": "cal1" + } + }, + { + "id": "user3", + "name": "Bob Johnson", + "email": "bob.johnson@example.com", + "timezone": "UTC", + "preferences": { + "notification_time": 10, + "default_calendar_id": "cal2" + } + }, + { + "id": "user4", + "name": "Alice Brown", + "email": "alice.brown@example.com", + "timezone": "UTC-5", + "preferences": { + "notification_time": 20, + "default_calendar_id": "cal1" + } + }, + { + "id": "user5", + "name": "Charlie Davis", + "email": "charlie.davis@example.com", + "timezone": "UTC+3", + "preferences": { + "notification_time": 15, + "default_calendar_id": "cal2" + } + } + ] +} diff --git a/examples/calendar/backend/main.rhai b/examples/calendar/backend/main.rhai new file mode 100644 index 0000000..2bda41d --- /dev/null +++ b/examples/calendar/backend/main.rhai @@ -0,0 +1,118 @@ +// main.rhai - Main script for the calendar backend + +// Import all modules +import "scripts/events" as events; +import "scripts/users" as users; +import "scripts/calendars" as calendars; +import "scripts/utils" as utils; + +// Example function to get a user's upcoming events +fn get_user_upcoming_events(user_id, days_ahead) { + let user = users::get_user(user_id); + + if utils::is_empty(user) { + return "User not found"; + } + + // Get current date + let current_date = utils::get_current_date(); + + // Calculate end date + let end_date = utils::add_days_to_date(current_date, days_ahead); + + // Get events in the date range + let upcoming_events = events::get_events_by_date_range(current_date, end_date); + + // Filter to only include events where the user is an attendee + let user_events = []; + for event in upcoming_events { + if utils::array_contains(event.attendees, user_id) { + user_events.push(event); + } + } + + return user_events; +} + +// Example function to get a user's calendar summary +fn get_user_calendar_summary(user_id) { + let user = users::get_user(user_id); + + if utils::is_empty(user) { + return "User not found"; + } + + let user_calendars = calendars::get_accessible_calendars(user_id); + let calendar_count = user_calendars.len(); + + let user_events = events::get_events_by_attendee(user_id); + let event_count = user_events.len(); + + let organized_events = events::get_events_by_organizer(user_id); + let organized_count = organized_events.len(); + + return #{ + user_name: user.name, + calendar_count: calendar_count, + event_count: event_count, + organized_count: organized_count + }; +} + +// Example function to get details of a specific event +fn get_event_details(event_id) { + let event = events::get_event(event_id); + + if utils::is_empty(event) { + return "Event not found"; + } + + let organizer = users::get_user(event.organizer_id); + let calendar = calendars::get_calendar(event.calendar_id); + + let attendees_info = []; + for attendee_id in event.attendees { + let attendee = users::get_user(attendee_id); + if !utils::is_empty(attendee) { + attendees_info.push(attendee.name); + } + } + + return #{ + title: event.title, + description: event.description, + start_time: event.start_time, + end_time: event.end_time, + location: event.location, + organizer: organizer.name, + calendar: calendar.name, + attendees: attendees_info, + status: event.status + }; +} + +// Example function to create a new event +fn create_new_event(title, description, start_time, end_time, location, calendar_id, organizer_id, attendees) { + // Validate inputs + let calendar = calendars::get_calendar(calendar_id); + if utils::is_empty(calendar) { + return "Calendar not found"; + } + + let organizer = users::get_user(organizer_id); + if utils::is_empty(organizer) { + return "Organizer not found"; + } + + // Create the event + let new_event = events::create_event( + title, description, start_time, end_time, location, + calendar_id, organizer_id, attendees, false, "confirmed" + ); + + return #{ + message: "Event created successfully", + event_id: new_event.id, + title: new_event.title + }; +} diff --git a/examples/calendar/backend/main.rs b/examples/calendar/backend/main.rs new file mode 100644 index 0000000..e7b001a --- /dev/null +++ b/examples/calendar/backend/main.rs @@ -0,0 +1,11 @@ +use rhai::{Engine}; +use std::path::{Path, PathBuf}; + +fn main() -> Result<(), Box> { + let engine = Engine::new(); + + // Rhai's import system works relative to current working dir + engine.eval_file::<()>(PathBuf::from("main.rhai"))?; + + Ok(()) +} \ No newline at end of file diff --git a/examples/calendar/backend/models/calendar_model.rhai b/examples/calendar/backend/models/calendar_model.rhai new file mode 100644 index 0000000..0afb1cc --- /dev/null +++ b/examples/calendar/backend/models/calendar_model.rhai @@ -0,0 +1,54 @@ +// calendar_model.rhai - Calendar data model + +// Create a new calendar object +fn create_calendar(id, name, owner_id, description, color, shared_with, visibility) { + return #{ + id: id, + name: name, + owner_id: owner_id, + description: description, + color: color, + shared_with: shared_with, + visibility: visibility + }; +} + +// Sample calendars data +fn get_sample_calendars() { + let calendars = []; + + // Calendar 1: Work Calendar + calendars.push(create_calendar( + "cal1", + "Work Calendar", + "user1", + "Main work calendar for team coordination", + "#4285F4", + ["user2", "user3", "user4"], + "team" + )); + + // Calendar 2: Personal Calendar + calendars.push(create_calendar( + "cal2", + "Personal Calendar", + "user1", + "Personal appointments and reminders", + "#0F9D58", + ["user5"], + "private" + )); + + // Calendar 3: Project Calendar + calendars.push(create_calendar( + "cal3", + "Project Calendar", + "user2", + "Project-specific deadlines and milestones", + "#DB4437", + ["user1", "user3", "user4"], + "public" + )); + + return calendars; +} diff --git a/examples/calendar/backend/models/event_model.rhai b/examples/calendar/backend/models/event_model.rhai new file mode 100644 index 0000000..d6586de --- /dev/null +++ b/examples/calendar/backend/models/event_model.rhai @@ -0,0 +1,92 @@ +// event_model.rhai - Event data model + +// Create a new event object +fn create_event(id, title, description, start_time, end_time, location, calendar_id, organizer_id, attendees, recurring, status) { + return #{ + id: id, + title: title, + description: description, + start_time: start_time, + end_time: end_time, + location: location, + calendar_id: calendar_id, + organizer_id: organizer_id, + attendees: attendees, + recurring: recurring, + status: status + }; +} + +// Create a recurring event object (extends regular event) +fn create_recurring_event(id, title, description, start_time, end_time, location, calendar_id, organizer_id, attendees, recurrence_pattern, status) { + let event = create_event(id, title, description, start_time, end_time, location, calendar_id, organizer_id, attendees, true, status); + event.recurrence_pattern = recurrence_pattern; + return event; +} + +// Sample events data +fn get_sample_events() { + let events = []; + + // Event 1: Team Meeting + events.push(create_event( + "event1", + "Team Meeting", + "Weekly team sync meeting", + "2025-04-04T10:00:00", + "2025-04-04T11:00:00", + "Conference Room A", + "cal1", + "user1", + ["user1", "user2", "user3"], + false, + "confirmed" + )); + + // Event 2: Project Deadline + events.push(create_event( + "event2", + "Project Deadline", + "Final submission for Q2 project", + "2025-04-15T17:00:00", + "2025-04-15T18:00:00", + "Virtual", + "cal1", + "user2", + ["user1", "user2", "user4"], + false, + "confirmed" + )); + + // Event 3: Lunch with Client + events.push(create_event( + "event3", + "Lunch with Client", + "Discuss upcoming partnership", + "2025-04-10T12:30:00", + "2025-04-10T14:00:00", + "Downtown Cafe", + "cal2", + "user1", + ["user1", "user5"], + false, + "tentative" + )); + + // Event 4: Weekly Status Update (recurring) + events.push(create_recurring_event( + "event4", + "Weekly Status Update", + "Regular status update meeting", + "2025-04-05T09:00:00", + "2025-04-05T09:30:00", + "Conference Room B", + "cal1", + "user3", + ["user1", "user2", "user3", "user4"], + "weekly", + "confirmed" + )); + + return events; +} diff --git a/examples/calendar/backend/models/user_model.rhai b/examples/calendar/backend/models/user_model.rhai new file mode 100644 index 0000000..4f08688 --- /dev/null +++ b/examples/calendar/backend/models/user_model.rhai @@ -0,0 +1,72 @@ +// user_model.rhai - User data model + +// Create user preferences object +fn create_user_preferences(notification_time, default_calendar_id) { + return #{ + notification_time: notification_time, + default_calendar_id: default_calendar_id + }; +} + +// Create a new user object +fn create_user(id, name, email, timezone, preferences) { + return #{ + id: id, + name: name, + email: email, + timezone: timezone, + preferences: preferences + }; +} + +// Sample users data +fn get_sample_users() { + let users = []; + + // User 1: John Doe + users.push(create_user( + "user1", + "John Doe", + "john.doe@example.com", + "UTC+2", + create_user_preferences(15, "cal1") + )); + + // User 2: Jane Smith + users.push(create_user( + "user2", + "Jane Smith", + "jane.smith@example.com", + "UTC+1", + create_user_preferences(30, "cal1") + )); + + // User 3: Bob Johnson + users.push(create_user( + "user3", + "Bob Johnson", + "bob.johnson@example.com", + "UTC", + create_user_preferences(10, "cal2") + )); + + // User 4: Alice Brown + users.push(create_user( + "user4", + "Alice Brown", + "alice.brown@example.com", + "UTC-5", + create_user_preferences(20, "cal1") + )); + + // User 5: Charlie Davis + users.push(create_user( + "user5", + "Charlie Davis", + "charlie.davis@example.com", + "UTC+3", + create_user_preferences(15, "cal2") + )); + + return users; +} diff --git a/examples/calendar/backend/scripts/calendars.rhai b/examples/calendar/backend/scripts/calendars.rhai new file mode 100644 index 0000000..0dabcd4 --- /dev/null +++ b/examples/calendar/backend/scripts/calendars.rhai @@ -0,0 +1,73 @@ +// calendars.rhai - Functions for handling calendars + +import "utils" as utils; +import "../models/calendar_model" as calendar_model; + +// Get all calendars +fn get_calendars() { + return calendar_model::get_sample_calendars(); +} + +// Get a specific calendar by ID +fn get_calendar(calendar_id) { + let calendars = get_all_calendars(); + return utils::find_by_id(calendars, calendar_id); +} + +// Get calendars owned by a specific user +fn get_calendars_by_owner(user_id) { + let calendars = get_all_calendars(); + return utils::filter_by_property(calendars, "owner_id", user_id); +} + +// Get calendars shared with a specific user +fn get_calendars_shared_with(user_id) { + let calendars = get_all_calendars(); + let shared_calendars = []; + + for calendar in calendars { + if utils::array_contains(calendar.shared_with, user_id) { + shared_calendars.push(calendar); + } + } + + return shared_calendars; +} + +// Get all calendars accessible by a user (owned + shared) +fn get_accessible_calendars(user_id) { + let owned = get_calendars_by_owner(user_id); + let shared_calendars = get_calendars_shared_with(user_id); + + // Combine the two arrays + for calendar in shared_calendars { + owned.push(calendar); + } + + return owned; +} + +// Create a new calendar +fn create_calendar(name, owner_id, description, color, shared_with, visibility) { + // Generate a simple ID (in a real app, we would use a proper ID generation method) + let id = "cal" + (get_all_calendars().len() + 1).to_string(); + + return calendar_model::create_calendar( + id, name, owner_id, description, color, shared_with, visibility + ); +} + +// Format calendar details for display +fn format_calendar(calendar) { + if utils::is_empty(calendar) { + return "Calendar not found"; + } + + let shared_with_count = calendar.shared_with.len(); + + return `${calendar.name} (${calendar.color}) +Description: ${calendar.description} +Owner: ${calendar.owner_id} +Visibility: ${calendar.visibility} +Shared with: ${shared_with_count} users`; +} diff --git a/examples/calendar/backend/scripts/events.rhai b/examples/calendar/backend/scripts/events.rhai new file mode 100644 index 0000000..cafdd08 --- /dev/null +++ b/examples/calendar/backend/scripts/events.rhai @@ -0,0 +1,85 @@ +// events.rhai - Functions for handling calendar events + +import "utils" as utils; +import "../models/event_model" as event_model; + +// Get all events +fn get_all_events() { + return event_model::get_sample_events(); +} + +// Get a specific event by ID +fn get_event(event_id) { + let events = get_all_events(); + return utils::find_by_id(events, event_id); +} + +// Get events for a specific calendar +fn get_events_by_calendar(calendar_id) { + let events = get_all_events(); + return utils::filter_by_property(events, "calendar_id", calendar_id); +} + +// Get events for a specific user (as attendee) +fn get_events_by_attendee(user_id) { + let events = get_all_events(); + let user_events = []; + + for event in events { + if utils::array_contains(event.attendees, user_id) { + user_events.push(event); + } + } + + return user_events; +} + +// Get events organized by a specific user +fn get_events_by_organizer(user_id) { + let events = get_all_events(); + return utils::filter_by_property(events, "organizer_id", user_id); +} + +// Get events for a specific date range +fn get_events_by_date_range(start_date, end_date) { + let events = get_all_events(); + let filtered_events = []; + + for event in events { + let event_start = event.start_time; + + // Simple string comparison - in a real app, we would use proper date comparison + if event_start >= start_date && event_start <= end_date { + filtered_events.push(event); + } + } + + return filtered_events; +} + +// Create a new event +fn create_event(title, description, start_time, end_time, location, calendar_id, organizer_id, attendees, recurring, status) { + // Generate a simple ID (in a real app, we would use a proper ID generation method) + let id = "event" + (get_all_events().len() + 1).to_string(); + + return event_model::create_event( + id, title, description, start_time, end_time, location, + calendar_id, organizer_id, attendees, recurring, status + ); +} + +// Format event details for display +fn format_event(event) { + if utils::is_empty(event) { + return "Event not found"; + } + + let start_date = utils::format_date(event.start_time); + let start_time = utils::format_time(event.start_time); + let end_time = utils::format_time(event.end_time); + + return `${event.title} (${start_date}, ${start_time} - ${end_time}) +Location: ${event.location} +Description: ${event.description} +Status: ${event.status}`; +} diff --git a/examples/calendar/backend/scripts/users.rhai b/examples/calendar/backend/scripts/users.rhai new file mode 100644 index 0000000..b3c4991 --- /dev/null +++ b/examples/calendar/backend/scripts/users.rhai @@ -0,0 +1,60 @@ +// users.rhai - Functions for handling calendar users + +import "utils" as utils; +import "../models/user_model" as user_model; + +// Get all users +fn get_all_users() { + return user_model::get_sample_users(); +} + +// Get a specific user by ID +fn get_user(user_id) { + let users = get_all_users(); + return utils::find_by_id(users, user_id); +} + +// Get user by email +fn get_user_by_email(email) { + let users = get_all_users(); + + for user in users { + if user.email == email { + return user; + } + } + + return #{}; // Return empty object if not found +} + +// Get users by timezone +fn get_users_by_timezone(timezone) { + let users = get_all_users(); + return utils::filter_by_property(users, "timezone", timezone); +} + +// Create a new user +fn create_user(name, email, timezone, notification_time, default_calendar_id) { + // Generate a simple ID (in a real app, we would use a proper ID generation method) + let id = "user" + (get_all_users().len() + 1).to_string(); + + let preferences = user_model::create_user_preferences( + notification_time, default_calendar_id + ); + + return user_model::create_user( + id, name, email, timezone, preferences + ); +} + +// Format user details for display +fn format_user(user) { + if utils::is_empty(user) { + return "User not found"; + } + + return `${user.name} (${user.email}) +Timezone: ${user.timezone} +Default Calendar: ${user.preferences.default_calendar_id} +Notification Time: ${user.preferences.notification_time} minutes before`; +} diff --git a/examples/calendar/backend/scripts/utils.rhai b/examples/calendar/backend/scripts/utils.rhai new file mode 100644 index 0000000..a7ef792 --- /dev/null +++ b/examples/calendar/backend/scripts/utils.rhai @@ -0,0 +1,84 @@ +// utils.rhai - Utility functions for the calendar backend + +// Function to find an item by ID in an array +fn find_by_id(array, id) { + for item in array { + if item.id == id { + return item; + } + } + return #{}; // Return empty object if not found +} + +// Function to filter array by a property value +fn filter_by_property(array, property, value) { + let result = []; + + for item in array { + if item[property] == value { + result.push(item); + } + } + + return result; +} + +// Function to check if an object is empty +fn is_empty(obj) { + if obj.type_of() == "object" { + return obj.keys().len() == 0; + } + if obj.type_of() == "array" { + return obj.len() == 0; + } + return false; +} + +// Function to format date string +fn format_date(date_str) { + // Simple formatting - in a real app, we would use proper date formatting + return date_str.substr(0, 10); +} + +// Function to format time string +fn format_time(date_str) { + // Simple formatting - in a real app, we would use proper time formatting + if date_str.len() >= 16 { + return date_str.substr(11, 5); + } + return ""; +} + +// Function to check if an array contains a value +fn array_contains(array, value) { + for item in array { + if item == value { + return true; + } + } + return false; +} + +// Function to get current date (simplified for demo) +fn get_current_date() { + return "2025-04-03"; +} + +// Function to calculate a future date (simplified for demo) +fn add_days_to_date(date_str, days) { + let year = date_str.substr(0, 4).parse_int(); + let month = date_str.substr(5, 2).parse_int(); + let day = date_str.substr(8, 2).parse_int() + days; + + // Very simplified date calculation - in a real app, we would handle month/year boundaries + if day > 30 { + day = day - 30; + month += 1; + } + if month > 12 { + month = 1; + year += 1; + } + + return `${year}-${month.to_string().pad_left(2, '0')}-${day.to_string().pad_left(2, '0')}`; +} diff --git a/examples/calendar/components/calendar/.cargo/config.toml b/examples/calendar/components/calendar/.cargo/config.toml new file mode 100644 index 0000000..63b6ada --- /dev/null +++ b/examples/calendar/components/calendar/.cargo/config.toml @@ -0,0 +1,2 @@ +[alias] +dev = "watch -w src -w examples -w src/templates -w src/scripts -x 'run --example server'" \ No newline at end of file diff --git a/examples/calendar/components/calendar/Cargo.lock b/examples/calendar/components/calendar/Cargo.lock new file mode 100644 index 0000000..21ebcd3 --- /dev/null +++ b/examples/calendar/components/calendar/Cargo.lock @@ -0,0 +1,1524 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "addr2line" +version = "0.24.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfbe277e56a376000877090da837660b4427aad530e3028d44e0bffe4f89a1c1" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler2" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" + +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "const-random", + "getrandom", + "once_cell", + "version_check", + "zerocopy 0.7.35", +] + +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "autocfg" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" + +[[package]] +name = "backtrace" +version = "0.3.74" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a" +dependencies = [ + "addr2line", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", + "windows-targets", +] + +[[package]] +name = "bitflags" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c8214115b7bf84099f1309324e63141d4c5d7cc26862f97a0a857dbefe165bd" + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "bstr" +version = "1.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "531a9155a481e2ee699d4f98f43c0ca4ff8ee1bfd55c31e9e98fb29d2b176fe0" +dependencies = [ + "memchr", + "serde", +] + +[[package]] +name = "bumpalo" +version = "3.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1628fb46dfa0b37568d12e5edd512553eccf6a22a78e8bde00bb4aed84d5bdbf" + +[[package]] +name = "bytes" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a" + +[[package]] +name = "calendar" +version = "0.1.0" +dependencies = [ + "http", + "httparse", + "hyper", + "once_cell", + "rhai", + "serde", + "serde_json", + "tera", + "tokio", +] + +[[package]] +name = "cc" +version = "1.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fcb57c740ae1daf453ae85f16e37396f672b039e00d9d866e07ddb24e328e3a" +dependencies = [ + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "chrono" +version = "0.4.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a7964611d71df112cb1730f2ee67324fcf4d0fc6606acbbe9bfe06df124637c" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "num-traits", + "windows-link", +] + +[[package]] +name = "chrono-tz" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93698b29de5e97ad0ae26447b344c482a7284c737d9ddc5f9e52b74a336671bb" +dependencies = [ + "chrono", + "chrono-tz-build", + "phf", +] + +[[package]] +name = "chrono-tz-build" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c088aee841df9c3041febbb73934cfc39708749bf96dc827e3359cd39ef11b1" +dependencies = [ + "parse-zoneinfo", + "phf", + "phf_codegen", +] + +[[package]] +name = "const-random" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87e00182fe74b066627d63b85fd550ac2998d4b0bd86bfed477a0ae4c7c71359" +dependencies = [ + "const-random-macro", +] + +[[package]] +name = "const-random-macro" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9d839f2a20b0aee515dc581a6172f2321f96cab76c1a38a4c584a194955390e" +dependencies = [ + "getrandom", + "once_cell", + "tiny-keccak", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cpufeatures" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" +dependencies = [ + "libc", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" + +[[package]] +name = "crunchy" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43da5946c66ffcc7745f48db692ffbb10a83bfe0afd96235c5c2a4fb23994929" + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "deunicode" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc55fe0d1f6c107595572ec8b107c0999bb1a2e0b75e37429a4fb0d6474a0e7d" + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", +] + +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "futures-channel" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" +dependencies = [ + "futures-core", +] + +[[package]] +name = "futures-core" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" + +[[package]] +name = "futures-sink" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" + +[[package]] +name = "futures-task" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" + +[[package]] +name = "futures-util" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" +dependencies = [ + "futures-core", + "futures-task", + "pin-project-lite", + "pin-utils", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "gimli" +version = "0.31.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" + +[[package]] +name = "globset" +version = "0.4.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54a1028dfc5f5df5da8a56a73e6c153c9a9708ec57232470703592a3f18e49f5" +dependencies = [ + "aho-corasick", + "bstr", + "log", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "globwalk" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf760ebf69878d9fd8f110c89703d90ce35095324d1f1edcb595c63945ee757" +dependencies = [ + "bitflags", + "ignore", + "walkdir", +] + +[[package]] +name = "h2" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81fe527a889e1532da5c525686d96d4c2e74cdd345badf8dfef9f6b39dd5f5e8" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "hashbrown" +version = "0.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" + +[[package]] +name = "http" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "601cbb57e577e2f5ef5be8e7b83f0f63994f25aa94d673e54a92d5c516d101f1" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" +dependencies = [ + "bytes", + "http", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" + +[[package]] +name = "httpdate" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" + +[[package]] +name = "humansize" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6cb51c9a029ddc91b07a787f1d86b53ccfa49b0e86688c946ebe8d3555685dd7" +dependencies = [ + "libm", +] + +[[package]] +name = "hyper" +version = "0.14.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41dfc780fdec9373c01bae43289ea34c972e40ee3c9f6b3c8801a35f35586ce7" +dependencies = [ + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", + "want", +] + +[[package]] +name = "iana-time-zone" +version = "0.1.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0c919e5debc312ad217002b8048a17b7d83f80703865bbfcfebb0458b0b27d8" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "log", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "ignore" +version = "0.4.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d89fd380afde86567dfba715db065673989d6253f42b88179abd3eae47bda4b" +dependencies = [ + "crossbeam-deque", + "globset", + "log", + "memchr", + "regex-automata", + "same-file", + "walkdir", + "winapi-util", +] + +[[package]] +name = "indexmap" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3954d50fe15b02142bf25d3b8bdadb634ec3948f103d04ffe3031bc8fe9d7058" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "instant" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0242819d153cba4b4b05a5a8f2a7e9bbf97b6055b2a002b395c96b5ff3c0222" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "itoa" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" + +[[package]] +name = "js-sys" +version = "0.3.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f" +dependencies = [ + "once_cell", + "wasm-bindgen", +] + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "libc" +version = "0.2.171" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c19937216e9d3aa9956d9bb8dfc0b0c8beb6058fc4f7a4dc4d850edf86a237d6" + +[[package]] +name = "libm" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8355be11b20d696c8f18f6cc018c4e372165b1fa8126cef092399c9951984ffa" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "miniz_oxide" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e3e04debbb59698c15bacbb6d93584a8c0ca9cc3213cb423d31f760d8843ce5" +dependencies = [ + "adler2", +] + +[[package]] +name = "mio" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2886843bf800fba2e3377cff24abf6379b4c4d5c6681eaf9ea5b0d15090450bd" +dependencies = [ + "libc", + "wasi", + "windows-sys", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "object" +version = "0.36.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62948e14d923ea95ea2c7c86c71013138b66525b86bdc08d2dcc262bdb497b87" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" +dependencies = [ + "portable-atomic", +] + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets", +] + +[[package]] +name = "parse-zoneinfo" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f2a05b18d44e2957b88f96ba460715e295bc1d7510468a2f3d3b44535d26c24" +dependencies = [ + "regex", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "pest" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "198db74531d58c70a361c42201efde7e2591e976d518caf7662a47dc5720e7b6" +dependencies = [ + "memchr", + "thiserror", + "ucd-trie", +] + +[[package]] +name = "pest_derive" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d725d9cfd79e87dccc9341a2ef39d1b6f6353d68c4b33c177febbe1a402c97c5" +dependencies = [ + "pest", + "pest_generator", +] + +[[package]] +name = "pest_generator" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db7d01726be8ab66ab32f9df467ae8b1148906685bbe75c82d1e65d7f5b3f841" +dependencies = [ + "pest", + "pest_meta", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pest_meta" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f9f832470494906d1fca5329f8ab5791cc60beb230c74815dff541cbd2b5ca0" +dependencies = [ + "once_cell", + "pest", + "sha2", +] + +[[package]] +name = "phf" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd6780a80ae0c52cc120a26a1a42c1ae51b247a253e4e06113d23d2c2edd078" +dependencies = [ + "phf_shared", +] + +[[package]] +name = "phf_codegen" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aef8048c789fa5e851558d709946d6d79a8ff88c0440c587967f8e94bfb1216a" +dependencies = [ + "phf_generator", + "phf_shared", +] + +[[package]] +name = "phf_generator" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c80231409c20246a13fddb31776fb942c38553c51e871f8cbd687a4cfb5843d" +dependencies = [ + "phf_shared", + "rand", +] + +[[package]] +name = "phf_shared" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67eabc2ef2a60eb7faa00097bd1ffdb5bd28e62bf39990626a582201b7a754e5" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "portable-atomic" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "350e9b48cbc6b0e028b0473b114454c6316e57336ee184ceab6e53f72c178b3e" + +[[package]] +name = "ppv-lite86" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" +dependencies = [ + "zerocopy 0.8.24", +] + +[[package]] +name = "proc-macro2" +version = "1.0.94" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a31971752e70b8b2686d7e46ec17fb38dad4051d94024c88df49b667caea9c84" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.5.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b8c0c260b63a8219631167be35e6a988e9554dbd323f8bd08439c8ed1302bd1" +dependencies = [ + "bitflags", +] + +[[package]] +name = "regex" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" + +[[package]] +name = "rhai" +version = "1.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce4d759a4729a655ddfdbb3ff6e77fb9eadd902dae12319455557796e435d2a6" +dependencies = [ + "ahash", + "bitflags", + "instant", + "num-traits", + "once_cell", + "rhai_codegen", + "serde", + "smallvec", + "smartstring", + "thin-vec", +] + +[[package]] +name = "rhai_codegen" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5a11a05ee1ce44058fa3d5961d05194fdbe3ad6b40f904af764d81b86450e6b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustversion" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eded382c5f5f786b989652c49544c4877d9f015cc22e145a5ea8ea66c2921cd2" + +[[package]] +name = "ryu" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "serde" +version = "1.0.219" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.219" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.140" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "sha2" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] + +[[package]] +name = "siphasher" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56199f7ddabf13fe5074ce809e7d3f42b42ae711800501b5b16ea82ad029c39d" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "slug" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "882a80f72ee45de3cc9a5afeb2da0331d58df69e4e7d8eeb5d3c7784ae67e724" +dependencies = [ + "deunicode", + "wasm-bindgen", +] + +[[package]] +name = "smallvec" +version = "1.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fcf8323ef1faaee30a44a340193b1ac6814fd9b7b4e88e9d4519a3e4abe1cfd" +dependencies = [ + "serde", +] + +[[package]] +name = "smartstring" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fb72c633efbaa2dd666986505016c32c3044395ceaf881518399d2f4127ee29" +dependencies = [ + "autocfg", + "serde", + "static_assertions", + "version_check", +] + +[[package]] +name = "socket2" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f5fd57c80058a56cf5c777ab8a126398ece8e442983605d280a44ce79d0edef" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + +[[package]] +name = "syn" +version = "2.0.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tera" +version = "1.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab9d851b45e865f178319da0abdbfe6acbc4328759ff18dafc3a41c16b4cd2ee" +dependencies = [ + "chrono", + "chrono-tz", + "globwalk", + "humansize", + "lazy_static", + "percent-encoding", + "pest", + "pest_derive", + "rand", + "regex", + "serde", + "serde_json", + "slug", + "unic-segment", +] + +[[package]] +name = "thin-vec" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "144f754d318415ac792f9d69fc87abbbfc043ce2ef041c60f16ad828f638717d" +dependencies = [ + "serde", +] + +[[package]] +name = "thiserror" +version = "2.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tiny-keccak" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" +dependencies = [ + "crunchy", +] + +[[package]] +name = "tokio" +version = "1.44.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f382da615b842244d4b8738c82ed1275e6c5dd90c459a30941cd07080b06c91a" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys", +] + +[[package]] +name = "tokio-macros" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e06d43f1345a3bcd39f6a56dbb7dcab2ba47e68e8ac134855e7e2bdbaf8cab8" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tokio-util" +version = "0.7.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b9590b93e6fcc1739458317cccd391ad3955e2bde8913edf6f95f9e65a8f034" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e672c95779cf947c5311f83787af4fa8fffd12fb27e4993211a84bdfd9610f9c" +dependencies = [ + "once_cell", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "typenum" +version = "1.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1dccffe3ce07af9386bfd29e80c0ab1a8205a2fc34e4bcd40364df902cfa8f3f" + +[[package]] +name = "ucd-trie" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2896d95c02a80c6d6a5d6e953d479f5ddf2dfdb6a244441010e373ac0fb88971" + +[[package]] +name = "unic-char-property" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8c57a407d9b6fa02b4795eb81c5b6652060a15a7903ea981f3d723e6c0be221" +dependencies = [ + "unic-char-range", +] + +[[package]] +name = "unic-char-range" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0398022d5f700414f6b899e10b8348231abf9173fa93144cbc1a43b9793c1fbc" + +[[package]] +name = "unic-common" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80d7ff825a6a654ee85a63e80f92f054f904f21e7d12da4e22f9834a4aaa35bc" + +[[package]] +name = "unic-segment" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4ed5d26be57f84f176157270c112ef57b86debac9cd21daaabbe56db0f88f23" +dependencies = [ + "unic-ucd-segment", +] + +[[package]] +name = "unic-ucd-segment" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2079c122a62205b421f499da10f3ee0f7697f012f55b675e002483c73ea34700" +dependencies = [ + "unic-char-property", + "unic-char-range", + "unic-ucd-version", +] + +[[package]] +name = "unic-ucd-version" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96bd2f2237fe450fcd0a1d2f5f4e91711124f7857ba2e964247776ebeeb7b0c4" +dependencies = [ + "unic-common", +] + +[[package]] +name = "unicode-ident" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6" +dependencies = [ + "bumpalo", + "log", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "winapi-util" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "windows-core" +version = "0.61.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4763c1de310c86d75a878046489e2e5ba02c649d185f21c67d4cf8a56d098980" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-implement" +version = "0.60.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a47fddd13af08290e67f4acabf4b459f647552718f683a7b415d290ac744a836" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-interface" +version = "0.59.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd9211b69f8dcdfa817bfd14bf1c97c9188afa36f4750130fcdf3f400eca9fa8" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-link" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76840935b766e1b0a05c0066835fb9ec80071d4c09a16f6bd5f7e655e3c14c38" + +[[package]] +name = "windows-result" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c64fd11a4fd95df68efcfee5f44a294fe71b8bc6a91993e2791938abcc712252" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-strings" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a2ba9642430ee452d5a7aa78d72907ebe8cfda358e8cb7918a2050581322f97" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "zerocopy-derive 0.7.35", +] + +[[package]] +name = "zerocopy" +version = "0.8.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2586fea28e186957ef732a5f8b3be2da217d65c5969d4b1e17f973ebbe876879" +dependencies = [ + "zerocopy-derive 0.8.24", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a996a8f63c5c4448cd959ac1bab0aaa3306ccfd060472f85943ee0750f0169be" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] diff --git a/examples/calendar/components/calendar/Cargo.toml b/examples/calendar/components/calendar/Cargo.toml new file mode 100644 index 0000000..e73a4c5 --- /dev/null +++ b/examples/calendar/components/calendar/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "calendar" +version = "0.1.0" +edition = "2021" + +[dependencies] +hyper = { version = "0.14", features = ["full"] } +tokio = { version = "1", features = ["full"] } +http = "0.2" +httparse = "1" +rhai = { version = "1.21", features = ["serde"] } +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" +tera = "1.0" +once_cell = "1" \ No newline at end of file diff --git a/examples/calendar/components/calendar/README.md b/examples/calendar/components/calendar/README.md new file mode 100644 index 0000000..3766fd9 --- /dev/null +++ b/examples/calendar/components/calendar/README.md @@ -0,0 +1,51 @@ +# Calendar Server Example + +A simple Rust web server using Hyper that exposes an `/all_calendars` endpoint. + +## Running the server + +```bash +# Navigate to the examples directory +cd /path/to/examples + +# Build and run the server +cargo run +``` + +Once the server is running, you can access the endpoint at: +- http://127.0.0.1:8080/all_calendars + +## Features +- Simple HTTP server using Hyper +- Single endpoint that returns "Hello World" + + +Sure thing! Here’s the Markdown version you can copy-paste directly into your README.md: + +## πŸ” Live Reload (Hot Reload for Development) + +To automatically recompile and restart your example server on file changes (e.g. Rust code, templates, Rhai scripts), you can use [`cargo-watch`](https://github.com/watchexec/cargo-watch): + +### βœ… Step 1: Install `cargo-watch` + +```bash +cargo install cargo-watch +``` + +### βœ… Step 2: Run the server with live reload + +cargo watch -x 'run --example server' + +This will: + β€’ Watch for file changes in your project + β€’ Rebuild and re-run examples/server.rs whenever you make a change + +### 🧠 Bonus: Watch additional folders + +To also reload when .tera templates or .rhai scripts change: + +cargo watch -w src -w examples -w src/templates -w src/scripts -x 'run --example server' + +### πŸ’‘ Optional: Clear terminal on each reload + +cargo watch -c -x 'run --example server' \ No newline at end of file diff --git a/examples/calendar/components/calendar/develop.sh b/examples/calendar/components/calendar/develop.sh new file mode 100755 index 0000000..89f807f --- /dev/null +++ b/examples/calendar/components/calendar/develop.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +set -e + +# πŸš€ Start dev server with file watching and browser reload +reloadd \ + --watch src \ + --watch src/templates \ + --watch examples \ + -- run --example server \ No newline at end of file diff --git a/examples/calendar/components/calendar/examples/server.rs b/examples/calendar/components/calendar/examples/server.rs new file mode 100644 index 0000000..92e8df8 --- /dev/null +++ b/examples/calendar/components/calendar/examples/server.rs @@ -0,0 +1,114 @@ +use hyper::{Body, Request, Response, Server}; +use hyper::service::{make_service_fn, service_fn}; +use hyper::{Method, StatusCode}; +use std::convert::Infallible; +use std::net::SocketAddr; +use tokio::io::{AsyncReadExt, AsyncWriteExt}; +use tokio::process::Command; +use httparse; + +async fn handle_request(req: Request) -> Result, Infallible> { + // Serialize request into raw HTTP format + let raw_request = build_raw_http_request(req).await; + + // Spawn the binary + let mut child = Command::new("./target/debug/calendar") + .stdin(std::process::Stdio::piped()) + .stdout(std::process::Stdio::piped()) + .spawn() + .expect("failed to spawn binary"); + + // Feed raw HTTP request to binary's stdin + if let Some(mut stdin) = child.stdin.take() { + let _ = stdin.write_all(&raw_request).await; + } + + // Read response from binary's stdout + let mut stdout = child.stdout.take().expect("no stdout"); + let mut output = Vec::new(); + let _ = stdout.read_to_end(&mut output).await; + + let _ = child.wait().await; + + // Parse raw HTTP response + match parse_raw_http_response(&output) { + Ok(res) => Ok(res), + Err(e) => { + let mut resp = Response::new(Body::from(format!("Failed to parse response: {}", e))); + *resp.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + Ok(resp) + } + } +} + +// Build raw HTTP request string +async fn build_raw_http_request(req: Request) -> Vec { + let mut raw = String::new(); + + let method = req.method(); + let path = req.uri().path(); + let version = match req.version() { + hyper::Version::HTTP_11 => "HTTP/1.1", + _ => "HTTP/1.1", + }; + + raw.push_str(&format!("{method} {path} {version}\r\n")); + + for (key, value) in req.headers() { + if let Ok(val_str) = value.to_str() { + raw.push_str(&format!("{}: {}\r\n", key, val_str)); + } + } + + raw.push_str("\r\n"); + + let body_bytes = hyper::body::to_bytes(req.into_body()).await.unwrap_or_default(); + let mut full = raw.into_bytes(); + full.extend_from_slice(&body_bytes); + + full +} + +// Parse raw HTTP response into hyper::Response +fn parse_raw_http_response(bytes: &[u8]) -> Result, Box> { + let mut headers = [httparse::EMPTY_HEADER; 64]; + let mut res = httparse::Response::new(&mut headers); + let parsed_len = res.parse(bytes)?.unwrap(); // returns offset + + let status = res.code.unwrap_or(200); + let mut builder = Response::builder().status(status); + + for h in res.headers.iter() { + builder = builder.header(h.name, std::str::from_utf8(h.value)?); + } + + // Get body and append LiveReload script + let mut body = bytes[parsed_len..].to_vec(); + let livereload_snippet = br#""#; + body.extend_from_slice(b"\n"); + body.extend_from_slice(livereload_snippet); + + Ok(builder.body(Body::from(body))?) +} + +#[tokio::main] +async fn main() { + let addr = SocketAddr::from(([127, 0, 0, 1], 8080)); + + let make_svc = make_service_fn(|_conn| async { + Ok::<_, Infallible>(service_fn(handle_request)) + }); + + println!("Proxy server running at http://{}", addr); + + if let Err(e) = Server::bind(&addr).serve(make_svc).await { + eprintln!("server error: {}", e); + } +} + + diff --git a/examples/calendar/components/calendar/src/controller/calendar.rs b/examples/calendar/components/calendar/src/controller/calendar.rs new file mode 100644 index 0000000..7364856 --- /dev/null +++ b/examples/calendar/components/calendar/src/controller/calendar.rs @@ -0,0 +1,121 @@ +use rhai::{Engine, Scope, Array, Dynamic, AST}; +use hyper::{Request, Body, Response, StatusCode}; +use std::collections::HashMap; +use tera::{Function as TeraFunction, Value, to_value, Result as TeraResult}; +use tera::Tera; +use std::path::PathBuf; +use serde_json; +use once_cell::sync::Lazy; + +pub fn get_calendars(_req: Request) -> Response { + let engine = Engine::new(); + + // Compile the script + let ast = match engine.compile_file( + "/Users/timurgordon/code/git.ourworld.tf/herocode/rhaj/examples/calendar/backend/scripts/calendars.rhai".into() + ) { + Ok(ast) => ast, + Err(e) => { + let mut res = Response::new(Body::from(format!("Rhai compile error: {}", e))); + *res.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + return res; + } + }; + + let mut scope = Scope::new(); + + + let tera = setup_tera_with_rhai(); + + let context = tera::Context::new(); // no need to pass data β€” we're calling the Rhai function inside + + let rendered = match tera.render("get_calendars.html.tera", &context) { + Ok(html) => Response::new(Body::from(html)), + Err(err) => { + // πŸ” Print the full error with source + eprintln!("Template render error: {:?}", err); // or use err.to_string() for cleaner message + + let mut res = Response::new(Body::from(format!("Template error: {}", err))); + *res.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + res + } + }; + + rendered +} + +// pub fn get_calendars(_req: Request) -> Response { +// let engine = Engine::new(); + +// // Compile the script +// let ast = match engine.compile_file( +// "/Users/timurgordon/code/git.ourworld.tf/herocode/rhaj/examples/calendar/backend/scripts/calendars.rhai".into() +// ) { +// Ok(ast) => ast, +// Err(e) => { +// let mut res = Response::new(Body::from(format!("Rhai compile error: {}", e))); +// *res.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; +// return res; +// } +// }; + +// let mut scope = Scope::new(); + +// // Call the function in the Rhai script +// match engine.call_fn::(&mut scope, &ast, "get_calendars", ()) { +// Ok(result) => { +// // Convert array to string representation +// let response_text = format!("{:?}", result); +// Response::new(Body::from(response_text)) +// }, +// Err(e) => { +// let mut res = Response::new(Body::from(format!("Rhai call error: {}", e))); +// *res.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; +// res +// } +// } +// } + +pub struct RhaiFunctionAdapter { + fn_name: String, + script_path: PathBuf, +} + +impl TeraFunction for RhaiFunctionAdapter { + fn call(&self, args: &HashMap) -> TeraResult { + let mut scope = Scope::new(); + + // Convert args from Tera into Rhai's Dynamic + for (key, value) in args { + let json_str = serde_json::to_string(value).unwrap(); + let json_value: serde_json::Value = serde_json::from_str(&json_str).unwrap(); + let dynamic = rhai::serde::to_dynamic(json_value).unwrap(); + scope.push_dynamic(key.clone(), dynamic); + } + + // Build engine and compile AST inside call (safe) + let engine = Engine::new(); + let ast = engine + .compile_file(self.script_path.clone()) + .map_err(|e| tera::Error::msg(format!("Rhai compile error: {}", e)))?; + + let result = engine + .call_fn::(&mut scope, &ast, &self.fn_name, ()) + .map_err(|e| tera::Error::msg(format!("Rhai error: {}", e)))?; + + let tera_value = rhai::serde::from_dynamic(&result).unwrap(); + Ok(tera_value) + } +} + +fn setup_tera_with_rhai() -> Tera { + let mut tera = Tera::new("src/templates/**/*").unwrap(); + + let adapter = RhaiFunctionAdapter { + fn_name: "get_calendars".into(), + script_path: PathBuf::from("../../backend/scripts/calendars.rhai"), + }; + + tera.register_function("get_calendars", adapter); + tera +} \ No newline at end of file diff --git a/examples/calendar/components/calendar/src/main.rs b/examples/calendar/components/calendar/src/main.rs new file mode 100644 index 0000000..9f7d1b0 --- /dev/null +++ b/examples/calendar/components/calendar/src/main.rs @@ -0,0 +1,69 @@ +mod controller { + pub mod calendar; +} + +use controller::calendar; + +use hyper::{Body, Method, Request, Response, StatusCode}; +use std::convert::Infallible; +use std::io::{self, Read}; + +#[tokio::main] +async fn main() -> Result<(), Box> { + let input = read_request_from_stdin()?; + let request = parse_http_request(&input)?; + let response = handle_request(request).await?; + print_http_response(response).await; + Ok(()) +} + +fn read_request_from_stdin() -> io::Result { + let mut buffer = String::new(); + io::stdin().read_to_string(&mut buffer)?; + Ok(buffer) +} + +fn parse_http_request(input: &str) -> Result, Box> { + let mut headers = [httparse::EMPTY_HEADER; 32]; + let mut req = httparse::Request::new(&mut headers); + + let bytes = input.as_bytes(); + let parsed_len = req.parse(bytes)?.unwrap(); + + let method = req.method.ok_or("missing method")?.parse::()?; + let path = req.path.ok_or("missing path")?; + let uri = path.parse::()?; + + let body = &bytes[parsed_len..]; + let request = Request::builder() + .method(method) + .uri(uri) + .body(Body::from(body.to_vec()))?; + + Ok(request) +} + +async fn handle_request(req: Request) -> Result, Infallible> { + match (req.method(), req.uri().path()) { + (&Method::GET, "/calendars") => Ok(calendar::get_calendars(req)), + _ => { + let mut res = Response::new(Body::from("Not Found")); + *res.status_mut() = StatusCode::NOT_FOUND; + Ok(res) + } + } +} + +async fn print_http_response(res: Response) { + println!("HTTP/1.1 {}", res.status()); + + for (key, value) in res.headers() { + println!("{}: {}", key, value.to_str().unwrap_or_default()); + } + + println!(); // blank line before body + + let body_bytes = hyper::body::to_bytes(res.into_body()).await.unwrap(); + let body = String::from_utf8_lossy(&body_bytes); + println!("{}", body); +} \ No newline at end of file diff --git a/examples/calendar/components/calendar/src/templates/get_calendars.html.tera b/examples/calendar/components/calendar/src/templates/get_calendars.html.tera new file mode 100644 index 0000000..aba9cc9 --- /dev/null +++ b/examples/calendar/components/calendar/src/templates/get_calendars.html.tera @@ -0,0 +1,16 @@ +

Calendars

+
    +{% for cal in get_calendars() %} +
  • +
    +
    +

    {{ cal.name }}

    +

    {{ cal.description }}

    +
    + +
    +
  • +{% endfor %} +
\ No newline at end of file