@removeOn
A projection definition can have zero, one or multiple @removeOn
type directives.
Example
In the following case the removeUser
event will remove data identified by the value of its id
payload field from the projection.
type User
@upsertOn(...)
@removeOn(
on: {
topic: "userManagement"
eventTypes: ["removeUser"]
}
identifyBy: { payload: ["id"] }
) {
// ...
}
Arguments
You can use the following arguments on the @removeOn
directive directly:
Argument | Description |
---|---|
on | restrict deletions of the projection |
identifyBy | specify how the identifier of the data is generated |
filterBy | delete entries from the projection by a filter |
The arguments and their respective attributes are described in the following sections.
Argument on
The on
argument restricts deletions of the projection to specific events.
You can use eventTypes
or topic
to filter the events.
Argument | Description |
---|---|
eventTypes | restrict deletions to the projection to a list of event types |
topic | restrict deletions to the projection to a topic string |
Argument identifyBy
The identifier can consist of one or more elements taken from the event attributes or event payload.
These elements will be concatenated into a string where the elements are separated by a -
character.
Argument | Description |
---|---|
attributes | specify a list of attributes that are part of the identifier |
payload | specify a list of event payload fields that are part of the identifier |
When using both attributes and payload, the attributes will be listed first in the identifier, followed by the payload fields. See the example below for clarification.
The @removeOn
directive in the following example will delete all events on an event type called removeUser
.
Every ID in this example starts with the prefix stream-
and is followed by a value from the payload.
Assuming the payload is {"id": "uuid"}
, the ID of the deleted field will be stream-uuid
.
@removeOn(
on: {
topic: "userManagement"
eventTypes: ["removeUser"]
}
identifyBy: { attributes: ["stream"], payload: ["id"] }
)
Available Event Attributes
The events to trigger a deletion can be filtered using the following attributes:
Attribute | Description |
---|---|
id | the identifier of the event |
tenantId | the identifier of the tenant |
topic | the topic to which the event was published to |
type | name of the event type |
stream | name of the used stream |
correlationId | correlation identifier |
causationId | causation identifier |
reason | the reason why the event was published |
Argument filterBy
Alternative to the identifyBy
argument, you can use the filterBy
argument to specify a filter that determines which data should be removed from the projection.
type User
@removeOn(
on: {
topic: "userManagement"
eventTypes: ["removeUser"]
}
filterBy: { fields: [{
projectionField: "name"
operation: "equals"
type: "String"
eventField: "userName"
}] }
){
// ...
}
This example shows how to use the filterBy
argument to remove data from the projection based on a filter.
In this case, the removeUser
event will remove data from the projection if the name
field of the projection matches the userName
field of the event.
Types and operations
Type | Allowed operations |
---|---|
ID | equals , notEquals , in , notIn |
[ID] | inArray , notInArray , lengthEq , lengthNotEq , lengthGt , lengthGtOrEq , lengthLt , lengthLtOrEq , empty , notEmpty |
String | equals , notEquals , equalsCaseInsensitive , notEqualsCaseInsensitive , in , notIn , contains , notContains , containsCaseInsensitive , notContainsCaseInsensitive |
[String] | inArray , notInArray , lengthEq , lengthNotEq , lengthGt , lengthGtOrEq , lengthLt , lengthLtOrEq , empty , notEmpty |
File | equals , notEquals , in , notIn |
DateTime | equals , notEquals , in , notIn , before ,beforeOrAt ,after ,atOrAfter |
[DateTime] | inArray , notInArray , lengthEq , lengthNotEq , lengthGt , lengthGtOrEq , lengthLt , lengthLtOrEq , empty , notEmpty |
Int | equals , notEquals , lessThan , lessThanOrEqual , greaterThan , greaterThanOrEqual |
[Int] | inArray , notInArray , lengthEq , lengthNotEq , lengthGt , lengthGtOrEq , lengthLt , lengthLtOrEq , empty , notEmpty |
Float | equals , notEquals , lessThan , lessThanOrEqual , greaterThan , greaterThanOrEqual |
[Float] | inArray , notInArray , lengthEq , lengthNotEq , lengthGt , lengthGtOrEq , lengthLt , lengthLtOrEq , empty , notEmpty |
Boolean | equals , notEquals |
The in
and notIn
filters require an array as value.
The inArray
and notInArray
filters allow arrays or single values.