lambda-request-handler
Advanced tools
Comparing version 0.3.0 to 0.3.1
@@ -11,6 +11,7 @@ /// <reference types="node" /> | ||
} | ||
declare type PromiseFactory<A> = () => Promise<A>; | ||
declare const handler: { | ||
(app: RequestListener): handler.APIGatewayEventHandler; | ||
deferred: (appPromiseFn: () => Promise<RequestListener>) => handler.APIGatewayEventHandler; | ||
deferred: (appFn: PromiseFactory<RequestListener>) => handler.APIGatewayEventHandler; | ||
}; | ||
export = handler; |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -9,28 +18,25 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
; | ||
const eventWithMultiValueHeaders = (event) => { | ||
const eventHasMultiValueHeaders = (event) => { | ||
return event.multiValueHeaders !== null && typeof event.multiValueHeaders === 'object'; | ||
}; | ||
const handlerPromise = (appPromiseFn) => { | ||
let _p = null; | ||
return (event, ctx) => { | ||
if (!_p) { | ||
_p = appPromiseFn(); | ||
const handlerBuilder = (appFn) => { | ||
let appHandler; | ||
return (event, ctx) => __awaiter(void 0, void 0, void 0, function* () { | ||
if (!appHandler) { | ||
const resolvedApp = yield appFn(); | ||
appHandler = in_process_request_1.default(resolvedApp); | ||
} | ||
return _p | ||
.then(app => processRequest(app, event, ctx)); | ||
}; | ||
try { | ||
const reqOptions = eventToRequestOptions_1.default(event, ctx); | ||
const mockResponse = yield appHandler(reqOptions); | ||
return response_1.inProcessResponseToLambdaResponse(mockResponse, eventHasMultiValueHeaders(event)); | ||
} | ||
catch (e) { | ||
console.error(e); | ||
return response_1.errorResponse(); | ||
} | ||
}); | ||
}; | ||
const processRequest = (app, event, ctx) => Promise.resolve() | ||
.then(() => { | ||
const reqOptions = eventToRequestOptions_1.default(event, ctx); | ||
const appHandler = in_process_request_1.default(app); | ||
return appHandler(reqOptions); | ||
}) | ||
.then(res => response_1.inProcessResponseToLambdaResponse(res, eventWithMultiValueHeaders(event))) | ||
.catch(e => { | ||
console.error(e); | ||
return response_1.errorResponse(); | ||
}); | ||
const handler = (app) => handlerPromise(() => Promise.resolve(app)); | ||
handler.deferred = handlerPromise; | ||
const handler = (app) => handlerBuilder(() => Promise.resolve(app)); | ||
handler.deferred = handlerBuilder; | ||
module.exports = handler; |
{ | ||
"name": "lambda-request-handler", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"license": "(MIT OR Apache-2.0)", | ||
@@ -44,12 +44,12 @@ "scripts": { | ||
"@types/jest": "^24.0.23", | ||
"@types/node": "^12.12.9", | ||
"@types/node": "^12.12.14", | ||
"compression": "^1.7.4", | ||
"cookie-parser": "^1.4.4", | ||
"ejs": "^2.7.3", | ||
"ejs": "^3.0.1", | ||
"express": "^4.17.1", | ||
"jest": "^24.9.0", | ||
"ts-jest": "^24.1.0", | ||
"ts-node": "^8.5.2", | ||
"typescript": "^3.7.2" | ||
"ts-jest": "^24.2.0", | ||
"ts-node": "^8.5.4", | ||
"typescript": "^3.7.3" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21938
272