Skip to content

Commit

Permalink
Add typescript definitions for built-in middlewares (#117)
Browse files Browse the repository at this point in the history
* Add typescript definitions for built-in middlewares

* Added main.d.ts and remapped exports

* Move typescript definitions to the root directory
  • Loading branch information
Juanelorganelo authored and lmammino committed Mar 4, 2018
1 parent 9880fcb commit 4f0f299
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 4 deletions.
File renamed without changes.
74 changes: 74 additions & 0 deletions middlewares.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { SSM } from 'aws-sdk'
import { Options as AjvOptions } from 'ajv'
import middy from './middy'

interface ICorsOptions {
origin: string;
}

interface ICacheOptions {
calculateCacheId?: (event: any) => Promise<string>;
getValue?: (key: string) => Promise<any>;
setValue?: (key: string) => Promise<void>;
}

interface IDoNotWaitForEmtpyEventLoopOptions {
runOnBefore?: boolean;
runOnAfter?: boolean;
runOnError?: boolean;
}

interface IHTTPContentNegotiationOptions {
parseCharsets?: boolean;
availableCharsets?: string[];
parseEncodings?: boolean;
availableEncodings?: string[];
parseLanguages?: boolean;
availableLanguages?: string[];
parseMediaTypes?: boolean;
availableMediaTypes?: string[];
failOnMismatch?: boolean;
}

interface IHTTPHeaderNormalizerOptions {
normalizeHeaderKey?: (key: string) => string;
}

interface ISSMOptions {
cache?: boolean;
params: { [key: string]: string; };
awsSdkOptions?: Partial<SSM.Types.ClientConfiguration>;
setToContext?: boolean;
}

interface IValidatorOptions {
inputSchema?: any;
outputSchema?: any;
ajvOptions?: Partial<AjvOptions>;
}

interface IURLEncodeBodyParserOptions {
extended?: false;
}

interface IWarmupOptions {
isWarmingUp?: (event: any) => boolean;
onWarmup?: (event: any) => void;
}

declare function cache(opts?: ICacheOptions): middy.IMiddyMiddlewareObject;
declare function cors(opts?: ICorsOptions): middy.IMiddyMiddlewareObject;
declare function doNotWaitForEmptyEventLoop(opts?: IDoNotWaitForEmtpyEventLoopOptions): middy.IMiddyMiddlewareObject;
declare function httpContentNegotiation(opts?: IHTTPContentNegotiationOptions): middy.IMiddyMiddlewareObject;
declare function httpErrorHandler(): middy.IMiddyMiddlewareObject;
declare function httpEventNormalizer(): middy.IMiddyMiddlewareObject;
declare function httpHeaderNormalizer(opts: IHTTPHeaderNormalizerOptions): middy.IMiddyMiddlewareObject;
declare function httpPartialResponse(): middy.IMiddyMiddlewareObject;
declare function jsonBodyParser(): middy.IMiddyMiddlewareObject;
declare function s3KeyNormalizer(): middy.IMiddyMiddlewareObject;
declare function ssm(opts?: ISSMOptions): middy.IMiddyMiddlewareObject;
declare function validator(opts?: IValidatorOptions): middy.IMiddyMiddlewareObject;
declare function urlEncodeBodyParser(opts?: IURLEncodeBodyParserOptions): middy.IMiddyMiddlewareObject;
declare function warmup(opts?: IWarmupOptions): middy.IMiddyMiddlewareObject;

export as namespace middlewares;
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"name": "middy",
"version": "0.9.2",
"version": "0.9.3",
"description": "🛵 The stylish Node.js middleware engine for AWS Lambda",
"main": "src/index.js",
"main": "./index.js",
"files": [
"src",
"typescript",
"index.js",
"middlewares.js",
"!__tests__"
],
"types": "./typescript/middy.d.ts",
"types": "./index.d.ts",
"scripts": {
"test:lint": "eslint --ignore-pattern='node_modules/' --ignore-pattern='coverage/' --ignore-pattern='docs/' .",
"test:unit": "jest --verbose --coverage",
Expand Down

0 comments on commit 4f0f299

Please sign in to comment.