5.0.9 • Published 1 year ago

@vhidvz/wfjs v5.0.9

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

WorkflowJS

npm Coverage npm GitHub Chat on Matrix documentation Build, Test and Publish

WorkflowJS is a lightweight and flexible library for building workflows and processes with NodeJS. It allows you to define processes using BPMN 2.0.

This is a JavaScript library for building and executing workflows. It provides a simple, declarative syntax for defining processes, and offers a flexible and extensible framework for handling workflow events and activities.

Installation

npm install --save @vhidvz/wfjs

Concepts

*ConceptDescriptionTypeDecoratorRequired
1Processis a BPMN lane, a collection of flow objects.Class@ProcessYes
2Nodeis a functionality of Activity in a workflow.Method@NodeYes
3Activityis a Flow Object or a Node of a workflow process.Param@Act()Yes
4Contextis storing the state of the machine during execution.Param@Ctx()No
5Tokenhas a history of the execution State, tokens are needed.Param@Sign()No
6historyis an array of the State of a flow object or node in a token.--@Sign()No
7Stateit contains the state of each node or flows object in history.--@Sign()No
8Datais a shared space across the execution context.Param@Data()Maybe
9Valueis an isolated space for each flow object or node.Param@Value()Maybe

Note: if you return a value in a Node the value is passed to the next available Node as a Value in a specific execution.

Getting Started

Define a BPMN Schema

To define a BPMN schema, you need to create a file with the extension .bpmn and define the schema using the BPMN 2.0 standard or use the online BPMN editor. Here's an example of a simple BPMN schema:

Simple Workflow

The full definition of the simple workflow schema .bpmn file located in this link.

Creating a Workflow Instance

To create a new workflow, you need to define a class with methods that represent the different steps of the workflow. You can use decorators to define the nodes and activities of the workflow. Here's an example of a simple workflow:

import { Act, Node, Process } from "@vhidvz/wfjs/common";
import { EventActivity } from "@vhidvz/wfjs/core";

@Process({ name: 'Simple Workflow' })
class SimpleWorkflow {
  @Node({ name: 'Start' })
  async start(@Act() activity: EventActivity) {
    activity.takeOutgoing();
  }
}

Building and Executing the Workflow

Once you have defined the workflow, you can build and execute it using the WorkflowJS library. Here's how you can do it:

import { parse, readFile, WorkflowJS } from '@vhidvz/wfjs';

(async () => {
  const workflow = WorkflowJS.build();

  const { context } = await workflow.execute({
    factory: () => new SimpleWorkflow(),
    xml: readFile('./example/simple-workflow.bpmn'),
  });

  console.debug('\nContext is:', JSON.stringify(context.serialize(), null, 2));
})()

More Example

Projects:

License

This project is licensed under the MIT License - SEE the LICENSE file for details

5.0.9

1 year ago

5.0.6

2 years ago

5.0.5

2 years ago

5.0.4

2 years ago

5.0.3

2 years ago

5.0.2

2 years ago

5.0.1

2 years ago

5.0.0

2 years ago

4.1.5

2 years ago

4.1.4

2 years ago

4.1.3

2 years ago

4.1.2

2 years ago

4.1.1

2 years ago

4.1.0

2 years ago

4.0.3

2 years ago

4.0.2

2 years ago

4.0.0

2 years ago

3.0.0

2 years ago

2.4.1

2 years ago

2.4.0

2 years ago

2.3.0

2 years ago

2.2.2

2 years ago

2.2.1

2 years ago

2.2.0

2 years ago

2.1.1

2 years ago

2.1.0

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.2.0

2 years ago

1.1.0

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

1.1.0-beta

2 years ago

1.0.1-beta

2 years ago

1.0.0-beta

2 years ago

1.1.1-alpha

2 years ago

1.1.0-alpha

2 years ago

1.0.8-alpha

2 years ago

1.0.7-alpha

2 years ago

1.0.6-alpha

2 years ago

1.0.5-alpha

2 years ago

1.0.4-alpha

2 years ago

1.0.3-alpha

2 years ago

1.0.2-alpha

2 years ago