MESG-js v1.4.0
A new version of the mesg-js
library has been released: v1.4.0
.
This version brings exciting new features to application developers, such as:
- Filtering data
- Execution tags
Filtering data
It’s now possible to filter any data being listened to from events and results.
This enables a more customized and granular flow in your applications.
whenEvent
MESG.whenEvent({
serviceID: 'xxx',
eventKey: 'xxx',
filter: function (eventKey, eventData) {
// Filter here is based on the eventKey (string)
// or the eventData (object) containing all the event's data
return true
}
}, taskDefinition)
whenResult
MESG.whenResult({
serviceID: 'xxx',
outputKey: 'xxx',
filter: function (outputKey, outputData, taskKey, tags) {
// Filter here is based
// on the result's outputKey (string)
// or the result's outputData (object) containing all the data from the result
// or the result's taskKey (string)
// or the result's tags ([]string) containing the execution's tags
returns true
}
}, taskDefinition)
You may notice the introduction of execution tags, keep reading for more info
Execution tags
A task’s executions can now accept tags.
You can attribute a list of tags to the task executions, then create task’s result filter based on them.
The tags system is powerful and customizable, as tags are not passed onto services.
You can create your own business-oriented logic without having to stick with the services’ logic.
Tags can help you to:
- categorize a task’s executions
- add metadata to executions
- filter based on data which is not related to the task’s input and output data
There are two different ways to attribute tags to task’s executions:
Static definition
MESG.whenEvent(eventDefinition, {
serviceID: 'yyy',
taskKey: 'yyy',
inputs: { foo: 'bar' },
tags: [
'metaX',
'metricsA',
...
]
})
Dynamic definition
whenEvent
MESG.whenEvent(eventDefinition, {
serviceID: 'yyy',
taskKey: 'yyy',
inputs: { foo: 'bar' },
tags: function (eventKey, eventData) {
// Create the tags ([]string) here based
// on the eventKey (string)
// or the eventData (object) that contains all the event's data
return [
eventKey,
eventData.foo
]
}
})
whenResult
MESG.whenResult(resultDefinition, {
serviceID: 'yyy',
taskKey: 'yyy',
inputs: { foo: 'bar' },
tags: function (outputKey, outputData, taskKey, tags) {
// Create the tags ([]string) here based
// on the result's outputKey (string)
// or the result's outputData (object) containing all the data from the result
// or the result's taskKey (string)
// or the result's tags ([]string)
return [
outputKey,
outputData.foo,
taskKey,
tags.foo
]
}
})