@mikeycoxon/aws-lambda-event-http-router
Version:
AWS Lambda handler utility for HTTP REST request routing based on details in the APIGatewayProxyEvent
72 lines (71 loc) • 3.37 kB
TypeScript
import type { APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda';
import { StatusCodes } from 'http-status-codes';
export declare const GET: string;
export declare const POST: string;
export declare const PUT: string;
export declare const PATCH: string;
export declare const DELETE: string;
export declare const UUID: string;
export declare const FILE: string;
export declare const ROUTE_KEY: string;
export declare class EventMap extends Map<string, string | undefined> implements AWSEventMap<string, string | undefined> {
constructor();
andResource(event: APIGatewayProxyEvent, res: string): AWSEventMap<string, string | undefined>;
andCustomIdFormat(event: APIGatewayProxyEvent, format: RegExp, name: string): AWSEventMap<string, string | undefined>;
}
export declare const withEvent: (event: APIGatewayProxyEvent) => AWSEventMap<string, string | undefined>;
export declare const isPathUuid: (event: APIGatewayProxyEvent) => string | undefined;
export declare const isPathFile: (event: APIGatewayProxyEvent) => string | undefined;
export declare const resource: (event: APIGatewayProxyEvent, resource: string) => string | undefined;
export declare const isGet: (event: APIGatewayProxyEvent) => string | undefined;
export declare const isPost: (event: APIGatewayProxyEvent) => string | undefined;
export declare const isPut: (event: APIGatewayProxyEvent) => string | undefined;
export declare const isPatch: (event: APIGatewayProxyEvent) => string | undefined;
export declare const isDelete: (event: APIGatewayProxyEvent) => string | undefined;
export declare const stripLeadingSlash: (resourceString: string | undefined) => string;
export interface AWSEventMap<K extends string, V extends string | undefined> extends Map<string, string | undefined> {
andResource(event: APIGatewayProxyEvent, res: string): AWSEventMap<K, V>;
andCustomIdFormat(event: APIGatewayProxyEvent, format: RegExp, name: string): AWSEventMap<K, V>;
get(key: K): V;
set(key: K, value: V): any;
}
export interface AwsFormatApiError {
format(): APIGatewayProxyResult;
message: string;
}
export interface AwsFormatSuccess {
format(): APIGatewayProxyResult;
message: string;
}
export declare class Success {
message: string;
statusCode: StatusCodes;
constructor(message: string, statusCode: StatusCodes);
format(): APIGatewayProxyResult;
}
export declare class ApiError extends Error {
statusCode: StatusCodes;
constructor(message: string, statusCode: StatusCodes);
format(): APIGatewayProxyResult;
}
export declare class NotFoundError extends ApiError implements AwsFormatApiError {
constructor(message: string);
}
export declare class ForbiddenError extends ApiError implements AwsFormatApiError {
constructor(message: string);
}
export declare class UnauthorizedError extends ApiError implements AwsFormatApiError {
constructor(message: string);
}
export declare class BadRequestError extends ApiError implements AwsFormatApiError {
constructor(message: string);
}
export declare class ServerError extends ApiError implements AwsFormatApiError {
constructor(message: string);
}
export declare class Created extends Success implements AwsFormatSuccess {
constructor(message: string);
}
export declare class OK extends Success implements AwsFormatSuccess {
constructor(message: string);
}