-
Notifications
You must be signed in to change notification settings - Fork 1
feat(client): add writing events to client adhering to the "Writing Events" compliance criteria #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
11b4dc5
feat(client): add writing events to client adhering to the "Writing E…
Snapstromegon ce372f7
feat(client): rework write events based on forward looking learnings …
Snapstromegon 2b3253b
chore(client): restructure event module to avoid allowing clippy warn…
Snapstromegon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use reqwest::Method; | ||
|
||
use crate::{error::ClientError, event::ManagementEvent}; | ||
|
||
use super::{ClientRequest, OneShotRequest}; | ||
|
||
/// Ping the Database instance | ||
#[derive(Debug, Clone, Copy)] | ||
pub struct PingRequest; | ||
|
||
impl ClientRequest for PingRequest { | ||
const URL_PATH: &'static str = "/api/v1/ping"; | ||
const METHOD: Method = Method::GET; | ||
} | ||
|
||
impl OneShotRequest for PingRequest { | ||
type Response = ManagementEvent; | ||
|
||
fn validate_response(&self, response: &Self::Response) -> Result<(), ClientError> { | ||
(response.ty() == "io.eventsourcingdb.api.ping-received") | ||
.then_some(()) | ||
.ok_or(ClientError::PingFailed) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use reqwest::Method; | ||
|
||
use crate::{error::ClientError, event::ManagementEvent}; | ||
|
||
use super::{ClientRequest, OneShotRequest}; | ||
|
||
/// Verify the API token | ||
#[derive(Debug, Clone, Copy)] | ||
pub struct VerifyApiTokenRequest; | ||
|
||
impl ClientRequest for VerifyApiTokenRequest { | ||
const URL_PATH: &'static str = "/api/v1/verify-api-token"; | ||
const METHOD: Method = Method::POST; | ||
} | ||
|
||
impl OneShotRequest for VerifyApiTokenRequest { | ||
type Response = ManagementEvent; | ||
|
||
fn validate_response(&self, response: &Self::Response) -> Result<(), ClientError> { | ||
(response.ty() == "io.eventsourcingdb.api.api-token-verified") | ||
.then_some(()) | ||
.ok_or(ClientError::APITokenInvalid) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use super::{ClientRequest, OneShotRequest}; | ||
use crate::{ | ||
client::Precondition, | ||
error::ClientError, | ||
event::{Event, EventCandidate}, | ||
}; | ||
use reqwest::Method; | ||
use serde::Serialize; | ||
|
||
#[derive(Debug, Serialize)] | ||
pub struct WriteEventsRequest { | ||
pub events: Vec<EventCandidate>, | ||
pub preconditions: Vec<Precondition>, | ||
} | ||
|
||
impl ClientRequest for WriteEventsRequest { | ||
const URL_PATH: &'static str = "/api/v1/write-events"; | ||
const METHOD: Method = Method::POST; | ||
|
||
fn body(&self) -> Option<Result<impl Serialize, ClientError>> { | ||
Some(Ok(self)) | ||
} | ||
} | ||
impl OneShotRequest for WriteEventsRequest { | ||
type Response = Vec<Event>; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use serde::Serialize; | ||
|
||
/// Enum for different preconditions that can be used when writing events | ||
#[derive(Debug, Serialize)] | ||
#[serde(tag = "type", content = "payload")] | ||
pub enum Precondition { | ||
/// Check if the subject with the given path has no other events | ||
#[serde(rename = "isSubjectPristine")] | ||
IsSubjectPristine { | ||
/// The subject to check | ||
subject: String, | ||
}, | ||
/// Check if the subject with the given path has no other events | ||
#[serde(rename = "isSubjectOnEventId")] | ||
IsSubjectOnEventId { | ||
/// The subject to check | ||
subject: String, | ||
/// The event ID to check against | ||
#[serde(rename = "eventId")] | ||
event_id: String, | ||
}, | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,14 @@ | ||
//! This module holds all event types that are send between the client and the database. | ||
mod management_event; | ||
mod event_types; | ||
mod trace_info; | ||
|
||
pub use management_event::ManagementEvent; | ||
// Reexport relevant types to flatten the module graph for consumers and | ||
// keep private encapsulation of implementation details. | ||
pub use event_types::event::Event; | ||
pub use event_types::event_candidate::EventCandidate; | ||
pub use event_types::management_event::ManagementEvent; | ||
pub use trace_info::TraceInfo; | ||
|
||
#[cfg(feature="cloudevents")] | ||
use crate::error::EventError; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
//! This module holds all possible event types this sdk works with. | ||
pub mod event; | ||
pub mod event_candidate; | ||
pub mod management_event; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.