/**
* Gina Framework — TypeScript declarations
*
* Main module declaration for `require('gina')`.
* Also exports all public types for use in consumer projects.
*
* @packageDocumentation
*/
///
///
import { EventEmitter } from 'events';
import type { IncomingMessage, ServerResponse } from 'http';
import type { Http2ServerRequest, Http2ServerResponse, ServerHttp2Stream } from 'http2';
import type { PathObject, OnCompletable, UuidFunction, LocaleResult } from './globals';
// ─── Request / Response aliases ──────────────────────────────────────────────
export type GinaRequest = (IncomingMessage | Http2ServerRequest) & {
/** Parsed GET query-string params */
get?: Record;
/** Parsed POST body */
post?: Record;
/** Parsed PUT body */
put?: Record;
/** Parsed PATCH body */
patch?: Record;
/** Parsed DELETE body */
delete?: Record;
/** Parsed HEAD query-string params */
head?: Record;
/** Alias for the method-specific params (e.g. req.post on POST) */
body?: Record;
/** URI params extracted by the router (`:id` segments, requirement captures) */
params?: Record;
/** Routing metadata attached by the router */
routing?: {
rule: string;
method: string;
param: RouteParam;
[key: string]: any;
};
/** Get all merged params for the current HTTP method */
getParams(): Record;
/** Get a single param by name */
getParam(name: string): any;
};
export type GinaResponse = (ServerResponse | Http2ServerResponse) & {
/** HTTP/2 stream when available */
stream?: ServerHttp2Stream;
status?: number;
};
export type NextFunction = (err?: any) => void;
// ─── SuperController ─────────────────────────────────────────────────────────
/**
* Base controller class. Every bundle controller inherits from SuperController.
* A fresh instance is created for each HTTP request.
*/
export class SuperController extends EventEmitter {
name: string;
engine: any;
isProcessingError: boolean;
/** Get the current request object */
getRequestObject(): GinaRequest;
/** Get the current response object */
getResponseObject(): GinaResponse;
/** Get the `next` middleware callback */
getNextCallback(): NextFunction | null;
/** True when running in dev mode */
isCacheless(): boolean;
/** True when scope is `'local'` */
isLocalScope(): boolean;
/** True when scope is `'production'` */
isProductionScope(): boolean;
/**
* Render an HTML template (Swig engine).
* @param userData - Template data merged into the view
* @param displayInspector - Show the Gina Inspector overlay
* @param errOptions - Error rendering options (internal)
*/
render(userData?: object, displayInspector?: boolean, errOptions?: object): void;
/** Render without the layout wrapper */
renderWithoutLayout(data?: object, displayInspector?: boolean): void;
/**
* Send a JSON response.
* @param jsonObj - Data to serialise; parsed if passed as a string
*/
renderJSON(jsonObj: any): void;
/**
* Stream an AsyncIterable as a chunked HTTP response.
* Defaults to `text/event-stream` (SSE) framing.
* @param asyncIterable - Source of chunks (strings or Buffers)
* @param contentType - Response Content-Type (default: `'text/event-stream'`)
*/
renderStream(asyncIterable: AsyncIterable, contentType?: string): void;
/** Send a plain-text response */
renderTEXT(content: string | any): void;
/**
* Send 103 Early Hints for preloading resources.
* @param links - Link header value(s)
* @returns `this` for chaining
*/
setEarlyHints(links: string | string[]): this;
/** True when the request was made via XMLHttpRequest */
isXMLRequest(): boolean;
/** True when credentials (cookies/auth) were sent */
isWithCredentials(): boolean;
/** True when the request originated from a Gina popin */
isPopinContext(): boolean;
/** Override the HTTP method for the current request */
setRequestMethod(requestMethod: string, conf: object): string;
/** Get the (possibly overridden) HTTP method */
getRequestMethod(): string | null;
/** Override the parsed method params */
setRequestMethodParams(params: object): void;
/** Get the overridden method params */
getRequestMethodParams(): object | null;
/**
* Redirect to a route name, URL, or full request triplet.
*
* Overloads:
* - `redirect(url: string, ignoreWebRoot?: boolean)`
* - `redirect(routeName: string, ignoreWebRoot?: boolean)`
* - `redirect(req, res, next)`
*/
redirect(target: string, ignoreWebRoot?: boolean): void;
redirect(req: GinaRequest, res: GinaResponse, next?: NextFunction): void;
/** Get a clone of the bundle configuration */
getConfig(name?: string): any;
/** Get locale utilities */
getLocales(shortCountryCode?: string): LocaleResult;
/** Get form validation rules for the current request */
getFormsRules(): object;
/**
* Make an outbound HTTP/HTTPS request.
* @param options - Request options (host, port, path, method, headers, critical, ...)
* @param data - Request body / query params
* @param callback - `callback(err, result)` -- omit for Promise
*/
query(options: QueryOptions, data?: object, callback?: (err: Error | null, result: any) => void): void | Promise;
/**
* Download a file from a remote URL and stream it to the client.
* @param url - Remote URL
* @param options - Download options (file, toLocalDir, contentType, ...)
* @param cb - Callback on completion
*/
downloadFromURL(url: string, options?: DownloadOptions, cb?: (err: Error | null, files?: any[]) => void): Promise;
/** Download a local file to the client */
downloadFromLocal(filename: string): void;
/**
* Store uploaded file(s) to a target directory.
* @param target - Destination directory path
* @param files - File(s) to store (defaults to all uploaded files)
* @param cb - Callback `(err, files)`
*/
store(target: string, files?: any, cb?: (err: Error | null, files?: any[]) => void): Promise;
/** Health check: responds with `{ status: 200, isAlive: true }` */
getBundleStatus(req: GinaRequest, res: GinaResponse, next: NextFunction): void;
/** Ping a sibling bundle's health endpoint */
checkBundleStatus(bundle: string, cb?: (err: Error | null, status: object) => void): Promise