import { IThrottler , ThrottlingError } from "@fluidframework/server-services-core" ; /**
 * Throttles if an id's count exceeds limit. Exposes tracked `throttleCounts` for easy assertions.
 */ export class TestThrottler implements IThrottler { public readonly throttleCounts : Map < string , number > = new Map < string , number > ( ) ; constructor ( private readonly limit ? ) { } public incrementCount ( id , weight = 1 ) { const currentCount = this . throttleCounts . get ( id ) || 0 ; this . checkThrottled ( currentCount ) ; const count = currentCount + weight ; this . throttleCounts . set ( id , count ) ; this . checkThrottled ( count ) ; } public decrementCount ( id , weight = 1 ) { const count = ( this . throttleCounts . get ( id ) || 0 ) - weight ; this . throttleCounts . set ( id , count ) ; } private checkThrottled ( count ) { if ( this . limit && count > this . limit ) { throw new ThrottlingError ( "throttled" , count - this . limit ) ; } } }