add heroledger example
This commit is contained in:
parent
5fd068f45d
commit
cc700a0abe
3
.gitignore
vendored
3
.gitignore
vendored
@ -1 +1,2 @@
|
|||||||
target
|
target
|
||||||
|
logs
|
12
Cargo.lock
generated
12
Cargo.lock
generated
@ -192,7 +192,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "baobab_actor"
|
name = "baobab_actor"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://git.ourworld.tf/herocode/baobab.git#ce76f0a2f7149a098dc075f70c50fa4dc2347c5a"
|
source = "git+https://git.ourworld.tf/herocode/baobab.git#04a1af242362e5158e40bb405c593af74f77d047"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
@ -392,7 +392,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "117725a109d387c937a1533ce01b450cbde6b88abceea8473c4d7a85853cda3c"
|
checksum = "117725a109d387c937a1533ce01b450cbde6b88abceea8473c4d7a85853cda3c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"windows-sys 0.59.0",
|
"windows-sys 0.48.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -982,7 +982,7 @@ checksum = "fc0fef456e4baa96da950455cd02c081ca953b141298e41db3fc7e36b1da849c"
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "hero_job"
|
name = "hero_job"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://git.ourworld.tf/herocode/baobab.git#ce76f0a2f7149a098dc075f70c50fa4dc2347c5a"
|
source = "git+https://git.ourworld.tf/herocode/baobab.git#04a1af242362e5158e40bb405c593af74f77d047"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"log",
|
"log",
|
||||||
@ -997,7 +997,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "hero_logger"
|
name = "hero_logger"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://git.ourworld.tf/herocode/baobab.git?branch=logger#0da7b9363c2956e6f17ac78232152c549f1d5e68"
|
source = "git+https://git.ourworld.tf/herocode/baobab.git?branch=logger#d7a7eae19ec22c8f5250a5ee1cea6affe7810d4f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"chrono",
|
"chrono",
|
||||||
@ -1014,7 +1014,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "hero_supervisor"
|
name = "hero_supervisor"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://git.ourworld.tf/herocode/baobab.git#ce76f0a2f7149a098dc075f70c50fa4dc2347c5a"
|
source = "git+https://git.ourworld.tf/herocode/baobab.git#04a1af242362e5158e40bb405c593af74f77d047"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"chrono",
|
"chrono",
|
||||||
@ -3825,7 +3825,7 @@ version = "0.1.9"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb"
|
checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"windows-sys 0.59.0",
|
"windows-sys 0.48.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
53
examples/scripts/heroledger.rhai
Normal file
53
examples/scripts/heroledger.rhai
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
// heroledger.rhai - Demonstration of HeroLedger models in Rhai
|
||||||
|
|
||||||
|
print("=== HeroLedger Models Demo ===");
|
||||||
|
|
||||||
|
// Create a new user
|
||||||
|
print("\n--- Creating User ---");
|
||||||
|
let new_user = new_user()
|
||||||
|
.name("Alice Johnson")
|
||||||
|
.email("alice@herocode.com")
|
||||||
|
.pubkey("0x1234567890abcdef")
|
||||||
|
.status("Active")
|
||||||
|
.save_user();
|
||||||
|
|
||||||
|
print("Created user: " + new_user.get_name());
|
||||||
|
print("User ID: " + new_user.get_id());
|
||||||
|
print("User email: " + new_user.get_email());
|
||||||
|
print("User pubkey: " + new_user.get_pubkey());
|
||||||
|
|
||||||
|
// Create a new group
|
||||||
|
print("\n--- Creating Group ---");
|
||||||
|
let new_group = new_group()
|
||||||
|
.name("HeroCode Developers")
|
||||||
|
.description("A group for HeroCode development team members")
|
||||||
|
.visibility("Public")
|
||||||
|
.save_group();
|
||||||
|
|
||||||
|
print("Created group: " + new_group.get_name());
|
||||||
|
print("Group ID: " + new_group.get_id());
|
||||||
|
print("Group description: " + new_group.get_description());
|
||||||
|
|
||||||
|
// Create a new account
|
||||||
|
print("\n--- Creating Account ---");
|
||||||
|
let new_account = new_account()
|
||||||
|
.name("Alice's Main Account")
|
||||||
|
.description("Primary account for Alice Johnson")
|
||||||
|
.currency("USD")
|
||||||
|
.save_account();
|
||||||
|
|
||||||
|
print("Created account: " + new_account.get_name());
|
||||||
|
print("Account ID: " + new_account.get_id());
|
||||||
|
print("Account currency: " + new_account.get_currency());
|
||||||
|
|
||||||
|
// Create a new DNS zone
|
||||||
|
print("\n--- Creating DNS Zone ---");
|
||||||
|
let new_dns_zone = new_dns_zone()
|
||||||
|
.name("herocode.com")
|
||||||
|
.description("Main domain for HeroCode")
|
||||||
|
.save_dns_zone();
|
||||||
|
|
||||||
|
print("Created DNS zone: " + new_dns_zone.get_name());
|
||||||
|
print("DNS zone ID: " + new_dns_zone.get_id());
|
||||||
|
|
||||||
|
print("\n=== Demo Complete ===");
|
@ -1,42 +1,4 @@
|
|||||||
//! # Rhailib Domain-Specific Language (DSL) Engine
|
use heromodels::models::heroledger::rhai::register_heroledger_rhai_modules;
|
||||||
//!
|
|
||||||
//! This module provides a comprehensive Domain-Specific Language implementation for the Rhai
|
|
||||||
//! scripting engine, exposing business domain models and operations through a fluent,
|
|
||||||
//! chainable API.
|
|
||||||
//!
|
|
||||||
//! ## Overview
|
|
||||||
//!
|
|
||||||
//! The DSL is organized into business domain modules, each providing Rhai-compatible
|
|
||||||
//! functions for creating, manipulating, and persisting domain entities. All operations
|
|
||||||
//! include proper authorization checks and type safety.
|
|
||||||
//!
|
|
||||||
//! ## Available Domains
|
|
||||||
//!
|
|
||||||
//! - **Business Operations** (`biz`): Companies, products, sales, shareholders
|
|
||||||
//! - **Financial Models** (`finance`): Accounts, assets, marketplace operations
|
|
||||||
//! - **Content Management** (`library`): Collections, images, PDFs, books, slideshows
|
|
||||||
//! - **Workflow Management** (`flow`): Flows, steps, signature requirements
|
|
||||||
//! - **Community Management** (`circle`): Circles, themes, membership
|
|
||||||
//! - **Contact Management** (`contact`): Contact information and relationships
|
|
||||||
//! - **Access Control** (`access`): Security and permissions
|
|
||||||
//! - **Time Management** (`calendar`): Calendar and scheduling
|
|
||||||
//! - **Core Utilities** (`core`): Comments and fundamental operations
|
|
||||||
//! - **Generic Objects** (`object`): Generic object manipulation
|
|
||||||
//!
|
|
||||||
//! ## Usage Example
|
|
||||||
//!
|
|
||||||
//! ```rust
|
|
||||||
//! use rhai::Engine;
|
|
||||||
//! use crate::engine::register_dsl_modules;
|
|
||||||
//!
|
|
||||||
//! let mut engine = Engine::new();
|
|
||||||
//! register_dsl_modules(&mut engine);
|
|
||||||
//!
|
|
||||||
//! // Now the engine can execute scripts like:
|
|
||||||
//! // let company = new_company().name("Acme Corp").email("contact@acme.com");
|
|
||||||
//! // let saved = save_company(company);
|
|
||||||
//! ```
|
|
||||||
|
|
||||||
use rhai::Engine;
|
use rhai::Engine;
|
||||||
use rhailib_dsl;
|
use rhailib_dsl;
|
||||||
use std::sync::{Arc, OnceLock};
|
use std::sync::{Arc, OnceLock};
|
||||||
@ -161,6 +123,8 @@ pub fn register_dsl_modules(engine: &mut Engine) {
|
|||||||
|
|
||||||
// Register basic object functionality directly
|
// Register basic object functionality directly
|
||||||
register_object_functions(engine);
|
register_object_functions(engine);
|
||||||
|
heromodels::heroledger::rhai::register_heroledger_rhai_modules(&mut engine);
|
||||||
|
|
||||||
|
|
||||||
println!("Rhailib Domain Specific Language modules registered successfully.");
|
println!("Rhailib Domain Specific Language modules registered successfully.");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user