Adds the v1.1.0 user-visible stdlib: regex, random, time, json, base64, hex, url — each exposed as a `::` namespace mirroring the existing `log::` pattern. Modules register once at engine build via `Engine::register_static_module`, distinct from the stateful service modules (KV, docs, …) that hook into `sdk::register_all` per call. - regex: linear-time, compile-per-call (no cache by design) - random: OsRng only; bytes/string capped to prevent script-side blow-up - time: UTC, ms-since-epoch as canonical i64; RFC 3339 strings for I/O - json: parse/stringify via existing dynamic<->json bridge - base64: standard + URL-safe alphabets, Blob and String inputs - hex: lowercase output, case-insensitive decode - url: RFC 3986 percent-encoding + encode_query for Maps Stdlib registration runs unconditionally — including in the parse-only validate path — so scripts get a uniform surface in both phases. See docs/sdk-shape.md for the stateless-vs-stateful distinction. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
41 lines
1.7 KiB
Rust
41 lines
1.7 KiB
Rust
//! SDK plumbing — types and the per-call registration entry point.
|
|
//!
|
|
//! `executor-core` is responsible for building the per-invocation Rhai
|
|
//! engine and wiring stateful services into it. v1.1.0 ships the
|
|
//! shapes (`Services` bundle, `SdkCallCx`, `register_all` entry point)
|
|
//! but no actual services — subsequent v1.1.x PRs (KV in v1.1.1,
|
|
//! docs in v1.1.2, …) extend `register_all` rather than re-threading
|
|
//! plumbing through `engine.rs`.
|
|
//!
|
|
//! Bridge functions (`json_to_dynamic` / `dynamic_to_json`) also live
|
|
//! here so service modules can convert values without `engine.rs`
|
|
//! being the only home for the conversion logic.
|
|
|
|
pub mod bridge;
|
|
pub mod cx;
|
|
pub mod stdlib;
|
|
|
|
pub use bridge::{dynamic_to_json, json_to_dynamic};
|
|
pub use cx::SdkCallCx;
|
|
|
|
use std::sync::Arc;
|
|
|
|
use picloud_shared::Services;
|
|
use rhai::Engine as RhaiEngine;
|
|
|
|
/// Single hook every v1.1.x stateful service registers into. Called
|
|
/// once per invocation, just after `build_engine` constructs the
|
|
/// sandboxed Rhai engine and just before script compilation.
|
|
///
|
|
/// v1.1.0 ships an intentionally empty body — the call site exists so
|
|
/// future PRs (KV first) drop their registration logic here rather
|
|
/// than reaching into `engine.rs::build_engine`. The signature is
|
|
/// locked: subsequent PRs MUST keep the same parameter shape so that
|
|
/// hosts don't have to re-thread the plumbing.
|
|
pub fn register_all(engine: &mut RhaiEngine, services: &Services, cx: Arc<SdkCallCx>) {
|
|
// Intentionally inert in v1.1.0. The unused-suppression below is a
|
|
// load-bearing placeholder: future PRs replace this `let _` with
|
|
// real `register_kv(engine, services, cx.clone())` calls etc.
|
|
let _ = (engine, services, cx);
|
|
}
|