Class WikimediaStreamFilter<T, U>

Describes a class that automatically filters events from a stream. A filter can be instantiated using WikimediaStream.filter, and then chained with none, all, and any methods to create a filter that will filter out events. The final filter can then be used to add event listeners to the stream.

none, all, and any are chainable, however this is only the case if they are used in the correct order. none filters are executed first and take highest priority. all filters are executed second, and any filters are executed last. Types help narrow down the final type of events passed through the event handlers, which is why the order of the filters is important.

Type Parameters

Constructors

  • Type Parameters

    • T extends default | default | default | default | default | default | MediaWikiRecentChangeEvent | default | default | default
    • U extends WikimediaEventStream

    Parameters

    • stream: WikimediaStream
    • eventType: U
    • Optional filters: {
          all: [any, FilterOptions][];
          any: [any, FilterOptions][];
          none: [any, FilterOptions][];
      }
      • all: [any, FilterOptions][]
      • any: [any, FilterOptions][]
      • none: [any, FilterOptions][]

    Returns WikimediaStreamFilter<T, U>

Properties

allFilters: [any, FilterOptions][] = []
anyFilters: [any, FilterOptions][] = []
eventType: U
listenerCache: Map<Function, WikimediaStreamEventListener<WikimediaEventStream>> = ...
noneFilters: [any, FilterOptions][] = []

Methods

  • Adds a filter that will filter out events that do not match all all masks.

    Note that, for use in TypeScript, none and any are set to never. This prevents unintended use of none and any after all is used, thus ensuring that the types emitted by the final event handler is correct. Since JavaScript does not perform type checks, this does not throw a runtime error.

    Type Parameters

    • V extends DeepPartial<T>

    Parameters

    • mask: V
    • options: FilterOptions = {}

    Returns WikimediaStreamFilter<T & V, U> & {
        none: never;
    }

  • Adds a filter that will filter out events that do not match any any masks.

    Note that, for use in TypeScript, none and all are set to never. This prevents unintended use of none and all after any is used, thus ensuring that the types emitted by the final event handler is correct. Since JavaScript does not perform type checks, this does not throw a runtime error.

    Type Parameters

    • V extends DeepPartial<T>

    Parameters

    • mask: V
    • options: FilterOptions = {}

    Returns WikimediaStreamFilter<T | T & V, U> & {
        all: never;
        none: never;
    }

  • Private

    Crawling function. Only triggers when depth cap hit or

    Parameters

    • expectedObject: any
    • actualObject: any
    • action: ((expected, actual) => boolean)
        • (expected, actual): boolean
        • Parameters

          • expected: any
          • actual: any

          Returns boolean

    • depth: number = 0

    Returns boolean

  • Private

    Performs a deep equality check. This checks if all keys and values of expectedObject match all keys and values of actualObject and vice versa. If oneWay is set to true, this only checks if keys and values of expectedObject are in actualObject, and still returns true if the actualObject contains extra properties.

    Parameters

    • expectedObject: any

      The object that is expected

    • actualObject: any

      The actual object

    • Optional oneWay: boolean

      Whether the comparison is made one way

    Returns boolean

    Whether the two objects are equal

  • Adds a filter that will filter out events that match the mask. none filters are run first, and take highest priority over other filters.

    Types for this method are only effective for specific cases due to the lack of negation types in TypeScript.

    Type Parameters

    • V extends DeepPartial<T>

    Parameters

    • mask: V
    • options: FilterOptions = {}

    Returns WikimediaStreamFilter<T, U>

Generated using TypeDoc