Options
All
  • Public
  • Public/Protected
  • All
Menu

Some common terms:

  • Plugger: the main class that can act as both a plugin and a loader.

  • Plugin: a Plugger instance that acts as a plugin.

  • Loader: a Plugger instance that acts as a loader.

  • Loaded plugin: a plugin that has been added/loaded to a loader by using the addPlugin() function.

  • Initialized plugin: a plugin that has been initialized by a loader by using the initPlugin() function.

Hierarchy

  • default
    • Plugger

Index

Constructor

  • new Plugger(name?: string): Plugger
  • Creates a Plugger instance.

    example
    const Plugger = require('./pluggers').default;
    const instance = new Plugger('master');
    category

    Constructor

    Parameters

    • name: string = ""

      The name of the instance.

    Returns Plugger

Base

errorTypes: { RequirementError: typeof RequirementError; ConflictError: typeof ConflictError; LoadError: typeof LoadError; InitializeError: typeof InitializeError } = errorTypes

Contains custom error classes.

Type declaration

  • RequirementError: typeof RequirementError
  • ConflictError: typeof ConflictError
  • LoadError: typeof LoadError
  • InitializeError: typeof InitializeError
metadata: { name: string; version?: string } = ...

The metadata of the instance.

Type declaration

  • [key: string]: unknown
  • name: string
  • Optional version?: string
  • getName(): string
  • Returns the name of the instance that is stored in instance.metadata.name.

    Returns string

    The name of the instance.

Plugin

pluginConfig: PluginConfigInterface = ...

Plugin behavior configurations.

pluginCallbacks: CallbacksInterface = ...
  • getContext(): {}
  • Returns the context of the instance.

    This context is exclusive to the instance only and directly mutable. Note that the context is not the state of the instance. It is designed to be used internally by the instance.

    Returns {}

    The context of the instance.

    • [key: string]: unknown
  • getRequiredPlugins(): { name: string; version?: string }[]
  • Returns the list of required plugins and their metadata.

    Returns { name: string; version?: string }[]

    A list of metadata.

  • removeRequiredPlugin(name: string): Plugger
  • Removes a plugin from the instance's required plugins.

    Parameters

    • name: string

      The name of the plugin.

    Returns Plugger

    The current instance.

  • requirePlugin(metadata: { name: string; version?: string }): Plugger
  • Adds metadata as a required plugin for the instance.

    A loader will check if a plugin with the same metadata is loaded and initialized first before trying to initialize the instance. The property 'version' of metadata and its nested objects supports semantic versioning syntax.

    Parameters

    • metadata: { name: string; version?: string }

      The metadata of the plugin.

      • [key: string]: unknown
      • name: string
      • Optional version?: string

    Returns Plugger

    The current instance.

  • requires(metadata: { name: string; version?: string }): boolean
  • Checks whether the instance requires a plugin or not.

    Parameters

    • metadata: { name: string; version?: string }

      The metadata of the plugin.

      • [key: string]: unknown
      • name: string
      • Optional version?: string

    Returns boolean

    true if the instance requires the plugin, false if not.

  • getState(): unknown
  • Returns the state of the instance

    Returns unknown

  • getStatus(): "ready" | "busy" | "initialized" | "crashed"
  • Returns the status of the instance

    Returns "ready" | "busy" | "initialized" | "crashed"

  • isInitialized(): boolean
  • Returns whether the instance is initialized or not.

    Returns boolean

  • selfInit(pluginsStates?: any): Promise<Plugger>
  • Runs the init callback function.

    Parameters

    • pluginsStates: any = {}

    Returns Promise<Plugger>

  • Runs the shutdown callback function.

    Returns Promise<Plugger>

  • createSession(func: () => unknown): Promise<unknown>
  • internal

    Parameters

    • func: () => unknown

      Function to be run subsequently.

        • (): unknown
        • Returns unknown

    Returns Promise<unknown>

    The return value of the function

Loader

  • getPlugins(): default[]
  • Returns all loaded plugins.

    Returns default[]

    An array of Plugger instances.

  • getPlugin(name: string): null | default
  • Returns the requested plugin.

    Parameters

    • name: string

      The name of the plugin.

    Returns null | default

    A Plugger instance, or null if not found.

  • addPlugin(plugin: default, priority?: { priority: undefined | number }): Plugger
  • Loads the plugin to the instance.

    Parameters

    • plugin: default

      The plugin that you want to load.

    • priority: { priority: undefined | number } = {}

      The load order priority of the plugin.

      • priority: undefined | number

    Returns Plugger

    The current instance.

  • removePlugin(plugin: default): Plugger
  • Removes the plugin from the instance.

    Parameters

    • plugin: default

      The plugin that you want to remove/unload.

    Returns Plugger

    The current instance.

  • getLoadOrder(): default[]
  • Returns the load order of the instance.

    Returns default[]

    All loaded plugins, sorted to their load order.

  • Sorts the load order of the instance.

    Plugins that are required by other plugins are set to initialize first. Their priorities are also taken into consideration.

    Returns Plugger

    The current instance.

  • hasLoaded(plugin: default): boolean
  • Returns wheter the plugin is loaded by the instance or not.

    Parameters

    • plugin: default

    Returns boolean

    true if the plugin is loaded by the instance, else false.

  • initPlugin(plugin: default): Promise<Plugger>
  • Initializes the plugin asynchronously.

    Parameters

    • plugin: default

      The plugin that you want to initialize.

    Returns Promise<Plugger>

    A Promise that resolves to the current instance.

  • Initializes all loaded plugins asynchronously in parallel.

    Returns Promise<Plugger>

    A Promise that resolves to the current instance.

  • shutdownPlugin(plugin: default): Promise<Plugger>
  • Shuts down the plugin asynchronously.

    Parameters

    • plugin: default

      The plugin that you want to shutdown.

    Returns Promise<Plugger>

    A Promise that resolves to the current instance.

  • Shuts down all loaded plugins asynchronously in parallel.

    Returns Promise<Plugger>

    A Promise that resolves to the current instance.

  • Adds an event listener that shuts down all loaded plugins when the process is exiting.

    This will run a function that executes instance.shutdownAll() when an exit event signal is emitted by process. It is recommended to only run this method on your main loader instance, as to not pollute the event with many listeners (NodeJS limited the number of listeners to 10 per event by default). Running this method multiple times on the same instance won't register multiple listeners.

    Returns Plugger

    The current instance.

  • Removes the attached event listener from the process.

    Running this method without running attachExitListener() first won't do anything.

    Returns Plugger

Generated using TypeDoc