Skip to content

Commit

Permalink
docs(contracts): added missing documentation for adapter contract
Browse files Browse the repository at this point in the history
  • Loading branch information
H4ad committed Feb 13, 2022
1 parent 6726c0e commit 4ed9e46
Showing 1 changed file with 98 additions and 0 deletions.
98 changes: 98 additions & 0 deletions src/v2/contracts/adapter.contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<TEvent, TContext> {
/**
* 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<TEvent> {
/**
* 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<string, string | string[]>;

/**
* 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<TEvent, TResponse> {
/**
* The event sent by the serverless
*/
event: TEvent;

/**
* The error throwed during forwarding
*/
error: Error;

/**
* The instance of the resolver
*/
resolver: Resolver<TResponse>;

/**
* Indicates whether to forward the (error.stack) or not to the client
*/
respondWithErrors: boolean;

/**
* The instance of the logger
*/
log: ILogger;
}

Expand Down

0 comments on commit 4ed9e46

Please sign in to comment.