///
///
///
import Emitter from 'node:events';
import util from 'node:util';
import http, { type IncomingMessage, type ServerResponse } from 'node:http';
import { type UnknownRecord } from 'type-fest';
import { HttpError } from 'http-errors';
import { type Context } from './context.types.js';
import compose, { type Middleware } from './compose.js';
import { type KoaRequest } from './request.types.js';
import { type KoaResponse } from './response.types.js';
export type Options = {
env?: string;
keys?: string[];
proxy?: boolean;
subdomainOffset?: number;
proxyIpHeader?: string;
maxIpsCount?: number;
compose?: typeof compose;
asyncLocalStorage?: boolean;
};
declare class App extends Emitter {
/**
* Make HttpError available to consumers of the library so that consumers don't
* have a direct dependency upon `http-errors`
*/
static HttpError: import("http-errors").HttpErrorConstructor;
/**
* app.proxy
*
* when true proxy header fields will be trusted
*/
proxy: boolean;
/**
* app.subdomainOffset
*
* offset of .subdomains to ignore, default to 2
*/
subdomainOffset: number;
/**
* app.proxyIpHeader
*
* proxy ip header, default to X-Forwarded-For
*/
proxyIpHeader: string;
/**
* app.maxIpsCount
* max ips read from proxy ip header, default to 0 (means infinity)
*/
maxIpsCount: number;
/**
* app.env
* Defaults to NODE_ENV or "development"
*/
env: string;
compose: typeof compose;
/**
* The extendable koa context prototype object.
*/
context: Context;
/**
* The koa request object.
*/
request: KoaRequest;
/**
* The incoming node request object.
*/
req?: IncomingMessage;
/**
* The node response object.
*/
res?: ServerResponse;
/**
* The koa response object.
*/
response: KoaResponse;
/**
* @prop app.keys
* array of signed cookie keys
*/
keys?: string[];
/**
* middleware
* @private
*/
private readonly middleware;
/**
* @name app.silent
* By default outputs all errors to stderr unless app.silent is true.
*/
silent?: boolean;
/**
* async local storage
* @private
*/
private readonly ctxStorage?;
[util.inspect.custom]?: () => UnknownRecord;
/**
* Application constructor.
*
* create a new koa application.
*
* @example
* ```ts
* import App from '@kosmic/koa';
* const app = new App();
* ```
* @param options
*/
constructor(options?: Options);
listen(...args: Parameters): http.Server;
toJSON(): UnknownRecord;
inspect(): UnknownRecord;
/**
* Use the given middleware `fn`.
*
* all function are async (or Promise returning) functions.
*
* @example
*
* app.use(async (ctx, next) => {
* await next();
* ctx.body = 'Hello World';
* })
*/
use(fn: Middleware): this;
callback(): (req: IncomingMessage, res: ServerResponse) => Promise | undefined>;
/**
* return current context from async local storage
*/
get currentContext(): Context | undefined;
/**
* Handle request in callback.
*
* @api private
*/
private handleRequest;
/**
* Initialize a new context.
*
* @api private
*/
createContext(request_: IncomingMessage, res: ServerResponse): Context;
/**
* Default error handler.
*
* @param {Error} err
* @api private
*/
onerror(error: HttpError): void;
/**
* Help TS users comply to CommonJS, ESM, bundler mismatch.
* @see https://github.com/koajs/koa/issues/1513
*/
static get default(): typeof App;
createAsyncCtxStorageMiddleware(): Middleware;
}
/**
* export types
*/
export { type Middleware, type Next } from './compose.js';
export { type Context, type State } from './context.types.js';
export { type KoaRequest, type Request } from './request.types.js';
export { type KoaResponse, type Response } from './response.types.js';
export default App;