This project enables generic invariant checking via two phase commit in event store
Run the container such that it can access your event store. Then you can write __InvariantCheckRequested
events to
the __async_invariant
stream.
example
import { EventStoreDBClient, jsonEvent, NO_STREAM } from '@eventstore/db-client'
const userId = uuid()
const eventId = uuid()
const invariantCheckRequested = {
type: '__InvariantCheckRequested',
id: eventId,
data: {
invariant: {
category: 'UserEmailReservation',
value: 'me@example.com',
type: 'unique',
entityId: userId,
},
resultingEvent: {
streamId: `User-${userId}`,
type: 'UserRegistered',
id: uuid(),
expectedRevision: NO_STREAM,
data: {
userId,
email: 'me@example.com',
name: 'Me Me',
},
},
},
metadata: {
$correlationId: eventId,
$causationId: eventId,
},
}
await client.appendToStream(
`__async_invariant`,
jsonEvent(invariantCheckRequested),
{
expectedRevision: ANY,
}
)
$ docker build -t invariant-checker:local .
$ docker run --rm -it \
-e ESDB_CONN_STRING="esdb://connectionstring" \
--name invariant-checker \
invariant-checker:local