// This file is @generated by prost-build. /// Request to create or update a script bound to a specific table and column. #[derive(serde::Serialize, serde::Deserialize)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct PostTableScriptRequest { /// Required. The metadata ID from table_definitions.id that identifies the /// table this script belongs to. The table must exist; its schema determines /// where referenced tables/columns are validated and where dependencies are stored. #[prost(int64, tag = "1")] pub table_definition_id: i64, /// Required. The target column in the target table that this script computes. /// Must be an existing user-defined column in that table (not a system column). /// System columns are reserved: "id", "deleted", "created_at". /// The column's data type must NOT be one of the prohibited target types: /// BIGINT, DATE, TIMESTAMPTZ /// Note: BOOLEAN targets are allowed (values are converted to Steel #true/#false). #[prost(string, tag = "2")] pub target_column: ::prost::alloc::string::String, /// Required. The script in the Steel DSL (S-expression style). /// Syntax requirements: /// - Non-empty, must start with '(' /// - Balanced parentheses /// /// Referencing data: /// - Structured table/column access (enforces link constraints): /// (steel_get_column "table_name" "column_name") /// (steel_get_column_with_index "table_name" index "column_name") /// • index must be a non-negative integer literal /// • self-references are allowed without links /// • other tables require an explicit link from the source table /// (table_definition_links) or the request fails /// - Raw SQL access (no link required, but still validated): /// (steel_query_sql "SELECT ...") /// • Basic checks disallow operations that imply prohibited types, /// e.g., EXTRACT(…), DATE_PART(…), ::DATE, ::TIMESTAMPTZ, ::BIGINT, CAST(…) /// - Self variable access in transformed scripts: /// (get-var "column_name") is treated as referencing the current table /// /// Math operations: /// - The script is transformed by steel_decimal; supported math forms include: /// +, -, *, /, ^, **, pow, sqrt, >, <, =, >=, <=, min, max, abs, round, /// ln, log, log10, exp, sin, cos, tan /// - Columns of the following types CANNOT be used inside math expressions: /// BIGINT, TEXT, BOOLEAN, DATE, TIMESTAMPTZ /// /// Dependency tracking and cycles: /// - Dependencies are extracted from steel_get_column(_with_index), get-var, /// and steel_query_sql and stored in script_dependencies with context /// - Cycles across tables are rejected (self-dependency is allowed) #[prost(string, tag = "3")] pub script: ::prost::alloc::string::String, /// Optional. Free-text description stored alongside the script (no functional effect). #[prost(string, tag = "4")] pub description: ::prost::alloc::string::String, } /// Response after creating or updating a script. #[derive(serde::Serialize, serde::Deserialize)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct TableScriptResponse { /// The ID of the script record in table_scripts (new or existing on upsert). #[prost(int64, tag = "1")] pub id: i64, /// Human-readable warnings concatenated into a single string. Possible messages: /// - Warning if the script references itself (may affect first population) /// - Count of raw SQL queries present /// - Info about number of structured linked-table accesses /// - Warning if many dependencies may affect performance #[prost(string, tag = "2")] pub warnings: ::prost::alloc::string::String, } #[derive(Clone, PartialEq, ::prost::Message)] pub struct GetTableScriptsRequest { /// Required. Profile (schema) name. #[prost(string, tag = "1")] pub profile_name: ::prost::alloc::string::String, /// Required. Table name within the profile. #[prost(string, tag = "2")] pub table_name: ::prost::alloc::string::String, } #[derive(Clone, PartialEq, ::prost::Message)] pub struct GetTableScriptsResponse { #[prost(message, repeated, tag = "1")] pub scripts: ::prost::alloc::vec::Vec, } #[derive(Clone, PartialEq, ::prost::Message)] pub struct StoredTableScript { #[prost(int64, tag = "1")] pub id: i64, #[prost(string, tag = "2")] pub target_column: ::prost::alloc::string::String, #[prost(string, tag = "3")] pub target_column_type: ::prost::alloc::string::String, #[prost(string, tag = "4")] pub script: ::prost::alloc::string::String, #[prost(string, tag = "5")] pub description: ::prost::alloc::string::String, #[prost(message, repeated, tag = "6")] pub dependencies: ::prost::alloc::vec::Vec, } #[derive(Clone, PartialEq, ::prost::Message)] pub struct ScriptDependency { #[prost(string, tag = "1")] pub target_table: ::prost::alloc::string::String, #[prost(string, tag = "2")] pub dependency_type: ::prost::alloc::string::String, #[prost(string, tag = "3")] pub column: ::prost::alloc::string::String, #[prost(int64, tag = "4")] pub index: i64, #[prost(string, tag = "5")] pub query_fragment: ::prost::alloc::string::String, } /// Generated client implementations. pub mod table_script_client { #![allow( unused_variables, dead_code, missing_docs, clippy::wildcard_imports, clippy::let_unit_value, )] use tonic::codegen::*; use tonic::codegen::http::Uri; /// Manages column-computation scripts for user-defined tables. /// Each script belongs to a single table (table_definition_id) and populates /// exactly one target column in that table. The server: /// - Validates script syntax (non-empty, balanced parentheses, starts with '(') /// - Validates the target column (exists, not a system column, allowed type) /// - Validates column/type usage inside math expressions /// - Validates referenced tables/columns against the schema /// - Enforces link constraints for structured access (see notes below) /// - Analyzes dependencies and prevents cycles across the schema /// - Transforms the script to decimal-safe math (steel_decimal) /// - Upserts into table_scripts and records dependencies in script_dependencies /// The whole operation is transactional. #[derive(Debug, Clone)] pub struct TableScriptClient { inner: tonic::client::Grpc, } impl TableScriptClient { /// Attempt to create a new client by connecting to a given endpoint. pub async fn connect(dst: D) -> Result where D: TryInto, D::Error: Into, { let conn = tonic::transport::Endpoint::new(dst)?.connect().await?; Ok(Self::new(conn)) } } impl TableScriptClient where T: tonic::client::GrpcService, T::Error: Into, T::ResponseBody: Body + std::marker::Send + 'static, ::Error: Into + std::marker::Send, { pub fn new(inner: T) -> Self { let inner = tonic::client::Grpc::new(inner); Self { inner } } pub fn with_origin(inner: T, origin: Uri) -> Self { let inner = tonic::client::Grpc::with_origin(inner, origin); Self { inner } } pub fn with_interceptor( inner: T, interceptor: F, ) -> TableScriptClient> where F: tonic::service::Interceptor, T::ResponseBody: Default, T: tonic::codegen::Service< http::Request, Response = http::Response< >::ResponseBody, >, >, , >>::Error: Into + std::marker::Send + std::marker::Sync, { TableScriptClient::new(InterceptedService::new(inner, interceptor)) } /// Compress requests with the given encoding. /// /// This requires the server to support it otherwise it might respond with an /// error. #[must_use] pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self { self.inner = self.inner.send_compressed(encoding); self } /// Enable decompressing responses. #[must_use] pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self { self.inner = self.inner.accept_compressed(encoding); self } /// Limits the maximum size of a decoded message. /// /// Default: `4MB` #[must_use] pub fn max_decoding_message_size(mut self, limit: usize) -> Self { self.inner = self.inner.max_decoding_message_size(limit); self } /// Limits the maximum size of an encoded message. /// /// Default: `usize::MAX` #[must_use] pub fn max_encoding_message_size(mut self, limit: usize) -> Self { self.inner = self.inner.max_encoding_message_size(limit); self } /// Create or update a script for a specific table and target column. /// /// Behavior: /// - Fetches the table by table_definition_id (must exist) /// - Validates "script" (syntax), "target_column" (exists and type rules), /// and all referenced tables/columns (must exist in same schema) /// - Validates math operations: prohibits using certain data types in math /// - Enforces link constraints for structured table access: /// • Allowed always: self-references (same table) /// • Structured access via steel_get_column / steel_get_column_with_index /// requires an explicit link in table_definition_links /// • Raw SQL access via steel_query_sql is permitted (still validated) /// - Detects and rejects circular dependencies across all scripts in the schema /// (self-references are allowed and not treated as cycles) /// - Transforms the script to decimal-safe operations (steel_decimal) /// - UPSERTS into table_scripts on (table_definitions_id, target_column) /// and saves a normalized dependency list into script_dependencies pub async fn post_table_script( &mut self, request: impl tonic::IntoRequest, ) -> std::result::Result< tonic::Response, tonic::Status, > { self.inner .ready() .await .map_err(|e| { tonic::Status::unknown( format!("Service was not ready: {}", e.into()), ) })?; let codec = tonic::codec::ProstCodec::default(); let path = http::uri::PathAndQuery::from_static( "/komp_ac.table_script.TableScript/PostTableScript", ); let mut req = request.into_request(); req.extensions_mut() .insert( GrpcMethod::new( "komp_ac.table_script.TableScript", "PostTableScript", ), ); self.inner.unary(req, path, codec).await } /// Fetch all stored scripts for a specific table. /// /// Behavior: /// - Resolves the table from (profile_name, table_name) /// - Returns the stored, transformed script from table_scripts /// - Includes normalized dependency metadata from script_dependencies /// - Returns an empty scripts list when the table has no scripts pub async fn get_table_scripts( &mut self, request: impl tonic::IntoRequest, ) -> std::result::Result< tonic::Response, tonic::Status, > { self.inner .ready() .await .map_err(|e| { tonic::Status::unknown( format!("Service was not ready: {}", e.into()), ) })?; let codec = tonic::codec::ProstCodec::default(); let path = http::uri::PathAndQuery::from_static( "/komp_ac.table_script.TableScript/GetTableScripts", ); let mut req = request.into_request(); req.extensions_mut() .insert( GrpcMethod::new( "komp_ac.table_script.TableScript", "GetTableScripts", ), ); self.inner.unary(req, path, codec).await } } } /// Generated server implementations. pub mod table_script_server { #![allow( unused_variables, dead_code, missing_docs, clippy::wildcard_imports, clippy::let_unit_value, )] use tonic::codegen::*; /// Generated trait containing gRPC methods that should be implemented for use with TableScriptServer. #[async_trait] pub trait TableScript: std::marker::Send + std::marker::Sync + 'static { /// Create or update a script for a specific table and target column. /// /// Behavior: /// - Fetches the table by table_definition_id (must exist) /// - Validates "script" (syntax), "target_column" (exists and type rules), /// and all referenced tables/columns (must exist in same schema) /// - Validates math operations: prohibits using certain data types in math /// - Enforces link constraints for structured table access: /// • Allowed always: self-references (same table) /// • Structured access via steel_get_column / steel_get_column_with_index /// requires an explicit link in table_definition_links /// • Raw SQL access via steel_query_sql is permitted (still validated) /// - Detects and rejects circular dependencies across all scripts in the schema /// (self-references are allowed and not treated as cycles) /// - Transforms the script to decimal-safe operations (steel_decimal) /// - UPSERTS into table_scripts on (table_definitions_id, target_column) /// and saves a normalized dependency list into script_dependencies async fn post_table_script( &self, request: tonic::Request, ) -> std::result::Result< tonic::Response, tonic::Status, >; /// Fetch all stored scripts for a specific table. /// /// Behavior: /// - Resolves the table from (profile_name, table_name) /// - Returns the stored, transformed script from table_scripts /// - Includes normalized dependency metadata from script_dependencies /// - Returns an empty scripts list when the table has no scripts async fn get_table_scripts( &self, request: tonic::Request, ) -> std::result::Result< tonic::Response, tonic::Status, >; } /// Manages column-computation scripts for user-defined tables. /// Each script belongs to a single table (table_definition_id) and populates /// exactly one target column in that table. The server: /// - Validates script syntax (non-empty, balanced parentheses, starts with '(') /// - Validates the target column (exists, not a system column, allowed type) /// - Validates column/type usage inside math expressions /// - Validates referenced tables/columns against the schema /// - Enforces link constraints for structured access (see notes below) /// - Analyzes dependencies and prevents cycles across the schema /// - Transforms the script to decimal-safe math (steel_decimal) /// - Upserts into table_scripts and records dependencies in script_dependencies /// The whole operation is transactional. #[derive(Debug)] pub struct TableScriptServer { inner: Arc, accept_compression_encodings: EnabledCompressionEncodings, send_compression_encodings: EnabledCompressionEncodings, max_decoding_message_size: Option, max_encoding_message_size: Option, } impl TableScriptServer { pub fn new(inner: T) -> Self { Self::from_arc(Arc::new(inner)) } pub fn from_arc(inner: Arc) -> Self { Self { inner, accept_compression_encodings: Default::default(), send_compression_encodings: Default::default(), max_decoding_message_size: None, max_encoding_message_size: None, } } pub fn with_interceptor( inner: T, interceptor: F, ) -> InterceptedService where F: tonic::service::Interceptor, { InterceptedService::new(Self::new(inner), interceptor) } /// Enable decompressing requests with the given encoding. #[must_use] pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self { self.accept_compression_encodings.enable(encoding); self } /// Compress responses with the given encoding, if the client supports it. #[must_use] pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self { self.send_compression_encodings.enable(encoding); self } /// Limits the maximum size of a decoded message. /// /// Default: `4MB` #[must_use] pub fn max_decoding_message_size(mut self, limit: usize) -> Self { self.max_decoding_message_size = Some(limit); self } /// Limits the maximum size of an encoded message. /// /// Default: `usize::MAX` #[must_use] pub fn max_encoding_message_size(mut self, limit: usize) -> Self { self.max_encoding_message_size = Some(limit); self } } impl tonic::codegen::Service> for TableScriptServer where T: TableScript, B: Body + std::marker::Send + 'static, B::Error: Into + std::marker::Send + 'static, { type Response = http::Response; type Error = std::convert::Infallible; type Future = BoxFuture; fn poll_ready( &mut self, _cx: &mut Context<'_>, ) -> Poll> { Poll::Ready(Ok(())) } fn call(&mut self, req: http::Request) -> Self::Future { match req.uri().path() { "/komp_ac.table_script.TableScript/PostTableScript" => { #[allow(non_camel_case_types)] struct PostTableScriptSvc(pub Arc); impl< T: TableScript, > tonic::server::UnaryService for PostTableScriptSvc { type Response = super::TableScriptResponse; type Future = BoxFuture< tonic::Response, tonic::Status, >; fn call( &mut self, request: tonic::Request, ) -> Self::Future { let inner = Arc::clone(&self.0); let fut = async move { ::post_table_script(&inner, request).await }; Box::pin(fut) } } let accept_compression_encodings = self.accept_compression_encodings; let send_compression_encodings = self.send_compression_encodings; let max_decoding_message_size = self.max_decoding_message_size; let max_encoding_message_size = self.max_encoding_message_size; let inner = self.inner.clone(); let fut = async move { let method = PostTableScriptSvc(inner); let codec = tonic::codec::ProstCodec::default(); let mut grpc = tonic::server::Grpc::new(codec) .apply_compression_config( accept_compression_encodings, send_compression_encodings, ) .apply_max_message_size_config( max_decoding_message_size, max_encoding_message_size, ); let res = grpc.unary(method, req).await; Ok(res) }; Box::pin(fut) } "/komp_ac.table_script.TableScript/GetTableScripts" => { #[allow(non_camel_case_types)] struct GetTableScriptsSvc(pub Arc); impl< T: TableScript, > tonic::server::UnaryService for GetTableScriptsSvc { type Response = super::GetTableScriptsResponse; type Future = BoxFuture< tonic::Response, tonic::Status, >; fn call( &mut self, request: tonic::Request, ) -> Self::Future { let inner = Arc::clone(&self.0); let fut = async move { ::get_table_scripts(&inner, request).await }; Box::pin(fut) } } let accept_compression_encodings = self.accept_compression_encodings; let send_compression_encodings = self.send_compression_encodings; let max_decoding_message_size = self.max_decoding_message_size; let max_encoding_message_size = self.max_encoding_message_size; let inner = self.inner.clone(); let fut = async move { let method = GetTableScriptsSvc(inner); let codec = tonic::codec::ProstCodec::default(); let mut grpc = tonic::server::Grpc::new(codec) .apply_compression_config( accept_compression_encodings, send_compression_encodings, ) .apply_max_message_size_config( max_decoding_message_size, max_encoding_message_size, ); let res = grpc.unary(method, req).await; Ok(res) }; Box::pin(fut) } _ => { Box::pin(async move { let mut response = http::Response::new( tonic::body::Body::default(), ); let headers = response.headers_mut(); headers .insert( tonic::Status::GRPC_STATUS, (tonic::Code::Unimplemented as i32).into(), ); headers .insert( http::header::CONTENT_TYPE, tonic::metadata::GRPC_CONTENT_TYPE, ); Ok(response) }) } } } } impl Clone for TableScriptServer { fn clone(&self) -> Self { let inner = self.inner.clone(); Self { inner, accept_compression_encodings: self.accept_compression_encodings, send_compression_encodings: self.send_compression_encodings, max_decoding_message_size: self.max_decoding_message_size, max_encoding_message_size: self.max_encoding_message_size, } } } /// Generated gRPC service name pub const SERVICE_NAME: &str = "komp_ac.table_script.TableScript"; impl tonic::server::NamedService for TableScriptServer { const NAME: &'static str = SERVICE_NAME; } }