outsidenote / eventualize

5 stars 0 forks source link

NJsonSchema, do we need it? #6

Closed bnayae closed 1 month ago

bnayae commented 11 months ago

If we do need it we have to setup an abstraction

bnaya-payoneer commented 11 months ago
using Generator.Equals;

namespace Eventualize.Core;

// TODO: Json data -> JsonElement if needed at all
[Equatable]
public partial record EventEntity (
                //string EventType,
                DateTime CapturedAt, 
                string CapturedBy, 
                DateTime? StoredAt)
{ 
}

[Equatable]
public partial record EventEntity<T> (
                //string EventType,
                DateTime CapturedAt, 
                string CapturedBy, 
                T JsonData, 
                DateTime? StoredAt): EventEntity(CapturedAt, CapturedBy, StoredAt)
{ 
}
outsidenote commented 11 months ago

I agree, we don't need to use JSONSchema in this case.

So if I understand correctly, of the event's payload will happen in the Repository, just before sending it to the SaveAsync() of IStoreAdapter? In that case, do we need to declare on a serialized event interface to be sent there?

[Equatable]
public partial record SearializedEventEntity (
                string EventType,
                DateTime CapturedAt, 
                string CapturedBy, 
                string JsonPayload,
                DateTime? StoredAt)
{
}

BTW, I'm fore adopting your terminology of EventEntity.Payload instead of EventEntity.JsonData.

outsidenote commented 11 months ago

Additional thoughts for the case where we use:

[Equatable]
public partial record EventEntity<T> (
                DateTime CapturedAt, 
                string CapturedBy, 
                T JsonData, 
                DateTime? StoredAt): EventEntity(CapturedAt, CapturedBy, StoredAt)
{ 
}

The EventType is basically now derived from T. It is important that T would have a human readable representation of the event type because it is something that should be known by product and potentially business and analytics stakeholders.

So maybe we should use:

interface IEventType
{
  public string GetHumanReadableName();
}

[Equatable]
public partial record EventEntity<IEventType> (
                DateTime CapturedAt, 
                string CapturedBy, 
                T JsonData, 
                DateTime? StoredAt): EventEntity(CapturedAt, CapturedBy, StoredAt)
{ 
}

And when the Repo serializes the event, then it also uses the human readable form of event type.

outsidenote commented 11 months ago

Another question (I separated the thoughts into different posts...): If now we have EventEntity<T> with generics. How do we represent a List of such events with different generic types?