Stone.js API
    Preparing search index...

    Class Route<IncomingEventType, OutgoingResponseType>

    Represents a route that defines how incoming events are handled.

    Type Parameters

    • IncomingEventType extends IIncomingEvent = IIncomingEvent

      The type of the incoming event.

    • OutgoingResponseType = unknown

      The type of the outgoing response.

    Index

    Configuration options for the route.

    • get domain(): string

      Gets the hostname of the route.

      Returns string

      The hostname as a string.

    • get hash(): string

      Gets the hash fragment from the event URL.

      Returns string

      The hash fragment as a string.

    • get params(): RouteParams

      Gets the parameters extracted from the route.

      Returns RouteParams

      The route parameters.

      If the event is not bound.

    • get path(): string

      Gets the pathname of the route.

      Returns string

      The pathname as a string.

    • get protocol(): string

      Gets the protocol for the route.

      Returns string

      The protocol as a string (http or https).

    • get query(): Record<string, string>

      Gets the query parameters from the event URL.

      Returns Record<string, string>

      A record of query parameters.

    • get uri(): string

      Gets the full URI of the route.

      Returns string

      The full URI as a string.

    • get url(): URL

      Gets the URL of the event.

      Returns URL

      The event URL or a default URL (http://localhost).

    • Binds the provided event to the route, initializing route parameters and query data.

      Parameters

      Returns Promise<void>

      A promise that resolves once the binding is complete.

    • Generates a URL or URI for the route with optional parameters, query, hash, and protocol.

      Parameters

      • options: Omit<GenerateOptions, "name">

        Options for generating the URL.

        • params: Route parameters to include in the path.
        • query: Query parameters to append to the URL.
        • hash: A hash fragment to include in the URL.
        • withDomain: Whether to include the domain in the URL.
        • protocol: The protocol to use in the URL.

      Returns string

      The generated URL as a string.

      RouterError if required parameters are missing.

    • Retrieves all parameters that are defined (non-undefined values).

      Returns RouteParams

      A record of defined parameters.

    • Returns the compiled regex matching the domain, or undefined when the route has no domain constraint.

      Returns RegExp

      The precompiled domain regex or undefined.

    • Retrieves a specified option from the route configuration.

      Type Parameters

      • TReturn = unknown

      Parameters

      Returns TReturn

      The value of the option or the fallback value if not found.

    • Retrieves a specified option from the route configuration.

      Type Parameters

      • TReturn = unknown

      Parameters

      Returns TReturn

      The value of the option or the fallback value if not found.

    • Retrieves the names of all optional parameters.

      Returns string[]

      An array of optional parameter names.

    • Retrieves a specified options from the route configuration.

      Type Parameters

      • TReturn = unknown

      Parameters

      • keys: string[]

        The kesy of the option to retrieve.

      Returns Record<string, TReturn>

      The values of the option.

    • Retrieves the value of a specific parameter.

      Type Parameters

      • TReturn = unknown

      Parameters

      • name: string

        The name of the parameter to retrieve.

      Returns TReturn

      The value of the parameter or the fallback value if not found.

    • Retrieves the value of a specific parameter.

      Type Parameters

      • TReturn = unknown

      Parameters

      • name: string

        The name of the parameter to retrieve.

      • fallback: TReturn

        A fallback value if the parameter is not found.

      Returns TReturn

      The value of the parameter or the fallback value if not found.

    • Retrieves the names of all parameters.

      Returns string[]

      An array of parameter names.

    • Returns the compiled regex matching the path only.

      Returns RegExp

      The precompiled path regex.

    • Computes a deterministic specificity score for the route.

      Higher is more specific. Static segments outrank required parameters, which outrank optional parameters, which outrank catch-all (*/+) wildcards. This lets the collection order routes by specificity independently of their declaration order (e.g. /users/new wins over /users/:id).

      Returns number

      The specificity score.

    • Returns the compiled regex matching the full URI (domain + path).

      Used to extract parameter values via named capture groups.

      Returns RegExp

      The precompiled URI regex.

    • Checks if the route has a domain constraint.

      Returns boolean

      true if the route has a domain constraint, otherwise false.

    • Checks if the route has a specific parameter.

      Parameters

      • name: string

        The name of the parameter to check.

      Returns boolean

      true if the parameter exists, otherwise false.

    • Checks if the route has any parameters.

      Returns boolean

      true if parameters are present, otherwise false.

    • Checks if the route is marked as a fallback route.

      Returns boolean

      true if the route is a fallback, otherwise false.

    • Checks if the route uses HTTP protocol.

      Returns boolean

      true if the route is HTTP-only, otherwise false.

    • Checks if the route uses HTTPS protocol.

      Returns boolean

      true if the route is HTTPS-only, otherwise false.

    • Checks if a parameter name is optional.

      Parameters

      • name: string

        The name of the parameter to check.

      Returns boolean

      true if the parameter is optional, otherwise false.

    • Checks if the route requires HTTPS for security.

      Returns boolean

      true if the route is HTTPS-only, otherwise false.

    • Checks if the route operates in strict mode.

      Returns boolean

      true if the route is strict, otherwise false.

    • Checks if the provided event matches the route.

      Parameters

      • event: IncomingEventType

        The incoming event to check against the route.

      • includingMethod: boolean

        Whether to include HTTP method matching in the evaluation.

      Returns boolean

      true if the event matches the route, otherwise false.

    • Executes the route's action based on the provided event.

      Note: The order of execution is important and should not be changed.

      Parameters

      Returns Promise<OutgoingResponseType>

      A promise that resolves to the outgoing response generated by the route's action.

      RouterError if the route action is invalid.

    • Sets the resolver for the route. The resolver is used to resolve the route's handler.

      Parameters

      Returns this

      The updated Route instance.

    • Converts the route into a JSON object representation.

      Returns Promise<Record<string, unknown>>

      A JSON object representing the route.

    • Converts the route into a string representation (JSON format).

      Returns Promise<string>

      A JSON string representing the route.