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
Event source concept #62
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,9 +13,9 @@ export class PartitionedFilterResult { | |
/** | ||
* Initializes a new instance of {@link PartitionedFilterResult}. | ||
* @param {boolean} shouldInclude Tells whether or not the event should be included. | ||
* @param {PartitionId | Guid | string} partitionId Tells which partition the event should be partitioned into. | ||
* @param {PartitionId | string} partitionId Tells which partition the event should be partitioned into. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guid here |
||
*/ | ||
constructor(readonly shouldInclude: boolean, partitionId: PartitionId | Guid | string) { | ||
constructor(readonly shouldInclude: boolean, partitionId: PartitionId | string) { | ||
this.partitionId = PartitionId.from(partitionId); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,10 +9,10 @@ import { Guid } from '@dolittle/rudiments'; | |
* | ||
* @export | ||
* @class EventSourceId | ||
* @extends {ConceptAs<Guid, '@dolittle/sdk.events.EventSourceId'>} | ||
* @extends {ConceptAs<string, '@dolittle/sdk.events.EventSourceId'>} | ||
*/ | ||
export class EventSourceId extends ConceptAs<Guid, '@dolittle/sdk.events.EventSourceId'> { | ||
constructor(id: Guid) { | ||
export class EventSourceId extends ConceptAs<string, '@dolittle/sdk.events.EventSourceId'> { | ||
constructor(id: string) { | ||
super(id, '@dolittle/sdk.events.EventSourceId'); | ||
} | ||
|
||
|
@@ -21,7 +21,7 @@ export class EventSourceId extends ConceptAs<Guid, '@dolittle/sdk.events.EventSo | |
* @returns {EventSourceId} | ||
*/ | ||
static new(): EventSourceId { | ||
return new EventSourceId(Guid.create()); | ||
return new EventSourceId(Guid.create().toString()); | ||
} | ||
|
||
/** | ||
|
@@ -31,8 +31,8 @@ export class EventSourceId extends ConceptAs<Guid, '@dolittle/sdk.events.EventSo | |
* @param {EventSourceId | Guid | string)} id | ||
* @returns {EventSourceId} | ||
*/ | ||
static from(id: EventSourceId | Guid | string): EventSourceId { | ||
static from(id: EventSourceId | string): EventSourceId { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guid here |
||
if (id instanceof EventSourceId) return id; | ||
return new EventSourceId(Guid.as(id)); | ||
return new EventSourceId(id); | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,31 +58,31 @@ export class EventStore extends IEventStore { | |
} | ||
|
||
/** @inheritdoc */ | ||
commit(event: any, eventSourceId: EventSourceId | Guid | string, eventType?: EventType | EventTypeId | Guid | string, cancellation?: Cancellation): Promise<CommitEventsResult>; | ||
commit(event: any, eventSourceId: EventSourceId | string, eventType?: EventType | EventTypeId | Guid | string, cancellation?: Cancellation): Promise<CommitEventsResult>; | ||
commit(eventOrEvents: UncommittedEvent | UncommittedEvent[], cancellation?: Cancellation): Promise<CommitEventsResult>; | ||
commit(eventOrEvents: any, eventSourceIdOrCancellation?: EventSourceId | Guid | string | Cancellation, eventType?: EventType | EventTypeId | Guid | string, cancellation?: Cancellation): Promise<CommitEventsResult> { | ||
commit(eventOrEvents: any, eventSourceIdOrCancellation?: EventSourceId | string | Cancellation, eventType?: EventType | EventTypeId | Guid | string, cancellation?: Cancellation): Promise<CommitEventsResult> { | ||
Comment on lines
+61
to
+63
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guid here |
||
if (this.isUncommittedEventOrEvents(eventOrEvents)) { | ||
return this.commitInternal(this.asArray(eventOrEvents), eventSourceIdOrCancellation as Cancellation); | ||
} | ||
const eventSourceId = eventSourceIdOrCancellation as Guid | string; | ||
const eventSourceId = eventSourceIdOrCancellation as string; | ||
return this.commitInternal([this.toUncommittedEvent(eventOrEvents, eventSourceId, eventType, false)], cancellation); | ||
} | ||
|
||
/** @inheritdoc */ | ||
commitPublic(event: any, eventSourceId: EventSourceId | Guid | string, eventType?: EventType | EventTypeId | Guid | string, cancellation?: Cancellation): Promise<CommitEventsResult> { | ||
commitPublic(event: any, eventSourceId: EventSourceId | string, eventType?: EventType | EventTypeId | Guid | string, cancellation?: Cancellation): Promise<CommitEventsResult> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guid here |
||
const events: UncommittedEvent[] = [this.toUncommittedEvent(event, eventSourceId, eventType, true)]; | ||
return this.commitInternal(events, cancellation); | ||
} | ||
|
||
/** @inheritdoc */ | ||
/** @inheritdoc */ | ||
commitForAggregate(event: any, eventSourceId: EventSourceId | Guid | string, aggregateRootId: AggregateRootId, expectedAggregateRootVersion: AggregateRootVersion, eventType?: EventType | EventTypeId | Guid | string, cancellation?: Cancellation): Promise<CommitAggregateEventsResult>; | ||
commitForAggregate(event: any, eventSourceId: EventSourceId | string, aggregateRootId: AggregateRootId, expectedAggregateRootVersion: AggregateRootVersion, eventType?: EventType | EventTypeId | Guid | string, cancellation?: Cancellation): Promise<CommitAggregateEventsResult>; | ||
commitForAggregate(events: UncommittedAggregateEvents, cancellation?: Cancellation): Promise<CommitAggregateEventsResult>; | ||
commitForAggregate(eventOrEvents: any, eventSourceIdOrCancellation?: EventSourceId | Guid | string | Cancellation, aggregateRootId?: AggregateRootId, expectedAggregateRootVersion?: AggregateRootVersion, eventType?: EventType | EventTypeId | Guid | string, cancellation?: Cancellation): Promise<CommitAggregateEventsResult> { | ||
commitForAggregate(eventOrEvents: any, eventSourceIdOrCancellation?: EventSourceId | string | Cancellation, aggregateRootId?: AggregateRootId, expectedAggregateRootVersion?: AggregateRootVersion, eventType?: EventType | EventTypeId | Guid | string, cancellation?: Cancellation): Promise<CommitAggregateEventsResult> { | ||
Comment on lines
+79
to
+81
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guid here |
||
if (this.isUncommittedAggregateEvents(eventOrEvents)) { | ||
return this.commitAggregateInternal(eventOrEvents, eventSourceIdOrCancellation as Cancellation); | ||
} | ||
const eventSourceId = eventSourceIdOrCancellation as Guid | string; | ||
const eventSourceId = eventSourceIdOrCancellation as string; | ||
return this.commitAggregateInternal( | ||
UncommittedAggregateEvents.from( | ||
eventSourceId, | ||
|
@@ -107,7 +107,7 @@ export class EventStore extends IEventStore { | |
request.setCallcontext(callContexts.toProtobuf(this._executionContext)); | ||
const aggregate = new Aggregate(); | ||
aggregate.setAggregaterootid(guids.toProtobuf(aggregateRootId.value)); | ||
aggregate.setEventsourceid(guids.toProtobuf(eventSourceId.value)); | ||
aggregate.setEventsourceid(eventSourceId.value); | ||
request.setAggregate(aggregate); | ||
|
||
return reactiveUnary(this._eventStoreClient, this._eventStoreClient.fetchForAggregate, request, cancellation) | ||
|
@@ -161,7 +161,7 @@ export class EventStore extends IEventStore { | |
const pbEvents = new PbUncommittedAggregateEvents(); | ||
pbEvents.setEventsList(uncommittedAggregateEvents); | ||
pbEvents.setAggregaterootid(guids.toProtobuf(aggregateRootId.value)); | ||
pbEvents.setEventsourceid(guids.toProtobuf(events.eventSourceId.value)); | ||
pbEvents.setEventsourceid(events.eventSourceId.value); | ||
pbEvents.setExpectedaggregaterootversion(events.expectedAggregateRootVersion.value); | ||
request.setCallcontext(callContexts.toProtobuf(this._executionContext)); | ||
request.setEvents(pbEvents); | ||
|
@@ -193,7 +193,7 @@ export class EventStore extends IEventStore { | |
return new CommittedAggregateEvents(eventSourceId, aggregateRootId, ...convertedEvents); | ||
} | ||
|
||
private toUncommittedEvent(content: any, eventSourceId: EventSourceId | Guid | string, eventTypeOrId?: EventType | EventTypeId | Guid | string, isPublic = false): UncommittedEvent { | ||
private toUncommittedEvent(content: any, eventSourceId: EventSourceId | string, eventTypeOrId?: EventType | EventTypeId | Guid | string, isPublic = false): UncommittedEvent { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's bring the Guid conversions back until we get the poll data :) |
||
let eventType: EventType | EventTypeId | undefined; | ||
if (eventTypeOrId !== undefined) { | ||
if (eventTypeOrId instanceof EventType) eventType = eventTypeOrId; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guid here