roadiejs-counter
v0.0.6
Published
Incrementing counters for RoadieJS
Downloads
5
Readme
roadiejs-counter
A plugin for RoadieJS
Provides API endpoints and data-tasks for auto-incrementing number sequences.
Contents
API
getCurrentAndIncrement
Returns the current value of the specified counter, and then increments it ready for the next request.
Request
GET /counters/:ns/:bp/:bv/:counterName
| Parameter | Notes
| ----- | ----
| counterName
| Name of the counter to get current value of and then increment
Response
Status 200
{
"value": 5
}
| Name | Notes
| ----- | ----
| value
| The integer value from the counter.
getCurrent
Returns the current value of the specified counter, without incrementing it.
Request
GET /counters/:ns/:bp/:bv/:counterName/current
| Parameter | Notes
| ----- | ----
| counterName
| Name of the counter to get the current value of
Response
Status 200
{
"value": 6
}
| Name | Notes
| ----- | ----
| value
| The integer value from the counter.
setCurrent
Sets the current value of the specified counter to the provided value.
Request
PUT /counters/:ns/:bp/:bv/:counterName/current
| Parameter | Notes
| ----- | ----
| counterName
| Name of the counter to set the value of
Body
{
nextValue: 5
}
| Name | Notes
| ----- | ----
| nextValue
| Required. The value to which the counter should be set (i.e. the next value a subsequent getCurrent
or getCurrentAndIncrement
will return).
Response
Status 200
deleteCounter
Deletes the specified counter (any subsequent calls refering to it will then cause errors).
Request
DELETE /counters/:ns/:bp/:bv/:counterName
| Parameter | Notes
| ----- | ----
| counterName
| Name of the counter to delete
Elements
counter
Registers a RoadieJS counter (useful for auto-incrementing ids - just like a database sequence).
Example
{
"element": "counter",
"id": "counterTest",
"config": {
"startWith": 10,
"incrementBy": 1
}
}
Config
| Name | Type | Notes
| ------------ | -------| -----------
| startWith
| number
| The first number out the counter (defaults to 1
if not supplied).
| incrementBy
| number
| How much to subsequently increase the counter by after the current value is returned (defaults to 1
if not supplied).
Activities
setValueFromCounter
Sets a value on the target activity to a counter's current value, and then increments.
Example
{
"element": "activity",
"id": "setEmployeeNumber",
"path": "employeeNumber",
"config": {
"activityType": "setValueFromCounter",
"config": {
"counterId": "employeeNumberCounter",
"targetActivityId": "createNewEmployeeUi",
"path": "employeeNumber"
}
}
}
Config
| Name | Type | Notes
| ------------ | -------| -----------
| counterId
| string
| Name of the counter that should provide the value.
| targetActivityId
| string
| Name of an activity in the current flow where the value should be set.
| path
| string
| A key name to store the counter's thay, will be set target activity's data
object.