Skip to content

PermissionPlugin

Defined in: src/plugins/application/permissions.ts:43

Shokupan Router

A router for organizing and grouping routes with shared middleware and configuration.

The shape of ctx.state for all routes in this router. Provides type safety for state management within the router’s middleware and handlers.

const router = new ShokupanRouter();
router.get('/users', (ctx) => ctx.json({ users: [] }));
app.mount('/api', router);
// Routes: GET /api/users
interface AuthState {
userId: string;
isAuthenticated: boolean;
}
class AuthRouter extends ShokupanRouter<AuthState> {
constructor() {
super();
// Router middleware has typed state
this.use((ctx, next) => {
ctx.state.userId = 'user-123';
ctx.state.isAuthenticated = true;
return next();
});
this.get('/me', (ctx) => {
// State is fully typed
return ctx.json({ userId: ctx.state.userId });
});
}
}
app.mount('/auth', new AuthRouter());
const apiRouter = new ShokupanRouter();
// Router-level middleware
apiRouter.use(async (ctx, next) => {
console.log(`API request: ${ctx.method} ${ctx.path}`);
return next();
});
apiRouter.get('/status', (ctx) => ctx.json({ status: 'ok' }));
app.mount('/api', apiRouter);

new PermissionPlugin(config): PermissionPlugin

Defined in: src/plugins/application/permissions.ts:48

PermissionConfig = {}

PermissionPlugin

ShokupanRouter.constructor

[$childControllers]: ShokupanController[] = []

Defined in: src/router.ts:101

ShokupanRouter.[$childControllers]


[$childRouters]: ShokupanRouter<any>[] = []

Defined in: src/router.ts:100

ShokupanRouter.[$childRouters]


[$mountPath]: string = "/"

Defined in: src/router.ts:97

ShokupanRouter.[$mountPath]


[$routes]: ShokupanRoute[] = []

Defined in: src/router.ts:146

ShokupanRouter.[$routes]


readonly optional config: object

Defined in: src/router.ts:297

optional autoBackpressureFeedback: boolean

Whether to enable automatic backpressure based on system CPU load.

false

optional autoBackpressureLevel: number

The CPU usage percentage threshold (0-100) at which to start rejecting requests.

optional fileAccessCheck: (ctx, path) => boolean

Custom file access check for routes that use ctx.file(). Return true to allow access to the file, false to deny.

ShokupanContext

string

boolean

optional group: string

optional hooks: { afterValidate?: (ctx, data) => void | Promise<void>; beforeValidate?: (ctx, data) => void | Promise<void>; onError?: (ctx, error) => void | Promise<void>; onReadTimeout?: (ctx) => void | Promise<void>; onRequestEnd?: (ctx) => void | Promise<void>; onRequestStart?: (ctx) => void | Promise<void>; onRequestTimeout?: (ctx) => void | Promise<void>; onResponseEnd?: (ctx, response) => void | Promise<void>; onResponseStart?: (ctx, response) => void | Promise<void>; onStop?: () => void | Promise<void>; onWriteTimeout?: (ctx) => void | Promise<void>; } | ({ afterValidate?: (ctx, data) => void | Promise<void>; beforeValidate?: (ctx, data) => void | Promise<void>; onError?: (ctx, error) => void | Promise<void>; onReadTimeout?: (ctx) => void | Promise<void>; onRequestEnd?: (ctx) => void | Promise<void>; onRequestStart?: (ctx) => void | Promise<void>; onRequestTimeout?: (ctx) => void | Promise<void>; onResponseEnd?: (ctx, response) => void | Promise<void>; onResponseStart?: (ctx, response) => void | Promise<void>; onStop?: () => void | Promise<void>; onWriteTimeout?: (ctx) => void | Promise<void>; } | undefined)[]

Hooks for this route/router.

optional name: string

