Documentation
¶
Overview ¶
Package sdk provides constants and documentation for developing WASM plugins for Lesstruct.
Plugins are compiled to WebAssembly (WASM) and loaded at runtime by the Lesstruct plugin system. Each plugin exports hook functions that the host calls at specific lifecycle points.
Getting Started ¶
1. Write a plugin in Go (TinyGo), Rust, or C/C++ 2. Export one or more hook functions named hook_{snake_case_hook_name} 3. Compile to WASM targeting the WASI runtime 4. Place the .wasm file in the plugins/ directory
System Fields ¶
System fields are special custom field values managed exclusively by plugins. They are defined in post type TOML schemas with `system = true` and stored in the `customFields` JSON map alongside regular custom fields.
Plugins write system field values through `before_save` hooks by including them in the `customFields` object of the returned JSON data. The host validates plugin-set system field values against their schema (type, options, min/max). User-submitted system field values are always stripped for security.
For examples of reading and writing system fields in hook handlers, see docs/plugin-development.md and the go-system-fields example.
See docs/plugin-development.md for the full plugin development guide.
Index ¶
Constants ¶
const ( HookBeforeSave = "before_save" HookAfterPublish = "after_publish" HookBeforeDelete = "before_delete" HookAfterCreate = "after_create" HookOnPluginLoaded = "on_plugin_loaded" )
Hook name constants matching the canonical WASM export suffixes. Plugin .wasm files MUST export functions named "hook_" + these values.
const ( // HostFunctionHTTPGet imports lesstruct.http_get for HTTP GET requests. HostFunctionHTTPGet = "http_get" // HostFunctionHTTPPost imports lesstruct.http_post for HTTP POST requests. HostFunctionHTTPPost = "http_post" // HostFunctionDBQuery imports lesstruct.db_query for SELECT queries. HostFunctionDBQuery = "db_query" // HostFunctionDBExec imports lesstruct.db_exec for INSERT/UPDATE/DELETE // statements. HostFunctionDBExec = "db_exec" // HostFunctionLogInfo imports lesstruct.log_info for informational logging. HostFunctionLogInfo = "log_info" // HostFunctionLogError imports lesstruct.log_error for error logging. HostFunctionLogError = "log_error" )
Host function name constants. Plugin .wasm files import these from the "lesstruct" host module when the corresponding capabilities are declared in the manifest.
const DefaultPriority = 100
DefaultPriority is the default execution priority for hooks. Lower values run earlier. Default is 100.
const ( // HostModuleName is the WASM import module name for Lesstruct host // functions. HostModuleName = "lesstruct" )
Host module namespace constants.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FailureMode ¶
type FailureMode int
FailureMode determines how the plugin system handles hook failures.
const ( FailFast FailureMode = iota // Stop execution on failure LogAndContinue // Log error and continue to next hook Fallback // Use fallback handler on failure )
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
go-content-transform
command
|
|
|
go-hello-world
command
|
|
|
go-system-fields
command
|
|
|
go-validation
command
|