npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@vhidvz/wfjs

v5.0.9

Published

Workflow Engine (BPMN Engine)

Downloads

1,048

Readme

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

| * | Concept | Description | Type | Decorator | Required | |---|----------|------------------------------------------------------------------|--------|-----------|----------| | 1 | Process | is a BPMN lane, a collection of flow objects. | Class | @Process | Yes | | 2 | Node | is a functionality of Activity in a workflow. | Method | @Node | Yes | | 3 | Activity | is a Flow Object or a Node of a workflow process. | Param | @Act() | Yes | | 4 | Context | is storing the state of the machine during execution. | Param | @Ctx() | No | | 5 | Token | has a history of the execution State, tokens are needed. | Param | @Sign() | No | | 6 | history | is an array of the State of a flow object or node in a token. | -- | @Sign() | No | | 7 | State | it contains the state of each node or flows object in history. | -- | @Sign() | No | | 8 | Data | is a shared space across the execution context. | Param | @Data() | Maybe | | 9 | Value | is 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