Function: defineMiddleware()
Function: defineMiddleware()
Defines middleware (function, factory, or class) for the Stone.js kernel.
This utility injects middleware metadata into the stone.kernel.middleware
blueprint field. It supports functional, factory, and class-based middleware.
Param
The middleware implementation (function, factory, or class).
Param
Optional middleware options and factory indicator.
Example
defineMiddleware((event, next) => next(event))
Call Signature
function defineMiddleware<U, V>(module, options?): Partial<StoneBlueprint<U, V>>;
Defines a function-based middleware.
Type Parameters
U
U
extends IncomingEvent
= IncomingEvent
V
V
extends OutgoingResponse
= OutgoingResponse
Parameters
module
FunctionalMiddleware
<U
, V
>
The middleware function to be registered.
options?
MiddlewareOptions
& object
Optional middleware options.
Returns
Partial
<StoneBlueprint
<U
, V
>>
A partial StoneBlueprint with the middleware metadata.
Param
The middleware implementation (function, factory, or class).
Param
Optional middleware options and factory indicator.
Example
defineMiddleware((event, next) => next(event))
Call Signature
function defineMiddleware<U, V>(module, options): Partial<StoneBlueprint<U, V>>;
Defines a factory-based middleware.
Type Parameters
U
U
extends IncomingEvent
= IncomingEvent
V
V
extends OutgoingResponse
= OutgoingResponse
Parameters
module
FactoryMiddleware
<U
, V
>
A factory that returns the middleware function.
options
MiddlewareOptions
& object
Middleware options including isFactory: true
.
Returns
Partial
<StoneBlueprint
<U
, V
>>
A partial StoneBlueprint with the middleware metadata.
Param
The middleware implementation (function, factory, or class).
Param
Optional middleware options and factory indicator.
Example
defineMiddleware((event, next) => next(event))
Call Signature
function defineMiddleware<U, V>(module, options): Partial<StoneBlueprint<U, V>>;
Defines a class-based middleware.
Type Parameters
U
U
extends IncomingEvent
= IncomingEvent
V
V
extends OutgoingResponse
= OutgoingResponse
Parameters
module
MiddlewareClass
<U
, V
>
A class-based middleware with a handle
method.
options
MiddlewareOptions
& object
Middleware options including isClass: true
.
Returns
Partial
<StoneBlueprint
<U
, V
>>
A partial StoneBlueprint with the middleware metadata.
Param
The middleware implementation (function, factory, or class).
Param
Optional middleware options and factory indicator.
Example
defineMiddleware((event, next) => next(event))