Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ jobs:
uses: Swatinem/rust-cache@v2.7.3
- name: Run cargo clippy
run: cargo clippy --all-targets -- --deny warnings
clippy-python:
name: Clippy-Python
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
- name: Cache dependencies
uses: Swatinem/rust-cache@v2.7.3
- name: Run cargo clippy
run: cargo clippy --all-targets -F python -- --deny warnings
fmt:
name: Rustfmt
runs-on: ubuntu-latest
Expand All @@ -34,6 +46,18 @@ jobs:
uses: Swatinem/rust-cache@v2.7.3
- name: Run cargo fmt
run: cargo fmt --all -- --check
check-python:
name: Check-Python
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
- name: Cache dependencies
uses: Swatinem/rust-cache@v2.7.3
- name: Run cargo fmt
run: cargo check --all-targets -F python
test:
name: Tests
strategy:
Expand Down
391 changes: 387 additions & 4 deletions src/lib.rs

Large diffs are not rendered by default.

330 changes: 330 additions & 0 deletions src/native/common.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,330 @@
use chrono::{DateTime, Utc};
use serde::Deserialize;

#[cfg(feature = "python")]
use pyo3::{prelude::*, types::PyDateTime};

use crate::native::deserializers::{
default_datetime_none, default_string_none, deserialize_empty_string_as_none,
deserialize_empty_string_as_none_datetime,
};

#[cfg(feature = "python")]
use crate::native::deserializers::{to_py_datetime, to_py_datetime_option};

#[cfg(not(feature = "python"))]
#[derive(Debug, Deserialize, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct Value {
pub by: String,

#[serde(
default = "default_string_none",
deserialize_with = "deserialize_empty_string_as_none"
)]
pub by_unique_id: Option<String>,
pub role: String,
pub when: DateTime<Utc>,

#[serde(rename = "$value")]
pub value: String,
}

#[cfg(feature = "python")]
#[derive(Clone, Debug, Deserialize, PartialEq)]
#[serde(rename_all = "camelCase")]
#[pyclass]
pub struct Value {
pub by: String,

#[serde(
default = "default_string_none",
deserialize_with = "deserialize_empty_string_as_none"
)]
pub by_unique_id: Option<String>,
pub role: String,
pub when: DateTime<Utc>,

#[serde(rename = "$value")]
pub value: String,
}

#[cfg(feature = "python")]
#[pymethods]
impl Value {
#[getter]
fn by(&self) -> PyResult<String> {
Ok(self.by.clone())
}

#[getter]
fn by_unique_id(&self) -> PyResult<Option<String>> {
Ok(self.by_unique_id.clone())
}

#[getter]
fn role(&self) -> PyResult<String> {
Ok(self.role.clone())
}

#[getter]
fn when<'py>(&self, py: Python<'py>) -> PyResult<Bound<'py, PyDateTime>> {
to_py_datetime(py, &self.when)
}

#[getter]
fn value(&self) -> PyResult<String> {
Ok(self.value.clone())
}
}

#[cfg(not(feature = "python"))]
#[derive(Debug, Deserialize, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct Reason {
pub by: String,

#[serde(
default = "default_string_none",
deserialize_with = "deserialize_empty_string_as_none"
)]
pub by_unique_id: Option<String>,

pub role: String,
pub when: DateTime<Utc>,

#[serde(rename = "$value")]
pub value: String,
}

#[cfg(feature = "python")]
#[derive(Clone, Debug, Deserialize, PartialEq)]
#[serde(rename_all = "camelCase")]
#[pyclass]
pub struct Reason {
pub by: String,

#[serde(
default = "default_string_none",
deserialize_with = "deserialize_empty_string_as_none"
)]
pub by_unique_id: Option<String>,

pub role: String,
pub when: DateTime<Utc>,

#[serde(rename = "$value")]
pub value: String,
}

#[cfg(feature = "python")]
#[pymethods]
impl Reason {
#[getter]
fn by(&self) -> PyResult<String> {
Ok(self.by.clone())
}

#[getter]
fn by_unique_id(&self) -> PyResult<Option<String>> {
Ok(self.by_unique_id.clone())
}

#[getter]
fn role(&self) -> PyResult<String> {
Ok(self.role.clone())
}

#[getter]
fn when<'py>(&self, py: Python<'py>) -> PyResult<Bound<'py, PyDateTime>> {
to_py_datetime(py, &self.when)
}

