Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@middy/core

Package Overview
Dependencies
Maintainers
3
Versions
226
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@middy/core - npm Package Compare versions

Comparing version 2.0.0-alpha.0 to 2.0.0-alpha.1

38

index.js

@@ -0,1 +1,3 @@

"use strict";
/**

@@ -75,3 +77,5 @@ * Middy factory function. Use it to wrap your existing handler to enable middlewares on it.

module.exports = (handler = () => {}, plugin) => {
plugin?.beforePrefetch?.();
var _plugin$beforePrefetc;
plugin === null || plugin === void 0 ? void 0 : (_plugin$beforePrefetc = plugin.beforePrefetch) === null || _plugin$beforePrefetc === void 0 ? void 0 : _plugin$beforePrefetc.call(plugin);
const beforeMiddlewares = [];

@@ -82,3 +86,5 @@ const afterMiddlewares = [];

const instance = (event = {}, context = {}) => {
plugin?.requestStart?.();
var _plugin$requestStart;
plugin === null || plugin === void 0 ? void 0 : (_plugin$requestStart = plugin.requestStart) === null || _plugin$requestStart === void 0 ? void 0 : _plugin$requestStart.call(plugin);
const request = {

@@ -94,17 +100,23 @@ event,

try {
var _plugin$beforeHandler, _plugin$afterHandler, _plugin$requestEnd2;
await runMiddlewares(beforeMiddlewares, request, plugin);
if (request.response !== undefined) {
var _plugin$requestEnd;
// catch short circuit
await plugin?.requestEnd?.();
await (plugin === null || plugin === void 0 ? void 0 : (_plugin$requestEnd = plugin.requestEnd) === null || _plugin$requestEnd === void 0 ? void 0 : _plugin$requestEnd.call(plugin));
return request.response;
}
plugin?.beforeHandler?.();
plugin === null || plugin === void 0 ? void 0 : (_plugin$beforeHandler = plugin.beforeHandler) === null || _plugin$beforeHandler === void 0 ? void 0 : _plugin$beforeHandler.call(plugin);
request.response = await handler(request.event, request.context);
plugin?.afterHandler?.();
plugin === null || plugin === void 0 ? void 0 : (_plugin$afterHandler = plugin.afterHandler) === null || _plugin$afterHandler === void 0 ? void 0 : _plugin$afterHandler.call(plugin);
await runMiddlewares(afterMiddlewares, request, plugin);
await plugin?.requestEnd?.();
await (plugin === null || plugin === void 0 ? void 0 : (_plugin$requestEnd2 = plugin.requestEnd) === null || _plugin$requestEnd2 === void 0 ? void 0 : _plugin$requestEnd2.call(plugin));
return request.response;
} catch (e) {
var _plugin$requestEnd4;
request.response = undefined;

@@ -117,3 +129,5 @@ request.error = e;

if (request.response !== undefined) {
await plugin?.requestEnd?.();
var _plugin$requestEnd3;
await (plugin === null || plugin === void 0 ? void 0 : (_plugin$requestEnd3 = plugin.requestEnd) === null || _plugin$requestEnd3 === void 0 ? void 0 : _plugin$requestEnd3.call(plugin));
return request.response;

@@ -126,3 +140,3 @@ }

await plugin?.requestEnd?.();
await (plugin === null || plugin === void 0 ? void 0 : (_plugin$requestEnd4 = plugin.requestEnd) === null || _plugin$requestEnd4 === void 0 ? void 0 : _plugin$requestEnd4.call(plugin));
throw request.error;

@@ -192,8 +206,10 @@ }

const runMiddlewares = async (middlewares, request, plugin) => {
var _plugin$beforeMiddlew, _plugin$afterMiddlewa;
const stack = Array.from(middlewares);
if (!stack.length) return;
const nextMiddleware = stack.shift();
plugin?.beforeMiddleware?.(nextMiddleware?.name);
const res = await nextMiddleware?.(request);
plugin?.afterMiddleware?.(nextMiddleware?.name);
plugin === null || plugin === void 0 ? void 0 : (_plugin$beforeMiddlew = plugin.beforeMiddleware) === null || _plugin$beforeMiddlew === void 0 ? void 0 : _plugin$beforeMiddlew.call(plugin, nextMiddleware === null || nextMiddleware === void 0 ? void 0 : nextMiddleware.name);
const res = await (nextMiddleware === null || nextMiddleware === void 0 ? void 0 : nextMiddleware(request));
plugin === null || plugin === void 0 ? void 0 : (_plugin$afterMiddlewa = plugin.afterMiddleware) === null || _plugin$afterMiddlewa === void 0 ? void 0 : _plugin$afterMiddlewa.call(plugin, nextMiddleware === null || nextMiddleware === void 0 ? void 0 : nextMiddleware.name);

@@ -200,0 +216,0 @@ if (res !== undefined) {

{
"name": "@middy/core",
"version": "2.0.0-alpha.0",
"version": "2.0.0-alpha.1",
"description": "🛵 The stylish Node.js middleware engine for AWS Lambda (core package)",

@@ -15,2 +15,3 @@ "type": "commonjs",

"types": "index.d.ts",
"files": [],
"scripts": {

@@ -46,3 +47,3 @@ "test": "npm run test:typings && npm run test:unit",

},
"gitHead": "e047c0d3db00aa11b39f2d3e193458ea021a58a0"
"gitHead": "f8b0f418477cdbff47da693963bf1ea918b39d04"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc