import Boom from '@hapi/boom' ; import { Transform } from 'stream' ; export function createLimitStream ( limit ) { let counter = 0 ; return new Transform ( { objectMode : true , async transform ( obj , enc , done ) { if ( counter >= limit ) { return done ( Boom . badRequest ( `Can't import more than ${ limit } objects` ) ) ; } counter ++ ; done ( undefined , obj ) ; } , } ) ; }