-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from mizrael/event-id
updated event id generation
- Loading branch information
Showing
62 changed files
with
884 additions
and
688 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
|
@@ -6,6 +6,6 @@ | |
} | ||
}, | ||
"ConnectionStrings": { | ||
"evenire": "http://localhost:5001" | ||
"evenire": "http://localhost:5243" | ||
} | ||
} |
This file contains 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 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 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 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,38 +1,12 @@ | ||
using EvenireDB.Common; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace EvenireDB.Client | ||
namespace EvenireDB.Client | ||
{ | ||
public record Event | ||
public record Event : EventData | ||
{ | ||
public Event(Guid id, string type, ReadOnlyMemory<byte> data) | ||
public Event(EventId id, string type, ReadOnlyMemory<byte> data) : base(type, data) | ||
{ | ||
if (string.IsNullOrWhiteSpace(type)) | ||
throw new ArgumentException($"'{nameof(type)}' cannot be null or whitespace.", nameof(type)); | ||
|
||
if (type.Length > Constants.MAX_EVENT_TYPE_LENGTH) | ||
throw new ArgumentOutOfRangeException($"event type cannot be longer than {Constants.MAX_EVENT_TYPE_LENGTH} characters.", nameof(type)); | ||
|
||
Id = id; | ||
Type = type; | ||
|
||
if (data.Length == 0) | ||
throw new ArgumentNullException(nameof(data)); | ||
Data = data; | ||
Id = id ?? throw new ArgumentNullException(nameof(id)); | ||
} | ||
|
||
public Guid Id { get; } | ||
public string Type { get; } | ||
|
||
public ReadOnlyMemory<byte> Data { get; } | ||
|
||
public static Event Create<T>(T payload, string type = "") | ||
{ | ||
if (string.IsNullOrWhiteSpace(type)) | ||
type = typeof(T).Name; | ||
var bytes = JsonSerializer.SerializeToUtf8Bytes<T>(payload); | ||
return new Event(Guid.NewGuid(), type, bytes); | ||
} | ||
public EventId Id { get; } | ||
} | ||
} |
This file contains 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,35 @@ | ||
using EvenireDB.Common; | ||
using System.Text.Json; | ||
|
||
namespace EvenireDB.Client | ||
{ | ||
public record EventData | ||
{ | ||
public EventData(string type, ReadOnlyMemory<byte> data) | ||
{ | ||
if (string.IsNullOrWhiteSpace(type)) | ||
throw new ArgumentException($"'{nameof(type)}' cannot be null or whitespace.", nameof(type)); | ||
|
||
if (type.Length > Constants.MAX_EVENT_TYPE_LENGTH) | ||
throw new ArgumentOutOfRangeException($"event type cannot be longer than {Constants.MAX_EVENT_TYPE_LENGTH} characters.", nameof(type)); | ||
|
||
Type = type; | ||
|
||
if (data.Length == 0) | ||
throw new ArgumentNullException(nameof(data)); | ||
Data = data; | ||
} | ||
|
||
public string Type { get; } | ||
|
||
public ReadOnlyMemory<byte> Data { get; } | ||
|
||
public static EventData Create<T>(T payload, string type = "") | ||
{ | ||
if (string.IsNullOrWhiteSpace(type)) | ||
type = typeof(T).Name; | ||
var bytes = JsonSerializer.SerializeToUtf8Bytes<T>(payload); | ||
return new EventData(type, bytes); | ||
} | ||
} | ||
} |
This file contains 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,4 @@ | ||
namespace EvenireDB.Client | ||
{ | ||
public record EventId(long Timestamp, int Sequence); | ||
} |
This file contains 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 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 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 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,8 +1,8 @@ | ||
namespace EvenireDB.Server.DTO | ||
{ | ||
public record EventDTO(Guid Id, string Type, ReadOnlyMemory<byte> Data) | ||
public record EventDTO(EventIdDTO Id, string Type, ReadOnlyMemory<byte> Data) | ||
{ | ||
public static EventDTO FromModel(IEvent @event) | ||
=> new EventDTO(@event.Id, @event.Type, @event.Data); | ||
public static EventDTO FromModel(Event @event) | ||
=> new EventDTO(EventIdDTO.FromModel(@event.Id), @event.Type, @event.Data); | ||
} | ||
} |
This file contains 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,4 @@ | ||
namespace EvenireDB.Server.DTO | ||
{ | ||
public record EventDataDTO(string Type, ReadOnlyMemory<byte> Data); | ||
} |
This file contains 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,11 @@ | ||
namespace EvenireDB.Server.DTO | ||
{ | ||
public record EventIdDTO(long Timestamp, int Sequence) | ||
{ | ||
public static EventIdDTO FromModel(EventId eventId) | ||
=> new EventIdDTO(eventId.Timestamp, eventId.Sequence); | ||
|
||
public EventId ToModel() | ||
=> new EventId(this.Timestamp, this.Sequence); | ||
} | ||
} |
This file contains 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
Oops, something went wrong.