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<es_entity::DbOpWithTime<'static>>>;
11
12pub use es_entity::graphql::UUID;
13
14#[derive(Clone, Serialize, Deserialize)]
15#[serde(transparent)]
16pub struct JSON(serde_json::Value);
17scalar!(JSON);
18impl From<serde_json::Value> for JSON {
19    fn from(value: serde_json::Value) -> Self {
20        Self(value)
21    }
22}
23
24impl JSON {
25    pub fn into_inner(self) -> serde_json::Value {
26        self.0
27    }
28}
29
30#[derive(Clone, Serialize, Deserialize)]
31#[serde(transparent)]
32pub struct Timestamp(chrono::DateTime<chrono::Utc>);
33scalar!(Timestamp);
34impl Timestamp {
35    pub fn into_inner(self) -> chrono::DateTime<chrono::Utc> {
36        self.0
37    }
38}
39impl From<chrono::DateTime<chrono::Utc>> for Timestamp {
40    fn from(value: chrono::DateTime<chrono::Utc>) -> Self {
41        Self(value)
42    }
43}
44
45#[derive(Enum, Copy, Clone, PartialEq, Eq)]
46#[graphql(remote = "cala_ledger::tx_template::ParamDataType")]
47pub enum ParamDataType {
48    String,
49    Integer,
50    Decimal,
51    Boolean,
52    Uuid,
53    Date,
54    Timestamp,
55    Json,
56}
57
58#[derive(Clone, Serialize, Deserialize)]
59#[serde(transparent)]
60pub struct Expression(String);
61scalar!(Expression);
62
63impl From<cel_interpreter::CelExpression> for Expression {
64    fn from(expr: cel_interpreter::CelExpression) -> Self {
65        Self(expr.to_string())
66    }
67}
68
69impl From<Expression> for String {
70    fn from(expr: Expression) -> Self {
71        expr.0
72    }
73}
74
75#[derive(Clone, Serialize, Deserialize)]
76#[serde(transparent)]
77pub struct Date(NaiveDate);
78scalar!(Date);
79impl From<NaiveDate> for Date {
80    fn from(value: NaiveDate) -> Self {
81        Self(value)
82    }
83}
84impl From<Date> for NaiveDate {
85    fn from(value: Date) -> Self {
86        value.0
87    }
88}
89
90#[derive(Serialize, Deserialize, Clone)]
91#[serde(transparent)]
92pub struct CurrencyCode(cala_types::primitives::Currency);
93scalar!(CurrencyCode);
94impl From<CurrencyCode> for cala_types::primitives::Currency {
95    fn from(code: CurrencyCode) -> Self {
96        code.0
97    }
98}
99impl From<cala_types::primitives::Currency> for CurrencyCode {
100    fn from(code: cala_types::primitives::Currency) -> Self {
101        Self(code)
102    }
103}
104
105#[derive(Clone, Serialize, Deserialize)]
106#[serde(transparent)]
107pub struct Decimal(rust_decimal::Decimal);
108scalar!(Decimal);
109impl From<rust_decimal::Decimal> for Decimal {
110    fn from(value: rust_decimal::Decimal) -> Self {
111        Self(value)
112    }
113}
114impl From<Decimal> for rust_decimal::Decimal {
115    fn from(value: Decimal) -> Self {
116        value.0
117    }
118}