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

@waylay/rules-helper

v1.4.0

Published

javascript helper code to create waylay.io rules

Downloads

2

Readme

Waylay Rules Helper

intro

This library will allow the user to create waylay tasks in an easier way.

There's two ways to use this library:

  • with a config and the so called subflows
  • with a chain style builder which requires no config, and adheres to the waylay format of plugins.

More on the specific ways below.

This is not a UI library.

Installation

npm install @waylay/rules-helper

Subflow

The subflow builder uses the so called subflows as the main components. Each of these subflows has to be defined in the config which has to be passed to the builder on initialisation.

A subflow should be seen as a wrapper for waylay plugins which will be executed sequentially. These can then be used in the UI to hide complex waylay logic.

Subflow configuration

A subflow requires a name, description, properties and a list of waylay plugins You can template the input params of a waylay plugin through the properties of the subflow. Use the template notation seen below on resource, to use the input as an argument of the plugin.

a keyword that's always available is <%previousNode%>. This way you can access data from the previously configured waylay plugin.

[
  {
    name: 'exit geofence',
    description: 'Checks if a resource entered a geofence',
    properties: {
      resource: {
        type: 'string'
      }
    },
    plugins: [{
      name: 'stream',
      type: 'sensor',
      version: '1.0.0',
      properties: {
        resource: '<%properties.resource%>'
      },
      dataTrigger: true,
      tickTrigger: false,
      triggers: [
        'Data'
      ]
    },
    {
      name: 'condition',
      version: '1.1.0',
      type: 'sensor',
      properties: {
        condition: '${<%previousNode%>.rawData.stream.direction} === "EXIT"',
      },
      dataTrigger: false,
      tickTrigger: false,
      triggers: [
        'True'
      ]
    }]
  }
]

Setting up the package

To use the subflow part of the waylay task-helper, you need to setup the waylay helper with the clientId, secret and domain of your waylay instance. The config is the array of subflows as configured above.

const Helper = require('@waylay/rules-helper')

const { subflow } = new Helper({ clientID: CLIENT_ID, secret: CLIENT_SECRET, domain: DOMAIN, config: exampleConfig })

Builder

Starting the builder

To use the builder you need to create a subflow builder instance.

const builder = subflow.createTaskBuilder()

Step

A step consists of 2 parts, the name of the subflow you want to use for the step and the properties defined on that subflow.

{
    name: 'exit geofence',
    properties: {
        resource: 'test resource'
    }
}

Functions

|function| |async| |---|---|---| |getSubflows()|Gives you a list of all configured subflows.|No| |addStep(step)|Adds the step at the end of the currently configured steps.|No| |addAndGate([step])|Adds the steps passed to the function at the end of the currently configured steps. It will combine them in a logical AND gate.|No| |addOrGate([step])|Adds the steps passed to the function at the end of the currently configured steps. It will combine them in a logical OR gate.|No| |removeStep()|Removes the last configured step, if the last one was a gate step, it will remove all those steps.|No| |getSteps()|Gives back all currently configured steps.|No| |createTask(name, options)|Creates a task on the waylay engine, you should pass a name to the task. In the options you can pass all options that are available on a task (docs link to be added)|Yes| |createTemplate(name)|Creates a template on the waylay engine. You should pass a name to the template.|Yes|

All these functions can be chained after one another

builder
    .addStep(dummyStepStream)
    .addAndGate([dummyStep, dummyStep])
    .addStep(dummyActuator)
    .createTask('subflow builder example test', {})

Chain

The chain builder is the most straight forward one to use seeing as it doesn't need a config to work. The downside to this is that more Waylay logic will have to be applied as a user / through the UX.

Setting up the package

To use the chain part of the waylay task-helper, you need to setup the waylay helper with the clientId, secret and domain of your waylay instance. The chain part of the task-helper doesn't require a configuration.

const Helper = require('@waylay/rules-helper')

const { chain } = new Helper({ clientID: CLIENT_ID, secret: CLIENT_SECRET, domain: DOMAIN })

Builder

List all plugins

const { sensors, actuators } = await chain.getPlugins()

Returns a list of all plugins active on your waylay instance. seperated into the categories sensors and actuators.

Starting the builder

To use the builder you need to create a chain builder instance.

const builder = chain.createBuilder()

Step

The steps of the chain builder adhere to the waylay format of plugins.

{
    name: 'inRange',
    type: 'sensor',
    version: '1.0.2',
    properties: {
        value: '${task.streamData}'
    },
    states: ['Above', 'In Range'],
    dataTrigger: true,
    tickTrigger: true
}

Functions

|function| |async| |---|---|---| |addStep(step)|Adds the step at the end of the currently configured steps.|No| |addAndGate([step])|Adds the steps passed to the function at the end of the currently configured steps. It will combine them in a logical AND gate.|No| |addOrGate([step])|Adds the steps passed to the function at the end of the currently configured steps. It will combine them in a logical OR gate.|No| |removeStep()|Removes the last configured step, if the last one was a gate step, it will remove all those steps.|No| |createTask(name, options)|Creates a task on the waylay engine, you should pass a name to the task. In the options you can pass all options that are available on a task (docs link to be added)|Yes| |createTemplate(name)|Creates a template on the waylay engine. You should pass a name to the template.|Yes|

All these functions can be chained after one another

builder
    .addStep(step)
    .addAndGate([step, step])
    .addStep(step)
    .createTask('chain builder example test', {})