Skip to content
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

Allow overriding commitVersion on single event commit #119

Merged
merged 1 commit into from
Jun 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/EventStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ class EventStore extends EventEmitter {
throw new OptimisticConcurrencyError(`Optimistic Concurrency error. Expected stream "${streamName}" at version ${expectedVersion} but is at version ${streamVersion}.`);
}

if (events.length > 1) {
delete metadata.commitVersion;
}

const commitId = this.length;
let commitVersion = 0;
const committedAt = Date.now();
Expand All @@ -216,7 +220,7 @@ class EventStore extends EventEmitter {
callback(commit);
};
for (let event of events) {
const eventMetadata = Object.assign({ commitId, committedAt }, metadata, { commitVersion, streamVersion });
const eventMetadata = Object.assign({ commitId, committedAt, commitVersion }, metadata, { streamVersion });
const storedEvent = { stream: streamName, payload: event, metadata: eventMetadata };
commitVersion++;
streamVersion++;
Expand Down
2 changes: 1 addition & 1 deletion src/EventStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class EventStream extends stream.Readable {
* Iterate over the events in this stream with a callback.
* This method is useful to gain access to the event metadata.
*
* @param {function(object, Object, string)} callback A callback function that will receive the event, the storage metadata and the original stream name for every event in this stream.
* @param {function(object, object, string)} callback A callback function that will receive the event, the storage metadata and the original stream name for every event in this stream.
*/
forEach(callback) {
let next;
Expand Down