mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 17:19:15 +08:00
refactor(hyperswitch_constraint_graph): Removal of lifetime from the Constraint Graph framework (#5132)
This commit is contained in:
@ -207,7 +207,7 @@ fn perform_condition_analyses(
|
|||||||
|
|
||||||
fn perform_context_analyses(
|
fn perform_context_analyses(
|
||||||
context: &types::ConjunctiveContext<'_>,
|
context: &types::ConjunctiveContext<'_>,
|
||||||
knowledge_graph: &ConstraintGraph<'_, dir::DirValue>,
|
knowledge_graph: &ConstraintGraph<dir::DirValue>,
|
||||||
) -> Result<(), types::AnalysisError> {
|
) -> Result<(), types::AnalysisError> {
|
||||||
perform_condition_analyses(context)?;
|
perform_condition_analyses(context)?;
|
||||||
let mut memo = Memoization::new();
|
let mut memo = Memoization::new();
|
||||||
@ -222,7 +222,7 @@ fn perform_context_analyses(
|
|||||||
|
|
||||||
pub fn analyze<O: EuclidAnalysable + EuclidDirFilter>(
|
pub fn analyze<O: EuclidAnalysable + EuclidDirFilter>(
|
||||||
program: ast::Program<O>,
|
program: ast::Program<O>,
|
||||||
knowledge_graph: Option<&ConstraintGraph<'_, dir::DirValue>>,
|
knowledge_graph: Option<&ConstraintGraph<dir::DirValue>>,
|
||||||
) -> Result<vir::ValuedProgram<O>, types::AnalysisError> {
|
) -> Result<vir::ValuedProgram<O>, types::AnalysisError> {
|
||||||
let dir_program = ast::lowering::lower_program(program)?;
|
let dir_program = ast::lowering::lower_program(program)?;
|
||||||
|
|
||||||
|
|||||||
@ -221,7 +221,7 @@ pub trait CgraphExt {
|
|||||||
ctx: &AnalysisContext,
|
ctx: &AnalysisContext,
|
||||||
memo: &mut cgraph::Memoization<dir::DirValue>,
|
memo: &mut cgraph::Memoization<dir::DirValue>,
|
||||||
cycle_map: &mut cgraph::CycleCheck,
|
cycle_map: &mut cgraph::CycleCheck,
|
||||||
domains: Option<&[&str]>,
|
domains: Option<&[String]>,
|
||||||
) -> Result<(), cgraph::GraphError<dir::DirValue>>;
|
) -> Result<(), cgraph::GraphError<dir::DirValue>>;
|
||||||
|
|
||||||
fn value_analysis(
|
fn value_analysis(
|
||||||
@ -230,7 +230,7 @@ pub trait CgraphExt {
|
|||||||
ctx: &AnalysisContext,
|
ctx: &AnalysisContext,
|
||||||
memo: &mut cgraph::Memoization<dir::DirValue>,
|
memo: &mut cgraph::Memoization<dir::DirValue>,
|
||||||
cycle_map: &mut cgraph::CycleCheck,
|
cycle_map: &mut cgraph::CycleCheck,
|
||||||
domains: Option<&[&str]>,
|
domains: Option<&[String]>,
|
||||||
) -> Result<(), cgraph::GraphError<dir::DirValue>>;
|
) -> Result<(), cgraph::GraphError<dir::DirValue>>;
|
||||||
|
|
||||||
fn check_value_validity(
|
fn check_value_validity(
|
||||||
@ -239,7 +239,7 @@ pub trait CgraphExt {
|
|||||||
analysis_ctx: &AnalysisContext,
|
analysis_ctx: &AnalysisContext,
|
||||||
memo: &mut cgraph::Memoization<dir::DirValue>,
|
memo: &mut cgraph::Memoization<dir::DirValue>,
|
||||||
cycle_map: &mut cgraph::CycleCheck,
|
cycle_map: &mut cgraph::CycleCheck,
|
||||||
domains: Option<&[&str]>,
|
domains: Option<&[String]>,
|
||||||
) -> Result<bool, cgraph::GraphError<dir::DirValue>>;
|
) -> Result<bool, cgraph::GraphError<dir::DirValue>>;
|
||||||
|
|
||||||
fn key_value_analysis(
|
fn key_value_analysis(
|
||||||
@ -248,7 +248,7 @@ pub trait CgraphExt {
|
|||||||
ctx: &AnalysisContext,
|
ctx: &AnalysisContext,
|
||||||
memo: &mut cgraph::Memoization<dir::DirValue>,
|
memo: &mut cgraph::Memoization<dir::DirValue>,
|
||||||
cycle_map: &mut cgraph::CycleCheck,
|
cycle_map: &mut cgraph::CycleCheck,
|
||||||
domains: Option<&[&str]>,
|
domains: Option<&[String]>,
|
||||||
) -> Result<(), cgraph::GraphError<dir::DirValue>>;
|
) -> Result<(), cgraph::GraphError<dir::DirValue>>;
|
||||||
|
|
||||||
fn assertion_analysis(
|
fn assertion_analysis(
|
||||||
@ -257,7 +257,7 @@ pub trait CgraphExt {
|
|||||||
analysis_ctx: &AnalysisContext,
|
analysis_ctx: &AnalysisContext,
|
||||||
memo: &mut cgraph::Memoization<dir::DirValue>,
|
memo: &mut cgraph::Memoization<dir::DirValue>,
|
||||||
cycle_map: &mut cgraph::CycleCheck,
|
cycle_map: &mut cgraph::CycleCheck,
|
||||||
domains: Option<&[&str]>,
|
domains: Option<&[String]>,
|
||||||
) -> Result<(), AnalysisError<dir::DirValue>>;
|
) -> Result<(), AnalysisError<dir::DirValue>>;
|
||||||
|
|
||||||
fn negation_analysis(
|
fn negation_analysis(
|
||||||
@ -266,25 +266,25 @@ pub trait CgraphExt {
|
|||||||
analysis_ctx: &mut AnalysisContext,
|
analysis_ctx: &mut AnalysisContext,
|
||||||
memo: &mut cgraph::Memoization<dir::DirValue>,
|
memo: &mut cgraph::Memoization<dir::DirValue>,
|
||||||
cycle_map: &mut cgraph::CycleCheck,
|
cycle_map: &mut cgraph::CycleCheck,
|
||||||
domains: Option<&[&str]>,
|
domains: Option<&[String]>,
|
||||||
) -> Result<(), AnalysisError<dir::DirValue>>;
|
) -> Result<(), AnalysisError<dir::DirValue>>;
|
||||||
|
|
||||||
fn perform_context_analysis(
|
fn perform_context_analysis(
|
||||||
&self,
|
&self,
|
||||||
ctx: &types::ConjunctiveContext<'_>,
|
ctx: &types::ConjunctiveContext<'_>,
|
||||||
memo: &mut cgraph::Memoization<dir::DirValue>,
|
memo: &mut cgraph::Memoization<dir::DirValue>,
|
||||||
domains: Option<&[&str]>,
|
domains: Option<&[String]>,
|
||||||
) -> Result<(), AnalysisError<dir::DirValue>>;
|
) -> Result<(), AnalysisError<dir::DirValue>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CgraphExt for cgraph::ConstraintGraph<'_, dir::DirValue> {
|
impl CgraphExt for cgraph::ConstraintGraph<dir::DirValue> {
|
||||||
fn key_analysis(
|
fn key_analysis(
|
||||||
&self,
|
&self,
|
||||||
key: dir::DirKey,
|
key: dir::DirKey,
|
||||||
ctx: &AnalysisContext,
|
ctx: &AnalysisContext,
|
||||||
memo: &mut cgraph::Memoization<dir::DirValue>,
|
memo: &mut cgraph::Memoization<dir::DirValue>,
|
||||||
cycle_map: &mut cgraph::CycleCheck,
|
cycle_map: &mut cgraph::CycleCheck,
|
||||||
domains: Option<&[&str]>,
|
domains: Option<&[String]>,
|
||||||
) -> Result<(), cgraph::GraphError<dir::DirValue>> {
|
) -> Result<(), cgraph::GraphError<dir::DirValue>> {
|
||||||
self.value_map
|
self.value_map
|
||||||
.get(&cgraph::NodeValue::Key(key))
|
.get(&cgraph::NodeValue::Key(key))
|
||||||
@ -307,7 +307,7 @@ impl CgraphExt for cgraph::ConstraintGraph<'_, dir::DirValue> {
|
|||||||
ctx: &AnalysisContext,
|
ctx: &AnalysisContext,
|
||||||
memo: &mut cgraph::Memoization<dir::DirValue>,
|
memo: &mut cgraph::Memoization<dir::DirValue>,
|
||||||
cycle_map: &mut cgraph::CycleCheck,
|
cycle_map: &mut cgraph::CycleCheck,
|
||||||
domains: Option<&[&str]>,
|
domains: Option<&[String]>,
|
||||||
) -> Result<(), cgraph::GraphError<dir::DirValue>> {
|
) -> Result<(), cgraph::GraphError<dir::DirValue>> {
|
||||||
self.value_map
|
self.value_map
|
||||||
.get(&cgraph::NodeValue::Value(val))
|
.get(&cgraph::NodeValue::Value(val))
|
||||||
@ -330,7 +330,7 @@ impl CgraphExt for cgraph::ConstraintGraph<'_, dir::DirValue> {
|
|||||||
analysis_ctx: &AnalysisContext,
|
analysis_ctx: &AnalysisContext,
|
||||||
memo: &mut cgraph::Memoization<dir::DirValue>,
|
memo: &mut cgraph::Memoization<dir::DirValue>,
|
||||||
cycle_map: &mut cgraph::CycleCheck,
|
cycle_map: &mut cgraph::CycleCheck,
|
||||||
domains: Option<&[&str]>,
|
domains: Option<&[String]>,
|
||||||
) -> Result<bool, cgraph::GraphError<dir::DirValue>> {
|
) -> Result<bool, cgraph::GraphError<dir::DirValue>> {
|
||||||
let maybe_node_id = self.value_map.get(&cgraph::NodeValue::Value(val));
|
let maybe_node_id = self.value_map.get(&cgraph::NodeValue::Value(val));
|
||||||
|
|
||||||
@ -365,7 +365,7 @@ impl CgraphExt for cgraph::ConstraintGraph<'_, dir::DirValue> {
|
|||||||
ctx: &AnalysisContext,
|
ctx: &AnalysisContext,
|
||||||
memo: &mut cgraph::Memoization<dir::DirValue>,
|
memo: &mut cgraph::Memoization<dir::DirValue>,
|
||||||
cycle_map: &mut cgraph::CycleCheck,
|
cycle_map: &mut cgraph::CycleCheck,
|
||||||
domains: Option<&[&str]>,
|
domains: Option<&[String]>,
|
||||||
) -> Result<(), cgraph::GraphError<dir::DirValue>> {
|
) -> Result<(), cgraph::GraphError<dir::DirValue>> {
|
||||||
self.key_analysis(val.get_key(), ctx, memo, cycle_map, domains)
|
self.key_analysis(val.get_key(), ctx, memo, cycle_map, domains)
|
||||||
.and_then(|_| self.value_analysis(val, ctx, memo, cycle_map, domains))
|
.and_then(|_| self.value_analysis(val, ctx, memo, cycle_map, domains))
|
||||||
@ -377,7 +377,7 @@ impl CgraphExt for cgraph::ConstraintGraph<'_, dir::DirValue> {
|
|||||||
analysis_ctx: &AnalysisContext,
|
analysis_ctx: &AnalysisContext,
|
||||||
memo: &mut cgraph::Memoization<dir::DirValue>,
|
memo: &mut cgraph::Memoization<dir::DirValue>,
|
||||||
cycle_map: &mut cgraph::CycleCheck,
|
cycle_map: &mut cgraph::CycleCheck,
|
||||||
domains: Option<&[&str]>,
|
domains: Option<&[String]>,
|
||||||
) -> Result<(), AnalysisError<dir::DirValue>> {
|
) -> Result<(), AnalysisError<dir::DirValue>> {
|
||||||
positive_ctx.iter().try_for_each(|(value, metadata)| {
|
positive_ctx.iter().try_for_each(|(value, metadata)| {
|
||||||
self.key_value_analysis((*value).clone(), analysis_ctx, memo, cycle_map, domains)
|
self.key_value_analysis((*value).clone(), analysis_ctx, memo, cycle_map, domains)
|
||||||
@ -391,7 +391,7 @@ impl CgraphExt for cgraph::ConstraintGraph<'_, dir::DirValue> {
|
|||||||
analysis_ctx: &mut AnalysisContext,
|
analysis_ctx: &mut AnalysisContext,
|
||||||
memo: &mut cgraph::Memoization<dir::DirValue>,
|
memo: &mut cgraph::Memoization<dir::DirValue>,
|
||||||
cycle_map: &mut cgraph::CycleCheck,
|
cycle_map: &mut cgraph::CycleCheck,
|
||||||
domains: Option<&[&str]>,
|
domains: Option<&[String]>,
|
||||||
) -> Result<(), AnalysisError<dir::DirValue>> {
|
) -> Result<(), AnalysisError<dir::DirValue>> {
|
||||||
let mut keywise_metadata: FxHashMap<dir::DirKey, Vec<&Metadata>> = FxHashMap::default();
|
let mut keywise_metadata: FxHashMap<dir::DirKey, Vec<&Metadata>> = FxHashMap::default();
|
||||||
let mut keywise_negation: FxHashMap<dir::DirKey, FxHashSet<&dir::DirValue>> =
|
let mut keywise_negation: FxHashMap<dir::DirKey, FxHashSet<&dir::DirValue>> =
|
||||||
@ -449,7 +449,7 @@ impl CgraphExt for cgraph::ConstraintGraph<'_, dir::DirValue> {
|
|||||||
&self,
|
&self,
|
||||||
ctx: &types::ConjunctiveContext<'_>,
|
ctx: &types::ConjunctiveContext<'_>,
|
||||||
memo: &mut cgraph::Memoization<dir::DirValue>,
|
memo: &mut cgraph::Memoization<dir::DirValue>,
|
||||||
domains: Option<&[&str]>,
|
domains: Option<&[String]>,
|
||||||
) -> Result<(), AnalysisError<dir::DirValue>> {
|
) -> Result<(), AnalysisError<dir::DirValue>> {
|
||||||
let mut analysis_ctx = AnalysisContext::from_dir_values(
|
let mut analysis_ctx = AnalysisContext::from_dir_values(
|
||||||
ctx.iter()
|
ctx.iter()
|
||||||
|
|||||||
@ -3,7 +3,7 @@ use once_cell::sync::Lazy;
|
|||||||
|
|
||||||
use crate::{dssa::graph::euclid_graph_prelude, frontend::dir};
|
use crate::{dssa::graph::euclid_graph_prelude, frontend::dir};
|
||||||
|
|
||||||
pub static ANALYSIS_GRAPH: Lazy<hyperswitch_constraint_graph::ConstraintGraph<'_, dir::DirValue>> =
|
pub static ANALYSIS_GRAPH: Lazy<hyperswitch_constraint_graph::ConstraintGraph<dir::DirValue>> =
|
||||||
Lazy::new(|| {
|
Lazy::new(|| {
|
||||||
knowledge! {
|
knowledge! {
|
||||||
// Payment Method should be `Card` for a CardType to be present
|
// Payment Method should be `Card` for a CardType to be present
|
||||||
|
|||||||
@ -33,12 +33,12 @@ use wasm_bindgen::prelude::*;
|
|||||||
use crate::utils::JsResultExt;
|
use crate::utils::JsResultExt;
|
||||||
type JsResult = Result<JsValue, JsValue>;
|
type JsResult = Result<JsValue, JsValue>;
|
||||||
|
|
||||||
struct SeedData<'a> {
|
struct SeedData {
|
||||||
cgraph: hyperswitch_constraint_graph::ConstraintGraph<'a, dir::DirValue>,
|
cgraph: hyperswitch_constraint_graph::ConstraintGraph<dir::DirValue>,
|
||||||
connectors: Vec<ast::ConnectorChoice>,
|
connectors: Vec<ast::ConnectorChoice>,
|
||||||
}
|
}
|
||||||
|
|
||||||
static SEED_DATA: OnceCell<SeedData<'_>> = OnceCell::new();
|
static SEED_DATA: OnceCell<SeedData> = OnceCell::new();
|
||||||
static SEED_FOREX: OnceCell<currency_conversion_types::ExchangeRates> = OnceCell::new();
|
static SEED_FOREX: OnceCell<currency_conversion_types::ExchangeRates> = OnceCell::new();
|
||||||
|
|
||||||
/// This function can be used by the frontend to educate wasm about the forex rates data.
|
/// This function can be used by the frontend to educate wasm about the forex rates data.
|
||||||
|
|||||||
@ -12,28 +12,34 @@ use crate::{
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub enum DomainIdOrIdentifier<'a> {
|
pub enum DomainIdOrIdentifier {
|
||||||
DomainId(DomainId),
|
DomainId(DomainId),
|
||||||
DomainIdentifier(DomainIdentifier<'a>),
|
DomainIdentifier(DomainIdentifier),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> From<&'a str> for DomainIdOrIdentifier<'a> {
|
impl From<String> for DomainIdOrIdentifier {
|
||||||
fn from(value: &'a str) -> Self {
|
fn from(value: String) -> Self {
|
||||||
Self::DomainIdentifier(DomainIdentifier::new(value))
|
Self::DomainIdentifier(DomainIdentifier::new(value))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<DomainId> for DomainIdOrIdentifier<'_> {
|
impl From<DomainIdentifier> for DomainIdOrIdentifier {
|
||||||
|
fn from(value: DomainIdentifier) -> Self {
|
||||||
|
Self::DomainIdentifier(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<DomainId> for DomainIdOrIdentifier {
|
||||||
fn from(value: DomainId) -> Self {
|
fn from(value: DomainId) -> Self {
|
||||||
Self::DomainId(value)
|
Self::DomainId(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ConstraintGraphBuilder<'a, V: ValueNode> {
|
pub struct ConstraintGraphBuilder<V: ValueNode> {
|
||||||
domain: DenseMap<DomainId, DomainInfo<'a>>,
|
domain: DenseMap<DomainId, DomainInfo>,
|
||||||
nodes: DenseMap<NodeId, Node<V>>,
|
nodes: DenseMap<NodeId, Node<V>>,
|
||||||
edges: DenseMap<EdgeId, Edge>,
|
edges: DenseMap<EdgeId, Edge>,
|
||||||
domain_identifier_map: FxHashMap<DomainIdentifier<'a>, DomainId>,
|
domain_identifier_map: FxHashMap<DomainIdentifier, DomainId>,
|
||||||
value_map: FxHashMap<NodeValue<V>, NodeId>,
|
value_map: FxHashMap<NodeValue<V>, NodeId>,
|
||||||
edges_map: FxHashMap<(NodeId, NodeId, Option<DomainId>), EdgeId>,
|
edges_map: FxHashMap<(NodeId, NodeId, Option<DomainId>), EdgeId>,
|
||||||
node_info: DenseMap<NodeId, Option<&'static str>>,
|
node_info: DenseMap<NodeId, Option<&'static str>>,
|
||||||
@ -41,7 +47,7 @@ pub struct ConstraintGraphBuilder<'a, V: ValueNode> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::new_without_default)]
|
#[allow(clippy::new_without_default)]
|
||||||
impl<'a, V> ConstraintGraphBuilder<'a, V>
|
impl<V> ConstraintGraphBuilder<V>
|
||||||
where
|
where
|
||||||
V: ValueNode,
|
V: ValueNode,
|
||||||
{
|
{
|
||||||
@ -58,7 +64,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build(self) -> ConstraintGraph<'a, V> {
|
pub fn build(self) -> ConstraintGraph<V> {
|
||||||
ConstraintGraph {
|
ConstraintGraph {
|
||||||
domain: self.domain,
|
domain: self.domain,
|
||||||
domain_identifier_map: self.domain_identifier_map,
|
domain_identifier_map: self.domain_identifier_map,
|
||||||
@ -72,7 +78,7 @@ where
|
|||||||
|
|
||||||
fn retrieve_domain_from_identifier(
|
fn retrieve_domain_from_identifier(
|
||||||
&self,
|
&self,
|
||||||
domain_ident: DomainIdentifier<'_>,
|
domain_ident: DomainIdentifier,
|
||||||
) -> Result<DomainId, GraphError<V>> {
|
) -> Result<DomainId, GraphError<V>> {
|
||||||
self.domain_identifier_map
|
self.domain_identifier_map
|
||||||
.get(&domain_ident)
|
.get(&domain_ident)
|
||||||
@ -82,7 +88,7 @@ where
|
|||||||
|
|
||||||
pub fn make_domain(
|
pub fn make_domain(
|
||||||
&mut self,
|
&mut self,
|
||||||
domain_identifier: &'a str,
|
domain_identifier: String,
|
||||||
domain_description: &str,
|
domain_description: &str,
|
||||||
) -> Result<DomainId, GraphError<V>> {
|
) -> Result<DomainId, GraphError<V>> {
|
||||||
let domain_identifier = DomainIdentifier::new(domain_identifier);
|
let domain_identifier = DomainIdentifier::new(domain_identifier);
|
||||||
@ -93,7 +99,7 @@ where
|
|||||||
.map_or_else(
|
.map_or_else(
|
||||||
|| {
|
|| {
|
||||||
let domain_id = self.domain.push(DomainInfo {
|
let domain_id = self.domain.push(DomainInfo {
|
||||||
domain_identifier,
|
domain_identifier: domain_identifier.clone(),
|
||||||
domain_description: domain_description.to_string(),
|
domain_description: domain_description.to_string(),
|
||||||
});
|
});
|
||||||
self.domain_identifier_map
|
self.domain_identifier_map
|
||||||
@ -123,7 +129,7 @@ where
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn make_edge<'short, T: Into<DomainIdOrIdentifier<'short>>>(
|
pub fn make_edge<T: Into<DomainIdOrIdentifier>>(
|
||||||
&mut self,
|
&mut self,
|
||||||
pred_id: NodeId,
|
pred_id: NodeId,
|
||||||
succ_id: NodeId,
|
succ_id: NodeId,
|
||||||
@ -188,7 +194,7 @@ where
|
|||||||
nodes: &[(NodeId, Relation, Strength)],
|
nodes: &[(NodeId, Relation, Strength)],
|
||||||
info: Option<&'static str>,
|
info: Option<&'static str>,
|
||||||
metadata: Option<M>,
|
metadata: Option<M>,
|
||||||
domain: Option<&str>,
|
domain: Option<String>,
|
||||||
) -> Result<NodeId, GraphError<V>> {
|
) -> Result<NodeId, GraphError<V>> {
|
||||||
nodes
|
nodes
|
||||||
.iter()
|
.iter()
|
||||||
@ -202,7 +208,13 @@ where
|
|||||||
.push(metadata.map(|meta| -> Arc<dyn Metadata> { Arc::new(meta) }));
|
.push(metadata.map(|meta| -> Arc<dyn Metadata> { Arc::new(meta) }));
|
||||||
|
|
||||||
for (node_id, relation, strength) in nodes {
|
for (node_id, relation, strength) in nodes {
|
||||||
self.make_edge(*node_id, aggregator_id, *strength, *relation, domain)?;
|
self.make_edge(
|
||||||
|
*node_id,
|
||||||
|
aggregator_id,
|
||||||
|
*strength,
|
||||||
|
*relation,
|
||||||
|
domain.clone(),
|
||||||
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(aggregator_id)
|
Ok(aggregator_id)
|
||||||
@ -213,7 +225,7 @@ where
|
|||||||
nodes: &[(NodeId, Relation, Strength)],
|
nodes: &[(NodeId, Relation, Strength)],
|
||||||
info: Option<&'static str>,
|
info: Option<&'static str>,
|
||||||
metadata: Option<M>,
|
metadata: Option<M>,
|
||||||
domain: Option<&str>,
|
domain: Option<String>,
|
||||||
) -> Result<NodeId, GraphError<V>> {
|
) -> Result<NodeId, GraphError<V>> {
|
||||||
nodes
|
nodes
|
||||||
.iter()
|
.iter()
|
||||||
@ -227,7 +239,13 @@ where
|
|||||||
.push(metadata.map(|meta| -> Arc<dyn Metadata> { Arc::new(meta) }));
|
.push(metadata.map(|meta| -> Arc<dyn Metadata> { Arc::new(meta) }));
|
||||||
|
|
||||||
for (node_id, relation, strength) in nodes {
|
for (node_id, relation, strength) in nodes {
|
||||||
self.make_edge(*node_id, aggregator_id, *strength, *relation, domain)?;
|
self.make_edge(
|
||||||
|
*node_id,
|
||||||
|
aggregator_id,
|
||||||
|
*strength,
|
||||||
|
*relation,
|
||||||
|
domain.clone(),
|
||||||
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(aggregator_id)
|
Ok(aggregator_id)
|
||||||
|
|||||||
@ -26,9 +26,9 @@ struct CheckNodeContext<'a, V: ValueNode, C: CheckingContext<Value = V>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ConstraintGraph<'a, V: ValueNode> {
|
pub struct ConstraintGraph<V: ValueNode> {
|
||||||
pub domain: DenseMap<DomainId, DomainInfo<'a>>,
|
pub domain: DenseMap<DomainId, DomainInfo>,
|
||||||
pub domain_identifier_map: FxHashMap<DomainIdentifier<'a>, DomainId>,
|
pub domain_identifier_map: FxHashMap<DomainIdentifier, DomainId>,
|
||||||
pub nodes: DenseMap<NodeId, Node<V>>,
|
pub nodes: DenseMap<NodeId, Node<V>>,
|
||||||
pub edges: DenseMap<EdgeId, Edge>,
|
pub edges: DenseMap<EdgeId, Edge>,
|
||||||
pub value_map: FxHashMap<NodeValue<V>, NodeId>,
|
pub value_map: FxHashMap<NodeValue<V>, NodeId>,
|
||||||
@ -36,7 +36,7 @@ pub struct ConstraintGraph<'a, V: ValueNode> {
|
|||||||
pub node_metadata: DenseMap<NodeId, Option<Arc<dyn Metadata>>>,
|
pub node_metadata: DenseMap<NodeId, Option<Arc<dyn Metadata>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, V> ConstraintGraph<'a, V>
|
impl<V> ConstraintGraph<V>
|
||||||
where
|
where
|
||||||
V: ValueNode,
|
V: ValueNode,
|
||||||
{
|
{
|
||||||
@ -70,7 +70,7 @@ where
|
|||||||
strength: Strength,
|
strength: Strength,
|
||||||
memo: &mut Memoization<V>,
|
memo: &mut Memoization<V>,
|
||||||
cycle_map: &mut CycleCheck,
|
cycle_map: &mut CycleCheck,
|
||||||
domains: Option<&[&str]>,
|
domains: Option<&[String]>,
|
||||||
) -> Result<(), GraphError<V>>
|
) -> Result<(), GraphError<V>>
|
||||||
where
|
where
|
||||||
C: CheckingContext<Value = V>,
|
C: CheckingContext<Value = V>,
|
||||||
@ -81,7 +81,7 @@ where
|
|||||||
.iter()
|
.iter()
|
||||||
.map(|domain_ident| {
|
.map(|domain_ident| {
|
||||||
self.domain_identifier_map
|
self.domain_identifier_map
|
||||||
.get(&DomainIdentifier::new(domain_ident))
|
.get(&DomainIdentifier::new(domain_ident.to_string()))
|
||||||
.copied()
|
.copied()
|
||||||
.ok_or(GraphError::DomainNotFound)
|
.ok_or(GraphError::DomainNotFound)
|
||||||
})
|
})
|
||||||
@ -482,15 +482,15 @@ where
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn combine<'b>(g1: &'b Self, g2: &'b Self) -> Result<Self, GraphError<V>> {
|
pub fn combine(g1: &Self, g2: &Self) -> Result<Self, GraphError<V>> {
|
||||||
let mut node_builder = builder::ConstraintGraphBuilder::new();
|
let mut node_builder = builder::ConstraintGraphBuilder::new();
|
||||||
let mut g1_old2new_id = DenseMap::<NodeId, NodeId>::new();
|
let mut g1_old2new_id = DenseMap::<NodeId, NodeId>::new();
|
||||||
let mut g2_old2new_id = DenseMap::<NodeId, NodeId>::new();
|
let mut g2_old2new_id = DenseMap::<NodeId, NodeId>::new();
|
||||||
let mut g1_old2new_domain_id = DenseMap::<DomainId, DomainId>::new();
|
let mut g1_old2new_domain_id = DenseMap::<DomainId, DomainId>::new();
|
||||||
let mut g2_old2new_domain_id = DenseMap::<DomainId, DomainId>::new();
|
let mut g2_old2new_domain_id = DenseMap::<DomainId, DomainId>::new();
|
||||||
|
|
||||||
let add_domain = |node_builder: &mut builder::ConstraintGraphBuilder<'a, V>,
|
let add_domain = |node_builder: &mut builder::ConstraintGraphBuilder<V>,
|
||||||
domain: DomainInfo<'a>|
|
domain: DomainInfo|
|
||||||
-> Result<DomainId, GraphError<V>> {
|
-> Result<DomainId, GraphError<V>> {
|
||||||
node_builder.make_domain(
|
node_builder.make_domain(
|
||||||
domain.domain_identifier.into_inner(),
|
domain.domain_identifier.into_inner(),
|
||||||
@ -498,7 +498,7 @@ where
|
|||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
let add_node = |node_builder: &mut builder::ConstraintGraphBuilder<'a, V>,
|
let add_node = |node_builder: &mut builder::ConstraintGraphBuilder<V>,
|
||||||
node: &Node<V>|
|
node: &Node<V>|
|
||||||
-> Result<NodeId, GraphError<V>> {
|
-> Result<NodeId, GraphError<V>> {
|
||||||
match &node.node_type {
|
match &node.node_type {
|
||||||
@ -553,14 +553,14 @@ where
|
|||||||
.domain
|
.domain
|
||||||
.map(|domain_id| g1.domain.get(domain_id).ok_or(GraphError::DomainNotFound))
|
.map(|domain_id| g1.domain.get(domain_id).ok_or(GraphError::DomainNotFound))
|
||||||
.transpose()?
|
.transpose()?
|
||||||
.map(|domain| domain.domain_identifier);
|
.map(|domain| domain.domain_identifier.clone());
|
||||||
|
|
||||||
node_builder.make_edge(
|
node_builder.make_edge(
|
||||||
*new_pred_id,
|
*new_pred_id,
|
||||||
*new_succ_id,
|
*new_succ_id,
|
||||||
edge.strength,
|
edge.strength,
|
||||||
edge.relation,
|
edge.relation,
|
||||||
domain_ident.as_deref(),
|
domain_ident,
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -575,14 +575,14 @@ where
|
|||||||
.domain
|
.domain
|
||||||
.map(|domain_id| g2.domain.get(domain_id).ok_or(GraphError::DomainNotFound))
|
.map(|domain_id| g2.domain.get(domain_id).ok_or(GraphError::DomainNotFound))
|
||||||
.transpose()?
|
.transpose()?
|
||||||
.map(|domain| domain.domain_identifier);
|
.map(|domain| domain.domain_identifier.clone());
|
||||||
|
|
||||||
node_builder.make_edge(
|
node_builder.make_edge(
|
||||||
*new_pred_id,
|
*new_pred_id,
|
||||||
*new_succ_id,
|
*new_succ_id,
|
||||||
edge.strength,
|
edge.strength,
|
||||||
edge.relation,
|
edge.relation,
|
||||||
domain_ident.as_deref(),
|
domain_ident,
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -604,7 +604,7 @@ mod viz {
|
|||||||
format!("N{}", node_id.get_id())
|
format!("N{}", node_id.get_id())
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, V> ConstraintGraph<'a, V>
|
impl<V> ConstraintGraph<V>
|
||||||
where
|
where
|
||||||
V: ValueNode + NodeViz,
|
V: ValueNode + NodeViz,
|
||||||
<V as ValueNode>::Key: NodeViz,
|
<V as ValueNode>::Key: NodeViz,
|
||||||
|
|||||||
@ -139,36 +139,36 @@ pub struct DomainId(usize);
|
|||||||
|
|
||||||
impl_entity!(DomainId);
|
impl_entity!(DomainId);
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
pub struct DomainIdentifier<'a>(&'a str);
|
pub struct DomainIdentifier(String);
|
||||||
|
|
||||||
impl<'a> DomainIdentifier<'a> {
|
impl DomainIdentifier {
|
||||||
pub fn new(identifier: &'a str) -> Self {
|
pub fn new(identifier: String) -> Self {
|
||||||
Self(identifier)
|
Self(identifier)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn into_inner(&self) -> &'a str {
|
pub fn into_inner(&self) -> String {
|
||||||
self.0
|
self.0.clone()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> From<&'a str> for DomainIdentifier<'a> {
|
impl From<String> for DomainIdentifier {
|
||||||
fn from(value: &'a str) -> Self {
|
fn from(value: String) -> Self {
|
||||||
Self(value)
|
Self(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Deref for DomainIdentifier<'a> {
|
// impl Deref for DomainIdentifier {
|
||||||
type Target = str;
|
// type Target = &String;
|
||||||
|
//
|
||||||
fn deref(&self) -> &'a Self::Target {
|
// fn deref(&self) -> Self::Target {
|
||||||
self.0
|
// self.0
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
pub struct DomainInfo<'a> {
|
pub struct DomainInfo {
|
||||||
pub domain_identifier: DomainIdentifier<'a>,
|
pub domain_identifier: DomainIdentifier,
|
||||||
pub domain_description: String,
|
pub domain_description: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -16,10 +16,10 @@ use euclid::{
|
|||||||
use hyperswitch_constraint_graph::{CycleCheck, Memoization};
|
use hyperswitch_constraint_graph::{CycleCheck, Memoization};
|
||||||
use kgraph_utils::{error::KgraphError, transformers::IntoDirValue, types::CountryCurrencyFilter};
|
use kgraph_utils::{error::KgraphError, transformers::IntoDirValue, types::CountryCurrencyFilter};
|
||||||
|
|
||||||
fn build_test_data<'a>(
|
fn build_test_data(
|
||||||
total_enabled: usize,
|
total_enabled: usize,
|
||||||
total_pm_types: usize,
|
total_pm_types: usize,
|
||||||
) -> hyperswitch_constraint_graph::ConstraintGraph<'a, dir::DirValue> {
|
) -> hyperswitch_constraint_graph::ConstraintGraph<dir::DirValue> {
|
||||||
use api_models::{admin::*, payment_methods::*};
|
use api_models::{admin::*, payment_methods::*};
|
||||||
|
|
||||||
let mut pms_enabled: Vec<PaymentMethodsEnabled> = Vec::new();
|
let mut pms_enabled: Vec<PaymentMethodsEnabled> = Vec::new();
|
||||||
|
|||||||
@ -147,7 +147,7 @@ fn get_dir_value_payment_method(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn compile_request_pm_types(
|
fn compile_request_pm_types(
|
||||||
builder: &mut cgraph::ConstraintGraphBuilder<'_, dir::DirValue>,
|
builder: &mut cgraph::ConstraintGraphBuilder<dir::DirValue>,
|
||||||
pm_types: RequestPaymentMethodTypes,
|
pm_types: RequestPaymentMethodTypes,
|
||||||
pm: api_enums::PaymentMethod,
|
pm: api_enums::PaymentMethod,
|
||||||
) -> Result<cgraph::NodeId, KgraphError> {
|
) -> Result<cgraph::NodeId, KgraphError> {
|
||||||
@ -332,7 +332,7 @@ fn compile_request_pm_types(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn compile_payment_method_enabled(
|
fn compile_payment_method_enabled(
|
||||||
builder: &mut cgraph::ConstraintGraphBuilder<'_, dir::DirValue>,
|
builder: &mut cgraph::ConstraintGraphBuilder<dir::DirValue>,
|
||||||
enabled: admin_api::PaymentMethodsEnabled,
|
enabled: admin_api::PaymentMethodsEnabled,
|
||||||
) -> Result<Option<cgraph::NodeId>, KgraphError> {
|
) -> Result<Option<cgraph::NodeId>, KgraphError> {
|
||||||
let agg_id = if !enabled
|
let agg_id = if !enabled
|
||||||
@ -400,7 +400,7 @@ macro_rules! collect_global_variants {
|
|||||||
}
|
}
|
||||||
fn global_vec_pmt(
|
fn global_vec_pmt(
|
||||||
enabled_pmt: Vec<dir::DirValue>,
|
enabled_pmt: Vec<dir::DirValue>,
|
||||||
builder: &mut cgraph::ConstraintGraphBuilder<'_, dir::DirValue>,
|
builder: &mut cgraph::ConstraintGraphBuilder<dir::DirValue>,
|
||||||
) -> Vec<cgraph::NodeId> {
|
) -> Vec<cgraph::NodeId> {
|
||||||
let mut global_vector: Vec<dir::DirValue> = Vec::new();
|
let mut global_vector: Vec<dir::DirValue> = Vec::new();
|
||||||
|
|
||||||
@ -437,7 +437,7 @@ fn global_vec_pmt(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn compile_graph_for_countries_and_currencies(
|
fn compile_graph_for_countries_and_currencies(
|
||||||
builder: &mut cgraph::ConstraintGraphBuilder<'_, dir::DirValue>,
|
builder: &mut cgraph::ConstraintGraphBuilder<dir::DirValue>,
|
||||||
config: &kgraph_types::CurrencyCountryFlowFilter,
|
config: &kgraph_types::CurrencyCountryFlowFilter,
|
||||||
payment_method_type_node: cgraph::NodeId,
|
payment_method_type_node: cgraph::NodeId,
|
||||||
) -> Result<cgraph::NodeId, KgraphError> {
|
) -> Result<cgraph::NodeId, KgraphError> {
|
||||||
@ -503,7 +503,7 @@ fn compile_graph_for_countries_and_currencies(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn compile_config_graph(
|
fn compile_config_graph(
|
||||||
builder: &mut cgraph::ConstraintGraphBuilder<'_, dir::DirValue>,
|
builder: &mut cgraph::ConstraintGraphBuilder<dir::DirValue>,
|
||||||
config: &kgraph_types::CountryCurrencyFilter,
|
config: &kgraph_types::CountryCurrencyFilter,
|
||||||
connector: &api_enums::RoutableConnectors,
|
connector: &api_enums::RoutableConnectors,
|
||||||
) -> Result<cgraph::NodeId, KgraphError> {
|
) -> Result<cgraph::NodeId, KgraphError> {
|
||||||
@ -596,7 +596,7 @@ fn compile_config_graph(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn compile_merchant_connector_graph(
|
fn compile_merchant_connector_graph(
|
||||||
builder: &mut cgraph::ConstraintGraphBuilder<'_, dir::DirValue>,
|
builder: &mut cgraph::ConstraintGraphBuilder<dir::DirValue>,
|
||||||
mca: admin_api::MerchantConnectorResponse,
|
mca: admin_api::MerchantConnectorResponse,
|
||||||
config: &kgraph_types::CountryCurrencyFilter,
|
config: &kgraph_types::CountryCurrencyFilter,
|
||||||
) -> Result<(), KgraphError> {
|
) -> Result<(), KgraphError> {
|
||||||
@ -669,13 +669,13 @@ fn compile_merchant_connector_graph(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn make_mca_graph<'a>(
|
pub fn make_mca_graph(
|
||||||
accts: Vec<admin_api::MerchantConnectorResponse>,
|
accts: Vec<admin_api::MerchantConnectorResponse>,
|
||||||
config: &kgraph_types::CountryCurrencyFilter,
|
config: &kgraph_types::CountryCurrencyFilter,
|
||||||
) -> Result<cgraph::ConstraintGraph<'a, dir::DirValue>, KgraphError> {
|
) -> Result<cgraph::ConstraintGraph<dir::DirValue>, KgraphError> {
|
||||||
let mut builder = cgraph::ConstraintGraphBuilder::new();
|
let mut builder = cgraph::ConstraintGraphBuilder::new();
|
||||||
let _domain = builder.make_domain(
|
let _domain = builder.make_domain(
|
||||||
DOMAIN_IDENTIFIER,
|
DOMAIN_IDENTIFIER.to_string(),
|
||||||
"Payment methods enabled for MerchantConnectorAccount",
|
"Payment methods enabled for MerchantConnectorAccount",
|
||||||
);
|
);
|
||||||
for acct in accts {
|
for acct in accts {
|
||||||
@ -701,7 +701,7 @@ mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
use crate::types as kgraph_types;
|
use crate::types as kgraph_types;
|
||||||
|
|
||||||
fn build_test_data<'a>() -> ConstraintGraph<'a, dir::DirValue> {
|
fn build_test_data() -> ConstraintGraph<dir::DirValue> {
|
||||||
use api_models::{admin::*, payment_methods::*};
|
use api_models::{admin::*, payment_methods::*};
|
||||||
|
|
||||||
let stripe_account = MerchantConnectorResponse {
|
let stripe_account = MerchantConnectorResponse {
|
||||||
|
|||||||
@ -539,7 +539,7 @@ pub async fn get_merchant_cgraph<'a>(
|
|||||||
key_store: &domain::MerchantKeyStore,
|
key_store: &domain::MerchantKeyStore,
|
||||||
#[cfg(feature = "business_profile_routing")] profile_id: Option<String>,
|
#[cfg(feature = "business_profile_routing")] profile_id: Option<String>,
|
||||||
transaction_type: &api_enums::TransactionType,
|
transaction_type: &api_enums::TransactionType,
|
||||||
) -> RoutingResult<Arc<hyperswitch_constraint_graph::ConstraintGraph<'a, euclid_dir::DirValue>>> {
|
) -> RoutingResult<Arc<hyperswitch_constraint_graph::ConstraintGraph<euclid_dir::DirValue>>> {
|
||||||
let merchant_id = &key_store.merchant_id;
|
let merchant_id = &key_store.merchant_id;
|
||||||
|
|
||||||
#[cfg(feature = "business_profile_routing")]
|
#[cfg(feature = "business_profile_routing")]
|
||||||
@ -565,7 +565,7 @@ pub async fn get_merchant_cgraph<'a>(
|
|||||||
};
|
};
|
||||||
|
|
||||||
let cached_cgraph = CGRAPH_CACHE
|
let cached_cgraph = CGRAPH_CACHE
|
||||||
.get_val::<Arc<hyperswitch_constraint_graph::ConstraintGraph<'_, euclid_dir::DirValue>>>(
|
.get_val::<Arc<hyperswitch_constraint_graph::ConstraintGraph<euclid_dir::DirValue>>>(
|
||||||
CacheKey {
|
CacheKey {
|
||||||
key: key.clone(),
|
key: key.clone(),
|
||||||
prefix: state.tenant.redis_key_prefix.clone(),
|
prefix: state.tenant.redis_key_prefix.clone(),
|
||||||
@ -596,7 +596,7 @@ pub async fn refresh_cgraph_cache<'a>(
|
|||||||
key: String,
|
key: String,
|
||||||
#[cfg(feature = "business_profile_routing")] profile_id: Option<String>,
|
#[cfg(feature = "business_profile_routing")] profile_id: Option<String>,
|
||||||
transaction_type: &api_enums::TransactionType,
|
transaction_type: &api_enums::TransactionType,
|
||||||
) -> RoutingResult<Arc<hyperswitch_constraint_graph::ConstraintGraph<'a, euclid_dir::DirValue>>> {
|
) -> RoutingResult<Arc<hyperswitch_constraint_graph::ConstraintGraph<euclid_dir::DirValue>>> {
|
||||||
let mut merchant_connector_accounts = state
|
let mut merchant_connector_accounts = state
|
||||||
.store
|
.store
|
||||||
.find_merchant_connector_account_by_merchant_id_and_disabled_list(
|
.find_merchant_connector_account_by_merchant_id_and_disabled_list(
|
||||||
|
|||||||
Reference in New Issue
Block a user