UNPKG

entangle.ts

Version:

A declarative, event-driven framework for orchestrating business logic in TypeScript & Node.js applications.

34 lines (33 loc) 1.12 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EventHorizon = void 0; const Query_builder_1 = require("./builders/Query.builder"); /** * The limit from which data cannot escape. * It holds a history of all past events and allows the search of it */ class EventHorizon { constructor() { this.causalityLogs = []; } /** * Adds a new event record to the causality log. * This method should be called whenever a new event is emitted. * @param event The name of the event that occurred. * @param args The arguments that were passed when the event was emitted. */ add(event, ...args) { this.causalityLogs.push({ event, args }); return this; } /** * Begins a new query of past events. * Returns a new QueryBuilder instance, allowing for a safe, chainable, * and state-isolated way to search the causality log. * @returns A new instance of `QueryBuilder`. */ query() { return new Query_builder_1.QueryBuilder(this.causalityLogs); } } exports.EventHorizon = EventHorizon;