Class: IncomingBrowserEvent
Class: IncomingBrowserEvent
Class representing an IncomingBrowserEvent.
Author
Mr. Stone evensstone@gmail.com
Extends
IncomingEvent
Constructors
Constructor
protected new IncomingBrowserEvent(options): IncomingBrowserEvent;
Constructor for IncomingBrowserEvent.
Parameters
options
The options to create an IncomingBrowserEvent instance.
Returns
IncomingBrowserEvent
Throws
If the URL option is not a valid instance of URL.
Overrides
IncomingEvent.constructor
Properties
cookies
readonly cookies: CookieCollection;
The cookies included in the request.
method
readonly method: "GET";
The HTTP method of the request.
protocol
readonly protocol: string;
The protocol used for the request (e.g., http or https).
query
readonly query: URLSearchParams;
The query parameters of the request.
queryString?
readonly optional queryString: string;
The query string of the request.
routeResolver()?
protected optional routeResolver: () => IRoute;
Returns
url
readonly url: URL;
The URL of the request.
userResolver()?
protected optional userResolver: () => unknown;
Returns
unknown
INCOMING_BROWSER_EVENT
static INCOMING_BROWSER_EVENT: string = 'stonejs@incoming_browser_event';
Accessors
decodedPathname
Get Signature
get decodedPathname(): undefined | string;
Returns
undefined
| string
The decoded pathname of the URL.
hash
Get Signature
get hash(): string;
Returns
string
The hash part of the URL.
host
Get Signature
get host(): string;
Returns
string
The host of the URL (hostname:port).
hostname
Get Signature
get hostname(): string;
Returns
string
The hostname of the URL.
isSecure
Get Signature
get isSecure(): boolean;
Returns
boolean
Whether the request was made over a secure connection.
params
Get Signature
get params(): undefined | Record<string, unknown>;
Returns
undefined
| Record
<string
, unknown
>
The route parameters.
path
Get Signature
get path(): string;
Returns
string
The full path including pathname and search query.
pathname
Get Signature
get pathname(): string;
Returns
string
The pathname of the URL.
scheme
Get Signature
get scheme(): string;
Returns
string
The protocol of the URL (e.g., "http" or "https").
segments
Get Signature
get segments(): string[];
Returns
string
[]
The URL segments split by '/'.
uri
Get Signature
get uri(): string;
Returns
string
The full URL as a string.
userAgent
Get Signature
get userAgent(): undefined | string;
Returns
undefined
| string
The user agent of the request.
Methods
fingerprint()
fingerprint(): string;
Generate a unique fingerprint for the event.
Returns
string
The generated fingerprint as a base64 string.
get()
Get data from the request.
Priority:
- Route params
- Query params
- Cookies
- Metadata
- Fallback value
Param
The key to look for.
Param
A fallback value if the key is not found.
Call Signature
get<TReturn>(key): undefined | TReturn;
Get data from the request.
Priority:
- Route params
- Query params
- Cookies
- Metadata
- Fallback value
Type Parameters
TReturn
TReturn
= unknown
Parameters
key
string
The key to look for.
Returns
undefined
| TReturn
The value of the key or the fallback.
Param
The key to look for.
Param
A fallback value if the key is not found.
Overrides
IncomingEvent.get
Call Signature
get<TReturn>(key, fallback): TReturn;
Get data from the request.
Priority:
- Route params
- Query params
- Cookies
- Metadata
- Fallback value
Type Parameters
TReturn
TReturn
= unknown
Parameters
key
string
The key to look for.
fallback
TReturn
A fallback value if the key is not found.
Returns
TReturn
The value of the key or the fallback.
Param
The key to look for.
Param
A fallback value if the key is not found.
Overrides
IncomingEvent.get
getCookie()
Get a cookie value.
Param
The cookie name.
Param
A fallback value if the cookie is not found.
Call Signature
getCookie<TReturn>(name): undefined | TReturn;
Get a cookie value.
Type Parameters
TReturn
TReturn
extends Cookie
= Cookie
Parameters
name
string
The cookie name.
Returns
undefined
| TReturn
The cookie value or the fallback.
Param
The cookie name.
Param
A fallback value if the cookie is not found.
Call Signature
getCookie<TReturn>(name, fallback): TReturn;
Get a cookie value.
Type Parameters
TReturn
TReturn
extends Cookie
= Cookie
Parameters
name
string
The cookie name.
fallback
TReturn
A fallback value if the cookie is not found.
Returns
TReturn
The cookie value or the fallback.
Param
The cookie name.
Param
A fallback value if the cookie is not found.
getParam()
Retrieve a parameter from the route if it exists.
Param
The name of the parameter to retrieve.
Param
The fallback value if the parameter does not exist.
Call Signature
getParam<TReturn>(name): undefined | TReturn;
Retrieve a parameter from the route if it exists.
Type Parameters
TReturn
TReturn
= unknown
Parameters
name
string
The name of the parameter to retrieve.
Returns
undefined
| TReturn
The value of the parameter if it exists, otherwise undefined.
Param
The name of the parameter to retrieve.
Param
The fallback value if the parameter does not exist.
Call Signature
getParam<TReturn>(name, fallback): TReturn;
Retrieve a parameter from the route if it exists.
Type Parameters
TReturn
TReturn
= unknown
Parameters
name
string
The name of the parameter to retrieve.
fallback
TReturn
The fallback value if the parameter does not exist.
Returns
TReturn
The value of the parameter if it exists, otherwise undefined.
Param
The name of the parameter to retrieve.
Param
The fallback value if the parameter does not exist.
getRoute()
getRoute<RouteType>(): undefined | RouteType;
Return the current route or a route parameter.
Type Parameters
RouteType
RouteType
extends IRoute
= IRoute
Returns
undefined
| RouteType
The route parameter or the route object.
getRouteResolver()
getRouteResolver(): () => undefined | IRoute;
Get the route resolver function.
Returns
The route resolver function.
(): undefined | IRoute;
Returns
undefined
| IRoute
getUri()
getUri(withDomain): undefined | string;
Get the URI with or without the domain.
Parameters
withDomain
boolean
= false
Whether to include the domain in the URI.
Returns
undefined
| string
The URI with or without the domain.
getUser()
getUser<T>(): undefined | T;
Get the user instance.
Type Parameters
T
T
Returns
undefined
| T
The user object, resolved through a user resolver function if available.
getUserResolver()
getUserResolver(): () => unknown;
Get the user resolver function.
Returns
The user resolver function.
(): unknown;
Returns
unknown
hasCookie()
hasCookie(name): boolean;
Check if a cookie exists.
Parameters
name
string
The cookie name to check.
Returns
boolean
True if the cookie exists, otherwise false.
isMethod()
isMethod(method): boolean;
Check if the current event method matches the given method.
Parameters
method
string
The method to check.
Returns
boolean
True if the event method matches, otherwise false.
setRouteResolver()
setRouteResolver<RouteType>(resolver): this;
Set the route resolver function.
Type Parameters
RouteType
RouteType
extends IRoute
= IRoute
Parameters
resolver
() => RouteType
The route resolver function.
Returns
this
The current instance for method chaining.
setUserResolver()
setUserResolver(resolver): this;
Set the user resolver function.
Parameters
resolver
() => unknown
The user resolver function.
Returns
this
The current instance for method chaining.
uriForPath()
uriForPath(path): string;
Generate a full URL for the given path.
Parameters
path
string
The path to append to the base URL.
Returns
string
The full URL for the given path.
create()
static create(options): IncomingBrowserEvent;
Create an IncomingBrowserEvent.
Parameters
options
The IncomingBrowserEvent options.
Returns
IncomingBrowserEvent
A new instance of IncomingBrowserEvent.
Overrides
IncomingEvent.create