(attrs, deleted)
| 57 | * @return {Attribution?} |
| 58 | */ |
| 59 | export const createAttributionFromAttributionItems = (attrs, deleted) => { |
| 60 | if (attrs == null) { |
| 61 | return null |
| 62 | } |
| 63 | /** |
| 64 | * @type {Attribution} |
| 65 | */ |
| 66 | const attribution = {} |
| 67 | if (deleted) { |
| 68 | attribution.delete = [] |
| 69 | } else { |
| 70 | attribution.insert = [] |
| 71 | } |
| 72 | attrs.forEach(attr => { |
| 73 | switch (attr.name) { |
| 74 | // eslint-disable-next-line no-fallthrough |
| 75 | case 'insert': |
| 76 | case 'delete': { |
| 77 | // needs to be non-ambiguous: don't add existing attr if it doesn't match the actual status |
| 78 | attribution[attr.name]?.push(attr.val) |
| 79 | break |
| 80 | } |
| 81 | default: { |
| 82 | if (attr.name[0] !== '_') { |
| 83 | /** @type {any} */ (attribution)[attr.name] = attr.val |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | }) |
| 88 | return attribution |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * @template T |
no test coverage detected
searching dependent graphs…