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