Skip to content

Commit

Permalink
Merge pull request #126 from ianbytchek/master
Browse files Browse the repository at this point in the history
Update typescript definitions file and improve the pre-test
  • Loading branch information
dougmoscrop authored Dec 4, 2019
2 parents c2cbf3e f8d969a commit 8b53225
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 25 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 15,7 @@
"url": "https://github.com/dougmoscrop/serverless-http"
},
"scripts": {
"pretest": "tsc --noEmit test/typecheck.ts",
"pretest": "tsc --strict --noEmit test/typecheck.ts",
"test": "nyc mocha",
"posttest": "eslint lib test",
"test:integration": "mocha test/integration/test.js",
Expand Down
46 changes: 27 additions & 19 deletions serverless-http.d.ts
Original file line number Diff line number Diff line change
@@ -1,26 1,34 @@
/// <reference types="aws-lambda" />

declare namespace ServerlessHttp {
type FrameworkApplication = {
callback: Function;
handle: Function;
router: {
route: Function;
}
_core: {
_dispatch: Function;
}
export interface FrameworkApplication {
callback: Function;
handle: Function;
router: {
route: Function;
}
type HandlerCompatibleApp = Function | Partial<FrameworkApplication>;
type LambdaPartial = (
event: AWSLambda.APIGatewayProxyEvent,
context: AWSLambda.Context
) => AWSLambda.APIGatewayProxyResult;
_core: {
_dispatch: Function;
}
}

/**
* Handler-compatible function or application.
*/
export type Application = Function | Partial<FrameworkApplication>;

/**
* AWS Lambda APIGatewayProxyHandler-like handler.
*/
export type Handler = (
event: AWSLambda.APIGatewayProxyEvent,
context: AWSLambda.Context
) => Promise<AWSLambda.APIGatewayProxyResult>;
}

declare function serverlessHttp(
app: ServerlessHttp.HandlerCompatibleApp,
opts?: any
): Promise<ServerlessHttp.LambdaPartial>;
/**
* Wraps the application into a Lambda APIGatewayProxyHandler-like handler.
*/
declare function ServerlessHttp(application: ServerlessHttp.Application, options?: any): ServerlessHttp.Handler;

export = serverlessHttp;
export = ServerlessHttp;
10 changes: 5 additions & 5 deletions test/typecheck.ts
Original file line number Diff line number Diff line change
@@ -1,6 1,6 @@
import serverlessHttp = require('..');
import Koa = require('koa');
import Koa = require("koa");
import serverlessHttp = require("..");

// Simple typescript sanity check
serverlessHttp(() => { });
serverlessHttp(new Koa());
// Basic definitions check.
const handlerWithFn: serverlessHttp.Handler = serverlessHttp(() => { });
const handlerWithApp: serverlessHttp.Handler = serverlessHttp(new Koa());

0 comments on commit 8b53225

Please sign in to comment.