otter-engine 0.1.3

Otter JavaScript engine
docs.rs failed to build otter-engine-0.1.3
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.

otter-engine

ESM module loader and capability-based security for Otter.

Overview

otter-engine provides the module loading infrastructure for the Otter runtime:

  • ESM module loading from file://, node:, and https:// URLs
  • Dependency graph with cycle detection
  • Capability-based security model
  • Automatic TypeScript transpilation
  • Import maps support

Usage

Add to your Cargo.toml:

[dependencies]
otter-engine = "0.1"

Module Loading

use otter_engine::{ModuleLoader, ModuleGraph, LoaderConfig};
use std::sync::Arc;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let config = LoaderConfig::default();
    let loader = Arc::new(ModuleLoader::new(config));
    let mut graph = ModuleGraph::new(loader);

    // Load a module and its dependencies
    graph.load("file:///path/to/main.ts").await?;

    // Get execution order (topologically sorted)
    for url in graph.execution_order() {
        println!("Execute: {}", url);
    }

    Ok(())
}

Capability-Based Security

use otter_engine::{Capabilities, CapabilitiesBuilder};
use std::path::PathBuf;

let caps = CapabilitiesBuilder::new()
    .allow_read([PathBuf::from("/app/src")])
    .allow_net(["api.example.com".to_string()])
    .allow_env(["NODE_ENV".to_string()])
    .build();

// Check permissions
if caps.can_read("/app/src/main.ts") {
    // allowed
}

// Or require permission (returns error if denied)
caps.require_net("api.example.com")?;

License

MIT