Skip to content

Latest commit

 

History

History
108 lines (90 loc) · 2.61 KB

api_reference_js.md

File metadata and controls

108 lines (90 loc) · 2.61 KB

API Reference (JavaScript)

Overview

Pondermatic is a functional effect system-driven rules engine designed for use with Clojure, ClojureScript, and JavaScript. This document provides an API reference for using Pondermatic with JavaScript.

Installation

Install via npm:

npm install @totalperspective/pondermatic

Usage

Creating an Engine

  • Description: Creates a new engine instance.
  • Parameters:
    • name (string): The name of the engine.
    • resetDb (boolean): Whether to reset the database.
  • Returns: An engine instance.
  • Example:
    import pondermatic from '@totalperspective/pondermatic';
    const engine = pondermatic.createEngine('example', true);

Defining Rules

  • Description: Defines a set of rules.
  • Parameters:
    • rules (Array): An array of rule definitions.
    • Returns: A ruleset.
    • Example:
      const rules = pondermatic.ruleset([
        {
          id: 'example-rule',
          'rule/when': { 'data/key': '?value' },
          'rule/then': { 'data/new-key': '?value' }
        }
      ]);
    • Adding Data

      • Description: Creates a dataset from an array of data objects.
      • Parameters:
        • data (Array): An array of data objects.
        • Returns: A dataset.
        • Example:
          const data = pondermatic.dataset([{ key: 'value' }]);
          pondermatic.sh(engine, { '->db': rules });
          pondermatic.sh(engine, { '->db': data });
        • Querying Data

          • Description: Executes a query on the engine.
          • Parameters:
            • engine (Engine): The engine instance.
            • query (string): The query string.
            • args (Array): An array of arguments for the query.
            • callback (Function): A callback function to handle the query results.
          • Returns: Query results.
          • Example:
            const q = pondermatic.q(
              engine,
              "[:find ?v . :where [?id :data/key ?v]]",
              [],
              r => {
                if (!r) {
                  return;
                }
                console.log(r);
              }
            );

          Stopping the Engine

          • Description: Stops the engine.
          • Parameters:
            • engine (Engine): The engine instance.
          • Returns: None.
          • Example:
            pondermatic.stop(engine);

          Table of Contents

          Changelog

          Version 1.11.10

          • Added support for JavaScript.
          • Improved performance optimizations.
          • Enhanced data source integrations.
          • Additional rule definition capabilities.
          • Expanded documentation and examples.