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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@mostajs/rules

v0.1.0

Published

Declarative rules / inference engine (ECA Condition) — pluggable backend, Prolog (tau-prolog) by default. Pure, bounded (no infinite loops), explainable. Composed by statemachine, trigger and rbac.

Downloads

86

Readme

@mostajs/rules

Moteur de règles déclaratif (la Condition d'Event-Condition-Action) — backend d'inférence pluggable, Prolog par défaut (via tau-prolog). Pur, borné (anti-boucle), explicable.

Auteur : Dr Hamid MADANI [email protected] · Licence : AGPL-3.0-or-later

@mostajs/rules est une primitive de l'écosystème @mostajs/*. Elle évalue des conditions/gardes déclaratives sur des faits — là où l'on disperserait sinon des if en dur. C'est la brique RULE du triptyque State · Rule · Trigger (inspiré des modules Drupal Workflow / Rules / Trigger) :

| Brique | Module | |---|---| | STATE | @mostajs/statemachine | | RULE | @mostajs/rules (ce module) | | TRIGGER | @mostajs/trigger | | stack d'assemblage | @mostajs/workflow |

Installation

npm i @mostajs/rules tau-prolog

tau-prolog est une peer dependency optionnelle : c'est le moteur par défaut (pur-JS, navigateur + Node). Sans elle, l'usage lève RuleEngineUnavailableError (le paquet s'installe quand même). Backends optionnels prévus : swipl-wasm, json-logic-js.

Exemple minimal

import { createKnowledgeBase } from "@mostajs/rules";

const kb = createKnowledgeBase(); // moteur Prolog par défaut

await kb.consult(`
  assignee(order(42), emp(7)).
  peut_modifier_etat(Emp, Order) :- assignee(Order, Emp).
`);

await kb.holds("peut_modifier_etat(emp(7), order(42))"); // true
await kb.holds("peut_modifier_etat(emp(9), order(42))"); // false (deny-by-default)

const sols = await kb.query("assignee(order(42), X)");
// [{ bindings: { X: "emp(7)" } }]

Cas d'usage dans l'écosystème

  • Garde de transition (@mostajs/statemachine / @mostajs/workflow) : transition_allowed(Order, Actor, From, To).
  • Autorisation d'instance (@mostajs/rbac) : « l'employé ne modifie que ses commandes » — peut_modifier_etat(Emp, Order) :- assignee(Order, Emp).
  • Gating d'action (@mostajs/trigger) : n'exécuter une action que si une condition tient.
  • Tarification / éligibilité / validation métier éditables sans redéploiement.

Règles nommées réutilisables

import { defineRule, createKnowledgeBase } from "@mostajs/rules";

defineRule("crm/transition_allowed", `transition_allowed(O, A, validee, terminee) :- ... .`);

const kb = createKnowledgeBase();
await kb.consult("crm/transition_allowed"); // chargé par son nom

Référence API

| Élément | Signature | Rôle | |---|---|---| | createKnowledgeBase(opts?) | → KnowledgeBase | crée une base (moteur Prolog par défaut) | | kb.consult(progOuNom) | → Promise<this> | charge du Prolog brut ou une règle nommée | | kb.assert(fact) / kb.retract(fact) | → Promise<this> | ajoute / retire un fait | | kb.query(goal, opts?) | → Promise<Solution[]> | solutions (bindings) | | kb.holds(goal, opts?) | → Promise<boolean> | garde booléenne (deny-by-default) | | kb.explain(goal, opts?) | → Promise<DerivationNode> | arbre de dérivation (v0.2) | | defineRule / getRule / listRules | — | règles nommées | | createEngine(name?) | → RuleEngine | "prolog" (défaut) · "swi"/"jsonlogic" (v0.3) |

QueryOptions = { max?, steps?, timeoutMs? }. Limites par défaut : DEFAULT_LIMITS = { steps: 500000, timeoutMs: 1000 }.

Garde-fous (anti-boucle)

Toute requête est bornée par un nombre de pas de résolution (steps) et un plafond horloge (timeoutMs). Dépassement → RuleStepLimitError / RuleTimeoutError. Le moteur est pur (aucun I/O).

Statut

v0.0.1 — scaffold. Wiring fonctionnel consult/query/holds (Prolog). Feuille de route : docs/03-PLAN-DEV-RULES.md (0.1 tests, 0.2 explain, 0.3 backends optionnels, 1.0 = 14 livrables). Étude & décisions : docs/01-ETUDE-ETAT-ART-RULES-07062026.md, docs/02-AUDIT-EXISTANT-RULES.md.