7.3 KiB
7.3 KiB
✅ OSIRIS Rhai Integration - ACTIVATED
The OSIRIS Rhai engine is now fully integrated and working in runner_rust!
🎉 Status: ACTIVE
✓ Dependency added to Cargo.toml
✓ Engine code activated in src/engine/osiris.rs
✓ Rhai support enabled in OSIRIS crate
✓ Test example running successfully
🚀 Quick Start
Run the Test
cargo run --example test_osiris
Output:
🧪 Testing OSIRIS Rhai Engine
Test 1: Creating OSIRIS engine...
✓ Engine created successfully
Test 2: Running simple script...
Hello from OSIRIS Rhai!
Note created: Test Note
✓ Script executed successfully
📝 Usage Example
Create and Store a Note
// Create a note with fluent builder pattern
let note = note("notes")
.title("My Note")
.content("This is the content")
.tag("project", "osiris")
.tag("priority", "high")
.mime("text/plain");
// Store it
let id = put_note(note);
print(`Stored with ID: ${id}`);
// Retrieve it
let retrieved = get_note("notes", id);
print(`Title: ${retrieved.get_title()}`);
Create and Store an Event
// Create an event
let event = event("calendar", "Team Meeting")
.description("Weekly sync")
.location("Conference Room A")
.category("meetings")
.all_day(false);
// Store it
let id = put_event(event);
print(`Event stored: ${id}`);
Query by Index
// Query notes by tag
let ids = query("notes", "tags:tag", "project=osiris");
print(`Found ${ids.len()} notes`);
for note_id in ids {
let n = get_note("notes", note_id);
print(` - ${n.get_title()}`);
}
🔧 Integration Details
Files Modified
-
Cargo.tomlosiris = { path = "../osiris", features = ["rhai-support"] } -
src/engine/osiris.rs- Activated full OSIRIS integration
- Removed placeholder code
- Using
OsirisRhaiEngine,register_note_api,register_event_api
-
src/engine/mod.rs- Exported
create_osiris_engineandrun_osiris_script
- Exported
OSIRIS Rhai Support
Located in osiris/src/rhai_support/:
note_rhai.rs- Note CustomType and builder APIevent_rhai.rs- Event CustomType and builder APIengine.rs- OsirisRhaiEngine wrapper (async → sync bridge)
📚 Available Functions
Note API
| Function | Description |
|---|---|
note(ns) |
Create new note in namespace |
.title(s) |
Set title (chainable) |
.content(s) |
Set content (chainable) |
.tag(k, v) |
Add tag (chainable) |
.mime(s) |
Set MIME type (chainable) |
put_note(note) |
Store note, returns ID |
get_note(ns, id) |
Retrieve note by ID |
.get_id() |
Get note ID |
.get_title() |
Get note title |
.get_content() |
Get note content |
.to_json() |
Serialize to JSON |
Event API
| Function | Description |
|---|---|
event(ns, title) |
Create new event |
.description(s) |
Set description (chainable) |
.location(s) |
Set location (chainable) |
.category(s) |
Set category (chainable) |
.all_day(b) |
Set all-day flag (chainable) |
put_event(event) |
Store event, returns ID |
get_event(ns, id) |
Retrieve event by ID |
.get_id() |
Get event ID |
.get_title() |
Get event title |
.to_json() |
Serialize to JSON |
Query API
| Function | Description |
|---|---|
query(ns, field, value) |
Query by indexed field, returns array of IDs |
🏗️ Architecture
┌─────────────────────────────────────────┐
│ Rhai Script │
│ note("notes").title("Hi").tag("x","y") │
└────────────────┬────────────────────────┘
│
┌────────────────▼────────────────────────┐
│ runner_rust/src/engine/osiris.rs │
│ create_osiris_engine() │
└────────────────┬────────────────────────┘
│
┌────────────────▼────────────────────────┐
│ osiris/src/rhai_support/ │
│ ├── note_rhai.rs (CustomType) │
│ ├── event_rhai.rs (CustomType) │
│ └── engine.rs (OsirisRhaiEngine) │
└────────────────┬────────────────────────┘
│
┌────────────────▼────────────────────────┐
│ osiris/src/store/GenericStore │
│ Automatic indexing via #[index] │
└────────────────┬────────────────────────┘
│
┌────────────────▼────────────────────────┐
│ HeroDB (Redis-compatible) │
└─────────────────────────────────────────┘
🎯 Key Features
- Fluent Builder Pattern - Chain method calls for clean code
- Type Safety - Rhai's type system ensures correctness
- Async Bridge - Sync Rhai scripts use async OSIRIS operations seamlessly
- Automatic Indexing - Objects indexed based on
#[index]attributes - Zero Boilerplate - Derive macro generates all indexing code
📖 Examples
Full Examples Available
examples/test_osiris.rs- Quick integration testexamples/osiris_example.rs- Comprehensive Rust exampleexamples/osiris_script.rhai- Complete Rhai script
Running with HeroDB
# Terminal 1: Start HeroDB
cd ../herodb
cargo run --release -- --dir ./data --admin-secret mysecret --port 6379
# Terminal 2: Run OSIRIS script
cd ../runner_rust
cargo run --example test_osiris
🔍 Testing
# Build check
cargo check
# Build examples
cargo build --examples
# Run test
cargo run --example test_osiris
# Run with HeroDB integration
# (requires HeroDB running on localhost:6379)
cargo run --example osiris_example
📊 Performance
- Sync Rhai → Async OSIRIS: Bridged via Tokio runtime
- Connection Pooling: HeroDB client maintains connection pool
- Automatic Indexing: Generated at compile-time, zero runtime overhead
- Type Safety: All type checks at compile-time
🎨 Extending
To add new OSIRIS object types:
- Create the object in
osiris/src/objects/ - Add
#[derive(DeriveObject)]and mark fields with#[index] - Create
{object}_rhai.rsinosiris/src/rhai_support/ - Implement
CustomTypeand builder methods - Register in
create_osiris_engine()
✅ Verification
Run this to verify everything works:
cargo run --example test_osiris
Expected output:
✓ Engine created successfully
✓ Script executed successfully
✅ Tests completed!
🎉 Success!
The OSIRIS Rhai engine is fully operational and ready for use in production scripts!