MCPcopy Create free account
hub / github.com/zenstackhq/zenstack / getModelIdFields

Function getModelIdFields

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

Source from the content-addressed store, hash-verified

244 * Gets `@@id` fields declared at the data model level (including search in base models)
245 */
246export function getModelIdFields(model: DataModel) {
247 const modelsToCheck = [model, ...getRecursiveBases(model)];
248
249 for (const modelToCheck of modelsToCheck) {
250 const allAttributes = getAllAttributes(modelToCheck);
251 const idAttr = allAttributes.find((attr) => attr.decl.$refText === '@@id');
252 if (!idAttr) {
253 continue;
254 }
255 const fieldsArg = idAttr.args.find((a) => a.$resolvedParam?.name === 'fields');
256 if (!fieldsArg || !isArrayExpr(fieldsArg.value)) {
257 continue;
258 }
259
260 return fieldsArg.value.items
261 .filter((item): item is ReferenceExpr => isReferenceExpr(item))
262 .map((item) => resolved(item.target) as DataField);
263 }
264
265 return [];
266}
267
268/**
269 * Gets `@@unique` fields declared at the data model level (including search in base models)

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