serde of jsonb in grpc
This commit is contained in:
@@ -13,6 +13,8 @@ serde = { version = "1.0.219", features = ["derive"] }
|
||||
|
||||
# Search
|
||||
tantivy = { workspace = true }
|
||||
serde_json.workspace = true
|
||||
|
||||
[build-dependencies]
|
||||
tonic-build = "0.13.0"
|
||||
tonic-build = { version = "0.13.0", features = ["prost-build"] }
|
||||
prost-build = "0.14.1"
|
||||
|
||||
@@ -2,21 +2,57 @@
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
tonic_build::configure()
|
||||
.build_server(true)
|
||||
.out_dir("src/proto")
|
||||
.file_descriptor_set_path("src/proto/descriptor.bin")
|
||||
.compile_protos( // Changed from .compile()
|
||||
.out_dir("src/proto")
|
||||
// Derive serde for all relevant messages
|
||||
.type_attribute(
|
||||
".komp_ac.table_validation.FieldValidation",
|
||||
"#[derive(serde::Serialize, serde::Deserialize)]",
|
||||
)
|
||||
.type_attribute(
|
||||
".komp_ac.table_validation.CharacterLimits",
|
||||
"#[derive(serde::Serialize, serde::Deserialize)]",
|
||||
)
|
||||
.type_attribute(
|
||||
".komp_ac.table_validation.TableValidationResponse",
|
||||
"#[derive(serde::Serialize, serde::Deserialize)]",
|
||||
)
|
||||
.type_attribute(
|
||||
".komp_ac.table_validation.UpdateFieldValidationRequest",
|
||||
"#[derive(serde::Serialize, serde::Deserialize)]",
|
||||
)
|
||||
.type_attribute(
|
||||
".komp_ac.table_validation.UpdateFieldValidationResponse",
|
||||
"#[derive(serde::Serialize, serde::Deserialize)]",
|
||||
)
|
||||
// Derive serde for the enum and keep legacy string values in JSON
|
||||
.type_attribute(
|
||||
".komp_ac.table_validation.CountMode",
|
||||
"#[derive(serde::Serialize, serde::Deserialize)]",
|
||||
)
|
||||
.type_attribute(
|
||||
".komp_ac.table_validation.CountMode",
|
||||
r#"#[serde(rename_all = "SCREAMING_SNAKE_CASE")]"#,
|
||||
)
|
||||
// Back-compat: allow old "character_limits" key to deserialize into "limits"
|
||||
.field_attribute(
|
||||
".komp_ac.table_validation.FieldValidation.limits",
|
||||
r#"#[serde(alias = "character_limits")]"#,
|
||||
)
|
||||
// Compile all protos (same list you already have)
|
||||
.compile_protos(
|
||||
&[
|
||||
"proto/common.proto",
|
||||
"proto/adresar.proto",
|
||||
"proto/auth.proto",
|
||||
"proto/uctovnictvo.proto",
|
||||
"proto/table_structure.proto",
|
||||
"proto/table_definition.proto",
|
||||
"proto/tables_data.proto",
|
||||
"proto/table_script.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",
|
||||
],
|
||||
&["proto"],
|
||||
)?;
|
||||
|
||||
@@ -53,4 +53,19 @@ message CharacterLimits {
|
||||
service TableValidationService {
|
||||
rpc GetTableValidation(GetTableValidationRequest)
|
||||
returns (TableValidationResponse);
|
||||
|
||||
rpc UpdateFieldValidation(UpdateFieldValidationRequest)
|
||||
returns (UpdateFieldValidationResponse);
|
||||
}
|
||||
|
||||
message UpdateFieldValidationRequest {
|
||||
string profile_name = 1;
|
||||
string table_name = 2;
|
||||
string data_key = 3;
|
||||
FieldValidation validation = 4;
|
||||
}
|
||||
|
||||
message UpdateFieldValidationResponse {
|
||||
bool success = 1;
|
||||
string message = 2;
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -9,12 +9,14 @@ pub struct GetTableValidationRequest {
|
||||
}
|
||||
/// Response with field-level validations; if a field is omitted,
|
||||
/// no validation is applied (default unspecified).
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||
pub struct TableValidationResponse {
|
||||
#[prost(message, repeated, tag = "1")]
|
||||
pub fields: ::prost::alloc::vec::Vec<FieldValidation>,
|
||||
}
|
||||
/// Field-level validation (extensible for future kinds)
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||
pub struct FieldValidation {
|
||||
/// MUST match your frontend FormState.data_key for the column
|
||||
@@ -28,9 +30,11 @@ pub struct FieldValidation {
|
||||
/// ExternalValidation external = 13;
|
||||
/// CustomFormatter formatter = 14;
|
||||
#[prost(message, optional, tag = "10")]
|
||||
#[serde(alias = "character_limits")]
|
||||
pub limits: ::core::option::Option<CharacterLimits>,
|
||||
}
|
||||
/// Character limit validation (Validation 1)
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
#[derive(Clone, Copy, PartialEq, ::prost::Message)]
|
||||
pub struct CharacterLimits {
|
||||
/// When zero, the field is considered "not set". If both min/max are zero,
|
||||
@@ -46,7 +50,29 @@ pub struct CharacterLimits {
|
||||
#[prost(enumeration = "CountMode", tag = "4")]
|
||||
pub count_mode: i32,
|
||||
}
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||
pub struct UpdateFieldValidationRequest {
|
||||
#[prost(string, tag = "1")]
|
||||
pub profile_name: ::prost::alloc::string::String,
|
||||
#[prost(string, tag = "2")]
|
||||
pub table_name: ::prost::alloc::string::String,
|
||||
#[prost(string, tag = "3")]
|
||||
pub data_key: ::prost::alloc::string::String,
|
||||
#[prost(message, optional, tag = "4")]
|
||||
pub validation: ::core::option::Option<FieldValidation>,
|
||||
}
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||
pub struct UpdateFieldValidationResponse {
|
||||
#[prost(bool, tag = "1")]
|
||||
pub success: bool,
|
||||
#[prost(string, tag = "2")]
|
||||
pub message: ::prost::alloc::string::String,
|
||||
}
|
||||
/// Character length counting mode
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
|
||||
#[repr(i32)]
|
||||
pub enum CountMode {
|
||||
@@ -203,6 +229,35 @@ pub mod table_validation_service_client {
|
||||
);
|
||||
self.inner.unary(req, path, codec).await
|
||||
}
|
||||
pub async fn update_field_validation(
|
||||
&mut self,
|
||||
request: impl tonic::IntoRequest<super::UpdateFieldValidationRequest>,
|
||||
) -> std::result::Result<
|
||||
tonic::Response<super::UpdateFieldValidationResponse>,
|
||||
tonic::Status,
|
||||
> {
|
||||
self.inner
|
||||
.ready()
|
||||
.await
|
||||
.map_err(|e| {
|
||||
tonic::Status::unknown(
|
||||
format!("Service was not ready: {}", e.into()),
|
||||
)
|
||||
})?;
|
||||
let codec = tonic::codec::ProstCodec::default();
|
||||
let path = http::uri::PathAndQuery::from_static(
|
||||
"/komp_ac.table_validation.TableValidationService/UpdateFieldValidation",
|
||||
);
|
||||
let mut req = request.into_request();
|
||||
req.extensions_mut()
|
||||
.insert(
|
||||
GrpcMethod::new(
|
||||
"komp_ac.table_validation.TableValidationService",
|
||||
"UpdateFieldValidation",
|
||||
),
|
||||
);
|
||||
self.inner.unary(req, path, codec).await
|
||||
}
|
||||
}
|
||||
}
|
||||
/// Generated server implementations.
|
||||
@@ -225,6 +280,13 @@ pub mod table_validation_service_server {
|
||||
tonic::Response<super::TableValidationResponse>,
|
||||
tonic::Status,
|
||||
>;
|
||||
async fn update_field_validation(
|
||||
&self,
|
||||
request: tonic::Request<super::UpdateFieldValidationRequest>,
|
||||
) -> std::result::Result<
|
||||
tonic::Response<super::UpdateFieldValidationResponse>,
|
||||
tonic::Status,
|
||||
>;
|
||||
}
|
||||
/// Service to fetch validations for a table
|
||||
#[derive(Debug)]
|
||||
@@ -353,6 +415,57 @@ pub mod table_validation_service_server {
|
||||
};
|
||||
Box::pin(fut)
|
||||
}
|
||||
"/komp_ac.table_validation.TableValidationService/UpdateFieldValidation" => {
|
||||
#[allow(non_camel_case_types)]
|
||||
struct UpdateFieldValidationSvc<T: TableValidationService>(
|
||||
pub Arc<T>,
|
||||
);
|
||||
impl<
|
||||
T: TableValidationService,
|
||||
> tonic::server::UnaryService<super::UpdateFieldValidationRequest>
|
||||
for UpdateFieldValidationSvc<T> {
|
||||
type Response = super::UpdateFieldValidationResponse;
|
||||
type Future = BoxFuture<
|
||||
tonic::Response<Self::Response>,
|
||||
tonic::Status,
|
||||
>;
|
||||
fn call(
|
||||
&mut self,
|
||||
request: tonic::Request<super::UpdateFieldValidationRequest>,
|
||||
) -> Self::Future {
|
||||
let inner = Arc::clone(&self.0);
|
||||
let fut = async move {
|
||||
<T as TableValidationService>::update_field_validation(
|
||||
&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 = UpdateFieldValidationSvc(inner);
|
||||
let codec = tonic::codec::ProstCodec::default();
|
||||
let mut grpc = tonic::server::Grpc::new(codec)
|
||||
.apply_compression_config(
|
||||
accept_compression_encodings,
|
||||
send_compression_encodings,
|
||||
)
|
||||
.apply_max_message_size_config(
|
||||
max_decoding_message_size,
|
||||
max_encoding_message_size,
|
||||
);
|
||||
let res = grpc.unary(method, req).await;
|
||||
Ok(res)
|
||||
};
|
||||
Box::pin(fut)
|
||||
}
|
||||
_ => {
|
||||
Box::pin(async move {
|
||||
let mut response = http::Response::new(
|
||||
|
||||
Reference in New Issue
Block a user