|
1 | 1 | import { |
2 | | - AttributeArg, |
3 | | - AttributeParam, |
4 | 2 | BuiltinType, |
5 | | - DataModelAttribute, |
6 | | - DataModelFieldAttribute, |
7 | 3 | Expression, |
8 | 4 | ExpressionType, |
9 | | - InternalAttribute, |
10 | | - isArrayExpr, |
11 | 5 | isDataModelField, |
12 | | - isEnum, |
13 | 6 | isMemberAccessExpr, |
14 | | - isReferenceExpr, |
15 | 7 | isStringLiteral, |
16 | 8 | } from '@zenstackhq/language/ast'; |
17 | | -import { isAuthInvocation, resolved } from '@zenstackhq/sdk'; |
| 9 | +import { isAuthInvocation } from '@zenstackhq/sdk'; |
18 | 10 | import { AstNode, ValidationAcceptor } from 'langium'; |
19 | 11 |
|
20 | 12 | /** |
@@ -109,80 +101,6 @@ export function mapBuiltinTypeToExpressionType( |
109 | 101 | } |
110 | 102 | } |
111 | 103 |
|
112 | | -/** |
113 | | - * Determines if the given attribute argument is assignable to the given attribute parameter |
114 | | - */ |
115 | | -export function assignableToAttributeParam( |
116 | | - arg: AttributeArg, |
117 | | - param: AttributeParam, |
118 | | - attr: DataModelAttribute | DataModelFieldAttribute | InternalAttribute |
119 | | -): boolean { |
120 | | - const argResolvedType = arg.$resolvedType; |
121 | | - if (!argResolvedType) { |
122 | | - return false; |
123 | | - } |
124 | | - |
125 | | - let dstType = param.type.type; |
126 | | - let dstIsArray = param.type.array; |
127 | | - const dstRef = param.type.reference; |
128 | | - |
129 | | - if (dstType === 'Any' && !dstIsArray) { |
130 | | - return true; |
131 | | - } |
132 | | - |
133 | | - // destination is field reference or transitive field reference, check if |
134 | | - // argument is reference or array or reference |
135 | | - if (dstType === 'FieldReference' || dstType === 'TransitiveFieldReference') { |
136 | | - if (dstIsArray) { |
137 | | - return ( |
138 | | - isArrayExpr(arg.value) && |
139 | | - !arg.value.items.find((item) => !isReferenceExpr(item) || !isDataModelField(item.target.ref)) |
140 | | - ); |
141 | | - } else { |
142 | | - return isReferenceExpr(arg.value) && isDataModelField(arg.value.target.ref); |
143 | | - } |
144 | | - } |
145 | | - |
146 | | - if (isEnum(argResolvedType.decl)) { |
147 | | - // enum type |
148 | | - |
149 | | - let attrArgDeclType = dstRef?.ref; |
150 | | - if (dstType === 'ContextType' && isDataModelField(attr.$container) && attr.$container?.type?.reference) { |
151 | | - // attribute parameter type is ContextType, need to infer type from |
152 | | - // the attribute's container |
153 | | - attrArgDeclType = resolved(attr.$container.type.reference); |
154 | | - dstIsArray = attr.$container.type.array; |
155 | | - } |
156 | | - return attrArgDeclType === argResolvedType.decl && dstIsArray === argResolvedType.array; |
157 | | - } else if (dstType) { |
158 | | - // scalar type |
159 | | - |
160 | | - if (typeof argResolvedType?.decl !== 'string') { |
161 | | - // destination type is not a reference, so argument type must be a plain expression |
162 | | - return false; |
163 | | - } |
164 | | - |
165 | | - if (dstType === 'ContextType') { |
166 | | - // attribute parameter type is ContextType, need to infer type from |
167 | | - // the attribute's container |
168 | | - if (isDataModelField(attr.$container)) { |
169 | | - if (!attr.$container?.type?.type) { |
170 | | - return false; |
171 | | - } |
172 | | - dstType = mapBuiltinTypeToExpressionType(attr.$container.type.type); |
173 | | - dstIsArray = attr.$container.type.array; |
174 | | - } else { |
175 | | - dstType = 'Any'; |
176 | | - } |
177 | | - } |
178 | | - |
179 | | - return typeAssignable(dstType, argResolvedType.decl, arg.value) && dstIsArray === argResolvedType.array; |
180 | | - } else { |
181 | | - // reference type |
182 | | - return (dstRef?.ref === argResolvedType.decl || dstType === 'Any') && dstIsArray === argResolvedType.array; |
183 | | - } |
184 | | -} |
185 | | - |
186 | 104 | export function isAuthOrAuthMemberAccess(expr: Expression): boolean { |
187 | 105 | return isAuthInvocation(expr) || (isMemberAccessExpr(expr) && isAuthOrAuthMemberAccess(expr.operand)); |
188 | 106 | } |
0 commit comments