cala_server/graphql/
primitives.rs

1#![allow(clippy::upper_case_acronyms)]
2use async_graphql::*;
3use chrono::NaiveDate;
4use serde::{Deserialize, Serialize};
5
6pub use cala_ledger::primitives::{DebitOrCredit, Layer, Status};
7
8use std::sync::Arc;
9use tokio::sync::Mutex;
10pub type DbOp = Arc<Mutex<cala_ledger::LedgerOperation<'static>>>;
11
12#[derive(Clone, Serialize, Deserialize)]
13#[serde(transparent)]
14pub struct JSON(serde_json::Value);
15scalar!(JSON);
16impl From<serde_json::Value> for JSON {
17    fn from(value: serde_json::Value) -> Self {
18        Self(value)
19    }
20}
21
22impl JSON {
23    pub fn into_inner(self) -> serde_json::Value {
24        self.0
25    }
26}
27
28#[derive(Clone, Serialize, Deserialize)]
29#[serde(transparent)]
30pub struct Timestamp(chrono::DateTime<chrono::Utc>);
31scalar!(Timestamp);
32impl Timestamp {
33    pub fn into_inner(self) -> chrono::DateTime<chrono::Utc> {
34        self.0
35    }
36}
37impl From<chrono::DateTime<chrono::Utc>> for Timestamp {
38    fn from(value: chrono::DateTime<chrono::Utc>) -> Self {
39        Self(value)
40    }
41}
42
43#[derive(Enum, Copy, Clone, PartialEq, Eq)]
44#[graphql(remote = "cala_ledger::tx_template::ParamDataType")]
45pub enum ParamDataType {
46    String,
47    Integer,
48    Decimal,
49    Boolean,
50    Uuid,
51    Date,
52    Timestamp,
53    Json,
54}
55
56#[derive(Clone, Debug, Copy, Serialize, Deserialize)]
57#[serde(transparent)]
58pub struct UUID(uuid::Uuid);
59scalar!(UUID);
60impl<T: Into<uuid::Uuid>> From<T> for UUID {
61    fn from(id: T) -> Self {
62        let uuid = id.into();
63        Self(uuid)
64    }
65}
66
67impl From<UUID> for cala_ledger::AccountId {
68    fn from(uuid: UUID) -> Self {
69        cala_ledger::AccountId::from(uuid.0)
70    }
71}
72
73impl From<UUID> for cala_ledger::AccountSetId {
74    fn from(uuid: UUID) -> Self {
75        cala_ledger::AccountSetId::from(uuid.0)
76    }
77}
78
79impl From<UUID> for cala_ledger::JournalId {
80    fn from(uuid: UUID) -> Self {
81        cala_ledger::JournalId::from(uuid.0)
82    }
83}
84
85impl From<UUID> for cala_ledger::VelocityLimitId {
86    fn from(uuid: UUID) -> Self {
87        cala_ledger::VelocityLimitId::from(uuid.0)
88    }
89}
90
91impl From<UUID> for cala_ledger::VelocityControlId {
92    fn from(uuid: UUID) -> Self {
93        cala_ledger::VelocityControlId::from(uuid.0)
94    }
95}
96
97impl From<UUID> for cala_ledger::TxTemplateId {
98    fn from(uuid: UUID) -> Self {
99        cala_ledger::TxTemplateId::from(uuid.0)
100    }
101}
102
103impl From<UUID> for cala_ledger::TransactionId {
104    fn from(uuid: UUID) -> Self {
105        cala_ledger::TransactionId::from(uuid.0)
106    }
107}
108
109impl From<UUID> for crate::primitives::JobId {
110    fn from(uuid: UUID) -> Self {
111        crate::primitives::JobId::from(uuid.0)
112    }
113}
114
115impl From<UUID> for crate::integration::IntegrationId {
116    fn from(uuid: UUID) -> Self {
117        crate::integration::IntegrationId::from(uuid.0)
118    }
119}
120
121#[derive(Clone, Serialize, Deserialize)]
122#[serde(transparent)]
123pub struct Expression(String);
124scalar!(Expression);
125
126impl From<cel_interpreter::CelExpression> for Expression {
127    fn from(expr: cel_interpreter::CelExpression) -> Self {
128        Self(expr.to_string())
129    }
130}
131
132impl From<Expression> for String {
133    fn from(expr: Expression) -> Self {
134        expr.0
135    }
136}
137
138#[derive(Clone, Serialize, Deserialize)]
139#[serde(transparent)]
140pub struct Date(NaiveDate);
141scalar!(Date);
142impl From<NaiveDate> for Date {
143    fn from(value: NaiveDate) -> Self {
144        Self(value)
145    }
146}
147impl From<Date> for NaiveDate {
148    fn from(value: Date) -> Self {
149        value.0
150    }
151}
152
153#[derive(Serialize, Deserialize, Clone)]
154#[serde(transparent)]
155pub struct CurrencyCode(cala_types::primitives::Currency);
156scalar!(CurrencyCode);
157impl From<CurrencyCode> for cala_types::primitives::Currency {
158    fn from(code: CurrencyCode) -> Self {
159        code.0
160    }
161}
162impl From<cala_types::primitives::Currency> for CurrencyCode {
163    fn from(code: cala_types::primitives::Currency) -> Self {
164        Self(code)
165    }
166}
167
168#[derive(Clone, Serialize, Deserialize)]
169#[serde(transparent)]
170pub struct Decimal(rust_decimal::Decimal);
171scalar!(Decimal);
172impl From<rust_decimal::Decimal> for Decimal {
173    fn from(value: rust_decimal::Decimal) -> Self {
174        Self(value)
175    }
176}
177impl From<Decimal> for rust_decimal::Decimal {
178    fn from(value: Decimal) -> Self {
179        value.0
180    }
181}