SerenityJS
    Preparing search index...

    Introduction

    Plugins are the fundamental building blocks of SerenityJS. They are used to add additional functionality to the server, which allows total control over the server.

    There are 2 types of plugins that are defined in the PluginType enum: Addon & Api

    Addon plugins add additional functionality to the server, without an exposed API. This means external plugins cannot directly interact with the plugins API. Api plugins add additional functionality to the server, with an exposed API for other plugins to use. This means external plugins can directly interact with the plugins API.

    import { Plugin, PluginType, PluginEvents } from "@serenityjs/plugins";

    class SamplePlugin extends Plugin {
    public readonly type = PluginType.Addon;

    public constructor() {
    super("sample-plugin", "1.0.0");
    }

    public onInitialize(): void {}

    public onStartUp(): void {}

    public onShutDown(): void {}
    }

    export default new SamplePlugin();

    Type Parameters

    • T = unknown

    Hierarchy

    • Emitter<T>
      • Plugin

    Implements

    Index

    Constructors

    • Create a new plugin instance.

      Type Parameters

      • T = unknown

      Parameters

      • identifier: string

        The identifier of the plugin.

      • version: string

        The version of the plugin.

      • Optionaloptions: Partial<PluginOptions>

        The options of the plugin.

      Returns Plugin<T>

    Properties

    blocks: PluginBlockRegistry = ...

    The block registry for the plugin.

    Only register types/traits during the onInitialize event.

    entities: PluginEntityRegistry = ...

    The entity registry for the plugin.

    Only register types/traits during the onInitialize event.

    identifier: string

    The identifier of the plugin.

    isBundled: boolean

    Whether or not the plugin is bundled.

    This is only available after the plugin is initialized.

    items: PluginItemRegistry = ...

    The item registry for the plugin.

    Only register types/traits during the onInitialize event.

    logger: Logger

    The logger for the plugin.

    path: string

    The path to the plugin.

    This is only available after the plugin is initialized.

    pipeline: Pipeline

    The plugin pipeline the plugin is in.

    This is only available after the plugin is initialized.

    priority: PluginPriority = PluginPriority.Normal

    The priority of the plugin.

    This is used to determine the order in which plugins are loaded.

    serenity: Serenity

    The serenity instance of the server.

    This is only available after the plugin is initialized.

    The type of the plugin.

    version: string

    The version of the plugin.

    Accessors

    • get maxListeners(): number

      The maximum number of listeners for the plugin.

      Returns number

    • set maxListeners(value: number): void

      The maximum number of listeners for the plugin.

      Parameters

      • value: number

      Returns void

    Methods

    • Type Parameters

      • K extends string | number | symbol

      Parameters

      • event: K
      • listener: Listener<ForceArray<T[K]>>

      Returns this

    • Type Parameters

      • K extends string | number | symbol

      Parameters

      • event: K
      • listener: Listener<ForceArray<T[K]>, boolean>

      Returns this

    • Type Parameters

      • K extends string | number | symbol

      Parameters

      • event: K
      • ...arguments_: ForceArray<T[K]>

      Returns boolean

    • Type Parameters

      • K extends string | number | symbol

      Parameters

      • event: K
      • listener: Listener<ForceArray<T[K]>>

      Returns this

    • Type Parameters

      • K extends string | number | symbol

      Parameters

      • event: K
      • listener: Listener<ForceArray<T[K]>>

      Returns this

    • Type Parameters

      • K extends string | number | symbol

      Parameters

      • event: K
      • listener: Listener<ForceArray<T[K]>>

      Returns this

    • Type Parameters

      • K extends string | number | symbol

      Parameters

      • event: K
      • listener: Listener<ForceArray<T[K]>, boolean>

      Returns this

    • Type Parameters

      • K extends string | number | symbol

      Parameters

      • event: K
      • listener: Listener<ForceArray<T[K]>>

      Returns this

    • Type Parameters

      • K extends string | number | symbol

      Parameters

      • event: K
      • listener: Listener<ForceArray<T[K]>>

      Returns this

    • Type Parameters

      • K extends string | number | symbol

      Parameters

      • Optionalevent: K

      Returns this

    • Type Parameters

      • K extends string | number | symbol

      Parameters

      • Optionalevent: K

      Returns this

    • Type Parameters

      • K extends string | number | symbol

      Parameters

      • Optionalevent: K

      Returns this

    • Type Parameters

      • K extends string | number | symbol

      Parameters

      • event: K
      • listener: Listener<ForceArray<T[K]>, boolean>

      Returns this

    • Parameters

      • path: string

      Returns this

    • Resolve a plugin by its identifier

      Type Parameters

      Parameters

      • identifier: string

        The identifier of the plugin to resolve.

      Returns null | T

      The plugin instance if found, otherwise null.