Skip to content

Commit

Permalink
use dts-buddy to generate type declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
paed01 committed Jun 18, 2024
1 parent 6414a99 commit e57f45b
Show file tree
Hide file tree
Showing 37 changed files with 1,867 additions and 1,277 deletions.
1 change: 0 additions & 1 deletion .eslintignore

This file was deleted.

7 changes: 0 additions & 7 deletions .eslintrc.json

This file was deleted.

10 changes: 5 additions & 5 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ jobs:
timeout-minutes: 20
strategy:
matrix:
node-version: [ 16, 18, latest ]
node-version: [18, 20, latest]
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm i
- run: npm run test:lcov
- name: Coveralls
uses: coverallsapp/github-action@master
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
flag-name: run-${{ matrix.node-version }}
Expand All @@ -33,7 +33,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Coveralls Finished
uses: coverallsapp/github-action@master
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
parallel-finished: true
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,5 @@ tmp/

dist/**/*
!dist/package.json

*.d.ts.map
2 changes: 1 addition & 1 deletion .mocharc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"require": "./test/helpers/setup.js",
"require": ["chai/register-expect.js", "./test/helpers/setup.js"],
"reporter": "spec",
"recursive": true,
"timeout": 1000,
Expand Down
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
types/index.d.ts
tsconfig.json
5 changes: 5 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"tabWidth": 2,
"printWidth": 140,
"singleQuote": true
}
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Changelog

# Unreleased

## [0.1.0] - 2024-06-18

