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