id stringlengths 11 116 | type stringclasses 1 value | granularity stringclasses 4 values | content stringlengths 16 477k | metadata dict |
|---|---|---|---|---|
fn_clm_common_utils_from_-7491340477675652801 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/encryption
// Implementation of Encryption for From<Encryptable<T>>
fn from(value: Encryptable<T>) -> Self {
Self::new(value.into_encrypted())
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 2604,
"total_crates": null
} |
fn_clm_common_utils_into_inner_-7491340477675652801 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/encryption
// Inherent implementation for Encryption
pub fn into_inner(self) -> Secret<Vec<u8>, EncryptionStrategy> {
self.inner
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 2061,
"total_crates": null
} |
fn_clm_common_utils_get_inner_-7491340477675652801 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/encryption
// Inherent implementation for Encryption
pub fn get_inner(&self) -> &Secret<Vec<u8>, EncryptionStrategy> {
&self.inner
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 594,
"total_crates": null
} |
fn_clm_common_utils_build_-7491340477675652801 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/encryption
// Implementation of Encryption for Queryable<sql_types::Binary, DB>
fn build(row: Self::Row) -> deserialize::Result<Self> {
Ok(Self { inner: row })
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 572,
"total_crates": null
} |
fn_clm_common_utils_from_-2934312499112945212 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/lib
// Implementation of DateTime<T> for From<PrimitiveDateTime>
fn from(value: PrimitiveDateTime) -> Self {
Self {
inner: PhantomData,
value,
}
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 2600,
"total_crates": null
} |
fn_clm_common_utils_now_-2934312499112945212 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/lib
/// Create a new [`PrimitiveDateTime`] with the current date and time in UTC.
pub fn now() -> PrimitiveDateTime {
let utc_date_time = OffsetDateTime::now_utc();
PrimitiveDateTime::new(utc_date_time.date(), utc_date_time.time())
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 987,
"total_crates": null
} |
fn_clm_common_utils_generate_id_-2934312499112945212 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/lib
pub fn generate_id(length: usize, prefix: &str) -> String {
format!("{}_{}", prefix, nanoid::nanoid!(length, &consts::ALPHABETS))
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 118,
"total_crates": null
} |
fn_clm_common_utils_serialize_-2934312499112945212 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/lib
// Implementation of DateTime<T> for Serialize
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.collect_str(self)
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 85,
"total_crates": null
} |
fn_clm_common_utils_generate_id_with_default_len_-2934312499112945212 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/lib
pub fn generate_id_with_default_len(prefix: &str) -> String {
let len: usize = consts::ID_LENGTH;
format!("{}_{}", prefix, nanoid::nanoid!(len, &consts::ALPHABETS))
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 67,
"total_crates": null
} |
fn_clm_common_utils_from_488542607492470028 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/new_type
// Implementation of MaskedPhoneNumber for From<Secret<String>>
fn from(secret: Secret<String>) -> Self {
Self::from(secret.expose())
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 2604,
"total_crates": null
} |
fn_clm_common_utils_foreign_from_488542607492470028 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/new_type
// Implementation of MaskedEmail for ForeignFrom<Email>
fn foreign_from(email: Email) -> Self {
let email_value: String = email.expose().peek().to_owned();
Self::from(email_value)
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 220,
"total_crates": null
} |
fn_clm_common_utils_apply_mask_488542607492470028 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/new_type
/// Function for masking alphanumeric characters in a string.
///
/// # Arguments
/// `val`
/// - holds reference to the string to be masked.
/// `unmasked_char_count`
/// - minimum character count to remain unmasked for identification
/// - this number is for keeping the characters unmasked from
/// both beginning (if feasible) and ending of the string.
/// `min_masked_char_count`
/// - this ensures the minimum number of characters to be masked
///
/// # Behaviour
/// - Returns the original string if its length is less than or equal to `unmasked_char_count`.
/// - If the string length allows, keeps `unmasked_char_count` characters unmasked at both start and end.
/// - Otherwise, keeps `unmasked_char_count` characters unmasked only at the end.
/// - Only alphanumeric characters are masked; other characters remain unchanged.
///
/// # Examples
/// Sort Code
/// (12-34-56, 2, 2) -> 12-**-56
/// Routing number
/// (026009593, 3, 3) -> 026***593
/// CNPJ
/// (12345678901, 4, 4) -> *******8901
/// CNPJ
/// (12345678901, 4, 3) -> 1234***8901
/// Pix key
/// (123e-a452-1243-1244-000, 4, 4) -> 123e-****-****-****-000
/// IBAN
/// (AL35202111090000000001234567, 5, 5) -> AL352******************34567
fn apply_mask(val: &str, unmasked_char_count: usize, min_masked_char_count: usize) -> String {
let len = val.len();
if len <= unmasked_char_count {
return val.to_string();
}
let mask_start_index =
// For showing only last `unmasked_char_count` characters
if len < (unmasked_char_count * 2 + min_masked_char_count) {
0
// For showing first and last `unmasked_char_count` characters
} else {
unmasked_char_count
};
let mask_end_index = len - unmasked_char_count - 1;
let range = mask_start_index..=mask_end_index;
val.chars()
.enumerate()
.fold(String::new(), |mut acc, (index, ch)| {
if ch.is_alphanumeric() && range.contains(&index) {
acc.push('*');
} else {
acc.push(ch);
}
acc
})
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 20,
"total_crates": null
} |
fn_clm_common_utils_test_masked_types_488542607492470028 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/new_type
fn test_masked_types() {
let sort_code = MaskedSortCode::from("110011".to_string());
let routing_number = MaskedRoutingNumber::from("056008849".to_string());
let bank_account = MaskedBankAccount::from("12345678901234".to_string());
let iban = MaskedIban::from("NL02ABNA0123456789".to_string());
let upi_vpa = MaskedUpiVpaId::from("someusername@okhdfcbank".to_string());
// Standard masked data tests
assert_eq!(sort_code.0.peek().to_owned(), "11**11".to_string());
assert_eq!(routing_number.0.peek().to_owned(), "056***849".to_string());
assert_eq!(
bank_account.0.peek().to_owned(),
"1234******1234".to_string()
);
assert_eq!(iban.0.peek().to_owned(), "NL02A********56789".to_string());
assert_eq!(
upi_vpa.0.peek().to_owned(),
"so**********@okhdfcbank".to_string()
);
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 20,
"total_crates": null
} |
fn_clm_common_utils_test_apply_mask_fn_488542607492470028 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/new_type
fn test_apply_mask_fn() {
let value = "12345678901".to_string();
// Generic masked tests
assert_eq!(apply_mask(&value, 2, 2), "12*******01".to_string());
assert_eq!(apply_mask(&value, 3, 2), "123*****901".to_string());
assert_eq!(apply_mask(&value, 3, 3), "123*****901".to_string());
assert_eq!(apply_mask(&value, 4, 3), "1234***8901".to_string());
assert_eq!(apply_mask(&value, 4, 4), "*******8901".to_string());
assert_eq!(apply_mask(&value, 5, 4), "******78901".to_string());
assert_eq!(apply_mask(&value, 5, 5), "******78901".to_string());
assert_eq!(apply_mask(&value, 6, 5), "*****678901".to_string());
assert_eq!(apply_mask(&value, 6, 6), "*****678901".to_string());
assert_eq!(apply_mask(&value, 7, 6), "****5678901".to_string());
assert_eq!(apply_mask(&value, 7, 7), "****5678901".to_string());
assert_eq!(apply_mask(&value, 8, 7), "***45678901".to_string());
assert_eq!(apply_mask(&value, 8, 8), "***45678901".to_string());
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 2,
"total_crates": null
} |
fn_clm_common_utils_when_7876561264291191705 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/fp_utils
/// This function wraps the evaluated result of `f` into current context,
/// based on the condition provided into the `predicate`
pub fn when<W: Applicative<(), WrappedSelf<()> = W>, F>(predicate: bool, f: F) -> W
where
F: FnOnce() -> W,
{
if predicate {
f()
} else {
W::pure(())
}
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 470,
"total_crates": null
} |
fn_clm_common_utils_pure_7876561264291191705 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/fp_utils
// Implementation of Result<R, E> for Applicative<R>
fn pure(v: R) -> Self::WrappedSelf<R> {
Ok(v)
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 11,
"total_crates": null
} |
fn_clm_common_utils_close_817284218056227262 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/signals
// Implementation of None for DummySignal
/// Hollow implementation, for windows compatibility
pub fn close(self) {}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 39,
"total_crates": null
} |
fn_clm_common_utils_handle_817284218056227262 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/signals
// Implementation of None for DummySignal
/// Dummy handler for signals in windows (empty)
pub fn handle(&self) -> Self {
self.clone()
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 38,
"total_crates": null
} |
fn_clm_common_utils_signal_handler_817284218056227262 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/signals
pub async fn signal_handler(_sig: DummySignal, _sender: mpsc::Sender<()>) {}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 19,
"total_crates": null
} |
fn_clm_common_utils_get_allowed_signals_817284218056227262 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/signals
pub fn get_allowed_signals() -> Result<DummySignal, std::io::Error> {
Ok(DummySignal)
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 19,
"total_crates": null
} |
fn_clm_common_utils_create_access_token_key_-467993698232365948 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/access_token
/// Create a key for fetching the access token from redis
pub fn create_access_token_key(
merchant_id: &id_type::MerchantId,
merchant_connector_id_or_connector_name: impl Display,
) -> String {
merchant_id.get_access_token_key(merchant_connector_id_or_connector_name)
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 12,
"total_crates": null
} |
fn_clm_common_utils_from_8738394823178034619 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/hashing
// Implementation of HashedString<T> for From<Secret<String, T>>
fn from(value: Secret<String, T>) -> Self {
Self(value)
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 2602,
"total_crates": null
} |
fn_clm_common_utils_serialize_8738394823178034619 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/hashing
// Implementation of HashedString<T> for Serialize
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let hashed_value = blake3::hash(self.0.peek().as_bytes()).to_hex();
hashed_value.serialize(serializer)
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 93,
"total_crates": null
} |
fn_clm_common_utils_contains_potential_xss_or_sqli_-5789299776266406187 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/validation
/// checks whether the input string contains potential XSS or SQL injection attack vectors
pub fn contains_potential_xss_or_sqli(input: &str) -> bool {
let decoded = urlencoding::decode(input).unwrap_or_else(|_| input.into());
// Check for suspicious percent-encoded patterns
static PERCENT_ENCODED: LazyLock<Option<Regex>> = LazyLock::new(|| {
Regex::new(r"%[0-9A-Fa-f]{2}")
.map_err(|_err| {
#[cfg(feature = "logs")]
logger::error!(?_err);
})
.ok()
});
if decoded.contains('%') {
match PERCENT_ENCODED.as_ref() {
Some(regex) => {
if regex.is_match(&decoded) {
return true;
}
}
None => return true,
}
}
if ammonia::is_html(&decoded) {
return true;
}
static XSS: LazyLock<Option<Regex>> = LazyLock::new(|| {
Regex::new(
r"(?is)\bon[a-z]+\s*=|\bjavascript\s*:|\bdata\s*:\s*text/html|\b(alert|prompt|confirm|eval)\s*\(",
)
.map_err(|_err| {
#[cfg(feature = "logs")]
logger::error!(?_err);
})
.ok()
});
static SQLI: LazyLock<Option<Regex>> = LazyLock::new(|| {
Regex::new(
r"(?is)(?:')\s*or\s*'?\d+'?=?\d*|union\s+select|insert\s+into|drop\s+table|information_schema|sleep\s*\(|--|;",
)
.map_err(|_err| {
#[cfg(feature = "logs")]
logger::error!(?_err);
})
.ok()
});
match XSS.as_ref() {
Some(regex) => {
if regex.is_match(&decoded) {
return true;
}
}
None => return true,
}
match SQLI.as_ref() {
Some(regex) => {
if regex.is_match(&decoded) {
return true;
}
}
None => return true,
}
false
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 59,
"total_crates": null
} |
fn_clm_common_utils_validate_email_-5789299776266406187 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/validation
/// Performs a simple validation against a provided email address.
pub fn validate_email(email: &str) -> CustomResult<(), ValidationError> {
#[deny(clippy::invalid_regex)]
static EMAIL_REGEX: LazyLock<Option<Regex>> = LazyLock::new(|| {
#[allow(unknown_lints)]
#[allow(clippy::manual_ok_err)]
match Regex::new(
r"^(?i)[a-z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)+$",
) {
Ok(regex) => Some(regex),
Err(_error) => {
#[cfg(feature = "logs")]
logger::error!(?_error);
None
}
}
});
let email_regex = match EMAIL_REGEX.as_ref() {
Some(regex) => Ok(regex),
None => Err(report!(ValidationError::InvalidValue {
message: "Invalid regex expression".into()
})),
}?;
const EMAIL_MAX_LENGTH: usize = 319;
if email.is_empty() || email.chars().count() > EMAIL_MAX_LENGTH {
return Err(report!(ValidationError::InvalidValue {
message: "Email address is either empty or exceeds maximum allowed length".into()
}));
}
if !email_regex.is_match(email) {
return Err(report!(ValidationError::InvalidValue {
message: "Invalid email address format".into()
}));
}
Ok(())
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 36,
"total_crates": null
} |
fn_clm_common_utils_validate_domain_against_allowed_domains_-5789299776266406187 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/validation
/// Checks whether a given domain matches against a list of valid domain glob patterns
pub fn validate_domain_against_allowed_domains(
domain: &str,
allowed_domains: HashSet<String>,
) -> bool {
allowed_domains.iter().any(|allowed_domain| {
Glob::new(allowed_domain)
.map(|glob| glob.compile_matcher().is_match(domain))
.map_err(|err| {
let err_msg = format!(
"Invalid glob pattern for configured allowed_domain [{allowed_domain:?}]! - {err:?}",
);
#[cfg(feature = "logs")]
logger::error!(err_msg);
err_msg
})
.unwrap_or(false)
})
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 32,
"total_crates": null
} |
fn_clm_common_utils_validate_phone_number_-5789299776266406187 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/validation
/// Validates a given phone number using the [phonenumber] crate
///
/// It returns a [ValidationError::InvalidValue] in case it could not parse the phone number
pub fn validate_phone_number(phone_number: &str) -> Result<(), ValidationError> {
let _ = phonenumber::parse(None, phone_number).map_err(|e| ValidationError::InvalidValue {
message: format!("Could not parse phone number: {phone_number}, because: {e:?}"),
})?;
Ok(())
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 17,
"total_crates": null
} |
fn_clm_common_utils_new_tree_-5789299776266406187 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/validation
// Implementation of ValidEmail for Strategy
fn new_tree(&self, _runner: &mut TestRunner) -> NewTree<Self> {
Ok(Just(SafeEmail().fake()))
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 14,
"total_crates": null
} |
fn_clm_common_utils_try_from_7951268606651782908 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/pii
// Implementation of Email for TryFrom<String>
fn try_from(value: String) -> Result<Self, Self::Error> {
Self::from_str(&value).change_context(errors::ParsingError::EmailParsingError)
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 2661,
"total_crates": null
} |
fn_clm_common_utils_from_7951268606651782908 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/pii
// Implementation of Email for From<Encryptable<Secret<String, EmailStrategy>>>
fn from(item: Encryptable<Secret<String, EmailStrategy>>) -> Self {
Self(item.into_inner())
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 2604,
"total_crates": null
} |
fn_clm_common_utils_expose_7951268606651782908 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/pii
// Implementation of Email for ExposeInterface<Secret<String, EmailStrategy>>
fn expose(self) -> Secret<String, EmailStrategy> {
self.0
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 887,
"total_crates": null
} |
fn_clm_common_utils_from_str_7951268606651782908 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/pii
// Implementation of Email for FromStr
fn from_str(email: &str) -> Result<Self, Self::Err> {
if email.eq(REDACTED) {
return Ok(Self(Secret::new(email.to_string())));
}
match validate_email(email) {
Ok(_) => {
let secret = Secret::<String, EmailStrategy>::new(email.to_string());
Ok(Self(secret))
}
Err(_) => Err(ValidationError::InvalidValue {
message: "Invalid email address format".into(),
}
.into()),
}
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 799,
"total_crates": null
} |
fn_clm_common_utils_build_7951268606651782908 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/pii
// Implementation of Email for Queryable<sql_types::Text, DB>
fn build(row: Self::Row) -> deserialize::Result<Self> {
Ok(row)
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 572,
"total_crates": null
} |
fn_clm_common_utils_switch_-4799217296292316745 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/errors
// Implementation of S for ErrorSwitch<T>
fn switch(&self) -> T {
T::switch_from(self)
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 3082,
"total_crates": null
} |
fn_clm_common_utils_call_encryption_service_-6659953211353241817 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/keymanager
pub async fn call_encryption_service<T, R>(
state: &KeyManagerState,
method: Method,
endpoint: &str,
request_body: T,
) -> errors::CustomResult<R, errors::KeyManagerClientError>
where
T: GetKeymanagerTenant + ConvertRaw + Send + Sync + 'static + Debug,
R: serde::de::DeserializeOwned,
{
let url = format!("{}/{endpoint}", &state.url);
logger::info!(key_manager_request=?request_body);
let mut header = vec![];
header.push((
HeaderName::from_str(CONTENT_TYPE)
.change_context(errors::KeyManagerClientError::FailedtoConstructHeader)?,
HeaderValue::from_str("application/json")
.change_context(errors::KeyManagerClientError::FailedtoConstructHeader)?,
));
#[cfg(feature = "km_forward_x_request_id")]
if let Some(request_id) = state.request_id {
header.push((
HeaderName::from_str(X_REQUEST_ID)
.change_context(errors::KeyManagerClientError::FailedtoConstructHeader)?,
HeaderValue::from_str(request_id.as_hyphenated().to_string().as_str())
.change_context(errors::KeyManagerClientError::FailedtoConstructHeader)?,
))
}
//Add Tenant ID
header.push((
HeaderName::from_str(TENANT_HEADER)
.change_context(errors::KeyManagerClientError::FailedtoConstructHeader)?,
HeaderValue::from_str(request_body.get_tenant_id(state).get_string_repr())
.change_context(errors::KeyManagerClientError::FailedtoConstructHeader)?,
));
let response = send_encryption_request(
state,
HeaderMap::from_iter(header.into_iter()),
url,
method,
request_body,
)
.await
.map_err(|err| err.change_context(errors::KeyManagerClientError::RequestSendFailed))?;
logger::info!(key_manager_response=?response);
match response.status() {
StatusCode::OK => response
.json::<R>()
.await
.change_context(errors::KeyManagerClientError::ResponseDecodingFailed),
StatusCode::INTERNAL_SERVER_ERROR => {
Err(errors::KeyManagerClientError::InternalServerError(
response
.bytes()
.await
.change_context(errors::KeyManagerClientError::ResponseDecodingFailed)?,
)
.into())
}
StatusCode::BAD_REQUEST => Err(errors::KeyManagerClientError::BadRequest(
response
.bytes()
.await
.change_context(errors::KeyManagerClientError::ResponseDecodingFailed)?,
)
.into()),
_ => Err(errors::KeyManagerClientError::Unexpected(
response
.bytes()
.await
.change_context(errors::KeyManagerClientError::ResponseDecodingFailed)?,
)
.into()),
}
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 106,
"total_crates": null
} |
fn_clm_common_utils_get_api_encryption_client_-6659953211353241817 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/keymanager
fn get_api_encryption_client(
state: &KeyManagerState,
) -> errors::CustomResult<reqwest::Client, errors::KeyManagerClientError> {
let get_client = || {
let mut client = reqwest::Client::builder()
.redirect(reqwest::redirect::Policy::none())
.pool_idle_timeout(std::time::Duration::from_secs(
state.client_idle_timeout.unwrap_or_default(),
));
#[cfg(feature = "keymanager_mtls")]
{
let cert = state.cert.clone();
let ca = state.ca.clone();
let identity = reqwest::Identity::from_pem(cert.peek().as_ref())
.change_context(errors::KeyManagerClientError::ClientConstructionFailed)?;
let ca_cert = reqwest::Certificate::from_pem(ca.peek().as_ref())
.change_context(errors::KeyManagerClientError::ClientConstructionFailed)?;
client = client
.use_rustls_tls()
.identity(identity)
.add_root_certificate(ca_cert)
.https_only(true);
}
client
.build()
.change_context(errors::KeyManagerClientError::ClientConstructionFailed)
};
Ok(ENCRYPTION_API_CLIENT.get_or_try_init(get_client)?.clone())
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 51,
"total_crates": null
} |
fn_clm_common_utils_send_encryption_request_-6659953211353241817 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/keymanager
pub async fn send_encryption_request<T>(
state: &KeyManagerState,
headers: HeaderMap,
url: String,
method: Method,
request_body: T,
) -> errors::CustomResult<reqwest::Response, errors::KeyManagerClientError>
where
T: ConvertRaw,
{
let client = get_api_encryption_client(state)?;
let url = reqwest::Url::parse(&url)
.change_context(errors::KeyManagerClientError::UrlEncodingFailed)?;
client
.request(method, url)
.json(&ConvertRaw::convert_raw(request_body)?)
.headers(headers)
.send()
.await
.change_context(errors::KeyManagerClientError::RequestNotSent(
"Unable to send request to encryption service".to_string(),
))
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 35,
"total_crates": null
} |
fn_clm_common_utils_convert_raw_-6659953211353241817 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/keymanager
// Implementation of TransientBatchDecryptDataRequest for ConvertRaw
fn convert_raw(self) -> Result<Self::Output, errors::KeyManagerClientError> {
let data = self
.data
.iter()
.map(|(k, v)| {
let value = match String::from_utf8(v.peek().clone()) {
Ok(data) => data,
Err(_) => {
let data = BASE64_ENGINE.encode(v.peek().clone());
format!("{DEFAULT_ENCRYPTION_VERSION}:{data}")
}
};
(k.to_owned(), StrongSecret::new(value))
})
.collect();
Ok(BatchDecryptDataRequest {
data,
identifier: self.identifier,
})
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 33,
"total_crates": null
} |
fn_clm_common_utils_transfer_key_to_key_manager_-6659953211353241817 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/keymanager
pub async fn transfer_key_to_key_manager(
state: &KeyManagerState,
request_body: EncryptionTransferRequest,
) -> errors::CustomResult<DataKeyCreateResponse, errors::KeyManagerError> {
call_encryption_service(state, Method::POST, "key/transfer", request_body)
.await
.change_context(errors::KeyManagerError::KeyTransferFailed)
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 26,
"total_crates": null
} |
fn_clm_common_utils_get_string_repr_-2374071360479736839 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/ucs_types
// Inherent implementation for UcsReferenceId
/// Returns the string representation of the reference ID.
///
/// This method matches the enum variant and calls the `get_string_repr`
/// method of the underlying ID type (either `PaymentReferenceId` or `RefundReferenceId`)
/// to get its string representation.
///
/// # Returns
///
/// A string slice (`&str`) representing the reference ID.
pub fn get_string_repr(&self) -> &str {
match self {
Self::Payment(id) => id.get_string_repr(),
Self::Refund(id) => id.get_string_repr(),
}
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 1372,
"total_crates": null
} |
fn_clm_common_utils_new_5444864533983678573 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/id_type
// Inherent implementation for LengthId<MAX_LENGTH, MIN_LENGTH>
/// Generate a new MerchantRefId of default length with the given prefix
pub fn new(prefix: &str) -> Self {
Self(AlphaNumericId::new(prefix))
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 14467,
"total_crates": null
} |
fn_clm_common_utils_from_5444864533983678573 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/id_type
// Inherent implementation for LengthId<MAX_LENGTH, MIN_LENGTH>
/// Generates new [MerchantReferenceId] from the given input string
pub fn from(input_string: Cow<'static, str>) -> Result<Self, LengthIdError> {
let trimmed_input_string = input_string.trim().to_string();
let length_of_input_string = u8::try_from(trimmed_input_string.len())
.map_err(|_| LengthIdError::MaxLengthViolated(MAX_LENGTH))?;
when(length_of_input_string > MAX_LENGTH, || {
Err(LengthIdError::MaxLengthViolated(MAX_LENGTH))
})?;
when(length_of_input_string < MIN_LENGTH, || {
Err(LengthIdError::MinLengthViolated(MIN_LENGTH))
})?;
let alphanumeric_id = match AlphaNumericId::from(trimmed_input_string.into()) {
Ok(valid_alphanumeric_id) => valid_alphanumeric_id,
Err(error) => Err(LengthIdError::AlphanumericIdError(error))?,
};
Ok(Self(alphanumeric_id))
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 2638,
"total_crates": null
} |
fn_clm_common_utils_deserialize_5444864533983678573 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/id_type
// Implementation of LengthId<MAX_LENGTH, MIN_LENGTH> for Deserialize<'de>
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let deserialized_string = String::deserialize(deserializer)?;
Self::from(deserialized_string.into()).map_err(serde::de::Error::custom)
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 142,
"total_crates": null
} |
fn_clm_common_utils_to_sql_5444864533983678573 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/id_type
// Implementation of LengthId<MAX_LENGTH, MIN_LENGTH> for ToSql<sql_types::Text, DB>
fn to_sql<'b>(&'b self, out: &mut Output<'b, '_, DB>) -> diesel::serialize::Result {
self.0 .0.to_sql(out)
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 100,
"total_crates": null
} |
fn_clm_common_utils_new_unchecked_5444864533983678573 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/id_type
// Inherent implementation for LengthId<MAX_LENGTH, MIN_LENGTH>
/// Use this function only if you are sure that the length is within the range
pub(crate) fn new_unchecked(alphanumeric_id: AlphaNumericId) -> Self {
Self(alphanumeric_id)
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 83,
"total_crates": null
} |
fn_clm_common_utils_test_enum_from_str_failures_yield_invalid_7821998726570502121 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/macros
fn test_enum_from_str_failures_yield_invalid() {
// Missing delimiter
let parsed: TestEnum = "VariantA".parse().unwrap();
assert_eq!(parsed, TestEnum::Invalid);
// Unknown tag
let parsed: TestEnum = "UnknownVariant:123".parse().unwrap();
assert_eq!(parsed, TestEnum::Invalid);
// Bad field data for i32
let parsed: TestEnum = "VariantA:not_a_number".parse().unwrap();
assert_eq!(parsed, TestEnum::Invalid);
// Bad field data for JsonValue
let parsed: TestEnum = r#"VariantJson:{"bad_json"#.parse().unwrap();
assert_eq!(parsed, TestEnum::Invalid);
// Empty field data for non-string (e.g., i32)
let parsed: TestEnum = "VariantA:".parse().unwrap();
assert_eq!(parsed, TestEnum::Invalid);
// Empty field data for string IS valid for String type
let parsed_str: TestEnum = "VariantB:".parse().unwrap();
assert_eq!(
parsed_str,
TestEnum::VariantB {
text: "".to_string()
}
);
// Parsing the literal "Invalid" string
let parsed_invalid_str: TestEnum = "Invalid".parse().unwrap();
assert_eq!(parsed_invalid_str, TestEnum::Invalid);
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 14,
"total_crates": null
} |
fn_clm_common_utils_test_enum_from_str_ok_7821998726570502121 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/macros
fn test_enum_from_str_ok() {
// Success cases just parse directly
let parsed_a: TestEnum = "VariantA:42".parse().unwrap(); // Unwrapping Infallible is fine
assert_eq!(parsed_a, TestEnum::VariantA { value: 42 });
let parsed_b: TestEnum = "VariantB:hello world".parse().unwrap();
assert_eq!(
parsed_b,
TestEnum::VariantB {
text: "hello world".to_string()
}
);
let parsed_c: TestEnum = "VariantC:123456789012345".parse().unwrap();
assert_eq!(
parsed_c,
TestEnum::VariantC {
id: 123456789012345
}
);
let parsed_json: TestEnum = r#"VariantJson:{"ok":true}"#.parse().unwrap();
assert_eq!(
parsed_json,
TestEnum::VariantJson {
data: json!({"ok": true})
}
);
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 8,
"total_crates": null
} |
fn_clm_common_utils_test_enum_deserialize_7821998726570502121 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/macros
fn test_enum_deserialize() {
// Deserialize valid
let input_a = "\"VariantA:123\"";
let deserialized_a: TestEnum = serde_json::from_str(input_a).expect("Deserialize A failed");
assert_eq!(deserialized_a, TestEnum::VariantA { value: 123 });
// Deserialize explicit "Invalid"
let input_invalid = "\"Invalid\"";
let deserialized_invalid: TestEnum =
serde_json::from_str(input_invalid).expect("Deserialize Invalid failed");
assert_eq!(deserialized_invalid, TestEnum::Invalid);
// Deserialize malformed string (according to macro rules) -> Invalid
let input_malformed = "\"VariantA_no_delimiter\"";
let deserialized_malformed: TestEnum =
serde_json::from_str(input_malformed).expect("Deserialize malformed should succeed");
assert_eq!(deserialized_malformed, TestEnum::Invalid);
// Deserialize string with bad field data -> Invalid
let input_bad_data = "\"VariantA:not_a_number\"";
let deserialized_bad_data: TestEnum =
serde_json::from_str(input_bad_data).expect("Deserialize bad data should succeed");
assert_eq!(deserialized_bad_data, TestEnum::Invalid);
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 8,
"total_crates": null
} |
fn_clm_common_utils_test_enum_display_and_serialize_7821998726570502121 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/macros
fn test_enum_display_and_serialize() {
// Display valid
let value_a = TestEnum::VariantA { value: 99 };
assert_eq!(value_a.to_string(), "VariantA:99");
// Serialize valid
let json_a = serde_json::to_string(&value_a).expect("Serialize A failed");
assert_eq!(json_a, "\"VariantA:99\""); // Serializes to JSON string
// Display Invalid
let value_invalid = TestEnum::Invalid;
assert_eq!(value_invalid.to_string(), "Invalid");
// Serialize Invalid
let json_invalid = serde_json::to_string(&value_invalid).expect("Serialize Invalid failed");
assert_eq!(json_invalid, "\"Invalid\""); // Serializes to JSON string "Invalid"
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 4,
"total_crates": null
} |
fn_clm_common_utils_default_-5832961537169702603 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/link_utils
// Implementation of GenericLinkStatus for Default
fn default() -> Self {
Self::PaymentMethodCollect(PaymentMethodCollectStatus::Initiated)
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 7705,
"total_crates": null
} |
fn_clm_common_utils_to_sql_-5832961537169702603 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/link_utils
// Implementation of PayoutLinkStatus for ToSql<Jsonb, diesel::pg::Pg>
fn to_sql<'b>(&'b self, out: &mut Output<'b, '_, diesel::pg::Pg>) -> diesel::serialize::Result {
let value = serde_json::to_value(GenericLinkStatus::PayoutLink(self.clone()))?;
// the function `reborrow` only works in case of `Pg` backend. But, in case of other backends
// please refer to the diesel migration blog:
// https://github.com/Diesel-rs/Diesel/blob/master/guide_drafts/migration_guide.md#changed-tosql-implementations
<serde_json::Value as ToSql<Jsonb, diesel::pg::Pg>>::to_sql(&value, &mut out.reborrow())
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 108,
"total_crates": null
} |
fn_clm_common_utils_from_sql_-5832961537169702603 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/link_utils
// Implementation of PayoutLinkStatus for FromSql<Jsonb, DB>
fn from_sql(bytes: DB::RawValue<'_>) -> deserialize::Result<Self> {
let value = <serde_json::Value as FromSql<Jsonb, DB>>::from_sql(bytes)?;
let generic_status: GenericLinkStatus = serde_json::from_value(value)?;
match generic_status {
GenericLinkStatus::PayoutLink(status) => Ok(status),
GenericLinkStatus::PaymentMethodCollect(_) => {
Err(report!(ParsingError::EnumParseFailure("PayoutLinkStatus")))
.attach_printable("Invalid status for PayoutLink")?
}
}
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 56,
"total_crates": null
} |
fn_clm_common_utils_validate_strict_domain_-5832961537169702603 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/link_utils
/// Util function for validating a domain without any wildcard characters.
pub fn validate_strict_domain(domain: &str) -> bool {
Regex::new(consts::STRICT_DOMAIN_REGEX)
.map(|regex| regex.is_match(domain))
.map_err(|err| {
let err_msg = format!("Invalid strict domain regex: {err:?}");
#[cfg(feature = "logs")]
logger::error!(err_msg);
err_msg
})
.unwrap_or(false)
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 23,
"total_crates": null
} |
fn_clm_common_utils_validate_wildcard_domain_-5832961537169702603 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/link_utils
/// Util function for validating a domain with "*" wildcard characters.
pub fn validate_wildcard_domain(domain: &str) -> bool {
Regex::new(consts::WILDCARD_DOMAIN_REGEX)
.map(|regex| regex.is_match(domain))
.map_err(|err| {
let err_msg = format!("Invalid strict domain regex: {err:?}");
#[cfg(feature = "logs")]
logger::error!(err_msg);
err_msg
})
.unwrap_or(false)
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 23,
"total_crates": null
} |
fn_clm_common_utils_new_6538734040281769980 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/crypto
// Inherent implementation for Encryptable<Secret<T, S>>
/// constructor function to be used by the encryptor and decryptor to generate the data type
pub fn new(
masked_data: Secret<T, S>,
encrypted_data: Secret<Vec<u8>, EncryptionStrategy>,
) -> Self {
Self {
inner: masked_data,
encrypted: encrypted_data,
}
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 14463,
"total_crates": null
} |
fn_clm_common_utils_map_6538734040281769980 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/crypto
// Inherent implementation for Encryptable<T>
/// consume self and modify the inner value
pub fn map<U: Clone>(self, f: impl FnOnce(T) -> U) -> Encryptable<U> {
let encrypted_data = self.encrypted;
let masked_data = f(self.inner);
Encryptable {
inner: masked_data,
encrypted: encrypted_data,
}
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 10682,
"total_crates": null
} |
fn_clm_common_utils_into_inner_6538734040281769980 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/crypto
// Inherent implementation for Encryptable<T>
pub fn into_inner(self) -> T {
self.inner
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 2061,
"total_crates": null
} |
fn_clm_common_utils_eq_6538734040281769980 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/crypto
// Implementation of Encryptable<T> for PartialEq
fn eq(&self, other: &Self) -> bool {
self.inner.eq(&other.inner)
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 1660,
"total_crates": null
} |
fn_clm_common_utils_get_inner_6538734040281769980 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/crypto
// Inherent implementation for Encryptable<T>
pub fn get_inner(&self) -> &T {
&self.inner
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 594,
"total_crates": null
} |
fn_clm_common_utils_deserialize_-7323342421096957814 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/custom_serde
/// Deserialize an [`PrimitiveDateTime`] from its ISO 8601 representation.
pub fn deserialize<'a, D>(deserializer: D) -> Result<PrimitiveDateTime, D::Error>
where
D: Deserializer<'a>,
{
iso8601::deserialize(deserializer).map(|offset_date_time| {
let utc_date_time = offset_date_time.to_offset(UtcOffset::UTC);
PrimitiveDateTime::new(utc_date_time.date(), utc_date_time.time())
})
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 148,
"total_crates": null
} |
fn_clm_common_utils_serialize_-7323342421096957814 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/custom_serde
/// Serialize a [`PrimitiveDateTime`] using the well-known ISO 8601 format.
pub fn serialize<S>(date_time: &PrimitiveDateTime, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
date_time
.assume_utc()
.format(&Iso8601::<FORMAT_CONFIG>)
.map_err(S::Error::custom)?
.replace('T', " ")
.replace('Z', "")
.serialize(serializer)
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 95,
"total_crates": null
} |
fn_clm_common_utils_test_leap_second_parse_-7323342421096957814 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/custom_serde
fn test_leap_second_parse() {
#[derive(Serialize, Deserialize)]
struct Try {
#[serde(with = "crate::custom_serde::iso8601")]
f: time::PrimitiveDateTime,
}
let leap_second_date_time = json!({"f": "2023-12-31T23:59:60.000Z"});
let deser = serde_json::from_value::<Try>(leap_second_date_time);
assert!(deser.is_ok())
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 0,
"total_crates": null
} |
fn_clm_common_utils_record_operation_time_7990481962817447751 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/metrics/utils
pub async fn record_operation_time<F, R>(
future: F,
metric: &opentelemetry::metrics::Histogram<f64>,
key_value: &[opentelemetry::KeyValue],
) -> R
where
F: futures::Future<Output = R>,
{
let (result, time) = time_future(future).await;
metric.record(time.as_secs_f64(), key_value);
result
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 79,
"total_crates": null
} |
fn_clm_common_utils_time_future_7990481962817447751 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/metrics/utils
pub async fn time_future<F, R>(future: F) -> (R, time::Duration)
where
F: futures::Future<Output = R>,
{
let start = time::Instant::now();
let result = future.await;
let time_spent = start.elapsed();
(result, time_spent)
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 23,
"total_crates": null
} |
fn_clm_common_utils_from_3575816632047387102 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/types/primitive_wrappers
// Implementation of RequestExtendedAuthorizationBool for From<bool>
fn from(value: bool) -> Self {
Self(value)
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 2602,
"total_crates": null
} |
fn_clm_common_utils_to_sql_3575816632047387102 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/types/primitive_wrappers
// Implementation of AlwaysRequestExtendedAuthorization for diesel::serialize::ToSql<diesel::sql_types::Bool, DB>
fn to_sql<'b>(
&'b self,
out: &mut diesel::serialize::Output<'b, '_, DB>,
) -> diesel::serialize::Result {
self.0.to_sql(out)
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 100,
"total_crates": null
} |
fn_clm_common_utils_from_sql_3575816632047387102 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/types/primitive_wrappers
// Implementation of AlwaysRequestExtendedAuthorization for diesel::deserialize::FromSql<diesel::sql_types::Bool, DB>
fn from_sql(value: DB::RawValue<'_>) -> diesel::deserialize::Result<Self> {
bool::from_sql(value).map(Self)
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 54,
"total_crates": null
} |
fn_clm_common_utils_is_true_3575816632047387102 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/types/primitive_wrappers
// Inherent implementation for RequestExtendedAuthorizationBool
/// returns the inner bool value
pub fn is_true(&self) -> bool {
self.0
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 24,
"total_crates": null
} |
fn_clm_common_utils_from_-493396240172805921 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/types/keymanager
// Implementation of TransientBatchDecryptDataRequest for From<(FxHashMap<String, Encryption>, Identifier)>
fn from((map, identifier): (FxHashMap<String, Encryption>, Identifier)) -> Self {
let data = map
.into_iter()
.map(|(k, v)| (k, StrongSecret::new(v.clone().into_inner().expose())))
.collect();
Self { data, identifier }
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 2614,
"total_crates": null
} |
fn_clm_common_utils_foreign_try_from_-493396240172805921 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/types/keymanager
// Implementation of FxHashMap<String, Encryptable<Secret<T, S>>> for ForeignTryFrom<(FxHashMap<String, Encryption>, BatchDecryptDataResponse)>
fn foreign_try_from(
(mut encrypted_data, response): (FxHashMap<String, Encryption>, BatchDecryptDataResponse),
) -> Result<Self, Self::Error> {
response
.data
.0
.into_iter()
.map(|(k, v)| match encrypted_data.remove(&k) {
Some(encrypted) => Ok((k.clone(), Encryptable::convert(&v, encrypted.clone())?)),
None => Err(errors::CryptoError::DecodingFailed)?,
})
.collect()
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 442,
"total_crates": null
} |
fn_clm_common_utils_convert_-493396240172805921 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/types/keymanager
// Implementation of Encryptable<Secret<Vec<u8>, S>> for DecryptedDataConversion<Vec<u8>, S>
fn convert(
value: &DecryptedData,
encryption: Encryption,
) -> CustomResult<Self, errors::CryptoError> {
Ok(Self::new(
Secret::new(value.clone().inner().peek().clone()),
encryption.clone().into_inner(),
))
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 378,
"total_crates": null
} |
fn_clm_common_utils_foreign_from_-493396240172805921 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/types/keymanager
// Implementation of Encryptable<Secret<T, S>> for ForeignFrom<(Secret<T, S>, EncryptDataResponse)>
fn foreign_from((masked_data, response): (Secret<T, S>, EncryptDataResponse)) -> Self {
Self::new(masked_data, response.data.data.peek().clone().into())
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 220,
"total_crates": null
} |
fn_clm_common_utils_deserialize_-493396240172805921 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/types/keymanager
// Implementation of EncryptedData for Deserialize<'de>
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
struct EncryptedDataVisitor;
impl Visitor<'_> for EncryptedDataVisitor {
type Value = EncryptedData;
fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str("string of the format {version}:{base64_encoded_data}'")
}
fn visit_str<E>(self, value: &str) -> Result<EncryptedData, E>
where
E: de::Error,
{
Ok(EncryptedData {
data: StrongSecret::new(value.as_bytes().to_vec()),
})
}
}
deserializer.deserialize_str(EncryptedDataVisitor)
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 144,
"total_crates": null
} |
fn_clm_common_utils_to_str_-8049205557109938781 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/types/authentication
// Inherent implementation for ResourceId
/// Get string representation of enclosed ID type
pub fn to_str(&self) -> &str {
match self {
Self::Payment(id) => id.get_string_repr(),
Self::Customer(id) => id.get_string_repr(),
Self::PaymentMethodSession(id) => id.get_string_repr(),
}
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 183,
"total_crates": null
} |
fn_clm_common_utils_new_-5351765584926030299 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/types/user/theme
// Implementation of None for ThemeLineage
/// Constructor for ThemeLineage
pub fn new(
entity_type: EntityType,
tenant_id: id_type::TenantId,
org_id: id_type::OrganizationId,
merchant_id: id_type::MerchantId,
profile_id: id_type::ProfileId,
) -> Self {
match entity_type {
EntityType::Tenant => Self::Tenant { tenant_id },
EntityType::Organization => Self::Organization { tenant_id, org_id },
EntityType::Merchant => Self::Merchant {
tenant_id,
org_id,
merchant_id,
},
EntityType::Profile => Self::Profile {
tenant_id,
org_id,
merchant_id,
profile_id,
},
}
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 14463,
"total_crates": null
} |
fn_clm_common_utils_entity_type_-5351765584926030299 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/types/user/theme
// Implementation of None for ThemeLineage
/// Get the entity_type from the lineage
pub fn entity_type(&self) -> EntityType {
match self {
Self::Tenant { .. } => EntityType::Tenant,
Self::Organization { .. } => EntityType::Organization,
Self::Merchant { .. } => EntityType::Merchant,
Self::Profile { .. } => EntityType::Profile,
}
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 24,
"total_crates": null
} |
fn_clm_common_utils_tenant_id_-5351765584926030299 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/types/user/theme
// Implementation of None for ThemeLineage
/// Get the tenant_id from the lineage
pub fn tenant_id(&self) -> &id_type::TenantId {
match self {
Self::Tenant { tenant_id }
| Self::Organization { tenant_id, .. }
| Self::Merchant { tenant_id, .. }
| Self::Profile { tenant_id, .. } => tenant_id,
}
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 24,
"total_crates": null
} |
fn_clm_common_utils_merchant_id_-5351765584926030299 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/types/user/theme
// Implementation of None for ThemeLineage
/// Get the merchant_id from the lineage
pub fn merchant_id(&self) -> Option<&id_type::MerchantId> {
match self {
Self::Tenant { .. } | Self::Organization { .. } => None,
Self::Merchant { merchant_id, .. } | Self::Profile { merchant_id, .. } => {
Some(merchant_id)
}
}
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 24,
"total_crates": null
} |
fn_clm_common_utils_get_same_and_higher_lineages_-5351765584926030299 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/types/user/theme
// Implementation of None for ThemeLineage
/// Get higher lineages from the current lineage
pub fn get_same_and_higher_lineages(self) -> Vec<Self> {
match &self {
Self::Tenant { .. } => vec![self],
Self::Organization { tenant_id, .. } => vec![
Self::Tenant {
tenant_id: tenant_id.clone(),
},
self,
],
Self::Merchant {
tenant_id, org_id, ..
} => vec![
Self::Tenant {
tenant_id: tenant_id.clone(),
},
Self::Organization {
tenant_id: tenant_id.clone(),
org_id: org_id.clone(),
},
self,
],
Self::Profile {
tenant_id,
org_id,
merchant_id,
..
} => vec![
Self::Tenant {
tenant_id: tenant_id.clone(),
},
Self::Organization {
tenant_id: tenant_id.clone(),
org_id: org_id.clone(),
},
Self::Merchant {
tenant_id: tenant_id.clone(),
org_id: org_id.clone(),
merchant_id: merchant_id.clone(),
},
self,
],
}
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 24,
"total_crates": null
} |
fn_clm_common_utils_try_from_string_-4535625922556734739 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/id_type/organization
// Inherent implementation for OrganizationId
/// Get an organization id from String
pub fn try_from_string(org_id: String) -> CustomResult<Self, ValidationError> {
Self::try_from(std::borrow::Cow::from(org_id))
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 88,
"total_crates": null
} |
fn_clm_common_utils_from_7762068683770106760 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/id_type/profile
// Implementation of router_env::opentelemetry::Value for From<ProfileId>
fn from(val: ProfileId) -> Self {
Self::from(val.0 .0 .0)
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 2602,
"total_crates": null
} |
fn_clm_common_utils_from_str_7762068683770106760 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/id_type/profile
// Implementation of ProfileId for FromStr
fn from_str(s: &str) -> Result<Self, Self::Err> {
let cow_string = std::borrow::Cow::Owned(s.to_string());
Self::try_from(cow_string)
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 785,
"total_crates": null
} |
fn_clm_common_utils_get_api_event_type_7762068683770106760 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/id_type/profile
// Implementation of ProfileId for crate::events::ApiEventMetric
fn get_api_event_type(&self) -> Option<crate::events::ApiEventsType> {
Some(crate::events::ApiEventsType::BusinessProfile {
profile_id: self.clone(),
})
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 28,
"total_crates": null
} |
fn_clm_common_utils_try_from_string_-5970731337908557916 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/id_type/tenant
// Inherent implementation for TenantId
/// Get tenant id from String
pub fn try_from_string(tenant_id: String) -> CustomResult<Self, ValidationError> {
Self::try_from(std::borrow::Cow::from(tenant_id))
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 88,
"total_crates": null
} |
fn_clm_common_utils_get_default_global_tenant_id_-5970731337908557916 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/id_type/tenant
// Inherent implementation for TenantId
/// Get the default global tenant ID
pub fn get_default_global_tenant_id() -> Self {
Self(super::LengthId::new_unchecked(
super::AlphaNumericId::new_unchecked(DEFAULT_GLOBAL_TENANT_ID.to_string()),
))
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 29,
"total_crates": null
} |
fn_clm_common_utils_from_str_4055914607305113315 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/id_type/merchant_connector_account
// Implementation of MerchantConnectorAccountId for FromStr
fn from_str(s: &str) -> Result<Self, Self::Err> {
Self::try_from(std::borrow::Cow::Owned(s.to_string())).map_err(|_| std::fmt::Error)
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 787,
"total_crates": null
} |
fn_clm_common_utils_wrap_4055914607305113315 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/id_type/merchant_connector_account
// Inherent implementation for MerchantConnectorAccountId
/// Get a merchant connector account id from String
pub fn wrap(merchant_connector_account_id: String) -> CustomResult<Self, ValidationError> {
Self::try_from(std::borrow::Cow::from(merchant_connector_account_id))
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 94,
"total_crates": null
} |
fn_clm_common_utils_get_api_event_type_-7457057124139948864 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/id_type/client_secret
// Implementation of ClientSecretId for crate::events::ApiEventMetric
fn get_api_event_type(&self) -> Option<crate::events::ApiEventsType> {
Some(crate::events::ApiEventsType::ClientSecret {
key_id: self.clone(),
})
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 28,
"total_crates": null
} |
fn_clm_common_utils_generate_redis_key_-7457057124139948864 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/id_type/client_secret
// Implementation of None for ClientSecretId
/// Generate a key for redis
pub fn generate_redis_key(&self) -> String {
format!("cs_{}", self.get_string_repr())
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 18,
"total_crates": null
} |
fn_clm_common_utils_from_-3676629758147312860 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/id_type/global_id
// Implementation of CellIdError for From<AlphaNumericIdError>
fn from(error: AlphaNumericIdError) -> Self {
Self::InvalidCellIdFormat(error)
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 2602,
"total_crates": null
} |
fn_clm_common_utils_get_string_repr_-3676629758147312860 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/id_type/global_id
// Implementation of None for GlobalId
pub(crate) fn get_string_repr(&self) -> &str {
&self.0 .0 .0
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 1368,
"total_crates": null
} |
fn_clm_common_utils_from_str_-3676629758147312860 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/id_type/global_id
// Inherent implementation for CellId
/// Create a new cell id from a string
fn from_str(cell_id_string: impl AsRef<str>) -> Result<Self, CellIdError> {
let trimmed_input_string = cell_id_string.as_ref().trim().to_string();
let alphanumeric_id = AlphaNumericId::from(trimmed_input_string.into())?;
let length_id = LengthId::from_alphanumeric_id(alphanumeric_id)?;
Ok(Self(length_id))
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 793,
"total_crates": null
} |
fn_clm_common_utils_generate_-3676629758147312860 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/id_type/global_id
// Implementation of None for GlobalId
/// Create a new global id from entity and cell information
/// The entity prefix is used to identify the entity, `cus` for customers, `pay`` for payments etc.
pub fn generate(cell_id: &CellId, entity: GlobalEntity) -> Self {
let prefix = format!("{}_{}", cell_id.get_string_repr(), entity.prefix());
let id = generate_time_ordered_id(&prefix);
let alphanumeric_id = AlphaNumericId::new_unchecked(id);
Self(LengthId::new_unchecked(alphanumeric_id))
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 149,
"total_crates": null
} |
fn_clm_common_utils_deserialize_-3676629758147312860 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/id_type/global_id
// Implementation of GlobalId for serde::Deserialize<'de>
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let deserialized_string = String::deserialize(deserializer)?;
Self::from_string(deserialized_string.into()).map_err(serde::de::Error::custom)
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 142,
"total_crates": null
} |
fn_clm_common_utils_get_api_event_type_-5159423833374433968 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/id_type/subscription
// Implementation of SubscriptionId for crate::events::ApiEventMetric
fn get_api_event_type(&self) -> Option<crate::events::ApiEventsType> {
Some(crate::events::ApiEventsType::Subscription)
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 26,
"total_crates": null
} |
fn_clm_common_utils_from_-1515564286038466489 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/id_type/merchant
// Implementation of keymanager::Identifier for From<MerchantId>
fn from(value: MerchantId) -> Self {
Self::Merchant(value)
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": false,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 2602,
"total_crates": null
} |
fn_clm_common_utils_wrap_-1515564286038466489 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/id_type/merchant
// Implementation of None for MerchantId
/// Get a merchant id from String
pub fn wrap(merchant_id: String) -> CustomResult<Self, ValidationError> {
Self::try_from(std::borrow::Cow::from(merchant_id))
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 94,
"total_crates": null
} |
fn_clm_common_utils_from_merchant_name_-1515564286038466489 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/id_type/merchant
// Implementation of None for MerchantId
/// Create a Merchant id from MerchantName
pub fn from_merchant_name(merchant_name: MerchantName) -> Self {
let merchant_name_string = merchant_name.into_inner();
let merchant_id_prefix = merchant_name_string.trim().to_lowercase().replace(' ', "");
let alphanumeric_id =
AlphaNumericId::new_unchecked(generate_id_with_default_len(&merchant_id_prefix));
let length_id = LengthId::new_unchecked(alphanumeric_id);
Self(length_id)
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 37,
"total_crates": null
} |
fn_clm_common_utils_get_internal_user_merchant_id_-1515564286038466489 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/id_type/merchant
// Implementation of None for MerchantId
/// Get a merchant id for internal use only
pub fn get_internal_user_merchant_id(merchant_id: &str) -> Self {
let alphanumeric_id = AlphaNumericId::new_unchecked(merchant_id.to_string());
let length_id = LengthId::new_unchecked(alphanumeric_id);
Self(length_id)
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 32,
"total_crates": null
} |
fn_clm_common_utils_new_from_unix_timestamp_-1515564286038466489 | clm | function | // Repository: hyperswitch
// Crate: common_utils
// Purpose: Utility functions shared across crates
// Module: crates/common_utils/src/id_type/merchant
// Implementation of None for MerchantId
/// Create a new merchant_id from unix timestamp, of the format `merchant_{timestamp}`
pub fn new_from_unix_timestamp() -> Self {
let merchant_id = format!("merchant_{}", date_time::now_unix_timestamp());
let alphanumeric_id = AlphaNumericId::new_unchecked(merchant_id);
let length_id = LengthId::new_unchecked(alphanumeric_id);
Self(length_id)
}
| {
"crate": "common_utils",
"file": null,
"file_size": null,
"is_async": false,
"is_pub": true,
"num_enums": null,
"num_structs": null,
"num_tables": null,
"score": 30,
"total_crates": null
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.