validation core as a dependency2
This commit is contained in:
@@ -64,6 +64,70 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
".komp_ac.table_validation.ReplaceTableValidationResponse",
|
||||
"#[derive(serde::Serialize, serde::Deserialize)]",
|
||||
)
|
||||
.type_attribute(
|
||||
".komp_ac.table_validation.ValidationRuleDefinition",
|
||||
"#[derive(serde::Serialize, serde::Deserialize)]",
|
||||
)
|
||||
.type_attribute(
|
||||
".komp_ac.table_validation.ValidationSetDefinition",
|
||||
"#[derive(serde::Serialize, serde::Deserialize)]",
|
||||
)
|
||||
.type_attribute(
|
||||
".komp_ac.table_validation.UpsertValidationRuleRequest",
|
||||
"#[derive(serde::Serialize, serde::Deserialize)]",
|
||||
)
|
||||
.type_attribute(
|
||||
".komp_ac.table_validation.UpsertValidationRuleResponse",
|
||||
"#[derive(serde::Serialize, serde::Deserialize)]",
|
||||
)
|
||||
.type_attribute(
|
||||
".komp_ac.table_validation.ListValidationRulesRequest",
|
||||
"#[derive(serde::Serialize, serde::Deserialize)]",
|
||||
)
|
||||
.type_attribute(
|
||||
".komp_ac.table_validation.ListValidationRulesResponse",
|
||||
"#[derive(serde::Serialize, serde::Deserialize)]",
|
||||
)
|
||||
.type_attribute(
|
||||
".komp_ac.table_validation.DeleteValidationRuleRequest",
|
||||
"#[derive(serde::Serialize, serde::Deserialize)]",
|
||||
)
|
||||
.type_attribute(
|
||||
".komp_ac.table_validation.DeleteValidationRuleResponse",
|
||||
"#[derive(serde::Serialize, serde::Deserialize)]",
|
||||
)
|
||||
.type_attribute(
|
||||
".komp_ac.table_validation.UpsertValidationSetRequest",
|
||||
"#[derive(serde::Serialize, serde::Deserialize)]",
|
||||
)
|
||||
.type_attribute(
|
||||
".komp_ac.table_validation.UpsertValidationSetResponse",
|
||||
"#[derive(serde::Serialize, serde::Deserialize)]",
|
||||
)
|
||||
.type_attribute(
|
||||
".komp_ac.table_validation.ListValidationSetsRequest",
|
||||
"#[derive(serde::Serialize, serde::Deserialize)]",
|
||||
)
|
||||
.type_attribute(
|
||||
".komp_ac.table_validation.ListValidationSetsResponse",
|
||||
"#[derive(serde::Serialize, serde::Deserialize)]",
|
||||
)
|
||||
.type_attribute(
|
||||
".komp_ac.table_validation.DeleteValidationSetRequest",
|
||||
"#[derive(serde::Serialize, serde::Deserialize)]",
|
||||
)
|
||||
.type_attribute(
|
||||
".komp_ac.table_validation.DeleteValidationSetResponse",
|
||||
"#[derive(serde::Serialize, serde::Deserialize)]",
|
||||
)
|
||||
.type_attribute(
|
||||
".komp_ac.table_validation.ApplyValidationSetRequest",
|
||||
"#[derive(serde::Serialize, serde::Deserialize)]",
|
||||
)
|
||||
.type_attribute(
|
||||
".komp_ac.table_validation.ApplyValidationSetResponse",
|
||||
"#[derive(serde::Serialize, serde::Deserialize)]",
|
||||
)
|
||||
// Enum -> readable strings in JSON ("BYTES", "DISPLAY_WIDTH")
|
||||
.type_attribute(
|
||||
".komp_ac.table_validation.CountMode",
|
||||
|
||||
@@ -178,6 +178,19 @@ service TableValidationService {
|
||||
|
||||
// Replace the full validation definition set for a table in one transaction.
|
||||
rpc ReplaceTableValidation(ReplaceTableValidationRequest) returns (ReplaceTableValidationResponse);
|
||||
|
||||
// Reusable named rule fragments.
|
||||
rpc UpsertValidationRule(UpsertValidationRuleRequest) returns (UpsertValidationRuleResponse);
|
||||
rpc ListValidationRules(ListValidationRulesRequest) returns (ListValidationRulesResponse);
|
||||
rpc DeleteValidationRule(DeleteValidationRuleRequest) returns (DeleteValidationRuleResponse);
|
||||
|
||||
// Reusable named sets composed from rules.
|
||||
rpc UpsertValidationSet(UpsertValidationSetRequest) returns (UpsertValidationSetResponse);
|
||||
rpc ListValidationSets(ListValidationSetsRequest) returns (ListValidationSetsResponse);
|
||||
rpc DeleteValidationSet(DeleteValidationSetRequest) returns (DeleteValidationSetResponse);
|
||||
|
||||
// Snapshot a reusable set onto a concrete table field.
|
||||
rpc ApplyValidationSet(ApplyValidationSetRequest) returns (ApplyValidationSetResponse);
|
||||
}
|
||||
|
||||
message UpdateFieldValidationRequest {
|
||||
@@ -204,3 +217,89 @@ message ReplaceTableValidationResponse {
|
||||
bool success = 1;
|
||||
string message = 2;
|
||||
}
|
||||
|
||||
message ValidationRuleDefinition {
|
||||
string name = 1;
|
||||
optional string description = 2;
|
||||
|
||||
// Reusable rule fragment. dataKey is ignored by the server for reusable rules.
|
||||
FieldValidation validation = 3;
|
||||
}
|
||||
|
||||
message ValidationSetDefinition {
|
||||
string name = 1;
|
||||
optional string description = 2;
|
||||
repeated string ruleNames = 3;
|
||||
|
||||
// Server-resolved snapshot of all rules in ruleNames order.
|
||||
FieldValidation resolvedValidation = 4;
|
||||
}
|
||||
|
||||
message UpsertValidationRuleRequest {
|
||||
string profileName = 1;
|
||||
ValidationRuleDefinition rule = 2;
|
||||
}
|
||||
|
||||
message UpsertValidationRuleResponse {
|
||||
bool success = 1;
|
||||
string message = 2;
|
||||
}
|
||||
|
||||
message ListValidationRulesRequest {
|
||||
string profileName = 1;
|
||||
}
|
||||
|
||||
message ListValidationRulesResponse {
|
||||
repeated ValidationRuleDefinition rules = 1;
|
||||
}
|
||||
|
||||
message DeleteValidationRuleRequest {
|
||||
string profileName = 1;
|
||||
string name = 2;
|
||||
}
|
||||
|
||||
message DeleteValidationRuleResponse {
|
||||
bool success = 1;
|
||||
string message = 2;
|
||||
}
|
||||
|
||||
message UpsertValidationSetRequest {
|
||||
string profileName = 1;
|
||||
ValidationSetDefinition set = 2;
|
||||
}
|
||||
|
||||
message UpsertValidationSetResponse {
|
||||
bool success = 1;
|
||||
string message = 2;
|
||||
}
|
||||
|
||||
message ListValidationSetsRequest {
|
||||
string profileName = 1;
|
||||
}
|
||||
|
||||
message ListValidationSetsResponse {
|
||||
repeated ValidationSetDefinition sets = 1;
|
||||
}
|
||||
|
||||
message DeleteValidationSetRequest {
|
||||
string profileName = 1;
|
||||
string name = 2;
|
||||
}
|
||||
|
||||
message DeleteValidationSetResponse {
|
||||
bool success = 1;
|
||||
string message = 2;
|
||||
}
|
||||
|
||||
message ApplyValidationSetRequest {
|
||||
string profileName = 1;
|
||||
string tableName = 2;
|
||||
string dataKey = 3;
|
||||
string setName = 4;
|
||||
}
|
||||
|
||||
message ApplyValidationSetResponse {
|
||||
bool success = 1;
|
||||
string message = 2;
|
||||
FieldValidation validation = 3;
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -206,6 +206,140 @@ pub struct ReplaceTableValidationResponse {
|
||||
#[prost(string, tag = "2")]
|
||||
pub message: ::prost::alloc::string::String,
|
||||
}
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||
pub struct ValidationRuleDefinition {
|
||||
#[prost(string, tag = "1")]
|
||||
pub name: ::prost::alloc::string::String,
|
||||
#[prost(string, optional, tag = "2")]
|
||||
pub description: ::core::option::Option<::prost::alloc::string::String>,
|
||||
/// Reusable rule fragment. dataKey is ignored by the server for reusable rules.
|
||||
#[prost(message, optional, tag = "3")]
|
||||
pub validation: ::core::option::Option<FieldValidation>,
|
||||
}
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||
pub struct ValidationSetDefinition {
|
||||
#[prost(string, tag = "1")]
|
||||
pub name: ::prost::alloc::string::String,
|
||||
#[prost(string, optional, tag = "2")]
|
||||
pub description: ::core::option::Option<::prost::alloc::string::String>,
|
||||
#[prost(string, repeated, tag = "3")]
|
||||
pub rule_names: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
|
||||
/// Server-resolved snapshot of all rules in ruleNames order.
|
||||
#[prost(message, optional, tag = "4")]
|
||||
pub resolved_validation: ::core::option::Option<FieldValidation>,
|
||||
}
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||
pub struct UpsertValidationRuleRequest {
|
||||
#[prost(string, tag = "1")]
|
||||
pub profile_name: ::prost::alloc::string::String,
|
||||
#[prost(message, optional, tag = "2")]
|
||||
pub rule: ::core::option::Option<ValidationRuleDefinition>,
|
||||
}
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||
pub struct UpsertValidationRuleResponse {
|
||||
#[prost(bool, tag = "1")]
|
||||
pub success: bool,
|
||||
#[prost(string, tag = "2")]
|
||||
pub message: ::prost::alloc::string::String,
|
||||
}
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||
pub struct ListValidationRulesRequest {
|
||||
#[prost(string, tag = "1")]
|
||||
pub profile_name: ::prost::alloc::string::String,
|
||||
}
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||
pub struct ListValidationRulesResponse {
|
||||
#[prost(message, repeated, tag = "1")]
|
||||
pub rules: ::prost::alloc::vec::Vec<ValidationRuleDefinition>,
|
||||
}
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||
pub struct DeleteValidationRuleRequest {
|
||||
#[prost(string, tag = "1")]
|
||||
pub profile_name: ::prost::alloc::string::String,
|
||||
#[prost(string, tag = "2")]
|
||||
pub name: ::prost::alloc::string::String,
|
||||
}
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||
pub struct DeleteValidationRuleResponse {
|
||||
#[prost(bool, tag = "1")]
|
||||
pub success: bool,
|
||||
#[prost(string, tag = "2")]
|
||||
pub message: ::prost::alloc::string::String,
|
||||
}
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||
pub struct UpsertValidationSetRequest {
|
||||
#[prost(string, tag = "1")]
|
||||
pub profile_name: ::prost::alloc::string::String,
|
||||
#[prost(message, optional, tag = "2")]
|
||||
pub set: ::core::option::Option<ValidationSetDefinition>,
|
||||
}
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||
pub struct UpsertValidationSetResponse {
|
||||
#[prost(bool, tag = "1")]
|
||||
pub success: bool,
|
||||
#[prost(string, tag = "2")]
|
||||
pub message: ::prost::alloc::string::String,
|
||||
}
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||
pub struct ListValidationSetsRequest {
|
||||
#[prost(string, tag = "1")]
|
||||
pub profile_name: ::prost::alloc::string::String,
|
||||
}
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||
pub struct ListValidationSetsResponse {
|
||||
#[prost(message, repeated, tag = "1")]
|
||||
pub sets: ::prost::alloc::vec::Vec<ValidationSetDefinition>,
|
||||
}
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||
pub struct DeleteValidationSetRequest {
|
||||
#[prost(string, tag = "1")]
|
||||
pub profile_name: ::prost::alloc::string::String,
|
||||
#[prost(string, tag = "2")]
|
||||
pub name: ::prost::alloc::string::String,
|
||||
}
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||
pub struct DeleteValidationSetResponse {
|
||||
#[prost(bool, tag = "1")]
|
||||
pub success: bool,
|
||||
#[prost(string, tag = "2")]
|
||||
pub message: ::prost::alloc::string::String,
|
||||
}
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||
pub struct ApplyValidationSetRequest {
|
||||
#[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(string, tag = "4")]
|
||||
pub set_name: ::prost::alloc::string::String,
|
||||
}
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
#[derive(Clone, PartialEq, ::prost::Message)]
|
||||
pub struct ApplyValidationSetResponse {
|
||||
#[prost(bool, tag = "1")]
|
||||
pub success: bool,
|
||||
#[prost(string, tag = "2")]
|
||||
pub message: ::prost::alloc::string::String,
|
||||
#[prost(message, optional, tag = "3")]
|
||||
pub validation: ::core::option::Option<FieldValidation>,
|
||||
}
|
||||
/// Character length counting mode
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
|
||||
@@ -509,6 +643,212 @@ pub mod table_validation_service_client {
|
||||
);
|
||||
self.inner.unary(req, path, codec).await
|
||||
}
|
||||
/// Reusable named rule fragments.
|
||||
pub async fn upsert_validation_rule(
|
||||
&mut self,
|
||||
request: impl tonic::IntoRequest<super::UpsertValidationRuleRequest>,
|
||||
) -> std::result::Result<
|
||||
tonic::Response<super::UpsertValidationRuleResponse>,
|
||||
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/UpsertValidationRule",
|
||||
);
|
||||
let mut req = request.into_request();
|
||||
req.extensions_mut()
|
||||
.insert(
|
||||
GrpcMethod::new(
|
||||
"komp_ac.table_validation.TableValidationService",
|
||||
"UpsertValidationRule",
|
||||
),
|
||||
);
|
||||
self.inner.unary(req, path, codec).await
|
||||
}
|
||||
pub async fn list_validation_rules(
|
||||
&mut self,
|
||||
request: impl tonic::IntoRequest<super::ListValidationRulesRequest>,
|
||||
) -> std::result::Result<
|
||||
tonic::Response<super::ListValidationRulesResponse>,
|
||||
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/ListValidationRules",
|
||||
);
|
||||
let mut req = request.into_request();
|
||||
req.extensions_mut()
|
||||
.insert(
|
||||
GrpcMethod::new(
|
||||
"komp_ac.table_validation.TableValidationService",
|
||||
"ListValidationRules",
|
||||
),
|
||||
);
|
||||
self.inner.unary(req, path, codec).await
|
||||
}
|
||||
pub async fn delete_validation_rule(
|
||||
&mut self,
|
||||
request: impl tonic::IntoRequest<super::DeleteValidationRuleRequest>,
|
||||
) -> std::result::Result<
|
||||
tonic::Response<super::DeleteValidationRuleResponse>,
|
||||
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/DeleteValidationRule",
|
||||
);
|
||||
let mut req = request.into_request();
|
||||
req.extensions_mut()
|
||||
.insert(
|
||||
GrpcMethod::new(
|
||||
"komp_ac.table_validation.TableValidationService",
|
||||
"DeleteValidationRule",
|
||||
),
|
||||
);
|
||||
self.inner.unary(req, path, codec).await
|
||||
}
|
||||
/// Reusable named sets composed from rules.
|
||||
pub async fn upsert_validation_set(
|
||||
&mut self,
|
||||
request: impl tonic::IntoRequest<super::UpsertValidationSetRequest>,
|
||||
) -> std::result::Result<
|
||||
tonic::Response<super::UpsertValidationSetResponse>,
|
||||
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/UpsertValidationSet",
|
||||
);
|
||||
let mut req = request.into_request();
|
||||
req.extensions_mut()
|
||||
.insert(
|
||||
GrpcMethod::new(
|
||||
"komp_ac.table_validation.TableValidationService",
|
||||
"UpsertValidationSet",
|
||||
),
|
||||
);
|
||||
self.inner.unary(req, path, codec).await
|
||||
}
|
||||
pub async fn list_validation_sets(
|
||||
&mut self,
|
||||
request: impl tonic::IntoRequest<super::ListValidationSetsRequest>,
|
||||
) -> std::result::Result<
|
||||
tonic::Response<super::ListValidationSetsResponse>,
|
||||
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/ListValidationSets",
|
||||
);
|
||||
let mut req = request.into_request();
|
||||
req.extensions_mut()
|
||||
.insert(
|
||||
GrpcMethod::new(
|
||||
"komp_ac.table_validation.TableValidationService",
|
||||
"ListValidationSets",
|
||||
),
|
||||
);
|
||||
self.inner.unary(req, path, codec).await
|
||||
}
|
||||
pub async fn delete_validation_set(
|
||||
&mut self,
|
||||
request: impl tonic::IntoRequest<super::DeleteValidationSetRequest>,
|
||||
) -> std::result::Result<
|
||||
tonic::Response<super::DeleteValidationSetResponse>,
|
||||
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/DeleteValidationSet",
|
||||
);
|
||||
let mut req = request.into_request();
|
||||
req.extensions_mut()
|
||||
.insert(
|
||||
GrpcMethod::new(
|
||||
"komp_ac.table_validation.TableValidationService",
|
||||
"DeleteValidationSet",
|
||||
),
|
||||
);
|
||||
self.inner.unary(req, path, codec).await
|
||||
}
|
||||
/// Snapshot a reusable set onto a concrete table field.
|
||||
pub async fn apply_validation_set(
|
||||
&mut self,
|
||||
request: impl tonic::IntoRequest<super::ApplyValidationSetRequest>,
|
||||
) -> std::result::Result<
|
||||
tonic::Response<super::ApplyValidationSetResponse>,
|
||||
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/ApplyValidationSet",
|
||||
);
|
||||
let mut req = request.into_request();
|
||||
req.extensions_mut()
|
||||
.insert(
|
||||
GrpcMethod::new(
|
||||
"komp_ac.table_validation.TableValidationService",
|
||||
"ApplyValidationSet",
|
||||
),
|
||||
);
|
||||
self.inner.unary(req, path, codec).await
|
||||
}
|
||||
}
|
||||
}
|
||||
/// Generated server implementations.
|
||||
@@ -547,6 +887,58 @@ pub mod table_validation_service_server {
|
||||
tonic::Response<super::ReplaceTableValidationResponse>,
|
||||
tonic::Status,
|
||||
>;
|
||||
/// Reusable named rule fragments.
|
||||
async fn upsert_validation_rule(
|
||||
&self,
|
||||
request: tonic::Request<super::UpsertValidationRuleRequest>,
|
||||
) -> std::result::Result<
|
||||
tonic::Response<super::UpsertValidationRuleResponse>,
|
||||
tonic::Status,
|
||||
>;
|
||||
async fn list_validation_rules(
|
||||
&self,
|
||||
request: tonic::Request<super::ListValidationRulesRequest>,
|
||||
) -> std::result::Result<
|
||||
tonic::Response<super::ListValidationRulesResponse>,
|
||||
tonic::Status,
|
||||
>;
|
||||
async fn delete_validation_rule(
|
||||
&self,
|
||||
request: tonic::Request<super::DeleteValidationRuleRequest>,
|
||||
) -> std::result::Result<
|
||||
tonic::Response<super::DeleteValidationRuleResponse>,
|
||||
tonic::Status,
|
||||
>;
|
||||
/// Reusable named sets composed from rules.
|
||||
async fn upsert_validation_set(
|
||||
&self,
|
||||
request: tonic::Request<super::UpsertValidationSetRequest>,
|
||||
) -> std::result::Result<
|
||||
tonic::Response<super::UpsertValidationSetResponse>,
|
||||
tonic::Status,
|
||||
>;
|
||||
async fn list_validation_sets(
|
||||
&self,
|
||||
request: tonic::Request<super::ListValidationSetsRequest>,
|
||||
) -> std::result::Result<
|
||||
tonic::Response<super::ListValidationSetsResponse>,
|
||||
tonic::Status,
|
||||
>;
|
||||
async fn delete_validation_set(
|
||||
&self,
|
||||
request: tonic::Request<super::DeleteValidationSetRequest>,
|
||||
) -> std::result::Result<
|
||||
tonic::Response<super::DeleteValidationSetResponse>,
|
||||
tonic::Status,
|
||||
>;
|
||||
/// Snapshot a reusable set onto a concrete table field.
|
||||
async fn apply_validation_set(
|
||||
&self,
|
||||
request: tonic::Request<super::ApplyValidationSetRequest>,
|
||||
) -> std::result::Result<
|
||||
tonic::Response<super::ApplyValidationSetResponse>,
|
||||
tonic::Status,
|
||||
>;
|
||||
}
|
||||
/// Service for storing and fetching field-validation definitions.
|
||||
#[derive(Debug)]
|
||||
@@ -777,6 +1169,353 @@ pub mod table_validation_service_server {
|
||||
};
|
||||
Box::pin(fut)
|
||||
}
|
||||
"/komp_ac.table_validation.TableValidationService/UpsertValidationRule" => {
|
||||
#[allow(non_camel_case_types)]
|
||||
struct UpsertValidationRuleSvc<T: TableValidationService>(
|
||||
pub Arc<T>,
|
||||
);
|
||||
impl<
|
||||
T: TableValidationService,
|
||||
> tonic::server::UnaryService<super::UpsertValidationRuleRequest>
|
||||
for UpsertValidationRuleSvc<T> {
|
||||
type Response = super::UpsertValidationRuleResponse;
|
||||
type Future = BoxFuture<
|
||||
tonic::Response<Self::Response>,
|
||||
tonic::Status,
|
||||
>;
|
||||
fn call(
|
||||
&mut self,
|
||||
request: tonic::Request<super::UpsertValidationRuleRequest>,
|
||||
) -> Self::Future {
|
||||
let inner = Arc::clone(&self.0);
|
||||
let fut = async move {
|
||||
<T as TableValidationService>::upsert_validation_rule(
|
||||
&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 = UpsertValidationRuleSvc(inner);
|
||||
let codec = tonic::codec::ProstCodec::default();
|
||||
let mut grpc = tonic::server::Grpc::new(codec)
|
||||
.apply_compression_config(
|
||||
accept_compression_encodings,
|
||||
send_compression_encodings,
|
||||
)
|
||||
.apply_max_message_size_config(
|
||||
max_decoding_message_size,
|
||||
max_encoding_message_size,
|
||||
);
|
||||
let res = grpc.unary(method, req).await;
|
||||
Ok(res)
|
||||
};
|
||||
Box::pin(fut)
|
||||
}
|
||||
"/komp_ac.table_validation.TableValidationService/ListValidationRules" => {
|
||||
#[allow(non_camel_case_types)]
|
||||
struct ListValidationRulesSvc<T: TableValidationService>(pub Arc<T>);
|
||||
impl<
|
||||
T: TableValidationService,
|
||||
> tonic::server::UnaryService<super::ListValidationRulesRequest>
|
||||
for ListValidationRulesSvc<T> {
|
||||
type Response = super::ListValidationRulesResponse;
|
||||
type Future = BoxFuture<
|
||||
tonic::Response<Self::Response>,
|
||||
tonic::Status,
|
||||
>;
|
||||
fn call(
|
||||
&mut self,
|
||||
request: tonic::Request<super::ListValidationRulesRequest>,
|
||||
) -> Self::Future {
|
||||
let inner = Arc::clone(&self.0);
|
||||
let fut = async move {
|
||||
<T as TableValidationService>::list_validation_rules(
|
||||
&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 = ListValidationRulesSvc(inner);
|
||||
let codec = tonic::codec::ProstCodec::default();
|
||||
let mut grpc = tonic::server::Grpc::new(codec)
|
||||
.apply_compression_config(
|
||||
accept_compression_encodings,
|
||||
send_compression_encodings,
|
||||
)
|
||||
.apply_max_message_size_config(
|
||||
max_decoding_message_size,
|
||||
max_encoding_message_size,
|
||||
);
|
||||
let res = grpc.unary(method, req).await;
|
||||
Ok(res)
|
||||
};
|
||||
Box::pin(fut)
|
||||
}
|
||||
"/komp_ac.table_validation.TableValidationService/DeleteValidationRule" => {
|
||||
#[allow(non_camel_case_types)]
|
||||
struct DeleteValidationRuleSvc<T: TableValidationService>(
|
||||
pub Arc<T>,
|
||||
);
|
||||
impl<
|
||||
T: TableValidationService,
|
||||
> tonic::server::UnaryService<super::DeleteValidationRuleRequest>
|
||||
for DeleteValidationRuleSvc<T> {
|
||||
type Response = super::DeleteValidationRuleResponse;
|
||||
type Future = BoxFuture<
|
||||
tonic::Response<Self::Response>,
|
||||
tonic::Status,
|
||||
>;
|
||||
fn call(
|
||||
&mut self,
|
||||
request: tonic::Request<super::DeleteValidationRuleRequest>,
|
||||
) -> Self::Future {
|
||||
let inner = Arc::clone(&self.0);
|
||||
let fut = async move {
|
||||
<T as TableValidationService>::delete_validation_rule(
|
||||
&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 = DeleteValidationRuleSvc(inner);
|
||||
let codec = tonic::codec::ProstCodec::default();
|
||||
let mut grpc = tonic::server::Grpc::new(codec)
|
||||
.apply_compression_config(
|
||||
accept_compression_encodings,
|
||||
send_compression_encodings,
|
||||
)
|
||||
.apply_max_message_size_config(
|
||||
max_decoding_message_size,
|
||||
max_encoding_message_size,
|
||||
);
|
||||
let res = grpc.unary(method, req).await;
|
||||
Ok(res)
|
||||
};
|
||||
Box::pin(fut)
|
||||
}
|
||||
"/komp_ac.table_validation.TableValidationService/UpsertValidationSet" => {
|
||||
#[allow(non_camel_case_types)]
|
||||
struct UpsertValidationSetSvc<T: TableValidationService>(pub Arc<T>);
|
||||
impl<
|
||||
T: TableValidationService,
|
||||
> tonic::server::UnaryService<super::UpsertValidationSetRequest>
|
||||
for UpsertValidationSetSvc<T> {
|
||||
type Response = super::UpsertValidationSetResponse;
|
||||
type Future = BoxFuture<
|
||||
tonic::Response<Self::Response>,
|
||||
tonic::Status,
|
||||
>;
|
||||
fn call(
|
||||
&mut self,
|
||||
request: tonic::Request<super::UpsertValidationSetRequest>,
|
||||
) -> Self::Future {
|
||||
let inner = Arc::clone(&self.0);
|
||||
let fut = async move {
|
||||
<T as TableValidationService>::upsert_validation_set(
|
||||
&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 = UpsertValidationSetSvc(inner);
|
||||
let codec = tonic::codec::ProstCodec::default();
|
||||
let mut grpc = tonic::server::Grpc::new(codec)
|
||||
.apply_compression_config(
|
||||
accept_compression_encodings,
|
||||
send_compression_encodings,
|
||||
)
|
||||
.apply_max_message_size_config(
|
||||
max_decoding_message_size,
|
||||
max_encoding_message_size,
|
||||
);
|
||||
let res = grpc.unary(method, req).await;
|
||||
Ok(res)
|
||||
};
|
||||
Box::pin(fut)
|
||||
}
|
||||
"/komp_ac.table_validation.TableValidationService/ListValidationSets" => {
|
||||
#[allow(non_camel_case_types)]
|
||||
struct ListValidationSetsSvc<T: TableValidationService>(pub Arc<T>);
|
||||
impl<
|
||||
T: TableValidationService,
|
||||
> tonic::server::UnaryService<super::ListValidationSetsRequest>
|
||||
for ListValidationSetsSvc<T> {
|
||||
type Response = super::ListValidationSetsResponse;
|
||||
type Future = BoxFuture<
|
||||
tonic::Response<Self::Response>,
|
||||
tonic::Status,
|
||||
>;
|
||||
fn call(
|
||||
&mut self,
|
||||
request: tonic::Request<super::ListValidationSetsRequest>,
|
||||
) -> Self::Future {
|
||||
let inner = Arc::clone(&self.0);
|
||||
let fut = async move {
|
||||
<T as TableValidationService>::list_validation_sets(
|
||||
&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 = ListValidationSetsSvc(inner);
|
||||
let codec = tonic::codec::ProstCodec::default();
|
||||
let mut grpc = tonic::server::Grpc::new(codec)
|
||||
.apply_compression_config(
|
||||
accept_compression_encodings,
|
||||
send_compression_encodings,
|
||||
)
|
||||
.apply_max_message_size_config(
|
||||
max_decoding_message_size,
|
||||
max_encoding_message_size,
|
||||
);
|
||||
let res = grpc.unary(method, req).await;
|
||||
Ok(res)
|
||||
};
|
||||
Box::pin(fut)
|
||||
}
|
||||
"/komp_ac.table_validation.TableValidationService/DeleteValidationSet" => {
|
||||
#[allow(non_camel_case_types)]
|
||||
struct DeleteValidationSetSvc<T: TableValidationService>(pub Arc<T>);
|
||||
impl<
|
||||
T: TableValidationService,
|
||||
> tonic::server::UnaryService<super::DeleteValidationSetRequest>
|
||||
for DeleteValidationSetSvc<T> {
|
||||
type Response = super::DeleteValidationSetResponse;
|
||||
type Future = BoxFuture<
|
||||
tonic::Response<Self::Response>,
|
||||
tonic::Status,
|
||||
>;
|
||||
fn call(
|
||||
&mut self,
|
||||
request: tonic::Request<super::DeleteValidationSetRequest>,
|
||||
) -> Self::Future {
|
||||
let inner = Arc::clone(&self.0);
|
||||
let fut = async move {
|
||||
<T as TableValidationService>::delete_validation_set(
|
||||
&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 = DeleteValidationSetSvc(inner);
|
||||
let codec = tonic::codec::ProstCodec::default();
|
||||
let mut grpc = tonic::server::Grpc::new(codec)
|
||||
.apply_compression_config(
|
||||
accept_compression_encodings,
|
||||
send_compression_encodings,
|
||||
)
|
||||
.apply_max_message_size_config(
|
||||
max_decoding_message_size,
|
||||
max_encoding_message_size,
|
||||
);
|
||||
let res = grpc.unary(method, req).await;
|
||||
Ok(res)
|
||||
};
|
||||
Box::pin(fut)
|
||||
}
|
||||
"/komp_ac.table_validation.TableValidationService/ApplyValidationSet" => {
|
||||
#[allow(non_camel_case_types)]
|
||||
struct ApplyValidationSetSvc<T: TableValidationService>(pub Arc<T>);
|
||||
impl<
|
||||
T: TableValidationService,
|
||||
> tonic::server::UnaryService<super::ApplyValidationSetRequest>
|
||||
for ApplyValidationSetSvc<T> {
|
||||
type Response = super::ApplyValidationSetResponse;
|
||||
type Future = BoxFuture<
|
||||
tonic::Response<Self::Response>,
|
||||
tonic::Status,
|
||||
>;
|
||||
fn call(
|
||||
&mut self,
|
||||
request: tonic::Request<super::ApplyValidationSetRequest>,
|
||||
) -> Self::Future {
|
||||
let inner = Arc::clone(&self.0);
|
||||
let fut = async move {
|
||||
<T as TableValidationService>::apply_validation_set(
|
||||
&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 = ApplyValidationSetSvc(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(
|
||||
|
||||
2
server
2
server
Submodule server updated: f828b7688a...93ceaf4267
@@ -4,7 +4,7 @@ version.workspace = true
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
authors.workspace = true
|
||||
description = "Shared validation primitives, recipes, and package metadata."
|
||||
description = "Shared validation primitives, rules, and sets."
|
||||
repository.workspace = true
|
||||
|
||||
[dependencies]
|
||||
|
||||
@@ -5,7 +5,7 @@ Validation is split into three ownership layers.
|
||||
```mermaid
|
||||
flowchart LR
|
||||
Server[server<br/>stores simple settings<br/>binds table fields<br/>enforces writes]
|
||||
Core[validation-core<br/>owns meaning<br/>resolves recipes<br/>runs pure validation]
|
||||
Core[validation-core<br/>owns meaning<br/>resolves sets<br/>runs pure validation]
|
||||
Canvas[canvas<br/>editor integration<br/>masking while typing<br/>UI feedback]
|
||||
Common[common/proto<br/>wire format]
|
||||
|
||||
@@ -23,13 +23,14 @@ settings mean. `canvas` uses the resolved result for editing behavior.
|
||||
```mermaid
|
||||
flowchart TD
|
||||
Settings[ValidationSettings<br/>serializable data]
|
||||
Recipe[ValidationRecipe<br/>named reusable settings]
|
||||
Package[ValidationPackage<br/>distributable recipes]
|
||||
Rule[ValidationRule<br/>named reusable fragment]
|
||||
Set[ValidationSet<br/>ordered rules]
|
||||
Config[ValidationConfig<br/>resolved runtime config]
|
||||
Result[ValidationResult]
|
||||
|
||||
Package --> Recipe
|
||||
Recipe --> Settings
|
||||
Rule --> Settings
|
||||
Set --> Rule
|
||||
Set --> Settings
|
||||
Settings --> Config
|
||||
Config --> Result
|
||||
```
|
||||
@@ -50,30 +51,32 @@ sequenceDiagram
|
||||
Client->>Client: canvas editing, masks, errors
|
||||
```
|
||||
|
||||
## Future Package Flow
|
||||
## Set Flow
|
||||
|
||||
```mermaid
|
||||
flowchart LR
|
||||
Registry[validation package registry]
|
||||
Package[phone package]
|
||||
Recipe[phone.e164 recipe]
|
||||
RuleA[digits-only rule]
|
||||
RuleB[phone-length rule]
|
||||
RuleC[phone-mask rule]
|
||||
Set[phone set]
|
||||
Assignment[column assignment]
|
||||
Stored[server stored settings<br/>recipe ref + resolved config]
|
||||
Stored[server stored settings<br/>set name + resolved config]
|
||||
Runtime[server/canvas runtime]
|
||||
|
||||
Registry --> Package
|
||||
Package --> Recipe
|
||||
Recipe --> Assignment
|
||||
RuleA --> Set
|
||||
RuleB --> Set
|
||||
RuleC --> Set
|
||||
Set --> Assignment
|
||||
Assignment --> Stored
|
||||
Stored --> Runtime
|
||||
```
|
||||
|
||||
The server may store both the recipe reference and the resolved settings:
|
||||
The server stores reusable rules and sets, and field application stores a
|
||||
resolved snapshot:
|
||||
|
||||
```text
|
||||
field customer_phone uses phone.e164@1.0.0
|
||||
field customer_phone uses set phone
|
||||
resolved settings = {...}
|
||||
```
|
||||
|
||||
That keeps package imports inspectable and versioned while preserving stable
|
||||
backend enforcement even if a package changes later.
|
||||
That keeps backend enforcement stable even if the reusable set changes later.
|
||||
|
||||
@@ -2,6 +2,8 @@ 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 {
|
||||
@@ -60,6 +62,7 @@ pub enum CharacterFilterSettings {
|
||||
Alphanumeric,
|
||||
Exact(char),
|
||||
OneOf(Vec<char>),
|
||||
Regex(String),
|
||||
}
|
||||
|
||||
impl CharacterFilterSettings {
|
||||
@@ -70,6 +73,22 @@ impl CharacterFilterSettings {
|
||||
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))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -126,6 +145,68 @@ impl ValidationSettings {
|
||||
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)]
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
pub mod config;
|
||||
pub mod recipe;
|
||||
pub mod rules;
|
||||
pub mod set;
|
||||
|
||||
pub use config::{
|
||||
AllowedValues, CharacterFilterSettings, FormatterOption, FormatterSettings, PatternSettings,
|
||||
PositionFilterSettings, ValidationConfig, ValidationResult, ValidationSettings,
|
||||
};
|
||||
pub use recipe::{
|
||||
AppliedValidation, PackageId, PackageRequirement, RecipeId, RecipeReference,
|
||||
ValidationPackage, ValidationRecipe,
|
||||
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};
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
use crate::{ValidationConfig, ValidationSettings};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
pub struct PackageId(pub String);
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
pub struct RecipeId(pub String);
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct ValidationRecipe {
|
||||
pub id: RecipeId,
|
||||
pub name: String,
|
||||
pub description: Option<String>,
|
||||
pub settings: ValidationSettings,
|
||||
}
|
||||
|
||||
impl ValidationRecipe {
|
||||
pub fn resolve(&self) -> ValidationConfig {
|
||||
self.settings.resolve()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct ValidationPackage {
|
||||
pub id: PackageId,
|
||||
pub name: String,
|
||||
pub version: String,
|
||||
pub description: Option<String>,
|
||||
pub recipes: Vec<ValidationRecipe>,
|
||||
pub dependencies: Vec<PackageRequirement>,
|
||||
}
|
||||
|
||||
impl ValidationPackage {
|
||||
pub fn recipe(&self, id: &RecipeId) -> Option<&ValidationRecipe> {
|
||||
self.recipes.iter().find(|recipe| &recipe.id == id)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct PackageRequirement {
|
||||
pub package_id: PackageId,
|
||||
pub version_requirement: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct RecipeReference {
|
||||
pub package_id: PackageId,
|
||||
pub recipe_id: RecipeId,
|
||||
pub version: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct AppliedValidation {
|
||||
pub source: Option<RecipeReference>,
|
||||
pub settings: ValidationSettings,
|
||||
}
|
||||
|
||||
impl AppliedValidation {
|
||||
pub fn resolve(&self) -> ValidationConfig {
|
||||
self.settings.resolve()
|
||||
}
|
||||
}
|
||||
@@ -73,6 +73,26 @@ impl CharacterLimits {
|
||||
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 {
|
||||
|
||||
@@ -237,6 +237,11 @@ impl DisplayMask {
|
||||
&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() {
|
||||
|
||||
118
validation-core/src/set.rs
Normal file
118
validation-core/src/set.rs
Normal file
@@ -0,0 +1,118 @@
|
||||
use crate::{ValidationConfig, ValidationMergeError, ValidationSettings};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[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 rules: Vec<ValidationRule>,
|
||||
}
|
||||
|
||||
impl ValidationSet {
|
||||
pub fn resolve_settings(&self) -> Result<ValidationSettings, ValidationMergeError> {
|
||||
ValidationSettings::merge_rules(self.rules.iter().map(|rule| &rule.settings))
|
||||
}
|
||||
|
||||
pub fn resolve(&self) -> Result<ValidationConfig, ValidationMergeError> {
|
||||
Ok(self.resolve_settings()?.resolve())
|
||||
}
|
||||
}
|
||||
|
||||
#[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,
|
||||
rules: vec![
|
||||
ValidationRule {
|
||||
name: "phone-length".to_string(),
|
||||
description: None,
|
||||
settings: ValidationSettings {
|
||||
character_limits: Some(CharacterLimits::new_range(10, 15)),
|
||||
..ValidationSettings::default()
|
||||
},
|
||||
},
|
||||
ValidationRule {
|
||||
name: "digits-only".to_string(),
|
||||
description: None,
|
||||
settings: ValidationSettings {
|
||||
pattern: Some(PatternSettings {
|
||||
filters: vec![PositionFilterSettings {
|
||||
positions: PositionRange::From(0),
|
||||
filter: CharacterFilterSettings::Numeric,
|
||||
}],
|
||||
description: None,
|
||||
}),
|
||||
..ValidationSettings::default()
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
let settings = set.resolve_settings().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,
|
||||
rules: vec![
|
||||
ValidationRule {
|
||||
name: "short".to_string(),
|
||||
description: None,
|
||||
settings: ValidationSettings {
|
||||
character_limits: Some(CharacterLimits::new(10)),
|
||||
..ValidationSettings::default()
|
||||
},
|
||||
},
|
||||
ValidationRule {
|
||||
name: "long".to_string(),
|
||||
description: None,
|
||||
settings: ValidationSettings {
|
||||
character_limits: Some(CharacterLimits::new(20)),
|
||||
..ValidationSettings::default()
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
assert!(set.resolve_settings().is_err());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user