11/* eslint-disable @typescript-eslint/no-explicit-any */
22
33import deepmerge from 'deepmerge' ;
4- import traverse from 'traverse' ;
54import { z , type ZodError , type ZodObject , type ZodSchema } from 'zod' ;
65import { fromZodError } from 'zod-validation-error' ;
76import { CrudFailureReason , PrismaErrorCode } from '../../../constants' ;
@@ -15,7 +14,7 @@ import {
1514 type FieldInfo ,
1615 type ModelMeta ,
1716} from '../../../cross' ;
18- import { isPlainObject , lowerCaseFirst , upperCaseFirst } from '../../../local-helpers' ;
17+ import { isPlainObject , simpleTraverse , lowerCaseFirst , upperCaseFirst } from '../../../local-helpers' ;
1918import {
2019 AuthUser ,
2120 CrudContract ,
@@ -691,27 +690,24 @@ export class PolicyUtil extends QueryUtils {
691690 // here we prefix the constraint variables coming from delegated checkers
692691 // with the relation field name to avoid conflicts
693692 const prefixConstraintVariables = ( constraint : unknown , prefix : string ) => {
694- return traverse ( constraint ) . map ( function ( value ) {
693+ return simpleTraverse ( constraint , ( { value, update } ) => {
695694 if ( isVariableConstraint ( value ) ) {
696- this . update (
695+ update (
697696 {
698697 ...value ,
699698 name : `${ prefix } ${ value . name } ` ,
700- } ,
701- true
699+ }
702700 ) ;
703701 }
704702 } ) ;
705703 } ;
706704
707- // eslint-disable-next-line @typescript-eslint/no-this-alias
708- const that = this ;
709- result = traverse ( result ) . forEach ( function ( value ) {
705+ result = simpleTraverse ( result , ( { value, update } ) => {
710706 if ( isDelegateConstraint ( value ) ) {
711707 const { model : delegateModel , relation, operation : delegateOp } = value ;
712- let newValue = that . getCheckerConstraint ( delegateModel , delegateOp ?? operation ) ;
708+ let newValue = this . getCheckerConstraint ( delegateModel , delegateOp ?? operation ) ;
713709 newValue = prefixConstraintVariables ( newValue , `${ relation } .` ) ;
714- this . update ( newValue , true ) ;
710+ update ( newValue ) ;
715711 }
716712 } ) ;
717713
0 commit comments