optional openapi: {[key: `x-${string}`]: any; [key: string]: any; consumes?: (string | undefined)[]; deprecated?: boolean; description?: string; externalDocs?: {[key: string]: any; description?: string; url?: string; }; operationId?: string; parameters?: ({[key: `x-${string}`]: any; [key: string]: any; $ref?: string; } | {[key: string]: any; description?: string; in?: ParameterLocation; name?: string; required?: boolean; schema?: {[key: `x-${(...)}`]: any; [key: string]: any; $ref?: … | …; } | {[key: string]: any; [key: `x-${(...)}`]: any; $ref?: … | …; $schema?: … | …; additionalItems?: … | … | … | …; additionalProperties?: … | … | … | …; allOf?: … | …; anyOf?: … | …; default?: any; definitions?: … | …; dependencies?: … | …; description?: … | …; discriminator?: … | …; enum?: … | …; example?: any; exclusiveMaximum?: … | … | …; exclusiveMinimum?: … | … | …; externalDocs?: … | …; id?: … | …; items?: … | … | … | … | …; maximum?: … | …; maxItems?: … | …; maxLength?: … | …; maxProperties?: … | …; minimum?: … | …; minItems?: … | …; minLength?: … | …; minProperties?: … | …; multipleOf?: … | …; not?: … | …; oneOf?: … | …; pattern?: … | …; patternProperties?: … | …; properties?: … | …; readOnly?: … | … | …; required?: … | …; title?: … | …; type?: … | … | …; uniqueItems?: … | … | …; xml?: … | …; }; } | {[key: string]: any; $ref?: string; allowEmptyValue?: boolean; collectionFormat?: string; default?: any; description?: string; enum?: any[]; exclusiveMaximum?: boolean; exclusiveMinimum?: boolean; format?: string; in?: ParameterLocation; items?: {[key: `x-${(...)}`]: any; [key: string]: any; $ref?: … | …; } | { $ref?: … | …; collectionFormat?: … | …; default?: any; enum?: … | …; exclusiveMaximum?: … | … | …; exclusiveMinimum?: … | … | …; format?: … | …; items?: { [x: `x-${string}`]: any; [x: string]: any; $ref?: string | undefined; } | { type?: string | undefined; format?: string | undefined; items?: { [x: `x-${string}`]: any; [x: string]: any; $ref?: string | undefined; } | … | undefined; … 14 more …; $ref?: string | undefined; } | undefined; maximum?: … | …; maxItems?: … | …; maxLength?: … | …; minimum?: … | …; minItems?: … | …; minLength?: … | …; multipleOf?: … | …; pattern?: … | …; type?: … | …; uniqueItems?: … | … | …; }; maximum?: number; maxItems?: number; maxLength?: number; minimum?: number; minItems?: number; minLength?: number; multipleOf?: number; name?: string; pattern?: string; required?: boolean; type?: string; uniqueItems?: boolean; } | undefined)[]; produces?: (string | undefined)[]; responses?: {[key: string]: {[key: `x-${string}`]: any; [key: string]: any; $ref?: string; } | {[key: `x-${string}`]: any; [key: string]: any; description?: string; examples?: {[key: string]: any; }; headers?: {[key: string]: … | …; }; schema?: {[key: `x-${(...)}`]: any; [key: string]: any; $ref?: … | …; } | {[key: string]: any; [key: `x-${(...)}`]: any; $ref?: … | …; $schema?: … | …; additionalItems?: … | … | … | …; additionalProperties?: … | … | … | …; allOf?: … | …; anyOf?: … | …; default?: any; definitions?: … | …; dependencies?: … | …; description?: … | …; discriminator?: … | …; enum?: … | …; example?: any; exclusiveMaximum?: … | … | …; exclusiveMinimum?: … | … | …; externalDocs?: … | …; id?: … | …; items?: … | … | … | … | …; maximum?: … | …; maxItems?: … | …; maxLength?: … | …; maxProperties?: … | …; minimum?: … | …; minItems?: … | …; minLength?: … | …; minProperties?: … | …; multipleOf?: … | …; not?: … | …; oneOf?: … | …; pattern?: … | …; patternProperties?: … | …; properties?: … | …; readOnly?: … | … | …; required?: … | …; title?: … | …; type?: … | … | …; uniqueItems?: … | … | …; xml?: … | …; }; } | undefined; default?: {[key: `x-${string}`]: any; [key: string]: any; $ref?: string; } | {[key: `x-${string}`]: any; [key: string]: any; description?: string; examples?: {[key: string]: any; }; headers?: {[key: string]: … | …; }; schema?: {[key: `x-${(...)}`]: any; [key: string]: any; $ref?: … | …; } | {[key: string]: any; [key: `x-${(...)}`]: any; $ref?: … | …; $schema?: … | …; additionalItems?: … | … | … | …; additionalProperties?: … | … | … | …; allOf?: … | …; anyOf?: … | …; default?: any; definitions?: … | …; dependencies?: … | …; description?: … | …; discriminator?: … | …; enum?: … | …; example?: any; exclusiveMaximum?: … | … | …; exclusiveMinimum?: … | … | …; externalDocs?: … | …; id?: … | …; items?: … | … | … | … | …; maximum?: … | …; maxItems?: … | …; maxLength?: … | …; maxProperties?: … | …; minimum?: … | …; minItems?: … | …; minLength?: … | …; minProperties?: … | …; multipleOf?: … | …; not?: … | …; oneOf?: … | …; pattern?: … | …; patternProperties?: … | …; properties?: … | …; readOnly?: … | … | …; required?: … | …; title?: … | …; type?: … | … | …; uniqueItems?: … | … | …; xml?: … | …; }; }; }; schemes?: (string | undefined)[]; security?: ({[key: string]: (… | …)[] | undefined; } | undefined)[]; summary?: string; tags?: (string | undefined)[]; } | {[key: `x-${string}`]: any; [key: string]: any; callbacks?: {[key: string]: {[key: `x-${string}`]: any; [key: string]: any; $ref?: string; } | {[key: string]: {[key: `x-${(...)}`]: any; [key: string]: any; $ref?: … | …; delete?: … | …; description?: … | …; get?: … | …; head?: … | …; options?: … | …; parameters?: … | …; patch?: … | …; post?: … | …; put?: … | …; servers?: … | …; summary?: … | …; trace?: … | …; } | undefined; } | undefined; }; deprecated?: boolean; description?: string; externalDocs?: { description?: string; url?: string; }; operationId?: string; parameters?: ({[key: `x-${string}`]: any; [key: string]: any; $ref?: string; } | { allowEmptyValue?: boolean; allowReserved?: boolean; content?: {[key: string]: … | …; }; deprecated?: boolean; description?: string; example?: any; examples?: {[key: string]: … | … | …; }; explode?: boolean; in?: ParameterLocation; name?: string; required?: boolean; schema?: {[key: `x-${(...)}`]: any; [key: string]: any; $ref?: … | …; } | {[key: `x-${(...)}`]: any; [key: string]: any; additionalProperties?: … | … | … | … | … | …; allOf?: … | …; anyOf?: … | …; default?: any; deprecated?: … | … | …; description?: … | …; discriminator?: … | …; enum?: … | …; example?: any; exclusiveMaximum?: … | … | …; exclusiveMinimum?: … | … | …; externalDocs?: … | …; format?: … | …; items?: { [x: `x-${string}`]: any; [x: string]: any; $ref?: string | undefined; } | { [x: `x-${string}`]: any; [x: string]: any; type?: “array” | undefined; items?: { [x: `x-${string}`]: any; [x: string]: any; $ref?: string | undefined; } | … | { …; } | undefined; … 33 more …; deprecated?: boolean | undefined; } | {…; maximum?: … | …; maxItems?: … | …; maxLength?: … | …; maxProperties?: … | …; minimum?: … | …; minItems?: … | …; minLength?: … | …; minProperties?: … | …; multipleOf?: … | …; not?: { [x: `x-${string}`]: any; [x: string]: any; $ref?: string | undefined; } | { [x: `x-${string}`]: any; [x: string]: any; type?: “array” | undefined; items?: { [x: `x-${string}`]: any; [x: string]: any; $ref?: string | undefined; } | … | { …; } | undefined; … 33 more …; deprecated?: boolean | undefined; } | {…; nullable?: … | … | …; oneOf?: … | …; pattern?: … | …; patternProperties?: … | …; properties?: … | …; readOnly?: … | … | …; required?: … | …; title?: … | …; type?: … | …; uniqueItems?: … | … | …; writeOnly?: … | … | …; xml?: … | …; } | {[key: `x-${(...)}`]: any; [key: string]: any; additionalProperties?: … | … | … | … | … | …; allOf?: … | …; anyOf?: … | …; default?: any; deprecated?: … | … | …; description?: … | …; discriminator?: … | …; enum?: … | …; example?: any; exclusiveMaximum?: … | … | …; exclusiveMinimum?: … | … | …; externalDocs?: … | …; format?: … | …; maximum?: … | …; maxItems?: … | …; maxLength?: … | …; maxProperties?: … | …; minimum?: … | …; minItems?: … | …; minLength?: … | …; minProperties?: … | …; multipleOf?: … | …; not?: { [x: `x-${string}`]: any; [x: string]: any; $ref?: string | undefined; } | { [x: `x-${string}`]: any; [x: string]: any; type?: “array” | undefined; items?: { [x: `x-${string}`]: any; [x: string]: any; $ref?: string | undefined; } | … | { …; } | undefined; … 33 more …; deprecated?: boolean | undefined; } | {…; nullable?: … | … | …; oneOf?: … | …; pattern?: … | …; patternProperties?: … | …; properties?: … | …; readOnly?: … | … | …; required?: … | …; title?: … | …; type?: … | …; uniqueItems?: … | … | …; writeOnly?: … | … | …; xml?: … | …; }; style?: ParameterStyle; } | undefined)[]; requestBody?: {[key: `x-${string}`]: any; [key: string]: any; $ref?: string; } | { content?: {[key: string]: { encoding?: … | …; example?: any; examples?: … | …; schema?: … | … | … | …; } | undefined; }; description?: string; required?: boolean; }; responses?: {[key: string]: {[key: `x-${string}`]: any; [key: string]: any; $ref?: string; } | {[key: `x-${string}`]: any; [key: string]: any; content?: {[key: string]: … | …; }; description?: string; headers?: {[key: string]: … | … | …; }; links?: {[key: string]: … | … | …; }; } | undefined; }; security?: ({[key: string]: (… | …)[] | undefined; } | undefined)[]; servers?: ({ description?: string; url?: string; variables?: {[key: string]: … | …; }; } | undefined)[]; summary?: string; tags?: (string | undefined)[]; } | {[key: string]: any; [key: number]: any; callbacks?: {[key: string]: {[key: string]: any; [key: number]: any; description?: string; summary?: string; } | {[key: string]: {[key: string]: any; [key: number]: any; description?: … | …; summary?: … | …; } | {[key: string]: any; [key: number]: any; delete?: … | …; get?: … | …; head?: … | …; options?: … | …; parameters?: … | …; patch?: … | …; post?: … | …; put?: … | …; servers?: … | …; trace?: … | …; } | undefined; } | undefined; }; parameters?: ({ allowEmptyValue?: boolean; allowReserved?: boolean; content?: {[key: string]: … | …; }; deprecated?: boolean; description?: string; example?: any; examples?: {[key: string]: … | … | …; }; explode?: boolean; in?: ParameterLocation; name?: string; required?: boolean; schema?: {[key: `x-${(...)}`]: any; [key: string]: any; $ref?: … | …; } | {[key: `x-${(...)}`]: any; [key: string]: any; additionalProperties?: … | … | … | … | … | …; allOf?: … | …; anyOf?: … | …; default?: any; deprecated?: … | … | …; description?: … | …; discriminator?: … | …; enum?: … | …; example?: any; exclusiveMaximum?: … | … | …; exclusiveMinimum?: … | … | …; externalDocs?: … | …; format?: … | …; items?: { [x: `x-${string}`]: any; [x: string]: any; $ref?: string | undefined; } | { [x: `x-${string}`]: any; [x: string]: any; type?: “array” | undefined; items?: { [x: `x-${string}`]: any; [x: string]: any; $ref?: string | undefined; } | … | { …; } | undefined; … 33 more …; deprecated?: boolean | undefined; } | {…; maximum?: … | …; maxItems?: … | …; maxLength?: … | …; maxProperties?: … | …; minimum?: … | …; minItems?: … | …; minLength?: … | …; minProperties?: … | …; multipleOf?: … | …; not?: { [x: `x-${string}`]: any; [x: string]: any; $ref?: string | undefined; } | { [x: `x-${string}`]: any; [x: string]: any; type?: “array” | undefined; items?: { [x: `x-${string}`]: any; [x: string]: any; $ref?: string | undefined; } | … | { …; } | undefined; … 33 more …; deprecated?: boolean | undefined; } | {…; nullable?: … | … | …; oneOf?: … | …; pattern?: … | …; patternProperties?: … | …; properties?: … | …; readOnly?: … | … | …; required?: … | …; title?: … | …; type?: … | …; uniqueItems?: … | … | …; writeOnly?: … | … | …; xml?: … | …; } | {[key: `x-${(...)}`]: any; [key: string]: any; additionalProperties?: … | … | … | … | … | …; allOf?: … | …; anyOf?: … | …; default?: any; deprecated?: … | … | …; description?: … | …; discriminator?: … | …; enum?: … | …; example?: any; exclusiveMaximum?: … | … | …; exclusiveMinimum?: … | … | …; externalDocs?: … | …; format?: … | …; maximum?: … | …; maxItems?: … | …; maxLength?: … | …; maxProperties?: … | …; minimum?: … | …; minItems?: … | …; minLength?: … | …; minProperties?: … | …; multipleOf?: … | …; not?: { [x: `x-${string}`]: any; [x: string]: any; $ref?: string | undefined; } | { [x: `x-${string}`]: any; [x: string]: any; type?: “array” | undefined; items?: { [x: `x-${string}`]: any; [x: string]: any; $ref?: string | undefined; } | … | { …; } | undefined; … 33 more …; deprecated?: boolean | undefined; } | {…; nullable?: … | … | …; oneOf?: … | …; pattern?: … | …; patternProperties?: … | …; properties?: … | …; readOnly?: … | … | …; required?: … | …; title?: … | …; type?: … | …; uniqueItems?: … | … | …; writeOnly?: … | … | …; xml?: … | …; }; style?: ParameterStyle; } | {[key: string]: any; [key: number]: any; description?: string; summary?: string; } | undefined)[]; requestBody?: {[key: string]: any; [key: number]: any; description?: string; summary?: string; } | { content?: {[key: string]: { encoding?: … | …; example?: any; examples?: … | …; schema?: … | … | … | … | … | … | …; } | undefined; }; description?: string; required?: boolean; }; responses?: {[key: string]: {[key: string]: any; [key: number]: any; description?: string; summary?: string; } | {[key: string]: any; [key: number]: any; content?: {[key: string]: … | …; }; headers?: {[key: string]: … | … | …; }; links?: {[key: string]: … | … | …; }; } | undefined; }; servers?: ({ description?: string; url?: string; variables?: {[key: string]: … | …; }; } | undefined)[]; } | {[key: string]: any; [key: number]: any; callbacks?: {[key: string]: {[key: string]: any; [key: number]: any; description?: string; summary?: string; } | {[key: string]: {[key: string]: any; [key: number]: any; description?: … | …; summary?: … | …; } | {[key: string]: any; [key: number]: any; additionalOperations?: … | …; delete?: … | …; get?: … | …; head?: … | …; options?: … | …; parameters?: … | …; patch?: … | …; post?: … | …; put?: … | …; query?: … | …; trace?: … | …; } | undefined; } | undefined; }; parameters?: ({[key: string]: any; [key: number]: any; description?: string; summary?: string; } | { allowEmptyValue?: boolean; allowReserved?: boolean; content?: {[key: string]: … | …; }; deprecated?: boolean; description?: string; example?: any; examples?: {[key: string]: … | … | …; }; explode?: boolean; in?: ParameterLocation; name?: string; required?: boolean; schema?: {[key: string]: any; [key: number]: any; description?: … | …; summary?: … | …; } | {[key: `x-${(...)}`]: any; [key: string]: any; valueOf?: … | …; } | {[key: `x-${(...)}`]: any; [key: string]: any; valueOf?: … | …; } | {[key: `x-${(...)}`]: any; [key: string]: any; $schema?: … | …; additionalProperties?: … | … | … | … | … | … | … | … | …; allOf?: … | …; anyOf?: … | …; const?: any; contentMediaType?: … | …; default?: any; deprecated?: … | … | …; description?: … | …; discriminator?: … | …; enum?: … | …; example?: any; examples?: … | …; exclusiveMaximum?: … | …; exclusiveMinimum?: … | …; externalDocs?: … | …; format?: … | …; items?: { [x: string]: any; [x: number]: any; summary?: string | undefined; description?: string | undefined; } | { [x: `x-${string}`]: any; [x: string]: any; valueOf?: (() => boolean) | undefined; } | { [x: `x-${string}`]: any; [x: string]: any; valueOf?: (() => boolean) | undefined; } | { …; } | { …; } | { …; } | un…; maximum?: … | …; maxItems?: … | …; maxLength?: … | …; maxProperties?: … | …; minimum?: … | …; minItems?: … | …; minLength?: … | …; minProperties?: … | …; multipleOf?: … | …; not?: … | … | … | … | … | … | …; oneOf?: … | …; pattern?: … | …; patternProperties?: … | …; properties?: … | …; readOnly?: … | … | …; required?: … | …; title?: … | …; type?: … | …; uniqueItems?: … | … | …; writeOnly?: … | … | …; xml?: … | …; } | {[key: `x-${(...)}`]: any; [key: string]: any; $schema?: … | …; additionalProperties?: … | … | … | … | … | … | … | … | …; allOf?: … | …; anyOf?: … | …; const?: any; contentMediaType?: … | …; default?: any; deprecated?: … | … | …; description?: … | …; discriminator?: … | …; enum?: … | …; example?: any; examples?: … | …; exclusiveMaximum?: … | …; exclusiveMinimum?: … | …; externalDocs?: … | …; format?: … | …; maximum?: … | …; maxItems?: … | …; maxLength?: … | …; maxProperties?: … | …; minimum?: … | …; minItems?: … | …; minLength?: … | …; minProperties?: … | …; multipleOf?: … | …; not?: … | … | … | … | … | … | …; oneOf?: … | …; pattern?: … | …; patternProperties?: … | …; properties?: … | …; readOnly?: … | … | …; required?: … | …; title?: … | …; type?: … | …; uniqueItems?: … | … | …; writeOnly?: … | … | …; xml?: … | …; } | {[key: `x-${(...)}`]: any; [key: string]: any; $schema?: … | …; additionalProperties?: … | … | … | … | … | … | … | … | …; allOf?: … | …; anyOf?: … | …; const?: any; contentMediaType?: … | …; default?: any; deprecated?: … | … | …; description?: … | …; discriminator?: … | …; enum?: … | …; example?: any; examples?: … | …; exclusiveMaximum?: … | …; exclusiveMinimum?: … | …; externalDocs?: … | …; format?: … | …; items?: { [x: string]: any; [x: number]: any; summary?: string | undefined; description?: string | undefined; } | { [x: `x-${string}`]: any; [x: string]: any; valueOf?: (() => boolean) | undefined; } | { [x: `x-${string}`]: any; [x: string]: any; valueOf?: (() => boolean) | undefined; } | { …; } | { …; } | { …; } | un…; maximum?: … | …; maxItems?: … | …; maxLength?: … | …; maxProperties?: … | …; minimum?: … | …; minItems?: … | …; minLength?: … | …; minProperties?: … | …; multipleOf?: … | …; not?: … | … | … | … | … | … | …; oneOf?: … | …; pattern?: … | …; patternProperties?: … | …; properties?: … | …; readOnly?: … | … | …; required?: … | …; title?: … | …; type?: … | …; uniqueItems?: … | … | …; writeOnly?: … | … | …; xml?: … | …; }; style?: ParameterStyle; } | undefined)[]; requestBody?: {[key: string]: any; [key: number]: any; description?: string; summary?: string; } | { content?: {[key: string]: {[key: string]: any; [key: number]: any; description?: … | …; summary?: … | …; } | { encoding?: … | …; example?: any; examples?: … | …; itemEncoding?: … | …; itemSchema?: … | … | … | … | … | … | …; prefixEncoding?: … | …; schema?: … | … | … | … | … | … | …; } | undefined; }; description?: string; required?: boolean; }; responses?: {[key: string]: {[key: string]: any; [key: number]: any; description?: string; summary?: string; } | {[key: string]: any; [key: number]: any; content?: {[key: string]: … | … | …; }; headers?: {[key: string]: … | … | …; }; links?: {[key: string]: … | … | …; }; summary?: string; } | undefined; }; servers?: ({ description?: string; name?: string; url?: string; variables?: {[key: string]: … | …; }; } | undefined)[]; }

optional renderer: JSXRenderer

Custom renderer for this route.

optional requestTimeout: number

Timeout for this specific route (milliseconds).

ShokupanRouter.config


mcpProtocol: McpProtocol

Defined in: src/router.ts:150

ShokupanRouter.mcpProtocol


optional metadata: RouteMetadata

Defined in: src/router.ts:148

ShokupanRouter.metadata


middleware: Middleware[] = []

Defined in: src/router.ts:133

ShokupanRouter.middleware


optional requestTimeout: number

Defined in: src/router.ts:126

ShokupanRouter.requestTimeout

get hasAfterValidateHook(): boolean

Defined in: src/router.ts:124

boolean

ShokupanRouter.hasAfterValidateHook


get hasBeforeValidateHook(): boolean

Defined in: src/router.ts:123

boolean

ShokupanRouter.hasBeforeValidateHook


get hasOnErrorHook(): boolean

Defined in: src/router.ts:119

boolean

ShokupanRouter.hasOnErrorHook


get hasOnReadTimeoutHook(): boolean

Defined in: src/router.ts:121

boolean

ShokupanRouter.hasOnReadTimeoutHook


get hasOnRequestEndHook(): boolean

Defined in: src/router.ts:117

boolean

ShokupanRouter.hasOnRequestEndHook


get hasOnRequestStartHook(): boolean

Defined in: src/router.ts:116

boolean

ShokupanRouter.hasOnRequestStartHook


get hasOnRequestTimeoutHook(): boolean

Defined in: src/router.ts:120

boolean

ShokupanRouter.hasOnRequestTimeoutHook


get hasOnResponseEndHook(): boolean

Defined in: src/router.ts:115

boolean

ShokupanRouter.hasOnResponseEndHook


get hasOnResponseStartHook(): boolean

Defined in: src/router.ts:118

boolean

ShokupanRouter.hasOnResponseStartHook


get hasOnStopHook(): boolean

Defined in: src/router.ts:114

boolean

ShokupanRouter.hasOnStopHook


get hasOnWriteTimeoutHook(): boolean

Defined in: src/router.ts:122

boolean

ShokupanRouter.hasOnWriteTimeoutHook


get logger(): Logger | undefined

Defined in: src/router.ts:142

Logger | undefined

ShokupanRouter.logger


get registry(): object

Defined in: src/router.ts:208

object

controllers: object[]

events: object[]

metadata: RouteMetadata | undefined

middleware: object[]

routers: object[]

routes: object[]

ShokupanRouter.registry


get root(): Shokupan<any>

Defined in: src/router.ts:138

Shokupan<any>

ShokupanRouter.root


get rootConfig(): Partial<{ adapter?: ServerAdapter | "bun" | "node" | "wintercg"; aiPlugin?: { api?: { is_user_authenticated?: boolean; type: "openapi"; url?: string; }; auth?: {[key: string]: any; type: "none" | "service_http" | "user_http" | "oauth"; }; contact_email?: string; description_for_human?: string; description_for_model?: string; enabled?: boolean; legal_info_url?: string; logo_url?: string; name_for_human?: string; name_for_model?: string; }; allowChunkedBody?: boolean; allowedStaticFilePaths?: string[]; apiCatalog?: { enabled?: boolean; versions?: object[]; }; astAnalysisTimeout?: number; astFilePath?: string; autoBackpressureFeedback?: boolean; autoBackpressureLevel?: number; blockOnAsyncApiGen: boolean; blockOnOpenApiGen: boolean; datastore?: { adapter: "surreal" | "sqlite" | "level"; options?: any; }; defaultResponseTransformer?: string; defaultSecurityHeaders?: any; development: boolean; disableBodyParsing?: boolean; enableAbortController?: boolean; enableAsyncApiGen: boolean; enableAsyncAstScanning?: boolean; enableAsyncLocalStorage: boolean; enableAutoContentNegotiation?: boolean; enableHTTPBridge?: boolean; enableMiddlewareTracking: boolean; enableOpenApiGen: boolean; enablePromiseMonkeypatch: boolean; enableTracing?: boolean; enableWebSocketTracking?: boolean; fileAccessCheck?: (ctx, path) => boolean; fileSystem?: FileSystemAdapter; hooks: ShokupanHooks<Record<string, any>> | ShokupanHooks<Record<string, any>>[]; hostname: string; httpLogger: (ctx) => void; ide?: string; idGenerator?: () => string; jsonParser?: "native" | "parse-json" | "secure-json-parse"; logger: Logger; maxBodySize?: number; middlewareTrackingMaxCapacity?: number; middlewareTrackingTTL?: number; port: number; queryParserMode?: "strict" | "extended" | "simple"; readTimeout: number; renderer: JSXRenderer; requestTimeout: number; reusePort: boolean; tls: {[key: string]: any; cert: string; key: string; }; validateStatusCodes: boolean; websocketErrorHandler?: (err, ctx) => void | Promise<void>; writeTimeout: number; }>

Defined in: src/router.ts:135

Partial<{ adapter?: ServerAdapter | "bun" | "node" | "wintercg"; aiPlugin?: { api?: { is_user_authenticated?: boolean; type: "openapi"; url?: string; }; auth?: {[key: string]: any; type: "none" | "service_http" | "user_http" | "oauth"; }; contact_email?: string; description_for_human?: string; description_for_model?: string; enabled?: boolean; legal_info_url?: string; logo_url?: string; name_for_human?: string; name_for_model?: string; }; allowChunkedBody?: boolean; allowedStaticFilePaths?: string[]; apiCatalog?: { enabled?: boolean; versions?: object[]; }; astAnalysisTimeout?: number; astFilePath?: string; autoBackpressureFeedback?: boolean; autoBackpressureLevel?: number; blockOnAsyncApiGen: boolean; blockOnOpenApiGen: boolean; datastore?: { adapter: "surreal" | "sqlite" | "level"; options?: any; }; defaultResponseTransformer?: string; defaultSecurityHeaders?: any; development: boolean; disableBodyParsing?: boolean; enableAbortController?: boolean; enableAsyncApiGen: boolean; enableAsyncAstScanning?: boolean; enableAsyncLocalStorage: boolean; enableAutoContentNegotiation?: boolean; enableHTTPBridge?: boolean; enableMiddlewareTracking: boolean; enableOpenApiGen: boolean; enablePromiseMonkeypatch: boolean; enableTracing?: boolean; enableWebSocketTracking?: boolean; fileAccessCheck?: (ctx, path) => boolean; fileSystem?: FileSystemAdapter; hooks: ShokupanHooks<Record<string, any>> | ShokupanHooks<Record<string, any>>[]; hostname: string; httpLogger: (ctx) => void; ide?: string; idGenerator?: () => string; jsonParser?: "native" | "parse-json" | "secure-json-parse"; logger: Logger; maxBodySize?: number; middlewareTrackingMaxCapacity?: number; middlewareTrackingTTL?: number; port: number; queryParserMode?: "strict" | "extended" | "simple"; readTimeout: number; renderer: JSXRenderer; requestTimeout: number; reusePort: boolean; tls: {[key: string]: any; cert: string; key: string; }; validateStatusCodes: boolean; websocketErrorHandler?: (err, ctx) => void | Promise<void>; writeTimeout: number; }>

ShokupanRouter.rootConfig

add(arg): PermissionPlugin

Defined in: src/router.ts:1160

Adds a route to the router.

Route configuration object

any

Controller for the route

string

Group for the route

ShokupanHandler<any>

Route handler function

{ file: string; line: number; }

string

number

Method

HTTP method

Middleware[]

string

URL path

RegExp

Custom regex for path matching

JSXRenderer

JSX renderer for the route

number

Timeout for this route in milliseconds

MethodAPISpec

OpenAPI specification for the route

PermissionPlugin

ShokupanRouter.add


addCustomResolver(key, resolver): void

Defined in: src/plugins/application/permissions.ts:132

string

PermissionResolver

void


addRole(role): void

Defined in: src/plugins/application/permissions.ts:120

Role

void


bindController(controller): void

Defined in: src/router.ts:402

Registers a controller instance to the router.

any

void

ShokupanRouter.bindController


checkPermission(user, check, ctx): Promise<boolean>

Defined in: src/plugins/application/permissions.ts:240

any

PermissionCheck

ShokupanContext

Promise<boolean>


delete<Path>(path, handler, …handlers): this

Defined in: src/router.ts:1368

Adds a DELETE route to the router.

Path extends string

Path

URL path

ShokupanHandler<any, RouteParams<Path>>

ShokupanHandler<any, RouteParams<Path>>[]

Route handler functions

this

ShokupanRouter.delete

delete<Path>(path, spec, handler, …handlers): this

Defined in: src/router.ts:1376

Adds a DELETE route to the router.

Path extends string

Path

URL path

MethodAPISpec

OpenAPI specification for the route

ShokupanHandler<any, RouteParams<Path>>

ShokupanHandler<any, RouteParams<Path>>[]

Route handler functions

this

ShokupanRouter.delete


find(method, path): { handler: ShokupanHandler<any>; params: Record<string, string>; route?: any; } | null

Defined in: src/router.ts:1065

Find a route matching the given method and path. Wraps handler with router middleware if present.

string

HTTP method

string

Request path

{ handler: ShokupanHandler<any>; params: Record<string, string>; route?: any; } | null

Route handler and parameters if found, otherwise null

ShokupanRouter.find


findEvent(name): ShokupanHandler<any>[] | null

Defined in: src/router.ts:383

Finds an event handler(s) by name.

string

ShokupanHandler<any>[] | null

ShokupanRouter.findEvent


generateApiSpec(options): Promise<any>

Defined in: src/router.ts:1652

Generates an OpenAPI 3.1 Document by recursing through the router and its descendants. Now includes runtime analysis of handler functions to infer request/response types.

OpenAPIOptions = {}

Promise<any>

ShokupanRouter.generateApiSpec


get<Path>(path, handler, …handlers): this

Defined in: src/router.ts:1308

Adds a GET route to the router.

Path extends string

Path

URL path

ShokupanHandler<any, RouteParams<Path>>

ShokupanHandler<any, RouteParams<Path>>[]

Route handler functions

this

ShokupanRouter.get

get<Path>(path, spec, handler, …handlers): this

Defined in: src/router.ts:1316

Adds a GET route to the router.

Path extends string

Path

URL path

MethodAPISpec

OpenAPI specification for the route

ShokupanHandler<any, RouteParams<Path>>

ShokupanHandler<any, RouteParams<Path>>[]

Route handler functions

this

ShokupanRouter.get


getEventHandlers(): Map<string, ShokupanHandler<any>[]>

Defined in: src/router.ts:409

Returns all registered event handlers.

Map<string, ShokupanHandler<any>[]>

ShokupanRouter.getEventHandlers


getRole(roleName): Role | undefined

Defined in: src/plugins/application/permissions.ts:128

string

Role | undefined


getRoutes(): object[]

Defined in: src/router.ts:801

Returns all routes attached to this router and its descendants.

object[]

ShokupanRouter.getRoutes


guard(handler): void

Defined in: src/router.ts:1509

Adds a guard to the router that applies to all routes added after this point. Guards must return true or call ctx.next() to allow the request to continue.

ShokupanHandler<any>

Guard handler function

void

ShokupanRouter.guard

guard(spec, handler): void

Defined in: src/router.ts:1517

Adds a guard to the router that applies to all routes added after this point. Guards must return true or call ctx.next() to allow the request to continue.

GuardAPISpec

OpenAPI specification for the guard

ShokupanHandler<any>

Guard handler function

void

ShokupanRouter.guard


hasHooks(name): boolean

Defined in: src/router.ts:1657

keyof ShokupanHooks<any>

boolean

ShokupanRouter.hasHooks


head<Path>(path, handler, …handlers): this

Defined in: src/router.ts:1428

Adds a HEAD route to the router.

Path extends string

Path

URL path

ShokupanHandler<any, RouteParams<Path>>

ShokupanHandler<any, RouteParams<Path>>[]

Route handler functions

this

ShokupanRouter.head

head<Path>(path, spec, handler, …handlers): this

Defined in: src/router.ts:1436

Adds a HEAD route to the router.

Path extends string

Path

URL path

MethodAPISpec

OpenAPI specification for the route

ShokupanHandler<any, RouteParams<Path>>

ShokupanHandler<any, RouteParams<Path>>[]

Route handler functions

this

ShokupanRouter.head


hook(name, handler): PermissionPlugin

Defined in: src/router.ts:317

Registers a lifecycle hook dynamically.

keyof ShokupanHooks<any>

Function

PermissionPlugin

ShokupanRouter.hook


internalRequest(arg): Promise<Response | undefined>

Defined in: src/router.ts:833

Makes an internal request through this router’s full routing pipeline. This is useful for calling other routes internally and supports streaming responses.

string | { body?: any; headers?: HeadersInit; method?: Method; path: string; }

Promise<Response | undefined>

The raw Response object.

ShokupanRouter.internalRequest


mount(prefix, controller): PermissionPlugin

Defined in: src/router.ts:423

Mounts a controller instance or WebSocket router to a path prefix.

Controller can be a convention router, WebSocket router, or an arbitrary class.

Routes are derived from method names:

  • get(ctx) -> GET /prefix/
  • getUsers(ctx) -> GET /prefix/users
  • postCreate(ctx) -> POST /prefix/create

string

Record<string, any> | ShokupanRouter<GlobalShokupanState> | ShokupanRouter<any> | ShokupanController | ShokupanController<any>

PermissionPlugin

ShokupanRouter.mount


onInit(app, options?): Promise<void>

Defined in: src/plugins/application/permissions.ts:67

Shokupan

ShokupanPluginOptions

Promise<void>

ShokupanPlugin.onInit


options<Path>(path, handler, …handlers): this

Defined in: src/router.ts:1408

Adds a OPTIONS route to the router.

Path extends string

Path

URL path

ShokupanHandler<any, RouteParams<Path>>

ShokupanHandler<any, RouteParams<Path>>[]

Route handler functions

this

ShokupanRouter.options

options<Path>(path, spec, handler, …handlers): this

Defined in: src/router.ts:1416

Adds a OPTIONS route to the router.

Path extends string

Path

URL path

MethodAPISpec

OpenAPI specification for the route

ShokupanHandler<any, RouteParams<Path>>

ShokupanHandler<any, RouteParams<Path>>[]

Route handler functions

this

ShokupanRouter.options


patch<Path>(path, handler, …handlers): this

Defined in: src/router.ts:1388

Adds a PATCH route to the router.

Path extends string

Path

URL path

ShokupanHandler<any, RouteParams<Path>>

ShokupanHandler<any, RouteParams<Path>>[]

Route handler functions

this

ShokupanRouter.patch

patch<Path>(path, spec, handler, …handlers): this

Defined in: src/router.ts:1396

Adds a PATCH route to the router.

Path extends string

Path

URL path

MethodAPISpec

OpenAPI specification for the route

ShokupanHandler<any, RouteParams<Path>>

ShokupanHandler<any, RouteParams<Path>>[]

Route handler functions

this

ShokupanRouter.patch


post<Path>(path, handler, …handlers): this

Defined in: src/router.ts:1328

Adds a POST route to the router.

Path extends string

Path

URL path

ShokupanHandler<any, RouteParams<Path>>

ShokupanHandler<any, RouteParams<Path>>[]

Route handler functions

this

ShokupanRouter.post

post<Path>(path, spec, handler, …handlers): this

Defined in: src/router.ts:1336

Adds a POST route to the router.

Path extends string

Path

URL path

MethodAPISpec

OpenAPI specification for the route

ShokupanHandler<any, RouteParams<Path>>

ShokupanHandler<any, RouteParams<Path>>[]

Route handler functions

this

ShokupanRouter.post


prompt(name, args, handler): PermissionPlugin

Defined in: src/router.ts:359

Registers an MCP Prompt.

string

object[] | undefined

Function

PermissionPlugin

ShokupanRouter.prompt


put<Path>(path, handler, …handlers): this

Defined in: src/router.ts:1348

Adds a PUT route to the router.

Path extends string

Path

URL path

ShokupanHandler<any, RouteParams<Path>>

ShokupanHandler<any, RouteParams<Path>>[]

Route handler functions

this

ShokupanRouter.put

put<Path>(path, spec, handler, …handlers): this

Defined in: src/router.ts:1356

Adds a PUT route to the router.

Path extends string

Path

URL path

MethodAPISpec

OpenAPI specification for the route

ShokupanHandler<any, RouteParams<Path>>

ShokupanHandler<any, RouteParams<Path>>[]

Route handler functions

this

ShokupanRouter.put


removeRole(roleName): void

Defined in: src/plugins/application/permissions.ts:124

string

void


requireAllPermissions(…checks): (ctx, next) => Promise<any>

Defined in: src/plugins/application/permissions.ts:368

PermissionCheck[]

(ctx, next): Promise<any>

ShokupanContext

() => Promise<any>

Promise<any>


requireAnyPermission(…checks): (ctx, next) => Promise<any>

Defined in: src/plugins/application/permissions.ts:339

PermissionCheck[]

(ctx, next): Promise<any>

ShokupanContext

() => Promise<any>

Promise<any>


requirePermission(resource, action, context?): (ctx, next) => Promise<any>

Defined in: src/plugins/application/permissions.ts:276

string

string

Record<string, any>

(ctx, next): Promise<any>

ShokupanContext

() => Promise<any>

Promise<any>


requireRole(…roleNames): (ctx, next) => Promise<any>

Defined in: src/plugins/application/permissions.ts:304

string[]

(ctx, next): Promise<any>

ShokupanContext

() => Promise<any>

Promise<any>


resource(uri, options, handler): PermissionPlugin

Defined in: src/router.ts:371

Registers an MCP Resource.

string

string

string

string

Function

PermissionPlugin

ShokupanRouter.resource


runHooks(name, …args): void | Promise<void[]>

Defined in: src/router.ts:1708

keyof ShokupanHooks<any>

any[]

void | Promise<void[]>

ShokupanRouter.runHooks


runOnStopHooks(app): Promise<void>

Defined in: src/router.ts:1749

Shokupan<any>

Promise<void>

ShokupanRouter.runOnStopHooks


socket<Path>(path, handler): this

Defined in: src/router.ts:1469

Adds a WebSocket route that handles its own upgrade logic.

Unless you need to handle the upgrade manually, you should use a ShokupanWebsocketRouter or WebsocketController instead.

Routes registered with .socket() will NOT be automatically upgraded by Shokupan’s WebSocket handling. You must implement all event handlers manually. You have been warned.

Path extends string

Path

URL path for the WebSocket endpoint

ShokupanHandler<any, RouteParams<Path>>

Route handler that will manually handle the upgrade

this

router.socket("/ws", (ctx) => {
const success = ctx.upgrade({
data: {
handler: {
open: (ws) => console.log("Connected"),
message: (ws, msg) => ws.send(msg),
close: (ws) => console.log("Disconnected")
}
}
});
if (!success) return ctx.text("Upgrade failed", 400);
});

ShokupanRouter.socket


static(uriPath, options): PermissionPlugin

Defined in: src/router.ts:1562

Statically serves a directory with standard options.

string

URL path prefix

Configuration options or root directory string

string | StaticServeOptions<any>

PermissionPlugin

ShokupanRouter.static


testRequest(options): Promise<ProcessResult>

Defined in: src/router.ts:865

Processes a request for testing purposes. Returns a simplified { status, headers, data } object instead of a Response.

RequestOptions

Promise<ProcessResult>

ShokupanRouter.testRequest


tool(name, schema, handler): PermissionPlugin

Defined in: src/router.ts:347

Registers an MCP Tool.

string

any

Function

PermissionPlugin

ShokupanRouter.tool


use(middleware): this

Defined in: src/router.ts:163

Registers middleware for this router. Middleware will run for all routes matched by this router.

Supports Express-style path-based middleware: use('/admin', middleware) runs only for routes under /admin.

Middleware | ShokupanHandler<any>

this

ShokupanRouter.use

use(path, middleware): this

Defined in: src/router.ts:164

Registers middleware for this router. Middleware will run for all routes matched by this router.

Supports Express-style path-based middleware: use('/admin', middleware) runs only for routes under /admin.

string

Middleware | ShokupanHandler<any>

this

ShokupanRouter.use