- generate type declarations with [dts-buddy](https://www.npmjs.com/package/dts-buddy)
98 changes: 57 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
bpmn-middleware
===============
# bpmn-middleware

[![Build](https://github.com/zerodep/bpmn-middleware/actions/workflows/build.yaml/badge.svg)](https://github.com/zerodep/bpmn-middleware/actions/workflows/build.yaml)[![Coverage Status](https://coveralls.io/repos/github/zerodep/bpmn-middleware/badge.svg?branch=main)](https://coveralls.io/github/zerodep/bpmn-middleware?branch=main)

Express middleware for [BPMN engine](https://npmjs.com/package/bpmn-engine).

Under construction so breaking changes will occur until v1.

# Usage
## Usage

```js
```javascript
import express from 'express';
import { bpmnEngineMiddleware, HttpError } from 'bpmn-express-middleware';
import { bpmnEngineMiddleware, HttpError } from 'bpmn-middleware';

const app = express();
app.use('/rest', bpmnEngineMiddleware({ idleTimeout: 90000 }));
Expand All @@ -27,24 +26,26 @@ function errorHandler(err, req, res, next) {
}
```

# Middleware
## Middleware

## `bpmnEngineMiddleware([options])`
### `bpmnEngineMiddleware([options])`

Create BPMN engine middleware.

Options:

- `adapter`: Optional [storage adapter](#storage-adapter). Defaults to in-memory adapter based on LRU cache
- `engineOptions`: Optional BPMN Engine [options](https://github.com/paed01/bpmn-engine/blob/master/docs/API.md)
- `engineCache`: Optional engine LRU cache, defaults to `new LRUCache({ max: 1000 })`
- `broker`: Optional [smqp](https://npmjs.com/package/smqp) broker, used for forwarding events from executing engines
- `idleTimeout`: Optional positive integer, engine execution timeout in milliseconds before engine execution is considered idle and is stopped, defaults to 120000ms

Returns Expressjs Router with extra properties:

- `middleware`: middleware route functions
- `engines`: BPMN engines handler

# Routes
## Routes

- [`GET (*)?/version`](#get-version)
- [`GET (*)?/deployment`](#get-deployment)
Expand All @@ -62,143 +63,157 @@ Returns Expressjs Router with extra properties:
- [`DELETE (*)?/internal/stop`](#delete-internalstop)
- [`DELETE (*)?/internal/stop/:token`](#delete-internalstoptoken)

## `GET (*)?/version`
### `GET (*)?/version`

Get app version.

Response body:

- `version`: string, resolved from `process.cwd() + '/package.json`

## `GET (*)?/deployment`
### `GET (*)?/deployment`

Get app name.

Response body:

- `name`: string, resolved from `process.cwd() + '/package.json`

## `POST (*)?/deployment/create`
### `POST (*)?/deployment/create`

Create deployment by passing multipart form with BPMN diagram file.

Content-type: `multipart/form-data`

Form fields:

- `deployment-name`: string, deployment name;
- `deployment-source`: string, deployment source;

Response body:

- `id`: string, same as deployment name
- `deploymentTime`: date, now
- `deployedProcessDefinitions`: object
* `[deploymentName]`: object, key as deployment name
- `[deploymentName]`: object, key as deployment name
- `id`: string, same as deployment name

## `POST (*)?/process-definition/:deploymentName/start`
### `POST (*)?/process-definition/:deploymentName/start`

Start deployment.

Params:

- `deploymentName`: deployment name

Request body:

- `businessKey`: string, business key
- `variables`: optional object with variables to pass to engine

Response body:

- `id`: string, unique execution token

## `GET (*)?/running`
### `GET (*)?/running`

Get all running instances.

Response body:

- `engines`: list of executing engines
* `token`: string, unique execution token
* `name`: string, deployment name
* `state`: string, engine status, `idle`, `running`, `stopped`, or `error`
* `activityStatus`: string, running activity status, `idle`, `executing`, `timer`, or `wait`
- `token`: string, unique execution token
- `name`: string, deployment name
- `state`: string, engine status, `idle`, `running`, `stopped`, or `error`
- `activityStatus`: string, running activity status, `idle`, `executing`, `timer`, or `wait`

## `GET (*)?/status/:token`
### `GET (*)?/status/:token`

Get process status

## `GET (*)?/status/:token/:activityId`
### `GET (*)?/status/:token/:activityId`

Get process activity status

## `POST (*)?/resume/:token`
### `POST (*)?/resume/:token`

Resume process run

## `POST (*)?/signal/:token`
### `POST (*)?/signal/:token`

Signal process activity.

Request body:

- `id`: activity id
- `executionId`: optional activity execution id
- `message`: optional message to signal activity with

## `POST (*)?/cancel/:token`
### `POST (*)?/cancel/:token`

Cancel process activity.

Request body:

- `id`: activity id
- `executionId`: optional activity execution id

## `POST (*)?/fail/:token`
### `POST (*)?/fail/:token`

Fail process activity.

Request body:

- `id`: activity id
- `executionId`: optional activity execution id
- `message`: optional message to send to activity

## `GET (*)?/state/:token`
### `GET (*)?/state/:token`

Get process engine state.

## `DELETE (*)?/state/:token`
### `DELETE (*)?/state/:token`

Delete process engine state.

## `DELETE (*)?/internal/stop`
### `DELETE (*)?/internal/stop`

Stop all running instances on this specific app instance.

## `DELETE (*)?/internal/stop/:token`
### `DELETE (*)?/internal/stop/:token`

Stop running instances by token on this specific app instance.

# Events
## Events

BPMN Engine will forward BPMN engine events to app prefixed by `bpmn/`.

## Event `bpmn/end`
### Event `bpmn/end`

BPMN Engine has completed successfully.

Handler arguments:

- `engine`: Engine instance

## Event `bpmn/stop`
### Event `bpmn/stop`

BPMN Engine execution has stopped.

Handler arguments:

- `engine`: Engine instance

## Event `bpmn/error`
### Event `bpmn/error`

BPMN Engine execution has failed.

Handler arguments:

- `err`: Error
- `engine`: Engine instance

# Storage adapter
## Storage adapter

Persistent storage adapter, defaults to in memory storage.

Expand All @@ -208,7 +223,7 @@ Three types will be saved to adapter:
- `file`: BPMN file with meta and content
- `state`: BPMN engine state

## `async upsert(type, key, value[, options])`
### `async upsert(type, key, value[, options])`

Set entry with key.

Expand All @@ -217,31 +232,31 @@ Set entry with key.
- `value`: object, value
- `options`: optional object with options

## `async delete(type, key)`
### `async delete(type, key)`

Delete entry by key.

- `type`: string, storage type, `deployment`, `file`, or `state`
- `key`: string, storage key

## `async fetch(type, key[, options])`
### `async fetch(type, key[, options])`

Fetch entry by key.

- `type`: string, storage type, `deployment`, `file`, or `state`
- `key`: string, storage key
- `options`: optional object with options
* `exclude`: optional list of fields to exclude
- `exclude`: optional list of fields to exclude

## `async query(type, qs[, options])`
### `async query(type, qs[, options])`

Query entries.

- `type`: string, storage type, `deployment`, `file`, or `state`
- `qs`: object, storage query
* `exclude`: optional list of fields to exclude
* `state`: optional string, get engine states by state of engine, `idle`, `running`, etc
* `caller`: optional object, get engines by call activity caller
- `exclude`: optional list of fields to exclude
- `state`: optional string, get engine states by state of engine, `idle`, `running`, etc
- `caller`: optional object, get engines by call activity caller
- `token`: string, calling process token
- `deployment`: string, calling process deployment name
- `id`: string, calling activity id
Expand All @@ -250,4 +265,5 @@ Query entries.
- `options`: optional object with options

Returns:

- `records`: List of entries
Loading

0 comments on commit e57f45b

Please sign in to comment.