diff --git a/src/v2/contracts/adapter.contract.ts b/src/v2/contracts/adapter.contract.ts index eeb7b4f7..d06b3310 100644 --- a/src/v2/contracts/adapter.contract.ts +++ b/src/v2/contracts/adapter.contract.ts @@ -3,37 +3,135 @@ import { ILogger } from '../core'; import { ServerlessResponse } from '../network'; import { Resolver } from './resolver.contract'; +/** + * The props of the method that verify if this handler should handle the event. + */ export interface CanHandleProps { + /** + * The event sent by the serverless + */ event: TEvent | unknown; + + /** + * The context sent by the serverless + */ context: TContext | unknown; + + /** + * The instance of the logger. + */ log: ILogger; } +/** + * The request interface used to bridge any event source to the framework. + */ export interface AdapterRequest { + /** + * The HTTP Method to use to create the request to the framework + */ method: string; + + /** + * The path to use to create the request to the framework + */ path: string; + + /** + * The headers to use to create the request to the framework + */ headers: SingleValueHeaders; + + /** + * The body as buffer to use to create the request to the framework + */ body: Buffer | undefined; + + /** + * The remote address (client ip) to use to create the request to the framework + */ remoteAddress?: string; + + /** + * The address of the event source (used in Lambda@edge) + */ host?: string; + + /** + * The address of the event source (used in Lambda@edge) + */ hostname?: string; } +/** + * The props of the method that get the response from the framework and transform it into a format that the event source can handle + */ export interface GetResponseAdapterProps { + /** + * The event sent by the serverless + */ event: TEvent; + + /** + * The framework {@link ServerlessResponse response}. + * + * @note It can be optional, as this method can be used when an error occurs during the handling of the request by the framework. + */ response?: ServerlessResponse; + + /** + * The framework response status code + */ statusCode: number; + + /** + * The framework response body + */ body: string; + + /** + * The framework response headers + */ headers: Record; + + /** + * Indicates whether the response is base64 encoded or not + */ isBase64Encoded: boolean; + + /** + * The instance of the logger + */ log: ILogger; } +/** + * The props of the method that handle the response when an error occurs while forwarding the request to the framework + */ export interface OnErrorProps { + /** + * The event sent by the serverless + */ event: TEvent; + + /** + * The error throwed during forwarding + */ error: Error; + + /** + * The instance of the resolver + */ resolver: Resolver; + + /** + * Indicates whether to forward the (error.stack) or not to the client + */ respondWithErrors: boolean; + + /** + * The instance of the logger + */ log: ILogger; }