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