@@ -447,44 +447,106 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
447447
448448            // go through create items, statically check input to determine if post-create 
449449            // check is needed, and also validate zod schema 
450-             let  needPostCreateCheck  =  false ; 
451-             for  ( const  item  of  enumerate ( args . data ) )  { 
452-                 const  validationResult  =  this . validateCreateInputSchema ( this . model ,  item ) ; 
453-                 if  ( validationResult  !==  item )  { 
454-                     this . policyUtils . replace ( item ,  validationResult ) ; 
455-                 } 
456- 
457-                 const  inputCheck  =  this . policyUtils . checkInputGuard ( this . model ,  item ,  'create' ) ; 
458-                 if  ( inputCheck  ===  false )  { 
459-                     // unconditionally deny 
460-                     throw  this . policyUtils . deniedByPolicy ( 
461-                         this . model , 
462-                         'create' , 
463-                         undefined , 
464-                         CrudFailureReason . ACCESS_POLICY_VIOLATION 
465-                     ) ; 
466-                 }  else  if  ( inputCheck  ===  true )  { 
467-                     // unconditionally allow 
468-                 }  else  if  ( inputCheck  ===  undefined )  { 
469-                     // static policy check is not possible, need to do post-create check 
470-                     needPostCreateCheck  =  true ; 
471-                 } 
472-             } 
450+             const  needPostCreateCheck  =  this . validateCreateInput ( args ) ; 
473451
474452            if  ( ! needPostCreateCheck )  { 
453+                 // direct create 
475454                return  this . modelClient . createMany ( args ) ; 
476455            }  else  { 
477456                // create entities in a transaction with post-create checks 
478457                return  this . queryUtils . transaction ( this . prisma ,  async  ( tx )  =>  { 
479458                    const  {  result,  postWriteChecks }  =  await  this . doCreateMany ( this . model ,  args ,  tx ) ; 
480459                    // post-create check 
481460                    await  this . runPostWriteChecks ( postWriteChecks ,  tx ) ; 
482-                     return  result ; 
461+                     return  {   count :  result . length   } ; 
483462                } ) ; 
484463            } 
485464        } ) ; 
486465    } 
487466
467+     createManyAndReturn ( args : {  select : any ;  include : any ;  data : any ;  skipDuplicates ?: boolean  } )  { 
468+         if  ( ! args )  { 
469+             throw  prismaClientValidationError ( this . prisma ,  this . prismaModule ,  'query argument is required' ) ; 
470+         } 
471+         if  ( ! args . data )  { 
472+             throw  prismaClientValidationError ( 
473+                 this . prisma , 
474+                 this . prismaModule , 
475+                 'data field is required in query argument' 
476+             ) ; 
477+         } 
478+ 
479+         return  createDeferredPromise ( async  ( )  =>  { 
480+             this . policyUtils . tryReject ( this . prisma ,  this . model ,  'create' ) ; 
481+ 
482+             const  origArgs  =  args ; 
483+             args  =  clone ( args ) ; 
484+ 
485+             // go through create items, statically check input to determine if post-create 
486+             // check is needed, and also validate zod schema 
487+             const  needPostCreateCheck  =  this . validateCreateInput ( args ) ; 
488+ 
489+             let  result : {  result : unknown ;  error ?: Error  } [ ] ; 
490+ 
491+             if  ( ! needPostCreateCheck )  { 
492+                 // direct create 
493+                 const  created  =  await  this . modelClient . createManyAndReturn ( args ) ; 
494+ 
495+                 // process read-back 
496+                 result  =  await  Promise . all ( 
497+                     created . map ( ( item )  =>  this . policyUtils . readBack ( this . prisma ,  this . model ,  'create' ,  origArgs ,  item ) ) 
498+                 ) ; 
499+             }  else  { 
500+                 // create entities in a transaction with post-create checks 
501+                 result  =  await  this . queryUtils . transaction ( this . prisma ,  async  ( tx )  =>  { 
502+                     const  {  result : created ,  postWriteChecks }  =  await  this . doCreateMany ( this . model ,  args ,  tx ) ; 
503+                     // post-create check 
504+                     await  this . runPostWriteChecks ( postWriteChecks ,  tx ) ; 
505+ 
506+                     // process read-back 
507+                     return  Promise . all ( 
508+                         created . map ( ( item )  =>  this . policyUtils . readBack ( tx ,  this . model ,  'create' ,  origArgs ,  item ) ) 
509+                     ) ; 
510+                 } ) ; 
511+             } 
512+ 
513+             // throw read-back error if any of create result read-back fails 
514+             const  error  =  result . find ( ( r )  =>  ! ! r . error ) ?. error ; 
515+             if  ( error )  { 
516+                 throw  error ; 
517+             }  else  { 
518+                 return  result . map ( ( r )  =>  r . result ) ; 
519+             } 
520+         } ) ; 
521+     } 
522+ 
523+     private  validateCreateInput ( args : {  data : any ;  skipDuplicates ?: boolean  |  undefined  } )  { 
524+         let  needPostCreateCheck  =  false ; 
525+         for  ( const  item  of  enumerate ( args . data ) )  { 
526+             const  validationResult  =  this . validateCreateInputSchema ( this . model ,  item ) ; 
527+             if  ( validationResult  !==  item )  { 
528+                 this . policyUtils . replace ( item ,  validationResult ) ; 
529+             } 
530+ 
531+             const  inputCheck  =  this . policyUtils . checkInputGuard ( this . model ,  item ,  'create' ) ; 
532+             if  ( inputCheck  ===  false )  { 
533+                 // unconditionally deny 
534+                 throw  this . policyUtils . deniedByPolicy ( 
535+                     this . model , 
536+                     'create' , 
537+                     undefined , 
538+                     CrudFailureReason . ACCESS_POLICY_VIOLATION 
539+                 ) ; 
540+             }  else  if  ( inputCheck  ===  true )  { 
541+                 // unconditionally allow 
542+             }  else  if  ( inputCheck  ===  undefined )  { 
543+                 // static policy check is not possible, need to do post-create check 
544+                 needPostCreateCheck  =  true ; 
545+             } 
546+         } 
547+         return  needPostCreateCheck ; 
548+     } 
549+ 
488550    private  async  doCreateMany ( model : string ,  args : {  data : any ;  skipDuplicates ?: boolean  } ,  db : CrudContract )  { 
489551        // We can't call the native "createMany" because we can't get back what was created 
490552        // for post-create checks. Instead, do a "create" for each item and collect the results. 
@@ -511,7 +573,7 @@ export class PolicyProxyHandler<DbClient extends DbClientContract> implements Pr
511573        createResult  =  createResult . filter ( ( p )  =>  ! ! p ) ; 
512574
513575        return  { 
514-             result : {   count :  createResult . length   } , 
576+             result : createResult , 
515577            postWriteChecks : createResult . map ( ( item )  =>  ( { 
516578                model, 
517579                operation : 'create'  as  PolicyOperationKind , 
0 commit comments