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

gawati-workflow

v1.0.7

Published

Finite State Machine Workflow library for Node JS

Downloads

4

Readme

Gawati Workflow

Workflow configurations are supported in both XML and JSON, they can be created in XML, and converted into JSON for application consumption. You can generate directed graphs of the Worfklow based on the instructions below (that requires the Workflow configuration to be in XML).

Gawati Workflow is a stateful workflow, and is intended to support moving a document through different states via state transitions. The Workflow allows defining who can do what in each state, and also who is allowed to transit between states. Transitions connect states, and allow building complex workflows using just a few states.

The typical process is to edit the workflow in XML and generate the production JSON out of that using the xml2jon script which has been provided.

Test

  • npm install followed by ;
  • npm test
  • Unit tests are found in test/testWorkflow.js, which provide an overview of how the API can be used.

Generating Documentation

  • NOTE: this requires the workflow configuration to be in XML format
  • npm install in the package folder
  • Download Saxon
  • Install Graphviz

Convert the Workflow XML to graphviz dot format

java -jar <path to saxon9 he>/saxon9he.jar wf/act-legislation.xml xslt/wf2dotML.xsl  > act-legislation.dotML
java -jar <path to saxon9 he>/saxon9he.jar ./act-legislation.dotML xslt/dotml2dot.xsl > act-legislation.dot

Convert the dot file to an image

dot ./act-legislation.dot -Tsvg -o ./act-legislation.svg

See an example SVG generated from the model workflow:

Svg from workflow XML

Converting the Workflow XML to JSON

Run:

node xml2json.js --name=wf/act-legislation.xml 
{"workflow":{"doctype":"act", .... "from":"publish","to":"review"}]}}}

To serialize it to a file:

node xml2json.js --name=wf/act-legislation.xml --output=wf/act-legislation.json

Workflow structure

Each workflow is defined using a <workflow> tag, the attributes doctype and subtype correspond to Akoma Ntoso document type and sub types for the document. A workflow definition

<workflow doctype="act" subtype="legislation">
    ....
</workflow>

Permissions

We describe available permissions in a <permissions> element. To the workflow package, the permissions are just labels and the application using the workflow needs to implement the corresponding functionality - except for the transit permission which is specific to the workflow, and states who is allowed to transit from one state of the workflow to another.

    <permissions>
        <permission name="view" title="View" icon="fa-eye"/>
        <permission name="edit" title="Edit" icon="fa-pencil"/>
        <permission name="delete" title="Delete" icon="fa-trash-o"/>
        <permission name="list" title="List" icon="fa-flag"/>
        <permission name="transit" title="Transit" icon="fa-flag"/>
    </permissions>

In the context of gawati the permissions are intended to have the following meaning: * view - allows viewing a document * edit - allows editing a document * delete - allows deleting a document * list - allows seeing the document in a list (but not viewing it) * transit - allows transiting from the state to another.

States

States are defined in the <states> element and are uniquely identified via a name attribute. In a workflow a state is always unique. level and color attributes are there for purely documentation related purposes and are non mandatory.

A state defines permissions applicable in that state. Each permission has to correspond to a name of a permission defined in the <permissions> block. A permission in a state is always associated with one or more roles stated in the roles attribute.

1    <state name="editable" title="Editable" level="2" color="initial">
2        <permission name="view" roles="admin editor"/>
3        <permission name="list" roles="admin editor submitter" />
4        <permission name="delete" roles="admin editor"/>
5        <permission name="edit" roles="admin editor"/>
6        <permission name="transit" roles="admin editor"/>
7    </state>

Permissions defined in a state have a particular meaning: * line 2 : <permission name="view" roles="admin editor"/> - only users with an admin or editor role can view the document * line 3 : <permission name="list" roles="admin editor submitter" /> - only users with an admin, editor or submitter role can see the document in a listing * line 4: <permission name="delete" roles="admin editor"/> - only admin, editor users can delete the document * line 6: <permission name="transit" roles="admin editor"/> - only admin, editor users can transit the document via a state transition

Transitions

Transitions allow the document to be moved from one state to another:

    <transitions>

        <transition name="make_editable" icon="fa-thumbs-up" title="Send for Editing"
            from="draft" to="editable" />

        <transition name="make_drafting" icon="fa-thumbs-up" title="Back to Drafting"
            from="editable" to="draft" />

        ...

        <transition name="make_retract" icon="fa-building" title="Retract" 
            from="publish" to="review" />

    </transitions>

A transition has to have a unique name, the icon attribute is a font-awesome icon code which is used in the UI next to the transition title. The transition also has from and to attributes each of which points to a <state> name defined earlier. This transition moves the document from editable=>available_for_review states.

    <transition name="send_for_review" icon="fa-check" title="Send for Review" 
        from="editable" to="available_for_review" />

The transit permission on the editable state (which is the from state), permits admin and editor role users to move the document from editable to available_for_review.

    <state name="editable" title="Editable" level="2" color="initial">
        ...
        <permission name="transit" roles="admin editor"/>
    </state>

Actions

Transitions support both pre and post transit actions. These are essentially JS functions which can be configured on the workflow via a custom module and triggered by the calling API doing the transition. See testModule.js in the unit tests, for an example of how this can be used.