07. Extension System
Extend TitanPL with JavaScript, WebAssembly, Native Rust, Go, or C++ modules for limitless performance and runtime capability.
TitanPL extensions allow developers to extend the Gravity runtime using JavaScript, Rust, Go, WebAssembly, and native system libraries.
Extensions integrate directly into the Gravity runtime and become accessible globally through the t namespace or via explicit imports from that npm package.
TitanPL supports multiple extension architectures optimized for different workloads, ranging from fully sandboxed JavaScript modules to high-performance native runtime integrations.
๐ Extension Types
TitanPL currently supports four extension categories:
| Type | Runtime | Performance | Sandbox | Build Step |
|---|---|---|---|---|
| JavaScript | V8 | Standard | Fully Sandboxed | No |
| WASM | WebAssembly | High | Sandboxed (Experimental) | Yes |
| Native | Rust/C++ | Maximum | Restricted | Yes |
| Golang | Go Shared Object | High | Restricted | Yes |
JavaScript Extensions
JS-Only Runtime Extensions
JavaScript extensions run directly inside the Gravity V8 runtime.
They are the simplest extension type and require no native compilation.
Best For
- Utility libraries
- Runtime helpers
- Shared business logic
- Middleware systems
- Lightweight runtime APIs
- Rapid prototyping
Security
JavaScript extensions are fully sandboxed inside Gravity and are always allowed by default.
Create Extension
titan create ext my-extThen select: js
Generated Structure
my-ext/
โโโ index.js
โโโ titan.json
โโโ utils/
โโโ registerExtension.jsFiles
| File | Purpose |
|---|---|
index.js | Main extension entrypoint |
titan.json | Extension metadata and runtime manifest |
registerExtension.js | Safe runtime registration helper |
Runtime Registration
JavaScript extensions register themselves onto the global t namespace.
Example:
import { registerExtension } from "./utils/registerExtension.js";
registerExtension("mathx", {
add(a, b) {
return a + b;
}
});Usage:
import Mathx from 'mathx'
const mathx = new Mathx
mathx.add(5, 2);Official JS Template
WebAssembly Extensions (Experimental)
WASM Runtime Extensions
WASM extensions allow Rust logic to run inside a portable sandboxed execution environment.
TitanPL compiles Rust WASM modules into runtime-loadable .wasm artifacts.
Best For
- Parsers
- Compression systems
- Cryptography
- Data processing
- Portable high-performance logic
- CPU-heavy algorithms
Security
WASM runs sandboxed and requires explicit permission inside tanfig.json.
Create Extension
titan create ext my-extThen select: wasm
Build WASM Extension
titan build extRequires:
- Rust toolchain
wasm32-unknown-unknowntarget
Runtime Output
build/
โโโ my-ext.wasmAllow WASM Permissions inside tanfig.json
{
"extensions": {
"allowWasm": true
}
}WASM Runtime Notes
- Runs isolated from native memory
- Portable across operating systems
- Lower risk than native libraries
- Automatically loaded by Gravity
Native Extensions
Native Rust/C++ Extensions
Native extensions provide direct access to operating system APIs and maximum runtime performance.
TitanPL supports Rust native libraries and C++ runtime modules.
Best For
- Database drivers
- GPU acceleration
- Networking engines
- File system APIs
- Native protocol bindings
- Hardware integrations
- Runtime accelerators
Security
Native extensions are blocked by default.
TitanPL enforces explicit allow-list security through tanfig.json.
Create Native Extension
titan create ext my-native-extThen select: native
Build Native Extension
titan build extOutputs:
| Platform | Output |
|---|---|
| Windows | .dll |
| Linux | .so |
| macOS | .dylib |
Native Permissions
{
"extensions": {
"allowNative": [
"@titanpl/core",
"my-native-ext"
]
}
}Gravity Security Policy: TitanPL will trigger a HARD ERROR and refuse to start if any native extension is detected that is not explicitly allowed inside tanfig.json.
Gravity Runtime Architecture
TitanPL executes native extensions outside the primary V8 isolate boundary for runtime stability and crash isolation.
Features
-
Native binary verification
-
Isolated execution layer
-
Runtime permission enforcement
-
Crash isolation
-
Extension manifest validation
Official Native Rust Template
Golang Extensions
Go Shared Library Extensions
TitanPL supports Go shared-object extensions through runtime-loadable binaries.
Best For
- Existing Go ecosystems
- Networking tools
- Concurrency-heavy systems
- Performance utilities
- Distributed tooling
Create Extension
titan create ext my-go-extThen select: golang
Build Go Extension
titan build extProduces:
.dll / .so / .dylibdepending on the target platform.
Official Golang Template
Extension Commands
TitanPL includes a complete extension lifecycle toolkit directly inside the CLI.
titan create ext <name>
Scaffolds a new TitanPL extension package.
Supported Extension Types
| Type | Description |
|---|---|
js | Pure JavaScript runtime extension |
native | Rust native extension |
golang | Go shared library extension |
wasm | WebAssembly extension |
Generated Structure
native/ โ Native source code
sandbox/ โ Extension testing runtime
titan.json โ Extension manifest
index.js โ Runtime registration entrypointExample
titan create ext my-exttitan build ext
Compiles extension runtime binaries.
Supported Targets
- Rust native libraries
- Go shared objects
- WebAssembly modules
Outputs
.dll.so.dylib.wasm
Example
titan build exttitan run ext
Launches the Titan Extension Test Harness.
Features
- Minimal TitanPL server
- Isolated Gravity sandbox
- Native extension injection
- Runtime validation
- Local extension linking
- Temporary virtual TitanPl project
- Standalone runtime execution
Sandbox Modes
| Mode | Description |
|---|---|
| TitanPL Sandbox | Minimal TitanPL server |
| TGRV Sandbox | Standalone Gravity runtime |
Example
titan run extSecurity Configuration
tanfig.json
TitanPL uses explicit runtime permissions for all non-JavaScript extensions.
Example:
{
"name": "my-secure-app",
"extensions": {
"allowWasm": true,
"allowNative": [
"@titanpl/core",
"my-custom-native-ext"
]
}
}Using Extensions
Typed Import Access
import { log, defineAction } from "@titanpl/native";
import "@titanpl/node/globals";
import bcrypt from "bcryptjs";
import Extension from "ext-template";
const demo = new Extension();
export default defineAction((req) => {
log(demo.hash("hello"));
})Extension Runtime Flow
Create Extension
โ
Build Extension
โ
Security Validation
โ
Runtime Registration
โ
Loaded into Gravity
โ
Accessible through t.* or JS importRecommended Extension Strategy
| Use Case | Recommended Type |
|---|---|
| Utilities | JS |
| High-performance portable logic | WASM |
| OS APIs / Drivers | Native |
| Existing Go ecosystem | Golang |
Summary
- TitanPL supports JS, WASM, Native Rust/C++, and Golang extensions.
- Extensions integrate directly into the Gravity runtime.
- Use
titan create extto scaffold new extensions. - Use
titan build extto compile runtime binaries. - Use
titan run extto test extensions inside isolated sandboxes. - WASM and Native extensions require explicit runtime permissions.
- Extensions become globally accessible through the
tnamespace or JS import.