arete_interpreter/lib.rs
1//! # arete-interpreter
2//!
3//! AST transformation runtime and VM for Arete streaming pipelines.
4//!
5//! This crate provides the core components for processing Solana blockchain
6//! events into typed state projections:
7//!
8//! - **AST Definition** - Type-safe schemas for state and event handlers
9//! - **Bytecode Compiler** - Compiles specs into optimized bytecode
10//! - **Virtual Machine** - Executes bytecode to process events
11//! - **TypeScript Generation** - Generate client SDKs automatically
12//!
13//! ## Example
14//!
15//! ```rust,ignore
16//! use arete_interpreter::{TypeScriptCompiler, TypeScriptConfig};
17//!
18//! let config = TypeScriptConfig::default();
19//! let compiler = TypeScriptCompiler::new(config);
20//! let typescript = compiler.compile(&spec)?;
21//! ```
22//!
23//! ## Feature Flags
24//!
25//! - `otel` - OpenTelemetry integration for distributed tracing and metrics
26
27pub mod ast;
28pub mod canonical_log;
29pub mod compiler;
30pub mod debugger;
31pub mod event_type_helpers;
32pub mod metrics_context;
33pub mod program_sdk;
34pub mod proto_router;
35pub mod public_artifacts;
36pub mod resolvers;
37pub mod runtime_resolvers;
38pub mod runtime_resolvers_factory;
39pub mod rust;
40pub mod scheduler;
41pub mod slot_hash_cache;
42pub mod spec_trait;
43pub mod typescript;
44pub mod typescript_instructions;
45pub mod versioned;
46pub mod vm;
47pub mod vm_metrics;
48
49// Re-export slot hash cache functions
50pub use slot_hash_cache::{get_slot_hash, record_slot_hash};
51
52pub use canonical_log::{CanonicalLog, LogLevel};
53pub use debugger::{VmDebugEvent, VmDebugger, VmLookupHop};
54pub use metrics_context::{FieldAccessor, FieldRef, MetricsContext};
55pub use resolvers::{
56 InstructionContext, KeyResolution, ResolveContext, ReverseLookupUpdater, TokenMetadata,
57};
58pub use runtime_resolvers::{
59 InProcessResolver, ResolverApplyFuture, ResolverBatchFuture, ResolverBatchResult,
60 RuntimeResolver, RuntimeResolverBatchRequest, RuntimeResolverBatchResponse,
61 RuntimeResolverRequest, RuntimeResolverResponse, SharedRuntimeResolver,
62};
63pub use typescript::{write_typescript_to_file, TypeScriptCompiler, TypeScriptConfig};
64pub use vm::{
65 CapacityWarning, CleanupResult, DirtyTracker, FieldChange, PendingAccountUpdate,
66 PendingQueueStats, QueuedAccountUpdate, ResolverRequest, ResolverTarget, ScheduledCallback,
67 StateTableConfig, UpdateContext, VmMemoryStats,
68};
69
70// Re-export macros for convenient use
71// The field! macro is the new recommended way to create field references
72// The field_accessor! macro is kept for backward compatibility
73
74use serde::{Deserialize, Serialize};
75use serde_json::Value;
76
77#[derive(Debug, Clone, Serialize, Deserialize)]
78pub struct Mutation {
79 pub export: String,
80 pub key: Value,
81 pub patch: Value,
82 #[serde(skip_serializing_if = "Vec::is_empty", default)]
83 pub append: Vec<String>,
84}
85
86/// Generic wrapper for event data that includes context metadata
87/// This ensures type safety for events captured in entity specs
88///
89/// # Runtime Structure
90/// Events captured with `#[event]` are automatically wrapped in this structure:
91/// ```json
92/// {
93/// "timestamp": 1234567890,
94/// "data": { /* event-specific data */ },
95/// "slot": 381471241,
96/// "signature": "4xNEYTVL8DB28W87..."
97/// }
98/// ```
99#[derive(Debug, Clone, Serialize, Deserialize)]
100pub struct EventWrapper<T = Value> {
101 /// Unix timestamp when the event was processed
102 pub timestamp: i64,
103 /// The event-specific data
104 pub data: T,
105 /// Optional slot number from UpdateContext
106 #[serde(skip_serializing_if = "Option::is_none")]
107 pub slot: Option<u64>,
108 /// Optional transaction signature from UpdateContext
109 #[serde(skip_serializing_if = "Option::is_none")]
110 pub signature: Option<String>,
111}
112
113/// Generic wrapper for account capture data that includes context metadata
114/// This ensures type safety for accounts captured with `#[capture]` in entity specs
115///
116/// # Runtime Structure
117/// Accounts captured with `#[capture]` are automatically wrapped in this structure:
118/// ```json
119/// {
120/// "timestamp": 1234567890,
121/// "account_address": "C6P5CpJnYHgpGvCGuXYAWL6guKH5LApn3QwTAZmNUPCj",
122/// "data": { /* account-specific data (filtered, no __ fields) */ },
123/// "slot": 381471241,
124/// "signature": "4xNEYTVL8DB28W87..."
125/// }
126/// ```
127#[derive(Debug, Clone, Serialize, Deserialize)]
128pub struct CaptureWrapper<T = Value> {
129 /// Unix timestamp when the account was captured
130 pub timestamp: i64,
131 /// The account address (base58 encoded public key)
132 pub account_address: String,
133 /// The account data (already filtered to remove internal __ fields)
134 pub data: T,
135 /// Optional slot number from UpdateContext
136 #[serde(skip_serializing_if = "Option::is_none")]
137 pub slot: Option<u64>,
138 /// Optional transaction signature from UpdateContext
139 #[serde(skip_serializing_if = "Option::is_none")]
140 pub signature: Option<String>,
141}