Stone.js API
    Preparing search index...

    Represents an incoming event. Generic interface for incoming events. Standalone interface for incoming events.

    interface IIncomingEvent {
        body?: unknown;
        decodedPathname?: string;
        getRoute?: <U extends IIncomingEvent, V = unknown>() => Route<U, V>;
        getUri: (withDomain: boolean) => string;
        host: string;
        isMethod: (method: HttpMethod) => boolean;
        isSecure?: boolean;
        locale: string;
        metadata: Record<string, unknown>;
        method: HttpMethod;
        pathname: string;
        query?: URLSearchParams;
        setRouteResolver: <U extends IIncomingEvent, V = unknown>(
            resolver: () => Route<U, V>,
        ) => void;
        source: IncomingEventSource;
        timeStamp: number;
        type: string;
        url: URL;
        get platform(): string | symbol;
        clone(): this;
        fingerprint(): string;
        get<TReturn = unknown>(key: string): TReturn;
        get<TReturn = unknown>(key: string, fallback: TReturn): TReturn;
        getMetadataValue<TReturn = unknown>(key: string): TReturn;
        getMetadataValue<TReturn = unknown>(
            key: string,
            fallback: TReturn,
        ): TReturn;
        is(key: string, value: unknown): boolean;
        isPlatform(platform: string | symbol): boolean;
        setMetadataValue(
            key: string | Record<string, unknown>,
            value?: unknown,
        ): this;
    }

    Hierarchy

    • IncomingEvent
      • IIncomingEvent
    Index
    body?: unknown
    decodedPathname?: string
    getRoute?: <U extends IIncomingEvent, V = unknown>() => Route<U, V>

    The resolved route, once routing has set one. Optional: before routing there is nothing to get, and the router itself only reads it as a shortcut.

    getUri: (withDomain: boolean) => string
    host: string
    isMethod: (method: HttpMethod) => boolean
    isSecure?: boolean
    locale: string

    The locale of the event.

    metadata: Record<string, unknown>

    The metadata associated with the event.

    method: HttpMethod
    pathname: string
    query?: URLSearchParams
    setRouteResolver: <U extends IIncomingEvent, V = unknown>(
        resolver: () => Route<U, V>,
    ) => void
    source: IncomingEventSource

    The source of the event.

    timeStamp: number

    The timestamp of the event creation.

    type: string

    The type of the event.

    url: URL
    • get platform(): string | symbol

      Get the platform of the event source.

      Returns string | symbol

      The platform of the event source.

    • Return a cloned instance.

      The metadata container is deep-copied (plain objects and arrays are recreated, special values kept by reference) so that mutating the clone's metadata — e.g. via middleware — never leaks back into the original event. This is what makes the Kernel's originalEvent snapshot a faithful pre-middleware copy.

      Returns this

      A cloned instance of the current class.

    • A stable identity for this event.

      What it is for: keying anything that has to survive one event being handled twice. A renderer stores its loader results under this key on the server and reads them back under the same key in the browser, so two renders of the same event find the same data.

      Defined here because identity is not a platform's idea. An event that carries a URL has a sharper one to offer and overrides this: IncomingHttpEvent and IncomingBrowserEvent both answer with their method and path. An event that carries a payload instead, from a queue or a timer, is identified by that payload, which is what this computes.

      Two properties it must have, and both come from what is excluded: the timestamp is left out, because a server render and a browser render of the same event happen at different moments and must agree; and keys are sorted, because two objects with the same entries in a different order are the same event.

      Returns string

      The fingerprint, base64-encoded.

    • Get data from metadata.

      Type Parameters

      • TReturn = unknown

      Parameters

      • key: string

        The key to retrieve from metadata.

      Returns TReturn

      The value associated with the key or the fallback.

    • Get data from metadata.

      Type Parameters

      • TReturn = unknown

      Parameters

      • key: string

        The key to retrieve from metadata.

      • fallback: TReturn

        The fallback value if the key is not found.

      Returns TReturn

      The value associated with the key or the fallback.

    • Get data from metadata.

      Type Parameters

      • TReturn = unknown

      Parameters

      • key: string

        The key to retrieve from metadata.

      Returns TReturn

      The value associated with the key or the fallback.

    • Get data from metadata.

      Type Parameters

      • TReturn = unknown

      Parameters

      • key: string

        The key to retrieve from metadata.

      • fallback: TReturn

        The fallback value if the key is not found.

      Returns TReturn

      The value associated with the key or the fallback.

    • Check if the given value is equal to the specified value.

      Parameters

      • key: string

        The key to check.

      • value: unknown

        The value to compare against.

      Returns boolean

      True if the key's value is equal to the specified value, false otherwise.

    • Check if the event source is from a platform.

      Parameters

      • platform: string | symbol

        The platform to check.

      Returns boolean

      True if the event source is from the platform, false otherwise.

    • Add data to metadata.

      Parameters

      • key: string | Record<string, unknown>

        The key or object to add to metadata.

      • Optionalvalue: unknown

        The value to associate with the key.

      Returns this

      This Event instance.