@@ -4,18 +4,23 @@ import {
44 type DiagnosticInfo ,
55 type ValidationAcceptor ,
66} from 'langium' ;
7+ import { IssueCodes , SCALAR_TYPES } from '../constants' ;
78import {
89 ArrayExpr ,
910 DataModel ,
1011 DataModelField ,
12+ Model ,
1113 ReferenceExpr ,
1214 isDataModel ,
15+ isDataSource ,
1316 isEnum ,
17+ isModel ,
1418 isStringLiteral ,
1519 isTypeDef ,
1620} from '../generated/ast' ;
1721import {
1822 findUpInheritance ,
23+ getLiteral ,
1924 getModelFieldsWithBases ,
2025 getModelIdFields ,
2126 getModelUniqueFields ,
@@ -25,7 +30,6 @@ import {
2530} from '../utils' ;
2631import { validateAttributeApplication } from './attribute-application-validator' ;
2732import { validateDuplicatedDeclarations , type AstValidator } from './common' ;
28- import { IssueCodes , SCALAR_TYPES } from '../constants' ;
2933
3034/**
3135 * Validates data model declarations.
@@ -147,6 +151,19 @@ export default class DataModelValidator implements AstValidator<DataModel> {
147151 ) ;
148152 }
149153
154+ if ( field . type . array && ! isDataModel ( field . type . reference ?. ref ) ) {
155+ const provider = this . getDataSourceProvider (
156+ AstUtils . getContainerOfType ( field , isModel ) !
157+ ) ;
158+ if ( provider === 'sqlite' ) {
159+ accept (
160+ 'error' ,
161+ `Array type is not supported for "${ provider } " provider.` ,
162+ { node : field . type }
163+ ) ;
164+ }
165+ }
166+
150167 field . attributes . forEach ( ( attr ) =>
151168 validateAttributeApplication ( attr , accept )
152169 ) ;
@@ -162,6 +179,18 @@ export default class DataModelValidator implements AstValidator<DataModel> {
162179 }
163180 }
164181
182+ private getDataSourceProvider ( model : Model ) {
183+ const dataSource = model . declarations . find ( isDataSource ) ;
184+ if ( ! dataSource ) {
185+ return undefined ;
186+ }
187+ const provider = dataSource ?. fields . find ( ( f ) => f . name === 'provider' ) ;
188+ if ( ! provider ) {
189+ return undefined ;
190+ }
191+ return getLiteral < string > ( provider . value ) ;
192+ }
193+
165194 private validateAttributes ( dm : DataModel , accept : ValidationAcceptor ) {
166195 dm . attributes . forEach ( ( attr ) =>
167196 validateAttributeApplication ( attr , accept )
0 commit comments