feat(wasm): execute client handlers without requests

req: client_local/001\nreq: client_local/004\nreq: client_local/005\nreq: client_local/009\nreq: client_local/010\nreq: client_local/014\nreq: v1_release/001
This commit is contained in:
slhx agent
2026-07-13 12:33:54 +02:00
parent 0d49007c61
commit 40643e360d
16 changed files with 515 additions and 25 deletions
+42
View File
@@ -0,0 +1,42 @@
//! Opt-in browser boundary for client-local hemx handlers.
//!
//! Application code reaches this crate through the `hemx` `client` feature and
//! `#[hemx::handler(client)]`; server-first applications do not depend on it.
use hemx_core::{BuildFingerprint, IntoEffect};
#[doc(hidden)]
pub use wasm_bindgen::prelude::wasm_bindgen;
#[doc(hidden)]
pub use wasm_bindgen::*;
/// Encodes a client handler result with the ordinary hemx effect wire format.
///
/// Keeping this conversion here gives generated WASM exports one ABI boundary
/// instead of teaching the proc macro a second effect protocol.
#[doc(hidden)]
pub fn encode_handler_effect(effect: impl IntoEffect, fingerprint: BuildFingerprint) -> Vec<u8> {
effect.into_batch(fingerprint).to_wire()
}
#[cfg(test)]
mod tests {
use super::encode_handler_effect;
use hemx_core::{BuildFingerprint, EffectBatch, Slot};
#[test]
fn client_handler_uses_the_ordinary_effect_wire_format() {
let fingerprint = BuildFingerprint(17);
let effect = Slot::<()>::new(4).text("local");
let wire = encode_handler_effect(effect.clone(), fingerprint);
assert_eq!(
EffectBatch::from_wire(&wire).expect("decode client effect"),
EffectBatch {
abi_version: hemx_core::EFFECT_BATCH_ABI_VERSION,
fingerprint,
ops: vec![effect],
}
); // req: client_local/005 req: client_local/009
}
}