camel_language_js/lib.rs
1//! JavaScript language plugin for Apache Camel Rust.
2//!
3//! Provides [`JsLanguage`] — a [`Language`](camel_language_api::Language) implementation
4//! backed by the [Boa](https://boajs.dev) JavaScript engine.
5//!
6//! # Resource Limits
7//!
8//! Scripts are bounded by configurable limits sourced from `[languages.js.limits]`
9//! in `Camel.toml`. When absent, rust-camel runtime defaults apply:
10//!
11//! | Limit | Default | Source |
12//! |---|---|---|
13//! | `execution-timeout-ms` | 5,000 | `tokio::time::timeout` + `spawn_blocking` |
14//! | `max-loop-iterations` | 100,000 | Boa `RuntimeLimits::set_loop_iteration_limit` |
15//! | `max-recursion-depth` | 512 | Boa `RuntimeLimits::set_recursion_limit` |
16//! | `max-stack-size` | 10,240 slots | Boa `RuntimeLimits::set_stack_size_limit` |
17//!
18//! ## Covered threats
19//!
20//! - Infinite loops (`while (true) {}`) — trip `max-loop-iterations`.
21//! - Deep recursion — trips `max-recursion-depth`.
22//! - Stack exhaustion — trips `max-stack-size`.
23//! - Wall-clock stalls — bounded by `execution-timeout-ms`.
24//!
25//! ## NOT covered
26//!
27//! **Heap cap** — `boa_engine` 0.21 does not expose a heap-size limit. A script
28//! that allocates many small objects can exhaust process memory before any other
29//! limit trips. Route authors writing JS that allocates heavily should validate
30//! their scripts carefully; untrusted JS should use `function:` (ADR-0005,
31//! out-of-process) instead of `js:`/`javascript:`.
32//!
33//! ## Timeout caveat
34//!
35//! Same as Rhai: when `execution-timeout-ms` fires, the route future resolves
36//! to an error, but the blocking thread may continue executing until a
37//! `RuntimeLimits` bound trips or the script finishes.
38
39pub mod engines;
40pub mod error;
41pub mod value;
42
43mod bindings;
44mod engine;
45mod expression;
46mod language;
47
48pub use engine::{JsEngine, JsEvalResult, JsExchange};
49pub use engines::BoaEngine;
50pub use error::JsLanguageError;
51pub use language::JsLanguage;