(model: Model)
| 208 | } |
| 209 | |
| 210 | function validationAfterImportMerge(model: Model) { |
| 211 | const errors: string[] = []; |
| 212 | const dataSources = model.declarations.filter((d) => isDataSource(d)); |
| 213 | if (dataSources.length === 0) { |
| 214 | errors.push('Validation error: schema must have a datasource declaration'); |
| 215 | } else { |
| 216 | if (dataSources.length > 1) { |
| 217 | errors.push('Validation error: multiple datasource declarations are not allowed'); |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | // at most one `@@auth` model |
| 222 | const decls = getDataModelAndTypeDefs(model, true); |
| 223 | const authDecls = decls.filter((d) => hasAttribute(d, '@@auth')); |
| 224 | if (authDecls.length > 1) { |
| 225 | errors.push('Validation error: Multiple `@@auth` declarations are not allowed'); |
| 226 | } |
| 227 | |
| 228 | // check for usages incompatible with the datasource provider |
| 229 | const provider = getDataSourceProvider(model); |
| 230 | invariant(provider !== undefined, 'Datasource provider should be defined at this point'); |
| 231 | |
| 232 | for (const decl of model.declarations.filter(isDataModel)) { |
| 233 | const fields = getAllFields(decl, true); |
| 234 | for (const field of fields) { |
| 235 | if (field.type.array && !isDataModel(field.type.reference?.ref)) { |
| 236 | if (!DB_PROVIDERS_SUPPORTING_LIST_TYPE.includes(provider)) { |
| 237 | errors.push( |
| 238 | `Validation error: List type is not supported for "${provider}" provider (model: "${decl.name}", field: "${field.name}")`, |
| 239 | ); |
| 240 | } |
| 241 | } |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | return errors; |
| 246 | } |
| 247 | |
| 248 | /** |
| 249 | * Formats the given ZModel content. |
no test coverage detected