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

Transactional outbox #32

Merged
merged 11 commits into from
Apr 3, 2024
Merged

Transactional outbox #32

merged 11 commits into from
Apr 3, 2024

Conversation

gtoselli
Copy link
Contributor

No description provided.

@gtoselli gtoselli linked an issue Mar 30, 2024 that may be closed by this pull request
@gtoselli gtoselli force-pushed the 4-simple-transactional-outbox branch from 04159f3 to 74885dc Compare March 30, 2024 19:01
Copy link

codecov bot commented Mar 30, 2024

Codecov Report

Attention: Patch coverage is 91.22807% with 10 lines in your changes are missing coverage. Please review.

Project coverage is 84.01%. Comparing base (ed552f8) to head (43c3f75).

❗ Current head 43c3f75 differs from pull request most recent head a32b38a. Consider uploading reports for the commit a32b38a to get more accurate results

Files Patch % Lines
packages/ddd-toolkit/src/outbox/mongo-outbox.ts 94.11% 4 Missing ⚠️
...kages/ddd-toolkit/src/repo/mongo-aggregate-repo.ts 85.18% 4 Missing ⚠️
packages/ddd-toolkit/src/index.ts 0.00% 1 Missing ⚠️
...olkit/src/repo/mongo-aggregate-repo-with-outbox.ts 94.44% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #32      +/-   ##
==========================================
+ Coverage   81.34%   84.01%   +2.66%     
==========================================
  Files          15       16       +1     
  Lines         252      319      +67     
  Branches       47       51       +4     
==========================================
+ Hits          205      268      +63     
- Misses         47       51       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@gtoselli gtoselli self-assigned this Mar 30, 2024
import { ISerializer } from './serializer.interface';
import { merge } from 'lodash';
import { DuplicatedIdError, OptimisticLockError, RepoHookError } from '../errors';
import { ILogger } from '../logger';
import { IInit } from '../init.interface';
import { IEvent } from '../event-bus/event-bus.interface';
import { IOutbox } from '../outbox/outbox.interface';

export interface IAggregateRepo<A> {
// TODO add id as a generic type
Copy link
Contributor Author

Choose a reason for hiding this comment

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

remove this line


export interface IAggregateRepo<A> {
// TODO add id as a generic type
getById: (id: string) => Promise<WithVersion<A> | null>;
save: (aggregate: A) => Promise<void>;
}

export interface IAggregateRepoWithOutbox<A> extends IAggregateRepo<A> {
saveAndPublish: (aggregate: A, eventsToBePublished?: IEvent<unknown>[]) => Promise<void>;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

rename in eventsToPublish

@@ -21,15 +27,19 @@ type WithOptionalVersion<T> = T & { __version?: number };
// TODO probably we should create a dedicated interface whit like DocumentWithIdAndTimestamps
const MONGODB_UNIQUE_INDEX_CONSTRAINT_ERROR = 11000;

export class MongoAggregateRepo<A, AM extends DocumentWithId> implements IAggregateRepo<A>, IInit {
export class MongoAggregateRepo<A, AM extends DocumentWithId>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

create another class

status: 'scheduled' | 'processing' | 'published';
publishedAt?: Date;
contextName?: string;
locked?: boolean;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

to remove

locked?: boolean;
};

export class MongoOutbox implements IOutbox {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

add init interface

return Object.values(insertedIds).map((id) => id.toString());
}

public async publishEvents(eventIds: string[]): Promise<void> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

better name?

@lucagiove lucagiove force-pushed the 4-simple-transactional-outbox branch from 74885dc to 8479ac9 Compare April 3, 2024 17:16
@lucagiove
Copy link
Contributor

Repo with Outbox has a dedicated class that extends base MongoAggregateRepo class

@gtoselli gtoselli force-pushed the 4-simple-transactional-outbox branch from cb8930d to fd4bb78 Compare April 3, 2024 19:55
@gtoselli gtoselli force-pushed the 4-simple-transactional-outbox branch from 0276534 to c48497c Compare April 3, 2024 20:09
@lucagiove lucagiove merged commit 924e5c0 into main Apr 3, 2024
9 checks passed
@lucagiove lucagiove deleted the 4-simple-transactional-outbox branch April 3, 2024 23:45
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.

Simple transactional outbox
2 participants