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

Function getModelUniqueFields

packages/language/src/utils.ts:271–291  ·  view source on GitHub ↗
(model: DataModel)

Source from the content-addressed store, hash-verified

269 * Gets `@@unique` fields declared at the data model level (including search in base models)
270 */
271export function getModelUniqueFields(model: DataModel) {
272 const modelsToCheck = [model, ...getRecursiveBases(model)];
273
274 for (const modelToCheck of modelsToCheck) {
275 const allAttributes = getAllAttributes(modelToCheck);
276 const uniqueAttr = allAttributes.find((attr) => attr.decl.$refText === '@@unique');
277 if (!uniqueAttr) {
278 continue;
279 }
280 const fieldsArg = uniqueAttr.args.find((a) => a.$resolvedParam?.name === 'fields');
281 if (!fieldsArg || !isArrayExpr(fieldsArg.value)) {
282 continue;
283 }
284
285 return fieldsArg.value.items
286 .filter((item): item is ReferenceExpr => isReferenceExpr(item))
287 .map((item) => resolved(item.target) as DataField);
288 }
289
290 return [];
291}
292
293/**
294 * Gets lists of unique fields declared at the data model level

Callers 2

validateFieldsMethod · 0.90
isIdFieldFunction · 0.90

Calls 6

isArrayExprFunction · 0.90
isReferenceExprFunction · 0.90
getRecursiveBasesFunction · 0.85
getAllAttributesFunction · 0.85
findMethod · 0.80
resolvedFunction · 0.70

Tested by

no test coverage detected