/** * FURI - Fast Uniform Resource Identifier. * * The Fast and Furious Node.js Router. * Copyright(c) 2016, 2025 Rajinder Yadav. * * Labs DevMentor.org Corp. * This code is released as-is without warranty under the "GNU GENERAL PUBLIC LICENSE". */ import { StoreState } from "./state.js"; import { HttpRequest, HttpResponse, MapOf, QueryParamTypes } from './types.js'; /** * An initialized Application Context object is passed to * each middleware and request handler. It provides helper * functions to simplify working with Request and Response objects. * It also helps manage application state and session state. */ export declare class ApplicationContext { appStore: StoreState; request: HttpRequest; response: HttpResponse; constructor(appStore: StoreState, request: HttpRequest, response: HttpResponse); /** * Parse query string into an object. * * @param ctx: Application context object. * @param simple true will parse all values as a string, * false will parse a value as a string or number. * @returns Parsed query string as an object, or null if no valid query parameters are found. */ queryStringToObject(simple?: boolean): MapOf | null; /************************************** * Application level helper functions. **************************************/ /** * Request session state. * Overloaded functions to read or set application state. * * Read session data from the request object. * Set session data from the request object. * Session data is automatically reset between requests. * * @param key The session data key. * @param value The session data value. * @return Session data value or undefined if not found, when value is not provided. */ sessionState(key: string): any; sessionState(key: string, value: any): void; /** * Global Application state. * Overloaded functions to read or set application state. * * Read application state data. * Set application state data. * * @param key The application state key. * @param value The application state value. * @return Application state value or undefined if not found, when value is not provided. */ storeState(key: string): any; storeState(key: string, value: any): void; /** * Fetch cookie from request header. * * @return Cookie value or undefined if not found. */ getCookie(): string | string[] | undefined; /** * Set cookies in response header. This function may be called * multiple times to set multiple cookies. * * @param name Cookie name. * @param value Cookie value. * @return void. */ setCookie(name: string, value: string): void; /************************************** * Request level helper functions. **************************************/ /** * Overloaded functions to read or set request headers. * * @param name The header name. * @param value The header value. * @returns Current header value or undefined if not found, when value is not provided. */ requestHeader(name: string): string | string[] | undefined; requestHeader(name: string, value: string): void; requestHeaders(): any; /************************************** * Response level helper functions. **************************************/ /** * Overloaded functions to read or set response headers. * * @param headers The headers to set. * @param name The header name. * @param value {optional} The header value. * @return Current header value or undefined if not found, when value is not provided. */ responseHeader(headers: Headers): void; responseHeader(name: string): string | string[] | undefined; responseHeader(name: string, value: string): void; /** * Overloaded method to send response data, default encoding is 'utf8'. * Support send both text or object input and will convert to JSON if data is an object. * * @param data The response data, can be a string or an object. * @param encoding The encoding of the response data, default is 'utf8'. * @return void. */ send(data: string, encoding?: NodeJS.BufferEncoding): void; send(data: object, encoding?: NodeJS.BufferEncoding): void; /** * Overloaded method to optionally send response data, and then close the connection. * Support send both text or object input and will convert to JSON if data is an object. * The default encoding is 'utf8'. * * @param data The response data, can be a string or an object, or empty. * @param encoding The encoding of the response data, default is 'utf8'. * @return void. */ end(): void; end(data: string): void; end(data: object): void; } //# sourceMappingURL=application-context.d.ts.map