Lines
100 %
Functions
60 %
Branches
//! Canonical host-fn registry for the 32 server commands.
//!
//! Each domain owns a submodule that mirrors the `server::command::*` shape and
//! holds one file per server command. Commands register their host fn through a
//! per-domain `register` entry point; the top-level `register_all` aggregates
//! every domain so a wasmtime [`Linker`] gains the full
//! canonical surface in one call.
//! Subsequent commits fill each domain. This commit lays down the directory
//! shape so per-command commits stay focused on one server command at a time.
use scripting::runtime::{alloc_pair_chain, alloc_string_ref};
use wasmtime::{AnyRef, ArrayRef, Caller, Linker, Rooted, StructRef};
use crate::session::SessionData;
/// One stringly-typed wasm host-fn argument as it lands on the
/// `linker.func_wrap_async` closure: nullable because the arg can be
/// absent, `Rooted<ArrayRef>` because the wasm side encodes strings as
/// `(ref null $i8_array)`.
pub(crate) type StringArg = Option<Rooted<ArrayRef>>;
/// Three-arg tuple shape used by `account_set_account_tag` and other
/// host fns that take three string args.
pub(crate) type StringArgTriple = (StringArg, StringArg, StringArg);
/// Allocates a `pair:string` chain from host strings.
pub(crate) async fn alloc_string_pair_chain(
caller: &mut Caller<'_, SessionData>,
lines: Vec<String>,
) -> wasmtime::Result<Option<Rooted<StructRef>>> {
let mut anyrefs: Vec<Option<Rooted<AnyRef>>> = Vec::with_capacity(lines.len());
for line in lines {
let s = alloc_string_ref(caller, line.as_bytes())?;
anyrefs.push(Some(s.to_anyref()));
}
alloc_pair_chain(caller, anyrefs).await
pub mod account;
mod args;
pub mod catch_each;
pub mod chart;
pub mod commodity;
pub mod config;
pub mod date;
pub mod env_io;
pub mod forms;
mod generated_specs;
pub mod meta;
pub(crate) mod native;
pub mod raise;
mod render;
pub mod report;
pub mod script_store;
pub mod split;
pub mod ssh_key;
pub mod tag;
pub mod template;
pub mod template_store;
pub mod transaction;
pub use generated_specs::all_compiler_specs;
pub use render::{RENDER_NATIVE_ALLOWLIST, link_render, render_compiler_specs};
/// Aggregator: registers every domain's host fns on `linker` in one call.
/// Bound to [`SessionData`] now that `meta` natives consult `ScriptCtx`
/// (user_id) — generic-T register fns from the empty per-domain modules
/// still satisfy this concrete type because they don't touch the Store data.
pub fn link(linker: &mut Linker<SessionData>) -> wasmtime::Result<()> {
meta::register(linker)?;
env_io::register(linker)?;
raise::register(linker)?;
catch_each::register(linker)?;
chart::register(linker)?;
account::register(linker)?;
commodity::register(linker)?;
config::register(linker)?;
date::register(linker)?;
forms::register(linker)?;
report::register(linker)?;
split::register(linker)?;
ssh_key::register(linker)?;
tag::register(linker)?;
script_store::register(linker)?;
template_store::register(linker)?;
template::register(linker)?;
transaction::register(linker)?;
Ok(())
// `all_compiler_specs` lives in `generated_specs` (tangled from
// `doc/scripting/native_reference.org` by `rpc/build.rs`) — see the
// `pub use` import above. Adding or modifying a native means editing
// the org table; cargo build regenerates the Rust.
#[must_use]
pub fn all_registered_commands() -> Vec<&'static str> {
[
account::REGISTERED_COMMANDS,
chart::REGISTERED_COMMANDS,
commodity::REGISTERED_COMMANDS,
config::REGISTERED_COMMANDS,
date::REGISTERED_COMMANDS,
forms::REGISTERED_COMMANDS,
report::REGISTERED_COMMANDS,
split::REGISTERED_COMMANDS,
script_store::REGISTERED_COMMANDS,
ssh_key::REGISTERED_COMMANDS,
tag::REGISTERED_COMMANDS,
template_store::REGISTERED_COMMANDS,
transaction::REGISTERED_COMMANDS,
]
.iter()
.flat_map(|d| d.iter().copied())
.collect()
#[cfg(test)]
#[path = "tests_registry.rs"]
mod tests;