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

constraints-engine

v0.4.0

Published

A library of utilities for working with constraints

Downloads

3

Readme

A module which provides a constraints engine

Terms

Constraint: A Constraint is an entity with 2 related domains of Constrained Entities. The Constraint expresses which Constrained Entities are consistent with each other. The Constraint has a Constraint Name.

Constrained Entity: An entity that is related to a Constraint.

Constraint Relationship: A Constraint is linked to Constrained Entities through a specific Constraint Relationship.

Consistency: Entities are consistent if

  • there are no constraints involving both Entities
  • there are no Constraints containing one Constrained Entity and not the other
  • all Constraints allow both nodes to coexist

Inconsistency: Entities are inconsistent if

  • there is one constraints in which either entity is exists but not the other entity.

Selecting: The act of identifying a selected Constrained Entity for each of the Constraint Relationships is referred to as Selecting.

Satisfied Constrained Entity: A Constrained Entity is Satisfied when all the Constraints it is associated with have been Selected.

Example constraints

The diagram belows has a visual representation of constraints.

Semantically the first constraints has the following meaning.

The UFB Available constraint expresses
the Auckland and Christchurch locations are UFB available sites and
that Fixed Access and Site Mobile Access  depend upon a location which is UFB available.

alt text

How to use

Define some constraints as an array of relationships from Constraint to Constrained Entity.

Each object in the array represents a link from the Constraint (source) to the Constrained Entity (target)

The source is always the Constraint.

The type value is used to split the Constrained Entities into the distinct sets.

var singleConstraint = [
  {
    source: "Constraint Id",
    sourcename: "Constraint Name",
    target: "Constrainee Reference",
    type: "Association"
  },
  {
    source: "Constraint Id",
    sourcename: "Constraint Name",
    target: "Constrainer id",
    type: "Dependency"
  }
]

Build the constraint engine passing the constraint data array.

var constraintEngine = constraints.compile(singleConstraint);

Then it is possible to query if nodes are consistent according to the constraints.

var consistencyCheck = constraintEngine.getConsistencyCheck("Entity1","Entity2").

Unit Tests

Run npm-watch to run the mocha test suite and look at the test.spec.js which has the following output when run successfully.


   Given a constraint engine
     When there is a single constraint
       √ Then there is a single constraint indexed
       √ Then the constrained nodes are consistent
       √ Then the constrainted nodes are consistent the other way around
       √ Then unconstrainted nodes are consistent
       √ Then constrained and unconstrainted nodes are not consistent
     When there is are 2 constraint
       √ Then there is 2 constraints indexed
       √ Then the constrained nodes are consistent
       √ Then the constrainted nodes are consistent the other way around
       √ Then entities which dont satisfy both constraints are inconsistent
     When there is are 3 constraints which make all combinations invalid
       √ Then consistent combinations are identified
       √ Then inconsistent combinations are identified