@samatawy/rules
    Preparing search index...

    Class WorkingMemory

    A context implementation that should be used whenever input data needs to be processed.

    Implements

    Index

    Constructors

    • Create a new instance implementing WorkingContext.

      Parameters

      • data: any

        Any input data that needs to be evaluated.

      • workspace: Workspace

        the current workspace, used to access rules, constants, and other shared data.

      • OptionalsharedData: any

        optional additional data that should be accessible to the output but not altered.

      • Optionallogger: ILogger

        optional logger instance to use for this context. If not provided, a default logger will be created.

      Returns WorkingMemory

    Properties

    cache: Map<string, any> = ...
    cacheMetrics: { sets: number; hits: number; misses: number } = ...

    Methods

    • Check if the context contains a constant for the given key. Nested keys are not allowed.

      Parameters

      • key: string

        the key to check in the constants.

      Returns boolean

      true if the constant exists, false otherwise.

    • Get a constant value from the context using the given key. Nested keys are not allowed.

      Parameters

      • key: string

        the key to look up in the constants.

      Returns any

      the constant value associated with the key, or undefined if the key is not found.

    • Check if the context contains data for the given key or path. Nested keys can be accessed using dot notation (e.g., "user.name").

      Parameters

      • key: string

        the key to check in the context.

      Returns boolean

      true if the key exists in the context, false otherwise.

    • Read data from the context using the given key or path. This method will first attempt to retrieve the value from the context's data. If the value is not found in the data, it will then attempt to retrieve it from the context's constants. Nested keys can be accessed using dot notation (e.g., "user.name").

      Parameters

      • key: string

        the key to look up in the context.

      Returns any

      the value associated with the key, or undefined if the key is not found.

    • Get the root-level keys of the context. This can be useful for determining what data is available in the context and for debugging purposes.

      Returns string[]

      an array of root-level keys in the context.

    • Set an output value in the context with the given key.

      Parameters

      • key: string

        the key to associate with the output value.

      • value: any

        the value to set for the given key.

      Returns void

    • Get an output value from the context using the given key, excluding any shared data. Nested keys can be accessed using dot notation (e.g., "result.value"). If no key is provided, all output data will be returned.

      Parameters

      • Optionalkey: string

        the key to look up in the outputs.

      Returns any

      the output value associated with the key, or undefined if the key is not found.

    • Get the value kept under a given identifer.

      Parameters

      • id: string

        the identifer to look for.

      Returns any

      the value kept under that identifer, or undefined if the id was not found.

    • Delete a single identifier and its value, or entirely delete all values.

      Parameters

      • Optionalid: string

        the identifier to delete. If not provided, the entire cache will be cleared.

      Returns void

    • Retrieve metrics for this cache instance. This is mainly a debugging/monitoring method.

      Returns { sets: number; hits: number; misses: number }

      a metrics object containing sets, hits, and misses.