# roadiejs-counter

> Incrementing counters for RoadieJS

Latest version **0.0.6** (published 2015-07-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install roadiejs-counter
pnpm add roadiejs-counter
yarn add roadiejs-counter
bun add roadiejs-counter
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.6 |
| Published | 2015-07-22 |
| First published | 2015-02-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| Author | Tim Needham |
| Maintainers | timneedham |
| Keywords | roadieJS, counter, nextval |

## Links

- npm: https://www.npmjs.com/package/roadiejs-counter
- Repository: https://github.com/wmfs/roadiejs-counter
- Homepage: https://github.com/wmfs/roadiejs-counter#readme
- Issues: https://github.com/wmfs/roadiejs-counter/issues
- npm.io page: https://npm.io/package/roadiejs-counter

## Dependencies (1)

- [underscore](https://npm.io/package/underscore.md) ~1.5.2

## Recent versions

- 0.0.6 (latest) — 2015-07-22
- 0.0.5 — 2015-06-18
- 0.0.4 — 2015-04-25
- 0.0.3 — 2015-02-07
- 0.0.2 — 2015-02-07
- 0.0.1 — 2015-02-06

## README

# roadiejs-counter
##### A plugin for [RoadieJS](https://github.com/wmfs/roadiejs)
Provides API endpoints and data-tasks for auto-incrementing number sequences.

## Contents
* [API](#api)
  * [getCurrentAndIncrement](#getCurrentAndIncrement)
  * [getCurrent](#getCurrent)
  * [setCurrent](#setCurrent)
  * [deleteCounter](#deleteCounter)
* [Elements](#elements)
  * [counter](#counter)
* [Activities](#activities)
  * [setValueFromCounter](#setValueFromCounter)
* [License](#license)

## <a name="api"></a>API

### <a name="getCurrentAndIncrement"></a>getCurrentAndIncrement

Returns the current value of the specified counter, and then increments it ready for the next request.

###### Request
<code><strong>GET</strong></code> <code>/counters/[:ns](https://github.com/wmfs/roadiejs#ns)/[:bp](https://github.com/wmfs/roadiejs#bp)/[:bv](https://github.com/wmfs/roadiejs#bv)/:counterName</code>


| 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.


***

### <a name="getCurrent"></a>getCurrent

Returns the current value of the specified counter, without incrementing it.

###### Request
<code><strong>GET</strong></code> <code>/counters/[:ns](https://github.com/wmfs/roadiejs#ns)/[:bp](https://github.com/wmfs/roadiejs#bp)/[:bv](https://github.com/wmfs/roadiejs#bv)/:counterName/current</code>


| 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.

***

### <a name="setCurrent"></a>setCurrent

Sets the current value of the specified counter to the provided value.

###### Request
<code><strong>PUT</strong></code> <code>/counters/[:ns](https://github.com/wmfs/roadiejs#ns)/[:bp](https://github.com/wmfs/roadiejs#bp)/[:bv](https://github.com/wmfs/roadiejs#bv)/:counterName/current</code>

| 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```

***

### <a name="deleteCounter"></a>deleteCounter

Deletes the specified counter (any subsequent calls refering to it will then cause errors).

###### Request
<code><strong>DELETE</strong></code> <code>/counters/[:ns](https://github.com/wmfs/roadiejs#ns)/[:bp](https://github.com/wmfs/roadiejs#bp)/[:bv](https://github.com/wmfs/roadiejs#bv)/:counterName</code>


| Parameter | Notes   
| ----- | ----
| `counterName`  | Name of the counter to delete


## <a name="elements"></a>Elements
### <a name="counter"></a>counter
Registers a RoadieJS counter (useful for auto-incrementing ids - just like a database sequence).
###### Example
```json
{
  "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).




## <a name="activities"></a>Activities
### <a name="setValueFromCounter"></a>setValueFromCounter
Sets a value on the target activity to a counter's current value, and then increments.
###### Example
```json
{
  "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. 




## <a name="license"></a>License
[MIT](https://github.com/wmfs/roadiejs-counter/blob/master/LICENSE.md)

---
_Source: https://npm.io/package/roadiejs-counter · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
