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.4.1 to 1.5.0

tsconfig.build.json

143

dist/index.d.ts

@@ -0,6 +1,33 @@

import { NextFunction } from 'express';
import { ParsedQs } from 'qs';
import { Request as Request_2 } from 'express';
import { Response as Response_2 } from 'express';
import { RouteParameters } from 'express-serve-static-core';
import { Router } from 'express';
import { ContextualizedRouterWithExpressRouter, IContextualizedRouter } from './types/index.js';
export * from './contextCreator.js';
export * from './types/index.js';
import { Send } from 'express-serve-static-core';
/**
* Allow to retrieve the context of a child router according to the current router path and to the child router path.
*/
export declare type ChildRouterContext<Route extends string, BasePath extends string, Context> = Route extends `${BasePath}/${any}` ? Context : Route extends `${BasePath}` ? Context : BasePath extends '/' ? Route extends `${BasePath}${any}` ? Context : Record<string, never> : Record<string, never>;
export declare class ContextCreator<Context extends Record<string, any>> {
context: Context;
constructor(context: Context);
isExpressContext: boolean;
getContext: () => Context;
}
export declare type ContextualizedRequest<Context = Record<string, any>, P extends Record<string, any> = {}, ResBody = any, ReqBody = any, ReqQuery extends ParsedQs = any> = Request_2<P, ResBody, ReqBody, ReqQuery> & {
context: Context;
};
/**
* The equivalent of Express RequestHandler but with a Context object in Request.
*/
export declare type ContextualizedRequestHandler<InputContext extends Record<string, any> = Record<string, any>, OutputContext extends Record<string, any> = Record<string, any>, P extends Record<string, any> = {}, ResBody = any, ReqBody = any, ReqQuery extends ParsedQs = any> = (req: ContextualizedRequest<InputContext, P, ResBody, ReqBody, ReqQuery>, res: Response_2<ResBody>, next: NextFunction) => ContextCreator<OutputContext> | undefined | Send | Response_2<ResBody> | void | Promise<ContextCreator<OutputContext> | undefined | Send | Response_2<ResBody> | void>;
export declare type ContextualizedRequestHandlerParams<InputContext extends Record<string, any> = Record<string, any>, OutputContext extends Record<string, any> = Record<string, any>, P extends Record<string, any> = {}, ResBody = any, ReqBody = any, ReqQuery extends ParsedQs = any> = ContextualizedRequestHandler<InputContext, OutputContext, P, ResBody, ReqBody, ReqQuery> | Array<ContextualizedRequestHandler<InputContext, OutputContext, P>>;
/**
* Create a contextualized Router.

@@ -11,1 +38,111 @@ *

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>;
/**
* The equivalent of Express RouterHandler but which takes a ContextualizedRequestHandler and returns a ContextualizedRouter
*/
export declare interface ContextualizedRouterHandler<Context extends Record<string, any>, BasePath extends string, P extends Record<string, any> = {}, ResBody = any, ReqBody = any, ReqQuery extends ParsedQs = any> {
<OutputContext extends Record<string, any>>(...handlers: Array<ContextualizedRequestHandler<ChildRouterContext<'', BasePath, Context>, OutputContext, P, ResBody, ReqBody, ReqQuery>>): IContextualizedRouter<Context extends Record<string, never> ? OutputContext : Context & OutputContext, '', P, ResBody, ReqBody, ReqQuery>;
<OutputContext1 extends Record<string, any>, OutputContext2 extends Record<string, any>>(handler1: ContextualizedRequestHandler<ChildRouterContext<'', BasePath, Context>, OutputContext1, P, ResBody, ReqBody, ReqQuery>, handler2: ContextualizedRequestHandler<ChildRouterContext<'', BasePath, Context> & OutputContext1, OutputContext2, P, ResBody, ReqBody, ReqQuery>): IContextualizedRouter<Context extends Record<string, never> ? OutputContext1 & OutputContext2 : Context & OutputContext1 & OutputContext2, '', P, ResBody, ReqBody, ReqQuery>;
<OutputContext1 extends Record<string, any>, OutputContext2 extends Record<string, any>, OutputContext3 extends Record<string, any>>(handler1: ContextualizedRequestHandler<ChildRouterContext<'', BasePath, Context>, OutputContext1, P, ResBody, ReqBody, ReqQuery>, handler2: ContextualizedRequestHandler<ChildRouterContext<'', BasePath, Context> & OutputContext1, OutputContext2, P, ResBody, ReqBody, ReqQuery>, handler3: ContextualizedRequestHandler<ChildRouterContext<'', BasePath, Context> & OutputContext1 & OutputContext2, OutputContext3, P, ResBody, ReqBody, ReqQuery>): IContextualizedRouter<Context extends Record<string, never> ? OutputContext1 & OutputContext2 & OutputContext3 : Context & OutputContext1 & OutputContext2 & OutputContext3, '', P, ResBody, ReqBody, ReqQuery>;
<OutputContext1 extends Record<string, any>, OutputContext2 extends Record<string, any>, OutputContext3 extends Record<string, any>, OutputContext4 extends Record<string, any>>(handler1: ContextualizedRequestHandler<ChildRouterContext<'', BasePath, Context>, OutputContext1, P, ResBody, ReqBody, ReqQuery>, handler2: ContextualizedRequestHandler<ChildRouterContext<'', BasePath, Context> & OutputContext1, OutputContext2, P, ResBody, ReqBody, ReqQuery>, handler3: ContextualizedRequestHandler<ChildRouterContext<'', BasePath, Context> & OutputContext1 & OutputContext2, OutputContext3, P, ResBody, ReqBody, ReqQuery>, handler4: ContextualizedRequestHandler<ChildRouterContext<'', BasePath, Context> & OutputContext1 & OutputContext2 & OutputContext3, OutputContext4, P, ResBody, ReqBody, ReqQuery>): IContextualizedRouter<Context extends Record<string, never> ? OutputContext1 & OutputContext2 & OutputContext3 & OutputContext4 : Context & OutputContext1 & OutputContext2 & OutputContext3 & OutputContext4, '', P, ResBody, ReqBody, ReqQuery>;
<OutputContext1 extends Record<string, any>, OutputContext2 extends Record<string, any>, OutputContext3 extends Record<string, any>, OutputContext4 extends Record<string, any>, OutputContext5 extends Record<string, any>>(handler1: ContextualizedRequestHandler<ChildRouterContext<'', BasePath, Context>, OutputContext1, P, ResBody, ReqBody, ReqQuery>, handler2: ContextualizedRequestHandler<ChildRouterContext<'', BasePath, Context> & OutputContext1, OutputContext2, P, ResBody, ReqBody, ReqQuery>, handler3: ContextualizedRequestHandler<ChildRouterContext<'', BasePath, Context> & OutputContext1 & OutputContext2, OutputContext3, P, ResBody, ReqBody, ReqQuery>, handler4: ContextualizedRequestHandler<ChildRouterContext<'', BasePath, Context> & OutputContext1 & OutputContext2 & OutputContext3, OutputContext4, P, ResBody, ReqBody, ReqQuery>, handler5: ContextualizedRequestHandler<ChildRouterContext<'', BasePath, Context> & OutputContext1 & OutputContext2 & OutputContext3 & OutputContext4, OutputContext5, P, ResBody, ReqBody, ReqQuery>): IContextualizedRouter<Context extends Record<string, never> ? OutputContext1 & OutputContext2 & OutputContext3 & OutputContext4 & OutputContext5 : Context & OutputContext1 & OutputContext2 & OutputContext3 & OutputContext4 & OutputContext5, '', P, ResBody, ReqBody, ReqQuery>;
<OutputContext1 extends Record<string, any>, OutputContext2 extends Record<string, any>, OutputContext3 extends Record<string, any>, OutputContext4 extends Record<string, any>, OutputContext5 extends Record<string, any>, OutputContext6 extends Record<string, any>>(handler1: ContextualizedRequestHandler<ChildRouterContext<'', BasePath, Context>, OutputContext1, P, ResBody, ReqBody, ReqQuery>, handler2: ContextualizedRequestHandler<ChildRouterContext<'', BasePath, Context> & OutputContext1, OutputContext2, P, ResBody, ReqBody, ReqQuery>, handler3: ContextualizedRequestHandler<ChildRouterContext<'', BasePath, Context> & OutputContext1 & OutputContext2, OutputContext3, P, ResBody, ReqBody, ReqQuery>, handler4: ContextualizedRequestHandler<ChildRouterContext<'', BasePath, Context> & OutputContext1 & OutputContext2 & OutputContext3, OutputContext4, P, ResBody, ReqBody, ReqQuery>, handler5: ContextualizedRequestHandler<ChildRouterContext<'', BasePath, Context> & OutputContext1 & OutputContext2 & OutputContext3 & OutputContext4, OutputContext5, P, ResBody, ReqBody, ReqQuery>, handle6: ContextualizedRequestHandler<ChildRouterContext<'', BasePath, Context> & OutputContext1 & OutputContext2 & OutputContext3 & OutputContext4 & OutputContext5, OutputContext6, P, ResBody, ReqBody, ReqQuery>): IContextualizedRouter<Context extends Record<string, never> ? OutputContext1 & OutputContext2 & OutputContext3 & OutputContext4 & OutputContext5 & OutputContext6 : Context & OutputContext1 & OutputContext2 & OutputContext3 & OutputContext4 & OutputContext5 & OutputContext6, '', P, ResBody, ReqBody, ReqQuery>;
<OutputContext1 extends Record<string, any>, OutputContext2 extends Record<string, any>>(handlers: [
ContextualizedRequestHandler<ChildRouterContext<'', BasePath, Context>, OutputContext1, P, ResBody, ReqBody, ReqQuery>,
ContextualizedRequestHandler<ChildRouterContext<'', BasePath, Context> & OutputContext1, OutputContext2, P, ResBody, ReqBody, ReqQuery>
]): IContextualizedRouter<Context extends Record<string, never> ? OutputContext1 & OutputContext2 : Context & OutputContext1 & OutputContext2, '', P, ResBody, ReqBody, ReqQuery>;
<OutputContext1 extends Record<string, any>, OutputContext2 extends Record<string, any>, OutputContext3 extends Record<string, any>>(handlers: [
ContextualizedRequestHandler<ChildRouterContext<'', BasePath, Context>, OutputContext1, P, ResBody, ReqBody, ReqQuery>,
ContextualizedRequestHandler<ChildRouterContext<'', BasePath, Context> & OutputContext1, OutputContext2, P, ResBody, ReqBody, ReqQuery>,
ContextualizedRequestHandler<ChildRouterContext<'', BasePath, Context> & OutputContext1 & OutputContext2, OutputContext3, P, ResBody, ReqBody, ReqQuery>
]): IContextualizedRouter<Context extends Record<string, never> ? OutputContext1 & OutputContext2 & OutputContext3 : Context & OutputContext1 & OutputContext2 & OutputContext3, '', P, ResBody, ReqBody, ReqQuery>;
<OutputContext1 extends Record<string, any>, OutputContext2 extends Record<string, any>, OutputContext3 extends Record<string, any>, OutputContext4 extends Record<string, any>>(handlers: [
ContextualizedRequestHandler<ChildRouterContext<'', BasePath, Context>, OutputContext1, P, ResBody, ReqBody, ReqQuery>,
ContextualizedRequestHandler<ChildRouterContext<'', BasePath, Context> & OutputContext1, OutputContext2, P, ResBody, ReqBody, ReqQuery>,
ContextualizedRequestHandler<ChildRouterContext<'', BasePath, Context> & OutputContext1 & OutputContext2, OutputContext3, P, ResBody, ReqBody, ReqQuery>,
ContextualizedRequestHandler<ChildRouterContext<'', BasePath, Context> & OutputContext1 & OutputContext2 & OutputContext3, OutputContext4, P, ResBody, ReqBody, ReqQuery>
]): IContextualizedRouter<Context extends Record<string, never> ? OutputContext1 & OutputContext2 & OutputContext3 & OutputContext4 : Context & OutputContext1 & OutputContext2 & OutputContext3 & OutputContext4, '', P, ResBody, ReqBody, ReqQuery>;
<OutputContext1 extends Record<string, any>, OutputContext2 extends Record<string, any>, OutputContext3 extends Record<string, any>, OutputContext4 extends Record<string, any>, OutputContext5 extends Record<string, any>>(handlers: [
ContextualizedRequestHandler<ChildRouterContext<'', BasePath, Context>, OutputContext1, P, ResBody, ReqBody, ReqQuery>,
ContextualizedRequestHandler<ChildRouterContext<'', BasePath, Context> & OutputContext1, OutputContext2, P, ResBody, ReqBody, ReqQuery>,
ContextualizedRequestHandler<ChildRouterContext<'', BasePath, Context> & OutputContext1 & OutputContext2, OutputContext3, P, ResBody, ReqBody, ReqQuery>,
ContextualizedRequestHandler<ChildRouterContext<'', BasePath, Context> & OutputContext1 & OutputContext2 & OutputContext3, OutputContext4, P, ResBody, ReqBody, ReqQuery>,
ContextualizedRequestHandler<ChildRouterContext<'', BasePath, Context> & OutputContext1 & OutputContext2 & OutputContext3 & OutputContext4, OutputContext5, P, ResBody, ReqBody, ReqQuery>
]): IContextualizedRouter<Context extends Record<string, never> ? OutputContext1 & OutputContext2 & OutputContext3 & OutputContext4 & OutputContext5 : Context & OutputContext1 & OutputContext2 & OutputContext3 & OutputContext4 & OutputContext5, '', P, ResBody, ReqBody, ReqQuery>;
<OutputContext1 extends Record<string, any>, OutputContext2 extends Record<string, any>, OutputContext3 extends Record<string, any>, OutputContext4 extends Record<string, any>, OutputContext5 extends Record<string, any>, OutputContext6 extends Record<string, any>>(handlers: [
ContextualizedRequestHandler<ChildRouterContext<'', BasePath, Context>, OutputContext1, P, ResBody, ReqBody, ReqQuery>,
ContextualizedRequestHandler<ChildRouterContext<'', BasePath, Context> & OutputContext1, OutputContext2, P, ResBody, ReqBody, ReqQuery>,
ContextualizedRequestHandler<ChildRouterContext<'', BasePath, Context> & OutputContext1 & OutputContext2, OutputContext3, P, ResBody, ReqBody, ReqQuery>,
ContextualizedRequestHandler<ChildRouterContext<'', BasePath, Context> & OutputContext1 & OutputContext2 & OutputContext3, OutputContext4, P, ResBody, ReqBody, ReqQuery>,
ContextualizedRequestHandler<ChildRouterContext<'', BasePath, Context> & OutputContext1 & OutputContext2 & OutputContext3 & OutputContext4, OutputContext5, P, ResBody, ReqBody, ReqQuery>,
ContextualizedRequestHandler<ChildRouterContext<'', BasePath, Context> & OutputContext1 & OutputContext2 & OutputContext3 & OutputContext4 & OutputContext5, OutputContext6, P, ResBody, ReqBody, ReqQuery>
]): IContextualizedRouter<Context extends Record<string, never> ? OutputContext1 & OutputContext2 & OutputContext3 & OutputContext4 & OutputContext5 & OutputContext6 : Context & OutputContext1 & OutputContext2 & OutputContext3 & OutputContext4 & OutputContext5 & OutputContext6, '', P, ResBody, ReqBody, ReqQuery>;
<OutputContext extends Record<string, any>>(...handlers: Array<Array<ContextualizedRequestHandler<ChildRouterContext<'', BasePath, Context>, OutputContext, P, ResBody, ReqBody, ReqQuery>>>): IContextualizedRouter<Context extends Record<string, never> ? OutputContext : Context & OutputContext, '', P, ResBody, ReqBody, ReqQuery>;
}
/**
* The equivalent of Express RouterMatcher but which takes a ContextualizedRequestHandler and returns a ContextualizedRouter
*/
export declare interface ContextualizedRouterMatcher<Context extends Record<string, any>, BasePath extends string, P extends Record<string, any> = {}, ResBody = any, ReqBody = any, ReqQuery extends ParsedQs = any> {
<OutputContext extends Record<string, any>, Route extends string>(path: Route, ...handlers: Array<ContextualizedRequestHandler<ChildRouterContext<Route, BasePath, Context>, OutputContext, P & RouteParameters<Route>, ResBody, ReqBody, ReqQuery>>): Context & OutputContext extends Record<string, never> ? ContextualizedRouterWithExpressRouter<Context extends Record<string, never> ? OutputContext : Context & OutputContext, Route, P & RouteParameters<Route>> : IContextualizedRouter<Context extends Record<string, never> ? OutputContext : Context & OutputContext, Route, P & RouteParameters<Route>>;
<OutputContext extends Record<string, any>, Route extends string>(path: Route, ...handlers: Array<Array<ContextualizedRequestHandler<ChildRouterContext<Route, BasePath, Context>, OutputContext, P & RouteParameters<Route>, ResBody, ReqBody, ReqQuery>>>): Context & OutputContext extends Record<string, never> ? ContextualizedRouterWithExpressRouter<Context extends Record<string, never> ? OutputContext : Context & OutputContext, Route, P & RouteParameters<Route>> : IContextualizedRouter<Context extends Record<string, never> ? OutputContext : Context & OutputContext, Route, P & RouteParameters<Route>>;
<OutputContext1 extends Record<string, any>, OutputContext2 extends Record<string, any>, Route extends string>(path: Route, handler1: ContextualizedRequestHandler<ChildRouterContext<Route, BasePath, Context>, OutputContext1, P, ResBody, ReqBody, ReqQuery>, handler2: ContextualizedRequestHandler<ChildRouterContext<Route, BasePath, Context> & OutputContext1, OutputContext2, P, ResBody, ReqBody, ReqQuery>): IContextualizedRouter<Context extends Record<string, never> ? OutputContext1 & OutputContext2 : Context & OutputContext1 & OutputContext2, Route, P, ResBody, ReqBody, ReqQuery>;
<OutputContext1 extends Record<string, any>, OutputContext2 extends Record<string, any>, OutputContext3 extends Record<string, any>, Route extends string>(path: Route, handler1: ContextualizedRequestHandler<ChildRouterContext<Route, BasePath, Context>, OutputContext1, P, ResBody, ReqBody, ReqQuery>, handler2: ContextualizedRequestHandler<ChildRouterContext<Route, BasePath, Context> & OutputContext1, OutputContext2, P, ResBody, ReqBody, ReqQuery>, handler3: ContextualizedRequestHandler<ChildRouterContext<Route, BasePath, Context> & OutputContext1 & OutputContext2, OutputContext3, P, ResBody, ReqBody, ReqQuery>): IContextualizedRouter<Context extends Record<string, never> ? OutputContext1 & OutputContext2 & OutputContext3 : Context & OutputContext1 & OutputContext2 & OutputContext3, Route, P, ResBody, ReqBody, ReqQuery>;
<OutputContext1 extends Record<string, any>, OutputContext2 extends Record<string, any>, OutputContext3 extends Record<string, any>, OutputContext4 extends Record<string, any>, Route extends string>(path: Route, handler1: ContextualizedRequestHandler<ChildRouterContext<Route, BasePath, Context>, OutputContext1, P, ResBody, ReqBody, ReqQuery>, handler2: ContextualizedRequestHandler<ChildRouterContext<Route, BasePath, Context> & OutputContext1, OutputContext2, P, ResBody, ReqBody, ReqQuery>, handler3: ContextualizedRequestHandler<ChildRouterContext<Route, BasePath, Context> & OutputContext1 & OutputContext2, OutputContext3, P, ResBody, ReqBody, ReqQuery>, handler4: ContextualizedRequestHandler<ChildRouterContext<Route, BasePath, Context> & OutputContext1 & OutputContext2 & OutputContext3, OutputContext4, P, ResBody, ReqBody, ReqQuery>): IContextualizedRouter<Context extends Record<string, never> ? OutputContext1 & OutputContext2 & OutputContext3 & OutputContext4 : Context & OutputContext1 & OutputContext2 & OutputContext3 & OutputContext4, Route, P, ResBody, ReqBody, ReqQuery>;
<OutputContext1 extends Record<string, any>, OutputContext2 extends Record<string, any>, OutputContext3 extends Record<string, any>, OutputContext4 extends Record<string, any>, OutputContext5 extends Record<string, any>, Route extends string>(path: Route, handler1: ContextualizedRequestHandler<ChildRouterContext<Route, BasePath, Context>, OutputContext1, P, ResBody, ReqBody, ReqQuery>, handler2: ContextualizedRequestHandler<ChildRouterContext<Route, BasePath, Context> & OutputContext1, OutputContext2, P, ResBody, ReqBody, ReqQuery>, handler3: ContextualizedRequestHandler<ChildRouterContext<Route, BasePath, Context> & OutputContext1 & OutputContext2, OutputContext3, P, ResBody, ReqBody, ReqQuery>, handler4: ContextualizedRequestHandler<ChildRouterContext<Route, BasePath, Context> & OutputContext1 & OutputContext2 & OutputContext3, OutputContext4, P, ResBody, ReqBody, ReqQuery>, handler5: ContextualizedRequestHandler<ChildRouterContext<Route, BasePath, Context> & OutputContext1 & OutputContext2 & OutputContext3 & OutputContext4, OutputContext5, P, ResBody, ReqBody, ReqQuery>): IContextualizedRouter<Context extends Record<string, never> ? OutputContext1 & OutputContext2 & OutputContext3 & OutputContext4 & OutputContext5 : Context & OutputContext1 & OutputContext2 & OutputContext3 & OutputContext4 & OutputContext5, Route, P, ResBody, ReqBody, ReqQuery>;
<OutputContext1 extends Record<string, any>, OutputContext2 extends Record<string, any>, OutputContext3 extends Record<string, any>, OutputContext4 extends Record<string, any>, OutputContext5 extends Record<string, any>, OutputContext6 extends Record<string, any>, Route extends string>(path: Route, handler1: ContextualizedRequestHandler<ChildRouterContext<Route, BasePath, Context>, OutputContext1, P, ResBody, ReqBody, ReqQuery>, handler2: ContextualizedRequestHandler<ChildRouterContext<Route, BasePath, Context> & OutputContext1, OutputContext2, P, ResBody, ReqBody, ReqQuery>, handler3: ContextualizedRequestHandler<ChildRouterContext<Route, BasePath, Context> & OutputContext1 & OutputContext2, OutputContext3, P, ResBody, ReqBody, ReqQuery>, handler4: ContextualizedRequestHandler<ChildRouterContext<Route, BasePath, Context> & OutputContext1 & OutputContext2 & OutputContext3, OutputContext4, P, ResBody, ReqBody, ReqQuery>, handler5: ContextualizedRequestHandler<ChildRouterContext<Route, BasePath, Context> & OutputContext1 & OutputContext2 & OutputContext3 & OutputContext4, OutputContext5, P, ResBody, ReqBody, ReqQuery>, handle6: ContextualizedRequestHandler<ChildRouterContext<Route, BasePath, Context> & OutputContext1 & OutputContext2 & OutputContext3 & OutputContext4 & OutputContext5, OutputContext6, P, ResBody, ReqBody, ReqQuery>): IContextualizedRouter<Context extends Record<string, never> ? OutputContext1 & OutputContext2 & OutputContext3 & OutputContext4 & OutputContext5 & OutputContext6 : Context & OutputContext1 & OutputContext2 & OutputContext3 & OutputContext4 & OutputContext5 & OutputContext6, '', P, ResBody, ReqBody, ReqQuery>;
<OutputContext1 extends Record<string, any>, OutputContext2 extends Record<string, any>, Route extends string>(path: Route, handlers: [
ContextualizedRequestHandler<ChildRouterContext<Route, BasePath, Context>, OutputContext1, P, ResBody, ReqBody, ReqQuery>,
ContextualizedRequestHandler<ChildRouterContext<Route, BasePath, Context> & OutputContext1, OutputContext2, P, ResBody, ReqBody, ReqQuery>
]): IContextualizedRouter<Context extends Record<string, never> ? OutputContext1 & OutputContext2 : Context & OutputContext1 & OutputContext2, Route, P, ResBody, ReqBody, ReqQuery>;
<OutputContext1 extends Record<string, any>, OutputContext2 extends Record<string, any>, OutputContext3 extends Record<string, any>, Route extends string>(path: Route, handlers: [
ContextualizedRequestHandler<ChildRouterContext<Route, BasePath, Context>, OutputContext1, P, ResBody, ReqBody, ReqQuery>,
ContextualizedRequestHandler<ChildRouterContext<Route, BasePath, Context> & OutputContext1, OutputContext2, P, ResBody, ReqBody, ReqQuery>,
ContextualizedRequestHandler<ChildRouterContext<Route, BasePath, Context> & OutputContext1 & OutputContext2, OutputContext3, P, ResBody, ReqBody, ReqQuery>
]): IContextualizedRouter<Context extends Record<string, never> ? OutputContext1 & OutputContext2 & OutputContext3 : Context & OutputContext1 & OutputContext2 & OutputContext3, Route, P, ResBody, ReqBody, ReqQuery>;
<OutputContext1 extends Record<string, any>, OutputContext2 extends Record<string, any>, OutputContext3 extends Record<string, any>, OutputContext4 extends Record<string, any>, Route extends string>(path: Route, handlers: [
ContextualizedRequestHandler<ChildRouterContext<Route, BasePath, Context>, OutputContext1, P, ResBody, ReqBody, ReqQuery>,
ContextualizedRequestHandler<ChildRouterContext<Route, BasePath, Context> & OutputContext1, OutputContext2, P, ResBody, ReqBody, ReqQuery>,
ContextualizedRequestHandler<ChildRouterContext<Route, BasePath, Context> & OutputContext1 & OutputContext2, OutputContext3, P, ResBody, ReqBody, ReqQuery>,
ContextualizedRequestHandler<ChildRouterContext<Route, BasePath, Context> & OutputContext1 & OutputContext2 & OutputContext3, OutputContext4, P, ResBody, ReqBody, ReqQuery>
]): IContextualizedRouter<Context extends Record<string, never> ? OutputContext1 & OutputContext2 & OutputContext3 & OutputContext4 : Context & OutputContext1 & OutputContext2 & OutputContext3 & OutputContext4, Route, P, ResBody, ReqBody, ReqQuery>;
<OutputContext1 extends Record<string, any>, OutputContext2 extends Record<string, any>, OutputContext3 extends Record<string, any>, OutputContext4 extends Record<string, any>, OutputContext5 extends Record<string, any>, Route extends string>(path: Route, handlers: [
ContextualizedRequestHandler<ChildRouterContext<Route, BasePath, Context>, OutputContext1, P, ResBody, ReqBody, ReqQuery>,
ContextualizedRequestHandler<ChildRouterContext<Route, BasePath, Context> & OutputContext1, OutputContext2, P, ResBody, ReqBody, ReqQuery>,
ContextualizedRequestHandler<ChildRouterContext<Route, BasePath, Context> & OutputContext1 & OutputContext2, OutputContext3, P, ResBody, ReqBody, ReqQuery>,
ContextualizedRequestHandler<ChildRouterContext<Route, BasePath, Context> & OutputContext1 & OutputContext2 & OutputContext3, OutputContext4, P, ResBody, ReqBody, ReqQuery>,
ContextualizedRequestHandler<ChildRouterContext<Route, BasePath, Context> & OutputContext1 & OutputContext2 & OutputContext3 & OutputContext4, OutputContext5, P, ResBody, ReqBody, ReqQuery>
]): IContextualizedRouter<Context extends Record<string, never> ? OutputContext1 & OutputContext2 & OutputContext3 & OutputContext4 & OutputContext5 : Context & OutputContext1 & OutputContext2 & OutputContext3 & OutputContext4 & OutputContext5, Route, P, ResBody, ReqBody, ReqQuery>;
<OutputContext1 extends Record<string, any>, OutputContext2 extends Record<string, any>, OutputContext3 extends Record<string, any>, OutputContext4 extends Record<string, any>, OutputContext5 extends Record<string, any>, OutputContext6 extends Record<string, any>, Route extends string>(path: Route, handlers: [
ContextualizedRequestHandler<ChildRouterContext<Route, BasePath, Context>, OutputContext1, P, ResBody, ReqBody, ReqQuery>,
ContextualizedRequestHandler<ChildRouterContext<Route, BasePath, Context> & OutputContext1, OutputContext2, P, ResBody, ReqBody, ReqQuery>,
ContextualizedRequestHandler<ChildRouterContext<Route, BasePath, Context> & OutputContext1 & OutputContext2, OutputContext3, P, ResBody, ReqBody, ReqQuery>,
ContextualizedRequestHandler<ChildRouterContext<Route, BasePath, Context> & OutputContext1 & OutputContext2 & OutputContext3, OutputContext4, P, ResBody, ReqBody, ReqQuery>,
ContextualizedRequestHandler<ChildRouterContext<Route, BasePath, Context> & OutputContext1 & OutputContext2 & OutputContext3 & OutputContext4, OutputContext5, P, ResBody, ReqBody, ReqQuery>,
ContextualizedRequestHandler<ChildRouterContext<Route, BasePath, Context> & OutputContext1 & OutputContext2 & OutputContext3 & OutputContext4 & OutputContext5, OutputContext6, P, ResBody, ReqBody, ReqQuery>
]): IContextualizedRouter<Context extends Record<string, never> ? OutputContext1 & OutputContext2 & OutputContext3 & OutputContext4 & OutputContext5 & OutputContext6 : Context & OutputContext1 & OutputContext2 & OutputContext3 & OutputContext4 & OutputContext5 & OutputContext6, '', P, ResBody, ReqBody, ReqQuery>;
}
/**
* Router is useful to use ContextualizedRouter directly with express (e.g: app.use(contextualizedRouter)).
* However if the use a ContextualizedRouter directly with Express we won't be type safe anymore, so we only expose this property if the context is empty.
*/
export declare type ContextualizedRouterWithExpressRouter<Context extends Record<string, any>, BasePath extends string, P extends Record<string, any>> = IContextualizedRouter<Context, BasePath, P> & {
expressRouter: Router;
};
/**
* The equivalent of Express Router but with route matcher defined as ContextualizedRouterMatcher.
*/
export declare interface IContextualizedRouter<Context extends Record<string, any>, BasePath extends string, P extends Record<string, any>, ResBody = any, ReqBody = any, ReqQuery extends ParsedQs = any> extends Omit<Router, 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head' | 'use'>, ContextualizedRequestHandler<Context, Record<string, never>, P, ResBody, ReqBody, ReqQuery> {
get: ContextualizedRouterMatcher<Context, BasePath, P, ResBody, ReqBody, ReqQuery>;
post: ContextualizedRouterMatcher<Context, BasePath, P, ResBody, ReqBody, ReqQuery>;
put: ContextualizedRouterMatcher<Context, BasePath, P, ResBody, ReqBody, ReqQuery>;
delete: ContextualizedRouterMatcher<Context, BasePath, P, ResBody, ReqBody, ReqQuery>;
patch: ContextualizedRouterMatcher<Context, BasePath, P, ResBody, ReqBody, ReqQuery>;
options: ContextualizedRouterMatcher<Context, BasePath, P, ResBody, ReqBody, ReqQuery>;
head: ContextualizedRouterMatcher<Context, BasePath, P, ResBody, ReqBody, ReqQuery>;
use: ContextualizedRouterMatcher<Context, BasePath, P, ResBody, ReqBody, ReqQuery> & ContextualizedRouterHandler<Context, BasePath, P, ResBody, ReqBody, ReqQuery>;
}
export { }

