@samatawy/rules
    Preparing search index...

    Class RulesEngine

    Index

    Constructors

    Properties

    workspaces: Map<string, Workspace>
    annotations: AnnotationRegistry

    Methods

    • Get the global registry instance of the RulesEngine. This is a singleton instance that can be used throughout the application to manage workspaces and rules.

      Returns RulesEngine

      The global RulesEngine instance.

    • Get the common workspace instance. This is a singleton workspace that can be used as a shared space for common rules, constants, types, and functions that can be sufficient for small applications.

      Returns Workspace

      The common Workspace instance.

    • Check if a workspace with the given name exists in this engine.

      Parameters

      • name: string

        The name of the workspace.

      Returns boolean

      True if the workspace exists, false otherwise.

    • Get the names of all workspaces in this engine.

      Returns string[]

      An array of workspace names.

    • Get the names of all workspaces in the global registry.

      Returns string[]

      An array of workspace names.

    • Check if a workspace with the given name exists in the global registry.

      Parameters

      • name: string

        The name of the workspace.

      Returns boolean

      True if the workspace exists, false otherwise.

    • Get a workspace by name from this engine.

      Parameters

      • name: string

        The name of the workspace to retrieve.

      Returns Workspace | undefined

      The Workspace instance associated with the given name, or undefined if not found.

    • Get a workspace by name from the global registry.

      Parameters

      • name: string

        The name of the workspace to retrieve.

      Returns Workspace | undefined

      The Workspace instance associated with the given name, or undefined if not found.

    • Add a workspace to this engine with the given name. If a workspace with the same name already exists, an error will be thrown.

      N.B. To reuse a name, get the workspace instance using getWorkspace() and call clear() to reset it.

      Parameters

      • name: string

        The name of the workspace.

      • workspace: Workspace

        The Workspace instance to add.

      Returns void

      EngineError if a workspace with the same name already exists.

    • Add a workspace to the global registry with the given name. If a workspace with the same name already exists, an error will be thrown.

      N.B. To reuse a name, get the workspace instance using getWorkspace() and call clear() to reset it.

      Parameters

      • name: string

        The name of the workspace.

      • workspace: Workspace

        The Workspace instance to add.

      Returns void

      EngineError if a workspace with the same name already exists.

    • Create a clone of the original Workspace instance, including all rules, constants, types, and functions. This is useful for creating isolated copies of the workspace for testing, experimentation, or parallel processing without affecting the original workspace. You can safely mutate a cloned workspace without affecting the source, since no references are shared.

      N.B. To clone a Workspace without adding it to a registry, you can simply call the clone() method on the Workspace instance itself, which will return a deep clone of the workspace.

      Parameters

      • source: string | Workspace

        the Workspace instance or name of the workspace to clone.

      • target_name: string

        name for the cloned workspace. The cloned workspace will be added to the engine's workspace map with this name.

      Returns Workspace

      a new Workspace instance that is a deep clone of the original workspace.

      EngineError if the source workspace is not found in the engine's workspace map or if a workspace with the new name already exists in the engine's workspace map.

    • Clone a workspace by name from the global registry and add it to the global registry with a new name.

      Parameters

      • source: string | Workspace

        the workspace instance or name of the workspace to clone.

      • target_name: string

        the name for the cloned workspace in the global registry.

      Returns Workspace

      a new Workspace instance that is a deep clone of the original workspace, added to the global registry with the new name.

      EngineError if the source workspace is not found in the global registry or if a workspace with the new name already exists in the global registry.