platform/server/middleware/src/connectionMgr.ts
Denis Bykhov 34d1b2bdd1
Connection mgr (#7031)
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
Co-authored-by: Andrey Sobolev <haiodo@gmail.com>
2024-10-25 01:17:46 +07:00

33 lines
883 B
TypeScript

import { generateId, type MeasureContext, type Tx } from '@hcengineering/core'
import {
BaseMiddleware,
type Middleware,
type PipelineContext,
type TxMiddlewareResult
} from '@hcengineering/server-core'
/**
* Will support apply tx
* @public
*/
export class ConnectionMgrMiddleware extends BaseMiddleware implements Middleware {
static async create (
ctx: MeasureContext,
context: PipelineContext,
next?: Middleware
): Promise<Middleware | undefined> {
return new ConnectionMgrMiddleware(context, next)
}
async tx (ctx: MeasureContext, tx: Tx[]): Promise<TxMiddlewareResult> {
if (ctx.id === undefined) {
ctx.id = generateId()
}
const result = await this.provideTx(ctx, tx)
this.context.endContext = async (_ctx: MeasureContext) => {
await this.context.adapterManager?.closeContext?.(ctx)
}
return result
}
}