Crate mockforge_plugin_core

Crate mockforge_plugin_core 

Source
Expand description

§MockForge Plugin Core

Core traits, types, and runtime interfaces for the MockForge plugin system.

This crate provides the foundational abstractions for building MockForge plugins, including custom authentication handlers, data sources, response generators, and template token resolvers.

§Overview

MockForge uses a WebAssembly-based plugin system that allows developers to extend its functionality without modifying the core application. Plugins are sandboxed for security and can be loaded/unloaded at runtime.

§Plugin Types

The plugin system supports several categories of plugins:

  • Authentication Plugins: Custom authentication and authorization logic
  • Data Source Plugins: Connect to external data sources for realistic test data
  • Response Plugins: Generate custom responses based on request data
  • Template Plugins: Custom token resolvers for the template system

§Quick Start

To create a plugin, implement one or more of the plugin traits:

use mockforge_plugin_core::{TokenResolver, ResolutionContext, PluginError};

pub struct MyPlugin;

#[async_trait::async_trait]
impl TokenResolver for MyPlugin {
    async fn can_resolve(&self, token: &str) -> bool {
        token.starts_with("my_")
    }

    async fn resolve_token(
        &self,
        token: &str,
        context: &ResolutionContext,
    ) -> Result<String, PluginError> {
        // Custom resolution logic
        Ok(format!("resolved: {}", token))
    }

    async fn get_metadata(&self) -> PluginMetadata {
        PluginMetadata::new("My custom plugin")
            .with_capability("token_resolver")
            .with_prefix("my_")
    }
}

§Key Types

§Features

  • Type-safe plugin interfaces
  • Comprehensive error handling
  • Built-in validation and health checks
  • Async/await support
  • Security sandboxing via WebAssembly

§For Plugin Developers

For a more convenient development experience, consider using the mockforge-plugin-sdk crate, which provides helper macros, testing utilities, and additional conveniences.

§Documentation

Re-exports§

pub use async_trait::TokenResolver;
pub use datasource::DataConnection;
pub use datasource::DataQuery;
pub use datasource::DataResult;
pub use datasource::DataSourcePlugin;
pub use datasource::DataSourcePluginConfig;
pub use response::ResponseData;
pub use response::ResponseModifierConfig;
pub use response::ResponseModifierPlugin;
pub use response::ResponsePlugin;
pub use response::ResponsePluginConfig;
pub use response::ResponseRequest;
pub use datasource::helpers as datasource_helpers;
pub use response::helpers as response_helpers;
pub use types::PluginAuthor;
pub use types::PluginHealth;
pub use types::PluginId;
pub use types::PluginInfo;
pub use types::PluginManifest;
pub use types::PluginMetadata;
pub use types::PluginState;
pub use types::PluginVersion;
pub use types::PluginError;
pub use types::PluginInstance;
pub use types::RequestMetadata;
pub use types::ResolutionContext;
pub use types::Result;
pub use auth::*;
pub use template::*;
pub use types::*;

Modules§

async_trait
Async Token Resolver Trait Definition
auth
Authentication plugin interface
datasource
Data source plugin interface
error
Plugin error types and result handling
manifest
Plugin manifest and metadata handling
response
Response generator plugin interface
runtime
WebAssembly runtime for plugin execution
template
Template plugin interface
types
Common types and interfaces used across all plugin types