MCPcopy Index your code
hub / github.com/zenstackhq/zenstack / validationAfterImportMerge

Function validationAfterImportMerge

packages/language/src/document.ts:210–246  ·  view source on GitHub ↗
(model: Model)

Source from the content-addressed store, hash-verified

208}
209
210function 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.

Callers 1

loadDocumentFunction · 0.85

Calls 8

isDataSourceFunction · 0.90
getDataModelAndTypeDefsFunction · 0.90
hasAttributeFunction · 0.90
getDataSourceProviderFunction · 0.90
invariantFunction · 0.90
getAllFieldsFunction · 0.90
isDataModelFunction · 0.90
pushMethod · 0.80

Tested by

no test coverage detected