Skip to content

Commit

Permalink
feat: add direnv for local dev (#262)
Browse files Browse the repository at this point in the history
* feat: add direnv config for local dev

* chore: run cargo fmt with new rustfmt config
  • Loading branch information
ar3s3ru authored Nov 12, 2023
1 parent 7c4cfb8 commit bada1c3
Show file tree
Hide file tree
Showing 28 changed files with 233 additions and 130 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
**/*.rs.bk
Cargo.lock
lcov.info

.direnv
2 changes: 0 additions & 2 deletions .gitpod.yml

This file was deleted.

1 change: 0 additions & 1 deletion .rustfmt.toml

This file was deleted.

13 changes: 5 additions & 8 deletions eventually-postgres/src/aggregate.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
use std::marker::PhantomData;

use async_trait::async_trait;
use eventually::{
aggregate,
aggregate::Aggregate,
serde::{Deserializer, Serde, Serializer},
version,
version::Version,
};
use eventually::aggregate::Aggregate;
use eventually::serde::{Deserializer, Serde, Serializer};
use eventually::version::Version;
use eventually::{aggregate, version};
use sqlx::{PgPool, Postgres, Row};

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -131,7 +128,7 @@ where
expected: expected_version,
actual: root.version(),
})
}
},
_ => SaveError::SaveAggregateState(err),
},
})?;
Expand Down
29 changes: 13 additions & 16 deletions eventually-postgres/src/event.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
use std::{marker::PhantomData, string::ToString};
use std::marker::PhantomData;
use std::string::ToString;

use async_trait::async_trait;
use chrono::Utc;
use eventually::{
event,
message::{Message, Metadata},
serde::{Deserializer, Serde, Serializer},
version,
version::Version,
};
use futures::{future::ready, StreamExt, TryStreamExt};
use eventually::message::{Message, Metadata};
use eventually::serde::{Deserializer, Serde, Serializer};
use eventually::version::Version;
use eventually::{event, version};
use futures::future::ready;
use futures::{StreamExt, TryStreamExt};
use lazy_static::lazy_static;
use regex::Regex;
use sqlx::{
postgres::{PgDatabaseError, PgRow},
PgPool, Postgres, Row, Transaction,
};
use sqlx::postgres::{PgDatabaseError, PgRow};
use sqlx::{PgPool, Postgres, Row, Transaction};

#[derive(Debug, thiserror::Error)]
pub enum StreamError {
Expand Down Expand Up @@ -285,7 +282,7 @@ where
.fetch_one(&mut tx)
.await
.and_then(|row| row.try_get(0))?
}
},
event::StreamVersionExpected::MustBe(v) => {
let new_version = v + (events.len() as Version);

Expand All @@ -303,12 +300,12 @@ where
expected: v,
actual: new_version,
})
}
},
_ => AppendError::UpsertEventStream(err),
},
})
.map(|_| new_version as i32)?
}
},
};

append_domain_events(&mut tx, &self.serde, &string_id, new_version, events)
Expand Down
8 changes: 3 additions & 5 deletions eventually-postgres/tests/aggregate_repository.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use eventually::{
aggregate::repository::{GetError, Getter, Saver},
serde::json::Json,
version,
};
use eventually::aggregate::repository::{GetError, Getter, Saver};
use eventually::serde::json::Json;
use eventually::version;
use eventually_postgres::aggregate;
use futures::TryFutureExt;
use rand::Rng;
Expand Down
12 changes: 5 additions & 7 deletions eventually-postgres/tests/event_store.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use std::time::{SystemTime, UNIX_EPOCH};

use eventually::{
event::{Appender, Persisted, StreamVersionExpected, Streamer, VersionSelect},
serde::json::Json,
version,
version::Version,
};
use eventually::event::{Appender, Persisted, StreamVersionExpected, Streamer, VersionSelect};
use eventually::serde::json::Json;
use eventually::version;
use eventually::version::Version;
use eventually_postgres::event;
use futures::{TryFutureExt, TryStreamExt};
use rand::Rng;
Expand Down Expand Up @@ -187,7 +185,7 @@ async fn it_handles_concurrent_writes_to_the_same_stream() {
} else {
panic!("unexpected error, {:?}", err);
}
}
},
(first, second) => panic!(
"invalid state detected, first: {:?}, second: {:?}",
first, second
Expand Down
12 changes: 6 additions & 6 deletions eventually-postgres/tests/setup/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::{
fmt::{Display, Formatter, Result as FmtResult},
time::{SystemTime, UNIX_EPOCH},
};
use std::fmt::{Display, Formatter, Result as FmtResult};
use std::time::{SystemTime, UNIX_EPOCH};

use eventually::{aggregate, aggregate::Aggregate, message::Message};
use eventually::aggregate;
use eventually::aggregate::Aggregate;
use eventually::message::Message;
use eventually_macros::aggregate_root;
use serde::{Deserialize, Serialize};
use sqlx::PgPool;
Expand Down Expand Up @@ -83,7 +83,7 @@ impl Aggregate for TestAggregate {
(Some(mut a), TestDomainEvent::WasDeleted { .. }) => {
a.is_deleted = true;
Ok(a)
}
},
(None, TestDomainEvent::WasDeleted { .. }) => Err(TestAggregateError::NotCreatedYet),
}
}
Expand Down
17 changes: 7 additions & 10 deletions eventually/src/aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
//! Aggregates should provide a way to **fold** Domain Events on the
//! current value of the state, to produce the next state.
use crate::{event, message, version::Version};
use crate::version::Version;
use crate::{event, message};

pub mod repository;

Expand Down Expand Up @@ -347,7 +348,7 @@ pub(crate) mod test_user_domain {
UserEvent::PasswordWasChanged { password } => {
state.password = password;
Ok(state)
}
},
UserEvent::WasCreated { .. } => Err(UserError::AlreadyCreated),
},
}
Expand Down Expand Up @@ -386,14 +387,10 @@ pub(crate) mod test_user_domain {
mod test {
use std::error::Error;

use crate::{
aggregate,
aggregate::repository::{Getter, Saver},
aggregate::test_user_domain::{User, UserEvent},
event,
event::store::EventStoreExt,
version,
};
use crate::aggregate::repository::{Getter, Saver};
use crate::aggregate::test_user_domain::{User, UserEvent};
use crate::event::store::EventStoreExt;
use crate::{aggregate, event, version};

#[tokio::test]
async fn repository_persists_new_aggregate_root() {
Expand Down
7 changes: 5 additions & 2 deletions eventually/src/aggregate/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
//! If you are looking for the Event-sourced implementation of an Aggregate Repository,
//! take a look at [EventSourced].
use std::{fmt::Debug, marker::PhantomData};
use std::fmt::Debug;
use std::marker::PhantomData;

use async_trait::async_trait;
use futures::TryStreamExt;

use crate::{aggregate, aggregate::Aggregate, event, version::Version};
use crate::aggregate::Aggregate;
use crate::version::Version;
use crate::{aggregate, event};

/// Error returned by a call to [`Repository::get`].
/// This type is used to check whether an Aggregate Root has been found or not.
Expand Down
7 changes: 2 additions & 5 deletions eventually/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,8 @@ where
mod test_user_domain {
use async_trait::async_trait;

use crate::{
aggregate,
aggregate::test_user_domain::{User, UserEvent},
command, event, message,
};
use crate::aggregate::test_user_domain::{User, UserEvent};
use crate::{aggregate, command, event, message};

struct CreateUser {
email: String,
Expand Down
9 changes: 6 additions & 3 deletions eventually/src/command/test.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
//! Module exposing a test [Scenario] type to write Domain [Command]s
//! test cases using the [given-then-when canvas](https://www.agilealliance.org/glossary/gwt/).
use std::{fmt::Debug, hash::Hash};
use std::fmt::Debug;
use std::hash::Hash;

use crate::{command, event, event::store::EventStoreExt, event::Appender, message};
use crate::event::store::EventStoreExt;
use crate::event::Appender;
use crate::{command, event, message};

/// A test scenario that can be used to test a [Command] [Handler][command::Handler]
/// using a [given-then-when canvas](https://www.agilealliance.org/glossary/gwt/) approach.
Expand Down Expand Up @@ -159,7 +162,7 @@ where
ScenarioThenCase::Produces(events) => {
let recorded_events = tracking_event_store.recorded_events();
assert_eq!(events, recorded_events);
}
},
ScenarioThenCase::Fails => assert!(result.is_err()),
};
}
Expand Down
6 changes: 2 additions & 4 deletions eventually/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ use async_trait::async_trait;
use futures::stream::BoxStream;
use serde::{Deserialize, Serialize};

use crate::{
message,
version::{ConflictError, Version},
};
use crate::message;
use crate::version::{ConflictError, Version};

pub mod store;

Expand Down
26 changes: 10 additions & 16 deletions eventually/src/event/store.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
//! Contains implementations of the [event::Store] trait and connected abstractions,
//! such as the [std::collections::HashMap]'s based [InMemory] Event Store implementation.
use std::{
collections::HashMap,
convert::Infallible,
hash::Hash,
sync::{Arc, RwLock},
};
use std::collections::HashMap;
use std::convert::Infallible;
use std::hash::Hash;
use std::sync::{Arc, RwLock};

use async_trait::async_trait;
use futures::stream::{iter, StreamExt};

use crate::{
event, message,
version::{ConflictError, Version},
};
use crate::version::{ConflictError, Version};
use crate::{event, message};

#[derive(Debug)]
struct InMemoryBackend<Id, Evt>
Expand Down Expand Up @@ -276,12 +272,10 @@ mod test {
use futures::TryStreamExt;

use super::*;
use crate::{
event,
event::{Appender, Streamer},
message::tests::StringMessage,
version::Version,
};
use crate::event;
use crate::event::{Appender, Streamer};
use crate::message::tests::StringMessage;
use crate::version::Version;

#[tokio::test]
async fn it_works() {
Expand Down
3 changes: 2 additions & 1 deletion eventually/src/serde/prost.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::marker::PhantomData;

use prost::{bytes::Bytes, Message};
use prost::bytes::Bytes;
use prost::Message;

use crate::serde::{Deserializer, Serializer};

Expand Down
10 changes: 5 additions & 5 deletions eventually/src/tracing.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
//! Module containing some extension traits to support code instrumentation
//! using the `tracing` crate.
use std::{
fmt::{Debug, Display},
marker::PhantomData,
};
use std::fmt::{Debug, Display};
use std::marker::PhantomData;

use async_trait::async_trait;
use tracing::instrument;

use crate::{aggregate, aggregate::Aggregate, event, message, version::Version};
use crate::aggregate::Aggregate;
use crate::version::Version;
use crate::{aggregate, event, message};

/// [aggregate::Repository] type wrapper that provides instrumentation
/// features through the `tracing` crate.
Expand Down
3 changes: 2 additions & 1 deletion examples/bank-accounting/build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::{env, path::PathBuf};
use std::env;
use std::path::PathBuf;

fn main() {
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
Expand Down
6 changes: 2 additions & 4 deletions examples/bank-accounting/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,8 @@ mod test {
use eventually::{command, event};
use rust_decimal::Decimal;

use crate::{
application,
domain::{BankAccountEvent, BankAccountRepository, Transaction},
};
use crate::application;
use crate::domain::{BankAccountEvent, BankAccountRepository, Transaction};

#[tokio::test]
async fn open_bank_account_works_when_bank_account_has_just_been_opened_for_the_first_time() {
Expand Down
Loading

0 comments on commit bada1c3

Please sign in to comment.