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

Partial #169 - MongoDB EventStore onAfterCommit hook #170

Merged
merged 3 commits into from
Jan 10, 2025

Conversation

alex-laycalvert
Copy link
Collaborator

@alex-laycalvert alex-laycalvert commented Jan 9, 2025

Description

  • Adds a basic onAfterCommit hook to the MongoDBEventStore options modeled after the in-memory event store
  • Adds same test suite for the inMemoryEventStore.onAfterCommit test
  • Adjusts the typing of EventStoreReadEventMetadata to allow for an undefined GlobalPosition. Without this change, attempting to pass the events to tryPublishMessagesAfterCommit gave a TS error because the events didn't have a global position, even though we didn't need one for mongodb

TODO

  • Tests

Relates to #169

@alex-laycalvert alex-laycalvert self-assigned this Jan 9, 2025
@alex-laycalvert
Copy link
Collaborator Author

alex-laycalvert commented Jan 9, 2025

@oskardudycz the change to the metadata typing is now giving an error for the in memeory event store, I'll check it out and if it gets too complicated I can just typecast the usage in mongodb

Ended up just throwing an expect error declaration on it to prevent other build errors in emmet

@@ -388,6 +393,15 @@ class MongoDBEventStoreImplementation implements MongoDBEventStore, Closeable {
);
}

await tryPublishMessagesAfterCommit<MongoDBEventStore>(
// @ts-expect-error Issues with `globalPosition` not being present causing the type for metadata to expect `never`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alex-laycalvert, that's weird; I noticed that TS got crazy on my other computer, but when I reinstalled fresh packages, then it worked fine. I'm not sure if that's the same issue, but I'll check the typing after the merge 👍

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't know for sure but I wonder if it has to do with the infer GV usage not working if global position is not on the type itself, even if we allow undefined.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, because technically, it's not undefined but optional. TypeScript is treating those cases differently. I'll have a look, it might be that I messed something out.

Copy link
Collaborator

@oskardudycz oskardudycz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alex-laycalvert looks good to me, thank you!

@oskardudycz oskardudycz added this to the 0.24.0 milestone Jan 10, 2025
@oskardudycz oskardudycz merged commit af8d86d into main Jan 10, 2025
3 checks passed
@oskardudycz oskardudycz deleted the feature/#169/mongodb-eventstore-async-sub-1 branch January 10, 2025 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants