CommitMongoDBStorage

Hierarchy

  • CommitMongoDBStorage

Implements

Index

Methods

Methods

findById

findById(commitId: string): Promise‹Commit | undefined›

Implementation of CommitStorage

Returns commit by id from MongoDB collection.

Parameters:

NameTypeDescription
commitIdstringIdentifier of Commit.

Returns: Promise‹Commit | undefined›

Instance implementing Commit interface, else undefined.


findLastVersionById

findLastVersionById(eventSourceableId: string | Guid): Promise‹number | undefined›

Implementation of CommitStorage

Returns last version of commit by event sourceable's id from MongoDB collection.

async

Parameters:

NameTypeDescription
eventSourceableIdstring | GuidIdentifier as string or Guid instance.

Returns: Promise‹number | undefined›

Last commit version as number, else undefined.


findOneAndUpdate

findOneAndUpdate(filter?: FilterQuery‹any›, update?: UpdateQuery‹any›, options?: FindOneAndUpdateOption): Promise‹Commit | undefined›

Find one document and updates it on MongoDB collection.

async

Parameters:

NameTypeDescription
filter?FilterQuery‹any›The Filter used to select the document to update
update?UpdateQuery‹any›The update operations to be applied to the document
options?FindOneAndUpdateOptionOptional settings

Returns: Promise‹Commit | undefined›

Updated instance implementing Commit interface, else undefined.


flagAndResolveCommitAsTimeouted

flagAndResolveCommitAsTimeouted(commitId: string, appId: string, workerId: string, failedAt: Date): Promise‹Commit | undefined›

Implementation of CommitStorage

Flags commit as timeouted on MongoDB collection.

async

Parameters:

NameTypeDescription
commitIdstringIdentifier for Commit that should be locked.
appIdstringApplication identifer on which commit timeouted.
workerIdstringWorker identifer on which commit timeouted.
failedAtDateDate of commit processing timeout.

Returns: Promise‹Commit | undefined›

Instance implementing Commit interface, else undefined.


flagCommitAsFailed

flagCommitAsFailed(commitId: string, appId: string, workerId: string, failedAt: Date): Promise‹boolean›

Implementation of CommitStorage

Flags commit as failed on MongoDB collection.

async

throws {UpdatingCommitError} Thrown if update operation on MongoDB is not successful.

Parameters:

NameTypeDescription
commitIdstringIdentifier for Commit that should be locked.
appIdstringApplication identifer on which commit failed.
workerIdstringWorker identifer on which commit failed.
failedAtDateDate of commit processing fail.

Returns: Promise‹boolean›

Returns true if commit was flagged successfully, else false.


flagCommitAsPublished

flagCommitAsPublished(commitId: string, appId: string, workerId: string, publishedAt: Date): Promise‹boolean›

Implementation of CommitStorage

Flags commit as published on MongoDB collection.

async

throws {UpdatingCommitError} Thrown if update operation on MongoDB is not successful.

Parameters:

NameTypeDescription
commitIdstringIdentifier for Commit that should be locked.
appIdstringApplication identifer on which commit is published.
workerIdstringWorker identifer on which commit is published.
publishedAtDateDate of commit publication.

Returns: Promise‹boolean›

Returns true if commit was flagged successfully, else false.


generateId

generateId(): Promise‹string›

Implementation of CommitStorage

Generates commit's id.

Returns: Promise‹string›

Identifier for Commit compatible with MongoDB.


getAllCommits

getAllCommits(): Promise‹Commit[]›

Implementation of CommitStorage

Returns all commits from MongoDB collection.

async

Returns: Promise‹Commit[]›

List of instances implementing Commit interface.


getCommits

getCommits(eventSourceableId: string | Stringifiable, versionOffset: number): Promise‹Commit[]›

Implementation of CommitStorage

Returns commit from MongoDB collection if exists by event sourceable's id for specific version offset.

async

Parameters:

NameTypeDescription
eventSourceableIdstring | StringifiableIdentifier as string or Guid instance.
versionOffsetnumberVersion number from which version events should be returned.

Returns: Promise‹Commit[]›

List of instances implementing Commit interface.


hasBySourceId

hasBySourceId(eventSourceableId: string | Guid): Promise‹boolean›

Implementation of CommitStorage

Evaluates whether event sourceable with id already exists.

async

Parameters:

NameTypeDescription
eventSourceableIdstring | GuidIdentifier as string or Guid instance.

Returns: Promise‹boolean›

Returns true if event sourceable exists, else false.


lockCommit

lockCommit(commitId: string, appId: string, workerId: string, registeredAndNotReceivedYetFilter: Record‹string, any›): Promise‹Commit | undefined›

Implementation of CommitStorage

Locks(changes state to received) commit on MongoDB and publishes it through CommitPublisher

async

Parameters:

NameTypeDescription
commitIdstringIdentifier for Commit that should be locked.
appIdstringApplication identifer that is handling(locking) Commit.
workerIdstringWorker identifer that is handling(locking) Commit.
registeredAndNotReceivedYetFilterRecord‹string, any›Filter for MongoDB query argument which selects only commits that have not been yet received by current application.

Returns: Promise‹Commit | undefined›

Instance implementing Commit interface, else undefined.


save

save(commit: Commit): Promise‹string›

Implementation of CommitStorage

Adds commit to MongoDB collection.

async

throws {CommitConcurrencyError} Thrown if commit with same id already exists on MongoDB collection.

throws {AddingCommitFailedError} Thrown if commit with same id already exists on MongoDB collection.

Parameters:

NameTypeDescription
commitCommitInstance implementing Commit interface.

Returns: Promise‹string›

Identifier for document(as Commit's id) on MongoDB collection.