本页还没有译文
本页 10 段还没译成Tiếng Việt,下面显示的是英文原文。createMiddleware
还没翻译译自英文(tanstack.com)本页 10 段都还没译
Function: createMiddleware()
function createMiddleware<TCtxIn>(): CreateMiddlewareBuilder<TCtxIn>;Defined in: packages/workflow-core/src/middleware/create-middleware.ts:46
Build a middleware that extends the workflow ctx. Type-level accumulation makes the extension visible to downstream middleware and the handler.
const traced = createMiddleware().server(async ({ ctx, next }) => {
const trace = startTrace(ctx.runId)
try {
return await next({ context: { trace } })
} finally {
trace.end()
}
})
For middleware that should compose on top of an already-extended ctx, type the generic explicitly:
createMiddleware<{ user: User }>().server(async ({ ctx, next }) => {
// ctx.user is typed
})
Type Parameters
TCtxIn
TCtxIn = unknown
Returns
CreateMiddlewareBuilder<TCtxIn>
AI 翻译查看英文原文