Refactor to use Rhai packages for efficient engine creation

- Created OsirisPackage with all OSIRIS types and functions registered in the package
- Functions now registered directly in package module (Note, Event, get_context)
- Created ZdfzPackage extending OsirisPackage
- Engine factory pattern: creates Engine::new_raw() + registers package (very cheap)
- Removed TypeRegistry (unused code)
- Simplified runner to use factory functions instead of passing packages
- Package is created once, then factory efficiently creates engines on demand
This commit is contained in:
Timur Gordon
2025-10-28 12:20:17 +01:00
parent e04012c8c0
commit e760a184b1
12 changed files with 399 additions and 805 deletions

View File

@@ -1,14 +1,12 @@
use crate::error::Result;
use crate::index::FieldIndex;
use crate::store::{HeroDbClient, Object, TypeRegistry};
use std::sync::Arc;
use crate::store::{HeroDbClient, Object};
/// Generic storage layer for OSIRIS objects
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct GenericStore {
client: HeroDbClient,
index: FieldIndex,
type_registry: Option<Arc<TypeRegistry>>,
}
impl GenericStore {
@@ -18,25 +16,9 @@ impl GenericStore {
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
pub async fn put<T: Object>(&self, obj: &T) -> Result<()> {
// Serialize object to JSON
@@ -68,11 +50,6 @@ impl GenericStore {
.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());