1
- import { getDefaultModelMeta } from '../loader' ;
2
1
import { withOmit , WithOmitOptions } from './omit' ;
3
2
import { withPassword , WithPasswordOptions } from './password' ;
4
3
import { withPolicy , WithPolicyContext , WithPolicyOptions } from './policy' ;
@@ -21,16 +20,15 @@ let hasOmit: boolean | undefined = undefined;
21
20
* @param context The context to for evaluating access policies.
22
21
* @param options Options.
23
22
*/
24
- export function enhance < DbClient extends object > (
23
+ export function createEnhancement < DbClient extends object > (
25
24
prisma : DbClient ,
26
- context ?: WithPolicyContext ,
27
- options ?: EnhancementOptions
25
+ options : EnhancementOptions ,
26
+ context ?: WithPolicyContext
28
27
) {
29
28
let result = prisma ;
30
29
31
30
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 ) ) ;
34
32
hasPassword = allFields . some ( ( field ) => field . attributes ?. some ( ( attr ) => attr . name === '@password' ) ) ;
35
33
hasOmit = allFields . some ( ( field ) => field . attributes ?. some ( ( attr ) => attr . name === '@omit' ) ) ;
36
34
}
@@ -46,7 +44,7 @@ export function enhance<DbClient extends object>(
46
44
}
47
45
48
46
// policy proxy
49
- result = withPolicy ( result , context , options ) ;
47
+ result = withPolicy ( result , options , context ) ;
50
48
51
49
return result ;
52
50
}
0 commit comments