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

blackbox-rules-utils

v1.0.1

Published

Provides default implementations for Blackbox rulebase dependencies.

Downloads

6

Readme

blackbox-rules-utils

Version standard-readme compliant

Blackbox rules utility classes and default implementations.

This package provides a default implementation of a RuleBase that includes all required properties for managing and persisting Rules, Conditions and Values.

Table of Contents

Install

npm i blackbox-rules-utils

Usage

Create a rulebase with custom Store, RemoteValueProtocol and VariableStore:

import {factory} from 'blackbox-ioc'

class MyRulebaseConfig {
  @factory('rulebase-store')
  createStore() { return new MyStore(); }

  @factory('remote-value-protocol')
  createRemoteValueProtocol() { return new MyRemoteValueProtocol(); }

  @factory('variable-store')
  createVariableStore() { return new MyVariableStore(); }
}

const rulebase = new DefaultRuleBase()

If any of the instances (created above with the factory decorator) are not provided then the defaults are used: DefaultStore, DefaultRemoteValueProtocol, and DefaultVariableStore.

If you are using a DefaultStore you can specify the database to use by providing an instance named rules-database, for example, via a factory decorator:

@factory('rules-database')
createDatabase() {
  return new SimpleFileDatabase({path:'/path/to/rulebase.json'})
}

or via a named class:

@named('rules-database')
class MyDB implements Database {
  ...
}

If using a SimpleFileDatabase then serialisers and deserialisers are needed for Rules, Conditions and Values. Deserialisers are obtained from serialiser and deserialiser services with the following tags: rule-deserialiser condition-deserialiser value-deserialiser rule-serialiser condition-serialiser value-serialiser. The RuleSerialiser, ConditionSerialiser and ValueSerialiser classes provide these services automatically for Rules, and all Conditions and Values provided by the blackbox-rules package.

To provide serialisers and deserialisers for custom Conditions and Values you will need to create taggedServices with the service name matching your Condition or Value type:

@taggedService('condition-deserialiser', 'my-type')
deserialise(data:any):MyCondition {
  ...
}

@taggedService('condition-serialiser', 'my-type')
serialise(data:MyCondition):any {
  ...
}

API

DefaultRuleBase: An implementation of a RuleBase that allows for overriding of its properties via named instances in the Blackbox IOC container (see Usage above).

DefaultStore: A Store potentially backed by a Database. See Usage above for examples of use and overrides.

DefaultRemoteValueProtocol: A basic RemoteValueProtocol that handles calling a remote Blackbox rulebase service.

DefaultVariableStore: A very basic in memory VariableStore.

Database: An interface for a database that persists the rulebase managed by a DefaultStore.

SimpleFileDatabase: A Database that persists data, via serialisers and deserialisers, to a file (see Usage above).

RuleSerialiser: Default JSON serialisers and deserialisers for Rules.

ConditionSerialisers: Default JSON serialisers and deserialisers for Conditions.

ValueSerialisers: Default JSON serialisers and deserialisers for Values.

Maintainers

@ellipsistechnology

Contributing

PRs accepted.

Small note: If editing the README, please conform to the standard-readme specification.

License

MIT © 2019 Ben Millar