Skip to content

Commit

Permalink
Making append backwards compatible with earlier clients
Browse files Browse the repository at this point in the history
  • Loading branch information
einari committed Aug 28, 2023
1 parent 2d509fe commit 83e9db5
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Source/Kernel/Domain/EventSequences/AppendEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ public record AppendEvent(
EventSourceId EventSourceId,
EventType EventType,
JsonObject Content,
IEnumerable<Causation> Causation,
Identity CausedBy,
IEnumerable<Causation>? Causation,
Identity? CausedBy,
DateTimeOffset? ValidFrom);
4 changes: 2 additions & 2 deletions Source/Kernel/Domain/EventSequences/AppendManyEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ namespace Aksio.Cratis.Kernel.Domain.EventSequences;
public record AppendManyEvents(
EventSourceId EventSourceId,
IEnumerable<EventToAppend> Events,
IEnumerable<Causation> Causation,
Identity CausedBy);
IEnumerable<Causation>? Causation,
Identity? CausedBy);
12 changes: 9 additions & 3 deletions Source/Kernel/Domain/EventSequences/EventSequence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,17 @@ public async Task Append(
[FromRoute] TenantId tenantId,
[FromBody] AppendEvent eventToAppend)
{
var causation = eventToAppend.Causation ?? _causationManager.GetCurrentChain();
var causedBy = eventToAppend.CausedBy ?? _identityProvider.GetCurrent();

_executionContextManager.Establish(tenantId, _executionContextManager.Current.CorrelationId, microserviceId);
var eventSequence = GetEventSequence(microserviceId, eventSequenceId, tenantId);
await eventSequence.Append(
eventToAppend.EventSourceId,
eventToAppend.EventType,
eventToAppend.Content,
eventToAppend.Causation,
eventToAppend.CausedBy,
causation,
causedBy,
eventToAppend.ValidFrom);
}

Expand All @@ -93,10 +96,13 @@ public async Task AppendMany(
[FromRoute] TenantId tenantId,
[FromBody] AppendManyEvents eventsToAppend)
{
var causation = eventsToAppend.Causation ?? _causationManager.GetCurrentChain();
var causedBy = eventsToAppend.CausedBy ?? _identityProvider.GetCurrent();

_executionContextManager.Establish(tenantId, _executionContextManager.Current.CorrelationId, microserviceId);
var eventSequence = GetEventSequence(microserviceId, eventSequenceId, tenantId);
var events = eventsToAppend.Events.Select(_ => new Grains.EventSequences.EventToAppend(eventsToAppend.EventSourceId, _.EventType, _.Content, _.ValidFrom)).ToArray();
await eventSequence.AppendMany(events, eventsToAppend.Causation, eventsToAppend.CausedBy);
await eventSequence.AppendMany(events, causation, causedBy);
}

/// <summary>
Expand Down
8 changes: 4 additions & 4 deletions Source/Workbench/API/events/store/sequence/Append.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface IAppend {
eventSourceId?: string;
eventType?: EventType;
content?: any;
causation?: Causation[];
causation?: Causation;
causedBy?: Identity;
validFrom?: Date;
}
Expand Down Expand Up @@ -48,7 +48,7 @@ export class Append extends Command<IAppend> implements IAppend {
private _eventSourceId!: string;
private _eventType!: EventType;
private _content!: any;
private _causation!: Causation[];
private _causation!: Causation;
private _causedBy!: Identity;
private _validFrom!: Date;

Expand Down Expand Up @@ -126,11 +126,11 @@ export class Append extends Command<IAppend> implements IAppend {
this._content = value;
this.propertyChanged('content');
}
get causation(): Causation[] {
get causation(): Causation {
return this._causation;
}

set causation(value: Causation[]) {
set causation(value: Causation) {
this._causation = value;
this.propertyChanged('causation');
}
Expand Down
8 changes: 4 additions & 4 deletions Source/Workbench/API/events/store/sequence/AppendMany.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface IAppendMany {
tenantId?: string;
eventSourceId?: string;
events?: EventToAppend[];
causation?: Causation[];
causation?: Causation;
causedBy?: Identity;
}

Expand All @@ -43,7 +43,7 @@ export class AppendMany extends Command<IAppendMany> implements IAppendMany {
private _tenantId!: string;
private _eventSourceId!: string;
private _events!: EventToAppend[];
private _causation!: Causation[];
private _causation!: Causation;
private _causedBy!: Identity;

constructor() {
Expand Down Expand Up @@ -110,11 +110,11 @@ export class AppendMany extends Command<IAppendMany> implements IAppendMany {
this._events = value;
this.propertyChanged('events');
}
get causation(): Causation[] {
get causation(): Causation {
return this._causation;
}

set causation(value: Causation[]) {
set causation(value: Causation) {
this._causation = value;
this.propertyChanged('causation');
}
Expand Down

0 comments on commit 83e9db5

Please sign in to comment.