Base class for communications. This class can be sub-classed if desired if you would like to modify the logic across ALL actions. To do so, sub-class this class and use the

Register Class

decorator from the @memberjunction/global package to register your sub-class with the ClassFactory. This will cause your sub-class to be used instead of this base class when the Metadata object insantiates the ActionEngine.

Hierarchy (view full)

Constructors

  • While the BaseEngine class is a singleton, normally, it is possible to have multiple instances of the class in an application if the class is used in multiple contexts that have different providers.

    Returns CommunicationEngineBase

Properties

_Metadata: {
    BaseMessageTypes: CommunicationBaseMessageTypeEntity[];
    EntityCommunicationFields: EntityCommunicationFieldEntity[];
    EntityCommunicationMessageTypes: EntityCommunicationMessageTypeEntity[];
    ProviderMessageTypes: CommunicationProviderMessageTypeEntity[];
    Providers: CommunicationProviderEntityExtended[];
} = ...

Type declaration

Accessors

  • get Configs(): BaseEnginePropertyConfig[]
  • Returns a COPY of the metadata configs array for the engine. This is a copy so you can't modify the original configs by modifying this array.

    Returns BaseEnginePropertyConfig[]

  • get ContextUser(): UserInfo
  • Returns the context user set for the object, this is set via the Config() method.

    Returns UserInfo

  • get DataChange$(): Observable<EngineDataChangeEvent>
  • Observable that emits when any data property changes due to a refresh. Subscribe to this to react to engine data updates (e.g., sync Angular observables).

    Events are emitted after data is refreshed in response to BaseEntity save/delete events. The event includes the full config and the new data array.

    Returns Observable<EngineDataChangeEvent>

    Example

    UserInfoEngine.Instance.DataChange$.subscribe(event => {
    if (event.config.PropertyName === 'UserApplications') {
    // Sync local state with engine's updated data
    this.refreshLocalAppList();
    }
    });
  • get EntityEventDebounceTime(): number
  • Overridable property to set the debounce time for entity events. Default is 1500 milliseconds (1.5 seconds). This debounce time is used when immediate array mutations cannot be applied (e.g., when Filter, OrderBy, or AdditionalLoading overrides are present) and a full view refresh is required.

    Note: When immediate mutations ARE possible (no Filter, OrderBy, or AdditionalLoading override), updates happen synchronously without any debounce delay.

    Returns number

  • get GlobalKey(): string
  • Returns string

  • get Loaded(): boolean
  • Returns true if the data has been loaded, false otherwise.

    Returns boolean

  • get LoadingSubject(): BehaviorSubject<boolean>
  • Returns the loading subject. You can call await Config() and after Config() comes back as true that means you're loaded. However you can also directly subscribe to this subject to get updates on the loading status.

    Returns BehaviorSubject<boolean>

  • get ProviderToUse(): IMetadataProvider
  • Returns the metadata provider to use for the engine. If a provider is set via the Config method, that provider will be used, otherwise the default provider will be used.

    Returns IMetadataProvider

  • get RunViewProviderToUse(): IRunViewProvider
  • Returns the RunView provider to use for the engine. This is the same underlying object as the

    Returns IRunViewProvider

  • get ProviderInstances(): any
  • Returns any

