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

@jsonspecs/rules

v4.0.1

Published

Declarative JSON rules engine for validation pipelines

Readme

JSONSpecs Rules

CI npm License: MIT Node 20+

На русском языке

Deterministic JSON rules runtime for Node.js. Version 4 implements the executable contract of jsonspecs/spec 1.0.0-rc.7.

The engine validates a closed snapshot once, verifies its JCS sourceHash, binds built-in and external operators, and returns a deterministic result with ordered business issues and ruleset provenance.

Install

npm install @jsonspecs/rules

Node.js 20 or newer is required. Regular expressions execute through RE2 compiled to WebAssembly (re2-wasm), so accepted patterns do not block the event loop with catastrophic backtracking and package installation does not require a native build toolchain.

Basic use

const {
  compileSnapshot,
  computeSourceHash,
  runPipeline,
} = require("@jsonspecs/rules");

const snapshot = {
  format: "jsonspecs-snapshot",
  formatVersion: 2,
  specVersion: "1.0.0-rc.7",
  exports: ["customer.validate"],
  artifacts: {
    "customer.validate": {
      type: "pipeline",
      steps: ["customer.name.required"],
    },
    "customer.name.required": {
      type: "rule",
      operator: "not_empty",
      field: "customer.name",
      issue: {
        level: "ERROR",
        code: "CUSTOMER.NAME.REQUIRED",
        message: "Customer name is required",
      },
    },
  },
};

snapshot.sourceHash = computeSourceHash(snapshot);
const prepared = compileSnapshot(snapshot);
const result = runPipeline(prepared, {
  pipelineId: "customer.validate",
  payload: { customer: { name: "" } },
  context: {},
});

pipelineId is always explicit. payload and context are nested JSON objects; pre-flattened payloads and payload.__context are not part of the contract.

Wildcard fields

RC.7 expands a wildcard from the real arrays in the nested payload. A rule over items[*].sku therefore evaluates every real items[i], including an item whose sku is absent. Presence operators can report a concrete field such as items[1].sku; value operators keep their existing SKIP behavior for absence. onEmpty applies only when no structural candidate exists.

The compiler accepts wildcard only on the primary payload field, pre-parses its path, and rejects wildcard under $context. See the linked behavior specification for the complete traversal and aggregation contract.

External operators

An operator package exports a map from immutable names to { schema, evaluate }. The schema is a closed JSON Schema draft-07 contract for operator-specific rule configuration. The engine resolves paths and passes values only; an operator never receives the payload, context, a resolver, or the use site.

const { createEngine } = require("@jsonspecs/rules");

const engine = createEngine({
  operators: {
    "credit.age_at_least": {
      schema: {
        type: "object",
        properties: {
          inputs: {
            type: "object",
            properties: { age: { type: "string", minLength: 1 } },
            required: ["age"],
            additionalProperties: false,
          },
          params: {
            type: "object",
            properties: { minimum: { type: "integer", minimum: 0 } },
            required: ["minimum"],
            additionalProperties: false,
          },
        },
        required: ["inputs", "params"],
        additionalProperties: false,
      },
      evaluate({ inputs, params }) {
        if (!("age" in inputs)) return "SKIP";
        return Number.isInteger(inputs.age) && inputs.age >= params.minimum
          ? "PASS"
          : "FAIL";
      },
    },
  },
});

evaluate returns exactly PASS, FAIL, or SKIP. A thrown value becomes ABORT OPERATOR_FAULT; any other return value becomes ABORT OPERATOR_CONTRACT_VIOLATION. Built-in names are reserved and cannot be overridden.

Public API

  • createEngine({ operators? })
  • builtInOperators — deeply immutable built-in definitions and schemas
  • CompilationError for rejected snapshots
  • compileSnapshot(snapshot) / engine.compileSnapshot(snapshot)
  • compileSnapshotText(text) for strict I-JSON parsing with duplicate-key checks
  • validate(snapshot)
  • runPipeline(prepared, { pipelineId, payload, context? })
  • inspect(prepared)
  • computeSourceHash(snapshot)
  • formatDiagnostics() and formatRuntimeError()

compileSnapshot accepts only formatVersion 2. Source artifacts, folders, imports, descriptions and authoring metadata are builder/CLI concerns.

Banking use

The runtime is suitable for deterministic validation and business-rule decisions in credit workflows and payment gateways: required data, eligibility, consistency, limits expressed by operators, routing conditions, sanctions flags, and ordered business diagnostics. Services remain responsible for transport byte limits, authentication, authorization, snapshot delivery, and deployment provenance of external operator packs.

See the behavior specification, engine implementation, operators, RC.7 migration guide, historical RC.6 migration, 2.x to 3.x migration, and testing.