( endpoints: Map<string, EndpointFields>, )
| 212 | ] |
| 213 | |
| 214 | function computeOverrides( |
| 215 | endpoints: Map<string, EndpointFields>, |
| 216 | ): Map<string, Partial<Record<RoleKey, string>>> { |
| 217 | const overrides = new Map<string, Partial<Record<RoleKey, string>>>() |
| 218 | |
| 219 | for (const [endpointId, { fields, isList, producesVideo }] of endpoints) { |
| 220 | const entry: Partial<Record<RoleKey, string>> = {} |
| 221 | for (const role of ROLE_ORDER) { |
| 222 | if (VIDEO_ONLY_ROLES.has(role) && !producesVideo) continue |
| 223 | const chosen = CANDIDATES[role].find((candidate) => fields.has(candidate)) |
| 224 | if (!chosen) continue |
| 225 | |
| 226 | // Arity sanity check: the runtime mapper decides array-wrapping from |
| 227 | // the static LIST_FIELDS set, so the actual type must agree. Run this |
| 228 | // for default-selected fields too, otherwise a default field's type |
| 229 | // could drift silently. |
| 230 | const actualIsList = isList.get(chosen) ?? false |
| 231 | const assumedIsList = LIST_FIELDS.has(chosen) |
| 232 | if (actualIsList !== assumedIsList) { |
| 233 | throw new Error( |
| 234 | `Arity mismatch for ${endpointId}.${chosen}: type says ` + |
| 235 | `${actualIsList ? 'array' : 'scalar'} but LIST_FIELDS assumes ` + |
| 236 | `${assumedIsList ? 'array' : 'scalar'}. Update LIST_FIELDS here ` + |
| 237 | `and LIST_FIELDS in image-inputs.ts.`, |
| 238 | ) |
| 239 | } |
| 240 | if (chosen === DEFAULTS[role]) continue |
| 241 | entry[role] = chosen |
| 242 | } |
| 243 | if (Object.keys(entry).length > 0) overrides.set(endpointId, entry) |
| 244 | } |
| 245 | return overrides |
| 246 | } |
| 247 | |
| 248 | // --------------------------------------------------------------------------- |
| 249 | // Emission |
no test coverage detected