1use graphrt_core::Registry;
4use graphrt_wasm::{WasmLimits, WasmPlugin};
5
6use crate::bundle::Bundle;
7use crate::error::BundleError;
8
9impl Bundle {
10 pub fn register_wasm_plugins(
21 &self,
22 registry: &mut Registry,
23 limits: &WasmLimits,
24 ) -> Result<Vec<String>, BundleError> {
25 let mut kinds = Vec::new();
26 for plugin in self.wasm_plugins()? {
27 let err = |message: String| BundleError::Plugin { plugin: plugin.name.clone(), message };
28 let module = plugin.module.as_deref().ok_or_else(|| err("missing module".into()))?;
29 let wasm =
30 WasmPlugin::load(module, limits.clone().with_expose_secrets(false)).map_err(|e| err(e.to_string()))?;
31 let allow_plain =
32 plugin.manifest.get("allow_unprefixed_kinds").and_then(serde_json::Value::as_bool).unwrap_or(false);
33 let prefix = format!("{}.", plugin.name);
34 for descriptor in wasm.descriptors() {
35 let plain = allow_plain && !descriptor.kind.contains('.');
36 if !descriptor.kind.starts_with(&prefix) && !plain {
37 return Err(err(format!(
38 "node kind `{}` must start with `{prefix}` (or be a plain name with `allow_unprefixed_kinds`)",
39 descriptor.kind
40 )));
41 }
42 }
43 let descriptors = wasm.descriptors();
44 if !descriptors.is_empty() && descriptors.iter().all(|d| registry.contains(&d.kind)) {
45 continue;
46 }
47 wasm.register(registry).map_err(|e| err(e.to_string()))?;
48 kinds.extend(wasm.descriptors().into_iter().map(|d| d.kind));
49 }
50 Ok(kinds)
51 }
52}