UNPKG

sfpm-js

Version:

A lightweight, dependency-free, forward-chaining inference engine for managing complex state and logic in a declarative way.

32 lines (27 loc) 727 B
// src/Query.js import { DictionaryFactSource } from "./FactSource.js"; import { match } from "./RuleMatcher.js"; export class Query { /** * @param {Map<string, any>} factData */ constructor(factData = new Map()) { // Default to an empty map this._factSource = new DictionaryFactSource(factData); } /** * @param {string} key * @param {any} value * @returns {this} */ add(key, value) { this._factSource.setFact(key, value); return this; // Return this for chaining, like in the C# example } /** * @param {import('./Rule').Rule[]} rules */ match(rules, ...data) { match(rules, this._factSource, ...data); } }