import type { Action } from './getPrismaClient' ; import type { Document } from './query' ; export type QueryMiddleware < T = unknown > = ( params : QueryMiddlewareParams , next : ( params : QueryMiddlewareParams ) => Promise < T > ) => Promise < T > ; export type QueryMiddlewareParams = { /** The model this is executed on */ model ? : string ; /** The action that is being handled */ action : Action ; /** TODO what is this */ dataPath : string [ ] ; /** TODO what is this */ runInTransaction : boolean ; /** TODO what is this */ args : any ; } ; export type EngineMiddleware < T = unknown > = ( params : EngineMiddlewareParams , next : ( params : EngineMiddlewareParams ) => Promise < { data : T ; elapsed : number ; } > ) => Promise < { data : T ; elapsed : number ; } > ; export type EngineMiddlewareParams = { document : Document ; runInTransaction ? : boolean ; } ; export type Namespace = 'all' | 'engine' ; class MiddlewareHandler < M extends Function > { private _middlewares : M [ ] = [ ] ; use ( middleware ) { this . _middlewares . push ( middleware ) ; } get ( id ) { return this . _middlewares [ id ] ; } has ( id ) { return ! ! this . _middlewares [ id ] ; } length ( ) { return this . _middlewares . length ; } } export class Middlewares { query = new MiddlewareHandler < QueryMiddleware > ( ) ; engine = new MiddlewareHandler < EngineMiddleware > ( ) ; }