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

wolkenkit-command-tools

v3.1.0

Published

wolkenkit-command-tools is a collection of tools for commands.

Downloads

13

Readme

wolkenkit-command-tools

wolkenkit-command-tools is a collection of tools for commands.

Installation

$ npm install wolkenkit-command-tools

Quick start

First you need to integrate wolkenkit-command-tools into your application. Typically, you will only require a specific set of tools, e.g. the only middleware.

const { only } = require('wolkenkit-command-tools');

Using middleware

Any middleware is a function that takes a aggregate instance, a command and the mark callback as parameters. So you may use a reference to the middleware within a command definition.

Just like in Express, all middleware uses a setup function. Hence you need to call it to get the actual middleware.

handle.physicalEvents

This middleware handles physical events, e.g. from an IoT context. Before you are able to use it, you need to configure the physical events that you want to handle and specify their properties.

Typically, before handling physical events, you want to make sure that the device you record events for actually exists. For this, you may use the only.ifExists middleware.

const commands = {
  recordEvent: [
    only.ifExists(),
    handle.physicalEvents({
      opened: {
        type: 'object',
        properties: { when: { type: 'object' }},
        required: [ 'when' ],
        additionalProperties: false
      },
      closed: {
        type: 'object',
        properties: { when: { type: 'object' }},
        required: [ 'when' ],
        additionalProperties: false
      }
    })
  ]
};

On the client-side, you need to send the appropriate command that contains the desired event's name and data in its data property.

accessManagement.monitoring.door(id).recordEvent({
  name: 'opened',
  data: {
    when: new Date()
  }
});

only.ifExists

This middleware passes if the aggregate instance exists, otherwise it rejects the command.

const commands = {
  join: [
    only.ifExists(),
    async (peerGroup, command) => {
      // ...
    }
  ]
};

only.ifNotExists

This middleware passes if the aggregate instance does not exist, otherwise it rejects the command.

const commands = {
  start: [
    only.ifNotExists(),
    async (peerGroup, command) => {
      // ...
    }
  ]
};

only.ifAggregateExists

This middleware passes if another aggregate instance exists, otherwise it rejects the command. You have to provide the names of the related context and aggregate, and a function to extract the related aggregate's id from the current command:

const commands = {
  start: [
    only.ifAggregateExists({
      contextName: 'planning',
      aggregateName: 'location',
      aggregateId (command) {
        return command.data.location.id;
      }
    }),
    async (peerGroup, command) => {
      // ...
    }
  ]
}

By default, when the aggregateId function is not able to return an aggregate id, the middleware will reject the command. If you want to allow the aggregateId to be optional, provide the isOptional property and set it to true:

const commands = {
  start: [
    only.ifAggregateExists({
      contextName: 'planning',
      aggregateName: 'location',
      aggregateId (command) {
        return command.data.location.id;
      },
      isOptional: true
    }),
    async (peerGroup, command) => {
      // ...
    }
  ]
}

only.ifInPhase

This middleware passes if the aggregate instance is in the given phase, otherwise it rejects the command.

const initialState = {
  phase: 'started',
  // ...
};

const commands = {
  join: [
    only.ifInPhase('started'),
    async (peerGroup, command) => {
      // ...
    }
  ]
};

You can also provide multiple phases:

const initialState = {
  phase: 'started',
  // ...
};

const commands = {
  join: [
    only.ifInPhase([ 'started', 'ready' ]),
    async (peerGroup, command) => {
      // ...
    }
  ]
};

When needed, you can change the name of the property to use for detecting the current phase. By default it is phase. To change it, hand over the desired name as second parameter to the middleware.

const initialState = {
  workflowStep: 'started',
  // ...
};

const commands = {
  join: [
    only.ifInPhase('started', 'workflowStep'),
    async (peerGroup, command) => {
      // ...
    }
  ]
};

only.ifCommandValidatedBy

This middleware passes if the command data can be validated by the given JSON schema, otherwise it rejects the command.

const commands = {
  start: [
    only.ifCommandValidatedBy({
      type: 'object',
      properties: {
        // ...
      }
    }),
    async (peerGroup, command) => {
      // ...
    }
  ]
};

Alternatively, you may also provide a validation function. This function must return true if the validation was successful, otherwise false.

const commands = {
  start: [
    only.ifCommandValidatedBy(data => {
      // return true;
      // - or -
      // return false;
    }),
    async (peerGroup, command) => {
      // ...
    }
  ]
};

only.ifStateValidatedBy

This middleware passes if the aggregate state can be validated by the given JSON schema, otherwise it rejects the command.

const commands = {
  start: [
    only.ifStateValidatedBy({
      type: 'object',
      properties: {
        // ...
      }
    }),
    async (peerGroup, command) => {
      // ...
    }
  ]
};

Alternatively, you may also provide a validation function. This function must return true if the validation was successful, otherwise false.

const commands = {
  start: [
    only.ifStateValidatedBy(state => {
      // return true;
      // - or -
      // return false;
    }),
    async (peerGroup, command) => {
      // ...
    }
  ]
};

Running the build

To build this module use roboter.

$ npx roboter

License

Copyright (c) 2015-2019 the native web.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see GNU Licenses.