Compare commits

...

10 Commits

Author SHA1 Message Date
Priec
9b6e594d2f common build.rs migration bug fixed 2026-06-10 19:49:41 +02:00
Priec
617f18f331 working upgraded 2026-06-10 18:08:19 +02:00
Priec
5481d1cb13 moving towards upgraded crates 2026-06-10 17:22:42 +02:00
Priec
40ad0db13f bumping up versions safely 2026-06-10 13:44:51 +02:00
Priec
ed1d4be61b flake update and resolver update 2026-06-10 13:39:19 +02:00
Priec
394cd863e4 edition 2024 2026-06-10 13:26:51 +02:00
Priec
f73548649f tui pages canvas 2026-06-10 13:04:44 +02:00
Priec
bd204895d5 we are all at v0.7.5 welcome to bulk post, tui-pages support for canvas crate, moved validation-core crate 2026-06-07 17:51:51 +02:00
Priec
a05f1f2a1e removed formatter for rules 2026-05-29 12:18:13 +02:00
Priec
f11c6060ea tui pages is not prod ready yet 2026-05-26 21:52:53 +02:00
38 changed files with 2941 additions and 4002 deletions

2
.gitignore vendored
View File

@@ -8,3 +8,5 @@ canvas/*.toml
.aider* .aider*
.codex .codex
TODO.md TODO.md
tui-pages-cli/
tui-canvas-validation-core/

5
.gitmodules vendored
View File

@@ -2,8 +2,11 @@
path = client path = client
url = git@gitlab.com:filipriec/komp_ac_client.git url = git@gitlab.com:filipriec/komp_ac_client.git
[submodule "canvas"] [submodule "canvas"]
path = canvas path = tui-canvas
url = git@gitlab.com:filipriec/tui-canvas.git url = git@gitlab.com:filipriec/tui-canvas.git
[submodule "server"] [submodule "server"]
path = server path = server
url = git@gitlab.com:filipriec/komp_ac_server.git url = git@gitlab.com:filipriec/komp_ac_server.git
[submodule "tui-pages"]
path = tui-pages
url = git@gitlab.com:filipriec/tui-pages.git

3670
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,12 +1,12 @@
[workspace] [workspace]
members = ["client", "server", "common", "search", "canvas", "validation-core"] members = ["client", "server", "common", "search", "tui-canvas", "tui-canvas/tui-canvas-validation-core", "tui-pages" ]
resolver = "2" resolver = "3"
[workspace.package] [workspace.package]
# TODO: idk how to do the name, fix later # TODO: idk how to do the name, fix later
# name = "komp_ac" # name = "komp_ac"
version = "0.6.12" version = "0.8.2"
edition = "2021" edition = "2024"
license = "GPL-3.0-or-later" license = "GPL-3.0-or-later"
authors = ["Filip Priečinský <filippriec@gmail.com>"] authors = ["Filip Priečinský <filippriec@gmail.com>"]
description = "Poriadny uctovnicky software." description = "Poriadny uctovnicky software."
@@ -20,37 +20,36 @@ categories = ["command-line-interface"]
[workspace.dependencies] [workspace.dependencies]
# Async and gRPC # Async and gRPC
tokio = { version = "1.44.2", features = ["full"] } tokio = { version = "1.52.3", features = ["full"] }
tonic = "0.13.0" tonic = "0.14.6"
prost = "0.13.5" prost = "0.14.4"
async-trait = "0.1.88" async-trait = "0.1.89"
prost-types = "0.13.0" prost-types = "0.14.4"
# Data Handling & Serialization # Data Handling & Serialization
serde = { version = "1.0.219", features = ["derive"] } serde = { version = "1.0.228", features = ["derive"] }
serde_json = "1.0.140" serde_json = "1.0.150"
time = "0.3.41" time = "0.3.47"
# Utilities & Error Handling # Utilities & Error Handling
anyhow = "1.0.98" anyhow = "1.0.102"
dotenvy = "0.15.7" dotenvy = "0.15.7"
lazy_static = "1.5.0" lazy_static = "1.5.0"
tracing = "0.1.41" tracing = "0.1.44"
# Search crate # Search crate
tantivy = "0.24.1" tantivy = "0.26.1"
# Steel_decimal crate # Steel_decimal crate
rust_decimal = { version = "1.37.2", features = ["maths", "serde"] } rust_decimal = { version = "1.42.0", features = ["maths", "serde"] }
rust_decimal_macros = "1.37.1" rust_decimal_macros = "1.40.0"
thiserror = "2.0.12" thiserror = "2.0.18"
regex = "1.11.1" regex = "1.12.4"
# Canvas crate # Canvas crate
ratatui = { version = "0.29.0", features = ["crossterm"] } ratatui = { version = "0.30.1", features = ["crossterm"] }
crossterm = "0.28.1" crossterm = "0.29.0"
toml = "0.8.20" toml = "1.1.2"
unicode-width = "0.2.0" unicode-width = "0.2.2"
common = { path = "./common" } common = { path = "./common" }
validation-core = { path = "./validation-core" }

1
canvas

Submodule canvas deleted from e6c942dd41

2
client

Submodule client updated: 3badee28b1...e800ead957

View File

@@ -7,14 +7,16 @@ license.workspace = true
[dependencies] [dependencies]
prost-types = { workspace = true } prost-types = { workspace = true }
tonic = "0.13.0" tonic = "0.14.6"
prost = "0.13.5" prost = "0.14.4"
serde = { version = "1.0.219", features = ["derive"] } serde = { version = "1.0.228", features = ["derive"] }
# Search # Search
tantivy = { workspace = true } tantivy = { workspace = true }
serde_json.workspace = true serde_json.workspace = true
tonic-prost = "0.14.6"
[build-dependencies] [build-dependencies]
tonic-build = { version = "0.13.0", features = ["prost-build"] } tonic-build = { version = "0.14.6" }
prost-build = "0.14.1" prost-build = "0.14.4"
tonic-prost-build = "0.14.6"

View File

@@ -1,5 +1,5 @@
fn main() -> Result<(), Box<dyn std::error::Error>> { fn main() -> Result<(), Box<dyn std::error::Error>> {
tonic_build::configure() tonic_prost_build::configure()
.build_server(true) .build_server(true)
.file_descriptor_set_path("src/proto/descriptor.bin") .file_descriptor_set_path("src/proto/descriptor.bin")
.out_dir("src/proto") .out_dir("src/proto")
@@ -40,14 +40,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
".komp_ac.table_validation.PatternRules", ".komp_ac.table_validation.PatternRules",
"#[derive(serde::Serialize, serde::Deserialize)]", "#[derive(serde::Serialize, serde::Deserialize)]",
) )
.type_attribute(
".komp_ac.table_validation.CustomFormatter",
"#[derive(serde::Serialize, serde::Deserialize)]",
)
.type_attribute(
".komp_ac.table_validation.FormatterOption",
"#[derive(serde::Serialize, serde::Deserialize)]",
)
.type_attribute( .type_attribute(
".komp_ac.table_validation.AllowedValues", ".komp_ac.table_validation.AllowedValues",
"#[derive(serde::Serialize, serde::Deserialize)]", "#[derive(serde::Serialize, serde::Deserialize)]",
@@ -225,5 +217,29 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
], ],
&["proto"], &["proto"],
)?; )?;
// Scope build-script reruns to the actual inputs. Without this, the script
// emits no `rerun-if-changed` directives, so Cargo reruns it whenever any
// file in the package changes. Since codegen writes into `src/proto/`, that
// self-write retriggers the script on every build (an infinite loop under
// `cargo watch`). tonic_build 0.13 emitted these automatically; 0.14
// (tonic_prost_build) no longer does.
println!("cargo:rerun-if-changed=build.rs");
for proto in [
"proto/common.proto",
"proto/adresar.proto",
"proto/auth.proto",
"proto/search.proto",
"proto/search2.proto",
"proto/table_definition.proto",
"proto/table_script.proto",
"proto/table_structure.proto",
"proto/table_validation.proto",
"proto/tables_data.proto",
"proto/uctovnictvo.proto",
] {
println!("cargo:rerun-if-changed={proto}");
}
Ok(()) Ok(())
} }

View File

@@ -13,7 +13,7 @@ package komp_ac.table_validation;
// //
// Important split: // Important split:
// - limits / pattern / allowed_values / required are validation rules. // - limits / pattern / allowed_values / required are validation rules.
// - mask / formatter are presentation and input-shaping metadata for clients. // - mask is presentation and input-shaping metadata for clients.
// Request validation rules for a table // Request validation rules for a table
message GetTableValidationRequest { message GetTableValidationRequest {
@@ -44,9 +44,6 @@ message FieldValidation {
// Client-side hint that this field participates in external/asynchronous validation UI. // Client-side hint that this field participates in external/asynchronous validation UI.
bool external_validation_enabled = 13; bool external_validation_enabled = 13;
// Client-side formatter metadata. This is intentionally data-only, not executable code.
optional CustomFormatter formatter = 14;
// Client-side display mask metadata. The server stores raw data without mask literals. // Client-side display mask metadata. The server stores raw data without mask literals.
DisplayMask mask = 3; DisplayMask mask = 3;
@@ -139,22 +136,6 @@ message PatternRule {
CharacterConstraint constraint = 2; CharacterConstraint constraint = 2;
} }
// Client-side formatter metadata.
// The formatter "type" is intended to be resolved by a client-side formatter registry.
message CustomFormatter {
// Formatter type identifier; handled clientside.
// Examples: "PSCFormatter", "PhoneFormatter", "CreditCardFormatter", "DateFormatter"
string type = 1;
repeated FormatterOption options = 2;
optional string description = 3;
}
message FormatterOption {
string key = 1;
string value = 2;
}
// Exact-value whitelist configuration. // Exact-value whitelist configuration.
// This maps to canvas AllowedValues semantics. // This maps to canvas AllowedValues semantics.
message AllowedValues { message AllowedValues {

View File

@@ -23,6 +23,17 @@ service TablesData {
// - If the physical table is missing but the definition exists, returns INTERNAL // - If the physical table is missing but the definition exists, returns INTERNAL
rpc PostTableData(PostTableDataRequest) returns (PostTableDataResponse); rpc PostTableData(PostTableDataRequest) returns (PostTableDataResponse);
// Insert multiple rows by applying PostTableData behavior to each row.
//
// Behavior:
// - Accepts 1..10,000 rows in one gRPC request
// - Processes rows in request order
// - Each row is inserted through the same validation, script execution,
// typed binding, database insert, and indexing path as PostTableData
// - Stops at the first failing row and returns that row's gRPC error code
// with row index context; rows inserted before the failure remain inserted
rpc PostTableDataBulk(PostTableDataBulkRequest) returns (PostTableDataBulkResponse);
// Update existing row data with strict type binding and script validation. // Update existing row data with strict type binding and script validation.
// //
// Behavior: // Behavior:
@@ -124,6 +135,36 @@ message PostTableDataResponse {
int64 inserted_id = 3; int64 inserted_id = 3;
} }
// One row in a bulk insert request.
message PostTableDataBulkRow {
// Required. Same data payload as PostTableDataRequest.data.
map<string, google.protobuf.Value> data = 1;
}
// Bulk insert request.
message PostTableDataBulkRequest {
// Required. Profile (PostgreSQL schema) name that owns the table.
string profile_name = 1;
// Required. Logical table (definition) name within the profile.
string table_name = 2;
// Required. Rows to insert. Must contain at least 1 and at most 10,000 rows.
repeated PostTableDataBulkRow rows = 3;
}
// Bulk insert response.
message PostTableDataBulkResponse {
// True if all rows were inserted successfully.
bool success = 1;
// Human-readable message.
string message = 2;
// Per-row responses from the underlying PostTableData logic, in request order.
repeated PostTableDataResponse responses = 3;
}
// Update an existing row. // Update an existing row.
message PutTableDataRequest { message PutTableDataRequest {
// Required. Profile (schema) name. // Required. Profile (schema) name.

Binary file not shown.

View File

@@ -1,15 +1,15 @@
// This file is @generated by prost-build. // This file is @generated by prost-build.
#[derive(Clone, Copy, PartialEq, ::prost::Message)] #[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct GetAdresarRequest { pub struct GetAdresarRequest {
#[prost(int64, tag = "1")] #[prost(int64, tag = "1")]
pub id: i64, pub id: i64,
} }
#[derive(Clone, Copy, PartialEq, ::prost::Message)] #[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct DeleteAdresarRequest { pub struct DeleteAdresarRequest {
#[prost(int64, tag = "1")] #[prost(int64, tag = "1")]
pub id: i64, pub id: i64,
} }
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct PostAdresarRequest { pub struct PostAdresarRequest {
#[prost(string, tag = "1")] #[prost(string, tag = "1")]
pub firma: ::prost::alloc::string::String, pub firma: ::prost::alloc::string::String,
@@ -42,7 +42,7 @@ pub struct PostAdresarRequest {
#[prost(string, tag = "15")] #[prost(string, tag = "15")]
pub fax: ::prost::alloc::string::String, pub fax: ::prost::alloc::string::String,
} }
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct AdresarResponse { pub struct AdresarResponse {
#[prost(int64, tag = "1")] #[prost(int64, tag = "1")]
pub id: i64, pub id: i64,
@@ -77,7 +77,7 @@ pub struct AdresarResponse {
#[prost(string, tag = "16")] #[prost(string, tag = "16")]
pub fax: ::prost::alloc::string::String, pub fax: ::prost::alloc::string::String,
} }
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct PutAdresarRequest { pub struct PutAdresarRequest {
#[prost(int64, tag = "1")] #[prost(int64, tag = "1")]
pub id: i64, pub id: i64,
@@ -112,7 +112,7 @@ pub struct PutAdresarRequest {
#[prost(string, tag = "16")] #[prost(string, tag = "16")]
pub fax: ::prost::alloc::string::String, pub fax: ::prost::alloc::string::String,
} }
#[derive(Clone, Copy, PartialEq, ::prost::Message)] #[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct DeleteAdresarResponse { pub struct DeleteAdresarResponse {
#[prost(bool, tag = "1")] #[prost(bool, tag = "1")]
pub success: bool, pub success: bool,
@@ -223,7 +223,7 @@ pub mod adresar_client {
format!("Service was not ready: {}", e.into()), format!("Service was not ready: {}", e.into()),
) )
})?; })?;
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static( let path = http::uri::PathAndQuery::from_static(
"/komp_ac.adresar.Adresar/PostAdresar", "/komp_ac.adresar.Adresar/PostAdresar",
); );
@@ -247,7 +247,7 @@ pub mod adresar_client {
format!("Service was not ready: {}", e.into()), format!("Service was not ready: {}", e.into()),
) )
})?; })?;
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static( let path = http::uri::PathAndQuery::from_static(
"/komp_ac.adresar.Adresar/GetAdresar", "/komp_ac.adresar.Adresar/GetAdresar",
); );
@@ -271,7 +271,7 @@ pub mod adresar_client {
format!("Service was not ready: {}", e.into()), format!("Service was not ready: {}", e.into()),
) )
})?; })?;
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static( let path = http::uri::PathAndQuery::from_static(
"/komp_ac.adresar.Adresar/PutAdresar", "/komp_ac.adresar.Adresar/PutAdresar",
); );
@@ -295,7 +295,7 @@ pub mod adresar_client {
format!("Service was not ready: {}", e.into()), format!("Service was not ready: {}", e.into()),
) )
})?; })?;
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static( let path = http::uri::PathAndQuery::from_static(
"/komp_ac.adresar.Adresar/DeleteAdresar", "/komp_ac.adresar.Adresar/DeleteAdresar",
); );
@@ -319,7 +319,7 @@ pub mod adresar_client {
format!("Service was not ready: {}", e.into()), format!("Service was not ready: {}", e.into()),
) )
})?; })?;
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static( let path = http::uri::PathAndQuery::from_static(
"/komp_ac.adresar.Adresar/GetAdresarCount", "/komp_ac.adresar.Adresar/GetAdresarCount",
); );
@@ -343,7 +343,7 @@ pub mod adresar_client {
format!("Service was not ready: {}", e.into()), format!("Service was not ready: {}", e.into()),
) )
})?; })?;
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static( let path = http::uri::PathAndQuery::from_static(
"/komp_ac.adresar.Adresar/GetAdresarByPosition", "/komp_ac.adresar.Adresar/GetAdresarByPosition",
); );
@@ -506,7 +506,7 @@ pub mod adresar_server {
let inner = self.inner.clone(); let inner = self.inner.clone();
let fut = async move { let fut = async move {
let method = PostAdresarSvc(inner); let method = PostAdresarSvc(inner);
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec) let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config( .apply_compression_config(
accept_compression_encodings, accept_compression_encodings,
@@ -551,7 +551,7 @@ pub mod adresar_server {
let inner = self.inner.clone(); let inner = self.inner.clone();
let fut = async move { let fut = async move {
let method = GetAdresarSvc(inner); let method = GetAdresarSvc(inner);
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec) let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config( .apply_compression_config(
accept_compression_encodings, accept_compression_encodings,
@@ -596,7 +596,7 @@ pub mod adresar_server {
let inner = self.inner.clone(); let inner = self.inner.clone();
let fut = async move { let fut = async move {
let method = PutAdresarSvc(inner); let method = PutAdresarSvc(inner);
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec) let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config( .apply_compression_config(
accept_compression_encodings, accept_compression_encodings,
@@ -641,7 +641,7 @@ pub mod adresar_server {
let inner = self.inner.clone(); let inner = self.inner.clone();
let fut = async move { let fut = async move {
let method = DeleteAdresarSvc(inner); let method = DeleteAdresarSvc(inner);
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec) let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config( .apply_compression_config(
accept_compression_encodings, accept_compression_encodings,
@@ -686,7 +686,7 @@ pub mod adresar_server {
let inner = self.inner.clone(); let inner = self.inner.clone();
let fut = async move { let fut = async move {
let method = GetAdresarCountSvc(inner); let method = GetAdresarCountSvc(inner);
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec) let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config( .apply_compression_config(
accept_compression_encodings, accept_compression_encodings,
@@ -734,7 +734,7 @@ pub mod adresar_server {
let inner = self.inner.clone(); let inner = self.inner.clone();
let fut = async move { let fut = async move {
let method = GetAdresarByPositionSvc(inner); let method = GetAdresarByPositionSvc(inner);
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec) let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config( .apply_compression_config(
accept_compression_encodings, accept_compression_encodings,

View File

@@ -1,5 +1,5 @@
// This file is @generated by prost-build. // This file is @generated by prost-build.
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct RegisterRequest { pub struct RegisterRequest {
#[prost(string, tag = "1")] #[prost(string, tag = "1")]
pub username: ::prost::alloc::string::String, pub username: ::prost::alloc::string::String,
@@ -12,7 +12,7 @@ pub struct RegisterRequest {
#[prost(string, tag = "5")] #[prost(string, tag = "5")]
pub role: ::prost::alloc::string::String, pub role: ::prost::alloc::string::String,
} }
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct AuthResponse { pub struct AuthResponse {
/// UUID in string format /// UUID in string format
#[prost(string, tag = "1")] #[prost(string, tag = "1")]
@@ -27,7 +27,7 @@ pub struct AuthResponse {
#[prost(string, tag = "4")] #[prost(string, tag = "4")]
pub role: ::prost::alloc::string::String, pub role: ::prost::alloc::string::String,
} }
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct LoginRequest { pub struct LoginRequest {
/// Can be username or email /// Can be username or email
#[prost(string, tag = "1")] #[prost(string, tag = "1")]
@@ -35,7 +35,7 @@ pub struct LoginRequest {
#[prost(string, tag = "2")] #[prost(string, tag = "2")]
pub password: ::prost::alloc::string::String, pub password: ::prost::alloc::string::String,
} }
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct LoginResponse { pub struct LoginResponse {
/// JWT token /// JWT token
#[prost(string, tag = "1")] #[prost(string, tag = "1")]
@@ -158,7 +158,7 @@ pub mod auth_service_client {
format!("Service was not ready: {}", e.into()), format!("Service was not ready: {}", e.into()),
) )
})?; })?;
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static( let path = http::uri::PathAndQuery::from_static(
"/komp_ac.auth.AuthService/Register", "/komp_ac.auth.AuthService/Register",
); );
@@ -179,7 +179,7 @@ pub mod auth_service_client {
format!("Service was not ready: {}", e.into()), format!("Service was not ready: {}", e.into()),
) )
})?; })?;
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static( let path = http::uri::PathAndQuery::from_static(
"/komp_ac.auth.AuthService/Login", "/komp_ac.auth.AuthService/Login",
); );
@@ -318,7 +318,7 @@ pub mod auth_service_server {
let inner = self.inner.clone(); let inner = self.inner.clone();
let fut = async move { let fut = async move {
let method = RegisterSvc(inner); let method = RegisterSvc(inner);
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec) let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config( .apply_compression_config(
accept_compression_encodings, accept_compression_encodings,
@@ -361,7 +361,7 @@ pub mod auth_service_server {
let inner = self.inner.clone(); let inner = self.inner.clone();
let fut = async move { let fut = async move {
let method = LoginSvc(inner); let method = LoginSvc(inner);
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec) let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config( .apply_compression_config(
accept_compression_encodings, accept_compression_encodings,

View File

@@ -1,12 +1,12 @@
// This file is @generated by prost-build. // This file is @generated by prost-build.
#[derive(Clone, Copy, PartialEq, ::prost::Message)] #[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct Empty {} pub struct Empty {}
#[derive(Clone, Copy, PartialEq, ::prost::Message)] #[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct CountResponse { pub struct CountResponse {
#[prost(int64, tag = "1")] #[prost(int64, tag = "1")]
pub count: i64, pub count: i64,
} }
#[derive(Clone, Copy, PartialEq, ::prost::Message)] #[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct PositionRequest { pub struct PositionRequest {
#[prost(int64, tag = "1")] #[prost(int64, tag = "1")]
pub position: i64, pub position: i64,

View File

@@ -1,5 +1,5 @@
// This file is @generated by prost-build. // This file is @generated by prost-build.
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct ColumnConstraint { pub struct ColumnConstraint {
#[prost(string, tag = "1")] #[prost(string, tag = "1")]
pub column: ::prost::alloc::string::String, pub column: ::prost::alloc::string::String,
@@ -173,7 +173,7 @@ pub mod searcher_client {
format!("Service was not ready: {}", e.into()), format!("Service was not ready: {}", e.into()),
) )
})?; })?;
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static( let path = http::uri::PathAndQuery::from_static(
"/komp_ac.search.Searcher/Search", "/komp_ac.search.Searcher/Search",
); );
@@ -306,7 +306,7 @@ pub mod searcher_server {
let inner = self.inner.clone(); let inner = self.inner.clone();
let fut = async move { let fut = async move {
let method = SearchSvc(inner); let method = SearchSvc(inner);
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec) let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config( .apply_compression_config(
accept_compression_encodings, accept_compression_encodings,

View File

@@ -17,7 +17,7 @@ pub struct Search2Request {
#[prost(bool, optional, tag = "7")] #[prost(bool, optional, tag = "7")]
pub order_desc: ::core::option::Option<bool>, pub order_desc: ::core::option::Option<bool>,
} }
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct ColumnFilter { pub struct ColumnFilter {
#[prost(string, tag = "1")] #[prost(string, tag = "1")]
pub column_name: ::prost::alloc::string::String, pub column_name: ::prost::alloc::string::String,
@@ -39,7 +39,7 @@ pub struct Search2Response {
} }
/// Nested message and enum types in `Search2Response`. /// Nested message and enum types in `Search2Response`.
pub mod search2_response { pub mod search2_response {
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct Hit { pub struct Hit {
#[prost(int64, tag = "1")] #[prost(int64, tag = "1")]
pub id: i64, pub id: i64,
@@ -204,7 +204,7 @@ pub mod search2_client {
format!("Service was not ready: {}", e.into()), format!("Service was not ready: {}", e.into()),
) )
})?; })?;
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static( let path = http::uri::PathAndQuery::from_static(
"/komp_ac.search2.Search2/SearchTable", "/komp_ac.search2.Search2/SearchTable",
); );
@@ -337,7 +337,7 @@ pub mod search2_server {
let inner = self.inner.clone(); let inner = self.inner.clone();
let fut = async move { let fut = async move {
let method = SearchTableSvc(inner); let method = SearchTableSvc(inner);
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec) let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config( .apply_compression_config(
accept_compression_encodings, accept_compression_encodings,

View File

@@ -1,10 +1,10 @@
// This file is @generated by prost-build. // This file is @generated by prost-build.
/// A single link to another table within the same profile (schema). /// A single link to another table within the same profile (schema).
#[derive(serde::Serialize, serde::Deserialize)] #[derive(serde::Serialize, serde::Deserialize)]
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct TableLink { pub struct TableLink {
/// Name of an existing table within the same profile to link to. /// Name of an existing table within the same profile to link to.
/// For each link, a "<linked>_id" column is created on the new table. /// For each link, a "<linked>\_id" column is created on the new table.
/// That column references "<linked>"(id) and adds an index automatically. /// That column references "<linked>"(id) and adds an index automatically.
#[prost(string, tag = "1")] #[prost(string, tag = "1")]
pub linked_table_name: ::prost::alloc::string::String, pub linked_table_name: ::prost::alloc::string::String,
@@ -20,12 +20,12 @@ pub struct TableLink {
pub struct PostTableDefinitionRequest { pub struct PostTableDefinitionRequest {
/// Table name to create inside the target profile. /// Table name to create inside the target profile.
/// Must be lowercase, alphanumeric with underscores, /// Must be lowercase, alphanumeric with underscores,
/// start with a letter, and be <= 63 chars. /// start with a letter, and be \<= 63 chars.
/// Forbidden names: "id", "deleted", "created_at", or ending in "_id". /// Forbidden names: "id", "deleted", "created_at", or ending in "\_id".
#[prost(string, tag = "1")] #[prost(string, tag = "1")]
pub table_name: ::prost::alloc::string::String, pub table_name: ::prost::alloc::string::String,
/// List of links (foreign keys) to existing tables in the same profile. /// List of links (foreign keys) to existing tables in the same profile.
/// Each will automatically get a "<linked>_id" column and an index. /// Each will automatically get a "<linked>\_id" column and an index.
#[prost(message, repeated, tag = "2")] #[prost(message, repeated, tag = "2")]
pub links: ::prost::alloc::vec::Vec<TableLink>, pub links: ::prost::alloc::vec::Vec<TableLink>,
/// List of user-defined columns (adds to system/id/fk columns). /// List of user-defined columns (adds to system/id/fk columns).
@@ -33,13 +33,13 @@ pub struct PostTableDefinitionRequest {
pub columns: ::prost::alloc::vec::Vec<ColumnDefinition>, pub columns: ::prost::alloc::vec::Vec<ColumnDefinition>,
/// List of column names to be indexed (must match existing user-defined columns). /// List of column names to be indexed (must match existing user-defined columns).
/// Indexes can target only user-defined columns; system columns ("id", "deleted", /// Indexes can target only user-defined columns; system columns ("id", "deleted",
/// "created_at") and automatically generated foreign key ("*_id") columns already /// "created_at") and automatically generated foreign key ("\*\_id") columns already
/// have indexes. Requests trying to index those columns are rejected. /// have indexes. Requests trying to index those columns are rejected.
#[prost(string, repeated, tag = "4")] #[prost(string, repeated, tag = "4")]
pub indexes: ::prost::alloc::vec::Vec<::prost::alloc::string::String>, pub indexes: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
/// Name of profile (Postgres schema) where the table will be created. /// Name of profile (Postgres schema) where the table will be created.
/// Same naming rules as table_name; cannot collide with reserved schemas /// Same naming rules as table_name; cannot collide with reserved schemas
/// like "public", "information_schema", or ones starting with "pg_". /// like "public", "information_schema", or ones starting with "pg\_".
#[prost(string, tag = "5")] #[prost(string, tag = "5")]
pub profile_name: ::prost::alloc::string::String, pub profile_name: ::prost::alloc::string::String,
} }
@@ -62,11 +62,11 @@ pub struct AddTableColumnsRequest {
} }
/// Describes one user-defined column for a table. /// Describes one user-defined column for a table.
#[derive(serde::Serialize, serde::Deserialize)] #[derive(serde::Serialize, serde::Deserialize)]
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct ColumnDefinition { pub struct ColumnDefinition {
/// Column name that follows the same validation rules as table_name. /// Column name that follows the same validation rules as table_name.
/// Must be lowercase, start with a letter, no uppercase characters, /// Must be lowercase, start with a letter, no uppercase characters,
/// and cannot be "id", "deleted", "created_at", or end with "_id". /// and cannot be "id", "deleted", "created_at", or end with "\_id".
#[prost(string, tag = "1")] #[prost(string, tag = "1")]
pub name: ::prost::alloc::string::String, pub name: ::prost::alloc::string::String,
/// Logical column type. Supported values (case-insensitive): /// Logical column type. Supported values (case-insensitive):
@@ -85,7 +85,7 @@ pub struct ColumnDefinition {
} }
/// Response after table creation (success + DDL preview). /// Response after table creation (success + DDL preview).
#[derive(serde::Serialize, serde::Deserialize)] #[derive(serde::Serialize, serde::Deserialize)]
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct TableDefinitionResponse { pub struct TableDefinitionResponse {
/// True if all DB changes and metadata inserts succeeded. /// True if all DB changes and metadata inserts succeeded.
#[prost(bool, tag = "1")] #[prost(bool, tag = "1")]
@@ -104,7 +104,7 @@ pub struct ProfileTreeResponse {
/// Nested message and enum types in `ProfileTreeResponse`. /// Nested message and enum types in `ProfileTreeResponse`.
pub mod profile_tree_response { pub mod profile_tree_response {
/// Table entry in a profile. /// Table entry in a profile.
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct Table { pub struct Table {
/// Internal ID from table_definitions.id (metadata record). /// Internal ID from table_definitions.id (metadata record).
#[prost(int64, tag = "1")] #[prost(int64, tag = "1")]
@@ -128,7 +128,7 @@ pub mod profile_tree_response {
} }
} }
/// Request to fetch all tables, columns and scripts for a profile. /// Request to fetch all tables, columns and scripts for a profile.
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct GetProfileDetailsRequest { pub struct GetProfileDetailsRequest {
/// Profile (schema) name to fetch details for. /// Profile (schema) name to fetch details for.
#[prost(string, tag = "1")] #[prost(string, tag = "1")]
@@ -144,7 +144,7 @@ pub struct GetProfileDetailsResponse {
} }
/// Request to fetch recorded column alias rename history for one profile. /// Request to fetch recorded column alias rename history for one profile.
#[derive(serde::Serialize, serde::Deserialize)] #[derive(serde::Serialize, serde::Deserialize)]
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct GetColumnAliasRenameHistoryRequest { pub struct GetColumnAliasRenameHistoryRequest {
#[prost(string, tag = "1")] #[prost(string, tag = "1")]
pub profile_name: ::prost::alloc::string::String, pub profile_name: ::prost::alloc::string::String,
@@ -154,7 +154,7 @@ pub struct GetColumnAliasRenameHistoryRequest {
} }
/// One recorded column alias rename. /// One recorded column alias rename.
#[derive(serde::Serialize, serde::Deserialize)] #[derive(serde::Serialize, serde::Deserialize)]
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct ColumnAliasRenameHistoryEntry { pub struct ColumnAliasRenameHistoryEntry {
#[prost(int64, tag = "1")] #[prost(int64, tag = "1")]
pub id: i64, pub id: i64,
@@ -193,7 +193,7 @@ pub struct TableDetail {
pub scripts: ::prost::alloc::vec::Vec<ScriptInfo>, pub scripts: ::prost::alloc::vec::Vec<ScriptInfo>,
} }
/// A script that targets a specific column in a table. /// A script that targets a specific column in a table.
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct ScriptInfo { pub struct ScriptInfo {
#[prost(int64, tag = "1")] #[prost(int64, tag = "1")]
pub script_id: i64, pub script_id: i64,
@@ -208,7 +208,7 @@ pub struct ScriptInfo {
} }
/// Request to rename one user-visible column alias in a table. /// Request to rename one user-visible column alias in a table.
#[derive(serde::Serialize, serde::Deserialize)] #[derive(serde::Serialize, serde::Deserialize)]
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct RenameColumnAliasRequest { pub struct RenameColumnAliasRequest {
#[prost(string, tag = "1")] #[prost(string, tag = "1")]
pub profile_name: ::prost::alloc::string::String, pub profile_name: ::prost::alloc::string::String,
@@ -221,7 +221,7 @@ pub struct RenameColumnAliasRequest {
} }
/// Response after renaming one column alias. /// Response after renaming one column alias.
#[derive(serde::Serialize, serde::Deserialize)] #[derive(serde::Serialize, serde::Deserialize)]
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct RenameColumnAliasResponse { pub struct RenameColumnAliasResponse {
#[prost(bool, tag = "1")] #[prost(bool, tag = "1")]
pub success: bool, pub success: bool,
@@ -229,7 +229,7 @@ pub struct RenameColumnAliasResponse {
pub message: ::prost::alloc::string::String, pub message: ::prost::alloc::string::String,
} }
/// Request to delete one table definition entirely. /// Request to delete one table definition entirely.
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct DeleteTableRequest { pub struct DeleteTableRequest {
/// Profile (schema) name owning the table (must exist). /// Profile (schema) name owning the table (must exist).
#[prost(string, tag = "1")] #[prost(string, tag = "1")]
@@ -240,7 +240,7 @@ pub struct DeleteTableRequest {
pub table_name: ::prost::alloc::string::String, pub table_name: ::prost::alloc::string::String,
} }
/// Response after table deletion. /// Response after table deletion.
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct DeleteTableResponse { pub struct DeleteTableResponse {
/// True if table and metadata were successfully deleted in one transaction. /// True if table and metadata were successfully deleted in one transaction.
#[prost(bool, tag = "1")] #[prost(bool, tag = "1")]
@@ -362,7 +362,7 @@ pub mod table_definition_client {
format!("Service was not ready: {}", e.into()), format!("Service was not ready: {}", e.into()),
) )
})?; })?;
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static( let path = http::uri::PathAndQuery::from_static(
"/komp_ac.table_definition.TableDefinition/PostTableDefinition", "/komp_ac.table_definition.TableDefinition/PostTableDefinition",
); );
@@ -393,7 +393,7 @@ pub mod table_definition_client {
format!("Service was not ready: {}", e.into()), format!("Service was not ready: {}", e.into()),
) )
})?; })?;
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static( let path = http::uri::PathAndQuery::from_static(
"/komp_ac.table_definition.TableDefinition/AddTableColumns", "/komp_ac.table_definition.TableDefinition/AddTableColumns",
); );
@@ -424,7 +424,7 @@ pub mod table_definition_client {
format!("Service was not ready: {}", e.into()), format!("Service was not ready: {}", e.into()),
) )
})?; })?;
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static( let path = http::uri::PathAndQuery::from_static(
"/komp_ac.table_definition.TableDefinition/GetProfileTree", "/komp_ac.table_definition.TableDefinition/GetProfileTree",
); );
@@ -455,7 +455,7 @@ pub mod table_definition_client {
format!("Service was not ready: {}", e.into()), format!("Service was not ready: {}", e.into()),
) )
})?; })?;
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static( let path = http::uri::PathAndQuery::from_static(
"/komp_ac.table_definition.TableDefinition/GetProfileDetails", "/komp_ac.table_definition.TableDefinition/GetProfileDetails",
); );
@@ -485,7 +485,7 @@ pub mod table_definition_client {
format!("Service was not ready: {}", e.into()), format!("Service was not ready: {}", e.into()),
) )
})?; })?;
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static( let path = http::uri::PathAndQuery::from_static(
"/komp_ac.table_definition.TableDefinition/GetColumnAliasRenameHistory", "/komp_ac.table_definition.TableDefinition/GetColumnAliasRenameHistory",
); );
@@ -515,7 +515,7 @@ pub mod table_definition_client {
format!("Service was not ready: {}", e.into()), format!("Service was not ready: {}", e.into()),
) )
})?; })?;
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static( let path = http::uri::PathAndQuery::from_static(
"/komp_ac.table_definition.TableDefinition/RenameColumnAlias", "/komp_ac.table_definition.TableDefinition/RenameColumnAlias",
); );
@@ -545,7 +545,7 @@ pub mod table_definition_client {
format!("Service was not ready: {}", e.into()), format!("Service was not ready: {}", e.into()),
) )
})?; })?;
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static( let path = http::uri::PathAndQuery::from_static(
"/komp_ac.table_definition.TableDefinition/DeleteTable", "/komp_ac.table_definition.TableDefinition/DeleteTable",
); );
@@ -750,7 +750,7 @@ pub mod table_definition_server {
let inner = self.inner.clone(); let inner = self.inner.clone();
let fut = async move { let fut = async move {
let method = PostTableDefinitionSvc(inner); let method = PostTableDefinitionSvc(inner);
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec) let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config( .apply_compression_config(
accept_compression_encodings, accept_compression_encodings,
@@ -796,7 +796,7 @@ pub mod table_definition_server {
let inner = self.inner.clone(); let inner = self.inner.clone();
let fut = async move { let fut = async move {
let method = AddTableColumnsSvc(inner); let method = AddTableColumnsSvc(inner);
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec) let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config( .apply_compression_config(
accept_compression_encodings, accept_compression_encodings,
@@ -842,7 +842,7 @@ pub mod table_definition_server {
let inner = self.inner.clone(); let inner = self.inner.clone();
let fut = async move { let fut = async move {
let method = GetProfileTreeSvc(inner); let method = GetProfileTreeSvc(inner);
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec) let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config( .apply_compression_config(
accept_compression_encodings, accept_compression_encodings,
@@ -888,7 +888,7 @@ pub mod table_definition_server {
let inner = self.inner.clone(); let inner = self.inner.clone();
let fut = async move { let fut = async move {
let method = GetProfileDetailsSvc(inner); let method = GetProfileDetailsSvc(inner);
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec) let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config( .apply_compression_config(
accept_compression_encodings, accept_compression_encodings,
@@ -942,7 +942,7 @@ pub mod table_definition_server {
let inner = self.inner.clone(); let inner = self.inner.clone();
let fut = async move { let fut = async move {
let method = GetColumnAliasRenameHistorySvc(inner); let method = GetColumnAliasRenameHistorySvc(inner);
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec) let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config( .apply_compression_config(
accept_compression_encodings, accept_compression_encodings,
@@ -988,7 +988,7 @@ pub mod table_definition_server {
let inner = self.inner.clone(); let inner = self.inner.clone();
let fut = async move { let fut = async move {
let method = RenameColumnAliasSvc(inner); let method = RenameColumnAliasSvc(inner);
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec) let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config( .apply_compression_config(
accept_compression_encodings, accept_compression_encodings,
@@ -1033,7 +1033,7 @@ pub mod table_definition_server {
let inner = self.inner.clone(); let inner = self.inner.clone();
let fut = async move { let fut = async move {
let method = DeleteTableSvc(inner); let method = DeleteTableSvc(inner);
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec) let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config( .apply_compression_config(
accept_compression_encodings, accept_compression_encodings,

View File

@@ -1,7 +1,7 @@
// This file is @generated by prost-build. // This file is @generated by prost-build.
/// Request to create or update a script bound to a specific table and column. /// Request to create or update a script bound to a specific table and column.
#[derive(serde::Serialize, serde::Deserialize)] #[derive(serde::Serialize, serde::Deserialize)]
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct PostTableScriptRequest { pub struct PostTableScriptRequest {
/// Required. The metadata ID from table_definitions.id that identifies the /// Required. The metadata ID from table_definitions.id that identifies the
/// table this script belongs to. The table must exist; its schema determines /// table this script belongs to. The table must exist; its schema determines
@@ -18,35 +18,39 @@ pub struct PostTableScriptRequest {
pub target_column: ::prost::alloc::string::String, pub target_column: ::prost::alloc::string::String,
/// Required. The script in the Steel DSL (S-expression style). /// Required. The script in the Steel DSL (S-expression style).
/// Syntax requirements: /// Syntax requirements:
/// - Non-empty, must start with '(' ///
/// - Balanced parentheses /// * Non-empty, must start with '('
/// * Balanced parentheses
/// ///
/// Referencing data: /// Referencing data:
/// - Structured table/column access (enforces link constraints): ///
/// * Structured table/column access (enforces link constraints):
/// (steel_get_column "table_name" "column_name") /// (steel_get_column "table_name" "column_name")
/// (steel_get_column_with_index "table_name" index "column_name") /// (steel_get_column_with_index "table_name" index "column_name")
/// • index must be a non-negative integer literal /// • index must be a non-negative integer literal
/// • self-references are allowed without links /// • self-references are allowed without links
/// • other tables require an explicit link from the source table /// • other tables require an explicit link from the source table
/// (table_definition_links) or the request fails /// (table_definition_links) or the request fails
/// - Raw SQL access (no link required, but still validated): /// * Raw SQL access (no link required, but still validated):
/// (steel_query_sql "SELECT ...") /// (steel_query_sql "SELECT ...")
/// • Basic checks disallow operations that imply prohibited types, /// • Basic checks disallow operations that imply prohibited types,
/// e.g., EXTRACT(…), DATE_PART(…), ::DATE, ::TIMESTAMPTZ, ::BIGINT, CAST(…) /// e.g., EXTRACT(…), DATE_PART(…), ::DATE, ::TIMESTAMPTZ, ::BIGINT, CAST(…)
/// - Self variable access in transformed scripts: /// * Self variable access in transformed scripts:
/// (get-var "column_name") is treated as referencing the current table /// (get-var "column_name") is treated as referencing the current table
/// ///
/// Math operations: /// Math operations:
/// - The script is transformed by steel_decimal; supported math forms include: ///
/// +, -, *, /, ^, **, pow, sqrt, >, <, =, >=, <=, min, max, abs, round, /// * The script is transformed by steel_decimal; supported math forms include:
/// +, -, \*, /, ^, \*\*, pow, sqrt, >, \<, =, >=, \<=, min, max, abs, round,
/// ln, log, log10, exp, sin, cos, tan /// ln, log, log10, exp, sin, cos, tan
/// - Columns of the following types CANNOT be used inside math expressions: /// * Columns of the following types CANNOT be used inside math expressions:
/// BIGINT, TEXT, BOOLEAN, DATE, TIMESTAMPTZ /// BIGINT, TEXT, BOOLEAN, DATE, TIMESTAMPTZ
/// ///
/// Dependency tracking and cycles: /// Dependency tracking and cycles:
/// - Dependencies are extracted from steel_get_column(_with_index), get-var, ///
/// * Dependencies are extracted from steel_get_column(\_with_index), get-var,
/// and steel_query_sql and stored in script_dependencies with context /// and steel_query_sql and stored in script_dependencies with context
/// - Cycles across tables are rejected (self-dependency is allowed) /// * Cycles across tables are rejected (self-dependency is allowed)
#[prost(string, tag = "3")] #[prost(string, tag = "3")]
pub script: ::prost::alloc::string::String, pub script: ::prost::alloc::string::String,
/// Optional. Free-text description stored alongside the script (no functional effect). /// Optional. Free-text description stored alongside the script (no functional effect).
@@ -55,20 +59,21 @@ pub struct PostTableScriptRequest {
} }
/// Response after creating or updating a script. /// Response after creating or updating a script.
#[derive(serde::Serialize, serde::Deserialize)] #[derive(serde::Serialize, serde::Deserialize)]
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct TableScriptResponse { pub struct TableScriptResponse {
/// The ID of the script record in table_scripts (new or existing on upsert). /// The ID of the script record in table_scripts (new or existing on upsert).
#[prost(int64, tag = "1")] #[prost(int64, tag = "1")]
pub id: i64, pub id: i64,
/// Human-readable warnings concatenated into a single string. Possible messages: /// 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 /// * Warning if the script references itself (may affect first population)
/// - Info about number of structured linked-table accesses /// * Count of raw SQL queries present
/// - Warning if many dependencies may affect performance /// * Info about number of structured linked-table accesses
/// * Warning if many dependencies may affect performance
#[prost(string, tag = "2")] #[prost(string, tag = "2")]
pub warnings: ::prost::alloc::string::String, pub warnings: ::prost::alloc::string::String,
} }
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct GetTableScriptsRequest { pub struct GetTableScriptsRequest {
/// Required. Profile (schema) name. /// Required. Profile (schema) name.
#[prost(string, tag = "1")] #[prost(string, tag = "1")]
@@ -97,7 +102,7 @@ pub struct StoredTableScript {
#[prost(message, repeated, tag = "6")] #[prost(message, repeated, tag = "6")]
pub dependencies: ::prost::alloc::vec::Vec<ScriptDependency>, pub dependencies: ::prost::alloc::vec::Vec<ScriptDependency>,
} }
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct ScriptDependency { pub struct ScriptDependency {
#[prost(string, tag = "1")] #[prost(string, tag = "1")]
pub target_table: ::prost::alloc::string::String, pub target_table: ::prost::alloc::string::String,
@@ -124,14 +129,15 @@ pub mod table_script_client {
/// Manages column-computation scripts for user-defined tables. /// Manages column-computation scripts for user-defined tables.
/// Each script belongs to a single table (table_definition_id) and populates /// Each script belongs to a single table (table_definition_id) and populates
/// exactly one target column in that table. The server: /// 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 script syntax (non-empty, balanced parentheses, starts with '(')
/// - Validates column/type usage inside math expressions /// * Validates the target column (exists, not a system column, allowed type)
/// - Validates referenced tables/columns against the schema /// * Validates column/type usage inside math expressions
/// - Enforces link constraints for structured access (see notes below) /// * Validates referenced tables/columns against the schema
/// - Analyzes dependencies and prevents cycles across the schema /// * Enforces link constraints for structured access (see notes below)
/// - Transforms the script to decimal-safe math (steel_decimal) /// * Analyzes dependencies and prevents cycles across the schema
/// - Upserts into table_scripts and records dependencies in script_dependencies /// * Transforms the script to decimal-safe math (steel_decimal)
/// * Upserts into table_scripts and records dependencies in script_dependencies
/// The whole operation is transactional. /// The whole operation is transactional.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct TableScriptClient<T> { pub struct TableScriptClient<T> {
@@ -216,19 +222,20 @@ pub mod table_script_client {
/// Create or update a script for a specific table and target column. /// Create or update a script for a specific table and target column.
/// ///
/// Behavior: /// Behavior:
/// - Fetches the table by table_definition_id (must exist) ///
/// - Validates "script" (syntax), "target_column" (exists and type rules), /// * 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) /// and all referenced tables/columns (must exist in same schema)
/// - Validates math operations: prohibits using certain data types in math /// * Validates math operations: prohibits using certain data types in math
/// - Enforces link constraints for structured table access: /// * Enforces link constraints for structured table access:
/// • Allowed always: self-references (same table) /// • Allowed always: self-references (same table)
/// • Structured access via steel_get_column / steel_get_column_with_index /// • Structured access via steel_get_column / steel_get_column_with_index
/// requires an explicit link in table_definition_links /// requires an explicit link in table_definition_links
/// • Raw SQL access via steel_query_sql is permitted (still validated) /// • Raw SQL access via steel_query_sql is permitted (still validated)
/// - Detects and rejects circular dependencies across all scripts in the schema /// * Detects and rejects circular dependencies across all scripts in the schema
/// (self-references are allowed and not treated as cycles) /// (self-references are allowed and not treated as cycles)
/// - Transforms the script to decimal-safe operations (steel_decimal) /// * Transforms the script to decimal-safe operations (steel_decimal)
/// - UPSERTS into table_scripts on (table_definitions_id, target_column) /// * UPSERTS into table_scripts on (table_definitions_id, target_column)
/// and saves a normalized dependency list into script_dependencies /// and saves a normalized dependency list into script_dependencies
pub async fn post_table_script( pub async fn post_table_script(
&mut self, &mut self,
@@ -245,7 +252,7 @@ pub mod table_script_client {
format!("Service was not ready: {}", e.into()), format!("Service was not ready: {}", e.into()),
) )
})?; })?;
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static( let path = http::uri::PathAndQuery::from_static(
"/komp_ac.table_script.TableScript/PostTableScript", "/komp_ac.table_script.TableScript/PostTableScript",
); );
@@ -262,10 +269,11 @@ pub mod table_script_client {
/// Fetch all stored scripts for a specific table. /// Fetch all stored scripts for a specific table.
/// ///
/// Behavior: /// Behavior:
/// - Resolves the table from (profile_name, table_name) ///
/// - Returns the stored, transformed script from table_scripts /// * Resolves the table from (profile_name, table_name)
/// - Includes normalized dependency metadata from script_dependencies /// * Returns the stored, transformed script from table_scripts
/// - Returns an empty scripts list when the table has no 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( pub async fn get_table_scripts(
&mut self, &mut self,
request: impl tonic::IntoRequest<super::GetTableScriptsRequest>, request: impl tonic::IntoRequest<super::GetTableScriptsRequest>,
@@ -281,7 +289,7 @@ pub mod table_script_client {
format!("Service was not ready: {}", e.into()), format!("Service was not ready: {}", e.into()),
) )
})?; })?;
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static( let path = http::uri::PathAndQuery::from_static(
"/komp_ac.table_script.TableScript/GetTableScripts", "/komp_ac.table_script.TableScript/GetTableScripts",
); );
@@ -313,19 +321,20 @@ pub mod table_script_server {
/// Create or update a script for a specific table and target column. /// Create or update a script for a specific table and target column.
/// ///
/// Behavior: /// Behavior:
/// - Fetches the table by table_definition_id (must exist) ///
/// - Validates "script" (syntax), "target_column" (exists and type rules), /// * 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) /// and all referenced tables/columns (must exist in same schema)
/// - Validates math operations: prohibits using certain data types in math /// * Validates math operations: prohibits using certain data types in math
/// - Enforces link constraints for structured table access: /// * Enforces link constraints for structured table access:
/// • Allowed always: self-references (same table) /// • Allowed always: self-references (same table)
/// • Structured access via steel_get_column / steel_get_column_with_index /// • Structured access via steel_get_column / steel_get_column_with_index
/// requires an explicit link in table_definition_links /// requires an explicit link in table_definition_links
/// • Raw SQL access via steel_query_sql is permitted (still validated) /// • Raw SQL access via steel_query_sql is permitted (still validated)
/// - Detects and rejects circular dependencies across all scripts in the schema /// * Detects and rejects circular dependencies across all scripts in the schema
/// (self-references are allowed and not treated as cycles) /// (self-references are allowed and not treated as cycles)
/// - Transforms the script to decimal-safe operations (steel_decimal) /// * Transforms the script to decimal-safe operations (steel_decimal)
/// - UPSERTS into table_scripts on (table_definitions_id, target_column) /// * UPSERTS into table_scripts on (table_definitions_id, target_column)
/// and saves a normalized dependency list into script_dependencies /// and saves a normalized dependency list into script_dependencies
async fn post_table_script( async fn post_table_script(
&self, &self,
@@ -337,10 +346,11 @@ pub mod table_script_server {
/// Fetch all stored scripts for a specific table. /// Fetch all stored scripts for a specific table.
/// ///
/// Behavior: /// Behavior:
/// - Resolves the table from (profile_name, table_name) ///
/// - Returns the stored, transformed script from table_scripts /// * Resolves the table from (profile_name, table_name)
/// - Includes normalized dependency metadata from script_dependencies /// * Returns the stored, transformed script from table_scripts
/// - Returns an empty scripts list when the table has no scripts /// * Includes normalized dependency metadata from script_dependencies
/// * Returns an empty scripts list when the table has no scripts
async fn get_table_scripts( async fn get_table_scripts(
&self, &self,
request: tonic::Request<super::GetTableScriptsRequest>, request: tonic::Request<super::GetTableScriptsRequest>,
@@ -352,14 +362,15 @@ pub mod table_script_server {
/// Manages column-computation scripts for user-defined tables. /// Manages column-computation scripts for user-defined tables.
/// Each script belongs to a single table (table_definition_id) and populates /// Each script belongs to a single table (table_definition_id) and populates
/// exactly one target column in that table. The server: /// 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 script syntax (non-empty, balanced parentheses, starts with '(')
/// - Validates column/type usage inside math expressions /// * Validates the target column (exists, not a system column, allowed type)
/// - Validates referenced tables/columns against the schema /// * Validates column/type usage inside math expressions
/// - Enforces link constraints for structured access (see notes below) /// * Validates referenced tables/columns against the schema
/// - Analyzes dependencies and prevents cycles across the schema /// * Enforces link constraints for structured access (see notes below)
/// - Transforms the script to decimal-safe math (steel_decimal) /// * Analyzes dependencies and prevents cycles across the schema
/// - Upserts into table_scripts and records dependencies in script_dependencies /// * Transforms the script to decimal-safe math (steel_decimal)
/// * Upserts into table_scripts and records dependencies in script_dependencies
/// The whole operation is transactional. /// The whole operation is transactional.
#[derive(Debug)] #[derive(Debug)]
pub struct TableScriptServer<T> { pub struct TableScriptServer<T> {
@@ -467,7 +478,7 @@ pub mod table_script_server {
let inner = self.inner.clone(); let inner = self.inner.clone();
let fut = async move { let fut = async move {
let method = PostTableScriptSvc(inner); let method = PostTableScriptSvc(inner);
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec) let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config( .apply_compression_config(
accept_compression_encodings, accept_compression_encodings,
@@ -512,7 +523,7 @@ pub mod table_script_server {
let inner = self.inner.clone(); let inner = self.inner.clone();
let fut = async move { let fut = async move {
let method = GetTableScriptsSvc(inner); let method = GetTableScriptsSvc(inner);
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec) let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config( .apply_compression_config(
accept_compression_encodings, accept_compression_encodings,

View File

@@ -1,6 +1,6 @@
// This file is @generated by prost-build. // This file is @generated by prost-build.
/// Request identifying the profile (schema) and tables to inspect. /// Request identifying the profile (schema) and tables to inspect.
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct GetTableStructureRequest { pub struct GetTableStructureRequest {
/// Required. Profile (PostgreSQL schema) name. Must exist in `schemas`. /// Required. Profile (PostgreSQL schema) name. Must exist in `schemas`.
#[prost(string, tag = "1")] #[prost(string, tag = "1")]
@@ -26,23 +26,24 @@ pub struct GetTableStructureResponse {
pub struct TableStructureResponse { pub struct TableStructureResponse {
/// Columns of the physical table, including system columns (id, deleted, /// Columns of the physical table, including system columns (id, deleted,
/// created_at), user-defined columns, and any foreign-key columns such as /// created_at), user-defined columns, and any foreign-key columns such as
/// "<linked_table>_id". May be empty if the physical table is missing. /// "\<linked_table>\_id". May be empty if the physical table is missing.
#[prost(message, repeated, tag = "1")] #[prost(message, repeated, tag = "1")]
pub columns: ::prost::alloc::vec::Vec<TableColumn>, pub columns: ::prost::alloc::vec::Vec<TableColumn>,
} }
/// One physical column entry as reported by information_schema. /// One physical column entry as reported by information_schema.
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct TableColumn { pub struct TableColumn {
/// Column name exactly as defined in PostgreSQL. /// Column name exactly as defined in PostgreSQL.
#[prost(string, tag = "1")] #[prost(string, tag = "1")]
pub name: ::prost::alloc::string::String, pub name: ::prost::alloc::string::String,
/// Normalized data type string derived from information_schema: /// Normalized data type string derived from information_schema:
/// - VARCHAR(n) when udt_name='varchar' with character_maximum_length ///
/// - CHAR(n) when udt_name='bpchar' with character_maximum_length /// * VARCHAR(n) when udt_name='varchar' with character_maximum_length
/// - NUMERIC(p,s) when udt_name='numeric' with precision and scale /// * CHAR(n) when udt_name='bpchar' with character_maximum_length
/// - NUMERIC(p) when udt_name='numeric' with precision only /// * NUMERIC(p,s) when udt_name='numeric' with precision and scale
/// - <TYPE>\[\] for array types (udt_name starting with '_', e.g., INT\[\] ) /// * NUMERIC(p) when udt_name='numeric' with precision only
/// - Otherwise UPPER(udt_name), e.g., TEXT, BIGINT, TIMESTAMPTZ /// * <TYPE>\[\] for array types (udt_name starting with '\_', e.g., INT\[\] )
/// * Otherwise UPPER(udt_name), e.g., TEXT, BIGINT, TIMESTAMPTZ
/// Examples: "TEXT", "BIGINT", "VARCHAR(255)", "TIMESTAMPTZ", "NUMERIC(14,4)" /// Examples: "TEXT", "BIGINT", "VARCHAR(255)", "TIMESTAMPTZ", "NUMERIC(14,4)"
#[prost(string, tag = "2")] #[prost(string, tag = "2")]
pub data_type: ::prost::alloc::string::String, pub data_type: ::prost::alloc::string::String,
@@ -68,8 +69,9 @@ pub mod table_structure_service_client {
/// Introspects the physical PostgreSQL tables for one or more logical tables /// Introspects the physical PostgreSQL tables for one or more logical tables
/// (defined in table_definitions) and returns their column structures. /// (defined in table_definitions) and returns their column structures.
/// The server validates that: /// The server validates that:
/// - The profile (schema) exists in `schemas` ///
/// - Every table is defined for that profile in `table_definitions` /// * The profile (schema) exists in `schemas`
/// * Every table is defined for that profile in `table_definitions`
/// It then queries information_schema for the physical tables and returns /// It then queries information_schema for the physical tables and returns
/// normalized column metadata. /// normalized column metadata.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
@@ -156,11 +158,12 @@ pub mod table_structure_service_client {
/// nullability, primary key flag) for one or more tables in a profile. /// nullability, primary key flag) for one or more tables in a profile.
/// ///
/// Behavior: /// Behavior:
/// - NOT_FOUND if profile doesn't exist in `schemas` ///
/// - NOT_FOUND if any table is not defined for that profile in `table_definitions` /// * NOT_FOUND if profile doesn't exist in `schemas`
/// - Queries information_schema.columns ordered by ordinal position /// * NOT_FOUND if any table is not defined for that profile in `table_definitions`
/// - Normalizes data_type text (details under TableColumn.data_type) /// * Queries information_schema.columns ordered by ordinal position
/// - Returns an error if any validated table has no visible columns in /// * Normalizes data_type text (details under TableColumn.data_type)
/// * Returns an error if any validated table has no visible columns in
/// information_schema (e.g., physical table missing) /// information_schema (e.g., physical table missing)
pub async fn get_table_structure( pub async fn get_table_structure(
&mut self, &mut self,
@@ -177,7 +180,7 @@ pub mod table_structure_service_client {
format!("Service was not ready: {}", e.into()), format!("Service was not ready: {}", e.into()),
) )
})?; })?;
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static( let path = http::uri::PathAndQuery::from_static(
"/komp_ac.table_structure.TableStructureService/GetTableStructure", "/komp_ac.table_structure.TableStructureService/GetTableStructure",
); );
@@ -210,11 +213,12 @@ pub mod table_structure_service_server {
/// nullability, primary key flag) for one or more tables in a profile. /// nullability, primary key flag) for one or more tables in a profile.
/// ///
/// Behavior: /// Behavior:
/// - NOT_FOUND if profile doesn't exist in `schemas` ///
/// - NOT_FOUND if any table is not defined for that profile in `table_definitions` /// * NOT_FOUND if profile doesn't exist in `schemas`
/// - Queries information_schema.columns ordered by ordinal position /// * NOT_FOUND if any table is not defined for that profile in `table_definitions`
/// - Normalizes data_type text (details under TableColumn.data_type) /// * Queries information_schema.columns ordered by ordinal position
/// - Returns an error if any validated table has no visible columns in /// * Normalizes data_type text (details under TableColumn.data_type)
/// * Returns an error if any validated table has no visible columns in
/// information_schema (e.g., physical table missing) /// information_schema (e.g., physical table missing)
async fn get_table_structure( async fn get_table_structure(
&self, &self,
@@ -227,8 +231,9 @@ pub mod table_structure_service_server {
/// Introspects the physical PostgreSQL tables for one or more logical tables /// Introspects the physical PostgreSQL tables for one or more logical tables
/// (defined in table_definitions) and returns their column structures. /// (defined in table_definitions) and returns their column structures.
/// The server validates that: /// The server validates that:
/// - The profile (schema) exists in `schemas` ///
/// - Every table is defined for that profile in `table_definitions` /// * The profile (schema) exists in `schemas`
/// * Every table is defined for that profile in `table_definitions`
/// It then queries information_schema for the physical tables and returns /// It then queries information_schema for the physical tables and returns
/// normalized column metadata. /// normalized column metadata.
#[derive(Debug)] #[derive(Debug)]
@@ -342,7 +347,7 @@ pub mod table_structure_service_server {
let inner = self.inner.clone(); let inner = self.inner.clone();
let fut = async move { let fut = async move {
let method = GetTableStructureSvc(inner); let method = GetTableStructureSvc(inner);
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec) let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config( .apply_compression_config(
accept_compression_encodings, accept_compression_encodings,

View File

@@ -1,6 +1,6 @@
// This file is @generated by prost-build. // This file is @generated by prost-build.
/// Request validation rules for a table /// Request validation rules for a table
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct GetTableValidationRequest { pub struct GetTableValidationRequest {
#[prost(string, tag = "1")] #[prost(string, tag = "1")]
pub profile_name: ::prost::alloc::string::String, pub profile_name: ::prost::alloc::string::String,
@@ -34,9 +34,6 @@ pub struct FieldValidation {
/// Client-side hint that this field participates in external/asynchronous validation UI. /// Client-side hint that this field participates in external/asynchronous validation UI.
#[prost(bool, tag = "13")] #[prost(bool, tag = "13")]
pub external_validation_enabled: bool, pub external_validation_enabled: bool,
/// Client-side formatter metadata. This is intentionally data-only, not executable code.
#[prost(message, optional, tag = "14")]
pub formatter: ::core::option::Option<CustomFormatter>,
/// Client-side display mask metadata. The server stores raw data without mask literals. /// Client-side display mask metadata. The server stores raw data without mask literals.
#[prost(message, optional, tag = "3")] #[prost(message, optional, tag = "3")]
pub mask: ::core::option::Option<DisplayMask>, pub mask: ::core::option::Option<DisplayMask>,
@@ -51,7 +48,7 @@ pub struct FieldValidation {
/// Character limit validation (Validation 1). /// Character limit validation (Validation 1).
/// These rules map directly to canvas CharacterLimits. /// These rules map directly to canvas CharacterLimits.
#[derive(serde::Serialize, serde::Deserialize)] #[derive(serde::Serialize, serde::Deserialize)]
#[derive(Clone, Copy, PartialEq, ::prost::Message)] #[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct CharacterLimits { pub struct CharacterLimits {
/// When zero, the field is considered "not set". If both min/max are zero, /// When zero, the field is considered "not set". If both min/max are zero,
/// the server should avoid sending this FieldValidation (no validation). /// the server should avoid sending this FieldValidation (no validation).
@@ -71,7 +68,7 @@ pub struct CharacterLimits {
/// This is not a validation rule by itself. It exists so clients can render and /// This is not a validation rule by itself. It exists so clients can render and
/// navigate masked input while still storing raw values server-side. /// navigate masked input while still storing raw values server-side.
#[derive(serde::Serialize, serde::Deserialize)] #[derive(serde::Serialize, serde::Deserialize)]
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct DisplayMask { pub struct DisplayMask {
/// e.g., "(###) ###-####" or "####-##-##" /// e.g., "(###) ###-####" or "####-##-##"
#[prost(string, tag = "1")] #[prost(string, tag = "1")]
@@ -79,7 +76,7 @@ pub struct DisplayMask {
/// e.g., "#" /// e.g., "#"
#[prost(string, tag = "2")] #[prost(string, tag = "2")]
pub input_char: ::prost::alloc::string::String, pub input_char: ::prost::alloc::string::String,
/// e.g., "_" /// e.g., "\_"
#[prost(string, optional, tag = "3")] #[prost(string, optional, tag = "3")]
pub template_char: ::core::option::Option<::prost::alloc::string::String>, pub template_char: ::core::option::Option<::prost::alloc::string::String>,
} }
@@ -87,7 +84,7 @@ pub struct DisplayMask {
/// This exists instead of a string syntax like "0-3" so the server can validate /// This exists instead of a string syntax like "0-3" so the server can validate
/// the structure directly and clients do not need to parse a DSL. /// the structure directly and clients do not need to parse a DSL.
#[derive(serde::Serialize, serde::Deserialize)] #[derive(serde::Serialize, serde::Deserialize)]
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct PatternPosition { pub struct PatternPosition {
#[prost(enumeration = "PatternPositionKind", tag = "1")] #[prost(enumeration = "PatternPositionKind", tag = "1")]
pub kind: i32, pub kind: i32,
@@ -103,7 +100,7 @@ pub struct PatternPosition {
/// What type of character constraint a pattern rule applies. /// What type of character constraint a pattern rule applies.
/// This mirrors the typed character filters used by canvas. /// This mirrors the typed character filters used by canvas.
#[derive(serde::Serialize, serde::Deserialize)] #[derive(serde::Serialize, serde::Deserialize)]
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct CharacterConstraint { pub struct CharacterConstraint {
#[prost(enumeration = "CharacterConstraintKind", tag = "1")] #[prost(enumeration = "CharacterConstraintKind", tag = "1")]
pub kind: i32, pub kind: i32,
@@ -119,39 +116,17 @@ pub struct CharacterConstraint {
} }
/// One position-based validation rule, similar to canvas PositionFilter. /// One position-based validation rule, similar to canvas PositionFilter.
#[derive(serde::Serialize, serde::Deserialize)] #[derive(serde::Serialize, serde::Deserialize)]
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct PatternRule { pub struct PatternRule {
#[prost(message, optional, tag = "1")] #[prost(message, optional, tag = "1")]
pub position: ::core::option::Option<PatternPosition>, pub position: ::core::option::Option<PatternPosition>,
#[prost(message, optional, tag = "2")] #[prost(message, optional, tag = "2")]
pub constraint: ::core::option::Option<CharacterConstraint>, pub constraint: ::core::option::Option<CharacterConstraint>,
} }
/// Client-side formatter metadata.
/// The formatter "type" is intended to be resolved by a client-side formatter registry.
#[derive(serde::Serialize, serde::Deserialize)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct CustomFormatter {
/// Formatter type identifier; handled clientside.
/// Examples: "PSCFormatter", "PhoneFormatter", "CreditCardFormatter", "DateFormatter"
#[prost(string, tag = "1")]
pub r#type: ::prost::alloc::string::String,
#[prost(message, repeated, tag = "2")]
pub options: ::prost::alloc::vec::Vec<FormatterOption>,
#[prost(string, optional, tag = "3")]
pub description: ::core::option::Option<::prost::alloc::string::String>,
}
#[derive(serde::Serialize, serde::Deserialize)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct FormatterOption {
#[prost(string, tag = "1")]
pub key: ::prost::alloc::string::String,
#[prost(string, tag = "2")]
pub value: ::prost::alloc::string::String,
}
/// Exact-value whitelist configuration. /// Exact-value whitelist configuration.
/// This maps to canvas AllowedValues semantics. /// This maps to canvas AllowedValues semantics.
#[derive(serde::Serialize, serde::Deserialize)] #[derive(serde::Serialize, serde::Deserialize)]
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct AllowedValues { pub struct AllowedValues {
#[prost(string, repeated, tag = "1")] #[prost(string, repeated, tag = "1")]
pub values: ::prost::alloc::vec::Vec<::prost::alloc::string::String>, pub values: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
@@ -184,7 +159,7 @@ pub struct UpdateFieldValidationRequest {
pub validation: ::core::option::Option<FieldValidation>, pub validation: ::core::option::Option<FieldValidation>,
} }
#[derive(serde::Serialize, serde::Deserialize)] #[derive(serde::Serialize, serde::Deserialize)]
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct UpdateFieldValidationResponse { pub struct UpdateFieldValidationResponse {
#[prost(bool, tag = "1")] #[prost(bool, tag = "1")]
pub success: bool, pub success: bool,
@@ -203,7 +178,7 @@ pub struct ReplaceTableValidationRequest {
pub fields: ::prost::alloc::vec::Vec<FieldValidation>, pub fields: ::prost::alloc::vec::Vec<FieldValidation>,
} }
#[derive(serde::Serialize, serde::Deserialize)] #[derive(serde::Serialize, serde::Deserialize)]
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct ReplaceTableValidationResponse { pub struct ReplaceTableValidationResponse {
#[prost(bool, tag = "1")] #[prost(bool, tag = "1")]
pub success: bool, pub success: bool,
@@ -271,7 +246,7 @@ pub struct UpsertValidationRuleRequest {
pub rule: ::core::option::Option<ValidationRuleDefinition>, pub rule: ::core::option::Option<ValidationRuleDefinition>,
} }
#[derive(serde::Serialize, serde::Deserialize)] #[derive(serde::Serialize, serde::Deserialize)]
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct UpsertValidationRuleResponse { pub struct UpsertValidationRuleResponse {
#[prost(bool, tag = "1")] #[prost(bool, tag = "1")]
pub success: bool, pub success: bool,
@@ -279,7 +254,7 @@ pub struct UpsertValidationRuleResponse {
pub message: ::prost::alloc::string::String, pub message: ::prost::alloc::string::String,
} }
#[derive(serde::Serialize, serde::Deserialize)] #[derive(serde::Serialize, serde::Deserialize)]
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct ListValidationRulesRequest { pub struct ListValidationRulesRequest {
#[prost(string, tag = "1")] #[prost(string, tag = "1")]
pub profile_name: ::prost::alloc::string::String, pub profile_name: ::prost::alloc::string::String,
@@ -291,7 +266,7 @@ pub struct ListValidationRulesResponse {
pub rules: ::prost::alloc::vec::Vec<ValidationRuleDefinition>, pub rules: ::prost::alloc::vec::Vec<ValidationRuleDefinition>,
} }
#[derive(serde::Serialize, serde::Deserialize)] #[derive(serde::Serialize, serde::Deserialize)]
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct DeleteValidationRuleRequest { pub struct DeleteValidationRuleRequest {
#[prost(string, tag = "1")] #[prost(string, tag = "1")]
pub profile_name: ::prost::alloc::string::String, pub profile_name: ::prost::alloc::string::String,
@@ -299,7 +274,7 @@ pub struct DeleteValidationRuleRequest {
pub name: ::prost::alloc::string::String, pub name: ::prost::alloc::string::String,
} }
#[derive(serde::Serialize, serde::Deserialize)] #[derive(serde::Serialize, serde::Deserialize)]
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct DeleteValidationRuleResponse { pub struct DeleteValidationRuleResponse {
#[prost(bool, tag = "1")] #[prost(bool, tag = "1")]
pub success: bool, pub success: bool,
@@ -315,7 +290,7 @@ pub struct UpsertValidationSetRequest {
pub set: ::core::option::Option<ValidationSetDefinition>, pub set: ::core::option::Option<ValidationSetDefinition>,
} }
#[derive(serde::Serialize, serde::Deserialize)] #[derive(serde::Serialize, serde::Deserialize)]
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct UpsertValidationSetResponse { pub struct UpsertValidationSetResponse {
#[prost(bool, tag = "1")] #[prost(bool, tag = "1")]
pub success: bool, pub success: bool,
@@ -323,7 +298,7 @@ pub struct UpsertValidationSetResponse {
pub message: ::prost::alloc::string::String, pub message: ::prost::alloc::string::String,
} }
#[derive(serde::Serialize, serde::Deserialize)] #[derive(serde::Serialize, serde::Deserialize)]
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct ListValidationSetsRequest { pub struct ListValidationSetsRequest {
#[prost(string, tag = "1")] #[prost(string, tag = "1")]
pub profile_name: ::prost::alloc::string::String, pub profile_name: ::prost::alloc::string::String,
@@ -335,7 +310,7 @@ pub struct ListValidationSetsResponse {
pub sets: ::prost::alloc::vec::Vec<ValidationSetDefinition>, pub sets: ::prost::alloc::vec::Vec<ValidationSetDefinition>,
} }
#[derive(serde::Serialize, serde::Deserialize)] #[derive(serde::Serialize, serde::Deserialize)]
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct DeleteValidationSetRequest { pub struct DeleteValidationSetRequest {
#[prost(string, tag = "1")] #[prost(string, tag = "1")]
pub profile_name: ::prost::alloc::string::String, pub profile_name: ::prost::alloc::string::String,
@@ -343,7 +318,7 @@ pub struct DeleteValidationSetRequest {
pub name: ::prost::alloc::string::String, pub name: ::prost::alloc::string::String,
} }
#[derive(serde::Serialize, serde::Deserialize)] #[derive(serde::Serialize, serde::Deserialize)]
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct DeleteValidationSetResponse { pub struct DeleteValidationSetResponse {
#[prost(bool, tag = "1")] #[prost(bool, tag = "1")]
pub success: bool, pub success: bool,
@@ -351,7 +326,7 @@ pub struct DeleteValidationSetResponse {
pub message: ::prost::alloc::string::String, pub message: ::prost::alloc::string::String,
} }
#[derive(serde::Serialize, serde::Deserialize)] #[derive(serde::Serialize, serde::Deserialize)]
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct ApplyValidationSetRequest { pub struct ApplyValidationSetRequest {
#[prost(string, tag = "1")] #[prost(string, tag = "1")]
pub profile_name: ::prost::alloc::string::String, pub profile_name: ::prost::alloc::string::String,
@@ -373,7 +348,7 @@ pub struct ApplyValidationSetResponse {
pub validation: ::core::option::Option<FieldValidation>, pub validation: ::core::option::Option<FieldValidation>,
} }
#[derive(serde::Serialize, serde::Deserialize)] #[derive(serde::Serialize, serde::Deserialize)]
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct LockFieldValidationRequest { pub struct LockFieldValidationRequest {
#[prost(string, tag = "1")] #[prost(string, tag = "1")]
pub profile_name: ::prost::alloc::string::String, pub profile_name: ::prost::alloc::string::String,
@@ -383,7 +358,7 @@ pub struct LockFieldValidationRequest {
pub data_key: ::prost::alloc::string::String, pub data_key: ::prost::alloc::string::String,
} }
#[derive(serde::Serialize, serde::Deserialize)] #[derive(serde::Serialize, serde::Deserialize)]
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct LockFieldValidationResponse { pub struct LockFieldValidationResponse {
#[prost(bool, tag = "1")] #[prost(bool, tag = "1")]
pub success: bool, pub success: bool,
@@ -619,7 +594,7 @@ pub mod table_validation_service_client {
format!("Service was not ready: {}", e.into()), format!("Service was not ready: {}", e.into()),
) )
})?; })?;
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static( let path = http::uri::PathAndQuery::from_static(
"/komp_ac.table_validation.TableValidationService/GetTableValidation", "/komp_ac.table_validation.TableValidationService/GetTableValidation",
); );
@@ -649,7 +624,7 @@ pub mod table_validation_service_client {
format!("Service was not ready: {}", e.into()), format!("Service was not ready: {}", e.into()),
) )
})?; })?;
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static( let path = http::uri::PathAndQuery::from_static(
"/komp_ac.table_validation.TableValidationService/UpdateFieldValidation", "/komp_ac.table_validation.TableValidationService/UpdateFieldValidation",
); );
@@ -679,7 +654,7 @@ pub mod table_validation_service_client {
format!("Service was not ready: {}", e.into()), format!("Service was not ready: {}", e.into()),
) )
})?; })?;
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static( let path = http::uri::PathAndQuery::from_static(
"/komp_ac.table_validation.TableValidationService/ReplaceTableValidation", "/komp_ac.table_validation.TableValidationService/ReplaceTableValidation",
); );
@@ -709,7 +684,7 @@ pub mod table_validation_service_client {
format!("Service was not ready: {}", e.into()), format!("Service was not ready: {}", e.into()),
) )
})?; })?;
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static( let path = http::uri::PathAndQuery::from_static(
"/komp_ac.table_validation.TableValidationService/UpsertValidationRule", "/komp_ac.table_validation.TableValidationService/UpsertValidationRule",
); );
@@ -738,7 +713,7 @@ pub mod table_validation_service_client {
format!("Service was not ready: {}", e.into()), format!("Service was not ready: {}", e.into()),
) )
})?; })?;
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static( let path = http::uri::PathAndQuery::from_static(
"/komp_ac.table_validation.TableValidationService/ListValidationRules", "/komp_ac.table_validation.TableValidationService/ListValidationRules",
); );
@@ -767,7 +742,7 @@ pub mod table_validation_service_client {
format!("Service was not ready: {}", e.into()), format!("Service was not ready: {}", e.into()),
) )
})?; })?;
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static( let path = http::uri::PathAndQuery::from_static(
"/komp_ac.table_validation.TableValidationService/DeleteValidationRule", "/komp_ac.table_validation.TableValidationService/DeleteValidationRule",
); );
@@ -797,7 +772,7 @@ pub mod table_validation_service_client {
format!("Service was not ready: {}", e.into()), format!("Service was not ready: {}", e.into()),
) )
})?; })?;
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static( let path = http::uri::PathAndQuery::from_static(
"/komp_ac.table_validation.TableValidationService/UpsertValidationSet", "/komp_ac.table_validation.TableValidationService/UpsertValidationSet",
); );
@@ -826,7 +801,7 @@ pub mod table_validation_service_client {
format!("Service was not ready: {}", e.into()), format!("Service was not ready: {}", e.into()),
) )
})?; })?;
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static( let path = http::uri::PathAndQuery::from_static(
"/komp_ac.table_validation.TableValidationService/ListValidationSets", "/komp_ac.table_validation.TableValidationService/ListValidationSets",
); );
@@ -855,7 +830,7 @@ pub mod table_validation_service_client {
format!("Service was not ready: {}", e.into()), format!("Service was not ready: {}", e.into()),
) )
})?; })?;
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static( let path = http::uri::PathAndQuery::from_static(
"/komp_ac.table_validation.TableValidationService/DeleteValidationSet", "/komp_ac.table_validation.TableValidationService/DeleteValidationSet",
); );
@@ -885,7 +860,7 @@ pub mod table_validation_service_client {
format!("Service was not ready: {}", e.into()), format!("Service was not ready: {}", e.into()),
) )
})?; })?;
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static( let path = http::uri::PathAndQuery::from_static(
"/komp_ac.table_validation.TableValidationService/ApplyValidationSet", "/komp_ac.table_validation.TableValidationService/ApplyValidationSet",
); );
@@ -915,7 +890,7 @@ pub mod table_validation_service_client {
format!("Service was not ready: {}", e.into()), format!("Service was not ready: {}", e.into()),
) )
})?; })?;
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static( let path = http::uri::PathAndQuery::from_static(
"/komp_ac.table_validation.TableValidationService/LockFieldValidation", "/komp_ac.table_validation.TableValidationService/LockFieldValidation",
); );
@@ -1140,7 +1115,7 @@ pub mod table_validation_service_server {
let inner = self.inner.clone(); let inner = self.inner.clone();
let fut = async move { let fut = async move {
let method = GetTableValidationSvc(inner); let method = GetTableValidationSvc(inner);
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec) let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config( .apply_compression_config(
accept_compression_encodings, accept_compression_encodings,
@@ -1191,7 +1166,7 @@ pub mod table_validation_service_server {
let inner = self.inner.clone(); let inner = self.inner.clone();
let fut = async move { let fut = async move {
let method = UpdateFieldValidationSvc(inner); let method = UpdateFieldValidationSvc(inner);
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec) let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config( .apply_compression_config(
accept_compression_encodings, accept_compression_encodings,
@@ -1242,7 +1217,7 @@ pub mod table_validation_service_server {
let inner = self.inner.clone(); let inner = self.inner.clone();
let fut = async move { let fut = async move {
let method = ReplaceTableValidationSvc(inner); let method = ReplaceTableValidationSvc(inner);
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec) let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config( .apply_compression_config(
accept_compression_encodings, accept_compression_encodings,
@@ -1293,7 +1268,7 @@ pub mod table_validation_service_server {
let inner = self.inner.clone(); let inner = self.inner.clone();
let fut = async move { let fut = async move {
let method = UpsertValidationRuleSvc(inner); let method = UpsertValidationRuleSvc(inner);
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec) let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config( .apply_compression_config(
accept_compression_encodings, accept_compression_encodings,
@@ -1342,7 +1317,7 @@ pub mod table_validation_service_server {
let inner = self.inner.clone(); let inner = self.inner.clone();
let fut = async move { let fut = async move {
let method = ListValidationRulesSvc(inner); let method = ListValidationRulesSvc(inner);
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec) let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config( .apply_compression_config(
accept_compression_encodings, accept_compression_encodings,
@@ -1393,7 +1368,7 @@ pub mod table_validation_service_server {
let inner = self.inner.clone(); let inner = self.inner.clone();
let fut = async move { let fut = async move {
let method = DeleteValidationRuleSvc(inner); let method = DeleteValidationRuleSvc(inner);
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec) let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config( .apply_compression_config(
accept_compression_encodings, accept_compression_encodings,
@@ -1442,7 +1417,7 @@ pub mod table_validation_service_server {
let inner = self.inner.clone(); let inner = self.inner.clone();
let fut = async move { let fut = async move {
let method = UpsertValidationSetSvc(inner); let method = UpsertValidationSetSvc(inner);
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec) let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config( .apply_compression_config(
accept_compression_encodings, accept_compression_encodings,
@@ -1491,7 +1466,7 @@ pub mod table_validation_service_server {
let inner = self.inner.clone(); let inner = self.inner.clone();
let fut = async move { let fut = async move {
let method = ListValidationSetsSvc(inner); let method = ListValidationSetsSvc(inner);
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec) let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config( .apply_compression_config(
accept_compression_encodings, accept_compression_encodings,
@@ -1540,7 +1515,7 @@ pub mod table_validation_service_server {
let inner = self.inner.clone(); let inner = self.inner.clone();
let fut = async move { let fut = async move {
let method = DeleteValidationSetSvc(inner); let method = DeleteValidationSetSvc(inner);
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec) let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config( .apply_compression_config(
accept_compression_encodings, accept_compression_encodings,
@@ -1589,7 +1564,7 @@ pub mod table_validation_service_server {
let inner = self.inner.clone(); let inner = self.inner.clone();
let fut = async move { let fut = async move {
let method = ApplyValidationSetSvc(inner); let method = ApplyValidationSetSvc(inner);
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec) let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config( .apply_compression_config(
accept_compression_encodings, accept_compression_encodings,
@@ -1638,7 +1613,7 @@ pub mod table_validation_service_server {
let inner = self.inner.clone(); let inner = self.inner.clone();
let fut = async move { let fut = async move {
let method = LockFieldValidationSvc(inner); let method = LockFieldValidationSvc(inner);
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec) let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config( .apply_compression_config(
accept_compression_encodings, accept_compression_encodings,

View File

@@ -13,28 +13,32 @@ pub struct PostTableDataRequest {
/// Required. Key-value data for columns to insert. /// Required. Key-value data for columns to insert.
/// ///
/// Allowed keys: /// Allowed keys:
/// - User-defined columns from the table definition ///
/// - System/FK columns: /// * User-defined columns from the table definition
/// * System/FK columns:
/// • "deleted" (BOOLEAN), optional; default FALSE if not provided /// • "deleted" (BOOLEAN), optional; default FALSE if not provided
/// • "<linked_table>_id" (BIGINT) for each table link /// • "\<linked_table>\_id" (BIGINT) for each table link
/// ///
/// Type expectations by SQL type: /// Type expectations by SQL type:
/// - TEXT: string value; empty string is treated as NULL ///
/// - BOOLEAN: bool value /// * TEXT: string value; empty string is treated as NULL
/// - TIMESTAMPTZ: ISO 8601/RFC 3339 string (parsed to TIMESTAMPTZ) /// * BOOLEAN: bool value
/// - INTEGER: number with no fractional part and within i32 range /// * TIMESTAMPTZ: ISO 8601/RFC 3339 string (parsed to TIMESTAMPTZ)
/// - BIGINT: number with no fractional part and within i64 range /// * INTEGER: number with no fractional part and within i32 range
/// - NUMERIC(p,s): string representation only; empty string becomes NULL /// * BIGINT: number with no fractional part and within i64 range
/// * NUMERIC(p,s): string representation only; empty string becomes NULL
/// (numbers for NUMERIC are rejected to avoid precision loss) /// (numbers for NUMERIC are rejected to avoid precision loss)
/// ///
/// Script validation rules: /// Script validation rules:
/// - If a script exists for a target column, that column MUST be present here, ///
/// * If a script exists for a target column, that column MUST be present here,
/// and its provided value MUST equal the scripts computed value (type-aware /// and its provided value MUST equal the scripts computed value (type-aware
/// comparison, e.g., decimals are compared numerically). /// comparison, e.g., decimals are compared numerically).
/// ///
/// Notes: /// Notes:
/// - Unknown/invalid column names are rejected ///
/// - Some application-specific validations may apply (e.g., max length for /// * Unknown/invalid column names are rejected
/// * Some application-specific validations may apply (e.g., max length for
/// certain fields like "telefon") /// certain fields like "telefon")
#[prost(map = "string, message", tag = "3")] #[prost(map = "string, message", tag = "3")]
pub data: ::std::collections::HashMap< pub data: ::std::collections::HashMap<
@@ -43,7 +47,7 @@ pub struct PostTableDataRequest {
>, >,
} }
/// Insert response. /// Insert response.
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct PostTableDataResponse { pub struct PostTableDataResponse {
/// True if the insert succeeded. /// True if the insert succeeded.
#[prost(bool, tag = "1")] #[prost(bool, tag = "1")]
@@ -55,6 +59,42 @@ pub struct PostTableDataResponse {
#[prost(int64, tag = "3")] #[prost(int64, tag = "3")]
pub inserted_id: i64, pub inserted_id: i64,
} }
/// One row in a bulk insert request.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct PostTableDataBulkRow {
/// Required. Same data payload as PostTableDataRequest.data.
#[prost(map = "string, message", tag = "1")]
pub data: ::std::collections::HashMap<
::prost::alloc::string::String,
::prost_types::Value,
>,
}
/// Bulk insert request.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct PostTableDataBulkRequest {
/// Required. Profile (PostgreSQL schema) name that owns the table.
#[prost(string, tag = "1")]
pub profile_name: ::prost::alloc::string::String,
/// Required. Logical table (definition) name within the profile.
#[prost(string, tag = "2")]
pub table_name: ::prost::alloc::string::String,
/// Required. Rows to insert. Must contain at least 1 and at most 10,000 rows.
#[prost(message, repeated, tag = "3")]
pub rows: ::prost::alloc::vec::Vec<PostTableDataBulkRow>,
}
/// Bulk insert response.
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct PostTableDataBulkResponse {
/// True if all rows were inserted successfully.
#[prost(bool, tag = "1")]
pub success: bool,
/// Human-readable message.
#[prost(string, tag = "2")]
pub message: ::prost::alloc::string::String,
/// Per-row responses from the underlying PostTableData logic, in request order.
#[prost(message, repeated, tag = "3")]
pub responses: ::prost::alloc::vec::Vec<PostTableDataResponse>,
}
/// Update an existing row. /// Update an existing row.
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, ::prost::Message)]
pub struct PutTableDataRequest { pub struct PutTableDataRequest {
@@ -70,9 +110,10 @@ pub struct PutTableDataRequest {
/// Required. Columns to update (same typing rules as PostTableDataRequest.data). /// Required. Columns to update (same typing rules as PostTableDataRequest.data).
/// ///
/// Special script rules: /// Special script rules:
/// - If a script targets column X and X is included here, the value for X must ///
/// * If a script targets column X and X is included here, the value for X must
/// equal the scripts result (type-aware). /// equal the scripts result (type-aware).
/// - If X is not included here but the update would cause the scripts result /// * If X is not included here but the update would cause the scripts result
/// to change compared to the current stored value, the update is rejected with /// to change compared to the current stored value, the update is rejected with
/// FAILED_PRECONDITION, instructing the caller to include X explicitly. /// FAILED_PRECONDITION, instructing the caller to include X explicitly.
/// ///
@@ -84,7 +125,7 @@ pub struct PutTableDataRequest {
>, >,
} }
/// Update response. /// Update response.
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct PutTableDataResponse { pub struct PutTableDataResponse {
/// True if the update succeeded (or no-op on empty data). /// True if the update succeeded (or no-op on empty data).
#[prost(bool, tag = "1")] #[prost(bool, tag = "1")]
@@ -97,7 +138,7 @@ pub struct PutTableDataResponse {
pub updated_id: i64, pub updated_id: i64,
} }
/// Soft-delete a single row. /// Soft-delete a single row.
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct DeleteTableDataRequest { pub struct DeleteTableDataRequest {
/// Required. Profile (schema) name. /// Required. Profile (schema) name.
#[prost(string, tag = "1")] #[prost(string, tag = "1")]
@@ -110,14 +151,14 @@ pub struct DeleteTableDataRequest {
pub record_id: i64, pub record_id: i64,
} }
/// Soft-delete response. /// Soft-delete response.
#[derive(Clone, Copy, PartialEq, ::prost::Message)] #[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct DeleteTableDataResponse { pub struct DeleteTableDataResponse {
/// True if a row was marked deleted (id existed and was not already deleted). /// True if a row was marked deleted (id existed and was not already deleted).
#[prost(bool, tag = "1")] #[prost(bool, tag = "1")]
pub success: bool, pub success: bool,
} }
/// Fetch a single non-deleted row by id. /// Fetch a single non-deleted row by id.
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct GetTableDataRequest { pub struct GetTableDataRequest {
/// Required. Profile (schema) name. /// Required. Profile (schema) name.
#[prost(string, tag = "1")] #[prost(string, tag = "1")]
@@ -133,9 +174,10 @@ pub struct GetTableDataRequest {
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, ::prost::Message)]
pub struct GetTableDataResponse { pub struct GetTableDataResponse {
/// Map of column_name → stringified value for: /// Map of column_name → stringified value for:
/// - id, deleted ///
/// - all user-defined columns from the table definition /// * id, deleted
/// - FK columns named "<linked_table>_id" for each table link /// * all user-defined columns from the table definition
/// * FK columns named "\<linked_table>\_id" for each table link
/// ///
/// All values are returned as TEXT via col::TEXT and COALESCEed to empty string /// All values are returned as TEXT via col::TEXT and COALESCEed to empty string
/// (NULL becomes ""). The row is returned only if deleted = FALSE. /// (NULL becomes ""). The row is returned only if deleted = FALSE.
@@ -146,7 +188,7 @@ pub struct GetTableDataResponse {
>, >,
} }
/// Count non-deleted rows. /// Count non-deleted rows.
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct GetTableDataCountRequest { pub struct GetTableDataCountRequest {
/// Required. Profile (schema) name. /// Required. Profile (schema) name.
#[prost(string, tag = "1")] #[prost(string, tag = "1")]
@@ -156,7 +198,7 @@ pub struct GetTableDataCountRequest {
pub table_name: ::prost::alloc::string::String, pub table_name: ::prost::alloc::string::String,
} }
/// Fetch by ordinal position among non-deleted rows (1-based). /// Fetch by ordinal position among non-deleted rows (1-based).
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct GetTableDataByPositionRequest { pub struct GetTableDataByPositionRequest {
/// Required. Profile (schema) name. /// Required. Profile (schema) name.
#[prost(string, tag = "1")] #[prost(string, tag = "1")]
@@ -267,13 +309,14 @@ pub mod tables_data_client {
/// Insert a new row into a table with strict type binding and script validation. /// Insert a new row into a table with strict type binding and script validation.
/// ///
/// Behavior: /// Behavior:
/// - Validates that profile (schema) exists and table is defined for it ///
/// - Validates provided columns exist (user-defined or allowed system/FK columns) /// * Validates that profile (schema) exists and table is defined for it
/// - For columns targeted by scripts in this table, the client MUST provide the /// * Validates provided columns exist (user-defined or allowed system/FK columns)
/// * For columns targeted by scripts in this table, the client MUST provide the
/// value, and it MUST equal the scripts calculated value (compared type-safely) /// value, and it MUST equal the scripts calculated value (compared type-safely)
/// - Binds values with correct SQL types, rejects invalid formats/ranges /// * Binds values with correct SQL types, rejects invalid formats/ranges
/// - Inserts the row and returns the new id; queues search indexing (best effort) /// * Inserts the row and returns the new id; queues search indexing (best effort)
/// - If the physical table is missing but the definition exists, returns INTERNAL /// * If the physical table is missing but the definition exists, returns INTERNAL
pub async fn post_table_data( pub async fn post_table_data(
&mut self, &mut self,
request: impl tonic::IntoRequest<super::PostTableDataRequest>, request: impl tonic::IntoRequest<super::PostTableDataRequest>,
@@ -289,7 +332,7 @@ pub mod tables_data_client {
format!("Service was not ready: {}", e.into()), format!("Service was not ready: {}", e.into()),
) )
})?; })?;
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static( let path = http::uri::PathAndQuery::from_static(
"/komp_ac.tables_data.TablesData/PostTableData", "/komp_ac.tables_data.TablesData/PostTableData",
); );
@@ -300,17 +343,57 @@ pub mod tables_data_client {
); );
self.inner.unary(req, path, codec).await self.inner.unary(req, path, codec).await
} }
/// Insert multiple rows by applying PostTableData behavior to each row.
///
/// Behavior:
///
/// * Accepts 1..10,000 rows in one gRPC request
/// * Processes rows in request order
/// * Each row is inserted through the same validation, script execution,
/// typed binding, database insert, and indexing path as PostTableData
/// * Stops at the first failing row and returns that row's gRPC error code
/// with row index context; rows inserted before the failure remain inserted
pub async fn post_table_data_bulk(
&mut self,
request: impl tonic::IntoRequest<super::PostTableDataBulkRequest>,
) -> std::result::Result<
tonic::Response<super::PostTableDataBulkResponse>,
tonic::Status,
> {
self.inner
.ready()
.await
.map_err(|e| {
tonic::Status::unknown(
format!("Service was not ready: {}", e.into()),
)
})?;
let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static(
"/komp_ac.tables_data.TablesData/PostTableDataBulk",
);
let mut req = request.into_request();
req.extensions_mut()
.insert(
GrpcMethod::new(
"komp_ac.tables_data.TablesData",
"PostTableDataBulk",
),
);
self.inner.unary(req, path, codec).await
}
/// Update existing row data with strict type binding and script validation. /// Update existing row data with strict type binding and script validation.
/// ///
/// Behavior: /// Behavior:
/// - Validates profile and table, and that the record exists ///
/// - If request data is empty, returns success without changing the row /// * Validates profile and table, and that the record exists
/// - For columns targeted by scripts: /// * If request data is empty, returns success without changing the row
/// * For columns targeted by scripts:
/// • If included in update, provided value must equal the script result /// • If included in update, provided value must equal the script result
/// • If not included, update must not cause the script result to differ /// • If not included, update must not cause the script result to differ
/// from the current stored value; otherwise FAILED_PRECONDITION is returned /// from the current stored value; otherwise FAILED_PRECONDITION is returned
/// - Binds values with correct SQL types; rejects invalid formats/ranges /// * Binds values with correct SQL types; rejects invalid formats/ranges
/// - Updates the row and returns the id; queues search indexing (best effort) /// * Updates the row and returns the id; queues search indexing (best effort)
pub async fn put_table_data( pub async fn put_table_data(
&mut self, &mut self,
request: impl tonic::IntoRequest<super::PutTableDataRequest>, request: impl tonic::IntoRequest<super::PutTableDataRequest>,
@@ -326,7 +409,7 @@ pub mod tables_data_client {
format!("Service was not ready: {}", e.into()), format!("Service was not ready: {}", e.into()),
) )
})?; })?;
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static( let path = http::uri::PathAndQuery::from_static(
"/komp_ac.tables_data.TablesData/PutTableData", "/komp_ac.tables_data.TablesData/PutTableData",
); );
@@ -340,10 +423,11 @@ pub mod tables_data_client {
/// Soft-delete a single record (sets deleted = true) if it exists and is not already deleted. /// Soft-delete a single record (sets deleted = true) if it exists and is not already deleted.
/// ///
/// Behavior: /// Behavior:
/// - Validates profile and table definition ///
/// - Updates only rows with deleted = false /// * Validates profile and table definition
/// - success = true means a row was actually changed; false means nothing to delete /// * Updates only rows with deleted = false
/// - If the physical table is missing but the definition exists, returns INTERNAL /// * success = true means a row was actually changed; false means nothing to delete
/// * If the physical table is missing but the definition exists, returns INTERNAL
pub async fn delete_table_data( pub async fn delete_table_data(
&mut self, &mut self,
request: impl tonic::IntoRequest<super::DeleteTableDataRequest>, request: impl tonic::IntoRequest<super::DeleteTableDataRequest>,
@@ -359,7 +443,7 @@ pub mod tables_data_client {
format!("Service was not ready: {}", e.into()), format!("Service was not ready: {}", e.into()),
) )
})?; })?;
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static( let path = http::uri::PathAndQuery::from_static(
"/komp_ac.tables_data.TablesData/DeleteTableData", "/komp_ac.tables_data.TablesData/DeleteTableData",
); );
@@ -373,12 +457,13 @@ pub mod tables_data_client {
/// Fetch a single non-deleted row by id as textified values. /// Fetch a single non-deleted row by id as textified values.
/// ///
/// Behavior: /// Behavior:
/// - Validates profile and table definition ///
/// - Returns all columns as strings (COALESCE(col::TEXT, '') AS col) /// * Validates profile and table definition
/// * Returns all columns as strings (COALESCE(col::TEXT, '') AS col)
/// including: id, deleted, all user-defined columns, and FK columns /// including: id, deleted, all user-defined columns, and FK columns
/// named "<linked_table>_id" for each table link /// named "\<linked_table>\_id" for each table link
/// - Fails with NOT_FOUND if record does not exist or is soft-deleted /// * Fails with NOT_FOUND if record does not exist or is soft-deleted
/// - If the physical table is missing but the definition exists, returns INTERNAL /// * If the physical table is missing but the definition exists, returns INTERNAL
pub async fn get_table_data( pub async fn get_table_data(
&mut self, &mut self,
request: impl tonic::IntoRequest<super::GetTableDataRequest>, request: impl tonic::IntoRequest<super::GetTableDataRequest>,
@@ -394,7 +479,7 @@ pub mod tables_data_client {
format!("Service was not ready: {}", e.into()), format!("Service was not ready: {}", e.into()),
) )
})?; })?;
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static( let path = http::uri::PathAndQuery::from_static(
"/komp_ac.tables_data.TablesData/GetTableData", "/komp_ac.tables_data.TablesData/GetTableData",
); );
@@ -408,9 +493,10 @@ pub mod tables_data_client {
/// Count non-deleted rows in a table. /// Count non-deleted rows in a table.
/// ///
/// Behavior: /// Behavior:
/// - Validates profile and table definition ///
/// - Returns komp_ac.common.CountResponse.count with rows where deleted = FALSE /// * Validates profile and table definition
/// - If the physical table is missing but the definition exists, returns INTERNAL /// * Returns komp_ac.common.CountResponse.count with rows where deleted = FALSE
/// * If the physical table is missing but the definition exists, returns INTERNAL
pub async fn get_table_data_count( pub async fn get_table_data_count(
&mut self, &mut self,
request: impl tonic::IntoRequest<super::GetTableDataCountRequest>, request: impl tonic::IntoRequest<super::GetTableDataCountRequest>,
@@ -426,7 +512,7 @@ pub mod tables_data_client {
format!("Service was not ready: {}", e.into()), format!("Service was not ready: {}", e.into()),
) )
})?; })?;
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static( let path = http::uri::PathAndQuery::from_static(
"/komp_ac.tables_data.TablesData/GetTableDataCount", "/komp_ac.tables_data.TablesData/GetTableDataCount",
); );
@@ -443,9 +529,10 @@ pub mod tables_data_client {
/// Fetch the N-th non-deleted row by id order (1-based), then return its full data. /// Fetch the N-th non-deleted row by id order (1-based), then return its full data.
/// ///
/// Behavior: /// Behavior:
/// - position is 1-based (position = 1 → first row by id ASC with deleted = FALSE) ///
/// - Returns NOT_FOUND if position is out of bounds /// * position is 1-based (position = 1 → first row by id ASC with deleted = FALSE)
/// - Otherwise identical to GetTableData for the selected id /// * Returns NOT_FOUND if position is out of bounds
/// * Otherwise identical to GetTableData for the selected id
pub async fn get_table_data_by_position( pub async fn get_table_data_by_position(
&mut self, &mut self,
request: impl tonic::IntoRequest<super::GetTableDataByPositionRequest>, request: impl tonic::IntoRequest<super::GetTableDataByPositionRequest>,
@@ -461,7 +548,7 @@ pub mod tables_data_client {
format!("Service was not ready: {}", e.into()), format!("Service was not ready: {}", e.into()),
) )
})?; })?;
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static( let path = http::uri::PathAndQuery::from_static(
"/komp_ac.tables_data.TablesData/GetTableDataByPosition", "/komp_ac.tables_data.TablesData/GetTableDataByPosition",
); );
@@ -493,13 +580,14 @@ pub mod tables_data_server {
/// Insert a new row into a table with strict type binding and script validation. /// Insert a new row into a table with strict type binding and script validation.
/// ///
/// Behavior: /// Behavior:
/// - Validates that profile (schema) exists and table is defined for it ///
/// - Validates provided columns exist (user-defined or allowed system/FK columns) /// * Validates that profile (schema) exists and table is defined for it
/// - For columns targeted by scripts in this table, the client MUST provide the /// * Validates provided columns exist (user-defined or allowed system/FK columns)
/// * For columns targeted by scripts in this table, the client MUST provide the
/// value, and it MUST equal the scripts calculated value (compared type-safely) /// value, and it MUST equal the scripts calculated value (compared type-safely)
/// - Binds values with correct SQL types, rejects invalid formats/ranges /// * Binds values with correct SQL types, rejects invalid formats/ranges
/// - Inserts the row and returns the new id; queues search indexing (best effort) /// * Inserts the row and returns the new id; queues search indexing (best effort)
/// - If the physical table is missing but the definition exists, returns INTERNAL /// * If the physical table is missing but the definition exists, returns INTERNAL
async fn post_table_data( async fn post_table_data(
&self, &self,
request: tonic::Request<super::PostTableDataRequest>, request: tonic::Request<super::PostTableDataRequest>,
@@ -507,17 +595,35 @@ pub mod tables_data_server {
tonic::Response<super::PostTableDataResponse>, tonic::Response<super::PostTableDataResponse>,
tonic::Status, tonic::Status,
>; >;
/// Insert multiple rows by applying PostTableData behavior to each row.
///
/// Behavior:
///
/// * Accepts 1..10,000 rows in one gRPC request
/// * Processes rows in request order
/// * Each row is inserted through the same validation, script execution,
/// typed binding, database insert, and indexing path as PostTableData
/// * Stops at the first failing row and returns that row's gRPC error code
/// with row index context; rows inserted before the failure remain inserted
async fn post_table_data_bulk(
&self,
request: tonic::Request<super::PostTableDataBulkRequest>,
) -> std::result::Result<
tonic::Response<super::PostTableDataBulkResponse>,
tonic::Status,
>;
/// Update existing row data with strict type binding and script validation. /// Update existing row data with strict type binding and script validation.
/// ///
/// Behavior: /// Behavior:
/// - Validates profile and table, and that the record exists ///
/// - If request data is empty, returns success without changing the row /// * Validates profile and table, and that the record exists
/// - For columns targeted by scripts: /// * If request data is empty, returns success without changing the row
/// * For columns targeted by scripts:
/// • If included in update, provided value must equal the script result /// • If included in update, provided value must equal the script result
/// • If not included, update must not cause the script result to differ /// • If not included, update must not cause the script result to differ
/// from the current stored value; otherwise FAILED_PRECONDITION is returned /// from the current stored value; otherwise FAILED_PRECONDITION is returned
/// - Binds values with correct SQL types; rejects invalid formats/ranges /// * Binds values with correct SQL types; rejects invalid formats/ranges
/// - Updates the row and returns the id; queues search indexing (best effort) /// * Updates the row and returns the id; queues search indexing (best effort)
async fn put_table_data( async fn put_table_data(
&self, &self,
request: tonic::Request<super::PutTableDataRequest>, request: tonic::Request<super::PutTableDataRequest>,
@@ -528,10 +634,11 @@ pub mod tables_data_server {
/// Soft-delete a single record (sets deleted = true) if it exists and is not already deleted. /// Soft-delete a single record (sets deleted = true) if it exists and is not already deleted.
/// ///
/// Behavior: /// Behavior:
/// - Validates profile and table definition ///
/// - Updates only rows with deleted = false /// * Validates profile and table definition
/// - success = true means a row was actually changed; false means nothing to delete /// * Updates only rows with deleted = false
/// - If the physical table is missing but the definition exists, returns INTERNAL /// * success = true means a row was actually changed; false means nothing to delete
/// * If the physical table is missing but the definition exists, returns INTERNAL
async fn delete_table_data( async fn delete_table_data(
&self, &self,
request: tonic::Request<super::DeleteTableDataRequest>, request: tonic::Request<super::DeleteTableDataRequest>,
@@ -542,12 +649,13 @@ pub mod tables_data_server {
/// Fetch a single non-deleted row by id as textified values. /// Fetch a single non-deleted row by id as textified values.
/// ///
/// Behavior: /// Behavior:
/// - Validates profile and table definition ///
/// - Returns all columns as strings (COALESCE(col::TEXT, '') AS col) /// * Validates profile and table definition
/// * Returns all columns as strings (COALESCE(col::TEXT, '') AS col)
/// including: id, deleted, all user-defined columns, and FK columns /// including: id, deleted, all user-defined columns, and FK columns
/// named "<linked_table>_id" for each table link /// named "\<linked_table>\_id" for each table link
/// - Fails with NOT_FOUND if record does not exist or is soft-deleted /// * Fails with NOT_FOUND if record does not exist or is soft-deleted
/// - If the physical table is missing but the definition exists, returns INTERNAL /// * If the physical table is missing but the definition exists, returns INTERNAL
async fn get_table_data( async fn get_table_data(
&self, &self,
request: tonic::Request<super::GetTableDataRequest>, request: tonic::Request<super::GetTableDataRequest>,
@@ -558,9 +666,10 @@ pub mod tables_data_server {
/// Count non-deleted rows in a table. /// Count non-deleted rows in a table.
/// ///
/// Behavior: /// Behavior:
/// - Validates profile and table definition ///
/// - Returns komp_ac.common.CountResponse.count with rows where deleted = FALSE /// * Validates profile and table definition
/// - If the physical table is missing but the definition exists, returns INTERNAL /// * Returns komp_ac.common.CountResponse.count with rows where deleted = FALSE
/// * If the physical table is missing but the definition exists, returns INTERNAL
async fn get_table_data_count( async fn get_table_data_count(
&self, &self,
request: tonic::Request<super::GetTableDataCountRequest>, request: tonic::Request<super::GetTableDataCountRequest>,
@@ -571,9 +680,10 @@ pub mod tables_data_server {
/// Fetch the N-th non-deleted row by id order (1-based), then return its full data. /// Fetch the N-th non-deleted row by id order (1-based), then return its full data.
/// ///
/// Behavior: /// Behavior:
/// - position is 1-based (position = 1 → first row by id ASC with deleted = FALSE) ///
/// - Returns NOT_FOUND if position is out of bounds /// * position is 1-based (position = 1 → first row by id ASC with deleted = FALSE)
/// - Otherwise identical to GetTableData for the selected id /// * Returns NOT_FOUND if position is out of bounds
/// * Otherwise identical to GetTableData for the selected id
async fn get_table_data_by_position( async fn get_table_data_by_position(
&self, &self,
request: tonic::Request<super::GetTableDataByPositionRequest>, request: tonic::Request<super::GetTableDataByPositionRequest>,
@@ -693,7 +803,53 @@ pub mod tables_data_server {
let inner = self.inner.clone(); let inner = self.inner.clone();
let fut = async move { let fut = async move {
let method = PostTableDataSvc(inner); let method = PostTableDataSvc(inner);
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::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.tables_data.TablesData/PostTableDataBulk" => {
#[allow(non_camel_case_types)]
struct PostTableDataBulkSvc<T: TablesData>(pub Arc<T>);
impl<
T: TablesData,
> tonic::server::UnaryService<super::PostTableDataBulkRequest>
for PostTableDataBulkSvc<T> {
type Response = super::PostTableDataBulkResponse;
type Future = BoxFuture<
tonic::Response<Self::Response>,
tonic::Status,
>;
fn call(
&mut self,
request: tonic::Request<super::PostTableDataBulkRequest>,
) -> Self::Future {
let inner = Arc::clone(&self.0);
let fut = async move {
<T as TablesData>::post_table_data_bulk(&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 = PostTableDataBulkSvc(inner);
let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec) let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config( .apply_compression_config(
accept_compression_encodings, accept_compression_encodings,
@@ -738,7 +894,7 @@ pub mod tables_data_server {
let inner = self.inner.clone(); let inner = self.inner.clone();
let fut = async move { let fut = async move {
let method = PutTableDataSvc(inner); let method = PutTableDataSvc(inner);
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec) let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config( .apply_compression_config(
accept_compression_encodings, accept_compression_encodings,
@@ -783,7 +939,7 @@ pub mod tables_data_server {
let inner = self.inner.clone(); let inner = self.inner.clone();
let fut = async move { let fut = async move {
let method = DeleteTableDataSvc(inner); let method = DeleteTableDataSvc(inner);
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec) let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config( .apply_compression_config(
accept_compression_encodings, accept_compression_encodings,
@@ -828,7 +984,7 @@ pub mod tables_data_server {
let inner = self.inner.clone(); let inner = self.inner.clone();
let fut = async move { let fut = async move {
let method = GetTableDataSvc(inner); let method = GetTableDataSvc(inner);
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec) let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config( .apply_compression_config(
accept_compression_encodings, accept_compression_encodings,
@@ -874,7 +1030,7 @@ pub mod tables_data_server {
let inner = self.inner.clone(); let inner = self.inner.clone();
let fut = async move { let fut = async move {
let method = GetTableDataCountSvc(inner); let method = GetTableDataCountSvc(inner);
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec) let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config( .apply_compression_config(
accept_compression_encodings, accept_compression_encodings,
@@ -923,7 +1079,7 @@ pub mod tables_data_server {
let inner = self.inner.clone(); let inner = self.inner.clone();
let fut = async move { let fut = async move {
let method = GetTableDataByPositionSvc(inner); let method = GetTableDataByPositionSvc(inner);
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec) let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config( .apply_compression_config(
accept_compression_encodings, accept_compression_encodings,

View File

@@ -1,5 +1,5 @@
// This file is @generated by prost-build. // This file is @generated by prost-build.
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct PostUctovnictvoRequest { pub struct PostUctovnictvoRequest {
#[prost(int64, tag = "1")] #[prost(int64, tag = "1")]
pub adresar_id: i64, pub adresar_id: i64,
@@ -25,7 +25,7 @@ pub struct PostUctovnictvoRequest {
#[prost(string, tag = "11")] #[prost(string, tag = "11")]
pub firma: ::prost::alloc::string::String, pub firma: ::prost::alloc::string::String,
} }
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct UctovnictvoResponse { pub struct UctovnictvoResponse {
#[prost(int64, tag = "1")] #[prost(int64, tag = "1")]
pub id: i64, pub id: i64,
@@ -52,7 +52,7 @@ pub struct UctovnictvoResponse {
#[prost(string, tag = "12")] #[prost(string, tag = "12")]
pub firma: ::prost::alloc::string::String, pub firma: ::prost::alloc::string::String,
} }
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct PutUctovnictvoRequest { pub struct PutUctovnictvoRequest {
#[prost(int64, tag = "1")] #[prost(int64, tag = "1")]
pub id: i64, pub id: i64,
@@ -79,7 +79,7 @@ pub struct PutUctovnictvoRequest {
#[prost(string, tag = "12")] #[prost(string, tag = "12")]
pub firma: ::prost::alloc::string::String, pub firma: ::prost::alloc::string::String,
} }
#[derive(Clone, Copy, PartialEq, ::prost::Message)] #[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct GetUctovnictvoRequest { pub struct GetUctovnictvoRequest {
#[prost(int64, tag = "1")] #[prost(int64, tag = "1")]
pub id: i64, pub id: i64,
@@ -190,7 +190,7 @@ pub mod uctovnictvo_client {
format!("Service was not ready: {}", e.into()), format!("Service was not ready: {}", e.into()),
) )
})?; })?;
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static( let path = http::uri::PathAndQuery::from_static(
"/komp_ac.uctovnictvo.Uctovnictvo/PostUctovnictvo", "/komp_ac.uctovnictvo.Uctovnictvo/PostUctovnictvo",
); );
@@ -216,7 +216,7 @@ pub mod uctovnictvo_client {
format!("Service was not ready: {}", e.into()), format!("Service was not ready: {}", e.into()),
) )
})?; })?;
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static( let path = http::uri::PathAndQuery::from_static(
"/komp_ac.uctovnictvo.Uctovnictvo/GetUctovnictvo", "/komp_ac.uctovnictvo.Uctovnictvo/GetUctovnictvo",
); );
@@ -242,7 +242,7 @@ pub mod uctovnictvo_client {
format!("Service was not ready: {}", e.into()), format!("Service was not ready: {}", e.into()),
) )
})?; })?;
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static( let path = http::uri::PathAndQuery::from_static(
"/komp_ac.uctovnictvo.Uctovnictvo/GetUctovnictvoCount", "/komp_ac.uctovnictvo.Uctovnictvo/GetUctovnictvoCount",
); );
@@ -271,7 +271,7 @@ pub mod uctovnictvo_client {
format!("Service was not ready: {}", e.into()), format!("Service was not ready: {}", e.into()),
) )
})?; })?;
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static( let path = http::uri::PathAndQuery::from_static(
"/komp_ac.uctovnictvo.Uctovnictvo/GetUctovnictvoByPosition", "/komp_ac.uctovnictvo.Uctovnictvo/GetUctovnictvoByPosition",
); );
@@ -300,7 +300,7 @@ pub mod uctovnictvo_client {
format!("Service was not ready: {}", e.into()), format!("Service was not ready: {}", e.into()),
) )
})?; })?;
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static( let path = http::uri::PathAndQuery::from_static(
"/komp_ac.uctovnictvo.Uctovnictvo/PutUctovnictvo", "/komp_ac.uctovnictvo.Uctovnictvo/PutUctovnictvo",
); );
@@ -468,7 +468,7 @@ pub mod uctovnictvo_server {
let inner = self.inner.clone(); let inner = self.inner.clone();
let fut = async move { let fut = async move {
let method = PostUctovnictvoSvc(inner); let method = PostUctovnictvoSvc(inner);
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec) let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config( .apply_compression_config(
accept_compression_encodings, accept_compression_encodings,
@@ -513,7 +513,7 @@ pub mod uctovnictvo_server {
let inner = self.inner.clone(); let inner = self.inner.clone();
let fut = async move { let fut = async move {
let method = GetUctovnictvoSvc(inner); let method = GetUctovnictvoSvc(inner);
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec) let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config( .apply_compression_config(
accept_compression_encodings, accept_compression_encodings,
@@ -559,7 +559,7 @@ pub mod uctovnictvo_server {
let inner = self.inner.clone(); let inner = self.inner.clone();
let fut = async move { let fut = async move {
let method = GetUctovnictvoCountSvc(inner); let method = GetUctovnictvoCountSvc(inner);
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec) let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config( .apply_compression_config(
accept_compression_encodings, accept_compression_encodings,
@@ -610,7 +610,7 @@ pub mod uctovnictvo_server {
let inner = self.inner.clone(); let inner = self.inner.clone();
let fut = async move { let fut = async move {
let method = GetUctovnictvoByPositionSvc(inner); let method = GetUctovnictvoByPositionSvc(inner);
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec) let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config( .apply_compression_config(
accept_compression_encodings, accept_compression_encodings,
@@ -655,7 +655,7 @@ pub mod uctovnictvo_server {
let inner = self.inner.clone(); let inner = self.inner.clone();
let fut = async move { let fut = async move {
let method = PutUctovnictvoSvc(inner); let method = PutUctovnictvoSvc(inner);
let codec = tonic::codec::ProstCodec::default(); let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec) let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config( .apply_compression_config(
accept_compression_encodings, accept_compression_encodings,

6
flake.lock generated
View File

@@ -20,11 +20,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1753549186, "lastModified": 1780749050,
"narHash": "sha256-Znl7rzuxKg/Mdm6AhimcKynM7V3YeNDIcLjBuoBcmNs=", "narHash": "sha256-3av0pIjlOWQ6rDbNOmpUSvbNnJkGORQKKjb4LtCZsIY=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "17f6bd177404d6d43017595c5264756764444ab8", "rev": "a799d3e3886da994fa307f817a6bc705ae538eeb",
"type": "github" "type": "github"
}, },
"original": { "original": {

View File

@@ -15,5 +15,5 @@ tracing = { workspace = true }
tantivy = { workspace = true } tantivy = { workspace = true }
common = { path = "../common" } common = { path = "../common" }
tonic-reflection = "0.13.1" tonic-reflection = "0.14.6"
sqlx = { version = "0.8.6", features = ["postgres"] } sqlx = { version = "0.9.0", features = ["postgres"] }

View File

@@ -6,10 +6,10 @@ use std::sync::{Arc, Mutex};
use common::proto::komp_ac::search::searcher_server::Searcher; use common::proto::komp_ac::search::searcher_server::Searcher;
pub use common::proto::komp_ac::search::searcher_server::SearcherServer; pub use common::proto::komp_ac::search::searcher_server::SearcherServer;
use common::proto::komp_ac::search::{search_response::Hit, SearchRequest, SearchResponse}; use common::proto::komp_ac::search::{SearchRequest, SearchResponse, search_response::Hit};
use common::search::{register_tokenizers, search_index_path, SchemaFields}; use common::search::{SchemaFields, register_tokenizers, search_index_path};
use query_builder::{build_master_query, ConstraintMode, SearchConstraint}; use query_builder::{ConstraintMode, SearchConstraint, build_master_query};
use sqlx::{PgPool, Row}; use sqlx::{AssertSqlSafe, PgPool, Row};
use tantivy::collector::TopDocs; use tantivy::collector::TopDocs;
use tantivy::schema::Value; use tantivy::schema::Value;
use tantivy::{Index, IndexReader, ReloadPolicy, TantivyDocument}; use tantivy::{Index, IndexReader, ReloadPolicy, TantivyDocument};
@@ -112,7 +112,6 @@ impl SearcherService {
Ok(Response::new(SearchResponse { hits })) Ok(Response::new(SearchResponse { hits }))
} }
} }
struct ProfileIndex { struct ProfileIndex {
@@ -322,7 +321,7 @@ async fn fetch_latest_rows(
qualify_profile_table(profile_name, table_name) qualify_profile_table(profile_name, table_name)
); );
let rows = sqlx::query(&sql) let rows = sqlx::query(AssertSqlSafe(sql))
.bind(limit as i64) .bind(limit as i64)
.fetch_all(pool) .fetch_all(pool)
.await .await
@@ -362,7 +361,7 @@ async fn run_search(
let searcher = profile.reader.searcher(); let searcher = profile.reader.searcher();
let top_docs = searcher let top_docs = searcher
.search(&*master_query, &TopDocs::with_limit(limit)) .search(&*master_query, &TopDocs::with_limit(limit).order_by_score())
.map_err(|e| Status::internal(format!("Search failed: {}", e)))?; .map_err(|e| Status::internal(format!("Search failed: {}", e)))?;
if top_docs.is_empty() { if top_docs.is_empty() {
@@ -409,7 +408,7 @@ async fn run_search(
qualify_profile_table(profile_name, &table_name) qualify_profile_table(profile_name, &table_name)
); );
let rows = sqlx::query(&sql) let rows = sqlx::query(AssertSqlSafe(sql))
.bind(&pg_ids) .bind(&pg_ids)
.fetch_all(pool) .fetch_all(pool)
.await .await

2
server

Submodule server updated: aa0f9a3108...3c3a1d6698

1
tui-canvas Submodule

Submodule tui-canvas added at cea9ced406

1
tui-pages Submodule

Submodule tui-pages added at 4a06774f0e

View File

@@ -0,0 +1,33 @@
1. Action System
tui-pages intentionally does not provide ActionResolution like client/src/action_engine/action_decider/
handler.rs:23. Replace it in the client adapter/handler, not in tui-pages.
Best path: keep the routing logic as app code inside TuiActionHandler::handle_action, or keep a private helper
equivalent to ActionDecider::resolve. ctx.current_view and ctx.focus from tui-pages/src/runtime/mod.rs:181 give
you enough data to route page/canvas/global actions. This is a client philosophy change: routing becomes part of
the app handler, while tui-pages only provides focus/view/input context.
2. Overlay Types
No tui-pages change needed. Your old OverlayKind maps naturally to the generic O parameter.
Define something like client-side enum ClientOverlay { CommandBar, SearchPalette, FindFilePalette, Sidebar,
Picker }, then use FocusTarget::Overlay(ClientOverlay::CommandBar) etc. DialogButton(usize) should probably
become FocusTarget::ModalItem(usize) if you use the modal path, because tui-pages separates simple named overlays
from modal item focus in tui-pages/src/focus/target.rs:19.
3. String vs Type-Based Modes
This is not a real incompatibility. ModeId is just a typed wrapper over strings and implements AsRef<str>/
From<String> in tui-pages/src/runtime/mod.rs:13. Your current KeyMode::as_str() values already match the tui-
pages::modes constants.
The actual migration is moving mode calculation from FocusTarget::mode_hint() in client/src/focus_manager/
target.rs:50 into PageSpec::modes(...). Since page_spec(view, state, focus) receives focus, you can preserve the
same behavior there. Watch one behavior: the old client converts plain insert-mode chars into
CanvasAction::InsertChar in client/src/input_pipeline/pipeline.rs:90; tui-pages returns PipelineResponse::Type
instead. Preserve that in TuiActionHandler::handle_text.
4. Page Identification
PageIdentifier should likely disappear. It duplicates AppView. tui-pages already gives ctx.current_view, so
checks like PageIdentifier::Form(_) become matches!(ctx.current_view, AppView::Form(_)).
This is a natural cleanup, not a tui-pages gap. The only case to keep a separate identifier is if you
intentionally want to collapse several AppView variants into one routing bucket. Even then, make it a client-
local helper derived from AppView, not a runtime concept.

View File

@@ -1,18 +0,0 @@
[package]
name = "validation-core"
version.workspace = true
edition.workspace = true
license.workspace = true
authors.workspace = true
description = "Shared validation primitives, rules, and sets."
repository.workspace = true
[dependencies]
serde = { workspace = true }
thiserror = { workspace = true }
unicode-width = { workspace = true }
regex = { workspace = true, optional = true }
[features]
default = []
regex = ["dep:regex"]

View File

@@ -1,493 +0,0 @@
# Validation
This document is the frontend guide for the validation system.
The important idea: reusable validation is built from **rules** and **sets**.
The frontend creates and manages those. When a set is applied to a table field,
the server resolves it into the existing `FieldValidation` shape, and the form
runtime continues to work through the normal table-validation flow.
## Ownership
```mermaid
flowchart LR
Core[validation-core<br/>validation meaning<br/>rule/set merge rules]
Server[server<br/>stores rules/sets<br/>applies sets<br/>enforces writes]
Common[common/proto<br/>gRPC contract]
Client[client/frontend<br/>rule/set UI<br/>calls gRPC]
Canvas[canvas<br/>field editing<br/>mask display<br/>local feedback]
Server --> Core
Canvas --> Core
Client --> Common
Server --> Common
Client --> Canvas
```
`server` stores simple serializable settings. `validation-core` owns how those
settings combine. `canvas` uses resolved field validation to guide editing.
## Terms
| Term | Meaning |
| --- | --- |
| `FieldValidation` | Existing per-column validation config from `common/proto/table_validation.proto`. This is what forms/canvas already consume. |
| `ValidationRule` | One named reusable fragment, for example `digits-only`, `phone-length`, or `required`. Stored by the server as a `FieldValidation` fragment with no meaningful `dataKey`. |
| `ValidationSet` | Ordered collection of rule names, for example `phone = [required, phone-length, digits-only, phone-mask]`. |
| Applied validation | A resolved snapshot of a set written to `table_validation_rules` for a concrete `(table, dataKey)`. |
| Snapshot | Applying a set copies the resolved config to a field. Later edits to the set do not automatically update fields that were already applied. |
## What Backend Enforces
Backend write validation enforces only server-relevant parts:
| FieldValidation part | Backend | Canvas/frontend |
| --- | --- | --- |
| `required` | Yes | Yes |
| `limits` | Yes | Yes |
| `pattern` | Yes | Yes |
| `allowed_values` | Yes | Yes |
| `mask` | Partly: raw value length/literals | Yes: display/editing mask |
| `formatter` | No | Yes |
| `external_validation_enabled` | No | Yes/UI hint |
`mask` is visual metadata, but the backend still uses it to reject incorrectly
submitted raw values. Example: if the mask is `(###) ###-####`, the backend
expects the stored value to be raw digits, not `(123) 456-7890`.
## Main User Flow
```mermaid
sequenceDiagram
participant UI as Frontend UI
participant API as TableValidationService
participant DB as Server DB
participant Form as Existing Form Runtime
UI->>API: UpsertValidationRule(required)
UI->>API: UpsertValidationRule(digits-only)
UI->>API: UpsertValidationRule(phone-length)
UI->>API: UpsertValidationSet(phone: [required, phone-length, digits-only])
UI->>API: ApplyValidationSet(profile, table, dataKey, phone)
API->>DB: write resolved FieldValidation snapshot
Form->>API: GetTableValidation(profile, table)
API->>Form: resolved FieldValidation for dataKey
```
After `ApplyValidationSet`, the existing form code does not need to know that a
set was used. It receives normal `FieldValidation`.
## API
All APIs live on `TableValidationService`.
### Rules
Create or update one reusable rule:
```text
UpsertValidationRule(UpsertValidationRuleRequest)
```
Request shape:
```text
profileName: string
rule:
name: string
description: optional string
validation: FieldValidation
```
Frontend rules:
- `rule.name` is required and unique inside a profile.
- `rule.validation.dataKey` is ignored by the server.
- A rule should usually configure one logical fragment.
- Examples: `required`, `phone-length`, `digits-only`, `phone-mask`.
List rules:
```text
ListValidationRules({ profileName })
```
Delete rule:
```text
DeleteValidationRule({ profileName, name })
```
Deleting a rule removes it from future reusable composition. Already applied
field snapshots are not changed.
### Sets
Create or update one reusable set:
```text
UpsertValidationSet(UpsertValidationSetRequest)
```
Request shape:
```text
profileName: string
set:
name: string
description: optional string
ruleItems: repeated ValidationSetRuleItem
```
Frontend rules:
- `set.name` is required and unique inside a profile.
- `ruleItems` must contain at least one item.
- `ruleItems` are ordered.
- Every global rule reference must already exist.
- Duplicate rule names in the same set are rejected.
- Conflicting singleton fragments are rejected.
Singleton fragments are:
```text
limits
allowed_values
mask
formatter
```
That means a set cannot currently contain two rules that both define `limits`.
Pattern rules are additive: multiple rules with `pattern` are merged into one
combined pattern.
List sets:
```text
ListValidationSets({ profileName })
```
Response includes each set plus `resolvedValidation`, so the frontend can show
what the set expands to.
Delete set:
```text
DeleteValidationSet({ profileName, name })
```
Deleting a set does not change already applied fields.
### Apply Set To Field
Apply a reusable set to one field:
```text
ApplyValidationSet(ApplyValidationSetRequest)
```
Request shape:
```text
profileName: string
tableName: string
dataKey: string
setName: string
```
Server behavior:
1. Loads the set.
2. Loads its ordered rules.
3. Resolves/merges them through `validation-core`.
4. Validates that `dataKey` exists in the table definition.
5. Writes the resolved config into existing `table_validation_rules`.
This is a snapshot. If the user later edits the `phone` set, fields that already
used `phone` keep their old resolved config until the set is applied again.
## FieldValidation Guide
Rules and direct field validation both use `FieldValidation`.
### Required
```text
required: true
```
Backend rejects missing or empty values.
### Limits
```text
limits:
min: 10
max: 10
warnAt: optional
countMode: CHARS | BYTES | DISPLAY_WIDTH
```
Backend enforces `min` and `max`. `warnAt` is mainly UI feedback.
### Pattern
Pattern rules validate characters at positions.
Example digits-only:
```text
pattern:
rules:
- position:
kind: PATTERN_POSITION_FROM
start: 0
constraint:
kind: CHARACTER_CONSTRAINT_NUMERIC
```
Useful constraints:
```text
CHARACTER_CONSTRAINT_ALPHABETIC
CHARACTER_CONSTRAINT_NUMERIC
CHARACTER_CONSTRAINT_ALPHANUMERIC
CHARACTER_CONSTRAINT_EXACT
CHARACTER_CONSTRAINT_ONE_OF
CHARACTER_CONSTRAINT_REGEX
```
Pattern fragments from multiple rules are merged.
### Allowed Values
```text
allowed_values:
values: ["open", "closed"]
allow_empty: false
case_insensitive: true
```
Backend rejects values not in the list.
### Mask
```text
mask:
pattern: "(###) ###-####"
input_char: "#"
template_char: "_"
```
Canvas uses this for display/editing. Backend expects raw values without mask
literals.
### Formatter
```text
formatter:
type: "PhoneFormatter"
options: []
description: optional
```
Formatter is resolved client-side. Backend stores it but does not execute it.
### External Validation
```text
external_validation_enabled: true
```
This is a frontend/UI hint. Backend stores it but does not perform external
validation.
## Recommended Frontend Screens
### Rule List
Show all rules for a profile.
Actions:
```text
create rule
edit rule
delete rule
preview rule config
```
### Rule Editor
Build a `ValidationRuleDefinition`.
Recommended UI:
```text
name
description
required toggle
limits section
pattern section
allowed values section
mask section
formatter section
external validation toggle
```
For v1, encourage one fragment per rule. Example: create `phone-length` and
`digits-only` separately, instead of one huge rule.
### Set List
Show all sets for a profile.
Use `ListValidationSets`, because it returns `resolvedValidation`.
Actions:
```text
create set
edit set
delete set
preview resolved validation
```
### Set Editor
Build a `ValidationSetDefinition`.
Recommended UI:
```text
name
description
ordered global/inline rule item picker
resolved preview
```
When rule ordering changes, call `UpsertValidationSet` and then refresh
`ListValidationSets`.
### Apply Set
On the table/field validation screen, add:
```text
Apply validation set
```
Flow:
1. Load sets with `ListValidationSets`.
2. User selects a set.
3. Call `ApplyValidationSet(profileName, tableName, dataKey, setName)`.
4. Refresh `GetTableValidation(profileName, tableName)`.
The field should now behave exactly like a directly configured field validation.
## Example: Phone
Create rule `required`:
```text
validation:
required: true
```
Create rule `phone-length`:
```text
validation:
limits:
min: 10
max: 10
countMode: CHARS
```
Create rule `digits-only`:
```text
validation:
pattern:
rules:
- position:
kind: PATTERN_POSITION_FROM
start: 0
constraint:
kind: CHARACTER_CONSTRAINT_NUMERIC
```
Create rule `phone-mask`:
```text
validation:
mask:
pattern: "(###) ###-####"
input_char: "#"
```
Create set `phone`:
```text
ruleItems:
- globalRuleName: required
- globalRuleName: phone-length
- globalRuleName: digits-only
- globalRuleName: phone-mask
```
Apply set:
```text
profileName: "default"
tableName: "customers"
dataKey: "customer_phone"
setName: "phone"
```
Then refresh:
```text
GetTableValidation(default, customers)
```
The response contains a normal `FieldValidation` for `customer_phone`.
## Important UX Notes
- Applying a set is not a live link.
- Editing a rule or set does not mutate fields where it was already applied.
- To update a field after set changes, apply the set again.
- If a set has conflicting singleton rules, the server rejects it.
- For now, the system does not store field metadata like `sourceSetName` on
applied fields. The field only stores the resolved validation snapshot.
## Files
Core model:
```text
validation-core/src/set.rs
validation-core/src/config.rs
```
Wire contract:
```text
common/proto/table_validation.proto
```
Server implementation:
```text
server/src/table_validation/get/service.rs
server/src/table_validation/post/repo.rs
server/src/table_validation/config.rs
```
Storage:
```text
server/migrations/20260506170000_create_validation_rules_and_sets.sql
```

View File

@@ -1,311 +0,0 @@
use crate::rules::{
CharacterFilter, CharacterLimits, DisplayMask, PatternFilters, PositionFilter, PositionRange,
};
use serde::{Deserialize, Serialize};
use std::sync::Arc;
use thiserror::Error;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AllowedValues {
pub values: Vec<String>,
pub allow_empty: bool,
pub case_insensitive: bool,
}
impl AllowedValues {
pub fn new(values: Vec<String>) -> Self {
Self {
values,
allow_empty: true,
case_insensitive: false,
}
}
pub fn allow_empty(mut self, allow_empty: bool) -> Self {
self.allow_empty = allow_empty;
self
}
pub fn case_insensitive(mut self, case_insensitive: bool) -> Self {
self.case_insensitive = case_insensitive;
self
}
pub fn matches(&self, text: &str) -> bool {
if self.case_insensitive {
self.values
.iter()
.any(|allowed| allowed.eq_ignore_ascii_case(text))
} else {
self.values.iter().any(|allowed| allowed == text)
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FormatterSettings {
pub formatter_type: String,
pub options: Vec<FormatterOption>,
pub description: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FormatterOption {
pub key: String,
pub value: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum CharacterFilterSettings {
Alphabetic,
Numeric,
Alphanumeric,
Exact(char),
OneOf(Vec<char>),
Regex(String),
}
impl CharacterFilterSettings {
pub fn resolve(&self) -> CharacterFilter {
match self {
Self::Alphabetic => CharacterFilter::Alphabetic,
Self::Numeric => CharacterFilter::Numeric,
Self::Alphanumeric => CharacterFilter::Alphanumeric,
Self::Exact(ch) => CharacterFilter::Exact(*ch),
Self::OneOf(chars) => CharacterFilter::OneOf(chars.clone()),
Self::Regex(pattern) => {
#[cfg(feature = "regex")]
{
match regex::Regex::new(pattern) {
Ok(regex) => CharacterFilter::Custom(Arc::new(move |ch| {
regex.is_match(&ch.to_string())
})),
Err(_) => CharacterFilter::Custom(Arc::new(|_| false)),
}
}
#[cfg(not(feature = "regex"))]
{
let _ = pattern;
CharacterFilter::Custom(Arc::new(|_| false))
}
}
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PositionFilterSettings {
pub positions: PositionRange,
pub filter: CharacterFilterSettings,
}
impl PositionFilterSettings {
pub fn resolve(&self) -> PositionFilter {
PositionFilter::new(self.positions.clone(), self.filter.resolve())
}
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct PatternSettings {
pub filters: Vec<PositionFilterSettings>,
pub description: Option<String>,
}
impl PatternSettings {
pub fn resolve(&self) -> PatternFilters {
PatternFilters::new().add_filters(
self.filters
.iter()
.map(PositionFilterSettings::resolve)
.collect(),
)
}
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct ValidationSettings {
pub required: bool,
pub character_limits: Option<CharacterLimits>,
pub pattern: Option<PatternSettings>,
pub allowed_values: Option<AllowedValues>,
pub display_mask: Option<DisplayMask>,
pub formatter: Option<FormatterSettings>,
pub external_validation_enabled: bool,
}
impl ValidationSettings {
pub fn resolve(&self) -> ValidationConfig {
ValidationConfig {
required: self.required,
character_limits: self.character_limits.clone(),
pattern_filters: self.pattern.as_ref().map(PatternSettings::resolve),
allowed_values: self.allowed_values.clone(),
display_mask: self.display_mask.clone(),
formatter: self.formatter.clone(),
external_validation_enabled: self.external_validation_enabled,
}
}
pub fn merge_rules<'a>(
rules: impl IntoIterator<Item = &'a ValidationSettings>,
) -> Result<Self, ValidationMergeError> {
let mut merged = ValidationSettings::default();
for rule in rules {
merged.merge_rule(rule)?;
}
Ok(merged)
}
pub fn merge_rule(&mut self, rule: &ValidationSettings) -> Result<(), ValidationMergeError> {
self.required |= rule.required;
self.external_validation_enabled |= rule.external_validation_enabled;
merge_singleton(
"character_limits",
&mut self.character_limits,
&rule.character_limits,
)?;
merge_singleton(
"allowed_values",
&mut self.allowed_values,
&rule.allowed_values,
)?;
merge_singleton("display_mask", &mut self.display_mask, &rule.display_mask)?;
merge_singleton("formatter", &mut self.formatter, &rule.formatter)?;
if let Some(pattern) = &rule.pattern {
match &mut self.pattern {
Some(existing) => {
existing.filters.extend(pattern.filters.clone());
if existing.description.is_none() {
existing.description = pattern.description.clone();
}
}
None => self.pattern = Some(pattern.clone()),
}
}
Ok(())
}
}
fn merge_singleton<T: Clone>(
field_name: &'static str,
target: &mut Option<T>,
source: &Option<T>,
) -> Result<(), ValidationMergeError> {
if let Some(source) = source {
if target.is_some() {
return Err(ValidationMergeError::DuplicateSingleton { field_name });
}
*target = Some(source.clone());
}
Ok(())
}
#[derive(Debug, Clone, PartialEq, Eq, Error)]
pub enum ValidationMergeError {
#[error("validation set contains more than one rule configuring {field_name}")]
DuplicateSingleton { field_name: &'static str },
}
#[derive(Debug, Clone, Default)]
pub struct ValidationConfig {
pub required: bool,
pub character_limits: Option<CharacterLimits>,
pub pattern_filters: Option<PatternFilters>,
pub allowed_values: Option<AllowedValues>,
pub display_mask: Option<DisplayMask>,
pub formatter: Option<FormatterSettings>,
pub external_validation_enabled: bool,
}
impl ValidationConfig {
pub fn validate_content(&self, text: &str) -> ValidationResult {
if text.is_empty() {
if self.required {
return ValidationResult::error("Value required");
}
if let Some(allowed_values) = &self.allowed_values {
if !allowed_values.allow_empty {
return ValidationResult::error("Empty value is not allowed");
}
}
return ValidationResult::Valid;
}
if let Some(limits) = &self.character_limits {
if let Some(result) = limits.validate_content(text) {
if !result.is_acceptable() {
return result;
}
}
}
if let Some(pattern_filters) = &self.pattern_filters {
if let Err(message) = pattern_filters.validate_text(text) {
return ValidationResult::error(message);
}
}
if let Some(allowed_values) = &self.allowed_values {
if !allowed_values.matches(text) {
return ValidationResult::error("Value must be one of the allowed options");
}
}
ValidationResult::Valid
}
pub fn has_validation(&self) -> bool {
self.required
|| self.character_limits.is_some()
|| self.pattern_filters.is_some()
|| self.allowed_values.is_some()
|| self.display_mask.is_some()
|| self.formatter.is_some()
|| self.external_validation_enabled
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ValidationResult {
Valid,
Warning { message: String },
Error { message: String },
}
impl ValidationResult {
pub fn is_acceptable(&self) -> bool {
matches!(self, Self::Valid | Self::Warning { .. })
}
pub fn is_error(&self) -> bool {
matches!(self, Self::Error { .. })
}
pub fn message(&self) -> Option<&str> {
match self {
Self::Valid => None,
Self::Warning { message } | Self::Error { message } => Some(message),
}
}
pub fn warning(message: impl Into<String>) -> Self {
Self::Warning {
message: message.into(),
}
}
pub fn error(message: impl Into<String>) -> Self {
Self::Error {
message: message.into(),
}
}
}

View File

@@ -1,16 +0,0 @@
pub mod config;
pub mod rules;
pub mod set;
pub use config::{
AllowedValues, CharacterFilterSettings, FormatterOption, FormatterSettings, PatternSettings,
PositionFilterSettings, ValidationConfig, ValidationMergeError, ValidationResult,
ValidationSettings,
};
pub use rules::{
count_text, CharacterFilter, CharacterLimits, CountMode, DisplayMask, LimitCheckResult,
MaskDisplayMode, PatternFilters, PositionFilter, PositionRange,
};
pub use set::{
AppliedValidation, ValidationRule, ValidationSet, ValidationSetItem, ValidationSetResolveError,
};

View File

@@ -1,452 +0,0 @@
// src/validation/limits.rs
//! Character limits validation implementation
use crate::ValidationResult;
use serde::{Deserialize, Serialize};
use unicode_width::UnicodeWidthStr;
/// Character limits configuration for a field
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CharacterLimits {
/// Maximum number of characters allowed (None = unlimited)
max_length: Option<usize>,
/// Minimum number of characters required (None = no minimum)
min_length: Option<usize>,
/// Warning threshold (warn when approaching max limit)
warning_threshold: Option<usize>,
/// Count mode: characters vs display width
count_mode: CountMode,
}
/// How to count characters for limit checking
#[derive(Debug, Clone, Copy, Serialize, Deserialize, Default)]
pub enum CountMode {
/// Count actual characters (default)
#[default]
Characters,
/// Count display width (useful for CJK characters)
DisplayWidth,
/// Count bytes (rarely used, but available)
Bytes,
}
/// Result of a character limit check
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum LimitCheckResult {
/// Within limits
Ok,
/// Approaching limit (warning)
Warning { current: usize, max: usize },
/// At or exceeding limit (error)
Exceeded { current: usize, max: usize },
/// Below minimum length
TooShort { current: usize, min: usize },
}
impl CharacterLimits {
/// Create new character limits with just max length
pub fn new(max_length: usize) -> Self {
Self {
max_length: Some(max_length),
min_length: None,
warning_threshold: None,
count_mode: CountMode::default(),
}
}
/// Create new character limits with min and max
pub fn new_range(min_length: usize, max_length: usize) -> Self {
Self {
max_length: Some(max_length),
min_length: Some(min_length),
warning_threshold: None,
count_mode: CountMode::default(),
}
}
/// Create new character limits with just minimum length
pub fn new_min(min_length: usize) -> Self {
Self {
max_length: None,
min_length: Some(min_length),
warning_threshold: None,
count_mode: CountMode::default(),
}
}
/// Create new character limits with only a warning threshold.
pub fn new_warning(threshold: usize) -> Self {
Self {
max_length: None,
min_length: None,
warning_threshold: Some(threshold),
count_mode: CountMode::default(),
}
}
/// Set warning threshold (when to show warning before hitting limit)
pub fn with_warning_threshold(mut self, threshold: usize) -> Self {
self.warning_threshold = Some(threshold);
self
}
/// Set count mode (characters vs display width vs bytes)
pub fn with_count_mode(mut self, mode: CountMode) -> Self {
self.count_mode = mode;
self
}
/// Get maximum length
pub fn max_length(&self) -> Option<usize> {
self.max_length
}
/// Get minimum length
pub fn min_length(&self) -> Option<usize> {
self.min_length
}
/// Get warning threshold
pub fn warning_threshold(&self) -> Option<usize> {
self.warning_threshold
}
/// Get count mode
pub fn count_mode(&self) -> CountMode {
self.count_mode
}
/// Count characters/width/bytes according to the configured mode
fn count(&self, text: &str) -> usize {
match self.count_mode {
CountMode::Characters => text.chars().count(),
CountMode::DisplayWidth => text.width(),
CountMode::Bytes => text.len(),
}
}
/// Check if inserting a character would exceed limits
pub fn validate_insertion(
&self,
current_text: &str,
position: usize,
character: char,
) -> Option<ValidationResult> {
let mut new_text = String::with_capacity(current_text.len() + character.len_utf8());
let mut chars = current_text.chars();
let clamped_pos = position.min(current_text.chars().count());
for _ in 0..clamped_pos {
if let Some(ch) = chars.next() {
new_text.push(ch);
}
}
new_text.push(character);
for ch in chars {
new_text.push(ch);
}
let new_count = self.count(&new_text);
let current_count = self.count(current_text);
if let Some(max) = self.max_length {
if new_count > max {
return Some(ValidationResult::error(format!(
"Character limit exceeded: {new_count}/{max}"
)));
}
if let Some(warning_threshold) = self.warning_threshold {
if new_count >= warning_threshold && current_count < warning_threshold {
return Some(ValidationResult::warning(format!(
"Approaching character limit: {new_count}/{max}"
)));
}
}
}
None // No validation issues
}
/// Validate the current content
pub fn validate_content(&self, text: &str) -> Option<ValidationResult> {
let count = self.count(text);
if let Some(min) = self.min_length {
if count < min {
return Some(ValidationResult::warning(format!(
"Minimum length not met: {count}/{min}"
)));
}
}
if let Some(max) = self.max_length {
if count > max {
return Some(ValidationResult::error(format!(
"Character limit exceeded: {count}/{max}"
)));
}
if let Some(warning_threshold) = self.warning_threshold {
if count >= warning_threshold {
return Some(ValidationResult::warning(format!(
"Approaching character limit: {count}/{max}"
)));
}
}
}
None // No validation issues
}
/// Get the current status of the text against limits
pub fn check_limits(&self, text: &str) -> LimitCheckResult {
let count = self.count(text);
if let Some(max) = self.max_length {
if count > max {
return LimitCheckResult::Exceeded {
current: count,
max,
};
}
if let Some(warning_threshold) = self.warning_threshold {
if count >= warning_threshold {
return LimitCheckResult::Warning {
current: count,
max,
};
}
}
}
// Check min length
if let Some(min) = self.min_length {
if count < min {
return LimitCheckResult::TooShort {
current: count,
min,
};
}
}
LimitCheckResult::Ok
}
/// Get a human-readable status string
pub fn status_text(&self, text: &str) -> Option<String> {
match self.check_limits(text) {
LimitCheckResult::Ok => {
// Show current/max if we have a max limit
self.max_length
.map(|max| format!("{}/{}", self.count(text), max))
}
LimitCheckResult::Warning { current, max } => {
Some(format!("{current}/{max} (approaching limit)"))
}
LimitCheckResult::Exceeded { current, max } => {
Some(format!("{current}/{max} (exceeded)"))
}
LimitCheckResult::TooShort { current, min } => Some(format!("{current}/{min} minimum")),
}
}
pub fn allows_field_switch(&self, text: &str) -> bool {
if let Some(min) = self.min_length {
let count = self.count(text);
// Allow switching if field is empty OR meets minimum requirement
count == 0 || count >= min
} else {
true // No minimum requirement, always allow switching
}
}
/// Get reason why field switching is not allowed (if any)
pub fn field_switch_block_reason(&self, text: &str) -> Option<String> {
if let Some(min) = self.min_length {
let count = self.count(text);
if count > 0 && count < min {
return Some(format!(
"Field must be empty or have at least {min} characters (currently: {count})"
));
}
}
None
}
}
pub fn count_text(text: &str, mode: CountMode) -> usize {
match mode {
CountMode::Characters => text.chars().count(),
CountMode::DisplayWidth => text.width(),
CountMode::Bytes => text.len(),
}
}
impl Default for CharacterLimits {
fn default() -> Self {
Self {
max_length: Some(30), // Default 30 character limit as specified
min_length: None,
warning_threshold: None,
count_mode: CountMode::default(),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_character_limits_creation() {
let limits = CharacterLimits::new(10);
assert_eq!(limits.max_length(), Some(10));
assert_eq!(limits.min_length(), None);
let range_limits = CharacterLimits::new_range(5, 15);
assert_eq!(range_limits.min_length(), Some(5));
assert_eq!(range_limits.max_length(), Some(15));
}
#[test]
fn test_default_limits() {
let limits = CharacterLimits::default();
assert_eq!(limits.max_length(), Some(30));
}
#[test]
fn test_character_counting() {
let limits = CharacterLimits::new(5);
// Test character mode (default)
assert_eq!(limits.count("hello"), 5);
assert_eq!(limits.count("héllo"), 5); // Accented character counts as 1
// Test display width mode
let limits = limits.with_count_mode(CountMode::DisplayWidth);
assert_eq!(limits.count("hello"), 5);
// Test bytes mode
let limits = limits.with_count_mode(CountMode::Bytes);
assert_eq!(limits.count("hello"), 5);
assert_eq!(limits.count("héllo"), 6); // é takes 2 bytes in UTF-8
}
#[test]
fn test_insertion_validation() {
let limits = CharacterLimits::new(5);
// Valid insertion
let result = limits.validate_insertion("test", 4, 'x');
assert!(result.is_none()); // No validation issues
// Invalid insertion (would exceed limit)
let result = limits.validate_insertion("tests", 5, 'x');
assert!(result.is_some());
assert!(!result.unwrap().is_acceptable());
}
#[test]
fn test_content_validation() {
let limits = CharacterLimits::new_range(3, 10);
// Too short
let result = limits.validate_content("hi");
assert!(result.is_some());
assert!(result.unwrap().is_acceptable()); // Warning, not error
// Just right
let result = limits.validate_content("hello");
assert!(result.is_none());
// Too long
let result = limits.validate_content("hello world!");
assert!(result.is_some());
assert!(!result.unwrap().is_acceptable()); // Error
}
#[test]
fn test_warning_threshold() {
let limits = CharacterLimits::new(10).with_warning_threshold(8);
// Below warning threshold
let result = limits.validate_insertion("123456", 6, 'x');
assert!(result.is_none());
// At warning threshold
let result = limits.validate_insertion("1234567", 7, 'x');
assert!(result.is_some()); // This brings us to 8 chars
assert!(result.unwrap().is_acceptable()); // Warning, not error
let result = limits.validate_insertion("12345678", 8, 'x');
assert!(result.is_none());
}
#[test]
fn test_status_text() {
let limits = CharacterLimits::new(10);
assert_eq!(limits.status_text("hello"), Some("5/10".to_string()));
let limits = limits.with_warning_threshold(8);
assert_eq!(
limits.status_text("12345678"),
Some("8/10 (approaching limit)".to_string())
);
assert_eq!(
limits.status_text("1234567890x"),
Some("11/10 (exceeded)".to_string())
);
}
#[test]
fn test_field_switch_blocking() {
let limits = CharacterLimits::new_range(3, 10);
// Empty field: should allow switching
assert!(limits.allows_field_switch(""));
assert!(limits.field_switch_block_reason("").is_none());
// Field with content below minimum: should block switching
assert!(!limits.allows_field_switch("hi"));
assert!(limits.field_switch_block_reason("hi").is_some());
assert!(limits
.field_switch_block_reason("hi")
.unwrap()
.contains("at least 3 characters"));
// Field meeting minimum: should allow switching
assert!(limits.allows_field_switch("hello"));
assert!(limits.field_switch_block_reason("hello").is_none());
// Field exceeding maximum: should still allow switching (validation shows error but doesn't block)
assert!(limits.allows_field_switch("this is way too long"));
assert!(limits
.field_switch_block_reason("this is way too long")
.is_none());
}
#[test]
fn test_field_switch_no_minimum() {
let limits = CharacterLimits::new(10); // Only max, no minimum
// Should always allow switching when there's no minimum
assert!(limits.allows_field_switch(""));
assert!(limits.allows_field_switch("a"));
assert!(limits.allows_field_switch("hello"));
assert!(limits.field_switch_block_reason("").is_none());
assert!(limits.field_switch_block_reason("a").is_none());
}
}

View File

@@ -1,348 +0,0 @@
// src/validation/mask.rs
//! Pure display mask system - user-defined patterns only
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
pub enum MaskDisplayMode {
/// Only show separators as user types
/// Example: "" → "", "123" → "123", "12345" → "(123) 45"
#[default]
Dynamic,
/// Show full template with placeholders from start
/// Example: "" → "(___) ___-____", "123" → "(123) ___-____"
Template {
/// Character to use as placeholder for empty input positions
placeholder: char,
},
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct DisplayMask {
/// Mask pattern like "##-##-####" where # = input position, others are visual separators
pattern: String,
/// Character used to represent input positions (usually '#')
input_char: char,
/// How to display the mask (dynamic vs template)
display_mode: MaskDisplayMode,
}
impl DisplayMask {
/// Create a new display mask with dynamic mode (current behavior)
///
/// # Arguments
/// * `pattern` - The mask pattern (e.g., "##-##-####", "(###) ###-####")
/// * `input_char` - Character representing input positions (usually '#')
///
/// # Examples
/// ```
/// use validation_core::DisplayMask;
///
/// // Phone number format
/// let phone_mask = DisplayMask::new("(###) ###-####", '#');
///
/// // Date format
/// let date_mask = DisplayMask::new("##/##/####", '#');
///
/// // Custom business format
/// let employee_id = DisplayMask::new("EMP-####-##", '#');
/// ```
pub fn new(pattern: impl Into<String>, input_char: char) -> Self {
Self {
pattern: pattern.into(),
input_char,
display_mode: MaskDisplayMode::Dynamic,
}
}
/// Set the display mode for this mask
///
/// # Examples
/// ```
/// use validation_core::{DisplayMask, MaskDisplayMode};
///
/// let dynamic_mask = DisplayMask::new("##-##", '#')
/// .with_mode(MaskDisplayMode::Dynamic);
///
/// let template_mask = DisplayMask::new("##-##", '#')
/// .with_mode(MaskDisplayMode::Template { placeholder: '_' });
/// ```
pub fn with_mode(mut self, mode: MaskDisplayMode) -> Self {
self.display_mode = mode;
self
}
/// Set template mode with custom placeholder
///
/// # Examples
/// ```
/// use validation_core::DisplayMask;
///
/// let phone_template = DisplayMask::new("(###) ###-####", '#')
/// .with_template('_'); // Shows "(___) ___-____" when empty
///
/// let date_dots = DisplayMask::new("##/##/####", '#')
/// .with_template('•'); // Shows "••/••/••••" when empty
/// ```
pub fn with_template(self, placeholder: char) -> Self {
self.with_mode(MaskDisplayMode::Template { placeholder })
}
/// Apply mask to raw input, showing visual separators and handling display mode
pub fn apply_to_display(&self, raw_input: &str) -> String {
match &self.display_mode {
MaskDisplayMode::Dynamic => self.apply_dynamic(raw_input),
MaskDisplayMode::Template { placeholder } => {
self.apply_template(raw_input, *placeholder)
}
}
}
/// Dynamic mode - only show separators as user types
fn apply_dynamic(&self, raw_input: &str) -> String {
if raw_input.is_empty() {
return String::new();
}
let mut result = String::new();
let mut raw_chars = raw_input.chars();
for pattern_char in self.pattern.chars() {
if pattern_char == self.input_char {
// Input position - take from raw input
if let Some(input_char) = raw_chars.next() {
result.push(input_char);
} else {
// No more input - stop here in dynamic mode
break;
}
} else {
// Visual separator - always show
result.push(pattern_char);
}
}
// Append any remaining raw characters that don't fit the pattern
for remaining_char in raw_chars {
result.push(remaining_char);
}
result
}
/// Template mode - show full pattern with placeholders
fn apply_template(&self, raw_input: &str, placeholder: char) -> String {
let mut result = String::new();
let mut raw_chars = raw_input.chars().peekable();
for pattern_char in self.pattern.chars() {
if pattern_char == self.input_char {
// Input position - take from raw input or use placeholder
if let Some(input_char) = raw_chars.next() {
result.push(input_char);
} else {
// No more input - use placeholder to show template
result.push(placeholder);
}
} else {
// Visual separator - always show in template mode
result.push(pattern_char);
}
}
// In template mode, we don't append extra characters beyond the pattern
// This keeps the template consistent
result
}
/// Check if a display position should accept cursor/input
pub fn is_input_position(&self, display_position: usize) -> bool {
self.pattern
.chars()
.nth(display_position)
.map(|c| c == self.input_char)
.unwrap_or(true) // Beyond pattern = accept input
}
/// Map display position to raw position
pub fn display_pos_to_raw_pos(&self, display_pos: usize) -> usize {
let mut raw_pos = 0;
for (i, pattern_char) in self.pattern.chars().enumerate() {
if i >= display_pos {
break;
}
if pattern_char == self.input_char {
raw_pos += 1;
}
}
raw_pos
}
/// Map raw position to display position
pub fn raw_pos_to_display_pos(&self, raw_pos: usize) -> usize {
let mut input_positions_seen = 0;
for (display_pos, pattern_char) in self.pattern.chars().enumerate() {
if pattern_char == self.input_char {
if input_positions_seen == raw_pos {
return display_pos;
}
input_positions_seen += 1;
}
}
// Beyond pattern, return position after pattern
self.pattern.len() + (raw_pos - input_positions_seen)
}
/// Find next input position at or after the given display position
pub fn next_input_position(&self, display_pos: usize) -> usize {
for (i, pattern_char) in self.pattern.chars().enumerate().skip(display_pos) {
if pattern_char == self.input_char {
return i;
}
}
// Beyond pattern = all positions are input positions
display_pos.max(self.pattern.len())
}
/// Find previous input position at or before the given display position
pub fn prev_input_position(&self, display_pos: usize) -> Option<usize> {
// Collect pattern chars with indices first, then search backwards
let pattern_chars: Vec<(usize, char)> = self.pattern.chars().enumerate().collect();
// Search backwards from display_pos
for &(i, pattern_char) in pattern_chars.iter().rev() {
if i <= display_pos && pattern_char == self.input_char {
return Some(i);
}
}
None
}
/// Get the display mode
pub fn display_mode(&self) -> &MaskDisplayMode {
&self.display_mode
}
/// Check if this mask uses template mode
pub fn is_template_mode(&self) -> bool {
matches!(self.display_mode, MaskDisplayMode::Template { .. })
}
/// Get the pattern string
pub fn pattern(&self) -> &str {
&self.pattern
}
/// Get the input placeholder character
pub fn input_char(&self) -> char {
self.input_char
}
/// Get the position of the first input character in the pattern
pub fn first_input_position(&self) -> usize {
for (pos, ch) in self.pattern.chars().enumerate() {
if ch == self.input_char {
return pos;
}
}
0
}
}
impl Default for DisplayMask {
fn default() -> Self {
Self::new("", '#')
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_user_defined_phone_mask() {
// User creates their own phone mask
let dynamic = DisplayMask::new("(###) ###-####", '#');
let template = DisplayMask::new("(###) ###-####", '#').with_template('_');
// Dynamic mode
assert_eq!(dynamic.apply_to_display(""), "");
assert_eq!(dynamic.apply_to_display("1234567890"), "(123) 456-7890");
// Template mode
assert_eq!(template.apply_to_display(""), "(___) ___-____");
assert_eq!(template.apply_to_display("123"), "(123) ___-____");
}
#[test]
fn test_user_defined_date_mask() {
// User creates their own date formats
let us_date = DisplayMask::new("##/##/####", '#');
let eu_date = DisplayMask::new("##.##.####", '#');
let iso_date = DisplayMask::new("####-##-##", '#');
assert_eq!(us_date.apply_to_display("12252024"), "12/25/2024");
assert_eq!(eu_date.apply_to_display("25122024"), "25.12.2024");
assert_eq!(iso_date.apply_to_display("20241225"), "2024-12-25");
}
#[test]
fn test_user_defined_business_formats() {
// User creates custom business formats
let employee_id = DisplayMask::new("EMP-####-##", '#');
let product_code = DisplayMask::new("###-###-###", '#');
let invoice = DisplayMask::new("INV####/##", '#');
assert_eq!(employee_id.apply_to_display("123456"), "EMP-1234-56");
assert_eq!(product_code.apply_to_display("123456789"), "123-456-789");
assert_eq!(invoice.apply_to_display("123456"), "INV1234/56");
}
#[test]
fn test_custom_input_characters() {
// User can define their own input character
let mask_with_x = DisplayMask::new("XXX-XX-XXXX", 'X');
let mask_with_hash = DisplayMask::new("###-##-####", '#');
let mask_with_n = DisplayMask::new("NNN-NN-NNNN", 'N');
assert_eq!(mask_with_x.apply_to_display("123456789"), "123-45-6789");
assert_eq!(mask_with_hash.apply_to_display("123456789"), "123-45-6789");
assert_eq!(mask_with_n.apply_to_display("123456789"), "123-45-6789");
}
#[test]
fn test_custom_placeholders() {
// User can define custom placeholder characters
let underscores = DisplayMask::new("##-##", '#').with_template('_');
let dots = DisplayMask::new("##-##", '#').with_template('•');
let dashes = DisplayMask::new("##-##", '#').with_template('-');
assert_eq!(underscores.apply_to_display(""), "__-__");
assert_eq!(dots.apply_to_display(""), "••-••");
assert_eq!(dashes.apply_to_display(""), "-----"); // Note: dashes blend with separator
}
#[test]
fn test_position_mapping_user_patterns() {
let custom = DisplayMask::new("ABC-###-XYZ", '#');
// Position mapping should work correctly with any pattern
assert_eq!(custom.raw_pos_to_display_pos(0), 4); // First # at position 4
assert_eq!(custom.raw_pos_to_display_pos(1), 5); // Second # at position 5
assert_eq!(custom.raw_pos_to_display_pos(2), 6); // Third # at position 6
assert_eq!(custom.display_pos_to_raw_pos(4), 0); // Position 4 -> first input
assert_eq!(custom.display_pos_to_raw_pos(5), 1); // Position 5 -> second input
assert_eq!(custom.display_pos_to_raw_pos(6), 2); // Position 6 -> third input
assert!(!custom.is_input_position(0)); // A
assert!(!custom.is_input_position(3)); // -
assert!(custom.is_input_position(4)); // #
assert!(!custom.is_input_position(8)); // Y
}
}

View File

@@ -1,7 +0,0 @@
pub mod character_limits;
pub mod display_mask;
pub mod pattern_rules;
pub use character_limits::{count_text, CharacterLimits, CountMode, LimitCheckResult};
pub use display_mask::{DisplayMask, MaskDisplayMode};
pub use pattern_rules::{CharacterFilter, PatternFilters, PositionFilter, PositionRange};

View File

@@ -1,330 +0,0 @@
// src/validation/patterns.rs
//! Position-based pattern filtering for validation
use serde::{Deserialize, Serialize};
use std::sync::Arc;
/// A filter that applies to specific character positions in a field
#[derive(Debug, Clone)]
pub struct PositionFilter {
/// Which positions this filter applies to
pub positions: PositionRange,
/// What type of character filter to apply
pub filter: CharacterFilter,
}
/// Defines which character positions a filter applies to
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum PositionRange {
/// Single position (e.g., position 3 only)
Single(usize),
/// Range of positions (e.g., positions 0-2, inclusive)
Range(usize, usize),
/// From position onwards (e.g., position 4 and beyond)
From(usize),
/// Multiple specific positions (e.g., positions 0, 2, 5)
Multiple(Vec<usize>),
}
/// Types of character filters that can be applied
pub enum CharacterFilter {
/// Allow only alphabetic characters (a-z, A-Z)
Alphabetic,
/// Allow only numeric characters (0-9)
Numeric,
/// Allow alphanumeric characters (a-z, A-Z, 0-9)
Alphanumeric,
/// Allow only exact character match
Exact(char),
/// Allow any character from the provided set
OneOf(Vec<char>),
/// Custom user-defined filter function
Custom(Arc<dyn Fn(char) -> bool + Send + Sync>),
}
// Manual implementations for Debug and Clone
impl std::fmt::Debug for CharacterFilter {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
CharacterFilter::Alphabetic => write!(f, "Alphabetic"),
CharacterFilter::Numeric => write!(f, "Numeric"),
CharacterFilter::Alphanumeric => write!(f, "Alphanumeric"),
CharacterFilter::Exact(ch) => write!(f, "Exact('{ch}')"),
CharacterFilter::OneOf(chars) => write!(f, "OneOf({chars:?})"),
CharacterFilter::Custom(_) => write!(f, "Custom(<function>)"),
}
}
}
impl Clone for CharacterFilter {
fn clone(&self) -> Self {
match self {
CharacterFilter::Alphabetic => CharacterFilter::Alphabetic,
CharacterFilter::Numeric => CharacterFilter::Numeric,
CharacterFilter::Alphanumeric => CharacterFilter::Alphanumeric,
CharacterFilter::Exact(ch) => CharacterFilter::Exact(*ch),
CharacterFilter::OneOf(chars) => CharacterFilter::OneOf(chars.clone()),
CharacterFilter::Custom(func) => CharacterFilter::Custom(Arc::clone(func)),
}
}
}
impl PositionRange {
/// Check if a position is included in this range
pub fn contains(&self, position: usize) -> bool {
match self {
PositionRange::Single(pos) => position == *pos,
PositionRange::Range(start, end) => position >= *start && position <= *end,
PositionRange::From(start) => position >= *start,
PositionRange::Multiple(positions) => positions.contains(&position),
}
}
/// Get all positions up to a given length that this range covers
pub fn positions_up_to(&self, max_length: usize) -> Vec<usize> {
match self {
PositionRange::Single(pos) => {
if *pos < max_length {
vec![*pos]
} else {
vec![]
}
}
PositionRange::Range(start, end) => {
let actual_end = (*end).min(max_length.saturating_sub(1));
if *start <= actual_end {
(*start..=actual_end).collect()
} else {
vec![]
}
}
PositionRange::From(start) => {
if *start < max_length {
(*start..max_length).collect()
} else {
vec![]
}
}
PositionRange::Multiple(positions) => positions
.iter()
.filter(|&&pos| pos < max_length)
.copied()
.collect(),
}
}
}
impl CharacterFilter {
/// Test if a character passes this filter
pub fn accepts(&self, ch: char) -> bool {
match self {
CharacterFilter::Alphabetic => ch.is_alphabetic(),
CharacterFilter::Numeric => ch.is_numeric(),
CharacterFilter::Alphanumeric => ch.is_alphanumeric(),
CharacterFilter::Exact(expected) => ch == *expected,
CharacterFilter::OneOf(chars) => chars.contains(&ch),
CharacterFilter::Custom(func) => func(ch),
}
}
/// Get a human-readable description of this filter
pub fn description(&self) -> String {
match self {
CharacterFilter::Alphabetic => "alphabetic characters (a-z, A-Z)".to_string(),
CharacterFilter::Numeric => "numeric characters (0-9)".to_string(),
CharacterFilter::Alphanumeric => "alphanumeric characters (a-z, A-Z, 0-9)".to_string(),
CharacterFilter::Exact(ch) => format!("exactly '{ch}'"),
CharacterFilter::OneOf(chars) => {
let char_list: String = chars.iter().collect();
format!("one of: {char_list}")
}
CharacterFilter::Custom(_) => "custom filter".to_string(),
}
}
}
impl PositionFilter {
/// Create a new position filter
pub fn new(positions: PositionRange, filter: CharacterFilter) -> Self {
Self { positions, filter }
}
/// Validate a character at a specific position
pub fn validate_position(&self, position: usize, character: char) -> bool {
if self.positions.contains(position) {
self.filter.accepts(character)
} else {
true // Position not covered by this filter, allow any character
}
}
/// Get error message for invalid character at position
pub fn error_message(&self, position: usize, character: char) -> Option<String> {
if self.positions.contains(position) && !self.filter.accepts(character) {
Some(format!(
"Position {} requires {} but got '{}'",
position,
self.filter.description(),
character
))
} else {
None
}
}
}
/// A collection of position filters for a field
#[derive(Debug, Clone, Default)]
pub struct PatternFilters {
filters: Vec<PositionFilter>,
}
impl PatternFilters {
/// Create empty pattern filters
pub fn new() -> Self {
Self::default()
}
/// Add a position filter
pub fn add_filter(mut self, filter: PositionFilter) -> Self {
self.filters.push(filter);
self
}
/// Add multiple filters
pub fn add_filters(mut self, filters: Vec<PositionFilter>) -> Self {
self.filters.extend(filters);
self
}
/// Validate a character at a specific position against all applicable filters
pub fn validate_char_at_position(
&self,
position: usize,
character: char,
) -> Result<(), String> {
for filter in &self.filters {
if let Some(error) = filter.error_message(position, character) {
return Err(error);
}
}
Ok(())
}
/// Validate entire text against all filters
pub fn validate_text(&self, text: &str) -> Result<(), String> {
for (position, character) in text.char_indices() {
self.validate_char_at_position(position, character)?
}
Ok(())
}
/// Check if any filters are configured
pub fn has_filters(&self) -> bool {
!self.filters.is_empty()
}
/// Get all configured filters
pub fn filters(&self) -> &[PositionFilter] {
&self.filters
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_position_range_contains() {
assert!(PositionRange::Single(3).contains(3));
assert!(!PositionRange::Single(3).contains(2));
assert!(PositionRange::Range(1, 4).contains(3));
assert!(!PositionRange::Range(1, 4).contains(5));
assert!(PositionRange::From(2).contains(5));
assert!(!PositionRange::From(2).contains(1));
assert!(PositionRange::Multiple(vec![0, 2, 5]).contains(2));
assert!(!PositionRange::Multiple(vec![0, 2, 5]).contains(3));
}
#[test]
fn test_position_range_positions_up_to() {
assert_eq!(PositionRange::Single(3).positions_up_to(5), vec![3]);
assert_eq!(PositionRange::Single(5).positions_up_to(3), vec![]);
assert_eq!(PositionRange::Range(1, 3).positions_up_to(5), vec![1, 2, 3]);
assert_eq!(PositionRange::Range(1, 5).positions_up_to(3), vec![1, 2]);
assert_eq!(PositionRange::From(2).positions_up_to(5), vec![2, 3, 4]);
assert_eq!(
PositionRange::Multiple(vec![0, 2, 5]).positions_up_to(4),
vec![0, 2]
);
}
#[test]
fn test_character_filter_accepts() {
assert!(CharacterFilter::Alphabetic.accepts('a'));
assert!(CharacterFilter::Alphabetic.accepts('Z'));
assert!(!CharacterFilter::Alphabetic.accepts('1'));
assert!(CharacterFilter::Numeric.accepts('5'));
assert!(!CharacterFilter::Numeric.accepts('a'));
assert!(CharacterFilter::Alphanumeric.accepts('a'));
assert!(CharacterFilter::Alphanumeric.accepts('5'));
assert!(!CharacterFilter::Alphanumeric.accepts('-'));
assert!(CharacterFilter::Exact('x').accepts('x'));
assert!(!CharacterFilter::Exact('x').accepts('y'));
assert!(CharacterFilter::OneOf(vec!['a', 'b', 'c']).accepts('b'));
assert!(!CharacterFilter::OneOf(vec!['a', 'b', 'c']).accepts('d'));
}
#[test]
fn test_position_filter_validation() {
let filter = PositionFilter::new(PositionRange::Range(0, 1), CharacterFilter::Alphabetic);
assert!(filter.validate_position(0, 'A'));
assert!(filter.validate_position(1, 'b'));
assert!(!filter.validate_position(0, '1'));
assert!(filter.validate_position(2, '1')); // Position 2 not covered, allow anything
}
#[test]
fn test_pattern_filters_validation() {
let patterns = PatternFilters::new()
.add_filter(PositionFilter::new(
PositionRange::Range(0, 1),
CharacterFilter::Alphabetic,
))
.add_filter(PositionFilter::new(
PositionRange::Range(2, 4),
CharacterFilter::Numeric,
));
// Valid pattern: AB123
assert!(patterns.validate_text("AB123").is_ok());
// Invalid: number in alphabetic position
assert!(patterns.validate_text("A1123").is_err());
// Invalid: letter in numeric position
assert!(patterns.validate_text("AB1A3").is_err());
}
#[test]
fn test_custom_filter() {
let pattern = PatternFilters::new().add_filter(PositionFilter::new(
PositionRange::From(0),
CharacterFilter::Custom(Arc::new(|c| c.is_lowercase())),
));
assert!(pattern.validate_text("hello").is_ok());
assert!(pattern.validate_text("Hello").is_err()); // Uppercase not allowed
}
}

View File

@@ -1,150 +0,0 @@
use crate::{ValidationConfig, ValidationMergeError, ValidationSettings};
use serde::{Deserialize, Serialize};
use thiserror::Error;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ValidationRule {
pub name: String,
pub description: Option<String>,
pub settings: ValidationSettings,
}
impl ValidationRule {
pub fn resolve(&self) -> ValidationConfig {
self.settings.resolve()
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ValidationSet {
pub name: String,
pub description: Option<String>,
pub items: Vec<ValidationSetItem>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ValidationSetItem {
GlobalRuleRef(String),
InlineRule {
name: Option<String>,
validation: ValidationSettings,
},
}
impl ValidationSet {
pub fn resolve_settings_with_rules<'a>(
&'a self,
rules: impl Fn(&str) -> Option<&'a ValidationRule>,
) -> Result<ValidationSettings, ValidationSetResolveError> {
let settings = self.items.iter().map(|item| match item {
ValidationSetItem::GlobalRuleRef(name) => {
rules(name).map(|rule| &rule.settings).ok_or_else(|| {
ValidationSetResolveError::MissingGlobalRule { name: name.clone() }
})
}
ValidationSetItem::InlineRule { validation, .. } => Ok(validation),
});
let settings = settings.collect::<Result<Vec<_>, _>>()?;
Ok(ValidationSettings::merge_rules(settings)?)
}
pub fn resolve_with_rules<'a>(
&'a self,
rules: impl Fn(&str) -> Option<&'a ValidationRule>,
) -> Result<ValidationConfig, ValidationSetResolveError> {
Ok(self.resolve_settings_with_rules(rules)?.resolve())
}
}
#[derive(Debug, Clone, PartialEq, Eq, Error)]
pub enum ValidationSetResolveError {
#[error("validation set references missing global rule '{name}'")]
MissingGlobalRule { name: String },
#[error(transparent)]
Merge(#[from] ValidationMergeError),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AppliedValidation {
pub set_name: Option<String>,
pub settings: ValidationSettings,
}
impl AppliedValidation {
pub fn resolve(&self) -> ValidationConfig {
self.settings.resolve()
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::{
CharacterFilterSettings, CharacterLimits, PatternSettings, PositionFilterSettings,
PositionRange,
};
#[test]
fn validation_set_merges_rule_fragments() {
let set = ValidationSet {
name: "phone".to_string(),
description: None,
items: vec![
ValidationSetItem::InlineRule {
name: Some("phone-length".to_string()),
validation: ValidationSettings {
character_limits: Some(CharacterLimits::new_range(10, 15)),
..ValidationSettings::default()
},
},
ValidationSetItem::InlineRule {
name: Some("digits-only".to_string()),
validation: ValidationSettings {
pattern: Some(PatternSettings {
filters: vec![PositionFilterSettings {
positions: PositionRange::From(0),
filter: CharacterFilterSettings::Numeric,
}],
description: None,
}),
..ValidationSettings::default()
},
},
],
};
let settings = set
.resolve_settings_with_rules(|_| None)
.expect("set should resolve");
assert!(settings.character_limits.is_some());
assert_eq!(settings.pattern.expect("pattern").filters.len(), 1);
}
#[test]
fn validation_set_rejects_duplicate_singleton_rules() {
let set = ValidationSet {
name: "conflict".to_string(),
description: None,
items: vec![
ValidationSetItem::InlineRule {
name: Some("short".to_string()),
validation: ValidationSettings {
character_limits: Some(CharacterLimits::new(10)),
..ValidationSettings::default()
},
},
ValidationSetItem::InlineRule {
name: Some("long".to_string()),
validation: ValidationSettings {
character_limits: Some(CharacterLimits::new(20)),
..ValidationSettings::default()
},
},
],
};
assert!(set.resolve_settings_with_rules(|_| None).is_err());
}
}