(model: DataModel)
| 296 | * TODO: merge this with {@link getModelUniqueFields} |
| 297 | */ |
| 298 | export function getUniqueFields(model: DataModel) { |
| 299 | const uniqueAttrs = model.attributes.filter( |
| 300 | (attr) => attr.decl.ref?.name === '@@unique' || attr.decl.ref?.name === '@@id', |
| 301 | ); |
| 302 | return uniqueAttrs.map((uniqueAttr) => { |
| 303 | const fieldsArg = uniqueAttr.args.find((a) => a.$resolvedParam?.name === 'fields'); |
| 304 | if (!fieldsArg || !isArrayExpr(fieldsArg.value)) { |
| 305 | return []; |
| 306 | } |
| 307 | |
| 308 | return fieldsArg.value.items |
| 309 | .filter((item): item is ReferenceExpr => isReferenceExpr(item)) |
| 310 | .map((item) => resolved(item.target) as DataField); |
| 311 | }); |
| 312 | } |
| 313 | |
| 314 | /** |
| 315 | * Finds the first ancestor of the given AST node that satisfies the given predicate function. Returns `undefined` if no such ancestor is found. |
no test coverage detected