@x82-softworks/aws-api
Version:
An OpenAPI compatible api system intended for use with AWS Lambda and API Gateway
249 lines (214 loc) • 6.15 kB
TypeScript
declare class API {
devMode: boolean;
rootDef: RootDefinition;
corsConfig: Function;
/**
* @internal
*/
paths: Array<Path>;
_suppressValidationErrors: boolean;
constructor(opts: RootDefinitionOverride, devMode: boolean);
/**
* Sets the validation error suppression
* @param val
*/
suppressValidationErrors(val: boolean): void;
/**
* @public
* @returns The Root API defintion
*/
getRoot(): object;
defRoot(def: object): void;
/**
* Define the Cors function
*/
cors(configFunc: Function): void;
defComponent(type: any, name: any, val: any): API;
defSecurity(name: any, props: any): API;
defResponse(name: any, props: any): API;
ref(type: string, name: string): Reference;
defSchema(name: any, props: any): API;
getHost(): string;
/**
* Gets the value from the reference object
* @public
* @param refObj
* @returns The referenced object
*/
getRef(refObj: Reference): object;
/**
* Ref requests
*/
refResponse(name: string): Reference;
refSchema(name: string): Reference;
refRequestBody(name: string): Reference;
refSecurity(name: string): Reference;
refExample(name: string): Reference;
refParameter(name: string): Reference;
refHeader(name: string): Reference;
refCallback(name: string): Reference;
refLink(name: string): Reference;
/**
* Adds a route to the router
* @public
* @param path
* @param method
* @param [def]
* @param handler
*/
path(path: string, method: Method, def: any, handler: Handler): API;
/**
* Adds a GET route
* @public
* @param path
* @param [def]
* @param handler
*/
get(path: string, def: any, handler: Handler): API;
/**
* Adds a POST route
* @public
* @param path
* @param [def]
* @param handler
*/
post(path: string, def: any, handler: Handler): API;
/**
* Adds a PUT route
* @public
* @param path
* @param [def]
* @param handler
*/
put(path: string, def: any, handler: Handler): API;
/**
* Adds a PATCH route
* @public
* @param path
* @param [def]
* @param handler
*/
patch(path: string, def: any, handler: Handler): API;
/**
* Adds a DELETE route
* @public
* @param path
* @param [def]
* @param handler
*/
delete(path: string, def: any, handler: Handler): API;
defParameter(name: any, props: any): API;
defExample(name: any, props: any): API;
defRequestBody(name: any, props: any): API;
defHeader(name: any, props: any): API;
defLink(name: any, props: any): API;
defCallback(name: any, props: any): API;
lambda(): (event: any) => Promise<Response_2>;
/**
* @public
* @param event
*/
dispatch(event: object): Promise<Response_2>;
}
export default API;
export declare const APIKEY = "apikey";
export declare const ARRAY = "array";
export declare const BINARY = "binary";
export declare const BOOLEAN = "boolean";
export declare const BYTE = "byte";
/**
* Factory function to create an API
* @public
* @param init
* @param debug
* @returns The created api
*/
export declare const create: (init: RootDefinitionOverride, debug: boolean) => API;
export declare const DATE = "date";
export declare const DATETIME = "dateTime";
export declare const DEFAULT_CORS: {
'Access-Control-Allow-Methods': string;
'Access-Control-Allow-headers': string;
};
export declare const DOUBLE = "double";
export declare const EMAIL = "email";
export declare const FLOAT = "float";
export declare const FORM_ENCODED = "application/x-www-form-urlencoded";
/**
* The default generic error code
* @public
*/
export declare const GENERIC_ERROR = "GenericError";
export declare type Handler = (Request: any, Response: any, API: any) => void;
export declare const HEADER = "header";
export declare const INT32 = "int32";
export declare const INT64 = "int64";
export declare const INTEGER = "integer";
/**
* An easy shorhand to create a json response with the provided schema
* @param schema
* @public
* @returns
*/
export declare const jsonResponseContent: (schema: object) => object;
declare enum Method {
GET = "get",
POST = "post",
PUT = "put",
DELETE = "delete",
PATCH = "patch",
OPTIONS = "options"
}
export declare const NUMBER = "number";
export declare const OBJECT = "object";
export declare const PASSWORD = "password";
declare type Path = {
regex: URLPattern;
original: string;
};
declare type Reference = {
$ref: string;
};
/**
* An easy shorthand to create a required JSON requestBody with provided inner schema
* @public
* @param schema
*/
export declare const requiredJsonRequest: (schema: object) => object;
declare interface Response_2 {
body: any;
headers: object;
statusCode: number;
}
declare interface RootDefinition {
components: Nullable<object>;
openapi: string;
paths: object;
info: RootDefinitionInfo;
host: string;
basePath: string;
}
declare interface RootDefinitionInfo {
version: string;
description: string;
termsOfService: string;
title: string;
contact: object;
license: object;
}
declare interface RootDefinitionOverride {
components?: RootDefinition['components'];
openapi?: RootDefinition['openapi'];
paths?: RootDefinition['paths'];
info?: RootDefinition['info'];
host?: RootDefinition['host'];
basePath?: RootDefinition['basePath'];
}
export declare const STRING = "string";
declare class URLPattern {
regex: RegExp;
keys: Array<string>;
constructor(pattern: string);
match(test: string): Nullable<object>;
}
export { }