@@ -23,10 +23,10 @@ import {
2323 getAllAttributes ,
2424 getStringLiteral ,
2525 isAuthOrAuthMemberAccess ,
26+ isBeforeInvocation ,
2627 isCollectionPredicate ,
2728 isDataFieldReference ,
2829 isDelegateModel ,
29- isFutureExpr ,
3030 isRelationshipField ,
3131 mapBuiltinTypeToExpressionType ,
3232 resolved ,
@@ -166,13 +166,20 @@ export default class AttributeApplicationValidator implements AstValidator<Attri
166166 } ) ;
167167 return ;
168168 }
169- this . validatePolicyKinds ( kind , [ 'create' , 'read' , 'update' , 'delete' , 'all' ] , attr , accept ) ;
169+ this . validatePolicyKinds ( kind , [ 'create' , 'read' , 'update' , 'post-update' , ' delete', 'all' ] , attr , accept ) ;
170170
171171 if ( ( kind === 'create' || kind === 'all' ) && attr . args [ 1 ] ?. value ) {
172172 // "create" rules cannot access non-owned relations because the entity does not exist yet, so
173173 // there can't possibly be a fk that points to it
174174 this . rejectNonOwnedRelationInExpression ( attr . args [ 1 ] . value , accept ) ;
175175 }
176+
177+ if ( kind !== 'post-update' && attr . args [ 1 ] ?. value ) {
178+ const beforeCall = AstUtils . streamAst ( attr . args [ 1 ] ?. value ) . find ( isBeforeInvocation ) ;
179+ if ( beforeCall ) {
180+ accept ( 'error' , `"before()" is only allowed in "post-update" policy rules` , { node : beforeCall } ) ;
181+ }
182+ }
176183 }
177184
178185 private rejectNonOwnedRelationInExpression ( expr : Expression , accept : ValidationAcceptor ) {
@@ -251,8 +258,8 @@ export default class AttributeApplicationValidator implements AstValidator<Attri
251258 const kindItems = this . validatePolicyKinds ( kind , [ 'read' , 'update' , 'all' ] , attr , accept ) ;
252259
253260 const expr = attr . args [ 1 ] ?. value ;
254- if ( expr && AstUtils . streamAst ( expr ) . some ( ( node ) => isFutureExpr ( node ) ) ) {
255- accept ( 'error' , `"future ()" is not allowed in field-level policy rules` , { node : expr } ) ;
261+ if ( expr && AstUtils . streamAst ( expr ) . some ( ( node ) => isBeforeInvocation ( node ) ) ) {
262+ accept ( 'error' , `"before ()" is not allowed in field-level policy rules` , { node : expr } ) ;
256263 }
257264
258265 // 'update' rules are not allowed for relation fields
0 commit comments