Methods

  • Adds a dynamic metadata configuration at runtime.

    Parameters

    Returns Promise<void>

  • This method is called to configure the engine. It loads the metadata and caches it in the GlobalObjectStore. You must call this method before doing anything else with the engine. If this method was previously run on the instance of the engine, it will return immediately without re-loading the metadata. If you want to force a reload of the metadata, you can pass true for the forceReload parameter.

    Parameters

    • forceRefresh: boolean = false

      If true, the metadata will be loaded from the database even if it was previously loaded.

    • Optional contextUser: UserInfo

      If you are running on the server side you must pass this in, but it is not required in an environment where a user is authenticated directly, e.g. a browser or other client.

    • Optional provider: IMetadataProvider

    Returns Promise<void>

  • Extended configuration method with object-based options. This provides a more flexible API compared to Config() with positional parameters.

    Internally calls Config() after setting up options that Load() can access.

    Parameters

    Returns Promise<unknown>

    Promise that resolves when configuration is complete

    Example

    await MyEngine.Instance.ConfigEx({
    forceRefresh: true,
    contextUser: currentUser
    });
  • This method handles the debouncing process, by default using the EntityEventDebounceTime property to set the debounce time. Debouncing is done on a per-entity basis, meaning that if the debounce time passes for a specific entity name, the event will be processed. This is done to prevent multiple events from being processed in quick succession for a single entity which would cause a lot of wasted processing.

    Override this method if you want to change how debouncing time such as having variable debounce times per-entity, etc.

    Parameters

    Returns Promise<boolean>

  • The Global Object Store is a place to store global objects that need to be shared across the application. Depending on the execution environment, this could be the window object in a browser, or the global object in a node environment, or something else in other contexts. The key here is that in some cases static variables are not truly shared because it is possible that a given class might have copies of its code in multiple paths in a deployed application. This approach ensures that no matter how many code copies might exist, there is only one instance of the object in question by using the Global Object Store.

    Returns typeof globalThis

  • This method handles the individual base entity event. For events that can use immediate array mutations (no Filter, OrderBy, or AdditionalLoading override), processing happens synchronously without debounce. For events that require full view refresh, debouncing is applied to batch rapid successive changes.

    Override this method if you want to have a different handling for the filtering of events that are debounced or if you don't want to debounce at all you can do that in an override of this method.

    Parameters

    Returns Promise<boolean>

  • Subclasses of BaseEngine can override this method to handle individual MJGlobal events. This is typically done to optimize the way refreshes are done when a BaseEntity is updated. If you are interested in only BaseEntity events, override the HandleIndividualBaseEntityEvent method instead as this method primarily serves to filter all the events we get from MJGlobal and only pass on BaseEntity events to HandleIndividualBaseEntityEvent.

    Parameters

    Returns Promise<boolean>

  • All BaseEngine sub-classes get an implementation of IStartupSink so they can be set the auto start in their app container, if desired, simply by adding the

    Parameters

    Returns Promise<void>

    See

    -

    • Config

    Register For Startup

    decorator. The BaseEngine implementation of IStartupSink.HandleStartup is to simply call

  • This method should be called by sub-classes to load up their specific metadata requirements. For more complex metadata loading or for post-processing of metadata loading done here, overide the AdditionalLoading method to add your logic.

    Parameters

    Returns Promise<void>

  • Loads the specified metadata configurations.

    Parameters

    Returns Promise<void>

  • Handles the process of loading multiple entity configs in a single network call via RunViews()

    Parameters

    Returns Promise<void>

  • Loads a single metadata configuration.

    Parameters

    Returns Promise<void>

  • Notify listeners that a data property has changed. Called automatically by HandleSingleViewResult after data refresh and by applyImmediateMutation for array operations. Subclasses can also call this manually when modifying data arrays directly.

    Parameters

    • config: BaseEnginePropertyConfig

      The configuration for the property that changed

    • data: unknown[]

      The current data array

    • Optional changeType: "refresh" | "add" | "update" | "delete"

      The type of change: 'refresh', 'add', 'update', or 'delete'

    • Optional affectedEntity: BaseEntity<unknown>

      For add/update/delete, the entity that was affected

    Returns void

  • This method does the actual work of processing the entity event. It is not directly called from the event handler because we want to first debounce the events which also introduces a delay which is usually desirable so that our processing is typically outside of the scope of any transaction processing that would have originated the event.

    This is the best method to override if you want to change the actual processing of an entity event but do NOT want to modify the debouncing behavior.

    Parameters

    Returns Promise<void>

  • Refreshes all items

    Returns Promise<void>

  • Refreshes a specific item.

    Parameters

    • propertyName: string

      The name of the property to refresh

    Returns Promise<void>

  • Removes a dynamic metadata configuration at runtime.

    Parameters

    • propertyName: string

      The name of the property to remove

    Returns void

  • Internal method to set the provider when an engine is loaded

    Parameters

    Returns void

  • This method is responsible for registering for MJGlobal events and listening for BaseEntity events where those BaseEntity are related to the engine's configuration metadata. The idea is to auto-refresh the releated configs when the BaseEntity is updated.

    Returns Promise<boolean>

  • Helper method for sub-classes to have a single line of code that will make sure the data is loaded before proceeding and will throw an error if not loaded.

    Returns void

  • Applies an immediate array mutation based on the entity event type. This is faster than running a full view refresh for simple add/update/delete operations.

    Parameters

    Returns void

  • Determines if an immediate array mutation can be used instead of running a full view refresh. Immediate mutations are only safe when:

    1. The config has no Filter (no server-side filtering that might exclude the entity)
    2. The config has no OrderBy (no server-side ordering that would need to be maintained)
    3. The subclass has not overridden AdditionalLoading (no post-processing that depends on full data)

    Parameters

    Returns boolean

    true if immediate mutation is safe, false if a full view refresh is needed

  • Finds an entity in the array by matching all primary key columns. Supports composite primary keys by comparing all PrimaryKey fields from EntityInfo.

    Parameters

    • dataArray: BaseEntity<unknown>[]

      The array of entities to search

    • targetEntity: BaseEntity<unknown>

      The entity to find (using its primary key values)

    Returns number

    The index of the matching entity, or -1 if not found

  • Checks if the current instance has overridden the AdditionalLoading method. We do this by comparing the method to the base class's method.

    Returns boolean

    true if AdditionalLoading is overridden, false if using the base implementation

  • Checks if the exact entity object reference is already in the config's data array. Used to skip unnecessary refreshes for UPDATE events where the object was mutated in place.

    Parameters

    Returns boolean

    true if the exact object reference is already in the array

  • Checks if an entity is in the config's data array by object reference OR by primary key match. Used for DELETE events where we need to know if the entity still exists in the array. The object reference may still exist (entity.Delete() just marks it deleted), but if it was manually spliced out by engine code, we check by primary key as fallback.

    Parameters

    Returns boolean

    true if the entity is in the array (by reference or by primary key)

  • This method will check for the existence of an instance of this engine class that is tied to a specific provider. If one exists, it will return it, otherwise it will create a new instance

    Type Parameters

    • T

    Parameters

    Returns BaseEngine<T>

  • Returns the singleton instance of the class. If the instance does not exist, it is created and stored in the Global Object Store. If className is provided it will be used as part of the key in the Global Object Store, otherwise the actual class name will be used. NOTE: the class name used by default is the lowest level of the object hierarchy, so if you have a class that extends another class, the lowest level class name will be used.

    Type Parameters

    Parameters

    • this: (new () => T)
        • new (): T
        • Returns T

    • Optional className: string

    Returns T