11'use strict' ;
22
33const promiseOrCallback = require ( '../promiseOrCallback' ) ;
4- const { queryMiddlewareFunctions, aggregateMiddlewareFunctions } = require ( '../../constants' ) ;
4+ const { queryMiddlewareFunctions, aggregateMiddlewareFunctions, modelMiddlewareFunctions , documentMiddlewareFunctions } = require ( '../../constants' ) ;
55
66const middlewareFunctions = [
7- ...queryMiddlewareFunctions ,
8- ...aggregateMiddlewareFunctions
7+ ...[
8+ ...queryMiddlewareFunctions ,
9+ ...aggregateMiddlewareFunctions ,
10+ ...modelMiddlewareFunctions ,
11+ ...documentMiddlewareFunctions
12+ ] . reduce ( ( s , hook ) => s . add ( hook ) , new Set ( ) )
913] ;
1014
1115module . exports = function applyStaticHooks ( model , hooks , statics ) {
@@ -14,8 +18,11 @@ module.exports = function applyStaticHooks(model, hooks, statics) {
1418 numCallbackParams : 1
1519 } ;
1620
21+ model . $__insertMany = hooks . createWrapper ( 'insertMany' ,
22+ model . $__insertMany , model , kareemOptions ) ;
23+
1724 hooks = hooks . filter ( hook => {
18- // If the custom static overwrites an existing query/aggregate middleware, don't apply
25+ // If the custom static overwrites an existing middleware, don't apply
1926 // middleware to it by default. This avoids a potential backwards breaking
2027 // change with plugins like `mongoose-delete` that use statics to overwrite
2128 // built-in Mongoose functions.
@@ -25,9 +32,6 @@ module.exports = function applyStaticHooks(model, hooks, statics) {
2532 return hook . model !== false ;
2633 } ) ;
2734
28- model . $__insertMany = hooks . createWrapper ( 'insertMany' ,
29- model . $__insertMany , model , kareemOptions ) ;
30-
3135 for ( const key of Object . keys ( statics ) ) {
3236 if ( hooks . hasHooks ( key ) ) {
3337 const original = model [ key ] ;
0 commit comments