supertokens-node
    Preparing search index...

    Interface SessionContext

    interface SessionContext {
        _debug: Debugger;
        _parent?: Context;
        configResolver: ConfigurationResolver;
        name: string;
        registry: Map<string, Binding<any>>;
        request: Request;
        response: Response;
        responseFinished: boolean;
        scope: BindingScope;
        session?: SessionContainer;
        subscriptionManager: ContextSubscriptionManager;
        tagIndexer: ContextTagIndexer;
        get parent(): undefined | Context;
        _findByTagIndex<ValueType = any>(
            tag: RegExp | BindingTag,
        ): Readonly<Binding<ValueType>>[];
        _mergeWithParent<ValueType>(
            childList: Readonly<Binding<ValueType>>[],
            parentList?: Readonly<Binding<ValueType>>[],
        ): Readonly<Binding<ValueType>>[];
        "[captureRejectionSymbol]"<K>(
            error: Error,
            event: string | symbol,
            ...args: AnyRest,
        ): void;
        add(binding: Binding<unknown>): this;
        addListener<K>(
            eventName: string | symbol,
            listener: (...args: any[]) => void,
        ): this;
        bind<ValueType = any>(key: BindingAddress<ValueType>): Binding<ValueType>;
        close(): void;
        configure<ConfigValueType = any>(
            key?: BindingAddress,
        ): Binding<ConfigValueType>;
        contains(key: BindingAddress): boolean;
        createView<T = unknown>(
            filter: BindingFilter,
            comparator?: BindingComparator,
            options?: Omit<ResolutionOptions, "session">,
        ): ContextView<T>;
        debug(...args: unknown[]): void;
        emit<K>(eventName: string | symbol, ...args: AnyRest): boolean;
        emitError(err: unknown): void;
        emitEvent<T extends ContextEvent>(type: string, event: T): void;
        eventNames(): (string | symbol)[];
        find<ValueType = any>(
            pattern?: string | RegExp | BindingFilter,
        ): Readonly<Binding<ValueType>>[];
        findByTag<ValueType = any>(
            tagFilter: RegExp | BindingTag,
        ): Readonly<Binding<ValueType>>[];
        findOrCreateBinding<T>(
            key: BindingAddress<T>,
            policy?: BindingCreationPolicy,
        ): Binding<T>;
        get<ValueType>(
            keyWithPath: BindingAddress<ValueType>,
            session?: ResolutionSession,
        ): Promise<ValueType>;
        get<ValueType>(
            keyWithPath: BindingAddress<ValueType>,
            options: ResolutionOptions,
        ): Promise<undefined | ValueType>;
        getBinding<ValueType = any>(
            key: BindingAddress<ValueType>,
        ): Binding<ValueType>;
        getBinding<ValueType>(
            key: BindingAddress<ValueType>,
            options?: { optional?: boolean },
        ): undefined | Binding<ValueType>;
        getConfig<ConfigValueType>(
            key: BindingAddress,
            propertyPath?: string,
            resolutionOptions?: ResolutionOptions,
        ): Promise<undefined | ConfigValueType>;
        getConfigAsValueOrPromise<ConfigValueType>(
            key: BindingAddress,
            propertyPath?: string,
            resolutionOptions?: ResolutionOptions,
        ): ValueOrPromise<undefined | ConfigValueType>;
        getConfigSync<ConfigValueType>(
            key: BindingAddress,
            propertyPath?: string,
            resolutionOptions?: ResolutionOptions,
        ): undefined | ConfigValueType;
        getDebugNamespace(): string;
        getMaxListeners(): number;
        getOwnerContext(
            keyOrBinding: BindingAddress | Readonly<Binding<unknown>>,
        ): undefined | Context;
        getResolutionContext(
            binding: Readonly<Binding<unknown>>,
        ): undefined | Context;
        getScopedContext(
            scope: APPLICATION | SERVER | REQUEST,
        ): undefined | Context;
        getSync<ValueType>(
            keyWithPath: BindingAddress<ValueType>,
            session?: ResolutionSession,
        ): ValueType;
        getSync<ValueType>(
            keyWithPath: BindingAddress<ValueType>,
            options?: ResolutionOptions,
        ): undefined | ValueType;
        getValueOrPromise<ValueType>(
            keyWithPath: BindingAddress<ValueType>,
            optionsOrSession?: ResolutionOptionsOrSession,
        ): ValueOrPromise<undefined | ValueType>;
        inspect(options?: ContextInspectOptions): JSONObject;
        isBound(key: BindingAddress): boolean;
        isSubscribed(observer: ContextObserver): boolean;
        isVisibleTo(ctx: Context): boolean;
        listenerCount<K>(eventName: string | symbol, listener?: Function): number;
        listeners<K>(eventName: string | symbol): Function[];
        off<K>(
            eventName: string | symbol,
            listener: (...args: any[]) => void,
        ): this;
        on(eventName: "bind" | "unbind", listener: ContextEventListener): this;
        on(event: string | symbol, listener: (...args: any[]) => void): this;
        once(eventName: "bind" | "unbind", listener: ContextEventListener): this;
        once(event: string | symbol, listener: (...args: any[]) => void): this;
        prependListener<K>(
            eventName: string | symbol,
            listener: (...args: any[]) => void,
        ): this;
        prependOnceListener<K>(
            eventName: string | symbol,
            listener: (...args: any[]) => void,
        ): this;
        rawListeners<K>(eventName: string | symbol): Function[];
        removeAllListeners(eventName?: string | symbol): this;
        removeListener<K>(
            eventName: string | symbol,
            listener: (...args: any[]) => void,
        ): this;
        setMaxListeners(n: number): this;
        setupBindings(): void;
        setupConfigurationResolverIfNeeded(): ConfigurationResolver;
        subscribe(observer: ContextEventObserver): Subscription;
        toJSON(): JSONObject;
        unbind(key: BindingAddress): boolean;
        unsubscribe(observer: ContextEventObserver): boolean;
    }

    Hierarchy

    • MiddlewareContext
      • SessionContext
    Index

    Properties

    _debug: Debugger

    A debug function which can be overridden by subclasses.

    import debugFactory from 'debug';
    const debug = debugFactory('loopback:context:application');
    export class Application extends Context {
    super('application');
    this._debug = debug;
    }
    _parent?: Context

    Parent context

    configResolver: ConfigurationResolver

    Configuration resolver

    name: string

    Name of the context

    registry: Map<string, Binding<any>>

    Key to binding map as the internal registry

    request: Request
    response: Response
    responseFinished: boolean

    A flag to tell if the response is finished.

    scope: BindingScope

    Scope for binding resolution

    subscriptionManager: ContextSubscriptionManager

    Manager for observer subscriptions

    tagIndexer: ContextTagIndexer

    Indexer for bindings by tag

    Accessors

    • get parent(): undefined | Context
      Internal

      Getter for ContextSubscriptionManager

      Returns undefined | Context

    Methods

    • Find bindings by tag leveraging indexes

      Type Parameters

      • ValueType = any

      Parameters

      • tag: RegExp | BindingTag

        Tag name pattern or name/value pairs

      Returns Readonly<Binding<ValueType>>[]

    • Type Parameters

      • ValueType

      Parameters

      • childList: Readonly<Binding<ValueType>>[]
      • OptionalparentList: Readonly<Binding<ValueType>>[]

      Returns Readonly<Binding<ValueType>>[]

    • Type Parameters

      • K

      Parameters

      • error: Error
      • event: string | symbol
      • ...args: AnyRest

      Returns void

    • Add a binding to the context. If a locked binding already exists with the same key, an error will be thrown.

      Parameters

      • binding: Binding<unknown>

        The configured binding to be added

      Returns this

    • Alias for emitter.on(eventName, listener).

      Type Parameters

      • K

      Parameters

      • eventName: string | symbol
      • listener: (...args: any[]) => void

      Returns this

      v0.1.26

    • Create a binding with the given key in the context. If a locked binding already exists with the same key, an error will be thrown.

      Type Parameters

      • ValueType = any

      Parameters

      Returns Binding<ValueType>

    • Close the context: clear observers, stop notifications, and remove event listeners from its parent context.

      Returns void

      This method MUST be called to avoid memory leaks once a context object is no longer needed and should be recycled. An example is the RequestContext, which is created per request.

    • Create a corresponding binding for configuration of the target bound by the given key in the context.

      For example, ctx.configure('controllers.MyController').to({x: 1}) will create binding controllers.MyController:$config with value {x: 1}.

      Type Parameters

      • ConfigValueType = any

      Parameters

      • Optionalkey: BindingAddress

        The key for the binding to be configured

      Returns Binding<ConfigValueType>

    • Check if a binding exists with the given key in the local context without delegating to the parent context

      Parameters

      • key: BindingAddress

        Binding key

      Returns boolean

    • Create a view of the context chain with the given binding filter

      Type Parameters

      • T = unknown

      Parameters

      • filter: BindingFilter

        A function to match bindings

      • Optionalcomparator: BindingComparator

        A function to sort matched bindings

      • Optionaloptions: Omit<ResolutionOptions, "session">

        Resolution options

      Returns ContextView<T>

    • Wrap the debug statement so that it always print out the context name as the prefix

      Parameters

      • ...args: unknown[]

        Arguments for the debug

      Returns void

    • Synchronously calls each of the listeners registered for the event namedeventName, in the order they were registered, passing the supplied arguments to each.

      Returns true if the event had listeners, false otherwise.

      import { EventEmitter } from 'node:events';
      const myEmitter = new EventEmitter();

      // First listener
      myEmitter.on('event', function firstListener() {
      console.log('Helloooo! first listener');
      });
      // Second listener
      myEmitter.on('event', function secondListener(arg1, arg2) {
      console.log(`event with parameters ${arg1}, ${arg2} in second listener`);
      });
      // Third listener
      myEmitter.on('event', function thirdListener(...args) {
      const parameters = args.join(', ');
      console.log(`event with parameters ${parameters} in third listener`);
      });

      console.log(myEmitter.listeners('event'));

      myEmitter.emit('event', 1, 2, 3, 4, 5);

      // Prints:
      // [
      // [Function: firstListener],
      // [Function: secondListener],
      // [Function: thirdListener]
      // ]
      // Helloooo! first listener
      // event with parameters 1, 2 in second listener
      // event with parameters 1, 2, 3, 4, 5 in third listener

      Type Parameters

      • K

      Parameters

      • eventName: string | symbol
      • ...args: AnyRest

      Returns boolean

      v0.1.26

    • Emit an error event

      Parameters

      • err: unknown

        Error

      Returns void

    • A strongly-typed method to emit context events

      Type Parameters

      • T extends ContextEvent

      Parameters

      • type: string

        Event type

      • event: T

        Context event

      Returns void

    • Returns an array listing the events for which the emitter has registered listeners. The values in the array are strings or Symbols.

      import { EventEmitter } from 'node:events';

      const myEE = new EventEmitter();
      myEE.on('foo', () => {});
      myEE.on('bar', () => {});

      const sym = Symbol('symbol');
      myEE.on(sym, () => {});

      console.log(myEE.eventNames());
      // Prints: [ 'foo', 'bar', Symbol(symbol) ]

      Returns (string | symbol)[]

      v6.0.0

    • Find bindings using a key pattern or filter function

      Type Parameters

      • ValueType = any

      Parameters

      • Optionalpattern: string | RegExp | BindingFilter

        A filter function, a regexp or a wildcard pattern with optional * and ?. Find returns such bindings where the key matches the provided pattern.

        For a wildcard:

        • * matches zero or more characters except . and :
        • ? matches exactly one character except . and :

        For a filter function:

        • return true to include the binding in the results
        • return false to exclude it.

      Returns Readonly<Binding<ValueType>>[]

    • Find bindings using the tag filter. If the filter matches one of the binding tags, the binding is included.

      Type Parameters

      • ValueType = any

      Parameters

      • tagFilter: RegExp | BindingTag

        A filter for tags. It can be in one of the following forms:

        • A regular expression, such as /controller/
        • A wildcard pattern string with optional * and ?, such as 'con*' For a wildcard:
          • * matches zero or more characters except . and :
          • ? matches exactly one character except . and :
        • An object containing tag name/value pairs, such as {name: 'my-controller'}

      Returns Readonly<Binding<ValueType>>[]

    • Find or create a binding for the given key

      Type Parameters

      • T

      Parameters

      • key: BindingAddress<T>

        Binding address

      • Optionalpolicy: BindingCreationPolicy

        Binding creation policy

      Returns Binding<T>

    • Get the value bound to the given key, throw an error when no value is bound for the given key.

      Type Parameters

      • ValueType

      Parameters

      • keyWithPath: BindingAddress<ValueType>

        The binding key, optionally suffixed with a path to the (deeply) nested property to retrieve.

      • Optionalsession: ResolutionSession

        Optional session for resolution (accepted for backward compatibility)

      Returns Promise<ValueType>

      A promise of the bound value.

      // get the value bound to "application.instance"
      const app = await ctx.get<Application>('application.instance');

      // get "rest" property from the value bound to "config"
      const config = await ctx.get<RestComponentConfig>('config#rest');

      // get "a" property of "numbers" property from the value bound to "data"
      ctx.bind('data').to({numbers: {a: 1, b: 2}, port: 3000});
      const a = await ctx.get<number>('data#numbers.a');
    • Get the value bound to the given key, optionally return a (deep) property of the bound value.

      Type Parameters

      • ValueType

      Parameters

      • keyWithPath: BindingAddress<ValueType>

        The binding key, optionally suffixed with a path to the (deeply) nested property to retrieve.

      • options: ResolutionOptions

        Options for resolution.

      Returns Promise<undefined | ValueType>

      A promise of the bound value, or a promise of undefined when the optional binding is not found.

      // get "rest" property from the value bound to "config"
      // use `undefined` when no config is provided
      const config = await ctx.get<RestComponentConfig>('config#rest', {
      optional: true
      });
    • Look up a binding by key in the context and its ancestors. If no matching binding is found, an error will be thrown.

      Type Parameters

      • ValueType = any

      Parameters

      Returns Binding<ValueType>

    • Look up a binding by key in the context and its ancestors. If no matching binding is found and options.optional is not set to true, an error will be thrown.

      Type Parameters

      • ValueType

      Parameters

      • key: BindingAddress<ValueType>

        Binding key

      • Optionaloptions: { optional?: boolean }

        Options to control if the binding is optional. If options.optional is set to true, the method will return undefined instead of throwing an error if the binding key is not found.

      Returns undefined | Binding<ValueType>

    • Resolve configuration for the binding by key

      Type Parameters

      • ConfigValueType

      Parameters

      • key: BindingAddress

        Binding key

      • OptionalpropertyPath: string

        Property path for the option. For example, x.y requests for <config>.x.y. If not set, the <config> object will be returned.

      • OptionalresolutionOptions: ResolutionOptions

        Options for the resolution.

      Returns Promise<undefined | ConfigValueType>

    • Get the value or promise of configuration for a given binding by key

      Type Parameters

      • ConfigValueType

      Parameters

      • key: BindingAddress

        Binding key

      • OptionalpropertyPath: string

        Property path for the option. For example, x.y requests for <config>.x.y. If not set, the <config> object will be returned.

      • OptionalresolutionOptions: ResolutionOptions

        Options for the resolution.

        • optional: if not set or set to true, undefined will be returned if no corresponding value is found. Otherwise, an error will be thrown.

      Returns ValueOrPromise<undefined | ConfigValueType>

    • Resolve configuration synchronously for the binding by key

      Type Parameters

      • ConfigValueType

      Parameters

      • key: BindingAddress

        Binding key

      • OptionalpropertyPath: string

        Property path for the option. For example, x.y requests for config.x.y. If not set, the config object will be returned.

      • OptionalresolutionOptions: ResolutionOptions

        Options for the resolution.

      Returns undefined | ConfigValueType

    • Get the debug namespace for the context class. Subclasses can override this method to supply its own namespace.

      Returns string

      export class Application extends Context {
      super('application');
      }

      protected getDebugNamespace() {
      return 'loopback:context:application';
      }
    • Returns the current max listener value for the EventEmitter which is either set by emitter.setMaxListeners(n) or defaults to defaultMaxListeners.

      Returns number

      v1.0.0

    • Get the owning context for a binding or its key

      Parameters

      • keyOrBinding: BindingAddress | Readonly<Binding<unknown>>

        Binding object or key

      Returns undefined | Context

    • Locate the resolution context for the given binding. Only bindings in the resolution context and its ancestors are visible as dependencies to resolve the given binding

      Parameters

      • binding: Readonly<Binding<unknown>>

        Binding object

      Returns undefined | Context

    • Get the context matching the scope

      Parameters

      • scope: APPLICATION | SERVER | REQUEST

        Binding scope

      Returns undefined | Context

    • Get the synchronous value bound to the given key, optionally return a (deep) property of the bound value.

      This method throws an error if the bound value requires async computation (returns a promise). You should never rely on sync bindings in production code.

      Type Parameters

      • ValueType

      Parameters

      • keyWithPath: BindingAddress<ValueType>

        The binding key, optionally suffixed with a path to the (deeply) nested property to retrieve.

      • Optionalsession: ResolutionSession

        Session for resolution (accepted for backward compatibility)

      Returns ValueType

      A promise of the bound value.

      // get the value bound to "application.instance"
      const app = ctx.getSync<Application>('application.instance');

      // get "rest" property from the value bound to "config"
      const config = await ctx.getSync<RestComponentConfig>('config#rest');
    • Get the synchronous value bound to the given key, optionally return a (deep) property of the bound value.

      This method throws an error if the bound value requires async computation (returns a promise). You should never rely on sync bindings in production code.

      Type Parameters

      • ValueType

      Parameters

      • keyWithPath: BindingAddress<ValueType>

        The binding key, optionally suffixed with a path to the (deeply) nested property to retrieve.

      • Optionaloptions: ResolutionOptions

        Options for resolution.

      Returns undefined | ValueType

      The bound value, or undefined when an optional binding is not found.

      // get "rest" property from the value bound to "config"
      // use "undefined" when no config is provided
      const config = await ctx.getSync<RestComponentConfig>('config#rest', {
      optional: true
      });
    • Internal

      Get the value bound to the given key.

      This is an internal version that preserves the dual sync/async result of Binding#getValue(). Users should use get() or getSync() instead.

      Type Parameters

      • ValueType

      Parameters

      • keyWithPath: BindingAddress<ValueType>

        The binding key, optionally suffixed with a path to the (deeply) nested property to retrieve.

      • OptionaloptionsOrSession: ResolutionOptionsOrSession

        Options for resolution or a session

      Returns ValueOrPromise<undefined | ValueType>

      The bound value or a promise of the bound value, depending on how the binding is configured.

      // get the value bound to "application.instance"
      ctx.getValueOrPromise<Application>('application.instance');

      // get "rest" property from the value bound to "config"
      ctx.getValueOrPromise<RestComponentConfig>('config#rest');

      // get "a" property of "numbers" property from the value bound to "data"
      ctx.bind('data').to({numbers: {a: 1, b: 2}, port: 3000});
      ctx.getValueOrPromise<number>('data#numbers.a');
    • Inspect the context and dump out a JSON object representing the context hierarchy

      Parameters

      • Optionaloptions: ContextInspectOptions

        Options for inspect

      Returns JSONObject

    • Check if a key is bound in the context or its ancestors

      Parameters

      • key: BindingAddress

        Binding key

      Returns boolean

    • Check if an observer is subscribed to this context

      Parameters

      • observer: ContextObserver

        Context observer

      Returns boolean

    • Check if this context is visible (same or ancestor) to the given one

      Parameters

      • ctx: Context

        Another context object

      Returns boolean

    • Returns the number of listeners listening for the event named eventName. If listener is provided, it will return how many times the listener is found in the list of the listeners of the event.

      Type Parameters

      • K

      Parameters

      • eventName: string | symbol

        The name of the event being listened for

      • Optionallistener: Function

        The event handler function

      Returns number

      v3.2.0

    • Returns a copy of the array of listeners for the event named eventName.

      server.on('connection', (stream) => {
      console.log('someone connected!');
      });
      console.log(util.inspect(server.listeners('connection')));
      // Prints: [ [Function] ]

      Type Parameters

      • K

      Parameters

      • eventName: string | symbol

      Returns Function[]

      v0.1.26

    • Alias for emitter.removeListener().

      Type Parameters

      • K

      Parameters

      • eventName: string | symbol
      • listener: (...args: any[]) => void

      Returns this

      v10.0.0

    • The "bind" event is emitted when a new binding is added to the context. The "unbind" event is emitted when an existing binding is removed.

      Parameters

      • eventName: "bind" | "unbind"

        The name of the event - always bind or unbind.

      • listener: ContextEventListener

        The listener function to call when the event is emitted.

      Returns this

    • The "bind" event is emitted when a new binding is added to the context. The "unbind" event is emitted when an existing binding is removed.

      Parameters

      • event: string | symbol
      • listener: (...args: any[]) => void

        The listener function to call when the event is emitted.

      Returns this

    • The "bind" event is emitted when a new binding is added to the context. The "unbind" event is emitted when an existing binding is removed.

      Parameters

      • eventName: "bind" | "unbind"

        The name of the event - always bind or unbind.

      • listener: ContextEventListener

        The listener function to call when the event is emitted.

      Returns this

    • The "bind" event is emitted when a new binding is added to the context. The "unbind" event is emitted when an existing binding is removed.

      Parameters

      • event: string | symbol
      • listener: (...args: any[]) => void

        The listener function to call when the event is emitted.

      Returns this

    • Adds the listener function to the beginning of the listeners array for the event named eventName. No checks are made to see if the listener has already been added. Multiple calls passing the same combination of eventNameand listener will result in the listener being added, and called, multiple times.

      server.prependListener('connection', (stream) => {
      console.log('someone connected!');
      });

      Returns a reference to the EventEmitter, so that calls can be chained.

      Type Parameters

      • K

      Parameters

      • eventName: string | symbol

        The name of the event.

      • listener: (...args: any[]) => void

        The callback function

      Returns this

      v6.0.0

    • Adds a one-timelistener function for the event named eventName to the beginning of the listeners array. The next time eventName is triggered, this listener is removed, and then invoked.

      server.prependOnceListener('connection', (stream) => {
      console.log('Ah, we have our first user!');
      });

      Returns a reference to the EventEmitter, so that calls can be chained.

      Type Parameters

      • K

      Parameters

      • eventName: string | symbol

        The name of the event.

      • listener: (...args: any[]) => void

        The callback function

      Returns this

      v6.0.0

    • Returns a copy of the array of listeners for the event named eventName, including any wrappers (such as those created by .once()).

      import { EventEmitter } from 'node:events';
      const emitter = new EventEmitter();
      emitter.once('log', () => console.log('log once'));

      // Returns a new Array with a function `onceWrapper` which has a property
      // `listener` which contains the original listener bound above
      const listeners = emitter.rawListeners('log');
      const logFnWrapper = listeners[0];

      // Logs "log once" to the console and does not unbind the `once` event
      logFnWrapper.listener();

      // Logs "log once" to the console and removes the listener
      logFnWrapper();

      emitter.on('log', () => console.log('log persistently'));
      // Will return a new Array with a single function bound by `.on()` above
      const newListeners = emitter.rawListeners('log');

      // Logs "log persistently" twice
      newListeners[0]();
      emitter.emit('log');

      Type Parameters

      • K

      Parameters

      • eventName: string | symbol

      Returns Function[]

      v9.4.0

    • Removes all listeners, or those of the specified eventName.

      It is bad practice to remove listeners added elsewhere in the code, particularly when the EventEmitter instance was created by some other component or module (e.g. sockets or file streams).

      Returns a reference to the EventEmitter, so that calls can be chained.

      Parameters

      • OptionaleventName: string | symbol

      Returns this

      v0.1.26

    • Removes the specified listener from the listener array for the event namedeventName.

      const callback = (stream) => {
      console.log('someone connected!');
      };
      server.on('connection', callback);
      // ...
      server.removeListener('connection', callback);

      removeListener() will remove, at most, one instance of a listener from the listener array. If any single listener has been added multiple times to the listener array for the specified eventName, then removeListener() must be called multiple times to remove each instance.

      Once an event is emitted, all listeners attached to it at the time of emitting are called in order. This implies that anyremoveListener() or removeAllListeners() calls after emitting and before the last listener finishes execution will not remove them fromemit() in progress. Subsequent events behave as expected.

      import { EventEmitter } from 'node:events';
      class MyEmitter extends EventEmitter {}
      const myEmitter = new MyEmitter();

      const callbackA = () => {
      console.log('A');
      myEmitter.removeListener('event', callbackB);
      };

      const callbackB = () => {
      console.log('B');
      };

      myEmitter.on('event', callbackA);

      myEmitter.on('event', callbackB);

      // callbackA removes listener callbackB but it will still be called.
      // Internal listener array at time of emit [callbackA, callbackB]
      myEmitter.emit('event');
      // Prints:
      // A
      // B

      // callbackB is now removed.
      // Internal listener array [callbackA]
      myEmitter.emit('event');
      // Prints:
      // A

      Because listeners are managed using an internal array, calling this will change the position indices of any listener registered after the listener being removed. This will not impact the order in which listeners are called, but it means that any copies of the listener array as returned by the emitter.listeners() method will need to be recreated.

      When a single function has been added as a handler multiple times for a single event (as in the example below), removeListener() will remove the most recently added instance. In the example the once('ping')listener is removed:

      import { EventEmitter } from 'node:events';
      const ee = new EventEmitter();

      function pong() {
      console.log('pong');
      }

      ee.on('ping', pong);
      ee.once('ping', pong);
      ee.removeListener('ping', pong);

      ee.emit('ping');
      ee.emit('ping');

      Returns a reference to the EventEmitter, so that calls can be chained.

      Type Parameters

      • K

      Parameters

      • eventName: string | symbol
      • listener: (...args: any[]) => void

      Returns this

      v0.1.26

    • By default EventEmitters will print a warning if more than 10 listeners are added for a particular event. This is a useful default that helps finding memory leaks. The emitter.setMaxListeners() method allows the limit to be modified for this specific EventEmitter instance. The value can be set toInfinity (or 0) to indicate an unlimited number of listeners.

      Returns a reference to the EventEmitter, so that calls can be chained.

      Parameters

      • n: number

      Returns this

      v0.3.5

    • Returns void

    • Set up the configuration resolver if needed

      Returns ConfigurationResolver

    • Add a context event observer to the context

      Parameters

      • observer: ContextEventObserver

        Context observer instance or function

      Returns Subscription

    • Create a plain JSON object for the context

      Returns JSONObject

    • Unbind a binding from the context. No parent contexts will be checked.

      Parameters

      • key: BindingAddress

        Binding key

      Returns boolean

      true if the binding key is found and removed from this context

      If you need to unbind a binding owned by a parent context, use the code below:

      const ownerCtx = ctx.getOwnerContext(key);
      return ownerCtx != null && ownerCtx.unbind(key);
    • Remove the context event observer from the context

      Parameters

      • observer: ContextEventObserver

        Context event observer

      Returns boolean