@opra/nestjs-http
Version:
Opra NestJS Http Module
62 lines (61 loc) • 2.48 kB
TypeScript
import * as http from 'node:http';
import { type IncomingMessage, type ServerResponse } from 'node:http';
import { type Type } from '@nestjs/common';
import { HttpController, HttpOperation } from '@opra/common';
import { HttpAdapter, HttpContext } from '@opra/http';
/**
* OpraHttpNestjsAdapter
*
* HTTP adapter used to integrate OPRA APIs with the NestJS framework.
* This adapter converts OPRA controllers into NestJS controllers and
* exports the OPRA documentation ($schema).
*/
export declare class OpraHttpNestjsAdapter extends HttpAdapter {
/** List of controller classes to be registered with NestJS */
readonly nestControllers: Type[];
/** Platform identifier */
readonly platform = "nestjs";
/**
* Creates a new instance of OpraHttpNestjsAdapter.
*
* @param options - Adapter configuration options.
*/
constructor(options: HttpAdapter.Options & {
/** Indicates whether the schema is public */
schemaIsPublic?: boolean;
/** Manually added NestJS controllers */
controllers?: Type[];
});
/**
* Closes the adapter.
* @returns {Promise<void>}
*/
close(): Promise<void>;
createContext(_req: any, _res: any, args?: {
controller?: HttpController;
controllerInstance?: any;
operation?: HttpOperation;
operationHandler: Function;
}): Promise<HttpContext>;
protected _httpHandler?: (req: IncomingMessage, res: ServerResponse) => void;
setHttpHandler(handler: (req: IncomingMessage, res: ServerResponse) => void): void;
handleRawRequest(req: http.IncomingMessage, res: http.ServerResponse): Promise<void>;
/**
* Adds the root controller that serves the OPRA schema.
*
* @param isPublic - Whether the schema is accessible without authentication.
* @protected
*/
protected _addRootController(isPublic?: boolean): void;
/**
* Adds the specified class and its sub-controllers to the NestJS controller list.
*
* @param sourceClass - Source OPRA controller class.
* @param currentPath - Current URL path.
* @param parentTree - List of parent controller classes.
* @protected
* @throws {@link NotFoundError} Thrown when no suitable endpoint is found for the operation.
* @throws {@link TypeError} Thrown when the controller is not a class.
*/
protected _addToNestControllers(sourceClass: Type, currentPath: string, parentTree: Type[]): void;
}