Plugin Module

Query's plugin system allows you to extend functionality using WebAssembly (WASM) plugins. The system is built on top of Extism, enabling plugins to be written in multiple languages including Rust, C, C++, Go, TypeScript, and more.

Basic Usage

import { plugin } from 'query:plugin';

// Execute a plugin function
const result = await plugin(
    "plugin_name.wasm",  // Plugin file name
    "function_name",     // Function to call
    "input_data",        // String input
    null                 // Optional configuration
);

API Reference

plugin(name, function, input, options?)

Executes a plugin function with the specified parameters.

Parameters

ParameterTypeRequiredDescription
namestringYesPlugin file name (e.g., "plugin_example.wasm")
functionstringYesName of the function to execute
inputstringYesInput data for the plugin function
optionsPluginOptionsNoPlugin configuration options

Plugin Options

interface PluginOptions {
    memory?: {
        maximum?: number;  // Maximum memory pages (64KB each)
        requested?: number;  // Requested initial memory pages
    };
    allowed_hosts?: string[] | null;  // Allowed hosts for HTTP requests
    allowed_paths?: Record<string, string> | null;  // Filesystem path mappings
    config?: Record<string, unknown>;  // Plugin-specific configuration
    timeout?: number;  // Execution timeout in milliseconds
}

For more information about the Query Plugin System, refer to the Query Plugin System.