-
Notifications
You must be signed in to change notification settings - Fork 2
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
Conversation
04159f3
to
74885dc
Compare
Codecov ReportAttention: Patch coverage is
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. |
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 |
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.
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>; |
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.
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> |
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.
create another class
status: 'scheduled' | 'processing' | 'published'; | ||
publishedAt?: Date; | ||
contextName?: string; | ||
locked?: boolean; |
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.
to remove
locked?: boolean; | ||
}; | ||
|
||
export class MongoOutbox implements IOutbox { |
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.
add init interface
return Object.values(insertedIds).map((id) => id.toString()); | ||
} | ||
|
||
public async publishEvents(eventIds: string[]): Promise<void> { |
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.
better name?
74885dc
to
8479ac9
Compare
Repo with Outbox has a dedicated class that extends base MongoAggregateRepo class |
cb8930d
to
fd4bb78
Compare
0276534
to
c48497c
Compare
No description provided.