55

dist/index.js

@@ -1,27 +0,31 @@

import { Router as m } from "express";
class E {
var y = Object.defineProperty;
var z = (o, t, e) => t in o ? y(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e;
var p = (o, t, e) => (z(o, typeof t != "symbol" ? t + "" : t, e), e);
import { Router as f } from "express";
class b {
constructor(t) {
this.context = t, this.isExpressContext = !0, this.getContext = () => this.context;
p(this, "isExpressContext", !0);
p(this, "getContext", () => this.context);
this.context = t;
}
}
const s = (n, t) => (r, ...p) => {
const d = typeof r == "string" ? r : "", f = typeof r == "string" ? p : [r, ...p];
for (const a of f.flat()) {
const s = (o, t) => (r, ...l) => {
const d = typeof r == "string" ? r : "", C = typeof r == "string" ? l : [r, ...l];
for (const a of C.flat()) {
if ("use" in a) {
t[n](d, a);
t[o](d, a);
continue;
}
const h = async (o, C, u) => {
var x;
const m = async (n, h, u) => {
try {
o.context = o.context || {};
let c = !1, l;
const g = Object.assign(o, {
context: (x = o.context) !== null && x !== void 0 ? x : {}
}), i = await a(g, C, (v) => {
c = !0, l = v;
n.context = n.context || {};
let c = !1, x;
const g = Object.assign(n, {
context: n.context ?? {}
}), i = await a(g, h, (R) => {
c = !0, x = R;
});
if (!i || !("isExpressContext" in i && i.isExpressContext)) {
if (c) {
u(l);
u(x);
return;

@@ -31,7 +35,6 @@ }

}
o.context = {
...o.context,
n.context = {
...n.context,
...i.getContext()
}, u(l);
return;
}, u(x);
} catch (c) {

@@ -41,12 +44,12 @@ u(c);

};
Object.defineProperty(h, "name", { value: a.name }), t[n](d, h);
Object.defineProperty(m, "name", { value: a.name }), t[o](d, m);
}
return y(t);
}, y = (n) => {
const t = n ?? m(), e = m();
return E(t);
}, E = (o) => {
const t = o ?? f(), e = f();
return e.get = s("get", t), e.post = s("post", t), e.put = s("put", t), e.delete = s("delete", t), e.patch = s("patch", t), e.options = s("options", t), e.head = s("head", t), e.use = s("use", t), e.params = t.params, e._params = t._params, e.caseSensitive = t.caseSensitive, e.mergeParams = t.mergeParams, e.strict = t.strict, e.stack = t.stack, e.expressRouter = t, e;
};
export {
E as ContextCreator,
y as ContextualizedRouter
b as ContextCreator,
E as ContextualizedRouter
};
{
"name": "express-contextualized-router",
"version": "1.4.1",
"version": "1.5.0",
"type": "module",

@@ -34,32 +34,33 @@ "exports": {

"prepublishOnly": "yarn build",
"release": "npx semantic-release@20.0.1"
"release": "semantic-release"
},
"devDependencies": {
"@commitlint/config-conventional": "17.6.6",
"@rollup/plugin-typescript": "11.1.1",
"@commitlint/config-conventional": "17.7.0",
"@tsconfig/strictest": "2.0.1",
"@types/express": "4.17.17",
"@types/node": "18.16.19",
"@types/node": "18.17.5",
"@types/supertest": "2.0.12",
"@typescript-eslint/eslint-plugin": "5.61.0",
"@typescript-eslint/parser": "5.61.0",
"@vitest/coverage-c8": "0.31.4",
"@typescript-eslint/eslint-plugin": "5.62.0",
"@typescript-eslint/parser": "5.62.0",
"@vitest/coverage-v8": "0.34.1",
"builtin-modules": "3.3.0",
"c8": "8.0.0",
"commitlint": "17.6.6",
"eslint": "8.41.0",
"eslint-config-prettier": "8.8.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.27.5",
"eslint-plugin-import": "2.28.0",
"eslint-plugin-n": "16.0.1",
"eslint-plugin-node": "11.1.0",
"eslint-plugin-prettier": "4.2.1",
"eslint-plugin-prettier": "5.0.0",
"eslint-plugin-promise": "6.1.1",
"express": "4.18.2",
"husky": "8.0.3",
"lint-staged": "13.1.0",
"prettier": "2.8.8",
"lint-staged": "14.0.0",
"prettier": "3.0.1",
"semantic-release": "21.0.7",
"supertest": "6.3.3",
"typescript": "5.1.6",
"vite": "4.3.9",
"vitest": "0.31.4"
"vite": "4.4.9",
"vite-plugin-dts": "3.5.2",
"vitest": "0.34.1"
},

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

@@ -8,4 +8,4 @@ {

"assignAutomerge": true,
"reviewers": ["KillianHmyd", "GuillaumeRahbari"],
"reviewersSampleSize": 1,
"assignees": ["KillianHmyd", "GuillaumeRahbari"],
"assigneesSampleSize": 1,
"packageRules": [

@@ -36,6 +36,2 @@ {

"labels": ["dependencies"],
"node": {
"enabled": true,
"supportPolicy": ["lts_latest"]
},
"postUpdateOptions": ["yarnDedupeHighest"],

@@ -42,0 +38,0 @@ "includeForks": true,

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

next(returnedError)
return
} catch (err) {

@@ -109,0 +108,0 @@ next(err)

{
"extends": "@tsconfig/strictest/tsconfig",
"compilerOptions": {
"module": "esnext",
"lib": ["es2023"],
"module": "Node16",
"target": "es2022",
"moduleResolution": "node16",
"baseUrl": ".",
"rootDir": "src",
"outDir": "dist",
"declaration": true,
"noImplicitReturns": false,
"noUnusedLocals": false,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"esModuleInterop": true,
"skipLibCheck": true,
"moduleResolution": "node16",
"noImplicitThis": true,
"noImplicitAny": true,
"strictNullChecks": true,
"suppressImplicitAnyIndexErrors": false,
"downlevelIteration": true,
"resolveJsonModule": true,
"sourceMap": true,
"strict": true,
"target": "es2019",
"lib": ["es2020"],
"noErrorTruncation": true
"declaration": true
},

@@ -27,0 +14,0 @@ "include": ["./src/**/*"],

import { defineConfig } from 'vite'
import { fileURLToPath } from 'node:url'
import { join } from 'path'
import builtins from 'builtin-modules'
import packageJson from './package.json' assert { type: 'json' }
import ts from '@rollup/plugin-typescript'
import dts from 'vite-plugin-dts'

@@ -25,3 +26,14 @@ const { dependencies, peerDependencies } = packageJson

},
plugins: [ts({ exclude: '**/*.test.ts' })],
plugins: [
dts({
tsconfigPath: join(__dirname, 'tsconfig.build.json'),
insertTypesEntry: true,
rollupTypes: true,
}),
],
test: {
coverage: {
reporter: ['text', 'json', 'html'],
},
},
})

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