Skip to main content

shape_runtime/engine/
types.rs

1//! Types for execution results and metrics
2
3use crate::query_result::QueryType;
4use serde::{Deserialize, Serialize};
5use shape_wire::WireValue;
6use shape_wire::metadata::TypeInfo;
7
8/// Snapshot of preloaded engine state (semantic + runtime context).
9///
10/// This is used by services (e.g. shape-server) to avoid reloading stdlib
11/// from disk on every request while still creating an isolated engine per run.
12#[derive(Clone)]
13pub struct EngineBootstrapState {
14    pub semantic: crate::snapshot::SemanticSnapshot,
15    pub context: crate::context::ExecutionContext,
16}
17
18/// Result from executing Shape code
19#[derive(Debug, Clone, Serialize, Deserialize)]
20pub struct ExecutionResult {
21    /// The value returned by the execution
22    pub value: WireValue,
23    /// Type information for the return value
24    pub type_info: Option<TypeInfo>,
25    /// Type of execution
26    pub execution_type: ExecutionType,
27    /// Performance metrics
28    pub metrics: ExecutionMetrics,
29    /// Any warnings or info messages
30    pub messages: Vec<Message>,
31    /// JSON representation of a Content node (if the result is Content)
32    #[serde(skip_serializing_if = "Option::is_none", default)]
33    pub content_json: Option<serde_json::Value>,
34    /// HTML representation of a Content node (if the result is Content)
35    #[serde(skip_serializing_if = "Option::is_none", default)]
36    pub content_html: Option<String>,
37    /// Terminal (ANSI) representation of a Content node (if the result is Content)
38    #[serde(skip_serializing_if = "Option::is_none", default)]
39    pub content_terminal: Option<String>,
40}
41
42/// Type of execution performed
43#[derive(Debug, Clone, Serialize, Deserialize)]
44pub enum ExecutionType {
45    /// Query execution (find, scan, analyze, etc.)
46    Query(QueryType),
47    /// Function execution
48    Function(String),
49    /// Script/expression evaluation
50    Script,
51    /// REPL command
52    Repl,
53}
54
55/// Performance metrics for execution
56#[derive(Debug, Clone, Serialize, Deserialize)]
57pub struct ExecutionMetrics {
58    /// Total execution time in milliseconds
59    pub execution_time_ms: u64,
60    /// Parse time in milliseconds
61    pub parse_time_ms: u64,
62    /// Analysis time in milliseconds
63    pub analysis_time_ms: u64,
64    /// Runtime execution time in milliseconds
65    pub runtime_time_ms: u64,
66    /// Memory used in bytes
67    pub memory_used_bytes: Option<usize>,
68    /// Number of rows processed
69    pub rows_processed: Option<usize>,
70}
71
72/// Messages from execution
73#[derive(Debug, Clone, Serialize, Deserialize)]
74pub struct Message {
75    pub level: MessageLevel,
76    pub text: String,
77    pub location: Option<String>,
78}
79
80#[derive(Debug, Clone, Serialize, Deserialize)]
81pub enum MessageLevel {
82    Info,
83    Warning,
84    Error,
85}