#[getter]
fn value(&self) -> PyResult<String> {
Ok(self.value.clone())
}
}

#[cfg(not(feature = "python"))]
#[derive(Debug, Deserialize, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct Entry {
#[serde(alias = "id")]
pub entry_id: String,
pub value: Option<Value>,
pub reason: Option<Reason>,
}

#[cfg(feature = "python")]
#[derive(Clone, Debug, Deserialize, PartialEq)]
#[serde(rename_all = "camelCase")]
#[pyclass(get_all)]
pub struct Entry {
#[serde(alias = "id")]
pub entry_id: String,
pub value: Option<Value>,
pub reason: Option<Reason>,
}

#[cfg(not(feature = "python"))]
#[derive(Debug, Deserialize, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct Field {
pub name: String,

#[serde(alias = "type")]
pub field_type: String,

pub data_type: String,
pub error_code: String,
pub when_created: DateTime<Utc>,
pub keep_history: bool,

#[serde(rename = "entry")]
pub entries: Option<Vec<Entry>>,
}

#[cfg(feature = "python")]
#[derive(Clone, Debug, Deserialize, PartialEq)]
#[serde(rename_all = "camelCase")]
#[pyclass]
pub struct Field {
pub name: String,

#[serde(alias = "type")]
pub field_type: String,

pub data_type: String,
pub error_code: String,
pub when_created: DateTime<Utc>,
pub keep_history: bool,

#[serde(rename = "entry")]
pub entries: Option<Vec<Entry>>,
}

#[cfg(feature = "python")]
#[pymethods]
impl Field {
#[getter]
fn name(&self) -> PyResult<String> {
Ok(self.name.clone())
}

#[getter]
fn field_type(&self) -> PyResult<String> {
Ok(self.field_type.clone())
}

#[getter]
fn data_type(&self) -> PyResult<String> {
Ok(self.data_type.clone())
}

#[getter]
fn error_code(&self) -> PyResult<String> {
Ok(self.error_code.clone())
}

#[getter]
fn when_created<'py>(&self, py: Python<'py>) -> PyResult<Bound<'py, PyDateTime>> {
to_py_datetime(py, &self.when_created)
}

#[getter]
fn keep_history(&self) -> PyResult<bool> {
Ok(self.keep_history)
}

#[getter]
fn entries(&self) -> PyResult<Option<Vec<Entry>>> {
Ok(self.entries.clone())
}
}

#[cfg(not(feature = "python"))]
#[derive(Debug, Deserialize, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct Category {
pub name: String,

#[serde(alias = "type")]
pub category_type: String,

pub highest_index: usize,

#[serde(rename = "field", default)]
pub fields: Vec<Field>,
}

#[cfg(feature = "python")]
#[derive(Clone, Debug, Deserialize, PartialEq)]
#[serde(rename_all = "camelCase")]
#[pyclass(get_all)]
pub struct Category {
pub name: String,

#[serde(alias = "type")]
pub category_type: String,

pub highest_index: usize,

#[serde(rename = "field", default)]
pub fields: Vec<Field>,
}

#[cfg(not(feature = "python"))]
#[derive(Debug, Deserialize, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct State {
pub value: String,
pub signer: String,
pub signer_unique_id: String,

#[serde(
default = "default_datetime_none",
deserialize_with = "deserialize_empty_string_as_none_datetime"
)]
pub date_signed: Option<DateTime<Utc>>,
}

#[cfg(feature = "python")]
#[derive(Clone, Debug, Deserialize, PartialEq)]
#[serde(rename_all = "camelCase")]
#[pyclass]
pub struct State {
pub value: String,
pub signer: String,
pub signer_unique_id: String,

#[serde(
default = "default_datetime_none",
deserialize_with = "deserialize_empty_string_as_none_datetime"
)]
pub date_signed: Option<DateTime<Utc>>,
}

#[cfg(feature = "python")]
#[pymethods]
impl State {
#[getter]
fn value(&self) -> PyResult<String> {
Ok(self.value.clone())
}

#[getter]
fn signer(&self) -> PyResult<String> {
Ok(self.signer.clone())
}

#[getter]
fn signer_unique_id(&self) -> PyResult<String> {
Ok(self.signer_unique_id.clone())
}

#[getter]
fn date_signed<'py>(&self, py: Python<'py>) -> PyResult<Option<Bound<'py, PyDateTime>>> {
to_py_datetime_option(py, &self.date_signed)
}
}
Loading