Socket
Socket
Sign inDemoInstall

express-router-api

Package Overview
Dependencies
65
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.3.2 to 1.3.3

4

dist/index.d.ts

@@ -20,4 +20,4 @@ import { Request, Response, Router, RouterOptions } from 'express';

export declare type AsyncApiResult = Observable<ApiResult> | Promise<ApiResult>;
export declare type ErrorFormatter = (err: Error, req: Request, res: Response) => AsyncApiResult | ApiResult;
export declare type SuccessFormatter = (data: ApiResult, req: Request, res: Response) => AsyncApiResult | ApiResult;
export declare type ErrorFormatter = (this: ExpressApiRouter, err: Error, req: Request, res: Response) => AsyncApiResult | ApiResult;
export declare type SuccessFormatter = (this: ExpressApiRouter, data: ApiResult, req: Request, res: Response) => AsyncApiResult | ApiResult;
export interface ApiRouterOptions extends RouterOptions {

@@ -24,0 +24,0 @@ errorFormatter?: ErrorFormatter;

@@ -184,5 +184,7 @@ "use strict";

const router = express_1.Router(options);
const errorFormatter = (options && options.errorFormatter) || defaultErrorFormatter;
const successFormatter = (options && options.successFormatter) || defaultSuccessFormatter;
const apiRouter = Object.assign(router, {
errorFormatter: defaultErrorFormatter,
successFormatter: defaultSuccessFormatter,
errorFormatter,
successFormatter,
setErrorFormatter(formatter) {

@@ -189,0 +191,0 @@ this.errorFormatter = formatter;

{
"name": "express-router-api",
"version": "1.3.2",
"version": "1.3.3",
"description": "Express router that lets you construct your API entirely on promises",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -43,4 +43,6 @@ import {

export type ErrorFormatter = (err: Error, req: Request, res: Response) => AsyncApiResult | ApiResult;
export type SuccessFormatter = (data: ApiResult, req: Request, res: Response) => AsyncApiResult | ApiResult;
export type ErrorFormatter = (this: ExpressApiRouter, err: Error, req: Request, res: Response)
=> AsyncApiResult | ApiResult;
export type SuccessFormatter = (this: ExpressApiRouter, data: ApiResult, req: Request, res: Response)
=> AsyncApiResult | ApiResult;

@@ -114,3 +116,4 @@ export interface ApiRouterOptions extends RouterOptions {

return (req: Request, res: Response, next: NextFunction) => {
const formatterOperator = switchMap((data: ApiResult) => resolve(this.successFormatter(data, req, res)));
const formatterOperator = switchMap((data: ApiResult) =>
resolve(this.successFormatter(data, req, res)));

@@ -241,5 +244,9 @@ const formatError = (err: Error): AsyncApiResult => {

const router = Router(options);
const errorFormatter = (options && options.errorFormatter) || defaultErrorFormatter;
const successFormatter = (options && options.successFormatter) || defaultSuccessFormatter;
const apiRouter: ExpressApiRouter = Object.assign(router, {
errorFormatter: defaultErrorFormatter,
successFormatter: defaultSuccessFormatter,
errorFormatter,
successFormatter,
setErrorFormatter(formatter: ErrorFormatter) {

@@ -246,0 +253,0 @@ this.errorFormatter = formatter;

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc