BSB Node.js Type Definitions
    Preparing search index...

    Class BSBEvents<ReferencedConfig>Abstract

    Type Parameters

    Index

    Constructors

    Properties

    appId: string = "tbd"

    The unique app id of the app that is running

    mode: DEBUG_MODE = "development"

    The mode the app is running in

    production (production mode - no debug)
    
    production-debug (production mode - debug)
    
    development (development mode - debug)
    
    cwd: string

    The current working directory of the app

    packageCwd: string

    The current working directory of the plugin

    pluginCwd: string

    The current working directory of the service

    pluginName: string

    The name of the plugin This is also the mapped name, or the name defined in the config rather than it's original defined name

    region?: string

    The deployment region for resource context

    config: ConfigPropertyTypeSafe<
        ReferencedConfig extends null
            ? null
            : BSBReferencePluginConfigDefinition<ReferencedConfig> & BSBReferenceConfigType,
    >

    The config of the plugin

    Methods

    • Run lifecycle method for events plugins.

      This method is inherited from the base plugin class but is not used by events plugins. Events plugins are initialized during the init phase and begin processing events immediately. They do not require a separate run phase.

      Returns void

      void

      Events plugins establish their event bus connections and listeners during initialization. The event routing is active as soon as init completes. Therefore, this method intentionally performs no operation.

      // Events plugins do not need to implement run()
      // The base class provides this no-op implementation
      export class MyEventsPlugin extends BSBEvents<MyConfig> {
      // No run() override needed
      }
    • Listens for events that are emitted by other plugins Broadcast events are emitted and received by all plugins

      Parameters

      • trace: Observable

        The trace object for tracking the operation

      • pluginName: string

        The name of the plugin that is being listened to

      • event: string

        The event to listen for

      • listener: (trace: Observable, args: any[]) => Promise<void>

        The function to call when the event is received

      Returns Promise<void>

      Promise that resolves when the event listener has been registered

    • Emits an event that is received by all plugins

      Parameters

      • trace: Observable

        The trace object for tracking the operation

      • pluginName: string

        The name of the plugin that is emitting the event

      • event: string

        The event to emit

      • args: any[]

        The arguments to pass to the event listener

      Returns Promise<void>

      Promise that resolves when the event has been emitted

    • Listens for events that are emitted by other plugins Events are emitted and received by a single plugin

      Parameters

      • trace: Observable

        The trace object for tracking the operation

      • pluginName: string

        The name of the plugin that is being listened to

      • event: string

        The event to listen for

      • listener: (trace: Observable, args: any[]) => Promise<void>

        The function to call when the event is received

      Returns Promise<void>

      Promise that resolves when the event listener has been registered

    • Emits an event that is received by a single plugin

      Parameters

      • trace: Observable

        The trace object for tracking the operation

      • pluginName: string

        The name of the plugin that is emitting the event

      • event: string

        The event to emit

      • args: any[]

        The arguments to pass to the event listener

      Returns Promise<void>

      Promise that resolves when the event has been emitted

    • Listens for events that are emitted by other plugins and return a value Events are emitted and received by a single plugin

      Parameters

      • trace: Observable

        The trace object for tracking the operation

      • pluginName: string

        The name of the plugin that is being listened to

      • event: string

        The event to listen for

      • listener: (trace: Observable, args: any[]) => Promise<any>

        The function to call when the event is received

      Returns Promise<void>

      Promise that resolves when the event listener has been registered

    • Emits an event that is received by a single plugin and returns a value

      Parameters

      • trace: Observable

        The trace object for tracking the operation

      • pluginName: string

        The name of the plugin that is emitting the event

      • event: string

        The event to emit

      • timeoutSeconds: number

        The number of seconds to wait for the value to be returned

      • args: any[]

        The arguments to pass to the event listener

      Returns Promise<any>

      Promise that resolves when the event has been emitted and the value has been returned

    • Sets up a receive stream to receive a stream from another plugin

      Parameters

      • trace: Observable

        The trace object for tracking the operation

      • pluginName: string

        The name of the plugin that is emitting the event

      • event: string

        The event to listen for

      • listener: (trace: Observable, error: Error | null, stream: Readable) => Promise<void>

        The function to call when the stream is received

      • OptionaltimeoutSeconds: number

        The number of seconds to wait for the stream to be received

      Returns Promise<string>

      Promise that resolves with the stream id that can be used to stream data to the listener

    • Sets up a send stream to send a stream to another plugin that created a receive stream

      Parameters

      • trace: Observable

        The trace object for tracking the operation

      • pluginName: string

        The name of the plugin that is emitting the event

      • event: string

        The event to listen for

      • streamId: string

        The id of the stream to send data to

      • stream: Readable

        The stream to send data from

      Returns Promise<void>

      Promise that resolves when the stream has been sent

    • Dispose Optional function to be called when the plugin is being disposed

      Returns void

      dispose?(): void; //to not use it
      
      dispose() { your code here };
      
    • Init Optional function to be called when the plugin is being initialized Can be sync or async

      Parameters

      • obs: Observable

        Observable context with logging, metrics, and trace information

      Returns void | Promise<void>

      v9 BREAKING CHANGE: Now requires Observable instead of DTrace. Observable provides unified access to logging, metrics, and tracing with automatic context propagation.

      async init(obs: Observable) {
      obs.log.info("Initializing plugin");
      // Set attributes for all child operations
      const withVersion = obs.setAttribute("plugin.version", "1.0.0");
      }