hyperstack_interpreter/lib.rs
1//! # hyperstack-interpreter
2//!
3//! AST transformation runtime and VM for HyperStack 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 hyperstack_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 compiler;
29pub mod metrics_context;
30pub mod proto_router;
31pub mod resolvers;
32pub mod rust;
33pub mod spec_trait;
34pub mod typescript;
35pub mod vm;
36
37// Re-export commonly used items
38pub use metrics_context::{FieldAccessor, FieldRef, MetricsContext};
39pub use resolvers::{InstructionContext, KeyResolution, ResolveContext, ReverseLookupUpdater};
40pub use typescript::{write_typescript_to_file, TypeScriptCompiler, TypeScriptConfig};
41pub use vm::{PendingAccountUpdate, PendingQueueStats, UpdateContext};
42
43// Re-export macros for convenient use
44// The field! macro is the new recommended way to create field references
45// The field_accessor! macro is kept for backward compatibility
46
47use serde::{Deserialize, Serialize};
48use serde_json::Value;
49
50#[derive(Debug, Clone, Serialize, Deserialize)]
51pub struct Mutation {
52 pub export: String,
53 pub key: Value,
54 pub patch: Value,
55}
56
57/// Generic wrapper for event data that includes context metadata
58/// This ensures type safety for events captured in entity specs
59///
60/// # Runtime Structure
61/// Events captured with `#[event]` are automatically wrapped in this structure:
62/// ```json
63/// {
64/// "timestamp": 1234567890,
65/// "data": { /* event-specific data */ },
66/// "slot": 381471241,
67/// "signature": "4xNEYTVL8DB28W87..."
68/// }
69/// ```
70#[derive(Debug, Clone, Serialize, Deserialize)]
71pub struct EventWrapper<T = Value> {
72 /// Unix timestamp when the event was processed
73 pub timestamp: i64,
74 /// The event-specific data
75 pub data: T,
76 /// Optional slot number from UpdateContext
77 #[serde(skip_serializing_if = "Option::is_none")]
78 pub slot: Option<u64>,
79 /// Optional transaction signature from UpdateContext
80 #[serde(skip_serializing_if = "Option::is_none")]
81 pub signature: Option<String>,
82}
83
84/// Generic wrapper for account capture data that includes context metadata
85/// This ensures type safety for accounts captured with `#[capture]` in entity specs
86///
87/// # Runtime Structure
88/// Accounts captured with `#[capture]` are automatically wrapped in this structure:
89/// ```json
90/// {
91/// "timestamp": 1234567890,
92/// "account_address": "C6P5CpJnYHgpGvCGuXYAWL6guKH5LApn3QwTAZmNUPCj",
93/// "data": { /* account-specific data (filtered, no __ fields) */ },
94/// "slot": 381471241,
95/// "signature": "4xNEYTVL8DB28W87..."
96/// }
97/// ```
98#[derive(Debug, Clone, Serialize, Deserialize)]
99pub struct CaptureWrapper<T = Value> {
100 /// Unix timestamp when the account was captured
101 pub timestamp: i64,
102 /// The account address (base58 encoded public key)
103 pub account_address: String,
104 /// The account data (already filtered to remove internal __ fields)
105 pub data: T,
106 /// Optional slot number from UpdateContext
107 #[serde(skip_serializing_if = "Option::is_none")]
108 pub slot: Option<u64>,
109 /// Optional transaction signature from UpdateContext
110 #[serde(skip_serializing_if = "Option::is_none")]
111 pub signature: Option<String>,
112}