@@ -55,8 +55,10 @@ import {
5555} from './ast' ;
5656import {
5757 getAllLoadedAndReachableDataModelsAndTypeDefs ,
58+ getAuthDecl ,
5859 getContainingDataModel ,
5960 getModelFieldsWithBases ,
61+ isAuthInvocation ,
6062 isFutureExpr ,
6163 isMemberContainer ,
6264 mapBuiltinTypeToExpressionType ,
@@ -360,23 +362,20 @@ export class ZModelLinker extends DefaultLinker {
360362 // eslint-disable-next-line @typescript-eslint/ban-types
361363 const funcDecl = node . function . ref as FunctionDecl ;
362364
363- // TODO: revisit this
364- // if (isAuthInvocation(node)) {
365- // // auth() function is resolved against all loaded and reachable documents
365+ if ( isAuthInvocation ( node ) ) {
366+ // auth() function is resolved against all loaded and reachable documents
366367
367- // // get all data models from loaded and reachable documents
368- // const allDecls = getAllLoadedAndReachableDataModelsAndTypeDefs(
369- // this.langiumDocuments(),
370- // AstUtils.getContainerOfType(node, isDataModel)
371- // );
372-
373- // const authDecl = getAuthDecl(allDecls);
374- // if (authDecl) {
375- // node.$resolvedType = { decl: authDecl, nullable: true };
376- // }
377- // } else
368+ // get all data models from loaded and reachable documents
369+ const allDecls = getAllLoadedAndReachableDataModelsAndTypeDefs (
370+ this . langiumDocuments ( ) ,
371+ AstUtils . getContainerOfType ( node , isDataModel )
372+ ) ;
378373
379- if ( isFutureExpr ( node ) ) {
374+ const authDecl = getAuthDecl ( allDecls ) ;
375+ if ( authDecl ) {
376+ node . $resolvedType = { decl : authDecl , nullable : true } ;
377+ }
378+ } else if ( isFutureExpr ( node ) ) {
380379 // future() function is resolved to current model
381380 node . $resolvedType = { decl : getContainingDataModel ( node ) } ;
382381 } else {
@@ -413,13 +412,11 @@ export class ZModelLinker extends DefaultLinker {
413412 // member access is resolved only in the context of the operand type
414413 if ( node . member . ref ) {
415414 this . resolveToDeclaredType ( node , node . member . ref . type ) ;
416-
417- // TODO: revisit this
418- // if (node.$resolvedType && isAuthInvocation(node.operand)) {
419- // // member access on auth() function is nullable
420- // // because user may not have provided all fields
421- // node.$resolvedType.nullable = true;
422- // }
415+ if ( node . $resolvedType && isAuthInvocation ( node . operand ) ) {
416+ // member access on auth() function is nullable
417+ // because user may not have provided all fields
418+ node . $resolvedType . nullable = true ;
419+ }
423420 }
424421 }
425422 }
0 commit comments