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

express-contextualized-router

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-contextualized-router - npm Package Compare versions

Comparing version 1.5.0 to 1.6.0

2

dist/index.d.ts

@@ -37,3 +37,3 @@ import { NextFunction } from 'express';

*/
export declare const ContextualizedRouter: <Context extends Record<string, any> = Record<string, never>, BasePath extends string = "", P extends Record<string, any> = {}>(originalRouter?: Router) => Context extends Record<string, never> ? ContextualizedRouterWithExpressRouter<Context, BasePath, P> : IContextualizedRouter<Context, BasePath, P, any, any, any>;
export declare const ContextualizedRouter: <Context extends Record<string, any> = Record<string, never>, BasePath extends string = "", P extends Record<string, any> = {}>(originalRouter?: Router) => Context extends Record<string, never> ? ContextualizedRouterWithExpressRouter<Context, BasePath, P> : IContextualizedRouter<Context, BasePath, P>;

@@ -40,0 +40,0 @@ /**

{
"name": "express-contextualized-router",
"version": "1.5.0",
"version": "1.6.0",
"type": "module",

@@ -27,3 +27,3 @@ "exports": {

"format:fix": "prettier --write .",
"lint": "eslint .",
"lint": "eslint --report-unused-disable-directives .",
"lint:fix": "eslint --fix ./",

@@ -38,30 +38,28 @@ "test": "vitest run --coverage",

"devDependencies": {
"@commitlint/config-conventional": "17.7.0",
"@tsconfig/strictest": "2.0.1",
"@types/express": "4.17.17",
"@types/node": "18.17.5",
"@types/supertest": "2.0.12",
"@typescript-eslint/eslint-plugin": "5.62.0",
"@typescript-eslint/parser": "5.62.0",
"@vitest/coverage-v8": "0.34.1",
"@commitlint/config-conventional": "19.0.3",
"@tsconfig/strictest": "2.0.3",
"@types/express": "4.17.21",
"@types/node": "20.11.25",
"@types/supertest": "6.0.2",
"@typescript-eslint/eslint-plugin": "7.1.1",
"@typescript-eslint/parser": "7.1.1",
"@vitest/coverage-v8": "1.3.1",
"builtin-modules": "3.3.0",
"commitlint": "17.7.1",
"eslint": "8.47.0",
"eslint-config-prettier": "9.0.0",
"eslint-config-standard-with-typescript": "27.0.1",
"eslint-plugin-import": "2.28.0",
"eslint-plugin-n": "16.0.1",
"eslint-plugin-node": "11.1.0",
"eslint-plugin-prettier": "5.0.0",
"eslint-plugin-promise": "6.1.1",
"express": "4.18.2",
"husky": "8.0.3",
"lint-staged": "14.0.0",
"prettier": "3.0.1",
"semantic-release": "21.0.7",
"supertest": "6.3.3",
"typescript": "5.1.6",
"vite": "4.4.9",
"vite-plugin-dts": "3.5.2",
"vitest": "0.34.1"
"commitlint": "19.0.3",
"eslint": "8.57.0",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-n": "16.6.2",
"eslint-plugin-security": "1.7.1",
"eslint-plugin-vitest": "0.3.22",
"eslint-plugin-vitest-globals": "1.4.0",
"express": "4.18.3",
"husky": "9.0.11",
"lint-staged": "15.2.2",
"prettier": "3.2.5",
"semantic-release": "22.0.12",
"supertest": "6.3.4",
"typescript": "5.4.2",
"vite": "5.1.5",
"vite-plugin-dts": "3.7.3",
"vitest": "1.3.1"
},

@@ -68,0 +66,0 @@ "peerDependencies": {

@@ -37,3 +37,3 @@ import { describe, it, vi, expect } from 'vitest'

contextualizedRouter.use((_req, _res, next) => {
contextualizedRouter.use((_req, _res, _next) => {
mockFn('Context Middleware')

@@ -43,3 +43,3 @@ return new ContextCreator({})

contextualizedRouter.get('/', (_req, res, next) => {
contextualizedRouter.get('/', (_req, res, _next) => {
mockFn('Handler')

@@ -63,3 +63,3 @@ res.status(200).json({ success: true })

contextualizedRouter.use((req, _res) => {
contextualizedRouter.use((_req, _res) => {
mockFn('Context Middleware')

@@ -92,7 +92,7 @@ return new ContextCreator({})

contextualizedRouter.use(
(_req, _res, next) => {
(_req, _res, _next) => {
mockFn('Context Middleware 1')
return new ContextCreator({})
},
(_req, _res, next) => {
(_req, _res, _next) => {
mockFn('Context Middleware 2')

@@ -105,3 +105,3 @@ return new ContextCreator({})

contextualizedRouter.get('/', (_req, res, next) => {
contextualizedRouter.get('/', (_req, res, _next) => {
mockFn('Handler')

@@ -127,7 +127,7 @@ res.status(200).json({ success: true })

contextualizedRouter.use([
(_req, _res, next) => {
(_req, _res, _next) => {
mockFn('Context Middleware 1')
return new ContextCreator({})
},
(_req, _res, next) => {
(_req, _res, _next) => {
mockFn('Context Middleware 2')

@@ -140,3 +140,3 @@ return new ContextCreator({})

contextualizedRouter.get('/', (_req, res, next) => {
contextualizedRouter.get('/', (_req, res, _next) => {
mockFn('Handler')

@@ -159,3 +159,3 @@ res.status(200).json({ success: true })

const fooRouter = contextualizedRouter.use((_req, _res, next) => {
const fooRouter = contextualizedRouter.use((_req, _res, _next) => {
return new ContextCreator({ foo: 'bar' })

@@ -178,3 +178,3 @@ })

const userRouter = contextualizedRouter.use('/:id', (req, _res, next) => {
const userRouter = contextualizedRouter.use('/:id', (req, _res, _next) => {
if (req.params.id === '1') {

@@ -193,3 +193,3 @@ throw new Error('Invalid User')

const handleError: ErrorRequestHandler = (err, req, res, next) => {
const handleError: ErrorRequestHandler = (err, req, res, _next) => {
res.status(500).json({ error: err.message })

@@ -239,3 +239,3 @@ }

const authenticatedRouter = contextualizedRouter.use((req, res, next) => {
const authenticatedRouter = contextualizedRouter.use((req, res, _next) => {
const userId = req.headers['user-id']

@@ -272,3 +272,3 @@ if (typeof userId !== 'string' || userId.length === 0) {

const authenticatedRouter = contextualizedRouter.use<{ userId: string }>(
(req, res, next) => {
(req, res, _next) => {
const userId = req.headers['user-id']

@@ -293,3 +293,3 @@ if (typeof userId !== 'string' || userId.length === 0) {

const handleError: ErrorRequestHandler = (err, req, res, next) => {
const handleError: ErrorRequestHandler = (err, req, res, _next) => {
res.status(500).json({ error: err.message })

@@ -337,3 +337,3 @@ }

const contextualizedRouter = ContextualizedRouter()
contextualizedRouter.get('/', function getUser(req, res, next) {
contextualizedRouter.get('/', function getUser(req, res, _next) {
return res.status(200).send({})

@@ -698,3 +698,3 @@ })

{ foo: number }
> = (req, res, next) => {
> = (_req, _res, _next) => {
return new ContextCreator({ foo: 'bar' })

@@ -730,3 +730,3 @@ }

{ foo: string }
> = (req, res, next) => {
> = (_req, res, _next) => {
// @ts-expect-error

@@ -733,0 +733,0 @@ return res.status(200).json({ foo: 12 })

@@ -41,3 +41,3 @@ import { NextFunction, Router } from 'express'

>,
...handlers: Array<
...handlers: (
| ContextualizedRequestHandler<

@@ -51,3 +51,3 @@ ChildRouterContext<Route, BasePath, Context>,

>
>
)[]
) => {

@@ -115,6 +115,6 @@ const pathToUse: Route = typeof path === 'string' ? path : ('' as Route)

// eslint-disable-next-line @typescript-eslint/no-misused-promises
router[verb](pathToUse, wrappedHandler)
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return ContextualizedRouter<Context & OutputContext, Route>(router) as any

@@ -121,0 +121,0 @@ }

@@ -24,8 +24,8 @@ import { NextFunction, Request, Response, Router } from 'express'

: Route extends `${BasePath}`
? Context
: BasePath extends '/'
? Route extends `${BasePath}${any}`
? Context
: Record<string, never>
: Record<string, never>
: BasePath extends '/'
? Route extends `${BasePath}${any}`
? Context
: Record<string, never>
: Record<string, never>

@@ -32,0 +32,0 @@ /**

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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