1- import { getDefaultModelMeta } from '../loader' ;
21import { withOmit , WithOmitOptions } from './omit' ;
32import { withPassword , WithPasswordOptions } from './password' ;
43import { withPolicy , WithPolicyContext , WithPolicyOptions } from './policy' ;
@@ -21,16 +20,15 @@ let hasOmit: boolean | undefined = undefined;
2120 * @param context The context to for evaluating access policies.
2221 * @param options Options.
2322 */
24- export function enhance < DbClient extends object > (
23+ export function createEnhancement < DbClient extends object > (
2524 prisma : DbClient ,
26- context ?: WithPolicyContext ,
27- options ?: EnhancementOptions
25+ options : EnhancementOptions ,
26+ context ?: WithPolicyContext
2827) {
2928 let result = prisma ;
3029
3130 if ( hasPassword === undefined || hasOmit === undefined ) {
32- const modelMeta = options ?. modelMeta ?? getDefaultModelMeta ( options ?. loadPath ) ;
33- const allFields = Object . values ( modelMeta . fields ) . flatMap ( ( modelInfo ) => Object . values ( modelInfo ) ) ;
31+ const allFields = Object . values ( options . modelMeta . fields ) . flatMap ( ( modelInfo ) => Object . values ( modelInfo ) ) ;
3432 hasPassword = allFields . some ( ( field ) => field . attributes ?. some ( ( attr ) => attr . name === '@password' ) ) ;
3533 hasOmit = allFields . some ( ( field ) => field . attributes ?. some ( ( attr ) => attr . name === '@omit' ) ) ;
3634 }
@@ -46,7 +44,7 @@ export function enhance<DbClient extends object>(
4644 }
4745
4846 // policy proxy
49- result = withPolicy ( result , context , options ) ;
47+ result = withPolicy ( result , options , context ) ;
5048
5149 return result ;
5250}
0 commit comments