Refactor Rhai integration with context-based execution and type registry

Major Changes:
- Moved Rhai support from rhai_support/ to rhai/ module
- Implemented context-based execution with signatory access control
- Added TypeRegistry for dynamic type registration and object creation
- Refactored engine to use context (Vec<String>) instead of instance
- Removed old runner binary (moved to runner_rust crate)

Rhai Module:
- engine.rs: Core Rhai engine with context-based get_context()
- functions.rs: Rhai function bindings (create_note, create_event, etc.)
- mod.rs: Module exports and organization

Store Improvements:
- TypeRegistry for registering object types and creators
- Generic store uses type registry for dynamic object creation
- Improved error handling and type safety

Documentation:
- RHAI_REFACTOR_COMPLETE.md: Refactoring details
- SIGNATORY_ACCESS_CONTROL.md: Context-based access control
- TYPE_REGISTRY_DESIGN.md: Type registry architecture
- REFACTORING_COMPLETE.md: Overall refactoring summary
- TESTS_COMPLETE.md: Testing documentation

Build Status:  Compiles successfully with minor warnings
This commit is contained in:
Timur Gordon
2025-10-28 03:33:39 +01:00
parent 097360ad12
commit e04012c8c0
24 changed files with 1810 additions and 249 deletions

View File

@@ -1,18 +1,40 @@
use crate::error::Result;
use crate::index::FieldIndex;
use crate::store::{HeroDbClient, Object};
use crate::store::{HeroDbClient, Object, TypeRegistry};
use std::sync::Arc;
/// Generic storage layer for OSIRIS objects
#[derive(Debug)]
pub struct GenericStore {
client: HeroDbClient,
index: FieldIndex,
type_registry: Option<Arc<TypeRegistry>>,
}
impl GenericStore {
/// Create a new generic store
pub fn new(client: HeroDbClient) -> Self {
let index = FieldIndex::new(client.clone());
Self { client, index }
Self {
client,
index,
type_registry: None,
}
}
/// Create a new generic store with a type registry
pub fn with_registry(client: HeroDbClient, registry: Arc<TypeRegistry>) -> Self {
let index = FieldIndex::new(client.clone());
Self {
client,
index,
type_registry: Some(registry),
}
}
/// Set the type registry
pub fn set_registry(&mut self, registry: Arc<TypeRegistry>) {
self.type_registry = Some(registry);
}
/// Store an object
@@ -39,6 +61,18 @@ impl GenericStore {
T::from_json(&json)
}
/// Get raw JSON data by ID (for generic access without type)
pub async fn get_raw(&self, ns: &str, id: &str) -> Result<String> {
let key = format!("obj:{}:{}", ns, id);
self.client.get(&key).await?
.ok_or_else(|| crate::error::Error::NotFound(format!("Object {}:{}", ns, id)))
}
/// Get the type registry if configured
pub fn type_registry(&self) -> Option<Arc<TypeRegistry>> {
self.type_registry.clone()
}
/// Delete an object
pub async fn delete<T: Object>(&self, obj: &T) -> Result<bool> {
let key = format!("obj:{}:{}", obj.namespace(), obj.id());