New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

express-valued-middleware

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-valued-middleware - npm Package Compare versions

Comparing version 0.5.0 to 0.6.0-rc.0

12

CHANGELOG.md

@@ -0,1 +1,13 @@

# [0.6.0-rc.0](https://gitlab.com/soul-codes/express-valued-middleware/compare/0.5.0...0.6.0-rc.0) (2022-09-07)
### Bug Fixes
* 🐛 do not synthesize/throw error on left branch map ([3a06bb9](https://gitlab.com/soul-codes/express-valued-middleware/commit/3a06bb998e411ffba43b5718b6dbd46a48b15aa0))
### BREAKING CHANGES
* 🧨 Map's left value `[response, nextError]` is no longer supported.
# [0.5.0](https://gitlab.com/soul-codes/express-valued-middleware/compare/0.4.4-rc.0...0.5.0) (2022-08-04)

@@ -2,0 +14,0 @@

4

lib/map.d.ts

@@ -1,2 +0,2 @@

import { Response } from "express";
import { NextFunction, Response } from "express";
import { Either } from "fp-ts/lib/Either";

@@ -21,4 +21,4 @@ import { ValuedMiddleware } from "./@types/ValueYieldingMiddleware";

export declare function map<A, B>(fn: (value: A) => Either<MapError, B>): MapCombinator<A, B>;
export declare type MapError = number | readonly [status: number, output: any] | ((res: Response) => void) | readonly [handleError: (res: Response) => void, nextError: unknown];
export declare type MapError = number | readonly [status: number, output: any] | ((res: Response, next: NextFunction) => void);
export declare type MapCombinator<A, B> = (fa: ValuedMiddleware<A>) => ValuedMiddleware<B>;
//# sourceMappingURL=map.d.ts.map

@@ -34,16 +34,10 @@ import { of } from "./of";

res.sendStatus(error);
return void next(new Error(`Middleware ${getName()}'s value could not be transformed. A status code ${error} was returned.`));
}
if (typeof error === "function") {
error(res);
return void next(new Error(`Middleware ${getName()}'s value could not be transformed.`));
else if (typeof error === "function") {
error(res, next);
}
if (typeof error[0] === "function") {
const [handleError, nextError] = error;
handleError(res);
return void next(nextError);
else {
const [statusCode, payload] = error;
res.status(statusCode).send(payload);
}
const [statusCode, payload] = error;
res.status(statusCode).send(payload);
return void next(new Error(`Middleware ${getName()}'s value could not be transformed. A status code ${statusCode} was returned.`));
});

@@ -50,0 +44,0 @@ };

{
"name": "express-valued-middleware",
"version": "0.5.0",
"version": "0.6.0-rc.0",
"description": "Composable value-yielding middleware creator and combinators for Express.",

@@ -5,0 +5,0 @@ "keywords": [

@@ -1,2 +0,2 @@

import { Request, Response } from "express";
import { NextFunction, Request, Response } from "express";
import { Either } from "fp-ts/lib/Either";

@@ -42,28 +42,8 @@

res.sendStatus(error);
return void next(
new Error(
`Middleware ${getName()}'s value could not be transformed. A status code ${error} was returned.`
)
);
} else if (typeof error === "function") {
error(res, next);
} else {
const [statusCode, payload] = error;
res.status(statusCode).send(payload);
}
if (typeof error === "function") {
error(res);
return void next(
new Error(
`Middleware ${getName()}'s value could not be transformed.`
)
);
}
if (typeof error[0] === "function") {
const [handleError, nextError] = error;
handleError(res);
return void next(nextError);
}
const [statusCode, payload] = error;
res.status(statusCode).send(payload);
return void next(
new Error(
`Middleware ${getName()}'s value could not be transformed. A status code ${statusCode} was returned.`
)
);
});

@@ -79,4 +59,3 @@ };

| readonly [status: number, output: any]
| ((res: Response) => void)
| readonly [handleError: (res: Response) => void, nextError: unknown];
| ((res: Response, next: NextFunction) => void);

@@ -83,0 +62,0 @@ export type MapCombinator<A, B> = (

@@ -74,4 +74,3 @@ import { MapError, map, of } from "@lib";

expect(res.status).toHaveBeenLastCalledWith(404);
expect(next).toHaveBeenCalledTimes(1);
expect(next.mock.calls[0][0]).not.toBeUndefined();
expect(next).not.toHaveBeenCalled();
expect(() => middleware.get(req)).toThrowError(/fooMiddleware/);

@@ -85,26 +84,13 @@ });

leftValue = jest.fn();
leftValue = jest.fn((res, next) => {
res.status(400);
});
middleware(req, res, next);
expect(leftValue).toHaveBeenCalledTimes(1);
expect(leftValue).toHaveBeenLastCalledWith(res);
expect(next).toHaveBeenCalledTimes(1);
expect(next.mock.calls[0][0]).not.toBeUndefined();
expect(res.status).toHaveBeenCalledTimes(1);
expect(res.status).toHaveBeenLastCalledWith(400);
expect(next).not.toHaveBeenCalled();
expect(() => middleware.get(req)).toThrowError(/fooMiddleware/);
});
test("posterior failure (manual reject with exact error)", () => {
const req = mockRequest();
const res = mockResponse();
const next = mockNext();
const nextError = Error("custom next error");
leftValue = [jest.fn(), nextError];
middleware(req, res, next);
expect(leftValue[0]).toHaveBeenCalledTimes(1);
expect(leftValue[0]).toHaveBeenLastCalledWith(res);
expect(next).toHaveBeenCalledTimes(1);
expect(next.mock.calls[0][0]).toBe(nextError);
expect(() => middleware.get(req)).toThrowError(/fooMiddleware/);
});
test("inherits name", () => {

@@ -111,0 +97,0 @@ expect(middleware.displayName).toBe("fooMiddleware");

Sorry, the diff of this file is not supported yet

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